|
| 1 | +// REQUIRES: aarch64-registered-target |
| 2 | + |
| 3 | +// Test that features requiring FEAT_PAuth fail early if the requirement is not met: |
| 4 | +// |
| 5 | +// RUN: not %clang %s -S -o - -target aarch64-linux-gnu -mcpu=cortex-a72 -mbranch-protection=pauthabi 2>&1 | FileCheck %s --check-prefix=FAIL |
| 6 | +// RUN: not %clang %s -S -o - -target aarch64-linux-gnu -mcpu=cortex-a72 -fptrauth-calls 2>&1 | FileCheck %s --check-prefix=FAIL |
| 7 | +// RUN: not %clang %s -S -o - -target aarch64-linux-gnu -mcpu=cortex-a72 -fptrauth-returns 2>&1 | FileCheck %s --check-prefix=FAIL |
| 8 | +// RUN: not %clang %s -S -o - -target aarch64-linux-gnu -mcpu=cortex-a72 -fptrauth-objc-isa 2>&1 | FileCheck %s --check-prefix=FAIL |
| 9 | +// |
| 10 | +// Test that no errors and warnings are generated if FEAT_PAUTH is supported: |
| 11 | +// RUN: %clang %s -S -o - -target aarch64-linux-gnu -mcpu=apple-a12 -mbranch-protection=pauthabi 2>&1 \ |
| 12 | +// RUN: | FileCheck %s --check-prefix=PAUTH --implicit-check-not=error --implicit-check-not=warning |
| 13 | +// RUN: %clang %s -S -o - -target aarch64-linux-gnu -march=armv8.3-a -mbranch-protection=pauthabi 2>&1 \ |
| 14 | +// RUN: | FileCheck %s --check-prefix=PAUTH --implicit-check-not=error --implicit-check-not=warning |
| 15 | +// RUN: %clang %s -S -o - -target aarch64-linux-gnu -march=armv9-a -mbranch-protection=pauthabi 2>&1 \ |
| 16 | +// RUN: | FileCheck %s --check-prefix=PAUTH --implicit-check-not=error --implicit-check-not=warning |
| 17 | +// RUN: %clang %s -S -o - -target aarch64-linux-gnu -march=armv8.2-a+pauth -mbranch-protection=pauthabi 2>&1 \ |
| 18 | +// RUN: | FileCheck %s --check-prefix=PAUTH --implicit-check-not=error --implicit-check-not=warning |
| 19 | +// |
| 20 | +// Test a few combinations of options that should not generate warnings (technically, prefix is CHECK): |
| 21 | +// RUN: %clang %s -S -o - -target aarch64-linux-gnu -march=armv8.3-a -fptrauth-returns 2>&1 \ |
| 22 | +// RUN: | FileCheck %s --allow-unused-prefixes --implicit-check-not=error --implicit-check-not=warning |
| 23 | +// RUN: %clang %s -S -o - -target aarch64-linux-gnu -march=armv8.3-a -fptrauth-objc-isa 2>&1 \ |
| 24 | +// RUN: | FileCheck %s --allow-unused-prefixes --implicit-check-not=error --implicit-check-not=warning |
| 25 | +// RUN: %clang %s -S -o - -target aarch64-linux-gnu -march=armv8.3-a -fptrauth-init-fini -fptrauth-calls 2>&1 \ |
| 26 | +// RUN: | FileCheck %s --allow-unused-prefixes --implicit-check-not=error --implicit-check-not=warning |
| 27 | +// RUN: %clang %s -S -o - -target aarch64-linux-gnu -march=armv8.3-a -fptrauth-init-fini -mbranch-protection=pauthabi 2>&1 \ |
| 28 | +// RUN: | FileCheck %s --allow-unused-prefixes --implicit-check-not=error --implicit-check-not=warning |
| 29 | + |
| 30 | +// Test that the following options are still gated on -fptrauth-calls. |
| 31 | +// If they are not, in assertion builds they would usually fail at asm printing time: |
| 32 | +// |
| 33 | +// RUN: %clang %s -S -o - -target aarch64-linux-gnu -mcpu=cortex-a72 -fptrauth-init-fini 2>&1 \ |
| 34 | +// RUN: | FileCheck %s --check-prefix=WARN -DOPTION=-fptrauth-init-fini |
| 35 | +// RUN: %clang %s -S -o - -target aarch64-linux-gnu -mcpu=cortex-a72 -fptrauth-function-pointer-type-discrimination 2>&1 \ |
| 36 | +// RUN: | FileCheck %s --check-prefix=WARN -DOPTION=-fptrauth-function-pointer-type-discrimination |
| 37 | +// RUN: %clang %s -S -o - -target aarch64-linux-gnu -mcpu=cortex-a72 -fptrauth-vtable-pointer-address-discrimination 2>&1 \ |
| 38 | +// RUN: | FileCheck %s --check-prefix=WARN -DOPTION=-fptrauth-vtable-pointer-address-discrimination |
| 39 | +// RUN: %clang %s -S -o - -target aarch64-linux-gnu -mcpu=cortex-a72 -fptrauth-vtable-pointer-type-discrimination 2>&1 \ |
| 40 | +// RUN: | FileCheck %s --check-prefix=WARN -DOPTION=-fptrauth-vtable-pointer-type-discrimination |
| 41 | +// RUN: %clang %s -S -o - -target aarch64-linux-gnu -mcpu=cortex-a72 -fptrauth-block-descriptor-pointers -fblocks -DBLOCKS 2>&1 \ |
| 42 | +// RUN: | FileCheck %s --check-prefix=WARN -DOPTION=-fptrauth-block-descriptor-pointers |
| 43 | + |
| 44 | +// Test that v8.2-compatible code is generated, if possible: |
| 45 | +// |
| 46 | +// RUN: %clang %s -S -o - -target aarch64-linux-gnu -mcpu=cortex-a72 -msign-return-address=all 2>&1 | FileCheck %s --check-prefix=COMPAT |
| 47 | +// RUN: %clang %s -S -o - -target aarch64-linux-gnu -mcpu=cortex-a72 -mbranch-protection=pac-ret 2>&1 | FileCheck %s --check-prefix=COMPAT |
| 48 | +// RUN: %clang %s -S -o - -target aarch64-linux-gnu -mcpu=cortex-a72 -mbranch-protection=pac-ret+b-key 2>&1 | FileCheck %s --check-prefix=COMPAT |
| 49 | + |
| 50 | +// arm64e has ptrauth enabled and assumes modern enough CPU by default: |
| 51 | +// |
| 52 | +// RUN: %clang %s -S -o - -target arm64e-apple-ios 2>&1 | FileCheck %s --check-prefix=PAUTH |
| 53 | +// RUN: not %clang %s -S -o - -target arm64e-apple-ios -mcpu=cortex-a72 2>&1 | FileCheck %s --check-prefix=FAIL |
| 54 | + |
| 55 | +volatile int counter; |
| 56 | + |
| 57 | +void ext(void); |
| 58 | + |
| 59 | +// Basically check the code generated for `caller`, other functions and classes |
| 60 | +// are provided just to ensure that assertion-enabled builds do not crash when |
| 61 | +// generating code for constructors, vtable, etc. |
| 62 | + |
| 63 | +extern "C" int caller(void) { |
| 64 | + ext(); |
| 65 | + return 0; |
| 66 | +} |
| 67 | + |
| 68 | +#ifdef BLOCKS |
| 69 | +int g(int (^bptr)(int)) { |
| 70 | + return bptr(42); |
| 71 | +} |
| 72 | +#endif |
| 73 | + |
| 74 | +class Base { |
| 75 | +public: |
| 76 | + virtual void f() {} |
| 77 | + virtual ~Base() {} |
| 78 | +}; |
| 79 | + |
| 80 | +class Derived : public Base { |
| 81 | + void f() override { |
| 82 | + counter += 1; |
| 83 | + } |
| 84 | +}; |
| 85 | + |
| 86 | +__attribute__((constructor)) void constr(void) { |
| 87 | + counter = 42; |
| 88 | +} |
| 89 | + |
| 90 | +__attribute__((destructor)) void destr(void) { |
| 91 | + counter = 0; |
| 92 | +} |
| 93 | + |
| 94 | +// Make Base and Derived usable from outside of this compilation unit |
| 95 | +// to prevent superfluous optimization. |
| 96 | +extern "C" void call_virtual(Base *B) { |
| 97 | + B->f(); |
| 98 | +} |
| 99 | +extern "C" void *create(bool f) { |
| 100 | + if (f) |
| 101 | + return new Base(); |
| 102 | + else |
| 103 | + return new Derived(); |
| 104 | +} |
| 105 | + |
| 106 | +// FIXME At now, the error message is printed twice. |
| 107 | +// Ideally, this should be fixed, but it seems rather harmless. |
| 108 | +// |
| 109 | +// FAIL-COUNT-2: error: neither FEAT_PAUTH nor -fptrauth-soft is enabled. Most of PAuth features are unavailable |
| 110 | +// WARN-COUNT-2: warning: [[OPTION]] is ignored because neither -fptrauth-calls nor -mbranch-protection=pauthabi is specified |
| 111 | + |
| 112 | +// COMPAT: caller: |
| 113 | +// COMPAT: hint {{#25|#27}} |
| 114 | +// |
| 115 | +// COMPAT: hint {{#29|#31}} |
| 116 | +// COMPAT: ret |
| 117 | +// COMPAT: -- End function |
| 118 | + |
| 119 | +// PAUTH: caller: |
| 120 | +// PAUTH: paci{{[ab]}}sp |
| 121 | +// |
| 122 | +// PAUTH: reta{{[ab]}} |
| 123 | +// PAUTH: -- End function |
| 124 | + |
| 125 | +// Just check that some assembler output is printed and -fptrauth-init-fini |
| 126 | +// is disabled. |
| 127 | +// |
| 128 | +// WARN-NOT: @AUTH |
| 129 | +// |
| 130 | +// WARN: caller: |
| 131 | +// |
| 132 | +// WARN-NOT: @AUTH |
0 commit comments