[llvm] [BOLT] Add rewriting support for Linux kernel __bug_table (PR #86908)
Davide Italiano via llvm-commits
llvm-commits at lists.llvm.org
Wed Mar 27 22:13:52 PDT 2024
================
@@ -1223,6 +1232,52 @@ Error LinuxKernelRewriter::readBugTable() {
return Error::success();
}
+/// find_bug() uses linear search to match an address to an entry in the bug
+/// table. Hence, there is no need to sort entries when rewriting the table.
+/// When we need to erase an entry, we set its instruction address to zero.
+Error LinuxKernelRewriter::rewriteBugTable() {
+ if (!BugTableSection)
+ return Error::success();
+
+ for (BinaryFunction &BF : llvm::make_second_range(BC.getBinaryFunctions())) {
+ if (!BC.shouldEmit(BF))
+ continue;
+
+ if (!FunctionBugList.count(&BF))
+ continue;
+
+ // Bugs that will be emitted for this function.
+ DenseSet<uint32_t> EmittedIDs;
+ for (BinaryBasicBlock &BB : BF) {
+ for (MCInst &Inst : BB) {
+ if (!BC.MIB->hasAnnotation(Inst, "BugEntry"))
+ continue;
+ const uint32_t ID = BC.MIB->getAnnotationAs<uint32_t>(Inst, "BugEntry");
+ EmittedIDs.insert(ID);
+
+ // Create a relocation entry for this bug entry;
+ MCSymbol *Label =
+ BC.MIB->getOrCreateInstLabel(Inst, "__BUG_", BC.Ctx.get());
+ const uint64_t EntryOffset = (ID - 1) * BUG_TABLE_ENTRY_SIZE;
+ BugTableSection->addRelocation(EntryOffset, Label, ELF::R_X86_64_PC32,
----------------
dcci wrote:
why the reloc you create is PCREL? Worth adding a comment maybe.
https://github.com/llvm/llvm-project/pull/86908
More information about the llvm-commits
mailing list