This is the mail archive of the
binutils@sources.redhat.com
mailing list for the binutils project.
Re: Confusing meaning of --no-undefined
Hi Guys,
Ok here is a revised patch. It applies the fix I posted before to
elf_link_output_extsym(), so that allow_shlib_undefined is only
checked if the symbol is in a shared library. It also applies
Alan's suggestion of the fix to elf_i386_relocate_section() so that
allow_shlib_undefined is not (bogusly) checked. It also changes the
default setting of allow_shlib_undefined to TRUE, which matches the
current behaviour, and it adds a new linker command line switch
--no-allow-shlib-undefined in order to gain the pre-binutils 2.12
behaviour of complaining about such things. Finally it updates the
linker documentation to describe the new switch and document the
current default behaviour.
> Does "ld --shared -Bsymbolic --no-undefined" work with the change? See
>
> http://sources.redhat.com/ml/binutils/2000-11/msg00314.html
Yes it does. I checked and you still get error messages, not
warnings. Of course if you want error messages from undefined
symbols in shared libraries you now have to add
--no-allow-shlib-undefined to the command line.
Any comments before I check it in ?
Cheers
Nick
bfd/ChangeLog
2003-02-14 Nick Clifton <nickc@redhat.com>
* elf32-i386.c (elf_i386_relocate_section): Remove bogus check
of allow_shlib_undefined.
* elflink.h (elf_link_output_extsym): Only check
allow_shlib_undefined for shared libraries.
ld/ChangeLog
2003-02-14 Nick Clifton <nickc@redhat.com>
* ldmain.c (main) Default allow_shlib_undefined to true.
* lexsup.c (ld_options): Add --no-allow-shlib-undefined.
(parse_args): Parse the new switch.
* ld.texinfo: Document new switch and default behaviour of
allowing undefined symbols in shared libraries.
Index: bfd/elf32-i386.c
===================================================================
RCS file: /cvs/src/src/bfd/elf32-i386.c,v
retrieving revision 1.93
diff -c -3 -p -w -r1.93 elf32-i386.c
*** bfd/elf32-i386.c 20 Jan 2003 18:06:21 -0000 1.93
--- bfd/elf32-i386.c 14 Feb 2003 19:29:28 -0000
*************** elf_i386_relocate_section (output_bfd, i
*** 2261,2267 ****
else if (h->root.type == bfd_link_hash_undefweak)
;
else if (info->shared
- && (!info->symbolic || info->allow_shlib_undefined)
&& !info->no_undefined
&& ELF_ST_VISIBILITY (h->other) == STV_DEFAULT)
;
--- 2261,2266 ----
Index: bfd/elflink.h
===================================================================
RCS file: /cvs/src/src/bfd/elflink.h,v
retrieving revision 1.205
diff -c -3 -p -w -r1.205 elflink.h
*** bfd/elflink.h 13 Feb 2003 22:14:10 -0000 1.205
--- bfd/elflink.h 14 Feb 2003 19:29:36 -0000
*************** elf_link_output_extsym (h, data)
*** 6166,6173 ****
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
&& h->root.type == bfd_link_hash_undefined
&& (h->elf_link_hash_flags & ELF_LINK_HASH_REF_DYNAMIC) != 0
&& (h->elf_link_hash_flags & ELF_LINK_HASH_REF_REGULAR) == 0
--- 6166,6172 ----
referenced by regular files, because we will already have issued
warnings for them. */
if (! finfo->info->relocateable
! && (! finfo->info->shared || ! finfo->info->allow_shlib_undefined)
&& h->root.type == bfd_link_hash_undefined
&& (h->elf_link_hash_flags & ELF_LINK_HASH_REF_DYNAMIC) != 0
&& (h->elf_link_hash_flags & ELF_LINK_HASH_REF_REGULAR) == 0
Index: ld/ldmain.c
===================================================================
RCS file: /cvs/src/src/ld/ldmain.c,v
retrieving revision 1.61
diff -c -3 -p -w -r1.61 ldmain.c
*** ld/ldmain.c 9 Jan 2003 21:26:53 -0000 1.61
--- ld/ldmain.c 14 Feb 2003 19:29:47 -0000
*************** main (argc, argv)
*** 265,271 ****
link_info.traditional_format = FALSE;
link_info.optimize = FALSE;
link_info.no_undefined = FALSE;
! link_info.allow_shlib_undefined = FALSE;
link_info.allow_multiple_definition = FALSE;
link_info.allow_undefined_version = TRUE;
link_info.keep_memory = TRUE;
--- 265,271 ----
link_info.traditional_format = FALSE;
link_info.optimize = FALSE;
link_info.no_undefined = FALSE;
! link_info.allow_shlib_undefined = TRUE;
link_info.allow_multiple_definition = FALSE;
link_info.allow_undefined_version = TRUE;
link_info.keep_memory = TRUE;
Index: ld/lexsup.c
===================================================================
RCS file: /cvs/src/src/ld/lexsup.c,v
retrieving revision 1.58
diff -c -3 -p -w -r1.58 lexsup.c
*** ld/lexsup.c 23 Dec 2002 12:05:38 -0000 1.58
--- ld/lexsup.c 14 Feb 2003 19:29:50 -0000
*************** int parsing_defsym = 0;
*** 126,132 ****
#define OPTION_UNIQUE (OPTION_SECTION_START + 1)
#define OPTION_TARGET_HELP (OPTION_UNIQUE + 1)
#define OPTION_ALLOW_SHLIB_UNDEFINED (OPTION_TARGET_HELP + 1)
! #define OPTION_ALLOW_MULTIPLE_DEFINITION (OPTION_ALLOW_SHLIB_UNDEFINED + 1)
#define OPTION_NO_UNDEFINED_VERSION (OPTION_ALLOW_MULTIPLE_DEFINITION + 1)
#define OPTION_DISCARD_NONE (OPTION_NO_UNDEFINED_VERSION + 1)
#define OPTION_SPARE_DYNAMIC_TAGS (OPTION_DISCARD_NONE + 1)
--- 126,133 ----
#define OPTION_UNIQUE (OPTION_SECTION_START + 1)
#define OPTION_TARGET_HELP (OPTION_UNIQUE + 1)
#define OPTION_ALLOW_SHLIB_UNDEFINED (OPTION_TARGET_HELP + 1)
! #define OPTION_NO_ALLOW_SHLIB_UNDEFINED (OPTION_ALLOW_SHLIB_UNDEFINED + 1)
! #define OPTION_ALLOW_MULTIPLE_DEFINITION (OPTION_NO_ALLOW_SHLIB_UNDEFINED + 1)
#define OPTION_NO_UNDEFINED_VERSION (OPTION_ALLOW_MULTIPLE_DEFINITION + 1)
#define OPTION_DISCARD_NONE (OPTION_NO_UNDEFINED_VERSION + 1)
#define OPTION_SPARE_DYNAMIC_TAGS (OPTION_DISCARD_NONE + 1)
*************** static const struct ld_option ld_options
*** 335,341 ****
{ {"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 },
{ {"allow-multiple-definition", no_argument, NULL, OPTION_ALLOW_MULTIPLE_DEFINITION},
'\0', NULL, N_("Allow multiple definitions"), TWO_DASHES },
{ {"no-undefined-version", no_argument, NULL, OPTION_NO_UNDEFINED_VERSION},
--- 336,344 ----
{ {"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 (the default)"), TWO_DASHES },
! { {"no-allow-shlib-undefined", no_argument, NULL, OPTION_NO_ALLOW_SHLIB_UNDEFINED},
! '\0', NULL, N_("Do not allow undefined symbols in shared objects"), TWO_DASHES },
{ {"allow-multiple-definition", no_argument, NULL, OPTION_ALLOW_MULTIPLE_DEFINITION},
'\0', NULL, N_("Allow multiple definitions"), TWO_DASHES },
{ {"no-undefined-version", no_argument, NULL, OPTION_NO_UNDEFINED_VERSION},
*************** parse_args (argc, argv)
*** 787,792 ****
--- 790,798 ----
break;
case OPTION_ALLOW_SHLIB_UNDEFINED:
link_info.allow_shlib_undefined = TRUE;
+ break;
+ case OPTION_NO_ALLOW_SHLIB_UNDEFINED:
+ link_info.allow_shlib_undefined = FALSE;
break;
case OPTION_ALLOW_MULTIPLE_DEFINITION:
link_info.allow_multiple_definition = TRUE;
Index: ld/ld.texinfo
===================================================================
RCS file: /cvs/src/src/ld/ld.texinfo,v
retrieving revision 1.84
diff -c -3 -p -w -r1.84 ld.texinfo
*** ld/ld.texinfo 23 Jan 2003 09:30:43 -0000 1.84
--- ld/ld.texinfo 14 Feb 2003 19:29:47 -0000
*************** while linking a large executable.
*** 1108,1115 ****
@item --no-undefined
@itemx -z defs
Normally when creating a non-symbolic shared library, undefined symbols
! are allowed and left to be resolved by the runtime loader. These options
! disallows such undefined symbols.
@kindex --allow-multiple-definition
@kindex -z muldefs
--- 1108,1117 ----
@item --no-undefined
@itemx -z defs
Normally when creating a non-symbolic shared library, undefined symbols
! are allowed and left to be resolved by the runtime loader. This option
! disallows such undefined symbols if they come from regular object
! files. The switch @samp{--no-allow-shlib-undefined} controls the
! behaviour for shared objects being linked into the shared library.
@kindex --allow-multiple-definition
@kindex -z muldefs
*************** report a fatal error. These options allo
*** 1120,1136 ****
first definition will be used.
@kindex --allow-shlib-undefined
@item --allow-shlib-undefined
! Allow undefined symbols in shared objects even when --no-undefined is
! set. 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.
@kindex --no-undefined-version
@item --no-undefined-version
--- 1122,1146 ----
first definition will be used.
@kindex --allow-shlib-undefined
+ @kindex --no-allow-shlib-undefined
@item --allow-shlib-undefined
! @itemx --no-allow-shlib-undefined
! Allow (the default) or disallow undefined symbols in shared objects.
! The setting of this switch overrides @samp {--no-undefined} where
! shared objects are concerned. Thus if @samp {--no-undefined} is set
! but @samp {--no-allow-shlib-undefined} is not, the net result will be
! that undefined symbols in regular object files will trigger an error,
! but undefined symbols in shared objects will be ignored.
!
! The reason that @samp{--allow-shlib-undefined} is the default is that
! the shared object being specified at link time may not be the same one
! that is available at load time, so the symbols might actually be
! resolvable at load time. Plus there are some systems, (eg 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. eg. to dynamically select an appropriate
! memset function. Apparently it is also normal for HPPA shared
! libraries to have undefined symbols.
@kindex --no-undefined-version
@item --no-undefined-version