Skip to content

Commit a4c6ab8

Browse files
committed
Address comments (more to be done)
1 parent 94f0cd9 commit a4c6ab8

File tree

3 files changed

+48
-11
lines changed

3 files changed

+48
-11
lines changed

clang/include/clang/Basic/DiagnosticDriverKinds.td

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -533,7 +533,10 @@ def err_stack_tagging_requires_hardware_feature : Error<
533533
"Armv9, try compiling with -march=armv8a+memtag or -march=armv9a+memtag">;
534534

535535
def err_pauth_cpu_feature_missing : Error<
536-
"A feature is requested that needs CPU with Pointer Authentication support">;
536+
"neither FEAT_PAUTH nor -fptrauth-soft is enabled. Most of PAuth features are unavailable">;
537+
538+
def warn_pauth_feature_ignored : Warning<
539+
"%0 is ignored because %1 is not specified">;
537540

538541
def err_cmse_pi_are_incompatible : Error<
539542
"cmse is not compatible with %select{RWPI|ROPI}0">;

clang/lib/Basic/Targets/AArch64.cpp

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -202,19 +202,44 @@ AArch64TargetInfo::AArch64TargetInfo(const llvm::Triple &Triple,
202202

203203
void AArch64TargetInfo::validatePAuthOptions(DiagnosticsEngine &Diags,
204204
const LangOptions &Opts) const {
205-
if (Opts.SoftPointerAuth)
205+
if (!Opts.PointerAuthCalls) {
206+
auto IgnoredWithoutPtrAuthCalls = [&Diags](const StringRef OptString) {
207+
Diags.Report(diag::warn_pauth_feature_ignored)
208+
<< OptString << "-fptrauth-calls";
209+
};
210+
211+
if (Opts.PointerAuthInitFini)
212+
IgnoredWithoutPtrAuthCalls("-fptrauth-init-fini");
213+
if (Opts.FunctionPointerTypeDiscrimination)
214+
IgnoredWithoutPtrAuthCalls(
215+
"-fptrauth-function-pointer-type-discrimination");
216+
if (Opts.PointerAuthVTPtrAddressDiscrimination)
217+
IgnoredWithoutPtrAuthCalls(
218+
"-fptrauth-vtable-pointer-address-discrimination");
219+
if (Opts.PointerAuthVTPtrTypeDiscrimination)
220+
IgnoredWithoutPtrAuthCalls(
221+
"-fptrauth-vtable-pointer-type-discrimination");
222+
if (Opts.PointerAuthBlockDescriptorPointers)
223+
IgnoredWithoutPtrAuthCalls("-fptrauth-block-descriptor-pointers");
224+
}
225+
226+
if (HasPAuth || Opts.SoftPointerAuth)
206227
return;
207228

208229
bool NeedsFeatPAuth = false;
209-
// FIXME: Some ptrauth_* intrinsics can be implemented without FEAT_PAuth.
230+
// FIXME: Some ptrauth_* intrinsics can be implemented by only using
231+
// HINT-encoded instructions, thus not requiring FEAT_PAUTH.
210232
// At now, checking conservatively.
211233
NeedsFeatPAuth |= Opts.PointerAuthIntrinsics;
212234
NeedsFeatPAuth |= Opts.PointerAuthCalls;
213235
NeedsFeatPAuth |= Opts.PointerAuthReturns;
214236
NeedsFeatPAuth |= Opts.getPointerAuthObjcIsaAuthentication() !=
215237
PointerAuthenticationMode::None;
216238

217-
if (NeedsFeatPAuth && !HasPAuth)
239+
// FIXME The particular command line option is not printed in error message,
240+
// as it would misleadingly mention various -fptrauth-<something>
241+
// options instead of -mbranch-protection=pauthabi.
242+
if (NeedsFeatPAuth)
218243
Diags.Report(diag::err_pauth_cpu_feature_missing);
219244
}
220245

clang/test/CodeGen/ptrauth-cpu-feature.c

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,20 @@
77
// RUN: not %clang %s -S -o - -target aarch64-linux-gnu -mcpu=cortex-a72 -fptrauth-returns 2>&1 | FileCheck %s --check-prefix=FAIL
88
// RUN: not %clang %s -S -o - -target aarch64-linux-gnu -mcpu=cortex-a72 -fptrauth-objc-isa 2>&1 | FileCheck %s --check-prefix=FAIL
99
//
10-
// RUN: %clang %s -S -o - -target aarch64-linux-gnu -mcpu=apple-a12 -mbranch-protection=pauthabi 2>&1 | FileCheck %s --check-prefix=PAUTH
10+
// Test that no error is generated if FEAT_PAUTH is supported:
11+
// RUN: %clang %s -S -o - -target aarch64-linux-gnu -mcpu=apple-a12 -mbranch-protection=pauthabi 2>&1 | FileCheck %s --check-prefix=PAUTH
12+
// RUN: %clang %s -S -o - -target aarch64-linux-gnu -march=armv8.3-a -mbranch-protection=pauthabi 2>&1 | FileCheck %s --check-prefix=PAUTH
13+
// RUN: %clang %s -S -o - -target aarch64-linux-gnu -march=armv9-a -mbranch-protection=pauthabi 2>&1 | FileCheck %s --check-prefix=PAUTH
14+
// RUN: %clang %s -S -o - -target aarch64-linux-gnu -march=armv8.2-a+pauth -mbranch-protection=pauthabi 2>&1 | FileCheck %s --check-prefix=PAUTH
1115

1216
// Test that the following options are still gated on -fptrauth-calls.
1317
// If they are not, in assertion builds they would fail at asm printing time:
1418
//
15-
// RUN: %clang %s -S -o - -target aarch64-linux-gnu -mcpu=cortex-a72 -fptrauth-init-fini
16-
// RUN: %clang %s -S -o - -target aarch64-linux-gnu -mcpu=cortex-a72 -fptrauth-function-pointer-type-discrimination
17-
// RUN: %clang %s -S -o - -target aarch64-linux-gnu -mcpu=cortex-a72 -fptrauth-vtable-pointer-address-discrimination
18-
// RUN: %clang %s -S -o - -target aarch64-linux-gnu -mcpu=cortex-a72 -fptrauth-vtable-pointer-type-discrimination
19-
// RUN: %clang %s -S -o - -target aarch64-linux-gnu -mcpu=cortex-a72 -fptrauth-block-descriptor-pointers -fblocks -DBLOCKS
19+
// RUN: %clang %s -S -o - -target aarch64-linux-gnu -mcpu=cortex-a72 -fptrauth-init-fini 2>&1 | FileCheck %s --check-prefix=WARN -DOPTION=-fptrauth-init-fini
20+
// RUN: %clang %s -S -o - -target aarch64-linux-gnu -mcpu=cortex-a72 -fptrauth-function-pointer-type-discrimination 2>&1 | FileCheck %s --check-prefix=WARN -DOPTION=-fptrauth-function-pointer-type-discrimination
21+
// RUN: %clang %s -S -o - -target aarch64-linux-gnu -mcpu=cortex-a72 -fptrauth-vtable-pointer-address-discrimination 2>&1 | FileCheck %s --check-prefix=WARN -DOPTION=-fptrauth-vtable-pointer-address-discrimination
22+
// RUN: %clang %s -S -o - -target aarch64-linux-gnu -mcpu=cortex-a72 -fptrauth-vtable-pointer-type-discrimination 2>&1 | FileCheck %s --check-prefix=WARN -DOPTION=-fptrauth-vtable-pointer-type-discrimination
23+
// RUN: %clang %s -S -o - -target aarch64-linux-gnu -mcpu=cortex-a72 -fptrauth-block-descriptor-pointers -fblocks -DBLOCKS 2>&1 | FileCheck %s --check-prefix=WARN -DOPTION=-fptrauth-block-descriptor-pointers
2024

2125
// Test that v8.2-compatible code is generated, if possible:
2226
//
@@ -45,7 +49,8 @@ int g(int (^bptr)(int)) {
4549
// FIXME At now, the error message is printed twice.
4650
// Ideally, this should be fixed, but it seems rather harmless.
4751
//
48-
// FAIL-COUNT-2: error: A feature is requested that needs CPU with Pointer Authentication support
52+
// FAIL-COUNT-2: error: neither FEAT_PAUTH nor -fptrauth-soft is enabled. Most of PAuth features are unavailable
53+
// WARN-COUNT-2: warning: [[OPTION]] is ignored because -fptrauth-calls is not specified
4954

5055
// COMPAT: f:
5156
// COMPAT: hint {{#25|#27}}
@@ -57,3 +62,7 @@ int g(int (^bptr)(int)) {
5762
// PAUTH: paci{{[ab]}}sp
5863
//
5964
// PAUTH: reta{{[ab]}}
65+
66+
// Just check that some assembler output is printed.
67+
// WARN: f:
68+
// WARN: ret

0 commit comments

Comments
 (0)