From: Fangrui Song Date: Sun, 14 Jul 2019 06:46:46 +0000 (+0000) Subject: [Driver] Simplify -lgcc & -lgcc_s X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=05629895331165f6f6024553c8d2e00de3f15fdf;p=clang [Driver] Simplify -lgcc & -lgcc_s gcc defaults to -shared-libgcc in C++ mode. Letting getLibGccType() return SharedLibGcc simplifies the logic. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@366012 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Driver/ToolChains/CommonArgs.cpp b/lib/Driver/ToolChains/CommonArgs.cpp index d0c9d7d396..b6a0afd7e5 100644 --- a/lib/Driver/ToolChains/CommonArgs.cpp +++ b/lib/Driver/ToolChains/CommonArgs.cpp @@ -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"); }