aboutsummaryrefslogtreecommitdiff
path: root/contrib/llvm-project/clang/lib/Driver/ToolChains/Darwin.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'contrib/llvm-project/clang/lib/Driver/ToolChains/Darwin.cpp')
-rw-r--r--contrib/llvm-project/clang/lib/Driver/ToolChains/Darwin.cpp132
1 files changed, 88 insertions, 44 deletions
diff --git a/contrib/llvm-project/clang/lib/Driver/ToolChains/Darwin.cpp b/contrib/llvm-project/clang/lib/Driver/ToolChains/Darwin.cpp
index 7b879f8cb652..eb7bd4aec898 100644
--- a/contrib/llvm-project/clang/lib/Driver/ToolChains/Darwin.cpp
+++ b/contrib/llvm-project/clang/lib/Driver/ToolChains/Darwin.cpp
@@ -7,6 +7,7 @@
//===----------------------------------------------------------------------===//
#include "Darwin.h"
+#include "Arch/AArch64.h"
#include "Arch/ARM.h"
#include "CommonArgs.h"
#include "clang/Basic/AlignedAllocation.h"
@@ -58,7 +59,7 @@ llvm::Triple::ArchType darwin::getArchTypeForMachOArchName(StringRef Str) {
.Cases("arm", "armv4t", "armv5", "armv6", "armv6m", llvm::Triple::arm)
.Cases("armv7", "armv7em", "armv7k", "armv7m", llvm::Triple::arm)
.Cases("armv7s", "xscale", llvm::Triple::arm)
- .Case("arm64", llvm::Triple::aarch64)
+ .Cases("arm64", "arm64e", llvm::Triple::aarch64)
.Case("arm64_32", llvm::Triple::aarch64_32)
.Case("r600", llvm::Triple::r600)
.Case("amdgcn", llvm::Triple::amdgcn)
@@ -74,7 +75,7 @@ void darwin::setTripleTypeForMachOArchName(llvm::Triple &T, StringRef Str) {
llvm::ARM::ArchKind ArchKind = llvm::ARM::parseArch(Str);
T.setArch(Arch);
- if (Str == "x86_64h")
+ if (Str == "x86_64h" || Str == "arm64e")
T.setArchName(Str);
else if (ArchKind == llvm::ARM::ArchKind::ARMV6M ||
ArchKind == llvm::ARM::ArchKind::ARMV7M ||
@@ -149,7 +150,7 @@ void darwin::Assembler::ConstructJob(Compilation &C, const JobAction &JA,
const char *Exec = Args.MakeArgString(getToolChain().GetProgramPath("as"));
C.addCommand(std::make_unique<Command>(JA, *this, ResponseFileSupport::None(),
- Exec, CmdArgs, Inputs));
+ Exec, CmdArgs, Inputs, Output));
}
void darwin::MachOTool::anchor() {}
@@ -204,15 +205,19 @@ static bool shouldLinkerNotDedup(bool IsLinkerOnlyAction, const ArgList &Args) {
void darwin::Linker::AddLinkArgs(Compilation &C, const ArgList &Args,
ArgStringList &CmdArgs,
const InputInfoList &Inputs,
- unsigned Version[5]) const {
+ unsigned Version[5], bool LinkerIsLLD,
+ bool LinkerIsLLDDarwinNew) const {
const Driver &D = getToolChain().getDriver();
const toolchains::MachO &MachOTC = getMachOToolChain();
// Newer linkers support -demangle. Pass it if supported and not disabled by
// the user.
- if (Version[0] >= 100 && !Args.hasArg(options::OPT_Z_Xlinker__no_demangle))
+ if ((Version[0] >= 100 || LinkerIsLLD) &&
+ !Args.hasArg(options::OPT_Z_Xlinker__no_demangle))
CmdArgs.push_back("-demangle");
+ // FIXME: Pass most of the flags below that check Version if LinkerIsLLD too.
+
if (Args.hasArg(options::OPT_rdynamic) && Version[0] >= 137)
CmdArgs.push_back("-export_dynamic");
@@ -249,7 +254,9 @@ void darwin::Linker::AddLinkArgs(Compilation &C, const ArgList &Args,
// Since this is passed unconditionally, ld64 will never look for libLTO.dylib
// next to it. That's ok since ld64 using a libLTO.dylib not matching the
// clang version won't work anyways.
- if (Version[0] >= 133) {
+ // lld is built at the same revision as clang and statically links in
+ // LLVM libraries, so it doesn't need libLTO.dylib.
+ if (Version[0] >= 133 && !LinkerIsLLD) {
// Search for libLTO in <InstalledDir>/../lib/libLTO.dylib
StringRef P = llvm::sys::path::parent_path(D.Dir);
SmallString<128> LibLTOPath(P);
@@ -332,7 +339,7 @@ void darwin::Linker::AddLinkArgs(Compilation &C, const ArgList &Args,
Args.AddAllArgs(CmdArgs, options::OPT_init);
// Add the deployment target.
- if (Version[0] >= 520)
+ if (Version[0] >= 520 || LinkerIsLLDDarwinNew)
MachOTC.addPlatformVersionArgs(Args, CmdArgs);
else
MachOTC.addMinVersionArgs(Args, CmdArgs);
@@ -522,7 +529,7 @@ void darwin::Linker::ConstructJob(Compilation &C, const JobAction &JA,
Args.MakeArgString(getToolChain().GetProgramPath("touch"));
CmdArgs.push_back(Output.getFilename());
C.addCommand(std::make_unique<Command>(
- JA, *this, ResponseFileSupport::None(), Exec, CmdArgs, None));
+ JA, *this, ResponseFileSupport::None(), Exec, CmdArgs, None, Output));
return;
}
@@ -533,9 +540,14 @@ void darwin::Linker::ConstructJob(Compilation &C, const JobAction &JA,
<< A->getAsString(Args);
}
+ bool LinkerIsLLD, LinkerIsLLDDarwinNew;
+ const char *Exec = Args.MakeArgString(
+ getToolChain().GetLinkerPath(&LinkerIsLLD, &LinkerIsLLDDarwinNew));
+
// I'm not sure why this particular decomposition exists in gcc, but
// we follow suite for ease of comparison.
- AddLinkArgs(C, Args, CmdArgs, Inputs, Version);
+ AddLinkArgs(C, Args, CmdArgs, Inputs, Version, LinkerIsLLD,
+ LinkerIsLLDDarwinNew);
if (willEmitRemarks(Args) &&
checkRemarksOptions(getToolChain().getDriver(), Args,
@@ -686,16 +698,20 @@ void darwin::Linker::ConstructJob(Compilation &C, const JobAction &JA,
}
}
- ResponseFileSupport ResponseSupport = ResponseFileSupport::AtFileUTF8();
- if (Version[0] < 607) {
+ ResponseFileSupport ResponseSupport;
+ if (LinkerIsLLDDarwinNew) {
+ // Xcode12's ld64 added support for @response files, but it's crashy:
+ // https://openradar.appspot.com/radar?id=4933317065441280
+ // FIXME: Pass this for ld64 once it no longer crashes.
+ ResponseSupport = ResponseFileSupport::AtFileUTF8();
+ } else {
// For older versions of the linker, use the legacy filelist method instead.
ResponseSupport = {ResponseFileSupport::RF_FileList, llvm::sys::WEM_UTF8,
"-filelist"};
}
- const char *Exec = Args.MakeArgString(getToolChain().GetLinkerPath());
std::unique_ptr<Command> Cmd = std::make_unique<Command>(
- JA, *this, ResponseSupport, Exec, CmdArgs, Inputs);
+ JA, *this, ResponseSupport, Exec, CmdArgs, Inputs, Output);
Cmd->setInputFileList(std::move(InputFileList));
C.addCommand(std::move(Cmd));
}
@@ -720,7 +736,7 @@ void darwin::Lipo::ConstructJob(Compilation &C, const JobAction &JA,
const char *Exec = Args.MakeArgString(getToolChain().GetProgramPath("lipo"));
C.addCommand(std::make_unique<Command>(JA, *this, ResponseFileSupport::None(),
- Exec, CmdArgs, Inputs));
+ Exec, CmdArgs, Inputs, Output));
}
void darwin::Dsymutil::ConstructJob(Compilation &C, const JobAction &JA,
@@ -741,7 +757,7 @@ void darwin::Dsymutil::ConstructJob(Compilation &C, const JobAction &JA,
const char *Exec =
Args.MakeArgString(getToolChain().GetProgramPath("dsymutil"));
C.addCommand(std::make_unique<Command>(JA, *this, ResponseFileSupport::None(),
- Exec, CmdArgs, Inputs));
+ Exec, CmdArgs, Inputs, Output));
}
void darwin::VerifyDebug::ConstructJob(Compilation &C, const JobAction &JA,
@@ -765,7 +781,7 @@ void darwin::VerifyDebug::ConstructJob(Compilation &C, const JobAction &JA,
const char *Exec =
Args.MakeArgString(getToolChain().GetProgramPath("dwarfdump"));
C.addCommand(std::make_unique<Command>(JA, *this, ResponseFileSupport::None(),
- Exec, CmdArgs, Inputs));
+ Exec, CmdArgs, Inputs, Output));
}
MachO::MachO(const Driver &D, const llvm::Triple &Triple, const ArgList &Args)
@@ -884,8 +900,11 @@ StringRef MachO::getMachOArchName(const ArgList &Args) const {
case llvm::Triple::aarch64_32:
return "arm64_32";
- case llvm::Triple::aarch64:
+ case llvm::Triple::aarch64: {
+ if (getTriple().isArm64e())
+ return "arm64e";
return "arm64";
+ }
case llvm::Triple::thumb:
case llvm::Triple::arm:
@@ -996,6 +1015,9 @@ void DarwinClang::AddLinkARCArgs(const ArgList &Args,
return;
if (isTargetAppleSiliconMac())
return;
+ // ARC runtime is supported everywhere on arm64e.
+ if (getTriple().isArm64e())
+ return;
ObjCRuntime runtime = getDefaultObjCRuntime(/*nonfragile*/ true);
@@ -1062,10 +1084,9 @@ void MachO::AddLinkRuntimeLib(const ArgList &Args, ArgStringList &CmdArgs,
DarwinLibName += Component;
if (!(Opts & RLO_IsEmbedded))
DarwinLibName += "_";
- DarwinLibName += getOSLibraryNameSuffix();
- } else
- DarwinLibName += getOSLibraryNameSuffix(true);
+ }
+ DarwinLibName += getOSLibraryNameSuffix();
DarwinLibName += IsShared ? "_dynamic.dylib" : ".a";
SmallString<128> Dir(getDriver().ResourceDir);
llvm::sys::path::append(
@@ -1196,8 +1217,8 @@ void Darwin::addProfileRTLibs(const ArgList &Args,
// runtime's functionality.
if (hasExportSymbolDirective(Args)) {
if (ForGCOV) {
- addExportedSymbol(CmdArgs, "___gcov_flush");
- addExportedSymbol(CmdArgs, "_flush_fn_list");
+ addExportedSymbol(CmdArgs, "___gcov_dump");
+ addExportedSymbol(CmdArgs, "___gcov_reset");
addExportedSymbol(CmdArgs, "_writeout_fn_list");
addExportedSymbol(CmdArgs, "_reset_fn_list");
} else {
@@ -1697,7 +1718,7 @@ inferDeploymentTargetFromArch(DerivedArgList &Args, const Darwin &Toolchain,
llvm::Triple::OSType OSTy = llvm::Triple::UnknownOS;
StringRef MachOArchName = Toolchain.getMachOArchName(Args);
- if (MachOArchName == "arm64") {
+ if (MachOArchName == "arm64" || MachOArchName == "arm64e") {
#if __arm64__
// A clang running on an Apple Silicon mac defaults
// to building for mac when building for arm64 rather than
@@ -2021,21 +2042,42 @@ void DarwinClang::AddClangCXXStdlibIncludeArgs(
switch (GetCXXStdlibType(DriverArgs)) {
case ToolChain::CST_Libcxx: {
- // On Darwin, libc++ is installed alongside the compiler in
- // include/c++/v1, so get from '<install>/bin' to '<install>/include/c++/v1'.
- {
- llvm::SmallString<128> P = llvm::StringRef(getDriver().getInstalledDir());
- // Note that P can be relative, so we have to '..' and not parent_path.
- llvm::sys::path::append(P, "..", "include", "c++", "v1");
- addSystemInclude(DriverArgs, CC1Args, P);
+ // On Darwin, libc++ can be installed in one of the following two places:
+ // 1. Alongside the compiler in <install>/include/c++/v1
+ // 2. In a SDK (or a custom sysroot) in <sysroot>/usr/include/c++/v1
+ //
+ // The precendence of paths is as listed above, i.e. we take the first path
+ // that exists. Also note that we never include libc++ twice -- we take the
+ // first path that exists and don't send the other paths to CC1 (otherwise
+ // include_next could break).
+
+ // Check for (1)
+ // Get from '<install>/bin' to '<install>/include/c++/v1'.
+ // Note that InstallBin can be relative, so we use '..' instead of
+ // parent_path.
+ llvm::SmallString<128> InstallBin =
+ llvm::StringRef(getDriver().getInstalledDir()); // <install>/bin
+ llvm::sys::path::append(InstallBin, "..", "include", "c++", "v1");
+ if (getVFS().exists(InstallBin)) {
+ addSystemInclude(DriverArgs, CC1Args, InstallBin);
+ return;
+ } else if (DriverArgs.hasArg(options::OPT_v)) {
+ llvm::errs() << "ignoring nonexistent directory \"" << InstallBin
+ << "\"\n";
}
- // Also add <sysroot>/usr/include/c++/v1 unless -nostdinc is used,
- // to match the legacy behavior in CC1.
- if (!DriverArgs.hasArg(options::OPT_nostdinc)) {
- llvm::SmallString<128> P = Sysroot;
- llvm::sys::path::append(P, "usr", "include", "c++", "v1");
- addSystemInclude(DriverArgs, CC1Args, P);
+
+ // Otherwise, check for (2)
+ llvm::SmallString<128> SysrootUsr = Sysroot;
+ llvm::sys::path::append(SysrootUsr, "usr", "include", "c++", "v1");
+ if (getVFS().exists(SysrootUsr)) {
+ addSystemInclude(DriverArgs, CC1Args, SysrootUsr);
+ return;
+ } else if (DriverArgs.hasArg(options::OPT_v)) {
+ llvm::errs() << "ignoring nonexistent directory \"" << SysrootUsr
+ << "\"\n";
}
+
+ // Otherwise, don't add any path.
break;
}
@@ -2271,11 +2313,6 @@ DerivedArgList *MachO::TranslateArgs(const DerivedArgList &Args,
}
}
- if (getTriple().isX86())
- if (!Args.hasArgNoClaim(options::OPT_mtune_EQ))
- DAL->AddJoinedArg(nullptr, Opts.getOption(options::OPT_mtune_EQ),
- "core2");
-
// Add the arch options based on the particular spelling of -arch, to match
// how the driver driver works.
if (!BoundArch.empty()) {
@@ -2413,6 +2450,13 @@ void Darwin::addClangTargetOptions(const llvm::opt::ArgList &DriverArgs,
// Enable compatibility mode for NSItemProviderCompletionHandler in
// Foundation/NSItemProvider.h.
CC1Args.push_back("-fcompatibility-qualified-id-block-type-checking");
+
+ // Give static local variables in inline functions hidden visibility when
+ // -fvisibility-inlines-hidden is enabled.
+ if (!DriverArgs.getLastArgNoClaim(
+ options::OPT_fvisibility_inlines_hidden_static_local_var,
+ options::OPT_fno_visibility_inlines_hidden_static_local_var))
+ CC1Args.push_back("-fvisibility-inlines-hidden-static-local-var");
}
DerivedArgList *
@@ -2713,6 +2757,7 @@ void Darwin::CheckObjCARC() const {
SanitizerMask Darwin::getSupportedSanitizers() const {
const bool IsX86_64 = getTriple().getArch() == llvm::Triple::x86_64;
+ const bool IsAArch64 = getTriple().getArch() == llvm::Triple::aarch64;
SanitizerMask Res = ToolChain::getSupportedSanitizers();
Res |= SanitizerKind::Address;
Res |= SanitizerKind::PointerCompare;
@@ -2730,9 +2775,8 @@ SanitizerMask Darwin::getSupportedSanitizers() const {
&& !(isTargetIPhoneOS() && isIPhoneOSVersionLT(5, 0)))
Res |= SanitizerKind::Vptr;
- if (isTargetMacOS()) {
- if (IsX86_64)
- Res |= SanitizerKind::Thread;
+ if ((IsX86_64 || IsAArch64) && isTargetMacOS()) {
+ Res |= SanitizerKind::Thread;
} else if (isTargetIOSSimulator() || isTargetTvOSSimulator()) {
if (IsX86_64)
Res |= SanitizerKind::Thread;