[Driver] Simplify -lgcc & -lgcc_s

gcc defaults to -shared-libgcc in C++ mode.
Letting getLibGccType() return SharedLibGcc simplifies the logic.

llvm-svn: 366012
This commit is contained in:
Fangrui Song 2019-07-14 06:46:46 +00:00
parent 9450b0084a
commit c7f9559d65
1 changed files with 13 additions and 17 deletions

View File

@ -1135,16 +1135,12 @@ bool tools::isObjCAutoRefCount(const ArgList &Args) {
enum class LibGccType { UnspecifiedLibGcc, StaticLibGcc, SharedLibGcc };
static LibGccType getLibGccType(const ArgList &Args) {
bool Static = Args.hasArg(options::OPT_static_libgcc) ||
Args.hasArg(options::OPT_static) ||
Args.hasArg(options::OPT_static_pie);
bool Shared = Args.hasArg(options::OPT_shared_libgcc);
if (Shared)
return LibGccType::SharedLibGcc;
if (Static)
static LibGccType getLibGccType(const Driver &D, const ArgList &Args) {
if (Args.hasArg(options::OPT_static_libgcc) ||
Args.hasArg(options::OPT_static) || Args.hasArg(options::OPT_static_pie))
return LibGccType::StaticLibGcc;
if (Args.hasArg(options::OPT_shared_libgcc) || D.CCCIsCXX())
return LibGccType::SharedLibGcc;
return LibGccType::UnspecifiedLibGcc;
}
@ -1170,8 +1166,8 @@ static void AddUnwindLibrary(const ToolChain &TC, const Driver &D,
UNW == ToolChain::UNW_None)
return;
LibGccType LGT = getLibGccType(Args);
bool AsNeeded = D.CCCIsCC() && LGT == LibGccType::UnspecifiedLibGcc &&
LibGccType LGT = getLibGccType(D, Args);
bool AsNeeded = LGT == LibGccType::UnspecifiedLibGcc &&
!TC.getTriple().isAndroid() && !TC.getTriple().isOSCygMing();
if (AsNeeded)
CmdArgs.push_back("--as-needed");
@ -1180,11 +1176,11 @@ static void AddUnwindLibrary(const ToolChain &TC, const Driver &D,
case ToolChain::UNW_None:
return;
case ToolChain::UNW_Libgcc: {
LibGccType LGT = getLibGccType(Args);
if (LGT == LibGccType::UnspecifiedLibGcc || LGT == LibGccType::SharedLibGcc)
CmdArgs.push_back("-lgcc_s");
else if (LGT == LibGccType::StaticLibGcc)
LibGccType LGT = getLibGccType(D, Args);
if (LGT == LibGccType::StaticLibGcc)
CmdArgs.push_back("-lgcc_eh");
else
CmdArgs.push_back("-lgcc_s");
break;
}
case ToolChain::UNW_CompilerRT:
@ -1200,7 +1196,7 @@ static void AddLibgcc(const ToolChain &TC, const Driver &D,
ArgStringList &CmdArgs, const ArgList &Args) {
bool isAndroid = TC.getTriple().isAndroid();
LibGccType LGT = getLibGccType(Args);
LibGccType LGT = getLibGccType(D, Args);
bool LibGccFirst = (D.CCCIsCC() && LGT == LibGccType::UnspecifiedLibGcc) ||
LGT == LibGccType::StaticLibGcc;
if (LibGccFirst)
@ -1216,7 +1212,7 @@ static void AddLibgcc(const ToolChain &TC, const Driver &D,
//
// NOTE: This fixes a link error on Android MIPS as well. The non-static
// libgcc for MIPS relies on _Unwind_Find_FDE and dl_iterate_phdr from libdl.
if (isAndroid && getLibGccType(Args) != LibGccType::StaticLibGcc)
if (isAndroid && getLibGccType(D, Args) != LibGccType::StaticLibGcc)
CmdArgs.push_back("-ldl");
}