aboutsummaryrefslogtreecommitdiff
path: root/ld
diff options
context:
space:
mode:
authorAlan Modra <amodra@gmail.com>2020-09-08 13:02:31 +0930
committerAlan Modra <amodra@gmail.com>2020-09-08 22:30:38 +0930
commit7ba115508aa02ffbb01a09613b5dffdd0c6563e3 (patch)
tree9a0251fdea1dd80de80d22b01ca2172b8fab0b71 /ld
parent7ade7fba756326c5f35f53a8e2d46443c6bab73f (diff)
downloadfsf-binutils-gdb-7ba115508aa02ffbb01a09613b5dffdd0c6563e3.zip
fsf-binutils-gdb-7ba115508aa02ffbb01a09613b5dffdd0c6563e3.tar.gz
fsf-binutils-gdb-7ba115508aa02ffbb01a09613b5dffdd0c6563e3.tar.bz2
PR26580, Size and alignment of commons vs as-needed shared lib
Two pieces to this puzzle: 1) Revert HJ's fix for PR13250 so that size and alignment isn't sticky, instead attack the real underlying problem that _bfd_generic_link_add_one_symbol does the wrong thing in making a common section in a shared library bfd. 2) Save and restore common u.c.p fields, which hold the section and alignment. A better fix for (2) would be to throw away all of that horrible code saving and restoring the hash table when loading as-needed library symbols, and instead do a scan over as-needed library symbols before adding anything. bfd/ PR 13250 PR 26580 * elflink.c (_bfd_elf_merge_symbol): Make "override" a bfd**. Return oldbfd in override when old common should override new common. (_bfd_elf_add_default_symbol): Adjust to suit. (elf_link_add_object_symbols): Likewise. Pass "override" to _bfd_generic_link_add_one_symbol. Save and restore common u.c.p field for --as-needed shared libraries. Revert pr13250 changes. ld/ * testsuite/ld-elf/pr26580-a.s, * testsuite/ld-elf/pr26580-b.s, * testsuite/ld-elf/pr26580-1.sd, * testsuite/ld-elf/pr26580-2.sd: New tests * testsuite/ld-elf/comm-data.exp: Run new tests. * testsuite/ld-elf/pr26580-a.c, * testsuite/ld-elf/pr26580-b.c, * testsuite/ld-elf/pr26580-3.out, * testsuite/ld-elf/pr26580-4.out: New tests. * testsuite/ld-elf/shared.exp: Run new tests.
Diffstat (limited to 'ld')
-rw-r--r--ld/ChangeLog13
-rw-r--r--ld/testsuite/ld-elf/comm-data.exp44
-rw-r--r--ld/testsuite/ld-elf/pr26580-1.sd4
-rw-r--r--ld/testsuite/ld-elf/pr26580-2.sd4
-rw-r--r--ld/testsuite/ld-elf/pr26580-3.out2
-rw-r--r--ld/testsuite/ld-elf/pr26580-4.out2
-rw-r--r--ld/testsuite/ld-elf/pr26580-a.c20
-rw-r--r--ld/testsuite/ld-elf/pr26580-a.s10
-rw-r--r--ld/testsuite/ld-elf/pr26580-b.c3
-rw-r--r--ld/testsuite/ld-elf/pr26580-b.s10
-rw-r--r--ld/testsuite/ld-elf/shared.exp11
11 files changed, 113 insertions, 10 deletions
diff --git a/ld/ChangeLog b/ld/ChangeLog
index 0a11b79..4b42f05 100644
--- a/ld/ChangeLog
+++ b/ld/ChangeLog
@@ -1,3 +1,16 @@
+2020-09-08 Alan Modra <amodra@gmail.com>
+
+ * testsuite/ld-elf/pr26580-a.s,
+ * testsuite/ld-elf/pr26580-b.s,
+ * testsuite/ld-elf/pr26580-1.sd,
+ * testsuite/ld-elf/pr26580-2.sd: New tests
+ * testsuite/ld-elf/comm-data.exp: Run new tests.
+ * testsuite/ld-elf/pr26580-a.c,
+ * testsuite/ld-elf/pr26580-b.c,
+ * testsuite/ld-elf/pr26580-3.out,
+ * testsuite/ld-elf/pr26580-4.out: New tests.
+ * testsuite/ld-elf/shared.exp: Run new tests.
+
2020-09-04 Alan Modra <amodra@gmail.com>
* testsuite/ld-plugin/lto.exp: Don't run pr15146 tests.
diff --git a/ld/testsuite/ld-elf/comm-data.exp b/ld/testsuite/ld-elf/comm-data.exp
index 87ae3b2..16b8e2b 100644
--- a/ld/testsuite/ld-elf/comm-data.exp
+++ b/ld/testsuite/ld-elf/comm-data.exp
@@ -48,6 +48,16 @@ if { [istarget "mips*vr4100*-*-elf*"] \
append LFLAGS " -call_shared"
}
+# Set the pointer size according to the ELF flavor.
+set AFLAGS ""
+if [is_elf64 "tmpdir/libcomm-data.so"] {
+ append AFLAGS " --defsym ELF64=1"
+}
+# HPUX targets use a different .comm syntax.
+if [istarget "*-*-hpux*"] {
+ append AFLAGS " --defsym HPUX=1"
+}
+
set testname "Common symbol override test"
# Define a global symbol.
@@ -62,18 +72,16 @@ run_ld_link_tests [list \
} \
"libcomm-data.so" \
] \
+ [list \
+ "libpr26580-1.so" \
+ "$LFLAGS -shared" "" \
+ "$AFLAGS_PIC $AFLAGS" \
+ { pr26580-b.s } \
+ { } \
+ "libpr26580-1.so" \
+ ] \
]
-# Set the pointer size according to the ELF flavor.
-set AFLAGS ""
-if [is_elf64 "tmpdir/libcomm-data.so"] {
- append AFLAGS " --defsym ELF64=1"
-}
-# HPUX targets use a different .comm syntax.
-if [istarget "*-*-hpux*"] {
- append AFLAGS " --defsym HPUX=1"
-}
-
# bfin-elf does not currently support copy relocs.
setup_xfail "bfin-*-*"
clear_xfail "bfin-*-linux-uclibc*"
@@ -113,4 +121,20 @@ run_ld_link_tests [list \
} \
"comm-data3b" \
] \
+ [list \
+ "pr26580-1" \
+ "$LFLAGS --as-needed -Ltmpdir -lpr26580-1" "" \
+ "$AFLAGS" \
+ { pr26580-a.s } \
+ { {readelf -s pr26580-1.sd} } \
+ "pr26580-1" \
+ ] \
+ [list \
+ "pr26580-2" \
+ "$LFLAGS --no-as-needed -Ltmpdir -lpr26580-1" "" \
+ "$AFLAGS" \
+ { pr26580-a.s } \
+ { {readelf -s pr26580-2.sd} } \
+ "pr26580-2" \
+ ] \
]
diff --git a/ld/testsuite/ld-elf/pr26580-1.sd b/ld/testsuite/ld-elf/pr26580-1.sd
new file mode 100644
index 0000000..b5adab0
--- /dev/null
+++ b/ld/testsuite/ld-elf/pr26580-1.sd
@@ -0,0 +1,4 @@
+
+#...
+.* 1 OBJECT GLOBAL DEFAULT .* one
+#pass
diff --git a/ld/testsuite/ld-elf/pr26580-2.sd b/ld/testsuite/ld-elf/pr26580-2.sd
new file mode 100644
index 0000000..265b880
--- /dev/null
+++ b/ld/testsuite/ld-elf/pr26580-2.sd
@@ -0,0 +1,4 @@
+
+#...
+.* 8 OBJECT GLOBAL DEFAULT .* one
+#pass
diff --git a/ld/testsuite/ld-elf/pr26580-3.out b/ld/testsuite/ld-elf/pr26580-3.out
new file mode 100644
index 0000000..566696f
--- /dev/null
+++ b/ld/testsuite/ld-elf/pr26580-3.out
@@ -0,0 +1,2 @@
+library not loaded
+alignment 1
diff --git a/ld/testsuite/ld-elf/pr26580-4.out b/ld/testsuite/ld-elf/pr26580-4.out
new file mode 100644
index 0000000..d91deea
--- /dev/null
+++ b/ld/testsuite/ld-elf/pr26580-4.out
@@ -0,0 +1,2 @@
+library loaded
+alignment 8
diff --git a/ld/testsuite/ld-elf/pr26580-a.c b/ld/testsuite/ld-elf/pr26580-a.c
new file mode 100644
index 0000000..5557997
--- /dev/null
+++ b/ld/testsuite/ld-elf/pr26580-a.c
@@ -0,0 +1,20 @@
+#include <stdio.h>
+
+extern void __attribute__ ((weak)) foo (void);
+
+char x, y, z;
+
+long
+lowest_align (void *a, void *b, void *c)
+{
+ unsigned long bits = (long) a | (long) b | (long) c;
+ return bits & -bits;
+}
+
+int
+main (void)
+{
+ printf ("library %sloaded\n", &foo ? "" : "not ");
+ printf ("alignment %ld\n", lowest_align (&x, &y, &z));
+ return 0;
+}
diff --git a/ld/testsuite/ld-elf/pr26580-a.s b/ld/testsuite/ld-elf/pr26580-a.s
new file mode 100644
index 0000000..3b70ccc
--- /dev/null
+++ b/ld/testsuite/ld-elf/pr26580-a.s
@@ -0,0 +1,10 @@
+ .text
+ .globl _start
+ .globl __start
+_start:
+__start:
+ .ifdef HPUX
+one .comm 1
+ .else
+ .comm one, 1, 1
+ .endif
diff --git a/ld/testsuite/ld-elf/pr26580-b.c b/ld/testsuite/ld-elf/pr26580-b.c
new file mode 100644
index 0000000..e7e13d6
--- /dev/null
+++ b/ld/testsuite/ld-elf/pr26580-b.c
@@ -0,0 +1,3 @@
+long long x, y, z;
+
+void foo (void) {}
diff --git a/ld/testsuite/ld-elf/pr26580-b.s b/ld/testsuite/ld-elf/pr26580-b.s
new file mode 100644
index 0000000..cb06378
--- /dev/null
+++ b/ld/testsuite/ld-elf/pr26580-b.s
@@ -0,0 +1,10 @@
+ .text
+ .globl _start
+ .globl __start
+_start:
+__start:
+ .ifdef HPUX
+one .comm 8
+ .else
+ .comm one, 8, 8
+ .endif
diff --git a/ld/testsuite/ld-elf/shared.exp b/ld/testsuite/ld-elf/shared.exp
index 87a40a3..6f53f9c 100644
--- a/ld/testsuite/ld-elf/shared.exp
+++ b/ld/testsuite/ld-elf/shared.exp
@@ -841,6 +841,9 @@ append build_tests {
{"Dump pr21978.so"
"-shared" "-fPIC -g -O2"
{pr21978a.c pr21978b.c} {{objdump {-Sl} pr21978.od}} "pr21978.so"}
+ {"libpr26580-2.so"
+ "-shared" "-fPIC -fcommon"
+ {pr26580-b.c} {} "libpr26580-2.so"}
}
run_cc_link_tests $build_tests
@@ -1044,6 +1047,14 @@ set run_tests [list \
[list "Run pr21964-3" \
"-Wl,--no-as-needed,-rpath,tmpdir tmpdir/pr21964-1a.so tmpdir/pr21964-1b.so tmpdir/pr21964-3a.so" "" \
{pr21964-3c.c} "pr21964-3" "pass.out" ] \
+ [list "pr26580-3" \
+ "" "" \
+ {pr26580-a.c} "pr26580-3" "pr26580-3.out" "-fcommon" "c" "" \
+ "-Wl,--as-needed tmpdir/libpr26580-2.so" ] \
+ [list "pr26580-4" \
+ "" "" \
+ {pr26580-a.c} "pr26580-4" "pr26580-4.out" "-fcommon" "c" "" \
+ "-Wl,--no-as-needed tmpdir/libpr26580-2.so" ] \
]
# NetBSD ELF systems do not currently support the .*_array sections.