Skip to content

Commit 316a6ff

Browse files
yozhumaksfb
andauthored
[BOLT][RelVTable] Skip special handling on non virtual function pointer relocations (#137406)
Besides virtual function pointers vtable could contain other kinds of entries like those for RTTI data that also require relocations. We need to skip special handling on relocations for non virtual function pointers in relative vtable. Co-authored-by: Maksim Panchenko <[email protected]>
1 parent 9005059 commit 316a6ff

File tree

2 files changed

+47
-13
lines changed

2 files changed

+47
-13
lines changed

bolt/lib/Rewrite/RewriteInstance.cpp

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2697,20 +2697,19 @@ void RewriteInstance::handleRelocation(const SectionRef &RelocatedSection,
26972697
BD->nameStartsWith("_ZTCN"))) { // construction vtable
26982698
BinaryFunction *BF = BC->getBinaryFunctionContainingAddress(
26992699
SymbolAddress, /*CheckPastEnd*/ false, /*UseMaxSize*/ true);
2700-
if (!BF || BF->getAddress() != SymbolAddress) {
2701-
BC->errs()
2702-
<< "BOLT-ERROR: the virtual function table entry at offset 0x"
2703-
<< Twine::utohexstr(Rel.getOffset());
2704-
if (BF)
2705-
BC->errs() << " points to the middle of a function @ 0x"
2706-
<< Twine::utohexstr(BF->getAddress()) << "\n";
2707-
else
2708-
BC->errs() << " does not point to any function\n";
2709-
exit(1);
2700+
if (BF) {
2701+
if (BF->getAddress() != SymbolAddress) {
2702+
BC->errs()
2703+
<< "BOLT-ERROR: the virtual function table entry at offset 0x"
2704+
<< Twine::utohexstr(Rel.getOffset())
2705+
<< " points to the middle of a function @ 0x"
2706+
<< Twine::utohexstr(BF->getAddress()) << "\n";
2707+
exit(1);
2708+
}
2709+
BC->addRelocation(Rel.getOffset(), BF->getSymbol(), RType, Addend,
2710+
ExtractedValue);
2711+
return;
27102712
}
2711-
BC->addRelocation(Rel.getOffset(), BF->getSymbol(), RType, Addend,
2712-
ExtractedValue);
2713-
return;
27142713
}
27152714
}
27162715

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
// Test the fix that BOLT should skip special handling of any non-virtual
2+
// function pointer relocations in relative vtable.
3+
4+
// RUN: llvm-mc -filetype=obj -triple aarch64-unknown-gnu %s -o %t.o
5+
// RUN: %clang %cxxflags -fuse-ld=lld %t.o -o %t.so -Wl,-q
6+
// RUN: llvm-bolt %t.so -o %t.bolted.so
7+
8+
.text
9+
.p2align 2
10+
.type foo,@function
11+
foo:
12+
.cfi_startproc
13+
adrp x8, _ZTV3gooE
14+
add x8, x8, :lo12:_ZTV3gooE
15+
ldr x0, [x8]
16+
ret
17+
.Lfunc_end0:
18+
.size foo, .Lfunc_end0-foo
19+
.cfi_endproc
20+
21+
.type _fake_rtti_data,@object
22+
.section .rodata.cst16._fake_rtti_data,"aMG",@progbits,16,_fake_rtti_data,comdat
23+
.p2align 3, 0x0
24+
_fake_rtti_data:
25+
.ascii "_FAKE_RTTI_DATA_"
26+
.size _fake_rtti_data, 16
27+
28+
.type _ZTV3gooE,@object
29+
.section .rodata,"a",@progbits
30+
.p2align 2, 0x0
31+
_ZTV3gooE:
32+
.word 0
33+
.word _fake_rtti_data-_ZTV3gooE-8
34+
.word foo@PLT-_ZTV3gooE-8
35+
.size _ZTV3gooE, 12

0 commit comments

Comments
 (0)