summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorH.J. Lu <hjl.tools@gmail.com>2016-03-02 08:48:33 -0800
committerH.J. Lu <hjl.tools@gmail.com>2016-03-02 12:17:01 -0800
commit3a37678369a3113672c9301bba9baca588603a05 (patch)
treef67277e0f521fc353017ff4cbbf01da7994af39b
parent7494161b47210a94b532a0f98d75e8cb084c21f9 (diff)
downloadbinutils-gdb-users/hjl/pr19579.tar.gz
Treat common symbol in executable as definitionusers/hjl/pr19579
Common symbol in executable is a definition, which overrides definition from shared objects. bfd/ PR ld/19579 * elflink.c (elf_link_add_object_symbols): Treat common symbol in executable as definition. ld/ PR ld/19579 * testsuite/ld-elf/pr19579a.c: New file. * testsuite/ld-elf/pr19579b.c: Likewise. * testsuite/ld-elf/shared.exp (build_tests): Prepare for PR ld/19579 test. (run_tests): Add a test for PR ld/19579.
-rw-r--r--bfd/elflink.c4
-rw-r--r--ld/testsuite/ld-elf/pr19579a.c13
-rw-r--r--ld/testsuite/ld-elf/pr19579b.c7
-rw-r--r--ld/testsuite/ld-elf/shared.exp9
4 files changed, 33 insertions, 0 deletions
diff --git a/bfd/elflink.c b/bfd/elflink.c
index 0e3abff5ce4..6c8f948a1d7 100644
--- a/bfd/elflink.c
+++ b/bfd/elflink.c
@@ -4332,6 +4332,10 @@ error_free_dyn:
h->root.u.c.p->alignment_power = align;
else
h->root.u.c.p->alignment_power = old_alignment;
+
+ /* Common symbol in executable is a definition. */
+ if (bfd_link_executable (info))
+ definition = TRUE;
}
if (is_elf_hash_table (htab))
diff --git a/ld/testsuite/ld-elf/pr19579a.c b/ld/testsuite/ld-elf/pr19579a.c
new file mode 100644
index 00000000000..9a47e26de2a
--- /dev/null
+++ b/ld/testsuite/ld-elf/pr19579a.c
@@ -0,0 +1,13 @@
+#include <stdio.h>
+
+int foo[1];
+
+extern int *foo_p (void);
+
+int
+main ()
+{
+ if (foo[0] == 0 && foo == foo_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..7cd8dc965ff
--- /dev/null
+++ b/ld/testsuite/ld-elf/pr19579b.c
@@ -0,0 +1,7 @@
+int foo[2];
+
+int *
+foo_p (void)
+{
+ return foo;
+}
diff --git a/ld/testsuite/ld-elf/shared.exp b/ld/testsuite/ld-elf/shared.exp
index 678ab1bb31f..7c7a1712731 100644
--- a/ld/testsuite/ld-elf/shared.exp
+++ b/ld/testsuite/ld-elf/shared.exp
@@ -279,6 +279,12 @@ set build_tests {
{"Build libpr19073.so"
"-shared -Wl,--version-script=pr19073.map tmpdir/pr19073a.o" "-fPIC"
{dummy.c} {{readelf {--dyn-syms --wide} pr19073.rd}} "libpr19073.so"}
+ {"Build pr19579a.o"
+ "-r -nostdlib" "-fPIE"
+ {pr19579a.c} {} "pr19073a.o"}
+ {"Build libpr19579.so"
+ "-shared" "-fPIC"
+ {pr19579b.c} {} "libpr19579.so"}
}
run_cc_link_tests $build_tests
@@ -432,6 +438,9 @@ set run_tests {
{"Run pr18458"
"tmpdir/libpr18458a.so tmpdir/libpr18458b.so -z now" ""
{pr18458c.c} "pr18458" "pass.out"}
+ {"Run pr19579"
+ "-pie -z text tmpdir/pr19579a.o tmpdir/libpr19579.so" ""
+ {dummy.c} "pr19579" "pass.out"}
}
# NetBSD ELF systems do not currently support the .*_array sections.