[PATCH] D80225: [Driver] Recognize -fuse-ld={bfd, gold, lld} but don't prepend "ld." or "ld64." for other values
Fangrui Song via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Tue May 19 12:37:11 PDT 2020
MaskRay updated this revision to Diff 264995.
MaskRay added a comment.
Fix fuse-ld-windows.c (I don't have Windows (REQUIRES: system-windows), so I failed to catch the issue earlier)
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D80225/new/
https://reviews.llvm.org/D80225
Files:
clang/lib/Driver/ToolChain.cpp
clang/test/Driver/Inputs/Windows/ARM/8.1/usr/bin/ld.lld-link2
clang/test/Driver/Inputs/Windows/ARM/8.1/usr/bin/lld-link2
clang/test/Driver/Inputs/fuse_ld_windows/foo.exe
clang/test/Driver/Inputs/fuse_ld_windows/ld.foo.exe
clang/test/Driver/fuse-ld-windows.c
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
@@ -15,6 +15,12 @@
// RUN: -target x86_64-unknown-freebsd \
// RUN: -B%S/Inputs/basic_freebsd_tree/usr/bin 2>&1 \
// RUN: | FileCheck %s -check-prefix=CHECK-FREEBSD-BFD
+// RUN: %clang %s -### -fuse-ld=ld.bfd \
+// RUN: --sysroot=%S/Inputs/basic_freebsd_tree \
+// RUN: -target x86_64-unknown-freebsd \
+// RUN: -B%S/Inputs/basic_freebsd_tree/usr/bin 2>&1 \
+// RUN: | FileCheck %s -check-prefix=CHECK-FREEBSD-BFD
+
// CHECK-FREEBSD-BFD: Inputs/basic_freebsd_tree/usr/bin{{/|\\+}}ld.bfd
// RUN: %clang %s -### -fuse-ld=gold \
@@ -22,6 +28,12 @@
// RUN: -target x86_64-unknown-freebsd \
// RUN: -B%S/Inputs/basic_freebsd_tree/usr/bin 2>&1 \
// RUN: | FileCheck %s -check-prefix=CHECK-FREEBSD-GOLD
+// RUN: %clang %s -### -fuse-ld=ld.gold \
+// RUN: --sysroot=%S/Inputs/basic_freebsd_tree \
+// RUN: -target x86_64-unknown-freebsd \
+// RUN: -B%S/Inputs/basic_freebsd_tree/usr/bin 2>&1 \
+// RUN: | FileCheck %s -check-prefix=CHECK-FREEBSD-GOLD
+
// CHECK-FREEBSD-GOLD: Inputs/basic_freebsd_tree/usr/bin{{/|\\+}}ld.gold
// RUN: %clang %s -### -fuse-ld=plib \
Index: clang/test/Driver/fuse-ld-windows.c
===================================================================
--- clang/test/Driver/fuse-ld-windows.c
+++ clang/test/Driver/fuse-ld-windows.c
@@ -22,4 +22,4 @@
// RUN: | FileCheck %s
// CHECK-NOT: invalid linker name
-// CHECK: /Inputs/fuse_ld_windows{{/|\\\\}}ld.foo
+// CHECK: /Inputs/fuse_ld_windows{{/|\\\\}}foo
Index: clang/lib/Driver/ToolChain.cpp
===================================================================
--- clang/lib/Driver/ToolChain.cpp
+++ clang/lib/Driver/ToolChain.cpp
@@ -534,21 +534,24 @@
const Arg* A = Args.getLastArg(options::OPT_fuse_ld_EQ);
StringRef UseLinker = A ? A->getValue() : CLANG_DEFAULT_LINKER;
+ // 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 (llvm::sys::path::is_absolute(UseLinker)) {
// If we're passed what looks like an absolute path, don't attempt to
// second-guess that.
if (llvm::sys::fs::can_execute(UseLinker))
return std::string(UseLinker);
- } else if (UseLinker.empty() || UseLinker == "ld") {
- // If we're passed -fuse-ld= with no argument, or with the argument ld,
- // then use whatever the default system linker is.
- return GetProgramPath(getDefaultLinker());
} else {
llvm::SmallString<8> LinkerName;
- if (Triple.isOSDarwin())
- LinkerName.append("ld64.");
- else
+ // Recognize common abbreviations by appending an OS specific prefix.
+ if (Triple.isOSDarwin()) {
+ if (UseLinker == "lld")
+ LinkerName.append("ld64.");
+ } else if (UseLinker == "bfd" || UseLinker == "gold" || UseLinker == "lld")
LinkerName.append("ld.");
+
LinkerName.append(UseLinker);
std::string LinkerPath(GetProgramPath(LinkerName.c_str()));
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D80225.264995.patch
Type: text/x-patch
Size: 3201 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20200519/2547b13b/attachment.bin>
More information about the cfe-commits
mailing list