Skip to content

Commit 6470d1b

Browse files
authored
[BOLT] Exclude BOLT injected functions from AssignSections. NFCI (llvm#171579)
Assign output sections for injected functions explicitly, and don't reassign in AssignSections pass. This change is a prerequisite for further PRs where veneer functions are created as injected functions and their code section depends on their placement.
1 parent c1fd5ac commit 6470d1b

File tree

3 files changed

+8
-10
lines changed

3 files changed

+8
-10
lines changed

bolt/include/bolt/Core/BinaryFunction.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -735,11 +735,12 @@ class BinaryFunction {
735735
Symbols.push_back(BC.Ctx->getOrCreateSymbol(Name));
736736
}
737737

738-
/// This constructor is used to create an injected function
738+
/// This constructor is used to create an injected function, i.e. a function
739+
/// that didn't originate in the input file.
739740
BinaryFunction(const std::string &Name, BinaryContext &BC, bool IsSimple)
740741
: Address(0), Size(0), BC(BC), IsSimple(IsSimple),
741-
CodeSectionName(buildCodeSectionName(Name, BC)),
742-
ColdCodeSectionName(buildColdCodeSectionName(Name, BC)),
742+
CodeSectionName(BC.getInjectedCodeSectionName()),
743+
ColdCodeSectionName(BC.getInjectedColdCodeSectionName()),
743744
FunctionNumber(++Count) {
744745
Symbols.push_back(BC.Ctx->getOrCreateSymbol(Name));
745746
IsInjected = true;

bolt/lib/Core/BinaryContext.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2598,6 +2598,10 @@ BinaryContext::createInstructionPatch(uint64_t Address,
25982598
PBF->addBasicBlock()->addInstructions(Instructions);
25992599
PBF->setIsPatch(true);
26002600

2601+
// Patch functions have to be emitted each into their unique section.
2602+
PBF->setCodeSectionName(
2603+
BinaryFunction::buildCodeSectionName(PBF->getOneName(), *this));
2604+
26012605
// Don't create symbol table entry if the name wasn't specified.
26022606
if (Name.str().empty())
26032607
PBF->setAnonymous(true);

bolt/lib/Passes/BinaryPasses.cpp

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1276,13 +1276,6 @@ Error SimplifyRODataLoads::runOnFunctions(BinaryContext &BC) {
12761276
}
12771277

12781278
Error AssignSections::runOnFunctions(BinaryContext &BC) {
1279-
for (BinaryFunction *Function : BC.getInjectedBinaryFunctions()) {
1280-
if (!Function->isPatch()) {
1281-
Function->setCodeSectionName(BC.getInjectedCodeSectionName());
1282-
Function->setColdCodeSectionName(BC.getInjectedColdCodeSectionName());
1283-
}
1284-
}
1285-
12861279
// In non-relocation mode functions have pre-assigned section names.
12871280
if (!BC.HasRelocations)
12881281
return Error::success();

0 commit comments

Comments
 (0)