[LLVMdev] ld with gold-plugin can do this?

Nick Lewycky nicholas at mxc.ca
Sat Sep 19 18:23:55 PDT 2009

zhunan wrote:
> Hi,all
> I have installed the gold-plugin and it can run correctly,but I still
> have another two questions:
> 1.Can gold-plugin generate a bitcode file:

No. The task of linking many .bc files into a single .bc file falls on 
llvm-ld and llvm-link.

A common followup question is "but how do I link native libraries into 
my .bc file". You don't. A .bc file is llvm ir, you can't put a native 
binary library into a .bc (barring sticking it in as a string, etc).

The build then looks like:

a) 'llvm-gcc -c -flo -O2' to generate the .bc files.
b) 'llvm-ld' to combine them into a single .bc. No, not a .so nor a .a.
c) 'llc' to turn your combined .bc into a .s
d) 'as' to turn your .s into a .o
e) 'ld' to turn your .o into a .so or final executable. This is the step 
where you get to specify all the native libraries to link with.

You can use 'gcc' to merge steps d and e (it just runs as and ld for 
you). Or you can use the gold plugin to merge steps b through e, but 
with the added benefit that it will optimize slightly better. See the 
llvm LTO documentation on why.

>>From the document and also my experience on using it,"ld -plugin...."
> will only generate an executable by link several LLVM bitcode file
> together,but how to make it generate a whole-program bitcode file?(even
> archieve it manually is OK)
> 2.llvm-gcc -c will stop the linker to run:
> I have been trying to generate a whole-program bitcode file,but when I
> use CFLAGS="-emit-llvm -c" to compile source files into LLVM bitcode
> file,llvm-gcc will not call "ld" to link modules together,so that I
> cannot link these modules together automatically.
> How to overcome this trouble?

You get to modify your program's build system. Things like 'configure' 
work by trying to compile and run small programs. You can't run a .bc file.


More information about the llvm-dev mailing list