> As far as I know, that should work. However, if your program uses > dlopen, then gcc needs the __cxa_atexit function to destroy globals in > the right order. Thanks Ian. How do I figure out if my program uses dlopen and is there a way around that? Also, I have attached a simple piece of code which replicates the problem. While built/run on solaris/gcc it gives the following output: Function static 1 constructor called Function static 2 constructor called Global static 1 constructor called Global static 2 constructor called Function static 2 destructor called Function static 1 destructor called Global static 2 destructor called Global static 1 destructor called The function statics are both created and destroyed before global statics which is incorrect. http://old.nabble.com/file/p30238350/gcc-statics.cpp gcc-statics.cpp Ian Lance Taylor-3 wrote: > > rvyas <rishabh.a.vyas@xxxxxxxxx> writes: > >> We recently had a weird memory corruption issue in our project during >> destruction. The problem boiled down to order of destruction of >> statics. They should have been destroyed in the exact reverse order of >> the completion of their respective constructors. However gcc did not >> preserve the order of destruction across block scope statics and >> namespace scope statics. > > As far as I know, that should work. However, if your program uses > dlopen, then gcc needs the __cxa_atexit function to destroy globals in > the right order. And with regard to __cxa_atexit: > >> /var/tmp//cc3nl8Dr.o: In function >> `__static_initialization_and_destruction_0(int, int)': >> temp.cpp:(.text+0x6a): undefined reference to `__cxa_atexit' > > there's the problem. The __cxa_atexit function is available in glibc on > GNU/Linux systems but is not in the Solaris library. I don't know of a > way to run destructors in the right order in the presence of dlopen > without __cxa_atexit. > > Ian > > -- View this message in context: http://old.nabble.com/Using-__cxa_atexit-on-Solaris-tp30232909p30238350.html Sent from the gcc - Help mailing list archive at Nabble.com.