|
| 1 | +// ignore-tidy-linelength |
| 2 | +//@ only-aarch64-unknown-linux-pauthtest |
| 3 | +//@ revisions: O0_PAUTH O3_PAUTH O0_PAUTH-ELF-GOT O3_PAUTH-ELF-GOT O0_NO_PAUTH O3_NO_PAUTH |
| 4 | + |
| 5 | +//@ [O0_PAUTH] needs-llvm-components: aarch64 |
| 6 | +//@ [O0_PAUTH] compile-flags: --target=aarch64-unknown-linux-pauthtest -C opt-level=0 |
| 7 | +//@ [O3_PAUTH] needs-llvm-components: aarch64 |
| 8 | +//@ [O3_PAUTH] compile-flags: --target=aarch64-unknown-linux-pauthtest -C opt-level=3 |
| 9 | +//@ [O0_PAUTH-ELF-GOT] needs-llvm-components: aarch64 |
| 10 | +//@ [O0_PAUTH-ELF-GOT] compile-flags: --target=aarch64-unknown-linux-pauthtest -C opt-level=0 -Z pauth_enable_elf_got |
| 11 | +//@ [O3_PAUTH-ELF-GOT] needs-llvm-components: aarch64 |
| 12 | +//@ [O3_PAUTH-ELF-GOT] compile-flags: --target=aarch64-unknown-linux-pauthtest -C opt-level=3 -Z pauth_enable_elf_got |
| 13 | +//@ [O0_NO_PAUTH] needs-llvm-components: aarch64 |
| 14 | +//@ [O0_NO_PAUTH] compile-flags: --target=aarch64-unknown-linux-gnu -C opt-level=0 |
| 15 | +//@ [O3_NO_PAUTH] needs-llvm-components: aarch64 |
| 16 | +//@ [O3_NO_PAUTH] compile-flags: --target=aarch64-unknown-linux-gnu -C opt-level=3 |
| 17 | + |
| 18 | +use std::hint::black_box; |
| 19 | + |
| 20 | +type FnPtr = unsafe extern "C" fn(i32, i32) -> i32; |
| 21 | + |
| 22 | +// O0_NO_PAUTH-NOT: "ptrauth"(i32 |
| 23 | +// O3_NO_PAUTH-NOT: "ptrauth"(i32 |
| 24 | + |
| 25 | +// O0_PAUTH: define {{.*}}pauth_extern_c4main |
| 26 | +// O3_PAUTH: define {{.*}}pauth_extern_c4main |
| 27 | +fn main() { |
| 28 | + // O0_PAUTH: ptr ptrauth (ptr @add_from_c, i32 0) |
| 29 | + // O3_PAUTH: ptr ptrauth (ptr @add_from_c, i32 0) |
| 30 | + let add_ptr: FnPtr = black_box(add_from_c); |
| 31 | + // O0_PAUTH: call i32 @{{.*}}pauth_extern_c7call_it{{.*}}(ptr {{.*}}) |
| 32 | + let _sum = call_it(add_ptr, 5, 7); |
| 33 | + assert!(12 == _sum); |
| 34 | +} |
| 35 | + |
| 36 | +// O0_PAUTH: define {{.*}}pauth_extern_c7call_it{{.*}} #[[ATTR_O0_1:[0-9]+]] |
| 37 | +// O3_PAUTH: define {{.*}}pauth_extern_c7call_it{{.*}} #[[ATTR_O3_1:[0-9]+]] |
| 38 | +#[inline(never)] |
| 39 | +fn call_it(fn_ptr: FnPtr, arg_1: i32, arg_2: i32) -> i32 { |
| 40 | + // O0_PAUTH: call i32 %fn_ptr(i32 %arg_1, i32 %arg_2) {{.*}} [ "ptrauth"(i32 0, i64 0) ] |
| 41 | + // O3_PAUTH: call {{.*}} i32 %fn_ptr(i32 {{.*}}, i32 {{.*}}) {{.*}} [ "ptrauth"(i32 0, i64 0) ] |
| 42 | + unsafe { fn_ptr(arg_1, arg_2) } |
| 43 | +} |
| 44 | + |
| 45 | +extern "C" { |
| 46 | + fn add_from_c(a: i32, b: i32) -> i32; |
| 47 | +} |
| 48 | + |
| 49 | +// O0_PAUTH-CHECK: attributes #[[ATTR_O0_1]] = { {{.*}}"aarch64-jump-table-hardening" |
| 50 | +// O0_PAUTH-CHECK-DAG: "ptrauth-auth-traps" |
| 51 | +// O0_PAUTH-CHECK-DAG: "ptrauth-calls" |
| 52 | +// O0_PAUTH-CHECK-DAG: "ptrauth-indirect-gotos" |
| 53 | +// O0_PAUTH-CHECK-DAG: "ptrauth-returns" |
| 54 | + |
| 55 | +// O3_PAUTH-CHECK: attributes #[[ATTR_O3_1]] = { {{.*}}"aarch64-jump-table-hardening" |
| 56 | +// O3_PAUTH-CHECK-DAG: "ptrauth-auth-traps" |
| 57 | +// O3_PAUTH-CHECK-DAG: "ptrauth-calls" |
| 58 | +// O3_PAUTH-CHECK-DAG: "ptrauth-indirect-gotos" |
| 59 | +// O3_PAUTH-CHECK-DAG: "ptrauth-returns" |
| 60 | + |
| 61 | +// O0_PAUTH-ELF-GOT: !{{[0-9]+}} = !{i32 7, !"ptrauth-elf-got", i32 1} |
| 62 | +// O0_PAUTH-NOT: !{{[0-9]+}} = !{i32 7, !"ptrauth-elf-got", i32 1} |
| 63 | +// O0_PAUTH: !{{[0-9]+}} = !{i32 7, !"ptrauth-sign-personality", i32 1} |
| 64 | +// O3_PAUTH-ELF-GOT: !{{[0-9]+}} = !{i32 7, !"ptrauth-elf-got", i32 1} |
| 65 | +// O3_PAUTH-NOT: !{{[0-9]+}} = !{i32 7, !"ptrauth-elf-got", i32 1} |
| 66 | +// O3_PAUTH: !{{[0-9]+}} = !{i32 7, !"ptrauth-sign-personality", i32 1} |
| 67 | + |
| 68 | +// O0_NO_PAUTH-NOT: !{{[0-9]+}} = !{i32 7, !"ptrauth-elf-got", i32 1} |
| 69 | +// O0_NO_PAUTH-NOT: !{{[0-9]+}} = !{i32 7, !"ptrauth-sign-personality", i32 1} |
| 70 | +// O3_NO_PAUTH-NOT: !{{[0-9]+}} = !{i32 7, !"ptrauth-elf-got", i32 1} |
| 71 | +// O3_NO_PAUTH-NOT: !{{[0-9]+}} = !{i32 7, !"ptrauth-sign-personality", i32 1} |
0 commit comments