Upload Tizen:Base source
[external/binutils.git] / packaging / 162_ld_cortex_a8_erratum.diff
1 # DP: Cortex A8 workarounds for PLT tail calls
2
3 bfd/
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.
6
7 ld/testsuite/
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.
14
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,
20                    bfd_vma target;
21                    enum elf32_arm_stub_type stub_type = arm_stub_none;
22                    struct a8_erratum_reloc key, *found;
23 +                  bfd_boolean use_plt = FALSE;
24  
25                    key.from = base_vma + i;
26                    found = (struct a8_erratum_reloc *)
27 @@ -4567,7 +4568,6 @@ cortex_a8_erratum_scan (bfd *input_bfd,
28                     {
29                       char *error_message = NULL;
30                       struct elf_link_hash_entry *entry;
31 -                     bfd_boolean use_plt = FALSE;
32  
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,
36                          offset =
37                           (bfd_signed_vma) (found->destination - pc_for_insn);
38  
39 +                      /* If the stub will use a Thumb-mode branch to a
40 +                         PLT target, redirect it to the preceding Thumb
41 +                         entry point.  */
42 +                      if (stub_type != arm_stub_a8_veneer_blx && use_plt)
43 +                        offset -= PLT_THUMB_STUB_SIZE;
44 +
45                        target = pc_for_insn + offset;
46  
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
52 @@ -0,0 +1,10 @@
53 +       .syntax unified
54 +       .globl  foo
55 +       .type   foo,%function
56 +       .thumb_func
57 +foo:
58 +       nop                     @ 0x00
59 +       movw    r0,#0           @ 0x02
60 +       movw    r0,#0           @ 0x06
61 +       movw    r0,#0           @ 0x0a
62 +       b.w     bar(PLT)        @ 0x0e
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
67 @@ -0,0 +1,30 @@
68 +
69 +.*
70 +
71 +
72 +Disassembly of section \.plt:
73 +
74 +00008000 <\.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
80 +    8014:      4778            bx      pc
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
85 +
86 +Disassembly of section \.text:
87 +
88 +00008ff0 <foo>:
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
102 @@ -0,0 +1,10 @@
103 +       .syntax unified
104 +       .globl  foo
105 +       .type   foo,%function
106 +       .thumb_func
107 +foo:
108 +       nop                     @ 0x00
109 +       movw    r0,#0           @ 0x02
110 +       movw    r0,#0           @ 0x06
111 +       movw    r0,#0           @ 0x0a
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
117 @@ -0,0 +1,32 @@
118 +
119 +.*
120 +
121 +
122 +Disassembly of section \.plt:
123 +
124 +00008000 <\.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
130 +    8014:      4778            bx      pc
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\]!
135 +
136 +Disassembly of section \.text:
137 +
138 +00008ff0 <foo>:
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
154 @@ -0,0 +1,10 @@
155 +       .syntax unified
156 +       .globl  foo
157 +       .type   foo,%function
158 +       .thumb_func
159 +foo:
160 +       nop                     @ 0x00
161 +       movw    r0,#0           @ 0x02
162 +       movw    r0,#0           @ 0x06
163 +       movw    r0,#0           @ 0x0a
164 +       bl      bar(PLT)        @ 0x0e
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
169 @@ -0,0 +1,28 @@
170 +
171 +.*
172 +
173 +
174 +Disassembly of section \.plt:
175 +
176 +00008000 <\.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
185 +
186 +Disassembly of section \.text:
187 +
188 +00008ff0 <foo>:
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
202 @@ -0,0 +1,10 @@
203 +       .syntax unified
204 +       .globl  foo
205 +       .type   foo,%function
206 +       .thumb_func
207 +foo:
208 +       nop                     @ 0x00
209 +       movw    r0,#0           @ 0x02
210 +       movw    r0,#0           @ 0x06
211 +       movw    r0,#0           @ 0x0a
212 +       blx     bar             @ 0x0e
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
217 @@ -0,0 +1,28 @@
218 +
219 +.*
220 +
221 +
222 +Disassembly of section \.plt:
223 +
224 +00008000 <\.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
233 +
234 +Disassembly of section \.text:
235 +
236 +00008ff0 <foo>:
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
250 @@ -0,0 +1,18 @@
251 +OUTPUT_ARCH(arm)
252 +ENTRY(_start)
253 +SECTIONS
254 +{
255 +  . = 0x07000;
256 +  .hash : { *(.hash) }
257 +  .gnu.hash : { *(.gnu.hash) }
258 +  .dynsym : { *(.dynsym) }
259 +  .dynstr : { *(.dynstr) }
260 +  .rel.dyn : { *(.rel.dyn) }
261 +  .rel.plt : { *(.rel.plt) }
262 +  . = 0x08000;
263 +  .plt : { *(.plt) }
264 +  . = 0x08ff0;
265 +  .text : { *(.text) }
266 +  . = 0x10000;
267 +  .dynamic : { *(.dynamic) }
268 +}
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}}
276       "cortex-a8-fix-b"}
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}}
285       "cortex-a8-fix-bl"}
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}}
294       "cortex-a8-fix-bcc"}
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}}
303       "cortex-a8-fix-blx"}
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}}