Skip to content

Commit b9acd3f

Browse files
committed
[BOLT] Clean up jump table handling for non-reloc. NFCI
This change affects non-relocation mode only. Prior to having CheckLargeFunctions pass, we could have emitted code for functions that was discarded at the end due to size limitations. Since we didn't know at the time of emission if the code would be discarded or not, we had to emit jump tables in separate sections and handle them separately. However, now we always run CheckLargeFunctions and make sure all emitted code is used. Thus, we can get rid of the special jump table handling.
1 parent 24162bd commit b9acd3f

File tree

2 files changed

+8
-55
lines changed

2 files changed

+8
-55
lines changed

bolt/lib/Core/BinaryEmitter.cpp

Lines changed: 6 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -730,30 +730,16 @@ void BinaryEmitter::emitJumpTables(const BinaryFunction &BF) {
730730
continue;
731731
if (opts::PrintJumpTables)
732732
JT.print(BC.outs());
733-
if (opts::JumpTables == JTS_BASIC && BC.HasRelocations) {
733+
if (opts::JumpTables == JTS_BASIC) {
734734
JT.updateOriginal();
735735
} else {
736736
MCSection *HotSection, *ColdSection;
737-
if (opts::JumpTables == JTS_BASIC) {
738-
// In non-relocation mode we have to emit jump tables in local sections.
739-
// This way we only overwrite them when the corresponding function is
740-
// overwritten.
741-
std::string Name = ".local." + JT.Labels[0]->getName().str();
742-
std::replace(Name.begin(), Name.end(), '/', '.');
743-
BinarySection &Section =
744-
BC.registerOrUpdateSection(Name, ELF::SHT_PROGBITS, ELF::SHF_ALLOC);
745-
Section.setAnonymous(true);
746-
JT.setOutputSection(Section);
747-
HotSection = BC.getDataSection(Name);
748-
ColdSection = HotSection;
737+
if (BF.isSimple()) {
738+
HotSection = ReadOnlySection;
739+
ColdSection = ReadOnlyColdSection;
749740
} else {
750-
if (BF.isSimple()) {
751-
HotSection = ReadOnlySection;
752-
ColdSection = ReadOnlyColdSection;
753-
} else {
754-
HotSection = BF.hasProfile() ? ReadOnlySection : ReadOnlyColdSection;
755-
ColdSection = HotSection;
756-
}
741+
HotSection = BF.hasProfile() ? ReadOnlySection : ReadOnlyColdSection;
742+
ColdSection = HotSection;
757743
}
758744
emitJumpTable(JT, HotSection, ColdSection);
759745
}

bolt/lib/Rewrite/RewriteInstance.cpp

Lines changed: 2 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,6 @@ namespace opts {
7878
extern cl::list<std::string> HotTextMoveSections;
7979
extern cl::opt<bool> Hugify;
8080
extern cl::opt<bool> Instrument;
81-
extern cl::opt<JumpTableSupportLevel> JumpTables;
8281
extern cl::opt<bool> KeepNops;
8382
extern cl::opt<bool> Lite;
8483
extern cl::list<std::string> ReorderData;
@@ -3841,20 +3840,6 @@ void RewriteInstance::mapCodeSections(BOLTLinker::SectionMapper MapSection) {
38413840
assert(Function.getImageSize() <= Function.getMaxSize() &&
38423841
"Unexpected large function");
38433842

3844-
// Map jump tables if updating in-place.
3845-
if (opts::JumpTables == JTS_BASIC) {
3846-
for (auto &JTI : Function.JumpTables) {
3847-
JumpTable *JT = JTI.second;
3848-
BinarySection &Section = JT->getOutputSection();
3849-
Section.setOutputAddress(JT->getAddress());
3850-
Section.setOutputFileOffset(getFileOffsetForAddress(JT->getAddress()));
3851-
LLVM_DEBUG(dbgs() << "BOLT-DEBUG: mapping JT " << Section.getName()
3852-
<< " to 0x" << Twine::utohexstr(JT->getAddress())
3853-
<< '\n');
3854-
MapSection(Section, JT->getAddress());
3855-
}
3856-
}
3857-
38583843
if (!Function.isSplit())
38593844
continue;
38603845

@@ -5637,26 +5622,8 @@ void RewriteInstance::rewriteFile() {
56375622
if (Function->getImageAddress() == 0 || Function->getImageSize() == 0)
56385623
continue;
56395624

5640-
if (Function->getImageSize() > Function->getMaxSize()) {
5641-
assert(!BC->isX86() && "Unexpected large function.");
5642-
if (opts::Verbosity >= 1)
5643-
BC->errs() << "BOLT-WARNING: new function size (0x"
5644-
<< Twine::utohexstr(Function->getImageSize())
5645-
<< ") is larger than maximum allowed size (0x"
5646-
<< Twine::utohexstr(Function->getMaxSize())
5647-
<< ") for function " << *Function << '\n';
5648-
5649-
// Remove jump table sections that this function owns in non-reloc mode
5650-
// because we don't want to write them anymore.
5651-
if (!BC->HasRelocations && opts::JumpTables == JTS_BASIC) {
5652-
for (auto &JTI : Function->JumpTables) {
5653-
JumpTable *JT = JTI.second;
5654-
BinarySection &Section = JT->getOutputSection();
5655-
BC->deregisterSection(Section);
5656-
}
5657-
}
5658-
continue;
5659-
}
5625+
assert(Function->getImageSize() <= Function->getMaxSize() &&
5626+
"Unexpected large function");
56605627

56615628
const auto HasAddress = [](const FunctionFragment &FF) {
56625629
return FF.empty() ||

0 commit comments

Comments
 (0)