Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / lld / test / ELF / ppc64-ifunc.s
blobd024c5d5e36c4fb9cd22d004485befc6f3f0fe7e
1 # REQUIRES: ppc
3 # RUN: llvm-mc -filetype=obj -triple=powerpc64le-unknown-linux %s -o %t.o
4 # RUN: ld.lld %t.o -o %t
5 # RUN: llvm-readelf -s %t | FileCheck --check-prefix=SYM %s
6 # RUN: llvm-readelf -S %t | FileCheck --check-prefix=SECTIONS %s
7 # RUN: llvm-objdump -d --no-show-raw-insn %t | FileCheck %s
8 # RUN: llvm-readobj -r %t | FileCheck --check-prefix=REL %s
10 # RUN: llvm-mc -filetype=obj -triple=powerpc64-unknown-linux %s -o %t.o
11 ## IRELATIVE relocs relocating NOBITS .plt do not cause --check-dynamic-relocations errors.
12 # RUN: ld.lld %t.o -o %t --apply-dynamic-relocs --check-dynamic-relocations
13 # RUN: llvm-readelf -s %t | FileCheck --check-prefix=SYM %s
14 # RUN: llvm-readelf -S %t | FileCheck --check-prefix=SECTIONS %s
15 # RUN: llvm-objdump -d --no-show-raw-insn %t | FileCheck %s
16 # RUN: llvm-readobj -r %t | FileCheck --check-prefix=REL %s
18 # SYM: Value Size Type Bind Vis Ndx
19 # SYM: 0000000010028298 0 NOTYPE LOCAL HIDDEN 4 .TOC.
20 # SYM: 0000000010010268 0 FUNC GLOBAL DEFAULT 3 ifunc1
21 # SYM: 0000000010010210 0 IFUNC GLOBAL DEFAULT 2 ifunc2
22 # SYM: 0000000010010288 0 FUNC GLOBAL DEFAULT 3 ifunc3
24 # SECTIONS: .plt NOBITS 00000000100302a0 0002a0 000018 00 WA 0 0 8
26 # __plt_ifunc - . = 0x10010218 - 0x10010208 = 16
27 # __plt_ifunc2 - . = 0x1001022c - 0x10010210 = 28
28 # CHECK: <_start>:
29 # CHECK-NEXT: addis 2, 12, 2
30 # CHECK-NEXT: addi 2, 2, -32636
31 # CHECK-NEXT: 1001021c: bl 0x10010240
32 # CHECK-NEXT: ld 2, 24(1)
33 # CHECK-NEXT: 10010224: bl 0x10010254
34 # CHECK-NEXT: ld 2, 24(1)
35 # CHECK-NEXT: addis 3, 2, -2
36 # CHECK-NEXT: addi 3, 3, 32720
37 # CHECK-NEXT: addis 3, 2, -2
38 # CHECK-NEXT: addi 3, 3, 32752
40 # .plt[1] - .TOC. = 0x100302a0+8 - 0x10028298 = (1<<16) - 32752
41 # CHECK: <__plt_ifunc2>:
42 # CHECK-NEXT: std 2, 24(1)
43 # CHECK-NEXT: addis 12, 2, 1
44 # CHECK-NEXT: ld 12, -32752(12)
45 # CHECK-NEXT: mtctr 12
46 # CHECK-NEXT: bctr
48 # .plt[2] - .TOC. = 0x100302a0+16 - 0x10028298 = (1<<16) - 32744
49 # CHECK: <__plt_ifunc3>:
50 # CHECK-NEXT: std 2, 24(1)
51 # CHECK-NEXT: addis 12, 2, 1
52 # CHECK-NEXT: ld 12, -32744(12)
53 # CHECK-NEXT: mtctr 12
54 # CHECK-NEXT: bctr
55 # CHECK-EMPTY:
57 ## .glink has 3 IPLT entries for ifunc1, ifunc2 and ifunc3.
58 ## ifunc2 and ifunc3 have the same code sequence as their PLT call stubs.
59 # CHECK: Disassembly of section .glink:
60 # CHECK-EMPTY:
61 # CHECK-NEXT: 0000000010010268 <ifunc1>:
62 # CHECK-NEXT: addis 12, 2, 1
63 # CHECK-NEXT: ld 12, -32760(12)
64 # CHECK-NEXT: mtctr 12
65 # CHECK-NEXT: bctr
66 # CHECK-NEXT: addis 12, 2, 1
67 # CHECK-NEXT: ld 12, -32752(12)
68 # CHECK-NEXT: mtctr 12
69 # CHECK-NEXT: bctr
70 # CHECK-EMPTY:
71 # CHECK-NEXT: 0000000010010288 <ifunc3>:
72 # CHECK-NEXT: addis 12, 2, 1
73 # CHECK-NEXT: ld 12, -32744(12)
74 # CHECK-NEXT: mtctr 12
75 # CHECK-NEXT: bctr
77 ## Check that we emit 3 R_PPC64_IRELATIVE in .rela.dyn.
78 # REL: .rela.dyn {
79 # REL-NEXT: 0x100302A0 R_PPC64_IRELATIVE - 0x10010210
80 # REL-NEXT: 0x100302A8 R_PPC64_IRELATIVE - 0x10010210
81 # REL-NEXT: 0x100302B0 R_PPC64_IRELATIVE - 0x10010210
82 # REL-NEXT: }
84 .type ifunc1,@gnu_indirect_function
85 .type ifunc2,@gnu_indirect_function
86 .type ifunc3,@gnu_indirect_function
87 .globl ifunc1, ifunc2, ifunc3
88 ifunc1:
89 ifunc2:
90 ifunc3:
91 blr
93 .global _start
94 .type _start,@function
96 _start:
97 .Lfunc_gep0:
98 addis 2, 12, .TOC.-.Lfunc_gep0@ha
99 addi 2, 2, .TOC.-.Lfunc_gep0@l
100 .Lfunc_lep0:
101 .localentry _start, .Lfunc_lep0-.Lfunc_gep0
103 ## ifunc1 is taken address.
104 ## ifunc2 is called.
105 ## ifunc3 is both taken address and called.
106 ## We need to create IPLT entries in .glink for ifunc1 and ifunc3, change
107 ## their types from STT_GNU_IFUNC to STT_FUNC, and set their st_shndx/st_value
108 ## to their .glink entries. Technically we don't need an entry for ifunc2 in
109 ## .glink, but we currently do that.
110 bl ifunc2
112 bl ifunc3
115 addis 3, 2, ifunc1@toc@ha
116 addi 3, 3, ifunc1@toc@l
117 addis 3, 2, ifunc3@toc@ha
118 addi 3, 3, ifunc3@toc@l