]> granicus.if.org Git - clang/commitdiff
[Driver] Support object files in addition to static and shared libraries in compiler-rt
authorPetr Hosek <phosek@chromium.org>
Tue, 12 Mar 2019 02:12:48 +0000 (02:12 +0000)
committerPetr Hosek <phosek@chromium.org>
Tue, 12 Mar 2019 02:12:48 +0000 (02:12 +0000)
This change introduces support for object files in addition to static
and shared libraries which were already supported which requires
changing the type of the argument from boolean to an enum.

Differential Revision: https://reviews.llvm.org/D56044

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

include/clang/Driver/ToolChain.h
lib/Driver/ToolChain.cpp
lib/Driver/ToolChains/CommonArgs.cpp
lib/Driver/ToolChains/MinGW.cpp
lib/Driver/ToolChains/MipsLinux.cpp
lib/Driver/ToolChains/MipsLinux.h

index 3b184987d02b40e7f1d0b814f99831b8d889f550..24ba25ae024e216a65d5e69bf392c729e11184a0 100644 (file)
@@ -104,6 +104,8 @@ public:
     RM_Disabled,
   };
 
+  enum FileType { FT_Object, FT_Static, FT_Shared };
+
 private:
   friend class RegisterEffectiveTriple;
 
@@ -371,11 +373,11 @@ public:
 
   virtual std::string getCompilerRT(const llvm::opt::ArgList &Args,
                                     StringRef Component,
-                                    bool Shared = false) const;
+                                    FileType Type = ToolChain::FT_Static) const;
 
-  const char *getCompilerRTArgString(const llvm::opt::ArgList &Args,
-                                     StringRef Component,
-                                     bool Shared = false) const;
+  const char *
+  getCompilerRTArgString(const llvm::opt::ArgList &Args, StringRef Component,
+                         FileType Type = ToolChain::FT_Static) const;
 
   // Returns <ResourceDir>/lib/<OSName>/<arch>.  This is used by runtimes (such
   // as OpenMP) to find arch-specific libraries.
index a89983d95538b2cc9e518ad4276d1e7a299ab482..6b5627157091d26c5105c1b406d673485e5e172f 100644 (file)
@@ -362,16 +362,27 @@ std::string ToolChain::getCompilerRTPath() const {
 }
 
 std::string ToolChain::getCompilerRT(const ArgList &Args, StringRef Component,
-                                     bool Shared) const {
+                                     FileType Type) const {
   const llvm::Triple &TT = getTriple();
   bool IsITANMSVCWindows =
       TT.isWindowsMSVCEnvironment() || TT.isWindowsItaniumEnvironment();
 
-  const char *Prefix = IsITANMSVCWindows ? "" : "lib";
-  const char *Suffix = Shared ? (Triple.isOSWindows() ? ".lib" : ".so")
-                              : (IsITANMSVCWindows ? ".lib" : ".a");
-  if (Shared && Triple.isWindowsGNUEnvironment())
-    Suffix = ".dll.a";
+  const char *Prefix =
+      IsITANMSVCWindows || Type == ToolChain::FT_Object ? "" : "lib";
+  const char *Suffix;
+  switch (Type) {
+  case ToolChain::FT_Object:
+    Suffix = IsITANMSVCWindows ? ".obj" : ".o";
+    break;
+  case ToolChain::FT_Static:
+    Suffix = IsITANMSVCWindows ? ".lib" : ".a";
+    break;
+  case ToolChain::FT_Shared:
+    Suffix = Triple.isOSWindows()
+                 ? (Triple.isWindowsGNUEnvironment() ? ".dll.a" : ".lib")
+                 : ".so";
+    break;
+  }
 
   for (const auto &LibPath : getLibraryPaths()) {
     SmallString<128> P(LibPath);
@@ -390,8 +401,8 @@ std::string ToolChain::getCompilerRT(const ArgList &Args, StringRef Component,
 
 const char *ToolChain::getCompilerRTArgString(const llvm::opt::ArgList &Args,
                                               StringRef Component,
-                                              bool Shared) const {
-  return Args.MakeArgString(getCompilerRT(Args, Component, Shared));
+                                              FileType Type) const {
+  return Args.MakeArgString(getCompilerRT(Args, Component, Type));
 }
 
 std::string ToolChain::getArchSpecificLibPath() const {
index a90ac9fcc83ed890517c7b67d5c5be703d7f35c8..eb22f8d24f84ad7c34369aa3d470eea63a868a8d 100644 (file)
@@ -535,7 +535,8 @@ static void addSanitizerRuntime(const ToolChain &TC, const ArgList &Args,
   // Wrap any static runtimes that must be forced into executable in
   // whole-archive.
   if (IsWhole) CmdArgs.push_back("--whole-archive");
-  CmdArgs.push_back(TC.getCompilerRTArgString(Args, Sanitizer, IsShared));
+  CmdArgs.push_back(TC.getCompilerRTArgString(
+      Args, Sanitizer, IsShared ? ToolChain::FT_Shared : ToolChain::FT_Static));
   if (IsWhole) CmdArgs.push_back("--no-whole-archive");
 
   if (IsShared) {
index 7b2af0cbe3880cf0e114d8e533d5dc975e7de7d1..b08ca7a845451a15a1b0ae303758143800f16ef7 100644 (file)
@@ -248,8 +248,8 @@ void tools::MinGW::Linker::ConstructJob(Compilation &C, const JobAction &JA,
 
       if (Sanitize.needsAsanRt()) {
         // MinGW always links against a shared MSVCRT.
-        CmdArgs.push_back(
-            TC.getCompilerRTArgString(Args, "asan_dynamic", true));
+        CmdArgs.push_back(TC.getCompilerRTArgString(Args, "asan_dynamic",
+                                                    ToolChain::FT_Shared));
         CmdArgs.push_back(
             TC.getCompilerRTArgString(Args, "asan_dynamic_runtime_thunk"));
         CmdArgs.push_back(Args.MakeArgString("--require-defined"));
index 47d8363fc46bc81bb45b0ebfd876391a5b517e7e..cfda7f4bb4dfddce1c0161145c25c4ac8fd1a90b 100644 (file)
@@ -118,11 +118,23 @@ void MipsLLVMToolChain::AddCXXStdlibLibArgs(const ArgList &Args,
 
 std::string MipsLLVMToolChain::getCompilerRT(const ArgList &Args,
                                              StringRef Component,
-                                             bool Shared) const {
+                                             FileType Type) const {
   SmallString<128> Path(getDriver().ResourceDir);
   llvm::sys::path::append(Path, SelectedMultilib.osSuffix(), "lib" + LibSuffix,
                           getOS());
-  llvm::sys::path::append(Path, Twine("libclang_rt." + Component + "-" +
-                                      "mips" + (Shared ? ".so" : ".a")));
+  const char *Suffix;
+  switch (Type) {
+  case ToolChain::FT_Object:
+    Suffix = ".o";
+    break;
+  case ToolChain::FT_Static:
+    Suffix = ".a";
+    break;
+  case ToolChain::FT_Shared:
+    Suffix = ".so";
+    break;
+  }
+  llvm::sys::path::append(
+      Path, Twine("libclang_rt." + Component + "-" + "mips" + Suffix));
   return Path.str();
 }
index 929d0bca604ae900153b0ca0c1662684c17bebac..31b547c0063ca7391978786ea1e6ad8f4ea640bc 100644 (file)
@@ -37,8 +37,9 @@ public:
   void AddCXXStdlibLibArgs(const llvm::opt::ArgList &Args,
                            llvm::opt::ArgStringList &CmdArgs) const override;
 
-  std::string getCompilerRT(const llvm::opt::ArgList &Args, StringRef Component,
-                            bool Shared = false) const override;
+  std::string
+  getCompilerRT(const llvm::opt::ArgList &Args, StringRef Component,
+                FileType Type = ToolChain::FT_Static) const override;
 
   std::string computeSysRoot() const override;