summaryrefslogtreecommitdiff
path: root/bolt
diff options
context:
space:
mode:
authorGergely Bálint <gergely.balint@arm.com>2025-10-28 12:43:52 +0100
committerGitHub <noreply@github.com>2025-10-28 12:43:52 +0100
commite12e0d39a718703f6b78fa586efafebad0b14bad (patch)
treeb03ec0256179efbfd1d454c083ba58589419d890 /bolt
parentb6bbc4b1940006884c49bad7c93b2a949928fe4c (diff)
[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
Diffstat (limited to 'bolt')
-rw-r--r--bolt/include/bolt/Passes/MarkRAStates.h5
-rw-r--r--bolt/lib/Passes/MarkRAStates.cpp5
2 files changed, 9 insertions, 1 deletions
diff --git a/bolt/include/bolt/Passes/MarkRAStates.h b/bolt/include/bolt/Passes/MarkRAStates.h
index 675ab9727142..202f1dda2aad 100644
--- a/bolt/include/bolt/Passes/MarkRAStates.h
+++ b/bolt/include/bolt/Passes/MarkRAStates.h
@@ -13,11 +13,16 @@
#define BOLT_PASSES_MARK_RA_STATES
#include "bolt/Passes/BinaryPasses.h"
+#include <mutex>
namespace llvm {
namespace bolt {
class MarkRAStates : public BinaryFunctionPass {
+ // setIgnored() is not thread-safe, but the pass is running on functions in
+ // parallel.
+ std::mutex IgnoreMutex;
+
public:
explicit MarkRAStates() : BinaryFunctionPass(false) {}
diff --git a/bolt/lib/Passes/MarkRAStates.cpp b/bolt/lib/Passes/MarkRAStates.cpp
index af6a5ca7e31e..b262d66732b7 100644
--- a/bolt/lib/Passes/MarkRAStates.cpp
+++ b/bolt/lib/Passes/MarkRAStates.cpp
@@ -43,10 +43,11 @@ bool MarkRAStates::runOnFunction(BinaryFunction &BF) {
// Not all functions have .cfi_negate_ra_state in them. But if one does,
// we expect psign/pauth instructions to have the hasNegateRAState
// annotation.
- BF.setIgnored();
BC.outs() << "BOLT-INFO: inconsistent RAStates in function "
<< BF.getPrintName()
<< ": ptr sign/auth inst without .cfi_negate_ra_state\n";
+ std::lock_guard<std::mutex> Lock(IgnoreMutex);
+ BF.setIgnored();
return false;
}
}
@@ -67,6 +68,7 @@ bool MarkRAStates::runOnFunction(BinaryFunction &BF) {
BC.outs() << "BOLT-INFO: inconsistent RAStates in function "
<< BF.getPrintName()
<< ": ptr signing inst encountered in Signed RA state\n";
+ std::lock_guard<std::mutex> Lock(IgnoreMutex);
BF.setIgnored();
return false;
}
@@ -80,6 +82,7 @@ bool MarkRAStates::runOnFunction(BinaryFunction &BF) {
<< BF.getPrintName()
<< ": ptr authenticating inst encountered in Unsigned RA "
"state\n";
+ std::lock_guard<std::mutex> Lock(IgnoreMutex);
BF.setIgnored();
return false;
}