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

Huaxia 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.

From:

https://developer.apple.com/library/mac/#documentation/macosx/Conceptual/BPFrameworks/Tasks/InitializingFrameworks.html#//apple_ref/doc/uid/20002259-BDEIDDJG

"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?

Thanks.

Huaxia



On 17 February 2013 20:01, Anton Korobeynikov <anton at korobeynikov.info>wrote:

> Hello
>
> > 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
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20130217/63ba55c2/attachment.html>


More information about the cfe-dev mailing list