<div dir="ltr">Hi everyone,<div><br></div><div>I want to perform whole-program analysis for apache httpd using httpd's original autoconf system so that I need to generate a single bitcode file. </div><div><br></div><div>
So I follow the instructions in LLVM document on gold plugin <a href="http://llvm.org/docs/GoldPlugin.html#lto-how-to-build">http://llvm.org/docs/GoldPlugin.html#lto-how-to-build</a>. However, when running a simple program using LTO, clang fails to link the object file with the LLVM bitcode.</div>
<div>There're only two c files, a.c and b.c in the source folder.</div><div><pre style="font-family:Consolas,'Deja Vu Sans Mono','Bitstream Vera Sans Mono',monospace;font-size:0.95em;line-height:15px;padding:0.5em;border:1px solid rgb(204,204,204);background-color:rgb(248,248,248);color:rgb(0,0,0)">
<span class="" style="color:rgb(187,96,213)">$ </span>clang -flto a.c -c -o a.o <span class="" style="color:rgb(96,160,176);font-style:italic"># <-- a.o is LLVM bitcode file</span>
<span class="" style="color:rgb(187,96,213)">$ </span>clang b.c -c -o b.o <span class="" style="color:rgb(96,160,176);font-style:italic"># <-- b.o is native object file</span>
<span class="" style="color:rgb(187,96,213)">$ </span>clang -flto a.o b.o -o main <span class="" style="color:rgb(96,160,176);font-style:italic"># <-- link with LLVMgold plugin</span></pre>When executing the last command, it prompts</div>
<div><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">a.o: file not recognized: File format not recognized<br>
clang: error: linker command failed with exit code 1 (use -v to see invocation)</blockquote></div><div>At the same time, performing the command of</div><div>ld -plugin=/usr/local/lib/LLVMgold.so a.o b.o -o main</div><div>
it will successfully generate main.</div><div><br></div><div>My libLTO build process is as follows,</div><div><ol><li>check out binutils</li><li>configure with --enable-gold --enable-plugins</li><li>make</li><li>make install</li>
<li>replace original ld in /usr/local/bin with ld.gold using ln</li><li>replace ar and nm in /usr/local/bin with ar and nm-new in the binutils folder just built using ln</li><li>configure LLVM with --with-binutils-include=/path/to/binutils/src/include</li>
<li>execute make again in LLVM root</li></ol><div>It seems the gold linker works well with the LLVMgold.so lib however clang fails to correctly invoke gold linker.</div></div><div>Could anyone tell me where my mistake is?</div>
<div><br></div><div>Regards,</div><div>Chunbai Yang</div></div>