r366012 - [Driver] Simplify -lgcc & -lgcc_s

Fangrui Song via cfe-commits cfe-commits at lists.llvm.org
Sat Jul 13 23:46:47 PDT 2019


Author: maskray
Date: Sat Jul 13 23:46:46 2019
New Revision: 366012

URL: http://llvm.org/viewvc/llvm-project?rev=366012&view=rev
Log:
[Driver] Simplify -lgcc & -lgcc_s

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

Modified:
    cfe/trunk/lib/Driver/ToolChains/CommonArgs.cpp

Modified: cfe/trunk/lib/Driver/ToolChains/CommonArgs.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/ToolChains/CommonArgs.cpp?rev=366012&r1=366011&r2=366012&view=diff
==============================================================================
--- cfe/trunk/lib/Driver/ToolChains/CommonArgs.cpp (original)
+++ cfe/trunk/lib/Driver/ToolChains/CommonArgs.cpp Sat Jul 13 23:46:46 2019
@@ -1135,16 +1135,12 @@ bool tools::isObjCAutoRefCount(const Arg
 
 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 ToolC
       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 ToolC
   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 &T
                       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 &T
   //
   // 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");
 }
 




More information about the cfe-commits mailing list