LLD - unknown argument: -arch
Asked Answered
M

2

11

Trying to link a simple program using LLVM 4.0.0 release (Clang, LLD) on Mac OS Sierra. Note, this is fully achievable in Linux.

My current path is prefixed with the LLVM's bin directory (i.e. /opt/LLVM/4.0.0/bin:$PATH.

The program (main.cpp) is the simplest possible C++ application:

int main()
{
    return 0;
}

The shell command issued is: clang -fuse-ld=lld.
This fails with these errors:

/opt/llvm/4/bin/ld.lld: error: unknown argument: -no_deduplicate
/opt/llvm/4/bin/ld.lld: error: unknown argument: -dynamic
/opt/llvm/4/bin/ld.lld: error: unknown argument: -arch
/opt/llvm/4/bin/ld.lld: error: unknown emulation: acosx_version_min
/opt/llvm/4/bin/ld.lld: error: unable to find library -lto_library
/opt/llvm/4/bin/ld.lld: error: /opt/llvm/4/lib/libLTO.dylib: invalid data encoding
clang-4.0: error: linker command failed with exit code 1 (use -v to see invocation)

Using the -v switch, I see this linker command (formatted):

"/opt/llvm/4/bin/ld.lld" \
    -demangle \
    -lto_library /opt/llvm/4/lib/libLTO.dylib \
    -no_deduplicate \
    -dynamic \
    -arch x86_64 \
    -macosx_version_min 10.12.0 \
    -o a.out \
    main.o \
    -lSystem /opt/llvm/4/bin/../lib/clang/4.0.0/lib/darwin/libclang_rt.osx.a

Does anyone know the proper switches for this platform?

Mostly answered 22/5, 2017 at 6:51 Comment(2)
you ever figure this out?Lauter
@Lauter yes. I contacted the Clang mailing list. Work on LLD for macOS (meaning, the Mach-O object format) is stale. Best way to go for now is to keep with the system linker (I believe it's called ld64).Mostly
M
1

After contacting the LLVM-dev mailing list, it appears that LLD for macOS (meaning, Mach-O object format linking) development is stale.

To use Clang on macOS, it's best to stick with the OS-provided ld64.

Mostly answered 15/3, 2018 at 23:0 Comment(2)
is ld64 the same as /usr/bin/ld? I wanted to use lld for the faster link times. I guess it's not possible yet?Lauter
Yes, I think they may actually be symlinked. Note, you CAN use LLD on macOS, but: 1. The 'bindings' to link automatically after compiling (clang -fuse-ld=lld) are broken in macOS. You would need to compile only, then link in a separate command. 1. According to the LLVM dev list, the linker itself is in pre-alpha quality, so for now, it's only for experimental stuff.Mostly
B
1

If the only reason to use LLVM-lld is speed, then try zld

It's consistently cuts time to half (often to less than half) as compared to that taken by Apple-ld.

Add the following linker flag:

-fuse-ld=`which zld` -Wl,-zld_original_ld_path,ld 
Batrachian answered 14/10, 2020 at 14:27 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.