From fcfc95066fbaf6b4b5e0ea8ae03fe52f4d7008c2 Mon Sep 17 00:00:00 2001 From: Dave Lee Date: Mon, 6 Nov 2017 21:18:05 +0000 Subject: [PATCH] Vary Windows toolchain selection by -fuse-ld Summary: This change allows binutils to be used for linking with MSVC. Currently, when using an MSVC target and `-fuse-ld=bfd`, the driver produces an invalid linker invocation. Reviewers: rnk, compnerd Reviewed By: compnerd Subscribers: smeenai, cfe-commits Differential Revision: https://reviews.llvm.org/D39509 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@317511 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Driver/Driver.cpp | 8 ++++++- test/Driver/Inputs/Windows/usr/bin/ld.bfd | 0 test/Driver/fuse-ld.c | 26 +++++++++++++++++++++++ 3 files changed, 33 insertions(+), 1 deletion(-) create mode 100755 test/Driver/Inputs/Windows/usr/bin/ld.bfd diff --git a/lib/Driver/Driver.cpp b/lib/Driver/Driver.cpp index 765b006e90..e14a596d98 100644 --- a/lib/Driver/Driver.cpp +++ b/lib/Driver/Driver.cpp @@ -3880,7 +3880,13 @@ const ToolChain &Driver::getToolChain(const ArgList &Args, break; case llvm::Triple::MSVC: case llvm::Triple::UnknownEnvironment: - TC = llvm::make_unique(*this, Target, Args); + if (Args.getLastArgValue(options::OPT_fuse_ld_EQ) + .startswith_lower("bfd")) + TC = llvm::make_unique( + *this, Target, Args); + else + TC = + llvm::make_unique(*this, Target, Args); break; } break; diff --git a/test/Driver/Inputs/Windows/usr/bin/ld.bfd b/test/Driver/Inputs/Windows/usr/bin/ld.bfd new file mode 100755 index 0000000000..e69de29bb2 diff --git a/test/Driver/fuse-ld.c b/test/Driver/fuse-ld.c index bd8c9a5386..b043ce624e 100644 --- a/test/Driver/fuse-ld.c +++ b/test/Driver/fuse-ld.c @@ -67,3 +67,29 @@ // RUN: -gcc-toolchain %S/Inputs/basic_android_tree 2>&1 \ // RUN: | FileCheck %s -check-prefix=CHECK-ANDROID-ARM-GOLD-TC // CHECK-ANDROID-ARM-GOLD-TC: Inputs/basic_android_tree/lib/gcc/arm-linux-androideabi/4.4.3/../../../../arm-linux-androideabi/bin{{/|\\+}}ld.gold + + +// RUN: %clang %s -### -fuse-ld=link \ +// RUN: -target i686-unknown-windows-msvc 2>&1 \ +// RUN: | FileCheck %s --check-prefix CHECK-WINDOWS-MSVC-LINK +// CHECK-WINDOWS-MSVC-LINK: "{{.*}}link.exe" +// CHECK-WINDOWS-MSVC-LINK-SAME: "-out:{{.*}}" + +// RUN: %clang %s -### -fuse-ld=lld \ +// RUN: -target i686-unknown-windows-msvc 2>&1 \ +// RUN: | FileCheck %s --check-prefix CHECK-WINDOWS-MSVC-LLD +// CHECK-WINDOWS-MSVC-LLD: "{{.*}}lld-link" +// CHECK-WINDOWS-MSVC-LLD-SAME: "-out:{{.*}}" + +// RUN: %clang %s -### -fuse-ld=lld-link \ +// RUN: -target i686-unknown-windows-msvc 2>&1 \ +// RUN: | FileCheck %s --check-prefix CHECK-WINDOWS-MSVC-LLD-LINK +// CHECK-WINDOWS-MSVC-LLD-LINK: "{{.*}}lld-link" +// CHECK-WINDOWS-MSVC-LLD-LINK-SAME: "-out:{{.*}}" + +// RUN: %clang %s -### -fuse-ld=bfd \ +// RUN: -target i686-unknown-windows-msvc \ +// RUN: -B %S/Inputs/Windows/usr/bin 2>&1 \ +// RUN: | FileCheck %s --check-prefix CHECK-WINDOWS-MSVC-BFD +// CHECK-WINDOWS-MSVC-BFD: "{{.*}}ld.bfd" +// CHECK-WINDOWS-MSVC-BFD-SAME: "-o" -- 2.40.0