1// This test checks that IFUNC trampoline is properly recognised by BOLT
2
3// With -O0 indirect call is performed on IPLT trampoline. IPLT trampoline
4// has IFUNC symbol.
5// RUN: %clang %cflags -nostdlib -O0 -no-pie %s -fuse-ld=lld \
6// RUN: -o %t.O0.exe -Wl,-q
7// RUN: llvm-bolt %t.O0.exe -o %t.O0.bolt.exe \
8// RUN: --print-disasm --print-only=_start | \
9// RUN: FileCheck --check-prefix=CHECK %s
10// RUN: llvm-readelf -aW %t.O0.bolt.exe | \
11// RUN: FileCheck --check-prefix=REL_CHECK %s
12
13// Non-pie static executable doesn't generate PT_DYNAMIC, check relocation
14// is readed successfully and IPLT trampoline has been identified by bolt.
15// RUN: %clang %cflags -nostdlib -O3 %s -fuse-ld=lld -no-pie \
16// RUN: -o %t.O3_nopie.exe -Wl,-q
17// RUN: llvm-readelf -l %t.O3_nopie.exe | \
18// RUN: FileCheck --check-prefix=NON_DYN_CHECK %s
19// RUN: llvm-bolt %t.O3_nopie.exe -o %t.O3_nopie.bolt.exe \
20// RUN: --print-disasm --print-only=_start | \
21// RUN: FileCheck --check-prefix=CHECK %s
22// RUN: llvm-readelf -aW %t.O3_nopie.bolt.exe | \
23// RUN: FileCheck --check-prefix=REL_CHECK %s
24
25// With -O3 direct call is performed on IPLT trampoline. IPLT trampoline
26// doesn't have associated symbol. The ifunc symbol has the same address as
27// IFUNC resolver function.
28// RUN: %clang %cflags -nostdlib -O3 %s -fuse-ld=lld -fPIC -pie \
29// RUN: -o %t.O3_pie.exe -Wl,-q
30// RUN: llvm-bolt %t.O3_pie.exe -o %t.O3_pie.bolt.exe \
31// RUN: --print-disasm --print-only=_start | \
32// RUN: FileCheck --check-prefix=CHECK %s
33// RUN: llvm-readelf -aW %t.O3_pie.bolt.exe | \
34// RUN: FileCheck --check-prefix=REL_CHECK %s
35
36// Check that IPLT trampoline located in .plt section are normally handled by
37// BOLT. The gnu-ld linker doesn't use separate .iplt section.
38// RUN: %clang %cflags -nostdlib -O3 %s -fuse-ld=lld -fPIC -pie \
39// RUN: -T %p/Inputs/iplt.ld -o %t.iplt_O3_pie.exe -Wl,-q
40// RUN: llvm-bolt %t.iplt_O3_pie.exe -o %t.iplt_O3_pie.bolt.exe \
41// RUN: --print-disasm --print-only=_start | \
42// RUN: FileCheck --check-prefix=CHECK %s
43// RUN: llvm-readelf -aW %t.iplt_O3_pie.bolt.exe | \
44// RUN: FileCheck --check-prefix=REL_CHECK %s
45
46// NON_DYN_CHECK-NOT: DYNAMIC
47
48// CHECK: {{(bl? "(resolver_foo|ifoo).*@PLT"|adr x[0-9]+, ifoo)}}
49
50// REL_CHECK: R_AARCH64_IRELATIVE [[#%x,REL_SYMB_ADDR:]]
51// REL_CHECK: [[#REL_SYMB_ADDR]] {{.*}} FUNC {{.*}} resolver_foo
52
53static void foo() {}
54static void bar() {}
55
56extern int use_foo;
57
58static void *resolver_foo(void) { return use_foo ? foo : bar; }
59
60__attribute__((ifunc("resolver_foo"))) void ifoo();
61
62void _start() { ifoo(); }
63

source code of bolt/test/AArch64/ifunc.c