LLD (macOS) usage?

Hi. I’m using LLVM 5.0.1 on macOS 10.12.

I have a very simple program (program.c):

int main() {}

When attempting to compile with LLD, I get this output:

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

Looks like the flags passed to the linker are just wrong, but can’t find any relevant documentation at llvm.org/docs.

Please help?

I’m seeing something similar.

clang is using HOST_LINK_VERSION, obtained from ld64, as the default for -mlinker-version. This causes Darwin.cpp to add the arguments you are seeing, but not handled by lld. Perhaps -fuse-ld should be considered in addition to -mlinker-version when adding these arguments.

As a workaround, you can try passing -mlinker-version. Looks like anything < 133 will work, including 0.


MachO support in lld is not really ready for real world usage. It was able to bootstrap itself a couple of years ago, but, it has not really been maintained or further developed since. I would recommend that you use ld64 if you are intending to build MachO binaries.

My case is slightly different in that I only use it for cross compiling clang from osx to linux, but to work around cmake issues, I have to set CLANG_DEFAULT_LINKER=lld. That means it’s only really usable when passing a non-darwin -target, e.g., “x86_64-unknown-linux-gnu”.

This also means you can’t use it for Native tools so you need to pass them as well.

I believe what’s happening here is that clang translates the -fuse-ld=lld into calling the ld.lld executable, which is actually the ELF LLD linker, not the Mach-O one. On 6.0, the Mach-O linker symlink is called ld64.lld instead (and clang has been changed to call out to that name) to disambiguate the two. For 5.0, I’m not sure how best to force the Mach-O linker (I’m not familiar with how the distribution is laid out).

As Saleem said though, Mach-O LLD isn’t really ready yet, so you’re better off using ld64 (the default linker).


$ …/llvm_project/build/cross/bin/clang -fuse-ld=lld -v -x c - </dev/null
clang version 7.0.0 (trunk 321948) (llvm/trunk 321947)
Target: x86_64-apple-darwin17.3.0
Thread model: posix
InstalledDir: /Users/dhinton/projects/misc/…/llvm_project/build/cross/bin
“/Users/dhinton/projects/llvm_project/build/cross/bin/clang-7.0” -cc1 -triple x86_64-apple-macosx10.13.0 -Wdeprecated-objc-isa-usage -Werror=deprecated-objc-isa-usage -emit-obj -mrelax-all -disable-free -main-file-name - -mrelocation-model pic -pic-level 2 -mthread-model posix -mdisable-fp-elim -masm-verbose -munwind-tables -target-cpu penryn -dwarf-column-info -debugger-tuning=lldb -target-linker-version 305 -v -resource-dir /Users/dhinton/projects/llvm_project/build/cross/lib/clang/7.0.0 -fdebug-compilation-dir /Users/dhinton/projects/misc -ferror-limit 19 -fmessage-length 208 -stack-protector 1 -fblocks -fencode-extended-block-signature -fobjc-runtime=macosx-10.13.0 -fmax-type-align=16 -fdiagnostics-show-option -fcolor-diagnostics -o /var/folders/c6/9lj3yxp109s0p6ch4jhcw5h00000gn/T/–1c2f9c.o -x c -
clang -cc1 version 7.0.0 based upon LLVM 7.0.0svn default target x86_64-apple-darwin17.3.0
#include “…” search starts here:
#include <…> search starts here:
/System/Library/Frameworks (framework directory)
/Library/Frameworks (framework directory)
End of search list.
“/Users/dhinton/projects/misc/…/llvm_project/build/cross/bin/ld64.lld” -demangle -lto_library /Users/dhinton/projects/llvm_project/build/cross/lib/libLTO.dylib -no_deduplicate -dynamic -arch x86_64 -macosx_version_min 10.13.0 -o a.out /var/folders/c6/9lj3yxp109s0p6ch4jhcw5h00000gn/T/–1c2f9c.o -lSystem
warning: ignoring unknown argument: -no_deduplicate
warning: -sdk_version is required when emitting min version load command. Setting sdk version to match provided min version
Unable to find library for -lto_library
clang-7.0: error: linker command failed with exit code 1 (use -v to see invocation)