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? 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. I've got a transform that instruments all code in a program (including constructors) with calls to a run-time library. I need to make sure that the call to the run-time library happens before main() is called or any static constructors are called. -- John T.
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
Chris Lattner wrote:> 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. >Right, I saw that. I just didn't see anything from main() calling those functions, which led me to believe that something else is calling those functions before main().>> 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. :) >I assume putting my constructor at the head of the llvm.globalctors list will force it to be run before anything else? Is that correct? -- John T.> -Chris > _______________________________________________ > LLVM Developers mailing list > LLVMdev at cs.uiuc.edu http://llvm.cs.uiuc.edu > http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev >