Wink Saville
2006-Feb-27 07:44 UTC
[LLVMdev] Using llvm-gcc with a simple program and the '-c' option
Misha Brukman wrote:> On Sun, Feb 26, 2006 at 10:00:18PM -0800, Wink Saville wrote: > >[snip]> 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, Great now I understand, one more related question. This actually started trying to understand how llvm-gcc, llvm-ar, llvm-ld & llc work together. With the help I've received I've successfully used them to create a native executable of 3 files, t1.c, t1sub1.c t1sub2.c, where t1.c calls a subroutine in t1sub1.c and t1sub2.c. I then do the following in my makefile: llvm-gcc -c t1.c -o t1.bc llvm-gcc -c t1sub1.c -o t1sub1.bc llvm-gcc -c t1sub2.c -o t1sub2.bc llvm-ar r t1.a t1sub1.bc t1sub2.bc llvm-ar: creating t1.a llvm-ld -o t1.app t1.bc t1.a /opt/llvm-1.6/llvm-gcc/lib/libcrtend.a llvm-ld: warning: Cannot find library 'crtend' llc t1.app.bc -o t1.app.s gcc -m32 t1.app.s -o t1 So a few minor problems, the first is really minor the llvm-ld command generates the t.app script that runs t1.app.bc, obviously no big deal, but isn't what I expected and would seem to be to be unnecessary. Another is the warning: llvm-ld: warning: Cannot find library 'crtend' I tried: llvm-ld -o t1.app t1.bc t1.a -L/opt/llvm-1.6/llvm-gcc/lib -lcrtend But that gives me two cannot find library warnings and __main is undefined. Again, the when using libcrtend.a directly everything works bit gives the warning which seems very odd as it is "obviously" there. Also, why does the second version not work? Thanks again, Wink
Chris Lattner
2006-Feb-27 20:55 UTC
[LLVMdev] Using llvm-gcc with a simple program and the '-c' option
On Sun, 26 Feb 2006, Wink Saville wrote:> I then do the following in my makefile: > > llvm-gcc -c t1.c -o t1.bc > llvm-gcc -c t1sub1.c -o t1sub1.bc > llvm-gcc -c t1sub2.c -o t1sub2.bc > llvm-ar r t1.a t1sub1.bc t1sub2.bc > llvm-ar: creating t1.a > llvm-ld -o t1.app t1.bc t1.a /opt/llvm-1.6/llvm-gcc/lib/libcrtend.a > llvm-ld: warning: Cannot find library 'crtend'Try passing "-L/opt/llvm-1.6/llvm-gcc/lib/ -lcrtend" to llvm-ld. Alternatively, instead of using llvm-ld, just use gccld to link like this: llvm-gcc -o t1.app t1.bc t1.a ... which should work.> llc t1.app.bc -o t1.app.s > gcc -m32 t1.app.s -o t1If you want a native app, try this: llvm-gcc -o t1.app t1.bc t1.a -Wl,-native ... which will invoke llc and the assembler for you. This will also fix the "script + bc" issue. -Chris -- http://nondot.org/sabre/ http://llvm.org/
Wink Saville
2006-Feb-28 04:43 UTC
[LLVMdev] Using llvm-gcc with a simple program and the '-c' option
Chris Lattner wrote:> On Sun, 26 Feb 2006, Wink Saville wrote: >> I then do the following in my makefile: >> >> llvm-gcc -c t1.c -o t1.bc >> llvm-gcc -c t1sub1.c -o t1sub1.bc >> llvm-gcc -c t1sub2.c -o t1sub2.bc >> llvm-ar r t1.a t1sub1.bc t1sub2.bc >> llvm-ar: creating t1.a >> llvm-ld -o t1.app t1.bc t1.a /opt/llvm-1.6/llvm-gcc/lib/libcrtend.a >> llvm-ld: warning: Cannot find library 'crtend' > > Try passing "-L/opt/llvm-1.6/llvm-gcc/lib/ -lcrtend" to llvm-ld.This didn't work for me: llvm-ld -o t1.app t1.bc t1.a -L/opt/llvm-1.6/llvm-gcc/lib/ -lcrtend.a I get two warning's about library 'crtend' missing> Alternatively, instead of using llvm-ld, just use gccld to link like > this: > > llvm-gcc -o t1.app t1.bc t1.a >Yes this works, but not native> ... which should work. > >> llc t1.app.bc -o t1.app.s >> gcc -m32 t1.app.s -o t1 > > If you want a native app, try this: > > llvm-gcc -o t1.app t1.bc t1.a -Wl,-native > > ... which will invoke llc and the assembler for you. This will also > fix the "script + bc" issue.Yes this works and doesn't generate the script but since I'm using an amd64 with linux the result doesn't run because I need the -m32.> > -Chris >Actually, the point of the above was to understand how the flow native and to see what difficulties I ran into. Is it a bug that I get the "llvm-ld: warning: Cannot find library 'crtend'"? If so, is it likely to be in llvm code and would it be something you'd let a neophyte to track down? Wink
Possibly Parallel 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] Using llvm-gcc with a simple program and the '-c' option
- [LLVMdev] Using llvm-gcc with a simple program and the '-c' option
- [LLVMdev] Using llvm-gcc with a simple program and the '-c' option