[SystemZ][z/OS] Fix "relative immediate relocation section mismatch" - #222437
Merged
Conversation
|
@llvm/pr-subscribers-backend-systemz Author: Kai Nacke (redstar) ChangesConstants 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 Full diff: https://github.com/llvm/llvm-project/pull/222437.diff 3 Files Affected:
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
|
…atch" 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.
redstar
force-pushed
the
users/redstar/fixconstsect
branch
from
September 10, 2026 13:48
eee3d12 to
7a92cd5
Compare
vadimkotov
pushed a commit
to vadimkotov/llvm-project
that referenced
this pull request
Sep 11, 2026
…lvm#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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.