From 5f73f68d39ef02b6ca4a082e7bc4c64903ed860a Mon Sep 17 00:00:00 2001
From: Peter Collingbourne
Clang has a -use-gold-plugin option which looks for the - gold plugin in the same directories as it looks for cc1 and passes - the -plugin option to ld. It will not look for an alternate - linker, which is why you need gold to be the installed system linker in your - path.
+Any of these flags will also cause clang to look for the + gold plugin in the lib directory under its prefix and pass the + -plugin option to ld. It will not look for an alternate + linker, which is why you need gold to be the installed system linker in + your path.
If you want ar and nm to work seamlessly as well, install LLVMgold.so to /usr/lib/bfd-plugins. If you built your @@ -141,10 +141,10 @@ void foo4(void) { } --- command lines --- -$ clang -flto a.c -c -o a.o # <-- a.o is LLVM bitcode file -$ ar q a.a a.o # <-- a.a is an archive with LLVM bitcode -$ clang b.c -c -o b.o # <-- b.o is native object file -$ clang -use-gold-plugin a.a b.o -o main # <-- link with LLVMgold plugin +$ clang -flto a.c -c -o a.o # <-- a.o is LLVM bitcode file +$ ar q a.a a.o # <-- a.a is an archive with LLVM bitcode +$ clang b.c -c -o b.o # <-- b.o is native object file +$ clang -flto a.a b.o -o main # <-- link with LLVMgold plugin
Gold informs the plugin that foo3 is never referenced outside the IR, @@ -171,13 +171,12 @@ $ clang -use-gold-plugin a.a b.o -o main # <-- link with LLVMgold plugin
-export CC="$PREFIX/bin/clang -use-gold-plugin" -export CXX="$PREFIX/bin/clang++ -use-gold-plugin" +export CC="$PREFIX/bin/clang -flto" +export CXX="$PREFIX/bin/clang++ -flto" export AR="$PREFIX/bin/ar" export NM="$PREFIX/bin/nm" export RANLIB=/bin/true #ranlib is not needed, and doesn't support .bc files in .a @@ -187,8 +186,8 @@ export CFLAGS="-O4"
export PATH="$PREFIX/bin:$PATH" -export CC="clang -use-gold-plugin" -export CXX="clang++ -use-gold-plugin" +export CC="clang -flto" +export CXX="clang++ -flto" export RANLIB=/bin/true export CFLAGS="-O4"