Skip to content

Commit c79abd9

Browse files
WIP: static fix: don't patch anything that is not in orig text segment
1 parent 67133dd commit c79abd9

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

bolt/lib/Rewrite/RewriteInstance.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5291,6 +5291,19 @@ void RewriteInstance::patchELFGOT(ELFObjectFile<ELFT> *File) {
52915291
GOTContents.size());
52925292
++GOTEntry) {
52935293
if (uint64_t NewAddress = getNewFunctionAddress(*GOTEntry)) {
5294+
auto *Function = BC->getBinaryFunctionAtAddress(*GOTEntry);
5295+
5296+
// On static binaries, avoid patching got entries that did not belong to
5297+
// the original text section. One such special case is the '_init'
5298+
// function, belonging to the '.init' section.
5299+
if (BC->IsStaticExecutable &&
5300+
Function->getOriginSectionName() != ".bolt.org.text") {
5301+
LLVM_DEBUG(dbgs() << "BOLT-DEBUG: ignoring GOT entry 0x"
5302+
<< Twine::utohexstr(*GOTEntry) << " for '"
5303+
<< Function->getOneName() << "'" << '\n');
5304+
continue;
5305+
}
5306+
52945307
LLVM_DEBUG(dbgs() << "BOLT-DEBUG: patching GOT entry 0x"
52955308
<< Twine::utohexstr(*GOTEntry) << " with 0x"
52965309
<< Twine::utohexstr(NewAddress) << '\n');

0 commit comments

Comments
 (0)