Skip to content

Commit

Permalink
[BOLT] Add mold-style PLT support
Browse files Browse the repository at this point in the history
mold linker creates symbols for PLT entries and that caught BOLT by
surprise. Add the support for marked PLT entries.

Fixes: llvm#58498

Reviewed By: yota9

Differential Revision: https://reviews.llvm.org/D136655
  • Loading branch information
maksfb authored and Siddharth Swain committed Oct 25, 2022
1 parent 53695f3 commit 552e018
Show file tree
Hide file tree
Showing 3 changed files with 421 additions and 9 deletions.
25 changes: 16 additions & 9 deletions bolt/lib/Rewrite/RewriteInstance.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1277,9 +1277,12 @@ void RewriteInstance::createPLTBinaryFunction(uint64_t TargetAddress,

ErrorOr<BinarySection &> Section = BC->getSectionForAddress(EntryAddress);
assert(Section && "cannot get section for address");
BF = BC->createBinaryFunction(Rel->Symbol->getName().str() + "@PLT", *Section,
EntryAddress, 0, EntrySize,
Section->getAlignment());
if (!BF)
BF = BC->createBinaryFunction(Rel->Symbol->getName().str() + "@PLT",
*Section, EntryAddress, 0, EntrySize,
Section->getAlignment());
else
BF->addAlternativeName(Rel->Symbol->getName().str() + "@PLT");
setPLTSymbol(BF, Rel->Symbol->getName());
}

Expand Down Expand Up @@ -1411,15 +1414,19 @@ void RewriteInstance::disassemblePLT() {
continue;

analyzeOnePLTSection(Section, PLTSI->EntrySize);
// If we did not register any function at the start of the section,
// then it must be a general PLT entry. Add a function at the location.
if (BC->getBinaryFunctions().find(Section.getAddress()) ==
BC->getBinaryFunctions().end()) {
BinaryFunction *BF = BC->createBinaryFunction(

BinaryFunction *PltBF;
auto BFIter = BC->getBinaryFunctions().find(Section.getAddress());
if (BFIter != BC->getBinaryFunctions().end()) {
PltBF = &BFIter->second;
} else {
// If we did not register any function at the start of the section,
// then it must be a general PLT entry. Add a function at the location.
PltBF = BC->createBinaryFunction(
"__BOLT_PSEUDO_" + Section.getName().str(), Section,
Section.getAddress(), 0, PLTSI->EntrySize, Section.getAlignment());
BF->setPseudo(true);
}
PltBF->setPseudo(true);
}
}

Expand Down
Loading

0 comments on commit 552e018

Please sign in to comment.