Skip to content

Commit 93d2b23

Browse files
committed
[test] Improve ifunc tests
Add ifunc-after-resolver tests to inprove coverage and demonstrate the -fsanitize=kcfi issue reported at llvm#96400.
1 parent 27f5c00 commit 93d2b23

File tree

2 files changed

+29
-11
lines changed

2 files changed

+29
-11
lines changed

clang/test/CodeGen/ifunc.c

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,12 @@
77
// RUN: %clang_cc1 -triple x86_64-apple-macosx -emit-llvm -o - %s | FileCheck %s
88
// RUN: %clang_cc1 -triple arm64-apple-macosx -O2 -emit-llvm -o - %s | FileCheck %s
99
// RUN: %clang_cc1 -triple x86_64-apple-macosx -O2 -emit-llvm -o - %s | FileCheck %s
10-
// RUN: %clang_cc1 -triple arm64-apple-macosx -fsanitize=thread -O2 -emit-llvm -o - %s | FileCheck %s --check-prefix=MACSAN
11-
// RUN: %clang_cc1 -triple x86_64-apple-macosx -fsanitize=thread -O2 -emit-llvm -o - %s | FileCheck %s --check-prefix=MACSAN
12-
// RUN: %clang_cc1 -triple arm64-apple-macosx -fsanitize=address -O2 -emit-llvm -o - %s | FileCheck %s --check-prefix=MACSAN
13-
// RUN: %clang_cc1 -triple x86_64-apple-macosx -fsanitize=address -O2 -emit-llvm -o - %s | FileCheck %s --check-prefix=MACSAN
10+
// RUN: %clang_cc1 -triple arm64-apple-macosx -fsanitize=thread -O2 -emit-llvm -o - %s | FileCheck %s --check-prefix=SAN
11+
// RUN: %clang_cc1 -triple x86_64-apple-macosx -fsanitize=thread -O2 -emit-llvm -o - %s | FileCheck %s --check-prefix=SAN
12+
// RUN: %clang_cc1 -triple arm64-apple-macosx -fsanitize=address -O2 -emit-llvm -o - %s | FileCheck %s --check-prefix=SAN
13+
// RUN: %clang_cc1 -triple x86_64-apple-macosx -fsanitize=address -O2 -emit-llvm -o - %s | FileCheck %s --check-prefix=SAN
1414

15+
/// The ifunc is emitted before its resolver.
1516
int foo(int) __attribute__ ((ifunc("foo_ifunc")));
1617

1718
static int f1(int i) {
@@ -45,20 +46,24 @@ extern void goo(void) __attribute__ ((ifunc("goo_ifunc")));
4546
void* goo_ifunc(void) {
4647
return 0;
4748
}
49+
50+
/// The ifunc is emitted after its resolver.
51+
void *hoo_ifunc(void) { return 0; }
52+
extern void hoo(int) __attribute__ ((ifunc("hoo_ifunc")));
53+
4854
// CHECK: @foo = ifunc i32 (i32), ptr @foo_ifunc
4955
// CHECK: @goo = ifunc void (), ptr @goo_ifunc
56+
// CHECK: @hoo = ifunc void (i32), ptr @hoo_ifunc
5057

5158
// CHECK: call i32 @foo(i32
5259
// CHECK: call void @goo()
5360

5461
// SAN: define internal nonnull {{(noundef )?}}ptr @foo_ifunc() #[[#FOO_IFUNC:]] {
55-
// MACSAN: define internal nonnull {{(noundef )?}}ptr @foo_ifunc() #[[#FOO_IFUNC:]] {
5662

57-
// SAN: define dso_local noalias {{(noundef )?}}ptr @goo_ifunc() #[[#GOO_IFUNC:]] {
58-
// MACSAN: define noalias {{(noundef )?}}ptr @goo_ifunc() #[[#GOO_IFUNC:]] {
63+
// SAN: define {{(dso_local )?}}noalias {{(noundef )?}}ptr @goo_ifunc() #[[#GOO_IFUNC:]] {
5964

60-
// SAN-DAG: attributes #[[#FOO_IFUNC]] = {{{.*}} disable_sanitizer_instrumentation {{.*}}
61-
// MACSAN-DAG: attributes #[[#FOO_IFUNC]] = {{{.*}} disable_sanitizer_instrumentation {{.*}}
65+
// SAN: define {{(dso_local )?}}noalias {{(noundef )?}}ptr @hoo_ifunc() #[[#HOO_IFUNC:]] {
6266

67+
// SAN-DAG: attributes #[[#FOO_IFUNC]] = {{{.*}} disable_sanitizer_instrumentation {{.*}}
6368
// SAN-DAG: attributes #[[#GOO_IFUNC]] = {{{.*}} disable_sanitizer_instrumentation {{.*}}
64-
// MACSAN-DAG: attributes #[[#GOO_IFUNC]] = {{{.*}} disable_sanitizer_instrumentation {{.*}}
69+
// SAN-DAG: attributes #[[#HOO_IFUNC]] = {{{.*}} disable_sanitizer_instrumentation {{.*}}

clang/test/CodeGen/kcfi.c

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -emit-llvm -fsanitize=kcfi -o - %s | FileCheck %s
1+
// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -emit-llvm -fsanitize=kcfi -o - %s | FileCheck %s --check-prefixes=CHECK,C
22
// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -emit-llvm -fsanitize=kcfi -x c++ -o - %s | FileCheck %s --check-prefixes=CHECK,MEMBER
33
// 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
44
#if !__has_feature(kcfi)
@@ -10,6 +10,9 @@
1010
// CHECK: module asm ".set __kcfi_typeid_[[F4]], [[#%d,HASH:]]"
1111
/// Must not __kcfi_typeid symbols for non-address-taken declarations
1212
// CHECK-NOT: module asm ".weak __kcfi_typeid_{{f6|_Z2f6v}}"
13+
14+
// C: @ifunc1 = ifunc i32 (i32), ptr @resolver1
15+
// C: @ifunc2 = ifunc i64 (i64), ptr @resolver2
1316
typedef int (*fn_t)(void);
1417

1518
// CHECK: define dso_local{{.*}} i32 @{{f1|_Z2f1v}}(){{.*}} !kcfi_type ![[#TYPE:]]
@@ -30,6 +33,16 @@ int call(fn_t f) {
3033
return f();
3134
}
3235

36+
#ifndef __cplusplus
37+
// C: define internal ptr @resolver1() #[[#]] {
38+
int ifunc1(int) __attribute__((ifunc("resolver1")));
39+
static void *resolver1(void) { return 0; }
40+
41+
// C: define internal ptr @resolver2() #[[#]] {
42+
static void *resolver2(void) { return 0; }
43+
long ifunc2(long) __attribute__((ifunc("resolver2")));
44+
#endif
45+
3346
// CHECK-DAG: define internal{{.*}} i32 @{{f3|_ZL2f3v}}(){{.*}} !kcfi_type ![[#TYPE]]
3447
static int f3(void) { return 1; }
3548

0 commit comments

Comments
 (0)