Skip to content

Commit e12e0d3

Browse files
authored
[BOLT] Fix thread-safety of MarkRAStates (#165368)
The pass calls setIgnored() on functions in parallel, but setIgnored is not thread safe. This patch adds a std::mutex to guard setIgnored calls. Fixes: #165362
1 parent b6bbc4b commit e12e0d3

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

bolt/include/bolt/Passes/MarkRAStates.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,16 @@
1313
#define BOLT_PASSES_MARK_RA_STATES
1414

1515
#include "bolt/Passes/BinaryPasses.h"
16+
#include <mutex>
1617

1718
namespace llvm {
1819
namespace bolt {
1920

2021
class MarkRAStates : public BinaryFunctionPass {
22+
// setIgnored() is not thread-safe, but the pass is running on functions in
23+
// parallel.
24+
std::mutex IgnoreMutex;
25+
2126
public:
2227
explicit MarkRAStates() : BinaryFunctionPass(false) {}
2328

bolt/lib/Passes/MarkRAStates.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,11 @@ bool MarkRAStates::runOnFunction(BinaryFunction &BF) {
4343
// Not all functions have .cfi_negate_ra_state in them. But if one does,
4444
// we expect psign/pauth instructions to have the hasNegateRAState
4545
// annotation.
46-
BF.setIgnored();
4746
BC.outs() << "BOLT-INFO: inconsistent RAStates in function "
4847
<< BF.getPrintName()
4948
<< ": ptr sign/auth inst without .cfi_negate_ra_state\n";
49+
std::lock_guard<std::mutex> Lock(IgnoreMutex);
50+
BF.setIgnored();
5051
return false;
5152
}
5253
}
@@ -67,6 +68,7 @@ bool MarkRAStates::runOnFunction(BinaryFunction &BF) {
6768
BC.outs() << "BOLT-INFO: inconsistent RAStates in function "
6869
<< BF.getPrintName()
6970
<< ": ptr signing inst encountered in Signed RA state\n";
71+
std::lock_guard<std::mutex> Lock(IgnoreMutex);
7072
BF.setIgnored();
7173
return false;
7274
}
@@ -80,6 +82,7 @@ bool MarkRAStates::runOnFunction(BinaryFunction &BF) {
8082
<< BF.getPrintName()
8183
<< ": ptr authenticating inst encountered in Unsigned RA "
8284
"state\n";
85+
std::lock_guard<std::mutex> Lock(IgnoreMutex);
8386
BF.setIgnored();
8487
return false;
8588
}

0 commit comments

Comments
 (0)