<!DOCTYPE html><html><head><title></title><style type="text/css">p.MsoNormal,p.MsoNoSpacing{margin:0}</style></head><body><div>Hi,<br></div><div><br></div><div>I'm attempting to build an all-LLVM cross-compiling toolchain for building a<br></div><div>kernel project I'm working on, but I'm having some trouble getting clang++ to<br></div><div>use LLD. If I pass -fuse-ld to clang to point at the LLD binary in the<br></div><div>toolchain, clang++ still tries to call the system g++ for linking. This is on<br></div><div>x86_64 Debian, compiling for x86_64-unknown-elf. Here's a minimal example:<br></div><div><br></div><div><br></div><div>$ cat test.cpp<br></div><div>int main(int argc, const char **argv) { return 0; }<br></div><div>$ /opt/cross/llvm-9-jsix/bin/ld.lld --version<br></div><div>LLD 9.0.1 (<a href="https://git.llvm.org/git/lld.git">https://git.llvm.org/git/lld.git</a> e2dc845f525b792e382c3df18ecbe4851aac7599) (compatible with GNU linkers)<br></div><div>$ /opt/cross/llvm-9-jsix/bin/clang++ --target=x86_64-unknown-elf -c ./test.cpp -o test.o<br></div><div>$ /opt/cross/llvm-9-jsix/bin/clang++ --target=x86_64-unknown-elf -v -fuse-ld=/opt/cross/llvm-9-jsix/bin/ld.lld -o test test.o<br></div><div>clang version 9.0.1 (<a href="https://git.llvm.org/git/clang.git">https://git.llvm.org/git/clang.git</a> bed37d4b18ce6993fc2567e8de61f6b30fd0cb75) (<a href="https://git.llvm.org/git/llvm.git">https://git.llvm.org/git/llvm.git</a> c2f5309b216cb02a0aae17353549d985b5b05635)<br></div><div>Target: x86_64-unknown-unknown-elf<br></div><div>Thread model: posix<br></div><div>InstalledDir: /opt/cross/llvm-9-jsix/bin<br></div><div>"/usr/bin/g++" -v -fuse-ld=/opt/cross/llvm-9-jsix/bin/ld.lld -m64 -o test test.o<br></div><div>Using built-in specs.<br></div><div>COLLECT_GCC=/usr/bin/g++<br></div><div>COLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-linux-gnu/8/lto-wrapper<br></div><div>OFFLOAD_TARGET_NAMES=nvptx-none<br></div><div>OFFLOAD_TARGET_DEFAULT=1<br></div><div>g++: error: unrecognized command line option ‘-fuse-ld=/opt/cross/llvm-9-jsix/bin/ld.lld’<br></div><div>Target: x86_64-linux-gnu<br></div><div>Configured with: ../src/configure -v --with-pkgversion='Debian 8.3.0-6' --with-bugurl=file:///usr/share/doc/gcc-8/README.Bugs --enable-languages=c,ada,c++,go,brig,d,fortran,objc,obj-c++ --prefix=/usr --with-gcc-major-version-only --program-suffix=-8 --program-prefix=x86_64-linux-gnu- --enable-shared --enable-linker-build-id --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --libdir=/usr/lib --enable-nls --enable-bootstrap --enable-clocale=gnu --enable-libstdcxx-debug --enable-libstdcxx-time=yes --with-default-libstdcxx-abi=new --enable-gnu-unique-object --disable-vtable-verify --enable-libmpx --enable-plugin --enable-default-pie --with-system-zlib --with-target-system-zlib --enable-objc-gc=auto --enable-multiarch --disable-werror --with-arch-32=i686 --with-abi=m64 --with-multilib-list=m32,m64,mx32 --enable-multilib --with-tune=generic --enable-offload-targets=nvptx-none --without-cuda-driver --enable-checking=release --build=x86_64-linux-gnu --host=x86_64-linux-gnu --target=x86_64-linux-gnu<br></div><div>Thread model: posix<br></div><div>gcc version 8.3.0 (Debian 8.3.0-6)<br></div><div>clang-9: error: linker (via gcc) command failed with exit code 1 (use -v to see invocation)<br></div><div><br></div><div><br></div><div>Can anyone tell me what I'm doing wrong here? Also, is there a way to set the<br></div><div>default linker in the LLVM build? (I'm passing -DLLVM_ENABLE_LLD=ON to cmake,<br></div><div>but that seems to be for using LLD in the build of LLVM.)<br></div><div><br></div><div>Thanks,<br></div><div><br></div><div>Justin<br></div><div><br></div></body></html>