This is the mail archive of the binutils@sources.redhat.com mailing list for the binutils project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Comments solicited re --no-undefined problem


I'm working on updating the BeOS binutils.  Two of the changes in
binutils 2.10 ld changed the way undefined symbols are handled:

  * Added --no-undefined option to disallow undefined symbols when creating a
    shared library.

  * The linker now issues a warning, not an error, for an undefined symbol when
    using -Bsymbolic; use the new --no-undefined option to get the old
    behaviour.

As it turns out, adding --no-undefined doesn't completely reverse the
problem of undefined symbols being warnings with -Bsymbolic because
now it also warns about undefined symbols in shared libraries that are
participating in the link.

On BeOS, it is normal to have some undefined symbols in shared
libraries.  As an example, libroot.so has the undefined symbol
memset_internal which the runtime loader patches to point to either
memset_default or memset_pIII as appropriate for the architecture.

It also appears that HPPA has shared libraries with undefined symbols.
From elf-hppa.h:

 /* If we are not creating a shared library, and this symbol is
     referenced by a shared library but is not defined anywhere, then
     the generic code will warn that it is undefined.

     This behavior is undesirable on HPs since the standard shared
     libraries contain references to undefined symbols.

     So we twiddle the flags associated with such symbols so that they
     will not trigger the warning.  ?!? FIXME.  This is horribly fragile.

One solution to this problem, which preserves the current behavior of
--no-undefined, is to add another option that allows shared libraries
to have undefined symbols.  Here is one example of a possible fix.
However I admit that it is a 10 minute proof of concept hack that I
threw together to test out the concept and get past this problem to
see if there are more lurking around to be solved.  So I'm NOT
presenting this as a patch to be accepted as-is.

-Fred

Index: bfd/ChangeLog
===================================================================
RCS file: /cvs/src/src/bfd/ChangeLog,v
retrieving revision 1.670
diff -c -p -r1.670 ChangeLog
*** ChangeLog	2000/11/18 00:41:35	1.670
--- ChangeLog	2000/11/18 08:48:06
***************
*** 1,3 ****
--- 1,8 ----
+ 2000-11-18  Fred Fish  <fnf@be.com>
+ 
+ 	* elflink.h (elf_link_output_extsym): Don't complain about undefined
+ 	symbols in shared objects if allow_shlib_undefined is true.
+ 
  2000-11-17  H.J. Lu  <hjl@gnu.org>
  
  	* elfxx-ia64.c (elfNN_ia64_size_dynamic_sections): Don't create
Index: bfd/elflink.h
===================================================================
RCS file: /cvs/src/src/bfd/elflink.h,v
retrieving revision 1.75
diff -c -p -r1.75 elflink.h
*** elflink.h	2000/11/13 22:49:54	1.75
--- elflink.h	2000/11/18 08:48:08
*************** elf_link_output_extsym (h, data)
*** 5095,5100 ****
--- 5095,5101 ----
       referenced by regular files, because we will already have issued
       warnings for them.  */
    if (! finfo->info->relocateable
+       && ! finfo->info->allow_shlib_undefined
        && ! (finfo->info->shared
  	    && !finfo->info->no_undefined)
        && h->root.type == bfd_link_hash_undefined
Index: include/ChangeLog
===================================================================
RCS file: /cvs/src/src/include/ChangeLog,v
retrieving revision 1.62
diff -c -p -r1.62 ChangeLog
*** ChangeLog	2000/11/15 12:01:15	1.62
--- ChangeLog	2000/11/18 08:48:09
***************
*** 1,3 ****
--- 1,10 ----
+ 2000-11-18  Fred Fish  <fnf@be.com>
+ 
+ 	* bfdlink.h (struct bfd_link_info): Add new allow_shlib_undefined
+ 	member to struct for systems where it is normal to have undefined
+ 	symbols in shared libraries at runtime and the runtime linker takes
+ 	care of redirecting them.
+ 
  2000-11-15  Kenneth Block  <kenneth.block@compaq.com>
  
  	* demangle.h: Add gnat and java demangle styles.
Index: include/bfdlink.h
===================================================================
RCS file: /cvs/src/src/include/bfdlink.h,v
retrieving revision 1.6
diff -c -p -r1.6 bfdlink.h
*** bfdlink.h	2000/07/20 21:19:33	1.6
--- bfdlink.h	2000/11/18 08:48:09
*************** struct bfd_link_info
*** 201,206 ****
--- 201,219 ----
    /* true if BFD should generate errors for undefined symbols
       even if generating a shared object.  */
    boolean no_undefined;
+   /* true if BFD should allow undefined symbols in shared objects even
+      when no_undefined is set to disallow undefined symbols.  The net
+      result will be that undefined symbols in regular objects will
+      still trigger an error, but undefined symbols in shared objects
+      will be ignored.  The implementation of no_undefined makes the
+      assumption that the runtime linker will choke on undefined
+      symbols.  However there is at least one system (BeOS) where
+      undefined symbols in shared libraries is normal since the kernel
+      patches them at load time to select which function is most
+      appropriate for the current architecture.  I.E. dynamically
+      select an appropriate memset function.  Apparently it is also
+      normal for HPPA shared libraries to have undefined symbols. */
+   boolean allow_shlib_undefined;
    /* Which symbols to strip.  */
    enum bfd_link_strip strip;
    /* Which local symbols to discard.  */
Index: ld/ChangeLog
===================================================================
RCS file: /cvs/src/src/ld/ChangeLog,v
retrieving revision 1.309
diff -c -p -r1.309 ChangeLog
*** ChangeLog	2000/11/15 23:16:29	1.309
--- ChangeLog	2000/11/18 08:48:13
***************
*** 1,3 ****
--- 1,11 ----
+ 2000-11-18  Fred Fish  <fnf@be.com>
+ 
+ 	* lexsup.c (OPTION_ALLOW_SHLIB_UNDEFINED): Define.
+ 	* lexsup.c (ld_options): Entry for --allow-shlib-undefined.
+ 	* lexsup.c (parse_args): Handle OPTION_ALLOW_SHLIB_UNDEFINED.
+ 	* ldmain.c (main): Initialize link_info.allow_shlib_undefined
+ 	to false.
+ 
  2000-11-15  Richard Henderson  <rth@redhat.com>
  
  	* emulparams/elf64alpha.sh (MAXPAGESIZE): Typo -- 64k, not 1M.
Index: ld/ldmain.c
===================================================================
RCS file: /cvs/src/src/ld/ldmain.c,v
retrieving revision 1.16
diff -c -p -r1.16 ldmain.c
*** ldmain.c	2000/10/09 15:09:17	1.16
--- ldmain.c	2000/11/18 08:48:13
*************** main (argc, argv)
*** 223,228 ****
--- 223,229 ----
    link_info.traditional_format = false;
    link_info.optimize = false;
    link_info.no_undefined = false;
+   link_info.allow_shlib_undefined = false;
    link_info.strip = strip_none;
    link_info.discard = discard_none;
    link_info.keep_memory = true;
Index: ld/lexsup.c
===================================================================
RCS file: /cvs/src/src/ld/lexsup.c,v
retrieving revision 1.23
diff -c -p -r1.23 lexsup.c
*** lexsup.c	2000/10/17 20:10:20	1.23
--- lexsup.c	2000/11/18 08:48:13
*************** int parsing_defsym = 0;
*** 127,132 ****
--- 127,133 ----
  #define OPTION_SECTION_START		(OPTION_FINI + 1)
  #define OPTION_UNIQUE			(OPTION_SECTION_START + 1)
  #define OPTION_TARGET_HELP              (OPTION_UNIQUE + 1)
+ #define OPTION_ALLOW_SHLIB_UNDEFINED	(OPTION_TARGET_HELP + 1)
  
  /* The long options.  This structure is used for both the option
     parsing and the help text.  */
*************** static const struct ld_option ld_options
*** 298,303 ****
--- 299,306 ----
        '\0', NULL, N_("Use less memory and more disk I/O"), TWO_DASHES },
    { {"no-undefined", no_argument, NULL, OPTION_NO_UNDEFINED},
       '\0', NULL, N_("Allow no undefined symbols"), TWO_DASHES },
+   { {"allow-shlib-undefined", no_argument, NULL, OPTION_ALLOW_SHLIB_UNDEFINED},
+      '\0', NULL, N_("Allow undefined symbols in shared objects"), TWO_DASHES },
    { {"no-warn-mismatch", no_argument, NULL, OPTION_NO_WARN_MISMATCH},
        '\0', NULL, N_("Don't warn about mismatched input files"), TWO_DASHES},
    { {"no-whole-archive", no_argument, NULL, OPTION_NO_WHOLE_ARCHIVE},
*************** parse_args (argc, argv)
*** 708,713 ****
--- 711,719 ----
  	  break;
  	case OPTION_NO_UNDEFINED:
  	  link_info.no_undefined = true;
+ 	  break;
+ 	case OPTION_ALLOW_SHLIB_UNDEFINED:
+ 	  link_info.allow_shlib_undefined = true;
  	  break;
  	case OPTION_NO_WARN_MISMATCH:
  	  command_line.warn_mismatch = false;

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]