1// REQUIRES: x86
2// RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t.o
3// RUN: ld.lld --hash-style=sysv --shared -o %t.so %t.o
4// RUN: llvm-objdump -d %t.so | FileCheck %s --check-prefix=DISASM
5// RUN: llvm-readobj -r %t.so | FileCheck %s
6
7// Check that an IRELATIVE relocation is used for a non-preemptible ifunc
8// handler and a JUMP_SLOT is used for a preemptible ifunc
9// DISASM: Disassembly of section .text:
10// DISASM-NEXT: fct:
11// DISASM-NEXT:     1000:       c3      retq
12// DISASM:     fct2:
13// DISASM-NEXT:     1001:       c3      retq
14// DISASM:     f1:
15// DISASM-NEXT:     1002:       e8 49 00 00 00          callq   73
16// DISASM-NEXT:     1007:       e8 24 00 00 00          callq   36
17// DISASM-NEXT:     100c:       e8 2f 00 00 00          callq   47
18// DISASM-NEXT:     1011:       c3      retq
19// DISASM:     f2:
20// DISASM-NEXT:     1012:       c3      retq
21// DISASM-NEXT: Disassembly of section .plt:
22// DISASM-NEXT: .plt:
23// DISASM-NEXT:     1020:       ff 35 e2 0f 00 00       pushq   4066(%rip)
24// DISASM-NEXT:     1026:       ff 25 e4 0f 00 00       jmpq    *4068(%rip)
25// DISASM-NEXT:     102c:       0f 1f 40 00     nopl    (%rax)
26// DISASM-EMPTY:
27// DISASM-NEXT:   fct2@plt:
28// DISASM-NEXT:     1030:       ff 25 e2 0f 00 00       jmpq    *4066(%rip)
29// DISASM-NEXT:     1036:       68 00 00 00 00          pushq   $0
30// DISASM-NEXT:     103b:       e9 e0 ff ff ff          jmp     -32 <.plt>
31// DISASM-EMPTY:
32// DISASM-NEXT:   f2@plt:
33// DISASM-NEXT:     1040:       ff 25 da 0f 00 00       jmpq    *4058(%rip)
34// DISASM-NEXT:     1046:       68 01 00 00 00          pushq   $1
35// DISASM-NEXT:     104b:       e9 d0 ff ff ff          jmp     -48 <.plt>
36// DISASM-NEXT:     1050:       ff 25 d2 0f 00 00       jmpq    *4050(%rip)
37// DISASM-NEXT:     1056:       68 00 00 00 00          pushq   $0
38// DISASM-NEXT:     105b:       e9 e0 ff ff ff          jmp     -32 <f2@plt>
39
40// CHECK: Relocations [
41// CHECK-NEXT:   Section (4) .rela.plt {
42// CHECK-NEXT:     0x2018 R_X86_64_JUMP_SLOT fct2 0x0
43// CHECK-NEXT:     0x2020 R_X86_64_JUMP_SLOT f2 0x0
44// CHECK-NEXT:     0x2028 R_X86_64_IRELATIVE - 0x1000
45
46 // Hidden expect IRELATIVE
47 .globl fct
48 .hidden fct
49 .type  fct, STT_GNU_IFUNC
50fct:
51 ret
52
53 // Not hidden expect JUMP_SLOT
54 .globl fct2
55 .type  fct2, STT_GNU_IFUNC
56fct2:
57 ret
58
59 .globl f1
60 .type f1, @function
61f1:
62 call fct
63 call fct2
64 call f2@PLT
65 ret
66
67 .globl f2
68 .type f2, @function
69f2:
70 ret
71