Hi everyone,
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.
So I follow the instructions in LLVM document on gold plugin http://llvm.org/docs/GoldPlugin.html#lto-how-to-build. However, when running a simple program using LTO, clang fails to link the object file with the LLVM bitcode.
There’re only two c files, a.c and b.c in the source folder.
$ clang -flto a.c -c -o a.o # <-- a.o is LLVM bitcode file
$ clang b.c -c -o b.o # <-- b.o is native object file
$ clang -flto a.o b.o -o main # <-- link with LLVMgold plugin
When executing the last command, it prompts
a.o: file not recognized: File format not recognized
clang: error: linker command failed with exit code 1 (use -v to see invocation)
At the same time, performing the command of
ld -plugin=/usr/local/lib/LLVMgold.so a.o b.o -o main
it will successfully generate main.
My libLTO build process is as follows,
- check out binutils
- configure with --enable-gold --enable-plugins
- make
- make install
- replace original ld in /usr/local/bin with ld.gold using ln
- replace ar and nm in /usr/local/bin with ar and nm-new in the binutils folder just built using ln
- configure LLVM with --with-binutils-include=/path/to/binutils/src/include
- execute make again in LLVM root
It seems the gold linker works well with the LLVMgold.so lib however clang fails to correctly invoke gold linker.
Could anyone tell me where my mistake is?
Regards,
Chunbai Yang