* emultempl/pe.em (debug_section_p): New bfd_map_over_sections hook.
[binutils.git] / bfd / elf32-arm.c
blob2527e5e8425714d8dd1d96aa6242c08f64b020cd
1 /* 32-bit ELF support for ARM
2 Copyright 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007,
3 2008 Free Software Foundation, Inc.
5 This file is part of BFD, the Binary File Descriptor library.
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 3 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
20 MA 02110-1301, USA. */
22 #include "sysdep.h"
23 #include "bfd.h"
24 #include "libiberty.h"
25 #include "libbfd.h"
26 #include "elf-bfd.h"
27 #include "elf-vxworks.h"
28 #include "elf/arm.h"
30 /* Return the relocation section associated with NAME. HTAB is the
31 bfd's elf32_arm_link_hash_entry. */
32 #define RELOC_SECTION(HTAB, NAME) \
33 ((HTAB)->use_rel ? ".rel" NAME : ".rela" NAME)
35 /* Return size of a relocation entry. HTAB is the bfd's
36 elf32_arm_link_hash_entry. */
37 #define RELOC_SIZE(HTAB) \
38 ((HTAB)->use_rel \
39 ? sizeof (Elf32_External_Rel) \
40 : sizeof (Elf32_External_Rela))
42 /* Return function to swap relocations in. HTAB is the bfd's
43 elf32_arm_link_hash_entry. */
44 #define SWAP_RELOC_IN(HTAB) \
45 ((HTAB)->use_rel \
46 ? bfd_elf32_swap_reloc_in \
47 : bfd_elf32_swap_reloca_in)
49 /* Return function to swap relocations out. HTAB is the bfd's
50 elf32_arm_link_hash_entry. */
51 #define SWAP_RELOC_OUT(HTAB) \
52 ((HTAB)->use_rel \
53 ? bfd_elf32_swap_reloc_out \
54 : bfd_elf32_swap_reloca_out)
56 #define elf_info_to_howto 0
57 #define elf_info_to_howto_rel elf32_arm_info_to_howto
59 #define ARM_ELF_ABI_VERSION 0
60 #define ARM_ELF_OS_ABI_VERSION ELFOSABI_ARM
62 static struct elf_backend_data elf32_arm_vxworks_bed;
64 /* Note: code such as elf32_arm_reloc_type_lookup expect to use e.g.
65 R_ARM_PC24 as an index into this, and find the R_ARM_PC24 HOWTO
66 in that slot. */
68 static reloc_howto_type elf32_arm_howto_table_1[] =
70 /* No relocation. */
71 HOWTO (R_ARM_NONE, /* type */
72 0, /* rightshift */
73 0, /* size (0 = byte, 1 = short, 2 = long) */
74 0, /* bitsize */
75 FALSE, /* pc_relative */
76 0, /* bitpos */
77 complain_overflow_dont,/* complain_on_overflow */
78 bfd_elf_generic_reloc, /* special_function */
79 "R_ARM_NONE", /* name */
80 FALSE, /* partial_inplace */
81 0, /* src_mask */
82 0, /* dst_mask */
83 FALSE), /* pcrel_offset */
85 HOWTO (R_ARM_PC24, /* type */
86 2, /* rightshift */
87 2, /* size (0 = byte, 1 = short, 2 = long) */
88 24, /* bitsize */
89 TRUE, /* pc_relative */
90 0, /* bitpos */
91 complain_overflow_signed,/* complain_on_overflow */
92 bfd_elf_generic_reloc, /* special_function */
93 "R_ARM_PC24", /* name */
94 FALSE, /* partial_inplace */
95 0x00ffffff, /* src_mask */
96 0x00ffffff, /* dst_mask */
97 TRUE), /* pcrel_offset */
99 /* 32 bit absolute */
100 HOWTO (R_ARM_ABS32, /* type */
101 0, /* rightshift */
102 2, /* size (0 = byte, 1 = short, 2 = long) */
103 32, /* bitsize */
104 FALSE, /* pc_relative */
105 0, /* bitpos */
106 complain_overflow_bitfield,/* complain_on_overflow */
107 bfd_elf_generic_reloc, /* special_function */
108 "R_ARM_ABS32", /* name */
109 FALSE, /* partial_inplace */
110 0xffffffff, /* src_mask */
111 0xffffffff, /* dst_mask */
112 FALSE), /* pcrel_offset */
114 /* standard 32bit pc-relative reloc */
115 HOWTO (R_ARM_REL32, /* type */
116 0, /* rightshift */
117 2, /* size (0 = byte, 1 = short, 2 = long) */
118 32, /* bitsize */
119 TRUE, /* pc_relative */
120 0, /* bitpos */
121 complain_overflow_bitfield,/* complain_on_overflow */
122 bfd_elf_generic_reloc, /* special_function */
123 "R_ARM_REL32", /* name */
124 FALSE, /* partial_inplace */
125 0xffffffff, /* src_mask */
126 0xffffffff, /* dst_mask */
127 TRUE), /* pcrel_offset */
129 /* 8 bit absolute - R_ARM_LDR_PC_G0 in AAELF */
130 HOWTO (R_ARM_LDR_PC_G0, /* type */
131 0, /* rightshift */
132 0, /* size (0 = byte, 1 = short, 2 = long) */
133 32, /* bitsize */
134 TRUE, /* pc_relative */
135 0, /* bitpos */
136 complain_overflow_dont,/* complain_on_overflow */
137 bfd_elf_generic_reloc, /* special_function */
138 "R_ARM_LDR_PC_G0", /* name */
139 FALSE, /* partial_inplace */
140 0xffffffff, /* src_mask */
141 0xffffffff, /* dst_mask */
142 TRUE), /* pcrel_offset */
144 /* 16 bit absolute */
145 HOWTO (R_ARM_ABS16, /* type */
146 0, /* rightshift */
147 1, /* size (0 = byte, 1 = short, 2 = long) */
148 16, /* bitsize */
149 FALSE, /* pc_relative */
150 0, /* bitpos */
151 complain_overflow_bitfield,/* complain_on_overflow */
152 bfd_elf_generic_reloc, /* special_function */
153 "R_ARM_ABS16", /* name */
154 FALSE, /* partial_inplace */
155 0x0000ffff, /* src_mask */
156 0x0000ffff, /* dst_mask */
157 FALSE), /* pcrel_offset */
159 /* 12 bit absolute */
160 HOWTO (R_ARM_ABS12, /* type */
161 0, /* rightshift */
162 2, /* size (0 = byte, 1 = short, 2 = long) */
163 12, /* bitsize */
164 FALSE, /* pc_relative */
165 0, /* bitpos */
166 complain_overflow_bitfield,/* complain_on_overflow */
167 bfd_elf_generic_reloc, /* special_function */
168 "R_ARM_ABS12", /* name */
169 FALSE, /* partial_inplace */
170 0x00000fff, /* src_mask */
171 0x00000fff, /* dst_mask */
172 FALSE), /* pcrel_offset */
174 HOWTO (R_ARM_THM_ABS5, /* type */
175 6, /* rightshift */
176 1, /* size (0 = byte, 1 = short, 2 = long) */
177 5, /* bitsize */
178 FALSE, /* pc_relative */
179 0, /* bitpos */
180 complain_overflow_bitfield,/* complain_on_overflow */
181 bfd_elf_generic_reloc, /* special_function */
182 "R_ARM_THM_ABS5", /* name */
183 FALSE, /* partial_inplace */
184 0x000007e0, /* src_mask */
185 0x000007e0, /* dst_mask */
186 FALSE), /* pcrel_offset */
188 /* 8 bit absolute */
189 HOWTO (R_ARM_ABS8, /* type */
190 0, /* rightshift */
191 0, /* size (0 = byte, 1 = short, 2 = long) */
192 8, /* bitsize */
193 FALSE, /* pc_relative */
194 0, /* bitpos */
195 complain_overflow_bitfield,/* complain_on_overflow */
196 bfd_elf_generic_reloc, /* special_function */
197 "R_ARM_ABS8", /* name */
198 FALSE, /* partial_inplace */
199 0x000000ff, /* src_mask */
200 0x000000ff, /* dst_mask */
201 FALSE), /* pcrel_offset */
203 HOWTO (R_ARM_SBREL32, /* type */
204 0, /* rightshift */
205 2, /* size (0 = byte, 1 = short, 2 = long) */
206 32, /* bitsize */
207 FALSE, /* pc_relative */
208 0, /* bitpos */
209 complain_overflow_dont,/* complain_on_overflow */
210 bfd_elf_generic_reloc, /* special_function */
211 "R_ARM_SBREL32", /* name */
212 FALSE, /* partial_inplace */
213 0xffffffff, /* src_mask */
214 0xffffffff, /* dst_mask */
215 FALSE), /* pcrel_offset */
217 HOWTO (R_ARM_THM_CALL, /* type */
218 1, /* rightshift */
219 2, /* size (0 = byte, 1 = short, 2 = long) */
220 25, /* bitsize */
221 TRUE, /* pc_relative */
222 0, /* bitpos */
223 complain_overflow_signed,/* complain_on_overflow */
224 bfd_elf_generic_reloc, /* special_function */
225 "R_ARM_THM_CALL", /* name */
226 FALSE, /* partial_inplace */
227 0x07ff07ff, /* src_mask */
228 0x07ff07ff, /* dst_mask */
229 TRUE), /* pcrel_offset */
231 HOWTO (R_ARM_THM_PC8, /* type */
232 1, /* rightshift */
233 1, /* size (0 = byte, 1 = short, 2 = long) */
234 8, /* bitsize */
235 TRUE, /* pc_relative */
236 0, /* bitpos */
237 complain_overflow_signed,/* complain_on_overflow */
238 bfd_elf_generic_reloc, /* special_function */
239 "R_ARM_THM_PC8", /* name */
240 FALSE, /* partial_inplace */
241 0x000000ff, /* src_mask */
242 0x000000ff, /* dst_mask */
243 TRUE), /* pcrel_offset */
245 HOWTO (R_ARM_BREL_ADJ, /* type */
246 1, /* rightshift */
247 1, /* size (0 = byte, 1 = short, 2 = long) */
248 32, /* bitsize */
249 FALSE, /* pc_relative */
250 0, /* bitpos */
251 complain_overflow_signed,/* complain_on_overflow */
252 bfd_elf_generic_reloc, /* special_function */
253 "R_ARM_BREL_ADJ", /* name */
254 FALSE, /* partial_inplace */
255 0xffffffff, /* src_mask */
256 0xffffffff, /* dst_mask */
257 FALSE), /* pcrel_offset */
259 HOWTO (R_ARM_SWI24, /* type */
260 0, /* rightshift */
261 0, /* size (0 = byte, 1 = short, 2 = long) */
262 0, /* bitsize */
263 FALSE, /* pc_relative */
264 0, /* bitpos */
265 complain_overflow_signed,/* complain_on_overflow */
266 bfd_elf_generic_reloc, /* special_function */
267 "R_ARM_SWI24", /* name */
268 FALSE, /* partial_inplace */
269 0x00000000, /* src_mask */
270 0x00000000, /* dst_mask */
271 FALSE), /* pcrel_offset */
273 HOWTO (R_ARM_THM_SWI8, /* type */
274 0, /* rightshift */
275 0, /* size (0 = byte, 1 = short, 2 = long) */
276 0, /* bitsize */
277 FALSE, /* pc_relative */
278 0, /* bitpos */
279 complain_overflow_signed,/* complain_on_overflow */
280 bfd_elf_generic_reloc, /* special_function */
281 "R_ARM_SWI8", /* name */
282 FALSE, /* partial_inplace */
283 0x00000000, /* src_mask */
284 0x00000000, /* dst_mask */
285 FALSE), /* pcrel_offset */
287 /* BLX instruction for the ARM. */
288 HOWTO (R_ARM_XPC25, /* type */
289 2, /* rightshift */
290 2, /* size (0 = byte, 1 = short, 2 = long) */
291 25, /* bitsize */
292 TRUE, /* pc_relative */
293 0, /* bitpos */
294 complain_overflow_signed,/* complain_on_overflow */
295 bfd_elf_generic_reloc, /* special_function */
296 "R_ARM_XPC25", /* name */
297 FALSE, /* partial_inplace */
298 0x00ffffff, /* src_mask */
299 0x00ffffff, /* dst_mask */
300 TRUE), /* pcrel_offset */
302 /* BLX instruction for the Thumb. */
303 HOWTO (R_ARM_THM_XPC22, /* type */
304 2, /* rightshift */
305 2, /* size (0 = byte, 1 = short, 2 = long) */
306 22, /* bitsize */
307 TRUE, /* pc_relative */
308 0, /* bitpos */
309 complain_overflow_signed,/* complain_on_overflow */
310 bfd_elf_generic_reloc, /* special_function */
311 "R_ARM_THM_XPC22", /* name */
312 FALSE, /* partial_inplace */
313 0x07ff07ff, /* src_mask */
314 0x07ff07ff, /* dst_mask */
315 TRUE), /* pcrel_offset */
317 /* Dynamic TLS relocations. */
319 HOWTO (R_ARM_TLS_DTPMOD32, /* type */
320 0, /* rightshift */
321 2, /* size (0 = byte, 1 = short, 2 = long) */
322 32, /* bitsize */
323 FALSE, /* pc_relative */
324 0, /* bitpos */
325 complain_overflow_bitfield,/* complain_on_overflow */
326 bfd_elf_generic_reloc, /* special_function */
327 "R_ARM_TLS_DTPMOD32", /* name */
328 TRUE, /* partial_inplace */
329 0xffffffff, /* src_mask */
330 0xffffffff, /* dst_mask */
331 FALSE), /* pcrel_offset */
333 HOWTO (R_ARM_TLS_DTPOFF32, /* type */
334 0, /* rightshift */
335 2, /* size (0 = byte, 1 = short, 2 = long) */
336 32, /* bitsize */
337 FALSE, /* pc_relative */
338 0, /* bitpos */
339 complain_overflow_bitfield,/* complain_on_overflow */
340 bfd_elf_generic_reloc, /* special_function */
341 "R_ARM_TLS_DTPOFF32", /* name */
342 TRUE, /* partial_inplace */
343 0xffffffff, /* src_mask */
344 0xffffffff, /* dst_mask */
345 FALSE), /* pcrel_offset */
347 HOWTO (R_ARM_TLS_TPOFF32, /* type */
348 0, /* rightshift */
349 2, /* size (0 = byte, 1 = short, 2 = long) */
350 32, /* bitsize */
351 FALSE, /* pc_relative */
352 0, /* bitpos */
353 complain_overflow_bitfield,/* complain_on_overflow */
354 bfd_elf_generic_reloc, /* special_function */
355 "R_ARM_TLS_TPOFF32", /* name */
356 TRUE, /* partial_inplace */
357 0xffffffff, /* src_mask */
358 0xffffffff, /* dst_mask */
359 FALSE), /* pcrel_offset */
361 /* Relocs used in ARM Linux */
363 HOWTO (R_ARM_COPY, /* type */
364 0, /* rightshift */
365 2, /* size (0 = byte, 1 = short, 2 = long) */
366 32, /* bitsize */
367 FALSE, /* pc_relative */
368 0, /* bitpos */
369 complain_overflow_bitfield,/* complain_on_overflow */
370 bfd_elf_generic_reloc, /* special_function */
371 "R_ARM_COPY", /* name */
372 TRUE, /* partial_inplace */
373 0xffffffff, /* src_mask */
374 0xffffffff, /* dst_mask */
375 FALSE), /* pcrel_offset */
377 HOWTO (R_ARM_GLOB_DAT, /* type */
378 0, /* rightshift */
379 2, /* size (0 = byte, 1 = short, 2 = long) */
380 32, /* bitsize */
381 FALSE, /* pc_relative */
382 0, /* bitpos */
383 complain_overflow_bitfield,/* complain_on_overflow */
384 bfd_elf_generic_reloc, /* special_function */
385 "R_ARM_GLOB_DAT", /* name */
386 TRUE, /* partial_inplace */
387 0xffffffff, /* src_mask */
388 0xffffffff, /* dst_mask */
389 FALSE), /* pcrel_offset */
391 HOWTO (R_ARM_JUMP_SLOT, /* type */
392 0, /* rightshift */
393 2, /* size (0 = byte, 1 = short, 2 = long) */
394 32, /* bitsize */
395 FALSE, /* pc_relative */
396 0, /* bitpos */
397 complain_overflow_bitfield,/* complain_on_overflow */
398 bfd_elf_generic_reloc, /* special_function */
399 "R_ARM_JUMP_SLOT", /* name */
400 TRUE, /* partial_inplace */
401 0xffffffff, /* src_mask */
402 0xffffffff, /* dst_mask */
403 FALSE), /* pcrel_offset */
405 HOWTO (R_ARM_RELATIVE, /* type */
406 0, /* rightshift */
407 2, /* size (0 = byte, 1 = short, 2 = long) */
408 32, /* bitsize */
409 FALSE, /* pc_relative */
410 0, /* bitpos */
411 complain_overflow_bitfield,/* complain_on_overflow */
412 bfd_elf_generic_reloc, /* special_function */
413 "R_ARM_RELATIVE", /* name */
414 TRUE, /* partial_inplace */
415 0xffffffff, /* src_mask */
416 0xffffffff, /* dst_mask */
417 FALSE), /* pcrel_offset */
419 HOWTO (R_ARM_GOTOFF32, /* type */
420 0, /* rightshift */
421 2, /* size (0 = byte, 1 = short, 2 = long) */
422 32, /* bitsize */
423 FALSE, /* pc_relative */
424 0, /* bitpos */
425 complain_overflow_bitfield,/* complain_on_overflow */
426 bfd_elf_generic_reloc, /* special_function */
427 "R_ARM_GOTOFF32", /* name */
428 TRUE, /* partial_inplace */
429 0xffffffff, /* src_mask */
430 0xffffffff, /* dst_mask */
431 FALSE), /* pcrel_offset */
433 HOWTO (R_ARM_GOTPC, /* type */
434 0, /* rightshift */
435 2, /* size (0 = byte, 1 = short, 2 = long) */
436 32, /* bitsize */
437 TRUE, /* pc_relative */
438 0, /* bitpos */
439 complain_overflow_bitfield,/* complain_on_overflow */
440 bfd_elf_generic_reloc, /* special_function */
441 "R_ARM_GOTPC", /* name */
442 TRUE, /* partial_inplace */
443 0xffffffff, /* src_mask */
444 0xffffffff, /* dst_mask */
445 TRUE), /* pcrel_offset */
447 HOWTO (R_ARM_GOT32, /* type */
448 0, /* rightshift */
449 2, /* size (0 = byte, 1 = short, 2 = long) */
450 32, /* bitsize */
451 FALSE, /* pc_relative */
452 0, /* bitpos */
453 complain_overflow_bitfield,/* complain_on_overflow */
454 bfd_elf_generic_reloc, /* special_function */
455 "R_ARM_GOT32", /* name */
456 TRUE, /* partial_inplace */
457 0xffffffff, /* src_mask */
458 0xffffffff, /* dst_mask */
459 FALSE), /* pcrel_offset */
461 HOWTO (R_ARM_PLT32, /* type */
462 2, /* rightshift */
463 2, /* size (0 = byte, 1 = short, 2 = long) */
464 24, /* bitsize */
465 TRUE, /* pc_relative */
466 0, /* bitpos */
467 complain_overflow_bitfield,/* complain_on_overflow */
468 bfd_elf_generic_reloc, /* special_function */
469 "R_ARM_PLT32", /* name */
470 FALSE, /* partial_inplace */
471 0x00ffffff, /* src_mask */
472 0x00ffffff, /* dst_mask */
473 TRUE), /* pcrel_offset */
475 HOWTO (R_ARM_CALL, /* type */
476 2, /* rightshift */
477 2, /* size (0 = byte, 1 = short, 2 = long) */
478 24, /* bitsize */
479 TRUE, /* pc_relative */
480 0, /* bitpos */
481 complain_overflow_signed,/* complain_on_overflow */
482 bfd_elf_generic_reloc, /* special_function */
483 "R_ARM_CALL", /* name */
484 FALSE, /* partial_inplace */
485 0x00ffffff, /* src_mask */
486 0x00ffffff, /* dst_mask */
487 TRUE), /* pcrel_offset */
489 HOWTO (R_ARM_JUMP24, /* type */
490 2, /* rightshift */
491 2, /* size (0 = byte, 1 = short, 2 = long) */
492 24, /* bitsize */
493 TRUE, /* pc_relative */
494 0, /* bitpos */
495 complain_overflow_signed,/* complain_on_overflow */
496 bfd_elf_generic_reloc, /* special_function */
497 "R_ARM_JUMP24", /* name */
498 FALSE, /* partial_inplace */
499 0x00ffffff, /* src_mask */
500 0x00ffffff, /* dst_mask */
501 TRUE), /* pcrel_offset */
503 HOWTO (R_ARM_THM_JUMP24, /* type */
504 1, /* rightshift */
505 2, /* size (0 = byte, 1 = short, 2 = long) */
506 24, /* bitsize */
507 TRUE, /* pc_relative */
508 0, /* bitpos */
509 complain_overflow_signed,/* complain_on_overflow */
510 bfd_elf_generic_reloc, /* special_function */
511 "R_ARM_THM_JUMP24", /* name */
512 FALSE, /* partial_inplace */
513 0x07ff2fff, /* src_mask */
514 0x07ff2fff, /* dst_mask */
515 TRUE), /* pcrel_offset */
517 HOWTO (R_ARM_BASE_ABS, /* type */
518 0, /* rightshift */
519 2, /* size (0 = byte, 1 = short, 2 = long) */
520 32, /* bitsize */
521 FALSE, /* pc_relative */
522 0, /* bitpos */
523 complain_overflow_dont,/* complain_on_overflow */
524 bfd_elf_generic_reloc, /* special_function */
525 "R_ARM_BASE_ABS", /* name */
526 FALSE, /* partial_inplace */
527 0xffffffff, /* src_mask */
528 0xffffffff, /* dst_mask */
529 FALSE), /* pcrel_offset */
531 HOWTO (R_ARM_ALU_PCREL7_0, /* type */
532 0, /* rightshift */
533 2, /* size (0 = byte, 1 = short, 2 = long) */
534 12, /* bitsize */
535 TRUE, /* pc_relative */
536 0, /* bitpos */
537 complain_overflow_dont,/* complain_on_overflow */
538 bfd_elf_generic_reloc, /* special_function */
539 "R_ARM_ALU_PCREL_7_0", /* name */
540 FALSE, /* partial_inplace */
541 0x00000fff, /* src_mask */
542 0x00000fff, /* dst_mask */
543 TRUE), /* pcrel_offset */
545 HOWTO (R_ARM_ALU_PCREL15_8, /* type */
546 0, /* rightshift */
547 2, /* size (0 = byte, 1 = short, 2 = long) */
548 12, /* bitsize */
549 TRUE, /* pc_relative */
550 8, /* bitpos */
551 complain_overflow_dont,/* complain_on_overflow */
552 bfd_elf_generic_reloc, /* special_function */
553 "R_ARM_ALU_PCREL_15_8",/* name */
554 FALSE, /* partial_inplace */
555 0x00000fff, /* src_mask */
556 0x00000fff, /* dst_mask */
557 TRUE), /* pcrel_offset */
559 HOWTO (R_ARM_ALU_PCREL23_15, /* type */
560 0, /* rightshift */
561 2, /* size (0 = byte, 1 = short, 2 = long) */
562 12, /* bitsize */
563 TRUE, /* pc_relative */
564 16, /* bitpos */
565 complain_overflow_dont,/* complain_on_overflow */
566 bfd_elf_generic_reloc, /* special_function */
567 "R_ARM_ALU_PCREL_23_15",/* name */
568 FALSE, /* partial_inplace */
569 0x00000fff, /* src_mask */
570 0x00000fff, /* dst_mask */
571 TRUE), /* pcrel_offset */
573 HOWTO (R_ARM_LDR_SBREL_11_0, /* type */
574 0, /* rightshift */
575 2, /* size (0 = byte, 1 = short, 2 = long) */
576 12, /* bitsize */
577 FALSE, /* pc_relative */
578 0, /* bitpos */
579 complain_overflow_dont,/* complain_on_overflow */
580 bfd_elf_generic_reloc, /* special_function */
581 "R_ARM_LDR_SBREL_11_0",/* name */
582 FALSE, /* partial_inplace */
583 0x00000fff, /* src_mask */
584 0x00000fff, /* dst_mask */
585 FALSE), /* pcrel_offset */
587 HOWTO (R_ARM_ALU_SBREL_19_12, /* type */
588 0, /* rightshift */
589 2, /* size (0 = byte, 1 = short, 2 = long) */
590 8, /* bitsize */
591 FALSE, /* pc_relative */
592 12, /* bitpos */
593 complain_overflow_dont,/* complain_on_overflow */
594 bfd_elf_generic_reloc, /* special_function */
595 "R_ARM_ALU_SBREL_19_12",/* name */
596 FALSE, /* partial_inplace */
597 0x000ff000, /* src_mask */
598 0x000ff000, /* dst_mask */
599 FALSE), /* pcrel_offset */
601 HOWTO (R_ARM_ALU_SBREL_27_20, /* type */
602 0, /* rightshift */
603 2, /* size (0 = byte, 1 = short, 2 = long) */
604 8, /* bitsize */
605 FALSE, /* pc_relative */
606 20, /* bitpos */
607 complain_overflow_dont,/* complain_on_overflow */
608 bfd_elf_generic_reloc, /* special_function */
609 "R_ARM_ALU_SBREL_27_20",/* name */
610 FALSE, /* partial_inplace */
611 0x0ff00000, /* src_mask */
612 0x0ff00000, /* dst_mask */
613 FALSE), /* pcrel_offset */
615 HOWTO (R_ARM_TARGET1, /* type */
616 0, /* rightshift */
617 2, /* size (0 = byte, 1 = short, 2 = long) */
618 32, /* bitsize */
619 FALSE, /* pc_relative */
620 0, /* bitpos */
621 complain_overflow_dont,/* complain_on_overflow */
622 bfd_elf_generic_reloc, /* special_function */
623 "R_ARM_TARGET1", /* name */
624 FALSE, /* partial_inplace */
625 0xffffffff, /* src_mask */
626 0xffffffff, /* dst_mask */
627 FALSE), /* pcrel_offset */
629 HOWTO (R_ARM_ROSEGREL32, /* type */
630 0, /* rightshift */
631 2, /* size (0 = byte, 1 = short, 2 = long) */
632 32, /* bitsize */
633 FALSE, /* pc_relative */
634 0, /* bitpos */
635 complain_overflow_dont,/* complain_on_overflow */
636 bfd_elf_generic_reloc, /* special_function */
637 "R_ARM_ROSEGREL32", /* name */
638 FALSE, /* partial_inplace */
639 0xffffffff, /* src_mask */
640 0xffffffff, /* dst_mask */
641 FALSE), /* pcrel_offset */
643 HOWTO (R_ARM_V4BX, /* type */
644 0, /* rightshift */
645 2, /* size (0 = byte, 1 = short, 2 = long) */
646 32, /* bitsize */
647 FALSE, /* pc_relative */
648 0, /* bitpos */
649 complain_overflow_dont,/* complain_on_overflow */
650 bfd_elf_generic_reloc, /* special_function */
651 "R_ARM_V4BX", /* name */
652 FALSE, /* partial_inplace */
653 0xffffffff, /* src_mask */
654 0xffffffff, /* dst_mask */
655 FALSE), /* pcrel_offset */
657 HOWTO (R_ARM_TARGET2, /* type */
658 0, /* rightshift */
659 2, /* size (0 = byte, 1 = short, 2 = long) */
660 32, /* bitsize */
661 FALSE, /* pc_relative */
662 0, /* bitpos */
663 complain_overflow_signed,/* complain_on_overflow */
664 bfd_elf_generic_reloc, /* special_function */
665 "R_ARM_TARGET2", /* name */
666 FALSE, /* partial_inplace */
667 0xffffffff, /* src_mask */
668 0xffffffff, /* dst_mask */
669 TRUE), /* pcrel_offset */
671 HOWTO (R_ARM_PREL31, /* type */
672 0, /* rightshift */
673 2, /* size (0 = byte, 1 = short, 2 = long) */
674 31, /* bitsize */
675 TRUE, /* pc_relative */
676 0, /* bitpos */
677 complain_overflow_signed,/* complain_on_overflow */
678 bfd_elf_generic_reloc, /* special_function */
679 "R_ARM_PREL31", /* name */
680 FALSE, /* partial_inplace */
681 0x7fffffff, /* src_mask */
682 0x7fffffff, /* dst_mask */
683 TRUE), /* pcrel_offset */
685 HOWTO (R_ARM_MOVW_ABS_NC, /* type */
686 0, /* rightshift */
687 2, /* size (0 = byte, 1 = short, 2 = long) */
688 16, /* bitsize */
689 FALSE, /* pc_relative */
690 0, /* bitpos */
691 complain_overflow_dont,/* complain_on_overflow */
692 bfd_elf_generic_reloc, /* special_function */
693 "R_ARM_MOVW_ABS_NC", /* name */
694 FALSE, /* partial_inplace */
695 0x000f0fff, /* src_mask */
696 0x000f0fff, /* dst_mask */
697 FALSE), /* pcrel_offset */
699 HOWTO (R_ARM_MOVT_ABS, /* type */
700 0, /* rightshift */
701 2, /* size (0 = byte, 1 = short, 2 = long) */
702 16, /* bitsize */
703 FALSE, /* pc_relative */
704 0, /* bitpos */
705 complain_overflow_bitfield,/* complain_on_overflow */
706 bfd_elf_generic_reloc, /* special_function */
707 "R_ARM_MOVT_ABS", /* name */
708 FALSE, /* partial_inplace */
709 0x000f0fff, /* src_mask */
710 0x000f0fff, /* dst_mask */
711 FALSE), /* pcrel_offset */
713 HOWTO (R_ARM_MOVW_PREL_NC, /* type */
714 0, /* rightshift */
715 2, /* size (0 = byte, 1 = short, 2 = long) */
716 16, /* bitsize */
717 TRUE, /* pc_relative */
718 0, /* bitpos */
719 complain_overflow_dont,/* complain_on_overflow */
720 bfd_elf_generic_reloc, /* special_function */
721 "R_ARM_MOVW_PREL_NC", /* name */
722 FALSE, /* partial_inplace */
723 0x000f0fff, /* src_mask */
724 0x000f0fff, /* dst_mask */
725 TRUE), /* pcrel_offset */
727 HOWTO (R_ARM_MOVT_PREL, /* type */
728 0, /* rightshift */
729 2, /* size (0 = byte, 1 = short, 2 = long) */
730 16, /* bitsize */
731 TRUE, /* pc_relative */
732 0, /* bitpos */
733 complain_overflow_bitfield,/* complain_on_overflow */
734 bfd_elf_generic_reloc, /* special_function */
735 "R_ARM_MOVT_PREL", /* name */
736 FALSE, /* partial_inplace */
737 0x000f0fff, /* src_mask */
738 0x000f0fff, /* dst_mask */
739 TRUE), /* pcrel_offset */
741 HOWTO (R_ARM_THM_MOVW_ABS_NC, /* type */
742 0, /* rightshift */
743 2, /* size (0 = byte, 1 = short, 2 = long) */
744 16, /* bitsize */
745 FALSE, /* pc_relative */
746 0, /* bitpos */
747 complain_overflow_dont,/* complain_on_overflow */
748 bfd_elf_generic_reloc, /* special_function */
749 "R_ARM_THM_MOVW_ABS_NC",/* name */
750 FALSE, /* partial_inplace */
751 0x040f70ff, /* src_mask */
752 0x040f70ff, /* dst_mask */
753 FALSE), /* pcrel_offset */
755 HOWTO (R_ARM_THM_MOVT_ABS, /* type */
756 0, /* rightshift */
757 2, /* size (0 = byte, 1 = short, 2 = long) */
758 16, /* bitsize */
759 FALSE, /* pc_relative */
760 0, /* bitpos */
761 complain_overflow_bitfield,/* complain_on_overflow */
762 bfd_elf_generic_reloc, /* special_function */
763 "R_ARM_THM_MOVT_ABS", /* name */
764 FALSE, /* partial_inplace */
765 0x040f70ff, /* src_mask */
766 0x040f70ff, /* dst_mask */
767 FALSE), /* pcrel_offset */
769 HOWTO (R_ARM_THM_MOVW_PREL_NC,/* type */
770 0, /* rightshift */
771 2, /* size (0 = byte, 1 = short, 2 = long) */
772 16, /* bitsize */
773 TRUE, /* pc_relative */
774 0, /* bitpos */
775 complain_overflow_dont,/* complain_on_overflow */
776 bfd_elf_generic_reloc, /* special_function */
777 "R_ARM_THM_MOVW_PREL_NC",/* name */
778 FALSE, /* partial_inplace */
779 0x040f70ff, /* src_mask */
780 0x040f70ff, /* dst_mask */
781 TRUE), /* pcrel_offset */
783 HOWTO (R_ARM_THM_MOVT_PREL, /* type */
784 0, /* rightshift */
785 2, /* size (0 = byte, 1 = short, 2 = long) */
786 16, /* bitsize */
787 TRUE, /* pc_relative */
788 0, /* bitpos */
789 complain_overflow_bitfield,/* complain_on_overflow */
790 bfd_elf_generic_reloc, /* special_function */
791 "R_ARM_THM_MOVT_PREL", /* name */
792 FALSE, /* partial_inplace */
793 0x040f70ff, /* src_mask */
794 0x040f70ff, /* dst_mask */
795 TRUE), /* pcrel_offset */
797 HOWTO (R_ARM_THM_JUMP19, /* type */
798 1, /* rightshift */
799 2, /* size (0 = byte, 1 = short, 2 = long) */
800 19, /* bitsize */
801 TRUE, /* pc_relative */
802 0, /* bitpos */
803 complain_overflow_signed,/* complain_on_overflow */
804 bfd_elf_generic_reloc, /* special_function */
805 "R_ARM_THM_JUMP19", /* name */
806 FALSE, /* partial_inplace */
807 0x043f2fff, /* src_mask */
808 0x043f2fff, /* dst_mask */
809 TRUE), /* pcrel_offset */
811 HOWTO (R_ARM_THM_JUMP6, /* type */
812 1, /* rightshift */
813 1, /* size (0 = byte, 1 = short, 2 = long) */
814 6, /* bitsize */
815 TRUE, /* pc_relative */
816 0, /* bitpos */
817 complain_overflow_unsigned,/* complain_on_overflow */
818 bfd_elf_generic_reloc, /* special_function */
819 "R_ARM_THM_JUMP6", /* name */
820 FALSE, /* partial_inplace */
821 0x02f8, /* src_mask */
822 0x02f8, /* dst_mask */
823 TRUE), /* pcrel_offset */
825 /* These are declared as 13-bit signed relocations because we can
826 address -4095 .. 4095(base) by altering ADDW to SUBW or vice
827 versa. */
828 HOWTO (R_ARM_THM_ALU_PREL_11_0,/* type */
829 0, /* rightshift */
830 2, /* size (0 = byte, 1 = short, 2 = long) */
831 13, /* bitsize */
832 TRUE, /* pc_relative */
833 0, /* bitpos */
834 complain_overflow_dont,/* complain_on_overflow */
835 bfd_elf_generic_reloc, /* special_function */
836 "R_ARM_THM_ALU_PREL_11_0",/* name */
837 FALSE, /* partial_inplace */
838 0xffffffff, /* src_mask */
839 0xffffffff, /* dst_mask */
840 TRUE), /* pcrel_offset */
842 HOWTO (R_ARM_THM_PC12, /* type */
843 0, /* rightshift */
844 2, /* size (0 = byte, 1 = short, 2 = long) */
845 13, /* bitsize */
846 TRUE, /* pc_relative */
847 0, /* bitpos */
848 complain_overflow_dont,/* complain_on_overflow */
849 bfd_elf_generic_reloc, /* special_function */
850 "R_ARM_THM_PC12", /* name */
851 FALSE, /* partial_inplace */
852 0xffffffff, /* src_mask */
853 0xffffffff, /* dst_mask */
854 TRUE), /* pcrel_offset */
856 HOWTO (R_ARM_ABS32_NOI, /* type */
857 0, /* rightshift */
858 2, /* size (0 = byte, 1 = short, 2 = long) */
859 32, /* bitsize */
860 FALSE, /* pc_relative */
861 0, /* bitpos */
862 complain_overflow_dont,/* complain_on_overflow */
863 bfd_elf_generic_reloc, /* special_function */
864 "R_ARM_ABS32_NOI", /* name */
865 FALSE, /* partial_inplace */
866 0xffffffff, /* src_mask */
867 0xffffffff, /* dst_mask */
868 FALSE), /* pcrel_offset */
870 HOWTO (R_ARM_REL32_NOI, /* type */
871 0, /* rightshift */
872 2, /* size (0 = byte, 1 = short, 2 = long) */
873 32, /* bitsize */
874 TRUE, /* pc_relative */
875 0, /* bitpos */
876 complain_overflow_dont,/* complain_on_overflow */
877 bfd_elf_generic_reloc, /* special_function */
878 "R_ARM_REL32_NOI", /* name */
879 FALSE, /* partial_inplace */
880 0xffffffff, /* src_mask */
881 0xffffffff, /* dst_mask */
882 FALSE), /* pcrel_offset */
884 /* Group relocations. */
886 HOWTO (R_ARM_ALU_PC_G0_NC, /* type */
887 0, /* rightshift */
888 2, /* size (0 = byte, 1 = short, 2 = long) */
889 32, /* bitsize */
890 TRUE, /* pc_relative */
891 0, /* bitpos */
892 complain_overflow_dont,/* complain_on_overflow */
893 bfd_elf_generic_reloc, /* special_function */
894 "R_ARM_ALU_PC_G0_NC", /* name */
895 FALSE, /* partial_inplace */
896 0xffffffff, /* src_mask */
897 0xffffffff, /* dst_mask */
898 TRUE), /* pcrel_offset */
900 HOWTO (R_ARM_ALU_PC_G0, /* type */
901 0, /* rightshift */
902 2, /* size (0 = byte, 1 = short, 2 = long) */
903 32, /* bitsize */
904 TRUE, /* pc_relative */
905 0, /* bitpos */
906 complain_overflow_dont,/* complain_on_overflow */
907 bfd_elf_generic_reloc, /* special_function */
908 "R_ARM_ALU_PC_G0", /* name */
909 FALSE, /* partial_inplace */
910 0xffffffff, /* src_mask */
911 0xffffffff, /* dst_mask */
912 TRUE), /* pcrel_offset */
914 HOWTO (R_ARM_ALU_PC_G1_NC, /* type */
915 0, /* rightshift */
916 2, /* size (0 = byte, 1 = short, 2 = long) */
917 32, /* bitsize */
918 TRUE, /* pc_relative */
919 0, /* bitpos */
920 complain_overflow_dont,/* complain_on_overflow */
921 bfd_elf_generic_reloc, /* special_function */
922 "R_ARM_ALU_PC_G1_NC", /* name */
923 FALSE, /* partial_inplace */
924 0xffffffff, /* src_mask */
925 0xffffffff, /* dst_mask */
926 TRUE), /* pcrel_offset */
928 HOWTO (R_ARM_ALU_PC_G1, /* type */
929 0, /* rightshift */
930 2, /* size (0 = byte, 1 = short, 2 = long) */
931 32, /* bitsize */
932 TRUE, /* pc_relative */
933 0, /* bitpos */
934 complain_overflow_dont,/* complain_on_overflow */
935 bfd_elf_generic_reloc, /* special_function */
936 "R_ARM_ALU_PC_G1", /* name */
937 FALSE, /* partial_inplace */
938 0xffffffff, /* src_mask */
939 0xffffffff, /* dst_mask */
940 TRUE), /* pcrel_offset */
942 HOWTO (R_ARM_ALU_PC_G2, /* type */
943 0, /* rightshift */
944 2, /* size (0 = byte, 1 = short, 2 = long) */
945 32, /* bitsize */
946 TRUE, /* pc_relative */
947 0, /* bitpos */
948 complain_overflow_dont,/* complain_on_overflow */
949 bfd_elf_generic_reloc, /* special_function */
950 "R_ARM_ALU_PC_G2", /* name */
951 FALSE, /* partial_inplace */
952 0xffffffff, /* src_mask */
953 0xffffffff, /* dst_mask */
954 TRUE), /* pcrel_offset */
956 HOWTO (R_ARM_LDR_PC_G1, /* type */
957 0, /* rightshift */
958 2, /* size (0 = byte, 1 = short, 2 = long) */
959 32, /* bitsize */
960 TRUE, /* pc_relative */
961 0, /* bitpos */
962 complain_overflow_dont,/* complain_on_overflow */
963 bfd_elf_generic_reloc, /* special_function */
964 "R_ARM_LDR_PC_G1", /* name */
965 FALSE, /* partial_inplace */
966 0xffffffff, /* src_mask */
967 0xffffffff, /* dst_mask */
968 TRUE), /* pcrel_offset */
970 HOWTO (R_ARM_LDR_PC_G2, /* type */
971 0, /* rightshift */
972 2, /* size (0 = byte, 1 = short, 2 = long) */
973 32, /* bitsize */
974 TRUE, /* pc_relative */
975 0, /* bitpos */
976 complain_overflow_dont,/* complain_on_overflow */
977 bfd_elf_generic_reloc, /* special_function */
978 "R_ARM_LDR_PC_G2", /* name */
979 FALSE, /* partial_inplace */
980 0xffffffff, /* src_mask */
981 0xffffffff, /* dst_mask */
982 TRUE), /* pcrel_offset */
984 HOWTO (R_ARM_LDRS_PC_G0, /* type */
985 0, /* rightshift */
986 2, /* size (0 = byte, 1 = short, 2 = long) */
987 32, /* bitsize */
988 TRUE, /* pc_relative */
989 0, /* bitpos */
990 complain_overflow_dont,/* complain_on_overflow */
991 bfd_elf_generic_reloc, /* special_function */
992 "R_ARM_LDRS_PC_G0", /* name */
993 FALSE, /* partial_inplace */
994 0xffffffff, /* src_mask */
995 0xffffffff, /* dst_mask */
996 TRUE), /* pcrel_offset */
998 HOWTO (R_ARM_LDRS_PC_G1, /* type */
999 0, /* rightshift */
1000 2, /* size (0 = byte, 1 = short, 2 = long) */
1001 32, /* bitsize */
1002 TRUE, /* pc_relative */
1003 0, /* bitpos */
1004 complain_overflow_dont,/* complain_on_overflow */
1005 bfd_elf_generic_reloc, /* special_function */
1006 "R_ARM_LDRS_PC_G1", /* name */
1007 FALSE, /* partial_inplace */
1008 0xffffffff, /* src_mask */
1009 0xffffffff, /* dst_mask */
1010 TRUE), /* pcrel_offset */
1012 HOWTO (R_ARM_LDRS_PC_G2, /* type */
1013 0, /* rightshift */
1014 2, /* size (0 = byte, 1 = short, 2 = long) */
1015 32, /* bitsize */
1016 TRUE, /* pc_relative */
1017 0, /* bitpos */
1018 complain_overflow_dont,/* complain_on_overflow */
1019 bfd_elf_generic_reloc, /* special_function */
1020 "R_ARM_LDRS_PC_G2", /* name */
1021 FALSE, /* partial_inplace */
1022 0xffffffff, /* src_mask */
1023 0xffffffff, /* dst_mask */
1024 TRUE), /* pcrel_offset */
1026 HOWTO (R_ARM_LDC_PC_G0, /* type */
1027 0, /* rightshift */
1028 2, /* size (0 = byte, 1 = short, 2 = long) */
1029 32, /* bitsize */
1030 TRUE, /* pc_relative */
1031 0, /* bitpos */
1032 complain_overflow_dont,/* complain_on_overflow */
1033 bfd_elf_generic_reloc, /* special_function */
1034 "R_ARM_LDC_PC_G0", /* name */
1035 FALSE, /* partial_inplace */
1036 0xffffffff, /* src_mask */
1037 0xffffffff, /* dst_mask */
1038 TRUE), /* pcrel_offset */
1040 HOWTO (R_ARM_LDC_PC_G1, /* type */
1041 0, /* rightshift */
1042 2, /* size (0 = byte, 1 = short, 2 = long) */
1043 32, /* bitsize */
1044 TRUE, /* pc_relative */
1045 0, /* bitpos */
1046 complain_overflow_dont,/* complain_on_overflow */
1047 bfd_elf_generic_reloc, /* special_function */
1048 "R_ARM_LDC_PC_G1", /* name */
1049 FALSE, /* partial_inplace */
1050 0xffffffff, /* src_mask */
1051 0xffffffff, /* dst_mask */
1052 TRUE), /* pcrel_offset */
1054 HOWTO (R_ARM_LDC_PC_G2, /* type */
1055 0, /* rightshift */
1056 2, /* size (0 = byte, 1 = short, 2 = long) */
1057 32, /* bitsize */
1058 TRUE, /* pc_relative */
1059 0, /* bitpos */
1060 complain_overflow_dont,/* complain_on_overflow */
1061 bfd_elf_generic_reloc, /* special_function */
1062 "R_ARM_LDC_PC_G2", /* name */
1063 FALSE, /* partial_inplace */
1064 0xffffffff, /* src_mask */
1065 0xffffffff, /* dst_mask */
1066 TRUE), /* pcrel_offset */
1068 HOWTO (R_ARM_ALU_SB_G0_NC, /* type */
1069 0, /* rightshift */
1070 2, /* size (0 = byte, 1 = short, 2 = long) */
1071 32, /* bitsize */
1072 TRUE, /* pc_relative */
1073 0, /* bitpos */
1074 complain_overflow_dont,/* complain_on_overflow */
1075 bfd_elf_generic_reloc, /* special_function */
1076 "R_ARM_ALU_SB_G0_NC", /* name */
1077 FALSE, /* partial_inplace */
1078 0xffffffff, /* src_mask */
1079 0xffffffff, /* dst_mask */
1080 TRUE), /* pcrel_offset */
1082 HOWTO (R_ARM_ALU_SB_G0, /* type */
1083 0, /* rightshift */
1084 2, /* size (0 = byte, 1 = short, 2 = long) */
1085 32, /* bitsize */
1086 TRUE, /* pc_relative */
1087 0, /* bitpos */
1088 complain_overflow_dont,/* complain_on_overflow */
1089 bfd_elf_generic_reloc, /* special_function */
1090 "R_ARM_ALU_SB_G0", /* name */
1091 FALSE, /* partial_inplace */
1092 0xffffffff, /* src_mask */
1093 0xffffffff, /* dst_mask */
1094 TRUE), /* pcrel_offset */
1096 HOWTO (R_ARM_ALU_SB_G1_NC, /* type */
1097 0, /* rightshift */
1098 2, /* size (0 = byte, 1 = short, 2 = long) */
1099 32, /* bitsize */
1100 TRUE, /* pc_relative */
1101 0, /* bitpos */
1102 complain_overflow_dont,/* complain_on_overflow */
1103 bfd_elf_generic_reloc, /* special_function */
1104 "R_ARM_ALU_SB_G1_NC", /* name */
1105 FALSE, /* partial_inplace */
1106 0xffffffff, /* src_mask */
1107 0xffffffff, /* dst_mask */
1108 TRUE), /* pcrel_offset */
1110 HOWTO (R_ARM_ALU_SB_G1, /* type */
1111 0, /* rightshift */
1112 2, /* size (0 = byte, 1 = short, 2 = long) */
1113 32, /* bitsize */
1114 TRUE, /* pc_relative */
1115 0, /* bitpos */
1116 complain_overflow_dont,/* complain_on_overflow */
1117 bfd_elf_generic_reloc, /* special_function */
1118 "R_ARM_ALU_SB_G1", /* name */
1119 FALSE, /* partial_inplace */
1120 0xffffffff, /* src_mask */
1121 0xffffffff, /* dst_mask */
1122 TRUE), /* pcrel_offset */
1124 HOWTO (R_ARM_ALU_SB_G2, /* type */
1125 0, /* rightshift */
1126 2, /* size (0 = byte, 1 = short, 2 = long) */
1127 32, /* bitsize */
1128 TRUE, /* pc_relative */
1129 0, /* bitpos */
1130 complain_overflow_dont,/* complain_on_overflow */
1131 bfd_elf_generic_reloc, /* special_function */
1132 "R_ARM_ALU_SB_G2", /* name */
1133 FALSE, /* partial_inplace */
1134 0xffffffff, /* src_mask */
1135 0xffffffff, /* dst_mask */
1136 TRUE), /* pcrel_offset */
1138 HOWTO (R_ARM_LDR_SB_G0, /* type */
1139 0, /* rightshift */
1140 2, /* size (0 = byte, 1 = short, 2 = long) */
1141 32, /* bitsize */
1142 TRUE, /* pc_relative */
1143 0, /* bitpos */
1144 complain_overflow_dont,/* complain_on_overflow */
1145 bfd_elf_generic_reloc, /* special_function */
1146 "R_ARM_LDR_SB_G0", /* name */
1147 FALSE, /* partial_inplace */
1148 0xffffffff, /* src_mask */
1149 0xffffffff, /* dst_mask */
1150 TRUE), /* pcrel_offset */
1152 HOWTO (R_ARM_LDR_SB_G1, /* type */
1153 0, /* rightshift */
1154 2, /* size (0 = byte, 1 = short, 2 = long) */
1155 32, /* bitsize */
1156 TRUE, /* pc_relative */
1157 0, /* bitpos */
1158 complain_overflow_dont,/* complain_on_overflow */
1159 bfd_elf_generic_reloc, /* special_function */
1160 "R_ARM_LDR_SB_G1", /* name */
1161 FALSE, /* partial_inplace */
1162 0xffffffff, /* src_mask */
1163 0xffffffff, /* dst_mask */
1164 TRUE), /* pcrel_offset */
1166 HOWTO (R_ARM_LDR_SB_G2, /* type */
1167 0, /* rightshift */
1168 2, /* size (0 = byte, 1 = short, 2 = long) */
1169 32, /* bitsize */
1170 TRUE, /* pc_relative */
1171 0, /* bitpos */
1172 complain_overflow_dont,/* complain_on_overflow */
1173 bfd_elf_generic_reloc, /* special_function */
1174 "R_ARM_LDR_SB_G2", /* name */
1175 FALSE, /* partial_inplace */
1176 0xffffffff, /* src_mask */
1177 0xffffffff, /* dst_mask */
1178 TRUE), /* pcrel_offset */
1180 HOWTO (R_ARM_LDRS_SB_G0, /* type */
1181 0, /* rightshift */
1182 2, /* size (0 = byte, 1 = short, 2 = long) */
1183 32, /* bitsize */
1184 TRUE, /* pc_relative */
1185 0, /* bitpos */
1186 complain_overflow_dont,/* complain_on_overflow */
1187 bfd_elf_generic_reloc, /* special_function */
1188 "R_ARM_LDRS_SB_G0", /* name */
1189 FALSE, /* partial_inplace */
1190 0xffffffff, /* src_mask */
1191 0xffffffff, /* dst_mask */
1192 TRUE), /* pcrel_offset */
1194 HOWTO (R_ARM_LDRS_SB_G1, /* type */
1195 0, /* rightshift */
1196 2, /* size (0 = byte, 1 = short, 2 = long) */
1197 32, /* bitsize */
1198 TRUE, /* pc_relative */
1199 0, /* bitpos */
1200 complain_overflow_dont,/* complain_on_overflow */
1201 bfd_elf_generic_reloc, /* special_function */
1202 "R_ARM_LDRS_SB_G1", /* name */
1203 FALSE, /* partial_inplace */
1204 0xffffffff, /* src_mask */
1205 0xffffffff, /* dst_mask */
1206 TRUE), /* pcrel_offset */
1208 HOWTO (R_ARM_LDRS_SB_G2, /* type */
1209 0, /* rightshift */
1210 2, /* size (0 = byte, 1 = short, 2 = long) */
1211 32, /* bitsize */
1212 TRUE, /* pc_relative */
1213 0, /* bitpos */
1214 complain_overflow_dont,/* complain_on_overflow */
1215 bfd_elf_generic_reloc, /* special_function */
1216 "R_ARM_LDRS_SB_G2", /* name */
1217 FALSE, /* partial_inplace */
1218 0xffffffff, /* src_mask */
1219 0xffffffff, /* dst_mask */
1220 TRUE), /* pcrel_offset */
1222 HOWTO (R_ARM_LDC_SB_G0, /* type */
1223 0, /* rightshift */
1224 2, /* size (0 = byte, 1 = short, 2 = long) */
1225 32, /* bitsize */
1226 TRUE, /* pc_relative */
1227 0, /* bitpos */
1228 complain_overflow_dont,/* complain_on_overflow */
1229 bfd_elf_generic_reloc, /* special_function */
1230 "R_ARM_LDC_SB_G0", /* name */
1231 FALSE, /* partial_inplace */
1232 0xffffffff, /* src_mask */
1233 0xffffffff, /* dst_mask */
1234 TRUE), /* pcrel_offset */
1236 HOWTO (R_ARM_LDC_SB_G1, /* type */
1237 0, /* rightshift */
1238 2, /* size (0 = byte, 1 = short, 2 = long) */
1239 32, /* bitsize */
1240 TRUE, /* pc_relative */
1241 0, /* bitpos */
1242 complain_overflow_dont,/* complain_on_overflow */
1243 bfd_elf_generic_reloc, /* special_function */
1244 "R_ARM_LDC_SB_G1", /* name */
1245 FALSE, /* partial_inplace */
1246 0xffffffff, /* src_mask */
1247 0xffffffff, /* dst_mask */
1248 TRUE), /* pcrel_offset */
1250 HOWTO (R_ARM_LDC_SB_G2, /* type */
1251 0, /* rightshift */
1252 2, /* size (0 = byte, 1 = short, 2 = long) */
1253 32, /* bitsize */
1254 TRUE, /* pc_relative */
1255 0, /* bitpos */
1256 complain_overflow_dont,/* complain_on_overflow */
1257 bfd_elf_generic_reloc, /* special_function */
1258 "R_ARM_LDC_SB_G2", /* name */
1259 FALSE, /* partial_inplace */
1260 0xffffffff, /* src_mask */
1261 0xffffffff, /* dst_mask */
1262 TRUE), /* pcrel_offset */
1264 /* End of group relocations. */
1266 HOWTO (R_ARM_MOVW_BREL_NC, /* type */
1267 0, /* rightshift */
1268 2, /* size (0 = byte, 1 = short, 2 = long) */
1269 16, /* bitsize */
1270 FALSE, /* pc_relative */
1271 0, /* bitpos */
1272 complain_overflow_dont,/* complain_on_overflow */
1273 bfd_elf_generic_reloc, /* special_function */
1274 "R_ARM_MOVW_BREL_NC", /* name */
1275 FALSE, /* partial_inplace */
1276 0x0000ffff, /* src_mask */
1277 0x0000ffff, /* dst_mask */
1278 FALSE), /* pcrel_offset */
1280 HOWTO (R_ARM_MOVT_BREL, /* type */
1281 0, /* rightshift */
1282 2, /* size (0 = byte, 1 = short, 2 = long) */
1283 16, /* bitsize */
1284 FALSE, /* pc_relative */
1285 0, /* bitpos */
1286 complain_overflow_bitfield,/* complain_on_overflow */
1287 bfd_elf_generic_reloc, /* special_function */
1288 "R_ARM_MOVT_BREL", /* name */
1289 FALSE, /* partial_inplace */
1290 0x0000ffff, /* src_mask */
1291 0x0000ffff, /* dst_mask */
1292 FALSE), /* pcrel_offset */
1294 HOWTO (R_ARM_MOVW_BREL, /* type */
1295 0, /* rightshift */
1296 2, /* size (0 = byte, 1 = short, 2 = long) */
1297 16, /* bitsize */
1298 FALSE, /* pc_relative */
1299 0, /* bitpos */
1300 complain_overflow_dont,/* complain_on_overflow */
1301 bfd_elf_generic_reloc, /* special_function */
1302 "R_ARM_MOVW_BREL", /* name */
1303 FALSE, /* partial_inplace */
1304 0x0000ffff, /* src_mask */
1305 0x0000ffff, /* dst_mask */
1306 FALSE), /* pcrel_offset */
1308 HOWTO (R_ARM_THM_MOVW_BREL_NC,/* type */
1309 0, /* rightshift */
1310 2, /* size (0 = byte, 1 = short, 2 = long) */
1311 16, /* bitsize */
1312 FALSE, /* pc_relative */
1313 0, /* bitpos */
1314 complain_overflow_dont,/* complain_on_overflow */
1315 bfd_elf_generic_reloc, /* special_function */
1316 "R_ARM_THM_MOVW_BREL_NC",/* name */
1317 FALSE, /* partial_inplace */
1318 0x040f70ff, /* src_mask */
1319 0x040f70ff, /* dst_mask */
1320 FALSE), /* pcrel_offset */
1322 HOWTO (R_ARM_THM_MOVT_BREL, /* type */
1323 0, /* rightshift */
1324 2, /* size (0 = byte, 1 = short, 2 = long) */
1325 16, /* bitsize */
1326 FALSE, /* pc_relative */
1327 0, /* bitpos */
1328 complain_overflow_bitfield,/* complain_on_overflow */
1329 bfd_elf_generic_reloc, /* special_function */
1330 "R_ARM_THM_MOVT_BREL", /* name */
1331 FALSE, /* partial_inplace */
1332 0x040f70ff, /* src_mask */
1333 0x040f70ff, /* dst_mask */
1334 FALSE), /* pcrel_offset */
1336 HOWTO (R_ARM_THM_MOVW_BREL, /* type */
1337 0, /* rightshift */
1338 2, /* size (0 = byte, 1 = short, 2 = long) */
1339 16, /* bitsize */
1340 FALSE, /* pc_relative */
1341 0, /* bitpos */
1342 complain_overflow_dont,/* complain_on_overflow */
1343 bfd_elf_generic_reloc, /* special_function */
1344 "R_ARM_THM_MOVW_BREL", /* name */
1345 FALSE, /* partial_inplace */
1346 0x040f70ff, /* src_mask */
1347 0x040f70ff, /* dst_mask */
1348 FALSE), /* pcrel_offset */
1350 EMPTY_HOWTO (90), /* Unallocated. */
1351 EMPTY_HOWTO (91),
1352 EMPTY_HOWTO (92),
1353 EMPTY_HOWTO (93),
1355 HOWTO (R_ARM_PLT32_ABS, /* type */
1356 0, /* rightshift */
1357 2, /* size (0 = byte, 1 = short, 2 = long) */
1358 32, /* bitsize */
1359 FALSE, /* pc_relative */
1360 0, /* bitpos */
1361 complain_overflow_dont,/* complain_on_overflow */
1362 bfd_elf_generic_reloc, /* special_function */
1363 "R_ARM_PLT32_ABS", /* name */
1364 FALSE, /* partial_inplace */
1365 0xffffffff, /* src_mask */
1366 0xffffffff, /* dst_mask */
1367 FALSE), /* pcrel_offset */
1369 HOWTO (R_ARM_GOT_ABS, /* type */
1370 0, /* rightshift */
1371 2, /* size (0 = byte, 1 = short, 2 = long) */
1372 32, /* bitsize */
1373 FALSE, /* pc_relative */
1374 0, /* bitpos */
1375 complain_overflow_dont,/* complain_on_overflow */
1376 bfd_elf_generic_reloc, /* special_function */
1377 "R_ARM_GOT_ABS", /* name */
1378 FALSE, /* partial_inplace */
1379 0xffffffff, /* src_mask */
1380 0xffffffff, /* dst_mask */
1381 FALSE), /* pcrel_offset */
1383 HOWTO (R_ARM_GOT_PREL, /* type */
1384 0, /* rightshift */
1385 2, /* size (0 = byte, 1 = short, 2 = long) */
1386 32, /* bitsize */
1387 TRUE, /* pc_relative */
1388 0, /* bitpos */
1389 complain_overflow_dont, /* complain_on_overflow */
1390 bfd_elf_generic_reloc, /* special_function */
1391 "R_ARM_GOT_PREL", /* name */
1392 FALSE, /* partial_inplace */
1393 0xffffffff, /* src_mask */
1394 0xffffffff, /* dst_mask */
1395 TRUE), /* pcrel_offset */
1397 HOWTO (R_ARM_GOT_BREL12, /* type */
1398 0, /* rightshift */
1399 2, /* size (0 = byte, 1 = short, 2 = long) */
1400 12, /* bitsize */
1401 FALSE, /* pc_relative */
1402 0, /* bitpos */
1403 complain_overflow_bitfield,/* complain_on_overflow */
1404 bfd_elf_generic_reloc, /* special_function */
1405 "R_ARM_GOT_BREL12", /* name */
1406 FALSE, /* partial_inplace */
1407 0x00000fff, /* src_mask */
1408 0x00000fff, /* dst_mask */
1409 FALSE), /* pcrel_offset */
1411 HOWTO (R_ARM_GOTOFF12, /* type */
1412 0, /* rightshift */
1413 2, /* size (0 = byte, 1 = short, 2 = long) */
1414 12, /* bitsize */
1415 FALSE, /* pc_relative */
1416 0, /* bitpos */
1417 complain_overflow_bitfield,/* complain_on_overflow */
1418 bfd_elf_generic_reloc, /* special_function */
1419 "R_ARM_GOTOFF12", /* name */
1420 FALSE, /* partial_inplace */
1421 0x00000fff, /* src_mask */
1422 0x00000fff, /* dst_mask */
1423 FALSE), /* pcrel_offset */
1425 EMPTY_HOWTO (R_ARM_GOTRELAX), /* reserved for future GOT-load optimizations */
1427 /* GNU extension to record C++ vtable member usage */
1428 HOWTO (R_ARM_GNU_VTENTRY, /* type */
1429 0, /* rightshift */
1430 2, /* size (0 = byte, 1 = short, 2 = long) */
1431 0, /* bitsize */
1432 FALSE, /* pc_relative */
1433 0, /* bitpos */
1434 complain_overflow_dont, /* complain_on_overflow */
1435 _bfd_elf_rel_vtable_reloc_fn, /* special_function */
1436 "R_ARM_GNU_VTENTRY", /* name */
1437 FALSE, /* partial_inplace */
1438 0, /* src_mask */
1439 0, /* dst_mask */
1440 FALSE), /* pcrel_offset */
1442 /* GNU extension to record C++ vtable hierarchy */
1443 HOWTO (R_ARM_GNU_VTINHERIT, /* type */
1444 0, /* rightshift */
1445 2, /* size (0 = byte, 1 = short, 2 = long) */
1446 0, /* bitsize */
1447 FALSE, /* pc_relative */
1448 0, /* bitpos */
1449 complain_overflow_dont, /* complain_on_overflow */
1450 NULL, /* special_function */
1451 "R_ARM_GNU_VTINHERIT", /* name */
1452 FALSE, /* partial_inplace */
1453 0, /* src_mask */
1454 0, /* dst_mask */
1455 FALSE), /* pcrel_offset */
1457 HOWTO (R_ARM_THM_JUMP11, /* type */
1458 1, /* rightshift */
1459 1, /* size (0 = byte, 1 = short, 2 = long) */
1460 11, /* bitsize */
1461 TRUE, /* pc_relative */
1462 0, /* bitpos */
1463 complain_overflow_signed, /* complain_on_overflow */
1464 bfd_elf_generic_reloc, /* special_function */
1465 "R_ARM_THM_JUMP11", /* name */
1466 FALSE, /* partial_inplace */
1467 0x000007ff, /* src_mask */
1468 0x000007ff, /* dst_mask */
1469 TRUE), /* pcrel_offset */
1471 HOWTO (R_ARM_THM_JUMP8, /* type */
1472 1, /* rightshift */
1473 1, /* size (0 = byte, 1 = short, 2 = long) */
1474 8, /* bitsize */
1475 TRUE, /* pc_relative */
1476 0, /* bitpos */
1477 complain_overflow_signed, /* complain_on_overflow */
1478 bfd_elf_generic_reloc, /* special_function */
1479 "R_ARM_THM_JUMP8", /* name */
1480 FALSE, /* partial_inplace */
1481 0x000000ff, /* src_mask */
1482 0x000000ff, /* dst_mask */
1483 TRUE), /* pcrel_offset */
1485 /* TLS relocations */
1486 HOWTO (R_ARM_TLS_GD32, /* type */
1487 0, /* rightshift */
1488 2, /* size (0 = byte, 1 = short, 2 = long) */
1489 32, /* bitsize */
1490 FALSE, /* pc_relative */
1491 0, /* bitpos */
1492 complain_overflow_bitfield,/* complain_on_overflow */
1493 NULL, /* special_function */
1494 "R_ARM_TLS_GD32", /* name */
1495 TRUE, /* partial_inplace */
1496 0xffffffff, /* src_mask */
1497 0xffffffff, /* dst_mask */
1498 FALSE), /* pcrel_offset */
1500 HOWTO (R_ARM_TLS_LDM32, /* type */
1501 0, /* rightshift */
1502 2, /* size (0 = byte, 1 = short, 2 = long) */
1503 32, /* bitsize */
1504 FALSE, /* pc_relative */
1505 0, /* bitpos */
1506 complain_overflow_bitfield,/* complain_on_overflow */
1507 bfd_elf_generic_reloc, /* special_function */
1508 "R_ARM_TLS_LDM32", /* name */
1509 TRUE, /* partial_inplace */
1510 0xffffffff, /* src_mask */
1511 0xffffffff, /* dst_mask */
1512 FALSE), /* pcrel_offset */
1514 HOWTO (R_ARM_TLS_LDO32, /* type */
1515 0, /* rightshift */
1516 2, /* size (0 = byte, 1 = short, 2 = long) */
1517 32, /* bitsize */
1518 FALSE, /* pc_relative */
1519 0, /* bitpos */
1520 complain_overflow_bitfield,/* complain_on_overflow */
1521 bfd_elf_generic_reloc, /* special_function */
1522 "R_ARM_TLS_LDO32", /* name */
1523 TRUE, /* partial_inplace */
1524 0xffffffff, /* src_mask */
1525 0xffffffff, /* dst_mask */
1526 FALSE), /* pcrel_offset */
1528 HOWTO (R_ARM_TLS_IE32, /* type */
1529 0, /* rightshift */
1530 2, /* size (0 = byte, 1 = short, 2 = long) */
1531 32, /* bitsize */
1532 FALSE, /* pc_relative */
1533 0, /* bitpos */
1534 complain_overflow_bitfield,/* complain_on_overflow */
1535 NULL, /* special_function */
1536 "R_ARM_TLS_IE32", /* name */
1537 TRUE, /* partial_inplace */
1538 0xffffffff, /* src_mask */
1539 0xffffffff, /* dst_mask */
1540 FALSE), /* pcrel_offset */
1542 HOWTO (R_ARM_TLS_LE32, /* type */
1543 0, /* rightshift */
1544 2, /* size (0 = byte, 1 = short, 2 = long) */
1545 32, /* bitsize */
1546 FALSE, /* pc_relative */
1547 0, /* bitpos */
1548 complain_overflow_bitfield,/* complain_on_overflow */
1549 bfd_elf_generic_reloc, /* special_function */
1550 "R_ARM_TLS_LE32", /* name */
1551 TRUE, /* partial_inplace */
1552 0xffffffff, /* src_mask */
1553 0xffffffff, /* dst_mask */
1554 FALSE), /* pcrel_offset */
1556 HOWTO (R_ARM_TLS_LDO12, /* type */
1557 0, /* rightshift */
1558 2, /* size (0 = byte, 1 = short, 2 = long) */
1559 12, /* bitsize */
1560 FALSE, /* pc_relative */
1561 0, /* bitpos */
1562 complain_overflow_bitfield,/* complain_on_overflow */
1563 bfd_elf_generic_reloc, /* special_function */
1564 "R_ARM_TLS_LDO12", /* name */
1565 FALSE, /* partial_inplace */
1566 0x00000fff, /* src_mask */
1567 0x00000fff, /* dst_mask */
1568 FALSE), /* pcrel_offset */
1570 HOWTO (R_ARM_TLS_LE12, /* type */
1571 0, /* rightshift */
1572 2, /* size (0 = byte, 1 = short, 2 = long) */
1573 12, /* bitsize */
1574 FALSE, /* pc_relative */
1575 0, /* bitpos */
1576 complain_overflow_bitfield,/* complain_on_overflow */
1577 bfd_elf_generic_reloc, /* special_function */
1578 "R_ARM_TLS_LE12", /* name */
1579 FALSE, /* partial_inplace */
1580 0x00000fff, /* src_mask */
1581 0x00000fff, /* dst_mask */
1582 FALSE), /* pcrel_offset */
1584 HOWTO (R_ARM_TLS_IE12GP, /* type */
1585 0, /* rightshift */
1586 2, /* size (0 = byte, 1 = short, 2 = long) */
1587 12, /* bitsize */
1588 FALSE, /* pc_relative */
1589 0, /* bitpos */
1590 complain_overflow_bitfield,/* complain_on_overflow */
1591 bfd_elf_generic_reloc, /* special_function */
1592 "R_ARM_TLS_IE12GP", /* name */
1593 FALSE, /* partial_inplace */
1594 0x00000fff, /* src_mask */
1595 0x00000fff, /* dst_mask */
1596 FALSE), /* pcrel_offset */
1599 /* 112-127 private relocations
1600 128 R_ARM_ME_TOO, obsolete
1601 129-255 unallocated in AAELF.
1603 249-255 extended, currently unused, relocations: */
1605 static reloc_howto_type elf32_arm_howto_table_2[4] =
1607 HOWTO (R_ARM_RREL32, /* type */
1608 0, /* rightshift */
1609 0, /* size (0 = byte, 1 = short, 2 = long) */
1610 0, /* bitsize */
1611 FALSE, /* pc_relative */
1612 0, /* bitpos */
1613 complain_overflow_dont,/* complain_on_overflow */
1614 bfd_elf_generic_reloc, /* special_function */
1615 "R_ARM_RREL32", /* name */
1616 FALSE, /* partial_inplace */
1617 0, /* src_mask */
1618 0, /* dst_mask */
1619 FALSE), /* pcrel_offset */
1621 HOWTO (R_ARM_RABS32, /* type */
1622 0, /* rightshift */
1623 0, /* size (0 = byte, 1 = short, 2 = long) */
1624 0, /* bitsize */
1625 FALSE, /* pc_relative */
1626 0, /* bitpos */
1627 complain_overflow_dont,/* complain_on_overflow */
1628 bfd_elf_generic_reloc, /* special_function */
1629 "R_ARM_RABS32", /* name */
1630 FALSE, /* partial_inplace */
1631 0, /* src_mask */
1632 0, /* dst_mask */
1633 FALSE), /* pcrel_offset */
1635 HOWTO (R_ARM_RPC24, /* type */
1636 0, /* rightshift */
1637 0, /* size (0 = byte, 1 = short, 2 = long) */
1638 0, /* bitsize */
1639 FALSE, /* pc_relative */
1640 0, /* bitpos */
1641 complain_overflow_dont,/* complain_on_overflow */
1642 bfd_elf_generic_reloc, /* special_function */
1643 "R_ARM_RPC24", /* name */
1644 FALSE, /* partial_inplace */
1645 0, /* src_mask */
1646 0, /* dst_mask */
1647 FALSE), /* pcrel_offset */
1649 HOWTO (R_ARM_RBASE, /* type */
1650 0, /* rightshift */
1651 0, /* size (0 = byte, 1 = short, 2 = long) */
1652 0, /* bitsize */
1653 FALSE, /* pc_relative */
1654 0, /* bitpos */
1655 complain_overflow_dont,/* complain_on_overflow */
1656 bfd_elf_generic_reloc, /* special_function */
1657 "R_ARM_RBASE", /* name */
1658 FALSE, /* partial_inplace */
1659 0, /* src_mask */
1660 0, /* dst_mask */
1661 FALSE) /* pcrel_offset */
1664 static reloc_howto_type *
1665 elf32_arm_howto_from_type (unsigned int r_type)
1667 if (r_type < ARRAY_SIZE (elf32_arm_howto_table_1))
1668 return &elf32_arm_howto_table_1[r_type];
1670 if (r_type >= R_ARM_RREL32
1671 && r_type < R_ARM_RREL32 + ARRAY_SIZE (elf32_arm_howto_table_2))
1672 return &elf32_arm_howto_table_2[r_type - R_ARM_RREL32];
1674 return NULL;
1677 static void
1678 elf32_arm_info_to_howto (bfd * abfd ATTRIBUTE_UNUSED, arelent * bfd_reloc,
1679 Elf_Internal_Rela * elf_reloc)
1681 unsigned int r_type;
1683 r_type = ELF32_R_TYPE (elf_reloc->r_info);
1684 bfd_reloc->howto = elf32_arm_howto_from_type (r_type);
1687 struct elf32_arm_reloc_map
1689 bfd_reloc_code_real_type bfd_reloc_val;
1690 unsigned char elf_reloc_val;
1693 /* All entries in this list must also be present in elf32_arm_howto_table. */
1694 static const struct elf32_arm_reloc_map elf32_arm_reloc_map[] =
1696 {BFD_RELOC_NONE, R_ARM_NONE},
1697 {BFD_RELOC_ARM_PCREL_BRANCH, R_ARM_PC24},
1698 {BFD_RELOC_ARM_PCREL_CALL, R_ARM_CALL},
1699 {BFD_RELOC_ARM_PCREL_JUMP, R_ARM_JUMP24},
1700 {BFD_RELOC_ARM_PCREL_BLX, R_ARM_XPC25},
1701 {BFD_RELOC_THUMB_PCREL_BLX, R_ARM_THM_XPC22},
1702 {BFD_RELOC_32, R_ARM_ABS32},
1703 {BFD_RELOC_32_PCREL, R_ARM_REL32},
1704 {BFD_RELOC_8, R_ARM_ABS8},
1705 {BFD_RELOC_16, R_ARM_ABS16},
1706 {BFD_RELOC_ARM_OFFSET_IMM, R_ARM_ABS12},
1707 {BFD_RELOC_ARM_THUMB_OFFSET, R_ARM_THM_ABS5},
1708 {BFD_RELOC_THUMB_PCREL_BRANCH25, R_ARM_THM_JUMP24},
1709 {BFD_RELOC_THUMB_PCREL_BRANCH23, R_ARM_THM_CALL},
1710 {BFD_RELOC_THUMB_PCREL_BRANCH12, R_ARM_THM_JUMP11},
1711 {BFD_RELOC_THUMB_PCREL_BRANCH20, R_ARM_THM_JUMP19},
1712 {BFD_RELOC_THUMB_PCREL_BRANCH9, R_ARM_THM_JUMP8},
1713 {BFD_RELOC_THUMB_PCREL_BRANCH7, R_ARM_THM_JUMP6},
1714 {BFD_RELOC_ARM_GLOB_DAT, R_ARM_GLOB_DAT},
1715 {BFD_RELOC_ARM_JUMP_SLOT, R_ARM_JUMP_SLOT},
1716 {BFD_RELOC_ARM_RELATIVE, R_ARM_RELATIVE},
1717 {BFD_RELOC_ARM_GOTOFF, R_ARM_GOTOFF32},
1718 {BFD_RELOC_ARM_GOTPC, R_ARM_GOTPC},
1719 {BFD_RELOC_ARM_GOT32, R_ARM_GOT32},
1720 {BFD_RELOC_ARM_PLT32, R_ARM_PLT32},
1721 {BFD_RELOC_ARM_TARGET1, R_ARM_TARGET1},
1722 {BFD_RELOC_ARM_ROSEGREL32, R_ARM_ROSEGREL32},
1723 {BFD_RELOC_ARM_SBREL32, R_ARM_SBREL32},
1724 {BFD_RELOC_ARM_PREL31, R_ARM_PREL31},
1725 {BFD_RELOC_ARM_TARGET2, R_ARM_TARGET2},
1726 {BFD_RELOC_ARM_PLT32, R_ARM_PLT32},
1727 {BFD_RELOC_ARM_TLS_GD32, R_ARM_TLS_GD32},
1728 {BFD_RELOC_ARM_TLS_LDO32, R_ARM_TLS_LDO32},
1729 {BFD_RELOC_ARM_TLS_LDM32, R_ARM_TLS_LDM32},
1730 {BFD_RELOC_ARM_TLS_DTPMOD32, R_ARM_TLS_DTPMOD32},
1731 {BFD_RELOC_ARM_TLS_DTPOFF32, R_ARM_TLS_DTPOFF32},
1732 {BFD_RELOC_ARM_TLS_TPOFF32, R_ARM_TLS_TPOFF32},
1733 {BFD_RELOC_ARM_TLS_IE32, R_ARM_TLS_IE32},
1734 {BFD_RELOC_ARM_TLS_LE32, R_ARM_TLS_LE32},
1735 {BFD_RELOC_VTABLE_INHERIT, R_ARM_GNU_VTINHERIT},
1736 {BFD_RELOC_VTABLE_ENTRY, R_ARM_GNU_VTENTRY},
1737 {BFD_RELOC_ARM_MOVW, R_ARM_MOVW_ABS_NC},
1738 {BFD_RELOC_ARM_MOVT, R_ARM_MOVT_ABS},
1739 {BFD_RELOC_ARM_MOVW_PCREL, R_ARM_MOVW_PREL_NC},
1740 {BFD_RELOC_ARM_MOVT_PCREL, R_ARM_MOVT_PREL},
1741 {BFD_RELOC_ARM_THUMB_MOVW, R_ARM_THM_MOVW_ABS_NC},
1742 {BFD_RELOC_ARM_THUMB_MOVT, R_ARM_THM_MOVT_ABS},
1743 {BFD_RELOC_ARM_THUMB_MOVW_PCREL, R_ARM_THM_MOVW_PREL_NC},
1744 {BFD_RELOC_ARM_THUMB_MOVT_PCREL, R_ARM_THM_MOVT_PREL},
1745 {BFD_RELOC_ARM_ALU_PC_G0_NC, R_ARM_ALU_PC_G0_NC},
1746 {BFD_RELOC_ARM_ALU_PC_G0, R_ARM_ALU_PC_G0},
1747 {BFD_RELOC_ARM_ALU_PC_G1_NC, R_ARM_ALU_PC_G1_NC},
1748 {BFD_RELOC_ARM_ALU_PC_G1, R_ARM_ALU_PC_G1},
1749 {BFD_RELOC_ARM_ALU_PC_G2, R_ARM_ALU_PC_G2},
1750 {BFD_RELOC_ARM_LDR_PC_G0, R_ARM_LDR_PC_G0},
1751 {BFD_RELOC_ARM_LDR_PC_G1, R_ARM_LDR_PC_G1},
1752 {BFD_RELOC_ARM_LDR_PC_G2, R_ARM_LDR_PC_G2},
1753 {BFD_RELOC_ARM_LDRS_PC_G0, R_ARM_LDRS_PC_G0},
1754 {BFD_RELOC_ARM_LDRS_PC_G1, R_ARM_LDRS_PC_G1},
1755 {BFD_RELOC_ARM_LDRS_PC_G2, R_ARM_LDRS_PC_G2},
1756 {BFD_RELOC_ARM_LDC_PC_G0, R_ARM_LDC_PC_G0},
1757 {BFD_RELOC_ARM_LDC_PC_G1, R_ARM_LDC_PC_G1},
1758 {BFD_RELOC_ARM_LDC_PC_G2, R_ARM_LDC_PC_G2},
1759 {BFD_RELOC_ARM_ALU_SB_G0_NC, R_ARM_ALU_SB_G0_NC},
1760 {BFD_RELOC_ARM_ALU_SB_G0, R_ARM_ALU_SB_G0},
1761 {BFD_RELOC_ARM_ALU_SB_G1_NC, R_ARM_ALU_SB_G1_NC},
1762 {BFD_RELOC_ARM_ALU_SB_G1, R_ARM_ALU_SB_G1},
1763 {BFD_RELOC_ARM_ALU_SB_G2, R_ARM_ALU_SB_G2},
1764 {BFD_RELOC_ARM_LDR_SB_G0, R_ARM_LDR_SB_G0},
1765 {BFD_RELOC_ARM_LDR_SB_G1, R_ARM_LDR_SB_G1},
1766 {BFD_RELOC_ARM_LDR_SB_G2, R_ARM_LDR_SB_G2},
1767 {BFD_RELOC_ARM_LDRS_SB_G0, R_ARM_LDRS_SB_G0},
1768 {BFD_RELOC_ARM_LDRS_SB_G1, R_ARM_LDRS_SB_G1},
1769 {BFD_RELOC_ARM_LDRS_SB_G2, R_ARM_LDRS_SB_G2},
1770 {BFD_RELOC_ARM_LDC_SB_G0, R_ARM_LDC_SB_G0},
1771 {BFD_RELOC_ARM_LDC_SB_G1, R_ARM_LDC_SB_G1},
1772 {BFD_RELOC_ARM_LDC_SB_G2, R_ARM_LDC_SB_G2},
1773 {BFD_RELOC_ARM_V4BX, R_ARM_V4BX}
1776 static reloc_howto_type *
1777 elf32_arm_reloc_type_lookup (bfd *abfd ATTRIBUTE_UNUSED,
1778 bfd_reloc_code_real_type code)
1780 unsigned int i;
1782 for (i = 0; i < ARRAY_SIZE (elf32_arm_reloc_map); i ++)
1783 if (elf32_arm_reloc_map[i].bfd_reloc_val == code)
1784 return elf32_arm_howto_from_type (elf32_arm_reloc_map[i].elf_reloc_val);
1786 return NULL;
1789 static reloc_howto_type *
1790 elf32_arm_reloc_name_lookup (bfd *abfd ATTRIBUTE_UNUSED,
1791 const char *r_name)
1793 unsigned int i;
1795 for (i = 0; i < ARRAY_SIZE (elf32_arm_howto_table_1); i++)
1796 if (elf32_arm_howto_table_1[i].name != NULL
1797 && strcasecmp (elf32_arm_howto_table_1[i].name, r_name) == 0)
1798 return &elf32_arm_howto_table_1[i];
1800 for (i = 0; i < ARRAY_SIZE (elf32_arm_howto_table_2); i++)
1801 if (elf32_arm_howto_table_2[i].name != NULL
1802 && strcasecmp (elf32_arm_howto_table_2[i].name, r_name) == 0)
1803 return &elf32_arm_howto_table_2[i];
1805 return NULL;
1808 /* Support for core dump NOTE sections. */
1810 static bfd_boolean
1811 elf32_arm_nabi_grok_prstatus (bfd *abfd, Elf_Internal_Note *note)
1813 int offset;
1814 size_t size;
1816 switch (note->descsz)
1818 default:
1819 return FALSE;
1821 case 148: /* Linux/ARM 32-bit. */
1822 /* pr_cursig */
1823 elf_tdata (abfd)->core_signal = bfd_get_16 (abfd, note->descdata + 12);
1825 /* pr_pid */
1826 elf_tdata (abfd)->core_pid = bfd_get_32 (abfd, note->descdata + 24);
1828 /* pr_reg */
1829 offset = 72;
1830 size = 72;
1832 break;
1835 /* Make a ".reg/999" section. */
1836 return _bfd_elfcore_make_pseudosection (abfd, ".reg",
1837 size, note->descpos + offset);
1840 static bfd_boolean
1841 elf32_arm_nabi_grok_psinfo (bfd *abfd, Elf_Internal_Note *note)
1843 switch (note->descsz)
1845 default:
1846 return FALSE;
1848 case 124: /* Linux/ARM elf_prpsinfo. */
1849 elf_tdata (abfd)->core_program
1850 = _bfd_elfcore_strndup (abfd, note->descdata + 28, 16);
1851 elf_tdata (abfd)->core_command
1852 = _bfd_elfcore_strndup (abfd, note->descdata + 44, 80);
1855 /* Note that for some reason, a spurious space is tacked
1856 onto the end of the args in some (at least one anyway)
1857 implementations, so strip it off if it exists. */
1859 char *command = elf_tdata (abfd)->core_command;
1860 int n = strlen (command);
1862 if (0 < n && command[n - 1] == ' ')
1863 command[n - 1] = '\0';
1866 return TRUE;
1869 #define TARGET_LITTLE_SYM bfd_elf32_littlearm_vec
1870 #define TARGET_LITTLE_NAME "elf32-littlearm"
1871 #define TARGET_BIG_SYM bfd_elf32_bigarm_vec
1872 #define TARGET_BIG_NAME "elf32-bigarm"
1874 #define elf_backend_grok_prstatus elf32_arm_nabi_grok_prstatus
1875 #define elf_backend_grok_psinfo elf32_arm_nabi_grok_psinfo
1877 typedef unsigned long int insn32;
1878 typedef unsigned short int insn16;
1880 /* In lieu of proper flags, assume all EABIv4 or later objects are
1881 interworkable. */
1882 #define INTERWORK_FLAG(abfd) \
1883 (EF_ARM_EABI_VERSION (elf_elfheader (abfd)->e_flags) >= EF_ARM_EABI_VER4 \
1884 || (elf_elfheader (abfd)->e_flags & EF_ARM_INTERWORK))
1886 /* The linker script knows the section names for placement.
1887 The entry_names are used to do simple name mangling on the stubs.
1888 Given a function name, and its type, the stub can be found. The
1889 name can be changed. The only requirement is the %s be present. */
1890 #define THUMB2ARM_GLUE_SECTION_NAME ".glue_7t"
1891 #define THUMB2ARM_GLUE_ENTRY_NAME "__%s_from_thumb"
1893 #define ARM2THUMB_GLUE_SECTION_NAME ".glue_7"
1894 #define ARM2THUMB_GLUE_ENTRY_NAME "__%s_from_arm"
1896 #define VFP11_ERRATUM_VENEER_SECTION_NAME ".vfp11_veneer"
1897 #define VFP11_ERRATUM_VENEER_ENTRY_NAME "__vfp11_veneer_%x"
1899 #define ARM_BX_GLUE_SECTION_NAME ".v4_bx"
1900 #define ARM_BX_GLUE_ENTRY_NAME "__bx_r%d"
1902 #define STUB_ENTRY_NAME "__%s_veneer"
1904 /* The name of the dynamic interpreter. This is put in the .interp
1905 section. */
1906 #define ELF_DYNAMIC_INTERPRETER "/usr/lib/ld.so.1"
1908 #ifdef FOUR_WORD_PLT
1910 /* The first entry in a procedure linkage table looks like
1911 this. It is set up so that any shared library function that is
1912 called before the relocation has been set up calls the dynamic
1913 linker first. */
1914 static const bfd_vma elf32_arm_plt0_entry [] =
1916 0xe52de004, /* str lr, [sp, #-4]! */
1917 0xe59fe010, /* ldr lr, [pc, #16] */
1918 0xe08fe00e, /* add lr, pc, lr */
1919 0xe5bef008, /* ldr pc, [lr, #8]! */
1922 /* Subsequent entries in a procedure linkage table look like
1923 this. */
1924 static const bfd_vma elf32_arm_plt_entry [] =
1926 0xe28fc600, /* add ip, pc, #NN */
1927 0xe28cca00, /* add ip, ip, #NN */
1928 0xe5bcf000, /* ldr pc, [ip, #NN]! */
1929 0x00000000, /* unused */
1932 #else
1934 /* The first entry in a procedure linkage table looks like
1935 this. It is set up so that any shared library function that is
1936 called before the relocation has been set up calls the dynamic
1937 linker first. */
1938 static const bfd_vma elf32_arm_plt0_entry [] =
1940 0xe52de004, /* str lr, [sp, #-4]! */
1941 0xe59fe004, /* ldr lr, [pc, #4] */
1942 0xe08fe00e, /* add lr, pc, lr */
1943 0xe5bef008, /* ldr pc, [lr, #8]! */
1944 0x00000000, /* &GOT[0] - . */
1947 /* Subsequent entries in a procedure linkage table look like
1948 this. */
1949 static const bfd_vma elf32_arm_plt_entry [] =
1951 0xe28fc600, /* add ip, pc, #0xNN00000 */
1952 0xe28cca00, /* add ip, ip, #0xNN000 */
1953 0xe5bcf000, /* ldr pc, [ip, #0xNNN]! */
1956 #endif
1958 /* The format of the first entry in the procedure linkage table
1959 for a VxWorks executable. */
1960 static const bfd_vma elf32_arm_vxworks_exec_plt0_entry[] =
1962 0xe52dc008, /* str ip,[sp,#-8]! */
1963 0xe59fc000, /* ldr ip,[pc] */
1964 0xe59cf008, /* ldr pc,[ip,#8] */
1965 0x00000000, /* .long _GLOBAL_OFFSET_TABLE_ */
1968 /* The format of subsequent entries in a VxWorks executable. */
1969 static const bfd_vma elf32_arm_vxworks_exec_plt_entry[] =
1971 0xe59fc000, /* ldr ip,[pc] */
1972 0xe59cf000, /* ldr pc,[ip] */
1973 0x00000000, /* .long @got */
1974 0xe59fc000, /* ldr ip,[pc] */
1975 0xea000000, /* b _PLT */
1976 0x00000000, /* .long @pltindex*sizeof(Elf32_Rela) */
1979 /* The format of entries in a VxWorks shared library. */
1980 static const bfd_vma elf32_arm_vxworks_shared_plt_entry[] =
1982 0xe59fc000, /* ldr ip,[pc] */
1983 0xe79cf009, /* ldr pc,[ip,r9] */
1984 0x00000000, /* .long @got */
1985 0xe59fc000, /* ldr ip,[pc] */
1986 0xe599f008, /* ldr pc,[r9,#8] */
1987 0x00000000, /* .long @pltindex*sizeof(Elf32_Rela) */
1990 /* An initial stub used if the PLT entry is referenced from Thumb code. */
1991 #define PLT_THUMB_STUB_SIZE 4
1992 static const bfd_vma elf32_arm_plt_thumb_stub [] =
1994 0x4778, /* bx pc */
1995 0x46c0 /* nop */
1998 /* The entries in a PLT when using a DLL-based target with multiple
1999 address spaces. */
2000 static const bfd_vma elf32_arm_symbian_plt_entry [] =
2002 0xe51ff004, /* ldr pc, [pc, #-4] */
2003 0x00000000, /* dcd R_ARM_GLOB_DAT(X) */
2006 #define ARM_MAX_FWD_BRANCH_OFFSET ((((1 << 23) - 1) << 2) + 8)
2007 #define ARM_MAX_BWD_BRANCH_OFFSET ((-((1 << 23) << 2)) + 8)
2008 #define THM_MAX_FWD_BRANCH_OFFSET ((1 << 22) -2 + 4)
2009 #define THM_MAX_BWD_BRANCH_OFFSET (-(1 << 22) + 4)
2010 #define THM2_MAX_FWD_BRANCH_OFFSET (((1 << 24) - 2) + 4)
2011 #define THM2_MAX_BWD_BRANCH_OFFSET (-(1 << 24) + 4)
2013 enum stub_insn_type
2015 THUMB16_TYPE = 1,
2016 THUMB32_TYPE,
2017 ARM_TYPE,
2018 DATA_TYPE
2021 #define THUMB16_INSN(X) {(X), THUMB16_TYPE, R_ARM_NONE, 0}
2022 #define THUMB32_INSN(X) {(X), THUMB32_TYPE, R_ARM_NONE, 0}
2023 #define ARM_INSN(X) {(X), ARM_TYPE, R_ARM_NONE, 0}
2024 #define ARM_REL_INSN(X, Z) {(X), ARM_TYPE, R_ARM_JUMP24, (Z)}
2025 #define DATA_WORD(X,Y,Z) {(X), DATA_TYPE, (Y), (Z)}
2027 typedef struct
2029 bfd_vma data;
2030 enum stub_insn_type type;
2031 unsigned int r_type;
2032 int reloc_addend;
2033 } insn_sequence;
2035 /* Arm/Thumb -> Arm/Thumb long branch stub. On V5T and above, use blx
2036 to reach the stub if necessary. */
2037 static const insn_sequence elf32_arm_stub_long_branch_any_any[] =
2039 ARM_INSN(0xe51ff004), /* ldr pc, [pc, #-4] */
2040 DATA_WORD(0, R_ARM_ABS32, 0), /* dcd R_ARM_ABS32(X) */
2043 /* V4T Arm -> Thumb long branch stub. Used on V4T where blx is not
2044 available. */
2045 static const insn_sequence elf32_arm_stub_long_branch_v4t_arm_thumb[] =
2047 ARM_INSN(0xe59fc000), /* ldr ip, [pc, #0] */
2048 ARM_INSN(0xe12fff1c), /* bx ip */
2049 DATA_WORD(0, R_ARM_ABS32, 0), /* dcd R_ARM_ABS32(X) */
2052 /* Thumb -> Thumb long branch stub. Used on architectures which
2053 support only this mode, or on V4T where it is expensive to switch
2054 to ARM. */
2055 static const insn_sequence elf32_arm_stub_long_branch_thumb_only[] =
2057 THUMB16_INSN(0xb401), /* push {r0} */
2058 THUMB16_INSN(0x4802), /* ldr r0, [pc, #8] */
2059 THUMB16_INSN(0x4684), /* mov ip, r0 */
2060 THUMB16_INSN(0xbc01), /* pop {r0} */
2061 THUMB16_INSN(0x4760), /* bx ip */
2062 THUMB16_INSN(0xbf00), /* nop */
2063 DATA_WORD(0, R_ARM_ABS32, 0), /* dcd R_ARM_ABS32(X) */
2066 /* V4T Thumb -> ARM long branch stub. Used on V4T where blx is not
2067 available. */
2068 static const insn_sequence elf32_arm_stub_long_branch_v4t_thumb_arm[] =
2070 THUMB16_INSN(0x4778), /* bx pc */
2071 THUMB16_INSN(0x46c0), /* nop */
2072 ARM_INSN(0xe51ff004), /* ldr pc, [pc, #-4] */
2073 DATA_WORD(0, R_ARM_ABS32, 0), /* dcd R_ARM_ABS32(X) */
2076 /* V4T Thumb -> ARM short branch stub. Shorter variant of the above
2077 one, when the destination is close enough. */
2078 static const insn_sequence elf32_arm_stub_short_branch_v4t_thumb_arm[] =
2080 THUMB16_INSN(0x4778), /* bx pc */
2081 THUMB16_INSN(0x46c0), /* nop */
2082 ARM_REL_INSN(0xea000000, -8), /* b (X-8) */
2085 /* ARM/Thumb -> ARM long branch stub, PIC. On V5T and above, use
2086 blx to reach the stub if necessary. */
2087 static const insn_sequence elf32_arm_stub_long_branch_any_arm_pic[] =
2089 ARM_INSN(0xe59fc000), /* ldr r12, [pc] */
2090 ARM_INSN(0xe08ff00c), /* add pc, pc, ip */
2091 DATA_WORD(0, R_ARM_REL32, -4), /* dcd R_ARM_REL32(X-4) */
2094 /* ARM/Thumb -> Thumb long branch stub, PIC. On V5T and above, use
2095 blx to reach the stub if necessary. We can not add into pc;
2096 it is not guaranteed to mode switch (different in ARMv6 and
2097 ARMv7). */
2098 static const insn_sequence elf32_arm_stub_long_branch_any_thumb_pic[] =
2100 ARM_INSN(0xe59fc004), /* ldr r12, [pc, #4] */
2101 ARM_INSN(0xe08fc00c), /* add ip, pc, ip */
2102 ARM_INSN(0xe12fff1c), /* bx ip */
2103 DATA_WORD(0, R_ARM_REL32, 0), /* dcd R_ARM_REL32(X) */
2106 /* V4T ARM -> ARM long branch stub, PIC. */
2107 static const insn_sequence elf32_arm_stub_long_branch_v4t_arm_thumb_pic[] =
2109 ARM_INSN(0xe59fc004), /* ldr ip, [pc, #4] */
2110 ARM_INSN(0xe08fc00c), /* add ip, pc, ip */
2111 ARM_INSN(0xe12fff1c), /* bx ip */
2112 DATA_WORD(0, R_ARM_REL32, 0), /* dcd R_ARM_REL32(X) */
2115 /* V4T Thumb -> ARM long branch stub, PIC. */
2116 static const insn_sequence elf32_arm_stub_long_branch_v4t_thumb_arm_pic[] =
2118 THUMB16_INSN(0x4778), /* bx pc */
2119 THUMB16_INSN(0x46c0), /* nop */
2120 ARM_INSN(0xe59fc000), /* ldr ip, [pc, #0] */
2121 ARM_INSN(0xe08cf00f), /* add pc, ip, pc */
2122 DATA_WORD(0, R_ARM_REL32, -4), /* dcd R_ARM_REL32(X) */
2125 /* Thumb -> Thumb long branch stub, PIC. Used on architectures which
2126 support only this mode, or on V4T where it is expensive to switch
2127 to ARM. */
2128 static const insn_sequence elf32_arm_stub_long_branch_thumb_only_pic[] =
2130 THUMB16_INSN(0xb401), /* push {r0} */
2131 THUMB16_INSN(0x4802), /* ldr r0, [pc, #8] */
2132 THUMB16_INSN(0x46fc), /* mov ip, pc */
2133 THUMB16_INSN(0x4484), /* add ip, r0 */
2134 THUMB16_INSN(0xbc01), /* pop {r0} */
2135 THUMB16_INSN(0x4760), /* bx ip */
2136 DATA_WORD(0, R_ARM_REL32, 4), /* dcd R_ARM_REL32(X) */
2139 /* Section name for stubs is the associated section name plus this
2140 string. */
2141 #define STUB_SUFFIX ".stub"
2143 enum elf32_arm_stub_type
2145 arm_stub_none,
2146 arm_stub_long_branch_any_any,
2147 arm_stub_long_branch_v4t_arm_thumb,
2148 arm_stub_long_branch_thumb_only,
2149 arm_stub_long_branch_v4t_thumb_arm,
2150 arm_stub_short_branch_v4t_thumb_arm,
2151 arm_stub_long_branch_any_arm_pic,
2152 arm_stub_long_branch_any_thumb_pic,
2153 arm_stub_long_branch_v4t_arm_thumb_pic,
2154 arm_stub_long_branch_v4t_thumb_arm_pic,
2155 arm_stub_long_branch_thumb_only_pic,
2158 struct elf32_arm_stub_hash_entry
2160 /* Base hash table entry structure. */
2161 struct bfd_hash_entry root;
2163 /* The stub section. */
2164 asection *stub_sec;
2166 /* Offset within stub_sec of the beginning of this stub. */
2167 bfd_vma stub_offset;
2169 /* Given the symbol's value and its section we can determine its final
2170 value when building the stubs (so the stub knows where to jump). */
2171 bfd_vma target_value;
2172 asection *target_section;
2174 /* The stub type. */
2175 enum elf32_arm_stub_type stub_type;
2176 /* Its encoding size in bytes. */
2177 int stub_size;
2178 /* Its template. */
2179 const insn_sequence *stub_template;
2180 /* The size of the template (number of entries). */
2181 int stub_template_size;
2183 /* The symbol table entry, if any, that this was derived from. */
2184 struct elf32_arm_link_hash_entry *h;
2186 /* Destination symbol type (STT_ARM_TFUNC, ...) */
2187 unsigned char st_type;
2189 /* Where this stub is being called from, or, in the case of combined
2190 stub sections, the first input section in the group. */
2191 asection *id_sec;
2193 /* The name for the local symbol at the start of this stub. The
2194 stub name in the hash table has to be unique; this does not, so
2195 it can be friendlier. */
2196 char *output_name;
2199 /* Used to build a map of a section. This is required for mixed-endian
2200 code/data. */
2202 typedef struct elf32_elf_section_map
2204 bfd_vma vma;
2205 char type;
2207 elf32_arm_section_map;
2209 /* Information about a VFP11 erratum veneer, or a branch to such a veneer. */
2211 typedef enum
2213 VFP11_ERRATUM_BRANCH_TO_ARM_VENEER,
2214 VFP11_ERRATUM_BRANCH_TO_THUMB_VENEER,
2215 VFP11_ERRATUM_ARM_VENEER,
2216 VFP11_ERRATUM_THUMB_VENEER
2218 elf32_vfp11_erratum_type;
2220 typedef struct elf32_vfp11_erratum_list
2222 struct elf32_vfp11_erratum_list *next;
2223 bfd_vma vma;
2224 union
2226 struct
2228 struct elf32_vfp11_erratum_list *veneer;
2229 unsigned int vfp_insn;
2230 } b;
2231 struct
2233 struct elf32_vfp11_erratum_list *branch;
2234 unsigned int id;
2235 } v;
2236 } u;
2237 elf32_vfp11_erratum_type type;
2239 elf32_vfp11_erratum_list;
2241 typedef struct _arm_elf_section_data
2243 struct bfd_elf_section_data elf;
2244 unsigned int mapcount;
2245 unsigned int mapsize;
2246 elf32_arm_section_map *map;
2247 unsigned int erratumcount;
2248 elf32_vfp11_erratum_list *erratumlist;
2250 _arm_elf_section_data;
2252 #define elf32_arm_section_data(sec) \
2253 ((_arm_elf_section_data *) elf_section_data (sec))
2255 /* The size of the thread control block. */
2256 #define TCB_SIZE 8
2258 struct elf_arm_obj_tdata
2260 struct elf_obj_tdata root;
2262 /* tls_type for each local got entry. */
2263 char *local_got_tls_type;
2265 /* Zero to warn when linking objects with incompatible enum sizes. */
2266 int no_enum_size_warning;
2268 /* Zero to warn when linking objects with incompatible wchar_t sizes. */
2269 int no_wchar_size_warning;
2272 #define elf_arm_tdata(bfd) \
2273 ((struct elf_arm_obj_tdata *) (bfd)->tdata.any)
2275 #define elf32_arm_local_got_tls_type(bfd) \
2276 (elf_arm_tdata (bfd)->local_got_tls_type)
2278 #define is_arm_elf(bfd) \
2279 (bfd_get_flavour (bfd) == bfd_target_elf_flavour \
2280 && elf_tdata (bfd) != NULL \
2281 && elf_object_id (bfd) == ARM_ELF_TDATA)
2283 static bfd_boolean
2284 elf32_arm_mkobject (bfd *abfd)
2286 return bfd_elf_allocate_object (abfd, sizeof (struct elf_arm_obj_tdata),
2287 ARM_ELF_TDATA);
2290 /* The ARM linker needs to keep track of the number of relocs that it
2291 decides to copy in check_relocs for each symbol. This is so that
2292 it can discard PC relative relocs if it doesn't need them when
2293 linking with -Bsymbolic. We store the information in a field
2294 extending the regular ELF linker hash table. */
2296 /* This structure keeps track of the number of relocs we have copied
2297 for a given symbol. */
2298 struct elf32_arm_relocs_copied
2300 /* Next section. */
2301 struct elf32_arm_relocs_copied * next;
2302 /* A section in dynobj. */
2303 asection * section;
2304 /* Number of relocs copied in this section. */
2305 bfd_size_type count;
2306 /* Number of PC-relative relocs copied in this section. */
2307 bfd_size_type pc_count;
2310 #define elf32_arm_hash_entry(ent) ((struct elf32_arm_link_hash_entry *)(ent))
2312 /* Arm ELF linker hash entry. */
2313 struct elf32_arm_link_hash_entry
2315 struct elf_link_hash_entry root;
2317 /* Number of PC relative relocs copied for this symbol. */
2318 struct elf32_arm_relocs_copied * relocs_copied;
2320 /* We reference count Thumb references to a PLT entry separately,
2321 so that we can emit the Thumb trampoline only if needed. */
2322 bfd_signed_vma plt_thumb_refcount;
2324 /* Some references from Thumb code may be eliminated by BL->BLX
2325 conversion, so record them separately. */
2326 bfd_signed_vma plt_maybe_thumb_refcount;
2328 /* Since PLT entries have variable size if the Thumb prologue is
2329 used, we need to record the index into .got.plt instead of
2330 recomputing it from the PLT offset. */
2331 bfd_signed_vma plt_got_offset;
2333 #define GOT_UNKNOWN 0
2334 #define GOT_NORMAL 1
2335 #define GOT_TLS_GD 2
2336 #define GOT_TLS_IE 4
2337 unsigned char tls_type;
2339 /* The symbol marking the real symbol location for exported thumb
2340 symbols with Arm stubs. */
2341 struct elf_link_hash_entry *export_glue;
2343 /* A pointer to the most recently used stub hash entry against this
2344 symbol. */
2345 struct elf32_arm_stub_hash_entry *stub_cache;
2348 /* Traverse an arm ELF linker hash table. */
2349 #define elf32_arm_link_hash_traverse(table, func, info) \
2350 (elf_link_hash_traverse \
2351 (&(table)->root, \
2352 (bfd_boolean (*) (struct elf_link_hash_entry *, void *)) (func), \
2353 (info)))
2355 /* Get the ARM elf linker hash table from a link_info structure. */
2356 #define elf32_arm_hash_table(info) \
2357 ((struct elf32_arm_link_hash_table *) ((info)->hash))
2359 #define arm_stub_hash_lookup(table, string, create, copy) \
2360 ((struct elf32_arm_stub_hash_entry *) \
2361 bfd_hash_lookup ((table), (string), (create), (copy)))
2363 /* ARM ELF linker hash table. */
2364 struct elf32_arm_link_hash_table
2366 /* The main hash table. */
2367 struct elf_link_hash_table root;
2369 /* The size in bytes of the section containing the Thumb-to-ARM glue. */
2370 bfd_size_type thumb_glue_size;
2372 /* The size in bytes of the section containing the ARM-to-Thumb glue. */
2373 bfd_size_type arm_glue_size;
2375 /* The size in bytes of section containing the ARMv4 BX veneers. */
2376 bfd_size_type bx_glue_size;
2378 /* Offsets of ARMv4 BX veneers. Bit1 set if present, and Bit0 set when
2379 veneer has been populated. */
2380 bfd_vma bx_glue_offset[15];
2382 /* The size in bytes of the section containing glue for VFP11 erratum
2383 veneers. */
2384 bfd_size_type vfp11_erratum_glue_size;
2386 /* An arbitrary input BFD chosen to hold the glue sections. */
2387 bfd * bfd_of_glue_owner;
2389 /* Nonzero to output a BE8 image. */
2390 int byteswap_code;
2392 /* Zero if R_ARM_TARGET1 means R_ARM_ABS32.
2393 Nonzero if R_ARM_TARGET1 means R_ARM_REL32. */
2394 int target1_is_rel;
2396 /* The relocation to use for R_ARM_TARGET2 relocations. */
2397 int target2_reloc;
2399 /* 0 = Ignore R_ARM_V4BX.
2400 1 = Convert BX to MOV PC.
2401 2 = Generate v4 interworing stubs. */
2402 int fix_v4bx;
2404 /* Nonzero if the ARM/Thumb BLX instructions are available for use. */
2405 int use_blx;
2407 /* What sort of code sequences we should look for which may trigger the
2408 VFP11 denorm erratum. */
2409 bfd_arm_vfp11_fix vfp11_fix;
2411 /* Global counter for the number of fixes we have emitted. */
2412 int num_vfp11_fixes;
2414 /* Nonzero to force PIC branch veneers. */
2415 int pic_veneer;
2417 /* The number of bytes in the initial entry in the PLT. */
2418 bfd_size_type plt_header_size;
2420 /* The number of bytes in the subsequent PLT etries. */
2421 bfd_size_type plt_entry_size;
2423 /* True if the target system is VxWorks. */
2424 int vxworks_p;
2426 /* True if the target system is Symbian OS. */
2427 int symbian_p;
2429 /* True if the target uses REL relocations. */
2430 int use_rel;
2432 /* Short-cuts to get to dynamic linker sections. */
2433 asection *sgot;
2434 asection *sgotplt;
2435 asection *srelgot;
2436 asection *splt;
2437 asection *srelplt;
2438 asection *sdynbss;
2439 asection *srelbss;
2441 /* The (unloaded but important) VxWorks .rela.plt.unloaded section. */
2442 asection *srelplt2;
2444 /* Data for R_ARM_TLS_LDM32 relocations. */
2445 union
2447 bfd_signed_vma refcount;
2448 bfd_vma offset;
2449 } tls_ldm_got;
2451 /* Small local sym to section mapping cache. */
2452 struct sym_sec_cache sym_sec;
2454 /* For convenience in allocate_dynrelocs. */
2455 bfd * obfd;
2457 /* The stub hash table. */
2458 struct bfd_hash_table stub_hash_table;
2460 /* Linker stub bfd. */
2461 bfd *stub_bfd;
2463 /* Linker call-backs. */
2464 asection * (*add_stub_section) (const char *, asection *);
2465 void (*layout_sections_again) (void);
2467 /* Array to keep track of which stub sections have been created, and
2468 information on stub grouping. */
2469 struct map_stub
2471 /* This is the section to which stubs in the group will be
2472 attached. */
2473 asection *link_sec;
2474 /* The stub section. */
2475 asection *stub_sec;
2476 } *stub_group;
2478 /* Assorted information used by elf32_arm_size_stubs. */
2479 unsigned int bfd_count;
2480 int top_index;
2481 asection **input_list;
2484 /* Create an entry in an ARM ELF linker hash table. */
2486 static struct bfd_hash_entry *
2487 elf32_arm_link_hash_newfunc (struct bfd_hash_entry * entry,
2488 struct bfd_hash_table * table,
2489 const char * string)
2491 struct elf32_arm_link_hash_entry * ret =
2492 (struct elf32_arm_link_hash_entry *) entry;
2494 /* Allocate the structure if it has not already been allocated by a
2495 subclass. */
2496 if (ret == NULL)
2497 ret = bfd_hash_allocate (table, sizeof (struct elf32_arm_link_hash_entry));
2498 if (ret == NULL)
2499 return (struct bfd_hash_entry *) ret;
2501 /* Call the allocation method of the superclass. */
2502 ret = ((struct elf32_arm_link_hash_entry *)
2503 _bfd_elf_link_hash_newfunc ((struct bfd_hash_entry *) ret,
2504 table, string));
2505 if (ret != NULL)
2507 ret->relocs_copied = NULL;
2508 ret->tls_type = GOT_UNKNOWN;
2509 ret->plt_thumb_refcount = 0;
2510 ret->plt_maybe_thumb_refcount = 0;
2511 ret->plt_got_offset = -1;
2512 ret->export_glue = NULL;
2514 ret->stub_cache = NULL;
2517 return (struct bfd_hash_entry *) ret;
2520 /* Initialize an entry in the stub hash table. */
2522 static struct bfd_hash_entry *
2523 stub_hash_newfunc (struct bfd_hash_entry *entry,
2524 struct bfd_hash_table *table,
2525 const char *string)
2527 /* Allocate the structure if it has not already been allocated by a
2528 subclass. */
2529 if (entry == NULL)
2531 entry = bfd_hash_allocate (table,
2532 sizeof (struct elf32_arm_stub_hash_entry));
2533 if (entry == NULL)
2534 return entry;
2537 /* Call the allocation method of the superclass. */
2538 entry = bfd_hash_newfunc (entry, table, string);
2539 if (entry != NULL)
2541 struct elf32_arm_stub_hash_entry *eh;
2543 /* Initialize the local fields. */
2544 eh = (struct elf32_arm_stub_hash_entry *) entry;
2545 eh->stub_sec = NULL;
2546 eh->stub_offset = 0;
2547 eh->target_value = 0;
2548 eh->target_section = NULL;
2549 eh->stub_type = arm_stub_none;
2550 eh->stub_size = 0;
2551 eh->stub_template = NULL;
2552 eh->stub_template_size = 0;
2553 eh->h = NULL;
2554 eh->id_sec = NULL;
2557 return entry;
2560 /* Create .got, .gotplt, and .rel(a).got sections in DYNOBJ, and set up
2561 shortcuts to them in our hash table. */
2563 static bfd_boolean
2564 create_got_section (bfd *dynobj, struct bfd_link_info *info)
2566 struct elf32_arm_link_hash_table *htab;
2568 htab = elf32_arm_hash_table (info);
2569 /* BPABI objects never have a GOT, or associated sections. */
2570 if (htab->symbian_p)
2571 return TRUE;
2573 if (! _bfd_elf_create_got_section (dynobj, info))
2574 return FALSE;
2576 htab->sgot = bfd_get_section_by_name (dynobj, ".got");
2577 htab->sgotplt = bfd_get_section_by_name (dynobj, ".got.plt");
2578 if (!htab->sgot || !htab->sgotplt)
2579 abort ();
2581 htab->srelgot = bfd_make_section_with_flags (dynobj,
2582 RELOC_SECTION (htab, ".got"),
2583 (SEC_ALLOC | SEC_LOAD
2584 | SEC_HAS_CONTENTS
2585 | SEC_IN_MEMORY
2586 | SEC_LINKER_CREATED
2587 | SEC_READONLY));
2588 if (htab->srelgot == NULL
2589 || ! bfd_set_section_alignment (dynobj, htab->srelgot, 2))
2590 return FALSE;
2591 return TRUE;
2594 /* Create .plt, .rel(a).plt, .got, .got.plt, .rel(a).got, .dynbss, and
2595 .rel(a).bss sections in DYNOBJ, and set up shortcuts to them in our
2596 hash table. */
2598 static bfd_boolean
2599 elf32_arm_create_dynamic_sections (bfd *dynobj, struct bfd_link_info *info)
2601 struct elf32_arm_link_hash_table *htab;
2603 htab = elf32_arm_hash_table (info);
2604 if (!htab->sgot && !create_got_section (dynobj, info))
2605 return FALSE;
2607 if (!_bfd_elf_create_dynamic_sections (dynobj, info))
2608 return FALSE;
2610 htab->splt = bfd_get_section_by_name (dynobj, ".plt");
2611 htab->srelplt = bfd_get_section_by_name (dynobj,
2612 RELOC_SECTION (htab, ".plt"));
2613 htab->sdynbss = bfd_get_section_by_name (dynobj, ".dynbss");
2614 if (!info->shared)
2615 htab->srelbss = bfd_get_section_by_name (dynobj,
2616 RELOC_SECTION (htab, ".bss"));
2618 if (htab->vxworks_p)
2620 if (!elf_vxworks_create_dynamic_sections (dynobj, info, &htab->srelplt2))
2621 return FALSE;
2623 if (info->shared)
2625 htab->plt_header_size = 0;
2626 htab->plt_entry_size
2627 = 4 * ARRAY_SIZE (elf32_arm_vxworks_shared_plt_entry);
2629 else
2631 htab->plt_header_size
2632 = 4 * ARRAY_SIZE (elf32_arm_vxworks_exec_plt0_entry);
2633 htab->plt_entry_size
2634 = 4 * ARRAY_SIZE (elf32_arm_vxworks_exec_plt_entry);
2638 if (!htab->splt
2639 || !htab->srelplt
2640 || !htab->sdynbss
2641 || (!info->shared && !htab->srelbss))
2642 abort ();
2644 return TRUE;
2647 /* Copy the extra info we tack onto an elf_link_hash_entry. */
2649 static void
2650 elf32_arm_copy_indirect_symbol (struct bfd_link_info *info,
2651 struct elf_link_hash_entry *dir,
2652 struct elf_link_hash_entry *ind)
2654 struct elf32_arm_link_hash_entry *edir, *eind;
2656 edir = (struct elf32_arm_link_hash_entry *) dir;
2657 eind = (struct elf32_arm_link_hash_entry *) ind;
2659 if (eind->relocs_copied != NULL)
2661 if (edir->relocs_copied != NULL)
2663 struct elf32_arm_relocs_copied **pp;
2664 struct elf32_arm_relocs_copied *p;
2666 /* Add reloc counts against the indirect sym to the direct sym
2667 list. Merge any entries against the same section. */
2668 for (pp = &eind->relocs_copied; (p = *pp) != NULL; )
2670 struct elf32_arm_relocs_copied *q;
2672 for (q = edir->relocs_copied; q != NULL; q = q->next)
2673 if (q->section == p->section)
2675 q->pc_count += p->pc_count;
2676 q->count += p->count;
2677 *pp = p->next;
2678 break;
2680 if (q == NULL)
2681 pp = &p->next;
2683 *pp = edir->relocs_copied;
2686 edir->relocs_copied = eind->relocs_copied;
2687 eind->relocs_copied = NULL;
2690 if (ind->root.type == bfd_link_hash_indirect)
2692 /* Copy over PLT info. */
2693 edir->plt_thumb_refcount += eind->plt_thumb_refcount;
2694 eind->plt_thumb_refcount = 0;
2695 edir->plt_maybe_thumb_refcount += eind->plt_maybe_thumb_refcount;
2696 eind->plt_maybe_thumb_refcount = 0;
2698 if (dir->got.refcount <= 0)
2700 edir->tls_type = eind->tls_type;
2701 eind->tls_type = GOT_UNKNOWN;
2705 _bfd_elf_link_hash_copy_indirect (info, dir, ind);
2708 /* Create an ARM elf linker hash table. */
2710 static struct bfd_link_hash_table *
2711 elf32_arm_link_hash_table_create (bfd *abfd)
2713 struct elf32_arm_link_hash_table *ret;
2714 bfd_size_type amt = sizeof (struct elf32_arm_link_hash_table);
2716 ret = bfd_malloc (amt);
2717 if (ret == NULL)
2718 return NULL;
2720 if (!_bfd_elf_link_hash_table_init (& ret->root, abfd,
2721 elf32_arm_link_hash_newfunc,
2722 sizeof (struct elf32_arm_link_hash_entry)))
2724 free (ret);
2725 return NULL;
2728 ret->sgot = NULL;
2729 ret->sgotplt = NULL;
2730 ret->srelgot = NULL;
2731 ret->splt = NULL;
2732 ret->srelplt = NULL;
2733 ret->sdynbss = NULL;
2734 ret->srelbss = NULL;
2735 ret->srelplt2 = NULL;
2736 ret->thumb_glue_size = 0;
2737 ret->arm_glue_size = 0;
2738 ret->bx_glue_size = 0;
2739 memset (ret->bx_glue_offset, 0, sizeof (ret->bx_glue_offset));
2740 ret->vfp11_fix = BFD_ARM_VFP11_FIX_NONE;
2741 ret->vfp11_erratum_glue_size = 0;
2742 ret->num_vfp11_fixes = 0;
2743 ret->bfd_of_glue_owner = NULL;
2744 ret->byteswap_code = 0;
2745 ret->target1_is_rel = 0;
2746 ret->target2_reloc = R_ARM_NONE;
2747 #ifdef FOUR_WORD_PLT
2748 ret->plt_header_size = 16;
2749 ret->plt_entry_size = 16;
2750 #else
2751 ret->plt_header_size = 20;
2752 ret->plt_entry_size = 12;
2753 #endif
2754 ret->fix_v4bx = 0;
2755 ret->use_blx = 0;
2756 ret->vxworks_p = 0;
2757 ret->symbian_p = 0;
2758 ret->use_rel = 1;
2759 ret->sym_sec.abfd = NULL;
2760 ret->obfd = abfd;
2761 ret->tls_ldm_got.refcount = 0;
2762 ret->stub_bfd = NULL;
2763 ret->add_stub_section = NULL;
2764 ret->layout_sections_again = NULL;
2765 ret->stub_group = NULL;
2766 ret->bfd_count = 0;
2767 ret->top_index = 0;
2768 ret->input_list = NULL;
2770 if (!bfd_hash_table_init (&ret->stub_hash_table, stub_hash_newfunc,
2771 sizeof (struct elf32_arm_stub_hash_entry)))
2773 free (ret);
2774 return NULL;
2777 return &ret->root.root;
2780 /* Free the derived linker hash table. */
2782 static void
2783 elf32_arm_hash_table_free (struct bfd_link_hash_table *hash)
2785 struct elf32_arm_link_hash_table *ret
2786 = (struct elf32_arm_link_hash_table *) hash;
2788 bfd_hash_table_free (&ret->stub_hash_table);
2789 _bfd_generic_link_hash_table_free (hash);
2792 /* Determine if we're dealing with a Thumb only architecture. */
2794 static bfd_boolean
2795 using_thumb_only (struct elf32_arm_link_hash_table *globals)
2797 int arch = bfd_elf_get_obj_attr_int (globals->obfd, OBJ_ATTR_PROC,
2798 Tag_CPU_arch);
2799 int profile;
2801 if (arch != TAG_CPU_ARCH_V7)
2802 return FALSE;
2804 profile = bfd_elf_get_obj_attr_int (globals->obfd, OBJ_ATTR_PROC,
2805 Tag_CPU_arch_profile);
2807 return profile == 'M';
2810 /* Determine if we're dealing with a Thumb-2 object. */
2812 static bfd_boolean
2813 using_thumb2 (struct elf32_arm_link_hash_table *globals)
2815 int arch = bfd_elf_get_obj_attr_int (globals->obfd, OBJ_ATTR_PROC,
2816 Tag_CPU_arch);
2817 return arch == TAG_CPU_ARCH_V6T2 || arch >= TAG_CPU_ARCH_V7;
2820 static bfd_boolean
2821 arm_stub_is_thumb (enum elf32_arm_stub_type stub_type)
2823 switch (stub_type)
2825 case arm_stub_long_branch_thumb_only:
2826 case arm_stub_long_branch_v4t_thumb_arm:
2827 case arm_stub_short_branch_v4t_thumb_arm:
2828 case arm_stub_long_branch_v4t_thumb_arm_pic:
2829 case arm_stub_long_branch_thumb_only_pic:
2830 return TRUE;
2831 case arm_stub_none:
2832 BFD_FAIL ();
2833 return FALSE;
2834 break;
2835 default:
2836 return FALSE;
2840 /* Determine the type of stub needed, if any, for a call. */
2842 static enum elf32_arm_stub_type
2843 arm_type_of_stub (struct bfd_link_info *info,
2844 asection *input_sec,
2845 const Elf_Internal_Rela *rel,
2846 unsigned char st_type,
2847 struct elf32_arm_link_hash_entry *hash,
2848 bfd_vma destination,
2849 asection *sym_sec,
2850 bfd *input_bfd,
2851 const char *name)
2853 bfd_vma location;
2854 bfd_signed_vma branch_offset;
2855 unsigned int r_type;
2856 struct elf32_arm_link_hash_table * globals;
2857 int thumb2;
2858 int thumb_only;
2859 enum elf32_arm_stub_type stub_type = arm_stub_none;
2861 /* We don't know the actual type of destination in case it is of
2862 type STT_SECTION: give up. */
2863 if (st_type == STT_SECTION)
2864 return stub_type;
2866 globals = elf32_arm_hash_table (info);
2868 thumb_only = using_thumb_only (globals);
2870 thumb2 = using_thumb2 (globals);
2872 /* Determine where the call point is. */
2873 location = (input_sec->output_offset
2874 + input_sec->output_section->vma
2875 + rel->r_offset);
2877 branch_offset = (bfd_signed_vma)(destination - location);
2879 r_type = ELF32_R_TYPE (rel->r_info);
2881 /* If the call will go through a PLT entry then we do not need
2882 glue. */
2883 if (globals->splt != NULL && hash != NULL && hash->root.plt.offset != (bfd_vma) -1)
2884 return stub_type;
2886 if (r_type == R_ARM_THM_CALL)
2888 if ((!thumb2
2889 && (branch_offset > THM_MAX_FWD_BRANCH_OFFSET
2890 || (branch_offset < THM_MAX_BWD_BRANCH_OFFSET)))
2891 || (thumb2
2892 && (branch_offset > THM2_MAX_FWD_BRANCH_OFFSET
2893 || (branch_offset < THM2_MAX_BWD_BRANCH_OFFSET)))
2894 || ((st_type != STT_ARM_TFUNC) && !globals->use_blx))
2896 if (st_type == STT_ARM_TFUNC)
2898 /* Thumb to thumb. */
2899 if (!thumb_only)
2901 stub_type = (info->shared | globals->pic_veneer)
2902 /* PIC stubs. */
2903 ? ((globals->use_blx)
2904 /* V5T and above. */
2905 ? arm_stub_long_branch_any_thumb_pic
2906 /* On V4T, use Thumb code only. */
2907 : arm_stub_long_branch_thumb_only_pic)
2909 /* non-PIC stubs. */
2910 : ((globals->use_blx)
2911 /* V5T and above. */
2912 ? arm_stub_long_branch_any_any
2913 /* V4T. */
2914 : arm_stub_long_branch_thumb_only);
2916 else
2918 stub_type = (info->shared | globals->pic_veneer)
2919 /* PIC stub. */
2920 ? arm_stub_long_branch_thumb_only_pic
2921 /* non-PIC stub. */
2922 : arm_stub_long_branch_thumb_only;
2925 else
2927 /* Thumb to arm. */
2928 if (sym_sec != NULL
2929 && sym_sec->owner != NULL
2930 && !INTERWORK_FLAG (sym_sec->owner))
2932 (*_bfd_error_handler)
2933 (_("%B(%s): warning: interworking not enabled.\n"
2934 " first occurrence: %B: Thumb call to ARM"),
2935 sym_sec->owner, input_bfd, name);
2938 stub_type = (info->shared | globals->pic_veneer)
2939 /* PIC stubs. */
2940 ? ((globals->use_blx)
2941 /* V5T and above. */
2942 ? arm_stub_long_branch_any_arm_pic
2943 /* V4T PIC stub. */
2944 : arm_stub_long_branch_v4t_thumb_arm_pic)
2946 /* non-PIC stubs. */
2947 : ((globals->use_blx)
2948 /* V5T and above. */
2949 ? arm_stub_long_branch_any_any
2950 /* V4T. */
2951 : arm_stub_long_branch_v4t_thumb_arm);
2953 /* Handle v4t short branches. */
2954 if ((stub_type == arm_stub_long_branch_v4t_thumb_arm)
2955 && (branch_offset <= THM_MAX_FWD_BRANCH_OFFSET)
2956 && (branch_offset >= THM_MAX_BWD_BRANCH_OFFSET))
2957 stub_type = arm_stub_short_branch_v4t_thumb_arm;
2961 else if (r_type == R_ARM_CALL)
2963 if (st_type == STT_ARM_TFUNC)
2965 /* Arm to thumb. */
2967 if (sym_sec != NULL
2968 && sym_sec->owner != NULL
2969 && !INTERWORK_FLAG (sym_sec->owner))
2971 (*_bfd_error_handler)
2972 (_("%B(%s): warning: interworking not enabled.\n"
2973 " first occurrence: %B: ARM call to Thumb"),
2974 sym_sec->owner, input_bfd, name);
2977 /* We have an extra 2-bytes reach because of
2978 the mode change (bit 24 (H) of BLX encoding). */
2979 if (branch_offset > (ARM_MAX_FWD_BRANCH_OFFSET + 2)
2980 || (branch_offset < ARM_MAX_BWD_BRANCH_OFFSET)
2981 || !globals->use_blx)
2983 stub_type = (info->shared | globals->pic_veneer)
2984 /* PIC stubs. */
2985 ? ((globals->use_blx)
2986 /* V5T and above. */
2987 ? arm_stub_long_branch_any_thumb_pic
2988 /* V4T stub. */
2989 : arm_stub_long_branch_v4t_arm_thumb_pic)
2991 /* non-PIC stubs. */
2992 : ((globals->use_blx)
2993 /* V5T and above. */
2994 ? arm_stub_long_branch_any_any
2995 /* V4T. */
2996 : arm_stub_long_branch_v4t_arm_thumb);
2999 else
3001 /* Arm to arm. */
3002 if (branch_offset > ARM_MAX_FWD_BRANCH_OFFSET
3003 || (branch_offset < ARM_MAX_BWD_BRANCH_OFFSET))
3005 stub_type = (info->shared | globals->pic_veneer)
3006 /* PIC stubs. */
3007 ? arm_stub_long_branch_any_arm_pic
3008 /* non-PIC stubs. */
3009 : arm_stub_long_branch_any_any;
3014 return stub_type;
3017 /* Build a name for an entry in the stub hash table. */
3019 static char *
3020 elf32_arm_stub_name (const asection *input_section,
3021 const asection *sym_sec,
3022 const struct elf32_arm_link_hash_entry *hash,
3023 const Elf_Internal_Rela *rel)
3025 char *stub_name;
3026 bfd_size_type len;
3028 if (hash)
3030 len = 8 + 1 + strlen (hash->root.root.root.string) + 1 + 8 + 1;
3031 stub_name = bfd_malloc (len);
3032 if (stub_name != NULL)
3033 sprintf (stub_name, "%08x_%s+%x",
3034 input_section->id & 0xffffffff,
3035 hash->root.root.root.string,
3036 (int) rel->r_addend & 0xffffffff);
3038 else
3040 len = 8 + 1 + 8 + 1 + 8 + 1 + 8 + 1;
3041 stub_name = bfd_malloc (len);
3042 if (stub_name != NULL)
3043 sprintf (stub_name, "%08x_%x:%x+%x",
3044 input_section->id & 0xffffffff,
3045 sym_sec->id & 0xffffffff,
3046 (int) ELF32_R_SYM (rel->r_info) & 0xffffffff,
3047 (int) rel->r_addend & 0xffffffff);
3050 return stub_name;
3053 /* Look up an entry in the stub hash. Stub entries are cached because
3054 creating the stub name takes a bit of time. */
3056 static struct elf32_arm_stub_hash_entry *
3057 elf32_arm_get_stub_entry (const asection *input_section,
3058 const asection *sym_sec,
3059 struct elf_link_hash_entry *hash,
3060 const Elf_Internal_Rela *rel,
3061 struct elf32_arm_link_hash_table *htab)
3063 struct elf32_arm_stub_hash_entry *stub_entry;
3064 struct elf32_arm_link_hash_entry *h = (struct elf32_arm_link_hash_entry *) hash;
3065 const asection *id_sec;
3067 if ((input_section->flags & SEC_CODE) == 0)
3068 return NULL;
3070 /* If this input section is part of a group of sections sharing one
3071 stub section, then use the id of the first section in the group.
3072 Stub names need to include a section id, as there may well be
3073 more than one stub used to reach say, printf, and we need to
3074 distinguish between them. */
3075 id_sec = htab->stub_group[input_section->id].link_sec;
3077 if (h != NULL && h->stub_cache != NULL
3078 && h->stub_cache->h == h
3079 && h->stub_cache->id_sec == id_sec)
3081 stub_entry = h->stub_cache;
3083 else
3085 char *stub_name;
3087 stub_name = elf32_arm_stub_name (id_sec, sym_sec, h, rel);
3088 if (stub_name == NULL)
3089 return NULL;
3091 stub_entry = arm_stub_hash_lookup (&htab->stub_hash_table,
3092 stub_name, FALSE, FALSE);
3093 if (h != NULL)
3094 h->stub_cache = stub_entry;
3096 free (stub_name);
3099 return stub_entry;
3102 /* Add a new stub entry to the stub hash. Not all fields of the new
3103 stub entry are initialised. */
3105 static struct elf32_arm_stub_hash_entry *
3106 elf32_arm_add_stub (const char *stub_name,
3107 asection *section,
3108 struct elf32_arm_link_hash_table *htab)
3110 asection *link_sec;
3111 asection *stub_sec;
3112 struct elf32_arm_stub_hash_entry *stub_entry;
3114 link_sec = htab->stub_group[section->id].link_sec;
3115 stub_sec = htab->stub_group[section->id].stub_sec;
3116 if (stub_sec == NULL)
3118 stub_sec = htab->stub_group[link_sec->id].stub_sec;
3119 if (stub_sec == NULL)
3121 size_t namelen;
3122 bfd_size_type len;
3123 char *s_name;
3125 namelen = strlen (link_sec->name);
3126 len = namelen + sizeof (STUB_SUFFIX);
3127 s_name = bfd_alloc (htab->stub_bfd, len);
3128 if (s_name == NULL)
3129 return NULL;
3131 memcpy (s_name, link_sec->name, namelen);
3132 memcpy (s_name + namelen, STUB_SUFFIX, sizeof (STUB_SUFFIX));
3133 stub_sec = (*htab->add_stub_section) (s_name, link_sec);
3134 if (stub_sec == NULL)
3135 return NULL;
3136 htab->stub_group[link_sec->id].stub_sec = stub_sec;
3138 htab->stub_group[section->id].stub_sec = stub_sec;
3141 /* Enter this entry into the linker stub hash table. */
3142 stub_entry = arm_stub_hash_lookup (&htab->stub_hash_table, stub_name,
3143 TRUE, FALSE);
3144 if (stub_entry == NULL)
3146 (*_bfd_error_handler) (_("%s: cannot create stub entry %s"),
3147 section->owner,
3148 stub_name);
3149 return NULL;
3152 stub_entry->stub_sec = stub_sec;
3153 stub_entry->stub_offset = 0;
3154 stub_entry->id_sec = link_sec;
3156 return stub_entry;
3159 /* Store an Arm insn into an output section not processed by
3160 elf32_arm_write_section. */
3162 static void
3163 put_arm_insn (struct elf32_arm_link_hash_table * htab,
3164 bfd * output_bfd, bfd_vma val, void * ptr)
3166 if (htab->byteswap_code != bfd_little_endian (output_bfd))
3167 bfd_putl32 (val, ptr);
3168 else
3169 bfd_putb32 (val, ptr);
3172 /* Store a 16-bit Thumb insn into an output section not processed by
3173 elf32_arm_write_section. */
3175 static void
3176 put_thumb_insn (struct elf32_arm_link_hash_table * htab,
3177 bfd * output_bfd, bfd_vma val, void * ptr)
3179 if (htab->byteswap_code != bfd_little_endian (output_bfd))
3180 bfd_putl16 (val, ptr);
3181 else
3182 bfd_putb16 (val, ptr);
3185 static bfd_boolean
3186 arm_build_one_stub (struct bfd_hash_entry *gen_entry,
3187 void * in_arg)
3189 struct elf32_arm_stub_hash_entry *stub_entry;
3190 struct bfd_link_info *info;
3191 struct elf32_arm_link_hash_table *htab;
3192 asection *stub_sec;
3193 bfd *stub_bfd;
3194 bfd_vma stub_addr;
3195 bfd_byte *loc;
3196 bfd_vma sym_value;
3197 int template_size;
3198 int size;
3199 const insn_sequence *template;
3200 int i;
3201 struct elf32_arm_link_hash_table * globals;
3202 int stub_reloc_idx = -1;
3203 int stub_reloc_offset = 0;
3205 /* Massage our args to the form they really have. */
3206 stub_entry = (struct elf32_arm_stub_hash_entry *) gen_entry;
3207 info = (struct bfd_link_info *) in_arg;
3209 globals = elf32_arm_hash_table (info);
3211 htab = elf32_arm_hash_table (info);
3212 stub_sec = stub_entry->stub_sec;
3214 /* Make a note of the offset within the stubs for this entry. */
3215 stub_entry->stub_offset = stub_sec->size;
3216 loc = stub_sec->contents + stub_entry->stub_offset;
3218 stub_bfd = stub_sec->owner;
3220 /* This is the address of the start of the stub. */
3221 stub_addr = stub_sec->output_section->vma + stub_sec->output_offset
3222 + stub_entry->stub_offset;
3224 /* This is the address of the stub destination. */
3225 sym_value = (stub_entry->target_value
3226 + stub_entry->target_section->output_offset
3227 + stub_entry->target_section->output_section->vma);
3229 template = stub_entry->stub_template;
3230 template_size = stub_entry->stub_template_size;
3232 size = 0;
3233 for (i = 0; i < template_size; i++)
3235 switch (template[i].type)
3237 case THUMB16_TYPE:
3238 put_thumb_insn (globals, stub_bfd, template[i].data, loc + size);
3239 size += 2;
3240 break;
3242 case ARM_TYPE:
3243 put_arm_insn (globals, stub_bfd, template[i].data, loc + size);
3244 /* Handle cases where the target is encoded within the
3245 instruction. */
3246 if (template[i].r_type == R_ARM_JUMP24)
3248 stub_reloc_idx = i;
3249 stub_reloc_offset = size;
3251 size += 4;
3252 break;
3254 case DATA_TYPE:
3255 bfd_put_32 (stub_bfd, template[i].data, loc + size);
3256 stub_reloc_idx = i;
3257 stub_reloc_offset = size;
3258 size += 4;
3259 break;
3261 default:
3262 BFD_FAIL ();
3263 return FALSE;
3267 stub_sec->size += size;
3269 /* Stub size has already been computed in arm_size_one_stub. Check
3270 consistency. */
3271 BFD_ASSERT (size == stub_entry->stub_size);
3273 /* Destination is Thumb. Force bit 0 to 1 to reflect this. */
3274 if (stub_entry->st_type == STT_ARM_TFUNC)
3275 sym_value |= 1;
3277 /* Assume there is one and only one entry to relocate in each stub. */
3278 BFD_ASSERT (stub_reloc_idx != -1);
3280 _bfd_final_link_relocate (elf32_arm_howto_from_type (template[stub_reloc_idx].r_type),
3281 stub_bfd, stub_sec, stub_sec->contents,
3282 stub_entry->stub_offset + stub_reloc_offset,
3283 sym_value, template[stub_reloc_idx].reloc_addend);
3285 return TRUE;
3288 /* As above, but don't actually build the stub. Just bump offset so
3289 we know stub section sizes. */
3291 static bfd_boolean
3292 arm_size_one_stub (struct bfd_hash_entry *gen_entry,
3293 void * in_arg)
3295 struct elf32_arm_stub_hash_entry *stub_entry;
3296 struct elf32_arm_link_hash_table *htab;
3297 const insn_sequence *template;
3298 int template_size;
3299 int size;
3300 int i;
3302 /* Massage our args to the form they really have. */
3303 stub_entry = (struct elf32_arm_stub_hash_entry *) gen_entry;
3304 htab = (struct elf32_arm_link_hash_table *) in_arg;
3306 switch (stub_entry->stub_type)
3308 case arm_stub_long_branch_any_any:
3309 template = elf32_arm_stub_long_branch_any_any;
3310 template_size = ARRAY_SIZE (elf32_arm_stub_long_branch_any_any);
3311 break;
3312 case arm_stub_long_branch_v4t_arm_thumb:
3313 template = elf32_arm_stub_long_branch_v4t_arm_thumb;
3314 template_size = ARRAY_SIZE (elf32_arm_stub_long_branch_v4t_arm_thumb);
3315 break;
3316 case arm_stub_long_branch_thumb_only:
3317 template = elf32_arm_stub_long_branch_thumb_only;
3318 template_size = ARRAY_SIZE (elf32_arm_stub_long_branch_thumb_only);
3319 break;
3320 case arm_stub_long_branch_v4t_thumb_arm:
3321 template = elf32_arm_stub_long_branch_v4t_thumb_arm;
3322 template_size = ARRAY_SIZE (elf32_arm_stub_long_branch_v4t_thumb_arm);
3323 break;
3324 case arm_stub_short_branch_v4t_thumb_arm:
3325 template = elf32_arm_stub_short_branch_v4t_thumb_arm;
3326 template_size = ARRAY_SIZE (elf32_arm_stub_short_branch_v4t_thumb_arm);
3327 break;
3328 case arm_stub_long_branch_any_arm_pic:
3329 template = elf32_arm_stub_long_branch_any_arm_pic;
3330 template_size = ARRAY_SIZE (elf32_arm_stub_long_branch_any_arm_pic);
3331 break;
3332 case arm_stub_long_branch_any_thumb_pic:
3333 template = elf32_arm_stub_long_branch_any_thumb_pic;
3334 template_size = ARRAY_SIZE (elf32_arm_stub_long_branch_any_thumb_pic);
3335 break;
3336 case arm_stub_long_branch_v4t_arm_thumb_pic:
3337 template = elf32_arm_stub_long_branch_v4t_arm_thumb_pic;
3338 template_size = ARRAY_SIZE (elf32_arm_stub_long_branch_v4t_arm_thumb_pic);
3339 break;
3340 case arm_stub_long_branch_v4t_thumb_arm_pic:
3341 template = elf32_arm_stub_long_branch_v4t_thumb_arm_pic;
3342 template_size = ARRAY_SIZE (elf32_arm_stub_long_branch_v4t_thumb_arm_pic);
3343 break;
3344 case arm_stub_long_branch_thumb_only_pic:
3345 template = elf32_arm_stub_long_branch_thumb_only_pic;
3346 template_size = ARRAY_SIZE (elf32_arm_stub_long_branch_thumb_only_pic);
3347 break;
3348 default:
3349 BFD_FAIL ();
3350 return FALSE;
3353 size = 0;
3354 for (i = 0; i < template_size; i++)
3356 switch (template[i].type)
3358 case THUMB16_TYPE:
3359 size += 2;
3360 break;
3362 case ARM_TYPE:
3363 size += 4;
3364 break;
3366 case DATA_TYPE:
3367 size += 4;
3368 break;
3370 default:
3371 BFD_FAIL ();
3372 return FALSE;
3376 stub_entry->stub_size = size;
3377 stub_entry->stub_template = template;
3378 stub_entry->stub_template_size = template_size;
3380 size = (size + 7) & ~7;
3381 stub_entry->stub_sec->size += size;
3383 return TRUE;
3386 /* External entry points for sizing and building linker stubs. */
3388 /* Set up various things so that we can make a list of input sections
3389 for each output section included in the link. Returns -1 on error,
3390 0 when no stubs will be needed, and 1 on success. */
3393 elf32_arm_setup_section_lists (bfd *output_bfd,
3394 struct bfd_link_info *info)
3396 bfd *input_bfd;
3397 unsigned int bfd_count;
3398 int top_id, top_index;
3399 asection *section;
3400 asection **input_list, **list;
3401 bfd_size_type amt;
3402 struct elf32_arm_link_hash_table *htab = elf32_arm_hash_table (info);
3404 if (! is_elf_hash_table (htab))
3405 return 0;
3407 /* Count the number of input BFDs and find the top input section id. */
3408 for (input_bfd = info->input_bfds, bfd_count = 0, top_id = 0;
3409 input_bfd != NULL;
3410 input_bfd = input_bfd->link_next)
3412 bfd_count += 1;
3413 for (section = input_bfd->sections;
3414 section != NULL;
3415 section = section->next)
3417 if (top_id < section->id)
3418 top_id = section->id;
3421 htab->bfd_count = bfd_count;
3423 amt = sizeof (struct map_stub) * (top_id + 1);
3424 htab->stub_group = bfd_zmalloc (amt);
3425 if (htab->stub_group == NULL)
3426 return -1;
3428 /* We can't use output_bfd->section_count here to find the top output
3429 section index as some sections may have been removed, and
3430 _bfd_strip_section_from_output doesn't renumber the indices. */
3431 for (section = output_bfd->sections, top_index = 0;
3432 section != NULL;
3433 section = section->next)
3435 if (top_index < section->index)
3436 top_index = section->index;
3439 htab->top_index = top_index;
3440 amt = sizeof (asection *) * (top_index + 1);
3441 input_list = bfd_malloc (amt);
3442 htab->input_list = input_list;
3443 if (input_list == NULL)
3444 return -1;
3446 /* For sections we aren't interested in, mark their entries with a
3447 value we can check later. */
3448 list = input_list + top_index;
3450 *list = bfd_abs_section_ptr;
3451 while (list-- != input_list);
3453 for (section = output_bfd->sections;
3454 section != NULL;
3455 section = section->next)
3457 if ((section->flags & SEC_CODE) != 0)
3458 input_list[section->index] = NULL;
3461 return 1;
3464 /* The linker repeatedly calls this function for each input section,
3465 in the order that input sections are linked into output sections.
3466 Build lists of input sections to determine groupings between which
3467 we may insert linker stubs. */
3469 void
3470 elf32_arm_next_input_section (struct bfd_link_info *info,
3471 asection *isec)
3473 struct elf32_arm_link_hash_table *htab = elf32_arm_hash_table (info);
3475 if (isec->output_section->index <= htab->top_index)
3477 asection **list = htab->input_list + isec->output_section->index;
3479 if (*list != bfd_abs_section_ptr)
3481 /* Steal the link_sec pointer for our list. */
3482 #define PREV_SEC(sec) (htab->stub_group[(sec)->id].link_sec)
3483 /* This happens to make the list in reverse order,
3484 which we reverse later. */
3485 PREV_SEC (isec) = *list;
3486 *list = isec;
3491 /* See whether we can group stub sections together. Grouping stub
3492 sections may result in fewer stubs. More importantly, we need to
3493 put all .init* and .fini* stubs at the end of the .init or
3494 .fini output sections respectively, because glibc splits the
3495 _init and _fini functions into multiple parts. Putting a stub in
3496 the middle of a function is not a good idea. */
3498 static void
3499 group_sections (struct elf32_arm_link_hash_table *htab,
3500 bfd_size_type stub_group_size,
3501 bfd_boolean stubs_always_after_branch)
3503 asection **list = htab->input_list;
3507 asection *tail = *list;
3508 asection *head;
3509 asection *tp;
3511 if (tail == bfd_abs_section_ptr)
3512 continue;
3514 /* Reverse the list: we must avoid placing stubs at the
3515 beginning of the section because the beginning of the text
3516 section may be required for an interrupt vector in bare metal
3517 code. */
3518 #define NEXT_SEC PREV_SEC
3519 head = tail;
3520 tp = NULL;
3521 for (;;)
3523 asection *h = PREV_SEC (head);
3524 NEXT_SEC (head) = tp;
3525 if (h == NULL)
3526 break;
3527 tp = head;
3528 head = h;
3531 while (head != NULL)
3533 asection *curr;
3534 asection *next;
3535 bfd_size_type total;
3537 curr = head;
3538 total = head->size;
3539 while ((next = NEXT_SEC (curr)) != NULL
3540 && ((total += next->output_offset - curr->output_offset)
3541 < stub_group_size))
3542 curr = next;
3544 /* OK, the size from the start to the start of CURR is less
3545 than stub_group_size and thus can be handled by one stub
3546 section. (Or the head section is itself larger than
3547 stub_group_size, in which case we may be toast.)
3548 We should really be keeping track of the total size of
3549 stubs added here, as stubs contribute to the final output
3550 section size. */
3553 next = NEXT_SEC (head);
3554 /* Set up this stub group. */
3555 htab->stub_group[head->id].link_sec = curr;
3557 while (head != curr && (head = next) != NULL);
3559 /* But wait, there's more! Input sections up to stub_group_size
3560 bytes after the stub section can be handled by it too. */
3561 if (!stubs_always_after_branch)
3563 total = 0;
3564 while (next != NULL
3565 && ((total += next->output_offset - head->output_offset)
3566 < stub_group_size))
3568 head = next;
3569 next = NEXT_SEC (head);
3570 htab->stub_group[head->id].link_sec = curr;
3573 head = next;
3576 while (list++ != htab->input_list + htab->top_index);
3578 free (htab->input_list);
3579 #undef PREV_SEC
3580 #undef NEXT_SEC
3583 /* Determine and set the size of the stub section for a final link.
3585 The basic idea here is to examine all the relocations looking for
3586 PC-relative calls to a target that is unreachable with a "bl"
3587 instruction. */
3589 bfd_boolean
3590 elf32_arm_size_stubs (bfd *output_bfd,
3591 bfd *stub_bfd,
3592 struct bfd_link_info *info,
3593 bfd_signed_vma group_size,
3594 asection * (*add_stub_section) (const char *, asection *),
3595 void (*layout_sections_again) (void))
3597 bfd_size_type stub_group_size;
3598 bfd_boolean stubs_always_after_branch;
3599 bfd_boolean stub_changed = 0;
3600 struct elf32_arm_link_hash_table *htab = elf32_arm_hash_table (info);
3602 /* Propagate mach to stub bfd, because it may not have been
3603 finalized when we created stub_bfd. */
3604 bfd_set_arch_mach (stub_bfd, bfd_get_arch (output_bfd),
3605 bfd_get_mach (output_bfd));
3607 /* Stash our params away. */
3608 htab->stub_bfd = stub_bfd;
3609 htab->add_stub_section = add_stub_section;
3610 htab->layout_sections_again = layout_sections_again;
3611 stubs_always_after_branch = group_size < 0;
3612 if (group_size < 0)
3613 stub_group_size = -group_size;
3614 else
3615 stub_group_size = group_size;
3617 if (stub_group_size == 1)
3619 /* Default values. */
3620 /* Thumb branch range is +-4MB has to be used as the default
3621 maximum size (a given section can contain both ARM and Thumb
3622 code, so the worst case has to be taken into account).
3624 This value is 24K less than that, which allows for 2025
3625 12-byte stubs. If we exceed that, then we will fail to link.
3626 The user will have to relink with an explicit group size
3627 option. */
3628 stub_group_size = 4170000;
3631 group_sections (htab, stub_group_size, stubs_always_after_branch);
3633 while (1)
3635 bfd *input_bfd;
3636 unsigned int bfd_indx;
3637 asection *stub_sec;
3639 for (input_bfd = info->input_bfds, bfd_indx = 0;
3640 input_bfd != NULL;
3641 input_bfd = input_bfd->link_next, bfd_indx++)
3643 Elf_Internal_Shdr *symtab_hdr;
3644 asection *section;
3645 Elf_Internal_Sym *local_syms = NULL;
3647 /* We'll need the symbol table in a second. */
3648 symtab_hdr = &elf_tdata (input_bfd)->symtab_hdr;
3649 if (symtab_hdr->sh_info == 0)
3650 continue;
3652 /* Walk over each section attached to the input bfd. */
3653 for (section = input_bfd->sections;
3654 section != NULL;
3655 section = section->next)
3657 Elf_Internal_Rela *internal_relocs, *irelaend, *irela;
3659 /* If there aren't any relocs, then there's nothing more
3660 to do. */
3661 if ((section->flags & SEC_RELOC) == 0
3662 || section->reloc_count == 0
3663 || (section->flags & SEC_CODE) == 0)
3664 continue;
3666 /* If this section is a link-once section that will be
3667 discarded, then don't create any stubs. */
3668 if (section->output_section == NULL
3669 || section->output_section->owner != output_bfd)
3670 continue;
3672 /* Get the relocs. */
3673 internal_relocs
3674 = _bfd_elf_link_read_relocs (input_bfd, section, NULL,
3675 NULL, info->keep_memory);
3676 if (internal_relocs == NULL)
3677 goto error_ret_free_local;
3679 /* Now examine each relocation. */
3680 irela = internal_relocs;
3681 irelaend = irela + section->reloc_count;
3682 for (; irela < irelaend; irela++)
3684 unsigned int r_type, r_indx;
3685 enum elf32_arm_stub_type stub_type;
3686 struct elf32_arm_stub_hash_entry *stub_entry;
3687 asection *sym_sec;
3688 bfd_vma sym_value;
3689 bfd_vma destination;
3690 struct elf32_arm_link_hash_entry *hash;
3691 const char *sym_name;
3692 char *stub_name;
3693 const asection *id_sec;
3694 unsigned char st_type;
3696 r_type = ELF32_R_TYPE (irela->r_info);
3697 r_indx = ELF32_R_SYM (irela->r_info);
3699 if (r_type >= (unsigned int) R_ARM_max)
3701 bfd_set_error (bfd_error_bad_value);
3702 error_ret_free_internal:
3703 if (elf_section_data (section)->relocs == NULL)
3704 free (internal_relocs);
3705 goto error_ret_free_local;
3708 /* Only look for stubs on call instructions. */
3709 if ((r_type != (unsigned int) R_ARM_CALL)
3710 && (r_type != (unsigned int) R_ARM_THM_CALL))
3711 continue;
3713 /* Now determine the call target, its name, value,
3714 section. */
3715 sym_sec = NULL;
3716 sym_value = 0;
3717 destination = 0;
3718 hash = NULL;
3719 sym_name = NULL;
3720 if (r_indx < symtab_hdr->sh_info)
3722 /* It's a local symbol. */
3723 Elf_Internal_Sym *sym;
3724 Elf_Internal_Shdr *hdr;
3726 if (local_syms == NULL)
3728 local_syms
3729 = (Elf_Internal_Sym *) symtab_hdr->contents;
3730 if (local_syms == NULL)
3731 local_syms
3732 = bfd_elf_get_elf_syms (input_bfd, symtab_hdr,
3733 symtab_hdr->sh_info, 0,
3734 NULL, NULL, NULL);
3735 if (local_syms == NULL)
3736 goto error_ret_free_internal;
3739 sym = local_syms + r_indx;
3740 hdr = elf_elfsections (input_bfd)[sym->st_shndx];
3741 sym_sec = hdr->bfd_section;
3742 if (ELF_ST_TYPE (sym->st_info) != STT_SECTION)
3743 sym_value = sym->st_value;
3744 destination = (sym_value + irela->r_addend
3745 + sym_sec->output_offset
3746 + sym_sec->output_section->vma);
3747 st_type = ELF_ST_TYPE (sym->st_info);
3748 sym_name
3749 = bfd_elf_string_from_elf_section (input_bfd,
3750 symtab_hdr->sh_link,
3751 sym->st_name);
3753 else
3755 /* It's an external symbol. */
3756 int e_indx;
3758 e_indx = r_indx - symtab_hdr->sh_info;
3759 hash = ((struct elf32_arm_link_hash_entry *)
3760 elf_sym_hashes (input_bfd)[e_indx]);
3762 while (hash->root.root.type == bfd_link_hash_indirect
3763 || hash->root.root.type == bfd_link_hash_warning)
3764 hash = ((struct elf32_arm_link_hash_entry *)
3765 hash->root.root.u.i.link);
3767 if (hash->root.root.type == bfd_link_hash_defined
3768 || hash->root.root.type == bfd_link_hash_defweak)
3770 sym_sec = hash->root.root.u.def.section;
3771 sym_value = hash->root.root.u.def.value;
3772 if (sym_sec->output_section != NULL)
3773 destination = (sym_value + irela->r_addend
3774 + sym_sec->output_offset
3775 + sym_sec->output_section->vma);
3777 else if (hash->root.root.type == bfd_link_hash_undefweak
3778 || hash->root.root.type == bfd_link_hash_undefined)
3779 /* For a shared library, these will need a PLT stub,
3780 which is treated separately.
3781 For absolute code, they cannot be handled. */
3782 continue;
3783 else
3785 bfd_set_error (bfd_error_bad_value);
3786 goto error_ret_free_internal;
3788 st_type = ELF_ST_TYPE (hash->root.type);
3789 sym_name = hash->root.root.root.string;
3792 /* Determine what (if any) linker stub is needed. */
3793 stub_type = arm_type_of_stub (info, section, irela, st_type,
3794 hash, destination, sym_sec,
3795 input_bfd, sym_name);
3796 if (stub_type == arm_stub_none)
3797 continue;
3799 /* Support for grouping stub sections. */
3800 id_sec = htab->stub_group[section->id].link_sec;
3802 /* Get the name of this stub. */
3803 stub_name = elf32_arm_stub_name (id_sec, sym_sec, hash, irela);
3804 if (!stub_name)
3805 goto error_ret_free_internal;
3807 stub_entry = arm_stub_hash_lookup (&htab->stub_hash_table,
3808 stub_name,
3809 FALSE, FALSE);
3810 if (stub_entry != NULL)
3812 /* The proper stub has already been created. */
3813 free (stub_name);
3814 continue;
3817 stub_entry = elf32_arm_add_stub (stub_name, section, htab);
3818 if (stub_entry == NULL)
3820 free (stub_name);
3821 goto error_ret_free_internal;
3824 stub_entry->target_value = sym_value;
3825 stub_entry->target_section = sym_sec;
3826 stub_entry->stub_type = stub_type;
3827 stub_entry->h = hash;
3828 stub_entry->st_type = st_type;
3830 if (sym_name == NULL)
3831 sym_name = "unnamed";
3832 stub_entry->output_name
3833 = bfd_alloc (htab->stub_bfd,
3834 sizeof (THUMB2ARM_GLUE_ENTRY_NAME)
3835 + strlen (sym_name));
3836 if (stub_entry->output_name == NULL)
3838 free (stub_name);
3839 goto error_ret_free_internal;
3842 /* For historical reasons, use the existing names for
3843 ARM-to-Thumb and Thumb-to-ARM stubs. */
3844 if (r_type == (unsigned int) R_ARM_THM_CALL
3845 && st_type != STT_ARM_TFUNC)
3846 sprintf (stub_entry->output_name, THUMB2ARM_GLUE_ENTRY_NAME,
3847 sym_name);
3848 else if (r_type == (unsigned int) R_ARM_CALL
3849 && st_type == STT_ARM_TFUNC)
3850 sprintf (stub_entry->output_name, ARM2THUMB_GLUE_ENTRY_NAME,
3851 sym_name);
3852 else
3853 sprintf (stub_entry->output_name, STUB_ENTRY_NAME,
3854 sym_name);
3856 stub_changed = TRUE;
3859 /* We're done with the internal relocs, free them. */
3860 if (elf_section_data (section)->relocs == NULL)
3861 free (internal_relocs);
3865 if (!stub_changed)
3866 break;
3868 /* OK, we've added some stubs. Find out the new size of the
3869 stub sections. */
3870 for (stub_sec = htab->stub_bfd->sections;
3871 stub_sec != NULL;
3872 stub_sec = stub_sec->next)
3873 stub_sec->size = 0;
3875 bfd_hash_traverse (&htab->stub_hash_table, arm_size_one_stub, htab);
3877 /* Ask the linker to do its stuff. */
3878 (*htab->layout_sections_again) ();
3879 stub_changed = FALSE;
3882 return TRUE;
3884 error_ret_free_local:
3885 return FALSE;
3888 /* Build all the stubs associated with the current output file. The
3889 stubs are kept in a hash table attached to the main linker hash
3890 table. We also set up the .plt entries for statically linked PIC
3891 functions here. This function is called via arm_elf_finish in the
3892 linker. */
3894 bfd_boolean
3895 elf32_arm_build_stubs (struct bfd_link_info *info)
3897 asection *stub_sec;
3898 struct bfd_hash_table *table;
3899 struct elf32_arm_link_hash_table *htab;
3901 htab = elf32_arm_hash_table (info);
3903 for (stub_sec = htab->stub_bfd->sections;
3904 stub_sec != NULL;
3905 stub_sec = stub_sec->next)
3907 bfd_size_type size;
3909 /* Ignore non-stub sections. */
3910 if (!strstr (stub_sec->name, STUB_SUFFIX))
3911 continue;
3913 /* Allocate memory to hold the linker stubs. */
3914 size = stub_sec->size;
3915 stub_sec->contents = bfd_zalloc (htab->stub_bfd, size);
3916 if (stub_sec->contents == NULL && size != 0)
3917 return FALSE;
3918 stub_sec->size = 0;
3921 /* Build the stubs as directed by the stub hash table. */
3922 table = &htab->stub_hash_table;
3923 bfd_hash_traverse (table, arm_build_one_stub, info);
3925 return TRUE;
3928 /* Locate the Thumb encoded calling stub for NAME. */
3930 static struct elf_link_hash_entry *
3931 find_thumb_glue (struct bfd_link_info *link_info,
3932 const char *name,
3933 char **error_message)
3935 char *tmp_name;
3936 struct elf_link_hash_entry *hash;
3937 struct elf32_arm_link_hash_table *hash_table;
3939 /* We need a pointer to the armelf specific hash table. */
3940 hash_table = elf32_arm_hash_table (link_info);
3942 tmp_name = bfd_malloc ((bfd_size_type) strlen (name)
3943 + strlen (THUMB2ARM_GLUE_ENTRY_NAME) + 1);
3945 BFD_ASSERT (tmp_name);
3947 sprintf (tmp_name, THUMB2ARM_GLUE_ENTRY_NAME, name);
3949 hash = elf_link_hash_lookup
3950 (&(hash_table)->root, tmp_name, FALSE, FALSE, TRUE);
3952 if (hash == NULL
3953 && asprintf (error_message, _("unable to find THUMB glue '%s' for '%s'"),
3954 tmp_name, name) == -1)
3955 *error_message = (char *) bfd_errmsg (bfd_error_system_call);
3957 free (tmp_name);
3959 return hash;
3962 /* Locate the ARM encoded calling stub for NAME. */
3964 static struct elf_link_hash_entry *
3965 find_arm_glue (struct bfd_link_info *link_info,
3966 const char *name,
3967 char **error_message)
3969 char *tmp_name;
3970 struct elf_link_hash_entry *myh;
3971 struct elf32_arm_link_hash_table *hash_table;
3973 /* We need a pointer to the elfarm specific hash table. */
3974 hash_table = elf32_arm_hash_table (link_info);
3976 tmp_name = bfd_malloc ((bfd_size_type) strlen (name)
3977 + strlen (ARM2THUMB_GLUE_ENTRY_NAME) + 1);
3979 BFD_ASSERT (tmp_name);
3981 sprintf (tmp_name, ARM2THUMB_GLUE_ENTRY_NAME, name);
3983 myh = elf_link_hash_lookup
3984 (&(hash_table)->root, tmp_name, FALSE, FALSE, TRUE);
3986 if (myh == NULL
3987 && asprintf (error_message, _("unable to find ARM glue '%s' for '%s'"),
3988 tmp_name, name) == -1)
3989 *error_message = (char *) bfd_errmsg (bfd_error_system_call);
3991 free (tmp_name);
3993 return myh;
3996 /* ARM->Thumb glue (static images):
3998 .arm
3999 __func_from_arm:
4000 ldr r12, __func_addr
4001 bx r12
4002 __func_addr:
4003 .word func @ behave as if you saw a ARM_32 reloc.
4005 (v5t static images)
4006 .arm
4007 __func_from_arm:
4008 ldr pc, __func_addr
4009 __func_addr:
4010 .word func @ behave as if you saw a ARM_32 reloc.
4012 (relocatable images)
4013 .arm
4014 __func_from_arm:
4015 ldr r12, __func_offset
4016 add r12, r12, pc
4017 bx r12
4018 __func_offset:
4019 .word func - . */
4021 #define ARM2THUMB_STATIC_GLUE_SIZE 12
4022 static const insn32 a2t1_ldr_insn = 0xe59fc000;
4023 static const insn32 a2t2_bx_r12_insn = 0xe12fff1c;
4024 static const insn32 a2t3_func_addr_insn = 0x00000001;
4026 #define ARM2THUMB_V5_STATIC_GLUE_SIZE 8
4027 static const insn32 a2t1v5_ldr_insn = 0xe51ff004;
4028 static const insn32 a2t2v5_func_addr_insn = 0x00000001;
4030 #define ARM2THUMB_PIC_GLUE_SIZE 16
4031 static const insn32 a2t1p_ldr_insn = 0xe59fc004;
4032 static const insn32 a2t2p_add_pc_insn = 0xe08cc00f;
4033 static const insn32 a2t3p_bx_r12_insn = 0xe12fff1c;
4035 /* Thumb->ARM: Thumb->(non-interworking aware) ARM
4037 .thumb .thumb
4038 .align 2 .align 2
4039 __func_from_thumb: __func_from_thumb:
4040 bx pc push {r6, lr}
4041 nop ldr r6, __func_addr
4042 .arm mov lr, pc
4043 b func bx r6
4044 .arm
4045 ;; back_to_thumb
4046 ldmia r13! {r6, lr}
4047 bx lr
4048 __func_addr:
4049 .word func */
4051 #define THUMB2ARM_GLUE_SIZE 8
4052 static const insn16 t2a1_bx_pc_insn = 0x4778;
4053 static const insn16 t2a2_noop_insn = 0x46c0;
4054 static const insn32 t2a3_b_insn = 0xea000000;
4056 #define VFP11_ERRATUM_VENEER_SIZE 8
4058 #define ARM_BX_VENEER_SIZE 12
4059 static const insn32 armbx1_tst_insn = 0xe3100001;
4060 static const insn32 armbx2_moveq_insn = 0x01a0f000;
4061 static const insn32 armbx3_bx_insn = 0xe12fff10;
4063 #ifndef ELFARM_NABI_C_INCLUDED
4064 static void
4065 arm_allocate_glue_section_space (bfd * abfd, bfd_size_type size, const char * name)
4067 asection * s;
4068 bfd_byte * contents;
4070 if (size == 0)
4071 return;
4073 BFD_ASSERT (abfd != NULL);
4075 s = bfd_get_section_by_name (abfd, name);
4076 BFD_ASSERT (s != NULL);
4078 contents = bfd_alloc (abfd, size);
4080 BFD_ASSERT (s->size == size);
4081 s->contents = contents;
4084 bfd_boolean
4085 bfd_elf32_arm_allocate_interworking_sections (struct bfd_link_info * info)
4087 struct elf32_arm_link_hash_table * globals;
4089 globals = elf32_arm_hash_table (info);
4090 BFD_ASSERT (globals != NULL);
4092 arm_allocate_glue_section_space (globals->bfd_of_glue_owner,
4093 globals->arm_glue_size,
4094 ARM2THUMB_GLUE_SECTION_NAME);
4096 arm_allocate_glue_section_space (globals->bfd_of_glue_owner,
4097 globals->thumb_glue_size,
4098 THUMB2ARM_GLUE_SECTION_NAME);
4100 arm_allocate_glue_section_space (globals->bfd_of_glue_owner,
4101 globals->vfp11_erratum_glue_size,
4102 VFP11_ERRATUM_VENEER_SECTION_NAME);
4104 arm_allocate_glue_section_space (globals->bfd_of_glue_owner,
4105 globals->bx_glue_size,
4106 ARM_BX_GLUE_SECTION_NAME);
4108 return TRUE;
4111 /* Allocate space and symbols for calling a Thumb function from Arm mode.
4112 returns the symbol identifying the stub. */
4114 static struct elf_link_hash_entry *
4115 record_arm_to_thumb_glue (struct bfd_link_info * link_info,
4116 struct elf_link_hash_entry * h)
4118 const char * name = h->root.root.string;
4119 asection * s;
4120 char * tmp_name;
4121 struct elf_link_hash_entry * myh;
4122 struct bfd_link_hash_entry * bh;
4123 struct elf32_arm_link_hash_table * globals;
4124 bfd_vma val;
4125 bfd_size_type size;
4127 globals = elf32_arm_hash_table (link_info);
4129 BFD_ASSERT (globals != NULL);
4130 BFD_ASSERT (globals->bfd_of_glue_owner != NULL);
4132 s = bfd_get_section_by_name
4133 (globals->bfd_of_glue_owner, ARM2THUMB_GLUE_SECTION_NAME);
4135 BFD_ASSERT (s != NULL);
4137 tmp_name = bfd_malloc ((bfd_size_type) strlen (name) + strlen (ARM2THUMB_GLUE_ENTRY_NAME) + 1);
4139 BFD_ASSERT (tmp_name);
4141 sprintf (tmp_name, ARM2THUMB_GLUE_ENTRY_NAME, name);
4143 myh = elf_link_hash_lookup
4144 (&(globals)->root, tmp_name, FALSE, FALSE, TRUE);
4146 if (myh != NULL)
4148 /* We've already seen this guy. */
4149 free (tmp_name);
4150 return myh;
4153 /* The only trick here is using hash_table->arm_glue_size as the value.
4154 Even though the section isn't allocated yet, this is where we will be
4155 putting it. The +1 on the value marks that the stub has not been
4156 output yet - not that it is a Thumb function. */
4157 bh = NULL;
4158 val = globals->arm_glue_size + 1;
4159 _bfd_generic_link_add_one_symbol (link_info, globals->bfd_of_glue_owner,
4160 tmp_name, BSF_GLOBAL, s, val,
4161 NULL, TRUE, FALSE, &bh);
4163 myh = (struct elf_link_hash_entry *) bh;
4164 myh->type = ELF_ST_INFO (STB_LOCAL, STT_FUNC);
4165 myh->forced_local = 1;
4167 free (tmp_name);
4169 if (link_info->shared || globals->root.is_relocatable_executable
4170 || globals->pic_veneer)
4171 size = ARM2THUMB_PIC_GLUE_SIZE;
4172 else if (globals->use_blx)
4173 size = ARM2THUMB_V5_STATIC_GLUE_SIZE;
4174 else
4175 size = ARM2THUMB_STATIC_GLUE_SIZE;
4177 s->size += size;
4178 globals->arm_glue_size += size;
4180 return myh;
4183 static void
4184 record_thumb_to_arm_glue (struct bfd_link_info *link_info,
4185 struct elf_link_hash_entry *h)
4187 const char *name = h->root.root.string;
4188 asection *s;
4189 char *tmp_name;
4190 struct elf_link_hash_entry *myh;
4191 struct bfd_link_hash_entry *bh;
4192 struct elf32_arm_link_hash_table *hash_table;
4193 bfd_vma val;
4195 hash_table = elf32_arm_hash_table (link_info);
4197 BFD_ASSERT (hash_table != NULL);
4198 BFD_ASSERT (hash_table->bfd_of_glue_owner != NULL);
4200 s = bfd_get_section_by_name
4201 (hash_table->bfd_of_glue_owner, THUMB2ARM_GLUE_SECTION_NAME);
4203 BFD_ASSERT (s != NULL);
4205 tmp_name = bfd_malloc ((bfd_size_type) strlen (name)
4206 + strlen (THUMB2ARM_GLUE_ENTRY_NAME) + 1);
4208 BFD_ASSERT (tmp_name);
4210 sprintf (tmp_name, THUMB2ARM_GLUE_ENTRY_NAME, name);
4212 myh = elf_link_hash_lookup
4213 (&(hash_table)->root, tmp_name, FALSE, FALSE, TRUE);
4215 if (myh != NULL)
4217 /* We've already seen this guy. */
4218 free (tmp_name);
4219 return;
4222 /* The only trick here is using hash_table->thumb_glue_size as the value.
4223 Even though the section isn't allocated yet, this is where we will be
4224 putting it. The +1 on the value marks that the stub has not been
4225 output yet - not that it is a Thumb function. */
4226 bh = NULL;
4227 val = hash_table->thumb_glue_size + 1;
4228 _bfd_generic_link_add_one_symbol (link_info, hash_table->bfd_of_glue_owner,
4229 tmp_name, BSF_GLOBAL, s, val,
4230 NULL, TRUE, FALSE, &bh);
4232 /* If we mark it 'Thumb', the disassembler will do a better job. */
4233 myh = (struct elf_link_hash_entry *) bh;
4234 myh->type = ELF_ST_INFO (STB_LOCAL, STT_ARM_TFUNC);
4235 myh->forced_local = 1;
4237 free (tmp_name);
4239 #define CHANGE_TO_ARM "__%s_change_to_arm"
4240 #define BACK_FROM_ARM "__%s_back_from_arm"
4242 /* Allocate another symbol to mark where we switch to Arm mode. */
4243 tmp_name = bfd_malloc ((bfd_size_type) strlen (name)
4244 + strlen (CHANGE_TO_ARM) + 1);
4246 BFD_ASSERT (tmp_name);
4248 sprintf (tmp_name, CHANGE_TO_ARM, name);
4250 bh = NULL;
4251 val = hash_table->thumb_glue_size + 4,
4252 _bfd_generic_link_add_one_symbol (link_info, hash_table->bfd_of_glue_owner,
4253 tmp_name, BSF_LOCAL, s, val,
4254 NULL, TRUE, FALSE, &bh);
4256 free (tmp_name);
4258 s->size += THUMB2ARM_GLUE_SIZE;
4259 hash_table->thumb_glue_size += THUMB2ARM_GLUE_SIZE;
4263 /* Allocate space for ARMv4 BX veneers. */
4265 static void
4266 record_arm_bx_glue (struct bfd_link_info * link_info, int reg)
4268 asection * s;
4269 struct elf32_arm_link_hash_table *globals;
4270 char *tmp_name;
4271 struct elf_link_hash_entry *myh;
4272 struct bfd_link_hash_entry *bh;
4273 bfd_vma val;
4275 /* BX PC does not need a veneer. */
4276 if (reg == 15)
4277 return;
4279 globals = elf32_arm_hash_table (link_info);
4281 BFD_ASSERT (globals != NULL);
4282 BFD_ASSERT (globals->bfd_of_glue_owner != NULL);
4284 /* Check if this veneer has already been allocated. */
4285 if (globals->bx_glue_offset[reg])
4286 return;
4288 s = bfd_get_section_by_name
4289 (globals->bfd_of_glue_owner, ARM_BX_GLUE_SECTION_NAME);
4291 BFD_ASSERT (s != NULL);
4293 /* Add symbol for veneer. */
4294 tmp_name = bfd_malloc ((bfd_size_type) strlen (ARM_BX_GLUE_ENTRY_NAME) + 1);
4296 BFD_ASSERT (tmp_name);
4298 sprintf (tmp_name, ARM_BX_GLUE_ENTRY_NAME, reg);
4300 myh = elf_link_hash_lookup
4301 (&(globals)->root, tmp_name, FALSE, FALSE, FALSE);
4303 BFD_ASSERT (myh == NULL);
4305 bh = NULL;
4306 val = globals->bx_glue_size;
4307 _bfd_generic_link_add_one_symbol (link_info, globals->bfd_of_glue_owner,
4308 tmp_name, BSF_FUNCTION | BSF_LOCAL, s, val,
4309 NULL, TRUE, FALSE, &bh);
4311 myh = (struct elf_link_hash_entry *) bh;
4312 myh->type = ELF_ST_INFO (STB_LOCAL, STT_FUNC);
4313 myh->forced_local = 1;
4315 s->size += ARM_BX_VENEER_SIZE;
4316 globals->bx_glue_offset[reg] = globals->bx_glue_size | 2;
4317 globals->bx_glue_size += ARM_BX_VENEER_SIZE;
4321 /* Add an entry to the code/data map for section SEC. */
4323 static void
4324 elf32_arm_section_map_add (asection *sec, char type, bfd_vma vma)
4326 struct _arm_elf_section_data *sec_data = elf32_arm_section_data (sec);
4327 unsigned int newidx;
4329 if (sec_data->map == NULL)
4331 sec_data->map = bfd_malloc (sizeof (elf32_arm_section_map));
4332 sec_data->mapcount = 0;
4333 sec_data->mapsize = 1;
4336 newidx = sec_data->mapcount++;
4338 if (sec_data->mapcount > sec_data->mapsize)
4340 sec_data->mapsize *= 2;
4341 sec_data->map = bfd_realloc_or_free (sec_data->map, sec_data->mapsize
4342 * sizeof (elf32_arm_section_map));
4345 if (sec_data->map)
4347 sec_data->map[newidx].vma = vma;
4348 sec_data->map[newidx].type = type;
4353 /* Record information about a VFP11 denorm-erratum veneer. Only ARM-mode
4354 veneers are handled for now. */
4356 static bfd_vma
4357 record_vfp11_erratum_veneer (struct bfd_link_info *link_info,
4358 elf32_vfp11_erratum_list *branch,
4359 bfd *branch_bfd,
4360 asection *branch_sec,
4361 unsigned int offset)
4363 asection *s;
4364 struct elf32_arm_link_hash_table *hash_table;
4365 char *tmp_name;
4366 struct elf_link_hash_entry *myh;
4367 struct bfd_link_hash_entry *bh;
4368 bfd_vma val;
4369 struct _arm_elf_section_data *sec_data;
4370 int errcount;
4371 elf32_vfp11_erratum_list *newerr;
4373 hash_table = elf32_arm_hash_table (link_info);
4375 BFD_ASSERT (hash_table != NULL);
4376 BFD_ASSERT (hash_table->bfd_of_glue_owner != NULL);
4378 s = bfd_get_section_by_name
4379 (hash_table->bfd_of_glue_owner, VFP11_ERRATUM_VENEER_SECTION_NAME);
4381 sec_data = elf32_arm_section_data (s);
4383 BFD_ASSERT (s != NULL);
4385 tmp_name = bfd_malloc ((bfd_size_type) strlen
4386 (VFP11_ERRATUM_VENEER_ENTRY_NAME) + 10);
4388 BFD_ASSERT (tmp_name);
4390 sprintf (tmp_name, VFP11_ERRATUM_VENEER_ENTRY_NAME,
4391 hash_table->num_vfp11_fixes);
4393 myh = elf_link_hash_lookup
4394 (&(hash_table)->root, tmp_name, FALSE, FALSE, FALSE);
4396 BFD_ASSERT (myh == NULL);
4398 bh = NULL;
4399 val = hash_table->vfp11_erratum_glue_size;
4400 _bfd_generic_link_add_one_symbol (link_info, hash_table->bfd_of_glue_owner,
4401 tmp_name, BSF_FUNCTION | BSF_LOCAL, s, val,
4402 NULL, TRUE, FALSE, &bh);
4404 myh = (struct elf_link_hash_entry *) bh;
4405 myh->type = ELF_ST_INFO (STB_LOCAL, STT_FUNC);
4406 myh->forced_local = 1;
4408 /* Link veneer back to calling location. */
4409 errcount = ++(sec_data->erratumcount);
4410 newerr = bfd_zmalloc (sizeof (elf32_vfp11_erratum_list));
4412 newerr->type = VFP11_ERRATUM_ARM_VENEER;
4413 newerr->vma = -1;
4414 newerr->u.v.branch = branch;
4415 newerr->u.v.id = hash_table->num_vfp11_fixes;
4416 branch->u.b.veneer = newerr;
4418 newerr->next = sec_data->erratumlist;
4419 sec_data->erratumlist = newerr;
4421 /* A symbol for the return from the veneer. */
4422 sprintf (tmp_name, VFP11_ERRATUM_VENEER_ENTRY_NAME "_r",
4423 hash_table->num_vfp11_fixes);
4425 myh = elf_link_hash_lookup
4426 (&(hash_table)->root, tmp_name, FALSE, FALSE, FALSE);
4428 if (myh != NULL)
4429 abort ();
4431 bh = NULL;
4432 val = offset + 4;
4433 _bfd_generic_link_add_one_symbol (link_info, branch_bfd, tmp_name, BSF_LOCAL,
4434 branch_sec, val, NULL, TRUE, FALSE, &bh);
4436 myh = (struct elf_link_hash_entry *) bh;
4437 myh->type = ELF_ST_INFO (STB_LOCAL, STT_FUNC);
4438 myh->forced_local = 1;
4440 free (tmp_name);
4442 /* Generate a mapping symbol for the veneer section, and explicitly add an
4443 entry for that symbol to the code/data map for the section. */
4444 if (hash_table->vfp11_erratum_glue_size == 0)
4446 bh = NULL;
4447 /* FIXME: Creates an ARM symbol. Thumb mode will need attention if it
4448 ever requires this erratum fix. */
4449 _bfd_generic_link_add_one_symbol (link_info,
4450 hash_table->bfd_of_glue_owner, "$a",
4451 BSF_LOCAL, s, 0, NULL,
4452 TRUE, FALSE, &bh);
4454 myh = (struct elf_link_hash_entry *) bh;
4455 myh->type = ELF_ST_INFO (STB_LOCAL, STT_NOTYPE);
4456 myh->forced_local = 1;
4458 /* The elf32_arm_init_maps function only cares about symbols from input
4459 BFDs. We must make a note of this generated mapping symbol
4460 ourselves so that code byteswapping works properly in
4461 elf32_arm_write_section. */
4462 elf32_arm_section_map_add (s, 'a', 0);
4465 s->size += VFP11_ERRATUM_VENEER_SIZE;
4466 hash_table->vfp11_erratum_glue_size += VFP11_ERRATUM_VENEER_SIZE;
4467 hash_table->num_vfp11_fixes++;
4469 /* The offset of the veneer. */
4470 return val;
4473 /* Note: we do not include the flag SEC_LINKER_CREATED, as that
4474 would prevent elf_link_input_bfd() from processing the contents
4475 of the section. */
4476 #define ARM_GLUE_SECTION_FLAGS \
4477 (SEC_ALLOC | SEC_LOAD | SEC_HAS_CONTENTS | SEC_IN_MEMORY | SEC_CODE | SEC_READONLY)
4479 /* Create a fake section for use by the ARM backend of the linker. */
4481 static bfd_boolean
4482 arm_make_glue_section (bfd * abfd, const char * name)
4484 asection * sec;
4486 sec = bfd_get_section_by_name (abfd, name);
4487 if (sec != NULL)
4488 /* Already made. */
4489 return TRUE;
4491 sec = bfd_make_section_with_flags (abfd, name, ARM_GLUE_SECTION_FLAGS);
4493 if (sec == NULL
4494 || !bfd_set_section_alignment (abfd, sec, 2))
4495 return FALSE;
4497 /* Set the gc mark to prevent the section from being removed by garbage
4498 collection, despite the fact that no relocs refer to this section. */
4499 sec->gc_mark = 1;
4501 return TRUE;
4504 /* Add the glue sections to ABFD. This function is called from the
4505 linker scripts in ld/emultempl/{armelf}.em. */
4507 bfd_boolean
4508 bfd_elf32_arm_add_glue_sections_to_bfd (bfd *abfd,
4509 struct bfd_link_info *info)
4511 /* If we are only performing a partial
4512 link do not bother adding the glue. */
4513 if (info->relocatable)
4514 return TRUE;
4516 /* Linker stubs don't need glue. */
4517 if (!strcmp (abfd->filename, "linker stubs"))
4518 return TRUE;
4520 return arm_make_glue_section (abfd, ARM2THUMB_GLUE_SECTION_NAME)
4521 && arm_make_glue_section (abfd, THUMB2ARM_GLUE_SECTION_NAME)
4522 && arm_make_glue_section (abfd, VFP11_ERRATUM_VENEER_SECTION_NAME)
4523 && arm_make_glue_section (abfd, ARM_BX_GLUE_SECTION_NAME);
4526 /* Select a BFD to be used to hold the sections used by the glue code.
4527 This function is called from the linker scripts in ld/emultempl/
4528 {armelf/pe}.em. */
4530 bfd_boolean
4531 bfd_elf32_arm_get_bfd_for_interworking (bfd *abfd, struct bfd_link_info *info)
4533 struct elf32_arm_link_hash_table *globals;
4535 /* If we are only performing a partial link
4536 do not bother getting a bfd to hold the glue. */
4537 if (info->relocatable)
4538 return TRUE;
4540 /* Make sure we don't attach the glue sections to a dynamic object. */
4541 BFD_ASSERT (!(abfd->flags & DYNAMIC));
4543 globals = elf32_arm_hash_table (info);
4545 BFD_ASSERT (globals != NULL);
4547 if (globals->bfd_of_glue_owner != NULL)
4548 return TRUE;
4550 /* Save the bfd for later use. */
4551 globals->bfd_of_glue_owner = abfd;
4553 return TRUE;
4556 static void
4557 check_use_blx (struct elf32_arm_link_hash_table *globals)
4559 if (bfd_elf_get_obj_attr_int (globals->obfd, OBJ_ATTR_PROC,
4560 Tag_CPU_arch) > 2)
4561 globals->use_blx = 1;
4564 bfd_boolean
4565 bfd_elf32_arm_process_before_allocation (bfd *abfd,
4566 struct bfd_link_info *link_info)
4568 Elf_Internal_Shdr *symtab_hdr;
4569 Elf_Internal_Rela *internal_relocs = NULL;
4570 Elf_Internal_Rela *irel, *irelend;
4571 bfd_byte *contents = NULL;
4573 asection *sec;
4574 struct elf32_arm_link_hash_table *globals;
4576 /* If we are only performing a partial link do not bother
4577 to construct any glue. */
4578 if (link_info->relocatable)
4579 return TRUE;
4581 /* Here we have a bfd that is to be included on the link. We have a
4582 hook to do reloc rummaging, before section sizes are nailed down. */
4583 globals = elf32_arm_hash_table (link_info);
4585 BFD_ASSERT (globals != NULL);
4587 check_use_blx (globals);
4589 if (globals->byteswap_code && !bfd_big_endian (abfd))
4591 _bfd_error_handler (_("%B: BE8 images only valid in big-endian mode."),
4592 abfd);
4593 return FALSE;
4596 /* PR 5398: If we have not decided to include any loadable sections in
4597 the output then we will not have a glue owner bfd. This is OK, it
4598 just means that there is nothing else for us to do here. */
4599 if (globals->bfd_of_glue_owner == NULL)
4600 return TRUE;
4602 /* Rummage around all the relocs and map the glue vectors. */
4603 sec = abfd->sections;
4605 if (sec == NULL)
4606 return TRUE;
4608 for (; sec != NULL; sec = sec->next)
4610 if (sec->reloc_count == 0)
4611 continue;
4613 if ((sec->flags & SEC_EXCLUDE) != 0)
4614 continue;
4616 symtab_hdr = & elf_symtab_hdr (abfd);
4618 /* Load the relocs. */
4619 internal_relocs
4620 = _bfd_elf_link_read_relocs (abfd, sec, NULL, NULL, FALSE);
4622 if (internal_relocs == NULL)
4623 goto error_return;
4625 irelend = internal_relocs + sec->reloc_count;
4626 for (irel = internal_relocs; irel < irelend; irel++)
4628 long r_type;
4629 unsigned long r_index;
4631 struct elf_link_hash_entry *h;
4633 r_type = ELF32_R_TYPE (irel->r_info);
4634 r_index = ELF32_R_SYM (irel->r_info);
4636 /* These are the only relocation types we care about. */
4637 if ( r_type != R_ARM_PC24
4638 && r_type != R_ARM_PLT32
4639 && r_type != R_ARM_JUMP24
4640 && r_type != R_ARM_THM_JUMP24
4641 && (r_type != R_ARM_V4BX || globals->fix_v4bx < 2))
4642 continue;
4644 /* Get the section contents if we haven't done so already. */
4645 if (contents == NULL)
4647 /* Get cached copy if it exists. */
4648 if (elf_section_data (sec)->this_hdr.contents != NULL)
4649 contents = elf_section_data (sec)->this_hdr.contents;
4650 else
4652 /* Go get them off disk. */
4653 if (! bfd_malloc_and_get_section (abfd, sec, &contents))
4654 goto error_return;
4658 if (r_type == R_ARM_V4BX)
4660 int reg;
4662 reg = bfd_get_32 (abfd, contents + irel->r_offset) & 0xf;
4663 record_arm_bx_glue (link_info, reg);
4664 continue;
4667 /* If the relocation is not against a symbol it cannot concern us. */
4668 h = NULL;
4670 /* We don't care about local symbols. */
4671 if (r_index < symtab_hdr->sh_info)
4672 continue;
4674 /* This is an external symbol. */
4675 r_index -= symtab_hdr->sh_info;
4676 h = (struct elf_link_hash_entry *)
4677 elf_sym_hashes (abfd)[r_index];
4679 /* If the relocation is against a static symbol it must be within
4680 the current section and so cannot be a cross ARM/Thumb relocation. */
4681 if (h == NULL)
4682 continue;
4684 /* If the call will go through a PLT entry then we do not need
4685 glue. */
4686 if (globals->splt != NULL && h->plt.offset != (bfd_vma) -1)
4687 continue;
4689 switch (r_type)
4691 case R_ARM_PC24:
4692 case R_ARM_PLT32:
4693 case R_ARM_JUMP24:
4694 /* This one is a call from arm code. We need to look up
4695 the target of the call. If it is a thumb target, we
4696 insert glue. */
4697 if (ELF_ST_TYPE (h->type) == STT_ARM_TFUNC)
4698 record_arm_to_thumb_glue (link_info, h);
4699 break;
4701 case R_ARM_THM_JUMP24:
4702 /* This one is a call from thumb code. We look
4703 up the target of the call. If it is not a thumb
4704 target, we insert glue. */
4705 if (ELF_ST_TYPE (h->type) != STT_ARM_TFUNC
4706 && !(globals->use_blx && r_type == R_ARM_THM_CALL)
4707 && h->root.type != bfd_link_hash_undefweak)
4708 record_thumb_to_arm_glue (link_info, h);
4709 break;
4711 default:
4712 abort ();
4716 if (contents != NULL
4717 && elf_section_data (sec)->this_hdr.contents != contents)
4718 free (contents);
4719 contents = NULL;
4721 if (internal_relocs != NULL
4722 && elf_section_data (sec)->relocs != internal_relocs)
4723 free (internal_relocs);
4724 internal_relocs = NULL;
4727 return TRUE;
4729 error_return:
4730 if (contents != NULL
4731 && elf_section_data (sec)->this_hdr.contents != contents)
4732 free (contents);
4733 if (internal_relocs != NULL
4734 && elf_section_data (sec)->relocs != internal_relocs)
4735 free (internal_relocs);
4737 return FALSE;
4739 #endif
4742 /* Initialise maps of ARM/Thumb/data for input BFDs. */
4744 void
4745 bfd_elf32_arm_init_maps (bfd *abfd)
4747 Elf_Internal_Sym *isymbuf;
4748 Elf_Internal_Shdr *hdr;
4749 unsigned int i, localsyms;
4751 /* PR 7093: Make sure that we are dealing with an arm elf binary. */
4752 if (! is_arm_elf (abfd))
4753 return;
4755 if ((abfd->flags & DYNAMIC) != 0)
4756 return;
4758 hdr = & elf_symtab_hdr (abfd);
4759 localsyms = hdr->sh_info;
4761 /* Obtain a buffer full of symbols for this BFD. The hdr->sh_info field
4762 should contain the number of local symbols, which should come before any
4763 global symbols. Mapping symbols are always local. */
4764 isymbuf = bfd_elf_get_elf_syms (abfd, hdr, localsyms, 0, NULL, NULL,
4765 NULL);
4767 /* No internal symbols read? Skip this BFD. */
4768 if (isymbuf == NULL)
4769 return;
4771 for (i = 0; i < localsyms; i++)
4773 Elf_Internal_Sym *isym = &isymbuf[i];
4774 asection *sec = bfd_section_from_elf_index (abfd, isym->st_shndx);
4775 const char *name;
4777 if (sec != NULL
4778 && ELF_ST_BIND (isym->st_info) == STB_LOCAL)
4780 name = bfd_elf_string_from_elf_section (abfd,
4781 hdr->sh_link, isym->st_name);
4783 if (bfd_is_arm_special_symbol_name (name,
4784 BFD_ARM_SPECIAL_SYM_TYPE_MAP))
4785 elf32_arm_section_map_add (sec, name[1], isym->st_value);
4791 void
4792 bfd_elf32_arm_set_vfp11_fix (bfd *obfd, struct bfd_link_info *link_info)
4794 struct elf32_arm_link_hash_table *globals = elf32_arm_hash_table (link_info);
4795 obj_attribute *out_attr = elf_known_obj_attributes_proc (obfd);
4797 /* We assume that ARMv7+ does not need the VFP11 denorm erratum fix. */
4798 if (out_attr[Tag_CPU_arch].i >= TAG_CPU_ARCH_V7)
4800 switch (globals->vfp11_fix)
4802 case BFD_ARM_VFP11_FIX_DEFAULT:
4803 case BFD_ARM_VFP11_FIX_NONE:
4804 globals->vfp11_fix = BFD_ARM_VFP11_FIX_NONE;
4805 break;
4807 default:
4808 /* Give a warning, but do as the user requests anyway. */
4809 (*_bfd_error_handler) (_("%B: warning: selected VFP11 erratum "
4810 "workaround is not necessary for target architecture"), obfd);
4813 else if (globals->vfp11_fix == BFD_ARM_VFP11_FIX_DEFAULT)
4814 /* For earlier architectures, we might need the workaround, but do not
4815 enable it by default. If users is running with broken hardware, they
4816 must enable the erratum fix explicitly. */
4817 globals->vfp11_fix = BFD_ARM_VFP11_FIX_NONE;
4821 enum bfd_arm_vfp11_pipe
4823 VFP11_FMAC,
4824 VFP11_LS,
4825 VFP11_DS,
4826 VFP11_BAD
4829 /* Return a VFP register number. This is encoded as RX:X for single-precision
4830 registers, or X:RX for double-precision registers, where RX is the group of
4831 four bits in the instruction encoding and X is the single extension bit.
4832 RX and X fields are specified using their lowest (starting) bit. The return
4833 value is:
4835 0...31: single-precision registers s0...s31
4836 32...63: double-precision registers d0...d31.
4838 Although X should be zero for VFP11 (encoding d0...d15 only), we might
4839 encounter VFP3 instructions, so we allow the full range for DP registers. */
4841 static unsigned int
4842 bfd_arm_vfp11_regno (unsigned int insn, bfd_boolean is_double, unsigned int rx,
4843 unsigned int x)
4845 if (is_double)
4846 return (((insn >> rx) & 0xf) | (((insn >> x) & 1) << 4)) + 32;
4847 else
4848 return (((insn >> rx) & 0xf) << 1) | ((insn >> x) & 1);
4851 /* Set bits in *WMASK according to a register number REG as encoded by
4852 bfd_arm_vfp11_regno(). Ignore d16-d31. */
4854 static void
4855 bfd_arm_vfp11_write_mask (unsigned int *wmask, unsigned int reg)
4857 if (reg < 32)
4858 *wmask |= 1 << reg;
4859 else if (reg < 48)
4860 *wmask |= 3 << ((reg - 32) * 2);
4863 /* Return TRUE if WMASK overwrites anything in REGS. */
4865 static bfd_boolean
4866 bfd_arm_vfp11_antidependency (unsigned int wmask, int *regs, int numregs)
4868 int i;
4870 for (i = 0; i < numregs; i++)
4872 unsigned int reg = regs[i];
4874 if (reg < 32 && (wmask & (1 << reg)) != 0)
4875 return TRUE;
4877 reg -= 32;
4879 if (reg >= 16)
4880 continue;
4882 if ((wmask & (3 << (reg * 2))) != 0)
4883 return TRUE;
4886 return FALSE;
4889 /* In this function, we're interested in two things: finding input registers
4890 for VFP data-processing instructions, and finding the set of registers which
4891 arbitrary VFP instructions may write to. We use a 32-bit unsigned int to
4892 hold the written set, so FLDM etc. are easy to deal with (we're only
4893 interested in 32 SP registers or 16 dp registers, due to the VFP version
4894 implemented by the chip in question). DP registers are marked by setting
4895 both SP registers in the write mask). */
4897 static enum bfd_arm_vfp11_pipe
4898 bfd_arm_vfp11_insn_decode (unsigned int insn, unsigned int *destmask, int *regs,
4899 int *numregs)
4901 enum bfd_arm_vfp11_pipe pipe = VFP11_BAD;
4902 bfd_boolean is_double = ((insn & 0xf00) == 0xb00) ? 1 : 0;
4904 if ((insn & 0x0f000e10) == 0x0e000a00) /* A data-processing insn. */
4906 unsigned int pqrs;
4907 unsigned int fd = bfd_arm_vfp11_regno (insn, is_double, 12, 22);
4908 unsigned int fm = bfd_arm_vfp11_regno (insn, is_double, 0, 5);
4910 pqrs = ((insn & 0x00800000) >> 20)
4911 | ((insn & 0x00300000) >> 19)
4912 | ((insn & 0x00000040) >> 6);
4914 switch (pqrs)
4916 case 0: /* fmac[sd]. */
4917 case 1: /* fnmac[sd]. */
4918 case 2: /* fmsc[sd]. */
4919 case 3: /* fnmsc[sd]. */
4920 pipe = VFP11_FMAC;
4921 bfd_arm_vfp11_write_mask (destmask, fd);
4922 regs[0] = fd;
4923 regs[1] = bfd_arm_vfp11_regno (insn, is_double, 16, 7); /* Fn. */
4924 regs[2] = fm;
4925 *numregs = 3;
4926 break;
4928 case 4: /* fmul[sd]. */
4929 case 5: /* fnmul[sd]. */
4930 case 6: /* fadd[sd]. */
4931 case 7: /* fsub[sd]. */
4932 pipe = VFP11_FMAC;
4933 goto vfp_binop;
4935 case 8: /* fdiv[sd]. */
4936 pipe = VFP11_DS;
4937 vfp_binop:
4938 bfd_arm_vfp11_write_mask (destmask, fd);
4939 regs[0] = bfd_arm_vfp11_regno (insn, is_double, 16, 7); /* Fn. */
4940 regs[1] = fm;
4941 *numregs = 2;
4942 break;
4944 case 15: /* extended opcode. */
4946 unsigned int extn = ((insn >> 15) & 0x1e)
4947 | ((insn >> 7) & 1);
4949 switch (extn)
4951 case 0: /* fcpy[sd]. */
4952 case 1: /* fabs[sd]. */
4953 case 2: /* fneg[sd]. */
4954 case 8: /* fcmp[sd]. */
4955 case 9: /* fcmpe[sd]. */
4956 case 10: /* fcmpz[sd]. */
4957 case 11: /* fcmpez[sd]. */
4958 case 16: /* fuito[sd]. */
4959 case 17: /* fsito[sd]. */
4960 case 24: /* ftoui[sd]. */
4961 case 25: /* ftouiz[sd]. */
4962 case 26: /* ftosi[sd]. */
4963 case 27: /* ftosiz[sd]. */
4964 /* These instructions will not bounce due to underflow. */
4965 *numregs = 0;
4966 pipe = VFP11_FMAC;
4967 break;
4969 case 3: /* fsqrt[sd]. */
4970 /* fsqrt cannot underflow, but it can (perhaps) overwrite
4971 registers to cause the erratum in previous instructions. */
4972 bfd_arm_vfp11_write_mask (destmask, fd);
4973 pipe = VFP11_DS;
4974 break;
4976 case 15: /* fcvt{ds,sd}. */
4978 int rnum = 0;
4980 bfd_arm_vfp11_write_mask (destmask, fd);
4982 /* Only FCVTSD can underflow. */
4983 if ((insn & 0x100) != 0)
4984 regs[rnum++] = fm;
4986 *numregs = rnum;
4988 pipe = VFP11_FMAC;
4990 break;
4992 default:
4993 return VFP11_BAD;
4996 break;
4998 default:
4999 return VFP11_BAD;
5002 /* Two-register transfer. */
5003 else if ((insn & 0x0fe00ed0) == 0x0c400a10)
5005 unsigned int fm = bfd_arm_vfp11_regno (insn, is_double, 0, 5);
5007 if ((insn & 0x100000) == 0)
5009 if (is_double)
5010 bfd_arm_vfp11_write_mask (destmask, fm);
5011 else
5013 bfd_arm_vfp11_write_mask (destmask, fm);
5014 bfd_arm_vfp11_write_mask (destmask, fm + 1);
5018 pipe = VFP11_LS;
5020 else if ((insn & 0x0e100e00) == 0x0c100a00) /* A load insn. */
5022 int fd = bfd_arm_vfp11_regno (insn, is_double, 12, 22);
5023 unsigned int puw = ((insn >> 21) & 0x1) | (((insn >> 23) & 3) << 1);
5025 switch (puw)
5027 case 0: /* Two-reg transfer. We should catch these above. */
5028 abort ();
5030 case 2: /* fldm[sdx]. */
5031 case 3:
5032 case 5:
5034 unsigned int i, offset = insn & 0xff;
5036 if (is_double)
5037 offset >>= 1;
5039 for (i = fd; i < fd + offset; i++)
5040 bfd_arm_vfp11_write_mask (destmask, i);
5042 break;
5044 case 4: /* fld[sd]. */
5045 case 6:
5046 bfd_arm_vfp11_write_mask (destmask, fd);
5047 break;
5049 default:
5050 return VFP11_BAD;
5053 pipe = VFP11_LS;
5055 /* Single-register transfer. Note L==0. */
5056 else if ((insn & 0x0f100e10) == 0x0e000a10)
5058 unsigned int opcode = (insn >> 21) & 7;
5059 unsigned int fn = bfd_arm_vfp11_regno (insn, is_double, 16, 7);
5061 switch (opcode)
5063 case 0: /* fmsr/fmdlr. */
5064 case 1: /* fmdhr. */
5065 /* Mark fmdhr and fmdlr as writing to the whole of the DP
5066 destination register. I don't know if this is exactly right,
5067 but it is the conservative choice. */
5068 bfd_arm_vfp11_write_mask (destmask, fn);
5069 break;
5071 case 7: /* fmxr. */
5072 break;
5075 pipe = VFP11_LS;
5078 return pipe;
5082 static int elf32_arm_compare_mapping (const void * a, const void * b);
5085 /* Look for potentially-troublesome code sequences which might trigger the
5086 VFP11 denormal/antidependency erratum. See, e.g., the ARM1136 errata sheet
5087 (available from ARM) for details of the erratum. A short version is
5088 described in ld.texinfo. */
5090 bfd_boolean
5091 bfd_elf32_arm_vfp11_erratum_scan (bfd *abfd, struct bfd_link_info *link_info)
5093 asection *sec;
5094 bfd_byte *contents = NULL;
5095 int state = 0;
5096 int regs[3], numregs = 0;
5097 struct elf32_arm_link_hash_table *globals = elf32_arm_hash_table (link_info);
5098 int use_vector = (globals->vfp11_fix == BFD_ARM_VFP11_FIX_VECTOR);
5100 /* We use a simple FSM to match troublesome VFP11 instruction sequences.
5101 The states transition as follows:
5103 0 -> 1 (vector) or 0 -> 2 (scalar)
5104 A VFP FMAC-pipeline instruction has been seen. Fill
5105 regs[0]..regs[numregs-1] with its input operands. Remember this
5106 instruction in 'first_fmac'.
5108 1 -> 2
5109 Any instruction, except for a VFP instruction which overwrites
5110 regs[*].
5112 1 -> 3 [ -> 0 ] or
5113 2 -> 3 [ -> 0 ]
5114 A VFP instruction has been seen which overwrites any of regs[*].
5115 We must make a veneer! Reset state to 0 before examining next
5116 instruction.
5118 2 -> 0
5119 If we fail to match anything in state 2, reset to state 0 and reset
5120 the instruction pointer to the instruction after 'first_fmac'.
5122 If the VFP11 vector mode is in use, there must be at least two unrelated
5123 instructions between anti-dependent VFP11 instructions to properly avoid
5124 triggering the erratum, hence the use of the extra state 1. */
5126 /* If we are only performing a partial link do not bother
5127 to construct any glue. */
5128 if (link_info->relocatable)
5129 return TRUE;
5131 /* Skip if this bfd does not correspond to an ELF image. */
5132 if (! is_arm_elf (abfd))
5133 return TRUE;
5135 /* We should have chosen a fix type by the time we get here. */
5136 BFD_ASSERT (globals->vfp11_fix != BFD_ARM_VFP11_FIX_DEFAULT);
5138 if (globals->vfp11_fix == BFD_ARM_VFP11_FIX_NONE)
5139 return TRUE;
5141 /* Skip this BFD if it corresponds to an executable or dynamic object. */
5142 if ((abfd->flags & (EXEC_P | DYNAMIC)) != 0)
5143 return TRUE;
5145 for (sec = abfd->sections; sec != NULL; sec = sec->next)
5147 unsigned int i, span, first_fmac = 0, veneer_of_insn = 0;
5148 struct _arm_elf_section_data *sec_data;
5150 /* If we don't have executable progbits, we're not interested in this
5151 section. Also skip if section is to be excluded. */
5152 if (elf_section_type (sec) != SHT_PROGBITS
5153 || (elf_section_flags (sec) & SHF_EXECINSTR) == 0
5154 || (sec->flags & SEC_EXCLUDE) != 0
5155 || sec->sec_info_type == ELF_INFO_TYPE_JUST_SYMS
5156 || sec->output_section == bfd_abs_section_ptr
5157 || strcmp (sec->name, VFP11_ERRATUM_VENEER_SECTION_NAME) == 0)
5158 continue;
5160 sec_data = elf32_arm_section_data (sec);
5162 if (sec_data->mapcount == 0)
5163 continue;
5165 if (elf_section_data (sec)->this_hdr.contents != NULL)
5166 contents = elf_section_data (sec)->this_hdr.contents;
5167 else if (! bfd_malloc_and_get_section (abfd, sec, &contents))
5168 goto error_return;
5170 qsort (sec_data->map, sec_data->mapcount, sizeof (elf32_arm_section_map),
5171 elf32_arm_compare_mapping);
5173 for (span = 0; span < sec_data->mapcount; span++)
5175 unsigned int span_start = sec_data->map[span].vma;
5176 unsigned int span_end = (span == sec_data->mapcount - 1)
5177 ? sec->size : sec_data->map[span + 1].vma;
5178 char span_type = sec_data->map[span].type;
5180 /* FIXME: Only ARM mode is supported at present. We may need to
5181 support Thumb-2 mode also at some point. */
5182 if (span_type != 'a')
5183 continue;
5185 for (i = span_start; i < span_end;)
5187 unsigned int next_i = i + 4;
5188 unsigned int insn = bfd_big_endian (abfd)
5189 ? (contents[i] << 24)
5190 | (contents[i + 1] << 16)
5191 | (contents[i + 2] << 8)
5192 | contents[i + 3]
5193 : (contents[i + 3] << 24)
5194 | (contents[i + 2] << 16)
5195 | (contents[i + 1] << 8)
5196 | contents[i];
5197 unsigned int writemask = 0;
5198 enum bfd_arm_vfp11_pipe pipe;
5200 switch (state)
5202 case 0:
5203 pipe = bfd_arm_vfp11_insn_decode (insn, &writemask, regs,
5204 &numregs);
5205 /* I'm assuming the VFP11 erratum can trigger with denorm
5206 operands on either the FMAC or the DS pipeline. This might
5207 lead to slightly overenthusiastic veneer insertion. */
5208 if (pipe == VFP11_FMAC || pipe == VFP11_DS)
5210 state = use_vector ? 1 : 2;
5211 first_fmac = i;
5212 veneer_of_insn = insn;
5214 break;
5216 case 1:
5218 int other_regs[3], other_numregs;
5219 pipe = bfd_arm_vfp11_insn_decode (insn, &writemask,
5220 other_regs,
5221 &other_numregs);
5222 if (pipe != VFP11_BAD
5223 && bfd_arm_vfp11_antidependency (writemask, regs,
5224 numregs))
5225 state = 3;
5226 else
5227 state = 2;
5229 break;
5231 case 2:
5233 int other_regs[3], other_numregs;
5234 pipe = bfd_arm_vfp11_insn_decode (insn, &writemask,
5235 other_regs,
5236 &other_numregs);
5237 if (pipe != VFP11_BAD
5238 && bfd_arm_vfp11_antidependency (writemask, regs,
5239 numregs))
5240 state = 3;
5241 else
5243 state = 0;
5244 next_i = first_fmac + 4;
5247 break;
5249 case 3:
5250 abort (); /* Should be unreachable. */
5253 if (state == 3)
5255 elf32_vfp11_erratum_list *newerr
5256 = bfd_zmalloc (sizeof (elf32_vfp11_erratum_list));
5257 int errcount;
5259 errcount = ++(elf32_arm_section_data (sec)->erratumcount);
5261 newerr->u.b.vfp_insn = veneer_of_insn;
5263 switch (span_type)
5265 case 'a':
5266 newerr->type = VFP11_ERRATUM_BRANCH_TO_ARM_VENEER;
5267 break;
5269 default:
5270 abort ();
5273 record_vfp11_erratum_veneer (link_info, newerr, abfd, sec,
5274 first_fmac);
5276 newerr->vma = -1;
5278 newerr->next = sec_data->erratumlist;
5279 sec_data->erratumlist = newerr;
5281 state = 0;
5284 i = next_i;
5288 if (contents != NULL
5289 && elf_section_data (sec)->this_hdr.contents != contents)
5290 free (contents);
5291 contents = NULL;
5294 return TRUE;
5296 error_return:
5297 if (contents != NULL
5298 && elf_section_data (sec)->this_hdr.contents != contents)
5299 free (contents);
5301 return FALSE;
5304 /* Find virtual-memory addresses for VFP11 erratum veneers and return locations
5305 after sections have been laid out, using specially-named symbols. */
5307 void
5308 bfd_elf32_arm_vfp11_fix_veneer_locations (bfd *abfd,
5309 struct bfd_link_info *link_info)
5311 asection *sec;
5312 struct elf32_arm_link_hash_table *globals;
5313 char *tmp_name;
5315 if (link_info->relocatable)
5316 return;
5318 /* Skip if this bfd does not correspond to an ELF image. */
5319 if (! is_arm_elf (abfd))
5320 return;
5322 globals = elf32_arm_hash_table (link_info);
5324 tmp_name = bfd_malloc ((bfd_size_type) strlen
5325 (VFP11_ERRATUM_VENEER_ENTRY_NAME) + 10);
5327 for (sec = abfd->sections; sec != NULL; sec = sec->next)
5329 struct _arm_elf_section_data *sec_data = elf32_arm_section_data (sec);
5330 elf32_vfp11_erratum_list *errnode = sec_data->erratumlist;
5332 for (; errnode != NULL; errnode = errnode->next)
5334 struct elf_link_hash_entry *myh;
5335 bfd_vma vma;
5337 switch (errnode->type)
5339 case VFP11_ERRATUM_BRANCH_TO_ARM_VENEER:
5340 case VFP11_ERRATUM_BRANCH_TO_THUMB_VENEER:
5341 /* Find veneer symbol. */
5342 sprintf (tmp_name, VFP11_ERRATUM_VENEER_ENTRY_NAME,
5343 errnode->u.b.veneer->u.v.id);
5345 myh = elf_link_hash_lookup
5346 (&(globals)->root, tmp_name, FALSE, FALSE, TRUE);
5348 if (myh == NULL)
5349 (*_bfd_error_handler) (_("%B: unable to find VFP11 veneer "
5350 "`%s'"), abfd, tmp_name);
5352 vma = myh->root.u.def.section->output_section->vma
5353 + myh->root.u.def.section->output_offset
5354 + myh->root.u.def.value;
5356 errnode->u.b.veneer->vma = vma;
5357 break;
5359 case VFP11_ERRATUM_ARM_VENEER:
5360 case VFP11_ERRATUM_THUMB_VENEER:
5361 /* Find return location. */
5362 sprintf (tmp_name, VFP11_ERRATUM_VENEER_ENTRY_NAME "_r",
5363 errnode->u.v.id);
5365 myh = elf_link_hash_lookup
5366 (&(globals)->root, tmp_name, FALSE, FALSE, TRUE);
5368 if (myh == NULL)
5369 (*_bfd_error_handler) (_("%B: unable to find VFP11 veneer "
5370 "`%s'"), abfd, tmp_name);
5372 vma = myh->root.u.def.section->output_section->vma
5373 + myh->root.u.def.section->output_offset
5374 + myh->root.u.def.value;
5376 errnode->u.v.branch->vma = vma;
5377 break;
5379 default:
5380 abort ();
5385 free (tmp_name);
5389 /* Set target relocation values needed during linking. */
5391 void
5392 bfd_elf32_arm_set_target_relocs (struct bfd *output_bfd,
5393 struct bfd_link_info *link_info,
5394 int target1_is_rel,
5395 char * target2_type,
5396 int fix_v4bx,
5397 int use_blx,
5398 bfd_arm_vfp11_fix vfp11_fix,
5399 int no_enum_warn, int no_wchar_warn,
5400 int pic_veneer)
5402 struct elf32_arm_link_hash_table *globals;
5404 globals = elf32_arm_hash_table (link_info);
5406 globals->target1_is_rel = target1_is_rel;
5407 if (strcmp (target2_type, "rel") == 0)
5408 globals->target2_reloc = R_ARM_REL32;
5409 else if (strcmp (target2_type, "abs") == 0)
5410 globals->target2_reloc = R_ARM_ABS32;
5411 else if (strcmp (target2_type, "got-rel") == 0)
5412 globals->target2_reloc = R_ARM_GOT_PREL;
5413 else
5415 _bfd_error_handler (_("Invalid TARGET2 relocation type '%s'."),
5416 target2_type);
5418 globals->fix_v4bx = fix_v4bx;
5419 globals->use_blx |= use_blx;
5420 globals->vfp11_fix = vfp11_fix;
5421 globals->pic_veneer = pic_veneer;
5423 BFD_ASSERT (is_arm_elf (output_bfd));
5424 elf_arm_tdata (output_bfd)->no_enum_size_warning = no_enum_warn;
5425 elf_arm_tdata (output_bfd)->no_wchar_size_warning = no_wchar_warn;
5428 /* Replace the target offset of a Thumb bl or b.w instruction. */
5430 static void
5431 insert_thumb_branch (bfd *abfd, long int offset, bfd_byte *insn)
5433 bfd_vma upper;
5434 bfd_vma lower;
5435 int reloc_sign;
5437 BFD_ASSERT ((offset & 1) == 0);
5439 upper = bfd_get_16 (abfd, insn);
5440 lower = bfd_get_16 (abfd, insn + 2);
5441 reloc_sign = (offset < 0) ? 1 : 0;
5442 upper = (upper & ~(bfd_vma) 0x7ff)
5443 | ((offset >> 12) & 0x3ff)
5444 | (reloc_sign << 10);
5445 lower = (lower & ~(bfd_vma) 0x2fff)
5446 | (((!((offset >> 23) & 1)) ^ reloc_sign) << 13)
5447 | (((!((offset >> 22) & 1)) ^ reloc_sign) << 11)
5448 | ((offset >> 1) & 0x7ff);
5449 bfd_put_16 (abfd, upper, insn);
5450 bfd_put_16 (abfd, lower, insn + 2);
5453 /* Thumb code calling an ARM function. */
5455 static int
5456 elf32_thumb_to_arm_stub (struct bfd_link_info * info,
5457 const char * name,
5458 bfd * input_bfd,
5459 bfd * output_bfd,
5460 asection * input_section,
5461 bfd_byte * hit_data,
5462 asection * sym_sec,
5463 bfd_vma offset,
5464 bfd_signed_vma addend,
5465 bfd_vma val,
5466 char **error_message)
5468 asection * s = 0;
5469 bfd_vma my_offset;
5470 long int ret_offset;
5471 struct elf_link_hash_entry * myh;
5472 struct elf32_arm_link_hash_table * globals;
5474 myh = find_thumb_glue (info, name, error_message);
5475 if (myh == NULL)
5476 return FALSE;
5478 globals = elf32_arm_hash_table (info);
5480 BFD_ASSERT (globals != NULL);
5481 BFD_ASSERT (globals->bfd_of_glue_owner != NULL);
5483 my_offset = myh->root.u.def.value;
5485 s = bfd_get_section_by_name (globals->bfd_of_glue_owner,
5486 THUMB2ARM_GLUE_SECTION_NAME);
5488 BFD_ASSERT (s != NULL);
5489 BFD_ASSERT (s->contents != NULL);
5490 BFD_ASSERT (s->output_section != NULL);
5492 if ((my_offset & 0x01) == 0x01)
5494 if (sym_sec != NULL
5495 && sym_sec->owner != NULL
5496 && !INTERWORK_FLAG (sym_sec->owner))
5498 (*_bfd_error_handler)
5499 (_("%B(%s): warning: interworking not enabled.\n"
5500 " first occurrence: %B: thumb call to arm"),
5501 sym_sec->owner, input_bfd, name);
5503 return FALSE;
5506 --my_offset;
5507 myh->root.u.def.value = my_offset;
5509 put_thumb_insn (globals, output_bfd, (bfd_vma) t2a1_bx_pc_insn,
5510 s->contents + my_offset);
5512 put_thumb_insn (globals, output_bfd, (bfd_vma) t2a2_noop_insn,
5513 s->contents + my_offset + 2);
5515 ret_offset =
5516 /* Address of destination of the stub. */
5517 ((bfd_signed_vma) val)
5518 - ((bfd_signed_vma)
5519 /* Offset from the start of the current section
5520 to the start of the stubs. */
5521 (s->output_offset
5522 /* Offset of the start of this stub from the start of the stubs. */
5523 + my_offset
5524 /* Address of the start of the current section. */
5525 + s->output_section->vma)
5526 /* The branch instruction is 4 bytes into the stub. */
5528 /* ARM branches work from the pc of the instruction + 8. */
5529 + 8);
5531 put_arm_insn (globals, output_bfd,
5532 (bfd_vma) t2a3_b_insn | ((ret_offset >> 2) & 0x00FFFFFF),
5533 s->contents + my_offset + 4);
5536 BFD_ASSERT (my_offset <= globals->thumb_glue_size);
5538 /* Now go back and fix up the original BL insn to point to here. */
5539 ret_offset =
5540 /* Address of where the stub is located. */
5541 (s->output_section->vma + s->output_offset + my_offset)
5542 /* Address of where the BL is located. */
5543 - (input_section->output_section->vma + input_section->output_offset
5544 + offset)
5545 /* Addend in the relocation. */
5546 - addend
5547 /* Biassing for PC-relative addressing. */
5548 - 8;
5550 insert_thumb_branch (input_bfd, ret_offset, hit_data - input_section->vma);
5552 return TRUE;
5555 /* Populate an Arm to Thumb stub. Returns the stub symbol. */
5557 static struct elf_link_hash_entry *
5558 elf32_arm_create_thumb_stub (struct bfd_link_info * info,
5559 const char * name,
5560 bfd * input_bfd,
5561 bfd * output_bfd,
5562 asection * sym_sec,
5563 bfd_vma val,
5564 asection * s,
5565 char ** error_message)
5567 bfd_vma my_offset;
5568 long int ret_offset;
5569 struct elf_link_hash_entry * myh;
5570 struct elf32_arm_link_hash_table * globals;
5572 myh = find_arm_glue (info, name, error_message);
5573 if (myh == NULL)
5574 return NULL;
5576 globals = elf32_arm_hash_table (info);
5578 BFD_ASSERT (globals != NULL);
5579 BFD_ASSERT (globals->bfd_of_glue_owner != NULL);
5581 my_offset = myh->root.u.def.value;
5583 if ((my_offset & 0x01) == 0x01)
5585 if (sym_sec != NULL
5586 && sym_sec->owner != NULL
5587 && !INTERWORK_FLAG (sym_sec->owner))
5589 (*_bfd_error_handler)
5590 (_("%B(%s): warning: interworking not enabled.\n"
5591 " first occurrence: %B: arm call to thumb"),
5592 sym_sec->owner, input_bfd, name);
5595 --my_offset;
5596 myh->root.u.def.value = my_offset;
5598 if (info->shared || globals->root.is_relocatable_executable
5599 || globals->pic_veneer)
5601 /* For relocatable objects we can't use absolute addresses,
5602 so construct the address from a relative offset. */
5603 /* TODO: If the offset is small it's probably worth
5604 constructing the address with adds. */
5605 put_arm_insn (globals, output_bfd, (bfd_vma) a2t1p_ldr_insn,
5606 s->contents + my_offset);
5607 put_arm_insn (globals, output_bfd, (bfd_vma) a2t2p_add_pc_insn,
5608 s->contents + my_offset + 4);
5609 put_arm_insn (globals, output_bfd, (bfd_vma) a2t3p_bx_r12_insn,
5610 s->contents + my_offset + 8);
5611 /* Adjust the offset by 4 for the position of the add,
5612 and 8 for the pipeline offset. */
5613 ret_offset = (val - (s->output_offset
5614 + s->output_section->vma
5615 + my_offset + 12))
5616 | 1;
5617 bfd_put_32 (output_bfd, ret_offset,
5618 s->contents + my_offset + 12);
5620 else if (globals->use_blx)
5622 put_arm_insn (globals, output_bfd, (bfd_vma) a2t1v5_ldr_insn,
5623 s->contents + my_offset);
5625 /* It's a thumb address. Add the low order bit. */
5626 bfd_put_32 (output_bfd, val | a2t2v5_func_addr_insn,
5627 s->contents + my_offset + 4);
5629 else
5631 put_arm_insn (globals, output_bfd, (bfd_vma) a2t1_ldr_insn,
5632 s->contents + my_offset);
5634 put_arm_insn (globals, output_bfd, (bfd_vma) a2t2_bx_r12_insn,
5635 s->contents + my_offset + 4);
5637 /* It's a thumb address. Add the low order bit. */
5638 bfd_put_32 (output_bfd, val | a2t3_func_addr_insn,
5639 s->contents + my_offset + 8);
5641 my_offset += 12;
5645 BFD_ASSERT (my_offset <= globals->arm_glue_size);
5647 return myh;
5650 /* Arm code calling a Thumb function. */
5652 static int
5653 elf32_arm_to_thumb_stub (struct bfd_link_info * info,
5654 const char * name,
5655 bfd * input_bfd,
5656 bfd * output_bfd,
5657 asection * input_section,
5658 bfd_byte * hit_data,
5659 asection * sym_sec,
5660 bfd_vma offset,
5661 bfd_signed_vma addend,
5662 bfd_vma val,
5663 char **error_message)
5665 unsigned long int tmp;
5666 bfd_vma my_offset;
5667 asection * s;
5668 long int ret_offset;
5669 struct elf_link_hash_entry * myh;
5670 struct elf32_arm_link_hash_table * globals;
5672 globals = elf32_arm_hash_table (info);
5674 BFD_ASSERT (globals != NULL);
5675 BFD_ASSERT (globals->bfd_of_glue_owner != NULL);
5677 s = bfd_get_section_by_name (globals->bfd_of_glue_owner,
5678 ARM2THUMB_GLUE_SECTION_NAME);
5679 BFD_ASSERT (s != NULL);
5680 BFD_ASSERT (s->contents != NULL);
5681 BFD_ASSERT (s->output_section != NULL);
5683 myh = elf32_arm_create_thumb_stub (info, name, input_bfd, output_bfd,
5684 sym_sec, val, s, error_message);
5685 if (!myh)
5686 return FALSE;
5688 my_offset = myh->root.u.def.value;
5689 tmp = bfd_get_32 (input_bfd, hit_data);
5690 tmp = tmp & 0xFF000000;
5692 /* Somehow these are both 4 too far, so subtract 8. */
5693 ret_offset = (s->output_offset
5694 + my_offset
5695 + s->output_section->vma
5696 - (input_section->output_offset
5697 + input_section->output_section->vma
5698 + offset + addend)
5699 - 8);
5701 tmp = tmp | ((ret_offset >> 2) & 0x00FFFFFF);
5703 bfd_put_32 (output_bfd, (bfd_vma) tmp, hit_data - input_section->vma);
5705 return TRUE;
5708 /* Populate Arm stub for an exported Thumb function. */
5710 static bfd_boolean
5711 elf32_arm_to_thumb_export_stub (struct elf_link_hash_entry *h, void * inf)
5713 struct bfd_link_info * info = (struct bfd_link_info *) inf;
5714 asection * s;
5715 struct elf_link_hash_entry * myh;
5716 struct elf32_arm_link_hash_entry *eh;
5717 struct elf32_arm_link_hash_table * globals;
5718 asection *sec;
5719 bfd_vma val;
5720 char *error_message;
5722 eh = elf32_arm_hash_entry (h);
5723 /* Allocate stubs for exported Thumb functions on v4t. */
5724 if (eh->export_glue == NULL)
5725 return TRUE;
5727 globals = elf32_arm_hash_table (info);
5729 BFD_ASSERT (globals != NULL);
5730 BFD_ASSERT (globals->bfd_of_glue_owner != NULL);
5732 s = bfd_get_section_by_name (globals->bfd_of_glue_owner,
5733 ARM2THUMB_GLUE_SECTION_NAME);
5734 BFD_ASSERT (s != NULL);
5735 BFD_ASSERT (s->contents != NULL);
5736 BFD_ASSERT (s->output_section != NULL);
5738 sec = eh->export_glue->root.u.def.section;
5740 BFD_ASSERT (sec->output_section != NULL);
5742 val = eh->export_glue->root.u.def.value + sec->output_offset
5743 + sec->output_section->vma;
5745 myh = elf32_arm_create_thumb_stub (info, h->root.root.string,
5746 h->root.u.def.section->owner,
5747 globals->obfd, sec, val, s,
5748 &error_message);
5749 BFD_ASSERT (myh);
5750 return TRUE;
5753 /* Populate ARMv4 BX veneers. Returns the absolute adress of the veneer. */
5755 static bfd_vma
5756 elf32_arm_bx_glue (struct bfd_link_info * info, int reg)
5758 bfd_byte *p;
5759 bfd_vma glue_addr;
5760 asection *s;
5761 struct elf32_arm_link_hash_table *globals;
5763 globals = elf32_arm_hash_table (info);
5765 BFD_ASSERT (globals != NULL);
5766 BFD_ASSERT (globals->bfd_of_glue_owner != NULL);
5768 s = bfd_get_section_by_name (globals->bfd_of_glue_owner,
5769 ARM_BX_GLUE_SECTION_NAME);
5770 BFD_ASSERT (s != NULL);
5771 BFD_ASSERT (s->contents != NULL);
5772 BFD_ASSERT (s->output_section != NULL);
5774 BFD_ASSERT (globals->bx_glue_offset[reg] & 2);
5776 glue_addr = globals->bx_glue_offset[reg] & ~(bfd_vma)3;
5778 if ((globals->bx_glue_offset[reg] & 1) == 0)
5780 p = s->contents + glue_addr;
5781 bfd_put_32 (globals->obfd, armbx1_tst_insn + (reg << 16), p);
5782 bfd_put_32 (globals->obfd, armbx2_moveq_insn + reg, p + 4);
5783 bfd_put_32 (globals->obfd, armbx3_bx_insn + reg, p + 8);
5784 globals->bx_glue_offset[reg] |= 1;
5787 return glue_addr + s->output_section->vma + s->output_offset;
5790 /* Generate Arm stubs for exported Thumb symbols. */
5791 static void
5792 elf32_arm_begin_write_processing (bfd *abfd ATTRIBUTE_UNUSED,
5793 struct bfd_link_info *link_info)
5795 struct elf32_arm_link_hash_table * globals;
5797 if (link_info == NULL)
5798 /* Ignore this if we are not called by the ELF backend linker. */
5799 return;
5801 globals = elf32_arm_hash_table (link_info);
5802 /* If blx is available then exported Thumb symbols are OK and there is
5803 nothing to do. */
5804 if (globals->use_blx)
5805 return;
5807 elf_link_hash_traverse (&globals->root, elf32_arm_to_thumb_export_stub,
5808 link_info);
5811 /* Some relocations map to different relocations depending on the
5812 target. Return the real relocation. */
5814 static int
5815 arm_real_reloc_type (struct elf32_arm_link_hash_table * globals,
5816 int r_type)
5818 switch (r_type)
5820 case R_ARM_TARGET1:
5821 if (globals->target1_is_rel)
5822 return R_ARM_REL32;
5823 else
5824 return R_ARM_ABS32;
5826 case R_ARM_TARGET2:
5827 return globals->target2_reloc;
5829 default:
5830 return r_type;
5834 /* Return the base VMA address which should be subtracted from real addresses
5835 when resolving @dtpoff relocation.
5836 This is PT_TLS segment p_vaddr. */
5838 static bfd_vma
5839 dtpoff_base (struct bfd_link_info *info)
5841 /* If tls_sec is NULL, we should have signalled an error already. */
5842 if (elf_hash_table (info)->tls_sec == NULL)
5843 return 0;
5844 return elf_hash_table (info)->tls_sec->vma;
5847 /* Return the relocation value for @tpoff relocation
5848 if STT_TLS virtual address is ADDRESS. */
5850 static bfd_vma
5851 tpoff (struct bfd_link_info *info, bfd_vma address)
5853 struct elf_link_hash_table *htab = elf_hash_table (info);
5854 bfd_vma base;
5856 /* If tls_sec is NULL, we should have signalled an error already. */
5857 if (htab->tls_sec == NULL)
5858 return 0;
5859 base = align_power ((bfd_vma) TCB_SIZE, htab->tls_sec->alignment_power);
5860 return address - htab->tls_sec->vma + base;
5863 /* Perform an R_ARM_ABS12 relocation on the field pointed to by DATA.
5864 VALUE is the relocation value. */
5866 static bfd_reloc_status_type
5867 elf32_arm_abs12_reloc (bfd *abfd, void *data, bfd_vma value)
5869 if (value > 0xfff)
5870 return bfd_reloc_overflow;
5872 value |= bfd_get_32 (abfd, data) & 0xfffff000;
5873 bfd_put_32 (abfd, value, data);
5874 return bfd_reloc_ok;
5877 /* For a given value of n, calculate the value of G_n as required to
5878 deal with group relocations. We return it in the form of an
5879 encoded constant-and-rotation, together with the final residual. If n is
5880 specified as less than zero, then final_residual is filled with the
5881 input value and no further action is performed. */
5883 static bfd_vma
5884 calculate_group_reloc_mask (bfd_vma value, int n, bfd_vma *final_residual)
5886 int current_n;
5887 bfd_vma g_n;
5888 bfd_vma encoded_g_n = 0;
5889 bfd_vma residual = value; /* Also known as Y_n. */
5891 for (current_n = 0; current_n <= n; current_n++)
5893 int shift;
5895 /* Calculate which part of the value to mask. */
5896 if (residual == 0)
5897 shift = 0;
5898 else
5900 int msb;
5902 /* Determine the most significant bit in the residual and
5903 align the resulting value to a 2-bit boundary. */
5904 for (msb = 30; msb >= 0; msb -= 2)
5905 if (residual & (3 << msb))
5906 break;
5908 /* The desired shift is now (msb - 6), or zero, whichever
5909 is the greater. */
5910 shift = msb - 6;
5911 if (shift < 0)
5912 shift = 0;
5915 /* Calculate g_n in 32-bit as well as encoded constant+rotation form. */
5916 g_n = residual & (0xff << shift);
5917 encoded_g_n = (g_n >> shift)
5918 | ((g_n <= 0xff ? 0 : (32 - shift) / 2) << 8);
5920 /* Calculate the residual for the next time around. */
5921 residual &= ~g_n;
5924 *final_residual = residual;
5926 return encoded_g_n;
5929 /* Given an ARM instruction, determine whether it is an ADD or a SUB.
5930 Returns 1 if it is an ADD, -1 if it is a SUB, and 0 otherwise. */
5932 static int
5933 identify_add_or_sub (bfd_vma insn)
5935 int opcode = insn & 0x1e00000;
5937 if (opcode == 1 << 23) /* ADD */
5938 return 1;
5940 if (opcode == 1 << 22) /* SUB */
5941 return -1;
5943 return 0;
5946 /* Perform a relocation as part of a final link. */
5948 static bfd_reloc_status_type
5949 elf32_arm_final_link_relocate (reloc_howto_type * howto,
5950 bfd * input_bfd,
5951 bfd * output_bfd,
5952 asection * input_section,
5953 bfd_byte * contents,
5954 Elf_Internal_Rela * rel,
5955 bfd_vma value,
5956 struct bfd_link_info * info,
5957 asection * sym_sec,
5958 const char * sym_name,
5959 int sym_flags,
5960 struct elf_link_hash_entry * h,
5961 bfd_boolean * unresolved_reloc_p,
5962 char ** error_message)
5964 unsigned long r_type = howto->type;
5965 unsigned long r_symndx;
5966 bfd_byte * hit_data = contents + rel->r_offset;
5967 bfd * dynobj = NULL;
5968 Elf_Internal_Shdr * symtab_hdr;
5969 struct elf_link_hash_entry ** sym_hashes;
5970 bfd_vma * local_got_offsets;
5971 asection * sgot = NULL;
5972 asection * splt = NULL;
5973 asection * sreloc = NULL;
5974 bfd_vma addend;
5975 bfd_signed_vma signed_addend;
5976 struct elf32_arm_link_hash_table * globals;
5978 globals = elf32_arm_hash_table (info);
5980 BFD_ASSERT (is_arm_elf (input_bfd));
5982 /* Some relocation types map to different relocations depending on the
5983 target. We pick the right one here. */
5984 r_type = arm_real_reloc_type (globals, r_type);
5985 if (r_type != howto->type)
5986 howto = elf32_arm_howto_from_type (r_type);
5988 /* If the start address has been set, then set the EF_ARM_HASENTRY
5989 flag. Setting this more than once is redundant, but the cost is
5990 not too high, and it keeps the code simple.
5992 The test is done here, rather than somewhere else, because the
5993 start address is only set just before the final link commences.
5995 Note - if the user deliberately sets a start address of 0, the
5996 flag will not be set. */
5997 if (bfd_get_start_address (output_bfd) != 0)
5998 elf_elfheader (output_bfd)->e_flags |= EF_ARM_HASENTRY;
6000 dynobj = elf_hash_table (info)->dynobj;
6001 if (dynobj)
6003 sgot = bfd_get_section_by_name (dynobj, ".got");
6004 splt = bfd_get_section_by_name (dynobj, ".plt");
6006 symtab_hdr = & elf_symtab_hdr (input_bfd);
6007 sym_hashes = elf_sym_hashes (input_bfd);
6008 local_got_offsets = elf_local_got_offsets (input_bfd);
6009 r_symndx = ELF32_R_SYM (rel->r_info);
6011 if (globals->use_rel)
6013 addend = bfd_get_32 (input_bfd, hit_data) & howto->src_mask;
6015 if (addend & ((howto->src_mask + 1) >> 1))
6017 signed_addend = -1;
6018 signed_addend &= ~ howto->src_mask;
6019 signed_addend |= addend;
6021 else
6022 signed_addend = addend;
6024 else
6025 addend = signed_addend = rel->r_addend;
6027 switch (r_type)
6029 case R_ARM_NONE:
6030 /* We don't need to find a value for this symbol. It's just a
6031 marker. */
6032 *unresolved_reloc_p = FALSE;
6033 return bfd_reloc_ok;
6035 case R_ARM_ABS12:
6036 if (!globals->vxworks_p)
6037 return elf32_arm_abs12_reloc (input_bfd, hit_data, value + addend);
6039 case R_ARM_PC24:
6040 case R_ARM_ABS32:
6041 case R_ARM_ABS32_NOI:
6042 case R_ARM_REL32:
6043 case R_ARM_REL32_NOI:
6044 case R_ARM_CALL:
6045 case R_ARM_JUMP24:
6046 case R_ARM_XPC25:
6047 case R_ARM_PREL31:
6048 case R_ARM_PLT32:
6049 /* Handle relocations which should use the PLT entry. ABS32/REL32
6050 will use the symbol's value, which may point to a PLT entry, but we
6051 don't need to handle that here. If we created a PLT entry, all
6052 branches in this object should go to it. */
6053 if ((r_type != R_ARM_ABS32 && r_type != R_ARM_REL32
6054 && r_type != R_ARM_ABS32_NOI && r_type != R_ARM_REL32_NOI)
6055 && h != NULL
6056 && splt != NULL
6057 && h->plt.offset != (bfd_vma) -1)
6059 /* If we've created a .plt section, and assigned a PLT entry to
6060 this function, it should not be known to bind locally. If
6061 it were, we would have cleared the PLT entry. */
6062 BFD_ASSERT (!SYMBOL_CALLS_LOCAL (info, h));
6064 value = (splt->output_section->vma
6065 + splt->output_offset
6066 + h->plt.offset);
6067 *unresolved_reloc_p = FALSE;
6068 return _bfd_final_link_relocate (howto, input_bfd, input_section,
6069 contents, rel->r_offset, value,
6070 rel->r_addend);
6073 /* When generating a shared object or relocatable executable, these
6074 relocations are copied into the output file to be resolved at
6075 run time. */
6076 if ((info->shared || globals->root.is_relocatable_executable)
6077 && (input_section->flags & SEC_ALLOC)
6078 && !(elf32_arm_hash_table (info)->vxworks_p
6079 && strcmp (input_section->output_section->name,
6080 ".tls_vars") == 0)
6081 && ((r_type != R_ARM_REL32 && r_type != R_ARM_REL32_NOI)
6082 || !SYMBOL_CALLS_LOCAL (info, h))
6083 && (h == NULL
6084 || ELF_ST_VISIBILITY (h->other) == STV_DEFAULT
6085 || h->root.type != bfd_link_hash_undefweak)
6086 && r_type != R_ARM_PC24
6087 && r_type != R_ARM_CALL
6088 && r_type != R_ARM_JUMP24
6089 && r_type != R_ARM_PREL31
6090 && r_type != R_ARM_PLT32)
6092 Elf_Internal_Rela outrel;
6093 bfd_byte *loc;
6094 bfd_boolean skip, relocate;
6096 *unresolved_reloc_p = FALSE;
6098 if (sreloc == NULL)
6100 sreloc = _bfd_elf_get_dynamic_reloc_section (input_bfd, input_section,
6101 ! globals->use_rel);
6103 if (sreloc == NULL)
6104 return bfd_reloc_notsupported;
6107 skip = FALSE;
6108 relocate = FALSE;
6110 outrel.r_addend = addend;
6111 outrel.r_offset =
6112 _bfd_elf_section_offset (output_bfd, info, input_section,
6113 rel->r_offset);
6114 if (outrel.r_offset == (bfd_vma) -1)
6115 skip = TRUE;
6116 else if (outrel.r_offset == (bfd_vma) -2)
6117 skip = TRUE, relocate = TRUE;
6118 outrel.r_offset += (input_section->output_section->vma
6119 + input_section->output_offset);
6121 if (skip)
6122 memset (&outrel, 0, sizeof outrel);
6123 else if (h != NULL
6124 && h->dynindx != -1
6125 && (!info->shared
6126 || !info->symbolic
6127 || !h->def_regular))
6128 outrel.r_info = ELF32_R_INFO (h->dynindx, r_type);
6129 else
6131 int symbol;
6133 /* This symbol is local, or marked to become local. */
6134 if (sym_flags == STT_ARM_TFUNC)
6135 value |= 1;
6136 if (globals->symbian_p)
6138 asection *osec;
6140 /* On Symbian OS, the data segment and text segement
6141 can be relocated independently. Therefore, we
6142 must indicate the segment to which this
6143 relocation is relative. The BPABI allows us to
6144 use any symbol in the right segment; we just use
6145 the section symbol as it is convenient. (We
6146 cannot use the symbol given by "h" directly as it
6147 will not appear in the dynamic symbol table.)
6149 Note that the dynamic linker ignores the section
6150 symbol value, so we don't subtract osec->vma
6151 from the emitted reloc addend. */
6152 if (sym_sec)
6153 osec = sym_sec->output_section;
6154 else
6155 osec = input_section->output_section;
6156 symbol = elf_section_data (osec)->dynindx;
6157 if (symbol == 0)
6159 struct elf_link_hash_table *htab = elf_hash_table (info);
6161 if ((osec->flags & SEC_READONLY) == 0
6162 && htab->data_index_section != NULL)
6163 osec = htab->data_index_section;
6164 else
6165 osec = htab->text_index_section;
6166 symbol = elf_section_data (osec)->dynindx;
6168 BFD_ASSERT (symbol != 0);
6170 else
6171 /* On SVR4-ish systems, the dynamic loader cannot
6172 relocate the text and data segments independently,
6173 so the symbol does not matter. */
6174 symbol = 0;
6175 outrel.r_info = ELF32_R_INFO (symbol, R_ARM_RELATIVE);
6176 if (globals->use_rel)
6177 relocate = TRUE;
6178 else
6179 outrel.r_addend += value;
6182 loc = sreloc->contents;
6183 loc += sreloc->reloc_count++ * RELOC_SIZE (globals);
6184 SWAP_RELOC_OUT (globals) (output_bfd, &outrel, loc);
6186 /* If this reloc is against an external symbol, we do not want to
6187 fiddle with the addend. Otherwise, we need to include the symbol
6188 value so that it becomes an addend for the dynamic reloc. */
6189 if (! relocate)
6190 return bfd_reloc_ok;
6192 return _bfd_final_link_relocate (howto, input_bfd, input_section,
6193 contents, rel->r_offset, value,
6194 (bfd_vma) 0);
6196 else switch (r_type)
6198 case R_ARM_ABS12:
6199 return elf32_arm_abs12_reloc (input_bfd, hit_data, value + addend);
6201 case R_ARM_XPC25: /* Arm BLX instruction. */
6202 case R_ARM_CALL:
6203 case R_ARM_JUMP24:
6204 case R_ARM_PC24: /* Arm B/BL instruction. */
6205 case R_ARM_PLT32:
6207 bfd_vma from;
6208 bfd_signed_vma branch_offset;
6209 struct elf32_arm_stub_hash_entry *stub_entry = NULL;
6211 from = (input_section->output_section->vma
6212 + input_section->output_offset
6213 + rel->r_offset);
6214 branch_offset = (bfd_signed_vma)(value - from);
6216 if (r_type == R_ARM_XPC25)
6218 /* Check for Arm calling Arm function. */
6219 /* FIXME: Should we translate the instruction into a BL
6220 instruction instead ? */
6221 if (sym_flags != STT_ARM_TFUNC)
6222 (*_bfd_error_handler)
6223 (_("\%B: Warning: Arm BLX instruction targets Arm function '%s'."),
6224 input_bfd,
6225 h ? h->root.root.string : "(local)");
6227 else if (r_type != R_ARM_CALL)
6229 /* Check for Arm calling Thumb function. */
6230 if (sym_flags == STT_ARM_TFUNC)
6232 if (elf32_arm_to_thumb_stub (info, sym_name, input_bfd,
6233 output_bfd, input_section,
6234 hit_data, sym_sec, rel->r_offset,
6235 signed_addend, value,
6236 error_message))
6237 return bfd_reloc_ok;
6238 else
6239 return bfd_reloc_dangerous;
6243 /* Check if a stub has to be inserted because the
6244 destination is too far or we are changing mode. */
6245 if (r_type == R_ARM_CALL)
6247 if (branch_offset > ARM_MAX_FWD_BRANCH_OFFSET
6248 || branch_offset < ARM_MAX_BWD_BRANCH_OFFSET
6249 || sym_flags == STT_ARM_TFUNC)
6251 /* The target is out of reach, so redirect the
6252 branch to the local stub for this function. */
6254 stub_entry = elf32_arm_get_stub_entry (input_section,
6255 sym_sec, h,
6256 rel, globals);
6257 if (stub_entry != NULL)
6258 value = (stub_entry->stub_offset
6259 + stub_entry->stub_sec->output_offset
6260 + stub_entry->stub_sec->output_section->vma);
6264 /* The ARM ELF ABI says that this reloc is computed as: S - P + A
6265 where:
6266 S is the address of the symbol in the relocation.
6267 P is address of the instruction being relocated.
6268 A is the addend (extracted from the instruction) in bytes.
6270 S is held in 'value'.
6271 P is the base address of the section containing the
6272 instruction plus the offset of the reloc into that
6273 section, ie:
6274 (input_section->output_section->vma +
6275 input_section->output_offset +
6276 rel->r_offset).
6277 A is the addend, converted into bytes, ie:
6278 (signed_addend * 4)
6280 Note: None of these operations have knowledge of the pipeline
6281 size of the processor, thus it is up to the assembler to
6282 encode this information into the addend. */
6283 value -= (input_section->output_section->vma
6284 + input_section->output_offset);
6285 value -= rel->r_offset;
6286 if (globals->use_rel)
6287 value += (signed_addend << howto->size);
6288 else
6289 /* RELA addends do not have to be adjusted by howto->size. */
6290 value += signed_addend;
6292 signed_addend = value;
6293 signed_addend >>= howto->rightshift;
6295 /* A branch to an undefined weak symbol is turned into a jump to
6296 the next instruction. */
6297 if (h && h->root.type == bfd_link_hash_undefweak)
6299 value = (bfd_get_32 (input_bfd, hit_data) & 0xf0000000)
6300 | 0x0affffff;
6302 else
6304 /* Perform a signed range check. */
6305 if ( signed_addend > ((bfd_signed_vma) (howto->dst_mask >> 1))
6306 || signed_addend < - ((bfd_signed_vma) ((howto->dst_mask + 1) >> 1)))
6307 return bfd_reloc_overflow;
6309 addend = (value & 2);
6311 value = (signed_addend & howto->dst_mask)
6312 | (bfd_get_32 (input_bfd, hit_data) & (~ howto->dst_mask));
6314 /* Set the H bit in the BLX instruction. */
6315 if (sym_flags == STT_ARM_TFUNC)
6317 if (addend)
6318 value |= (1 << 24);
6319 else
6320 value &= ~(bfd_vma)(1 << 24);
6322 if (r_type == R_ARM_CALL)
6324 /* Select the correct instruction (BL or BLX). */
6325 /* Only if we are not handling a BL to a stub. In this
6326 case, mode switching is performed by the stub. */
6327 if (sym_flags == STT_ARM_TFUNC && !stub_entry)
6328 value |= (1 << 28);
6329 else
6331 value &= ~(bfd_vma)(1 << 28);
6332 value |= (1 << 24);
6337 break;
6339 case R_ARM_ABS32:
6340 value += addend;
6341 if (sym_flags == STT_ARM_TFUNC)
6342 value |= 1;
6343 break;
6345 case R_ARM_ABS32_NOI:
6346 value += addend;
6347 break;
6349 case R_ARM_REL32:
6350 value += addend;
6351 if (sym_flags == STT_ARM_TFUNC)
6352 value |= 1;
6353 value -= (input_section->output_section->vma
6354 + input_section->output_offset + rel->r_offset);
6355 break;
6357 case R_ARM_REL32_NOI:
6358 value += addend;
6359 value -= (input_section->output_section->vma
6360 + input_section->output_offset + rel->r_offset);
6361 break;
6363 case R_ARM_PREL31:
6364 value -= (input_section->output_section->vma
6365 + input_section->output_offset + rel->r_offset);
6366 value += signed_addend;
6367 if (! h || h->root.type != bfd_link_hash_undefweak)
6369 /* Check for overflow. */
6370 if ((value ^ (value >> 1)) & (1 << 30))
6371 return bfd_reloc_overflow;
6373 value &= 0x7fffffff;
6374 value |= (bfd_get_32 (input_bfd, hit_data) & 0x80000000);
6375 if (sym_flags == STT_ARM_TFUNC)
6376 value |= 1;
6377 break;
6380 bfd_put_32 (input_bfd, value, hit_data);
6381 return bfd_reloc_ok;
6383 case R_ARM_ABS8:
6384 value += addend;
6385 if ((long) value > 0x7f || (long) value < -0x80)
6386 return bfd_reloc_overflow;
6388 bfd_put_8 (input_bfd, value, hit_data);
6389 return bfd_reloc_ok;
6391 case R_ARM_ABS16:
6392 value += addend;
6394 if ((long) value > 0x7fff || (long) value < -0x8000)
6395 return bfd_reloc_overflow;
6397 bfd_put_16 (input_bfd, value, hit_data);
6398 return bfd_reloc_ok;
6400 case R_ARM_THM_ABS5:
6401 /* Support ldr and str instructions for the thumb. */
6402 if (globals->use_rel)
6404 /* Need to refetch addend. */
6405 addend = bfd_get_16 (input_bfd, hit_data) & howto->src_mask;
6406 /* ??? Need to determine shift amount from operand size. */
6407 addend >>= howto->rightshift;
6409 value += addend;
6411 /* ??? Isn't value unsigned? */
6412 if ((long) value > 0x1f || (long) value < -0x10)
6413 return bfd_reloc_overflow;
6415 /* ??? Value needs to be properly shifted into place first. */
6416 value |= bfd_get_16 (input_bfd, hit_data) & 0xf83f;
6417 bfd_put_16 (input_bfd, value, hit_data);
6418 return bfd_reloc_ok;
6420 case R_ARM_THM_ALU_PREL_11_0:
6421 /* Corresponds to: addw.w reg, pc, #offset (and similarly for subw). */
6423 bfd_vma insn;
6424 bfd_signed_vma relocation;
6426 insn = (bfd_get_16 (input_bfd, hit_data) << 16)
6427 | bfd_get_16 (input_bfd, hit_data + 2);
6429 if (globals->use_rel)
6431 signed_addend = (insn & 0xff) | ((insn & 0x7000) >> 4)
6432 | ((insn & (1 << 26)) >> 15);
6433 if (insn & 0xf00000)
6434 signed_addend = -signed_addend;
6437 relocation = value + signed_addend;
6438 relocation -= (input_section->output_section->vma
6439 + input_section->output_offset
6440 + rel->r_offset);
6442 value = abs (relocation);
6444 if (value >= 0x1000)
6445 return bfd_reloc_overflow;
6447 insn = (insn & 0xfb0f8f00) | (value & 0xff)
6448 | ((value & 0x700) << 4)
6449 | ((value & 0x800) << 15);
6450 if (relocation < 0)
6451 insn |= 0xa00000;
6453 bfd_put_16 (input_bfd, insn >> 16, hit_data);
6454 bfd_put_16 (input_bfd, insn & 0xffff, hit_data + 2);
6456 return bfd_reloc_ok;
6459 case R_ARM_THM_PC12:
6460 /* Corresponds to: ldr.w reg, [pc, #offset]. */
6462 bfd_vma insn;
6463 bfd_signed_vma relocation;
6465 insn = (bfd_get_16 (input_bfd, hit_data) << 16)
6466 | bfd_get_16 (input_bfd, hit_data + 2);
6468 if (globals->use_rel)
6470 signed_addend = insn & 0xfff;
6471 if (!(insn & (1 << 23)))
6472 signed_addend = -signed_addend;
6475 relocation = value + signed_addend;
6476 relocation -= (input_section->output_section->vma
6477 + input_section->output_offset
6478 + rel->r_offset);
6480 value = abs (relocation);
6482 if (value >= 0x1000)
6483 return bfd_reloc_overflow;
6485 insn = (insn & 0xff7ff000) | value;
6486 if (relocation >= 0)
6487 insn |= (1 << 23);
6489 bfd_put_16 (input_bfd, insn >> 16, hit_data);
6490 bfd_put_16 (input_bfd, insn & 0xffff, hit_data + 2);
6492 return bfd_reloc_ok;
6495 case R_ARM_THM_XPC22:
6496 case R_ARM_THM_CALL:
6497 case R_ARM_THM_JUMP24:
6498 /* Thumb BL (branch long instruction). */
6500 bfd_vma relocation;
6501 bfd_vma reloc_sign;
6502 bfd_boolean overflow = FALSE;
6503 bfd_vma upper_insn = bfd_get_16 (input_bfd, hit_data);
6504 bfd_vma lower_insn = bfd_get_16 (input_bfd, hit_data + 2);
6505 bfd_signed_vma reloc_signed_max;
6506 bfd_signed_vma reloc_signed_min;
6507 bfd_vma check;
6508 bfd_signed_vma signed_check;
6509 int bitsize;
6510 int thumb2 = using_thumb2 (globals);
6512 /* A branch to an undefined weak symbol is turned into a jump to
6513 the next instruction unless a PLT entry will be created. */
6514 if (h && h->root.type == bfd_link_hash_undefweak
6515 && !(splt != NULL && h->plt.offset != (bfd_vma) -1))
6517 bfd_put_16 (input_bfd, 0xe000, hit_data);
6518 bfd_put_16 (input_bfd, 0xbf00, hit_data + 2);
6519 return bfd_reloc_ok;
6522 /* Fetch the addend. We use the Thumb-2 encoding (backwards compatible
6523 with Thumb-1) involving the J1 and J2 bits. */
6524 if (globals->use_rel)
6526 bfd_vma s = (upper_insn & (1 << 10)) >> 10;
6527 bfd_vma upper = upper_insn & 0x3ff;
6528 bfd_vma lower = lower_insn & 0x7ff;
6529 bfd_vma j1 = (lower_insn & (1 << 13)) >> 13;
6530 bfd_vma j2 = (lower_insn & (1 << 11)) >> 11;
6531 bfd_vma i1 = j1 ^ s ? 0 : 1;
6532 bfd_vma i2 = j2 ^ s ? 0 : 1;
6534 addend = (i1 << 23) | (i2 << 22) | (upper << 12) | (lower << 1);
6535 /* Sign extend. */
6536 addend = (addend | ((s ? 0 : 1) << 24)) - (1 << 24);
6538 signed_addend = addend;
6541 if (r_type == R_ARM_THM_XPC22)
6543 /* Check for Thumb to Thumb call. */
6544 /* FIXME: Should we translate the instruction into a BL
6545 instruction instead ? */
6546 if (sym_flags == STT_ARM_TFUNC)
6547 (*_bfd_error_handler)
6548 (_("%B: Warning: Thumb BLX instruction targets thumb function '%s'."),
6549 input_bfd,
6550 h ? h->root.root.string : "(local)");
6552 else
6554 /* If it is not a call to Thumb, assume call to Arm.
6555 If it is a call relative to a section name, then it is not a
6556 function call at all, but rather a long jump. Calls through
6557 the PLT do not require stubs. */
6558 if (sym_flags != STT_ARM_TFUNC && sym_flags != STT_SECTION
6559 && (h == NULL || splt == NULL
6560 || h->plt.offset == (bfd_vma) -1))
6562 if (globals->use_blx && r_type == R_ARM_THM_CALL)
6564 /* Convert BL to BLX. */
6565 lower_insn = (lower_insn & ~0x1000) | 0x0800;
6567 else if (r_type != R_ARM_THM_CALL)
6569 if (elf32_thumb_to_arm_stub
6570 (info, sym_name, input_bfd, output_bfd, input_section,
6571 hit_data, sym_sec, rel->r_offset, signed_addend, value,
6572 error_message))
6573 return bfd_reloc_ok;
6574 else
6575 return bfd_reloc_dangerous;
6578 else if (sym_flags == STT_ARM_TFUNC && globals->use_blx
6579 && r_type == R_ARM_THM_CALL)
6581 /* Make sure this is a BL. */
6582 lower_insn |= 0x1800;
6586 /* Handle calls via the PLT. */
6587 if (h != NULL && splt != NULL && h->plt.offset != (bfd_vma) -1)
6589 value = (splt->output_section->vma
6590 + splt->output_offset
6591 + h->plt.offset);
6592 if (globals->use_blx && r_type == R_ARM_THM_CALL)
6594 /* If the Thumb BLX instruction is available, convert the
6595 BL to a BLX instruction to call the ARM-mode PLT entry. */
6596 lower_insn = (lower_insn & ~0x1000) | 0x0800;
6598 else
6599 /* Target the Thumb stub before the ARM PLT entry. */
6600 value -= PLT_THUMB_STUB_SIZE;
6601 *unresolved_reloc_p = FALSE;
6604 if (r_type == R_ARM_THM_CALL)
6606 /* Check if a stub has to be inserted because the destination
6607 is too far. */
6608 bfd_vma from;
6609 bfd_signed_vma branch_offset;
6610 struct elf32_arm_stub_hash_entry *stub_entry = NULL;
6612 from = (input_section->output_section->vma
6613 + input_section->output_offset
6614 + rel->r_offset);
6615 branch_offset = (bfd_signed_vma)(value - from);
6617 if ((!thumb2
6618 && (branch_offset > THM_MAX_FWD_BRANCH_OFFSET
6619 || (branch_offset < THM_MAX_BWD_BRANCH_OFFSET)))
6621 (thumb2
6622 && (branch_offset > THM2_MAX_FWD_BRANCH_OFFSET
6623 || (branch_offset < THM2_MAX_BWD_BRANCH_OFFSET)))
6624 || ((sym_flags != STT_ARM_TFUNC) && !globals->use_blx))
6626 /* The target is out of reach or we are changing modes, so
6627 redirect the branch to the local stub for this
6628 function. */
6629 stub_entry = elf32_arm_get_stub_entry (input_section,
6630 sym_sec, h,
6631 rel, globals);
6632 if (stub_entry != NULL)
6633 value = (stub_entry->stub_offset
6634 + stub_entry->stub_sec->output_offset
6635 + stub_entry->stub_sec->output_section->vma);
6637 /* If this call becomes a call to Arm, force BLX. */
6638 if (globals->use_blx)
6640 if ((stub_entry
6641 && !arm_stub_is_thumb (stub_entry->stub_type))
6642 || (sym_flags != STT_ARM_TFUNC))
6643 lower_insn = (lower_insn & ~0x1000) | 0x0800;
6648 relocation = value + signed_addend;
6650 relocation -= (input_section->output_section->vma
6651 + input_section->output_offset
6652 + rel->r_offset);
6654 check = relocation >> howto->rightshift;
6656 /* If this is a signed value, the rightshift just dropped
6657 leading 1 bits (assuming twos complement). */
6658 if ((bfd_signed_vma) relocation >= 0)
6659 signed_check = check;
6660 else
6661 signed_check = check | ~((bfd_vma) -1 >> howto->rightshift);
6663 /* Calculate the permissable maximum and minimum values for
6664 this relocation according to whether we're relocating for
6665 Thumb-2 or not. */
6666 bitsize = howto->bitsize;
6667 if (!thumb2)
6668 bitsize -= 2;
6669 reloc_signed_max = ((1 << (bitsize - 1)) - 1) >> howto->rightshift;
6670 reloc_signed_min = ~reloc_signed_max;
6672 /* Assumes two's complement. */
6673 if (signed_check > reloc_signed_max || signed_check < reloc_signed_min)
6674 overflow = TRUE;
6676 if ((lower_insn & 0x5000) == 0x4000)
6677 /* For a BLX instruction, make sure that the relocation is rounded up
6678 to a word boundary. This follows the semantics of the instruction
6679 which specifies that bit 1 of the target address will come from bit
6680 1 of the base address. */
6681 relocation = (relocation + 2) & ~ 3;
6683 /* Put RELOCATION back into the insn. Assumes two's complement.
6684 We use the Thumb-2 encoding, which is safe even if dealing with
6685 a Thumb-1 instruction by virtue of our overflow check above. */
6686 reloc_sign = (signed_check < 0) ? 1 : 0;
6687 upper_insn = (upper_insn & ~(bfd_vma) 0x7ff)
6688 | ((relocation >> 12) & 0x3ff)
6689 | (reloc_sign << 10);
6690 lower_insn = (lower_insn & ~(bfd_vma) 0x2fff)
6691 | (((!((relocation >> 23) & 1)) ^ reloc_sign) << 13)
6692 | (((!((relocation >> 22) & 1)) ^ reloc_sign) << 11)
6693 | ((relocation >> 1) & 0x7ff);
6695 /* Put the relocated value back in the object file: */
6696 bfd_put_16 (input_bfd, upper_insn, hit_data);
6697 bfd_put_16 (input_bfd, lower_insn, hit_data + 2);
6699 return (overflow ? bfd_reloc_overflow : bfd_reloc_ok);
6701 break;
6703 case R_ARM_THM_JUMP19:
6704 /* Thumb32 conditional branch instruction. */
6706 bfd_vma relocation;
6707 bfd_boolean overflow = FALSE;
6708 bfd_vma upper_insn = bfd_get_16 (input_bfd, hit_data);
6709 bfd_vma lower_insn = bfd_get_16 (input_bfd, hit_data + 2);
6710 bfd_signed_vma reloc_signed_max = 0xffffe;
6711 bfd_signed_vma reloc_signed_min = -0x100000;
6712 bfd_signed_vma signed_check;
6714 /* Need to refetch the addend, reconstruct the top three bits,
6715 and squish the two 11 bit pieces together. */
6716 if (globals->use_rel)
6718 bfd_vma S = (upper_insn & 0x0400) >> 10;
6719 bfd_vma upper = (upper_insn & 0x003f);
6720 bfd_vma J1 = (lower_insn & 0x2000) >> 13;
6721 bfd_vma J2 = (lower_insn & 0x0800) >> 11;
6722 bfd_vma lower = (lower_insn & 0x07ff);
6724 upper |= J1 << 6;
6725 upper |= J2 << 7;
6726 upper |= (!S) << 8;
6727 upper -= 0x0100; /* Sign extend. */
6729 addend = (upper << 12) | (lower << 1);
6730 signed_addend = addend;
6733 /* Handle calls via the PLT. */
6734 if (h != NULL && splt != NULL && h->plt.offset != (bfd_vma) -1)
6736 value = (splt->output_section->vma
6737 + splt->output_offset
6738 + h->plt.offset);
6739 /* Target the Thumb stub before the ARM PLT entry. */
6740 value -= PLT_THUMB_STUB_SIZE;
6741 *unresolved_reloc_p = FALSE;
6744 /* ??? Should handle interworking? GCC might someday try to
6745 use this for tail calls. */
6747 relocation = value + signed_addend;
6748 relocation -= (input_section->output_section->vma
6749 + input_section->output_offset
6750 + rel->r_offset);
6751 signed_check = (bfd_signed_vma) relocation;
6753 if (signed_check > reloc_signed_max || signed_check < reloc_signed_min)
6754 overflow = TRUE;
6756 /* Put RELOCATION back into the insn. */
6758 bfd_vma S = (relocation & 0x00100000) >> 20;
6759 bfd_vma J2 = (relocation & 0x00080000) >> 19;
6760 bfd_vma J1 = (relocation & 0x00040000) >> 18;
6761 bfd_vma hi = (relocation & 0x0003f000) >> 12;
6762 bfd_vma lo = (relocation & 0x00000ffe) >> 1;
6764 upper_insn = (upper_insn & 0xfbc0) | (S << 10) | hi;
6765 lower_insn = (lower_insn & 0xd000) | (J1 << 13) | (J2 << 11) | lo;
6768 /* Put the relocated value back in the object file: */
6769 bfd_put_16 (input_bfd, upper_insn, hit_data);
6770 bfd_put_16 (input_bfd, lower_insn, hit_data + 2);
6772 return (overflow ? bfd_reloc_overflow : bfd_reloc_ok);
6775 case R_ARM_THM_JUMP11:
6776 case R_ARM_THM_JUMP8:
6777 case R_ARM_THM_JUMP6:
6778 /* Thumb B (branch) instruction). */
6780 bfd_signed_vma relocation;
6781 bfd_signed_vma reloc_signed_max = (1 << (howto->bitsize - 1)) - 1;
6782 bfd_signed_vma reloc_signed_min = ~ reloc_signed_max;
6783 bfd_signed_vma signed_check;
6785 /* CZB cannot jump backward. */
6786 if (r_type == R_ARM_THM_JUMP6)
6787 reloc_signed_min = 0;
6789 if (globals->use_rel)
6791 /* Need to refetch addend. */
6792 addend = bfd_get_16 (input_bfd, hit_data) & howto->src_mask;
6793 if (addend & ((howto->src_mask + 1) >> 1))
6795 signed_addend = -1;
6796 signed_addend &= ~ howto->src_mask;
6797 signed_addend |= addend;
6799 else
6800 signed_addend = addend;
6801 /* The value in the insn has been right shifted. We need to
6802 undo this, so that we can perform the address calculation
6803 in terms of bytes. */
6804 signed_addend <<= howto->rightshift;
6806 relocation = value + signed_addend;
6808 relocation -= (input_section->output_section->vma
6809 + input_section->output_offset
6810 + rel->r_offset);
6812 relocation >>= howto->rightshift;
6813 signed_check = relocation;
6815 if (r_type == R_ARM_THM_JUMP6)
6816 relocation = ((relocation & 0x0020) << 4) | ((relocation & 0x001f) << 3);
6817 else
6818 relocation &= howto->dst_mask;
6819 relocation |= (bfd_get_16 (input_bfd, hit_data) & (~ howto->dst_mask));
6821 bfd_put_16 (input_bfd, relocation, hit_data);
6823 /* Assumes two's complement. */
6824 if (signed_check > reloc_signed_max || signed_check < reloc_signed_min)
6825 return bfd_reloc_overflow;
6827 return bfd_reloc_ok;
6830 case R_ARM_ALU_PCREL7_0:
6831 case R_ARM_ALU_PCREL15_8:
6832 case R_ARM_ALU_PCREL23_15:
6834 bfd_vma insn;
6835 bfd_vma relocation;
6837 insn = bfd_get_32 (input_bfd, hit_data);
6838 if (globals->use_rel)
6840 /* Extract the addend. */
6841 addend = (insn & 0xff) << ((insn & 0xf00) >> 7);
6842 signed_addend = addend;
6844 relocation = value + signed_addend;
6846 relocation -= (input_section->output_section->vma
6847 + input_section->output_offset
6848 + rel->r_offset);
6849 insn = (insn & ~0xfff)
6850 | ((howto->bitpos << 7) & 0xf00)
6851 | ((relocation >> howto->bitpos) & 0xff);
6852 bfd_put_32 (input_bfd, value, hit_data);
6854 return bfd_reloc_ok;
6856 case R_ARM_GNU_VTINHERIT:
6857 case R_ARM_GNU_VTENTRY:
6858 return bfd_reloc_ok;
6860 case R_ARM_GOTOFF32:
6861 /* Relocation is relative to the start of the
6862 global offset table. */
6864 BFD_ASSERT (sgot != NULL);
6865 if (sgot == NULL)
6866 return bfd_reloc_notsupported;
6868 /* If we are addressing a Thumb function, we need to adjust the
6869 address by one, so that attempts to call the function pointer will
6870 correctly interpret it as Thumb code. */
6871 if (sym_flags == STT_ARM_TFUNC)
6872 value += 1;
6874 /* Note that sgot->output_offset is not involved in this
6875 calculation. We always want the start of .got. If we
6876 define _GLOBAL_OFFSET_TABLE in a different way, as is
6877 permitted by the ABI, we might have to change this
6878 calculation. */
6879 value -= sgot->output_section->vma;
6880 return _bfd_final_link_relocate (howto, input_bfd, input_section,
6881 contents, rel->r_offset, value,
6882 rel->r_addend);
6884 case R_ARM_GOTPC:
6885 /* Use global offset table as symbol value. */
6886 BFD_ASSERT (sgot != NULL);
6888 if (sgot == NULL)
6889 return bfd_reloc_notsupported;
6891 *unresolved_reloc_p = FALSE;
6892 value = sgot->output_section->vma;
6893 return _bfd_final_link_relocate (howto, input_bfd, input_section,
6894 contents, rel->r_offset, value,
6895 rel->r_addend);
6897 case R_ARM_GOT32:
6898 case R_ARM_GOT_PREL:
6899 /* Relocation is to the entry for this symbol in the
6900 global offset table. */
6901 if (sgot == NULL)
6902 return bfd_reloc_notsupported;
6904 if (h != NULL)
6906 bfd_vma off;
6907 bfd_boolean dyn;
6909 off = h->got.offset;
6910 BFD_ASSERT (off != (bfd_vma) -1);
6911 dyn = globals->root.dynamic_sections_created;
6913 if (! WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn, info->shared, h)
6914 || (info->shared
6915 && SYMBOL_REFERENCES_LOCAL (info, h))
6916 || (ELF_ST_VISIBILITY (h->other)
6917 && h->root.type == bfd_link_hash_undefweak))
6919 /* This is actually a static link, or it is a -Bsymbolic link
6920 and the symbol is defined locally. We must initialize this
6921 entry in the global offset table. Since the offset must
6922 always be a multiple of 4, we use the least significant bit
6923 to record whether we have initialized it already.
6925 When doing a dynamic link, we create a .rel(a).got relocation
6926 entry to initialize the value. This is done in the
6927 finish_dynamic_symbol routine. */
6928 if ((off & 1) != 0)
6929 off &= ~1;
6930 else
6932 /* If we are addressing a Thumb function, we need to
6933 adjust the address by one, so that attempts to
6934 call the function pointer will correctly
6935 interpret it as Thumb code. */
6936 if (sym_flags == STT_ARM_TFUNC)
6937 value |= 1;
6939 bfd_put_32 (output_bfd, value, sgot->contents + off);
6940 h->got.offset |= 1;
6943 else
6944 *unresolved_reloc_p = FALSE;
6946 value = sgot->output_offset + off;
6948 else
6950 bfd_vma off;
6952 BFD_ASSERT (local_got_offsets != NULL &&
6953 local_got_offsets[r_symndx] != (bfd_vma) -1);
6955 off = local_got_offsets[r_symndx];
6957 /* The offset must always be a multiple of 4. We use the
6958 least significant bit to record whether we have already
6959 generated the necessary reloc. */
6960 if ((off & 1) != 0)
6961 off &= ~1;
6962 else
6964 /* If we are addressing a Thumb function, we need to
6965 adjust the address by one, so that attempts to
6966 call the function pointer will correctly
6967 interpret it as Thumb code. */
6968 if (sym_flags == STT_ARM_TFUNC)
6969 value |= 1;
6971 if (globals->use_rel)
6972 bfd_put_32 (output_bfd, value, sgot->contents + off);
6974 if (info->shared)
6976 asection * srelgot;
6977 Elf_Internal_Rela outrel;
6978 bfd_byte *loc;
6980 srelgot = (bfd_get_section_by_name
6981 (dynobj, RELOC_SECTION (globals, ".got")));
6982 BFD_ASSERT (srelgot != NULL);
6984 outrel.r_addend = addend + value;
6985 outrel.r_offset = (sgot->output_section->vma
6986 + sgot->output_offset
6987 + off);
6988 outrel.r_info = ELF32_R_INFO (0, R_ARM_RELATIVE);
6989 loc = srelgot->contents;
6990 loc += srelgot->reloc_count++ * RELOC_SIZE (globals);
6991 SWAP_RELOC_OUT (globals) (output_bfd, &outrel, loc);
6994 local_got_offsets[r_symndx] |= 1;
6997 value = sgot->output_offset + off;
6999 if (r_type != R_ARM_GOT32)
7000 value += sgot->output_section->vma;
7002 return _bfd_final_link_relocate (howto, input_bfd, input_section,
7003 contents, rel->r_offset, value,
7004 rel->r_addend);
7006 case R_ARM_TLS_LDO32:
7007 value = value - dtpoff_base (info);
7009 return _bfd_final_link_relocate (howto, input_bfd, input_section,
7010 contents, rel->r_offset, value,
7011 rel->r_addend);
7013 case R_ARM_TLS_LDM32:
7015 bfd_vma off;
7017 if (globals->sgot == NULL)
7018 abort ();
7020 off = globals->tls_ldm_got.offset;
7022 if ((off & 1) != 0)
7023 off &= ~1;
7024 else
7026 /* If we don't know the module number, create a relocation
7027 for it. */
7028 if (info->shared)
7030 Elf_Internal_Rela outrel;
7031 bfd_byte *loc;
7033 if (globals->srelgot == NULL)
7034 abort ();
7036 outrel.r_addend = 0;
7037 outrel.r_offset = (globals->sgot->output_section->vma
7038 + globals->sgot->output_offset + off);
7039 outrel.r_info = ELF32_R_INFO (0, R_ARM_TLS_DTPMOD32);
7041 if (globals->use_rel)
7042 bfd_put_32 (output_bfd, outrel.r_addend,
7043 globals->sgot->contents + off);
7045 loc = globals->srelgot->contents;
7046 loc += globals->srelgot->reloc_count++ * RELOC_SIZE (globals);
7047 SWAP_RELOC_OUT (globals) (output_bfd, &outrel, loc);
7049 else
7050 bfd_put_32 (output_bfd, 1, globals->sgot->contents + off);
7052 globals->tls_ldm_got.offset |= 1;
7055 value = globals->sgot->output_section->vma + globals->sgot->output_offset + off
7056 - (input_section->output_section->vma + input_section->output_offset + rel->r_offset);
7058 return _bfd_final_link_relocate (howto, input_bfd, input_section,
7059 contents, rel->r_offset, value,
7060 rel->r_addend);
7063 case R_ARM_TLS_GD32:
7064 case R_ARM_TLS_IE32:
7066 bfd_vma off;
7067 int indx;
7068 char tls_type;
7070 if (globals->sgot == NULL)
7071 abort ();
7073 indx = 0;
7074 if (h != NULL)
7076 bfd_boolean dyn;
7077 dyn = globals->root.dynamic_sections_created;
7078 if (WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn, info->shared, h)
7079 && (!info->shared
7080 || !SYMBOL_REFERENCES_LOCAL (info, h)))
7082 *unresolved_reloc_p = FALSE;
7083 indx = h->dynindx;
7085 off = h->got.offset;
7086 tls_type = ((struct elf32_arm_link_hash_entry *) h)->tls_type;
7088 else
7090 if (local_got_offsets == NULL)
7091 abort ();
7092 off = local_got_offsets[r_symndx];
7093 tls_type = elf32_arm_local_got_tls_type (input_bfd)[r_symndx];
7096 if (tls_type == GOT_UNKNOWN)
7097 abort ();
7099 if ((off & 1) != 0)
7100 off &= ~1;
7101 else
7103 bfd_boolean need_relocs = FALSE;
7104 Elf_Internal_Rela outrel;
7105 bfd_byte *loc = NULL;
7106 int cur_off = off;
7108 /* The GOT entries have not been initialized yet. Do it
7109 now, and emit any relocations. If both an IE GOT and a
7110 GD GOT are necessary, we emit the GD first. */
7112 if ((info->shared || indx != 0)
7113 && (h == NULL
7114 || ELF_ST_VISIBILITY (h->other) == STV_DEFAULT
7115 || h->root.type != bfd_link_hash_undefweak))
7117 need_relocs = TRUE;
7118 if (globals->srelgot == NULL)
7119 abort ();
7120 loc = globals->srelgot->contents;
7121 loc += globals->srelgot->reloc_count * RELOC_SIZE (globals);
7124 if (tls_type & GOT_TLS_GD)
7126 if (need_relocs)
7128 outrel.r_addend = 0;
7129 outrel.r_offset = (globals->sgot->output_section->vma
7130 + globals->sgot->output_offset
7131 + cur_off);
7132 outrel.r_info = ELF32_R_INFO (indx, R_ARM_TLS_DTPMOD32);
7134 if (globals->use_rel)
7135 bfd_put_32 (output_bfd, outrel.r_addend,
7136 globals->sgot->contents + cur_off);
7138 SWAP_RELOC_OUT (globals) (output_bfd, &outrel, loc);
7139 globals->srelgot->reloc_count++;
7140 loc += RELOC_SIZE (globals);
7142 if (indx == 0)
7143 bfd_put_32 (output_bfd, value - dtpoff_base (info),
7144 globals->sgot->contents + cur_off + 4);
7145 else
7147 outrel.r_addend = 0;
7148 outrel.r_info = ELF32_R_INFO (indx,
7149 R_ARM_TLS_DTPOFF32);
7150 outrel.r_offset += 4;
7152 if (globals->use_rel)
7153 bfd_put_32 (output_bfd, outrel.r_addend,
7154 globals->sgot->contents + cur_off + 4);
7157 SWAP_RELOC_OUT (globals) (output_bfd, &outrel, loc);
7158 globals->srelgot->reloc_count++;
7159 loc += RELOC_SIZE (globals);
7162 else
7164 /* If we are not emitting relocations for a
7165 general dynamic reference, then we must be in a
7166 static link or an executable link with the
7167 symbol binding locally. Mark it as belonging
7168 to module 1, the executable. */
7169 bfd_put_32 (output_bfd, 1,
7170 globals->sgot->contents + cur_off);
7171 bfd_put_32 (output_bfd, value - dtpoff_base (info),
7172 globals->sgot->contents + cur_off + 4);
7175 cur_off += 8;
7178 if (tls_type & GOT_TLS_IE)
7180 if (need_relocs)
7182 if (indx == 0)
7183 outrel.r_addend = value - dtpoff_base (info);
7184 else
7185 outrel.r_addend = 0;
7186 outrel.r_offset = (globals->sgot->output_section->vma
7187 + globals->sgot->output_offset
7188 + cur_off);
7189 outrel.r_info = ELF32_R_INFO (indx, R_ARM_TLS_TPOFF32);
7191 if (globals->use_rel)
7192 bfd_put_32 (output_bfd, outrel.r_addend,
7193 globals->sgot->contents + cur_off);
7195 SWAP_RELOC_OUT (globals) (output_bfd, &outrel, loc);
7196 globals->srelgot->reloc_count++;
7197 loc += RELOC_SIZE (globals);
7199 else
7200 bfd_put_32 (output_bfd, tpoff (info, value),
7201 globals->sgot->contents + cur_off);
7202 cur_off += 4;
7205 if (h != NULL)
7206 h->got.offset |= 1;
7207 else
7208 local_got_offsets[r_symndx] |= 1;
7211 if ((tls_type & GOT_TLS_GD) && r_type != R_ARM_TLS_GD32)
7212 off += 8;
7213 value = globals->sgot->output_section->vma + globals->sgot->output_offset + off
7214 - (input_section->output_section->vma + input_section->output_offset + rel->r_offset);
7216 return _bfd_final_link_relocate (howto, input_bfd, input_section,
7217 contents, rel->r_offset, value,
7218 rel->r_addend);
7221 case R_ARM_TLS_LE32:
7222 if (info->shared)
7224 (*_bfd_error_handler)
7225 (_("%B(%A+0x%lx): R_ARM_TLS_LE32 relocation not permitted in shared object"),
7226 input_bfd, input_section,
7227 (long) rel->r_offset, howto->name);
7228 return FALSE;
7230 else
7231 value = tpoff (info, value);
7233 return _bfd_final_link_relocate (howto, input_bfd, input_section,
7234 contents, rel->r_offset, value,
7235 rel->r_addend);
7237 case R_ARM_V4BX:
7238 if (globals->fix_v4bx)
7240 bfd_vma insn = bfd_get_32 (input_bfd, hit_data);
7242 /* Ensure that we have a BX instruction. */
7243 BFD_ASSERT ((insn & 0x0ffffff0) == 0x012fff10);
7245 if (globals->fix_v4bx == 2 && (insn & 0xf) != 0xf)
7247 /* Branch to veneer. */
7248 bfd_vma glue_addr;
7249 glue_addr = elf32_arm_bx_glue (info, insn & 0xf);
7250 glue_addr -= input_section->output_section->vma
7251 + input_section->output_offset
7252 + rel->r_offset + 8;
7253 insn = (insn & 0xf0000000) | 0x0a000000
7254 | ((glue_addr >> 2) & 0x00ffffff);
7256 else
7258 /* Preserve Rm (lowest four bits) and the condition code
7259 (highest four bits). Other bits encode MOV PC,Rm. */
7260 insn = (insn & 0xf000000f) | 0x01a0f000;
7263 bfd_put_32 (input_bfd, insn, hit_data);
7265 return bfd_reloc_ok;
7267 case R_ARM_MOVW_ABS_NC:
7268 case R_ARM_MOVT_ABS:
7269 case R_ARM_MOVW_PREL_NC:
7270 case R_ARM_MOVT_PREL:
7271 /* Until we properly support segment-base-relative addressing then
7272 we assume the segment base to be zero, as for the group relocations.
7273 Thus R_ARM_MOVW_BREL_NC has the same semantics as R_ARM_MOVW_ABS_NC
7274 and R_ARM_MOVT_BREL has the same semantics as R_ARM_MOVT_ABS. */
7275 case R_ARM_MOVW_BREL_NC:
7276 case R_ARM_MOVW_BREL:
7277 case R_ARM_MOVT_BREL:
7279 bfd_vma insn = bfd_get_32 (input_bfd, hit_data);
7281 if (globals->use_rel)
7283 addend = ((insn >> 4) & 0xf000) | (insn & 0xfff);
7284 signed_addend = (addend ^ 0x8000) - 0x8000;
7287 value += signed_addend;
7289 if (r_type == R_ARM_MOVW_PREL_NC || r_type == R_ARM_MOVT_PREL)
7290 value -= (input_section->output_section->vma
7291 + input_section->output_offset + rel->r_offset);
7293 if (r_type == R_ARM_MOVW_BREL && value >= 0x10000)
7294 return bfd_reloc_overflow;
7296 if (sym_flags == STT_ARM_TFUNC)
7297 value |= 1;
7299 if (r_type == R_ARM_MOVT_ABS || r_type == R_ARM_MOVT_PREL
7300 || r_type == R_ARM_MOVT_BREL)
7301 value >>= 16;
7303 insn &= 0xfff0f000;
7304 insn |= value & 0xfff;
7305 insn |= (value & 0xf000) << 4;
7306 bfd_put_32 (input_bfd, insn, hit_data);
7308 return bfd_reloc_ok;
7310 case R_ARM_THM_MOVW_ABS_NC:
7311 case R_ARM_THM_MOVT_ABS:
7312 case R_ARM_THM_MOVW_PREL_NC:
7313 case R_ARM_THM_MOVT_PREL:
7314 /* Until we properly support segment-base-relative addressing then
7315 we assume the segment base to be zero, as for the above relocations.
7316 Thus R_ARM_THM_MOVW_BREL_NC has the same semantics as
7317 R_ARM_THM_MOVW_ABS_NC and R_ARM_THM_MOVT_BREL has the same semantics
7318 as R_ARM_THM_MOVT_ABS. */
7319 case R_ARM_THM_MOVW_BREL_NC:
7320 case R_ARM_THM_MOVW_BREL:
7321 case R_ARM_THM_MOVT_BREL:
7323 bfd_vma insn;
7325 insn = bfd_get_16 (input_bfd, hit_data) << 16;
7326 insn |= bfd_get_16 (input_bfd, hit_data + 2);
7328 if (globals->use_rel)
7330 addend = ((insn >> 4) & 0xf000)
7331 | ((insn >> 15) & 0x0800)
7332 | ((insn >> 4) & 0x0700)
7333 | (insn & 0x00ff);
7334 signed_addend = (addend ^ 0x8000) - 0x8000;
7337 value += signed_addend;
7339 if (r_type == R_ARM_THM_MOVW_PREL_NC || r_type == R_ARM_THM_MOVT_PREL)
7340 value -= (input_section->output_section->vma
7341 + input_section->output_offset + rel->r_offset);
7343 if (r_type == R_ARM_THM_MOVW_BREL && value >= 0x10000)
7344 return bfd_reloc_overflow;
7346 if (sym_flags == STT_ARM_TFUNC)
7347 value |= 1;
7349 if (r_type == R_ARM_THM_MOVT_ABS || r_type == R_ARM_THM_MOVT_PREL
7350 || r_type == R_ARM_THM_MOVT_BREL)
7351 value >>= 16;
7353 insn &= 0xfbf08f00;
7354 insn |= (value & 0xf000) << 4;
7355 insn |= (value & 0x0800) << 15;
7356 insn |= (value & 0x0700) << 4;
7357 insn |= (value & 0x00ff);
7359 bfd_put_16 (input_bfd, insn >> 16, hit_data);
7360 bfd_put_16 (input_bfd, insn & 0xffff, hit_data + 2);
7362 return bfd_reloc_ok;
7364 case R_ARM_ALU_PC_G0_NC:
7365 case R_ARM_ALU_PC_G1_NC:
7366 case R_ARM_ALU_PC_G0:
7367 case R_ARM_ALU_PC_G1:
7368 case R_ARM_ALU_PC_G2:
7369 case R_ARM_ALU_SB_G0_NC:
7370 case R_ARM_ALU_SB_G1_NC:
7371 case R_ARM_ALU_SB_G0:
7372 case R_ARM_ALU_SB_G1:
7373 case R_ARM_ALU_SB_G2:
7375 bfd_vma insn = bfd_get_32 (input_bfd, hit_data);
7376 bfd_vma pc = input_section->output_section->vma
7377 + input_section->output_offset + rel->r_offset;
7378 /* sb should be the origin of the *segment* containing the symbol.
7379 It is not clear how to obtain this OS-dependent value, so we
7380 make an arbitrary choice of zero. */
7381 bfd_vma sb = 0;
7382 bfd_vma residual;
7383 bfd_vma g_n;
7384 bfd_signed_vma signed_value;
7385 int group = 0;
7387 /* Determine which group of bits to select. */
7388 switch (r_type)
7390 case R_ARM_ALU_PC_G0_NC:
7391 case R_ARM_ALU_PC_G0:
7392 case R_ARM_ALU_SB_G0_NC:
7393 case R_ARM_ALU_SB_G0:
7394 group = 0;
7395 break;
7397 case R_ARM_ALU_PC_G1_NC:
7398 case R_ARM_ALU_PC_G1:
7399 case R_ARM_ALU_SB_G1_NC:
7400 case R_ARM_ALU_SB_G1:
7401 group = 1;
7402 break;
7404 case R_ARM_ALU_PC_G2:
7405 case R_ARM_ALU_SB_G2:
7406 group = 2;
7407 break;
7409 default:
7410 abort ();
7413 /* If REL, extract the addend from the insn. If RELA, it will
7414 have already been fetched for us. */
7415 if (globals->use_rel)
7417 int negative;
7418 bfd_vma constant = insn & 0xff;
7419 bfd_vma rotation = (insn & 0xf00) >> 8;
7421 if (rotation == 0)
7422 signed_addend = constant;
7423 else
7425 /* Compensate for the fact that in the instruction, the
7426 rotation is stored in multiples of 2 bits. */
7427 rotation *= 2;
7429 /* Rotate "constant" right by "rotation" bits. */
7430 signed_addend = (constant >> rotation) |
7431 (constant << (8 * sizeof (bfd_vma) - rotation));
7434 /* Determine if the instruction is an ADD or a SUB.
7435 (For REL, this determines the sign of the addend.) */
7436 negative = identify_add_or_sub (insn);
7437 if (negative == 0)
7439 (*_bfd_error_handler)
7440 (_("%B(%A+0x%lx): Only ADD or SUB instructions are allowed for ALU group relocations"),
7441 input_bfd, input_section,
7442 (long) rel->r_offset, howto->name);
7443 return bfd_reloc_overflow;
7446 signed_addend *= negative;
7449 /* Compute the value (X) to go in the place. */
7450 if (r_type == R_ARM_ALU_PC_G0_NC
7451 || r_type == R_ARM_ALU_PC_G1_NC
7452 || r_type == R_ARM_ALU_PC_G0
7453 || r_type == R_ARM_ALU_PC_G1
7454 || r_type == R_ARM_ALU_PC_G2)
7455 /* PC relative. */
7456 signed_value = value - pc + signed_addend;
7457 else
7458 /* Section base relative. */
7459 signed_value = value - sb + signed_addend;
7461 /* If the target symbol is a Thumb function, then set the
7462 Thumb bit in the address. */
7463 if (sym_flags == STT_ARM_TFUNC)
7464 signed_value |= 1;
7466 /* Calculate the value of the relevant G_n, in encoded
7467 constant-with-rotation format. */
7468 g_n = calculate_group_reloc_mask (abs (signed_value), group,
7469 &residual);
7471 /* Check for overflow if required. */
7472 if ((r_type == R_ARM_ALU_PC_G0
7473 || r_type == R_ARM_ALU_PC_G1
7474 || r_type == R_ARM_ALU_PC_G2
7475 || r_type == R_ARM_ALU_SB_G0
7476 || r_type == R_ARM_ALU_SB_G1
7477 || r_type == R_ARM_ALU_SB_G2) && residual != 0)
7479 (*_bfd_error_handler)
7480 (_("%B(%A+0x%lx): Overflow whilst splitting 0x%lx for group relocation %s"),
7481 input_bfd, input_section,
7482 (long) rel->r_offset, abs (signed_value), howto->name);
7483 return bfd_reloc_overflow;
7486 /* Mask out the value and the ADD/SUB part of the opcode; take care
7487 not to destroy the S bit. */
7488 insn &= 0xff1ff000;
7490 /* Set the opcode according to whether the value to go in the
7491 place is negative. */
7492 if (signed_value < 0)
7493 insn |= 1 << 22;
7494 else
7495 insn |= 1 << 23;
7497 /* Encode the offset. */
7498 insn |= g_n;
7500 bfd_put_32 (input_bfd, insn, hit_data);
7502 return bfd_reloc_ok;
7504 case R_ARM_LDR_PC_G0:
7505 case R_ARM_LDR_PC_G1:
7506 case R_ARM_LDR_PC_G2:
7507 case R_ARM_LDR_SB_G0:
7508 case R_ARM_LDR_SB_G1:
7509 case R_ARM_LDR_SB_G2:
7511 bfd_vma insn = bfd_get_32 (input_bfd, hit_data);
7512 bfd_vma pc = input_section->output_section->vma
7513 + input_section->output_offset + rel->r_offset;
7514 bfd_vma sb = 0; /* See note above. */
7515 bfd_vma residual;
7516 bfd_signed_vma signed_value;
7517 int group = 0;
7519 /* Determine which groups of bits to calculate. */
7520 switch (r_type)
7522 case R_ARM_LDR_PC_G0:
7523 case R_ARM_LDR_SB_G0:
7524 group = 0;
7525 break;
7527 case R_ARM_LDR_PC_G1:
7528 case R_ARM_LDR_SB_G1:
7529 group = 1;
7530 break;
7532 case R_ARM_LDR_PC_G2:
7533 case R_ARM_LDR_SB_G2:
7534 group = 2;
7535 break;
7537 default:
7538 abort ();
7541 /* If REL, extract the addend from the insn. If RELA, it will
7542 have already been fetched for us. */
7543 if (globals->use_rel)
7545 int negative = (insn & (1 << 23)) ? 1 : -1;
7546 signed_addend = negative * (insn & 0xfff);
7549 /* Compute the value (X) to go in the place. */
7550 if (r_type == R_ARM_LDR_PC_G0
7551 || r_type == R_ARM_LDR_PC_G1
7552 || r_type == R_ARM_LDR_PC_G2)
7553 /* PC relative. */
7554 signed_value = value - pc + signed_addend;
7555 else
7556 /* Section base relative. */
7557 signed_value = value - sb + signed_addend;
7559 /* Calculate the value of the relevant G_{n-1} to obtain
7560 the residual at that stage. */
7561 calculate_group_reloc_mask (abs (signed_value), group - 1, &residual);
7563 /* Check for overflow. */
7564 if (residual >= 0x1000)
7566 (*_bfd_error_handler)
7567 (_("%B(%A+0x%lx): Overflow whilst splitting 0x%lx for group relocation %s"),
7568 input_bfd, input_section,
7569 (long) rel->r_offset, abs (signed_value), howto->name);
7570 return bfd_reloc_overflow;
7573 /* Mask out the value and U bit. */
7574 insn &= 0xff7ff000;
7576 /* Set the U bit if the value to go in the place is non-negative. */
7577 if (signed_value >= 0)
7578 insn |= 1 << 23;
7580 /* Encode the offset. */
7581 insn |= residual;
7583 bfd_put_32 (input_bfd, insn, hit_data);
7585 return bfd_reloc_ok;
7587 case R_ARM_LDRS_PC_G0:
7588 case R_ARM_LDRS_PC_G1:
7589 case R_ARM_LDRS_PC_G2:
7590 case R_ARM_LDRS_SB_G0:
7591 case R_ARM_LDRS_SB_G1:
7592 case R_ARM_LDRS_SB_G2:
7594 bfd_vma insn = bfd_get_32 (input_bfd, hit_data);
7595 bfd_vma pc = input_section->output_section->vma
7596 + input_section->output_offset + rel->r_offset;
7597 bfd_vma sb = 0; /* See note above. */
7598 bfd_vma residual;
7599 bfd_signed_vma signed_value;
7600 int group = 0;
7602 /* Determine which groups of bits to calculate. */
7603 switch (r_type)
7605 case R_ARM_LDRS_PC_G0:
7606 case R_ARM_LDRS_SB_G0:
7607 group = 0;
7608 break;
7610 case R_ARM_LDRS_PC_G1:
7611 case R_ARM_LDRS_SB_G1:
7612 group = 1;
7613 break;
7615 case R_ARM_LDRS_PC_G2:
7616 case R_ARM_LDRS_SB_G2:
7617 group = 2;
7618 break;
7620 default:
7621 abort ();
7624 /* If REL, extract the addend from the insn. If RELA, it will
7625 have already been fetched for us. */
7626 if (globals->use_rel)
7628 int negative = (insn & (1 << 23)) ? 1 : -1;
7629 signed_addend = negative * (((insn & 0xf00) >> 4) + (insn & 0xf));
7632 /* Compute the value (X) to go in the place. */
7633 if (r_type == R_ARM_LDRS_PC_G0
7634 || r_type == R_ARM_LDRS_PC_G1
7635 || r_type == R_ARM_LDRS_PC_G2)
7636 /* PC relative. */
7637 signed_value = value - pc + signed_addend;
7638 else
7639 /* Section base relative. */
7640 signed_value = value - sb + signed_addend;
7642 /* Calculate the value of the relevant G_{n-1} to obtain
7643 the residual at that stage. */
7644 calculate_group_reloc_mask (abs (signed_value), group - 1, &residual);
7646 /* Check for overflow. */
7647 if (residual >= 0x100)
7649 (*_bfd_error_handler)
7650 (_("%B(%A+0x%lx): Overflow whilst splitting 0x%lx for group relocation %s"),
7651 input_bfd, input_section,
7652 (long) rel->r_offset, abs (signed_value), howto->name);
7653 return bfd_reloc_overflow;
7656 /* Mask out the value and U bit. */
7657 insn &= 0xff7ff0f0;
7659 /* Set the U bit if the value to go in the place is non-negative. */
7660 if (signed_value >= 0)
7661 insn |= 1 << 23;
7663 /* Encode the offset. */
7664 insn |= ((residual & 0xf0) << 4) | (residual & 0xf);
7666 bfd_put_32 (input_bfd, insn, hit_data);
7668 return bfd_reloc_ok;
7670 case R_ARM_LDC_PC_G0:
7671 case R_ARM_LDC_PC_G1:
7672 case R_ARM_LDC_PC_G2:
7673 case R_ARM_LDC_SB_G0:
7674 case R_ARM_LDC_SB_G1:
7675 case R_ARM_LDC_SB_G2:
7677 bfd_vma insn = bfd_get_32 (input_bfd, hit_data);
7678 bfd_vma pc = input_section->output_section->vma
7679 + input_section->output_offset + rel->r_offset;
7680 bfd_vma sb = 0; /* See note above. */
7681 bfd_vma residual;
7682 bfd_signed_vma signed_value;
7683 int group = 0;
7685 /* Determine which groups of bits to calculate. */
7686 switch (r_type)
7688 case R_ARM_LDC_PC_G0:
7689 case R_ARM_LDC_SB_G0:
7690 group = 0;
7691 break;
7693 case R_ARM_LDC_PC_G1:
7694 case R_ARM_LDC_SB_G1:
7695 group = 1;
7696 break;
7698 case R_ARM_LDC_PC_G2:
7699 case R_ARM_LDC_SB_G2:
7700 group = 2;
7701 break;
7703 default:
7704 abort ();
7707 /* If REL, extract the addend from the insn. If RELA, it will
7708 have already been fetched for us. */
7709 if (globals->use_rel)
7711 int negative = (insn & (1 << 23)) ? 1 : -1;
7712 signed_addend = negative * ((insn & 0xff) << 2);
7715 /* Compute the value (X) to go in the place. */
7716 if (r_type == R_ARM_LDC_PC_G0
7717 || r_type == R_ARM_LDC_PC_G1
7718 || r_type == R_ARM_LDC_PC_G2)
7719 /* PC relative. */
7720 signed_value = value - pc + signed_addend;
7721 else
7722 /* Section base relative. */
7723 signed_value = value - sb + signed_addend;
7725 /* Calculate the value of the relevant G_{n-1} to obtain
7726 the residual at that stage. */
7727 calculate_group_reloc_mask (abs (signed_value), group - 1, &residual);
7729 /* Check for overflow. (The absolute value to go in the place must be
7730 divisible by four and, after having been divided by four, must
7731 fit in eight bits.) */
7732 if ((residual & 0x3) != 0 || residual >= 0x400)
7734 (*_bfd_error_handler)
7735 (_("%B(%A+0x%lx): Overflow whilst splitting 0x%lx for group relocation %s"),
7736 input_bfd, input_section,
7737 (long) rel->r_offset, abs (signed_value), howto->name);
7738 return bfd_reloc_overflow;
7741 /* Mask out the value and U bit. */
7742 insn &= 0xff7fff00;
7744 /* Set the U bit if the value to go in the place is non-negative. */
7745 if (signed_value >= 0)
7746 insn |= 1 << 23;
7748 /* Encode the offset. */
7749 insn |= residual >> 2;
7751 bfd_put_32 (input_bfd, insn, hit_data);
7753 return bfd_reloc_ok;
7755 default:
7756 return bfd_reloc_notsupported;
7760 /* Add INCREMENT to the reloc (of type HOWTO) at ADDRESS. */
7761 static void
7762 arm_add_to_rel (bfd * abfd,
7763 bfd_byte * address,
7764 reloc_howto_type * howto,
7765 bfd_signed_vma increment)
7767 bfd_signed_vma addend;
7769 if (howto->type == R_ARM_THM_CALL
7770 || howto->type == R_ARM_THM_JUMP24)
7772 int upper_insn, lower_insn;
7773 int upper, lower;
7775 upper_insn = bfd_get_16 (abfd, address);
7776 lower_insn = bfd_get_16 (abfd, address + 2);
7777 upper = upper_insn & 0x7ff;
7778 lower = lower_insn & 0x7ff;
7780 addend = (upper << 12) | (lower << 1);
7781 addend += increment;
7782 addend >>= 1;
7784 upper_insn = (upper_insn & 0xf800) | ((addend >> 11) & 0x7ff);
7785 lower_insn = (lower_insn & 0xf800) | (addend & 0x7ff);
7787 bfd_put_16 (abfd, (bfd_vma) upper_insn, address);
7788 bfd_put_16 (abfd, (bfd_vma) lower_insn, address + 2);
7790 else
7792 bfd_vma contents;
7794 contents = bfd_get_32 (abfd, address);
7796 /* Get the (signed) value from the instruction. */
7797 addend = contents & howto->src_mask;
7798 if (addend & ((howto->src_mask + 1) >> 1))
7800 bfd_signed_vma mask;
7802 mask = -1;
7803 mask &= ~ howto->src_mask;
7804 addend |= mask;
7807 /* Add in the increment, (which is a byte value). */
7808 switch (howto->type)
7810 default:
7811 addend += increment;
7812 break;
7814 case R_ARM_PC24:
7815 case R_ARM_PLT32:
7816 case R_ARM_CALL:
7817 case R_ARM_JUMP24:
7818 addend <<= howto->size;
7819 addend += increment;
7821 /* Should we check for overflow here ? */
7823 /* Drop any undesired bits. */
7824 addend >>= howto->rightshift;
7825 break;
7828 contents = (contents & ~ howto->dst_mask) | (addend & howto->dst_mask);
7830 bfd_put_32 (abfd, contents, address);
7834 #define IS_ARM_TLS_RELOC(R_TYPE) \
7835 ((R_TYPE) == R_ARM_TLS_GD32 \
7836 || (R_TYPE) == R_ARM_TLS_LDO32 \
7837 || (R_TYPE) == R_ARM_TLS_LDM32 \
7838 || (R_TYPE) == R_ARM_TLS_DTPOFF32 \
7839 || (R_TYPE) == R_ARM_TLS_DTPMOD32 \
7840 || (R_TYPE) == R_ARM_TLS_TPOFF32 \
7841 || (R_TYPE) == R_ARM_TLS_LE32 \
7842 || (R_TYPE) == R_ARM_TLS_IE32)
7844 /* Relocate an ARM ELF section. */
7846 static bfd_boolean
7847 elf32_arm_relocate_section (bfd * output_bfd,
7848 struct bfd_link_info * info,
7849 bfd * input_bfd,
7850 asection * input_section,
7851 bfd_byte * contents,
7852 Elf_Internal_Rela * relocs,
7853 Elf_Internal_Sym * local_syms,
7854 asection ** local_sections)
7856 Elf_Internal_Shdr *symtab_hdr;
7857 struct elf_link_hash_entry **sym_hashes;
7858 Elf_Internal_Rela *rel;
7859 Elf_Internal_Rela *relend;
7860 const char *name;
7861 struct elf32_arm_link_hash_table * globals;
7863 globals = elf32_arm_hash_table (info);
7865 symtab_hdr = & elf_symtab_hdr (input_bfd);
7866 sym_hashes = elf_sym_hashes (input_bfd);
7868 rel = relocs;
7869 relend = relocs + input_section->reloc_count;
7870 for (; rel < relend; rel++)
7872 int r_type;
7873 reloc_howto_type * howto;
7874 unsigned long r_symndx;
7875 Elf_Internal_Sym * sym;
7876 asection * sec;
7877 struct elf_link_hash_entry * h;
7878 bfd_vma relocation;
7879 bfd_reloc_status_type r;
7880 arelent bfd_reloc;
7881 char sym_type;
7882 bfd_boolean unresolved_reloc = FALSE;
7883 char *error_message = NULL;
7885 r_symndx = ELF32_R_SYM (rel->r_info);
7886 r_type = ELF32_R_TYPE (rel->r_info);
7887 r_type = arm_real_reloc_type (globals, r_type);
7889 if ( r_type == R_ARM_GNU_VTENTRY
7890 || r_type == R_ARM_GNU_VTINHERIT)
7891 continue;
7893 bfd_reloc.howto = elf32_arm_howto_from_type (r_type);
7894 howto = bfd_reloc.howto;
7896 h = NULL;
7897 sym = NULL;
7898 sec = NULL;
7900 if (r_symndx < symtab_hdr->sh_info)
7902 sym = local_syms + r_symndx;
7903 sym_type = ELF32_ST_TYPE (sym->st_info);
7904 sec = local_sections[r_symndx];
7905 if (globals->use_rel)
7907 relocation = (sec->output_section->vma
7908 + sec->output_offset
7909 + sym->st_value);
7910 if (!info->relocatable
7911 && (sec->flags & SEC_MERGE)
7912 && ELF_ST_TYPE (sym->st_info) == STT_SECTION)
7914 asection *msec;
7915 bfd_vma addend, value;
7917 switch (r_type)
7919 case R_ARM_MOVW_ABS_NC:
7920 case R_ARM_MOVT_ABS:
7921 value = bfd_get_32 (input_bfd, contents + rel->r_offset);
7922 addend = ((value & 0xf0000) >> 4) | (value & 0xfff);
7923 addend = (addend ^ 0x8000) - 0x8000;
7924 break;
7926 case R_ARM_THM_MOVW_ABS_NC:
7927 case R_ARM_THM_MOVT_ABS:
7928 value = bfd_get_16 (input_bfd, contents + rel->r_offset)
7929 << 16;
7930 value |= bfd_get_16 (input_bfd,
7931 contents + rel->r_offset + 2);
7932 addend = ((value & 0xf7000) >> 4) | (value & 0xff)
7933 | ((value & 0x04000000) >> 15);
7934 addend = (addend ^ 0x8000) - 0x8000;
7935 break;
7937 default:
7938 if (howto->rightshift
7939 || (howto->src_mask & (howto->src_mask + 1)))
7941 (*_bfd_error_handler)
7942 (_("%B(%A+0x%lx): %s relocation against SEC_MERGE section"),
7943 input_bfd, input_section,
7944 (long) rel->r_offset, howto->name);
7945 return FALSE;
7948 value = bfd_get_32 (input_bfd, contents + rel->r_offset);
7950 /* Get the (signed) value from the instruction. */
7951 addend = value & howto->src_mask;
7952 if (addend & ((howto->src_mask + 1) >> 1))
7954 bfd_signed_vma mask;
7956 mask = -1;
7957 mask &= ~ howto->src_mask;
7958 addend |= mask;
7960 break;
7963 msec = sec;
7964 addend =
7965 _bfd_elf_rel_local_sym (output_bfd, sym, &msec, addend)
7966 - relocation;
7967 addend += msec->output_section->vma + msec->output_offset;
7969 /* Cases here must match those in the preceeding
7970 switch statement. */
7971 switch (r_type)
7973 case R_ARM_MOVW_ABS_NC:
7974 case R_ARM_MOVT_ABS:
7975 value = (value & 0xfff0f000) | ((addend & 0xf000) << 4)
7976 | (addend & 0xfff);
7977 bfd_put_32 (input_bfd, value, contents + rel->r_offset);
7978 break;
7980 case R_ARM_THM_MOVW_ABS_NC:
7981 case R_ARM_THM_MOVT_ABS:
7982 value = (value & 0xfbf08f00) | ((addend & 0xf700) << 4)
7983 | (addend & 0xff) | ((addend & 0x0800) << 15);
7984 bfd_put_16 (input_bfd, value >> 16,
7985 contents + rel->r_offset);
7986 bfd_put_16 (input_bfd, value,
7987 contents + rel->r_offset + 2);
7988 break;
7990 default:
7991 value = (value & ~ howto->dst_mask)
7992 | (addend & howto->dst_mask);
7993 bfd_put_32 (input_bfd, value, contents + rel->r_offset);
7994 break;
7998 else
7999 relocation = _bfd_elf_rela_local_sym (output_bfd, sym, &sec, rel);
8001 else
8003 bfd_boolean warned;
8005 RELOC_FOR_GLOBAL_SYMBOL (info, input_bfd, input_section, rel,
8006 r_symndx, symtab_hdr, sym_hashes,
8007 h, sec, relocation,
8008 unresolved_reloc, warned);
8010 sym_type = h->type;
8013 if (sec != NULL && elf_discarded_section (sec))
8015 /* For relocs against symbols from removed linkonce sections,
8016 or sections discarded by a linker script, we just want the
8017 section contents zeroed. Avoid any special processing. */
8018 _bfd_clear_contents (howto, input_bfd, contents + rel->r_offset);
8019 rel->r_info = 0;
8020 rel->r_addend = 0;
8021 continue;
8024 if (info->relocatable)
8026 /* This is a relocatable link. We don't have to change
8027 anything, unless the reloc is against a section symbol,
8028 in which case we have to adjust according to where the
8029 section symbol winds up in the output section. */
8030 if (sym != NULL && ELF_ST_TYPE (sym->st_info) == STT_SECTION)
8032 if (globals->use_rel)
8033 arm_add_to_rel (input_bfd, contents + rel->r_offset,
8034 howto, (bfd_signed_vma) sec->output_offset);
8035 else
8036 rel->r_addend += sec->output_offset;
8038 continue;
8041 if (h != NULL)
8042 name = h->root.root.string;
8043 else
8045 name = (bfd_elf_string_from_elf_section
8046 (input_bfd, symtab_hdr->sh_link, sym->st_name));
8047 if (name == NULL || *name == '\0')
8048 name = bfd_section_name (input_bfd, sec);
8051 if (r_symndx != 0
8052 && r_type != R_ARM_NONE
8053 && (h == NULL
8054 || h->root.type == bfd_link_hash_defined
8055 || h->root.type == bfd_link_hash_defweak)
8056 && IS_ARM_TLS_RELOC (r_type) != (sym_type == STT_TLS))
8058 (*_bfd_error_handler)
8059 ((sym_type == STT_TLS
8060 ? _("%B(%A+0x%lx): %s used with TLS symbol %s")
8061 : _("%B(%A+0x%lx): %s used with non-TLS symbol %s")),
8062 input_bfd,
8063 input_section,
8064 (long) rel->r_offset,
8065 howto->name,
8066 name);
8069 r = elf32_arm_final_link_relocate (howto, input_bfd, output_bfd,
8070 input_section, contents, rel,
8071 relocation, info, sec, name,
8072 (h ? ELF_ST_TYPE (h->type) :
8073 ELF_ST_TYPE (sym->st_info)), h,
8074 &unresolved_reloc, &error_message);
8076 /* Dynamic relocs are not propagated for SEC_DEBUGGING sections
8077 because such sections are not SEC_ALLOC and thus ld.so will
8078 not process them. */
8079 if (unresolved_reloc
8080 && !((input_section->flags & SEC_DEBUGGING) != 0
8081 && h->def_dynamic))
8083 (*_bfd_error_handler)
8084 (_("%B(%A+0x%lx): unresolvable %s relocation against symbol `%s'"),
8085 input_bfd,
8086 input_section,
8087 (long) rel->r_offset,
8088 howto->name,
8089 h->root.root.string);
8090 return FALSE;
8093 if (r != bfd_reloc_ok)
8095 switch (r)
8097 case bfd_reloc_overflow:
8098 /* If the overflowing reloc was to an undefined symbol,
8099 we have already printed one error message and there
8100 is no point complaining again. */
8101 if ((! h ||
8102 h->root.type != bfd_link_hash_undefined)
8103 && (!((*info->callbacks->reloc_overflow)
8104 (info, (h ? &h->root : NULL), name, howto->name,
8105 (bfd_vma) 0, input_bfd, input_section,
8106 rel->r_offset))))
8107 return FALSE;
8108 break;
8110 case bfd_reloc_undefined:
8111 if (!((*info->callbacks->undefined_symbol)
8112 (info, name, input_bfd, input_section,
8113 rel->r_offset, TRUE)))
8114 return FALSE;
8115 break;
8117 case bfd_reloc_outofrange:
8118 error_message = _("out of range");
8119 goto common_error;
8121 case bfd_reloc_notsupported:
8122 error_message = _("unsupported relocation");
8123 goto common_error;
8125 case bfd_reloc_dangerous:
8126 /* error_message should already be set. */
8127 goto common_error;
8129 default:
8130 error_message = _("unknown error");
8131 /* Fall through. */
8133 common_error:
8134 BFD_ASSERT (error_message != NULL);
8135 if (!((*info->callbacks->reloc_dangerous)
8136 (info, error_message, input_bfd, input_section,
8137 rel->r_offset)))
8138 return FALSE;
8139 break;
8144 return TRUE;
8147 /* Set the right machine number. */
8149 static bfd_boolean
8150 elf32_arm_object_p (bfd *abfd)
8152 unsigned int mach;
8154 mach = bfd_arm_get_mach_from_notes (abfd, ARM_NOTE_SECTION);
8156 if (mach != bfd_mach_arm_unknown)
8157 bfd_default_set_arch_mach (abfd, bfd_arch_arm, mach);
8159 else if (elf_elfheader (abfd)->e_flags & EF_ARM_MAVERICK_FLOAT)
8160 bfd_default_set_arch_mach (abfd, bfd_arch_arm, bfd_mach_arm_ep9312);
8162 else
8163 bfd_default_set_arch_mach (abfd, bfd_arch_arm, mach);
8165 return TRUE;
8168 /* Function to keep ARM specific flags in the ELF header. */
8170 static bfd_boolean
8171 elf32_arm_set_private_flags (bfd *abfd, flagword flags)
8173 if (elf_flags_init (abfd)
8174 && elf_elfheader (abfd)->e_flags != flags)
8176 if (EF_ARM_EABI_VERSION (flags) == EF_ARM_EABI_UNKNOWN)
8178 if (flags & EF_ARM_INTERWORK)
8179 (*_bfd_error_handler)
8180 (_("Warning: Not setting interworking flag of %B since it has already been specified as non-interworking"),
8181 abfd);
8182 else
8183 _bfd_error_handler
8184 (_("Warning: Clearing the interworking flag of %B due to outside request"),
8185 abfd);
8188 else
8190 elf_elfheader (abfd)->e_flags = flags;
8191 elf_flags_init (abfd) = TRUE;
8194 return TRUE;
8197 /* Copy backend specific data from one object module to another. */
8199 static bfd_boolean
8200 elf32_arm_copy_private_bfd_data (bfd *ibfd, bfd *obfd)
8202 flagword in_flags;
8203 flagword out_flags;
8205 if (! is_arm_elf (ibfd) || ! is_arm_elf (obfd))
8206 return TRUE;
8208 in_flags = elf_elfheader (ibfd)->e_flags;
8209 out_flags = elf_elfheader (obfd)->e_flags;
8211 if (elf_flags_init (obfd)
8212 && EF_ARM_EABI_VERSION (out_flags) == EF_ARM_EABI_UNKNOWN
8213 && in_flags != out_flags)
8215 /* Cannot mix APCS26 and APCS32 code. */
8216 if ((in_flags & EF_ARM_APCS_26) != (out_flags & EF_ARM_APCS_26))
8217 return FALSE;
8219 /* Cannot mix float APCS and non-float APCS code. */
8220 if ((in_flags & EF_ARM_APCS_FLOAT) != (out_flags & EF_ARM_APCS_FLOAT))
8221 return FALSE;
8223 /* If the src and dest have different interworking flags
8224 then turn off the interworking bit. */
8225 if ((in_flags & EF_ARM_INTERWORK) != (out_flags & EF_ARM_INTERWORK))
8227 if (out_flags & EF_ARM_INTERWORK)
8228 _bfd_error_handler
8229 (_("Warning: Clearing the interworking flag of %B because non-interworking code in %B has been linked with it"),
8230 obfd, ibfd);
8232 in_flags &= ~EF_ARM_INTERWORK;
8235 /* Likewise for PIC, though don't warn for this case. */
8236 if ((in_flags & EF_ARM_PIC) != (out_flags & EF_ARM_PIC))
8237 in_flags &= ~EF_ARM_PIC;
8240 elf_elfheader (obfd)->e_flags = in_flags;
8241 elf_flags_init (obfd) = TRUE;
8243 /* Also copy the EI_OSABI field. */
8244 elf_elfheader (obfd)->e_ident[EI_OSABI] =
8245 elf_elfheader (ibfd)->e_ident[EI_OSABI];
8247 /* Copy object attributes. */
8248 _bfd_elf_copy_obj_attributes (ibfd, obfd);
8250 return TRUE;
8253 /* Values for Tag_ABI_PCS_R9_use. */
8254 enum
8256 AEABI_R9_V6,
8257 AEABI_R9_SB,
8258 AEABI_R9_TLS,
8259 AEABI_R9_unused
8262 /* Values for Tag_ABI_PCS_RW_data. */
8263 enum
8265 AEABI_PCS_RW_data_absolute,
8266 AEABI_PCS_RW_data_PCrel,
8267 AEABI_PCS_RW_data_SBrel,
8268 AEABI_PCS_RW_data_unused
8271 /* Values for Tag_ABI_enum_size. */
8272 enum
8274 AEABI_enum_unused,
8275 AEABI_enum_short,
8276 AEABI_enum_wide,
8277 AEABI_enum_forced_wide
8280 /* Determine whether an object attribute tag takes an integer, a
8281 string or both. */
8283 static int
8284 elf32_arm_obj_attrs_arg_type (int tag)
8286 if (tag == Tag_compatibility)
8287 return ATTR_TYPE_FLAG_INT_VAL | ATTR_TYPE_FLAG_STR_VAL;
8288 else if (tag == Tag_nodefaults)
8289 return ATTR_TYPE_FLAG_INT_VAL | ATTR_TYPE_FLAG_NO_DEFAULT;
8290 else if (tag == Tag_CPU_raw_name || tag == Tag_CPU_name)
8291 return ATTR_TYPE_FLAG_STR_VAL;
8292 else if (tag < 32)
8293 return ATTR_TYPE_FLAG_INT_VAL;
8294 else
8295 return (tag & 1) != 0 ? ATTR_TYPE_FLAG_STR_VAL : ATTR_TYPE_FLAG_INT_VAL;
8298 /* The ABI defines that Tag_conformance should be emitted first, and that
8299 Tag_nodefaults should be second (if either is defined). This sets those
8300 two positions, and bumps up the position of all the remaining tags to
8301 compensate. */
8302 static int
8303 elf32_arm_obj_attrs_order (int num)
8305 if (num == 4)
8306 return Tag_conformance;
8307 if (num == 5)
8308 return Tag_nodefaults;
8309 if ((num - 2) < Tag_nodefaults)
8310 return num - 2;
8311 if ((num - 1) < Tag_conformance)
8312 return num - 1;
8313 return num;
8316 /* Read the architecture from the Tag_also_compatible_with attribute, if any.
8317 Returns -1 if no architecture could be read. */
8319 static int
8320 get_secondary_compatible_arch (bfd *abfd)
8322 obj_attribute *attr =
8323 &elf_known_obj_attributes_proc (abfd)[Tag_also_compatible_with];
8325 /* Note: the tag and its argument below are uleb128 values, though
8326 currently-defined values fit in one byte for each. */
8327 if (attr->s
8328 && attr->s[0] == Tag_CPU_arch
8329 && (attr->s[1] & 128) != 128
8330 && attr->s[2] == 0)
8331 return attr->s[1];
8333 /* This tag is "safely ignorable", so don't complain if it looks funny. */
8334 return -1;
8337 /* Set, or unset, the architecture of the Tag_also_compatible_with attribute.
8338 The tag is removed if ARCH is -1. */
8340 static void
8341 set_secondary_compatible_arch (bfd *abfd, int arch)
8343 obj_attribute *attr =
8344 &elf_known_obj_attributes_proc (abfd)[Tag_also_compatible_with];
8346 if (arch == -1)
8348 attr->s = NULL;
8349 return;
8352 /* Note: the tag and its argument below are uleb128 values, though
8353 currently-defined values fit in one byte for each. */
8354 if (!attr->s)
8355 attr->s = bfd_alloc (abfd, 3);
8356 attr->s[0] = Tag_CPU_arch;
8357 attr->s[1] = arch;
8358 attr->s[2] = '\0';
8361 /* Combine two values for Tag_CPU_arch, taking secondary compatibility tags
8362 into account. */
8364 static int
8365 tag_cpu_arch_combine (bfd *ibfd, int oldtag, int *secondary_compat_out,
8366 int newtag, int secondary_compat)
8368 #define T(X) TAG_CPU_ARCH_##X
8369 int tagl, tagh, result;
8370 const int v6t2[] =
8372 T(V6T2), /* PRE_V4. */
8373 T(V6T2), /* V4. */
8374 T(V6T2), /* V4T. */
8375 T(V6T2), /* V5T. */
8376 T(V6T2), /* V5TE. */
8377 T(V6T2), /* V5TEJ. */
8378 T(V6T2), /* V6. */
8379 T(V7), /* V6KZ. */
8380 T(V6T2) /* V6T2. */
8382 const int v6k[] =
8384 T(V6K), /* PRE_V4. */
8385 T(V6K), /* V4. */
8386 T(V6K), /* V4T. */
8387 T(V6K), /* V5T. */
8388 T(V6K), /* V5TE. */
8389 T(V6K), /* V5TEJ. */
8390 T(V6K), /* V6. */
8391 T(V6KZ), /* V6KZ. */
8392 T(V7), /* V6T2. */
8393 T(V6K) /* V6K. */
8395 const int v7[] =
8397 T(V7), /* PRE_V4. */
8398 T(V7), /* V4. */
8399 T(V7), /* V4T. */
8400 T(V7), /* V5T. */
8401 T(V7), /* V5TE. */
8402 T(V7), /* V5TEJ. */
8403 T(V7), /* V6. */
8404 T(V7), /* V6KZ. */
8405 T(V7), /* V6T2. */
8406 T(V7), /* V6K. */
8407 T(V7) /* V7. */
8409 const int v6_m[] =
8411 -1, /* PRE_V4. */
8412 -1, /* V4. */
8413 T(V6K), /* V4T. */
8414 T(V6K), /* V5T. */
8415 T(V6K), /* V5TE. */
8416 T(V6K), /* V5TEJ. */
8417 T(V6K), /* V6. */
8418 T(V6KZ), /* V6KZ. */
8419 T(V7), /* V6T2. */
8420 T(V6K), /* V6K. */
8421 T(V7), /* V7. */
8422 T(V6_M) /* V6_M. */
8424 const int v6s_m[] =
8426 -1, /* PRE_V4. */
8427 -1, /* V4. */
8428 T(V6K), /* V4T. */
8429 T(V6K), /* V5T. */
8430 T(V6K), /* V5TE. */
8431 T(V6K), /* V5TEJ. */
8432 T(V6K), /* V6. */
8433 T(V6KZ), /* V6KZ. */
8434 T(V7), /* V6T2. */
8435 T(V6K), /* V6K. */
8436 T(V7), /* V7. */
8437 T(V6S_M), /* V6_M. */
8438 T(V6S_M) /* V6S_M. */
8440 const int v4t_plus_v6_m[] =
8442 -1, /* PRE_V4. */
8443 -1, /* V4. */
8444 T(V4T), /* V4T. */
8445 T(V5T), /* V5T. */
8446 T(V5TE), /* V5TE. */
8447 T(V5TEJ), /* V5TEJ. */
8448 T(V6), /* V6. */
8449 T(V6KZ), /* V6KZ. */
8450 T(V6T2), /* V6T2. */
8451 T(V6K), /* V6K. */
8452 T(V7), /* V7. */
8453 T(V6_M), /* V6_M. */
8454 T(V6S_M), /* V6S_M. */
8455 T(V4T_PLUS_V6_M) /* V4T plus V6_M. */
8457 const int *comb[] =
8459 v6t2,
8460 v6k,
8462 v6_m,
8463 v6s_m,
8464 /* Pseudo-architecture. */
8465 v4t_plus_v6_m
8468 /* Check we've not got a higher architecture than we know about. */
8470 if (oldtag >= MAX_TAG_CPU_ARCH || newtag >= MAX_TAG_CPU_ARCH)
8472 _bfd_error_handler (_("ERROR: %B: Unknown CPU architecture"), ibfd);
8473 return -1;
8476 /* Override old tag if we have a Tag_also_compatible_with on the output. */
8478 if ((oldtag == T(V6_M) && *secondary_compat_out == T(V4T))
8479 || (oldtag == T(V4T) && *secondary_compat_out == T(V6_M)))
8480 oldtag = T(V4T_PLUS_V6_M);
8482 /* And override the new tag if we have a Tag_also_compatible_with on the
8483 input. */
8485 if ((newtag == T(V6_M) && secondary_compat == T(V4T))
8486 || (newtag == T(V4T) && secondary_compat == T(V6_M)))
8487 newtag = T(V4T_PLUS_V6_M);
8489 tagl = (oldtag < newtag) ? oldtag : newtag;
8490 result = tagh = (oldtag > newtag) ? oldtag : newtag;
8492 /* Architectures before V6KZ add features monotonically. */
8493 if (tagh <= TAG_CPU_ARCH_V6KZ)
8494 return result;
8496 result = comb[tagh - T(V6T2)][tagl];
8498 /* Use Tag_CPU_arch == V4T and Tag_also_compatible_with (Tag_CPU_arch V6_M)
8499 as the canonical version. */
8500 if (result == T(V4T_PLUS_V6_M))
8502 result = T(V4T);
8503 *secondary_compat_out = T(V6_M);
8505 else
8506 *secondary_compat_out = -1;
8508 if (result == -1)
8510 _bfd_error_handler (_("ERROR: %B: Conflicting CPU architectures %d/%d"),
8511 ibfd, oldtag, newtag);
8512 return -1;
8515 return result;
8516 #undef T
8519 /* Merge EABI object attributes from IBFD into OBFD. Raise an error if there
8520 are conflicting attributes. */
8522 static bfd_boolean
8523 elf32_arm_merge_eabi_attributes (bfd *ibfd, bfd *obfd)
8525 obj_attribute *in_attr;
8526 obj_attribute *out_attr;
8527 obj_attribute_list *in_list;
8528 obj_attribute_list *out_list;
8529 obj_attribute_list **out_listp;
8530 /* Some tags have 0 = don't care, 1 = strong requirement,
8531 2 = weak requirement. */
8532 static const int order_021[3] = {0, 2, 1};
8533 /* For use with Tag_VFP_arch. */
8534 static const int order_01243[5] = {0, 1, 2, 4, 3};
8535 int i;
8536 bfd_boolean result = TRUE;
8538 if (!elf_known_obj_attributes_proc (obfd)[0].i)
8540 /* This is the first object. Copy the attributes. */
8541 _bfd_elf_copy_obj_attributes (ibfd, obfd);
8543 /* Use the Tag_null value to indicate the attributes have been
8544 initialized. */
8545 elf_known_obj_attributes_proc (obfd)[0].i = 1;
8547 return TRUE;
8550 in_attr = elf_known_obj_attributes_proc (ibfd);
8551 out_attr = elf_known_obj_attributes_proc (obfd);
8552 /* This needs to happen before Tag_ABI_FP_number_model is merged. */
8553 if (in_attr[Tag_ABI_VFP_args].i != out_attr[Tag_ABI_VFP_args].i)
8555 /* Ignore mismatches if the object doesn't use floating point. */
8556 if (out_attr[Tag_ABI_FP_number_model].i == 0)
8557 out_attr[Tag_ABI_VFP_args].i = in_attr[Tag_ABI_VFP_args].i;
8558 else if (in_attr[Tag_ABI_FP_number_model].i != 0)
8560 _bfd_error_handler
8561 (_("ERROR: %B uses VFP register arguments, %B does not"),
8562 ibfd, obfd);
8563 result = FALSE;
8567 for (i = 4; i < NUM_KNOWN_OBJ_ATTRIBUTES; i++)
8569 /* Merge this attribute with existing attributes. */
8570 switch (i)
8572 case Tag_CPU_raw_name:
8573 case Tag_CPU_name:
8574 /* These are merged after Tag_CPU_arch. */
8575 break;
8577 case Tag_ABI_optimization_goals:
8578 case Tag_ABI_FP_optimization_goals:
8579 /* Use the first value seen. */
8580 break;
8582 case Tag_CPU_arch:
8584 int secondary_compat = -1, secondary_compat_out = -1;
8585 unsigned int saved_out_attr = out_attr[i].i;
8586 static const char *name_table[] = {
8587 /* These aren't real CPU names, but we can't guess
8588 that from the architecture version alone. */
8589 "Pre v4",
8590 "ARM v4",
8591 "ARM v4T",
8592 "ARM v5T",
8593 "ARM v5TE",
8594 "ARM v5TEJ",
8595 "ARM v6",
8596 "ARM v6KZ",
8597 "ARM v6T2",
8598 "ARM v6K",
8599 "ARM v7",
8600 "ARM v6-M",
8601 "ARM v6S-M"
8604 /* Merge Tag_CPU_arch and Tag_also_compatible_with. */
8605 secondary_compat = get_secondary_compatible_arch (ibfd);
8606 secondary_compat_out = get_secondary_compatible_arch (obfd);
8607 out_attr[i].i = tag_cpu_arch_combine (ibfd, out_attr[i].i,
8608 &secondary_compat_out,
8609 in_attr[i].i,
8610 secondary_compat);
8611 set_secondary_compatible_arch (obfd, secondary_compat_out);
8613 /* Merge Tag_CPU_name and Tag_CPU_raw_name. */
8614 if (out_attr[i].i == saved_out_attr)
8615 ; /* Leave the names alone. */
8616 else if (out_attr[i].i == in_attr[i].i)
8618 /* The output architecture has been changed to match the
8619 input architecture. Use the input names. */
8620 out_attr[Tag_CPU_name].s = in_attr[Tag_CPU_name].s
8621 ? _bfd_elf_attr_strdup (obfd, in_attr[Tag_CPU_name].s)
8622 : NULL;
8623 out_attr[Tag_CPU_raw_name].s = in_attr[Tag_CPU_raw_name].s
8624 ? _bfd_elf_attr_strdup (obfd, in_attr[Tag_CPU_raw_name].s)
8625 : NULL;
8627 else
8629 out_attr[Tag_CPU_name].s = NULL;
8630 out_attr[Tag_CPU_raw_name].s = NULL;
8633 /* If we still don't have a value for Tag_CPU_name,
8634 make one up now. Tag_CPU_raw_name remains blank. */
8635 if (out_attr[Tag_CPU_name].s == NULL
8636 && out_attr[i].i < ARRAY_SIZE (name_table))
8637 out_attr[Tag_CPU_name].s =
8638 _bfd_elf_attr_strdup (obfd, name_table[out_attr[i].i]);
8640 break;
8642 case Tag_ARM_ISA_use:
8643 case Tag_THUMB_ISA_use:
8644 case Tag_WMMX_arch:
8645 case Tag_Advanced_SIMD_arch:
8646 /* ??? Do Advanced_SIMD (NEON) and WMMX conflict? */
8647 case Tag_ABI_FP_rounding:
8648 case Tag_ABI_FP_exceptions:
8649 case Tag_ABI_FP_user_exceptions:
8650 case Tag_ABI_FP_number_model:
8651 case Tag_VFP_HP_extension:
8652 case Tag_CPU_unaligned_access:
8653 case Tag_T2EE_use:
8654 case Tag_Virtualization_use:
8655 case Tag_MPextension_use:
8656 /* Use the largest value specified. */
8657 if (in_attr[i].i > out_attr[i].i)
8658 out_attr[i].i = in_attr[i].i;
8659 break;
8661 case Tag_ABI_align8_preserved:
8662 case Tag_ABI_PCS_RO_data:
8663 /* Use the smallest value specified. */
8664 if (in_attr[i].i < out_attr[i].i)
8665 out_attr[i].i = in_attr[i].i;
8666 break;
8668 case Tag_ABI_align8_needed:
8669 if ((in_attr[i].i > 0 || out_attr[i].i > 0)
8670 && (in_attr[Tag_ABI_align8_preserved].i == 0
8671 || out_attr[Tag_ABI_align8_preserved].i == 0))
8673 /* This error message should be enabled once all non-conformant
8674 binaries in the toolchain have had the attributes set
8675 properly.
8676 _bfd_error_handler
8677 (_("ERROR: %B: 8-byte data alignment conflicts with %B"),
8678 obfd, ibfd);
8679 result = FALSE; */
8681 /* Fall through. */
8682 case Tag_ABI_FP_denormal:
8683 case Tag_ABI_PCS_GOT_use:
8684 /* Use the "greatest" from the sequence 0, 2, 1, or the largest
8685 value if greater than 2 (for future-proofing). */
8686 if ((in_attr[i].i > 2 && in_attr[i].i > out_attr[i].i)
8687 || (in_attr[i].i <= 2 && out_attr[i].i <= 2
8688 && order_021[in_attr[i].i] > order_021[out_attr[i].i]))
8689 out_attr[i].i = in_attr[i].i;
8690 break;
8693 case Tag_CPU_arch_profile:
8694 if (out_attr[i].i != in_attr[i].i)
8696 /* 0 will merge with anything.
8697 'A' and 'S' merge to 'A'.
8698 'R' and 'S' merge to 'R'.
8699 'M' and 'A|R|S' is an error. */
8700 if (out_attr[i].i == 0
8701 || (out_attr[i].i == 'S'
8702 && (in_attr[i].i == 'A' || in_attr[i].i == 'R')))
8703 out_attr[i].i = in_attr[i].i;
8704 else if (in_attr[i].i == 0
8705 || (in_attr[i].i == 'S'
8706 && (out_attr[i].i == 'A' || out_attr[i].i == 'R')))
8707 ; /* Do nothing. */
8708 else
8710 _bfd_error_handler
8711 (_("ERROR: %B: Conflicting architecture profiles %c/%c"),
8712 ibfd,
8713 in_attr[i].i ? in_attr[i].i : '0',
8714 out_attr[i].i ? out_attr[i].i : '0');
8715 result = FALSE;
8718 break;
8719 case Tag_VFP_arch:
8720 /* Use the "greatest" from the sequence 0, 1, 2, 4, 3, or the
8721 largest value if greater than 4 (for future-proofing). */
8722 if ((in_attr[i].i > 4 && in_attr[i].i > out_attr[i].i)
8723 || (in_attr[i].i <= 4 && out_attr[i].i <= 4
8724 && order_01243[in_attr[i].i] > order_01243[out_attr[i].i]))
8725 out_attr[i].i = in_attr[i].i;
8726 break;
8727 case Tag_PCS_config:
8728 if (out_attr[i].i == 0)
8729 out_attr[i].i = in_attr[i].i;
8730 else if (in_attr[i].i != 0 && out_attr[i].i != 0)
8732 /* It's sometimes ok to mix different configs, so this is only
8733 a warning. */
8734 _bfd_error_handler
8735 (_("Warning: %B: Conflicting platform configuration"), ibfd);
8737 break;
8738 case Tag_ABI_PCS_R9_use:
8739 if (in_attr[i].i != out_attr[i].i
8740 && out_attr[i].i != AEABI_R9_unused
8741 && in_attr[i].i != AEABI_R9_unused)
8743 _bfd_error_handler
8744 (_("ERROR: %B: Conflicting use of R9"), ibfd);
8745 result = FALSE;
8747 if (out_attr[i].i == AEABI_R9_unused)
8748 out_attr[i].i = in_attr[i].i;
8749 break;
8750 case Tag_ABI_PCS_RW_data:
8751 if (in_attr[i].i == AEABI_PCS_RW_data_SBrel
8752 && out_attr[Tag_ABI_PCS_R9_use].i != AEABI_R9_SB
8753 && out_attr[Tag_ABI_PCS_R9_use].i != AEABI_R9_unused)
8755 _bfd_error_handler
8756 (_("ERROR: %B: SB relative addressing conflicts with use of R9"),
8757 ibfd);
8758 result = FALSE;
8760 /* Use the smallest value specified. */
8761 if (in_attr[i].i < out_attr[i].i)
8762 out_attr[i].i = in_attr[i].i;
8763 break;
8764 case Tag_ABI_PCS_wchar_t:
8765 if (out_attr[i].i && in_attr[i].i && out_attr[i].i != in_attr[i].i
8766 && !elf_arm_tdata (obfd)->no_wchar_size_warning)
8768 _bfd_error_handler
8769 (_("warning: %B uses %u-byte wchar_t yet the output is to use %u-byte wchar_t; use of wchar_t values across objects may fail"),
8770 ibfd, in_attr[i].i, out_attr[i].i);
8772 else if (in_attr[i].i && !out_attr[i].i)
8773 out_attr[i].i = in_attr[i].i;
8774 break;
8775 case Tag_ABI_enum_size:
8776 if (in_attr[i].i != AEABI_enum_unused)
8778 if (out_attr[i].i == AEABI_enum_unused
8779 || out_attr[i].i == AEABI_enum_forced_wide)
8781 /* The existing object is compatible with anything.
8782 Use whatever requirements the new object has. */
8783 out_attr[i].i = in_attr[i].i;
8785 else if (in_attr[i].i != AEABI_enum_forced_wide
8786 && out_attr[i].i != in_attr[i].i
8787 && !elf_arm_tdata (obfd)->no_enum_size_warning)
8789 static const char *aeabi_enum_names[] =
8790 { "", "variable-size", "32-bit", "" };
8791 const char *in_name =
8792 in_attr[i].i < ARRAY_SIZE(aeabi_enum_names)
8793 ? aeabi_enum_names[in_attr[i].i]
8794 : "<unknown>";
8795 const char *out_name =
8796 out_attr[i].i < ARRAY_SIZE(aeabi_enum_names)
8797 ? aeabi_enum_names[out_attr[i].i]
8798 : "<unknown>";
8799 _bfd_error_handler
8800 (_("warning: %B uses %s enums yet the output is to use %s enums; use of enum values across objects may fail"),
8801 ibfd, in_name, out_name);
8804 break;
8805 case Tag_ABI_VFP_args:
8806 /* Aready done. */
8807 break;
8808 case Tag_ABI_WMMX_args:
8809 if (in_attr[i].i != out_attr[i].i)
8811 _bfd_error_handler
8812 (_("ERROR: %B uses iWMMXt register arguments, %B does not"),
8813 ibfd, obfd);
8814 result = FALSE;
8816 break;
8817 case Tag_compatibility:
8818 /* Merged in target-independent code. */
8819 break;
8820 case Tag_ABI_HardFP_use:
8821 /* 1 (SP) and 2 (DP) conflict, so combine to 3 (SP & DP). */
8822 if ((in_attr[i].i == 1 && out_attr[i].i == 2)
8823 || (in_attr[i].i == 2 && out_attr[i].i == 1))
8824 out_attr[i].i = 3;
8825 else if (in_attr[i].i > out_attr[i].i)
8826 out_attr[i].i = in_attr[i].i;
8827 break;
8828 case Tag_ABI_FP_16bit_format:
8829 if (in_attr[i].i != 0 && out_attr[i].i != 0)
8831 if (in_attr[i].i != out_attr[i].i)
8833 _bfd_error_handler
8834 (_("ERROR: fp16 format mismatch between %B and %B"),
8835 ibfd, obfd);
8836 result = FALSE;
8839 if (in_attr[i].i != 0)
8840 out_attr[i].i = in_attr[i].i;
8841 break;
8843 case Tag_nodefaults:
8844 /* This tag is set if it exists, but the value is unused (and is
8845 typically zero). We don't actually need to do anything here -
8846 the merge happens automatically when the type flags are merged
8847 below. */
8848 break;
8849 case Tag_also_compatible_with:
8850 /* Already done in Tag_CPU_arch. */
8851 break;
8852 case Tag_conformance:
8853 /* Keep the attribute if it matches. Throw it away otherwise.
8854 No attribute means no claim to conform. */
8855 if (!in_attr[i].s || !out_attr[i].s
8856 || strcmp (in_attr[i].s, out_attr[i].s) != 0)
8857 out_attr[i].s = NULL;
8858 break;
8860 default:
8862 bfd *err_bfd = NULL;
8864 /* The "known_obj_attributes" table does contain some undefined
8865 attributes. Ensure that there are unused. */
8866 if (out_attr[i].i != 0 || out_attr[i].s != NULL)
8867 err_bfd = obfd;
8868 else if (in_attr[i].i != 0 || in_attr[i].s != NULL)
8869 err_bfd = ibfd;
8871 if (err_bfd != NULL)
8873 /* Attribute numbers >=64 (mod 128) can be safely ignored. */
8874 if ((i & 127) < 64)
8876 _bfd_error_handler
8877 (_("%B: Unknown mandatory EABI object attribute %d"),
8878 err_bfd, i);
8879 bfd_set_error (bfd_error_bad_value);
8880 result = FALSE;
8882 else
8884 _bfd_error_handler
8885 (_("Warning: %B: Unknown EABI object attribute %d"),
8886 err_bfd, i);
8890 /* Only pass on attributes that match in both inputs. */
8891 if (in_attr[i].i != out_attr[i].i
8892 || in_attr[i].s != out_attr[i].s
8893 || (in_attr[i].s != NULL && out_attr[i].s != NULL
8894 && strcmp (in_attr[i].s, out_attr[i].s) != 0))
8896 out_attr[i].i = 0;
8897 out_attr[i].s = NULL;
8902 /* If out_attr was copied from in_attr then it won't have a type yet. */
8903 if (in_attr[i].type && !out_attr[i].type)
8904 out_attr[i].type = in_attr[i].type;
8907 /* Merge Tag_compatibility attributes and any common GNU ones. */
8908 _bfd_elf_merge_object_attributes (ibfd, obfd);
8910 /* Check for any attributes not known on ARM. */
8911 in_list = elf_other_obj_attributes_proc (ibfd);
8912 out_listp = &elf_other_obj_attributes_proc (obfd);
8913 out_list = *out_listp;
8915 for (; in_list || out_list; )
8917 bfd *err_bfd = NULL;
8918 int err_tag = 0;
8920 /* The tags for each list are in numerical order. */
8921 /* If the tags are equal, then merge. */
8922 if (out_list && (!in_list || in_list->tag > out_list->tag))
8924 /* This attribute only exists in obfd. We can't merge, and we don't
8925 know what the tag means, so delete it. */
8926 err_bfd = obfd;
8927 err_tag = out_list->tag;
8928 *out_listp = out_list->next;
8929 out_list = *out_listp;
8931 else if (in_list && (!out_list || in_list->tag < out_list->tag))
8933 /* This attribute only exists in ibfd. We can't merge, and we don't
8934 know what the tag means, so ignore it. */
8935 err_bfd = ibfd;
8936 err_tag = in_list->tag;
8937 in_list = in_list->next;
8939 else /* The tags are equal. */
8941 /* As present, all attributes in the list are unknown, and
8942 therefore can't be merged meaningfully. */
8943 err_bfd = obfd;
8944 err_tag = out_list->tag;
8946 /* Only pass on attributes that match in both inputs. */
8947 if (in_list->attr.i != out_list->attr.i
8948 || in_list->attr.s != out_list->attr.s
8949 || (in_list->attr.s && out_list->attr.s
8950 && strcmp (in_list->attr.s, out_list->attr.s) != 0))
8952 /* No match. Delete the attribute. */
8953 *out_listp = out_list->next;
8954 out_list = *out_listp;
8956 else
8958 /* Matched. Keep the attribute and move to the next. */
8959 out_list = out_list->next;
8960 in_list = in_list->next;
8964 if (err_bfd)
8966 /* Attribute numbers >=64 (mod 128) can be safely ignored. */
8967 if ((err_tag & 127) < 64)
8969 _bfd_error_handler
8970 (_("%B: Unknown mandatory EABI object attribute %d"),
8971 err_bfd, err_tag);
8972 bfd_set_error (bfd_error_bad_value);
8973 result = FALSE;
8975 else
8977 _bfd_error_handler
8978 (_("Warning: %B: Unknown EABI object attribute %d"),
8979 err_bfd, err_tag);
8983 return result;
8987 /* Return TRUE if the two EABI versions are incompatible. */
8989 static bfd_boolean
8990 elf32_arm_versions_compatible (unsigned iver, unsigned over)
8992 /* v4 and v5 are the same spec before and after it was released,
8993 so allow mixing them. */
8994 if ((iver == EF_ARM_EABI_VER4 && over == EF_ARM_EABI_VER5)
8995 || (iver == EF_ARM_EABI_VER5 && over == EF_ARM_EABI_VER4))
8996 return TRUE;
8998 return (iver == over);
9001 /* Merge backend specific data from an object file to the output
9002 object file when linking. */
9004 static bfd_boolean
9005 elf32_arm_merge_private_bfd_data (bfd * ibfd, bfd * obfd)
9007 flagword out_flags;
9008 flagword in_flags;
9009 bfd_boolean flags_compatible = TRUE;
9010 asection *sec;
9012 /* Check if we have the same endianess. */
9013 if (! _bfd_generic_verify_endian_match (ibfd, obfd))
9014 return FALSE;
9016 if (! is_arm_elf (ibfd) || ! is_arm_elf (obfd))
9017 return TRUE;
9019 if (!elf32_arm_merge_eabi_attributes (ibfd, obfd))
9020 return FALSE;
9022 /* The input BFD must have had its flags initialised. */
9023 /* The following seems bogus to me -- The flags are initialized in
9024 the assembler but I don't think an elf_flags_init field is
9025 written into the object. */
9026 /* BFD_ASSERT (elf_flags_init (ibfd)); */
9028 in_flags = elf_elfheader (ibfd)->e_flags;
9029 out_flags = elf_elfheader (obfd)->e_flags;
9031 /* In theory there is no reason why we couldn't handle this. However
9032 in practice it isn't even close to working and there is no real
9033 reason to want it. */
9034 if (EF_ARM_EABI_VERSION (in_flags) >= EF_ARM_EABI_VER4
9035 && !(ibfd->flags & DYNAMIC)
9036 && (in_flags & EF_ARM_BE8))
9038 _bfd_error_handler (_("ERROR: %B is already in final BE8 format"),
9039 ibfd);
9040 return FALSE;
9043 if (!elf_flags_init (obfd))
9045 /* If the input is the default architecture and had the default
9046 flags then do not bother setting the flags for the output
9047 architecture, instead allow future merges to do this. If no
9048 future merges ever set these flags then they will retain their
9049 uninitialised values, which surprise surprise, correspond
9050 to the default values. */
9051 if (bfd_get_arch_info (ibfd)->the_default
9052 && elf_elfheader (ibfd)->e_flags == 0)
9053 return TRUE;
9055 elf_flags_init (obfd) = TRUE;
9056 elf_elfheader (obfd)->e_flags = in_flags;
9058 if (bfd_get_arch (obfd) == bfd_get_arch (ibfd)
9059 && bfd_get_arch_info (obfd)->the_default)
9060 return bfd_set_arch_mach (obfd, bfd_get_arch (ibfd), bfd_get_mach (ibfd));
9062 return TRUE;
9065 /* Determine what should happen if the input ARM architecture
9066 does not match the output ARM architecture. */
9067 if (! bfd_arm_merge_machines (ibfd, obfd))
9068 return FALSE;
9070 /* Identical flags must be compatible. */
9071 if (in_flags == out_flags)
9072 return TRUE;
9074 /* Check to see if the input BFD actually contains any sections. If
9075 not, its flags may not have been initialised either, but it
9076 cannot actually cause any incompatiblity. Do not short-circuit
9077 dynamic objects; their section list may be emptied by
9078 elf_link_add_object_symbols.
9080 Also check to see if there are no code sections in the input.
9081 In this case there is no need to check for code specific flags.
9082 XXX - do we need to worry about floating-point format compatability
9083 in data sections ? */
9084 if (!(ibfd->flags & DYNAMIC))
9086 bfd_boolean null_input_bfd = TRUE;
9087 bfd_boolean only_data_sections = TRUE;
9089 for (sec = ibfd->sections; sec != NULL; sec = sec->next)
9091 /* Ignore synthetic glue sections. */
9092 if (strcmp (sec->name, ".glue_7")
9093 && strcmp (sec->name, ".glue_7t"))
9095 if ((bfd_get_section_flags (ibfd, sec)
9096 & (SEC_LOAD | SEC_CODE | SEC_HAS_CONTENTS))
9097 == (SEC_LOAD | SEC_CODE | SEC_HAS_CONTENTS))
9098 only_data_sections = FALSE;
9100 null_input_bfd = FALSE;
9101 break;
9105 if (null_input_bfd || only_data_sections)
9106 return TRUE;
9109 /* Complain about various flag mismatches. */
9110 if (!elf32_arm_versions_compatible (EF_ARM_EABI_VERSION (in_flags),
9111 EF_ARM_EABI_VERSION (out_flags)))
9113 _bfd_error_handler
9114 (_("ERROR: Source object %B has EABI version %d, but target %B has EABI version %d"),
9115 ibfd, obfd,
9116 (in_flags & EF_ARM_EABIMASK) >> 24,
9117 (out_flags & EF_ARM_EABIMASK) >> 24);
9118 return FALSE;
9121 /* Not sure what needs to be checked for EABI versions >= 1. */
9122 /* VxWorks libraries do not use these flags. */
9123 if (get_elf_backend_data (obfd) != &elf32_arm_vxworks_bed
9124 && get_elf_backend_data (ibfd) != &elf32_arm_vxworks_bed
9125 && EF_ARM_EABI_VERSION (in_flags) == EF_ARM_EABI_UNKNOWN)
9127 if ((in_flags & EF_ARM_APCS_26) != (out_flags & EF_ARM_APCS_26))
9129 _bfd_error_handler
9130 (_("ERROR: %B is compiled for APCS-%d, whereas target %B uses APCS-%d"),
9131 ibfd, obfd,
9132 in_flags & EF_ARM_APCS_26 ? 26 : 32,
9133 out_flags & EF_ARM_APCS_26 ? 26 : 32);
9134 flags_compatible = FALSE;
9137 if ((in_flags & EF_ARM_APCS_FLOAT) != (out_flags & EF_ARM_APCS_FLOAT))
9139 if (in_flags & EF_ARM_APCS_FLOAT)
9140 _bfd_error_handler
9141 (_("ERROR: %B passes floats in float registers, whereas %B passes them in integer registers"),
9142 ibfd, obfd);
9143 else
9144 _bfd_error_handler
9145 (_("ERROR: %B passes floats in integer registers, whereas %B passes them in float registers"),
9146 ibfd, obfd);
9148 flags_compatible = FALSE;
9151 if ((in_flags & EF_ARM_VFP_FLOAT) != (out_flags & EF_ARM_VFP_FLOAT))
9153 if (in_flags & EF_ARM_VFP_FLOAT)
9154 _bfd_error_handler
9155 (_("ERROR: %B uses VFP instructions, whereas %B does not"),
9156 ibfd, obfd);
9157 else
9158 _bfd_error_handler
9159 (_("ERROR: %B uses FPA instructions, whereas %B does not"),
9160 ibfd, obfd);
9162 flags_compatible = FALSE;
9165 if ((in_flags & EF_ARM_MAVERICK_FLOAT) != (out_flags & EF_ARM_MAVERICK_FLOAT))
9167 if (in_flags & EF_ARM_MAVERICK_FLOAT)
9168 _bfd_error_handler
9169 (_("ERROR: %B uses Maverick instructions, whereas %B does not"),
9170 ibfd, obfd);
9171 else
9172 _bfd_error_handler
9173 (_("ERROR: %B does not use Maverick instructions, whereas %B does"),
9174 ibfd, obfd);
9176 flags_compatible = FALSE;
9179 #ifdef EF_ARM_SOFT_FLOAT
9180 if ((in_flags & EF_ARM_SOFT_FLOAT) != (out_flags & EF_ARM_SOFT_FLOAT))
9182 /* We can allow interworking between code that is VFP format
9183 layout, and uses either soft float or integer regs for
9184 passing floating point arguments and results. We already
9185 know that the APCS_FLOAT flags match; similarly for VFP
9186 flags. */
9187 if ((in_flags & EF_ARM_APCS_FLOAT) != 0
9188 || (in_flags & EF_ARM_VFP_FLOAT) == 0)
9190 if (in_flags & EF_ARM_SOFT_FLOAT)
9191 _bfd_error_handler
9192 (_("ERROR: %B uses software FP, whereas %B uses hardware FP"),
9193 ibfd, obfd);
9194 else
9195 _bfd_error_handler
9196 (_("ERROR: %B uses hardware FP, whereas %B uses software FP"),
9197 ibfd, obfd);
9199 flags_compatible = FALSE;
9202 #endif
9204 /* Interworking mismatch is only a warning. */
9205 if ((in_flags & EF_ARM_INTERWORK) != (out_flags & EF_ARM_INTERWORK))
9207 if (in_flags & EF_ARM_INTERWORK)
9209 _bfd_error_handler
9210 (_("Warning: %B supports interworking, whereas %B does not"),
9211 ibfd, obfd);
9213 else
9215 _bfd_error_handler
9216 (_("Warning: %B does not support interworking, whereas %B does"),
9217 ibfd, obfd);
9222 return flags_compatible;
9225 /* Display the flags field. */
9227 static bfd_boolean
9228 elf32_arm_print_private_bfd_data (bfd *abfd, void * ptr)
9230 FILE * file = (FILE *) ptr;
9231 unsigned long flags;
9233 BFD_ASSERT (abfd != NULL && ptr != NULL);
9235 /* Print normal ELF private data. */
9236 _bfd_elf_print_private_bfd_data (abfd, ptr);
9238 flags = elf_elfheader (abfd)->e_flags;
9239 /* Ignore init flag - it may not be set, despite the flags field
9240 containing valid data. */
9242 /* xgettext:c-format */
9243 fprintf (file, _("private flags = %lx:"), elf_elfheader (abfd)->e_flags);
9245 switch (EF_ARM_EABI_VERSION (flags))
9247 case EF_ARM_EABI_UNKNOWN:
9248 /* The following flag bits are GNU extensions and not part of the
9249 official ARM ELF extended ABI. Hence they are only decoded if
9250 the EABI version is not set. */
9251 if (flags & EF_ARM_INTERWORK)
9252 fprintf (file, _(" [interworking enabled]"));
9254 if (flags & EF_ARM_APCS_26)
9255 fprintf (file, " [APCS-26]");
9256 else
9257 fprintf (file, " [APCS-32]");
9259 if (flags & EF_ARM_VFP_FLOAT)
9260 fprintf (file, _(" [VFP float format]"));
9261 else if (flags & EF_ARM_MAVERICK_FLOAT)
9262 fprintf (file, _(" [Maverick float format]"));
9263 else
9264 fprintf (file, _(" [FPA float format]"));
9266 if (flags & EF_ARM_APCS_FLOAT)
9267 fprintf (file, _(" [floats passed in float registers]"));
9269 if (flags & EF_ARM_PIC)
9270 fprintf (file, _(" [position independent]"));
9272 if (flags & EF_ARM_NEW_ABI)
9273 fprintf (file, _(" [new ABI]"));
9275 if (flags & EF_ARM_OLD_ABI)
9276 fprintf (file, _(" [old ABI]"));
9278 if (flags & EF_ARM_SOFT_FLOAT)
9279 fprintf (file, _(" [software FP]"));
9281 flags &= ~(EF_ARM_INTERWORK | EF_ARM_APCS_26 | EF_ARM_APCS_FLOAT
9282 | EF_ARM_PIC | EF_ARM_NEW_ABI | EF_ARM_OLD_ABI
9283 | EF_ARM_SOFT_FLOAT | EF_ARM_VFP_FLOAT
9284 | EF_ARM_MAVERICK_FLOAT);
9285 break;
9287 case EF_ARM_EABI_VER1:
9288 fprintf (file, _(" [Version1 EABI]"));
9290 if (flags & EF_ARM_SYMSARESORTED)
9291 fprintf (file, _(" [sorted symbol table]"));
9292 else
9293 fprintf (file, _(" [unsorted symbol table]"));
9295 flags &= ~ EF_ARM_SYMSARESORTED;
9296 break;
9298 case EF_ARM_EABI_VER2:
9299 fprintf (file, _(" [Version2 EABI]"));
9301 if (flags & EF_ARM_SYMSARESORTED)
9302 fprintf (file, _(" [sorted symbol table]"));
9303 else
9304 fprintf (file, _(" [unsorted symbol table]"));
9306 if (flags & EF_ARM_DYNSYMSUSESEGIDX)
9307 fprintf (file, _(" [dynamic symbols use segment index]"));
9309 if (flags & EF_ARM_MAPSYMSFIRST)
9310 fprintf (file, _(" [mapping symbols precede others]"));
9312 flags &= ~(EF_ARM_SYMSARESORTED | EF_ARM_DYNSYMSUSESEGIDX
9313 | EF_ARM_MAPSYMSFIRST);
9314 break;
9316 case EF_ARM_EABI_VER3:
9317 fprintf (file, _(" [Version3 EABI]"));
9318 break;
9320 case EF_ARM_EABI_VER4:
9321 fprintf (file, _(" [Version4 EABI]"));
9322 goto eabi;
9324 case EF_ARM_EABI_VER5:
9325 fprintf (file, _(" [Version5 EABI]"));
9326 eabi:
9327 if (flags & EF_ARM_BE8)
9328 fprintf (file, _(" [BE8]"));
9330 if (flags & EF_ARM_LE8)
9331 fprintf (file, _(" [LE8]"));
9333 flags &= ~(EF_ARM_LE8 | EF_ARM_BE8);
9334 break;
9336 default:
9337 fprintf (file, _(" <EABI version unrecognised>"));
9338 break;
9341 flags &= ~ EF_ARM_EABIMASK;
9343 if (flags & EF_ARM_RELEXEC)
9344 fprintf (file, _(" [relocatable executable]"));
9346 if (flags & EF_ARM_HASENTRY)
9347 fprintf (file, _(" [has entry point]"));
9349 flags &= ~ (EF_ARM_RELEXEC | EF_ARM_HASENTRY);
9351 if (flags)
9352 fprintf (file, _("<Unrecognised flag bits set>"));
9354 fputc ('\n', file);
9356 return TRUE;
9359 static int
9360 elf32_arm_get_symbol_type (Elf_Internal_Sym * elf_sym, int type)
9362 switch (ELF_ST_TYPE (elf_sym->st_info))
9364 case STT_ARM_TFUNC:
9365 return ELF_ST_TYPE (elf_sym->st_info);
9367 case STT_ARM_16BIT:
9368 /* If the symbol is not an object, return the STT_ARM_16BIT flag.
9369 This allows us to distinguish between data used by Thumb instructions
9370 and non-data (which is probably code) inside Thumb regions of an
9371 executable. */
9372 if (type != STT_OBJECT && type != STT_TLS)
9373 return ELF_ST_TYPE (elf_sym->st_info);
9374 break;
9376 default:
9377 break;
9380 return type;
9383 static asection *
9384 elf32_arm_gc_mark_hook (asection *sec,
9385 struct bfd_link_info *info,
9386 Elf_Internal_Rela *rel,
9387 struct elf_link_hash_entry *h,
9388 Elf_Internal_Sym *sym)
9390 if (h != NULL)
9391 switch (ELF32_R_TYPE (rel->r_info))
9393 case R_ARM_GNU_VTINHERIT:
9394 case R_ARM_GNU_VTENTRY:
9395 return NULL;
9398 return _bfd_elf_gc_mark_hook (sec, info, rel, h, sym);
9401 /* Update the got entry reference counts for the section being removed. */
9403 static bfd_boolean
9404 elf32_arm_gc_sweep_hook (bfd * abfd,
9405 struct bfd_link_info * info,
9406 asection * sec,
9407 const Elf_Internal_Rela * relocs)
9409 Elf_Internal_Shdr *symtab_hdr;
9410 struct elf_link_hash_entry **sym_hashes;
9411 bfd_signed_vma *local_got_refcounts;
9412 const Elf_Internal_Rela *rel, *relend;
9413 struct elf32_arm_link_hash_table * globals;
9415 if (info->relocatable)
9416 return TRUE;
9418 globals = elf32_arm_hash_table (info);
9420 elf_section_data (sec)->local_dynrel = NULL;
9422 symtab_hdr = & elf_symtab_hdr (abfd);
9423 sym_hashes = elf_sym_hashes (abfd);
9424 local_got_refcounts = elf_local_got_refcounts (abfd);
9426 check_use_blx (globals);
9428 relend = relocs + sec->reloc_count;
9429 for (rel = relocs; rel < relend; rel++)
9431 unsigned long r_symndx;
9432 struct elf_link_hash_entry *h = NULL;
9433 int r_type;
9435 r_symndx = ELF32_R_SYM (rel->r_info);
9436 if (r_symndx >= symtab_hdr->sh_info)
9438 h = sym_hashes[r_symndx - symtab_hdr->sh_info];
9439 while (h->root.type == bfd_link_hash_indirect
9440 || h->root.type == bfd_link_hash_warning)
9441 h = (struct elf_link_hash_entry *) h->root.u.i.link;
9444 r_type = ELF32_R_TYPE (rel->r_info);
9445 r_type = arm_real_reloc_type (globals, r_type);
9446 switch (r_type)
9448 case R_ARM_GOT32:
9449 case R_ARM_GOT_PREL:
9450 case R_ARM_TLS_GD32:
9451 case R_ARM_TLS_IE32:
9452 if (h != NULL)
9454 if (h->got.refcount > 0)
9455 h->got.refcount -= 1;
9457 else if (local_got_refcounts != NULL)
9459 if (local_got_refcounts[r_symndx] > 0)
9460 local_got_refcounts[r_symndx] -= 1;
9462 break;
9464 case R_ARM_TLS_LDM32:
9465 elf32_arm_hash_table (info)->tls_ldm_got.refcount -= 1;
9466 break;
9468 case R_ARM_ABS32:
9469 case R_ARM_ABS32_NOI:
9470 case R_ARM_REL32:
9471 case R_ARM_REL32_NOI:
9472 case R_ARM_PC24:
9473 case R_ARM_PLT32:
9474 case R_ARM_CALL:
9475 case R_ARM_JUMP24:
9476 case R_ARM_PREL31:
9477 case R_ARM_THM_CALL:
9478 case R_ARM_THM_JUMP24:
9479 case R_ARM_THM_JUMP19:
9480 case R_ARM_MOVW_ABS_NC:
9481 case R_ARM_MOVT_ABS:
9482 case R_ARM_MOVW_PREL_NC:
9483 case R_ARM_MOVT_PREL:
9484 case R_ARM_THM_MOVW_ABS_NC:
9485 case R_ARM_THM_MOVT_ABS:
9486 case R_ARM_THM_MOVW_PREL_NC:
9487 case R_ARM_THM_MOVT_PREL:
9488 /* Should the interworking branches be here also? */
9490 if (h != NULL)
9492 struct elf32_arm_link_hash_entry *eh;
9493 struct elf32_arm_relocs_copied **pp;
9494 struct elf32_arm_relocs_copied *p;
9496 eh = (struct elf32_arm_link_hash_entry *) h;
9498 if (h->plt.refcount > 0)
9500 h->plt.refcount -= 1;
9501 if (r_type == R_ARM_THM_CALL)
9502 eh->plt_maybe_thumb_refcount--;
9504 if (r_type == R_ARM_THM_JUMP24
9505 || r_type == R_ARM_THM_JUMP19)
9506 eh->plt_thumb_refcount--;
9509 if (r_type == R_ARM_ABS32
9510 || r_type == R_ARM_REL32
9511 || r_type == R_ARM_ABS32_NOI
9512 || r_type == R_ARM_REL32_NOI)
9514 for (pp = &eh->relocs_copied; (p = *pp) != NULL;
9515 pp = &p->next)
9516 if (p->section == sec)
9518 p->count -= 1;
9519 if (ELF32_R_TYPE (rel->r_info) == R_ARM_REL32
9520 || ELF32_R_TYPE (rel->r_info) == R_ARM_REL32_NOI)
9521 p->pc_count -= 1;
9522 if (p->count == 0)
9523 *pp = p->next;
9524 break;
9528 break;
9530 default:
9531 break;
9535 return TRUE;
9538 /* Look through the relocs for a section during the first phase. */
9540 static bfd_boolean
9541 elf32_arm_check_relocs (bfd *abfd, struct bfd_link_info *info,
9542 asection *sec, const Elf_Internal_Rela *relocs)
9544 Elf_Internal_Shdr *symtab_hdr;
9545 struct elf_link_hash_entry **sym_hashes;
9546 const Elf_Internal_Rela *rel;
9547 const Elf_Internal_Rela *rel_end;
9548 bfd *dynobj;
9549 asection *sreloc;
9550 bfd_vma *local_got_offsets;
9551 struct elf32_arm_link_hash_table *htab;
9552 bfd_boolean needs_plt;
9554 if (info->relocatable)
9555 return TRUE;
9557 BFD_ASSERT (is_arm_elf (abfd));
9559 htab = elf32_arm_hash_table (info);
9560 sreloc = NULL;
9562 /* Create dynamic sections for relocatable executables so that we can
9563 copy relocations. */
9564 if (htab->root.is_relocatable_executable
9565 && ! htab->root.dynamic_sections_created)
9567 if (! _bfd_elf_link_create_dynamic_sections (abfd, info))
9568 return FALSE;
9571 dynobj = elf_hash_table (info)->dynobj;
9572 local_got_offsets = elf_local_got_offsets (abfd);
9574 symtab_hdr = & elf_symtab_hdr (abfd);
9575 sym_hashes = elf_sym_hashes (abfd);
9577 rel_end = relocs + sec->reloc_count;
9578 for (rel = relocs; rel < rel_end; rel++)
9580 struct elf_link_hash_entry *h;
9581 struct elf32_arm_link_hash_entry *eh;
9582 unsigned long r_symndx;
9583 int r_type;
9585 r_symndx = ELF32_R_SYM (rel->r_info);
9586 r_type = ELF32_R_TYPE (rel->r_info);
9587 r_type = arm_real_reloc_type (htab, r_type);
9589 if (r_symndx >= NUM_SHDR_ENTRIES (symtab_hdr))
9591 (*_bfd_error_handler) (_("%B: bad symbol index: %d"), abfd,
9592 r_symndx);
9593 return FALSE;
9596 if (r_symndx < symtab_hdr->sh_info)
9597 h = NULL;
9598 else
9600 h = sym_hashes[r_symndx - symtab_hdr->sh_info];
9601 while (h->root.type == bfd_link_hash_indirect
9602 || h->root.type == bfd_link_hash_warning)
9603 h = (struct elf_link_hash_entry *) h->root.u.i.link;
9606 eh = (struct elf32_arm_link_hash_entry *) h;
9608 switch (r_type)
9610 case R_ARM_GOT32:
9611 case R_ARM_GOT_PREL:
9612 case R_ARM_TLS_GD32:
9613 case R_ARM_TLS_IE32:
9614 /* This symbol requires a global offset table entry. */
9616 int tls_type, old_tls_type;
9618 switch (r_type)
9620 case R_ARM_TLS_GD32: tls_type = GOT_TLS_GD; break;
9621 case R_ARM_TLS_IE32: tls_type = GOT_TLS_IE; break;
9622 default: tls_type = GOT_NORMAL; break;
9625 if (h != NULL)
9627 h->got.refcount++;
9628 old_tls_type = elf32_arm_hash_entry (h)->tls_type;
9630 else
9632 bfd_signed_vma *local_got_refcounts;
9634 /* This is a global offset table entry for a local symbol. */
9635 local_got_refcounts = elf_local_got_refcounts (abfd);
9636 if (local_got_refcounts == NULL)
9638 bfd_size_type size;
9640 size = symtab_hdr->sh_info;
9641 size *= (sizeof (bfd_signed_vma) + sizeof (char));
9642 local_got_refcounts = bfd_zalloc (abfd, size);
9643 if (local_got_refcounts == NULL)
9644 return FALSE;
9645 elf_local_got_refcounts (abfd) = local_got_refcounts;
9646 elf32_arm_local_got_tls_type (abfd)
9647 = (char *) (local_got_refcounts + symtab_hdr->sh_info);
9649 local_got_refcounts[r_symndx] += 1;
9650 old_tls_type = elf32_arm_local_got_tls_type (abfd) [r_symndx];
9653 /* We will already have issued an error message if there is a
9654 TLS / non-TLS mismatch, based on the symbol type. We don't
9655 support any linker relaxations. So just combine any TLS
9656 types needed. */
9657 if (old_tls_type != GOT_UNKNOWN && old_tls_type != GOT_NORMAL
9658 && tls_type != GOT_NORMAL)
9659 tls_type |= old_tls_type;
9661 if (old_tls_type != tls_type)
9663 if (h != NULL)
9664 elf32_arm_hash_entry (h)->tls_type = tls_type;
9665 else
9666 elf32_arm_local_got_tls_type (abfd) [r_symndx] = tls_type;
9669 /* Fall through. */
9671 case R_ARM_TLS_LDM32:
9672 if (r_type == R_ARM_TLS_LDM32)
9673 htab->tls_ldm_got.refcount++;
9674 /* Fall through. */
9676 case R_ARM_GOTOFF32:
9677 case R_ARM_GOTPC:
9678 if (htab->sgot == NULL)
9680 if (htab->root.dynobj == NULL)
9681 htab->root.dynobj = abfd;
9682 if (!create_got_section (htab->root.dynobj, info))
9683 return FALSE;
9685 break;
9687 case R_ARM_ABS12:
9688 /* VxWorks uses dynamic R_ARM_ABS12 relocations for
9689 ldr __GOTT_INDEX__ offsets. */
9690 if (!htab->vxworks_p)
9691 break;
9692 /* Fall through. */
9694 case R_ARM_PC24:
9695 case R_ARM_PLT32:
9696 case R_ARM_CALL:
9697 case R_ARM_JUMP24:
9698 case R_ARM_PREL31:
9699 case R_ARM_THM_CALL:
9700 case R_ARM_THM_JUMP24:
9701 case R_ARM_THM_JUMP19:
9702 needs_plt = 1;
9703 goto normal_reloc;
9705 case R_ARM_ABS32:
9706 case R_ARM_ABS32_NOI:
9707 case R_ARM_REL32:
9708 case R_ARM_REL32_NOI:
9709 case R_ARM_MOVW_ABS_NC:
9710 case R_ARM_MOVT_ABS:
9711 case R_ARM_MOVW_PREL_NC:
9712 case R_ARM_MOVT_PREL:
9713 case R_ARM_THM_MOVW_ABS_NC:
9714 case R_ARM_THM_MOVT_ABS:
9715 case R_ARM_THM_MOVW_PREL_NC:
9716 case R_ARM_THM_MOVT_PREL:
9717 needs_plt = 0;
9718 normal_reloc:
9720 /* Should the interworking branches be listed here? */
9721 if (h != NULL)
9723 /* If this reloc is in a read-only section, we might
9724 need a copy reloc. We can't check reliably at this
9725 stage whether the section is read-only, as input
9726 sections have not yet been mapped to output sections.
9727 Tentatively set the flag for now, and correct in
9728 adjust_dynamic_symbol. */
9729 if (!info->shared)
9730 h->non_got_ref = 1;
9732 /* We may need a .plt entry if the function this reloc
9733 refers to is in a different object. We can't tell for
9734 sure yet, because something later might force the
9735 symbol local. */
9736 if (needs_plt)
9737 h->needs_plt = 1;
9739 /* If we create a PLT entry, this relocation will reference
9740 it, even if it's an ABS32 relocation. */
9741 h->plt.refcount += 1;
9743 /* It's too early to use htab->use_blx here, so we have to
9744 record possible blx references separately from
9745 relocs that definitely need a thumb stub. */
9747 if (r_type == R_ARM_THM_CALL)
9748 eh->plt_maybe_thumb_refcount += 1;
9750 if (r_type == R_ARM_THM_JUMP24
9751 || r_type == R_ARM_THM_JUMP19)
9752 eh->plt_thumb_refcount += 1;
9755 /* If we are creating a shared library or relocatable executable,
9756 and this is a reloc against a global symbol, or a non PC
9757 relative reloc against a local symbol, then we need to copy
9758 the reloc into the shared library. However, if we are linking
9759 with -Bsymbolic, we do not need to copy a reloc against a
9760 global symbol which is defined in an object we are
9761 including in the link (i.e., DEF_REGULAR is set). At
9762 this point we have not seen all the input files, so it is
9763 possible that DEF_REGULAR is not set now but will be set
9764 later (it is never cleared). We account for that
9765 possibility below by storing information in the
9766 relocs_copied field of the hash table entry. */
9767 if ((info->shared || htab->root.is_relocatable_executable)
9768 && (sec->flags & SEC_ALLOC) != 0
9769 && ((r_type == R_ARM_ABS32 || r_type == R_ARM_ABS32_NOI)
9770 || (h != NULL && ! h->needs_plt
9771 && (! info->symbolic || ! h->def_regular))))
9773 struct elf32_arm_relocs_copied *p, **head;
9775 /* When creating a shared object, we must copy these
9776 reloc types into the output file. We create a reloc
9777 section in dynobj and make room for this reloc. */
9778 if (sreloc == NULL)
9780 sreloc = _bfd_elf_make_dynamic_reloc_section
9781 (sec, dynobj, 2, abfd, ! htab->use_rel);
9783 if (sreloc == NULL)
9784 return FALSE;
9786 /* BPABI objects never have dynamic relocations mapped. */
9787 if (! htab->symbian_p)
9789 flagword flags;
9791 flags = bfd_get_section_flags (dynobj, sreloc);
9792 flags |= (SEC_LOAD | SEC_ALLOC);
9793 bfd_set_section_flags (dynobj, sreloc, flags);
9797 /* If this is a global symbol, we count the number of
9798 relocations we need for this symbol. */
9799 if (h != NULL)
9801 head = &((struct elf32_arm_link_hash_entry *) h)->relocs_copied;
9803 else
9805 /* Track dynamic relocs needed for local syms too.
9806 We really need local syms available to do this
9807 easily. Oh well. */
9809 asection *s;
9810 void *vpp;
9812 s = bfd_section_from_r_symndx (abfd, &htab->sym_sec,
9813 sec, r_symndx);
9814 if (s == NULL)
9815 return FALSE;
9817 vpp = &elf_section_data (s)->local_dynrel;
9818 head = (struct elf32_arm_relocs_copied **) vpp;
9821 p = *head;
9822 if (p == NULL || p->section != sec)
9824 bfd_size_type amt = sizeof *p;
9826 p = bfd_alloc (htab->root.dynobj, amt);
9827 if (p == NULL)
9828 return FALSE;
9829 p->next = *head;
9830 *head = p;
9831 p->section = sec;
9832 p->count = 0;
9833 p->pc_count = 0;
9836 if (r_type == R_ARM_REL32 || r_type == R_ARM_REL32_NOI)
9837 p->pc_count += 1;
9838 p->count += 1;
9840 break;
9842 /* This relocation describes the C++ object vtable hierarchy.
9843 Reconstruct it for later use during GC. */
9844 case R_ARM_GNU_VTINHERIT:
9845 if (!bfd_elf_gc_record_vtinherit (abfd, sec, h, rel->r_offset))
9846 return FALSE;
9847 break;
9849 /* This relocation describes which C++ vtable entries are actually
9850 used. Record for later use during GC. */
9851 case R_ARM_GNU_VTENTRY:
9852 BFD_ASSERT (h != NULL);
9853 if (h != NULL
9854 && !bfd_elf_gc_record_vtentry (abfd, sec, h, rel->r_offset))
9855 return FALSE;
9856 break;
9860 return TRUE;
9863 /* Unwinding tables are not referenced directly. This pass marks them as
9864 required if the corresponding code section is marked. */
9866 static bfd_boolean
9867 elf32_arm_gc_mark_extra_sections (struct bfd_link_info *info,
9868 elf_gc_mark_hook_fn gc_mark_hook)
9870 bfd *sub;
9871 Elf_Internal_Shdr **elf_shdrp;
9872 bfd_boolean again;
9874 /* Marking EH data may cause additional code sections to be marked,
9875 requiring multiple passes. */
9876 again = TRUE;
9877 while (again)
9879 again = FALSE;
9880 for (sub = info->input_bfds; sub != NULL; sub = sub->link_next)
9882 asection *o;
9884 if (! is_arm_elf (sub))
9885 continue;
9887 elf_shdrp = elf_elfsections (sub);
9888 for (o = sub->sections; o != NULL; o = o->next)
9890 Elf_Internal_Shdr *hdr;
9892 hdr = &elf_section_data (o)->this_hdr;
9893 if (hdr->sh_type == SHT_ARM_EXIDX
9894 && hdr->sh_link
9895 && hdr->sh_link < elf_numsections (sub)
9896 && !o->gc_mark
9897 && elf_shdrp[hdr->sh_link]->bfd_section->gc_mark)
9899 again = TRUE;
9900 if (!_bfd_elf_gc_mark (info, o, gc_mark_hook))
9901 return FALSE;
9907 return TRUE;
9910 /* Treat mapping symbols as special target symbols. */
9912 static bfd_boolean
9913 elf32_arm_is_target_special_symbol (bfd * abfd ATTRIBUTE_UNUSED, asymbol * sym)
9915 return bfd_is_arm_special_symbol_name (sym->name,
9916 BFD_ARM_SPECIAL_SYM_TYPE_ANY);
9919 /* This is a copy of elf_find_function() from elf.c except that
9920 ARM mapping symbols are ignored when looking for function names
9921 and STT_ARM_TFUNC is considered to a function type. */
9923 static bfd_boolean
9924 arm_elf_find_function (bfd * abfd ATTRIBUTE_UNUSED,
9925 asection * section,
9926 asymbol ** symbols,
9927 bfd_vma offset,
9928 const char ** filename_ptr,
9929 const char ** functionname_ptr)
9931 const char * filename = NULL;
9932 asymbol * func = NULL;
9933 bfd_vma low_func = 0;
9934 asymbol ** p;
9936 for (p = symbols; *p != NULL; p++)
9938 elf_symbol_type *q;
9940 q = (elf_symbol_type *) *p;
9942 switch (ELF_ST_TYPE (q->internal_elf_sym.st_info))
9944 default:
9945 break;
9946 case STT_FILE:
9947 filename = bfd_asymbol_name (&q->symbol);
9948 break;
9949 case STT_FUNC:
9950 case STT_ARM_TFUNC:
9951 case STT_NOTYPE:
9952 /* Skip mapping symbols. */
9953 if ((q->symbol.flags & BSF_LOCAL)
9954 && bfd_is_arm_special_symbol_name (q->symbol.name,
9955 BFD_ARM_SPECIAL_SYM_TYPE_ANY))
9956 continue;
9957 /* Fall through. */
9958 if (bfd_get_section (&q->symbol) == section
9959 && q->symbol.value >= low_func
9960 && q->symbol.value <= offset)
9962 func = (asymbol *) q;
9963 low_func = q->symbol.value;
9965 break;
9969 if (func == NULL)
9970 return FALSE;
9972 if (filename_ptr)
9973 *filename_ptr = filename;
9974 if (functionname_ptr)
9975 *functionname_ptr = bfd_asymbol_name (func);
9977 return TRUE;
9981 /* Find the nearest line to a particular section and offset, for error
9982 reporting. This code is a duplicate of the code in elf.c, except
9983 that it uses arm_elf_find_function. */
9985 static bfd_boolean
9986 elf32_arm_find_nearest_line (bfd * abfd,
9987 asection * section,
9988 asymbol ** symbols,
9989 bfd_vma offset,
9990 const char ** filename_ptr,
9991 const char ** functionname_ptr,
9992 unsigned int * line_ptr)
9994 bfd_boolean found = FALSE;
9996 /* We skip _bfd_dwarf1_find_nearest_line since no known ARM toolchain uses it. */
9998 if (_bfd_dwarf2_find_nearest_line (abfd, section, symbols, offset,
9999 filename_ptr, functionname_ptr,
10000 line_ptr, 0,
10001 & elf_tdata (abfd)->dwarf2_find_line_info))
10003 if (!*functionname_ptr)
10004 arm_elf_find_function (abfd, section, symbols, offset,
10005 *filename_ptr ? NULL : filename_ptr,
10006 functionname_ptr);
10008 return TRUE;
10011 if (! _bfd_stab_section_find_nearest_line (abfd, symbols, section, offset,
10012 & found, filename_ptr,
10013 functionname_ptr, line_ptr,
10014 & elf_tdata (abfd)->line_info))
10015 return FALSE;
10017 if (found && (*functionname_ptr || *line_ptr))
10018 return TRUE;
10020 if (symbols == NULL)
10021 return FALSE;
10023 if (! arm_elf_find_function (abfd, section, symbols, offset,
10024 filename_ptr, functionname_ptr))
10025 return FALSE;
10027 *line_ptr = 0;
10028 return TRUE;
10031 static bfd_boolean
10032 elf32_arm_find_inliner_info (bfd * abfd,
10033 const char ** filename_ptr,
10034 const char ** functionname_ptr,
10035 unsigned int * line_ptr)
10037 bfd_boolean found;
10038 found = _bfd_dwarf2_find_inliner_info (abfd, filename_ptr,
10039 functionname_ptr, line_ptr,
10040 & elf_tdata (abfd)->dwarf2_find_line_info);
10041 return found;
10044 /* Adjust a symbol defined by a dynamic object and referenced by a
10045 regular object. The current definition is in some section of the
10046 dynamic object, but we're not including those sections. We have to
10047 change the definition to something the rest of the link can
10048 understand. */
10050 static bfd_boolean
10051 elf32_arm_adjust_dynamic_symbol (struct bfd_link_info * info,
10052 struct elf_link_hash_entry * h)
10054 bfd * dynobj;
10055 asection * s;
10056 struct elf32_arm_link_hash_entry * eh;
10057 struct elf32_arm_link_hash_table *globals;
10059 globals = elf32_arm_hash_table (info);
10060 dynobj = elf_hash_table (info)->dynobj;
10062 /* Make sure we know what is going on here. */
10063 BFD_ASSERT (dynobj != NULL
10064 && (h->needs_plt
10065 || h->u.weakdef != NULL
10066 || (h->def_dynamic
10067 && h->ref_regular
10068 && !h->def_regular)));
10070 eh = (struct elf32_arm_link_hash_entry *) h;
10072 /* If this is a function, put it in the procedure linkage table. We
10073 will fill in the contents of the procedure linkage table later,
10074 when we know the address of the .got section. */
10075 if (h->type == STT_FUNC || h->type == STT_ARM_TFUNC
10076 || h->needs_plt)
10078 if (h->plt.refcount <= 0
10079 || SYMBOL_CALLS_LOCAL (info, h)
10080 || (ELF_ST_VISIBILITY (h->other) != STV_DEFAULT
10081 && h->root.type == bfd_link_hash_undefweak))
10083 /* This case can occur if we saw a PLT32 reloc in an input
10084 file, but the symbol was never referred to by a dynamic
10085 object, or if all references were garbage collected. In
10086 such a case, we don't actually need to build a procedure
10087 linkage table, and we can just do a PC24 reloc instead. */
10088 h->plt.offset = (bfd_vma) -1;
10089 eh->plt_thumb_refcount = 0;
10090 eh->plt_maybe_thumb_refcount = 0;
10091 h->needs_plt = 0;
10094 return TRUE;
10096 else
10098 /* It's possible that we incorrectly decided a .plt reloc was
10099 needed for an R_ARM_PC24 or similar reloc to a non-function sym
10100 in check_relocs. We can't decide accurately between function
10101 and non-function syms in check-relocs; Objects loaded later in
10102 the link may change h->type. So fix it now. */
10103 h->plt.offset = (bfd_vma) -1;
10104 eh->plt_thumb_refcount = 0;
10105 eh->plt_maybe_thumb_refcount = 0;
10108 /* If this is a weak symbol, and there is a real definition, the
10109 processor independent code will have arranged for us to see the
10110 real definition first, and we can just use the same value. */
10111 if (h->u.weakdef != NULL)
10113 BFD_ASSERT (h->u.weakdef->root.type == bfd_link_hash_defined
10114 || h->u.weakdef->root.type == bfd_link_hash_defweak);
10115 h->root.u.def.section = h->u.weakdef->root.u.def.section;
10116 h->root.u.def.value = h->u.weakdef->root.u.def.value;
10117 return TRUE;
10120 /* If there are no non-GOT references, we do not need a copy
10121 relocation. */
10122 if (!h->non_got_ref)
10123 return TRUE;
10125 /* This is a reference to a symbol defined by a dynamic object which
10126 is not a function. */
10128 /* If we are creating a shared library, we must presume that the
10129 only references to the symbol are via the global offset table.
10130 For such cases we need not do anything here; the relocations will
10131 be handled correctly by relocate_section. Relocatable executables
10132 can reference data in shared objects directly, so we don't need to
10133 do anything here. */
10134 if (info->shared || globals->root.is_relocatable_executable)
10135 return TRUE;
10137 if (h->size == 0)
10139 (*_bfd_error_handler) (_("dynamic variable `%s' is zero size"),
10140 h->root.root.string);
10141 return TRUE;
10144 /* We must allocate the symbol in our .dynbss section, which will
10145 become part of the .bss section of the executable. There will be
10146 an entry for this symbol in the .dynsym section. The dynamic
10147 object will contain position independent code, so all references
10148 from the dynamic object to this symbol will go through the global
10149 offset table. The dynamic linker will use the .dynsym entry to
10150 determine the address it must put in the global offset table, so
10151 both the dynamic object and the regular object will refer to the
10152 same memory location for the variable. */
10153 s = bfd_get_section_by_name (dynobj, ".dynbss");
10154 BFD_ASSERT (s != NULL);
10156 /* We must generate a R_ARM_COPY reloc to tell the dynamic linker to
10157 copy the initial value out of the dynamic object and into the
10158 runtime process image. We need to remember the offset into the
10159 .rel(a).bss section we are going to use. */
10160 if ((h->root.u.def.section->flags & SEC_ALLOC) != 0)
10162 asection *srel;
10164 srel = bfd_get_section_by_name (dynobj, RELOC_SECTION (globals, ".bss"));
10165 BFD_ASSERT (srel != NULL);
10166 srel->size += RELOC_SIZE (globals);
10167 h->needs_copy = 1;
10170 return _bfd_elf_adjust_dynamic_copy (h, s);
10173 /* Allocate space in .plt, .got and associated reloc sections for
10174 dynamic relocs. */
10176 static bfd_boolean
10177 allocate_dynrelocs (struct elf_link_hash_entry *h, void * inf)
10179 struct bfd_link_info *info;
10180 struct elf32_arm_link_hash_table *htab;
10181 struct elf32_arm_link_hash_entry *eh;
10182 struct elf32_arm_relocs_copied *p;
10183 bfd_signed_vma thumb_refs;
10185 eh = (struct elf32_arm_link_hash_entry *) h;
10187 if (h->root.type == bfd_link_hash_indirect)
10188 return TRUE;
10190 if (h->root.type == bfd_link_hash_warning)
10191 /* When warning symbols are created, they **replace** the "real"
10192 entry in the hash table, thus we never get to see the real
10193 symbol in a hash traversal. So look at it now. */
10194 h = (struct elf_link_hash_entry *) h->root.u.i.link;
10196 info = (struct bfd_link_info *) inf;
10197 htab = elf32_arm_hash_table (info);
10199 if (htab->root.dynamic_sections_created
10200 && h->plt.refcount > 0)
10202 /* Make sure this symbol is output as a dynamic symbol.
10203 Undefined weak syms won't yet be marked as dynamic. */
10204 if (h->dynindx == -1
10205 && !h->forced_local)
10207 if (! bfd_elf_link_record_dynamic_symbol (info, h))
10208 return FALSE;
10211 if (info->shared
10212 || WILL_CALL_FINISH_DYNAMIC_SYMBOL (1, 0, h))
10214 asection *s = htab->splt;
10216 /* If this is the first .plt entry, make room for the special
10217 first entry. */
10218 if (s->size == 0)
10219 s->size += htab->plt_header_size;
10221 h->plt.offset = s->size;
10223 /* If we will insert a Thumb trampoline before this PLT, leave room
10224 for it. */
10225 thumb_refs = eh->plt_thumb_refcount;
10226 if (!htab->use_blx)
10227 thumb_refs += eh->plt_maybe_thumb_refcount;
10229 if (thumb_refs > 0)
10231 h->plt.offset += PLT_THUMB_STUB_SIZE;
10232 s->size += PLT_THUMB_STUB_SIZE;
10235 /* If this symbol is not defined in a regular file, and we are
10236 not generating a shared library, then set the symbol to this
10237 location in the .plt. This is required to make function
10238 pointers compare as equal between the normal executable and
10239 the shared library. */
10240 if (! info->shared
10241 && !h->def_regular)
10243 h->root.u.def.section = s;
10244 h->root.u.def.value = h->plt.offset;
10246 /* Make sure the function is not marked as Thumb, in case
10247 it is the target of an ABS32 relocation, which will
10248 point to the PLT entry. */
10249 if (ELF_ST_TYPE (h->type) == STT_ARM_TFUNC)
10250 h->type = ELF_ST_INFO (ELF_ST_BIND (h->type), STT_FUNC);
10253 /* Make room for this entry. */
10254 s->size += htab->plt_entry_size;
10256 if (!htab->symbian_p)
10258 /* We also need to make an entry in the .got.plt section, which
10259 will be placed in the .got section by the linker script. */
10260 eh->plt_got_offset = htab->sgotplt->size;
10261 htab->sgotplt->size += 4;
10264 /* We also need to make an entry in the .rel(a).plt section. */
10265 htab->srelplt->size += RELOC_SIZE (htab);
10267 /* VxWorks executables have a second set of relocations for
10268 each PLT entry. They go in a separate relocation section,
10269 which is processed by the kernel loader. */
10270 if (htab->vxworks_p && !info->shared)
10272 /* There is a relocation for the initial PLT entry:
10273 an R_ARM_32 relocation for _GLOBAL_OFFSET_TABLE_. */
10274 if (h->plt.offset == htab->plt_header_size)
10275 htab->srelplt2->size += RELOC_SIZE (htab);
10277 /* There are two extra relocations for each subsequent
10278 PLT entry: an R_ARM_32 relocation for the GOT entry,
10279 and an R_ARM_32 relocation for the PLT entry. */
10280 htab->srelplt2->size += RELOC_SIZE (htab) * 2;
10283 else
10285 h->plt.offset = (bfd_vma) -1;
10286 h->needs_plt = 0;
10289 else
10291 h->plt.offset = (bfd_vma) -1;
10292 h->needs_plt = 0;
10295 if (h->got.refcount > 0)
10297 asection *s;
10298 bfd_boolean dyn;
10299 int tls_type = elf32_arm_hash_entry (h)->tls_type;
10300 int indx;
10302 /* Make sure this symbol is output as a dynamic symbol.
10303 Undefined weak syms won't yet be marked as dynamic. */
10304 if (h->dynindx == -1
10305 && !h->forced_local)
10307 if (! bfd_elf_link_record_dynamic_symbol (info, h))
10308 return FALSE;
10311 if (!htab->symbian_p)
10313 s = htab->sgot;
10314 h->got.offset = s->size;
10316 if (tls_type == GOT_UNKNOWN)
10317 abort ();
10319 if (tls_type == GOT_NORMAL)
10320 /* Non-TLS symbols need one GOT slot. */
10321 s->size += 4;
10322 else
10324 if (tls_type & GOT_TLS_GD)
10325 /* R_ARM_TLS_GD32 needs 2 consecutive GOT slots. */
10326 s->size += 8;
10327 if (tls_type & GOT_TLS_IE)
10328 /* R_ARM_TLS_IE32 needs one GOT slot. */
10329 s->size += 4;
10332 dyn = htab->root.dynamic_sections_created;
10334 indx = 0;
10335 if (WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn, info->shared, h)
10336 && (!info->shared
10337 || !SYMBOL_REFERENCES_LOCAL (info, h)))
10338 indx = h->dynindx;
10340 if (tls_type != GOT_NORMAL
10341 && (info->shared || indx != 0)
10342 && (ELF_ST_VISIBILITY (h->other) == STV_DEFAULT
10343 || h->root.type != bfd_link_hash_undefweak))
10345 if (tls_type & GOT_TLS_IE)
10346 htab->srelgot->size += RELOC_SIZE (htab);
10348 if (tls_type & GOT_TLS_GD)
10349 htab->srelgot->size += RELOC_SIZE (htab);
10351 if ((tls_type & GOT_TLS_GD) && indx != 0)
10352 htab->srelgot->size += RELOC_SIZE (htab);
10354 else if ((ELF_ST_VISIBILITY (h->other) == STV_DEFAULT
10355 || h->root.type != bfd_link_hash_undefweak)
10356 && (info->shared
10357 || WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn, 0, h)))
10358 htab->srelgot->size += RELOC_SIZE (htab);
10361 else
10362 h->got.offset = (bfd_vma) -1;
10364 /* Allocate stubs for exported Thumb functions on v4t. */
10365 if (!htab->use_blx && h->dynindx != -1
10366 && h->def_regular
10367 && ELF_ST_TYPE (h->type) == STT_ARM_TFUNC
10368 && ELF_ST_VISIBILITY (h->other) == STV_DEFAULT)
10370 struct elf_link_hash_entry * th;
10371 struct bfd_link_hash_entry * bh;
10372 struct elf_link_hash_entry * myh;
10373 char name[1024];
10374 asection *s;
10375 bh = NULL;
10376 /* Create a new symbol to regist the real location of the function. */
10377 s = h->root.u.def.section;
10378 sprintf (name, "__real_%s", h->root.root.string);
10379 _bfd_generic_link_add_one_symbol (info, s->owner,
10380 name, BSF_GLOBAL, s,
10381 h->root.u.def.value,
10382 NULL, TRUE, FALSE, &bh);
10384 myh = (struct elf_link_hash_entry *) bh;
10385 myh->type = ELF_ST_INFO (STB_LOCAL, STT_ARM_TFUNC);
10386 myh->forced_local = 1;
10387 eh->export_glue = myh;
10388 th = record_arm_to_thumb_glue (info, h);
10389 /* Point the symbol at the stub. */
10390 h->type = ELF_ST_INFO (ELF_ST_BIND (h->type), STT_FUNC);
10391 h->root.u.def.section = th->root.u.def.section;
10392 h->root.u.def.value = th->root.u.def.value & ~1;
10395 if (eh->relocs_copied == NULL)
10396 return TRUE;
10398 /* In the shared -Bsymbolic case, discard space allocated for
10399 dynamic pc-relative relocs against symbols which turn out to be
10400 defined in regular objects. For the normal shared case, discard
10401 space for pc-relative relocs that have become local due to symbol
10402 visibility changes. */
10404 if (info->shared || htab->root.is_relocatable_executable)
10406 /* The only relocs that use pc_count are R_ARM_REL32 and
10407 R_ARM_REL32_NOI, which will appear on something like
10408 ".long foo - .". We want calls to protected symbols to resolve
10409 directly to the function rather than going via the plt. If people
10410 want function pointer comparisons to work as expected then they
10411 should avoid writing assembly like ".long foo - .". */
10412 if (SYMBOL_CALLS_LOCAL (info, h))
10414 struct elf32_arm_relocs_copied **pp;
10416 for (pp = &eh->relocs_copied; (p = *pp) != NULL; )
10418 p->count -= p->pc_count;
10419 p->pc_count = 0;
10420 if (p->count == 0)
10421 *pp = p->next;
10422 else
10423 pp = &p->next;
10427 if (elf32_arm_hash_table (info)->vxworks_p)
10429 struct elf32_arm_relocs_copied **pp;
10431 for (pp = &eh->relocs_copied; (p = *pp) != NULL; )
10433 if (strcmp (p->section->output_section->name, ".tls_vars") == 0)
10434 *pp = p->next;
10435 else
10436 pp = &p->next;
10440 /* Also discard relocs on undefined weak syms with non-default
10441 visibility. */
10442 if (eh->relocs_copied != NULL
10443 && h->root.type == bfd_link_hash_undefweak)
10445 if (ELF_ST_VISIBILITY (h->other) != STV_DEFAULT)
10446 eh->relocs_copied = NULL;
10448 /* Make sure undefined weak symbols are output as a dynamic
10449 symbol in PIEs. */
10450 else if (h->dynindx == -1
10451 && !h->forced_local)
10453 if (! bfd_elf_link_record_dynamic_symbol (info, h))
10454 return FALSE;
10458 else if (htab->root.is_relocatable_executable && h->dynindx == -1
10459 && h->root.type == bfd_link_hash_new)
10461 /* Output absolute symbols so that we can create relocations
10462 against them. For normal symbols we output a relocation
10463 against the section that contains them. */
10464 if (! bfd_elf_link_record_dynamic_symbol (info, h))
10465 return FALSE;
10469 else
10471 /* For the non-shared case, discard space for relocs against
10472 symbols which turn out to need copy relocs or are not
10473 dynamic. */
10475 if (!h->non_got_ref
10476 && ((h->def_dynamic
10477 && !h->def_regular)
10478 || (htab->root.dynamic_sections_created
10479 && (h->root.type == bfd_link_hash_undefweak
10480 || h->root.type == bfd_link_hash_undefined))))
10482 /* Make sure this symbol is output as a dynamic symbol.
10483 Undefined weak syms won't yet be marked as dynamic. */
10484 if (h->dynindx == -1
10485 && !h->forced_local)
10487 if (! bfd_elf_link_record_dynamic_symbol (info, h))
10488 return FALSE;
10491 /* If that succeeded, we know we'll be keeping all the
10492 relocs. */
10493 if (h->dynindx != -1)
10494 goto keep;
10497 eh->relocs_copied = NULL;
10499 keep: ;
10502 /* Finally, allocate space. */
10503 for (p = eh->relocs_copied; p != NULL; p = p->next)
10505 asection *sreloc = elf_section_data (p->section)->sreloc;
10506 sreloc->size += p->count * RELOC_SIZE (htab);
10509 return TRUE;
10512 /* Find any dynamic relocs that apply to read-only sections. */
10514 static bfd_boolean
10515 elf32_arm_readonly_dynrelocs (struct elf_link_hash_entry * h, void * inf)
10517 struct elf32_arm_link_hash_entry * eh;
10518 struct elf32_arm_relocs_copied * p;
10520 if (h->root.type == bfd_link_hash_warning)
10521 h = (struct elf_link_hash_entry *) h->root.u.i.link;
10523 eh = (struct elf32_arm_link_hash_entry *) h;
10524 for (p = eh->relocs_copied; p != NULL; p = p->next)
10526 asection *s = p->section;
10528 if (s != NULL && (s->flags & SEC_READONLY) != 0)
10530 struct bfd_link_info *info = (struct bfd_link_info *) inf;
10532 info->flags |= DF_TEXTREL;
10534 /* Not an error, just cut short the traversal. */
10535 return FALSE;
10538 return TRUE;
10541 void
10542 bfd_elf32_arm_set_byteswap_code (struct bfd_link_info *info,
10543 int byteswap_code)
10545 struct elf32_arm_link_hash_table *globals;
10547 globals = elf32_arm_hash_table (info);
10548 globals->byteswap_code = byteswap_code;
10551 /* Set the sizes of the dynamic sections. */
10553 static bfd_boolean
10554 elf32_arm_size_dynamic_sections (bfd * output_bfd ATTRIBUTE_UNUSED,
10555 struct bfd_link_info * info)
10557 bfd * dynobj;
10558 asection * s;
10559 bfd_boolean plt;
10560 bfd_boolean relocs;
10561 bfd *ibfd;
10562 struct elf32_arm_link_hash_table *htab;
10564 htab = elf32_arm_hash_table (info);
10565 dynobj = elf_hash_table (info)->dynobj;
10566 BFD_ASSERT (dynobj != NULL);
10567 check_use_blx (htab);
10569 if (elf_hash_table (info)->dynamic_sections_created)
10571 /* Set the contents of the .interp section to the interpreter. */
10572 if (info->executable)
10574 s = bfd_get_section_by_name (dynobj, ".interp");
10575 BFD_ASSERT (s != NULL);
10576 s->size = sizeof ELF_DYNAMIC_INTERPRETER;
10577 s->contents = (unsigned char *) ELF_DYNAMIC_INTERPRETER;
10581 /* Set up .got offsets for local syms, and space for local dynamic
10582 relocs. */
10583 for (ibfd = info->input_bfds; ibfd != NULL; ibfd = ibfd->link_next)
10585 bfd_signed_vma *local_got;
10586 bfd_signed_vma *end_local_got;
10587 char *local_tls_type;
10588 bfd_size_type locsymcount;
10589 Elf_Internal_Shdr *symtab_hdr;
10590 asection *srel;
10591 bfd_boolean is_vxworks = elf32_arm_hash_table (info)->vxworks_p;
10593 if (! is_arm_elf (ibfd))
10594 continue;
10596 for (s = ibfd->sections; s != NULL; s = s->next)
10598 struct elf32_arm_relocs_copied *p;
10600 for (p = elf_section_data (s)->local_dynrel; p != NULL; p = p->next)
10602 if (!bfd_is_abs_section (p->section)
10603 && bfd_is_abs_section (p->section->output_section))
10605 /* Input section has been discarded, either because
10606 it is a copy of a linkonce section or due to
10607 linker script /DISCARD/, so we'll be discarding
10608 the relocs too. */
10610 else if (is_vxworks
10611 && strcmp (p->section->output_section->name,
10612 ".tls_vars") == 0)
10614 /* Relocations in vxworks .tls_vars sections are
10615 handled specially by the loader. */
10617 else if (p->count != 0)
10619 srel = elf_section_data (p->section)->sreloc;
10620 srel->size += p->count * RELOC_SIZE (htab);
10621 if ((p->section->output_section->flags & SEC_READONLY) != 0)
10622 info->flags |= DF_TEXTREL;
10627 local_got = elf_local_got_refcounts (ibfd);
10628 if (!local_got)
10629 continue;
10631 symtab_hdr = & elf_symtab_hdr (ibfd);
10632 locsymcount = symtab_hdr->sh_info;
10633 end_local_got = local_got + locsymcount;
10634 local_tls_type = elf32_arm_local_got_tls_type (ibfd);
10635 s = htab->sgot;
10636 srel = htab->srelgot;
10637 for (; local_got < end_local_got; ++local_got, ++local_tls_type)
10639 if (*local_got > 0)
10641 *local_got = s->size;
10642 if (*local_tls_type & GOT_TLS_GD)
10643 /* TLS_GD relocs need an 8-byte structure in the GOT. */
10644 s->size += 8;
10645 if (*local_tls_type & GOT_TLS_IE)
10646 s->size += 4;
10647 if (*local_tls_type == GOT_NORMAL)
10648 s->size += 4;
10650 if (info->shared || *local_tls_type == GOT_TLS_GD)
10651 srel->size += RELOC_SIZE (htab);
10653 else
10654 *local_got = (bfd_vma) -1;
10658 if (htab->tls_ldm_got.refcount > 0)
10660 /* Allocate two GOT entries and one dynamic relocation (if necessary)
10661 for R_ARM_TLS_LDM32 relocations. */
10662 htab->tls_ldm_got.offset = htab->sgot->size;
10663 htab->sgot->size += 8;
10664 if (info->shared)
10665 htab->srelgot->size += RELOC_SIZE (htab);
10667 else
10668 htab->tls_ldm_got.offset = -1;
10670 /* Allocate global sym .plt and .got entries, and space for global
10671 sym dynamic relocs. */
10672 elf_link_hash_traverse (& htab->root, allocate_dynrelocs, info);
10674 /* Here we rummage through the found bfds to collect glue information. */
10675 for (ibfd = info->input_bfds; ibfd != NULL; ibfd = ibfd->link_next)
10677 if (! is_arm_elf (ibfd))
10678 continue;
10680 /* Initialise mapping tables for code/data. */
10681 bfd_elf32_arm_init_maps (ibfd);
10683 if (!bfd_elf32_arm_process_before_allocation (ibfd, info)
10684 || !bfd_elf32_arm_vfp11_erratum_scan (ibfd, info))
10685 /* xgettext:c-format */
10686 _bfd_error_handler (_("Errors encountered processing file %s"),
10687 ibfd->filename);
10690 /* The check_relocs and adjust_dynamic_symbol entry points have
10691 determined the sizes of the various dynamic sections. Allocate
10692 memory for them. */
10693 plt = FALSE;
10694 relocs = FALSE;
10695 for (s = dynobj->sections; s != NULL; s = s->next)
10697 const char * name;
10699 if ((s->flags & SEC_LINKER_CREATED) == 0)
10700 continue;
10702 /* It's OK to base decisions on the section name, because none
10703 of the dynobj section names depend upon the input files. */
10704 name = bfd_get_section_name (dynobj, s);
10706 if (strcmp (name, ".plt") == 0)
10708 /* Remember whether there is a PLT. */
10709 plt = s->size != 0;
10711 else if (CONST_STRNEQ (name, ".rel"))
10713 if (s->size != 0)
10715 /* Remember whether there are any reloc sections other
10716 than .rel(a).plt and .rela.plt.unloaded. */
10717 if (s != htab->srelplt && s != htab->srelplt2)
10718 relocs = TRUE;
10720 /* We use the reloc_count field as a counter if we need
10721 to copy relocs into the output file. */
10722 s->reloc_count = 0;
10725 else if (! CONST_STRNEQ (name, ".got")
10726 && strcmp (name, ".dynbss") != 0)
10728 /* It's not one of our sections, so don't allocate space. */
10729 continue;
10732 if (s->size == 0)
10734 /* If we don't need this section, strip it from the
10735 output file. This is mostly to handle .rel(a).bss and
10736 .rel(a).plt. We must create both sections in
10737 create_dynamic_sections, because they must be created
10738 before the linker maps input sections to output
10739 sections. The linker does that before
10740 adjust_dynamic_symbol is called, and it is that
10741 function which decides whether anything needs to go
10742 into these sections. */
10743 s->flags |= SEC_EXCLUDE;
10744 continue;
10747 if ((s->flags & SEC_HAS_CONTENTS) == 0)
10748 continue;
10750 /* Allocate memory for the section contents. */
10751 s->contents = bfd_zalloc (dynobj, s->size);
10752 if (s->contents == NULL)
10753 return FALSE;
10756 if (elf_hash_table (info)->dynamic_sections_created)
10758 /* Add some entries to the .dynamic section. We fill in the
10759 values later, in elf32_arm_finish_dynamic_sections, but we
10760 must add the entries now so that we get the correct size for
10761 the .dynamic section. The DT_DEBUG entry is filled in by the
10762 dynamic linker and used by the debugger. */
10763 #define add_dynamic_entry(TAG, VAL) \
10764 _bfd_elf_add_dynamic_entry (info, TAG, VAL)
10766 if (info->executable)
10768 if (!add_dynamic_entry (DT_DEBUG, 0))
10769 return FALSE;
10772 if (plt)
10774 if ( !add_dynamic_entry (DT_PLTGOT, 0)
10775 || !add_dynamic_entry (DT_PLTRELSZ, 0)
10776 || !add_dynamic_entry (DT_PLTREL,
10777 htab->use_rel ? DT_REL : DT_RELA)
10778 || !add_dynamic_entry (DT_JMPREL, 0))
10779 return FALSE;
10782 if (relocs)
10784 if (htab->use_rel)
10786 if (!add_dynamic_entry (DT_REL, 0)
10787 || !add_dynamic_entry (DT_RELSZ, 0)
10788 || !add_dynamic_entry (DT_RELENT, RELOC_SIZE (htab)))
10789 return FALSE;
10791 else
10793 if (!add_dynamic_entry (DT_RELA, 0)
10794 || !add_dynamic_entry (DT_RELASZ, 0)
10795 || !add_dynamic_entry (DT_RELAENT, RELOC_SIZE (htab)))
10796 return FALSE;
10800 /* If any dynamic relocs apply to a read-only section,
10801 then we need a DT_TEXTREL entry. */
10802 if ((info->flags & DF_TEXTREL) == 0)
10803 elf_link_hash_traverse (& htab->root, elf32_arm_readonly_dynrelocs,
10804 info);
10806 if ((info->flags & DF_TEXTREL) != 0)
10808 if (!add_dynamic_entry (DT_TEXTREL, 0))
10809 return FALSE;
10811 if (htab->vxworks_p
10812 && !elf_vxworks_add_dynamic_entries (output_bfd, info))
10813 return FALSE;
10815 #undef add_dynamic_entry
10817 return TRUE;
10820 /* Finish up dynamic symbol handling. We set the contents of various
10821 dynamic sections here. */
10823 static bfd_boolean
10824 elf32_arm_finish_dynamic_symbol (bfd * output_bfd,
10825 struct bfd_link_info * info,
10826 struct elf_link_hash_entry * h,
10827 Elf_Internal_Sym * sym)
10829 bfd * dynobj;
10830 struct elf32_arm_link_hash_table *htab;
10831 struct elf32_arm_link_hash_entry *eh;
10833 dynobj = elf_hash_table (info)->dynobj;
10834 htab = elf32_arm_hash_table (info);
10835 eh = (struct elf32_arm_link_hash_entry *) h;
10837 if (h->plt.offset != (bfd_vma) -1)
10839 asection * splt;
10840 asection * srel;
10841 bfd_byte *loc;
10842 bfd_vma plt_index;
10843 Elf_Internal_Rela rel;
10845 /* This symbol has an entry in the procedure linkage table. Set
10846 it up. */
10848 BFD_ASSERT (h->dynindx != -1);
10850 splt = bfd_get_section_by_name (dynobj, ".plt");
10851 srel = bfd_get_section_by_name (dynobj, RELOC_SECTION (htab, ".plt"));
10852 BFD_ASSERT (splt != NULL && srel != NULL);
10854 /* Fill in the entry in the procedure linkage table. */
10855 if (htab->symbian_p)
10857 put_arm_insn (htab, output_bfd,
10858 elf32_arm_symbian_plt_entry[0],
10859 splt->contents + h->plt.offset);
10860 bfd_put_32 (output_bfd,
10861 elf32_arm_symbian_plt_entry[1],
10862 splt->contents + h->plt.offset + 4);
10864 /* Fill in the entry in the .rel.plt section. */
10865 rel.r_offset = (splt->output_section->vma
10866 + splt->output_offset
10867 + h->plt.offset + 4);
10868 rel.r_info = ELF32_R_INFO (h->dynindx, R_ARM_GLOB_DAT);
10870 /* Get the index in the procedure linkage table which
10871 corresponds to this symbol. This is the index of this symbol
10872 in all the symbols for which we are making plt entries. The
10873 first entry in the procedure linkage table is reserved. */
10874 plt_index = ((h->plt.offset - htab->plt_header_size)
10875 / htab->plt_entry_size);
10877 else
10879 bfd_vma got_offset, got_address, plt_address;
10880 bfd_vma got_displacement;
10881 asection * sgot;
10882 bfd_byte * ptr;
10884 sgot = bfd_get_section_by_name (dynobj, ".got.plt");
10885 BFD_ASSERT (sgot != NULL);
10887 /* Get the offset into the .got.plt table of the entry that
10888 corresponds to this function. */
10889 got_offset = eh->plt_got_offset;
10891 /* Get the index in the procedure linkage table which
10892 corresponds to this symbol. This is the index of this symbol
10893 in all the symbols for which we are making plt entries. The
10894 first three entries in .got.plt are reserved; after that
10895 symbols appear in the same order as in .plt. */
10896 plt_index = (got_offset - 12) / 4;
10898 /* Calculate the address of the GOT entry. */
10899 got_address = (sgot->output_section->vma
10900 + sgot->output_offset
10901 + got_offset);
10903 /* ...and the address of the PLT entry. */
10904 plt_address = (splt->output_section->vma
10905 + splt->output_offset
10906 + h->plt.offset);
10908 ptr = htab->splt->contents + h->plt.offset;
10909 if (htab->vxworks_p && info->shared)
10911 unsigned int i;
10912 bfd_vma val;
10914 for (i = 0; i != htab->plt_entry_size / 4; i++, ptr += 4)
10916 val = elf32_arm_vxworks_shared_plt_entry[i];
10917 if (i == 2)
10918 val |= got_address - sgot->output_section->vma;
10919 if (i == 5)
10920 val |= plt_index * RELOC_SIZE (htab);
10921 if (i == 2 || i == 5)
10922 bfd_put_32 (output_bfd, val, ptr);
10923 else
10924 put_arm_insn (htab, output_bfd, val, ptr);
10927 else if (htab->vxworks_p)
10929 unsigned int i;
10930 bfd_vma val;
10932 for (i = 0; i != htab->plt_entry_size / 4; i++, ptr += 4)
10934 val = elf32_arm_vxworks_exec_plt_entry[i];
10935 if (i == 2)
10936 val |= got_address;
10937 if (i == 4)
10938 val |= 0xffffff & -((h->plt.offset + i * 4 + 8) >> 2);
10939 if (i == 5)
10940 val |= plt_index * RELOC_SIZE (htab);
10941 if (i == 2 || i == 5)
10942 bfd_put_32 (output_bfd, val, ptr);
10943 else
10944 put_arm_insn (htab, output_bfd, val, ptr);
10947 loc = (htab->srelplt2->contents
10948 + (plt_index * 2 + 1) * RELOC_SIZE (htab));
10950 /* Create the .rela.plt.unloaded R_ARM_ABS32 relocation
10951 referencing the GOT for this PLT entry. */
10952 rel.r_offset = plt_address + 8;
10953 rel.r_info = ELF32_R_INFO (htab->root.hgot->indx, R_ARM_ABS32);
10954 rel.r_addend = got_offset;
10955 SWAP_RELOC_OUT (htab) (output_bfd, &rel, loc);
10956 loc += RELOC_SIZE (htab);
10958 /* Create the R_ARM_ABS32 relocation referencing the
10959 beginning of the PLT for this GOT entry. */
10960 rel.r_offset = got_address;
10961 rel.r_info = ELF32_R_INFO (htab->root.hplt->indx, R_ARM_ABS32);
10962 rel.r_addend = 0;
10963 SWAP_RELOC_OUT (htab) (output_bfd, &rel, loc);
10965 else
10967 bfd_signed_vma thumb_refs;
10968 /* Calculate the displacement between the PLT slot and the
10969 entry in the GOT. The eight-byte offset accounts for the
10970 value produced by adding to pc in the first instruction
10971 of the PLT stub. */
10972 got_displacement = got_address - (plt_address + 8);
10974 BFD_ASSERT ((got_displacement & 0xf0000000) == 0);
10976 thumb_refs = eh->plt_thumb_refcount;
10977 if (!htab->use_blx)
10978 thumb_refs += eh->plt_maybe_thumb_refcount;
10980 if (thumb_refs > 0)
10982 put_thumb_insn (htab, output_bfd,
10983 elf32_arm_plt_thumb_stub[0], ptr - 4);
10984 put_thumb_insn (htab, output_bfd,
10985 elf32_arm_plt_thumb_stub[1], ptr - 2);
10988 put_arm_insn (htab, output_bfd,
10989 elf32_arm_plt_entry[0]
10990 | ((got_displacement & 0x0ff00000) >> 20),
10991 ptr + 0);
10992 put_arm_insn (htab, output_bfd,
10993 elf32_arm_plt_entry[1]
10994 | ((got_displacement & 0x000ff000) >> 12),
10995 ptr+ 4);
10996 put_arm_insn (htab, output_bfd,
10997 elf32_arm_plt_entry[2]
10998 | (got_displacement & 0x00000fff),
10999 ptr + 8);
11000 #ifdef FOUR_WORD_PLT
11001 bfd_put_32 (output_bfd, elf32_arm_plt_entry[3], ptr + 12);
11002 #endif
11005 /* Fill in the entry in the global offset table. */
11006 bfd_put_32 (output_bfd,
11007 (splt->output_section->vma
11008 + splt->output_offset),
11009 sgot->contents + got_offset);
11011 /* Fill in the entry in the .rel(a).plt section. */
11012 rel.r_addend = 0;
11013 rel.r_offset = got_address;
11014 rel.r_info = ELF32_R_INFO (h->dynindx, R_ARM_JUMP_SLOT);
11017 loc = srel->contents + plt_index * RELOC_SIZE (htab);
11018 SWAP_RELOC_OUT (htab) (output_bfd, &rel, loc);
11020 if (!h->def_regular)
11022 /* Mark the symbol as undefined, rather than as defined in
11023 the .plt section. Leave the value alone. */
11024 sym->st_shndx = SHN_UNDEF;
11025 /* If the symbol is weak, we do need to clear the value.
11026 Otherwise, the PLT entry would provide a definition for
11027 the symbol even if the symbol wasn't defined anywhere,
11028 and so the symbol would never be NULL. */
11029 if (!h->ref_regular_nonweak)
11030 sym->st_value = 0;
11034 if (h->got.offset != (bfd_vma) -1
11035 && (elf32_arm_hash_entry (h)->tls_type & GOT_TLS_GD) == 0
11036 && (elf32_arm_hash_entry (h)->tls_type & GOT_TLS_IE) == 0)
11038 asection * sgot;
11039 asection * srel;
11040 Elf_Internal_Rela rel;
11041 bfd_byte *loc;
11042 bfd_vma offset;
11044 /* This symbol has an entry in the global offset table. Set it
11045 up. */
11046 sgot = bfd_get_section_by_name (dynobj, ".got");
11047 srel = bfd_get_section_by_name (dynobj, RELOC_SECTION (htab, ".got"));
11048 BFD_ASSERT (sgot != NULL && srel != NULL);
11050 offset = (h->got.offset & ~(bfd_vma) 1);
11051 rel.r_addend = 0;
11052 rel.r_offset = (sgot->output_section->vma
11053 + sgot->output_offset
11054 + offset);
11056 /* If this is a static link, or it is a -Bsymbolic link and the
11057 symbol is defined locally or was forced to be local because
11058 of a version file, we just want to emit a RELATIVE reloc.
11059 The entry in the global offset table will already have been
11060 initialized in the relocate_section function. */
11061 if (info->shared
11062 && SYMBOL_REFERENCES_LOCAL (info, h))
11064 BFD_ASSERT ((h->got.offset & 1) != 0);
11065 rel.r_info = ELF32_R_INFO (0, R_ARM_RELATIVE);
11066 if (!htab->use_rel)
11068 rel.r_addend = bfd_get_32 (output_bfd, sgot->contents + offset);
11069 bfd_put_32 (output_bfd, (bfd_vma) 0, sgot->contents + offset);
11072 else
11074 BFD_ASSERT ((h->got.offset & 1) == 0);
11075 bfd_put_32 (output_bfd, (bfd_vma) 0, sgot->contents + offset);
11076 rel.r_info = ELF32_R_INFO (h->dynindx, R_ARM_GLOB_DAT);
11079 loc = srel->contents + srel->reloc_count++ * RELOC_SIZE (htab);
11080 SWAP_RELOC_OUT (htab) (output_bfd, &rel, loc);
11083 if (h->needs_copy)
11085 asection * s;
11086 Elf_Internal_Rela rel;
11087 bfd_byte *loc;
11089 /* This symbol needs a copy reloc. Set it up. */
11090 BFD_ASSERT (h->dynindx != -1
11091 && (h->root.type == bfd_link_hash_defined
11092 || h->root.type == bfd_link_hash_defweak));
11094 s = bfd_get_section_by_name (h->root.u.def.section->owner,
11095 RELOC_SECTION (htab, ".bss"));
11096 BFD_ASSERT (s != NULL);
11098 rel.r_addend = 0;
11099 rel.r_offset = (h->root.u.def.value
11100 + h->root.u.def.section->output_section->vma
11101 + h->root.u.def.section->output_offset);
11102 rel.r_info = ELF32_R_INFO (h->dynindx, R_ARM_COPY);
11103 loc = s->contents + s->reloc_count++ * RELOC_SIZE (htab);
11104 SWAP_RELOC_OUT (htab) (output_bfd, &rel, loc);
11107 /* Mark _DYNAMIC and _GLOBAL_OFFSET_TABLE_ as absolute. On VxWorks,
11108 the _GLOBAL_OFFSET_TABLE_ symbol is not absolute: it is relative
11109 to the ".got" section. */
11110 if (strcmp (h->root.root.string, "_DYNAMIC") == 0
11111 || (!htab->vxworks_p && h == htab->root.hgot))
11112 sym->st_shndx = SHN_ABS;
11114 return TRUE;
11117 /* Finish up the dynamic sections. */
11119 static bfd_boolean
11120 elf32_arm_finish_dynamic_sections (bfd * output_bfd, struct bfd_link_info * info)
11122 bfd * dynobj;
11123 asection * sgot;
11124 asection * sdyn;
11126 dynobj = elf_hash_table (info)->dynobj;
11128 sgot = bfd_get_section_by_name (dynobj, ".got.plt");
11129 BFD_ASSERT (elf32_arm_hash_table (info)->symbian_p || sgot != NULL);
11130 sdyn = bfd_get_section_by_name (dynobj, ".dynamic");
11132 if (elf_hash_table (info)->dynamic_sections_created)
11134 asection *splt;
11135 Elf32_External_Dyn *dyncon, *dynconend;
11136 struct elf32_arm_link_hash_table *htab;
11138 htab = elf32_arm_hash_table (info);
11139 splt = bfd_get_section_by_name (dynobj, ".plt");
11140 BFD_ASSERT (splt != NULL && sdyn != NULL);
11142 dyncon = (Elf32_External_Dyn *) sdyn->contents;
11143 dynconend = (Elf32_External_Dyn *) (sdyn->contents + sdyn->size);
11145 for (; dyncon < dynconend; dyncon++)
11147 Elf_Internal_Dyn dyn;
11148 const char * name;
11149 asection * s;
11151 bfd_elf32_swap_dyn_in (dynobj, dyncon, &dyn);
11153 switch (dyn.d_tag)
11155 unsigned int type;
11157 default:
11158 if (htab->vxworks_p
11159 && elf_vxworks_finish_dynamic_entry (output_bfd, &dyn))
11160 bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon);
11161 break;
11163 case DT_HASH:
11164 name = ".hash";
11165 goto get_vma_if_bpabi;
11166 case DT_STRTAB:
11167 name = ".dynstr";
11168 goto get_vma_if_bpabi;
11169 case DT_SYMTAB:
11170 name = ".dynsym";
11171 goto get_vma_if_bpabi;
11172 case DT_VERSYM:
11173 name = ".gnu.version";
11174 goto get_vma_if_bpabi;
11175 case DT_VERDEF:
11176 name = ".gnu.version_d";
11177 goto get_vma_if_bpabi;
11178 case DT_VERNEED:
11179 name = ".gnu.version_r";
11180 goto get_vma_if_bpabi;
11182 case DT_PLTGOT:
11183 name = ".got";
11184 goto get_vma;
11185 case DT_JMPREL:
11186 name = RELOC_SECTION (htab, ".plt");
11187 get_vma:
11188 s = bfd_get_section_by_name (output_bfd, name);
11189 BFD_ASSERT (s != NULL);
11190 if (!htab->symbian_p)
11191 dyn.d_un.d_ptr = s->vma;
11192 else
11193 /* In the BPABI, tags in the PT_DYNAMIC section point
11194 at the file offset, not the memory address, for the
11195 convenience of the post linker. */
11196 dyn.d_un.d_ptr = s->filepos;
11197 bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon);
11198 break;
11200 get_vma_if_bpabi:
11201 if (htab->symbian_p)
11202 goto get_vma;
11203 break;
11205 case DT_PLTRELSZ:
11206 s = bfd_get_section_by_name (output_bfd,
11207 RELOC_SECTION (htab, ".plt"));
11208 BFD_ASSERT (s != NULL);
11209 dyn.d_un.d_val = s->size;
11210 bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon);
11211 break;
11213 case DT_RELSZ:
11214 case DT_RELASZ:
11215 if (!htab->symbian_p)
11217 /* My reading of the SVR4 ABI indicates that the
11218 procedure linkage table relocs (DT_JMPREL) should be
11219 included in the overall relocs (DT_REL). This is
11220 what Solaris does. However, UnixWare can not handle
11221 that case. Therefore, we override the DT_RELSZ entry
11222 here to make it not include the JMPREL relocs. Since
11223 the linker script arranges for .rel(a).plt to follow all
11224 other relocation sections, we don't have to worry
11225 about changing the DT_REL entry. */
11226 s = bfd_get_section_by_name (output_bfd,
11227 RELOC_SECTION (htab, ".plt"));
11228 if (s != NULL)
11229 dyn.d_un.d_val -= s->size;
11230 bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon);
11231 break;
11233 /* Fall through. */
11235 case DT_REL:
11236 case DT_RELA:
11237 /* In the BPABI, the DT_REL tag must point at the file
11238 offset, not the VMA, of the first relocation
11239 section. So, we use code similar to that in
11240 elflink.c, but do not check for SHF_ALLOC on the
11241 relcoation section, since relocations sections are
11242 never allocated under the BPABI. The comments above
11243 about Unixware notwithstanding, we include all of the
11244 relocations here. */
11245 if (htab->symbian_p)
11247 unsigned int i;
11248 type = ((dyn.d_tag == DT_REL || dyn.d_tag == DT_RELSZ)
11249 ? SHT_REL : SHT_RELA);
11250 dyn.d_un.d_val = 0;
11251 for (i = 1; i < elf_numsections (output_bfd); i++)
11253 Elf_Internal_Shdr *hdr
11254 = elf_elfsections (output_bfd)[i];
11255 if (hdr->sh_type == type)
11257 if (dyn.d_tag == DT_RELSZ
11258 || dyn.d_tag == DT_RELASZ)
11259 dyn.d_un.d_val += hdr->sh_size;
11260 else if ((ufile_ptr) hdr->sh_offset
11261 <= dyn.d_un.d_val - 1)
11262 dyn.d_un.d_val = hdr->sh_offset;
11265 bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon);
11267 break;
11269 /* Set the bottom bit of DT_INIT/FINI if the
11270 corresponding function is Thumb. */
11271 case DT_INIT:
11272 name = info->init_function;
11273 goto get_sym;
11274 case DT_FINI:
11275 name = info->fini_function;
11276 get_sym:
11277 /* If it wasn't set by elf_bfd_final_link
11278 then there is nothing to adjust. */
11279 if (dyn.d_un.d_val != 0)
11281 struct elf_link_hash_entry * eh;
11283 eh = elf_link_hash_lookup (elf_hash_table (info), name,
11284 FALSE, FALSE, TRUE);
11285 if (eh != NULL
11286 && ELF_ST_TYPE (eh->type) == STT_ARM_TFUNC)
11288 dyn.d_un.d_val |= 1;
11289 bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon);
11292 break;
11296 /* Fill in the first entry in the procedure linkage table. */
11297 if (splt->size > 0 && elf32_arm_hash_table (info)->plt_header_size)
11299 const bfd_vma *plt0_entry;
11300 bfd_vma got_address, plt_address, got_displacement;
11302 /* Calculate the addresses of the GOT and PLT. */
11303 got_address = sgot->output_section->vma + sgot->output_offset;
11304 plt_address = splt->output_section->vma + splt->output_offset;
11306 if (htab->vxworks_p)
11308 /* The VxWorks GOT is relocated by the dynamic linker.
11309 Therefore, we must emit relocations rather than simply
11310 computing the values now. */
11311 Elf_Internal_Rela rel;
11313 plt0_entry = elf32_arm_vxworks_exec_plt0_entry;
11314 put_arm_insn (htab, output_bfd, plt0_entry[0],
11315 splt->contents + 0);
11316 put_arm_insn (htab, output_bfd, plt0_entry[1],
11317 splt->contents + 4);
11318 put_arm_insn (htab, output_bfd, plt0_entry[2],
11319 splt->contents + 8);
11320 bfd_put_32 (output_bfd, got_address, splt->contents + 12);
11322 /* Generate a relocation for _GLOBAL_OFFSET_TABLE_. */
11323 rel.r_offset = plt_address + 12;
11324 rel.r_info = ELF32_R_INFO (htab->root.hgot->indx, R_ARM_ABS32);
11325 rel.r_addend = 0;
11326 SWAP_RELOC_OUT (htab) (output_bfd, &rel,
11327 htab->srelplt2->contents);
11329 else
11331 got_displacement = got_address - (plt_address + 16);
11333 plt0_entry = elf32_arm_plt0_entry;
11334 put_arm_insn (htab, output_bfd, plt0_entry[0],
11335 splt->contents + 0);
11336 put_arm_insn (htab, output_bfd, plt0_entry[1],
11337 splt->contents + 4);
11338 put_arm_insn (htab, output_bfd, plt0_entry[2],
11339 splt->contents + 8);
11340 put_arm_insn (htab, output_bfd, plt0_entry[3],
11341 splt->contents + 12);
11343 #ifdef FOUR_WORD_PLT
11344 /* The displacement value goes in the otherwise-unused
11345 last word of the second entry. */
11346 bfd_put_32 (output_bfd, got_displacement, splt->contents + 28);
11347 #else
11348 bfd_put_32 (output_bfd, got_displacement, splt->contents + 16);
11349 #endif
11353 /* UnixWare sets the entsize of .plt to 4, although that doesn't
11354 really seem like the right value. */
11355 if (splt->output_section->owner == output_bfd)
11356 elf_section_data (splt->output_section)->this_hdr.sh_entsize = 4;
11358 if (htab->vxworks_p && !info->shared && htab->splt->size > 0)
11360 /* Correct the .rel(a).plt.unloaded relocations. They will have
11361 incorrect symbol indexes. */
11362 int num_plts;
11363 unsigned char *p;
11365 num_plts = ((htab->splt->size - htab->plt_header_size)
11366 / htab->plt_entry_size);
11367 p = htab->srelplt2->contents + RELOC_SIZE (htab);
11369 for (; num_plts; num_plts--)
11371 Elf_Internal_Rela rel;
11373 SWAP_RELOC_IN (htab) (output_bfd, p, &rel);
11374 rel.r_info = ELF32_R_INFO (htab->root.hgot->indx, R_ARM_ABS32);
11375 SWAP_RELOC_OUT (htab) (output_bfd, &rel, p);
11376 p += RELOC_SIZE (htab);
11378 SWAP_RELOC_IN (htab) (output_bfd, p, &rel);
11379 rel.r_info = ELF32_R_INFO (htab->root.hplt->indx, R_ARM_ABS32);
11380 SWAP_RELOC_OUT (htab) (output_bfd, &rel, p);
11381 p += RELOC_SIZE (htab);
11386 /* Fill in the first three entries in the global offset table. */
11387 if (sgot)
11389 if (sgot->size > 0)
11391 if (sdyn == NULL)
11392 bfd_put_32 (output_bfd, (bfd_vma) 0, sgot->contents);
11393 else
11394 bfd_put_32 (output_bfd,
11395 sdyn->output_section->vma + sdyn->output_offset,
11396 sgot->contents);
11397 bfd_put_32 (output_bfd, (bfd_vma) 0, sgot->contents + 4);
11398 bfd_put_32 (output_bfd, (bfd_vma) 0, sgot->contents + 8);
11401 elf_section_data (sgot->output_section)->this_hdr.sh_entsize = 4;
11404 return TRUE;
11407 static void
11408 elf32_arm_post_process_headers (bfd * abfd, struct bfd_link_info * link_info ATTRIBUTE_UNUSED)
11410 Elf_Internal_Ehdr * i_ehdrp; /* ELF file header, internal form. */
11411 struct elf32_arm_link_hash_table *globals;
11413 i_ehdrp = elf_elfheader (abfd);
11415 if (EF_ARM_EABI_VERSION (i_ehdrp->e_flags) == EF_ARM_EABI_UNKNOWN)
11416 i_ehdrp->e_ident[EI_OSABI] = ELFOSABI_ARM;
11417 else
11418 i_ehdrp->e_ident[EI_OSABI] = 0;
11419 i_ehdrp->e_ident[EI_ABIVERSION] = ARM_ELF_ABI_VERSION;
11421 if (link_info)
11423 globals = elf32_arm_hash_table (link_info);
11424 if (globals->byteswap_code)
11425 i_ehdrp->e_flags |= EF_ARM_BE8;
11429 static enum elf_reloc_type_class
11430 elf32_arm_reloc_type_class (const Elf_Internal_Rela *rela)
11432 switch ((int) ELF32_R_TYPE (rela->r_info))
11434 case R_ARM_RELATIVE:
11435 return reloc_class_relative;
11436 case R_ARM_JUMP_SLOT:
11437 return reloc_class_plt;
11438 case R_ARM_COPY:
11439 return reloc_class_copy;
11440 default:
11441 return reloc_class_normal;
11445 /* Set the right machine number for an Arm ELF file. */
11447 static bfd_boolean
11448 elf32_arm_section_flags (flagword *flags, const Elf_Internal_Shdr *hdr)
11450 if (hdr->sh_type == SHT_NOTE)
11451 *flags |= SEC_LINK_ONCE | SEC_LINK_DUPLICATES_SAME_CONTENTS;
11453 return TRUE;
11456 static void
11457 elf32_arm_final_write_processing (bfd *abfd, bfd_boolean linker ATTRIBUTE_UNUSED)
11459 bfd_arm_update_notes (abfd, ARM_NOTE_SECTION);
11462 /* Return TRUE if this is an unwinding table entry. */
11464 static bfd_boolean
11465 is_arm_elf_unwind_section_name (bfd * abfd ATTRIBUTE_UNUSED, const char * name)
11467 return (CONST_STRNEQ (name, ELF_STRING_ARM_unwind)
11468 || CONST_STRNEQ (name, ELF_STRING_ARM_unwind_once));
11472 /* Set the type and flags for an ARM section. We do this by
11473 the section name, which is a hack, but ought to work. */
11475 static bfd_boolean
11476 elf32_arm_fake_sections (bfd * abfd, Elf_Internal_Shdr * hdr, asection * sec)
11478 const char * name;
11480 name = bfd_get_section_name (abfd, sec);
11482 if (is_arm_elf_unwind_section_name (abfd, name))
11484 hdr->sh_type = SHT_ARM_EXIDX;
11485 hdr->sh_flags |= SHF_LINK_ORDER;
11487 return TRUE;
11490 /* Handle an ARM specific section when reading an object file. This is
11491 called when bfd_section_from_shdr finds a section with an unknown
11492 type. */
11494 static bfd_boolean
11495 elf32_arm_section_from_shdr (bfd *abfd,
11496 Elf_Internal_Shdr * hdr,
11497 const char *name,
11498 int shindex)
11500 /* There ought to be a place to keep ELF backend specific flags, but
11501 at the moment there isn't one. We just keep track of the
11502 sections by their name, instead. Fortunately, the ABI gives
11503 names for all the ARM specific sections, so we will probably get
11504 away with this. */
11505 switch (hdr->sh_type)
11507 case SHT_ARM_EXIDX:
11508 case SHT_ARM_PREEMPTMAP:
11509 case SHT_ARM_ATTRIBUTES:
11510 break;
11512 default:
11513 return FALSE;
11516 if (! _bfd_elf_make_section_from_shdr (abfd, hdr, name, shindex))
11517 return FALSE;
11519 return TRUE;
11522 /* A structure used to record a list of sections, independently
11523 of the next and prev fields in the asection structure. */
11524 typedef struct section_list
11526 asection * sec;
11527 struct section_list * next;
11528 struct section_list * prev;
11530 section_list;
11532 /* Unfortunately we need to keep a list of sections for which
11533 an _arm_elf_section_data structure has been allocated. This
11534 is because it is possible for functions like elf32_arm_write_section
11535 to be called on a section which has had an elf_data_structure
11536 allocated for it (and so the used_by_bfd field is valid) but
11537 for which the ARM extended version of this structure - the
11538 _arm_elf_section_data structure - has not been allocated. */
11539 static section_list * sections_with_arm_elf_section_data = NULL;
11541 static void
11542 record_section_with_arm_elf_section_data (asection * sec)
11544 struct section_list * entry;
11546 entry = bfd_malloc (sizeof (* entry));
11547 if (entry == NULL)
11548 return;
11549 entry->sec = sec;
11550 entry->next = sections_with_arm_elf_section_data;
11551 entry->prev = NULL;
11552 if (entry->next != NULL)
11553 entry->next->prev = entry;
11554 sections_with_arm_elf_section_data = entry;
11557 static struct section_list *
11558 find_arm_elf_section_entry (asection * sec)
11560 struct section_list * entry;
11561 static struct section_list * last_entry = NULL;
11563 /* This is a short cut for the typical case where the sections are added
11564 to the sections_with_arm_elf_section_data list in forward order and
11565 then looked up here in backwards order. This makes a real difference
11566 to the ld-srec/sec64k.exp linker test. */
11567 entry = sections_with_arm_elf_section_data;
11568 if (last_entry != NULL)
11570 if (last_entry->sec == sec)
11571 entry = last_entry;
11572 else if (last_entry->next != NULL
11573 && last_entry->next->sec == sec)
11574 entry = last_entry->next;
11577 for (; entry; entry = entry->next)
11578 if (entry->sec == sec)
11579 break;
11581 if (entry)
11582 /* Record the entry prior to this one - it is the entry we are most
11583 likely to want to locate next time. Also this way if we have been
11584 called from unrecord_section_with_arm_elf_section_data() we will not
11585 be caching a pointer that is about to be freed. */
11586 last_entry = entry->prev;
11588 return entry;
11591 static _arm_elf_section_data *
11592 get_arm_elf_section_data (asection * sec)
11594 struct section_list * entry;
11596 entry = find_arm_elf_section_entry (sec);
11598 if (entry)
11599 return elf32_arm_section_data (entry->sec);
11600 else
11601 return NULL;
11604 static void
11605 unrecord_section_with_arm_elf_section_data (asection * sec)
11607 struct section_list * entry;
11609 entry = find_arm_elf_section_entry (sec);
11611 if (entry)
11613 if (entry->prev != NULL)
11614 entry->prev->next = entry->next;
11615 if (entry->next != NULL)
11616 entry->next->prev = entry->prev;
11617 if (entry == sections_with_arm_elf_section_data)
11618 sections_with_arm_elf_section_data = entry->next;
11619 free (entry);
11624 typedef struct
11626 void *finfo;
11627 struct bfd_link_info *info;
11628 asection *sec;
11629 int sec_shndx;
11630 bfd_boolean (*func) (void *, const char *, Elf_Internal_Sym *,
11631 asection *, struct elf_link_hash_entry *);
11632 } output_arch_syminfo;
11634 enum map_symbol_type
11636 ARM_MAP_ARM,
11637 ARM_MAP_THUMB,
11638 ARM_MAP_DATA
11642 /* Output a single mapping symbol. */
11644 static bfd_boolean
11645 elf32_arm_output_map_sym (output_arch_syminfo *osi,
11646 enum map_symbol_type type,
11647 bfd_vma offset)
11649 static const char *names[3] = {"$a", "$t", "$d"};
11650 struct elf32_arm_link_hash_table *htab;
11651 Elf_Internal_Sym sym;
11653 htab = elf32_arm_hash_table (osi->info);
11654 sym.st_value = osi->sec->output_section->vma
11655 + osi->sec->output_offset
11656 + offset;
11657 sym.st_size = 0;
11658 sym.st_other = 0;
11659 sym.st_info = ELF_ST_INFO (STB_LOCAL, STT_NOTYPE);
11660 sym.st_shndx = osi->sec_shndx;
11661 if (!osi->func (osi->finfo, names[type], &sym, osi->sec, NULL))
11662 return FALSE;
11663 return TRUE;
11667 /* Output mapping symbols for PLT entries associated with H. */
11669 static bfd_boolean
11670 elf32_arm_output_plt_map (struct elf_link_hash_entry *h, void *inf)
11672 output_arch_syminfo *osi = (output_arch_syminfo *) inf;
11673 struct elf32_arm_link_hash_table *htab;
11674 struct elf32_arm_link_hash_entry *eh;
11675 bfd_vma addr;
11677 htab = elf32_arm_hash_table (osi->info);
11679 if (h->root.type == bfd_link_hash_indirect)
11680 return TRUE;
11682 if (h->root.type == bfd_link_hash_warning)
11683 /* When warning symbols are created, they **replace** the "real"
11684 entry in the hash table, thus we never get to see the real
11685 symbol in a hash traversal. So look at it now. */
11686 h = (struct elf_link_hash_entry *) h->root.u.i.link;
11688 if (h->plt.offset == (bfd_vma) -1)
11689 return TRUE;
11691 eh = (struct elf32_arm_link_hash_entry *) h;
11692 addr = h->plt.offset;
11693 if (htab->symbian_p)
11695 if (!elf32_arm_output_map_sym (osi, ARM_MAP_ARM, addr))
11696 return FALSE;
11697 if (!elf32_arm_output_map_sym (osi, ARM_MAP_DATA, addr + 4))
11698 return FALSE;
11700 else if (htab->vxworks_p)
11702 if (!elf32_arm_output_map_sym (osi, ARM_MAP_ARM, addr))
11703 return FALSE;
11704 if (!elf32_arm_output_map_sym (osi, ARM_MAP_DATA, addr + 8))
11705 return FALSE;
11706 if (!elf32_arm_output_map_sym (osi, ARM_MAP_ARM, addr + 12))
11707 return FALSE;
11708 if (!elf32_arm_output_map_sym (osi, ARM_MAP_DATA, addr + 20))
11709 return FALSE;
11711 else
11713 bfd_signed_vma thumb_refs;
11715 thumb_refs = eh->plt_thumb_refcount;
11716 if (!htab->use_blx)
11717 thumb_refs += eh->plt_maybe_thumb_refcount;
11719 if (thumb_refs > 0)
11721 if (!elf32_arm_output_map_sym (osi, ARM_MAP_THUMB, addr - 4))
11722 return FALSE;
11724 #ifdef FOUR_WORD_PLT
11725 if (!elf32_arm_output_map_sym (osi, ARM_MAP_ARM, addr))
11726 return FALSE;
11727 if (!elf32_arm_output_map_sym (osi, ARM_MAP_DATA, addr + 12))
11728 return FALSE;
11729 #else
11730 /* A three-word PLT with no Thumb thunk contains only Arm code,
11731 so only need to output a mapping symbol for the first PLT entry and
11732 entries with thumb thunks. */
11733 if (thumb_refs > 0 || addr == 20)
11735 if (!elf32_arm_output_map_sym (osi, ARM_MAP_ARM, addr))
11736 return FALSE;
11738 #endif
11741 return TRUE;
11744 /* Output a single local symbol for a generated stub. */
11746 static bfd_boolean
11747 elf32_arm_output_stub_sym (output_arch_syminfo *osi, const char *name,
11748 bfd_vma offset, bfd_vma size)
11750 struct elf32_arm_link_hash_table *htab;
11751 Elf_Internal_Sym sym;
11753 htab = elf32_arm_hash_table (osi->info);
11754 sym.st_value = osi->sec->output_section->vma
11755 + osi->sec->output_offset
11756 + offset;
11757 sym.st_size = size;
11758 sym.st_other = 0;
11759 sym.st_info = ELF_ST_INFO (STB_LOCAL, STT_FUNC);
11760 sym.st_shndx = osi->sec_shndx;
11761 if (!osi->func (osi->finfo, name, &sym, osi->sec, NULL))
11762 return FALSE;
11763 return TRUE;
11766 static bfd_boolean
11767 arm_map_one_stub (struct bfd_hash_entry * gen_entry,
11768 void * in_arg)
11770 struct elf32_arm_stub_hash_entry *stub_entry;
11771 struct bfd_link_info *info;
11772 struct elf32_arm_link_hash_table *htab;
11773 asection *stub_sec;
11774 bfd_vma addr;
11775 char *stub_name;
11776 output_arch_syminfo *osi;
11777 const insn_sequence *template;
11778 enum stub_insn_type prev_type;
11779 int size;
11780 int i;
11781 enum map_symbol_type sym_type;
11783 /* Massage our args to the form they really have. */
11784 stub_entry = (struct elf32_arm_stub_hash_entry *) gen_entry;
11785 osi = (output_arch_syminfo *) in_arg;
11787 info = osi->info;
11789 htab = elf32_arm_hash_table (info);
11790 stub_sec = stub_entry->stub_sec;
11792 /* Ensure this stub is attached to the current section being
11793 processed. */
11794 if (stub_sec != osi->sec)
11795 return TRUE;
11797 addr = (bfd_vma) stub_entry->stub_offset;
11798 stub_name = stub_entry->output_name;
11800 template = stub_entry->stub_template;
11801 switch (template[0].type)
11803 case ARM_TYPE:
11804 if (!elf32_arm_output_stub_sym (osi, stub_name, addr, stub_entry->stub_size))
11805 return FALSE;
11806 break;
11807 case THUMB16_TYPE:
11808 if (!elf32_arm_output_stub_sym (osi, stub_name, addr | 1,
11809 stub_entry->stub_size))
11810 return FALSE;
11811 break;
11812 default:
11813 BFD_FAIL ();
11814 return FALSE;
11817 prev_type = DATA_TYPE;
11818 size = 0;
11819 for (i = 0; i < stub_entry->stub_template_size; i++)
11821 switch (template[i].type)
11823 case ARM_TYPE:
11824 sym_type = ARM_MAP_ARM;
11825 break;
11827 case THUMB16_TYPE:
11828 sym_type = ARM_MAP_THUMB;
11829 break;
11831 case DATA_TYPE:
11832 sym_type = ARM_MAP_DATA;
11833 break;
11835 default:
11836 BFD_FAIL ();
11837 return FALSE;
11840 if (template[i].type != prev_type)
11842 prev_type = template[i].type;
11843 if (!elf32_arm_output_map_sym (osi, sym_type, addr + size))
11844 return FALSE;
11847 switch (template[i].type)
11849 case ARM_TYPE:
11850 size += 4;
11851 break;
11853 case THUMB16_TYPE:
11854 size += 2;
11855 break;
11857 case DATA_TYPE:
11858 size += 4;
11859 break;
11861 default:
11862 BFD_FAIL ();
11863 return FALSE;
11867 return TRUE;
11870 /* Output mapping symbols for linker generated sections. */
11872 static bfd_boolean
11873 elf32_arm_output_arch_local_syms (bfd *output_bfd,
11874 struct bfd_link_info *info,
11875 void *finfo,
11876 bfd_boolean (*func) (void *, const char *,
11877 Elf_Internal_Sym *,
11878 asection *,
11879 struct elf_link_hash_entry *))
11881 output_arch_syminfo osi;
11882 struct elf32_arm_link_hash_table *htab;
11883 bfd_vma offset;
11884 bfd_size_type size;
11886 htab = elf32_arm_hash_table (info);
11887 check_use_blx (htab);
11889 osi.finfo = finfo;
11890 osi.info = info;
11891 osi.func = func;
11893 /* ARM->Thumb glue. */
11894 if (htab->arm_glue_size > 0)
11896 osi.sec = bfd_get_section_by_name (htab->bfd_of_glue_owner,
11897 ARM2THUMB_GLUE_SECTION_NAME);
11899 osi.sec_shndx = _bfd_elf_section_from_bfd_section
11900 (output_bfd, osi.sec->output_section);
11901 if (info->shared || htab->root.is_relocatable_executable
11902 || htab->pic_veneer)
11903 size = ARM2THUMB_PIC_GLUE_SIZE;
11904 else if (htab->use_blx)
11905 size = ARM2THUMB_V5_STATIC_GLUE_SIZE;
11906 else
11907 size = ARM2THUMB_STATIC_GLUE_SIZE;
11909 for (offset = 0; offset < htab->arm_glue_size; offset += size)
11911 elf32_arm_output_map_sym (&osi, ARM_MAP_ARM, offset);
11912 elf32_arm_output_map_sym (&osi, ARM_MAP_DATA, offset + size - 4);
11916 /* Thumb->ARM glue. */
11917 if (htab->thumb_glue_size > 0)
11919 osi.sec = bfd_get_section_by_name (htab->bfd_of_glue_owner,
11920 THUMB2ARM_GLUE_SECTION_NAME);
11922 osi.sec_shndx = _bfd_elf_section_from_bfd_section
11923 (output_bfd, osi.sec->output_section);
11924 size = THUMB2ARM_GLUE_SIZE;
11926 for (offset = 0; offset < htab->thumb_glue_size; offset += size)
11928 elf32_arm_output_map_sym (&osi, ARM_MAP_THUMB, offset);
11929 elf32_arm_output_map_sym (&osi, ARM_MAP_ARM, offset + 4);
11933 /* ARMv4 BX veneers. */
11934 if (htab->bx_glue_size > 0)
11936 osi.sec = bfd_get_section_by_name (htab->bfd_of_glue_owner,
11937 ARM_BX_GLUE_SECTION_NAME);
11939 osi.sec_shndx = _bfd_elf_section_from_bfd_section
11940 (output_bfd, osi.sec->output_section);
11942 elf32_arm_output_map_sym (&osi, ARM_MAP_ARM, 0);
11945 /* Long calls stubs. */
11946 if (htab->stub_bfd && htab->stub_bfd->sections)
11948 asection* stub_sec;
11950 for (stub_sec = htab->stub_bfd->sections;
11951 stub_sec != NULL;
11952 stub_sec = stub_sec->next)
11954 /* Ignore non-stub sections. */
11955 if (!strstr (stub_sec->name, STUB_SUFFIX))
11956 continue;
11958 osi.sec = stub_sec;
11960 osi.sec_shndx = _bfd_elf_section_from_bfd_section
11961 (output_bfd, osi.sec->output_section);
11963 bfd_hash_traverse (&htab->stub_hash_table, arm_map_one_stub, &osi);
11967 /* Finally, output mapping symbols for the PLT. */
11968 if (!htab->splt || htab->splt->size == 0)
11969 return TRUE;
11971 osi.sec_shndx = _bfd_elf_section_from_bfd_section (output_bfd,
11972 htab->splt->output_section);
11973 osi.sec = htab->splt;
11974 /* Output mapping symbols for the plt header. SymbianOS does not have a
11975 plt header. */
11976 if (htab->vxworks_p)
11978 /* VxWorks shared libraries have no PLT header. */
11979 if (!info->shared)
11981 if (!elf32_arm_output_map_sym (&osi, ARM_MAP_ARM, 0))
11982 return FALSE;
11983 if (!elf32_arm_output_map_sym (&osi, ARM_MAP_DATA, 12))
11984 return FALSE;
11987 else if (!htab->symbian_p)
11989 if (!elf32_arm_output_map_sym (&osi, ARM_MAP_ARM, 0))
11990 return FALSE;
11991 #ifndef FOUR_WORD_PLT
11992 if (!elf32_arm_output_map_sym (&osi, ARM_MAP_DATA, 16))
11993 return FALSE;
11994 #endif
11997 elf_link_hash_traverse (&htab->root, elf32_arm_output_plt_map, (void *) &osi);
11998 return TRUE;
12001 /* Allocate target specific section data. */
12003 static bfd_boolean
12004 elf32_arm_new_section_hook (bfd *abfd, asection *sec)
12006 if (!sec->used_by_bfd)
12008 _arm_elf_section_data *sdata;
12009 bfd_size_type amt = sizeof (*sdata);
12011 sdata = bfd_zalloc (abfd, amt);
12012 if (sdata == NULL)
12013 return FALSE;
12014 sec->used_by_bfd = sdata;
12017 record_section_with_arm_elf_section_data (sec);
12019 return _bfd_elf_new_section_hook (abfd, sec);
12023 /* Used to order a list of mapping symbols by address. */
12025 static int
12026 elf32_arm_compare_mapping (const void * a, const void * b)
12028 const elf32_arm_section_map *amap = (const elf32_arm_section_map *) a;
12029 const elf32_arm_section_map *bmap = (const elf32_arm_section_map *) b;
12031 if (amap->vma > bmap->vma)
12032 return 1;
12033 else if (amap->vma < bmap->vma)
12034 return -1;
12035 else if (amap->type > bmap->type)
12036 /* Ensure results do not depend on the host qsort for objects with
12037 multiple mapping symbols at the same address by sorting on type
12038 after vma. */
12039 return 1;
12040 else if (amap->type < bmap->type)
12041 return -1;
12042 else
12043 return 0;
12047 /* Do code byteswapping. Return FALSE afterwards so that the section is
12048 written out as normal. */
12050 static bfd_boolean
12051 elf32_arm_write_section (bfd *output_bfd,
12052 struct bfd_link_info *link_info,
12053 asection *sec,
12054 bfd_byte *contents)
12056 int mapcount, errcount;
12057 _arm_elf_section_data *arm_data;
12058 struct elf32_arm_link_hash_table *globals = elf32_arm_hash_table (link_info);
12059 elf32_arm_section_map *map;
12060 elf32_vfp11_erratum_list *errnode;
12061 bfd_vma ptr;
12062 bfd_vma end;
12063 bfd_vma offset = sec->output_section->vma + sec->output_offset;
12064 bfd_byte tmp;
12065 int i;
12067 /* If this section has not been allocated an _arm_elf_section_data
12068 structure then we cannot record anything. */
12069 arm_data = get_arm_elf_section_data (sec);
12070 if (arm_data == NULL)
12071 return FALSE;
12073 mapcount = arm_data->mapcount;
12074 map = arm_data->map;
12075 errcount = arm_data->erratumcount;
12077 if (errcount != 0)
12079 unsigned int endianflip = bfd_big_endian (output_bfd) ? 3 : 0;
12081 for (errnode = arm_data->erratumlist; errnode != 0;
12082 errnode = errnode->next)
12084 bfd_vma index = errnode->vma - offset;
12086 switch (errnode->type)
12088 case VFP11_ERRATUM_BRANCH_TO_ARM_VENEER:
12090 bfd_vma branch_to_veneer;
12091 /* Original condition code of instruction, plus bit mask for
12092 ARM B instruction. */
12093 unsigned int insn = (errnode->u.b.vfp_insn & 0xf0000000)
12094 | 0x0a000000;
12096 /* The instruction is before the label. */
12097 index -= 4;
12099 /* Above offset included in -4 below. */
12100 branch_to_veneer = errnode->u.b.veneer->vma
12101 - errnode->vma - 4;
12103 if ((signed) branch_to_veneer < -(1 << 25)
12104 || (signed) branch_to_veneer >= (1 << 25))
12105 (*_bfd_error_handler) (_("%B: error: VFP11 veneer out of "
12106 "range"), output_bfd);
12108 insn |= (branch_to_veneer >> 2) & 0xffffff;
12109 contents[endianflip ^ index] = insn & 0xff;
12110 contents[endianflip ^ (index + 1)] = (insn >> 8) & 0xff;
12111 contents[endianflip ^ (index + 2)] = (insn >> 16) & 0xff;
12112 contents[endianflip ^ (index + 3)] = (insn >> 24) & 0xff;
12114 break;
12116 case VFP11_ERRATUM_ARM_VENEER:
12118 bfd_vma branch_from_veneer;
12119 unsigned int insn;
12121 /* Take size of veneer into account. */
12122 branch_from_veneer = errnode->u.v.branch->vma
12123 - errnode->vma - 12;
12125 if ((signed) branch_from_veneer < -(1 << 25)
12126 || (signed) branch_from_veneer >= (1 << 25))
12127 (*_bfd_error_handler) (_("%B: error: VFP11 veneer out of "
12128 "range"), output_bfd);
12130 /* Original instruction. */
12131 insn = errnode->u.v.branch->u.b.vfp_insn;
12132 contents[endianflip ^ index] = insn & 0xff;
12133 contents[endianflip ^ (index + 1)] = (insn >> 8) & 0xff;
12134 contents[endianflip ^ (index + 2)] = (insn >> 16) & 0xff;
12135 contents[endianflip ^ (index + 3)] = (insn >> 24) & 0xff;
12137 /* Branch back to insn after original insn. */
12138 insn = 0xea000000 | ((branch_from_veneer >> 2) & 0xffffff);
12139 contents[endianflip ^ (index + 4)] = insn & 0xff;
12140 contents[endianflip ^ (index + 5)] = (insn >> 8) & 0xff;
12141 contents[endianflip ^ (index + 6)] = (insn >> 16) & 0xff;
12142 contents[endianflip ^ (index + 7)] = (insn >> 24) & 0xff;
12144 break;
12146 default:
12147 abort ();
12152 if (mapcount == 0)
12153 return FALSE;
12155 if (globals->byteswap_code)
12157 qsort (map, mapcount, sizeof (* map), elf32_arm_compare_mapping);
12159 ptr = map[0].vma;
12160 for (i = 0; i < mapcount; i++)
12162 if (i == mapcount - 1)
12163 end = sec->size;
12164 else
12165 end = map[i + 1].vma;
12167 switch (map[i].type)
12169 case 'a':
12170 /* Byte swap code words. */
12171 while (ptr + 3 < end)
12173 tmp = contents[ptr];
12174 contents[ptr] = contents[ptr + 3];
12175 contents[ptr + 3] = tmp;
12176 tmp = contents[ptr + 1];
12177 contents[ptr + 1] = contents[ptr + 2];
12178 contents[ptr + 2] = tmp;
12179 ptr += 4;
12181 break;
12183 case 't':
12184 /* Byte swap code halfwords. */
12185 while (ptr + 1 < end)
12187 tmp = contents[ptr];
12188 contents[ptr] = contents[ptr + 1];
12189 contents[ptr + 1] = tmp;
12190 ptr += 2;
12192 break;
12194 case 'd':
12195 /* Leave data alone. */
12196 break;
12198 ptr = end;
12202 free (map);
12203 arm_data->mapcount = 0;
12204 arm_data->mapsize = 0;
12205 arm_data->map = NULL;
12206 unrecord_section_with_arm_elf_section_data (sec);
12208 return FALSE;
12211 static void
12212 unrecord_section_via_map_over_sections (bfd * abfd ATTRIBUTE_UNUSED,
12213 asection * sec,
12214 void * ignore ATTRIBUTE_UNUSED)
12216 unrecord_section_with_arm_elf_section_data (sec);
12219 static bfd_boolean
12220 elf32_arm_close_and_cleanup (bfd * abfd)
12222 if (abfd->sections)
12223 bfd_map_over_sections (abfd,
12224 unrecord_section_via_map_over_sections,
12225 NULL);
12227 return _bfd_elf_close_and_cleanup (abfd);
12230 static bfd_boolean
12231 elf32_arm_bfd_free_cached_info (bfd * abfd)
12233 if (abfd->sections)
12234 bfd_map_over_sections (abfd,
12235 unrecord_section_via_map_over_sections,
12236 NULL);
12238 return _bfd_free_cached_info (abfd);
12241 /* Display STT_ARM_TFUNC symbols as functions. */
12243 static void
12244 elf32_arm_symbol_processing (bfd *abfd ATTRIBUTE_UNUSED,
12245 asymbol *asym)
12247 elf_symbol_type *elfsym = (elf_symbol_type *) asym;
12249 if (ELF_ST_TYPE (elfsym->internal_elf_sym.st_info) == STT_ARM_TFUNC)
12250 elfsym->symbol.flags |= BSF_FUNCTION;
12254 /* Mangle thumb function symbols as we read them in. */
12256 static bfd_boolean
12257 elf32_arm_swap_symbol_in (bfd * abfd,
12258 const void *psrc,
12259 const void *pshn,
12260 Elf_Internal_Sym *dst)
12262 if (!bfd_elf32_swap_symbol_in (abfd, psrc, pshn, dst))
12263 return FALSE;
12265 /* New EABI objects mark thumb function symbols by setting the low bit of
12266 the address. Turn these into STT_ARM_TFUNC. */
12267 if ((ELF_ST_TYPE (dst->st_info) == STT_FUNC)
12268 && (dst->st_value & 1))
12270 dst->st_info = ELF_ST_INFO (ELF_ST_BIND (dst->st_info), STT_ARM_TFUNC);
12271 dst->st_value &= ~(bfd_vma) 1;
12273 return TRUE;
12277 /* Mangle thumb function symbols as we write them out. */
12279 static void
12280 elf32_arm_swap_symbol_out (bfd *abfd,
12281 const Elf_Internal_Sym *src,
12282 void *cdst,
12283 void *shndx)
12285 Elf_Internal_Sym newsym;
12287 /* We convert STT_ARM_TFUNC symbols into STT_FUNC with the low bit
12288 of the address set, as per the new EABI. We do this unconditionally
12289 because objcopy does not set the elf header flags until after
12290 it writes out the symbol table. */
12291 if (ELF_ST_TYPE (src->st_info) == STT_ARM_TFUNC)
12293 newsym = *src;
12294 newsym.st_info = ELF_ST_INFO (ELF_ST_BIND (src->st_info), STT_FUNC);
12295 if (newsym.st_shndx != SHN_UNDEF)
12297 /* Do this only for defined symbols. At link type, the static
12298 linker will simulate the work of dynamic linker of resolving
12299 symbols and will carry over the thumbness of found symbols to
12300 the output symbol table. It's not clear how it happens, but
12301 the thumbness of undefined symbols can well be different at
12302 runtime, and writing '1' for them will be confusing for users
12303 and possibly for dynamic linker itself.
12305 newsym.st_value |= 1;
12308 src = &newsym;
12310 bfd_elf32_swap_symbol_out (abfd, src, cdst, shndx);
12313 /* Add the PT_ARM_EXIDX program header. */
12315 static bfd_boolean
12316 elf32_arm_modify_segment_map (bfd *abfd,
12317 struct bfd_link_info *info ATTRIBUTE_UNUSED)
12319 struct elf_segment_map *m;
12320 asection *sec;
12322 sec = bfd_get_section_by_name (abfd, ".ARM.exidx");
12323 if (sec != NULL && (sec->flags & SEC_LOAD) != 0)
12325 /* If there is already a PT_ARM_EXIDX header, then we do not
12326 want to add another one. This situation arises when running
12327 "strip"; the input binary already has the header. */
12328 m = elf_tdata (abfd)->segment_map;
12329 while (m && m->p_type != PT_ARM_EXIDX)
12330 m = m->next;
12331 if (!m)
12333 m = bfd_zalloc (abfd, sizeof (struct elf_segment_map));
12334 if (m == NULL)
12335 return FALSE;
12336 m->p_type = PT_ARM_EXIDX;
12337 m->count = 1;
12338 m->sections[0] = sec;
12340 m->next = elf_tdata (abfd)->segment_map;
12341 elf_tdata (abfd)->segment_map = m;
12345 return TRUE;
12348 /* We may add a PT_ARM_EXIDX program header. */
12350 static int
12351 elf32_arm_additional_program_headers (bfd *abfd,
12352 struct bfd_link_info *info ATTRIBUTE_UNUSED)
12354 asection *sec;
12356 sec = bfd_get_section_by_name (abfd, ".ARM.exidx");
12357 if (sec != NULL && (sec->flags & SEC_LOAD) != 0)
12358 return 1;
12359 else
12360 return 0;
12363 /* We have two function types: STT_FUNC and STT_ARM_TFUNC. */
12365 static bfd_boolean
12366 elf32_arm_is_function_type (unsigned int type)
12368 return (type == STT_FUNC) || (type == STT_ARM_TFUNC);
12371 /* We use this to override swap_symbol_in and swap_symbol_out. */
12372 const struct elf_size_info elf32_arm_size_info =
12374 sizeof (Elf32_External_Ehdr),
12375 sizeof (Elf32_External_Phdr),
12376 sizeof (Elf32_External_Shdr),
12377 sizeof (Elf32_External_Rel),
12378 sizeof (Elf32_External_Rela),
12379 sizeof (Elf32_External_Sym),
12380 sizeof (Elf32_External_Dyn),
12381 sizeof (Elf_External_Note),
12384 32, 2,
12385 ELFCLASS32, EV_CURRENT,
12386 bfd_elf32_write_out_phdrs,
12387 bfd_elf32_write_shdrs_and_ehdr,
12388 bfd_elf32_checksum_contents,
12389 bfd_elf32_write_relocs,
12390 elf32_arm_swap_symbol_in,
12391 elf32_arm_swap_symbol_out,
12392 bfd_elf32_slurp_reloc_table,
12393 bfd_elf32_slurp_symbol_table,
12394 bfd_elf32_swap_dyn_in,
12395 bfd_elf32_swap_dyn_out,
12396 bfd_elf32_swap_reloc_in,
12397 bfd_elf32_swap_reloc_out,
12398 bfd_elf32_swap_reloca_in,
12399 bfd_elf32_swap_reloca_out
12402 #define ELF_ARCH bfd_arch_arm
12403 #define ELF_MACHINE_CODE EM_ARM
12404 #ifdef __QNXTARGET__
12405 #define ELF_MAXPAGESIZE 0x1000
12406 #else
12407 #define ELF_MAXPAGESIZE 0x8000
12408 #endif
12409 #define ELF_MINPAGESIZE 0x1000
12410 #define ELF_COMMONPAGESIZE 0x1000
12412 #define bfd_elf32_mkobject elf32_arm_mkobject
12414 #define bfd_elf32_bfd_copy_private_bfd_data elf32_arm_copy_private_bfd_data
12415 #define bfd_elf32_bfd_merge_private_bfd_data elf32_arm_merge_private_bfd_data
12416 #define bfd_elf32_bfd_set_private_flags elf32_arm_set_private_flags
12417 #define bfd_elf32_bfd_print_private_bfd_data elf32_arm_print_private_bfd_data
12418 #define bfd_elf32_bfd_link_hash_table_create elf32_arm_link_hash_table_create
12419 #define bfd_elf32_bfd_link_hash_table_free elf32_arm_hash_table_free
12420 #define bfd_elf32_bfd_reloc_type_lookup elf32_arm_reloc_type_lookup
12421 #define bfd_elf32_bfd_reloc_name_lookup elf32_arm_reloc_name_lookup
12422 #define bfd_elf32_find_nearest_line elf32_arm_find_nearest_line
12423 #define bfd_elf32_find_inliner_info elf32_arm_find_inliner_info
12424 #define bfd_elf32_new_section_hook elf32_arm_new_section_hook
12425 #define bfd_elf32_bfd_is_target_special_symbol elf32_arm_is_target_special_symbol
12426 #define bfd_elf32_close_and_cleanup elf32_arm_close_and_cleanup
12427 #define bfd_elf32_bfd_free_cached_info elf32_arm_bfd_free_cached_info
12429 #define elf_backend_get_symbol_type elf32_arm_get_symbol_type
12430 #define elf_backend_gc_mark_hook elf32_arm_gc_mark_hook
12431 #define elf_backend_gc_mark_extra_sections elf32_arm_gc_mark_extra_sections
12432 #define elf_backend_gc_sweep_hook elf32_arm_gc_sweep_hook
12433 #define elf_backend_check_relocs elf32_arm_check_relocs
12434 #define elf_backend_relocate_section elf32_arm_relocate_section
12435 #define elf_backend_write_section elf32_arm_write_section
12436 #define elf_backend_adjust_dynamic_symbol elf32_arm_adjust_dynamic_symbol
12437 #define elf_backend_create_dynamic_sections elf32_arm_create_dynamic_sections
12438 #define elf_backend_finish_dynamic_symbol elf32_arm_finish_dynamic_symbol
12439 #define elf_backend_finish_dynamic_sections elf32_arm_finish_dynamic_sections
12440 #define elf_backend_size_dynamic_sections elf32_arm_size_dynamic_sections
12441 #define elf_backend_init_index_section _bfd_elf_init_2_index_sections
12442 #define elf_backend_post_process_headers elf32_arm_post_process_headers
12443 #define elf_backend_reloc_type_class elf32_arm_reloc_type_class
12444 #define elf_backend_object_p elf32_arm_object_p
12445 #define elf_backend_section_flags elf32_arm_section_flags
12446 #define elf_backend_fake_sections elf32_arm_fake_sections
12447 #define elf_backend_section_from_shdr elf32_arm_section_from_shdr
12448 #define elf_backend_final_write_processing elf32_arm_final_write_processing
12449 #define elf_backend_copy_indirect_symbol elf32_arm_copy_indirect_symbol
12450 #define elf_backend_symbol_processing elf32_arm_symbol_processing
12451 #define elf_backend_size_info elf32_arm_size_info
12452 #define elf_backend_modify_segment_map elf32_arm_modify_segment_map
12453 #define elf_backend_additional_program_headers elf32_arm_additional_program_headers
12454 #define elf_backend_output_arch_local_syms elf32_arm_output_arch_local_syms
12455 #define elf_backend_begin_write_processing elf32_arm_begin_write_processing
12456 #define elf_backend_is_function_type elf32_arm_is_function_type
12458 #define elf_backend_can_refcount 1
12459 #define elf_backend_can_gc_sections 1
12460 #define elf_backend_plt_readonly 1
12461 #define elf_backend_want_got_plt 1
12462 #define elf_backend_want_plt_sym 0
12463 #define elf_backend_may_use_rel_p 1
12464 #define elf_backend_may_use_rela_p 0
12465 #define elf_backend_default_use_rela_p 0
12467 #define elf_backend_got_header_size 12
12469 #undef elf_backend_obj_attrs_vendor
12470 #define elf_backend_obj_attrs_vendor "aeabi"
12471 #undef elf_backend_obj_attrs_section
12472 #define elf_backend_obj_attrs_section ".ARM.attributes"
12473 #undef elf_backend_obj_attrs_arg_type
12474 #define elf_backend_obj_attrs_arg_type elf32_arm_obj_attrs_arg_type
12475 #undef elf_backend_obj_attrs_section_type
12476 #define elf_backend_obj_attrs_section_type SHT_ARM_ATTRIBUTES
12477 #define elf_backend_obj_attrs_order elf32_arm_obj_attrs_order
12479 #include "elf32-target.h"
12481 /* VxWorks Targets. */
12483 #undef TARGET_LITTLE_SYM
12484 #define TARGET_LITTLE_SYM bfd_elf32_littlearm_vxworks_vec
12485 #undef TARGET_LITTLE_NAME
12486 #define TARGET_LITTLE_NAME "elf32-littlearm-vxworks"
12487 #undef TARGET_BIG_SYM
12488 #define TARGET_BIG_SYM bfd_elf32_bigarm_vxworks_vec
12489 #undef TARGET_BIG_NAME
12490 #define TARGET_BIG_NAME "elf32-bigarm-vxworks"
12492 /* Like elf32_arm_link_hash_table_create -- but overrides
12493 appropriately for VxWorks. */
12495 static struct bfd_link_hash_table *
12496 elf32_arm_vxworks_link_hash_table_create (bfd *abfd)
12498 struct bfd_link_hash_table *ret;
12500 ret = elf32_arm_link_hash_table_create (abfd);
12501 if (ret)
12503 struct elf32_arm_link_hash_table *htab
12504 = (struct elf32_arm_link_hash_table *) ret;
12505 htab->use_rel = 0;
12506 htab->vxworks_p = 1;
12508 return ret;
12511 static void
12512 elf32_arm_vxworks_final_write_processing (bfd *abfd, bfd_boolean linker)
12514 elf32_arm_final_write_processing (abfd, linker);
12515 elf_vxworks_final_write_processing (abfd, linker);
12518 #undef elf32_bed
12519 #define elf32_bed elf32_arm_vxworks_bed
12521 #undef bfd_elf32_bfd_link_hash_table_create
12522 #define bfd_elf32_bfd_link_hash_table_create elf32_arm_vxworks_link_hash_table_create
12523 #undef elf_backend_add_symbol_hook
12524 #define elf_backend_add_symbol_hook elf_vxworks_add_symbol_hook
12525 #undef elf_backend_final_write_processing
12526 #define elf_backend_final_write_processing elf32_arm_vxworks_final_write_processing
12527 #undef elf_backend_emit_relocs
12528 #define elf_backend_emit_relocs elf_vxworks_emit_relocs
12530 #undef elf_backend_may_use_rel_p
12531 #define elf_backend_may_use_rel_p 0
12532 #undef elf_backend_may_use_rela_p
12533 #define elf_backend_may_use_rela_p 1
12534 #undef elf_backend_default_use_rela_p
12535 #define elf_backend_default_use_rela_p 1
12536 #undef elf_backend_want_plt_sym
12537 #define elf_backend_want_plt_sym 1
12538 #undef ELF_MAXPAGESIZE
12539 #define ELF_MAXPAGESIZE 0x1000
12541 #include "elf32-target.h"
12544 /* Symbian OS Targets. */
12546 #undef TARGET_LITTLE_SYM
12547 #define TARGET_LITTLE_SYM bfd_elf32_littlearm_symbian_vec
12548 #undef TARGET_LITTLE_NAME
12549 #define TARGET_LITTLE_NAME "elf32-littlearm-symbian"
12550 #undef TARGET_BIG_SYM
12551 #define TARGET_BIG_SYM bfd_elf32_bigarm_symbian_vec
12552 #undef TARGET_BIG_NAME
12553 #define TARGET_BIG_NAME "elf32-bigarm-symbian"
12555 /* Like elf32_arm_link_hash_table_create -- but overrides
12556 appropriately for Symbian OS. */
12558 static struct bfd_link_hash_table *
12559 elf32_arm_symbian_link_hash_table_create (bfd *abfd)
12561 struct bfd_link_hash_table *ret;
12563 ret = elf32_arm_link_hash_table_create (abfd);
12564 if (ret)
12566 struct elf32_arm_link_hash_table *htab
12567 = (struct elf32_arm_link_hash_table *)ret;
12568 /* There is no PLT header for Symbian OS. */
12569 htab->plt_header_size = 0;
12570 /* The PLT entries are each one instruction and one word. */
12571 htab->plt_entry_size = 4 * ARRAY_SIZE (elf32_arm_symbian_plt_entry);
12572 htab->symbian_p = 1;
12573 /* Symbian uses armv5t or above, so use_blx is always true. */
12574 htab->use_blx = 1;
12575 htab->root.is_relocatable_executable = 1;
12577 return ret;
12580 static const struct bfd_elf_special_section
12581 elf32_arm_symbian_special_sections[] =
12583 /* In a BPABI executable, the dynamic linking sections do not go in
12584 the loadable read-only segment. The post-linker may wish to
12585 refer to these sections, but they are not part of the final
12586 program image. */
12587 { STRING_COMMA_LEN (".dynamic"), 0, SHT_DYNAMIC, 0 },
12588 { STRING_COMMA_LEN (".dynstr"), 0, SHT_STRTAB, 0 },
12589 { STRING_COMMA_LEN (".dynsym"), 0, SHT_DYNSYM, 0 },
12590 { STRING_COMMA_LEN (".got"), 0, SHT_PROGBITS, 0 },
12591 { STRING_COMMA_LEN (".hash"), 0, SHT_HASH, 0 },
12592 /* These sections do not need to be writable as the SymbianOS
12593 postlinker will arrange things so that no dynamic relocation is
12594 required. */
12595 { STRING_COMMA_LEN (".init_array"), 0, SHT_INIT_ARRAY, SHF_ALLOC },
12596 { STRING_COMMA_LEN (".fini_array"), 0, SHT_FINI_ARRAY, SHF_ALLOC },
12597 { STRING_COMMA_LEN (".preinit_array"), 0, SHT_PREINIT_ARRAY, SHF_ALLOC },
12598 { NULL, 0, 0, 0, 0 }
12601 static void
12602 elf32_arm_symbian_begin_write_processing (bfd *abfd,
12603 struct bfd_link_info *link_info)
12605 /* BPABI objects are never loaded directly by an OS kernel; they are
12606 processed by a postlinker first, into an OS-specific format. If
12607 the D_PAGED bit is set on the file, BFD will align segments on
12608 page boundaries, so that an OS can directly map the file. With
12609 BPABI objects, that just results in wasted space. In addition,
12610 because we clear the D_PAGED bit, map_sections_to_segments will
12611 recognize that the program headers should not be mapped into any
12612 loadable segment. */
12613 abfd->flags &= ~D_PAGED;
12614 elf32_arm_begin_write_processing (abfd, link_info);
12617 static bfd_boolean
12618 elf32_arm_symbian_modify_segment_map (bfd *abfd,
12619 struct bfd_link_info *info)
12621 struct elf_segment_map *m;
12622 asection *dynsec;
12624 /* BPABI shared libraries and executables should have a PT_DYNAMIC
12625 segment. However, because the .dynamic section is not marked
12626 with SEC_LOAD, the generic ELF code will not create such a
12627 segment. */
12628 dynsec = bfd_get_section_by_name (abfd, ".dynamic");
12629 if (dynsec)
12631 for (m = elf_tdata (abfd)->segment_map; m != NULL; m = m->next)
12632 if (m->p_type == PT_DYNAMIC)
12633 break;
12635 if (m == NULL)
12637 m = _bfd_elf_make_dynamic_segment (abfd, dynsec);
12638 m->next = elf_tdata (abfd)->segment_map;
12639 elf_tdata (abfd)->segment_map = m;
12643 /* Also call the generic arm routine. */
12644 return elf32_arm_modify_segment_map (abfd, info);
12647 /* Return address for Ith PLT stub in section PLT, for relocation REL
12648 or (bfd_vma) -1 if it should not be included. */
12650 static bfd_vma
12651 elf32_arm_symbian_plt_sym_val (bfd_vma i, const asection *plt,
12652 const arelent *rel ATTRIBUTE_UNUSED)
12654 return plt->vma + 4 * ARRAY_SIZE (elf32_arm_symbian_plt_entry) * i;
12658 #undef elf32_bed
12659 #define elf32_bed elf32_arm_symbian_bed
12661 /* The dynamic sections are not allocated on SymbianOS; the postlinker
12662 will process them and then discard them. */
12663 #undef ELF_DYNAMIC_SEC_FLAGS
12664 #define ELF_DYNAMIC_SEC_FLAGS \
12665 (SEC_HAS_CONTENTS | SEC_IN_MEMORY | SEC_LINKER_CREATED)
12667 #undef elf_backend_add_symbol_hook
12668 #undef elf_backend_emit_relocs
12670 #undef bfd_elf32_bfd_link_hash_table_create
12671 #define bfd_elf32_bfd_link_hash_table_create elf32_arm_symbian_link_hash_table_create
12672 #undef elf_backend_special_sections
12673 #define elf_backend_special_sections elf32_arm_symbian_special_sections
12674 #undef elf_backend_begin_write_processing
12675 #define elf_backend_begin_write_processing elf32_arm_symbian_begin_write_processing
12676 #undef elf_backend_final_write_processing
12677 #define elf_backend_final_write_processing elf32_arm_final_write_processing
12679 #undef elf_backend_modify_segment_map
12680 #define elf_backend_modify_segment_map elf32_arm_symbian_modify_segment_map
12682 /* There is no .got section for BPABI objects, and hence no header. */
12683 #undef elf_backend_got_header_size
12684 #define elf_backend_got_header_size 0
12686 /* Similarly, there is no .got.plt section. */
12687 #undef elf_backend_want_got_plt
12688 #define elf_backend_want_got_plt 0
12690 #undef elf_backend_plt_sym_val
12691 #define elf_backend_plt_sym_val elf32_arm_symbian_plt_sym_val
12693 #undef elf_backend_may_use_rel_p
12694 #define elf_backend_may_use_rel_p 1
12695 #undef elf_backend_may_use_rela_p
12696 #define elf_backend_may_use_rela_p 0
12697 #undef elf_backend_default_use_rela_p
12698 #define elf_backend_default_use_rela_p 0
12699 #undef elf_backend_want_plt_sym
12700 #define elf_backend_want_plt_sym 0
12701 #undef ELF_MAXPAGESIZE
12702 #define ELF_MAXPAGESIZE 0x8000
12704 #include "elf32-target.h"