[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:29:39 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;
----------------
dcci wrote:
Also, minor, typo, should this be `.` instead of `;`
https://github.com/llvm/llvm-project/pull/86908
More information about the llvm-commits
mailing list