llvm.org GIT mirror llvm / f5ba24d
[mips] Correct jal expansion for local symbols in .local directives. This patch corrects the behaviour of code such as: .local foo jal foo foo: to use the correct jal expansion when writing ELF files. Patch by: Daniel Sanders Reviewers: zoran.jovanovic, seanbruno, vkalintiris Differential Revision: https://reviews.llvm.org/D24722 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@287918 91177308-0d34-0410-b5e6-96231b3b80d8 Simon Dardis 2 years ago
2 changed file(s) with 131 addition(s) and 31 deletion(s). Raw diff Collapse all Expand all
18051805 // FIXME: Add support for label+offset operands (currently causes an error).
18061806 // FIXME: Add support for forward-declared local symbols.
18071807 // FIXME: Add expansion for when the LargeGOT option is enabled.
1808 if (JalSym->isInSection() || JalSym->isTemporary()) {
1808 if (JalSym->isInSection() || JalSym->isTemporary() ||
1809 (JalSym->isELF() && cast(JalSym)->getBinding() == ELF::STB_LOCAL)) {
18091810 if (isABI_O32()) {
18101811 // If it's a local symbol and the O32 ABI is being used, we expand to:
18111812 // lw $25, 0($gp)
1414
1515 # RUN: llvm-mc %s -arch=mips64 -mcpu=mips64 -target-abi n64 -mattr=micromips -show-encoding |\
1616 # RUN: FileCheck %s -check-prefixes=ALL,MICROMIPS,N64-MICROMIPS
17
18 # Repeat the tests but using ELF output. An initial version of this patch did
19 # this as the output different depending on whether it went through
20 # MCAsmStreamer or MCELFStreamer. This ensures that the assembly expansion and
21 # direct objection emission match.
22
23 # RUN: llvm-mc %s -arch=mips -mcpu=mips32 -filetype=obj | \
24 # RUN: llvm-objdump -d -r - | FileCheck %s -check-prefixes=ELF-O32
25 # RUN: llvm-mc %s -arch=mips64 -mcpu=mips64 -target-abi n32 -filetype=obj | \
26 # RUN: llvm-objdump -d -r - | FileCheck %s -check-prefixes=ELF-N32
27 # RUN: llvm-mc %s -arch=mips64 -mcpu=mips64 -target-abi n64 -filetype=obj | \
28 # RUN: llvm-objdump -d -r - | FileCheck %s -check-prefixes=ELF-N64
1729
1830 .weak weak_label
1931
2638 .set noreorder
2739
2840 jal local_label
29 nop
30
31 jal weak_label
32 nop
33
34 jal global_label
35 nop
36
37 jal .text
38 nop
39
40 # local labels ($tmp symbols)
41 jal 1f
42 nop
43
44 .end local_label
45
46 1:
47 nop
48 add $8, $8, $8
4941 nop
5042
5143 # Expanding "jal local_label":
5345 # O32: # fixup A - offset: 0, value: %got(local_label), kind: fixup_Mips_GOT
5446 # O32: addiu $25, $25, %lo(local_label) # encoding: [0x27,0x39,A,A]
5547 # O32: # fixup A - offset: 0, value: %lo(local_label), kind: fixup_Mips_LO16
48 # ELF-O32: 8f 99 00 00 lw $25, 0($gp)
49 # ELF-O32-NEXT: R_MIPS_GOT16 .text
50 # ELF-O32-NEXT: 27 39 00 00 addiu $25, $25, 0
51 # ELF-O32-NEXT: R_MIPS_LO16 .text
5652
5753 # N32: lw $25, %got_disp(local_label)($gp) # encoding: [0x8f,0x99,A,A]
5854 # N32: # fixup A - offset: 0, value: %got_disp(local_label), kind: fixup_Mips_GOT_DISP
5955
56 # ELF-N32: 8f 99 00 00 lw $25, 0($gp)
57 # ELF-N32-NEXT: R_MIPS_GOT_DISP/R_MIPS_NONE/R_MIPS_NONE local_label
58
6059 # N64: ld $25, %got_disp(local_label)($gp) # encoding: [0xdf,0x99,A,A]
6160 # N64: # fixup A - offset: 0, value: %got_disp(local_label), kind: fixup_Mips_GOT_DISP
61
62 # ELF-N64: df 99 00 00 ld $25, 0($gp)
63 # ELF-N64-NEXT: R_MIPS_GOT_DISP/R_MIPS_NONE/R_MIPS_NONE local_label
6264
6365 # O32-MICROMIPS: lw $25, %got(local_label)($gp) # encoding: [0xff,0x3c,A,A]
6466 # O32-MICROMIPS: # fixup A - offset: 0, value: %got(local_label), kind: fixup_MICROMIPS_GOT16
7577 # MICROMIPS: jalr $ra, $25 # encoding: [0x03,0xf9,0x0f,0x3c]
7678 # ALL: nop # encoding: [0x00,0x00,0x00,0x00]
7779
80 jal weak_label
81 nop
7882
7983 # Expanding "jal weak_label":
8084 # O32: lw $25, %call16(weak_label)($gp) # encoding: [0x8f,0x99,A,A]
8185 # O32: # fixup A - offset: 0, value: %call16(weak_label), kind: fixup_Mips_CALL16
8286
87 # ELF-O32: 8f 99 00 00 lw $25, 0($gp)
88 # ELF-O32-NEXT: R_MIPS_CALL16 weak_label
89
8390 # N32: lw $25, %call16(weak_label)($gp) # encoding: [0x8f,0x99,A,A]
8491 # N32: # fixup A - offset: 0, value: %call16(weak_label), kind: fixup_Mips_CALL16
8592
93 # ELF-N32: 8f 99 00 00 lw $25, 0($gp)
94 # ELF-N32-NEXT: R_MIPS_CALL16/R_MIPS_NONE/R_MIPS_NONE weak_label
95
8696 # N64: ld $25, %call16(weak_label)($gp) # encoding: [0xdf,0x99,A,A]
8797 # N64: # fixup A - offset: 0, value: %call16(weak_label), kind: fixup_Mips_CALL16
8898
99 # ELF-N64: df 99 00 00 ld $25, 0($gp)
100 # ELF-N64-NEXT: R_MIPS_CALL16/R_MIPS_NONE/R_MIPS_NONE weak_label
101
89102 # O32-MICROMIPS: lw $25, %call16(weak_label)($gp) # encoding: [0xff,0x3c,A,A]
90103 # O32-MICROMIPS: # fixup A - offset: 0, value: %call16(weak_label), kind: fixup_MICROMIPS_CALL16
91104
99112 # MICROMIPS: jalr $ra, $25 # encoding: [0x03,0xf9,0x0f,0x3c]
100113 # ALL: nop # encoding: [0x00,0x00,0x00,0x00]
101114
115 jal global_label
116 nop
102117
103118 # Expanding "jal global_label":
104119 # O32: lw $25, %call16(global_label)($gp) # encoding: [0x8f,0x99,A,A]
105120 # O32: # fixup A - offset: 0, value: %call16(global_label), kind: fixup_Mips_CALL16
106121
122 # ELF-O32: 8f 99 00 00 lw $25, 0($gp)
123 # ELF-O32-NEXT: R_MIPS_CALL16 global_label
124
107125 # N32: lw $25, %call16(global_label)($gp) # encoding: [0x8f,0x99,A,A]
108126 # N32: # fixup A - offset: 0, value: %call16(global_label), kind: fixup_Mips_CALL16
109127
128 # ELF-N32: 8f 99 00 00 lw $25, 0($gp)
129 # ELF-N32-NEXT: R_MIPS_CALL16/R_MIPS_NONE/R_MIPS_NONE global_label
130
110131 # N64: ld $25, %call16(global_label)($gp) # encoding: [0xdf,0x99,A,A]
111132 # N64: # fixup A - offset: 0, value: %call16(global_label), kind: fixup_Mips_CALL16
112133
134 # ELF-N64: df 99 00 00 ld $25, 0($gp)
135 # ELF-N64-NEXT: R_MIPS_CALL16/R_MIPS_NONE/R_MIPS_NONE global_label
136
113137 # O32-MICROMIPS: lw $25, %call16(global_label)($gp) # encoding: [0xff,0x3c,A,A]
114138 # O32-MICROMIPS: # fixup A - offset: 0, value: %call16(global_label), kind: fixup_MICROMIPS_CALL16
115139
123147 # MICROMIPS: jalr $ra, $25 # encoding: [0x03,0xf9,0x0f,0x3c]
124148 # ALL: nop # encoding: [0x00,0x00,0x00,0x00]
125149
150 jal .text
151 nop
126152
127153 # FIXME: The .text section MCSymbol isn't created when printing assembly. However,
128154 # it is created when generating an ELF object file.
129155 # Expanding "jal .text":
130 # O32-FIXME: lw $25, %got(.text)($gp) # encoding: [0x8f,0x99,A,A]
131 # O32-FIXME: # fixup A - offset: 0, value: %got(.text), kind: fixup_Mips_GOT
132 # O32-FIXME: addiu $25, $25, %lo(.text) # encoding: [0x27,0x39,A,A]
133 # O32-FIXME: # fixup A - offset: 0, value: %lo(.text), kind: fixup_Mips_LO16
134
135 # N32-FIXME: lw $25, %got_disp(.text)($gp) # encoding: [0x8f,0x99,A,A]
136 # N32-FIXME: # fixup A - offset: 0, value: %got_disp(.text), kind: fixup_Mips_GOT_DISP
137
138 # N64-FIXME: ld $25, %got_disp(.text)($gp) # encoding: [0xdf,0x99,A,A]
139 # N64-FIXME: # fixup A - offset: 0, value: %got_disp(.text), kind: fixup_Mips_GOT_DISP
156 # O32-FIXME: lw $25, %call16(.text)($gp) # encoding: [0x8f,0x99,A,A]
157 # O32-FIXME: # fixup A - offset: 0, value: %got(.text), kind: fixup_Mips_GOT_CALL
158
159 # ELF-O32: 8f 99 00 00 lw $25, 0($gp)
160 # ELF-O32-NEXT: R_MIPS_CALL16 .text
161
162 # N32-FIXME: lw $25, %call16(.text)($gp) # encoding: [0x8f,0x99,A,A]
163 # N32-FIXME: # fixup A - offset: 0, value: %call16(.text), kind: fixup_Mips_GOT_DISP
164
165 # ELF-N32: 8f 99 00 00 lw $25, 0($gp)
166 # ELF-N32-NEXT: R_MIPS_CALL16/R_MIPS_NONE/R_MIPS_NONE .text
167
168 # N64-FIXME: ld $25, %call16(.text)($gp) # encoding: [0xdf,0x99,A,A]
169 # N64-FIXME: # fixup A - offset: 0, value: %call16(.text), kind: fixup_Mips_GOT_DISP
170
171 # ELF-N64: df 99 00 00 ld $25, 0($gp)
172 # ELF-N64-NEXT: R_MIPS_CALL16/R_MIPS_NONE/R_MIPS_NONE .text
140173
141174 # O32-MICROMIPS-FIXME: lw $25, %got(.text)($gp) # encoding: [0xff,0x3c,A,A]
142175 # O32-MICROMIPS-FIXME: # fixup A - offset: 0, value: %got(.text), kind: fixup_MICROMIPS_GOT16
153186 # MICROMIPS: jalr $ra, $25 # encoding: [0x03,0xf9,0x0f,0x3c]
154187 # ALL: nop # encoding: [0x00,0x00,0x00,0x00]
155188
189 # local labels ($tmp symbols)
190 jal 1f
191 nop
156192
157193 # Expanding "jal 1f":
158194 # O32: lw $25, %got($tmp0)($gp) # encoding: [0x8f,0x99,A,A]
160196 # O32: addiu $25, $25, %lo($tmp0) # encoding: [0x27,0x39,A,A]
161197 # O32: # fixup A - offset: 0, value: %lo($tmp0), kind: fixup_Mips_LO16
162198
199 # ELF-O32: 8f 99 00 00 lw $25, 0($gp)
200 # ELF-O32-NEXT: R_MIPS_GOT16 .text
201 # ELF-O32-NEXT: 27 39 00 54 addiu $25, $25, 84
202 # ELF-O32-NEXT: R_MIPS_LO16 .text
203
163204 # N32: lw $25, %got_disp($tmp0)($gp) # encoding: [0x8f,0x99,A,A]
164205 # N32: # fixup A - offset: 0, value: %got_disp($tmp0), kind: fixup_Mips_GOT_DISP
165206
207 # ELF-N32: 8f 99 00 00 lw $25, 0($gp)
208 # ELF-N32-NEXT: R_MIPS_GOT_DISP/R_MIPS_NONE/R_MIPS_NONE .Ltmp0
209
166210 # N64: ld $25, %got_disp(.Ltmp0)($gp) # encoding: [0xdf,0x99,A,A]
167211 # N64: # fixup A - offset: 0, value: %got_disp(.Ltmp0), kind: fixup_Mips_GOT_DISP
212
213 # ELF-N64: df 99 00 00 ld $25, 0($gp)
214 # ELF-N64-NEXT: R_MIPS_GOT_DISP/R_MIPS_NONE/R_MIPS_NONE .Ltmp0
168215
169216 # O32-MICROMIPS: lw $25, %got($tmp0)($gp) # encoding: [0xff,0x3c,A,A]
170217 # O32-MICROMIPS: # fixup A - offset: 0, value: %got($tmp0), kind: fixup_MICROMIPS_GOT16
180227 # NORMAL: jalr $25 # encoding: [0x03,0x20,0xf8,0x09]
181228 # MICROMIPS: jalr $ra, $25 # encoding: [0x03,0xf9,0x0f,0x3c]
182229 # ALL: nop # encoding: [0x00,0x00,0x00,0x00]
230
231 .local forward_local
232 jal forward_local
233 nop
234
235 # Expanding "jal forward_local":
236 # O32-FIXME: lw $25, %got(forward_local)($gp) # encoding: [0x8f,0x99,A,A]
237 # O32-FIXME: # fixup A - offset: 0, value: %got(forward_local), kind: fixup_Mips_GOT
238 # O32-FIXME: addiu $25, $25, %lo(forward_local) # encoding: [0x27,0x39,A,A]
239 # O32-FIXME:: # fixup A - offset: 0, value: %lo(forward_local), kind: fixup_Mips_LO16
240
241 # ELF-O32: 8f 99 00 00 lw $25, 0($gp)
242 # ELF-O32-NEXT: R_MIPS_GOT16 .text
243 # ELF-O32-NEXT: 27 39 00 60 addiu $25, $25, 96
244 # ELF-O32-NEXT: R_MIPS_LO16 .text
245
246 # N32-FIXME: lw $25, %got_disp(forward_local)($gp) # encoding: [0x8f,0x99,A,A]
247 # N32-FIXME: # fixup A - offset: 0, value: %got_disp(forward_local), kind: fixup_Mips_GOT_DISP
248
249 # ELF-N32: 8f 99 00 00 lw $25, 0($gp)
250 # ELF-N32-NEXT: R_MIPS_GOT_DISP/R_MIPS_NONE/R_MIPS_NONE forward_local
251
252 # N64-FIXME: ld $25, %got_disp(forward_local)($gp) # encoding: [0xdf,0x99,A,A]
253 # N64-FIXME: # fixup A - offset: 0, value: %got_disp(forward_local), kind: fixup_Mips_GOT_DISP
254
255 # ELF-N64: df 99 00 00 ld $25, 0($gp)
256 # ELF-N64-NEXT: R_MIPS_GOT_DISP/R_MIPS_NONE/R_MIPS_NONE forward_local
257
258 # O32-MICROMIPS-FIXME: lw $25, %got(forward_local)($gp) # encoding: [0xff,0x3c,A,A]
259 # O32-MICROMIPS-FIXME: # fixup A - offset: 0, value: %got(forward_local), kind: fixup_MICROMIPS_GOT16
260 # O32-MICROMIPS-FIXME: addiu $25, $25, %lo(forward_local) # encoding: [0x33,0x39,A,A]
261 # O32-MICROMIPS-FIXME: # fixup A - offset: 0, value: %lo(forward_local), kind: fixup_MICROMIPS_LO16
262
263 # N32-MICROMIPS-FIXME: lw $25, %got_disp(forward_local)($gp) # encoding: [0xff,0x3c,A,A]
264 # N32-MICROMIPS-FIXME: # fixup A - offset: 0, value: %got_disp(forward_local), kind: fixup_MICROMIPS_GOT_DISP
265
266 # N64-MICROMIPS-FIXME: ld $25, %got_disp(forward_local)($gp) # encoding: [0xdf,0x99,A,A]
267 # N64-MICROMIPS-FIXME: # fixup A - offset: 0, value: %got_disp(forward_local), kind: fixup_MICROMIPS_GOT_DISP
268
269 # NORMAL: jalr $25 # encoding: [0x03,0x20,0xf8,0x09]
270 # MICROMIPS: jalr $ra, $25 # encoding: [0x03,0xf9,0x0f,0x3c]
271 # ALL: nop # encoding: [0x00,0x00,0x00,0x00]
272
273
274 .end local_label
275
276 1:
277 nop
278 add $8, $8, $8
279 nop
280 forward_local:
281