[cfe-users] Getting clang to use LLD (-fuse-ld issue)

Justin C Miller via cfe-users cfe-users at lists.llvm.org
Tue Oct 22 10:27:45 PDT 2019


Hi,

I'm attempting to build an all-LLVM cross-compiling toolchain for building a
kernel project I'm working on, but I'm having some trouble getting clang++ to
use LLD. If I pass -fuse-ld to clang to point at the LLD binary in the
toolchain, clang++ still tries to call the system g++ for linking. This is on
x86_64 Debian, compiling for x86_64-unknown-elf. Here's a minimal example:


$ cat test.cpp
int main(int argc, const char **argv) { return 0; }
$ /opt/cross/llvm-9-jsix/bin/ld.lld --version
LLD 9.0.1 (https://git.llvm.org/git/lld.git e2dc845f525b792e382c3df18ecbe4851aac7599) (compatible with GNU linkers)
$ /opt/cross/llvm-9-jsix/bin/clang++ --target=x86_64-unknown-elf -c ./test.cpp -o test.o
$ /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
clang version 9.0.1 (https://git.llvm.org/git/clang.git bed37d4b18ce6993fc2567e8de61f6b30fd0cb75) (https://git.llvm.org/git/llvm.git c2f5309b216cb02a0aae17353549d985b5b05635)
Target: x86_64-unknown-unknown-elf
Thread model: posix
InstalledDir: /opt/cross/llvm-9-jsix/bin
"/usr/bin/g++" -v -fuse-ld=/opt/cross/llvm-9-jsix/bin/ld.lld -m64 -o test test.o
Using built-in specs.
COLLECT_GCC=/usr/bin/g++
COLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-linux-gnu/8/lto-wrapper
OFFLOAD_TARGET_NAMES=nvptx-none
OFFLOAD_TARGET_DEFAULT=1
g++: error: unrecognized command line option ‘-fuse-ld=/opt/cross/llvm-9-jsix/bin/ld.lld’
Target: x86_64-linux-gnu
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
Thread model: posix
gcc version 8.3.0 (Debian 8.3.0-6)
clang-9: error: linker (via gcc) command failed with exit code 1 (use -v to see invocation)


Can anyone tell me what I'm doing wrong here? Also, is there a way to set the
default linker in the LLVM build? (I'm passing -DLLVM_ENABLE_LLD=ON to cmake,
but that seems to be for using LLD in the build of LLVM.)

Thanks,

Justin
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-users/attachments/20191022/69ad71c6/attachment.html>


More information about the cfe-users mailing list