For some time now the gold linker has support for plugins and llvm has
a plugin for it.
Unfortunately, it was still not possible to do fully transparent LTO
on linux because ar had no support for plugins and a library created
with llvm files in it would have no symbol table and would be rejected
by gold.
Today support for plugins has been committed to BFD. That is the file
format abstraction library used by binutils. This now works
$ llvm-gcc -emit-llvm -O2 -c a.c
$ llvm-gcc -emit-llvm -O2 -c b.c
$ ar --plugin libLLVMgold.so q a.a a.o
$ llvm-gcc -use-gold-plugin b.o a.a -o t
$ objdump -d t | grep main\>: -A 2
0000000000400330 <main>:
400330: 31 c0 xor %eax,%eax
400332: c3 retq
with a.c being "int f(void) { return 0;}" and b.c being "int f(void);
int main(void) { return f(); }".
BFD will also search for plugins in <prefix>/lib/bfd-plugins. You can
just put libLLVMgold.so there and all you will need for LTO is to pass
-use-gold-plugin while linking 
Note that you must use the gold linker for -use-gold-plugin to work 
Cheers,
Today support for plugins has been committed to BFD. That is the file
format abstraction library used by binutils. This now works
Very nice Rafael! Can you please update the web page to mention this, e.g. in the LinkTimeOptimization.html document and wherever else relevant?
-Chris
Today support for plugins has been committed to BFD. That is the file
format abstraction library used by binutils. This now works
Very nice Rafael! Can you please update the web page to mention this, e.g.
in the LinkTimeOptimization.html document and wherever else relevant?
It was already documented in http://llvm.org/docs/GoldPlugin.html. I
just changed the example a bit to show that ar works.
-Chris
Cheers,
Ok, I just thought there were places on the web page where we claimed that LTO wasn't supported on linux. The only place I found was on the open projects page, so I updated it. Thanks Rafael!
-Chris
That's pretty awesome!
Will ar, etc. eventually get some autodiscovery of plugins so that
things work OOTB after a make install of llvm/llvm-gcc?
- Daniel
That's pretty awesome!
Thanks!
Will ar, etc. eventually get some autodiscovery of plugins so that
things work OOTB after a make install of llvm/llvm-gcc?
The bfd library (used by ar and nm) already searches for plugins in
$install_dir/lib/bfd-plugins/. Maybe we could pass an option to llvm's
configure to tell it where to install a copy of the plugin?
- Daniel
Cheers,
Will ar, etc. eventually get some autodiscovery of plugins so that
things work OOTB after a make install of llvm/llvm-gcc?
The bfd library (used by ar and nm) already searches for plugins in
$install_dir/lib/bfd-plugins/. Maybe we could pass an option to llvm's
configure to tell it where to install a copy of the plugin?
Ah, cool. I think we will need a little extra magic in the Makefiles
for this too but should be pretty straightforward. I filed PR4564, I
may do this at some point if no one beats me to it.
Chris, can you add a gold-plugin component to bugzilla?
- Daniel