Refactor -KPIC handling for as invocation.

llvm-svn: 201719
This commit is contained in:
Joerg Sonnenberger 2014-02-19 21:58:52 +00:00
parent 37136c0333
commit c151b024dc
1 changed files with 21 additions and 53 deletions

View File

@ -44,6 +44,21 @@ using namespace clang::driver::tools;
using namespace clang; using namespace clang;
using namespace llvm::opt; using namespace llvm::opt;
static void addAssemblerKPIC(const ArgList &Args, ArgStringList &CmdArgs) {
Arg *LastPICArg = Args.getLastArg(options::OPT_fPIC, options::OPT_fno_PIC,
options::OPT_fpic, options::OPT_fno_pic,
options::OPT_fPIE, options::OPT_fno_PIE,
options::OPT_fpie, options::OPT_fno_pie);
if (!LastPICArg)
return;
if (LastPICArg->getOption().matches(options::OPT_fPIC) ||
LastPICArg->getOption().matches(options::OPT_fpic) ||
LastPICArg->getOption().matches(options::OPT_fPIE) ||
LastPICArg->getOption().matches(options::OPT_fpie)) {
CmdArgs.push_back("-KPIC");
}
}
/// CheckPreprocessingOptions - Perform some validation of preprocessing /// CheckPreprocessingOptions - Perform some validation of preprocessing
/// arguments that is shared with gcc. /// arguments that is shared with gcc.
static void CheckPreprocessingOptions(const Driver &D, const ArgList &Args) { static void CheckPreprocessingOptions(const Driver &D, const ArgList &Args) {
@ -5576,13 +5591,7 @@ void openbsd::Assemble::ConstructJob(Compilation &C, const JobAction &JA,
options::OPT_fpic, options::OPT_fno_pic, options::OPT_fpic, options::OPT_fno_pic,
options::OPT_fPIE, options::OPT_fno_PIE, options::OPT_fPIE, options::OPT_fno_PIE,
options::OPT_fpie, options::OPT_fno_pie); options::OPT_fpie, options::OPT_fno_pie);
if (LastPICArg && addAssemblerKPIC(Args, CmdArgs);
(LastPICArg->getOption().matches(options::OPT_fPIC) ||
LastPICArg->getOption().matches(options::OPT_fpic) ||
LastPICArg->getOption().matches(options::OPT_fPIE) ||
LastPICArg->getOption().matches(options::OPT_fpie))) {
CmdArgs.push_back("-KPIC");
}
} }
Args.AddAllArgValues(CmdArgs, options::OPT_Wa_COMMA, Args.AddAllArgValues(CmdArgs, options::OPT_Wa_COMMA,
@ -5907,17 +5916,7 @@ void freebsd::Assemble::ConstructJob(Compilation &C, const JobAction &JA,
else else
CmdArgs.push_back("-EL"); CmdArgs.push_back("-EL");
Arg *LastPICArg = Args.getLastArg(options::OPT_fPIC, options::OPT_fno_PIC, addAssemblerKPIC(Args, CmdArgs);
options::OPT_fpic, options::OPT_fno_pic,
options::OPT_fPIE, options::OPT_fno_PIE,
options::OPT_fpie, options::OPT_fno_pie);
if (LastPICArg &&
(LastPICArg->getOption().matches(options::OPT_fPIC) ||
LastPICArg->getOption().matches(options::OPT_fpic) ||
LastPICArg->getOption().matches(options::OPT_fPIE) ||
LastPICArg->getOption().matches(options::OPT_fpie))) {
CmdArgs.push_back("-KPIC");
}
} else if (getToolChain().getArch() == llvm::Triple::arm || } else if (getToolChain().getArch() == llvm::Triple::arm ||
getToolChain().getArch() == llvm::Triple::thumb) { getToolChain().getArch() == llvm::Triple::thumb) {
const Driver &D = getToolChain().getDriver(); const Driver &D = getToolChain().getDriver();
@ -5942,17 +5941,7 @@ void freebsd::Assemble::ConstructJob(Compilation &C, const JobAction &JA,
} }
} else if (getToolChain().getArch() == llvm::Triple::sparc || } else if (getToolChain().getArch() == llvm::Triple::sparc ||
getToolChain().getArch() == llvm::Triple::sparcv9) { getToolChain().getArch() == llvm::Triple::sparcv9) {
Arg *LastPICArg = Args.getLastArg(options::OPT_fPIC, options::OPT_fno_PIC, addAssemblerKPIC(Args, CmdArgs);
options::OPT_fpic, options::OPT_fno_pic,
options::OPT_fPIE, options::OPT_fno_PIE,
options::OPT_fpie, options::OPT_fno_pie);
if (LastPICArg &&
(LastPICArg->getOption().matches(options::OPT_fPIC) ||
LastPICArg->getOption().matches(options::OPT_fpic) ||
LastPICArg->getOption().matches(options::OPT_fPIE) ||
LastPICArg->getOption().matches(options::OPT_fpie))) {
CmdArgs.push_back("-KPIC");
}
} }
Args.AddAllArgValues(CmdArgs, options::OPT_Wa_COMMA, Args.AddAllArgValues(CmdArgs, options::OPT_Wa_COMMA,
@ -6191,17 +6180,7 @@ void netbsd::Assemble::ConstructJob(Compilation &C, const JobAction &JA,
else else
CmdArgs.push_back("-EL"); CmdArgs.push_back("-EL");
Arg *LastPICArg = Args.getLastArg(options::OPT_fPIC, options::OPT_fno_PIC, addAssemblerKPIC(Args, CmdArgs);
options::OPT_fpic, options::OPT_fno_pic,
options::OPT_fPIE, options::OPT_fno_PIE,
options::OPT_fpie, options::OPT_fno_pie);
if (LastPICArg &&
(LastPICArg->getOption().matches(options::OPT_fPIC) ||
LastPICArg->getOption().matches(options::OPT_fpic) ||
LastPICArg->getOption().matches(options::OPT_fPIE) ||
LastPICArg->getOption().matches(options::OPT_fpie))) {
CmdArgs.push_back("-KPIC");
}
} }
Args.AddAllArgValues(CmdArgs, options::OPT_Wa_COMMA, Args.AddAllArgValues(CmdArgs, options::OPT_Wa_COMMA,
@ -6486,19 +6465,8 @@ void gnutools::Assemble::ConstructJob(Compilation &C, const JobAction &JA,
CmdArgs.push_back(Args.MakeArgString("-march=" + CPUName)); CmdArgs.push_back(Args.MakeArgString("-march=" + CPUName));
} }
if (NeedsKPIC) { if (NeedsKPIC)
Arg *LastPICArg = Args.getLastArg(options::OPT_fPIC, options::OPT_fno_PIC, addAssemblerKPIC(Args, CmdArgs);
options::OPT_fpic, options::OPT_fno_pic,
options::OPT_fPIE, options::OPT_fno_PIE,
options::OPT_fpie, options::OPT_fno_pie);
if (LastPICArg &&
(LastPICArg->getOption().matches(options::OPT_fPIC) ||
LastPICArg->getOption().matches(options::OPT_fpic) ||
LastPICArg->getOption().matches(options::OPT_fPIE) ||
LastPICArg->getOption().matches(options::OPT_fpie))) {
CmdArgs.push_back("-KPIC");
}
}
Args.AddAllArgValues(CmdArgs, options::OPT_Wa_COMMA, Args.AddAllArgValues(CmdArgs, options::OPT_Wa_COMMA,
options::OPT_Xassembler); options::OPT_Xassembler);