[llvm] [BOLT] Fix thread-safety of MarkRAStates (PR #165368)
Gergely Bálint via llvm-commits
llvm-commits at lists.llvm.org
Tue Oct 28 03:56:21 PDT 2025
https://github.com/bgergely0 created https://github.com/llvm/llvm-project/pull/165368
The pass calls setIgnored() on functions in parallel, but setIgnored is
not thread safe. The patch adds a mutex to guard setIgnored calls.
Fixes: #165362
>From e29e1ab06e3570cf6c76634f8954b4c381fbbb33 Mon Sep 17 00:00:00 2001
From: Gergely Balint <gergely.balint at arm.com>
Date: Tue, 28 Oct 2025 09:15:35 +0000
Subject: [PATCH] [BOLT] Fix thread-safety of MarkRAStates
The pass calls setIgnored() on functions in parallel, but setIgnored is
not thread safe. The patch adds a mutex to guard setIgnored calls.
Fixes: #165362
---
bolt/include/bolt/Passes/MarkRAStates.h | 5 +++++
bolt/lib/Passes/MarkRAStates.cpp | 3 +++
2 files changed, 8 insertions(+)
diff --git a/bolt/include/bolt/Passes/MarkRAStates.h b/bolt/include/bolt/Passes/MarkRAStates.h
index 675ab9727142b..202f1dda2aad8 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 af6a5ca7e31e5..edef5d88aec62 100644
--- a/bolt/lib/Passes/MarkRAStates.cpp
+++ b/bolt/lib/Passes/MarkRAStates.cpp
@@ -43,6 +43,7 @@ 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.
+ std::lock_guard<std::mutex> Lock(IgnoreMutex);
BF.setIgnored();
BC.outs() << "BOLT-INFO: inconsistent RAStates in function "
<< BF.getPrintName()
@@ -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;
}
More information about the llvm-commits
mailing list