bfd/
[binutils.git] / bfd / elf32-arm.c
blob881bd6013e944e2649a28b79f5830a420613e0ba
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 HOWTO (R_ARM_THM_CALL, /* type */
221 1, /* rightshift */
222 2, /* size (0 = byte, 1 = short, 2 = long) */
223 25, /* bitsize */
224 TRUE, /* pc_relative */
225 0, /* bitpos */
226 complain_overflow_signed,/* complain_on_overflow */
227 bfd_elf_generic_reloc, /* special_function */
228 "R_ARM_THM_CALL", /* name */
229 FALSE, /* partial_inplace */
230 0x07ff07ff, /* src_mask */
231 0x07ff07ff, /* dst_mask */
232 TRUE), /* pcrel_offset */
234 HOWTO (R_ARM_THM_PC8, /* type */
235 1, /* rightshift */
236 1, /* size (0 = byte, 1 = short, 2 = long) */
237 8, /* bitsize */
238 TRUE, /* pc_relative */
239 0, /* bitpos */
240 complain_overflow_signed,/* complain_on_overflow */
241 bfd_elf_generic_reloc, /* special_function */
242 "R_ARM_THM_PC8", /* name */
243 FALSE, /* partial_inplace */
244 0x000000ff, /* src_mask */
245 0x000000ff, /* dst_mask */
246 TRUE), /* pcrel_offset */
248 HOWTO (R_ARM_BREL_ADJ, /* type */
249 1, /* rightshift */
250 1, /* size (0 = byte, 1 = short, 2 = long) */
251 32, /* bitsize */
252 FALSE, /* pc_relative */
253 0, /* bitpos */
254 complain_overflow_signed,/* complain_on_overflow */
255 bfd_elf_generic_reloc, /* special_function */
256 "R_ARM_BREL_ADJ", /* name */
257 FALSE, /* partial_inplace */
258 0xffffffff, /* src_mask */
259 0xffffffff, /* dst_mask */
260 FALSE), /* pcrel_offset */
262 HOWTO (R_ARM_SWI24, /* type */
263 0, /* rightshift */
264 0, /* size (0 = byte, 1 = short, 2 = long) */
265 0, /* bitsize */
266 FALSE, /* pc_relative */
267 0, /* bitpos */
268 complain_overflow_signed,/* complain_on_overflow */
269 bfd_elf_generic_reloc, /* special_function */
270 "R_ARM_SWI24", /* name */
271 FALSE, /* partial_inplace */
272 0x00000000, /* src_mask */
273 0x00000000, /* dst_mask */
274 FALSE), /* pcrel_offset */
276 HOWTO (R_ARM_THM_SWI8, /* type */
277 0, /* rightshift */
278 0, /* size (0 = byte, 1 = short, 2 = long) */
279 0, /* bitsize */
280 FALSE, /* pc_relative */
281 0, /* bitpos */
282 complain_overflow_signed,/* complain_on_overflow */
283 bfd_elf_generic_reloc, /* special_function */
284 "R_ARM_SWI8", /* name */
285 FALSE, /* partial_inplace */
286 0x00000000, /* src_mask */
287 0x00000000, /* dst_mask */
288 FALSE), /* pcrel_offset */
290 /* BLX instruction for the ARM. */
291 HOWTO (R_ARM_XPC25, /* type */
292 2, /* rightshift */
293 2, /* size (0 = byte, 1 = short, 2 = long) */
294 25, /* bitsize */
295 TRUE, /* pc_relative */
296 0, /* bitpos */
297 complain_overflow_signed,/* complain_on_overflow */
298 bfd_elf_generic_reloc, /* special_function */
299 "R_ARM_XPC25", /* name */
300 FALSE, /* partial_inplace */
301 0x00ffffff, /* src_mask */
302 0x00ffffff, /* dst_mask */
303 TRUE), /* pcrel_offset */
305 /* BLX instruction for the Thumb. */
306 HOWTO (R_ARM_THM_XPC22, /* type */
307 2, /* rightshift */
308 2, /* size (0 = byte, 1 = short, 2 = long) */
309 22, /* bitsize */
310 TRUE, /* pc_relative */
311 0, /* bitpos */
312 complain_overflow_signed,/* complain_on_overflow */
313 bfd_elf_generic_reloc, /* special_function */
314 "R_ARM_THM_XPC22", /* name */
315 FALSE, /* partial_inplace */
316 0x07ff07ff, /* src_mask */
317 0x07ff07ff, /* dst_mask */
318 TRUE), /* pcrel_offset */
320 /* Dynamic TLS relocations. */
322 HOWTO (R_ARM_TLS_DTPMOD32, /* type */
323 0, /* rightshift */
324 2, /* size (0 = byte, 1 = short, 2 = long) */
325 32, /* bitsize */
326 FALSE, /* pc_relative */
327 0, /* bitpos */
328 complain_overflow_bitfield,/* complain_on_overflow */
329 bfd_elf_generic_reloc, /* special_function */
330 "R_ARM_TLS_DTPMOD32", /* name */
331 TRUE, /* partial_inplace */
332 0xffffffff, /* src_mask */
333 0xffffffff, /* dst_mask */
334 FALSE), /* pcrel_offset */
336 HOWTO (R_ARM_TLS_DTPOFF32, /* type */
337 0, /* rightshift */
338 2, /* size (0 = byte, 1 = short, 2 = long) */
339 32, /* bitsize */
340 FALSE, /* pc_relative */
341 0, /* bitpos */
342 complain_overflow_bitfield,/* complain_on_overflow */
343 bfd_elf_generic_reloc, /* special_function */
344 "R_ARM_TLS_DTPOFF32", /* name */
345 TRUE, /* partial_inplace */
346 0xffffffff, /* src_mask */
347 0xffffffff, /* dst_mask */
348 FALSE), /* pcrel_offset */
350 HOWTO (R_ARM_TLS_TPOFF32, /* type */
351 0, /* rightshift */
352 2, /* size (0 = byte, 1 = short, 2 = long) */
353 32, /* bitsize */
354 FALSE, /* pc_relative */
355 0, /* bitpos */
356 complain_overflow_bitfield,/* complain_on_overflow */
357 bfd_elf_generic_reloc, /* special_function */
358 "R_ARM_TLS_TPOFF32", /* name */
359 TRUE, /* partial_inplace */
360 0xffffffff, /* src_mask */
361 0xffffffff, /* dst_mask */
362 FALSE), /* pcrel_offset */
364 /* Relocs used in ARM Linux */
366 HOWTO (R_ARM_COPY, /* type */
367 0, /* rightshift */
368 2, /* size (0 = byte, 1 = short, 2 = long) */
369 32, /* bitsize */
370 FALSE, /* pc_relative */
371 0, /* bitpos */
372 complain_overflow_bitfield,/* complain_on_overflow */
373 bfd_elf_generic_reloc, /* special_function */
374 "R_ARM_COPY", /* name */
375 TRUE, /* partial_inplace */
376 0xffffffff, /* src_mask */
377 0xffffffff, /* dst_mask */
378 FALSE), /* pcrel_offset */
380 HOWTO (R_ARM_GLOB_DAT, /* type */
381 0, /* rightshift */
382 2, /* size (0 = byte, 1 = short, 2 = long) */
383 32, /* bitsize */
384 FALSE, /* pc_relative */
385 0, /* bitpos */
386 complain_overflow_bitfield,/* complain_on_overflow */
387 bfd_elf_generic_reloc, /* special_function */
388 "R_ARM_GLOB_DAT", /* name */
389 TRUE, /* partial_inplace */
390 0xffffffff, /* src_mask */
391 0xffffffff, /* dst_mask */
392 FALSE), /* pcrel_offset */
394 HOWTO (R_ARM_JUMP_SLOT, /* type */
395 0, /* rightshift */
396 2, /* size (0 = byte, 1 = short, 2 = long) */
397 32, /* bitsize */
398 FALSE, /* pc_relative */
399 0, /* bitpos */
400 complain_overflow_bitfield,/* complain_on_overflow */
401 bfd_elf_generic_reloc, /* special_function */
402 "R_ARM_JUMP_SLOT", /* name */
403 TRUE, /* partial_inplace */
404 0xffffffff, /* src_mask */
405 0xffffffff, /* dst_mask */
406 FALSE), /* pcrel_offset */
408 HOWTO (R_ARM_RELATIVE, /* type */
409 0, /* rightshift */
410 2, /* size (0 = byte, 1 = short, 2 = long) */
411 32, /* bitsize */
412 FALSE, /* pc_relative */
413 0, /* bitpos */
414 complain_overflow_bitfield,/* complain_on_overflow */
415 bfd_elf_generic_reloc, /* special_function */
416 "R_ARM_RELATIVE", /* name */
417 TRUE, /* partial_inplace */
418 0xffffffff, /* src_mask */
419 0xffffffff, /* dst_mask */
420 FALSE), /* pcrel_offset */
422 HOWTO (R_ARM_GOTOFF32, /* type */
423 0, /* rightshift */
424 2, /* size (0 = byte, 1 = short, 2 = long) */
425 32, /* bitsize */
426 FALSE, /* pc_relative */
427 0, /* bitpos */
428 complain_overflow_bitfield,/* complain_on_overflow */
429 bfd_elf_generic_reloc, /* special_function */
430 "R_ARM_GOTOFF32", /* name */
431 TRUE, /* partial_inplace */
432 0xffffffff, /* src_mask */
433 0xffffffff, /* dst_mask */
434 FALSE), /* pcrel_offset */
436 HOWTO (R_ARM_GOTPC, /* type */
437 0, /* rightshift */
438 2, /* size (0 = byte, 1 = short, 2 = long) */
439 32, /* bitsize */
440 TRUE, /* pc_relative */
441 0, /* bitpos */
442 complain_overflow_bitfield,/* complain_on_overflow */
443 bfd_elf_generic_reloc, /* special_function */
444 "R_ARM_GOTPC", /* name */
445 TRUE, /* partial_inplace */
446 0xffffffff, /* src_mask */
447 0xffffffff, /* dst_mask */
448 TRUE), /* pcrel_offset */
450 HOWTO (R_ARM_GOT32, /* type */
451 0, /* rightshift */
452 2, /* size (0 = byte, 1 = short, 2 = long) */
453 32, /* bitsize */
454 FALSE, /* pc_relative */
455 0, /* bitpos */
456 complain_overflow_bitfield,/* complain_on_overflow */
457 bfd_elf_generic_reloc, /* special_function */
458 "R_ARM_GOT32", /* name */
459 TRUE, /* partial_inplace */
460 0xffffffff, /* src_mask */
461 0xffffffff, /* dst_mask */
462 FALSE), /* pcrel_offset */
464 HOWTO (R_ARM_PLT32, /* type */
465 2, /* rightshift */
466 2, /* size (0 = byte, 1 = short, 2 = long) */
467 24, /* bitsize */
468 TRUE, /* pc_relative */
469 0, /* bitpos */
470 complain_overflow_bitfield,/* complain_on_overflow */
471 bfd_elf_generic_reloc, /* special_function */
472 "R_ARM_PLT32", /* name */
473 FALSE, /* partial_inplace */
474 0x00ffffff, /* src_mask */
475 0x00ffffff, /* dst_mask */
476 TRUE), /* pcrel_offset */
478 HOWTO (R_ARM_CALL, /* type */
479 2, /* rightshift */
480 2, /* size (0 = byte, 1 = short, 2 = long) */
481 24, /* bitsize */
482 TRUE, /* pc_relative */
483 0, /* bitpos */
484 complain_overflow_signed,/* complain_on_overflow */
485 bfd_elf_generic_reloc, /* special_function */
486 "R_ARM_CALL", /* name */
487 FALSE, /* partial_inplace */
488 0x00ffffff, /* src_mask */
489 0x00ffffff, /* dst_mask */
490 TRUE), /* pcrel_offset */
492 HOWTO (R_ARM_JUMP24, /* type */
493 2, /* rightshift */
494 2, /* size (0 = byte, 1 = short, 2 = long) */
495 24, /* bitsize */
496 TRUE, /* pc_relative */
497 0, /* bitpos */
498 complain_overflow_signed,/* complain_on_overflow */
499 bfd_elf_generic_reloc, /* special_function */
500 "R_ARM_JUMP24", /* name */
501 FALSE, /* partial_inplace */
502 0x00ffffff, /* src_mask */
503 0x00ffffff, /* dst_mask */
504 TRUE), /* pcrel_offset */
506 HOWTO (R_ARM_THM_JUMP24, /* type */
507 1, /* rightshift */
508 2, /* size (0 = byte, 1 = short, 2 = long) */
509 24, /* bitsize */
510 TRUE, /* pc_relative */
511 0, /* bitpos */
512 complain_overflow_signed,/* complain_on_overflow */
513 bfd_elf_generic_reloc, /* special_function */
514 "R_ARM_THM_JUMP24", /* name */
515 FALSE, /* partial_inplace */
516 0x07ff2fff, /* src_mask */
517 0x07ff2fff, /* dst_mask */
518 TRUE), /* pcrel_offset */
520 HOWTO (R_ARM_BASE_ABS, /* type */
521 0, /* rightshift */
522 2, /* size (0 = byte, 1 = short, 2 = long) */
523 32, /* bitsize */
524 FALSE, /* pc_relative */
525 0, /* bitpos */
526 complain_overflow_dont,/* complain_on_overflow */
527 bfd_elf_generic_reloc, /* special_function */
528 "R_ARM_BASE_ABS", /* name */
529 FALSE, /* partial_inplace */
530 0xffffffff, /* src_mask */
531 0xffffffff, /* dst_mask */
532 FALSE), /* pcrel_offset */
534 HOWTO (R_ARM_ALU_PCREL7_0, /* type */
535 0, /* rightshift */
536 2, /* size (0 = byte, 1 = short, 2 = long) */
537 12, /* bitsize */
538 TRUE, /* pc_relative */
539 0, /* bitpos */
540 complain_overflow_dont,/* complain_on_overflow */
541 bfd_elf_generic_reloc, /* special_function */
542 "R_ARM_ALU_PCREL_7_0", /* name */
543 FALSE, /* partial_inplace */
544 0x00000fff, /* src_mask */
545 0x00000fff, /* dst_mask */
546 TRUE), /* pcrel_offset */
548 HOWTO (R_ARM_ALU_PCREL15_8, /* type */
549 0, /* rightshift */
550 2, /* size (0 = byte, 1 = short, 2 = long) */
551 12, /* bitsize */
552 TRUE, /* pc_relative */
553 8, /* bitpos */
554 complain_overflow_dont,/* complain_on_overflow */
555 bfd_elf_generic_reloc, /* special_function */
556 "R_ARM_ALU_PCREL_15_8",/* name */
557 FALSE, /* partial_inplace */
558 0x00000fff, /* src_mask */
559 0x00000fff, /* dst_mask */
560 TRUE), /* pcrel_offset */
562 HOWTO (R_ARM_ALU_PCREL23_15, /* type */
563 0, /* rightshift */
564 2, /* size (0 = byte, 1 = short, 2 = long) */
565 12, /* bitsize */
566 TRUE, /* pc_relative */
567 16, /* bitpos */
568 complain_overflow_dont,/* complain_on_overflow */
569 bfd_elf_generic_reloc, /* special_function */
570 "R_ARM_ALU_PCREL_23_15",/* name */
571 FALSE, /* partial_inplace */
572 0x00000fff, /* src_mask */
573 0x00000fff, /* dst_mask */
574 TRUE), /* pcrel_offset */
576 HOWTO (R_ARM_LDR_SBREL_11_0, /* type */
577 0, /* rightshift */
578 2, /* size (0 = byte, 1 = short, 2 = long) */
579 12, /* bitsize */
580 FALSE, /* pc_relative */
581 0, /* bitpos */
582 complain_overflow_dont,/* complain_on_overflow */
583 bfd_elf_generic_reloc, /* special_function */
584 "R_ARM_LDR_SBREL_11_0",/* name */
585 FALSE, /* partial_inplace */
586 0x00000fff, /* src_mask */
587 0x00000fff, /* dst_mask */
588 FALSE), /* pcrel_offset */
590 HOWTO (R_ARM_ALU_SBREL_19_12, /* type */
591 0, /* rightshift */
592 2, /* size (0 = byte, 1 = short, 2 = long) */
593 8, /* bitsize */
594 FALSE, /* pc_relative */
595 12, /* bitpos */
596 complain_overflow_dont,/* complain_on_overflow */
597 bfd_elf_generic_reloc, /* special_function */
598 "R_ARM_ALU_SBREL_19_12",/* name */
599 FALSE, /* partial_inplace */
600 0x000ff000, /* src_mask */
601 0x000ff000, /* dst_mask */
602 FALSE), /* pcrel_offset */
604 HOWTO (R_ARM_ALU_SBREL_27_20, /* type */
605 0, /* rightshift */
606 2, /* size (0 = byte, 1 = short, 2 = long) */
607 8, /* bitsize */
608 FALSE, /* pc_relative */
609 20, /* bitpos */
610 complain_overflow_dont,/* complain_on_overflow */
611 bfd_elf_generic_reloc, /* special_function */
612 "R_ARM_ALU_SBREL_27_20",/* name */
613 FALSE, /* partial_inplace */
614 0x0ff00000, /* src_mask */
615 0x0ff00000, /* dst_mask */
616 FALSE), /* pcrel_offset */
618 HOWTO (R_ARM_TARGET1, /* type */
619 0, /* rightshift */
620 2, /* size (0 = byte, 1 = short, 2 = long) */
621 32, /* bitsize */
622 FALSE, /* pc_relative */
623 0, /* bitpos */
624 complain_overflow_dont,/* complain_on_overflow */
625 bfd_elf_generic_reloc, /* special_function */
626 "R_ARM_TARGET1", /* name */
627 FALSE, /* partial_inplace */
628 0xffffffff, /* src_mask */
629 0xffffffff, /* dst_mask */
630 FALSE), /* pcrel_offset */
632 HOWTO (R_ARM_ROSEGREL32, /* type */
633 0, /* rightshift */
634 2, /* size (0 = byte, 1 = short, 2 = long) */
635 32, /* bitsize */
636 FALSE, /* pc_relative */
637 0, /* bitpos */
638 complain_overflow_dont,/* complain_on_overflow */
639 bfd_elf_generic_reloc, /* special_function */
640 "R_ARM_ROSEGREL32", /* name */
641 FALSE, /* partial_inplace */
642 0xffffffff, /* src_mask */
643 0xffffffff, /* dst_mask */
644 FALSE), /* pcrel_offset */
646 HOWTO (R_ARM_V4BX, /* type */
647 0, /* rightshift */
648 2, /* size (0 = byte, 1 = short, 2 = long) */
649 32, /* bitsize */
650 FALSE, /* pc_relative */
651 0, /* bitpos */
652 complain_overflow_dont,/* complain_on_overflow */
653 bfd_elf_generic_reloc, /* special_function */
654 "R_ARM_V4BX", /* name */
655 FALSE, /* partial_inplace */
656 0xffffffff, /* src_mask */
657 0xffffffff, /* dst_mask */
658 FALSE), /* pcrel_offset */
660 HOWTO (R_ARM_TARGET2, /* type */
661 0, /* rightshift */
662 2, /* size (0 = byte, 1 = short, 2 = long) */
663 32, /* bitsize */
664 FALSE, /* pc_relative */
665 0, /* bitpos */
666 complain_overflow_signed,/* complain_on_overflow */
667 bfd_elf_generic_reloc, /* special_function */
668 "R_ARM_TARGET2", /* name */
669 FALSE, /* partial_inplace */
670 0xffffffff, /* src_mask */
671 0xffffffff, /* dst_mask */
672 TRUE), /* pcrel_offset */
674 HOWTO (R_ARM_PREL31, /* type */
675 0, /* rightshift */
676 2, /* size (0 = byte, 1 = short, 2 = long) */
677 31, /* bitsize */
678 TRUE, /* pc_relative */
679 0, /* bitpos */
680 complain_overflow_signed,/* complain_on_overflow */
681 bfd_elf_generic_reloc, /* special_function */
682 "R_ARM_PREL31", /* name */
683 FALSE, /* partial_inplace */
684 0x7fffffff, /* src_mask */
685 0x7fffffff, /* dst_mask */
686 TRUE), /* pcrel_offset */
688 HOWTO (R_ARM_MOVW_ABS_NC, /* type */
689 0, /* rightshift */
690 2, /* size (0 = byte, 1 = short, 2 = long) */
691 16, /* bitsize */
692 FALSE, /* pc_relative */
693 0, /* bitpos */
694 complain_overflow_dont,/* complain_on_overflow */
695 bfd_elf_generic_reloc, /* special_function */
696 "R_ARM_MOVW_ABS_NC", /* name */
697 FALSE, /* partial_inplace */
698 0x0000ffff, /* src_mask */
699 0x0000ffff, /* dst_mask */
700 FALSE), /* pcrel_offset */
702 HOWTO (R_ARM_MOVT_ABS, /* type */
703 0, /* rightshift */
704 2, /* size (0 = byte, 1 = short, 2 = long) */
705 16, /* bitsize */
706 FALSE, /* pc_relative */
707 0, /* bitpos */
708 complain_overflow_bitfield,/* complain_on_overflow */
709 bfd_elf_generic_reloc, /* special_function */
710 "R_ARM_MOVT_ABS", /* name */
711 FALSE, /* partial_inplace */
712 0x0000ffff, /* src_mask */
713 0x0000ffff, /* dst_mask */
714 FALSE), /* pcrel_offset */
716 HOWTO (R_ARM_MOVW_PREL_NC, /* type */
717 0, /* rightshift */
718 2, /* size (0 = byte, 1 = short, 2 = long) */
719 16, /* bitsize */
720 TRUE, /* pc_relative */
721 0, /* bitpos */
722 complain_overflow_dont,/* complain_on_overflow */
723 bfd_elf_generic_reloc, /* special_function */
724 "R_ARM_MOVW_PREL_NC", /* name */
725 FALSE, /* partial_inplace */
726 0x0000ffff, /* src_mask */
727 0x0000ffff, /* dst_mask */
728 TRUE), /* pcrel_offset */
730 HOWTO (R_ARM_MOVT_PREL, /* type */
731 0, /* rightshift */
732 2, /* size (0 = byte, 1 = short, 2 = long) */
733 16, /* bitsize */
734 TRUE, /* pc_relative */
735 0, /* bitpos */
736 complain_overflow_bitfield,/* complain_on_overflow */
737 bfd_elf_generic_reloc, /* special_function */
738 "R_ARM_MOVT_PREL", /* name */
739 FALSE, /* partial_inplace */
740 0x0000ffff, /* src_mask */
741 0x0000ffff, /* dst_mask */
742 TRUE), /* pcrel_offset */
744 HOWTO (R_ARM_THM_MOVW_ABS_NC, /* type */
745 0, /* rightshift */
746 2, /* size (0 = byte, 1 = short, 2 = long) */
747 16, /* bitsize */
748 FALSE, /* pc_relative */
749 0, /* bitpos */
750 complain_overflow_dont,/* complain_on_overflow */
751 bfd_elf_generic_reloc, /* special_function */
752 "R_ARM_THM_MOVW_ABS_NC",/* name */
753 FALSE, /* partial_inplace */
754 0x040f70ff, /* src_mask */
755 0x040f70ff, /* dst_mask */
756 FALSE), /* pcrel_offset */
758 HOWTO (R_ARM_THM_MOVT_ABS, /* type */
759 0, /* rightshift */
760 2, /* size (0 = byte, 1 = short, 2 = long) */
761 16, /* bitsize */
762 FALSE, /* pc_relative */
763 0, /* bitpos */
764 complain_overflow_bitfield,/* complain_on_overflow */
765 bfd_elf_generic_reloc, /* special_function */
766 "R_ARM_THM_MOVT_ABS", /* name */
767 FALSE, /* partial_inplace */
768 0x040f70ff, /* src_mask */
769 0x040f70ff, /* dst_mask */
770 FALSE), /* pcrel_offset */
772 HOWTO (R_ARM_THM_MOVW_PREL_NC,/* type */
773 0, /* rightshift */
774 2, /* size (0 = byte, 1 = short, 2 = long) */
775 16, /* bitsize */
776 TRUE, /* pc_relative */
777 0, /* bitpos */
778 complain_overflow_dont,/* complain_on_overflow */
779 bfd_elf_generic_reloc, /* special_function */
780 "R_ARM_THM_MOVW_PREL_NC",/* name */
781 FALSE, /* partial_inplace */
782 0x040f70ff, /* src_mask */
783 0x040f70ff, /* dst_mask */
784 TRUE), /* pcrel_offset */
786 HOWTO (R_ARM_THM_MOVT_PREL, /* type */
787 0, /* rightshift */
788 2, /* size (0 = byte, 1 = short, 2 = long) */
789 16, /* bitsize */
790 TRUE, /* pc_relative */
791 0, /* bitpos */
792 complain_overflow_bitfield,/* complain_on_overflow */
793 bfd_elf_generic_reloc, /* special_function */
794 "R_ARM_THM_MOVT_PREL", /* name */
795 FALSE, /* partial_inplace */
796 0x040f70ff, /* src_mask */
797 0x040f70ff, /* dst_mask */
798 TRUE), /* pcrel_offset */
800 HOWTO (R_ARM_THM_JUMP19, /* type */
801 1, /* rightshift */
802 2, /* size (0 = byte, 1 = short, 2 = long) */
803 19, /* bitsize */
804 TRUE, /* pc_relative */
805 0, /* bitpos */
806 complain_overflow_signed,/* complain_on_overflow */
807 bfd_elf_generic_reloc, /* special_function */
808 "R_ARM_THM_JUMP19", /* name */
809 FALSE, /* partial_inplace */
810 0x043f2fff, /* src_mask */
811 0x043f2fff, /* dst_mask */
812 TRUE), /* pcrel_offset */
814 HOWTO (R_ARM_THM_JUMP6, /* type */
815 1, /* rightshift */
816 1, /* size (0 = byte, 1 = short, 2 = long) */
817 6, /* bitsize */
818 TRUE, /* pc_relative */
819 0, /* bitpos */
820 complain_overflow_unsigned,/* complain_on_overflow */
821 bfd_elf_generic_reloc, /* special_function */
822 "R_ARM_THM_JUMP6", /* name */
823 FALSE, /* partial_inplace */
824 0x02f8, /* src_mask */
825 0x02f8, /* dst_mask */
826 TRUE), /* pcrel_offset */
828 /* These are declared as 13-bit signed relocations because we can
829 address -4095 .. 4095(base) by altering ADDW to SUBW or vice
830 versa. */
831 HOWTO (R_ARM_THM_ALU_PREL_11_0,/* type */
832 0, /* rightshift */
833 2, /* size (0 = byte, 1 = short, 2 = long) */
834 13, /* bitsize */
835 TRUE, /* pc_relative */
836 0, /* bitpos */
837 complain_overflow_dont,/* complain_on_overflow */
838 bfd_elf_generic_reloc, /* special_function */
839 "R_ARM_THM_ALU_PREL_11_0",/* name */
840 FALSE, /* partial_inplace */
841 0xffffffff, /* src_mask */
842 0xffffffff, /* dst_mask */
843 TRUE), /* pcrel_offset */
845 HOWTO (R_ARM_THM_PC12, /* type */
846 0, /* rightshift */
847 2, /* size (0 = byte, 1 = short, 2 = long) */
848 13, /* bitsize */
849 TRUE, /* pc_relative */
850 0, /* bitpos */
851 complain_overflow_dont,/* complain_on_overflow */
852 bfd_elf_generic_reloc, /* special_function */
853 "R_ARM_THM_PC12", /* name */
854 FALSE, /* partial_inplace */
855 0xffffffff, /* src_mask */
856 0xffffffff, /* dst_mask */
857 TRUE), /* pcrel_offset */
859 HOWTO (R_ARM_ABS32_NOI, /* type */
860 0, /* rightshift */
861 2, /* size (0 = byte, 1 = short, 2 = long) */
862 32, /* bitsize */
863 FALSE, /* pc_relative */
864 0, /* bitpos */
865 complain_overflow_dont,/* complain_on_overflow */
866 bfd_elf_generic_reloc, /* special_function */
867 "R_ARM_ABS32_NOI", /* name */
868 FALSE, /* partial_inplace */
869 0xffffffff, /* src_mask */
870 0xffffffff, /* dst_mask */
871 FALSE), /* pcrel_offset */
873 HOWTO (R_ARM_REL32_NOI, /* type */
874 0, /* rightshift */
875 2, /* size (0 = byte, 1 = short, 2 = long) */
876 32, /* bitsize */
877 TRUE, /* pc_relative */
878 0, /* bitpos */
879 complain_overflow_dont,/* complain_on_overflow */
880 bfd_elf_generic_reloc, /* special_function */
881 "R_ARM_REL32_NOI", /* name */
882 FALSE, /* partial_inplace */
883 0xffffffff, /* src_mask */
884 0xffffffff, /* dst_mask */
885 FALSE), /* pcrel_offset */
887 /* Group relocations. */
889 HOWTO (R_ARM_ALU_PC_G0_NC, /* type */
890 0, /* rightshift */
891 2, /* size (0 = byte, 1 = short, 2 = long) */
892 32, /* bitsize */
893 TRUE, /* pc_relative */
894 0, /* bitpos */
895 complain_overflow_dont,/* complain_on_overflow */
896 bfd_elf_generic_reloc, /* special_function */
897 "R_ARM_ALU_PC_G0_NC", /* name */
898 FALSE, /* partial_inplace */
899 0xffffffff, /* src_mask */
900 0xffffffff, /* dst_mask */
901 TRUE), /* pcrel_offset */
903 HOWTO (R_ARM_ALU_PC_G0, /* type */
904 0, /* rightshift */
905 2, /* size (0 = byte, 1 = short, 2 = long) */
906 32, /* bitsize */
907 TRUE, /* pc_relative */
908 0, /* bitpos */
909 complain_overflow_dont,/* complain_on_overflow */
910 bfd_elf_generic_reloc, /* special_function */
911 "R_ARM_ALU_PC_G0", /* name */
912 FALSE, /* partial_inplace */
913 0xffffffff, /* src_mask */
914 0xffffffff, /* dst_mask */
915 TRUE), /* pcrel_offset */
917 HOWTO (R_ARM_ALU_PC_G1_NC, /* type */
918 0, /* rightshift */
919 2, /* size (0 = byte, 1 = short, 2 = long) */
920 32, /* bitsize */
921 TRUE, /* pc_relative */
922 0, /* bitpos */
923 complain_overflow_dont,/* complain_on_overflow */
924 bfd_elf_generic_reloc, /* special_function */
925 "R_ARM_ALU_PC_G1_NC", /* name */
926 FALSE, /* partial_inplace */
927 0xffffffff, /* src_mask */
928 0xffffffff, /* dst_mask */
929 TRUE), /* pcrel_offset */
931 HOWTO (R_ARM_ALU_PC_G1, /* type */
932 0, /* rightshift */
933 2, /* size (0 = byte, 1 = short, 2 = long) */
934 32, /* bitsize */
935 TRUE, /* pc_relative */
936 0, /* bitpos */
937 complain_overflow_dont,/* complain_on_overflow */
938 bfd_elf_generic_reloc, /* special_function */
939 "R_ARM_ALU_PC_G1", /* name */
940 FALSE, /* partial_inplace */
941 0xffffffff, /* src_mask */
942 0xffffffff, /* dst_mask */
943 TRUE), /* pcrel_offset */
945 HOWTO (R_ARM_ALU_PC_G2, /* type */
946 0, /* rightshift */
947 2, /* size (0 = byte, 1 = short, 2 = long) */
948 32, /* bitsize */
949 TRUE, /* pc_relative */
950 0, /* bitpos */
951 complain_overflow_dont,/* complain_on_overflow */
952 bfd_elf_generic_reloc, /* special_function */
953 "R_ARM_ALU_PC_G2", /* name */
954 FALSE, /* partial_inplace */
955 0xffffffff, /* src_mask */
956 0xffffffff, /* dst_mask */
957 TRUE), /* pcrel_offset */
959 HOWTO (R_ARM_LDR_PC_G1, /* type */
960 0, /* rightshift */
961 2, /* size (0 = byte, 1 = short, 2 = long) */
962 32, /* bitsize */
963 TRUE, /* pc_relative */
964 0, /* bitpos */
965 complain_overflow_dont,/* complain_on_overflow */
966 bfd_elf_generic_reloc, /* special_function */
967 "R_ARM_LDR_PC_G1", /* name */
968 FALSE, /* partial_inplace */
969 0xffffffff, /* src_mask */
970 0xffffffff, /* dst_mask */
971 TRUE), /* pcrel_offset */
973 HOWTO (R_ARM_LDR_PC_G2, /* type */
974 0, /* rightshift */
975 2, /* size (0 = byte, 1 = short, 2 = long) */
976 32, /* bitsize */
977 TRUE, /* pc_relative */
978 0, /* bitpos */
979 complain_overflow_dont,/* complain_on_overflow */
980 bfd_elf_generic_reloc, /* special_function */
981 "R_ARM_LDR_PC_G2", /* name */
982 FALSE, /* partial_inplace */
983 0xffffffff, /* src_mask */
984 0xffffffff, /* dst_mask */
985 TRUE), /* pcrel_offset */
987 HOWTO (R_ARM_LDRS_PC_G0, /* type */
988 0, /* rightshift */
989 2, /* size (0 = byte, 1 = short, 2 = long) */
990 32, /* bitsize */
991 TRUE, /* pc_relative */
992 0, /* bitpos */
993 complain_overflow_dont,/* complain_on_overflow */
994 bfd_elf_generic_reloc, /* special_function */
995 "R_ARM_LDRS_PC_G0", /* name */
996 FALSE, /* partial_inplace */
997 0xffffffff, /* src_mask */
998 0xffffffff, /* dst_mask */
999 TRUE), /* pcrel_offset */
1001 HOWTO (R_ARM_LDRS_PC_G1, /* type */
1002 0, /* rightshift */
1003 2, /* size (0 = byte, 1 = short, 2 = long) */
1004 32, /* bitsize */
1005 TRUE, /* pc_relative */
1006 0, /* bitpos */
1007 complain_overflow_dont,/* complain_on_overflow */
1008 bfd_elf_generic_reloc, /* special_function */
1009 "R_ARM_LDRS_PC_G1", /* name */
1010 FALSE, /* partial_inplace */
1011 0xffffffff, /* src_mask */
1012 0xffffffff, /* dst_mask */
1013 TRUE), /* pcrel_offset */
1015 HOWTO (R_ARM_LDRS_PC_G2, /* type */
1016 0, /* rightshift */
1017 2, /* size (0 = byte, 1 = short, 2 = long) */
1018 32, /* bitsize */
1019 TRUE, /* pc_relative */
1020 0, /* bitpos */
1021 complain_overflow_dont,/* complain_on_overflow */
1022 bfd_elf_generic_reloc, /* special_function */
1023 "R_ARM_LDRS_PC_G2", /* name */
1024 FALSE, /* partial_inplace */
1025 0xffffffff, /* src_mask */
1026 0xffffffff, /* dst_mask */
1027 TRUE), /* pcrel_offset */
1029 HOWTO (R_ARM_LDC_PC_G0, /* type */
1030 0, /* rightshift */
1031 2, /* size (0 = byte, 1 = short, 2 = long) */
1032 32, /* bitsize */
1033 TRUE, /* pc_relative */
1034 0, /* bitpos */
1035 complain_overflow_dont,/* complain_on_overflow */
1036 bfd_elf_generic_reloc, /* special_function */
1037 "R_ARM_LDC_PC_G0", /* name */
1038 FALSE, /* partial_inplace */
1039 0xffffffff, /* src_mask */
1040 0xffffffff, /* dst_mask */
1041 TRUE), /* pcrel_offset */
1043 HOWTO (R_ARM_LDC_PC_G1, /* type */
1044 0, /* rightshift */
1045 2, /* size (0 = byte, 1 = short, 2 = long) */
1046 32, /* bitsize */
1047 TRUE, /* pc_relative */
1048 0, /* bitpos */
1049 complain_overflow_dont,/* complain_on_overflow */
1050 bfd_elf_generic_reloc, /* special_function */
1051 "R_ARM_LDC_PC_G1", /* name */
1052 FALSE, /* partial_inplace */
1053 0xffffffff, /* src_mask */
1054 0xffffffff, /* dst_mask */
1055 TRUE), /* pcrel_offset */
1057 HOWTO (R_ARM_LDC_PC_G2, /* type */
1058 0, /* rightshift */
1059 2, /* size (0 = byte, 1 = short, 2 = long) */
1060 32, /* bitsize */
1061 TRUE, /* pc_relative */
1062 0, /* bitpos */
1063 complain_overflow_dont,/* complain_on_overflow */
1064 bfd_elf_generic_reloc, /* special_function */
1065 "R_ARM_LDC_PC_G2", /* name */
1066 FALSE, /* partial_inplace */
1067 0xffffffff, /* src_mask */
1068 0xffffffff, /* dst_mask */
1069 TRUE), /* pcrel_offset */
1071 HOWTO (R_ARM_ALU_SB_G0_NC, /* type */
1072 0, /* rightshift */
1073 2, /* size (0 = byte, 1 = short, 2 = long) */
1074 32, /* bitsize */
1075 TRUE, /* pc_relative */
1076 0, /* bitpos */
1077 complain_overflow_dont,/* complain_on_overflow */
1078 bfd_elf_generic_reloc, /* special_function */
1079 "R_ARM_ALU_SB_G0_NC", /* name */
1080 FALSE, /* partial_inplace */
1081 0xffffffff, /* src_mask */
1082 0xffffffff, /* dst_mask */
1083 TRUE), /* pcrel_offset */
1085 HOWTO (R_ARM_ALU_SB_G0, /* type */
1086 0, /* rightshift */
1087 2, /* size (0 = byte, 1 = short, 2 = long) */
1088 32, /* bitsize */
1089 TRUE, /* pc_relative */
1090 0, /* bitpos */
1091 complain_overflow_dont,/* complain_on_overflow */
1092 bfd_elf_generic_reloc, /* special_function */
1093 "R_ARM_ALU_SB_G0", /* name */
1094 FALSE, /* partial_inplace */
1095 0xffffffff, /* src_mask */
1096 0xffffffff, /* dst_mask */
1097 TRUE), /* pcrel_offset */
1099 HOWTO (R_ARM_ALU_SB_G1_NC, /* type */
1100 0, /* rightshift */
1101 2, /* size (0 = byte, 1 = short, 2 = long) */
1102 32, /* bitsize */
1103 TRUE, /* pc_relative */
1104 0, /* bitpos */
1105 complain_overflow_dont,/* complain_on_overflow */
1106 bfd_elf_generic_reloc, /* special_function */
1107 "R_ARM_ALU_SB_G1_NC", /* name */
1108 FALSE, /* partial_inplace */
1109 0xffffffff, /* src_mask */
1110 0xffffffff, /* dst_mask */
1111 TRUE), /* pcrel_offset */
1113 HOWTO (R_ARM_ALU_SB_G1, /* type */
1114 0, /* rightshift */
1115 2, /* size (0 = byte, 1 = short, 2 = long) */
1116 32, /* bitsize */
1117 TRUE, /* pc_relative */
1118 0, /* bitpos */
1119 complain_overflow_dont,/* complain_on_overflow */
1120 bfd_elf_generic_reloc, /* special_function */
1121 "R_ARM_ALU_SB_G1", /* name */
1122 FALSE, /* partial_inplace */
1123 0xffffffff, /* src_mask */
1124 0xffffffff, /* dst_mask */
1125 TRUE), /* pcrel_offset */
1127 HOWTO (R_ARM_ALU_SB_G2, /* type */
1128 0, /* rightshift */
1129 2, /* size (0 = byte, 1 = short, 2 = long) */
1130 32, /* bitsize */
1131 TRUE, /* pc_relative */
1132 0, /* bitpos */
1133 complain_overflow_dont,/* complain_on_overflow */
1134 bfd_elf_generic_reloc, /* special_function */
1135 "R_ARM_ALU_SB_G2", /* name */
1136 FALSE, /* partial_inplace */
1137 0xffffffff, /* src_mask */
1138 0xffffffff, /* dst_mask */
1139 TRUE), /* pcrel_offset */
1141 HOWTO (R_ARM_LDR_SB_G0, /* type */
1142 0, /* rightshift */
1143 2, /* size (0 = byte, 1 = short, 2 = long) */
1144 32, /* bitsize */
1145 TRUE, /* pc_relative */
1146 0, /* bitpos */
1147 complain_overflow_dont,/* complain_on_overflow */
1148 bfd_elf_generic_reloc, /* special_function */
1149 "R_ARM_LDR_SB_G0", /* name */
1150 FALSE, /* partial_inplace */
1151 0xffffffff, /* src_mask */
1152 0xffffffff, /* dst_mask */
1153 TRUE), /* pcrel_offset */
1155 HOWTO (R_ARM_LDR_SB_G1, /* type */
1156 0, /* rightshift */
1157 2, /* size (0 = byte, 1 = short, 2 = long) */
1158 32, /* bitsize */
1159 TRUE, /* pc_relative */
1160 0, /* bitpos */
1161 complain_overflow_dont,/* complain_on_overflow */
1162 bfd_elf_generic_reloc, /* special_function */
1163 "R_ARM_LDR_SB_G1", /* name */
1164 FALSE, /* partial_inplace */
1165 0xffffffff, /* src_mask */
1166 0xffffffff, /* dst_mask */
1167 TRUE), /* pcrel_offset */
1169 HOWTO (R_ARM_LDR_SB_G2, /* type */
1170 0, /* rightshift */
1171 2, /* size (0 = byte, 1 = short, 2 = long) */
1172 32, /* bitsize */
1173 TRUE, /* pc_relative */
1174 0, /* bitpos */
1175 complain_overflow_dont,/* complain_on_overflow */
1176 bfd_elf_generic_reloc, /* special_function */
1177 "R_ARM_LDR_SB_G2", /* name */
1178 FALSE, /* partial_inplace */
1179 0xffffffff, /* src_mask */
1180 0xffffffff, /* dst_mask */
1181 TRUE), /* pcrel_offset */
1183 HOWTO (R_ARM_LDRS_SB_G0, /* type */
1184 0, /* rightshift */
1185 2, /* size (0 = byte, 1 = short, 2 = long) */
1186 32, /* bitsize */
1187 TRUE, /* pc_relative */
1188 0, /* bitpos */
1189 complain_overflow_dont,/* complain_on_overflow */
1190 bfd_elf_generic_reloc, /* special_function */
1191 "R_ARM_LDRS_SB_G0", /* name */
1192 FALSE, /* partial_inplace */
1193 0xffffffff, /* src_mask */
1194 0xffffffff, /* dst_mask */
1195 TRUE), /* pcrel_offset */
1197 HOWTO (R_ARM_LDRS_SB_G1, /* type */
1198 0, /* rightshift */
1199 2, /* size (0 = byte, 1 = short, 2 = long) */
1200 32, /* bitsize */
1201 TRUE, /* pc_relative */
1202 0, /* bitpos */
1203 complain_overflow_dont,/* complain_on_overflow */
1204 bfd_elf_generic_reloc, /* special_function */
1205 "R_ARM_LDRS_SB_G1", /* name */
1206 FALSE, /* partial_inplace */
1207 0xffffffff, /* src_mask */
1208 0xffffffff, /* dst_mask */
1209 TRUE), /* pcrel_offset */
1211 HOWTO (R_ARM_LDRS_SB_G2, /* type */
1212 0, /* rightshift */
1213 2, /* size (0 = byte, 1 = short, 2 = long) */
1214 32, /* bitsize */
1215 TRUE, /* pc_relative */
1216 0, /* bitpos */
1217 complain_overflow_dont,/* complain_on_overflow */
1218 bfd_elf_generic_reloc, /* special_function */
1219 "R_ARM_LDRS_SB_G2", /* name */
1220 FALSE, /* partial_inplace */
1221 0xffffffff, /* src_mask */
1222 0xffffffff, /* dst_mask */
1223 TRUE), /* pcrel_offset */
1225 HOWTO (R_ARM_LDC_SB_G0, /* type */
1226 0, /* rightshift */
1227 2, /* size (0 = byte, 1 = short, 2 = long) */
1228 32, /* bitsize */
1229 TRUE, /* pc_relative */
1230 0, /* bitpos */
1231 complain_overflow_dont,/* complain_on_overflow */
1232 bfd_elf_generic_reloc, /* special_function */
1233 "R_ARM_LDC_SB_G0", /* name */
1234 FALSE, /* partial_inplace */
1235 0xffffffff, /* src_mask */
1236 0xffffffff, /* dst_mask */
1237 TRUE), /* pcrel_offset */
1239 HOWTO (R_ARM_LDC_SB_G1, /* type */
1240 0, /* rightshift */
1241 2, /* size (0 = byte, 1 = short, 2 = long) */
1242 32, /* bitsize */
1243 TRUE, /* pc_relative */
1244 0, /* bitpos */
1245 complain_overflow_dont,/* complain_on_overflow */
1246 bfd_elf_generic_reloc, /* special_function */
1247 "R_ARM_LDC_SB_G1", /* name */
1248 FALSE, /* partial_inplace */
1249 0xffffffff, /* src_mask */
1250 0xffffffff, /* dst_mask */
1251 TRUE), /* pcrel_offset */
1253 HOWTO (R_ARM_LDC_SB_G2, /* type */
1254 0, /* rightshift */
1255 2, /* size (0 = byte, 1 = short, 2 = long) */
1256 32, /* bitsize */
1257 TRUE, /* pc_relative */
1258 0, /* bitpos */
1259 complain_overflow_dont,/* complain_on_overflow */
1260 bfd_elf_generic_reloc, /* special_function */
1261 "R_ARM_LDC_SB_G2", /* name */
1262 FALSE, /* partial_inplace */
1263 0xffffffff, /* src_mask */
1264 0xffffffff, /* dst_mask */
1265 TRUE), /* pcrel_offset */
1267 /* End of group relocations. */
1269 HOWTO (R_ARM_MOVW_BREL_NC, /* type */
1270 0, /* rightshift */
1271 2, /* size (0 = byte, 1 = short, 2 = long) */
1272 16, /* bitsize */
1273 FALSE, /* pc_relative */
1274 0, /* bitpos */
1275 complain_overflow_dont,/* complain_on_overflow */
1276 bfd_elf_generic_reloc, /* special_function */
1277 "R_ARM_MOVW_BREL_NC", /* name */
1278 FALSE, /* partial_inplace */
1279 0x0000ffff, /* src_mask */
1280 0x0000ffff, /* dst_mask */
1281 FALSE), /* pcrel_offset */
1283 HOWTO (R_ARM_MOVT_BREL, /* type */
1284 0, /* rightshift */
1285 2, /* size (0 = byte, 1 = short, 2 = long) */
1286 16, /* bitsize */
1287 FALSE, /* pc_relative */
1288 0, /* bitpos */
1289 complain_overflow_bitfield,/* complain_on_overflow */
1290 bfd_elf_generic_reloc, /* special_function */
1291 "R_ARM_MOVT_BREL", /* name */
1292 FALSE, /* partial_inplace */
1293 0x0000ffff, /* src_mask */
1294 0x0000ffff, /* dst_mask */
1295 FALSE), /* pcrel_offset */
1297 HOWTO (R_ARM_MOVW_BREL, /* type */
1298 0, /* rightshift */
1299 2, /* size (0 = byte, 1 = short, 2 = long) */
1300 16, /* bitsize */
1301 FALSE, /* pc_relative */
1302 0, /* bitpos */
1303 complain_overflow_dont,/* complain_on_overflow */
1304 bfd_elf_generic_reloc, /* special_function */
1305 "R_ARM_MOVW_BREL", /* name */
1306 FALSE, /* partial_inplace */
1307 0x0000ffff, /* src_mask */
1308 0x0000ffff, /* dst_mask */
1309 FALSE), /* pcrel_offset */
1311 HOWTO (R_ARM_THM_MOVW_BREL_NC,/* type */
1312 0, /* rightshift */
1313 2, /* size (0 = byte, 1 = short, 2 = long) */
1314 16, /* bitsize */
1315 FALSE, /* pc_relative */
1316 0, /* bitpos */
1317 complain_overflow_dont,/* complain_on_overflow */
1318 bfd_elf_generic_reloc, /* special_function */
1319 "R_ARM_THM_MOVW_BREL_NC",/* name */
1320 FALSE, /* partial_inplace */
1321 0x040f70ff, /* src_mask */
1322 0x040f70ff, /* dst_mask */
1323 FALSE), /* pcrel_offset */
1325 HOWTO (R_ARM_THM_MOVT_BREL, /* type */
1326 0, /* rightshift */
1327 2, /* size (0 = byte, 1 = short, 2 = long) */
1328 16, /* bitsize */
1329 FALSE, /* pc_relative */
1330 0, /* bitpos */
1331 complain_overflow_bitfield,/* complain_on_overflow */
1332 bfd_elf_generic_reloc, /* special_function */
1333 "R_ARM_THM_MOVT_BREL", /* name */
1334 FALSE, /* partial_inplace */
1335 0x040f70ff, /* src_mask */
1336 0x040f70ff, /* dst_mask */
1337 FALSE), /* pcrel_offset */
1339 HOWTO (R_ARM_THM_MOVW_BREL, /* type */
1340 0, /* rightshift */
1341 2, /* size (0 = byte, 1 = short, 2 = long) */
1342 16, /* bitsize */
1343 FALSE, /* pc_relative */
1344 0, /* bitpos */
1345 complain_overflow_dont,/* complain_on_overflow */
1346 bfd_elf_generic_reloc, /* special_function */
1347 "R_ARM_THM_MOVW_BREL", /* name */
1348 FALSE, /* partial_inplace */
1349 0x040f70ff, /* src_mask */
1350 0x040f70ff, /* dst_mask */
1351 FALSE), /* pcrel_offset */
1353 EMPTY_HOWTO (90), /* unallocated */
1354 EMPTY_HOWTO (91),
1355 EMPTY_HOWTO (92),
1356 EMPTY_HOWTO (93),
1358 HOWTO (R_ARM_PLT32_ABS, /* type */
1359 0, /* rightshift */
1360 2, /* size (0 = byte, 1 = short, 2 = long) */
1361 32, /* bitsize */
1362 FALSE, /* pc_relative */
1363 0, /* bitpos */
1364 complain_overflow_dont,/* complain_on_overflow */
1365 bfd_elf_generic_reloc, /* special_function */
1366 "R_ARM_PLT32_ABS", /* name */
1367 FALSE, /* partial_inplace */
1368 0xffffffff, /* src_mask */
1369 0xffffffff, /* dst_mask */
1370 FALSE), /* pcrel_offset */
1372 HOWTO (R_ARM_GOT_ABS, /* type */
1373 0, /* rightshift */
1374 2, /* size (0 = byte, 1 = short, 2 = long) */
1375 32, /* bitsize */
1376 FALSE, /* pc_relative */
1377 0, /* bitpos */
1378 complain_overflow_dont,/* complain_on_overflow */
1379 bfd_elf_generic_reloc, /* special_function */
1380 "R_ARM_GOT_ABS", /* name */
1381 FALSE, /* partial_inplace */
1382 0xffffffff, /* src_mask */
1383 0xffffffff, /* dst_mask */
1384 FALSE), /* pcrel_offset */
1386 HOWTO (R_ARM_GOT_PREL, /* type */
1387 0, /* rightshift */
1388 2, /* size (0 = byte, 1 = short, 2 = long) */
1389 32, /* bitsize */
1390 TRUE, /* pc_relative */
1391 0, /* bitpos */
1392 complain_overflow_dont, /* complain_on_overflow */
1393 bfd_elf_generic_reloc, /* special_function */
1394 "R_ARM_GOT_PREL", /* name */
1395 FALSE, /* partial_inplace */
1396 0xffffffff, /* src_mask */
1397 0xffffffff, /* dst_mask */
1398 TRUE), /* pcrel_offset */
1400 HOWTO (R_ARM_GOT_BREL12, /* type */
1401 0, /* rightshift */
1402 2, /* size (0 = byte, 1 = short, 2 = long) */
1403 12, /* bitsize */
1404 FALSE, /* pc_relative */
1405 0, /* bitpos */
1406 complain_overflow_bitfield,/* complain_on_overflow */
1407 bfd_elf_generic_reloc, /* special_function */
1408 "R_ARM_GOT_BREL12", /* name */
1409 FALSE, /* partial_inplace */
1410 0x00000fff, /* src_mask */
1411 0x00000fff, /* dst_mask */
1412 FALSE), /* pcrel_offset */
1414 HOWTO (R_ARM_GOTOFF12, /* type */
1415 0, /* rightshift */
1416 2, /* size (0 = byte, 1 = short, 2 = long) */
1417 12, /* bitsize */
1418 FALSE, /* pc_relative */
1419 0, /* bitpos */
1420 complain_overflow_bitfield,/* complain_on_overflow */
1421 bfd_elf_generic_reloc, /* special_function */
1422 "R_ARM_GOTOFF12", /* name */
1423 FALSE, /* partial_inplace */
1424 0x00000fff, /* src_mask */
1425 0x00000fff, /* dst_mask */
1426 FALSE), /* pcrel_offset */
1428 EMPTY_HOWTO (R_ARM_GOTRELAX), /* reserved for future GOT-load optimizations */
1430 /* GNU extension to record C++ vtable member usage */
1431 HOWTO (R_ARM_GNU_VTENTRY, /* type */
1432 0, /* rightshift */
1433 2, /* size (0 = byte, 1 = short, 2 = long) */
1434 0, /* bitsize */
1435 FALSE, /* pc_relative */
1436 0, /* bitpos */
1437 complain_overflow_dont, /* complain_on_overflow */
1438 _bfd_elf_rel_vtable_reloc_fn, /* special_function */
1439 "R_ARM_GNU_VTENTRY", /* name */
1440 FALSE, /* partial_inplace */
1441 0, /* src_mask */
1442 0, /* dst_mask */
1443 FALSE), /* pcrel_offset */
1445 /* GNU extension to record C++ vtable hierarchy */
1446 HOWTO (R_ARM_GNU_VTINHERIT, /* type */
1447 0, /* rightshift */
1448 2, /* size (0 = byte, 1 = short, 2 = long) */
1449 0, /* bitsize */
1450 FALSE, /* pc_relative */
1451 0, /* bitpos */
1452 complain_overflow_dont, /* complain_on_overflow */
1453 NULL, /* special_function */
1454 "R_ARM_GNU_VTINHERIT", /* name */
1455 FALSE, /* partial_inplace */
1456 0, /* src_mask */
1457 0, /* dst_mask */
1458 FALSE), /* pcrel_offset */
1460 HOWTO (R_ARM_THM_JUMP11, /* type */
1461 1, /* rightshift */
1462 1, /* size (0 = byte, 1 = short, 2 = long) */
1463 11, /* bitsize */
1464 TRUE, /* pc_relative */
1465 0, /* bitpos */
1466 complain_overflow_signed, /* complain_on_overflow */
1467 bfd_elf_generic_reloc, /* special_function */
1468 "R_ARM_THM_JUMP11", /* name */
1469 FALSE, /* partial_inplace */
1470 0x000007ff, /* src_mask */
1471 0x000007ff, /* dst_mask */
1472 TRUE), /* pcrel_offset */
1474 HOWTO (R_ARM_THM_JUMP8, /* type */
1475 1, /* rightshift */
1476 1, /* size (0 = byte, 1 = short, 2 = long) */
1477 8, /* bitsize */
1478 TRUE, /* pc_relative */
1479 0, /* bitpos */
1480 complain_overflow_signed, /* complain_on_overflow */
1481 bfd_elf_generic_reloc, /* special_function */
1482 "R_ARM_THM_JUMP8", /* name */
1483 FALSE, /* partial_inplace */
1484 0x000000ff, /* src_mask */
1485 0x000000ff, /* dst_mask */
1486 TRUE), /* pcrel_offset */
1488 /* TLS relocations */
1489 HOWTO (R_ARM_TLS_GD32, /* type */
1490 0, /* rightshift */
1491 2, /* size (0 = byte, 1 = short, 2 = long) */
1492 32, /* bitsize */
1493 FALSE, /* pc_relative */
1494 0, /* bitpos */
1495 complain_overflow_bitfield,/* complain_on_overflow */
1496 NULL, /* special_function */
1497 "R_ARM_TLS_GD32", /* name */
1498 TRUE, /* partial_inplace */
1499 0xffffffff, /* src_mask */
1500 0xffffffff, /* dst_mask */
1501 FALSE), /* pcrel_offset */
1503 HOWTO (R_ARM_TLS_LDM32, /* type */
1504 0, /* rightshift */
1505 2, /* size (0 = byte, 1 = short, 2 = long) */
1506 32, /* bitsize */
1507 FALSE, /* pc_relative */
1508 0, /* bitpos */
1509 complain_overflow_bitfield,/* complain_on_overflow */
1510 bfd_elf_generic_reloc, /* special_function */
1511 "R_ARM_TLS_LDM32", /* name */
1512 TRUE, /* partial_inplace */
1513 0xffffffff, /* src_mask */
1514 0xffffffff, /* dst_mask */
1515 FALSE), /* pcrel_offset */
1517 HOWTO (R_ARM_TLS_LDO32, /* type */
1518 0, /* rightshift */
1519 2, /* size (0 = byte, 1 = short, 2 = long) */
1520 32, /* bitsize */
1521 FALSE, /* pc_relative */
1522 0, /* bitpos */
1523 complain_overflow_bitfield,/* complain_on_overflow */
1524 bfd_elf_generic_reloc, /* special_function */
1525 "R_ARM_TLS_LDO32", /* name */
1526 TRUE, /* partial_inplace */
1527 0xffffffff, /* src_mask */
1528 0xffffffff, /* dst_mask */
1529 FALSE), /* pcrel_offset */
1531 HOWTO (R_ARM_TLS_IE32, /* type */
1532 0, /* rightshift */
1533 2, /* size (0 = byte, 1 = short, 2 = long) */
1534 32, /* bitsize */
1535 FALSE, /* pc_relative */
1536 0, /* bitpos */
1537 complain_overflow_bitfield,/* complain_on_overflow */
1538 NULL, /* special_function */
1539 "R_ARM_TLS_IE32", /* name */
1540 TRUE, /* partial_inplace */
1541 0xffffffff, /* src_mask */
1542 0xffffffff, /* dst_mask */
1543 FALSE), /* pcrel_offset */
1545 HOWTO (R_ARM_TLS_LE32, /* type */
1546 0, /* rightshift */
1547 2, /* size (0 = byte, 1 = short, 2 = long) */
1548 32, /* bitsize */
1549 FALSE, /* pc_relative */
1550 0, /* bitpos */
1551 complain_overflow_bitfield,/* complain_on_overflow */
1552 bfd_elf_generic_reloc, /* special_function */
1553 "R_ARM_TLS_LE32", /* name */
1554 TRUE, /* partial_inplace */
1555 0xffffffff, /* src_mask */
1556 0xffffffff, /* dst_mask */
1557 FALSE), /* pcrel_offset */
1559 HOWTO (R_ARM_TLS_LDO12, /* type */
1560 0, /* rightshift */
1561 2, /* size (0 = byte, 1 = short, 2 = long) */
1562 12, /* bitsize */
1563 FALSE, /* pc_relative */
1564 0, /* bitpos */
1565 complain_overflow_bitfield,/* complain_on_overflow */
1566 bfd_elf_generic_reloc, /* special_function */
1567 "R_ARM_TLS_LDO12", /* name */
1568 FALSE, /* partial_inplace */
1569 0x00000fff, /* src_mask */
1570 0x00000fff, /* dst_mask */
1571 FALSE), /* pcrel_offset */
1573 HOWTO (R_ARM_TLS_LE12, /* type */
1574 0, /* rightshift */
1575 2, /* size (0 = byte, 1 = short, 2 = long) */
1576 12, /* bitsize */
1577 FALSE, /* pc_relative */
1578 0, /* bitpos */
1579 complain_overflow_bitfield,/* complain_on_overflow */
1580 bfd_elf_generic_reloc, /* special_function */
1581 "R_ARM_TLS_LE12", /* name */
1582 FALSE, /* partial_inplace */
1583 0x00000fff, /* src_mask */
1584 0x00000fff, /* dst_mask */
1585 FALSE), /* pcrel_offset */
1587 HOWTO (R_ARM_TLS_IE12GP, /* type */
1588 0, /* rightshift */
1589 2, /* size (0 = byte, 1 = short, 2 = long) */
1590 12, /* bitsize */
1591 FALSE, /* pc_relative */
1592 0, /* bitpos */
1593 complain_overflow_bitfield,/* complain_on_overflow */
1594 bfd_elf_generic_reloc, /* special_function */
1595 "R_ARM_TLS_IE12GP", /* name */
1596 FALSE, /* partial_inplace */
1597 0x00000fff, /* src_mask */
1598 0x00000fff, /* dst_mask */
1599 FALSE), /* pcrel_offset */
1602 /* 112-127 private relocations
1603 128 R_ARM_ME_TOO, obsolete
1604 129-255 unallocated in AAELF.
1606 249-255 extended, currently unused, relocations: */
1608 static reloc_howto_type elf32_arm_howto_table_2[4] =
1610 HOWTO (R_ARM_RREL32, /* type */
1611 0, /* rightshift */
1612 0, /* size (0 = byte, 1 = short, 2 = long) */
1613 0, /* bitsize */
1614 FALSE, /* pc_relative */
1615 0, /* bitpos */
1616 complain_overflow_dont,/* complain_on_overflow */
1617 bfd_elf_generic_reloc, /* special_function */
1618 "R_ARM_RREL32", /* name */
1619 FALSE, /* partial_inplace */
1620 0, /* src_mask */
1621 0, /* dst_mask */
1622 FALSE), /* pcrel_offset */
1624 HOWTO (R_ARM_RABS32, /* type */
1625 0, /* rightshift */
1626 0, /* size (0 = byte, 1 = short, 2 = long) */
1627 0, /* bitsize */
1628 FALSE, /* pc_relative */
1629 0, /* bitpos */
1630 complain_overflow_dont,/* complain_on_overflow */
1631 bfd_elf_generic_reloc, /* special_function */
1632 "R_ARM_RABS32", /* name */
1633 FALSE, /* partial_inplace */
1634 0, /* src_mask */
1635 0, /* dst_mask */
1636 FALSE), /* pcrel_offset */
1638 HOWTO (R_ARM_RPC24, /* type */
1639 0, /* rightshift */
1640 0, /* size (0 = byte, 1 = short, 2 = long) */
1641 0, /* bitsize */
1642 FALSE, /* pc_relative */
1643 0, /* bitpos */
1644 complain_overflow_dont,/* complain_on_overflow */
1645 bfd_elf_generic_reloc, /* special_function */
1646 "R_ARM_RPC24", /* name */
1647 FALSE, /* partial_inplace */
1648 0, /* src_mask */
1649 0, /* dst_mask */
1650 FALSE), /* pcrel_offset */
1652 HOWTO (R_ARM_RBASE, /* type */
1653 0, /* rightshift */
1654 0, /* size (0 = byte, 1 = short, 2 = long) */
1655 0, /* bitsize */
1656 FALSE, /* pc_relative */
1657 0, /* bitpos */
1658 complain_overflow_dont,/* complain_on_overflow */
1659 bfd_elf_generic_reloc, /* special_function */
1660 "R_ARM_RBASE", /* name */
1661 FALSE, /* partial_inplace */
1662 0, /* src_mask */
1663 0, /* dst_mask */
1664 FALSE) /* pcrel_offset */
1667 static reloc_howto_type *
1668 elf32_arm_howto_from_type (unsigned int r_type)
1670 if (r_type < NUM_ELEM (elf32_arm_howto_table_1))
1671 return &elf32_arm_howto_table_1[r_type];
1673 if (r_type >= R_ARM_RREL32
1674 && r_type < R_ARM_RREL32 + NUM_ELEM (elf32_arm_howto_table_2))
1675 return &elf32_arm_howto_table_2[r_type - R_ARM_RREL32];
1677 return NULL;
1680 static void
1681 elf32_arm_info_to_howto (bfd * abfd ATTRIBUTE_UNUSED, arelent * bfd_reloc,
1682 Elf_Internal_Rela * elf_reloc)
1684 unsigned int r_type;
1686 r_type = ELF32_R_TYPE (elf_reloc->r_info);
1687 bfd_reloc->howto = elf32_arm_howto_from_type (r_type);
1690 struct elf32_arm_reloc_map
1692 bfd_reloc_code_real_type bfd_reloc_val;
1693 unsigned char elf_reloc_val;
1696 /* All entries in this list must also be present in elf32_arm_howto_table. */
1697 static const struct elf32_arm_reloc_map elf32_arm_reloc_map[] =
1699 {BFD_RELOC_NONE, R_ARM_NONE},
1700 {BFD_RELOC_ARM_PCREL_BRANCH, R_ARM_PC24},
1701 {BFD_RELOC_ARM_PCREL_CALL, R_ARM_CALL},
1702 {BFD_RELOC_ARM_PCREL_JUMP, R_ARM_JUMP24},
1703 {BFD_RELOC_ARM_PCREL_BLX, R_ARM_XPC25},
1704 {BFD_RELOC_THUMB_PCREL_BLX, R_ARM_THM_XPC22},
1705 {BFD_RELOC_32, R_ARM_ABS32},
1706 {BFD_RELOC_32_PCREL, R_ARM_REL32},
1707 {BFD_RELOC_8, R_ARM_ABS8},
1708 {BFD_RELOC_16, R_ARM_ABS16},
1709 {BFD_RELOC_ARM_OFFSET_IMM, R_ARM_ABS12},
1710 {BFD_RELOC_ARM_THUMB_OFFSET, R_ARM_THM_ABS5},
1711 {BFD_RELOC_THUMB_PCREL_BRANCH25, R_ARM_THM_JUMP24},
1712 {BFD_RELOC_THUMB_PCREL_BRANCH23, R_ARM_THM_CALL},
1713 {BFD_RELOC_THUMB_PCREL_BRANCH12, R_ARM_THM_JUMP11},
1714 {BFD_RELOC_THUMB_PCREL_BRANCH20, R_ARM_THM_JUMP19},
1715 {BFD_RELOC_THUMB_PCREL_BRANCH9, R_ARM_THM_JUMP8},
1716 {BFD_RELOC_THUMB_PCREL_BRANCH7, R_ARM_THM_JUMP6},
1717 {BFD_RELOC_ARM_GLOB_DAT, R_ARM_GLOB_DAT},
1718 {BFD_RELOC_ARM_JUMP_SLOT, R_ARM_JUMP_SLOT},
1719 {BFD_RELOC_ARM_RELATIVE, R_ARM_RELATIVE},
1720 {BFD_RELOC_ARM_GOTOFF, R_ARM_GOTOFF32},
1721 {BFD_RELOC_ARM_GOTPC, R_ARM_GOTPC},
1722 {BFD_RELOC_ARM_GOT32, R_ARM_GOT32},
1723 {BFD_RELOC_ARM_PLT32, R_ARM_PLT32},
1724 {BFD_RELOC_ARM_TARGET1, R_ARM_TARGET1},
1725 {BFD_RELOC_ARM_ROSEGREL32, R_ARM_ROSEGREL32},
1726 {BFD_RELOC_ARM_SBREL32, R_ARM_SBREL32},
1727 {BFD_RELOC_ARM_PREL31, R_ARM_PREL31},
1728 {BFD_RELOC_ARM_TARGET2, R_ARM_TARGET2},
1729 {BFD_RELOC_ARM_PLT32, R_ARM_PLT32},
1730 {BFD_RELOC_ARM_TLS_GD32, R_ARM_TLS_GD32},
1731 {BFD_RELOC_ARM_TLS_LDO32, R_ARM_TLS_LDO32},
1732 {BFD_RELOC_ARM_TLS_LDM32, R_ARM_TLS_LDM32},
1733 {BFD_RELOC_ARM_TLS_DTPMOD32, R_ARM_TLS_DTPMOD32},
1734 {BFD_RELOC_ARM_TLS_DTPOFF32, R_ARM_TLS_DTPOFF32},
1735 {BFD_RELOC_ARM_TLS_TPOFF32, R_ARM_TLS_TPOFF32},
1736 {BFD_RELOC_ARM_TLS_IE32, R_ARM_TLS_IE32},
1737 {BFD_RELOC_ARM_TLS_LE32, R_ARM_TLS_LE32},
1738 {BFD_RELOC_VTABLE_INHERIT, R_ARM_GNU_VTINHERIT},
1739 {BFD_RELOC_VTABLE_ENTRY, R_ARM_GNU_VTENTRY},
1740 {BFD_RELOC_ARM_MOVW, R_ARM_MOVW_ABS_NC},
1741 {BFD_RELOC_ARM_MOVT, R_ARM_MOVT_ABS},
1742 {BFD_RELOC_ARM_MOVW_PCREL, R_ARM_MOVW_PREL_NC},
1743 {BFD_RELOC_ARM_MOVT_PCREL, R_ARM_MOVT_PREL},
1744 {BFD_RELOC_ARM_THUMB_MOVW, R_ARM_THM_MOVW_ABS_NC},
1745 {BFD_RELOC_ARM_THUMB_MOVT, R_ARM_THM_MOVT_ABS},
1746 {BFD_RELOC_ARM_THUMB_MOVW_PCREL, R_ARM_THM_MOVW_PREL_NC},
1747 {BFD_RELOC_ARM_THUMB_MOVT_PCREL, R_ARM_THM_MOVT_PREL},
1748 {BFD_RELOC_ARM_ALU_PC_G0_NC, R_ARM_ALU_PC_G0_NC},
1749 {BFD_RELOC_ARM_ALU_PC_G0, R_ARM_ALU_PC_G0},
1750 {BFD_RELOC_ARM_ALU_PC_G1_NC, R_ARM_ALU_PC_G1_NC},
1751 {BFD_RELOC_ARM_ALU_PC_G1, R_ARM_ALU_PC_G1},
1752 {BFD_RELOC_ARM_ALU_PC_G2, R_ARM_ALU_PC_G2},
1753 {BFD_RELOC_ARM_LDR_PC_G0, R_ARM_LDR_PC_G0},
1754 {BFD_RELOC_ARM_LDR_PC_G1, R_ARM_LDR_PC_G1},
1755 {BFD_RELOC_ARM_LDR_PC_G2, R_ARM_LDR_PC_G2},
1756 {BFD_RELOC_ARM_LDRS_PC_G0, R_ARM_LDRS_PC_G0},
1757 {BFD_RELOC_ARM_LDRS_PC_G1, R_ARM_LDRS_PC_G1},
1758 {BFD_RELOC_ARM_LDRS_PC_G2, R_ARM_LDRS_PC_G2},
1759 {BFD_RELOC_ARM_LDC_PC_G0, R_ARM_LDC_PC_G0},
1760 {BFD_RELOC_ARM_LDC_PC_G1, R_ARM_LDC_PC_G1},
1761 {BFD_RELOC_ARM_LDC_PC_G2, R_ARM_LDC_PC_G2},
1762 {BFD_RELOC_ARM_ALU_SB_G0_NC, R_ARM_ALU_SB_G0_NC},
1763 {BFD_RELOC_ARM_ALU_SB_G0, R_ARM_ALU_SB_G0},
1764 {BFD_RELOC_ARM_ALU_SB_G1_NC, R_ARM_ALU_SB_G1_NC},
1765 {BFD_RELOC_ARM_ALU_SB_G1, R_ARM_ALU_SB_G1},
1766 {BFD_RELOC_ARM_ALU_SB_G2, R_ARM_ALU_SB_G2},
1767 {BFD_RELOC_ARM_LDR_SB_G0, R_ARM_LDR_SB_G0},
1768 {BFD_RELOC_ARM_LDR_SB_G1, R_ARM_LDR_SB_G1},
1769 {BFD_RELOC_ARM_LDR_SB_G2, R_ARM_LDR_SB_G2},
1770 {BFD_RELOC_ARM_LDRS_SB_G0, R_ARM_LDRS_SB_G0},
1771 {BFD_RELOC_ARM_LDRS_SB_G1, R_ARM_LDRS_SB_G1},
1772 {BFD_RELOC_ARM_LDRS_SB_G2, R_ARM_LDRS_SB_G2},
1773 {BFD_RELOC_ARM_LDC_SB_G0, R_ARM_LDC_SB_G0},
1774 {BFD_RELOC_ARM_LDC_SB_G1, R_ARM_LDC_SB_G1},
1775 {BFD_RELOC_ARM_LDC_SB_G2, R_ARM_LDC_SB_G2}
1778 static reloc_howto_type *
1779 elf32_arm_reloc_type_lookup (bfd *abfd ATTRIBUTE_UNUSED,
1780 bfd_reloc_code_real_type code)
1782 unsigned int i;
1783 for (i = 0; i < NUM_ELEM (elf32_arm_reloc_map); i ++)
1784 if (elf32_arm_reloc_map[i].bfd_reloc_val == code)
1785 return elf32_arm_howto_from_type (elf32_arm_reloc_map[i].elf_reloc_val);
1787 return NULL;
1790 /* Support for core dump NOTE sections */
1791 static bfd_boolean
1792 elf32_arm_nabi_grok_prstatus (bfd *abfd, Elf_Internal_Note *note)
1794 int offset;
1795 size_t size;
1797 switch (note->descsz)
1799 default:
1800 return FALSE;
1802 case 148: /* Linux/ARM 32-bit*/
1803 /* pr_cursig */
1804 elf_tdata (abfd)->core_signal = bfd_get_16 (abfd, note->descdata + 12);
1806 /* pr_pid */
1807 elf_tdata (abfd)->core_pid = bfd_get_32 (abfd, note->descdata + 24);
1809 /* pr_reg */
1810 offset = 72;
1811 size = 72;
1813 break;
1816 /* Make a ".reg/999" section. */
1817 return _bfd_elfcore_make_pseudosection (abfd, ".reg",
1818 size, note->descpos + offset);
1821 static bfd_boolean
1822 elf32_arm_nabi_grok_psinfo (bfd *abfd, Elf_Internal_Note *note)
1824 switch (note->descsz)
1826 default:
1827 return FALSE;
1829 case 124: /* Linux/ARM elf_prpsinfo */
1830 elf_tdata (abfd)->core_program
1831 = _bfd_elfcore_strndup (abfd, note->descdata + 28, 16);
1832 elf_tdata (abfd)->core_command
1833 = _bfd_elfcore_strndup (abfd, note->descdata + 44, 80);
1836 /* Note that for some reason, a spurious space is tacked
1837 onto the end of the args in some (at least one anyway)
1838 implementations, so strip it off if it exists. */
1841 char *command = elf_tdata (abfd)->core_command;
1842 int n = strlen (command);
1844 if (0 < n && command[n - 1] == ' ')
1845 command[n - 1] = '\0';
1848 return TRUE;
1851 #define TARGET_LITTLE_SYM bfd_elf32_littlearm_vec
1852 #define TARGET_LITTLE_NAME "elf32-littlearm"
1853 #define TARGET_BIG_SYM bfd_elf32_bigarm_vec
1854 #define TARGET_BIG_NAME "elf32-bigarm"
1856 #define elf_backend_grok_prstatus elf32_arm_nabi_grok_prstatus
1857 #define elf_backend_grok_psinfo elf32_arm_nabi_grok_psinfo
1859 typedef unsigned long int insn32;
1860 typedef unsigned short int insn16;
1862 /* In lieu of proper flags, assume all EABIv4 or later objects are
1863 interworkable. */
1864 #define INTERWORK_FLAG(abfd) \
1865 (EF_ARM_EABI_VERSION (elf_elfheader (abfd)->e_flags) >= EF_ARM_EABI_VER4 \
1866 || (elf_elfheader (abfd)->e_flags & EF_ARM_INTERWORK))
1868 /* The linker script knows the section names for placement.
1869 The entry_names are used to do simple name mangling on the stubs.
1870 Given a function name, and its type, the stub can be found. The
1871 name can be changed. The only requirement is the %s be present. */
1872 #define THUMB2ARM_GLUE_SECTION_NAME ".glue_7t"
1873 #define THUMB2ARM_GLUE_ENTRY_NAME "__%s_from_thumb"
1875 #define ARM2THUMB_GLUE_SECTION_NAME ".glue_7"
1876 #define ARM2THUMB_GLUE_ENTRY_NAME "__%s_from_arm"
1878 /* The name of the dynamic interpreter. This is put in the .interp
1879 section. */
1880 #define ELF_DYNAMIC_INTERPRETER "/usr/lib/ld.so.1"
1882 #ifdef FOUR_WORD_PLT
1884 /* The first entry in a procedure linkage table looks like
1885 this. It is set up so that any shared library function that is
1886 called before the relocation has been set up calls the dynamic
1887 linker first. */
1888 static const bfd_vma elf32_arm_plt0_entry [] =
1890 0xe52de004, /* str lr, [sp, #-4]! */
1891 0xe59fe010, /* ldr lr, [pc, #16] */
1892 0xe08fe00e, /* add lr, pc, lr */
1893 0xe5bef008, /* ldr pc, [lr, #8]! */
1896 /* Subsequent entries in a procedure linkage table look like
1897 this. */
1898 static const bfd_vma elf32_arm_plt_entry [] =
1900 0xe28fc600, /* add ip, pc, #NN */
1901 0xe28cca00, /* add ip, ip, #NN */
1902 0xe5bcf000, /* ldr pc, [ip, #NN]! */
1903 0x00000000, /* unused */
1906 #else
1908 /* The first entry in a procedure linkage table looks like
1909 this. It is set up so that any shared library function that is
1910 called before the relocation has been set up calls the dynamic
1911 linker first. */
1912 static const bfd_vma elf32_arm_plt0_entry [] =
1914 0xe52de004, /* str lr, [sp, #-4]! */
1915 0xe59fe004, /* ldr lr, [pc, #4] */
1916 0xe08fe00e, /* add lr, pc, lr */
1917 0xe5bef008, /* ldr pc, [lr, #8]! */
1918 0x00000000, /* &GOT[0] - . */
1921 /* Subsequent entries in a procedure linkage table look like
1922 this. */
1923 static const bfd_vma elf32_arm_plt_entry [] =
1925 0xe28fc600, /* add ip, pc, #0xNN00000 */
1926 0xe28cca00, /* add ip, ip, #0xNN000 */
1927 0xe5bcf000, /* ldr pc, [ip, #0xNNN]! */
1930 #endif
1932 /* The format of the first entry in the procedure linkage table
1933 for a VxWorks executable. */
1934 static const bfd_vma elf32_arm_vxworks_exec_plt0_entry[] =
1936 0xe52dc008, /* str ip,[sp,#-8]! */
1937 0xe59fc000, /* ldr ip,[pc] */
1938 0xe59cf008, /* ldr pc,[ip,#8] */
1939 0x00000000, /* .long _GLOBAL_OFFSET_TABLE_ */
1942 /* The format of subsequent entries in a VxWorks executable. */
1943 static const bfd_vma elf32_arm_vxworks_exec_plt_entry[] =
1945 0xe59fc000, /* ldr ip,[pc] */
1946 0xe59cf000, /* ldr pc,[ip] */
1947 0x00000000, /* .long @got */
1948 0xe59fc000, /* ldr ip,[pc] */
1949 0xea000000, /* b _PLT */
1950 0x00000000, /* .long @pltindex*sizeof(Elf32_Rela) */
1953 /* The format of entries in a VxWorks shared library. */
1954 static const bfd_vma elf32_arm_vxworks_shared_plt_entry[] =
1956 0xe59fc000, /* ldr ip,[pc] */
1957 0xe79cf009, /* ldr pc,[ip,r9] */
1958 0x00000000, /* .long @got */
1959 0xe59fc000, /* ldr ip,[pc] */
1960 0xe599f008, /* ldr pc,[r9,#8] */
1961 0x00000000, /* .long @pltindex*sizeof(Elf32_Rela) */
1964 /* An initial stub used if the PLT entry is referenced from Thumb code. */
1965 #define PLT_THUMB_STUB_SIZE 4
1966 static const bfd_vma elf32_arm_plt_thumb_stub [] =
1968 0x4778, /* bx pc */
1969 0x46c0 /* nop */
1972 /* The entries in a PLT when using a DLL-based target with multiple
1973 address spaces. */
1974 static const bfd_vma elf32_arm_symbian_plt_entry [] =
1976 0xe51ff004, /* ldr pc, [pc, #-4] */
1977 0x00000000, /* dcd R_ARM_GLOB_DAT(X) */
1980 /* Used to build a map of a section. This is required for mixed-endian
1981 code/data. */
1983 typedef struct elf32_elf_section_map
1985 bfd_vma vma;
1986 char type;
1988 elf32_arm_section_map;
1990 typedef struct _arm_elf_section_data
1992 struct bfd_elf_section_data elf;
1993 unsigned int mapcount;
1994 elf32_arm_section_map *map;
1996 _arm_elf_section_data;
1998 #define elf32_arm_section_data(sec) \
1999 ((_arm_elf_section_data *) elf_section_data (sec))
2001 /* The size of the thread control block. */
2002 #define TCB_SIZE 8
2004 #define NUM_KNOWN_ATTRIBUTES 32
2006 typedef struct aeabi_attribute
2008 int type;
2009 unsigned int i;
2010 char *s;
2011 } aeabi_attribute;
2013 typedef struct aeabi_attribute_list
2015 struct aeabi_attribute_list *next;
2016 int tag;
2017 aeabi_attribute attr;
2018 } aeabi_attribute_list;
2020 struct elf32_arm_obj_tdata
2022 struct elf_obj_tdata root;
2024 /* tls_type for each local got entry. */
2025 char *local_got_tls_type;
2027 aeabi_attribute known_eabi_attributes[NUM_KNOWN_ATTRIBUTES];
2028 aeabi_attribute_list *other_eabi_attributes;
2031 #define elf32_arm_tdata(abfd) \
2032 ((struct elf32_arm_obj_tdata *) (abfd)->tdata.any)
2034 #define elf32_arm_local_got_tls_type(abfd) \
2035 (elf32_arm_tdata (abfd)->local_got_tls_type)
2037 static bfd_boolean
2038 elf32_arm_mkobject (bfd *abfd)
2040 if (abfd->tdata.any == NULL)
2042 bfd_size_type amt = sizeof (struct elf32_arm_obj_tdata);
2043 abfd->tdata.any = bfd_zalloc (abfd, amt);
2044 if (abfd->tdata.any == NULL)
2045 return FALSE;
2047 return bfd_elf_mkobject (abfd);
2050 /* The ARM linker needs to keep track of the number of relocs that it
2051 decides to copy in check_relocs for each symbol. This is so that
2052 it can discard PC relative relocs if it doesn't need them when
2053 linking with -Bsymbolic. We store the information in a field
2054 extending the regular ELF linker hash table. */
2056 /* This structure keeps track of the number of relocs we have copied
2057 for a given symbol. */
2058 struct elf32_arm_relocs_copied
2060 /* Next section. */
2061 struct elf32_arm_relocs_copied * next;
2062 /* A section in dynobj. */
2063 asection * section;
2064 /* Number of relocs copied in this section. */
2065 bfd_size_type count;
2066 /* Number of PC-relative relocs copied in this section. */
2067 bfd_size_type pc_count;
2070 #define elf32_arm_hash_entry(ent) ((struct elf32_arm_link_hash_entry *)(ent))
2072 /* Arm ELF linker hash entry. */
2073 struct elf32_arm_link_hash_entry
2075 struct elf_link_hash_entry root;
2077 /* Number of PC relative relocs copied for this symbol. */
2078 struct elf32_arm_relocs_copied * relocs_copied;
2080 /* We reference count Thumb references to a PLT entry separately,
2081 so that we can emit the Thumb trampoline only if needed. */
2082 bfd_signed_vma plt_thumb_refcount;
2084 /* Since PLT entries have variable size if the Thumb prologue is
2085 used, we need to record the index into .got.plt instead of
2086 recomputing it from the PLT offset. */
2087 bfd_signed_vma plt_got_offset;
2089 #define GOT_UNKNOWN 0
2090 #define GOT_NORMAL 1
2091 #define GOT_TLS_GD 2
2092 #define GOT_TLS_IE 4
2093 unsigned char tls_type;
2095 /* The symbol marking the real symbol location for exported thumb
2096 symbols with Arm stubs. */
2097 struct elf_link_hash_entry *export_glue;
2100 /* Traverse an arm ELF linker hash table. */
2101 #define elf32_arm_link_hash_traverse(table, func, info) \
2102 (elf_link_hash_traverse \
2103 (&(table)->root, \
2104 (bfd_boolean (*) (struct elf_link_hash_entry *, void *)) (func), \
2105 (info)))
2107 /* Get the ARM elf linker hash table from a link_info structure. */
2108 #define elf32_arm_hash_table(info) \
2109 ((struct elf32_arm_link_hash_table *) ((info)->hash))
2111 /* ARM ELF linker hash table. */
2112 struct elf32_arm_link_hash_table
2114 /* The main hash table. */
2115 struct elf_link_hash_table root;
2117 /* The size in bytes of the section containing the Thumb-to-ARM glue. */
2118 bfd_size_type thumb_glue_size;
2120 /* The size in bytes of the section containing the ARM-to-Thumb glue. */
2121 bfd_size_type arm_glue_size;
2123 /* An arbitrary input BFD chosen to hold the glue sections. */
2124 bfd * bfd_of_glue_owner;
2126 /* Nonzero to output a BE8 image. */
2127 int byteswap_code;
2129 /* Zero if R_ARM_TARGET1 means R_ARM_ABS32.
2130 Nonzero if R_ARM_TARGET1 means R_ARM_REL32. */
2131 int target1_is_rel;
2133 /* The relocation to use for R_ARM_TARGET2 relocations. */
2134 int target2_reloc;
2136 /* Nonzero to fix BX instructions for ARMv4 targets. */
2137 int fix_v4bx;
2139 /* Nonzero if the ARM/Thumb BLX instructions are available for use. */
2140 int use_blx;
2142 /* The number of bytes in the initial entry in the PLT. */
2143 bfd_size_type plt_header_size;
2145 /* The number of bytes in the subsequent PLT etries. */
2146 bfd_size_type plt_entry_size;
2148 /* True if the target system is VxWorks. */
2149 int vxworks_p;
2151 /* True if the target system is Symbian OS. */
2152 int symbian_p;
2154 /* True if the target uses REL relocations. */
2155 int use_rel;
2157 /* Short-cuts to get to dynamic linker sections. */
2158 asection *sgot;
2159 asection *sgotplt;
2160 asection *srelgot;
2161 asection *splt;
2162 asection *srelplt;
2163 asection *sdynbss;
2164 asection *srelbss;
2166 /* The (unloaded but important) VxWorks .rela.plt.unloaded section. */
2167 asection *srelplt2;
2169 /* Data for R_ARM_TLS_LDM32 relocations. */
2170 union {
2171 bfd_signed_vma refcount;
2172 bfd_vma offset;
2173 } tls_ldm_got;
2175 /* Small local sym to section mapping cache. */
2176 struct sym_sec_cache sym_sec;
2178 /* For convenience in allocate_dynrelocs. */
2179 bfd * obfd;
2182 /* Create an entry in an ARM ELF linker hash table. */
2184 static struct bfd_hash_entry *
2185 elf32_arm_link_hash_newfunc (struct bfd_hash_entry * entry,
2186 struct bfd_hash_table * table,
2187 const char * string)
2189 struct elf32_arm_link_hash_entry * ret =
2190 (struct elf32_arm_link_hash_entry *) entry;
2192 /* Allocate the structure if it has not already been allocated by a
2193 subclass. */
2194 if (ret == (struct elf32_arm_link_hash_entry *) NULL)
2195 ret = bfd_hash_allocate (table, sizeof (struct elf32_arm_link_hash_entry));
2196 if (ret == NULL)
2197 return (struct bfd_hash_entry *) ret;
2199 /* Call the allocation method of the superclass. */
2200 ret = ((struct elf32_arm_link_hash_entry *)
2201 _bfd_elf_link_hash_newfunc ((struct bfd_hash_entry *) ret,
2202 table, string));
2203 if (ret != NULL)
2205 ret->relocs_copied = NULL;
2206 ret->tls_type = GOT_UNKNOWN;
2207 ret->plt_thumb_refcount = 0;
2208 ret->plt_got_offset = -1;
2209 ret->export_glue = NULL;
2212 return (struct bfd_hash_entry *) ret;
2215 /* Return true if NAME is the name of the relocation section associated
2216 with S. */
2218 static bfd_boolean
2219 reloc_section_p (struct elf32_arm_link_hash_table *htab,
2220 const char *name, asection *s)
2222 if (htab->use_rel)
2223 return CONST_STRNEQ (name, ".rel") && strcmp (s->name, name + 4) == 0;
2224 else
2225 return CONST_STRNEQ (name, ".rela") && strcmp (s->name, name + 5) == 0;
2228 /* Create .got, .gotplt, and .rel(a).got sections in DYNOBJ, and set up
2229 shortcuts to them in our hash table. */
2231 static bfd_boolean
2232 create_got_section (bfd *dynobj, struct bfd_link_info *info)
2234 struct elf32_arm_link_hash_table *htab;
2236 htab = elf32_arm_hash_table (info);
2237 /* BPABI objects never have a GOT, or associated sections. */
2238 if (htab->symbian_p)
2239 return TRUE;
2241 if (! _bfd_elf_create_got_section (dynobj, info))
2242 return FALSE;
2244 htab->sgot = bfd_get_section_by_name (dynobj, ".got");
2245 htab->sgotplt = bfd_get_section_by_name (dynobj, ".got.plt");
2246 if (!htab->sgot || !htab->sgotplt)
2247 abort ();
2249 htab->srelgot = bfd_make_section_with_flags (dynobj,
2250 RELOC_SECTION (htab, ".got"),
2251 (SEC_ALLOC | SEC_LOAD
2252 | SEC_HAS_CONTENTS
2253 | SEC_IN_MEMORY
2254 | SEC_LINKER_CREATED
2255 | SEC_READONLY));
2256 if (htab->srelgot == NULL
2257 || ! bfd_set_section_alignment (dynobj, htab->srelgot, 2))
2258 return FALSE;
2259 return TRUE;
2262 /* Create .plt, .rel(a).plt, .got, .got.plt, .rel(a).got, .dynbss, and
2263 .rel(a).bss sections in DYNOBJ, and set up shortcuts to them in our
2264 hash table. */
2266 static bfd_boolean
2267 elf32_arm_create_dynamic_sections (bfd *dynobj, struct bfd_link_info *info)
2269 struct elf32_arm_link_hash_table *htab;
2271 htab = elf32_arm_hash_table (info);
2272 if (!htab->sgot && !create_got_section (dynobj, info))
2273 return FALSE;
2275 if (!_bfd_elf_create_dynamic_sections (dynobj, info))
2276 return FALSE;
2278 htab->splt = bfd_get_section_by_name (dynobj, ".plt");
2279 htab->srelplt = bfd_get_section_by_name (dynobj,
2280 RELOC_SECTION (htab, ".plt"));
2281 htab->sdynbss = bfd_get_section_by_name (dynobj, ".dynbss");
2282 if (!info->shared)
2283 htab->srelbss = bfd_get_section_by_name (dynobj,
2284 RELOC_SECTION (htab, ".bss"));
2286 if (htab->vxworks_p)
2288 if (!elf_vxworks_create_dynamic_sections (dynobj, info, &htab->srelplt2))
2289 return FALSE;
2291 if (info->shared)
2293 htab->plt_header_size = 0;
2294 htab->plt_entry_size
2295 = 4 * ARRAY_SIZE (elf32_arm_vxworks_shared_plt_entry);
2297 else
2299 htab->plt_header_size
2300 = 4 * ARRAY_SIZE (elf32_arm_vxworks_exec_plt0_entry);
2301 htab->plt_entry_size
2302 = 4 * ARRAY_SIZE (elf32_arm_vxworks_exec_plt_entry);
2306 if (!htab->splt
2307 || !htab->srelplt
2308 || !htab->sdynbss
2309 || (!info->shared && !htab->srelbss))
2310 abort ();
2312 return TRUE;
2315 /* Copy the extra info we tack onto an elf_link_hash_entry. */
2317 static void
2318 elf32_arm_copy_indirect_symbol (struct bfd_link_info *info,
2319 struct elf_link_hash_entry *dir,
2320 struct elf_link_hash_entry *ind)
2322 struct elf32_arm_link_hash_entry *edir, *eind;
2324 edir = (struct elf32_arm_link_hash_entry *) dir;
2325 eind = (struct elf32_arm_link_hash_entry *) ind;
2327 if (eind->relocs_copied != NULL)
2329 if (edir->relocs_copied != NULL)
2331 struct elf32_arm_relocs_copied **pp;
2332 struct elf32_arm_relocs_copied *p;
2334 /* Add reloc counts against the indirect sym to the direct sym
2335 list. Merge any entries against the same section. */
2336 for (pp = &eind->relocs_copied; (p = *pp) != NULL; )
2338 struct elf32_arm_relocs_copied *q;
2340 for (q = edir->relocs_copied; q != NULL; q = q->next)
2341 if (q->section == p->section)
2343 q->pc_count += p->pc_count;
2344 q->count += p->count;
2345 *pp = p->next;
2346 break;
2348 if (q == NULL)
2349 pp = &p->next;
2351 *pp = edir->relocs_copied;
2354 edir->relocs_copied = eind->relocs_copied;
2355 eind->relocs_copied = NULL;
2358 if (ind->root.type == bfd_link_hash_indirect)
2360 /* Copy over PLT info. */
2361 edir->plt_thumb_refcount += eind->plt_thumb_refcount;
2362 eind->plt_thumb_refcount = 0;
2364 if (dir->got.refcount <= 0)
2366 edir->tls_type = eind->tls_type;
2367 eind->tls_type = GOT_UNKNOWN;
2371 _bfd_elf_link_hash_copy_indirect (info, dir, ind);
2374 /* Create an ARM elf linker hash table. */
2376 static struct bfd_link_hash_table *
2377 elf32_arm_link_hash_table_create (bfd *abfd)
2379 struct elf32_arm_link_hash_table *ret;
2380 bfd_size_type amt = sizeof (struct elf32_arm_link_hash_table);
2382 ret = bfd_malloc (amt);
2383 if (ret == NULL)
2384 return NULL;
2386 if (!_bfd_elf_link_hash_table_init (& ret->root, abfd,
2387 elf32_arm_link_hash_newfunc,
2388 sizeof (struct elf32_arm_link_hash_entry)))
2390 free (ret);
2391 return NULL;
2394 ret->sgot = NULL;
2395 ret->sgotplt = NULL;
2396 ret->srelgot = NULL;
2397 ret->splt = NULL;
2398 ret->srelplt = NULL;
2399 ret->sdynbss = NULL;
2400 ret->srelbss = NULL;
2401 ret->srelplt2 = NULL;
2402 ret->thumb_glue_size = 0;
2403 ret->arm_glue_size = 0;
2404 ret->bfd_of_glue_owner = NULL;
2405 ret->byteswap_code = 0;
2406 ret->target1_is_rel = 0;
2407 ret->target2_reloc = R_ARM_NONE;
2408 #ifdef FOUR_WORD_PLT
2409 ret->plt_header_size = 16;
2410 ret->plt_entry_size = 16;
2411 #else
2412 ret->plt_header_size = 20;
2413 ret->plt_entry_size = 12;
2414 #endif
2415 ret->fix_v4bx = 0;
2416 ret->use_blx = 0;
2417 ret->vxworks_p = 0;
2418 ret->symbian_p = 0;
2419 ret->use_rel = 1;
2420 ret->sym_sec.abfd = NULL;
2421 ret->obfd = abfd;
2422 ret->tls_ldm_got.refcount = 0;
2424 return &ret->root.root;
2427 /* Locate the Thumb encoded calling stub for NAME. */
2429 static struct elf_link_hash_entry *
2430 find_thumb_glue (struct bfd_link_info *link_info,
2431 const char *name,
2432 char **error_message)
2434 char *tmp_name;
2435 struct elf_link_hash_entry *hash;
2436 struct elf32_arm_link_hash_table *hash_table;
2438 /* We need a pointer to the armelf specific hash table. */
2439 hash_table = elf32_arm_hash_table (link_info);
2441 tmp_name = bfd_malloc ((bfd_size_type) strlen (name)
2442 + strlen (THUMB2ARM_GLUE_ENTRY_NAME) + 1);
2444 BFD_ASSERT (tmp_name);
2446 sprintf (tmp_name, THUMB2ARM_GLUE_ENTRY_NAME, name);
2448 hash = elf_link_hash_lookup
2449 (&(hash_table)->root, tmp_name, FALSE, FALSE, TRUE);
2451 if (hash == NULL)
2452 asprintf (error_message, _("unable to find THUMB glue '%s' for '%s'"),
2453 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 char **error_message)
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 asprintf (error_message, _("unable to find ARM glue '%s' for '%s'"),
2486 tmp_name, name);
2488 free (tmp_name);
2490 return myh;
2493 /* ARM->Thumb glue (static images):
2495 .arm
2496 __func_from_arm:
2497 ldr r12, __func_addr
2498 bx r12
2499 __func_addr:
2500 .word func @ behave as if you saw a ARM_32 reloc.
2502 (relocatable images)
2503 .arm
2504 __func_from_arm:
2505 ldr r12, __func_offset
2506 add r12, r12, pc
2507 bx r12
2508 __func_offset:
2509 .word func - .
2512 #define ARM2THUMB_STATIC_GLUE_SIZE 12
2513 static const insn32 a2t1_ldr_insn = 0xe59fc000;
2514 static const insn32 a2t2_bx_r12_insn = 0xe12fff1c;
2515 static const insn32 a2t3_func_addr_insn = 0x00000001;
2517 #define ARM2THUMB_PIC_GLUE_SIZE 16
2518 static const insn32 a2t1p_ldr_insn = 0xe59fc004;
2519 static const insn32 a2t2p_add_pc_insn = 0xe08cc00f;
2520 static const insn32 a2t3p_bx_r12_insn = 0xe12fff1c;
2522 /* Thumb->ARM: Thumb->(non-interworking aware) ARM
2524 .thumb .thumb
2525 .align 2 .align 2
2526 __func_from_thumb: __func_from_thumb:
2527 bx pc push {r6, lr}
2528 nop ldr r6, __func_addr
2529 .arm mov lr, pc
2530 __func_change_to_arm: bx r6
2531 b func .arm
2532 __func_back_to_thumb:
2533 ldmia r13! {r6, lr}
2534 bx lr
2535 __func_addr:
2536 .word func */
2538 #define THUMB2ARM_GLUE_SIZE 8
2539 static const insn16 t2a1_bx_pc_insn = 0x4778;
2540 static const insn16 t2a2_noop_insn = 0x46c0;
2541 static const insn32 t2a3_b_insn = 0xea000000;
2543 #ifndef ELFARM_NABI_C_INCLUDED
2544 bfd_boolean
2545 bfd_elf32_arm_allocate_interworking_sections (struct bfd_link_info * info)
2547 asection * s;
2548 bfd_byte * foo;
2549 struct elf32_arm_link_hash_table * globals;
2551 globals = elf32_arm_hash_table (info);
2553 BFD_ASSERT (globals != NULL);
2555 if (globals->arm_glue_size != 0)
2557 BFD_ASSERT (globals->bfd_of_glue_owner != NULL);
2559 s = bfd_get_section_by_name (globals->bfd_of_glue_owner,
2560 ARM2THUMB_GLUE_SECTION_NAME);
2562 BFD_ASSERT (s != NULL);
2564 foo = bfd_alloc (globals->bfd_of_glue_owner, globals->arm_glue_size);
2566 BFD_ASSERT (s->size == globals->arm_glue_size);
2567 s->contents = foo;
2570 if (globals->thumb_glue_size != 0)
2572 BFD_ASSERT (globals->bfd_of_glue_owner != NULL);
2574 s = bfd_get_section_by_name
2575 (globals->bfd_of_glue_owner, THUMB2ARM_GLUE_SECTION_NAME);
2577 BFD_ASSERT (s != NULL);
2579 foo = bfd_alloc (globals->bfd_of_glue_owner, globals->thumb_glue_size);
2581 BFD_ASSERT (s->size == globals->thumb_glue_size);
2582 s->contents = foo;
2585 return TRUE;
2588 /* Allocate space and symbols for calling a Thumb function from Arm mode.
2589 returns the symbol identifying teh stub. */
2590 static struct elf_link_hash_entry *
2591 record_arm_to_thumb_glue (struct bfd_link_info * link_info,
2592 struct elf_link_hash_entry * h)
2594 const char * name = h->root.root.string;
2595 asection * s;
2596 char * tmp_name;
2597 struct elf_link_hash_entry * myh;
2598 struct bfd_link_hash_entry * bh;
2599 struct elf32_arm_link_hash_table * globals;
2600 bfd_vma val;
2601 bfd_size_type size;
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 size = ARM2THUMB_PIC_GLUE_SIZE;
2646 else
2647 size = ARM2THUMB_STATIC_GLUE_SIZE;
2649 s->size += size;
2650 globals->arm_glue_size += size;
2652 return myh;
2655 static void
2656 record_thumb_to_arm_glue (struct bfd_link_info *link_info,
2657 struct elf_link_hash_entry *h)
2659 const char *name = h->root.root.string;
2660 asection *s;
2661 char *tmp_name;
2662 struct elf_link_hash_entry *myh;
2663 struct bfd_link_hash_entry *bh;
2664 struct elf32_arm_link_hash_table *hash_table;
2665 bfd_vma val;
2667 hash_table = elf32_arm_hash_table (link_info);
2669 BFD_ASSERT (hash_table != NULL);
2670 BFD_ASSERT (hash_table->bfd_of_glue_owner != NULL);
2672 s = bfd_get_section_by_name
2673 (hash_table->bfd_of_glue_owner, THUMB2ARM_GLUE_SECTION_NAME);
2675 BFD_ASSERT (s != NULL);
2677 tmp_name = bfd_malloc ((bfd_size_type) strlen (name)
2678 + strlen (THUMB2ARM_GLUE_ENTRY_NAME) + 1);
2680 BFD_ASSERT (tmp_name);
2682 sprintf (tmp_name, THUMB2ARM_GLUE_ENTRY_NAME, name);
2684 myh = elf_link_hash_lookup
2685 (&(hash_table)->root, tmp_name, FALSE, FALSE, TRUE);
2687 if (myh != NULL)
2689 /* We've already seen this guy. */
2690 free (tmp_name);
2691 return;
2694 bh = NULL;
2695 val = hash_table->thumb_glue_size + 1;
2696 _bfd_generic_link_add_one_symbol (link_info, hash_table->bfd_of_glue_owner,
2697 tmp_name, BSF_GLOBAL, s, val,
2698 NULL, TRUE, FALSE, &bh);
2700 /* If we mark it 'Thumb', the disassembler will do a better job. */
2701 myh = (struct elf_link_hash_entry *) bh;
2702 myh->type = ELF_ST_INFO (STB_LOCAL, STT_ARM_TFUNC);
2703 myh->forced_local = 1;
2705 free (tmp_name);
2707 #define CHANGE_TO_ARM "__%s_change_to_arm"
2708 #define BACK_FROM_ARM "__%s_back_from_arm"
2710 /* Allocate another symbol to mark where we switch to Arm mode. */
2711 tmp_name = bfd_malloc ((bfd_size_type) strlen (name)
2712 + strlen (CHANGE_TO_ARM) + 1);
2714 BFD_ASSERT (tmp_name);
2716 sprintf (tmp_name, CHANGE_TO_ARM, name);
2718 bh = NULL;
2719 val = hash_table->thumb_glue_size + 4,
2720 _bfd_generic_link_add_one_symbol (link_info, hash_table->bfd_of_glue_owner,
2721 tmp_name, BSF_LOCAL, s, val,
2722 NULL, TRUE, FALSE, &bh);
2724 free (tmp_name);
2726 s->size += THUMB2ARM_GLUE_SIZE;
2727 hash_table->thumb_glue_size += THUMB2ARM_GLUE_SIZE;
2729 return;
2732 /* Add the glue sections to ABFD. This function is called from the
2733 linker scripts in ld/emultempl/{armelf}.em. */
2735 bfd_boolean
2736 bfd_elf32_arm_add_glue_sections_to_bfd (bfd *abfd,
2737 struct bfd_link_info *info)
2739 flagword flags;
2740 asection *sec;
2742 /* If we are only performing a partial
2743 link do not bother adding the glue. */
2744 if (info->relocatable)
2745 return TRUE;
2747 sec = bfd_get_section_by_name (abfd, ARM2THUMB_GLUE_SECTION_NAME);
2749 if (sec == NULL)
2751 /* Note: we do not include the flag SEC_LINKER_CREATED, as this
2752 will prevent elf_link_input_bfd() from processing the contents
2753 of this section. */
2754 flags = (SEC_ALLOC | SEC_LOAD | SEC_HAS_CONTENTS | SEC_IN_MEMORY
2755 | SEC_CODE | SEC_READONLY);
2757 sec = bfd_make_section_with_flags (abfd,
2758 ARM2THUMB_GLUE_SECTION_NAME,
2759 flags);
2761 if (sec == NULL
2762 || !bfd_set_section_alignment (abfd, sec, 2))
2763 return FALSE;
2765 /* Set the gc mark to prevent the section from being removed by garbage
2766 collection, despite the fact that no relocs refer to this section. */
2767 sec->gc_mark = 1;
2770 sec = bfd_get_section_by_name (abfd, THUMB2ARM_GLUE_SECTION_NAME);
2772 if (sec == NULL)
2774 flags = (SEC_ALLOC | SEC_LOAD | SEC_HAS_CONTENTS | SEC_IN_MEMORY
2775 | SEC_CODE | SEC_READONLY);
2777 sec = bfd_make_section_with_flags (abfd,
2778 THUMB2ARM_GLUE_SECTION_NAME,
2779 flags);
2781 if (sec == NULL
2782 || !bfd_set_section_alignment (abfd, sec, 2))
2783 return FALSE;
2785 sec->gc_mark = 1;
2788 return TRUE;
2791 /* Select a BFD to be used to hold the sections used by the glue code.
2792 This function is called from the linker scripts in ld/emultempl/
2793 {armelf/pe}.em */
2795 bfd_boolean
2796 bfd_elf32_arm_get_bfd_for_interworking (bfd *abfd, struct bfd_link_info *info)
2798 struct elf32_arm_link_hash_table *globals;
2800 /* If we are only performing a partial link
2801 do not bother getting a bfd to hold the glue. */
2802 if (info->relocatable)
2803 return TRUE;
2805 /* Make sure we don't attach the glue sections to a dynamic object. */
2806 BFD_ASSERT (!(abfd->flags & DYNAMIC));
2808 globals = elf32_arm_hash_table (info);
2810 BFD_ASSERT (globals != NULL);
2812 if (globals->bfd_of_glue_owner != NULL)
2813 return TRUE;
2815 /* Save the bfd for later use. */
2816 globals->bfd_of_glue_owner = abfd;
2818 return TRUE;
2821 static void check_use_blx(struct elf32_arm_link_hash_table *globals)
2823 if (elf32_arm_get_eabi_attr_int (globals->obfd, Tag_CPU_arch) > 2)
2824 globals->use_blx = 1;
2827 bfd_boolean
2828 bfd_elf32_arm_process_before_allocation (bfd *abfd,
2829 struct bfd_link_info *link_info)
2831 Elf_Internal_Shdr *symtab_hdr;
2832 Elf_Internal_Rela *internal_relocs = NULL;
2833 Elf_Internal_Rela *irel, *irelend;
2834 bfd_byte *contents = NULL;
2836 asection *sec;
2837 struct elf32_arm_link_hash_table *globals;
2839 /* If we are only performing a partial link do not bother
2840 to construct any glue. */
2841 if (link_info->relocatable)
2842 return TRUE;
2844 /* Here we have a bfd that is to be included on the link. We have a hook
2845 to do reloc rummaging, before section sizes are nailed down. */
2846 globals = elf32_arm_hash_table (link_info);
2847 check_use_blx (globals);
2849 BFD_ASSERT (globals != NULL);
2850 BFD_ASSERT (globals->bfd_of_glue_owner != NULL);
2852 if (globals->byteswap_code && !bfd_big_endian (abfd))
2854 _bfd_error_handler (_("%B: BE8 images only valid in big-endian mode."),
2855 abfd);
2856 return FALSE;
2859 /* Rummage around all the relocs and map the glue vectors. */
2860 sec = abfd->sections;
2862 if (sec == NULL)
2863 return TRUE;
2865 for (; sec != NULL; sec = sec->next)
2867 if (sec->reloc_count == 0)
2868 continue;
2870 if ((sec->flags & SEC_EXCLUDE) != 0)
2871 continue;
2873 symtab_hdr = &elf_tdata (abfd)->symtab_hdr;
2875 /* Load the relocs. */
2876 internal_relocs
2877 = _bfd_elf_link_read_relocs (abfd, sec, (void *) NULL,
2878 (Elf_Internal_Rela *) NULL, FALSE);
2880 if (internal_relocs == NULL)
2881 goto error_return;
2883 irelend = internal_relocs + sec->reloc_count;
2884 for (irel = internal_relocs; irel < irelend; irel++)
2886 long r_type;
2887 unsigned long r_index;
2889 struct elf_link_hash_entry *h;
2891 r_type = ELF32_R_TYPE (irel->r_info);
2892 r_index = ELF32_R_SYM (irel->r_info);
2894 /* These are the only relocation types we care about. */
2895 if ( r_type != R_ARM_PC24
2896 && r_type != R_ARM_PLT32
2897 && r_type != R_ARM_CALL
2898 && r_type != R_ARM_JUMP24
2899 && r_type != R_ARM_THM_CALL)
2900 continue;
2902 /* Get the section contents if we haven't done so already. */
2903 if (contents == NULL)
2905 /* Get cached copy if it exists. */
2906 if (elf_section_data (sec)->this_hdr.contents != NULL)
2907 contents = elf_section_data (sec)->this_hdr.contents;
2908 else
2910 /* Go get them off disk. */
2911 if (! bfd_malloc_and_get_section (abfd, sec, &contents))
2912 goto error_return;
2916 /* If the relocation is not against a symbol it cannot concern us. */
2917 h = NULL;
2919 /* We don't care about local symbols. */
2920 if (r_index < symtab_hdr->sh_info)
2921 continue;
2923 /* This is an external symbol. */
2924 r_index -= symtab_hdr->sh_info;
2925 h = (struct elf_link_hash_entry *)
2926 elf_sym_hashes (abfd)[r_index];
2928 /* If the relocation is against a static symbol it must be within
2929 the current section and so cannot be a cross ARM/Thumb relocation. */
2930 if (h == NULL)
2931 continue;
2933 /* If the call will go through a PLT entry then we do not need
2934 glue. */
2935 if (globals->splt != NULL && h->plt.offset != (bfd_vma) -1)
2936 continue;
2938 switch (r_type)
2940 case R_ARM_PC24:
2941 case R_ARM_PLT32:
2942 case R_ARM_CALL:
2943 case R_ARM_JUMP24:
2944 /* This one is a call from arm code. We need to look up
2945 the target of the call. If it is a thumb target, we
2946 insert glue. */
2947 if (ELF_ST_TYPE(h->type) == STT_ARM_TFUNC
2948 && !(r_type == R_ARM_CALL && globals->use_blx))
2949 record_arm_to_thumb_glue (link_info, h);
2950 break;
2952 case R_ARM_THM_CALL:
2953 /* This one is a call from thumb code. We look
2954 up the target of the call. If it is not a thumb
2955 target, we insert glue. */
2956 if (ELF_ST_TYPE (h->type) != STT_ARM_TFUNC && !globals->use_blx)
2957 record_thumb_to_arm_glue (link_info, h);
2958 break;
2960 default:
2961 abort ();
2965 if (contents != NULL
2966 && elf_section_data (sec)->this_hdr.contents != contents)
2967 free (contents);
2968 contents = NULL;
2970 if (internal_relocs != NULL
2971 && elf_section_data (sec)->relocs != internal_relocs)
2972 free (internal_relocs);
2973 internal_relocs = NULL;
2976 return TRUE;
2978 error_return:
2979 if (contents != NULL
2980 && elf_section_data (sec)->this_hdr.contents != contents)
2981 free (contents);
2982 if (internal_relocs != NULL
2983 && elf_section_data (sec)->relocs != internal_relocs)
2984 free (internal_relocs);
2986 return FALSE;
2988 #endif
2991 /* Set target relocation values needed during linking. */
2993 void
2994 bfd_elf32_arm_set_target_relocs (struct bfd_link_info *link_info,
2995 int target1_is_rel,
2996 char * target2_type,
2997 int fix_v4bx,
2998 int use_blx)
3000 struct elf32_arm_link_hash_table *globals;
3002 globals = elf32_arm_hash_table (link_info);
3004 globals->target1_is_rel = target1_is_rel;
3005 if (strcmp (target2_type, "rel") == 0)
3006 globals->target2_reloc = R_ARM_REL32;
3007 else if (strcmp (target2_type, "abs") == 0)
3008 globals->target2_reloc = R_ARM_ABS32;
3009 else if (strcmp (target2_type, "got-rel") == 0)
3010 globals->target2_reloc = R_ARM_GOT_PREL;
3011 else
3013 _bfd_error_handler (_("Invalid TARGET2 relocation type '%s'."),
3014 target2_type);
3016 globals->fix_v4bx = fix_v4bx;
3017 globals->use_blx |= use_blx;
3020 /* The thumb form of a long branch is a bit finicky, because the offset
3021 encoding is split over two fields, each in it's own instruction. They
3022 can occur in any order. So given a thumb form of long branch, and an
3023 offset, insert the offset into the thumb branch and return finished
3024 instruction.
3026 It takes two thumb instructions to encode the target address. Each has
3027 11 bits to invest. The upper 11 bits are stored in one (identified by
3028 H-0.. see below), the lower 11 bits are stored in the other (identified
3029 by H-1).
3031 Combine together and shifted left by 1 (it's a half word address) and
3032 there you have it.
3034 Op: 1111 = F,
3035 H-0, upper address-0 = 000
3036 Op: 1111 = F,
3037 H-1, lower address-0 = 800
3039 They can be ordered either way, but the arm tools I've seen always put
3040 the lower one first. It probably doesn't matter. krk@cygnus.com
3042 XXX: Actually the order does matter. The second instruction (H-1)
3043 moves the computed address into the PC, so it must be the second one
3044 in the sequence. The problem, however is that whilst little endian code
3045 stores the instructions in HI then LOW order, big endian code does the
3046 reverse. nickc@cygnus.com. */
3048 #define LOW_HI_ORDER 0xF800F000
3049 #define HI_LOW_ORDER 0xF000F800
3051 static insn32
3052 insert_thumb_branch (insn32 br_insn, int rel_off)
3054 unsigned int low_bits;
3055 unsigned int high_bits;
3057 BFD_ASSERT ((rel_off & 1) != 1);
3059 rel_off >>= 1; /* Half word aligned address. */
3060 low_bits = rel_off & 0x000007FF; /* The bottom 11 bits. */
3061 high_bits = (rel_off >> 11) & 0x000007FF; /* The top 11 bits. */
3063 if ((br_insn & LOW_HI_ORDER) == LOW_HI_ORDER)
3064 br_insn = LOW_HI_ORDER | (low_bits << 16) | high_bits;
3065 else if ((br_insn & HI_LOW_ORDER) == HI_LOW_ORDER)
3066 br_insn = HI_LOW_ORDER | (high_bits << 16) | low_bits;
3067 else
3068 /* FIXME: abort is probably not the right call. krk@cygnus.com */
3069 abort (); /* Error - not a valid branch instruction form. */
3071 return br_insn;
3075 /* Store an Arm insn into an output section not processed by
3076 elf32_arm_write_section. */
3078 static void
3079 put_arm_insn (struct elf32_arm_link_hash_table *htab,
3080 bfd * output_bfd, bfd_vma val, void * ptr)
3082 if (htab->byteswap_code != bfd_little_endian (output_bfd))
3083 bfd_putl32 (val, ptr);
3084 else
3085 bfd_putb32 (val, ptr);
3089 /* Store a 16-bit Thumb insn into an output section not processed by
3090 elf32_arm_write_section. */
3092 static void
3093 put_thumb_insn (struct elf32_arm_link_hash_table *htab,
3094 bfd * output_bfd, bfd_vma val, void * ptr)
3096 if (htab->byteswap_code != bfd_little_endian (output_bfd))
3097 bfd_putl16 (val, ptr);
3098 else
3099 bfd_putb16 (val, ptr);
3103 /* Thumb code calling an ARM function. */
3105 static int
3106 elf32_thumb_to_arm_stub (struct bfd_link_info * info,
3107 const char * name,
3108 bfd * input_bfd,
3109 bfd * output_bfd,
3110 asection * input_section,
3111 bfd_byte * hit_data,
3112 asection * sym_sec,
3113 bfd_vma offset,
3114 bfd_signed_vma addend,
3115 bfd_vma val,
3116 char **error_message)
3118 asection * s = 0;
3119 bfd_vma my_offset;
3120 unsigned long int tmp;
3121 long int ret_offset;
3122 struct elf_link_hash_entry * myh;
3123 struct elf32_arm_link_hash_table * globals;
3125 myh = find_thumb_glue (info, name, error_message);
3126 if (myh == NULL)
3127 return FALSE;
3129 globals = elf32_arm_hash_table (info);
3131 BFD_ASSERT (globals != NULL);
3132 BFD_ASSERT (globals->bfd_of_glue_owner != NULL);
3134 my_offset = myh->root.u.def.value;
3136 s = bfd_get_section_by_name (globals->bfd_of_glue_owner,
3137 THUMB2ARM_GLUE_SECTION_NAME);
3139 BFD_ASSERT (s != NULL);
3140 BFD_ASSERT (s->contents != NULL);
3141 BFD_ASSERT (s->output_section != NULL);
3143 if ((my_offset & 0x01) == 0x01)
3145 if (sym_sec != NULL
3146 && sym_sec->owner != NULL
3147 && !INTERWORK_FLAG (sym_sec->owner))
3149 (*_bfd_error_handler)
3150 (_("%B(%s): warning: interworking not enabled.\n"
3151 " first occurrence: %B: thumb call to arm"),
3152 sym_sec->owner, input_bfd, name);
3154 return FALSE;
3157 --my_offset;
3158 myh->root.u.def.value = my_offset;
3160 put_thumb_insn (globals, output_bfd, (bfd_vma) t2a1_bx_pc_insn,
3161 s->contents + my_offset);
3163 put_thumb_insn (globals, output_bfd, (bfd_vma) t2a2_noop_insn,
3164 s->contents + my_offset + 2);
3166 ret_offset =
3167 /* Address of destination of the stub. */
3168 ((bfd_signed_vma) val)
3169 - ((bfd_signed_vma)
3170 /* Offset from the start of the current section
3171 to the start of the stubs. */
3172 (s->output_offset
3173 /* Offset of the start of this stub from the start of the stubs. */
3174 + my_offset
3175 /* Address of the start of the current section. */
3176 + s->output_section->vma)
3177 /* The branch instruction is 4 bytes into the stub. */
3179 /* ARM branches work from the pc of the instruction + 8. */
3180 + 8);
3182 put_arm_insn (globals, output_bfd,
3183 (bfd_vma) t2a3_b_insn | ((ret_offset >> 2) & 0x00FFFFFF),
3184 s->contents + my_offset + 4);
3187 BFD_ASSERT (my_offset <= globals->thumb_glue_size);
3189 /* Now go back and fix up the original BL insn to point to here. */
3190 ret_offset =
3191 /* Address of where the stub is located. */
3192 (s->output_section->vma + s->output_offset + my_offset)
3193 /* Address of where the BL is located. */
3194 - (input_section->output_section->vma + input_section->output_offset
3195 + offset)
3196 /* Addend in the relocation. */
3197 - addend
3198 /* Biassing for PC-relative addressing. */
3199 - 8;
3201 tmp = bfd_get_32 (input_bfd, hit_data
3202 - input_section->vma);
3204 bfd_put_32 (output_bfd,
3205 (bfd_vma) insert_thumb_branch (tmp, ret_offset),
3206 hit_data - input_section->vma);
3208 return TRUE;
3211 /* Populate an Arm to Thumb stub. Returns the stub symbol. */
3213 static struct elf_link_hash_entry *
3214 elf32_arm_create_thumb_stub (struct bfd_link_info * info,
3215 const char * name,
3216 bfd * input_bfd,
3217 bfd * output_bfd,
3218 asection * sym_sec,
3219 bfd_vma val,
3220 asection *s,
3221 char **error_message)
3223 bfd_vma my_offset;
3224 long int ret_offset;
3225 struct elf_link_hash_entry * myh;
3226 struct elf32_arm_link_hash_table * globals;
3228 myh = find_arm_glue (info, name, error_message);
3229 if (myh == NULL)
3230 return NULL;
3232 globals = elf32_arm_hash_table (info);
3234 BFD_ASSERT (globals != NULL);
3235 BFD_ASSERT (globals->bfd_of_glue_owner != NULL);
3237 my_offset = myh->root.u.def.value;
3239 if ((my_offset & 0x01) == 0x01)
3241 if (sym_sec != NULL
3242 && sym_sec->owner != NULL
3243 && !INTERWORK_FLAG (sym_sec->owner))
3245 (*_bfd_error_handler)
3246 (_("%B(%s): warning: interworking not enabled.\n"
3247 " first occurrence: %B: arm call to thumb"),
3248 sym_sec->owner, input_bfd, name);
3251 --my_offset;
3252 myh->root.u.def.value = my_offset;
3254 if ((info->shared || globals->root.is_relocatable_executable))
3256 /* For relocatable objects we can't use absolute addresses,
3257 so construct the address from a relative offset. */
3258 /* TODO: If the offset is small it's probably worth
3259 constructing the address with adds. */
3260 put_arm_insn (globals, output_bfd, (bfd_vma) a2t1p_ldr_insn,
3261 s->contents + my_offset);
3262 put_arm_insn (globals, output_bfd, (bfd_vma) a2t2p_add_pc_insn,
3263 s->contents + my_offset + 4);
3264 put_arm_insn (globals, output_bfd, (bfd_vma) a2t3p_bx_r12_insn,
3265 s->contents + my_offset + 8);
3266 /* Adjust the offset by 4 for the position of the add,
3267 and 8 for the pipeline offset. */
3268 ret_offset = (val - (s->output_offset
3269 + s->output_section->vma
3270 + my_offset + 12))
3271 | 1;
3272 bfd_put_32 (output_bfd, ret_offset,
3273 s->contents + my_offset + 12);
3275 else
3277 put_arm_insn (globals, output_bfd, (bfd_vma) a2t1_ldr_insn,
3278 s->contents + my_offset);
3280 put_arm_insn (globals, output_bfd, (bfd_vma) a2t2_bx_r12_insn,
3281 s->contents + my_offset + 4);
3283 /* It's a thumb address. Add the low order bit. */
3284 bfd_put_32 (output_bfd, val | a2t3_func_addr_insn,
3285 s->contents + my_offset + 8);
3289 BFD_ASSERT (my_offset <= globals->arm_glue_size);
3291 return myh;
3294 /* Arm code calling a Thumb function. */
3296 static int
3297 elf32_arm_to_thumb_stub (struct bfd_link_info * info,
3298 const char * name,
3299 bfd * input_bfd,
3300 bfd * output_bfd,
3301 asection * input_section,
3302 bfd_byte * hit_data,
3303 asection * sym_sec,
3304 bfd_vma offset,
3305 bfd_signed_vma addend,
3306 bfd_vma val,
3307 char **error_message)
3309 unsigned long int tmp;
3310 bfd_vma my_offset;
3311 asection * s;
3312 long int ret_offset;
3313 struct elf_link_hash_entry * myh;
3314 struct elf32_arm_link_hash_table * globals;
3316 globals = elf32_arm_hash_table (info);
3318 BFD_ASSERT (globals != NULL);
3319 BFD_ASSERT (globals->bfd_of_glue_owner != NULL);
3321 s = bfd_get_section_by_name (globals->bfd_of_glue_owner,
3322 ARM2THUMB_GLUE_SECTION_NAME);
3323 BFD_ASSERT (s != NULL);
3324 BFD_ASSERT (s->contents != NULL);
3325 BFD_ASSERT (s->output_section != NULL);
3327 myh = elf32_arm_create_thumb_stub (info, name, input_bfd, output_bfd,
3328 sym_sec, val, s, error_message);
3329 if (!myh)
3330 return FALSE;
3332 my_offset = myh->root.u.def.value;
3333 tmp = bfd_get_32 (input_bfd, hit_data);
3334 tmp = tmp & 0xFF000000;
3336 /* Somehow these are both 4 too far, so subtract 8. */
3337 ret_offset = (s->output_offset
3338 + my_offset
3339 + s->output_section->vma
3340 - (input_section->output_offset
3341 + input_section->output_section->vma
3342 + offset + addend)
3343 - 8);
3345 tmp = tmp | ((ret_offset >> 2) & 0x00FFFFFF);
3347 bfd_put_32 (output_bfd, (bfd_vma) tmp, hit_data - input_section->vma);
3349 return TRUE;
3352 /* Populate Arm stub for an exported Thumb function. */
3354 static bfd_boolean
3355 elf32_arm_to_thumb_export_stub (struct elf_link_hash_entry *h, void * inf)
3357 struct bfd_link_info * info = (struct bfd_link_info *) inf;
3358 asection * s;
3359 struct elf_link_hash_entry * myh;
3360 struct elf32_arm_link_hash_entry *eh;
3361 struct elf32_arm_link_hash_table * globals;
3362 asection *sec;
3363 bfd_vma val;
3364 char *error_message;
3366 eh = elf32_arm_hash_entry(h);
3367 /* Allocate stubs for exported Thumb functions on v4t. */
3368 if (eh->export_glue == NULL)
3369 return TRUE;
3371 globals = elf32_arm_hash_table (info);
3373 BFD_ASSERT (globals != NULL);
3374 BFD_ASSERT (globals->bfd_of_glue_owner != NULL);
3376 s = bfd_get_section_by_name (globals->bfd_of_glue_owner,
3377 ARM2THUMB_GLUE_SECTION_NAME);
3378 BFD_ASSERT (s != NULL);
3379 BFD_ASSERT (s->contents != NULL);
3380 BFD_ASSERT (s->output_section != NULL);
3382 sec = eh->export_glue->root.u.def.section;
3384 BFD_ASSERT (sec->output_section != NULL);
3386 val = eh->export_glue->root.u.def.value + sec->output_offset
3387 + sec->output_section->vma;
3388 myh = elf32_arm_create_thumb_stub (info, h->root.root.string,
3389 h->root.u.def.section->owner,
3390 globals->obfd, sec, val, s,
3391 &error_message);
3392 BFD_ASSERT (myh);
3393 return TRUE;
3396 /* Generate Arm stubs for exported Thumb symbols. */
3397 static void
3398 elf32_arm_begin_write_processing (bfd *abfd ATTRIBUTE_UNUSED,
3399 struct bfd_link_info *link_info)
3401 struct elf32_arm_link_hash_table * globals;
3403 if (!link_info)
3404 return;
3406 globals = elf32_arm_hash_table (link_info);
3407 /* If blx is available then exported Thumb symbols are OK and there is
3408 nothing to do. */
3409 if (globals->use_blx)
3410 return;
3412 elf_link_hash_traverse (&globals->root, elf32_arm_to_thumb_export_stub,
3413 link_info);
3416 /* Some relocations map to different relocations depending on the
3417 target. Return the real relocation. */
3418 static int
3419 arm_real_reloc_type (struct elf32_arm_link_hash_table * globals,
3420 int r_type)
3422 switch (r_type)
3424 case R_ARM_TARGET1:
3425 if (globals->target1_is_rel)
3426 return R_ARM_REL32;
3427 else
3428 return R_ARM_ABS32;
3430 case R_ARM_TARGET2:
3431 return globals->target2_reloc;
3433 default:
3434 return r_type;
3438 /* Return the base VMA address which should be subtracted from real addresses
3439 when resolving @dtpoff relocation.
3440 This is PT_TLS segment p_vaddr. */
3442 static bfd_vma
3443 dtpoff_base (struct bfd_link_info *info)
3445 /* If tls_sec is NULL, we should have signalled an error already. */
3446 if (elf_hash_table (info)->tls_sec == NULL)
3447 return 0;
3448 return elf_hash_table (info)->tls_sec->vma;
3451 /* Return the relocation value for @tpoff relocation
3452 if STT_TLS virtual address is ADDRESS. */
3454 static bfd_vma
3455 tpoff (struct bfd_link_info *info, bfd_vma address)
3457 struct elf_link_hash_table *htab = elf_hash_table (info);
3458 bfd_vma base;
3460 /* If tls_sec is NULL, we should have signalled an error already. */
3461 if (htab->tls_sec == NULL)
3462 return 0;
3463 base = align_power ((bfd_vma) TCB_SIZE, htab->tls_sec->alignment_power);
3464 return address - htab->tls_sec->vma + base;
3467 /* Perform an R_ARM_ABS12 relocation on the field pointed to by DATA.
3468 VALUE is the relocation value. */
3470 static bfd_reloc_status_type
3471 elf32_arm_abs12_reloc (bfd *abfd, void *data, bfd_vma value)
3473 if (value > 0xfff)
3474 return bfd_reloc_overflow;
3476 value |= bfd_get_32 (abfd, data) & 0xfffff000;
3477 bfd_put_32 (abfd, value, data);
3478 return bfd_reloc_ok;
3481 /* For a given value of n, calculate the value of G_n as required to
3482 deal with group relocations. We return it in the form of an
3483 encoded constant-and-rotation, together with the final residual. If n is
3484 specified as less than zero, then final_residual is filled with the
3485 input value and no further action is performed. */
3487 static bfd_vma
3488 calculate_group_reloc_mask (bfd_vma value, int n, bfd_vma *final_residual)
3490 int current_n;
3491 bfd_vma g_n;
3492 bfd_vma encoded_g_n = 0;
3493 bfd_vma residual = value; /* Also known as Y_n. */
3495 for (current_n = 0; current_n <= n; current_n++)
3497 int shift;
3499 /* Calculate which part of the value to mask. */
3500 if (residual == 0)
3501 shift = 0;
3502 else
3504 int msb;
3506 /* Determine the most significant bit in the residual and
3507 align the resulting value to a 2-bit boundary. */
3508 for (msb = 30; msb >= 0; msb -= 2)
3509 if (residual & (3 << msb))
3510 break;
3512 /* The desired shift is now (msb - 6), or zero, whichever
3513 is the greater. */
3514 shift = msb - 6;
3515 if (shift < 0)
3516 shift = 0;
3519 /* Calculate g_n in 32-bit as well as encoded constant+rotation form. */
3520 g_n = residual & (0xff << shift);
3521 encoded_g_n = (g_n >> shift)
3522 | ((g_n <= 0xff ? 0 : (32 - shift) / 2) << 8);
3524 /* Calculate the residual for the next time around. */
3525 residual &= ~g_n;
3528 *final_residual = residual;
3530 return encoded_g_n;
3533 /* Given an ARM instruction, determine whether it is an ADD or a SUB.
3534 Returns 1 if it is an ADD, -1 if it is a SUB, and 0 otherwise. */
3535 static int
3536 identify_add_or_sub(bfd_vma insn)
3538 int opcode = insn & 0x1e00000;
3540 if (opcode == 1 << 23) /* ADD */
3541 return 1;
3543 if (opcode == 1 << 22) /* SUB */
3544 return -1;
3546 return 0;
3549 /* Determine if we're dealing with a Thumb-2 object. */
3551 static int using_thumb2 (struct elf32_arm_link_hash_table *globals)
3553 int arch = elf32_arm_get_eabi_attr_int (globals->obfd, Tag_CPU_arch);
3554 return arch == TAG_CPU_ARCH_V6T2 || arch >= TAG_CPU_ARCH_V7;
3557 /* Perform a relocation as part of a final link. */
3559 static bfd_reloc_status_type
3560 elf32_arm_final_link_relocate (reloc_howto_type * howto,
3561 bfd * input_bfd,
3562 bfd * output_bfd,
3563 asection * input_section,
3564 bfd_byte * contents,
3565 Elf_Internal_Rela * rel,
3566 bfd_vma value,
3567 struct bfd_link_info * info,
3568 asection * sym_sec,
3569 const char * sym_name,
3570 int sym_flags,
3571 struct elf_link_hash_entry * h,
3572 bfd_boolean * unresolved_reloc_p,
3573 char **error_message)
3575 unsigned long r_type = howto->type;
3576 unsigned long r_symndx;
3577 bfd_byte * hit_data = contents + rel->r_offset;
3578 bfd * dynobj = NULL;
3579 Elf_Internal_Shdr * symtab_hdr;
3580 struct elf_link_hash_entry ** sym_hashes;
3581 bfd_vma * local_got_offsets;
3582 asection * sgot = NULL;
3583 asection * splt = NULL;
3584 asection * sreloc = NULL;
3585 bfd_vma addend;
3586 bfd_signed_vma signed_addend;
3587 struct elf32_arm_link_hash_table * globals;
3589 globals = elf32_arm_hash_table (info);
3591 /* Some relocation type map to different relocations depending on the
3592 target. We pick the right one here. */
3593 r_type = arm_real_reloc_type (globals, r_type);
3594 if (r_type != howto->type)
3595 howto = elf32_arm_howto_from_type (r_type);
3597 /* If the start address has been set, then set the EF_ARM_HASENTRY
3598 flag. Setting this more than once is redundant, but the cost is
3599 not too high, and it keeps the code simple.
3601 The test is done here, rather than somewhere else, because the
3602 start address is only set just before the final link commences.
3604 Note - if the user deliberately sets a start address of 0, the
3605 flag will not be set. */
3606 if (bfd_get_start_address (output_bfd) != 0)
3607 elf_elfheader (output_bfd)->e_flags |= EF_ARM_HASENTRY;
3609 dynobj = elf_hash_table (info)->dynobj;
3610 if (dynobj)
3612 sgot = bfd_get_section_by_name (dynobj, ".got");
3613 splt = bfd_get_section_by_name (dynobj, ".plt");
3615 symtab_hdr = & elf_tdata (input_bfd)->symtab_hdr;
3616 sym_hashes = elf_sym_hashes (input_bfd);
3617 local_got_offsets = elf_local_got_offsets (input_bfd);
3618 r_symndx = ELF32_R_SYM (rel->r_info);
3620 if (globals->use_rel)
3622 addend = bfd_get_32 (input_bfd, hit_data) & howto->src_mask;
3624 if (addend & ((howto->src_mask + 1) >> 1))
3626 signed_addend = -1;
3627 signed_addend &= ~ howto->src_mask;
3628 signed_addend |= addend;
3630 else
3631 signed_addend = addend;
3633 else
3634 addend = signed_addend = rel->r_addend;
3636 switch (r_type)
3638 case R_ARM_NONE:
3639 /* We don't need to find a value for this symbol. It's just a
3640 marker. */
3641 *unresolved_reloc_p = FALSE;
3642 return bfd_reloc_ok;
3644 case R_ARM_ABS12:
3645 if (!globals->vxworks_p)
3646 return elf32_arm_abs12_reloc (input_bfd, hit_data, value + addend);
3648 case R_ARM_PC24:
3649 case R_ARM_ABS32:
3650 case R_ARM_ABS32_NOI:
3651 case R_ARM_REL32:
3652 case R_ARM_REL32_NOI:
3653 case R_ARM_CALL:
3654 case R_ARM_JUMP24:
3655 case R_ARM_XPC25:
3656 case R_ARM_PREL31:
3657 case R_ARM_PLT32:
3658 /* r_symndx will be zero only for relocs against symbols
3659 from removed linkonce sections, or sections discarded by
3660 a linker script. */
3661 if (r_symndx == 0)
3663 _bfd_clear_contents (howto, input_bfd, contents + rel->r_offset);
3664 return bfd_reloc_ok;
3667 /* Handle relocations which should use the PLT entry. ABS32/REL32
3668 will use the symbol's value, which may point to a PLT entry, but we
3669 don't need to handle that here. If we created a PLT entry, all
3670 branches in this object should go to it. */
3671 if ((r_type != R_ARM_ABS32 && r_type != R_ARM_REL32
3672 && r_type != R_ARM_ABS32_NOI && r_type != R_ARM_REL32_NOI)
3673 && h != NULL
3674 && splt != NULL
3675 && h->plt.offset != (bfd_vma) -1)
3677 /* If we've created a .plt section, and assigned a PLT entry to
3678 this function, it should not be known to bind locally. If
3679 it were, we would have cleared the PLT entry. */
3680 BFD_ASSERT (!SYMBOL_CALLS_LOCAL (info, h));
3682 value = (splt->output_section->vma
3683 + splt->output_offset
3684 + h->plt.offset);
3685 *unresolved_reloc_p = FALSE;
3686 return _bfd_final_link_relocate (howto, input_bfd, input_section,
3687 contents, rel->r_offset, value,
3688 rel->r_addend);
3691 /* When generating a shared object or relocatable executable, these
3692 relocations are copied into the output file to be resolved at
3693 run time. */
3694 if ((info->shared || globals->root.is_relocatable_executable)
3695 && (input_section->flags & SEC_ALLOC)
3696 && ((r_type != R_ARM_REL32 && r_type != R_ARM_REL32_NOI)
3697 || !SYMBOL_CALLS_LOCAL (info, h))
3698 && (h == NULL
3699 || ELF_ST_VISIBILITY (h->other) == STV_DEFAULT
3700 || h->root.type != bfd_link_hash_undefweak)
3701 && r_type != R_ARM_PC24
3702 && r_type != R_ARM_CALL
3703 && r_type != R_ARM_JUMP24
3704 && r_type != R_ARM_PREL31
3705 && r_type != R_ARM_PLT32)
3707 Elf_Internal_Rela outrel;
3708 bfd_byte *loc;
3709 bfd_boolean skip, relocate;
3711 *unresolved_reloc_p = FALSE;
3713 if (sreloc == NULL)
3715 const char * name;
3717 name = (bfd_elf_string_from_elf_section
3718 (input_bfd,
3719 elf_elfheader (input_bfd)->e_shstrndx,
3720 elf_section_data (input_section)->rel_hdr.sh_name));
3721 if (name == NULL)
3722 return bfd_reloc_notsupported;
3724 BFD_ASSERT (reloc_section_p (globals, name, input_section));
3726 sreloc = bfd_get_section_by_name (dynobj, name);
3727 BFD_ASSERT (sreloc != NULL);
3730 skip = FALSE;
3731 relocate = FALSE;
3733 outrel.r_addend = addend;
3734 outrel.r_offset =
3735 _bfd_elf_section_offset (output_bfd, info, input_section,
3736 rel->r_offset);
3737 if (outrel.r_offset == (bfd_vma) -1)
3738 skip = TRUE;
3739 else if (outrel.r_offset == (bfd_vma) -2)
3740 skip = TRUE, relocate = TRUE;
3741 outrel.r_offset += (input_section->output_section->vma
3742 + input_section->output_offset);
3744 if (skip)
3745 memset (&outrel, 0, sizeof outrel);
3746 else if (h != NULL
3747 && h->dynindx != -1
3748 && (!info->shared
3749 || !info->symbolic
3750 || !h->def_regular))
3751 outrel.r_info = ELF32_R_INFO (h->dynindx, r_type);
3752 else
3754 int symbol;
3756 /* This symbol is local, or marked to become local. */
3757 if (sym_flags == STT_ARM_TFUNC)
3758 value |= 1;
3759 if (globals->symbian_p)
3761 asection *osec;
3763 /* On Symbian OS, the data segment and text segement
3764 can be relocated independently. Therefore, we
3765 must indicate the segment to which this
3766 relocation is relative. The BPABI allows us to
3767 use any symbol in the right segment; we just use
3768 the section symbol as it is convenient. (We
3769 cannot use the symbol given by "h" directly as it
3770 will not appear in the dynamic symbol table.)
3772 Note that the dynamic linker ignores the section
3773 symbol value, so we don't subtract osec->vma
3774 from the emitted reloc addend. */
3775 if (sym_sec)
3776 osec = sym_sec->output_section;
3777 else
3778 osec = input_section->output_section;
3779 symbol = elf_section_data (osec)->dynindx;
3780 if (symbol == 0)
3782 struct elf_link_hash_table *htab = elf_hash_table (info);
3784 if ((osec->flags & SEC_READONLY) == 0
3785 && htab->data_index_section != NULL)
3786 osec = htab->data_index_section;
3787 else
3788 osec = htab->text_index_section;
3789 symbol = elf_section_data (osec)->dynindx;
3791 BFD_ASSERT (symbol != 0);
3793 else
3794 /* On SVR4-ish systems, the dynamic loader cannot
3795 relocate the text and data segments independently,
3796 so the symbol does not matter. */
3797 symbol = 0;
3798 outrel.r_info = ELF32_R_INFO (symbol, R_ARM_RELATIVE);
3799 if (globals->use_rel)
3800 relocate = TRUE;
3801 else
3802 outrel.r_addend += value;
3805 loc = sreloc->contents;
3806 loc += sreloc->reloc_count++ * RELOC_SIZE (globals);
3807 SWAP_RELOC_OUT (globals) (output_bfd, &outrel, loc);
3809 /* If this reloc is against an external symbol, we do not want to
3810 fiddle with the addend. Otherwise, we need to include the symbol
3811 value so that it becomes an addend for the dynamic reloc. */
3812 if (! relocate)
3813 return bfd_reloc_ok;
3815 return _bfd_final_link_relocate (howto, input_bfd, input_section,
3816 contents, rel->r_offset, value,
3817 (bfd_vma) 0);
3819 else switch (r_type)
3821 case R_ARM_ABS12:
3822 return elf32_arm_abs12_reloc (input_bfd, hit_data, value + addend);
3824 case R_ARM_XPC25: /* Arm BLX instruction. */
3825 case R_ARM_CALL:
3826 case R_ARM_JUMP24:
3827 case R_ARM_PC24: /* Arm B/BL instruction */
3828 case R_ARM_PLT32:
3829 if (r_type == R_ARM_XPC25)
3831 /* Check for Arm calling Arm function. */
3832 /* FIXME: Should we translate the instruction into a BL
3833 instruction instead ? */
3834 if (sym_flags != STT_ARM_TFUNC)
3835 (*_bfd_error_handler)
3836 (_("\%B: Warning: Arm BLX instruction targets Arm function '%s'."),
3837 input_bfd,
3838 h ? h->root.root.string : "(local)");
3840 else if (r_type != R_ARM_CALL || !globals->use_blx)
3842 /* Check for Arm calling Thumb function. */
3843 if (sym_flags == STT_ARM_TFUNC)
3845 if (elf32_arm_to_thumb_stub (info, sym_name, input_bfd,
3846 output_bfd, input_section,
3847 hit_data, sym_sec, rel->r_offset,
3848 signed_addend, value,
3849 error_message))
3850 return bfd_reloc_ok;
3851 else
3852 return bfd_reloc_dangerous;
3856 /* The ARM ELF ABI says that this reloc is computed as: S - P + A
3857 where:
3858 S is the address of the symbol in the relocation.
3859 P is address of the instruction being relocated.
3860 A is the addend (extracted from the instruction) in bytes.
3862 S is held in 'value'.
3863 P is the base address of the section containing the
3864 instruction plus the offset of the reloc into that
3865 section, ie:
3866 (input_section->output_section->vma +
3867 input_section->output_offset +
3868 rel->r_offset).
3869 A is the addend, converted into bytes, ie:
3870 (signed_addend * 4)
3872 Note: None of these operations have knowledge of the pipeline
3873 size of the processor, thus it is up to the assembler to
3874 encode this information into the addend. */
3875 value -= (input_section->output_section->vma
3876 + input_section->output_offset);
3877 value -= rel->r_offset;
3878 if (globals->use_rel)
3879 value += (signed_addend << howto->size);
3880 else
3881 /* RELA addends do not have to be adjusted by howto->size. */
3882 value += signed_addend;
3884 signed_addend = value;
3885 signed_addend >>= howto->rightshift;
3887 /* It is not an error for an undefined weak reference to be
3888 out of range. Any program that branches to such a symbol
3889 is going to crash anyway, so there is no point worrying
3890 about getting the destination exactly right. */
3891 if (! h || h->root.type != bfd_link_hash_undefweak)
3893 /* Perform a signed range check. */
3894 if ( signed_addend > ((bfd_signed_vma) (howto->dst_mask >> 1))
3895 || signed_addend < - ((bfd_signed_vma) ((howto->dst_mask + 1) >> 1)))
3896 return bfd_reloc_overflow;
3899 addend = (value & 2);
3901 value = (signed_addend & howto->dst_mask)
3902 | (bfd_get_32 (input_bfd, hit_data) & (~ howto->dst_mask));
3904 /* Set the H bit in the BLX instruction. */
3905 if (sym_flags == STT_ARM_TFUNC)
3907 if (addend)
3908 value |= (1 << 24);
3909 else
3910 value &= ~(bfd_vma)(1 << 24);
3912 if (r_type == R_ARM_CALL)
3914 /* Select the correct instruction (BL or BLX). */
3915 if (sym_flags == STT_ARM_TFUNC)
3916 value |= (1 << 28);
3917 else
3919 value &= ~(bfd_vma)(1 << 28);
3920 value |= (1 << 24);
3923 break;
3925 case R_ARM_ABS32:
3926 value += addend;
3927 if (sym_flags == STT_ARM_TFUNC)
3928 value |= 1;
3929 break;
3931 case R_ARM_ABS32_NOI:
3932 value += addend;
3933 break;
3935 case R_ARM_REL32:
3936 value += addend;
3937 if (sym_flags == STT_ARM_TFUNC)
3938 value |= 1;
3939 value -= (input_section->output_section->vma
3940 + input_section->output_offset + rel->r_offset);
3941 break;
3943 case R_ARM_REL32_NOI:
3944 value += addend;
3945 value -= (input_section->output_section->vma
3946 + input_section->output_offset + rel->r_offset);
3947 break;
3949 case R_ARM_PREL31:
3950 value -= (input_section->output_section->vma
3951 + input_section->output_offset + rel->r_offset);
3952 value += signed_addend;
3953 if (! h || h->root.type != bfd_link_hash_undefweak)
3955 /* Check for overflow */
3956 if ((value ^ (value >> 1)) & (1 << 30))
3957 return bfd_reloc_overflow;
3959 value &= 0x7fffffff;
3960 value |= (bfd_get_32 (input_bfd, hit_data) & 0x80000000);
3961 if (sym_flags == STT_ARM_TFUNC)
3962 value |= 1;
3963 break;
3966 bfd_put_32 (input_bfd, value, hit_data);
3967 return bfd_reloc_ok;
3969 case R_ARM_ABS8:
3970 value += addend;
3971 if ((long) value > 0x7f || (long) value < -0x80)
3972 return bfd_reloc_overflow;
3974 bfd_put_8 (input_bfd, value, hit_data);
3975 return bfd_reloc_ok;
3977 case R_ARM_ABS16:
3978 value += addend;
3980 if ((long) value > 0x7fff || (long) value < -0x8000)
3981 return bfd_reloc_overflow;
3983 bfd_put_16 (input_bfd, value, hit_data);
3984 return bfd_reloc_ok;
3986 case R_ARM_THM_ABS5:
3987 /* Support ldr and str instructions for the thumb. */
3988 if (globals->use_rel)
3990 /* Need to refetch addend. */
3991 addend = bfd_get_16 (input_bfd, hit_data) & howto->src_mask;
3992 /* ??? Need to determine shift amount from operand size. */
3993 addend >>= howto->rightshift;
3995 value += addend;
3997 /* ??? Isn't value unsigned? */
3998 if ((long) value > 0x1f || (long) value < -0x10)
3999 return bfd_reloc_overflow;
4001 /* ??? Value needs to be properly shifted into place first. */
4002 value |= bfd_get_16 (input_bfd, hit_data) & 0xf83f;
4003 bfd_put_16 (input_bfd, value, hit_data);
4004 return bfd_reloc_ok;
4006 case R_ARM_THM_ALU_PREL_11_0:
4007 /* Corresponds to: addw.w reg, pc, #offset (and similarly for subw). */
4009 bfd_vma insn;
4010 bfd_signed_vma relocation;
4012 insn = (bfd_get_16 (input_bfd, hit_data) << 16)
4013 | bfd_get_16 (input_bfd, hit_data + 2);
4015 if (globals->use_rel)
4017 signed_addend = (insn & 0xff) | ((insn & 0x7000) >> 4)
4018 | ((insn & (1 << 26)) >> 15);
4019 if (insn & 0xf00000)
4020 signed_addend = -signed_addend;
4023 relocation = value + signed_addend;
4024 relocation -= (input_section->output_section->vma
4025 + input_section->output_offset
4026 + rel->r_offset);
4028 value = abs (relocation);
4030 if (value >= 0x1000)
4031 return bfd_reloc_overflow;
4033 insn = (insn & 0xfb0f8f00) | (value & 0xff)
4034 | ((value & 0x700) << 4)
4035 | ((value & 0x800) << 15);
4036 if (relocation < 0)
4037 insn |= 0xa00000;
4039 bfd_put_16 (input_bfd, insn >> 16, hit_data);
4040 bfd_put_16 (input_bfd, insn & 0xffff, hit_data + 2);
4042 return bfd_reloc_ok;
4045 case R_ARM_THM_PC12:
4046 /* Corresponds to: ldr.w reg, [pc, #offset]. */
4048 bfd_vma insn;
4049 bfd_signed_vma relocation;
4051 insn = (bfd_get_16 (input_bfd, hit_data) << 16)
4052 | bfd_get_16 (input_bfd, hit_data + 2);
4054 if (globals->use_rel)
4056 signed_addend = insn & 0xfff;
4057 if (!(insn & (1 << 23)))
4058 signed_addend = -signed_addend;
4061 relocation = value + signed_addend;
4062 relocation -= (input_section->output_section->vma
4063 + input_section->output_offset
4064 + rel->r_offset);
4066 value = abs (relocation);
4068 if (value >= 0x1000)
4069 return bfd_reloc_overflow;
4071 insn = (insn & 0xff7ff000) | value;
4072 if (relocation >= 0)
4073 insn |= (1 << 23);
4075 bfd_put_16 (input_bfd, insn >> 16, hit_data);
4076 bfd_put_16 (input_bfd, insn & 0xffff, hit_data + 2);
4078 return bfd_reloc_ok;
4081 case R_ARM_THM_XPC22:
4082 case R_ARM_THM_CALL:
4083 /* Thumb BL (branch long instruction). */
4085 bfd_vma relocation;
4086 bfd_vma reloc_sign;
4087 bfd_boolean overflow = FALSE;
4088 bfd_vma upper_insn = bfd_get_16 (input_bfd, hit_data);
4089 bfd_vma lower_insn = bfd_get_16 (input_bfd, hit_data + 2);
4090 bfd_signed_vma reloc_signed_max;
4091 bfd_signed_vma reloc_signed_min;
4092 bfd_vma check;
4093 bfd_signed_vma signed_check;
4094 int bitsize;
4095 int thumb2 = using_thumb2 (globals);
4097 /* Fetch the addend. We use the Thumb-2 encoding (backwards compatible
4098 with Thumb-1) involving the J1 and J2 bits. */
4099 if (globals->use_rel)
4101 bfd_vma s = (upper_insn & (1 << 10)) >> 10;
4102 bfd_vma upper = upper_insn & 0x3ff;
4103 bfd_vma lower = lower_insn & 0x7ff;
4104 bfd_vma j1 = (lower_insn & (1 << 13)) >> 13;
4105 bfd_vma j2 = (lower_insn & (1 << 11)) >> 11;
4106 bfd_vma i1 = j1 ^ s ? 0 : 1;
4107 bfd_vma i2 = j2 ^ s ? 0 : 1;
4109 addend = (i1 << 23) | (i2 << 22) | (upper << 12) | (lower << 1);
4110 /* Sign extend. */
4111 addend = (addend | ((s ? 0 : 1) << 24)) - (1 << 24);
4113 signed_addend = addend;
4116 if (r_type == R_ARM_THM_XPC22)
4118 /* Check for Thumb to Thumb call. */
4119 /* FIXME: Should we translate the instruction into a BL
4120 instruction instead ? */
4121 if (sym_flags == STT_ARM_TFUNC)
4122 (*_bfd_error_handler)
4123 (_("%B: Warning: Thumb BLX instruction targets thumb function '%s'."),
4124 input_bfd,
4125 h ? h->root.root.string : "(local)");
4127 else
4129 /* If it is not a call to Thumb, assume call to Arm.
4130 If it is a call relative to a section name, then it is not a
4131 function call at all, but rather a long jump. Calls through
4132 the PLT do not require stubs. */
4133 if (sym_flags != STT_ARM_TFUNC && sym_flags != STT_SECTION
4134 && (h == NULL || splt == NULL
4135 || h->plt.offset == (bfd_vma) -1))
4137 if (globals->use_blx)
4139 /* Convert BL to BLX. */
4140 lower_insn = (lower_insn & ~0x1000) | 0x0800;
4142 else if (elf32_thumb_to_arm_stub
4143 (info, sym_name, input_bfd, output_bfd, input_section,
4144 hit_data, sym_sec, rel->r_offset, signed_addend, value,
4145 error_message))
4146 return bfd_reloc_ok;
4147 else
4148 return bfd_reloc_dangerous;
4150 else if (sym_flags == STT_ARM_TFUNC && globals->use_blx)
4152 /* Make sure this is a BL. */
4153 lower_insn |= 0x1800;
4157 /* Handle calls via the PLT. */
4158 if (h != NULL && splt != NULL && h->plt.offset != (bfd_vma) -1)
4160 value = (splt->output_section->vma
4161 + splt->output_offset
4162 + h->plt.offset);
4163 if (globals->use_blx)
4165 /* If the Thumb BLX instruction is available, convert the
4166 BL to a BLX instruction to call the ARM-mode PLT entry. */
4167 lower_insn = (lower_insn & ~0x1000) | 0x0800;
4169 else
4170 /* Target the Thumb stub before the ARM PLT entry. */
4171 value -= PLT_THUMB_STUB_SIZE;
4172 *unresolved_reloc_p = FALSE;
4175 relocation = value + signed_addend;
4177 relocation -= (input_section->output_section->vma
4178 + input_section->output_offset
4179 + rel->r_offset);
4181 check = relocation >> howto->rightshift;
4183 /* If this is a signed value, the rightshift just dropped
4184 leading 1 bits (assuming twos complement). */
4185 if ((bfd_signed_vma) relocation >= 0)
4186 signed_check = check;
4187 else
4188 signed_check = check | ~((bfd_vma) -1 >> howto->rightshift);
4190 /* Calculate the permissable maximum and minimum values for
4191 this relocation according to whether we're relocating for
4192 Thumb-2 or not. */
4193 bitsize = howto->bitsize;
4194 if (!thumb2)
4195 bitsize -= 2;
4196 reloc_signed_max = ((1 << (bitsize - 1)) - 1) >> howto->rightshift;
4197 reloc_signed_min = ~reloc_signed_max;
4199 /* Assumes two's complement. */
4200 if (signed_check > reloc_signed_max || signed_check < reloc_signed_min)
4201 overflow = TRUE;
4203 if ((lower_insn & 0x1800) == 0x0800)
4204 /* For a BLX instruction, make sure that the relocation is rounded up
4205 to a word boundary. This follows the semantics of the instruction
4206 which specifies that bit 1 of the target address will come from bit
4207 1 of the base address. */
4208 relocation = (relocation + 2) & ~ 3;
4210 /* Put RELOCATION back into the insn. Assumes two's complement.
4211 We use the Thumb-2 encoding, which is safe even if dealing with
4212 a Thumb-1 instruction by virtue of our overflow check above. */
4213 reloc_sign = (signed_check < 0) ? 1 : 0;
4214 upper_insn = (upper_insn & ~(bfd_vma) 0x7ff)
4215 | ((relocation >> 12) & 0x3ff)
4216 | (reloc_sign << 10);
4217 lower_insn = (lower_insn & ~(bfd_vma) 0x2fff)
4218 | (((!((relocation >> 23) & 1)) ^ reloc_sign) << 13)
4219 | (((!((relocation >> 22) & 1)) ^ reloc_sign) << 11)
4220 | ((relocation >> 1) & 0x7ff);
4222 /* Put the relocated value back in the object file: */
4223 bfd_put_16 (input_bfd, upper_insn, hit_data);
4224 bfd_put_16 (input_bfd, lower_insn, hit_data + 2);
4226 return (overflow ? bfd_reloc_overflow : bfd_reloc_ok);
4228 break;
4230 case R_ARM_THM_JUMP24:
4231 /* Thumb32 unconditional branch instruction. */
4233 bfd_vma relocation;
4234 bfd_boolean overflow = FALSE;
4235 bfd_vma upper_insn = bfd_get_16 (input_bfd, hit_data);
4236 bfd_vma lower_insn = bfd_get_16 (input_bfd, hit_data + 2);
4237 bfd_signed_vma reloc_signed_max = ((1 << (howto->bitsize - 1)) - 1) >> howto->rightshift;
4238 bfd_signed_vma reloc_signed_min = ~ reloc_signed_max;
4239 bfd_vma check;
4240 bfd_signed_vma signed_check;
4242 /* Need to refetch the addend, reconstruct the top three bits, and glue the
4243 two pieces together. */
4244 if (globals->use_rel)
4246 bfd_vma S = (upper_insn & 0x0400) >> 10;
4247 bfd_vma hi = (upper_insn & 0x03ff);
4248 bfd_vma I1 = (lower_insn & 0x2000) >> 13;
4249 bfd_vma I2 = (lower_insn & 0x0800) >> 11;
4250 bfd_vma lo = (lower_insn & 0x07ff);
4252 I1 = !(I1 ^ S);
4253 I2 = !(I2 ^ S);
4254 S = !S;
4256 signed_addend = (S << 24) | (I1 << 23) | (I2 << 22) | (hi << 12) | (lo << 1);
4257 signed_addend -= (1 << 24); /* Sign extend. */
4260 /* ??? Should handle interworking? GCC might someday try to
4261 use this for tail calls. */
4263 relocation = value + signed_addend;
4264 relocation -= (input_section->output_section->vma
4265 + input_section->output_offset
4266 + rel->r_offset);
4268 check = relocation >> howto->rightshift;
4270 /* If this is a signed value, the rightshift just dropped
4271 leading 1 bits (assuming twos complement). */
4272 if ((bfd_signed_vma) relocation >= 0)
4273 signed_check = check;
4274 else
4275 signed_check = check | ~((bfd_vma) -1 >> howto->rightshift);
4277 /* Assumes two's complement. */
4278 if (signed_check > reloc_signed_max || signed_check < reloc_signed_min)
4279 overflow = TRUE;
4281 /* Put RELOCATION back into the insn. */
4283 bfd_vma S = (relocation & 0x01000000) >> 24;
4284 bfd_vma I1 = (relocation & 0x00800000) >> 23;
4285 bfd_vma I2 = (relocation & 0x00400000) >> 22;
4286 bfd_vma hi = (relocation & 0x003ff000) >> 12;
4287 bfd_vma lo = (relocation & 0x00000ffe) >> 1;
4289 I1 = !(I1 ^ S);
4290 I2 = !(I2 ^ S);
4292 upper_insn = (upper_insn & (bfd_vma) 0xf800) | (S << 10) | hi;
4293 lower_insn = (lower_insn & (bfd_vma) 0xd000) | (I1 << 13) | (I2 << 11) | lo;
4296 /* Put the relocated value back in the object file: */
4297 bfd_put_16 (input_bfd, upper_insn, hit_data);
4298 bfd_put_16 (input_bfd, lower_insn, hit_data + 2);
4300 return (overflow ? bfd_reloc_overflow : bfd_reloc_ok);
4303 case R_ARM_THM_JUMP19:
4304 /* Thumb32 conditional branch instruction. */
4306 bfd_vma relocation;
4307 bfd_boolean overflow = FALSE;
4308 bfd_vma upper_insn = bfd_get_16 (input_bfd, hit_data);
4309 bfd_vma lower_insn = bfd_get_16 (input_bfd, hit_data + 2);
4310 bfd_signed_vma reloc_signed_max = ((1 << (howto->bitsize - 1)) - 1) >> howto->rightshift;
4311 bfd_signed_vma reloc_signed_min = ~ reloc_signed_max;
4312 bfd_vma check;
4313 bfd_signed_vma signed_check;
4315 /* Need to refetch the addend, reconstruct the top three bits,
4316 and squish the two 11 bit pieces together. */
4317 if (globals->use_rel)
4319 bfd_vma S = (upper_insn & 0x0400) >> 10;
4320 bfd_vma upper = (upper_insn & 0x001f);
4321 bfd_vma J1 = (lower_insn & 0x2000) >> 13;
4322 bfd_vma J2 = (lower_insn & 0x0800) >> 11;
4323 bfd_vma lower = (lower_insn & 0x07ff);
4325 upper |= J2 << 6;
4326 upper |= J1 << 7;
4327 upper |= ~S << 8;
4328 upper -= 0x0100; /* Sign extend. */
4330 addend = (upper << 12) | (lower << 1);
4331 signed_addend = addend;
4334 /* ??? Should handle interworking? GCC might someday try to
4335 use this for tail calls. */
4337 relocation = value + signed_addend;
4338 relocation -= (input_section->output_section->vma
4339 + input_section->output_offset
4340 + rel->r_offset);
4342 check = relocation >> howto->rightshift;
4344 /* If this is a signed value, the rightshift just dropped
4345 leading 1 bits (assuming twos complement). */
4346 if ((bfd_signed_vma) relocation >= 0)
4347 signed_check = check;
4348 else
4349 signed_check = check | ~((bfd_vma) -1 >> howto->rightshift);
4351 /* Assumes two's complement. */
4352 if (signed_check > reloc_signed_max || signed_check < reloc_signed_min)
4353 overflow = TRUE;
4355 /* Put RELOCATION back into the insn. */
4357 bfd_vma S = (relocation & 0x00100000) >> 20;
4358 bfd_vma J2 = (relocation & 0x00080000) >> 19;
4359 bfd_vma J1 = (relocation & 0x00040000) >> 18;
4360 bfd_vma hi = (relocation & 0x0003f000) >> 12;
4361 bfd_vma lo = (relocation & 0x00000ffe) >> 1;
4363 upper_insn = (upper_insn & 0xfb30) | (S << 10) | hi;
4364 lower_insn = (lower_insn & 0xd000) | (J1 << 13) | (J2 << 11) | lo;
4367 /* Put the relocated value back in the object file: */
4368 bfd_put_16 (input_bfd, upper_insn, hit_data);
4369 bfd_put_16 (input_bfd, lower_insn, hit_data + 2);
4371 return (overflow ? bfd_reloc_overflow : bfd_reloc_ok);
4374 case R_ARM_THM_JUMP11:
4375 case R_ARM_THM_JUMP8:
4376 case R_ARM_THM_JUMP6:
4377 /* Thumb B (branch) instruction). */
4379 bfd_signed_vma relocation;
4380 bfd_signed_vma reloc_signed_max = (1 << (howto->bitsize - 1)) - 1;
4381 bfd_signed_vma reloc_signed_min = ~ reloc_signed_max;
4382 bfd_signed_vma signed_check;
4384 /* CZB cannot jump backward. */
4385 if (r_type == R_ARM_THM_JUMP6)
4386 reloc_signed_min = 0;
4388 if (globals->use_rel)
4390 /* Need to refetch addend. */
4391 addend = bfd_get_16 (input_bfd, hit_data) & howto->src_mask;
4392 if (addend & ((howto->src_mask + 1) >> 1))
4394 signed_addend = -1;
4395 signed_addend &= ~ howto->src_mask;
4396 signed_addend |= addend;
4398 else
4399 signed_addend = addend;
4400 /* The value in the insn has been right shifted. We need to
4401 undo this, so that we can perform the address calculation
4402 in terms of bytes. */
4403 signed_addend <<= howto->rightshift;
4405 relocation = value + signed_addend;
4407 relocation -= (input_section->output_section->vma
4408 + input_section->output_offset
4409 + rel->r_offset);
4411 relocation >>= howto->rightshift;
4412 signed_check = relocation;
4414 if (r_type == R_ARM_THM_JUMP6)
4415 relocation = ((relocation & 0x0020) << 4) | ((relocation & 0x001f) << 3);
4416 else
4417 relocation &= howto->dst_mask;
4418 relocation |= (bfd_get_16 (input_bfd, hit_data) & (~ howto->dst_mask));
4420 bfd_put_16 (input_bfd, relocation, hit_data);
4422 /* Assumes two's complement. */
4423 if (signed_check > reloc_signed_max || signed_check < reloc_signed_min)
4424 return bfd_reloc_overflow;
4426 return bfd_reloc_ok;
4429 case R_ARM_ALU_PCREL7_0:
4430 case R_ARM_ALU_PCREL15_8:
4431 case R_ARM_ALU_PCREL23_15:
4433 bfd_vma insn;
4434 bfd_vma relocation;
4436 insn = bfd_get_32 (input_bfd, hit_data);
4437 if (globals->use_rel)
4439 /* Extract the addend. */
4440 addend = (insn & 0xff) << ((insn & 0xf00) >> 7);
4441 signed_addend = addend;
4443 relocation = value + signed_addend;
4445 relocation -= (input_section->output_section->vma
4446 + input_section->output_offset
4447 + rel->r_offset);
4448 insn = (insn & ~0xfff)
4449 | ((howto->bitpos << 7) & 0xf00)
4450 | ((relocation >> howto->bitpos) & 0xff);
4451 bfd_put_32 (input_bfd, value, hit_data);
4453 return bfd_reloc_ok;
4455 case R_ARM_GNU_VTINHERIT:
4456 case R_ARM_GNU_VTENTRY:
4457 return bfd_reloc_ok;
4459 case R_ARM_GOTOFF32:
4460 /* Relocation is relative to the start of the
4461 global offset table. */
4463 BFD_ASSERT (sgot != NULL);
4464 if (sgot == NULL)
4465 return bfd_reloc_notsupported;
4467 /* If we are addressing a Thumb function, we need to adjust the
4468 address by one, so that attempts to call the function pointer will
4469 correctly interpret it as Thumb code. */
4470 if (sym_flags == STT_ARM_TFUNC)
4471 value += 1;
4473 /* Note that sgot->output_offset is not involved in this
4474 calculation. We always want the start of .got. If we
4475 define _GLOBAL_OFFSET_TABLE in a different way, as is
4476 permitted by the ABI, we might have to change this
4477 calculation. */
4478 value -= sgot->output_section->vma;
4479 return _bfd_final_link_relocate (howto, input_bfd, input_section,
4480 contents, rel->r_offset, value,
4481 rel->r_addend);
4483 case R_ARM_GOTPC:
4484 /* Use global offset table as symbol value. */
4485 BFD_ASSERT (sgot != NULL);
4487 if (sgot == NULL)
4488 return bfd_reloc_notsupported;
4490 *unresolved_reloc_p = FALSE;
4491 value = sgot->output_section->vma;
4492 return _bfd_final_link_relocate (howto, input_bfd, input_section,
4493 contents, rel->r_offset, value,
4494 rel->r_addend);
4496 case R_ARM_GOT32:
4497 case R_ARM_GOT_PREL:
4498 /* Relocation is to the entry for this symbol in the
4499 global offset table. */
4500 if (sgot == NULL)
4501 return bfd_reloc_notsupported;
4503 if (h != NULL)
4505 bfd_vma off;
4506 bfd_boolean dyn;
4508 off = h->got.offset;
4509 BFD_ASSERT (off != (bfd_vma) -1);
4510 dyn = globals->root.dynamic_sections_created;
4512 if (! WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn, info->shared, h)
4513 || (info->shared
4514 && SYMBOL_REFERENCES_LOCAL (info, h))
4515 || (ELF_ST_VISIBILITY (h->other)
4516 && h->root.type == bfd_link_hash_undefweak))
4518 /* This is actually a static link, or it is a -Bsymbolic link
4519 and the symbol is defined locally. We must initialize this
4520 entry in the global offset table. Since the offset must
4521 always be a multiple of 4, we use the least significant bit
4522 to record whether we have initialized it already.
4524 When doing a dynamic link, we create a .rel(a).got relocation
4525 entry to initialize the value. This is done in the
4526 finish_dynamic_symbol routine. */
4527 if ((off & 1) != 0)
4528 off &= ~1;
4529 else
4531 /* If we are addressing a Thumb function, we need to
4532 adjust the address by one, so that attempts to
4533 call the function pointer will correctly
4534 interpret it as Thumb code. */
4535 if (sym_flags == STT_ARM_TFUNC)
4536 value |= 1;
4538 bfd_put_32 (output_bfd, value, sgot->contents + off);
4539 h->got.offset |= 1;
4542 else
4543 *unresolved_reloc_p = FALSE;
4545 value = sgot->output_offset + off;
4547 else
4549 bfd_vma off;
4551 BFD_ASSERT (local_got_offsets != NULL &&
4552 local_got_offsets[r_symndx] != (bfd_vma) -1);
4554 off = local_got_offsets[r_symndx];
4556 /* The offset must always be a multiple of 4. We use the
4557 least significant bit to record whether we have already
4558 generated the necessary reloc. */
4559 if ((off & 1) != 0)
4560 off &= ~1;
4561 else
4563 /* If we are addressing a Thumb function, we need to
4564 adjust the address by one, so that attempts to
4565 call the function pointer will correctly
4566 interpret it as Thumb code. */
4567 if (sym_flags == STT_ARM_TFUNC)
4568 value |= 1;
4570 if (globals->use_rel)
4571 bfd_put_32 (output_bfd, value, sgot->contents + off);
4573 if (info->shared)
4575 asection * srelgot;
4576 Elf_Internal_Rela outrel;
4577 bfd_byte *loc;
4579 srelgot = (bfd_get_section_by_name
4580 (dynobj, RELOC_SECTION (globals, ".got")));
4581 BFD_ASSERT (srelgot != NULL);
4583 outrel.r_addend = addend + value;
4584 outrel.r_offset = (sgot->output_section->vma
4585 + sgot->output_offset
4586 + off);
4587 outrel.r_info = ELF32_R_INFO (0, R_ARM_RELATIVE);
4588 loc = srelgot->contents;
4589 loc += srelgot->reloc_count++ * RELOC_SIZE (globals);
4590 SWAP_RELOC_OUT (globals) (output_bfd, &outrel, loc);
4593 local_got_offsets[r_symndx] |= 1;
4596 value = sgot->output_offset + off;
4598 if (r_type != R_ARM_GOT32)
4599 value += sgot->output_section->vma;
4601 return _bfd_final_link_relocate (howto, input_bfd, input_section,
4602 contents, rel->r_offset, value,
4603 rel->r_addend);
4605 case R_ARM_TLS_LDO32:
4606 value = value - dtpoff_base (info);
4608 return _bfd_final_link_relocate (howto, input_bfd, input_section,
4609 contents, rel->r_offset, value,
4610 rel->r_addend);
4612 case R_ARM_TLS_LDM32:
4614 bfd_vma off;
4616 if (globals->sgot == NULL)
4617 abort ();
4619 off = globals->tls_ldm_got.offset;
4621 if ((off & 1) != 0)
4622 off &= ~1;
4623 else
4625 /* If we don't know the module number, create a relocation
4626 for it. */
4627 if (info->shared)
4629 Elf_Internal_Rela outrel;
4630 bfd_byte *loc;
4632 if (globals->srelgot == NULL)
4633 abort ();
4635 outrel.r_addend = 0;
4636 outrel.r_offset = (globals->sgot->output_section->vma
4637 + globals->sgot->output_offset + off);
4638 outrel.r_info = ELF32_R_INFO (0, R_ARM_TLS_DTPMOD32);
4640 if (globals->use_rel)
4641 bfd_put_32 (output_bfd, outrel.r_addend,
4642 globals->sgot->contents + off);
4644 loc = globals->srelgot->contents;
4645 loc += globals->srelgot->reloc_count++ * RELOC_SIZE (globals);
4646 SWAP_RELOC_OUT (globals) (output_bfd, &outrel, loc);
4648 else
4649 bfd_put_32 (output_bfd, 1, globals->sgot->contents + off);
4651 globals->tls_ldm_got.offset |= 1;
4654 value = globals->sgot->output_section->vma + globals->sgot->output_offset + off
4655 - (input_section->output_section->vma + input_section->output_offset + rel->r_offset);
4657 return _bfd_final_link_relocate (howto, input_bfd, input_section,
4658 contents, rel->r_offset, value,
4659 rel->r_addend);
4662 case R_ARM_TLS_GD32:
4663 case R_ARM_TLS_IE32:
4665 bfd_vma off;
4666 int indx;
4667 char tls_type;
4669 if (globals->sgot == NULL)
4670 abort ();
4672 indx = 0;
4673 if (h != NULL)
4675 bfd_boolean dyn;
4676 dyn = globals->root.dynamic_sections_created;
4677 if (WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn, info->shared, h)
4678 && (!info->shared
4679 || !SYMBOL_REFERENCES_LOCAL (info, h)))
4681 *unresolved_reloc_p = FALSE;
4682 indx = h->dynindx;
4684 off = h->got.offset;
4685 tls_type = ((struct elf32_arm_link_hash_entry *) h)->tls_type;
4687 else
4689 if (local_got_offsets == NULL)
4690 abort ();
4691 off = local_got_offsets[r_symndx];
4692 tls_type = elf32_arm_local_got_tls_type (input_bfd)[r_symndx];
4695 if (tls_type == GOT_UNKNOWN)
4696 abort ();
4698 if ((off & 1) != 0)
4699 off &= ~1;
4700 else
4702 bfd_boolean need_relocs = FALSE;
4703 Elf_Internal_Rela outrel;
4704 bfd_byte *loc = NULL;
4705 int cur_off = off;
4707 /* The GOT entries have not been initialized yet. Do it
4708 now, and emit any relocations. If both an IE GOT and a
4709 GD GOT are necessary, we emit the GD first. */
4711 if ((info->shared || indx != 0)
4712 && (h == NULL
4713 || ELF_ST_VISIBILITY (h->other) == STV_DEFAULT
4714 || h->root.type != bfd_link_hash_undefweak))
4716 need_relocs = TRUE;
4717 if (globals->srelgot == NULL)
4718 abort ();
4719 loc = globals->srelgot->contents;
4720 loc += globals->srelgot->reloc_count * RELOC_SIZE (globals);
4723 if (tls_type & GOT_TLS_GD)
4725 if (need_relocs)
4727 outrel.r_addend = 0;
4728 outrel.r_offset = (globals->sgot->output_section->vma
4729 + globals->sgot->output_offset
4730 + cur_off);
4731 outrel.r_info = ELF32_R_INFO (indx, R_ARM_TLS_DTPMOD32);
4733 if (globals->use_rel)
4734 bfd_put_32 (output_bfd, outrel.r_addend,
4735 globals->sgot->contents + cur_off);
4737 SWAP_RELOC_OUT (globals) (output_bfd, &outrel, loc);
4738 globals->srelgot->reloc_count++;
4739 loc += RELOC_SIZE (globals);
4741 if (indx == 0)
4742 bfd_put_32 (output_bfd, value - dtpoff_base (info),
4743 globals->sgot->contents + cur_off + 4);
4744 else
4746 outrel.r_addend = 0;
4747 outrel.r_info = ELF32_R_INFO (indx,
4748 R_ARM_TLS_DTPOFF32);
4749 outrel.r_offset += 4;
4751 if (globals->use_rel)
4752 bfd_put_32 (output_bfd, outrel.r_addend,
4753 globals->sgot->contents + cur_off + 4);
4756 SWAP_RELOC_OUT (globals) (output_bfd, &outrel, loc);
4757 globals->srelgot->reloc_count++;
4758 loc += RELOC_SIZE (globals);
4761 else
4763 /* If we are not emitting relocations for a
4764 general dynamic reference, then we must be in a
4765 static link or an executable link with the
4766 symbol binding locally. Mark it as belonging
4767 to module 1, the executable. */
4768 bfd_put_32 (output_bfd, 1,
4769 globals->sgot->contents + cur_off);
4770 bfd_put_32 (output_bfd, value - dtpoff_base (info),
4771 globals->sgot->contents + cur_off + 4);
4774 cur_off += 8;
4777 if (tls_type & GOT_TLS_IE)
4779 if (need_relocs)
4781 if (indx == 0)
4782 outrel.r_addend = value - dtpoff_base (info);
4783 else
4784 outrel.r_addend = 0;
4785 outrel.r_offset = (globals->sgot->output_section->vma
4786 + globals->sgot->output_offset
4787 + cur_off);
4788 outrel.r_info = ELF32_R_INFO (indx, R_ARM_TLS_TPOFF32);
4790 if (globals->use_rel)
4791 bfd_put_32 (output_bfd, outrel.r_addend,
4792 globals->sgot->contents + cur_off);
4794 SWAP_RELOC_OUT (globals) (output_bfd, &outrel, loc);
4795 globals->srelgot->reloc_count++;
4796 loc += RELOC_SIZE (globals);
4798 else
4799 bfd_put_32 (output_bfd, tpoff (info, value),
4800 globals->sgot->contents + cur_off);
4801 cur_off += 4;
4804 if (h != NULL)
4805 h->got.offset |= 1;
4806 else
4807 local_got_offsets[r_symndx] |= 1;
4810 if ((tls_type & GOT_TLS_GD) && r_type != R_ARM_TLS_GD32)
4811 off += 8;
4812 value = globals->sgot->output_section->vma + globals->sgot->output_offset + off
4813 - (input_section->output_section->vma + input_section->output_offset + rel->r_offset);
4815 return _bfd_final_link_relocate (howto, input_bfd, input_section,
4816 contents, rel->r_offset, value,
4817 rel->r_addend);
4820 case R_ARM_TLS_LE32:
4821 if (info->shared)
4823 (*_bfd_error_handler)
4824 (_("%B(%A+0x%lx): R_ARM_TLS_LE32 relocation not permitted in shared object"),
4825 input_bfd, input_section,
4826 (long) rel->r_offset, howto->name);
4827 return FALSE;
4829 else
4830 value = tpoff (info, value);
4832 return _bfd_final_link_relocate (howto, input_bfd, input_section,
4833 contents, rel->r_offset, value,
4834 rel->r_addend);
4836 case R_ARM_V4BX:
4837 if (globals->fix_v4bx)
4839 bfd_vma insn = bfd_get_32 (input_bfd, hit_data);
4841 /* Ensure that we have a BX instruction. */
4842 BFD_ASSERT ((insn & 0x0ffffff0) == 0x012fff10);
4844 /* Preserve Rm (lowest four bits) and the condition code
4845 (highest four bits). Other bits encode MOV PC,Rm. */
4846 insn = (insn & 0xf000000f) | 0x01a0f000;
4848 bfd_put_32 (input_bfd, insn, hit_data);
4850 return bfd_reloc_ok;
4852 case R_ARM_MOVW_ABS_NC:
4853 case R_ARM_MOVT_ABS:
4854 case R_ARM_MOVW_PREL_NC:
4855 case R_ARM_MOVT_PREL:
4856 /* Until we properly support segment-base-relative addressing then
4857 we assume the segment base to be zero, as for the group relocations.
4858 Thus R_ARM_MOVW_BREL_NC has the same semantics as R_ARM_MOVW_ABS_NC
4859 and R_ARM_MOVT_BREL has the same semantics as R_ARM_MOVT_ABS. */
4860 case R_ARM_MOVW_BREL_NC:
4861 case R_ARM_MOVW_BREL:
4862 case R_ARM_MOVT_BREL:
4864 bfd_vma insn = bfd_get_32 (input_bfd, hit_data);
4866 if (globals->use_rel)
4868 addend = ((insn >> 4) & 0xf000) | (insn & 0xfff);
4869 signed_addend = (addend ^ 0x10000) - 0x10000;
4872 value += signed_addend;
4874 if (r_type == R_ARM_MOVW_PREL_NC || r_type == R_ARM_MOVT_PREL)
4875 value -= (input_section->output_section->vma
4876 + input_section->output_offset + rel->r_offset);
4878 if (r_type == R_ARM_MOVW_BREL && value >= 0x10000)
4879 return bfd_reloc_overflow;
4881 if (sym_flags == STT_ARM_TFUNC)
4882 value |= 1;
4884 if (r_type == R_ARM_MOVT_ABS || r_type == R_ARM_MOVT_PREL
4885 || r_type == R_ARM_MOVT_BREL)
4886 value >>= 16;
4888 insn &= 0xfff0f000;
4889 insn |= value & 0xfff;
4890 insn |= (value & 0xf000) << 4;
4891 bfd_put_32 (input_bfd, insn, hit_data);
4893 return bfd_reloc_ok;
4895 case R_ARM_THM_MOVW_ABS_NC:
4896 case R_ARM_THM_MOVT_ABS:
4897 case R_ARM_THM_MOVW_PREL_NC:
4898 case R_ARM_THM_MOVT_PREL:
4899 /* Until we properly support segment-base-relative addressing then
4900 we assume the segment base to be zero, as for the above relocations.
4901 Thus R_ARM_THM_MOVW_BREL_NC has the same semantics as
4902 R_ARM_THM_MOVW_ABS_NC and R_ARM_THM_MOVT_BREL has the same semantics
4903 as R_ARM_THM_MOVT_ABS. */
4904 case R_ARM_THM_MOVW_BREL_NC:
4905 case R_ARM_THM_MOVW_BREL:
4906 case R_ARM_THM_MOVT_BREL:
4908 bfd_vma insn;
4910 insn = bfd_get_16 (input_bfd, hit_data) << 16;
4911 insn |= bfd_get_16 (input_bfd, hit_data + 2);
4913 if (globals->use_rel)
4915 addend = ((insn >> 4) & 0xf000)
4916 | ((insn >> 15) & 0x0800)
4917 | ((insn >> 4) & 0x0700)
4918 | (insn & 0x00ff);
4919 signed_addend = (addend ^ 0x10000) - 0x10000;
4922 value += signed_addend;
4924 if (r_type == R_ARM_THM_MOVW_PREL_NC || r_type == R_ARM_THM_MOVT_PREL)
4925 value -= (input_section->output_section->vma
4926 + input_section->output_offset + rel->r_offset);
4928 if (r_type == R_ARM_THM_MOVW_BREL && value >= 0x10000)
4929 return bfd_reloc_overflow;
4931 if (sym_flags == STT_ARM_TFUNC)
4932 value |= 1;
4934 if (r_type == R_ARM_THM_MOVT_ABS || r_type == R_ARM_THM_MOVT_PREL
4935 || r_type == R_ARM_THM_MOVT_BREL)
4936 value >>= 16;
4938 insn &= 0xfbf08f00;
4939 insn |= (value & 0xf000) << 4;
4940 insn |= (value & 0x0800) << 15;
4941 insn |= (value & 0x0700) << 4;
4942 insn |= (value & 0x00ff);
4944 bfd_put_16 (input_bfd, insn >> 16, hit_data);
4945 bfd_put_16 (input_bfd, insn & 0xffff, hit_data + 2);
4947 return bfd_reloc_ok;
4949 case R_ARM_ALU_PC_G0_NC:
4950 case R_ARM_ALU_PC_G1_NC:
4951 case R_ARM_ALU_PC_G0:
4952 case R_ARM_ALU_PC_G1:
4953 case R_ARM_ALU_PC_G2:
4954 case R_ARM_ALU_SB_G0_NC:
4955 case R_ARM_ALU_SB_G1_NC:
4956 case R_ARM_ALU_SB_G0:
4957 case R_ARM_ALU_SB_G1:
4958 case R_ARM_ALU_SB_G2:
4960 bfd_vma insn = bfd_get_32 (input_bfd, hit_data);
4961 bfd_vma pc = input_section->output_section->vma
4962 + input_section->output_offset + rel->r_offset;
4963 /* sb should be the origin of the *segment* containing the symbol.
4964 It is not clear how to obtain this OS-dependent value, so we
4965 make an arbitrary choice of zero. */
4966 bfd_vma sb = 0;
4967 bfd_vma residual;
4968 bfd_vma g_n;
4969 bfd_signed_vma signed_value;
4970 int group = 0;
4972 /* Determine which group of bits to select. */
4973 switch (r_type)
4975 case R_ARM_ALU_PC_G0_NC:
4976 case R_ARM_ALU_PC_G0:
4977 case R_ARM_ALU_SB_G0_NC:
4978 case R_ARM_ALU_SB_G0:
4979 group = 0;
4980 break;
4982 case R_ARM_ALU_PC_G1_NC:
4983 case R_ARM_ALU_PC_G1:
4984 case R_ARM_ALU_SB_G1_NC:
4985 case R_ARM_ALU_SB_G1:
4986 group = 1;
4987 break;
4989 case R_ARM_ALU_PC_G2:
4990 case R_ARM_ALU_SB_G2:
4991 group = 2;
4992 break;
4994 default:
4995 abort();
4998 /* If REL, extract the addend from the insn. If RELA, it will
4999 have already been fetched for us. */
5000 if (globals->use_rel)
5002 int negative;
5003 bfd_vma constant = insn & 0xff;
5004 bfd_vma rotation = (insn & 0xf00) >> 8;
5006 if (rotation == 0)
5007 signed_addend = constant;
5008 else
5010 /* Compensate for the fact that in the instruction, the
5011 rotation is stored in multiples of 2 bits. */
5012 rotation *= 2;
5014 /* Rotate "constant" right by "rotation" bits. */
5015 signed_addend = (constant >> rotation) |
5016 (constant << (8 * sizeof (bfd_vma) - rotation));
5019 /* Determine if the instruction is an ADD or a SUB.
5020 (For REL, this determines the sign of the addend.) */
5021 negative = identify_add_or_sub (insn);
5022 if (negative == 0)
5024 (*_bfd_error_handler)
5025 (_("%B(%A+0x%lx): Only ADD or SUB instructions are allowed for ALU group relocations"),
5026 input_bfd, input_section,
5027 (long) rel->r_offset, howto->name);
5028 return bfd_reloc_overflow;
5031 signed_addend *= negative;
5034 /* Compute the value (X) to go in the place. */
5035 if (r_type == R_ARM_ALU_PC_G0_NC
5036 || r_type == R_ARM_ALU_PC_G1_NC
5037 || r_type == R_ARM_ALU_PC_G0
5038 || r_type == R_ARM_ALU_PC_G1
5039 || r_type == R_ARM_ALU_PC_G2)
5040 /* PC relative. */
5041 signed_value = value - pc + signed_addend;
5042 else
5043 /* Section base relative. */
5044 signed_value = value - sb + signed_addend;
5046 /* If the target symbol is a Thumb function, then set the
5047 Thumb bit in the address. */
5048 if (sym_flags == STT_ARM_TFUNC)
5049 signed_value |= 1;
5051 /* Calculate the value of the relevant G_n, in encoded
5052 constant-with-rotation format. */
5053 g_n = calculate_group_reloc_mask (abs (signed_value), group,
5054 &residual);
5056 /* Check for overflow if required. */
5057 if ((r_type == R_ARM_ALU_PC_G0
5058 || r_type == R_ARM_ALU_PC_G1
5059 || r_type == R_ARM_ALU_PC_G2
5060 || r_type == R_ARM_ALU_SB_G0
5061 || r_type == R_ARM_ALU_SB_G1
5062 || r_type == R_ARM_ALU_SB_G2) && residual != 0)
5064 (*_bfd_error_handler)
5065 (_("%B(%A+0x%lx): Overflow whilst splitting 0x%lx for group relocation %s"),
5066 input_bfd, input_section,
5067 (long) rel->r_offset, abs (signed_value), howto->name);
5068 return bfd_reloc_overflow;
5071 /* Mask out the value and the ADD/SUB part of the opcode; take care
5072 not to destroy the S bit. */
5073 insn &= 0xff1ff000;
5075 /* Set the opcode according to whether the value to go in the
5076 place is negative. */
5077 if (signed_value < 0)
5078 insn |= 1 << 22;
5079 else
5080 insn |= 1 << 23;
5082 /* Encode the offset. */
5083 insn |= g_n;
5085 bfd_put_32 (input_bfd, insn, hit_data);
5087 return bfd_reloc_ok;
5089 case R_ARM_LDR_PC_G0:
5090 case R_ARM_LDR_PC_G1:
5091 case R_ARM_LDR_PC_G2:
5092 case R_ARM_LDR_SB_G0:
5093 case R_ARM_LDR_SB_G1:
5094 case R_ARM_LDR_SB_G2:
5096 bfd_vma insn = bfd_get_32 (input_bfd, hit_data);
5097 bfd_vma pc = input_section->output_section->vma
5098 + input_section->output_offset + rel->r_offset;
5099 bfd_vma sb = 0; /* See note above. */
5100 bfd_vma residual;
5101 bfd_signed_vma signed_value;
5102 int group = 0;
5104 /* Determine which groups of bits to calculate. */
5105 switch (r_type)
5107 case R_ARM_LDR_PC_G0:
5108 case R_ARM_LDR_SB_G0:
5109 group = 0;
5110 break;
5112 case R_ARM_LDR_PC_G1:
5113 case R_ARM_LDR_SB_G1:
5114 group = 1;
5115 break;
5117 case R_ARM_LDR_PC_G2:
5118 case R_ARM_LDR_SB_G2:
5119 group = 2;
5120 break;
5122 default:
5123 abort();
5126 /* If REL, extract the addend from the insn. If RELA, it will
5127 have already been fetched for us. */
5128 if (globals->use_rel)
5130 int negative = (insn & (1 << 23)) ? 1 : -1;
5131 signed_addend = negative * (insn & 0xfff);
5134 /* Compute the value (X) to go in the place. */
5135 if (r_type == R_ARM_LDR_PC_G0
5136 || r_type == R_ARM_LDR_PC_G1
5137 || r_type == R_ARM_LDR_PC_G2)
5138 /* PC relative. */
5139 signed_value = value - pc + signed_addend;
5140 else
5141 /* Section base relative. */
5142 signed_value = value - sb + signed_addend;
5144 /* Calculate the value of the relevant G_{n-1} to obtain
5145 the residual at that stage. */
5146 calculate_group_reloc_mask (abs (signed_value), group - 1, &residual);
5148 /* Check for overflow. */
5149 if (residual >= 0x1000)
5151 (*_bfd_error_handler)
5152 (_("%B(%A+0x%lx): Overflow whilst splitting 0x%lx for group relocation %s"),
5153 input_bfd, input_section,
5154 (long) rel->r_offset, abs (signed_value), howto->name);
5155 return bfd_reloc_overflow;
5158 /* Mask out the value and U bit. */
5159 insn &= 0xff7ff000;
5161 /* Set the U bit if the value to go in the place is non-negative. */
5162 if (signed_value >= 0)
5163 insn |= 1 << 23;
5165 /* Encode the offset. */
5166 insn |= residual;
5168 bfd_put_32 (input_bfd, insn, hit_data);
5170 return bfd_reloc_ok;
5172 case R_ARM_LDRS_PC_G0:
5173 case R_ARM_LDRS_PC_G1:
5174 case R_ARM_LDRS_PC_G2:
5175 case R_ARM_LDRS_SB_G0:
5176 case R_ARM_LDRS_SB_G1:
5177 case R_ARM_LDRS_SB_G2:
5179 bfd_vma insn = bfd_get_32 (input_bfd, hit_data);
5180 bfd_vma pc = input_section->output_section->vma
5181 + input_section->output_offset + rel->r_offset;
5182 bfd_vma sb = 0; /* See note above. */
5183 bfd_vma residual;
5184 bfd_signed_vma signed_value;
5185 int group = 0;
5187 /* Determine which groups of bits to calculate. */
5188 switch (r_type)
5190 case R_ARM_LDRS_PC_G0:
5191 case R_ARM_LDRS_SB_G0:
5192 group = 0;
5193 break;
5195 case R_ARM_LDRS_PC_G1:
5196 case R_ARM_LDRS_SB_G1:
5197 group = 1;
5198 break;
5200 case R_ARM_LDRS_PC_G2:
5201 case R_ARM_LDRS_SB_G2:
5202 group = 2;
5203 break;
5205 default:
5206 abort();
5209 /* If REL, extract the addend from the insn. If RELA, it will
5210 have already been fetched for us. */
5211 if (globals->use_rel)
5213 int negative = (insn & (1 << 23)) ? 1 : -1;
5214 signed_addend = negative * (((insn & 0xf00) >> 4) + (insn & 0xf));
5217 /* Compute the value (X) to go in the place. */
5218 if (r_type == R_ARM_LDRS_PC_G0
5219 || r_type == R_ARM_LDRS_PC_G1
5220 || r_type == R_ARM_LDRS_PC_G2)
5221 /* PC relative. */
5222 signed_value = value - pc + signed_addend;
5223 else
5224 /* Section base relative. */
5225 signed_value = value - sb + signed_addend;
5227 /* Calculate the value of the relevant G_{n-1} to obtain
5228 the residual at that stage. */
5229 calculate_group_reloc_mask (abs (signed_value), group - 1, &residual);
5231 /* Check for overflow. */
5232 if (residual >= 0x100)
5234 (*_bfd_error_handler)
5235 (_("%B(%A+0x%lx): Overflow whilst splitting 0x%lx for group relocation %s"),
5236 input_bfd, input_section,
5237 (long) rel->r_offset, abs (signed_value), howto->name);
5238 return bfd_reloc_overflow;
5241 /* Mask out the value and U bit. */
5242 insn &= 0xff7ff0f0;
5244 /* Set the U bit if the value to go in the place is non-negative. */
5245 if (signed_value >= 0)
5246 insn |= 1 << 23;
5248 /* Encode the offset. */
5249 insn |= ((residual & 0xf0) << 4) | (residual & 0xf);
5251 bfd_put_32 (input_bfd, insn, hit_data);
5253 return bfd_reloc_ok;
5255 case R_ARM_LDC_PC_G0:
5256 case R_ARM_LDC_PC_G1:
5257 case R_ARM_LDC_PC_G2:
5258 case R_ARM_LDC_SB_G0:
5259 case R_ARM_LDC_SB_G1:
5260 case R_ARM_LDC_SB_G2:
5262 bfd_vma insn = bfd_get_32 (input_bfd, hit_data);
5263 bfd_vma pc = input_section->output_section->vma
5264 + input_section->output_offset + rel->r_offset;
5265 bfd_vma sb = 0; /* See note above. */
5266 bfd_vma residual;
5267 bfd_signed_vma signed_value;
5268 int group = 0;
5270 /* Determine which groups of bits to calculate. */
5271 switch (r_type)
5273 case R_ARM_LDC_PC_G0:
5274 case R_ARM_LDC_SB_G0:
5275 group = 0;
5276 break;
5278 case R_ARM_LDC_PC_G1:
5279 case R_ARM_LDC_SB_G1:
5280 group = 1;
5281 break;
5283 case R_ARM_LDC_PC_G2:
5284 case R_ARM_LDC_SB_G2:
5285 group = 2;
5286 break;
5288 default:
5289 abort();
5292 /* If REL, extract the addend from the insn. If RELA, it will
5293 have already been fetched for us. */
5294 if (globals->use_rel)
5296 int negative = (insn & (1 << 23)) ? 1 : -1;
5297 signed_addend = negative * ((insn & 0xff) << 2);
5300 /* Compute the value (X) to go in the place. */
5301 if (r_type == R_ARM_LDC_PC_G0
5302 || r_type == R_ARM_LDC_PC_G1
5303 || r_type == R_ARM_LDC_PC_G2)
5304 /* PC relative. */
5305 signed_value = value - pc + signed_addend;
5306 else
5307 /* Section base relative. */
5308 signed_value = value - sb + signed_addend;
5310 /* Calculate the value of the relevant G_{n-1} to obtain
5311 the residual at that stage. */
5312 calculate_group_reloc_mask (abs (signed_value), group - 1, &residual);
5314 /* Check for overflow. (The absolute value to go in the place must be
5315 divisible by four and, after having been divided by four, must
5316 fit in eight bits.) */
5317 if ((residual & 0x3) != 0 || residual >= 0x400)
5319 (*_bfd_error_handler)
5320 (_("%B(%A+0x%lx): Overflow whilst splitting 0x%lx for group relocation %s"),
5321 input_bfd, input_section,
5322 (long) rel->r_offset, abs (signed_value), howto->name);
5323 return bfd_reloc_overflow;
5326 /* Mask out the value and U bit. */
5327 insn &= 0xff7fff00;
5329 /* Set the U bit if the value to go in the place is non-negative. */
5330 if (signed_value >= 0)
5331 insn |= 1 << 23;
5333 /* Encode the offset. */
5334 insn |= residual >> 2;
5336 bfd_put_32 (input_bfd, insn, hit_data);
5338 return bfd_reloc_ok;
5340 default:
5341 return bfd_reloc_notsupported;
5346 static int
5347 uleb128_size (unsigned int i)
5349 int size;
5350 size = 1;
5351 while (i >= 0x80)
5353 i >>= 7;
5354 size++;
5356 return size;
5359 /* Return TRUE if the attribute has the default value (0/""). */
5360 static bfd_boolean
5361 is_default_attr (aeabi_attribute *attr)
5363 if ((attr->type & 1) && attr->i != 0)
5364 return FALSE;
5365 if ((attr->type & 2) && attr->s && *attr->s)
5366 return FALSE;
5368 return TRUE;
5371 /* Return the size of a single attribute. */
5372 static bfd_vma
5373 eabi_attr_size(int tag, aeabi_attribute *attr)
5375 bfd_vma size;
5377 if (is_default_attr (attr))
5378 return 0;
5380 size = uleb128_size (tag);
5381 if (attr->type & 1)
5382 size += uleb128_size (attr->i);
5383 if (attr->type & 2)
5384 size += strlen ((char *)attr->s) + 1;
5385 return size;
5388 /* Returns the size of the eabi object attributess section. */
5389 bfd_vma
5390 elf32_arm_eabi_attr_size (bfd *abfd)
5392 bfd_vma size;
5393 aeabi_attribute *attr;
5394 aeabi_attribute_list *list;
5395 int i;
5397 attr = elf32_arm_tdata (abfd)->known_eabi_attributes;
5398 size = 16; /* 'A' <size> "aeabi" 0x1 <size>. */
5399 for (i = 4; i < NUM_KNOWN_ATTRIBUTES; i++)
5400 size += eabi_attr_size (i, &attr[i]);
5402 for (list = elf32_arm_tdata (abfd)->other_eabi_attributes;
5403 list;
5404 list = list->next)
5405 size += eabi_attr_size (list->tag, &list->attr);
5407 return size;
5410 static bfd_byte *
5411 write_uleb128 (bfd_byte *p, unsigned int val)
5413 bfd_byte c;
5416 c = val & 0x7f;
5417 val >>= 7;
5418 if (val)
5419 c |= 0x80;
5420 *(p++) = c;
5422 while (val);
5423 return p;
5426 /* Write attribute ATTR to butter P, and return a pointer to the following
5427 byte. */
5428 static bfd_byte *
5429 write_eabi_attribute (bfd_byte *p, int tag, aeabi_attribute *attr)
5431 /* Suppress default entries. */
5432 if (is_default_attr(attr))
5433 return p;
5435 p = write_uleb128 (p, tag);
5436 if (attr->type & 1)
5437 p = write_uleb128 (p, attr->i);
5438 if (attr->type & 2)
5440 int len;
5442 len = strlen (attr->s) + 1;
5443 memcpy (p, attr->s, len);
5444 p += len;
5447 return p;
5450 /* Write the contents of the eabi attributes section to p. */
5451 void
5452 elf32_arm_set_eabi_attr_contents (bfd *abfd, bfd_byte *contents, bfd_vma size)
5454 bfd_byte *p;
5455 aeabi_attribute *attr;
5456 aeabi_attribute_list *list;
5457 int i;
5459 p = contents;
5460 *(p++) = 'A';
5461 bfd_put_32 (abfd, size - 1, p);
5462 p += 4;
5463 memcpy (p, "aeabi", 6);
5464 p += 6;
5465 *(p++) = Tag_File;
5466 bfd_put_32 (abfd, size - 11, p);
5467 p += 4;
5469 attr = elf32_arm_tdata (abfd)->known_eabi_attributes;
5470 for (i = 4; i < NUM_KNOWN_ATTRIBUTES; i++)
5471 p = write_eabi_attribute (p, i, &attr[i]);
5473 for (list = elf32_arm_tdata (abfd)->other_eabi_attributes;
5474 list;
5475 list = list->next)
5476 p = write_eabi_attribute (p, list->tag, &list->attr);
5479 /* Override final_link to handle EABI object attribute sections. */
5481 static bfd_boolean
5482 elf32_arm_bfd_final_link (bfd *abfd, struct bfd_link_info *info)
5484 asection *o;
5485 struct bfd_link_order *p;
5486 asection *attr_section = NULL;
5487 bfd_byte *contents;
5488 bfd_vma size = 0;
5490 /* elf32_arm_merge_private_bfd_data will already have merged the
5491 object attributes. Remove the input sections from the link, and set
5492 the contents of the output secton. */
5493 for (o = abfd->sections; o != NULL; o = o->next)
5495 if (strcmp (o->name, ".ARM.attributes") == 0)
5497 for (p = o->map_head.link_order; p != NULL; p = p->next)
5499 asection *input_section;
5501 if (p->type != bfd_indirect_link_order)
5502 continue;
5503 input_section = p->u.indirect.section;
5504 /* Hack: reset the SEC_HAS_CONTENTS flag so that
5505 elf_link_input_bfd ignores this section. */
5506 input_section->flags &= ~SEC_HAS_CONTENTS;
5509 size = elf32_arm_eabi_attr_size (abfd);
5510 bfd_set_section_size (abfd, o, size);
5511 attr_section = o;
5512 /* Skip this section later on. */
5513 o->map_head.link_order = NULL;
5516 /* Invoke the ELF linker to do all the work. */
5517 if (!bfd_elf_final_link (abfd, info))
5518 return FALSE;
5520 if (attr_section)
5522 contents = bfd_malloc(size);
5523 if (contents == NULL)
5524 return FALSE;
5525 elf32_arm_set_eabi_attr_contents (abfd, contents, size);
5526 bfd_set_section_contents (abfd, attr_section, contents, 0, size);
5527 free (contents);
5529 return TRUE;
5533 /* Add INCREMENT to the reloc (of type HOWTO) at ADDRESS. */
5534 static void
5535 arm_add_to_rel (bfd * abfd,
5536 bfd_byte * address,
5537 reloc_howto_type * howto,
5538 bfd_signed_vma increment)
5540 bfd_signed_vma addend;
5542 if (howto->type == R_ARM_THM_CALL)
5544 int upper_insn, lower_insn;
5545 int upper, lower;
5547 upper_insn = bfd_get_16 (abfd, address);
5548 lower_insn = bfd_get_16 (abfd, address + 2);
5549 upper = upper_insn & 0x7ff;
5550 lower = lower_insn & 0x7ff;
5552 addend = (upper << 12) | (lower << 1);
5553 addend += increment;
5554 addend >>= 1;
5556 upper_insn = (upper_insn & 0xf800) | ((addend >> 11) & 0x7ff);
5557 lower_insn = (lower_insn & 0xf800) | (addend & 0x7ff);
5559 bfd_put_16 (abfd, (bfd_vma) upper_insn, address);
5560 bfd_put_16 (abfd, (bfd_vma) lower_insn, address + 2);
5562 else
5564 bfd_vma contents;
5566 contents = bfd_get_32 (abfd, address);
5568 /* Get the (signed) value from the instruction. */
5569 addend = contents & howto->src_mask;
5570 if (addend & ((howto->src_mask + 1) >> 1))
5572 bfd_signed_vma mask;
5574 mask = -1;
5575 mask &= ~ howto->src_mask;
5576 addend |= mask;
5579 /* Add in the increment, (which is a byte value). */
5580 switch (howto->type)
5582 default:
5583 addend += increment;
5584 break;
5586 case R_ARM_PC24:
5587 case R_ARM_PLT32:
5588 case R_ARM_CALL:
5589 case R_ARM_JUMP24:
5590 addend <<= howto->size;
5591 addend += increment;
5593 /* Should we check for overflow here ? */
5595 /* Drop any undesired bits. */
5596 addend >>= howto->rightshift;
5597 break;
5600 contents = (contents & ~ howto->dst_mask) | (addend & howto->dst_mask);
5602 bfd_put_32 (abfd, contents, address);
5606 #define IS_ARM_TLS_RELOC(R_TYPE) \
5607 ((R_TYPE) == R_ARM_TLS_GD32 \
5608 || (R_TYPE) == R_ARM_TLS_LDO32 \
5609 || (R_TYPE) == R_ARM_TLS_LDM32 \
5610 || (R_TYPE) == R_ARM_TLS_DTPOFF32 \
5611 || (R_TYPE) == R_ARM_TLS_DTPMOD32 \
5612 || (R_TYPE) == R_ARM_TLS_TPOFF32 \
5613 || (R_TYPE) == R_ARM_TLS_LE32 \
5614 || (R_TYPE) == R_ARM_TLS_IE32)
5616 /* Relocate an ARM ELF section. */
5617 static bfd_boolean
5618 elf32_arm_relocate_section (bfd * output_bfd,
5619 struct bfd_link_info * info,
5620 bfd * input_bfd,
5621 asection * input_section,
5622 bfd_byte * contents,
5623 Elf_Internal_Rela * relocs,
5624 Elf_Internal_Sym * local_syms,
5625 asection ** local_sections)
5627 Elf_Internal_Shdr *symtab_hdr;
5628 struct elf_link_hash_entry **sym_hashes;
5629 Elf_Internal_Rela *rel;
5630 Elf_Internal_Rela *relend;
5631 const char *name;
5632 struct elf32_arm_link_hash_table * globals;
5634 globals = elf32_arm_hash_table (info);
5635 if (info->relocatable && !globals->use_rel)
5636 return TRUE;
5638 symtab_hdr = & elf_tdata (input_bfd)->symtab_hdr;
5639 sym_hashes = elf_sym_hashes (input_bfd);
5641 rel = relocs;
5642 relend = relocs + input_section->reloc_count;
5643 for (; rel < relend; rel++)
5645 int r_type;
5646 reloc_howto_type * howto;
5647 unsigned long r_symndx;
5648 Elf_Internal_Sym * sym;
5649 asection * sec;
5650 struct elf_link_hash_entry * h;
5651 bfd_vma relocation;
5652 bfd_reloc_status_type r;
5653 arelent bfd_reloc;
5654 char sym_type;
5655 bfd_boolean unresolved_reloc = FALSE;
5656 char *error_message = NULL;
5658 r_symndx = ELF32_R_SYM (rel->r_info);
5659 r_type = ELF32_R_TYPE (rel->r_info);
5660 r_type = arm_real_reloc_type (globals, r_type);
5662 if ( r_type == R_ARM_GNU_VTENTRY
5663 || r_type == R_ARM_GNU_VTINHERIT)
5664 continue;
5666 bfd_reloc.howto = elf32_arm_howto_from_type (r_type);
5667 howto = bfd_reloc.howto;
5669 if (info->relocatable && globals->use_rel)
5671 /* This is a relocatable link. We don't have to change
5672 anything, unless the reloc is against a section symbol,
5673 in which case we have to adjust according to where the
5674 section symbol winds up in the output section. */
5675 if (r_symndx < symtab_hdr->sh_info)
5677 sym = local_syms + r_symndx;
5678 if (ELF_ST_TYPE (sym->st_info) == STT_SECTION)
5680 sec = local_sections[r_symndx];
5681 arm_add_to_rel (input_bfd, contents + rel->r_offset,
5682 howto,
5683 (bfd_signed_vma) (sec->output_offset
5684 + sym->st_value));
5688 continue;
5691 /* This is a final link. */
5692 h = NULL;
5693 sym = NULL;
5694 sec = NULL;
5696 if (r_symndx < symtab_hdr->sh_info)
5698 sym = local_syms + r_symndx;
5699 sym_type = ELF32_ST_TYPE (sym->st_info);
5700 sec = local_sections[r_symndx];
5701 if (globals->use_rel)
5703 relocation = (sec->output_section->vma
5704 + sec->output_offset
5705 + sym->st_value);
5706 if ((sec->flags & SEC_MERGE)
5707 && ELF_ST_TYPE (sym->st_info) == STT_SECTION)
5709 asection *msec;
5710 bfd_vma addend, value;
5712 if (howto->rightshift)
5714 (*_bfd_error_handler)
5715 (_("%B(%A+0x%lx): %s relocation against SEC_MERGE section"),
5716 input_bfd, input_section,
5717 (long) rel->r_offset, howto->name);
5718 return FALSE;
5721 value = bfd_get_32 (input_bfd, contents + rel->r_offset);
5723 /* Get the (signed) value from the instruction. */
5724 addend = value & howto->src_mask;
5725 if (addend & ((howto->src_mask + 1) >> 1))
5727 bfd_signed_vma mask;
5729 mask = -1;
5730 mask &= ~ howto->src_mask;
5731 addend |= mask;
5733 msec = sec;
5734 addend =
5735 _bfd_elf_rel_local_sym (output_bfd, sym, &msec, addend)
5736 - relocation;
5737 addend += msec->output_section->vma + msec->output_offset;
5738 value = (value & ~ howto->dst_mask) | (addend & howto->dst_mask);
5739 bfd_put_32 (input_bfd, value, contents + rel->r_offset);
5742 else
5743 relocation = _bfd_elf_rela_local_sym (output_bfd, sym, &sec, rel);
5745 else
5747 bfd_boolean warned;
5749 RELOC_FOR_GLOBAL_SYMBOL (info, input_bfd, input_section, rel,
5750 r_symndx, symtab_hdr, sym_hashes,
5751 h, sec, relocation,
5752 unresolved_reloc, warned);
5754 sym_type = h->type;
5757 if (h != NULL)
5758 name = h->root.root.string;
5759 else
5761 name = (bfd_elf_string_from_elf_section
5762 (input_bfd, symtab_hdr->sh_link, sym->st_name));
5763 if (name == NULL || *name == '\0')
5764 name = bfd_section_name (input_bfd, sec);
5767 if (r_symndx != 0
5768 && r_type != R_ARM_NONE
5769 && (h == NULL
5770 || h->root.type == bfd_link_hash_defined
5771 || h->root.type == bfd_link_hash_defweak)
5772 && IS_ARM_TLS_RELOC (r_type) != (sym_type == STT_TLS))
5774 (*_bfd_error_handler)
5775 ((sym_type == STT_TLS
5776 ? _("%B(%A+0x%lx): %s used with TLS symbol %s")
5777 : _("%B(%A+0x%lx): %s used with non-TLS symbol %s")),
5778 input_bfd,
5779 input_section,
5780 (long) rel->r_offset,
5781 howto->name,
5782 name);
5785 r = elf32_arm_final_link_relocate (howto, input_bfd, output_bfd,
5786 input_section, contents, rel,
5787 relocation, info, sec, name,
5788 (h ? ELF_ST_TYPE (h->type) :
5789 ELF_ST_TYPE (sym->st_info)), h,
5790 &unresolved_reloc, &error_message);
5792 /* Dynamic relocs are not propagated for SEC_DEBUGGING sections
5793 because such sections are not SEC_ALLOC and thus ld.so will
5794 not process them. */
5795 if (unresolved_reloc
5796 && !((input_section->flags & SEC_DEBUGGING) != 0
5797 && h->def_dynamic))
5799 (*_bfd_error_handler)
5800 (_("%B(%A+0x%lx): unresolvable %s relocation against symbol `%s'"),
5801 input_bfd,
5802 input_section,
5803 (long) rel->r_offset,
5804 howto->name,
5805 h->root.root.string);
5806 return FALSE;
5809 if (r != bfd_reloc_ok)
5811 switch (r)
5813 case bfd_reloc_overflow:
5814 /* If the overflowing reloc was to an undefined symbol,
5815 we have already printed one error message and there
5816 is no point complaining again. */
5817 if ((! h ||
5818 h->root.type != bfd_link_hash_undefined)
5819 && (!((*info->callbacks->reloc_overflow)
5820 (info, (h ? &h->root : NULL), name, howto->name,
5821 (bfd_vma) 0, input_bfd, input_section,
5822 rel->r_offset))))
5823 return FALSE;
5824 break;
5826 case bfd_reloc_undefined:
5827 if (!((*info->callbacks->undefined_symbol)
5828 (info, name, input_bfd, input_section,
5829 rel->r_offset, TRUE)))
5830 return FALSE;
5831 break;
5833 case bfd_reloc_outofrange:
5834 error_message = _("out of range");
5835 goto common_error;
5837 case bfd_reloc_notsupported:
5838 error_message = _("unsupported relocation");
5839 goto common_error;
5841 case bfd_reloc_dangerous:
5842 /* error_message should already be set. */
5843 goto common_error;
5845 default:
5846 error_message = _("unknown error");
5847 /* fall through */
5849 common_error:
5850 BFD_ASSERT (error_message != NULL);
5851 if (!((*info->callbacks->reloc_dangerous)
5852 (info, error_message, input_bfd, input_section,
5853 rel->r_offset)))
5854 return FALSE;
5855 break;
5860 return TRUE;
5863 /* Allocate/find an object attribute. */
5864 static aeabi_attribute *
5865 elf32_arm_new_eabi_attr (bfd *abfd, int tag)
5867 aeabi_attribute *attr;
5868 aeabi_attribute_list *list;
5869 aeabi_attribute_list *p;
5870 aeabi_attribute_list **lastp;
5873 if (tag < NUM_KNOWN_ATTRIBUTES)
5875 /* Knwon tags are preallocated. */
5876 attr = &elf32_arm_tdata (abfd)->known_eabi_attributes[tag];
5878 else
5880 /* Create a new tag. */
5881 list = (aeabi_attribute_list *)
5882 bfd_alloc (abfd, sizeof (aeabi_attribute_list));
5883 memset (list, 0, sizeof (aeabi_attribute_list));
5884 list->tag = tag;
5885 /* Keep the tag list in order. */
5886 lastp = &elf32_arm_tdata (abfd)->other_eabi_attributes;
5887 for (p = *lastp; p; p = p->next)
5889 if (tag < p->tag)
5890 break;
5891 lastp = &p->next;
5893 list->next = *lastp;
5894 *lastp = list;
5895 attr = &list->attr;
5898 return attr;
5902 elf32_arm_get_eabi_attr_int (bfd *abfd, int tag)
5904 aeabi_attribute_list *p;
5906 if (tag < NUM_KNOWN_ATTRIBUTES)
5908 /* Knwon tags are preallocated. */
5909 return elf32_arm_tdata (abfd)->known_eabi_attributes[tag].i;
5911 else
5913 for (p = elf32_arm_tdata (abfd)->other_eabi_attributes;
5915 p = p->next)
5917 if (tag == p->tag)
5918 return p->attr.i;
5919 if (tag < p->tag)
5920 break;
5922 return 0;
5926 void
5927 elf32_arm_add_eabi_attr_int (bfd *abfd, int tag, unsigned int i)
5929 aeabi_attribute *attr;
5931 attr = elf32_arm_new_eabi_attr (abfd, tag);
5932 attr->type = 1;
5933 attr->i = i;
5936 static char *
5937 attr_strdup (bfd *abfd, const char * s)
5939 char * p;
5940 int len;
5942 len = strlen (s) + 1;
5943 p = (char *)bfd_alloc(abfd, len);
5944 return memcpy (p, s, len);
5947 void
5948 elf32_arm_add_eabi_attr_string (bfd *abfd, int tag, const char *s)
5950 aeabi_attribute *attr;
5952 attr = elf32_arm_new_eabi_attr (abfd, tag);
5953 attr->type = 2;
5954 attr->s = attr_strdup (abfd, s);
5957 void
5958 elf32_arm_add_eabi_attr_compat (bfd *abfd, unsigned int i, const char *s)
5960 aeabi_attribute_list *list;
5961 aeabi_attribute_list *p;
5962 aeabi_attribute_list **lastp;
5964 list = (aeabi_attribute_list *)
5965 bfd_alloc (abfd, sizeof (aeabi_attribute_list));
5966 memset (list, 0, sizeof (aeabi_attribute_list));
5967 list->tag = Tag_compatibility;
5968 list->attr.type = 3;
5969 list->attr.i = i;
5970 list->attr.s = attr_strdup (abfd, s);
5972 lastp = &elf32_arm_tdata (abfd)->other_eabi_attributes;
5973 for (p = *lastp; p; p = p->next)
5975 int cmp;
5976 if (p->tag != Tag_compatibility)
5977 break;
5978 cmp = strcmp(s, p->attr.s);
5979 if (cmp < 0 || (cmp == 0 && i < p->attr.i))
5980 break;
5981 lastp = &p->next;
5983 list->next = *lastp;
5984 *lastp = list;
5987 /* Set the right machine number. */
5989 static bfd_boolean
5990 elf32_arm_object_p (bfd *abfd)
5992 unsigned int mach;
5994 mach = bfd_arm_get_mach_from_notes (abfd, ARM_NOTE_SECTION);
5996 if (mach != bfd_mach_arm_unknown)
5997 bfd_default_set_arch_mach (abfd, bfd_arch_arm, mach);
5999 else if (elf_elfheader (abfd)->e_flags & EF_ARM_MAVERICK_FLOAT)
6000 bfd_default_set_arch_mach (abfd, bfd_arch_arm, bfd_mach_arm_ep9312);
6002 else
6003 bfd_default_set_arch_mach (abfd, bfd_arch_arm, mach);
6005 return TRUE;
6008 /* Function to keep ARM specific flags in the ELF header. */
6010 static bfd_boolean
6011 elf32_arm_set_private_flags (bfd *abfd, flagword flags)
6013 if (elf_flags_init (abfd)
6014 && elf_elfheader (abfd)->e_flags != flags)
6016 if (EF_ARM_EABI_VERSION (flags) == EF_ARM_EABI_UNKNOWN)
6018 if (flags & EF_ARM_INTERWORK)
6019 (*_bfd_error_handler)
6020 (_("Warning: Not setting interworking flag of %B since it has already been specified as non-interworking"),
6021 abfd);
6022 else
6023 _bfd_error_handler
6024 (_("Warning: Clearing the interworking flag of %B due to outside request"),
6025 abfd);
6028 else
6030 elf_elfheader (abfd)->e_flags = flags;
6031 elf_flags_init (abfd) = TRUE;
6034 return TRUE;
6037 /* Copy the eabi object attribute from IBFD to OBFD. */
6038 static void
6039 copy_eabi_attributes (bfd *ibfd, bfd *obfd)
6041 aeabi_attribute *in_attr;
6042 aeabi_attribute *out_attr;
6043 aeabi_attribute_list *list;
6044 int i;
6046 in_attr = &elf32_arm_tdata (ibfd)->known_eabi_attributes[4];
6047 out_attr = &elf32_arm_tdata (obfd)->known_eabi_attributes[4];
6048 for (i = 4; i < NUM_KNOWN_ATTRIBUTES; i++)
6050 out_attr->i = in_attr->i;
6051 if (in_attr->s && *in_attr->s)
6052 out_attr->s = attr_strdup (obfd, in_attr->s);
6053 in_attr++;
6054 out_attr++;
6057 for (list = elf32_arm_tdata (ibfd)->other_eabi_attributes;
6058 list;
6059 list = list->next)
6061 in_attr = &list->attr;
6062 switch (in_attr->type)
6064 case 1:
6065 elf32_arm_add_eabi_attr_int (obfd, list->tag, in_attr->i);
6066 break;
6067 case 2:
6068 elf32_arm_add_eabi_attr_string (obfd, list->tag, in_attr->s);
6069 break;
6070 case 3:
6071 elf32_arm_add_eabi_attr_compat (obfd, in_attr->i, in_attr->s);
6072 break;
6073 default:
6074 abort();
6080 /* Copy backend specific data from one object module to another. */
6082 static bfd_boolean
6083 elf32_arm_copy_private_bfd_data (bfd *ibfd, bfd *obfd)
6085 flagword in_flags;
6086 flagword out_flags;
6088 if ( bfd_get_flavour (ibfd) != bfd_target_elf_flavour
6089 || bfd_get_flavour (obfd) != bfd_target_elf_flavour)
6090 return TRUE;
6092 in_flags = elf_elfheader (ibfd)->e_flags;
6093 out_flags = elf_elfheader (obfd)->e_flags;
6095 if (elf_flags_init (obfd)
6096 && EF_ARM_EABI_VERSION (out_flags) == EF_ARM_EABI_UNKNOWN
6097 && in_flags != out_flags)
6099 /* Cannot mix APCS26 and APCS32 code. */
6100 if ((in_flags & EF_ARM_APCS_26) != (out_flags & EF_ARM_APCS_26))
6101 return FALSE;
6103 /* Cannot mix float APCS and non-float APCS code. */
6104 if ((in_flags & EF_ARM_APCS_FLOAT) != (out_flags & EF_ARM_APCS_FLOAT))
6105 return FALSE;
6107 /* If the src and dest have different interworking flags
6108 then turn off the interworking bit. */
6109 if ((in_flags & EF_ARM_INTERWORK) != (out_flags & EF_ARM_INTERWORK))
6111 if (out_flags & EF_ARM_INTERWORK)
6112 _bfd_error_handler
6113 (_("Warning: Clearing the interworking flag of %B because non-interworking code in %B has been linked with it"),
6114 obfd, ibfd);
6116 in_flags &= ~EF_ARM_INTERWORK;
6119 /* Likewise for PIC, though don't warn for this case. */
6120 if ((in_flags & EF_ARM_PIC) != (out_flags & EF_ARM_PIC))
6121 in_flags &= ~EF_ARM_PIC;
6124 elf_elfheader (obfd)->e_flags = in_flags;
6125 elf_flags_init (obfd) = TRUE;
6127 /* Also copy the EI_OSABI field. */
6128 elf_elfheader (obfd)->e_ident[EI_OSABI] =
6129 elf_elfheader (ibfd)->e_ident[EI_OSABI];
6131 /* Copy EABI object attributes. */
6132 copy_eabi_attributes (ibfd, obfd);
6134 return TRUE;
6137 /* Values for Tag_ABI_PCS_R9_use. */
6138 enum
6140 AEABI_R9_V6,
6141 AEABI_R9_SB,
6142 AEABI_R9_TLS,
6143 AEABI_R9_unused
6146 /* Values for Tag_ABI_PCS_RW_data. */
6147 enum
6149 AEABI_PCS_RW_data_absolute,
6150 AEABI_PCS_RW_data_PCrel,
6151 AEABI_PCS_RW_data_SBrel,
6152 AEABI_PCS_RW_data_unused
6155 /* Values for Tag_ABI_enum_size. */
6156 enum
6158 AEABI_enum_unused,
6159 AEABI_enum_short,
6160 AEABI_enum_wide,
6161 AEABI_enum_forced_wide
6164 /* Merge EABI object attributes from IBFD into OBFD. Raise an error if there
6165 are conflicting attributes. */
6166 static bfd_boolean
6167 elf32_arm_merge_eabi_attributes (bfd *ibfd, bfd *obfd)
6169 aeabi_attribute *in_attr;
6170 aeabi_attribute *out_attr;
6171 aeabi_attribute_list *in_list;
6172 aeabi_attribute_list *out_list;
6173 /* Some tags have 0 = don't care, 1 = strong requirement,
6174 2 = weak requirement. */
6175 static const int order_312[3] = {3, 1, 2};
6176 int i;
6178 if (!elf32_arm_tdata (obfd)->known_eabi_attributes[0].i)
6180 /* This is the first object. Copy the attributes. */
6181 copy_eabi_attributes (ibfd, obfd);
6183 /* Use the Tag_null value to indicate the attributes have been
6184 initialized. */
6185 elf32_arm_tdata (obfd)->known_eabi_attributes[0].i = 1;
6187 return TRUE;
6190 in_attr = elf32_arm_tdata (ibfd)->known_eabi_attributes;
6191 out_attr = elf32_arm_tdata (obfd)->known_eabi_attributes;
6192 /* This needs to happen before Tag_ABI_FP_number_model is merged. */
6193 if (in_attr[Tag_ABI_VFP_args].i != out_attr[Tag_ABI_VFP_args].i)
6195 /* Ignore mismatches if teh object doesn't use floating point. */
6196 if (out_attr[Tag_ABI_FP_number_model].i == 0)
6197 out_attr[Tag_ABI_VFP_args].i = in_attr[Tag_ABI_VFP_args].i;
6198 else if (in_attr[Tag_ABI_FP_number_model].i != 0)
6200 _bfd_error_handler
6201 (_("ERROR: %B uses VFP register arguments, %B does not"),
6202 ibfd, obfd);
6203 return FALSE;
6207 for (i = 4; i < NUM_KNOWN_ATTRIBUTES; i++)
6209 /* Merge this attribute with existing attributes. */
6210 switch (i)
6212 case Tag_CPU_raw_name:
6213 case Tag_CPU_name:
6214 /* Use whichever has the greatest architecture requirements. We
6215 won't necessarily have both the above tags, so make sure input
6216 name is non-NULL. */
6217 if (in_attr[Tag_CPU_arch].i > out_attr[Tag_CPU_arch].i
6218 && in_attr[i].s)
6219 out_attr[i].s = attr_strdup(obfd, in_attr[i].s);
6220 break;
6222 case Tag_ABI_optimization_goals:
6223 case Tag_ABI_FP_optimization_goals:
6224 /* Use the first value seen. */
6225 break;
6227 case Tag_CPU_arch:
6228 case Tag_ARM_ISA_use:
6229 case Tag_THUMB_ISA_use:
6230 case Tag_VFP_arch:
6231 case Tag_WMMX_arch:
6232 case Tag_NEON_arch:
6233 /* ??? Do NEON and WMMX conflict? */
6234 case Tag_ABI_FP_rounding:
6235 case Tag_ABI_FP_denormal:
6236 case Tag_ABI_FP_exceptions:
6237 case Tag_ABI_FP_user_exceptions:
6238 case Tag_ABI_FP_number_model:
6239 case Tag_ABI_align8_preserved:
6240 case Tag_ABI_HardFP_use:
6241 /* Use the largest value specified. */
6242 if (in_attr[i].i > out_attr[i].i)
6243 out_attr[i].i = in_attr[i].i;
6244 break;
6246 case Tag_CPU_arch_profile:
6247 /* Warn if conflicting architecture profiles used. */
6248 if (out_attr[i].i && in_attr[i].i && in_attr[i].i != out_attr[i].i)
6250 _bfd_error_handler
6251 (_("ERROR: %B: Conflicting architecture profiles %c/%c"),
6252 ibfd, in_attr[i].i, out_attr[i].i);
6253 return FALSE;
6255 if (in_attr[i].i)
6256 out_attr[i].i = in_attr[i].i;
6257 break;
6258 case Tag_PCS_config:
6259 if (out_attr[i].i == 0)
6260 out_attr[i].i = in_attr[i].i;
6261 else if (in_attr[i].i != 0 && out_attr[i].i != 0)
6263 /* It's sometimes ok to mix different configs, so this is only
6264 a warning. */
6265 _bfd_error_handler
6266 (_("Warning: %B: Conflicting platform configuration"), ibfd);
6268 break;
6269 case Tag_ABI_PCS_R9_use:
6270 if (in_attr[i].i != out_attr[i].i
6271 && out_attr[i].i != AEABI_R9_unused
6272 && in_attr[i].i != AEABI_R9_unused)
6274 _bfd_error_handler
6275 (_("ERROR: %B: Conflicting use of R9"), ibfd);
6276 return FALSE;
6278 if (out_attr[i].i == AEABI_R9_unused)
6279 out_attr[i].i = in_attr[i].i;
6280 break;
6281 case Tag_ABI_PCS_RW_data:
6282 if (in_attr[i].i == AEABI_PCS_RW_data_SBrel
6283 && out_attr[Tag_ABI_PCS_R9_use].i != AEABI_R9_SB
6284 && out_attr[Tag_ABI_PCS_R9_use].i != AEABI_R9_unused)
6286 _bfd_error_handler
6287 (_("ERROR: %B: SB relative addressing conflicts with use of R9"),
6288 ibfd);
6289 return FALSE;
6291 /* Use the smallest value specified. */
6292 if (in_attr[i].i < out_attr[i].i)
6293 out_attr[i].i = in_attr[i].i;
6294 break;
6295 case Tag_ABI_PCS_RO_data:
6296 /* Use the smallest value specified. */
6297 if (in_attr[i].i < out_attr[i].i)
6298 out_attr[i].i = in_attr[i].i;
6299 break;
6300 case Tag_ABI_PCS_GOT_use:
6301 if (in_attr[i].i > 2 || out_attr[i].i > 2
6302 || order_312[in_attr[i].i] < order_312[out_attr[i].i])
6303 out_attr[i].i = in_attr[i].i;
6304 break;
6305 case Tag_ABI_PCS_wchar_t:
6306 if (out_attr[i].i && in_attr[i].i && out_attr[i].i != in_attr[i].i)
6308 _bfd_error_handler
6309 (_("ERROR: %B: Conflicting definitions of wchar_t"), ibfd);
6310 return FALSE;
6312 if (in_attr[i].i)
6313 out_attr[i].i = in_attr[i].i;
6314 break;
6315 case Tag_ABI_align8_needed:
6316 /* ??? Check against Tag_ABI_align8_preserved. */
6317 if (in_attr[i].i > 2 || out_attr[i].i > 2
6318 || order_312[in_attr[i].i] < order_312[out_attr[i].i])
6319 out_attr[i].i = in_attr[i].i;
6320 break;
6321 case Tag_ABI_enum_size:
6322 if (in_attr[i].i != AEABI_enum_unused)
6324 if (out_attr[i].i == AEABI_enum_unused
6325 || out_attr[i].i == AEABI_enum_forced_wide)
6327 /* The existing object is compatible with anything.
6328 Use whatever requirements the new object has. */
6329 out_attr[i].i = in_attr[i].i;
6331 else if (in_attr[i].i != AEABI_enum_forced_wide
6332 && out_attr[i].i != in_attr[i].i)
6334 _bfd_error_handler
6335 (_("ERROR: %B: Conflicting enum sizes"), ibfd);
6338 break;
6339 case Tag_ABI_VFP_args:
6340 /* Aready done. */
6341 break;
6342 case Tag_ABI_WMMX_args:
6343 if (in_attr[i].i != out_attr[i].i)
6345 _bfd_error_handler
6346 (_("ERROR: %B uses iWMMXt register arguments, %B does not"),
6347 ibfd, obfd);
6348 return FALSE;
6350 break;
6351 default: /* All known attributes should be explicitly covered. */
6352 abort ();
6356 in_list = elf32_arm_tdata (ibfd)->other_eabi_attributes;
6357 out_list = elf32_arm_tdata (ibfd)->other_eabi_attributes;
6358 while (in_list && in_list->tag == Tag_compatibility)
6360 in_attr = &in_list->attr;
6361 if (in_attr->i == 0)
6362 continue;
6363 if (in_attr->i == 1)
6365 _bfd_error_handler
6366 (_("ERROR: %B: Must be processed by '%s' toolchain"),
6367 ibfd, in_attr->s);
6368 return FALSE;
6370 if (!out_list || out_list->tag != Tag_compatibility
6371 || strcmp (in_attr->s, out_list->attr.s) != 0)
6373 /* Add this compatibility tag to the output. */
6374 elf32_arm_add_eabi_attr_compat (obfd, in_attr->i, in_attr->s);
6375 continue;
6377 out_attr = &out_list->attr;
6378 /* Check all the input tags with the same identifier. */
6379 for (;;)
6381 if (out_list->tag != Tag_compatibility
6382 || in_attr->i != out_attr->i
6383 || strcmp (in_attr->s, out_attr->s) != 0)
6385 _bfd_error_handler
6386 (_("ERROR: %B: Incompatible object tag '%s':%d"),
6387 ibfd, in_attr->s, in_attr->i);
6388 return FALSE;
6390 in_list = in_list->next;
6391 if (in_list->tag != Tag_compatibility
6392 || strcmp (in_attr->s, in_list->attr.s) != 0)
6393 break;
6394 in_attr = &in_list->attr;
6395 out_list = out_list->next;
6396 if (out_list)
6397 out_attr = &out_list->attr;
6400 /* Check the output doesn't have extra tags with this identifier. */
6401 if (out_list && out_list->tag == Tag_compatibility
6402 && strcmp (in_attr->s, out_list->attr.s) == 0)
6404 _bfd_error_handler
6405 (_("ERROR: %B: Incompatible object tag '%s':%d"),
6406 ibfd, in_attr->s, out_list->attr.i);
6407 return FALSE;
6411 for (; in_list; in_list = in_list->next)
6413 if ((in_list->tag & 128) < 64)
6415 _bfd_error_handler
6416 (_("Warning: %B: Unknown EABI object attribute %d"),
6417 ibfd, in_list->tag);
6418 break;
6421 return TRUE;
6425 /* Return TRUE if the two EABI versions are incompatible. */
6427 static bfd_boolean
6428 elf32_arm_versions_compatible (unsigned iver, unsigned over)
6430 /* v4 and v5 are the same spec before and after it was released,
6431 so allow mixing them. */
6432 if ((iver == EF_ARM_EABI_VER4 && over == EF_ARM_EABI_VER5)
6433 || (iver == EF_ARM_EABI_VER5 && over == EF_ARM_EABI_VER4))
6434 return TRUE;
6436 return (iver == over);
6439 /* Merge backend specific data from an object file to the output
6440 object file when linking. */
6442 static bfd_boolean
6443 elf32_arm_merge_private_bfd_data (bfd * ibfd, bfd * obfd)
6445 flagword out_flags;
6446 flagword in_flags;
6447 bfd_boolean flags_compatible = TRUE;
6448 asection *sec;
6450 /* Check if we have the same endianess. */
6451 if (! _bfd_generic_verify_endian_match (ibfd, obfd))
6452 return FALSE;
6454 if ( bfd_get_flavour (ibfd) != bfd_target_elf_flavour
6455 || bfd_get_flavour (obfd) != bfd_target_elf_flavour)
6456 return TRUE;
6458 if (!elf32_arm_merge_eabi_attributes (ibfd, obfd))
6459 return FALSE;
6461 /* The input BFD must have had its flags initialised. */
6462 /* The following seems bogus to me -- The flags are initialized in
6463 the assembler but I don't think an elf_flags_init field is
6464 written into the object. */
6465 /* BFD_ASSERT (elf_flags_init (ibfd)); */
6467 in_flags = elf_elfheader (ibfd)->e_flags;
6468 out_flags = elf_elfheader (obfd)->e_flags;
6470 if (!elf_flags_init (obfd))
6472 /* If the input is the default architecture and had the default
6473 flags then do not bother setting the flags for the output
6474 architecture, instead allow future merges to do this. If no
6475 future merges ever set these flags then they will retain their
6476 uninitialised values, which surprise surprise, correspond
6477 to the default values. */
6478 if (bfd_get_arch_info (ibfd)->the_default
6479 && elf_elfheader (ibfd)->e_flags == 0)
6480 return TRUE;
6482 elf_flags_init (obfd) = TRUE;
6483 elf_elfheader (obfd)->e_flags = in_flags;
6485 if (bfd_get_arch (obfd) == bfd_get_arch (ibfd)
6486 && bfd_get_arch_info (obfd)->the_default)
6487 return bfd_set_arch_mach (obfd, bfd_get_arch (ibfd), bfd_get_mach (ibfd));
6489 return TRUE;
6492 /* Determine what should happen if the input ARM architecture
6493 does not match the output ARM architecture. */
6494 if (! bfd_arm_merge_machines (ibfd, obfd))
6495 return FALSE;
6497 /* Identical flags must be compatible. */
6498 if (in_flags == out_flags)
6499 return TRUE;
6501 /* Check to see if the input BFD actually contains any sections. If
6502 not, its flags may not have been initialised either, but it
6503 cannot actually cause any incompatiblity. Do not short-circuit
6504 dynamic objects; their section list may be emptied by
6505 elf_link_add_object_symbols.
6507 Also check to see if there are no code sections in the input.
6508 In this case there is no need to check for code specific flags.
6509 XXX - do we need to worry about floating-point format compatability
6510 in data sections ? */
6511 if (!(ibfd->flags & DYNAMIC))
6513 bfd_boolean null_input_bfd = TRUE;
6514 bfd_boolean only_data_sections = TRUE;
6516 for (sec = ibfd->sections; sec != NULL; sec = sec->next)
6518 /* Ignore synthetic glue sections. */
6519 if (strcmp (sec->name, ".glue_7")
6520 && strcmp (sec->name, ".glue_7t"))
6522 if ((bfd_get_section_flags (ibfd, sec)
6523 & (SEC_LOAD | SEC_CODE | SEC_HAS_CONTENTS))
6524 == (SEC_LOAD | SEC_CODE | SEC_HAS_CONTENTS))
6525 only_data_sections = FALSE;
6527 null_input_bfd = FALSE;
6528 break;
6532 if (null_input_bfd || only_data_sections)
6533 return TRUE;
6536 /* Complain about various flag mismatches. */
6537 if (!elf32_arm_versions_compatible (EF_ARM_EABI_VERSION (in_flags),
6538 EF_ARM_EABI_VERSION (out_flags)))
6540 _bfd_error_handler
6541 (_("ERROR: Source object %B has EABI version %d, but target %B has EABI version %d"),
6542 ibfd, obfd,
6543 (in_flags & EF_ARM_EABIMASK) >> 24,
6544 (out_flags & EF_ARM_EABIMASK) >> 24);
6545 return FALSE;
6548 /* Not sure what needs to be checked for EABI versions >= 1. */
6549 /* VxWorks libraries do not use these flags. */
6550 if (get_elf_backend_data (obfd) != &elf32_arm_vxworks_bed
6551 && get_elf_backend_data (ibfd) != &elf32_arm_vxworks_bed
6552 && EF_ARM_EABI_VERSION (in_flags) == EF_ARM_EABI_UNKNOWN)
6554 if ((in_flags & EF_ARM_APCS_26) != (out_flags & EF_ARM_APCS_26))
6556 _bfd_error_handler
6557 (_("ERROR: %B is compiled for APCS-%d, whereas target %B uses APCS-%d"),
6558 ibfd, obfd,
6559 in_flags & EF_ARM_APCS_26 ? 26 : 32,
6560 out_flags & EF_ARM_APCS_26 ? 26 : 32);
6561 flags_compatible = FALSE;
6564 if ((in_flags & EF_ARM_APCS_FLOAT) != (out_flags & EF_ARM_APCS_FLOAT))
6566 if (in_flags & EF_ARM_APCS_FLOAT)
6567 _bfd_error_handler
6568 (_("ERROR: %B passes floats in float registers, whereas %B passes them in integer registers"),
6569 ibfd, obfd);
6570 else
6571 _bfd_error_handler
6572 (_("ERROR: %B passes floats in integer registers, whereas %B passes them in float registers"),
6573 ibfd, obfd);
6575 flags_compatible = FALSE;
6578 if ((in_flags & EF_ARM_VFP_FLOAT) != (out_flags & EF_ARM_VFP_FLOAT))
6580 if (in_flags & EF_ARM_VFP_FLOAT)
6581 _bfd_error_handler
6582 (_("ERROR: %B uses VFP instructions, whereas %B does not"),
6583 ibfd, obfd);
6584 else
6585 _bfd_error_handler
6586 (_("ERROR: %B uses FPA instructions, whereas %B does not"),
6587 ibfd, obfd);
6589 flags_compatible = FALSE;
6592 if ((in_flags & EF_ARM_MAVERICK_FLOAT) != (out_flags & EF_ARM_MAVERICK_FLOAT))
6594 if (in_flags & EF_ARM_MAVERICK_FLOAT)
6595 _bfd_error_handler
6596 (_("ERROR: %B uses Maverick instructions, whereas %B does not"),
6597 ibfd, obfd);
6598 else
6599 _bfd_error_handler
6600 (_("ERROR: %B does not use Maverick instructions, whereas %B does"),
6601 ibfd, obfd);
6603 flags_compatible = FALSE;
6606 #ifdef EF_ARM_SOFT_FLOAT
6607 if ((in_flags & EF_ARM_SOFT_FLOAT) != (out_flags & EF_ARM_SOFT_FLOAT))
6609 /* We can allow interworking between code that is VFP format
6610 layout, and uses either soft float or integer regs for
6611 passing floating point arguments and results. We already
6612 know that the APCS_FLOAT flags match; similarly for VFP
6613 flags. */
6614 if ((in_flags & EF_ARM_APCS_FLOAT) != 0
6615 || (in_flags & EF_ARM_VFP_FLOAT) == 0)
6617 if (in_flags & EF_ARM_SOFT_FLOAT)
6618 _bfd_error_handler
6619 (_("ERROR: %B uses software FP, whereas %B uses hardware FP"),
6620 ibfd, obfd);
6621 else
6622 _bfd_error_handler
6623 (_("ERROR: %B uses hardware FP, whereas %B uses software FP"),
6624 ibfd, obfd);
6626 flags_compatible = FALSE;
6629 #endif
6631 /* Interworking mismatch is only a warning. */
6632 if ((in_flags & EF_ARM_INTERWORK) != (out_flags & EF_ARM_INTERWORK))
6634 if (in_flags & EF_ARM_INTERWORK)
6636 _bfd_error_handler
6637 (_("Warning: %B supports interworking, whereas %B does not"),
6638 ibfd, obfd);
6640 else
6642 _bfd_error_handler
6643 (_("Warning: %B does not support interworking, whereas %B does"),
6644 ibfd, obfd);
6649 return flags_compatible;
6652 /* Display the flags field. */
6654 static bfd_boolean
6655 elf32_arm_print_private_bfd_data (bfd *abfd, void * ptr)
6657 FILE * file = (FILE *) ptr;
6658 unsigned long flags;
6660 BFD_ASSERT (abfd != NULL && ptr != NULL);
6662 /* Print normal ELF private data. */
6663 _bfd_elf_print_private_bfd_data (abfd, ptr);
6665 flags = elf_elfheader (abfd)->e_flags;
6666 /* Ignore init flag - it may not be set, despite the flags field
6667 containing valid data. */
6669 /* xgettext:c-format */
6670 fprintf (file, _("private flags = %lx:"), elf_elfheader (abfd)->e_flags);
6672 switch (EF_ARM_EABI_VERSION (flags))
6674 case EF_ARM_EABI_UNKNOWN:
6675 /* The following flag bits are GNU extensions and not part of the
6676 official ARM ELF extended ABI. Hence they are only decoded if
6677 the EABI version is not set. */
6678 if (flags & EF_ARM_INTERWORK)
6679 fprintf (file, _(" [interworking enabled]"));
6681 if (flags & EF_ARM_APCS_26)
6682 fprintf (file, " [APCS-26]");
6683 else
6684 fprintf (file, " [APCS-32]");
6686 if (flags & EF_ARM_VFP_FLOAT)
6687 fprintf (file, _(" [VFP float format]"));
6688 else if (flags & EF_ARM_MAVERICK_FLOAT)
6689 fprintf (file, _(" [Maverick float format]"));
6690 else
6691 fprintf (file, _(" [FPA float format]"));
6693 if (flags & EF_ARM_APCS_FLOAT)
6694 fprintf (file, _(" [floats passed in float registers]"));
6696 if (flags & EF_ARM_PIC)
6697 fprintf (file, _(" [position independent]"));
6699 if (flags & EF_ARM_NEW_ABI)
6700 fprintf (file, _(" [new ABI]"));
6702 if (flags & EF_ARM_OLD_ABI)
6703 fprintf (file, _(" [old ABI]"));
6705 if (flags & EF_ARM_SOFT_FLOAT)
6706 fprintf (file, _(" [software FP]"));
6708 flags &= ~(EF_ARM_INTERWORK | EF_ARM_APCS_26 | EF_ARM_APCS_FLOAT
6709 | EF_ARM_PIC | EF_ARM_NEW_ABI | EF_ARM_OLD_ABI
6710 | EF_ARM_SOFT_FLOAT | EF_ARM_VFP_FLOAT
6711 | EF_ARM_MAVERICK_FLOAT);
6712 break;
6714 case EF_ARM_EABI_VER1:
6715 fprintf (file, _(" [Version1 EABI]"));
6717 if (flags & EF_ARM_SYMSARESORTED)
6718 fprintf (file, _(" [sorted symbol table]"));
6719 else
6720 fprintf (file, _(" [unsorted symbol table]"));
6722 flags &= ~ EF_ARM_SYMSARESORTED;
6723 break;
6725 case EF_ARM_EABI_VER2:
6726 fprintf (file, _(" [Version2 EABI]"));
6728 if (flags & EF_ARM_SYMSARESORTED)
6729 fprintf (file, _(" [sorted symbol table]"));
6730 else
6731 fprintf (file, _(" [unsorted symbol table]"));
6733 if (flags & EF_ARM_DYNSYMSUSESEGIDX)
6734 fprintf (file, _(" [dynamic symbols use segment index]"));
6736 if (flags & EF_ARM_MAPSYMSFIRST)
6737 fprintf (file, _(" [mapping symbols precede others]"));
6739 flags &= ~(EF_ARM_SYMSARESORTED | EF_ARM_DYNSYMSUSESEGIDX
6740 | EF_ARM_MAPSYMSFIRST);
6741 break;
6743 case EF_ARM_EABI_VER3:
6744 fprintf (file, _(" [Version3 EABI]"));
6745 break;
6747 case EF_ARM_EABI_VER4:
6748 fprintf (file, _(" [Version4 EABI]"));
6749 goto eabi;
6751 case EF_ARM_EABI_VER5:
6752 fprintf (file, _(" [Version5 EABI]"));
6753 eabi:
6754 if (flags & EF_ARM_BE8)
6755 fprintf (file, _(" [BE8]"));
6757 if (flags & EF_ARM_LE8)
6758 fprintf (file, _(" [LE8]"));
6760 flags &= ~(EF_ARM_LE8 | EF_ARM_BE8);
6761 break;
6763 default:
6764 fprintf (file, _(" <EABI version unrecognised>"));
6765 break;
6768 flags &= ~ EF_ARM_EABIMASK;
6770 if (flags & EF_ARM_RELEXEC)
6771 fprintf (file, _(" [relocatable executable]"));
6773 if (flags & EF_ARM_HASENTRY)
6774 fprintf (file, _(" [has entry point]"));
6776 flags &= ~ (EF_ARM_RELEXEC | EF_ARM_HASENTRY);
6778 if (flags)
6779 fprintf (file, _("<Unrecognised flag bits set>"));
6781 fputc ('\n', file);
6783 return TRUE;
6786 static int
6787 elf32_arm_get_symbol_type (Elf_Internal_Sym * elf_sym, int type)
6789 switch (ELF_ST_TYPE (elf_sym->st_info))
6791 case STT_ARM_TFUNC:
6792 return ELF_ST_TYPE (elf_sym->st_info);
6794 case STT_ARM_16BIT:
6795 /* If the symbol is not an object, return the STT_ARM_16BIT flag.
6796 This allows us to distinguish between data used by Thumb instructions
6797 and non-data (which is probably code) inside Thumb regions of an
6798 executable. */
6799 if (type != STT_OBJECT && type != STT_TLS)
6800 return ELF_ST_TYPE (elf_sym->st_info);
6801 break;
6803 default:
6804 break;
6807 return type;
6810 static asection *
6811 elf32_arm_gc_mark_hook (asection *sec,
6812 struct bfd_link_info *info,
6813 Elf_Internal_Rela *rel,
6814 struct elf_link_hash_entry *h,
6815 Elf_Internal_Sym *sym)
6817 if (h != NULL)
6818 switch (ELF32_R_TYPE (rel->r_info))
6820 case R_ARM_GNU_VTINHERIT:
6821 case R_ARM_GNU_VTENTRY:
6822 return NULL;
6825 return _bfd_elf_gc_mark_hook (sec, info, rel, h, sym);
6828 /* Update the got entry reference counts for the section being removed. */
6830 static bfd_boolean
6831 elf32_arm_gc_sweep_hook (bfd * abfd,
6832 struct bfd_link_info * info,
6833 asection * sec,
6834 const Elf_Internal_Rela * relocs)
6836 Elf_Internal_Shdr *symtab_hdr;
6837 struct elf_link_hash_entry **sym_hashes;
6838 bfd_signed_vma *local_got_refcounts;
6839 const Elf_Internal_Rela *rel, *relend;
6840 struct elf32_arm_link_hash_table * globals;
6842 globals = elf32_arm_hash_table (info);
6844 elf_section_data (sec)->local_dynrel = NULL;
6846 symtab_hdr = &elf_tdata (abfd)->symtab_hdr;
6847 sym_hashes = elf_sym_hashes (abfd);
6848 local_got_refcounts = elf_local_got_refcounts (abfd);
6850 relend = relocs + sec->reloc_count;
6851 for (rel = relocs; rel < relend; rel++)
6853 unsigned long r_symndx;
6854 struct elf_link_hash_entry *h = NULL;
6855 int r_type;
6857 r_symndx = ELF32_R_SYM (rel->r_info);
6858 if (r_symndx >= symtab_hdr->sh_info)
6860 h = sym_hashes[r_symndx - symtab_hdr->sh_info];
6861 while (h->root.type == bfd_link_hash_indirect
6862 || h->root.type == bfd_link_hash_warning)
6863 h = (struct elf_link_hash_entry *) h->root.u.i.link;
6866 r_type = ELF32_R_TYPE (rel->r_info);
6867 r_type = arm_real_reloc_type (globals, r_type);
6868 switch (r_type)
6870 case R_ARM_GOT32:
6871 case R_ARM_GOT_PREL:
6872 case R_ARM_TLS_GD32:
6873 case R_ARM_TLS_IE32:
6874 if (h != NULL)
6876 if (h->got.refcount > 0)
6877 h->got.refcount -= 1;
6879 else if (local_got_refcounts != NULL)
6881 if (local_got_refcounts[r_symndx] > 0)
6882 local_got_refcounts[r_symndx] -= 1;
6884 break;
6886 case R_ARM_TLS_LDM32:
6887 elf32_arm_hash_table (info)->tls_ldm_got.refcount -= 1;
6888 break;
6890 case R_ARM_ABS32:
6891 case R_ARM_ABS32_NOI:
6892 case R_ARM_REL32:
6893 case R_ARM_REL32_NOI:
6894 case R_ARM_PC24:
6895 case R_ARM_PLT32:
6896 case R_ARM_CALL:
6897 case R_ARM_JUMP24:
6898 case R_ARM_PREL31:
6899 case R_ARM_THM_CALL:
6900 case R_ARM_MOVW_ABS_NC:
6901 case R_ARM_MOVT_ABS:
6902 case R_ARM_MOVW_PREL_NC:
6903 case R_ARM_MOVT_PREL:
6904 case R_ARM_THM_MOVW_ABS_NC:
6905 case R_ARM_THM_MOVT_ABS:
6906 case R_ARM_THM_MOVW_PREL_NC:
6907 case R_ARM_THM_MOVT_PREL:
6908 /* Should the interworking branches be here also? */
6910 if (h != NULL)
6912 struct elf32_arm_link_hash_entry *eh;
6913 struct elf32_arm_relocs_copied **pp;
6914 struct elf32_arm_relocs_copied *p;
6916 eh = (struct elf32_arm_link_hash_entry *) h;
6918 if (h->plt.refcount > 0)
6920 h->plt.refcount -= 1;
6921 if (ELF32_R_TYPE (rel->r_info) == R_ARM_THM_CALL)
6922 eh->plt_thumb_refcount--;
6925 if (r_type == R_ARM_ABS32
6926 || r_type == R_ARM_REL32
6927 || r_type == R_ARM_ABS32_NOI
6928 || r_type == R_ARM_REL32_NOI)
6930 for (pp = &eh->relocs_copied; (p = *pp) != NULL;
6931 pp = &p->next)
6932 if (p->section == sec)
6934 p->count -= 1;
6935 if (ELF32_R_TYPE (rel->r_info) == R_ARM_REL32
6936 || ELF32_R_TYPE (rel->r_info) == R_ARM_REL32_NOI)
6937 p->pc_count -= 1;
6938 if (p->count == 0)
6939 *pp = p->next;
6940 break;
6944 break;
6946 default:
6947 break;
6951 return TRUE;
6954 /* Look through the relocs for a section during the first phase. */
6956 static bfd_boolean
6957 elf32_arm_check_relocs (bfd *abfd, struct bfd_link_info *info,
6958 asection *sec, const Elf_Internal_Rela *relocs)
6960 Elf_Internal_Shdr *symtab_hdr;
6961 struct elf_link_hash_entry **sym_hashes;
6962 struct elf_link_hash_entry **sym_hashes_end;
6963 const Elf_Internal_Rela *rel;
6964 const Elf_Internal_Rela *rel_end;
6965 bfd *dynobj;
6966 asection *sreloc;
6967 bfd_vma *local_got_offsets;
6968 struct elf32_arm_link_hash_table *htab;
6970 if (info->relocatable)
6971 return TRUE;
6973 htab = elf32_arm_hash_table (info);
6974 sreloc = NULL;
6976 /* Create dynamic sections for relocatable executables so that we can
6977 copy relocations. */
6978 if (htab->root.is_relocatable_executable
6979 && ! htab->root.dynamic_sections_created)
6981 if (! _bfd_elf_link_create_dynamic_sections (abfd, info))
6982 return FALSE;
6985 dynobj = elf_hash_table (info)->dynobj;
6986 local_got_offsets = elf_local_got_offsets (abfd);
6988 symtab_hdr = &elf_tdata (abfd)->symtab_hdr;
6989 sym_hashes = elf_sym_hashes (abfd);
6990 sym_hashes_end = sym_hashes
6991 + symtab_hdr->sh_size / sizeof (Elf32_External_Sym);
6993 if (!elf_bad_symtab (abfd))
6994 sym_hashes_end -= symtab_hdr->sh_info;
6996 rel_end = relocs + sec->reloc_count;
6997 for (rel = relocs; rel < rel_end; rel++)
6999 struct elf_link_hash_entry *h;
7000 struct elf32_arm_link_hash_entry *eh;
7001 unsigned long r_symndx;
7002 int r_type;
7004 r_symndx = ELF32_R_SYM (rel->r_info);
7005 r_type = ELF32_R_TYPE (rel->r_info);
7006 r_type = arm_real_reloc_type (htab, r_type);
7008 if (r_symndx >= NUM_SHDR_ENTRIES (symtab_hdr))
7010 (*_bfd_error_handler) (_("%B: bad symbol index: %d"), abfd,
7011 r_symndx);
7012 return FALSE;
7015 if (r_symndx < symtab_hdr->sh_info)
7016 h = NULL;
7017 else
7019 h = sym_hashes[r_symndx - symtab_hdr->sh_info];
7020 while (h->root.type == bfd_link_hash_indirect
7021 || h->root.type == bfd_link_hash_warning)
7022 h = (struct elf_link_hash_entry *) h->root.u.i.link;
7025 eh = (struct elf32_arm_link_hash_entry *) h;
7027 switch (r_type)
7029 case R_ARM_GOT32:
7030 case R_ARM_GOT_PREL:
7031 case R_ARM_TLS_GD32:
7032 case R_ARM_TLS_IE32:
7033 /* This symbol requires a global offset table entry. */
7035 int tls_type, old_tls_type;
7037 switch (r_type)
7039 case R_ARM_TLS_GD32: tls_type = GOT_TLS_GD; break;
7040 case R_ARM_TLS_IE32: tls_type = GOT_TLS_IE; break;
7041 default: tls_type = GOT_NORMAL; break;
7044 if (h != NULL)
7046 h->got.refcount++;
7047 old_tls_type = elf32_arm_hash_entry (h)->tls_type;
7049 else
7051 bfd_signed_vma *local_got_refcounts;
7053 /* This is a global offset table entry for a local symbol. */
7054 local_got_refcounts = elf_local_got_refcounts (abfd);
7055 if (local_got_refcounts == NULL)
7057 bfd_size_type size;
7059 size = symtab_hdr->sh_info;
7060 size *= (sizeof (bfd_signed_vma) + sizeof(char));
7061 local_got_refcounts = bfd_zalloc (abfd, size);
7062 if (local_got_refcounts == NULL)
7063 return FALSE;
7064 elf_local_got_refcounts (abfd) = local_got_refcounts;
7065 elf32_arm_local_got_tls_type (abfd)
7066 = (char *) (local_got_refcounts + symtab_hdr->sh_info);
7068 local_got_refcounts[r_symndx] += 1;
7069 old_tls_type = elf32_arm_local_got_tls_type (abfd) [r_symndx];
7072 /* We will already have issued an error message if there is a
7073 TLS / non-TLS mismatch, based on the symbol type. We don't
7074 support any linker relaxations. So just combine any TLS
7075 types needed. */
7076 if (old_tls_type != GOT_UNKNOWN && old_tls_type != GOT_NORMAL
7077 && tls_type != GOT_NORMAL)
7078 tls_type |= old_tls_type;
7080 if (old_tls_type != tls_type)
7082 if (h != NULL)
7083 elf32_arm_hash_entry (h)->tls_type = tls_type;
7084 else
7085 elf32_arm_local_got_tls_type (abfd) [r_symndx] = tls_type;
7088 /* Fall through */
7090 case R_ARM_TLS_LDM32:
7091 if (r_type == R_ARM_TLS_LDM32)
7092 htab->tls_ldm_got.refcount++;
7093 /* Fall through */
7095 case R_ARM_GOTOFF32:
7096 case R_ARM_GOTPC:
7097 if (htab->sgot == NULL)
7099 if (htab->root.dynobj == NULL)
7100 htab->root.dynobj = abfd;
7101 if (!create_got_section (htab->root.dynobj, info))
7102 return FALSE;
7104 break;
7106 case R_ARM_ABS12:
7107 /* VxWorks uses dynamic R_ARM_ABS12 relocations for
7108 ldr __GOTT_INDEX__ offsets. */
7109 if (!htab->vxworks_p)
7110 break;
7111 /* Fall through */
7113 case R_ARM_ABS32:
7114 case R_ARM_ABS32_NOI:
7115 case R_ARM_REL32:
7116 case R_ARM_REL32_NOI:
7117 case R_ARM_PC24:
7118 case R_ARM_PLT32:
7119 case R_ARM_CALL:
7120 case R_ARM_JUMP24:
7121 case R_ARM_PREL31:
7122 case R_ARM_THM_CALL:
7123 case R_ARM_MOVW_ABS_NC:
7124 case R_ARM_MOVT_ABS:
7125 case R_ARM_MOVW_PREL_NC:
7126 case R_ARM_MOVT_PREL:
7127 case R_ARM_THM_MOVW_ABS_NC:
7128 case R_ARM_THM_MOVT_ABS:
7129 case R_ARM_THM_MOVW_PREL_NC:
7130 case R_ARM_THM_MOVT_PREL:
7131 /* Should the interworking branches be listed here? */
7132 if (h != NULL)
7134 /* If this reloc is in a read-only section, we might
7135 need a copy reloc. We can't check reliably at this
7136 stage whether the section is read-only, as input
7137 sections have not yet been mapped to output sections.
7138 Tentatively set the flag for now, and correct in
7139 adjust_dynamic_symbol. */
7140 if (!info->shared)
7141 h->non_got_ref = 1;
7143 /* We may need a .plt entry if the function this reloc
7144 refers to is in a different object. We can't tell for
7145 sure yet, because something later might force the
7146 symbol local. */
7147 if (r_type != R_ARM_ABS32
7148 && r_type != R_ARM_REL32
7149 && r_type != R_ARM_ABS32_NOI
7150 && r_type != R_ARM_REL32_NOI)
7151 h->needs_plt = 1;
7153 /* If we create a PLT entry, this relocation will reference
7154 it, even if it's an ABS32 relocation. */
7155 h->plt.refcount += 1;
7157 if (r_type == R_ARM_THM_CALL)
7158 eh->plt_thumb_refcount += 1;
7161 /* If we are creating a shared library or relocatable executable,
7162 and this is a reloc against a global symbol, or a non PC
7163 relative reloc against a local symbol, then we need to copy
7164 the reloc into the shared library. However, if we are linking
7165 with -Bsymbolic, we do not need to copy a reloc against a
7166 global symbol which is defined in an object we are
7167 including in the link (i.e., DEF_REGULAR is set). At
7168 this point we have not seen all the input files, so it is
7169 possible that DEF_REGULAR is not set now but will be set
7170 later (it is never cleared). We account for that
7171 possibility below by storing information in the
7172 relocs_copied field of the hash table entry. */
7173 if ((info->shared || htab->root.is_relocatable_executable)
7174 && (sec->flags & SEC_ALLOC) != 0
7175 && ((r_type == R_ARM_ABS32 || r_type == R_ARM_ABS32_NOI)
7176 || (h != NULL && ! h->needs_plt
7177 && (! info->symbolic || ! h->def_regular))))
7179 struct elf32_arm_relocs_copied *p, **head;
7181 /* When creating a shared object, we must copy these
7182 reloc types into the output file. We create a reloc
7183 section in dynobj and make room for this reloc. */
7184 if (sreloc == NULL)
7186 const char * name;
7188 name = (bfd_elf_string_from_elf_section
7189 (abfd,
7190 elf_elfheader (abfd)->e_shstrndx,
7191 elf_section_data (sec)->rel_hdr.sh_name));
7192 if (name == NULL)
7193 return FALSE;
7195 BFD_ASSERT (reloc_section_p (htab, name, sec));
7197 sreloc = bfd_get_section_by_name (dynobj, name);
7198 if (sreloc == NULL)
7200 flagword flags;
7202 flags = (SEC_HAS_CONTENTS | SEC_READONLY
7203 | SEC_IN_MEMORY | SEC_LINKER_CREATED);
7204 if ((sec->flags & SEC_ALLOC) != 0
7205 /* BPABI objects never have dynamic
7206 relocations mapped. */
7207 && !htab->symbian_p)
7208 flags |= SEC_ALLOC | SEC_LOAD;
7209 sreloc = bfd_make_section_with_flags (dynobj,
7210 name,
7211 flags);
7212 if (sreloc == NULL
7213 || ! bfd_set_section_alignment (dynobj, sreloc, 2))
7214 return FALSE;
7217 elf_section_data (sec)->sreloc = sreloc;
7220 /* If this is a global symbol, we count the number of
7221 relocations we need for this symbol. */
7222 if (h != NULL)
7224 head = &((struct elf32_arm_link_hash_entry *) h)->relocs_copied;
7226 else
7228 /* Track dynamic relocs needed for local syms too.
7229 We really need local syms available to do this
7230 easily. Oh well. */
7232 asection *s;
7233 void *vpp;
7235 s = bfd_section_from_r_symndx (abfd, &htab->sym_sec,
7236 sec, r_symndx);
7237 if (s == NULL)
7238 return FALSE;
7240 vpp = &elf_section_data (s)->local_dynrel;
7241 head = (struct elf32_arm_relocs_copied **) vpp;
7244 p = *head;
7245 if (p == NULL || p->section != sec)
7247 bfd_size_type amt = sizeof *p;
7249 p = bfd_alloc (htab->root.dynobj, amt);
7250 if (p == NULL)
7251 return FALSE;
7252 p->next = *head;
7253 *head = p;
7254 p->section = sec;
7255 p->count = 0;
7256 p->pc_count = 0;
7259 if (r_type == R_ARM_REL32 || r_type == R_ARM_REL32_NOI)
7260 p->pc_count += 1;
7261 p->count += 1;
7263 break;
7265 /* This relocation describes the C++ object vtable hierarchy.
7266 Reconstruct it for later use during GC. */
7267 case R_ARM_GNU_VTINHERIT:
7268 if (!bfd_elf_gc_record_vtinherit (abfd, sec, h, rel->r_offset))
7269 return FALSE;
7270 break;
7272 /* This relocation describes which C++ vtable entries are actually
7273 used. Record for later use during GC. */
7274 case R_ARM_GNU_VTENTRY:
7275 if (!bfd_elf_gc_record_vtentry (abfd, sec, h, rel->r_offset))
7276 return FALSE;
7277 break;
7281 return TRUE;
7284 /* Treat mapping symbols as special target symbols. */
7286 static bfd_boolean
7287 elf32_arm_is_target_special_symbol (bfd * abfd ATTRIBUTE_UNUSED, asymbol * sym)
7289 return bfd_is_arm_special_symbol_name (sym->name,
7290 BFD_ARM_SPECIAL_SYM_TYPE_ANY);
7293 /* This is a copy of elf_find_function() from elf.c except that
7294 ARM mapping symbols are ignored when looking for function names
7295 and STT_ARM_TFUNC is considered to a function type. */
7297 static bfd_boolean
7298 arm_elf_find_function (bfd * abfd ATTRIBUTE_UNUSED,
7299 asection * section,
7300 asymbol ** symbols,
7301 bfd_vma offset,
7302 const char ** filename_ptr,
7303 const char ** functionname_ptr)
7305 const char * filename = NULL;
7306 asymbol * func = NULL;
7307 bfd_vma low_func = 0;
7308 asymbol ** p;
7310 for (p = symbols; *p != NULL; p++)
7312 elf_symbol_type *q;
7314 q = (elf_symbol_type *) *p;
7316 switch (ELF_ST_TYPE (q->internal_elf_sym.st_info))
7318 default:
7319 break;
7320 case STT_FILE:
7321 filename = bfd_asymbol_name (&q->symbol);
7322 break;
7323 case STT_FUNC:
7324 case STT_ARM_TFUNC:
7325 case STT_NOTYPE:
7326 /* Skip mapping symbols. */
7327 if ((q->symbol.flags & BSF_LOCAL)
7328 && bfd_is_arm_special_symbol_name (q->symbol.name,
7329 BFD_ARM_SPECIAL_SYM_TYPE_ANY))
7330 continue;
7331 /* Fall through. */
7332 if (bfd_get_section (&q->symbol) == section
7333 && q->symbol.value >= low_func
7334 && q->symbol.value <= offset)
7336 func = (asymbol *) q;
7337 low_func = q->symbol.value;
7339 break;
7343 if (func == NULL)
7344 return FALSE;
7346 if (filename_ptr)
7347 *filename_ptr = filename;
7348 if (functionname_ptr)
7349 *functionname_ptr = bfd_asymbol_name (func);
7351 return TRUE;
7355 /* Find the nearest line to a particular section and offset, for error
7356 reporting. This code is a duplicate of the code in elf.c, except
7357 that it uses arm_elf_find_function. */
7359 static bfd_boolean
7360 elf32_arm_find_nearest_line (bfd * abfd,
7361 asection * section,
7362 asymbol ** symbols,
7363 bfd_vma offset,
7364 const char ** filename_ptr,
7365 const char ** functionname_ptr,
7366 unsigned int * line_ptr)
7368 bfd_boolean found = FALSE;
7370 /* We skip _bfd_dwarf1_find_nearest_line since no known ARM toolchain uses it. */
7372 if (_bfd_dwarf2_find_nearest_line (abfd, section, symbols, offset,
7373 filename_ptr, functionname_ptr,
7374 line_ptr, 0,
7375 & elf_tdata (abfd)->dwarf2_find_line_info))
7377 if (!*functionname_ptr)
7378 arm_elf_find_function (abfd, section, symbols, offset,
7379 *filename_ptr ? NULL : filename_ptr,
7380 functionname_ptr);
7382 return TRUE;
7385 if (! _bfd_stab_section_find_nearest_line (abfd, symbols, section, offset,
7386 & found, filename_ptr,
7387 functionname_ptr, line_ptr,
7388 & elf_tdata (abfd)->line_info))
7389 return FALSE;
7391 if (found && (*functionname_ptr || *line_ptr))
7392 return TRUE;
7394 if (symbols == NULL)
7395 return FALSE;
7397 if (! arm_elf_find_function (abfd, section, symbols, offset,
7398 filename_ptr, functionname_ptr))
7399 return FALSE;
7401 *line_ptr = 0;
7402 return TRUE;
7405 static bfd_boolean
7406 elf32_arm_find_inliner_info (bfd * abfd,
7407 const char ** filename_ptr,
7408 const char ** functionname_ptr,
7409 unsigned int * line_ptr)
7411 bfd_boolean found;
7412 found = _bfd_dwarf2_find_inliner_info (abfd, filename_ptr,
7413 functionname_ptr, line_ptr,
7414 & elf_tdata (abfd)->dwarf2_find_line_info);
7415 return found;
7418 /* Adjust a symbol defined by a dynamic object and referenced by a
7419 regular object. The current definition is in some section of the
7420 dynamic object, but we're not including those sections. We have to
7421 change the definition to something the rest of the link can
7422 understand. */
7424 static bfd_boolean
7425 elf32_arm_adjust_dynamic_symbol (struct bfd_link_info * info,
7426 struct elf_link_hash_entry * h)
7428 bfd * dynobj;
7429 asection * s;
7430 unsigned int power_of_two;
7431 struct elf32_arm_link_hash_entry * eh;
7432 struct elf32_arm_link_hash_table *globals;
7434 globals = elf32_arm_hash_table (info);
7435 dynobj = elf_hash_table (info)->dynobj;
7437 /* Make sure we know what is going on here. */
7438 BFD_ASSERT (dynobj != NULL
7439 && (h->needs_plt
7440 || h->u.weakdef != NULL
7441 || (h->def_dynamic
7442 && h->ref_regular
7443 && !h->def_regular)));
7445 eh = (struct elf32_arm_link_hash_entry *) h;
7447 /* If this is a function, put it in the procedure linkage table. We
7448 will fill in the contents of the procedure linkage table later,
7449 when we know the address of the .got section. */
7450 if (h->type == STT_FUNC || h->type == STT_ARM_TFUNC
7451 || h->needs_plt)
7453 if (h->plt.refcount <= 0
7454 || SYMBOL_CALLS_LOCAL (info, h)
7455 || (ELF_ST_VISIBILITY (h->other) != STV_DEFAULT
7456 && h->root.type == bfd_link_hash_undefweak))
7458 /* This case can occur if we saw a PLT32 reloc in an input
7459 file, but the symbol was never referred to by a dynamic
7460 object, or if all references were garbage collected. In
7461 such a case, we don't actually need to build a procedure
7462 linkage table, and we can just do a PC24 reloc instead. */
7463 h->plt.offset = (bfd_vma) -1;
7464 eh->plt_thumb_refcount = 0;
7465 h->needs_plt = 0;
7468 return TRUE;
7470 else
7472 /* It's possible that we incorrectly decided a .plt reloc was
7473 needed for an R_ARM_PC24 or similar reloc to a non-function sym
7474 in check_relocs. We can't decide accurately between function
7475 and non-function syms in check-relocs; Objects loaded later in
7476 the link may change h->type. So fix it now. */
7477 h->plt.offset = (bfd_vma) -1;
7478 eh->plt_thumb_refcount = 0;
7481 /* If this is a weak symbol, and there is a real definition, the
7482 processor independent code will have arranged for us to see the
7483 real definition first, and we can just use the same value. */
7484 if (h->u.weakdef != NULL)
7486 BFD_ASSERT (h->u.weakdef->root.type == bfd_link_hash_defined
7487 || h->u.weakdef->root.type == bfd_link_hash_defweak);
7488 h->root.u.def.section = h->u.weakdef->root.u.def.section;
7489 h->root.u.def.value = h->u.weakdef->root.u.def.value;
7490 return TRUE;
7493 /* If there are no non-GOT references, we do not need a copy
7494 relocation. */
7495 if (!h->non_got_ref)
7496 return TRUE;
7498 /* This is a reference to a symbol defined by a dynamic object which
7499 is not a function. */
7501 /* If we are creating a shared library, we must presume that the
7502 only references to the symbol are via the global offset table.
7503 For such cases we need not do anything here; the relocations will
7504 be handled correctly by relocate_section. Relocatable executables
7505 can reference data in shared objects directly, so we don't need to
7506 do anything here. */
7507 if (info->shared || globals->root.is_relocatable_executable)
7508 return TRUE;
7510 if (h->size == 0)
7512 (*_bfd_error_handler) (_("dynamic variable `%s' is zero size"),
7513 h->root.root.string);
7514 return TRUE;
7517 /* We must allocate the symbol in our .dynbss section, which will
7518 become part of the .bss section of the executable. There will be
7519 an entry for this symbol in the .dynsym section. The dynamic
7520 object will contain position independent code, so all references
7521 from the dynamic object to this symbol will go through the global
7522 offset table. The dynamic linker will use the .dynsym entry to
7523 determine the address it must put in the global offset table, so
7524 both the dynamic object and the regular object will refer to the
7525 same memory location for the variable. */
7526 s = bfd_get_section_by_name (dynobj, ".dynbss");
7527 BFD_ASSERT (s != NULL);
7529 /* We must generate a R_ARM_COPY reloc to tell the dynamic linker to
7530 copy the initial value out of the dynamic object and into the
7531 runtime process image. We need to remember the offset into the
7532 .rel(a).bss section we are going to use. */
7533 if ((h->root.u.def.section->flags & SEC_ALLOC) != 0)
7535 asection *srel;
7537 srel = bfd_get_section_by_name (dynobj, RELOC_SECTION (globals, ".bss"));
7538 BFD_ASSERT (srel != NULL);
7539 srel->size += RELOC_SIZE (globals);
7540 h->needs_copy = 1;
7543 /* We need to figure out the alignment required for this symbol. I
7544 have no idea how ELF linkers handle this. */
7545 power_of_two = bfd_log2 (h->size);
7546 if (power_of_two > 3)
7547 power_of_two = 3;
7549 /* Apply the required alignment. */
7550 s->size = BFD_ALIGN (s->size, (bfd_size_type) (1 << power_of_two));
7551 if (power_of_two > bfd_get_section_alignment (dynobj, s))
7553 if (! bfd_set_section_alignment (dynobj, s, power_of_two))
7554 return FALSE;
7557 /* Define the symbol as being at this point in the section. */
7558 h->root.u.def.section = s;
7559 h->root.u.def.value = s->size;
7561 /* Increment the section size to make room for the symbol. */
7562 s->size += h->size;
7564 return TRUE;
7567 /* Allocate space in .plt, .got and associated reloc sections for
7568 dynamic relocs. */
7570 static bfd_boolean
7571 allocate_dynrelocs (struct elf_link_hash_entry *h, void * inf)
7573 struct bfd_link_info *info;
7574 struct elf32_arm_link_hash_table *htab;
7575 struct elf32_arm_link_hash_entry *eh;
7576 struct elf32_arm_relocs_copied *p;
7578 eh = (struct elf32_arm_link_hash_entry *) h;
7580 if (h->root.type == bfd_link_hash_indirect)
7581 return TRUE;
7583 if (h->root.type == bfd_link_hash_warning)
7584 /* When warning symbols are created, they **replace** the "real"
7585 entry in the hash table, thus we never get to see the real
7586 symbol in a hash traversal. So look at it now. */
7587 h = (struct elf_link_hash_entry *) h->root.u.i.link;
7589 info = (struct bfd_link_info *) inf;
7590 htab = elf32_arm_hash_table (info);
7592 if (htab->root.dynamic_sections_created
7593 && h->plt.refcount > 0)
7595 /* Make sure this symbol is output as a dynamic symbol.
7596 Undefined weak syms won't yet be marked as dynamic. */
7597 if (h->dynindx == -1
7598 && !h->forced_local)
7600 if (! bfd_elf_link_record_dynamic_symbol (info, h))
7601 return FALSE;
7604 if (info->shared
7605 || WILL_CALL_FINISH_DYNAMIC_SYMBOL (1, 0, h))
7607 asection *s = htab->splt;
7609 /* If this is the first .plt entry, make room for the special
7610 first entry. */
7611 if (s->size == 0)
7612 s->size += htab->plt_header_size;
7614 h->plt.offset = s->size;
7616 /* If we will insert a Thumb trampoline before this PLT, leave room
7617 for it. */
7618 if (!htab->use_blx && eh->plt_thumb_refcount > 0)
7620 h->plt.offset += PLT_THUMB_STUB_SIZE;
7621 s->size += PLT_THUMB_STUB_SIZE;
7624 /* If this symbol is not defined in a regular file, and we are
7625 not generating a shared library, then set the symbol to this
7626 location in the .plt. This is required to make function
7627 pointers compare as equal between the normal executable and
7628 the shared library. */
7629 if (! info->shared
7630 && !h->def_regular)
7632 h->root.u.def.section = s;
7633 h->root.u.def.value = h->plt.offset;
7635 /* Make sure the function is not marked as Thumb, in case
7636 it is the target of an ABS32 relocation, which will
7637 point to the PLT entry. */
7638 if (ELF_ST_TYPE (h->type) == STT_ARM_TFUNC)
7639 h->type = ELF_ST_INFO (ELF_ST_BIND (h->type), STT_FUNC);
7642 /* Make room for this entry. */
7643 s->size += htab->plt_entry_size;
7645 if (!htab->symbian_p)
7647 /* We also need to make an entry in the .got.plt section, which
7648 will be placed in the .got section by the linker script. */
7649 eh->plt_got_offset = htab->sgotplt->size;
7650 htab->sgotplt->size += 4;
7653 /* We also need to make an entry in the .rel(a).plt section. */
7654 htab->srelplt->size += RELOC_SIZE (htab);
7656 /* VxWorks executables have a second set of relocations for
7657 each PLT entry. They go in a separate relocation section,
7658 which is processed by the kernel loader. */
7659 if (htab->vxworks_p && !info->shared)
7661 /* There is a relocation for the initial PLT entry:
7662 an R_ARM_32 relocation for _GLOBAL_OFFSET_TABLE_. */
7663 if (h->plt.offset == htab->plt_header_size)
7664 htab->srelplt2->size += RELOC_SIZE (htab);
7666 /* There are two extra relocations for each subsequent
7667 PLT entry: an R_ARM_32 relocation for the GOT entry,
7668 and an R_ARM_32 relocation for the PLT entry. */
7669 htab->srelplt2->size += RELOC_SIZE (htab) * 2;
7672 else
7674 h->plt.offset = (bfd_vma) -1;
7675 h->needs_plt = 0;
7678 else
7680 h->plt.offset = (bfd_vma) -1;
7681 h->needs_plt = 0;
7684 if (h->got.refcount > 0)
7686 asection *s;
7687 bfd_boolean dyn;
7688 int tls_type = elf32_arm_hash_entry (h)->tls_type;
7689 int indx;
7691 /* Make sure this symbol is output as a dynamic symbol.
7692 Undefined weak syms won't yet be marked as dynamic. */
7693 if (h->dynindx == -1
7694 && !h->forced_local)
7696 if (! bfd_elf_link_record_dynamic_symbol (info, h))
7697 return FALSE;
7700 if (!htab->symbian_p)
7702 s = htab->sgot;
7703 h->got.offset = s->size;
7705 if (tls_type == GOT_UNKNOWN)
7706 abort ();
7708 if (tls_type == GOT_NORMAL)
7709 /* Non-TLS symbols need one GOT slot. */
7710 s->size += 4;
7711 else
7713 if (tls_type & GOT_TLS_GD)
7714 /* R_ARM_TLS_GD32 needs 2 consecutive GOT slots. */
7715 s->size += 8;
7716 if (tls_type & GOT_TLS_IE)
7717 /* R_ARM_TLS_IE32 needs one GOT slot. */
7718 s->size += 4;
7721 dyn = htab->root.dynamic_sections_created;
7723 indx = 0;
7724 if (WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn, info->shared, h)
7725 && (!info->shared
7726 || !SYMBOL_REFERENCES_LOCAL (info, h)))
7727 indx = h->dynindx;
7729 if (tls_type != GOT_NORMAL
7730 && (info->shared || indx != 0)
7731 && (ELF_ST_VISIBILITY (h->other) == STV_DEFAULT
7732 || h->root.type != bfd_link_hash_undefweak))
7734 if (tls_type & GOT_TLS_IE)
7735 htab->srelgot->size += RELOC_SIZE (htab);
7737 if (tls_type & GOT_TLS_GD)
7738 htab->srelgot->size += RELOC_SIZE (htab);
7740 if ((tls_type & GOT_TLS_GD) && indx != 0)
7741 htab->srelgot->size += RELOC_SIZE (htab);
7743 else if ((ELF_ST_VISIBILITY (h->other) == STV_DEFAULT
7744 || h->root.type != bfd_link_hash_undefweak)
7745 && (info->shared
7746 || WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn, 0, h)))
7747 htab->srelgot->size += RELOC_SIZE (htab);
7750 else
7751 h->got.offset = (bfd_vma) -1;
7753 /* Allocate stubs for exported Thumb functions on v4t. */
7754 if (!htab->use_blx && h->dynindx != -1
7755 && h->def_regular
7756 && ELF_ST_TYPE (h->type) == STT_ARM_TFUNC
7757 && ELF_ST_VISIBILITY (h->other) == STV_DEFAULT)
7759 struct elf_link_hash_entry * th;
7760 struct bfd_link_hash_entry * bh;
7761 struct elf_link_hash_entry * myh;
7762 char name[1024];
7763 asection *s;
7764 bh = NULL;
7765 /* Create a new symbol to regist the real location of the function. */
7766 s = h->root.u.def.section;
7767 sprintf(name, "__real_%s", h->root.root.string);
7768 _bfd_generic_link_add_one_symbol (info, s->owner,
7769 name, BSF_GLOBAL, s,
7770 h->root.u.def.value,
7771 NULL, TRUE, FALSE, &bh);
7773 myh = (struct elf_link_hash_entry *) bh;
7774 myh->type = ELF_ST_INFO (STB_LOCAL, STT_ARM_TFUNC);
7775 myh->forced_local = 1;
7776 eh->export_glue = myh;
7777 th = record_arm_to_thumb_glue (info, h);
7778 /* Point the symbol at the stub. */
7779 h->type = ELF_ST_INFO (ELF_ST_BIND (h->type), STT_FUNC);
7780 h->root.u.def.section = th->root.u.def.section;
7781 h->root.u.def.value = th->root.u.def.value & ~1;
7784 if (eh->relocs_copied == NULL)
7785 return TRUE;
7787 /* In the shared -Bsymbolic case, discard space allocated for
7788 dynamic pc-relative relocs against symbols which turn out to be
7789 defined in regular objects. For the normal shared case, discard
7790 space for pc-relative relocs that have become local due to symbol
7791 visibility changes. */
7793 if (info->shared || htab->root.is_relocatable_executable)
7795 /* The only reloc thats uses pc_count are R_ARM_REL32 and
7796 R_ARM_REL32_NOI, which will appear on something like
7797 ".long foo - .". We want calls to protected symbols to resolve
7798 directly to the function rather than going via the plt. If people
7799 want function pointer comparisons to work as expected then they
7800 should avoid writing assembly like ".long foo - .". */
7801 if (SYMBOL_CALLS_LOCAL (info, h))
7803 struct elf32_arm_relocs_copied **pp;
7805 for (pp = &eh->relocs_copied; (p = *pp) != NULL; )
7807 p->count -= p->pc_count;
7808 p->pc_count = 0;
7809 if (p->count == 0)
7810 *pp = p->next;
7811 else
7812 pp = &p->next;
7816 /* Also discard relocs on undefined weak syms with non-default
7817 visibility. */
7818 if (eh->relocs_copied != NULL
7819 && h->root.type == bfd_link_hash_undefweak)
7821 if (ELF_ST_VISIBILITY (h->other) != STV_DEFAULT)
7822 eh->relocs_copied = NULL;
7824 /* Make sure undefined weak symbols are output as a dynamic
7825 symbol in PIEs. */
7826 else if (h->dynindx == -1
7827 && !h->forced_local)
7829 if (! bfd_elf_link_record_dynamic_symbol (info, h))
7830 return FALSE;
7834 else if (htab->root.is_relocatable_executable && h->dynindx == -1
7835 && h->root.type == bfd_link_hash_new)
7837 /* Output absolute symbols so that we can create relocations
7838 against them. For normal symbols we output a relocation
7839 against the section that contains them. */
7840 if (! bfd_elf_link_record_dynamic_symbol (info, h))
7841 return FALSE;
7845 else
7847 /* For the non-shared case, discard space for relocs against
7848 symbols which turn out to need copy relocs or are not
7849 dynamic. */
7851 if (!h->non_got_ref
7852 && ((h->def_dynamic
7853 && !h->def_regular)
7854 || (htab->root.dynamic_sections_created
7855 && (h->root.type == bfd_link_hash_undefweak
7856 || h->root.type == bfd_link_hash_undefined))))
7858 /* Make sure this symbol is output as a dynamic symbol.
7859 Undefined weak syms won't yet be marked as dynamic. */
7860 if (h->dynindx == -1
7861 && !h->forced_local)
7863 if (! bfd_elf_link_record_dynamic_symbol (info, h))
7864 return FALSE;
7867 /* If that succeeded, we know we'll be keeping all the
7868 relocs. */
7869 if (h->dynindx != -1)
7870 goto keep;
7873 eh->relocs_copied = NULL;
7875 keep: ;
7878 /* Finally, allocate space. */
7879 for (p = eh->relocs_copied; p != NULL; p = p->next)
7881 asection *sreloc = elf_section_data (p->section)->sreloc;
7882 sreloc->size += p->count * RELOC_SIZE (htab);
7885 return TRUE;
7888 /* Find any dynamic relocs that apply to read-only sections. */
7890 static bfd_boolean
7891 elf32_arm_readonly_dynrelocs (struct elf_link_hash_entry *h, PTR inf)
7893 struct elf32_arm_link_hash_entry *eh;
7894 struct elf32_arm_relocs_copied *p;
7896 if (h->root.type == bfd_link_hash_warning)
7897 h = (struct elf_link_hash_entry *) h->root.u.i.link;
7899 eh = (struct elf32_arm_link_hash_entry *) h;
7900 for (p = eh->relocs_copied; p != NULL; p = p->next)
7902 asection *s = p->section;
7904 if (s != NULL && (s->flags & SEC_READONLY) != 0)
7906 struct bfd_link_info *info = (struct bfd_link_info *) inf;
7908 info->flags |= DF_TEXTREL;
7910 /* Not an error, just cut short the traversal. */
7911 return FALSE;
7914 return TRUE;
7917 void
7918 bfd_elf32_arm_set_byteswap_code (struct bfd_link_info *info,
7919 int byteswap_code)
7921 struct elf32_arm_link_hash_table *globals;
7923 globals = elf32_arm_hash_table (info);
7924 globals->byteswap_code = byteswap_code;
7927 /* Set the sizes of the dynamic sections. */
7929 static bfd_boolean
7930 elf32_arm_size_dynamic_sections (bfd * output_bfd ATTRIBUTE_UNUSED,
7931 struct bfd_link_info * info)
7933 bfd * dynobj;
7934 asection * s;
7935 bfd_boolean plt;
7936 bfd_boolean relocs;
7937 bfd *ibfd;
7938 struct elf32_arm_link_hash_table *htab;
7940 htab = elf32_arm_hash_table (info);
7941 dynobj = elf_hash_table (info)->dynobj;
7942 BFD_ASSERT (dynobj != NULL);
7943 check_use_blx (htab);
7945 if (elf_hash_table (info)->dynamic_sections_created)
7947 /* Set the contents of the .interp section to the interpreter. */
7948 if (info->executable)
7950 s = bfd_get_section_by_name (dynobj, ".interp");
7951 BFD_ASSERT (s != NULL);
7952 s->size = sizeof ELF_DYNAMIC_INTERPRETER;
7953 s->contents = (unsigned char *) ELF_DYNAMIC_INTERPRETER;
7957 /* Set up .got offsets for local syms, and space for local dynamic
7958 relocs. */
7959 for (ibfd = info->input_bfds; ibfd != NULL; ibfd = ibfd->link_next)
7961 bfd_signed_vma *local_got;
7962 bfd_signed_vma *end_local_got;
7963 char *local_tls_type;
7964 bfd_size_type locsymcount;
7965 Elf_Internal_Shdr *symtab_hdr;
7966 asection *srel;
7968 if (bfd_get_flavour (ibfd) != bfd_target_elf_flavour)
7969 continue;
7971 for (s = ibfd->sections; s != NULL; s = s->next)
7973 struct elf32_arm_relocs_copied *p;
7975 for (p = elf_section_data (s)->local_dynrel; p != NULL; p = p->next)
7977 if (!bfd_is_abs_section (p->section)
7978 && bfd_is_abs_section (p->section->output_section))
7980 /* Input section has been discarded, either because
7981 it is a copy of a linkonce section or due to
7982 linker script /DISCARD/, so we'll be discarding
7983 the relocs too. */
7985 else if (p->count != 0)
7987 srel = elf_section_data (p->section)->sreloc;
7988 srel->size += p->count * RELOC_SIZE (htab);
7989 if ((p->section->output_section->flags & SEC_READONLY) != 0)
7990 info->flags |= DF_TEXTREL;
7995 local_got = elf_local_got_refcounts (ibfd);
7996 if (!local_got)
7997 continue;
7999 symtab_hdr = &elf_tdata (ibfd)->symtab_hdr;
8000 locsymcount = symtab_hdr->sh_info;
8001 end_local_got = local_got + locsymcount;
8002 local_tls_type = elf32_arm_local_got_tls_type (ibfd);
8003 s = htab->sgot;
8004 srel = htab->srelgot;
8005 for (; local_got < end_local_got; ++local_got, ++local_tls_type)
8007 if (*local_got > 0)
8009 *local_got = s->size;
8010 if (*local_tls_type & GOT_TLS_GD)
8011 /* TLS_GD relocs need an 8-byte structure in the GOT. */
8012 s->size += 8;
8013 if (*local_tls_type & GOT_TLS_IE)
8014 s->size += 4;
8015 if (*local_tls_type == GOT_NORMAL)
8016 s->size += 4;
8018 if (info->shared || *local_tls_type == GOT_TLS_GD)
8019 srel->size += RELOC_SIZE (htab);
8021 else
8022 *local_got = (bfd_vma) -1;
8026 if (htab->tls_ldm_got.refcount > 0)
8028 /* Allocate two GOT entries and one dynamic relocation (if necessary)
8029 for R_ARM_TLS_LDM32 relocations. */
8030 htab->tls_ldm_got.offset = htab->sgot->size;
8031 htab->sgot->size += 8;
8032 if (info->shared)
8033 htab->srelgot->size += RELOC_SIZE (htab);
8035 else
8036 htab->tls_ldm_got.offset = -1;
8038 /* Allocate global sym .plt and .got entries, and space for global
8039 sym dynamic relocs. */
8040 elf_link_hash_traverse (& htab->root, allocate_dynrelocs, info);
8042 /* Here we rummage through the found bfds to collect glue information. */
8043 for (ibfd = info->input_bfds; ibfd != NULL; ibfd = ibfd->link_next)
8044 if (!bfd_elf32_arm_process_before_allocation (ibfd, info))
8045 /* xgettext:c-format */
8046 _bfd_error_handler (_("Errors encountered processing file %s"),
8047 ibfd->filename);
8049 /* The check_relocs and adjust_dynamic_symbol entry points have
8050 determined the sizes of the various dynamic sections. Allocate
8051 memory for them. */
8052 plt = FALSE;
8053 relocs = FALSE;
8054 for (s = dynobj->sections; s != NULL; s = s->next)
8056 const char * name;
8058 if ((s->flags & SEC_LINKER_CREATED) == 0)
8059 continue;
8061 /* It's OK to base decisions on the section name, because none
8062 of the dynobj section names depend upon the input files. */
8063 name = bfd_get_section_name (dynobj, s);
8065 if (strcmp (name, ".plt") == 0)
8067 /* Remember whether there is a PLT. */
8068 plt = s->size != 0;
8070 else if (CONST_STRNEQ (name, ".rel"))
8072 if (s->size != 0)
8074 /* Remember whether there are any reloc sections other
8075 than .rel(a).plt and .rela.plt.unloaded. */
8076 if (s != htab->srelplt && s != htab->srelplt2)
8077 relocs = TRUE;
8079 /* We use the reloc_count field as a counter if we need
8080 to copy relocs into the output file. */
8081 s->reloc_count = 0;
8084 else if (! CONST_STRNEQ (name, ".got")
8085 && strcmp (name, ".dynbss") != 0)
8087 /* It's not one of our sections, so don't allocate space. */
8088 continue;
8091 if (s->size == 0)
8093 /* If we don't need this section, strip it from the
8094 output file. This is mostly to handle .rel(a).bss and
8095 .rel(a).plt. We must create both sections in
8096 create_dynamic_sections, because they must be created
8097 before the linker maps input sections to output
8098 sections. The linker does that before
8099 adjust_dynamic_symbol is called, and it is that
8100 function which decides whether anything needs to go
8101 into these sections. */
8102 s->flags |= SEC_EXCLUDE;
8103 continue;
8106 if ((s->flags & SEC_HAS_CONTENTS) == 0)
8107 continue;
8109 /* Allocate memory for the section contents. */
8110 s->contents = (bfd_byte *) bfd_zalloc (dynobj, s->size);
8111 if (s->contents == NULL)
8112 return FALSE;
8115 if (elf_hash_table (info)->dynamic_sections_created)
8117 /* Add some entries to the .dynamic section. We fill in the
8118 values later, in elf32_arm_finish_dynamic_sections, but we
8119 must add the entries now so that we get the correct size for
8120 the .dynamic section. The DT_DEBUG entry is filled in by the
8121 dynamic linker and used by the debugger. */
8122 #define add_dynamic_entry(TAG, VAL) \
8123 _bfd_elf_add_dynamic_entry (info, TAG, VAL)
8125 if (info->executable)
8127 if (!add_dynamic_entry (DT_DEBUG, 0))
8128 return FALSE;
8131 if (plt)
8133 if ( !add_dynamic_entry (DT_PLTGOT, 0)
8134 || !add_dynamic_entry (DT_PLTRELSZ, 0)
8135 || !add_dynamic_entry (DT_PLTREL,
8136 htab->use_rel ? DT_REL : DT_RELA)
8137 || !add_dynamic_entry (DT_JMPREL, 0))
8138 return FALSE;
8141 if (relocs)
8143 if (htab->use_rel)
8145 if (!add_dynamic_entry (DT_REL, 0)
8146 || !add_dynamic_entry (DT_RELSZ, 0)
8147 || !add_dynamic_entry (DT_RELENT, RELOC_SIZE (htab)))
8148 return FALSE;
8150 else
8152 if (!add_dynamic_entry (DT_RELA, 0)
8153 || !add_dynamic_entry (DT_RELASZ, 0)
8154 || !add_dynamic_entry (DT_RELAENT, RELOC_SIZE (htab)))
8155 return FALSE;
8159 /* If any dynamic relocs apply to a read-only section,
8160 then we need a DT_TEXTREL entry. */
8161 if ((info->flags & DF_TEXTREL) == 0)
8162 elf_link_hash_traverse (&htab->root, elf32_arm_readonly_dynrelocs,
8163 (PTR) info);
8165 if ((info->flags & DF_TEXTREL) != 0)
8167 if (!add_dynamic_entry (DT_TEXTREL, 0))
8168 return FALSE;
8171 #undef add_dynamic_entry
8173 return TRUE;
8176 /* Finish up dynamic symbol handling. We set the contents of various
8177 dynamic sections here. */
8179 static bfd_boolean
8180 elf32_arm_finish_dynamic_symbol (bfd * output_bfd, struct bfd_link_info * info,
8181 struct elf_link_hash_entry * h, Elf_Internal_Sym * sym)
8183 bfd * dynobj;
8184 struct elf32_arm_link_hash_table *htab;
8185 struct elf32_arm_link_hash_entry *eh;
8187 dynobj = elf_hash_table (info)->dynobj;
8188 htab = elf32_arm_hash_table (info);
8189 eh = (struct elf32_arm_link_hash_entry *) h;
8191 if (h->plt.offset != (bfd_vma) -1)
8193 asection * splt;
8194 asection * srel;
8195 bfd_byte *loc;
8196 bfd_vma plt_index;
8197 Elf_Internal_Rela rel;
8199 /* This symbol has an entry in the procedure linkage table. Set
8200 it up. */
8202 BFD_ASSERT (h->dynindx != -1);
8204 splt = bfd_get_section_by_name (dynobj, ".plt");
8205 srel = bfd_get_section_by_name (dynobj, RELOC_SECTION (htab, ".plt"));
8206 BFD_ASSERT (splt != NULL && srel != NULL);
8208 /* Fill in the entry in the procedure linkage table. */
8209 if (htab->symbian_p)
8211 put_arm_insn (htab, output_bfd,
8212 elf32_arm_symbian_plt_entry[0],
8213 splt->contents + h->plt.offset);
8214 bfd_put_32 (output_bfd,
8215 elf32_arm_symbian_plt_entry[1],
8216 splt->contents + h->plt.offset + 4);
8218 /* Fill in the entry in the .rel.plt section. */
8219 rel.r_offset = (splt->output_section->vma
8220 + splt->output_offset
8221 + h->plt.offset + 4);
8222 rel.r_info = ELF32_R_INFO (h->dynindx, R_ARM_GLOB_DAT);
8224 /* Get the index in the procedure linkage table which
8225 corresponds to this symbol. This is the index of this symbol
8226 in all the symbols for which we are making plt entries. The
8227 first entry in the procedure linkage table is reserved. */
8228 plt_index = ((h->plt.offset - htab->plt_header_size)
8229 / htab->plt_entry_size);
8231 else
8233 bfd_vma got_offset, got_address, plt_address;
8234 bfd_vma got_displacement;
8235 asection * sgot;
8236 bfd_byte * ptr;
8238 sgot = bfd_get_section_by_name (dynobj, ".got.plt");
8239 BFD_ASSERT (sgot != NULL);
8241 /* Get the offset into the .got.plt table of the entry that
8242 corresponds to this function. */
8243 got_offset = eh->plt_got_offset;
8245 /* Get the index in the procedure linkage table which
8246 corresponds to this symbol. This is the index of this symbol
8247 in all the symbols for which we are making plt entries. The
8248 first three entries in .got.plt are reserved; after that
8249 symbols appear in the same order as in .plt. */
8250 plt_index = (got_offset - 12) / 4;
8252 /* Calculate the address of the GOT entry. */
8253 got_address = (sgot->output_section->vma
8254 + sgot->output_offset
8255 + got_offset);
8257 /* ...and the address of the PLT entry. */
8258 plt_address = (splt->output_section->vma
8259 + splt->output_offset
8260 + h->plt.offset);
8262 ptr = htab->splt->contents + h->plt.offset;
8263 if (htab->vxworks_p && info->shared)
8265 unsigned int i;
8266 bfd_vma val;
8268 for (i = 0; i != htab->plt_entry_size / 4; i++, ptr += 4)
8270 val = elf32_arm_vxworks_shared_plt_entry[i];
8271 if (i == 2)
8272 val |= got_address - sgot->output_section->vma;
8273 if (i == 5)
8274 val |= plt_index * RELOC_SIZE (htab);
8275 if (i == 2 || i == 5)
8276 bfd_put_32 (output_bfd, val, ptr);
8277 else
8278 put_arm_insn (htab, output_bfd, val, ptr);
8281 else if (htab->vxworks_p)
8283 unsigned int i;
8284 bfd_vma val;
8286 for (i = 0; i != htab->plt_entry_size / 4; i++)
8288 val = elf32_arm_vxworks_exec_plt_entry[i];
8289 if (i == 2)
8290 val |= got_address;
8291 if (i == 4)
8292 val |= 0xffffff & -((h->plt.offset + i * 4 + 8) >> 2);
8293 if (i == 5)
8294 val |= plt_index * RELOC_SIZE (htab);
8295 if (i == 2 || i == 5)
8296 bfd_put_32 (output_bfd, val, ptr);
8297 else
8298 put_arm_insn (htab, output_bfd, val, ptr);
8301 loc = (htab->srelplt2->contents
8302 + (plt_index * 2 + 1) * RELOC_SIZE (htab));
8304 /* Create the .rela.plt.unloaded R_ARM_ABS32 relocation
8305 referencing the GOT for this PLT entry. */
8306 rel.r_offset = plt_address + 8;
8307 rel.r_info = ELF32_R_INFO (htab->root.hgot->indx, R_ARM_ABS32);
8308 rel.r_addend = got_offset;
8309 SWAP_RELOC_OUT (htab) (output_bfd, &rel, loc);
8310 loc += RELOC_SIZE (htab);
8312 /* Create the R_ARM_ABS32 relocation referencing the
8313 beginning of the PLT for this GOT entry. */
8314 rel.r_offset = got_address;
8315 rel.r_info = ELF32_R_INFO (htab->root.hplt->indx, R_ARM_ABS32);
8316 rel.r_addend = 0;
8317 SWAP_RELOC_OUT (htab) (output_bfd, &rel, loc);
8319 else
8321 /* Calculate the displacement between the PLT slot and the
8322 entry in the GOT. The eight-byte offset accounts for the
8323 value produced by adding to pc in the first instruction
8324 of the PLT stub. */
8325 got_displacement = got_address - (plt_address + 8);
8327 BFD_ASSERT ((got_displacement & 0xf0000000) == 0);
8329 if (!htab->use_blx && eh->plt_thumb_refcount > 0)
8331 put_thumb_insn (htab, output_bfd,
8332 elf32_arm_plt_thumb_stub[0], ptr - 4);
8333 put_thumb_insn (htab, output_bfd,
8334 elf32_arm_plt_thumb_stub[1], ptr - 2);
8337 put_arm_insn (htab, output_bfd,
8338 elf32_arm_plt_entry[0]
8339 | ((got_displacement & 0x0ff00000) >> 20),
8340 ptr + 0);
8341 put_arm_insn (htab, output_bfd,
8342 elf32_arm_plt_entry[1]
8343 | ((got_displacement & 0x000ff000) >> 12),
8344 ptr+ 4);
8345 put_arm_insn (htab, output_bfd,
8346 elf32_arm_plt_entry[2]
8347 | (got_displacement & 0x00000fff),
8348 ptr + 8);
8349 #ifdef FOUR_WORD_PLT
8350 bfd_put_32 (output_bfd, elf32_arm_plt_entry[3], ptr + 12);
8351 #endif
8354 /* Fill in the entry in the global offset table. */
8355 bfd_put_32 (output_bfd,
8356 (splt->output_section->vma
8357 + splt->output_offset),
8358 sgot->contents + got_offset);
8360 /* Fill in the entry in the .rel(a).plt section. */
8361 rel.r_addend = 0;
8362 rel.r_offset = got_address;
8363 rel.r_info = ELF32_R_INFO (h->dynindx, R_ARM_JUMP_SLOT);
8366 loc = srel->contents + plt_index * RELOC_SIZE (htab);
8367 SWAP_RELOC_OUT (htab) (output_bfd, &rel, loc);
8369 if (!h->def_regular)
8371 /* Mark the symbol as undefined, rather than as defined in
8372 the .plt section. Leave the value alone. */
8373 sym->st_shndx = SHN_UNDEF;
8374 /* If the symbol is weak, we do need to clear the value.
8375 Otherwise, the PLT entry would provide a definition for
8376 the symbol even if the symbol wasn't defined anywhere,
8377 and so the symbol would never be NULL. */
8378 if (!h->ref_regular_nonweak)
8379 sym->st_value = 0;
8383 if (h->got.offset != (bfd_vma) -1
8384 && (elf32_arm_hash_entry (h)->tls_type & GOT_TLS_GD) == 0
8385 && (elf32_arm_hash_entry (h)->tls_type & GOT_TLS_IE) == 0)
8387 asection * sgot;
8388 asection * srel;
8389 Elf_Internal_Rela rel;
8390 bfd_byte *loc;
8391 bfd_vma offset;
8393 /* This symbol has an entry in the global offset table. Set it
8394 up. */
8395 sgot = bfd_get_section_by_name (dynobj, ".got");
8396 srel = bfd_get_section_by_name (dynobj, RELOC_SECTION (htab, ".got"));
8397 BFD_ASSERT (sgot != NULL && srel != NULL);
8399 offset = (h->got.offset & ~(bfd_vma) 1);
8400 rel.r_addend = 0;
8401 rel.r_offset = (sgot->output_section->vma
8402 + sgot->output_offset
8403 + offset);
8405 /* If this is a static link, or it is a -Bsymbolic link and the
8406 symbol is defined locally or was forced to be local because
8407 of a version file, we just want to emit a RELATIVE reloc.
8408 The entry in the global offset table will already have been
8409 initialized in the relocate_section function. */
8410 if (info->shared
8411 && SYMBOL_REFERENCES_LOCAL (info, h))
8413 BFD_ASSERT((h->got.offset & 1) != 0);
8414 rel.r_info = ELF32_R_INFO (0, R_ARM_RELATIVE);
8415 if (!htab->use_rel)
8417 rel.r_addend = bfd_get_32 (output_bfd, sgot->contents + offset);
8418 bfd_put_32 (output_bfd, (bfd_vma) 0, sgot->contents + offset);
8421 else
8423 BFD_ASSERT((h->got.offset & 1) == 0);
8424 bfd_put_32 (output_bfd, (bfd_vma) 0, sgot->contents + offset);
8425 rel.r_info = ELF32_R_INFO (h->dynindx, R_ARM_GLOB_DAT);
8428 loc = srel->contents + srel->reloc_count++ * RELOC_SIZE (htab);
8429 SWAP_RELOC_OUT (htab) (output_bfd, &rel, loc);
8432 if (h->needs_copy)
8434 asection * s;
8435 Elf_Internal_Rela rel;
8436 bfd_byte *loc;
8438 /* This symbol needs a copy reloc. Set it up. */
8439 BFD_ASSERT (h->dynindx != -1
8440 && (h->root.type == bfd_link_hash_defined
8441 || h->root.type == bfd_link_hash_defweak));
8443 s = bfd_get_section_by_name (h->root.u.def.section->owner,
8444 RELOC_SECTION (htab, ".bss"));
8445 BFD_ASSERT (s != NULL);
8447 rel.r_addend = 0;
8448 rel.r_offset = (h->root.u.def.value
8449 + h->root.u.def.section->output_section->vma
8450 + h->root.u.def.section->output_offset);
8451 rel.r_info = ELF32_R_INFO (h->dynindx, R_ARM_COPY);
8452 loc = s->contents + s->reloc_count++ * RELOC_SIZE (htab);
8453 SWAP_RELOC_OUT (htab) (output_bfd, &rel, loc);
8456 /* Mark _DYNAMIC and _GLOBAL_OFFSET_TABLE_ as absolute. On VxWorks,
8457 the _GLOBAL_OFFSET_TABLE_ symbol is not absolute: it is relative
8458 to the ".got" section. */
8459 if (strcmp (h->root.root.string, "_DYNAMIC") == 0
8460 || (!htab->vxworks_p && h == htab->root.hgot))
8461 sym->st_shndx = SHN_ABS;
8463 return TRUE;
8466 /* Finish up the dynamic sections. */
8468 static bfd_boolean
8469 elf32_arm_finish_dynamic_sections (bfd * output_bfd, struct bfd_link_info * info)
8471 bfd * dynobj;
8472 asection * sgot;
8473 asection * sdyn;
8475 dynobj = elf_hash_table (info)->dynobj;
8477 sgot = bfd_get_section_by_name (dynobj, ".got.plt");
8478 BFD_ASSERT (elf32_arm_hash_table (info)->symbian_p || sgot != NULL);
8479 sdyn = bfd_get_section_by_name (dynobj, ".dynamic");
8481 if (elf_hash_table (info)->dynamic_sections_created)
8483 asection *splt;
8484 Elf32_External_Dyn *dyncon, *dynconend;
8485 struct elf32_arm_link_hash_table *htab;
8487 htab = elf32_arm_hash_table (info);
8488 splt = bfd_get_section_by_name (dynobj, ".plt");
8489 BFD_ASSERT (splt != NULL && sdyn != NULL);
8491 dyncon = (Elf32_External_Dyn *) sdyn->contents;
8492 dynconend = (Elf32_External_Dyn *) (sdyn->contents + sdyn->size);
8494 for (; dyncon < dynconend; dyncon++)
8496 Elf_Internal_Dyn dyn;
8497 const char * name;
8498 asection * s;
8500 bfd_elf32_swap_dyn_in (dynobj, dyncon, &dyn);
8502 switch (dyn.d_tag)
8504 unsigned int type;
8506 default:
8507 break;
8509 case DT_HASH:
8510 name = ".hash";
8511 goto get_vma_if_bpabi;
8512 case DT_STRTAB:
8513 name = ".dynstr";
8514 goto get_vma_if_bpabi;
8515 case DT_SYMTAB:
8516 name = ".dynsym";
8517 goto get_vma_if_bpabi;
8518 case DT_VERSYM:
8519 name = ".gnu.version";
8520 goto get_vma_if_bpabi;
8521 case DT_VERDEF:
8522 name = ".gnu.version_d";
8523 goto get_vma_if_bpabi;
8524 case DT_VERNEED:
8525 name = ".gnu.version_r";
8526 goto get_vma_if_bpabi;
8528 case DT_PLTGOT:
8529 name = ".got";
8530 goto get_vma;
8531 case DT_JMPREL:
8532 name = RELOC_SECTION (htab, ".plt");
8533 get_vma:
8534 s = bfd_get_section_by_name (output_bfd, name);
8535 BFD_ASSERT (s != NULL);
8536 if (!htab->symbian_p)
8537 dyn.d_un.d_ptr = s->vma;
8538 else
8539 /* In the BPABI, tags in the PT_DYNAMIC section point
8540 at the file offset, not the memory address, for the
8541 convenience of the post linker. */
8542 dyn.d_un.d_ptr = s->filepos;
8543 bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon);
8544 break;
8546 get_vma_if_bpabi:
8547 if (htab->symbian_p)
8548 goto get_vma;
8549 break;
8551 case DT_PLTRELSZ:
8552 s = bfd_get_section_by_name (output_bfd,
8553 RELOC_SECTION (htab, ".plt"));
8554 BFD_ASSERT (s != NULL);
8555 dyn.d_un.d_val = s->size;
8556 bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon);
8557 break;
8559 case DT_RELSZ:
8560 case DT_RELASZ:
8561 if (!htab->symbian_p)
8563 /* My reading of the SVR4 ABI indicates that the
8564 procedure linkage table relocs (DT_JMPREL) should be
8565 included in the overall relocs (DT_REL). This is
8566 what Solaris does. However, UnixWare can not handle
8567 that case. Therefore, we override the DT_RELSZ entry
8568 here to make it not include the JMPREL relocs. Since
8569 the linker script arranges for .rel(a).plt to follow all
8570 other relocation sections, we don't have to worry
8571 about changing the DT_REL entry. */
8572 s = bfd_get_section_by_name (output_bfd,
8573 RELOC_SECTION (htab, ".plt"));
8574 if (s != NULL)
8575 dyn.d_un.d_val -= s->size;
8576 bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon);
8577 break;
8579 /* Fall through */
8581 case DT_REL:
8582 case DT_RELA:
8583 /* In the BPABI, the DT_REL tag must point at the file
8584 offset, not the VMA, of the first relocation
8585 section. So, we use code similar to that in
8586 elflink.c, but do not check for SHF_ALLOC on the
8587 relcoation section, since relocations sections are
8588 never allocated under the BPABI. The comments above
8589 about Unixware notwithstanding, we include all of the
8590 relocations here. */
8591 if (htab->symbian_p)
8593 unsigned int i;
8594 type = ((dyn.d_tag == DT_REL || dyn.d_tag == DT_RELSZ)
8595 ? SHT_REL : SHT_RELA);
8596 dyn.d_un.d_val = 0;
8597 for (i = 1; i < elf_numsections (output_bfd); i++)
8599 Elf_Internal_Shdr *hdr
8600 = elf_elfsections (output_bfd)[i];
8601 if (hdr->sh_type == type)
8603 if (dyn.d_tag == DT_RELSZ
8604 || dyn.d_tag == DT_RELASZ)
8605 dyn.d_un.d_val += hdr->sh_size;
8606 else if ((ufile_ptr) hdr->sh_offset
8607 <= dyn.d_un.d_val - 1)
8608 dyn.d_un.d_val = hdr->sh_offset;
8611 bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon);
8613 break;
8615 /* Set the bottom bit of DT_INIT/FINI if the
8616 corresponding function is Thumb. */
8617 case DT_INIT:
8618 name = info->init_function;
8619 goto get_sym;
8620 case DT_FINI:
8621 name = info->fini_function;
8622 get_sym:
8623 /* If it wasn't set by elf_bfd_final_link
8624 then there is nothing to adjust. */
8625 if (dyn.d_un.d_val != 0)
8627 struct elf_link_hash_entry * eh;
8629 eh = elf_link_hash_lookup (elf_hash_table (info), name,
8630 FALSE, FALSE, TRUE);
8631 if (eh != (struct elf_link_hash_entry *) NULL
8632 && ELF_ST_TYPE (eh->type) == STT_ARM_TFUNC)
8634 dyn.d_un.d_val |= 1;
8635 bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon);
8638 break;
8642 /* Fill in the first entry in the procedure linkage table. */
8643 if (splt->size > 0 && elf32_arm_hash_table (info)->plt_header_size)
8645 const bfd_vma *plt0_entry;
8646 bfd_vma got_address, plt_address, got_displacement;
8648 /* Calculate the addresses of the GOT and PLT. */
8649 got_address = sgot->output_section->vma + sgot->output_offset;
8650 plt_address = splt->output_section->vma + splt->output_offset;
8652 if (htab->vxworks_p)
8654 /* The VxWorks GOT is relocated by the dynamic linker.
8655 Therefore, we must emit relocations rather than simply
8656 computing the values now. */
8657 Elf_Internal_Rela rel;
8659 plt0_entry = elf32_arm_vxworks_exec_plt0_entry;
8660 put_arm_insn (htab, output_bfd, plt0_entry[0],
8661 splt->contents + 0);
8662 put_arm_insn (htab, output_bfd, plt0_entry[1],
8663 splt->contents + 4);
8664 put_arm_insn (htab, output_bfd, plt0_entry[2],
8665 splt->contents + 8);
8666 bfd_put_32 (output_bfd, got_address, splt->contents + 12);
8668 /* Generate a relocation for _GLOBAL_OFFSET_TABLE_. */
8669 rel.r_offset = plt_address + 12;
8670 rel.r_info = ELF32_R_INFO (htab->root.hgot->indx, R_ARM_ABS32);
8671 rel.r_addend = 0;
8672 SWAP_RELOC_OUT (htab) (output_bfd, &rel,
8673 htab->srelplt2->contents);
8675 else
8677 got_displacement = got_address - (plt_address + 16);
8679 plt0_entry = elf32_arm_plt0_entry;
8680 put_arm_insn (htab, output_bfd, plt0_entry[0],
8681 splt->contents + 0);
8682 put_arm_insn (htab, output_bfd, plt0_entry[1],
8683 splt->contents + 4);
8684 put_arm_insn (htab, output_bfd, plt0_entry[2],
8685 splt->contents + 8);
8686 put_arm_insn (htab, output_bfd, plt0_entry[3],
8687 splt->contents + 12);
8689 #ifdef FOUR_WORD_PLT
8690 /* The displacement value goes in the otherwise-unused
8691 last word of the second entry. */
8692 bfd_put_32 (output_bfd, got_displacement, splt->contents + 28);
8693 #else
8694 bfd_put_32 (output_bfd, got_displacement, splt->contents + 16);
8695 #endif
8699 /* UnixWare sets the entsize of .plt to 4, although that doesn't
8700 really seem like the right value. */
8701 if (splt->output_section->owner == output_bfd)
8702 elf_section_data (splt->output_section)->this_hdr.sh_entsize = 4;
8704 if (htab->vxworks_p && !info->shared && htab->splt->size > 0)
8706 /* Correct the .rel(a).plt.unloaded relocations. They will have
8707 incorrect symbol indexes. */
8708 int num_plts;
8709 unsigned char *p;
8711 num_plts = ((htab->splt->size - htab->plt_header_size)
8712 / htab->plt_entry_size);
8713 p = htab->srelplt2->contents + RELOC_SIZE (htab);
8715 for (; num_plts; num_plts--)
8717 Elf_Internal_Rela rel;
8719 SWAP_RELOC_IN (htab) (output_bfd, p, &rel);
8720 rel.r_info = ELF32_R_INFO (htab->root.hgot->indx, R_ARM_ABS32);
8721 SWAP_RELOC_OUT (htab) (output_bfd, &rel, p);
8722 p += RELOC_SIZE (htab);
8724 SWAP_RELOC_IN (htab) (output_bfd, p, &rel);
8725 rel.r_info = ELF32_R_INFO (htab->root.hplt->indx, R_ARM_ABS32);
8726 SWAP_RELOC_OUT (htab) (output_bfd, &rel, p);
8727 p += RELOC_SIZE (htab);
8732 /* Fill in the first three entries in the global offset table. */
8733 if (sgot)
8735 if (sgot->size > 0)
8737 if (sdyn == NULL)
8738 bfd_put_32 (output_bfd, (bfd_vma) 0, sgot->contents);
8739 else
8740 bfd_put_32 (output_bfd,
8741 sdyn->output_section->vma + sdyn->output_offset,
8742 sgot->contents);
8743 bfd_put_32 (output_bfd, (bfd_vma) 0, sgot->contents + 4);
8744 bfd_put_32 (output_bfd, (bfd_vma) 0, sgot->contents + 8);
8747 elf_section_data (sgot->output_section)->this_hdr.sh_entsize = 4;
8750 return TRUE;
8753 static void
8754 elf32_arm_post_process_headers (bfd * abfd, struct bfd_link_info * link_info ATTRIBUTE_UNUSED)
8756 Elf_Internal_Ehdr * i_ehdrp; /* ELF file header, internal form. */
8757 struct elf32_arm_link_hash_table *globals;
8759 i_ehdrp = elf_elfheader (abfd);
8761 if (EF_ARM_EABI_VERSION (i_ehdrp->e_flags) == EF_ARM_EABI_UNKNOWN)
8762 i_ehdrp->e_ident[EI_OSABI] = ELFOSABI_ARM;
8763 else
8764 i_ehdrp->e_ident[EI_OSABI] = 0;
8765 i_ehdrp->e_ident[EI_ABIVERSION] = ARM_ELF_ABI_VERSION;
8767 if (link_info)
8769 globals = elf32_arm_hash_table (link_info);
8770 if (globals->byteswap_code)
8771 i_ehdrp->e_flags |= EF_ARM_BE8;
8775 static enum elf_reloc_type_class
8776 elf32_arm_reloc_type_class (const Elf_Internal_Rela *rela)
8778 switch ((int) ELF32_R_TYPE (rela->r_info))
8780 case R_ARM_RELATIVE:
8781 return reloc_class_relative;
8782 case R_ARM_JUMP_SLOT:
8783 return reloc_class_plt;
8784 case R_ARM_COPY:
8785 return reloc_class_copy;
8786 default:
8787 return reloc_class_normal;
8791 /* Set the right machine number for an Arm ELF file. */
8793 static bfd_boolean
8794 elf32_arm_section_flags (flagword *flags, const Elf_Internal_Shdr *hdr)
8796 if (hdr->sh_type == SHT_NOTE)
8797 *flags |= SEC_LINK_ONCE | SEC_LINK_DUPLICATES_SAME_CONTENTS;
8799 return TRUE;
8802 static void
8803 elf32_arm_final_write_processing (bfd *abfd, bfd_boolean linker ATTRIBUTE_UNUSED)
8805 bfd_arm_update_notes (abfd, ARM_NOTE_SECTION);
8808 /* Return TRUE if this is an unwinding table entry. */
8810 static bfd_boolean
8811 is_arm_elf_unwind_section_name (bfd * abfd ATTRIBUTE_UNUSED, const char * name)
8813 return (CONST_STRNEQ (name, ELF_STRING_ARM_unwind)
8814 || CONST_STRNEQ (name, ELF_STRING_ARM_unwind_once));
8818 /* Set the type and flags for an ARM section. We do this by
8819 the section name, which is a hack, but ought to work. */
8821 static bfd_boolean
8822 elf32_arm_fake_sections (bfd * abfd, Elf_Internal_Shdr * hdr, asection * sec)
8824 const char * name;
8826 name = bfd_get_section_name (abfd, sec);
8828 if (is_arm_elf_unwind_section_name (abfd, name))
8830 hdr->sh_type = SHT_ARM_EXIDX;
8831 hdr->sh_flags |= SHF_LINK_ORDER;
8833 else if (strcmp(name, ".ARM.attributes") == 0)
8835 hdr->sh_type = SHT_ARM_ATTRIBUTES;
8837 return TRUE;
8840 /* Parse an Arm EABI attributes section. */
8841 static void
8842 elf32_arm_parse_attributes (bfd *abfd, Elf_Internal_Shdr * hdr)
8844 bfd_byte *contents;
8845 bfd_byte *p;
8846 bfd_vma len;
8848 contents = bfd_malloc (hdr->sh_size);
8849 if (!contents)
8850 return;
8851 if (!bfd_get_section_contents (abfd, hdr->bfd_section, contents, 0,
8852 hdr->sh_size))
8854 free (contents);
8855 return;
8857 p = contents;
8858 if (*(p++) == 'A')
8860 len = hdr->sh_size - 1;
8861 while (len > 0)
8863 int namelen;
8864 bfd_vma section_len;
8866 section_len = bfd_get_32 (abfd, p);
8867 p += 4;
8868 if (section_len > len)
8869 section_len = len;
8870 len -= section_len;
8871 namelen = strlen ((char *)p) + 1;
8872 section_len -= namelen + 4;
8873 if (strcmp((char *)p, "aeabi") != 0)
8875 /* Vendor section. Ignore it. */
8876 p += namelen + section_len;
8878 else
8880 p += namelen;
8881 while (section_len > 0)
8883 int tag;
8884 unsigned int n;
8885 unsigned int val;
8886 bfd_vma subsection_len;
8887 bfd_byte *end;
8889 tag = read_unsigned_leb128 (abfd, p, &n);
8890 p += n;
8891 subsection_len = bfd_get_32 (abfd, p);
8892 p += 4;
8893 if (subsection_len > section_len)
8894 subsection_len = section_len;
8895 section_len -= subsection_len;
8896 subsection_len -= n + 4;
8897 end = p + subsection_len;
8898 switch (tag)
8900 case Tag_File:
8901 while (p < end)
8903 bfd_boolean is_string;
8905 tag = read_unsigned_leb128 (abfd, p, &n);
8906 p += n;
8907 if (tag == 4 || tag == 5)
8908 is_string = 1;
8909 else if (tag < 32)
8910 is_string = 0;
8911 else
8912 is_string = (tag & 1) != 0;
8913 if (tag == Tag_compatibility)
8915 val = read_unsigned_leb128 (abfd, p, &n);
8916 p += n;
8917 elf32_arm_add_eabi_attr_compat (abfd, val,
8918 (char *)p);
8919 p += strlen ((char *)p) + 1;
8921 else if (is_string)
8923 elf32_arm_add_eabi_attr_string (abfd, tag,
8924 (char *)p);
8925 p += strlen ((char *)p) + 1;
8927 else
8929 val = read_unsigned_leb128 (abfd, p, &n);
8930 p += n;
8931 elf32_arm_add_eabi_attr_int (abfd, tag, val);
8934 break;
8935 case Tag_Section:
8936 case Tag_Symbol:
8937 /* Don't have anywhere convenient to attach these.
8938 Fall through for now. */
8939 default:
8940 /* Ignore things we don't kow about. */
8941 p += subsection_len;
8942 subsection_len = 0;
8943 break;
8949 free (contents);
8952 /* Handle an ARM specific section when reading an object file. This is
8953 called when bfd_section_from_shdr finds a section with an unknown
8954 type. */
8956 static bfd_boolean
8957 elf32_arm_section_from_shdr (bfd *abfd,
8958 Elf_Internal_Shdr * hdr,
8959 const char *name,
8960 int shindex)
8962 /* There ought to be a place to keep ELF backend specific flags, but
8963 at the moment there isn't one. We just keep track of the
8964 sections by their name, instead. Fortunately, the ABI gives
8965 names for all the ARM specific sections, so we will probably get
8966 away with this. */
8967 switch (hdr->sh_type)
8969 case SHT_ARM_EXIDX:
8970 case SHT_ARM_PREEMPTMAP:
8971 case SHT_ARM_ATTRIBUTES:
8972 break;
8974 default:
8975 return FALSE;
8978 if (! _bfd_elf_make_section_from_shdr (abfd, hdr, name, shindex))
8979 return FALSE;
8981 if (hdr->sh_type == SHT_ARM_ATTRIBUTES)
8982 elf32_arm_parse_attributes(abfd, hdr);
8983 return TRUE;
8986 /* A structure used to record a list of sections, independently
8987 of the next and prev fields in the asection structure. */
8988 typedef struct section_list
8990 asection * sec;
8991 struct section_list * next;
8992 struct section_list * prev;
8994 section_list;
8996 /* Unfortunately we need to keep a list of sections for which
8997 an _arm_elf_section_data structure has been allocated. This
8998 is because it is possible for functions like elf32_arm_write_section
8999 to be called on a section which has had an elf_data_structure
9000 allocated for it (and so the used_by_bfd field is valid) but
9001 for which the ARM extended version of this structure - the
9002 _arm_elf_section_data structure - has not been allocated. */
9003 static section_list * sections_with_arm_elf_section_data = NULL;
9005 static void
9006 record_section_with_arm_elf_section_data (asection * sec)
9008 struct section_list * entry;
9010 entry = bfd_malloc (sizeof (* entry));
9011 if (entry == NULL)
9012 return;
9013 entry->sec = sec;
9014 entry->next = sections_with_arm_elf_section_data;
9015 entry->prev = NULL;
9016 if (entry->next != NULL)
9017 entry->next->prev = entry;
9018 sections_with_arm_elf_section_data = entry;
9021 static struct section_list *
9022 find_arm_elf_section_entry (asection * sec)
9024 struct section_list * entry;
9025 static struct section_list * last_entry = NULL;
9027 /* This is a short cut for the typical case where the sections are added
9028 to the sections_with_arm_elf_section_data list in forward order and
9029 then looked up here in backwards order. This makes a real difference
9030 to the ld-srec/sec64k.exp linker test. */
9031 entry = sections_with_arm_elf_section_data;
9032 if (last_entry != NULL)
9034 if (last_entry->sec == sec)
9035 entry = last_entry;
9036 else if (last_entry->next != NULL
9037 && last_entry->next->sec == sec)
9038 entry = last_entry->next;
9041 for (; entry; entry = entry->next)
9042 if (entry->sec == sec)
9043 break;
9045 if (entry)
9046 /* Record the entry prior to this one - it is the entry we are most
9047 likely to want to locate next time. Also this way if we have been
9048 called from unrecord_section_with_arm_elf_section_data() we will not
9049 be caching a pointer that is about to be freed. */
9050 last_entry = entry->prev;
9052 return entry;
9055 static _arm_elf_section_data *
9056 get_arm_elf_section_data (asection * sec)
9058 struct section_list * entry;
9060 entry = find_arm_elf_section_entry (sec);
9062 if (entry)
9063 return elf32_arm_section_data (entry->sec);
9064 else
9065 return NULL;
9068 static void
9069 unrecord_section_with_arm_elf_section_data (asection * sec)
9071 struct section_list * entry;
9073 entry = find_arm_elf_section_entry (sec);
9075 if (entry)
9077 if (entry->prev != NULL)
9078 entry->prev->next = entry->next;
9079 if (entry->next != NULL)
9080 entry->next->prev = entry->prev;
9081 if (entry == sections_with_arm_elf_section_data)
9082 sections_with_arm_elf_section_data = entry->next;
9083 free (entry);
9087 /* Called for each symbol. Builds a section map based on mapping symbols.
9088 Does not alter any of the symbols. */
9090 static bfd_boolean
9091 elf32_arm_output_symbol_hook (struct bfd_link_info *info,
9092 const char *name,
9093 Elf_Internal_Sym *elfsym,
9094 asection *input_sec,
9095 struct elf_link_hash_entry *h)
9097 int mapcount;
9098 elf32_arm_section_map *map;
9099 elf32_arm_section_map *newmap;
9100 _arm_elf_section_data *arm_data;
9101 struct elf32_arm_link_hash_table *globals;
9103 globals = elf32_arm_hash_table (info);
9104 if (globals->vxworks_p
9105 && !elf_vxworks_link_output_symbol_hook (info, name, elfsym,
9106 input_sec, h))
9107 return FALSE;
9109 /* Only do this on final link. */
9110 if (info->relocatable)
9111 return TRUE;
9113 /* Only build a map if we need to byteswap code. */
9114 if (!globals->byteswap_code)
9115 return TRUE;
9117 /* We only want mapping symbols. */
9118 if (!bfd_is_arm_special_symbol_name (name, BFD_ARM_SPECIAL_SYM_TYPE_MAP))
9119 return TRUE;
9121 /* If this section has not been allocated an _arm_elf_section_data
9122 structure then we cannot record anything. */
9123 arm_data = get_arm_elf_section_data (input_sec);
9124 if (arm_data == NULL)
9125 return TRUE;
9127 mapcount = arm_data->mapcount + 1;
9128 map = arm_data->map;
9130 /* TODO: This may be inefficient, but we probably don't usually have many
9131 mapping symbols per section. */
9132 newmap = bfd_realloc (map, mapcount * sizeof (* map));
9133 if (newmap != NULL)
9135 arm_data->map = newmap;
9136 arm_data->mapcount = mapcount;
9138 newmap[mapcount - 1].vma = elfsym->st_value;
9139 newmap[mapcount - 1].type = name[1];
9142 return TRUE;
9145 typedef struct
9147 void *finfo;
9148 struct bfd_link_info *info;
9149 int plt_shndx;
9150 bfd_vma plt_offset;
9151 bfd_boolean (*func) (void *, const char *, Elf_Internal_Sym *,
9152 asection *, struct elf_link_hash_entry *);
9153 } output_arch_syminfo;
9155 enum map_symbol_type
9157 ARM_MAP_ARM,
9158 ARM_MAP_THUMB,
9159 ARM_MAP_DATA
9163 /* Output a single PLT mapping symbol. */
9165 static bfd_boolean
9166 elf32_arm_ouput_plt_map_sym (output_arch_syminfo *osi,
9167 enum map_symbol_type type,
9168 bfd_vma offset)
9170 static const char *names[3] = {"$a", "$t", "$d"};
9171 struct elf32_arm_link_hash_table *htab;
9172 Elf_Internal_Sym sym;
9174 htab = elf32_arm_hash_table (osi->info);
9175 sym.st_value = osi->plt_offset + offset;
9176 sym.st_size = 0;
9177 sym.st_other = 0;
9178 sym.st_info = ELF_ST_INFO (STB_LOCAL, STT_NOTYPE);
9179 sym.st_shndx = osi->plt_shndx;
9180 if (!osi->func (osi->finfo, names[type], &sym, htab->splt, NULL))
9181 return FALSE;
9182 return TRUE;
9186 /* Output mapping symbols for PLT entries associated with H. */
9188 static bfd_boolean
9189 elf32_arm_output_plt_map (struct elf_link_hash_entry *h, void *inf)
9191 output_arch_syminfo *osi = (output_arch_syminfo *) inf;
9192 struct elf32_arm_link_hash_table *htab;
9193 struct elf32_arm_link_hash_entry *eh;
9194 bfd_vma addr;
9196 htab = elf32_arm_hash_table (osi->info);
9198 if (h->root.type == bfd_link_hash_indirect)
9199 return TRUE;
9201 if (h->root.type == bfd_link_hash_warning)
9202 /* When warning symbols are created, they **replace** the "real"
9203 entry in the hash table, thus we never get to see the real
9204 symbol in a hash traversal. So look at it now. */
9205 h = (struct elf_link_hash_entry *) h->root.u.i.link;
9207 if (h->plt.offset == (bfd_vma) -1)
9208 return TRUE;
9210 eh = (struct elf32_arm_link_hash_entry *) h;
9211 addr = h->plt.offset;
9212 if (htab->symbian_p)
9214 if (!elf32_arm_ouput_plt_map_sym (osi, ARM_MAP_ARM, addr))
9215 return FALSE;
9216 if (!elf32_arm_ouput_plt_map_sym (osi, ARM_MAP_DATA, addr + 4))
9217 return FALSE;
9219 else if (htab->vxworks_p)
9221 if (!elf32_arm_ouput_plt_map_sym (osi, ARM_MAP_ARM, addr))
9222 return FALSE;
9223 if (!elf32_arm_ouput_plt_map_sym (osi, ARM_MAP_DATA, addr + 8))
9224 return FALSE;
9225 if (!elf32_arm_ouput_plt_map_sym (osi, ARM_MAP_ARM, addr + 12))
9226 return FALSE;
9227 if (!elf32_arm_ouput_plt_map_sym (osi, ARM_MAP_DATA, addr + 20))
9228 return FALSE;
9230 else
9232 bfd_boolean thumb_stub;
9234 thumb_stub = eh->plt_thumb_refcount > 0 && !htab->use_blx;
9235 if (thumb_stub)
9237 if (!elf32_arm_ouput_plt_map_sym (osi, ARM_MAP_THUMB, addr - 4))
9238 return FALSE;
9240 #ifdef FOUR_WORD_PLT
9241 if (!elf32_arm_ouput_plt_map_sym (osi, ARM_MAP_ARM, addr))
9242 return FALSE;
9243 if (!elf32_arm_ouput_plt_map_sym (osi, ARM_MAP_DATA, addr + 12))
9244 return FALSE;
9245 #else
9246 /* A three-word PLT with no Thumb thunk contains only Arm code,
9247 so only need to output a mapping symbol for the first PLT entry and
9248 entries with thumb thunks. */
9249 if (thumb_stub || addr == 20)
9251 if (!elf32_arm_ouput_plt_map_sym (osi, ARM_MAP_ARM, addr))
9252 return FALSE;
9254 #endif
9257 return TRUE;
9261 /* Output mapping symbols for the PLT. */
9263 static bfd_boolean
9264 elf32_arm_output_arch_local_syms (bfd *output_bfd,
9265 struct bfd_link_info *info,
9266 void *finfo, bfd_boolean (*func) (void *, const char *,
9267 Elf_Internal_Sym *,
9268 asection *,
9269 struct elf_link_hash_entry *))
9271 output_arch_syminfo osi;
9272 struct elf32_arm_link_hash_table *htab;
9274 htab = elf32_arm_hash_table (info);
9275 if (!htab->splt || htab->splt->size == 0)
9276 return TRUE;
9278 check_use_blx(htab);
9279 osi.finfo = finfo;
9280 osi.info = info;
9281 osi.func = func;
9282 osi.plt_shndx = _bfd_elf_section_from_bfd_section (output_bfd,
9283 htab->splt->output_section);
9284 osi.plt_offset = htab->splt->output_section->vma;
9286 /* Output mapping symbols for the plt header. SymbianOS does not have a
9287 plt header. */
9288 if (htab->vxworks_p)
9290 /* VxWorks shared libraries have no PLT header. */
9291 if (!info->shared)
9293 if (!elf32_arm_ouput_plt_map_sym (&osi, ARM_MAP_ARM, 0))
9294 return FALSE;
9295 if (!elf32_arm_ouput_plt_map_sym (&osi, ARM_MAP_DATA, 12))
9296 return FALSE;
9299 else if (!htab->symbian_p)
9301 if (!elf32_arm_ouput_plt_map_sym (&osi, ARM_MAP_ARM, 0))
9302 return FALSE;
9303 #ifndef FOUR_WORD_PLT
9304 if (!elf32_arm_ouput_plt_map_sym (&osi, ARM_MAP_DATA, 16))
9305 return FALSE;
9306 #endif
9309 elf_link_hash_traverse (&htab->root, elf32_arm_output_plt_map, (void *) &osi);
9310 return TRUE;
9313 /* Allocate target specific section data. */
9315 static bfd_boolean
9316 elf32_arm_new_section_hook (bfd *abfd, asection *sec)
9318 if (!sec->used_by_bfd)
9320 _arm_elf_section_data *sdata;
9321 bfd_size_type amt = sizeof (*sdata);
9323 sdata = bfd_zalloc (abfd, amt);
9324 if (sdata == NULL)
9325 return FALSE;
9326 sec->used_by_bfd = sdata;
9329 record_section_with_arm_elf_section_data (sec);
9331 return _bfd_elf_new_section_hook (abfd, sec);
9335 /* Used to order a list of mapping symbols by address. */
9337 static int
9338 elf32_arm_compare_mapping (const void * a, const void * b)
9340 return ((const elf32_arm_section_map *) a)->vma
9341 > ((const elf32_arm_section_map *) b)->vma;
9345 /* Do code byteswapping. Return FALSE afterwards so that the section is
9346 written out as normal. */
9348 static bfd_boolean
9349 elf32_arm_write_section (bfd *output_bfd ATTRIBUTE_UNUSED, asection *sec,
9350 bfd_byte *contents)
9352 int mapcount;
9353 _arm_elf_section_data *arm_data;
9354 elf32_arm_section_map *map;
9355 bfd_vma ptr;
9356 bfd_vma end;
9357 bfd_vma offset;
9358 bfd_byte tmp;
9359 int i;
9361 /* If this section has not been allocated an _arm_elf_section_data
9362 structure then we cannot record anything. */
9363 arm_data = get_arm_elf_section_data (sec);
9364 if (arm_data == NULL)
9365 return FALSE;
9367 mapcount = arm_data->mapcount;
9368 map = arm_data->map;
9370 if (mapcount == 0)
9371 return FALSE;
9373 qsort (map, mapcount, sizeof (* map), elf32_arm_compare_mapping);
9375 offset = sec->output_section->vma + sec->output_offset;
9376 ptr = map[0].vma - offset;
9377 for (i = 0; i < mapcount; i++)
9379 if (i == mapcount - 1)
9380 end = sec->size;
9381 else
9382 end = map[i + 1].vma - offset;
9384 switch (map[i].type)
9386 case 'a':
9387 /* Byte swap code words. */
9388 while (ptr + 3 < end)
9390 tmp = contents[ptr];
9391 contents[ptr] = contents[ptr + 3];
9392 contents[ptr + 3] = tmp;
9393 tmp = contents[ptr + 1];
9394 contents[ptr + 1] = contents[ptr + 2];
9395 contents[ptr + 2] = tmp;
9396 ptr += 4;
9398 break;
9400 case 't':
9401 /* Byte swap code halfwords. */
9402 while (ptr + 1 < end)
9404 tmp = contents[ptr];
9405 contents[ptr] = contents[ptr + 1];
9406 contents[ptr + 1] = tmp;
9407 ptr += 2;
9409 break;
9411 case 'd':
9412 /* Leave data alone. */
9413 break;
9415 ptr = end;
9418 free (map);
9419 arm_data->mapcount = 0;
9420 arm_data->map = NULL;
9421 unrecord_section_with_arm_elf_section_data (sec);
9423 return FALSE;
9426 static void
9427 unrecord_section_via_map_over_sections (bfd * abfd ATTRIBUTE_UNUSED,
9428 asection * sec,
9429 void * ignore ATTRIBUTE_UNUSED)
9431 unrecord_section_with_arm_elf_section_data (sec);
9434 static bfd_boolean
9435 elf32_arm_close_and_cleanup (bfd * abfd)
9437 if (abfd->sections)
9438 bfd_map_over_sections (abfd,
9439 unrecord_section_via_map_over_sections,
9440 NULL);
9442 return _bfd_elf_close_and_cleanup (abfd);
9445 static bfd_boolean
9446 elf32_arm_bfd_free_cached_info (bfd * abfd)
9448 if (abfd->sections)
9449 bfd_map_over_sections (abfd,
9450 unrecord_section_via_map_over_sections,
9451 NULL);
9453 return _bfd_free_cached_info (abfd);
9456 /* Display STT_ARM_TFUNC symbols as functions. */
9458 static void
9459 elf32_arm_symbol_processing (bfd *abfd ATTRIBUTE_UNUSED,
9460 asymbol *asym)
9462 elf_symbol_type *elfsym = (elf_symbol_type *) asym;
9464 if (ELF_ST_TYPE (elfsym->internal_elf_sym.st_info) == STT_ARM_TFUNC)
9465 elfsym->symbol.flags |= BSF_FUNCTION;
9469 /* Mangle thumb function symbols as we read them in. */
9471 static bfd_boolean
9472 elf32_arm_swap_symbol_in (bfd * abfd,
9473 const void *psrc,
9474 const void *pshn,
9475 Elf_Internal_Sym *dst)
9477 if (!bfd_elf32_swap_symbol_in (abfd, psrc, pshn, dst))
9478 return FALSE;
9480 /* New EABI objects mark thumb function symbols by setting the low bit of
9481 the address. Turn these into STT_ARM_TFUNC. */
9482 if (ELF_ST_TYPE (dst->st_info) == STT_FUNC
9483 && (dst->st_value & 1))
9485 dst->st_info = ELF_ST_INFO (ELF_ST_BIND (dst->st_info), STT_ARM_TFUNC);
9486 dst->st_value &= ~(bfd_vma) 1;
9488 return TRUE;
9492 /* Mangle thumb function symbols as we write them out. */
9494 static void
9495 elf32_arm_swap_symbol_out (bfd *abfd,
9496 const Elf_Internal_Sym *src,
9497 void *cdst,
9498 void *shndx)
9500 Elf_Internal_Sym newsym;
9502 /* We convert STT_ARM_TFUNC symbols into STT_FUNC with the low bit
9503 of the address set, as per the new EABI. We do this unconditionally
9504 because objcopy does not set the elf header flags until after
9505 it writes out the symbol table. */
9506 if (ELF_ST_TYPE (src->st_info) == STT_ARM_TFUNC)
9508 newsym = *src;
9509 newsym.st_info = ELF_ST_INFO (ELF_ST_BIND (src->st_info), STT_FUNC);
9510 if (newsym.st_shndx != SHN_UNDEF)
9512 /* Do this only for defined symbols. At link type, the static
9513 linker will simulate the work of dynamic linker of resolving
9514 symbols and will carry over the thumbness of found symbols to
9515 the output symbol table. It's not clear how it happens, but
9516 the thumbness of undefined symbols can well be different at
9517 runtime, and writing '1' for them will be confusing for users
9518 and possibly for dynamic linker itself.
9520 newsym.st_value |= 1;
9523 src = &newsym;
9525 bfd_elf32_swap_symbol_out (abfd, src, cdst, shndx);
9528 /* Add the PT_ARM_EXIDX program header. */
9530 static bfd_boolean
9531 elf32_arm_modify_segment_map (bfd *abfd,
9532 struct bfd_link_info *info ATTRIBUTE_UNUSED)
9534 struct elf_segment_map *m;
9535 asection *sec;
9537 sec = bfd_get_section_by_name (abfd, ".ARM.exidx");
9538 if (sec != NULL && (sec->flags & SEC_LOAD) != 0)
9540 /* If there is already a PT_ARM_EXIDX header, then we do not
9541 want to add another one. This situation arises when running
9542 "strip"; the input binary already has the header. */
9543 m = elf_tdata (abfd)->segment_map;
9544 while (m && m->p_type != PT_ARM_EXIDX)
9545 m = m->next;
9546 if (!m)
9548 m = bfd_zalloc (abfd, sizeof (struct elf_segment_map));
9549 if (m == NULL)
9550 return FALSE;
9551 m->p_type = PT_ARM_EXIDX;
9552 m->count = 1;
9553 m->sections[0] = sec;
9555 m->next = elf_tdata (abfd)->segment_map;
9556 elf_tdata (abfd)->segment_map = m;
9560 return TRUE;
9563 /* We may add a PT_ARM_EXIDX program header. */
9565 static int
9566 elf32_arm_additional_program_headers (bfd *abfd,
9567 struct bfd_link_info *info ATTRIBUTE_UNUSED)
9569 asection *sec;
9571 sec = bfd_get_section_by_name (abfd, ".ARM.exidx");
9572 if (sec != NULL && (sec->flags & SEC_LOAD) != 0)
9573 return 1;
9574 else
9575 return 0;
9578 /* We use this to override swap_symbol_in and swap_symbol_out. */
9579 const struct elf_size_info elf32_arm_size_info = {
9580 sizeof (Elf32_External_Ehdr),
9581 sizeof (Elf32_External_Phdr),
9582 sizeof (Elf32_External_Shdr),
9583 sizeof (Elf32_External_Rel),
9584 sizeof (Elf32_External_Rela),
9585 sizeof (Elf32_External_Sym),
9586 sizeof (Elf32_External_Dyn),
9587 sizeof (Elf_External_Note),
9590 32, 2,
9591 ELFCLASS32, EV_CURRENT,
9592 bfd_elf32_write_out_phdrs,
9593 bfd_elf32_write_shdrs_and_ehdr,
9594 bfd_elf32_write_relocs,
9595 elf32_arm_swap_symbol_in,
9596 elf32_arm_swap_symbol_out,
9597 bfd_elf32_slurp_reloc_table,
9598 bfd_elf32_slurp_symbol_table,
9599 bfd_elf32_swap_dyn_in,
9600 bfd_elf32_swap_dyn_out,
9601 bfd_elf32_swap_reloc_in,
9602 bfd_elf32_swap_reloc_out,
9603 bfd_elf32_swap_reloca_in,
9604 bfd_elf32_swap_reloca_out
9607 #define ELF_ARCH bfd_arch_arm
9608 #define ELF_MACHINE_CODE EM_ARM
9609 #ifdef __QNXTARGET__
9610 #define ELF_MAXPAGESIZE 0x1000
9611 #else
9612 #define ELF_MAXPAGESIZE 0x8000
9613 #endif
9614 #define ELF_MINPAGESIZE 0x1000
9615 #define ELF_COMMONPAGESIZE 0x1000
9617 #define bfd_elf32_mkobject elf32_arm_mkobject
9619 #define bfd_elf32_bfd_copy_private_bfd_data elf32_arm_copy_private_bfd_data
9620 #define bfd_elf32_bfd_merge_private_bfd_data elf32_arm_merge_private_bfd_data
9621 #define bfd_elf32_bfd_set_private_flags elf32_arm_set_private_flags
9622 #define bfd_elf32_bfd_print_private_bfd_data elf32_arm_print_private_bfd_data
9623 #define bfd_elf32_bfd_link_hash_table_create elf32_arm_link_hash_table_create
9624 #define bfd_elf32_bfd_reloc_type_lookup elf32_arm_reloc_type_lookup
9625 #define bfd_elf32_find_nearest_line elf32_arm_find_nearest_line
9626 #define bfd_elf32_find_inliner_info elf32_arm_find_inliner_info
9627 #define bfd_elf32_new_section_hook elf32_arm_new_section_hook
9628 #define bfd_elf32_bfd_is_target_special_symbol elf32_arm_is_target_special_symbol
9629 #define bfd_elf32_close_and_cleanup elf32_arm_close_and_cleanup
9630 #define bfd_elf32_bfd_free_cached_info elf32_arm_bfd_free_cached_info
9631 #define bfd_elf32_bfd_final_link elf32_arm_bfd_final_link
9633 #define elf_backend_get_symbol_type elf32_arm_get_symbol_type
9634 #define elf_backend_gc_mark_hook elf32_arm_gc_mark_hook
9635 #define elf_backend_gc_sweep_hook elf32_arm_gc_sweep_hook
9636 #define elf_backend_check_relocs elf32_arm_check_relocs
9637 #define elf_backend_relocate_section elf32_arm_relocate_section
9638 #define elf_backend_write_section elf32_arm_write_section
9639 #define elf_backend_adjust_dynamic_symbol elf32_arm_adjust_dynamic_symbol
9640 #define elf_backend_create_dynamic_sections elf32_arm_create_dynamic_sections
9641 #define elf_backend_finish_dynamic_symbol elf32_arm_finish_dynamic_symbol
9642 #define elf_backend_finish_dynamic_sections elf32_arm_finish_dynamic_sections
9643 #define elf_backend_link_output_symbol_hook elf32_arm_output_symbol_hook
9644 #define elf_backend_size_dynamic_sections elf32_arm_size_dynamic_sections
9645 #define elf_backend_init_index_section _bfd_elf_init_2_index_sections
9646 #define elf_backend_post_process_headers elf32_arm_post_process_headers
9647 #define elf_backend_reloc_type_class elf32_arm_reloc_type_class
9648 #define elf_backend_object_p elf32_arm_object_p
9649 #define elf_backend_section_flags elf32_arm_section_flags
9650 #define elf_backend_fake_sections elf32_arm_fake_sections
9651 #define elf_backend_section_from_shdr elf32_arm_section_from_shdr
9652 #define elf_backend_final_write_processing elf32_arm_final_write_processing
9653 #define elf_backend_copy_indirect_symbol elf32_arm_copy_indirect_symbol
9654 #define elf_backend_symbol_processing elf32_arm_symbol_processing
9655 #define elf_backend_size_info elf32_arm_size_info
9656 #define elf_backend_modify_segment_map elf32_arm_modify_segment_map
9657 #define elf_backend_additional_program_headers \
9658 elf32_arm_additional_program_headers
9659 #define elf_backend_output_arch_local_syms \
9660 elf32_arm_output_arch_local_syms
9661 #define elf_backend_begin_write_processing \
9662 elf32_arm_begin_write_processing
9664 #define elf_backend_can_refcount 1
9665 #define elf_backend_can_gc_sections 1
9666 #define elf_backend_plt_readonly 1
9667 #define elf_backend_want_got_plt 1
9668 #define elf_backend_want_plt_sym 0
9669 #define elf_backend_may_use_rel_p 1
9670 #define elf_backend_may_use_rela_p 0
9671 #define elf_backend_default_use_rela_p 0
9672 #define elf_backend_rela_normal 0
9674 #define elf_backend_got_header_size 12
9676 #include "elf32-target.h"
9678 /* VxWorks Targets */
9680 #undef TARGET_LITTLE_SYM
9681 #define TARGET_LITTLE_SYM bfd_elf32_littlearm_vxworks_vec
9682 #undef TARGET_LITTLE_NAME
9683 #define TARGET_LITTLE_NAME "elf32-littlearm-vxworks"
9684 #undef TARGET_BIG_SYM
9685 #define TARGET_BIG_SYM bfd_elf32_bigarm_vxworks_vec
9686 #undef TARGET_BIG_NAME
9687 #define TARGET_BIG_NAME "elf32-bigarm-vxworks"
9689 /* Like elf32_arm_link_hash_table_create -- but overrides
9690 appropriately for VxWorks. */
9691 static struct bfd_link_hash_table *
9692 elf32_arm_vxworks_link_hash_table_create (bfd *abfd)
9694 struct bfd_link_hash_table *ret;
9696 ret = elf32_arm_link_hash_table_create (abfd);
9697 if (ret)
9699 struct elf32_arm_link_hash_table *htab
9700 = (struct elf32_arm_link_hash_table *) ret;
9701 htab->use_rel = 0;
9702 htab->vxworks_p = 1;
9704 return ret;
9707 static void
9708 elf32_arm_vxworks_final_write_processing (bfd *abfd, bfd_boolean linker)
9710 elf32_arm_final_write_processing (abfd, linker);
9711 elf_vxworks_final_write_processing (abfd, linker);
9714 #undef elf32_bed
9715 #define elf32_bed elf32_arm_vxworks_bed
9717 #undef bfd_elf32_bfd_link_hash_table_create
9718 #define bfd_elf32_bfd_link_hash_table_create \
9719 elf32_arm_vxworks_link_hash_table_create
9720 #undef elf_backend_add_symbol_hook
9721 #define elf_backend_add_symbol_hook \
9722 elf_vxworks_add_symbol_hook
9723 #undef elf_backend_final_write_processing
9724 #define elf_backend_final_write_processing \
9725 elf32_arm_vxworks_final_write_processing
9726 #undef elf_backend_emit_relocs
9727 #define elf_backend_emit_relocs \
9728 elf_vxworks_emit_relocs
9730 #undef elf_backend_may_use_rel_p
9731 #define elf_backend_may_use_rel_p 0
9732 #undef elf_backend_may_use_rela_p
9733 #define elf_backend_may_use_rela_p 1
9734 #undef elf_backend_default_use_rela_p
9735 #define elf_backend_default_use_rela_p 1
9736 #undef elf_backend_rela_normal
9737 #define elf_backend_rela_normal 1
9738 #undef elf_backend_want_plt_sym
9739 #define elf_backend_want_plt_sym 1
9740 #undef ELF_MAXPAGESIZE
9741 #define ELF_MAXPAGESIZE 0x1000
9743 #include "elf32-target.h"
9746 /* Symbian OS Targets */
9748 #undef TARGET_LITTLE_SYM
9749 #define TARGET_LITTLE_SYM bfd_elf32_littlearm_symbian_vec
9750 #undef TARGET_LITTLE_NAME
9751 #define TARGET_LITTLE_NAME "elf32-littlearm-symbian"
9752 #undef TARGET_BIG_SYM
9753 #define TARGET_BIG_SYM bfd_elf32_bigarm_symbian_vec
9754 #undef TARGET_BIG_NAME
9755 #define TARGET_BIG_NAME "elf32-bigarm-symbian"
9757 /* Like elf32_arm_link_hash_table_create -- but overrides
9758 appropriately for Symbian OS. */
9759 static struct bfd_link_hash_table *
9760 elf32_arm_symbian_link_hash_table_create (bfd *abfd)
9762 struct bfd_link_hash_table *ret;
9764 ret = elf32_arm_link_hash_table_create (abfd);
9765 if (ret)
9767 struct elf32_arm_link_hash_table *htab
9768 = (struct elf32_arm_link_hash_table *)ret;
9769 /* There is no PLT header for Symbian OS. */
9770 htab->plt_header_size = 0;
9771 /* The PLT entries are each three instructions. */
9772 htab->plt_entry_size = 4 * NUM_ELEM (elf32_arm_symbian_plt_entry);
9773 htab->symbian_p = 1;
9774 /* Symbian uses armv5t or above, so use_blx is always true. */
9775 htab->use_blx = 1;
9776 htab->root.is_relocatable_executable = 1;
9778 return ret;
9781 static const struct bfd_elf_special_section
9782 elf32_arm_symbian_special_sections[] =
9784 /* In a BPABI executable, the dynamic linking sections do not go in
9785 the loadable read-only segment. The post-linker may wish to
9786 refer to these sections, but they are not part of the final
9787 program image. */
9788 { STRING_COMMA_LEN (".dynamic"), 0, SHT_DYNAMIC, 0 },
9789 { STRING_COMMA_LEN (".dynstr"), 0, SHT_STRTAB, 0 },
9790 { STRING_COMMA_LEN (".dynsym"), 0, SHT_DYNSYM, 0 },
9791 { STRING_COMMA_LEN (".got"), 0, SHT_PROGBITS, 0 },
9792 { STRING_COMMA_LEN (".hash"), 0, SHT_HASH, 0 },
9793 /* These sections do not need to be writable as the SymbianOS
9794 postlinker will arrange things so that no dynamic relocation is
9795 required. */
9796 { STRING_COMMA_LEN (".init_array"), 0, SHT_INIT_ARRAY, SHF_ALLOC },
9797 { STRING_COMMA_LEN (".fini_array"), 0, SHT_FINI_ARRAY, SHF_ALLOC },
9798 { STRING_COMMA_LEN (".preinit_array"), 0, SHT_PREINIT_ARRAY, SHF_ALLOC },
9799 { NULL, 0, 0, 0, 0 }
9802 static void
9803 elf32_arm_symbian_begin_write_processing (bfd *abfd,
9804 struct bfd_link_info *link_info)
9806 /* BPABI objects are never loaded directly by an OS kernel; they are
9807 processed by a postlinker first, into an OS-specific format. If
9808 the D_PAGED bit is set on the file, BFD will align segments on
9809 page boundaries, so that an OS can directly map the file. With
9810 BPABI objects, that just results in wasted space. In addition,
9811 because we clear the D_PAGED bit, map_sections_to_segments will
9812 recognize that the program headers should not be mapped into any
9813 loadable segment. */
9814 abfd->flags &= ~D_PAGED;
9815 elf32_arm_begin_write_processing(abfd, link_info);
9818 static bfd_boolean
9819 elf32_arm_symbian_modify_segment_map (bfd *abfd,
9820 struct bfd_link_info *info)
9822 struct elf_segment_map *m;
9823 asection *dynsec;
9825 /* BPABI shared libraries and executables should have a PT_DYNAMIC
9826 segment. However, because the .dynamic section is not marked
9827 with SEC_LOAD, the generic ELF code will not create such a
9828 segment. */
9829 dynsec = bfd_get_section_by_name (abfd, ".dynamic");
9830 if (dynsec)
9832 for (m = elf_tdata (abfd)->segment_map; m != NULL; m = m->next)
9833 if (m->p_type == PT_DYNAMIC)
9834 break;
9836 if (m == NULL)
9838 m = _bfd_elf_make_dynamic_segment (abfd, dynsec);
9839 m->next = elf_tdata (abfd)->segment_map;
9840 elf_tdata (abfd)->segment_map = m;
9844 /* Also call the generic arm routine. */
9845 return elf32_arm_modify_segment_map (abfd, info);
9848 #undef elf32_bed
9849 #define elf32_bed elf32_arm_symbian_bed
9851 /* The dynamic sections are not allocated on SymbianOS; the postlinker
9852 will process them and then discard them. */
9853 #undef ELF_DYNAMIC_SEC_FLAGS
9854 #define ELF_DYNAMIC_SEC_FLAGS \
9855 (SEC_HAS_CONTENTS | SEC_IN_MEMORY | SEC_LINKER_CREATED)
9857 #undef bfd_elf32_bfd_link_hash_table_create
9858 #define bfd_elf32_bfd_link_hash_table_create \
9859 elf32_arm_symbian_link_hash_table_create
9860 #undef elf_backend_add_symbol_hook
9862 #undef elf_backend_special_sections
9863 #define elf_backend_special_sections elf32_arm_symbian_special_sections
9865 #undef elf_backend_begin_write_processing
9866 #define elf_backend_begin_write_processing \
9867 elf32_arm_symbian_begin_write_processing
9868 #undef elf_backend_final_write_processing
9869 #define elf_backend_final_write_processing \
9870 elf32_arm_final_write_processing
9871 #undef elf_backend_emit_relocs
9873 #undef elf_backend_modify_segment_map
9874 #define elf_backend_modify_segment_map elf32_arm_symbian_modify_segment_map
9876 /* There is no .got section for BPABI objects, and hence no header. */
9877 #undef elf_backend_got_header_size
9878 #define elf_backend_got_header_size 0
9880 /* Similarly, there is no .got.plt section. */
9881 #undef elf_backend_want_got_plt
9882 #define elf_backend_want_got_plt 0
9884 #undef elf_backend_may_use_rel_p
9885 #define elf_backend_may_use_rel_p 1
9886 #undef elf_backend_may_use_rela_p
9887 #define elf_backend_may_use_rela_p 0
9888 #undef elf_backend_default_use_rela_p
9889 #define elf_backend_default_use_rela_p 0
9890 #undef elf_backend_rela_normal
9891 #define elf_backend_rela_normal 0
9892 #undef elf_backend_want_plt_sym
9893 #define elf_backend_want_plt_sym 0
9894 #undef ELF_MAXPAGESIZE
9895 #define ELF_MAXPAGESIZE 0x8000
9897 #include "elf32-target.h"