mirror of https://github.com/microsoft/clang.git
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. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@217895 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
ac1430893a
commit
d2ad1701f6
|
@ -7825,15 +7825,33 @@ void visualstudio::Link::ConstructJob(Compilation &C, const JobAction &JA,
|
|||
}
|
||||
}
|
||||
|
||||
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"));
|
||||
|
|
|
@ -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"
|
||||
|
|
Loading…
Reference in New Issue