11// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -emit-llvm -fsanitize=kcfi -o - %s | FileCheck %s
2- // RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -emit-llvm -fsanitize=kcfi -x c++ -o - %s | FileCheck %s --check-prefixes=CHECK,MEMBER
32// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -emit-llvm -fsanitize=kcfi -fpatchable-function-entry-offset=3 -o - %s | FileCheck %s --check-prefixes=CHECK,OFFSET
43
54// Note that the interleving of functions, which normally would be in sequence,
98#error Missing kcfi?
109#endif
1110
12- #define __cfi_salt __attribute__((cfi_salt ("pepper")))
11+ #define __kcfi_salt __attribute__((kcfi_salt ("pepper")))
1312
1413typedef int (* fn_t )(void );
15- typedef int __cfi_salt (* fn_salt_t )(void );
14+ typedef int __kcfi_salt (* fn_salt_t )(void );
1615
1716typedef unsigned int (* ufn_t )(void );
18- typedef unsigned int __cfi_salt (* ufn_salt_t )(void );
17+ typedef unsigned int __kcfi_salt (* ufn_salt_t )(void );
1918
2019/// Must emit __kcfi_typeid symbols for address-taken function declarations
2120// CHECK: module asm ".weak __kcfi_typeid_[[F4:[a-zA-Z0-9_]+]]"
@@ -27,25 +26,25 @@ typedef unsigned int __cfi_salt (*ufn_salt_t)(void);
2726// CHECK-NOT: module asm ".weak __kcfi_typeid_{{f6|_Z2f6v}}"
2827
2928int f1 (void );
30- int f1_salt (void ) __cfi_salt ;
29+ int f1_salt (void ) __kcfi_salt ;
3130
3231unsigned int f2 (void );
33- unsigned int f2_salt (void ) __cfi_salt ;
32+ unsigned int f2_salt (void ) __kcfi_salt ;
3433
3534static int f3 (void );
36- static int f3_salt (void ) __cfi_salt ;
35+ static int f3_salt (void ) __kcfi_salt ;
3736
3837extern int f4 (void );
39- extern int f4_salt (void ) __cfi_salt ;
38+ extern int f4_salt (void ) __kcfi_salt ;
4039
4140static int f5 (void );
42- static int f5_salt (void ) __cfi_salt ;
41+ static int f5_salt (void ) __kcfi_salt ;
4342
4443extern int f6 (void );
45- extern int f6_salt (void ) __cfi_salt ;
44+ extern int f6_salt (void ) __kcfi_salt ;
4645
4746struct cfi_struct {
48- fn_t __cfi_salt fptr ;
47+ fn_t __kcfi_salt fptr ;
4948 fn_salt_t td_fptr ;
5049};
5150
@@ -67,7 +66,7 @@ int __call(fn_t f) __attribute__((__no_sanitize__("kcfi"))) {
6766// CHECK-LABEL: @{{call_salt_ty|_Z12call_salt_tyPFivE}}
6867// CHECK: call{{.*}} i32 %{{.}}(){{.*}} [ "kcfi"(i32 [[#SALTY_HASH]]) ]
6968int call (fn_t f ) { return f (); }
70- int call_salt (fn_t __cfi_salt f ) { return f (); }
69+ int call_salt (fn_t __kcfi_salt f ) { return f (); }
7170int call_salt_ty (fn_salt_t f ) { return f (); }
7271
7372// CHECK-LABEL: @{{ucall|_Z5ucallPFjvE}}
@@ -77,7 +76,7 @@ int call_salt_ty(fn_salt_t f) { return f(); }
7776// CHECK-LABEL: @{{ucall_salt_ty|_Z13ucall_salt_tyPFjvE}}
7877// CHECK: call{{.*}} i32 %{{.}}(){{.*}} [ "kcfi"(i32 [[#SALTY_UHASH]]) ]
7978unsigned int ucall (ufn_t f ) { return f (); }
80- unsigned int ucall_salt (ufn_t __cfi_salt f ) { return f (); }
79+ unsigned int ucall_salt (ufn_t __kcfi_salt f ) { return f (); }
8180unsigned int ucall_salt_ty (ufn_salt_t f ) { return f (); }
8281
8382int test1 (struct cfi_struct * ptr ) {
@@ -115,21 +114,21 @@ int test1(struct cfi_struct *ptr) {
115114// CHECK-LABEL: define dso_local{{.*}} i32 @{{f1_salt|_Z7f1_saltv}}(){{.*}} !kcfi_type
116115// CHECK-SAME: ![[#SALTY_TYPE:]]
117116int f1 (void ) { return 0 ; }
118- int f1_salt (void ) __cfi_salt { return 0 ; }
117+ int f1_salt (void ) __kcfi_salt { return 0 ; }
119118
120119// CHECK-LABEL: define dso_local{{.*}} i32 @{{f2|_Z2f2v}}(){{.*}} !kcfi_type
121120// CHECK-SAME: ![[#LOW_SODIUM_UTYPE:]]
122121// CHECK: define dso_local{{.*}} i32 @{{f2_salt|_Z7f2_saltv}}(){{.*}} !kcfi_type
123122// CHECK-SAME: ![[#SALTY_UTYPE:]]
124123unsigned int f2 (void ) { return 2 ; }
125- unsigned int f2_salt (void ) __cfi_salt { return 2 ; }
124+ unsigned int f2_salt (void ) __kcfi_salt { return 2 ; }
126125
127126// CHECK-LABEL: define internal{{.*}} i32 @{{f3|_ZL2f3v}}(){{.*}} !kcfi_type
128127// CHECK-SAME: ![[#LOW_SODIUM_TYPE]]
129128// CHECK-LABEL: define internal{{.*}} i32 @{{f3_salt|_ZL7f3_saltv}}(){{.*}} !kcfi_type
130129// CHECK-SAME: ![[#SALTY_TYPE]]
131130static int f3 (void ) { return 1 ; }
132- static int f3_salt (void ) __cfi_salt { return 1 ; }
131+ static int f3_salt (void ) __kcfi_salt { return 1 ; }
133132
134133// CHECK: declare !kcfi_type ![[#LOW_SODIUM_TYPE]]{{.*}} i32 @[[F4]]()
135134// CHECK: declare !kcfi_type ![[#SALTY_TYPE]]{{.*}} i32 @[[F4_SALT]]()
@@ -142,7 +141,7 @@ static int f3_salt(void) __cfi_salt { return 1; }
142141// CHECK-NOT: !kcfi_type
143142// CHECK-SAME: {
144143static int f5 (void ) { return 2 ; }
145- static int f5_salt (void ) __cfi_salt { return 2 ; }
144+ static int f5_salt (void ) __kcfi_salt { return 2 ; }
146145
147146// CHECK: declare !kcfi_type ![[#LOW_SODIUM_TYPE]]{{.*}} i32 @{{f6|_Z2f6v}}()
148147// CHECK: declare !kcfi_type ![[#SALTY_TYPE]]{{.*}} i32 @{{f6_salt|_Z7f6_saltv}}()
@@ -154,29 +153,6 @@ static int f5_salt(void) __cfi_salt { return 2; }
154153int f7_salt (struct cfi_struct * ptr ) { return ptr -> fptr (); }
155154int f7_typedef_salt (struct cfi_struct * ptr ) { return ptr -> td_fptr (); }
156155
157- #ifdef __cplusplus
158- // MEMBER-LABEL: define dso_local void @_Z16test_member_callv() #0 !kcfi_type
159- // MEMBER: call void %[[#]](ptr{{.*}} [ "kcfi"(i32 [[#%d,MEMBER_LOW_SODIUM_HASH:]]) ]
160- // MEMBER: call void %[[#]](ptr{{.*}} [ "kcfi"(i32 [[#%d,MEMBER_SALT_HASH:]]) ]
161-
162- // MEMBER-LABEL: define{{.*}} void @_ZN1A1fEv(ptr{{.*}} %this){{.*}} !kcfi_type
163- // MEMBER-SAME: [[#MEMBER_LOW_SODIUM_TYPE:]]
164- // MEMBER-LABEL: define{{.*}} void @_ZN1A1gEv(ptr{{.*}} %this){{.*}} !kcfi_type
165- // MEMBER-SAME: [[#MEMBER_SALT_TYPE:]]
166- struct A {
167- void f () {}
168- void __cfi_salt g () {}
169- };
170-
171- void test_member_call (void ) {
172- void (A ::* p )() = & A ::f ;
173- (A ().* p )();
174-
175- void __cfi_salt (A ::* q )() = & A ::g ;
176- (A ().* q )();
177- }
178- #endif
179-
180156// CHECK: ![[#]] = !{i32 4, !"kcfi", i32 1}
181157// OFFSET: ![[#]] = !{i32 4, !"kcfi-offset", i32 3}
182158//
@@ -185,6 +161,3 @@ void test_member_call(void) {
185161//
186162// CHECK: ![[#LOW_SODIUM_UTYPE]] = !{i32 [[#LOW_SODIUM_UHASH]]}
187163// CHECK: ![[#SALTY_UTYPE]] = !{i32 [[#SALTY_UHASH]]}
188- //
189- // MEMBER: ![[#MEMBER_LOW_SODIUM_TYPE]] = !{i32 [[#MEMBER_LOW_SODIUM_HASH]]}
190- // MEMBER: ![[#MEMBER_SALT_TYPE]] = !{i32 [[#MEMBER_SALT_HASH]]}
0 commit comments