Don't re-export common symbols
authorH.J. Lu <hjl.tools@gmail.com>
Mon, 5 Oct 2015 21:45:17 +0000 (14:45 -0700)
committerH.J. Lu <hjl.tools@gmail.com>
Mon, 5 Oct 2015 21:45:17 +0000 (14:45 -0700)
For ELF linker, a common symbol isn't a definition.  When we decide if a
symbol should be re-exported, we should check if the symbol isn't
undefined, not if it is a definition.

bfd/

PR ld/18914
* elflink.c (elf_link_add_object_symbols): Don't re-export a
symbol if it isn't undefined.

ld/testsuite/

PR ld/18914
* ld-elf/exclude.exp: Also check exclude_common.
* ld-elf/exclude2.s: Add exclude_common.

bfd/ChangeLog
bfd/elflink.c
ld/testsuite/ChangeLog
ld/testsuite/ld-elf/exclude.exp
ld/testsuite/ld-elf/exclude2.s

index 7674750f425f9865c7752867763f34f26b39eba5..db6fe6b07159fa24f083db576158e7ce476ad54f 100644 (file)
@@ -1,3 +1,9 @@
+2015-10-05  H.J. Lu  <hongjiu.lu@intel.com>
+
+       PR ld/18914
+       * elflink.c (elf_link_add_object_symbols): Don't re-export a
+       symbol if it isn't undefined.
+
 2015-10-04  H.J. Lu  <hongjiu.lu@intel.com>
 
        * config.bfd (targ_selvecs, targ64_selvecs): Add iamcu_elf32_vec,
index 90af6cfdfa0db957995614c3185a762ca302337e..94bb7109151f061d8a0e18f5668dc1476f594fa8 100644 (file)
@@ -4216,7 +4216,7 @@ error_free_dyn:
 
          /* If this symbol has default visibility and the user has
             requested we not re-export it, then mark it as hidden.  */
-         if (definition
+         if (!bfd_is_und_section (sec)
              && !dynamic
              && abfd->no_export
              && ELF_ST_VISIBILITY (isym->st_other) != STV_INTERNAL)
index b078d3a617a9ee145c7e877b517e49d93a251366..490aa503b2897f88c70ac77648bb2de5665c3a45 100644 (file)
@@ -1,3 +1,9 @@
+2015-10-05  H.J. Lu  <hongjiu.lu@intel.com>
+
+       PR ld/18914
+       * ld-elf/exclude.exp: Also check exclude_common.
+       * ld-elf/exclude2.s: Add exclude_common.
+
 2015-10-02  Renlin Li  <renlin.li@arm.com>
 
        * ld-aarch64/aarch64-elf.exp (tls-relax-large-le-ie): Run new test.
index 3b0539dbe16441d65923584401445bfb9df70106..1b96dac503899ea2a6870347840af3d55b39f61f 100644 (file)
@@ -83,7 +83,8 @@ if { [ld_simple_link $ld tmpdir/exclude.so "--shared tmpdir/exclude1.o -Ltmpdir
 
 if ![ld_nm $nm "-D" tmpdir/exclude.so] {
     unresolved $test2
-} elseif { [info exists nm_output(exclude_sym)] } {
+} elseif { [info exists nm_output(exclude_common)]
+           && [info exists nm_output(exclude_sym)] } {
     pass $test2
 } else {
     fail $test2
@@ -99,7 +100,8 @@ if { [ld_simple_link $ld tmpdir/exclude.so "--exclude-libs libexclude --shared t
 
 if ![ld_nm $nm "-D" tmpdir/exclude.so] {
     unresolved $test4
-} elseif { ! [info exists nm_output(exclude_sym)] } {
+} elseif { ! [info exists nm_output(exclude_common)]
+          &&  ! [info exists nm_output(exclude_sym)] } {
     pass $test4
 } else {
     fail $test4
@@ -109,6 +111,7 @@ if ![ld_nm $nm "-D" tmpdir/exclude.so] {
 
 if { [ld_simple_link $ld tmpdir/exclude.so "--exclude-libs libexclude.a --shared tmpdir/exclude1.o -Ltmpdir -lexclude"]
      && [ld_nm $nm "-D" tmpdir/exclude.so]
+     && ! [info exists nm_output(exclude_common)]
      && ! [info exists nm_output(exclude_sym)] } {
     pass $test5
 } else {
@@ -117,6 +120,7 @@ if { [ld_simple_link $ld tmpdir/exclude.so "--exclude-libs libexclude.a --shared
 
 if { [ld_simple_link $ld tmpdir/exclude.so "--exclude-libs ALL --shared tmpdir/exclude1.o -Ltmpdir -lexclude"]
      && [ld_nm $nm "-D" tmpdir/exclude.so]
+     && ! [info exists nm_output(exclude_common)]
      && ! [info exists nm_output(exclude_sym)] } {
     pass $test6
 } else {
@@ -125,6 +129,7 @@ if { [ld_simple_link $ld tmpdir/exclude.so "--exclude-libs ALL --shared tmpdir/e
 
 if { [ld_simple_link $ld tmpdir/exclude.so "--exclude-libs foo:libexclude.a --shared tmpdir/exclude1.o -Ltmpdir -lexclude"]
      && [ld_nm $nm "-D" tmpdir/exclude.so]
+     && ! [info exists nm_output(exclude_common)]
      && ! [info exists nm_output(exclude_sym)] } {
     pass $test7
 } else {
@@ -133,6 +138,7 @@ if { [ld_simple_link $ld tmpdir/exclude.so "--exclude-libs foo:libexclude.a --sh
 
 if { [ld_simple_link $ld tmpdir/exclude.so "--exclude-libs foo,libexclude.a --shared tmpdir/exclude1.o -Ltmpdir -lexclude"]
      && [ld_nm $nm "-D" tmpdir/exclude.so]
+     && ! [info exists nm_output(exclude_common)]
      && ! [info exists nm_output(exclude_sym)] } {
     pass $test8
 } else {
@@ -141,6 +147,7 @@ if { [ld_simple_link $ld tmpdir/exclude.so "--exclude-libs foo,libexclude.a --sh
 
 if { [ld_simple_link $ld tmpdir/exclude.so "--exclude-libs foo:bar --shared tmpdir/exclude1.o -Ltmpdir -lexclude"]
      && [ld_nm $nm "-D" tmpdir/exclude.so]
+     && [info exists nm_output(exclude_common)]
      && [info exists nm_output(exclude_sym)] } {
     pass $test9
 } else {
index e9b5819dadfea4b3dba1ffdf93ad5da95d54a3bf..f6ade79474b6d450c011370f6b64ef999b9ce0cd 100644 (file)
@@ -2,3 +2,4 @@
        .data
 exclude_sym:
        .long   0
+       .common exclude_common, 4, 4