Skip to content

[BOLT][RelVTable] Skip special handling on non virtual function pointer relocations #137406

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Apr 29, 2025
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 12 additions & 13 deletions bolt/lib/Rewrite/RewriteInstance.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2697,20 +2697,19 @@ void RewriteInstance::handleRelocation(const SectionRef &RelocatedSection,
BD->nameStartsWith("_ZTCN"))) { // construction vtable
BinaryFunction *BF = BC->getBinaryFunctionContainingAddress(
SymbolAddress, /*CheckPastEnd*/ false, /*UseMaxSize*/ true);
if (!BF || BF->getAddress() != SymbolAddress) {
BC->errs()
<< "BOLT-ERROR: the virtual function table entry at offset 0x"
<< Twine::utohexstr(Rel.getOffset());
if (BF)
BC->errs() << " points to the middle of a function @ 0x"
<< Twine::utohexstr(BF->getAddress()) << "\n";
else
BC->errs() << " does not point to any function\n";
exit(1);
if (BF) {
if (BF->getAddress() != SymbolAddress) {
BC->errs()
<< "BOLT-ERROR: the virtual function table entry at offset 0x"
<< Twine::utohexstr(Rel.getOffset())
<< " points to the middle of a function @ 0x"
<< Twine::utohexstr(BF->getAddress()) << "\n";
exit(1);
}
BC->addRelocation(Rel.getOffset(), BF->getSymbol(), RType, Addend,
ExtractedValue);
return;
}
BC->addRelocation(Rel.getOffset(), BF->getSymbol(), RType, Addend,
ExtractedValue);
return;
}
}

Expand Down
35 changes: 35 additions & 0 deletions bolt/test/AArch64/skip-non-vfuncptr-reloc-in-relative-vtable.s
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
// Test the fix that BOLT should skip speical 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