I had a crash in cxa_finalize
running a program (this is a program, not a library inside):
$ ./ac-test.exe Assertion failed: AcLock.cpp(54): AcLock libc++abi.dylib: terminate called without an active exception Abort trap: 6
An assertion / failure is associated with the interaction between the entity and the registrar. The logger is destroyed in front of the object, but the object uses the logger. Thus, a mutex that receives a pop-up confirmation or a failure has already been destroyed (therefore, the reason pthread_mutex_lock
does not work when the registrar is blocked).
I read the GCC manual on Specifying Variable Attributes and Declaring Function Attributes , but I obviously missed something.
I placed the object and the logger in a common header inside accessors and tried to specify the construction order:
// AcGlobals.h static AcLogger& GetLogger() { static AcLogger logger __attribute__(init_priority(50)); return logger; } static AcSocketList& GetAcceptSockets() { static AcSocketList sockets __attribute__(init_priority(100)); return sockets; }
This led to many errors:
./AcGlobals.h:24:46: error: expected ';' at end of declaration static AcLogger logger __attribute__((init_priori... ./AcGlobals.h:24:47: warning: declaration does not declare anything [-Wmissing-declarations] static AcLogger logger __attribute__((init_priori...
I also tried to place a function attribute, not a variable:
// AcGlobals.h static AcLogger& GetLogger() __attribute__(init_priority(50)) { static AcLogger logger; return logger; } static AcSocketList& GetAcceptSockets() __attribute__(init_priority(100)) { static AcSocketList sockets; return sockets; }
As a result, more problems appeared:
./AcGlobals.h:22:53: warning: GCC does not allow init_priority attribute in this position on a function definition [-Wgcc-compat] static AcLogger& GetLogger() __attribute__((init_priority(50))) { ^ ./AcGlobals.h:22:53: error: can only use 'init_priority' attribute on file-scope definitions of objects of class type
I also tried __attribute__((constructor(50)))
instead of init_priority
without joy.
Note. I am working on an Apple machine. Apple has a βfeatureβ where constructor priority applies only to decorated functions and variables in a single file. Therefore, they cannot be distributed between translation units.
How to specify the order of construction and destruction of local static objects?
c ++ gcc initialization clang
jww Dec 03 '13 at 8:52 2013-12-03 08:52
source share