[LLVMdev] How to compile apps to bc files with the new llvm-gcc4?

Reid Spencer rspencer at reidspencer.com
Sun Dec 10 08:31:01 PST 2006


On Sun, 2006-12-10 at 10:53 -0500, Chandler Carruth wrote:
> Unless I'm missing something, the problem lies directly with the fact
> that you are trying to do a link-stage operation with the GCC
> frontend. GCC, by default, probably runs "ld" or another system
> linker, which grabs the executable from binutils. This linker hasn't
> been modified (yet) to include support for .bc files, but you're
> compiler is emitting byte code to the *.o files. That is why the
> linker barfs, and tries to interpret as a script. 

Correct. In a discussion with Domagoj on IRC, it turns out that he
actually doesn't want to link a native executable. He just wants to get
a single linked .bc file for each program. llvm-gcc3 used to do this
because it linked with gccld which produces a .bc file and a shell
script for running that bc file with lli. I suggested to him that he
change his makefiles to simply link the llvm-gcc4 produced bytecode
files with gccld as did llvm-gcc3.

> I am actually planning on working on integration between binutils' ld
> and LLVM to allow just this functionality. I'll be working on this
> over the holidays, and hopefully will get something working by mid
> January. Until then, directly using the LLVM linking facilities to
> handle the bytecode is probably the best if not only option. 

We look forward to LTO in binutils. This will be a great addition to
LLVM (and binutils) that will make using bytecode more transparent than

> -Chandler
> PS: I'm still kinda new, so someone else may come along and correct
> me, but that's the best I can figure out...

You got it right, Chandler :)


> On 12/10/06, Domagoj Babic <babic.domagoj at gmail.com> wrote:
>         Hi,
>         I'm trying to compile some apps with the new llvm-gcc4 on
>         amd64 linux
>         to .bc files, rather than to the native code. The same process
>         I used to
>         build those apps before with llvm-gcc3 doesn't work:
>         1) 
>         export CC=llvm-gcc CXX=llvm-g++ CFLAGS="-g -fno-inline"
>         CXXFLAGS="-g
>         -fno-inline"
>         2) cd <whatever-app>; ./configure
>         3) make CFLAGS+=-emit-llvm CXXFLAGS+=-emit-llvm
>         [Reid told me not to pass -emit-llvm to configure scripts.] 
>         The process fails for the same reason on several apps I tried:
>         --------------------------------------------------------------
>         $ llvm-gcc
>         -shared  .libs/libdspam.o .libs/heap.o .libs/diction.o
>         .libs/base64.o .libs/buffer.o .libs/util.o .libs/nodetree.o 
>         .libs/error.o .libs/decode.o .libs/pref.o .libs/config_shared.o
>         .libs/bnr.o .libs/hash.o .libs/list.o .libs/ldap_client.o
>         .libs/tokenizer.o .libs/hash_drv.o  -lm -ldl  -Wl,-soname
>         -Wl,libdspam.so.7 -o .libs/libdspam.so.7.0.0 -v 
>         Using built-in specs.
>         Target: x86_64-unknown-linux-gnu
>         Configured with: ../dst-directory/configure --disable-shared
>         --prefix=/usr/local/devapps/llvm --enable-languages=c,c++
>         --enable-llvm=/work/projects/llvm-obj --program-prefix=llvm- 
>         --enable-checking --disable-multilib
>         Thread model: posix
>         gcc version 4.0.1 LLVM (Apple Computer, Inc. build 5421)
>         /usr/local/devapps/llvm/libexec/gcc/x86_64-unknown-linux-gnu/4.0.1/collect2
>         --eh-frame-hdr -m elf_x86_64 -shared
>         -o .libs/libdspam.so.7.0.0 
>         /usr/lib/../lib64/crti.o
>         /usr/local/devapps/llvm/lib/gcc/x86_64-unknown-linux-gnu/4.0.1/crtbeginS.o
>         -L/usr/local/devapps/llvm/lib/gcc/x86_64-unknown-linux-gnu/4.0.1
>         -L/usr/local/devapps/llvm/lib/gcc/x86_64-unknown-linux-gnu/4.0.1/../../../../lib64 
>         -L/usr/local/devapps/llvm/lib/gcc/x86_64-unknown-linux-gnu/4.0.1/../../..
>         -L/lib/../lib64
>         -L/usr/lib/../lib64 .libs/libdspam.o .libs/heap.o
>         .libs/diction.o .libs/base64.o .libs/buffer.o .libs/util.o
>         .libs/nodetree.o .libs/error.o .libs/decode.o .libs/pref.o 
>         .libs/config_shared.o .libs/bnr.o .libs/hash.o .libs/list.o
>         .libs/ldap_client.o .libs/tokenizer.o .libs/hash_drv.o -lm
>         -ldl
>         -soname libdspam.so.7 -lgcc -lc -lgcc
>         /usr/local/devapps/llvm/lib/gcc/x86_64-unknown-linux-gnu/4.0.1/crtendS.o 
>         /usr/lib/../lib64/crtn.o
>         /usr/bin/ld:.libs/libdspam.o: file format not recognized;
>         treating as
>         linker script
>         /usr/bin/ld:.libs/libdspam.o:1: syntax error
>         collect2: ld returned 1 exit status
>         -------------------------------------------------------------- 
>         If I execute the last command manually with llvm-ld, removing
>         -shared
>         and -Wl, it goes through.
>         So, obviously I'm doing something wrong.
>         What do I need to change in the build process to compile the
>         same apps 
>         I could compile before with llvm-gcc3 to bc files?
>         Thx in advance,
>                     Domagoj
>         _______________________________________________
>         LLVM Developers mailing list
>         LLVMdev at cs.uiuc.edu         http://llvm.cs.uiuc.edu
>         http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev
> _______________________________________________
> LLVM Developers mailing list
> LLVMdev at cs.uiuc.edu         http://llvm.cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev

More information about the llvm-dev mailing list