[LLVMdev] llvmc doesn't work for compilation nor linking
Holger Schurig
hs4233 at mail.mn-solutions.de
Tue Aug 28 08:36:25 PDT 2007
> If you would like to work on it, patches are welcomed!
I think this problem space matched my capabilities, below is a
patch. With this patch applied, the following worked:
$ llvmc -verbose -native -lstdc++ -o hellocpp hello.cpp
g++ -E hello.cpp -o /tmp/llvm_30nlL0/hello.E
/usr/src/llvm/dist/libexec/gcc/i686-pc-linux-gnu/4.0.1/cc1plus -quiet -emit-llvm /tmp/llvm_30nlL0/hello.E -o /tmp/llvm_30nlL0/hello.trans -O1
llvm-as /tmp/llvm_30nlL0/hello.trans -o /tmp/llvm_30nlL0/hello.trans.bc
/usr/src/llvm/dist/bin/opt /tmp/llvm_30nlL0/hello.trans.bc -std-compile-opts -f -o /tmp/llvm_30nlL0/hello.opt
llvm-ld -O1 /tmp/llvm_30nlL0/hello.opt -lstdc++ -L%llvmgccdir%/lib -L%llvmgccdir%/lib -L/usr/local/lib/ -L/usr/X11R6/lib/ -L/usr/lib/ -L/lib/ -native -v -o hellocpp
Linking bitcode file '/tmp/llvm_30nlL0/hello.opt'
Linked in file '/tmp/llvm_30nlL0/hello.opt'
Linking archive file '/usr/src/llvm/dist/lib/libstdc++.a'
Generating Bitcode To hellocpp.bc
Generating Assembly With:
'/usr/src/llvm/dist/bin/llc' '-f' '-o' 'hellocpp.s' 'hellocpp.bc'
Generating Native Executable With:
'/usr/bin/gcc' '-fno-strict-aliasing' '-O3' '-o' 'hellocpp' 'hellocpp.s' '-L' '%llvmgccdir%/lib' '-L' '%llvmgccdir%/lib' '-L' '/usr/local/lib/' '-L' '/usr/X11R6/lib/' '-L' '/usr/lib/' '-L' '/lib/' '-lstdc++'
$ llvmc -verbose -native -o helloc hello.c
gcc -E hello.c -o /tmp/llvm_XpaR7m/hello.E
/usr/src/llvm/dist/libexec/gcc/i686-pc-linux-gnu/4.0.1/cc1 -quiet -emit-llvm /tmp/llvm_XpaR7m/hello.E -o /tmp/llvm_XpaR7m/hello.trans -O1
llvm-as /tmp/llvm_XpaR7m/hello.trans -o /tmp/llvm_XpaR7m/hello.trans.bc
/usr/src/llvm/dist/bin/opt /tmp/llvm_XpaR7m/hello.trans.bc -std-compile-opts -f -o /tmp/llvm_XpaR7m/hello.opt
llvm-ld -O1 /tmp/llvm_XpaR7m/hello.opt -L%llvmgccdir%/lib -L%llvmgccdir%/lib -L/usr/local/lib/ -L/usr/X11R6/lib/ -L/usr/lib/ -L/lib/ -native -v -o helloc
Linking bitcode file '/tmp/llvm_XpaR7m/hello.opt'
Linked in file '/tmp/llvm_XpaR7m/hello.opt'
Generating Bitcode To helloc.bc
Generating Assembly With:
'/usr/src/llvm/dist/bin/llc' '-f' '-o' 'helloc.s' 'helloc.bc'
Generating Native Executable With:
'/usr/bin/gcc' '-fno-strict-aliasing' '-O3' '-o' 'helloc' 'helloc.s' '-L' '%llvmgccdir%/lib' '-L' '%llvmgccdir%/lib' '-L' '/usr/local/lib/' '-L' '/usr/X11R6/lib/' '-L' '/usr/lib/' '-L' '/lib/'
$ size helloc hellocpp
text data bss dec hex filename
911 260 4 1175 497 helloc
1427 288 148 1863 747 hellocpp
I'll look after the strange '-L' '%llvmgccdir%/lib' in a
separate patch, but I guess that this has something to do with
the configure call I made for LLVM.
Now the patch:
------------------------------------------------------------------
Add "-emit-llvm" to the cc1 call so that cc1 to trigger usage
of the llvm-framework
Use "opt" instead of the deprecated "ggcas". For now, use
"-std-compile-opts" just like the "gccas" shell script.
Fix optimizer output, it was "bytecode" which was wrong:
* the lexer knows "bitcode", but not "bytecode"
* the optimizer produces human-readable code, so it must
be assembly anyway
Index: tools/llvmc/cpp
===================================================================
--- tools/llvmc/cpp (revision 41536)
+++ tools/llvmc/cpp (working copy)
@@ -25,7 +25,7 @@
##########################################################
# To compile C++ source, just use llvm-g++'s cc1
- translator.command=%llvmcc1plus% -quiet %in% -o %out% \
+ translator.command=%llvmcc1plus% -quiet -emit-llvm %in% -o %out% \
%opt% %incls% %defs% %WOpts% %fOpts% %MOpts% %args% \
-D_GNU_SOURCE
@@ -42,18 +42,18 @@
# Optimizer definitions
##########################################################
- # Use gccas to clean up the generated code
- optimizer.command=%bindir%/gccas %in% -o %out% %args%
+ # Use opt to clean up the generated code
+ optimizer.command=%bindir%/opt %in% -std-compile-opts -f -o %out% %args%
optimizer.required = true
- # gccas doesn't translate
+ # opt doesn't translate
optimizer.translates = false
- # gccas doesn't preprocess
+ # opt doesn't preprocess
optimizer.preprocesses=false
- # gccas produces bytecode
- optimizer.output = bytecode
+ # opt produces assembly
+ optimizer.output = assembly
##########################################################
# Assembler definitions
Index: tools/llvmc/c
===================================================================
--- tools/llvmc/c (revision 41536)
+++ tools/llvmc/c (working copy)
@@ -24,7 +24,7 @@
##########################################################
# To compile C source, just use llvm-gcc's cc1
- translator.command=%llvmcc1% -quiet %in% -o %out% \
+ translator.command=%llvmcc1% -quiet -emit-llvm %in% -o %out% \
%opt% %incls% %defs% %WOpts% %fOpts% %MOpts% %args% \
-D_GNU_SOURCE
@@ -41,18 +41,18 @@
# Optimizer definitions
##########################################################
- # Use gccas to clean up the generated code
- optimizer.command=%bindir%/gccas %in% -o %out% %args%
+ # Use opt to clean up the generated code
+ optimizer.command=%bindir%/opt %in% -std-compile-opts -f -o %out% %args%
optimizer.required = true
- # gccas doesn't translate
- optimizer.translates = false
+ # opt doesn't translate
+ optimizer.translates = true
- # gccas doesn't preprocess
+ # opt doesn't preprocess
optimizer.preprocesses=false
- # gccas produces bytecode
- optimizer.output = bytecode
+ # opt produces llvm assembly
+ optimizer.output = assembly
##########################################################
# Assembler definitions
Index: tools/llvmc/st
===================================================================
--- tools/llvmc/st (revision 41536)
+++ tools/llvmc/st (working copy)
@@ -36,7 +36,7 @@
translator.required=false
# stkrc doesn't handle the -On options
- translator.output=bytecode
+ translator.output=bitcode
##########################################################
# Optimizer definitions
@@ -54,8 +54,8 @@
# opt doesn't preprocess
optimizer.preprocesses=yes
- # opt produces bytecode
- optimizer.output = bc
+ # opt produces assembly
+ optimizer.output = assembly
##########################################################
# Assembler definitions
More information about the llvm-dev
mailing list