This is the mail archive of the
binutils@sourceware.org
mailing list for the binutils project.
[PATCH] PR ld/20306: Skip version check for unreferenced and undefined symbol
- From: "H.J. Lu" <hongjiu dot lu at intel dot com>
- To: binutils at sourceware dot org
- Date: Tue, 28 Jun 2016 06:37:18 -0700
- Subject: [PATCH] PR ld/20306: Skip version check for unreferenced and undefined symbol
- Authentication-results: sourceware.org; auth=none
- Reply-to: "H.J. Lu" <hjl dot tools at gmail dot com>
No need to check version if symbol is unreferenced and undefined.
OK for trunk?
H.J.
---
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/elflink.c | 3 ++-
ld/testsuite/ld-gc/gc.exp | 11 +++++++++++
ld/testsuite/ld-gc/pr20306.c | 2 ++
ld/testsuite/ld-gc/pr20306.d | 3 +++
4 files changed, 18 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/elflink.c b/bfd/elflink.c
index ad8493b..3e24940 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/testsuite/ld-gc/gc.exp b/ld/testsuite/ld-gc/gc.exp
index ffc619c..871bb5b 100644
--- a/ld/testsuite/ld-gc/gc.exp
+++ b/ld/testsuite/ld-gc/gc.exp
@@ -118,6 +118,17 @@ if { [is_elf_format] && [check_shared_lib_support] } then {
run_dump_test "personality"
}
run_dump_test "pr18223"
+ run_cc_link_tests [list \
+ [list \
+ "Build libpr20306.so" \
+ "-shared" \
+ "-fPIC" \
+ {pr20306.c} \
+ {} \
+ "libpr20306.so" \
+ ] \
+ ]
+ run_dump_test "pr20306"
}
if { [is_remote host] || [which $CC] != 0 } {
diff --git a/ld/testsuite/ld-gc/pr20306.c b/ld/testsuite/ld-gc/pr20306.c
new file mode 100644
index 0000000..0968c73
--- /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 0000000..07cc8e8
--- /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.7.4