[llvm] [SystemZ][z/OS] Fix "relative immediate relocation section mismatch" (PR #222437)
Kai Nacke via llvm-commits
llvm-commits at lists.llvm.org
Thu Sep 10 06:48:08 PDT 2026
https://github.com/redstar updated https://github.com/llvm/llvm-project/pull/222437
>From 7a92cd5e3747fc602f5353b30fb27ae3aa56387f Mon Sep 17 00:00:00 2001
From: Kai Nacke <kai.peter.nacke at ibm.com>
Date: Wed, 9 Sep 2026 15:33:12 -0400
Subject: [PATCH] [SystemZ][z/OS] Fix error "relative immediate relocation
section mismatch"
Constants should go inside the text section, but this is not explicitly coded.
In the test case, the EH table is generated into a PR section. Then the
constant pool of function `fn_with_const_pool()` is emitted, which goes into
the PR section of the EH table insted of the code section. When the constant
is later referenced in the code, the relative offset cannot be calculated
because different sections are involved.
The fix is to explicitly return the text section for constants.
---
llvm/include/llvm/CodeGen/TargetLoweringObjectFileImpl.h | 3 +++
llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp | 6 ++++++
llvm/test/CodeGen/SystemZ/zos-eh.ll | 5 +++++
3 files changed, 14 insertions(+)
diff --git a/llvm/include/llvm/CodeGen/TargetLoweringObjectFileImpl.h b/llvm/include/llvm/CodeGen/TargetLoweringObjectFileImpl.h
index af6eb0269378a..e631d820eb637 100644
--- a/llvm/include/llvm/CodeGen/TargetLoweringObjectFileImpl.h
+++ b/llvm/include/llvm/CodeGen/TargetLoweringObjectFileImpl.h
@@ -333,6 +333,9 @@ class LLVM_ABI TargetLoweringObjectFileGOFF : public TargetLoweringObjectFile {
bool shouldPutJumpTableInFunctionSection(bool UsesLabelDifference,
const Function &F) const override;
+ MCSection *getSectionForConstant(const DataLayout &DL, SectionKind Kind,
+ const Constant *C, Align &Alignment,
+ const Function *F) const override;
MCSection *SelectSectionForGlobal(const GlobalObject *GO, SectionKind Kind,
const TargetMachine &TM) const override;
MCSection *getExplicitSectionGlobal(const GlobalObject *GO, SectionKind Kind,
diff --git a/llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp b/llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp
index 4643ef995afec..2fb44041c164e 100644
--- a/llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp
+++ b/llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp
@@ -2860,6 +2860,12 @@ bool TargetLoweringObjectFileGOFF::shouldPutJumpTableInFunctionSection(
return true;
}
+MCSection *TargetLoweringObjectFileGOFF::getSectionForConstant(
+ const DataLayout &DL, SectionKind Kind, const Constant *C, Align &Alignment,
+ const Function *F) const {
+ return TextSection;
+}
+
MCSection *TargetLoweringObjectFileGOFF::getExplicitSectionGlobal(
const GlobalObject *GO, SectionKind Kind, const TargetMachine &TM) const {
return SelectSectionForGlobal(GO, Kind, TM);
diff --git a/llvm/test/CodeGen/SystemZ/zos-eh.ll b/llvm/test/CodeGen/SystemZ/zos-eh.ll
index 9439289bfbd6b..a424de3068d9e 100644
--- a/llvm/test/CodeGen/SystemZ/zos-eh.ll
+++ b/llvm/test/CodeGen/SystemZ/zos-eh.ll
@@ -13,6 +13,11 @@ bb1:
ret { ptr, i32 } zeroinitializer
}
+define double @fn_with_const_pool() {
+start:
+ ret double 1.0 ; forces a constant pool entry (L#CPI1_0)
+}
+
declare i32 @__zos_cxx_personality_v2(...)
; CHECK: C_WSA64 CATTR ALIGN(2),FILL(0),NOTEXECUTABLE,RMODE(64),PART(.gcc_excepti
More information about the llvm-commits
mailing list