diff options
Diffstat (limited to 'ld')
-rw-r--r-- | ld/ChangeLog | 17 | ||||
-rw-r--r-- | ld/NEWS | 5 | ||||
-rw-r--r-- | ld/emultempl/elf32.em | 7 | ||||
-rw-r--r-- | ld/ld.texinfo | 116 | ||||
-rw-r--r-- | ld/ldmain.c | 4 | ||||
-rw-r--r-- | ld/lexsup.c | 246 |
6 files changed, 272 insertions, 123 deletions
diff --git a/ld/ChangeLog b/ld/ChangeLog index 65da76f..76f1cc6 100644 --- a/ld/ChangeLog +++ b/ld/ChangeLog @@ -1,3 +1,20 @@ +2003-08-20 Nick Clifton <nickc@redhat.com> + + * ldmain.c: Initialise the new fields in bfd_link_info to + NOT_YET_SET. + * lexsup.c (enum option_values): New enum. Use this to + replace the handed coded values for the long switch options. + (ld_options): Add 'unresolved-symbols', + 'warn-unresolved-symbols' and 'error-unresolved-symbols'. + (parse_args): Handle the new switches. Set the values of + unresolved_symbols_in_objects and + unresolved_symbols_in_shared_libs appropriately. If they were + not initialised by the command line, install default values. + * emultempl/elf32.em (handle_option): Update OPTION_GROUP and + -z defs to use the new fields in bfd_link_info. + * ld.texinfo: Document the new switches. + * NEWS: Mention this feature. + 2003-08-15 Dmitry Diky <diwil@mail.ru> * Makefile.am (GENSCRIPTS_EXTRA): New script definition which @@ -1,5 +1,10 @@ -*- text -*- +* Improved linker's handling of unresolved symbols. The switch + --unresolved-symbols=<method> has been added to tell the linker when it + should report them and the switch --warn-unresolved-symbols has been added to + make reports be issued as warning messages rather than errors. + * Added support for Xtensa architecture. * Added --with-sysroot configure switch to specify a target system root, for diff --git a/ld/emultempl/elf32.em b/ld/emultempl/elf32.em index dfe4e2d..33cff6a 100644 --- a/ld/emultempl/elf32.em +++ b/ld/emultempl/elf32.em @@ -1602,7 +1602,8 @@ cat >>e${EMULATION_NAME}.c <<EOF case OPTION_GROUP: link_info.flags_1 |= (bfd_vma) DF_1_GROUP; /* Groups must be self-contained. */ - link_info.no_undefined = TRUE; + link_info.unresolved_syms_in_objects = RM_GENERATE_ERROR; + link_info.unresolved_syms_in_shared_libs = RM_GENERATE_ERROR; break; case 'z': @@ -1631,7 +1632,7 @@ cat >>e${EMULATION_NAME}.c <<EOF link_info.flags_1 |= (bfd_vma) DF_1_ORIGIN; } else if (strcmp (optarg, "defs") == 0) - link_info.no_undefined = TRUE; + link_info.unresolved_syms_in_objects = RM_GENERATE_ERROR; else if (strcmp (optarg, "muldefs") == 0) link_info.allow_multiple_definition = TRUE; else if (strcmp (optarg, "combreloc") == 0) @@ -1684,7 +1685,7 @@ cat >>e${EMULATION_NAME}.c <<EOF fprintf (file, _(" --enable-new-dtags\tEnable new dynamic tags\n")); fprintf (file, _(" --eh-frame-hdr\tCreate .eh_frame_hdr section\n")); fprintf (file, _(" -z combreloc\t\tMerge dynamic relocs into one section and sort\n")); - fprintf (file, _(" -z defs\t\tDisallows undefined symbols\n")); + fprintf (file, _(" -z defs\t\tReport unresolved symbols in object files.\n")); fprintf (file, _(" -z execstack\t\tMark executable as requiring executable stack\n")); fprintf (file, _(" -z initfirst\t\tMark DSO to be initialized first at runtime\n")); fprintf (file, _(" -z interpose\t\tMark object to interpose all DSOs but executable\n")); diff --git a/ld/ld.texinfo b/ld/ld.texinfo index 040359a..b01a105 100644 --- a/ld/ld.texinfo +++ b/ld/ld.texinfo @@ -883,7 +883,8 @@ Combines multiple reloc sections and sorts them to make dynamic symbol lookup caching possible. @item defs -Disallows undefined symbols. +Disallows undefined symbols in object files. Undefined symbols in +shared libaries are still allowed. @item initfirst This option is only meaningful when building a shared object. @@ -984,15 +985,16 @@ for which shared libraries are supported. This option is normally the default on such platforms. The different variants of this option are for compatibility with various systems. You may use this option multiple times on the command line: it affects library searching for -@option{-l} options which follow it. +@option{-l} options which follow it. This +option also implies @option{--unresolved-symbols=ignore-all}. @kindex -Bgroup @item -Bgroup Set the @code{DF_1_GROUP} flag in the @code{DT_FLAGS_1} entry in the dynamic section. This causes the runtime linker to handle lookups in this object and its dependencies to be performed only inside the group. -@option{--no-undefined} is implied. This option is only meaningful on ELF -platforms which support shared libraries. +@option{--unresolved-symbols=report-all} is implied. This option is +only meaningful on ELF platforms which support shared libraries. @kindex -Bstatic @kindex -dn @@ -1006,7 +1008,8 @@ Do not link against shared libraries. This is only meaningful on platforms for which shared libraries are supported. The different variants of this option are for compatibility with various systems. You may use this option multiple times on the command line: it affects -library searching for @option{-l} options which follow it. +library searching for @option{-l} options which follow it. This +option also implies @option{--unresolved-symbols=report-all}. @kindex -Bsymbolic @item -Bsymbolic @@ -1025,7 +1028,7 @@ been assigned to see if there any overlaps. Normally the linker will perform this check, and if it finds any overlaps it will produce suitable error messages. The linker does know about, and does make allowances for sections in overlays. The default behaviour can be -restored by using the command line switch @samp{--check-sections}. +restored by using the command line switch @option{--check-sections}. @cindex cross reference table @kindex --cref @@ -1146,7 +1149,7 @@ Print a summary of all target specific options on the standard output and exit. @kindex -Map @item -Map @var{mapfile} Print a link map to the file @var{mapfile}. See the description of the -@samp{-M} option, above. +@option{-M} option, above. @cindex memory usage @kindex --no-keep-memory @@ -1161,11 +1164,11 @@ while linking a large executable. @kindex -z defs @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. +Report unresolved symbol references from regular object files. This +is done even if the linker is creating a non-symbolic shared library. +The switch @option{--[no-]allow-shlib-undefined} controls the +behaviour for reporting unresolved references found in shared +libraries being linked in. @kindex --allow-multiple-definition @kindex -z muldefs @@ -1179,22 +1182,21 @@ first definition will be used. @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 +Allows (the default) or disallows undefined symbols in shared libraries. +This switch is similar to @option{--no-undefined} except that it +determines the behaviour when the undefined symbols are in a +shared library rather than a regular object file. It does not affect +how undefined symbols in regular object files are handled. + +The reason that @option{--allow-shlib-undefined} is the default is that +the shared library being specified at link time may not be the same as +the 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. +undefined symbols in shared libraries is normal. (The kernel patches +them at load time to select which function is most appropriate +for the current architecture. This is used for example 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 @@ -1486,6 +1488,39 @@ sign (``@key{=}''), and @var{org}. Same as --section-start, with @code{.bss}, @code{.data} or @code{.text} as the @var{sectionname}. +@kindex --unresolved-symbols +@item --unresolved-symbols=@var{method} +Determine how to handle unresolved symbols. There are four possible +values for @samp{method}: + +@table @samp +@item ignore-all +Do not report any unresolved symbols. This is the default when +creating shared libraries or dynamic executables. + +@item report-all +Report all unresolved symbols. This is the default when creating +static binaries. + +@item ignore-in-object-files +Report unresolved symbols that are contained in shared libraries, but +ignore them if they come from regular object files. + +@item ignore-in-shared-libs +Report unresolved symbols that come from regular object files, but +ignore them if they come from shared libraries. This can be useful +when creating a dynamic binary and it is known that all the shared +libraries that it should be referencing are included on the linker's +command line. +@end table + +The behaviour for shared libraries on their own can also be controlled +by the @option{--[no-]allow-shlib-undefined} option. + +Normally the linker will generate an error message for each reported +unresolved symbol but the option @option{--warn-unresolved-symbols} +can change this to a warning. + @kindex --verbose @cindex verbose @item --dll-verbose @@ -1508,10 +1543,10 @@ is only meaningful on ELF platforms which support shared libraries. @cindex combining symbols, warnings on @item --warn-common Warn when a common symbol is combined with another common symbol or with -a symbol definition. Unix linkers allow this somewhat sloppy practice, +a symbol definition. Unix linkers allow this somewhat sloppy practise, but linkers on some other operating systems do not. This option allows you to find potential problems from combining global symbols. -Unfortunately, some C libraries use this practice, so you may get some +Unfortunately, some C libraries use this practise, so you may get some warnings about symbols in the libraries as well as in your programs. There are three kinds of global symbols, illustrated here by C examples: @@ -1625,6 +1660,17 @@ The address will only be changed if it not explicitly specified; that is, if the @code{SECTIONS} command does not specify a start address for the section (@pxref{SECTIONS}). +@kindex --warn-unresolved-symbols +@item --warn-unresolved-symbols +If the linker is going to report an unresolved symbol (see the option +@option{--unresolved-symbols}) it will normally generate an error. +This option makes it generate a warning instead. + +@kindex --error-unresolved-symbols +@item --error-unresolved-symbols +This restores the linker's default behaviour of generating errors when +it is reporting unresolved symbols. + @kindex --whole-archive @cindex including an entire archive @item --whole-archive @@ -1871,7 +1917,7 @@ automatically or implicitly exported symbols. The linker will create the file @var{file} which will contain an import lib corresponding to the DLL the linker is generating. This import lib (which should be called @code{*.dll.a} or @code{*.a} -may be used to link clients against the generated DLL; this behavior +may be used to link clients against the generated DLL; this behaviour makes it possible to skip a separate @code{dlltool} import library creation step. [This option is specific to the i386 PE targeted port of the linker] @@ -1897,7 +1943,7 @@ default. @item --dll-search-prefix @var{string} When linking dynamically to a dll without an import library, search for @code{<string><basename>.dll} in preference to -@code{lib<basename>.dll}. This behavior allows easy distinction +@code{lib<basename>.dll}. This behaviour allows easy distinction between DLLs built for the various "subplatforms": native, cygwin, uwin, pw, etc. For instance, cygwin DLLs typically use @code{--dll-search-prefix=cyg}. @@ -1928,7 +1974,7 @@ data type of the exported variable: One way is to use --enable-runtime-pseudo-reloc switch. This leaves the task of adjusting references in your client code for runtime environment, so -this method works only when runtime environtment supports this feature. +this method works only when runtime environment supports this feature. A second solution is to force one of the 'constants' to be a variable -- that is, unknown and un-optimizable at compile time. For arrays, @@ -1968,7 +2014,7 @@ extern_ll --> A third method of dealing with this difficulty is to abandon 'auto-import' for the offending symbol and mark it with -@code{__declspec(dllimport)}. However, in practice that +@code{__declspec(dllimport)}. However, in practise that requires using compile-time #defines to indicate whether you are building a DLL, building client code that will link to the DLL, or merely building/linking to a static library. In making the choice @@ -2025,7 +2071,7 @@ functions). @kindex --disable-auto-import @item --disable-auto-import -Do not attempt to do sophisticalted linking of @code{_symbol} to +Do not attempt to do sophisticated linking of @code{_symbol} to @code{__imp__symbol} for DATA imports from DLLs. [This option is specific to the i386 PE targeted port of the linker] @@ -2083,7 +2129,7 @@ subsystem version also. @c man begin ENVIRONMENT -You can change the behavior of @command{ld} with the environment variables +You can change the behaviour of @command{ld} with the environment variables @ifclear SingleFormat @code{GNUTARGET}, @end ifclear diff --git a/ld/ldmain.c b/ld/ldmain.c index 048ebba..fb07a81 100644 --- a/ld/ldmain.c +++ b/ld/ldmain.c @@ -289,8 +289,8 @@ main (int argc, char **argv) link_info.static_link = FALSE; link_info.traditional_format = FALSE; link_info.optimize = FALSE; - link_info.no_undefined = FALSE; - link_info.allow_shlib_undefined = TRUE; + link_info.unresolved_syms_in_objects = RM_NOT_YET_SET; + link_info.unresolved_syms_in_shared_libs = RM_NOT_YET_SET; link_info.allow_multiple_definition = FALSE; link_info.allow_undefined_version = TRUE; link_info.keep_memory = TRUE; diff --git a/ld/lexsup.c b/ld/lexsup.c index 185a86d..fe19e61 100644 --- a/ld/lexsup.c +++ b/ld/lexsup.c @@ -62,82 +62,87 @@ int parsing_defsym = 0; /* Codes used for the long options with no short synonyms. 150 isn't special; it's just an arbitrary non-ASCII char value. */ - -#define OPTION_ASSERT 150 -#define OPTION_CALL_SHARED (OPTION_ASSERT + 1) -#define OPTION_CREF (OPTION_CALL_SHARED + 1) -#define OPTION_DEFSYM (OPTION_CREF + 1) -#define OPTION_DEMANGLE (OPTION_DEFSYM + 1) -#define OPTION_DYNAMIC_LINKER (OPTION_DEMANGLE + 1) -#define OPTION_EB (OPTION_DYNAMIC_LINKER + 1) -#define OPTION_EL (OPTION_EB + 1) -#define OPTION_EMBEDDED_RELOCS (OPTION_EL + 1) -#define OPTION_EXPORT_DYNAMIC (OPTION_EMBEDDED_RELOCS + 1) -#define OPTION_HELP (OPTION_EXPORT_DYNAMIC + 1) -#define OPTION_IGNORE (OPTION_HELP + 1) -#define OPTION_MAP (OPTION_IGNORE + 1) -#define OPTION_NO_DEMANGLE (OPTION_MAP + 1) -#define OPTION_NO_KEEP_MEMORY (OPTION_NO_DEMANGLE + 1) -#define OPTION_NO_WARN_MISMATCH (OPTION_NO_KEEP_MEMORY + 1) -#define OPTION_NOINHIBIT_EXEC (OPTION_NO_WARN_MISMATCH + 1) -#define OPTION_NON_SHARED (OPTION_NOINHIBIT_EXEC + 1) -#define OPTION_NO_WHOLE_ARCHIVE (OPTION_NON_SHARED + 1) -#define OPTION_OFORMAT (OPTION_NO_WHOLE_ARCHIVE + 1) -#define OPTION_RELAX (OPTION_OFORMAT + 1) -#define OPTION_RETAIN_SYMBOLS_FILE (OPTION_RELAX + 1) -#define OPTION_RPATH (OPTION_RETAIN_SYMBOLS_FILE + 1) -#define OPTION_RPATH_LINK (OPTION_RPATH + 1) -#define OPTION_SHARED (OPTION_RPATH_LINK + 1) -#define OPTION_SONAME (OPTION_SHARED + 1) -#define OPTION_SORT_COMMON (OPTION_SONAME + 1) -#define OPTION_STATS (OPTION_SORT_COMMON + 1) -#define OPTION_SYMBOLIC (OPTION_STATS + 1) -#define OPTION_TASK_LINK (OPTION_SYMBOLIC + 1) -#define OPTION_TBSS (OPTION_TASK_LINK + 1) -#define OPTION_TDATA (OPTION_TBSS + 1) -#define OPTION_TTEXT (OPTION_TDATA + 1) -#define OPTION_TRADITIONAL_FORMAT (OPTION_TTEXT + 1) -#define OPTION_UR (OPTION_TRADITIONAL_FORMAT + 1) -#define OPTION_VERBOSE (OPTION_UR + 1) -#define OPTION_VERSION (OPTION_VERBOSE + 1) -#define OPTION_VERSION_SCRIPT (OPTION_VERSION + 1) -#define OPTION_VERSION_EXPORTS_SECTION (OPTION_VERSION_SCRIPT + 1) -#define OPTION_WARN_COMMON (OPTION_VERSION_EXPORTS_SECTION + 1) -#define OPTION_WARN_CONSTRUCTORS (OPTION_WARN_COMMON + 1) -#define OPTION_WARN_FATAL (OPTION_WARN_CONSTRUCTORS + 1) -#define OPTION_WARN_MULTIPLE_GP (OPTION_WARN_FATAL + 1) -#define OPTION_WARN_ONCE (OPTION_WARN_MULTIPLE_GP + 1) -#define OPTION_WARN_SECTION_ALIGN (OPTION_WARN_ONCE + 1) -#define OPTION_SPLIT_BY_RELOC (OPTION_WARN_SECTION_ALIGN + 1) -#define OPTION_SPLIT_BY_FILE (OPTION_SPLIT_BY_RELOC + 1) -#define OPTION_WHOLE_ARCHIVE (OPTION_SPLIT_BY_FILE + 1) -#define OPTION_WRAP (OPTION_WHOLE_ARCHIVE + 1) -#define OPTION_FORCE_EXE_SUFFIX (OPTION_WRAP + 1) -#define OPTION_GC_SECTIONS (OPTION_FORCE_EXE_SUFFIX + 1) -#define OPTION_NO_GC_SECTIONS (OPTION_GC_SECTIONS + 1) -#define OPTION_CHECK_SECTIONS (OPTION_NO_GC_SECTIONS + 1) -#define OPTION_NO_CHECK_SECTIONS (OPTION_CHECK_SECTIONS + 1) -#define OPTION_MPC860C0 (OPTION_NO_CHECK_SECTIONS + 1) -#define OPTION_NO_UNDEFINED (OPTION_MPC860C0 + 1) -#define OPTION_INIT (OPTION_NO_UNDEFINED + 1) -#define OPTION_FINI (OPTION_INIT + 1) -#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) -#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) -#define OPTION_NO_DEFINE_COMMON (OPTION_SPARE_DYNAMIC_TAGS + 1) -#define OPTION_NOSTDLIB (OPTION_NO_DEFINE_COMMON + 1) -#define OPTION_NO_OMAGIC (OPTION_NOSTDLIB + 1) -#define OPTION_STRIP_DISCARDED (OPTION_NO_OMAGIC + 1) -#define OPTION_NO_STRIP_DISCARDED (OPTION_STRIP_DISCARDED + 1) -#define OPTION_ACCEPT_UNKNOWN_INPUT_ARCH (OPTION_NO_STRIP_DISCARDED + 1) -#define OPTION_NO_ACCEPT_UNKNOWN_INPUT_ARCH (OPTION_ACCEPT_UNKNOWN_INPUT_ARCH + 1) -#define OPTION_PIE (OPTION_NO_ACCEPT_UNKNOWN_INPUT_ARCH + 1) +enum option_values +{ + OPTION_ASSERT = 150, + OPTION_CALL_SHARED, + OPTION_CREF, + OPTION_DEFSYM, + OPTION_DEMANGLE, + OPTION_DYNAMIC_LINKER, + OPTION_EB, + OPTION_EL, + OPTION_EMBEDDED_RELOCS, + OPTION_EXPORT_DYNAMIC, + OPTION_HELP, + OPTION_IGNORE, + OPTION_MAP, + OPTION_NO_DEMANGLE, + OPTION_NO_KEEP_MEMORY, + OPTION_NO_WARN_MISMATCH, + OPTION_NOINHIBIT_EXEC, + OPTION_NON_SHARED, + OPTION_NO_WHOLE_ARCHIVE, + OPTION_OFORMAT, + OPTION_RELAX, + OPTION_RETAIN_SYMBOLS_FILE, + OPTION_RPATH, + OPTION_RPATH_LINK, + OPTION_SHARED, + OPTION_SONAME, + OPTION_SORT_COMMON, + OPTION_STATS, + OPTION_SYMBOLIC, + OPTION_TASK_LINK, + OPTION_TBSS, + OPTION_TDATA, + OPTION_TTEXT, + OPTION_TRADITIONAL_FORMAT, + OPTION_UR, + OPTION_VERBOSE, + OPTION_VERSION, + OPTION_VERSION_SCRIPT, + OPTION_VERSION_EXPORTS_SECTION, + OPTION_WARN_COMMON, + OPTION_WARN_CONSTRUCTORS, + OPTION_WARN_FATAL, + OPTION_WARN_MULTIPLE_GP, + OPTION_WARN_ONCE, + OPTION_WARN_SECTION_ALIGN, + OPTION_SPLIT_BY_RELOC, + OPTION_SPLIT_BY_FILE , + OPTION_WHOLE_ARCHIVE, + OPTION_WRAP, + OPTION_FORCE_EXE_SUFFIX, + OPTION_GC_SECTIONS, + OPTION_NO_GC_SECTIONS, + OPTION_CHECK_SECTIONS, + OPTION_NO_CHECK_SECTIONS, + OPTION_MPC860C0, + OPTION_NO_UNDEFINED, + OPTION_INIT, + OPTION_FINI, + OPTION_SECTION_START, + OPTION_UNIQUE, + OPTION_TARGET_HELP, + OPTION_ALLOW_SHLIB_UNDEFINED, + OPTION_NO_ALLOW_SHLIB_UNDEFINED, + OPTION_ALLOW_MULTIPLE_DEFINITION, + OPTION_NO_UNDEFINED_VERSION, + OPTION_DISCARD_NONE, + OPTION_SPARE_DYNAMIC_TAGS, + OPTION_NO_DEFINE_COMMON, + OPTION_NOSTDLIB, + OPTION_NO_OMAGIC, + OPTION_STRIP_DISCARDED, + OPTION_NO_STRIP_DISCARDED, + OPTION_ACCEPT_UNKNOWN_INPUT_ARCH, + OPTION_NO_ACCEPT_UNKNOWN_INPUT_ARCH, + OPTION_PIE, + OPTION_UNRESOLVED_SYMBOLS, + OPTION_WARN_UNRESOLVED_SYMBOLS, + OPTION_ERROR_UNRESOLVED_SYMBOLS +}; /* The long options. This structure is used for both the option parsing and the help text. */ @@ -334,11 +339,11 @@ static const struct ld_option ld_options[] = { {"no-keep-memory", no_argument, NULL, OPTION_NO_KEEP_MEMORY}, '\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 }, + '\0', NULL, N_("Do not allow unresolved references in object files"), 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 }, + '\0', NULL, N_("Allow unresolved references in shared libaries"), 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 }, + '\0', NULL, N_("Do not allow unresolved references in shared libs"), 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}, @@ -400,6 +405,9 @@ static const struct ld_option ld_options[] = '\0', N_("ADDRESS"), N_("Set address of .data section"), ONE_DASH }, { {"Ttext", required_argument, NULL, OPTION_TTEXT}, '\0', N_("ADDRESS"), N_("Set address of .text section"), ONE_DASH }, + { {"unresolved-symbols=<method>", required_argument, NULL, OPTION_UNRESOLVED_SYMBOLS}, + '\0', NULL, N_("How to handle unresolved symbols. <method> is:\n\t\t\t\tignore-all, report-all, ignore-in-object-files,\n\t\t\t\tignore-in-shared-libs"), + TWO_DASHES }, { {"verbose", no_argument, NULL, OPTION_VERBOSE}, '\0', NULL, N_("Output lots of information during link"), TWO_DASHES }, { {"dll-verbose", no_argument, NULL, OPTION_VERBOSE}, /* Linux. */ @@ -422,6 +430,10 @@ static const struct ld_option ld_options[] = { {"warn-section-align", no_argument, NULL, OPTION_WARN_SECTION_ALIGN}, '\0', NULL, N_("Warn if start of section changes due to alignment"), TWO_DASHES }, + { {"warn-unresolved-symbols", no_argument, NULL, OPTION_WARN_UNRESOLVED_SYMBOLS}, + '\0', NULL, N_("Report unresolved symbols as warnings"), TWO_DASHES }, + { {"error-unresolved-symbols", no_argument, NULL, OPTION_ERROR_UNRESOLVED_SYMBOLS}, + '\0', NULL, N_("Report unresolved symbols as errors"), TWO_DASHES }, { {"fatal-warnings", no_argument, NULL, OPTION_WARN_FATAL}, '\0', NULL, N_("Treat warnings as errors"), TWO_DASHES }, @@ -469,6 +481,7 @@ parse_args (unsigned argc, char **argv) struct option *longopts; struct option *really_longopts; int last_optind; + enum report_method how_to_report_unresolved_symbols = RM_GENERATE_ERROR; shortopts = xmalloc (OPTION_COUNT * 3 + 2); longopts = xmalloc (sizeof (*longopts) * (OPTION_COUNT + 1)); @@ -647,9 +660,21 @@ parse_args (unsigned argc, char **argv) break; case OPTION_CALL_SHARED: config.dynamic_link = TRUE; + /* When linking against shared libraries, the default + behaviour is to ignore any unresolved references. */ + if (link_info.unresolved_syms_in_objects == RM_NOT_YET_SET) + link_info.unresolved_syms_in_objects = RM_IGNORE; + if (link_info.unresolved_syms_in_shared_libs == RM_NOT_YET_SET) + link_info.unresolved_syms_in_shared_libs = RM_IGNORE; break; case OPTION_NON_SHARED: config.dynamic_link = FALSE; + /* When linking against static libraries, the default + behaviour is to report any unresolved references. */ + if (link_info.unresolved_syms_in_objects == RM_NOT_YET_SET) + link_info.unresolved_syms_in_objects = how_to_report_unresolved_symbols; + if (link_info.unresolved_syms_in_shared_libs == RM_NOT_YET_SET) + link_info.unresolved_syms_in_shared_libs = how_to_report_unresolved_symbols; break; case OPTION_CREF: command_line.cref = TRUE; @@ -790,14 +815,53 @@ parse_args (unsigned argc, char **argv) link_info.keep_memory = FALSE; break; case OPTION_NO_UNDEFINED: - link_info.no_undefined = TRUE; + link_info.unresolved_syms_in_objects = how_to_report_unresolved_symbols; break; case OPTION_ALLOW_SHLIB_UNDEFINED: - link_info.allow_shlib_undefined = TRUE; + link_info.unresolved_syms_in_shared_libs = RM_IGNORE; break; case OPTION_NO_ALLOW_SHLIB_UNDEFINED: - link_info.allow_shlib_undefined = FALSE; + link_info.unresolved_syms_in_shared_libs = how_to_report_unresolved_symbols; break; + case OPTION_UNRESOLVED_SYMBOLS: + if (strcmp (optarg, "ignore-all") == 0) + { + link_info.unresolved_syms_in_objects = RM_IGNORE; + link_info.unresolved_syms_in_shared_libs = RM_IGNORE; + } + else if (strcmp (optarg, "report-all") == 0) + { + link_info.unresolved_syms_in_objects = how_to_report_unresolved_symbols; + link_info.unresolved_syms_in_shared_libs = how_to_report_unresolved_symbols; + } + else if (strcmp (optarg, "ignore-in-object-files") == 0) + { + link_info.unresolved_syms_in_objects = RM_IGNORE; + link_info.unresolved_syms_in_shared_libs = how_to_report_unresolved_symbols; + } + else if (strcmp (optarg, "ignore-in-shared-libs") == 0) + { + link_info.unresolved_syms_in_objects = how_to_report_unresolved_symbols; + link_info.unresolved_syms_in_shared_libs = RM_IGNORE; + } + else + einfo (_("%P%F: bad --unresolved-symbols option: %s\n"), optarg); + break; + case OPTION_WARN_UNRESOLVED_SYMBOLS: + how_to_report_unresolved_symbols = RM_GENERATE_WARNING; + if (link_info.unresolved_syms_in_objects == RM_GENERATE_ERROR) + link_info.unresolved_syms_in_objects = RM_GENERATE_WARNING; + if (link_info.unresolved_syms_in_shared_libs == RM_GENERATE_ERROR) + link_info.unresolved_syms_in_shared_libs = RM_GENERATE_WARNING; + break; + + case OPTION_ERROR_UNRESOLVED_SYMBOLS: + how_to_report_unresolved_symbols = RM_GENERATE_ERROR; + if (link_info.unresolved_syms_in_objects == RM_GENERATE_WARNING) + link_info.unresolved_syms_in_objects = RM_GENERATE_ERROR; + if (link_info.unresolved_syms_in_shared_libs == RM_GENERATE_WARNING) + link_info.unresolved_syms_in_shared_libs = RM_GENERATE_ERROR; + break; case OPTION_ALLOW_MULTIPLE_DEFINITION: link_info.allow_multiple_definition = TRUE; break; @@ -948,7 +1012,15 @@ parse_args (unsigned argc, char **argv) break; case OPTION_SHARED: if (config.has_shared) - link_info.shared = TRUE; + { + link_info.shared = TRUE; + /* When creating a shared library, the default + behaviour is to ignore any unresolved references. */ + if (link_info.unresolved_syms_in_objects == RM_NOT_YET_SET) + link_info.unresolved_syms_in_objects = RM_IGNORE; + if (link_info.unresolved_syms_in_shared_libs == RM_NOT_YET_SET) + link_info.unresolved_syms_in_shared_libs = RM_IGNORE; + } else einfo (_("%P%F: -shared not supported\n")); break; @@ -1202,6 +1274,14 @@ parse_args (unsigned argc, char **argv) set_default_dirlist (default_dirlist); free (default_dirlist); } + + if (link_info.unresolved_syms_in_objects == RM_NOT_YET_SET) + /* FIXME: Should we allow emulations a chance to set this ? */ + link_info.unresolved_syms_in_objects = how_to_report_unresolved_symbols; + + if (link_info.unresolved_syms_in_shared_libs == RM_NOT_YET_SET) + /* FIXME: Should we allow emulations a chance to set this ? */ + link_info.unresolved_syms_in_shared_libs = how_to_report_unresolved_symbols; } /* Add the (colon-separated) elements of DIRLIST_PTR to the |