[LLVMdev] Getting LLVM bit-code for programs using a couple of libraries

John Criswell criswell at illinois.edu
Thu May 29 12:08:16 PDT 2014


Dear Sandeep,

There are a couple of ways to get what you want, depending on what you 
want to do.

If you want to run LLVM's link-time optimization passes, then following 
the suggestion of using libLTO to just transparently link together files 
generated by clang -flto is the best way to go.

If you want to write a new optimization and have it run at link time, 
then your best bet is to modify libLTO to run your new optimization pass.

If you really just want a single bitcode file for a program, you could 
modify libLTO to run a pass that will dump the linked LLVM IR bitcode to 
a file.  I believe one of our students (now a postdoc) tried that 
approach.  Alternatively, you can change the application's Makefiles to 
use -emit-llvm, but that may be more work (depending on the program).

Hope this helps,

John Criswell

On 5/26/14, 9:58 PM, Sandeep K Chaudhary wrote:
> Hi guys,
>
> I am compiling some programs with clang which use a couple of
> libraries. When I compile with the command - "clang -O2 -I. -o hello
> -ldl -llttng-ust hello.c tp.c", it goes successful.
>
> My aim is to get the bitcode for these programs but if I try to
> generate the bitcode with -emit-llvm option, it produces linking
> issues as follows : (also at - http://pastebin.com/zkmL2SAH)
>
> sandeep at ubuntu:~/lttng-git/lttng-ust/tests/hello2$ clang -emit-llvm
> -O2 -I. -o hello -ldl -llttng-ust hello.c tp.c
> /usr/bin/ld: error: /tmp/hello-u3dmcq.o:1:3: invalid character
> /usr/bin/ld: error: /tmp/hello-u3dmcq.o:1:3: syntax error, unexpected $end
> /usr/bin/ld: error: /tmp/hello-u3dmcq.o: not an object or archive
> /usr/bin/ld: error: /tmp/tp-1CR8ta.o:1:3: invalid character
> /usr/bin/ld: error: /tmp/tp-1CR8ta.o:1:3: syntax error, unexpected $end
> /usr/bin/ld: error: /tmp/tp-1CR8ta.o: not an object or archive
> /usr/lib/gcc/x86_64-linux-gnu/4.6/../../../x86_64-linux-gnu/crt1.o(.text+0x20):
> error: undefined reference to 'main'
> clang: error: linker command failed with exit code 1 (use -v to see invocation)
>
> What is a way to go around these linking issues?
>
> Also, I can successfully generate bitcode for a simple hello-world
> program using the -emit-llvm program so I installation of clang/llvm
> on my system is good.
>
> PS: I hope that I am not mistaken in posting this query here. But if
> I'am, please excuse me.
>
> Thanks and regards,
> Sandeep.
> _______________________________________________
> 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