[lld] [SystemZ,test] Cover non-preemptible PLTOFF (PR #195600)

Fangrui Song via llvm-commits llvm-commits at lists.llvm.org
Mon May 4 00:15:42 PDT 2026


https://github.com/MaskRay created https://github.com/llvm/llvm-project/pull/195600

R_390_PLTOFF{16,32,64} against a non-preemptible (hidden) symbol takes
fromPlt(R_PLT_GOTREL) → R_GOTREL in RelocScan::process so the relocation
resolves to symbol - .got with no PLT entry. Add tests to fix the
the test gap from the initial SystemZ port (fe3406e349884e4ef61480dd0607f1e237102c74).

>From 71c065dbd012f4dc82c9b6743ef026402b37d9a0 Mon Sep 17 00:00:00 2001
From: Fangrui Song <i at maskray.me>
Date: Mon, 4 May 2026 00:10:48 -0700
Subject: [PATCH] [SystemZ,test] Cover non-preemptible PLTOFF
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

R_390_PLTOFF{16,32,64} against a non-preemptible (hidden) symbol takes
fromPlt(R_PLT_GOTREL) → R_GOTREL in RelocScan::process so the relocation
resolves to symbol - .got with no PLT entry. Add tests to fix the
the test gap from the initial SystemZ port (fe3406e349884e4ef61480dd0607f1e237102c74).
---
 lld/test/ELF/systemz-reloc-gotrel.s | 39 +++++++++++++++++++++++------
 1 file changed, 31 insertions(+), 8 deletions(-)

diff --git a/lld/test/ELF/systemz-reloc-gotrel.s b/lld/test/ELF/systemz-reloc-gotrel.s
index 46669ecfa7fd0..de5121b1242c3 100644
--- a/lld/test/ELF/systemz-reloc-gotrel.s
+++ b/lld/test/ELF/systemz-reloc-gotrel.s
@@ -2,7 +2,7 @@
 # RUN: llvm-mc -filetype=obj -triple=s390x-unknown-linux %s -o %t.o
 # RUN: ld.lld -shared %t.o -soname=t.so -o %t.so
 
-# RUN: llvm-readelf -S -s -x .data %t.so | FileCheck %s
+# RUN: llvm-readelf -S -s -x .data -x .data1 %t.so | FileCheck %s
 
 # CHECK: Section Headers:
 # CHECK: .plt PROGBITS 0000000000001290
@@ -10,27 +10,50 @@
 
 # CHECK: Symbol table '.symtab'
 # CHECK: 0000000000001288 {{.*}}  bar
+# CHECK: 000000000000128a {{.*}}  baz
 
-## Note: foo is the first (and only) PLT entry, which resides at .plt + 32
-## PLTOFF (foo) is (.plt + 32) - .got == 0x12b0 - 0x2390 == 0xffffef20
-## GOTOFF (bar) is bar - .got == 0x1288 - 0x2390 == 0xffffeef8
+## .data holds relocations against non-preemptible symbols (link-time
+## constants): GOTOFF (bar) and PLTOFF (baz). For PLTOFF (baz) the scan
+## rewrites R_PLT_GOTREL → R_GOTREL via fromPlt so the result is
+## baz - .got, not the offset of a PLT entry.
+## GOTOFF (bar) = bar - .got = 0x1288 - 0x2390 = 0xffffeef8
+## PLTOFF (baz) = baz - .got = 0x128a - 0x2390 = 0xffffeefa
 # CHECK: Hex dump of section '.data':
-# CHECK-NEXT: eef8ef20 ffffeef8 ffffef20 ffffffff
-# CHECK-NEXT: ffffeef8 ffffffff ffffef20
+# CHECK-NEXT: eef8eefa ffffeef8 ffffeefa ffffffff
+# CHECK-NEXT: ffffeef8 ffffffff ffffeefa
+
+## .data1 holds relocations against the preemptible foo, which uses the
+## first (and only) PLT entry at .plt + 32.
+## PLTOFF (foo) = (.plt + 32) - .got = 0x12b0 - 0x2390 = 0xffffef20
+# CHECK: Hex dump of section '.data1':
+# CHECK-NEXT: ef20ffff ef20ffff ffffffff ef20
 
 bar:
   br %r14
 
+.hidden baz
+.globl baz
+baz:
+  br %r14
+
 .data
 .reloc ., R_390_GOTOFF16, bar
 .space 2
-.reloc ., R_390_PLTOFF16, foo
+.reloc ., R_390_PLTOFF16, baz
 .space 2
 .reloc ., R_390_GOTOFF, bar
 .space 4
-.reloc ., R_390_PLTOFF32, foo
+.reloc ., R_390_PLTOFF32, baz
 .space 4
 .reloc ., R_390_GOTOFF64, bar
 .space 8
+.reloc ., R_390_PLTOFF64, baz
+.space 8
+
+.section .data1,"aw"
+.reloc ., R_390_PLTOFF16, foo
+.space 2
+.reloc ., R_390_PLTOFF32, foo
+.space 4
 .reloc ., R_390_PLTOFF64, foo
 .space 8



More information about the llvm-commits mailing list