r355891 - [Driver] Support object files in addition to static and shared libraries in compiler-rt
Petr Hosek via cfe-commits
cfe-commits at lists.llvm.org
Mon Mar 11 19:12:49 PDT 2019
Author: phosek
Date: Mon Mar 11 19:12:48 2019
New Revision: 355891
URL: http://llvm.org/viewvc/llvm-project?rev=355891&view=rev
Log:
[Driver] Support object files in addition to static and shared libraries in compiler-rt
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
Modified:
cfe/trunk/include/clang/Driver/ToolChain.h
cfe/trunk/lib/Driver/ToolChain.cpp
cfe/trunk/lib/Driver/ToolChains/CommonArgs.cpp
cfe/trunk/lib/Driver/ToolChains/MinGW.cpp
cfe/trunk/lib/Driver/ToolChains/MipsLinux.cpp
cfe/trunk/lib/Driver/ToolChains/MipsLinux.h
Modified: cfe/trunk/include/clang/Driver/ToolChain.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Driver/ToolChain.h?rev=355891&r1=355890&r2=355891&view=diff
==============================================================================
--- cfe/trunk/include/clang/Driver/ToolChain.h (original)
+++ cfe/trunk/include/clang/Driver/ToolChain.h Mon Mar 11 19:12:48 2019
@@ -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.
Modified: cfe/trunk/lib/Driver/ToolChain.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/ToolChain.cpp?rev=355891&r1=355890&r2=355891&view=diff
==============================================================================
--- cfe/trunk/lib/Driver/ToolChain.cpp (original)
+++ cfe/trunk/lib/Driver/ToolChain.cpp Mon Mar 11 19:12:48 2019
@@ -362,16 +362,27 @@ std::string ToolChain::getCompilerRTPath
}
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(con
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 {
Modified: cfe/trunk/lib/Driver/ToolChains/CommonArgs.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/ToolChains/CommonArgs.cpp?rev=355891&r1=355890&r2=355891&view=diff
==============================================================================
--- cfe/trunk/lib/Driver/ToolChains/CommonArgs.cpp (original)
+++ cfe/trunk/lib/Driver/ToolChains/CommonArgs.cpp Mon Mar 11 19:12:48 2019
@@ -535,7 +535,8 @@ static void addSanitizerRuntime(const To
// 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) {
Modified: cfe/trunk/lib/Driver/ToolChains/MinGW.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/ToolChains/MinGW.cpp?rev=355891&r1=355890&r2=355891&view=diff
==============================================================================
--- cfe/trunk/lib/Driver/ToolChains/MinGW.cpp (original)
+++ cfe/trunk/lib/Driver/ToolChains/MinGW.cpp Mon Mar 11 19:12:48 2019
@@ -248,8 +248,8 @@ void tools::MinGW::Linker::ConstructJob(
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"));
Modified: cfe/trunk/lib/Driver/ToolChains/MipsLinux.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/ToolChains/MipsLinux.cpp?rev=355891&r1=355890&r2=355891&view=diff
==============================================================================
--- cfe/trunk/lib/Driver/ToolChains/MipsLinux.cpp (original)
+++ cfe/trunk/lib/Driver/ToolChains/MipsLinux.cpp Mon Mar 11 19:12:48 2019
@@ -118,11 +118,23 @@ void MipsLLVMToolChain::AddCXXStdlibLibA
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();
}
Modified: cfe/trunk/lib/Driver/ToolChains/MipsLinux.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/ToolChains/MipsLinux.h?rev=355891&r1=355890&r2=355891&view=diff
==============================================================================
--- cfe/trunk/lib/Driver/ToolChains/MipsLinux.h (original)
+++ cfe/trunk/lib/Driver/ToolChains/MipsLinux.h Mon Mar 11 19:12:48 2019
@@ -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;
More information about the cfe-commits
mailing list