[LLVMdev] Using llvm-gcc with a simple program and the '-c' option

Misha Brukman brukman at cs.uiuc.edu
Sun Feb 26 22:17:07 PST 2006


On Sun, Feb 26, 2006 at 10:00:18PM -0800, Wink Saville wrote:
> Thanks for the info, you've confirmed what I was trying to do, but when 
> I compile:
[snip]
> without "-c" (llvm-gcc t1.c -o t1) the dissassembled bytecode does not 
> call __main:

__main() is used to run static constructors and destructors, so if
you're compiling without -c, LLVM knows all the files you're compiling
and if there are no static constructors, __main() is not necessary (or
if it's there, it's empty, and can be inlined into a no-op).

[snip]
> But if I use the "-c" option (llvm-gcc -c t1.c -o t1.bc) the bytecode
> is:

If you're using -c, you're telling LLVM that there are other modules you
will link into the executable.  Thus, LLVM does not know whether there
will be static ctors/dtors to run or not, so there's the call to
__main() from main.

__main() gets linked into your program if you use gccld (which is what
llvm-gcc uses) or llvm-ld manually.  The __main() itself comes from one
of the runtime libraries: llvm/runtime/GCCLibraries/crtend/crtend.c .

-- 
Misha Brukman :: http://misha.brukman.net




More information about the llvm-dev mailing list