Skip to content

[BOLT] Clean up jump table handling in non-reloc mode. NFCI #119614

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 6 additions & 20 deletions bolt/lib/Core/BinaryEmitter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -730,30 +730,16 @@ void BinaryEmitter::emitJumpTables(const BinaryFunction &BF) {
continue;
if (opts::PrintJumpTables)
JT.print(BC.outs());
if (opts::JumpTables == JTS_BASIC && BC.HasRelocations) {
if (opts::JumpTables == JTS_BASIC) {
JT.updateOriginal();
} else {
MCSection *HotSection, *ColdSection;
if (opts::JumpTables == JTS_BASIC) {
// In non-relocation mode we have to emit jump tables in local sections.
// This way we only overwrite them when the corresponding function is
// overwritten.
std::string Name = ".local." + JT.Labels[0]->getName().str();
std::replace(Name.begin(), Name.end(), '/', '.');
BinarySection &Section =
BC.registerOrUpdateSection(Name, ELF::SHT_PROGBITS, ELF::SHF_ALLOC);
Section.setAnonymous(true);
JT.setOutputSection(Section);
HotSection = BC.getDataSection(Name);
ColdSection = HotSection;
if (BF.isSimple()) {
HotSection = ReadOnlySection;
ColdSection = ReadOnlyColdSection;
} else {
if (BF.isSimple()) {
HotSection = ReadOnlySection;
ColdSection = ReadOnlyColdSection;
} else {
HotSection = BF.hasProfile() ? ReadOnlySection : ReadOnlyColdSection;
ColdSection = HotSection;
}
HotSection = BF.hasProfile() ? ReadOnlySection : ReadOnlyColdSection;
ColdSection = HotSection;
}
emitJumpTable(JT, HotSection, ColdSection);
}
Expand Down
37 changes: 2 additions & 35 deletions bolt/lib/Rewrite/RewriteInstance.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,6 @@ namespace opts {
extern cl::list<std::string> HotTextMoveSections;
extern cl::opt<bool> Hugify;
extern cl::opt<bool> Instrument;
extern cl::opt<JumpTableSupportLevel> JumpTables;
extern cl::opt<bool> KeepNops;
extern cl::opt<bool> Lite;
extern cl::list<std::string> ReorderData;
Expand Down Expand Up @@ -3841,20 +3840,6 @@ void RewriteInstance::mapCodeSections(BOLTLinker::SectionMapper MapSection) {
assert(Function.getImageSize() <= Function.getMaxSize() &&
"Unexpected large function");

// Map jump tables if updating in-place.
if (opts::JumpTables == JTS_BASIC) {
for (auto &JTI : Function.JumpTables) {
JumpTable *JT = JTI.second;
BinarySection &Section = JT->getOutputSection();
Section.setOutputAddress(JT->getAddress());
Section.setOutputFileOffset(getFileOffsetForAddress(JT->getAddress()));
LLVM_DEBUG(dbgs() << "BOLT-DEBUG: mapping JT " << Section.getName()
<< " to 0x" << Twine::utohexstr(JT->getAddress())
<< '\n');
MapSection(Section, JT->getAddress());
}
}

if (!Function.isSplit())
continue;

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

if (Function->getImageSize() > Function->getMaxSize()) {
assert(!BC->isX86() && "Unexpected large function.");
if (opts::Verbosity >= 1)
BC->errs() << "BOLT-WARNING: new function size (0x"
<< Twine::utohexstr(Function->getImageSize())
<< ") is larger than maximum allowed size (0x"
<< Twine::utohexstr(Function->getMaxSize())
<< ") for function " << *Function << '\n';

// Remove jump table sections that this function owns in non-reloc mode
// because we don't want to write them anymore.
if (!BC->HasRelocations && opts::JumpTables == JTS_BASIC) {
for (auto &JTI : Function->JumpTables) {
JumpTable *JT = JTI.second;
BinarySection &Section = JT->getOutputSection();
BC->deregisterSection(Section);
}
}
continue;
}
assert(Function->getImageSize() <= Function->getMaxSize() &&
"Unexpected large function");

const auto HasAddress = [](const FunctionFragment &FF) {
return FF.empty() ||
Expand Down
Loading