[llvm] 746d09a - [SystemZ][z/OS] Fix "relative immediate relocation section mismatch" (#222437)
via llvm-commits
llvm-commits at lists.llvm.org
Thu Sep 10 07:52:37 PDT 2026
Author: Kai Nacke
Date: 2026-09-10T10:52:32-04:00
New Revision: 746d09af26a84cdbe1e03aeb436c8ada09ac8ecf
URL: https://github.com/llvm/llvm-project/commit/746d09af26a84cdbe1e03aeb436c8ada09ac8ecf
DIFF: https://github.com/llvm/llvm-project/commit/746d09af26a84cdbe1e03aeb436c8ada09ac8ecf.diff
LOG: [SystemZ][z/OS] Fix "relative immediate relocation section mismatch" (#222437)
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 instead 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.
Added:
Modified:
llvm/include/llvm/CodeGen/TargetLoweringObjectFileImpl.h
llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp
llvm/test/CodeGen/SystemZ/zos-eh.ll
Removed:
################################################################################
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