[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 <maks@meta.com>
This commit is contained in:
parent
900505900e
commit
316a6ff3d0
@ -2697,20 +2697,19 @@ void RewriteInstance::handleRelocation(const SectionRef &RelocatedSection,
|
|||||||
BD->nameStartsWith("_ZTCN"))) { // construction vtable
|
BD->nameStartsWith("_ZTCN"))) { // construction vtable
|
||||||
BinaryFunction *BF = BC->getBinaryFunctionContainingAddress(
|
BinaryFunction *BF = BC->getBinaryFunctionContainingAddress(
|
||||||
SymbolAddress, /*CheckPastEnd*/ false, /*UseMaxSize*/ true);
|
SymbolAddress, /*CheckPastEnd*/ false, /*UseMaxSize*/ true);
|
||||||
if (!BF || BF->getAddress() != SymbolAddress) {
|
if (BF) {
|
||||||
BC->errs()
|
if (BF->getAddress() != SymbolAddress) {
|
||||||
<< "BOLT-ERROR: the virtual function table entry at offset 0x"
|
BC->errs()
|
||||||
<< Twine::utohexstr(Rel.getOffset());
|
<< "BOLT-ERROR: the virtual function table entry at offset 0x"
|
||||||
if (BF)
|
<< Twine::utohexstr(Rel.getOffset())
|
||||||
BC->errs() << " points to the middle of a function @ 0x"
|
<< " points to the middle of a function @ 0x"
|
||||||
<< Twine::utohexstr(BF->getAddress()) << "\n";
|
<< Twine::utohexstr(BF->getAddress()) << "\n";
|
||||||
else
|
exit(1);
|
||||||
BC->errs() << " does not point to any function\n";
|
}
|
||||||
exit(1);
|
BC->addRelocation(Rel.getOffset(), BF->getSymbol(), RType, Addend,
|
||||||
|
ExtractedValue);
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
BC->addRelocation(Rel.getOffset(), BF->getSymbol(), RType, Addend,
|
|
||||||
ExtractedValue);
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -0,0 +1,35 @@
|
|||||||
|
// Test the fix that BOLT should skip special handling of any non-virtual
|
||||||
|
// function pointer relocations in relative vtable.
|
||||||
|
|
||||||
|
// RUN: llvm-mc -filetype=obj -triple aarch64-unknown-gnu %s -o %t.o
|
||||||
|
// RUN: %clang %cxxflags -fuse-ld=lld %t.o -o %t.so -Wl,-q
|
||||||
|
// RUN: llvm-bolt %t.so -o %t.bolted.so
|
||||||
|
|
||||||
|
.text
|
||||||
|
.p2align 2
|
||||||
|
.type foo,@function
|
||||||
|
foo:
|
||||||
|
.cfi_startproc
|
||||||
|
adrp x8, _ZTV3gooE
|
||||||
|
add x8, x8, :lo12:_ZTV3gooE
|
||||||
|
ldr x0, [x8]
|
||||||
|
ret
|
||||||
|
.Lfunc_end0:
|
||||||
|
.size foo, .Lfunc_end0-foo
|
||||||
|
.cfi_endproc
|
||||||
|
|
||||||
|
.type _fake_rtti_data,@object
|
||||||
|
.section .rodata.cst16._fake_rtti_data,"aMG",@progbits,16,_fake_rtti_data,comdat
|
||||||
|
.p2align 3, 0x0
|
||||||
|
_fake_rtti_data:
|
||||||
|
.ascii "_FAKE_RTTI_DATA_"
|
||||||
|
.size _fake_rtti_data, 16
|
||||||
|
|
||||||
|
.type _ZTV3gooE,@object
|
||||||
|
.section .rodata,"a",@progbits
|
||||||
|
.p2align 2, 0x0
|
||||||
|
_ZTV3gooE:
|
||||||
|
.word 0
|
||||||
|
.word _fake_rtti_data-_ZTV3gooE-8
|
||||||
|
.word foo@PLT-_ZTV3gooE-8
|
||||||
|
.size _ZTV3gooE, 12
|
Loading…
x
Reference in New Issue
Block a user