Skip version check for unreferenced and undefined symbol
authorH.J. Lu <hjl.tools@gmail.com>
Tue, 28 Jun 2016 15:08:04 +0000 (08:08 -0700)
committerH.J. Lu <hjl.tools@gmail.com>
Tue, 28 Jun 2016 15:08:30 +0000 (08:08 -0700)
No need to check version if symbol is unreferenced and undefined.

bfd/

PR ld/20306
* elflink.c (elf_link_check_versioned_symbol): Return false
for unreferenced undefined symbol.

ld/testsuite/

* testsuite/ld-gc/gc.exp: Run pr20306 test.
* ld-gc/pr20306.c: New file.
* ld-gc/pr20306.d: Likewise.

bfd/ChangeLog
bfd/elflink.c
ld/ChangeLog
ld/testsuite/ld-gc/gc.exp
ld/testsuite/ld-gc/pr20306.c [new file with mode: 0644]
ld/testsuite/ld-gc/pr20306.d [new file with mode: 0644]

index 8ad7d0d49b1d441ddaabd756204228084de376b7..9e2534e03b0096f07b610a0454f2ac729d998fec 100644 (file)
@@ -1,3 +1,9 @@
+2016-06-28  H.J. Lu  <hongjiu.lu@intel.com>
+
+       PR ld/20306
+       * elflink.c (elf_link_check_versioned_symbol): Return false
+       for unreferenced undefined symbol.
+
 2016-06-28  Nick Clifton  <nickc@redhat.com>
 
        * elf32-bfin.c (bfin_adjust_dynamic_symbol): Fail if a COPY reloc
index ad8493b3a90317b5f3c7b54a6a2778d257da607a..3e249400f67f75f492c1a7f72b811965aa39995c 100644 (file)
@@ -9053,7 +9053,8 @@ elf_link_check_versioned_symbol (struct bfd_link_info *info,
     case bfd_link_hash_undefined:
     case bfd_link_hash_undefweak:
       abfd = h->root.u.undef.abfd;
-      if ((abfd->flags & DYNAMIC) == 0
+      if (abfd == NULL
+         || (abfd->flags & DYNAMIC) == 0
          || (elf_dyn_lib_class (abfd) & DYN_DT_NEEDED) == 0)
        return FALSE;
       break;
index 631fec5aef2be98df48b61bda1eb854c01904540..b7a5fd74afc5b9461980ba0fb8e85b105495bfe1 100644 (file)
@@ -1,3 +1,9 @@
+2016-06-28  H.J. Lu  <hongjiu.lu@intel.com>
+
+       * testsuite/ld-gc/gc.exp: Run pr20306 test.
+       * ld-gc/pr20306.c: New file.
+       * ld-gc/pr20306.d: Likewise.
+
 2016-06-28  Nick Clifton  <nickc@redhat.com>
 
        * testsuite/ld-elf/comm-data.exp: Expect comm-data2 test to fail
index ffc619c61d2ebbd4a5e054b7f030e18fd226dfbc..a6f3e13edce66a6f88ca0cebe584ca52ff4d9e94 100644 (file)
@@ -146,3 +146,18 @@ if { [is_remote host] || [which $CC] != 0 } {
     ld_compile "$CC $CFLAGS $cflags -O0" $srcdir/$subdir/pr19161-2.c tmpdir/pr19161-2.o
     run_dump_test "pr19161"
 }
+
+if { [is_elf_format] && [check_shared_lib_support] \
+     && ([is_remote host] || [which $CC] != 0) } {
+    run_cc_link_tests [list \
+       [list \
+           "Build libpr20306.so" \
+           "-shared" \
+           "-fPIC" \
+           {pr20306.c} \
+           {} \
+           "libpr20306.so" \
+       ] \
+    ]
+    run_dump_test "pr20306"
+}
diff --git a/ld/testsuite/ld-gc/pr20306.c b/ld/testsuite/ld-gc/pr20306.c
new file mode 100644 (file)
index 0000000..0968c73
--- /dev/null
@@ -0,0 +1,2 @@
+extern void foo();
+void bar() {foo();}
diff --git a/ld/testsuite/ld-gc/pr20306.d b/ld/testsuite/ld-gc/pr20306.d
new file mode 100644 (file)
index 0000000..07cc8e8
--- /dev/null
@@ -0,0 +1,3 @@
+#source: dummy.s
+#ld: -u foo --gc-sections tmpdir/libpr20306.so
+#error: .* generated: undefined reference to `foo'