[PATCH] D84029: [clang][Driver] Default to /usr/bin/ld on Solaris

Rainer Orth via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Fri Jul 17 08:06:19 PDT 2020


ro created this revision.
ro added reviewers: clang, rsmith, mehdi_amini, rnk.
ro added a project: clang.
Herald added a subscriber: fedor.sergeev.

`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`.

Ok for master?


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D84029

Files:
  clang/lib/Driver/ToolChain.cpp
  clang/lib/Driver/ToolChains/Solaris.h


Index: clang/lib/Driver/ToolChains/Solaris.h
===================================================================
--- clang/lib/Driver/ToolChains/Solaris.h
+++ clang/lib/Driver/ToolChains/Solaris.h
@@ -65,6 +65,11 @@
   SanitizerMask getSupportedSanitizers() const override;
   unsigned GetDefaultDwarfVersion() const override { return 2; }
 
+  const char *getDefaultLinker() const override {
+    // clang currently uses Solaris ld-only options.
+    return "/usr/bin/ld";
+  }
+
 protected:
   Tool *buildAssembler() const override;
   Tool *buildLinker() const override;
Index: clang/lib/Driver/ToolChain.cpp
===================================================================
--- clang/lib/Driver/ToolChain.cpp
+++ clang/lib/Driver/ToolChain.cpp
@@ -558,7 +558,11 @@
   } else if (UseLinker.empty() || UseLinker == "ld") {
     // If we're passed -fuse-ld= with no argument, or with the argument ld,
     // then use whatever the default system linker is.
-    return GetProgramPath(getDefaultLinker());
+    const char *DefaultLinker = getDefaultLinker();
+    if (llvm::sys::path::is_absolute(DefaultLinker))
+      return DefaultLinker;
+    else
+      return GetProgramPath(DefaultLinker);
   } else {
     llvm::SmallString<8> LinkerName;
     if (Triple.isOSDarwin())


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D84029.278767.patch
Type: text/x-patch
Size: 1279 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20200717/2392473a/attachment-0001.bin>


More information about the cfe-commits mailing list