Skip to content

Commit 5f7c906

Browse files
authored
Merge pull request swiftlang#9850 from swiftlang/mracek/6.1/none-macho-arm64e
[6.1 cp] [Clang][Driver] Add arm64e support for Swift’s "-none-macho" target triples in Clang Driver
2 parents 3f67652 + d4a36b9 commit 5f7c906

File tree

3 files changed

+79
-62
lines changed

3 files changed

+79
-62
lines changed

clang/lib/Driver/ToolChains/Darwin.cpp

Lines changed: 67 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -1285,65 +1285,9 @@ void DarwinClang::addClangWarningOptions(ArgStringList &CC1Args) const {
12851285

12861286
void DarwinClang::addClangTargetOptions(
12871287
const llvm::opt::ArgList &DriverArgs, llvm::opt::ArgStringList &CC1Args,
1288-
Action::OffloadKind DeviceOffloadKind) const{
1288+
Action::OffloadKind DeviceOffloadKind) const {
12891289

12901290
Darwin::addClangTargetOptions(DriverArgs, CC1Args, DeviceOffloadKind);
1291-
1292-
// On arm64e, enable pointer authentication (for the return address and
1293-
// indirect calls), as well as usage of the intrinsics.
1294-
if (getArchName() == "arm64e") {
1295-
// The ptrauth ABI version is 0 by default, but can be overridden.
1296-
static const constexpr unsigned DefaultPtrauthABIVersion = 0;
1297-
1298-
unsigned PtrAuthABIVersion = DefaultPtrauthABIVersion;
1299-
const Arg *A = DriverArgs.getLastArg(options::OPT_fptrauth_abi_version_EQ,
1300-
options::OPT_fno_ptrauth_abi_version);
1301-
bool HasVersionArg =
1302-
A && A->getOption().matches(options::OPT_fptrauth_abi_version_EQ);
1303-
if (HasVersionArg) {
1304-
unsigned PtrAuthABIVersionArg;
1305-
if (StringRef(A->getValue()).getAsInteger(10, PtrAuthABIVersionArg))
1306-
getDriver().Diag(diag::err_drv_invalid_value)
1307-
<< A->getAsString(DriverArgs) << A->getValue();
1308-
else
1309-
PtrAuthABIVersion = PtrAuthABIVersionArg;
1310-
}
1311-
1312-
// Pass the ABI version to -cc1, regardless of its value, if the user asked
1313-
// for it or if the user didn't explicitly disable it.
1314-
if (HasVersionArg ||
1315-
!DriverArgs.hasArg(options::OPT_fno_ptrauth_abi_version)) {
1316-
CC1Args.push_back(DriverArgs.MakeArgString(
1317-
"-fptrauth-abi-version=" + llvm::utostr(PtrAuthABIVersion)));
1318-
1319-
// -f(no-)ptrauth-kernel-abi-version can override -mkernel and
1320-
// -fapple-kext
1321-
if (DriverArgs.hasArg(options::OPT_fptrauth_kernel_abi_version,
1322-
options::OPT_mkernel, options::OPT_fapple_kext) &&
1323-
!DriverArgs.hasArg(options::OPT_fno_ptrauth_kernel_abi_version))
1324-
CC1Args.push_back("-fptrauth-kernel-abi-version");
1325-
}
1326-
1327-
if (!DriverArgs.hasArg(options::OPT_fptrauth_returns,
1328-
options::OPT_fno_ptrauth_returns))
1329-
CC1Args.push_back("-fptrauth-returns");
1330-
1331-
if (!DriverArgs.hasArg(options::OPT_fptrauth_intrinsics,
1332-
options::OPT_fno_ptrauth_intrinsics))
1333-
CC1Args.push_back("-fptrauth-intrinsics");
1334-
1335-
if (!DriverArgs.hasArg(options::OPT_fptrauth_calls,
1336-
options::OPT_fno_ptrauth_calls))
1337-
CC1Args.push_back("-fptrauth-calls");
1338-
1339-
if (!DriverArgs.hasArg(options::OPT_fptrauth_indirect_gotos,
1340-
options::OPT_fno_ptrauth_indirect_gotos))
1341-
CC1Args.push_back("-fptrauth-indirect-gotos");
1342-
1343-
if (!DriverArgs.hasArg(options::OPT_fptrauth_auth_traps,
1344-
options::OPT_fno_ptrauth_auth_traps))
1345-
CC1Args.push_back("-fptrauth-auth-traps");
1346-
}
13471291
}
13481292

13491293
/// Take a path that speculatively points into Xcode and return the
@@ -3203,9 +3147,75 @@ bool Darwin::isSizedDeallocationUnavailable() const {
32033147
return TargetVersion < sizedDeallocMinVersion(OS);
32043148
}
32053149

3150+
void MachO::addClangTargetOptions(
3151+
const llvm::opt::ArgList &DriverArgs, llvm::opt::ArgStringList &CC1Args,
3152+
Action::OffloadKind DeviceOffloadKind) const {
3153+
3154+
ToolChain::addClangTargetOptions(DriverArgs, CC1Args, DeviceOffloadKind);
3155+
3156+
// On arm64e, enable pointer authentication (for the return address and
3157+
// indirect calls), as well as usage of the intrinsics.
3158+
if (getArchName() == "arm64e") {
3159+
// The ptrauth ABI version is 0 by default, but can be overridden.
3160+
static const constexpr unsigned DefaultPtrauthABIVersion = 0;
3161+
3162+
unsigned PtrAuthABIVersion = DefaultPtrauthABIVersion;
3163+
const Arg *A = DriverArgs.getLastArg(options::OPT_fptrauth_abi_version_EQ,
3164+
options::OPT_fno_ptrauth_abi_version);
3165+
bool HasVersionArg =
3166+
A && A->getOption().matches(options::OPT_fptrauth_abi_version_EQ);
3167+
if (HasVersionArg) {
3168+
unsigned PtrAuthABIVersionArg;
3169+
if (StringRef(A->getValue()).getAsInteger(10, PtrAuthABIVersionArg))
3170+
getDriver().Diag(diag::err_drv_invalid_value)
3171+
<< A->getAsString(DriverArgs) << A->getValue();
3172+
else
3173+
PtrAuthABIVersion = PtrAuthABIVersionArg;
3174+
}
3175+
3176+
// Pass the ABI version to -cc1, regardless of its value, if the user asked
3177+
// for it or if the user didn't explicitly disable it.
3178+
if (HasVersionArg ||
3179+
!DriverArgs.hasArg(options::OPT_fno_ptrauth_abi_version)) {
3180+
CC1Args.push_back(DriverArgs.MakeArgString(
3181+
"-fptrauth-abi-version=" + llvm::utostr(PtrAuthABIVersion)));
3182+
3183+
// -f(no-)ptrauth-kernel-abi-version can override -mkernel and
3184+
// -fapple-kext
3185+
if (DriverArgs.hasArg(options::OPT_fptrauth_kernel_abi_version,
3186+
options::OPT_mkernel, options::OPT_fapple_kext) &&
3187+
!DriverArgs.hasArg(options::OPT_fno_ptrauth_kernel_abi_version))
3188+
CC1Args.push_back("-fptrauth-kernel-abi-version");
3189+
}
3190+
3191+
if (!DriverArgs.hasArg(options::OPT_fptrauth_returns,
3192+
options::OPT_fno_ptrauth_returns))
3193+
CC1Args.push_back("-fptrauth-returns");
3194+
3195+
if (!DriverArgs.hasArg(options::OPT_fptrauth_intrinsics,
3196+
options::OPT_fno_ptrauth_intrinsics))
3197+
CC1Args.push_back("-fptrauth-intrinsics");
3198+
3199+
if (!DriverArgs.hasArg(options::OPT_fptrauth_calls,
3200+
options::OPT_fno_ptrauth_calls))
3201+
CC1Args.push_back("-fptrauth-calls");
3202+
3203+
if (!DriverArgs.hasArg(options::OPT_fptrauth_indirect_gotos,
3204+
options::OPT_fno_ptrauth_indirect_gotos))
3205+
CC1Args.push_back("-fptrauth-indirect-gotos");
3206+
3207+
if (!DriverArgs.hasArg(options::OPT_fptrauth_auth_traps,
3208+
options::OPT_fno_ptrauth_auth_traps))
3209+
CC1Args.push_back("-fptrauth-auth-traps");
3210+
}
3211+
}
3212+
32063213
void Darwin::addClangTargetOptions(
32073214
const llvm::opt::ArgList &DriverArgs, llvm::opt::ArgStringList &CC1Args,
32083215
Action::OffloadKind DeviceOffloadKind) const {
3216+
3217+
MachO::addClangTargetOptions(DriverArgs, CC1Args, DeviceOffloadKind);
3218+
32093219
// Pass "-faligned-alloc-unavailable" only when the user hasn't manually
32103220
// enabled or disabled aligned allocations.
32113221
if (!DriverArgs.hasArgNoClaim(options::OPT_faligned_allocation,

clang/lib/Driver/ToolChains/Darwin.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,10 @@ class LLVM_LIBRARY_VISIBILITY MachO : public ToolChain {
144144
Tool *buildStaticLibTool() const override;
145145
Tool *getTool(Action::ActionClass AC) const override;
146146

147+
void addClangTargetOptions(const llvm::opt::ArgList &DriverArgs,
148+
llvm::opt::ArgStringList &CC1Args,
149+
Action::OffloadKind DeviceOffloadKind) const override;
150+
147151
private:
148152
mutable std::unique_ptr<tools::darwin::Lipo> Lipo;
149153
mutable std::unique_ptr<tools::darwin::Dsymutil> Dsymutil;

clang/test/Driver/arch-arm64e.c

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,30 +33,33 @@
3333
// RUN: %clang -target arm64e-apple-ios -c %s -### 2>&1 | FileCheck %s --check-prefix DEFAULT
3434
// RUN: %clang -mkernel -target arm64e-apple-ios -c %s -### 2>&1 | FileCheck %s --check-prefix DEFAULT
3535
// RUN: %clang -fapple-kext -target arm64e-apple-ios -c %s -### 2>&1 | FileCheck %s --check-prefix DEFAULT
36-
// DEFAULT: "-fptrauth-returns" "-fptrauth-intrinsics" "-fptrauth-calls" "-fptrauth-indirect-gotos" "-fptrauth-auth-traps" "-target-cpu" "apple-a12"{{.*}}
36+
// DEFAULT: "-fptrauth-returns" "-fptrauth-intrinsics" "-fptrauth-calls" "-fptrauth-indirect-gotos" "-fptrauth-auth-traps" {{.*}}"-target-cpu" "apple-a12"{{.*}}
37+
38+
// RUN: %clang -target arm64e-apple-none-macho -c %s -### 2>&1 | FileCheck %s --check-prefix DEFAULT-MACHO
39+
// DEFAULT-MACHO: "-fptrauth-returns" "-fptrauth-intrinsics" "-fptrauth-calls" "-fptrauth-indirect-gotos" "-fptrauth-auth-traps" {{.*}}"-target-cpu" "apple-a12"{{.*}}
3740

3841

3942
// RUN: %clang -target arm64e-apple-ios -fno-ptrauth-calls -c %s -### 2>&1 | FileCheck %s --check-prefix DEFAULT-NOCALL
4043
// RUN: %clang -mkernel -target arm64e-apple-ios -fno-ptrauth-calls -c %s -### 2>&1 | FileCheck %s --check-prefix DEFAULT-NOCALL
4144
// RUN: %clang -fapple-kext -target arm64e-apple-ios -fno-ptrauth-calls -c %s -### 2>&1 | FileCheck %s --check-prefix DEFAULT-NOCALL
4245
// DEFAULT-NOCALL-NOT: "-fptrauth-calls"
43-
// DEFAULT-NOCALL: "-fptrauth-returns" "-fptrauth-intrinsics" "-fptrauth-indirect-gotos" "-fptrauth-auth-traps" "-target-cpu" "apple-a12"
46+
// DEFAULT-NOCALL: "-fptrauth-returns" "-fptrauth-intrinsics" "-fptrauth-indirect-gotos" "-fptrauth-auth-traps" {{.*}}"-target-cpu" "apple-a12"
4447

4548

4649
// RUN: %clang -target arm64e-apple-ios -fno-ptrauth-returns -c %s -### 2>&1 | FileCheck %s --check-prefix NORET
4750

4851
// NORET-NOT: "-fptrauth-returns"
49-
// NORET: "-fptrauth-intrinsics" "-fptrauth-calls" "-fptrauth-indirect-gotos" "-fptrauth-auth-traps" "-target-cpu" "apple-a12"
52+
// NORET: "-fptrauth-intrinsics" "-fptrauth-calls" "-fptrauth-indirect-gotos" "-fptrauth-auth-traps" {{.*}}"-target-cpu" "apple-a12"
5053

5154
// RUN: %clang -target arm64e-apple-ios -fno-ptrauth-intrinsics -c %s -### 2>&1 | FileCheck %s --check-prefix NOINTRIN
5255

5356
// NOINTRIN: "-fptrauth-returns"
5457
// NOINTRIN-NOT: "-fptrauth-intrinsics"
55-
// NOINTRIN: "-fptrauth-calls" "-fptrauth-indirect-gotos" "-fptrauth-auth-traps" "-target-cpu" "apple-a12"{{.*}}
58+
// NOINTRIN: "-fptrauth-calls" "-fptrauth-indirect-gotos" "-fptrauth-auth-traps" {{.*}}"-target-cpu" "apple-a12"{{.*}}
5659

5760

5861
// RUN: %clang -target arm64e-apple-ios -fno-ptrauth-auth-traps -c %s -### 2>&1 | FileCheck %s --check-prefix NOTRAP
59-
// NOTRAP: "-fptrauth-returns" "-fptrauth-intrinsics" "-fptrauth-calls" "-fptrauth-indirect-gotos" "-target-cpu" "apple-a12"
62+
// NOTRAP: "-fptrauth-returns" "-fptrauth-intrinsics" "-fptrauth-calls" "-fptrauth-indirect-gotos" {{.*}}"-target-cpu" "apple-a12"
6063

6164

6265
// Check the CPU defaults and overrides.

0 commit comments

Comments
 (0)