Hi LLVMDev, The GCC frontend for LLVM inserts a call to a __main() in the main() function. Whats the purpose of this? And which LLVM library do I need to link to satisfy the reference? Thanks, Rahul
> Hi LLVMDev, > > The GCC frontend for LLVM inserts a call to a __main() in the > main() function. Whats the purpose of this? And which LLVM > library do I need to link to satisfy the reference?__main is used primarily to call static constructors. The way you satisfy this dependency is to link the bytecode file against crtend.o (aka libcrtend.bc). This is normally accomplished by using gccld (or by llvm-gcc <bytecode files> -o program, which calls gccld). If you're in a pinch, and you absolutely know for sure that you won't ever have any static constructors called in your program, you can replace __main with an empty function. But I heartily recommend the solution above, because it's much more complete and only minimally more painful. Hope this helps, -Brian -- gaeke at uiuc.edu
On Mon, 27 Oct 2003, Brian R. Gaeke wrote:> __main is used primarily to call static constructors. The way you > satisfy this dependency is to link the bytecode file against crtend.o > (aka libcrtend.bc). This is normally accomplished by using gccld > (or by llvm-gcc <bytecode files> -o program, which calls gccld).Brian is absolutely right. Note that static constructors really only happen in C++ programs (or C programs which use the GCC constructor/destructor extensions, which are really really rare). However, gccld should elimination all of the overhead of the __main function if the functionality is not used, so C programs don't suffer any overhead, and you can just delete the call to __main if it is causing you grief. If you're interested, the source code for __main lives in: llvm/runtime/GCCLibraries/crtend/crtend.c & listend.ll -Chris -- http://llvm.cs.uiuc.edu/ http://www.nondot.org/~sabre/Projects/
Maybe Matching Threads
- [LLVMdev] Using llvm-gcc with a simple program and the '-c' option
- [LLVMdev] Using llvm-gcc with a simple program and the '-c' option
- [LLVMdev] Building llvm and cfrontend under cygwin
- [LLVMdev] Building the llvm runtime: 'Can't destroy file: The process cannot access the fi
- [LLVMdev] Using llvm-gcc with a simple program and the '-c' option