-
Notifications
You must be signed in to change notification settings - Fork 12.6k
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
[BOLT] Clean up jump table handling in non-reloc mode. NFCI #119614
Conversation
@llvm/pr-subscribers-bolt Author: Maksim Panchenko (maksfb) ChangesThis 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. Full diff: https://github.com/llvm/llvm-project/pull/119614.diff 2 Files Affected:
diff --git a/bolt/lib/Core/BinaryEmitter.cpp b/bolt/lib/Core/BinaryEmitter.cpp
index f34a94c5779213..1744c1e5717224 100644
--- a/bolt/lib/Core/BinaryEmitter.cpp
+++ b/bolt/lib/Core/BinaryEmitter.cpp
@@ -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);
}
diff --git a/bolt/lib/Rewrite/RewriteInstance.cpp b/bolt/lib/Rewrite/RewriteInstance.cpp
index 76e1f0156f828d..27a2636438cdad 100644
--- a/bolt/lib/Rewrite/RewriteInstance.cpp
+++ b/bolt/lib/Rewrite/RewriteInstance.cpp
@@ -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;
@@ -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;
@@ -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() ||
|
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Makes sense. Thanks for the clean up.
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.