[cfe-dev] Priority settings for static variables and __attribute__((destructor))

Anton Korobeynikov anton at korobeynikov.info
Sun Feb 17 04:01:28 PST 2013


> When dylib unloaded, the static variable Resource will be unloaded first
> then clang will call shutdown() with a crash.   I tried GCC style
> __attribute__((destructor(100))) to set the priority but it seems that clang
> cannot recongnised this.
It does recognize this, but on darwin constructor / destructor
priorities works only inside single module.

> Is there anyway I can precisely constrol the order of static variables
> deconstruction and attributed destructor functions in clang.  My environment
> is Mac OS X 10.7.5, Xcode 4.6 with clang-425.0.24 x86_64-aple-darwin11.4.2
If I remember correctly, on darwin the order of ctors / dtors is
induced by link order. Though, in general you cannot rely on this :)

With best regards, Anton Korobeynikov
Faculty of Mathematics and Mechanics, Saint Petersburg State University

More information about the cfe-dev mailing list