aboutsummaryrefslogtreecommitdiff
path: root/ld
diff options
context:
space:
mode:
authorAndreas Krebbel <krebbel@linux.ibm.com>2024-02-27 14:01:41 +0100
committerAndreas Krebbel <krebbel@linux.ibm.com>2024-02-27 14:07:17 +0100
commit896a639babe2d883467978abce7a4c55bc9f00ed (patch)
treea34555d413cf1725e980564cef66f03bcfda3cfa /ld
parentd6a14e41381d0aa0a99c6796d3bd3677c80dfe06 (diff)
downloadgdb-896a639babe2d883467978abce7a4c55bc9f00ed.zip
gdb-896a639babe2d883467978abce7a4c55bc9f00ed.tar.gz
gdb-896a639babe2d883467978abce7a4c55bc9f00ed.tar.bz2
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, a NOP, or a trapping insn. This prevents the PC32DBL relocation from overflowing in case the binary will be loaded at 4GB or more. bfd/ChangeLog: * bfd/elf64-s390.c (elf_s390_relocate_section): Replace instructions using undefined weak symbols with relative addressing to avoid relocation overflows. ld/ChangeLog: * ld/testsuite/ld-s390/s390.exp: * ld/testsuite/ld-s390/8GB.ld: New test. * ld/testsuite/ld-s390/weakundef-1.dd: New test. * ld/testsuite/ld-s390/weakundef-1.s: New test.
Diffstat (limited to 'ld')
-rw-r--r--ld/testsuite/ld-s390/8GB.ld1
-rw-r--r--ld/testsuite/ld-s390/s390.exp3
-rw-r--r--ld/testsuite/ld-s390/weakundef-1.dd15
-rw-r--r--ld/testsuite/ld-s390/weakundef-1.s18
4 files changed, 37 insertions, 0 deletions
diff --git a/ld/testsuite/ld-s390/8GB.ld b/ld/testsuite/ld-s390/8GB.ld
new file mode 100644
index 0000000..7ab94cb
--- /dev/null
+++ b/ld/testsuite/ld-s390/8GB.ld
@@ -0,0 +1 @@
+SECTIONS { . = 0x200000000; }
diff --git a/ld/testsuite/ld-s390/s390.exp b/ld/testsuite/ld-s390/s390.exp
index 27bfdee..6b97b6c 100644
--- a/ld/testsuite/ld-s390/s390.exp
+++ b/ld/testsuite/ld-s390/s390.exp
@@ -85,6 +85,9 @@ set s390xtests {
"-m64" {pltoffset-1.s}
{{objdump "-dzrj.text --stop-address=16" pltoffset-1.dd}}
"pltoffset-1"}
+ {"WEAKUNDEF1: overflow test"
+ "-m elf64_s390 -dT 8GB.ld --no-error-rwx-segments" "" "-m64" {weakundef-1.s}
+ {{objdump "-dzrj.text" weakundef-1.dd}} "weakundef-1"}
}
if [istarget "s390-*-*"] {
diff --git a/ld/testsuite/ld-s390/weakundef-1.dd b/ld/testsuite/ld-s390/weakundef-1.dd
new file mode 100644
index 0000000..e514524
--- /dev/null
+++ b/ld/testsuite/ld-s390/weakundef-1.dd
@@ -0,0 +1,15 @@
+tmpdir/weakundef-1: file format elf64-s390
+
+Disassembly of section .text:
+
+.* <foo>:
+.*: c0 10 00 00 00 1e [ ]*larl %r1,20000003c <d>
+.*: c0 10 00 00 00 1f [ ]*larl %r1,200000044 <wd>
+.*: e3 10 00 00 00 71 [ ]*lay %r1,0
+.*: c0 f4 00 00 00 01 [ ]*jg .*
+.*: c0 f4 00 00 00 01 [ ]*jg .*
+.*: c0 f4 00 00 00 01 [ ]*jg .*
+.*: c0 f4 00 00 00 01 [ ]*jg .*
+.*: c0 f4 00 00 00 01 [ ]*jg .*
+.*: c0 f4 00 00 00 01 [ ]*jg .*
+.*: c0 04 00 00 00 00 [ ]*jgnop .*
diff --git a/ld/testsuite/ld-s390/weakundef-1.s b/ld/testsuite/ld-s390/weakundef-1.s
new file mode 100644
index 0000000..aeaef8d
--- /dev/null
+++ b/ld/testsuite/ld-s390/weakundef-1.s
@@ -0,0 +1,18 @@
+.text
+ .globl foo
+foo:
+ larl %r1,d
+ larl %r1,wd
+ larl %r1,wu
+ brasl %r1,wu
+ crl %r1,wu
+ lrl %r1,wu
+ strl %r1,wu
+ exrl %r1,wu
+ brcth %r1,wu
+ pfdrl %r1,wu
+ .weak wd
+ .weak wu
+.data
+d: .quad 0x123
+wd: .quad 0x123