[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 31 04:57:13 PDT 2020


ro updated this revision to Diff 282192.
ro added a comment.
Herald added subscribers: llvm-commits, ormris, delcypher.
Herald added a project: LLVM.

Add testcase.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D84029/new/

https://reviews.llvm.org/D84029

Files:
  clang/lib/Driver/ToolChain.cpp
  clang/lib/Driver/ToolChains/Solaris.h
  clang/test/Driver/solaris-ld-sld.c
  llvm/utils/lit/lit/llvm/config.py


Index: llvm/utils/lit/lit/llvm/config.py
===================================================================
--- llvm/utils/lit/lit/llvm/config.py
+++ llvm/utils/lit/lit/llvm/config.py
@@ -59,6 +59,8 @@
             features.add('system-netbsd')
         elif platform.system() == 'AIX':
             features.add('system-aix')
+        elif platform.system() == 'SunOS':
+            features.add('system-solaris')
 
         # Native compilation: host arch == default triple arch
         # Both of these values should probably be in every site config (e.g. as
Index: clang/test/Driver/solaris-ld-sld.c
===================================================================
--- /dev/null
+++ clang/test/Driver/solaris-ld-sld.c
@@ -0,0 +1,9 @@
+// REQUIRES: system-solaris
+
+// Check that clang invokes the native ld.
+
+// FIXME: Test should be UNSUPPORTED if GNU ld isn't installed.
+// RUN: test -f /usr/gnu/bin/ld
+// RUN: env PATH=/usr/gnu/bin %clang -o %t.o %s
+
+int main() { return 0; }
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
@@ -568,8 +568,13 @@
   }
   // If we're passed -fuse-ld= with no argument, or with the argument ld,
   // then use whatever the default system linker is.
-  if (UseLinker.empty() || UseLinker == "ld")
-    return GetProgramPath(getDefaultLinker());
+  if (UseLinker.empty() || UseLinker == "ld") {
+    const char *DefaultLinker = getDefaultLinker();
+    if (!llvm::sys::path::is_absolute(DefaultLinker))
+      return GetProgramPath(DefaultLinker);
+    else
+      return std::string(DefaultLinker);
+  }
 
   // Extending -fuse-ld= to an absolute or relative path is unexpected. Checking
   // for the linker flavor is brittle. In addition, prepending "ld." or "ld64."


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D84029.282192.patch
Type: text/x-patch
Size: 2418 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20200731/b4ad42af/attachment.bin>


More information about the cfe-commits mailing list