Implement -static-libgcc on linux and refactor the code responsible for adding

libgcc to the link line into a helper function.

llvm-svn: 142269
This commit is contained in:
Rafael Espindola 2011-10-17 21:39:04 +00:00
parent 30abeb1680
commit cc35432550
1 changed files with 27 additions and 31 deletions

View File

@ -4233,6 +4233,30 @@ void linuxtools::Assemble::ConstructJob(Compilation &C, const JobAction &JA,
C.addCommand(new Command(JA, *this, Exec, CmdArgs));
}
static void AddLibgcc(const Driver &D, ArgStringList &CmdArgs,
const ArgList &Args) {
bool StaticLibgcc = Args.hasArg(options::OPT_static) ||
Args.hasArg(options::OPT_static_libgcc);
if (!D.CCCIsCXX)
CmdArgs.push_back("-lgcc");
if (StaticLibgcc) {
if (D.CCCIsCXX)
CmdArgs.push_back("-lgcc");
} else {
if (!D.CCCIsCXX)
CmdArgs.push_back("--as-needed");
CmdArgs.push_back("-lgcc_s");
if (!D.CCCIsCXX)
CmdArgs.push_back("--no-as-needed");
}
if (StaticLibgcc)
CmdArgs.push_back("-lgcc_eh");
else if (!Args.hasArg(options::OPT_shared) && D.CCCIsCXX)
CmdArgs.push_back("-lgcc");
}
void linuxtools::Link::ConstructJob(Compilation &C, const JobAction &JA,
const InputInfo &Output,
const InputInfoList &Inputs,
@ -4359,24 +4383,7 @@ void linuxtools::Link::ConstructJob(Compilation &C, const JobAction &JA,
if (Args.hasArg(options::OPT_static))
CmdArgs.push_back("--start-group");
if (!D.CCCIsCXX)
CmdArgs.push_back("-lgcc");
if (Args.hasArg(options::OPT_static)) {
if (D.CCCIsCXX)
CmdArgs.push_back("-lgcc");
} else {
if (!D.CCCIsCXX)
CmdArgs.push_back("--as-needed");
CmdArgs.push_back("-lgcc_s");
if (!D.CCCIsCXX)
CmdArgs.push_back("--no-as-needed");
}
if (Args.hasArg(options::OPT_static))
CmdArgs.push_back("-lgcc_eh");
else if (!Args.hasArg(options::OPT_shared) && D.CCCIsCXX)
CmdArgs.push_back("-lgcc");
AddLibgcc(D, CmdArgs, Args);
if (Args.hasArg(options::OPT_pthread) ||
Args.hasArg(options::OPT_pthreads))
@ -4386,19 +4393,8 @@ void linuxtools::Link::ConstructJob(Compilation &C, const JobAction &JA,
if (Args.hasArg(options::OPT_static))
CmdArgs.push_back("--end-group");
else {
if (!D.CCCIsCXX)
CmdArgs.push_back("-lgcc");
if (!D.CCCIsCXX)
CmdArgs.push_back("--as-needed");
CmdArgs.push_back("-lgcc_s");
if (!D.CCCIsCXX)
CmdArgs.push_back("--no-as-needed");
if (!Args.hasArg(options::OPT_shared) && D.CCCIsCXX)
CmdArgs.push_back("-lgcc");
}
else
AddLibgcc(D, CmdArgs, Args);
if (!Args.hasArg(options::OPT_nostartfiles)) {