Skip to content

Ensure manage_exception_state uses correct TLS#324

Merged
olk merged 2 commits intoboostorg:developfrom
zhykzhykzhyk:patch-1
Mar 10, 2026
Merged

Ensure manage_exception_state uses correct TLS#324
olk merged 2 commits intoboostorg:developfrom
zhykzhykzhyk:patch-1

Conversation

@zhykzhykzhyk
Copy link
Contributor

Solves #323

@CreoValis
Copy link

Wouldn't access through a volatile * be a better solution here? The "no inline" spec probably works around the issue, but that just seems to push the dtor body to the point where gcc couldn't "see into it" to optimize it away.
I think using a volatile pointer cast would forbid it from even optimizing it away.

Like so:

    manage_exception_state() {
        exception_state_ = *(volatile __cxa_eh_globals *)__cxa_get_globals();
    }
    ~manage_exception_state() {
        *(volatile __cxa_eh_globals *)__cxa_get_globals() = exception_state_;
    }
`

@olk olk merged commit 86436e4 into boostorg:develop Mar 10, 2026
14 of 34 checks passed
@olk
Copy link
Member

olk commented Mar 10, 2026

ty

@pdimov
Copy link
Member

pdimov commented Mar 10, 2026

This merge causes build failures on Linux:

gcc.compile.c++ bin.v2/libs/fiber/build/gcc-11/release/x86_64/threading-multi/visibility-hidden/algo/round_robin.o
In file included from ./boost/context/fiber.hpp:12,
                 from ./boost/fiber/context.hpp:28,
                 from ./boost/fiber/algo/round_robin.hpp:16,
                 from /home/runner/work/boost/boost/libs/fiber/src/algo/round_robin.cpp:7:
./boost/context/fiber_fcontext.hpp: In constructor ‘__cxxabiv1::manage_exception_state::manage_exception_state()’:
./boost/context/fiber_fcontext.hpp:91:76: error: ambiguous overload for ‘operator=’ (operand types are ‘__cxxabiv1::__cxa_eh_globals’ and ‘volatile __cxxabiv1::__cxa_eh_globals’)
   91 |         exception_state_ = *(volatile __cxa_eh_globals *)__cxa_get_globals();
      |                                                                            ^
./boost/context/fiber_fcontext.hpp:83:8: note: candidate: ‘constexpr __cxxabiv1::__cxa_eh_globals& __cxxabiv1::__cxa_eh_globals::operator=(const __cxxabiv1::__cxa_eh_globals&)’ (near match)
   83 | struct __cxa_eh_globals {
      |        ^~~~~~~~~~~~~~~~
./boost/context/fiber_fcontext.hpp:83:8: note:   conversion of argument 1 would be ill-formed:
./boost/context/fiber_fcontext.hpp:91:28: error: binding reference of type ‘const __cxxabiv1::__cxa_eh_globals&’ to ‘volatile __cxxabiv1::__cxa_eh_globals’ discards qualifiers
   91 |         exception_state_ = *(volatile __cxa_eh_globals *)__cxa_get_globals();
      |                            ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
./boost/context/fiber_fcontext.hpp:83:8: note: candidate: ‘constexpr __cxxabiv1::__cxa_eh_globals& __cxxabiv1::__cxa_eh_globals::operator=(__cxxabiv1::__cxa_eh_globals&&)’ (near match)
   83 | struct __cxa_eh_globals {
      |        ^~~~~~~~~~~~~~~~
./boost/context/fiber_fcontext.hpp:83:8: note:   conversion of argument 1 would be ill-formed:
./boost/context/fiber_fcontext.hpp:91:28: error: cannot bind rvalue reference of type ‘__cxxabiv1::__cxa_eh_globals&&’ to lvalue of type ‘volatile __cxxabiv1::__cxa_eh_globals’
   91 |         exception_state_ = *(volatile __cxa_eh_globals *)__cxa_get_globals();
      |                            ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
./boost/context/fiber_fcontext.hpp: In destructor ‘__cxxabiv1::manage_exception_state::~manage_exception_state()’:
./boost/context/fiber_fcontext.hpp:94:61: error: passing ‘volatile __cxxabiv1::__cxa_eh_globals’ as ‘this’ argument discards qualifiers [-fpermissive]
   94 |         *(volatile __cxa_eh_globals *)__cxa_get_globals() = exception_state_;
      |                                                             ^~~~~~~~~~~~~~~~
./boost/context/fiber_fcontext.hpp:83:8: note:   in call to ‘constexpr __cxxabiv1::__cxa_eh_globals& __cxxabiv1::__cxa_eh_globals::operator=(const __cxxabiv1::__cxa_eh_globals&)’
   83 | struct __cxa_eh_globals {
      |        ^~~~~~~~~~~~~~~~

https://github.com/boostorg/boost/actions/runs/22891458318/job/66415405269

@pdimov
Copy link
Member

pdimov commented Mar 10, 2026

@grisumbras
Copy link
Member

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants