Does anyone know a general rule for which LLVM IR code will be executed before main?
When using Clang ++ 3.6, it seems that the global class variables have their own constructors, called through a function in the ".text.startup" section of the object file. For instance:
define internal void @__cxx_global_var_init() section ".text.startup" {
call void @_ZN7MyClassC2Ev(%class.MyClass* @M)
ret void
}
In this example, I would suggest that I should look for exactly those IR function definitions that indicate section ".text.startup".
I have two reasons to suspect that my theory is correct:
I don’t see anything else in my LLVM IR file ( .ll)suggesting to start global object constructors first, assuming LLVM doesn’t sniff for C ++ functional function names like "__cxx_global_var_init". Thus, the section ".text.startup"only obvious way to say that the code should work up to main(). But even if it’s correct, we have defined a sufficient condition for starting the function up main(), but haven’t shown that this is the only way in LLVM IR to call the function before main().
Gnu, , .text , Pi , .text.startup , .text , .text.startup.
, , :
grep LLVM 3.6 ".startup", CLAN LLVM. , , LLVM; , , ++.
++, , ".text.startup", , " , Linux . , , Linux , LLVM IR.
Linux 3.13.0, , ".startup", , ".text.startup".