Skip to content

Commit 7d6fda4

Browse files
authored
[BOLT] Run PatchEntries pass before LongJmp (llvm#137236)
With --force-patch option, every original function entry point is overwritten with a trampoline to a new version of the function to prevent the execution of the original code. If the function size is too small for the trampoline code, we are forced to bail out on rewriting the function. That presented a problem on AArch64 due to LongJmp pass that assumed the presence of the new copy of the function. If the new copy was not emitted it could have lead to a relocation overflow. Run PatchEntries pass before LongJmp and make the latter aware of the functions that are not going to be emitted. Make --force-patch option behavior on AArch64 consistent with other architectures.
1 parent 472c211 commit 7d6fda4

File tree

2 files changed

+5
-16
lines changed

2 files changed

+5
-16
lines changed

bolt/lib/Passes/PatchEntries.cpp

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -98,21 +98,10 @@ Error PatchEntries::runOnFunctions(BinaryContext &BC) {
9898
});
9999

100100
if (!Success) {
101-
// We can't change output layout for AArch64 due to LongJmp pass
102-
if (BC.isAArch64()) {
103-
if (opts::ForcePatch) {
104-
BC.errs() << "BOLT-ERROR: unable to patch entries in " << Function
105-
<< "\n";
106-
return createFatalBOLTError("");
107-
}
108-
109-
continue;
110-
}
111-
112101
// If the original function entries cannot be patched, then we cannot
113102
// safely emit new function body.
114103
BC.errs() << "BOLT-WARNING: failed to patch entries in " << Function
115-
<< ". The function will not be optimized.\n";
104+
<< ". The function will not be optimized\n";
116105
Function.setIgnored();
117106
continue;
118107
}

bolt/lib/Rewrite/BinaryPassManager.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -497,6 +497,10 @@ Error BinaryFunctionPassManager::runAllPasses(BinaryContext &BC) {
497497
// memory profiling data.
498498
Manager.registerPass(std::make_unique<ReorderData>());
499499

500+
// Patch original function entries
501+
if (BC.HasRelocations)
502+
Manager.registerPass(std::make_unique<PatchEntries>());
503+
500504
if (BC.isAArch64()) {
501505
Manager.registerPass(
502506
std::make_unique<ADRRelaxationPass>(PrintAdrRelaxation));
@@ -524,10 +528,6 @@ Error BinaryFunctionPassManager::runAllPasses(BinaryContext &BC) {
524528
// Assign each function an output section.
525529
Manager.registerPass(std::make_unique<AssignSections>());
526530

527-
// Patch original function entries
528-
if (BC.HasRelocations)
529-
Manager.registerPass(std::make_unique<PatchEntries>());
530-
531531
// This pass turns tail calls into jumps which makes them invisible to
532532
// function reordering. It's unsafe to use any CFG or instruction analysis
533533
// after this point.

0 commit comments

Comments
 (0)