[PATCH] D80660: clang: Add support for relative linker paths with -fuse-ld

Keith Smiley via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Tue Jun 2 14:16:19 PDT 2020


keith updated this revision to Diff 267991.
keith added a comment.

Fix test on windows


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D80660

Files:
  clang/lib/Driver/ToolChain.cpp
  clang/test/Driver/fuse-ld.c


Index: clang/test/Driver/fuse-ld.c
===================================================================
--- clang/test/Driver/fuse-ld.c
+++ clang/test/Driver/fuse-ld.c
@@ -4,7 +4,6 @@
 // RUN:   | FileCheck %s --check-prefix=CHECK-ABSOLUTE-LD
 // CHECK-ABSOLUTE-LD: /usr/local/bin/or1k-linux-ld
 
-
 // RUN: %clang %s -### \
 // RUN:     -target x86_64-unknown-freebsd 2>&1 \
 // RUN:   | FileCheck %s --check-prefix=CHECK-FREEBSD-LD
@@ -94,3 +93,18 @@
 // RUN:   | FileCheck %s --check-prefix CHECK-WINDOWS-MSVC-BFD
 // CHECK-WINDOWS-MSVC-BFD: "{{.*}}ld.bfd"
 // CHECK-WINDOWS-MSVC-BFD-SAME: "-o"
+
+// RUN: %clang %s -### \
+// RUN:     -target x86_64-unknown-linux \
+// RUN:     -working-directory "%S/Inputs" \
+// RUN:     -fuse-ld=fuse_ld_windows/ld.foo.exe 2>&1 \
+// RUN:   | FileCheck %s --check-prefix=CHECK-RELATIVE-WORKDIR-LD
+// CHECK-RELATIVE-WORKDIR-LD-NOT: error: invalid linker name
+// CHECK-RELATIVE-WORKDIR-LD: test{{/|\\+}}Driver{{/|\\+}}Inputs{{/|\\+}}fuse_ld_windows/ld.foo.exe
+
+// RUN: cd "%S" && %clang %s -### \
+// RUN:     -target x86_64-unknown-linux \
+// RUN:     -fuse-ld=Inputs/fuse_ld_windows/ld.foo.exe 2>&1 \
+// RUN:   | FileCheck %s --check-prefix=CHECK-RELATIVE-LD
+// CHECK-RELATIVE-LD-NOT: error: invalid linker name
+// CHECK-RELATIVE-LD: test{{/|\\+}}Driver{{/|\\+}}Inputs{{/|\\+}}fuse_ld_windows/ld.foo.exe
Index: clang/lib/Driver/ToolChain.cpp
===================================================================
--- clang/lib/Driver/ToolChain.cpp
+++ clang/lib/Driver/ToolChain.cpp
@@ -557,6 +557,18 @@
     std::string LinkerPath(GetProgramPath(LinkerName.c_str()));
     if (llvm::sys::fs::can_execute(LinkerPath))
       return LinkerPath;
+
+    const Arg *WorkingDir = Args.getLastArg(options::OPT_working_directory);
+    SmallString<128> ResolvedPath(UseLinker);
+    if (WorkingDir) {
+      sys::fs::make_absolute(WorkingDir->getValue(), ResolvedPath);
+      if (llvm::sys::fs::can_execute(ResolvedPath))
+        return std::string(ResolvedPath);
+    }
+
+    if (!sys::fs::make_absolute(ResolvedPath) &&
+        llvm::sys::fs::can_execute(ResolvedPath))
+      return std::string(ResolvedPath);
   }
 
   if (A)


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D80660.267991.patch
Type: text/x-patch
Size: 2173 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20200602/01a12ec0/attachment-0001.bin>


More information about the cfe-commits mailing list