This is an archive of the discontinued LLVM Phabricator instance.

Add a ld64.lld alias for the MACHO LLD target
ClosedPublic

Authored by martell on Sep 26 2017, 12:19 PM.

Diff Detail

Repository
rL LLVM

Event Timeline

martell created this revision.Sep 26 2017, 12:19 PM

I have a patch that does a bunch of updates for testing lld correctly in clang and this was a part of it but I didn't want the patch to get too involved so I separated this out.
I have seen this issue raised on various forums such as stackoverflow here and figured I would just fix it for users.
https://stackoverflow.com/questions/44106329/lld-unknown-argument-arch

mstorsjo added inline comments.
tools/clang/lib/Driver/ToolChain.cpp
394 ↗(On Diff #116697)

Space between if and (

martell updated this revision to Diff 116801.Sep 27 2017, 6:07 AM

address comment

martell marked an inline comment as done.Sep 27 2017, 6:08 AM
ruiu edited edge metadata.Sep 27 2017, 8:27 PM

Is this for cross-compilation? If you invoke lld on macOS, it should act as ld64.

macOS lld is not actively maintained, so I wouldn't make it available more widely.

martell added a comment.EditedSep 27 2017, 11:18 PM
In D38290#882911, @ruiu wrote:

Is this for cross-compilation?

It is mostly for native compilation on mac but this will work for cross compiling also.

If you invoke lld on macOS, it should act as ld64.

That is if the file name is ld or if you pass the darwin flavour but that is not how clang invokes lld.

-fuse-ld=lld invokes ld.lld which is bound to the gnu frontend only, even on MacOS hosts.
The reason for introducing ld64 is so we can still cross compile from MacOS to linux targets cleanly.

macOS lld is not actively maintained, so I wouldn't make it available more widely.

It seems to be able to link simple programs at least.
A user has to specifically pass -fuse-ld=lld to use lld for apple targets, I'm not making it the default here.
Most importantly though it makes less sense to have users invoking the ELF linker for MACHO targets as I highlighted above.

ruiu added a comment.Oct 1 2017, 7:45 PM

This patch virtually sets ld64 the linker command name for macOS. I'd be a bit reluctant doing that, because ld64 sounds like a too generic name to indicate "a linker for macOS". But that's probably okay because we don't have a better name.

Can you get an LGTM from someone who owns the clang driver?

CODE_OWNERS.TXT does not have a list of driver owners.
It does have rsmith as an owner for all things not covered by someone else so I added him.
Reid usually reviews driver patches I submit to clang and is on the owner list so I added him here initially.
I think either should be fine.
ping @rnk

rnk accepted this revision.Oct 2 2017, 1:18 PM
In D38290#885503, @ruiu wrote:

This patch virtually sets ld64 the linker command name for macOS. I'd be a bit reluctant doing that, because ld64 sounds like a too generic name to indicate "a linker for macOS". But that's probably okay because we don't have a better name.

It's not a good name, but I do believe it is recognizable as the Darwin linker. It's also consistent with the names we invent on other platforms, which are essentially "native linker binary name plus lld".

Can you get an LGTM from someone who owns the clang driver?

lgtm

Thinking *LONG LONG* term, what I want to see happen is:

  1. Annotate the exported C++ API of libLLVM.so to ensure that this does not regress clang compilation time (avoids PLT indirection for calls internal to LLVM)
  2. Build with -fvisibility=hidden, so MachO and ELF builds of LLVM work like COFF
  3. Make building LLVM.dll/libLLVM.dylib/libLLVM.so the default
  4. Stop busy-boxing the LLD ports, and have separate executables for each: ld64.lld, lld-link.exe, and ld.lld

This will save disk space and potentially runtime if the loader keeps the LLVM shared object in memory, rather than loading a second copy for every link step in the buidl.

This revision is now accepted and ready to land.Oct 2 2017, 1:18 PM
This revision was automatically updated to reflect the committed changes.