#else
-// Single-threaded fallback buffer.
-static __cxa_eh_globals eh_globals;
+#if __has_cpp_attribute(clang::require_constant_initialization)
+# define __constinit [[clang::require_constant_initialization]]
+#endif
+
+namespace
+{
+ struct constant_init
+ {
+ union {
+ unsigned char unused;
+ __cxa_eh_globals obj;
+ };
+ constexpr constant_init() : obj() { }
+
+ ~constant_init() { /* do nothing, union member is not destroyed */ }
+ };
+
+ // Single-threaded fallback buffer.
+ __constinit constant_init eh_globals;
+}
#if __GTHREADS
struct __eh_globals_init
{
__gthread_key_t _M_key;
- bool _M_init;
+ static bool _S_init;
- __eh_globals_init() : _M_init(false)
- {
+ __eh_globals_init()
+ {
if (__gthread_active_p())
- _M_init = __gthread_key_create(&_M_key, eh_globals_dtor) == 0;
+ _S_init = __gthread_key_create(&_M_key, eh_globals_dtor) == 0;
}
~__eh_globals_init()
{
- if (_M_init)
+ if (_S_init)
__gthread_key_delete(_M_key);
- _M_init = false;
+ _S_init = false;
}
+
+ __eh_globals_init(const __eh_globals_init&) = delete;
+ __eh_globals_init& operator=(const __eh_globals_init&) = delete;
};
+bool __eh_globals_init::_S_init = false;
+
static __eh_globals_init init;
extern "C" __cxa_eh_globals*
__cxxabiv1::__cxa_get_globals_fast() _GLIBCXX_NOTHROW
{
__cxa_eh_globals* g;
- if (init._M_init)
+ if (init._S_init)
g = static_cast<__cxa_eh_globals*>(__gthread_getspecific(init._M_key));
else
- g = &eh_globals;
+ g = &eh_globals.obj;
return g;
}
__cxxabiv1::__cxa_get_globals() _GLIBCXX_NOTHROW
{
__cxa_eh_globals* g;
- if (init._M_init)
+ if (init._S_init)
{
g = static_cast<__cxa_eh_globals*>(__gthread_getspecific(init._M_key));
if (!g)
}
}
else
- g = &eh_globals;
+ g = &eh_globals.obj;
return g;
}
extern "C" __cxa_eh_globals*
__cxxabiv1::__cxa_get_globals_fast() _GLIBCXX_NOTHROW
-{ return &eh_globals; }
+{ return &eh_globals.obj; }
extern "C" __cxa_eh_globals*
__cxxabiv1::__cxa_get_globals() _GLIBCXX_NOTHROW
-{ return &eh_globals; }
+{ return &eh_globals.obj; }
#endif