Add -z undefs option to the ELF linker.
authorNick Clifton <nickc@redhat.com>
Fri, 12 Jan 2018 08:15:55 +0000 (08:15 +0000)
committerNick Clifton <nickc@redhat.com>
Fri, 12 Jan 2018 08:15:55 +0000 (08:15 +0000)
  Currently we have no obvious way to revert the action of the "-z defs"
  command line option.  The "--unresolved-symbols=ignore-in-object-files"
  does pretty much what is needed, but it is non-obvious and it also
  touches the setting for reporting unresolved symbol references from
  shared libraries.  So I am proposing adding a "-z undefs" option to be
  the inverse of "-z defs".  (I thought that "-z nodefs" might be
  confusing since it implies banning all definitions, rather than
  allowing them).

  In addition the description of the "-z defs" option in the linker
  documentation is misleading in one place, where it says:

    'defs'
       Disallows undefined symbols in object files.  Undefined
       symbols in shared libraries are still allowed.

  whereas later on it gets it right:

    '-z defs'
       Report unresolved symbol references from regular object files.
       This is done even if the linker is creating a non-symbolic shared
       library.  The switch '--[no-]allow-shlib-undefined' controls the
       behaviour for reporting unresolved references found in shared
       libraries being linked in.

* emultempl/elf32.em (_handle_option): Add support for "-z undefs"
as the opposite of "-z defs".
* ld.texinfo: Document the new option.  Update the description of
the -z defs option to make it clear that it does generate an error
if an undefined symbol reference is found in an object file whilst
creating a shared library.
* NEWS: Document this new feature.

ld/ChangeLog
ld/NEWS
ld/emultempl/elf32.em
ld/ld.texinfo

index 19e34dadc162053bcbbd00a3367ea1024a8e73d8..a2c13c8385b47cc9952aaf3e818d5fab2212b51a 100644 (file)
@@ -1,3 +1,13 @@
+2018-01-12  Nick Clifton  <nickc@redhat.com>
+
+       * emultempl/elf32.em (_handle_option): Add support for "-z undefs"
+       as the opposite of "-z defs".
+       * ld.texinfo: Document the new option.  Update the description of
+       the -z defs option to make it clear that it does generate an error
+       if an undefined symbol reference is found in an object file whilst
+       creating a shared library.
+       * NEWS: Document this new feature.
+
 2018-01-11  H.J. Lu  <hongjiu.lu@intel.com>
 
        * testsuite/ld-elf/pr22393-2a.rd: Replace "-z textonly" with
diff --git a/ld/NEWS b/ld/NEWS
index 0d40ccd4948b07ec70136ea42cda61ca250cff8f..69c8b1de7cc801fa1242c6d24a0f9675df627595 100644 (file)
--- a/ld/NEWS
+++ b/ld/NEWS
@@ -1,6 +1,9 @@
 -*- text -*-
+
 * Add -z separate-code to generate separate code PT_LOAD segment.
 
+* Add "-z undefs" command line option as the inverse of the "-z defs" option.
+
 * Add -z globalaudit command line option to force audit libraries to be run
   for every dynamic object loaded by an executable - provided that the loader
   supports this functionality.
index 8ff19bf8833f93313b7eecdc3453c7b9bb164688..c0925fc9b970e66a6d014960e5a09919369d69ac 100644 (file)
@@ -2726,6 +2726,8 @@ fragment <<EOF
     case 'z':
       if (strcmp (optarg, "defs") == 0)
        link_info.unresolved_syms_in_objects = RM_GENERATE_ERROR;
+      else if (strcmp (optarg, "undefs") == 0)
+       link_info.unresolved_syms_in_objects = RM_IGNORE;
       else if (strcmp (optarg, "muldefs") == 0)
        link_info.allow_multiple_definition = TRUE;
       else if (CONST_STRNEQ (optarg, "max-page-size="))
index 8cd2bed340f7af6d90040a3bce3c5c57b5f3ed08..94d340caa653d57001b3b289da4333b961e24869 100644 (file)
@@ -1147,8 +1147,9 @@ layout will be optimized to minimize memory pages if the system is
 using pages of this size.
 
 @item defs
-Disallows undefined symbols in object files.  Undefined symbols in
-shared libraries are still allowed.
+Report unresolved symbol references from regular object files.  This
+is done even if the linker is creating a non-symbolic shared library.
+This option is the inverse of @samp{-z undefs}.
 
 @item dynamic-undefined-weak
 @itemx nodynamic-undefined-weak
@@ -1288,6 +1289,11 @@ Report an error if DT_TEXTREL is set, i.e., if the binary has dynamic
 relocations in read-only sections.  Don't report an error if
 @samp{notext} or @samp{textoff}.
 
+@item undefs
+Do not report unresolved symbol references from regular object files,
+either when creating an executable, or when creating a shared library.
+This option is the inverse of @samp{-z defs}.
+
 @end table
 
 Other keywords are ignored for Solaris compatibility.
@@ -1693,6 +1699,7 @@ while linking a large executable.
 
 @kindex --no-undefined
 @kindex -z defs
+@kindex -z undefs
 @item --no-undefined
 @itemx -z defs
 Report unresolved symbol references from regular object files.  This
@@ -1701,6 +1708,8 @@ The switch @option{--[no-]allow-shlib-undefined} controls the
 behaviour for reporting unresolved references found in shared
 libraries being linked in.
 
+The effects of this option can be reverted by using @code{-z undefs}.
+
 @kindex --allow-multiple-definition
 @kindex -z muldefs
 @item --allow-multiple-definition
This page took 0.029884 seconds and 4 git commands to generate.