diff options
Diffstat (limited to 'bolt/lib/Rewrite')
-rw-r--r-- | bolt/lib/Rewrite/BinaryPassManager.cpp | 13 | ||||
-rw-r--r-- | bolt/lib/Rewrite/RewriteInstance.cpp | 21 |
2 files changed, 30 insertions, 4 deletions
diff --git a/bolt/lib/Rewrite/BinaryPassManager.cpp b/bolt/lib/Rewrite/BinaryPassManager.cpp index d9b7a2bd..782137e 100644 --- a/bolt/lib/Rewrite/BinaryPassManager.cpp +++ b/bolt/lib/Rewrite/BinaryPassManager.cpp @@ -19,11 +19,13 @@ #include "bolt/Passes/IdenticalCodeFolding.h" #include "bolt/Passes/IndirectCallPromotion.h" #include "bolt/Passes/Inliner.h" +#include "bolt/Passes/InsertNegateRAStatePass.h" #include "bolt/Passes/Instrumentation.h" #include "bolt/Passes/JTFootprintReduction.h" #include "bolt/Passes/LongJmp.h" #include "bolt/Passes/LoopInversionPass.h" #include "bolt/Passes/MCF.h" +#include "bolt/Passes/MarkRAStates.h" #include "bolt/Passes/PLTCall.h" #include "bolt/Passes/PatchEntries.h" #include "bolt/Passes/ProfileQualityStats.h" @@ -276,6 +278,12 @@ static cl::opt<bool> ShortenInstructions("shorten-instructions", cl::desc("shorten instructions"), cl::init(true), cl::cat(BoltOptCategory)); + +cl::opt<bool> + UpdateBranchProtection("update-branch-protection", + cl::desc("Rewrites pac-ret DWARF CFI instructions " + "(AArch64-only, on by default)"), + cl::init(true), cl::Hidden, cl::cat(BoltCategory)); } // namespace opts namespace llvm { @@ -353,6 +361,9 @@ Error BinaryFunctionPassManager::runPasses() { Error BinaryFunctionPassManager::runAllPasses(BinaryContext &BC) { BinaryFunctionPassManager Manager(BC); + if (BC.isAArch64()) + Manager.registerPass(std::make_unique<MarkRAStates>()); + Manager.registerPass( std::make_unique<EstimateEdgeCounts>(PrintEstimateEdgeCounts)); @@ -512,6 +523,8 @@ Error BinaryFunctionPassManager::runAllPasses(BinaryContext &BC) { // targets. No extra instructions after this pass, otherwise we may have // relocations out of range and crash during linking. Manager.registerPass(std::make_unique<LongJmpPass>(PrintLongJmp)); + + Manager.registerPass(std::make_unique<InsertNegateRAState>()); } // This pass should always run last.* diff --git a/bolt/lib/Rewrite/RewriteInstance.cpp b/bolt/lib/Rewrite/RewriteInstance.cpp index ddf9347..dad6717 100644 --- a/bolt/lib/Rewrite/RewriteInstance.cpp +++ b/bolt/lib/Rewrite/RewriteInstance.cpp @@ -3524,6 +3524,17 @@ void RewriteInstance::disassembleFunctions() { } } + // Check if fillCFIInfoFor removed any OpNegateRAState CFIs from the + // function. + if (Function.containedNegateRAState()) { + if (!opts::UpdateBranchProtection) { + BC->errs() + << "BOLT-ERROR: --update-branch-protection is set to false, but " + << Function.getPrintName() << " contains .cfi-negate-ra-state\n"; + exit(1); + } + } + // Parse LSDA. if (Function.getLSDAAddress() != 0 && !BC->getFragmentsToSkip().count(&Function)) { @@ -3994,10 +4005,12 @@ 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" - << " using 0x" << Twine::utohexstr(opts::AlignText) - << " alignment. " << CodeSize << " bytes needed, have " - << BC->OldTextSectionSize << " bytes available.\n"; + BC->errs() << "BOLT-WARNING: --use-old-text failed. The original .text " + "too small to fit the new code using 0x" + << Twine::utohexstr(opts::AlignText) << " alignment. " + << CodeSize << " bytes needed, have " << BC->OldTextSectionSize + << " bytes available. Rebuilding without --use-old-text may " + "produce a smaller binary\n"; opts::UseOldText = false; } } |