[LLVMdev] clang -emit-llvm uses system ld

Duncan Sands baldrick at free.fr
Fri Jul 1 00:20:46 PDT 2011


Hi Gregory,

> I think this is a misunderstanding on my part about what the dragonegg plugin is
> supposed to do. I am looking for something that will essentially be a
> replacement for gcc except that it generates llvm bitcode instead of normal
> object files. If I run something like:

you need to use -S otherwise gcc will pass the output to the system assembler,
which will barf (as you saw) since it doesn't understand LLVM IR.

>
> gcc-4.5 -fplugin=/homes/malecha/tmp/libc-scratch/dragonegg/dragonegg.so a.c -c
> -o a.o -flto
> /tmp/ccRKW0GD.s: Assembler messages:
> /tmp/ccRKW0GD.s:1: Error: junk at end of line, first unrecognized character is `.'
> /tmp/ccRKW0GD.s:2: Error: no such instruction: `target triple="x86_64--linux-gnu"'
> /tmp/ccRKW0GD.s:4: Error: no such instruction: `module asm "\09.ident\09\22GCC:
> (GNU) 4.5.2 LLVM: 133848\22"'
> ...
>
> I assume because my system assembler doesn't understand llvm bitcode. So I ended
> up wrapping it up in a script that calls gcc with -emit-llvm -S and then runs
> llvm-as on the resulting llvm assembly code. I think that I just need to
> manually (i.e. with a script) expand the gcc calls to incorporate the llvm
> toolchain.

Right, you need to run llvm-as manually.  This is a pain, but I didn't find I
good solution for this yet.

Ciao, Duncan.

>
>
>     Ciao, Duncan.
>
>       I'm not sure if it is related to my installation of gold or my gcc
>      > configuration.
>      >
>      > I'm really interested in getting the resulting program as bitcode though.
>     Will
>      > LTO do that for me? What I'm trying to do is build a bitcode version of libc
>      > that I can combine with a program and analyze/optimize the resulting program.
>      >
>      >
>      >
>      > 2011/6/28 Rafael Ávila de Espíndola <rafael.espindola at gmail.com
>     <mailto:rafael.espindola at gmail.com>
>      > <mailto:rafael.espindola at gmail.com <mailto:rafael.espindola at gmail.com>>>
>      >
>      >     On 11-06-28 10:45 PM, Gregory Malecha wrote:
>      > > Hello,
>      > >
>      > > I've been trying to build some normal linux applications with clang and I
>      >     keep running into a snag in configure scripts. Perhaps these scripts
>     are not
>      >     written very well, but the current clang behavior seems strange. When
>     I run
>      >     clang with the -emit-llvm option, it still uses /usr/bin/ld as the linker
>      >     which fails to compile llvm bitcode on linux (though it works on mac).
>      >     Here's a simple example:
>      > >
>      > > $ cat > test.c
>      > > int main(void) { return 0; }
>      > > $ clang -emit-llvm test.c
>      > > /tmp/cc-pDfs56.o: file not recognized: File format not recognized
>      > > clang: error: linker command failed with exit code 1 (use -v to see
>      >     invocation)
>      > > $ clang -emit-llvm test.c -c
>      > > $
>      > >
>      > > It seems to me that clang should call llvm-ld when it generates llvm code
>      >     and ld otherwise, but maybe there's something that I have configured
>      >     incorrectly. What is the appropriate way to address this?
>      >
>      >     llvm-ld is not a full replacement for a system ld. If you want to do LTO
>      >     (which is why I assume you
>      >     are using -emit-llvm), you should use a linker that support it. Gold
>     support
>      >     plugins and can
>      >     use the LLVM one. Recently gnu ld implemented the same interface, but I
>      >     haven't tested it.
>      >
>      > http://llvm.org/docs/GoldPlugin.html
>      >
>      > > Thanks.
>      >
>      >     Cheers,
>      >     Rafael
>      >     _______________________________________________
>      >     LLVM Developers mailing list
>      > LLVMdev at cs.uiuc.edu <mailto:LLVMdev at cs.uiuc.edu>
>     <mailto:LLVMdev at cs.uiuc.edu <mailto:LLVMdev at cs.uiuc.edu>>
>     http://llvm.cs.uiuc.edu
>      > http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev
>      >
>      >
>      >
>      >
>      > --
>      > gregory malecha
>      >
>      >
>      >
>      > _______________________________________________
>      > LLVM Developers mailing list
>      > LLVMdev at cs.uiuc.edu <mailto: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 <mailto:LLVMdev at cs.uiuc.edu> http://llvm.cs.uiuc.edu
>     http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev
>
>
>
>
> --
> gregory malecha




More information about the llvm-dev mailing list