Skip to content

Commit 8950f02

Browse files
committed
[BOLT] Introduce BinaryFunction::canClone()
In some scenarios, we want to allow execution of the original function code together with its rewritten (optimized) copy. We used to limit such capability when the function uses C++ exceptions, since we cannot duplicate exception tables. There's more metadata that cannot be duplicated, and this PR adds more checks via the introduction of canClone() function that checks all such limitations.
1 parent dbe070e commit 8950f02

File tree

3 files changed

+16
-1
lines changed

3 files changed

+16
-1
lines changed

bolt/include/bolt/Core/BinaryFunction.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1375,6 +1375,11 @@ class BinaryFunction {
13751375
/// Return true if the function should not have associated symbol table entry.
13761376
bool isAnonymous() const { return IsAnonymous; }
13771377

1378+
/// Return true if we can allow the execution of the original body of the
1379+
/// function together with its rewritten copy. This means, e.g., that metadata
1380+
/// associated with the function can be duplicated/cloned.
1381+
bool canClone() const;
1382+
13781383
/// If this function was folded, return the function it was folded into.
13791384
BinaryFunction *getFoldedIntoFunction() const { return FoldedIntoFunction; }
13801385

bolt/lib/Core/BinaryFunction.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3744,6 +3744,16 @@ void BinaryFunction::postProcessBranches() {
37443744
assert(validateCFG() && "invalid CFG");
37453745
}
37463746

3747+
bool BinaryFunction::canClone() const {
3748+
// For instrumentation, we need to restrict the execution to the rewritten
3749+
// version of the function.
3750+
if (opts::Instrument)
3751+
return false;
3752+
3753+
// Check for the presence of metadata that cannot be duplicated.
3754+
return !hasEHRanges() && !hasSDTMarker() && !hasPseudoProbe() && !hasORC();
3755+
}
3756+
37473757
MCSymbol *BinaryFunction::addEntryPointAtOffset(uint64_t Offset) {
37483758
assert(Offset && "cannot add primary entry point");
37493759
assert(CurrentState == State::Empty || CurrentState == State::Disassembled);

bolt/lib/Passes/PatchEntries.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ Error PatchEntries::runOnFunctions(BinaryContext &BC) {
6565
continue;
6666

6767
// Check if we can skip patching the function.
68-
if (!opts::ForcePatch && !Function.hasEHRanges() &&
68+
if (!opts::ForcePatch && Function.canClone() &&
6969
Function.getSize() < PatchThreshold)
7070
continue;
7171

0 commit comments

Comments
 (0)