Skip to content

Commit 4935f07

Browse files
committed
[clang][PAC] Disallow -pedantic-errors in conjunction with pointer authentication
The __has_extension query for the __ptrauth qualifier returns false when -pedantic-errors is specified by the developer, which results in ABI mismatches and potentially ODR violations as well. The only way to resolve this is to to make it an error to attempt to use the -pedantic-errors option when targeting a platform where pointer authentication is present. This may cause compilation issues for some projects but is better than bad codegen.
1 parent 0a20ab9 commit 4935f07

File tree

2 files changed

+58
-15
lines changed

2 files changed

+58
-15
lines changed

clang/lib/Frontend/CompilerInvocation.cpp

Lines changed: 32 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -3470,22 +3470,34 @@ static void GeneratePointerAuthArgs(const LangOptions &Opts,
34703470

34713471
static void ParsePointerAuthArgs(LangOptions &Opts, ArgList &Args,
34723472
DiagnosticsEngine &Diags) {
3473-
Opts.PointerAuthIntrinsics = Args.hasArg(OPT_fptrauth_intrinsics);
3474-
Opts.PointerAuthCalls = Args.hasArg(OPT_fptrauth_calls);
3475-
Opts.PointerAuthReturns = Args.hasArg(OPT_fptrauth_returns);
3476-
Opts.PointerAuthIndirectGotos = Args.hasArg(OPT_fptrauth_indirect_gotos);
3477-
Opts.PointerAuthAuthTraps = Args.hasArg(OPT_fptrauth_auth_traps);
3478-
Opts.PointerAuthVTPtrAddressDiscrimination =
3479-
Args.hasArg(OPT_fptrauth_vtable_pointer_address_discrimination);
3480-
Opts.PointerAuthVTPtrTypeDiscrimination =
3481-
Args.hasArg(OPT_fptrauth_vtable_pointer_type_discrimination);
3482-
Opts.PointerAuthTypeInfoVTPtrDiscrimination =
3483-
Args.hasArg(OPT_fptrauth_type_info_vtable_pointer_discrimination);
3484-
Opts.PointerAuthFunctionTypeDiscrimination =
3485-
Args.hasArg(OPT_fptrauth_function_pointer_type_discrimination);
3486-
Opts.PointerAuthInitFini = Args.hasArg(OPT_fptrauth_init_fini);
3473+
const Arg *PedanticErrors = Args.getLastArgNoClaim(OPT_pedantic_errors);
3474+
auto GetAndCheckPointerAuthArg = [&](driver::options::ID Option) {
3475+
Arg *OptionArg = Args.getLastArg(Option);
3476+
if (OptionArg && PedanticErrors) {
3477+
Diags.Report(diag::err_drv_incompatible_options)
3478+
<< OptionArg->getSpelling() << PedanticErrors->getSpelling();
3479+
}
3480+
return OptionArg != nullptr;
3481+
};
3482+
Opts.PointerAuthIntrinsics =
3483+
GetAndCheckPointerAuthArg(OPT_fptrauth_intrinsics);
3484+
Opts.PointerAuthCalls = GetAndCheckPointerAuthArg(OPT_fptrauth_calls);
3485+
Opts.PointerAuthReturns = GetAndCheckPointerAuthArg(OPT_fptrauth_returns);
3486+
Opts.PointerAuthIndirectGotos =
3487+
GetAndCheckPointerAuthArg(OPT_fptrauth_indirect_gotos);
3488+
Opts.PointerAuthAuthTraps =
3489+
GetAndCheckPointerAuthArg(OPT_fptrauth_auth_traps);
3490+
Opts.PointerAuthVTPtrAddressDiscrimination = GetAndCheckPointerAuthArg(
3491+
OPT_fptrauth_vtable_pointer_address_discrimination);
3492+
Opts.PointerAuthVTPtrTypeDiscrimination = GetAndCheckPointerAuthArg(
3493+
OPT_fptrauth_vtable_pointer_type_discrimination);
3494+
Opts.PointerAuthTypeInfoVTPtrDiscrimination = GetAndCheckPointerAuthArg(
3495+
OPT_fptrauth_type_info_vtable_pointer_discrimination);
3496+
Opts.PointerAuthFunctionTypeDiscrimination = GetAndCheckPointerAuthArg(
3497+
OPT_fptrauth_function_pointer_type_discrimination);
3498+
Opts.PointerAuthInitFini = GetAndCheckPointerAuthArg(OPT_fptrauth_init_fini);
34873499
Opts.PointerAuthInitFiniAddressDiscrimination =
3488-
Args.hasArg(OPT_fptrauth_init_fini_address_discrimination);
3500+
GetAndCheckPointerAuthArg(OPT_fptrauth_init_fini_address_discrimination);
34893501
}
34903502

34913503
/// Check if input file kind and language standard are compatible.
@@ -4895,6 +4907,11 @@ bool CompilerInvocation::CreateFromArgsImpl(
48954907
InputKind DashX = Res.getFrontendOpts().DashX;
48964908
ParseTargetArgs(Res.getTargetOpts(), Args, Diags);
48974909
llvm::Triple T(Res.getTargetOpts().Triple);
4910+
if (const Arg *PedanticErrors = Args.getLastArgNoClaim(OPT_pedantic_errors);
4911+
PedanticErrors && T.isArm64e()) {
4912+
Diags.Report(diag::err_drv_unsupported_opt_for_target)
4913+
<< PedanticErrors->getSpelling() << T.str();
4914+
}
48984915
ParseHeaderSearchArgs(Res.getHeaderSearchOpts(), Args, Diags,
48994916
Res.getFileSystemOpts().WorkingDir);
49004917
ParseAPINotesArgs(Res.getAPINotesOpts(), Args, Diags);
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
// REQUIRES: aarch64-registered-target
2+
3+
// RUN: not %clang -pedantic-errors --target=aarch64 -fptrauth-intrinsics %s -c 2>&1 | FileCheck %s
4+
// RUN: not %clang -pedantic-errors --target=aarch64 -fptrauth-calls %s -c 2>&1 | FileCheck %s
5+
// RUN: not %clang -pedantic-errors --target=aarch64 -fptrauth-returns %s -c 2>&1 | FileCheck %s
6+
// RUN: not %clang -pedantic-errors --target=aarch64 -fptrauth-indirect-gotos %s -c 2>&1 | FileCheck %s
7+
// RUN: not %clang -pedantic-errors --target=aarch64 -fptrauth-auth-traps %s -c 2>&1 | FileCheck %s
8+
// RUN: not %clang -pedantic-errors --target=aarch64 -fptrauth-vtable-pointer-address-discrimination %s -c 2>&1 | FileCheck %s
9+
// RUN: not %clang -pedantic-errors --target=aarch64 -fptrauth-vtable-pointer-type-discrimination %s -c 2>&1 | FileCheck %s
10+
// RUN: not %clang -pedantic-errors --target=aarch64 -fptrauth-function-pointer-type-discrimination %s -c 2>&1 | FileCheck %s
11+
// RUN: not %clang -pedantic-errors --target=aarch64 -fptrauth-init-fini %s -c 2>&1 | FileCheck %s
12+
// RUN: not %clang -pedantic-errors --target=aarch64 -fptrauth-init-fini-address-discrimination %s -c 2>&1 | FileCheck %s
13+
// RUN: not %clang -pedantic-errors --target=arm64e %s -c 2>&1 | FileCheck %s --check-prefix ARM64E_TRIPLE
14+
// RUN: not %clang -pedantic-errors --target=arm64e-apple-macosx10.0 %s -c 2>&1 | FileCheck %s --check-prefix ARM64E_MACOS_TRIPLE
15+
// RUN: not %clang -pedantic-errors -arch arm64e %s -c 2>&1 | FileCheck %s --check-prefix ARM64E_ARCH
16+
17+
int i;
18+
19+
// CHECK: error: the combination of '{{.*}}' and '-pedantic-errors' is incompatible
20+
// ARM64E_TRIPLE: error: unsupported option '-pedantic-errors' for target 'arm64e'
21+
// ARM64E_MACOS_TRIPLE: error: unsupported option '-pedantic-errors' for target 'arm64e-apple-macosx10.0.0'
22+
23+
// We have a trailing 'arm64e with no closing ' as the full triple is inferred from the host
24+
// which we don't care about, and don't want to specify as we're wanting to ensure that *just*
25+
// using '-arch arm64e' is sufficient
26+
// ARM64E_ARCH: error: unsupported option '-pedantic-errors' for target 'arm64e

0 commit comments

Comments
 (0)