[Driver] Enable --rtlib option for MSVC target

This enables "--rtlib compiler-rt" option under MSVC environment.

Patch by Roman Shirokiy.

Differential Revision: http://reviews.llvm.org/D17453

llvm-svn: 263422
This commit is contained in:
Andrey Turetskiy 2016-03-14 11:19:43 +00:00
parent 392408cfc8
commit a486857cd4
3 changed files with 25 additions and 1 deletions

View File

@ -8948,7 +8948,16 @@ static void AddRunTimeLibs(const ToolChain &TC, const Driver &D,
}
break;
case ToolChain::RLT_Libgcc:
AddLibgcc(TC.getTriple(), D, CmdArgs, Args);
// Make sure libgcc is not used under MSVC environment by default
if (TC.getTriple().isKnownWindowsMSVCEnvironment()) {
// Issue error diagnostic if libgcc is explicitly specified
// through command line as --rtlib option argument.
if (Args.hasArg(options::OPT_rtlib_EQ)) {
TC.getDriver().Diag(diag::err_drv_unsupported_rtlib_for_platform)
<< Args.getLastArg(options::OPT_rtlib_EQ)->getValue() << "MSVC";
}
} else
AddLibgcc(TC.getTriple(), D, CmdArgs, Args);
break;
}
}
@ -9754,6 +9763,12 @@ void visualstudio::Linker::ConstructJob(Compilation &C, const JobAction &JA,
}
}
// Add compiler-rt lib in case if it was explicitly
// specified as an argument for --rtlib option.
if (!Args.hasArg(options::OPT_nostdlib)) {
AddRunTimeLibs(TC, TC.getDriver(), CmdArgs, Args);
}
// Add filenames, libraries, and other linker inputs.
for (const auto &Input : Inputs) {
if (Input.isFilename()) {

View File

@ -0,0 +1,5 @@
// RUN: %clang -target x86_64-pc-windows-msvc --rtlib=compiler-rt -### %s 2>&1 | FileCheck %s -check-prefix MSVC-COMPILER-RT
// RUN: not %clang %s -target x86_64-pc-windows-msvc --rtlib=libgcc 2>&1 | FileCheck %s -check-prefix CHECK-ERROR
// MSVC-COMPILER-RT: "{{.*}}clang_rt.builtins{{.*}}"
// CHECK-ERROR: unsupported runtime library 'libgcc' for platform 'MSVC'

View File

@ -22,6 +22,10 @@
// RUN: -resource-dir=%S/Inputs/resource_dir -lclang_rt.builtins-i686 \
// RUN: | FileCheck --check-prefix=CHECK-LINUX-NOSTDLIB %s
//
// RUN: %clang -target x86_64-pc-windows-msvc -nostdlib --rtlib=compiler-rt -### %s 2>&1 | FileCheck %s -check-prefix CHECK-MSVC-NOSTDLIB
// RUN: %clang -target x86_64-pc-windows-msvc --rtlib=compiler-rt -nostdlib -### %s 2>&1 | FileCheck %s -check-prefix CHECK-MSVC-NOSTDLIB
//
// CHECK-LINUX-NOSTDLIB: warning: argument unused during compilation: '--rtlib=compiler-rt'
// CHECK-LINUX-NOSTDLIB: "{{(.*[^.0-9A-Z_a-z])?}}ld{{(.exe)?}}"
// CHECK-LINUX-NOSTDLIB-NOT: "{{.*}}/Inputs/resource_dir{{/|\\\\}}lib{{/|\\\\}}linux{{/|\\\\}}libclang_rt.builtins-i686.a"
// CHECK-MSVC-NOSTDLIB: warning: argument unused during compilation: '--rtlib=compiler-rt'