fix: re-apply BOOST_NOINLINE to manage_exception_state (reverted in #324 merge)#331
Merged
olk merged 1 commit intoboostorg:developfrom May 8, 2026
Conversation
Member
|
ty |
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.
What happened
This is a re-application of the fix from #324. That PR was merged on Mar 10 with
BOOST_NOINLINEon the ctor/dtor ofmanage_exception_state, but the fix doesn't appear to be indevelopanymore - not sure exactly what happened, looks like it may have been reverted after the build failures reported by @pdimov and @grisumbras. Either way, the fix is gone and the issue is still hitting us in production.This PR just brings back commit da3fa4f from #324, without any other changes.
Why BOOST_NOINLINE
__cxa_get_globals()is a pure/const-attributed function, so the compiler is free to cache its return value across the constructor and destructor. If the fiber migrates to another thread between the two calls, both end up reading/writing the TLS slot of the original thread - wrong exception state on resume. The disassembly showing the single__cxa_get_globalscall is in the original issue: #323.Making the ctor/dtor
noinlineforces the compiler to treat them as opaque call sites and re-evaluate__cxa_get_globals()each time.Why not volatile
The
volatilecast (@CreoValis's suggestion in #324) prevents the compiler from optimizing away the dereference, but the pointer returned by__cxa_get_globals()can still be cached - it's the address computation that's the problem, not the access through it. The build failures on GCC confirmed it doesn't even compile cleanly, and it doesn't fix the root cause anyway.Prior art
Same fundamental issue is documented in userver-framework/userver#242, along with upstream compiler issues: llvm/llvm-project#98479, GCC #26461. The userver team's conclusion after investigating was the same:
noinlineis the only reliable workaround without a dedicated compiler flag for fiber-safe TLS.We're hitting this in production on Boost 1.87+ - the symptom is exception state ending up in the wrong thread after a fiber resumes on a different one.
Fixes #323