]> granicus.if.org Git - clang/commitdiff
Driver: unify addClangRT{Linux,Windows}
authorSaleem Abdulrasool <compnerd@compnerd.org>
Tue, 30 Dec 2014 02:10:36 +0000 (02:10 +0000)
committerSaleem Abdulrasool <compnerd@compnerd.org>
Tue, 30 Dec 2014 02:10:36 +0000 (02:10 +0000)
The differences are pretty superficial:
- .lib vs .a extensions
- whether or not to link (potentially) incorrectly against libgcc_s

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@224975 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Driver/Tools.cpp

index 5212d46345a3a70db8a09f18c45b118a7d51b8c8..6ee9a9204cc8291ee7cbc42c27ebfa6d22c01068 100644 (file)
@@ -2124,25 +2124,23 @@ static SmallString<128> getCompilerRTLibDir(const ToolChain &TC) {
 // This adds the static libclang_rt.builtins-arch.a directly to the command line
 // FIXME: Make sure we can also emit shared objects if they're requested
 // and available, check for possible errors, etc.
-static void addClangRTLinux(
-    const ToolChain &TC, const ArgList &Args, ArgStringList &CmdArgs) {
-  SmallString<128> LibClangRT = getCompilerRTLibDir(TC);
-  llvm::sys::path::append(LibClangRT, Twine("libclang_rt.builtins-") +
-                                          getArchNameForCompilerRTLib(TC) +
-                                          ".a");
+static void addClangRT(const ToolChain &TC, const ArgList &Args,
+                       ArgStringList &CmdArgs) {
+  bool IsOSWindows = TC.getTriple().isOSWindows();
+  StringRef Arch = getArchNameForCompilerRTLib(TC);
+  const char *Suffix = IsOSWindows ? ".lib" : ".a";
 
-  CmdArgs.push_back(Args.MakeArgString(LibClangRT));
-  CmdArgs.push_back("-lgcc_s");
-  if (TC.getDriver().CCCIsCXX())
-    CmdArgs.push_back("-lgcc_eh");
-}
-
-static void addClangRTWindows(const ToolChain &TC, const ArgList &Args,
-                              ArgStringList &CmdArgs) {
   SmallString<128> LibClangRT = getCompilerRTLibDir(TC);
-  llvm::sys::path::append(LibClangRT, Twine("libclang_rt.builtins-") +
-                          getArchNameForCompilerRTLib(TC) + ".lib");
+  llvm::sys::path::append(LibClangRT,
+                          Twine("libclang_rt.builtins-") + Arch + Suffix);
+
   CmdArgs.push_back(Args.MakeArgString(LibClangRT));
+  if (!IsOSWindows) {
+    // FIXME: why do we link against gcc when we are using compiler-rt?
+    CmdArgs.push_back("-lgcc_s");
+    if (TC.getDriver().CCCIsCXX())
+      CmdArgs.push_back("-lgcc_eh");
+  }
 }
 
 static void addProfileRT(
@@ -7298,15 +7296,13 @@ static void AddRunTimeLibs(const ToolChain &TC, const Driver &D,
   // Make use of compiler-rt if --rtlib option is used
   ToolChain::RuntimeLibType RLT = TC.GetRuntimeLibType(Args);
 
-  switch(RLT) {
+  switch (RLT) {
   case ToolChain::RLT_CompilerRT:
     switch (TC.getTriple().getOS()) {
     default: llvm_unreachable("unsupported OS");
     case llvm::Triple::Win32:
-      addClangRTWindows(TC, Args, CmdArgs);
-      break;
     case llvm::Triple::Linux:
-      addClangRTLinux(TC, Args, CmdArgs);
+      addClangRT(TC, Args, CmdArgs);
       break;
     }
     break;