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
19static void foo() { printf(format: "foo\n"); }
20
21static void *resolver_foo(void) { return foo; }
22
23__attribute__((ifunc("resolver_foo"))) void ifoo();
24
25static void *resolver_memcpy(void) { return memcpy; }
26
27__attribute__((ifunc("resolver_memcpy"))) void *
28imemcpy(void *dest, const void *src, size_t n);
29
30int main() {
31 int a = 0xdeadbeef, b = 0;
32 imemcpy(dest: &b, src: &a, n: sizeof(b));
33 if (a != b)
34 return -1;
35
36 ifoo();
37}
38

source code of bolt/test/runtime/iplt.c