summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorH.J. Lu <hjl.tools@gmail.com>2016-03-09 05:59:20 -0800
committerH.J. Lu <hjl.tools@gmail.com>2016-03-09 05:59:31 -0800
commit1134e6ce012575e6d0e99933d0d29cc7978af9af (patch)
treef196f9e0f5930bb6b27d87c3fa5f48fce56345cb
parent343a405c03ce478634d8ce5a38faae832d39b361 (diff)
downloadbinutils-gdb-1134e6ce012575e6d0e99933d0d29cc7978af9af.tar.gz
Treat common symbol in executable as definition
Common symbol in executable is a definition, which overrides definition from shared objects. When linker sees a new definition from a shared object, the new dynamic definition should be overridden by the previous common symbol in executable. Backport from master bfd/ PR ld/19579 * elflink.c (_bfd_elf_merge_symbol): Group common symbol checking together. * elflink.c (_bfd_elf_merge_symbol): Treat common symbol in executable as definition if the new definition comes from a shared library. ld/ PR ld/19579 * testsuite/ld-elf/pr19579a.c: New file. * testsuite/ld-elf/pr19579b.c: Likewise. * testsuite/ld-elf/shared.exp: Run PR ld/19579 test.
-rw-r--r--bfd/ChangeLog15
-rw-r--r--bfd/elflink.c7
-rw-r--r--ld/ChangeLog10
-rw-r--r--ld/testsuite/ld-elf/pr19579a.c15
-rw-r--r--ld/testsuite/ld-elf/pr19579b.c14
-rw-r--r--ld/testsuite/ld-elf/shared.exp24
6 files changed, 83 insertions, 2 deletions
diff --git a/bfd/ChangeLog b/bfd/ChangeLog
index 0a08b556384..a8beeccbdba 100644
--- a/bfd/ChangeLog
+++ b/bfd/ChangeLog
@@ -1,3 +1,18 @@
+2016-03-09 H.J. Lu <hongjiu.lu@intel.com>
+
+ PR ld/19579
+ Backport from master
+ 2016-03-08 H.J. Lu <hongjiu.lu@intel.com>
+
+ * elflink.c (_bfd_elf_merge_symbol): Group common symbol checking
+ together.
+
+ 2016-03-04 H.J. Lu <hongjiu.lu@intel.com>
+
+ * elflink.c (_bfd_elf_merge_symbol): Treat common symbol in
+ executable as definition if the new definition comes from a
+ shared library.
+
2016-03-09 Nick Clifton <nickc@redhat.com>
Alan Modra <amodra@gmail.com>
diff --git a/bfd/elflink.c b/bfd/elflink.c
index 8fcaaddfd44..842e85ba741 100644
--- a/bfd/elflink.c
+++ b/bfd/elflink.c
@@ -1485,13 +1485,16 @@ _bfd_elf_merge_symbol (bfd *abfd,
represent variables; this can cause confusion in principle, but
any such confusion would seem to indicate an erroneous program or
shared library. We also permit a common symbol in a regular
- object to override a weak symbol in a shared object. */
+ object to override a weak symbol in a shared object. A common
+ symbol in executable also overrides a symbol in a shared object. */
if (newdyn
&& newdef
&& (olddef
|| (h->root.type == bfd_link_hash_common
- && (newweak || newfunc))))
+ && (newweak
+ || newfunc
+ || (!olddyn && bfd_link_executable (info))))))
{
*override = TRUE;
newdef = FALSE;
diff --git a/ld/ChangeLog b/ld/ChangeLog
index 1ee2dfa392d..2fa9ad37636 100644
--- a/ld/ChangeLog
+++ b/ld/ChangeLog
@@ -1,3 +1,13 @@
+2016-03-09 H.J. Lu <hongjiu.lu@intel.com>
+
+ Backport from master
+ 2016-03-04 H.J. Lu <hongjiu.lu@intel.com>
+
+ PR ld/19579
+ * testsuite/ld-elf/pr19579a.c: New file.
+ * testsuite/ld-elf/pr19579b.c: Likewise.
+ * testsuite/ld-elf/shared.exp: Run PR ld/19579 test.
+
2016-03-04 H.J. Lu <hongjiu.lu@intel.com>
Backport from master
diff --git a/ld/testsuite/ld-elf/pr19579a.c b/ld/testsuite/ld-elf/pr19579a.c
new file mode 100644
index 00000000000..e4a6eb1ea9b
--- /dev/null
+++ b/ld/testsuite/ld-elf/pr19579a.c
@@ -0,0 +1,15 @@
+#include <stdio.h>
+
+int foo[1];
+int bar[2];
+
+extern int *foo_p (void);
+extern int *bar_p (void);
+
+int
+main ()
+{
+ if (foo[0] == 0 && foo == foo_p () && bar[0] == 0 && bar == bar_p ())
+ printf ("PASS\n");
+ return 0;
+}
diff --git a/ld/testsuite/ld-elf/pr19579b.c b/ld/testsuite/ld-elf/pr19579b.c
new file mode 100644
index 00000000000..d9065458ed9
--- /dev/null
+++ b/ld/testsuite/ld-elf/pr19579b.c
@@ -0,0 +1,14 @@
+int foo[2];
+int bar[2] = { -1, -1 };
+
+int *
+foo_p (void)
+{
+ return foo;
+}
+
+int *
+bar_p (void)
+{
+ return bar;
+}
diff --git a/ld/testsuite/ld-elf/shared.exp b/ld/testsuite/ld-elf/shared.exp
index 731eef30911..b8c12cb1f36 100644
--- a/ld/testsuite/ld-elf/shared.exp
+++ b/ld/testsuite/ld-elf/shared.exp
@@ -524,6 +524,21 @@ if { [istarget *-*-linux*]
{} \
"libpr2404b.a" \
] \
+ [list \
+ "Build pr19579a.o" \
+ "" "-fPIE" \
+ {pr19579a.c} \
+ {} \
+ "libpr19579a.a" \
+ ] \
+ [list \
+ "Build libpr19579.so" \
+ "-shared" \
+ "-fPIC" \
+ {pr19579b.c} \
+ {} \
+ "libpr19579.so" \
+ ] \
]
run_ld_link_exec_tests [] [list \
[list \
@@ -580,5 +595,14 @@ if { [istarget *-*-linux*]
"pass.out" \
"-O2 -fPIC -I../bfd" \
] \
+ [list \
+ "Run pr19579" \
+ "-pie -z text tmpdir/pr19579a.o tmpdir/libpr19579.so" \
+ "" \
+ {dummy.c} \
+ "pr19579" \
+ "pass.out" \
+ "-fPIE" \
+ ] \
]
}