Repository navigation
Conversation
Fatal::~Fatal terminates via _Exit to avoid running static destructors, which bypasses the atexit handlers registered by LLVM's instrumentation profile runtime and drops profile data on fatal error paths. Move the exit path into a mutex-serialized Fatal::exit helper in src/support/utilities.cpp. When __LLVM_INSTR_PROFILE_GENERATE is defined, Fatal::~Fatal passes the caller's __llvm_profile_write_file function pointer to Fatal::exit, which flushes the library's profile runtime and, if the function pointer is distinct, the caller's profile runtime as well. This flushes both runtimes in shared-library builds where the library and executables each link a separate hidden copy of the profile runtime, while avoiding duplicate writes when both resolve to the same copy. Also remove unused includes from src/support/utilities.h (<cstdint>, <iostream>, <memory>, and "support/bits.h") and add the missing #include <cstdint> to src/support/string.h.
kripken
reviewed
Nov 30, 2026
| // output or race while flushing instrumentation profiles before _Exit. | ||
| static std::mutex fatalMutex; | ||
| std::lock_guard<std::mutex> lock(fatalMutex); | ||
| std::cerr << msg << std::endl; |
Member
There was a problem hiding this comment.
Why is the mutex out of the ifdef beginning on line 40? Do we need it for some reason other than LLVM's profile writing?
Member
There was a problem hiding this comment.
Oh, is that what "interleave output" means? So the idea is to guard against parallel Fatals?
Member
Author
There was a problem hiding this comment.
Yeah. Not necessary when considering just the use case of ensuring consistent profile writes, but seems like a nice improvement at best and harmless at worst.
kripken
approved these changes
Nov 30, 2026
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fatal::~Fatal terminates via _Exit to avoid running static destructors, which bypasses the atexit handlers registered by LLVM's instrumentation profile runtime and drops profile data on fatal error paths.
Move the exit path into a mutex-serialized Fatal::exit helper in src/support/utilities.cpp. When __LLVM_INSTR_PROFILE_GENERATE is defined, Fatal::~Fatal passes the caller's __llvm_profile_write_file function pointer to Fatal::exit, which flushes the library's profile runtime and, if the function pointer is distinct, the caller's profile runtime as well. This flushes both runtimes in shared-library builds where the library and executables each link a separate hidden copy of the profile runtime, while avoiding duplicate writes when both resolve to the same copy.
Also remove unused includes from src/support/utilities.h (, , , and "support/bits.h") and add the missing #include to src/support/string.h.