]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commit
s390: Do not rewrite insns and their relocs in linker if --no-relax
authorJens Remus <jremus@linux.ibm.com>
Thu, 16 Oct 2025 09:09:06 +0000 (11:09 +0200)
committerJens Remus <jremus@linux.ibm.com>
Thu, 16 Oct 2025 09:09:06 +0000 (11:09 +0200)
commit5a7173cd46252fbbac5c7b30efebd2d66aad5eb3
tree612a0abf2f00e70b0b884f682383255ad7f0c938
parentbedc0be59330aaef361387481a073a725830adab
s390: Do not rewrite insns and their relocs in linker if --no-relax

Under certain conditions the linker rewrites:
- GOT access using lgrl to larl, changing the GOTENT to a PC32DBL reloc
- GOT access using lg to larl, changing the GOT20 to a PC32DBL reloc
- Relative long addressing instructions of weak symbols, which
  definitively resolve to zero to either (1) load address of zero,
  (2) a NOP, or (3) a trapping instruction, changing the relocation to
  a NONE reloc.

Suppress rewriting of non-TLS instructions and related relocations in
linker if option --no-relax is specified.  This aligns with LLVM linker
behavior on s390.

Like x86-64 do not actually enable the linker relaxation option by
default, as other targets would do using ENABLE_RELAXATION or
TARGET_ENABLE_RELAXATION in their linker emulation scripts.  Instead
perform linker instruction/relocation rewrites by default unless linker
option --no-relax is explicitly specified by the user.  This ensures no
functional change unless --no-relax is used.

bfd/
* elf64-s390.c (elf_s390_relocate_section): Do not rewrite
non-TLS instructions and related relocations if --no-relax.
* elf32-s390.c (elf_s390_relocate_section): Likewise.

ld/testsuite/
* ld-s390/s390.exp: New tests.  Same as gotreloc_*-1a and
weakundef-*a, but with linker option --no-relax, to verify
suppression of linker non-TLS insn and reloc rewrites.
* ld-s390/gotreloc_31-1b.dd: Likewise.
* ld-s390/gotreloc_31-no-pie-1b.dd: Likewise.
* ld-s390/gotreloc_64-no-pie-1b.dd: Likewise.
* ld-s390/gotreloc_64-norelro-1b.dd: Likewise.
* ld-s390/gotreloc_64-relro-1b.dd: Likewise.
* ld-s390/weakundef-1b.d: Likewise.  Check for expected reloc
overflows.
* ld-s390/weakundef-2b.d: Likewise.

Signed-off-by: Jens Remus <jremus@linux.ibm.com>
bfd/elf32-s390.c
bfd/elf64-s390.c
ld/testsuite/ld-s390/gotreloc_31-1b.dd [new file with mode: 0644]
ld/testsuite/ld-s390/gotreloc_31-no-pie-1b.dd [new file with mode: 0644]
ld/testsuite/ld-s390/gotreloc_64-no-pie-1b.dd [new file with mode: 0644]
ld/testsuite/ld-s390/gotreloc_64-norelro-1b.dd [new file with mode: 0644]
ld/testsuite/ld-s390/gotreloc_64-relro-1b.dd [new file with mode: 0644]
ld/testsuite/ld-s390/s390.exp
ld/testsuite/ld-s390/weakundef-1b.d [new file with mode: 0644]
ld/testsuite/ld-s390/weakundef-2b.d [new file with mode: 0644]