[LLVMdev] C++ Constructors

Chris Lattner clattner at apple.com
Thu Dec 11 14:43:40 PST 2008


On Dec 11, 2008, at 2:35 PM, John Criswell wrote:

> Dear All,
>
> Are global static constructors called before main() in LLVM these days
> using some behind-the-scenes magic that is not explicit in the LLVM
> bitcode?

It is explicit in the bitcode.  You should see an llvm.globalctors  
global array that has function pointers for each initializer to run.

>  In older versions of LLVM, llvm-gcc added an explicit function
> call to __main() as the first instruction in main(); __main() would  
> call
> all global static constructors.  It seems __main() is now gone.

Yep, __main is now gone, llvm.globalctors is king. :)

-Chris



More information about the llvm-dev mailing list