1 // This test checks that the ifuncs works after bolt.
2 // Compiling with 00 results in IFUNC indirect calling.
3
4 // RUN: %clang %cflags -O0 -no-pie %s -fuse-ld=lld \
5 // RUN: -o %t.exe -Wl,-q
6 // RUN: llvm-bolt %t.exe -o %t.bolt.exe --use-old-text=0 --lite=0
7 // RUN: %t.bolt.exe | FileCheck %s
8
9 // RUN: %clang %cflags -O3 -no-pie %s -fuse-ld=lld \
10 // RUN: -o %t.O3.exe -Wl,-q
11 // RUN: llvm-bolt %t.O3.exe -o %t.O3.bolt.exe --use-old-text=0 --lite=0
12 // RUN: %t.O3.bolt.exe | FileCheck %s
13
14 // CHECK: foo
15
16 #include <stdio.h>
17 #include <string.h>
18
foo()19 static void foo() { printf("foo\n"); }
20
resolver_foo(void)21 static void *resolver_foo(void) { return foo; }
22
23 __attribute__((ifunc("resolver_foo"))) void ifoo();
24
resolver_memcpy(void)25 static void *resolver_memcpy(void) { return memcpy; }
26
27 __attribute__((ifunc("resolver_memcpy"))) void *
28 imemcpy(void *dest, const void *src, size_t n);
29
main()30 int main() {
31 int a = 0xdeadbeef, b = 0;
32 imemcpy(&b, &a, sizeof(b));
33 if (a != b)
34 return -1;
35
36 ifoo();
37 }
38