[BOLT] Refactor mapCodeSections(). NFC (#146434)
Factor out non-relocation specific code into a separate function.
This commit is contained in:
@@ -202,6 +202,9 @@ private:
|
||||
/// Map code sections generated by BOLT.
|
||||
void mapCodeSections(BOLTLinker::SectionMapper MapSection);
|
||||
|
||||
/// Map code without relocating sections.
|
||||
void mapCodeSectionsInPlace(BOLTLinker::SectionMapper MapSection);
|
||||
|
||||
/// Map the rest of allocatable sections.
|
||||
void mapAllocatableSections(BOLTLinker::SectionMapper MapSection);
|
||||
|
||||
|
||||
@@ -3856,7 +3856,11 @@ std::vector<BinarySection *> RewriteInstance::getCodeSections() {
|
||||
}
|
||||
|
||||
void RewriteInstance::mapCodeSections(BOLTLinker::SectionMapper MapSection) {
|
||||
if (BC->HasRelocations) {
|
||||
if (!BC->HasRelocations) {
|
||||
mapCodeSectionsInPlace(MapSection);
|
||||
return;
|
||||
}
|
||||
|
||||
// Map sections for functions with pre-assigned addresses.
|
||||
for (BinaryFunction *InjectedFunction : BC->getInjectedBinaryFunctions()) {
|
||||
const uint64_t OutputAddress = InjectedFunction->getOutputAddress();
|
||||
@@ -3880,9 +3884,8 @@ void RewriteInstance::mapCodeSections(BOLTLinker::SectionMapper MapSection) {
|
||||
return Section->getOutputAddress();
|
||||
});
|
||||
LLVM_DEBUG(dbgs() << "Code sections in the order of output:\n";
|
||||
for (const BinarySection *Section : CodeSections)
|
||||
dbgs() << Section->getName() << '\n';
|
||||
);
|
||||
for (const BinarySection *Section : CodeSections) dbgs()
|
||||
<< Section->getName() << '\n';);
|
||||
|
||||
uint64_t PaddingSize = 0; // size of padding required at the end
|
||||
|
||||
@@ -3954,8 +3957,7 @@ void RewriteInstance::mapCodeSections(BOLTLinker::SectionMapper MapSection) {
|
||||
BC->outs() << '\n';
|
||||
AllocationDone = true;
|
||||
} else {
|
||||
BC->errs()
|
||||
<< "BOLT-WARNING: original .text too small to fit the new code"
|
||||
BC->errs() << "BOLT-WARNING: original .text too small to fit the new code"
|
||||
<< " using 0x" << Twine::utohexstr(opts::AlignText)
|
||||
<< " alignment. " << CodeSize << " bytes needed, have "
|
||||
<< BC->OldTextSectionSize << " bytes available.\n";
|
||||
@@ -3968,9 +3970,9 @@ void RewriteInstance::mapCodeSections(BOLTLinker::SectionMapper MapSection) {
|
||||
|
||||
// Do the mapping for ORC layer based on the allocation.
|
||||
for (BinarySection *Section : CodeSections) {
|
||||
LLVM_DEBUG(
|
||||
dbgs() << "BOLT: mapping " << Section->getName() << " at 0x"
|
||||
<< Twine::utohexstr(Section->getAllocAddress()) << " to 0x"
|
||||
LLVM_DEBUG(dbgs() << "BOLT: mapping " << Section->getName() << " at 0x"
|
||||
<< Twine::utohexstr(Section->getAllocAddress())
|
||||
<< " to 0x"
|
||||
<< Twine::utohexstr(Section->getOutputAddress()) << '\n');
|
||||
MapSection(*Section, Section->getOutputAddress());
|
||||
Section->setOutputFileOffset(
|
||||
@@ -3982,10 +3984,10 @@ void RewriteInstance::mapCodeSections(BOLTLinker::SectionMapper MapSection) {
|
||||
BC->outs() << "BOLT-INFO: padding code to 0x"
|
||||
<< Twine::utohexstr(NextAvailableAddress)
|
||||
<< " to accommodate hot text\n";
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
void RewriteInstance::mapCodeSectionsInPlace(
|
||||
BOLTLinker::SectionMapper MapSection) {
|
||||
// Processing in non-relocation mode.
|
||||
uint64_t NewTextSectionStartAddress = NextAvailableAddress;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user