Skip to content

Commit ab897ae

Browse files
authored
[BOLT] Support fragment symbol mapped to the parent address (#162727)
Observed in GCC-produced binary. Emit a warning for the user. Test Plan: added bolt/test/X86/fragment-alias.s
1 parent 06cffb7 commit ab897ae

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

bolt/lib/Rewrite/RewriteInstance.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1514,6 +1514,12 @@ void RewriteInstance::registerFragments() {
15141514
}
15151515
if (BD) {
15161516
BinaryFunction *BF = BC->getFunctionForSymbol(BD->getSymbol());
1517+
if (BF == &Function) {
1518+
BC->errs()
1519+
<< "BOLT-WARNING: fragment maps to the same function as parent: "
1520+
<< Function << '\n';
1521+
continue;
1522+
}
15171523
if (BF) {
15181524
BC->registerFragment(Function, *BF);
15191525
continue;

bolt/test/X86/fragment-alias.s

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
## This test reproduces the issue where a fragment has the same address as
2+
## parent function.
3+
# RUN: llvm-mc --filetype=obj --triple x86_64-unknown-unknown %s -o %t.o
4+
# RUN: %clang %cflags %t.o -o %t
5+
# RUN: llvm-bolt %t -o %t.out 2>&1 | FileCheck %s
6+
# CHECK: BOLT-WARNING: fragment maps to the same function as parent: main/1(*2)
7+
.type main, @function
8+
.type main.cold, @function
9+
main.cold:
10+
main:
11+
ret
12+
.size main, .-main
13+
.size main.cold, .-main.cold

0 commit comments

Comments
 (0)