Skip to content

Commit 5cbd4ce

Browse files
committed
[BOLT] Fix multithreading in #120064
- use SkipPredicates, - use atomic counters.
1 parent 250f060 commit 5cbd4ce

File tree

5 files changed

+27
-25
lines changed

5 files changed

+27
-25
lines changed

bolt/include/bolt/Core/BinaryFunction.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ class BinaryFunction {
149149
};
150150

151151
void setContainedNegateRAState() { HadNegateRAState = true; }
152-
bool containedNegateRAState() { return HadNegateRAState; }
152+
bool containedNegateRAState() const { return HadNegateRAState; }
153153
void setInitialRAState(bool State) { InitialRAState = State; }
154154
bool getInitialRAState() { return InitialRAState; }
155155

bolt/include/bolt/Passes/InsertNegateRAStatePass.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ class InsertNegateRAState : public BinaryFunctionPass {
2828
void runOnFunction(BinaryFunction &BF);
2929

3030
private:
31-
uint64_t FunctionsModified{0};
3231
/// Because states are tracked as MCAnnotations on individual instructions,
3332
/// newly inserted instructions do not have a state associated with them.
3433
/// New states are "inherited" from the last known state.

bolt/include/bolt/Passes/MarkRAStates.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,6 @@ class MarkRAStates : public BinaryFunctionPass {
2626
/// Pass entry point
2727
Error runOnFunctions(BinaryContext &BC) override;
2828
bool runOnFunction(BinaryFunction &BF);
29-
30-
private:
31-
uint64_t FunctionsIgnored{0};
3229
};
3330

3431
} // namespace bolt

bolt/lib/Passes/InsertNegateRAStatePass.cpp

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -114,20 +114,23 @@ void InsertNegateRAState::inferUnknownStates(BinaryFunction &BF) {
114114
}
115115

116116
Error InsertNegateRAState::runOnFunctions(BinaryContext &BC) {
117+
std::atomic<uint64_t> FunctionsModified{0};
117118
ParallelUtilities::WorkFuncTy WorkFun = [&](BinaryFunction &BF) {
118-
if (BF.containedNegateRAState() && !BF.isIgnored()) {
119-
// We can skip functions which did not include negate-ra-state CFIs. This
120-
// includes code using pac-ret hardening as well, if the binary is
121-
// compiled with `-fno-exceptions -fno-unwind-tables
122-
// -fno-asynchronous-unwind-tables`
123-
FunctionsModified++;
124-
runOnFunction(BF);
125-
}
119+
FunctionsModified++;
120+
runOnFunction(BF);
121+
};
122+
123+
ParallelUtilities::PredicateTy SkipPredicate = [&](const BinaryFunction &BF) {
124+
// We can skip functions which did not include negate-ra-state CFIs. This
125+
// includes code using pac-ret hardening as well, if the binary is
126+
// compiled with `-fno-exceptions -fno-unwind-tables
127+
// -fno-asynchronous-unwind-tables`
128+
return !BF.containedNegateRAState() || BF.isIgnored();
126129
};
127130

128131
ParallelUtilities::runOnEachFunction(
129-
BC, ParallelUtilities::SchedulingPolicy::SP_TRIVIAL, WorkFun, nullptr,
130-
"InsertNegateRAStatePass");
132+
BC, ParallelUtilities::SchedulingPolicy::SP_TRIVIAL, WorkFun,
133+
SkipPredicate, "InsertNegateRAStatePass");
131134

132135
BC.outs() << "BOLT-INFO: rewritten pac-ret DWARF info in "
133136
<< FunctionsModified << " out of " << BC.getBinaryFunctions().size()

bolt/lib/Passes/MarkRAStates.cpp

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -119,21 +119,24 @@ bool MarkRAStates::runOnFunction(BinaryFunction &BF) {
119119
}
120120

121121
Error MarkRAStates::runOnFunctions(BinaryContext &BC) {
122+
std::atomic<uint64_t> FunctionsIgnored{0};
122123
ParallelUtilities::WorkFuncTy WorkFun = [&](BinaryFunction &BF) {
123-
if (BF.containedNegateRAState() && !BF.isIgnored()) {
124-
// We can skip functions which did not include negate-ra-state CFIs. This
125-
// includes code using pac-ret hardening as well, if the binary is
126-
// compiled with `-fno-exceptions -fno-unwind-tables
127-
// -fno-asynchronous-unwind-tables`
128-
if (!runOnFunction(BF)) {
129-
FunctionsIgnored++;
130-
}
124+
if (!runOnFunction(BF)) {
125+
FunctionsIgnored++;
131126
}
132127
};
133128

129+
ParallelUtilities::PredicateTy SkipPredicate = [&](const BinaryFunction &BF) {
130+
// We can skip functions which did not include negate-ra-state CFIs. This
131+
// includes code using pac-ret hardening as well, if the binary is
132+
// compiled with `-fno-exceptions -fno-unwind-tables
133+
// -fno-asynchronous-unwind-tables`
134+
return !BF.containedNegateRAState() || BF.isIgnored();
135+
};
136+
134137
ParallelUtilities::runOnEachFunction(
135-
BC, ParallelUtilities::SchedulingPolicy::SP_TRIVIAL, WorkFun, nullptr,
136-
"MarkRAStates");
138+
BC, ParallelUtilities::SchedulingPolicy::SP_TRIVIAL, WorkFun,
139+
SkipPredicate, "MarkRAStates");
137140

138141
int Total = llvm::count_if(
139142
BC.getBinaryFunctions(),

0 commit comments

Comments
 (0)