<div dir="ltr">Hi,<br><br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">> I wasn't aware of the gold linker plugin.</blockquote>
<br>It doesn't seem to be that well known indeed... yet it's been the best way to compile source to bitcode and bitcode to programs, in my experience. Here are a few more hints (that may also be useful to others who stumble upon this thread).<br>
<br>- To generate bitcode files from Clang, use -flto (or -emit-llvm)<br>- During linking, use -flto to accept bitcode files as input.<br> Note that their extension matters (.bc gets compiled, LTO'd and linked, .o gets just LTO'd and linked)<br>
- You can obtain the merged bitcode file that corresponds to the final executable as follows:<br> - on Mac, pass -Wl,-save-temps to the compiler. This will give you both a prog.lto.bc and a prog.lto.opt.bc file. One corresponds to the program before link-time optimization passes were applied, the other after link-time optimization.<br>
- on Linux, the corresponding command is -Wl,-plugin-opt=also-emit-llvm . This only gives you the bitcode before link-time optimizations, unfortunately. You can use the attached patch to make the behavior more consistent between Linux and Mac.<br>
- If your program creates libraries, you can make them contain LLVM bitcode instead of regular object code.<br> On Linux, this requires a few tweaks because nm, ar, ranlib etc. don't know how to handle LLVM bitcode natively. Usually, passing the following to the configure script helps:<br>
RANLIB="ar -s --plugin=/path/to/llvm/lib/LLVMgold.so"<br> AR="ar -cru --plugin=/path/to/llvm/lib/LLVMgold.so"<br> NM="nm --plugin=/path/to/llvm/lib/LLVMgold.so"<br><br>Let us know if this helps. Also, if anybody knows better workflows, I'd be very interested.<br>
<br>Cheers,<br>Jonas </div>