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())


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())
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to