Skip to content

Commit b560b87

Browse files
authored
[BOLT] Clean up jump table handling in non-reloc mode. NFCI (#119614)
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 2daadbd commit b560b87

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
@@ -761,30 +761,16 @@ void BinaryEmitter::emitJumpTables(const BinaryFunction &BF) {
761761
continue;
762762
if (opts::PrintJumpTables)
763763
JT.print(BC.outs());
764-
if (opts::JumpTables == JTS_BASIC && BC.HasRelocations) {
764+
if (opts::JumpTables == JTS_BASIC) {
765765
JT.updateOriginal();
766766
} else {
767767
MCSection *HotSection, *ColdSection;
768-
if (opts::JumpTables == JTS_BASIC) {
769-
// In non-relocation mode we have to emit jump tables in local sections.
770-
// This way we only overwrite them when the corresponding function is
771-
// overwritten.
772-
std::string Name = ".local." + JT.Labels[0]->getName().str();
773-
std::replace(Name.begin(), Name.end(), '/', '.');
774-
BinarySection &Section =
775-
BC.registerOrUpdateSection(Name, ELF::SHT_PROGBITS, ELF::SHF_ALLOC);
776-
Section.setAnonymous(true);
777-
JT.setOutputSection(Section);
778-
HotSection = BC.getDataSection(Name);
779-
ColdSection = HotSection;
768+
if (BF.isSimple()) {
769+
HotSection = ReadOnlySection;
770+
ColdSection = ReadOnlyColdSection;
780771
} else {
781-
if (BF.isSimple()) {
782-
HotSection = ReadOnlySection;
783-
ColdSection = ReadOnlyColdSection;
784-
} else {
785-
HotSection = BF.hasProfile() ? ReadOnlySection : ReadOnlyColdSection;
786-
ColdSection = HotSection;
787-
}
772+
HotSection = BF.hasProfile() ? ReadOnlySection : ReadOnlyColdSection;
773+
ColdSection = HotSection;
788774
}
789775
emitJumpTable(JT, HotSection, ColdSection);
790776
}

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;
@@ -3848,20 +3847,6 @@ void RewriteInstance::mapCodeSections(BOLTLinker::SectionMapper MapSection) {
38483847
assert(Function.getImageSize() <= Function.getMaxSize() &&
38493848
"Unexpected large function");
38503849

3851-
// Map jump tables if updating in-place.
3852-
if (opts::JumpTables == JTS_BASIC) {
3853-
for (auto &JTI : Function.JumpTables) {
3854-
JumpTable *JT = JTI.second;
3855-
BinarySection &Section = JT->getOutputSection();
3856-
Section.setOutputAddress(JT->getAddress());
3857-
Section.setOutputFileOffset(getFileOffsetForAddress(JT->getAddress()));
3858-
LLVM_DEBUG(dbgs() << "BOLT-DEBUG: mapping JT " << Section.getName()
3859-
<< " to 0x" << Twine::utohexstr(JT->getAddress())
3860-
<< '\n');
3861-
MapSection(Section, JT->getAddress());
3862-
}
3863-
}
3864-
38653850
if (!Function.isSplit())
38663851
continue;
38673852

@@ -5644,26 +5629,8 @@ void RewriteInstance::rewriteFile() {
56445629
if (Function->getImageAddress() == 0 || Function->getImageSize() == 0)
56455630
continue;
56465631

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

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

0 commit comments

Comments
 (0)