[cfe-dev] Priority settings for static variables and __attribute__((destructor))
huaxia.zhao at gmail.com
Sun Feb 17 05:23:20 PST 2013
Well, this would be a weak point since Apple recommend
__attribute__((destructor)) as a module finalizer.
"Module initializers are the preferred way to initialize a framework. A
module initializer is a static function that takes no arguments and returns
no value. It is declared using the constructor compiler attribute as shown
in Listing 1. "
Does this mean that the module ctor/dtor are unable to safely use any
existing static variables?
On 17 February 2013 20:01, Anton Korobeynikov <anton at korobeynikov.info>wrote:
> > 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
> > 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
> > is Mac OS X 10.7.5, Xcode 4.6 with clang-425.0.24
> 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
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the cfe-dev