Wink Saville
2006-Feb-27 04:02 UTC
[LLVMdev] Using llvm-gcc with a simple program and the '-c' option
Hello, When I compile a "hello.c" program with a printf in "main" and use llvm-gcc with a "-c" option: llvm-gcc -c t1.c -o t1.bc and then try to compile t1.bc to native using llc & gcc I get a call to "__main" which is undefined. If I don't use the "-c" option: llvm-gcc t1.c -o t1 I don't get a reference to "__main" and I can compile to native without problem. Also, I created some simple modules without a "main" and using the "-c" option and that works as expected. What am I doing wrong? Thanks, Wink Saville
Robert L. Bocchino Jr.
2006-Feb-27 05:12 UTC
[LLVMdev] Using llvm-gcc with a simple program and the '-c' option
The -c option tells llvm-gcc to build a bytecode file without linking in the LLVM runtime library. This is similar to the -c option for regular gcc, which you use to build multiple separate .o files that you're going to link into a single executable. If you want to build from a single source file, it's easiest just to compile without the -c option. If you're building from multiple source files, you can either give them all to llvm-gcc at the same time with no -c option llvm-gcc foo.c bar.c -o foobar or compile separately with -c and then link them together llvm-gcc -c foo.c -o foo.bc llvm-gcc -c bar.c -o bar.bc llvm-gcc foo.bc bar.bc -o foobar You can also use llvm-ld for the last step. Rob On Sunday, February 26, 2006, at 10:02 PM, Wink Saville wrote:> Hello, > > When I compile a "hello.c" program with a printf in "main" and use > llvm-gcc with a "-c" option: > > llvm-gcc -c t1.c -o t1.bc > > and then try to compile t1.bc to native using llc & gcc I get a call > to "__main" which is undefined. > > If I don't use the "-c" option: > > llvm-gcc t1.c -o t1 > > I don't get a reference to "__main" and I can compile to native > without problem. Also, I created some simple modules without a "main" > and using the "-c" option and that works as expected. What am I doing > wrong? > > Thanks, > > Wink Saville > > _______________________________________________ > LLVM Developers mailing list > LLVMdev at cs.uiuc.edu http://llvm.cs.uiuc.edu > http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev >Robert L. Bocchino Jr. 1950 South Orchard St., Apt. A Urbana, IL 61801 (217) 979-1053
Wink Saville
2006-Feb-27 06:00 UTC
[LLVMdev] Using llvm-gcc with a simple program and the '-c' option
Robert, Thanks for the info, you've confirmed what I was trying to do, but when I compile: ----------------------- #include <stdio.h> int main(int argc, char *argv[]) { printf("yo\n"); return 0; } ----------------------- without "-c" (llvm-gcc t1.c -o t1) the dissassembled bytecode does not call __main: ----------------------- ; ModuleID = '<stdin>' target endian = little target pointersize = 32 target triple = "i686-pc-linux-gnu" deplibs = [ "c", "crtend" ] %struct..TorRec = type { int, void ()* } %struct.TorRec = type { int, void ()* } %.str_1 = internal constant [4 x sbyte] c"yo\0A\00" ; <[4 x sbyte]*> [#uses=1] implementation ; Functions: declare int %printf(sbyte*, ...) int %main(int %argc, sbyte** %argv) { entry: %tmp.0 = tail call int (sbyte*, ...)* %printf( sbyte* getelementptr ([4 x sbyte]* %.str_1, int 0, int 0) ) ; <int> [#uses=0] ret int 0 } ----------------------- But if I use the "-c" option (llvm-gcc -c t1.c -o t1.bc) the bytecode is: ----------------------- ; ModuleID = '<stdin>' target endian = little target pointersize = 32 target triple = "i686-pc-linux-gnu" deplibs = [ "c", "crtend" ] %.str_1 = internal constant [4 x sbyte] c"yo\0A\00" ; <[4 x sbyte]*> [#uses=1] implementation ; Functions: declare int %printf(sbyte*, ...) int %main(int %argc, sbyte** %argv) { entry: tail call void %__main( ) %tmp.0 = tail call int (sbyte*, ...)* %printf( sbyte* getelementptr ([4 x sbyte]* %.str_1, int 0, int 0) ) ; <int> [#uses=0] ret int 0 } declare void %__main() -------------------------- Note the call to %__main. 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] __main() function and AliasSet
- [LLVMdev] How could I hide the visible string?
- [LLVMdev] Re: __main() function and AliasSet