forked from OSchip/llvm-project
clang-cl: Support /link option and set target to win32
This adds support for the /link option, which forwards subsequent arguments to the linker. The test for this will only work when targetting win32. Since that's the only target where clang-cl makes sense, use that target by default. Differential Revision: http://llvm-reviews.chandlerc.com/D1388 llvm-svn: 188331
This commit is contained in:
parent
7a15c4af90
commit
2e27459d6c
|
@ -32,6 +32,9 @@ class CLIgnoredJoined<string name> : Option<["/", "-"], name, KIND_JOINED>,
|
||||||
class CLJoinedOrSeparate<string name> : Option<["/", "-"], name,
|
class CLJoinedOrSeparate<string name> : Option<["/", "-"], name,
|
||||||
KIND_JOINED_OR_SEPARATE>, Group<cl_Group>, Flags<[CLOption, DriverOption]>;
|
KIND_JOINED_OR_SEPARATE>, Group<cl_Group>, Flags<[CLOption, DriverOption]>;
|
||||||
|
|
||||||
|
class CLRemainingArgs<string name> : Option<["/", "-"], name,
|
||||||
|
KIND_REMAINING_ARGS>, Group<cl_Group>, Flags<[CLOption, DriverOption]>;
|
||||||
|
|
||||||
// Aliases:
|
// Aliases:
|
||||||
|
|
||||||
def _SLASH_c : CLFlag<"c">, HelpText<"Compile only">, Alias<c>;
|
def _SLASH_c : CLFlag<"c">, HelpText<"Compile only">, Alias<c>;
|
||||||
|
@ -96,6 +99,8 @@ def _SLASH_Fe : CLJoined<"Fe">,
|
||||||
def _SLASH_Fo : CLJoined<"Fo">,
|
def _SLASH_Fo : CLJoined<"Fo">,
|
||||||
HelpText<"Set output object file, or directory (ends in / or \\)">,
|
HelpText<"Set output object file, or directory (ends in / or \\)">,
|
||||||
MetaVarName<"<file or directory>">;
|
MetaVarName<"<file or directory>">;
|
||||||
|
def _SLASH_link : CLRemainingArgs<"link">,
|
||||||
|
HelpText<"Forward options to the linker">, MetaVarName<"<options>">;
|
||||||
def _SLASH_MD : CLFlag<"MD">,
|
def _SLASH_MD : CLFlag<"MD">,
|
||||||
HelpText<"Use DLL run-time">;
|
HelpText<"Use DLL run-time">;
|
||||||
def _SLASH_MDd : CLFlag<"MDd">,
|
def _SLASH_MDd : CLFlag<"MDd">,
|
||||||
|
|
|
@ -351,6 +351,12 @@ Compilation *Driver::BuildCompilation(ArrayRef<const char *> ArgList) {
|
||||||
options::OPT_ccc_pch_is_pth);
|
options::OPT_ccc_pch_is_pth);
|
||||||
// FIXME: DefaultTargetTriple is used by the target-prefixed calls to as/ld
|
// FIXME: DefaultTargetTriple is used by the target-prefixed calls to as/ld
|
||||||
// and getToolChain is const.
|
// and getToolChain is const.
|
||||||
|
if (IsCLMode()) {
|
||||||
|
// clang-cl targets Win32.
|
||||||
|
llvm::Triple T(DefaultTargetTriple);
|
||||||
|
T.setOSName(llvm::Triple::getOSTypeName(llvm::Triple::Win32));
|
||||||
|
DefaultTargetTriple = T.str();
|
||||||
|
}
|
||||||
if (const Arg *A = Args->getLastArg(options::OPT_target))
|
if (const Arg *A = Args->getLastArg(options::OPT_target))
|
||||||
DefaultTargetTriple = A->getValue();
|
DefaultTargetTriple = A->getValue();
|
||||||
if (const Arg *A = Args->getLastArg(options::OPT_ccc_install_dir))
|
if (const Arg *A = Args->getLastArg(options::OPT_ccc_install_dir))
|
||||||
|
|
|
@ -6590,12 +6590,14 @@ void visualstudio::Link::ConstructJob(Compilation &C, const JobAction &JA,
|
||||||
CmdArgs.push_back("-nologo");
|
CmdArgs.push_back("-nologo");
|
||||||
|
|
||||||
Args.AddAllArgValues(CmdArgs, options::OPT_l);
|
Args.AddAllArgValues(CmdArgs, options::OPT_l);
|
||||||
|
Args.AddAllArgValues(CmdArgs, options::OPT__SLASH_link);
|
||||||
|
|
||||||
// Add filenames immediately.
|
// Add filenames immediately.
|
||||||
for (InputInfoList::const_iterator
|
for (InputInfoList::const_iterator
|
||||||
it = Inputs.begin(), ie = Inputs.end(); it != ie; ++it) {
|
it = Inputs.begin(), ie = Inputs.end(); it != ie; ++it) {
|
||||||
if (it->isFilename())
|
if (it->isFilename())
|
||||||
CmdArgs.push_back(it->getFilename());
|
CmdArgs.push_back(it->getFilename());
|
||||||
|
// FIXME: Forward -Wl, etc.
|
||||||
}
|
}
|
||||||
|
|
||||||
const char *Exec =
|
const char *Exec =
|
||||||
|
|
|
@ -0,0 +1,12 @@
|
||||||
|
// Don't attempt slash switches on msys bash.
|
||||||
|
// REQUIRES: shell-preserves-root
|
||||||
|
|
||||||
|
// Note: %s must be preceded by -- or bound to another option, otherwise it may
|
||||||
|
// be interpreted as a command-line option, e.g. on Mac where %s is commonly
|
||||||
|
// under /Users.
|
||||||
|
|
||||||
|
// RUN: %clang_cl /Tc%s -### /link foo bar baz 2>&1 | FileCheck %s
|
||||||
|
// CHECK: link.exe
|
||||||
|
// CHECK: "foo"
|
||||||
|
// CHECK: "bar"
|
||||||
|
// CHECK: "baz"
|
Loading…
Reference in New Issue