Skip to content

Conversation

@maksfb
Copy link
Contributor

@maksfb maksfb commented Nov 2, 2025

Replace assert with an error and improve the report when unclaimed PC-relative relocation is left in strict mode.

@llvmbot
Copy link
Member

llvmbot commented Nov 2, 2025

@llvm/pr-subscribers-bolt

Author: Maksim Panchenko (maksfb)

Changes

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 --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-.

@maksfb maksfb force-pushed the gh-unclaimed-rel-error branch from 646886d to f2b04d5 Compare November 2, 2025 21:46
Replace assert with an error and improve the report when unclaimed
PC-relative relocation is left in strict mode.
@maksfb maksfb force-pushed the gh-unclaimed-rel-error branch from f2b04d5 to c697fcd Compare November 2, 2025 21:48
@maksfb maksfb merged commit 97660c1 into llvm:main Nov 3, 2025
10 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants