aboutsummaryrefslogtreecommitdiff
path: root/ld
diff options
context:
space:
mode:
authorMichael Matz <matz@suse.de>2022-10-12 17:29:43 +0200
committerMichael Matz <matz@suse.de>2023-01-20 14:58:04 +0100
commitec15b12d0684b41f67b56623f6e9b5024bf08905 (patch)
tree1fb4110367f93c99af7e05f0bb4c1ad5f955fbb7 /ld
parent26ec71f5128af2da9bf859321f388f76ad04dfe0 (diff)
downloadbinutils-ec15b12d0684b41f67b56623f6e9b5024bf08905.zip
binutils-ec15b12d0684b41f67b56623f6e9b5024bf08905.tar.gz
binutils-ec15b12d0684b41f67b56623f6e9b5024bf08905.tar.bz2
Add testcase ld-elf/merge4
to check a situation that once failed with the new section merging when it mishandled offsets pointing into alignment padding in mergable string sections (i.e. pointing to zeros). It made bootstrap.exp fail but that depends on many factors to actually go wrong so this is a more explicit variant of it.
Diffstat (limited to 'ld')
-rw-r--r--ld/testsuite/ld-elf/elf.exp6
-rw-r--r--ld/testsuite/ld-elf/merge4.out3
-rw-r--r--ld/testsuite/ld-elf/merge4a.c23
-rw-r--r--ld/testsuite/ld-elf/merge4b.s23
4 files changed, 55 insertions, 0 deletions
diff --git a/ld/testsuite/ld-elf/elf.exp b/ld/testsuite/ld-elf/elf.exp
index a3a8994..1a160d0 100644
--- a/ld/testsuite/ld-elf/elf.exp
+++ b/ld/testsuite/ld-elf/elf.exp
@@ -607,4 +607,10 @@ run_ld_link_exec_tests [list \
] \
]
+set merge_exec_tests {
+ {"merge4" "" ""
+ {merge4a.c merge4b.s} "merge4" "merge4.out"}
+}
+run_ld_link_exec_tests $merge_exec_tests
+
catch "exec rm -f tmpdir/preinit tmpdir/init tmpdir/fini tmpdir/init-mixed" status
diff --git a/ld/testsuite/ld-elf/merge4.out b/ld/testsuite/ld-elf/merge4.out
new file mode 100644
index 0000000..92c1b71
--- /dev/null
+++ b/ld/testsuite/ld-elf/merge4.out
@@ -0,0 +1,3 @@
+1: foobar
+2:
+3: blabla
diff --git a/ld/testsuite/ld-elf/merge4a.c b/ld/testsuite/ld-elf/merge4a.c
new file mode 100644
index 0000000..133303e
--- /dev/null
+++ b/ld/testsuite/ld-elf/merge4a.c
@@ -0,0 +1,23 @@
+extern const char * getstr3(int);
+extern int printf (const char *, ...);
+
+extern const char *addr_of_str;
+extern const char *addr_of_str2;
+
+/* "foobar" needs to be a string literal, so that it's put into
+ a mergable string section, then merged with the "foobar" from merge4b.s
+ and then (when the linker is buggy) doesn't cover the additional
+ nul byte after "foobar" in the asm source (which addr_of_str2 is supposed
+ to point into. */
+const char * getstr3(int i)
+{
+ return i ? "blabla" : "foobar";
+}
+
+int main(void)
+{
+ printf ("1: %s\n", addr_of_str);
+ printf ("2: %s\n", addr_of_str2);
+ printf ("3: %s\n", getstr3(1));
+ return 0;
+}
diff --git a/ld/testsuite/ld-elf/merge4b.s b/ld/testsuite/ld-elf/merge4b.s
new file mode 100644
index 0000000..d4b66aa
--- /dev/null
+++ b/ld/testsuite/ld-elf/merge4b.s
@@ -0,0 +1,23 @@
+/* Check that pointing into padding zeros of string sections works. */
+ .section .rodata.str1.1,"aMS",@progbits,1
+ .string ""
+.LC0:
+ .string "foobar"
+1:
+ .string ""
+ .string "whatever"
+ .section .data
+ .globl addr_of_str
+ .type addr_of_str, @object
+addr_of_str:
+ .dc.a str
+ .globl addr_of_str2
+ .type addr_of_str2, @object
+addr_of_str2:
+ .dc.a 1b
+ .section .rodata
+ .type str, @object
+ .size str, 7
+str:
+ .string "foobar"
+ .section .note.GNU-stack,"",@progbits