[llvm] [BOLT] Issue error on unclaimed PC-relative relocation (PR #166098)
via llvm-commits
llvm-commits at lists.llvm.org
Sun Nov 2 13:04:20 PST 2025
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-bolt
Author: Maksim Panchenko (maksfb)
<details>
<summary>Changes</summary>
Replace assert with an error and improve the report when unclaimed PC-relative relocation is left in strict mode.
---
Full diff: https://github.com/llvm/llvm-project/pull/166098.diff
2 Files Affected:
- (modified) bolt/lib/Core/BinaryContext.cpp (+11-7)
- (added) bolt/test/X86/unclaimed-pc-rel.s (+23)
``````````diff
diff --git a/bolt/lib/Core/BinaryContext.cpp b/bolt/lib/Core/BinaryContext.cpp
index a383ced1712e3..c7cd034a30410 100644
--- a/bolt/lib/Core/BinaryContext.cpp
+++ b/bolt/lib/Core/BinaryContext.cpp
@@ -778,13 +778,17 @@ void BinaryContext::populateJumpTables() {
}
if (opts::StrictMode && DataPCRelocations.size()) {
- LLVM_DEBUG({
- dbgs() << DataPCRelocations.size()
- << " unclaimed PC-relative relocations left in data:\n";
- for (uint64_t Reloc : DataPCRelocations)
- dbgs() << Twine::utohexstr(Reloc) << '\n';
- });
- assert(0 && "unclaimed PC-relative relocations left in data\n");
+ this->errs() << "BOLT-ERROR: " << DataPCRelocations.size()
+ << " unclaimed PC-relative relocation(s) left in data";
+ if (opts::Verbosity) {
+ this->errs() << ":\n";
+ for (uint64_t RelocOffset : DataPCRelocations)
+ this->errs() << " @0x" << Twine::utohexstr(RelocOffset) << '\n';
+ } else {
+ this->errs() << ". Re-run with -v=1 to see the list\n";
+ }
+ this->errs() << "BOLT-ERROR: unable to proceed with --strict\n";
+ exit(1);
}
clearList(DataPCRelocations);
}
diff --git a/bolt/test/X86/unclaimed-pc-rel.s b/bolt/test/X86/unclaimed-pc-rel.s
new file mode 100644
index 0000000000000..a461c2cf75300
--- /dev/null
+++ b/bolt/test/X86/unclaimed-pc-rel.s
@@ -0,0 +1,23 @@
+## TODO:
+
+# REQUIRES: system-linux
+
+# RUN: %clang %cflags -no-pie %s -o %t.exe -Wl,-q -nostartfiles
+# RUN: not llvm-bolt %t.exe -o %t.bolt --strict 2>&1 | FileCheck %s
+
+# CHECK: BOLT-ERROR: 1 unclaimed PC-relative relocation(s) left in data
+
+ .text
+ .globl _start
+ .type _start, %function
+_start:
+ movl $42, %eax
+.L0:
+ ret
+ .size _start, .-_start
+
+## For relocations against .text
+ .reloc 0, R_X86_64_NONE
+
+.section .rodata
+ .long .L0-.
``````````
</details>
https://github.com/llvm/llvm-project/pull/166098
More information about the llvm-commits
mailing list