Skip to content

Add a global lock to FatalErrorHandler to avoid re-entry #122144

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions compiler/rustc_llvm/llvm-wrapper/RustWrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,12 +60,17 @@ static AtomicOrdering fromRust(LLVMAtomicOrdering Ordering) {

static LLVM_THREAD_LOCAL char *LastError;

static std::mutex FatalErrorHandlerMutex;
static std::unique_lock<std::mutex> FatalErrorHandlerLock(FatalErrorHandlerMutex, std::defer_lock);
// Custom error handler for fatal LLVM errors.
//
// Notably it exits the process with code 101, unlike LLVM's default of 1.
static void FatalErrorHandler(void *UserData,
const char* Reason,
bool GenCrashDiag) {
// Add a global lock to avoid re-entry here. When encountering an error,
// we only need and can only enter once.
FatalErrorHandlerLock.lock();
// Once upon a time we emitted "LLVM ERROR:" specifically to mimic LLVM. Then,
// we developed crater and other tools which only expose logs, not error codes.
// Use a more greppable prefix that will still match the "LLVM ERROR:" prefix.
Expand Down