This is the mail archive of the
binutils@sourceware.org
mailing list for the binutils project.
[commited, PATCH] PR ld/18718: Skip missing symbol version section check for executable
- From: "H.J. Lu" <hjl dot tools at gmail dot com>
- To: binutils at sourceware dot org
- Date: Sat, 25 Jul 2015 08:07:19 -0700
- Subject: [commited, PATCH] PR ld/18718: Skip missing symbol version section check for executable
- Authentication-results: sourceware.org; auth=none
Missing symbol version section is a run-time problem only if it will
be referenced dynamically at run-time. We should skip the check for
locally defined symbol, which isn't referenced by shared library, when
linking executable.
bfd/
PR ld/18718
* elflink.c (elf_link_output_extsym): Check symbol version
section check only if not linking executable, the symbol is
referenced by shared library or not locally defined.
ld/testsuite/
PR ld/18718
* ld-elf/pr18718.c: New file.
* ld-elf/shared.exp: Run tests for PR ld/18718.
---
bfd/elflink.c | 8 ++++++--
ld/testsuite/ld-elf/pr18718.c | 26 ++++++++++++++++++++++++
ld/testsuite/ld-elf/shared.exp | 45 ++++++++++++++++++++++++++++++++++++++++++
3 files changed, 77 insertions(+), 2 deletions(-)
create mode 100644 ld/testsuite/ld-elf/pr18718.c
diff --git a/bfd/elflink.c b/bfd/elflink.c
index b741e7e..ccb7ba2 100644
--- a/bfd/elflink.c
+++ b/bfd/elflink.c
@@ -9217,8 +9217,12 @@ elf_link_output_extsym (struct bfd_hash_entry *bh, void *data)
/* Since there is no version information in the dynamic string,
if there is no version info in symbol version section, we will
- have a run-time problem. */
- if (h->verinfo.verdef == NULL)
+ have a run-time problem if not linking executable, referenced
+ by shared library, or not locally defined. */
+ if (h->verinfo.verdef == NULL
+ && (!flinfo->info->executable
+ || h->ref_dynamic
+ || !h->def_regular))
{
char *p = strrchr (h->root.root.string, ELF_VER_CHR);
diff --git a/ld/testsuite/ld-elf/pr18718.c b/ld/testsuite/ld-elf/pr18718.c
new file mode 100644
index 0000000..de628ef
--- /dev/null
+++ b/ld/testsuite/ld-elf/pr18718.c
@@ -0,0 +1,26 @@
+#include <stdio.h>
+#include <bfd_stdint.h>
+
+extern void foo (void);
+
+void
+new_foo (void)
+{
+}
+
+__asm__(".symver new_foo, foo@@VERS_2.0");
+
+__attribute__ ((noinline, noclone))
+int
+bar (void)
+{
+ return (intptr_t) &foo == 0x12345678 ? 1 : 0;
+}
+
+int
+main(void)
+{
+ bar ();
+ printf("PASS\n");
+ return 0;
+}
diff --git a/ld/testsuite/ld-elf/shared.exp b/ld/testsuite/ld-elf/shared.exp
index bcbe8e2..92188f9 100644
--- a/ld/testsuite/ld-elf/shared.exp
+++ b/ld/testsuite/ld-elf/shared.exp
@@ -529,5 +529,50 @@ if { [istarget *-*-linux*]
"pr2404.out" \
"-fPIE" \
] \
+ [list \
+ "Run pr18718" \
+ "" \
+ "" \
+ { pr18718.c } \
+ "pr18718" \
+ "pass.out" \
+ "-I../bfd" \
+ ] \
+ [list \
+ "Run pr18718 with PIE (1)" \
+ "-pie" \
+ "" \
+ { pr18718.c } \
+ "pr18718pie1" \
+ "pass.out" \
+ "-fPIE -I../bfd" \
+ ] \
+ [list \
+ "Run pr18718 with PIE (2)" \
+ "" \
+ "" \
+ { pr18718.c } \
+ "pr18718pie2" \
+ "pass.out" \
+ "-fPIE -I../bfd" \
+ ] \
+ [list \
+ "Run pr18718 with PIC (1)" \
+ "" \
+ "" \
+ { pr18718.c } \
+ "pr18718pic1" \
+ "pass.out" \
+ "-fPIC -I../bfd" \
+ ] \
+ [list \
+ "Run pr18718 with PIC (2)" \
+ "-pie" \
+ "" \
+ { pr18718.c } \
+ "pr18718pic2" \
+ "pass.out" \
+ "-fPIC -I../bfd" \
+ ] \
]
}
--
2.4.3