summaryrefslogtreecommitdiff
path: root/lib/Driver/ToolChain.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'lib/Driver/ToolChain.cpp')
-rw-r--r--lib/Driver/ToolChain.cpp147
1 files changed, 113 insertions, 34 deletions
diff --git a/lib/Driver/ToolChain.cpp b/lib/Driver/ToolChain.cpp
index 88a627eab6de..b1fddb0af55d 100644
--- a/lib/Driver/ToolChain.cpp
+++ b/lib/Driver/ToolChain.cpp
@@ -1,9 +1,8 @@
//===- ToolChain.cpp - Collections of tools for one platform --------------===//
//
-// The LLVM Compiler Infrastructure
-//
-// This file is distributed under the University of Illinois Open Source
-// License. See LICENSE.TXT for details.
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
@@ -74,17 +73,13 @@ ToolChain::ToolChain(const Driver &D, const llvm::Triple &T,
const ArgList &Args)
: D(D), Triple(T), Args(Args), CachedRTTIArg(GetRTTIArgument(Args)),
CachedRTTIMode(CalculateRTTIMode(Args, Triple, CachedRTTIArg)) {
- SmallString<128> P;
-
- P.assign(D.ResourceDir);
- llvm::sys::path::append(P, D.getTargetTriple(), "lib");
- if (getVFS().exists(P))
- getLibraryPaths().push_back(P.str());
+ if (D.CCCIsCXX()) {
+ if (auto CXXStdlibPath = getCXXStdlibPath())
+ getFilePaths().push_back(*CXXStdlibPath);
+ }
- P.assign(D.ResourceDir);
- llvm::sys::path::append(P, Triple.str(), "lib");
- if (getVFS().exists(P))
- getLibraryPaths().push_back(P.str());
+ if (auto RuntimePath = getRuntimePath())
+ getLibraryPaths().push_back(*RuntimePath);
std::string CandidateLibPath = getArchSpecificLibPath();
if (getVFS().exists(CandidateLibPath))
@@ -113,6 +108,10 @@ bool ToolChain::useRelaxRelocations() const {
return ENABLE_X86_RELAX_RELOCATIONS;
}
+bool ToolChain::isNoExecStackDefault() const {
+ return false;
+}
+
const SanitizerArgs& ToolChain::getSanitizerArgs() const {
if (!SanitizerArguments.get())
SanitizerArguments.reset(new SanitizerArgs(*this, Args));
@@ -363,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);
@@ -391,8 +401,45 @@ 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));
+}
+
+
+Optional<std::string> ToolChain::getRuntimePath() const {
+ SmallString<128> P;
+
+ // First try the triple passed to driver as --target=<triple>.
+ P.assign(D.ResourceDir);
+ llvm::sys::path::append(P, "lib", D.getTargetTriple());
+ if (getVFS().exists(P))
+ return llvm::Optional<std::string>(P.str());
+
+ // Second try the normalized triple.
+ P.assign(D.ResourceDir);
+ llvm::sys::path::append(P, "lib", Triple.str());
+ if (getVFS().exists(P))
+ return llvm::Optional<std::string>(P.str());
+
+ return None;
+}
+
+Optional<std::string> ToolChain::getCXXStdlibPath() const {
+ SmallString<128> P;
+
+ // First try the triple passed to driver as --target=<triple>.
+ P.assign(D.Dir);
+ llvm::sys::path::append(P, "..", "lib", D.getTargetTriple(), "c++");
+ if (getVFS().exists(P))
+ return llvm::Optional<std::string>(P.str());
+
+ // Second try the normalized triple.
+ P.assign(D.Dir);
+ llvm::sys::path::append(P, "..", "lib", Triple.str(), "c++");
+ if (getVFS().exists(P))
+ return llvm::Optional<std::string>(P.str());
+
+ return None;
}
std::string ToolChain::getArchSpecificLibPath() const {
@@ -403,12 +450,18 @@ std::string ToolChain::getArchSpecificLibPath() const {
}
bool ToolChain::needsProfileRT(const ArgList &Args) {
+ if (Args.hasArg(options::OPT_noprofilelib))
+ return false;
+
if (needsGCovInstrumentation(Args) ||
Args.hasArg(options::OPT_fprofile_generate) ||
Args.hasArg(options::OPT_fprofile_generate_EQ) ||
+ Args.hasArg(options::OPT_fcs_profile_generate) ||
+ Args.hasArg(options::OPT_fcs_profile_generate_EQ) ||
Args.hasArg(options::OPT_fprofile_instr_generate) ||
Args.hasArg(options::OPT_fprofile_instr_generate_EQ) ||
- Args.hasArg(options::OPT_fcreate_profile))
+ Args.hasArg(options::OPT_fcreate_profile) ||
+ Args.hasArg(options::OPT_forder_file_instrumentation))
return true;
return false;
@@ -680,6 +733,33 @@ ToolChain::RuntimeLibType ToolChain::GetRuntimeLibType(
return GetDefaultRuntimeLibType();
}
+ToolChain::UnwindLibType ToolChain::GetUnwindLibType(
+ const ArgList &Args) const {
+ const Arg *A = Args.getLastArg(options::OPT_unwindlib_EQ);
+ StringRef LibName = A ? A->getValue() : CLANG_DEFAULT_UNWINDLIB;
+
+ if (LibName == "none")
+ return ToolChain::UNW_None;
+ else if (LibName == "platform" || LibName == "") {
+ ToolChain::RuntimeLibType RtLibType = GetRuntimeLibType(Args);
+ if (RtLibType == ToolChain::RLT_CompilerRT)
+ return ToolChain::UNW_None;
+ else if (RtLibType == ToolChain::RLT_Libgcc)
+ return ToolChain::UNW_Libgcc;
+ } else if (LibName == "libunwind") {
+ if (GetRuntimeLibType(Args) == RLT_Libgcc)
+ getDriver().Diag(diag::err_drv_incompatible_unwindlib);
+ return ToolChain::UNW_CompilerRT;
+ } else if (LibName == "libgcc")
+ return ToolChain::UNW_Libgcc;
+
+ if (A)
+ getDriver().Diag(diag::err_drv_invalid_unwindlib_name)
+ << A->getAsString(Args);
+
+ return GetDefaultUnwindLibType();
+}
+
ToolChain::CXXStdlibType ToolChain::GetCXXStdlibType(const ArgList &Args) const{
const Arg *A = Args.getLastArg(options::OPT_stdlib_EQ);
StringRef LibName = A ? A->getValue() : CLANG_DEFAULT_CXX_STDLIB;
@@ -777,10 +857,6 @@ void ToolChain::AddCXXStdlibLibArgs(const ArgList &Args,
void ToolChain::AddFilePathLibArgs(const ArgList &Args,
ArgStringList &CmdArgs) const {
- for (const auto &LibPath : getLibraryPaths())
- if(LibPath.length() > 0)
- CmdArgs.push_back(Args.MakeArgString(StringRef("-L") + LibPath));
-
for (const auto &LibPath : getFilePaths())
if(LibPath.length() > 0)
CmdArgs.push_back(Args.MakeArgString(StringRef("-L") + LibPath));
@@ -819,21 +895,24 @@ SanitizerMask ToolChain::getSupportedSanitizers() const {
// Return sanitizers which don't require runtime support and are not
// platform dependent.
- using namespace SanitizerKind;
-
- SanitizerMask Res = (Undefined & ~Vptr & ~Function) | (CFI & ~CFIICall) |
- CFICastStrict | UnsignedIntegerOverflow |
- ImplicitConversion | Nullability | LocalBounds;
+ SanitizerMask Res = (SanitizerKind::Undefined & ~SanitizerKind::Vptr &
+ ~SanitizerKind::Function) |
+ (SanitizerKind::CFI & ~SanitizerKind::CFIICall) |
+ SanitizerKind::CFICastStrict |
+ SanitizerKind::FloatDivideByZero |
+ SanitizerKind::UnsignedIntegerOverflow |
+ SanitizerKind::ImplicitConversion |
+ SanitizerKind::Nullability | SanitizerKind::LocalBounds;
if (getTriple().getArch() == llvm::Triple::x86 ||
getTriple().getArch() == llvm::Triple::x86_64 ||
getTriple().getArch() == llvm::Triple::arm ||
getTriple().getArch() == llvm::Triple::aarch64 ||
getTriple().getArch() == llvm::Triple::wasm32 ||
getTriple().getArch() == llvm::Triple::wasm64)
- Res |= CFIICall;
+ Res |= SanitizerKind::CFIICall;
if (getTriple().getArch() == llvm::Triple::x86_64 ||
getTriple().getArch() == llvm::Triple::aarch64)
- Res |= ShadowCallStack;
+ Res |= SanitizerKind::ShadowCallStack;
return Res;
}