Add comment missing from previous patch.
[binutils.git] / bfd / elf32-arm.c
blob7cea9406f514678d331dbc0071baa29d51eb6c9f
1 /* 32-bit ELF support for ARM
2 Copyright 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006
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 "bfd.h"
22 #include "sysdep.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 /* FIXME: Has two more bits of offset in Thumb32. */
221 HOWTO (R_ARM_THM_CALL, /* type */
222 1, /* rightshift */
223 2, /* size (0 = byte, 1 = short, 2 = long) */
224 23, /* bitsize */
225 TRUE, /* pc_relative */
226 0, /* bitpos */
227 complain_overflow_signed,/* complain_on_overflow */
228 bfd_elf_generic_reloc, /* special_function */
229 "R_ARM_THM_CALL", /* name */
230 FALSE, /* partial_inplace */
231 0x07ff07ff, /* src_mask */
232 0x07ff07ff, /* dst_mask */
233 TRUE), /* pcrel_offset */
235 HOWTO (R_ARM_THM_PC8, /* type */
236 1, /* rightshift */
237 1, /* size (0 = byte, 1 = short, 2 = long) */
238 8, /* bitsize */
239 TRUE, /* pc_relative */
240 0, /* bitpos */
241 complain_overflow_signed,/* complain_on_overflow */
242 bfd_elf_generic_reloc, /* special_function */
243 "R_ARM_THM_PC8", /* name */
244 FALSE, /* partial_inplace */
245 0x000000ff, /* src_mask */
246 0x000000ff, /* dst_mask */
247 TRUE), /* pcrel_offset */
249 HOWTO (R_ARM_BREL_ADJ, /* type */
250 1, /* rightshift */
251 1, /* size (0 = byte, 1 = short, 2 = long) */
252 32, /* bitsize */
253 FALSE, /* pc_relative */
254 0, /* bitpos */
255 complain_overflow_signed,/* complain_on_overflow */
256 bfd_elf_generic_reloc, /* special_function */
257 "R_ARM_BREL_ADJ", /* name */
258 FALSE, /* partial_inplace */
259 0xffffffff, /* src_mask */
260 0xffffffff, /* dst_mask */
261 FALSE), /* pcrel_offset */
263 HOWTO (R_ARM_SWI24, /* type */
264 0, /* rightshift */
265 0, /* size (0 = byte, 1 = short, 2 = long) */
266 0, /* bitsize */
267 FALSE, /* pc_relative */
268 0, /* bitpos */
269 complain_overflow_signed,/* complain_on_overflow */
270 bfd_elf_generic_reloc, /* special_function */
271 "R_ARM_SWI24", /* name */
272 FALSE, /* partial_inplace */
273 0x00000000, /* src_mask */
274 0x00000000, /* dst_mask */
275 FALSE), /* pcrel_offset */
277 HOWTO (R_ARM_THM_SWI8, /* type */
278 0, /* rightshift */
279 0, /* size (0 = byte, 1 = short, 2 = long) */
280 0, /* bitsize */
281 FALSE, /* pc_relative */
282 0, /* bitpos */
283 complain_overflow_signed,/* complain_on_overflow */
284 bfd_elf_generic_reloc, /* special_function */
285 "R_ARM_SWI8", /* name */
286 FALSE, /* partial_inplace */
287 0x00000000, /* src_mask */
288 0x00000000, /* dst_mask */
289 FALSE), /* pcrel_offset */
291 /* BLX instruction for the ARM. */
292 HOWTO (R_ARM_XPC25, /* type */
293 2, /* rightshift */
294 2, /* size (0 = byte, 1 = short, 2 = long) */
295 25, /* bitsize */
296 TRUE, /* pc_relative */
297 0, /* bitpos */
298 complain_overflow_signed,/* complain_on_overflow */
299 bfd_elf_generic_reloc, /* special_function */
300 "R_ARM_XPC25", /* name */
301 FALSE, /* partial_inplace */
302 0x00ffffff, /* src_mask */
303 0x00ffffff, /* dst_mask */
304 TRUE), /* pcrel_offset */
306 /* BLX instruction for the Thumb. */
307 HOWTO (R_ARM_THM_XPC22, /* type */
308 2, /* rightshift */
309 2, /* size (0 = byte, 1 = short, 2 = long) */
310 22, /* bitsize */
311 TRUE, /* pc_relative */
312 0, /* bitpos */
313 complain_overflow_signed,/* complain_on_overflow */
314 bfd_elf_generic_reloc, /* special_function */
315 "R_ARM_THM_XPC22", /* name */
316 FALSE, /* partial_inplace */
317 0x07ff07ff, /* src_mask */
318 0x07ff07ff, /* dst_mask */
319 TRUE), /* pcrel_offset */
321 /* Dynamic TLS relocations. */
323 HOWTO (R_ARM_TLS_DTPMOD32, /* type */
324 0, /* rightshift */
325 2, /* size (0 = byte, 1 = short, 2 = long) */
326 32, /* bitsize */
327 FALSE, /* pc_relative */
328 0, /* bitpos */
329 complain_overflow_bitfield,/* complain_on_overflow */
330 bfd_elf_generic_reloc, /* special_function */
331 "R_ARM_TLS_DTPMOD32", /* name */
332 TRUE, /* partial_inplace */
333 0xffffffff, /* src_mask */
334 0xffffffff, /* dst_mask */
335 FALSE), /* pcrel_offset */
337 HOWTO (R_ARM_TLS_DTPOFF32, /* type */
338 0, /* rightshift */
339 2, /* size (0 = byte, 1 = short, 2 = long) */
340 32, /* bitsize */
341 FALSE, /* pc_relative */
342 0, /* bitpos */
343 complain_overflow_bitfield,/* complain_on_overflow */
344 bfd_elf_generic_reloc, /* special_function */
345 "R_ARM_TLS_DTPOFF32", /* name */
346 TRUE, /* partial_inplace */
347 0xffffffff, /* src_mask */
348 0xffffffff, /* dst_mask */
349 FALSE), /* pcrel_offset */
351 HOWTO (R_ARM_TLS_TPOFF32, /* type */
352 0, /* rightshift */
353 2, /* size (0 = byte, 1 = short, 2 = long) */
354 32, /* bitsize */
355 FALSE, /* pc_relative */
356 0, /* bitpos */
357 complain_overflow_bitfield,/* complain_on_overflow */
358 bfd_elf_generic_reloc, /* special_function */
359 "R_ARM_TLS_TPOFF32", /* name */
360 TRUE, /* partial_inplace */
361 0xffffffff, /* src_mask */
362 0xffffffff, /* dst_mask */
363 FALSE), /* pcrel_offset */
365 /* Relocs used in ARM Linux */
367 HOWTO (R_ARM_COPY, /* type */
368 0, /* rightshift */
369 2, /* size (0 = byte, 1 = short, 2 = long) */
370 32, /* bitsize */
371 FALSE, /* pc_relative */
372 0, /* bitpos */
373 complain_overflow_bitfield,/* complain_on_overflow */
374 bfd_elf_generic_reloc, /* special_function */
375 "R_ARM_COPY", /* name */
376 TRUE, /* partial_inplace */
377 0xffffffff, /* src_mask */
378 0xffffffff, /* dst_mask */
379 FALSE), /* pcrel_offset */
381 HOWTO (R_ARM_GLOB_DAT, /* type */
382 0, /* rightshift */
383 2, /* size (0 = byte, 1 = short, 2 = long) */
384 32, /* bitsize */
385 FALSE, /* pc_relative */
386 0, /* bitpos */
387 complain_overflow_bitfield,/* complain_on_overflow */
388 bfd_elf_generic_reloc, /* special_function */
389 "R_ARM_GLOB_DAT", /* name */
390 TRUE, /* partial_inplace */
391 0xffffffff, /* src_mask */
392 0xffffffff, /* dst_mask */
393 FALSE), /* pcrel_offset */
395 HOWTO (R_ARM_JUMP_SLOT, /* type */
396 0, /* rightshift */
397 2, /* size (0 = byte, 1 = short, 2 = long) */
398 32, /* bitsize */
399 FALSE, /* pc_relative */
400 0, /* bitpos */
401 complain_overflow_bitfield,/* complain_on_overflow */
402 bfd_elf_generic_reloc, /* special_function */
403 "R_ARM_JUMP_SLOT", /* name */
404 TRUE, /* partial_inplace */
405 0xffffffff, /* src_mask */
406 0xffffffff, /* dst_mask */
407 FALSE), /* pcrel_offset */
409 HOWTO (R_ARM_RELATIVE, /* type */
410 0, /* rightshift */
411 2, /* size (0 = byte, 1 = short, 2 = long) */
412 32, /* bitsize */
413 FALSE, /* pc_relative */
414 0, /* bitpos */
415 complain_overflow_bitfield,/* complain_on_overflow */
416 bfd_elf_generic_reloc, /* special_function */
417 "R_ARM_RELATIVE", /* name */
418 TRUE, /* partial_inplace */
419 0xffffffff, /* src_mask */
420 0xffffffff, /* dst_mask */
421 FALSE), /* pcrel_offset */
423 HOWTO (R_ARM_GOTOFF32, /* type */
424 0, /* rightshift */
425 2, /* size (0 = byte, 1 = short, 2 = long) */
426 32, /* bitsize */
427 FALSE, /* pc_relative */
428 0, /* bitpos */
429 complain_overflow_bitfield,/* complain_on_overflow */
430 bfd_elf_generic_reloc, /* special_function */
431 "R_ARM_GOTOFF32", /* name */
432 TRUE, /* partial_inplace */
433 0xffffffff, /* src_mask */
434 0xffffffff, /* dst_mask */
435 FALSE), /* pcrel_offset */
437 HOWTO (R_ARM_GOTPC, /* type */
438 0, /* rightshift */
439 2, /* size (0 = byte, 1 = short, 2 = long) */
440 32, /* bitsize */
441 TRUE, /* pc_relative */
442 0, /* bitpos */
443 complain_overflow_bitfield,/* complain_on_overflow */
444 bfd_elf_generic_reloc, /* special_function */
445 "R_ARM_GOTPC", /* name */
446 TRUE, /* partial_inplace */
447 0xffffffff, /* src_mask */
448 0xffffffff, /* dst_mask */
449 TRUE), /* pcrel_offset */
451 HOWTO (R_ARM_GOT32, /* type */
452 0, /* rightshift */
453 2, /* size (0 = byte, 1 = short, 2 = long) */
454 32, /* bitsize */
455 FALSE, /* pc_relative */
456 0, /* bitpos */
457 complain_overflow_bitfield,/* complain_on_overflow */
458 bfd_elf_generic_reloc, /* special_function */
459 "R_ARM_GOT32", /* name */
460 TRUE, /* partial_inplace */
461 0xffffffff, /* src_mask */
462 0xffffffff, /* dst_mask */
463 FALSE), /* pcrel_offset */
465 HOWTO (R_ARM_PLT32, /* type */
466 2, /* rightshift */
467 2, /* size (0 = byte, 1 = short, 2 = long) */
468 24, /* bitsize */
469 TRUE, /* pc_relative */
470 0, /* bitpos */
471 complain_overflow_bitfield,/* complain_on_overflow */
472 bfd_elf_generic_reloc, /* special_function */
473 "R_ARM_PLT32", /* name */
474 FALSE, /* partial_inplace */
475 0x00ffffff, /* src_mask */
476 0x00ffffff, /* dst_mask */
477 TRUE), /* pcrel_offset */
479 HOWTO (R_ARM_CALL, /* type */
480 2, /* rightshift */
481 2, /* size (0 = byte, 1 = short, 2 = long) */
482 24, /* bitsize */
483 TRUE, /* pc_relative */
484 0, /* bitpos */
485 complain_overflow_signed,/* complain_on_overflow */
486 bfd_elf_generic_reloc, /* special_function */
487 "R_ARM_CALL", /* name */
488 FALSE, /* partial_inplace */
489 0x00ffffff, /* src_mask */
490 0x00ffffff, /* dst_mask */
491 TRUE), /* pcrel_offset */
493 HOWTO (R_ARM_JUMP24, /* type */
494 2, /* rightshift */
495 2, /* size (0 = byte, 1 = short, 2 = long) */
496 24, /* bitsize */
497 TRUE, /* pc_relative */
498 0, /* bitpos */
499 complain_overflow_signed,/* complain_on_overflow */
500 bfd_elf_generic_reloc, /* special_function */
501 "R_ARM_JUMP24", /* name */
502 FALSE, /* partial_inplace */
503 0x00ffffff, /* src_mask */
504 0x00ffffff, /* dst_mask */
505 TRUE), /* pcrel_offset */
507 HOWTO (R_ARM_THM_JUMP24, /* type */
508 1, /* rightshift */
509 2, /* size (0 = byte, 1 = short, 2 = long) */
510 24, /* bitsize */
511 TRUE, /* pc_relative */
512 0, /* bitpos */
513 complain_overflow_signed,/* complain_on_overflow */
514 bfd_elf_generic_reloc, /* special_function */
515 "R_ARM_THM_JUMP24", /* name */
516 FALSE, /* partial_inplace */
517 0x07ff2fff, /* src_mask */
518 0x07ff2fff, /* dst_mask */
519 TRUE), /* pcrel_offset */
521 HOWTO (R_ARM_BASE_ABS, /* type */
522 0, /* rightshift */
523 2, /* size (0 = byte, 1 = short, 2 = long) */
524 32, /* bitsize */
525 FALSE, /* pc_relative */
526 0, /* bitpos */
527 complain_overflow_dont,/* complain_on_overflow */
528 bfd_elf_generic_reloc, /* special_function */
529 "R_ARM_BASE_ABS", /* name */
530 FALSE, /* partial_inplace */
531 0xffffffff, /* src_mask */
532 0xffffffff, /* dst_mask */
533 FALSE), /* pcrel_offset */
535 HOWTO (R_ARM_ALU_PCREL7_0, /* type */
536 0, /* rightshift */
537 2, /* size (0 = byte, 1 = short, 2 = long) */
538 12, /* bitsize */
539 TRUE, /* pc_relative */
540 0, /* bitpos */
541 complain_overflow_dont,/* complain_on_overflow */
542 bfd_elf_generic_reloc, /* special_function */
543 "R_ARM_ALU_PCREL_7_0", /* name */
544 FALSE, /* partial_inplace */
545 0x00000fff, /* src_mask */
546 0x00000fff, /* dst_mask */
547 TRUE), /* pcrel_offset */
549 HOWTO (R_ARM_ALU_PCREL15_8, /* type */
550 0, /* rightshift */
551 2, /* size (0 = byte, 1 = short, 2 = long) */
552 12, /* bitsize */
553 TRUE, /* pc_relative */
554 8, /* bitpos */
555 complain_overflow_dont,/* complain_on_overflow */
556 bfd_elf_generic_reloc, /* special_function */
557 "R_ARM_ALU_PCREL_15_8",/* name */
558 FALSE, /* partial_inplace */
559 0x00000fff, /* src_mask */
560 0x00000fff, /* dst_mask */
561 TRUE), /* pcrel_offset */
563 HOWTO (R_ARM_ALU_PCREL23_15, /* type */
564 0, /* rightshift */
565 2, /* size (0 = byte, 1 = short, 2 = long) */
566 12, /* bitsize */
567 TRUE, /* pc_relative */
568 16, /* bitpos */
569 complain_overflow_dont,/* complain_on_overflow */
570 bfd_elf_generic_reloc, /* special_function */
571 "R_ARM_ALU_PCREL_23_15",/* name */
572 FALSE, /* partial_inplace */
573 0x00000fff, /* src_mask */
574 0x00000fff, /* dst_mask */
575 TRUE), /* pcrel_offset */
577 HOWTO (R_ARM_LDR_SBREL_11_0, /* type */
578 0, /* rightshift */
579 2, /* size (0 = byte, 1 = short, 2 = long) */
580 12, /* bitsize */
581 FALSE, /* pc_relative */
582 0, /* bitpos */
583 complain_overflow_dont,/* complain_on_overflow */
584 bfd_elf_generic_reloc, /* special_function */
585 "R_ARM_LDR_SBREL_11_0",/* name */
586 FALSE, /* partial_inplace */
587 0x00000fff, /* src_mask */
588 0x00000fff, /* dst_mask */
589 FALSE), /* pcrel_offset */
591 HOWTO (R_ARM_ALU_SBREL_19_12, /* type */
592 0, /* rightshift */
593 2, /* size (0 = byte, 1 = short, 2 = long) */
594 8, /* bitsize */
595 FALSE, /* pc_relative */
596 12, /* bitpos */
597 complain_overflow_dont,/* complain_on_overflow */
598 bfd_elf_generic_reloc, /* special_function */
599 "R_ARM_ALU_SBREL_19_12",/* name */
600 FALSE, /* partial_inplace */
601 0x000ff000, /* src_mask */
602 0x000ff000, /* dst_mask */
603 FALSE), /* pcrel_offset */
605 HOWTO (R_ARM_ALU_SBREL_27_20, /* type */
606 0, /* rightshift */
607 2, /* size (0 = byte, 1 = short, 2 = long) */
608 8, /* bitsize */
609 FALSE, /* pc_relative */
610 20, /* bitpos */
611 complain_overflow_dont,/* complain_on_overflow */
612 bfd_elf_generic_reloc, /* special_function */
613 "R_ARM_ALU_SBREL_27_20",/* name */
614 FALSE, /* partial_inplace */
615 0x0ff00000, /* src_mask */
616 0x0ff00000, /* dst_mask */
617 FALSE), /* pcrel_offset */
619 HOWTO (R_ARM_TARGET1, /* type */
620 0, /* rightshift */
621 2, /* size (0 = byte, 1 = short, 2 = long) */
622 32, /* bitsize */
623 FALSE, /* pc_relative */
624 0, /* bitpos */
625 complain_overflow_dont,/* complain_on_overflow */
626 bfd_elf_generic_reloc, /* special_function */
627 "R_ARM_TARGET1", /* name */
628 FALSE, /* partial_inplace */
629 0xffffffff, /* src_mask */
630 0xffffffff, /* dst_mask */
631 FALSE), /* pcrel_offset */
633 HOWTO (R_ARM_ROSEGREL32, /* type */
634 0, /* rightshift */
635 2, /* size (0 = byte, 1 = short, 2 = long) */
636 32, /* bitsize */
637 FALSE, /* pc_relative */
638 0, /* bitpos */
639 complain_overflow_dont,/* complain_on_overflow */
640 bfd_elf_generic_reloc, /* special_function */
641 "R_ARM_ROSEGREL32", /* name */
642 FALSE, /* partial_inplace */
643 0xffffffff, /* src_mask */
644 0xffffffff, /* dst_mask */
645 FALSE), /* pcrel_offset */
647 HOWTO (R_ARM_V4BX, /* type */
648 0, /* rightshift */
649 2, /* size (0 = byte, 1 = short, 2 = long) */
650 32, /* bitsize */
651 FALSE, /* pc_relative */
652 0, /* bitpos */
653 complain_overflow_dont,/* complain_on_overflow */
654 bfd_elf_generic_reloc, /* special_function */
655 "R_ARM_V4BX", /* name */
656 FALSE, /* partial_inplace */
657 0xffffffff, /* src_mask */
658 0xffffffff, /* dst_mask */
659 FALSE), /* pcrel_offset */
661 HOWTO (R_ARM_TARGET2, /* type */
662 0, /* rightshift */
663 2, /* size (0 = byte, 1 = short, 2 = long) */
664 32, /* bitsize */
665 FALSE, /* pc_relative */
666 0, /* bitpos */
667 complain_overflow_signed,/* complain_on_overflow */
668 bfd_elf_generic_reloc, /* special_function */
669 "R_ARM_TARGET2", /* name */
670 FALSE, /* partial_inplace */
671 0xffffffff, /* src_mask */
672 0xffffffff, /* dst_mask */
673 TRUE), /* pcrel_offset */
675 HOWTO (R_ARM_PREL31, /* type */
676 0, /* rightshift */
677 2, /* size (0 = byte, 1 = short, 2 = long) */
678 31, /* bitsize */
679 TRUE, /* pc_relative */
680 0, /* bitpos */
681 complain_overflow_signed,/* complain_on_overflow */
682 bfd_elf_generic_reloc, /* special_function */
683 "R_ARM_PREL31", /* name */
684 FALSE, /* partial_inplace */
685 0x7fffffff, /* src_mask */
686 0x7fffffff, /* dst_mask */
687 TRUE), /* pcrel_offset */
689 HOWTO (R_ARM_MOVW_ABS_NC, /* type */
690 0, /* rightshift */
691 2, /* size (0 = byte, 1 = short, 2 = long) */
692 16, /* bitsize */
693 FALSE, /* pc_relative */
694 0, /* bitpos */
695 complain_overflow_dont,/* complain_on_overflow */
696 bfd_elf_generic_reloc, /* special_function */
697 "R_ARM_MOVW_ABS_NC", /* name */
698 FALSE, /* partial_inplace */
699 0x0000ffff, /* src_mask */
700 0x0000ffff, /* dst_mask */
701 FALSE), /* pcrel_offset */
703 HOWTO (R_ARM_MOVT_ABS, /* type */
704 0, /* rightshift */
705 2, /* size (0 = byte, 1 = short, 2 = long) */
706 16, /* bitsize */
707 FALSE, /* pc_relative */
708 0, /* bitpos */
709 complain_overflow_bitfield,/* complain_on_overflow */
710 bfd_elf_generic_reloc, /* special_function */
711 "R_ARM_MOVT_ABS", /* name */
712 FALSE, /* partial_inplace */
713 0x0000ffff, /* src_mask */
714 0x0000ffff, /* dst_mask */
715 FALSE), /* pcrel_offset */
717 HOWTO (R_ARM_MOVW_PREL_NC, /* type */
718 0, /* rightshift */
719 2, /* size (0 = byte, 1 = short, 2 = long) */
720 16, /* bitsize */
721 TRUE, /* pc_relative */
722 0, /* bitpos */
723 complain_overflow_dont,/* complain_on_overflow */
724 bfd_elf_generic_reloc, /* special_function */
725 "R_ARM_MOVW_PREL_NC", /* name */
726 FALSE, /* partial_inplace */
727 0x0000ffff, /* src_mask */
728 0x0000ffff, /* dst_mask */
729 TRUE), /* pcrel_offset */
731 HOWTO (R_ARM_MOVT_PREL, /* type */
732 0, /* rightshift */
733 2, /* size (0 = byte, 1 = short, 2 = long) */
734 16, /* bitsize */
735 TRUE, /* pc_relative */
736 0, /* bitpos */
737 complain_overflow_bitfield,/* complain_on_overflow */
738 bfd_elf_generic_reloc, /* special_function */
739 "R_ARM_MOVT_PREL", /* name */
740 FALSE, /* partial_inplace */
741 0x0000ffff, /* src_mask */
742 0x0000ffff, /* dst_mask */
743 TRUE), /* pcrel_offset */
745 HOWTO (R_ARM_THM_MOVW_ABS_NC, /* type */
746 0, /* rightshift */
747 2, /* size (0 = byte, 1 = short, 2 = long) */
748 16, /* bitsize */
749 FALSE, /* pc_relative */
750 0, /* bitpos */
751 complain_overflow_dont,/* complain_on_overflow */
752 bfd_elf_generic_reloc, /* special_function */
753 "R_ARM_THM_MOVW_ABS_NC",/* name */
754 FALSE, /* partial_inplace */
755 0x040f70ff, /* src_mask */
756 0x040f70ff, /* dst_mask */
757 FALSE), /* pcrel_offset */
759 HOWTO (R_ARM_THM_MOVT_ABS, /* type */
760 0, /* rightshift */
761 2, /* size (0 = byte, 1 = short, 2 = long) */
762 16, /* bitsize */
763 FALSE, /* pc_relative */
764 0, /* bitpos */
765 complain_overflow_bitfield,/* complain_on_overflow */
766 bfd_elf_generic_reloc, /* special_function */
767 "R_ARM_THM_MOVT_ABS", /* name */
768 FALSE, /* partial_inplace */
769 0x040f70ff, /* src_mask */
770 0x040f70ff, /* dst_mask */
771 FALSE), /* pcrel_offset */
773 HOWTO (R_ARM_THM_MOVW_PREL_NC,/* type */
774 0, /* rightshift */
775 2, /* size (0 = byte, 1 = short, 2 = long) */
776 16, /* bitsize */
777 TRUE, /* pc_relative */
778 0, /* bitpos */
779 complain_overflow_dont,/* complain_on_overflow */
780 bfd_elf_generic_reloc, /* special_function */
781 "R_ARM_THM_MOVW_PREL_NC",/* name */
782 FALSE, /* partial_inplace */
783 0x040f70ff, /* src_mask */
784 0x040f70ff, /* dst_mask */
785 TRUE), /* pcrel_offset */
787 HOWTO (R_ARM_THM_MOVT_PREL, /* type */
788 0, /* rightshift */
789 2, /* size (0 = byte, 1 = short, 2 = long) */
790 16, /* bitsize */
791 TRUE, /* pc_relative */
792 0, /* bitpos */
793 complain_overflow_bitfield,/* complain_on_overflow */
794 bfd_elf_generic_reloc, /* special_function */
795 "R_ARM_THM_MOVT_PREL", /* name */
796 FALSE, /* partial_inplace */
797 0x040f70ff, /* src_mask */
798 0x040f70ff, /* dst_mask */
799 TRUE), /* pcrel_offset */
801 HOWTO (R_ARM_THM_JUMP19, /* type */
802 1, /* rightshift */
803 2, /* size (0 = byte, 1 = short, 2 = long) */
804 19, /* bitsize */
805 TRUE, /* pc_relative */
806 0, /* bitpos */
807 complain_overflow_signed,/* complain_on_overflow */
808 bfd_elf_generic_reloc, /* special_function */
809 "R_ARM_THM_JUMP19", /* name */
810 FALSE, /* partial_inplace */
811 0x043f2fff, /* src_mask */
812 0x043f2fff, /* dst_mask */
813 TRUE), /* pcrel_offset */
815 HOWTO (R_ARM_THM_JUMP6, /* type */
816 1, /* rightshift */
817 1, /* size (0 = byte, 1 = short, 2 = long) */
818 6, /* bitsize */
819 TRUE, /* pc_relative */
820 0, /* bitpos */
821 complain_overflow_unsigned,/* complain_on_overflow */
822 bfd_elf_generic_reloc, /* special_function */
823 "R_ARM_THM_JUMP6", /* name */
824 FALSE, /* partial_inplace */
825 0x02f8, /* src_mask */
826 0x02f8, /* dst_mask */
827 TRUE), /* pcrel_offset */
829 /* These are declared as 13-bit signed relocations because we can
830 address -4095 .. 4095(base) by altering ADDW to SUBW or vice
831 versa. */
832 HOWTO (R_ARM_THM_ALU_PREL_11_0,/* type */
833 0, /* rightshift */
834 2, /* size (0 = byte, 1 = short, 2 = long) */
835 13, /* bitsize */
836 TRUE, /* pc_relative */
837 0, /* bitpos */
838 complain_overflow_signed,/* complain_on_overflow */
839 bfd_elf_generic_reloc, /* special_function */
840 "R_ARM_THM_ALU_PREL_11_0",/* name */
841 FALSE, /* partial_inplace */
842 0x040070ff, /* src_mask */
843 0x040070ff, /* dst_mask */
844 TRUE), /* pcrel_offset */
846 HOWTO (R_ARM_THM_PC12, /* type */
847 0, /* rightshift */
848 2, /* size (0 = byte, 1 = short, 2 = long) */
849 13, /* bitsize */
850 TRUE, /* pc_relative */
851 0, /* bitpos */
852 complain_overflow_signed,/* complain_on_overflow */
853 bfd_elf_generic_reloc, /* special_function */
854 "R_ARM_THM_PC12", /* name */
855 FALSE, /* partial_inplace */
856 0x040070ff, /* src_mask */
857 0x040070ff, /* dst_mask */
858 TRUE), /* pcrel_offset */
860 HOWTO (R_ARM_ABS32_NOI, /* type */
861 0, /* rightshift */
862 2, /* size (0 = byte, 1 = short, 2 = long) */
863 32, /* bitsize */
864 FALSE, /* pc_relative */
865 0, /* bitpos */
866 complain_overflow_dont,/* complain_on_overflow */
867 bfd_elf_generic_reloc, /* special_function */
868 "R_ARM_ABS32_NOI", /* name */
869 FALSE, /* partial_inplace */
870 0xffffffff, /* src_mask */
871 0xffffffff, /* dst_mask */
872 FALSE), /* pcrel_offset */
874 HOWTO (R_ARM_REL32_NOI, /* type */
875 0, /* rightshift */
876 2, /* size (0 = byte, 1 = short, 2 = long) */
877 32, /* bitsize */
878 TRUE, /* pc_relative */
879 0, /* bitpos */
880 complain_overflow_dont,/* complain_on_overflow */
881 bfd_elf_generic_reloc, /* special_function */
882 "R_ARM_REL32_NOI", /* name */
883 FALSE, /* partial_inplace */
884 0xffffffff, /* src_mask */
885 0xffffffff, /* dst_mask */
886 FALSE), /* pcrel_offset */
888 /* Group relocations. */
890 HOWTO (R_ARM_ALU_PC_G0_NC, /* type */
891 0, /* rightshift */
892 2, /* size (0 = byte, 1 = short, 2 = long) */
893 32, /* bitsize */
894 TRUE, /* pc_relative */
895 0, /* bitpos */
896 complain_overflow_dont,/* complain_on_overflow */
897 bfd_elf_generic_reloc, /* special_function */
898 "R_ARM_ALU_PC_G0_NC", /* name */
899 FALSE, /* partial_inplace */
900 0xffffffff, /* src_mask */
901 0xffffffff, /* dst_mask */
902 TRUE), /* pcrel_offset */
904 HOWTO (R_ARM_ALU_PC_G0, /* type */
905 0, /* rightshift */
906 2, /* size (0 = byte, 1 = short, 2 = long) */
907 32, /* bitsize */
908 TRUE, /* pc_relative */
909 0, /* bitpos */
910 complain_overflow_dont,/* complain_on_overflow */
911 bfd_elf_generic_reloc, /* special_function */
912 "R_ARM_ALU_PC_G0", /* name */
913 FALSE, /* partial_inplace */
914 0xffffffff, /* src_mask */
915 0xffffffff, /* dst_mask */
916 TRUE), /* pcrel_offset */
918 HOWTO (R_ARM_ALU_PC_G1_NC, /* type */
919 0, /* rightshift */
920 2, /* size (0 = byte, 1 = short, 2 = long) */
921 32, /* bitsize */
922 TRUE, /* pc_relative */
923 0, /* bitpos */
924 complain_overflow_dont,/* complain_on_overflow */
925 bfd_elf_generic_reloc, /* special_function */
926 "R_ARM_ALU_PC_G1_NC", /* name */
927 FALSE, /* partial_inplace */
928 0xffffffff, /* src_mask */
929 0xffffffff, /* dst_mask */
930 TRUE), /* pcrel_offset */
932 HOWTO (R_ARM_ALU_PC_G1, /* type */
933 0, /* rightshift */
934 2, /* size (0 = byte, 1 = short, 2 = long) */
935 32, /* bitsize */
936 TRUE, /* pc_relative */
937 0, /* bitpos */
938 complain_overflow_dont,/* complain_on_overflow */
939 bfd_elf_generic_reloc, /* special_function */
940 "R_ARM_ALU_PC_G1", /* name */
941 FALSE, /* partial_inplace */
942 0xffffffff, /* src_mask */
943 0xffffffff, /* dst_mask */
944 TRUE), /* pcrel_offset */
946 HOWTO (R_ARM_ALU_PC_G2, /* type */
947 0, /* rightshift */
948 2, /* size (0 = byte, 1 = short, 2 = long) */
949 32, /* bitsize */
950 TRUE, /* pc_relative */
951 0, /* bitpos */
952 complain_overflow_dont,/* complain_on_overflow */
953 bfd_elf_generic_reloc, /* special_function */
954 "R_ARM_ALU_PC_G2", /* name */
955 FALSE, /* partial_inplace */
956 0xffffffff, /* src_mask */
957 0xffffffff, /* dst_mask */
958 TRUE), /* pcrel_offset */
960 HOWTO (R_ARM_LDR_PC_G1, /* type */
961 0, /* rightshift */
962 2, /* size (0 = byte, 1 = short, 2 = long) */
963 32, /* bitsize */
964 TRUE, /* pc_relative */
965 0, /* bitpos */
966 complain_overflow_dont,/* complain_on_overflow */
967 bfd_elf_generic_reloc, /* special_function */
968 "R_ARM_LDR_PC_G1", /* name */
969 FALSE, /* partial_inplace */
970 0xffffffff, /* src_mask */
971 0xffffffff, /* dst_mask */
972 TRUE), /* pcrel_offset */
974 HOWTO (R_ARM_LDR_PC_G2, /* type */
975 0, /* rightshift */
976 2, /* size (0 = byte, 1 = short, 2 = long) */
977 32, /* bitsize */
978 TRUE, /* pc_relative */
979 0, /* bitpos */
980 complain_overflow_dont,/* complain_on_overflow */
981 bfd_elf_generic_reloc, /* special_function */
982 "R_ARM_LDR_PC_G2", /* name */
983 FALSE, /* partial_inplace */
984 0xffffffff, /* src_mask */
985 0xffffffff, /* dst_mask */
986 TRUE), /* pcrel_offset */
988 HOWTO (R_ARM_LDRS_PC_G0, /* type */
989 0, /* rightshift */
990 2, /* size (0 = byte, 1 = short, 2 = long) */
991 32, /* bitsize */
992 TRUE, /* pc_relative */
993 0, /* bitpos */
994 complain_overflow_dont,/* complain_on_overflow */
995 bfd_elf_generic_reloc, /* special_function */
996 "R_ARM_LDRS_PC_G0", /* name */
997 FALSE, /* partial_inplace */
998 0xffffffff, /* src_mask */
999 0xffffffff, /* dst_mask */
1000 TRUE), /* pcrel_offset */
1002 HOWTO (R_ARM_LDRS_PC_G1, /* type */
1003 0, /* rightshift */
1004 2, /* size (0 = byte, 1 = short, 2 = long) */
1005 32, /* bitsize */
1006 TRUE, /* pc_relative */
1007 0, /* bitpos */
1008 complain_overflow_dont,/* complain_on_overflow */
1009 bfd_elf_generic_reloc, /* special_function */
1010 "R_ARM_LDRS_PC_G1", /* name */
1011 FALSE, /* partial_inplace */
1012 0xffffffff, /* src_mask */
1013 0xffffffff, /* dst_mask */
1014 TRUE), /* pcrel_offset */
1016 HOWTO (R_ARM_LDRS_PC_G2, /* type */
1017 0, /* rightshift */
1018 2, /* size (0 = byte, 1 = short, 2 = long) */
1019 32, /* bitsize */
1020 TRUE, /* pc_relative */
1021 0, /* bitpos */
1022 complain_overflow_dont,/* complain_on_overflow */
1023 bfd_elf_generic_reloc, /* special_function */
1024 "R_ARM_LDRS_PC_G2", /* name */
1025 FALSE, /* partial_inplace */
1026 0xffffffff, /* src_mask */
1027 0xffffffff, /* dst_mask */
1028 TRUE), /* pcrel_offset */
1030 HOWTO (R_ARM_LDC_PC_G0, /* type */
1031 0, /* rightshift */
1032 2, /* size (0 = byte, 1 = short, 2 = long) */
1033 32, /* bitsize */
1034 TRUE, /* pc_relative */
1035 0, /* bitpos */
1036 complain_overflow_dont,/* complain_on_overflow */
1037 bfd_elf_generic_reloc, /* special_function */
1038 "R_ARM_LDC_PC_G0", /* name */
1039 FALSE, /* partial_inplace */
1040 0xffffffff, /* src_mask */
1041 0xffffffff, /* dst_mask */
1042 TRUE), /* pcrel_offset */
1044 HOWTO (R_ARM_LDC_PC_G1, /* type */
1045 0, /* rightshift */
1046 2, /* size (0 = byte, 1 = short, 2 = long) */
1047 32, /* bitsize */
1048 TRUE, /* pc_relative */
1049 0, /* bitpos */
1050 complain_overflow_dont,/* complain_on_overflow */
1051 bfd_elf_generic_reloc, /* special_function */
1052 "R_ARM_LDC_PC_G1", /* name */
1053 FALSE, /* partial_inplace */
1054 0xffffffff, /* src_mask */
1055 0xffffffff, /* dst_mask */
1056 TRUE), /* pcrel_offset */
1058 HOWTO (R_ARM_LDC_PC_G2, /* type */
1059 0, /* rightshift */
1060 2, /* size (0 = byte, 1 = short, 2 = long) */
1061 32, /* bitsize */
1062 TRUE, /* pc_relative */
1063 0, /* bitpos */
1064 complain_overflow_dont,/* complain_on_overflow */
1065 bfd_elf_generic_reloc, /* special_function */
1066 "R_ARM_LDC_PC_G2", /* name */
1067 FALSE, /* partial_inplace */
1068 0xffffffff, /* src_mask */
1069 0xffffffff, /* dst_mask */
1070 TRUE), /* pcrel_offset */
1072 HOWTO (R_ARM_ALU_SB_G0_NC, /* type */
1073 0, /* rightshift */
1074 2, /* size (0 = byte, 1 = short, 2 = long) */
1075 32, /* bitsize */
1076 TRUE, /* pc_relative */
1077 0, /* bitpos */
1078 complain_overflow_dont,/* complain_on_overflow */
1079 bfd_elf_generic_reloc, /* special_function */
1080 "R_ARM_ALU_SB_G0_NC", /* name */
1081 FALSE, /* partial_inplace */
1082 0xffffffff, /* src_mask */
1083 0xffffffff, /* dst_mask */
1084 TRUE), /* pcrel_offset */
1086 HOWTO (R_ARM_ALU_SB_G0, /* type */
1087 0, /* rightshift */
1088 2, /* size (0 = byte, 1 = short, 2 = long) */
1089 32, /* bitsize */
1090 TRUE, /* pc_relative */
1091 0, /* bitpos */
1092 complain_overflow_dont,/* complain_on_overflow */
1093 bfd_elf_generic_reloc, /* special_function */
1094 "R_ARM_ALU_SB_G0", /* name */
1095 FALSE, /* partial_inplace */
1096 0xffffffff, /* src_mask */
1097 0xffffffff, /* dst_mask */
1098 TRUE), /* pcrel_offset */
1100 HOWTO (R_ARM_ALU_SB_G1_NC, /* type */
1101 0, /* rightshift */
1102 2, /* size (0 = byte, 1 = short, 2 = long) */
1103 32, /* bitsize */
1104 TRUE, /* pc_relative */
1105 0, /* bitpos */
1106 complain_overflow_dont,/* complain_on_overflow */
1107 bfd_elf_generic_reloc, /* special_function */
1108 "R_ARM_ALU_SB_G1_NC", /* name */
1109 FALSE, /* partial_inplace */
1110 0xffffffff, /* src_mask */
1111 0xffffffff, /* dst_mask */
1112 TRUE), /* pcrel_offset */
1114 HOWTO (R_ARM_ALU_SB_G1, /* type */
1115 0, /* rightshift */
1116 2, /* size (0 = byte, 1 = short, 2 = long) */
1117 32, /* bitsize */
1118 TRUE, /* pc_relative */
1119 0, /* bitpos */
1120 complain_overflow_dont,/* complain_on_overflow */
1121 bfd_elf_generic_reloc, /* special_function */
1122 "R_ARM_ALU_SB_G1", /* name */
1123 FALSE, /* partial_inplace */
1124 0xffffffff, /* src_mask */
1125 0xffffffff, /* dst_mask */
1126 TRUE), /* pcrel_offset */
1128 HOWTO (R_ARM_ALU_SB_G2, /* type */
1129 0, /* rightshift */
1130 2, /* size (0 = byte, 1 = short, 2 = long) */
1131 32, /* bitsize */
1132 TRUE, /* pc_relative */
1133 0, /* bitpos */
1134 complain_overflow_dont,/* complain_on_overflow */
1135 bfd_elf_generic_reloc, /* special_function */
1136 "R_ARM_ALU_SB_G2", /* name */
1137 FALSE, /* partial_inplace */
1138 0xffffffff, /* src_mask */
1139 0xffffffff, /* dst_mask */
1140 TRUE), /* pcrel_offset */
1142 HOWTO (R_ARM_LDR_SB_G0, /* type */
1143 0, /* rightshift */
1144 2, /* size (0 = byte, 1 = short, 2 = long) */
1145 32, /* bitsize */
1146 TRUE, /* pc_relative */
1147 0, /* bitpos */
1148 complain_overflow_dont,/* complain_on_overflow */
1149 bfd_elf_generic_reloc, /* special_function */
1150 "R_ARM_LDR_SB_G0", /* name */
1151 FALSE, /* partial_inplace */
1152 0xffffffff, /* src_mask */
1153 0xffffffff, /* dst_mask */
1154 TRUE), /* pcrel_offset */
1156 HOWTO (R_ARM_LDR_SB_G1, /* type */
1157 0, /* rightshift */
1158 2, /* size (0 = byte, 1 = short, 2 = long) */
1159 32, /* bitsize */
1160 TRUE, /* pc_relative */
1161 0, /* bitpos */
1162 complain_overflow_dont,/* complain_on_overflow */
1163 bfd_elf_generic_reloc, /* special_function */
1164 "R_ARM_LDR_SB_G1", /* name */
1165 FALSE, /* partial_inplace */
1166 0xffffffff, /* src_mask */
1167 0xffffffff, /* dst_mask */
1168 TRUE), /* pcrel_offset */
1170 HOWTO (R_ARM_LDR_SB_G2, /* type */
1171 0, /* rightshift */
1172 2, /* size (0 = byte, 1 = short, 2 = long) */
1173 32, /* bitsize */
1174 TRUE, /* pc_relative */
1175 0, /* bitpos */
1176 complain_overflow_dont,/* complain_on_overflow */
1177 bfd_elf_generic_reloc, /* special_function */
1178 "R_ARM_LDR_SB_G2", /* name */
1179 FALSE, /* partial_inplace */
1180 0xffffffff, /* src_mask */
1181 0xffffffff, /* dst_mask */
1182 TRUE), /* pcrel_offset */
1184 HOWTO (R_ARM_LDRS_SB_G0, /* type */
1185 0, /* rightshift */
1186 2, /* size (0 = byte, 1 = short, 2 = long) */
1187 32, /* bitsize */
1188 TRUE, /* pc_relative */
1189 0, /* bitpos */
1190 complain_overflow_dont,/* complain_on_overflow */
1191 bfd_elf_generic_reloc, /* special_function */
1192 "R_ARM_LDRS_SB_G0", /* name */
1193 FALSE, /* partial_inplace */
1194 0xffffffff, /* src_mask */
1195 0xffffffff, /* dst_mask */
1196 TRUE), /* pcrel_offset */
1198 HOWTO (R_ARM_LDRS_SB_G1, /* type */
1199 0, /* rightshift */
1200 2, /* size (0 = byte, 1 = short, 2 = long) */
1201 32, /* bitsize */
1202 TRUE, /* pc_relative */
1203 0, /* bitpos */
1204 complain_overflow_dont,/* complain_on_overflow */
1205 bfd_elf_generic_reloc, /* special_function */
1206 "R_ARM_LDRS_SB_G1", /* name */
1207 FALSE, /* partial_inplace */
1208 0xffffffff, /* src_mask */
1209 0xffffffff, /* dst_mask */
1210 TRUE), /* pcrel_offset */
1212 HOWTO (R_ARM_LDRS_SB_G2, /* type */
1213 0, /* rightshift */
1214 2, /* size (0 = byte, 1 = short, 2 = long) */
1215 32, /* bitsize */
1216 TRUE, /* pc_relative */
1217 0, /* bitpos */
1218 complain_overflow_dont,/* complain_on_overflow */
1219 bfd_elf_generic_reloc, /* special_function */
1220 "R_ARM_LDRS_SB_G2", /* name */
1221 FALSE, /* partial_inplace */
1222 0xffffffff, /* src_mask */
1223 0xffffffff, /* dst_mask */
1224 TRUE), /* pcrel_offset */
1226 HOWTO (R_ARM_LDC_SB_G0, /* type */
1227 0, /* rightshift */
1228 2, /* size (0 = byte, 1 = short, 2 = long) */
1229 32, /* bitsize */
1230 TRUE, /* pc_relative */
1231 0, /* bitpos */
1232 complain_overflow_dont,/* complain_on_overflow */
1233 bfd_elf_generic_reloc, /* special_function */
1234 "R_ARM_LDC_SB_G0", /* name */
1235 FALSE, /* partial_inplace */
1236 0xffffffff, /* src_mask */
1237 0xffffffff, /* dst_mask */
1238 TRUE), /* pcrel_offset */
1240 HOWTO (R_ARM_LDC_SB_G1, /* type */
1241 0, /* rightshift */
1242 2, /* size (0 = byte, 1 = short, 2 = long) */
1243 32, /* bitsize */
1244 TRUE, /* pc_relative */
1245 0, /* bitpos */
1246 complain_overflow_dont,/* complain_on_overflow */
1247 bfd_elf_generic_reloc, /* special_function */
1248 "R_ARM_LDC_SB_G1", /* name */
1249 FALSE, /* partial_inplace */
1250 0xffffffff, /* src_mask */
1251 0xffffffff, /* dst_mask */
1252 TRUE), /* pcrel_offset */
1254 HOWTO (R_ARM_LDC_SB_G2, /* type */
1255 0, /* rightshift */
1256 2, /* size (0 = byte, 1 = short, 2 = long) */
1257 32, /* bitsize */
1258 TRUE, /* pc_relative */
1259 0, /* bitpos */
1260 complain_overflow_dont,/* complain_on_overflow */
1261 bfd_elf_generic_reloc, /* special_function */
1262 "R_ARM_LDC_SB_G2", /* name */
1263 FALSE, /* partial_inplace */
1264 0xffffffff, /* src_mask */
1265 0xffffffff, /* dst_mask */
1266 TRUE), /* pcrel_offset */
1268 /* End of group relocations. */
1270 HOWTO (R_ARM_MOVW_BREL_NC, /* type */
1271 0, /* rightshift */
1272 2, /* size (0 = byte, 1 = short, 2 = long) */
1273 16, /* bitsize */
1274 FALSE, /* pc_relative */
1275 0, /* bitpos */
1276 complain_overflow_dont,/* complain_on_overflow */
1277 bfd_elf_generic_reloc, /* special_function */
1278 "R_ARM_MOVW_BREL_NC", /* name */
1279 FALSE, /* partial_inplace */
1280 0x0000ffff, /* src_mask */
1281 0x0000ffff, /* dst_mask */
1282 FALSE), /* pcrel_offset */
1284 HOWTO (R_ARM_MOVT_BREL, /* type */
1285 0, /* rightshift */
1286 2, /* size (0 = byte, 1 = short, 2 = long) */
1287 16, /* bitsize */
1288 FALSE, /* pc_relative */
1289 0, /* bitpos */
1290 complain_overflow_bitfield,/* complain_on_overflow */
1291 bfd_elf_generic_reloc, /* special_function */
1292 "R_ARM_MOVT_BREL", /* name */
1293 FALSE, /* partial_inplace */
1294 0x0000ffff, /* src_mask */
1295 0x0000ffff, /* dst_mask */
1296 FALSE), /* pcrel_offset */
1298 HOWTO (R_ARM_MOVW_BREL, /* type */
1299 0, /* rightshift */
1300 2, /* size (0 = byte, 1 = short, 2 = long) */
1301 16, /* bitsize */
1302 FALSE, /* pc_relative */
1303 0, /* bitpos */
1304 complain_overflow_dont,/* complain_on_overflow */
1305 bfd_elf_generic_reloc, /* special_function */
1306 "R_ARM_MOVW_BREL", /* name */
1307 FALSE, /* partial_inplace */
1308 0x0000ffff, /* src_mask */
1309 0x0000ffff, /* dst_mask */
1310 FALSE), /* pcrel_offset */
1312 HOWTO (R_ARM_THM_MOVW_BREL_NC,/* type */
1313 0, /* rightshift */
1314 2, /* size (0 = byte, 1 = short, 2 = long) */
1315 16, /* bitsize */
1316 FALSE, /* pc_relative */
1317 0, /* bitpos */
1318 complain_overflow_dont,/* complain_on_overflow */
1319 bfd_elf_generic_reloc, /* special_function */
1320 "R_ARM_THM_MOVW_BREL_NC",/* name */
1321 FALSE, /* partial_inplace */
1322 0x040f70ff, /* src_mask */
1323 0x040f70ff, /* dst_mask */
1324 FALSE), /* pcrel_offset */
1326 HOWTO (R_ARM_THM_MOVT_BREL, /* type */
1327 0, /* rightshift */
1328 2, /* size (0 = byte, 1 = short, 2 = long) */
1329 16, /* bitsize */
1330 FALSE, /* pc_relative */
1331 0, /* bitpos */
1332 complain_overflow_bitfield,/* complain_on_overflow */
1333 bfd_elf_generic_reloc, /* special_function */
1334 "R_ARM_THM_MOVT_BREL", /* name */
1335 FALSE, /* partial_inplace */
1336 0x040f70ff, /* src_mask */
1337 0x040f70ff, /* dst_mask */
1338 FALSE), /* pcrel_offset */
1340 HOWTO (R_ARM_THM_MOVW_BREL, /* type */
1341 0, /* rightshift */
1342 2, /* size (0 = byte, 1 = short, 2 = long) */
1343 16, /* bitsize */
1344 FALSE, /* pc_relative */
1345 0, /* bitpos */
1346 complain_overflow_dont,/* complain_on_overflow */
1347 bfd_elf_generic_reloc, /* special_function */
1348 "R_ARM_THM_MOVW_BREL", /* name */
1349 FALSE, /* partial_inplace */
1350 0x040f70ff, /* src_mask */
1351 0x040f70ff, /* dst_mask */
1352 FALSE), /* pcrel_offset */
1354 EMPTY_HOWTO (90), /* unallocated */
1355 EMPTY_HOWTO (91),
1356 EMPTY_HOWTO (92),
1357 EMPTY_HOWTO (93),
1359 HOWTO (R_ARM_PLT32_ABS, /* type */
1360 0, /* rightshift */
1361 2, /* size (0 = byte, 1 = short, 2 = long) */
1362 32, /* bitsize */
1363 FALSE, /* pc_relative */
1364 0, /* bitpos */
1365 complain_overflow_dont,/* complain_on_overflow */
1366 bfd_elf_generic_reloc, /* special_function */
1367 "R_ARM_PLT32_ABS", /* name */
1368 FALSE, /* partial_inplace */
1369 0xffffffff, /* src_mask */
1370 0xffffffff, /* dst_mask */
1371 FALSE), /* pcrel_offset */
1373 HOWTO (R_ARM_GOT_ABS, /* type */
1374 0, /* rightshift */
1375 2, /* size (0 = byte, 1 = short, 2 = long) */
1376 32, /* bitsize */
1377 FALSE, /* pc_relative */
1378 0, /* bitpos */
1379 complain_overflow_dont,/* complain_on_overflow */
1380 bfd_elf_generic_reloc, /* special_function */
1381 "R_ARM_GOT_ABS", /* name */
1382 FALSE, /* partial_inplace */
1383 0xffffffff, /* src_mask */
1384 0xffffffff, /* dst_mask */
1385 FALSE), /* pcrel_offset */
1387 HOWTO (R_ARM_GOT_PREL, /* type */
1388 0, /* rightshift */
1389 2, /* size (0 = byte, 1 = short, 2 = long) */
1390 32, /* bitsize */
1391 TRUE, /* pc_relative */
1392 0, /* bitpos */
1393 complain_overflow_dont, /* complain_on_overflow */
1394 bfd_elf_generic_reloc, /* special_function */
1395 "R_ARM_GOT_PREL", /* name */
1396 FALSE, /* partial_inplace */
1397 0xffffffff, /* src_mask */
1398 0xffffffff, /* dst_mask */
1399 TRUE), /* pcrel_offset */
1401 HOWTO (R_ARM_GOT_BREL12, /* type */
1402 0, /* rightshift */
1403 2, /* size (0 = byte, 1 = short, 2 = long) */
1404 12, /* bitsize */
1405 FALSE, /* pc_relative */
1406 0, /* bitpos */
1407 complain_overflow_bitfield,/* complain_on_overflow */
1408 bfd_elf_generic_reloc, /* special_function */
1409 "R_ARM_GOT_BREL12", /* name */
1410 FALSE, /* partial_inplace */
1411 0x00000fff, /* src_mask */
1412 0x00000fff, /* dst_mask */
1413 FALSE), /* pcrel_offset */
1415 HOWTO (R_ARM_GOTOFF12, /* type */
1416 0, /* rightshift */
1417 2, /* size (0 = byte, 1 = short, 2 = long) */
1418 12, /* bitsize */
1419 FALSE, /* pc_relative */
1420 0, /* bitpos */
1421 complain_overflow_bitfield,/* complain_on_overflow */
1422 bfd_elf_generic_reloc, /* special_function */
1423 "R_ARM_GOTOFF12", /* name */
1424 FALSE, /* partial_inplace */
1425 0x00000fff, /* src_mask */
1426 0x00000fff, /* dst_mask */
1427 FALSE), /* pcrel_offset */
1429 EMPTY_HOWTO (R_ARM_GOTRELAX), /* reserved for future GOT-load optimizations */
1431 /* GNU extension to record C++ vtable member usage */
1432 HOWTO (R_ARM_GNU_VTENTRY, /* type */
1433 0, /* rightshift */
1434 2, /* size (0 = byte, 1 = short, 2 = long) */
1435 0, /* bitsize */
1436 FALSE, /* pc_relative */
1437 0, /* bitpos */
1438 complain_overflow_dont, /* complain_on_overflow */
1439 _bfd_elf_rel_vtable_reloc_fn, /* special_function */
1440 "R_ARM_GNU_VTENTRY", /* name */
1441 FALSE, /* partial_inplace */
1442 0, /* src_mask */
1443 0, /* dst_mask */
1444 FALSE), /* pcrel_offset */
1446 /* GNU extension to record C++ vtable hierarchy */
1447 HOWTO (R_ARM_GNU_VTINHERIT, /* type */
1448 0, /* rightshift */
1449 2, /* size (0 = byte, 1 = short, 2 = long) */
1450 0, /* bitsize */
1451 FALSE, /* pc_relative */
1452 0, /* bitpos */
1453 complain_overflow_dont, /* complain_on_overflow */
1454 NULL, /* special_function */
1455 "R_ARM_GNU_VTINHERIT", /* name */
1456 FALSE, /* partial_inplace */
1457 0, /* src_mask */
1458 0, /* dst_mask */
1459 FALSE), /* pcrel_offset */
1461 HOWTO (R_ARM_THM_JUMP11, /* type */
1462 1, /* rightshift */
1463 1, /* size (0 = byte, 1 = short, 2 = long) */
1464 11, /* bitsize */
1465 TRUE, /* pc_relative */
1466 0, /* bitpos */
1467 complain_overflow_signed, /* complain_on_overflow */
1468 bfd_elf_generic_reloc, /* special_function */
1469 "R_ARM_THM_JUMP11", /* name */
1470 FALSE, /* partial_inplace */
1471 0x000007ff, /* src_mask */
1472 0x000007ff, /* dst_mask */
1473 TRUE), /* pcrel_offset */
1475 HOWTO (R_ARM_THM_JUMP8, /* type */
1476 1, /* rightshift */
1477 1, /* size (0 = byte, 1 = short, 2 = long) */
1478 8, /* bitsize */
1479 TRUE, /* pc_relative */
1480 0, /* bitpos */
1481 complain_overflow_signed, /* complain_on_overflow */
1482 bfd_elf_generic_reloc, /* special_function */
1483 "R_ARM_THM_JUMP8", /* name */
1484 FALSE, /* partial_inplace */
1485 0x000000ff, /* src_mask */
1486 0x000000ff, /* dst_mask */
1487 TRUE), /* pcrel_offset */
1489 /* TLS relocations */
1490 HOWTO (R_ARM_TLS_GD32, /* type */
1491 0, /* rightshift */
1492 2, /* size (0 = byte, 1 = short, 2 = long) */
1493 32, /* bitsize */
1494 FALSE, /* pc_relative */
1495 0, /* bitpos */
1496 complain_overflow_bitfield,/* complain_on_overflow */
1497 NULL, /* special_function */
1498 "R_ARM_TLS_GD32", /* name */
1499 TRUE, /* partial_inplace */
1500 0xffffffff, /* src_mask */
1501 0xffffffff, /* dst_mask */
1502 FALSE), /* pcrel_offset */
1504 HOWTO (R_ARM_TLS_LDM32, /* type */
1505 0, /* rightshift */
1506 2, /* size (0 = byte, 1 = short, 2 = long) */
1507 32, /* bitsize */
1508 FALSE, /* pc_relative */
1509 0, /* bitpos */
1510 complain_overflow_bitfield,/* complain_on_overflow */
1511 bfd_elf_generic_reloc, /* special_function */
1512 "R_ARM_TLS_LDM32", /* name */
1513 TRUE, /* partial_inplace */
1514 0xffffffff, /* src_mask */
1515 0xffffffff, /* dst_mask */
1516 FALSE), /* pcrel_offset */
1518 HOWTO (R_ARM_TLS_LDO32, /* type */
1519 0, /* rightshift */
1520 2, /* size (0 = byte, 1 = short, 2 = long) */
1521 32, /* bitsize */
1522 FALSE, /* pc_relative */
1523 0, /* bitpos */
1524 complain_overflow_bitfield,/* complain_on_overflow */
1525 bfd_elf_generic_reloc, /* special_function */
1526 "R_ARM_TLS_LDO32", /* name */
1527 TRUE, /* partial_inplace */
1528 0xffffffff, /* src_mask */
1529 0xffffffff, /* dst_mask */
1530 FALSE), /* pcrel_offset */
1532 HOWTO (R_ARM_TLS_IE32, /* type */
1533 0, /* rightshift */
1534 2, /* size (0 = byte, 1 = short, 2 = long) */
1535 32, /* bitsize */
1536 FALSE, /* pc_relative */
1537 0, /* bitpos */
1538 complain_overflow_bitfield,/* complain_on_overflow */
1539 NULL, /* special_function */
1540 "R_ARM_TLS_IE32", /* name */
1541 TRUE, /* partial_inplace */
1542 0xffffffff, /* src_mask */
1543 0xffffffff, /* dst_mask */
1544 FALSE), /* pcrel_offset */
1546 HOWTO (R_ARM_TLS_LE32, /* type */
1547 0, /* rightshift */
1548 2, /* size (0 = byte, 1 = short, 2 = long) */
1549 32, /* bitsize */
1550 FALSE, /* pc_relative */
1551 0, /* bitpos */
1552 complain_overflow_bitfield,/* complain_on_overflow */
1553 bfd_elf_generic_reloc, /* special_function */
1554 "R_ARM_TLS_LE32", /* name */
1555 TRUE, /* partial_inplace */
1556 0xffffffff, /* src_mask */
1557 0xffffffff, /* dst_mask */
1558 FALSE), /* pcrel_offset */
1560 HOWTO (R_ARM_TLS_LDO12, /* type */
1561 0, /* rightshift */
1562 2, /* size (0 = byte, 1 = short, 2 = long) */
1563 12, /* bitsize */
1564 FALSE, /* pc_relative */
1565 0, /* bitpos */
1566 complain_overflow_bitfield,/* complain_on_overflow */
1567 bfd_elf_generic_reloc, /* special_function */
1568 "R_ARM_TLS_LDO12", /* name */
1569 FALSE, /* partial_inplace */
1570 0x00000fff, /* src_mask */
1571 0x00000fff, /* dst_mask */
1572 FALSE), /* pcrel_offset */
1574 HOWTO (R_ARM_TLS_LE12, /* type */
1575 0, /* rightshift */
1576 2, /* size (0 = byte, 1 = short, 2 = long) */
1577 12, /* bitsize */
1578 FALSE, /* pc_relative */
1579 0, /* bitpos */
1580 complain_overflow_bitfield,/* complain_on_overflow */
1581 bfd_elf_generic_reloc, /* special_function */
1582 "R_ARM_TLS_LE12", /* name */
1583 FALSE, /* partial_inplace */
1584 0x00000fff, /* src_mask */
1585 0x00000fff, /* dst_mask */
1586 FALSE), /* pcrel_offset */
1588 HOWTO (R_ARM_TLS_IE12GP, /* type */
1589 0, /* rightshift */
1590 2, /* size (0 = byte, 1 = short, 2 = long) */
1591 12, /* bitsize */
1592 FALSE, /* pc_relative */
1593 0, /* bitpos */
1594 complain_overflow_bitfield,/* complain_on_overflow */
1595 bfd_elf_generic_reloc, /* special_function */
1596 "R_ARM_TLS_IE12GP", /* name */
1597 FALSE, /* partial_inplace */
1598 0x00000fff, /* src_mask */
1599 0x00000fff, /* dst_mask */
1600 FALSE), /* pcrel_offset */
1603 /* 112-127 private relocations
1604 128 R_ARM_ME_TOO, obsolete
1605 129-255 unallocated in AAELF.
1607 249-255 extended, currently unused, relocations: */
1609 static reloc_howto_type elf32_arm_howto_table_2[4] =
1611 HOWTO (R_ARM_RREL32, /* type */
1612 0, /* rightshift */
1613 0, /* size (0 = byte, 1 = short, 2 = long) */
1614 0, /* bitsize */
1615 FALSE, /* pc_relative */
1616 0, /* bitpos */
1617 complain_overflow_dont,/* complain_on_overflow */
1618 bfd_elf_generic_reloc, /* special_function */
1619 "R_ARM_RREL32", /* name */
1620 FALSE, /* partial_inplace */
1621 0, /* src_mask */
1622 0, /* dst_mask */
1623 FALSE), /* pcrel_offset */
1625 HOWTO (R_ARM_RABS32, /* type */
1626 0, /* rightshift */
1627 0, /* size (0 = byte, 1 = short, 2 = long) */
1628 0, /* bitsize */
1629 FALSE, /* pc_relative */
1630 0, /* bitpos */
1631 complain_overflow_dont,/* complain_on_overflow */
1632 bfd_elf_generic_reloc, /* special_function */
1633 "R_ARM_RABS32", /* name */
1634 FALSE, /* partial_inplace */
1635 0, /* src_mask */
1636 0, /* dst_mask */
1637 FALSE), /* pcrel_offset */
1639 HOWTO (R_ARM_RPC24, /* type */
1640 0, /* rightshift */
1641 0, /* size (0 = byte, 1 = short, 2 = long) */
1642 0, /* bitsize */
1643 FALSE, /* pc_relative */
1644 0, /* bitpos */
1645 complain_overflow_dont,/* complain_on_overflow */
1646 bfd_elf_generic_reloc, /* special_function */
1647 "R_ARM_RPC24", /* name */
1648 FALSE, /* partial_inplace */
1649 0, /* src_mask */
1650 0, /* dst_mask */
1651 FALSE), /* pcrel_offset */
1653 HOWTO (R_ARM_RBASE, /* type */
1654 0, /* rightshift */
1655 0, /* size (0 = byte, 1 = short, 2 = long) */
1656 0, /* bitsize */
1657 FALSE, /* pc_relative */
1658 0, /* bitpos */
1659 complain_overflow_dont,/* complain_on_overflow */
1660 bfd_elf_generic_reloc, /* special_function */
1661 "R_ARM_RBASE", /* name */
1662 FALSE, /* partial_inplace */
1663 0, /* src_mask */
1664 0, /* dst_mask */
1665 FALSE) /* pcrel_offset */
1668 static reloc_howto_type *
1669 elf32_arm_howto_from_type (unsigned int r_type)
1671 if (r_type < NUM_ELEM (elf32_arm_howto_table_1))
1672 return &elf32_arm_howto_table_1[r_type];
1674 if (r_type >= R_ARM_RREL32
1675 && r_type < R_ARM_RREL32 + NUM_ELEM (elf32_arm_howto_table_2))
1676 return &elf32_arm_howto_table_2[r_type - R_ARM_RREL32];
1678 return NULL;
1681 static void
1682 elf32_arm_info_to_howto (bfd * abfd ATTRIBUTE_UNUSED, arelent * bfd_reloc,
1683 Elf_Internal_Rela * elf_reloc)
1685 unsigned int r_type;
1687 r_type = ELF32_R_TYPE (elf_reloc->r_info);
1688 bfd_reloc->howto = elf32_arm_howto_from_type (r_type);
1691 struct elf32_arm_reloc_map
1693 bfd_reloc_code_real_type bfd_reloc_val;
1694 unsigned char elf_reloc_val;
1697 /* All entries in this list must also be present in elf32_arm_howto_table. */
1698 static const struct elf32_arm_reloc_map elf32_arm_reloc_map[] =
1700 {BFD_RELOC_NONE, R_ARM_NONE},
1701 {BFD_RELOC_ARM_PCREL_BRANCH, R_ARM_PC24},
1702 {BFD_RELOC_ARM_PCREL_CALL, R_ARM_CALL},
1703 {BFD_RELOC_ARM_PCREL_JUMP, R_ARM_JUMP24},
1704 {BFD_RELOC_ARM_PCREL_BLX, R_ARM_XPC25},
1705 {BFD_RELOC_THUMB_PCREL_BLX, R_ARM_THM_XPC22},
1706 {BFD_RELOC_32, R_ARM_ABS32},
1707 {BFD_RELOC_32_PCREL, R_ARM_REL32},
1708 {BFD_RELOC_8, R_ARM_ABS8},
1709 {BFD_RELOC_16, R_ARM_ABS16},
1710 {BFD_RELOC_ARM_OFFSET_IMM, R_ARM_ABS12},
1711 {BFD_RELOC_ARM_THUMB_OFFSET, R_ARM_THM_ABS5},
1712 {BFD_RELOC_THUMB_PCREL_BRANCH25, R_ARM_THM_JUMP24},
1713 {BFD_RELOC_THUMB_PCREL_BRANCH23, R_ARM_THM_CALL},
1714 {BFD_RELOC_THUMB_PCREL_BRANCH12, R_ARM_THM_JUMP11},
1715 {BFD_RELOC_THUMB_PCREL_BRANCH20, R_ARM_THM_JUMP19},
1716 {BFD_RELOC_THUMB_PCREL_BRANCH9, R_ARM_THM_JUMP8},
1717 {BFD_RELOC_THUMB_PCREL_BRANCH7, R_ARM_THM_JUMP6},
1718 {BFD_RELOC_ARM_GLOB_DAT, R_ARM_GLOB_DAT},
1719 {BFD_RELOC_ARM_JUMP_SLOT, R_ARM_JUMP_SLOT},
1720 {BFD_RELOC_ARM_RELATIVE, R_ARM_RELATIVE},
1721 {BFD_RELOC_ARM_GOTOFF, R_ARM_GOTOFF32},
1722 {BFD_RELOC_ARM_GOTPC, R_ARM_GOTPC},
1723 {BFD_RELOC_ARM_GOT32, R_ARM_GOT32},
1724 {BFD_RELOC_ARM_PLT32, R_ARM_PLT32},
1725 {BFD_RELOC_ARM_TARGET1, R_ARM_TARGET1},
1726 {BFD_RELOC_ARM_ROSEGREL32, R_ARM_ROSEGREL32},
1727 {BFD_RELOC_ARM_SBREL32, R_ARM_SBREL32},
1728 {BFD_RELOC_ARM_PREL31, R_ARM_PREL31},
1729 {BFD_RELOC_ARM_TARGET2, R_ARM_TARGET2},
1730 {BFD_RELOC_ARM_PLT32, R_ARM_PLT32},
1731 {BFD_RELOC_ARM_TLS_GD32, R_ARM_TLS_GD32},
1732 {BFD_RELOC_ARM_TLS_LDO32, R_ARM_TLS_LDO32},
1733 {BFD_RELOC_ARM_TLS_LDM32, R_ARM_TLS_LDM32},
1734 {BFD_RELOC_ARM_TLS_DTPMOD32, R_ARM_TLS_DTPMOD32},
1735 {BFD_RELOC_ARM_TLS_DTPOFF32, R_ARM_TLS_DTPOFF32},
1736 {BFD_RELOC_ARM_TLS_TPOFF32, R_ARM_TLS_TPOFF32},
1737 {BFD_RELOC_ARM_TLS_IE32, R_ARM_TLS_IE32},
1738 {BFD_RELOC_ARM_TLS_LE32, R_ARM_TLS_LE32},
1739 {BFD_RELOC_VTABLE_INHERIT, R_ARM_GNU_VTINHERIT},
1740 {BFD_RELOC_VTABLE_ENTRY, R_ARM_GNU_VTENTRY},
1741 {BFD_RELOC_ARM_MOVW, R_ARM_MOVW_ABS_NC},
1742 {BFD_RELOC_ARM_MOVT, R_ARM_MOVT_ABS},
1743 {BFD_RELOC_ARM_MOVW_PCREL, R_ARM_MOVW_PREL_NC},
1744 {BFD_RELOC_ARM_MOVT_PCREL, R_ARM_MOVT_PREL},
1745 {BFD_RELOC_ARM_THUMB_MOVW, R_ARM_THM_MOVW_ABS_NC},
1746 {BFD_RELOC_ARM_THUMB_MOVT, R_ARM_THM_MOVT_ABS},
1747 {BFD_RELOC_ARM_THUMB_MOVW_PCREL, R_ARM_THM_MOVW_PREL_NC},
1748 {BFD_RELOC_ARM_THUMB_MOVT_PCREL, R_ARM_THM_MOVT_PREL},
1749 {BFD_RELOC_ARM_ALU_PC_G0_NC, R_ARM_ALU_PC_G0_NC},
1750 {BFD_RELOC_ARM_ALU_PC_G0, R_ARM_ALU_PC_G0},
1751 {BFD_RELOC_ARM_ALU_PC_G1_NC, R_ARM_ALU_PC_G1_NC},
1752 {BFD_RELOC_ARM_ALU_PC_G1, R_ARM_ALU_PC_G1},
1753 {BFD_RELOC_ARM_ALU_PC_G2, R_ARM_ALU_PC_G2},
1754 {BFD_RELOC_ARM_LDR_PC_G0, R_ARM_LDR_PC_G0},
1755 {BFD_RELOC_ARM_LDR_PC_G1, R_ARM_LDR_PC_G1},
1756 {BFD_RELOC_ARM_LDR_PC_G2, R_ARM_LDR_PC_G2},
1757 {BFD_RELOC_ARM_LDRS_PC_G0, R_ARM_LDRS_PC_G0},
1758 {BFD_RELOC_ARM_LDRS_PC_G1, R_ARM_LDRS_PC_G1},
1759 {BFD_RELOC_ARM_LDRS_PC_G2, R_ARM_LDRS_PC_G2},
1760 {BFD_RELOC_ARM_LDC_PC_G0, R_ARM_LDC_PC_G0},
1761 {BFD_RELOC_ARM_LDC_PC_G1, R_ARM_LDC_PC_G1},
1762 {BFD_RELOC_ARM_LDC_PC_G2, R_ARM_LDC_PC_G2},
1763 {BFD_RELOC_ARM_ALU_SB_G0_NC, R_ARM_ALU_SB_G0_NC},
1764 {BFD_RELOC_ARM_ALU_SB_G0, R_ARM_ALU_SB_G0},
1765 {BFD_RELOC_ARM_ALU_SB_G1_NC, R_ARM_ALU_SB_G1_NC},
1766 {BFD_RELOC_ARM_ALU_SB_G1, R_ARM_ALU_SB_G1},
1767 {BFD_RELOC_ARM_ALU_SB_G2, R_ARM_ALU_SB_G2},
1768 {BFD_RELOC_ARM_LDR_SB_G0, R_ARM_LDR_SB_G0},
1769 {BFD_RELOC_ARM_LDR_SB_G1, R_ARM_LDR_SB_G1},
1770 {BFD_RELOC_ARM_LDR_SB_G2, R_ARM_LDR_SB_G2},
1771 {BFD_RELOC_ARM_LDRS_SB_G0, R_ARM_LDRS_SB_G0},
1772 {BFD_RELOC_ARM_LDRS_SB_G1, R_ARM_LDRS_SB_G1},
1773 {BFD_RELOC_ARM_LDRS_SB_G2, R_ARM_LDRS_SB_G2},
1774 {BFD_RELOC_ARM_LDC_SB_G0, R_ARM_LDC_SB_G0},
1775 {BFD_RELOC_ARM_LDC_SB_G1, R_ARM_LDC_SB_G1},
1776 {BFD_RELOC_ARM_LDC_SB_G2, R_ARM_LDC_SB_G2}
1779 static reloc_howto_type *
1780 elf32_arm_reloc_type_lookup (bfd *abfd ATTRIBUTE_UNUSED,
1781 bfd_reloc_code_real_type code)
1783 unsigned int i;
1784 for (i = 0; i < NUM_ELEM (elf32_arm_reloc_map); i ++)
1785 if (elf32_arm_reloc_map[i].bfd_reloc_val == code)
1786 return elf32_arm_howto_from_type (elf32_arm_reloc_map[i].elf_reloc_val);
1788 return NULL;
1791 /* Support for core dump NOTE sections */
1792 static bfd_boolean
1793 elf32_arm_nabi_grok_prstatus (bfd *abfd, Elf_Internal_Note *note)
1795 int offset;
1796 size_t size;
1798 switch (note->descsz)
1800 default:
1801 return FALSE;
1803 case 148: /* Linux/ARM 32-bit*/
1804 /* pr_cursig */
1805 elf_tdata (abfd)->core_signal = bfd_get_16 (abfd, note->descdata + 12);
1807 /* pr_pid */
1808 elf_tdata (abfd)->core_pid = bfd_get_32 (abfd, note->descdata + 24);
1810 /* pr_reg */
1811 offset = 72;
1812 size = 72;
1814 break;
1817 /* Make a ".reg/999" section. */
1818 return _bfd_elfcore_make_pseudosection (abfd, ".reg",
1819 size, note->descpos + offset);
1822 static bfd_boolean
1823 elf32_arm_nabi_grok_psinfo (bfd *abfd, Elf_Internal_Note *note)
1825 switch (note->descsz)
1827 default:
1828 return FALSE;
1830 case 124: /* Linux/ARM elf_prpsinfo */
1831 elf_tdata (abfd)->core_program
1832 = _bfd_elfcore_strndup (abfd, note->descdata + 28, 16);
1833 elf_tdata (abfd)->core_command
1834 = _bfd_elfcore_strndup (abfd, note->descdata + 44, 80);
1837 /* Note that for some reason, a spurious space is tacked
1838 onto the end of the args in some (at least one anyway)
1839 implementations, so strip it off if it exists. */
1842 char *command = elf_tdata (abfd)->core_command;
1843 int n = strlen (command);
1845 if (0 < n && command[n - 1] == ' ')
1846 command[n - 1] = '\0';
1849 return TRUE;
1852 #define TARGET_LITTLE_SYM bfd_elf32_littlearm_vec
1853 #define TARGET_LITTLE_NAME "elf32-littlearm"
1854 #define TARGET_BIG_SYM bfd_elf32_bigarm_vec
1855 #define TARGET_BIG_NAME "elf32-bigarm"
1857 #define elf_backend_grok_prstatus elf32_arm_nabi_grok_prstatus
1858 #define elf_backend_grok_psinfo elf32_arm_nabi_grok_psinfo
1860 typedef unsigned long int insn32;
1861 typedef unsigned short int insn16;
1863 /* In lieu of proper flags, assume all EABIv4 or later objects are
1864 interworkable. */
1865 #define INTERWORK_FLAG(abfd) \
1866 (EF_ARM_EABI_VERSION (elf_elfheader (abfd)->e_flags) >= EF_ARM_EABI_VER4 \
1867 || (elf_elfheader (abfd)->e_flags & EF_ARM_INTERWORK))
1869 /* The linker script knows the section names for placement.
1870 The entry_names are used to do simple name mangling on the stubs.
1871 Given a function name, and its type, the stub can be found. The
1872 name can be changed. The only requirement is the %s be present. */
1873 #define THUMB2ARM_GLUE_SECTION_NAME ".glue_7t"
1874 #define THUMB2ARM_GLUE_ENTRY_NAME "__%s_from_thumb"
1876 #define ARM2THUMB_GLUE_SECTION_NAME ".glue_7"
1877 #define ARM2THUMB_GLUE_ENTRY_NAME "__%s_from_arm"
1879 /* The name of the dynamic interpreter. This is put in the .interp
1880 section. */
1881 #define ELF_DYNAMIC_INTERPRETER "/usr/lib/ld.so.1"
1883 #ifdef FOUR_WORD_PLT
1885 /* The first entry in a procedure linkage table looks like
1886 this. It is set up so that any shared library function that is
1887 called before the relocation has been set up calls the dynamic
1888 linker first. */
1889 static const bfd_vma elf32_arm_plt0_entry [] =
1891 0xe52de004, /* str lr, [sp, #-4]! */
1892 0xe59fe010, /* ldr lr, [pc, #16] */
1893 0xe08fe00e, /* add lr, pc, lr */
1894 0xe5bef008, /* ldr pc, [lr, #8]! */
1897 /* Subsequent entries in a procedure linkage table look like
1898 this. */
1899 static const bfd_vma elf32_arm_plt_entry [] =
1901 0xe28fc600, /* add ip, pc, #NN */
1902 0xe28cca00, /* add ip, ip, #NN */
1903 0xe5bcf000, /* ldr pc, [ip, #NN]! */
1904 0x00000000, /* unused */
1907 #else
1909 /* The first entry in a procedure linkage table looks like
1910 this. It is set up so that any shared library function that is
1911 called before the relocation has been set up calls the dynamic
1912 linker first. */
1913 static const bfd_vma elf32_arm_plt0_entry [] =
1915 0xe52de004, /* str lr, [sp, #-4]! */
1916 0xe59fe004, /* ldr lr, [pc, #4] */
1917 0xe08fe00e, /* add lr, pc, lr */
1918 0xe5bef008, /* ldr pc, [lr, #8]! */
1919 0x00000000, /* &GOT[0] - . */
1922 /* Subsequent entries in a procedure linkage table look like
1923 this. */
1924 static const bfd_vma elf32_arm_plt_entry [] =
1926 0xe28fc600, /* add ip, pc, #0xNN00000 */
1927 0xe28cca00, /* add ip, ip, #0xNN000 */
1928 0xe5bcf000, /* ldr pc, [ip, #0xNNN]! */
1931 #endif
1933 /* The format of the first entry in the procedure linkage table
1934 for a VxWorks executable. */
1935 static const bfd_vma elf32_arm_vxworks_exec_plt0_entry[] =
1937 0xe52dc008, /* str ip,[sp,#-8]! */
1938 0xe59fc000, /* ldr ip,[pc] */
1939 0xe59cf008, /* ldr pc,[ip,#8] */
1940 0x00000000, /* .long _GLOBAL_OFFSET_TABLE_ */
1943 /* The format of subsequent entries in a VxWorks executable. */
1944 static const bfd_vma elf32_arm_vxworks_exec_plt_entry[] =
1946 0xe59fc000, /* ldr ip,[pc] */
1947 0xe59cf000, /* ldr pc,[ip] */
1948 0x00000000, /* .long @got */
1949 0xe59fc000, /* ldr ip,[pc] */
1950 0xea000000, /* b _PLT */
1951 0x00000000, /* .long @pltindex*sizeof(Elf32_Rela) */
1954 /* The format of entries in a VxWorks shared library. */
1955 static const bfd_vma elf32_arm_vxworks_shared_plt_entry[] =
1957 0xe59fc000, /* ldr ip,[pc] */
1958 0xe79cf009, /* ldr pc,[ip,r9] */
1959 0x00000000, /* .long @got */
1960 0xe59fc000, /* ldr ip,[pc] */
1961 0xe599f008, /* ldr pc,[r9,#8] */
1962 0x00000000, /* .long @pltindex*sizeof(Elf32_Rela) */
1965 /* An initial stub used if the PLT entry is referenced from Thumb code. */
1966 #define PLT_THUMB_STUB_SIZE 4
1967 static const bfd_vma elf32_arm_plt_thumb_stub [] =
1969 0x4778, /* bx pc */
1970 0x46c0 /* nop */
1973 /* The entries in a PLT when using a DLL-based target with multiple
1974 address spaces. */
1975 static const bfd_vma elf32_arm_symbian_plt_entry [] =
1977 0xe51ff004, /* ldr pc, [pc, #-4] */
1978 0x00000000, /* dcd R_ARM_GLOB_DAT(X) */
1981 /* Used to build a map of a section. This is required for mixed-endian
1982 code/data. */
1984 typedef struct elf32_elf_section_map
1986 bfd_vma vma;
1987 char type;
1989 elf32_arm_section_map;
1991 typedef struct _arm_elf_section_data
1993 struct bfd_elf_section_data elf;
1994 unsigned int mapcount;
1995 elf32_arm_section_map *map;
1997 _arm_elf_section_data;
1999 #define elf32_arm_section_data(sec) \
2000 ((_arm_elf_section_data *) elf_section_data (sec))
2002 /* The size of the thread control block. */
2003 #define TCB_SIZE 8
2005 #define NUM_KNOWN_ATTRIBUTES 32
2007 typedef struct aeabi_attribute
2009 int type;
2010 unsigned int i;
2011 char *s;
2012 } aeabi_attribute;
2014 typedef struct aeabi_attribute_list
2016 struct aeabi_attribute_list *next;
2017 int tag;
2018 aeabi_attribute attr;
2019 } aeabi_attribute_list;
2021 struct elf32_arm_obj_tdata
2023 struct elf_obj_tdata root;
2025 /* tls_type for each local got entry. */
2026 char *local_got_tls_type;
2028 aeabi_attribute known_eabi_attributes[NUM_KNOWN_ATTRIBUTES];
2029 aeabi_attribute_list *other_eabi_attributes;
2032 #define elf32_arm_tdata(abfd) \
2033 ((struct elf32_arm_obj_tdata *) (abfd)->tdata.any)
2035 #define elf32_arm_local_got_tls_type(abfd) \
2036 (elf32_arm_tdata (abfd)->local_got_tls_type)
2038 static bfd_boolean
2039 elf32_arm_mkobject (bfd *abfd)
2041 if (abfd->tdata.any == NULL)
2043 bfd_size_type amt = sizeof (struct elf32_arm_obj_tdata);
2044 abfd->tdata.any = bfd_zalloc (abfd, amt);
2045 if (abfd->tdata.any == NULL)
2046 return FALSE;
2048 return bfd_elf_mkobject (abfd);
2051 /* The ARM linker needs to keep track of the number of relocs that it
2052 decides to copy in check_relocs for each symbol. This is so that
2053 it can discard PC relative relocs if it doesn't need them when
2054 linking with -Bsymbolic. We store the information in a field
2055 extending the regular ELF linker hash table. */
2057 /* This structure keeps track of the number of relocs we have copied
2058 for a given symbol. */
2059 struct elf32_arm_relocs_copied
2061 /* Next section. */
2062 struct elf32_arm_relocs_copied * next;
2063 /* A section in dynobj. */
2064 asection * section;
2065 /* Number of relocs copied in this section. */
2066 bfd_size_type count;
2067 /* Number of PC-relative relocs copied in this section. */
2068 bfd_size_type pc_count;
2071 #define elf32_arm_hash_entry(ent) ((struct elf32_arm_link_hash_entry *)(ent))
2073 /* Arm ELF linker hash entry. */
2074 struct elf32_arm_link_hash_entry
2076 struct elf_link_hash_entry root;
2078 /* Number of PC relative relocs copied for this symbol. */
2079 struct elf32_arm_relocs_copied * relocs_copied;
2081 /* We reference count Thumb references to a PLT entry separately,
2082 so that we can emit the Thumb trampoline only if needed. */
2083 bfd_signed_vma plt_thumb_refcount;
2085 /* Since PLT entries have variable size if the Thumb prologue is
2086 used, we need to record the index into .got.plt instead of
2087 recomputing it from the PLT offset. */
2088 bfd_signed_vma plt_got_offset;
2090 #define GOT_UNKNOWN 0
2091 #define GOT_NORMAL 1
2092 #define GOT_TLS_GD 2
2093 #define GOT_TLS_IE 4
2094 unsigned char tls_type;
2096 /* The symbol marking the real symbol location for exported thumb
2097 symbols with Arm stubs. */
2098 struct elf_link_hash_entry *export_glue;
2101 /* Traverse an arm ELF linker hash table. */
2102 #define elf32_arm_link_hash_traverse(table, func, info) \
2103 (elf_link_hash_traverse \
2104 (&(table)->root, \
2105 (bfd_boolean (*) (struct elf_link_hash_entry *, void *)) (func), \
2106 (info)))
2108 /* Get the ARM elf linker hash table from a link_info structure. */
2109 #define elf32_arm_hash_table(info) \
2110 ((struct elf32_arm_link_hash_table *) ((info)->hash))
2112 /* ARM ELF linker hash table. */
2113 struct elf32_arm_link_hash_table
2115 /* The main hash table. */
2116 struct elf_link_hash_table root;
2118 /* The size in bytes of the section containing the Thumb-to-ARM glue. */
2119 bfd_size_type thumb_glue_size;
2121 /* The size in bytes of the section containing the ARM-to-Thumb glue. */
2122 bfd_size_type arm_glue_size;
2124 /* An arbitrary input BFD chosen to hold the glue sections. */
2125 bfd * bfd_of_glue_owner;
2127 /* Nonzero to output a BE8 image. */
2128 int byteswap_code;
2130 /* Zero if R_ARM_TARGET1 means R_ARM_ABS32.
2131 Nonzero if R_ARM_TARGET1 means R_ARM_ABS32. */
2132 int target1_is_rel;
2134 /* The relocation to use for R_ARM_TARGET2 relocations. */
2135 int target2_reloc;
2137 /* Nonzero to fix BX instructions for ARMv4 targets. */
2138 int fix_v4bx;
2140 /* Nonzero if the ARM/Thumb BLX instructions are available for use. */
2141 int use_blx;
2143 /* The number of bytes in the initial entry in the PLT. */
2144 bfd_size_type plt_header_size;
2146 /* The number of bytes in the subsequent PLT etries. */
2147 bfd_size_type plt_entry_size;
2149 /* True if the target system is VxWorks. */
2150 int vxworks_p;
2152 /* True if the target system is Symbian OS. */
2153 int symbian_p;
2155 /* True if the target uses REL relocations. */
2156 int use_rel;
2158 /* Short-cuts to get to dynamic linker sections. */
2159 asection *sgot;
2160 asection *sgotplt;
2161 asection *srelgot;
2162 asection *splt;
2163 asection *srelplt;
2164 asection *sdynbss;
2165 asection *srelbss;
2167 /* The (unloaded but important) VxWorks .rela.plt.unloaded section. */
2168 asection *srelplt2;
2170 /* Data for R_ARM_TLS_LDM32 relocations. */
2171 union {
2172 bfd_signed_vma refcount;
2173 bfd_vma offset;
2174 } tls_ldm_got;
2176 /* Small local sym to section mapping cache. */
2177 struct sym_sec_cache sym_sec;
2179 /* For convenience in allocate_dynrelocs. */
2180 bfd * obfd;
2183 /* Create an entry in an ARM ELF linker hash table. */
2185 static struct bfd_hash_entry *
2186 elf32_arm_link_hash_newfunc (struct bfd_hash_entry * entry,
2187 struct bfd_hash_table * table,
2188 const char * string)
2190 struct elf32_arm_link_hash_entry * ret =
2191 (struct elf32_arm_link_hash_entry *) entry;
2193 /* Allocate the structure if it has not already been allocated by a
2194 subclass. */
2195 if (ret == (struct elf32_arm_link_hash_entry *) NULL)
2196 ret = bfd_hash_allocate (table, sizeof (struct elf32_arm_link_hash_entry));
2197 if (ret == NULL)
2198 return (struct bfd_hash_entry *) ret;
2200 /* Call the allocation method of the superclass. */
2201 ret = ((struct elf32_arm_link_hash_entry *)
2202 _bfd_elf_link_hash_newfunc ((struct bfd_hash_entry *) ret,
2203 table, string));
2204 if (ret != NULL)
2206 ret->relocs_copied = NULL;
2207 ret->tls_type = GOT_UNKNOWN;
2208 ret->plt_thumb_refcount = 0;
2209 ret->plt_got_offset = -1;
2210 ret->export_glue = NULL;
2213 return (struct bfd_hash_entry *) ret;
2216 /* Return true if NAME is the name of the relocation section associated
2217 with S. */
2219 static bfd_boolean
2220 reloc_section_p (struct elf32_arm_link_hash_table *htab,
2221 const char *name, asection *s)
2223 if (htab->use_rel)
2224 return strncmp (name, ".rel", 4) == 0 && strcmp (s->name, name + 4) == 0;
2225 else
2226 return strncmp (name, ".rela", 5) == 0 && strcmp (s->name, name + 5) == 0;
2229 /* Create .got, .gotplt, and .rel(a).got sections in DYNOBJ, and set up
2230 shortcuts to them in our hash table. */
2232 static bfd_boolean
2233 create_got_section (bfd *dynobj, struct bfd_link_info *info)
2235 struct elf32_arm_link_hash_table *htab;
2237 htab = elf32_arm_hash_table (info);
2238 /* BPABI objects never have a GOT, or associated sections. */
2239 if (htab->symbian_p)
2240 return TRUE;
2242 if (! _bfd_elf_create_got_section (dynobj, info))
2243 return FALSE;
2245 htab->sgot = bfd_get_section_by_name (dynobj, ".got");
2246 htab->sgotplt = bfd_get_section_by_name (dynobj, ".got.plt");
2247 if (!htab->sgot || !htab->sgotplt)
2248 abort ();
2250 htab->srelgot = bfd_make_section_with_flags (dynobj,
2251 RELOC_SECTION (htab, ".got"),
2252 (SEC_ALLOC | SEC_LOAD
2253 | SEC_HAS_CONTENTS
2254 | SEC_IN_MEMORY
2255 | SEC_LINKER_CREATED
2256 | SEC_READONLY));
2257 if (htab->srelgot == NULL
2258 || ! bfd_set_section_alignment (dynobj, htab->srelgot, 2))
2259 return FALSE;
2260 return TRUE;
2263 /* Create .plt, .rel(a).plt, .got, .got.plt, .rel(a).got, .dynbss, and
2264 .rel(a).bss sections in DYNOBJ, and set up shortcuts to them in our
2265 hash table. */
2267 static bfd_boolean
2268 elf32_arm_create_dynamic_sections (bfd *dynobj, struct bfd_link_info *info)
2270 struct elf32_arm_link_hash_table *htab;
2272 htab = elf32_arm_hash_table (info);
2273 if (!htab->sgot && !create_got_section (dynobj, info))
2274 return FALSE;
2276 if (!_bfd_elf_create_dynamic_sections (dynobj, info))
2277 return FALSE;
2279 htab->splt = bfd_get_section_by_name (dynobj, ".plt");
2280 htab->srelplt = bfd_get_section_by_name (dynobj,
2281 RELOC_SECTION (htab, ".plt"));
2282 htab->sdynbss = bfd_get_section_by_name (dynobj, ".dynbss");
2283 if (!info->shared)
2284 htab->srelbss = bfd_get_section_by_name (dynobj,
2285 RELOC_SECTION (htab, ".bss"));
2287 if (htab->vxworks_p)
2289 if (!elf_vxworks_create_dynamic_sections (dynobj, info, &htab->srelplt2))
2290 return FALSE;
2292 if (info->shared)
2294 htab->plt_header_size = 0;
2295 htab->plt_entry_size
2296 = 4 * ARRAY_SIZE (elf32_arm_vxworks_shared_plt_entry);
2298 else
2300 htab->plt_header_size
2301 = 4 * ARRAY_SIZE (elf32_arm_vxworks_exec_plt0_entry);
2302 htab->plt_entry_size
2303 = 4 * ARRAY_SIZE (elf32_arm_vxworks_exec_plt_entry);
2307 if (!htab->splt
2308 || !htab->srelplt
2309 || !htab->sdynbss
2310 || (!info->shared && !htab->srelbss))
2311 abort ();
2313 return TRUE;
2316 /* Copy the extra info we tack onto an elf_link_hash_entry. */
2318 static void
2319 elf32_arm_copy_indirect_symbol (struct bfd_link_info *info,
2320 struct elf_link_hash_entry *dir,
2321 struct elf_link_hash_entry *ind)
2323 struct elf32_arm_link_hash_entry *edir, *eind;
2325 edir = (struct elf32_arm_link_hash_entry *) dir;
2326 eind = (struct elf32_arm_link_hash_entry *) ind;
2328 if (eind->relocs_copied != NULL)
2330 if (edir->relocs_copied != NULL)
2332 struct elf32_arm_relocs_copied **pp;
2333 struct elf32_arm_relocs_copied *p;
2335 /* Add reloc counts against the indirect sym to the direct sym
2336 list. Merge any entries against the same section. */
2337 for (pp = &eind->relocs_copied; (p = *pp) != NULL; )
2339 struct elf32_arm_relocs_copied *q;
2341 for (q = edir->relocs_copied; q != NULL; q = q->next)
2342 if (q->section == p->section)
2344 q->pc_count += p->pc_count;
2345 q->count += p->count;
2346 *pp = p->next;
2347 break;
2349 if (q == NULL)
2350 pp = &p->next;
2352 *pp = edir->relocs_copied;
2355 edir->relocs_copied = eind->relocs_copied;
2356 eind->relocs_copied = NULL;
2359 /* Copy over PLT info. */
2360 edir->plt_thumb_refcount += eind->plt_thumb_refcount;
2361 eind->plt_thumb_refcount = 0;
2363 if (ind->root.type == bfd_link_hash_indirect
2364 && dir->got.refcount <= 0)
2366 edir->tls_type = eind->tls_type;
2367 eind->tls_type = GOT_UNKNOWN;
2370 _bfd_elf_link_hash_copy_indirect (info, dir, ind);
2373 /* Create an ARM elf linker hash table. */
2375 static struct bfd_link_hash_table *
2376 elf32_arm_link_hash_table_create (bfd *abfd)
2378 struct elf32_arm_link_hash_table *ret;
2379 bfd_size_type amt = sizeof (struct elf32_arm_link_hash_table);
2381 ret = bfd_malloc (amt);
2382 if (ret == NULL)
2383 return NULL;
2385 if (!_bfd_elf_link_hash_table_init (& ret->root, abfd,
2386 elf32_arm_link_hash_newfunc,
2387 sizeof (struct elf32_arm_link_hash_entry)))
2389 free (ret);
2390 return NULL;
2393 ret->sgot = NULL;
2394 ret->sgotplt = NULL;
2395 ret->srelgot = NULL;
2396 ret->splt = NULL;
2397 ret->srelplt = NULL;
2398 ret->sdynbss = NULL;
2399 ret->srelbss = NULL;
2400 ret->srelplt2 = NULL;
2401 ret->thumb_glue_size = 0;
2402 ret->arm_glue_size = 0;
2403 ret->bfd_of_glue_owner = NULL;
2404 ret->byteswap_code = 0;
2405 ret->target1_is_rel = 0;
2406 ret->target2_reloc = R_ARM_NONE;
2407 #ifdef FOUR_WORD_PLT
2408 ret->plt_header_size = 16;
2409 ret->plt_entry_size = 16;
2410 #else
2411 ret->plt_header_size = 20;
2412 ret->plt_entry_size = 12;
2413 #endif
2414 ret->fix_v4bx = 0;
2415 ret->use_blx = 0;
2416 ret->vxworks_p = 0;
2417 ret->symbian_p = 0;
2418 ret->use_rel = 1;
2419 ret->sym_sec.abfd = NULL;
2420 ret->obfd = abfd;
2421 ret->tls_ldm_got.refcount = 0;
2423 return &ret->root.root;
2426 /* Locate the Thumb encoded calling stub for NAME. */
2428 static struct elf_link_hash_entry *
2429 find_thumb_glue (struct bfd_link_info *link_info,
2430 const char *name,
2431 bfd *input_bfd)
2433 char *tmp_name;
2434 struct elf_link_hash_entry *hash;
2435 struct elf32_arm_link_hash_table *hash_table;
2437 /* We need a pointer to the armelf specific hash table. */
2438 hash_table = elf32_arm_hash_table (link_info);
2440 tmp_name = bfd_malloc ((bfd_size_type) strlen (name)
2441 + strlen (THUMB2ARM_GLUE_ENTRY_NAME) + 1);
2443 BFD_ASSERT (tmp_name);
2445 sprintf (tmp_name, THUMB2ARM_GLUE_ENTRY_NAME, name);
2447 hash = elf_link_hash_lookup
2448 (&(hash_table)->root, tmp_name, FALSE, FALSE, TRUE);
2450 if (hash == NULL)
2451 /* xgettext:c-format */
2452 (*_bfd_error_handler) (_("%B: unable to find THUMB glue '%s' for `%s'"),
2453 input_bfd, tmp_name, name);
2455 free (tmp_name);
2457 return hash;
2460 /* Locate the ARM encoded calling stub for NAME. */
2462 static struct elf_link_hash_entry *
2463 find_arm_glue (struct bfd_link_info *link_info,
2464 const char *name,
2465 bfd *input_bfd)
2467 char *tmp_name;
2468 struct elf_link_hash_entry *myh;
2469 struct elf32_arm_link_hash_table *hash_table;
2471 /* We need a pointer to the elfarm specific hash table. */
2472 hash_table = elf32_arm_hash_table (link_info);
2474 tmp_name = bfd_malloc ((bfd_size_type) strlen (name)
2475 + strlen (ARM2THUMB_GLUE_ENTRY_NAME) + 1);
2477 BFD_ASSERT (tmp_name);
2479 sprintf (tmp_name, ARM2THUMB_GLUE_ENTRY_NAME, name);
2481 myh = elf_link_hash_lookup
2482 (&(hash_table)->root, tmp_name, FALSE, FALSE, TRUE);
2484 if (myh == NULL)
2485 /* xgettext:c-format */
2486 (*_bfd_error_handler) (_("%B: unable to find ARM glue '%s' for `%s'"),
2487 input_bfd, tmp_name, name);
2489 free (tmp_name);
2491 return myh;
2494 /* ARM->Thumb glue (static images):
2496 .arm
2497 __func_from_arm:
2498 ldr r12, __func_addr
2499 bx r12
2500 __func_addr:
2501 .word func @ behave as if you saw a ARM_32 reloc.
2503 (relocatable images)
2504 .arm
2505 __func_from_arm:
2506 ldr r12, __func_offset
2507 add r12, r12, pc
2508 bx r12
2509 __func_offset:
2510 .word func - .
2513 #define ARM2THUMB_STATIC_GLUE_SIZE 12
2514 static const insn32 a2t1_ldr_insn = 0xe59fc000;
2515 static const insn32 a2t2_bx_r12_insn = 0xe12fff1c;
2516 static const insn32 a2t3_func_addr_insn = 0x00000001;
2518 #define ARM2THUMB_PIC_GLUE_SIZE 16
2519 static const insn32 a2t1p_ldr_insn = 0xe59fc004;
2520 static const insn32 a2t2p_add_pc_insn = 0xe08cc00f;
2521 static const insn32 a2t3p_bx_r12_insn = 0xe12fff1c;
2523 /* Thumb->ARM: Thumb->(non-interworking aware) ARM
2525 .thumb .thumb
2526 .align 2 .align 2
2527 __func_from_thumb: __func_from_thumb:
2528 bx pc push {r6, lr}
2529 nop ldr r6, __func_addr
2530 .arm mov lr, pc
2531 __func_change_to_arm: bx r6
2532 b func .arm
2533 __func_back_to_thumb:
2534 ldmia r13! {r6, lr}
2535 bx lr
2536 __func_addr:
2537 .word func */
2539 #define THUMB2ARM_GLUE_SIZE 8
2540 static const insn16 t2a1_bx_pc_insn = 0x4778;
2541 static const insn16 t2a2_noop_insn = 0x46c0;
2542 static const insn32 t2a3_b_insn = 0xea000000;
2544 #ifndef ELFARM_NABI_C_INCLUDED
2545 bfd_boolean
2546 bfd_elf32_arm_allocate_interworking_sections (struct bfd_link_info * info)
2548 asection * s;
2549 bfd_byte * foo;
2550 struct elf32_arm_link_hash_table * globals;
2552 globals = elf32_arm_hash_table (info);
2554 BFD_ASSERT (globals != NULL);
2556 if (globals->arm_glue_size != 0)
2558 BFD_ASSERT (globals->bfd_of_glue_owner != NULL);
2560 s = bfd_get_section_by_name (globals->bfd_of_glue_owner,
2561 ARM2THUMB_GLUE_SECTION_NAME);
2563 BFD_ASSERT (s != NULL);
2565 foo = bfd_alloc (globals->bfd_of_glue_owner, globals->arm_glue_size);
2567 s->size = globals->arm_glue_size;
2568 s->contents = foo;
2571 if (globals->thumb_glue_size != 0)
2573 BFD_ASSERT (globals->bfd_of_glue_owner != NULL);
2575 s = bfd_get_section_by_name
2576 (globals->bfd_of_glue_owner, THUMB2ARM_GLUE_SECTION_NAME);
2578 BFD_ASSERT (s != NULL);
2580 foo = bfd_alloc (globals->bfd_of_glue_owner, globals->thumb_glue_size);
2582 s->size = globals->thumb_glue_size;
2583 s->contents = foo;
2586 return TRUE;
2589 /* Allocate space and symbols for calling a Thumb function from Arm mode.
2590 returns the symbol identifying teh stub. */
2591 static struct elf_link_hash_entry *
2592 record_arm_to_thumb_glue (struct bfd_link_info * link_info,
2593 struct elf_link_hash_entry * h)
2595 const char * name = h->root.root.string;
2596 asection * s;
2597 char * tmp_name;
2598 struct elf_link_hash_entry * myh;
2599 struct bfd_link_hash_entry * bh;
2600 struct elf32_arm_link_hash_table * globals;
2601 bfd_vma val;
2603 globals = elf32_arm_hash_table (link_info);
2605 BFD_ASSERT (globals != NULL);
2606 BFD_ASSERT (globals->bfd_of_glue_owner != NULL);
2608 s = bfd_get_section_by_name
2609 (globals->bfd_of_glue_owner, ARM2THUMB_GLUE_SECTION_NAME);
2611 BFD_ASSERT (s != NULL);
2613 tmp_name = bfd_malloc ((bfd_size_type) strlen (name) + strlen (ARM2THUMB_GLUE_ENTRY_NAME) + 1);
2615 BFD_ASSERT (tmp_name);
2617 sprintf (tmp_name, ARM2THUMB_GLUE_ENTRY_NAME, name);
2619 myh = elf_link_hash_lookup
2620 (&(globals)->root, tmp_name, FALSE, FALSE, TRUE);
2622 if (myh != NULL)
2624 /* We've already seen this guy. */
2625 free (tmp_name);
2626 return myh;
2629 /* The only trick here is using hash_table->arm_glue_size as the value.
2630 Even though the section isn't allocated yet, this is where we will be
2631 putting it. */
2632 bh = NULL;
2633 val = globals->arm_glue_size + 1;
2634 _bfd_generic_link_add_one_symbol (link_info, globals->bfd_of_glue_owner,
2635 tmp_name, BSF_GLOBAL, s, val,
2636 NULL, TRUE, FALSE, &bh);
2638 myh = (struct elf_link_hash_entry *) bh;
2639 myh->type = ELF_ST_INFO (STB_LOCAL, STT_FUNC);
2640 myh->forced_local = 1;
2642 free (tmp_name);
2644 if ((link_info->shared || globals->root.is_relocatable_executable))
2645 globals->arm_glue_size += ARM2THUMB_PIC_GLUE_SIZE;
2646 else
2647 globals->arm_glue_size += ARM2THUMB_STATIC_GLUE_SIZE;
2649 return myh;
2652 static void
2653 record_thumb_to_arm_glue (struct bfd_link_info *link_info,
2654 struct elf_link_hash_entry *h)
2656 const char *name = h->root.root.string;
2657 asection *s;
2658 char *tmp_name;
2659 struct elf_link_hash_entry *myh;
2660 struct bfd_link_hash_entry *bh;
2661 struct elf32_arm_link_hash_table *hash_table;
2662 bfd_vma val;
2664 hash_table = elf32_arm_hash_table (link_info);
2666 BFD_ASSERT (hash_table != NULL);
2667 BFD_ASSERT (hash_table->bfd_of_glue_owner != NULL);
2669 s = bfd_get_section_by_name
2670 (hash_table->bfd_of_glue_owner, THUMB2ARM_GLUE_SECTION_NAME);
2672 BFD_ASSERT (s != NULL);
2674 tmp_name = bfd_malloc ((bfd_size_type) strlen (name)
2675 + strlen (THUMB2ARM_GLUE_ENTRY_NAME) + 1);
2677 BFD_ASSERT (tmp_name);
2679 sprintf (tmp_name, THUMB2ARM_GLUE_ENTRY_NAME, name);
2681 myh = elf_link_hash_lookup
2682 (&(hash_table)->root, tmp_name, FALSE, FALSE, TRUE);
2684 if (myh != NULL)
2686 /* We've already seen this guy. */
2687 free (tmp_name);
2688 return;
2691 bh = NULL;
2692 val = hash_table->thumb_glue_size + 1;
2693 _bfd_generic_link_add_one_symbol (link_info, hash_table->bfd_of_glue_owner,
2694 tmp_name, BSF_GLOBAL, s, val,
2695 NULL, TRUE, FALSE, &bh);
2697 /* If we mark it 'Thumb', the disassembler will do a better job. */
2698 myh = (struct elf_link_hash_entry *) bh;
2699 myh->type = ELF_ST_INFO (STB_LOCAL, STT_ARM_TFUNC);
2700 myh->forced_local = 1;
2702 free (tmp_name);
2704 #define CHANGE_TO_ARM "__%s_change_to_arm"
2705 #define BACK_FROM_ARM "__%s_back_from_arm"
2707 /* Allocate another symbol to mark where we switch to Arm mode. */
2708 tmp_name = bfd_malloc ((bfd_size_type) strlen (name)
2709 + strlen (CHANGE_TO_ARM) + 1);
2711 BFD_ASSERT (tmp_name);
2713 sprintf (tmp_name, CHANGE_TO_ARM, name);
2715 bh = NULL;
2716 val = hash_table->thumb_glue_size + 4,
2717 _bfd_generic_link_add_one_symbol (link_info, hash_table->bfd_of_glue_owner,
2718 tmp_name, BSF_LOCAL, s, val,
2719 NULL, TRUE, FALSE, &bh);
2721 free (tmp_name);
2723 hash_table->thumb_glue_size += THUMB2ARM_GLUE_SIZE;
2725 return;
2728 /* Add the glue sections to ABFD. This function is called from the
2729 linker scripts in ld/emultempl/{armelf}.em. */
2731 bfd_boolean
2732 bfd_elf32_arm_add_glue_sections_to_bfd (bfd *abfd,
2733 struct bfd_link_info *info)
2735 flagword flags;
2736 asection *sec;
2738 /* If we are only performing a partial
2739 link do not bother adding the glue. */
2740 if (info->relocatable)
2741 return TRUE;
2743 sec = bfd_get_section_by_name (abfd, ARM2THUMB_GLUE_SECTION_NAME);
2745 if (sec == NULL)
2747 /* Note: we do not include the flag SEC_LINKER_CREATED, as this
2748 will prevent elf_link_input_bfd() from processing the contents
2749 of this section. */
2750 flags = SEC_ALLOC | SEC_LOAD | SEC_HAS_CONTENTS | SEC_IN_MEMORY | SEC_CODE | SEC_READONLY;
2752 sec = bfd_make_section_with_flags (abfd,
2753 ARM2THUMB_GLUE_SECTION_NAME,
2754 flags);
2756 if (sec == NULL
2757 || !bfd_set_section_alignment (abfd, sec, 2))
2758 return FALSE;
2760 /* Set the gc mark to prevent the section from being removed by garbage
2761 collection, despite the fact that no relocs refer to this section. */
2762 sec->gc_mark = 1;
2765 sec = bfd_get_section_by_name (abfd, THUMB2ARM_GLUE_SECTION_NAME);
2767 if (sec == NULL)
2769 flags = SEC_ALLOC | SEC_LOAD | SEC_HAS_CONTENTS | SEC_IN_MEMORY
2770 | SEC_CODE | SEC_READONLY;
2772 sec = bfd_make_section_with_flags (abfd,
2773 THUMB2ARM_GLUE_SECTION_NAME,
2774 flags);
2776 if (sec == NULL
2777 || !bfd_set_section_alignment (abfd, sec, 2))
2778 return FALSE;
2780 sec->gc_mark = 1;
2783 return TRUE;
2786 /* Select a BFD to be used to hold the sections used by the glue code.
2787 This function is called from the linker scripts in ld/emultempl/
2788 {armelf/pe}.em */
2790 bfd_boolean
2791 bfd_elf32_arm_get_bfd_for_interworking (bfd *abfd, struct bfd_link_info *info)
2793 struct elf32_arm_link_hash_table *globals;
2795 /* If we are only performing a partial link
2796 do not bother getting a bfd to hold the glue. */
2797 if (info->relocatable)
2798 return TRUE;
2800 /* Make sure we don't attach the glue sections to a dynamic object. */
2801 BFD_ASSERT (!(abfd->flags & DYNAMIC));
2803 globals = elf32_arm_hash_table (info);
2805 BFD_ASSERT (globals != NULL);
2807 if (globals->bfd_of_glue_owner != NULL)
2808 return TRUE;
2810 /* Save the bfd for later use. */
2811 globals->bfd_of_glue_owner = abfd;
2813 return TRUE;
2816 static void check_use_blx(struct elf32_arm_link_hash_table *globals)
2818 if (elf32_arm_get_eabi_attr_int (globals->obfd, Tag_CPU_arch) > 2)
2819 globals->use_blx = 1;
2822 bfd_boolean
2823 bfd_elf32_arm_process_before_allocation (bfd *abfd,
2824 struct bfd_link_info *link_info,
2825 int byteswap_code)
2827 Elf_Internal_Shdr *symtab_hdr;
2828 Elf_Internal_Rela *internal_relocs = NULL;
2829 Elf_Internal_Rela *irel, *irelend;
2830 bfd_byte *contents = NULL;
2832 asection *sec;
2833 struct elf32_arm_link_hash_table *globals;
2835 /* If we are only performing a partial link do not bother
2836 to construct any glue. */
2837 if (link_info->relocatable)
2838 return TRUE;
2840 /* Here we have a bfd that is to be included on the link. We have a hook
2841 to do reloc rummaging, before section sizes are nailed down. */
2842 globals = elf32_arm_hash_table (link_info);
2843 check_use_blx (globals);
2845 BFD_ASSERT (globals != NULL);
2846 BFD_ASSERT (globals->bfd_of_glue_owner != NULL);
2848 if (byteswap_code && !bfd_big_endian (abfd))
2850 _bfd_error_handler (_("%B: BE8 images only valid in big-endian mode."),
2851 abfd);
2852 return FALSE;
2854 globals->byteswap_code = byteswap_code;
2856 /* Rummage around all the relocs and map the glue vectors. */
2857 sec = abfd->sections;
2859 if (sec == NULL)
2860 return TRUE;
2862 for (; sec != NULL; sec = sec->next)
2864 if (sec->reloc_count == 0)
2865 continue;
2867 symtab_hdr = &elf_tdata (abfd)->symtab_hdr;
2869 /* Load the relocs. */
2870 internal_relocs
2871 = _bfd_elf_link_read_relocs (abfd, sec, (void *) NULL,
2872 (Elf_Internal_Rela *) NULL, FALSE);
2874 if (internal_relocs == NULL)
2875 goto error_return;
2877 irelend = internal_relocs + sec->reloc_count;
2878 for (irel = internal_relocs; irel < irelend; irel++)
2880 long r_type;
2881 unsigned long r_index;
2883 struct elf_link_hash_entry *h;
2885 r_type = ELF32_R_TYPE (irel->r_info);
2886 r_index = ELF32_R_SYM (irel->r_info);
2888 /* These are the only relocation types we care about. */
2889 if ( r_type != R_ARM_PC24
2890 && r_type != R_ARM_PLT32
2891 && r_type != R_ARM_CALL
2892 && r_type != R_ARM_JUMP24
2893 && r_type != R_ARM_THM_CALL)
2894 continue;
2896 /* Get the section contents if we haven't done so already. */
2897 if (contents == NULL)
2899 /* Get cached copy if it exists. */
2900 if (elf_section_data (sec)->this_hdr.contents != NULL)
2901 contents = elf_section_data (sec)->this_hdr.contents;
2902 else
2904 /* Go get them off disk. */
2905 if (! bfd_malloc_and_get_section (abfd, sec, &contents))
2906 goto error_return;
2910 /* If the relocation is not against a symbol it cannot concern us. */
2911 h = NULL;
2913 /* We don't care about local symbols. */
2914 if (r_index < symtab_hdr->sh_info)
2915 continue;
2917 /* This is an external symbol. */
2918 r_index -= symtab_hdr->sh_info;
2919 h = (struct elf_link_hash_entry *)
2920 elf_sym_hashes (abfd)[r_index];
2922 /* If the relocation is against a static symbol it must be within
2923 the current section and so cannot be a cross ARM/Thumb relocation. */
2924 if (h == NULL)
2925 continue;
2927 /* If the call will go through a PLT entry then we do not need
2928 glue. */
2929 if (globals->splt != NULL && h->plt.offset != (bfd_vma) -1)
2930 continue;
2932 switch (r_type)
2934 case R_ARM_PC24:
2935 case R_ARM_PLT32:
2936 case R_ARM_CALL:
2937 case R_ARM_JUMP24:
2938 /* This one is a call from arm code. We need to look up
2939 the target of the call. If it is a thumb target, we
2940 insert glue. */
2941 if (ELF_ST_TYPE(h->type) == STT_ARM_TFUNC
2942 && !(r_type == R_ARM_CALL && globals->use_blx))
2943 record_arm_to_thumb_glue (link_info, h);
2944 break;
2946 case R_ARM_THM_CALL:
2947 /* This one is a call from thumb code. We look
2948 up the target of the call. If it is not a thumb
2949 target, we insert glue. */
2950 if (ELF_ST_TYPE (h->type) != STT_ARM_TFUNC && !globals->use_blx)
2951 record_thumb_to_arm_glue (link_info, h);
2952 break;
2954 default:
2955 abort ();
2959 if (contents != NULL
2960 && elf_section_data (sec)->this_hdr.contents != contents)
2961 free (contents);
2962 contents = NULL;
2964 if (internal_relocs != NULL
2965 && elf_section_data (sec)->relocs != internal_relocs)
2966 free (internal_relocs);
2967 internal_relocs = NULL;
2970 return TRUE;
2972 error_return:
2973 if (contents != NULL
2974 && elf_section_data (sec)->this_hdr.contents != contents)
2975 free (contents);
2976 if (internal_relocs != NULL
2977 && elf_section_data (sec)->relocs != internal_relocs)
2978 free (internal_relocs);
2980 return FALSE;
2982 #endif
2985 /* Set target relocation values needed during linking. */
2987 void
2988 bfd_elf32_arm_set_target_relocs (struct bfd_link_info *link_info,
2989 int target1_is_rel,
2990 char * target2_type,
2991 int fix_v4bx,
2992 int use_blx)
2994 struct elf32_arm_link_hash_table *globals;
2996 globals = elf32_arm_hash_table (link_info);
2998 globals->target1_is_rel = target1_is_rel;
2999 if (strcmp (target2_type, "rel") == 0)
3000 globals->target2_reloc = R_ARM_REL32;
3001 else if (strcmp (target2_type, "abs") == 0)
3002 globals->target2_reloc = R_ARM_ABS32;
3003 else if (strcmp (target2_type, "got-rel") == 0)
3004 globals->target2_reloc = R_ARM_GOT_PREL;
3005 else
3007 _bfd_error_handler (_("Invalid TARGET2 relocation type '%s'."),
3008 target2_type);
3010 globals->fix_v4bx = fix_v4bx;
3011 globals->use_blx |= use_blx;
3014 /* The thumb form of a long branch is a bit finicky, because the offset
3015 encoding is split over two fields, each in it's own instruction. They
3016 can occur in any order. So given a thumb form of long branch, and an
3017 offset, insert the offset into the thumb branch and return finished
3018 instruction.
3020 It takes two thumb instructions to encode the target address. Each has
3021 11 bits to invest. The upper 11 bits are stored in one (identified by
3022 H-0.. see below), the lower 11 bits are stored in the other (identified
3023 by H-1).
3025 Combine together and shifted left by 1 (it's a half word address) and
3026 there you have it.
3028 Op: 1111 = F,
3029 H-0, upper address-0 = 000
3030 Op: 1111 = F,
3031 H-1, lower address-0 = 800
3033 They can be ordered either way, but the arm tools I've seen always put
3034 the lower one first. It probably doesn't matter. krk@cygnus.com
3036 XXX: Actually the order does matter. The second instruction (H-1)
3037 moves the computed address into the PC, so it must be the second one
3038 in the sequence. The problem, however is that whilst little endian code
3039 stores the instructions in HI then LOW order, big endian code does the
3040 reverse. nickc@cygnus.com. */
3042 #define LOW_HI_ORDER 0xF800F000
3043 #define HI_LOW_ORDER 0xF000F800
3045 static insn32
3046 insert_thumb_branch (insn32 br_insn, int rel_off)
3048 unsigned int low_bits;
3049 unsigned int high_bits;
3051 BFD_ASSERT ((rel_off & 1) != 1);
3053 rel_off >>= 1; /* Half word aligned address. */
3054 low_bits = rel_off & 0x000007FF; /* The bottom 11 bits. */
3055 high_bits = (rel_off >> 11) & 0x000007FF; /* The top 11 bits. */
3057 if ((br_insn & LOW_HI_ORDER) == LOW_HI_ORDER)
3058 br_insn = LOW_HI_ORDER | (low_bits << 16) | high_bits;
3059 else if ((br_insn & HI_LOW_ORDER) == HI_LOW_ORDER)
3060 br_insn = HI_LOW_ORDER | (high_bits << 16) | low_bits;
3061 else
3062 /* FIXME: abort is probably not the right call. krk@cygnus.com */
3063 abort (); /* Error - not a valid branch instruction form. */
3065 return br_insn;
3069 /* Store an Arm insn into an output section not processed by
3070 elf32_arm_write_section. */
3072 static void
3073 put_arm_insn (struct elf32_arm_link_hash_table *htab,
3074 bfd * output_bfd, bfd_vma val, void * ptr)
3076 if (htab->byteswap_code != bfd_little_endian (output_bfd))
3077 bfd_putl32 (val, ptr);
3078 else
3079 bfd_putb32 (val, ptr);
3083 /* Store a 16-bit Thumb insn into an output section not processed by
3084 elf32_arm_write_section. */
3086 static void
3087 put_thumb_insn (struct elf32_arm_link_hash_table *htab,
3088 bfd * output_bfd, bfd_vma val, void * ptr)
3090 if (htab->byteswap_code != bfd_little_endian (output_bfd))
3091 bfd_putl16 (val, ptr);
3092 else
3093 bfd_putb16 (val, ptr);
3097 /* Thumb code calling an ARM function. */
3099 static int
3100 elf32_thumb_to_arm_stub (struct bfd_link_info * info,
3101 const char * name,
3102 bfd * input_bfd,
3103 bfd * output_bfd,
3104 asection * input_section,
3105 bfd_byte * hit_data,
3106 asection * sym_sec,
3107 bfd_vma offset,
3108 bfd_signed_vma addend,
3109 bfd_vma val)
3111 asection * s = 0;
3112 bfd_vma my_offset;
3113 unsigned long int tmp;
3114 long int ret_offset;
3115 struct elf_link_hash_entry * myh;
3116 struct elf32_arm_link_hash_table * globals;
3118 myh = find_thumb_glue (info, name, input_bfd);
3119 if (myh == NULL)
3120 return FALSE;
3122 globals = elf32_arm_hash_table (info);
3124 BFD_ASSERT (globals != NULL);
3125 BFD_ASSERT (globals->bfd_of_glue_owner != NULL);
3127 my_offset = myh->root.u.def.value;
3129 s = bfd_get_section_by_name (globals->bfd_of_glue_owner,
3130 THUMB2ARM_GLUE_SECTION_NAME);
3132 BFD_ASSERT (s != NULL);
3133 BFD_ASSERT (s->contents != NULL);
3134 BFD_ASSERT (s->output_section != NULL);
3136 if ((my_offset & 0x01) == 0x01)
3138 if (sym_sec != NULL
3139 && sym_sec->owner != NULL
3140 && !INTERWORK_FLAG (sym_sec->owner))
3142 (*_bfd_error_handler)
3143 (_("%B(%s): warning: interworking not enabled.\n"
3144 " first occurrence: %B: thumb call to arm"),
3145 sym_sec->owner, input_bfd, name);
3147 return FALSE;
3150 --my_offset;
3151 myh->root.u.def.value = my_offset;
3153 put_thumb_insn (globals, output_bfd, (bfd_vma) t2a1_bx_pc_insn,
3154 s->contents + my_offset);
3156 put_thumb_insn (globals, output_bfd, (bfd_vma) t2a2_noop_insn,
3157 s->contents + my_offset + 2);
3159 ret_offset =
3160 /* Address of destination of the stub. */
3161 ((bfd_signed_vma) val)
3162 - ((bfd_signed_vma)
3163 /* Offset from the start of the current section
3164 to the start of the stubs. */
3165 (s->output_offset
3166 /* Offset of the start of this stub from the start of the stubs. */
3167 + my_offset
3168 /* Address of the start of the current section. */
3169 + s->output_section->vma)
3170 /* The branch instruction is 4 bytes into the stub. */
3172 /* ARM branches work from the pc of the instruction + 8. */
3173 + 8);
3175 put_arm_insn (globals, output_bfd,
3176 (bfd_vma) t2a3_b_insn | ((ret_offset >> 2) & 0x00FFFFFF),
3177 s->contents + my_offset + 4);
3180 BFD_ASSERT (my_offset <= globals->thumb_glue_size);
3182 /* Now go back and fix up the original BL insn to point to here. */
3183 ret_offset =
3184 /* Address of where the stub is located. */
3185 (s->output_section->vma + s->output_offset + my_offset)
3186 /* Address of where the BL is located. */
3187 - (input_section->output_section->vma + input_section->output_offset
3188 + offset)
3189 /* Addend in the relocation. */
3190 - addend
3191 /* Biassing for PC-relative addressing. */
3192 - 8;
3194 tmp = bfd_get_32 (input_bfd, hit_data
3195 - input_section->vma);
3197 bfd_put_32 (output_bfd,
3198 (bfd_vma) insert_thumb_branch (tmp, ret_offset),
3199 hit_data - input_section->vma);
3201 return TRUE;
3204 /* Populate an Arm to Thumb stub. Returns the stub symbol. */
3206 static struct elf_link_hash_entry *
3207 elf32_arm_create_thumb_stub (struct bfd_link_info * info,
3208 const char * name,
3209 bfd * input_bfd,
3210 bfd * output_bfd,
3211 asection * sym_sec,
3212 bfd_vma val,
3213 asection *s)
3215 bfd_vma my_offset;
3216 long int ret_offset;
3217 struct elf_link_hash_entry * myh;
3218 struct elf32_arm_link_hash_table * globals;
3220 myh = find_arm_glue (info, name, input_bfd);
3221 if (myh == NULL)
3222 return NULL;
3224 globals = elf32_arm_hash_table (info);
3226 BFD_ASSERT (globals != NULL);
3227 BFD_ASSERT (globals->bfd_of_glue_owner != NULL);
3229 my_offset = myh->root.u.def.value;
3231 if ((my_offset & 0x01) == 0x01)
3233 if (sym_sec != NULL
3234 && sym_sec->owner != NULL
3235 && !INTERWORK_FLAG (sym_sec->owner))
3237 (*_bfd_error_handler)
3238 (_("%B(%s): warning: interworking not enabled.\n"
3239 " first occurrence: %B: arm call to thumb"),
3240 sym_sec->owner, input_bfd, name);
3243 --my_offset;
3244 myh->root.u.def.value = my_offset;
3246 if ((info->shared || globals->root.is_relocatable_executable))
3248 /* For relocatable objects we can't use absolute addresses,
3249 so construct the address from a relative offset. */
3250 /* TODO: If the offset is small it's probably worth
3251 constructing the address with adds. */
3252 put_arm_insn (globals, output_bfd, (bfd_vma) a2t1p_ldr_insn,
3253 s->contents + my_offset);
3254 put_arm_insn (globals, output_bfd, (bfd_vma) a2t2p_add_pc_insn,
3255 s->contents + my_offset + 4);
3256 put_arm_insn (globals, output_bfd, (bfd_vma) a2t3p_bx_r12_insn,
3257 s->contents + my_offset + 8);
3258 /* Adjust the offset by 4 for the position of the add,
3259 and 8 for the pipeline offset. */
3260 ret_offset = (val - (s->output_offset
3261 + s->output_section->vma
3262 + my_offset + 12))
3263 | 1;
3264 bfd_put_32 (output_bfd, ret_offset,
3265 s->contents + my_offset + 12);
3267 else
3269 put_arm_insn (globals, output_bfd, (bfd_vma) a2t1_ldr_insn,
3270 s->contents + my_offset);
3272 put_arm_insn (globals, output_bfd, (bfd_vma) a2t2_bx_r12_insn,
3273 s->contents + my_offset + 4);
3275 /* It's a thumb address. Add the low order bit. */
3276 bfd_put_32 (output_bfd, val | a2t3_func_addr_insn,
3277 s->contents + my_offset + 8);
3281 BFD_ASSERT (my_offset <= globals->arm_glue_size);
3283 return myh;
3286 /* Arm code calling a Thumb function. */
3288 static int
3289 elf32_arm_to_thumb_stub (struct bfd_link_info * info,
3290 const char * name,
3291 bfd * input_bfd,
3292 bfd * output_bfd,
3293 asection * input_section,
3294 bfd_byte * hit_data,
3295 asection * sym_sec,
3296 bfd_vma offset,
3297 bfd_signed_vma addend,
3298 bfd_vma val)
3300 unsigned long int tmp;
3301 bfd_vma my_offset;
3302 asection * s;
3303 long int ret_offset;
3304 struct elf_link_hash_entry * myh;
3305 struct elf32_arm_link_hash_table * globals;
3307 globals = elf32_arm_hash_table (info);
3309 BFD_ASSERT (globals != NULL);
3310 BFD_ASSERT (globals->bfd_of_glue_owner != NULL);
3312 s = bfd_get_section_by_name (globals->bfd_of_glue_owner,
3313 ARM2THUMB_GLUE_SECTION_NAME);
3314 BFD_ASSERT (s != NULL);
3315 BFD_ASSERT (s->contents != NULL);
3316 BFD_ASSERT (s->output_section != NULL);
3318 myh = elf32_arm_create_thumb_stub (info, name, input_bfd, output_bfd,
3319 sym_sec, val, s);
3320 if (!myh)
3321 return FALSE;
3323 my_offset = myh->root.u.def.value;
3324 tmp = bfd_get_32 (input_bfd, hit_data);
3325 tmp = tmp & 0xFF000000;
3327 /* Somehow these are both 4 too far, so subtract 8. */
3328 ret_offset = (s->output_offset
3329 + my_offset
3330 + s->output_section->vma
3331 - (input_section->output_offset
3332 + input_section->output_section->vma
3333 + offset + addend)
3334 - 8);
3336 tmp = tmp | ((ret_offset >> 2) & 0x00FFFFFF);
3338 bfd_put_32 (output_bfd, (bfd_vma) tmp, hit_data - input_section->vma);
3340 return TRUE;
3343 /* Populate Arm stub for an exported Thumb function. */
3345 static bfd_boolean
3346 elf32_arm_to_thumb_export_stub (struct elf_link_hash_entry *h, void * inf)
3348 struct bfd_link_info * info = (struct bfd_link_info *) inf;
3349 asection * s;
3350 struct elf_link_hash_entry * myh;
3351 struct elf32_arm_link_hash_entry *eh;
3352 struct elf32_arm_link_hash_table * globals;
3353 asection *sec;
3354 bfd_vma val;
3356 eh = elf32_arm_hash_entry(h);
3357 /* Allocate stubs for exported Thumb functions on v4t. */
3358 if (eh->export_glue == NULL)
3359 return TRUE;
3361 globals = elf32_arm_hash_table (info);
3363 BFD_ASSERT (globals != NULL);
3364 BFD_ASSERT (globals->bfd_of_glue_owner != NULL);
3366 s = bfd_get_section_by_name (globals->bfd_of_glue_owner,
3367 ARM2THUMB_GLUE_SECTION_NAME);
3368 BFD_ASSERT (s != NULL);
3369 BFD_ASSERT (s->contents != NULL);
3370 BFD_ASSERT (s->output_section != NULL);
3372 sec = eh->export_glue->root.u.def.section;
3373 val = eh->export_glue->root.u.def.value + sec->output_offset
3374 + sec->output_section->vma;
3375 myh = elf32_arm_create_thumb_stub (info, h->root.root.string,
3376 h->root.u.def.section->owner,
3377 globals->obfd, sec, val, s);
3378 BFD_ASSERT (myh);
3379 return TRUE;
3382 /* Generate Arm stubs for exported Thumb symbols. */
3383 static void
3384 elf32_arm_begin_write_processing (bfd *abfd ATTRIBUTE_UNUSED,
3385 struct bfd_link_info *link_info)
3387 struct elf32_arm_link_hash_table * globals;
3389 if (!link_info)
3390 return;
3392 globals = elf32_arm_hash_table (link_info);
3393 /* If blx is available then exported Thumb symbols are OK and there is
3394 nothing to do. */
3395 if (globals->use_blx)
3396 return;
3398 elf_link_hash_traverse (&globals->root, elf32_arm_to_thumb_export_stub,
3399 link_info);
3402 /* Some relocations map to different relocations depending on the
3403 target. Return the real relocation. */
3404 static int
3405 arm_real_reloc_type (struct elf32_arm_link_hash_table * globals,
3406 int r_type)
3408 switch (r_type)
3410 case R_ARM_TARGET1:
3411 if (globals->target1_is_rel)
3412 return R_ARM_REL32;
3413 else
3414 return R_ARM_ABS32;
3416 case R_ARM_TARGET2:
3417 return globals->target2_reloc;
3419 default:
3420 return r_type;
3424 /* Return the base VMA address which should be subtracted from real addresses
3425 when resolving @dtpoff relocation.
3426 This is PT_TLS segment p_vaddr. */
3428 static bfd_vma
3429 dtpoff_base (struct bfd_link_info *info)
3431 /* If tls_sec is NULL, we should have signalled an error already. */
3432 if (elf_hash_table (info)->tls_sec == NULL)
3433 return 0;
3434 return elf_hash_table (info)->tls_sec->vma;
3437 /* Return the relocation value for @tpoff relocation
3438 if STT_TLS virtual address is ADDRESS. */
3440 static bfd_vma
3441 tpoff (struct bfd_link_info *info, bfd_vma address)
3443 struct elf_link_hash_table *htab = elf_hash_table (info);
3444 bfd_vma base;
3446 /* If tls_sec is NULL, we should have signalled an error already. */
3447 if (htab->tls_sec == NULL)
3448 return 0;
3449 base = align_power ((bfd_vma) TCB_SIZE, htab->tls_sec->alignment_power);
3450 return address - htab->tls_sec->vma + base;
3453 /* Perform an R_ARM_ABS12 relocation on the field pointed to by DATA.
3454 VALUE is the relocation value. */
3456 static bfd_reloc_status_type
3457 elf32_arm_abs12_reloc (bfd *abfd, void *data, bfd_vma value)
3459 if (value > 0xfff)
3460 return bfd_reloc_overflow;
3462 value |= bfd_get_32 (abfd, data) & 0xfffff000;
3463 bfd_put_32 (abfd, value, data);
3464 return bfd_reloc_ok;
3467 /* For a given value of n, calculate the value of G_n as required to
3468 deal with group relocations. We return it in the form of an
3469 encoded constant-and-rotation, together with the final residual. If n is
3470 specified as less than zero, then final_residual is filled with the
3471 input value and no further action is performed. */
3473 static bfd_vma
3474 calculate_group_reloc_mask (bfd_vma value, int n, bfd_vma *final_residual)
3476 int current_n;
3477 bfd_vma g_n;
3478 bfd_vma encoded_g_n = 0;
3479 bfd_vma residual = value; /* Also known as Y_n. */
3481 for (current_n = 0; current_n <= n; current_n++)
3483 int shift;
3485 /* Calculate which part of the value to mask. */
3486 if (residual == 0)
3487 shift = 0;
3488 else
3490 int msb;
3492 /* Determine the most significant bit in the residual and
3493 align the resulting value to a 2-bit boundary. */
3494 for (msb = 30; msb >= 0; msb -= 2)
3495 if (residual & (3 << msb))
3496 break;
3498 /* The desired shift is now (msb - 6), or zero, whichever
3499 is the greater. */
3500 shift = msb - 6;
3501 if (shift < 0)
3502 shift = 0;
3505 /* Calculate g_n in 32-bit as well as encoded constant+rotation form. */
3506 g_n = residual & (0xff << shift);
3507 encoded_g_n = (g_n >> shift)
3508 | ((g_n <= 0xff ? 0 : (32 - shift) / 2) << 8);
3510 /* Calculate the residual for the next time around. */
3511 residual &= ~g_n;
3514 *final_residual = residual;
3516 return encoded_g_n;
3519 /* Given an ARM instruction, determine whether it is an ADD or a SUB.
3520 Returns 1 if it is an ADD, -1 if it is a SUB, and 0 otherwise. */
3521 static int
3522 identify_add_or_sub(bfd_vma insn)
3524 int opcode = insn & 0x1e00000;
3526 if (opcode == 1 << 23) /* ADD */
3527 return 1;
3529 if (opcode == 1 << 22) /* SUB */
3530 return -1;
3532 return 0;
3535 /* Perform a relocation as part of a final link. */
3537 static bfd_reloc_status_type
3538 elf32_arm_final_link_relocate (reloc_howto_type * howto,
3539 bfd * input_bfd,
3540 bfd * output_bfd,
3541 asection * input_section,
3542 bfd_byte * contents,
3543 Elf_Internal_Rela * rel,
3544 bfd_vma value,
3545 struct bfd_link_info * info,
3546 asection * sym_sec,
3547 const char * sym_name,
3548 int sym_flags,
3549 struct elf_link_hash_entry * h,
3550 bfd_boolean * unresolved_reloc_p)
3552 unsigned long r_type = howto->type;
3553 unsigned long r_symndx;
3554 bfd_byte * hit_data = contents + rel->r_offset;
3555 bfd * dynobj = NULL;
3556 Elf_Internal_Shdr * symtab_hdr;
3557 struct elf_link_hash_entry ** sym_hashes;
3558 bfd_vma * local_got_offsets;
3559 asection * sgot = NULL;
3560 asection * splt = NULL;
3561 asection * sreloc = NULL;
3562 bfd_vma addend;
3563 bfd_signed_vma signed_addend;
3564 struct elf32_arm_link_hash_table * globals;
3566 globals = elf32_arm_hash_table (info);
3568 /* Some relocation type map to different relocations depending on the
3569 target. We pick the right one here. */
3570 r_type = arm_real_reloc_type (globals, r_type);
3571 if (r_type != howto->type)
3572 howto = elf32_arm_howto_from_type (r_type);
3574 /* If the start address has been set, then set the EF_ARM_HASENTRY
3575 flag. Setting this more than once is redundant, but the cost is
3576 not too high, and it keeps the code simple.
3578 The test is done here, rather than somewhere else, because the
3579 start address is only set just before the final link commences.
3581 Note - if the user deliberately sets a start address of 0, the
3582 flag will not be set. */
3583 if (bfd_get_start_address (output_bfd) != 0)
3584 elf_elfheader (output_bfd)->e_flags |= EF_ARM_HASENTRY;
3586 dynobj = elf_hash_table (info)->dynobj;
3587 if (dynobj)
3589 sgot = bfd_get_section_by_name (dynobj, ".got");
3590 splt = bfd_get_section_by_name (dynobj, ".plt");
3592 symtab_hdr = & elf_tdata (input_bfd)->symtab_hdr;
3593 sym_hashes = elf_sym_hashes (input_bfd);
3594 local_got_offsets = elf_local_got_offsets (input_bfd);
3595 r_symndx = ELF32_R_SYM (rel->r_info);
3597 if (globals->use_rel)
3599 addend = bfd_get_32 (input_bfd, hit_data) & howto->src_mask;
3601 if (addend & ((howto->src_mask + 1) >> 1))
3603 signed_addend = -1;
3604 signed_addend &= ~ howto->src_mask;
3605 signed_addend |= addend;
3607 else
3608 signed_addend = addend;
3610 else
3611 addend = signed_addend = rel->r_addend;
3613 switch (r_type)
3615 case R_ARM_NONE:
3616 /* We don't need to find a value for this symbol. It's just a
3617 marker. */
3618 *unresolved_reloc_p = FALSE;
3619 return bfd_reloc_ok;
3621 case R_ARM_ABS12:
3622 if (!globals->vxworks_p)
3623 return elf32_arm_abs12_reloc (input_bfd, hit_data, value + addend);
3625 case R_ARM_PC24:
3626 case R_ARM_ABS32:
3627 case R_ARM_REL32:
3628 case R_ARM_CALL:
3629 case R_ARM_JUMP24:
3630 case R_ARM_XPC25:
3631 case R_ARM_PREL31:
3632 case R_ARM_PLT32:
3633 /* r_symndx will be zero only for relocs against symbols
3634 from removed linkonce sections, or sections discarded by
3635 a linker script. */
3636 if (r_symndx == 0)
3637 return bfd_reloc_ok;
3639 /* Handle relocations which should use the PLT entry. ABS32/REL32
3640 will use the symbol's value, which may point to a PLT entry, but we
3641 don't need to handle that here. If we created a PLT entry, all
3642 branches in this object should go to it. */
3643 if ((r_type != R_ARM_ABS32 && r_type != R_ARM_REL32)
3644 && h != NULL
3645 && splt != NULL
3646 && h->plt.offset != (bfd_vma) -1)
3648 /* If we've created a .plt section, and assigned a PLT entry to
3649 this function, it should not be known to bind locally. If
3650 it were, we would have cleared the PLT entry. */
3651 BFD_ASSERT (!SYMBOL_CALLS_LOCAL (info, h));
3653 value = (splt->output_section->vma
3654 + splt->output_offset
3655 + h->plt.offset);
3656 *unresolved_reloc_p = FALSE;
3657 return _bfd_final_link_relocate (howto, input_bfd, input_section,
3658 contents, rel->r_offset, value,
3659 rel->r_addend);
3662 /* When generating a shared object or relocatable executable, these
3663 relocations are copied into the output file to be resolved at
3664 run time. */
3665 if ((info->shared || globals->root.is_relocatable_executable)
3666 && (input_section->flags & SEC_ALLOC)
3667 && (r_type != R_ARM_REL32
3668 || !SYMBOL_CALLS_LOCAL (info, h))
3669 && (h == NULL
3670 || ELF_ST_VISIBILITY (h->other) == STV_DEFAULT
3671 || h->root.type != bfd_link_hash_undefweak)
3672 && r_type != R_ARM_PC24
3673 && r_type != R_ARM_CALL
3674 && r_type != R_ARM_JUMP24
3675 && r_type != R_ARM_PREL31
3676 && r_type != R_ARM_PLT32)
3678 Elf_Internal_Rela outrel;
3679 bfd_byte *loc;
3680 bfd_boolean skip, relocate;
3682 *unresolved_reloc_p = FALSE;
3684 if (sreloc == NULL)
3686 const char * name;
3688 name = (bfd_elf_string_from_elf_section
3689 (input_bfd,
3690 elf_elfheader (input_bfd)->e_shstrndx,
3691 elf_section_data (input_section)->rel_hdr.sh_name));
3692 if (name == NULL)
3693 return bfd_reloc_notsupported;
3695 BFD_ASSERT (reloc_section_p (globals, name, input_section));
3697 sreloc = bfd_get_section_by_name (dynobj, name);
3698 BFD_ASSERT (sreloc != NULL);
3701 skip = FALSE;
3702 relocate = FALSE;
3704 outrel.r_addend = addend;
3705 outrel.r_offset =
3706 _bfd_elf_section_offset (output_bfd, info, input_section,
3707 rel->r_offset);
3708 if (outrel.r_offset == (bfd_vma) -1)
3709 skip = TRUE;
3710 else if (outrel.r_offset == (bfd_vma) -2)
3711 skip = TRUE, relocate = TRUE;
3712 outrel.r_offset += (input_section->output_section->vma
3713 + input_section->output_offset);
3715 if (skip)
3716 memset (&outrel, 0, sizeof outrel);
3717 else if (h != NULL
3718 && h->dynindx != -1
3719 && (!info->shared
3720 || !info->symbolic
3721 || !h->def_regular))
3722 outrel.r_info = ELF32_R_INFO (h->dynindx, r_type);
3723 else
3725 int symbol;
3727 /* This symbol is local, or marked to become local. */
3728 if (sym_flags == STT_ARM_TFUNC)
3729 value |= 1;
3730 if (globals->symbian_p)
3732 /* On Symbian OS, the data segment and text segement
3733 can be relocated independently. Therefore, we
3734 must indicate the segment to which this
3735 relocation is relative. The BPABI allows us to
3736 use any symbol in the right segment; we just use
3737 the section symbol as it is convenient. (We
3738 cannot use the symbol given by "h" directly as it
3739 will not appear in the dynamic symbol table.) */
3740 if (sym_sec)
3741 symbol = elf_section_data (sym_sec->output_section)->dynindx;
3742 else
3743 symbol = elf_section_data (input_section->output_section)->dynindx;
3744 BFD_ASSERT (symbol != 0);
3746 else
3747 /* On SVR4-ish systems, the dynamic loader cannot
3748 relocate the text and data segments independently,
3749 so the symbol does not matter. */
3750 symbol = 0;
3751 outrel.r_info = ELF32_R_INFO (symbol, R_ARM_RELATIVE);
3752 if (globals->use_rel)
3753 relocate = TRUE;
3754 else
3755 outrel.r_addend += value;
3758 loc = sreloc->contents;
3759 loc += sreloc->reloc_count++ * RELOC_SIZE (globals);
3760 SWAP_RELOC_OUT (globals) (output_bfd, &outrel, loc);
3762 /* If this reloc is against an external symbol, we do not want to
3763 fiddle with the addend. Otherwise, we need to include the symbol
3764 value so that it becomes an addend for the dynamic reloc. */
3765 if (! relocate)
3766 return bfd_reloc_ok;
3768 return _bfd_final_link_relocate (howto, input_bfd, input_section,
3769 contents, rel->r_offset, value,
3770 (bfd_vma) 0);
3772 else switch (r_type)
3774 case R_ARM_ABS12:
3775 return elf32_arm_abs12_reloc (input_bfd, hit_data, value + addend);
3777 case R_ARM_XPC25: /* Arm BLX instruction. */
3778 case R_ARM_CALL:
3779 case R_ARM_JUMP24:
3780 case R_ARM_PC24: /* Arm B/BL instruction */
3781 case R_ARM_PLT32:
3782 if (r_type == R_ARM_XPC25)
3784 /* Check for Arm calling Arm function. */
3785 /* FIXME: Should we translate the instruction into a BL
3786 instruction instead ? */
3787 if (sym_flags != STT_ARM_TFUNC)
3788 (*_bfd_error_handler)
3789 (_("\%B: Warning: Arm BLX instruction targets Arm function '%s'."),
3790 input_bfd,
3791 h ? h->root.root.string : "(local)");
3793 else if (r_type != R_ARM_CALL || !globals->use_blx)
3795 /* Check for Arm calling Thumb function. */
3796 if (sym_flags == STT_ARM_TFUNC)
3798 elf32_arm_to_thumb_stub (info, sym_name, input_bfd,
3799 output_bfd, input_section,
3800 hit_data, sym_sec, rel->r_offset,
3801 signed_addend, value);
3802 return bfd_reloc_ok;
3806 /* The ARM ELF ABI says that this reloc is computed as: S - P + A
3807 where:
3808 S is the address of the symbol in the relocation.
3809 P is address of the instruction being relocated.
3810 A is the addend (extracted from the instruction) in bytes.
3812 S is held in 'value'.
3813 P is the base address of the section containing the
3814 instruction plus the offset of the reloc into that
3815 section, ie:
3816 (input_section->output_section->vma +
3817 input_section->output_offset +
3818 rel->r_offset).
3819 A is the addend, converted into bytes, ie:
3820 (signed_addend * 4)
3822 Note: None of these operations have knowledge of the pipeline
3823 size of the processor, thus it is up to the assembler to
3824 encode this information into the addend. */
3825 value -= (input_section->output_section->vma
3826 + input_section->output_offset);
3827 value -= rel->r_offset;
3828 if (globals->use_rel)
3829 value += (signed_addend << howto->size);
3830 else
3831 /* RELA addends do not have to be adjusted by howto->size. */
3832 value += signed_addend;
3834 signed_addend = value;
3835 signed_addend >>= howto->rightshift;
3837 /* It is not an error for an undefined weak reference to be
3838 out of range. Any program that branches to such a symbol
3839 is going to crash anyway, so there is no point worrying
3840 about getting the destination exactly right. */
3841 if (! h || h->root.type != bfd_link_hash_undefweak)
3843 /* Perform a signed range check. */
3844 if ( signed_addend > ((bfd_signed_vma) (howto->dst_mask >> 1))
3845 || signed_addend < - ((bfd_signed_vma) ((howto->dst_mask + 1) >> 1)))
3846 return bfd_reloc_overflow;
3849 addend = (value & 2);
3851 value = (signed_addend & howto->dst_mask)
3852 | (bfd_get_32 (input_bfd, hit_data) & (~ howto->dst_mask));
3854 /* Set the H bit in the BLX instruction. */
3855 if (sym_flags == STT_ARM_TFUNC)
3857 if (addend)
3858 value |= (1 << 24);
3859 else
3860 value &= ~(bfd_vma)(1 << 24);
3862 if (r_type == R_ARM_CALL)
3864 /* Select the correct instruction (BL or BLX). */
3865 if (sym_flags == STT_ARM_TFUNC)
3866 value |= (1 << 28);
3867 else
3869 value &= ~(bfd_vma)(1 << 28);
3870 value |= (1 << 24);
3873 break;
3875 case R_ARM_ABS32:
3876 value += addend;
3877 if (sym_flags == STT_ARM_TFUNC)
3878 value |= 1;
3879 break;
3881 case R_ARM_REL32:
3882 value += addend;
3883 if (sym_flags == STT_ARM_TFUNC)
3884 value |= 1;
3885 value -= (input_section->output_section->vma
3886 + input_section->output_offset + rel->r_offset);
3887 break;
3889 case R_ARM_PREL31:
3890 value -= (input_section->output_section->vma
3891 + input_section->output_offset + rel->r_offset);
3892 value += signed_addend;
3893 if (! h || h->root.type != bfd_link_hash_undefweak)
3895 /* Check for overflow */
3896 if ((value ^ (value >> 1)) & (1 << 30))
3897 return bfd_reloc_overflow;
3899 value &= 0x7fffffff;
3900 value |= (bfd_get_32 (input_bfd, hit_data) & 0x80000000);
3901 if (sym_flags == STT_ARM_TFUNC)
3902 value |= 1;
3903 break;
3906 bfd_put_32 (input_bfd, value, hit_data);
3907 return bfd_reloc_ok;
3909 case R_ARM_ABS8:
3910 value += addend;
3911 if ((long) value > 0x7f || (long) value < -0x80)
3912 return bfd_reloc_overflow;
3914 bfd_put_8 (input_bfd, value, hit_data);
3915 return bfd_reloc_ok;
3917 case R_ARM_ABS16:
3918 value += addend;
3920 if ((long) value > 0x7fff || (long) value < -0x8000)
3921 return bfd_reloc_overflow;
3923 bfd_put_16 (input_bfd, value, hit_data);
3924 return bfd_reloc_ok;
3926 case R_ARM_THM_ABS5:
3927 /* Support ldr and str instructions for the thumb. */
3928 if (globals->use_rel)
3930 /* Need to refetch addend. */
3931 addend = bfd_get_16 (input_bfd, hit_data) & howto->src_mask;
3932 /* ??? Need to determine shift amount from operand size. */
3933 addend >>= howto->rightshift;
3935 value += addend;
3937 /* ??? Isn't value unsigned? */
3938 if ((long) value > 0x1f || (long) value < -0x10)
3939 return bfd_reloc_overflow;
3941 /* ??? Value needs to be properly shifted into place first. */
3942 value |= bfd_get_16 (input_bfd, hit_data) & 0xf83f;
3943 bfd_put_16 (input_bfd, value, hit_data);
3944 return bfd_reloc_ok;
3946 case R_ARM_THM_XPC22:
3947 case R_ARM_THM_CALL:
3948 /* Thumb BL (branch long instruction). */
3950 bfd_vma relocation;
3951 bfd_boolean overflow = FALSE;
3952 bfd_vma upper_insn = bfd_get_16 (input_bfd, hit_data);
3953 bfd_vma lower_insn = bfd_get_16 (input_bfd, hit_data + 2);
3954 bfd_signed_vma reloc_signed_max = ((1 << (howto->bitsize - 1)) - 1) >> howto->rightshift;
3955 bfd_signed_vma reloc_signed_min = ~ reloc_signed_max;
3956 bfd_vma check;
3957 bfd_signed_vma signed_check;
3959 /* Need to refetch the addend and squish the two 11 bit pieces
3960 together. */
3961 if (globals->use_rel)
3963 bfd_vma upper = upper_insn & 0x7ff;
3964 bfd_vma lower = lower_insn & 0x7ff;
3965 upper = (upper ^ 0x400) - 0x400; /* Sign extend. */
3966 addend = (upper << 12) | (lower << 1);
3967 signed_addend = addend;
3970 if (r_type == R_ARM_THM_XPC22)
3972 /* Check for Thumb to Thumb call. */
3973 /* FIXME: Should we translate the instruction into a BL
3974 instruction instead ? */
3975 if (sym_flags == STT_ARM_TFUNC)
3976 (*_bfd_error_handler)
3977 (_("%B: Warning: Thumb BLX instruction targets thumb function '%s'."),
3978 input_bfd,
3979 h ? h->root.root.string : "(local)");
3981 else
3983 /* If it is not a call to Thumb, assume call to Arm.
3984 If it is a call relative to a section name, then it is not a
3985 function call at all, but rather a long jump. Calls through
3986 the PLT do not require stubs. */
3987 if (sym_flags != STT_ARM_TFUNC && sym_flags != STT_SECTION
3988 && (h == NULL || splt == NULL
3989 || h->plt.offset == (bfd_vma) -1))
3991 if (globals->use_blx)
3993 /* Convert BL to BLX. */
3994 lower_insn = (lower_insn & ~0x1000) | 0x0800;
3996 else if (elf32_thumb_to_arm_stub
3997 (info, sym_name, input_bfd, output_bfd, input_section,
3998 hit_data, sym_sec, rel->r_offset, signed_addend, value))
3999 return bfd_reloc_ok;
4000 else
4001 return bfd_reloc_dangerous;
4003 else if (sym_flags == STT_ARM_TFUNC && globals->use_blx)
4005 /* Make sure this is a BL. */
4006 lower_insn |= 0x1800;
4010 /* Handle calls via the PLT. */
4011 if (h != NULL && splt != NULL && h->plt.offset != (bfd_vma) -1)
4013 value = (splt->output_section->vma
4014 + splt->output_offset
4015 + h->plt.offset);
4016 if (globals->use_blx)
4018 /* If the Thumb BLX instruction is available, convert the
4019 BL to a BLX instruction to call the ARM-mode PLT entry. */
4020 lower_insn = (lower_insn & ~0x1000) | 0x0800;
4022 else
4023 /* Target the Thumb stub before the ARM PLT entry. */
4024 value -= PLT_THUMB_STUB_SIZE;
4025 *unresolved_reloc_p = FALSE;
4028 relocation = value + signed_addend;
4030 relocation -= (input_section->output_section->vma
4031 + input_section->output_offset
4032 + rel->r_offset);
4034 check = relocation >> howto->rightshift;
4036 /* If this is a signed value, the rightshift just dropped
4037 leading 1 bits (assuming twos complement). */
4038 if ((bfd_signed_vma) relocation >= 0)
4039 signed_check = check;
4040 else
4041 signed_check = check | ~((bfd_vma) -1 >> howto->rightshift);
4043 /* Assumes two's complement. */
4044 if (signed_check > reloc_signed_max || signed_check < reloc_signed_min)
4045 overflow = TRUE;
4047 if ((lower_insn & 0x1800) == 0x0800)
4048 /* For a BLX instruction, make sure that the relocation is rounded up
4049 to a word boundary. This follows the semantics of the instruction
4050 which specifies that bit 1 of the target address will come from bit
4051 1 of the base address. */
4052 relocation = (relocation + 2) & ~ 3;
4054 /* Put RELOCATION back into the insn. */
4055 upper_insn = (upper_insn & ~(bfd_vma) 0x7ff) | ((relocation >> 12) & 0x7ff);
4056 lower_insn = (lower_insn & ~(bfd_vma) 0x7ff) | ((relocation >> 1) & 0x7ff);
4058 /* Put the relocated value back in the object file: */
4059 bfd_put_16 (input_bfd, upper_insn, hit_data);
4060 bfd_put_16 (input_bfd, lower_insn, hit_data + 2);
4062 return (overflow ? bfd_reloc_overflow : bfd_reloc_ok);
4064 break;
4066 case R_ARM_THM_JUMP24:
4067 /* Thumb32 unconditional branch instruction. */
4069 bfd_vma relocation;
4070 bfd_boolean overflow = FALSE;
4071 bfd_vma upper_insn = bfd_get_16 (input_bfd, hit_data);
4072 bfd_vma lower_insn = bfd_get_16 (input_bfd, hit_data + 2);
4073 bfd_signed_vma reloc_signed_max = ((1 << (howto->bitsize - 1)) - 1) >> howto->rightshift;
4074 bfd_signed_vma reloc_signed_min = ~ reloc_signed_max;
4075 bfd_vma check;
4076 bfd_signed_vma signed_check;
4078 /* Need to refetch the addend, reconstruct the top three bits, and glue the
4079 two pieces together. */
4080 if (globals->use_rel)
4082 bfd_vma S = (upper_insn & 0x0400) >> 10;
4083 bfd_vma hi = (upper_insn & 0x03ff);
4084 bfd_vma I1 = (lower_insn & 0x2000) >> 13;
4085 bfd_vma I2 = (lower_insn & 0x0800) >> 11;
4086 bfd_vma lo = (lower_insn & 0x07ff);
4088 I1 = !(I1 ^ S);
4089 I2 = !(I2 ^ S);
4090 S = !S;
4092 signed_addend = (S << 24) | (I1 << 23) | (I2 << 22) | (hi << 12) | (lo << 1);
4093 signed_addend -= (1 << 24); /* Sign extend. */
4096 /* ??? Should handle interworking? GCC might someday try to
4097 use this for tail calls. */
4099 relocation = value + signed_addend;
4100 relocation -= (input_section->output_section->vma
4101 + input_section->output_offset
4102 + rel->r_offset);
4104 check = relocation >> howto->rightshift;
4106 /* If this is a signed value, the rightshift just dropped
4107 leading 1 bits (assuming twos complement). */
4108 if ((bfd_signed_vma) relocation >= 0)
4109 signed_check = check;
4110 else
4111 signed_check = check | ~((bfd_vma) -1 >> howto->rightshift);
4113 /* Assumes two's complement. */
4114 if (signed_check > reloc_signed_max || signed_check < reloc_signed_min)
4115 overflow = TRUE;
4117 /* Put RELOCATION back into the insn. */
4119 bfd_vma S = (relocation & 0x01000000) >> 24;
4120 bfd_vma I1 = (relocation & 0x00800000) >> 23;
4121 bfd_vma I2 = (relocation & 0x00400000) >> 22;
4122 bfd_vma hi = (relocation & 0x003ff000) >> 12;
4123 bfd_vma lo = (relocation & 0x00000ffe) >> 1;
4125 I1 = !(I1 ^ S);
4126 I2 = !(I2 ^ S);
4128 upper_insn = (upper_insn & (bfd_vma) 0xf800) | (S << 10) | hi;
4129 lower_insn = (lower_insn & (bfd_vma) 0xd000) | (I1 << 13) | (I2 << 11) | lo;
4132 /* Put the relocated value back in the object file: */
4133 bfd_put_16 (input_bfd, upper_insn, hit_data);
4134 bfd_put_16 (input_bfd, lower_insn, hit_data + 2);
4136 return (overflow ? bfd_reloc_overflow : bfd_reloc_ok);
4139 case R_ARM_THM_JUMP19:
4140 /* Thumb32 conditional branch instruction. */
4142 bfd_vma relocation;
4143 bfd_boolean overflow = FALSE;
4144 bfd_vma upper_insn = bfd_get_16 (input_bfd, hit_data);
4145 bfd_vma lower_insn = bfd_get_16 (input_bfd, hit_data + 2);
4146 bfd_signed_vma reloc_signed_max = ((1 << (howto->bitsize - 1)) - 1) >> howto->rightshift;
4147 bfd_signed_vma reloc_signed_min = ~ reloc_signed_max;
4148 bfd_vma check;
4149 bfd_signed_vma signed_check;
4151 /* Need to refetch the addend, reconstruct the top three bits,
4152 and squish the two 11 bit pieces together. */
4153 if (globals->use_rel)
4155 bfd_vma S = (upper_insn & 0x0400) >> 10;
4156 bfd_vma upper = (upper_insn & 0x001f);
4157 bfd_vma J1 = (lower_insn & 0x2000) >> 13;
4158 bfd_vma J2 = (lower_insn & 0x0800) >> 11;
4159 bfd_vma lower = (lower_insn & 0x07ff);
4161 upper |= J2 << 6;
4162 upper |= J1 << 7;
4163 upper |= ~S << 8;
4164 upper -= 0x0100; /* Sign extend. */
4166 addend = (upper << 12) | (lower << 1);
4167 signed_addend = addend;
4170 /* ??? Should handle interworking? GCC might someday try to
4171 use this for tail calls. */
4173 relocation = value + signed_addend;
4174 relocation -= (input_section->output_section->vma
4175 + input_section->output_offset
4176 + rel->r_offset);
4178 check = relocation >> howto->rightshift;
4180 /* If this is a signed value, the rightshift just dropped
4181 leading 1 bits (assuming twos complement). */
4182 if ((bfd_signed_vma) relocation >= 0)
4183 signed_check = check;
4184 else
4185 signed_check = check | ~((bfd_vma) -1 >> howto->rightshift);
4187 /* Assumes two's complement. */
4188 if (signed_check > reloc_signed_max || signed_check < reloc_signed_min)
4189 overflow = TRUE;
4191 /* Put RELOCATION back into the insn. */
4193 bfd_vma S = (relocation & 0x00100000) >> 20;
4194 bfd_vma J2 = (relocation & 0x00080000) >> 19;
4195 bfd_vma J1 = (relocation & 0x00040000) >> 18;
4196 bfd_vma hi = (relocation & 0x0003f000) >> 12;
4197 bfd_vma lo = (relocation & 0x00000ffe) >> 1;
4199 upper_insn = (upper_insn & 0xfb30) | (S << 10) | hi;
4200 lower_insn = (lower_insn & 0xd000) | (J1 << 13) | (J2 << 11) | lo;
4203 /* Put the relocated value back in the object file: */
4204 bfd_put_16 (input_bfd, upper_insn, hit_data);
4205 bfd_put_16 (input_bfd, lower_insn, hit_data + 2);
4207 return (overflow ? bfd_reloc_overflow : bfd_reloc_ok);
4210 case R_ARM_THM_JUMP11:
4211 case R_ARM_THM_JUMP8:
4212 case R_ARM_THM_JUMP6:
4213 /* Thumb B (branch) instruction). */
4215 bfd_signed_vma relocation;
4216 bfd_signed_vma reloc_signed_max = (1 << (howto->bitsize - 1)) - 1;
4217 bfd_signed_vma reloc_signed_min = ~ reloc_signed_max;
4218 bfd_signed_vma signed_check;
4220 /* CZB cannot jump backward. */
4221 if (r_type == R_ARM_THM_JUMP6)
4222 reloc_signed_min = 0;
4224 if (globals->use_rel)
4226 /* Need to refetch addend. */
4227 addend = bfd_get_16 (input_bfd, hit_data) & howto->src_mask;
4228 if (addend & ((howto->src_mask + 1) >> 1))
4230 signed_addend = -1;
4231 signed_addend &= ~ howto->src_mask;
4232 signed_addend |= addend;
4234 else
4235 signed_addend = addend;
4236 /* The value in the insn has been right shifted. We need to
4237 undo this, so that we can perform the address calculation
4238 in terms of bytes. */
4239 signed_addend <<= howto->rightshift;
4241 relocation = value + signed_addend;
4243 relocation -= (input_section->output_section->vma
4244 + input_section->output_offset
4245 + rel->r_offset);
4247 relocation >>= howto->rightshift;
4248 signed_check = relocation;
4250 if (r_type == R_ARM_THM_JUMP6)
4251 relocation = ((relocation & 0x0020) << 4) | ((relocation & 0x001f) << 3);
4252 else
4253 relocation &= howto->dst_mask;
4254 relocation |= (bfd_get_16 (input_bfd, hit_data) & (~ howto->dst_mask));
4256 bfd_put_16 (input_bfd, relocation, hit_data);
4258 /* Assumes two's complement. */
4259 if (signed_check > reloc_signed_max || signed_check < reloc_signed_min)
4260 return bfd_reloc_overflow;
4262 return bfd_reloc_ok;
4265 case R_ARM_ALU_PCREL7_0:
4266 case R_ARM_ALU_PCREL15_8:
4267 case R_ARM_ALU_PCREL23_15:
4269 bfd_vma insn;
4270 bfd_vma relocation;
4272 insn = bfd_get_32 (input_bfd, hit_data);
4273 if (globals->use_rel)
4275 /* Extract the addend. */
4276 addend = (insn & 0xff) << ((insn & 0xf00) >> 7);
4277 signed_addend = addend;
4279 relocation = value + signed_addend;
4281 relocation -= (input_section->output_section->vma
4282 + input_section->output_offset
4283 + rel->r_offset);
4284 insn = (insn & ~0xfff)
4285 | ((howto->bitpos << 7) & 0xf00)
4286 | ((relocation >> howto->bitpos) & 0xff);
4287 bfd_put_32 (input_bfd, value, hit_data);
4289 return bfd_reloc_ok;
4291 case R_ARM_GNU_VTINHERIT:
4292 case R_ARM_GNU_VTENTRY:
4293 return bfd_reloc_ok;
4295 case R_ARM_GOTOFF32:
4296 /* Relocation is relative to the start of the
4297 global offset table. */
4299 BFD_ASSERT (sgot != NULL);
4300 if (sgot == NULL)
4301 return bfd_reloc_notsupported;
4303 /* If we are addressing a Thumb function, we need to adjust the
4304 address by one, so that attempts to call the function pointer will
4305 correctly interpret it as Thumb code. */
4306 if (sym_flags == STT_ARM_TFUNC)
4307 value += 1;
4309 /* Note that sgot->output_offset is not involved in this
4310 calculation. We always want the start of .got. If we
4311 define _GLOBAL_OFFSET_TABLE in a different way, as is
4312 permitted by the ABI, we might have to change this
4313 calculation. */
4314 value -= sgot->output_section->vma;
4315 return _bfd_final_link_relocate (howto, input_bfd, input_section,
4316 contents, rel->r_offset, value,
4317 rel->r_addend);
4319 case R_ARM_GOTPC:
4320 /* Use global offset table as symbol value. */
4321 BFD_ASSERT (sgot != NULL);
4323 if (sgot == NULL)
4324 return bfd_reloc_notsupported;
4326 *unresolved_reloc_p = FALSE;
4327 value = sgot->output_section->vma;
4328 return _bfd_final_link_relocate (howto, input_bfd, input_section,
4329 contents, rel->r_offset, value,
4330 rel->r_addend);
4332 case R_ARM_GOT32:
4333 case R_ARM_GOT_PREL:
4334 /* Relocation is to the entry for this symbol in the
4335 global offset table. */
4336 if (sgot == NULL)
4337 return bfd_reloc_notsupported;
4339 if (h != NULL)
4341 bfd_vma off;
4342 bfd_boolean dyn;
4344 off = h->got.offset;
4345 BFD_ASSERT (off != (bfd_vma) -1);
4346 dyn = globals->root.dynamic_sections_created;
4348 if (! WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn, info->shared, h)
4349 || (info->shared
4350 && SYMBOL_REFERENCES_LOCAL (info, h))
4351 || (ELF_ST_VISIBILITY (h->other)
4352 && h->root.type == bfd_link_hash_undefweak))
4354 /* This is actually a static link, or it is a -Bsymbolic link
4355 and the symbol is defined locally. We must initialize this
4356 entry in the global offset table. Since the offset must
4357 always be a multiple of 4, we use the least significant bit
4358 to record whether we have initialized it already.
4360 When doing a dynamic link, we create a .rel(a).got relocation
4361 entry to initialize the value. This is done in the
4362 finish_dynamic_symbol routine. */
4363 if ((off & 1) != 0)
4364 off &= ~1;
4365 else
4367 /* If we are addressing a Thumb function, we need to
4368 adjust the address by one, so that attempts to
4369 call the function pointer will correctly
4370 interpret it as Thumb code. */
4371 if (sym_flags == STT_ARM_TFUNC)
4372 value |= 1;
4374 bfd_put_32 (output_bfd, value, sgot->contents + off);
4375 h->got.offset |= 1;
4378 else
4379 *unresolved_reloc_p = FALSE;
4381 value = sgot->output_offset + off;
4383 else
4385 bfd_vma off;
4387 BFD_ASSERT (local_got_offsets != NULL &&
4388 local_got_offsets[r_symndx] != (bfd_vma) -1);
4390 off = local_got_offsets[r_symndx];
4392 /* The offset must always be a multiple of 4. We use the
4393 least significant bit to record whether we have already
4394 generated the necessary reloc. */
4395 if ((off & 1) != 0)
4396 off &= ~1;
4397 else
4399 /* If we are addressing a Thumb function, we need to
4400 adjust the address by one, so that attempts to
4401 call the function pointer will correctly
4402 interpret it as Thumb code. */
4403 if (sym_flags == STT_ARM_TFUNC)
4404 value |= 1;
4406 if (globals->use_rel)
4407 bfd_put_32 (output_bfd, value, sgot->contents + off);
4409 if (info->shared)
4411 asection * srelgot;
4412 Elf_Internal_Rela outrel;
4413 bfd_byte *loc;
4415 srelgot = (bfd_get_section_by_name
4416 (dynobj, RELOC_SECTION (globals, ".got")));
4417 BFD_ASSERT (srelgot != NULL);
4419 outrel.r_addend = addend + value;
4420 outrel.r_offset = (sgot->output_section->vma
4421 + sgot->output_offset
4422 + off);
4423 outrel.r_info = ELF32_R_INFO (0, R_ARM_RELATIVE);
4424 loc = srelgot->contents;
4425 loc += srelgot->reloc_count++ * RELOC_SIZE (globals);
4426 SWAP_RELOC_OUT (globals) (output_bfd, &outrel, loc);
4429 local_got_offsets[r_symndx] |= 1;
4432 value = sgot->output_offset + off;
4434 if (r_type != R_ARM_GOT32)
4435 value += sgot->output_section->vma;
4437 return _bfd_final_link_relocate (howto, input_bfd, input_section,
4438 contents, rel->r_offset, value,
4439 rel->r_addend);
4441 case R_ARM_TLS_LDO32:
4442 value = value - dtpoff_base (info);
4444 return _bfd_final_link_relocate (howto, input_bfd, input_section,
4445 contents, rel->r_offset, value,
4446 rel->r_addend);
4448 case R_ARM_TLS_LDM32:
4450 bfd_vma off;
4452 if (globals->sgot == NULL)
4453 abort ();
4455 off = globals->tls_ldm_got.offset;
4457 if ((off & 1) != 0)
4458 off &= ~1;
4459 else
4461 /* If we don't know the module number, create a relocation
4462 for it. */
4463 if (info->shared)
4465 Elf_Internal_Rela outrel;
4466 bfd_byte *loc;
4468 if (globals->srelgot == NULL)
4469 abort ();
4471 outrel.r_addend = 0;
4472 outrel.r_offset = (globals->sgot->output_section->vma
4473 + globals->sgot->output_offset + off);
4474 outrel.r_info = ELF32_R_INFO (0, R_ARM_TLS_DTPMOD32);
4476 if (globals->use_rel)
4477 bfd_put_32 (output_bfd, outrel.r_addend,
4478 globals->sgot->contents + off);
4480 loc = globals->srelgot->contents;
4481 loc += globals->srelgot->reloc_count++ * RELOC_SIZE (globals);
4482 SWAP_RELOC_OUT (globals) (output_bfd, &outrel, loc);
4484 else
4485 bfd_put_32 (output_bfd, 1, globals->sgot->contents + off);
4487 globals->tls_ldm_got.offset |= 1;
4490 value = globals->sgot->output_section->vma + globals->sgot->output_offset + off
4491 - (input_section->output_section->vma + input_section->output_offset + rel->r_offset);
4493 return _bfd_final_link_relocate (howto, input_bfd, input_section,
4494 contents, rel->r_offset, value,
4495 rel->r_addend);
4498 case R_ARM_TLS_GD32:
4499 case R_ARM_TLS_IE32:
4501 bfd_vma off;
4502 int indx;
4503 char tls_type;
4505 if (globals->sgot == NULL)
4506 abort ();
4508 indx = 0;
4509 if (h != NULL)
4511 bfd_boolean dyn;
4512 dyn = globals->root.dynamic_sections_created;
4513 if (WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn, info->shared, h)
4514 && (!info->shared
4515 || !SYMBOL_REFERENCES_LOCAL (info, h)))
4517 *unresolved_reloc_p = FALSE;
4518 indx = h->dynindx;
4520 off = h->got.offset;
4521 tls_type = ((struct elf32_arm_link_hash_entry *) h)->tls_type;
4523 else
4525 if (local_got_offsets == NULL)
4526 abort ();
4527 off = local_got_offsets[r_symndx];
4528 tls_type = elf32_arm_local_got_tls_type (input_bfd)[r_symndx];
4531 if (tls_type == GOT_UNKNOWN)
4532 abort ();
4534 if ((off & 1) != 0)
4535 off &= ~1;
4536 else
4538 bfd_boolean need_relocs = FALSE;
4539 Elf_Internal_Rela outrel;
4540 bfd_byte *loc = NULL;
4541 int cur_off = off;
4543 /* The GOT entries have not been initialized yet. Do it
4544 now, and emit any relocations. If both an IE GOT and a
4545 GD GOT are necessary, we emit the GD first. */
4547 if ((info->shared || indx != 0)
4548 && (h == NULL
4549 || ELF_ST_VISIBILITY (h->other) == STV_DEFAULT
4550 || h->root.type != bfd_link_hash_undefweak))
4552 need_relocs = TRUE;
4553 if (globals->srelgot == NULL)
4554 abort ();
4555 loc = globals->srelgot->contents;
4556 loc += globals->srelgot->reloc_count * RELOC_SIZE (globals);
4559 if (tls_type & GOT_TLS_GD)
4561 if (need_relocs)
4563 outrel.r_addend = 0;
4564 outrel.r_offset = (globals->sgot->output_section->vma
4565 + globals->sgot->output_offset
4566 + cur_off);
4567 outrel.r_info = ELF32_R_INFO (indx, R_ARM_TLS_DTPMOD32);
4569 if (globals->use_rel)
4570 bfd_put_32 (output_bfd, outrel.r_addend,
4571 globals->sgot->contents + cur_off);
4573 SWAP_RELOC_OUT (globals) (output_bfd, &outrel, loc);
4574 globals->srelgot->reloc_count++;
4575 loc += RELOC_SIZE (globals);
4577 if (indx == 0)
4578 bfd_put_32 (output_bfd, value - dtpoff_base (info),
4579 globals->sgot->contents + cur_off + 4);
4580 else
4582 outrel.r_addend = 0;
4583 outrel.r_info = ELF32_R_INFO (indx,
4584 R_ARM_TLS_DTPOFF32);
4585 outrel.r_offset += 4;
4587 if (globals->use_rel)
4588 bfd_put_32 (output_bfd, outrel.r_addend,
4589 globals->sgot->contents + cur_off + 4);
4592 SWAP_RELOC_OUT (globals) (output_bfd, &outrel, loc);
4593 globals->srelgot->reloc_count++;
4594 loc += RELOC_SIZE (globals);
4597 else
4599 /* If we are not emitting relocations for a
4600 general dynamic reference, then we must be in a
4601 static link or an executable link with the
4602 symbol binding locally. Mark it as belonging
4603 to module 1, the executable. */
4604 bfd_put_32 (output_bfd, 1,
4605 globals->sgot->contents + cur_off);
4606 bfd_put_32 (output_bfd, value - dtpoff_base (info),
4607 globals->sgot->contents + cur_off + 4);
4610 cur_off += 8;
4613 if (tls_type & GOT_TLS_IE)
4615 if (need_relocs)
4617 if (indx == 0)
4618 outrel.r_addend = value - dtpoff_base (info);
4619 else
4620 outrel.r_addend = 0;
4621 outrel.r_offset = (globals->sgot->output_section->vma
4622 + globals->sgot->output_offset
4623 + cur_off);
4624 outrel.r_info = ELF32_R_INFO (indx, R_ARM_TLS_TPOFF32);
4626 if (globals->use_rel)
4627 bfd_put_32 (output_bfd, outrel.r_addend,
4628 globals->sgot->contents + cur_off);
4630 SWAP_RELOC_OUT (globals) (output_bfd, &outrel, loc);
4631 globals->srelgot->reloc_count++;
4632 loc += RELOC_SIZE (globals);
4634 else
4635 bfd_put_32 (output_bfd, tpoff (info, value),
4636 globals->sgot->contents + cur_off);
4637 cur_off += 4;
4640 if (h != NULL)
4641 h->got.offset |= 1;
4642 else
4643 local_got_offsets[r_symndx] |= 1;
4646 if ((tls_type & GOT_TLS_GD) && r_type != R_ARM_TLS_GD32)
4647 off += 8;
4648 value = globals->sgot->output_section->vma + globals->sgot->output_offset + off
4649 - (input_section->output_section->vma + input_section->output_offset + rel->r_offset);
4651 return _bfd_final_link_relocate (howto, input_bfd, input_section,
4652 contents, rel->r_offset, value,
4653 rel->r_addend);
4656 case R_ARM_TLS_LE32:
4657 if (info->shared)
4659 (*_bfd_error_handler)
4660 (_("%B(%A+0x%lx): R_ARM_TLS_LE32 relocation not permitted in shared object"),
4661 input_bfd, input_section,
4662 (long) rel->r_offset, howto->name);
4663 return FALSE;
4665 else
4666 value = tpoff (info, value);
4668 return _bfd_final_link_relocate (howto, input_bfd, input_section,
4669 contents, rel->r_offset, value,
4670 rel->r_addend);
4672 case R_ARM_V4BX:
4673 if (globals->fix_v4bx)
4675 bfd_vma insn = bfd_get_32 (input_bfd, hit_data);
4677 /* Ensure that we have a BX instruction. */
4678 BFD_ASSERT ((insn & 0x0ffffff0) == 0x012fff10);
4680 /* Preserve Rm (lowest four bits) and the condition code
4681 (highest four bits). Other bits encode MOV PC,Rm. */
4682 insn = (insn & 0xf000000f) | 0x01a0f000;
4684 bfd_put_32 (input_bfd, insn, hit_data);
4686 return bfd_reloc_ok;
4688 case R_ARM_MOVW_ABS_NC:
4689 case R_ARM_MOVT_ABS:
4690 case R_ARM_MOVW_PREL_NC:
4691 case R_ARM_MOVT_PREL:
4693 bfd_vma insn = bfd_get_32 (input_bfd, hit_data);
4695 if (globals->use_rel)
4697 addend = ((insn >> 4) & 0xf000) | (insn & 0xfff);
4698 signed_addend = (addend ^ 0x10000) - 0x10000;
4700 value += signed_addend;
4701 if (sym_flags == STT_ARM_TFUNC)
4702 value |= 1;
4704 if (r_type == R_ARM_MOVW_PREL_NC || r_type == R_ARM_MOVT_PREL)
4705 value -= (input_section->output_section->vma
4706 + input_section->output_offset + rel->r_offset);
4708 if (r_type == R_ARM_MOVT_ABS || r_type == R_ARM_MOVT_PREL)
4709 value >>= 16;
4711 insn &= 0xfff0f000;
4712 insn |= value & 0xfff;
4713 insn |= (value & 0xf000) << 4;
4714 bfd_put_32 (input_bfd, insn, hit_data);
4716 return bfd_reloc_ok;
4718 case R_ARM_THM_MOVW_ABS_NC:
4719 case R_ARM_THM_MOVT_ABS:
4720 case R_ARM_THM_MOVW_PREL_NC:
4721 case R_ARM_THM_MOVT_PREL:
4723 bfd_vma insn;
4725 insn = bfd_get_16 (input_bfd, hit_data) << 16;
4726 insn |= bfd_get_16 (input_bfd, hit_data + 2);
4728 if (globals->use_rel)
4730 addend = ((insn >> 4) & 0xf000)
4731 | ((insn >> 15) & 0x0800)
4732 | ((insn >> 4) & 0x0700)
4733 | (insn & 0x00ff);
4734 signed_addend = (addend ^ 0x10000) - 0x10000;
4736 value += signed_addend;
4737 if (sym_flags == STT_ARM_TFUNC)
4738 value |= 1;
4740 if (r_type == R_ARM_THM_MOVW_PREL_NC || r_type == R_ARM_THM_MOVT_PREL)
4741 value -= (input_section->output_section->vma
4742 + input_section->output_offset + rel->r_offset);
4744 if (r_type == R_ARM_THM_MOVT_ABS || r_type == R_ARM_THM_MOVT_PREL)
4745 value >>= 16;
4747 insn &= 0xfbf08f00;
4748 insn |= (value & 0xf000) << 4;
4749 insn |= (value & 0x0800) << 15;
4750 insn |= (value & 0x0700) << 4;
4751 insn |= (value & 0x00ff);
4753 bfd_put_16 (input_bfd, insn >> 16, hit_data);
4754 bfd_put_16 (input_bfd, insn & 0xffff, hit_data + 2);
4756 return bfd_reloc_ok;
4758 case R_ARM_ALU_PC_G0_NC:
4759 case R_ARM_ALU_PC_G1_NC:
4760 case R_ARM_ALU_PC_G0:
4761 case R_ARM_ALU_PC_G1:
4762 case R_ARM_ALU_PC_G2:
4763 case R_ARM_ALU_SB_G0_NC:
4764 case R_ARM_ALU_SB_G1_NC:
4765 case R_ARM_ALU_SB_G0:
4766 case R_ARM_ALU_SB_G1:
4767 case R_ARM_ALU_SB_G2:
4769 bfd_vma insn = bfd_get_32 (input_bfd, hit_data);
4770 bfd_vma pc = input_section->output_section->vma
4771 + input_section->output_offset + rel->r_offset;
4772 /* sb should be the origin of the *segment* containing the symbol.
4773 It is not clear how to obtain this OS-dependent value, so we
4774 make an arbitrary choice of zero. */
4775 bfd_vma sb = 0;
4776 bfd_vma residual;
4777 bfd_vma g_n;
4778 bfd_signed_vma signed_value;
4779 int group = 0;
4781 /* Determine which group of bits to select. */
4782 switch (r_type)
4784 case R_ARM_ALU_PC_G0_NC:
4785 case R_ARM_ALU_PC_G0:
4786 case R_ARM_ALU_SB_G0_NC:
4787 case R_ARM_ALU_SB_G0:
4788 group = 0;
4789 break;
4791 case R_ARM_ALU_PC_G1_NC:
4792 case R_ARM_ALU_PC_G1:
4793 case R_ARM_ALU_SB_G1_NC:
4794 case R_ARM_ALU_SB_G1:
4795 group = 1;
4796 break;
4798 case R_ARM_ALU_PC_G2:
4799 case R_ARM_ALU_SB_G2:
4800 group = 2;
4801 break;
4803 default:
4804 abort();
4807 /* If REL, extract the addend from the insn. If RELA, it will
4808 have already been fetched for us. */
4809 if (globals->use_rel)
4811 int negative;
4812 bfd_vma constant = insn & 0xff;
4813 bfd_vma rotation = (insn & 0xf00) >> 8;
4815 if (rotation == 0)
4816 signed_addend = constant;
4817 else
4819 /* Compensate for the fact that in the instruction, the
4820 rotation is stored in multiples of 2 bits. */
4821 rotation *= 2;
4823 /* Rotate "constant" right by "rotation" bits. */
4824 signed_addend = (constant >> rotation) |
4825 (constant << (8 * sizeof (bfd_vma) - rotation));
4828 /* Determine if the instruction is an ADD or a SUB.
4829 (For REL, this determines the sign of the addend.) */
4830 negative = identify_add_or_sub (insn);
4831 if (negative == 0)
4833 (*_bfd_error_handler)
4834 (_("%B(%A+0x%lx): Only ADD or SUB instructions are allowed for ALU group relocations"),
4835 input_bfd, input_section,
4836 (long) rel->r_offset, howto->name);
4837 return bfd_reloc_overflow;
4840 signed_addend *= negative;
4843 /* Compute the value (X) to go in the place. */
4844 if (r_type == R_ARM_ALU_PC_G0_NC
4845 || r_type == R_ARM_ALU_PC_G1_NC
4846 || r_type == R_ARM_ALU_PC_G0
4847 || r_type == R_ARM_ALU_PC_G1
4848 || r_type == R_ARM_ALU_PC_G2)
4849 /* PC relative. */
4850 signed_value = value - pc + signed_addend;
4851 else
4852 /* Section base relative. */
4853 signed_value = value - sb + signed_addend;
4855 /* If the target symbol is a Thumb function, then set the
4856 Thumb bit in the address. */
4857 if (sym_flags == STT_ARM_TFUNC)
4858 signed_value |= 1;
4860 /* Calculate the value of the relevant G_n, in encoded
4861 constant-with-rotation format. */
4862 g_n = calculate_group_reloc_mask (abs (signed_value), group,
4863 &residual);
4865 /* Check for overflow if required. */
4866 if ((r_type == R_ARM_ALU_PC_G0
4867 || r_type == R_ARM_ALU_PC_G1
4868 || r_type == R_ARM_ALU_PC_G2
4869 || r_type == R_ARM_ALU_SB_G0
4870 || r_type == R_ARM_ALU_SB_G1
4871 || r_type == R_ARM_ALU_SB_G2) && residual != 0)
4873 (*_bfd_error_handler)
4874 (_("%B(%A+0x%lx): Overflow whilst splitting 0x%lx for group relocation %s"),
4875 input_bfd, input_section,
4876 (long) rel->r_offset, abs (signed_value), howto->name);
4877 return bfd_reloc_overflow;
4880 /* Mask out the value and the ADD/SUB part of the opcode; take care
4881 not to destroy the S bit. */
4882 insn &= 0xff1ff000;
4884 /* Set the opcode according to whether the value to go in the
4885 place is negative. */
4886 if (signed_value < 0)
4887 insn |= 1 << 22;
4888 else
4889 insn |= 1 << 23;
4891 /* Encode the offset. */
4892 insn |= g_n;
4894 bfd_put_32 (input_bfd, insn, hit_data);
4896 return bfd_reloc_ok;
4898 case R_ARM_LDR_PC_G0:
4899 case R_ARM_LDR_PC_G1:
4900 case R_ARM_LDR_PC_G2:
4901 case R_ARM_LDR_SB_G0:
4902 case R_ARM_LDR_SB_G1:
4903 case R_ARM_LDR_SB_G2:
4905 bfd_vma insn = bfd_get_32 (input_bfd, hit_data);
4906 bfd_vma pc = input_section->output_section->vma
4907 + input_section->output_offset + rel->r_offset;
4908 bfd_vma sb = 0; /* See note above. */
4909 bfd_vma residual;
4910 bfd_signed_vma signed_value;
4911 int group = 0;
4913 /* Determine which groups of bits to calculate. */
4914 switch (r_type)
4916 case R_ARM_LDR_PC_G0:
4917 case R_ARM_LDR_SB_G0:
4918 group = 0;
4919 break;
4921 case R_ARM_LDR_PC_G1:
4922 case R_ARM_LDR_SB_G1:
4923 group = 1;
4924 break;
4926 case R_ARM_LDR_PC_G2:
4927 case R_ARM_LDR_SB_G2:
4928 group = 2;
4929 break;
4931 default:
4932 abort();
4935 /* If REL, extract the addend from the insn. If RELA, it will
4936 have already been fetched for us. */
4937 if (globals->use_rel)
4939 int negative = (insn & (1 << 23)) ? 1 : -1;
4940 signed_addend = negative * (insn & 0xfff);
4943 /* Compute the value (X) to go in the place. */
4944 if (r_type == R_ARM_LDR_PC_G0
4945 || r_type == R_ARM_LDR_PC_G1
4946 || r_type == R_ARM_LDR_PC_G2)
4947 /* PC relative. */
4948 signed_value = value - pc + signed_addend;
4949 else
4950 /* Section base relative. */
4951 signed_value = value - sb + signed_addend;
4953 /* Calculate the value of the relevant G_{n-1} to obtain
4954 the residual at that stage. */
4955 calculate_group_reloc_mask (abs (signed_value), group - 1, &residual);
4957 /* Check for overflow. */
4958 if (residual >= 0x1000)
4960 (*_bfd_error_handler)
4961 (_("%B(%A+0x%lx): Overflow whilst splitting 0x%lx for group relocation %s"),
4962 input_bfd, input_section,
4963 (long) rel->r_offset, abs (signed_value), howto->name);
4964 return bfd_reloc_overflow;
4967 /* Mask out the value and U bit. */
4968 insn &= 0xff7ff000;
4970 /* Set the U bit if the value to go in the place is non-negative. */
4971 if (signed_value >= 0)
4972 insn |= 1 << 23;
4974 /* Encode the offset. */
4975 insn |= residual;
4977 bfd_put_32 (input_bfd, insn, hit_data);
4979 return bfd_reloc_ok;
4981 case R_ARM_LDRS_PC_G0:
4982 case R_ARM_LDRS_PC_G1:
4983 case R_ARM_LDRS_PC_G2:
4984 case R_ARM_LDRS_SB_G0:
4985 case R_ARM_LDRS_SB_G1:
4986 case R_ARM_LDRS_SB_G2:
4988 bfd_vma insn = bfd_get_32 (input_bfd, hit_data);
4989 bfd_vma pc = input_section->output_section->vma
4990 + input_section->output_offset + rel->r_offset;
4991 bfd_vma sb = 0; /* See note above. */
4992 bfd_vma residual;
4993 bfd_signed_vma signed_value;
4994 int group = 0;
4996 /* Determine which groups of bits to calculate. */
4997 switch (r_type)
4999 case R_ARM_LDRS_PC_G0:
5000 case R_ARM_LDRS_SB_G0:
5001 group = 0;
5002 break;
5004 case R_ARM_LDRS_PC_G1:
5005 case R_ARM_LDRS_SB_G1:
5006 group = 1;
5007 break;
5009 case R_ARM_LDRS_PC_G2:
5010 case R_ARM_LDRS_SB_G2:
5011 group = 2;
5012 break;
5014 default:
5015 abort();
5018 /* If REL, extract the addend from the insn. If RELA, it will
5019 have already been fetched for us. */
5020 if (globals->use_rel)
5022 int negative = (insn & (1 << 23)) ? 1 : -1;
5023 signed_addend = negative * (((insn & 0xf00) >> 4) + (insn & 0xf));
5026 /* Compute the value (X) to go in the place. */
5027 if (r_type == R_ARM_LDRS_PC_G0
5028 || r_type == R_ARM_LDRS_PC_G1
5029 || r_type == R_ARM_LDRS_PC_G2)
5030 /* PC relative. */
5031 signed_value = value - pc + signed_addend;
5032 else
5033 /* Section base relative. */
5034 signed_value = value - sb + signed_addend;
5036 /* Calculate the value of the relevant G_{n-1} to obtain
5037 the residual at that stage. */
5038 calculate_group_reloc_mask (abs (signed_value), group - 1, &residual);
5040 /* Check for overflow. */
5041 if (residual >= 0x100)
5043 (*_bfd_error_handler)
5044 (_("%B(%A+0x%lx): Overflow whilst splitting 0x%lx for group relocation %s"),
5045 input_bfd, input_section,
5046 (long) rel->r_offset, abs (signed_value), howto->name);
5047 return bfd_reloc_overflow;
5050 /* Mask out the value and U bit. */
5051 insn &= 0xff7ff0f0;
5053 /* Set the U bit if the value to go in the place is non-negative. */
5054 if (signed_value >= 0)
5055 insn |= 1 << 23;
5057 /* Encode the offset. */
5058 insn |= ((residual & 0xf0) << 4) | (residual & 0xf);
5060 bfd_put_32 (input_bfd, insn, hit_data);
5062 return bfd_reloc_ok;
5064 case R_ARM_LDC_PC_G0:
5065 case R_ARM_LDC_PC_G1:
5066 case R_ARM_LDC_PC_G2:
5067 case R_ARM_LDC_SB_G0:
5068 case R_ARM_LDC_SB_G1:
5069 case R_ARM_LDC_SB_G2:
5071 bfd_vma insn = bfd_get_32 (input_bfd, hit_data);
5072 bfd_vma pc = input_section->output_section->vma
5073 + input_section->output_offset + rel->r_offset;
5074 bfd_vma sb = 0; /* See note above. */
5075 bfd_vma residual;
5076 bfd_signed_vma signed_value;
5077 int group = 0;
5079 /* Determine which groups of bits to calculate. */
5080 switch (r_type)
5082 case R_ARM_LDC_PC_G0:
5083 case R_ARM_LDC_SB_G0:
5084 group = 0;
5085 break;
5087 case R_ARM_LDC_PC_G1:
5088 case R_ARM_LDC_SB_G1:
5089 group = 1;
5090 break;
5092 case R_ARM_LDC_PC_G2:
5093 case R_ARM_LDC_SB_G2:
5094 group = 2;
5095 break;
5097 default:
5098 abort();
5101 /* If REL, extract the addend from the insn. If RELA, it will
5102 have already been fetched for us. */
5103 if (globals->use_rel)
5105 int negative = (insn & (1 << 23)) ? 1 : -1;
5106 signed_addend = negative * ((insn & 0xff) << 2);
5109 /* Compute the value (X) to go in the place. */
5110 if (r_type == R_ARM_LDC_PC_G0
5111 || r_type == R_ARM_LDC_PC_G1
5112 || r_type == R_ARM_LDC_PC_G2)
5113 /* PC relative. */
5114 signed_value = value - pc + signed_addend;
5115 else
5116 /* Section base relative. */
5117 signed_value = value - sb + signed_addend;
5119 /* Calculate the value of the relevant G_{n-1} to obtain
5120 the residual at that stage. */
5121 calculate_group_reloc_mask (abs (signed_value), group - 1, &residual);
5123 /* Check for overflow. (The absolute value to go in the place must be
5124 divisible by four and, after having been divided by four, must
5125 fit in eight bits.) */
5126 if ((residual & 0x3) != 0 || residual >= 0x400)
5128 (*_bfd_error_handler)
5129 (_("%B(%A+0x%lx): Overflow whilst splitting 0x%lx for group relocation %s"),
5130 input_bfd, input_section,
5131 (long) rel->r_offset, abs (signed_value), howto->name);
5132 return bfd_reloc_overflow;
5135 /* Mask out the value and U bit. */
5136 insn &= 0xff7fff00;
5138 /* Set the U bit if the value to go in the place is non-negative. */
5139 if (signed_value >= 0)
5140 insn |= 1 << 23;
5142 /* Encode the offset. */
5143 insn |= residual >> 2;
5145 bfd_put_32 (input_bfd, insn, hit_data);
5147 return bfd_reloc_ok;
5149 default:
5150 return bfd_reloc_notsupported;
5155 static int
5156 uleb128_size (unsigned int i)
5158 int size;
5159 size = 1;
5160 while (i >= 0x80)
5162 i >>= 7;
5163 size++;
5165 return size;
5168 /* Return TRUE if the attribute has the default value (0/""). */
5169 static bfd_boolean
5170 is_default_attr (aeabi_attribute *attr)
5172 if ((attr->type & 1) && attr->i != 0)
5173 return FALSE;
5174 if ((attr->type & 2) && attr->s && *attr->s)
5175 return FALSE;
5177 return TRUE;
5180 /* Return the size of a single attribute. */
5181 static bfd_vma
5182 eabi_attr_size(int tag, aeabi_attribute *attr)
5184 bfd_vma size;
5186 if (is_default_attr (attr))
5187 return 0;
5189 size = uleb128_size (tag);
5190 if (attr->type & 1)
5191 size += uleb128_size (attr->i);
5192 if (attr->type & 2)
5193 size += strlen ((char *)attr->s) + 1;
5194 return size;
5197 /* Returns the size of the eabi object attributess section. */
5198 bfd_vma
5199 elf32_arm_eabi_attr_size (bfd *abfd)
5201 bfd_vma size;
5202 aeabi_attribute *attr;
5203 aeabi_attribute_list *list;
5204 int i;
5206 attr = elf32_arm_tdata (abfd)->known_eabi_attributes;
5207 size = 16; /* 'A' <size> "aeabi" 0x1 <size>. */
5208 for (i = 4; i < NUM_KNOWN_ATTRIBUTES; i++)
5209 size += eabi_attr_size (i, &attr[i]);
5211 for (list = elf32_arm_tdata (abfd)->other_eabi_attributes;
5212 list;
5213 list = list->next)
5214 size += eabi_attr_size (list->tag, &list->attr);
5216 return size;
5219 static bfd_byte *
5220 write_uleb128 (bfd_byte *p, unsigned int val)
5222 bfd_byte c;
5225 c = val & 0x7f;
5226 val >>= 7;
5227 if (val)
5228 c |= 0x80;
5229 *(p++) = c;
5231 while (val);
5232 return p;
5235 /* Write attribute ATTR to butter P, and return a pointer to the following
5236 byte. */
5237 static bfd_byte *
5238 write_eabi_attribute (bfd_byte *p, int tag, aeabi_attribute *attr)
5240 /* Suppress default entries. */
5241 if (is_default_attr(attr))
5242 return p;
5244 p = write_uleb128 (p, tag);
5245 if (attr->type & 1)
5246 p = write_uleb128 (p, attr->i);
5247 if (attr->type & 2)
5249 int len;
5251 len = strlen (attr->s) + 1;
5252 memcpy (p, attr->s, len);
5253 p += len;
5256 return p;
5259 /* Write the contents of the eabi attributes section to p. */
5260 void
5261 elf32_arm_set_eabi_attr_contents (bfd *abfd, bfd_byte *contents, bfd_vma size)
5263 bfd_byte *p;
5264 aeabi_attribute *attr;
5265 aeabi_attribute_list *list;
5266 int i;
5268 p = contents;
5269 *(p++) = 'A';
5270 bfd_put_32 (abfd, size - 1, p);
5271 p += 4;
5272 memcpy (p, "aeabi", 6);
5273 p += 6;
5274 *(p++) = Tag_File;
5275 bfd_put_32 (abfd, size - 11, p);
5276 p += 4;
5278 attr = elf32_arm_tdata (abfd)->known_eabi_attributes;
5279 for (i = 4; i < NUM_KNOWN_ATTRIBUTES; i++)
5280 p = write_eabi_attribute (p, i, &attr[i]);
5282 for (list = elf32_arm_tdata (abfd)->other_eabi_attributes;
5283 list;
5284 list = list->next)
5285 p = write_eabi_attribute (p, list->tag, &list->attr);
5288 /* Override final_link to handle EABI object attribute sections. */
5290 static bfd_boolean
5291 elf32_arm_bfd_final_link (bfd *abfd, struct bfd_link_info *info)
5293 asection *o;
5294 struct bfd_link_order *p;
5295 asection *attr_section = NULL;
5296 bfd_byte *contents;
5297 bfd_vma size = 0;
5299 /* elf32_arm_merge_private_bfd_data will already have merged the
5300 object attributes. Remove the input sections from the link, and set
5301 the contents of the output secton. */
5302 for (o = abfd->sections; o != NULL; o = o->next)
5304 if (strcmp (o->name, ".ARM.attributes") == 0)
5306 for (p = o->map_head.link_order; p != NULL; p = p->next)
5308 asection *input_section;
5310 if (p->type != bfd_indirect_link_order)
5311 continue;
5312 input_section = p->u.indirect.section;
5313 /* Hack: reset the SEC_HAS_CONTENTS flag so that
5314 elf_link_input_bfd ignores this section. */
5315 input_section->flags &= ~SEC_HAS_CONTENTS;
5318 size = elf32_arm_eabi_attr_size (abfd);
5319 bfd_set_section_size (abfd, o, size);
5320 attr_section = o;
5321 /* Skip this section later on. */
5322 o->map_head.link_order = NULL;
5325 /* Invoke the ELF linker to do all the work. */
5326 if (!bfd_elf_final_link (abfd, info))
5327 return FALSE;
5329 if (attr_section)
5331 contents = bfd_malloc(size);
5332 if (contents == NULL)
5333 return FALSE;
5334 elf32_arm_set_eabi_attr_contents (abfd, contents, size);
5335 bfd_set_section_contents (abfd, attr_section, contents, 0, size);
5336 free (contents);
5338 return TRUE;
5342 /* Add INCREMENT to the reloc (of type HOWTO) at ADDRESS. */
5343 static void
5344 arm_add_to_rel (bfd * abfd,
5345 bfd_byte * address,
5346 reloc_howto_type * howto,
5347 bfd_signed_vma increment)
5349 bfd_signed_vma addend;
5351 if (howto->type == R_ARM_THM_CALL)
5353 int upper_insn, lower_insn;
5354 int upper, lower;
5356 upper_insn = bfd_get_16 (abfd, address);
5357 lower_insn = bfd_get_16 (abfd, address + 2);
5358 upper = upper_insn & 0x7ff;
5359 lower = lower_insn & 0x7ff;
5361 addend = (upper << 12) | (lower << 1);
5362 addend += increment;
5363 addend >>= 1;
5365 upper_insn = (upper_insn & 0xf800) | ((addend >> 11) & 0x7ff);
5366 lower_insn = (lower_insn & 0xf800) | (addend & 0x7ff);
5368 bfd_put_16 (abfd, (bfd_vma) upper_insn, address);
5369 bfd_put_16 (abfd, (bfd_vma) lower_insn, address + 2);
5371 else
5373 bfd_vma contents;
5375 contents = bfd_get_32 (abfd, address);
5377 /* Get the (signed) value from the instruction. */
5378 addend = contents & howto->src_mask;
5379 if (addend & ((howto->src_mask + 1) >> 1))
5381 bfd_signed_vma mask;
5383 mask = -1;
5384 mask &= ~ howto->src_mask;
5385 addend |= mask;
5388 /* Add in the increment, (which is a byte value). */
5389 switch (howto->type)
5391 default:
5392 addend += increment;
5393 break;
5395 case R_ARM_PC24:
5396 case R_ARM_PLT32:
5397 case R_ARM_CALL:
5398 case R_ARM_JUMP24:
5399 addend <<= howto->size;
5400 addend += increment;
5402 /* Should we check for overflow here ? */
5404 /* Drop any undesired bits. */
5405 addend >>= howto->rightshift;
5406 break;
5409 contents = (contents & ~ howto->dst_mask) | (addend & howto->dst_mask);
5411 bfd_put_32 (abfd, contents, address);
5415 #define IS_ARM_TLS_RELOC(R_TYPE) \
5416 ((R_TYPE) == R_ARM_TLS_GD32 \
5417 || (R_TYPE) == R_ARM_TLS_LDO32 \
5418 || (R_TYPE) == R_ARM_TLS_LDM32 \
5419 || (R_TYPE) == R_ARM_TLS_DTPOFF32 \
5420 || (R_TYPE) == R_ARM_TLS_DTPMOD32 \
5421 || (R_TYPE) == R_ARM_TLS_TPOFF32 \
5422 || (R_TYPE) == R_ARM_TLS_LE32 \
5423 || (R_TYPE) == R_ARM_TLS_IE32)
5425 /* Relocate an ARM ELF section. */
5426 static bfd_boolean
5427 elf32_arm_relocate_section (bfd * output_bfd,
5428 struct bfd_link_info * info,
5429 bfd * input_bfd,
5430 asection * input_section,
5431 bfd_byte * contents,
5432 Elf_Internal_Rela * relocs,
5433 Elf_Internal_Sym * local_syms,
5434 asection ** local_sections)
5436 Elf_Internal_Shdr *symtab_hdr;
5437 struct elf_link_hash_entry **sym_hashes;
5438 Elf_Internal_Rela *rel;
5439 Elf_Internal_Rela *relend;
5440 const char *name;
5441 struct elf32_arm_link_hash_table * globals;
5443 globals = elf32_arm_hash_table (info);
5444 if (info->relocatable && !globals->use_rel)
5445 return TRUE;
5447 symtab_hdr = & elf_tdata (input_bfd)->symtab_hdr;
5448 sym_hashes = elf_sym_hashes (input_bfd);
5450 rel = relocs;
5451 relend = relocs + input_section->reloc_count;
5452 for (; rel < relend; rel++)
5454 int r_type;
5455 reloc_howto_type * howto;
5456 unsigned long r_symndx;
5457 Elf_Internal_Sym * sym;
5458 asection * sec;
5459 struct elf_link_hash_entry * h;
5460 bfd_vma relocation;
5461 bfd_reloc_status_type r;
5462 arelent bfd_reloc;
5463 char sym_type;
5464 bfd_boolean unresolved_reloc = FALSE;
5466 r_symndx = ELF32_R_SYM (rel->r_info);
5467 r_type = ELF32_R_TYPE (rel->r_info);
5468 r_type = arm_real_reloc_type (globals, r_type);
5470 if ( r_type == R_ARM_GNU_VTENTRY
5471 || r_type == R_ARM_GNU_VTINHERIT)
5472 continue;
5474 bfd_reloc.howto = elf32_arm_howto_from_type (r_type);
5475 howto = bfd_reloc.howto;
5477 if (info->relocatable && globals->use_rel)
5479 /* This is a relocatable link. We don't have to change
5480 anything, unless the reloc is against a section symbol,
5481 in which case we have to adjust according to where the
5482 section symbol winds up in the output section. */
5483 if (r_symndx < symtab_hdr->sh_info)
5485 sym = local_syms + r_symndx;
5486 if (ELF_ST_TYPE (sym->st_info) == STT_SECTION)
5488 sec = local_sections[r_symndx];
5489 arm_add_to_rel (input_bfd, contents + rel->r_offset,
5490 howto,
5491 (bfd_signed_vma) (sec->output_offset
5492 + sym->st_value));
5496 continue;
5499 /* This is a final link. */
5500 h = NULL;
5501 sym = NULL;
5502 sec = NULL;
5504 if (r_symndx < symtab_hdr->sh_info)
5506 sym = local_syms + r_symndx;
5507 sym_type = ELF32_ST_TYPE (sym->st_info);
5508 sec = local_sections[r_symndx];
5509 if (globals->use_rel)
5511 relocation = (sec->output_section->vma
5512 + sec->output_offset
5513 + sym->st_value);
5514 if ((sec->flags & SEC_MERGE)
5515 && ELF_ST_TYPE (sym->st_info) == STT_SECTION)
5517 asection *msec;
5518 bfd_vma addend, value;
5520 if (howto->rightshift)
5522 (*_bfd_error_handler)
5523 (_("%B(%A+0x%lx): %s relocation against SEC_MERGE section"),
5524 input_bfd, input_section,
5525 (long) rel->r_offset, howto->name);
5526 return FALSE;
5529 value = bfd_get_32 (input_bfd, contents + rel->r_offset);
5531 /* Get the (signed) value from the instruction. */
5532 addend = value & howto->src_mask;
5533 if (addend & ((howto->src_mask + 1) >> 1))
5535 bfd_signed_vma mask;
5537 mask = -1;
5538 mask &= ~ howto->src_mask;
5539 addend |= mask;
5541 msec = sec;
5542 addend =
5543 _bfd_elf_rel_local_sym (output_bfd, sym, &msec, addend)
5544 - relocation;
5545 addend += msec->output_section->vma + msec->output_offset;
5546 value = (value & ~ howto->dst_mask) | (addend & howto->dst_mask);
5547 bfd_put_32 (input_bfd, value, contents + rel->r_offset);
5550 else
5551 relocation = _bfd_elf_rela_local_sym (output_bfd, sym, &sec, rel);
5553 else
5555 bfd_boolean warned;
5557 RELOC_FOR_GLOBAL_SYMBOL (info, input_bfd, input_section, rel,
5558 r_symndx, symtab_hdr, sym_hashes,
5559 h, sec, relocation,
5560 unresolved_reloc, warned);
5562 sym_type = h->type;
5565 if (h != NULL)
5566 name = h->root.root.string;
5567 else
5569 name = (bfd_elf_string_from_elf_section
5570 (input_bfd, symtab_hdr->sh_link, sym->st_name));
5571 if (name == NULL || *name == '\0')
5572 name = bfd_section_name (input_bfd, sec);
5575 if (r_symndx != 0
5576 && r_type != R_ARM_NONE
5577 && (h == NULL
5578 || h->root.type == bfd_link_hash_defined
5579 || h->root.type == bfd_link_hash_defweak)
5580 && IS_ARM_TLS_RELOC (r_type) != (sym_type == STT_TLS))
5582 (*_bfd_error_handler)
5583 ((sym_type == STT_TLS
5584 ? _("%B(%A+0x%lx): %s used with TLS symbol %s")
5585 : _("%B(%A+0x%lx): %s used with non-TLS symbol %s")),
5586 input_bfd,
5587 input_section,
5588 (long) rel->r_offset,
5589 howto->name,
5590 name);
5593 r = elf32_arm_final_link_relocate (howto, input_bfd, output_bfd,
5594 input_section, contents, rel,
5595 relocation, info, sec, name,
5596 (h ? ELF_ST_TYPE (h->type) :
5597 ELF_ST_TYPE (sym->st_info)), h,
5598 &unresolved_reloc);
5600 /* Dynamic relocs are not propagated for SEC_DEBUGGING sections
5601 because such sections are not SEC_ALLOC and thus ld.so will
5602 not process them. */
5603 if (unresolved_reloc
5604 && !((input_section->flags & SEC_DEBUGGING) != 0
5605 && h->def_dynamic))
5607 (*_bfd_error_handler)
5608 (_("%B(%A+0x%lx): unresolvable %s relocation against symbol `%s'"),
5609 input_bfd,
5610 input_section,
5611 (long) rel->r_offset,
5612 howto->name,
5613 h->root.root.string);
5614 return FALSE;
5617 if (r != bfd_reloc_ok)
5619 const char * msg = (const char *) 0;
5621 switch (r)
5623 case bfd_reloc_overflow:
5624 /* If the overflowing reloc was to an undefined symbol,
5625 we have already printed one error message and there
5626 is no point complaining again. */
5627 if ((! h ||
5628 h->root.type != bfd_link_hash_undefined)
5629 && (!((*info->callbacks->reloc_overflow)
5630 (info, (h ? &h->root : NULL), name, howto->name,
5631 (bfd_vma) 0, input_bfd, input_section,
5632 rel->r_offset))))
5633 return FALSE;
5634 break;
5636 case bfd_reloc_undefined:
5637 if (!((*info->callbacks->undefined_symbol)
5638 (info, name, input_bfd, input_section,
5639 rel->r_offset, TRUE)))
5640 return FALSE;
5641 break;
5643 case bfd_reloc_outofrange:
5644 msg = _("internal error: out of range error");
5645 goto common_error;
5647 case bfd_reloc_notsupported:
5648 msg = _("internal error: unsupported relocation error");
5649 goto common_error;
5651 case bfd_reloc_dangerous:
5652 msg = _("internal error: dangerous error");
5653 goto common_error;
5655 default:
5656 msg = _("internal error: unknown error");
5657 /* fall through */
5659 common_error:
5660 if (!((*info->callbacks->warning)
5661 (info, msg, name, input_bfd, input_section,
5662 rel->r_offset)))
5663 return FALSE;
5664 break;
5669 return TRUE;
5672 /* Allocate/find an object attribute. */
5673 static aeabi_attribute *
5674 elf32_arm_new_eabi_attr (bfd *abfd, int tag)
5676 aeabi_attribute *attr;
5677 aeabi_attribute_list *list;
5678 aeabi_attribute_list *p;
5679 aeabi_attribute_list **lastp;
5682 if (tag < NUM_KNOWN_ATTRIBUTES)
5684 /* Knwon tags are preallocated. */
5685 attr = &elf32_arm_tdata (abfd)->known_eabi_attributes[tag];
5687 else
5689 /* Create a new tag. */
5690 list = (aeabi_attribute_list *)
5691 bfd_alloc (abfd, sizeof (aeabi_attribute_list));
5692 memset (list, 0, sizeof (aeabi_attribute_list));
5693 list->tag = tag;
5694 /* Keep the tag list in order. */
5695 lastp = &elf32_arm_tdata (abfd)->other_eabi_attributes;
5696 for (p = *lastp; p; p = p->next)
5698 if (tag < p->tag)
5699 break;
5700 lastp = &p->next;
5702 list->next = *lastp;
5703 *lastp = list;
5704 attr = &list->attr;
5707 return attr;
5711 elf32_arm_get_eabi_attr_int (bfd *abfd, int tag)
5713 aeabi_attribute_list *p;
5715 if (tag < NUM_KNOWN_ATTRIBUTES)
5717 /* Knwon tags are preallocated. */
5718 return elf32_arm_tdata (abfd)->known_eabi_attributes[tag].i;
5720 else
5722 for (p = elf32_arm_tdata (abfd)->other_eabi_attributes;
5724 p = p->next)
5726 if (tag == p->tag)
5727 return p->attr.i;
5728 if (tag < p->tag)
5729 break;
5731 return 0;
5735 void
5736 elf32_arm_add_eabi_attr_int (bfd *abfd, int tag, unsigned int i)
5738 aeabi_attribute *attr;
5740 attr = elf32_arm_new_eabi_attr (abfd, tag);
5741 attr->type = 1;
5742 attr->i = i;
5745 static char *
5746 attr_strdup (bfd *abfd, const char * s)
5748 char * p;
5749 int len;
5751 len = strlen (s) + 1;
5752 p = (char *)bfd_alloc(abfd, len);
5753 return memcpy (p, s, len);
5756 void
5757 elf32_arm_add_eabi_attr_string (bfd *abfd, int tag, const char *s)
5759 aeabi_attribute *attr;
5761 attr = elf32_arm_new_eabi_attr (abfd, tag);
5762 attr->type = 2;
5763 attr->s = attr_strdup (abfd, s);
5766 void
5767 elf32_arm_add_eabi_attr_compat (bfd *abfd, unsigned int i, const char *s)
5769 aeabi_attribute_list *list;
5770 aeabi_attribute_list *p;
5771 aeabi_attribute_list **lastp;
5773 list = (aeabi_attribute_list *)
5774 bfd_alloc (abfd, sizeof (aeabi_attribute_list));
5775 memset (list, 0, sizeof (aeabi_attribute_list));
5776 list->tag = Tag_compatibility;
5777 list->attr.type = 3;
5778 list->attr.i = i;
5779 list->attr.s = attr_strdup (abfd, s);
5781 lastp = &elf32_arm_tdata (abfd)->other_eabi_attributes;
5782 for (p = *lastp; p; p = p->next)
5784 int cmp;
5785 if (p->tag != Tag_compatibility)
5786 break;
5787 cmp = strcmp(s, p->attr.s);
5788 if (cmp < 0 || (cmp == 0 && i < p->attr.i))
5789 break;
5790 lastp = &p->next;
5792 list->next = *lastp;
5793 *lastp = list;
5796 /* Set the right machine number. */
5798 static bfd_boolean
5799 elf32_arm_object_p (bfd *abfd)
5801 unsigned int mach;
5803 mach = bfd_arm_get_mach_from_notes (abfd, ARM_NOTE_SECTION);
5805 if (mach != bfd_mach_arm_unknown)
5806 bfd_default_set_arch_mach (abfd, bfd_arch_arm, mach);
5808 else if (elf_elfheader (abfd)->e_flags & EF_ARM_MAVERICK_FLOAT)
5809 bfd_default_set_arch_mach (abfd, bfd_arch_arm, bfd_mach_arm_ep9312);
5811 else
5812 bfd_default_set_arch_mach (abfd, bfd_arch_arm, mach);
5814 return TRUE;
5817 /* Function to keep ARM specific flags in the ELF header. */
5819 static bfd_boolean
5820 elf32_arm_set_private_flags (bfd *abfd, flagword flags)
5822 if (elf_flags_init (abfd)
5823 && elf_elfheader (abfd)->e_flags != flags)
5825 if (EF_ARM_EABI_VERSION (flags) == EF_ARM_EABI_UNKNOWN)
5827 if (flags & EF_ARM_INTERWORK)
5828 (*_bfd_error_handler)
5829 (_("Warning: Not setting interworking flag of %B since it has already been specified as non-interworking"),
5830 abfd);
5831 else
5832 _bfd_error_handler
5833 (_("Warning: Clearing the interworking flag of %B due to outside request"),
5834 abfd);
5837 else
5839 elf_elfheader (abfd)->e_flags = flags;
5840 elf_flags_init (abfd) = TRUE;
5843 return TRUE;
5846 /* Copy the eabi object attribute from IBFD to OBFD. */
5847 static void
5848 copy_eabi_attributes (bfd *ibfd, bfd *obfd)
5850 aeabi_attribute *in_attr;
5851 aeabi_attribute *out_attr;
5852 aeabi_attribute_list *list;
5853 int i;
5855 in_attr = elf32_arm_tdata (ibfd)->known_eabi_attributes;
5856 out_attr = elf32_arm_tdata (obfd)->known_eabi_attributes;
5857 for (i = 4; i < NUM_KNOWN_ATTRIBUTES; i++)
5859 out_attr->i = in_attr->i;
5860 if (in_attr->s && *in_attr->s)
5861 out_attr->s = attr_strdup (obfd, in_attr->s);
5862 in_attr++;
5863 out_attr++;
5866 for (list = elf32_arm_tdata (ibfd)->other_eabi_attributes;
5867 list;
5868 list = list->next)
5870 in_attr = &list->attr;
5871 switch (in_attr->type)
5873 case 1:
5874 elf32_arm_add_eabi_attr_int (obfd, list->tag, in_attr->i);
5875 break;
5876 case 2:
5877 elf32_arm_add_eabi_attr_string (obfd, list->tag, in_attr->s);
5878 break;
5879 case 3:
5880 elf32_arm_add_eabi_attr_compat (obfd, in_attr->i, in_attr->s);
5881 break;
5882 default:
5883 abort();
5889 /* Copy backend specific data from one object module to another. */
5891 static bfd_boolean
5892 elf32_arm_copy_private_bfd_data (bfd *ibfd, bfd *obfd)
5894 flagword in_flags;
5895 flagword out_flags;
5897 if ( bfd_get_flavour (ibfd) != bfd_target_elf_flavour
5898 || bfd_get_flavour (obfd) != bfd_target_elf_flavour)
5899 return TRUE;
5901 in_flags = elf_elfheader (ibfd)->e_flags;
5902 out_flags = elf_elfheader (obfd)->e_flags;
5904 if (elf_flags_init (obfd)
5905 && EF_ARM_EABI_VERSION (out_flags) == EF_ARM_EABI_UNKNOWN
5906 && in_flags != out_flags)
5908 /* Cannot mix APCS26 and APCS32 code. */
5909 if ((in_flags & EF_ARM_APCS_26) != (out_flags & EF_ARM_APCS_26))
5910 return FALSE;
5912 /* Cannot mix float APCS and non-float APCS code. */
5913 if ((in_flags & EF_ARM_APCS_FLOAT) != (out_flags & EF_ARM_APCS_FLOAT))
5914 return FALSE;
5916 /* If the src and dest have different interworking flags
5917 then turn off the interworking bit. */
5918 if ((in_flags & EF_ARM_INTERWORK) != (out_flags & EF_ARM_INTERWORK))
5920 if (out_flags & EF_ARM_INTERWORK)
5921 _bfd_error_handler
5922 (_("Warning: Clearing the interworking flag of %B because non-interworking code in %B has been linked with it"),
5923 obfd, ibfd);
5925 in_flags &= ~EF_ARM_INTERWORK;
5928 /* Likewise for PIC, though don't warn for this case. */
5929 if ((in_flags & EF_ARM_PIC) != (out_flags & EF_ARM_PIC))
5930 in_flags &= ~EF_ARM_PIC;
5933 elf_elfheader (obfd)->e_flags = in_flags;
5934 elf_flags_init (obfd) = TRUE;
5936 /* Also copy the EI_OSABI field. */
5937 elf_elfheader (obfd)->e_ident[EI_OSABI] =
5938 elf_elfheader (ibfd)->e_ident[EI_OSABI];
5940 /* Copy EABI object attributes. */
5941 copy_eabi_attributes (ibfd, obfd);
5943 return TRUE;
5946 /* Values for Tag_ABI_PCS_R9_use. */
5947 enum
5949 AEABI_R9_V6,
5950 AEABI_R9_SB,
5951 AEABI_R9_TLS,
5952 AEABI_R9_unused
5955 /* Values for Tag_ABI_PCS_RW_data. */
5956 enum
5958 AEABI_PCS_RW_data_absolute,
5959 AEABI_PCS_RW_data_PCrel,
5960 AEABI_PCS_RW_data_SBrel,
5961 AEABI_PCS_RW_data_unused
5964 /* Values for Tag_ABI_enum_size. */
5965 enum
5967 AEABI_enum_unused,
5968 AEABI_enum_short,
5969 AEABI_enum_wide,
5970 AEABI_enum_forced_wide
5973 /* Merge EABI object attributes from IBFD into OBFD. Raise an error if there
5974 are conflicting attributes. */
5975 static bfd_boolean
5976 elf32_arm_merge_eabi_attributes (bfd *ibfd, bfd *obfd)
5978 aeabi_attribute *in_attr;
5979 aeabi_attribute *out_attr;
5980 aeabi_attribute_list *in_list;
5981 aeabi_attribute_list *out_list;
5982 /* Some tags have 0 = don't care, 1 = strong requirement,
5983 2 = weak requirement. */
5984 static const int order_312[3] = {3, 1, 2};
5985 int i;
5987 if (!elf32_arm_tdata (ibfd)->known_eabi_attributes[0].i)
5989 /* This is the first object. Copy the attributes. */
5990 copy_eabi_attributes (ibfd, obfd);
5991 return TRUE;
5994 /* Use the Tag_null value to indicate the attributes have been
5995 initialized. */
5996 elf32_arm_tdata (ibfd)->known_eabi_attributes[0].i = 1;
5998 in_attr = elf32_arm_tdata (ibfd)->known_eabi_attributes;
5999 out_attr = elf32_arm_tdata (obfd)->known_eabi_attributes;
6000 /* This needs to happen before Tag_ABI_FP_number_model is merged. */
6001 if (in_attr[Tag_ABI_VFP_args].i != out_attr[Tag_ABI_VFP_args].i)
6003 /* Ignore mismatches if teh object doesn't use floating point. */
6004 if (out_attr[Tag_ABI_FP_number_model].i == 0)
6005 out_attr[Tag_ABI_VFP_args].i = in_attr[Tag_ABI_VFP_args].i;
6006 else if (in_attr[Tag_ABI_FP_number_model].i != 0)
6008 _bfd_error_handler
6009 (_("ERROR: %B uses VFP register arguments, %B does not"),
6010 ibfd, obfd);
6011 return FALSE;
6015 for (i = 4; i < NUM_KNOWN_ATTRIBUTES; i++)
6017 /* Merge this attribute with existing attributes. */
6018 switch (i)
6020 case Tag_CPU_raw_name:
6021 case Tag_CPU_name:
6022 /* Use whichever has the greatest architecture requirements. */
6023 if (in_attr[Tag_CPU_arch].i > out_attr[Tag_CPU_arch].i)
6024 out_attr[i].s = attr_strdup(obfd, in_attr[i].s);
6025 break;
6027 case Tag_ABI_optimization_goals:
6028 case Tag_ABI_FP_optimization_goals:
6029 /* Use the first value seen. */
6030 break;
6032 case Tag_CPU_arch:
6033 case Tag_ARM_ISA_use:
6034 case Tag_THUMB_ISA_use:
6035 case Tag_VFP_arch:
6036 case Tag_WMMX_arch:
6037 case Tag_NEON_arch:
6038 /* ??? Do NEON and WMMX conflict? */
6039 case Tag_ABI_FP_rounding:
6040 case Tag_ABI_FP_denormal:
6041 case Tag_ABI_FP_exceptions:
6042 case Tag_ABI_FP_user_exceptions:
6043 case Tag_ABI_FP_number_model:
6044 case Tag_ABI_align8_preserved:
6045 case Tag_ABI_HardFP_use:
6046 /* Use the largest value specified. */
6047 if (in_attr[i].i > out_attr[i].i)
6048 out_attr[i].i = in_attr[i].i;
6049 break;
6051 case Tag_CPU_arch_profile:
6052 /* Warn if conflicting architecture profiles used. */
6053 if (out_attr[i].i && in_attr[i].i && in_attr[i].i != out_attr[i].i)
6055 _bfd_error_handler
6056 (_("ERROR: %B: Conflicting architecture profiles %c/%c"),
6057 ibfd, in_attr[i].i, out_attr[i].i);
6058 return FALSE;
6060 if (in_attr[i].i)
6061 out_attr[i].i = in_attr[i].i;
6062 break;
6063 case Tag_PCS_config:
6064 if (out_attr[i].i == 0)
6065 out_attr[i].i = in_attr[i].i;
6066 else if (in_attr[i].i != 0 && out_attr[i].i != 0)
6068 /* It's sometimes ok to mix different configs, so this is only
6069 a warning. */
6070 _bfd_error_handler
6071 (_("Warning: %B: Conflicting platform configuration"), ibfd);
6073 break;
6074 case Tag_ABI_PCS_R9_use:
6075 if (out_attr[i].i != AEABI_R9_unused
6076 && in_attr[i].i != AEABI_R9_unused)
6078 _bfd_error_handler
6079 (_("ERROR: %B: Conflicting use of R9"), ibfd);
6080 return FALSE;
6082 if (out_attr[i].i == AEABI_R9_unused)
6083 out_attr[i].i = in_attr[i].i;
6084 break;
6085 case Tag_ABI_PCS_RW_data:
6086 if (in_attr[i].i == AEABI_PCS_RW_data_SBrel
6087 && out_attr[Tag_ABI_PCS_R9_use].i != AEABI_R9_SB
6088 && out_attr[Tag_ABI_PCS_R9_use].i != AEABI_R9_unused)
6090 _bfd_error_handler
6091 (_("ERROR: %B: SB relative addressing conflicts with use of R9"),
6092 ibfd);
6093 return FALSE;
6095 /* Use the smallest value specified. */
6096 if (in_attr[i].i < out_attr[i].i)
6097 out_attr[i].i = in_attr[i].i;
6098 break;
6099 case Tag_ABI_PCS_RO_data:
6100 /* Use the smallest value specified. */
6101 if (in_attr[i].i < out_attr[i].i)
6102 out_attr[i].i = in_attr[i].i;
6103 break;
6104 case Tag_ABI_PCS_GOT_use:
6105 if (in_attr[i].i > 2 || out_attr[i].i > 2
6106 || order_312[in_attr[i].i] < order_312[out_attr[i].i])
6107 out_attr[i].i = in_attr[i].i;
6108 break;
6109 case Tag_ABI_PCS_wchar_t:
6110 if (out_attr[i].i && in_attr[i].i && out_attr[i].i != in_attr[i].i)
6112 _bfd_error_handler
6113 (_("ERROR: %B: Conflicting definitions of wchar_t"), ibfd);
6114 return FALSE;
6116 if (in_attr[i].i)
6117 out_attr[i].i = in_attr[i].i;
6118 break;
6119 case Tag_ABI_align8_needed:
6120 /* ??? Check against Tag_ABI_align8_preserved. */
6121 if (in_attr[i].i > 2 || out_attr[i].i > 2
6122 || order_312[in_attr[i].i] < order_312[out_attr[i].i])
6123 out_attr[i].i = in_attr[i].i;
6124 break;
6125 case Tag_ABI_enum_size:
6126 if (in_attr[i].i != AEABI_enum_unused)
6128 if (out_attr[i].i == AEABI_enum_unused
6129 || out_attr[i].i == AEABI_enum_forced_wide)
6131 /* The existing object is compatible with anything.
6132 Use whatever requirements the new object has. */
6133 out_attr[i].i = in_attr[i].i;
6135 else if (in_attr[i].i != AEABI_enum_forced_wide
6136 && out_attr[i].i != in_attr[i].i)
6138 _bfd_error_handler
6139 (_("ERROR: %B: Conflicting enum sizes"), ibfd);
6142 break;
6143 case Tag_ABI_VFP_args:
6144 /* Aready done. */
6145 break;
6146 case Tag_ABI_WMMX_args:
6147 if (in_attr[i].i != out_attr[i].i)
6149 _bfd_error_handler
6150 (_("ERROR: %B uses iWMMXt register arguments, %B does not"),
6151 ibfd, obfd);
6152 return FALSE;
6154 break;
6155 default: /* All known attributes should be explicitly covered. */
6156 abort ();
6160 in_list = elf32_arm_tdata (ibfd)->other_eabi_attributes;
6161 out_list = elf32_arm_tdata (ibfd)->other_eabi_attributes;
6162 while (in_list && in_list->tag == Tag_compatibility)
6164 in_attr = &in_list->attr;
6165 if (in_attr->i == 0)
6166 continue;
6167 if (in_attr->i == 1)
6169 _bfd_error_handler
6170 (_("ERROR: %B: Must be processed by '%s' toolchain"),
6171 ibfd, in_attr->s);
6172 return FALSE;
6174 if (!out_list || out_list->tag != Tag_compatibility
6175 || strcmp (in_attr->s, out_list->attr.s) != 0)
6177 /* Add this compatibility tag to the output. */
6178 elf32_arm_add_eabi_attr_compat (obfd, in_attr->i, in_attr->s);
6179 continue;
6181 out_attr = &out_list->attr;
6182 /* Check all the input tags with the same identifier. */
6183 for (;;)
6185 if (out_list->tag != Tag_compatibility
6186 || in_attr->i != out_attr->i
6187 || strcmp (in_attr->s, out_attr->s) != 0)
6189 _bfd_error_handler
6190 (_("ERROR: %B: Incompatible object tag '%s':%d"),
6191 ibfd, in_attr->s, in_attr->i);
6192 return FALSE;
6194 in_list = in_list->next;
6195 if (in_list->tag != Tag_compatibility
6196 || strcmp (in_attr->s, in_list->attr.s) != 0)
6197 break;
6198 in_attr = &in_list->attr;
6199 out_list = out_list->next;
6200 if (out_list)
6201 out_attr = &out_list->attr;
6204 /* Check the output doesn't have extra tags with this identifier. */
6205 if (out_list && out_list->tag == Tag_compatibility
6206 && strcmp (in_attr->s, out_list->attr.s) == 0)
6208 _bfd_error_handler
6209 (_("ERROR: %B: Incompatible object tag '%s':%d"),
6210 ibfd, in_attr->s, out_list->attr.i);
6211 return FALSE;
6215 for (; in_list; in_list = in_list->next)
6217 if ((in_list->tag & 128) < 64)
6219 _bfd_error_handler
6220 (_("Warning: %B: Unknown EABI object attribute %d"),
6221 ibfd, in_list->tag);
6222 break;
6225 return TRUE;
6229 /* Return TRUE if the two EABI versions are incompatible. */
6231 static bfd_boolean
6232 elf32_arm_versions_compatible (unsigned iver, unsigned over)
6234 /* v4 and v5 are the same spec before and after it was released,
6235 so allow mixing them. */
6236 if ((iver == EF_ARM_EABI_VER4 && over == EF_ARM_EABI_VER5)
6237 || (iver == EF_ARM_EABI_VER5 && over == EF_ARM_EABI_VER4))
6238 return TRUE;
6240 return (iver == over);
6243 /* Merge backend specific data from an object file to the output
6244 object file when linking. */
6246 static bfd_boolean
6247 elf32_arm_merge_private_bfd_data (bfd * ibfd, bfd * obfd)
6249 flagword out_flags;
6250 flagword in_flags;
6251 bfd_boolean flags_compatible = TRUE;
6252 asection *sec;
6254 /* Check if we have the same endianess. */
6255 if (! _bfd_generic_verify_endian_match (ibfd, obfd))
6256 return FALSE;
6258 if ( bfd_get_flavour (ibfd) != bfd_target_elf_flavour
6259 || bfd_get_flavour (obfd) != bfd_target_elf_flavour)
6260 return TRUE;
6262 if (!elf32_arm_merge_eabi_attributes (ibfd, obfd))
6263 return FALSE;
6265 /* The input BFD must have had its flags initialised. */
6266 /* The following seems bogus to me -- The flags are initialized in
6267 the assembler but I don't think an elf_flags_init field is
6268 written into the object. */
6269 /* BFD_ASSERT (elf_flags_init (ibfd)); */
6271 in_flags = elf_elfheader (ibfd)->e_flags;
6272 out_flags = elf_elfheader (obfd)->e_flags;
6274 if (!elf_flags_init (obfd))
6276 /* If the input is the default architecture and had the default
6277 flags then do not bother setting the flags for the output
6278 architecture, instead allow future merges to do this. If no
6279 future merges ever set these flags then they will retain their
6280 uninitialised values, which surprise surprise, correspond
6281 to the default values. */
6282 if (bfd_get_arch_info (ibfd)->the_default
6283 && elf_elfheader (ibfd)->e_flags == 0)
6284 return TRUE;
6286 elf_flags_init (obfd) = TRUE;
6287 elf_elfheader (obfd)->e_flags = in_flags;
6289 if (bfd_get_arch (obfd) == bfd_get_arch (ibfd)
6290 && bfd_get_arch_info (obfd)->the_default)
6291 return bfd_set_arch_mach (obfd, bfd_get_arch (ibfd), bfd_get_mach (ibfd));
6293 return TRUE;
6296 /* Determine what should happen if the input ARM architecture
6297 does not match the output ARM architecture. */
6298 if (! bfd_arm_merge_machines (ibfd, obfd))
6299 return FALSE;
6301 /* Identical flags must be compatible. */
6302 if (in_flags == out_flags)
6303 return TRUE;
6305 /* Check to see if the input BFD actually contains any sections. If
6306 not, its flags may not have been initialised either, but it
6307 cannot actually cause any incompatiblity. Do not short-circuit
6308 dynamic objects; their section list may be emptied by
6309 elf_link_add_object_symbols.
6311 Also check to see if there are no code sections in the input.
6312 In this case there is no need to check for code specific flags.
6313 XXX - do we need to worry about floating-point format compatability
6314 in data sections ? */
6315 if (!(ibfd->flags & DYNAMIC))
6317 bfd_boolean null_input_bfd = TRUE;
6318 bfd_boolean only_data_sections = TRUE;
6320 for (sec = ibfd->sections; sec != NULL; sec = sec->next)
6322 /* Ignore synthetic glue sections. */
6323 if (strcmp (sec->name, ".glue_7")
6324 && strcmp (sec->name, ".glue_7t"))
6326 if ((bfd_get_section_flags (ibfd, sec)
6327 & (SEC_LOAD | SEC_CODE | SEC_HAS_CONTENTS))
6328 == (SEC_LOAD | SEC_CODE | SEC_HAS_CONTENTS))
6329 only_data_sections = FALSE;
6331 null_input_bfd = FALSE;
6332 break;
6336 if (null_input_bfd || only_data_sections)
6337 return TRUE;
6340 /* Complain about various flag mismatches. */
6341 if (!elf32_arm_versions_compatible (EF_ARM_EABI_VERSION (in_flags),
6342 EF_ARM_EABI_VERSION (out_flags)))
6344 _bfd_error_handler
6345 (_("ERROR: Source object %B has EABI version %d, but target %B has EABI version %d"),
6346 ibfd, obfd,
6347 (in_flags & EF_ARM_EABIMASK) >> 24,
6348 (out_flags & EF_ARM_EABIMASK) >> 24);
6349 return FALSE;
6352 /* Not sure what needs to be checked for EABI versions >= 1. */
6353 /* VxWorks libraries do not use these flags. */
6354 if (get_elf_backend_data (obfd) != &elf32_arm_vxworks_bed
6355 && get_elf_backend_data (ibfd) != &elf32_arm_vxworks_bed
6356 && EF_ARM_EABI_VERSION (in_flags) == EF_ARM_EABI_UNKNOWN)
6358 if ((in_flags & EF_ARM_APCS_26) != (out_flags & EF_ARM_APCS_26))
6360 _bfd_error_handler
6361 (_("ERROR: %B is compiled for APCS-%d, whereas target %B uses APCS-%d"),
6362 ibfd, obfd,
6363 in_flags & EF_ARM_APCS_26 ? 26 : 32,
6364 out_flags & EF_ARM_APCS_26 ? 26 : 32);
6365 flags_compatible = FALSE;
6368 if ((in_flags & EF_ARM_APCS_FLOAT) != (out_flags & EF_ARM_APCS_FLOAT))
6370 if (in_flags & EF_ARM_APCS_FLOAT)
6371 _bfd_error_handler
6372 (_("ERROR: %B passes floats in float registers, whereas %B passes them in integer registers"),
6373 ibfd, obfd);
6374 else
6375 _bfd_error_handler
6376 (_("ERROR: %B passes floats in integer registers, whereas %B passes them in float registers"),
6377 ibfd, obfd);
6379 flags_compatible = FALSE;
6382 if ((in_flags & EF_ARM_VFP_FLOAT) != (out_flags & EF_ARM_VFP_FLOAT))
6384 if (in_flags & EF_ARM_VFP_FLOAT)
6385 _bfd_error_handler
6386 (_("ERROR: %B uses VFP instructions, whereas %B does not"),
6387 ibfd, obfd);
6388 else
6389 _bfd_error_handler
6390 (_("ERROR: %B uses FPA instructions, whereas %B does not"),
6391 ibfd, obfd);
6393 flags_compatible = FALSE;
6396 if ((in_flags & EF_ARM_MAVERICK_FLOAT) != (out_flags & EF_ARM_MAVERICK_FLOAT))
6398 if (in_flags & EF_ARM_MAVERICK_FLOAT)
6399 _bfd_error_handler
6400 (_("ERROR: %B uses Maverick instructions, whereas %B does not"),
6401 ibfd, obfd);
6402 else
6403 _bfd_error_handler
6404 (_("ERROR: %B does not use Maverick instructions, whereas %B does"),
6405 ibfd, obfd);
6407 flags_compatible = FALSE;
6410 #ifdef EF_ARM_SOFT_FLOAT
6411 if ((in_flags & EF_ARM_SOFT_FLOAT) != (out_flags & EF_ARM_SOFT_FLOAT))
6413 /* We can allow interworking between code that is VFP format
6414 layout, and uses either soft float or integer regs for
6415 passing floating point arguments and results. We already
6416 know that the APCS_FLOAT flags match; similarly for VFP
6417 flags. */
6418 if ((in_flags & EF_ARM_APCS_FLOAT) != 0
6419 || (in_flags & EF_ARM_VFP_FLOAT) == 0)
6421 if (in_flags & EF_ARM_SOFT_FLOAT)
6422 _bfd_error_handler
6423 (_("ERROR: %B uses software FP, whereas %B uses hardware FP"),
6424 ibfd, obfd);
6425 else
6426 _bfd_error_handler
6427 (_("ERROR: %B uses hardware FP, whereas %B uses software FP"),
6428 ibfd, obfd);
6430 flags_compatible = FALSE;
6433 #endif
6435 /* Interworking mismatch is only a warning. */
6436 if ((in_flags & EF_ARM_INTERWORK) != (out_flags & EF_ARM_INTERWORK))
6438 if (in_flags & EF_ARM_INTERWORK)
6440 _bfd_error_handler
6441 (_("Warning: %B supports interworking, whereas %B does not"),
6442 ibfd, obfd);
6444 else
6446 _bfd_error_handler
6447 (_("Warning: %B does not support interworking, whereas %B does"),
6448 ibfd, obfd);
6453 return flags_compatible;
6456 /* Display the flags field. */
6458 static bfd_boolean
6459 elf32_arm_print_private_bfd_data (bfd *abfd, void * ptr)
6461 FILE * file = (FILE *) ptr;
6462 unsigned long flags;
6464 BFD_ASSERT (abfd != NULL && ptr != NULL);
6466 /* Print normal ELF private data. */
6467 _bfd_elf_print_private_bfd_data (abfd, ptr);
6469 flags = elf_elfheader (abfd)->e_flags;
6470 /* Ignore init flag - it may not be set, despite the flags field
6471 containing valid data. */
6473 /* xgettext:c-format */
6474 fprintf (file, _("private flags = %lx:"), elf_elfheader (abfd)->e_flags);
6476 switch (EF_ARM_EABI_VERSION (flags))
6478 case EF_ARM_EABI_UNKNOWN:
6479 /* The following flag bits are GNU extensions and not part of the
6480 official ARM ELF extended ABI. Hence they are only decoded if
6481 the EABI version is not set. */
6482 if (flags & EF_ARM_INTERWORK)
6483 fprintf (file, _(" [interworking enabled]"));
6485 if (flags & EF_ARM_APCS_26)
6486 fprintf (file, " [APCS-26]");
6487 else
6488 fprintf (file, " [APCS-32]");
6490 if (flags & EF_ARM_VFP_FLOAT)
6491 fprintf (file, _(" [VFP float format]"));
6492 else if (flags & EF_ARM_MAVERICK_FLOAT)
6493 fprintf (file, _(" [Maverick float format]"));
6494 else
6495 fprintf (file, _(" [FPA float format]"));
6497 if (flags & EF_ARM_APCS_FLOAT)
6498 fprintf (file, _(" [floats passed in float registers]"));
6500 if (flags & EF_ARM_PIC)
6501 fprintf (file, _(" [position independent]"));
6503 if (flags & EF_ARM_NEW_ABI)
6504 fprintf (file, _(" [new ABI]"));
6506 if (flags & EF_ARM_OLD_ABI)
6507 fprintf (file, _(" [old ABI]"));
6509 if (flags & EF_ARM_SOFT_FLOAT)
6510 fprintf (file, _(" [software FP]"));
6512 flags &= ~(EF_ARM_INTERWORK | EF_ARM_APCS_26 | EF_ARM_APCS_FLOAT
6513 | EF_ARM_PIC | EF_ARM_NEW_ABI | EF_ARM_OLD_ABI
6514 | EF_ARM_SOFT_FLOAT | EF_ARM_VFP_FLOAT
6515 | EF_ARM_MAVERICK_FLOAT);
6516 break;
6518 case EF_ARM_EABI_VER1:
6519 fprintf (file, _(" [Version1 EABI]"));
6521 if (flags & EF_ARM_SYMSARESORTED)
6522 fprintf (file, _(" [sorted symbol table]"));
6523 else
6524 fprintf (file, _(" [unsorted symbol table]"));
6526 flags &= ~ EF_ARM_SYMSARESORTED;
6527 break;
6529 case EF_ARM_EABI_VER2:
6530 fprintf (file, _(" [Version2 EABI]"));
6532 if (flags & EF_ARM_SYMSARESORTED)
6533 fprintf (file, _(" [sorted symbol table]"));
6534 else
6535 fprintf (file, _(" [unsorted symbol table]"));
6537 if (flags & EF_ARM_DYNSYMSUSESEGIDX)
6538 fprintf (file, _(" [dynamic symbols use segment index]"));
6540 if (flags & EF_ARM_MAPSYMSFIRST)
6541 fprintf (file, _(" [mapping symbols precede others]"));
6543 flags &= ~(EF_ARM_SYMSARESORTED | EF_ARM_DYNSYMSUSESEGIDX
6544 | EF_ARM_MAPSYMSFIRST);
6545 break;
6547 case EF_ARM_EABI_VER3:
6548 fprintf (file, _(" [Version3 EABI]"));
6549 break;
6551 case EF_ARM_EABI_VER4:
6552 fprintf (file, _(" [Version4 EABI]"));
6553 goto eabi;
6555 case EF_ARM_EABI_VER5:
6556 fprintf (file, _(" [Version5 EABI]"));
6557 eabi:
6558 if (flags & EF_ARM_BE8)
6559 fprintf (file, _(" [BE8]"));
6561 if (flags & EF_ARM_LE8)
6562 fprintf (file, _(" [LE8]"));
6564 flags &= ~(EF_ARM_LE8 | EF_ARM_BE8);
6565 break;
6567 default:
6568 fprintf (file, _(" <EABI version unrecognised>"));
6569 break;
6572 flags &= ~ EF_ARM_EABIMASK;
6574 if (flags & EF_ARM_RELEXEC)
6575 fprintf (file, _(" [relocatable executable]"));
6577 if (flags & EF_ARM_HASENTRY)
6578 fprintf (file, _(" [has entry point]"));
6580 flags &= ~ (EF_ARM_RELEXEC | EF_ARM_HASENTRY);
6582 if (flags)
6583 fprintf (file, _("<Unrecognised flag bits set>"));
6585 fputc ('\n', file);
6587 return TRUE;
6590 static int
6591 elf32_arm_get_symbol_type (Elf_Internal_Sym * elf_sym, int type)
6593 switch (ELF_ST_TYPE (elf_sym->st_info))
6595 case STT_ARM_TFUNC:
6596 return ELF_ST_TYPE (elf_sym->st_info);
6598 case STT_ARM_16BIT:
6599 /* If the symbol is not an object, return the STT_ARM_16BIT flag.
6600 This allows us to distinguish between data used by Thumb instructions
6601 and non-data (which is probably code) inside Thumb regions of an
6602 executable. */
6603 if (type != STT_OBJECT && type != STT_TLS)
6604 return ELF_ST_TYPE (elf_sym->st_info);
6605 break;
6607 default:
6608 break;
6611 return type;
6614 static asection *
6615 elf32_arm_gc_mark_hook (asection * sec,
6616 struct bfd_link_info * info ATTRIBUTE_UNUSED,
6617 Elf_Internal_Rela * rel,
6618 struct elf_link_hash_entry * h,
6619 Elf_Internal_Sym * sym)
6621 if (h != NULL)
6623 switch (ELF32_R_TYPE (rel->r_info))
6625 case R_ARM_GNU_VTINHERIT:
6626 case R_ARM_GNU_VTENTRY:
6627 break;
6629 default:
6630 switch (h->root.type)
6632 case bfd_link_hash_defined:
6633 case bfd_link_hash_defweak:
6634 return h->root.u.def.section;
6636 case bfd_link_hash_common:
6637 return h->root.u.c.p->section;
6639 default:
6640 break;
6644 else
6645 return bfd_section_from_elf_index (sec->owner, sym->st_shndx);
6647 return NULL;
6650 /* Update the got entry reference counts for the section being removed. */
6652 static bfd_boolean
6653 elf32_arm_gc_sweep_hook (bfd * abfd,
6654 struct bfd_link_info * info,
6655 asection * sec,
6656 const Elf_Internal_Rela * relocs)
6658 Elf_Internal_Shdr *symtab_hdr;
6659 struct elf_link_hash_entry **sym_hashes;
6660 bfd_signed_vma *local_got_refcounts;
6661 const Elf_Internal_Rela *rel, *relend;
6662 struct elf32_arm_link_hash_table * globals;
6664 globals = elf32_arm_hash_table (info);
6666 elf_section_data (sec)->local_dynrel = NULL;
6668 symtab_hdr = &elf_tdata (abfd)->symtab_hdr;
6669 sym_hashes = elf_sym_hashes (abfd);
6670 local_got_refcounts = elf_local_got_refcounts (abfd);
6672 relend = relocs + sec->reloc_count;
6673 for (rel = relocs; rel < relend; rel++)
6675 unsigned long r_symndx;
6676 struct elf_link_hash_entry *h = NULL;
6677 int r_type;
6679 r_symndx = ELF32_R_SYM (rel->r_info);
6680 if (r_symndx >= symtab_hdr->sh_info)
6682 h = sym_hashes[r_symndx - symtab_hdr->sh_info];
6683 while (h->root.type == bfd_link_hash_indirect
6684 || h->root.type == bfd_link_hash_warning)
6685 h = (struct elf_link_hash_entry *) h->root.u.i.link;
6688 r_type = ELF32_R_TYPE (rel->r_info);
6689 r_type = arm_real_reloc_type (globals, r_type);
6690 switch (r_type)
6692 case R_ARM_GOT32:
6693 case R_ARM_GOT_PREL:
6694 case R_ARM_TLS_GD32:
6695 case R_ARM_TLS_IE32:
6696 if (h != NULL)
6698 if (h->got.refcount > 0)
6699 h->got.refcount -= 1;
6701 else if (local_got_refcounts != NULL)
6703 if (local_got_refcounts[r_symndx] > 0)
6704 local_got_refcounts[r_symndx] -= 1;
6706 break;
6708 case R_ARM_TLS_LDM32:
6709 elf32_arm_hash_table (info)->tls_ldm_got.refcount -= 1;
6710 break;
6712 case R_ARM_ABS32:
6713 case R_ARM_REL32:
6714 case R_ARM_PC24:
6715 case R_ARM_PLT32:
6716 case R_ARM_CALL:
6717 case R_ARM_JUMP24:
6718 case R_ARM_PREL31:
6719 case R_ARM_THM_CALL:
6720 case R_ARM_MOVW_ABS_NC:
6721 case R_ARM_MOVT_ABS:
6722 case R_ARM_MOVW_PREL_NC:
6723 case R_ARM_MOVT_PREL:
6724 case R_ARM_THM_MOVW_ABS_NC:
6725 case R_ARM_THM_MOVT_ABS:
6726 case R_ARM_THM_MOVW_PREL_NC:
6727 case R_ARM_THM_MOVT_PREL:
6728 /* Should the interworking branches be here also? */
6730 if (h != NULL)
6732 struct elf32_arm_link_hash_entry *eh;
6733 struct elf32_arm_relocs_copied **pp;
6734 struct elf32_arm_relocs_copied *p;
6736 eh = (struct elf32_arm_link_hash_entry *) h;
6738 if (h->plt.refcount > 0)
6740 h->plt.refcount -= 1;
6741 if (ELF32_R_TYPE (rel->r_info) == R_ARM_THM_CALL)
6742 eh->plt_thumb_refcount--;
6745 if (r_type == R_ARM_ABS32
6746 || r_type == R_ARM_REL32)
6748 for (pp = &eh->relocs_copied; (p = *pp) != NULL;
6749 pp = &p->next)
6750 if (p->section == sec)
6752 p->count -= 1;
6753 if (ELF32_R_TYPE (rel->r_info) == R_ARM_REL32)
6754 p->pc_count -= 1;
6755 if (p->count == 0)
6756 *pp = p->next;
6757 break;
6761 break;
6763 default:
6764 break;
6768 return TRUE;
6771 /* Look through the relocs for a section during the first phase. */
6773 static bfd_boolean
6774 elf32_arm_check_relocs (bfd *abfd, struct bfd_link_info *info,
6775 asection *sec, const Elf_Internal_Rela *relocs)
6777 Elf_Internal_Shdr *symtab_hdr;
6778 struct elf_link_hash_entry **sym_hashes;
6779 struct elf_link_hash_entry **sym_hashes_end;
6780 const Elf_Internal_Rela *rel;
6781 const Elf_Internal_Rela *rel_end;
6782 bfd *dynobj;
6783 asection *sreloc;
6784 bfd_vma *local_got_offsets;
6785 struct elf32_arm_link_hash_table *htab;
6787 if (info->relocatable)
6788 return TRUE;
6790 htab = elf32_arm_hash_table (info);
6791 sreloc = NULL;
6793 /* Create dynamic sections for relocatable executables so that we can
6794 copy relocations. */
6795 if (htab->root.is_relocatable_executable
6796 && ! htab->root.dynamic_sections_created)
6798 if (! _bfd_elf_link_create_dynamic_sections (abfd, info))
6799 return FALSE;
6802 dynobj = elf_hash_table (info)->dynobj;
6803 local_got_offsets = elf_local_got_offsets (abfd);
6805 symtab_hdr = &elf_tdata (abfd)->symtab_hdr;
6806 sym_hashes = elf_sym_hashes (abfd);
6807 sym_hashes_end = sym_hashes
6808 + symtab_hdr->sh_size / sizeof (Elf32_External_Sym);
6810 if (!elf_bad_symtab (abfd))
6811 sym_hashes_end -= symtab_hdr->sh_info;
6813 rel_end = relocs + sec->reloc_count;
6814 for (rel = relocs; rel < rel_end; rel++)
6816 struct elf_link_hash_entry *h;
6817 struct elf32_arm_link_hash_entry *eh;
6818 unsigned long r_symndx;
6819 int r_type;
6821 r_symndx = ELF32_R_SYM (rel->r_info);
6822 r_type = ELF32_R_TYPE (rel->r_info);
6823 r_type = arm_real_reloc_type (htab, r_type);
6825 if (r_symndx >= NUM_SHDR_ENTRIES (symtab_hdr))
6827 (*_bfd_error_handler) (_("%B: bad symbol index: %d"), abfd,
6828 r_symndx);
6829 return FALSE;
6832 if (r_symndx < symtab_hdr->sh_info)
6833 h = NULL;
6834 else
6836 h = sym_hashes[r_symndx - symtab_hdr->sh_info];
6837 while (h->root.type == bfd_link_hash_indirect
6838 || h->root.type == bfd_link_hash_warning)
6839 h = (struct elf_link_hash_entry *) h->root.u.i.link;
6842 eh = (struct elf32_arm_link_hash_entry *) h;
6844 switch (r_type)
6846 case R_ARM_GOT32:
6847 case R_ARM_GOT_PREL:
6848 case R_ARM_TLS_GD32:
6849 case R_ARM_TLS_IE32:
6850 /* This symbol requires a global offset table entry. */
6852 int tls_type, old_tls_type;
6854 switch (r_type)
6856 case R_ARM_TLS_GD32: tls_type = GOT_TLS_GD; break;
6857 case R_ARM_TLS_IE32: tls_type = GOT_TLS_IE; break;
6858 default: tls_type = GOT_NORMAL; break;
6861 if (h != NULL)
6863 h->got.refcount++;
6864 old_tls_type = elf32_arm_hash_entry (h)->tls_type;
6866 else
6868 bfd_signed_vma *local_got_refcounts;
6870 /* This is a global offset table entry for a local symbol. */
6871 local_got_refcounts = elf_local_got_refcounts (abfd);
6872 if (local_got_refcounts == NULL)
6874 bfd_size_type size;
6876 size = symtab_hdr->sh_info;
6877 size *= (sizeof (bfd_signed_vma) + sizeof(char));
6878 local_got_refcounts = bfd_zalloc (abfd, size);
6879 if (local_got_refcounts == NULL)
6880 return FALSE;
6881 elf_local_got_refcounts (abfd) = local_got_refcounts;
6882 elf32_arm_local_got_tls_type (abfd)
6883 = (char *) (local_got_refcounts + symtab_hdr->sh_info);
6885 local_got_refcounts[r_symndx] += 1;
6886 old_tls_type = elf32_arm_local_got_tls_type (abfd) [r_symndx];
6889 /* We will already have issued an error message if there is a
6890 TLS / non-TLS mismatch, based on the symbol type. We don't
6891 support any linker relaxations. So just combine any TLS
6892 types needed. */
6893 if (old_tls_type != GOT_UNKNOWN && old_tls_type != GOT_NORMAL
6894 && tls_type != GOT_NORMAL)
6895 tls_type |= old_tls_type;
6897 if (old_tls_type != tls_type)
6899 if (h != NULL)
6900 elf32_arm_hash_entry (h)->tls_type = tls_type;
6901 else
6902 elf32_arm_local_got_tls_type (abfd) [r_symndx] = tls_type;
6905 /* Fall through */
6907 case R_ARM_TLS_LDM32:
6908 if (r_type == R_ARM_TLS_LDM32)
6909 htab->tls_ldm_got.refcount++;
6910 /* Fall through */
6912 case R_ARM_GOTOFF32:
6913 case R_ARM_GOTPC:
6914 if (htab->sgot == NULL)
6916 if (htab->root.dynobj == NULL)
6917 htab->root.dynobj = abfd;
6918 if (!create_got_section (htab->root.dynobj, info))
6919 return FALSE;
6921 break;
6923 case R_ARM_ABS12:
6924 /* VxWorks uses dynamic R_ARM_ABS12 relocations for
6925 ldr __GOTT_INDEX__ offsets. */
6926 if (!htab->vxworks_p)
6927 break;
6928 /* Fall through */
6930 case R_ARM_ABS32:
6931 case R_ARM_REL32:
6932 case R_ARM_PC24:
6933 case R_ARM_PLT32:
6934 case R_ARM_CALL:
6935 case R_ARM_JUMP24:
6936 case R_ARM_PREL31:
6937 case R_ARM_THM_CALL:
6938 case R_ARM_MOVW_ABS_NC:
6939 case R_ARM_MOVT_ABS:
6940 case R_ARM_MOVW_PREL_NC:
6941 case R_ARM_MOVT_PREL:
6942 case R_ARM_THM_MOVW_ABS_NC:
6943 case R_ARM_THM_MOVT_ABS:
6944 case R_ARM_THM_MOVW_PREL_NC:
6945 case R_ARM_THM_MOVT_PREL:
6946 /* Should the interworking branches be listed here? */
6947 if (h != NULL)
6949 /* If this reloc is in a read-only section, we might
6950 need a copy reloc. We can't check reliably at this
6951 stage whether the section is read-only, as input
6952 sections have not yet been mapped to output sections.
6953 Tentatively set the flag for now, and correct in
6954 adjust_dynamic_symbol. */
6955 if (!info->shared)
6956 h->non_got_ref = 1;
6958 /* We may need a .plt entry if the function this reloc
6959 refers to is in a different object. We can't tell for
6960 sure yet, because something later might force the
6961 symbol local. */
6962 if (r_type != R_ARM_ABS32 && r_type != R_ARM_REL32)
6963 h->needs_plt = 1;
6965 /* If we create a PLT entry, this relocation will reference
6966 it, even if it's an ABS32 relocation. */
6967 h->plt.refcount += 1;
6969 if (r_type == R_ARM_THM_CALL)
6970 eh->plt_thumb_refcount += 1;
6973 /* If we are creating a shared library or relocatable executable,
6974 and this is a reloc against a global symbol, or a non PC
6975 relative reloc against a local symbol, then we need to copy
6976 the reloc into the shared library. However, if we are linking
6977 with -Bsymbolic, we do not need to copy a reloc against a
6978 global symbol which is defined in an object we are
6979 including in the link (i.e., DEF_REGULAR is set). At
6980 this point we have not seen all the input files, so it is
6981 possible that DEF_REGULAR is not set now but will be set
6982 later (it is never cleared). We account for that
6983 possibility below by storing information in the
6984 relocs_copied field of the hash table entry. */
6985 if ((info->shared || htab->root.is_relocatable_executable)
6986 && (sec->flags & SEC_ALLOC) != 0
6987 && (r_type == R_ARM_ABS32
6988 || (h != NULL && ! h->needs_plt
6989 && (! info->symbolic || ! h->def_regular))))
6991 struct elf32_arm_relocs_copied *p, **head;
6993 /* When creating a shared object, we must copy these
6994 reloc types into the output file. We create a reloc
6995 section in dynobj and make room for this reloc. */
6996 if (sreloc == NULL)
6998 const char * name;
7000 name = (bfd_elf_string_from_elf_section
7001 (abfd,
7002 elf_elfheader (abfd)->e_shstrndx,
7003 elf_section_data (sec)->rel_hdr.sh_name));
7004 if (name == NULL)
7005 return FALSE;
7007 BFD_ASSERT (reloc_section_p (htab, name, sec));
7009 sreloc = bfd_get_section_by_name (dynobj, name);
7010 if (sreloc == NULL)
7012 flagword flags;
7014 flags = (SEC_HAS_CONTENTS | SEC_READONLY
7015 | SEC_IN_MEMORY | SEC_LINKER_CREATED);
7016 if ((sec->flags & SEC_ALLOC) != 0
7017 /* BPABI objects never have dynamic
7018 relocations mapped. */
7019 && !htab->symbian_p)
7020 flags |= SEC_ALLOC | SEC_LOAD;
7021 sreloc = bfd_make_section_with_flags (dynobj,
7022 name,
7023 flags);
7024 if (sreloc == NULL
7025 || ! bfd_set_section_alignment (dynobj, sreloc, 2))
7026 return FALSE;
7029 elf_section_data (sec)->sreloc = sreloc;
7032 /* If this is a global symbol, we count the number of
7033 relocations we need for this symbol. */
7034 if (h != NULL)
7036 head = &((struct elf32_arm_link_hash_entry *) h)->relocs_copied;
7038 else
7040 /* Track dynamic relocs needed for local syms too.
7041 We really need local syms available to do this
7042 easily. Oh well. */
7044 asection *s;
7045 void *vpp;
7047 s = bfd_section_from_r_symndx (abfd, &htab->sym_sec,
7048 sec, r_symndx);
7049 if (s == NULL)
7050 return FALSE;
7052 vpp = &elf_section_data (s)->local_dynrel;
7053 head = (struct elf32_arm_relocs_copied **) vpp;
7056 p = *head;
7057 if (p == NULL || p->section != sec)
7059 bfd_size_type amt = sizeof *p;
7061 p = bfd_alloc (htab->root.dynobj, amt);
7062 if (p == NULL)
7063 return FALSE;
7064 p->next = *head;
7065 *head = p;
7066 p->section = sec;
7067 p->count = 0;
7068 p->pc_count = 0;
7071 if (r_type == R_ARM_REL32)
7072 p->pc_count += 1;
7073 p->count += 1;
7075 break;
7077 /* This relocation describes the C++ object vtable hierarchy.
7078 Reconstruct it for later use during GC. */
7079 case R_ARM_GNU_VTINHERIT:
7080 if (!bfd_elf_gc_record_vtinherit (abfd, sec, h, rel->r_offset))
7081 return FALSE;
7082 break;
7084 /* This relocation describes which C++ vtable entries are actually
7085 used. Record for later use during GC. */
7086 case R_ARM_GNU_VTENTRY:
7087 if (!bfd_elf_gc_record_vtentry (abfd, sec, h, rel->r_offset))
7088 return FALSE;
7089 break;
7093 return TRUE;
7096 /* Treat mapping symbols as special target symbols. */
7098 static bfd_boolean
7099 elf32_arm_is_target_special_symbol (bfd * abfd ATTRIBUTE_UNUSED, asymbol * sym)
7101 return bfd_is_arm_special_symbol_name (sym->name,
7102 BFD_ARM_SPECIAL_SYM_TYPE_ANY);
7105 /* This is a copy of elf_find_function() from elf.c except that
7106 ARM mapping symbols are ignored when looking for function names
7107 and STT_ARM_TFUNC is considered to a function type. */
7109 static bfd_boolean
7110 arm_elf_find_function (bfd * abfd ATTRIBUTE_UNUSED,
7111 asection * section,
7112 asymbol ** symbols,
7113 bfd_vma offset,
7114 const char ** filename_ptr,
7115 const char ** functionname_ptr)
7117 const char * filename = NULL;
7118 asymbol * func = NULL;
7119 bfd_vma low_func = 0;
7120 asymbol ** p;
7122 for (p = symbols; *p != NULL; p++)
7124 elf_symbol_type *q;
7126 q = (elf_symbol_type *) *p;
7128 switch (ELF_ST_TYPE (q->internal_elf_sym.st_info))
7130 default:
7131 break;
7132 case STT_FILE:
7133 filename = bfd_asymbol_name (&q->symbol);
7134 break;
7135 case STT_FUNC:
7136 case STT_ARM_TFUNC:
7137 case STT_NOTYPE:
7138 /* Skip mapping symbols. */
7139 if ((q->symbol.flags & BSF_LOCAL)
7140 && bfd_is_arm_special_symbol_name (q->symbol.name,
7141 BFD_ARM_SPECIAL_SYM_TYPE_ANY))
7142 continue;
7143 /* Fall through. */
7144 if (bfd_get_section (&q->symbol) == section
7145 && q->symbol.value >= low_func
7146 && q->symbol.value <= offset)
7148 func = (asymbol *) q;
7149 low_func = q->symbol.value;
7151 break;
7155 if (func == NULL)
7156 return FALSE;
7158 if (filename_ptr)
7159 *filename_ptr = filename;
7160 if (functionname_ptr)
7161 *functionname_ptr = bfd_asymbol_name (func);
7163 return TRUE;
7167 /* Find the nearest line to a particular section and offset, for error
7168 reporting. This code is a duplicate of the code in elf.c, except
7169 that it uses arm_elf_find_function. */
7171 static bfd_boolean
7172 elf32_arm_find_nearest_line (bfd * abfd,
7173 asection * section,
7174 asymbol ** symbols,
7175 bfd_vma offset,
7176 const char ** filename_ptr,
7177 const char ** functionname_ptr,
7178 unsigned int * line_ptr)
7180 bfd_boolean found = FALSE;
7182 /* We skip _bfd_dwarf1_find_nearest_line since no known ARM toolchain uses it. */
7184 if (_bfd_dwarf2_find_nearest_line (abfd, section, symbols, offset,
7185 filename_ptr, functionname_ptr,
7186 line_ptr, 0,
7187 & elf_tdata (abfd)->dwarf2_find_line_info))
7189 if (!*functionname_ptr)
7190 arm_elf_find_function (abfd, section, symbols, offset,
7191 *filename_ptr ? NULL : filename_ptr,
7192 functionname_ptr);
7194 return TRUE;
7197 if (! _bfd_stab_section_find_nearest_line (abfd, symbols, section, offset,
7198 & found, filename_ptr,
7199 functionname_ptr, line_ptr,
7200 & elf_tdata (abfd)->line_info))
7201 return FALSE;
7203 if (found && (*functionname_ptr || *line_ptr))
7204 return TRUE;
7206 if (symbols == NULL)
7207 return FALSE;
7209 if (! arm_elf_find_function (abfd, section, symbols, offset,
7210 filename_ptr, functionname_ptr))
7211 return FALSE;
7213 *line_ptr = 0;
7214 return TRUE;
7217 static bfd_boolean
7218 elf32_arm_find_inliner_info (bfd * abfd,
7219 const char ** filename_ptr,
7220 const char ** functionname_ptr,
7221 unsigned int * line_ptr)
7223 bfd_boolean found;
7224 found = _bfd_dwarf2_find_inliner_info (abfd, filename_ptr,
7225 functionname_ptr, line_ptr,
7226 & elf_tdata (abfd)->dwarf2_find_line_info);
7227 return found;
7230 /* Adjust a symbol defined by a dynamic object and referenced by a
7231 regular object. The current definition is in some section of the
7232 dynamic object, but we're not including those sections. We have to
7233 change the definition to something the rest of the link can
7234 understand. */
7236 static bfd_boolean
7237 elf32_arm_adjust_dynamic_symbol (struct bfd_link_info * info,
7238 struct elf_link_hash_entry * h)
7240 bfd * dynobj;
7241 asection * s;
7242 unsigned int power_of_two;
7243 struct elf32_arm_link_hash_entry * eh;
7244 struct elf32_arm_link_hash_table *globals;
7246 globals = elf32_arm_hash_table (info);
7247 dynobj = elf_hash_table (info)->dynobj;
7249 /* Make sure we know what is going on here. */
7250 BFD_ASSERT (dynobj != NULL
7251 && (h->needs_plt
7252 || h->u.weakdef != NULL
7253 || (h->def_dynamic
7254 && h->ref_regular
7255 && !h->def_regular)));
7257 eh = (struct elf32_arm_link_hash_entry *) h;
7259 /* If this is a function, put it in the procedure linkage table. We
7260 will fill in the contents of the procedure linkage table later,
7261 when we know the address of the .got section. */
7262 if (h->type == STT_FUNC || h->type == STT_ARM_TFUNC
7263 || h->needs_plt)
7265 if (h->plt.refcount <= 0
7266 || SYMBOL_CALLS_LOCAL (info, h)
7267 || (ELF_ST_VISIBILITY (h->other) != STV_DEFAULT
7268 && h->root.type == bfd_link_hash_undefweak))
7270 /* This case can occur if we saw a PLT32 reloc in an input
7271 file, but the symbol was never referred to by a dynamic
7272 object, or if all references were garbage collected. In
7273 such a case, we don't actually need to build a procedure
7274 linkage table, and we can just do a PC24 reloc instead. */
7275 h->plt.offset = (bfd_vma) -1;
7276 eh->plt_thumb_refcount = 0;
7277 h->needs_plt = 0;
7280 return TRUE;
7282 else
7284 /* It's possible that we incorrectly decided a .plt reloc was
7285 needed for an R_ARM_PC24 or similar reloc to a non-function sym
7286 in check_relocs. We can't decide accurately between function
7287 and non-function syms in check-relocs; Objects loaded later in
7288 the link may change h->type. So fix it now. */
7289 h->plt.offset = (bfd_vma) -1;
7290 eh->plt_thumb_refcount = 0;
7293 /* If this is a weak symbol, and there is a real definition, the
7294 processor independent code will have arranged for us to see the
7295 real definition first, and we can just use the same value. */
7296 if (h->u.weakdef != NULL)
7298 BFD_ASSERT (h->u.weakdef->root.type == bfd_link_hash_defined
7299 || h->u.weakdef->root.type == bfd_link_hash_defweak);
7300 h->root.u.def.section = h->u.weakdef->root.u.def.section;
7301 h->root.u.def.value = h->u.weakdef->root.u.def.value;
7302 return TRUE;
7305 /* If there are no non-GOT references, we do not need a copy
7306 relocation. */
7307 if (!h->non_got_ref)
7308 return TRUE;
7310 /* This is a reference to a symbol defined by a dynamic object which
7311 is not a function. */
7313 /* If we are creating a shared library, we must presume that the
7314 only references to the symbol are via the global offset table.
7315 For such cases we need not do anything here; the relocations will
7316 be handled correctly by relocate_section. Relocatable executables
7317 can reference data in shared objects directly, so we don't need to
7318 do anything here. */
7319 if (info->shared || globals->root.is_relocatable_executable)
7320 return TRUE;
7322 if (h->size == 0)
7324 (*_bfd_error_handler) (_("dynamic variable `%s' is zero size"),
7325 h->root.root.string);
7326 return TRUE;
7329 /* We must allocate the symbol in our .dynbss section, which will
7330 become part of the .bss section of the executable. There will be
7331 an entry for this symbol in the .dynsym section. The dynamic
7332 object will contain position independent code, so all references
7333 from the dynamic object to this symbol will go through the global
7334 offset table. The dynamic linker will use the .dynsym entry to
7335 determine the address it must put in the global offset table, so
7336 both the dynamic object and the regular object will refer to the
7337 same memory location for the variable. */
7338 s = bfd_get_section_by_name (dynobj, ".dynbss");
7339 BFD_ASSERT (s != NULL);
7341 /* We must generate a R_ARM_COPY reloc to tell the dynamic linker to
7342 copy the initial value out of the dynamic object and into the
7343 runtime process image. We need to remember the offset into the
7344 .rel(a).bss section we are going to use. */
7345 if ((h->root.u.def.section->flags & SEC_ALLOC) != 0)
7347 asection *srel;
7349 srel = bfd_get_section_by_name (dynobj, RELOC_SECTION (globals, ".bss"));
7350 BFD_ASSERT (srel != NULL);
7351 srel->size += RELOC_SIZE (globals);
7352 h->needs_copy = 1;
7355 /* We need to figure out the alignment required for this symbol. I
7356 have no idea how ELF linkers handle this. */
7357 power_of_two = bfd_log2 (h->size);
7358 if (power_of_two > 3)
7359 power_of_two = 3;
7361 /* Apply the required alignment. */
7362 s->size = BFD_ALIGN (s->size, (bfd_size_type) (1 << power_of_two));
7363 if (power_of_two > bfd_get_section_alignment (dynobj, s))
7365 if (! bfd_set_section_alignment (dynobj, s, power_of_two))
7366 return FALSE;
7369 /* Define the symbol as being at this point in the section. */
7370 h->root.u.def.section = s;
7371 h->root.u.def.value = s->size;
7373 /* Increment the section size to make room for the symbol. */
7374 s->size += h->size;
7376 return TRUE;
7379 /* Allocate space in .plt, .got and associated reloc sections for
7380 dynamic relocs. */
7382 static bfd_boolean
7383 allocate_dynrelocs (struct elf_link_hash_entry *h, void * inf)
7385 struct bfd_link_info *info;
7386 struct elf32_arm_link_hash_table *htab;
7387 struct elf32_arm_link_hash_entry *eh;
7388 struct elf32_arm_relocs_copied *p;
7390 eh = (struct elf32_arm_link_hash_entry *) h;
7392 if (h->root.type == bfd_link_hash_indirect)
7393 return TRUE;
7395 if (h->root.type == bfd_link_hash_warning)
7396 /* When warning symbols are created, they **replace** the "real"
7397 entry in the hash table, thus we never get to see the real
7398 symbol in a hash traversal. So look at it now. */
7399 h = (struct elf_link_hash_entry *) h->root.u.i.link;
7401 info = (struct bfd_link_info *) inf;
7402 htab = elf32_arm_hash_table (info);
7404 if (htab->root.dynamic_sections_created
7405 && h->plt.refcount > 0)
7407 /* Make sure this symbol is output as a dynamic symbol.
7408 Undefined weak syms won't yet be marked as dynamic. */
7409 if (h->dynindx == -1
7410 && !h->forced_local)
7412 if (! bfd_elf_link_record_dynamic_symbol (info, h))
7413 return FALSE;
7416 if (info->shared
7417 || WILL_CALL_FINISH_DYNAMIC_SYMBOL (1, 0, h))
7419 asection *s = htab->splt;
7421 /* If this is the first .plt entry, make room for the special
7422 first entry. */
7423 if (s->size == 0)
7424 s->size += htab->plt_header_size;
7426 h->plt.offset = s->size;
7428 /* If we will insert a Thumb trampoline before this PLT, leave room
7429 for it. */
7430 if (!htab->use_blx && eh->plt_thumb_refcount > 0)
7432 h->plt.offset += PLT_THUMB_STUB_SIZE;
7433 s->size += PLT_THUMB_STUB_SIZE;
7436 /* If this symbol is not defined in a regular file, and we are
7437 not generating a shared library, then set the symbol to this
7438 location in the .plt. This is required to make function
7439 pointers compare as equal between the normal executable and
7440 the shared library. */
7441 if (! info->shared
7442 && !h->def_regular)
7444 h->root.u.def.section = s;
7445 h->root.u.def.value = h->plt.offset;
7447 /* Make sure the function is not marked as Thumb, in case
7448 it is the target of an ABS32 relocation, which will
7449 point to the PLT entry. */
7450 if (ELF_ST_TYPE (h->type) == STT_ARM_TFUNC)
7451 h->type = ELF_ST_INFO (ELF_ST_BIND (h->type), STT_FUNC);
7454 /* Make room for this entry. */
7455 s->size += htab->plt_entry_size;
7457 if (!htab->symbian_p)
7459 /* We also need to make an entry in the .got.plt section, which
7460 will be placed in the .got section by the linker script. */
7461 eh->plt_got_offset = htab->sgotplt->size;
7462 htab->sgotplt->size += 4;
7465 /* We also need to make an entry in the .rel(a).plt section. */
7466 htab->srelplt->size += RELOC_SIZE (htab);
7468 /* VxWorks executables have a second set of relocations for
7469 each PLT entry. They go in a separate relocation section,
7470 which is processed by the kernel loader. */
7471 if (htab->vxworks_p && !info->shared)
7473 /* There is a relocation for the initial PLT entry:
7474 an R_ARM_32 relocation for _GLOBAL_OFFSET_TABLE_. */
7475 if (h->plt.offset == htab->plt_header_size)
7476 htab->srelplt2->size += RELOC_SIZE (htab);
7478 /* There are two extra relocations for each subsequent
7479 PLT entry: an R_ARM_32 relocation for the GOT entry,
7480 and an R_ARM_32 relocation for the PLT entry. */
7481 htab->srelplt2->size += RELOC_SIZE (htab) * 2;
7484 else
7486 h->plt.offset = (bfd_vma) -1;
7487 h->needs_plt = 0;
7490 else
7492 h->plt.offset = (bfd_vma) -1;
7493 h->needs_plt = 0;
7496 if (h->got.refcount > 0)
7498 asection *s;
7499 bfd_boolean dyn;
7500 int tls_type = elf32_arm_hash_entry (h)->tls_type;
7501 int indx;
7503 /* Make sure this symbol is output as a dynamic symbol.
7504 Undefined weak syms won't yet be marked as dynamic. */
7505 if (h->dynindx == -1
7506 && !h->forced_local)
7508 if (! bfd_elf_link_record_dynamic_symbol (info, h))
7509 return FALSE;
7512 if (!htab->symbian_p)
7514 s = htab->sgot;
7515 h->got.offset = s->size;
7517 if (tls_type == GOT_UNKNOWN)
7518 abort ();
7520 if (tls_type == GOT_NORMAL)
7521 /* Non-TLS symbols need one GOT slot. */
7522 s->size += 4;
7523 else
7525 if (tls_type & GOT_TLS_GD)
7526 /* R_ARM_TLS_GD32 needs 2 consecutive GOT slots. */
7527 s->size += 8;
7528 if (tls_type & GOT_TLS_IE)
7529 /* R_ARM_TLS_IE32 needs one GOT slot. */
7530 s->size += 4;
7533 dyn = htab->root.dynamic_sections_created;
7535 indx = 0;
7536 if (WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn, info->shared, h)
7537 && (!info->shared
7538 || !SYMBOL_REFERENCES_LOCAL (info, h)))
7539 indx = h->dynindx;
7541 if (tls_type != GOT_NORMAL
7542 && (info->shared || indx != 0)
7543 && (ELF_ST_VISIBILITY (h->other) == STV_DEFAULT
7544 || h->root.type != bfd_link_hash_undefweak))
7546 if (tls_type & GOT_TLS_IE)
7547 htab->srelgot->size += RELOC_SIZE (htab);
7549 if (tls_type & GOT_TLS_GD)
7550 htab->srelgot->size += RELOC_SIZE (htab);
7552 if ((tls_type & GOT_TLS_GD) && indx != 0)
7553 htab->srelgot->size += RELOC_SIZE (htab);
7555 else if ((ELF_ST_VISIBILITY (h->other) == STV_DEFAULT
7556 || h->root.type != bfd_link_hash_undefweak)
7557 && (info->shared
7558 || WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn, 0, h)))
7559 htab->srelgot->size += RELOC_SIZE (htab);
7562 else
7563 h->got.offset = (bfd_vma) -1;
7565 /* Allocate stubs for exported Thumb functions on v4t. */
7566 if (!htab->use_blx && h->dynindx != -1
7567 && ELF_ST_TYPE (h->type) == STT_ARM_TFUNC
7568 && ELF_ST_VISIBILITY (h->other) == STV_DEFAULT)
7570 struct elf_link_hash_entry * th;
7571 struct bfd_link_hash_entry * bh;
7572 struct elf_link_hash_entry * myh;
7573 char name[1024];
7574 asection *s;
7575 bh = NULL;
7576 /* Create a new symbol to regist the real location of the function. */
7577 s = h->root.u.def.section;
7578 sprintf(name, "__real_%s", h->root.root.string);
7579 _bfd_generic_link_add_one_symbol (info, s->owner,
7580 name, BSF_GLOBAL, s,
7581 h->root.u.def.value,
7582 NULL, TRUE, FALSE, &bh);
7584 myh = (struct elf_link_hash_entry *) bh;
7585 myh->type = ELF_ST_INFO (STB_LOCAL, STT_ARM_TFUNC);
7586 myh->forced_local = 1;
7587 eh->export_glue = myh;
7588 th = record_arm_to_thumb_glue (info, h);
7589 /* Point the symbol at the stub. */
7590 h->type = ELF_ST_INFO (ELF_ST_BIND (h->type), STT_FUNC);
7591 h->root.u.def.section = th->root.u.def.section;
7592 h->root.u.def.value = th->root.u.def.value & ~1;
7595 if (eh->relocs_copied == NULL)
7596 return TRUE;
7598 /* In the shared -Bsymbolic case, discard space allocated for
7599 dynamic pc-relative relocs against symbols which turn out to be
7600 defined in regular objects. For the normal shared case, discard
7601 space for pc-relative relocs that have become local due to symbol
7602 visibility changes. */
7604 if (info->shared || htab->root.is_relocatable_executable)
7606 /* The only reloc that uses pc_count is R_ARM_REL32, which will
7607 appear on something like ".long foo - .". We want calls to
7608 protected symbols to resolve directly to the function rather
7609 than going via the plt. If people want function pointer
7610 comparisons to work as expected then they should avoid
7611 writing assembly like ".long foo - .". */
7612 if (SYMBOL_CALLS_LOCAL (info, h))
7614 struct elf32_arm_relocs_copied **pp;
7616 for (pp = &eh->relocs_copied; (p = *pp) != NULL; )
7618 p->count -= p->pc_count;
7619 p->pc_count = 0;
7620 if (p->count == 0)
7621 *pp = p->next;
7622 else
7623 pp = &p->next;
7627 /* Also discard relocs on undefined weak syms with non-default
7628 visibility. */
7629 if (eh->relocs_copied != NULL
7630 && h->root.type == bfd_link_hash_undefweak)
7632 if (ELF_ST_VISIBILITY (h->other) != STV_DEFAULT)
7633 eh->relocs_copied = NULL;
7635 /* Make sure undefined weak symbols are output as a dynamic
7636 symbol in PIEs. */
7637 else if (h->dynindx == -1
7638 && !h->forced_local)
7640 if (! bfd_elf_link_record_dynamic_symbol (info, h))
7641 return FALSE;
7645 else if (htab->root.is_relocatable_executable && h->dynindx == -1
7646 && h->root.type == bfd_link_hash_new)
7648 /* Output absolute symbols so that we can create relocations
7649 against them. For normal symbols we output a relocation
7650 against the section that contains them. */
7651 if (! bfd_elf_link_record_dynamic_symbol (info, h))
7652 return FALSE;
7656 else
7658 /* For the non-shared case, discard space for relocs against
7659 symbols which turn out to need copy relocs or are not
7660 dynamic. */
7662 if (!h->non_got_ref
7663 && ((h->def_dynamic
7664 && !h->def_regular)
7665 || (htab->root.dynamic_sections_created
7666 && (h->root.type == bfd_link_hash_undefweak
7667 || h->root.type == bfd_link_hash_undefined))))
7669 /* Make sure this symbol is output as a dynamic symbol.
7670 Undefined weak syms won't yet be marked as dynamic. */
7671 if (h->dynindx == -1
7672 && !h->forced_local)
7674 if (! bfd_elf_link_record_dynamic_symbol (info, h))
7675 return FALSE;
7678 /* If that succeeded, we know we'll be keeping all the
7679 relocs. */
7680 if (h->dynindx != -1)
7681 goto keep;
7684 eh->relocs_copied = NULL;
7686 keep: ;
7689 /* Finally, allocate space. */
7690 for (p = eh->relocs_copied; p != NULL; p = p->next)
7692 asection *sreloc = elf_section_data (p->section)->sreloc;
7693 sreloc->size += p->count * RELOC_SIZE (htab);
7696 return TRUE;
7699 /* Find any dynamic relocs that apply to read-only sections. */
7701 static bfd_boolean
7702 elf32_arm_readonly_dynrelocs (struct elf_link_hash_entry *h, PTR inf)
7704 struct elf32_arm_link_hash_entry *eh;
7705 struct elf32_arm_relocs_copied *p;
7707 if (h->root.type == bfd_link_hash_warning)
7708 h = (struct elf_link_hash_entry *) h->root.u.i.link;
7710 eh = (struct elf32_arm_link_hash_entry *) h;
7711 for (p = eh->relocs_copied; p != NULL; p = p->next)
7713 asection *s = p->section;
7715 if (s != NULL && (s->flags & SEC_READONLY) != 0)
7717 struct bfd_link_info *info = (struct bfd_link_info *) inf;
7719 info->flags |= DF_TEXTREL;
7721 /* Not an error, just cut short the traversal. */
7722 return FALSE;
7725 return TRUE;
7728 /* Set the sizes of the dynamic sections. */
7730 static bfd_boolean
7731 elf32_arm_size_dynamic_sections (bfd * output_bfd ATTRIBUTE_UNUSED,
7732 struct bfd_link_info * info)
7734 bfd * dynobj;
7735 asection * s;
7736 bfd_boolean plt;
7737 bfd_boolean relocs;
7738 bfd *ibfd;
7739 struct elf32_arm_link_hash_table *htab;
7741 htab = elf32_arm_hash_table (info);
7742 dynobj = elf_hash_table (info)->dynobj;
7743 BFD_ASSERT (dynobj != NULL);
7744 check_use_blx (htab);
7746 if (elf_hash_table (info)->dynamic_sections_created)
7748 /* Set the contents of the .interp section to the interpreter. */
7749 if (info->executable)
7751 s = bfd_get_section_by_name (dynobj, ".interp");
7752 BFD_ASSERT (s != NULL);
7753 s->size = sizeof ELF_DYNAMIC_INTERPRETER;
7754 s->contents = (unsigned char *) ELF_DYNAMIC_INTERPRETER;
7758 /* Set up .got offsets for local syms, and space for local dynamic
7759 relocs. */
7760 for (ibfd = info->input_bfds; ibfd != NULL; ibfd = ibfd->link_next)
7762 bfd_signed_vma *local_got;
7763 bfd_signed_vma *end_local_got;
7764 char *local_tls_type;
7765 bfd_size_type locsymcount;
7766 Elf_Internal_Shdr *symtab_hdr;
7767 asection *srel;
7769 if (bfd_get_flavour (ibfd) != bfd_target_elf_flavour)
7770 continue;
7772 for (s = ibfd->sections; s != NULL; s = s->next)
7774 struct elf32_arm_relocs_copied *p;
7776 for (p = elf_section_data (s)->local_dynrel; p != NULL; p = p->next)
7778 if (!bfd_is_abs_section (p->section)
7779 && bfd_is_abs_section (p->section->output_section))
7781 /* Input section has been discarded, either because
7782 it is a copy of a linkonce section or due to
7783 linker script /DISCARD/, so we'll be discarding
7784 the relocs too. */
7786 else if (p->count != 0)
7788 srel = elf_section_data (p->section)->sreloc;
7789 srel->size += p->count * RELOC_SIZE (htab);
7790 if ((p->section->output_section->flags & SEC_READONLY) != 0)
7791 info->flags |= DF_TEXTREL;
7796 local_got = elf_local_got_refcounts (ibfd);
7797 if (!local_got)
7798 continue;
7800 symtab_hdr = &elf_tdata (ibfd)->symtab_hdr;
7801 locsymcount = symtab_hdr->sh_info;
7802 end_local_got = local_got + locsymcount;
7803 local_tls_type = elf32_arm_local_got_tls_type (ibfd);
7804 s = htab->sgot;
7805 srel = htab->srelgot;
7806 for (; local_got < end_local_got; ++local_got, ++local_tls_type)
7808 if (*local_got > 0)
7810 *local_got = s->size;
7811 if (*local_tls_type & GOT_TLS_GD)
7812 /* TLS_GD relocs need an 8-byte structure in the GOT. */
7813 s->size += 8;
7814 if (*local_tls_type & GOT_TLS_IE)
7815 s->size += 4;
7816 if (*local_tls_type == GOT_NORMAL)
7817 s->size += 4;
7819 if (info->shared || *local_tls_type == GOT_TLS_GD)
7820 srel->size += RELOC_SIZE (htab);
7822 else
7823 *local_got = (bfd_vma) -1;
7827 if (htab->tls_ldm_got.refcount > 0)
7829 /* Allocate two GOT entries and one dynamic relocation (if necessary)
7830 for R_ARM_TLS_LDM32 relocations. */
7831 htab->tls_ldm_got.offset = htab->sgot->size;
7832 htab->sgot->size += 8;
7833 if (info->shared)
7834 htab->srelgot->size += RELOC_SIZE (htab);
7836 else
7837 htab->tls_ldm_got.offset = -1;
7839 /* Allocate global sym .plt and .got entries, and space for global
7840 sym dynamic relocs. */
7841 elf_link_hash_traverse (& htab->root, allocate_dynrelocs, info);
7843 /* The check_relocs and adjust_dynamic_symbol entry points have
7844 determined the sizes of the various dynamic sections. Allocate
7845 memory for them. */
7846 plt = FALSE;
7847 relocs = FALSE;
7848 for (s = dynobj->sections; s != NULL; s = s->next)
7850 const char * name;
7852 if ((s->flags & SEC_LINKER_CREATED) == 0)
7853 continue;
7855 /* It's OK to base decisions on the section name, because none
7856 of the dynobj section names depend upon the input files. */
7857 name = bfd_get_section_name (dynobj, s);
7859 if (strcmp (name, ".plt") == 0)
7861 /* Remember whether there is a PLT. */
7862 plt = s->size != 0;
7864 else if (strncmp (name, ".rel", 4) == 0)
7866 if (s->size != 0)
7868 /* Remember whether there are any reloc sections other
7869 than .rel(a).plt and .rela.plt.unloaded. */
7870 if (s != htab->srelplt && s != htab->srelplt2)
7871 relocs = TRUE;
7873 /* We use the reloc_count field as a counter if we need
7874 to copy relocs into the output file. */
7875 s->reloc_count = 0;
7878 else if (strncmp (name, ".got", 4) != 0
7879 && strcmp (name, ".dynbss") != 0)
7881 /* It's not one of our sections, so don't allocate space. */
7882 continue;
7885 if (s->size == 0)
7887 /* If we don't need this section, strip it from the
7888 output file. This is mostly to handle .rel(a).bss and
7889 .rel(a).plt. We must create both sections in
7890 create_dynamic_sections, because they must be created
7891 before the linker maps input sections to output
7892 sections. The linker does that before
7893 adjust_dynamic_symbol is called, and it is that
7894 function which decides whether anything needs to go
7895 into these sections. */
7896 s->flags |= SEC_EXCLUDE;
7897 continue;
7900 if ((s->flags & SEC_HAS_CONTENTS) == 0)
7901 continue;
7903 /* Allocate memory for the section contents. */
7904 s->contents = (bfd_byte *) bfd_zalloc (dynobj, s->size);
7905 if (s->contents == NULL)
7906 return FALSE;
7909 if (elf_hash_table (info)->dynamic_sections_created)
7911 /* Add some entries to the .dynamic section. We fill in the
7912 values later, in elf32_arm_finish_dynamic_sections, but we
7913 must add the entries now so that we get the correct size for
7914 the .dynamic section. The DT_DEBUG entry is filled in by the
7915 dynamic linker and used by the debugger. */
7916 #define add_dynamic_entry(TAG, VAL) \
7917 _bfd_elf_add_dynamic_entry (info, TAG, VAL)
7919 if (info->executable)
7921 if (!add_dynamic_entry (DT_DEBUG, 0))
7922 return FALSE;
7925 if (plt)
7927 if ( !add_dynamic_entry (DT_PLTGOT, 0)
7928 || !add_dynamic_entry (DT_PLTRELSZ, 0)
7929 || !add_dynamic_entry (DT_PLTREL,
7930 htab->use_rel ? DT_REL : DT_RELA)
7931 || !add_dynamic_entry (DT_JMPREL, 0))
7932 return FALSE;
7935 if (relocs)
7937 if (htab->use_rel)
7939 if (!add_dynamic_entry (DT_REL, 0)
7940 || !add_dynamic_entry (DT_RELSZ, 0)
7941 || !add_dynamic_entry (DT_RELENT, RELOC_SIZE (htab)))
7942 return FALSE;
7944 else
7946 if (!add_dynamic_entry (DT_RELA, 0)
7947 || !add_dynamic_entry (DT_RELASZ, 0)
7948 || !add_dynamic_entry (DT_RELAENT, RELOC_SIZE (htab)))
7949 return FALSE;
7953 /* If any dynamic relocs apply to a read-only section,
7954 then we need a DT_TEXTREL entry. */
7955 if ((info->flags & DF_TEXTREL) == 0)
7956 elf_link_hash_traverse (&htab->root, elf32_arm_readonly_dynrelocs,
7957 (PTR) info);
7959 if ((info->flags & DF_TEXTREL) != 0)
7961 if (!add_dynamic_entry (DT_TEXTREL, 0))
7962 return FALSE;
7965 #undef add_dynamic_entry
7967 return TRUE;
7970 /* Finish up dynamic symbol handling. We set the contents of various
7971 dynamic sections here. */
7973 static bfd_boolean
7974 elf32_arm_finish_dynamic_symbol (bfd * output_bfd, struct bfd_link_info * info,
7975 struct elf_link_hash_entry * h, Elf_Internal_Sym * sym)
7977 bfd * dynobj;
7978 struct elf32_arm_link_hash_table *htab;
7979 struct elf32_arm_link_hash_entry *eh;
7981 dynobj = elf_hash_table (info)->dynobj;
7982 htab = elf32_arm_hash_table (info);
7983 eh = (struct elf32_arm_link_hash_entry *) h;
7985 if (h->plt.offset != (bfd_vma) -1)
7987 asection * splt;
7988 asection * srel;
7989 bfd_byte *loc;
7990 bfd_vma plt_index;
7991 Elf_Internal_Rela rel;
7993 /* This symbol has an entry in the procedure linkage table. Set
7994 it up. */
7996 BFD_ASSERT (h->dynindx != -1);
7998 splt = bfd_get_section_by_name (dynobj, ".plt");
7999 srel = bfd_get_section_by_name (dynobj, RELOC_SECTION (htab, ".plt"));
8000 BFD_ASSERT (splt != NULL && srel != NULL);
8002 /* Fill in the entry in the procedure linkage table. */
8003 if (htab->symbian_p)
8005 put_arm_insn (htab, output_bfd,
8006 elf32_arm_symbian_plt_entry[0],
8007 splt->contents + h->plt.offset);
8008 bfd_put_32 (output_bfd,
8009 elf32_arm_symbian_plt_entry[1],
8010 splt->contents + h->plt.offset + 4);
8012 /* Fill in the entry in the .rel.plt section. */
8013 rel.r_offset = (splt->output_section->vma
8014 + splt->output_offset
8015 + h->plt.offset + 4);
8016 rel.r_info = ELF32_R_INFO (h->dynindx, R_ARM_GLOB_DAT);
8018 /* Get the index in the procedure linkage table which
8019 corresponds to this symbol. This is the index of this symbol
8020 in all the symbols for which we are making plt entries. The
8021 first entry in the procedure linkage table is reserved. */
8022 plt_index = ((h->plt.offset - htab->plt_header_size)
8023 / htab->plt_entry_size);
8025 else
8027 bfd_vma got_offset, got_address, plt_address;
8028 bfd_vma got_displacement;
8029 asection * sgot;
8030 bfd_byte * ptr;
8032 sgot = bfd_get_section_by_name (dynobj, ".got.plt");
8033 BFD_ASSERT (sgot != NULL);
8035 /* Get the offset into the .got.plt table of the entry that
8036 corresponds to this function. */
8037 got_offset = eh->plt_got_offset;
8039 /* Get the index in the procedure linkage table which
8040 corresponds to this symbol. This is the index of this symbol
8041 in all the symbols for which we are making plt entries. The
8042 first three entries in .got.plt are reserved; after that
8043 symbols appear in the same order as in .plt. */
8044 plt_index = (got_offset - 12) / 4;
8046 /* Calculate the address of the GOT entry. */
8047 got_address = (sgot->output_section->vma
8048 + sgot->output_offset
8049 + got_offset);
8051 /* ...and the address of the PLT entry. */
8052 plt_address = (splt->output_section->vma
8053 + splt->output_offset
8054 + h->plt.offset);
8056 ptr = htab->splt->contents + h->plt.offset;
8057 if (htab->vxworks_p && info->shared)
8059 unsigned int i;
8060 bfd_vma val;
8062 for (i = 0; i != htab->plt_entry_size / 4; i++, ptr += 4)
8064 val = elf32_arm_vxworks_shared_plt_entry[i];
8065 if (i == 2)
8066 val |= got_address - sgot->output_section->vma;
8067 if (i == 5)
8068 val |= plt_index * RELOC_SIZE (htab);
8069 if (i == 2 || i == 5)
8070 bfd_put_32 (output_bfd, val, ptr);
8071 else
8072 put_arm_insn (htab, output_bfd, val, ptr);
8075 else if (htab->vxworks_p)
8077 unsigned int i;
8078 bfd_vma val;
8080 for (i = 0; i != htab->plt_entry_size / 4; i++)
8082 val = elf32_arm_vxworks_exec_plt_entry[i];
8083 if (i == 2)
8084 val |= got_address;
8085 if (i == 4)
8086 val |= 0xffffff & -((h->plt.offset + i * 4 + 8) >> 2);
8087 if (i == 5)
8088 val |= plt_index * RELOC_SIZE (htab);
8089 if (i == 2 || i == 5)
8090 bfd_put_32 (output_bfd, val, ptr);
8091 else
8092 put_arm_insn (htab, output_bfd, val, ptr);
8095 loc = (htab->srelplt2->contents
8096 + (plt_index * 2 + 1) * RELOC_SIZE (htab));
8098 /* Create the .rela.plt.unloaded R_ARM_ABS32 relocation
8099 referencing the GOT for this PLT entry. */
8100 rel.r_offset = plt_address + 8;
8101 rel.r_info = ELF32_R_INFO (htab->root.hgot->indx, R_ARM_ABS32);
8102 rel.r_addend = got_offset;
8103 SWAP_RELOC_OUT (htab) (output_bfd, &rel, loc);
8104 loc += RELOC_SIZE (htab);
8106 /* Create the R_ARM_ABS32 relocation referencing the
8107 beginning of the PLT for this GOT entry. */
8108 rel.r_offset = got_address;
8109 rel.r_info = ELF32_R_INFO (htab->root.hplt->indx, R_ARM_ABS32);
8110 rel.r_addend = 0;
8111 SWAP_RELOC_OUT (htab) (output_bfd, &rel, loc);
8113 else
8115 /* Calculate the displacement between the PLT slot and the
8116 entry in the GOT. The eight-byte offset accounts for the
8117 value produced by adding to pc in the first instruction
8118 of the PLT stub. */
8119 got_displacement = got_address - (plt_address + 8);
8121 BFD_ASSERT ((got_displacement & 0xf0000000) == 0);
8123 if (!htab->use_blx && eh->plt_thumb_refcount > 0)
8125 put_thumb_insn (htab, output_bfd,
8126 elf32_arm_plt_thumb_stub[0], ptr - 4);
8127 put_thumb_insn (htab, output_bfd,
8128 elf32_arm_plt_thumb_stub[1], ptr - 2);
8131 put_arm_insn (htab, output_bfd,
8132 elf32_arm_plt_entry[0]
8133 | ((got_displacement & 0x0ff00000) >> 20),
8134 ptr + 0);
8135 put_arm_insn (htab, output_bfd,
8136 elf32_arm_plt_entry[1]
8137 | ((got_displacement & 0x000ff000) >> 12),
8138 ptr+ 4);
8139 put_arm_insn (htab, output_bfd,
8140 elf32_arm_plt_entry[2]
8141 | (got_displacement & 0x00000fff),
8142 ptr + 8);
8143 #ifdef FOUR_WORD_PLT
8144 bfd_put_32 (output_bfd, elf32_arm_plt_entry[3], ptr + 12);
8145 #endif
8148 /* Fill in the entry in the global offset table. */
8149 bfd_put_32 (output_bfd,
8150 (splt->output_section->vma
8151 + splt->output_offset),
8152 sgot->contents + got_offset);
8154 /* Fill in the entry in the .rel(a).plt section. */
8155 rel.r_addend = 0;
8156 rel.r_offset = got_address;
8157 rel.r_info = ELF32_R_INFO (h->dynindx, R_ARM_JUMP_SLOT);
8160 loc = srel->contents + plt_index * RELOC_SIZE (htab);
8161 SWAP_RELOC_OUT (htab) (output_bfd, &rel, loc);
8163 if (!h->def_regular)
8165 /* Mark the symbol as undefined, rather than as defined in
8166 the .plt section. Leave the value alone. */
8167 sym->st_shndx = SHN_UNDEF;
8168 /* If the symbol is weak, we do need to clear the value.
8169 Otherwise, the PLT entry would provide a definition for
8170 the symbol even if the symbol wasn't defined anywhere,
8171 and so the symbol would never be NULL. */
8172 if (!h->ref_regular_nonweak)
8173 sym->st_value = 0;
8177 if (h->got.offset != (bfd_vma) -1
8178 && (elf32_arm_hash_entry (h)->tls_type & GOT_TLS_GD) == 0
8179 && (elf32_arm_hash_entry (h)->tls_type & GOT_TLS_IE) == 0)
8181 asection * sgot;
8182 asection * srel;
8183 Elf_Internal_Rela rel;
8184 bfd_byte *loc;
8185 bfd_vma offset;
8187 /* This symbol has an entry in the global offset table. Set it
8188 up. */
8189 sgot = bfd_get_section_by_name (dynobj, ".got");
8190 srel = bfd_get_section_by_name (dynobj, RELOC_SECTION (htab, ".got"));
8191 BFD_ASSERT (sgot != NULL && srel != NULL);
8193 offset = (h->got.offset & ~(bfd_vma) 1);
8194 rel.r_addend = 0;
8195 rel.r_offset = (sgot->output_section->vma
8196 + sgot->output_offset
8197 + offset);
8199 /* If this is a static link, or it is a -Bsymbolic link and the
8200 symbol is defined locally or was forced to be local because
8201 of a version file, we just want to emit a RELATIVE reloc.
8202 The entry in the global offset table will already have been
8203 initialized in the relocate_section function. */
8204 if (info->shared
8205 && SYMBOL_REFERENCES_LOCAL (info, h))
8207 BFD_ASSERT((h->got.offset & 1) != 0);
8208 rel.r_info = ELF32_R_INFO (0, R_ARM_RELATIVE);
8209 if (!htab->use_rel)
8211 rel.r_addend = bfd_get_32 (output_bfd, sgot->contents + offset);
8212 bfd_put_32 (output_bfd, (bfd_vma) 0, sgot->contents + offset);
8215 else
8217 BFD_ASSERT((h->got.offset & 1) == 0);
8218 bfd_put_32 (output_bfd, (bfd_vma) 0, sgot->contents + offset);
8219 rel.r_info = ELF32_R_INFO (h->dynindx, R_ARM_GLOB_DAT);
8222 loc = srel->contents + srel->reloc_count++ * RELOC_SIZE (htab);
8223 SWAP_RELOC_OUT (htab) (output_bfd, &rel, loc);
8226 if (h->needs_copy)
8228 asection * s;
8229 Elf_Internal_Rela rel;
8230 bfd_byte *loc;
8232 /* This symbol needs a copy reloc. Set it up. */
8233 BFD_ASSERT (h->dynindx != -1
8234 && (h->root.type == bfd_link_hash_defined
8235 || h->root.type == bfd_link_hash_defweak));
8237 s = bfd_get_section_by_name (h->root.u.def.section->owner,
8238 RELOC_SECTION (htab, ".bss"));
8239 BFD_ASSERT (s != NULL);
8241 rel.r_addend = 0;
8242 rel.r_offset = (h->root.u.def.value
8243 + h->root.u.def.section->output_section->vma
8244 + h->root.u.def.section->output_offset);
8245 rel.r_info = ELF32_R_INFO (h->dynindx, R_ARM_COPY);
8246 loc = s->contents + s->reloc_count++ * RELOC_SIZE (htab);
8247 SWAP_RELOC_OUT (htab) (output_bfd, &rel, loc);
8250 /* Mark _DYNAMIC and _GLOBAL_OFFSET_TABLE_ as absolute. On VxWorks,
8251 the _GLOBAL_OFFSET_TABLE_ symbol is not absolute: it is relative
8252 to the ".got" section. */
8253 if (strcmp (h->root.root.string, "_DYNAMIC") == 0
8254 || (!htab->vxworks_p && h == htab->root.hgot))
8255 sym->st_shndx = SHN_ABS;
8257 return TRUE;
8260 /* Finish up the dynamic sections. */
8262 static bfd_boolean
8263 elf32_arm_finish_dynamic_sections (bfd * output_bfd, struct bfd_link_info * info)
8265 bfd * dynobj;
8266 asection * sgot;
8267 asection * sdyn;
8269 dynobj = elf_hash_table (info)->dynobj;
8271 sgot = bfd_get_section_by_name (dynobj, ".got.plt");
8272 BFD_ASSERT (elf32_arm_hash_table (info)->symbian_p || sgot != NULL);
8273 sdyn = bfd_get_section_by_name (dynobj, ".dynamic");
8275 if (elf_hash_table (info)->dynamic_sections_created)
8277 asection *splt;
8278 Elf32_External_Dyn *dyncon, *dynconend;
8279 struct elf32_arm_link_hash_table *htab;
8281 htab = elf32_arm_hash_table (info);
8282 splt = bfd_get_section_by_name (dynobj, ".plt");
8283 BFD_ASSERT (splt != NULL && sdyn != NULL);
8285 dyncon = (Elf32_External_Dyn *) sdyn->contents;
8286 dynconend = (Elf32_External_Dyn *) (sdyn->contents + sdyn->size);
8288 for (; dyncon < dynconend; dyncon++)
8290 Elf_Internal_Dyn dyn;
8291 const char * name;
8292 asection * s;
8294 bfd_elf32_swap_dyn_in (dynobj, dyncon, &dyn);
8296 switch (dyn.d_tag)
8298 unsigned int type;
8300 default:
8301 break;
8303 case DT_HASH:
8304 name = ".hash";
8305 goto get_vma_if_bpabi;
8306 case DT_STRTAB:
8307 name = ".dynstr";
8308 goto get_vma_if_bpabi;
8309 case DT_SYMTAB:
8310 name = ".dynsym";
8311 goto get_vma_if_bpabi;
8312 case DT_VERSYM:
8313 name = ".gnu.version";
8314 goto get_vma_if_bpabi;
8315 case DT_VERDEF:
8316 name = ".gnu.version_d";
8317 goto get_vma_if_bpabi;
8318 case DT_VERNEED:
8319 name = ".gnu.version_r";
8320 goto get_vma_if_bpabi;
8322 case DT_PLTGOT:
8323 name = ".got";
8324 goto get_vma;
8325 case DT_JMPREL:
8326 name = RELOC_SECTION (htab, ".plt");
8327 get_vma:
8328 s = bfd_get_section_by_name (output_bfd, name);
8329 BFD_ASSERT (s != NULL);
8330 if (!htab->symbian_p)
8331 dyn.d_un.d_ptr = s->vma;
8332 else
8333 /* In the BPABI, tags in the PT_DYNAMIC section point
8334 at the file offset, not the memory address, for the
8335 convenience of the post linker. */
8336 dyn.d_un.d_ptr = s->filepos;
8337 bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon);
8338 break;
8340 get_vma_if_bpabi:
8341 if (htab->symbian_p)
8342 goto get_vma;
8343 break;
8345 case DT_PLTRELSZ:
8346 s = bfd_get_section_by_name (output_bfd,
8347 RELOC_SECTION (htab, ".plt"));
8348 BFD_ASSERT (s != NULL);
8349 dyn.d_un.d_val = s->size;
8350 bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon);
8351 break;
8353 case DT_RELSZ:
8354 case DT_RELASZ:
8355 if (!htab->symbian_p)
8357 /* My reading of the SVR4 ABI indicates that the
8358 procedure linkage table relocs (DT_JMPREL) should be
8359 included in the overall relocs (DT_REL). This is
8360 what Solaris does. However, UnixWare can not handle
8361 that case. Therefore, we override the DT_RELSZ entry
8362 here to make it not include the JMPREL relocs. Since
8363 the linker script arranges for .rel(a).plt to follow all
8364 other relocation sections, we don't have to worry
8365 about changing the DT_REL entry. */
8366 s = bfd_get_section_by_name (output_bfd,
8367 RELOC_SECTION (htab, ".plt"));
8368 if (s != NULL)
8369 dyn.d_un.d_val -= s->size;
8370 bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon);
8371 break;
8373 /* Fall through */
8375 case DT_REL:
8376 case DT_RELA:
8377 /* In the BPABI, the DT_REL tag must point at the file
8378 offset, not the VMA, of the first relocation
8379 section. So, we use code similar to that in
8380 elflink.c, but do not check for SHF_ALLOC on the
8381 relcoation section, since relocations sections are
8382 never allocated under the BPABI. The comments above
8383 about Unixware notwithstanding, we include all of the
8384 relocations here. */
8385 if (htab->symbian_p)
8387 unsigned int i;
8388 type = ((dyn.d_tag == DT_REL || dyn.d_tag == DT_RELSZ)
8389 ? SHT_REL : SHT_RELA);
8390 dyn.d_un.d_val = 0;
8391 for (i = 1; i < elf_numsections (output_bfd); i++)
8393 Elf_Internal_Shdr *hdr
8394 = elf_elfsections (output_bfd)[i];
8395 if (hdr->sh_type == type)
8397 if (dyn.d_tag == DT_RELSZ
8398 || dyn.d_tag == DT_RELASZ)
8399 dyn.d_un.d_val += hdr->sh_size;
8400 else if ((ufile_ptr) hdr->sh_offset
8401 <= dyn.d_un.d_val - 1)
8402 dyn.d_un.d_val = hdr->sh_offset;
8405 bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon);
8407 break;
8409 /* Set the bottom bit of DT_INIT/FINI if the
8410 corresponding function is Thumb. */
8411 case DT_INIT:
8412 name = info->init_function;
8413 goto get_sym;
8414 case DT_FINI:
8415 name = info->fini_function;
8416 get_sym:
8417 /* If it wasn't set by elf_bfd_final_link
8418 then there is nothing to adjust. */
8419 if (dyn.d_un.d_val != 0)
8421 struct elf_link_hash_entry * eh;
8423 eh = elf_link_hash_lookup (elf_hash_table (info), name,
8424 FALSE, FALSE, TRUE);
8425 if (eh != (struct elf_link_hash_entry *) NULL
8426 && ELF_ST_TYPE (eh->type) == STT_ARM_TFUNC)
8428 dyn.d_un.d_val |= 1;
8429 bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon);
8432 break;
8436 /* Fill in the first entry in the procedure linkage table. */
8437 if (splt->size > 0 && elf32_arm_hash_table (info)->plt_header_size)
8439 const bfd_vma *plt0_entry;
8440 bfd_vma got_address, plt_address, got_displacement;
8442 /* Calculate the addresses of the GOT and PLT. */
8443 got_address = sgot->output_section->vma + sgot->output_offset;
8444 plt_address = splt->output_section->vma + splt->output_offset;
8446 if (htab->vxworks_p)
8448 /* The VxWorks GOT is relocated by the dynamic linker.
8449 Therefore, we must emit relocations rather than simply
8450 computing the values now. */
8451 Elf_Internal_Rela rel;
8453 plt0_entry = elf32_arm_vxworks_exec_plt0_entry;
8454 put_arm_insn (htab, output_bfd, plt0_entry[0],
8455 splt->contents + 0);
8456 put_arm_insn (htab, output_bfd, plt0_entry[1],
8457 splt->contents + 4);
8458 put_arm_insn (htab, output_bfd, plt0_entry[2],
8459 splt->contents + 8);
8460 bfd_put_32 (output_bfd, got_address, splt->contents + 12);
8462 /* Generate a relocation for _GLOBAL_OFFSET_TABLE_. */
8463 rel.r_offset = plt_address + 12;
8464 rel.r_info = ELF32_R_INFO (htab->root.hgot->indx, R_ARM_ABS32);
8465 rel.r_addend = 0;
8466 SWAP_RELOC_OUT (htab) (output_bfd, &rel,
8467 htab->srelplt2->contents);
8469 else
8471 got_displacement = got_address - (plt_address + 16);
8473 plt0_entry = elf32_arm_plt0_entry;
8474 put_arm_insn (htab, output_bfd, plt0_entry[0],
8475 splt->contents + 0);
8476 put_arm_insn (htab, output_bfd, plt0_entry[1],
8477 splt->contents + 4);
8478 put_arm_insn (htab, output_bfd, plt0_entry[2],
8479 splt->contents + 8);
8480 put_arm_insn (htab, output_bfd, plt0_entry[3],
8481 splt->contents + 12);
8483 #ifdef FOUR_WORD_PLT
8484 /* The displacement value goes in the otherwise-unused
8485 last word of the second entry. */
8486 bfd_put_32 (output_bfd, got_displacement, splt->contents + 28);
8487 #else
8488 bfd_put_32 (output_bfd, got_displacement, splt->contents + 16);
8489 #endif
8493 /* UnixWare sets the entsize of .plt to 4, although that doesn't
8494 really seem like the right value. */
8495 elf_section_data (splt->output_section)->this_hdr.sh_entsize = 4;
8497 if (htab->vxworks_p && !info->shared && htab->splt->size > 0)
8499 /* Correct the .rel(a).plt.unloaded relocations. They will have
8500 incorrect symbol indexes. */
8501 int num_plts;
8502 unsigned char *p;
8504 num_plts = ((htab->splt->size - htab->plt_header_size)
8505 / htab->plt_entry_size);
8506 p = htab->srelplt2->contents + RELOC_SIZE (htab);
8508 for (; num_plts; num_plts--)
8510 Elf_Internal_Rela rel;
8512 SWAP_RELOC_IN (htab) (output_bfd, p, &rel);
8513 rel.r_info = ELF32_R_INFO (htab->root.hgot->indx, R_ARM_ABS32);
8514 SWAP_RELOC_OUT (htab) (output_bfd, &rel, p);
8515 p += RELOC_SIZE (htab);
8517 SWAP_RELOC_IN (htab) (output_bfd, p, &rel);
8518 rel.r_info = ELF32_R_INFO (htab->root.hplt->indx, R_ARM_ABS32);
8519 SWAP_RELOC_OUT (htab) (output_bfd, &rel, p);
8520 p += RELOC_SIZE (htab);
8525 /* Fill in the first three entries in the global offset table. */
8526 if (sgot)
8528 if (sgot->size > 0)
8530 if (sdyn == NULL)
8531 bfd_put_32 (output_bfd, (bfd_vma) 0, sgot->contents);
8532 else
8533 bfd_put_32 (output_bfd,
8534 sdyn->output_section->vma + sdyn->output_offset,
8535 sgot->contents);
8536 bfd_put_32 (output_bfd, (bfd_vma) 0, sgot->contents + 4);
8537 bfd_put_32 (output_bfd, (bfd_vma) 0, sgot->contents + 8);
8540 elf_section_data (sgot->output_section)->this_hdr.sh_entsize = 4;
8543 return TRUE;
8546 static void
8547 elf32_arm_post_process_headers (bfd * abfd, struct bfd_link_info * link_info ATTRIBUTE_UNUSED)
8549 Elf_Internal_Ehdr * i_ehdrp; /* ELF file header, internal form. */
8550 struct elf32_arm_link_hash_table *globals;
8552 i_ehdrp = elf_elfheader (abfd);
8554 if (EF_ARM_EABI_VERSION (i_ehdrp->e_flags) == EF_ARM_EABI_UNKNOWN)
8555 i_ehdrp->e_ident[EI_OSABI] = ELFOSABI_ARM;
8556 else
8557 i_ehdrp->e_ident[EI_OSABI] = 0;
8558 i_ehdrp->e_ident[EI_ABIVERSION] = ARM_ELF_ABI_VERSION;
8560 if (link_info)
8562 globals = elf32_arm_hash_table (link_info);
8563 if (globals->byteswap_code)
8564 i_ehdrp->e_flags |= EF_ARM_BE8;
8568 static enum elf_reloc_type_class
8569 elf32_arm_reloc_type_class (const Elf_Internal_Rela *rela)
8571 switch ((int) ELF32_R_TYPE (rela->r_info))
8573 case R_ARM_RELATIVE:
8574 return reloc_class_relative;
8575 case R_ARM_JUMP_SLOT:
8576 return reloc_class_plt;
8577 case R_ARM_COPY:
8578 return reloc_class_copy;
8579 default:
8580 return reloc_class_normal;
8584 /* Set the right machine number for an Arm ELF file. */
8586 static bfd_boolean
8587 elf32_arm_section_flags (flagword *flags, const Elf_Internal_Shdr *hdr)
8589 if (hdr->sh_type == SHT_NOTE)
8590 *flags |= SEC_LINK_ONCE | SEC_LINK_DUPLICATES_SAME_CONTENTS;
8592 return TRUE;
8595 static void
8596 elf32_arm_final_write_processing (bfd *abfd, bfd_boolean linker ATTRIBUTE_UNUSED)
8598 bfd_arm_update_notes (abfd, ARM_NOTE_SECTION);
8601 /* Return TRUE if this is an unwinding table entry. */
8603 static bfd_boolean
8604 is_arm_elf_unwind_section_name (bfd * abfd ATTRIBUTE_UNUSED, const char * name)
8606 size_t len1, len2;
8608 len1 = sizeof (ELF_STRING_ARM_unwind) - 1;
8609 len2 = sizeof (ELF_STRING_ARM_unwind_once) - 1;
8610 return (strncmp (name, ELF_STRING_ARM_unwind, len1) == 0
8611 || strncmp (name, ELF_STRING_ARM_unwind_once, len2) == 0);
8615 /* Set the type and flags for an ARM section. We do this by
8616 the section name, which is a hack, but ought to work. */
8618 static bfd_boolean
8619 elf32_arm_fake_sections (bfd * abfd, Elf_Internal_Shdr * hdr, asection * sec)
8621 const char * name;
8623 name = bfd_get_section_name (abfd, sec);
8625 if (is_arm_elf_unwind_section_name (abfd, name))
8627 hdr->sh_type = SHT_ARM_EXIDX;
8628 hdr->sh_flags |= SHF_LINK_ORDER;
8630 else if (strcmp(name, ".ARM.attributes") == 0)
8632 hdr->sh_type = SHT_ARM_ATTRIBUTES;
8634 return TRUE;
8637 /* Parse an Arm EABI attributes section. */
8638 static void
8639 elf32_arm_parse_attributes (bfd *abfd, Elf_Internal_Shdr * hdr)
8641 bfd_byte *contents;
8642 bfd_byte *p;
8643 bfd_vma len;
8645 contents = bfd_malloc (hdr->sh_size);
8646 if (!contents)
8647 return;
8648 if (!bfd_get_section_contents (abfd, hdr->bfd_section, contents, 0,
8649 hdr->sh_size))
8651 free (contents);
8652 return;
8654 p = contents;
8655 if (*(p++) == 'A')
8657 len = hdr->sh_size - 1;
8658 while (len > 0)
8660 int namelen;
8661 bfd_vma section_len;
8663 section_len = bfd_get_32 (abfd, p);
8664 p += 4;
8665 if (section_len > len)
8666 section_len = len;
8667 len -= section_len;
8668 namelen = strlen ((char *)p) + 1;
8669 section_len -= namelen + 4;
8670 if (strcmp((char *)p, "aeabi") != 0)
8672 /* Vendor section. Ignore it. */
8673 p += namelen + section_len;
8675 else
8677 p += namelen;
8678 while (section_len > 0)
8680 int tag;
8681 unsigned int n;
8682 unsigned int val;
8683 bfd_vma subsection_len;
8684 bfd_byte *end;
8686 tag = read_unsigned_leb128 (abfd, p, &n);
8687 p += n;
8688 subsection_len = bfd_get_32 (abfd, p);
8689 p += 4;
8690 if (subsection_len > section_len)
8691 subsection_len = section_len;
8692 section_len -= subsection_len;
8693 subsection_len -= n + 4;
8694 end = p + subsection_len;
8695 switch (tag)
8697 case Tag_File:
8698 while (p < end)
8700 bfd_boolean is_string;
8702 tag = read_unsigned_leb128 (abfd, p, &n);
8703 p += n;
8704 if (tag == 4 || tag == 5)
8705 is_string = 1;
8706 else if (tag < 32)
8707 is_string = 0;
8708 else
8709 is_string = (tag & 1) != 0;
8710 if (tag == Tag_compatibility)
8712 val = read_unsigned_leb128 (abfd, p, &n);
8713 p += n;
8714 elf32_arm_add_eabi_attr_compat (abfd, val,
8715 (char *)p);
8716 p += strlen ((char *)p) + 1;
8718 else if (is_string)
8720 elf32_arm_add_eabi_attr_string (abfd, tag,
8721 (char *)p);
8722 p += strlen ((char *)p) + 1;
8724 else
8726 val = read_unsigned_leb128 (abfd, p, &n);
8727 p += n;
8728 elf32_arm_add_eabi_attr_int (abfd, tag, val);
8731 break;
8732 case Tag_Section:
8733 case Tag_Symbol:
8734 /* Don't have anywhere convenient to attach these.
8735 Fall through for now. */
8736 default:
8737 /* Ignore things we don't kow about. */
8738 p += subsection_len;
8739 subsection_len = 0;
8740 break;
8746 free (contents);
8749 /* Handle an ARM specific section when reading an object file. This is
8750 called when bfd_section_from_shdr finds a section with an unknown
8751 type. */
8753 static bfd_boolean
8754 elf32_arm_section_from_shdr (bfd *abfd,
8755 Elf_Internal_Shdr * hdr,
8756 const char *name,
8757 int shindex)
8759 /* There ought to be a place to keep ELF backend specific flags, but
8760 at the moment there isn't one. We just keep track of the
8761 sections by their name, instead. Fortunately, the ABI gives
8762 names for all the ARM specific sections, so we will probably get
8763 away with this. */
8764 switch (hdr->sh_type)
8766 case SHT_ARM_EXIDX:
8767 case SHT_ARM_PREEMPTMAP:
8768 case SHT_ARM_ATTRIBUTES:
8769 break;
8771 default:
8772 return FALSE;
8775 if (! _bfd_elf_make_section_from_shdr (abfd, hdr, name, shindex))
8776 return FALSE;
8778 if (hdr->sh_type == SHT_ARM_ATTRIBUTES)
8779 elf32_arm_parse_attributes(abfd, hdr);
8780 return TRUE;
8783 /* A structure used to record a list of sections, independently
8784 of the next and prev fields in the asection structure. */
8785 typedef struct section_list
8787 asection * sec;
8788 struct section_list * next;
8789 struct section_list * prev;
8791 section_list;
8793 /* Unfortunately we need to keep a list of sections for which
8794 an _arm_elf_section_data structure has been allocated. This
8795 is because it is possible for functions like elf32_arm_write_section
8796 to be called on a section which has had an elf_data_structure
8797 allocated for it (and so the used_by_bfd field is valid) but
8798 for which the ARM extended version of this structure - the
8799 _arm_elf_section_data structure - has not been allocated. */
8800 static section_list * sections_with_arm_elf_section_data = NULL;
8802 static void
8803 record_section_with_arm_elf_section_data (asection * sec)
8805 struct section_list * entry;
8807 entry = bfd_malloc (sizeof (* entry));
8808 if (entry == NULL)
8809 return;
8810 entry->sec = sec;
8811 entry->next = sections_with_arm_elf_section_data;
8812 entry->prev = NULL;
8813 if (entry->next != NULL)
8814 entry->next->prev = entry;
8815 sections_with_arm_elf_section_data = entry;
8818 static struct section_list *
8819 find_arm_elf_section_entry (asection * sec)
8821 struct section_list * entry;
8822 static struct section_list * last_entry = NULL;
8824 /* This is a short cut for the typical case where the sections are added
8825 to the sections_with_arm_elf_section_data list in forward order and
8826 then looked up here in backwards order. This makes a real difference
8827 to the ld-srec/sec64k.exp linker test. */
8828 entry = sections_with_arm_elf_section_data;
8829 if (last_entry != NULL)
8831 if (last_entry->sec == sec)
8832 entry = last_entry;
8833 else if (last_entry->next != NULL
8834 && last_entry->next->sec == sec)
8835 entry = last_entry->next;
8838 for (; entry; entry = entry->next)
8839 if (entry->sec == sec)
8840 break;
8842 if (entry)
8843 /* Record the entry prior to this one - it is the entry we are most
8844 likely to want to locate next time. Also this way if we have been
8845 called from unrecord_section_with_arm_elf_section_data() we will not
8846 be caching a pointer that is about to be freed. */
8847 last_entry = entry->prev;
8849 return entry;
8852 static _arm_elf_section_data *
8853 get_arm_elf_section_data (asection * sec)
8855 struct section_list * entry;
8857 entry = find_arm_elf_section_entry (sec);
8859 if (entry)
8860 return elf32_arm_section_data (entry->sec);
8861 else
8862 return NULL;
8865 static void
8866 unrecord_section_with_arm_elf_section_data (asection * sec)
8868 struct section_list * entry;
8870 entry = find_arm_elf_section_entry (sec);
8872 if (entry)
8874 if (entry->prev != NULL)
8875 entry->prev->next = entry->next;
8876 if (entry->next != NULL)
8877 entry->next->prev = entry->prev;
8878 if (entry == sections_with_arm_elf_section_data)
8879 sections_with_arm_elf_section_data = entry->next;
8880 free (entry);
8884 /* Called for each symbol. Builds a section map based on mapping symbols.
8885 Does not alter any of the symbols. */
8887 static bfd_boolean
8888 elf32_arm_output_symbol_hook (struct bfd_link_info *info,
8889 const char *name,
8890 Elf_Internal_Sym *elfsym,
8891 asection *input_sec,
8892 struct elf_link_hash_entry *h)
8894 int mapcount;
8895 elf32_arm_section_map *map;
8896 elf32_arm_section_map *newmap;
8897 _arm_elf_section_data *arm_data;
8898 struct elf32_arm_link_hash_table *globals;
8900 globals = elf32_arm_hash_table (info);
8901 if (globals->vxworks_p
8902 && !elf_vxworks_link_output_symbol_hook (info, name, elfsym,
8903 input_sec, h))
8904 return FALSE;
8906 /* Only do this on final link. */
8907 if (info->relocatable)
8908 return TRUE;
8910 /* Only build a map if we need to byteswap code. */
8911 if (!globals->byteswap_code)
8912 return TRUE;
8914 /* We only want mapping symbols. */
8915 if (!bfd_is_arm_special_symbol_name (name, BFD_ARM_SPECIAL_SYM_TYPE_MAP))
8916 return TRUE;
8918 /* If this section has not been allocated an _arm_elf_section_data
8919 structure then we cannot record anything. */
8920 arm_data = get_arm_elf_section_data (input_sec);
8921 if (arm_data == NULL)
8922 return TRUE;
8924 mapcount = arm_data->mapcount + 1;
8925 map = arm_data->map;
8927 /* TODO: This may be inefficient, but we probably don't usually have many
8928 mapping symbols per section. */
8929 newmap = bfd_realloc (map, mapcount * sizeof (* map));
8930 if (newmap != NULL)
8932 arm_data->map = newmap;
8933 arm_data->mapcount = mapcount;
8935 newmap[mapcount - 1].vma = elfsym->st_value;
8936 newmap[mapcount - 1].type = name[1];
8939 return TRUE;
8942 typedef struct
8944 void *finfo;
8945 struct bfd_link_info *info;
8946 int plt_shndx;
8947 bfd_vma plt_offset;
8948 bfd_boolean (*func) (void *, const char *, Elf_Internal_Sym *,
8949 asection *, struct elf_link_hash_entry *);
8950 } output_arch_syminfo;
8952 enum map_symbol_type
8954 ARM_MAP_ARM,
8955 ARM_MAP_THUMB,
8956 ARM_MAP_DATA
8960 /* Output a single PLT mapping symbol. */
8962 static bfd_boolean
8963 elf32_arm_ouput_plt_map_sym (output_arch_syminfo *osi,
8964 enum map_symbol_type type,
8965 bfd_vma offset)
8967 static const char *names[3] = {"$a", "$t", "$d"};
8968 struct elf32_arm_link_hash_table *htab;
8969 Elf_Internal_Sym sym;
8971 htab = elf32_arm_hash_table (osi->info);
8972 sym.st_value = osi->plt_offset + offset;
8973 sym.st_size = 0;
8974 sym.st_other = 0;
8975 sym.st_info = ELF_ST_INFO (STB_LOCAL, STT_NOTYPE);
8976 sym.st_shndx = osi->plt_shndx;
8977 if (!osi->func (osi->finfo, names[type], &sym, htab->splt, NULL))
8978 return FALSE;
8979 return TRUE;
8983 /* Output mapping symbols for PLT entries associated with H. */
8985 static bfd_boolean
8986 elf32_arm_output_plt_map (struct elf_link_hash_entry *h, void *inf)
8988 output_arch_syminfo *osi = (output_arch_syminfo *) inf;
8989 struct elf32_arm_link_hash_table *htab;
8990 struct elf32_arm_link_hash_entry *eh;
8991 bfd_vma addr;
8993 htab = elf32_arm_hash_table (osi->info);
8995 if (h->root.type == bfd_link_hash_indirect)
8996 return TRUE;
8998 if (h->root.type == bfd_link_hash_warning)
8999 /* When warning symbols are created, they **replace** the "real"
9000 entry in the hash table, thus we never get to see the real
9001 symbol in a hash traversal. So look at it now. */
9002 h = (struct elf_link_hash_entry *) h->root.u.i.link;
9004 if (h->plt.offset == (bfd_vma) -1)
9005 return TRUE;
9007 eh = (struct elf32_arm_link_hash_entry *) h;
9008 addr = h->plt.offset;
9009 if (htab->symbian_p)
9011 if (!elf32_arm_ouput_plt_map_sym (osi, ARM_MAP_ARM, addr))
9012 return FALSE;
9013 if (!elf32_arm_ouput_plt_map_sym (osi, ARM_MAP_DATA, addr + 4))
9014 return FALSE;
9016 else if (htab->vxworks_p)
9018 if (!elf32_arm_ouput_plt_map_sym (osi, ARM_MAP_ARM, addr))
9019 return FALSE;
9020 if (!elf32_arm_ouput_plt_map_sym (osi, ARM_MAP_DATA, addr + 8))
9021 return FALSE;
9022 if (!elf32_arm_ouput_plt_map_sym (osi, ARM_MAP_ARM, addr + 12))
9023 return FALSE;
9024 if (!elf32_arm_ouput_plt_map_sym (osi, ARM_MAP_DATA, addr + 20))
9025 return FALSE;
9027 else
9029 bfd_boolean thumb_stub;
9031 thumb_stub = eh->plt_thumb_refcount > 0 && !htab->use_blx;
9032 if (thumb_stub)
9034 if (!elf32_arm_ouput_plt_map_sym (osi, ARM_MAP_THUMB, addr - 4))
9035 return FALSE;
9037 #ifdef FOUR_WORD_PLT
9038 if (!elf32_arm_ouput_plt_map_sym (osi, ARM_MAP_ARM, addr))
9039 return FALSE;
9040 if (!elf32_arm_ouput_plt_map_sym (osi, ARM_MAP_DATA, addr + 12))
9041 return FALSE;
9042 #else
9043 /* A three-word PLT with no Thumb thunk contains only Arm code,
9044 so only need to output a mapping symbol for the first PLT entry and
9045 entries with thumb thunks. */
9046 if (thumb_stub || addr == 20)
9048 if (!elf32_arm_ouput_plt_map_sym (osi, ARM_MAP_ARM, addr))
9049 return FALSE;
9051 #endif
9054 return TRUE;
9058 /* Output mapping symbols for the PLT. */
9060 static bfd_boolean
9061 elf32_arm_output_arch_local_syms (bfd *output_bfd,
9062 struct bfd_link_info *info,
9063 void *finfo, bfd_boolean (*func) (void *, const char *,
9064 Elf_Internal_Sym *,
9065 asection *,
9066 struct elf_link_hash_entry *))
9068 output_arch_syminfo osi;
9069 struct elf32_arm_link_hash_table *htab;
9071 htab = elf32_arm_hash_table (info);
9072 if (!htab->splt || htab->splt->size == 0)
9073 return TRUE;
9075 check_use_blx(htab);
9076 osi.finfo = finfo;
9077 osi.info = info;
9078 osi.func = func;
9079 osi.plt_shndx = _bfd_elf_section_from_bfd_section (output_bfd,
9080 htab->splt->output_section);
9081 osi.plt_offset = htab->splt->output_section->vma;
9083 /* Output mapping symbols for the plt header. SymbianOS does not have a
9084 plt header. */
9085 if (htab->vxworks_p)
9087 /* VxWorks shared libraries have no PLT header. */
9088 if (!info->shared)
9090 if (!elf32_arm_ouput_plt_map_sym (&osi, ARM_MAP_ARM, 0))
9091 return FALSE;
9092 if (!elf32_arm_ouput_plt_map_sym (&osi, ARM_MAP_DATA, 12))
9093 return FALSE;
9096 else if (!htab->symbian_p)
9098 if (!elf32_arm_ouput_plt_map_sym (&osi, ARM_MAP_ARM, 0))
9099 return FALSE;
9100 #ifndef FOUR_WORD_PLT
9101 if (!elf32_arm_ouput_plt_map_sym (&osi, ARM_MAP_DATA, 16))
9102 return FALSE;
9103 #endif
9106 elf_link_hash_traverse (&htab->root, elf32_arm_output_plt_map, (void *) &osi);
9107 return TRUE;
9110 /* Allocate target specific section data. */
9112 static bfd_boolean
9113 elf32_arm_new_section_hook (bfd *abfd, asection *sec)
9115 if (!sec->used_by_bfd)
9117 _arm_elf_section_data *sdata;
9118 bfd_size_type amt = sizeof (*sdata);
9120 sdata = bfd_zalloc (abfd, amt);
9121 if (sdata == NULL)
9122 return FALSE;
9123 sec->used_by_bfd = sdata;
9126 record_section_with_arm_elf_section_data (sec);
9128 return _bfd_elf_new_section_hook (abfd, sec);
9132 /* Used to order a list of mapping symbols by address. */
9134 static int
9135 elf32_arm_compare_mapping (const void * a, const void * b)
9137 return ((const elf32_arm_section_map *) a)->vma
9138 > ((const elf32_arm_section_map *) b)->vma;
9142 /* Do code byteswapping. Return FALSE afterwards so that the section is
9143 written out as normal. */
9145 static bfd_boolean
9146 elf32_arm_write_section (bfd *output_bfd ATTRIBUTE_UNUSED, asection *sec,
9147 bfd_byte *contents)
9149 int mapcount;
9150 _arm_elf_section_data *arm_data;
9151 elf32_arm_section_map *map;
9152 bfd_vma ptr;
9153 bfd_vma end;
9154 bfd_vma offset;
9155 bfd_byte tmp;
9156 int i;
9158 /* If this section has not been allocated an _arm_elf_section_data
9159 structure then we cannot record anything. */
9160 arm_data = get_arm_elf_section_data (sec);
9161 if (arm_data == NULL)
9162 return FALSE;
9164 mapcount = arm_data->mapcount;
9165 map = arm_data->map;
9167 if (mapcount == 0)
9168 return FALSE;
9170 qsort (map, mapcount, sizeof (* map), elf32_arm_compare_mapping);
9172 offset = sec->output_section->vma + sec->output_offset;
9173 ptr = map[0].vma - offset;
9174 for (i = 0; i < mapcount; i++)
9176 if (i == mapcount - 1)
9177 end = sec->size;
9178 else
9179 end = map[i + 1].vma - offset;
9181 switch (map[i].type)
9183 case 'a':
9184 /* Byte swap code words. */
9185 while (ptr + 3 < end)
9187 tmp = contents[ptr];
9188 contents[ptr] = contents[ptr + 3];
9189 contents[ptr + 3] = tmp;
9190 tmp = contents[ptr + 1];
9191 contents[ptr + 1] = contents[ptr + 2];
9192 contents[ptr + 2] = tmp;
9193 ptr += 4;
9195 break;
9197 case 't':
9198 /* Byte swap code halfwords. */
9199 while (ptr + 1 < end)
9201 tmp = contents[ptr];
9202 contents[ptr] = contents[ptr + 1];
9203 contents[ptr + 1] = tmp;
9204 ptr += 2;
9206 break;
9208 case 'd':
9209 /* Leave data alone. */
9210 break;
9212 ptr = end;
9215 free (map);
9216 arm_data->mapcount = 0;
9217 arm_data->map = NULL;
9218 unrecord_section_with_arm_elf_section_data (sec);
9220 return FALSE;
9223 static void
9224 unrecord_section_via_map_over_sections (bfd * abfd ATTRIBUTE_UNUSED,
9225 asection * sec,
9226 void * ignore ATTRIBUTE_UNUSED)
9228 unrecord_section_with_arm_elf_section_data (sec);
9231 static bfd_boolean
9232 elf32_arm_close_and_cleanup (bfd * abfd)
9234 if (abfd->sections)
9235 bfd_map_over_sections (abfd,
9236 unrecord_section_via_map_over_sections,
9237 NULL);
9239 return _bfd_elf_close_and_cleanup (abfd);
9242 static bfd_boolean
9243 elf32_arm_bfd_free_cached_info (bfd * abfd)
9245 if (abfd->sections)
9246 bfd_map_over_sections (abfd,
9247 unrecord_section_via_map_over_sections,
9248 NULL);
9250 return _bfd_free_cached_info (abfd);
9253 /* Display STT_ARM_TFUNC symbols as functions. */
9255 static void
9256 elf32_arm_symbol_processing (bfd *abfd ATTRIBUTE_UNUSED,
9257 asymbol *asym)
9259 elf_symbol_type *elfsym = (elf_symbol_type *) asym;
9261 if (ELF_ST_TYPE (elfsym->internal_elf_sym.st_info) == STT_ARM_TFUNC)
9262 elfsym->symbol.flags |= BSF_FUNCTION;
9266 /* Mangle thumb function symbols as we read them in. */
9268 static void
9269 elf32_arm_swap_symbol_in (bfd * abfd,
9270 const void *psrc,
9271 const void *pshn,
9272 Elf_Internal_Sym *dst)
9274 bfd_elf32_swap_symbol_in (abfd, psrc, pshn, dst);
9276 /* New EABI objects mark thumb function symbols by setting the low bit of
9277 the address. Turn these into STT_ARM_TFUNC. */
9278 if (ELF_ST_TYPE (dst->st_info) == STT_FUNC
9279 && (dst->st_value & 1))
9281 dst->st_info = ELF_ST_INFO (ELF_ST_BIND (dst->st_info), STT_ARM_TFUNC);
9282 dst->st_value &= ~(bfd_vma) 1;
9287 /* Mangle thumb function symbols as we write them out. */
9289 static void
9290 elf32_arm_swap_symbol_out (bfd *abfd,
9291 const Elf_Internal_Sym *src,
9292 void *cdst,
9293 void *shndx)
9295 Elf_Internal_Sym newsym;
9297 /* We convert STT_ARM_TFUNC symbols into STT_FUNC with the low bit
9298 of the address set, as per the new EABI. We do this unconditionally
9299 because objcopy does not set the elf header flags until after
9300 it writes out the symbol table. */
9301 if (ELF_ST_TYPE (src->st_info) == STT_ARM_TFUNC)
9303 newsym = *src;
9304 newsym.st_info = ELF_ST_INFO (ELF_ST_BIND (src->st_info), STT_FUNC);
9305 if (newsym.st_shndx != SHN_UNDEF)
9307 /* Do this only for defined symbols. At link type, the static
9308 linker will simulate the work of dynamic linker of resolving
9309 symbols and will carry over the thumbness of found symbols to
9310 the output symbol table. It's not clear how it happens, but
9311 the thumbness of underfined symbols can well be different at
9312 runtime, and writing '1' for them will be confusing for users
9313 and possibly for dynamic linker itself.
9315 newsym.st_value |= 1;
9318 newsym.st_value |= 1;
9320 src = &newsym;
9322 bfd_elf32_swap_symbol_out (abfd, src, cdst, shndx);
9325 /* Add the PT_ARM_EXIDX program header. */
9327 static bfd_boolean
9328 elf32_arm_modify_segment_map (bfd *abfd,
9329 struct bfd_link_info *info ATTRIBUTE_UNUSED)
9331 struct elf_segment_map *m;
9332 asection *sec;
9334 sec = bfd_get_section_by_name (abfd, ".ARM.exidx");
9335 if (sec != NULL && (sec->flags & SEC_LOAD) != 0)
9337 /* If there is already a PT_ARM_EXIDX header, then we do not
9338 want to add another one. This situation arises when running
9339 "strip"; the input binary already has the header. */
9340 m = elf_tdata (abfd)->segment_map;
9341 while (m && m->p_type != PT_ARM_EXIDX)
9342 m = m->next;
9343 if (!m)
9345 m = bfd_zalloc (abfd, sizeof (struct elf_segment_map));
9346 if (m == NULL)
9347 return FALSE;
9348 m->p_type = PT_ARM_EXIDX;
9349 m->count = 1;
9350 m->sections[0] = sec;
9352 m->next = elf_tdata (abfd)->segment_map;
9353 elf_tdata (abfd)->segment_map = m;
9357 return TRUE;
9360 /* We may add a PT_ARM_EXIDX program header. */
9362 static int
9363 elf32_arm_additional_program_headers (bfd *abfd,
9364 struct bfd_link_info *info ATTRIBUTE_UNUSED)
9366 asection *sec;
9368 sec = bfd_get_section_by_name (abfd, ".ARM.exidx");
9369 if (sec != NULL && (sec->flags & SEC_LOAD) != 0)
9370 return 1;
9371 else
9372 return 0;
9375 /* We use this to override swap_symbol_in and swap_symbol_out. */
9376 const struct elf_size_info elf32_arm_size_info = {
9377 sizeof (Elf32_External_Ehdr),
9378 sizeof (Elf32_External_Phdr),
9379 sizeof (Elf32_External_Shdr),
9380 sizeof (Elf32_External_Rel),
9381 sizeof (Elf32_External_Rela),
9382 sizeof (Elf32_External_Sym),
9383 sizeof (Elf32_External_Dyn),
9384 sizeof (Elf_External_Note),
9387 32, 2,
9388 ELFCLASS32, EV_CURRENT,
9389 bfd_elf32_write_out_phdrs,
9390 bfd_elf32_write_shdrs_and_ehdr,
9391 bfd_elf32_write_relocs,
9392 elf32_arm_swap_symbol_in,
9393 elf32_arm_swap_symbol_out,
9394 bfd_elf32_slurp_reloc_table,
9395 bfd_elf32_slurp_symbol_table,
9396 bfd_elf32_swap_dyn_in,
9397 bfd_elf32_swap_dyn_out,
9398 bfd_elf32_swap_reloc_in,
9399 bfd_elf32_swap_reloc_out,
9400 bfd_elf32_swap_reloca_in,
9401 bfd_elf32_swap_reloca_out
9404 #define ELF_ARCH bfd_arch_arm
9405 #define ELF_MACHINE_CODE EM_ARM
9406 #ifdef __QNXTARGET__
9407 #define ELF_MAXPAGESIZE 0x1000
9408 #else
9409 #define ELF_MAXPAGESIZE 0x8000
9410 #endif
9411 #define ELF_MINPAGESIZE 0x1000
9412 #define ELF_COMMONPAGESIZE 0x1000
9414 #define bfd_elf32_mkobject elf32_arm_mkobject
9416 #define bfd_elf32_bfd_copy_private_bfd_data elf32_arm_copy_private_bfd_data
9417 #define bfd_elf32_bfd_merge_private_bfd_data elf32_arm_merge_private_bfd_data
9418 #define bfd_elf32_bfd_set_private_flags elf32_arm_set_private_flags
9419 #define bfd_elf32_bfd_print_private_bfd_data elf32_arm_print_private_bfd_data
9420 #define bfd_elf32_bfd_link_hash_table_create elf32_arm_link_hash_table_create
9421 #define bfd_elf32_bfd_reloc_type_lookup elf32_arm_reloc_type_lookup
9422 #define bfd_elf32_find_nearest_line elf32_arm_find_nearest_line
9423 #define bfd_elf32_find_inliner_info elf32_arm_find_inliner_info
9424 #define bfd_elf32_new_section_hook elf32_arm_new_section_hook
9425 #define bfd_elf32_bfd_is_target_special_symbol elf32_arm_is_target_special_symbol
9426 #define bfd_elf32_close_and_cleanup elf32_arm_close_and_cleanup
9427 #define bfd_elf32_bfd_free_cached_info elf32_arm_bfd_free_cached_info
9428 #define bfd_elf32_bfd_final_link elf32_arm_bfd_final_link
9430 #define elf_backend_get_symbol_type elf32_arm_get_symbol_type
9431 #define elf_backend_gc_mark_hook elf32_arm_gc_mark_hook
9432 #define elf_backend_gc_sweep_hook elf32_arm_gc_sweep_hook
9433 #define elf_backend_check_relocs elf32_arm_check_relocs
9434 #define elf_backend_relocate_section elf32_arm_relocate_section
9435 #define elf_backend_write_section elf32_arm_write_section
9436 #define elf_backend_adjust_dynamic_symbol elf32_arm_adjust_dynamic_symbol
9437 #define elf_backend_create_dynamic_sections elf32_arm_create_dynamic_sections
9438 #define elf_backend_finish_dynamic_symbol elf32_arm_finish_dynamic_symbol
9439 #define elf_backend_finish_dynamic_sections elf32_arm_finish_dynamic_sections
9440 #define elf_backend_link_output_symbol_hook elf32_arm_output_symbol_hook
9441 #define elf_backend_size_dynamic_sections elf32_arm_size_dynamic_sections
9442 #define elf_backend_post_process_headers elf32_arm_post_process_headers
9443 #define elf_backend_reloc_type_class elf32_arm_reloc_type_class
9444 #define elf_backend_object_p elf32_arm_object_p
9445 #define elf_backend_section_flags elf32_arm_section_flags
9446 #define elf_backend_fake_sections elf32_arm_fake_sections
9447 #define elf_backend_section_from_shdr elf32_arm_section_from_shdr
9448 #define elf_backend_final_write_processing elf32_arm_final_write_processing
9449 #define elf_backend_copy_indirect_symbol elf32_arm_copy_indirect_symbol
9450 #define elf_backend_symbol_processing elf32_arm_symbol_processing
9451 #define elf_backend_size_info elf32_arm_size_info
9452 #define elf_backend_modify_segment_map elf32_arm_modify_segment_map
9453 #define elf_backend_additional_program_headers \
9454 elf32_arm_additional_program_headers
9455 #define elf_backend_output_arch_local_syms \
9456 elf32_arm_output_arch_local_syms
9457 #define elf_backend_begin_write_processing \
9458 elf32_arm_begin_write_processing
9460 #define elf_backend_can_refcount 1
9461 #define elf_backend_can_gc_sections 1
9462 #define elf_backend_plt_readonly 1
9463 #define elf_backend_want_got_plt 1
9464 #define elf_backend_want_plt_sym 0
9465 #define elf_backend_may_use_rel_p 1
9466 #define elf_backend_may_use_rela_p 0
9467 #define elf_backend_default_use_rela_p 0
9468 #define elf_backend_rela_normal 0
9470 #define elf_backend_got_header_size 12
9472 #include "elf32-target.h"
9474 /* VxWorks Targets */
9476 #undef TARGET_LITTLE_SYM
9477 #define TARGET_LITTLE_SYM bfd_elf32_littlearm_vxworks_vec
9478 #undef TARGET_LITTLE_NAME
9479 #define TARGET_LITTLE_NAME "elf32-littlearm-vxworks"
9480 #undef TARGET_BIG_SYM
9481 #define TARGET_BIG_SYM bfd_elf32_bigarm_vxworks_vec
9482 #undef TARGET_BIG_NAME
9483 #define TARGET_BIG_NAME "elf32-bigarm-vxworks"
9485 /* Like elf32_arm_link_hash_table_create -- but overrides
9486 appropriately for VxWorks. */
9487 static struct bfd_link_hash_table *
9488 elf32_arm_vxworks_link_hash_table_create (bfd *abfd)
9490 struct bfd_link_hash_table *ret;
9492 ret = elf32_arm_link_hash_table_create (abfd);
9493 if (ret)
9495 struct elf32_arm_link_hash_table *htab
9496 = (struct elf32_arm_link_hash_table *) ret;
9497 htab->use_rel = 0;
9498 htab->vxworks_p = 1;
9500 return ret;
9503 static void
9504 elf32_arm_vxworks_final_write_processing (bfd *abfd, bfd_boolean linker)
9506 elf32_arm_final_write_processing (abfd, linker);
9507 elf_vxworks_final_write_processing (abfd, linker);
9510 #undef elf32_bed
9511 #define elf32_bed elf32_arm_vxworks_bed
9513 #undef bfd_elf32_bfd_link_hash_table_create
9514 #define bfd_elf32_bfd_link_hash_table_create \
9515 elf32_arm_vxworks_link_hash_table_create
9516 #undef elf_backend_add_symbol_hook
9517 #define elf_backend_add_symbol_hook \
9518 elf_vxworks_add_symbol_hook
9519 #undef elf_backend_final_write_processing
9520 #define elf_backend_final_write_processing \
9521 elf32_arm_vxworks_final_write_processing
9522 #undef elf_backend_emit_relocs
9523 #define elf_backend_emit_relocs \
9524 elf_vxworks_emit_relocs
9526 #undef elf_backend_may_use_rel_p
9527 #define elf_backend_may_use_rel_p 0
9528 #undef elf_backend_may_use_rela_p
9529 #define elf_backend_may_use_rela_p 1
9530 #undef elf_backend_default_use_rela_p
9531 #define elf_backend_default_use_rela_p 1
9532 #undef elf_backend_rela_normal
9533 #define elf_backend_rela_normal 1
9534 #undef elf_backend_want_plt_sym
9535 #define elf_backend_want_plt_sym 1
9536 #undef ELF_MAXPAGESIZE
9537 #define ELF_MAXPAGESIZE 0x1000
9539 #include "elf32-target.h"
9542 /* Symbian OS Targets */
9544 #undef TARGET_LITTLE_SYM
9545 #define TARGET_LITTLE_SYM bfd_elf32_littlearm_symbian_vec
9546 #undef TARGET_LITTLE_NAME
9547 #define TARGET_LITTLE_NAME "elf32-littlearm-symbian"
9548 #undef TARGET_BIG_SYM
9549 #define TARGET_BIG_SYM bfd_elf32_bigarm_symbian_vec
9550 #undef TARGET_BIG_NAME
9551 #define TARGET_BIG_NAME "elf32-bigarm-symbian"
9553 /* Like elf32_arm_link_hash_table_create -- but overrides
9554 appropriately for Symbian OS. */
9555 static struct bfd_link_hash_table *
9556 elf32_arm_symbian_link_hash_table_create (bfd *abfd)
9558 struct bfd_link_hash_table *ret;
9560 ret = elf32_arm_link_hash_table_create (abfd);
9561 if (ret)
9563 struct elf32_arm_link_hash_table *htab
9564 = (struct elf32_arm_link_hash_table *)ret;
9565 /* There is no PLT header for Symbian OS. */
9566 htab->plt_header_size = 0;
9567 /* The PLT entries are each three instructions. */
9568 htab->plt_entry_size = 4 * NUM_ELEM (elf32_arm_symbian_plt_entry);
9569 htab->symbian_p = 1;
9570 /* Symbian uses armv5t or above, so use_blx is always true. */
9571 htab->use_blx = 1;
9572 htab->root.is_relocatable_executable = 1;
9574 return ret;
9577 static const struct bfd_elf_special_section
9578 elf32_arm_symbian_special_sections[] =
9580 /* In a BPABI executable, the dynamic linking sections do not go in
9581 the loadable read-only segment. The post-linker may wish to
9582 refer to these sections, but they are not part of the final
9583 program image. */
9584 { ".dynamic", 8, 0, SHT_DYNAMIC, 0 },
9585 { ".dynstr", 7, 0, SHT_STRTAB, 0 },
9586 { ".dynsym", 7, 0, SHT_DYNSYM, 0 },
9587 { ".got", 4, 0, SHT_PROGBITS, 0 },
9588 { ".hash", 5, 0, SHT_HASH, 0 },
9589 /* These sections do not need to be writable as the SymbianOS
9590 postlinker will arrange things so that no dynamic relocation is
9591 required. */
9592 { ".init_array", 11, 0, SHT_INIT_ARRAY, SHF_ALLOC },
9593 { ".fini_array", 11, 0, SHT_FINI_ARRAY, SHF_ALLOC },
9594 { ".preinit_array", 14, 0, SHT_PREINIT_ARRAY, SHF_ALLOC },
9595 { NULL, 0, 0, 0, 0 }
9598 static void
9599 elf32_arm_symbian_begin_write_processing (bfd *abfd,
9600 struct bfd_link_info *link_info)
9602 /* BPABI objects are never loaded directly by an OS kernel; they are
9603 processed by a postlinker first, into an OS-specific format. If
9604 the D_PAGED bit is set on the file, BFD will align segments on
9605 page boundaries, so that an OS can directly map the file. With
9606 BPABI objects, that just results in wasted space. In addition,
9607 because we clear the D_PAGED bit, map_sections_to_segments will
9608 recognize that the program headers should not be mapped into any
9609 loadable segment. */
9610 abfd->flags &= ~D_PAGED;
9611 elf32_arm_begin_write_processing(abfd, link_info);
9614 static bfd_boolean
9615 elf32_arm_symbian_modify_segment_map (bfd *abfd,
9616 struct bfd_link_info *info)
9618 struct elf_segment_map *m;
9619 asection *dynsec;
9621 /* BPABI shared libraries and executables should have a PT_DYNAMIC
9622 segment. However, because the .dynamic section is not marked
9623 with SEC_LOAD, the generic ELF code will not create such a
9624 segment. */
9625 dynsec = bfd_get_section_by_name (abfd, ".dynamic");
9626 if (dynsec)
9628 for (m = elf_tdata (abfd)->segment_map; m != NULL; m = m->next)
9629 if (m->p_type == PT_DYNAMIC)
9630 break;
9632 if (m == NULL)
9634 m = _bfd_elf_make_dynamic_segment (abfd, dynsec);
9635 m->next = elf_tdata (abfd)->segment_map;
9636 elf_tdata (abfd)->segment_map = m;
9640 /* Also call the generic arm routine. */
9641 return elf32_arm_modify_segment_map (abfd, info);
9644 #undef elf32_bed
9645 #define elf32_bed elf32_arm_symbian_bed
9647 /* The dynamic sections are not allocated on SymbianOS; the postlinker
9648 will process them and then discard them. */
9649 #undef ELF_DYNAMIC_SEC_FLAGS
9650 #define ELF_DYNAMIC_SEC_FLAGS \
9651 (SEC_HAS_CONTENTS | SEC_IN_MEMORY | SEC_LINKER_CREATED)
9653 #undef bfd_elf32_bfd_link_hash_table_create
9654 #define bfd_elf32_bfd_link_hash_table_create \
9655 elf32_arm_symbian_link_hash_table_create
9656 #undef elf_backend_add_symbol_hook
9658 #undef elf_backend_special_sections
9659 #define elf_backend_special_sections elf32_arm_symbian_special_sections
9661 #undef elf_backend_begin_write_processing
9662 #define elf_backend_begin_write_processing \
9663 elf32_arm_symbian_begin_write_processing
9664 #undef elf_backend_final_write_processing
9665 #define elf_backend_final_write_processing \
9666 elf32_arm_final_write_processing
9667 #undef elf_backend_emit_relocs
9669 #undef elf_backend_modify_segment_map
9670 #define elf_backend_modify_segment_map elf32_arm_symbian_modify_segment_map
9672 /* There is no .got section for BPABI objects, and hence no header. */
9673 #undef elf_backend_got_header_size
9674 #define elf_backend_got_header_size 0
9676 /* Similarly, there is no .got.plt section. */
9677 #undef elf_backend_want_got_plt
9678 #define elf_backend_want_got_plt 0
9680 #undef elf_backend_may_use_rel_p
9681 #define elf_backend_may_use_rel_p 1
9682 #undef elf_backend_may_use_rela_p
9683 #define elf_backend_may_use_rela_p 0
9684 #undef elf_backend_default_use_rela_p
9685 #define elf_backend_default_use_rela_p 0
9686 #undef elf_backend_rela_normal
9687 #define elf_backend_rela_normal 0
9688 #undef elf_backend_want_plt_sym
9689 #define elf_backend_want_plt_sym 0
9690 #undef ELF_MAXPAGESIZE
9691 #define ELF_MAXPAGESIZE 0x8000
9693 #include "elf32-target.h"