r217895 - Fix forwarding -l to MSVC's link.exe
Reid Kleckner
reid at kleckner.net
Tue Sep 16 12:22:00 PDT 2014
Author: rnk
Date: Tue Sep 16 14:22:00 2014
New Revision: 217895
URL: http://llvm.org/viewvc/llvm-project?rev=217895&view=rev
Log:
Fix forwarding -l to MSVC's link.exe
Translate -lfoo to -lfoo.lib while making sure that -lfoo.lib stays as
-lfoo.lib. Also, these arguments were being passed twice: once
explicitly via AddAllArgs, and again implicitly as linker inputs. Now
they are passed once.
Fixes PR20868.
Modified:
cfe/trunk/lib/Driver/Tools.cpp
cfe/trunk/test/Driver/msvc_forward.c
Modified: cfe/trunk/lib/Driver/Tools.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/Tools.cpp?rev=217895&r1=217894&r2=217895&view=diff
==============================================================================
--- cfe/trunk/lib/Driver/Tools.cpp (original)
+++ cfe/trunk/lib/Driver/Tools.cpp Tue Sep 16 14:22:00 2014
@@ -7825,15 +7825,33 @@ void visualstudio::Link::ConstructJob(Co
}
}
- Args.AddAllArgValues(CmdArgs, options::OPT_l);
Args.AddAllArgValues(CmdArgs, options::OPT__SLASH_link);
- // Add filenames immediately.
- for (const auto &Input : Inputs)
- if (Input.isFilename())
+ // Add filenames, libraries, and other linker inputs.
+ for (const auto &Input : Inputs) {
+ if (Input.isFilename()) {
CmdArgs.push_back(Input.getFilename());
- else
- Input.getInputArg().renderAsInput(Args, CmdArgs);
+ continue;
+ }
+
+ const Arg &A = Input.getInputArg();
+
+ // Render -l options differently for the MSVC linker.
+ if (A.getOption().matches(options::OPT_l)) {
+ StringRef Lib = A.getValue();
+ const char *LinkLibArg;
+ if (Lib.endswith(".lib"))
+ LinkLibArg = Args.MakeArgString(Lib);
+ else
+ LinkLibArg = Args.MakeArgString(Lib + ".lib");
+ CmdArgs.push_back(LinkLibArg);
+ continue;
+ }
+
+ // Otherwise, this is some other kind of linker input option like -Wl, -z,
+ // or -L. Render it, even if MSVC doesn't understand it.
+ A.renderAsInput(Args, CmdArgs);
+ }
const char *Exec =
Args.MakeArgString(getToolChain().GetProgramPath("link.exe"));
Modified: cfe/trunk/test/Driver/msvc_forward.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Driver/msvc_forward.c?rev=217895&r1=217894&r2=217895&view=diff
==============================================================================
--- cfe/trunk/test/Driver/msvc_forward.c (original)
+++ cfe/trunk/test/Driver/msvc_forward.c Tue Sep 16 14:22:00 2014
@@ -1,5 +1,7 @@
-// RUN: %clang -target i686-pc-win32 -lkernel32.lib -luser32.lib -### %s 2>&1 | FileCheck %s
+// RUN: %clang -target i686-pc-win32 -loldnames -lkernel32.lib -luser32.lib -### %s 2>&1 | FileCheck %s
+// CHECK-NOT: "-loldnames.lib"
// CHECK-NOT: "-lkernel32.lib"
// CHECK-NOT: "-luser32.lib"
+// CHECK: "oldnames.lib"
// CHECK: "kernel32.lib"
// CHECK: "user32.lib"
More information about the cfe-commits
mailing list