[llvm] [SystemZ][z/OS] Use section ordinal for temporary symbols (PR #226306)
Kai Nacke via llvm-commits
llvm-commits at lists.llvm.org
Fri Sep 25 06:42:03 PDT 2026
https://github.com/redstar updated https://github.com/llvm/llvm-project/pull/226306
>From 637d0afeada3378dbefbf785e50559a00fbfdf76 Mon Sep 17 00:00:00 2001
From: Kai Nacke <kai.peter.nacke at ibm.com>
Date: Thu, 24 Sep 2026 17:31:07 -0400
Subject: [PATCH] [SystemZ][z/OS] Use section ordinal for temporary symbols
A relocation involving a temporary symbol is interpreted as offset
of the symbol to the section begin. Currently, this is resolved via
the begin symbol of the section. However, that symbol may also have
the temporary flag set, and therefore has an index of 0. Since a
symbol is emitted of reach section, it is safe to use the ordinal
of the section instead, avoiding all issues with temporary symbols.
---
llvm/lib/MC/GOFFObjectWriter.cpp | 4 +---
llvm/test/CodeGen/SystemZ/zos-section-1.ll | 4 ++--
llvm/test/CodeGen/SystemZ/zos-section-2.ll | 4 ++--
llvm/test/CodeGen/SystemZ/zos-symbol-2.ll | 4 ++--
4 files changed, 7 insertions(+), 9 deletions(-)
diff --git a/llvm/lib/MC/GOFFObjectWriter.cpp b/llvm/lib/MC/GOFFObjectWriter.cpp
index 4545aea35cba5e..36407759dbc50c 100644
--- a/llvm/lib/MC/GOFFObjectWriter.cpp
+++ b/llvm/lib/MC/GOFFObjectWriter.cpp
@@ -599,9 +599,7 @@ void GOFFWriter::writeRelocations() {
for (auto &RelocEntry : Relocations) {
auto GetRptr = [](const MCSymbolGOFF *Sym) -> uint32_t {
if (Sym->isTemporary())
- return static_cast<MCSectionGOFF &>(Sym->getSection())
- .getBeginSymbol()
- ->getIndex();
+ return static_cast<MCSectionGOFF &>(Sym->getSection()).getOrdinal();
return Sym->getIndex();
};
diff --git a/llvm/test/CodeGen/SystemZ/zos-section-1.ll b/llvm/test/CodeGen/SystemZ/zos-section-1.ll
index f4b9667d5d9158..3f5056d2f9ec05 100644
--- a/llvm/test/CodeGen/SystemZ/zos-section-1.ll
+++ b/llvm/test/CodeGen/SystemZ/zos-section-1.ll
@@ -147,9 +147,9 @@ entry:
; The relocation data directory.
; CHECK: 0005f0 03 21 00 00 00 5c 00 00 02 00 04 00 00 00 00 00
-; CHECK-NEXT: 000600 00 08 00 00 00 02 00 00 00 04 60 00 00 00 04 00
+; CHECK-NEXT: 000600 00 02 00 00 00 02 00 00 00 04 60 00 00 00 04 00
; CHECK-NEXT: 000610 00 00 00 00 00 09 00 00 00 00 08 00 00 00 00 00
-; CHECK-NEXT: 000620 00 08 00 00 00 04 00 00 00 00 60 00 02 00 08 00
+; CHECK-NEXT: 000620 00 02 00 00 00 04 00 00 00 00 60 00 02 00 08 00
; CHECK-NEXT: 000630 00 00 00 00 00 09 20 70 01 00 08 00 00 00 00 00
; Continuation of the relocation data directory.
; CHECK-NEXT: 000640 03 22 00 00 0b 00 00 00 06 c0 00 01 00 08 00 00
diff --git a/llvm/test/CodeGen/SystemZ/zos-section-2.ll b/llvm/test/CodeGen/SystemZ/zos-section-2.ll
index dad9b4866f1552..eb6e64cd73aa18 100644
--- a/llvm/test/CodeGen/SystemZ/zos-section-2.ll
+++ b/llvm/test/CodeGen/SystemZ/zos-section-2.ll
@@ -177,9 +177,9 @@ source_filename = "test.ll"
; The relocation data directory
; CHECK: 000690 03 20 00 00 00 40 00 00 02 00 04 00 00 00 00 00
-; CHECK-NEXT: 0006a0 00 0e 00 00 00 02 00 00 00 04 60 00 00 00 04 00
+; CHECK-NEXT: 0006a0 00 02 00 00 00 02 00 00 00 04 60 00 00 00 04 00
; CHECK-NEXT: 0006b0 00 00 00 00 00 0f 00 00 00 00 08 00 00 00 00 00
-; CHECK-NEXT: 0006c0 00 0e 00 00 00 04 00 00 00 00 60 00 02 00 08 00
+; CHECK-NEXT: 0006c0 00 02 00 00 00 04 00 00 00 00 60 00 02 00 08 00
; CHECK-NEXT: 0006d0 00 00 00 00 00 0f 00 00 00 00 00 00 00 00 00 00
; End record.
diff --git a/llvm/test/CodeGen/SystemZ/zos-symbol-2.ll b/llvm/test/CodeGen/SystemZ/zos-symbol-2.ll
index c06a33f5fcb237..9d3133b29ee6a6 100644
--- a/llvm/test/CodeGen/SystemZ/zos-symbol-2.ll
+++ b/llvm/test/CodeGen/SystemZ/zos-symbol-2.ll
@@ -51,9 +51,9 @@ entry:
; .1 is flag (record is continued)
; 00 is version
; CHECKREL: 000690 03 21 00 00 00 60 00 00 02 00 04 00 00 00 00 00
-; CHECKREL-NEXT: 0006a0 00 0b 00 00 00 02 00 00 00 04 60 00 00 00 04 00
+; CHECKREL-NEXT: 0006a0 00 02 00 00 00 02 00 00 00 04 60 00 00 00 04 00
; CHECKREL-NEXT: 0006b0 00 00 00 00 00 0c 00 00 00 00 08 00 00 00 00 00
-; CHECKREL-NEXT: 0006c0 00 0b 00 00 00 04 00 00 00 00 60 00 02 00 08 00
+; CHECKREL-NEXT: 0006c0 00 02 00 00 00 04 00 00 00 00 60 00 02 00 08 00
; CHECKREL-NEXT: 0006d0 00 00 00 00 00 0c 20 00 00 00 08 00 00 00 00 00
; Continuation of relocation data directory.
; 03 is prefix byte
More information about the llvm-commits
mailing list