xref: /llvm-project/lld/test/ELF/gnu-ifunc-nonpreemptible.s (revision 93c16e75b8935f6a3f5f39301007f9a42a1f7da1)
1# REQUIRES: x86
2# RUN: rm -rf %t && split-file %s %t && cd %t
3# RUN: llvm-mc -filetype=obj -triple=x86_64 a.s -o a.o
4# RUN: llvm-mc -filetype=obj -triple=x86_64 b.s -o b.o
5# RUN: ld.lld -shared -soname=b.so b.o -o b.so
6
7# RUN: ld.lld a.o -o a
8# RUN: llvm-objdump --no-print-imm-hex -d --no-show-raw-insn a | FileCheck %s --check-prefix=DISASM
9# RUN: llvm-readelf -r -s a | FileCheck %s
10
11# CHECK:      Relocation section '.rela.dyn' at offset {{.*}} contains 3 entries:
12# CHECK-NEXT:     Type
13# CHECK-NEXT: {{0*}}[[#%x,O:]] [[#%x,]] R_X86_64_IRELATIVE  [[#%x,QUX:]]
14# CHECK-NEXT: {{0*}}[[#O+8]]   [[#%x,]] R_X86_64_IRELATIVE
15# CHECK-NEXT: {{0*}}[[#O+16]]  [[#%x,]] R_X86_64_IRELATIVE
16
17# CHECK:                      0 NOTYPE  LOCAL  HIDDEN     [[#]] __rela_iplt_start
18# CHECK-NEXT:                 0 NOTYPE  LOCAL  HIDDEN     [[#]] __rela_iplt_end
19# CHECK-NEXT: {{0*}}[[#QUX]]  0 IFUNC   GLOBAL DEFAULT    [[#]] qux
20
21# RUN: ld.lld -pie a.o b.so -o a1
22# RUN: llvm-readelf -rs a1 | FileCheck %s --check-prefixes=PIC,PIE
23# RUN: ld.lld -shared a.o b.so -o a2
24# RUN: llvm-readelf -rs a2 | FileCheck %s --check-prefix=PIC
25
26# PIC:      {{0*}}[[#%x,O:]] [[#%x,]] R_X86_64_RELATIVE
27# PIC-NEXT:                           R_X86_64_GLOB_DAT      0000000000000000 ext + 0
28# PIC-NEXT: {{0*}}[[#O-16]]  [[#%x,]] R_X86_64_64            0000000000000000 __rela_iplt_start + 0
29# PIC-NEXT: {{0*}}[[#O-8]]   [[#%x,]] R_X86_64_64            0000000000000000 __rela_iplt_end + 0
30# PIE-NEXT: {{0*}}[[#O+8]]   [[#%x,]] R_X86_64_IRELATIVE
31# PIE-NEXT: {{0*}}[[#O+16]]  [[#%x,]] R_X86_64_IRELATIVE
32# PIE-NEXT: {{0*}}[[#O+24]]  [[#%x,]] R_X86_64_IRELATIVE
33
34# PIC:        0 NOTYPE  WEAK   DEFAULT    UND __rela_iplt_start
35# PIC-NEXT:   0 NOTYPE  WEAK   DEFAULT    UND __rela_iplt_end
36
37# DISASM: Disassembly of section .text:
38# DISASM-EMPTY:
39# DISASM-NEXT: <qux>:
40# DISASM:      <foo>:
41# DISASM:      <bar>:
42# DISASM:      <unused>:
43# DISASM:      <_start>:
44# DISASM-NEXT:   callq 0x[[#%x,foo:]]
45# DISASM-NEXT:   callq 0x[[#%x,bar:]]
46# DISASM-NEXT:   callq 0x[[#%x,qux:]]
47# DISASM-EMPTY:
48# DISASM-NEXT: Disassembly of section .iplt:
49# DISASM-EMPTY:
50# DISASM-NEXT: <.iplt>:
51# DISASM-NEXT:  [[#qux]]: jmpq *{{.*}}(%rip)
52# DISASM-NEXT:            pushq $0
53# DISASM-NEXT:            jmp 0x0
54# DISASM-NEXT:  [[#foo]]: jmpq *{{.*}}(%rip)
55# DISASM-NEXT:            pushq $1
56# DISASM-NEXT:            jmp 0x0
57# DISASM-NEXT:  [[#bar]]: jmpq *{{.*}}(%rip)
58# DISASM-NEXT:            pushq $2
59# DISASM-NEXT:            jmp 0x0
60
61#--- a.s
62.globl qux, foo, bar
63.type qux, @gnu_indirect_function
64.type foo STT_GNU_IFUNC
65.type bar STT_GNU_IFUNC
66qux: ret
67foo: ret
68bar: ret
69
70.type unused, @gnu_indirect_function
71.globl unused
72.weak ext
73unused: mov ext@gotpcrel(%rip), %rax
74
75.weak __rela_iplt_start
76.weak __rela_iplt_end
77
78.globl _start
79_start:
80 call foo
81 call bar
82 call qux
83
84.data
85  .quad __rela_iplt_start
86  .quad __rela_iplt_end
87  .quad .data
88
89#--- b.s
90.globl ext
91ext:
92  ret
93