1 # DP: Cortex A8 workarounds for PLT tail calls
4 * elf32-arm.c (cortex_a8_erratum_scan): If the stub is a Thumb
5 branch to a PLT entry, redirect it to the PLT's Thumb entry point.
8 * ld-arm/cortex-a8-fix-b-plt.s, ld-arm/cortex-a8-fix-b-plt.d,
9 ld-arm/cortex-a8-fix-bcc-plt.s, ld-arm/cortex-a8-fix-bcc-plt.d,
10 ld-arm/cortex-a8-fix-bl-plt.s, ld-arm/cortex-a8-fix-bl-plt.d,
11 ld-arm/cortex-a8-fix-blx-plt.s, ld-arm/cortex-a8-fix-blx-plt.d,
12 ld-arm/cortex-a8-fix-plt.ld: New tests.
13 * ld-arm/arm-elf.exp: Run them.
15 Index: bfd/elf32-arm.c
16 ===================================================================
17 --- ./bfd/elf32-arm.c 2011-04-11 16:23:04.000000000 +0100
18 +++ ./bfd/elf32-arm.c 2011-04-12 09:22:06.000000000 +0100
19 @@ -4556,6 +4556,7 @@ cortex_a8_erratum_scan (bfd *input_bfd,
21 enum elf32_arm_stub_type stub_type = arm_stub_none;
22 struct a8_erratum_reloc key, *found;
23 + bfd_boolean use_plt = FALSE;
25 key.from = base_vma + i;
26 found = (struct a8_erratum_reloc *)
27 @@ -4567,7 +4568,6 @@ cortex_a8_erratum_scan (bfd *input_bfd,
29 char *error_message = NULL;
30 struct elf_link_hash_entry *entry;
31 - bfd_boolean use_plt = FALSE;
33 /* We don't care about the error returned from this
34 function, only if there is glue or not. */
35 @@ -4671,6 +4671,12 @@ cortex_a8_erratum_scan (bfd *input_bfd,
37 (bfd_signed_vma) (found->destination - pc_for_insn);
39 + /* If the stub will use a Thumb-mode branch to a
40 + PLT target, redirect it to the preceding Thumb
42 + if (stub_type != arm_stub_a8_veneer_blx && use_plt)
43 + offset -= PLT_THUMB_STUB_SIZE;
45 target = pc_for_insn + offset;
47 /* The BLX stub is ARM-mode code. Adjust the offset to
48 Index: ld/testsuite/ld-arm/cortex-a8-fix-b-plt.s
49 ===================================================================
50 --- /dev/null 2011-03-23 08:42:11.268792848 +0000
51 +++ ./ld/testsuite/ld-arm/cortex-a8-fix-b-plt.s 2011-04-11 16:23:18.000000000 +0100
63 Index: ld/testsuite/ld-arm/cortex-a8-fix-b-plt.d
64 ===================================================================
65 --- /dev/null 2011-03-23 08:42:11.268792848 +0000
66 +++ ./ld/testsuite/ld-arm/cortex-a8-fix-b-plt.d 2011-04-11 16:23:18.000000000 +0100
72 +Disassembly of section \.plt:
75 + 8000: e52de004 push {lr} ; \(str lr, \[sp, #-4\]!\)
76 + 8004: e59fe004 ldr lr, \[pc, #4\] ; 8010 <foo-0xfe0>
77 + 8008: e08fe00e add lr, pc, lr
78 + 800c: e5bef008 ldr pc, \[lr, #8\]!
79 + 8010: 00000ffc \.word 0x00000ffc
81 + 8016: 46c0 nop ; \(mov r8, r8\)
82 + 8018: e28fc600 add ip, pc, #0
83 + 801c: e28cca00 add ip, ip, #0
84 + 8020: e5bcfff8 ldr pc, \[ip, #4088\]! ; 0xff8
86 +Disassembly of section \.text:
89 + 8ff0: 46c0 nop ; \(mov r8, r8\)
90 + 8ff2: f240 0000 movw r0, #0
91 + 8ff6: f240 0000 movw r0, #0
92 + 8ffa: f240 0000 movw r0, #0
93 + 8ffe: f000 b803 b\.w 9008 <foo\+0x18>
94 + 9002: 0000 movs r0, r0
95 + 9004: 0000 movs r0, r0
96 + 9006: 0000 movs r0, r0
97 + 9008: f7ff b804 b\.w 8014 <foo-0xfdc>
98 Index: ld/testsuite/ld-arm/cortex-a8-fix-bcc-plt.s
99 ===================================================================
100 --- /dev/null 2011-03-23 08:42:11.268792848 +0000
101 +++ ./ld/testsuite/ld-arm/cortex-a8-fix-bcc-plt.s 2011-04-11 16:23:18.000000000 +0100
105 + .type foo,%function
112 + beq.w bar(PLT) @ 0x0e
113 Index: ld/testsuite/ld-arm/cortex-a8-fix-bcc-plt.d
114 ===================================================================
115 --- /dev/null 2011-03-23 08:42:11.268792848 +0000
116 +++ ./ld/testsuite/ld-arm/cortex-a8-fix-bcc-plt.d 2011-04-11 16:23:18.000000000 +0100
122 +Disassembly of section \.plt:
125 + 8000: e52de004 push {lr} ; \(str lr, \[sp, #-4\]!\)
126 + 8004: e59fe004 ldr lr, \[pc, #4\] ; 8010 <foo-0xfe0>
127 + 8008: e08fe00e add lr, pc, lr
128 + 800c: e5bef008 ldr pc, \[lr, #8\]!
129 + 8010: 00001004 \.word 0x00001004
131 + 8016: 46c0 nop ; \(mov r8, r8\)
132 + 8018: e28fc600 add ip, pc, #0
133 + 801c: e28cca01 add ip, ip, #4096 ; 0x1000
134 + 8020: e5bcf000 ldr pc, \[ip\]!
136 +Disassembly of section \.text:
139 + 8ff0: 46c0 nop ; \(mov r8, r8\)
140 + 8ff2: f240 0000 movw r0, #0
141 + 8ff6: f240 0000 movw r0, #0
142 + 8ffa: f240 0000 movw r0, #0
143 + 8ffe: f000 b803 b\.w 9008 <foo\+0x18>
144 + 9002: 0000 movs r0, r0
145 + 9004: 0000 movs r0, r0
146 + 9006: 0000 movs r0, r0
147 + 9008: d001 beq\.n 900e <foo\+0x1e>
148 + 900a: f7ff bffa b\.w 9002 <foo\+0x12>
149 + 900e: f7ff b801 b\.w 8014 <foo-0xfdc>
150 Index: ld/testsuite/ld-arm/cortex-a8-fix-bl-plt.s
151 ===================================================================
152 --- /dev/null 2011-03-23 08:42:11.268792848 +0000
153 +++ ./ld/testsuite/ld-arm/cortex-a8-fix-bl-plt.s 2011-04-11 16:23:18.000000000 +0100
157 + .type foo,%function
165 Index: ld/testsuite/ld-arm/cortex-a8-fix-bl-plt.d
166 ===================================================================
167 --- /dev/null 2011-03-23 08:42:11.268792848 +0000
168 +++ ./ld/testsuite/ld-arm/cortex-a8-fix-bl-plt.d 2011-04-11 16:23:18.000000000 +0100
174 +Disassembly of section \.plt:
177 + 8000: e52de004 push {lr} ; \(str lr, \[sp, #-4\]!\)
178 + 8004: e59fe004 ldr lr, \[pc, #4\] ; 8010 <foo-0xfe0>
179 + 8008: e08fe00e add lr, pc, lr
180 + 800c: e5bef008 ldr pc, \[lr, #8\]!
181 + 8010: 00000ffc \.word 0x00000ffc
182 + 8014: e28fc600 add ip, pc, #0
183 + 8018: e28cca00 add ip, ip, #0
184 + 801c: e5bcfffc ldr pc, \[ip, #4092\]! ; 0xffc
186 +Disassembly of section \.text:
189 + 8ff0: 46c0 nop ; \(mov r8, r8\)
190 + 8ff2: f240 0000 movw r0, #0
191 + 8ff6: f240 0000 movw r0, #0
192 + 8ffa: f240 0000 movw r0, #0
193 + 8ffe: f000 e804 blx 9008 <foo\+0x18>
194 + 9002: 0000 movs r0, r0
195 + 9004: 0000 movs r0, r0
196 + 9006: 0000 movs r0, r0
197 + 9008: eafffc01 b 8014 <foo-0xfdc>
198 Index: ld/testsuite/ld-arm/cortex-a8-fix-blx-plt.s
199 ===================================================================
200 --- /dev/null 2011-03-23 08:42:11.268792848 +0000
201 +++ ./ld/testsuite/ld-arm/cortex-a8-fix-blx-plt.s 2011-04-11 16:23:18.000000000 +0100
205 + .type foo,%function
213 Index: ld/testsuite/ld-arm/cortex-a8-fix-blx-plt.d
214 ===================================================================
215 --- /dev/null 2011-03-23 08:42:11.268792848 +0000
216 +++ ./ld/testsuite/ld-arm/cortex-a8-fix-blx-plt.d 2011-04-11 16:23:18.000000000 +0100
222 +Disassembly of section \.plt:
225 + 8000: e52de004 push {lr} ; \(str lr, \[sp, #-4\]!\)
226 + 8004: e59fe004 ldr lr, \[pc, #4\] ; 8010 <foo-0xfe0>
227 + 8008: e08fe00e add lr, pc, lr
228 + 800c: e5bef008 ldr pc, \[lr, #8\]!
229 + 8010: 00000ffc \.word 0x00000ffc
230 + 8014: e28fc600 add ip, pc, #0
231 + 8018: e28cca00 add ip, ip, #0
232 + 801c: e5bcfffc ldr pc, \[ip, #4092\]! ; 0xffc
234 +Disassembly of section \.text:
237 + 8ff0: 46c0 nop ; \(mov r8, r8\)
238 + 8ff2: f240 0000 movw r0, #0
239 + 8ff6: f240 0000 movw r0, #0
240 + 8ffa: f240 0000 movw r0, #0
241 + 8ffe: f000 e804 blx 9008 <foo\+0x18>
242 + 9002: 0000 movs r0, r0
243 + 9004: 0000 movs r0, r0
244 + 9006: 0000 movs r0, r0
245 + 9008: eafffc01 b 8014 <foo-0xfdc>
246 Index: ld/testsuite/ld-arm/cortex-a8-fix-plt.ld
247 ===================================================================
248 --- /dev/null 2011-03-23 08:42:11.268792848 +0000
249 +++ ./ld/testsuite/ld-arm/cortex-a8-fix-plt.ld 2011-04-11 16:23:18.000000000 +0100
256 + .hash : { *(.hash) }
257 + .gnu.hash : { *(.gnu.hash) }
258 + .dynsym : { *(.dynsym) }
259 + .dynstr : { *(.dynstr) }
260 + .rel.dyn : { *(.rel.dyn) }
261 + .rel.plt : { *(.rel.plt) }
265 + .text : { *(.text) }
267 + .dynamic : { *(.dynamic) }
269 Index: ld/testsuite/ld-arm/arm-elf.exp
270 ===================================================================
271 --- ld/testsuite/ld-arm/arm-elf.exp 2011-04-11 16:23:04.000000000 +0100
272 +++ ./ld/testsuite/ld-arm/arm-elf.exp 2011-04-11 16:23:18.000000000 +0100
273 @@ -210,18 +210,38 @@ set armelftests {
274 "-EL -Ttext=0x8f00 --fix-cortex-a8" "-EL" {cortex-a8-fix-b.s}
275 {{objdump -dr cortex-a8-fix-b.d}}
277 + {"Cortex-A8 erratum fix, b.w to PLT"
278 + "-EL -Tcortex-a8-fix-plt.ld --fix-cortex-a8 -shared" "-EL"
279 + {cortex-a8-fix-b-plt.s}
280 + {{objdump -dr cortex-a8-fix-b-plt.d}}
281 + "cortex-a8-fix-b-plt"}
282 {"Cortex-A8 erratum fix, bl.w"
283 "-EL -Ttext=0x8f00 --fix-cortex-a8" "-EL" {cortex-a8-fix-bl.s}
284 {{objdump -dr cortex-a8-fix-bl.d}}
286 + {"Cortex-A8 erratum fix, bl.w to PLT"
287 + "-EL -Tcortex-a8-fix-plt.ld --fix-cortex-a8 -shared" "-EL"
288 + {cortex-a8-fix-bl-plt.s}
289 + {{objdump -dr cortex-a8-fix-bl-plt.d}}
290 + "cortex-a8-fix-bl-plt"}
291 {"Cortex-A8 erratum fix, bcc.w"
292 "-EL -Ttext=0x8f00 --fix-cortex-a8" "-EL" {cortex-a8-fix-bcc.s}
293 {{objdump -dr cortex-a8-fix-bcc.d}}
295 + {"Cortex-A8 erratum fix, bcc.w to PLT"
296 + "-EL -Tcortex-a8-fix-plt.ld --fix-cortex-a8 -shared" "-EL"
297 + {cortex-a8-fix-bcc-plt.s}
298 + {{objdump -dr cortex-a8-fix-bcc-plt.d}}
299 + "cortex-a8-fix-bcc-plt"}
300 {"Cortex-A8 erratum fix, blx.w"
301 "-EL -Ttext=0x8f00 --fix-cortex-a8" "-EL" {cortex-a8-fix-blx.s}
302 {{objdump -dr cortex-a8-fix-blx.d}}
304 + {"Cortex-A8 erratum fix, blx.w to PLT"
305 + "-EL -Tcortex-a8-fix-plt.ld --fix-cortex-a8 -shared" "-EL"
306 + {cortex-a8-fix-blx-plt.s}
307 + {{objdump -dr cortex-a8-fix-blx-plt.d}}
308 + "cortex-a8-fix-blx-plt"}
309 {"Cortex-A8 erratum fix, relocate b.w to ARM"
310 "-EL -Ttext=0x8f00 --fix-cortex-a8" "-EL" {cortex-a8-arm-target.s cortex-a8-fix-b-rel.s}
311 {{objdump -dr cortex-a8-fix-b-rel-arm.d}}