r249030 - Allow a ToolChain to compute the path of a compiler-rt's component.
Vasileios Kalintiris via cfe-commits
cfe-commits at lists.llvm.org
Thu Oct 1 09:54:58 PDT 2015
Author: vkalintiris
Date: Thu Oct 1 11:54:58 2015
New Revision: 249030
URL: http://llvm.org/viewvc/llvm-project?rev=249030&view=rev
Log:
Allow a ToolChain to compute the path of a compiler-rt's component.
Summary:
This patch moves getCompilerRT() from the clang::driver::tools namespace to
the ToolChain class. This is needed for multilib toolchains that need to
place their libraries in Clang's resource directory with a layout that is
different from the default one.
Reviewers: atanasyan, rsmith
Subscribers: tberghammer, danalbert, srhines, cfe-commits
Differential Revision: http://reviews.llvm.org/D13339
Modified:
cfe/trunk/include/clang/Driver/ToolChain.h
cfe/trunk/lib/Driver/SanitizerArgs.cpp
cfe/trunk/lib/Driver/ToolChain.cpp
cfe/trunk/lib/Driver/Tools.cpp
Modified: cfe/trunk/include/clang/Driver/ToolChain.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Driver/ToolChain.h?rev=249030&r1=249029&r2=249030&view=diff
==============================================================================
--- cfe/trunk/include/clang/Driver/ToolChain.h (original)
+++ cfe/trunk/include/clang/Driver/ToolChain.h Thu Oct 1 11:54:58 2015
@@ -250,6 +250,10 @@ public:
return ToolChain::RLT_Libgcc;
}
+ virtual std::string getCompilerRT(const llvm::opt::ArgList &Args,
+ StringRef Component,
+ bool Shared = false) const;
+
/// IsUnwindTablesDefault - Does this tool chain use -funwind-tables
/// by default.
virtual bool IsUnwindTablesDefault() const;
Modified: cfe/trunk/lib/Driver/SanitizerArgs.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/SanitizerArgs.cpp?rev=249030&r1=249029&r2=249030&view=diff
==============================================================================
--- cfe/trunk/lib/Driver/SanitizerArgs.cpp (original)
+++ cfe/trunk/lib/Driver/SanitizerArgs.cpp Thu Oct 1 11:54:58 2015
@@ -609,13 +609,11 @@ void SanitizerArgs::addArgs(const ToolCh
if (TC.getTriple().isOSWindows() && needsUbsanRt()) {
// Instruct the code generator to embed linker directives in the object file
// that cause the required runtime libraries to be linked.
- CmdArgs.push_back(
- Args.MakeArgString("--dependent-lib=" +
- tools::getCompilerRT(TC, Args, "ubsan_standalone")));
+ CmdArgs.push_back(Args.MakeArgString(
+ "--dependent-lib=" + TC.getCompilerRT(Args, "ubsan_standalone")));
if (types::isCXX(InputType))
CmdArgs.push_back(Args.MakeArgString(
- "--dependent-lib=" +
- tools::getCompilerRT(TC, Args, "ubsan_standalone_cxx")));
+ "--dependent-lib=" + TC.getCompilerRT(Args, "ubsan_standalone_cxx")));
}
}
Modified: cfe/trunk/lib/Driver/ToolChain.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/ToolChain.cpp?rev=249030&r1=249029&r2=249030&view=diff
==============================================================================
--- cfe/trunk/lib/Driver/ToolChain.cpp (original)
+++ cfe/trunk/lib/Driver/ToolChain.cpp Thu Oct 1 11:54:58 2015
@@ -23,7 +23,9 @@
#include "llvm/Support/ErrorHandling.h"
#include "llvm/Support/FileSystem.h"
#include "llvm/Support/TargetRegistry.h"
+
using namespace clang::driver;
+using namespace clang::driver::tools;
using namespace clang;
using namespace llvm::opt;
@@ -265,6 +267,43 @@ Tool *ToolChain::getTool(Action::ActionC
llvm_unreachable("Invalid tool kind.");
}
+static StringRef getArchNameForCompilerRTLib(const ToolChain &TC,
+ const ArgList &Args) {
+ const llvm::Triple &Triple = TC.getTriple();
+ bool IsWindows = Triple.isOSWindows();
+
+ if (Triple.isWindowsMSVCEnvironment() && TC.getArch() == llvm::Triple::x86)
+ return "i386";
+
+ if (TC.getArch() == llvm::Triple::arm || TC.getArch() == llvm::Triple::armeb)
+ return (arm::getARMFloatABI(TC, Args) == arm::FloatABI::Hard && !IsWindows)
+ ? "armhf"
+ : "arm";
+
+ return TC.getArchName();
+}
+
+std::string ToolChain::getCompilerRT(const ArgList &Args, StringRef Component,
+ bool Shared) const {
+ const llvm::Triple &TT = getTriple();
+ const char *Env =
+ (TT.getEnvironment() == llvm::Triple::Android) ? "-android" : "";
+ bool IsITANMSVCWindows =
+ TT.isWindowsMSVCEnvironment() || TT.isWindowsItaniumEnvironment();
+
+ StringRef Arch = getArchNameForCompilerRTLib(*this, Args);
+ const char *Prefix = IsITANMSVCWindows ? "" : "lib";
+ const char *Suffix = Shared ? (Triple.isOSWindows() ? ".dll" : ".so")
+ : (IsITANMSVCWindows ? ".lib" : ".a");
+
+ SmallString<128> Path(getDriver().ResourceDir);
+ StringRef OSLibName = Triple.isOSFreeBSD() ? "freebsd" : getOS();
+ llvm::sys::path::append(Path, "lib", OSLibName);
+ llvm::sys::path::append(Path, Prefix + Twine("clang_rt.") + Component + "-" +
+ Arch + Env + Suffix);
+ return Path.str();
+}
+
Tool *ToolChain::SelectTool(const JobAction &JA) const {
if (getDriver().ShouldUseClangCompiler(JA))
return getClang();
@@ -306,7 +345,6 @@ std::string ToolChain::GetLinkerPath() c
return GetProgramPath("ld");
}
-
types::ID ToolChain::LookupTypeForExtension(const char *Ext) const {
return types::lookupTypeForExtension(Ext);
}
Modified: cfe/trunk/lib/Driver/Tools.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/Tools.cpp?rev=249030&r1=249029&r2=249030&view=diff
==============================================================================
--- cfe/trunk/lib/Driver/Tools.cpp (original)
+++ cfe/trunk/lib/Driver/Tools.cpp Thu Oct 1 11:54:58 2015
@@ -2402,60 +2402,11 @@ static void CollectArgsForIntegratedAsse
}
}
-// Until ARM libraries are build separately, we have them all in one library
-static StringRef getArchNameForCompilerRTLib(const ToolChain &TC,
- const ArgList &Args) {
- const llvm::Triple &Triple = TC.getTriple();
- bool IsWindows = Triple.isOSWindows();
-
- if (Triple.isWindowsMSVCEnvironment() && TC.getArch() == llvm::Triple::x86)
- return "i386";
-
- if (TC.getArch() == llvm::Triple::arm || TC.getArch() == llvm::Triple::armeb)
- return (arm::getARMFloatABI(TC, Args) == arm::FloatABI::Hard && !IsWindows)
- ? "armhf"
- : "arm";
-
- return TC.getArchName();
-}
-
-static SmallString<128> getCompilerRTLibDir(const ToolChain &TC) {
- // The runtimes are located in the OS-specific resource directory.
- SmallString<128> Res(TC.getDriver().ResourceDir);
- const llvm::Triple &Triple = TC.getTriple();
- // TC.getOS() yield "freebsd10.0" whereas "freebsd" is expected.
- StringRef OSLibName =
- (Triple.getOS() == llvm::Triple::FreeBSD) ? "freebsd" : TC.getOS();
- llvm::sys::path::append(Res, "lib", OSLibName);
- return Res;
-}
-
-SmallString<128> tools::getCompilerRT(const ToolChain &TC, const ArgList &Args,
- StringRef Component, bool Shared) {
- const char *Env = TC.getTriple().getEnvironment() == llvm::Triple::Android
- ? "-android"
- : "";
-
- bool IsOSWindows = TC.getTriple().isOSWindows();
- bool IsITANMSVCWindows = TC.getTriple().isWindowsMSVCEnvironment() ||
- TC.getTriple().isWindowsItaniumEnvironment();
- StringRef Arch = getArchNameForCompilerRTLib(TC, Args);
- const char *Prefix = IsITANMSVCWindows ? "" : "lib";
- const char *Suffix =
- Shared ? (IsOSWindows ? ".dll" : ".so") : (IsITANMSVCWindows ? ".lib" : ".a");
-
- SmallString<128> Path = getCompilerRTLibDir(TC);
- llvm::sys::path::append(Path, Prefix + Twine("clang_rt.") + Component + "-" +
- Arch + Env + Suffix);
-
- return Path;
-}
-
static const char *getCompilerRTArgString(const ToolChain &TC,
const llvm::opt::ArgList &Args,
StringRef Component,
bool Shared = false) {
- return Args.MakeArgString(getCompilerRT(TC, Args, Component, Shared));
+ return Args.MakeArgString(TC.getCompilerRT(Args, Component, Shared));
}
// This adds the static libclang_rt.builtins-arch.a directly to the command line
@@ -2569,7 +2520,7 @@ static void addSanitizerRuntime(const To
static bool addSanitizerDynamicList(const ToolChain &TC, const ArgList &Args,
ArgStringList &CmdArgs,
StringRef Sanitizer) {
- SmallString<128> SanRT = getCompilerRT(TC, Args, Sanitizer);
+ SmallString<128> SanRT(TC.getCompilerRT(Args, Sanitizer));
if (llvm::sys::fs::exists(SanRT + ".syms")) {
CmdArgs.push_back(Args.MakeArgString("--dynamic-list=" + SanRT + ".syms"));
return true;
More information about the cfe-commits
mailing list