[clang][Driver] Default to /usr/bin/ld on Solaris
authorRainer Orth <ro@gcc.gnu.org>
Thu, 13 Aug 2020 20:42:58 +0000 (22:42 +0200)
committerRainer Orth <ro@gcc.gnu.org>
Thu, 13 Aug 2020 20:42:58 +0000 (22:42 +0200)
commitf59bec7acb8228fc215fca3ee1e524c38083c50b
tree4da3f9daa8c9cf6b7ca7d41f5885620e55a12dfb
parent18910c4cb5d4e59ef25f4b8b48fcbd3146833645
[clang][Driver] Default to /usr/bin/ld on Solaris

`clang` currently requires the native linker on Solaris:

  - It passes `-C` to `ld` which GNU `ld` doesn't understand.

  - To use `gld`, one needs to pass the correct `-m EMU` option to select
    the right emulation.  Solaris `ld` cannot handle that option.

So far I've worked around this by passing `-DCLANG_DEFAULT_LINKER=/usr/bin/ld`
to `cmake`.  However, if someone forgets this, it depends on the user's
`PATH` whether or not `clang` finds the correct linker, which doesn't make
for a good user experience.

While it would be nice to detect the linker flavor at runtime, this is more
involved.  Instead, this patch defaults to `/usr/bin/ld` on Solaris.  This
doesn't work on its own, however: a link fails with

  clang-12: error: unable to execute command: Executable "x86_64-pc-solaris2.11-/usr/bin/ld" doesn't exist!

I avoid this by leaving absolute paths alone in `ToolChain::GetLinkerPath`.

Tested on `amd64-pc-solaris2.11`, `sparcv9-sun-solaris2.11`, and
`x86_64-pc-linux-gnu`.

Differential Revision: https://reviews.llvm.org/D84029
clang/lib/Driver/ToolChain.cpp
clang/lib/Driver/ToolChains/Solaris.h
clang/test/Driver/solaris-ld-sld.c [new file with mode: 0644]
llvm/utils/lit/lit/llvm/config.py