Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / lld / test / ELF / i386-plt.s
blob0f15aead2e5ab80a4c76d9f1fb643c65062b7560
1 // REQUIRES: x86
2 // RUN: llvm-mc -filetype=obj -triple=i686-unknown-linux %s -o %t.o
3 // RUN: llvm-mc -filetype=obj -triple=i686-unknown-linux %p/Inputs/shared.s -o %t2.o
4 // RUN: ld.lld -shared %t2.o -soname=t2.so -o %t2.so
5 // RUN: ld.lld %t.o %t2.so -o %t
6 // RUN: llvm-readobj -S -r %t | FileCheck %s
7 // RUN: llvm-objdump -d --no-show-raw-insn --print-imm-hex %t | FileCheck --check-prefix=DISASM %s
8 // RUN: ld.lld -shared %t.o %t2.so -o %t
9 // RUN: llvm-readobj -S -r %t | FileCheck --check-prefix=CHECKSHARED %s
10 // RUN: llvm-objdump --no-print-imm-hex -d --no-show-raw-insn %t | FileCheck --check-prefix=DISASMSHARED %s
11 // RUN: ld.lld -pie %t.o %t2.so -o %t
12 // RUN: llvm-objdump --no-print-imm-hex -d --no-show-raw-insn %t | FileCheck --check-prefix=DISASMPIE %s
14 // CHECK: Name: .plt
15 // CHECK-NEXT: Type: SHT_PROGBITS
16 // CHECK-NEXT: Flags [
17 // CHECK-NEXT: SHF_ALLOC
18 // CHECK-NEXT: SHF_EXECINSTR
19 // CHECK-NEXT: ]
20 // CHECK-NEXT: Address: 0x4011E0
21 // CHECK-NEXT: Offset:
22 // CHECK-NEXT: Size: 48
23 // CHECK-NEXT: Link: 0
24 // CHECK-NEXT: Info: 0
25 // CHECK-NEXT: AddressAlignment: 16
27 // CHECK: Name: .got.plt
28 // CHECK-NEXT: Type: SHT_PROGBITS
29 // CHECK-NEXT: Flags [
30 // CHECK-NEXT: SHF_ALLOC
31 // CHECK-NEXT: SHF_WRITE
32 // CHECK-NEXT: ]
33 // CHECK-NEXT: Address: 0x403278
34 // CHECK-NEXT: Offset: 0x278
35 // CHECK-NEXT: Size: 20
36 // CHECK-NEXT: Link: 0
37 // CHECK-NEXT: Info: 0
38 // CHECK-NEXT: AddressAlignment: 4
39 // CHECK-NEXT: EntrySize: 0
41 // First 3 slots of .got.plt are reserved.
42 // &.got.plt[3] = 0x403278 + 12 = 0x403284
43 // &.got.plt[4] = 0x403278 + 16 = 0x403288
44 // CHECK: Relocations [
45 // CHECK-NEXT: Section ({{.*}}) .rel.plt {
46 // CHECK-NEXT: 0x403284 R_386_JUMP_SLOT bar
47 // CHECK-NEXT: 0x403288 R_386_JUMP_SLOT zed
48 // CHECK-NEXT: }
49 // CHECK-NEXT: ]
51 // DISASM: <local>:
52 // DISASM-NEXT: 4011bc:
53 // DISASM-NEXT: 4011be:
54 // DISASM: <_start>:
55 // DISASM-NEXT: 4011c0: jmp 0x4011f0 <bar@plt>
56 // DISASM-NEXT: 4011c5: jmp 0x4011f0 <bar@plt>
57 // DISASM-NEXT: 4011ca: jmp 0x401200 <zed@plt>
58 // DISASM-NEXT: 4011cf: jmp 0x4011bc <local>
60 // DISASM: Disassembly of section .plt:
61 // DISASM-EMPTY:
62 // DISASM-NEXT: <.plt>:
63 /// Push .got.plt[1], then jump to .got.plt[2]
64 // DISASM-NEXT: 4011e0: pushl 0x40327c
65 // DISASM-NEXT: jmpl *0x403280
66 // DISASM-NEXT: nop
67 // DISASM-NEXT: nop
68 // DISASM-NEXT: nop
69 // DISASM-NEXT: nop
70 // DISASM-EMPTY:
71 // DISASM-NEXT: <bar@plt>:
72 /// .got.plt[3] = 0x403278 + 12 = 0x403284
73 // DISASM-NEXT: 4011f0: jmpl *0x403284
74 // DISASM-NEXT: pushl $0x0
75 // DISASM-NEXT: jmp 0x4011e0 <.plt>
76 // DISASM-EMPTY:
77 // DISASM-NEXT: <zed@plt>:
78 /// .got.plt[4] = 0x403278 + 16 = 0x403288
79 // DISASM-NEXT: 401200: jmpl *0x403288
80 // DISASM-NEXT: pushl $0x8
81 // DISASM-NEXT: jmp 0x4011e0 <.plt>
83 // CHECKSHARED: Name: .plt
84 // CHECKSHARED-NEXT: Type: SHT_PROGBITS
85 // CHECKSHARED-NEXT: Flags [
86 // CHECKSHARED-NEXT: SHF_ALLOC
87 // CHECKSHARED-NEXT: SHF_EXECINSTR
88 // CHECKSHARED-NEXT: ]
89 // CHECKSHARED-NEXT: Address: 0x1200
90 // CHECKSHARED-NEXT: Offset: 0x200
91 // CHECKSHARED-NEXT: Size: 48
92 // CHECKSHARED-NEXT: Link: 0
93 // CHECKSHARED-NEXT: Info: 0
94 // CHECKSHARED-NEXT: AddressAlignment: 16
95 // CHECKSHARED-NEXT: EntrySize: 0
96 // CHECKSHARED-NEXT: }
97 // CHECKSHARED: Name: .got.plt
98 // CHECKSHARED-NEXT: Type: SHT_PROGBITS
99 // CHECKSHARED-NEXT: Flags [
100 // CHECKSHARED-NEXT: SHF_ALLOC
101 // CHECKSHARED-NEXT: SHF_WRITE
102 // CHECKSHARED-NEXT: ]
103 // CHECKSHARED-NEXT: Address: 0x3290
104 // CHECKSHARED-NEXT: Offset: 0x290
105 // CHECKSHARED-NEXT: Size: 20
106 // CHECKSHARED-NEXT: Link: 0
107 // CHECKSHARED-NEXT: Info: 0
108 // CHECKSHARED-NEXT: AddressAlignment: 4
109 // CHECKSHARED-NEXT: EntrySize: 0
110 // CHECKSHARED-NEXT: }
112 // 0x3000 + got.plt.reserved(12) = 0x300C
113 // 0x3000 + got.plt.reserved(12) + 4 = 0x3010
114 // CHECKSHARED: Relocations [
115 // CHECKSHARED-NEXT: Section ({{.*}}) .rel.plt {
116 // CHECKSHARED-NEXT: 0x329C R_386_JUMP_SLOT bar
117 // CHECKSHARED-NEXT: 0x32A0 R_386_JUMP_SLOT zed
118 // CHECKSHARED-NEXT: }
119 // CHECKSHARED-NEXT: ]
121 // DISASMSHARED: <local>:
122 // DISASMSHARED-NEXT: 11e0:
123 // DISASMSHARED-NEXT: 11e2:
124 // DISASMSHARED: <_start>:
125 // DISASMSHARED-NEXT: 11e4: jmp 0x1210 <bar@plt>
126 // DISASMSHARED-NEXT: jmp 0x1210 <bar@plt>
127 // DISASMSHARED-NEXT: jmp 0x1220 <zed@plt>
128 // DISASMSHARED-NEXT: jmp 0x11e0 <local>
129 // DISASMSHARED-EMPTY:
130 // DISASMSHARED-NEXT: Disassembly of section .plt:
131 // DISASMSHARED-EMPTY:
132 // DISASMSHARED-NEXT: <.plt>:
133 // DISASMSHARED-NEXT: 1200: pushl 4(%ebx)
134 // DISASMSHARED-NEXT: jmpl *8(%ebx)
135 // DISASMSHARED-NEXT: nop
136 // DISASMSHARED-NEXT: nop
137 // DISASMSHARED-NEXT: nop
138 // DISASMSHARED-NEXT: nop
139 // DISASMSHARED: <bar@plt>:
140 // DISASMSHARED-NEXT: 1210: jmpl *12(%ebx)
141 // DISASMSHARED-NEXT: pushl $0
142 // DISASMSHARED-NEXT: jmp 0x1200 <.plt>
143 // DISASMSHARED: <zed@plt>:
144 // DISASMSHARED-NEXT: 1220: jmpl *16(%ebx)
145 // DISASMSHARED-NEXT: pushl $8
146 // DISASMSHARED-NEXT: jmp 0x1200 <.plt>
148 // DISASMPIE: Disassembly of section .plt:
149 // DISASMPIE-EMPTY:
150 // DISASMPIE-NEXT: <.plt>:
151 // DISASMPIE-NEXT: 11e0: pushl 4(%ebx)
152 // DISASMPIE-NEXT: jmpl *8(%ebx)
153 // DISASMPIE-NEXT: nop
154 // DISASMPIE-NEXT: nop
155 // DISASMPIE-NEXT: nop
156 // DISASMPIE-NEXT: nop
157 // DISASMPIE-EMPTY:
158 // DISASMPIE-NEXT: <bar@plt>:
159 // DISASMPIE-NEXT: 11f0: jmpl *12(%ebx)
160 // DISASMPIE-NEXT: pushl $0
161 // DISASMPIE-NEXT: jmp 0x11e0 <.plt>
162 // DISASMPIE-EMPTY:
163 // DISASMPIE-NEXT: <zed@plt>:
164 // DISASMPIE-NEXT: 1200: jmpl *16(%ebx)
165 // DISASMPIE-NEXT: pushl $8
166 // DISASMPIE-NEXT: jmp 0x11e0 <.plt>
168 local:
169 .long 0
171 .global _start
172 _start:
173 jmp bar@PLT
174 jmp bar@PLT
175 jmp zed@PLT
176 jmp local@plt