Skip to content

Commit d93cc44

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 f9b9e9b commit d93cc44

File tree

2 files changed

+71
-20
lines changed

2 files changed

+71
-20
lines changed

clang/lib/Frontend/CompilerInvocation.cpp

Lines changed: 38 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -3602,30 +3602,43 @@ static void GeneratePointerAuthArgs(const LangOptions &Opts,
36023602

36033603
static void ParsePointerAuthArgs(LangOptions &Opts, ArgList &Args,
36043604
DiagnosticsEngine &Diags) {
3605-
Opts.PointerAuthIntrinsics = Args.hasArg(OPT_fptrauth_intrinsics);
3606-
Opts.PointerAuthCalls = Args.hasArg(OPT_fptrauth_calls);
3607-
Opts.PointerAuthReturns = Args.hasArg(OPT_fptrauth_returns);
3608-
Opts.PointerAuthIndirectGotos = Args.hasArg(OPT_fptrauth_indirect_gotos);
3609-
Opts.PointerAuthAuthTraps = Args.hasArg(OPT_fptrauth_auth_traps);
3610-
Opts.PointerAuthVTPtrAddressDiscrimination =
3611-
Args.hasArg(OPT_fptrauth_vtable_pointer_address_discrimination);
3612-
Opts.PointerAuthVTPtrTypeDiscrimination =
3613-
Args.hasArg(OPT_fptrauth_vtable_pointer_type_discrimination);
3614-
Opts.PointerAuthTypeInfoVTPtrDiscrimination =
3615-
Args.hasArg(OPT_fptrauth_type_info_vtable_pointer_discrimination);
3616-
Opts.PointerAuthFunctionTypeDiscrimination =
3617-
Args.hasArg(OPT_fptrauth_function_pointer_type_discrimination);
3618-
Opts.PointerAuthInitFini = Args.hasArg(OPT_fptrauth_init_fini);
3605+
const Arg *PedanticErrors = Args.getLastArgNoClaim(OPT_pedantic_errors);
3606+
auto GetAndCheckPointerAuthArg = [&](driver::options::ID Option) {
3607+
Arg *OptionArg = Args.getLastArg(Option);
3608+
if (OptionArg && PedanticErrors) {
3609+
Diags.Report(diag::err_drv_incompatible_options)
3610+
<< OptionArg->getSpelling() << PedanticErrors->getSpelling();
3611+
}
3612+
return OptionArg != nullptr;
3613+
};
3614+
Opts.PointerAuthIntrinsics =
3615+
GetAndCheckPointerAuthArg(OPT_fptrauth_intrinsics);
3616+
Opts.PointerAuthCalls = GetAndCheckPointerAuthArg(OPT_fptrauth_calls);
3617+
Opts.PointerAuthReturns = GetAndCheckPointerAuthArg(OPT_fptrauth_returns);
3618+
Opts.PointerAuthIndirectGotos =
3619+
GetAndCheckPointerAuthArg(OPT_fptrauth_indirect_gotos);
3620+
Opts.PointerAuthAuthTraps =
3621+
GetAndCheckPointerAuthArg(OPT_fptrauth_auth_traps);
3622+
Opts.PointerAuthVTPtrAddressDiscrimination = GetAndCheckPointerAuthArg(
3623+
OPT_fptrauth_vtable_pointer_address_discrimination);
3624+
Opts.PointerAuthVTPtrTypeDiscrimination = GetAndCheckPointerAuthArg(
3625+
OPT_fptrauth_vtable_pointer_type_discrimination);
3626+
Opts.PointerAuthTypeInfoVTPtrDiscrimination = GetAndCheckPointerAuthArg(
3627+
OPT_fptrauth_type_info_vtable_pointer_discrimination);
3628+
Opts.PointerAuthFunctionTypeDiscrimination = GetAndCheckPointerAuthArg(
3629+
OPT_fptrauth_function_pointer_type_discrimination);
3630+
Opts.PointerAuthInitFini = GetAndCheckPointerAuthArg(OPT_fptrauth_init_fini);
36193631
Opts.PointerAuthInitFiniAddressDiscrimination =
3620-
Args.hasArg(OPT_fptrauth_init_fini_address_discrimination);
3621-
Opts.PointerAuthELFGOT = Args.hasArg(OPT_fptrauth_elf_got);
3632+
GetAndCheckPointerAuthArg(OPT_fptrauth_init_fini_address_discrimination);
3633+
Opts.PointerAuthELFGOT = GetAndCheckPointerAuthArg(OPT_fptrauth_elf_got);
36223634
Opts.AArch64JumpTableHardening =
3623-
Args.hasArg(OPT_faarch64_jump_table_hardening);
3635+
GetAndCheckPointerAuthArg(OPT_faarch64_jump_table_hardening);
36243636

3625-
Opts.PointerAuthObjcIsa = Args.hasArg(OPT_fptrauth_objc_isa);
3626-
Opts.PointerAuthObjcClassROPointers = Args.hasArg(OPT_fptrauth_objc_class_ro);
3637+
Opts.PointerAuthObjcIsa = GetAndCheckPointerAuthArg(OPT_fptrauth_objc_isa);
3638+
Opts.PointerAuthObjcClassROPointers =
3639+
GetAndCheckPointerAuthArg(OPT_fptrauth_objc_class_ro);
36273640
Opts.PointerAuthObjcInterfaceSel =
3628-
Args.hasArg(OPT_fptrauth_objc_interface_sel);
3641+
GetAndCheckPointerAuthArg(OPT_fptrauth_objc_interface_sel);
36293642

36303643
if (Opts.PointerAuthObjcInterfaceSel)
36313644
Opts.PointerAuthObjcInterfaceSelKey =
@@ -5021,6 +5034,11 @@ bool CompilerInvocation::CreateFromArgsImpl(
50215034
InputKind DashX = Res.getFrontendOpts().DashX;
50225035
ParseTargetArgs(Res.getTargetOpts(), Args, Diags);
50235036
llvm::Triple T(Res.getTargetOpts().Triple);
5037+
if (const Arg *PedanticErrors = Args.getLastArgNoClaim(OPT_pedantic_errors);
5038+
PedanticErrors && T.isArm64e()) {
5039+
Diags.Report(diag::err_drv_unsupported_opt_for_target)
5040+
<< PedanticErrors->getSpelling() << T.str();
5041+
}
50245042
ParseHeaderSearchArgs(Res.getHeaderSearchOpts(), Args, Diags,
50255043
Res.getFileSystemOpts().WorkingDir);
50265044
if (Res.getFrontendOpts().GenReducedBMI ||
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
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=aarch64 -faarch64-jump-table-hardening %s -c 2>&1 | FileCheck %s
14+
// RUN: not %clang -pedantic-errors --target=aarch64 -fptrauth-objc-isa %s -c 2>&1 | FileCheck %s
15+
// RUN: not %clang -pedantic-errors --target=aarch64 -fptrauth-objc-class-ro %s -c 2>&1 | FileCheck %s
16+
// RUN: not %clang -pedantic-errors --target=aarch64 -fptrauth-objc-interface-sel %s -c 2>&1 | FileCheck %s
17+
// RUN: not %clang -pedantic-errors --target=arm64e %s -c 2>&1 | FileCheck %s --check-prefix ARM64E_TRIPLE
18+
// RUN: not %clang -pedantic-errors --target=arm64e-apple-macosx10.0 %s -c 2>&1 | FileCheck %s --check-prefix ARM64E_MACOS_TRIPLE
19+
// RUN: not %clang -pedantic-errors -arch arm64e %s -c 2>&1 | FileCheck %s --check-prefix ARM64E_ARCH
20+
21+
// FIXME: Cannot work out what the correct invocation to permit -fptrauth-elf-got is
22+
// -- not %clang -pedantic-errors --target=aarch64 -fptrauth-elf-got %s -c 2>&1 | FileCheck %s
23+
24+
int i;
25+
26+
// CHECK: error: the combination of '{{.*}}' and '-pedantic-errors' is incompatible
27+
// ARM64E_TRIPLE: error: unsupported option '-pedantic-errors' for target 'arm64e'
28+
// ARM64E_MACOS_TRIPLE: error: unsupported option '-pedantic-errors' for target 'arm64e-apple-macosx10.0.0'
29+
30+
// We have a trailing 'arm64e with no closing ' as the full triple is inferred from the host
31+
// which we don't care about, and don't want to specify as we're wanting to ensure that *just*
32+
// using '-arch arm64e' is sufficient
33+
// ARM64E_ARCH: error: unsupported option '-pedantic-errors' for target 'arm64e

0 commit comments

Comments
 (0)