The use of the -fno-threadsafe-statics eliminates the function references to the guard functions, __cxa_guard_acquire __cxa_guard_release but it doesn't eliminate the variables used to guard the initialization. A compiled version of the attached file using the g++ command line therein generated no references to the guard functions, but the guard variable remains. # nm -C guard | grep guard 0000000000600a88 b guard variable for f()::a
I neglected to include the version information: # g++ --version g++ (Debian 4.9.2-10) 4.9.2
You need the variable even without thread safe ones because calling the function twice means it gets initlized only once rather twice. There is no other way around this because the variable only gets initialized if the function is called.
I've come to the same conclusion. My hope was that I could eliminate the guard and force the compiler to initialize block scoped statics at the start of execution. It looks like the standard stands in the way of this simplification.
*** Bug 66173 has been marked as a duplicate of this bug. ***