Skip to content

Commit 20204db

Browse files
committed
[BOLT] Add mold-style PLT support
mold linker creates symbols for PLT entries and that caught BOLT by surprise. Add the support for marked PLT entries. Fixes: #58498 Reviewed By: yota9 Differential Revision: https://reviews.llvm.org/D136655
1 parent 1232f97 commit 20204db

File tree

3 files changed

+421
-9
lines changed

3 files changed

+421
-9
lines changed

bolt/lib/Rewrite/RewriteInstance.cpp

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1277,9 +1277,12 @@ void RewriteInstance::createPLTBinaryFunction(uint64_t TargetAddress,
12771277

12781278
ErrorOr<BinarySection &> Section = BC->getSectionForAddress(EntryAddress);
12791279
assert(Section && "cannot get section for address");
1280-
BF = BC->createBinaryFunction(Rel->Symbol->getName().str() + "@PLT", *Section,
1281-
EntryAddress, 0, EntrySize,
1282-
Section->getAlignment());
1280+
if (!BF)
1281+
BF = BC->createBinaryFunction(Rel->Symbol->getName().str() + "@PLT",
1282+
*Section, EntryAddress, 0, EntrySize,
1283+
Section->getAlignment());
1284+
else
1285+
BF->addAlternativeName(Rel->Symbol->getName().str() + "@PLT");
12831286
setPLTSymbol(BF, Rel->Symbol->getName());
12841287
}
12851288

@@ -1411,15 +1414,19 @@ void RewriteInstance::disassemblePLT() {
14111414
continue;
14121415

14131416
analyzeOnePLTSection(Section, PLTSI->EntrySize);
1414-
// If we did not register any function at the start of the section,
1415-
// then it must be a general PLT entry. Add a function at the location.
1416-
if (BC->getBinaryFunctions().find(Section.getAddress()) ==
1417-
BC->getBinaryFunctions().end()) {
1418-
BinaryFunction *BF = BC->createBinaryFunction(
1417+
1418+
BinaryFunction *PltBF;
1419+
auto BFIter = BC->getBinaryFunctions().find(Section.getAddress());
1420+
if (BFIter != BC->getBinaryFunctions().end()) {
1421+
PltBF = &BFIter->second;
1422+
} else {
1423+
// If we did not register any function at the start of the section,
1424+
// then it must be a general PLT entry. Add a function at the location.
1425+
PltBF = BC->createBinaryFunction(
14191426
"__BOLT_PSEUDO_" + Section.getName().str(), Section,
14201427
Section.getAddress(), 0, PLTSI->EntrySize, Section.getAlignment());
1421-
BF->setPseudo(true);
14221428
}
1429+
PltBF->setPseudo(true);
14231430
}
14241431
}
14251432

0 commit comments

Comments
 (0)