aboutsummaryrefslogtreecommitdiff
path: root/ld
diff options
context:
space:
mode:
authorJens Remus <jremus@linux.ibm.com>2024-07-12 16:53:47 +0200
committerJens Remus <jremus@linux.ibm.com>2024-07-12 16:53:47 +0200
commit6f8b365b653dc9a7370b3bb906a945b5bf5f867c (patch)
treeb4b64b1751dbe4e3b61ed9d9fc1197821f8b799e /ld
parent83511d2679bbcc4b8d6ac42fb71cfbc35e77107e (diff)
downloadbinutils-6f8b365b653dc9a7370b3bb906a945b5bf5f867c.zip
binutils-6f8b365b653dc9a7370b3bb906a945b5bf5f867c.tar.gz
binutils-6f8b365b653dc9a7370b3bb906a945b5bf5f867c.tar.bz2
s390: Avoid reloc overflows on undefined weak symbols (cont)
This complements and reuses logic from Andreas Krebbel's commit 896a639babe2 ("s390: Avoid reloc overflows on undefined weak symbols"). Replace relative long addressing instructions of weak symbols, which will definitely resolve to zero, with either a load address of 0 or a a trapping insn. This prevents the PLT32DBL relocation from overflowing in case the binary will be loaded at 4GB or more. bfd/ * elf64-s390.c (elf_s390_relocate_section): Replace instructions using undefined weak symbols with relative addressing to avoid relocation overflows. ld/ * testsuite/ld-s390/s390.exp: Add new test. * testsuite/ld-s390/weakundef-2.s: New test. * testsuite/ld-s390/weakundef-2.dd: Likewise. Reported-by: Alexander Gordeev <agordeev@linux.ibm.com> Suggested-by: Ilya Leoshkevich <iii@linux.ibm.com> Suggested-by: Andreas Krebbel <krebbel@linux.ibm.com> Signed-off-by: Jens Remus <jremus@linux.ibm.com>
Diffstat (limited to 'ld')
-rw-r--r--ld/testsuite/ld-s390/s390.exp5
-rw-r--r--ld/testsuite/ld-s390/weakundef-2.dd17
-rw-r--r--ld/testsuite/ld-s390/weakundef-2.s17
3 files changed, 38 insertions, 1 deletions
diff --git a/ld/testsuite/ld-s390/s390.exp b/ld/testsuite/ld-s390/s390.exp
index eb9ea35..ac62d7a 100644
--- a/ld/testsuite/ld-s390/s390.exp
+++ b/ld/testsuite/ld-s390/s390.exp
@@ -95,9 +95,12 @@ set s390xtests {
"-m64" {pltoffset-1.s}
{{objdump "-dzrj.text --stop-address=16" pltoffset-1.dd}}
"pltoffset-1"}
- {"WEAKUNDEF1: overflow test"
+ {"WEAKUNDEF1: overflow test (PC32DBL)"
"-m elf64_s390 -dT 8GB.ld --no-error-rwx-segments" "" "-m64" {weakundef-1.s}
{{objdump "-dzrj.text" weakundef-1.dd}} "weakundef-1"}
+ {"WEAKUNDEF2: overflow test (PLT32DBL)"
+ "-m elf64_s390 -dT 8GB.ld --no-error-rwx-segments -no-pie" "" "-m64" {weakundef-2.s}
+ {{objdump "-dzrj.text" weakundef-2.dd}} "weakundef-2"}
}
if [istarget "s390-*-*"] {
diff --git a/ld/testsuite/ld-s390/weakundef-2.dd b/ld/testsuite/ld-s390/weakundef-2.dd
new file mode 100644
index 0000000..e7f0e22
--- /dev/null
+++ b/ld/testsuite/ld-s390/weakundef-2.dd
@@ -0,0 +1,17 @@
+tmpdir/weakundef-2: file format elf64-s390
+
+Disassembly of section .text:
+
+0+200000000 <foo>:
+.*: c0 10 00 00 00 12 [ ]*larl %r1,200000024 <d>
+.*: c0 10 00 00 00 10 [ ]*larl %r1,200000026 <wd>
+.*: e3 10 00 00 00 71 [ ]*lay %r1,0
+.*: c0 e5 00 00 00 09 [ ]*brasl %r14,200000024 <d>
+.*: c0 e5 00 00 00 07 [ ]*brasl %r14,200000026 <wd>
+.*: c0 f4 00 00 00 01 [ ]*jg .*
+
+0+200000024 <d>:
+.*: 07 fe [ ]*br %r14
+
+0+200000026 <wd>:
+.*: 07 fe [ ]*br %r14
diff --git a/ld/testsuite/ld-s390/weakundef-2.s b/ld/testsuite/ld-s390/weakundef-2.s
new file mode 100644
index 0000000..d147b53
--- /dev/null
+++ b/ld/testsuite/ld-s390/weakundef-2.s
@@ -0,0 +1,17 @@
+.text
+ .globl foo
+foo:
+ larl %r1,d@PLT
+ larl %r1,wd@PLT
+ larl %r1,wu@PLT
+ brasl %r14,d@PLT
+ brasl %r14,wd@PLT
+ brasl %r14,wu@PLT
+ .weak wu
+ .type d,@function
+d:
+ br %r14
+ .weak wd
+ .type wd,@function
+wd:
+ br %r14