[LLVMdev] CVS binutils includes support for plugins, can use the llvm plugin.

Rafael Espindola espindola at google.com
Tue May 26 10:52:54 PDT 2009

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 :-)

Rafael Avila de Espindola

Google | Gordon House | Barrow Street | Dublin 4 | Ireland
Registered in Dublin, Ireland | Registration Number: 368047

More information about the llvm-dev mailing list