[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
Wed May 27 14:10:15 PDT 2020
keith created this revision.
keith added reviewers: kastiglione, MaskRay, theraven, rnk.
Herald added a project: clang.
This adds support for resolving linker executable paths relatively
instead of requiring them to be names, or absolute paths. This is useful
if you're vendoring an in-tree linker, and do not want to potentially
invalidate shared remote caches by using local absolute paths in command
lines.
Repository:
rG LLVM Github Monorepo
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,6 +4,20 @@
// RUN: | FileCheck %s --check-prefix=CHECK-ABSOLUTE-LD
// CHECK-ABSOLUTE-LD: /usr/local/bin/or1k-linux-ld
+// RUN: cd "%S" && %clang %s -### \
+// RUN: -fuse-ld=Inputs/fuse_ld_windows/ld.foo.exe 2>&1 \
+// RUN: -target x86_64-unknown-linux \
+// 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
+
+// RUN: %clang %s -### \
+// RUN: -fuse-ld=fuse_ld_windows/ld.foo.exe 2>&1 \
+// RUN: -target x86_64-unknown-linux \
+// RUN: -working-directory "%S/Inputs" \
+// 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: %clang %s -### \
// RUN: -target x86_64-unknown-freebsd 2>&1 \
Index: clang/lib/Driver/ToolChain.cpp
===================================================================
--- clang/lib/Driver/ToolChain.cpp
+++ clang/lib/Driver/ToolChain.cpp
@@ -554,6 +554,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.266656.patch
Type: text/x-patch
Size: 1902 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20200527/a566668c/attachment.bin>
More information about the cfe-commits
mailing list