thakis created this revision.
thakis added a reviewer: MaskRay.
Herald added a subscriber: StephenFan.
Herald added a project: All.
thakis requested review of this revision.

This allows using --ld-path= to set a custom linker path, while
still informing clang that the binary at that path is an lld built
at the same revision as clang, so that clang can make assumptions
about the flags it supports, its output format, etc.

This currently only has an observable effect on Darwin.


https://reviews.llvm.org/D134063

Files:
  clang/lib/Driver/ToolChain.cpp
  clang/test/Driver/darwin-ld-demangle-lld.c


Index: clang/test/Driver/darwin-ld-demangle-lld.c
===================================================================
--- clang/test/Driver/darwin-ld-demangle-lld.c
+++ clang/test/Driver/darwin-ld-demangle-lld.c
@@ -1,8 +1,12 @@
 // With -fuse-ld=lld, -demangle is always passed to the linker on Darwin.
 // REQUIRES: shell
 
-// RUN: %clang --target=x86_64-apple-darwin -### \
-// RUN:   -fuse-ld=lld -B%S/Inputs/lld -mlinker-version=0 %s 2>&1 \
+// RUN: %clang --target=x86_64-apple-darwin -### -fuse-ld=lld \
+// RUN:   -B%S/Inputs/lld -mlinker-version=0 %s 2>&1 \
+// RUN:   | FileCheck %s
+
+// RUN: %clang --target=x86_64-apple-darwin -### -fuse-ld=lld \
+// RUN:   --ld-path=%S/Inputs/lld/ld64.lld -mlinker-version=0 %s 2>&1 \
 // RUN:   | FileCheck %s
 
 // CHECK: "-demangle"
Index: clang/lib/Driver/ToolChain.cpp
===================================================================
--- clang/lib/Driver/ToolChain.cpp
+++ clang/lib/Driver/ToolChain.cpp
@@ -620,13 +620,18 @@
   // --ld-path= takes precedence over -fuse-ld= and specifies the executable
   // name. -B, COMPILER_PATH and PATH and consulted if the value does not
   // contain a path component separator.
+  // -fuse-ld=lld can be used with --ld-path= to inform clang that the binary
+  // that --ld-path= points to is lld.
   if (const Arg *A = Args.getLastArg(options::OPT_ld_path_EQ)) {
     std::string Path(A->getValue());
     if (!Path.empty()) {
       if (llvm::sys::path::parent_path(Path).empty())
         Path = GetProgramPath(A->getValue());
-      if (llvm::sys::fs::can_execute(Path))
+      if (llvm::sys::fs::can_execute(Path)) {
+        if (LinkerIsLLD)
+          *LinkerIsLLD = UseLinker == "lld";
         return std::string(Path);
+      }
     }
     getDriver().Diag(diag::err_drv_invalid_linker_name) << 
A->getAsString(Args);
     return GetProgramPath(getDefaultLinker());


Index: clang/test/Driver/darwin-ld-demangle-lld.c
===================================================================
--- clang/test/Driver/darwin-ld-demangle-lld.c
+++ clang/test/Driver/darwin-ld-demangle-lld.c
@@ -1,8 +1,12 @@
 // With -fuse-ld=lld, -demangle is always passed to the linker on Darwin.
 // REQUIRES: shell
 
-// RUN: %clang --target=x86_64-apple-darwin -### \
-// RUN:   -fuse-ld=lld -B%S/Inputs/lld -mlinker-version=0 %s 2>&1 \
+// RUN: %clang --target=x86_64-apple-darwin -### -fuse-ld=lld \
+// RUN:   -B%S/Inputs/lld -mlinker-version=0 %s 2>&1 \
+// RUN:   | FileCheck %s
+
+// RUN: %clang --target=x86_64-apple-darwin -### -fuse-ld=lld \
+// RUN:   --ld-path=%S/Inputs/lld/ld64.lld -mlinker-version=0 %s 2>&1 \
 // RUN:   | FileCheck %s
 
 // CHECK: "-demangle"
Index: clang/lib/Driver/ToolChain.cpp
===================================================================
--- clang/lib/Driver/ToolChain.cpp
+++ clang/lib/Driver/ToolChain.cpp
@@ -620,13 +620,18 @@
   // --ld-path= takes precedence over -fuse-ld= and specifies the executable
   // name. -B, COMPILER_PATH and PATH and consulted if the value does not
   // contain a path component separator.
+  // -fuse-ld=lld can be used with --ld-path= to inform clang that the binary
+  // that --ld-path= points to is lld.
   if (const Arg *A = Args.getLastArg(options::OPT_ld_path_EQ)) {
     std::string Path(A->getValue());
     if (!Path.empty()) {
       if (llvm::sys::path::parent_path(Path).empty())
         Path = GetProgramPath(A->getValue());
-      if (llvm::sys::fs::can_execute(Path))
+      if (llvm::sys::fs::can_execute(Path)) {
+        if (LinkerIsLLD)
+          *LinkerIsLLD = UseLinker == "lld";
         return std::string(Path);
+      }
     }
     getDriver().Diag(diag::err_drv_invalid_linker_name) << A->getAsString(Args);
     return GetProgramPath(getDefaultLinker());
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to