ld/
[binutils.git] / bfd / elf32-arm.c
blobd36c923e05c2a3f21a44a7680d713533407bb611
1 /* 32-bit ELF support for ARM
2 Copyright 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007
3 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 2 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, MA 02110-1301, USA. */
21 #include "sysdep.h"
22 #include "bfd.h"
23 #include "libiberty.h"
24 #include "libbfd.h"
25 #include "elf-bfd.h"
26 #include "elf-vxworks.h"
27 #include "elf/arm.h"
29 #ifndef NUM_ELEM
30 #define NUM_ELEM(a) (sizeof (a) / (sizeof (a)[0]))
31 #endif
33 /* Return the relocation section associated with NAME. HTAB is the
34 bfd's elf32_arm_link_hash_entry. */
35 #define RELOC_SECTION(HTAB, NAME) \
36 ((HTAB)->use_rel ? ".rel" NAME : ".rela" NAME)
38 /* Return size of a relocation entry. HTAB is the bfd's
39 elf32_arm_link_hash_entry. */
40 #define RELOC_SIZE(HTAB) \
41 ((HTAB)->use_rel \
42 ? sizeof (Elf32_External_Rel) \
43 : sizeof (Elf32_External_Rela))
45 /* Return function to swap relocations in. HTAB is the bfd's
46 elf32_arm_link_hash_entry. */
47 #define SWAP_RELOC_IN(HTAB) \
48 ((HTAB)->use_rel \
49 ? bfd_elf32_swap_reloc_in \
50 : bfd_elf32_swap_reloca_in)
52 /* Return function to swap relocations out. HTAB is the bfd's
53 elf32_arm_link_hash_entry. */
54 #define SWAP_RELOC_OUT(HTAB) \
55 ((HTAB)->use_rel \
56 ? bfd_elf32_swap_reloc_out \
57 : bfd_elf32_swap_reloca_out)
59 #define elf_info_to_howto 0
60 #define elf_info_to_howto_rel elf32_arm_info_to_howto
62 #define ARM_ELF_ABI_VERSION 0
63 #define ARM_ELF_OS_ABI_VERSION ELFOSABI_ARM
65 static struct elf_backend_data elf32_arm_vxworks_bed;
67 /* Note: code such as elf32_arm_reloc_type_lookup expect to use e.g.
68 R_ARM_PC24 as an index into this, and find the R_ARM_PC24 HOWTO
69 in that slot. */
71 static reloc_howto_type elf32_arm_howto_table_1[] =
73 /* No relocation */
74 HOWTO (R_ARM_NONE, /* type */
75 0, /* rightshift */
76 0, /* size (0 = byte, 1 = short, 2 = long) */
77 0, /* bitsize */
78 FALSE, /* pc_relative */
79 0, /* bitpos */
80 complain_overflow_dont,/* complain_on_overflow */
81 bfd_elf_generic_reloc, /* special_function */
82 "R_ARM_NONE", /* name */
83 FALSE, /* partial_inplace */
84 0, /* src_mask */
85 0, /* dst_mask */
86 FALSE), /* pcrel_offset */
88 HOWTO (R_ARM_PC24, /* type */
89 2, /* rightshift */
90 2, /* size (0 = byte, 1 = short, 2 = long) */
91 24, /* bitsize */
92 TRUE, /* pc_relative */
93 0, /* bitpos */
94 complain_overflow_signed,/* complain_on_overflow */
95 bfd_elf_generic_reloc, /* special_function */
96 "R_ARM_PC24", /* name */
97 FALSE, /* partial_inplace */
98 0x00ffffff, /* src_mask */
99 0x00ffffff, /* dst_mask */
100 TRUE), /* pcrel_offset */
102 /* 32 bit absolute */
103 HOWTO (R_ARM_ABS32, /* type */
104 0, /* rightshift */
105 2, /* size (0 = byte, 1 = short, 2 = long) */
106 32, /* bitsize */
107 FALSE, /* pc_relative */
108 0, /* bitpos */
109 complain_overflow_bitfield,/* complain_on_overflow */
110 bfd_elf_generic_reloc, /* special_function */
111 "R_ARM_ABS32", /* name */
112 FALSE, /* partial_inplace */
113 0xffffffff, /* src_mask */
114 0xffffffff, /* dst_mask */
115 FALSE), /* pcrel_offset */
117 /* standard 32bit pc-relative reloc */
118 HOWTO (R_ARM_REL32, /* type */
119 0, /* rightshift */
120 2, /* size (0 = byte, 1 = short, 2 = long) */
121 32, /* bitsize */
122 TRUE, /* pc_relative */
123 0, /* bitpos */
124 complain_overflow_bitfield,/* complain_on_overflow */
125 bfd_elf_generic_reloc, /* special_function */
126 "R_ARM_REL32", /* name */
127 FALSE, /* partial_inplace */
128 0xffffffff, /* src_mask */
129 0xffffffff, /* dst_mask */
130 TRUE), /* pcrel_offset */
132 /* 8 bit absolute - R_ARM_LDR_PC_G0 in AAELF */
133 HOWTO (R_ARM_LDR_PC_G0, /* type */
134 0, /* rightshift */
135 0, /* size (0 = byte, 1 = short, 2 = long) */
136 32, /* bitsize */
137 TRUE, /* pc_relative */
138 0, /* bitpos */
139 complain_overflow_dont,/* complain_on_overflow */
140 bfd_elf_generic_reloc, /* special_function */
141 "R_ARM_LDR_PC_G0", /* name */
142 FALSE, /* partial_inplace */
143 0xffffffff, /* src_mask */
144 0xffffffff, /* dst_mask */
145 TRUE), /* pcrel_offset */
147 /* 16 bit absolute */
148 HOWTO (R_ARM_ABS16, /* type */
149 0, /* rightshift */
150 1, /* size (0 = byte, 1 = short, 2 = long) */
151 16, /* bitsize */
152 FALSE, /* pc_relative */
153 0, /* bitpos */
154 complain_overflow_bitfield,/* complain_on_overflow */
155 bfd_elf_generic_reloc, /* special_function */
156 "R_ARM_ABS16", /* name */
157 FALSE, /* partial_inplace */
158 0x0000ffff, /* src_mask */
159 0x0000ffff, /* dst_mask */
160 FALSE), /* pcrel_offset */
162 /* 12 bit absolute */
163 HOWTO (R_ARM_ABS12, /* type */
164 0, /* rightshift */
165 2, /* size (0 = byte, 1 = short, 2 = long) */
166 12, /* bitsize */
167 FALSE, /* pc_relative */
168 0, /* bitpos */
169 complain_overflow_bitfield,/* complain_on_overflow */
170 bfd_elf_generic_reloc, /* special_function */
171 "R_ARM_ABS12", /* name */
172 FALSE, /* partial_inplace */
173 0x00000fff, /* src_mask */
174 0x00000fff, /* dst_mask */
175 FALSE), /* pcrel_offset */
177 HOWTO (R_ARM_THM_ABS5, /* type */
178 6, /* rightshift */
179 1, /* size (0 = byte, 1 = short, 2 = long) */
180 5, /* bitsize */
181 FALSE, /* pc_relative */
182 0, /* bitpos */
183 complain_overflow_bitfield,/* complain_on_overflow */
184 bfd_elf_generic_reloc, /* special_function */
185 "R_ARM_THM_ABS5", /* name */
186 FALSE, /* partial_inplace */
187 0x000007e0, /* src_mask */
188 0x000007e0, /* dst_mask */
189 FALSE), /* pcrel_offset */
191 /* 8 bit absolute */
192 HOWTO (R_ARM_ABS8, /* type */
193 0, /* rightshift */
194 0, /* size (0 = byte, 1 = short, 2 = long) */
195 8, /* bitsize */
196 FALSE, /* pc_relative */
197 0, /* bitpos */
198 complain_overflow_bitfield,/* complain_on_overflow */
199 bfd_elf_generic_reloc, /* special_function */
200 "R_ARM_ABS8", /* name */
201 FALSE, /* partial_inplace */
202 0x000000ff, /* src_mask */
203 0x000000ff, /* dst_mask */
204 FALSE), /* pcrel_offset */
206 HOWTO (R_ARM_SBREL32, /* type */
207 0, /* rightshift */
208 2, /* size (0 = byte, 1 = short, 2 = long) */
209 32, /* bitsize */
210 FALSE, /* pc_relative */
211 0, /* bitpos */
212 complain_overflow_dont,/* complain_on_overflow */
213 bfd_elf_generic_reloc, /* special_function */
214 "R_ARM_SBREL32", /* name */
215 FALSE, /* partial_inplace */
216 0xffffffff, /* src_mask */
217 0xffffffff, /* dst_mask */
218 FALSE), /* pcrel_offset */
220 HOWTO (R_ARM_THM_CALL, /* type */
221 1, /* rightshift */
222 2, /* size (0 = byte, 1 = short, 2 = long) */
223 25, /* bitsize */
224 TRUE, /* pc_relative */
225 0, /* bitpos */
226 complain_overflow_signed,/* complain_on_overflow */
227 bfd_elf_generic_reloc, /* special_function */
228 "R_ARM_THM_CALL", /* name */
229 FALSE, /* partial_inplace */
230 0x07ff07ff, /* src_mask */
231 0x07ff07ff, /* dst_mask */
232 TRUE), /* pcrel_offset */
234 HOWTO (R_ARM_THM_PC8, /* type */
235 1, /* rightshift */
236 1, /* size (0 = byte, 1 = short, 2 = long) */
237 8, /* bitsize */
238 TRUE, /* pc_relative */
239 0, /* bitpos */
240 complain_overflow_signed,/* complain_on_overflow */
241 bfd_elf_generic_reloc, /* special_function */
242 "R_ARM_THM_PC8", /* name */
243 FALSE, /* partial_inplace */
244 0x000000ff, /* src_mask */
245 0x000000ff, /* dst_mask */
246 TRUE), /* pcrel_offset */
248 HOWTO (R_ARM_BREL_ADJ, /* type */
249 1, /* rightshift */
250 1, /* size (0 = byte, 1 = short, 2 = long) */
251 32, /* bitsize */
252 FALSE, /* pc_relative */
253 0, /* bitpos */
254 complain_overflow_signed,/* complain_on_overflow */
255 bfd_elf_generic_reloc, /* special_function */
256 "R_ARM_BREL_ADJ", /* name */
257 FALSE, /* partial_inplace */
258 0xffffffff, /* src_mask */
259 0xffffffff, /* dst_mask */
260 FALSE), /* pcrel_offset */
262 HOWTO (R_ARM_SWI24, /* type */
263 0, /* rightshift */
264 0, /* size (0 = byte, 1 = short, 2 = long) */
265 0, /* bitsize */
266 FALSE, /* pc_relative */
267 0, /* bitpos */
268 complain_overflow_signed,/* complain_on_overflow */
269 bfd_elf_generic_reloc, /* special_function */
270 "R_ARM_SWI24", /* name */
271 FALSE, /* partial_inplace */
272 0x00000000, /* src_mask */
273 0x00000000, /* dst_mask */
274 FALSE), /* pcrel_offset */
276 HOWTO (R_ARM_THM_SWI8, /* type */
277 0, /* rightshift */
278 0, /* size (0 = byte, 1 = short, 2 = long) */
279 0, /* bitsize */
280 FALSE, /* pc_relative */
281 0, /* bitpos */
282 complain_overflow_signed,/* complain_on_overflow */
283 bfd_elf_generic_reloc, /* special_function */
284 "R_ARM_SWI8", /* name */
285 FALSE, /* partial_inplace */
286 0x00000000, /* src_mask */
287 0x00000000, /* dst_mask */
288 FALSE), /* pcrel_offset */
290 /* BLX instruction for the ARM. */
291 HOWTO (R_ARM_XPC25, /* type */
292 2, /* rightshift */
293 2, /* size (0 = byte, 1 = short, 2 = long) */
294 25, /* bitsize */
295 TRUE, /* pc_relative */
296 0, /* bitpos */
297 complain_overflow_signed,/* complain_on_overflow */
298 bfd_elf_generic_reloc, /* special_function */
299 "R_ARM_XPC25", /* name */
300 FALSE, /* partial_inplace */
301 0x00ffffff, /* src_mask */
302 0x00ffffff, /* dst_mask */
303 TRUE), /* pcrel_offset */
305 /* BLX instruction for the Thumb. */
306 HOWTO (R_ARM_THM_XPC22, /* type */
307 2, /* rightshift */
308 2, /* size (0 = byte, 1 = short, 2 = long) */
309 22, /* bitsize */
310 TRUE, /* pc_relative */
311 0, /* bitpos */
312 complain_overflow_signed,/* complain_on_overflow */
313 bfd_elf_generic_reloc, /* special_function */
314 "R_ARM_THM_XPC22", /* name */
315 FALSE, /* partial_inplace */
316 0x07ff07ff, /* src_mask */
317 0x07ff07ff, /* dst_mask */
318 TRUE), /* pcrel_offset */
320 /* Dynamic TLS relocations. */
322 HOWTO (R_ARM_TLS_DTPMOD32, /* type */
323 0, /* rightshift */
324 2, /* size (0 = byte, 1 = short, 2 = long) */
325 32, /* bitsize */
326 FALSE, /* pc_relative */
327 0, /* bitpos */
328 complain_overflow_bitfield,/* complain_on_overflow */
329 bfd_elf_generic_reloc, /* special_function */
330 "R_ARM_TLS_DTPMOD32", /* name */
331 TRUE, /* partial_inplace */
332 0xffffffff, /* src_mask */
333 0xffffffff, /* dst_mask */
334 FALSE), /* pcrel_offset */
336 HOWTO (R_ARM_TLS_DTPOFF32, /* type */
337 0, /* rightshift */
338 2, /* size (0 = byte, 1 = short, 2 = long) */
339 32, /* bitsize */
340 FALSE, /* pc_relative */
341 0, /* bitpos */
342 complain_overflow_bitfield,/* complain_on_overflow */
343 bfd_elf_generic_reloc, /* special_function */
344 "R_ARM_TLS_DTPOFF32", /* name */
345 TRUE, /* partial_inplace */
346 0xffffffff, /* src_mask */
347 0xffffffff, /* dst_mask */
348 FALSE), /* pcrel_offset */
350 HOWTO (R_ARM_TLS_TPOFF32, /* type */
351 0, /* rightshift */
352 2, /* size (0 = byte, 1 = short, 2 = long) */
353 32, /* bitsize */
354 FALSE, /* pc_relative */
355 0, /* bitpos */
356 complain_overflow_bitfield,/* complain_on_overflow */
357 bfd_elf_generic_reloc, /* special_function */
358 "R_ARM_TLS_TPOFF32", /* name */
359 TRUE, /* partial_inplace */
360 0xffffffff, /* src_mask */
361 0xffffffff, /* dst_mask */
362 FALSE), /* pcrel_offset */
364 /* Relocs used in ARM Linux */
366 HOWTO (R_ARM_COPY, /* type */
367 0, /* rightshift */
368 2, /* size (0 = byte, 1 = short, 2 = long) */
369 32, /* bitsize */
370 FALSE, /* pc_relative */
371 0, /* bitpos */
372 complain_overflow_bitfield,/* complain_on_overflow */
373 bfd_elf_generic_reloc, /* special_function */
374 "R_ARM_COPY", /* name */
375 TRUE, /* partial_inplace */
376 0xffffffff, /* src_mask */
377 0xffffffff, /* dst_mask */
378 FALSE), /* pcrel_offset */
380 HOWTO (R_ARM_GLOB_DAT, /* type */
381 0, /* rightshift */
382 2, /* size (0 = byte, 1 = short, 2 = long) */
383 32, /* bitsize */
384 FALSE, /* pc_relative */
385 0, /* bitpos */
386 complain_overflow_bitfield,/* complain_on_overflow */
387 bfd_elf_generic_reloc, /* special_function */
388 "R_ARM_GLOB_DAT", /* name */
389 TRUE, /* partial_inplace */
390 0xffffffff, /* src_mask */
391 0xffffffff, /* dst_mask */
392 FALSE), /* pcrel_offset */
394 HOWTO (R_ARM_JUMP_SLOT, /* type */
395 0, /* rightshift */
396 2, /* size (0 = byte, 1 = short, 2 = long) */
397 32, /* bitsize */
398 FALSE, /* pc_relative */
399 0, /* bitpos */
400 complain_overflow_bitfield,/* complain_on_overflow */
401 bfd_elf_generic_reloc, /* special_function */
402 "R_ARM_JUMP_SLOT", /* name */
403 TRUE, /* partial_inplace */
404 0xffffffff, /* src_mask */
405 0xffffffff, /* dst_mask */
406 FALSE), /* pcrel_offset */
408 HOWTO (R_ARM_RELATIVE, /* type */
409 0, /* rightshift */
410 2, /* size (0 = byte, 1 = short, 2 = long) */
411 32, /* bitsize */
412 FALSE, /* pc_relative */
413 0, /* bitpos */
414 complain_overflow_bitfield,/* complain_on_overflow */
415 bfd_elf_generic_reloc, /* special_function */
416 "R_ARM_RELATIVE", /* name */
417 TRUE, /* partial_inplace */
418 0xffffffff, /* src_mask */
419 0xffffffff, /* dst_mask */
420 FALSE), /* pcrel_offset */
422 HOWTO (R_ARM_GOTOFF32, /* type */
423 0, /* rightshift */
424 2, /* size (0 = byte, 1 = short, 2 = long) */
425 32, /* bitsize */
426 FALSE, /* pc_relative */
427 0, /* bitpos */
428 complain_overflow_bitfield,/* complain_on_overflow */
429 bfd_elf_generic_reloc, /* special_function */
430 "R_ARM_GOTOFF32", /* name */
431 TRUE, /* partial_inplace */
432 0xffffffff, /* src_mask */
433 0xffffffff, /* dst_mask */
434 FALSE), /* pcrel_offset */
436 HOWTO (R_ARM_GOTPC, /* type */
437 0, /* rightshift */
438 2, /* size (0 = byte, 1 = short, 2 = long) */
439 32, /* bitsize */
440 TRUE, /* pc_relative */
441 0, /* bitpos */
442 complain_overflow_bitfield,/* complain_on_overflow */
443 bfd_elf_generic_reloc, /* special_function */
444 "R_ARM_GOTPC", /* name */
445 TRUE, /* partial_inplace */
446 0xffffffff, /* src_mask */
447 0xffffffff, /* dst_mask */
448 TRUE), /* pcrel_offset */
450 HOWTO (R_ARM_GOT32, /* type */
451 0, /* rightshift */
452 2, /* size (0 = byte, 1 = short, 2 = long) */
453 32, /* bitsize */
454 FALSE, /* pc_relative */
455 0, /* bitpos */
456 complain_overflow_bitfield,/* complain_on_overflow */
457 bfd_elf_generic_reloc, /* special_function */
458 "R_ARM_GOT32", /* name */
459 TRUE, /* partial_inplace */
460 0xffffffff, /* src_mask */
461 0xffffffff, /* dst_mask */
462 FALSE), /* pcrel_offset */
464 HOWTO (R_ARM_PLT32, /* type */
465 2, /* rightshift */
466 2, /* size (0 = byte, 1 = short, 2 = long) */
467 24, /* bitsize */
468 TRUE, /* pc_relative */
469 0, /* bitpos */
470 complain_overflow_bitfield,/* complain_on_overflow */
471 bfd_elf_generic_reloc, /* special_function */
472 "R_ARM_PLT32", /* name */
473 FALSE, /* partial_inplace */
474 0x00ffffff, /* src_mask */
475 0x00ffffff, /* dst_mask */
476 TRUE), /* pcrel_offset */
478 HOWTO (R_ARM_CALL, /* type */
479 2, /* rightshift */
480 2, /* size (0 = byte, 1 = short, 2 = long) */
481 24, /* bitsize */
482 TRUE, /* pc_relative */
483 0, /* bitpos */
484 complain_overflow_signed,/* complain_on_overflow */
485 bfd_elf_generic_reloc, /* special_function */
486 "R_ARM_CALL", /* name */
487 FALSE, /* partial_inplace */
488 0x00ffffff, /* src_mask */
489 0x00ffffff, /* dst_mask */
490 TRUE), /* pcrel_offset */
492 HOWTO (R_ARM_JUMP24, /* type */
493 2, /* rightshift */
494 2, /* size (0 = byte, 1 = short, 2 = long) */
495 24, /* bitsize */
496 TRUE, /* pc_relative */
497 0, /* bitpos */
498 complain_overflow_signed,/* complain_on_overflow */
499 bfd_elf_generic_reloc, /* special_function */
500 "R_ARM_JUMP24", /* name */
501 FALSE, /* partial_inplace */
502 0x00ffffff, /* src_mask */
503 0x00ffffff, /* dst_mask */
504 TRUE), /* pcrel_offset */
506 HOWTO (R_ARM_THM_JUMP24, /* type */
507 1, /* rightshift */
508 2, /* size (0 = byte, 1 = short, 2 = long) */
509 24, /* bitsize */
510 TRUE, /* pc_relative */
511 0, /* bitpos */
512 complain_overflow_signed,/* complain_on_overflow */
513 bfd_elf_generic_reloc, /* special_function */
514 "R_ARM_THM_JUMP24", /* name */
515 FALSE, /* partial_inplace */
516 0x07ff2fff, /* src_mask */
517 0x07ff2fff, /* dst_mask */
518 TRUE), /* pcrel_offset */
520 HOWTO (R_ARM_BASE_ABS, /* type */
521 0, /* rightshift */
522 2, /* size (0 = byte, 1 = short, 2 = long) */
523 32, /* bitsize */
524 FALSE, /* pc_relative */
525 0, /* bitpos */
526 complain_overflow_dont,/* complain_on_overflow */
527 bfd_elf_generic_reloc, /* special_function */
528 "R_ARM_BASE_ABS", /* name */
529 FALSE, /* partial_inplace */
530 0xffffffff, /* src_mask */
531 0xffffffff, /* dst_mask */
532 FALSE), /* pcrel_offset */
534 HOWTO (R_ARM_ALU_PCREL7_0, /* type */
535 0, /* rightshift */
536 2, /* size (0 = byte, 1 = short, 2 = long) */
537 12, /* bitsize */
538 TRUE, /* pc_relative */
539 0, /* bitpos */
540 complain_overflow_dont,/* complain_on_overflow */
541 bfd_elf_generic_reloc, /* special_function */
542 "R_ARM_ALU_PCREL_7_0", /* name */
543 FALSE, /* partial_inplace */
544 0x00000fff, /* src_mask */
545 0x00000fff, /* dst_mask */
546 TRUE), /* pcrel_offset */
548 HOWTO (R_ARM_ALU_PCREL15_8, /* type */
549 0, /* rightshift */
550 2, /* size (0 = byte, 1 = short, 2 = long) */
551 12, /* bitsize */
552 TRUE, /* pc_relative */
553 8, /* bitpos */
554 complain_overflow_dont,/* complain_on_overflow */
555 bfd_elf_generic_reloc, /* special_function */
556 "R_ARM_ALU_PCREL_15_8",/* name */
557 FALSE, /* partial_inplace */
558 0x00000fff, /* src_mask */
559 0x00000fff, /* dst_mask */
560 TRUE), /* pcrel_offset */
562 HOWTO (R_ARM_ALU_PCREL23_15, /* type */
563 0, /* rightshift */
564 2, /* size (0 = byte, 1 = short, 2 = long) */
565 12, /* bitsize */
566 TRUE, /* pc_relative */
567 16, /* bitpos */
568 complain_overflow_dont,/* complain_on_overflow */
569 bfd_elf_generic_reloc, /* special_function */
570 "R_ARM_ALU_PCREL_23_15",/* name */
571 FALSE, /* partial_inplace */
572 0x00000fff, /* src_mask */
573 0x00000fff, /* dst_mask */
574 TRUE), /* pcrel_offset */
576 HOWTO (R_ARM_LDR_SBREL_11_0, /* type */
577 0, /* rightshift */
578 2, /* size (0 = byte, 1 = short, 2 = long) */
579 12, /* bitsize */
580 FALSE, /* pc_relative */
581 0, /* bitpos */
582 complain_overflow_dont,/* complain_on_overflow */
583 bfd_elf_generic_reloc, /* special_function */
584 "R_ARM_LDR_SBREL_11_0",/* name */
585 FALSE, /* partial_inplace */
586 0x00000fff, /* src_mask */
587 0x00000fff, /* dst_mask */
588 FALSE), /* pcrel_offset */
590 HOWTO (R_ARM_ALU_SBREL_19_12, /* type */
591 0, /* rightshift */
592 2, /* size (0 = byte, 1 = short, 2 = long) */
593 8, /* bitsize */
594 FALSE, /* pc_relative */
595 12, /* bitpos */
596 complain_overflow_dont,/* complain_on_overflow */
597 bfd_elf_generic_reloc, /* special_function */
598 "R_ARM_ALU_SBREL_19_12",/* name */
599 FALSE, /* partial_inplace */
600 0x000ff000, /* src_mask */
601 0x000ff000, /* dst_mask */
602 FALSE), /* pcrel_offset */
604 HOWTO (R_ARM_ALU_SBREL_27_20, /* type */
605 0, /* rightshift */
606 2, /* size (0 = byte, 1 = short, 2 = long) */
607 8, /* bitsize */
608 FALSE, /* pc_relative */
609 20, /* bitpos */
610 complain_overflow_dont,/* complain_on_overflow */
611 bfd_elf_generic_reloc, /* special_function */
612 "R_ARM_ALU_SBREL_27_20",/* name */
613 FALSE, /* partial_inplace */
614 0x0ff00000, /* src_mask */
615 0x0ff00000, /* dst_mask */
616 FALSE), /* pcrel_offset */
618 HOWTO (R_ARM_TARGET1, /* type */
619 0, /* rightshift */
620 2, /* size (0 = byte, 1 = short, 2 = long) */
621 32, /* bitsize */
622 FALSE, /* pc_relative */
623 0, /* bitpos */
624 complain_overflow_dont,/* complain_on_overflow */
625 bfd_elf_generic_reloc, /* special_function */
626 "R_ARM_TARGET1", /* name */
627 FALSE, /* partial_inplace */
628 0xffffffff, /* src_mask */
629 0xffffffff, /* dst_mask */
630 FALSE), /* pcrel_offset */
632 HOWTO (R_ARM_ROSEGREL32, /* type */
633 0, /* rightshift */
634 2, /* size (0 = byte, 1 = short, 2 = long) */
635 32, /* bitsize */
636 FALSE, /* pc_relative */
637 0, /* bitpos */
638 complain_overflow_dont,/* complain_on_overflow */
639 bfd_elf_generic_reloc, /* special_function */
640 "R_ARM_ROSEGREL32", /* name */
641 FALSE, /* partial_inplace */
642 0xffffffff, /* src_mask */
643 0xffffffff, /* dst_mask */
644 FALSE), /* pcrel_offset */
646 HOWTO (R_ARM_V4BX, /* type */
647 0, /* rightshift */
648 2, /* size (0 = byte, 1 = short, 2 = long) */
649 32, /* bitsize */
650 FALSE, /* pc_relative */
651 0, /* bitpos */
652 complain_overflow_dont,/* complain_on_overflow */
653 bfd_elf_generic_reloc, /* special_function */
654 "R_ARM_V4BX", /* name */
655 FALSE, /* partial_inplace */
656 0xffffffff, /* src_mask */
657 0xffffffff, /* dst_mask */
658 FALSE), /* pcrel_offset */
660 HOWTO (R_ARM_TARGET2, /* type */
661 0, /* rightshift */
662 2, /* size (0 = byte, 1 = short, 2 = long) */
663 32, /* bitsize */
664 FALSE, /* pc_relative */
665 0, /* bitpos */
666 complain_overflow_signed,/* complain_on_overflow */
667 bfd_elf_generic_reloc, /* special_function */
668 "R_ARM_TARGET2", /* name */
669 FALSE, /* partial_inplace */
670 0xffffffff, /* src_mask */
671 0xffffffff, /* dst_mask */
672 TRUE), /* pcrel_offset */
674 HOWTO (R_ARM_PREL31, /* type */
675 0, /* rightshift */
676 2, /* size (0 = byte, 1 = short, 2 = long) */
677 31, /* bitsize */
678 TRUE, /* pc_relative */
679 0, /* bitpos */
680 complain_overflow_signed,/* complain_on_overflow */
681 bfd_elf_generic_reloc, /* special_function */
682 "R_ARM_PREL31", /* name */
683 FALSE, /* partial_inplace */
684 0x7fffffff, /* src_mask */
685 0x7fffffff, /* dst_mask */
686 TRUE), /* pcrel_offset */
688 HOWTO (R_ARM_MOVW_ABS_NC, /* type */
689 0, /* rightshift */
690 2, /* size (0 = byte, 1 = short, 2 = long) */
691 16, /* bitsize */
692 FALSE, /* pc_relative */
693 0, /* bitpos */
694 complain_overflow_dont,/* complain_on_overflow */
695 bfd_elf_generic_reloc, /* special_function */
696 "R_ARM_MOVW_ABS_NC", /* name */
697 FALSE, /* partial_inplace */
698 0x0000ffff, /* src_mask */
699 0x0000ffff, /* dst_mask */
700 FALSE), /* pcrel_offset */
702 HOWTO (R_ARM_MOVT_ABS, /* type */
703 0, /* rightshift */
704 2, /* size (0 = byte, 1 = short, 2 = long) */
705 16, /* bitsize */
706 FALSE, /* pc_relative */
707 0, /* bitpos */
708 complain_overflow_bitfield,/* complain_on_overflow */
709 bfd_elf_generic_reloc, /* special_function */
710 "R_ARM_MOVT_ABS", /* name */
711 FALSE, /* partial_inplace */
712 0x0000ffff, /* src_mask */
713 0x0000ffff, /* dst_mask */
714 FALSE), /* pcrel_offset */
716 HOWTO (R_ARM_MOVW_PREL_NC, /* type */
717 0, /* rightshift */
718 2, /* size (0 = byte, 1 = short, 2 = long) */
719 16, /* bitsize */
720 TRUE, /* pc_relative */
721 0, /* bitpos */
722 complain_overflow_dont,/* complain_on_overflow */
723 bfd_elf_generic_reloc, /* special_function */
724 "R_ARM_MOVW_PREL_NC", /* name */
725 FALSE, /* partial_inplace */
726 0x0000ffff, /* src_mask */
727 0x0000ffff, /* dst_mask */
728 TRUE), /* pcrel_offset */
730 HOWTO (R_ARM_MOVT_PREL, /* type */
731 0, /* rightshift */
732 2, /* size (0 = byte, 1 = short, 2 = long) */
733 16, /* bitsize */
734 TRUE, /* pc_relative */
735 0, /* bitpos */
736 complain_overflow_bitfield,/* complain_on_overflow */
737 bfd_elf_generic_reloc, /* special_function */
738 "R_ARM_MOVT_PREL", /* name */
739 FALSE, /* partial_inplace */
740 0x0000ffff, /* src_mask */
741 0x0000ffff, /* dst_mask */
742 TRUE), /* pcrel_offset */
744 HOWTO (R_ARM_THM_MOVW_ABS_NC, /* type */
745 0, /* rightshift */
746 2, /* size (0 = byte, 1 = short, 2 = long) */
747 16, /* bitsize */
748 FALSE, /* pc_relative */
749 0, /* bitpos */
750 complain_overflow_dont,/* complain_on_overflow */
751 bfd_elf_generic_reloc, /* special_function */
752 "R_ARM_THM_MOVW_ABS_NC",/* name */
753 FALSE, /* partial_inplace */
754 0x040f70ff, /* src_mask */
755 0x040f70ff, /* dst_mask */
756 FALSE), /* pcrel_offset */
758 HOWTO (R_ARM_THM_MOVT_ABS, /* type */
759 0, /* rightshift */
760 2, /* size (0 = byte, 1 = short, 2 = long) */
761 16, /* bitsize */
762 FALSE, /* pc_relative */
763 0, /* bitpos */
764 complain_overflow_bitfield,/* complain_on_overflow */
765 bfd_elf_generic_reloc, /* special_function */
766 "R_ARM_THM_MOVT_ABS", /* name */
767 FALSE, /* partial_inplace */
768 0x040f70ff, /* src_mask */
769 0x040f70ff, /* dst_mask */
770 FALSE), /* pcrel_offset */
772 HOWTO (R_ARM_THM_MOVW_PREL_NC,/* type */
773 0, /* rightshift */
774 2, /* size (0 = byte, 1 = short, 2 = long) */
775 16, /* bitsize */
776 TRUE, /* pc_relative */
777 0, /* bitpos */
778 complain_overflow_dont,/* complain_on_overflow */
779 bfd_elf_generic_reloc, /* special_function */
780 "R_ARM_THM_MOVW_PREL_NC",/* name */
781 FALSE, /* partial_inplace */
782 0x040f70ff, /* src_mask */
783 0x040f70ff, /* dst_mask */
784 TRUE), /* pcrel_offset */
786 HOWTO (R_ARM_THM_MOVT_PREL, /* type */
787 0, /* rightshift */
788 2, /* size (0 = byte, 1 = short, 2 = long) */
789 16, /* bitsize */
790 TRUE, /* pc_relative */
791 0, /* bitpos */
792 complain_overflow_bitfield,/* complain_on_overflow */
793 bfd_elf_generic_reloc, /* special_function */
794 "R_ARM_THM_MOVT_PREL", /* name */
795 FALSE, /* partial_inplace */
796 0x040f70ff, /* src_mask */
797 0x040f70ff, /* dst_mask */
798 TRUE), /* pcrel_offset */
800 HOWTO (R_ARM_THM_JUMP19, /* type */
801 1, /* rightshift */
802 2, /* size (0 = byte, 1 = short, 2 = long) */
803 19, /* bitsize */
804 TRUE, /* pc_relative */
805 0, /* bitpos */
806 complain_overflow_signed,/* complain_on_overflow */
807 bfd_elf_generic_reloc, /* special_function */
808 "R_ARM_THM_JUMP19", /* name */
809 FALSE, /* partial_inplace */
810 0x043f2fff, /* src_mask */
811 0x043f2fff, /* dst_mask */
812 TRUE), /* pcrel_offset */
814 HOWTO (R_ARM_THM_JUMP6, /* type */
815 1, /* rightshift */
816 1, /* size (0 = byte, 1 = short, 2 = long) */
817 6, /* bitsize */
818 TRUE, /* pc_relative */
819 0, /* bitpos */
820 complain_overflow_unsigned,/* complain_on_overflow */
821 bfd_elf_generic_reloc, /* special_function */
822 "R_ARM_THM_JUMP6", /* name */
823 FALSE, /* partial_inplace */
824 0x02f8, /* src_mask */
825 0x02f8, /* dst_mask */
826 TRUE), /* pcrel_offset */
828 /* These are declared as 13-bit signed relocations because we can
829 address -4095 .. 4095(base) by altering ADDW to SUBW or vice
830 versa. */
831 HOWTO (R_ARM_THM_ALU_PREL_11_0,/* type */
832 0, /* rightshift */
833 2, /* size (0 = byte, 1 = short, 2 = long) */
834 13, /* bitsize */
835 TRUE, /* pc_relative */
836 0, /* bitpos */
837 complain_overflow_dont,/* complain_on_overflow */
838 bfd_elf_generic_reloc, /* special_function */
839 "R_ARM_THM_ALU_PREL_11_0",/* name */
840 FALSE, /* partial_inplace */
841 0xffffffff, /* src_mask */
842 0xffffffff, /* dst_mask */
843 TRUE), /* pcrel_offset */
845 HOWTO (R_ARM_THM_PC12, /* type */
846 0, /* rightshift */
847 2, /* size (0 = byte, 1 = short, 2 = long) */
848 13, /* bitsize */
849 TRUE, /* pc_relative */
850 0, /* bitpos */
851 complain_overflow_dont,/* complain_on_overflow */
852 bfd_elf_generic_reloc, /* special_function */
853 "R_ARM_THM_PC12", /* name */
854 FALSE, /* partial_inplace */
855 0xffffffff, /* src_mask */
856 0xffffffff, /* dst_mask */
857 TRUE), /* pcrel_offset */
859 HOWTO (R_ARM_ABS32_NOI, /* type */
860 0, /* rightshift */
861 2, /* size (0 = byte, 1 = short, 2 = long) */
862 32, /* bitsize */
863 FALSE, /* pc_relative */
864 0, /* bitpos */
865 complain_overflow_dont,/* complain_on_overflow */
866 bfd_elf_generic_reloc, /* special_function */
867 "R_ARM_ABS32_NOI", /* name */
868 FALSE, /* partial_inplace */
869 0xffffffff, /* src_mask */
870 0xffffffff, /* dst_mask */
871 FALSE), /* pcrel_offset */
873 HOWTO (R_ARM_REL32_NOI, /* type */
874 0, /* rightshift */
875 2, /* size (0 = byte, 1 = short, 2 = long) */
876 32, /* bitsize */
877 TRUE, /* pc_relative */
878 0, /* bitpos */
879 complain_overflow_dont,/* complain_on_overflow */
880 bfd_elf_generic_reloc, /* special_function */
881 "R_ARM_REL32_NOI", /* name */
882 FALSE, /* partial_inplace */
883 0xffffffff, /* src_mask */
884 0xffffffff, /* dst_mask */
885 FALSE), /* pcrel_offset */
887 /* Group relocations. */
889 HOWTO (R_ARM_ALU_PC_G0_NC, /* type */
890 0, /* rightshift */
891 2, /* size (0 = byte, 1 = short, 2 = long) */
892 32, /* bitsize */
893 TRUE, /* pc_relative */
894 0, /* bitpos */
895 complain_overflow_dont,/* complain_on_overflow */
896 bfd_elf_generic_reloc, /* special_function */
897 "R_ARM_ALU_PC_G0_NC", /* name */
898 FALSE, /* partial_inplace */
899 0xffffffff, /* src_mask */
900 0xffffffff, /* dst_mask */
901 TRUE), /* pcrel_offset */
903 HOWTO (R_ARM_ALU_PC_G0, /* type */
904 0, /* rightshift */
905 2, /* size (0 = byte, 1 = short, 2 = long) */
906 32, /* bitsize */
907 TRUE, /* pc_relative */
908 0, /* bitpos */
909 complain_overflow_dont,/* complain_on_overflow */
910 bfd_elf_generic_reloc, /* special_function */
911 "R_ARM_ALU_PC_G0", /* name */
912 FALSE, /* partial_inplace */
913 0xffffffff, /* src_mask */
914 0xffffffff, /* dst_mask */
915 TRUE), /* pcrel_offset */
917 HOWTO (R_ARM_ALU_PC_G1_NC, /* type */
918 0, /* rightshift */
919 2, /* size (0 = byte, 1 = short, 2 = long) */
920 32, /* bitsize */
921 TRUE, /* pc_relative */
922 0, /* bitpos */
923 complain_overflow_dont,/* complain_on_overflow */
924 bfd_elf_generic_reloc, /* special_function */
925 "R_ARM_ALU_PC_G1_NC", /* name */
926 FALSE, /* partial_inplace */
927 0xffffffff, /* src_mask */
928 0xffffffff, /* dst_mask */
929 TRUE), /* pcrel_offset */
931 HOWTO (R_ARM_ALU_PC_G1, /* type */
932 0, /* rightshift */
933 2, /* size (0 = byte, 1 = short, 2 = long) */
934 32, /* bitsize */
935 TRUE, /* pc_relative */
936 0, /* bitpos */
937 complain_overflow_dont,/* complain_on_overflow */
938 bfd_elf_generic_reloc, /* special_function */
939 "R_ARM_ALU_PC_G1", /* name */
940 FALSE, /* partial_inplace */
941 0xffffffff, /* src_mask */
942 0xffffffff, /* dst_mask */
943 TRUE), /* pcrel_offset */
945 HOWTO (R_ARM_ALU_PC_G2, /* type */
946 0, /* rightshift */
947 2, /* size (0 = byte, 1 = short, 2 = long) */
948 32, /* bitsize */
949 TRUE, /* pc_relative */
950 0, /* bitpos */
951 complain_overflow_dont,/* complain_on_overflow */
952 bfd_elf_generic_reloc, /* special_function */
953 "R_ARM_ALU_PC_G2", /* name */
954 FALSE, /* partial_inplace */
955 0xffffffff, /* src_mask */
956 0xffffffff, /* dst_mask */
957 TRUE), /* pcrel_offset */
959 HOWTO (R_ARM_LDR_PC_G1, /* type */
960 0, /* rightshift */
961 2, /* size (0 = byte, 1 = short, 2 = long) */
962 32, /* bitsize */
963 TRUE, /* pc_relative */
964 0, /* bitpos */
965 complain_overflow_dont,/* complain_on_overflow */
966 bfd_elf_generic_reloc, /* special_function */
967 "R_ARM_LDR_PC_G1", /* name */
968 FALSE, /* partial_inplace */
969 0xffffffff, /* src_mask */
970 0xffffffff, /* dst_mask */
971 TRUE), /* pcrel_offset */
973 HOWTO (R_ARM_LDR_PC_G2, /* type */
974 0, /* rightshift */
975 2, /* size (0 = byte, 1 = short, 2 = long) */
976 32, /* bitsize */
977 TRUE, /* pc_relative */
978 0, /* bitpos */
979 complain_overflow_dont,/* complain_on_overflow */
980 bfd_elf_generic_reloc, /* special_function */
981 "R_ARM_LDR_PC_G2", /* name */
982 FALSE, /* partial_inplace */
983 0xffffffff, /* src_mask */
984 0xffffffff, /* dst_mask */
985 TRUE), /* pcrel_offset */
987 HOWTO (R_ARM_LDRS_PC_G0, /* type */
988 0, /* rightshift */
989 2, /* size (0 = byte, 1 = short, 2 = long) */
990 32, /* bitsize */
991 TRUE, /* pc_relative */
992 0, /* bitpos */
993 complain_overflow_dont,/* complain_on_overflow */
994 bfd_elf_generic_reloc, /* special_function */
995 "R_ARM_LDRS_PC_G0", /* name */
996 FALSE, /* partial_inplace */
997 0xffffffff, /* src_mask */
998 0xffffffff, /* dst_mask */
999 TRUE), /* pcrel_offset */
1001 HOWTO (R_ARM_LDRS_PC_G1, /* type */
1002 0, /* rightshift */
1003 2, /* size (0 = byte, 1 = short, 2 = long) */
1004 32, /* bitsize */
1005 TRUE, /* pc_relative */
1006 0, /* bitpos */
1007 complain_overflow_dont,/* complain_on_overflow */
1008 bfd_elf_generic_reloc, /* special_function */
1009 "R_ARM_LDRS_PC_G1", /* name */
1010 FALSE, /* partial_inplace */
1011 0xffffffff, /* src_mask */
1012 0xffffffff, /* dst_mask */
1013 TRUE), /* pcrel_offset */
1015 HOWTO (R_ARM_LDRS_PC_G2, /* type */
1016 0, /* rightshift */
1017 2, /* size (0 = byte, 1 = short, 2 = long) */
1018 32, /* bitsize */
1019 TRUE, /* pc_relative */
1020 0, /* bitpos */
1021 complain_overflow_dont,/* complain_on_overflow */
1022 bfd_elf_generic_reloc, /* special_function */
1023 "R_ARM_LDRS_PC_G2", /* name */
1024 FALSE, /* partial_inplace */
1025 0xffffffff, /* src_mask */
1026 0xffffffff, /* dst_mask */
1027 TRUE), /* pcrel_offset */
1029 HOWTO (R_ARM_LDC_PC_G0, /* type */
1030 0, /* rightshift */
1031 2, /* size (0 = byte, 1 = short, 2 = long) */
1032 32, /* bitsize */
1033 TRUE, /* pc_relative */
1034 0, /* bitpos */
1035 complain_overflow_dont,/* complain_on_overflow */
1036 bfd_elf_generic_reloc, /* special_function */
1037 "R_ARM_LDC_PC_G0", /* name */
1038 FALSE, /* partial_inplace */
1039 0xffffffff, /* src_mask */
1040 0xffffffff, /* dst_mask */
1041 TRUE), /* pcrel_offset */
1043 HOWTO (R_ARM_LDC_PC_G1, /* type */
1044 0, /* rightshift */
1045 2, /* size (0 = byte, 1 = short, 2 = long) */
1046 32, /* bitsize */
1047 TRUE, /* pc_relative */
1048 0, /* bitpos */
1049 complain_overflow_dont,/* complain_on_overflow */
1050 bfd_elf_generic_reloc, /* special_function */
1051 "R_ARM_LDC_PC_G1", /* name */
1052 FALSE, /* partial_inplace */
1053 0xffffffff, /* src_mask */
1054 0xffffffff, /* dst_mask */
1055 TRUE), /* pcrel_offset */
1057 HOWTO (R_ARM_LDC_PC_G2, /* type */
1058 0, /* rightshift */
1059 2, /* size (0 = byte, 1 = short, 2 = long) */
1060 32, /* bitsize */
1061 TRUE, /* pc_relative */
1062 0, /* bitpos */
1063 complain_overflow_dont,/* complain_on_overflow */
1064 bfd_elf_generic_reloc, /* special_function */
1065 "R_ARM_LDC_PC_G2", /* name */
1066 FALSE, /* partial_inplace */
1067 0xffffffff, /* src_mask */
1068 0xffffffff, /* dst_mask */
1069 TRUE), /* pcrel_offset */
1071 HOWTO (R_ARM_ALU_SB_G0_NC, /* type */
1072 0, /* rightshift */
1073 2, /* size (0 = byte, 1 = short, 2 = long) */
1074 32, /* bitsize */
1075 TRUE, /* pc_relative */
1076 0, /* bitpos */
1077 complain_overflow_dont,/* complain_on_overflow */
1078 bfd_elf_generic_reloc, /* special_function */
1079 "R_ARM_ALU_SB_G0_NC", /* name */
1080 FALSE, /* partial_inplace */
1081 0xffffffff, /* src_mask */
1082 0xffffffff, /* dst_mask */
1083 TRUE), /* pcrel_offset */
1085 HOWTO (R_ARM_ALU_SB_G0, /* type */
1086 0, /* rightshift */
1087 2, /* size (0 = byte, 1 = short, 2 = long) */
1088 32, /* bitsize */
1089 TRUE, /* pc_relative */
1090 0, /* bitpos */
1091 complain_overflow_dont,/* complain_on_overflow */
1092 bfd_elf_generic_reloc, /* special_function */
1093 "R_ARM_ALU_SB_G0", /* name */
1094 FALSE, /* partial_inplace */
1095 0xffffffff, /* src_mask */
1096 0xffffffff, /* dst_mask */
1097 TRUE), /* pcrel_offset */
1099 HOWTO (R_ARM_ALU_SB_G1_NC, /* type */
1100 0, /* rightshift */
1101 2, /* size (0 = byte, 1 = short, 2 = long) */
1102 32, /* bitsize */
1103 TRUE, /* pc_relative */
1104 0, /* bitpos */
1105 complain_overflow_dont,/* complain_on_overflow */
1106 bfd_elf_generic_reloc, /* special_function */
1107 "R_ARM_ALU_SB_G1_NC", /* name */
1108 FALSE, /* partial_inplace */
1109 0xffffffff, /* src_mask */
1110 0xffffffff, /* dst_mask */
1111 TRUE), /* pcrel_offset */
1113 HOWTO (R_ARM_ALU_SB_G1, /* type */
1114 0, /* rightshift */
1115 2, /* size (0 = byte, 1 = short, 2 = long) */
1116 32, /* bitsize */
1117 TRUE, /* pc_relative */
1118 0, /* bitpos */
1119 complain_overflow_dont,/* complain_on_overflow */
1120 bfd_elf_generic_reloc, /* special_function */
1121 "R_ARM_ALU_SB_G1", /* name */
1122 FALSE, /* partial_inplace */
1123 0xffffffff, /* src_mask */
1124 0xffffffff, /* dst_mask */
1125 TRUE), /* pcrel_offset */
1127 HOWTO (R_ARM_ALU_SB_G2, /* type */
1128 0, /* rightshift */
1129 2, /* size (0 = byte, 1 = short, 2 = long) */
1130 32, /* bitsize */
1131 TRUE, /* pc_relative */
1132 0, /* bitpos */
1133 complain_overflow_dont,/* complain_on_overflow */
1134 bfd_elf_generic_reloc, /* special_function */
1135 "R_ARM_ALU_SB_G2", /* name */
1136 FALSE, /* partial_inplace */
1137 0xffffffff, /* src_mask */
1138 0xffffffff, /* dst_mask */
1139 TRUE), /* pcrel_offset */
1141 HOWTO (R_ARM_LDR_SB_G0, /* type */
1142 0, /* rightshift */
1143 2, /* size (0 = byte, 1 = short, 2 = long) */
1144 32, /* bitsize */
1145 TRUE, /* pc_relative */
1146 0, /* bitpos */
1147 complain_overflow_dont,/* complain_on_overflow */
1148 bfd_elf_generic_reloc, /* special_function */
1149 "R_ARM_LDR_SB_G0", /* name */
1150 FALSE, /* partial_inplace */
1151 0xffffffff, /* src_mask */
1152 0xffffffff, /* dst_mask */
1153 TRUE), /* pcrel_offset */
1155 HOWTO (R_ARM_LDR_SB_G1, /* type */
1156 0, /* rightshift */
1157 2, /* size (0 = byte, 1 = short, 2 = long) */
1158 32, /* bitsize */
1159 TRUE, /* pc_relative */
1160 0, /* bitpos */
1161 complain_overflow_dont,/* complain_on_overflow */
1162 bfd_elf_generic_reloc, /* special_function */
1163 "R_ARM_LDR_SB_G1", /* name */
1164 FALSE, /* partial_inplace */
1165 0xffffffff, /* src_mask */
1166 0xffffffff, /* dst_mask */
1167 TRUE), /* pcrel_offset */
1169 HOWTO (R_ARM_LDR_SB_G2, /* type */
1170 0, /* rightshift */
1171 2, /* size (0 = byte, 1 = short, 2 = long) */
1172 32, /* bitsize */
1173 TRUE, /* pc_relative */
1174 0, /* bitpos */
1175 complain_overflow_dont,/* complain_on_overflow */
1176 bfd_elf_generic_reloc, /* special_function */
1177 "R_ARM_LDR_SB_G2", /* name */
1178 FALSE, /* partial_inplace */
1179 0xffffffff, /* src_mask */
1180 0xffffffff, /* dst_mask */
1181 TRUE), /* pcrel_offset */
1183 HOWTO (R_ARM_LDRS_SB_G0, /* type */
1184 0, /* rightshift */
1185 2, /* size (0 = byte, 1 = short, 2 = long) */
1186 32, /* bitsize */
1187 TRUE, /* pc_relative */
1188 0, /* bitpos */
1189 complain_overflow_dont,/* complain_on_overflow */
1190 bfd_elf_generic_reloc, /* special_function */
1191 "R_ARM_LDRS_SB_G0", /* name */
1192 FALSE, /* partial_inplace */
1193 0xffffffff, /* src_mask */
1194 0xffffffff, /* dst_mask */
1195 TRUE), /* pcrel_offset */
1197 HOWTO (R_ARM_LDRS_SB_G1, /* type */
1198 0, /* rightshift */
1199 2, /* size (0 = byte, 1 = short, 2 = long) */
1200 32, /* bitsize */
1201 TRUE, /* pc_relative */
1202 0, /* bitpos */
1203 complain_overflow_dont,/* complain_on_overflow */
1204 bfd_elf_generic_reloc, /* special_function */
1205 "R_ARM_LDRS_SB_G1", /* name */
1206 FALSE, /* partial_inplace */
1207 0xffffffff, /* src_mask */
1208 0xffffffff, /* dst_mask */
1209 TRUE), /* pcrel_offset */
1211 HOWTO (R_ARM_LDRS_SB_G2, /* type */
1212 0, /* rightshift */
1213 2, /* size (0 = byte, 1 = short, 2 = long) */
1214 32, /* bitsize */
1215 TRUE, /* pc_relative */
1216 0, /* bitpos */
1217 complain_overflow_dont,/* complain_on_overflow */
1218 bfd_elf_generic_reloc, /* special_function */
1219 "R_ARM_LDRS_SB_G2", /* name */
1220 FALSE, /* partial_inplace */
1221 0xffffffff, /* src_mask */
1222 0xffffffff, /* dst_mask */
1223 TRUE), /* pcrel_offset */
1225 HOWTO (R_ARM_LDC_SB_G0, /* type */
1226 0, /* rightshift */
1227 2, /* size (0 = byte, 1 = short, 2 = long) */
1228 32, /* bitsize */
1229 TRUE, /* pc_relative */
1230 0, /* bitpos */
1231 complain_overflow_dont,/* complain_on_overflow */
1232 bfd_elf_generic_reloc, /* special_function */
1233 "R_ARM_LDC_SB_G0", /* name */
1234 FALSE, /* partial_inplace */
1235 0xffffffff, /* src_mask */
1236 0xffffffff, /* dst_mask */
1237 TRUE), /* pcrel_offset */
1239 HOWTO (R_ARM_LDC_SB_G1, /* type */
1240 0, /* rightshift */
1241 2, /* size (0 = byte, 1 = short, 2 = long) */
1242 32, /* bitsize */
1243 TRUE, /* pc_relative */
1244 0, /* bitpos */
1245 complain_overflow_dont,/* complain_on_overflow */
1246 bfd_elf_generic_reloc, /* special_function */
1247 "R_ARM_LDC_SB_G1", /* name */
1248 FALSE, /* partial_inplace */
1249 0xffffffff, /* src_mask */
1250 0xffffffff, /* dst_mask */
1251 TRUE), /* pcrel_offset */
1253 HOWTO (R_ARM_LDC_SB_G2, /* type */
1254 0, /* rightshift */
1255 2, /* size (0 = byte, 1 = short, 2 = long) */
1256 32, /* bitsize */
1257 TRUE, /* pc_relative */
1258 0, /* bitpos */
1259 complain_overflow_dont,/* complain_on_overflow */
1260 bfd_elf_generic_reloc, /* special_function */
1261 "R_ARM_LDC_SB_G2", /* name */
1262 FALSE, /* partial_inplace */
1263 0xffffffff, /* src_mask */
1264 0xffffffff, /* dst_mask */
1265 TRUE), /* pcrel_offset */
1267 /* End of group relocations. */
1269 HOWTO (R_ARM_MOVW_BREL_NC, /* type */
1270 0, /* rightshift */
1271 2, /* size (0 = byte, 1 = short, 2 = long) */
1272 16, /* bitsize */
1273 FALSE, /* pc_relative */
1274 0, /* bitpos */
1275 complain_overflow_dont,/* complain_on_overflow */
1276 bfd_elf_generic_reloc, /* special_function */
1277 "R_ARM_MOVW_BREL_NC", /* name */
1278 FALSE, /* partial_inplace */
1279 0x0000ffff, /* src_mask */
1280 0x0000ffff, /* dst_mask */
1281 FALSE), /* pcrel_offset */
1283 HOWTO (R_ARM_MOVT_BREL, /* type */
1284 0, /* rightshift */
1285 2, /* size (0 = byte, 1 = short, 2 = long) */
1286 16, /* bitsize */
1287 FALSE, /* pc_relative */
1288 0, /* bitpos */
1289 complain_overflow_bitfield,/* complain_on_overflow */
1290 bfd_elf_generic_reloc, /* special_function */
1291 "R_ARM_MOVT_BREL", /* name */
1292 FALSE, /* partial_inplace */
1293 0x0000ffff, /* src_mask */
1294 0x0000ffff, /* dst_mask */
1295 FALSE), /* pcrel_offset */
1297 HOWTO (R_ARM_MOVW_BREL, /* type */
1298 0, /* rightshift */
1299 2, /* size (0 = byte, 1 = short, 2 = long) */
1300 16, /* bitsize */
1301 FALSE, /* pc_relative */
1302 0, /* bitpos */
1303 complain_overflow_dont,/* complain_on_overflow */
1304 bfd_elf_generic_reloc, /* special_function */
1305 "R_ARM_MOVW_BREL", /* name */
1306 FALSE, /* partial_inplace */
1307 0x0000ffff, /* src_mask */
1308 0x0000ffff, /* dst_mask */
1309 FALSE), /* pcrel_offset */
1311 HOWTO (R_ARM_THM_MOVW_BREL_NC,/* type */
1312 0, /* rightshift */
1313 2, /* size (0 = byte, 1 = short, 2 = long) */
1314 16, /* bitsize */
1315 FALSE, /* pc_relative */
1316 0, /* bitpos */
1317 complain_overflow_dont,/* complain_on_overflow */
1318 bfd_elf_generic_reloc, /* special_function */
1319 "R_ARM_THM_MOVW_BREL_NC",/* name */
1320 FALSE, /* partial_inplace */
1321 0x040f70ff, /* src_mask */
1322 0x040f70ff, /* dst_mask */
1323 FALSE), /* pcrel_offset */
1325 HOWTO (R_ARM_THM_MOVT_BREL, /* type */
1326 0, /* rightshift */
1327 2, /* size (0 = byte, 1 = short, 2 = long) */
1328 16, /* bitsize */
1329 FALSE, /* pc_relative */
1330 0, /* bitpos */
1331 complain_overflow_bitfield,/* complain_on_overflow */
1332 bfd_elf_generic_reloc, /* special_function */
1333 "R_ARM_THM_MOVT_BREL", /* name */
1334 FALSE, /* partial_inplace */
1335 0x040f70ff, /* src_mask */
1336 0x040f70ff, /* dst_mask */
1337 FALSE), /* pcrel_offset */
1339 HOWTO (R_ARM_THM_MOVW_BREL, /* type */
1340 0, /* rightshift */
1341 2, /* size (0 = byte, 1 = short, 2 = long) */
1342 16, /* bitsize */
1343 FALSE, /* pc_relative */
1344 0, /* bitpos */
1345 complain_overflow_dont,/* complain_on_overflow */
1346 bfd_elf_generic_reloc, /* special_function */
1347 "R_ARM_THM_MOVW_BREL", /* name */
1348 FALSE, /* partial_inplace */
1349 0x040f70ff, /* src_mask */
1350 0x040f70ff, /* dst_mask */
1351 FALSE), /* pcrel_offset */
1353 EMPTY_HOWTO (90), /* unallocated */
1354 EMPTY_HOWTO (91),
1355 EMPTY_HOWTO (92),
1356 EMPTY_HOWTO (93),
1358 HOWTO (R_ARM_PLT32_ABS, /* type */
1359 0, /* rightshift */
1360 2, /* size (0 = byte, 1 = short, 2 = long) */
1361 32, /* bitsize */
1362 FALSE, /* pc_relative */
1363 0, /* bitpos */
1364 complain_overflow_dont,/* complain_on_overflow */
1365 bfd_elf_generic_reloc, /* special_function */
1366 "R_ARM_PLT32_ABS", /* name */
1367 FALSE, /* partial_inplace */
1368 0xffffffff, /* src_mask */
1369 0xffffffff, /* dst_mask */
1370 FALSE), /* pcrel_offset */
1372 HOWTO (R_ARM_GOT_ABS, /* type */
1373 0, /* rightshift */
1374 2, /* size (0 = byte, 1 = short, 2 = long) */
1375 32, /* bitsize */
1376 FALSE, /* pc_relative */
1377 0, /* bitpos */
1378 complain_overflow_dont,/* complain_on_overflow */
1379 bfd_elf_generic_reloc, /* special_function */
1380 "R_ARM_GOT_ABS", /* name */
1381 FALSE, /* partial_inplace */
1382 0xffffffff, /* src_mask */
1383 0xffffffff, /* dst_mask */
1384 FALSE), /* pcrel_offset */
1386 HOWTO (R_ARM_GOT_PREL, /* type */
1387 0, /* rightshift */
1388 2, /* size (0 = byte, 1 = short, 2 = long) */
1389 32, /* bitsize */
1390 TRUE, /* pc_relative */
1391 0, /* bitpos */
1392 complain_overflow_dont, /* complain_on_overflow */
1393 bfd_elf_generic_reloc, /* special_function */
1394 "R_ARM_GOT_PREL", /* name */
1395 FALSE, /* partial_inplace */
1396 0xffffffff, /* src_mask */
1397 0xffffffff, /* dst_mask */
1398 TRUE), /* pcrel_offset */
1400 HOWTO (R_ARM_GOT_BREL12, /* type */
1401 0, /* rightshift */
1402 2, /* size (0 = byte, 1 = short, 2 = long) */
1403 12, /* bitsize */
1404 FALSE, /* pc_relative */
1405 0, /* bitpos */
1406 complain_overflow_bitfield,/* complain_on_overflow */
1407 bfd_elf_generic_reloc, /* special_function */
1408 "R_ARM_GOT_BREL12", /* name */
1409 FALSE, /* partial_inplace */
1410 0x00000fff, /* src_mask */
1411 0x00000fff, /* dst_mask */
1412 FALSE), /* pcrel_offset */
1414 HOWTO (R_ARM_GOTOFF12, /* type */
1415 0, /* rightshift */
1416 2, /* size (0 = byte, 1 = short, 2 = long) */
1417 12, /* bitsize */
1418 FALSE, /* pc_relative */
1419 0, /* bitpos */
1420 complain_overflow_bitfield,/* complain_on_overflow */
1421 bfd_elf_generic_reloc, /* special_function */
1422 "R_ARM_GOTOFF12", /* name */
1423 FALSE, /* partial_inplace */
1424 0x00000fff, /* src_mask */
1425 0x00000fff, /* dst_mask */
1426 FALSE), /* pcrel_offset */
1428 EMPTY_HOWTO (R_ARM_GOTRELAX), /* reserved for future GOT-load optimizations */
1430 /* GNU extension to record C++ vtable member usage */
1431 HOWTO (R_ARM_GNU_VTENTRY, /* type */
1432 0, /* rightshift */
1433 2, /* size (0 = byte, 1 = short, 2 = long) */
1434 0, /* bitsize */
1435 FALSE, /* pc_relative */
1436 0, /* bitpos */
1437 complain_overflow_dont, /* complain_on_overflow */
1438 _bfd_elf_rel_vtable_reloc_fn, /* special_function */
1439 "R_ARM_GNU_VTENTRY", /* name */
1440 FALSE, /* partial_inplace */
1441 0, /* src_mask */
1442 0, /* dst_mask */
1443 FALSE), /* pcrel_offset */
1445 /* GNU extension to record C++ vtable hierarchy */
1446 HOWTO (R_ARM_GNU_VTINHERIT, /* type */
1447 0, /* rightshift */
1448 2, /* size (0 = byte, 1 = short, 2 = long) */
1449 0, /* bitsize */
1450 FALSE, /* pc_relative */
1451 0, /* bitpos */
1452 complain_overflow_dont, /* complain_on_overflow */
1453 NULL, /* special_function */
1454 "R_ARM_GNU_VTINHERIT", /* name */
1455 FALSE, /* partial_inplace */
1456 0, /* src_mask */
1457 0, /* dst_mask */
1458 FALSE), /* pcrel_offset */
1460 HOWTO (R_ARM_THM_JUMP11, /* type */
1461 1, /* rightshift */
1462 1, /* size (0 = byte, 1 = short, 2 = long) */
1463 11, /* bitsize */
1464 TRUE, /* pc_relative */
1465 0, /* bitpos */
1466 complain_overflow_signed, /* complain_on_overflow */
1467 bfd_elf_generic_reloc, /* special_function */
1468 "R_ARM_THM_JUMP11", /* name */
1469 FALSE, /* partial_inplace */
1470 0x000007ff, /* src_mask */
1471 0x000007ff, /* dst_mask */
1472 TRUE), /* pcrel_offset */
1474 HOWTO (R_ARM_THM_JUMP8, /* type */
1475 1, /* rightshift */
1476 1, /* size (0 = byte, 1 = short, 2 = long) */
1477 8, /* bitsize */
1478 TRUE, /* pc_relative */
1479 0, /* bitpos */
1480 complain_overflow_signed, /* complain_on_overflow */
1481 bfd_elf_generic_reloc, /* special_function */
1482 "R_ARM_THM_JUMP8", /* name */
1483 FALSE, /* partial_inplace */
1484 0x000000ff, /* src_mask */
1485 0x000000ff, /* dst_mask */
1486 TRUE), /* pcrel_offset */
1488 /* TLS relocations */
1489 HOWTO (R_ARM_TLS_GD32, /* type */
1490 0, /* rightshift */
1491 2, /* size (0 = byte, 1 = short, 2 = long) */
1492 32, /* bitsize */
1493 FALSE, /* pc_relative */
1494 0, /* bitpos */
1495 complain_overflow_bitfield,/* complain_on_overflow */
1496 NULL, /* special_function */
1497 "R_ARM_TLS_GD32", /* name */
1498 TRUE, /* partial_inplace */
1499 0xffffffff, /* src_mask */
1500 0xffffffff, /* dst_mask */
1501 FALSE), /* pcrel_offset */
1503 HOWTO (R_ARM_TLS_LDM32, /* type */
1504 0, /* rightshift */
1505 2, /* size (0 = byte, 1 = short, 2 = long) */
1506 32, /* bitsize */
1507 FALSE, /* pc_relative */
1508 0, /* bitpos */
1509 complain_overflow_bitfield,/* complain_on_overflow */
1510 bfd_elf_generic_reloc, /* special_function */
1511 "R_ARM_TLS_LDM32", /* name */
1512 TRUE, /* partial_inplace */
1513 0xffffffff, /* src_mask */
1514 0xffffffff, /* dst_mask */
1515 FALSE), /* pcrel_offset */
1517 HOWTO (R_ARM_TLS_LDO32, /* type */
1518 0, /* rightshift */
1519 2, /* size (0 = byte, 1 = short, 2 = long) */
1520 32, /* bitsize */
1521 FALSE, /* pc_relative */
1522 0, /* bitpos */
1523 complain_overflow_bitfield,/* complain_on_overflow */
1524 bfd_elf_generic_reloc, /* special_function */
1525 "R_ARM_TLS_LDO32", /* name */
1526 TRUE, /* partial_inplace */
1527 0xffffffff, /* src_mask */
1528 0xffffffff, /* dst_mask */
1529 FALSE), /* pcrel_offset */
1531 HOWTO (R_ARM_TLS_IE32, /* type */
1532 0, /* rightshift */
1533 2, /* size (0 = byte, 1 = short, 2 = long) */
1534 32, /* bitsize */
1535 FALSE, /* pc_relative */
1536 0, /* bitpos */
1537 complain_overflow_bitfield,/* complain_on_overflow */
1538 NULL, /* special_function */
1539 "R_ARM_TLS_IE32", /* name */
1540 TRUE, /* partial_inplace */
1541 0xffffffff, /* src_mask */
1542 0xffffffff, /* dst_mask */
1543 FALSE), /* pcrel_offset */
1545 HOWTO (R_ARM_TLS_LE32, /* type */
1546 0, /* rightshift */
1547 2, /* size (0 = byte, 1 = short, 2 = long) */
1548 32, /* bitsize */
1549 FALSE, /* pc_relative */
1550 0, /* bitpos */
1551 complain_overflow_bitfield,/* complain_on_overflow */
1552 bfd_elf_generic_reloc, /* special_function */
1553 "R_ARM_TLS_LE32", /* name */
1554 TRUE, /* partial_inplace */
1555 0xffffffff, /* src_mask */
1556 0xffffffff, /* dst_mask */
1557 FALSE), /* pcrel_offset */
1559 HOWTO (R_ARM_TLS_LDO12, /* type */
1560 0, /* rightshift */
1561 2, /* size (0 = byte, 1 = short, 2 = long) */
1562 12, /* bitsize */
1563 FALSE, /* pc_relative */
1564 0, /* bitpos */
1565 complain_overflow_bitfield,/* complain_on_overflow */
1566 bfd_elf_generic_reloc, /* special_function */
1567 "R_ARM_TLS_LDO12", /* name */
1568 FALSE, /* partial_inplace */
1569 0x00000fff, /* src_mask */
1570 0x00000fff, /* dst_mask */
1571 FALSE), /* pcrel_offset */
1573 HOWTO (R_ARM_TLS_LE12, /* type */
1574 0, /* rightshift */
1575 2, /* size (0 = byte, 1 = short, 2 = long) */
1576 12, /* bitsize */
1577 FALSE, /* pc_relative */
1578 0, /* bitpos */
1579 complain_overflow_bitfield,/* complain_on_overflow */
1580 bfd_elf_generic_reloc, /* special_function */
1581 "R_ARM_TLS_LE12", /* name */
1582 FALSE, /* partial_inplace */
1583 0x00000fff, /* src_mask */
1584 0x00000fff, /* dst_mask */
1585 FALSE), /* pcrel_offset */
1587 HOWTO (R_ARM_TLS_IE12GP, /* type */
1588 0, /* rightshift */
1589 2, /* size (0 = byte, 1 = short, 2 = long) */
1590 12, /* bitsize */
1591 FALSE, /* pc_relative */
1592 0, /* bitpos */
1593 complain_overflow_bitfield,/* complain_on_overflow */
1594 bfd_elf_generic_reloc, /* special_function */
1595 "R_ARM_TLS_IE12GP", /* name */
1596 FALSE, /* partial_inplace */
1597 0x00000fff, /* src_mask */
1598 0x00000fff, /* dst_mask */
1599 FALSE), /* pcrel_offset */
1602 /* 112-127 private relocations
1603 128 R_ARM_ME_TOO, obsolete
1604 129-255 unallocated in AAELF.
1606 249-255 extended, currently unused, relocations: */
1608 static reloc_howto_type elf32_arm_howto_table_2[4] =
1610 HOWTO (R_ARM_RREL32, /* type */
1611 0, /* rightshift */
1612 0, /* size (0 = byte, 1 = short, 2 = long) */
1613 0, /* bitsize */
1614 FALSE, /* pc_relative */
1615 0, /* bitpos */
1616 complain_overflow_dont,/* complain_on_overflow */
1617 bfd_elf_generic_reloc, /* special_function */
1618 "R_ARM_RREL32", /* name */
1619 FALSE, /* partial_inplace */
1620 0, /* src_mask */
1621 0, /* dst_mask */
1622 FALSE), /* pcrel_offset */
1624 HOWTO (R_ARM_RABS32, /* type */
1625 0, /* rightshift */
1626 0, /* size (0 = byte, 1 = short, 2 = long) */
1627 0, /* bitsize */
1628 FALSE, /* pc_relative */
1629 0, /* bitpos */
1630 complain_overflow_dont,/* complain_on_overflow */
1631 bfd_elf_generic_reloc, /* special_function */
1632 "R_ARM_RABS32", /* name */
1633 FALSE, /* partial_inplace */
1634 0, /* src_mask */
1635 0, /* dst_mask */
1636 FALSE), /* pcrel_offset */
1638 HOWTO (R_ARM_RPC24, /* type */
1639 0, /* rightshift */
1640 0, /* size (0 = byte, 1 = short, 2 = long) */
1641 0, /* bitsize */
1642 FALSE, /* pc_relative */
1643 0, /* bitpos */
1644 complain_overflow_dont,/* complain_on_overflow */
1645 bfd_elf_generic_reloc, /* special_function */
1646 "R_ARM_RPC24", /* name */
1647 FALSE, /* partial_inplace */
1648 0, /* src_mask */
1649 0, /* dst_mask */
1650 FALSE), /* pcrel_offset */
1652 HOWTO (R_ARM_RBASE, /* type */
1653 0, /* rightshift */
1654 0, /* size (0 = byte, 1 = short, 2 = long) */
1655 0, /* bitsize */
1656 FALSE, /* pc_relative */
1657 0, /* bitpos */
1658 complain_overflow_dont,/* complain_on_overflow */
1659 bfd_elf_generic_reloc, /* special_function */
1660 "R_ARM_RBASE", /* name */
1661 FALSE, /* partial_inplace */
1662 0, /* src_mask */
1663 0, /* dst_mask */
1664 FALSE) /* pcrel_offset */
1667 static reloc_howto_type *
1668 elf32_arm_howto_from_type (unsigned int r_type)
1670 if (r_type < NUM_ELEM (elf32_arm_howto_table_1))
1671 return &elf32_arm_howto_table_1[r_type];
1673 if (r_type >= R_ARM_RREL32
1674 && r_type < R_ARM_RREL32 + NUM_ELEM (elf32_arm_howto_table_2))
1675 return &elf32_arm_howto_table_2[r_type - R_ARM_RREL32];
1677 return NULL;
1680 static void
1681 elf32_arm_info_to_howto (bfd * abfd ATTRIBUTE_UNUSED, arelent * bfd_reloc,
1682 Elf_Internal_Rela * elf_reloc)
1684 unsigned int r_type;
1686 r_type = ELF32_R_TYPE (elf_reloc->r_info);
1687 bfd_reloc->howto = elf32_arm_howto_from_type (r_type);
1690 struct elf32_arm_reloc_map
1692 bfd_reloc_code_real_type bfd_reloc_val;
1693 unsigned char elf_reloc_val;
1696 /* All entries in this list must also be present in elf32_arm_howto_table. */
1697 static const struct elf32_arm_reloc_map elf32_arm_reloc_map[] =
1699 {BFD_RELOC_NONE, R_ARM_NONE},
1700 {BFD_RELOC_ARM_PCREL_BRANCH, R_ARM_PC24},
1701 {BFD_RELOC_ARM_PCREL_CALL, R_ARM_CALL},
1702 {BFD_RELOC_ARM_PCREL_JUMP, R_ARM_JUMP24},
1703 {BFD_RELOC_ARM_PCREL_BLX, R_ARM_XPC25},
1704 {BFD_RELOC_THUMB_PCREL_BLX, R_ARM_THM_XPC22},
1705 {BFD_RELOC_32, R_ARM_ABS32},
1706 {BFD_RELOC_32_PCREL, R_ARM_REL32},
1707 {BFD_RELOC_8, R_ARM_ABS8},
1708 {BFD_RELOC_16, R_ARM_ABS16},
1709 {BFD_RELOC_ARM_OFFSET_IMM, R_ARM_ABS12},
1710 {BFD_RELOC_ARM_THUMB_OFFSET, R_ARM_THM_ABS5},
1711 {BFD_RELOC_THUMB_PCREL_BRANCH25, R_ARM_THM_JUMP24},
1712 {BFD_RELOC_THUMB_PCREL_BRANCH23, R_ARM_THM_CALL},
1713 {BFD_RELOC_THUMB_PCREL_BRANCH12, R_ARM_THM_JUMP11},
1714 {BFD_RELOC_THUMB_PCREL_BRANCH20, R_ARM_THM_JUMP19},
1715 {BFD_RELOC_THUMB_PCREL_BRANCH9, R_ARM_THM_JUMP8},
1716 {BFD_RELOC_THUMB_PCREL_BRANCH7, R_ARM_THM_JUMP6},
1717 {BFD_RELOC_ARM_GLOB_DAT, R_ARM_GLOB_DAT},
1718 {BFD_RELOC_ARM_JUMP_SLOT, R_ARM_JUMP_SLOT},
1719 {BFD_RELOC_ARM_RELATIVE, R_ARM_RELATIVE},
1720 {BFD_RELOC_ARM_GOTOFF, R_ARM_GOTOFF32},
1721 {BFD_RELOC_ARM_GOTPC, R_ARM_GOTPC},
1722 {BFD_RELOC_ARM_GOT32, R_ARM_GOT32},
1723 {BFD_RELOC_ARM_PLT32, R_ARM_PLT32},
1724 {BFD_RELOC_ARM_TARGET1, R_ARM_TARGET1},
1725 {BFD_RELOC_ARM_ROSEGREL32, R_ARM_ROSEGREL32},
1726 {BFD_RELOC_ARM_SBREL32, R_ARM_SBREL32},
1727 {BFD_RELOC_ARM_PREL31, R_ARM_PREL31},
1728 {BFD_RELOC_ARM_TARGET2, R_ARM_TARGET2},
1729 {BFD_RELOC_ARM_PLT32, R_ARM_PLT32},
1730 {BFD_RELOC_ARM_TLS_GD32, R_ARM_TLS_GD32},
1731 {BFD_RELOC_ARM_TLS_LDO32, R_ARM_TLS_LDO32},
1732 {BFD_RELOC_ARM_TLS_LDM32, R_ARM_TLS_LDM32},
1733 {BFD_RELOC_ARM_TLS_DTPMOD32, R_ARM_TLS_DTPMOD32},
1734 {BFD_RELOC_ARM_TLS_DTPOFF32, R_ARM_TLS_DTPOFF32},
1735 {BFD_RELOC_ARM_TLS_TPOFF32, R_ARM_TLS_TPOFF32},
1736 {BFD_RELOC_ARM_TLS_IE32, R_ARM_TLS_IE32},
1737 {BFD_RELOC_ARM_TLS_LE32, R_ARM_TLS_LE32},
1738 {BFD_RELOC_VTABLE_INHERIT, R_ARM_GNU_VTINHERIT},
1739 {BFD_RELOC_VTABLE_ENTRY, R_ARM_GNU_VTENTRY},
1740 {BFD_RELOC_ARM_MOVW, R_ARM_MOVW_ABS_NC},
1741 {BFD_RELOC_ARM_MOVT, R_ARM_MOVT_ABS},
1742 {BFD_RELOC_ARM_MOVW_PCREL, R_ARM_MOVW_PREL_NC},
1743 {BFD_RELOC_ARM_MOVT_PCREL, R_ARM_MOVT_PREL},
1744 {BFD_RELOC_ARM_THUMB_MOVW, R_ARM_THM_MOVW_ABS_NC},
1745 {BFD_RELOC_ARM_THUMB_MOVT, R_ARM_THM_MOVT_ABS},
1746 {BFD_RELOC_ARM_THUMB_MOVW_PCREL, R_ARM_THM_MOVW_PREL_NC},
1747 {BFD_RELOC_ARM_THUMB_MOVT_PCREL, R_ARM_THM_MOVT_PREL},
1748 {BFD_RELOC_ARM_ALU_PC_G0_NC, R_ARM_ALU_PC_G0_NC},
1749 {BFD_RELOC_ARM_ALU_PC_G0, R_ARM_ALU_PC_G0},
1750 {BFD_RELOC_ARM_ALU_PC_G1_NC, R_ARM_ALU_PC_G1_NC},
1751 {BFD_RELOC_ARM_ALU_PC_G1, R_ARM_ALU_PC_G1},
1752 {BFD_RELOC_ARM_ALU_PC_G2, R_ARM_ALU_PC_G2},
1753 {BFD_RELOC_ARM_LDR_PC_G0, R_ARM_LDR_PC_G0},
1754 {BFD_RELOC_ARM_LDR_PC_G1, R_ARM_LDR_PC_G1},
1755 {BFD_RELOC_ARM_LDR_PC_G2, R_ARM_LDR_PC_G2},
1756 {BFD_RELOC_ARM_LDRS_PC_G0, R_ARM_LDRS_PC_G0},
1757 {BFD_RELOC_ARM_LDRS_PC_G1, R_ARM_LDRS_PC_G1},
1758 {BFD_RELOC_ARM_LDRS_PC_G2, R_ARM_LDRS_PC_G2},
1759 {BFD_RELOC_ARM_LDC_PC_G0, R_ARM_LDC_PC_G0},
1760 {BFD_RELOC_ARM_LDC_PC_G1, R_ARM_LDC_PC_G1},
1761 {BFD_RELOC_ARM_LDC_PC_G2, R_ARM_LDC_PC_G2},
1762 {BFD_RELOC_ARM_ALU_SB_G0_NC, R_ARM_ALU_SB_G0_NC},
1763 {BFD_RELOC_ARM_ALU_SB_G0, R_ARM_ALU_SB_G0},
1764 {BFD_RELOC_ARM_ALU_SB_G1_NC, R_ARM_ALU_SB_G1_NC},
1765 {BFD_RELOC_ARM_ALU_SB_G1, R_ARM_ALU_SB_G1},
1766 {BFD_RELOC_ARM_ALU_SB_G2, R_ARM_ALU_SB_G2},
1767 {BFD_RELOC_ARM_LDR_SB_G0, R_ARM_LDR_SB_G0},
1768 {BFD_RELOC_ARM_LDR_SB_G1, R_ARM_LDR_SB_G1},
1769 {BFD_RELOC_ARM_LDR_SB_G2, R_ARM_LDR_SB_G2},
1770 {BFD_RELOC_ARM_LDRS_SB_G0, R_ARM_LDRS_SB_G0},
1771 {BFD_RELOC_ARM_LDRS_SB_G1, R_ARM_LDRS_SB_G1},
1772 {BFD_RELOC_ARM_LDRS_SB_G2, R_ARM_LDRS_SB_G2},
1773 {BFD_RELOC_ARM_LDC_SB_G0, R_ARM_LDC_SB_G0},
1774 {BFD_RELOC_ARM_LDC_SB_G1, R_ARM_LDC_SB_G1},
1775 {BFD_RELOC_ARM_LDC_SB_G2, R_ARM_LDC_SB_G2}
1778 static reloc_howto_type *
1779 elf32_arm_reloc_type_lookup (bfd *abfd ATTRIBUTE_UNUSED,
1780 bfd_reloc_code_real_type code)
1782 unsigned int i;
1783 for (i = 0; i < NUM_ELEM (elf32_arm_reloc_map); i ++)
1784 if (elf32_arm_reloc_map[i].bfd_reloc_val == code)
1785 return elf32_arm_howto_from_type (elf32_arm_reloc_map[i].elf_reloc_val);
1787 return NULL;
1790 static reloc_howto_type *
1791 elf32_arm_reloc_name_lookup (bfd *abfd ATTRIBUTE_UNUSED,
1792 const char *r_name)
1794 unsigned int i;
1796 for (i = 0;
1797 i < (sizeof (elf32_arm_howto_table_1)
1798 / sizeof (elf32_arm_howto_table_1[0]));
1799 i++)
1800 if (elf32_arm_howto_table_1[i].name != NULL
1801 && strcasecmp (elf32_arm_howto_table_1[i].name, r_name) == 0)
1802 return &elf32_arm_howto_table_1[i];
1804 for (i = 0;
1805 i < (sizeof (elf32_arm_howto_table_2)
1806 / sizeof (elf32_arm_howto_table_2[0]));
1807 i++)
1808 if (elf32_arm_howto_table_2[i].name != NULL
1809 && strcasecmp (elf32_arm_howto_table_2[i].name, r_name) == 0)
1810 return &elf32_arm_howto_table_2[i];
1812 return NULL;
1815 /* Support for core dump NOTE sections */
1816 static bfd_boolean
1817 elf32_arm_nabi_grok_prstatus (bfd *abfd, Elf_Internal_Note *note)
1819 int offset;
1820 size_t size;
1822 switch (note->descsz)
1824 default:
1825 return FALSE;
1827 case 148: /* Linux/ARM 32-bit*/
1828 /* pr_cursig */
1829 elf_tdata (abfd)->core_signal = bfd_get_16 (abfd, note->descdata + 12);
1831 /* pr_pid */
1832 elf_tdata (abfd)->core_pid = bfd_get_32 (abfd, note->descdata + 24);
1834 /* pr_reg */
1835 offset = 72;
1836 size = 72;
1838 break;
1841 /* Make a ".reg/999" section. */
1842 return _bfd_elfcore_make_pseudosection (abfd, ".reg",
1843 size, note->descpos + offset);
1846 static bfd_boolean
1847 elf32_arm_nabi_grok_psinfo (bfd *abfd, Elf_Internal_Note *note)
1849 switch (note->descsz)
1851 default:
1852 return FALSE;
1854 case 124: /* Linux/ARM elf_prpsinfo */
1855 elf_tdata (abfd)->core_program
1856 = _bfd_elfcore_strndup (abfd, note->descdata + 28, 16);
1857 elf_tdata (abfd)->core_command
1858 = _bfd_elfcore_strndup (abfd, note->descdata + 44, 80);
1861 /* Note that for some reason, a spurious space is tacked
1862 onto the end of the args in some (at least one anyway)
1863 implementations, so strip it off if it exists. */
1866 char *command = elf_tdata (abfd)->core_command;
1867 int n = strlen (command);
1869 if (0 < n && command[n - 1] == ' ')
1870 command[n - 1] = '\0';
1873 return TRUE;
1876 #define TARGET_LITTLE_SYM bfd_elf32_littlearm_vec
1877 #define TARGET_LITTLE_NAME "elf32-littlearm"
1878 #define TARGET_BIG_SYM bfd_elf32_bigarm_vec
1879 #define TARGET_BIG_NAME "elf32-bigarm"
1881 #define elf_backend_grok_prstatus elf32_arm_nabi_grok_prstatus
1882 #define elf_backend_grok_psinfo elf32_arm_nabi_grok_psinfo
1884 typedef unsigned long int insn32;
1885 typedef unsigned short int insn16;
1887 /* In lieu of proper flags, assume all EABIv4 or later objects are
1888 interworkable. */
1889 #define INTERWORK_FLAG(abfd) \
1890 (EF_ARM_EABI_VERSION (elf_elfheader (abfd)->e_flags) >= EF_ARM_EABI_VER4 \
1891 || (elf_elfheader (abfd)->e_flags & EF_ARM_INTERWORK))
1893 /* The linker script knows the section names for placement.
1894 The entry_names are used to do simple name mangling on the stubs.
1895 Given a function name, and its type, the stub can be found. The
1896 name can be changed. The only requirement is the %s be present. */
1897 #define THUMB2ARM_GLUE_SECTION_NAME ".glue_7t"
1898 #define THUMB2ARM_GLUE_ENTRY_NAME "__%s_from_thumb"
1900 #define ARM2THUMB_GLUE_SECTION_NAME ".glue_7"
1901 #define ARM2THUMB_GLUE_ENTRY_NAME "__%s_from_arm"
1903 #define VFP11_ERRATUM_VENEER_SECTION_NAME ".vfp11_veneer"
1904 #define VFP11_ERRATUM_VENEER_ENTRY_NAME "__vfp11_veneer_%x"
1906 /* The name of the dynamic interpreter. This is put in the .interp
1907 section. */
1908 #define ELF_DYNAMIC_INTERPRETER "/usr/lib/ld.so.1"
1910 #ifdef FOUR_WORD_PLT
1912 /* The first entry in a procedure linkage table looks like
1913 this. It is set up so that any shared library function that is
1914 called before the relocation has been set up calls the dynamic
1915 linker first. */
1916 static const bfd_vma elf32_arm_plt0_entry [] =
1918 0xe52de004, /* str lr, [sp, #-4]! */
1919 0xe59fe010, /* ldr lr, [pc, #16] */
1920 0xe08fe00e, /* add lr, pc, lr */
1921 0xe5bef008, /* ldr pc, [lr, #8]! */
1924 /* Subsequent entries in a procedure linkage table look like
1925 this. */
1926 static const bfd_vma elf32_arm_plt_entry [] =
1928 0xe28fc600, /* add ip, pc, #NN */
1929 0xe28cca00, /* add ip, ip, #NN */
1930 0xe5bcf000, /* ldr pc, [ip, #NN]! */
1931 0x00000000, /* unused */
1934 #else
1936 /* The first entry in a procedure linkage table looks like
1937 this. It is set up so that any shared library function that is
1938 called before the relocation has been set up calls the dynamic
1939 linker first. */
1940 static const bfd_vma elf32_arm_plt0_entry [] =
1942 0xe52de004, /* str lr, [sp, #-4]! */
1943 0xe59fe004, /* ldr lr, [pc, #4] */
1944 0xe08fe00e, /* add lr, pc, lr */
1945 0xe5bef008, /* ldr pc, [lr, #8]! */
1946 0x00000000, /* &GOT[0] - . */
1949 /* Subsequent entries in a procedure linkage table look like
1950 this. */
1951 static const bfd_vma elf32_arm_plt_entry [] =
1953 0xe28fc600, /* add ip, pc, #0xNN00000 */
1954 0xe28cca00, /* add ip, ip, #0xNN000 */
1955 0xe5bcf000, /* ldr pc, [ip, #0xNNN]! */
1958 #endif
1960 /* The format of the first entry in the procedure linkage table
1961 for a VxWorks executable. */
1962 static const bfd_vma elf32_arm_vxworks_exec_plt0_entry[] =
1964 0xe52dc008, /* str ip,[sp,#-8]! */
1965 0xe59fc000, /* ldr ip,[pc] */
1966 0xe59cf008, /* ldr pc,[ip,#8] */
1967 0x00000000, /* .long _GLOBAL_OFFSET_TABLE_ */
1970 /* The format of subsequent entries in a VxWorks executable. */
1971 static const bfd_vma elf32_arm_vxworks_exec_plt_entry[] =
1973 0xe59fc000, /* ldr ip,[pc] */
1974 0xe59cf000, /* ldr pc,[ip] */
1975 0x00000000, /* .long @got */
1976 0xe59fc000, /* ldr ip,[pc] */
1977 0xea000000, /* b _PLT */
1978 0x00000000, /* .long @pltindex*sizeof(Elf32_Rela) */
1981 /* The format of entries in a VxWorks shared library. */
1982 static const bfd_vma elf32_arm_vxworks_shared_plt_entry[] =
1984 0xe59fc000, /* ldr ip,[pc] */
1985 0xe79cf009, /* ldr pc,[ip,r9] */
1986 0x00000000, /* .long @got */
1987 0xe59fc000, /* ldr ip,[pc] */
1988 0xe599f008, /* ldr pc,[r9,#8] */
1989 0x00000000, /* .long @pltindex*sizeof(Elf32_Rela) */
1992 /* An initial stub used if the PLT entry is referenced from Thumb code. */
1993 #define PLT_THUMB_STUB_SIZE 4
1994 static const bfd_vma elf32_arm_plt_thumb_stub [] =
1996 0x4778, /* bx pc */
1997 0x46c0 /* nop */
2000 /* The entries in a PLT when using a DLL-based target with multiple
2001 address spaces. */
2002 static const bfd_vma elf32_arm_symbian_plt_entry [] =
2004 0xe51ff004, /* ldr pc, [pc, #-4] */
2005 0x00000000, /* dcd R_ARM_GLOB_DAT(X) */
2008 /* Used to build a map of a section. This is required for mixed-endian
2009 code/data. */
2011 typedef struct elf32_elf_section_map
2013 bfd_vma vma;
2014 char type;
2016 elf32_arm_section_map;
2018 /* Information about a VFP11 erratum veneer, or a branch to such a veneer. */
2020 typedef enum
2022 VFP11_ERRATUM_BRANCH_TO_ARM_VENEER,
2023 VFP11_ERRATUM_BRANCH_TO_THUMB_VENEER,
2024 VFP11_ERRATUM_ARM_VENEER,
2025 VFP11_ERRATUM_THUMB_VENEER
2027 elf32_vfp11_erratum_type;
2029 typedef struct elf32_vfp11_erratum_list
2031 struct elf32_vfp11_erratum_list *next;
2032 bfd_vma vma;
2033 union
2035 struct
2037 struct elf32_vfp11_erratum_list *veneer;
2038 unsigned int vfp_insn;
2039 } b;
2040 struct
2042 struct elf32_vfp11_erratum_list *branch;
2043 unsigned int id;
2044 } v;
2045 } u;
2046 elf32_vfp11_erratum_type type;
2048 elf32_vfp11_erratum_list;
2050 typedef struct _arm_elf_section_data
2052 struct bfd_elf_section_data elf;
2053 unsigned int mapcount;
2054 unsigned int mapsize;
2055 elf32_arm_section_map *map;
2056 unsigned int erratumcount;
2057 elf32_vfp11_erratum_list *erratumlist;
2059 _arm_elf_section_data;
2061 #define elf32_arm_section_data(sec) \
2062 ((_arm_elf_section_data *) elf_section_data (sec))
2064 /* The size of the thread control block. */
2065 #define TCB_SIZE 8
2067 #define NUM_KNOWN_ATTRIBUTES 32
2069 typedef struct aeabi_attribute
2071 int type;
2072 unsigned int i;
2073 char *s;
2074 } aeabi_attribute;
2076 typedef struct aeabi_attribute_list
2078 struct aeabi_attribute_list *next;
2079 int tag;
2080 aeabi_attribute attr;
2081 } aeabi_attribute_list;
2083 struct elf32_arm_obj_tdata
2085 struct elf_obj_tdata root;
2087 /* tls_type for each local got entry. */
2088 char *local_got_tls_type;
2090 aeabi_attribute known_eabi_attributes[NUM_KNOWN_ATTRIBUTES];
2091 aeabi_attribute_list *other_eabi_attributes;
2093 /* Zero to warn when linking objects with incompatible enum sizes. */
2094 int no_enum_size_warning;
2097 #define elf32_arm_tdata(abfd) \
2098 ((struct elf32_arm_obj_tdata *) (abfd)->tdata.any)
2100 #define elf32_arm_local_got_tls_type(abfd) \
2101 (elf32_arm_tdata (abfd)->local_got_tls_type)
2103 static bfd_boolean
2104 elf32_arm_mkobject (bfd *abfd)
2106 if (abfd->tdata.any == NULL)
2108 bfd_size_type amt = sizeof (struct elf32_arm_obj_tdata);
2109 abfd->tdata.any = bfd_zalloc (abfd, amt);
2110 if (abfd->tdata.any == NULL)
2111 return FALSE;
2113 return bfd_elf_mkobject (abfd);
2116 /* The ARM linker needs to keep track of the number of relocs that it
2117 decides to copy in check_relocs for each symbol. This is so that
2118 it can discard PC relative relocs if it doesn't need them when
2119 linking with -Bsymbolic. We store the information in a field
2120 extending the regular ELF linker hash table. */
2122 /* This structure keeps track of the number of relocs we have copied
2123 for a given symbol. */
2124 struct elf32_arm_relocs_copied
2126 /* Next section. */
2127 struct elf32_arm_relocs_copied * next;
2128 /* A section in dynobj. */
2129 asection * section;
2130 /* Number of relocs copied in this section. */
2131 bfd_size_type count;
2132 /* Number of PC-relative relocs copied in this section. */
2133 bfd_size_type pc_count;
2136 #define elf32_arm_hash_entry(ent) ((struct elf32_arm_link_hash_entry *)(ent))
2138 /* Arm ELF linker hash entry. */
2139 struct elf32_arm_link_hash_entry
2141 struct elf_link_hash_entry root;
2143 /* Number of PC relative relocs copied for this symbol. */
2144 struct elf32_arm_relocs_copied * relocs_copied;
2146 /* We reference count Thumb references to a PLT entry separately,
2147 so that we can emit the Thumb trampoline only if needed. */
2148 bfd_signed_vma plt_thumb_refcount;
2150 /* Since PLT entries have variable size if the Thumb prologue is
2151 used, we need to record the index into .got.plt instead of
2152 recomputing it from the PLT offset. */
2153 bfd_signed_vma plt_got_offset;
2155 #define GOT_UNKNOWN 0
2156 #define GOT_NORMAL 1
2157 #define GOT_TLS_GD 2
2158 #define GOT_TLS_IE 4
2159 unsigned char tls_type;
2161 /* The symbol marking the real symbol location for exported thumb
2162 symbols with Arm stubs. */
2163 struct elf_link_hash_entry *export_glue;
2166 /* Traverse an arm ELF linker hash table. */
2167 #define elf32_arm_link_hash_traverse(table, func, info) \
2168 (elf_link_hash_traverse \
2169 (&(table)->root, \
2170 (bfd_boolean (*) (struct elf_link_hash_entry *, void *)) (func), \
2171 (info)))
2173 /* Get the ARM elf linker hash table from a link_info structure. */
2174 #define elf32_arm_hash_table(info) \
2175 ((struct elf32_arm_link_hash_table *) ((info)->hash))
2177 /* ARM ELF linker hash table. */
2178 struct elf32_arm_link_hash_table
2180 /* The main hash table. */
2181 struct elf_link_hash_table root;
2183 /* The size in bytes of the section containing the Thumb-to-ARM glue. */
2184 bfd_size_type thumb_glue_size;
2186 /* The size in bytes of the section containing the ARM-to-Thumb glue. */
2187 bfd_size_type arm_glue_size;
2189 /* The size in bytes of the section containing glue for VFP11 erratum
2190 veneers. */
2191 bfd_size_type vfp11_erratum_glue_size;
2193 /* An arbitrary input BFD chosen to hold the glue sections. */
2194 bfd * bfd_of_glue_owner;
2196 /* Nonzero to output a BE8 image. */
2197 int byteswap_code;
2199 /* Zero if R_ARM_TARGET1 means R_ARM_ABS32.
2200 Nonzero if R_ARM_TARGET1 means R_ARM_REL32. */
2201 int target1_is_rel;
2203 /* The relocation to use for R_ARM_TARGET2 relocations. */
2204 int target2_reloc;
2206 /* Nonzero to fix BX instructions for ARMv4 targets. */
2207 int fix_v4bx;
2209 /* Nonzero if the ARM/Thumb BLX instructions are available for use. */
2210 int use_blx;
2212 /* What sort of code sequences we should look for which may trigger the
2213 VFP11 denorm erratum. */
2214 bfd_arm_vfp11_fix vfp11_fix;
2216 /* Global counter for the number of fixes we have emitted. */
2217 int num_vfp11_fixes;
2219 /* Nonzero to force PIC branch veneers. */
2220 int pic_veneer;
2222 /* The number of bytes in the initial entry in the PLT. */
2223 bfd_size_type plt_header_size;
2225 /* The number of bytes in the subsequent PLT etries. */
2226 bfd_size_type plt_entry_size;
2228 /* True if the target system is VxWorks. */
2229 int vxworks_p;
2231 /* True if the target system is Symbian OS. */
2232 int symbian_p;
2234 /* True if the target uses REL relocations. */
2235 int use_rel;
2237 /* Short-cuts to get to dynamic linker sections. */
2238 asection *sgot;
2239 asection *sgotplt;
2240 asection *srelgot;
2241 asection *splt;
2242 asection *srelplt;
2243 asection *sdynbss;
2244 asection *srelbss;
2246 /* The (unloaded but important) VxWorks .rela.plt.unloaded section. */
2247 asection *srelplt2;
2249 /* Data for R_ARM_TLS_LDM32 relocations. */
2250 union {
2251 bfd_signed_vma refcount;
2252 bfd_vma offset;
2253 } tls_ldm_got;
2255 /* Small local sym to section mapping cache. */
2256 struct sym_sec_cache sym_sec;
2258 /* For convenience in allocate_dynrelocs. */
2259 bfd * obfd;
2262 /* Create an entry in an ARM ELF linker hash table. */
2264 static struct bfd_hash_entry *
2265 elf32_arm_link_hash_newfunc (struct bfd_hash_entry * entry,
2266 struct bfd_hash_table * table,
2267 const char * string)
2269 struct elf32_arm_link_hash_entry * ret =
2270 (struct elf32_arm_link_hash_entry *) entry;
2272 /* Allocate the structure if it has not already been allocated by a
2273 subclass. */
2274 if (ret == (struct elf32_arm_link_hash_entry *) NULL)
2275 ret = bfd_hash_allocate (table, sizeof (struct elf32_arm_link_hash_entry));
2276 if (ret == NULL)
2277 return (struct bfd_hash_entry *) ret;
2279 /* Call the allocation method of the superclass. */
2280 ret = ((struct elf32_arm_link_hash_entry *)
2281 _bfd_elf_link_hash_newfunc ((struct bfd_hash_entry *) ret,
2282 table, string));
2283 if (ret != NULL)
2285 ret->relocs_copied = NULL;
2286 ret->tls_type = GOT_UNKNOWN;
2287 ret->plt_thumb_refcount = 0;
2288 ret->plt_got_offset = -1;
2289 ret->export_glue = NULL;
2292 return (struct bfd_hash_entry *) ret;
2295 /* Return true if NAME is the name of the relocation section associated
2296 with S. */
2298 static bfd_boolean
2299 reloc_section_p (struct elf32_arm_link_hash_table *htab,
2300 const char *name, asection *s)
2302 if (htab->use_rel)
2303 return CONST_STRNEQ (name, ".rel") && strcmp (s->name, name + 4) == 0;
2304 else
2305 return CONST_STRNEQ (name, ".rela") && strcmp (s->name, name + 5) == 0;
2308 /* Create .got, .gotplt, and .rel(a).got sections in DYNOBJ, and set up
2309 shortcuts to them in our hash table. */
2311 static bfd_boolean
2312 create_got_section (bfd *dynobj, struct bfd_link_info *info)
2314 struct elf32_arm_link_hash_table *htab;
2316 htab = elf32_arm_hash_table (info);
2317 /* BPABI objects never have a GOT, or associated sections. */
2318 if (htab->symbian_p)
2319 return TRUE;
2321 if (! _bfd_elf_create_got_section (dynobj, info))
2322 return FALSE;
2324 htab->sgot = bfd_get_section_by_name (dynobj, ".got");
2325 htab->sgotplt = bfd_get_section_by_name (dynobj, ".got.plt");
2326 if (!htab->sgot || !htab->sgotplt)
2327 abort ();
2329 htab->srelgot = bfd_make_section_with_flags (dynobj,
2330 RELOC_SECTION (htab, ".got"),
2331 (SEC_ALLOC | SEC_LOAD
2332 | SEC_HAS_CONTENTS
2333 | SEC_IN_MEMORY
2334 | SEC_LINKER_CREATED
2335 | SEC_READONLY));
2336 if (htab->srelgot == NULL
2337 || ! bfd_set_section_alignment (dynobj, htab->srelgot, 2))
2338 return FALSE;
2339 return TRUE;
2342 /* Create .plt, .rel(a).plt, .got, .got.plt, .rel(a).got, .dynbss, and
2343 .rel(a).bss sections in DYNOBJ, and set up shortcuts to them in our
2344 hash table. */
2346 static bfd_boolean
2347 elf32_arm_create_dynamic_sections (bfd *dynobj, struct bfd_link_info *info)
2349 struct elf32_arm_link_hash_table *htab;
2351 htab = elf32_arm_hash_table (info);
2352 if (!htab->sgot && !create_got_section (dynobj, info))
2353 return FALSE;
2355 if (!_bfd_elf_create_dynamic_sections (dynobj, info))
2356 return FALSE;
2358 htab->splt = bfd_get_section_by_name (dynobj, ".plt");
2359 htab->srelplt = bfd_get_section_by_name (dynobj,
2360 RELOC_SECTION (htab, ".plt"));
2361 htab->sdynbss = bfd_get_section_by_name (dynobj, ".dynbss");
2362 if (!info->shared)
2363 htab->srelbss = bfd_get_section_by_name (dynobj,
2364 RELOC_SECTION (htab, ".bss"));
2366 if (htab->vxworks_p)
2368 if (!elf_vxworks_create_dynamic_sections (dynobj, info, &htab->srelplt2))
2369 return FALSE;
2371 if (info->shared)
2373 htab->plt_header_size = 0;
2374 htab->plt_entry_size
2375 = 4 * ARRAY_SIZE (elf32_arm_vxworks_shared_plt_entry);
2377 else
2379 htab->plt_header_size
2380 = 4 * ARRAY_SIZE (elf32_arm_vxworks_exec_plt0_entry);
2381 htab->plt_entry_size
2382 = 4 * ARRAY_SIZE (elf32_arm_vxworks_exec_plt_entry);
2386 if (!htab->splt
2387 || !htab->srelplt
2388 || !htab->sdynbss
2389 || (!info->shared && !htab->srelbss))
2390 abort ();
2392 return TRUE;
2395 /* Copy the extra info we tack onto an elf_link_hash_entry. */
2397 static void
2398 elf32_arm_copy_indirect_symbol (struct bfd_link_info *info,
2399 struct elf_link_hash_entry *dir,
2400 struct elf_link_hash_entry *ind)
2402 struct elf32_arm_link_hash_entry *edir, *eind;
2404 edir = (struct elf32_arm_link_hash_entry *) dir;
2405 eind = (struct elf32_arm_link_hash_entry *) ind;
2407 if (eind->relocs_copied != NULL)
2409 if (edir->relocs_copied != NULL)
2411 struct elf32_arm_relocs_copied **pp;
2412 struct elf32_arm_relocs_copied *p;
2414 /* Add reloc counts against the indirect sym to the direct sym
2415 list. Merge any entries against the same section. */
2416 for (pp = &eind->relocs_copied; (p = *pp) != NULL; )
2418 struct elf32_arm_relocs_copied *q;
2420 for (q = edir->relocs_copied; q != NULL; q = q->next)
2421 if (q->section == p->section)
2423 q->pc_count += p->pc_count;
2424 q->count += p->count;
2425 *pp = p->next;
2426 break;
2428 if (q == NULL)
2429 pp = &p->next;
2431 *pp = edir->relocs_copied;
2434 edir->relocs_copied = eind->relocs_copied;
2435 eind->relocs_copied = NULL;
2438 if (ind->root.type == bfd_link_hash_indirect)
2440 /* Copy over PLT info. */
2441 edir->plt_thumb_refcount += eind->plt_thumb_refcount;
2442 eind->plt_thumb_refcount = 0;
2444 if (dir->got.refcount <= 0)
2446 edir->tls_type = eind->tls_type;
2447 eind->tls_type = GOT_UNKNOWN;
2451 _bfd_elf_link_hash_copy_indirect (info, dir, ind);
2454 /* Create an ARM elf linker hash table. */
2456 static struct bfd_link_hash_table *
2457 elf32_arm_link_hash_table_create (bfd *abfd)
2459 struct elf32_arm_link_hash_table *ret;
2460 bfd_size_type amt = sizeof (struct elf32_arm_link_hash_table);
2462 ret = bfd_malloc (amt);
2463 if (ret == NULL)
2464 return NULL;
2466 if (!_bfd_elf_link_hash_table_init (& ret->root, abfd,
2467 elf32_arm_link_hash_newfunc,
2468 sizeof (struct elf32_arm_link_hash_entry)))
2470 free (ret);
2471 return NULL;
2474 ret->sgot = NULL;
2475 ret->sgotplt = NULL;
2476 ret->srelgot = NULL;
2477 ret->splt = NULL;
2478 ret->srelplt = NULL;
2479 ret->sdynbss = NULL;
2480 ret->srelbss = NULL;
2481 ret->srelplt2 = NULL;
2482 ret->thumb_glue_size = 0;
2483 ret->arm_glue_size = 0;
2484 ret->vfp11_fix = BFD_ARM_VFP11_FIX_NONE;
2485 ret->vfp11_erratum_glue_size = 0;
2486 ret->num_vfp11_fixes = 0;
2487 ret->bfd_of_glue_owner = NULL;
2488 ret->byteswap_code = 0;
2489 ret->target1_is_rel = 0;
2490 ret->target2_reloc = R_ARM_NONE;
2491 #ifdef FOUR_WORD_PLT
2492 ret->plt_header_size = 16;
2493 ret->plt_entry_size = 16;
2494 #else
2495 ret->plt_header_size = 20;
2496 ret->plt_entry_size = 12;
2497 #endif
2498 ret->fix_v4bx = 0;
2499 ret->use_blx = 0;
2500 ret->vxworks_p = 0;
2501 ret->symbian_p = 0;
2502 ret->use_rel = 1;
2503 ret->sym_sec.abfd = NULL;
2504 ret->obfd = abfd;
2505 ret->tls_ldm_got.refcount = 0;
2507 return &ret->root.root;
2510 /* Locate the Thumb encoded calling stub for NAME. */
2512 static struct elf_link_hash_entry *
2513 find_thumb_glue (struct bfd_link_info *link_info,
2514 const char *name,
2515 char **error_message)
2517 char *tmp_name;
2518 struct elf_link_hash_entry *hash;
2519 struct elf32_arm_link_hash_table *hash_table;
2521 /* We need a pointer to the armelf specific hash table. */
2522 hash_table = elf32_arm_hash_table (link_info);
2524 tmp_name = bfd_malloc ((bfd_size_type) strlen (name)
2525 + strlen (THUMB2ARM_GLUE_ENTRY_NAME) + 1);
2527 BFD_ASSERT (tmp_name);
2529 sprintf (tmp_name, THUMB2ARM_GLUE_ENTRY_NAME, name);
2531 hash = elf_link_hash_lookup
2532 (&(hash_table)->root, tmp_name, FALSE, FALSE, TRUE);
2534 if (hash == NULL)
2535 asprintf (error_message, _("unable to find THUMB glue '%s' for '%s'"),
2536 tmp_name, name);
2538 free (tmp_name);
2540 return hash;
2543 /* Locate the ARM encoded calling stub for NAME. */
2545 static struct elf_link_hash_entry *
2546 find_arm_glue (struct bfd_link_info *link_info,
2547 const char *name,
2548 char **error_message)
2550 char *tmp_name;
2551 struct elf_link_hash_entry *myh;
2552 struct elf32_arm_link_hash_table *hash_table;
2554 /* We need a pointer to the elfarm specific hash table. */
2555 hash_table = elf32_arm_hash_table (link_info);
2557 tmp_name = bfd_malloc ((bfd_size_type) strlen (name)
2558 + strlen (ARM2THUMB_GLUE_ENTRY_NAME) + 1);
2560 BFD_ASSERT (tmp_name);
2562 sprintf (tmp_name, ARM2THUMB_GLUE_ENTRY_NAME, name);
2564 myh = elf_link_hash_lookup
2565 (&(hash_table)->root, tmp_name, FALSE, FALSE, TRUE);
2567 if (myh == NULL)
2568 asprintf (error_message, _("unable to find ARM glue '%s' for '%s'"),
2569 tmp_name, name);
2571 free (tmp_name);
2573 return myh;
2576 /* ARM->Thumb glue (static images):
2578 .arm
2579 __func_from_arm:
2580 ldr r12, __func_addr
2581 bx r12
2582 __func_addr:
2583 .word func @ behave as if you saw a ARM_32 reloc.
2585 (v5t static images)
2586 .arm
2587 __func_from_arm:
2588 ldr pc, __func_addr
2589 __func_addr:
2590 .word func @ behave as if you saw a ARM_32 reloc.
2592 (relocatable images)
2593 .arm
2594 __func_from_arm:
2595 ldr r12, __func_offset
2596 add r12, r12, pc
2597 bx r12
2598 __func_offset:
2599 .word func - .
2602 #define ARM2THUMB_STATIC_GLUE_SIZE 12
2603 static const insn32 a2t1_ldr_insn = 0xe59fc000;
2604 static const insn32 a2t2_bx_r12_insn = 0xe12fff1c;
2605 static const insn32 a2t3_func_addr_insn = 0x00000001;
2607 #define ARM2THUMB_V5_STATIC_GLUE_SIZE 8
2608 static const insn32 a2t1v5_ldr_insn = 0xe51ff004;
2609 static const insn32 a2t2v5_func_addr_insn = 0x00000001;
2611 #define ARM2THUMB_PIC_GLUE_SIZE 16
2612 static const insn32 a2t1p_ldr_insn = 0xe59fc004;
2613 static const insn32 a2t2p_add_pc_insn = 0xe08cc00f;
2614 static const insn32 a2t3p_bx_r12_insn = 0xe12fff1c;
2616 /* Thumb->ARM: Thumb->(non-interworking aware) ARM
2618 .thumb .thumb
2619 .align 2 .align 2
2620 __func_from_thumb: __func_from_thumb:
2621 bx pc push {r6, lr}
2622 nop ldr r6, __func_addr
2623 .arm mov lr, pc
2624 __func_change_to_arm: bx r6
2625 b func .arm
2626 __func_back_to_thumb:
2627 ldmia r13! {r6, lr}
2628 bx lr
2629 __func_addr:
2630 .word func */
2632 #define THUMB2ARM_GLUE_SIZE 8
2633 static const insn16 t2a1_bx_pc_insn = 0x4778;
2634 static const insn16 t2a2_noop_insn = 0x46c0;
2635 static const insn32 t2a3_b_insn = 0xea000000;
2637 #define VFP11_ERRATUM_VENEER_SIZE 8
2639 #ifndef ELFARM_NABI_C_INCLUDED
2640 bfd_boolean
2641 bfd_elf32_arm_allocate_interworking_sections (struct bfd_link_info * info)
2643 asection * s;
2644 bfd_byte * foo;
2645 struct elf32_arm_link_hash_table * globals;
2647 globals = elf32_arm_hash_table (info);
2649 BFD_ASSERT (globals != NULL);
2651 if (globals->arm_glue_size != 0)
2653 BFD_ASSERT (globals->bfd_of_glue_owner != NULL);
2655 s = bfd_get_section_by_name (globals->bfd_of_glue_owner,
2656 ARM2THUMB_GLUE_SECTION_NAME);
2658 BFD_ASSERT (s != NULL);
2660 foo = bfd_alloc (globals->bfd_of_glue_owner, globals->arm_glue_size);
2662 BFD_ASSERT (s->size == globals->arm_glue_size);
2663 s->contents = foo;
2666 if (globals->thumb_glue_size != 0)
2668 BFD_ASSERT (globals->bfd_of_glue_owner != NULL);
2670 s = bfd_get_section_by_name
2671 (globals->bfd_of_glue_owner, THUMB2ARM_GLUE_SECTION_NAME);
2673 BFD_ASSERT (s != NULL);
2675 foo = bfd_alloc (globals->bfd_of_glue_owner, globals->thumb_glue_size);
2677 BFD_ASSERT (s->size == globals->thumb_glue_size);
2678 s->contents = foo;
2681 if (globals->vfp11_erratum_glue_size != 0)
2683 BFD_ASSERT (globals->bfd_of_glue_owner != NULL);
2685 s = bfd_get_section_by_name
2686 (globals->bfd_of_glue_owner, VFP11_ERRATUM_VENEER_SECTION_NAME);
2688 BFD_ASSERT (s != NULL);
2690 foo = bfd_alloc (globals->bfd_of_glue_owner,
2691 globals->vfp11_erratum_glue_size);
2693 BFD_ASSERT (s->size == globals->vfp11_erratum_glue_size);
2694 s->contents = foo;
2697 return TRUE;
2700 /* Allocate space and symbols for calling a Thumb function from Arm mode.
2701 returns the symbol identifying teh stub. */
2702 static struct elf_link_hash_entry *
2703 record_arm_to_thumb_glue (struct bfd_link_info * link_info,
2704 struct elf_link_hash_entry * h)
2706 const char * name = h->root.root.string;
2707 asection * s;
2708 char * tmp_name;
2709 struct elf_link_hash_entry * myh;
2710 struct bfd_link_hash_entry * bh;
2711 struct elf32_arm_link_hash_table * globals;
2712 bfd_vma val;
2713 bfd_size_type size;
2715 globals = elf32_arm_hash_table (link_info);
2717 BFD_ASSERT (globals != NULL);
2718 BFD_ASSERT (globals->bfd_of_glue_owner != NULL);
2720 s = bfd_get_section_by_name
2721 (globals->bfd_of_glue_owner, ARM2THUMB_GLUE_SECTION_NAME);
2723 BFD_ASSERT (s != NULL);
2725 tmp_name = bfd_malloc ((bfd_size_type) strlen (name) + strlen (ARM2THUMB_GLUE_ENTRY_NAME) + 1);
2727 BFD_ASSERT (tmp_name);
2729 sprintf (tmp_name, ARM2THUMB_GLUE_ENTRY_NAME, name);
2731 myh = elf_link_hash_lookup
2732 (&(globals)->root, tmp_name, FALSE, FALSE, TRUE);
2734 if (myh != NULL)
2736 /* We've already seen this guy. */
2737 free (tmp_name);
2738 return myh;
2741 /* The only trick here is using hash_table->arm_glue_size as the value.
2742 Even though the section isn't allocated yet, this is where we will be
2743 putting it. */
2744 bh = NULL;
2745 val = globals->arm_glue_size + 1;
2746 _bfd_generic_link_add_one_symbol (link_info, globals->bfd_of_glue_owner,
2747 tmp_name, BSF_GLOBAL, s, val,
2748 NULL, TRUE, FALSE, &bh);
2750 myh = (struct elf_link_hash_entry *) bh;
2751 myh->type = ELF_ST_INFO (STB_LOCAL, STT_FUNC);
2752 myh->forced_local = 1;
2754 free (tmp_name);
2756 if (link_info->shared || globals->root.is_relocatable_executable
2757 || globals->pic_veneer)
2758 size = ARM2THUMB_PIC_GLUE_SIZE;
2759 else if (globals->use_blx)
2760 size = ARM2THUMB_V5_STATIC_GLUE_SIZE;
2761 else
2762 size = ARM2THUMB_STATIC_GLUE_SIZE;
2764 s->size += size;
2765 globals->arm_glue_size += size;
2767 return myh;
2770 static void
2771 record_thumb_to_arm_glue (struct bfd_link_info *link_info,
2772 struct elf_link_hash_entry *h)
2774 const char *name = h->root.root.string;
2775 asection *s;
2776 char *tmp_name;
2777 struct elf_link_hash_entry *myh;
2778 struct bfd_link_hash_entry *bh;
2779 struct elf32_arm_link_hash_table *hash_table;
2780 bfd_vma val;
2782 hash_table = elf32_arm_hash_table (link_info);
2784 BFD_ASSERT (hash_table != NULL);
2785 BFD_ASSERT (hash_table->bfd_of_glue_owner != NULL);
2787 s = bfd_get_section_by_name
2788 (hash_table->bfd_of_glue_owner, THUMB2ARM_GLUE_SECTION_NAME);
2790 BFD_ASSERT (s != NULL);
2792 tmp_name = bfd_malloc ((bfd_size_type) strlen (name)
2793 + strlen (THUMB2ARM_GLUE_ENTRY_NAME) + 1);
2795 BFD_ASSERT (tmp_name);
2797 sprintf (tmp_name, THUMB2ARM_GLUE_ENTRY_NAME, name);
2799 myh = elf_link_hash_lookup
2800 (&(hash_table)->root, tmp_name, FALSE, FALSE, TRUE);
2802 if (myh != NULL)
2804 /* We've already seen this guy. */
2805 free (tmp_name);
2806 return;
2809 bh = NULL;
2810 val = hash_table->thumb_glue_size + 1;
2811 _bfd_generic_link_add_one_symbol (link_info, hash_table->bfd_of_glue_owner,
2812 tmp_name, BSF_GLOBAL, s, val,
2813 NULL, TRUE, FALSE, &bh);
2815 /* If we mark it 'Thumb', the disassembler will do a better job. */
2816 myh = (struct elf_link_hash_entry *) bh;
2817 myh->type = ELF_ST_INFO (STB_LOCAL, STT_ARM_TFUNC);
2818 myh->forced_local = 1;
2820 free (tmp_name);
2822 #define CHANGE_TO_ARM "__%s_change_to_arm"
2823 #define BACK_FROM_ARM "__%s_back_from_arm"
2825 /* Allocate another symbol to mark where we switch to Arm mode. */
2826 tmp_name = bfd_malloc ((bfd_size_type) strlen (name)
2827 + strlen (CHANGE_TO_ARM) + 1);
2829 BFD_ASSERT (tmp_name);
2831 sprintf (tmp_name, CHANGE_TO_ARM, name);
2833 bh = NULL;
2834 val = hash_table->thumb_glue_size + 4,
2835 _bfd_generic_link_add_one_symbol (link_info, hash_table->bfd_of_glue_owner,
2836 tmp_name, BSF_LOCAL, s, val,
2837 NULL, TRUE, FALSE, &bh);
2839 free (tmp_name);
2841 s->size += THUMB2ARM_GLUE_SIZE;
2842 hash_table->thumb_glue_size += THUMB2ARM_GLUE_SIZE;
2844 return;
2848 /* Add an entry to the code/data map for section SEC. */
2850 static void
2851 elf32_arm_section_map_add (asection *sec, char type, bfd_vma vma)
2853 struct _arm_elf_section_data *sec_data = elf32_arm_section_data (sec);
2854 unsigned int newidx;
2856 if (sec_data->map == NULL)
2858 sec_data->map = bfd_malloc (sizeof (elf32_arm_section_map));
2859 sec_data->mapcount = 0;
2860 sec_data->mapsize = 1;
2863 newidx = sec_data->mapcount++;
2865 if (sec_data->mapcount > sec_data->mapsize)
2867 sec_data->mapsize *= 2;
2868 sec_data->map = bfd_realloc (sec_data->map, sec_data->mapsize
2869 * sizeof (elf32_arm_section_map));
2872 sec_data->map[newidx].vma = vma;
2873 sec_data->map[newidx].type = type;
2877 /* Record information about a VFP11 denorm-erratum veneer. Only ARM-mode
2878 veneers are handled for now. */
2880 static bfd_vma
2881 record_vfp11_erratum_veneer (struct bfd_link_info *link_info,
2882 elf32_vfp11_erratum_list *branch,
2883 bfd *branch_bfd,
2884 asection *branch_sec,
2885 unsigned int offset)
2887 asection *s;
2888 struct elf32_arm_link_hash_table *hash_table;
2889 char *tmp_name;
2890 struct elf_link_hash_entry *myh;
2891 struct bfd_link_hash_entry *bh;
2892 bfd_vma val;
2893 struct _arm_elf_section_data *sec_data;
2894 int errcount;
2895 elf32_vfp11_erratum_list *newerr;
2897 hash_table = elf32_arm_hash_table (link_info);
2899 BFD_ASSERT (hash_table != NULL);
2900 BFD_ASSERT (hash_table->bfd_of_glue_owner != NULL);
2902 s = bfd_get_section_by_name
2903 (hash_table->bfd_of_glue_owner, VFP11_ERRATUM_VENEER_SECTION_NAME);
2905 sec_data = elf32_arm_section_data (s);
2907 BFD_ASSERT (s != NULL);
2909 tmp_name = bfd_malloc ((bfd_size_type) strlen
2910 (VFP11_ERRATUM_VENEER_ENTRY_NAME) + 10);
2912 BFD_ASSERT (tmp_name);
2914 sprintf (tmp_name, VFP11_ERRATUM_VENEER_ENTRY_NAME,
2915 hash_table->num_vfp11_fixes);
2917 myh = elf_link_hash_lookup
2918 (&(hash_table)->root, tmp_name, FALSE, FALSE, FALSE);
2920 BFD_ASSERT (myh == NULL);
2922 bh = NULL;
2923 val = hash_table->vfp11_erratum_glue_size;
2924 _bfd_generic_link_add_one_symbol (link_info, hash_table->bfd_of_glue_owner,
2925 tmp_name, BSF_FUNCTION | BSF_LOCAL, s, val,
2926 NULL, TRUE, FALSE, &bh);
2928 myh = (struct elf_link_hash_entry *) bh;
2929 myh->type = ELF_ST_INFO (STB_LOCAL, STT_FUNC);
2930 myh->forced_local = 1;
2932 /* Link veneer back to calling location. */
2933 errcount = ++(sec_data->erratumcount);
2934 newerr = bfd_zmalloc (sizeof (elf32_vfp11_erratum_list));
2936 newerr->type = VFP11_ERRATUM_ARM_VENEER;
2937 newerr->vma = -1;
2938 newerr->u.v.branch = branch;
2939 newerr->u.v.id = hash_table->num_vfp11_fixes;
2940 branch->u.b.veneer = newerr;
2942 newerr->next = sec_data->erratumlist;
2943 sec_data->erratumlist = newerr;
2945 /* A symbol for the return from the veneer. */
2946 sprintf (tmp_name, VFP11_ERRATUM_VENEER_ENTRY_NAME "_r",
2947 hash_table->num_vfp11_fixes);
2949 myh = elf_link_hash_lookup
2950 (&(hash_table)->root, tmp_name, FALSE, FALSE, FALSE);
2952 if (myh != NULL)
2953 abort ();
2955 bh = NULL;
2956 val = offset + 4;
2957 _bfd_generic_link_add_one_symbol (link_info, branch_bfd, tmp_name, BSF_LOCAL,
2958 branch_sec, val, NULL, TRUE, FALSE, &bh);
2960 myh = (struct elf_link_hash_entry *) bh;
2961 myh->type = ELF_ST_INFO (STB_LOCAL, STT_FUNC);
2962 myh->forced_local = 1;
2964 free (tmp_name);
2966 /* Generate a mapping symbol for the veneer section, and explicitly add an
2967 entry for that symbol to the code/data map for the section. */
2968 if (hash_table->vfp11_erratum_glue_size == 0)
2970 bh = NULL;
2971 /* FIXME: Creates an ARM symbol. Thumb mode will need attention if it
2972 ever requires this erratum fix. */
2973 _bfd_generic_link_add_one_symbol (link_info,
2974 hash_table->bfd_of_glue_owner, "$a",
2975 BSF_LOCAL, s, 0, NULL,
2976 TRUE, FALSE, &bh);
2978 myh = (struct elf_link_hash_entry *) bh;
2979 myh->type = ELF_ST_INFO (STB_LOCAL, STT_NOTYPE);
2980 myh->forced_local = 1;
2982 /* The elf32_arm_init_maps function only cares about symbols from input
2983 BFDs. We must make a note of this generated mapping symbol
2984 ourselves so that code byteswapping works properly in
2985 elf32_arm_write_section. */
2986 elf32_arm_section_map_add (s, 'a', 0);
2989 s->size += VFP11_ERRATUM_VENEER_SIZE;
2990 hash_table->vfp11_erratum_glue_size += VFP11_ERRATUM_VENEER_SIZE;
2991 hash_table->num_vfp11_fixes++;
2993 /* The offset of the veneer. */
2994 return val;
2997 /* Add the glue sections to ABFD. This function is called from the
2998 linker scripts in ld/emultempl/{armelf}.em. */
3000 bfd_boolean
3001 bfd_elf32_arm_add_glue_sections_to_bfd (bfd *abfd,
3002 struct bfd_link_info *info)
3004 flagword flags;
3005 asection *sec;
3007 /* If we are only performing a partial
3008 link do not bother adding the glue. */
3009 if (info->relocatable)
3010 return TRUE;
3012 sec = bfd_get_section_by_name (abfd, ARM2THUMB_GLUE_SECTION_NAME);
3014 if (sec == NULL)
3016 /* Note: we do not include the flag SEC_LINKER_CREATED, as this
3017 will prevent elf_link_input_bfd() from processing the contents
3018 of this section. */
3019 flags = (SEC_ALLOC | SEC_LOAD | SEC_HAS_CONTENTS | SEC_IN_MEMORY
3020 | SEC_CODE | SEC_READONLY);
3022 sec = bfd_make_section_with_flags (abfd,
3023 ARM2THUMB_GLUE_SECTION_NAME,
3024 flags);
3026 if (sec == NULL
3027 || !bfd_set_section_alignment (abfd, sec, 2))
3028 return FALSE;
3030 /* Set the gc mark to prevent the section from being removed by garbage
3031 collection, despite the fact that no relocs refer to this section. */
3032 sec->gc_mark = 1;
3035 sec = bfd_get_section_by_name (abfd, THUMB2ARM_GLUE_SECTION_NAME);
3037 if (sec == NULL)
3039 flags = (SEC_ALLOC | SEC_LOAD | SEC_HAS_CONTENTS | SEC_IN_MEMORY
3040 | SEC_CODE | SEC_READONLY);
3042 sec = bfd_make_section_with_flags (abfd,
3043 THUMB2ARM_GLUE_SECTION_NAME,
3044 flags);
3046 if (sec == NULL
3047 || !bfd_set_section_alignment (abfd, sec, 2))
3048 return FALSE;
3050 sec->gc_mark = 1;
3053 sec = bfd_get_section_by_name (abfd, VFP11_ERRATUM_VENEER_SECTION_NAME);
3055 if (sec == NULL)
3057 flags = (SEC_ALLOC | SEC_LOAD | SEC_HAS_CONTENTS | SEC_IN_MEMORY
3058 | SEC_CODE | SEC_READONLY);
3060 sec = bfd_make_section_with_flags (abfd,
3061 VFP11_ERRATUM_VENEER_SECTION_NAME,
3062 flags);
3064 if (sec == NULL
3065 || !bfd_set_section_alignment (abfd, sec, 2))
3066 return FALSE;
3068 sec->gc_mark = 1;
3071 return TRUE;
3074 /* Select a BFD to be used to hold the sections used by the glue code.
3075 This function is called from the linker scripts in ld/emultempl/
3076 {armelf/pe}.em */
3078 bfd_boolean
3079 bfd_elf32_arm_get_bfd_for_interworking (bfd *abfd, struct bfd_link_info *info)
3081 struct elf32_arm_link_hash_table *globals;
3083 /* If we are only performing a partial link
3084 do not bother getting a bfd to hold the glue. */
3085 if (info->relocatable)
3086 return TRUE;
3088 /* Make sure we don't attach the glue sections to a dynamic object. */
3089 BFD_ASSERT (!(abfd->flags & DYNAMIC));
3091 globals = elf32_arm_hash_table (info);
3093 BFD_ASSERT (globals != NULL);
3095 if (globals->bfd_of_glue_owner != NULL)
3096 return TRUE;
3098 /* Save the bfd for later use. */
3099 globals->bfd_of_glue_owner = abfd;
3101 return TRUE;
3104 static void check_use_blx(struct elf32_arm_link_hash_table *globals)
3106 if (elf32_arm_get_eabi_attr_int (globals->obfd, Tag_CPU_arch) > 2)
3107 globals->use_blx = 1;
3110 bfd_boolean
3111 bfd_elf32_arm_process_before_allocation (bfd *abfd,
3112 struct bfd_link_info *link_info)
3114 Elf_Internal_Shdr *symtab_hdr;
3115 Elf_Internal_Rela *internal_relocs = NULL;
3116 Elf_Internal_Rela *irel, *irelend;
3117 bfd_byte *contents = NULL;
3119 asection *sec;
3120 struct elf32_arm_link_hash_table *globals;
3122 /* If we are only performing a partial link do not bother
3123 to construct any glue. */
3124 if (link_info->relocatable)
3125 return TRUE;
3127 /* Here we have a bfd that is to be included on the link. We have a hook
3128 to do reloc rummaging, before section sizes are nailed down. */
3129 globals = elf32_arm_hash_table (link_info);
3130 check_use_blx (globals);
3132 BFD_ASSERT (globals != NULL);
3133 BFD_ASSERT (globals->bfd_of_glue_owner != NULL);
3135 if (globals->byteswap_code && !bfd_big_endian (abfd))
3137 _bfd_error_handler (_("%B: BE8 images only valid in big-endian mode."),
3138 abfd);
3139 return FALSE;
3142 /* Rummage around all the relocs and map the glue vectors. */
3143 sec = abfd->sections;
3145 if (sec == NULL)
3146 return TRUE;
3148 for (; sec != NULL; sec = sec->next)
3150 if (sec->reloc_count == 0)
3151 continue;
3153 if ((sec->flags & SEC_EXCLUDE) != 0)
3154 continue;
3156 symtab_hdr = &elf_tdata (abfd)->symtab_hdr;
3158 /* Load the relocs. */
3159 internal_relocs
3160 = _bfd_elf_link_read_relocs (abfd, sec, (void *) NULL,
3161 (Elf_Internal_Rela *) NULL, FALSE);
3163 if (internal_relocs == NULL)
3164 goto error_return;
3166 irelend = internal_relocs + sec->reloc_count;
3167 for (irel = internal_relocs; irel < irelend; irel++)
3169 long r_type;
3170 unsigned long r_index;
3172 struct elf_link_hash_entry *h;
3174 r_type = ELF32_R_TYPE (irel->r_info);
3175 r_index = ELF32_R_SYM (irel->r_info);
3177 /* These are the only relocation types we care about. */
3178 if ( r_type != R_ARM_PC24
3179 && r_type != R_ARM_PLT32
3180 && r_type != R_ARM_CALL
3181 && r_type != R_ARM_JUMP24
3182 && r_type != R_ARM_THM_CALL)
3183 continue;
3185 /* Get the section contents if we haven't done so already. */
3186 if (contents == NULL)
3188 /* Get cached copy if it exists. */
3189 if (elf_section_data (sec)->this_hdr.contents != NULL)
3190 contents = elf_section_data (sec)->this_hdr.contents;
3191 else
3193 /* Go get them off disk. */
3194 if (! bfd_malloc_and_get_section (abfd, sec, &contents))
3195 goto error_return;
3199 /* If the relocation is not against a symbol it cannot concern us. */
3200 h = NULL;
3202 /* We don't care about local symbols. */
3203 if (r_index < symtab_hdr->sh_info)
3204 continue;
3206 /* This is an external symbol. */
3207 r_index -= symtab_hdr->sh_info;
3208 h = (struct elf_link_hash_entry *)
3209 elf_sym_hashes (abfd)[r_index];
3211 /* If the relocation is against a static symbol it must be within
3212 the current section and so cannot be a cross ARM/Thumb relocation. */
3213 if (h == NULL)
3214 continue;
3216 /* If the call will go through a PLT entry then we do not need
3217 glue. */
3218 if (globals->splt != NULL && h->plt.offset != (bfd_vma) -1)
3219 continue;
3221 switch (r_type)
3223 case R_ARM_PC24:
3224 case R_ARM_PLT32:
3225 case R_ARM_CALL:
3226 case R_ARM_JUMP24:
3227 /* This one is a call from arm code. We need to look up
3228 the target of the call. If it is a thumb target, we
3229 insert glue. */
3230 if (ELF_ST_TYPE(h->type) == STT_ARM_TFUNC
3231 && !(r_type == R_ARM_CALL && globals->use_blx))
3232 record_arm_to_thumb_glue (link_info, h);
3233 break;
3235 case R_ARM_THM_CALL:
3236 /* This one is a call from thumb code. We look
3237 up the target of the call. If it is not a thumb
3238 target, we insert glue. */
3239 if (ELF_ST_TYPE (h->type) != STT_ARM_TFUNC && !globals->use_blx)
3240 record_thumb_to_arm_glue (link_info, h);
3241 break;
3243 default:
3244 abort ();
3248 if (contents != NULL
3249 && elf_section_data (sec)->this_hdr.contents != contents)
3250 free (contents);
3251 contents = NULL;
3253 if (internal_relocs != NULL
3254 && elf_section_data (sec)->relocs != internal_relocs)
3255 free (internal_relocs);
3256 internal_relocs = NULL;
3259 return TRUE;
3261 error_return:
3262 if (contents != NULL
3263 && elf_section_data (sec)->this_hdr.contents != contents)
3264 free (contents);
3265 if (internal_relocs != NULL
3266 && elf_section_data (sec)->relocs != internal_relocs)
3267 free (internal_relocs);
3269 return FALSE;
3271 #endif
3274 /* Initialise maps of ARM/Thumb/data for input BFDs. */
3276 void
3277 bfd_elf32_arm_init_maps (bfd *abfd)
3279 Elf_Internal_Sym *isymbuf;
3280 Elf_Internal_Shdr *hdr;
3281 unsigned int i, localsyms;
3283 if ((abfd->flags & DYNAMIC) != 0)
3284 return;
3286 hdr = &elf_tdata (abfd)->symtab_hdr;
3287 localsyms = hdr->sh_info;
3289 /* Obtain a buffer full of symbols for this BFD. The hdr->sh_info field
3290 should contain the number of local symbols, which should come before any
3291 global symbols. Mapping symbols are always local. */
3292 isymbuf = bfd_elf_get_elf_syms (abfd, hdr, localsyms, 0, NULL, NULL,
3293 NULL);
3295 /* No internal symbols read? Skip this BFD. */
3296 if (isymbuf == NULL)
3297 return;
3299 for (i = 0; i < localsyms; i++)
3301 Elf_Internal_Sym *isym = &isymbuf[i];
3302 asection *sec = bfd_section_from_elf_index (abfd, isym->st_shndx);
3303 const char *name;
3305 if (sec != NULL
3306 && ELF_ST_BIND (isym->st_info) == STB_LOCAL)
3308 name = bfd_elf_string_from_elf_section (abfd,
3309 hdr->sh_link, isym->st_name);
3311 if (bfd_is_arm_special_symbol_name (name,
3312 BFD_ARM_SPECIAL_SYM_TYPE_MAP))
3313 elf32_arm_section_map_add (sec, name[1], isym->st_value);
3319 void
3320 bfd_elf32_arm_set_vfp11_fix (bfd *obfd, struct bfd_link_info *link_info)
3322 struct elf32_arm_link_hash_table *globals = elf32_arm_hash_table (link_info);
3323 aeabi_attribute *out_attr = elf32_arm_tdata (obfd)->known_eabi_attributes;
3325 /* We assume that ARMv7+ does not need the VFP11 denorm erratum fix. */
3326 if (out_attr[Tag_CPU_arch].i >= TAG_CPU_ARCH_V7)
3328 switch (globals->vfp11_fix)
3330 case BFD_ARM_VFP11_FIX_DEFAULT:
3331 case BFD_ARM_VFP11_FIX_NONE:
3332 globals->vfp11_fix = BFD_ARM_VFP11_FIX_NONE;
3333 break;
3335 default:
3336 /* Give a warning, but do as the user requests anyway. */
3337 (*_bfd_error_handler) (_("%B: warning: selected VFP11 erratum "
3338 "workaround is not necessary for target architecture"), obfd);
3341 else if (globals->vfp11_fix == BFD_ARM_VFP11_FIX_DEFAULT)
3342 /* For earlier architectures, we might need the workaround, but do not
3343 enable it by default. If users is running with broken hardware, they
3344 must enable the erratum fix explicitly. */
3345 globals->vfp11_fix = BFD_ARM_VFP11_FIX_NONE;
3349 enum bfd_arm_vfp11_pipe {
3350 VFP11_FMAC,
3351 VFP11_LS,
3352 VFP11_DS,
3353 VFP11_BAD
3356 /* Return a VFP register number. This is encoded as RX:X for single-precision
3357 registers, or X:RX for double-precision registers, where RX is the group of
3358 four bits in the instruction encoding and X is the single extension bit.
3359 RX and X fields are specified using their lowest (starting) bit. The return
3360 value is:
3362 0...31: single-precision registers s0...s31
3363 32...63: double-precision registers d0...d31.
3365 Although X should be zero for VFP11 (encoding d0...d15 only), we might
3366 encounter VFP3 instructions, so we allow the full range for DP registers. */
3368 static unsigned int
3369 bfd_arm_vfp11_regno (unsigned int insn, bfd_boolean is_double, unsigned int rx,
3370 unsigned int x)
3372 if (is_double)
3373 return (((insn >> rx) & 0xf) | (((insn >> x) & 1) << 4)) + 32;
3374 else
3375 return (((insn >> rx) & 0xf) << 1) | ((insn >> x) & 1);
3378 /* Set bits in *WMASK according to a register number REG as encoded by
3379 bfd_arm_vfp11_regno(). Ignore d16-d31. */
3381 static void
3382 bfd_arm_vfp11_write_mask (unsigned int *wmask, unsigned int reg)
3384 if (reg < 32)
3385 *wmask |= 1 << reg;
3386 else if (reg < 48)
3387 *wmask |= 3 << ((reg - 32) * 2);
3390 /* Return TRUE if WMASK overwrites anything in REGS. */
3392 static bfd_boolean
3393 bfd_arm_vfp11_antidependency (unsigned int wmask, int *regs, int numregs)
3395 int i;
3397 for (i = 0; i < numregs; i++)
3399 unsigned int reg = regs[i];
3401 if (reg < 32 && (wmask & (1 << reg)) != 0)
3402 return TRUE;
3404 reg -= 32;
3406 if (reg >= 16)
3407 continue;
3409 if ((wmask & (3 << (reg * 2))) != 0)
3410 return TRUE;
3413 return FALSE;
3416 /* In this function, we're interested in two things: finding input registers
3417 for VFP data-processing instructions, and finding the set of registers which
3418 arbitrary VFP instructions may write to. We use a 32-bit unsigned int to
3419 hold the written set, so FLDM etc. are easy to deal with (we're only
3420 interested in 32 SP registers or 16 dp registers, due to the VFP version
3421 implemented by the chip in question). DP registers are marked by setting
3422 both SP registers in the write mask). */
3424 static enum bfd_arm_vfp11_pipe
3425 bfd_arm_vfp11_insn_decode (unsigned int insn, unsigned int *destmask, int *regs,
3426 int *numregs)
3428 enum bfd_arm_vfp11_pipe pipe = VFP11_BAD;
3429 bfd_boolean is_double = ((insn & 0xf00) == 0xb00) ? 1 : 0;
3431 if ((insn & 0x0f000e10) == 0x0e000a00) /* A data-processing insn. */
3433 unsigned int pqrs;
3434 unsigned int fd = bfd_arm_vfp11_regno (insn, is_double, 12, 22);
3435 unsigned int fm = bfd_arm_vfp11_regno (insn, is_double, 0, 5);
3437 pqrs = ((insn & 0x00800000) >> 20)
3438 | ((insn & 0x00300000) >> 19)
3439 | ((insn & 0x00000040) >> 6);
3441 switch (pqrs)
3443 case 0: /* fmac[sd]. */
3444 case 1: /* fnmac[sd]. */
3445 case 2: /* fmsc[sd]. */
3446 case 3: /* fnmsc[sd]. */
3447 pipe = VFP11_FMAC;
3448 bfd_arm_vfp11_write_mask (destmask, fd);
3449 regs[0] = fd;
3450 regs[1] = bfd_arm_vfp11_regno (insn, is_double, 16, 7); /* Fn. */
3451 regs[2] = fm;
3452 *numregs = 3;
3453 break;
3455 case 4: /* fmul[sd]. */
3456 case 5: /* fnmul[sd]. */
3457 case 6: /* fadd[sd]. */
3458 case 7: /* fsub[sd]. */
3459 pipe = VFP11_FMAC;
3460 goto vfp_binop;
3462 case 8: /* fdiv[sd]. */
3463 pipe = VFP11_DS;
3464 vfp_binop:
3465 bfd_arm_vfp11_write_mask (destmask, fd);
3466 regs[0] = bfd_arm_vfp11_regno (insn, is_double, 16, 7); /* Fn. */
3467 regs[1] = fm;
3468 *numregs = 2;
3469 break;
3471 case 15: /* extended opcode. */
3473 unsigned int extn = ((insn >> 15) & 0x1e)
3474 | ((insn >> 7) & 1);
3476 switch (extn)
3478 case 0: /* fcpy[sd]. */
3479 case 1: /* fabs[sd]. */
3480 case 2: /* fneg[sd]. */
3481 case 8: /* fcmp[sd]. */
3482 case 9: /* fcmpe[sd]. */
3483 case 10: /* fcmpz[sd]. */
3484 case 11: /* fcmpez[sd]. */
3485 case 16: /* fuito[sd]. */
3486 case 17: /* fsito[sd]. */
3487 case 24: /* ftoui[sd]. */
3488 case 25: /* ftouiz[sd]. */
3489 case 26: /* ftosi[sd]. */
3490 case 27: /* ftosiz[sd]. */
3491 /* These instructions will not bounce due to underflow. */
3492 *numregs = 0;
3493 pipe = VFP11_FMAC;
3494 break;
3496 case 3: /* fsqrt[sd]. */
3497 /* fsqrt cannot underflow, but it can (perhaps) overwrite
3498 registers to cause the erratum in previous instructions. */
3499 bfd_arm_vfp11_write_mask (destmask, fd);
3500 pipe = VFP11_DS;
3501 break;
3503 case 15: /* fcvt{ds,sd}. */
3505 int rnum = 0;
3507 bfd_arm_vfp11_write_mask (destmask, fd);
3509 /* Only FCVTSD can underflow. */
3510 if ((insn & 0x100) != 0)
3511 regs[rnum++] = fm;
3513 *numregs = rnum;
3515 pipe = VFP11_FMAC;
3517 break;
3519 default:
3520 return VFP11_BAD;
3523 break;
3525 default:
3526 return VFP11_BAD;
3529 /* Two-register transfer. */
3530 else if ((insn & 0x0fe00ed0) == 0x0c400a10)
3532 unsigned int fm = bfd_arm_vfp11_regno (insn, is_double, 0, 5);
3534 if ((insn & 0x100000) == 0)
3536 if (is_double)
3537 bfd_arm_vfp11_write_mask (destmask, fm);
3538 else
3540 bfd_arm_vfp11_write_mask (destmask, fm);
3541 bfd_arm_vfp11_write_mask (destmask, fm + 1);
3545 pipe = VFP11_LS;
3547 else if ((insn & 0x0e100e00) == 0x0c100a00) /* A load insn. */
3549 int fd = bfd_arm_vfp11_regno (insn, is_double, 12, 22);
3550 unsigned int puw = ((insn >> 21) & 0x1) | (((insn >> 23) & 3) << 1);
3552 switch (puw)
3554 case 0: /* Two-reg transfer. We should catch these above. */
3555 abort ();
3557 case 2: /* fldm[sdx]. */
3558 case 3:
3559 case 5:
3561 unsigned int i, offset = insn & 0xff;
3563 if (is_double)
3564 offset >>= 1;
3566 for (i = fd; i < fd + offset; i++)
3567 bfd_arm_vfp11_write_mask (destmask, i);
3569 break;
3571 case 4: /* fld[sd]. */
3572 case 6:
3573 bfd_arm_vfp11_write_mask (destmask, fd);
3574 break;
3576 default:
3577 return VFP11_BAD;
3580 pipe = VFP11_LS;
3582 /* Single-register transfer. Note L==0. */
3583 else if ((insn & 0x0f100e10) == 0x0e000a10)
3585 unsigned int opcode = (insn >> 21) & 7;
3586 unsigned int fn = bfd_arm_vfp11_regno (insn, is_double, 16, 7);
3588 switch (opcode)
3590 case 0: /* fmsr/fmdlr. */
3591 case 1: /* fmdhr. */
3592 /* Mark fmdhr and fmdlr as writing to the whole of the DP
3593 destination register. I don't know if this is exactly right,
3594 but it is the conservative choice. */
3595 bfd_arm_vfp11_write_mask (destmask, fn);
3596 break;
3598 case 7: /* fmxr. */
3599 break;
3602 pipe = VFP11_LS;
3605 return pipe;
3609 static int elf32_arm_compare_mapping (const void * a, const void * b);
3612 /* Look for potentially-troublesome code sequences which might trigger the
3613 VFP11 denormal/antidependency erratum. See, e.g., the ARM1136 errata sheet
3614 (available from ARM) for details of the erratum. A short version is
3615 described in ld.texinfo. */
3617 bfd_boolean
3618 bfd_elf32_arm_vfp11_erratum_scan (bfd *abfd, struct bfd_link_info *link_info)
3620 asection *sec;
3621 bfd_byte *contents = NULL;
3622 int state = 0;
3623 int regs[3], numregs = 0;
3624 struct elf32_arm_link_hash_table *globals = elf32_arm_hash_table (link_info);
3625 int use_vector = (globals->vfp11_fix == BFD_ARM_VFP11_FIX_VECTOR);
3627 /* We use a simple FSM to match troublesome VFP11 instruction sequences.
3628 The states transition as follows:
3630 0 -> 1 (vector) or 0 -> 2 (scalar)
3631 A VFP FMAC-pipeline instruction has been seen. Fill
3632 regs[0]..regs[numregs-1] with its input operands. Remember this
3633 instruction in 'first_fmac'.
3635 1 -> 2
3636 Any instruction, except for a VFP instruction which overwrites
3637 regs[*].
3639 1 -> 3 [ -> 0 ] or
3640 2 -> 3 [ -> 0 ]
3641 A VFP instruction has been seen which overwrites any of regs[*].
3642 We must make a veneer! Reset state to 0 before examining next
3643 instruction.
3645 2 -> 0
3646 If we fail to match anything in state 2, reset to state 0 and reset
3647 the instruction pointer to the instruction after 'first_fmac'.
3649 If the VFP11 vector mode is in use, there must be at least two unrelated
3650 instructions between anti-dependent VFP11 instructions to properly avoid
3651 triggering the erratum, hence the use of the extra state 1.
3654 /* If we are only performing a partial link do not bother
3655 to construct any glue. */
3656 if (link_info->relocatable)
3657 return TRUE;
3659 /* We should have chosen a fix type by the time we get here. */
3660 BFD_ASSERT (globals->vfp11_fix != BFD_ARM_VFP11_FIX_DEFAULT);
3662 if (globals->vfp11_fix == BFD_ARM_VFP11_FIX_NONE)
3663 return TRUE;
3665 /* Skip if this bfd does not correspond to an ELF image. */
3666 if (bfd_get_flavour (abfd) != bfd_target_elf_flavour)
3667 return TRUE;
3669 for (sec = abfd->sections; sec != NULL; sec = sec->next)
3671 unsigned int i, span, first_fmac = 0, veneer_of_insn = 0;
3672 struct _arm_elf_section_data *sec_data;
3674 /* If we don't have executable progbits, we're not interested in this
3675 section. Also skip if section is to be excluded. */
3676 if (elf_section_type (sec) != SHT_PROGBITS
3677 || (elf_section_flags (sec) & SHF_EXECINSTR) == 0
3678 || (sec->flags & SEC_EXCLUDE) != 0
3679 || strcmp (sec->name, VFP11_ERRATUM_VENEER_SECTION_NAME) == 0)
3680 continue;
3682 sec_data = elf32_arm_section_data (sec);
3684 if (sec_data->mapcount == 0)
3685 continue;
3687 if (elf_section_data (sec)->this_hdr.contents != NULL)
3688 contents = elf_section_data (sec)->this_hdr.contents;
3689 else if (! bfd_malloc_and_get_section (abfd, sec, &contents))
3690 goto error_return;
3692 qsort (sec_data->map, sec_data->mapcount, sizeof (elf32_arm_section_map),
3693 elf32_arm_compare_mapping);
3695 for (span = 0; span < sec_data->mapcount; span++)
3697 unsigned int span_start = sec_data->map[span].vma;
3698 unsigned int span_end = (span == sec_data->mapcount - 1)
3699 ? sec->size : sec_data->map[span + 1].vma;
3700 char span_type = sec_data->map[span].type;
3702 /* FIXME: Only ARM mode is supported at present. We may need to
3703 support Thumb-2 mode also at some point. */
3704 if (span_type != 'a')
3705 continue;
3707 for (i = span_start; i < span_end;)
3709 unsigned int next_i = i + 4;
3710 unsigned int insn = bfd_big_endian (abfd)
3711 ? (contents[i] << 24)
3712 | (contents[i + 1] << 16)
3713 | (contents[i + 2] << 8)
3714 | contents[i + 3]
3715 : (contents[i + 3] << 24)
3716 | (contents[i + 2] << 16)
3717 | (contents[i + 1] << 8)
3718 | contents[i];
3719 unsigned int writemask = 0;
3720 enum bfd_arm_vfp11_pipe pipe;
3722 switch (state)
3724 case 0:
3725 pipe = bfd_arm_vfp11_insn_decode (insn, &writemask, regs,
3726 &numregs);
3727 /* I'm assuming the VFP11 erratum can trigger with denorm
3728 operands on either the FMAC or the DS pipeline. This might
3729 lead to slightly overenthusiastic veneer insertion. */
3730 if (pipe == VFP11_FMAC || pipe == VFP11_DS)
3732 state = use_vector ? 1 : 2;
3733 first_fmac = i;
3734 veneer_of_insn = insn;
3736 break;
3738 case 1:
3740 int other_regs[3], other_numregs;
3741 pipe = bfd_arm_vfp11_insn_decode (insn, &writemask,
3742 other_regs,
3743 &other_numregs);
3744 if (pipe != VFP11_BAD
3745 && bfd_arm_vfp11_antidependency (writemask, regs,
3746 numregs))
3747 state = 3;
3748 else
3749 state = 2;
3751 break;
3753 case 2:
3755 int other_regs[3], other_numregs;
3756 pipe = bfd_arm_vfp11_insn_decode (insn, &writemask,
3757 other_regs,
3758 &other_numregs);
3759 if (pipe != VFP11_BAD
3760 && bfd_arm_vfp11_antidependency (writemask, regs,
3761 numregs))
3762 state = 3;
3763 else
3765 state = 0;
3766 next_i = first_fmac + 4;
3769 break;
3771 case 3:
3772 abort (); /* Should be unreachable. */
3775 if (state == 3)
3777 elf32_vfp11_erratum_list *newerr
3778 = bfd_zmalloc (sizeof (elf32_vfp11_erratum_list));
3779 int errcount;
3781 errcount = ++(elf32_arm_section_data (sec)->erratumcount);
3783 newerr->u.b.vfp_insn = veneer_of_insn;
3785 switch (span_type)
3787 case 'a':
3788 newerr->type = VFP11_ERRATUM_BRANCH_TO_ARM_VENEER;
3789 break;
3791 default:
3792 abort ();
3795 record_vfp11_erratum_veneer (link_info, newerr, abfd, sec,
3796 first_fmac);
3798 newerr->vma = -1;
3800 newerr->next = sec_data->erratumlist;
3801 sec_data->erratumlist = newerr;
3803 state = 0;
3806 i = next_i;
3810 if (contents != NULL
3811 && elf_section_data (sec)->this_hdr.contents != contents)
3812 free (contents);
3813 contents = NULL;
3816 return TRUE;
3818 error_return:
3819 if (contents != NULL
3820 && elf_section_data (sec)->this_hdr.contents != contents)
3821 free (contents);
3823 return FALSE;
3826 /* Find virtual-memory addresses for VFP11 erratum veneers and return locations
3827 after sections have been laid out, using specially-named symbols. */
3829 void
3830 bfd_elf32_arm_vfp11_fix_veneer_locations (bfd *abfd,
3831 struct bfd_link_info *link_info)
3833 asection *sec;
3834 struct elf32_arm_link_hash_table *globals;
3835 char *tmp_name;
3837 if (link_info->relocatable)
3838 return;
3840 /* Skip if this bfd does not correspond to an ELF image. */
3841 if (bfd_get_flavour (abfd) != bfd_target_elf_flavour)
3842 return;
3844 globals = elf32_arm_hash_table (link_info);
3846 tmp_name = bfd_malloc ((bfd_size_type) strlen
3847 (VFP11_ERRATUM_VENEER_ENTRY_NAME) + 10);
3849 for (sec = abfd->sections; sec != NULL; sec = sec->next)
3851 struct _arm_elf_section_data *sec_data = elf32_arm_section_data (sec);
3852 elf32_vfp11_erratum_list *errnode = sec_data->erratumlist;
3854 for (; errnode != NULL; errnode = errnode->next)
3856 struct elf_link_hash_entry *myh;
3857 bfd_vma vma;
3859 switch (errnode->type)
3861 case VFP11_ERRATUM_BRANCH_TO_ARM_VENEER:
3862 case VFP11_ERRATUM_BRANCH_TO_THUMB_VENEER:
3863 /* Find veneer symbol. */
3864 sprintf (tmp_name, VFP11_ERRATUM_VENEER_ENTRY_NAME,
3865 errnode->u.b.veneer->u.v.id);
3867 myh = elf_link_hash_lookup
3868 (&(globals)->root, tmp_name, FALSE, FALSE, TRUE);
3870 if (myh == NULL)
3871 (*_bfd_error_handler) (_("%B: unable to find VFP11 veneer "
3872 "`%s'"), abfd, tmp_name);
3874 vma = myh->root.u.def.section->output_section->vma
3875 + myh->root.u.def.section->output_offset
3876 + myh->root.u.def.value;
3878 errnode->u.b.veneer->vma = vma;
3879 break;
3881 case VFP11_ERRATUM_ARM_VENEER:
3882 case VFP11_ERRATUM_THUMB_VENEER:
3883 /* Find return location. */
3884 sprintf (tmp_name, VFP11_ERRATUM_VENEER_ENTRY_NAME "_r",
3885 errnode->u.v.id);
3887 myh = elf_link_hash_lookup
3888 (&(globals)->root, tmp_name, FALSE, FALSE, TRUE);
3890 if (myh == NULL)
3891 (*_bfd_error_handler) (_("%B: unable to find VFP11 veneer "
3892 "`%s'"), abfd, tmp_name);
3894 vma = myh->root.u.def.section->output_section->vma
3895 + myh->root.u.def.section->output_offset
3896 + myh->root.u.def.value;
3898 errnode->u.v.branch->vma = vma;
3899 break;
3901 default:
3902 abort ();
3907 free (tmp_name);
3911 /* Set target relocation values needed during linking. */
3913 void
3914 bfd_elf32_arm_set_target_relocs (struct bfd *output_bfd,
3915 struct bfd_link_info *link_info,
3916 int target1_is_rel,
3917 char * target2_type,
3918 int fix_v4bx,
3919 int use_blx,
3920 bfd_arm_vfp11_fix vfp11_fix,
3921 int no_enum_warn, int pic_veneer)
3923 struct elf32_arm_link_hash_table *globals;
3925 globals = elf32_arm_hash_table (link_info);
3927 globals->target1_is_rel = target1_is_rel;
3928 if (strcmp (target2_type, "rel") == 0)
3929 globals->target2_reloc = R_ARM_REL32;
3930 else if (strcmp (target2_type, "abs") == 0)
3931 globals->target2_reloc = R_ARM_ABS32;
3932 else if (strcmp (target2_type, "got-rel") == 0)
3933 globals->target2_reloc = R_ARM_GOT_PREL;
3934 else
3936 _bfd_error_handler (_("Invalid TARGET2 relocation type '%s'."),
3937 target2_type);
3939 globals->fix_v4bx = fix_v4bx;
3940 globals->use_blx |= use_blx;
3941 globals->vfp11_fix = vfp11_fix;
3942 globals->pic_veneer = pic_veneer;
3944 elf32_arm_tdata (output_bfd)->no_enum_size_warning = no_enum_warn;
3947 /* The thumb form of a long branch is a bit finicky, because the offset
3948 encoding is split over two fields, each in it's own instruction. They
3949 can occur in any order. So given a thumb form of long branch, and an
3950 offset, insert the offset into the thumb branch and return finished
3951 instruction.
3953 It takes two thumb instructions to encode the target address. Each has
3954 11 bits to invest. The upper 11 bits are stored in one (identified by
3955 H-0.. see below), the lower 11 bits are stored in the other (identified
3956 by H-1).
3958 Combine together and shifted left by 1 (it's a half word address) and
3959 there you have it.
3961 Op: 1111 = F,
3962 H-0, upper address-0 = 000
3963 Op: 1111 = F,
3964 H-1, lower address-0 = 800
3966 They can be ordered either way, but the arm tools I've seen always put
3967 the lower one first. It probably doesn't matter. krk@cygnus.com
3969 XXX: Actually the order does matter. The second instruction (H-1)
3970 moves the computed address into the PC, so it must be the second one
3971 in the sequence. The problem, however is that whilst little endian code
3972 stores the instructions in HI then LOW order, big endian code does the
3973 reverse. nickc@cygnus.com. */
3975 #define LOW_HI_ORDER 0xF800F000
3976 #define HI_LOW_ORDER 0xF000F800
3978 static insn32
3979 insert_thumb_branch (insn32 br_insn, int rel_off)
3981 unsigned int low_bits;
3982 unsigned int high_bits;
3984 BFD_ASSERT ((rel_off & 1) != 1);
3986 rel_off >>= 1; /* Half word aligned address. */
3987 low_bits = rel_off & 0x000007FF; /* The bottom 11 bits. */
3988 high_bits = (rel_off >> 11) & 0x000007FF; /* The top 11 bits. */
3990 if ((br_insn & LOW_HI_ORDER) == LOW_HI_ORDER)
3991 br_insn = LOW_HI_ORDER | (low_bits << 16) | high_bits;
3992 else if ((br_insn & HI_LOW_ORDER) == HI_LOW_ORDER)
3993 br_insn = HI_LOW_ORDER | (high_bits << 16) | low_bits;
3994 else
3995 /* FIXME: abort is probably not the right call. krk@cygnus.com */
3996 abort (); /* Error - not a valid branch instruction form. */
3998 return br_insn;
4002 /* Store an Arm insn into an output section not processed by
4003 elf32_arm_write_section. */
4005 static void
4006 put_arm_insn (struct elf32_arm_link_hash_table *htab,
4007 bfd * output_bfd, bfd_vma val, void * ptr)
4009 if (htab->byteswap_code != bfd_little_endian (output_bfd))
4010 bfd_putl32 (val, ptr);
4011 else
4012 bfd_putb32 (val, ptr);
4016 /* Store a 16-bit Thumb insn into an output section not processed by
4017 elf32_arm_write_section. */
4019 static void
4020 put_thumb_insn (struct elf32_arm_link_hash_table *htab,
4021 bfd * output_bfd, bfd_vma val, void * ptr)
4023 if (htab->byteswap_code != bfd_little_endian (output_bfd))
4024 bfd_putl16 (val, ptr);
4025 else
4026 bfd_putb16 (val, ptr);
4030 /* Thumb code calling an ARM function. */
4032 static int
4033 elf32_thumb_to_arm_stub (struct bfd_link_info * info,
4034 const char * name,
4035 bfd * input_bfd,
4036 bfd * output_bfd,
4037 asection * input_section,
4038 bfd_byte * hit_data,
4039 asection * sym_sec,
4040 bfd_vma offset,
4041 bfd_signed_vma addend,
4042 bfd_vma val,
4043 char **error_message)
4045 asection * s = 0;
4046 bfd_vma my_offset;
4047 unsigned long int tmp;
4048 long int ret_offset;
4049 struct elf_link_hash_entry * myh;
4050 struct elf32_arm_link_hash_table * globals;
4052 myh = find_thumb_glue (info, name, error_message);
4053 if (myh == NULL)
4054 return FALSE;
4056 globals = elf32_arm_hash_table (info);
4058 BFD_ASSERT (globals != NULL);
4059 BFD_ASSERT (globals->bfd_of_glue_owner != NULL);
4061 my_offset = myh->root.u.def.value;
4063 s = bfd_get_section_by_name (globals->bfd_of_glue_owner,
4064 THUMB2ARM_GLUE_SECTION_NAME);
4066 BFD_ASSERT (s != NULL);
4067 BFD_ASSERT (s->contents != NULL);
4068 BFD_ASSERT (s->output_section != NULL);
4070 if ((my_offset & 0x01) == 0x01)
4072 if (sym_sec != NULL
4073 && sym_sec->owner != NULL
4074 && !INTERWORK_FLAG (sym_sec->owner))
4076 (*_bfd_error_handler)
4077 (_("%B(%s): warning: interworking not enabled.\n"
4078 " first occurrence: %B: thumb call to arm"),
4079 sym_sec->owner, input_bfd, name);
4081 return FALSE;
4084 --my_offset;
4085 myh->root.u.def.value = my_offset;
4087 put_thumb_insn (globals, output_bfd, (bfd_vma) t2a1_bx_pc_insn,
4088 s->contents + my_offset);
4090 put_thumb_insn (globals, output_bfd, (bfd_vma) t2a2_noop_insn,
4091 s->contents + my_offset + 2);
4093 ret_offset =
4094 /* Address of destination of the stub. */
4095 ((bfd_signed_vma) val)
4096 - ((bfd_signed_vma)
4097 /* Offset from the start of the current section
4098 to the start of the stubs. */
4099 (s->output_offset
4100 /* Offset of the start of this stub from the start of the stubs. */
4101 + my_offset
4102 /* Address of the start of the current section. */
4103 + s->output_section->vma)
4104 /* The branch instruction is 4 bytes into the stub. */
4106 /* ARM branches work from the pc of the instruction + 8. */
4107 + 8);
4109 put_arm_insn (globals, output_bfd,
4110 (bfd_vma) t2a3_b_insn | ((ret_offset >> 2) & 0x00FFFFFF),
4111 s->contents + my_offset + 4);
4114 BFD_ASSERT (my_offset <= globals->thumb_glue_size);
4116 /* Now go back and fix up the original BL insn to point to here. */
4117 ret_offset =
4118 /* Address of where the stub is located. */
4119 (s->output_section->vma + s->output_offset + my_offset)
4120 /* Address of where the BL is located. */
4121 - (input_section->output_section->vma + input_section->output_offset
4122 + offset)
4123 /* Addend in the relocation. */
4124 - addend
4125 /* Biassing for PC-relative addressing. */
4126 - 8;
4128 tmp = bfd_get_32 (input_bfd, hit_data
4129 - input_section->vma);
4131 bfd_put_32 (output_bfd,
4132 (bfd_vma) insert_thumb_branch (tmp, ret_offset),
4133 hit_data - input_section->vma);
4135 return TRUE;
4138 /* Populate an Arm to Thumb stub. Returns the stub symbol. */
4140 static struct elf_link_hash_entry *
4141 elf32_arm_create_thumb_stub (struct bfd_link_info * info,
4142 const char * name,
4143 bfd * input_bfd,
4144 bfd * output_bfd,
4145 asection * sym_sec,
4146 bfd_vma val,
4147 asection *s,
4148 char **error_message)
4150 bfd_vma my_offset;
4151 long int ret_offset;
4152 struct elf_link_hash_entry * myh;
4153 struct elf32_arm_link_hash_table * globals;
4155 myh = find_arm_glue (info, name, error_message);
4156 if (myh == NULL)
4157 return NULL;
4159 globals = elf32_arm_hash_table (info);
4161 BFD_ASSERT (globals != NULL);
4162 BFD_ASSERT (globals->bfd_of_glue_owner != NULL);
4164 my_offset = myh->root.u.def.value;
4166 if ((my_offset & 0x01) == 0x01)
4168 if (sym_sec != NULL
4169 && sym_sec->owner != NULL
4170 && !INTERWORK_FLAG (sym_sec->owner))
4172 (*_bfd_error_handler)
4173 (_("%B(%s): warning: interworking not enabled.\n"
4174 " first occurrence: %B: arm call to thumb"),
4175 sym_sec->owner, input_bfd, name);
4178 --my_offset;
4179 myh->root.u.def.value = my_offset;
4181 if (info->shared || globals->root.is_relocatable_executable
4182 || globals->pic_veneer)
4184 /* For relocatable objects we can't use absolute addresses,
4185 so construct the address from a relative offset. */
4186 /* TODO: If the offset is small it's probably worth
4187 constructing the address with adds. */
4188 put_arm_insn (globals, output_bfd, (bfd_vma) a2t1p_ldr_insn,
4189 s->contents + my_offset);
4190 put_arm_insn (globals, output_bfd, (bfd_vma) a2t2p_add_pc_insn,
4191 s->contents + my_offset + 4);
4192 put_arm_insn (globals, output_bfd, (bfd_vma) a2t3p_bx_r12_insn,
4193 s->contents + my_offset + 8);
4194 /* Adjust the offset by 4 for the position of the add,
4195 and 8 for the pipeline offset. */
4196 ret_offset = (val - (s->output_offset
4197 + s->output_section->vma
4198 + my_offset + 12))
4199 | 1;
4200 bfd_put_32 (output_bfd, ret_offset,
4201 s->contents + my_offset + 12);
4203 else if (globals->use_blx)
4205 put_arm_insn (globals, output_bfd, (bfd_vma) a2t1v5_ldr_insn,
4206 s->contents + my_offset);
4208 /* It's a thumb address. Add the low order bit. */
4209 bfd_put_32 (output_bfd, val | a2t2v5_func_addr_insn,
4210 s->contents + my_offset + 4);
4212 else
4214 put_arm_insn (globals, output_bfd, (bfd_vma) a2t1_ldr_insn,
4215 s->contents + my_offset);
4217 put_arm_insn (globals, output_bfd, (bfd_vma) a2t2_bx_r12_insn,
4218 s->contents + my_offset + 4);
4220 /* It's a thumb address. Add the low order bit. */
4221 bfd_put_32 (output_bfd, val | a2t3_func_addr_insn,
4222 s->contents + my_offset + 8);
4226 BFD_ASSERT (my_offset <= globals->arm_glue_size);
4228 return myh;
4231 /* Arm code calling a Thumb function. */
4233 static int
4234 elf32_arm_to_thumb_stub (struct bfd_link_info * info,
4235 const char * name,
4236 bfd * input_bfd,
4237 bfd * output_bfd,
4238 asection * input_section,
4239 bfd_byte * hit_data,
4240 asection * sym_sec,
4241 bfd_vma offset,
4242 bfd_signed_vma addend,
4243 bfd_vma val,
4244 char **error_message)
4246 unsigned long int tmp;
4247 bfd_vma my_offset;
4248 asection * s;
4249 long int ret_offset;
4250 struct elf_link_hash_entry * myh;
4251 struct elf32_arm_link_hash_table * globals;
4253 globals = elf32_arm_hash_table (info);
4255 BFD_ASSERT (globals != NULL);
4256 BFD_ASSERT (globals->bfd_of_glue_owner != NULL);
4258 s = bfd_get_section_by_name (globals->bfd_of_glue_owner,
4259 ARM2THUMB_GLUE_SECTION_NAME);
4260 BFD_ASSERT (s != NULL);
4261 BFD_ASSERT (s->contents != NULL);
4262 BFD_ASSERT (s->output_section != NULL);
4264 myh = elf32_arm_create_thumb_stub (info, name, input_bfd, output_bfd,
4265 sym_sec, val, s, error_message);
4266 if (!myh)
4267 return FALSE;
4269 my_offset = myh->root.u.def.value;
4270 tmp = bfd_get_32 (input_bfd, hit_data);
4271 tmp = tmp & 0xFF000000;
4273 /* Somehow these are both 4 too far, so subtract 8. */
4274 ret_offset = (s->output_offset
4275 + my_offset
4276 + s->output_section->vma
4277 - (input_section->output_offset
4278 + input_section->output_section->vma
4279 + offset + addend)
4280 - 8);
4282 tmp = tmp | ((ret_offset >> 2) & 0x00FFFFFF);
4284 bfd_put_32 (output_bfd, (bfd_vma) tmp, hit_data - input_section->vma);
4286 return TRUE;
4289 /* Populate Arm stub for an exported Thumb function. */
4291 static bfd_boolean
4292 elf32_arm_to_thumb_export_stub (struct elf_link_hash_entry *h, void * inf)
4294 struct bfd_link_info * info = (struct bfd_link_info *) inf;
4295 asection * s;
4296 struct elf_link_hash_entry * myh;
4297 struct elf32_arm_link_hash_entry *eh;
4298 struct elf32_arm_link_hash_table * globals;
4299 asection *sec;
4300 bfd_vma val;
4301 char *error_message;
4303 eh = elf32_arm_hash_entry(h);
4304 /* Allocate stubs for exported Thumb functions on v4t. */
4305 if (eh->export_glue == NULL)
4306 return TRUE;
4308 globals = elf32_arm_hash_table (info);
4310 BFD_ASSERT (globals != NULL);
4311 BFD_ASSERT (globals->bfd_of_glue_owner != NULL);
4313 s = bfd_get_section_by_name (globals->bfd_of_glue_owner,
4314 ARM2THUMB_GLUE_SECTION_NAME);
4315 BFD_ASSERT (s != NULL);
4316 BFD_ASSERT (s->contents != NULL);
4317 BFD_ASSERT (s->output_section != NULL);
4319 sec = eh->export_glue->root.u.def.section;
4321 BFD_ASSERT (sec->output_section != NULL);
4323 val = eh->export_glue->root.u.def.value + sec->output_offset
4324 + sec->output_section->vma;
4325 myh = elf32_arm_create_thumb_stub (info, h->root.root.string,
4326 h->root.u.def.section->owner,
4327 globals->obfd, sec, val, s,
4328 &error_message);
4329 BFD_ASSERT (myh);
4330 return TRUE;
4333 /* Generate Arm stubs for exported Thumb symbols. */
4334 static void
4335 elf32_arm_begin_write_processing (bfd *abfd ATTRIBUTE_UNUSED,
4336 struct bfd_link_info *link_info)
4338 struct elf32_arm_link_hash_table * globals;
4340 if (!link_info)
4341 return;
4343 globals = elf32_arm_hash_table (link_info);
4344 /* If blx is available then exported Thumb symbols are OK and there is
4345 nothing to do. */
4346 if (globals->use_blx)
4347 return;
4349 elf_link_hash_traverse (&globals->root, elf32_arm_to_thumb_export_stub,
4350 link_info);
4353 /* Some relocations map to different relocations depending on the
4354 target. Return the real relocation. */
4355 static int
4356 arm_real_reloc_type (struct elf32_arm_link_hash_table * globals,
4357 int r_type)
4359 switch (r_type)
4361 case R_ARM_TARGET1:
4362 if (globals->target1_is_rel)
4363 return R_ARM_REL32;
4364 else
4365 return R_ARM_ABS32;
4367 case R_ARM_TARGET2:
4368 return globals->target2_reloc;
4370 default:
4371 return r_type;
4375 /* Return the base VMA address which should be subtracted from real addresses
4376 when resolving @dtpoff relocation.
4377 This is PT_TLS segment p_vaddr. */
4379 static bfd_vma
4380 dtpoff_base (struct bfd_link_info *info)
4382 /* If tls_sec is NULL, we should have signalled an error already. */
4383 if (elf_hash_table (info)->tls_sec == NULL)
4384 return 0;
4385 return elf_hash_table (info)->tls_sec->vma;
4388 /* Return the relocation value for @tpoff relocation
4389 if STT_TLS virtual address is ADDRESS. */
4391 static bfd_vma
4392 tpoff (struct bfd_link_info *info, bfd_vma address)
4394 struct elf_link_hash_table *htab = elf_hash_table (info);
4395 bfd_vma base;
4397 /* If tls_sec is NULL, we should have signalled an error already. */
4398 if (htab->tls_sec == NULL)
4399 return 0;
4400 base = align_power ((bfd_vma) TCB_SIZE, htab->tls_sec->alignment_power);
4401 return address - htab->tls_sec->vma + base;
4404 /* Perform an R_ARM_ABS12 relocation on the field pointed to by DATA.
4405 VALUE is the relocation value. */
4407 static bfd_reloc_status_type
4408 elf32_arm_abs12_reloc (bfd *abfd, void *data, bfd_vma value)
4410 if (value > 0xfff)
4411 return bfd_reloc_overflow;
4413 value |= bfd_get_32 (abfd, data) & 0xfffff000;
4414 bfd_put_32 (abfd, value, data);
4415 return bfd_reloc_ok;
4418 /* For a given value of n, calculate the value of G_n as required to
4419 deal with group relocations. We return it in the form of an
4420 encoded constant-and-rotation, together with the final residual. If n is
4421 specified as less than zero, then final_residual is filled with the
4422 input value and no further action is performed. */
4424 static bfd_vma
4425 calculate_group_reloc_mask (bfd_vma value, int n, bfd_vma *final_residual)
4427 int current_n;
4428 bfd_vma g_n;
4429 bfd_vma encoded_g_n = 0;
4430 bfd_vma residual = value; /* Also known as Y_n. */
4432 for (current_n = 0; current_n <= n; current_n++)
4434 int shift;
4436 /* Calculate which part of the value to mask. */
4437 if (residual == 0)
4438 shift = 0;
4439 else
4441 int msb;
4443 /* Determine the most significant bit in the residual and
4444 align the resulting value to a 2-bit boundary. */
4445 for (msb = 30; msb >= 0; msb -= 2)
4446 if (residual & (3 << msb))
4447 break;
4449 /* The desired shift is now (msb - 6), or zero, whichever
4450 is the greater. */
4451 shift = msb - 6;
4452 if (shift < 0)
4453 shift = 0;
4456 /* Calculate g_n in 32-bit as well as encoded constant+rotation form. */
4457 g_n = residual & (0xff << shift);
4458 encoded_g_n = (g_n >> shift)
4459 | ((g_n <= 0xff ? 0 : (32 - shift) / 2) << 8);
4461 /* Calculate the residual for the next time around. */
4462 residual &= ~g_n;
4465 *final_residual = residual;
4467 return encoded_g_n;
4470 /* Given an ARM instruction, determine whether it is an ADD or a SUB.
4471 Returns 1 if it is an ADD, -1 if it is a SUB, and 0 otherwise. */
4472 static int
4473 identify_add_or_sub(bfd_vma insn)
4475 int opcode = insn & 0x1e00000;
4477 if (opcode == 1 << 23) /* ADD */
4478 return 1;
4480 if (opcode == 1 << 22) /* SUB */
4481 return -1;
4483 return 0;
4486 /* Determine if we're dealing with a Thumb-2 object. */
4488 static int using_thumb2 (struct elf32_arm_link_hash_table *globals)
4490 int arch = elf32_arm_get_eabi_attr_int (globals->obfd, Tag_CPU_arch);
4491 return arch == TAG_CPU_ARCH_V6T2 || arch >= TAG_CPU_ARCH_V7;
4494 /* Perform a relocation as part of a final link. */
4496 static bfd_reloc_status_type
4497 elf32_arm_final_link_relocate (reloc_howto_type * howto,
4498 bfd * input_bfd,
4499 bfd * output_bfd,
4500 asection * input_section,
4501 bfd_byte * contents,
4502 Elf_Internal_Rela * rel,
4503 bfd_vma value,
4504 struct bfd_link_info * info,
4505 asection * sym_sec,
4506 const char * sym_name,
4507 int sym_flags,
4508 struct elf_link_hash_entry * h,
4509 bfd_boolean * unresolved_reloc_p,
4510 char **error_message)
4512 unsigned long r_type = howto->type;
4513 unsigned long r_symndx;
4514 bfd_byte * hit_data = contents + rel->r_offset;
4515 bfd * dynobj = NULL;
4516 Elf_Internal_Shdr * symtab_hdr;
4517 struct elf_link_hash_entry ** sym_hashes;
4518 bfd_vma * local_got_offsets;
4519 asection * sgot = NULL;
4520 asection * splt = NULL;
4521 asection * sreloc = NULL;
4522 bfd_vma addend;
4523 bfd_signed_vma signed_addend;
4524 struct elf32_arm_link_hash_table * globals;
4526 globals = elf32_arm_hash_table (info);
4528 /* Some relocation type map to different relocations depending on the
4529 target. We pick the right one here. */
4530 r_type = arm_real_reloc_type (globals, r_type);
4531 if (r_type != howto->type)
4532 howto = elf32_arm_howto_from_type (r_type);
4534 /* If the start address has been set, then set the EF_ARM_HASENTRY
4535 flag. Setting this more than once is redundant, but the cost is
4536 not too high, and it keeps the code simple.
4538 The test is done here, rather than somewhere else, because the
4539 start address is only set just before the final link commences.
4541 Note - if the user deliberately sets a start address of 0, the
4542 flag will not be set. */
4543 if (bfd_get_start_address (output_bfd) != 0)
4544 elf_elfheader (output_bfd)->e_flags |= EF_ARM_HASENTRY;
4546 dynobj = elf_hash_table (info)->dynobj;
4547 if (dynobj)
4549 sgot = bfd_get_section_by_name (dynobj, ".got");
4550 splt = bfd_get_section_by_name (dynobj, ".plt");
4552 symtab_hdr = & elf_tdata (input_bfd)->symtab_hdr;
4553 sym_hashes = elf_sym_hashes (input_bfd);
4554 local_got_offsets = elf_local_got_offsets (input_bfd);
4555 r_symndx = ELF32_R_SYM (rel->r_info);
4557 if (globals->use_rel)
4559 addend = bfd_get_32 (input_bfd, hit_data) & howto->src_mask;
4561 if (addend & ((howto->src_mask + 1) >> 1))
4563 signed_addend = -1;
4564 signed_addend &= ~ howto->src_mask;
4565 signed_addend |= addend;
4567 else
4568 signed_addend = addend;
4570 else
4571 addend = signed_addend = rel->r_addend;
4573 switch (r_type)
4575 case R_ARM_NONE:
4576 /* We don't need to find a value for this symbol. It's just a
4577 marker. */
4578 *unresolved_reloc_p = FALSE;
4579 return bfd_reloc_ok;
4581 case R_ARM_ABS12:
4582 if (!globals->vxworks_p)
4583 return elf32_arm_abs12_reloc (input_bfd, hit_data, value + addend);
4585 case R_ARM_PC24:
4586 case R_ARM_ABS32:
4587 case R_ARM_ABS32_NOI:
4588 case R_ARM_REL32:
4589 case R_ARM_REL32_NOI:
4590 case R_ARM_CALL:
4591 case R_ARM_JUMP24:
4592 case R_ARM_XPC25:
4593 case R_ARM_PREL31:
4594 case R_ARM_PLT32:
4595 /* Handle relocations which should use the PLT entry. ABS32/REL32
4596 will use the symbol's value, which may point to a PLT entry, but we
4597 don't need to handle that here. If we created a PLT entry, all
4598 branches in this object should go to it. */
4599 if ((r_type != R_ARM_ABS32 && r_type != R_ARM_REL32
4600 && r_type != R_ARM_ABS32_NOI && r_type != R_ARM_REL32_NOI)
4601 && h != NULL
4602 && splt != NULL
4603 && h->plt.offset != (bfd_vma) -1)
4605 /* If we've created a .plt section, and assigned a PLT entry to
4606 this function, it should not be known to bind locally. If
4607 it were, we would have cleared the PLT entry. */
4608 BFD_ASSERT (!SYMBOL_CALLS_LOCAL (info, h));
4610 value = (splt->output_section->vma
4611 + splt->output_offset
4612 + h->plt.offset);
4613 *unresolved_reloc_p = FALSE;
4614 return _bfd_final_link_relocate (howto, input_bfd, input_section,
4615 contents, rel->r_offset, value,
4616 rel->r_addend);
4619 /* When generating a shared object or relocatable executable, these
4620 relocations are copied into the output file to be resolved at
4621 run time. */
4622 if ((info->shared || globals->root.is_relocatable_executable)
4623 && (input_section->flags & SEC_ALLOC)
4624 && ((r_type != R_ARM_REL32 && r_type != R_ARM_REL32_NOI)
4625 || !SYMBOL_CALLS_LOCAL (info, h))
4626 && (h == NULL
4627 || ELF_ST_VISIBILITY (h->other) == STV_DEFAULT
4628 || h->root.type != bfd_link_hash_undefweak)
4629 && r_type != R_ARM_PC24
4630 && r_type != R_ARM_CALL
4631 && r_type != R_ARM_JUMP24
4632 && r_type != R_ARM_PREL31
4633 && r_type != R_ARM_PLT32)
4635 Elf_Internal_Rela outrel;
4636 bfd_byte *loc;
4637 bfd_boolean skip, relocate;
4639 *unresolved_reloc_p = FALSE;
4641 if (sreloc == NULL)
4643 const char * name;
4645 name = (bfd_elf_string_from_elf_section
4646 (input_bfd,
4647 elf_elfheader (input_bfd)->e_shstrndx,
4648 elf_section_data (input_section)->rel_hdr.sh_name));
4649 if (name == NULL)
4650 return bfd_reloc_notsupported;
4652 BFD_ASSERT (reloc_section_p (globals, name, input_section));
4654 sreloc = bfd_get_section_by_name (dynobj, name);
4655 BFD_ASSERT (sreloc != NULL);
4658 skip = FALSE;
4659 relocate = FALSE;
4661 outrel.r_addend = addend;
4662 outrel.r_offset =
4663 _bfd_elf_section_offset (output_bfd, info, input_section,
4664 rel->r_offset);
4665 if (outrel.r_offset == (bfd_vma) -1)
4666 skip = TRUE;
4667 else if (outrel.r_offset == (bfd_vma) -2)
4668 skip = TRUE, relocate = TRUE;
4669 outrel.r_offset += (input_section->output_section->vma
4670 + input_section->output_offset);
4672 if (skip)
4673 memset (&outrel, 0, sizeof outrel);
4674 else if (h != NULL
4675 && h->dynindx != -1
4676 && (!info->shared
4677 || !info->symbolic
4678 || !h->def_regular))
4679 outrel.r_info = ELF32_R_INFO (h->dynindx, r_type);
4680 else
4682 int symbol;
4684 /* This symbol is local, or marked to become local. */
4685 if (sym_flags == STT_ARM_TFUNC)
4686 value |= 1;
4687 if (globals->symbian_p)
4689 asection *osec;
4691 /* On Symbian OS, the data segment and text segement
4692 can be relocated independently. Therefore, we
4693 must indicate the segment to which this
4694 relocation is relative. The BPABI allows us to
4695 use any symbol in the right segment; we just use
4696 the section symbol as it is convenient. (We
4697 cannot use the symbol given by "h" directly as it
4698 will not appear in the dynamic symbol table.)
4700 Note that the dynamic linker ignores the section
4701 symbol value, so we don't subtract osec->vma
4702 from the emitted reloc addend. */
4703 if (sym_sec)
4704 osec = sym_sec->output_section;
4705 else
4706 osec = input_section->output_section;
4707 symbol = elf_section_data (osec)->dynindx;
4708 if (symbol == 0)
4710 struct elf_link_hash_table *htab = elf_hash_table (info);
4712 if ((osec->flags & SEC_READONLY) == 0
4713 && htab->data_index_section != NULL)
4714 osec = htab->data_index_section;
4715 else
4716 osec = htab->text_index_section;
4717 symbol = elf_section_data (osec)->dynindx;
4719 BFD_ASSERT (symbol != 0);
4721 else
4722 /* On SVR4-ish systems, the dynamic loader cannot
4723 relocate the text and data segments independently,
4724 so the symbol does not matter. */
4725 symbol = 0;
4726 outrel.r_info = ELF32_R_INFO (symbol, R_ARM_RELATIVE);
4727 if (globals->use_rel)
4728 relocate = TRUE;
4729 else
4730 outrel.r_addend += value;
4733 loc = sreloc->contents;
4734 loc += sreloc->reloc_count++ * RELOC_SIZE (globals);
4735 SWAP_RELOC_OUT (globals) (output_bfd, &outrel, loc);
4737 /* If this reloc is against an external symbol, we do not want to
4738 fiddle with the addend. Otherwise, we need to include the symbol
4739 value so that it becomes an addend for the dynamic reloc. */
4740 if (! relocate)
4741 return bfd_reloc_ok;
4743 return _bfd_final_link_relocate (howto, input_bfd, input_section,
4744 contents, rel->r_offset, value,
4745 (bfd_vma) 0);
4747 else switch (r_type)
4749 case R_ARM_ABS12:
4750 return elf32_arm_abs12_reloc (input_bfd, hit_data, value + addend);
4752 case R_ARM_XPC25: /* Arm BLX instruction. */
4753 case R_ARM_CALL:
4754 case R_ARM_JUMP24:
4755 case R_ARM_PC24: /* Arm B/BL instruction */
4756 case R_ARM_PLT32:
4757 if (r_type == R_ARM_XPC25)
4759 /* Check for Arm calling Arm function. */
4760 /* FIXME: Should we translate the instruction into a BL
4761 instruction instead ? */
4762 if (sym_flags != STT_ARM_TFUNC)
4763 (*_bfd_error_handler)
4764 (_("\%B: Warning: Arm BLX instruction targets Arm function '%s'."),
4765 input_bfd,
4766 h ? h->root.root.string : "(local)");
4768 else if (r_type != R_ARM_CALL || !globals->use_blx)
4770 /* Check for Arm calling Thumb function. */
4771 if (sym_flags == STT_ARM_TFUNC)
4773 if (elf32_arm_to_thumb_stub (info, sym_name, input_bfd,
4774 output_bfd, input_section,
4775 hit_data, sym_sec, rel->r_offset,
4776 signed_addend, value,
4777 error_message))
4778 return bfd_reloc_ok;
4779 else
4780 return bfd_reloc_dangerous;
4784 /* The ARM ELF ABI says that this reloc is computed as: S - P + A
4785 where:
4786 S is the address of the symbol in the relocation.
4787 P is address of the instruction being relocated.
4788 A is the addend (extracted from the instruction) in bytes.
4790 S is held in 'value'.
4791 P is the base address of the section containing the
4792 instruction plus the offset of the reloc into that
4793 section, ie:
4794 (input_section->output_section->vma +
4795 input_section->output_offset +
4796 rel->r_offset).
4797 A is the addend, converted into bytes, ie:
4798 (signed_addend * 4)
4800 Note: None of these operations have knowledge of the pipeline
4801 size of the processor, thus it is up to the assembler to
4802 encode this information into the addend. */
4803 value -= (input_section->output_section->vma
4804 + input_section->output_offset);
4805 value -= rel->r_offset;
4806 if (globals->use_rel)
4807 value += (signed_addend << howto->size);
4808 else
4809 /* RELA addends do not have to be adjusted by howto->size. */
4810 value += signed_addend;
4812 signed_addend = value;
4813 signed_addend >>= howto->rightshift;
4815 /* It is not an error for an undefined weak reference to be
4816 out of range. Any program that branches to such a symbol
4817 is going to crash anyway, so there is no point worrying
4818 about getting the destination exactly right. */
4819 if (! h || h->root.type != bfd_link_hash_undefweak)
4821 /* Perform a signed range check. */
4822 if ( signed_addend > ((bfd_signed_vma) (howto->dst_mask >> 1))
4823 || signed_addend < - ((bfd_signed_vma) ((howto->dst_mask + 1) >> 1)))
4824 return bfd_reloc_overflow;
4827 addend = (value & 2);
4829 value = (signed_addend & howto->dst_mask)
4830 | (bfd_get_32 (input_bfd, hit_data) & (~ howto->dst_mask));
4832 /* Set the H bit in the BLX instruction. */
4833 if (sym_flags == STT_ARM_TFUNC)
4835 if (addend)
4836 value |= (1 << 24);
4837 else
4838 value &= ~(bfd_vma)(1 << 24);
4840 if (r_type == R_ARM_CALL)
4842 /* Select the correct instruction (BL or BLX). */
4843 if (sym_flags == STT_ARM_TFUNC)
4844 value |= (1 << 28);
4845 else
4847 value &= ~(bfd_vma)(1 << 28);
4848 value |= (1 << 24);
4851 break;
4853 case R_ARM_ABS32:
4854 value += addend;
4855 if (sym_flags == STT_ARM_TFUNC)
4856 value |= 1;
4857 break;
4859 case R_ARM_ABS32_NOI:
4860 value += addend;
4861 break;
4863 case R_ARM_REL32:
4864 value += addend;
4865 if (sym_flags == STT_ARM_TFUNC)
4866 value |= 1;
4867 value -= (input_section->output_section->vma
4868 + input_section->output_offset + rel->r_offset);
4869 break;
4871 case R_ARM_REL32_NOI:
4872 value += addend;
4873 value -= (input_section->output_section->vma
4874 + input_section->output_offset + rel->r_offset);
4875 break;
4877 case R_ARM_PREL31:
4878 value -= (input_section->output_section->vma
4879 + input_section->output_offset + rel->r_offset);
4880 value += signed_addend;
4881 if (! h || h->root.type != bfd_link_hash_undefweak)
4883 /* Check for overflow */
4884 if ((value ^ (value >> 1)) & (1 << 30))
4885 return bfd_reloc_overflow;
4887 value &= 0x7fffffff;
4888 value |= (bfd_get_32 (input_bfd, hit_data) & 0x80000000);
4889 if (sym_flags == STT_ARM_TFUNC)
4890 value |= 1;
4891 break;
4894 bfd_put_32 (input_bfd, value, hit_data);
4895 return bfd_reloc_ok;
4897 case R_ARM_ABS8:
4898 value += addend;
4899 if ((long) value > 0x7f || (long) value < -0x80)
4900 return bfd_reloc_overflow;
4902 bfd_put_8 (input_bfd, value, hit_data);
4903 return bfd_reloc_ok;
4905 case R_ARM_ABS16:
4906 value += addend;
4908 if ((long) value > 0x7fff || (long) value < -0x8000)
4909 return bfd_reloc_overflow;
4911 bfd_put_16 (input_bfd, value, hit_data);
4912 return bfd_reloc_ok;
4914 case R_ARM_THM_ABS5:
4915 /* Support ldr and str instructions for the thumb. */
4916 if (globals->use_rel)
4918 /* Need to refetch addend. */
4919 addend = bfd_get_16 (input_bfd, hit_data) & howto->src_mask;
4920 /* ??? Need to determine shift amount from operand size. */
4921 addend >>= howto->rightshift;
4923 value += addend;
4925 /* ??? Isn't value unsigned? */
4926 if ((long) value > 0x1f || (long) value < -0x10)
4927 return bfd_reloc_overflow;
4929 /* ??? Value needs to be properly shifted into place first. */
4930 value |= bfd_get_16 (input_bfd, hit_data) & 0xf83f;
4931 bfd_put_16 (input_bfd, value, hit_data);
4932 return bfd_reloc_ok;
4934 case R_ARM_THM_ALU_PREL_11_0:
4935 /* Corresponds to: addw.w reg, pc, #offset (and similarly for subw). */
4937 bfd_vma insn;
4938 bfd_signed_vma relocation;
4940 insn = (bfd_get_16 (input_bfd, hit_data) << 16)
4941 | bfd_get_16 (input_bfd, hit_data + 2);
4943 if (globals->use_rel)
4945 signed_addend = (insn & 0xff) | ((insn & 0x7000) >> 4)
4946 | ((insn & (1 << 26)) >> 15);
4947 if (insn & 0xf00000)
4948 signed_addend = -signed_addend;
4951 relocation = value + signed_addend;
4952 relocation -= (input_section->output_section->vma
4953 + input_section->output_offset
4954 + rel->r_offset);
4956 value = abs (relocation);
4958 if (value >= 0x1000)
4959 return bfd_reloc_overflow;
4961 insn = (insn & 0xfb0f8f00) | (value & 0xff)
4962 | ((value & 0x700) << 4)
4963 | ((value & 0x800) << 15);
4964 if (relocation < 0)
4965 insn |= 0xa00000;
4967 bfd_put_16 (input_bfd, insn >> 16, hit_data);
4968 bfd_put_16 (input_bfd, insn & 0xffff, hit_data + 2);
4970 return bfd_reloc_ok;
4973 case R_ARM_THM_PC12:
4974 /* Corresponds to: ldr.w reg, [pc, #offset]. */
4976 bfd_vma insn;
4977 bfd_signed_vma relocation;
4979 insn = (bfd_get_16 (input_bfd, hit_data) << 16)
4980 | bfd_get_16 (input_bfd, hit_data + 2);
4982 if (globals->use_rel)
4984 signed_addend = insn & 0xfff;
4985 if (!(insn & (1 << 23)))
4986 signed_addend = -signed_addend;
4989 relocation = value + signed_addend;
4990 relocation -= (input_section->output_section->vma
4991 + input_section->output_offset
4992 + rel->r_offset);
4994 value = abs (relocation);
4996 if (value >= 0x1000)
4997 return bfd_reloc_overflow;
4999 insn = (insn & 0xff7ff000) | value;
5000 if (relocation >= 0)
5001 insn |= (1 << 23);
5003 bfd_put_16 (input_bfd, insn >> 16, hit_data);
5004 bfd_put_16 (input_bfd, insn & 0xffff, hit_data + 2);
5006 return bfd_reloc_ok;
5009 case R_ARM_THM_XPC22:
5010 case R_ARM_THM_CALL:
5011 /* Thumb BL (branch long instruction). */
5013 bfd_vma relocation;
5014 bfd_vma reloc_sign;
5015 bfd_boolean overflow = FALSE;
5016 bfd_vma upper_insn = bfd_get_16 (input_bfd, hit_data);
5017 bfd_vma lower_insn = bfd_get_16 (input_bfd, hit_data + 2);
5018 bfd_signed_vma reloc_signed_max;
5019 bfd_signed_vma reloc_signed_min;
5020 bfd_vma check;
5021 bfd_signed_vma signed_check;
5022 int bitsize;
5023 int thumb2 = using_thumb2 (globals);
5025 /* Fetch the addend. We use the Thumb-2 encoding (backwards compatible
5026 with Thumb-1) involving the J1 and J2 bits. */
5027 if (globals->use_rel)
5029 bfd_vma s = (upper_insn & (1 << 10)) >> 10;
5030 bfd_vma upper = upper_insn & 0x3ff;
5031 bfd_vma lower = lower_insn & 0x7ff;
5032 bfd_vma j1 = (lower_insn & (1 << 13)) >> 13;
5033 bfd_vma j2 = (lower_insn & (1 << 11)) >> 11;
5034 bfd_vma i1 = j1 ^ s ? 0 : 1;
5035 bfd_vma i2 = j2 ^ s ? 0 : 1;
5037 addend = (i1 << 23) | (i2 << 22) | (upper << 12) | (lower << 1);
5038 /* Sign extend. */
5039 addend = (addend | ((s ? 0 : 1) << 24)) - (1 << 24);
5041 signed_addend = addend;
5044 if (r_type == R_ARM_THM_XPC22)
5046 /* Check for Thumb to Thumb call. */
5047 /* FIXME: Should we translate the instruction into a BL
5048 instruction instead ? */
5049 if (sym_flags == STT_ARM_TFUNC)
5050 (*_bfd_error_handler)
5051 (_("%B: Warning: Thumb BLX instruction targets thumb function '%s'."),
5052 input_bfd,
5053 h ? h->root.root.string : "(local)");
5055 else
5057 /* If it is not a call to Thumb, assume call to Arm.
5058 If it is a call relative to a section name, then it is not a
5059 function call at all, but rather a long jump. Calls through
5060 the PLT do not require stubs. */
5061 if (sym_flags != STT_ARM_TFUNC && sym_flags != STT_SECTION
5062 && (h == NULL || splt == NULL
5063 || h->plt.offset == (bfd_vma) -1))
5065 if (globals->use_blx)
5067 /* Convert BL to BLX. */
5068 lower_insn = (lower_insn & ~0x1000) | 0x0800;
5070 else if (elf32_thumb_to_arm_stub
5071 (info, sym_name, input_bfd, output_bfd, input_section,
5072 hit_data, sym_sec, rel->r_offset, signed_addend, value,
5073 error_message))
5074 return bfd_reloc_ok;
5075 else
5076 return bfd_reloc_dangerous;
5078 else if (sym_flags == STT_ARM_TFUNC && globals->use_blx)
5080 /* Make sure this is a BL. */
5081 lower_insn |= 0x1800;
5085 /* Handle calls via the PLT. */
5086 if (h != NULL && splt != NULL && h->plt.offset != (bfd_vma) -1)
5088 value = (splt->output_section->vma
5089 + splt->output_offset
5090 + h->plt.offset);
5091 if (globals->use_blx)
5093 /* If the Thumb BLX instruction is available, convert the
5094 BL to a BLX instruction to call the ARM-mode PLT entry. */
5095 lower_insn = (lower_insn & ~0x1000) | 0x0800;
5097 else
5098 /* Target the Thumb stub before the ARM PLT entry. */
5099 value -= PLT_THUMB_STUB_SIZE;
5100 *unresolved_reloc_p = FALSE;
5103 relocation = value + signed_addend;
5105 relocation -= (input_section->output_section->vma
5106 + input_section->output_offset
5107 + rel->r_offset);
5109 check = relocation >> howto->rightshift;
5111 /* If this is a signed value, the rightshift just dropped
5112 leading 1 bits (assuming twos complement). */
5113 if ((bfd_signed_vma) relocation >= 0)
5114 signed_check = check;
5115 else
5116 signed_check = check | ~((bfd_vma) -1 >> howto->rightshift);
5118 /* Calculate the permissable maximum and minimum values for
5119 this relocation according to whether we're relocating for
5120 Thumb-2 or not. */
5121 bitsize = howto->bitsize;
5122 if (!thumb2)
5123 bitsize -= 2;
5124 reloc_signed_max = ((1 << (bitsize - 1)) - 1) >> howto->rightshift;
5125 reloc_signed_min = ~reloc_signed_max;
5127 /* Assumes two's complement. */
5128 if (signed_check > reloc_signed_max || signed_check < reloc_signed_min)
5129 overflow = TRUE;
5131 if ((lower_insn & 0x1800) == 0x0800)
5132 /* For a BLX instruction, make sure that the relocation is rounded up
5133 to a word boundary. This follows the semantics of the instruction
5134 which specifies that bit 1 of the target address will come from bit
5135 1 of the base address. */
5136 relocation = (relocation + 2) & ~ 3;
5138 /* Put RELOCATION back into the insn. Assumes two's complement.
5139 We use the Thumb-2 encoding, which is safe even if dealing with
5140 a Thumb-1 instruction by virtue of our overflow check above. */
5141 reloc_sign = (signed_check < 0) ? 1 : 0;
5142 upper_insn = (upper_insn & ~(bfd_vma) 0x7ff)
5143 | ((relocation >> 12) & 0x3ff)
5144 | (reloc_sign << 10);
5145 lower_insn = (lower_insn & ~(bfd_vma) 0x2fff)
5146 | (((!((relocation >> 23) & 1)) ^ reloc_sign) << 13)
5147 | (((!((relocation >> 22) & 1)) ^ reloc_sign) << 11)
5148 | ((relocation >> 1) & 0x7ff);
5150 /* Put the relocated value back in the object file: */
5151 bfd_put_16 (input_bfd, upper_insn, hit_data);
5152 bfd_put_16 (input_bfd, lower_insn, hit_data + 2);
5154 return (overflow ? bfd_reloc_overflow : bfd_reloc_ok);
5156 break;
5158 case R_ARM_THM_JUMP24:
5159 /* Thumb32 unconditional branch instruction. */
5161 bfd_vma relocation;
5162 bfd_boolean overflow = FALSE;
5163 bfd_vma upper_insn = bfd_get_16 (input_bfd, hit_data);
5164 bfd_vma lower_insn = bfd_get_16 (input_bfd, hit_data + 2);
5165 bfd_signed_vma reloc_signed_max = ((1 << (howto->bitsize - 1)) - 1) >> howto->rightshift;
5166 bfd_signed_vma reloc_signed_min = ~ reloc_signed_max;
5167 bfd_vma check;
5168 bfd_signed_vma signed_check;
5170 /* Need to refetch the addend, reconstruct the top three bits, and glue the
5171 two pieces together. */
5172 if (globals->use_rel)
5174 bfd_vma S = (upper_insn & 0x0400) >> 10;
5175 bfd_vma hi = (upper_insn & 0x03ff);
5176 bfd_vma I1 = (lower_insn & 0x2000) >> 13;
5177 bfd_vma I2 = (lower_insn & 0x0800) >> 11;
5178 bfd_vma lo = (lower_insn & 0x07ff);
5180 I1 = !(I1 ^ S);
5181 I2 = !(I2 ^ S);
5182 S = !S;
5184 signed_addend = (S << 24) | (I1 << 23) | (I2 << 22) | (hi << 12) | (lo << 1);
5185 signed_addend -= (1 << 24); /* Sign extend. */
5188 /* ??? Should handle interworking? GCC might someday try to
5189 use this for tail calls. */
5191 relocation = value + signed_addend;
5192 relocation -= (input_section->output_section->vma
5193 + input_section->output_offset
5194 + rel->r_offset);
5196 check = relocation >> howto->rightshift;
5198 /* If this is a signed value, the rightshift just dropped
5199 leading 1 bits (assuming twos complement). */
5200 if ((bfd_signed_vma) relocation >= 0)
5201 signed_check = check;
5202 else
5203 signed_check = check | ~((bfd_vma) -1 >> howto->rightshift);
5205 /* Assumes two's complement. */
5206 if (signed_check > reloc_signed_max || signed_check < reloc_signed_min)
5207 overflow = TRUE;
5209 /* Put RELOCATION back into the insn. */
5211 bfd_vma S = (relocation & 0x01000000) >> 24;
5212 bfd_vma I1 = (relocation & 0x00800000) >> 23;
5213 bfd_vma I2 = (relocation & 0x00400000) >> 22;
5214 bfd_vma hi = (relocation & 0x003ff000) >> 12;
5215 bfd_vma lo = (relocation & 0x00000ffe) >> 1;
5217 I1 = !(I1 ^ S);
5218 I2 = !(I2 ^ S);
5220 upper_insn = (upper_insn & (bfd_vma) 0xf800) | (S << 10) | hi;
5221 lower_insn = (lower_insn & (bfd_vma) 0xd000) | (I1 << 13) | (I2 << 11) | lo;
5224 /* Put the relocated value back in the object file: */
5225 bfd_put_16 (input_bfd, upper_insn, hit_data);
5226 bfd_put_16 (input_bfd, lower_insn, hit_data + 2);
5228 return (overflow ? bfd_reloc_overflow : bfd_reloc_ok);
5231 case R_ARM_THM_JUMP19:
5232 /* Thumb32 conditional branch instruction. */
5234 bfd_vma relocation;
5235 bfd_boolean overflow = FALSE;
5236 bfd_vma upper_insn = bfd_get_16 (input_bfd, hit_data);
5237 bfd_vma lower_insn = bfd_get_16 (input_bfd, hit_data + 2);
5238 bfd_signed_vma reloc_signed_max = 0xffffe;
5239 bfd_signed_vma reloc_signed_min = -0x100000;
5240 bfd_signed_vma signed_check;
5242 /* Need to refetch the addend, reconstruct the top three bits,
5243 and squish the two 11 bit pieces together. */
5244 if (globals->use_rel)
5246 bfd_vma S = (upper_insn & 0x0400) >> 10;
5247 bfd_vma upper = (upper_insn & 0x003f);
5248 bfd_vma J1 = (lower_insn & 0x2000) >> 13;
5249 bfd_vma J2 = (lower_insn & 0x0800) >> 11;
5250 bfd_vma lower = (lower_insn & 0x07ff);
5252 upper |= J1 << 6;
5253 upper |= J2 << 7;
5254 upper |= (!S) << 8;
5255 upper -= 0x0100; /* Sign extend. */
5257 addend = (upper << 12) | (lower << 1);
5258 signed_addend = addend;
5261 /* ??? Should handle interworking? GCC might someday try to
5262 use this for tail calls. */
5264 relocation = value + signed_addend;
5265 relocation -= (input_section->output_section->vma
5266 + input_section->output_offset
5267 + rel->r_offset);
5268 signed_check = (bfd_signed_vma) relocation;
5270 if (signed_check > reloc_signed_max || signed_check < reloc_signed_min)
5271 overflow = TRUE;
5273 /* Put RELOCATION back into the insn. */
5275 bfd_vma S = (relocation & 0x00100000) >> 20;
5276 bfd_vma J2 = (relocation & 0x00080000) >> 19;
5277 bfd_vma J1 = (relocation & 0x00040000) >> 18;
5278 bfd_vma hi = (relocation & 0x0003f000) >> 12;
5279 bfd_vma lo = (relocation & 0x00000ffe) >> 1;
5281 upper_insn = (upper_insn & 0xfbc0) | (S << 10) | hi;
5282 lower_insn = (lower_insn & 0xd000) | (J1 << 13) | (J2 << 11) | lo;
5285 /* Put the relocated value back in the object file: */
5286 bfd_put_16 (input_bfd, upper_insn, hit_data);
5287 bfd_put_16 (input_bfd, lower_insn, hit_data + 2);
5289 return (overflow ? bfd_reloc_overflow : bfd_reloc_ok);
5292 case R_ARM_THM_JUMP11:
5293 case R_ARM_THM_JUMP8:
5294 case R_ARM_THM_JUMP6:
5295 /* Thumb B (branch) instruction). */
5297 bfd_signed_vma relocation;
5298 bfd_signed_vma reloc_signed_max = (1 << (howto->bitsize - 1)) - 1;
5299 bfd_signed_vma reloc_signed_min = ~ reloc_signed_max;
5300 bfd_signed_vma signed_check;
5302 /* CZB cannot jump backward. */
5303 if (r_type == R_ARM_THM_JUMP6)
5304 reloc_signed_min = 0;
5306 if (globals->use_rel)
5308 /* Need to refetch addend. */
5309 addend = bfd_get_16 (input_bfd, hit_data) & howto->src_mask;
5310 if (addend & ((howto->src_mask + 1) >> 1))
5312 signed_addend = -1;
5313 signed_addend &= ~ howto->src_mask;
5314 signed_addend |= addend;
5316 else
5317 signed_addend = addend;
5318 /* The value in the insn has been right shifted. We need to
5319 undo this, so that we can perform the address calculation
5320 in terms of bytes. */
5321 signed_addend <<= howto->rightshift;
5323 relocation = value + signed_addend;
5325 relocation -= (input_section->output_section->vma
5326 + input_section->output_offset
5327 + rel->r_offset);
5329 relocation >>= howto->rightshift;
5330 signed_check = relocation;
5332 if (r_type == R_ARM_THM_JUMP6)
5333 relocation = ((relocation & 0x0020) << 4) | ((relocation & 0x001f) << 3);
5334 else
5335 relocation &= howto->dst_mask;
5336 relocation |= (bfd_get_16 (input_bfd, hit_data) & (~ howto->dst_mask));
5338 bfd_put_16 (input_bfd, relocation, hit_data);
5340 /* Assumes two's complement. */
5341 if (signed_check > reloc_signed_max || signed_check < reloc_signed_min)
5342 return bfd_reloc_overflow;
5344 return bfd_reloc_ok;
5347 case R_ARM_ALU_PCREL7_0:
5348 case R_ARM_ALU_PCREL15_8:
5349 case R_ARM_ALU_PCREL23_15:
5351 bfd_vma insn;
5352 bfd_vma relocation;
5354 insn = bfd_get_32 (input_bfd, hit_data);
5355 if (globals->use_rel)
5357 /* Extract the addend. */
5358 addend = (insn & 0xff) << ((insn & 0xf00) >> 7);
5359 signed_addend = addend;
5361 relocation = value + signed_addend;
5363 relocation -= (input_section->output_section->vma
5364 + input_section->output_offset
5365 + rel->r_offset);
5366 insn = (insn & ~0xfff)
5367 | ((howto->bitpos << 7) & 0xf00)
5368 | ((relocation >> howto->bitpos) & 0xff);
5369 bfd_put_32 (input_bfd, value, hit_data);
5371 return bfd_reloc_ok;
5373 case R_ARM_GNU_VTINHERIT:
5374 case R_ARM_GNU_VTENTRY:
5375 return bfd_reloc_ok;
5377 case R_ARM_GOTOFF32:
5378 /* Relocation is relative to the start of the
5379 global offset table. */
5381 BFD_ASSERT (sgot != NULL);
5382 if (sgot == NULL)
5383 return bfd_reloc_notsupported;
5385 /* If we are addressing a Thumb function, we need to adjust the
5386 address by one, so that attempts to call the function pointer will
5387 correctly interpret it as Thumb code. */
5388 if (sym_flags == STT_ARM_TFUNC)
5389 value += 1;
5391 /* Note that sgot->output_offset is not involved in this
5392 calculation. We always want the start of .got. If we
5393 define _GLOBAL_OFFSET_TABLE in a different way, as is
5394 permitted by the ABI, we might have to change this
5395 calculation. */
5396 value -= sgot->output_section->vma;
5397 return _bfd_final_link_relocate (howto, input_bfd, input_section,
5398 contents, rel->r_offset, value,
5399 rel->r_addend);
5401 case R_ARM_GOTPC:
5402 /* Use global offset table as symbol value. */
5403 BFD_ASSERT (sgot != NULL);
5405 if (sgot == NULL)
5406 return bfd_reloc_notsupported;
5408 *unresolved_reloc_p = FALSE;
5409 value = sgot->output_section->vma;
5410 return _bfd_final_link_relocate (howto, input_bfd, input_section,
5411 contents, rel->r_offset, value,
5412 rel->r_addend);
5414 case R_ARM_GOT32:
5415 case R_ARM_GOT_PREL:
5416 /* Relocation is to the entry for this symbol in the
5417 global offset table. */
5418 if (sgot == NULL)
5419 return bfd_reloc_notsupported;
5421 if (h != NULL)
5423 bfd_vma off;
5424 bfd_boolean dyn;
5426 off = h->got.offset;
5427 BFD_ASSERT (off != (bfd_vma) -1);
5428 dyn = globals->root.dynamic_sections_created;
5430 if (! WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn, info->shared, h)
5431 || (info->shared
5432 && SYMBOL_REFERENCES_LOCAL (info, h))
5433 || (ELF_ST_VISIBILITY (h->other)
5434 && h->root.type == bfd_link_hash_undefweak))
5436 /* This is actually a static link, or it is a -Bsymbolic link
5437 and the symbol is defined locally. We must initialize this
5438 entry in the global offset table. Since the offset must
5439 always be a multiple of 4, we use the least significant bit
5440 to record whether we have initialized it already.
5442 When doing a dynamic link, we create a .rel(a).got relocation
5443 entry to initialize the value. This is done in the
5444 finish_dynamic_symbol routine. */
5445 if ((off & 1) != 0)
5446 off &= ~1;
5447 else
5449 /* If we are addressing a Thumb function, we need to
5450 adjust the address by one, so that attempts to
5451 call the function pointer will correctly
5452 interpret it as Thumb code. */
5453 if (sym_flags == STT_ARM_TFUNC)
5454 value |= 1;
5456 bfd_put_32 (output_bfd, value, sgot->contents + off);
5457 h->got.offset |= 1;
5460 else
5461 *unresolved_reloc_p = FALSE;
5463 value = sgot->output_offset + off;
5465 else
5467 bfd_vma off;
5469 BFD_ASSERT (local_got_offsets != NULL &&
5470 local_got_offsets[r_symndx] != (bfd_vma) -1);
5472 off = local_got_offsets[r_symndx];
5474 /* The offset must always be a multiple of 4. We use the
5475 least significant bit to record whether we have already
5476 generated the necessary reloc. */
5477 if ((off & 1) != 0)
5478 off &= ~1;
5479 else
5481 /* If we are addressing a Thumb function, we need to
5482 adjust the address by one, so that attempts to
5483 call the function pointer will correctly
5484 interpret it as Thumb code. */
5485 if (sym_flags == STT_ARM_TFUNC)
5486 value |= 1;
5488 if (globals->use_rel)
5489 bfd_put_32 (output_bfd, value, sgot->contents + off);
5491 if (info->shared)
5493 asection * srelgot;
5494 Elf_Internal_Rela outrel;
5495 bfd_byte *loc;
5497 srelgot = (bfd_get_section_by_name
5498 (dynobj, RELOC_SECTION (globals, ".got")));
5499 BFD_ASSERT (srelgot != NULL);
5501 outrel.r_addend = addend + value;
5502 outrel.r_offset = (sgot->output_section->vma
5503 + sgot->output_offset
5504 + off);
5505 outrel.r_info = ELF32_R_INFO (0, R_ARM_RELATIVE);
5506 loc = srelgot->contents;
5507 loc += srelgot->reloc_count++ * RELOC_SIZE (globals);
5508 SWAP_RELOC_OUT (globals) (output_bfd, &outrel, loc);
5511 local_got_offsets[r_symndx] |= 1;
5514 value = sgot->output_offset + off;
5516 if (r_type != R_ARM_GOT32)
5517 value += sgot->output_section->vma;
5519 return _bfd_final_link_relocate (howto, input_bfd, input_section,
5520 contents, rel->r_offset, value,
5521 rel->r_addend);
5523 case R_ARM_TLS_LDO32:
5524 value = value - dtpoff_base (info);
5526 return _bfd_final_link_relocate (howto, input_bfd, input_section,
5527 contents, rel->r_offset, value,
5528 rel->r_addend);
5530 case R_ARM_TLS_LDM32:
5532 bfd_vma off;
5534 if (globals->sgot == NULL)
5535 abort ();
5537 off = globals->tls_ldm_got.offset;
5539 if ((off & 1) != 0)
5540 off &= ~1;
5541 else
5543 /* If we don't know the module number, create a relocation
5544 for it. */
5545 if (info->shared)
5547 Elf_Internal_Rela outrel;
5548 bfd_byte *loc;
5550 if (globals->srelgot == NULL)
5551 abort ();
5553 outrel.r_addend = 0;
5554 outrel.r_offset = (globals->sgot->output_section->vma
5555 + globals->sgot->output_offset + off);
5556 outrel.r_info = ELF32_R_INFO (0, R_ARM_TLS_DTPMOD32);
5558 if (globals->use_rel)
5559 bfd_put_32 (output_bfd, outrel.r_addend,
5560 globals->sgot->contents + off);
5562 loc = globals->srelgot->contents;
5563 loc += globals->srelgot->reloc_count++ * RELOC_SIZE (globals);
5564 SWAP_RELOC_OUT (globals) (output_bfd, &outrel, loc);
5566 else
5567 bfd_put_32 (output_bfd, 1, globals->sgot->contents + off);
5569 globals->tls_ldm_got.offset |= 1;
5572 value = globals->sgot->output_section->vma + globals->sgot->output_offset + off
5573 - (input_section->output_section->vma + input_section->output_offset + rel->r_offset);
5575 return _bfd_final_link_relocate (howto, input_bfd, input_section,
5576 contents, rel->r_offset, value,
5577 rel->r_addend);
5580 case R_ARM_TLS_GD32:
5581 case R_ARM_TLS_IE32:
5583 bfd_vma off;
5584 int indx;
5585 char tls_type;
5587 if (globals->sgot == NULL)
5588 abort ();
5590 indx = 0;
5591 if (h != NULL)
5593 bfd_boolean dyn;
5594 dyn = globals->root.dynamic_sections_created;
5595 if (WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn, info->shared, h)
5596 && (!info->shared
5597 || !SYMBOL_REFERENCES_LOCAL (info, h)))
5599 *unresolved_reloc_p = FALSE;
5600 indx = h->dynindx;
5602 off = h->got.offset;
5603 tls_type = ((struct elf32_arm_link_hash_entry *) h)->tls_type;
5605 else
5607 if (local_got_offsets == NULL)
5608 abort ();
5609 off = local_got_offsets[r_symndx];
5610 tls_type = elf32_arm_local_got_tls_type (input_bfd)[r_symndx];
5613 if (tls_type == GOT_UNKNOWN)
5614 abort ();
5616 if ((off & 1) != 0)
5617 off &= ~1;
5618 else
5620 bfd_boolean need_relocs = FALSE;
5621 Elf_Internal_Rela outrel;
5622 bfd_byte *loc = NULL;
5623 int cur_off = off;
5625 /* The GOT entries have not been initialized yet. Do it
5626 now, and emit any relocations. If both an IE GOT and a
5627 GD GOT are necessary, we emit the GD first. */
5629 if ((info->shared || indx != 0)
5630 && (h == NULL
5631 || ELF_ST_VISIBILITY (h->other) == STV_DEFAULT
5632 || h->root.type != bfd_link_hash_undefweak))
5634 need_relocs = TRUE;
5635 if (globals->srelgot == NULL)
5636 abort ();
5637 loc = globals->srelgot->contents;
5638 loc += globals->srelgot->reloc_count * RELOC_SIZE (globals);
5641 if (tls_type & GOT_TLS_GD)
5643 if (need_relocs)
5645 outrel.r_addend = 0;
5646 outrel.r_offset = (globals->sgot->output_section->vma
5647 + globals->sgot->output_offset
5648 + cur_off);
5649 outrel.r_info = ELF32_R_INFO (indx, R_ARM_TLS_DTPMOD32);
5651 if (globals->use_rel)
5652 bfd_put_32 (output_bfd, outrel.r_addend,
5653 globals->sgot->contents + cur_off);
5655 SWAP_RELOC_OUT (globals) (output_bfd, &outrel, loc);
5656 globals->srelgot->reloc_count++;
5657 loc += RELOC_SIZE (globals);
5659 if (indx == 0)
5660 bfd_put_32 (output_bfd, value - dtpoff_base (info),
5661 globals->sgot->contents + cur_off + 4);
5662 else
5664 outrel.r_addend = 0;
5665 outrel.r_info = ELF32_R_INFO (indx,
5666 R_ARM_TLS_DTPOFF32);
5667 outrel.r_offset += 4;
5669 if (globals->use_rel)
5670 bfd_put_32 (output_bfd, outrel.r_addend,
5671 globals->sgot->contents + cur_off + 4);
5674 SWAP_RELOC_OUT (globals) (output_bfd, &outrel, loc);
5675 globals->srelgot->reloc_count++;
5676 loc += RELOC_SIZE (globals);
5679 else
5681 /* If we are not emitting relocations for a
5682 general dynamic reference, then we must be in a
5683 static link or an executable link with the
5684 symbol binding locally. Mark it as belonging
5685 to module 1, the executable. */
5686 bfd_put_32 (output_bfd, 1,
5687 globals->sgot->contents + cur_off);
5688 bfd_put_32 (output_bfd, value - dtpoff_base (info),
5689 globals->sgot->contents + cur_off + 4);
5692 cur_off += 8;
5695 if (tls_type & GOT_TLS_IE)
5697 if (need_relocs)
5699 if (indx == 0)
5700 outrel.r_addend = value - dtpoff_base (info);
5701 else
5702 outrel.r_addend = 0;
5703 outrel.r_offset = (globals->sgot->output_section->vma
5704 + globals->sgot->output_offset
5705 + cur_off);
5706 outrel.r_info = ELF32_R_INFO (indx, R_ARM_TLS_TPOFF32);
5708 if (globals->use_rel)
5709 bfd_put_32 (output_bfd, outrel.r_addend,
5710 globals->sgot->contents + cur_off);
5712 SWAP_RELOC_OUT (globals) (output_bfd, &outrel, loc);
5713 globals->srelgot->reloc_count++;
5714 loc += RELOC_SIZE (globals);
5716 else
5717 bfd_put_32 (output_bfd, tpoff (info, value),
5718 globals->sgot->contents + cur_off);
5719 cur_off += 4;
5722 if (h != NULL)
5723 h->got.offset |= 1;
5724 else
5725 local_got_offsets[r_symndx] |= 1;
5728 if ((tls_type & GOT_TLS_GD) && r_type != R_ARM_TLS_GD32)
5729 off += 8;
5730 value = globals->sgot->output_section->vma + globals->sgot->output_offset + off
5731 - (input_section->output_section->vma + input_section->output_offset + rel->r_offset);
5733 return _bfd_final_link_relocate (howto, input_bfd, input_section,
5734 contents, rel->r_offset, value,
5735 rel->r_addend);
5738 case R_ARM_TLS_LE32:
5739 if (info->shared)
5741 (*_bfd_error_handler)
5742 (_("%B(%A+0x%lx): R_ARM_TLS_LE32 relocation not permitted in shared object"),
5743 input_bfd, input_section,
5744 (long) rel->r_offset, howto->name);
5745 return FALSE;
5747 else
5748 value = tpoff (info, value);
5750 return _bfd_final_link_relocate (howto, input_bfd, input_section,
5751 contents, rel->r_offset, value,
5752 rel->r_addend);
5754 case R_ARM_V4BX:
5755 if (globals->fix_v4bx)
5757 bfd_vma insn = bfd_get_32 (input_bfd, hit_data);
5759 /* Ensure that we have a BX instruction. */
5760 BFD_ASSERT ((insn & 0x0ffffff0) == 0x012fff10);
5762 /* Preserve Rm (lowest four bits) and the condition code
5763 (highest four bits). Other bits encode MOV PC,Rm. */
5764 insn = (insn & 0xf000000f) | 0x01a0f000;
5766 bfd_put_32 (input_bfd, insn, hit_data);
5768 return bfd_reloc_ok;
5770 case R_ARM_MOVW_ABS_NC:
5771 case R_ARM_MOVT_ABS:
5772 case R_ARM_MOVW_PREL_NC:
5773 case R_ARM_MOVT_PREL:
5774 /* Until we properly support segment-base-relative addressing then
5775 we assume the segment base to be zero, as for the group relocations.
5776 Thus R_ARM_MOVW_BREL_NC has the same semantics as R_ARM_MOVW_ABS_NC
5777 and R_ARM_MOVT_BREL has the same semantics as R_ARM_MOVT_ABS. */
5778 case R_ARM_MOVW_BREL_NC:
5779 case R_ARM_MOVW_BREL:
5780 case R_ARM_MOVT_BREL:
5782 bfd_vma insn = bfd_get_32 (input_bfd, hit_data);
5784 if (globals->use_rel)
5786 addend = ((insn >> 4) & 0xf000) | (insn & 0xfff);
5787 signed_addend = (addend ^ 0x10000) - 0x10000;
5790 value += signed_addend;
5792 if (r_type == R_ARM_MOVW_PREL_NC || r_type == R_ARM_MOVT_PREL)
5793 value -= (input_section->output_section->vma
5794 + input_section->output_offset + rel->r_offset);
5796 if (r_type == R_ARM_MOVW_BREL && value >= 0x10000)
5797 return bfd_reloc_overflow;
5799 if (sym_flags == STT_ARM_TFUNC)
5800 value |= 1;
5802 if (r_type == R_ARM_MOVT_ABS || r_type == R_ARM_MOVT_PREL
5803 || r_type == R_ARM_MOVT_BREL)
5804 value >>= 16;
5806 insn &= 0xfff0f000;
5807 insn |= value & 0xfff;
5808 insn |= (value & 0xf000) << 4;
5809 bfd_put_32 (input_bfd, insn, hit_data);
5811 return bfd_reloc_ok;
5813 case R_ARM_THM_MOVW_ABS_NC:
5814 case R_ARM_THM_MOVT_ABS:
5815 case R_ARM_THM_MOVW_PREL_NC:
5816 case R_ARM_THM_MOVT_PREL:
5817 /* Until we properly support segment-base-relative addressing then
5818 we assume the segment base to be zero, as for the above relocations.
5819 Thus R_ARM_THM_MOVW_BREL_NC has the same semantics as
5820 R_ARM_THM_MOVW_ABS_NC and R_ARM_THM_MOVT_BREL has the same semantics
5821 as R_ARM_THM_MOVT_ABS. */
5822 case R_ARM_THM_MOVW_BREL_NC:
5823 case R_ARM_THM_MOVW_BREL:
5824 case R_ARM_THM_MOVT_BREL:
5826 bfd_vma insn;
5828 insn = bfd_get_16 (input_bfd, hit_data) << 16;
5829 insn |= bfd_get_16 (input_bfd, hit_data + 2);
5831 if (globals->use_rel)
5833 addend = ((insn >> 4) & 0xf000)
5834 | ((insn >> 15) & 0x0800)
5835 | ((insn >> 4) & 0x0700)
5836 | (insn & 0x00ff);
5837 signed_addend = (addend ^ 0x10000) - 0x10000;
5840 value += signed_addend;
5842 if (r_type == R_ARM_THM_MOVW_PREL_NC || r_type == R_ARM_THM_MOVT_PREL)
5843 value -= (input_section->output_section->vma
5844 + input_section->output_offset + rel->r_offset);
5846 if (r_type == R_ARM_THM_MOVW_BREL && value >= 0x10000)
5847 return bfd_reloc_overflow;
5849 if (sym_flags == STT_ARM_TFUNC)
5850 value |= 1;
5852 if (r_type == R_ARM_THM_MOVT_ABS || r_type == R_ARM_THM_MOVT_PREL
5853 || r_type == R_ARM_THM_MOVT_BREL)
5854 value >>= 16;
5856 insn &= 0xfbf08f00;
5857 insn |= (value & 0xf000) << 4;
5858 insn |= (value & 0x0800) << 15;
5859 insn |= (value & 0x0700) << 4;
5860 insn |= (value & 0x00ff);
5862 bfd_put_16 (input_bfd, insn >> 16, hit_data);
5863 bfd_put_16 (input_bfd, insn & 0xffff, hit_data + 2);
5865 return bfd_reloc_ok;
5867 case R_ARM_ALU_PC_G0_NC:
5868 case R_ARM_ALU_PC_G1_NC:
5869 case R_ARM_ALU_PC_G0:
5870 case R_ARM_ALU_PC_G1:
5871 case R_ARM_ALU_PC_G2:
5872 case R_ARM_ALU_SB_G0_NC:
5873 case R_ARM_ALU_SB_G1_NC:
5874 case R_ARM_ALU_SB_G0:
5875 case R_ARM_ALU_SB_G1:
5876 case R_ARM_ALU_SB_G2:
5878 bfd_vma insn = bfd_get_32 (input_bfd, hit_data);
5879 bfd_vma pc = input_section->output_section->vma
5880 + input_section->output_offset + rel->r_offset;
5881 /* sb should be the origin of the *segment* containing the symbol.
5882 It is not clear how to obtain this OS-dependent value, so we
5883 make an arbitrary choice of zero. */
5884 bfd_vma sb = 0;
5885 bfd_vma residual;
5886 bfd_vma g_n;
5887 bfd_signed_vma signed_value;
5888 int group = 0;
5890 /* Determine which group of bits to select. */
5891 switch (r_type)
5893 case R_ARM_ALU_PC_G0_NC:
5894 case R_ARM_ALU_PC_G0:
5895 case R_ARM_ALU_SB_G0_NC:
5896 case R_ARM_ALU_SB_G0:
5897 group = 0;
5898 break;
5900 case R_ARM_ALU_PC_G1_NC:
5901 case R_ARM_ALU_PC_G1:
5902 case R_ARM_ALU_SB_G1_NC:
5903 case R_ARM_ALU_SB_G1:
5904 group = 1;
5905 break;
5907 case R_ARM_ALU_PC_G2:
5908 case R_ARM_ALU_SB_G2:
5909 group = 2;
5910 break;
5912 default:
5913 abort();
5916 /* If REL, extract the addend from the insn. If RELA, it will
5917 have already been fetched for us. */
5918 if (globals->use_rel)
5920 int negative;
5921 bfd_vma constant = insn & 0xff;
5922 bfd_vma rotation = (insn & 0xf00) >> 8;
5924 if (rotation == 0)
5925 signed_addend = constant;
5926 else
5928 /* Compensate for the fact that in the instruction, the
5929 rotation is stored in multiples of 2 bits. */
5930 rotation *= 2;
5932 /* Rotate "constant" right by "rotation" bits. */
5933 signed_addend = (constant >> rotation) |
5934 (constant << (8 * sizeof (bfd_vma) - rotation));
5937 /* Determine if the instruction is an ADD or a SUB.
5938 (For REL, this determines the sign of the addend.) */
5939 negative = identify_add_or_sub (insn);
5940 if (negative == 0)
5942 (*_bfd_error_handler)
5943 (_("%B(%A+0x%lx): Only ADD or SUB instructions are allowed for ALU group relocations"),
5944 input_bfd, input_section,
5945 (long) rel->r_offset, howto->name);
5946 return bfd_reloc_overflow;
5949 signed_addend *= negative;
5952 /* Compute the value (X) to go in the place. */
5953 if (r_type == R_ARM_ALU_PC_G0_NC
5954 || r_type == R_ARM_ALU_PC_G1_NC
5955 || r_type == R_ARM_ALU_PC_G0
5956 || r_type == R_ARM_ALU_PC_G1
5957 || r_type == R_ARM_ALU_PC_G2)
5958 /* PC relative. */
5959 signed_value = value - pc + signed_addend;
5960 else
5961 /* Section base relative. */
5962 signed_value = value - sb + signed_addend;
5964 /* If the target symbol is a Thumb function, then set the
5965 Thumb bit in the address. */
5966 if (sym_flags == STT_ARM_TFUNC)
5967 signed_value |= 1;
5969 /* Calculate the value of the relevant G_n, in encoded
5970 constant-with-rotation format. */
5971 g_n = calculate_group_reloc_mask (abs (signed_value), group,
5972 &residual);
5974 /* Check for overflow if required. */
5975 if ((r_type == R_ARM_ALU_PC_G0
5976 || r_type == R_ARM_ALU_PC_G1
5977 || r_type == R_ARM_ALU_PC_G2
5978 || r_type == R_ARM_ALU_SB_G0
5979 || r_type == R_ARM_ALU_SB_G1
5980 || r_type == R_ARM_ALU_SB_G2) && residual != 0)
5982 (*_bfd_error_handler)
5983 (_("%B(%A+0x%lx): Overflow whilst splitting 0x%lx for group relocation %s"),
5984 input_bfd, input_section,
5985 (long) rel->r_offset, abs (signed_value), howto->name);
5986 return bfd_reloc_overflow;
5989 /* Mask out the value and the ADD/SUB part of the opcode; take care
5990 not to destroy the S bit. */
5991 insn &= 0xff1ff000;
5993 /* Set the opcode according to whether the value to go in the
5994 place is negative. */
5995 if (signed_value < 0)
5996 insn |= 1 << 22;
5997 else
5998 insn |= 1 << 23;
6000 /* Encode the offset. */
6001 insn |= g_n;
6003 bfd_put_32 (input_bfd, insn, hit_data);
6005 return bfd_reloc_ok;
6007 case R_ARM_LDR_PC_G0:
6008 case R_ARM_LDR_PC_G1:
6009 case R_ARM_LDR_PC_G2:
6010 case R_ARM_LDR_SB_G0:
6011 case R_ARM_LDR_SB_G1:
6012 case R_ARM_LDR_SB_G2:
6014 bfd_vma insn = bfd_get_32 (input_bfd, hit_data);
6015 bfd_vma pc = input_section->output_section->vma
6016 + input_section->output_offset + rel->r_offset;
6017 bfd_vma sb = 0; /* See note above. */
6018 bfd_vma residual;
6019 bfd_signed_vma signed_value;
6020 int group = 0;
6022 /* Determine which groups of bits to calculate. */
6023 switch (r_type)
6025 case R_ARM_LDR_PC_G0:
6026 case R_ARM_LDR_SB_G0:
6027 group = 0;
6028 break;
6030 case R_ARM_LDR_PC_G1:
6031 case R_ARM_LDR_SB_G1:
6032 group = 1;
6033 break;
6035 case R_ARM_LDR_PC_G2:
6036 case R_ARM_LDR_SB_G2:
6037 group = 2;
6038 break;
6040 default:
6041 abort();
6044 /* If REL, extract the addend from the insn. If RELA, it will
6045 have already been fetched for us. */
6046 if (globals->use_rel)
6048 int negative = (insn & (1 << 23)) ? 1 : -1;
6049 signed_addend = negative * (insn & 0xfff);
6052 /* Compute the value (X) to go in the place. */
6053 if (r_type == R_ARM_LDR_PC_G0
6054 || r_type == R_ARM_LDR_PC_G1
6055 || r_type == R_ARM_LDR_PC_G2)
6056 /* PC relative. */
6057 signed_value = value - pc + signed_addend;
6058 else
6059 /* Section base relative. */
6060 signed_value = value - sb + signed_addend;
6062 /* Calculate the value of the relevant G_{n-1} to obtain
6063 the residual at that stage. */
6064 calculate_group_reloc_mask (abs (signed_value), group - 1, &residual);
6066 /* Check for overflow. */
6067 if (residual >= 0x1000)
6069 (*_bfd_error_handler)
6070 (_("%B(%A+0x%lx): Overflow whilst splitting 0x%lx for group relocation %s"),
6071 input_bfd, input_section,
6072 (long) rel->r_offset, abs (signed_value), howto->name);
6073 return bfd_reloc_overflow;
6076 /* Mask out the value and U bit. */
6077 insn &= 0xff7ff000;
6079 /* Set the U bit if the value to go in the place is non-negative. */
6080 if (signed_value >= 0)
6081 insn |= 1 << 23;
6083 /* Encode the offset. */
6084 insn |= residual;
6086 bfd_put_32 (input_bfd, insn, hit_data);
6088 return bfd_reloc_ok;
6090 case R_ARM_LDRS_PC_G0:
6091 case R_ARM_LDRS_PC_G1:
6092 case R_ARM_LDRS_PC_G2:
6093 case R_ARM_LDRS_SB_G0:
6094 case R_ARM_LDRS_SB_G1:
6095 case R_ARM_LDRS_SB_G2:
6097 bfd_vma insn = bfd_get_32 (input_bfd, hit_data);
6098 bfd_vma pc = input_section->output_section->vma
6099 + input_section->output_offset + rel->r_offset;
6100 bfd_vma sb = 0; /* See note above. */
6101 bfd_vma residual;
6102 bfd_signed_vma signed_value;
6103 int group = 0;
6105 /* Determine which groups of bits to calculate. */
6106 switch (r_type)
6108 case R_ARM_LDRS_PC_G0:
6109 case R_ARM_LDRS_SB_G0:
6110 group = 0;
6111 break;
6113 case R_ARM_LDRS_PC_G1:
6114 case R_ARM_LDRS_SB_G1:
6115 group = 1;
6116 break;
6118 case R_ARM_LDRS_PC_G2:
6119 case R_ARM_LDRS_SB_G2:
6120 group = 2;
6121 break;
6123 default:
6124 abort();
6127 /* If REL, extract the addend from the insn. If RELA, it will
6128 have already been fetched for us. */
6129 if (globals->use_rel)
6131 int negative = (insn & (1 << 23)) ? 1 : -1;
6132 signed_addend = negative * (((insn & 0xf00) >> 4) + (insn & 0xf));
6135 /* Compute the value (X) to go in the place. */
6136 if (r_type == R_ARM_LDRS_PC_G0
6137 || r_type == R_ARM_LDRS_PC_G1
6138 || r_type == R_ARM_LDRS_PC_G2)
6139 /* PC relative. */
6140 signed_value = value - pc + signed_addend;
6141 else
6142 /* Section base relative. */
6143 signed_value = value - sb + signed_addend;
6145 /* Calculate the value of the relevant G_{n-1} to obtain
6146 the residual at that stage. */
6147 calculate_group_reloc_mask (abs (signed_value), group - 1, &residual);
6149 /* Check for overflow. */
6150 if (residual >= 0x100)
6152 (*_bfd_error_handler)
6153 (_("%B(%A+0x%lx): Overflow whilst splitting 0x%lx for group relocation %s"),
6154 input_bfd, input_section,
6155 (long) rel->r_offset, abs (signed_value), howto->name);
6156 return bfd_reloc_overflow;
6159 /* Mask out the value and U bit. */
6160 insn &= 0xff7ff0f0;
6162 /* Set the U bit if the value to go in the place is non-negative. */
6163 if (signed_value >= 0)
6164 insn |= 1 << 23;
6166 /* Encode the offset. */
6167 insn |= ((residual & 0xf0) << 4) | (residual & 0xf);
6169 bfd_put_32 (input_bfd, insn, hit_data);
6171 return bfd_reloc_ok;
6173 case R_ARM_LDC_PC_G0:
6174 case R_ARM_LDC_PC_G1:
6175 case R_ARM_LDC_PC_G2:
6176 case R_ARM_LDC_SB_G0:
6177 case R_ARM_LDC_SB_G1:
6178 case R_ARM_LDC_SB_G2:
6180 bfd_vma insn = bfd_get_32 (input_bfd, hit_data);
6181 bfd_vma pc = input_section->output_section->vma
6182 + input_section->output_offset + rel->r_offset;
6183 bfd_vma sb = 0; /* See note above. */
6184 bfd_vma residual;
6185 bfd_signed_vma signed_value;
6186 int group = 0;
6188 /* Determine which groups of bits to calculate. */
6189 switch (r_type)
6191 case R_ARM_LDC_PC_G0:
6192 case R_ARM_LDC_SB_G0:
6193 group = 0;
6194 break;
6196 case R_ARM_LDC_PC_G1:
6197 case R_ARM_LDC_SB_G1:
6198 group = 1;
6199 break;
6201 case R_ARM_LDC_PC_G2:
6202 case R_ARM_LDC_SB_G2:
6203 group = 2;
6204 break;
6206 default:
6207 abort();
6210 /* If REL, extract the addend from the insn. If RELA, it will
6211 have already been fetched for us. */
6212 if (globals->use_rel)
6214 int negative = (insn & (1 << 23)) ? 1 : -1;
6215 signed_addend = negative * ((insn & 0xff) << 2);
6218 /* Compute the value (X) to go in the place. */
6219 if (r_type == R_ARM_LDC_PC_G0
6220 || r_type == R_ARM_LDC_PC_G1
6221 || r_type == R_ARM_LDC_PC_G2)
6222 /* PC relative. */
6223 signed_value = value - pc + signed_addend;
6224 else
6225 /* Section base relative. */
6226 signed_value = value - sb + signed_addend;
6228 /* Calculate the value of the relevant G_{n-1} to obtain
6229 the residual at that stage. */
6230 calculate_group_reloc_mask (abs (signed_value), group - 1, &residual);
6232 /* Check for overflow. (The absolute value to go in the place must be
6233 divisible by four and, after having been divided by four, must
6234 fit in eight bits.) */
6235 if ((residual & 0x3) != 0 || residual >= 0x400)
6237 (*_bfd_error_handler)
6238 (_("%B(%A+0x%lx): Overflow whilst splitting 0x%lx for group relocation %s"),
6239 input_bfd, input_section,
6240 (long) rel->r_offset, abs (signed_value), howto->name);
6241 return bfd_reloc_overflow;
6244 /* Mask out the value and U bit. */
6245 insn &= 0xff7fff00;
6247 /* Set the U bit if the value to go in the place is non-negative. */
6248 if (signed_value >= 0)
6249 insn |= 1 << 23;
6251 /* Encode the offset. */
6252 insn |= residual >> 2;
6254 bfd_put_32 (input_bfd, insn, hit_data);
6256 return bfd_reloc_ok;
6258 default:
6259 return bfd_reloc_notsupported;
6264 static int
6265 uleb128_size (unsigned int i)
6267 int size;
6268 size = 1;
6269 while (i >= 0x80)
6271 i >>= 7;
6272 size++;
6274 return size;
6277 /* Return TRUE if the attribute has the default value (0/""). */
6278 static bfd_boolean
6279 is_default_attr (aeabi_attribute *attr)
6281 if ((attr->type & 1) && attr->i != 0)
6282 return FALSE;
6283 if ((attr->type & 2) && attr->s && *attr->s)
6284 return FALSE;
6286 return TRUE;
6289 /* Return the size of a single attribute. */
6290 static bfd_vma
6291 eabi_attr_size(int tag, aeabi_attribute *attr)
6293 bfd_vma size;
6295 if (is_default_attr (attr))
6296 return 0;
6298 size = uleb128_size (tag);
6299 if (attr->type & 1)
6300 size += uleb128_size (attr->i);
6301 if (attr->type & 2)
6302 size += strlen ((char *)attr->s) + 1;
6303 return size;
6306 /* Returns the size of the eabi object attributess section. */
6307 bfd_vma
6308 elf32_arm_eabi_attr_size (bfd *abfd)
6310 bfd_vma size;
6311 aeabi_attribute *attr;
6312 aeabi_attribute_list *list;
6313 int i;
6315 attr = elf32_arm_tdata (abfd)->known_eabi_attributes;
6316 size = 16; /* 'A' <size> "aeabi" 0x1 <size>. */
6317 for (i = 4; i < NUM_KNOWN_ATTRIBUTES; i++)
6318 size += eabi_attr_size (i, &attr[i]);
6320 for (list = elf32_arm_tdata (abfd)->other_eabi_attributes;
6321 list;
6322 list = list->next)
6323 size += eabi_attr_size (list->tag, &list->attr);
6325 return size;
6328 static bfd_byte *
6329 write_uleb128 (bfd_byte *p, unsigned int val)
6331 bfd_byte c;
6334 c = val & 0x7f;
6335 val >>= 7;
6336 if (val)
6337 c |= 0x80;
6338 *(p++) = c;
6340 while (val);
6341 return p;
6344 /* Write attribute ATTR to butter P, and return a pointer to the following
6345 byte. */
6346 static bfd_byte *
6347 write_eabi_attribute (bfd_byte *p, int tag, aeabi_attribute *attr)
6349 /* Suppress default entries. */
6350 if (is_default_attr(attr))
6351 return p;
6353 p = write_uleb128 (p, tag);
6354 if (attr->type & 1)
6355 p = write_uleb128 (p, attr->i);
6356 if (attr->type & 2)
6358 int len;
6360 len = strlen (attr->s) + 1;
6361 memcpy (p, attr->s, len);
6362 p += len;
6365 return p;
6368 /* Write the contents of the eabi attributes section to p. */
6369 void
6370 elf32_arm_set_eabi_attr_contents (bfd *abfd, bfd_byte *contents, bfd_vma size)
6372 bfd_byte *p;
6373 aeabi_attribute *attr;
6374 aeabi_attribute_list *list;
6375 int i;
6377 p = contents;
6378 *(p++) = 'A';
6379 bfd_put_32 (abfd, size - 1, p);
6380 p += 4;
6381 memcpy (p, "aeabi", 6);
6382 p += 6;
6383 *(p++) = Tag_File;
6384 bfd_put_32 (abfd, size - 11, p);
6385 p += 4;
6387 attr = elf32_arm_tdata (abfd)->known_eabi_attributes;
6388 for (i = 4; i < NUM_KNOWN_ATTRIBUTES; i++)
6389 p = write_eabi_attribute (p, i, &attr[i]);
6391 for (list = elf32_arm_tdata (abfd)->other_eabi_attributes;
6392 list;
6393 list = list->next)
6394 p = write_eabi_attribute (p, list->tag, &list->attr);
6397 /* Override final_link to handle EABI object attribute sections. */
6399 static bfd_boolean
6400 elf32_arm_bfd_final_link (bfd *abfd, struct bfd_link_info *info)
6402 asection *o;
6403 struct bfd_link_order *p;
6404 asection *attr_section = NULL;
6405 bfd_byte *contents;
6406 bfd_vma size = 0;
6408 /* elf32_arm_merge_private_bfd_data will already have merged the
6409 object attributes. Remove the input sections from the link, and set
6410 the contents of the output secton. */
6411 for (o = abfd->sections; o != NULL; o = o->next)
6413 if (strcmp (o->name, ".ARM.attributes") == 0)
6415 for (p = o->map_head.link_order; p != NULL; p = p->next)
6417 asection *input_section;
6419 if (p->type != bfd_indirect_link_order)
6420 continue;
6421 input_section = p->u.indirect.section;
6422 /* Hack: reset the SEC_HAS_CONTENTS flag so that
6423 elf_link_input_bfd ignores this section. */
6424 input_section->flags &= ~SEC_HAS_CONTENTS;
6427 size = elf32_arm_eabi_attr_size (abfd);
6428 bfd_set_section_size (abfd, o, size);
6429 attr_section = o;
6430 /* Skip this section later on. */
6431 o->map_head.link_order = NULL;
6434 /* Invoke the ELF linker to do all the work. */
6435 if (!bfd_elf_final_link (abfd, info))
6436 return FALSE;
6438 if (attr_section)
6440 contents = bfd_malloc(size);
6441 if (contents == NULL)
6442 return FALSE;
6443 elf32_arm_set_eabi_attr_contents (abfd, contents, size);
6444 bfd_set_section_contents (abfd, attr_section, contents, 0, size);
6445 free (contents);
6447 return TRUE;
6451 /* Add INCREMENT to the reloc (of type HOWTO) at ADDRESS. */
6452 static void
6453 arm_add_to_rel (bfd * abfd,
6454 bfd_byte * address,
6455 reloc_howto_type * howto,
6456 bfd_signed_vma increment)
6458 bfd_signed_vma addend;
6460 if (howto->type == R_ARM_THM_CALL)
6462 int upper_insn, lower_insn;
6463 int upper, lower;
6465 upper_insn = bfd_get_16 (abfd, address);
6466 lower_insn = bfd_get_16 (abfd, address + 2);
6467 upper = upper_insn & 0x7ff;
6468 lower = lower_insn & 0x7ff;
6470 addend = (upper << 12) | (lower << 1);
6471 addend += increment;
6472 addend >>= 1;
6474 upper_insn = (upper_insn & 0xf800) | ((addend >> 11) & 0x7ff);
6475 lower_insn = (lower_insn & 0xf800) | (addend & 0x7ff);
6477 bfd_put_16 (abfd, (bfd_vma) upper_insn, address);
6478 bfd_put_16 (abfd, (bfd_vma) lower_insn, address + 2);
6480 else
6482 bfd_vma contents;
6484 contents = bfd_get_32 (abfd, address);
6486 /* Get the (signed) value from the instruction. */
6487 addend = contents & howto->src_mask;
6488 if (addend & ((howto->src_mask + 1) >> 1))
6490 bfd_signed_vma mask;
6492 mask = -1;
6493 mask &= ~ howto->src_mask;
6494 addend |= mask;
6497 /* Add in the increment, (which is a byte value). */
6498 switch (howto->type)
6500 default:
6501 addend += increment;
6502 break;
6504 case R_ARM_PC24:
6505 case R_ARM_PLT32:
6506 case R_ARM_CALL:
6507 case R_ARM_JUMP24:
6508 addend <<= howto->size;
6509 addend += increment;
6511 /* Should we check for overflow here ? */
6513 /* Drop any undesired bits. */
6514 addend >>= howto->rightshift;
6515 break;
6518 contents = (contents & ~ howto->dst_mask) | (addend & howto->dst_mask);
6520 bfd_put_32 (abfd, contents, address);
6524 #define IS_ARM_TLS_RELOC(R_TYPE) \
6525 ((R_TYPE) == R_ARM_TLS_GD32 \
6526 || (R_TYPE) == R_ARM_TLS_LDO32 \
6527 || (R_TYPE) == R_ARM_TLS_LDM32 \
6528 || (R_TYPE) == R_ARM_TLS_DTPOFF32 \
6529 || (R_TYPE) == R_ARM_TLS_DTPMOD32 \
6530 || (R_TYPE) == R_ARM_TLS_TPOFF32 \
6531 || (R_TYPE) == R_ARM_TLS_LE32 \
6532 || (R_TYPE) == R_ARM_TLS_IE32)
6534 /* Relocate an ARM ELF section. */
6535 static bfd_boolean
6536 elf32_arm_relocate_section (bfd * output_bfd,
6537 struct bfd_link_info * info,
6538 bfd * input_bfd,
6539 asection * input_section,
6540 bfd_byte * contents,
6541 Elf_Internal_Rela * relocs,
6542 Elf_Internal_Sym * local_syms,
6543 asection ** local_sections)
6545 Elf_Internal_Shdr *symtab_hdr;
6546 struct elf_link_hash_entry **sym_hashes;
6547 Elf_Internal_Rela *rel;
6548 Elf_Internal_Rela *relend;
6549 const char *name;
6550 struct elf32_arm_link_hash_table * globals;
6552 globals = elf32_arm_hash_table (info);
6554 symtab_hdr = & elf_tdata (input_bfd)->symtab_hdr;
6555 sym_hashes = elf_sym_hashes (input_bfd);
6557 rel = relocs;
6558 relend = relocs + input_section->reloc_count;
6559 for (; rel < relend; rel++)
6561 int r_type;
6562 reloc_howto_type * howto;
6563 unsigned long r_symndx;
6564 Elf_Internal_Sym * sym;
6565 asection * sec;
6566 struct elf_link_hash_entry * h;
6567 bfd_vma relocation;
6568 bfd_reloc_status_type r;
6569 arelent bfd_reloc;
6570 char sym_type;
6571 bfd_boolean unresolved_reloc = FALSE;
6572 char *error_message = NULL;
6574 r_symndx = ELF32_R_SYM (rel->r_info);
6575 r_type = ELF32_R_TYPE (rel->r_info);
6576 r_type = arm_real_reloc_type (globals, r_type);
6578 if ( r_type == R_ARM_GNU_VTENTRY
6579 || r_type == R_ARM_GNU_VTINHERIT)
6580 continue;
6582 bfd_reloc.howto = elf32_arm_howto_from_type (r_type);
6583 howto = bfd_reloc.howto;
6585 h = NULL;
6586 sym = NULL;
6587 sec = NULL;
6589 if (r_symndx < symtab_hdr->sh_info)
6591 sym = local_syms + r_symndx;
6592 sym_type = ELF32_ST_TYPE (sym->st_info);
6593 sec = local_sections[r_symndx];
6594 if (globals->use_rel)
6596 relocation = (sec->output_section->vma
6597 + sec->output_offset
6598 + sym->st_value);
6599 if (!info->relocatable
6600 && (sec->flags & SEC_MERGE)
6601 && ELF_ST_TYPE (sym->st_info) == STT_SECTION)
6603 asection *msec;
6604 bfd_vma addend, value;
6606 if (howto->rightshift)
6608 (*_bfd_error_handler)
6609 (_("%B(%A+0x%lx): %s relocation against SEC_MERGE section"),
6610 input_bfd, input_section,
6611 (long) rel->r_offset, howto->name);
6612 return FALSE;
6615 value = bfd_get_32 (input_bfd, contents + rel->r_offset);
6617 /* Get the (signed) value from the instruction. */
6618 addend = value & howto->src_mask;
6619 if (addend & ((howto->src_mask + 1) >> 1))
6621 bfd_signed_vma mask;
6623 mask = -1;
6624 mask &= ~ howto->src_mask;
6625 addend |= mask;
6627 msec = sec;
6628 addend =
6629 _bfd_elf_rel_local_sym (output_bfd, sym, &msec, addend)
6630 - relocation;
6631 addend += msec->output_section->vma + msec->output_offset;
6632 value = (value & ~ howto->dst_mask) | (addend & howto->dst_mask);
6633 bfd_put_32 (input_bfd, value, contents + rel->r_offset);
6636 else
6637 relocation = _bfd_elf_rela_local_sym (output_bfd, sym, &sec, rel);
6639 else
6641 bfd_boolean warned;
6643 RELOC_FOR_GLOBAL_SYMBOL (info, input_bfd, input_section, rel,
6644 r_symndx, symtab_hdr, sym_hashes,
6645 h, sec, relocation,
6646 unresolved_reloc, warned);
6648 sym_type = h->type;
6651 if (sec != NULL && elf_discarded_section (sec))
6653 /* For relocs against symbols from removed linkonce sections,
6654 or sections discarded by a linker script, we just want the
6655 section contents zeroed. Avoid any special processing. */
6656 _bfd_clear_contents (howto, input_bfd, contents + rel->r_offset);
6657 rel->r_info = 0;
6658 rel->r_addend = 0;
6659 continue;
6662 if (info->relocatable)
6664 /* This is a relocatable link. We don't have to change
6665 anything, unless the reloc is against a section symbol,
6666 in which case we have to adjust according to where the
6667 section symbol winds up in the output section. */
6668 if (sym != NULL && ELF_ST_TYPE (sym->st_info) == STT_SECTION)
6670 if (globals->use_rel)
6671 arm_add_to_rel (input_bfd, contents + rel->r_offset,
6672 howto, (bfd_signed_vma) sec->output_offset);
6673 else
6674 rel->r_addend += sec->output_offset;
6676 continue;
6679 if (h != NULL)
6680 name = h->root.root.string;
6681 else
6683 name = (bfd_elf_string_from_elf_section
6684 (input_bfd, symtab_hdr->sh_link, sym->st_name));
6685 if (name == NULL || *name == '\0')
6686 name = bfd_section_name (input_bfd, sec);
6689 if (r_symndx != 0
6690 && r_type != R_ARM_NONE
6691 && (h == NULL
6692 || h->root.type == bfd_link_hash_defined
6693 || h->root.type == bfd_link_hash_defweak)
6694 && IS_ARM_TLS_RELOC (r_type) != (sym_type == STT_TLS))
6696 (*_bfd_error_handler)
6697 ((sym_type == STT_TLS
6698 ? _("%B(%A+0x%lx): %s used with TLS symbol %s")
6699 : _("%B(%A+0x%lx): %s used with non-TLS symbol %s")),
6700 input_bfd,
6701 input_section,
6702 (long) rel->r_offset,
6703 howto->name,
6704 name);
6707 r = elf32_arm_final_link_relocate (howto, input_bfd, output_bfd,
6708 input_section, contents, rel,
6709 relocation, info, sec, name,
6710 (h ? ELF_ST_TYPE (h->type) :
6711 ELF_ST_TYPE (sym->st_info)), h,
6712 &unresolved_reloc, &error_message);
6714 /* Dynamic relocs are not propagated for SEC_DEBUGGING sections
6715 because such sections are not SEC_ALLOC and thus ld.so will
6716 not process them. */
6717 if (unresolved_reloc
6718 && !((input_section->flags & SEC_DEBUGGING) != 0
6719 && h->def_dynamic))
6721 (*_bfd_error_handler)
6722 (_("%B(%A+0x%lx): unresolvable %s relocation against symbol `%s'"),
6723 input_bfd,
6724 input_section,
6725 (long) rel->r_offset,
6726 howto->name,
6727 h->root.root.string);
6728 return FALSE;
6731 if (r != bfd_reloc_ok)
6733 switch (r)
6735 case bfd_reloc_overflow:
6736 /* If the overflowing reloc was to an undefined symbol,
6737 we have already printed one error message and there
6738 is no point complaining again. */
6739 if ((! h ||
6740 h->root.type != bfd_link_hash_undefined)
6741 && (!((*info->callbacks->reloc_overflow)
6742 (info, (h ? &h->root : NULL), name, howto->name,
6743 (bfd_vma) 0, input_bfd, input_section,
6744 rel->r_offset))))
6745 return FALSE;
6746 break;
6748 case bfd_reloc_undefined:
6749 if (!((*info->callbacks->undefined_symbol)
6750 (info, name, input_bfd, input_section,
6751 rel->r_offset, TRUE)))
6752 return FALSE;
6753 break;
6755 case bfd_reloc_outofrange:
6756 error_message = _("out of range");
6757 goto common_error;
6759 case bfd_reloc_notsupported:
6760 error_message = _("unsupported relocation");
6761 goto common_error;
6763 case bfd_reloc_dangerous:
6764 /* error_message should already be set. */
6765 goto common_error;
6767 default:
6768 error_message = _("unknown error");
6769 /* fall through */
6771 common_error:
6772 BFD_ASSERT (error_message != NULL);
6773 if (!((*info->callbacks->reloc_dangerous)
6774 (info, error_message, input_bfd, input_section,
6775 rel->r_offset)))
6776 return FALSE;
6777 break;
6782 return TRUE;
6785 /* Allocate/find an object attribute. */
6786 static aeabi_attribute *
6787 elf32_arm_new_eabi_attr (bfd *abfd, int tag)
6789 aeabi_attribute *attr;
6790 aeabi_attribute_list *list;
6791 aeabi_attribute_list *p;
6792 aeabi_attribute_list **lastp;
6795 if (tag < NUM_KNOWN_ATTRIBUTES)
6797 /* Knwon tags are preallocated. */
6798 attr = &elf32_arm_tdata (abfd)->known_eabi_attributes[tag];
6800 else
6802 /* Create a new tag. */
6803 list = (aeabi_attribute_list *)
6804 bfd_alloc (abfd, sizeof (aeabi_attribute_list));
6805 memset (list, 0, sizeof (aeabi_attribute_list));
6806 list->tag = tag;
6807 /* Keep the tag list in order. */
6808 lastp = &elf32_arm_tdata (abfd)->other_eabi_attributes;
6809 for (p = *lastp; p; p = p->next)
6811 if (tag < p->tag)
6812 break;
6813 lastp = &p->next;
6815 list->next = *lastp;
6816 *lastp = list;
6817 attr = &list->attr;
6820 return attr;
6824 elf32_arm_get_eabi_attr_int (bfd *abfd, int tag)
6826 aeabi_attribute_list *p;
6828 if (tag < NUM_KNOWN_ATTRIBUTES)
6830 /* Knwon tags are preallocated. */
6831 return elf32_arm_tdata (abfd)->known_eabi_attributes[tag].i;
6833 else
6835 for (p = elf32_arm_tdata (abfd)->other_eabi_attributes;
6837 p = p->next)
6839 if (tag == p->tag)
6840 return p->attr.i;
6841 if (tag < p->tag)
6842 break;
6844 return 0;
6848 void
6849 elf32_arm_add_eabi_attr_int (bfd *abfd, int tag, unsigned int i)
6851 aeabi_attribute *attr;
6853 attr = elf32_arm_new_eabi_attr (abfd, tag);
6854 attr->type = 1;
6855 attr->i = i;
6858 static char *
6859 attr_strdup (bfd *abfd, const char * s)
6861 char * p;
6862 int len;
6864 len = strlen (s) + 1;
6865 p = (char *)bfd_alloc(abfd, len);
6866 return memcpy (p, s, len);
6869 void
6870 elf32_arm_add_eabi_attr_string (bfd *abfd, int tag, const char *s)
6872 aeabi_attribute *attr;
6874 attr = elf32_arm_new_eabi_attr (abfd, tag);
6875 attr->type = 2;
6876 attr->s = attr_strdup (abfd, s);
6879 void
6880 elf32_arm_add_eabi_attr_compat (bfd *abfd, unsigned int i, const char *s)
6882 aeabi_attribute_list *list;
6883 aeabi_attribute_list *p;
6884 aeabi_attribute_list **lastp;
6886 list = (aeabi_attribute_list *)
6887 bfd_alloc (abfd, sizeof (aeabi_attribute_list));
6888 memset (list, 0, sizeof (aeabi_attribute_list));
6889 list->tag = Tag_compatibility;
6890 list->attr.type = 3;
6891 list->attr.i = i;
6892 list->attr.s = attr_strdup (abfd, s);
6894 lastp = &elf32_arm_tdata (abfd)->other_eabi_attributes;
6895 for (p = *lastp; p; p = p->next)
6897 int cmp;
6898 if (p->tag != Tag_compatibility)
6899 break;
6900 cmp = strcmp(s, p->attr.s);
6901 if (cmp < 0 || (cmp == 0 && i < p->attr.i))
6902 break;
6903 lastp = &p->next;
6905 list->next = *lastp;
6906 *lastp = list;
6909 /* Set the right machine number. */
6911 static bfd_boolean
6912 elf32_arm_object_p (bfd *abfd)
6914 unsigned int mach;
6916 mach = bfd_arm_get_mach_from_notes (abfd, ARM_NOTE_SECTION);
6918 if (mach != bfd_mach_arm_unknown)
6919 bfd_default_set_arch_mach (abfd, bfd_arch_arm, mach);
6921 else if (elf_elfheader (abfd)->e_flags & EF_ARM_MAVERICK_FLOAT)
6922 bfd_default_set_arch_mach (abfd, bfd_arch_arm, bfd_mach_arm_ep9312);
6924 else
6925 bfd_default_set_arch_mach (abfd, bfd_arch_arm, mach);
6927 return TRUE;
6930 /* Function to keep ARM specific flags in the ELF header. */
6932 static bfd_boolean
6933 elf32_arm_set_private_flags (bfd *abfd, flagword flags)
6935 if (elf_flags_init (abfd)
6936 && elf_elfheader (abfd)->e_flags != flags)
6938 if (EF_ARM_EABI_VERSION (flags) == EF_ARM_EABI_UNKNOWN)
6940 if (flags & EF_ARM_INTERWORK)
6941 (*_bfd_error_handler)
6942 (_("Warning: Not setting interworking flag of %B since it has already been specified as non-interworking"),
6943 abfd);
6944 else
6945 _bfd_error_handler
6946 (_("Warning: Clearing the interworking flag of %B due to outside request"),
6947 abfd);
6950 else
6952 elf_elfheader (abfd)->e_flags = flags;
6953 elf_flags_init (abfd) = TRUE;
6956 return TRUE;
6959 /* Copy the eabi object attribute from IBFD to OBFD. */
6960 static void
6961 copy_eabi_attributes (bfd *ibfd, bfd *obfd)
6963 aeabi_attribute *in_attr;
6964 aeabi_attribute *out_attr;
6965 aeabi_attribute_list *list;
6966 int i;
6968 in_attr = &elf32_arm_tdata (ibfd)->known_eabi_attributes[4];
6969 out_attr = &elf32_arm_tdata (obfd)->known_eabi_attributes[4];
6970 for (i = 4; i < NUM_KNOWN_ATTRIBUTES; i++)
6972 out_attr->i = in_attr->i;
6973 if (in_attr->s && *in_attr->s)
6974 out_attr->s = attr_strdup (obfd, in_attr->s);
6975 in_attr++;
6976 out_attr++;
6979 for (list = elf32_arm_tdata (ibfd)->other_eabi_attributes;
6980 list;
6981 list = list->next)
6983 in_attr = &list->attr;
6984 switch (in_attr->type)
6986 case 1:
6987 elf32_arm_add_eabi_attr_int (obfd, list->tag, in_attr->i);
6988 break;
6989 case 2:
6990 elf32_arm_add_eabi_attr_string (obfd, list->tag, in_attr->s);
6991 break;
6992 case 3:
6993 elf32_arm_add_eabi_attr_compat (obfd, in_attr->i, in_attr->s);
6994 break;
6995 default:
6996 abort();
7002 /* Copy backend specific data from one object module to another. */
7004 static bfd_boolean
7005 elf32_arm_copy_private_bfd_data (bfd *ibfd, bfd *obfd)
7007 flagword in_flags;
7008 flagword out_flags;
7010 if ( bfd_get_flavour (ibfd) != bfd_target_elf_flavour
7011 || bfd_get_flavour (obfd) != bfd_target_elf_flavour)
7012 return TRUE;
7014 in_flags = elf_elfheader (ibfd)->e_flags;
7015 out_flags = elf_elfheader (obfd)->e_flags;
7017 if (elf_flags_init (obfd)
7018 && EF_ARM_EABI_VERSION (out_flags) == EF_ARM_EABI_UNKNOWN
7019 && in_flags != out_flags)
7021 /* Cannot mix APCS26 and APCS32 code. */
7022 if ((in_flags & EF_ARM_APCS_26) != (out_flags & EF_ARM_APCS_26))
7023 return FALSE;
7025 /* Cannot mix float APCS and non-float APCS code. */
7026 if ((in_flags & EF_ARM_APCS_FLOAT) != (out_flags & EF_ARM_APCS_FLOAT))
7027 return FALSE;
7029 /* If the src and dest have different interworking flags
7030 then turn off the interworking bit. */
7031 if ((in_flags & EF_ARM_INTERWORK) != (out_flags & EF_ARM_INTERWORK))
7033 if (out_flags & EF_ARM_INTERWORK)
7034 _bfd_error_handler
7035 (_("Warning: Clearing the interworking flag of %B because non-interworking code in %B has been linked with it"),
7036 obfd, ibfd);
7038 in_flags &= ~EF_ARM_INTERWORK;
7041 /* Likewise for PIC, though don't warn for this case. */
7042 if ((in_flags & EF_ARM_PIC) != (out_flags & EF_ARM_PIC))
7043 in_flags &= ~EF_ARM_PIC;
7046 elf_elfheader (obfd)->e_flags = in_flags;
7047 elf_flags_init (obfd) = TRUE;
7049 /* Also copy the EI_OSABI field. */
7050 elf_elfheader (obfd)->e_ident[EI_OSABI] =
7051 elf_elfheader (ibfd)->e_ident[EI_OSABI];
7053 /* Copy EABI object attributes. */
7054 copy_eabi_attributes (ibfd, obfd);
7056 return TRUE;
7059 /* Values for Tag_ABI_PCS_R9_use. */
7060 enum
7062 AEABI_R9_V6,
7063 AEABI_R9_SB,
7064 AEABI_R9_TLS,
7065 AEABI_R9_unused
7068 /* Values for Tag_ABI_PCS_RW_data. */
7069 enum
7071 AEABI_PCS_RW_data_absolute,
7072 AEABI_PCS_RW_data_PCrel,
7073 AEABI_PCS_RW_data_SBrel,
7074 AEABI_PCS_RW_data_unused
7077 /* Values for Tag_ABI_enum_size. */
7078 enum
7080 AEABI_enum_unused,
7081 AEABI_enum_short,
7082 AEABI_enum_wide,
7083 AEABI_enum_forced_wide
7086 /* Merge EABI object attributes from IBFD into OBFD. Raise an error if there
7087 are conflicting attributes. */
7088 static bfd_boolean
7089 elf32_arm_merge_eabi_attributes (bfd *ibfd, bfd *obfd)
7091 aeabi_attribute *in_attr;
7092 aeabi_attribute *out_attr;
7093 aeabi_attribute_list *in_list;
7094 aeabi_attribute_list *out_list;
7095 /* Some tags have 0 = don't care, 1 = strong requirement,
7096 2 = weak requirement. */
7097 static const int order_312[3] = {3, 1, 2};
7098 int i;
7100 if (!elf32_arm_tdata (obfd)->known_eabi_attributes[0].i)
7102 /* This is the first object. Copy the attributes. */
7103 copy_eabi_attributes (ibfd, obfd);
7105 /* Use the Tag_null value to indicate the attributes have been
7106 initialized. */
7107 elf32_arm_tdata (obfd)->known_eabi_attributes[0].i = 1;
7109 return TRUE;
7112 in_attr = elf32_arm_tdata (ibfd)->known_eabi_attributes;
7113 out_attr = elf32_arm_tdata (obfd)->known_eabi_attributes;
7114 /* This needs to happen before Tag_ABI_FP_number_model is merged. */
7115 if (in_attr[Tag_ABI_VFP_args].i != out_attr[Tag_ABI_VFP_args].i)
7117 /* Ignore mismatches if teh object doesn't use floating point. */
7118 if (out_attr[Tag_ABI_FP_number_model].i == 0)
7119 out_attr[Tag_ABI_VFP_args].i = in_attr[Tag_ABI_VFP_args].i;
7120 else if (in_attr[Tag_ABI_FP_number_model].i != 0)
7122 _bfd_error_handler
7123 (_("ERROR: %B uses VFP register arguments, %B does not"),
7124 ibfd, obfd);
7125 return FALSE;
7129 for (i = 4; i < NUM_KNOWN_ATTRIBUTES; i++)
7131 /* Merge this attribute with existing attributes. */
7132 switch (i)
7134 case Tag_CPU_raw_name:
7135 case Tag_CPU_name:
7136 /* Use whichever has the greatest architecture requirements. We
7137 won't necessarily have both the above tags, so make sure input
7138 name is non-NULL. */
7139 if (in_attr[Tag_CPU_arch].i > out_attr[Tag_CPU_arch].i
7140 && in_attr[i].s)
7141 out_attr[i].s = attr_strdup(obfd, in_attr[i].s);
7142 break;
7144 case Tag_ABI_optimization_goals:
7145 case Tag_ABI_FP_optimization_goals:
7146 /* Use the first value seen. */
7147 break;
7149 case Tag_CPU_arch:
7150 case Tag_ARM_ISA_use:
7151 case Tag_THUMB_ISA_use:
7152 case Tag_VFP_arch:
7153 case Tag_WMMX_arch:
7154 case Tag_NEON_arch:
7155 /* ??? Do NEON and WMMX conflict? */
7156 case Tag_ABI_FP_rounding:
7157 case Tag_ABI_FP_denormal:
7158 case Tag_ABI_FP_exceptions:
7159 case Tag_ABI_FP_user_exceptions:
7160 case Tag_ABI_FP_number_model:
7161 case Tag_ABI_align8_preserved:
7162 case Tag_ABI_HardFP_use:
7163 /* Use the largest value specified. */
7164 if (in_attr[i].i > out_attr[i].i)
7165 out_attr[i].i = in_attr[i].i;
7166 break;
7168 case Tag_CPU_arch_profile:
7169 /* Warn if conflicting architecture profiles used. */
7170 if (out_attr[i].i && in_attr[i].i && in_attr[i].i != out_attr[i].i)
7172 _bfd_error_handler
7173 (_("ERROR: %B: Conflicting architecture profiles %c/%c"),
7174 ibfd, in_attr[i].i, out_attr[i].i);
7175 return FALSE;
7177 if (in_attr[i].i)
7178 out_attr[i].i = in_attr[i].i;
7179 break;
7180 case Tag_PCS_config:
7181 if (out_attr[i].i == 0)
7182 out_attr[i].i = in_attr[i].i;
7183 else if (in_attr[i].i != 0 && out_attr[i].i != 0)
7185 /* It's sometimes ok to mix different configs, so this is only
7186 a warning. */
7187 _bfd_error_handler
7188 (_("Warning: %B: Conflicting platform configuration"), ibfd);
7190 break;
7191 case Tag_ABI_PCS_R9_use:
7192 if (in_attr[i].i != out_attr[i].i
7193 && out_attr[i].i != AEABI_R9_unused
7194 && in_attr[i].i != AEABI_R9_unused)
7196 _bfd_error_handler
7197 (_("ERROR: %B: Conflicting use of R9"), ibfd);
7198 return FALSE;
7200 if (out_attr[i].i == AEABI_R9_unused)
7201 out_attr[i].i = in_attr[i].i;
7202 break;
7203 case Tag_ABI_PCS_RW_data:
7204 if (in_attr[i].i == AEABI_PCS_RW_data_SBrel
7205 && out_attr[Tag_ABI_PCS_R9_use].i != AEABI_R9_SB
7206 && out_attr[Tag_ABI_PCS_R9_use].i != AEABI_R9_unused)
7208 _bfd_error_handler
7209 (_("ERROR: %B: SB relative addressing conflicts with use of R9"),
7210 ibfd);
7211 return FALSE;
7213 /* Use the smallest value specified. */
7214 if (in_attr[i].i < out_attr[i].i)
7215 out_attr[i].i = in_attr[i].i;
7216 break;
7217 case Tag_ABI_PCS_RO_data:
7218 /* Use the smallest value specified. */
7219 if (in_attr[i].i < out_attr[i].i)
7220 out_attr[i].i = in_attr[i].i;
7221 break;
7222 case Tag_ABI_PCS_GOT_use:
7223 if (in_attr[i].i > 2 || out_attr[i].i > 2
7224 || order_312[in_attr[i].i] < order_312[out_attr[i].i])
7225 out_attr[i].i = in_attr[i].i;
7226 break;
7227 case Tag_ABI_PCS_wchar_t:
7228 if (out_attr[i].i && in_attr[i].i && out_attr[i].i != in_attr[i].i)
7230 _bfd_error_handler
7231 (_("ERROR: %B: Conflicting definitions of wchar_t"), ibfd);
7232 return FALSE;
7234 if (in_attr[i].i)
7235 out_attr[i].i = in_attr[i].i;
7236 break;
7237 case Tag_ABI_align8_needed:
7238 /* ??? Check against Tag_ABI_align8_preserved. */
7239 if (in_attr[i].i > 2 || out_attr[i].i > 2
7240 || order_312[in_attr[i].i] < order_312[out_attr[i].i])
7241 out_attr[i].i = in_attr[i].i;
7242 break;
7243 case Tag_ABI_enum_size:
7244 if (in_attr[i].i != AEABI_enum_unused)
7246 if (out_attr[i].i == AEABI_enum_unused
7247 || out_attr[i].i == AEABI_enum_forced_wide)
7249 /* The existing object is compatible with anything.
7250 Use whatever requirements the new object has. */
7251 out_attr[i].i = in_attr[i].i;
7253 else if (in_attr[i].i != AEABI_enum_forced_wide
7254 && out_attr[i].i != in_attr[i].i
7255 && !elf32_arm_tdata (obfd)->no_enum_size_warning)
7257 const char *aeabi_enum_names[] =
7258 { "", "variable-size", "32-bit", "" };
7259 _bfd_error_handler
7260 (_("warning: %B uses %s enums yet the output is to use %s enums; use of enum values across objects may fail"),
7261 ibfd, aeabi_enum_names[in_attr[i].i],
7262 aeabi_enum_names[out_attr[i].i]);
7265 break;
7266 case Tag_ABI_VFP_args:
7267 /* Aready done. */
7268 break;
7269 case Tag_ABI_WMMX_args:
7270 if (in_attr[i].i != out_attr[i].i)
7272 _bfd_error_handler
7273 (_("ERROR: %B uses iWMMXt register arguments, %B does not"),
7274 ibfd, obfd);
7275 return FALSE;
7277 break;
7278 default: /* All known attributes should be explicitly covered. */
7279 abort ();
7283 in_list = elf32_arm_tdata (ibfd)->other_eabi_attributes;
7284 out_list = elf32_arm_tdata (ibfd)->other_eabi_attributes;
7285 while (in_list && in_list->tag == Tag_compatibility)
7287 in_attr = &in_list->attr;
7288 if (in_attr->i == 0)
7289 continue;
7290 if (in_attr->i == 1)
7292 _bfd_error_handler
7293 (_("ERROR: %B: Must be processed by '%s' toolchain"),
7294 ibfd, in_attr->s);
7295 return FALSE;
7297 if (!out_list || out_list->tag != Tag_compatibility
7298 || strcmp (in_attr->s, out_list->attr.s) != 0)
7300 /* Add this compatibility tag to the output. */
7301 elf32_arm_add_eabi_attr_compat (obfd, in_attr->i, in_attr->s);
7302 continue;
7304 out_attr = &out_list->attr;
7305 /* Check all the input tags with the same identifier. */
7306 for (;;)
7308 if (out_list->tag != Tag_compatibility
7309 || in_attr->i != out_attr->i
7310 || strcmp (in_attr->s, out_attr->s) != 0)
7312 _bfd_error_handler
7313 (_("ERROR: %B: Incompatible object tag '%s':%d"),
7314 ibfd, in_attr->s, in_attr->i);
7315 return FALSE;
7317 in_list = in_list->next;
7318 if (in_list->tag != Tag_compatibility
7319 || strcmp (in_attr->s, in_list->attr.s) != 0)
7320 break;
7321 in_attr = &in_list->attr;
7322 out_list = out_list->next;
7323 if (out_list)
7324 out_attr = &out_list->attr;
7327 /* Check the output doesn't have extra tags with this identifier. */
7328 if (out_list && out_list->tag == Tag_compatibility
7329 && strcmp (in_attr->s, out_list->attr.s) == 0)
7331 _bfd_error_handler
7332 (_("ERROR: %B: Incompatible object tag '%s':%d"),
7333 ibfd, in_attr->s, out_list->attr.i);
7334 return FALSE;
7338 for (; in_list; in_list = in_list->next)
7340 if ((in_list->tag & 128) < 64)
7342 _bfd_error_handler
7343 (_("Warning: %B: Unknown EABI object attribute %d"),
7344 ibfd, in_list->tag);
7345 break;
7348 return TRUE;
7352 /* Return TRUE if the two EABI versions are incompatible. */
7354 static bfd_boolean
7355 elf32_arm_versions_compatible (unsigned iver, unsigned over)
7357 /* v4 and v5 are the same spec before and after it was released,
7358 so allow mixing them. */
7359 if ((iver == EF_ARM_EABI_VER4 && over == EF_ARM_EABI_VER5)
7360 || (iver == EF_ARM_EABI_VER5 && over == EF_ARM_EABI_VER4))
7361 return TRUE;
7363 return (iver == over);
7366 /* Merge backend specific data from an object file to the output
7367 object file when linking. */
7369 static bfd_boolean
7370 elf32_arm_merge_private_bfd_data (bfd * ibfd, bfd * obfd)
7372 flagword out_flags;
7373 flagword in_flags;
7374 bfd_boolean flags_compatible = TRUE;
7375 asection *sec;
7377 /* Check if we have the same endianess. */
7378 if (! _bfd_generic_verify_endian_match (ibfd, obfd))
7379 return FALSE;
7381 if ( bfd_get_flavour (ibfd) != bfd_target_elf_flavour
7382 || bfd_get_flavour (obfd) != bfd_target_elf_flavour)
7383 return TRUE;
7385 if (!elf32_arm_merge_eabi_attributes (ibfd, obfd))
7386 return FALSE;
7388 /* The input BFD must have had its flags initialised. */
7389 /* The following seems bogus to me -- The flags are initialized in
7390 the assembler but I don't think an elf_flags_init field is
7391 written into the object. */
7392 /* BFD_ASSERT (elf_flags_init (ibfd)); */
7394 in_flags = elf_elfheader (ibfd)->e_flags;
7395 out_flags = elf_elfheader (obfd)->e_flags;
7397 if (!elf_flags_init (obfd))
7399 /* If the input is the default architecture and had the default
7400 flags then do not bother setting the flags for the output
7401 architecture, instead allow future merges to do this. If no
7402 future merges ever set these flags then they will retain their
7403 uninitialised values, which surprise surprise, correspond
7404 to the default values. */
7405 if (bfd_get_arch_info (ibfd)->the_default
7406 && elf_elfheader (ibfd)->e_flags == 0)
7407 return TRUE;
7409 elf_flags_init (obfd) = TRUE;
7410 elf_elfheader (obfd)->e_flags = in_flags;
7412 if (bfd_get_arch (obfd) == bfd_get_arch (ibfd)
7413 && bfd_get_arch_info (obfd)->the_default)
7414 return bfd_set_arch_mach (obfd, bfd_get_arch (ibfd), bfd_get_mach (ibfd));
7416 return TRUE;
7419 /* Determine what should happen if the input ARM architecture
7420 does not match the output ARM architecture. */
7421 if (! bfd_arm_merge_machines (ibfd, obfd))
7422 return FALSE;
7424 /* Identical flags must be compatible. */
7425 if (in_flags == out_flags)
7426 return TRUE;
7428 /* Check to see if the input BFD actually contains any sections. If
7429 not, its flags may not have been initialised either, but it
7430 cannot actually cause any incompatiblity. Do not short-circuit
7431 dynamic objects; their section list may be emptied by
7432 elf_link_add_object_symbols.
7434 Also check to see if there are no code sections in the input.
7435 In this case there is no need to check for code specific flags.
7436 XXX - do we need to worry about floating-point format compatability
7437 in data sections ? */
7438 if (!(ibfd->flags & DYNAMIC))
7440 bfd_boolean null_input_bfd = TRUE;
7441 bfd_boolean only_data_sections = TRUE;
7443 for (sec = ibfd->sections; sec != NULL; sec = sec->next)
7445 /* Ignore synthetic glue sections. */
7446 if (strcmp (sec->name, ".glue_7")
7447 && strcmp (sec->name, ".glue_7t"))
7449 if ((bfd_get_section_flags (ibfd, sec)
7450 & (SEC_LOAD | SEC_CODE | SEC_HAS_CONTENTS))
7451 == (SEC_LOAD | SEC_CODE | SEC_HAS_CONTENTS))
7452 only_data_sections = FALSE;
7454 null_input_bfd = FALSE;
7455 break;
7459 if (null_input_bfd || only_data_sections)
7460 return TRUE;
7463 /* Complain about various flag mismatches. */
7464 if (!elf32_arm_versions_compatible (EF_ARM_EABI_VERSION (in_flags),
7465 EF_ARM_EABI_VERSION (out_flags)))
7467 _bfd_error_handler
7468 (_("ERROR: Source object %B has EABI version %d, but target %B has EABI version %d"),
7469 ibfd, obfd,
7470 (in_flags & EF_ARM_EABIMASK) >> 24,
7471 (out_flags & EF_ARM_EABIMASK) >> 24);
7472 return FALSE;
7475 /* Not sure what needs to be checked for EABI versions >= 1. */
7476 /* VxWorks libraries do not use these flags. */
7477 if (get_elf_backend_data (obfd) != &elf32_arm_vxworks_bed
7478 && get_elf_backend_data (ibfd) != &elf32_arm_vxworks_bed
7479 && EF_ARM_EABI_VERSION (in_flags) == EF_ARM_EABI_UNKNOWN)
7481 if ((in_flags & EF_ARM_APCS_26) != (out_flags & EF_ARM_APCS_26))
7483 _bfd_error_handler
7484 (_("ERROR: %B is compiled for APCS-%d, whereas target %B uses APCS-%d"),
7485 ibfd, obfd,
7486 in_flags & EF_ARM_APCS_26 ? 26 : 32,
7487 out_flags & EF_ARM_APCS_26 ? 26 : 32);
7488 flags_compatible = FALSE;
7491 if ((in_flags & EF_ARM_APCS_FLOAT) != (out_flags & EF_ARM_APCS_FLOAT))
7493 if (in_flags & EF_ARM_APCS_FLOAT)
7494 _bfd_error_handler
7495 (_("ERROR: %B passes floats in float registers, whereas %B passes them in integer registers"),
7496 ibfd, obfd);
7497 else
7498 _bfd_error_handler
7499 (_("ERROR: %B passes floats in integer registers, whereas %B passes them in float registers"),
7500 ibfd, obfd);
7502 flags_compatible = FALSE;
7505 if ((in_flags & EF_ARM_VFP_FLOAT) != (out_flags & EF_ARM_VFP_FLOAT))
7507 if (in_flags & EF_ARM_VFP_FLOAT)
7508 _bfd_error_handler
7509 (_("ERROR: %B uses VFP instructions, whereas %B does not"),
7510 ibfd, obfd);
7511 else
7512 _bfd_error_handler
7513 (_("ERROR: %B uses FPA instructions, whereas %B does not"),
7514 ibfd, obfd);
7516 flags_compatible = FALSE;
7519 if ((in_flags & EF_ARM_MAVERICK_FLOAT) != (out_flags & EF_ARM_MAVERICK_FLOAT))
7521 if (in_flags & EF_ARM_MAVERICK_FLOAT)
7522 _bfd_error_handler
7523 (_("ERROR: %B uses Maverick instructions, whereas %B does not"),
7524 ibfd, obfd);
7525 else
7526 _bfd_error_handler
7527 (_("ERROR: %B does not use Maverick instructions, whereas %B does"),
7528 ibfd, obfd);
7530 flags_compatible = FALSE;
7533 #ifdef EF_ARM_SOFT_FLOAT
7534 if ((in_flags & EF_ARM_SOFT_FLOAT) != (out_flags & EF_ARM_SOFT_FLOAT))
7536 /* We can allow interworking between code that is VFP format
7537 layout, and uses either soft float or integer regs for
7538 passing floating point arguments and results. We already
7539 know that the APCS_FLOAT flags match; similarly for VFP
7540 flags. */
7541 if ((in_flags & EF_ARM_APCS_FLOAT) != 0
7542 || (in_flags & EF_ARM_VFP_FLOAT) == 0)
7544 if (in_flags & EF_ARM_SOFT_FLOAT)
7545 _bfd_error_handler
7546 (_("ERROR: %B uses software FP, whereas %B uses hardware FP"),
7547 ibfd, obfd);
7548 else
7549 _bfd_error_handler
7550 (_("ERROR: %B uses hardware FP, whereas %B uses software FP"),
7551 ibfd, obfd);
7553 flags_compatible = FALSE;
7556 #endif
7558 /* Interworking mismatch is only a warning. */
7559 if ((in_flags & EF_ARM_INTERWORK) != (out_flags & EF_ARM_INTERWORK))
7561 if (in_flags & EF_ARM_INTERWORK)
7563 _bfd_error_handler
7564 (_("Warning: %B supports interworking, whereas %B does not"),
7565 ibfd, obfd);
7567 else
7569 _bfd_error_handler
7570 (_("Warning: %B does not support interworking, whereas %B does"),
7571 ibfd, obfd);
7576 return flags_compatible;
7579 /* Display the flags field. */
7581 static bfd_boolean
7582 elf32_arm_print_private_bfd_data (bfd *abfd, void * ptr)
7584 FILE * file = (FILE *) ptr;
7585 unsigned long flags;
7587 BFD_ASSERT (abfd != NULL && ptr != NULL);
7589 /* Print normal ELF private data. */
7590 _bfd_elf_print_private_bfd_data (abfd, ptr);
7592 flags = elf_elfheader (abfd)->e_flags;
7593 /* Ignore init flag - it may not be set, despite the flags field
7594 containing valid data. */
7596 /* xgettext:c-format */
7597 fprintf (file, _("private flags = %lx:"), elf_elfheader (abfd)->e_flags);
7599 switch (EF_ARM_EABI_VERSION (flags))
7601 case EF_ARM_EABI_UNKNOWN:
7602 /* The following flag bits are GNU extensions and not part of the
7603 official ARM ELF extended ABI. Hence they are only decoded if
7604 the EABI version is not set. */
7605 if (flags & EF_ARM_INTERWORK)
7606 fprintf (file, _(" [interworking enabled]"));
7608 if (flags & EF_ARM_APCS_26)
7609 fprintf (file, " [APCS-26]");
7610 else
7611 fprintf (file, " [APCS-32]");
7613 if (flags & EF_ARM_VFP_FLOAT)
7614 fprintf (file, _(" [VFP float format]"));
7615 else if (flags & EF_ARM_MAVERICK_FLOAT)
7616 fprintf (file, _(" [Maverick float format]"));
7617 else
7618 fprintf (file, _(" [FPA float format]"));
7620 if (flags & EF_ARM_APCS_FLOAT)
7621 fprintf (file, _(" [floats passed in float registers]"));
7623 if (flags & EF_ARM_PIC)
7624 fprintf (file, _(" [position independent]"));
7626 if (flags & EF_ARM_NEW_ABI)
7627 fprintf (file, _(" [new ABI]"));
7629 if (flags & EF_ARM_OLD_ABI)
7630 fprintf (file, _(" [old ABI]"));
7632 if (flags & EF_ARM_SOFT_FLOAT)
7633 fprintf (file, _(" [software FP]"));
7635 flags &= ~(EF_ARM_INTERWORK | EF_ARM_APCS_26 | EF_ARM_APCS_FLOAT
7636 | EF_ARM_PIC | EF_ARM_NEW_ABI | EF_ARM_OLD_ABI
7637 | EF_ARM_SOFT_FLOAT | EF_ARM_VFP_FLOAT
7638 | EF_ARM_MAVERICK_FLOAT);
7639 break;
7641 case EF_ARM_EABI_VER1:
7642 fprintf (file, _(" [Version1 EABI]"));
7644 if (flags & EF_ARM_SYMSARESORTED)
7645 fprintf (file, _(" [sorted symbol table]"));
7646 else
7647 fprintf (file, _(" [unsorted symbol table]"));
7649 flags &= ~ EF_ARM_SYMSARESORTED;
7650 break;
7652 case EF_ARM_EABI_VER2:
7653 fprintf (file, _(" [Version2 EABI]"));
7655 if (flags & EF_ARM_SYMSARESORTED)
7656 fprintf (file, _(" [sorted symbol table]"));
7657 else
7658 fprintf (file, _(" [unsorted symbol table]"));
7660 if (flags & EF_ARM_DYNSYMSUSESEGIDX)
7661 fprintf (file, _(" [dynamic symbols use segment index]"));
7663 if (flags & EF_ARM_MAPSYMSFIRST)
7664 fprintf (file, _(" [mapping symbols precede others]"));
7666 flags &= ~(EF_ARM_SYMSARESORTED | EF_ARM_DYNSYMSUSESEGIDX
7667 | EF_ARM_MAPSYMSFIRST);
7668 break;
7670 case EF_ARM_EABI_VER3:
7671 fprintf (file, _(" [Version3 EABI]"));
7672 break;
7674 case EF_ARM_EABI_VER4:
7675 fprintf (file, _(" [Version4 EABI]"));
7676 goto eabi;
7678 case EF_ARM_EABI_VER5:
7679 fprintf (file, _(" [Version5 EABI]"));
7680 eabi:
7681 if (flags & EF_ARM_BE8)
7682 fprintf (file, _(" [BE8]"));
7684 if (flags & EF_ARM_LE8)
7685 fprintf (file, _(" [LE8]"));
7687 flags &= ~(EF_ARM_LE8 | EF_ARM_BE8);
7688 break;
7690 default:
7691 fprintf (file, _(" <EABI version unrecognised>"));
7692 break;
7695 flags &= ~ EF_ARM_EABIMASK;
7697 if (flags & EF_ARM_RELEXEC)
7698 fprintf (file, _(" [relocatable executable]"));
7700 if (flags & EF_ARM_HASENTRY)
7701 fprintf (file, _(" [has entry point]"));
7703 flags &= ~ (EF_ARM_RELEXEC | EF_ARM_HASENTRY);
7705 if (flags)
7706 fprintf (file, _("<Unrecognised flag bits set>"));
7708 fputc ('\n', file);
7710 return TRUE;
7713 static int
7714 elf32_arm_get_symbol_type (Elf_Internal_Sym * elf_sym, int type)
7716 switch (ELF_ST_TYPE (elf_sym->st_info))
7718 case STT_ARM_TFUNC:
7719 return ELF_ST_TYPE (elf_sym->st_info);
7721 case STT_ARM_16BIT:
7722 /* If the symbol is not an object, return the STT_ARM_16BIT flag.
7723 This allows us to distinguish between data used by Thumb instructions
7724 and non-data (which is probably code) inside Thumb regions of an
7725 executable. */
7726 if (type != STT_OBJECT && type != STT_TLS)
7727 return ELF_ST_TYPE (elf_sym->st_info);
7728 break;
7730 default:
7731 break;
7734 return type;
7737 static asection *
7738 elf32_arm_gc_mark_hook (asection *sec,
7739 struct bfd_link_info *info,
7740 Elf_Internal_Rela *rel,
7741 struct elf_link_hash_entry *h,
7742 Elf_Internal_Sym *sym)
7744 if (h != NULL)
7745 switch (ELF32_R_TYPE (rel->r_info))
7747 case R_ARM_GNU_VTINHERIT:
7748 case R_ARM_GNU_VTENTRY:
7749 return NULL;
7752 return _bfd_elf_gc_mark_hook (sec, info, rel, h, sym);
7755 /* Update the got entry reference counts for the section being removed. */
7757 static bfd_boolean
7758 elf32_arm_gc_sweep_hook (bfd * abfd,
7759 struct bfd_link_info * info,
7760 asection * sec,
7761 const Elf_Internal_Rela * relocs)
7763 Elf_Internal_Shdr *symtab_hdr;
7764 struct elf_link_hash_entry **sym_hashes;
7765 bfd_signed_vma *local_got_refcounts;
7766 const Elf_Internal_Rela *rel, *relend;
7767 struct elf32_arm_link_hash_table * globals;
7769 globals = elf32_arm_hash_table (info);
7771 elf_section_data (sec)->local_dynrel = NULL;
7773 symtab_hdr = &elf_tdata (abfd)->symtab_hdr;
7774 sym_hashes = elf_sym_hashes (abfd);
7775 local_got_refcounts = elf_local_got_refcounts (abfd);
7777 relend = relocs + sec->reloc_count;
7778 for (rel = relocs; rel < relend; rel++)
7780 unsigned long r_symndx;
7781 struct elf_link_hash_entry *h = NULL;
7782 int r_type;
7784 r_symndx = ELF32_R_SYM (rel->r_info);
7785 if (r_symndx >= symtab_hdr->sh_info)
7787 h = sym_hashes[r_symndx - symtab_hdr->sh_info];
7788 while (h->root.type == bfd_link_hash_indirect
7789 || h->root.type == bfd_link_hash_warning)
7790 h = (struct elf_link_hash_entry *) h->root.u.i.link;
7793 r_type = ELF32_R_TYPE (rel->r_info);
7794 r_type = arm_real_reloc_type (globals, r_type);
7795 switch (r_type)
7797 case R_ARM_GOT32:
7798 case R_ARM_GOT_PREL:
7799 case R_ARM_TLS_GD32:
7800 case R_ARM_TLS_IE32:
7801 if (h != NULL)
7803 if (h->got.refcount > 0)
7804 h->got.refcount -= 1;
7806 else if (local_got_refcounts != NULL)
7808 if (local_got_refcounts[r_symndx] > 0)
7809 local_got_refcounts[r_symndx] -= 1;
7811 break;
7813 case R_ARM_TLS_LDM32:
7814 elf32_arm_hash_table (info)->tls_ldm_got.refcount -= 1;
7815 break;
7817 case R_ARM_ABS32:
7818 case R_ARM_ABS32_NOI:
7819 case R_ARM_REL32:
7820 case R_ARM_REL32_NOI:
7821 case R_ARM_PC24:
7822 case R_ARM_PLT32:
7823 case R_ARM_CALL:
7824 case R_ARM_JUMP24:
7825 case R_ARM_PREL31:
7826 case R_ARM_THM_CALL:
7827 case R_ARM_MOVW_ABS_NC:
7828 case R_ARM_MOVT_ABS:
7829 case R_ARM_MOVW_PREL_NC:
7830 case R_ARM_MOVT_PREL:
7831 case R_ARM_THM_MOVW_ABS_NC:
7832 case R_ARM_THM_MOVT_ABS:
7833 case R_ARM_THM_MOVW_PREL_NC:
7834 case R_ARM_THM_MOVT_PREL:
7835 /* Should the interworking branches be here also? */
7837 if (h != NULL)
7839 struct elf32_arm_link_hash_entry *eh;
7840 struct elf32_arm_relocs_copied **pp;
7841 struct elf32_arm_relocs_copied *p;
7843 eh = (struct elf32_arm_link_hash_entry *) h;
7845 if (h->plt.refcount > 0)
7847 h->plt.refcount -= 1;
7848 if (ELF32_R_TYPE (rel->r_info) == R_ARM_THM_CALL)
7849 eh->plt_thumb_refcount--;
7852 if (r_type == R_ARM_ABS32
7853 || r_type == R_ARM_REL32
7854 || r_type == R_ARM_ABS32_NOI
7855 || r_type == R_ARM_REL32_NOI)
7857 for (pp = &eh->relocs_copied; (p = *pp) != NULL;
7858 pp = &p->next)
7859 if (p->section == sec)
7861 p->count -= 1;
7862 if (ELF32_R_TYPE (rel->r_info) == R_ARM_REL32
7863 || ELF32_R_TYPE (rel->r_info) == R_ARM_REL32_NOI)
7864 p->pc_count -= 1;
7865 if (p->count == 0)
7866 *pp = p->next;
7867 break;
7871 break;
7873 default:
7874 break;
7878 return TRUE;
7881 /* Look through the relocs for a section during the first phase. */
7883 static bfd_boolean
7884 elf32_arm_check_relocs (bfd *abfd, struct bfd_link_info *info,
7885 asection *sec, const Elf_Internal_Rela *relocs)
7887 Elf_Internal_Shdr *symtab_hdr;
7888 struct elf_link_hash_entry **sym_hashes;
7889 struct elf_link_hash_entry **sym_hashes_end;
7890 const Elf_Internal_Rela *rel;
7891 const Elf_Internal_Rela *rel_end;
7892 bfd *dynobj;
7893 asection *sreloc;
7894 bfd_vma *local_got_offsets;
7895 struct elf32_arm_link_hash_table *htab;
7897 if (info->relocatable)
7898 return TRUE;
7900 htab = elf32_arm_hash_table (info);
7901 sreloc = NULL;
7903 /* Create dynamic sections for relocatable executables so that we can
7904 copy relocations. */
7905 if (htab->root.is_relocatable_executable
7906 && ! htab->root.dynamic_sections_created)
7908 if (! _bfd_elf_link_create_dynamic_sections (abfd, info))
7909 return FALSE;
7912 dynobj = elf_hash_table (info)->dynobj;
7913 local_got_offsets = elf_local_got_offsets (abfd);
7915 symtab_hdr = &elf_tdata (abfd)->symtab_hdr;
7916 sym_hashes = elf_sym_hashes (abfd);
7917 sym_hashes_end = sym_hashes
7918 + symtab_hdr->sh_size / sizeof (Elf32_External_Sym);
7920 if (!elf_bad_symtab (abfd))
7921 sym_hashes_end -= symtab_hdr->sh_info;
7923 rel_end = relocs + sec->reloc_count;
7924 for (rel = relocs; rel < rel_end; rel++)
7926 struct elf_link_hash_entry *h;
7927 struct elf32_arm_link_hash_entry *eh;
7928 unsigned long r_symndx;
7929 int r_type;
7931 r_symndx = ELF32_R_SYM (rel->r_info);
7932 r_type = ELF32_R_TYPE (rel->r_info);
7933 r_type = arm_real_reloc_type (htab, r_type);
7935 if (r_symndx >= NUM_SHDR_ENTRIES (symtab_hdr))
7937 (*_bfd_error_handler) (_("%B: bad symbol index: %d"), abfd,
7938 r_symndx);
7939 return FALSE;
7942 if (r_symndx < symtab_hdr->sh_info)
7943 h = NULL;
7944 else
7946 h = sym_hashes[r_symndx - symtab_hdr->sh_info];
7947 while (h->root.type == bfd_link_hash_indirect
7948 || h->root.type == bfd_link_hash_warning)
7949 h = (struct elf_link_hash_entry *) h->root.u.i.link;
7952 eh = (struct elf32_arm_link_hash_entry *) h;
7954 switch (r_type)
7956 case R_ARM_GOT32:
7957 case R_ARM_GOT_PREL:
7958 case R_ARM_TLS_GD32:
7959 case R_ARM_TLS_IE32:
7960 /* This symbol requires a global offset table entry. */
7962 int tls_type, old_tls_type;
7964 switch (r_type)
7966 case R_ARM_TLS_GD32: tls_type = GOT_TLS_GD; break;
7967 case R_ARM_TLS_IE32: tls_type = GOT_TLS_IE; break;
7968 default: tls_type = GOT_NORMAL; break;
7971 if (h != NULL)
7973 h->got.refcount++;
7974 old_tls_type = elf32_arm_hash_entry (h)->tls_type;
7976 else
7978 bfd_signed_vma *local_got_refcounts;
7980 /* This is a global offset table entry for a local symbol. */
7981 local_got_refcounts = elf_local_got_refcounts (abfd);
7982 if (local_got_refcounts == NULL)
7984 bfd_size_type size;
7986 size = symtab_hdr->sh_info;
7987 size *= (sizeof (bfd_signed_vma) + sizeof(char));
7988 local_got_refcounts = bfd_zalloc (abfd, size);
7989 if (local_got_refcounts == NULL)
7990 return FALSE;
7991 elf_local_got_refcounts (abfd) = local_got_refcounts;
7992 elf32_arm_local_got_tls_type (abfd)
7993 = (char *) (local_got_refcounts + symtab_hdr->sh_info);
7995 local_got_refcounts[r_symndx] += 1;
7996 old_tls_type = elf32_arm_local_got_tls_type (abfd) [r_symndx];
7999 /* We will already have issued an error message if there is a
8000 TLS / non-TLS mismatch, based on the symbol type. We don't
8001 support any linker relaxations. So just combine any TLS
8002 types needed. */
8003 if (old_tls_type != GOT_UNKNOWN && old_tls_type != GOT_NORMAL
8004 && tls_type != GOT_NORMAL)
8005 tls_type |= old_tls_type;
8007 if (old_tls_type != tls_type)
8009 if (h != NULL)
8010 elf32_arm_hash_entry (h)->tls_type = tls_type;
8011 else
8012 elf32_arm_local_got_tls_type (abfd) [r_symndx] = tls_type;
8015 /* Fall through */
8017 case R_ARM_TLS_LDM32:
8018 if (r_type == R_ARM_TLS_LDM32)
8019 htab->tls_ldm_got.refcount++;
8020 /* Fall through */
8022 case R_ARM_GOTOFF32:
8023 case R_ARM_GOTPC:
8024 if (htab->sgot == NULL)
8026 if (htab->root.dynobj == NULL)
8027 htab->root.dynobj = abfd;
8028 if (!create_got_section (htab->root.dynobj, info))
8029 return FALSE;
8031 break;
8033 case R_ARM_ABS12:
8034 /* VxWorks uses dynamic R_ARM_ABS12 relocations for
8035 ldr __GOTT_INDEX__ offsets. */
8036 if (!htab->vxworks_p)
8037 break;
8038 /* Fall through */
8040 case R_ARM_ABS32:
8041 case R_ARM_ABS32_NOI:
8042 case R_ARM_REL32:
8043 case R_ARM_REL32_NOI:
8044 case R_ARM_PC24:
8045 case R_ARM_PLT32:
8046 case R_ARM_CALL:
8047 case R_ARM_JUMP24:
8048 case R_ARM_PREL31:
8049 case R_ARM_THM_CALL:
8050 case R_ARM_MOVW_ABS_NC:
8051 case R_ARM_MOVT_ABS:
8052 case R_ARM_MOVW_PREL_NC:
8053 case R_ARM_MOVT_PREL:
8054 case R_ARM_THM_MOVW_ABS_NC:
8055 case R_ARM_THM_MOVT_ABS:
8056 case R_ARM_THM_MOVW_PREL_NC:
8057 case R_ARM_THM_MOVT_PREL:
8058 /* Should the interworking branches be listed here? */
8059 if (h != NULL)
8061 /* If this reloc is in a read-only section, we might
8062 need a copy reloc. We can't check reliably at this
8063 stage whether the section is read-only, as input
8064 sections have not yet been mapped to output sections.
8065 Tentatively set the flag for now, and correct in
8066 adjust_dynamic_symbol. */
8067 if (!info->shared)
8068 h->non_got_ref = 1;
8070 /* We may need a .plt entry if the function this reloc
8071 refers to is in a different object. We can't tell for
8072 sure yet, because something later might force the
8073 symbol local. */
8074 if (r_type != R_ARM_ABS32
8075 && r_type != R_ARM_REL32
8076 && r_type != R_ARM_ABS32_NOI
8077 && r_type != R_ARM_REL32_NOI
8078 && r_type != R_ARM_ABS12)
8079 h->needs_plt = 1;
8081 /* If we create a PLT entry, this relocation will reference
8082 it, even if it's an ABS32 relocation. */
8083 h->plt.refcount += 1;
8085 if (r_type == R_ARM_THM_CALL)
8086 eh->plt_thumb_refcount += 1;
8089 /* If we are creating a shared library or relocatable executable,
8090 and this is a reloc against a global symbol, or a non PC
8091 relative reloc against a local symbol, then we need to copy
8092 the reloc into the shared library. However, if we are linking
8093 with -Bsymbolic, we do not need to copy a reloc against a
8094 global symbol which is defined in an object we are
8095 including in the link (i.e., DEF_REGULAR is set). At
8096 this point we have not seen all the input files, so it is
8097 possible that DEF_REGULAR is not set now but will be set
8098 later (it is never cleared). We account for that
8099 possibility below by storing information in the
8100 relocs_copied field of the hash table entry. */
8101 if ((info->shared || htab->root.is_relocatable_executable)
8102 && (sec->flags & SEC_ALLOC) != 0
8103 && ((r_type == R_ARM_ABS32 || r_type == R_ARM_ABS32_NOI)
8104 || (h != NULL && ! h->needs_plt
8105 && (! info->symbolic || ! h->def_regular))))
8107 struct elf32_arm_relocs_copied *p, **head;
8109 /* When creating a shared object, we must copy these
8110 reloc types into the output file. We create a reloc
8111 section in dynobj and make room for this reloc. */
8112 if (sreloc == NULL)
8114 const char * name;
8116 name = (bfd_elf_string_from_elf_section
8117 (abfd,
8118 elf_elfheader (abfd)->e_shstrndx,
8119 elf_section_data (sec)->rel_hdr.sh_name));
8120 if (name == NULL)
8121 return FALSE;
8123 BFD_ASSERT (reloc_section_p (htab, name, sec));
8125 sreloc = bfd_get_section_by_name (dynobj, name);
8126 if (sreloc == NULL)
8128 flagword flags;
8130 flags = (SEC_HAS_CONTENTS | SEC_READONLY
8131 | SEC_IN_MEMORY | SEC_LINKER_CREATED);
8132 if ((sec->flags & SEC_ALLOC) != 0
8133 /* BPABI objects never have dynamic
8134 relocations mapped. */
8135 && !htab->symbian_p)
8136 flags |= SEC_ALLOC | SEC_LOAD;
8137 sreloc = bfd_make_section_with_flags (dynobj,
8138 name,
8139 flags);
8140 if (sreloc == NULL
8141 || ! bfd_set_section_alignment (dynobj, sreloc, 2))
8142 return FALSE;
8145 elf_section_data (sec)->sreloc = sreloc;
8148 /* If this is a global symbol, we count the number of
8149 relocations we need for this symbol. */
8150 if (h != NULL)
8152 head = &((struct elf32_arm_link_hash_entry *) h)->relocs_copied;
8154 else
8156 /* Track dynamic relocs needed for local syms too.
8157 We really need local syms available to do this
8158 easily. Oh well. */
8160 asection *s;
8161 void *vpp;
8163 s = bfd_section_from_r_symndx (abfd, &htab->sym_sec,
8164 sec, r_symndx);
8165 if (s == NULL)
8166 return FALSE;
8168 vpp = &elf_section_data (s)->local_dynrel;
8169 head = (struct elf32_arm_relocs_copied **) vpp;
8172 p = *head;
8173 if (p == NULL || p->section != sec)
8175 bfd_size_type amt = sizeof *p;
8177 p = bfd_alloc (htab->root.dynobj, amt);
8178 if (p == NULL)
8179 return FALSE;
8180 p->next = *head;
8181 *head = p;
8182 p->section = sec;
8183 p->count = 0;
8184 p->pc_count = 0;
8187 if (r_type == R_ARM_REL32 || r_type == R_ARM_REL32_NOI)
8188 p->pc_count += 1;
8189 p->count += 1;
8191 break;
8193 /* This relocation describes the C++ object vtable hierarchy.
8194 Reconstruct it for later use during GC. */
8195 case R_ARM_GNU_VTINHERIT:
8196 if (!bfd_elf_gc_record_vtinherit (abfd, sec, h, rel->r_offset))
8197 return FALSE;
8198 break;
8200 /* This relocation describes which C++ vtable entries are actually
8201 used. Record for later use during GC. */
8202 case R_ARM_GNU_VTENTRY:
8203 if (!bfd_elf_gc_record_vtentry (abfd, sec, h, rel->r_offset))
8204 return FALSE;
8205 break;
8209 return TRUE;
8212 /* Unwinding tables are not referenced directly. This pass marks them as
8213 required if the corresponding code section is marked. */
8215 static bfd_boolean
8216 elf32_arm_gc_mark_extra_sections(struct bfd_link_info *info,
8217 elf_gc_mark_hook_fn gc_mark_hook)
8219 bfd *sub;
8220 Elf_Internal_Shdr **elf_shdrp;
8221 bfd_boolean again;
8223 /* Marking EH data may cause additional code sections to be marked,
8224 requiring multiple passes. */
8225 again = TRUE;
8226 while (again)
8228 again = FALSE;
8229 for (sub = info->input_bfds; sub != NULL; sub = sub->link_next)
8231 asection *o;
8233 if (bfd_get_flavour (sub) != bfd_target_elf_flavour)
8234 continue;
8236 elf_shdrp = elf_elfsections (sub);
8237 for (o = sub->sections; o != NULL; o = o->next)
8239 Elf_Internal_Shdr *hdr;
8240 hdr = &elf_section_data (o)->this_hdr;
8241 if (hdr->sh_type == SHT_ARM_EXIDX && hdr->sh_link
8242 && !o->gc_mark
8243 && elf_shdrp[hdr->sh_link]->bfd_section->gc_mark)
8245 again = TRUE;
8246 if (!_bfd_elf_gc_mark (info, o, gc_mark_hook))
8247 return FALSE;
8253 return TRUE;
8256 /* Treat mapping symbols as special target symbols. */
8258 static bfd_boolean
8259 elf32_arm_is_target_special_symbol (bfd * abfd ATTRIBUTE_UNUSED, asymbol * sym)
8261 return bfd_is_arm_special_symbol_name (sym->name,
8262 BFD_ARM_SPECIAL_SYM_TYPE_ANY);
8265 /* This is a copy of elf_find_function() from elf.c except that
8266 ARM mapping symbols are ignored when looking for function names
8267 and STT_ARM_TFUNC is considered to a function type. */
8269 static bfd_boolean
8270 arm_elf_find_function (bfd * abfd ATTRIBUTE_UNUSED,
8271 asection * section,
8272 asymbol ** symbols,
8273 bfd_vma offset,
8274 const char ** filename_ptr,
8275 const char ** functionname_ptr)
8277 const char * filename = NULL;
8278 asymbol * func = NULL;
8279 bfd_vma low_func = 0;
8280 asymbol ** p;
8282 for (p = symbols; *p != NULL; p++)
8284 elf_symbol_type *q;
8286 q = (elf_symbol_type *) *p;
8288 switch (ELF_ST_TYPE (q->internal_elf_sym.st_info))
8290 default:
8291 break;
8292 case STT_FILE:
8293 filename = bfd_asymbol_name (&q->symbol);
8294 break;
8295 case STT_FUNC:
8296 case STT_ARM_TFUNC:
8297 case STT_NOTYPE:
8298 /* Skip mapping symbols. */
8299 if ((q->symbol.flags & BSF_LOCAL)
8300 && bfd_is_arm_special_symbol_name (q->symbol.name,
8301 BFD_ARM_SPECIAL_SYM_TYPE_ANY))
8302 continue;
8303 /* Fall through. */
8304 if (bfd_get_section (&q->symbol) == section
8305 && q->symbol.value >= low_func
8306 && q->symbol.value <= offset)
8308 func = (asymbol *) q;
8309 low_func = q->symbol.value;
8311 break;
8315 if (func == NULL)
8316 return FALSE;
8318 if (filename_ptr)
8319 *filename_ptr = filename;
8320 if (functionname_ptr)
8321 *functionname_ptr = bfd_asymbol_name (func);
8323 return TRUE;
8327 /* Find the nearest line to a particular section and offset, for error
8328 reporting. This code is a duplicate of the code in elf.c, except
8329 that it uses arm_elf_find_function. */
8331 static bfd_boolean
8332 elf32_arm_find_nearest_line (bfd * abfd,
8333 asection * section,
8334 asymbol ** symbols,
8335 bfd_vma offset,
8336 const char ** filename_ptr,
8337 const char ** functionname_ptr,
8338 unsigned int * line_ptr)
8340 bfd_boolean found = FALSE;
8342 /* We skip _bfd_dwarf1_find_nearest_line since no known ARM toolchain uses it. */
8344 if (_bfd_dwarf2_find_nearest_line (abfd, section, symbols, offset,
8345 filename_ptr, functionname_ptr,
8346 line_ptr, 0,
8347 & elf_tdata (abfd)->dwarf2_find_line_info))
8349 if (!*functionname_ptr)
8350 arm_elf_find_function (abfd, section, symbols, offset,
8351 *filename_ptr ? NULL : filename_ptr,
8352 functionname_ptr);
8354 return TRUE;
8357 if (! _bfd_stab_section_find_nearest_line (abfd, symbols, section, offset,
8358 & found, filename_ptr,
8359 functionname_ptr, line_ptr,
8360 & elf_tdata (abfd)->line_info))
8361 return FALSE;
8363 if (found && (*functionname_ptr || *line_ptr))
8364 return TRUE;
8366 if (symbols == NULL)
8367 return FALSE;
8369 if (! arm_elf_find_function (abfd, section, symbols, offset,
8370 filename_ptr, functionname_ptr))
8371 return FALSE;
8373 *line_ptr = 0;
8374 return TRUE;
8377 static bfd_boolean
8378 elf32_arm_find_inliner_info (bfd * abfd,
8379 const char ** filename_ptr,
8380 const char ** functionname_ptr,
8381 unsigned int * line_ptr)
8383 bfd_boolean found;
8384 found = _bfd_dwarf2_find_inliner_info (abfd, filename_ptr,
8385 functionname_ptr, line_ptr,
8386 & elf_tdata (abfd)->dwarf2_find_line_info);
8387 return found;
8390 /* Adjust a symbol defined by a dynamic object and referenced by a
8391 regular object. The current definition is in some section of the
8392 dynamic object, but we're not including those sections. We have to
8393 change the definition to something the rest of the link can
8394 understand. */
8396 static bfd_boolean
8397 elf32_arm_adjust_dynamic_symbol (struct bfd_link_info * info,
8398 struct elf_link_hash_entry * h)
8400 bfd * dynobj;
8401 asection * s;
8402 struct elf32_arm_link_hash_entry * eh;
8403 struct elf32_arm_link_hash_table *globals;
8405 globals = elf32_arm_hash_table (info);
8406 dynobj = elf_hash_table (info)->dynobj;
8408 /* Make sure we know what is going on here. */
8409 BFD_ASSERT (dynobj != NULL
8410 && (h->needs_plt
8411 || h->u.weakdef != NULL
8412 || (h->def_dynamic
8413 && h->ref_regular
8414 && !h->def_regular)));
8416 eh = (struct elf32_arm_link_hash_entry *) h;
8418 /* If this is a function, put it in the procedure linkage table. We
8419 will fill in the contents of the procedure linkage table later,
8420 when we know the address of the .got section. */
8421 if (h->type == STT_FUNC || h->type == STT_ARM_TFUNC
8422 || h->needs_plt)
8424 if (h->plt.refcount <= 0
8425 || SYMBOL_CALLS_LOCAL (info, h)
8426 || (ELF_ST_VISIBILITY (h->other) != STV_DEFAULT
8427 && h->root.type == bfd_link_hash_undefweak))
8429 /* This case can occur if we saw a PLT32 reloc in an input
8430 file, but the symbol was never referred to by a dynamic
8431 object, or if all references were garbage collected. In
8432 such a case, we don't actually need to build a procedure
8433 linkage table, and we can just do a PC24 reloc instead. */
8434 h->plt.offset = (bfd_vma) -1;
8435 eh->plt_thumb_refcount = 0;
8436 h->needs_plt = 0;
8439 return TRUE;
8441 else
8443 /* It's possible that we incorrectly decided a .plt reloc was
8444 needed for an R_ARM_PC24 or similar reloc to a non-function sym
8445 in check_relocs. We can't decide accurately between function
8446 and non-function syms in check-relocs; Objects loaded later in
8447 the link may change h->type. So fix it now. */
8448 h->plt.offset = (bfd_vma) -1;
8449 eh->plt_thumb_refcount = 0;
8452 /* If this is a weak symbol, and there is a real definition, the
8453 processor independent code will have arranged for us to see the
8454 real definition first, and we can just use the same value. */
8455 if (h->u.weakdef != NULL)
8457 BFD_ASSERT (h->u.weakdef->root.type == bfd_link_hash_defined
8458 || h->u.weakdef->root.type == bfd_link_hash_defweak);
8459 h->root.u.def.section = h->u.weakdef->root.u.def.section;
8460 h->root.u.def.value = h->u.weakdef->root.u.def.value;
8461 return TRUE;
8464 /* If there are no non-GOT references, we do not need a copy
8465 relocation. */
8466 if (!h->non_got_ref)
8467 return TRUE;
8469 /* This is a reference to a symbol defined by a dynamic object which
8470 is not a function. */
8472 /* If we are creating a shared library, we must presume that the
8473 only references to the symbol are via the global offset table.
8474 For such cases we need not do anything here; the relocations will
8475 be handled correctly by relocate_section. Relocatable executables
8476 can reference data in shared objects directly, so we don't need to
8477 do anything here. */
8478 if (info->shared || globals->root.is_relocatable_executable)
8479 return TRUE;
8481 if (h->size == 0)
8483 (*_bfd_error_handler) (_("dynamic variable `%s' is zero size"),
8484 h->root.root.string);
8485 return TRUE;
8488 /* We must allocate the symbol in our .dynbss section, which will
8489 become part of the .bss section of the executable. There will be
8490 an entry for this symbol in the .dynsym section. The dynamic
8491 object will contain position independent code, so all references
8492 from the dynamic object to this symbol will go through the global
8493 offset table. The dynamic linker will use the .dynsym entry to
8494 determine the address it must put in the global offset table, so
8495 both the dynamic object and the regular object will refer to the
8496 same memory location for the variable. */
8497 s = bfd_get_section_by_name (dynobj, ".dynbss");
8498 BFD_ASSERT (s != NULL);
8500 /* We must generate a R_ARM_COPY reloc to tell the dynamic linker to
8501 copy the initial value out of the dynamic object and into the
8502 runtime process image. We need to remember the offset into the
8503 .rel(a).bss section we are going to use. */
8504 if ((h->root.u.def.section->flags & SEC_ALLOC) != 0)
8506 asection *srel;
8508 srel = bfd_get_section_by_name (dynobj, RELOC_SECTION (globals, ".bss"));
8509 BFD_ASSERT (srel != NULL);
8510 srel->size += RELOC_SIZE (globals);
8511 h->needs_copy = 1;
8514 return _bfd_elf_adjust_dynamic_copy (h, s);
8517 /* Allocate space in .plt, .got and associated reloc sections for
8518 dynamic relocs. */
8520 static bfd_boolean
8521 allocate_dynrelocs (struct elf_link_hash_entry *h, void * inf)
8523 struct bfd_link_info *info;
8524 struct elf32_arm_link_hash_table *htab;
8525 struct elf32_arm_link_hash_entry *eh;
8526 struct elf32_arm_relocs_copied *p;
8528 eh = (struct elf32_arm_link_hash_entry *) h;
8530 if (h->root.type == bfd_link_hash_indirect)
8531 return TRUE;
8533 if (h->root.type == bfd_link_hash_warning)
8534 /* When warning symbols are created, they **replace** the "real"
8535 entry in the hash table, thus we never get to see the real
8536 symbol in a hash traversal. So look at it now. */
8537 h = (struct elf_link_hash_entry *) h->root.u.i.link;
8539 info = (struct bfd_link_info *) inf;
8540 htab = elf32_arm_hash_table (info);
8542 if (htab->root.dynamic_sections_created
8543 && h->plt.refcount > 0)
8545 /* Make sure this symbol is output as a dynamic symbol.
8546 Undefined weak syms won't yet be marked as dynamic. */
8547 if (h->dynindx == -1
8548 && !h->forced_local)
8550 if (! bfd_elf_link_record_dynamic_symbol (info, h))
8551 return FALSE;
8554 if (info->shared
8555 || WILL_CALL_FINISH_DYNAMIC_SYMBOL (1, 0, h))
8557 asection *s = htab->splt;
8559 /* If this is the first .plt entry, make room for the special
8560 first entry. */
8561 if (s->size == 0)
8562 s->size += htab->plt_header_size;
8564 h->plt.offset = s->size;
8566 /* If we will insert a Thumb trampoline before this PLT, leave room
8567 for it. */
8568 if (!htab->use_blx && eh->plt_thumb_refcount > 0)
8570 h->plt.offset += PLT_THUMB_STUB_SIZE;
8571 s->size += PLT_THUMB_STUB_SIZE;
8574 /* If this symbol is not defined in a regular file, and we are
8575 not generating a shared library, then set the symbol to this
8576 location in the .plt. This is required to make function
8577 pointers compare as equal between the normal executable and
8578 the shared library. */
8579 if (! info->shared
8580 && !h->def_regular)
8582 h->root.u.def.section = s;
8583 h->root.u.def.value = h->plt.offset;
8585 /* Make sure the function is not marked as Thumb, in case
8586 it is the target of an ABS32 relocation, which will
8587 point to the PLT entry. */
8588 if (ELF_ST_TYPE (h->type) == STT_ARM_TFUNC)
8589 h->type = ELF_ST_INFO (ELF_ST_BIND (h->type), STT_FUNC);
8592 /* Make room for this entry. */
8593 s->size += htab->plt_entry_size;
8595 if (!htab->symbian_p)
8597 /* We also need to make an entry in the .got.plt section, which
8598 will be placed in the .got section by the linker script. */
8599 eh->plt_got_offset = htab->sgotplt->size;
8600 htab->sgotplt->size += 4;
8603 /* We also need to make an entry in the .rel(a).plt section. */
8604 htab->srelplt->size += RELOC_SIZE (htab);
8606 /* VxWorks executables have a second set of relocations for
8607 each PLT entry. They go in a separate relocation section,
8608 which is processed by the kernel loader. */
8609 if (htab->vxworks_p && !info->shared)
8611 /* There is a relocation for the initial PLT entry:
8612 an R_ARM_32 relocation for _GLOBAL_OFFSET_TABLE_. */
8613 if (h->plt.offset == htab->plt_header_size)
8614 htab->srelplt2->size += RELOC_SIZE (htab);
8616 /* There are two extra relocations for each subsequent
8617 PLT entry: an R_ARM_32 relocation for the GOT entry,
8618 and an R_ARM_32 relocation for the PLT entry. */
8619 htab->srelplt2->size += RELOC_SIZE (htab) * 2;
8622 else
8624 h->plt.offset = (bfd_vma) -1;
8625 h->needs_plt = 0;
8628 else
8630 h->plt.offset = (bfd_vma) -1;
8631 h->needs_plt = 0;
8634 if (h->got.refcount > 0)
8636 asection *s;
8637 bfd_boolean dyn;
8638 int tls_type = elf32_arm_hash_entry (h)->tls_type;
8639 int indx;
8641 /* Make sure this symbol is output as a dynamic symbol.
8642 Undefined weak syms won't yet be marked as dynamic. */
8643 if (h->dynindx == -1
8644 && !h->forced_local)
8646 if (! bfd_elf_link_record_dynamic_symbol (info, h))
8647 return FALSE;
8650 if (!htab->symbian_p)
8652 s = htab->sgot;
8653 h->got.offset = s->size;
8655 if (tls_type == GOT_UNKNOWN)
8656 abort ();
8658 if (tls_type == GOT_NORMAL)
8659 /* Non-TLS symbols need one GOT slot. */
8660 s->size += 4;
8661 else
8663 if (tls_type & GOT_TLS_GD)
8664 /* R_ARM_TLS_GD32 needs 2 consecutive GOT slots. */
8665 s->size += 8;
8666 if (tls_type & GOT_TLS_IE)
8667 /* R_ARM_TLS_IE32 needs one GOT slot. */
8668 s->size += 4;
8671 dyn = htab->root.dynamic_sections_created;
8673 indx = 0;
8674 if (WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn, info->shared, h)
8675 && (!info->shared
8676 || !SYMBOL_REFERENCES_LOCAL (info, h)))
8677 indx = h->dynindx;
8679 if (tls_type != GOT_NORMAL
8680 && (info->shared || indx != 0)
8681 && (ELF_ST_VISIBILITY (h->other) == STV_DEFAULT
8682 || h->root.type != bfd_link_hash_undefweak))
8684 if (tls_type & GOT_TLS_IE)
8685 htab->srelgot->size += RELOC_SIZE (htab);
8687 if (tls_type & GOT_TLS_GD)
8688 htab->srelgot->size += RELOC_SIZE (htab);
8690 if ((tls_type & GOT_TLS_GD) && indx != 0)
8691 htab->srelgot->size += RELOC_SIZE (htab);
8693 else if ((ELF_ST_VISIBILITY (h->other) == STV_DEFAULT
8694 || h->root.type != bfd_link_hash_undefweak)
8695 && (info->shared
8696 || WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn, 0, h)))
8697 htab->srelgot->size += RELOC_SIZE (htab);
8700 else
8701 h->got.offset = (bfd_vma) -1;
8703 /* Allocate stubs for exported Thumb functions on v4t. */
8704 if (!htab->use_blx && h->dynindx != -1
8705 && h->def_regular
8706 && ELF_ST_TYPE (h->type) == STT_ARM_TFUNC
8707 && ELF_ST_VISIBILITY (h->other) == STV_DEFAULT)
8709 struct elf_link_hash_entry * th;
8710 struct bfd_link_hash_entry * bh;
8711 struct elf_link_hash_entry * myh;
8712 char name[1024];
8713 asection *s;
8714 bh = NULL;
8715 /* Create a new symbol to regist the real location of the function. */
8716 s = h->root.u.def.section;
8717 sprintf(name, "__real_%s", h->root.root.string);
8718 _bfd_generic_link_add_one_symbol (info, s->owner,
8719 name, BSF_GLOBAL, s,
8720 h->root.u.def.value,
8721 NULL, TRUE, FALSE, &bh);
8723 myh = (struct elf_link_hash_entry *) bh;
8724 myh->type = ELF_ST_INFO (STB_LOCAL, STT_ARM_TFUNC);
8725 myh->forced_local = 1;
8726 eh->export_glue = myh;
8727 th = record_arm_to_thumb_glue (info, h);
8728 /* Point the symbol at the stub. */
8729 h->type = ELF_ST_INFO (ELF_ST_BIND (h->type), STT_FUNC);
8730 h->root.u.def.section = th->root.u.def.section;
8731 h->root.u.def.value = th->root.u.def.value & ~1;
8734 if (eh->relocs_copied == NULL)
8735 return TRUE;
8737 /* In the shared -Bsymbolic case, discard space allocated for
8738 dynamic pc-relative relocs against symbols which turn out to be
8739 defined in regular objects. For the normal shared case, discard
8740 space for pc-relative relocs that have become local due to symbol
8741 visibility changes. */
8743 if (info->shared || htab->root.is_relocatable_executable)
8745 /* The only relocs that use pc_count are R_ARM_REL32 and
8746 R_ARM_REL32_NOI, which will appear on something like
8747 ".long foo - .". We want calls to protected symbols to resolve
8748 directly to the function rather than going via the plt. If people
8749 want function pointer comparisons to work as expected then they
8750 should avoid writing assembly like ".long foo - .". */
8751 if (SYMBOL_CALLS_LOCAL (info, h))
8753 struct elf32_arm_relocs_copied **pp;
8755 for (pp = &eh->relocs_copied; (p = *pp) != NULL; )
8757 p->count -= p->pc_count;
8758 p->pc_count = 0;
8759 if (p->count == 0)
8760 *pp = p->next;
8761 else
8762 pp = &p->next;
8766 /* Also discard relocs on undefined weak syms with non-default
8767 visibility. */
8768 if (eh->relocs_copied != NULL
8769 && h->root.type == bfd_link_hash_undefweak)
8771 if (ELF_ST_VISIBILITY (h->other) != STV_DEFAULT)
8772 eh->relocs_copied = NULL;
8774 /* Make sure undefined weak symbols are output as a dynamic
8775 symbol in PIEs. */
8776 else if (h->dynindx == -1
8777 && !h->forced_local)
8779 if (! bfd_elf_link_record_dynamic_symbol (info, h))
8780 return FALSE;
8784 else if (htab->root.is_relocatable_executable && h->dynindx == -1
8785 && h->root.type == bfd_link_hash_new)
8787 /* Output absolute symbols so that we can create relocations
8788 against them. For normal symbols we output a relocation
8789 against the section that contains them. */
8790 if (! bfd_elf_link_record_dynamic_symbol (info, h))
8791 return FALSE;
8795 else
8797 /* For the non-shared case, discard space for relocs against
8798 symbols which turn out to need copy relocs or are not
8799 dynamic. */
8801 if (!h->non_got_ref
8802 && ((h->def_dynamic
8803 && !h->def_regular)
8804 || (htab->root.dynamic_sections_created
8805 && (h->root.type == bfd_link_hash_undefweak
8806 || h->root.type == bfd_link_hash_undefined))))
8808 /* Make sure this symbol is output as a dynamic symbol.
8809 Undefined weak syms won't yet be marked as dynamic. */
8810 if (h->dynindx == -1
8811 && !h->forced_local)
8813 if (! bfd_elf_link_record_dynamic_symbol (info, h))
8814 return FALSE;
8817 /* If that succeeded, we know we'll be keeping all the
8818 relocs. */
8819 if (h->dynindx != -1)
8820 goto keep;
8823 eh->relocs_copied = NULL;
8825 keep: ;
8828 /* Finally, allocate space. */
8829 for (p = eh->relocs_copied; p != NULL; p = p->next)
8831 asection *sreloc = elf_section_data (p->section)->sreloc;
8832 sreloc->size += p->count * RELOC_SIZE (htab);
8835 return TRUE;
8838 /* Find any dynamic relocs that apply to read-only sections. */
8840 static bfd_boolean
8841 elf32_arm_readonly_dynrelocs (struct elf_link_hash_entry *h, PTR inf)
8843 struct elf32_arm_link_hash_entry *eh;
8844 struct elf32_arm_relocs_copied *p;
8846 if (h->root.type == bfd_link_hash_warning)
8847 h = (struct elf_link_hash_entry *) h->root.u.i.link;
8849 eh = (struct elf32_arm_link_hash_entry *) h;
8850 for (p = eh->relocs_copied; p != NULL; p = p->next)
8852 asection *s = p->section;
8854 if (s != NULL && (s->flags & SEC_READONLY) != 0)
8856 struct bfd_link_info *info = (struct bfd_link_info *) inf;
8858 info->flags |= DF_TEXTREL;
8860 /* Not an error, just cut short the traversal. */
8861 return FALSE;
8864 return TRUE;
8867 void
8868 bfd_elf32_arm_set_byteswap_code (struct bfd_link_info *info,
8869 int byteswap_code)
8871 struct elf32_arm_link_hash_table *globals;
8873 globals = elf32_arm_hash_table (info);
8874 globals->byteswap_code = byteswap_code;
8877 /* Set the sizes of the dynamic sections. */
8879 static bfd_boolean
8880 elf32_arm_size_dynamic_sections (bfd * output_bfd ATTRIBUTE_UNUSED,
8881 struct bfd_link_info * info)
8883 bfd * dynobj;
8884 asection * s;
8885 bfd_boolean plt;
8886 bfd_boolean relocs;
8887 bfd *ibfd;
8888 struct elf32_arm_link_hash_table *htab;
8890 htab = elf32_arm_hash_table (info);
8891 dynobj = elf_hash_table (info)->dynobj;
8892 BFD_ASSERT (dynobj != NULL);
8893 check_use_blx (htab);
8895 if (elf_hash_table (info)->dynamic_sections_created)
8897 /* Set the contents of the .interp section to the interpreter. */
8898 if (info->executable)
8900 s = bfd_get_section_by_name (dynobj, ".interp");
8901 BFD_ASSERT (s != NULL);
8902 s->size = sizeof ELF_DYNAMIC_INTERPRETER;
8903 s->contents = (unsigned char *) ELF_DYNAMIC_INTERPRETER;
8907 /* Set up .got offsets for local syms, and space for local dynamic
8908 relocs. */
8909 for (ibfd = info->input_bfds; ibfd != NULL; ibfd = ibfd->link_next)
8911 bfd_signed_vma *local_got;
8912 bfd_signed_vma *end_local_got;
8913 char *local_tls_type;
8914 bfd_size_type locsymcount;
8915 Elf_Internal_Shdr *symtab_hdr;
8916 asection *srel;
8918 if (bfd_get_flavour (ibfd) != bfd_target_elf_flavour)
8919 continue;
8921 for (s = ibfd->sections; s != NULL; s = s->next)
8923 struct elf32_arm_relocs_copied *p;
8925 for (p = elf_section_data (s)->local_dynrel; p != NULL; p = p->next)
8927 if (!bfd_is_abs_section (p->section)
8928 && bfd_is_abs_section (p->section->output_section))
8930 /* Input section has been discarded, either because
8931 it is a copy of a linkonce section or due to
8932 linker script /DISCARD/, so we'll be discarding
8933 the relocs too. */
8935 else if (p->count != 0)
8937 srel = elf_section_data (p->section)->sreloc;
8938 srel->size += p->count * RELOC_SIZE (htab);
8939 if ((p->section->output_section->flags & SEC_READONLY) != 0)
8940 info->flags |= DF_TEXTREL;
8945 local_got = elf_local_got_refcounts (ibfd);
8946 if (!local_got)
8947 continue;
8949 symtab_hdr = &elf_tdata (ibfd)->symtab_hdr;
8950 locsymcount = symtab_hdr->sh_info;
8951 end_local_got = local_got + locsymcount;
8952 local_tls_type = elf32_arm_local_got_tls_type (ibfd);
8953 s = htab->sgot;
8954 srel = htab->srelgot;
8955 for (; local_got < end_local_got; ++local_got, ++local_tls_type)
8957 if (*local_got > 0)
8959 *local_got = s->size;
8960 if (*local_tls_type & GOT_TLS_GD)
8961 /* TLS_GD relocs need an 8-byte structure in the GOT. */
8962 s->size += 8;
8963 if (*local_tls_type & GOT_TLS_IE)
8964 s->size += 4;
8965 if (*local_tls_type == GOT_NORMAL)
8966 s->size += 4;
8968 if (info->shared || *local_tls_type == GOT_TLS_GD)
8969 srel->size += RELOC_SIZE (htab);
8971 else
8972 *local_got = (bfd_vma) -1;
8976 if (htab->tls_ldm_got.refcount > 0)
8978 /* Allocate two GOT entries and one dynamic relocation (if necessary)
8979 for R_ARM_TLS_LDM32 relocations. */
8980 htab->tls_ldm_got.offset = htab->sgot->size;
8981 htab->sgot->size += 8;
8982 if (info->shared)
8983 htab->srelgot->size += RELOC_SIZE (htab);
8985 else
8986 htab->tls_ldm_got.offset = -1;
8988 /* Allocate global sym .plt and .got entries, and space for global
8989 sym dynamic relocs. */
8990 elf_link_hash_traverse (& htab->root, allocate_dynrelocs, info);
8992 /* Here we rummage through the found bfds to collect glue information. */
8993 for (ibfd = info->input_bfds; ibfd != NULL; ibfd = ibfd->link_next)
8995 /* Initialise mapping tables for code/data. */
8996 bfd_elf32_arm_init_maps (ibfd);
8998 if (!bfd_elf32_arm_process_before_allocation (ibfd, info)
8999 || !bfd_elf32_arm_vfp11_erratum_scan (ibfd, info))
9000 /* xgettext:c-format */
9001 _bfd_error_handler (_("Errors encountered processing file %s"),
9002 ibfd->filename);
9005 /* The check_relocs and adjust_dynamic_symbol entry points have
9006 determined the sizes of the various dynamic sections. Allocate
9007 memory for them. */
9008 plt = FALSE;
9009 relocs = FALSE;
9010 for (s = dynobj->sections; s != NULL; s = s->next)
9012 const char * name;
9014 if ((s->flags & SEC_LINKER_CREATED) == 0)
9015 continue;
9017 /* It's OK to base decisions on the section name, because none
9018 of the dynobj section names depend upon the input files. */
9019 name = bfd_get_section_name (dynobj, s);
9021 if (strcmp (name, ".plt") == 0)
9023 /* Remember whether there is a PLT. */
9024 plt = s->size != 0;
9026 else if (CONST_STRNEQ (name, ".rel"))
9028 if (s->size != 0)
9030 /* Remember whether there are any reloc sections other
9031 than .rel(a).plt and .rela.plt.unloaded. */
9032 if (s != htab->srelplt && s != htab->srelplt2)
9033 relocs = TRUE;
9035 /* We use the reloc_count field as a counter if we need
9036 to copy relocs into the output file. */
9037 s->reloc_count = 0;
9040 else if (! CONST_STRNEQ (name, ".got")
9041 && strcmp (name, ".dynbss") != 0)
9043 /* It's not one of our sections, so don't allocate space. */
9044 continue;
9047 if (s->size == 0)
9049 /* If we don't need this section, strip it from the
9050 output file. This is mostly to handle .rel(a).bss and
9051 .rel(a).plt. We must create both sections in
9052 create_dynamic_sections, because they must be created
9053 before the linker maps input sections to output
9054 sections. The linker does that before
9055 adjust_dynamic_symbol is called, and it is that
9056 function which decides whether anything needs to go
9057 into these sections. */
9058 s->flags |= SEC_EXCLUDE;
9059 continue;
9062 if ((s->flags & SEC_HAS_CONTENTS) == 0)
9063 continue;
9065 /* Allocate memory for the section contents. */
9066 s->contents = (bfd_byte *) bfd_zalloc (dynobj, s->size);
9067 if (s->contents == NULL)
9068 return FALSE;
9071 if (elf_hash_table (info)->dynamic_sections_created)
9073 /* Add some entries to the .dynamic section. We fill in the
9074 values later, in elf32_arm_finish_dynamic_sections, but we
9075 must add the entries now so that we get the correct size for
9076 the .dynamic section. The DT_DEBUG entry is filled in by the
9077 dynamic linker and used by the debugger. */
9078 #define add_dynamic_entry(TAG, VAL) \
9079 _bfd_elf_add_dynamic_entry (info, TAG, VAL)
9081 if (info->executable)
9083 if (!add_dynamic_entry (DT_DEBUG, 0))
9084 return FALSE;
9087 if (plt)
9089 if ( !add_dynamic_entry (DT_PLTGOT, 0)
9090 || !add_dynamic_entry (DT_PLTRELSZ, 0)
9091 || !add_dynamic_entry (DT_PLTREL,
9092 htab->use_rel ? DT_REL : DT_RELA)
9093 || !add_dynamic_entry (DT_JMPREL, 0))
9094 return FALSE;
9097 if (relocs)
9099 if (htab->use_rel)
9101 if (!add_dynamic_entry (DT_REL, 0)
9102 || !add_dynamic_entry (DT_RELSZ, 0)
9103 || !add_dynamic_entry (DT_RELENT, RELOC_SIZE (htab)))
9104 return FALSE;
9106 else
9108 if (!add_dynamic_entry (DT_RELA, 0)
9109 || !add_dynamic_entry (DT_RELASZ, 0)
9110 || !add_dynamic_entry (DT_RELAENT, RELOC_SIZE (htab)))
9111 return FALSE;
9115 /* If any dynamic relocs apply to a read-only section,
9116 then we need a DT_TEXTREL entry. */
9117 if ((info->flags & DF_TEXTREL) == 0)
9118 elf_link_hash_traverse (&htab->root, elf32_arm_readonly_dynrelocs,
9119 (PTR) info);
9121 if ((info->flags & DF_TEXTREL) != 0)
9123 if (!add_dynamic_entry (DT_TEXTREL, 0))
9124 return FALSE;
9127 #undef add_dynamic_entry
9129 return TRUE;
9132 /* Finish up dynamic symbol handling. We set the contents of various
9133 dynamic sections here. */
9135 static bfd_boolean
9136 elf32_arm_finish_dynamic_symbol (bfd * output_bfd, struct bfd_link_info * info,
9137 struct elf_link_hash_entry * h, Elf_Internal_Sym * sym)
9139 bfd * dynobj;
9140 struct elf32_arm_link_hash_table *htab;
9141 struct elf32_arm_link_hash_entry *eh;
9143 dynobj = elf_hash_table (info)->dynobj;
9144 htab = elf32_arm_hash_table (info);
9145 eh = (struct elf32_arm_link_hash_entry *) h;
9147 if (h->plt.offset != (bfd_vma) -1)
9149 asection * splt;
9150 asection * srel;
9151 bfd_byte *loc;
9152 bfd_vma plt_index;
9153 Elf_Internal_Rela rel;
9155 /* This symbol has an entry in the procedure linkage table. Set
9156 it up. */
9158 BFD_ASSERT (h->dynindx != -1);
9160 splt = bfd_get_section_by_name (dynobj, ".plt");
9161 srel = bfd_get_section_by_name (dynobj, RELOC_SECTION (htab, ".plt"));
9162 BFD_ASSERT (splt != NULL && srel != NULL);
9164 /* Fill in the entry in the procedure linkage table. */
9165 if (htab->symbian_p)
9167 put_arm_insn (htab, output_bfd,
9168 elf32_arm_symbian_plt_entry[0],
9169 splt->contents + h->plt.offset);
9170 bfd_put_32 (output_bfd,
9171 elf32_arm_symbian_plt_entry[1],
9172 splt->contents + h->plt.offset + 4);
9174 /* Fill in the entry in the .rel.plt section. */
9175 rel.r_offset = (splt->output_section->vma
9176 + splt->output_offset
9177 + h->plt.offset + 4);
9178 rel.r_info = ELF32_R_INFO (h->dynindx, R_ARM_GLOB_DAT);
9180 /* Get the index in the procedure linkage table which
9181 corresponds to this symbol. This is the index of this symbol
9182 in all the symbols for which we are making plt entries. The
9183 first entry in the procedure linkage table is reserved. */
9184 plt_index = ((h->plt.offset - htab->plt_header_size)
9185 / htab->plt_entry_size);
9187 else
9189 bfd_vma got_offset, got_address, plt_address;
9190 bfd_vma got_displacement;
9191 asection * sgot;
9192 bfd_byte * ptr;
9194 sgot = bfd_get_section_by_name (dynobj, ".got.plt");
9195 BFD_ASSERT (sgot != NULL);
9197 /* Get the offset into the .got.plt table of the entry that
9198 corresponds to this function. */
9199 got_offset = eh->plt_got_offset;
9201 /* Get the index in the procedure linkage table which
9202 corresponds to this symbol. This is the index of this symbol
9203 in all the symbols for which we are making plt entries. The
9204 first three entries in .got.plt are reserved; after that
9205 symbols appear in the same order as in .plt. */
9206 plt_index = (got_offset - 12) / 4;
9208 /* Calculate the address of the GOT entry. */
9209 got_address = (sgot->output_section->vma
9210 + sgot->output_offset
9211 + got_offset);
9213 /* ...and the address of the PLT entry. */
9214 plt_address = (splt->output_section->vma
9215 + splt->output_offset
9216 + h->plt.offset);
9218 ptr = htab->splt->contents + h->plt.offset;
9219 if (htab->vxworks_p && info->shared)
9221 unsigned int i;
9222 bfd_vma val;
9224 for (i = 0; i != htab->plt_entry_size / 4; i++, ptr += 4)
9226 val = elf32_arm_vxworks_shared_plt_entry[i];
9227 if (i == 2)
9228 val |= got_address - sgot->output_section->vma;
9229 if (i == 5)
9230 val |= plt_index * RELOC_SIZE (htab);
9231 if (i == 2 || i == 5)
9232 bfd_put_32 (output_bfd, val, ptr);
9233 else
9234 put_arm_insn (htab, output_bfd, val, ptr);
9237 else if (htab->vxworks_p)
9239 unsigned int i;
9240 bfd_vma val;
9242 for (i = 0; i != htab->plt_entry_size / 4; i++, ptr += 4)
9244 val = elf32_arm_vxworks_exec_plt_entry[i];
9245 if (i == 2)
9246 val |= got_address;
9247 if (i == 4)
9248 val |= 0xffffff & -((h->plt.offset + i * 4 + 8) >> 2);
9249 if (i == 5)
9250 val |= plt_index * RELOC_SIZE (htab);
9251 if (i == 2 || i == 5)
9252 bfd_put_32 (output_bfd, val, ptr);
9253 else
9254 put_arm_insn (htab, output_bfd, val, ptr);
9257 loc = (htab->srelplt2->contents
9258 + (plt_index * 2 + 1) * RELOC_SIZE (htab));
9260 /* Create the .rela.plt.unloaded R_ARM_ABS32 relocation
9261 referencing the GOT for this PLT entry. */
9262 rel.r_offset = plt_address + 8;
9263 rel.r_info = ELF32_R_INFO (htab->root.hgot->indx, R_ARM_ABS32);
9264 rel.r_addend = got_offset;
9265 SWAP_RELOC_OUT (htab) (output_bfd, &rel, loc);
9266 loc += RELOC_SIZE (htab);
9268 /* Create the R_ARM_ABS32 relocation referencing the
9269 beginning of the PLT for this GOT entry. */
9270 rel.r_offset = got_address;
9271 rel.r_info = ELF32_R_INFO (htab->root.hplt->indx, R_ARM_ABS32);
9272 rel.r_addend = 0;
9273 SWAP_RELOC_OUT (htab) (output_bfd, &rel, loc);
9275 else
9277 /* Calculate the displacement between the PLT slot and the
9278 entry in the GOT. The eight-byte offset accounts for the
9279 value produced by adding to pc in the first instruction
9280 of the PLT stub. */
9281 got_displacement = got_address - (plt_address + 8);
9283 BFD_ASSERT ((got_displacement & 0xf0000000) == 0);
9285 if (!htab->use_blx && eh->plt_thumb_refcount > 0)
9287 put_thumb_insn (htab, output_bfd,
9288 elf32_arm_plt_thumb_stub[0], ptr - 4);
9289 put_thumb_insn (htab, output_bfd,
9290 elf32_arm_plt_thumb_stub[1], ptr - 2);
9293 put_arm_insn (htab, output_bfd,
9294 elf32_arm_plt_entry[0]
9295 | ((got_displacement & 0x0ff00000) >> 20),
9296 ptr + 0);
9297 put_arm_insn (htab, output_bfd,
9298 elf32_arm_plt_entry[1]
9299 | ((got_displacement & 0x000ff000) >> 12),
9300 ptr+ 4);
9301 put_arm_insn (htab, output_bfd,
9302 elf32_arm_plt_entry[2]
9303 | (got_displacement & 0x00000fff),
9304 ptr + 8);
9305 #ifdef FOUR_WORD_PLT
9306 bfd_put_32 (output_bfd, elf32_arm_plt_entry[3], ptr + 12);
9307 #endif
9310 /* Fill in the entry in the global offset table. */
9311 bfd_put_32 (output_bfd,
9312 (splt->output_section->vma
9313 + splt->output_offset),
9314 sgot->contents + got_offset);
9316 /* Fill in the entry in the .rel(a).plt section. */
9317 rel.r_addend = 0;
9318 rel.r_offset = got_address;
9319 rel.r_info = ELF32_R_INFO (h->dynindx, R_ARM_JUMP_SLOT);
9322 loc = srel->contents + plt_index * RELOC_SIZE (htab);
9323 SWAP_RELOC_OUT (htab) (output_bfd, &rel, loc);
9325 if (!h->def_regular)
9327 /* Mark the symbol as undefined, rather than as defined in
9328 the .plt section. Leave the value alone. */
9329 sym->st_shndx = SHN_UNDEF;
9330 /* If the symbol is weak, we do need to clear the value.
9331 Otherwise, the PLT entry would provide a definition for
9332 the symbol even if the symbol wasn't defined anywhere,
9333 and so the symbol would never be NULL. */
9334 if (!h->ref_regular_nonweak)
9335 sym->st_value = 0;
9339 if (h->got.offset != (bfd_vma) -1
9340 && (elf32_arm_hash_entry (h)->tls_type & GOT_TLS_GD) == 0
9341 && (elf32_arm_hash_entry (h)->tls_type & GOT_TLS_IE) == 0)
9343 asection * sgot;
9344 asection * srel;
9345 Elf_Internal_Rela rel;
9346 bfd_byte *loc;
9347 bfd_vma offset;
9349 /* This symbol has an entry in the global offset table. Set it
9350 up. */
9351 sgot = bfd_get_section_by_name (dynobj, ".got");
9352 srel = bfd_get_section_by_name (dynobj, RELOC_SECTION (htab, ".got"));
9353 BFD_ASSERT (sgot != NULL && srel != NULL);
9355 offset = (h->got.offset & ~(bfd_vma) 1);
9356 rel.r_addend = 0;
9357 rel.r_offset = (sgot->output_section->vma
9358 + sgot->output_offset
9359 + offset);
9361 /* If this is a static link, or it is a -Bsymbolic link and the
9362 symbol is defined locally or was forced to be local because
9363 of a version file, we just want to emit a RELATIVE reloc.
9364 The entry in the global offset table will already have been
9365 initialized in the relocate_section function. */
9366 if (info->shared
9367 && SYMBOL_REFERENCES_LOCAL (info, h))
9369 BFD_ASSERT((h->got.offset & 1) != 0);
9370 rel.r_info = ELF32_R_INFO (0, R_ARM_RELATIVE);
9371 if (!htab->use_rel)
9373 rel.r_addend = bfd_get_32 (output_bfd, sgot->contents + offset);
9374 bfd_put_32 (output_bfd, (bfd_vma) 0, sgot->contents + offset);
9377 else
9379 BFD_ASSERT((h->got.offset & 1) == 0);
9380 bfd_put_32 (output_bfd, (bfd_vma) 0, sgot->contents + offset);
9381 rel.r_info = ELF32_R_INFO (h->dynindx, R_ARM_GLOB_DAT);
9384 loc = srel->contents + srel->reloc_count++ * RELOC_SIZE (htab);
9385 SWAP_RELOC_OUT (htab) (output_bfd, &rel, loc);
9388 if (h->needs_copy)
9390 asection * s;
9391 Elf_Internal_Rela rel;
9392 bfd_byte *loc;
9394 /* This symbol needs a copy reloc. Set it up. */
9395 BFD_ASSERT (h->dynindx != -1
9396 && (h->root.type == bfd_link_hash_defined
9397 || h->root.type == bfd_link_hash_defweak));
9399 s = bfd_get_section_by_name (h->root.u.def.section->owner,
9400 RELOC_SECTION (htab, ".bss"));
9401 BFD_ASSERT (s != NULL);
9403 rel.r_addend = 0;
9404 rel.r_offset = (h->root.u.def.value
9405 + h->root.u.def.section->output_section->vma
9406 + h->root.u.def.section->output_offset);
9407 rel.r_info = ELF32_R_INFO (h->dynindx, R_ARM_COPY);
9408 loc = s->contents + s->reloc_count++ * RELOC_SIZE (htab);
9409 SWAP_RELOC_OUT (htab) (output_bfd, &rel, loc);
9412 /* Mark _DYNAMIC and _GLOBAL_OFFSET_TABLE_ as absolute. On VxWorks,
9413 the _GLOBAL_OFFSET_TABLE_ symbol is not absolute: it is relative
9414 to the ".got" section. */
9415 if (strcmp (h->root.root.string, "_DYNAMIC") == 0
9416 || (!htab->vxworks_p && h == htab->root.hgot))
9417 sym->st_shndx = SHN_ABS;
9419 return TRUE;
9422 /* Finish up the dynamic sections. */
9424 static bfd_boolean
9425 elf32_arm_finish_dynamic_sections (bfd * output_bfd, struct bfd_link_info * info)
9427 bfd * dynobj;
9428 asection * sgot;
9429 asection * sdyn;
9431 dynobj = elf_hash_table (info)->dynobj;
9433 sgot = bfd_get_section_by_name (dynobj, ".got.plt");
9434 BFD_ASSERT (elf32_arm_hash_table (info)->symbian_p || sgot != NULL);
9435 sdyn = bfd_get_section_by_name (dynobj, ".dynamic");
9437 if (elf_hash_table (info)->dynamic_sections_created)
9439 asection *splt;
9440 Elf32_External_Dyn *dyncon, *dynconend;
9441 struct elf32_arm_link_hash_table *htab;
9443 htab = elf32_arm_hash_table (info);
9444 splt = bfd_get_section_by_name (dynobj, ".plt");
9445 BFD_ASSERT (splt != NULL && sdyn != NULL);
9447 dyncon = (Elf32_External_Dyn *) sdyn->contents;
9448 dynconend = (Elf32_External_Dyn *) (sdyn->contents + sdyn->size);
9450 for (; dyncon < dynconend; dyncon++)
9452 Elf_Internal_Dyn dyn;
9453 const char * name;
9454 asection * s;
9456 bfd_elf32_swap_dyn_in (dynobj, dyncon, &dyn);
9458 switch (dyn.d_tag)
9460 unsigned int type;
9462 default:
9463 break;
9465 case DT_HASH:
9466 name = ".hash";
9467 goto get_vma_if_bpabi;
9468 case DT_STRTAB:
9469 name = ".dynstr";
9470 goto get_vma_if_bpabi;
9471 case DT_SYMTAB:
9472 name = ".dynsym";
9473 goto get_vma_if_bpabi;
9474 case DT_VERSYM:
9475 name = ".gnu.version";
9476 goto get_vma_if_bpabi;
9477 case DT_VERDEF:
9478 name = ".gnu.version_d";
9479 goto get_vma_if_bpabi;
9480 case DT_VERNEED:
9481 name = ".gnu.version_r";
9482 goto get_vma_if_bpabi;
9484 case DT_PLTGOT:
9485 name = ".got";
9486 goto get_vma;
9487 case DT_JMPREL:
9488 name = RELOC_SECTION (htab, ".plt");
9489 get_vma:
9490 s = bfd_get_section_by_name (output_bfd, name);
9491 BFD_ASSERT (s != NULL);
9492 if (!htab->symbian_p)
9493 dyn.d_un.d_ptr = s->vma;
9494 else
9495 /* In the BPABI, tags in the PT_DYNAMIC section point
9496 at the file offset, not the memory address, for the
9497 convenience of the post linker. */
9498 dyn.d_un.d_ptr = s->filepos;
9499 bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon);
9500 break;
9502 get_vma_if_bpabi:
9503 if (htab->symbian_p)
9504 goto get_vma;
9505 break;
9507 case DT_PLTRELSZ:
9508 s = bfd_get_section_by_name (output_bfd,
9509 RELOC_SECTION (htab, ".plt"));
9510 BFD_ASSERT (s != NULL);
9511 dyn.d_un.d_val = s->size;
9512 bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon);
9513 break;
9515 case DT_RELSZ:
9516 case DT_RELASZ:
9517 if (!htab->symbian_p)
9519 /* My reading of the SVR4 ABI indicates that the
9520 procedure linkage table relocs (DT_JMPREL) should be
9521 included in the overall relocs (DT_REL). This is
9522 what Solaris does. However, UnixWare can not handle
9523 that case. Therefore, we override the DT_RELSZ entry
9524 here to make it not include the JMPREL relocs. Since
9525 the linker script arranges for .rel(a).plt to follow all
9526 other relocation sections, we don't have to worry
9527 about changing the DT_REL entry. */
9528 s = bfd_get_section_by_name (output_bfd,
9529 RELOC_SECTION (htab, ".plt"));
9530 if (s != NULL)
9531 dyn.d_un.d_val -= s->size;
9532 bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon);
9533 break;
9535 /* Fall through */
9537 case DT_REL:
9538 case DT_RELA:
9539 /* In the BPABI, the DT_REL tag must point at the file
9540 offset, not the VMA, of the first relocation
9541 section. So, we use code similar to that in
9542 elflink.c, but do not check for SHF_ALLOC on the
9543 relcoation section, since relocations sections are
9544 never allocated under the BPABI. The comments above
9545 about Unixware notwithstanding, we include all of the
9546 relocations here. */
9547 if (htab->symbian_p)
9549 unsigned int i;
9550 type = ((dyn.d_tag == DT_REL || dyn.d_tag == DT_RELSZ)
9551 ? SHT_REL : SHT_RELA);
9552 dyn.d_un.d_val = 0;
9553 for (i = 1; i < elf_numsections (output_bfd); i++)
9555 Elf_Internal_Shdr *hdr
9556 = elf_elfsections (output_bfd)[i];
9557 if (hdr->sh_type == type)
9559 if (dyn.d_tag == DT_RELSZ
9560 || dyn.d_tag == DT_RELASZ)
9561 dyn.d_un.d_val += hdr->sh_size;
9562 else if ((ufile_ptr) hdr->sh_offset
9563 <= dyn.d_un.d_val - 1)
9564 dyn.d_un.d_val = hdr->sh_offset;
9567 bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon);
9569 break;
9571 /* Set the bottom bit of DT_INIT/FINI if the
9572 corresponding function is Thumb. */
9573 case DT_INIT:
9574 name = info->init_function;
9575 goto get_sym;
9576 case DT_FINI:
9577 name = info->fini_function;
9578 get_sym:
9579 /* If it wasn't set by elf_bfd_final_link
9580 then there is nothing to adjust. */
9581 if (dyn.d_un.d_val != 0)
9583 struct elf_link_hash_entry * eh;
9585 eh = elf_link_hash_lookup (elf_hash_table (info), name,
9586 FALSE, FALSE, TRUE);
9587 if (eh != (struct elf_link_hash_entry *) NULL
9588 && ELF_ST_TYPE (eh->type) == STT_ARM_TFUNC)
9590 dyn.d_un.d_val |= 1;
9591 bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon);
9594 break;
9598 /* Fill in the first entry in the procedure linkage table. */
9599 if (splt->size > 0 && elf32_arm_hash_table (info)->plt_header_size)
9601 const bfd_vma *plt0_entry;
9602 bfd_vma got_address, plt_address, got_displacement;
9604 /* Calculate the addresses of the GOT and PLT. */
9605 got_address = sgot->output_section->vma + sgot->output_offset;
9606 plt_address = splt->output_section->vma + splt->output_offset;
9608 if (htab->vxworks_p)
9610 /* The VxWorks GOT is relocated by the dynamic linker.
9611 Therefore, we must emit relocations rather than simply
9612 computing the values now. */
9613 Elf_Internal_Rela rel;
9615 plt0_entry = elf32_arm_vxworks_exec_plt0_entry;
9616 put_arm_insn (htab, output_bfd, plt0_entry[0],
9617 splt->contents + 0);
9618 put_arm_insn (htab, output_bfd, plt0_entry[1],
9619 splt->contents + 4);
9620 put_arm_insn (htab, output_bfd, plt0_entry[2],
9621 splt->contents + 8);
9622 bfd_put_32 (output_bfd, got_address, splt->contents + 12);
9624 /* Generate a relocation for _GLOBAL_OFFSET_TABLE_. */
9625 rel.r_offset = plt_address + 12;
9626 rel.r_info = ELF32_R_INFO (htab->root.hgot->indx, R_ARM_ABS32);
9627 rel.r_addend = 0;
9628 SWAP_RELOC_OUT (htab) (output_bfd, &rel,
9629 htab->srelplt2->contents);
9631 else
9633 got_displacement = got_address - (plt_address + 16);
9635 plt0_entry = elf32_arm_plt0_entry;
9636 put_arm_insn (htab, output_bfd, plt0_entry[0],
9637 splt->contents + 0);
9638 put_arm_insn (htab, output_bfd, plt0_entry[1],
9639 splt->contents + 4);
9640 put_arm_insn (htab, output_bfd, plt0_entry[2],
9641 splt->contents + 8);
9642 put_arm_insn (htab, output_bfd, plt0_entry[3],
9643 splt->contents + 12);
9645 #ifdef FOUR_WORD_PLT
9646 /* The displacement value goes in the otherwise-unused
9647 last word of the second entry. */
9648 bfd_put_32 (output_bfd, got_displacement, splt->contents + 28);
9649 #else
9650 bfd_put_32 (output_bfd, got_displacement, splt->contents + 16);
9651 #endif
9655 /* UnixWare sets the entsize of .plt to 4, although that doesn't
9656 really seem like the right value. */
9657 if (splt->output_section->owner == output_bfd)
9658 elf_section_data (splt->output_section)->this_hdr.sh_entsize = 4;
9660 if (htab->vxworks_p && !info->shared && htab->splt->size > 0)
9662 /* Correct the .rel(a).plt.unloaded relocations. They will have
9663 incorrect symbol indexes. */
9664 int num_plts;
9665 unsigned char *p;
9667 num_plts = ((htab->splt->size - htab->plt_header_size)
9668 / htab->plt_entry_size);
9669 p = htab->srelplt2->contents + RELOC_SIZE (htab);
9671 for (; num_plts; num_plts--)
9673 Elf_Internal_Rela rel;
9675 SWAP_RELOC_IN (htab) (output_bfd, p, &rel);
9676 rel.r_info = ELF32_R_INFO (htab->root.hgot->indx, R_ARM_ABS32);
9677 SWAP_RELOC_OUT (htab) (output_bfd, &rel, p);
9678 p += RELOC_SIZE (htab);
9680 SWAP_RELOC_IN (htab) (output_bfd, p, &rel);
9681 rel.r_info = ELF32_R_INFO (htab->root.hplt->indx, R_ARM_ABS32);
9682 SWAP_RELOC_OUT (htab) (output_bfd, &rel, p);
9683 p += RELOC_SIZE (htab);
9688 /* Fill in the first three entries in the global offset table. */
9689 if (sgot)
9691 if (sgot->size > 0)
9693 if (sdyn == NULL)
9694 bfd_put_32 (output_bfd, (bfd_vma) 0, sgot->contents);
9695 else
9696 bfd_put_32 (output_bfd,
9697 sdyn->output_section->vma + sdyn->output_offset,
9698 sgot->contents);
9699 bfd_put_32 (output_bfd, (bfd_vma) 0, sgot->contents + 4);
9700 bfd_put_32 (output_bfd, (bfd_vma) 0, sgot->contents + 8);
9703 elf_section_data (sgot->output_section)->this_hdr.sh_entsize = 4;
9706 return TRUE;
9709 static void
9710 elf32_arm_post_process_headers (bfd * abfd, struct bfd_link_info * link_info ATTRIBUTE_UNUSED)
9712 Elf_Internal_Ehdr * i_ehdrp; /* ELF file header, internal form. */
9713 struct elf32_arm_link_hash_table *globals;
9715 i_ehdrp = elf_elfheader (abfd);
9717 if (EF_ARM_EABI_VERSION (i_ehdrp->e_flags) == EF_ARM_EABI_UNKNOWN)
9718 i_ehdrp->e_ident[EI_OSABI] = ELFOSABI_ARM;
9719 else
9720 i_ehdrp->e_ident[EI_OSABI] = 0;
9721 i_ehdrp->e_ident[EI_ABIVERSION] = ARM_ELF_ABI_VERSION;
9723 if (link_info)
9725 globals = elf32_arm_hash_table (link_info);
9726 if (globals->byteswap_code)
9727 i_ehdrp->e_flags |= EF_ARM_BE8;
9731 static enum elf_reloc_type_class
9732 elf32_arm_reloc_type_class (const Elf_Internal_Rela *rela)
9734 switch ((int) ELF32_R_TYPE (rela->r_info))
9736 case R_ARM_RELATIVE:
9737 return reloc_class_relative;
9738 case R_ARM_JUMP_SLOT:
9739 return reloc_class_plt;
9740 case R_ARM_COPY:
9741 return reloc_class_copy;
9742 default:
9743 return reloc_class_normal;
9747 /* Set the right machine number for an Arm ELF file. */
9749 static bfd_boolean
9750 elf32_arm_section_flags (flagword *flags, const Elf_Internal_Shdr *hdr)
9752 if (hdr->sh_type == SHT_NOTE)
9753 *flags |= SEC_LINK_ONCE | SEC_LINK_DUPLICATES_SAME_CONTENTS;
9755 return TRUE;
9758 static void
9759 elf32_arm_final_write_processing (bfd *abfd, bfd_boolean linker ATTRIBUTE_UNUSED)
9761 bfd_arm_update_notes (abfd, ARM_NOTE_SECTION);
9764 /* Return TRUE if this is an unwinding table entry. */
9766 static bfd_boolean
9767 is_arm_elf_unwind_section_name (bfd * abfd ATTRIBUTE_UNUSED, const char * name)
9769 return (CONST_STRNEQ (name, ELF_STRING_ARM_unwind)
9770 || CONST_STRNEQ (name, ELF_STRING_ARM_unwind_once));
9774 /* Set the type and flags for an ARM section. We do this by
9775 the section name, which is a hack, but ought to work. */
9777 static bfd_boolean
9778 elf32_arm_fake_sections (bfd * abfd, Elf_Internal_Shdr * hdr, asection * sec)
9780 const char * name;
9782 name = bfd_get_section_name (abfd, sec);
9784 if (is_arm_elf_unwind_section_name (abfd, name))
9786 hdr->sh_type = SHT_ARM_EXIDX;
9787 hdr->sh_flags |= SHF_LINK_ORDER;
9789 else if (strcmp(name, ".ARM.attributes") == 0)
9791 hdr->sh_type = SHT_ARM_ATTRIBUTES;
9793 return TRUE;
9796 /* Parse an Arm EABI attributes section. */
9797 static void
9798 elf32_arm_parse_attributes (bfd *abfd, Elf_Internal_Shdr * hdr)
9800 bfd_byte *contents;
9801 bfd_byte *p;
9802 bfd_vma len;
9804 contents = bfd_malloc (hdr->sh_size);
9805 if (!contents)
9806 return;
9807 if (!bfd_get_section_contents (abfd, hdr->bfd_section, contents, 0,
9808 hdr->sh_size))
9810 free (contents);
9811 return;
9813 p = contents;
9814 if (*(p++) == 'A')
9816 len = hdr->sh_size - 1;
9817 while (len > 0)
9819 int namelen;
9820 bfd_vma section_len;
9822 section_len = bfd_get_32 (abfd, p);
9823 p += 4;
9824 if (section_len > len)
9825 section_len = len;
9826 len -= section_len;
9827 namelen = strlen ((char *)p) + 1;
9828 section_len -= namelen + 4;
9829 if (strcmp((char *)p, "aeabi") != 0)
9831 /* Vendor section. Ignore it. */
9832 p += namelen + section_len;
9834 else
9836 p += namelen;
9837 while (section_len > 0)
9839 int tag;
9840 unsigned int n;
9841 unsigned int val;
9842 bfd_vma subsection_len;
9843 bfd_byte *end;
9845 tag = read_unsigned_leb128 (abfd, p, &n);
9846 p += n;
9847 subsection_len = bfd_get_32 (abfd, p);
9848 p += 4;
9849 if (subsection_len > section_len)
9850 subsection_len = section_len;
9851 section_len -= subsection_len;
9852 subsection_len -= n + 4;
9853 end = p + subsection_len;
9854 switch (tag)
9856 case Tag_File:
9857 while (p < end)
9859 bfd_boolean is_string;
9861 tag = read_unsigned_leb128 (abfd, p, &n);
9862 p += n;
9863 if (tag == 4 || tag == 5)
9864 is_string = 1;
9865 else if (tag < 32)
9866 is_string = 0;
9867 else
9868 is_string = (tag & 1) != 0;
9869 if (tag == Tag_compatibility)
9871 val = read_unsigned_leb128 (abfd, p, &n);
9872 p += n;
9873 elf32_arm_add_eabi_attr_compat (abfd, val,
9874 (char *)p);
9875 p += strlen ((char *)p) + 1;
9877 else if (is_string)
9879 elf32_arm_add_eabi_attr_string (abfd, tag,
9880 (char *)p);
9881 p += strlen ((char *)p) + 1;
9883 else
9885 val = read_unsigned_leb128 (abfd, p, &n);
9886 p += n;
9887 elf32_arm_add_eabi_attr_int (abfd, tag, val);
9890 break;
9891 case Tag_Section:
9892 case Tag_Symbol:
9893 /* Don't have anywhere convenient to attach these.
9894 Fall through for now. */
9895 default:
9896 /* Ignore things we don't kow about. */
9897 p += subsection_len;
9898 subsection_len = 0;
9899 break;
9905 free (contents);
9908 /* Handle an ARM specific section when reading an object file. This is
9909 called when bfd_section_from_shdr finds a section with an unknown
9910 type. */
9912 static bfd_boolean
9913 elf32_arm_section_from_shdr (bfd *abfd,
9914 Elf_Internal_Shdr * hdr,
9915 const char *name,
9916 int shindex)
9918 /* There ought to be a place to keep ELF backend specific flags, but
9919 at the moment there isn't one. We just keep track of the
9920 sections by their name, instead. Fortunately, the ABI gives
9921 names for all the ARM specific sections, so we will probably get
9922 away with this. */
9923 switch (hdr->sh_type)
9925 case SHT_ARM_EXIDX:
9926 case SHT_ARM_PREEMPTMAP:
9927 case SHT_ARM_ATTRIBUTES:
9928 break;
9930 default:
9931 return FALSE;
9934 if (! _bfd_elf_make_section_from_shdr (abfd, hdr, name, shindex))
9935 return FALSE;
9937 if (hdr->sh_type == SHT_ARM_ATTRIBUTES)
9938 elf32_arm_parse_attributes(abfd, hdr);
9939 return TRUE;
9942 /* A structure used to record a list of sections, independently
9943 of the next and prev fields in the asection structure. */
9944 typedef struct section_list
9946 asection * sec;
9947 struct section_list * next;
9948 struct section_list * prev;
9950 section_list;
9952 /* Unfortunately we need to keep a list of sections for which
9953 an _arm_elf_section_data structure has been allocated. This
9954 is because it is possible for functions like elf32_arm_write_section
9955 to be called on a section which has had an elf_data_structure
9956 allocated for it (and so the used_by_bfd field is valid) but
9957 for which the ARM extended version of this structure - the
9958 _arm_elf_section_data structure - has not been allocated. */
9959 static section_list * sections_with_arm_elf_section_data = NULL;
9961 static void
9962 record_section_with_arm_elf_section_data (asection * sec)
9964 struct section_list * entry;
9966 entry = bfd_malloc (sizeof (* entry));
9967 if (entry == NULL)
9968 return;
9969 entry->sec = sec;
9970 entry->next = sections_with_arm_elf_section_data;
9971 entry->prev = NULL;
9972 if (entry->next != NULL)
9973 entry->next->prev = entry;
9974 sections_with_arm_elf_section_data = entry;
9977 static struct section_list *
9978 find_arm_elf_section_entry (asection * sec)
9980 struct section_list * entry;
9981 static struct section_list * last_entry = NULL;
9983 /* This is a short cut for the typical case where the sections are added
9984 to the sections_with_arm_elf_section_data list in forward order and
9985 then looked up here in backwards order. This makes a real difference
9986 to the ld-srec/sec64k.exp linker test. */
9987 entry = sections_with_arm_elf_section_data;
9988 if (last_entry != NULL)
9990 if (last_entry->sec == sec)
9991 entry = last_entry;
9992 else if (last_entry->next != NULL
9993 && last_entry->next->sec == sec)
9994 entry = last_entry->next;
9997 for (; entry; entry = entry->next)
9998 if (entry->sec == sec)
9999 break;
10001 if (entry)
10002 /* Record the entry prior to this one - it is the entry we are most
10003 likely to want to locate next time. Also this way if we have been
10004 called from unrecord_section_with_arm_elf_section_data() we will not
10005 be caching a pointer that is about to be freed. */
10006 last_entry = entry->prev;
10008 return entry;
10011 static _arm_elf_section_data *
10012 get_arm_elf_section_data (asection * sec)
10014 struct section_list * entry;
10016 entry = find_arm_elf_section_entry (sec);
10018 if (entry)
10019 return elf32_arm_section_data (entry->sec);
10020 else
10021 return NULL;
10024 static void
10025 unrecord_section_with_arm_elf_section_data (asection * sec)
10027 struct section_list * entry;
10029 entry = find_arm_elf_section_entry (sec);
10031 if (entry)
10033 if (entry->prev != NULL)
10034 entry->prev->next = entry->next;
10035 if (entry->next != NULL)
10036 entry->next->prev = entry->prev;
10037 if (entry == sections_with_arm_elf_section_data)
10038 sections_with_arm_elf_section_data = entry->next;
10039 free (entry);
10044 typedef struct
10046 void *finfo;
10047 struct bfd_link_info *info;
10048 int plt_shndx;
10049 bfd_vma plt_offset;
10050 bfd_boolean (*func) (void *, const char *, Elf_Internal_Sym *,
10051 asection *, struct elf_link_hash_entry *);
10052 } output_arch_syminfo;
10054 enum map_symbol_type
10056 ARM_MAP_ARM,
10057 ARM_MAP_THUMB,
10058 ARM_MAP_DATA
10062 /* Output a single PLT mapping symbol. */
10064 static bfd_boolean
10065 elf32_arm_ouput_plt_map_sym (output_arch_syminfo *osi,
10066 enum map_symbol_type type,
10067 bfd_vma offset)
10069 static const char *names[3] = {"$a", "$t", "$d"};
10070 struct elf32_arm_link_hash_table *htab;
10071 Elf_Internal_Sym sym;
10073 htab = elf32_arm_hash_table (osi->info);
10074 sym.st_value = osi->plt_offset + offset;
10075 sym.st_size = 0;
10076 sym.st_other = 0;
10077 sym.st_info = ELF_ST_INFO (STB_LOCAL, STT_NOTYPE);
10078 sym.st_shndx = osi->plt_shndx;
10079 if (!osi->func (osi->finfo, names[type], &sym, htab->splt, NULL))
10080 return FALSE;
10081 return TRUE;
10085 /* Output mapping symbols for PLT entries associated with H. */
10087 static bfd_boolean
10088 elf32_arm_output_plt_map (struct elf_link_hash_entry *h, void *inf)
10090 output_arch_syminfo *osi = (output_arch_syminfo *) inf;
10091 struct elf32_arm_link_hash_table *htab;
10092 struct elf32_arm_link_hash_entry *eh;
10093 bfd_vma addr;
10095 htab = elf32_arm_hash_table (osi->info);
10097 if (h->root.type == bfd_link_hash_indirect)
10098 return TRUE;
10100 if (h->root.type == bfd_link_hash_warning)
10101 /* When warning symbols are created, they **replace** the "real"
10102 entry in the hash table, thus we never get to see the real
10103 symbol in a hash traversal. So look at it now. */
10104 h = (struct elf_link_hash_entry *) h->root.u.i.link;
10106 if (h->plt.offset == (bfd_vma) -1)
10107 return TRUE;
10109 eh = (struct elf32_arm_link_hash_entry *) h;
10110 addr = h->plt.offset;
10111 if (htab->symbian_p)
10113 if (!elf32_arm_ouput_plt_map_sym (osi, ARM_MAP_ARM, addr))
10114 return FALSE;
10115 if (!elf32_arm_ouput_plt_map_sym (osi, ARM_MAP_DATA, addr + 4))
10116 return FALSE;
10118 else if (htab->vxworks_p)
10120 if (!elf32_arm_ouput_plt_map_sym (osi, ARM_MAP_ARM, addr))
10121 return FALSE;
10122 if (!elf32_arm_ouput_plt_map_sym (osi, ARM_MAP_DATA, addr + 8))
10123 return FALSE;
10124 if (!elf32_arm_ouput_plt_map_sym (osi, ARM_MAP_ARM, addr + 12))
10125 return FALSE;
10126 if (!elf32_arm_ouput_plt_map_sym (osi, ARM_MAP_DATA, addr + 20))
10127 return FALSE;
10129 else
10131 bfd_boolean thumb_stub;
10133 thumb_stub = eh->plt_thumb_refcount > 0 && !htab->use_blx;
10134 if (thumb_stub)
10136 if (!elf32_arm_ouput_plt_map_sym (osi, ARM_MAP_THUMB, addr - 4))
10137 return FALSE;
10139 #ifdef FOUR_WORD_PLT
10140 if (!elf32_arm_ouput_plt_map_sym (osi, ARM_MAP_ARM, addr))
10141 return FALSE;
10142 if (!elf32_arm_ouput_plt_map_sym (osi, ARM_MAP_DATA, addr + 12))
10143 return FALSE;
10144 #else
10145 /* A three-word PLT with no Thumb thunk contains only Arm code,
10146 so only need to output a mapping symbol for the first PLT entry and
10147 entries with thumb thunks. */
10148 if (thumb_stub || addr == 20)
10150 if (!elf32_arm_ouput_plt_map_sym (osi, ARM_MAP_ARM, addr))
10151 return FALSE;
10153 #endif
10156 return TRUE;
10160 /* Output mapping symbols for the PLT. */
10162 static bfd_boolean
10163 elf32_arm_output_arch_local_syms (bfd *output_bfd,
10164 struct bfd_link_info *info,
10165 void *finfo, bfd_boolean (*func) (void *, const char *,
10166 Elf_Internal_Sym *,
10167 asection *,
10168 struct elf_link_hash_entry *))
10170 output_arch_syminfo osi;
10171 struct elf32_arm_link_hash_table *htab;
10173 htab = elf32_arm_hash_table (info);
10174 if (!htab->splt || htab->splt->size == 0)
10175 return TRUE;
10177 check_use_blx(htab);
10178 osi.finfo = finfo;
10179 osi.info = info;
10180 osi.func = func;
10181 osi.plt_shndx = _bfd_elf_section_from_bfd_section (output_bfd,
10182 htab->splt->output_section);
10183 osi.plt_offset = htab->splt->output_section->vma;
10185 /* Output mapping symbols for the plt header. SymbianOS does not have a
10186 plt header. */
10187 if (htab->vxworks_p)
10189 /* VxWorks shared libraries have no PLT header. */
10190 if (!info->shared)
10192 if (!elf32_arm_ouput_plt_map_sym (&osi, ARM_MAP_ARM, 0))
10193 return FALSE;
10194 if (!elf32_arm_ouput_plt_map_sym (&osi, ARM_MAP_DATA, 12))
10195 return FALSE;
10198 else if (!htab->symbian_p)
10200 if (!elf32_arm_ouput_plt_map_sym (&osi, ARM_MAP_ARM, 0))
10201 return FALSE;
10202 #ifndef FOUR_WORD_PLT
10203 if (!elf32_arm_ouput_plt_map_sym (&osi, ARM_MAP_DATA, 16))
10204 return FALSE;
10205 #endif
10208 elf_link_hash_traverse (&htab->root, elf32_arm_output_plt_map, (void *) &osi);
10209 return TRUE;
10212 /* Allocate target specific section data. */
10214 static bfd_boolean
10215 elf32_arm_new_section_hook (bfd *abfd, asection *sec)
10217 if (!sec->used_by_bfd)
10219 _arm_elf_section_data *sdata;
10220 bfd_size_type amt = sizeof (*sdata);
10222 sdata = bfd_zalloc (abfd, amt);
10223 if (sdata == NULL)
10224 return FALSE;
10225 sec->used_by_bfd = sdata;
10228 record_section_with_arm_elf_section_data (sec);
10230 return _bfd_elf_new_section_hook (abfd, sec);
10234 /* Used to order a list of mapping symbols by address. */
10236 static int
10237 elf32_arm_compare_mapping (const void * a, const void * b)
10239 return ((const elf32_arm_section_map *) a)->vma
10240 > ((const elf32_arm_section_map *) b)->vma;
10244 /* Do code byteswapping. Return FALSE afterwards so that the section is
10245 written out as normal. */
10247 static bfd_boolean
10248 elf32_arm_write_section (bfd *output_bfd,
10249 struct bfd_link_info *link_info, asection *sec,
10250 bfd_byte *contents)
10252 int mapcount, errcount;
10253 _arm_elf_section_data *arm_data;
10254 struct elf32_arm_link_hash_table *globals = elf32_arm_hash_table (link_info);
10255 elf32_arm_section_map *map;
10256 elf32_vfp11_erratum_list *errnode;
10257 bfd_vma ptr;
10258 bfd_vma end;
10259 bfd_vma offset = sec->output_section->vma + sec->output_offset;
10260 bfd_byte tmp;
10261 int i;
10263 /* If this section has not been allocated an _arm_elf_section_data
10264 structure then we cannot record anything. */
10265 arm_data = get_arm_elf_section_data (sec);
10266 if (arm_data == NULL)
10267 return FALSE;
10269 mapcount = arm_data->mapcount;
10270 map = arm_data->map;
10271 errcount = arm_data->erratumcount;
10273 if (errcount != 0)
10275 unsigned int endianflip = bfd_big_endian (output_bfd) ? 3 : 0;
10277 for (errnode = arm_data->erratumlist; errnode != 0;
10278 errnode = errnode->next)
10280 bfd_vma index = errnode->vma - offset;
10282 switch (errnode->type)
10284 case VFP11_ERRATUM_BRANCH_TO_ARM_VENEER:
10286 bfd_vma branch_to_veneer;
10287 /* Original condition code of instruction, plus bit mask for
10288 ARM B instruction. */
10289 unsigned int insn = (errnode->u.b.vfp_insn & 0xf0000000)
10290 | 0x0a000000;
10292 /* The instruction is before the label. */
10293 index -= 4;
10295 /* Above offset included in -4 below. */
10296 branch_to_veneer = errnode->u.b.veneer->vma
10297 - errnode->vma - 4;
10299 if ((signed) branch_to_veneer < -(1 << 25)
10300 || (signed) branch_to_veneer >= (1 << 25))
10301 (*_bfd_error_handler) (_("%B: error: VFP11 veneer out of "
10302 "range"), output_bfd);
10304 insn |= (branch_to_veneer >> 2) & 0xffffff;
10305 contents[endianflip ^ index] = insn & 0xff;
10306 contents[endianflip ^ (index + 1)] = (insn >> 8) & 0xff;
10307 contents[endianflip ^ (index + 2)] = (insn >> 16) & 0xff;
10308 contents[endianflip ^ (index + 3)] = (insn >> 24) & 0xff;
10310 break;
10312 case VFP11_ERRATUM_ARM_VENEER:
10314 bfd_vma branch_from_veneer;
10315 unsigned int insn;
10317 /* Take size of veneer into account. */
10318 branch_from_veneer = errnode->u.v.branch->vma
10319 - errnode->vma - 12;
10321 if ((signed) branch_from_veneer < -(1 << 25)
10322 || (signed) branch_from_veneer >= (1 << 25))
10323 (*_bfd_error_handler) (_("%B: error: VFP11 veneer out of "
10324 "range"), output_bfd);
10326 /* Original instruction. */
10327 insn = errnode->u.v.branch->u.b.vfp_insn;
10328 contents[endianflip ^ index] = insn & 0xff;
10329 contents[endianflip ^ (index + 1)] = (insn >> 8) & 0xff;
10330 contents[endianflip ^ (index + 2)] = (insn >> 16) & 0xff;
10331 contents[endianflip ^ (index + 3)] = (insn >> 24) & 0xff;
10333 /* Branch back to insn after original insn. */
10334 insn = 0xea000000 | ((branch_from_veneer >> 2) & 0xffffff);
10335 contents[endianflip ^ (index + 4)] = insn & 0xff;
10336 contents[endianflip ^ (index + 5)] = (insn >> 8) & 0xff;
10337 contents[endianflip ^ (index + 6)] = (insn >> 16) & 0xff;
10338 contents[endianflip ^ (index + 7)] = (insn >> 24) & 0xff;
10340 break;
10342 default:
10343 abort ();
10348 if (mapcount == 0)
10349 return FALSE;
10351 if (globals->byteswap_code)
10353 qsort (map, mapcount, sizeof (* map), elf32_arm_compare_mapping);
10355 ptr = map[0].vma;
10356 for (i = 0; i < mapcount; i++)
10358 if (i == mapcount - 1)
10359 end = sec->size;
10360 else
10361 end = map[i + 1].vma;
10363 switch (map[i].type)
10365 case 'a':
10366 /* Byte swap code words. */
10367 while (ptr + 3 < end)
10369 tmp = contents[ptr];
10370 contents[ptr] = contents[ptr + 3];
10371 contents[ptr + 3] = tmp;
10372 tmp = contents[ptr + 1];
10373 contents[ptr + 1] = contents[ptr + 2];
10374 contents[ptr + 2] = tmp;
10375 ptr += 4;
10377 break;
10379 case 't':
10380 /* Byte swap code halfwords. */
10381 while (ptr + 1 < end)
10383 tmp = contents[ptr];
10384 contents[ptr] = contents[ptr + 1];
10385 contents[ptr + 1] = tmp;
10386 ptr += 2;
10388 break;
10390 case 'd':
10391 /* Leave data alone. */
10392 break;
10394 ptr = end;
10398 free (map);
10399 arm_data->mapcount = 0;
10400 arm_data->mapsize = 0;
10401 arm_data->map = NULL;
10402 unrecord_section_with_arm_elf_section_data (sec);
10404 return FALSE;
10407 static void
10408 unrecord_section_via_map_over_sections (bfd * abfd ATTRIBUTE_UNUSED,
10409 asection * sec,
10410 void * ignore ATTRIBUTE_UNUSED)
10412 unrecord_section_with_arm_elf_section_data (sec);
10415 static bfd_boolean
10416 elf32_arm_close_and_cleanup (bfd * abfd)
10418 if (abfd->sections)
10419 bfd_map_over_sections (abfd,
10420 unrecord_section_via_map_over_sections,
10421 NULL);
10423 return _bfd_elf_close_and_cleanup (abfd);
10426 static bfd_boolean
10427 elf32_arm_bfd_free_cached_info (bfd * abfd)
10429 if (abfd->sections)
10430 bfd_map_over_sections (abfd,
10431 unrecord_section_via_map_over_sections,
10432 NULL);
10434 return _bfd_free_cached_info (abfd);
10437 /* Display STT_ARM_TFUNC symbols as functions. */
10439 static void
10440 elf32_arm_symbol_processing (bfd *abfd ATTRIBUTE_UNUSED,
10441 asymbol *asym)
10443 elf_symbol_type *elfsym = (elf_symbol_type *) asym;
10445 if (ELF_ST_TYPE (elfsym->internal_elf_sym.st_info) == STT_ARM_TFUNC)
10446 elfsym->symbol.flags |= BSF_FUNCTION;
10450 /* Mangle thumb function symbols as we read them in. */
10452 static bfd_boolean
10453 elf32_arm_swap_symbol_in (bfd * abfd,
10454 const void *psrc,
10455 const void *pshn,
10456 Elf_Internal_Sym *dst)
10458 if (!bfd_elf32_swap_symbol_in (abfd, psrc, pshn, dst))
10459 return FALSE;
10461 /* New EABI objects mark thumb function symbols by setting the low bit of
10462 the address. Turn these into STT_ARM_TFUNC. */
10463 if (ELF_ST_TYPE (dst->st_info) == STT_FUNC
10464 && (dst->st_value & 1))
10466 dst->st_info = ELF_ST_INFO (ELF_ST_BIND (dst->st_info), STT_ARM_TFUNC);
10467 dst->st_value &= ~(bfd_vma) 1;
10469 return TRUE;
10473 /* Mangle thumb function symbols as we write them out. */
10475 static void
10476 elf32_arm_swap_symbol_out (bfd *abfd,
10477 const Elf_Internal_Sym *src,
10478 void *cdst,
10479 void *shndx)
10481 Elf_Internal_Sym newsym;
10483 /* We convert STT_ARM_TFUNC symbols into STT_FUNC with the low bit
10484 of the address set, as per the new EABI. We do this unconditionally
10485 because objcopy does not set the elf header flags until after
10486 it writes out the symbol table. */
10487 if (ELF_ST_TYPE (src->st_info) == STT_ARM_TFUNC)
10489 newsym = *src;
10490 newsym.st_info = ELF_ST_INFO (ELF_ST_BIND (src->st_info), STT_FUNC);
10491 if (newsym.st_shndx != SHN_UNDEF)
10493 /* Do this only for defined symbols. At link type, the static
10494 linker will simulate the work of dynamic linker of resolving
10495 symbols and will carry over the thumbness of found symbols to
10496 the output symbol table. It's not clear how it happens, but
10497 the thumbness of undefined symbols can well be different at
10498 runtime, and writing '1' for them will be confusing for users
10499 and possibly for dynamic linker itself.
10501 newsym.st_value |= 1;
10504 src = &newsym;
10506 bfd_elf32_swap_symbol_out (abfd, src, cdst, shndx);
10509 /* Add the PT_ARM_EXIDX program header. */
10511 static bfd_boolean
10512 elf32_arm_modify_segment_map (bfd *abfd,
10513 struct bfd_link_info *info ATTRIBUTE_UNUSED)
10515 struct elf_segment_map *m;
10516 asection *sec;
10518 sec = bfd_get_section_by_name (abfd, ".ARM.exidx");
10519 if (sec != NULL && (sec->flags & SEC_LOAD) != 0)
10521 /* If there is already a PT_ARM_EXIDX header, then we do not
10522 want to add another one. This situation arises when running
10523 "strip"; the input binary already has the header. */
10524 m = elf_tdata (abfd)->segment_map;
10525 while (m && m->p_type != PT_ARM_EXIDX)
10526 m = m->next;
10527 if (!m)
10529 m = bfd_zalloc (abfd, sizeof (struct elf_segment_map));
10530 if (m == NULL)
10531 return FALSE;
10532 m->p_type = PT_ARM_EXIDX;
10533 m->count = 1;
10534 m->sections[0] = sec;
10536 m->next = elf_tdata (abfd)->segment_map;
10537 elf_tdata (abfd)->segment_map = m;
10541 return TRUE;
10544 /* We may add a PT_ARM_EXIDX program header. */
10546 static int
10547 elf32_arm_additional_program_headers (bfd *abfd,
10548 struct bfd_link_info *info ATTRIBUTE_UNUSED)
10550 asection *sec;
10552 sec = bfd_get_section_by_name (abfd, ".ARM.exidx");
10553 if (sec != NULL && (sec->flags & SEC_LOAD) != 0)
10554 return 1;
10555 else
10556 return 0;
10559 /* We have two function types: STT_FUNC and STT_ARM_TFUNC. */
10560 static bfd_boolean
10561 elf32_arm_is_function_type (unsigned int type)
10563 return (type == STT_FUNC) || (type == STT_ARM_TFUNC);
10566 /* We use this to override swap_symbol_in and swap_symbol_out. */
10567 const struct elf_size_info elf32_arm_size_info = {
10568 sizeof (Elf32_External_Ehdr),
10569 sizeof (Elf32_External_Phdr),
10570 sizeof (Elf32_External_Shdr),
10571 sizeof (Elf32_External_Rel),
10572 sizeof (Elf32_External_Rela),
10573 sizeof (Elf32_External_Sym),
10574 sizeof (Elf32_External_Dyn),
10575 sizeof (Elf_External_Note),
10578 32, 2,
10579 ELFCLASS32, EV_CURRENT,
10580 bfd_elf32_write_out_phdrs,
10581 bfd_elf32_write_shdrs_and_ehdr,
10582 bfd_elf32_write_relocs,
10583 elf32_arm_swap_symbol_in,
10584 elf32_arm_swap_symbol_out,
10585 bfd_elf32_slurp_reloc_table,
10586 bfd_elf32_slurp_symbol_table,
10587 bfd_elf32_swap_dyn_in,
10588 bfd_elf32_swap_dyn_out,
10589 bfd_elf32_swap_reloc_in,
10590 bfd_elf32_swap_reloc_out,
10591 bfd_elf32_swap_reloca_in,
10592 bfd_elf32_swap_reloca_out
10595 #define ELF_ARCH bfd_arch_arm
10596 #define ELF_MACHINE_CODE EM_ARM
10597 #ifdef __QNXTARGET__
10598 #define ELF_MAXPAGESIZE 0x1000
10599 #else
10600 #define ELF_MAXPAGESIZE 0x8000
10601 #endif
10602 #define ELF_MINPAGESIZE 0x1000
10603 #define ELF_COMMONPAGESIZE 0x1000
10605 #define bfd_elf32_mkobject elf32_arm_mkobject
10607 #define bfd_elf32_bfd_copy_private_bfd_data elf32_arm_copy_private_bfd_data
10608 #define bfd_elf32_bfd_merge_private_bfd_data elf32_arm_merge_private_bfd_data
10609 #define bfd_elf32_bfd_set_private_flags elf32_arm_set_private_flags
10610 #define bfd_elf32_bfd_print_private_bfd_data elf32_arm_print_private_bfd_data
10611 #define bfd_elf32_bfd_link_hash_table_create elf32_arm_link_hash_table_create
10612 #define bfd_elf32_bfd_reloc_type_lookup elf32_arm_reloc_type_lookup
10613 #define bfd_elf32_bfd_reloc_name_lookup elf32_arm_reloc_name_lookup
10614 #define bfd_elf32_find_nearest_line elf32_arm_find_nearest_line
10615 #define bfd_elf32_find_inliner_info elf32_arm_find_inliner_info
10616 #define bfd_elf32_new_section_hook elf32_arm_new_section_hook
10617 #define bfd_elf32_bfd_is_target_special_symbol elf32_arm_is_target_special_symbol
10618 #define bfd_elf32_close_and_cleanup elf32_arm_close_and_cleanup
10619 #define bfd_elf32_bfd_free_cached_info elf32_arm_bfd_free_cached_info
10620 #define bfd_elf32_bfd_final_link elf32_arm_bfd_final_link
10622 #define elf_backend_get_symbol_type elf32_arm_get_symbol_type
10623 #define elf_backend_gc_mark_hook elf32_arm_gc_mark_hook
10624 #define elf_backend_gc_mark_extra_sections elf32_arm_gc_mark_extra_sections
10625 #define elf_backend_gc_sweep_hook elf32_arm_gc_sweep_hook
10626 #define elf_backend_check_relocs elf32_arm_check_relocs
10627 #define elf_backend_relocate_section elf32_arm_relocate_section
10628 #define elf_backend_write_section elf32_arm_write_section
10629 #define elf_backend_adjust_dynamic_symbol elf32_arm_adjust_dynamic_symbol
10630 #define elf_backend_create_dynamic_sections elf32_arm_create_dynamic_sections
10631 #define elf_backend_finish_dynamic_symbol elf32_arm_finish_dynamic_symbol
10632 #define elf_backend_finish_dynamic_sections elf32_arm_finish_dynamic_sections
10633 #define elf_backend_size_dynamic_sections elf32_arm_size_dynamic_sections
10634 #define elf_backend_init_index_section _bfd_elf_init_2_index_sections
10635 #define elf_backend_post_process_headers elf32_arm_post_process_headers
10636 #define elf_backend_reloc_type_class elf32_arm_reloc_type_class
10637 #define elf_backend_object_p elf32_arm_object_p
10638 #define elf_backend_section_flags elf32_arm_section_flags
10639 #define elf_backend_fake_sections elf32_arm_fake_sections
10640 #define elf_backend_section_from_shdr elf32_arm_section_from_shdr
10641 #define elf_backend_final_write_processing elf32_arm_final_write_processing
10642 #define elf_backend_copy_indirect_symbol elf32_arm_copy_indirect_symbol
10643 #define elf_backend_symbol_processing elf32_arm_symbol_processing
10644 #define elf_backend_size_info elf32_arm_size_info
10645 #define elf_backend_modify_segment_map elf32_arm_modify_segment_map
10646 #define elf_backend_additional_program_headers \
10647 elf32_arm_additional_program_headers
10648 #define elf_backend_output_arch_local_syms \
10649 elf32_arm_output_arch_local_syms
10650 #define elf_backend_begin_write_processing \
10651 elf32_arm_begin_write_processing
10652 #define elf_backend_is_function_type elf32_arm_is_function_type
10654 #define elf_backend_can_refcount 1
10655 #define elf_backend_can_gc_sections 1
10656 #define elf_backend_plt_readonly 1
10657 #define elf_backend_want_got_plt 1
10658 #define elf_backend_want_plt_sym 0
10659 #define elf_backend_may_use_rel_p 1
10660 #define elf_backend_may_use_rela_p 0
10661 #define elf_backend_default_use_rela_p 0
10663 #define elf_backend_got_header_size 12
10665 #include "elf32-target.h"
10667 /* VxWorks Targets */
10669 #undef TARGET_LITTLE_SYM
10670 #define TARGET_LITTLE_SYM bfd_elf32_littlearm_vxworks_vec
10671 #undef TARGET_LITTLE_NAME
10672 #define TARGET_LITTLE_NAME "elf32-littlearm-vxworks"
10673 #undef TARGET_BIG_SYM
10674 #define TARGET_BIG_SYM bfd_elf32_bigarm_vxworks_vec
10675 #undef TARGET_BIG_NAME
10676 #define TARGET_BIG_NAME "elf32-bigarm-vxworks"
10678 /* Like elf32_arm_link_hash_table_create -- but overrides
10679 appropriately for VxWorks. */
10680 static struct bfd_link_hash_table *
10681 elf32_arm_vxworks_link_hash_table_create (bfd *abfd)
10683 struct bfd_link_hash_table *ret;
10685 ret = elf32_arm_link_hash_table_create (abfd);
10686 if (ret)
10688 struct elf32_arm_link_hash_table *htab
10689 = (struct elf32_arm_link_hash_table *) ret;
10690 htab->use_rel = 0;
10691 htab->vxworks_p = 1;
10693 return ret;
10696 static void
10697 elf32_arm_vxworks_final_write_processing (bfd *abfd, bfd_boolean linker)
10699 elf32_arm_final_write_processing (abfd, linker);
10700 elf_vxworks_final_write_processing (abfd, linker);
10703 #undef elf32_bed
10704 #define elf32_bed elf32_arm_vxworks_bed
10706 #undef bfd_elf32_bfd_link_hash_table_create
10707 #define bfd_elf32_bfd_link_hash_table_create \
10708 elf32_arm_vxworks_link_hash_table_create
10709 #undef elf_backend_add_symbol_hook
10710 #define elf_backend_add_symbol_hook \
10711 elf_vxworks_add_symbol_hook
10712 #undef elf_backend_final_write_processing
10713 #define elf_backend_final_write_processing \
10714 elf32_arm_vxworks_final_write_processing
10715 #undef elf_backend_emit_relocs
10716 #define elf_backend_emit_relocs \
10717 elf_vxworks_emit_relocs
10719 #undef elf_backend_may_use_rel_p
10720 #define elf_backend_may_use_rel_p 0
10721 #undef elf_backend_may_use_rela_p
10722 #define elf_backend_may_use_rela_p 1
10723 #undef elf_backend_default_use_rela_p
10724 #define elf_backend_default_use_rela_p 1
10725 #undef elf_backend_want_plt_sym
10726 #define elf_backend_want_plt_sym 1
10727 #undef ELF_MAXPAGESIZE
10728 #define ELF_MAXPAGESIZE 0x1000
10730 #include "elf32-target.h"
10733 /* Symbian OS Targets */
10735 #undef TARGET_LITTLE_SYM
10736 #define TARGET_LITTLE_SYM bfd_elf32_littlearm_symbian_vec
10737 #undef TARGET_LITTLE_NAME
10738 #define TARGET_LITTLE_NAME "elf32-littlearm-symbian"
10739 #undef TARGET_BIG_SYM
10740 #define TARGET_BIG_SYM bfd_elf32_bigarm_symbian_vec
10741 #undef TARGET_BIG_NAME
10742 #define TARGET_BIG_NAME "elf32-bigarm-symbian"
10744 /* Like elf32_arm_link_hash_table_create -- but overrides
10745 appropriately for Symbian OS. */
10746 static struct bfd_link_hash_table *
10747 elf32_arm_symbian_link_hash_table_create (bfd *abfd)
10749 struct bfd_link_hash_table *ret;
10751 ret = elf32_arm_link_hash_table_create (abfd);
10752 if (ret)
10754 struct elf32_arm_link_hash_table *htab
10755 = (struct elf32_arm_link_hash_table *)ret;
10756 /* There is no PLT header for Symbian OS. */
10757 htab->plt_header_size = 0;
10758 /* The PLT entries are each three instructions. */
10759 htab->plt_entry_size = 4 * NUM_ELEM (elf32_arm_symbian_plt_entry);
10760 htab->symbian_p = 1;
10761 /* Symbian uses armv5t or above, so use_blx is always true. */
10762 htab->use_blx = 1;
10763 htab->root.is_relocatable_executable = 1;
10765 return ret;
10768 static const struct bfd_elf_special_section
10769 elf32_arm_symbian_special_sections[] =
10771 /* In a BPABI executable, the dynamic linking sections do not go in
10772 the loadable read-only segment. The post-linker may wish to
10773 refer to these sections, but they are not part of the final
10774 program image. */
10775 { STRING_COMMA_LEN (".dynamic"), 0, SHT_DYNAMIC, 0 },
10776 { STRING_COMMA_LEN (".dynstr"), 0, SHT_STRTAB, 0 },
10777 { STRING_COMMA_LEN (".dynsym"), 0, SHT_DYNSYM, 0 },
10778 { STRING_COMMA_LEN (".got"), 0, SHT_PROGBITS, 0 },
10779 { STRING_COMMA_LEN (".hash"), 0, SHT_HASH, 0 },
10780 /* These sections do not need to be writable as the SymbianOS
10781 postlinker will arrange things so that no dynamic relocation is
10782 required. */
10783 { STRING_COMMA_LEN (".init_array"), 0, SHT_INIT_ARRAY, SHF_ALLOC },
10784 { STRING_COMMA_LEN (".fini_array"), 0, SHT_FINI_ARRAY, SHF_ALLOC },
10785 { STRING_COMMA_LEN (".preinit_array"), 0, SHT_PREINIT_ARRAY, SHF_ALLOC },
10786 { NULL, 0, 0, 0, 0 }
10789 static void
10790 elf32_arm_symbian_begin_write_processing (bfd *abfd,
10791 struct bfd_link_info *link_info)
10793 /* BPABI objects are never loaded directly by an OS kernel; they are
10794 processed by a postlinker first, into an OS-specific format. If
10795 the D_PAGED bit is set on the file, BFD will align segments on
10796 page boundaries, so that an OS can directly map the file. With
10797 BPABI objects, that just results in wasted space. In addition,
10798 because we clear the D_PAGED bit, map_sections_to_segments will
10799 recognize that the program headers should not be mapped into any
10800 loadable segment. */
10801 abfd->flags &= ~D_PAGED;
10802 elf32_arm_begin_write_processing(abfd, link_info);
10805 static bfd_boolean
10806 elf32_arm_symbian_modify_segment_map (bfd *abfd,
10807 struct bfd_link_info *info)
10809 struct elf_segment_map *m;
10810 asection *dynsec;
10812 /* BPABI shared libraries and executables should have a PT_DYNAMIC
10813 segment. However, because the .dynamic section is not marked
10814 with SEC_LOAD, the generic ELF code will not create such a
10815 segment. */
10816 dynsec = bfd_get_section_by_name (abfd, ".dynamic");
10817 if (dynsec)
10819 for (m = elf_tdata (abfd)->segment_map; m != NULL; m = m->next)
10820 if (m->p_type == PT_DYNAMIC)
10821 break;
10823 if (m == NULL)
10825 m = _bfd_elf_make_dynamic_segment (abfd, dynsec);
10826 m->next = elf_tdata (abfd)->segment_map;
10827 elf_tdata (abfd)->segment_map = m;
10831 /* Also call the generic arm routine. */
10832 return elf32_arm_modify_segment_map (abfd, info);
10835 #undef elf32_bed
10836 #define elf32_bed elf32_arm_symbian_bed
10838 /* The dynamic sections are not allocated on SymbianOS; the postlinker
10839 will process them and then discard them. */
10840 #undef ELF_DYNAMIC_SEC_FLAGS
10841 #define ELF_DYNAMIC_SEC_FLAGS \
10842 (SEC_HAS_CONTENTS | SEC_IN_MEMORY | SEC_LINKER_CREATED)
10844 #undef bfd_elf32_bfd_link_hash_table_create
10845 #define bfd_elf32_bfd_link_hash_table_create \
10846 elf32_arm_symbian_link_hash_table_create
10847 #undef elf_backend_add_symbol_hook
10849 #undef elf_backend_special_sections
10850 #define elf_backend_special_sections elf32_arm_symbian_special_sections
10852 #undef elf_backend_begin_write_processing
10853 #define elf_backend_begin_write_processing \
10854 elf32_arm_symbian_begin_write_processing
10855 #undef elf_backend_final_write_processing
10856 #define elf_backend_final_write_processing \
10857 elf32_arm_final_write_processing
10858 #undef elf_backend_emit_relocs
10860 #undef elf_backend_modify_segment_map
10861 #define elf_backend_modify_segment_map elf32_arm_symbian_modify_segment_map
10863 /* There is no .got section for BPABI objects, and hence no header. */
10864 #undef elf_backend_got_header_size
10865 #define elf_backend_got_header_size 0
10867 /* Similarly, there is no .got.plt section. */
10868 #undef elf_backend_want_got_plt
10869 #define elf_backend_want_got_plt 0
10871 #undef elf_backend_may_use_rel_p
10872 #define elf_backend_may_use_rel_p 1
10873 #undef elf_backend_may_use_rela_p
10874 #define elf_backend_may_use_rela_p 0
10875 #undef elf_backend_default_use_rela_p
10876 #define elf_backend_default_use_rela_p 0
10877 #undef elf_backend_want_plt_sym
10878 #define elf_backend_want_plt_sym 0
10879 #undef ELF_MAXPAGESIZE
10880 #define ELF_MAXPAGESIZE 0x8000
10882 #include "elf32-target.h"