Debian Codegraph @

clang/test/Driver/aarch64-ptrauth.c

raw
1 // REQUIRES: aarch64-registered-target
2
3 // RUN: %clang -### -c --target=aarch64 %s 2>&1 | FileCheck %s --check-prefix NONE
4 // NONE: "-cc1"
5 // NONE-NOT: "-fptrauth-
6
7 //// -fptauth-* driver flags on Linux are only supported with pauthtest ABI.
8 // RUN: %clang -### -c --target=aarch64-linux -mabi=pauthtest \
9 // RUN: -fno-ptrauth-intrinsics -fptrauth-intrinsics \
10 // RUN: -fno-ptrauth-calls -fptrauth-calls \
11 // RUN: -fno-ptrauth-returns -fptrauth-returns \
12 // RUN: -fno-ptrauth-auth-traps -fptrauth-auth-traps \
13 // RUN: -fno-ptrauth-vtable-pointer-address-discrimination -fptrauth-vtable-pointer-address-discrimination \
14 // RUN: -fno-ptrauth-vtable-pointer-type-discrimination -fptrauth-vtable-pointer-type-discrimination \
15 // RUN: -fno-ptrauth-type-info-vtable-pointer-discrimination -fptrauth-type-info-vtable-pointer-discrimination \
16 // RUN: -fno-ptrauth-indirect-gotos -fptrauth-indirect-gotos \
17 // RUN: -fno-ptrauth-init-fini -fptrauth-init-fini \
18 // RUN: -fno-ptrauth-init-fini-address-discrimination -fptrauth-init-fini-address-discrimination \
19 // RUN: -fno-ptrauth-elf-got -fptrauth-elf-got \
20 // RUN: -fno-aarch64-jump-table-hardening -faarch64-jump-table-hardening \
21 // RUN: %s 2>&1 | FileCheck %s --check-prefix=ALL-LINUX-PAUTHABI
22 // RUN: %clang -### -c --target=aarch64-linux-pauthtest \
23 // RUN: -fno-ptrauth-intrinsics -fptrauth-intrinsics \
24 // RUN: -fno-ptrauth-calls -fptrauth-calls \
25 // RUN: -fno-ptrauth-returns -fptrauth-returns \
26 // RUN: -fno-ptrauth-auth-traps -fptrauth-auth-traps \
27 // RUN: -fno-ptrauth-vtable-pointer-address-discrimination -fptrauth-vtable-pointer-address-discrimination \
28 // RUN: -fno-ptrauth-vtable-pointer-type-discrimination -fptrauth-vtable-pointer-type-discrimination \
29 // RUN: -fno-ptrauth-type-info-vtable-pointer-discrimination -fptrauth-type-info-vtable-pointer-discrimination \
30 // RUN: -fno-ptrauth-indirect-gotos -fptrauth-indirect-gotos \
31 // RUN: -fno-ptrauth-init-fini -fptrauth-init-fini \
32 // RUN: -fno-ptrauth-init-fini-address-discrimination -fptrauth-init-fini-address-discrimination \
33 // RUN: -fno-ptrauth-elf-got -fptrauth-elf-got \
34 // RUN: -fno-aarch64-jump-table-hardening -faarch64-jump-table-hardening \
35 // RUN: %s 2>&1 | FileCheck %s --check-prefix=ALL-LINUX-PAUTHABI
36 // ALL-LINUX-PAUTHABI: "-cc1"{{.*}} "-fptrauth-intrinsics" "-fptrauth-calls" "-fptrauth-returns" "-fptrauth-auth-traps" "-fptrauth-vtable-pointer-address-discrimination" "-fptrauth-vtable-pointer-type-discrimination" "-fptrauth-type-info-vtable-pointer-discrimination" "-fptrauth-indirect-gotos" "-fptrauth-init-fini" "-fptrauth-init-fini-address-discrimination" "-fptrauth-elf-got"{{.*}} "-faarch64-jump-table-hardening"
37
38 // RUN: %clang -### -c --target=aarch64-linux \
39 // RUN: -fno-aarch64-jump-table-hardening -faarch64-jump-table-hardening \
40 // RUN: %s 2>&1 | FileCheck %s --check-prefix=ALL-LINUX
41 // ALL-LINUX: "-cc1"{{.*}} "-faarch64-jump-table-hardening"
42
43 //// Some -fptrauth-* flags are supported for ARM64 Darwin.
44 // RUN: %clang -### -c --target=arm64-darwin \
45 // RUN: -fno-ptrauth-intrinsics -fptrauth-intrinsics \
46 // RUN: -fno-ptrauth-calls -fptrauth-calls \
47 // RUN: -fno-ptrauth-returns -fptrauth-returns \
48 // RUN: -fno-ptrauth-auth-traps -fptrauth-auth-traps \
49 // RUN: -fno-ptrauth-vtable-pointer-address-discrimination -fptrauth-vtable-pointer-address-discrimination \
50 // RUN: -fno-ptrauth-vtable-pointer-type-discrimination -fptrauth-vtable-pointer-type-discrimination \
51 // RUN: -fno-ptrauth-type-info-vtable-pointer-discrimination -fptrauth-type-info-vtable-pointer-discrimination \
52 // RUN: -fno-ptrauth-indirect-gotos -fptrauth-indirect-gotos \
53 // RUN: -fno-aarch64-jump-table-hardening -faarch64-jump-table-hardening \
54 // RUN: %s 2>&1 | FileCheck %s --check-prefix=ALL-DARWIN
55 // ALL-DARWIN: "-cc1"{{.*}} "-fptrauth-intrinsics" "-fptrauth-calls" "-fptrauth-returns" "-fptrauth-auth-traps" "-fptrauth-vtable-pointer-address-discrimination" "-fptrauth-vtable-pointer-type-discrimination" "-fptrauth-type-info-vtable-pointer-discrimination" "-fptrauth-indirect-gotos"{{.*}} "-faarch64-jump-table-hardening"
56
57 // RUN: %clang -### -c --target=aarch64-linux -mabi=pauthtest %s 2>&1 | FileCheck %s --check-prefix=PAUTHABI1
58 // RUN: %clang -### -c --target=aarch64-linux-pauthtest %s 2>&1 | FileCheck %s --check-prefix=PAUTHABI1
59 // PAUTHABI1: "-cc1"{{.*}} "-triple" "aarch64-unknown-linux-pauthtest"
60 // PAUTHABI1-SAME: "-fptrauth-intrinsics" "-fptrauth-calls" "-fptrauth-returns" "-fptrauth-auth-traps" "-fptrauth-vtable-pointer-address-discrimination" "-fptrauth-vtable-pointer-type-discrimination" "-fptrauth-type-info-vtable-pointer-discrimination" "-fptrauth-indirect-gotos" "-fptrauth-init-fini" "-fptrauth-init-fini-address-discrimination" "-faarch64-jump-table-hardening"
61 // PAUTHABI1-SAME: "-target-abi" "pauthtest"
62 // PAUTHABI1-NOT: "-fptrauth-function-pointer-type-discrimination"
63
64 // RUN: %clang -### -c --target=aarch64-linux -mabi=pauthtest -fno-ptrauth-intrinsics \
65 // RUN: -fno-ptrauth-calls -fno-ptrauth-returns -fno-ptrauth-auth-traps \
66 // RUN: -fno-ptrauth-vtable-pointer-address-discrimination -fno-ptrauth-vtable-pointer-type-discrimination \
67 // RUN: -fno-ptrauth-type-info-vtable-pointer-discrimination -fno-ptrauth-indirect-gotos \
68 // RUN: -fno-ptrauth-init-fini -fno-ptrauth-init-fini-address-discrimination \
69 // RUN: -fno-aarch64-jump-table-hardening %s 2>&1 | FileCheck %s --check-prefix=PAUTHABI2
70 // RUN: %clang -### -c --target=aarch64-linux-pauthtest -fno-ptrauth-intrinsics \
71 // RUN: -fno-ptrauth-calls -fno-ptrauth-returns -fno-ptrauth-auth-traps \
72 // RUN: -fno-ptrauth-vtable-pointer-address-discrimination -fno-ptrauth-vtable-pointer-type-discrimination \
73 // RUN: -fno-ptrauth-type-info-vtable-pointer-discrimination -fno-ptrauth-indirect-gotos \
74 // RUN: -fno-ptrauth-init-fini -fno-ptrauth-init-fini-address-discrimination \
75 // RUN: -fno-aarch64-jump-table-hardening %s 2>&1 | FileCheck %s --check-prefix=PAUTHABI2
76
77 //// Non-linux OS: pauthtest ABI has no effect in terms of passing ptrauth cc1 flags.
78 //// An error about unsupported ABI will be emitted later in pipeline (see ERR3 below)
79 // RUN: %clang -### -c --target=aarch64 -mabi=pauthtest %s 2>&1 | FileCheck %s --check-prefix=PAUTHABI2
80
81 // PAUTHABI2: "-cc1"
82 // PAUTHABI2-SAME: "-target-abi" "pauthtest"
83 // PAUTHABI2-NOT: "-fptrauth-
84 // PAUTHABI2-NOT: "-faarch64-jump-table-hardening"
85
86 //// Non-linux OS: pauthtest environment does not correspond to pauthtest ABI; aapcs is the default.
87 // RUN: %clang -### -c --target=aarch64-pauthtest %s 2>&1 | FileCheck %s --check-prefix=PAUTHABI3
88 // PAUTHABI3: "-cc1"
89 // PAUTHABI3-SAME: "-target-abi" "aapcs"
90 // PAUTHABI3-NOT: "-fptrauth-
91 // PAUTHABI3-NOT: "-faarch64-jump-table-hardening"
92
93 //// Non-pauthtest ABI.
94 // RUN: not %clang -### -c --target=aarch64-linux -fptrauth-intrinsics -fptrauth-calls -fptrauth-returns -fptrauth-auth-traps \
95 // RUN: -fptrauth-vtable-pointer-address-discrimination -fptrauth-vtable-pointer-type-discrimination \
96 // RUN: -fptrauth-type-info-vtable-pointer-discrimination -fptrauth-indirect-gotos -fptrauth-init-fini \
97 // RUN: -fptrauth-init-fini-address-discrimination -fptrauth-elf-got %s 2>&1 | FileCheck %s --check-prefix=ERR1
98 // ERR1: error: unsupported option '-fptrauth-intrinsics' for target '{{.*}}'
99 // ERR1-NEXT: error: unsupported option '-fptrauth-calls' for target '{{.*}}'
100 // ERR1-NEXT: error: unsupported option '-fptrauth-returns' for target '{{.*}}'
101 // ERR1-NEXT: error: unsupported option '-fptrauth-auth-traps' for target '{{.*}}'
102 // ERR1-NEXT: error: unsupported option '-fptrauth-vtable-pointer-address-discrimination' for target '{{.*}}'
103 // ERR1-NEXT: error: unsupported option '-fptrauth-vtable-pointer-type-discrimination' for target '{{.*}}'
104 // ERR1-NEXT: error: unsupported option '-fptrauth-type-info-vtable-pointer-discrimination' for target '{{.*}}'
105 // ERR1-NEXT: error: unsupported option '-fptrauth-indirect-gotos' for target '{{.*}}'
106 // ERR1-NEXT: error: unsupported option '-fptrauth-init-fini' for target '{{.*}}'
107 // ERR1-NEXT: error: unsupported option '-fptrauth-init-fini-address-discrimination' for target '{{.*}}'
108 // ERR1-NEXT: error: unsupported option '-fptrauth-elf-got' for target '{{.*}}'
109
110 //// Non-AArch64.
111 // RUN: not %clang -### -c --target=x86_64-linux -faarch64-jump-table-hardening %s 2>&1 | FileCheck %s --check-prefix=ERR2
112 // ERR2: error: unsupported option '-faarch64-jump-table-hardening' for target '{{.*}}'
113
114 //// Only support PAuth ABI for Linux as for now.
115 // RUN: not %clang -c --target=aarch64 -mabi=pauthtest %s 2>&1 | FileCheck %s --check-prefix=ERR3
116 // ERR3: error: unknown target ABI 'pauthtest'
117
118 //// The ABI is not specified explicitly, and for non-Linux pauthtest environment does not correspond
119 //// to pauthtest ABI (each OS target defines this behavior separately). Do not emit an error.
120 // RUN: %clang -c --target=aarch64-pauthtest %s -o /dev/null
121
122 //// PAuth ABI is encoded as environment part of the triple, so don't allow to explicitly set other environments.
123 // RUN: not %clang -### -c --target=aarch64-linux-gnu -mabi=pauthtest %s 2>&1 | FileCheck %s --check-prefix=ERR4
124 // ERR4: error: unsupported option '-mabi=pauthtest' for target 'aarch64-unknown-linux-gnu'
125 // RUN: %clang -### -c --target=aarch64-linux-pauthtest -mabi=pauthtest %s
126
127 //// The only branch protection option compatible with PAuthABI is BTI.
128 // RUN: not %clang -### -c --target=aarch64-linux -mabi=pauthtest -mbranch-protection=pac-ret %s 2>&1 | \
129 // RUN: FileCheck %s --check-prefix=ERR5_1
130 // RUN: not %clang -### -c --target=aarch64-linux-pauthtest -mbranch-protection=pac-ret %s 2>&1 | \
131 // RUN: FileCheck %s --check-prefix=ERR5_1
132 // RUN: not %clang -### -c --target=aarch64 -fptrauth-returns -mbranch-protection=pac-ret %s 2>&1 | \
133 // RUN: FileCheck %s --check-prefix=ERR5_2
134 // ERR5_1: error: unsupported option '-mbranch-protection=pac-ret' for target 'aarch64-unknown-linux-pauthtest'
135 // ERR5_2: error: the combination of '-mbranch-protection=pac-ret' and '-fptrauth-returns' is incompatible
136
137 // RUN: not %clang -### -c --target=aarch64-linux -mabi=pauthtest -mbranch-protection=gcs %s 2>&1 | \
138 // RUN: FileCheck %s --check-prefix=ERR6_1
139 // RUN: not %clang -### -c --target=aarch64-linux-pauthtest -mbranch-protection=gcs %s 2>&1 | \
140 // RUN: FileCheck %s --check-prefix=ERR6_1
141 // RUN: not %clang -### -c --target=aarch64 -fptrauth-returns -mbranch-protection=gcs %s 2>&1 | \
142 // RUN: FileCheck %s --check-prefix=ERR6_2
143 // ERR6_1: error: unsupported option '-mbranch-protection=gcs' for target 'aarch64-unknown-linux-pauthtest'
144 // ERR6_2: error: the combination of '-mbranch-protection=gcs' and '-fptrauth-returns' is incompatible
145
146 // RUN: not %clang -### -c --target=aarch64-linux -mabi=pauthtest -mbranch-protection=standard %s 2>&1 | \
147 // RUN: FileCheck %s --check-prefix=ERR7_1
148 // RUN: not %clang -### -c --target=aarch64-linux-pauthtest -mbranch-protection=standard %s 2>&1 | \
149 // RUN: FileCheck %s --check-prefix=ERR7_1
150 // RUN: not %clang -### -c --target=aarch64 -fptrauth-returns -mbranch-protection=standard %s 2>&1 | \
151 // RUN: FileCheck %s --check-prefix=ERR7_2
152 // ERR7_1: error: unsupported option '-mbranch-protection=standard' for target 'aarch64-unknown-linux-pauthtest'
153 // ERR7_2: error: the combination of '-mbranch-protection=standard' and '-fptrauth-returns' is incompatible
154
155 // RUN: not %clang -### -c --target=aarch64-linux -mabi=pauthtest -msign-return-address=all %s 2>&1 | \
156 // RUN: FileCheck %s --check-prefix=ERR8
157 // RUN: not %clang -### -c --target=aarch64-linux-pauthtest -msign-return-address=all %s 2>&1 | \
158 // RUN: FileCheck %s --check-prefix=ERR8
159 // ERR8: error: unsupported option '-msign-return-address=all' for target 'aarch64-unknown-linux-pauthtest'
160
161 // RUN: not %clang -### -c --target=aarch64-linux -mabi=pauthtest -msign-return-address=non-leaf %s 2>&1 | \
162 // RUN: FileCheck %s --check-prefix=ERR9
163 // RUN: not %clang -### -c --target=aarch64-linux-pauthtest -msign-return-address=non-leaf %s 2>&1 | \
164 // RUN: FileCheck %s --check-prefix=ERR9
165 // ERR9: error: unsupported option '-msign-return-address=non-leaf' for target 'aarch64-unknown-linux-pauthtest'
166
167 // RUN: %clang -### -c --target=aarch64-linux -mabi=pauthtest -msign-return-address=none %s
168 // RUN: %clang -### -c --target=aarch64-linux-pauthtest -msign-return-address=none %s
169 // RUN: %clang -### -c --target=aarch64-linux -mabi=pauthtest -mbranch-protection=bti %s
170 // RUN: %clang -### -c --target=aarch64-linux-pauthtest -mbranch-protection=bti %s
171 // RUN: %clang -### -c --target=aarch64-linux -mabi=pauthtest -mbranch-protection=none %s
172 // RUN: %clang -### -c --target=aarch64-linux-pauthtest -mbranch-protection=none %s