Hi,
I am trying to use LLVM LTO. I read http://llvm.org/docs/GoldPlugin.html and have some questions. Could anyone help?
- Can LLVMgold.so work with BFD LD instead of gold? In the description of changes in binutils 2.20, “* The plugin target has been added to bfd. It can load the same shared objects
used by gold and uses them to provide basic support for new file formats.”. Does this mean BFD LD after 2.20 can support LLVMgold.so? Ld version on my system is:
GNU ld (GNU Binutils for Ubuntu) 2.21.53.20110810
- Gold only supports ELF. If BFD LD can support LLVMgold, can LTO be applied to COFF objects after recompiling the binutils with target==x86_64-pc-pe?
Thanks!
Rui
FYI, the last time I attempted, I was not able to activate lto.
IIRC, I met some sorts of crashing.
Let's know if you could, thanks 
...Takumi
Hi,
I am trying to use LLVM LTO. I read The LLVM gold plugin — LLVM 18.0.0git documentation and
have some questions. Could anyone help?
1. Can LLVMgold.so work with BFD LD instead of gold? In the
description of changes in binutils 2.20, “* The plugin target has been added
to bfd. It can load the same shared objects
used by gold and uses them to provide basic support for new file formats.”.
Does this mean BFD LD after 2.20 can support LLVMgold.so? Ld version on my
system is:
GNU ld (GNU Binutils for Ubuntu) 2.21.53.20110810
In theory it can, but I think it is completely untested. I think
that, as with gold, you have to build it with --enable-plugins.
2. Gold only supports ELF. If BFD LD can support LLVMgold, can LTO be
applied to COFF objects after recompiling the binutils with
target==x86_64-pc-pe?
Double untested, but I guess it could be made to work 
Thanks!
Rui
Cheers,
Rafael
Rafael, Rui,
This is obviously an old thread, but in case there is interest, I've been able to get this to work (using the LLVM gold plugin with the ld.bfd linker). This requires some additional logic in the ld.bfd linker (and a small change to the bfd library). I've attached the patch (against binutils HEAD from 2013-09-17) in case anyone finds this useful. The core issue is that ld.bfd is currently setup to use the GCC LTO plugin, which produces its IR in an ELF container, and we don't. As a result, ld.bfd needs to ask the plugin if it would like to claim files of unknown format (in addition to querying for recognized object files).
-Hal
P.S. For the record, I'm certainly not a binutils expert, this just seems to work for me.
ldbfd-bin-plugin.patch (2.07 KB)
Quick update: the previous patch only worked for static linking; this version should work for both static and dynamic linking.
I'm not going to send any more updated patches to this list, but please feel free to e-mail me off-list, and I'll be happy to share any updates I have at any point in the future.
-Hal
ldbfd-bin-plugin-v2.patch (3.01 KB)
You should probably send them for review/inclusion in bfd.
You should probably send them for review/inclusion in bfd.
Yes, I'll do that. FWIW, I imagine that further modification will be necessary for upstream acceptance (unless everything just works out okay, and I've not really tested this, some of the checks for a valid object file that the patch elides may need to be added back at some other points in order to not introduce problems with actually-invalid input files).
Thanks again,
Hal