[PATCH] D134063: [clang] Make --ld-path= work with -fuse-ld=lld

Nico Weber via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Fri Sep 16 12:30:28 PDT 2022


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


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D134063.460848.patch
Type: text/x-patch
Size: 1874 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20220916/5ce05dcd/attachment.bin>


More information about the cfe-commits mailing list