From f4ab0e2d1d4e14cfdddf46ac846c48ae55f4e14a Mon Sep 17 00:00:00 2001 From: "H.J. Lu" Date: Tue, 28 Jun 2016 08:08:04 -0700 Subject: [PATCH] Skip version check for unreferenced and undefined symbol 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 | 6 ++++++ bfd/elflink.c | 3 ++- ld/ChangeLog | 6 ++++++ ld/testsuite/ld-gc/gc.exp | 15 +++++++++++++++ ld/testsuite/ld-gc/pr20306.c | 2 ++ ld/testsuite/ld-gc/pr20306.d | 3 +++ 6 files changed, 34 insertions(+), 1 deletion(-) create mode 100644 ld/testsuite/ld-gc/pr20306.c create mode 100644 ld/testsuite/ld-gc/pr20306.d diff --git a/bfd/ChangeLog b/bfd/ChangeLog index 8ad7d0d49b1..9e2534e03b0 100644 --- a/bfd/ChangeLog +++ b/bfd/ChangeLog @@ -1,3 +1,9 @@ +2016-06-28 H.J. Lu + + PR ld/20306 + * elflink.c (elf_link_check_versioned_symbol): Return false + for unreferenced undefined symbol. + 2016-06-28 Nick Clifton * elf32-bfin.c (bfin_adjust_dynamic_symbol): Fail if a COPY reloc diff --git a/bfd/elflink.c b/bfd/elflink.c index ad8493b3a90..3e249400f67 100644 --- a/bfd/elflink.c +++ b/bfd/elflink.c @@ -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; diff --git a/ld/ChangeLog b/ld/ChangeLog index 631fec5aef2..b7a5fd74afc 100644 --- a/ld/ChangeLog +++ b/ld/ChangeLog @@ -1,3 +1,9 @@ +2016-06-28 H.J. Lu + + * testsuite/ld-gc/gc.exp: Run pr20306 test. + * ld-gc/pr20306.c: New file. + * ld-gc/pr20306.d: Likewise. + 2016-06-28 Nick Clifton * testsuite/ld-elf/comm-data.exp: Expect comm-data2 test to fail diff --git a/ld/testsuite/ld-gc/gc.exp b/ld/testsuite/ld-gc/gc.exp index ffc619c61d2..a6f3e13edce 100644 --- a/ld/testsuite/ld-gc/gc.exp +++ b/ld/testsuite/ld-gc/gc.exp @@ -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 index 00000000000..0968c73aa5e --- /dev/null +++ b/ld/testsuite/ld-gc/pr20306.c @@ -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 index 00000000000..07cc8e8a4a8 --- /dev/null +++ b/ld/testsuite/ld-gc/pr20306.d @@ -0,0 +1,3 @@ +#source: dummy.s +#ld: -u foo --gc-sections tmpdir/libpr20306.so +#error: .* generated: undefined reference to `foo' -- 2.30.2