-
Notifications
You must be signed in to change notification settings - Fork 14.8k
[clang][PAC] Disallow -pedantic-errors in conjunction with pointer au… #153503
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
@llvm/pr-subscribers-clang-driver @llvm/pr-subscribers-clang Author: Oliver Hunt (ojhunt) Changes…thentication 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. Full diff: https://github.com/llvm/llvm-project/pull/153503.diff 2 Files Affected:
diff --git a/clang/lib/Frontend/CompilerInvocation.cpp b/clang/lib/Frontend/CompilerInvocation.cpp
index db7c791059a32..2942d5aefe354 100644
--- a/clang/lib/Frontend/CompilerInvocation.cpp
+++ b/clang/lib/Frontend/CompilerInvocation.cpp
@@ -3470,22 +3470,31 @@ static void GeneratePointerAuthArgs(const LangOptions &Opts,
static void ParsePointerAuthArgs(LangOptions &Opts, ArgList &Args,
DiagnosticsEngine &Diags) {
- Opts.PointerAuthIntrinsics = Args.hasArg(OPT_fptrauth_intrinsics);
- Opts.PointerAuthCalls = Args.hasArg(OPT_fptrauth_calls);
- Opts.PointerAuthReturns = Args.hasArg(OPT_fptrauth_returns);
- Opts.PointerAuthIndirectGotos = Args.hasArg(OPT_fptrauth_indirect_gotos);
- Opts.PointerAuthAuthTraps = Args.hasArg(OPT_fptrauth_auth_traps);
+ const Arg *PedanticErrors = Args.getLastArgNoClaim(OPT_pedantic_errors);
+ auto GetAndCheckPointerAuthArg = [&](driver::options::ID Option) {
+ Arg *OptionArg = Args.getLastArg(Option);
+ if (OptionArg && PedanticErrors) {
+ Diags.Report(diag::err_drv_incompatible_options)
+ << OptionArg->getSpelling() << PedanticErrors->getSpelling();
+ }
+ return OptionArg != nullptr;
+ };
+ Opts.PointerAuthIntrinsics = GetAndCheckPointerAuthArg(OPT_fptrauth_intrinsics);
+ Opts.PointerAuthCalls = GetAndCheckPointerAuthArg(OPT_fptrauth_calls);
+ Opts.PointerAuthReturns = GetAndCheckPointerAuthArg(OPT_fptrauth_returns);
+ Opts.PointerAuthIndirectGotos = GetAndCheckPointerAuthArg(OPT_fptrauth_indirect_gotos);
+ Opts.PointerAuthAuthTraps = GetAndCheckPointerAuthArg(OPT_fptrauth_auth_traps);
Opts.PointerAuthVTPtrAddressDiscrimination =
- Args.hasArg(OPT_fptrauth_vtable_pointer_address_discrimination);
+ GetAndCheckPointerAuthArg(OPT_fptrauth_vtable_pointer_address_discrimination);
Opts.PointerAuthVTPtrTypeDiscrimination =
- Args.hasArg(OPT_fptrauth_vtable_pointer_type_discrimination);
+ GetAndCheckPointerAuthArg(OPT_fptrauth_vtable_pointer_type_discrimination);
Opts.PointerAuthTypeInfoVTPtrDiscrimination =
- Args.hasArg(OPT_fptrauth_type_info_vtable_pointer_discrimination);
+ GetAndCheckPointerAuthArg(OPT_fptrauth_type_info_vtable_pointer_discrimination);
Opts.PointerAuthFunctionTypeDiscrimination =
- Args.hasArg(OPT_fptrauth_function_pointer_type_discrimination);
- Opts.PointerAuthInitFini = Args.hasArg(OPT_fptrauth_init_fini);
+ GetAndCheckPointerAuthArg(OPT_fptrauth_function_pointer_type_discrimination);
+ Opts.PointerAuthInitFini = GetAndCheckPointerAuthArg(OPT_fptrauth_init_fini);
Opts.PointerAuthInitFiniAddressDiscrimination =
- Args.hasArg(OPT_fptrauth_init_fini_address_discrimination);
+ GetAndCheckPointerAuthArg(OPT_fptrauth_init_fini_address_discrimination);
}
/// Check if input file kind and language standard are compatible.
@@ -4895,6 +4904,11 @@ bool CompilerInvocation::CreateFromArgsImpl(
InputKind DashX = Res.getFrontendOpts().DashX;
ParseTargetArgs(Res.getTargetOpts(), Args, Diags);
llvm::Triple T(Res.getTargetOpts().Triple);
+ if (const Arg *PedanticErrors = Args.getLastArgNoClaim(OPT_pedantic_errors);
+ PedanticErrors && T.isArm64e()) {
+ Diags.Report(diag::err_drv_unsupported_opt_for_target)
+ << PedanticErrors->getSpelling() << T.str();
+ }
ParseHeaderSearchArgs(Res.getHeaderSearchOpts(), Args, Diags,
Res.getFileSystemOpts().WorkingDir);
ParseAPINotesArgs(Res.getAPINotesOpts(), Args, Diags);
diff --git a/clang/test/Driver/aarch64-ptrauth-pedantic-errors.c b/clang/test/Driver/aarch64-ptrauth-pedantic-errors.c
new file mode 100644
index 0000000000000..61cc68666ffd8
--- /dev/null
+++ b/clang/test/Driver/aarch64-ptrauth-pedantic-errors.c
@@ -0,0 +1,26 @@
+// REQUIRES: aarch64-registered-target
+
+// RUN: not %clang -pedantic-errors --target=aarch64 -fptrauth-intrinsics %s -c 2>&1 | FileCheck %s
+// RUN: not %clang -pedantic-errors --target=aarch64 -fptrauth-calls %s -c 2>&1 | FileCheck %s
+// RUN: not %clang -pedantic-errors --target=aarch64 -fptrauth-returns %s -c 2>&1 | FileCheck %s
+// RUN: not %clang -pedantic-errors --target=aarch64 -fptrauth-indirect-gotos %s -c 2>&1 | FileCheck %s
+// RUN: not %clang -pedantic-errors --target=aarch64 -fptrauth-auth-traps %s -c 2>&1 | FileCheck %s
+// RUN: not %clang -pedantic-errors --target=aarch64 -fptrauth-vtable-pointer-address-discrimination %s -c 2>&1 | FileCheck %s
+// RUN: not %clang -pedantic-errors --target=aarch64 -fptrauth-vtable-pointer-type-discrimination %s -c 2>&1 | FileCheck %s
+// RUN: not %clang -pedantic-errors --target=aarch64 -fptrauth-function-pointer-type-discrimination %s -c 2>&1 | FileCheck %s
+// RUN: not %clang -pedantic-errors --target=aarch64 -fptrauth-init-fini %s -c 2>&1 | FileCheck %s
+// RUN: not %clang -pedantic-errors --target=aarch64 -fptrauth-init-fini-address-discrimination %s -c 2>&1 | FileCheck %s
+// RUN: not %clang -pedantic-errors --target=arm64e %s -c 2>&1 | FileCheck %s --check-prefix ARM64E_TRIPLE
+// RUN: not %clang -pedantic-errors --target=arm64e-apple-macosx10.0 %s -c 2>&1 | FileCheck %s --check-prefix ARM64E_MACOS_TRIPLE
+// RUN: not %clang -pedantic-errors -arch arm64e %s -c 2>&1 | FileCheck %s --check-prefix ARM64E_ARCH
+
+int i;
+
+// CHECK: error: the combination of '{{.*}}' and '-pedantic-errors' is incompatible
+// ARM64E_TRIPLE: error: unsupported option '-pedantic-errors' for target 'arm64e'
+// ARM64E_MACOS_TRIPLE: error: unsupported option '-pedantic-errors' for target 'arm64e-apple-macosx10.0.0'
+
+// We have a trailing 'arm64e with no closing ' as the full triple is inferred from the host
+// which we don't care about, and don't want to specify as we're wanting to ensure that *just*
+// using '-arch arm64e' is sufficient
+// ARM64E_ARCH: error: unsupported option '-pedantic-errors' for target 'arm64e
\ No newline at end of file
|
I have prepared this PR as the only sound alternative to #153291 While it will cause compilation failures for some projects, the alternative is incorrect codegen which is substantially worse. |
e69b1ac
to
4935f07
Compare
force pushed the formatting fix as I forgot to run clang-format before hand, and I figure that no one looked at this in the last 10 seconds :D |
<please hold while I update this PR to some notion of today's tree - I forgot I had been hunting a regression earlier and wrote this on top of a very old tree> |
…thentication 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.
4935f07
to
d93cc44
Compare
@AaronBallman if we can take #153506 then this can be closed |
I think closing this is the correct approach and taking some variation of #153506 - essentially working to resolve the ODR/ABI impact of -pedantic-errors |
…thentication
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.