Skip to content

Commit 97660c1

Browse files
authored
[BOLT] Issue error on unclaimed PC-relative relocation (llvm#166098)
Replace assert with an error and improve the report when unclaimed PC-relative relocation is left in strict mode.
1 parent 5f01699 commit 97660c1

File tree

2 files changed

+35
-7
lines changed

2 files changed

+35
-7
lines changed

bolt/lib/Core/BinaryContext.cpp

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -778,13 +778,17 @@ void BinaryContext::populateJumpTables() {
778778
}
779779

780780
if (opts::StrictMode && DataPCRelocations.size()) {
781-
LLVM_DEBUG({
782-
dbgs() << DataPCRelocations.size()
783-
<< " unclaimed PC-relative relocations left in data:\n";
784-
for (uint64_t Reloc : DataPCRelocations)
785-
dbgs() << Twine::utohexstr(Reloc) << '\n';
786-
});
787-
assert(0 && "unclaimed PC-relative relocations left in data\n");
781+
this->errs() << "BOLT-ERROR: " << DataPCRelocations.size()
782+
<< " unclaimed PC-relative relocation(s) left in data";
783+
if (opts::Verbosity) {
784+
this->errs() << ":\n";
785+
for (uint64_t RelocOffset : DataPCRelocations)
786+
this->errs() << " @0x" << Twine::utohexstr(RelocOffset) << '\n';
787+
} else {
788+
this->errs() << ". Re-run with -v=1 to see the list\n";
789+
}
790+
this->errs() << "BOLT-ERROR: unable to proceed with --strict\n";
791+
exit(1);
788792
}
789793
clearList(DataPCRelocations);
790794
}

bolt/test/X86/unclaimed-pc-rel.s

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
## Check that unclaimed PC-relative relocation from data to code is detected
2+
## and reported to the user.
3+
4+
# REQUIRES: system-linux
5+
6+
# RUN: %clang %cflags -no-pie %s -o %t.exe -Wl,-q -nostartfiles
7+
# RUN: not llvm-bolt %t.exe -o %t.bolt --strict 2>&1 | FileCheck %s
8+
9+
# CHECK: BOLT-ERROR: 1 unclaimed PC-relative relocation(s) left in data
10+
11+
.text
12+
.globl _start
13+
.type _start, %function
14+
_start:
15+
movl $42, %eax
16+
.L0:
17+
ret
18+
.size _start, .-_start
19+
20+
## Force relocation mode.
21+
.reloc 0, R_X86_64_NONE
22+
23+
.section .rodata
24+
.long .L0-.

0 commit comments

Comments
 (0)