[llvm] [BOLT] Move target-specific relocation logic into target handlers (PR #217926)
via llvm-commits
llvm-commits at lists.llvm.org
Thu Sep 10 04:15:19 PDT 2026
github-actions[bot] wrote:
<!--LLVM CODE FORMAT COMMENT: {clang-format}-->
:warning: C/C++ code formatter, clang-format found issues in your code. :warning:
<details>
<summary>
You can test this locally with the following command:
</summary>
``````````bash
git-clang-format --diff origin/main HEAD --extensions cpp,h -- bolt/lib/Target/AArch64/AArch64RelocationHandler.cpp bolt/lib/Target/RISCV/RISCVRelocationHandler.cpp bolt/lib/Target/X86/X86RelocationHandler.cpp bolt/include/bolt/Core/BinaryContext.h bolt/include/bolt/Core/BinarySection.h bolt/include/bolt/Core/Relocation.h bolt/lib/Core/BinaryContext.cpp bolt/lib/Core/BinaryEmitter.cpp bolt/lib/Core/BinaryFunction.cpp bolt/lib/Core/BinarySection.cpp bolt/lib/Core/Relocation.cpp bolt/lib/Rewrite/LinuxKernelRewriter.cpp bolt/lib/Rewrite/MachORewriteInstance.cpp bolt/lib/Rewrite/RSeqRewriter.cpp bolt/lib/Rewrite/RewriteInstance.cpp bolt/lib/Target/AArch64/AArch64MCSymbolizer.cpp bolt/lib/Target/X86/X86MCSymbolizer.cpp bolt/unittests/Core/BinaryContext.cpp bolt/unittests/Core/MCPlusBuilder.cpp bolt/unittests/Core/MemoryMaps.cpp bolt/unittests/Passes/LivenessAnalysis.cpp bolt/unittests/Passes/PointerAuthCFIFixup.cpp bolt/unittests/Profile/DataAggregator.cpp bolt/unittests/Profile/PerfScripts.cpp bolt/unittests/Profile/PerfSpeEvents.cpp --diff_from_common_commit
``````````
:warning:
The reproduction instructions above might return results for more than one PR
in a stack if you are using a stacked PR workflow. You can limit the results by
changing `origin/main` to the base branch/commit you want to compare against.
:warning:
</details>
<details>
<summary>
View the diff from clang-format here.
</summary>
``````````diff
diff --git a/bolt/include/bolt/Core/Relocation.h b/bolt/include/bolt/Core/Relocation.h
index 38c064f27..96de92903 100644
--- a/bolt/include/bolt/Core/Relocation.h
+++ b/bolt/include/bolt/Core/Relocation.h
@@ -159,7 +159,8 @@ public:
/// overflows as BOLT uses 32 bits for the type.
static uint32_t getType(const object::RelocationRef &Rel);
- size_t getSize(const RelocationHandler &RH) const { return RH.getSizeForType(Type);
+ size_t getSize(const RelocationHandler &RH) const {
+ return RH.getSizeForType(Type);
}
/// Emit relocation at a current \p Streamer' position. The caller is
@@ -195,8 +196,7 @@ public:
private:
const MCExpr *createExpr(MCStreamer *Streamer,
const RelocationHandler &RH) const;
- const MCExpr *createExpr(MCStreamer *Streamer,
- const MCExpr *RetainedValue,
+ const MCExpr *createExpr(MCStreamer *Streamer, const MCExpr *RetainedValue,
const RelocationHandler &RH) const;
};
diff --git a/bolt/lib/Core/BinaryContext.cpp b/bolt/lib/Core/BinaryContext.cpp
index f13ae8eae..40aa24dce 100644
--- a/bolt/lib/Core/BinaryContext.cpp
+++ b/bolt/lib/Core/BinaryContext.cpp
@@ -166,12 +166,12 @@ BinaryContext::BinaryContext(std::unique_ptr<MCContext> Ctx,
: Ctx(std::move(Ctx)), DwCtx(std::move(DwCtx)),
TheTriple(std::move(TheTriple)),
RelocHandler(createRelocationHandler(this->TheTriple->getArch())),
- SSP(std::move(SSP)),
- TheTarget(TheTarget), TripleName(TripleName), MCE(std::move(MCE)),
- MOFI(std::move(MOFI)), AsmInfo(std::move(AsmInfo)), MII(std::move(MII)),
- STI(std::move(STI)), InstPrinter(std::move(InstPrinter)),
- MIA(std::move(MIA)), MIB(std::move(MIB)), MRI(std::move(MRI)),
- DisAsm(std::move(DisAsm)), Logger(Logger), InitialDynoStats(isAArch64()) {
+ SSP(std::move(SSP)), TheTarget(TheTarget), TripleName(TripleName),
+ MCE(std::move(MCE)), MOFI(std::move(MOFI)), AsmInfo(std::move(AsmInfo)),
+ MII(std::move(MII)), STI(std::move(STI)),
+ InstPrinter(std::move(InstPrinter)), MIA(std::move(MIA)),
+ MIB(std::move(MIB)), MRI(std::move(MRI)), DisAsm(std::move(DisAsm)),
+ Logger(Logger), InitialDynoStats(isAArch64()) {
RegularPageSize = isAArch64() ? RegularPageSizeAArch64 : RegularPageSizeX86;
PageAlign = opts::NoHugePages ? RegularPageSize : HugePageSize;
}
diff --git a/bolt/lib/Core/BinarySection.cpp b/bolt/lib/Core/BinarySection.cpp
index e17a2bad4..5d55b8e4d 100644
--- a/bolt/lib/Core/BinarySection.cpp
+++ b/bolt/lib/Core/BinarySection.cpp
@@ -142,7 +142,8 @@ void BinarySection::emitAsData(MCStreamer &Streamer,
}
#endif
- size_t RelocationSize = Relocation::emit(ROI, ROE, &Streamer, BC.getRelocationHandler());
+ size_t RelocationSize =
+ Relocation::emit(ROI, ROE, &Streamer, BC.getRelocationHandler());
SectionOffset += RelocationSize;
}
assert(SectionOffset <= SectionContents.size() && "overflow error");
@@ -195,27 +196,27 @@ void BinarySection::flushPendingRelocations(raw_fd_ostream &OS,
// Safely skip any optional pending relocation that cannot be encoded.
if (Reloc.isOptional() &&
!BC.getRelocationHandler().canEncodeValue(
- Reloc.Type, Value,
- SectionAddress + Reloc.Offset)) {
+ Reloc.Type, Value, SectionAddress + Reloc.Offset)) {
++SkippedPendingRelocations;
continue;
}
Value = BC.getRelocationHandler().encodeValue(
- Reloc.Type, Value,
- SectionAddress + Reloc.Offset);
+ Reloc.Type, Value, SectionAddress + Reloc.Offset);
safePWrite(OS, reinterpret_cast<const char *>(&Value),
BC.getRelocationHandler().getSizeForType(Reloc.Type),
SectionFileOffset + Reloc.Offset);
- LLVM_DEBUG(dbgs() << "BOLT-DEBUG: writing value 0x" << Twine::utohexstr(Value)
- << " of size " << BC.getRelocationHandler().getSizeForType(Reloc.Type)
- << " at section offset 0x" << Twine::utohexstr(Reloc.Offset)
- << " address 0x"
- << Twine::utohexstr(SectionAddress + Reloc.Offset)
- << " file offset 0x"
- << Twine::utohexstr(SectionFileOffset + Reloc.Offset) << '\n';);
+ LLVM_DEBUG(dbgs() << "BOLT-DEBUG: writing value 0x"
+ << Twine::utohexstr(Value) << " of size "
+ << BC.getRelocationHandler().getSizeForType(Reloc.Type)
+ << " at section offset 0x"
+ << Twine::utohexstr(Reloc.Offset) << " address 0x"
+ << Twine::utohexstr(SectionAddress + Reloc.Offset)
+ << " file offset 0x"
+ << Twine::utohexstr(SectionFileOffset + Reloc.Offset)
+ << '\n';);
}
clearList(PendingRelocations);
diff --git a/bolt/lib/Rewrite/LinuxKernelRewriter.cpp b/bolt/lib/Rewrite/LinuxKernelRewriter.cpp
index 43c415e51..16d07b40f 100644
--- a/bolt/lib/Rewrite/LinuxKernelRewriter.cpp
+++ b/bolt/lib/Rewrite/LinuxKernelRewriter.cpp
@@ -494,8 +494,7 @@ void LinuxKernelRewriter::processLKKSymtab(bool IsGPL) {
continue;
BC.addRelocation(EntryAddress, BF->getSymbol(),
- BC.getRelocationHandler().getPC32(), 0,
- *Offset);
+ BC.getRelocationHandler().getPC32(), 0, *Offset);
}
}
diff --git a/bolt/lib/Rewrite/RewriteInstance.cpp b/bolt/lib/Rewrite/RewriteInstance.cpp
index 31b94b4dc..4ef4adfcb 100644
--- a/bolt/lib/Rewrite/RewriteInstance.cpp
+++ b/bolt/lib/Rewrite/RewriteInstance.cpp
@@ -1419,7 +1419,8 @@ void RewriteInstance::discoverFileObjects() {
/*CheckPastEnd*/ false,
/*UseMaxSize*/ true);
if (BF) {
- assert(BC->getRelocationHandler().isRelative(Rel.Type) && "Expected relative relocation for island");
+ assert(BC->getRelocationHandler().isRelative(Rel.Type) &&
+ "Expected relative relocation for island");
BC->logBOLTErrorsAndQuitOnFatal(
BF->markIslandDynamicRelocationAtAddress(RelAddress));
}
@@ -1634,7 +1635,8 @@ Error RewriteInstance::updateRtInitReloc() {
return createStringError(std::errc::not_supported,
"inconsistent .init_array dynamic relocation");
InitArraySection->addDynamicRelocation(
- Relocation{/*Offset*/ 0, /*Symbol*/ nullptr, /*Type*/ BC->getRelocationHandler().getAbs64(),
+ Relocation{/*Offset*/ 0, /*Symbol*/ nullptr,
+ /*Type*/ BC->getRelocationHandler().getAbs64(),
/*Addend*/ RT->getRuntimeStartAddress(), /*Value*/ 0});
}
}
@@ -1644,7 +1646,8 @@ Error RewriteInstance::updateRtInitReloc() {
// "Symbol + Addend". Since we don't have a symbol, just set the addend to the
// desired value.
InitArraySection->addPendingRelocation(
- Relocation{/*Offset*/ 0, /*Symbol*/ nullptr, /*Type*/ BC->getRelocationHandler().getAbs64(),
+ Relocation{/*Offset*/ 0, /*Symbol*/ nullptr,
+ /*Type*/ BC->getRelocationHandler().getAbs64(),
/*Addend*/ RT->getRuntimeStartAddress(), /*Value*/ 0});
BC->outs()
<< "BOLT-INFO: runtime library initialization was hooked via .init_array "
@@ -1690,7 +1693,8 @@ Error RewriteInstance::updateRtFiniReloc() {
// "Symbol + Addend". Since we don't have a symbol, just set the addend to the
// desired value.
FiniArraySection->addPendingRelocation(
- Relocation{/*Offset*/ 0, /*Symbol*/ nullptr, /*Type*/ BC->getRelocationHandler().getAbs64(),
+ Relocation{/*Offset*/ 0, /*Symbol*/ nullptr,
+ /*Type*/ BC->getRelocationHandler().getAbs64(),
/*Addend*/ RT->getRuntimeFiniAddress(), /*Value*/ 0});
BC->outs() << "BOLT-INFO: runtime library finalization was hooked via "
".fini_array entry, set to 0x"
diff --git a/bolt/lib/Target/RISCV/RISCVRelocationHandler.cpp b/bolt/lib/Target/RISCV/RISCVRelocationHandler.cpp
index 48d8ab0d0..935934fcd 100644
--- a/bolt/lib/Target/RISCV/RISCVRelocationHandler.cpp
+++ b/bolt/lib/Target/RISCV/RISCVRelocationHandler.cpp
@@ -335,8 +335,7 @@ bool RISCVRelocationHandler::isPCRelative(uint32_t Type) const {
namespace llvm::bolt {
-std::unique_ptr<RelocationHandler>
-createRISCVRelocationHandler(bool Is64Bit) {
+std::unique_ptr<RelocationHandler> createRISCVRelocationHandler(bool Is64Bit) {
return std::make_unique<RISCVRelocationHandler>(Is64Bit);
}
``````````
</details>
https://github.com/llvm/llvm-project/pull/217926
More information about the llvm-commits
mailing list