aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/MC/MCSection.cpp
diff options
context:
space:
mode:
authorFangrui Song <i@maskray.me>2025-05-23 18:44:15 -0700
committerGitHub <noreply@github.com>2025-05-23 18:44:15 -0700
commitbb03cdcb441fd68da9d1ebb7d5f39f73667cd39c (patch)
tree27d76f4d725a8b0a1cc8eb3f9d7ca9fcc3a2a4b0 /llvm/lib/MC/MCSection.cpp
parentd5802c30ae6cf296489daf12b36582e9e1d658bb (diff)
downloadllvm-bb03cdcb441fd68da9d1ebb7d5f39f73667cd39c.zip
llvm-bb03cdcb441fd68da9d1ebb7d5f39f73667cd39c.tar.gz
llvm-bb03cdcb441fd68da9d1ebb7d5f39f73667cd39c.tar.bz2
RISCV: Remove shouldForceRelocation and unneeded relocations
Follow-up to #140494 `shouldForceRelocation` is conservative and produces redundant relocations. For example, RISCVAsmBackend::ForceRelocs (introduced to support mixed relax/norelax code) leads to redundant relocations in the following example adapted from #77436 ``` .option norelax j label // For assembly input, RISCVAsmParser::ParseInstruction sets ForceRelocs (https://reviews.llvm.org/D46423). // For direct object emission, RISCVELFStreamer sets ForceRelocs (#77436) .option relax call foo // linker-relaxable .option norelax j label // redundant relocation due to ForceRelocs .option relax label: ``` Root problem: The `isSymbolRefDifferenceFullyResolvedImpl` condition in MCAssembler::evaluateFixup does not check whether two locations are separated by a fragment whose size can be indeterminate due to linker instruction (e.g. MCDataFragment with relaxation, or MCAlignFragment due to indeterminate start offst). This patch * Updates the fragment walk code in `attemptToFoldSymbolOffsetDifference` to treat MCRelaxableFragment (for --riscv-asm-relax-branches) as fixed size after finishLayout. * Adds a condition in `addReloc` to complement `isSymbolRefDifferenceFullyResolvedImpl`. * Removes the no longer needed `shouldForceRelocation`. This fragment walk code path handles nicely handles mixed relax/norelax case from https://discourse.llvm.org/t/possible-problem-related-to-subtarget-usage/75283 and allows us to remove `MCSubtargetInfo` argument (#73721) as a follow-up. This fragment walk code should be avoided in the absence of linker-relaxable fragments within the current section. Adjust two bolt/test/RISCV tests (#141310) Pull Request: https://github.com/llvm/llvm-project/pull/140692
Diffstat (limited to 'llvm/lib/MC/MCSection.cpp')
-rw-r--r--llvm/lib/MC/MCSection.cpp2
1 files changed, 1 insertions, 1 deletions
diff --git a/llvm/lib/MC/MCSection.cpp b/llvm/lib/MC/MCSection.cpp
index 94f12dd..8409eeb 100644
--- a/llvm/lib/MC/MCSection.cpp
+++ b/llvm/lib/MC/MCSection.cpp
@@ -23,7 +23,7 @@ MCSection::MCSection(SectionVariant V, StringRef Name, bool IsText,
bool IsVirtual, MCSymbol *Begin)
: Begin(Begin), BundleGroupBeforeFirstInst(false), HasInstructions(false),
HasLayout(false), IsRegistered(false), IsText(IsText),
- IsVirtual(IsVirtual), Name(Name), Variant(V) {
+ IsVirtual(IsVirtual), LinkerRelaxable(false), Name(Name), Variant(V) {
DummyFragment.setParent(this);
// The initial subsection number is 0. Create a fragment list.
CurFragList = &Subsections.emplace_back(0u, FragList{}).second;