I ran into this problem. Here are the conditions which seem to reliably generate the trouble:
- g++ linking without the C/C++ standard library:
-nostdlib
(typical small embedded scenario).
- Defining a statically allocated standard library object; specific to my case is
std::vector
. Previously this was std::array
statically allocated without any problems. Apparently not all std::
statically allocated objects will cause the problem.
- Note that I am not using a shared library of any type.
- GCC/ARM cross compiler is in use.
If this is your use case then merely add the command line option to your compile/link command line: -fno-use-cxa-atexit
Here is a very good link to the __dso_handle usage as 'handle to dynamic shared object'.
There appears to be a typo in the page, but I have no idea who to contact to confirm:
After you have called the objects' constructor destructors GCC automatically calls the function ...
I think this should read "Once all destructors have been called GCC calls the function" ...
One way to confirm this would be to implement the __cxa_atexit
function as mentioned and then single step the program and see where it gets called. I'll try that one of these days, but not right now.