daily update
[binutils.git] / bfd / elf32-arm.c
blob6f220e9631beea651e7407d8673ad76dd755cb88
1 /* 32-bit ELF support for ARM
2 Copyright 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005
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 "libbfd.h"
24 #include "elf-bfd.h"
25 #include "elf/arm.h"
27 #ifndef NUM_ELEM
28 #define NUM_ELEM(a) (sizeof (a) / (sizeof (a)[0]))
29 #endif
31 #define elf_info_to_howto 0
32 #define elf_info_to_howto_rel elf32_arm_info_to_howto
34 #define ARM_ELF_ABI_VERSION 0
35 #define ARM_ELF_OS_ABI_VERSION ELFOSABI_ARM
37 /* Note: code such as elf32_arm_reloc_type_lookup expect to use e.g.
38 R_ARM_PC24 as an index into this, and find the R_ARM_PC24 HOWTO
39 in that slot. */
41 static reloc_howto_type elf32_arm_howto_table_1[] =
43 /* No relocation */
44 HOWTO (R_ARM_NONE, /* type */
45 0, /* rightshift */
46 0, /* size (0 = byte, 1 = short, 2 = long) */
47 0, /* bitsize */
48 FALSE, /* pc_relative */
49 0, /* bitpos */
50 complain_overflow_dont,/* complain_on_overflow */
51 bfd_elf_generic_reloc, /* special_function */
52 "R_ARM_NONE", /* name */
53 FALSE, /* partial_inplace */
54 0, /* src_mask */
55 0, /* dst_mask */
56 FALSE), /* pcrel_offset */
58 HOWTO (R_ARM_PC24, /* type */
59 2, /* rightshift */
60 2, /* size (0 = byte, 1 = short, 2 = long) */
61 24, /* bitsize */
62 TRUE, /* pc_relative */
63 0, /* bitpos */
64 complain_overflow_signed,/* complain_on_overflow */
65 bfd_elf_generic_reloc, /* special_function */
66 "R_ARM_PC24", /* name */
67 FALSE, /* partial_inplace */
68 0x00ffffff, /* src_mask */
69 0x00ffffff, /* dst_mask */
70 TRUE), /* pcrel_offset */
72 /* 32 bit absolute */
73 HOWTO (R_ARM_ABS32, /* type */
74 0, /* rightshift */
75 2, /* size (0 = byte, 1 = short, 2 = long) */
76 32, /* bitsize */
77 FALSE, /* pc_relative */
78 0, /* bitpos */
79 complain_overflow_bitfield,/* complain_on_overflow */
80 bfd_elf_generic_reloc, /* special_function */
81 "R_ARM_ABS32", /* name */
82 FALSE, /* partial_inplace */
83 0xffffffff, /* src_mask */
84 0xffffffff, /* dst_mask */
85 FALSE), /* pcrel_offset */
87 /* standard 32bit pc-relative reloc */
88 HOWTO (R_ARM_REL32, /* type */
89 0, /* rightshift */
90 2, /* size (0 = byte, 1 = short, 2 = long) */
91 32, /* bitsize */
92 TRUE, /* pc_relative */
93 0, /* bitpos */
94 complain_overflow_bitfield,/* complain_on_overflow */
95 bfd_elf_generic_reloc, /* special_function */
96 "R_ARM_REL32", /* name */
97 FALSE, /* partial_inplace */
98 0xffffffff, /* src_mask */
99 0xffffffff, /* dst_mask */
100 TRUE), /* pcrel_offset */
102 /* 8 bit absolute - R_ARM_LDR_PC_G0 in AAELF */
103 HOWTO (R_ARM_PC13, /* type */
104 0, /* rightshift */
105 0, /* size (0 = byte, 1 = short, 2 = long) */
106 8, /* 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_PC13", /* name */
112 FALSE, /* partial_inplace */
113 0x000000ff, /* src_mask */
114 0x000000ff, /* dst_mask */
115 FALSE), /* pcrel_offset */
117 /* 16 bit absolute */
118 HOWTO (R_ARM_ABS16, /* type */
119 0, /* rightshift */
120 1, /* size (0 = byte, 1 = short, 2 = long) */
121 16, /* bitsize */
122 FALSE, /* pc_relative */
123 0, /* bitpos */
124 complain_overflow_bitfield,/* complain_on_overflow */
125 bfd_elf_generic_reloc, /* special_function */
126 "R_ARM_ABS16", /* name */
127 FALSE, /* partial_inplace */
128 0x0000ffff, /* src_mask */
129 0x0000ffff, /* dst_mask */
130 FALSE), /* pcrel_offset */
132 /* 12 bit absolute */
133 HOWTO (R_ARM_ABS12, /* type */
134 0, /* rightshift */
135 2, /* size (0 = byte, 1 = short, 2 = long) */
136 12, /* bitsize */
137 FALSE, /* pc_relative */
138 0, /* bitpos */
139 complain_overflow_bitfield,/* complain_on_overflow */
140 bfd_elf_generic_reloc, /* special_function */
141 "R_ARM_ABS12", /* name */
142 FALSE, /* partial_inplace */
143 0x000008ff, /* src_mask */
144 0x000008ff, /* dst_mask */
145 FALSE), /* pcrel_offset */
147 HOWTO (R_ARM_THM_ABS5, /* type */
148 6, /* rightshift */
149 1, /* size (0 = byte, 1 = short, 2 = long) */
150 5, /* bitsize */
151 FALSE, /* pc_relative */
152 0, /* bitpos */
153 complain_overflow_bitfield,/* complain_on_overflow */
154 bfd_elf_generic_reloc, /* special_function */
155 "R_ARM_THM_ABS5", /* name */
156 FALSE, /* partial_inplace */
157 0x000007e0, /* src_mask */
158 0x000007e0, /* dst_mask */
159 FALSE), /* pcrel_offset */
161 /* 8 bit absolute */
162 HOWTO (R_ARM_ABS8, /* type */
163 0, /* rightshift */
164 0, /* size (0 = byte, 1 = short, 2 = long) */
165 8, /* bitsize */
166 FALSE, /* pc_relative */
167 0, /* bitpos */
168 complain_overflow_bitfield,/* complain_on_overflow */
169 bfd_elf_generic_reloc, /* special_function */
170 "R_ARM_ABS8", /* name */
171 FALSE, /* partial_inplace */
172 0x000000ff, /* src_mask */
173 0x000000ff, /* dst_mask */
174 FALSE), /* pcrel_offset */
176 HOWTO (R_ARM_SBREL32, /* type */
177 0, /* rightshift */
178 2, /* size (0 = byte, 1 = short, 2 = long) */
179 32, /* bitsize */
180 FALSE, /* pc_relative */
181 0, /* bitpos */
182 complain_overflow_dont,/* complain_on_overflow */
183 bfd_elf_generic_reloc, /* special_function */
184 "R_ARM_SBREL32", /* name */
185 FALSE, /* partial_inplace */
186 0xffffffff, /* src_mask */
187 0xffffffff, /* dst_mask */
188 FALSE), /* pcrel_offset */
190 /* FIXME: Has two more bits of offset in Thumb32. */
191 HOWTO (R_ARM_THM_CALL, /* type */
192 1, /* rightshift */
193 2, /* size (0 = byte, 1 = short, 2 = long) */
194 23, /* bitsize */
195 TRUE, /* pc_relative */
196 0, /* bitpos */
197 complain_overflow_signed,/* complain_on_overflow */
198 bfd_elf_generic_reloc, /* special_function */
199 "R_ARM_THM_CALL", /* name */
200 FALSE, /* partial_inplace */
201 0x07ff07ff, /* src_mask */
202 0x07ff07ff, /* dst_mask */
203 TRUE), /* pcrel_offset */
205 HOWTO (R_ARM_THM_PC8, /* type */
206 1, /* rightshift */
207 1, /* size (0 = byte, 1 = short, 2 = long) */
208 8, /* bitsize */
209 TRUE, /* pc_relative */
210 0, /* bitpos */
211 complain_overflow_signed,/* complain_on_overflow */
212 bfd_elf_generic_reloc, /* special_function */
213 "R_ARM_THM_PC8", /* name */
214 FALSE, /* partial_inplace */
215 0x000000ff, /* src_mask */
216 0x000000ff, /* dst_mask */
217 TRUE), /* pcrel_offset */
219 HOWTO (R_ARM_BREL_ADJ, /* type */
220 1, /* rightshift */
221 1, /* size (0 = byte, 1 = short, 2 = long) */
222 32, /* bitsize */
223 FALSE, /* pc_relative */
224 0, /* bitpos */
225 complain_overflow_signed,/* complain_on_overflow */
226 bfd_elf_generic_reloc, /* special_function */
227 "R_ARM_BREL_ADJ", /* name */
228 FALSE, /* partial_inplace */
229 0xffffffff, /* src_mask */
230 0xffffffff, /* dst_mask */
231 FALSE), /* pcrel_offset */
233 HOWTO (R_ARM_SWI24, /* type */
234 0, /* rightshift */
235 0, /* size (0 = byte, 1 = short, 2 = long) */
236 0, /* bitsize */
237 FALSE, /* pc_relative */
238 0, /* bitpos */
239 complain_overflow_signed,/* complain_on_overflow */
240 bfd_elf_generic_reloc, /* special_function */
241 "R_ARM_SWI24", /* name */
242 FALSE, /* partial_inplace */
243 0x00000000, /* src_mask */
244 0x00000000, /* dst_mask */
245 FALSE), /* pcrel_offset */
247 HOWTO (R_ARM_THM_SWI8, /* type */
248 0, /* rightshift */
249 0, /* size (0 = byte, 1 = short, 2 = long) */
250 0, /* bitsize */
251 FALSE, /* pc_relative */
252 0, /* bitpos */
253 complain_overflow_signed,/* complain_on_overflow */
254 bfd_elf_generic_reloc, /* special_function */
255 "R_ARM_SWI8", /* name */
256 FALSE, /* partial_inplace */
257 0x00000000, /* src_mask */
258 0x00000000, /* dst_mask */
259 FALSE), /* pcrel_offset */
261 /* BLX instruction for the ARM. */
262 HOWTO (R_ARM_XPC25, /* type */
263 2, /* rightshift */
264 2, /* size (0 = byte, 1 = short, 2 = long) */
265 25, /* bitsize */
266 TRUE, /* pc_relative */
267 0, /* bitpos */
268 complain_overflow_signed,/* complain_on_overflow */
269 bfd_elf_generic_reloc, /* special_function */
270 "R_ARM_XPC25", /* name */
271 FALSE, /* partial_inplace */
272 0x00ffffff, /* src_mask */
273 0x00ffffff, /* dst_mask */
274 TRUE), /* pcrel_offset */
276 /* BLX instruction for the Thumb. */
277 HOWTO (R_ARM_THM_XPC22, /* type */
278 2, /* rightshift */
279 2, /* size (0 = byte, 1 = short, 2 = long) */
280 22, /* bitsize */
281 TRUE, /* pc_relative */
282 0, /* bitpos */
283 complain_overflow_signed,/* complain_on_overflow */
284 bfd_elf_generic_reloc, /* special_function */
285 "R_ARM_THM_XPC22", /* name */
286 FALSE, /* partial_inplace */
287 0x07ff07ff, /* src_mask */
288 0x07ff07ff, /* dst_mask */
289 TRUE), /* pcrel_offset */
291 /* Dynamic TLS relocations. */
293 HOWTO (R_ARM_TLS_DTPMOD32, /* type */
294 0, /* rightshift */
295 2, /* size (0 = byte, 1 = short, 2 = long) */
296 32, /* bitsize */
297 FALSE, /* pc_relative */
298 0, /* bitpos */
299 complain_overflow_bitfield,/* complain_on_overflow */
300 bfd_elf_generic_reloc, /* special_function */
301 "R_ARM_TLS_DTPMOD32", /* name */
302 TRUE, /* partial_inplace */
303 0xffffffff, /* src_mask */
304 0xffffffff, /* dst_mask */
305 FALSE), /* pcrel_offset */
307 HOWTO (R_ARM_TLS_DTPOFF32, /* type */
308 0, /* rightshift */
309 2, /* size (0 = byte, 1 = short, 2 = long) */
310 32, /* bitsize */
311 FALSE, /* pc_relative */
312 0, /* bitpos */
313 complain_overflow_bitfield,/* complain_on_overflow */
314 bfd_elf_generic_reloc, /* special_function */
315 "R_ARM_TLS_DTPOFF32", /* name */
316 TRUE, /* partial_inplace */
317 0xffffffff, /* src_mask */
318 0xffffffff, /* dst_mask */
319 FALSE), /* pcrel_offset */
321 HOWTO (R_ARM_TLS_TPOFF32, /* type */
322 0, /* rightshift */
323 2, /* size (0 = byte, 1 = short, 2 = long) */
324 32, /* bitsize */
325 FALSE, /* pc_relative */
326 0, /* bitpos */
327 complain_overflow_bitfield,/* complain_on_overflow */
328 bfd_elf_generic_reloc, /* special_function */
329 "R_ARM_TLS_TPOFF32", /* name */
330 TRUE, /* partial_inplace */
331 0xffffffff, /* src_mask */
332 0xffffffff, /* dst_mask */
333 FALSE), /* pcrel_offset */
335 /* Relocs used in ARM Linux */
337 HOWTO (R_ARM_COPY, /* type */
338 0, /* rightshift */
339 2, /* size (0 = byte, 1 = short, 2 = long) */
340 32, /* bitsize */
341 FALSE, /* pc_relative */
342 0, /* bitpos */
343 complain_overflow_bitfield,/* complain_on_overflow */
344 bfd_elf_generic_reloc, /* special_function */
345 "R_ARM_COPY", /* name */
346 TRUE, /* partial_inplace */
347 0xffffffff, /* src_mask */
348 0xffffffff, /* dst_mask */
349 FALSE), /* pcrel_offset */
351 HOWTO (R_ARM_GLOB_DAT, /* type */
352 0, /* rightshift */
353 2, /* size (0 = byte, 1 = short, 2 = long) */
354 32, /* bitsize */
355 FALSE, /* pc_relative */
356 0, /* bitpos */
357 complain_overflow_bitfield,/* complain_on_overflow */
358 bfd_elf_generic_reloc, /* special_function */
359 "R_ARM_GLOB_DAT", /* name */
360 TRUE, /* partial_inplace */
361 0xffffffff, /* src_mask */
362 0xffffffff, /* dst_mask */
363 FALSE), /* pcrel_offset */
365 HOWTO (R_ARM_JUMP_SLOT, /* type */
366 0, /* rightshift */
367 2, /* size (0 = byte, 1 = short, 2 = long) */
368 32, /* bitsize */
369 FALSE, /* pc_relative */
370 0, /* bitpos */
371 complain_overflow_bitfield,/* complain_on_overflow */
372 bfd_elf_generic_reloc, /* special_function */
373 "R_ARM_JUMP_SLOT", /* name */
374 TRUE, /* partial_inplace */
375 0xffffffff, /* src_mask */
376 0xffffffff, /* dst_mask */
377 FALSE), /* pcrel_offset */
379 HOWTO (R_ARM_RELATIVE, /* type */
380 0, /* rightshift */
381 2, /* size (0 = byte, 1 = short, 2 = long) */
382 32, /* bitsize */
383 FALSE, /* pc_relative */
384 0, /* bitpos */
385 complain_overflow_bitfield,/* complain_on_overflow */
386 bfd_elf_generic_reloc, /* special_function */
387 "R_ARM_RELATIVE", /* name */
388 TRUE, /* partial_inplace */
389 0xffffffff, /* src_mask */
390 0xffffffff, /* dst_mask */
391 FALSE), /* pcrel_offset */
393 HOWTO (R_ARM_GOTOFF32, /* type */
394 0, /* rightshift */
395 2, /* size (0 = byte, 1 = short, 2 = long) */
396 32, /* bitsize */
397 FALSE, /* pc_relative */
398 0, /* bitpos */
399 complain_overflow_bitfield,/* complain_on_overflow */
400 bfd_elf_generic_reloc, /* special_function */
401 "R_ARM_GOTOFF32", /* name */
402 TRUE, /* partial_inplace */
403 0xffffffff, /* src_mask */
404 0xffffffff, /* dst_mask */
405 FALSE), /* pcrel_offset */
407 HOWTO (R_ARM_GOTPC, /* type */
408 0, /* rightshift */
409 2, /* size (0 = byte, 1 = short, 2 = long) */
410 32, /* bitsize */
411 TRUE, /* pc_relative */
412 0, /* bitpos */
413 complain_overflow_bitfield,/* complain_on_overflow */
414 bfd_elf_generic_reloc, /* special_function */
415 "R_ARM_GOTPC", /* name */
416 TRUE, /* partial_inplace */
417 0xffffffff, /* src_mask */
418 0xffffffff, /* dst_mask */
419 TRUE), /* pcrel_offset */
421 HOWTO (R_ARM_GOT32, /* type */
422 0, /* rightshift */
423 2, /* size (0 = byte, 1 = short, 2 = long) */
424 32, /* bitsize */
425 FALSE, /* pc_relative */
426 0, /* bitpos */
427 complain_overflow_bitfield,/* complain_on_overflow */
428 bfd_elf_generic_reloc, /* special_function */
429 "R_ARM_GOT32", /* name */
430 TRUE, /* partial_inplace */
431 0xffffffff, /* src_mask */
432 0xffffffff, /* dst_mask */
433 FALSE), /* pcrel_offset */
435 HOWTO (R_ARM_PLT32, /* type */
436 2, /* rightshift */
437 2, /* size (0 = byte, 1 = short, 2 = long) */
438 24, /* bitsize */
439 TRUE, /* pc_relative */
440 0, /* bitpos */
441 complain_overflow_bitfield,/* complain_on_overflow */
442 bfd_elf_generic_reloc, /* special_function */
443 "R_ARM_PLT32", /* name */
444 FALSE, /* partial_inplace */
445 0x00ffffff, /* src_mask */
446 0x00ffffff, /* dst_mask */
447 TRUE), /* pcrel_offset */
449 HOWTO (R_ARM_CALL, /* type */
450 2, /* rightshift */
451 2, /* size (0 = byte, 1 = short, 2 = long) */
452 24, /* bitsize */
453 TRUE, /* pc_relative */
454 0, /* bitpos */
455 complain_overflow_signed,/* complain_on_overflow */
456 bfd_elf_generic_reloc, /* special_function */
457 "R_ARM_CALL", /* name */
458 FALSE, /* partial_inplace */
459 0x00ffffff, /* src_mask */
460 0x00ffffff, /* dst_mask */
461 TRUE), /* pcrel_offset */
463 HOWTO (R_ARM_JUMP24, /* type */
464 2, /* rightshift */
465 2, /* size (0 = byte, 1 = short, 2 = long) */
466 24, /* bitsize */
467 TRUE, /* pc_relative */
468 0, /* bitpos */
469 complain_overflow_signed,/* complain_on_overflow */
470 bfd_elf_generic_reloc, /* special_function */
471 "R_ARM_JUMP24", /* name */
472 FALSE, /* partial_inplace */
473 0x00ffffff, /* src_mask */
474 0x00ffffff, /* dst_mask */
475 TRUE), /* pcrel_offset */
477 HOWTO (R_ARM_THM_JUMP24, /* type */
478 1, /* rightshift */
479 2, /* size (0 = byte, 1 = short, 2 = long) */
480 24, /* bitsize */
481 TRUE, /* pc_relative */
482 0, /* bitpos */
483 complain_overflow_signed,/* complain_on_overflow */
484 bfd_elf_generic_reloc, /* special_function */
485 "R_ARM_THM_JUMP24", /* name */
486 FALSE, /* partial_inplace */
487 0x07ff2fff, /* src_mask */
488 0x07ff2fff, /* dst_mask */
489 TRUE), /* pcrel_offset */
491 HOWTO (R_ARM_BASE_ABS, /* type */
492 0, /* rightshift */
493 2, /* size (0 = byte, 1 = short, 2 = long) */
494 32, /* bitsize */
495 FALSE, /* pc_relative */
496 0, /* bitpos */
497 complain_overflow_dont,/* complain_on_overflow */
498 bfd_elf_generic_reloc, /* special_function */
499 "R_ARM_BASE_ABS", /* name */
500 FALSE, /* partial_inplace */
501 0xffffffff, /* src_mask */
502 0xffffffff, /* dst_mask */
503 FALSE), /* pcrel_offset */
505 HOWTO (R_ARM_ALU_PCREL7_0, /* type */
506 0, /* rightshift */
507 2, /* size (0 = byte, 1 = short, 2 = long) */
508 12, /* bitsize */
509 TRUE, /* pc_relative */
510 0, /* bitpos */
511 complain_overflow_dont,/* complain_on_overflow */
512 bfd_elf_generic_reloc, /* special_function */
513 "R_ARM_ALU_PCREL_7_0", /* name */
514 FALSE, /* partial_inplace */
515 0x00000fff, /* src_mask */
516 0x00000fff, /* dst_mask */
517 TRUE), /* pcrel_offset */
519 HOWTO (R_ARM_ALU_PCREL15_8, /* type */
520 0, /* rightshift */
521 2, /* size (0 = byte, 1 = short, 2 = long) */
522 12, /* bitsize */
523 TRUE, /* pc_relative */
524 8, /* bitpos */
525 complain_overflow_dont,/* complain_on_overflow */
526 bfd_elf_generic_reloc, /* special_function */
527 "R_ARM_ALU_PCREL_15_8",/* name */
528 FALSE, /* partial_inplace */
529 0x00000fff, /* src_mask */
530 0x00000fff, /* dst_mask */
531 TRUE), /* pcrel_offset */
533 HOWTO (R_ARM_ALU_PCREL23_15, /* type */
534 0, /* rightshift */
535 2, /* size (0 = byte, 1 = short, 2 = long) */
536 12, /* bitsize */
537 TRUE, /* pc_relative */
538 16, /* bitpos */
539 complain_overflow_dont,/* complain_on_overflow */
540 bfd_elf_generic_reloc, /* special_function */
541 "R_ARM_ALU_PCREL_23_15",/* name */
542 FALSE, /* partial_inplace */
543 0x00000fff, /* src_mask */
544 0x00000fff, /* dst_mask */
545 TRUE), /* pcrel_offset */
547 HOWTO (R_ARM_LDR_SBREL_11_0, /* type */
548 0, /* rightshift */
549 2, /* size (0 = byte, 1 = short, 2 = long) */
550 12, /* bitsize */
551 FALSE, /* pc_relative */
552 0, /* bitpos */
553 complain_overflow_dont,/* complain_on_overflow */
554 bfd_elf_generic_reloc, /* special_function */
555 "R_ARM_LDR_SBREL_11_0",/* name */
556 FALSE, /* partial_inplace */
557 0x00000fff, /* src_mask */
558 0x00000fff, /* dst_mask */
559 FALSE), /* pcrel_offset */
561 HOWTO (R_ARM_ALU_SBREL_19_12, /* type */
562 0, /* rightshift */
563 2, /* size (0 = byte, 1 = short, 2 = long) */
564 8, /* bitsize */
565 FALSE, /* pc_relative */
566 12, /* bitpos */
567 complain_overflow_dont,/* complain_on_overflow */
568 bfd_elf_generic_reloc, /* special_function */
569 "R_ARM_ALU_SBREL_19_12",/* name */
570 FALSE, /* partial_inplace */
571 0x000ff000, /* src_mask */
572 0x000ff000, /* dst_mask */
573 FALSE), /* pcrel_offset */
575 HOWTO (R_ARM_ALU_SBREL_27_20, /* type */
576 0, /* rightshift */
577 2, /* size (0 = byte, 1 = short, 2 = long) */
578 8, /* bitsize */
579 FALSE, /* pc_relative */
580 20, /* bitpos */
581 complain_overflow_dont,/* complain_on_overflow */
582 bfd_elf_generic_reloc, /* special_function */
583 "R_ARM_ALU_SBREL_27_20",/* name */
584 FALSE, /* partial_inplace */
585 0x0ff00000, /* src_mask */
586 0x0ff00000, /* dst_mask */
587 FALSE), /* pcrel_offset */
589 HOWTO (R_ARM_TARGET1, /* type */
590 0, /* rightshift */
591 2, /* size (0 = byte, 1 = short, 2 = long) */
592 32, /* bitsize */
593 FALSE, /* pc_relative */
594 0, /* bitpos */
595 complain_overflow_dont,/* complain_on_overflow */
596 bfd_elf_generic_reloc, /* special_function */
597 "R_ARM_TARGET1", /* name */
598 FALSE, /* partial_inplace */
599 0xffffffff, /* src_mask */
600 0xffffffff, /* dst_mask */
601 FALSE), /* pcrel_offset */
603 HOWTO (R_ARM_ROSEGREL32, /* type */
604 0, /* rightshift */
605 2, /* size (0 = byte, 1 = short, 2 = long) */
606 32, /* bitsize */
607 FALSE, /* pc_relative */
608 0, /* bitpos */
609 complain_overflow_dont,/* complain_on_overflow */
610 bfd_elf_generic_reloc, /* special_function */
611 "R_ARM_ROSEGREL32", /* name */
612 FALSE, /* partial_inplace */
613 0xffffffff, /* src_mask */
614 0xffffffff, /* dst_mask */
615 FALSE), /* pcrel_offset */
617 HOWTO (R_ARM_V4BX, /* type */
618 0, /* rightshift */
619 2, /* size (0 = byte, 1 = short, 2 = long) */
620 32, /* bitsize */
621 FALSE, /* pc_relative */
622 0, /* bitpos */
623 complain_overflow_dont,/* complain_on_overflow */
624 bfd_elf_generic_reloc, /* special_function */
625 "R_ARM_V4BX", /* name */
626 FALSE, /* partial_inplace */
627 0xffffffff, /* src_mask */
628 0xffffffff, /* dst_mask */
629 FALSE), /* pcrel_offset */
631 HOWTO (R_ARM_TARGET2, /* type */
632 0, /* rightshift */
633 2, /* size (0 = byte, 1 = short, 2 = long) */
634 32, /* bitsize */
635 FALSE, /* pc_relative */
636 0, /* bitpos */
637 complain_overflow_signed,/* complain_on_overflow */
638 bfd_elf_generic_reloc, /* special_function */
639 "R_ARM_TARGET2", /* name */
640 FALSE, /* partial_inplace */
641 0xffffffff, /* src_mask */
642 0xffffffff, /* dst_mask */
643 TRUE), /* pcrel_offset */
645 HOWTO (R_ARM_PREL31, /* type */
646 0, /* rightshift */
647 2, /* size (0 = byte, 1 = short, 2 = long) */
648 31, /* bitsize */
649 TRUE, /* pc_relative */
650 0, /* bitpos */
651 complain_overflow_signed,/* complain_on_overflow */
652 bfd_elf_generic_reloc, /* special_function */
653 "R_ARM_PREL31", /* name */
654 FALSE, /* partial_inplace */
655 0x7fffffff, /* src_mask */
656 0x7fffffff, /* dst_mask */
657 TRUE), /* pcrel_offset */
659 HOWTO (R_ARM_MOVW_ABS_NC, /* type */
660 0, /* rightshift */
661 2, /* size (0 = byte, 1 = short, 2 = long) */
662 16, /* bitsize */
663 FALSE, /* pc_relative */
664 0, /* bitpos */
665 complain_overflow_dont,/* complain_on_overflow */
666 bfd_elf_generic_reloc, /* special_function */
667 "R_ARM_MOVW_ABS_NC", /* name */
668 FALSE, /* partial_inplace */
669 0x0000ffff, /* src_mask */
670 0x0000ffff, /* dst_mask */
671 FALSE), /* pcrel_offset */
673 HOWTO (R_ARM_MOVT_ABS, /* type */
674 0, /* rightshift */
675 2, /* size (0 = byte, 1 = short, 2 = long) */
676 16, /* bitsize */
677 FALSE, /* pc_relative */
678 0, /* bitpos */
679 complain_overflow_bitfield,/* complain_on_overflow */
680 bfd_elf_generic_reloc, /* special_function */
681 "R_ARM_MOVT_ABS", /* name */
682 FALSE, /* partial_inplace */
683 0x0000ffff, /* src_mask */
684 0x0000ffff, /* dst_mask */
685 FALSE), /* pcrel_offset */
687 HOWTO (R_ARM_MOVW_PREL_NC, /* type */
688 0, /* rightshift */
689 2, /* size (0 = byte, 1 = short, 2 = long) */
690 16, /* bitsize */
691 TRUE, /* pc_relative */
692 0, /* bitpos */
693 complain_overflow_dont,/* complain_on_overflow */
694 bfd_elf_generic_reloc, /* special_function */
695 "R_ARM_MOVW_PREL_NC", /* name */
696 FALSE, /* partial_inplace */
697 0x0000ffff, /* src_mask */
698 0x0000ffff, /* dst_mask */
699 TRUE), /* pcrel_offset */
701 HOWTO (R_ARM_MOVT_PREL, /* type */
702 0, /* rightshift */
703 2, /* size (0 = byte, 1 = short, 2 = long) */
704 16, /* bitsize */
705 TRUE, /* pc_relative */
706 0, /* bitpos */
707 complain_overflow_bitfield,/* complain_on_overflow */
708 bfd_elf_generic_reloc, /* special_function */
709 "R_ARM_MOVT_PREL", /* name */
710 FALSE, /* partial_inplace */
711 0x0000ffff, /* src_mask */
712 0x0000ffff, /* dst_mask */
713 TRUE), /* pcrel_offset */
715 HOWTO (R_ARM_THM_MOVW_ABS_NC, /* type */
716 0, /* rightshift */
717 2, /* size (0 = byte, 1 = short, 2 = long) */
718 16, /* bitsize */
719 FALSE, /* pc_relative */
720 0, /* bitpos */
721 complain_overflow_dont,/* complain_on_overflow */
722 bfd_elf_generic_reloc, /* special_function */
723 "R_ARM_THM_MOVW_ABS_NC",/* name */
724 FALSE, /* partial_inplace */
725 0x040f70ff, /* src_mask */
726 0x040f70ff, /* dst_mask */
727 FALSE), /* pcrel_offset */
729 HOWTO (R_ARM_THM_MOVT_ABS, /* type */
730 0, /* rightshift */
731 2, /* size (0 = byte, 1 = short, 2 = long) */
732 16, /* bitsize */
733 FALSE, /* pc_relative */
734 0, /* bitpos */
735 complain_overflow_bitfield,/* complain_on_overflow */
736 bfd_elf_generic_reloc, /* special_function */
737 "R_ARM_THM_MOVT_ABS", /* name */
738 FALSE, /* partial_inplace */
739 0x040f70ff, /* src_mask */
740 0x040f70ff, /* dst_mask */
741 FALSE), /* pcrel_offset */
743 HOWTO (R_ARM_THM_MOVW_PREL_NC,/* type */
744 0, /* rightshift */
745 2, /* size (0 = byte, 1 = short, 2 = long) */
746 16, /* bitsize */
747 TRUE, /* pc_relative */
748 0, /* bitpos */
749 complain_overflow_dont,/* complain_on_overflow */
750 bfd_elf_generic_reloc, /* special_function */
751 "R_ARM_THM_MOVW_PREL_NC",/* name */
752 FALSE, /* partial_inplace */
753 0x040f70ff, /* src_mask */
754 0x040f70ff, /* dst_mask */
755 TRUE), /* pcrel_offset */
757 HOWTO (R_ARM_THM_MOVT_PREL, /* type */
758 0, /* rightshift */
759 2, /* size (0 = byte, 1 = short, 2 = long) */
760 16, /* bitsize */
761 TRUE, /* pc_relative */
762 0, /* bitpos */
763 complain_overflow_bitfield,/* complain_on_overflow */
764 bfd_elf_generic_reloc, /* special_function */
765 "R_ARM_THM_MOVT_PREL", /* name */
766 FALSE, /* partial_inplace */
767 0x040f70ff, /* src_mask */
768 0x040f70ff, /* dst_mask */
769 TRUE), /* pcrel_offset */
771 HOWTO (R_ARM_THM_JUMP19, /* type */
772 1, /* rightshift */
773 2, /* size (0 = byte, 1 = short, 2 = long) */
774 19, /* bitsize */
775 TRUE, /* pc_relative */
776 0, /* bitpos */
777 complain_overflow_signed,/* complain_on_overflow */
778 bfd_elf_generic_reloc, /* special_function */
779 "R_ARM_THM_JUMP19", /* name */
780 FALSE, /* partial_inplace */
781 0x043f2fff, /* src_mask */
782 0x043f2fff, /* dst_mask */
783 TRUE), /* pcrel_offset */
785 HOWTO (R_ARM_THM_JUMP6, /* type */
786 1, /* rightshift */
787 1, /* size (0 = byte, 1 = short, 2 = long) */
788 6, /* bitsize */
789 TRUE, /* pc_relative */
790 0, /* bitpos */
791 complain_overflow_unsigned,/* complain_on_overflow */
792 bfd_elf_generic_reloc, /* special_function */
793 "R_ARM_THM_JUMP6", /* name */
794 FALSE, /* partial_inplace */
795 0x02f8, /* src_mask */
796 0x02f8, /* dst_mask */
797 TRUE), /* pcrel_offset */
799 /* These are declared as 13-bit signed relocations because we can
800 address -4095 .. 4095(base) by altering ADDW to SUBW or vice
801 versa. */
802 HOWTO (R_ARM_THM_ALU_PREL_11_0,/* type */
803 0, /* rightshift */
804 2, /* size (0 = byte, 1 = short, 2 = long) */
805 13, /* bitsize */
806 TRUE, /* pc_relative */
807 0, /* bitpos */
808 complain_overflow_signed,/* complain_on_overflow */
809 bfd_elf_generic_reloc, /* special_function */
810 "R_ARM_THM_ALU_PREL_11_0",/* name */
811 FALSE, /* partial_inplace */
812 0x040070ff, /* src_mask */
813 0x040070ff, /* dst_mask */
814 TRUE), /* pcrel_offset */
816 HOWTO (R_ARM_THM_PC12, /* type */
817 0, /* rightshift */
818 2, /* size (0 = byte, 1 = short, 2 = long) */
819 13, /* bitsize */
820 TRUE, /* pc_relative */
821 0, /* bitpos */
822 complain_overflow_signed,/* complain_on_overflow */
823 bfd_elf_generic_reloc, /* special_function */
824 "R_ARM_THM_PC12", /* name */
825 FALSE, /* partial_inplace */
826 0x040070ff, /* src_mask */
827 0x040070ff, /* dst_mask */
828 TRUE), /* pcrel_offset */
830 HOWTO (R_ARM_ABS32_NOI, /* type */
831 0, /* rightshift */
832 2, /* size (0 = byte, 1 = short, 2 = long) */
833 32, /* bitsize */
834 FALSE, /* pc_relative */
835 0, /* bitpos */
836 complain_overflow_dont,/* complain_on_overflow */
837 bfd_elf_generic_reloc, /* special_function */
838 "R_ARM_ABS32_NOI", /* name */
839 FALSE, /* partial_inplace */
840 0xffffffff, /* src_mask */
841 0xffffffff, /* dst_mask */
842 FALSE), /* pcrel_offset */
844 HOWTO (R_ARM_REL32_NOI, /* type */
845 0, /* rightshift */
846 2, /* size (0 = byte, 1 = short, 2 = long) */
847 32, /* bitsize */
848 TRUE, /* pc_relative */
849 0, /* bitpos */
850 complain_overflow_dont,/* complain_on_overflow */
851 bfd_elf_generic_reloc, /* special_function */
852 "R_ARM_REL32_NOI", /* name */
853 FALSE, /* partial_inplace */
854 0xffffffff, /* src_mask */
855 0xffffffff, /* dst_mask */
856 FALSE), /* pcrel_offset */
859 /* Relocations 57 .. 83 are the "group relocations" which we do not
860 support. */
862 static reloc_howto_type elf32_arm_howto_table_2[] =
864 HOWTO (R_ARM_MOVW_BREL_NC, /* type */
865 0, /* rightshift */
866 2, /* size (0 = byte, 1 = short, 2 = long) */
867 16, /* bitsize */
868 FALSE, /* pc_relative */
869 0, /* bitpos */
870 complain_overflow_dont,/* complain_on_overflow */
871 bfd_elf_generic_reloc, /* special_function */
872 "R_ARM_MOVW_BREL_NC", /* name */
873 FALSE, /* partial_inplace */
874 0x0000ffff, /* src_mask */
875 0x0000ffff, /* dst_mask */
876 FALSE), /* pcrel_offset */
878 HOWTO (R_ARM_MOVT_BREL, /* type */
879 0, /* rightshift */
880 2, /* size (0 = byte, 1 = short, 2 = long) */
881 16, /* bitsize */
882 FALSE, /* pc_relative */
883 0, /* bitpos */
884 complain_overflow_bitfield,/* complain_on_overflow */
885 bfd_elf_generic_reloc, /* special_function */
886 "R_ARM_MOVT_BREL", /* name */
887 FALSE, /* partial_inplace */
888 0x0000ffff, /* src_mask */
889 0x0000ffff, /* dst_mask */
890 FALSE), /* pcrel_offset */
892 HOWTO (R_ARM_MOVW_BREL, /* type */
893 0, /* rightshift */
894 2, /* size (0 = byte, 1 = short, 2 = long) */
895 16, /* bitsize */
896 FALSE, /* pc_relative */
897 0, /* bitpos */
898 complain_overflow_dont,/* complain_on_overflow */
899 bfd_elf_generic_reloc, /* special_function */
900 "R_ARM_MOVW_BREL", /* name */
901 FALSE, /* partial_inplace */
902 0x0000ffff, /* src_mask */
903 0x0000ffff, /* dst_mask */
904 FALSE), /* pcrel_offset */
906 HOWTO (R_ARM_THM_MOVW_BREL_NC,/* type */
907 0, /* rightshift */
908 2, /* size (0 = byte, 1 = short, 2 = long) */
909 16, /* bitsize */
910 FALSE, /* pc_relative */
911 0, /* bitpos */
912 complain_overflow_dont,/* complain_on_overflow */
913 bfd_elf_generic_reloc, /* special_function */
914 "R_ARM_THM_MOVW_BREL_NC",/* name */
915 FALSE, /* partial_inplace */
916 0x040f70ff, /* src_mask */
917 0x040f70ff, /* dst_mask */
918 FALSE), /* pcrel_offset */
920 HOWTO (R_ARM_THM_MOVT_BREL, /* type */
921 0, /* rightshift */
922 2, /* size (0 = byte, 1 = short, 2 = long) */
923 16, /* bitsize */
924 FALSE, /* pc_relative */
925 0, /* bitpos */
926 complain_overflow_bitfield,/* complain_on_overflow */
927 bfd_elf_generic_reloc, /* special_function */
928 "R_ARM_THM_MOVT_BREL", /* name */
929 FALSE, /* partial_inplace */
930 0x040f70ff, /* src_mask */
931 0x040f70ff, /* dst_mask */
932 FALSE), /* pcrel_offset */
934 HOWTO (R_ARM_THM_MOVW_BREL, /* type */
935 0, /* rightshift */
936 2, /* size (0 = byte, 1 = short, 2 = long) */
937 16, /* bitsize */
938 FALSE, /* pc_relative */
939 0, /* bitpos */
940 complain_overflow_dont,/* complain_on_overflow */
941 bfd_elf_generic_reloc, /* special_function */
942 "R_ARM_THM_MOVW_BREL", /* name */
943 FALSE, /* partial_inplace */
944 0x040f70ff, /* src_mask */
945 0x040f70ff, /* dst_mask */
946 FALSE), /* pcrel_offset */
948 EMPTY_HOWTO (90), /* unallocated */
949 EMPTY_HOWTO (91),
950 EMPTY_HOWTO (92),
951 EMPTY_HOWTO (93),
953 HOWTO (R_ARM_PLT32_ABS, /* type */
954 0, /* rightshift */
955 2, /* size (0 = byte, 1 = short, 2 = long) */
956 32, /* bitsize */
957 FALSE, /* pc_relative */
958 0, /* bitpos */
959 complain_overflow_dont,/* complain_on_overflow */
960 bfd_elf_generic_reloc, /* special_function */
961 "R_ARM_PLT32_ABS", /* name */
962 FALSE, /* partial_inplace */
963 0xffffffff, /* src_mask */
964 0xffffffff, /* dst_mask */
965 FALSE), /* pcrel_offset */
967 HOWTO (R_ARM_GOT_ABS, /* type */
968 0, /* rightshift */
969 2, /* size (0 = byte, 1 = short, 2 = long) */
970 32, /* bitsize */
971 FALSE, /* pc_relative */
972 0, /* bitpos */
973 complain_overflow_dont,/* complain_on_overflow */
974 bfd_elf_generic_reloc, /* special_function */
975 "R_ARM_GOT_ABS", /* name */
976 FALSE, /* partial_inplace */
977 0xffffffff, /* src_mask */
978 0xffffffff, /* dst_mask */
979 FALSE), /* pcrel_offset */
981 HOWTO (R_ARM_GOT_PREL, /* type */
982 0, /* rightshift */
983 2, /* size (0 = byte, 1 = short, 2 = long) */
984 32, /* bitsize */
985 TRUE, /* pc_relative */
986 0, /* bitpos */
987 complain_overflow_dont, /* complain_on_overflow */
988 bfd_elf_generic_reloc, /* special_function */
989 "R_ARM_GOT_PREL", /* name */
990 FALSE, /* partial_inplace */
991 0xffffffff, /* src_mask */
992 0xffffffff, /* dst_mask */
993 TRUE), /* pcrel_offset */
995 HOWTO (R_ARM_GOT_BREL12, /* type */
996 0, /* rightshift */
997 2, /* size (0 = byte, 1 = short, 2 = long) */
998 12, /* bitsize */
999 FALSE, /* pc_relative */
1000 0, /* bitpos */
1001 complain_overflow_bitfield,/* complain_on_overflow */
1002 bfd_elf_generic_reloc, /* special_function */
1003 "R_ARM_GOT_BREL12", /* name */
1004 FALSE, /* partial_inplace */
1005 0x00000fff, /* src_mask */
1006 0x00000fff, /* dst_mask */
1007 FALSE), /* pcrel_offset */
1009 HOWTO (R_ARM_GOTOFF12, /* type */
1010 0, /* rightshift */
1011 2, /* size (0 = byte, 1 = short, 2 = long) */
1012 12, /* bitsize */
1013 FALSE, /* pc_relative */
1014 0, /* bitpos */
1015 complain_overflow_bitfield,/* complain_on_overflow */
1016 bfd_elf_generic_reloc, /* special_function */
1017 "R_ARM_GOTOFF12", /* name */
1018 FALSE, /* partial_inplace */
1019 0x00000fff, /* src_mask */
1020 0x00000fff, /* dst_mask */
1021 FALSE), /* pcrel_offset */
1023 EMPTY_HOWTO (R_ARM_GOTRELAX), /* reserved for future GOT-load optimizations */
1025 /* GNU extension to record C++ vtable member usage */
1026 HOWTO (R_ARM_GNU_VTENTRY, /* type */
1027 0, /* rightshift */
1028 2, /* size (0 = byte, 1 = short, 2 = long) */
1029 0, /* bitsize */
1030 FALSE, /* pc_relative */
1031 0, /* bitpos */
1032 complain_overflow_dont, /* complain_on_overflow */
1033 _bfd_elf_rel_vtable_reloc_fn, /* special_function */
1034 "R_ARM_GNU_VTENTRY", /* name */
1035 FALSE, /* partial_inplace */
1036 0, /* src_mask */
1037 0, /* dst_mask */
1038 FALSE), /* pcrel_offset */
1040 /* GNU extension to record C++ vtable hierarchy */
1041 HOWTO (R_ARM_GNU_VTINHERIT, /* type */
1042 0, /* rightshift */
1043 2, /* size (0 = byte, 1 = short, 2 = long) */
1044 0, /* bitsize */
1045 FALSE, /* pc_relative */
1046 0, /* bitpos */
1047 complain_overflow_dont, /* complain_on_overflow */
1048 NULL, /* special_function */
1049 "R_ARM_GNU_VTINHERIT", /* name */
1050 FALSE, /* partial_inplace */
1051 0, /* src_mask */
1052 0, /* dst_mask */
1053 FALSE), /* pcrel_offset */
1055 HOWTO (R_ARM_THM_JUMP11, /* type */
1056 1, /* rightshift */
1057 1, /* size (0 = byte, 1 = short, 2 = long) */
1058 11, /* bitsize */
1059 TRUE, /* pc_relative */
1060 0, /* bitpos */
1061 complain_overflow_signed, /* complain_on_overflow */
1062 bfd_elf_generic_reloc, /* special_function */
1063 "R_ARM_THM_JUMP11", /* name */
1064 FALSE, /* partial_inplace */
1065 0x000007ff, /* src_mask */
1066 0x000007ff, /* dst_mask */
1067 TRUE), /* pcrel_offset */
1069 HOWTO (R_ARM_THM_JUMP8, /* type */
1070 1, /* rightshift */
1071 1, /* size (0 = byte, 1 = short, 2 = long) */
1072 8, /* bitsize */
1073 TRUE, /* pc_relative */
1074 0, /* bitpos */
1075 complain_overflow_signed, /* complain_on_overflow */
1076 bfd_elf_generic_reloc, /* special_function */
1077 "R_ARM_THM_JUMP8", /* name */
1078 FALSE, /* partial_inplace */
1079 0x000000ff, /* src_mask */
1080 0x000000ff, /* dst_mask */
1081 TRUE), /* pcrel_offset */
1083 /* TLS relocations */
1084 HOWTO (R_ARM_TLS_GD32, /* type */
1085 0, /* rightshift */
1086 2, /* size (0 = byte, 1 = short, 2 = long) */
1087 32, /* bitsize */
1088 FALSE, /* pc_relative */
1089 0, /* bitpos */
1090 complain_overflow_bitfield,/* complain_on_overflow */
1091 NULL, /* special_function */
1092 "R_ARM_TLS_GD32", /* name */
1093 TRUE, /* partial_inplace */
1094 0xffffffff, /* src_mask */
1095 0xffffffff, /* dst_mask */
1096 FALSE), /* pcrel_offset */
1098 HOWTO (R_ARM_TLS_LDM32, /* type */
1099 0, /* rightshift */
1100 2, /* size (0 = byte, 1 = short, 2 = long) */
1101 32, /* bitsize */
1102 FALSE, /* pc_relative */
1103 0, /* bitpos */
1104 complain_overflow_bitfield,/* complain_on_overflow */
1105 bfd_elf_generic_reloc, /* special_function */
1106 "R_ARM_TLS_LDM32", /* name */
1107 TRUE, /* partial_inplace */
1108 0xffffffff, /* src_mask */
1109 0xffffffff, /* dst_mask */
1110 FALSE), /* pcrel_offset */
1112 HOWTO (R_ARM_TLS_LDO32, /* type */
1113 0, /* rightshift */
1114 2, /* size (0 = byte, 1 = short, 2 = long) */
1115 32, /* bitsize */
1116 FALSE, /* pc_relative */
1117 0, /* bitpos */
1118 complain_overflow_bitfield,/* complain_on_overflow */
1119 bfd_elf_generic_reloc, /* special_function */
1120 "R_ARM_TLS_LDO32", /* name */
1121 TRUE, /* partial_inplace */
1122 0xffffffff, /* src_mask */
1123 0xffffffff, /* dst_mask */
1124 FALSE), /* pcrel_offset */
1126 HOWTO (R_ARM_TLS_IE32, /* type */
1127 0, /* rightshift */
1128 2, /* size (0 = byte, 1 = short, 2 = long) */
1129 32, /* bitsize */
1130 FALSE, /* pc_relative */
1131 0, /* bitpos */
1132 complain_overflow_bitfield,/* complain_on_overflow */
1133 NULL, /* special_function */
1134 "R_ARM_TLS_IE32", /* name */
1135 TRUE, /* partial_inplace */
1136 0xffffffff, /* src_mask */
1137 0xffffffff, /* dst_mask */
1138 FALSE), /* pcrel_offset */
1140 HOWTO (R_ARM_TLS_LE32, /* type */
1141 0, /* rightshift */
1142 2, /* size (0 = byte, 1 = short, 2 = long) */
1143 32, /* bitsize */
1144 FALSE, /* pc_relative */
1145 0, /* bitpos */
1146 complain_overflow_bitfield,/* complain_on_overflow */
1147 bfd_elf_generic_reloc, /* special_function */
1148 "R_ARM_TLS_LE32", /* name */
1149 TRUE, /* partial_inplace */
1150 0xffffffff, /* src_mask */
1151 0xffffffff, /* dst_mask */
1152 FALSE), /* pcrel_offset */
1154 HOWTO (R_ARM_TLS_LDO12, /* type */
1155 0, /* rightshift */
1156 2, /* size (0 = byte, 1 = short, 2 = long) */
1157 12, /* bitsize */
1158 FALSE, /* pc_relative */
1159 0, /* bitpos */
1160 complain_overflow_bitfield,/* complain_on_overflow */
1161 bfd_elf_generic_reloc, /* special_function */
1162 "R_ARM_TLS_LDO12", /* name */
1163 FALSE, /* partial_inplace */
1164 0x00000fff, /* src_mask */
1165 0x00000fff, /* dst_mask */
1166 FALSE), /* pcrel_offset */
1168 HOWTO (R_ARM_TLS_LE12, /* type */
1169 0, /* rightshift */
1170 2, /* size (0 = byte, 1 = short, 2 = long) */
1171 12, /* bitsize */
1172 FALSE, /* pc_relative */
1173 0, /* bitpos */
1174 complain_overflow_bitfield,/* complain_on_overflow */
1175 bfd_elf_generic_reloc, /* special_function */
1176 "R_ARM_TLS_LE12", /* name */
1177 FALSE, /* partial_inplace */
1178 0x00000fff, /* src_mask */
1179 0x00000fff, /* dst_mask */
1180 FALSE), /* pcrel_offset */
1182 HOWTO (R_ARM_TLS_IE12GP, /* type */
1183 0, /* rightshift */
1184 2, /* size (0 = byte, 1 = short, 2 = long) */
1185 12, /* bitsize */
1186 FALSE, /* pc_relative */
1187 0, /* bitpos */
1188 complain_overflow_bitfield,/* complain_on_overflow */
1189 bfd_elf_generic_reloc, /* special_function */
1190 "R_ARM_TLS_IE12GP", /* name */
1191 FALSE, /* partial_inplace */
1192 0x00000fff, /* src_mask */
1193 0x00000fff, /* dst_mask */
1194 FALSE), /* pcrel_offset */
1197 /* 112-127 private relocations
1198 128 R_ARM_ME_TOO, obsolete
1199 129-255 unallocated in AAELF.
1201 249-255 extended, currently unused, relocations: */
1203 static reloc_howto_type elf32_arm_howto_table_3[4] =
1205 HOWTO (R_ARM_RREL32, /* type */
1206 0, /* rightshift */
1207 0, /* size (0 = byte, 1 = short, 2 = long) */
1208 0, /* bitsize */
1209 FALSE, /* pc_relative */
1210 0, /* bitpos */
1211 complain_overflow_dont,/* complain_on_overflow */
1212 bfd_elf_generic_reloc, /* special_function */
1213 "R_ARM_RREL32", /* name */
1214 FALSE, /* partial_inplace */
1215 0, /* src_mask */
1216 0, /* dst_mask */
1217 FALSE), /* pcrel_offset */
1219 HOWTO (R_ARM_RABS32, /* type */
1220 0, /* rightshift */
1221 0, /* size (0 = byte, 1 = short, 2 = long) */
1222 0, /* bitsize */
1223 FALSE, /* pc_relative */
1224 0, /* bitpos */
1225 complain_overflow_dont,/* complain_on_overflow */
1226 bfd_elf_generic_reloc, /* special_function */
1227 "R_ARM_RABS32", /* name */
1228 FALSE, /* partial_inplace */
1229 0, /* src_mask */
1230 0, /* dst_mask */
1231 FALSE), /* pcrel_offset */
1233 HOWTO (R_ARM_RPC24, /* type */
1234 0, /* rightshift */
1235 0, /* size (0 = byte, 1 = short, 2 = long) */
1236 0, /* bitsize */
1237 FALSE, /* pc_relative */
1238 0, /* bitpos */
1239 complain_overflow_dont,/* complain_on_overflow */
1240 bfd_elf_generic_reloc, /* special_function */
1241 "R_ARM_RPC24", /* name */
1242 FALSE, /* partial_inplace */
1243 0, /* src_mask */
1244 0, /* dst_mask */
1245 FALSE), /* pcrel_offset */
1247 HOWTO (R_ARM_RBASE, /* type */
1248 0, /* rightshift */
1249 0, /* size (0 = byte, 1 = short, 2 = long) */
1250 0, /* bitsize */
1251 FALSE, /* pc_relative */
1252 0, /* bitpos */
1253 complain_overflow_dont,/* complain_on_overflow */
1254 bfd_elf_generic_reloc, /* special_function */
1255 "R_ARM_RBASE", /* name */
1256 FALSE, /* partial_inplace */
1257 0, /* src_mask */
1258 0, /* dst_mask */
1259 FALSE) /* pcrel_offset */
1262 static reloc_howto_type *
1263 elf32_arm_howto_from_type (unsigned int r_type)
1265 if (r_type < NUM_ELEM (elf32_arm_howto_table_1))
1266 return &elf32_arm_howto_table_1[r_type];
1268 if (r_type >= R_ARM_MOVW_BREL_NC
1269 && r_type < R_ARM_MOVW_BREL_NC + NUM_ELEM (elf32_arm_howto_table_2))
1270 return &elf32_arm_howto_table_2[r_type - R_ARM_MOVW_BREL_NC];
1272 if (r_type >= R_ARM_RREL32
1273 && r_type < R_ARM_RREL32 + NUM_ELEM (elf32_arm_howto_table_2))
1274 return &elf32_arm_howto_table_3[r_type - R_ARM_RREL32];
1276 return NULL;
1279 static void
1280 elf32_arm_info_to_howto (bfd * abfd ATTRIBUTE_UNUSED, arelent * bfd_reloc,
1281 Elf_Internal_Rela * elf_reloc)
1283 unsigned int r_type;
1285 r_type = ELF32_R_TYPE (elf_reloc->r_info);
1286 bfd_reloc->howto = elf32_arm_howto_from_type (r_type);
1289 struct elf32_arm_reloc_map
1291 bfd_reloc_code_real_type bfd_reloc_val;
1292 unsigned char elf_reloc_val;
1295 /* All entries in this list must also be present in elf32_arm_howto_table. */
1296 static const struct elf32_arm_reloc_map elf32_arm_reloc_map[] =
1298 {BFD_RELOC_NONE, R_ARM_NONE},
1299 {BFD_RELOC_ARM_PCREL_BRANCH, R_ARM_PC24},
1300 {BFD_RELOC_ARM_PCREL_BLX, R_ARM_XPC25},
1301 {BFD_RELOC_THUMB_PCREL_BLX, R_ARM_THM_XPC22},
1302 {BFD_RELOC_32, R_ARM_ABS32},
1303 {BFD_RELOC_32_PCREL, R_ARM_REL32},
1304 {BFD_RELOC_8, R_ARM_ABS8},
1305 {BFD_RELOC_16, R_ARM_ABS16},
1306 {BFD_RELOC_ARM_OFFSET_IMM, R_ARM_ABS12},
1307 {BFD_RELOC_ARM_THUMB_OFFSET, R_ARM_THM_ABS5},
1308 {BFD_RELOC_THUMB_PCREL_BRANCH25, R_ARM_THM_JUMP24},
1309 {BFD_RELOC_THUMB_PCREL_BRANCH23, R_ARM_THM_CALL},
1310 {BFD_RELOC_THUMB_PCREL_BRANCH12, R_ARM_THM_JUMP11},
1311 {BFD_RELOC_THUMB_PCREL_BRANCH20, R_ARM_THM_JUMP19},
1312 {BFD_RELOC_THUMB_PCREL_BRANCH9, R_ARM_THM_JUMP8},
1313 {BFD_RELOC_THUMB_PCREL_BRANCH7, R_ARM_THM_JUMP6},
1314 {BFD_RELOC_ARM_GLOB_DAT, R_ARM_GLOB_DAT},
1315 {BFD_RELOC_ARM_JUMP_SLOT, R_ARM_JUMP_SLOT},
1316 {BFD_RELOC_ARM_RELATIVE, R_ARM_RELATIVE},
1317 {BFD_RELOC_ARM_GOTOFF, R_ARM_GOTOFF32},
1318 {BFD_RELOC_ARM_GOTPC, R_ARM_GOTPC},
1319 {BFD_RELOC_ARM_GOT32, R_ARM_GOT32},
1320 {BFD_RELOC_ARM_PLT32, R_ARM_PLT32},
1321 {BFD_RELOC_ARM_TARGET1, R_ARM_TARGET1},
1322 {BFD_RELOC_ARM_ROSEGREL32, R_ARM_ROSEGREL32},
1323 {BFD_RELOC_ARM_SBREL32, R_ARM_SBREL32},
1324 {BFD_RELOC_ARM_PREL31, R_ARM_PREL31},
1325 {BFD_RELOC_ARM_TARGET2, R_ARM_TARGET2},
1326 {BFD_RELOC_ARM_PLT32, R_ARM_PLT32},
1327 {BFD_RELOC_ARM_TLS_GD32, R_ARM_TLS_GD32},
1328 {BFD_RELOC_ARM_TLS_LDO32, R_ARM_TLS_LDO32},
1329 {BFD_RELOC_ARM_TLS_LDM32, R_ARM_TLS_LDM32},
1330 {BFD_RELOC_ARM_TLS_DTPMOD32, R_ARM_TLS_DTPMOD32},
1331 {BFD_RELOC_ARM_TLS_DTPOFF32, R_ARM_TLS_DTPOFF32},
1332 {BFD_RELOC_ARM_TLS_TPOFF32, R_ARM_TLS_TPOFF32},
1333 {BFD_RELOC_ARM_TLS_IE32, R_ARM_TLS_IE32},
1334 {BFD_RELOC_ARM_TLS_LE32, R_ARM_TLS_LE32},
1335 {BFD_RELOC_VTABLE_INHERIT, R_ARM_GNU_VTINHERIT},
1336 {BFD_RELOC_VTABLE_ENTRY, R_ARM_GNU_VTENTRY},
1339 static reloc_howto_type *
1340 elf32_arm_reloc_type_lookup (bfd *abfd ATTRIBUTE_UNUSED,
1341 bfd_reloc_code_real_type code)
1343 unsigned int i;
1344 for (i = 0; i < NUM_ELEM (elf32_arm_reloc_map); i ++)
1345 if (elf32_arm_reloc_map[i].bfd_reloc_val == code)
1346 return elf32_arm_howto_from_type (elf32_arm_reloc_map[i].elf_reloc_val);
1348 return NULL;
1351 /* Support for core dump NOTE sections */
1352 static bfd_boolean
1353 elf32_arm_nabi_grok_prstatus (bfd *abfd, Elf_Internal_Note *note)
1355 int offset;
1356 size_t size;
1358 switch (note->descsz)
1360 default:
1361 return FALSE;
1363 case 148: /* Linux/ARM 32-bit*/
1364 /* pr_cursig */
1365 elf_tdata (abfd)->core_signal = bfd_get_16 (abfd, note->descdata + 12);
1367 /* pr_pid */
1368 elf_tdata (abfd)->core_pid = bfd_get_32 (abfd, note->descdata + 24);
1370 /* pr_reg */
1371 offset = 72;
1372 size = 72;
1374 break;
1377 /* Make a ".reg/999" section. */
1378 return _bfd_elfcore_make_pseudosection (abfd, ".reg",
1379 size, note->descpos + offset);
1382 static bfd_boolean
1383 elf32_arm_nabi_grok_psinfo (bfd *abfd, Elf_Internal_Note *note)
1385 switch (note->descsz)
1387 default:
1388 return FALSE;
1390 case 124: /* Linux/ARM elf_prpsinfo */
1391 elf_tdata (abfd)->core_program
1392 = _bfd_elfcore_strndup (abfd, note->descdata + 28, 16);
1393 elf_tdata (abfd)->core_command
1394 = _bfd_elfcore_strndup (abfd, note->descdata + 44, 80);
1397 /* Note that for some reason, a spurious space is tacked
1398 onto the end of the args in some (at least one anyway)
1399 implementations, so strip it off if it exists. */
1402 char *command = elf_tdata (abfd)->core_command;
1403 int n = strlen (command);
1405 if (0 < n && command[n - 1] == ' ')
1406 command[n - 1] = '\0';
1409 return TRUE;
1412 #define TARGET_LITTLE_SYM bfd_elf32_littlearm_vec
1413 #define TARGET_LITTLE_NAME "elf32-littlearm"
1414 #define TARGET_BIG_SYM bfd_elf32_bigarm_vec
1415 #define TARGET_BIG_NAME "elf32-bigarm"
1417 #define elf_backend_grok_prstatus elf32_arm_nabi_grok_prstatus
1418 #define elf_backend_grok_psinfo elf32_arm_nabi_grok_psinfo
1420 typedef unsigned long int insn32;
1421 typedef unsigned short int insn16;
1423 /* In lieu of proper flags, assume all EABIv4 objects are interworkable. */
1424 #define INTERWORK_FLAG(abfd) \
1425 (EF_ARM_EABI_VERSION (elf_elfheader (abfd)->e_flags) == EF_ARM_EABI_VER4 \
1426 || (elf_elfheader (abfd)->e_flags & EF_ARM_INTERWORK))
1428 /* The linker script knows the section names for placement.
1429 The entry_names are used to do simple name mangling on the stubs.
1430 Given a function name, and its type, the stub can be found. The
1431 name can be changed. The only requirement is the %s be present. */
1432 #define THUMB2ARM_GLUE_SECTION_NAME ".glue_7t"
1433 #define THUMB2ARM_GLUE_ENTRY_NAME "__%s_from_thumb"
1435 #define ARM2THUMB_GLUE_SECTION_NAME ".glue_7"
1436 #define ARM2THUMB_GLUE_ENTRY_NAME "__%s_from_arm"
1438 /* The name of the dynamic interpreter. This is put in the .interp
1439 section. */
1440 #define ELF_DYNAMIC_INTERPRETER "/usr/lib/ld.so.1"
1442 #ifdef FOUR_WORD_PLT
1444 /* The first entry in a procedure linkage table looks like
1445 this. It is set up so that any shared library function that is
1446 called before the relocation has been set up calls the dynamic
1447 linker first. */
1448 static const bfd_vma elf32_arm_plt0_entry [] =
1450 0xe52de004, /* str lr, [sp, #-4]! */
1451 0xe59fe010, /* ldr lr, [pc, #16] */
1452 0xe08fe00e, /* add lr, pc, lr */
1453 0xe5bef008, /* ldr pc, [lr, #8]! */
1456 /* Subsequent entries in a procedure linkage table look like
1457 this. */
1458 static const bfd_vma elf32_arm_plt_entry [] =
1460 0xe28fc600, /* add ip, pc, #NN */
1461 0xe28cca00, /* add ip, ip, #NN */
1462 0xe5bcf000, /* ldr pc, [ip, #NN]! */
1463 0x00000000, /* unused */
1466 #else
1468 /* The first entry in a procedure linkage table looks like
1469 this. It is set up so that any shared library function that is
1470 called before the relocation has been set up calls the dynamic
1471 linker first. */
1472 static const bfd_vma elf32_arm_plt0_entry [] =
1474 0xe52de004, /* str lr, [sp, #-4]! */
1475 0xe59fe004, /* ldr lr, [pc, #4] */
1476 0xe08fe00e, /* add lr, pc, lr */
1477 0xe5bef008, /* ldr pc, [lr, #8]! */
1478 0x00000000, /* &GOT[0] - . */
1481 /* Subsequent entries in a procedure linkage table look like
1482 this. */
1483 static const bfd_vma elf32_arm_plt_entry [] =
1485 0xe28fc600, /* add ip, pc, #0xNN00000 */
1486 0xe28cca00, /* add ip, ip, #0xNN000 */
1487 0xe5bcf000, /* ldr pc, [ip, #0xNNN]! */
1490 #endif
1492 /* An initial stub used if the PLT entry is referenced from Thumb code. */
1493 #define PLT_THUMB_STUB_SIZE 4
1494 static const bfd_vma elf32_arm_plt_thumb_stub [] =
1496 0x4778, /* bx pc */
1497 0x46c0 /* nop */
1500 /* The entries in a PLT when using a DLL-based target with multiple
1501 address spaces. */
1502 static const bfd_vma elf32_arm_symbian_plt_entry [] =
1504 0xe51ff004, /* ldr pc, [pc, #-4] */
1505 0x00000000, /* dcd R_ARM_GLOB_DAT(X) */
1508 /* Used to build a map of a section. This is required for mixed-endian
1509 code/data. */
1511 typedef struct elf32_elf_section_map
1513 bfd_vma vma;
1514 char type;
1516 elf32_arm_section_map;
1518 typedef struct _arm_elf_section_data
1520 struct bfd_elf_section_data elf;
1521 unsigned int mapcount;
1522 elf32_arm_section_map *map;
1524 _arm_elf_section_data;
1526 #define elf32_arm_section_data(sec) \
1527 ((_arm_elf_section_data *) elf_section_data (sec))
1529 /* The size of the thread control block. */
1530 #define TCB_SIZE 8
1532 #define NUM_KNOWN_ATTRIBUTES 32
1534 typedef struct aeabi_attribute
1536 int type;
1537 unsigned int i;
1538 char *s;
1539 } aeabi_attribute;
1541 typedef struct aeabi_attribute_list
1543 struct aeabi_attribute_list *next;
1544 int tag;
1545 aeabi_attribute attr;
1546 } aeabi_attribute_list;
1548 struct elf32_arm_obj_tdata
1550 struct elf_obj_tdata root;
1552 /* tls_type for each local got entry. */
1553 char *local_got_tls_type;
1555 aeabi_attribute known_eabi_attributes[NUM_KNOWN_ATTRIBUTES];
1556 aeabi_attribute_list *other_eabi_attributes;
1559 #define elf32_arm_tdata(abfd) \
1560 ((struct elf32_arm_obj_tdata *) (abfd)->tdata.any)
1562 #define elf32_arm_local_got_tls_type(abfd) \
1563 (elf32_arm_tdata (abfd)->local_got_tls_type)
1565 static bfd_boolean
1566 elf32_arm_mkobject (bfd *abfd)
1568 bfd_size_type amt = sizeof (struct elf32_arm_obj_tdata);
1569 abfd->tdata.any = bfd_zalloc (abfd, amt);
1570 if (abfd->tdata.any == NULL)
1571 return FALSE;
1572 return TRUE;
1575 /* The ARM linker needs to keep track of the number of relocs that it
1576 decides to copy in check_relocs for each symbol. This is so that
1577 it can discard PC relative relocs if it doesn't need them when
1578 linking with -Bsymbolic. We store the information in a field
1579 extending the regular ELF linker hash table. */
1581 /* This structure keeps track of the number of relocs we have copied
1582 for a given symbol. */
1583 struct elf32_arm_relocs_copied
1585 /* Next section. */
1586 struct elf32_arm_relocs_copied * next;
1587 /* A section in dynobj. */
1588 asection * section;
1589 /* Number of relocs copied in this section. */
1590 bfd_size_type count;
1591 /* Number of PC-relative relocs copied in this section. */
1592 bfd_size_type pc_count;
1595 #define elf32_arm_hash_entry(ent) ((struct elf32_arm_link_hash_entry *)(ent))
1597 /* Arm ELF linker hash entry. */
1598 struct elf32_arm_link_hash_entry
1600 struct elf_link_hash_entry root;
1602 /* Number of PC relative relocs copied for this symbol. */
1603 struct elf32_arm_relocs_copied * relocs_copied;
1605 /* We reference count Thumb references to a PLT entry separately,
1606 so that we can emit the Thumb trampoline only if needed. */
1607 bfd_signed_vma plt_thumb_refcount;
1609 /* Since PLT entries have variable size if the Thumb prologue is
1610 used, we need to record the index into .got.plt instead of
1611 recomputing it from the PLT offset. */
1612 bfd_signed_vma plt_got_offset;
1614 #define GOT_UNKNOWN 0
1615 #define GOT_NORMAL 1
1616 #define GOT_TLS_GD 2
1617 #define GOT_TLS_IE 4
1618 unsigned char tls_type;
1621 /* Traverse an arm ELF linker hash table. */
1622 #define elf32_arm_link_hash_traverse(table, func, info) \
1623 (elf_link_hash_traverse \
1624 (&(table)->root, \
1625 (bfd_boolean (*) (struct elf_link_hash_entry *, void *)) (func), \
1626 (info)))
1628 /* Get the ARM elf linker hash table from a link_info structure. */
1629 #define elf32_arm_hash_table(info) \
1630 ((struct elf32_arm_link_hash_table *) ((info)->hash))
1632 /* ARM ELF linker hash table. */
1633 struct elf32_arm_link_hash_table
1635 /* The main hash table. */
1636 struct elf_link_hash_table root;
1638 /* The size in bytes of the section containing the Thumb-to-ARM glue. */
1639 bfd_size_type thumb_glue_size;
1641 /* The size in bytes of the section containing the ARM-to-Thumb glue. */
1642 bfd_size_type arm_glue_size;
1644 /* An arbitrary input BFD chosen to hold the glue sections. */
1645 bfd * bfd_of_glue_owner;
1647 /* Nonzero to output a BE8 image. */
1648 int byteswap_code;
1650 /* Zero if R_ARM_TARGET1 means R_ARM_ABS32.
1651 Nonzero if R_ARM_TARGET1 means R_ARM_ABS32. */
1652 int target1_is_rel;
1654 /* The relocation to use for R_ARM_TARGET2 relocations. */
1655 int target2_reloc;
1657 /* Nonzero to fix BX instructions for ARMv4 targets. */
1658 int fix_v4bx;
1660 /* Nonzero if the ARM/Thumb BLX instructions are available for use. */
1661 int use_blx;
1663 /* The number of bytes in the initial entry in the PLT. */
1664 bfd_size_type plt_header_size;
1666 /* The number of bytes in the subsequent PLT etries. */
1667 bfd_size_type plt_entry_size;
1669 /* True if the target system is Symbian OS. */
1670 int symbian_p;
1672 /* True if the target uses REL relocations. */
1673 int use_rel;
1675 /* Short-cuts to get to dynamic linker sections. */
1676 asection *sgot;
1677 asection *sgotplt;
1678 asection *srelgot;
1679 asection *splt;
1680 asection *srelplt;
1681 asection *sdynbss;
1682 asection *srelbss;
1684 /* Data for R_ARM_TLS_LDM32 relocations. */
1685 union {
1686 bfd_signed_vma refcount;
1687 bfd_vma offset;
1688 } tls_ldm_got;
1690 /* Small local sym to section mapping cache. */
1691 struct sym_sec_cache sym_sec;
1693 /* For convenience in allocate_dynrelocs. */
1694 bfd * obfd;
1697 /* Create an entry in an ARM ELF linker hash table. */
1699 static struct bfd_hash_entry *
1700 elf32_arm_link_hash_newfunc (struct bfd_hash_entry * entry,
1701 struct bfd_hash_table * table,
1702 const char * string)
1704 struct elf32_arm_link_hash_entry * ret =
1705 (struct elf32_arm_link_hash_entry *) entry;
1707 /* Allocate the structure if it has not already been allocated by a
1708 subclass. */
1709 if (ret == (struct elf32_arm_link_hash_entry *) NULL)
1710 ret = bfd_hash_allocate (table, sizeof (struct elf32_arm_link_hash_entry));
1711 if (ret == NULL)
1712 return (struct bfd_hash_entry *) ret;
1714 /* Call the allocation method of the superclass. */
1715 ret = ((struct elf32_arm_link_hash_entry *)
1716 _bfd_elf_link_hash_newfunc ((struct bfd_hash_entry *) ret,
1717 table, string));
1718 if (ret != NULL)
1720 ret->relocs_copied = NULL;
1721 ret->tls_type = GOT_UNKNOWN;
1722 ret->plt_thumb_refcount = 0;
1723 ret->plt_got_offset = -1;
1726 return (struct bfd_hash_entry *) ret;
1729 /* Create .got, .gotplt, and .rel.got sections in DYNOBJ, and set up
1730 shortcuts to them in our hash table. */
1732 static bfd_boolean
1733 create_got_section (bfd *dynobj, struct bfd_link_info *info)
1735 struct elf32_arm_link_hash_table *htab;
1737 htab = elf32_arm_hash_table (info);
1738 /* BPABI objects never have a GOT, or associated sections. */
1739 if (htab->symbian_p)
1740 return TRUE;
1742 if (! _bfd_elf_create_got_section (dynobj, info))
1743 return FALSE;
1745 htab->sgot = bfd_get_section_by_name (dynobj, ".got");
1746 htab->sgotplt = bfd_get_section_by_name (dynobj, ".got.plt");
1747 if (!htab->sgot || !htab->sgotplt)
1748 abort ();
1750 htab->srelgot = bfd_make_section_with_flags (dynobj, ".rel.got",
1751 (SEC_ALLOC | SEC_LOAD
1752 | SEC_HAS_CONTENTS
1753 | SEC_IN_MEMORY
1754 | SEC_LINKER_CREATED
1755 | SEC_READONLY));
1756 if (htab->srelgot == NULL
1757 || ! bfd_set_section_alignment (dynobj, htab->srelgot, 2))
1758 return FALSE;
1759 return TRUE;
1762 /* Create .plt, .rel.plt, .got, .got.plt, .rel.got, .dynbss, and
1763 .rel.bss sections in DYNOBJ, and set up shortcuts to them in our
1764 hash table. */
1766 static bfd_boolean
1767 elf32_arm_create_dynamic_sections (bfd *dynobj, struct bfd_link_info *info)
1769 struct elf32_arm_link_hash_table *htab;
1771 htab = elf32_arm_hash_table (info);
1772 if (!htab->sgot && !create_got_section (dynobj, info))
1773 return FALSE;
1775 if (!_bfd_elf_create_dynamic_sections (dynobj, info))
1776 return FALSE;
1778 htab->splt = bfd_get_section_by_name (dynobj, ".plt");
1779 htab->srelplt = bfd_get_section_by_name (dynobj, ".rel.plt");
1780 htab->sdynbss = bfd_get_section_by_name (dynobj, ".dynbss");
1781 if (!info->shared)
1782 htab->srelbss = bfd_get_section_by_name (dynobj, ".rel.bss");
1784 if (!htab->splt
1785 || !htab->srelplt
1786 || !htab->sdynbss
1787 || (!info->shared && !htab->srelbss))
1788 abort ();
1790 return TRUE;
1793 /* Copy the extra info we tack onto an elf_link_hash_entry. */
1795 static void
1796 elf32_arm_copy_indirect_symbol (struct bfd_link_info *info,
1797 struct elf_link_hash_entry *dir,
1798 struct elf_link_hash_entry *ind)
1800 struct elf32_arm_link_hash_entry *edir, *eind;
1802 edir = (struct elf32_arm_link_hash_entry *) dir;
1803 eind = (struct elf32_arm_link_hash_entry *) ind;
1805 if (eind->relocs_copied != NULL)
1807 if (edir->relocs_copied != NULL)
1809 struct elf32_arm_relocs_copied **pp;
1810 struct elf32_arm_relocs_copied *p;
1812 /* Add reloc counts against the indirect sym to the direct sym
1813 list. Merge any entries against the same section. */
1814 for (pp = &eind->relocs_copied; (p = *pp) != NULL; )
1816 struct elf32_arm_relocs_copied *q;
1818 for (q = edir->relocs_copied; q != NULL; q = q->next)
1819 if (q->section == p->section)
1821 q->pc_count += p->pc_count;
1822 q->count += p->count;
1823 *pp = p->next;
1824 break;
1826 if (q == NULL)
1827 pp = &p->next;
1829 *pp = edir->relocs_copied;
1832 edir->relocs_copied = eind->relocs_copied;
1833 eind->relocs_copied = NULL;
1836 /* Copy over PLT info. */
1837 edir->plt_thumb_refcount += eind->plt_thumb_refcount;
1838 eind->plt_thumb_refcount = 0;
1840 if (ind->root.type == bfd_link_hash_indirect
1841 && dir->got.refcount <= 0)
1843 edir->tls_type = eind->tls_type;
1844 eind->tls_type = GOT_UNKNOWN;
1847 _bfd_elf_link_hash_copy_indirect (info, dir, ind);
1850 /* Create an ARM elf linker hash table. */
1852 static struct bfd_link_hash_table *
1853 elf32_arm_link_hash_table_create (bfd *abfd)
1855 struct elf32_arm_link_hash_table *ret;
1856 bfd_size_type amt = sizeof (struct elf32_arm_link_hash_table);
1858 ret = bfd_malloc (amt);
1859 if (ret == NULL)
1860 return NULL;
1862 if (!_bfd_elf_link_hash_table_init (& ret->root, abfd,
1863 elf32_arm_link_hash_newfunc))
1865 free (ret);
1866 return NULL;
1869 ret->sgot = NULL;
1870 ret->sgotplt = NULL;
1871 ret->srelgot = NULL;
1872 ret->splt = NULL;
1873 ret->srelplt = NULL;
1874 ret->sdynbss = NULL;
1875 ret->srelbss = NULL;
1876 ret->thumb_glue_size = 0;
1877 ret->arm_glue_size = 0;
1878 ret->bfd_of_glue_owner = NULL;
1879 ret->byteswap_code = 0;
1880 ret->target1_is_rel = 0;
1881 ret->target2_reloc = R_ARM_NONE;
1882 #ifdef FOUR_WORD_PLT
1883 ret->plt_header_size = 16;
1884 ret->plt_entry_size = 16;
1885 #else
1886 ret->plt_header_size = 20;
1887 ret->plt_entry_size = 12;
1888 #endif
1889 ret->fix_v4bx = 0;
1890 ret->use_blx = 0;
1891 ret->symbian_p = 0;
1892 ret->use_rel = 1;
1893 ret->sym_sec.abfd = NULL;
1894 ret->obfd = abfd;
1895 ret->tls_ldm_got.refcount = 0;
1897 return &ret->root.root;
1900 /* Locate the Thumb encoded calling stub for NAME. */
1902 static struct elf_link_hash_entry *
1903 find_thumb_glue (struct bfd_link_info *link_info,
1904 const char *name,
1905 bfd *input_bfd)
1907 char *tmp_name;
1908 struct elf_link_hash_entry *hash;
1909 struct elf32_arm_link_hash_table *hash_table;
1911 /* We need a pointer to the armelf specific hash table. */
1912 hash_table = elf32_arm_hash_table (link_info);
1914 tmp_name = bfd_malloc ((bfd_size_type) strlen (name)
1915 + strlen (THUMB2ARM_GLUE_ENTRY_NAME) + 1);
1917 BFD_ASSERT (tmp_name);
1919 sprintf (tmp_name, THUMB2ARM_GLUE_ENTRY_NAME, name);
1921 hash = elf_link_hash_lookup
1922 (&(hash_table)->root, tmp_name, FALSE, FALSE, TRUE);
1924 if (hash == NULL)
1925 /* xgettext:c-format */
1926 (*_bfd_error_handler) (_("%B: unable to find THUMB glue '%s' for `%s'"),
1927 input_bfd, tmp_name, name);
1929 free (tmp_name);
1931 return hash;
1934 /* Locate the ARM encoded calling stub for NAME. */
1936 static struct elf_link_hash_entry *
1937 find_arm_glue (struct bfd_link_info *link_info,
1938 const char *name,
1939 bfd *input_bfd)
1941 char *tmp_name;
1942 struct elf_link_hash_entry *myh;
1943 struct elf32_arm_link_hash_table *hash_table;
1945 /* We need a pointer to the elfarm specific hash table. */
1946 hash_table = elf32_arm_hash_table (link_info);
1948 tmp_name = bfd_malloc ((bfd_size_type) strlen (name)
1949 + strlen (ARM2THUMB_GLUE_ENTRY_NAME) + 1);
1951 BFD_ASSERT (tmp_name);
1953 sprintf (tmp_name, ARM2THUMB_GLUE_ENTRY_NAME, name);
1955 myh = elf_link_hash_lookup
1956 (&(hash_table)->root, tmp_name, FALSE, FALSE, TRUE);
1958 if (myh == NULL)
1959 /* xgettext:c-format */
1960 (*_bfd_error_handler) (_("%B: unable to find ARM glue '%s' for `%s'"),
1961 input_bfd, tmp_name, name);
1963 free (tmp_name);
1965 return myh;
1968 /* ARM->Thumb glue (static images):
1970 .arm
1971 __func_from_arm:
1972 ldr r12, __func_addr
1973 bx r12
1974 __func_addr:
1975 .word func @ behave as if you saw a ARM_32 reloc.
1977 (relocatable images)
1978 .arm
1979 __func_from_arm:
1980 ldr r12, __func_offset
1981 add r12, r12, pc
1982 bx r12
1983 __func_offset:
1984 .word func - .
1987 #define ARM2THUMB_STATIC_GLUE_SIZE 12
1988 static const insn32 a2t1_ldr_insn = 0xe59fc000;
1989 static const insn32 a2t2_bx_r12_insn = 0xe12fff1c;
1990 static const insn32 a2t3_func_addr_insn = 0x00000001;
1992 #define ARM2THUMB_PIC_GLUE_SIZE 16
1993 static const insn32 a2t1p_ldr_insn = 0xe59fc004;
1994 static const insn32 a2t2p_add_pc_insn = 0xe08cc00f;
1995 static const insn32 a2t3p_bx_r12_insn = 0xe12fff1c;
1997 /* Thumb->ARM: Thumb->(non-interworking aware) ARM
1999 .thumb .thumb
2000 .align 2 .align 2
2001 __func_from_thumb: __func_from_thumb:
2002 bx pc push {r6, lr}
2003 nop ldr r6, __func_addr
2004 .arm mov lr, pc
2005 __func_change_to_arm: bx r6
2006 b func .arm
2007 __func_back_to_thumb:
2008 ldmia r13! {r6, lr}
2009 bx lr
2010 __func_addr:
2011 .word func */
2013 #define THUMB2ARM_GLUE_SIZE 8
2014 static const insn16 t2a1_bx_pc_insn = 0x4778;
2015 static const insn16 t2a2_noop_insn = 0x46c0;
2016 static const insn32 t2a3_b_insn = 0xea000000;
2018 #ifndef ELFARM_NABI_C_INCLUDED
2019 bfd_boolean
2020 bfd_elf32_arm_allocate_interworking_sections (struct bfd_link_info * info)
2022 asection * s;
2023 bfd_byte * foo;
2024 struct elf32_arm_link_hash_table * globals;
2026 globals = elf32_arm_hash_table (info);
2028 BFD_ASSERT (globals != NULL);
2030 if (globals->arm_glue_size != 0)
2032 BFD_ASSERT (globals->bfd_of_glue_owner != NULL);
2034 s = bfd_get_section_by_name (globals->bfd_of_glue_owner,
2035 ARM2THUMB_GLUE_SECTION_NAME);
2037 BFD_ASSERT (s != NULL);
2039 foo = bfd_alloc (globals->bfd_of_glue_owner, globals->arm_glue_size);
2041 s->size = globals->arm_glue_size;
2042 s->contents = foo;
2045 if (globals->thumb_glue_size != 0)
2047 BFD_ASSERT (globals->bfd_of_glue_owner != NULL);
2049 s = bfd_get_section_by_name
2050 (globals->bfd_of_glue_owner, THUMB2ARM_GLUE_SECTION_NAME);
2052 BFD_ASSERT (s != NULL);
2054 foo = bfd_alloc (globals->bfd_of_glue_owner, globals->thumb_glue_size);
2056 s->size = globals->thumb_glue_size;
2057 s->contents = foo;
2060 return TRUE;
2063 static void
2064 record_arm_to_thumb_glue (struct bfd_link_info * link_info,
2065 struct elf_link_hash_entry * h)
2067 const char * name = h->root.root.string;
2068 asection * s;
2069 char * tmp_name;
2070 struct elf_link_hash_entry * myh;
2071 struct bfd_link_hash_entry * bh;
2072 struct elf32_arm_link_hash_table * globals;
2073 bfd_vma val;
2075 globals = elf32_arm_hash_table (link_info);
2077 BFD_ASSERT (globals != NULL);
2078 BFD_ASSERT (globals->bfd_of_glue_owner != NULL);
2080 s = bfd_get_section_by_name
2081 (globals->bfd_of_glue_owner, ARM2THUMB_GLUE_SECTION_NAME);
2083 BFD_ASSERT (s != NULL);
2085 tmp_name = bfd_malloc ((bfd_size_type) strlen (name) + strlen (ARM2THUMB_GLUE_ENTRY_NAME) + 1);
2087 BFD_ASSERT (tmp_name);
2089 sprintf (tmp_name, ARM2THUMB_GLUE_ENTRY_NAME, name);
2091 myh = elf_link_hash_lookup
2092 (&(globals)->root, tmp_name, FALSE, FALSE, TRUE);
2094 if (myh != NULL)
2096 /* We've already seen this guy. */
2097 free (tmp_name);
2098 return;
2101 /* The only trick here is using hash_table->arm_glue_size as the value.
2102 Even though the section isn't allocated yet, this is where we will be
2103 putting it. */
2104 bh = NULL;
2105 val = globals->arm_glue_size + 1;
2106 _bfd_generic_link_add_one_symbol (link_info, globals->bfd_of_glue_owner,
2107 tmp_name, BSF_GLOBAL, s, val,
2108 NULL, TRUE, FALSE, &bh);
2110 myh = (struct elf_link_hash_entry *) bh;
2111 myh->type = ELF_ST_INFO (STB_LOCAL, STT_FUNC);
2112 myh->forced_local = 1;
2114 free (tmp_name);
2116 if ((link_info->shared || globals->root.is_relocatable_executable))
2117 globals->arm_glue_size += ARM2THUMB_PIC_GLUE_SIZE;
2118 else
2119 globals->arm_glue_size += ARM2THUMB_STATIC_GLUE_SIZE;
2121 return;
2124 static void
2125 record_thumb_to_arm_glue (struct bfd_link_info *link_info,
2126 struct elf_link_hash_entry *h)
2128 const char *name = h->root.root.string;
2129 asection *s;
2130 char *tmp_name;
2131 struct elf_link_hash_entry *myh;
2132 struct bfd_link_hash_entry *bh;
2133 struct elf32_arm_link_hash_table *hash_table;
2134 bfd_vma val;
2136 hash_table = elf32_arm_hash_table (link_info);
2138 BFD_ASSERT (hash_table != NULL);
2139 BFD_ASSERT (hash_table->bfd_of_glue_owner != NULL);
2141 s = bfd_get_section_by_name
2142 (hash_table->bfd_of_glue_owner, THUMB2ARM_GLUE_SECTION_NAME);
2144 BFD_ASSERT (s != NULL);
2146 tmp_name = bfd_malloc ((bfd_size_type) strlen (name)
2147 + strlen (THUMB2ARM_GLUE_ENTRY_NAME) + 1);
2149 BFD_ASSERT (tmp_name);
2151 sprintf (tmp_name, THUMB2ARM_GLUE_ENTRY_NAME, name);
2153 myh = elf_link_hash_lookup
2154 (&(hash_table)->root, tmp_name, FALSE, FALSE, TRUE);
2156 if (myh != NULL)
2158 /* We've already seen this guy. */
2159 free (tmp_name);
2160 return;
2163 bh = NULL;
2164 val = hash_table->thumb_glue_size + 1;
2165 _bfd_generic_link_add_one_symbol (link_info, hash_table->bfd_of_glue_owner,
2166 tmp_name, BSF_GLOBAL, s, val,
2167 NULL, TRUE, FALSE, &bh);
2169 /* If we mark it 'Thumb', the disassembler will do a better job. */
2170 myh = (struct elf_link_hash_entry *) bh;
2171 myh->type = ELF_ST_INFO (STB_LOCAL, STT_ARM_TFUNC);
2172 myh->forced_local = 1;
2174 free (tmp_name);
2176 #define CHANGE_TO_ARM "__%s_change_to_arm"
2177 #define BACK_FROM_ARM "__%s_back_from_arm"
2179 /* Allocate another symbol to mark where we switch to Arm mode. */
2180 tmp_name = bfd_malloc ((bfd_size_type) strlen (name)
2181 + strlen (CHANGE_TO_ARM) + 1);
2183 BFD_ASSERT (tmp_name);
2185 sprintf (tmp_name, CHANGE_TO_ARM, name);
2187 bh = NULL;
2188 val = hash_table->thumb_glue_size + 4,
2189 _bfd_generic_link_add_one_symbol (link_info, hash_table->bfd_of_glue_owner,
2190 tmp_name, BSF_LOCAL, s, val,
2191 NULL, TRUE, FALSE, &bh);
2193 free (tmp_name);
2195 hash_table->thumb_glue_size += THUMB2ARM_GLUE_SIZE;
2197 return;
2200 /* Add the glue sections to ABFD. This function is called from the
2201 linker scripts in ld/emultempl/{armelf}.em. */
2203 bfd_boolean
2204 bfd_elf32_arm_add_glue_sections_to_bfd (bfd *abfd,
2205 struct bfd_link_info *info)
2207 flagword flags;
2208 asection *sec;
2210 /* If we are only performing a partial
2211 link do not bother adding the glue. */
2212 if (info->relocatable)
2213 return TRUE;
2215 sec = bfd_get_section_by_name (abfd, ARM2THUMB_GLUE_SECTION_NAME);
2217 if (sec == NULL)
2219 /* Note: we do not include the flag SEC_LINKER_CREATED, as this
2220 will prevent elf_link_input_bfd() from processing the contents
2221 of this section. */
2222 flags = SEC_ALLOC | SEC_LOAD | SEC_HAS_CONTENTS | SEC_IN_MEMORY | SEC_CODE | SEC_READONLY;
2224 sec = bfd_make_section_with_flags (abfd,
2225 ARM2THUMB_GLUE_SECTION_NAME,
2226 flags);
2228 if (sec == NULL
2229 || !bfd_set_section_alignment (abfd, sec, 2))
2230 return FALSE;
2232 /* Set the gc mark to prevent the section from being removed by garbage
2233 collection, despite the fact that no relocs refer to this section. */
2234 sec->gc_mark = 1;
2237 sec = bfd_get_section_by_name (abfd, THUMB2ARM_GLUE_SECTION_NAME);
2239 if (sec == NULL)
2241 flags = SEC_ALLOC | SEC_LOAD | SEC_HAS_CONTENTS | SEC_IN_MEMORY
2242 | SEC_CODE | SEC_READONLY;
2244 sec = bfd_make_section_with_flags (abfd,
2245 THUMB2ARM_GLUE_SECTION_NAME,
2246 flags);
2248 if (sec == NULL
2249 || !bfd_set_section_alignment (abfd, sec, 2))
2250 return FALSE;
2252 sec->gc_mark = 1;
2255 return TRUE;
2258 /* Select a BFD to be used to hold the sections used by the glue code.
2259 This function is called from the linker scripts in ld/emultempl/
2260 {armelf/pe}.em */
2262 bfd_boolean
2263 bfd_elf32_arm_get_bfd_for_interworking (bfd *abfd, struct bfd_link_info *info)
2265 struct elf32_arm_link_hash_table *globals;
2267 /* If we are only performing a partial link
2268 do not bother getting a bfd to hold the glue. */
2269 if (info->relocatable)
2270 return TRUE;
2272 /* Make sure we don't attach the glue sections to a dynamic object. */
2273 BFD_ASSERT (!(abfd->flags & DYNAMIC));
2275 globals = elf32_arm_hash_table (info);
2277 BFD_ASSERT (globals != NULL);
2279 if (globals->bfd_of_glue_owner != NULL)
2280 return TRUE;
2282 /* Save the bfd for later use. */
2283 globals->bfd_of_glue_owner = abfd;
2285 return TRUE;
2288 bfd_boolean
2289 bfd_elf32_arm_process_before_allocation (bfd *abfd,
2290 struct bfd_link_info *link_info,
2291 int byteswap_code)
2293 Elf_Internal_Shdr *symtab_hdr;
2294 Elf_Internal_Rela *internal_relocs = NULL;
2295 Elf_Internal_Rela *irel, *irelend;
2296 bfd_byte *contents = NULL;
2298 asection *sec;
2299 struct elf32_arm_link_hash_table *globals;
2301 /* If we are only performing a partial link do not bother
2302 to construct any glue. */
2303 if (link_info->relocatable)
2304 return TRUE;
2306 /* Here we have a bfd that is to be included on the link. We have a hook
2307 to do reloc rummaging, before section sizes are nailed down. */
2308 globals = elf32_arm_hash_table (link_info);
2310 BFD_ASSERT (globals != NULL);
2311 BFD_ASSERT (globals->bfd_of_glue_owner != NULL);
2313 if (byteswap_code && !bfd_big_endian (abfd))
2315 _bfd_error_handler (_("%B: BE8 images only valid in big-endian mode."),
2316 abfd);
2317 return FALSE;
2319 globals->byteswap_code = byteswap_code;
2321 /* Rummage around all the relocs and map the glue vectors. */
2322 sec = abfd->sections;
2324 if (sec == NULL)
2325 return TRUE;
2327 for (; sec != NULL; sec = sec->next)
2329 if (sec->reloc_count == 0)
2330 continue;
2332 symtab_hdr = &elf_tdata (abfd)->symtab_hdr;
2334 /* Load the relocs. */
2335 internal_relocs
2336 = _bfd_elf_link_read_relocs (abfd, sec, (void *) NULL,
2337 (Elf_Internal_Rela *) NULL, FALSE);
2339 if (internal_relocs == NULL)
2340 goto error_return;
2342 irelend = internal_relocs + sec->reloc_count;
2343 for (irel = internal_relocs; irel < irelend; irel++)
2345 long r_type;
2346 unsigned long r_index;
2348 struct elf_link_hash_entry *h;
2350 r_type = ELF32_R_TYPE (irel->r_info);
2351 r_index = ELF32_R_SYM (irel->r_info);
2353 /* These are the only relocation types we care about. */
2354 if ( r_type != R_ARM_PC24
2355 && r_type != R_ARM_PLT32
2356 && r_type != R_ARM_CALL
2357 && r_type != R_ARM_JUMP24
2358 && r_type != R_ARM_THM_CALL)
2359 continue;
2361 /* Get the section contents if we haven't done so already. */
2362 if (contents == NULL)
2364 /* Get cached copy if it exists. */
2365 if (elf_section_data (sec)->this_hdr.contents != NULL)
2366 contents = elf_section_data (sec)->this_hdr.contents;
2367 else
2369 /* Go get them off disk. */
2370 if (! bfd_malloc_and_get_section (abfd, sec, &contents))
2371 goto error_return;
2375 /* If the relocation is not against a symbol it cannot concern us. */
2376 h = NULL;
2378 /* We don't care about local symbols. */
2379 if (r_index < symtab_hdr->sh_info)
2380 continue;
2382 /* This is an external symbol. */
2383 r_index -= symtab_hdr->sh_info;
2384 h = (struct elf_link_hash_entry *)
2385 elf_sym_hashes (abfd)[r_index];
2387 /* If the relocation is against a static symbol it must be within
2388 the current section and so cannot be a cross ARM/Thumb relocation. */
2389 if (h == NULL)
2390 continue;
2392 /* If the call will go through a PLT entry then we do not need
2393 glue. */
2394 if (globals->splt != NULL && h->plt.offset != (bfd_vma) -1)
2395 continue;
2397 switch (r_type)
2399 case R_ARM_PC24:
2400 case R_ARM_PLT32:
2401 case R_ARM_CALL:
2402 case R_ARM_JUMP24:
2403 /* This one is a call from arm code. We need to look up
2404 the target of the call. If it is a thumb target, we
2405 insert glue. */
2406 if (ELF_ST_TYPE(h->type) == STT_ARM_TFUNC)
2407 record_arm_to_thumb_glue (link_info, h);
2408 break;
2410 case R_ARM_THM_CALL:
2411 /* This one is a call from thumb code. We look
2412 up the target of the call. If it is not a thumb
2413 target, we insert glue. */
2414 if (ELF_ST_TYPE (h->type) != STT_ARM_TFUNC)
2415 record_thumb_to_arm_glue (link_info, h);
2416 break;
2418 default:
2419 abort ();
2423 if (contents != NULL
2424 && elf_section_data (sec)->this_hdr.contents != contents)
2425 free (contents);
2426 contents = NULL;
2428 if (internal_relocs != NULL
2429 && elf_section_data (sec)->relocs != internal_relocs)
2430 free (internal_relocs);
2431 internal_relocs = NULL;
2434 return TRUE;
2436 error_return:
2437 if (contents != NULL
2438 && elf_section_data (sec)->this_hdr.contents != contents)
2439 free (contents);
2440 if (internal_relocs != NULL
2441 && elf_section_data (sec)->relocs != internal_relocs)
2442 free (internal_relocs);
2444 return FALSE;
2446 #endif
2449 /* Set target relocation values needed during linking. */
2451 void
2452 bfd_elf32_arm_set_target_relocs (struct bfd_link_info *link_info,
2453 int target1_is_rel,
2454 char * target2_type,
2455 int fix_v4bx,
2456 int use_blx)
2458 struct elf32_arm_link_hash_table *globals;
2460 globals = elf32_arm_hash_table (link_info);
2462 globals->target1_is_rel = target1_is_rel;
2463 if (strcmp (target2_type, "rel") == 0)
2464 globals->target2_reloc = R_ARM_REL32;
2465 else if (strcmp (target2_type, "abs") == 0)
2466 globals->target2_reloc = R_ARM_ABS32;
2467 else if (strcmp (target2_type, "got-rel") == 0)
2468 globals->target2_reloc = R_ARM_GOT_PREL;
2469 else
2471 _bfd_error_handler (_("Invalid TARGET2 relocation type '%s'."),
2472 target2_type);
2474 globals->fix_v4bx = fix_v4bx;
2475 globals->use_blx |= use_blx;
2478 /* The thumb form of a long branch is a bit finicky, because the offset
2479 encoding is split over two fields, each in it's own instruction. They
2480 can occur in any order. So given a thumb form of long branch, and an
2481 offset, insert the offset into the thumb branch and return finished
2482 instruction.
2484 It takes two thumb instructions to encode the target address. Each has
2485 11 bits to invest. The upper 11 bits are stored in one (identified by
2486 H-0.. see below), the lower 11 bits are stored in the other (identified
2487 by H-1).
2489 Combine together and shifted left by 1 (it's a half word address) and
2490 there you have it.
2492 Op: 1111 = F,
2493 H-0, upper address-0 = 000
2494 Op: 1111 = F,
2495 H-1, lower address-0 = 800
2497 They can be ordered either way, but the arm tools I've seen always put
2498 the lower one first. It probably doesn't matter. krk@cygnus.com
2500 XXX: Actually the order does matter. The second instruction (H-1)
2501 moves the computed address into the PC, so it must be the second one
2502 in the sequence. The problem, however is that whilst little endian code
2503 stores the instructions in HI then LOW order, big endian code does the
2504 reverse. nickc@cygnus.com. */
2506 #define LOW_HI_ORDER 0xF800F000
2507 #define HI_LOW_ORDER 0xF000F800
2509 static insn32
2510 insert_thumb_branch (insn32 br_insn, int rel_off)
2512 unsigned int low_bits;
2513 unsigned int high_bits;
2515 BFD_ASSERT ((rel_off & 1) != 1);
2517 rel_off >>= 1; /* Half word aligned address. */
2518 low_bits = rel_off & 0x000007FF; /* The bottom 11 bits. */
2519 high_bits = (rel_off >> 11) & 0x000007FF; /* The top 11 bits. */
2521 if ((br_insn & LOW_HI_ORDER) == LOW_HI_ORDER)
2522 br_insn = LOW_HI_ORDER | (low_bits << 16) | high_bits;
2523 else if ((br_insn & HI_LOW_ORDER) == HI_LOW_ORDER)
2524 br_insn = HI_LOW_ORDER | (high_bits << 16) | low_bits;
2525 else
2526 /* FIXME: abort is probably not the right call. krk@cygnus.com */
2527 abort (); /* Error - not a valid branch instruction form. */
2529 return br_insn;
2532 /* Thumb code calling an ARM function. */
2534 static int
2535 elf32_thumb_to_arm_stub (struct bfd_link_info * info,
2536 const char * name,
2537 bfd * input_bfd,
2538 bfd * output_bfd,
2539 asection * input_section,
2540 bfd_byte * hit_data,
2541 asection * sym_sec,
2542 bfd_vma offset,
2543 bfd_signed_vma addend,
2544 bfd_vma val)
2546 asection * s = 0;
2547 bfd_vma my_offset;
2548 unsigned long int tmp;
2549 long int ret_offset;
2550 struct elf_link_hash_entry * myh;
2551 struct elf32_arm_link_hash_table * globals;
2553 myh = find_thumb_glue (info, name, input_bfd);
2554 if (myh == NULL)
2555 return FALSE;
2557 globals = elf32_arm_hash_table (info);
2559 BFD_ASSERT (globals != NULL);
2560 BFD_ASSERT (globals->bfd_of_glue_owner != NULL);
2562 my_offset = myh->root.u.def.value;
2564 s = bfd_get_section_by_name (globals->bfd_of_glue_owner,
2565 THUMB2ARM_GLUE_SECTION_NAME);
2567 BFD_ASSERT (s != NULL);
2568 BFD_ASSERT (s->contents != NULL);
2569 BFD_ASSERT (s->output_section != NULL);
2571 if ((my_offset & 0x01) == 0x01)
2573 if (sym_sec != NULL
2574 && sym_sec->owner != NULL
2575 && !INTERWORK_FLAG (sym_sec->owner))
2577 (*_bfd_error_handler)
2578 (_("%B(%s): warning: interworking not enabled.\n"
2579 " first occurrence: %B: thumb call to arm"),
2580 sym_sec->owner, input_bfd, name);
2582 return FALSE;
2585 --my_offset;
2586 myh->root.u.def.value = my_offset;
2588 bfd_put_16 (output_bfd, (bfd_vma) t2a1_bx_pc_insn,
2589 s->contents + my_offset);
2591 bfd_put_16 (output_bfd, (bfd_vma) t2a2_noop_insn,
2592 s->contents + my_offset + 2);
2594 ret_offset =
2595 /* Address of destination of the stub. */
2596 ((bfd_signed_vma) val)
2597 - ((bfd_signed_vma)
2598 /* Offset from the start of the current section
2599 to the start of the stubs. */
2600 (s->output_offset
2601 /* Offset of the start of this stub from the start of the stubs. */
2602 + my_offset
2603 /* Address of the start of the current section. */
2604 + s->output_section->vma)
2605 /* The branch instruction is 4 bytes into the stub. */
2607 /* ARM branches work from the pc of the instruction + 8. */
2608 + 8);
2610 bfd_put_32 (output_bfd,
2611 (bfd_vma) t2a3_b_insn | ((ret_offset >> 2) & 0x00FFFFFF),
2612 s->contents + my_offset + 4);
2615 BFD_ASSERT (my_offset <= globals->thumb_glue_size);
2617 /* Now go back and fix up the original BL insn to point to here. */
2618 ret_offset =
2619 /* Address of where the stub is located. */
2620 (s->output_section->vma + s->output_offset + my_offset)
2621 /* Address of where the BL is located. */
2622 - (input_section->output_section->vma + input_section->output_offset
2623 + offset)
2624 /* Addend in the relocation. */
2625 - addend
2626 /* Biassing for PC-relative addressing. */
2627 - 8;
2629 tmp = bfd_get_32 (input_bfd, hit_data
2630 - input_section->vma);
2632 bfd_put_32 (output_bfd,
2633 (bfd_vma) insert_thumb_branch (tmp, ret_offset),
2634 hit_data - input_section->vma);
2636 return TRUE;
2639 /* Arm code calling a Thumb function. */
2641 static int
2642 elf32_arm_to_thumb_stub (struct bfd_link_info * info,
2643 const char * name,
2644 bfd * input_bfd,
2645 bfd * output_bfd,
2646 asection * input_section,
2647 bfd_byte * hit_data,
2648 asection * sym_sec,
2649 bfd_vma offset,
2650 bfd_signed_vma addend,
2651 bfd_vma val)
2653 unsigned long int tmp;
2654 bfd_vma my_offset;
2655 asection * s;
2656 long int ret_offset;
2657 struct elf_link_hash_entry * myh;
2658 struct elf32_arm_link_hash_table * globals;
2660 myh = find_arm_glue (info, name, input_bfd);
2661 if (myh == NULL)
2662 return FALSE;
2664 globals = elf32_arm_hash_table (info);
2666 BFD_ASSERT (globals != NULL);
2667 BFD_ASSERT (globals->bfd_of_glue_owner != NULL);
2669 my_offset = myh->root.u.def.value;
2670 s = bfd_get_section_by_name (globals->bfd_of_glue_owner,
2671 ARM2THUMB_GLUE_SECTION_NAME);
2672 BFD_ASSERT (s != NULL);
2673 BFD_ASSERT (s->contents != NULL);
2674 BFD_ASSERT (s->output_section != NULL);
2676 if ((my_offset & 0x01) == 0x01)
2678 if (sym_sec != NULL
2679 && sym_sec->owner != NULL
2680 && !INTERWORK_FLAG (sym_sec->owner))
2682 (*_bfd_error_handler)
2683 (_("%B(%s): warning: interworking not enabled.\n"
2684 " first occurrence: %B: arm call to thumb"),
2685 sym_sec->owner, input_bfd, name);
2688 --my_offset;
2689 myh->root.u.def.value = my_offset;
2691 if ((info->shared || globals->root.is_relocatable_executable))
2693 /* For relocatable objects we can't use absolute addresses,
2694 so construct the address from a relative offset. */
2695 /* TODO: If the offset is small it's probably worth
2696 constructing the address with adds. */
2697 bfd_put_32 (output_bfd, (bfd_vma) a2t1p_ldr_insn,
2698 s->contents + my_offset);
2699 bfd_put_32 (output_bfd, (bfd_vma) a2t2p_add_pc_insn,
2700 s->contents + my_offset + 4);
2701 bfd_put_32 (output_bfd, (bfd_vma) a2t3p_bx_r12_insn,
2702 s->contents + my_offset + 8);
2703 /* Adjust the offset by 4 for the position of the add,
2704 and 8 for the pipeline offset. */
2705 ret_offset = (val - (s->output_offset
2706 + s->output_section->vma
2707 + my_offset + 12))
2708 | 1;
2709 bfd_put_32 (output_bfd, ret_offset,
2710 s->contents + my_offset + 12);
2712 else
2714 bfd_put_32 (output_bfd, (bfd_vma) a2t1_ldr_insn,
2715 s->contents + my_offset);
2717 bfd_put_32 (output_bfd, (bfd_vma) a2t2_bx_r12_insn,
2718 s->contents + my_offset + 4);
2720 /* It's a thumb address. Add the low order bit. */
2721 bfd_put_32 (output_bfd, val | a2t3_func_addr_insn,
2722 s->contents + my_offset + 8);
2726 BFD_ASSERT (my_offset <= globals->arm_glue_size);
2728 tmp = bfd_get_32 (input_bfd, hit_data);
2729 tmp = tmp & 0xFF000000;
2731 /* Somehow these are both 4 too far, so subtract 8. */
2732 ret_offset = (s->output_offset
2733 + my_offset
2734 + s->output_section->vma
2735 - (input_section->output_offset
2736 + input_section->output_section->vma
2737 + offset + addend)
2738 - 8);
2740 tmp = tmp | ((ret_offset >> 2) & 0x00FFFFFF);
2742 bfd_put_32 (output_bfd, (bfd_vma) tmp, hit_data - input_section->vma);
2744 return TRUE;
2747 /* Some relocations map to different relocations depending on the
2748 target. Return the real relocation. */
2749 static int
2750 arm_real_reloc_type (struct elf32_arm_link_hash_table * globals,
2751 int r_type)
2753 switch (r_type)
2755 case R_ARM_TARGET1:
2756 if (globals->target1_is_rel)
2757 return R_ARM_REL32;
2758 else
2759 return R_ARM_ABS32;
2761 case R_ARM_TARGET2:
2762 return globals->target2_reloc;
2764 default:
2765 return r_type;
2769 /* Return the base VMA address which should be subtracted from real addresses
2770 when resolving @dtpoff relocation.
2771 This is PT_TLS segment p_vaddr. */
2773 static bfd_vma
2774 dtpoff_base (struct bfd_link_info *info)
2776 /* If tls_sec is NULL, we should have signalled an error already. */
2777 if (elf_hash_table (info)->tls_sec == NULL)
2778 return 0;
2779 return elf_hash_table (info)->tls_sec->vma;
2782 /* Return the relocation value for @tpoff relocation
2783 if STT_TLS virtual address is ADDRESS. */
2785 static bfd_vma
2786 tpoff (struct bfd_link_info *info, bfd_vma address)
2788 struct elf_link_hash_table *htab = elf_hash_table (info);
2789 bfd_vma base;
2791 /* If tls_sec is NULL, we should have signalled an error already. */
2792 if (htab->tls_sec == NULL)
2793 return 0;
2794 base = align_power ((bfd_vma) TCB_SIZE, htab->tls_sec->alignment_power);
2795 return address - htab->tls_sec->vma + base;
2798 /* Perform a relocation as part of a final link. */
2800 static bfd_reloc_status_type
2801 elf32_arm_final_link_relocate (reloc_howto_type * howto,
2802 bfd * input_bfd,
2803 bfd * output_bfd,
2804 asection * input_section,
2805 bfd_byte * contents,
2806 Elf_Internal_Rela * rel,
2807 bfd_vma value,
2808 struct bfd_link_info * info,
2809 asection * sym_sec,
2810 const char * sym_name,
2811 int sym_flags,
2812 struct elf_link_hash_entry * h,
2813 bfd_boolean * unresolved_reloc_p)
2815 unsigned long r_type = howto->type;
2816 unsigned long r_symndx;
2817 bfd_byte * hit_data = contents + rel->r_offset;
2818 bfd * dynobj = NULL;
2819 Elf_Internal_Shdr * symtab_hdr;
2820 struct elf_link_hash_entry ** sym_hashes;
2821 bfd_vma * local_got_offsets;
2822 asection * sgot = NULL;
2823 asection * splt = NULL;
2824 asection * sreloc = NULL;
2825 bfd_vma addend;
2826 bfd_signed_vma signed_addend;
2827 struct elf32_arm_link_hash_table * globals;
2829 globals = elf32_arm_hash_table (info);
2831 /* Some relocation type map to different relocations depending on the
2832 target. We pick the right one here. */
2833 r_type = arm_real_reloc_type (globals, r_type);
2834 if (r_type != howto->type)
2835 howto = elf32_arm_howto_from_type (r_type);
2837 /* If the start address has been set, then set the EF_ARM_HASENTRY
2838 flag. Setting this more than once is redundant, but the cost is
2839 not too high, and it keeps the code simple.
2841 The test is done here, rather than somewhere else, because the
2842 start address is only set just before the final link commences.
2844 Note - if the user deliberately sets a start address of 0, the
2845 flag will not be set. */
2846 if (bfd_get_start_address (output_bfd) != 0)
2847 elf_elfheader (output_bfd)->e_flags |= EF_ARM_HASENTRY;
2849 dynobj = elf_hash_table (info)->dynobj;
2850 if (dynobj)
2852 sgot = bfd_get_section_by_name (dynobj, ".got");
2853 splt = bfd_get_section_by_name (dynobj, ".plt");
2855 symtab_hdr = & elf_tdata (input_bfd)->symtab_hdr;
2856 sym_hashes = elf_sym_hashes (input_bfd);
2857 local_got_offsets = elf_local_got_offsets (input_bfd);
2858 r_symndx = ELF32_R_SYM (rel->r_info);
2860 if (globals->use_rel)
2862 addend = bfd_get_32 (input_bfd, hit_data) & howto->src_mask;
2864 if (addend & ((howto->src_mask + 1) >> 1))
2866 signed_addend = -1;
2867 signed_addend &= ~ howto->src_mask;
2868 signed_addend |= addend;
2870 else
2871 signed_addend = addend;
2873 else
2874 addend = signed_addend = rel->r_addend;
2876 switch (r_type)
2878 case R_ARM_NONE:
2879 /* We don't need to find a value for this symbol. It's just a
2880 marker. */
2881 *unresolved_reloc_p = FALSE;
2882 return bfd_reloc_ok;
2884 case R_ARM_PC24:
2885 case R_ARM_ABS32:
2886 case R_ARM_REL32:
2887 case R_ARM_CALL:
2888 case R_ARM_JUMP24:
2889 case R_ARM_XPC25:
2890 case R_ARM_PREL31:
2891 case R_ARM_PLT32:
2892 /* r_symndx will be zero only for relocs against symbols
2893 from removed linkonce sections, or sections discarded by
2894 a linker script. */
2895 if (r_symndx == 0)
2896 return bfd_reloc_ok;
2898 /* Handle relocations which should use the PLT entry. ABS32/REL32
2899 will use the symbol's value, which may point to a PLT entry, but we
2900 don't need to handle that here. If we created a PLT entry, all
2901 branches in this object should go to it. */
2902 if ((r_type != R_ARM_ABS32 && r_type != R_ARM_REL32)
2903 && h != NULL
2904 && splt != NULL
2905 && h->plt.offset != (bfd_vma) -1)
2907 /* If we've created a .plt section, and assigned a PLT entry to
2908 this function, it should not be known to bind locally. If
2909 it were, we would have cleared the PLT entry. */
2910 BFD_ASSERT (!SYMBOL_CALLS_LOCAL (info, h));
2912 value = (splt->output_section->vma
2913 + splt->output_offset
2914 + h->plt.offset);
2915 *unresolved_reloc_p = FALSE;
2916 return _bfd_final_link_relocate (howto, input_bfd, input_section,
2917 contents, rel->r_offset, value,
2918 (bfd_vma) 0);
2921 /* When generating a shared object or relocatable executable, these
2922 relocations are copied into the output file to be resolved at
2923 run time. */
2924 if ((info->shared || globals->root.is_relocatable_executable)
2925 && (input_section->flags & SEC_ALLOC)
2926 && (r_type != R_ARM_REL32
2927 || !SYMBOL_CALLS_LOCAL (info, h))
2928 && (h == NULL
2929 || ELF_ST_VISIBILITY (h->other) == STV_DEFAULT
2930 || h->root.type != bfd_link_hash_undefweak)
2931 && r_type != R_ARM_PC24
2932 && r_type != R_ARM_CALL
2933 && r_type != R_ARM_JUMP24
2934 && r_type != R_ARM_PREL31
2935 && r_type != R_ARM_PLT32)
2937 Elf_Internal_Rela outrel;
2938 bfd_byte *loc;
2939 bfd_boolean skip, relocate;
2941 *unresolved_reloc_p = FALSE;
2943 if (sreloc == NULL)
2945 const char * name;
2947 name = (bfd_elf_string_from_elf_section
2948 (input_bfd,
2949 elf_elfheader (input_bfd)->e_shstrndx,
2950 elf_section_data (input_section)->rel_hdr.sh_name));
2951 if (name == NULL)
2952 return bfd_reloc_notsupported;
2954 BFD_ASSERT (strncmp (name, ".rel", 4) == 0
2955 && strcmp (bfd_get_section_name (input_bfd,
2956 input_section),
2957 name + 4) == 0);
2959 sreloc = bfd_get_section_by_name (dynobj, name);
2960 BFD_ASSERT (sreloc != NULL);
2963 skip = FALSE;
2964 relocate = FALSE;
2966 outrel.r_offset =
2967 _bfd_elf_section_offset (output_bfd, info, input_section,
2968 rel->r_offset);
2969 if (outrel.r_offset == (bfd_vma) -1)
2970 skip = TRUE;
2971 else if (outrel.r_offset == (bfd_vma) -2)
2972 skip = TRUE, relocate = TRUE;
2973 outrel.r_offset += (input_section->output_section->vma
2974 + input_section->output_offset);
2976 if (skip)
2977 memset (&outrel, 0, sizeof outrel);
2978 else if (h != NULL
2979 && h->dynindx != -1
2980 && (!info->shared
2981 || !info->symbolic
2982 || !h->def_regular))
2983 outrel.r_info = ELF32_R_INFO (h->dynindx, r_type);
2984 else
2986 int symbol;
2988 /* This symbol is local, or marked to become local. */
2989 relocate = TRUE;
2990 if (sym_flags == STT_ARM_TFUNC)
2991 value |= 1;
2992 if (globals->symbian_p)
2994 /* On Symbian OS, the data segment and text segement
2995 can be relocated independently. Therefore, we
2996 must indicate the segment to which this
2997 relocation is relative. The BPABI allows us to
2998 use any symbol in the right segment; we just use
2999 the section symbol as it is convenient. (We
3000 cannot use the symbol given by "h" directly as it
3001 will not appear in the dynamic symbol table.) */
3002 if (sym_sec)
3003 symbol = elf_section_data (sym_sec->output_section)->dynindx;
3004 else
3005 symbol = elf_section_data (input_section->output_section)->dynindx;
3006 BFD_ASSERT (symbol != 0);
3008 else
3009 /* On SVR4-ish systems, the dynamic loader cannot
3010 relocate the text and data segments independently,
3011 so the symbol does not matter. */
3012 symbol = 0;
3013 outrel.r_info = ELF32_R_INFO (symbol, R_ARM_RELATIVE);
3016 loc = sreloc->contents;
3017 loc += sreloc->reloc_count++ * sizeof (Elf32_External_Rel);
3018 bfd_elf32_swap_reloc_out (output_bfd, &outrel, loc);
3020 /* If this reloc is against an external symbol, we do not want to
3021 fiddle with the addend. Otherwise, we need to include the symbol
3022 value so that it becomes an addend for the dynamic reloc. */
3023 if (! relocate)
3024 return bfd_reloc_ok;
3026 return _bfd_final_link_relocate (howto, input_bfd, input_section,
3027 contents, rel->r_offset, value,
3028 (bfd_vma) 0);
3030 else switch (r_type)
3032 case R_ARM_XPC25: /* Arm BLX instruction. */
3033 case R_ARM_CALL:
3034 case R_ARM_JUMP24:
3035 case R_ARM_PC24: /* Arm B/BL instruction */
3036 case R_ARM_PLT32:
3037 if (r_type == R_ARM_XPC25)
3039 /* Check for Arm calling Arm function. */
3040 /* FIXME: Should we translate the instruction into a BL
3041 instruction instead ? */
3042 if (sym_flags != STT_ARM_TFUNC)
3043 (*_bfd_error_handler)
3044 (_("\%B: Warning: Arm BLX instruction targets Arm function '%s'."),
3045 input_bfd,
3046 h ? h->root.root.string : "(local)");
3048 else
3050 /* Check for Arm calling Thumb function. */
3051 if (sym_flags == STT_ARM_TFUNC)
3053 elf32_arm_to_thumb_stub (info, sym_name, input_bfd,
3054 output_bfd, input_section,
3055 hit_data, sym_sec, rel->r_offset,
3056 signed_addend, value);
3057 return bfd_reloc_ok;
3061 /* The ARM ELF ABI says that this reloc is computed as: S - P + A
3062 where:
3063 S is the address of the symbol in the relocation.
3064 P is address of the instruction being relocated.
3065 A is the addend (extracted from the instruction) in bytes.
3067 S is held in 'value'.
3068 P is the base address of the section containing the
3069 instruction plus the offset of the reloc into that
3070 section, ie:
3071 (input_section->output_section->vma +
3072 input_section->output_offset +
3073 rel->r_offset).
3074 A is the addend, converted into bytes, ie:
3075 (signed_addend * 4)
3077 Note: None of these operations have knowledge of the pipeline
3078 size of the processor, thus it is up to the assembler to
3079 encode this information into the addend. */
3080 value -= (input_section->output_section->vma
3081 + input_section->output_offset);
3082 value -= rel->r_offset;
3083 if (globals->use_rel)
3084 value += (signed_addend << howto->size);
3085 else
3086 /* RELA addends do not have to be adjusted by howto->size. */
3087 value += signed_addend;
3089 signed_addend = value;
3090 signed_addend >>= howto->rightshift;
3092 /* It is not an error for an undefined weak reference to be
3093 out of range. Any program that branches to such a symbol
3094 is going to crash anyway, so there is no point worrying
3095 about getting the destination exactly right. */
3096 if (! h || h->root.type != bfd_link_hash_undefweak)
3098 /* Perform a signed range check. */
3099 if ( signed_addend > ((bfd_signed_vma) (howto->dst_mask >> 1))
3100 || signed_addend < - ((bfd_signed_vma) ((howto->dst_mask + 1) >> 1)))
3101 return bfd_reloc_overflow;
3104 /* If necessary set the H bit in the BLX instruction. */
3105 if (r_type == R_ARM_XPC25 && ((value & 2) == 2))
3106 value = (signed_addend & howto->dst_mask)
3107 | (bfd_get_32 (input_bfd, hit_data) & (~ howto->dst_mask))
3108 | (1 << 24);
3109 else
3110 value = (signed_addend & howto->dst_mask)
3111 | (bfd_get_32 (input_bfd, hit_data) & (~ howto->dst_mask));
3112 break;
3114 case R_ARM_ABS32:
3115 value += addend;
3116 if (sym_flags == STT_ARM_TFUNC)
3117 value |= 1;
3118 break;
3120 case R_ARM_REL32:
3121 value -= (input_section->output_section->vma
3122 + input_section->output_offset + rel->r_offset);
3123 value += addend;
3124 break;
3126 case R_ARM_PREL31:
3127 value -= (input_section->output_section->vma
3128 + input_section->output_offset + rel->r_offset);
3129 value += signed_addend;
3130 if (! h || h->root.type != bfd_link_hash_undefweak)
3132 /* Check for overflow */
3133 if ((value ^ (value >> 1)) & (1 << 30))
3134 return bfd_reloc_overflow;
3136 value &= 0x7fffffff;
3137 value |= (bfd_get_32 (input_bfd, hit_data) & 0x80000000);
3138 if (sym_flags == STT_ARM_TFUNC)
3139 value |= 1;
3140 break;
3143 bfd_put_32 (input_bfd, value, hit_data);
3144 return bfd_reloc_ok;
3146 case R_ARM_ABS8:
3147 value += addend;
3148 if ((long) value > 0x7f || (long) value < -0x80)
3149 return bfd_reloc_overflow;
3151 bfd_put_8 (input_bfd, value, hit_data);
3152 return bfd_reloc_ok;
3154 case R_ARM_ABS16:
3155 value += addend;
3157 if ((long) value > 0x7fff || (long) value < -0x8000)
3158 return bfd_reloc_overflow;
3160 bfd_put_16 (input_bfd, value, hit_data);
3161 return bfd_reloc_ok;
3163 case R_ARM_ABS12:
3164 /* Support ldr and str instruction for the arm */
3165 /* Also thumb b (unconditional branch). ??? Really? */
3166 value += addend;
3168 if ((long) value > 0x7ff || (long) value < -0x800)
3169 return bfd_reloc_overflow;
3171 value |= (bfd_get_32 (input_bfd, hit_data) & 0xfffff000);
3172 bfd_put_32 (input_bfd, value, hit_data);
3173 return bfd_reloc_ok;
3175 case R_ARM_THM_ABS5:
3176 /* Support ldr and str instructions for the thumb. */
3177 if (globals->use_rel)
3179 /* Need to refetch addend. */
3180 addend = bfd_get_16 (input_bfd, hit_data) & howto->src_mask;
3181 /* ??? Need to determine shift amount from operand size. */
3182 addend >>= howto->rightshift;
3184 value += addend;
3186 /* ??? Isn't value unsigned? */
3187 if ((long) value > 0x1f || (long) value < -0x10)
3188 return bfd_reloc_overflow;
3190 /* ??? Value needs to be properly shifted into place first. */
3191 value |= bfd_get_16 (input_bfd, hit_data) & 0xf83f;
3192 bfd_put_16 (input_bfd, value, hit_data);
3193 return bfd_reloc_ok;
3195 case R_ARM_THM_XPC22:
3196 case R_ARM_THM_CALL:
3197 /* Thumb BL (branch long instruction). */
3199 bfd_vma relocation;
3200 bfd_boolean overflow = FALSE;
3201 bfd_vma upper_insn = bfd_get_16 (input_bfd, hit_data);
3202 bfd_vma lower_insn = bfd_get_16 (input_bfd, hit_data + 2);
3203 bfd_signed_vma reloc_signed_max = ((1 << (howto->bitsize - 1)) - 1) >> howto->rightshift;
3204 bfd_signed_vma reloc_signed_min = ~ reloc_signed_max;
3205 bfd_vma check;
3206 bfd_signed_vma signed_check;
3207 bfd_boolean thumb_plt_call = FALSE;
3209 /* Need to refetch the addend and squish the two 11 bit pieces
3210 together. */
3211 if (globals->use_rel)
3213 bfd_vma upper = upper_insn & 0x7ff;
3214 bfd_vma lower = lower_insn & 0x7ff;
3215 upper = (upper ^ 0x400) - 0x400; /* Sign extend. */
3216 addend = (upper << 12) | (lower << 1);
3217 signed_addend = addend;
3220 if (r_type == R_ARM_THM_XPC22)
3222 /* Check for Thumb to Thumb call. */
3223 /* FIXME: Should we translate the instruction into a BL
3224 instruction instead ? */
3225 if (sym_flags == STT_ARM_TFUNC)
3226 (*_bfd_error_handler)
3227 (_("%B: Warning: Thumb BLX instruction targets thumb function '%s'."),
3228 input_bfd,
3229 h ? h->root.root.string : "(local)");
3231 else
3233 /* If it is not a call to Thumb, assume call to Arm.
3234 If it is a call relative to a section name, then it is not a
3235 function call at all, but rather a long jump. Calls through
3236 the PLT do not require stubs. */
3237 if (sym_flags != STT_ARM_TFUNC && sym_flags != STT_SECTION
3238 && (h == NULL || splt == NULL
3239 || h->plt.offset == (bfd_vma) -1))
3241 if (elf32_thumb_to_arm_stub
3242 (info, sym_name, input_bfd, output_bfd, input_section,
3243 hit_data, sym_sec, rel->r_offset, signed_addend, value))
3244 return bfd_reloc_ok;
3245 else
3246 return bfd_reloc_dangerous;
3250 /* Handle calls via the PLT. */
3251 if (h != NULL && splt != NULL && h->plt.offset != (bfd_vma) -1)
3253 value = (splt->output_section->vma
3254 + splt->output_offset
3255 + h->plt.offset);
3256 if (globals->use_blx)
3258 /* If the Thumb BLX instruction is available, convert the
3259 BL to a BLX instruction to call the ARM-mode PLT entry. */
3260 if ((lower_insn & (0x3 << 11)) == 0x3 << 11)
3262 lower_insn = (lower_insn & ~(0x3 << 11)) | 0x1 << 11;
3263 thumb_plt_call = TRUE;
3266 else
3267 /* Target the Thumb stub before the ARM PLT entry. */
3268 value -= PLT_THUMB_STUB_SIZE;
3269 *unresolved_reloc_p = FALSE;
3272 relocation = value + signed_addend;
3274 relocation -= (input_section->output_section->vma
3275 + input_section->output_offset
3276 + rel->r_offset);
3278 check = relocation >> howto->rightshift;
3280 /* If this is a signed value, the rightshift just dropped
3281 leading 1 bits (assuming twos complement). */
3282 if ((bfd_signed_vma) relocation >= 0)
3283 signed_check = check;
3284 else
3285 signed_check = check | ~((bfd_vma) -1 >> howto->rightshift);
3287 /* Assumes two's complement. */
3288 if (signed_check > reloc_signed_max || signed_check < reloc_signed_min)
3289 overflow = TRUE;
3291 if ((r_type == R_ARM_THM_XPC22
3292 && ((lower_insn & 0x1800) == 0x0800))
3293 || thumb_plt_call)
3294 /* For a BLX instruction, make sure that the relocation is rounded up
3295 to a word boundary. This follows the semantics of the instruction
3296 which specifies that bit 1 of the target address will come from bit
3297 1 of the base address. */
3298 relocation = (relocation + 2) & ~ 3;
3300 /* Put RELOCATION back into the insn. */
3301 upper_insn = (upper_insn & ~(bfd_vma) 0x7ff) | ((relocation >> 12) & 0x7ff);
3302 lower_insn = (lower_insn & ~(bfd_vma) 0x7ff) | ((relocation >> 1) & 0x7ff);
3304 /* Put the relocated value back in the object file: */
3305 bfd_put_16 (input_bfd, upper_insn, hit_data);
3306 bfd_put_16 (input_bfd, lower_insn, hit_data + 2);
3308 return (overflow ? bfd_reloc_overflow : bfd_reloc_ok);
3310 break;
3312 case R_ARM_THM_JUMP24:
3313 /* Thumb32 unconditional branch instruction. */
3315 bfd_vma relocation;
3316 bfd_boolean overflow = FALSE;
3317 bfd_vma upper_insn = bfd_get_16 (input_bfd, hit_data);
3318 bfd_vma lower_insn = bfd_get_16 (input_bfd, hit_data + 2);
3319 bfd_signed_vma reloc_signed_max = ((1 << (howto->bitsize - 1)) - 1) >> howto->rightshift;
3320 bfd_signed_vma reloc_signed_min = ~ reloc_signed_max;
3321 bfd_vma check;
3322 bfd_signed_vma signed_check;
3324 /* Need to refetch the addend, reconstruct the top three bits, and glue the
3325 two pieces together. */
3326 if (globals->use_rel)
3328 bfd_vma S = (upper_insn & 0x0400) >> 10;
3329 bfd_vma hi = (upper_insn & 0x03ff);
3330 bfd_vma I1 = (lower_insn & 0x2000) >> 13;
3331 bfd_vma I2 = (lower_insn & 0x0800) >> 11;
3332 bfd_vma lo = (lower_insn & 0x07ff);
3334 I1 = !(I1 ^ S);
3335 I2 = !(I2 ^ S);
3336 S = !S;
3338 signed_addend = (S << 24) | (I1 << 23) | (I2 << 22) | (hi << 12) | (lo << 1);
3339 signed_addend -= (1 << 24); /* Sign extend. */
3342 /* ??? Should handle interworking? GCC might someday try to
3343 use this for tail calls. */
3345 relocation = value + signed_addend;
3346 relocation -= (input_section->output_section->vma
3347 + input_section->output_offset
3348 + rel->r_offset);
3350 check = relocation >> howto->rightshift;
3352 /* If this is a signed value, the rightshift just dropped
3353 leading 1 bits (assuming twos complement). */
3354 if ((bfd_signed_vma) relocation >= 0)
3355 signed_check = check;
3356 else
3357 signed_check = check | ~((bfd_vma) -1 >> howto->rightshift);
3359 /* Assumes two's complement. */
3360 if (signed_check > reloc_signed_max || signed_check < reloc_signed_min)
3361 overflow = TRUE;
3363 /* Put RELOCATION back into the insn. */
3365 bfd_vma S = (relocation & 0x01000000) >> 24;
3366 bfd_vma I1 = (relocation & 0x00800000) >> 23;
3367 bfd_vma I2 = (relocation & 0x00400000) >> 22;
3368 bfd_vma hi = (relocation & 0x003ff000) >> 12;
3369 bfd_vma lo = (relocation & 0x00000ffe) >> 1;
3371 I1 = !(I1 ^ S);
3372 I2 = !(I2 ^ S);
3374 upper_insn = (upper_insn & (bfd_vma) 0xf800) | (S << 10) | hi;
3375 lower_insn = (lower_insn & (bfd_vma) 0xd000) | (I1 << 13) | (I2 << 11) | lo;
3378 /* Put the relocated value back in the object file: */
3379 bfd_put_16 (input_bfd, upper_insn, hit_data);
3380 bfd_put_16 (input_bfd, lower_insn, hit_data + 2);
3382 return (overflow ? bfd_reloc_overflow : bfd_reloc_ok);
3385 case R_ARM_THM_JUMP19:
3386 /* Thumb32 conditional branch instruction. */
3388 bfd_vma relocation;
3389 bfd_boolean overflow = FALSE;
3390 bfd_vma upper_insn = bfd_get_16 (input_bfd, hit_data);
3391 bfd_vma lower_insn = bfd_get_16 (input_bfd, hit_data + 2);
3392 bfd_signed_vma reloc_signed_max = ((1 << (howto->bitsize - 1)) - 1) >> howto->rightshift;
3393 bfd_signed_vma reloc_signed_min = ~ reloc_signed_max;
3394 bfd_vma check;
3395 bfd_signed_vma signed_check;
3397 /* Need to refetch the addend, reconstruct the top three bits,
3398 and squish the two 11 bit pieces together. */
3399 if (globals->use_rel)
3401 bfd_vma S = (upper_insn & 0x0400) >> 10;
3402 bfd_vma upper = (upper_insn & 0x001f);
3403 bfd_vma J1 = (lower_insn & 0x2000) >> 13;
3404 bfd_vma J2 = (lower_insn & 0x0800) >> 11;
3405 bfd_vma lower = (lower_insn & 0x07ff);
3407 upper |= J2 << 6;
3408 upper |= J1 << 7;
3409 upper |= ~S << 8;
3410 upper -= 0x0100; /* Sign extend. */
3412 addend = (upper << 12) | (lower << 1);
3413 signed_addend = addend;
3416 /* ??? Should handle interworking? GCC might someday try to
3417 use this for tail calls. */
3419 relocation = value + signed_addend;
3420 relocation -= (input_section->output_section->vma
3421 + input_section->output_offset
3422 + rel->r_offset);
3424 check = relocation >> howto->rightshift;
3426 /* If this is a signed value, the rightshift just dropped
3427 leading 1 bits (assuming twos complement). */
3428 if ((bfd_signed_vma) relocation >= 0)
3429 signed_check = check;
3430 else
3431 signed_check = check | ~((bfd_vma) -1 >> howto->rightshift);
3433 /* Assumes two's complement. */
3434 if (signed_check > reloc_signed_max || signed_check < reloc_signed_min)
3435 overflow = TRUE;
3437 /* Put RELOCATION back into the insn. */
3439 bfd_vma S = (relocation & 0x00100000) >> 20;
3440 bfd_vma J2 = (relocation & 0x00080000) >> 19;
3441 bfd_vma J1 = (relocation & 0x00040000) >> 18;
3442 bfd_vma hi = (relocation & 0x0003f000) >> 12;
3443 bfd_vma lo = (relocation & 0x00000ffe) >> 1;
3445 upper_insn = (upper_insn & 0xfb30) | (S << 10) | hi;
3446 lower_insn = (lower_insn & 0xd000) | (J1 << 13) | (J2 << 11) | lo;
3449 /* Put the relocated value back in the object file: */
3450 bfd_put_16 (input_bfd, upper_insn, hit_data);
3451 bfd_put_16 (input_bfd, lower_insn, hit_data + 2);
3453 return (overflow ? bfd_reloc_overflow : bfd_reloc_ok);
3456 case R_ARM_THM_JUMP11:
3457 case R_ARM_THM_JUMP8:
3458 case R_ARM_THM_JUMP6:
3459 /* Thumb B (branch) instruction). */
3461 bfd_signed_vma relocation;
3462 bfd_signed_vma reloc_signed_max = (1 << (howto->bitsize - 1)) - 1;
3463 bfd_signed_vma reloc_signed_min = ~ reloc_signed_max;
3464 bfd_signed_vma signed_check;
3466 /* CZB cannot jump backward. */
3467 if (r_type == R_ARM_THM_JUMP6)
3468 reloc_signed_min = 0;
3470 if (globals->use_rel)
3472 /* Need to refetch addend. */
3473 addend = bfd_get_16 (input_bfd, hit_data) & howto->src_mask;
3474 if (addend & ((howto->src_mask + 1) >> 1))
3476 signed_addend = -1;
3477 signed_addend &= ~ howto->src_mask;
3478 signed_addend |= addend;
3480 else
3481 signed_addend = addend;
3482 /* The value in the insn has been right shifted. We need to
3483 undo this, so that we can perform the address calculation
3484 in terms of bytes. */
3485 signed_addend <<= howto->rightshift;
3487 relocation = value + signed_addend;
3489 relocation -= (input_section->output_section->vma
3490 + input_section->output_offset
3491 + rel->r_offset);
3493 relocation >>= howto->rightshift;
3494 signed_check = relocation;
3496 if (r_type == R_ARM_THM_JUMP6)
3497 relocation = ((relocation & 0x0020) << 4) | ((relocation & 0x001f) << 3);
3498 else
3499 relocation &= howto->dst_mask;
3500 relocation |= (bfd_get_16 (input_bfd, hit_data) & (~ howto->dst_mask));
3502 bfd_put_16 (input_bfd, relocation, hit_data);
3504 /* Assumes two's complement. */
3505 if (signed_check > reloc_signed_max || signed_check < reloc_signed_min)
3506 return bfd_reloc_overflow;
3508 return bfd_reloc_ok;
3511 case R_ARM_ALU_PCREL7_0:
3512 case R_ARM_ALU_PCREL15_8:
3513 case R_ARM_ALU_PCREL23_15:
3515 bfd_vma insn;
3516 bfd_vma relocation;
3518 insn = bfd_get_32 (input_bfd, hit_data);
3519 if (globals->use_rel)
3521 /* Extract the addend. */
3522 addend = (insn & 0xff) << ((insn & 0xf00) >> 7);
3523 signed_addend = addend;
3525 relocation = value + signed_addend;
3527 relocation -= (input_section->output_section->vma
3528 + input_section->output_offset
3529 + rel->r_offset);
3530 insn = (insn & ~0xfff)
3531 | ((howto->bitpos << 7) & 0xf00)
3532 | ((relocation >> howto->bitpos) & 0xff);
3533 bfd_put_32 (input_bfd, value, hit_data);
3535 return bfd_reloc_ok;
3537 case R_ARM_GNU_VTINHERIT:
3538 case R_ARM_GNU_VTENTRY:
3539 return bfd_reloc_ok;
3541 case R_ARM_GOTOFF32:
3542 /* Relocation is relative to the start of the
3543 global offset table. */
3545 BFD_ASSERT (sgot != NULL);
3546 if (sgot == NULL)
3547 return bfd_reloc_notsupported;
3549 /* If we are addressing a Thumb function, we need to adjust the
3550 address by one, so that attempts to call the function pointer will
3551 correctly interpret it as Thumb code. */
3552 if (sym_flags == STT_ARM_TFUNC)
3553 value += 1;
3555 /* Note that sgot->output_offset is not involved in this
3556 calculation. We always want the start of .got. If we
3557 define _GLOBAL_OFFSET_TABLE in a different way, as is
3558 permitted by the ABI, we might have to change this
3559 calculation. */
3560 value -= sgot->output_section->vma;
3561 return _bfd_final_link_relocate (howto, input_bfd, input_section,
3562 contents, rel->r_offset, value,
3563 (bfd_vma) 0);
3565 case R_ARM_GOTPC:
3566 /* Use global offset table as symbol value. */
3567 BFD_ASSERT (sgot != NULL);
3569 if (sgot == NULL)
3570 return bfd_reloc_notsupported;
3572 *unresolved_reloc_p = FALSE;
3573 value = sgot->output_section->vma;
3574 return _bfd_final_link_relocate (howto, input_bfd, input_section,
3575 contents, rel->r_offset, value,
3576 (bfd_vma) 0);
3578 case R_ARM_GOT32:
3579 case R_ARM_GOT_PREL:
3580 /* Relocation is to the entry for this symbol in the
3581 global offset table. */
3582 if (sgot == NULL)
3583 return bfd_reloc_notsupported;
3585 if (h != NULL)
3587 bfd_vma off;
3588 bfd_boolean dyn;
3590 off = h->got.offset;
3591 BFD_ASSERT (off != (bfd_vma) -1);
3592 dyn = globals->root.dynamic_sections_created;
3594 if (! WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn, info->shared, h)
3595 || (info->shared
3596 && SYMBOL_REFERENCES_LOCAL (info, h))
3597 || (ELF_ST_VISIBILITY (h->other)
3598 && h->root.type == bfd_link_hash_undefweak))
3600 /* This is actually a static link, or it is a -Bsymbolic link
3601 and the symbol is defined locally. We must initialize this
3602 entry in the global offset table. Since the offset must
3603 always be a multiple of 4, we use the least significant bit
3604 to record whether we have initialized it already.
3606 When doing a dynamic link, we create a .rel.got relocation
3607 entry to initialize the value. This is done in the
3608 finish_dynamic_symbol routine. */
3609 if ((off & 1) != 0)
3610 off &= ~1;
3611 else
3613 /* If we are addressing a Thumb function, we need to
3614 adjust the address by one, so that attempts to
3615 call the function pointer will correctly
3616 interpret it as Thumb code. */
3617 if (sym_flags == STT_ARM_TFUNC)
3618 value |= 1;
3620 bfd_put_32 (output_bfd, value, sgot->contents + off);
3621 h->got.offset |= 1;
3624 else
3625 *unresolved_reloc_p = FALSE;
3627 value = sgot->output_offset + off;
3629 else
3631 bfd_vma off;
3633 BFD_ASSERT (local_got_offsets != NULL &&
3634 local_got_offsets[r_symndx] != (bfd_vma) -1);
3636 off = local_got_offsets[r_symndx];
3638 /* The offset must always be a multiple of 4. We use the
3639 least significant bit to record whether we have already
3640 generated the necessary reloc. */
3641 if ((off & 1) != 0)
3642 off &= ~1;
3643 else
3645 /* If we are addressing a Thumb function, we need to
3646 adjust the address by one, so that attempts to
3647 call the function pointer will correctly
3648 interpret it as Thumb code. */
3649 if (sym_flags == STT_ARM_TFUNC)
3650 value |= 1;
3652 bfd_put_32 (output_bfd, value, sgot->contents + off);
3654 if (info->shared)
3656 asection * srelgot;
3657 Elf_Internal_Rela outrel;
3658 bfd_byte *loc;
3660 srelgot = bfd_get_section_by_name (dynobj, ".rel.got");
3661 BFD_ASSERT (srelgot != NULL);
3663 outrel.r_offset = (sgot->output_section->vma
3664 + sgot->output_offset
3665 + off);
3666 outrel.r_info = ELF32_R_INFO (0, R_ARM_RELATIVE);
3667 loc = srelgot->contents;
3668 loc += srelgot->reloc_count++ * sizeof (Elf32_External_Rel);
3669 bfd_elf32_swap_reloc_out (output_bfd, &outrel, loc);
3672 local_got_offsets[r_symndx] |= 1;
3675 value = sgot->output_offset + off;
3677 if (r_type != R_ARM_GOT32)
3678 value += sgot->output_section->vma;
3680 return _bfd_final_link_relocate (howto, input_bfd, input_section,
3681 contents, rel->r_offset, value,
3682 (bfd_vma) 0);
3684 case R_ARM_TLS_LDO32:
3685 value = value - dtpoff_base (info);
3687 return _bfd_final_link_relocate (howto, input_bfd, input_section,
3688 contents, rel->r_offset, value, (bfd_vma) 0);
3690 case R_ARM_TLS_LDM32:
3692 bfd_vma off;
3694 if (globals->sgot == NULL)
3695 abort ();
3697 off = globals->tls_ldm_got.offset;
3699 if ((off & 1) != 0)
3700 off &= ~1;
3701 else
3703 /* If we don't know the module number, create a relocation
3704 for it. */
3705 if (info->shared)
3707 Elf_Internal_Rela outrel;
3708 bfd_byte *loc;
3710 if (globals->srelgot == NULL)
3711 abort ();
3713 outrel.r_offset = (globals->sgot->output_section->vma
3714 + globals->sgot->output_offset + off);
3715 outrel.r_info = ELF32_R_INFO (0, R_ARM_TLS_DTPMOD32);
3717 bfd_put_32 (output_bfd, 0, globals->sgot->contents + off);
3719 loc = globals->srelgot->contents;
3720 loc += globals->srelgot->reloc_count++ * sizeof (Elf32_External_Rel);
3721 bfd_elf32_swap_reloc_out (output_bfd, &outrel, loc);
3723 else
3724 bfd_put_32 (output_bfd, 1, globals->sgot->contents + off);
3726 globals->tls_ldm_got.offset |= 1;
3729 value = globals->sgot->output_section->vma + globals->sgot->output_offset + off
3730 - (input_section->output_section->vma + input_section->output_offset + rel->r_offset);
3732 return _bfd_final_link_relocate (howto, input_bfd, input_section,
3733 contents, rel->r_offset, value,
3734 (bfd_vma) 0);
3737 case R_ARM_TLS_GD32:
3738 case R_ARM_TLS_IE32:
3740 bfd_vma off;
3741 int indx;
3742 char tls_type;
3744 if (globals->sgot == NULL)
3745 abort ();
3747 indx = 0;
3748 if (h != NULL)
3750 bfd_boolean dyn;
3751 dyn = globals->root.dynamic_sections_created;
3752 if (WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn, info->shared, h)
3753 && (!info->shared
3754 || !SYMBOL_REFERENCES_LOCAL (info, h)))
3756 *unresolved_reloc_p = FALSE;
3757 indx = h->dynindx;
3759 off = h->got.offset;
3760 tls_type = ((struct elf32_arm_link_hash_entry *) h)->tls_type;
3762 else
3764 if (local_got_offsets == NULL)
3765 abort ();
3766 off = local_got_offsets[r_symndx];
3767 tls_type = elf32_arm_local_got_tls_type (input_bfd)[r_symndx];
3770 if (tls_type == GOT_UNKNOWN)
3771 abort ();
3773 if ((off & 1) != 0)
3774 off &= ~1;
3775 else
3777 bfd_boolean need_relocs = FALSE;
3778 Elf_Internal_Rela outrel;
3779 bfd_byte *loc = NULL;
3780 int cur_off = off;
3782 /* The GOT entries have not been initialized yet. Do it
3783 now, and emit any relocations. If both an IE GOT and a
3784 GD GOT are necessary, we emit the GD first. */
3786 if ((info->shared || indx != 0)
3787 && (h == NULL
3788 || ELF_ST_VISIBILITY (h->other) == STV_DEFAULT
3789 || h->root.type != bfd_link_hash_undefweak))
3791 need_relocs = TRUE;
3792 if (globals->srelgot == NULL)
3793 abort ();
3794 loc = globals->srelgot->contents;
3795 loc += globals->srelgot->reloc_count * sizeof (Elf32_External_Rel);
3798 if (tls_type & GOT_TLS_GD)
3800 if (need_relocs)
3802 outrel.r_offset = (globals->sgot->output_section->vma
3803 + globals->sgot->output_offset + cur_off);
3804 outrel.r_info = ELF32_R_INFO (indx, R_ARM_TLS_DTPMOD32);
3805 bfd_put_32 (output_bfd, 0, globals->sgot->contents + cur_off);
3807 bfd_elf32_swap_reloc_out (output_bfd, &outrel, loc);
3808 globals->srelgot->reloc_count++;
3809 loc += sizeof (Elf32_External_Rel);
3811 if (indx == 0)
3812 bfd_put_32 (output_bfd, value - dtpoff_base (info),
3813 globals->sgot->contents + cur_off + 4);
3814 else
3816 bfd_put_32 (output_bfd, 0,
3817 globals->sgot->contents + cur_off + 4);
3819 outrel.r_info = ELF32_R_INFO (indx,
3820 R_ARM_TLS_DTPOFF32);
3821 outrel.r_offset += 4;
3822 bfd_elf32_swap_reloc_out (output_bfd, &outrel, loc);
3823 globals->srelgot->reloc_count++;
3824 loc += sizeof (Elf32_External_Rel);
3827 else
3829 /* If we are not emitting relocations for a
3830 general dynamic reference, then we must be in a
3831 static link or an executable link with the
3832 symbol binding locally. Mark it as belonging
3833 to module 1, the executable. */
3834 bfd_put_32 (output_bfd, 1,
3835 globals->sgot->contents + cur_off);
3836 bfd_put_32 (output_bfd, value - dtpoff_base (info),
3837 globals->sgot->contents + cur_off + 4);
3840 cur_off += 8;
3843 if (tls_type & GOT_TLS_IE)
3845 if (need_relocs)
3847 outrel.r_offset = (globals->sgot->output_section->vma
3848 + globals->sgot->output_offset
3849 + cur_off);
3850 outrel.r_info = ELF32_R_INFO (indx, R_ARM_TLS_TPOFF32);
3852 if (indx == 0)
3853 bfd_put_32 (output_bfd, value - dtpoff_base (info),
3854 globals->sgot->contents + cur_off);
3855 else
3856 bfd_put_32 (output_bfd, 0,
3857 globals->sgot->contents + cur_off);
3859 bfd_elf32_swap_reloc_out (output_bfd, &outrel, loc);
3860 globals->srelgot->reloc_count++;
3861 loc += sizeof (Elf32_External_Rel);
3863 else
3864 bfd_put_32 (output_bfd, tpoff (info, value),
3865 globals->sgot->contents + cur_off);
3866 cur_off += 4;
3869 if (h != NULL)
3870 h->got.offset |= 1;
3871 else
3872 local_got_offsets[r_symndx] |= 1;
3875 if ((tls_type & GOT_TLS_GD) && r_type != R_ARM_TLS_GD32)
3876 off += 8;
3877 value = globals->sgot->output_section->vma + globals->sgot->output_offset + off
3878 - (input_section->output_section->vma + input_section->output_offset + rel->r_offset);
3880 return _bfd_final_link_relocate (howto, input_bfd, input_section,
3881 contents, rel->r_offset, value,
3882 (bfd_vma) 0);
3885 case R_ARM_TLS_LE32:
3886 if (info->shared)
3888 (*_bfd_error_handler)
3889 (_("%B(%A+0x%lx): R_ARM_TLS_LE32 relocation not permitted in shared object"),
3890 input_bfd, input_section,
3891 (long) rel->r_offset, howto->name);
3892 return FALSE;
3894 else
3895 value = tpoff (info, value);
3897 return _bfd_final_link_relocate (howto, input_bfd, input_section,
3898 contents, rel->r_offset, value, (bfd_vma) 0);
3900 case R_ARM_V4BX:
3901 if (globals->fix_v4bx)
3903 bfd_vma insn = bfd_get_32 (input_bfd, hit_data);
3905 /* Ensure that we have a BX instruction. */
3906 BFD_ASSERT ((insn & 0x0ffffff0) == 0x012fff10);
3908 /* Preserve Rm (lowest four bits) and the condition code
3909 (highest four bits). Other bits encode MOV PC,Rm. */
3910 insn = (insn & 0xf000000f) | 0x01a0f000;
3912 bfd_put_32 (input_bfd, insn, hit_data);
3914 return bfd_reloc_ok;
3916 default:
3917 return bfd_reloc_notsupported;
3922 static int
3923 uleb128_size (unsigned int i)
3925 int size;
3926 size = 1;
3927 while (i >= 0x80)
3929 i >>= 7;
3930 size++;
3932 return size;
3935 /* Return TRUE if the attribute has the default value (0/""). */
3936 static bfd_boolean
3937 is_default_attr (aeabi_attribute *attr)
3939 if ((attr->type & 1) && attr->i != 0)
3940 return FALSE;
3941 if ((attr->type & 2) && attr->s && *attr->s)
3942 return FALSE;
3944 return TRUE;
3947 /* Return the size of a single attribute. */
3948 static bfd_vma
3949 eabi_attr_size(int tag, aeabi_attribute *attr)
3951 bfd_vma size;
3953 if (is_default_attr (attr))
3954 return 0;
3956 size = uleb128_size (tag);
3957 if (attr->type & 1)
3958 size += uleb128_size (attr->i);
3959 if (attr->type & 2)
3960 size += strlen ((char *)attr->s) + 1;
3961 return size;
3964 /* Returns the size of the eabi object attributess section. */
3965 bfd_vma
3966 elf32_arm_eabi_attr_size (bfd *abfd)
3968 bfd_vma size;
3969 aeabi_attribute *attr;
3970 aeabi_attribute_list *list;
3971 int i;
3973 attr = elf32_arm_tdata (abfd)->known_eabi_attributes;
3974 size = 16; /* 'A' <size> "aeabi" 0x1 <size>. */
3975 for (i = 4; i < NUM_KNOWN_ATTRIBUTES; i++)
3976 size += eabi_attr_size (i, &attr[i]);
3978 for (list = elf32_arm_tdata (abfd)->other_eabi_attributes;
3979 list;
3980 list = list->next)
3981 size += eabi_attr_size (list->tag, &list->attr);
3983 return size;
3986 static bfd_byte *
3987 write_uleb128 (bfd_byte *p, unsigned int val)
3989 bfd_byte c;
3992 c = val & 0x7f;
3993 val >>= 7;
3994 if (val)
3995 c |= 0x80;
3996 *(p++) = c;
3998 while (val);
3999 return p;
4002 /* Write attribute ATTR to butter P, and return a pointer to the following
4003 byte. */
4004 static bfd_byte *
4005 write_eabi_attribute (bfd_byte *p, int tag, aeabi_attribute *attr)
4007 /* Suppress default entries. */
4008 if (is_default_attr(attr))
4009 return p;
4011 p = write_uleb128 (p, tag);
4012 if (attr->type & 1)
4013 p = write_uleb128 (p, attr->i);
4014 if (attr->type & 2)
4016 int len;
4018 len = strlen (attr->s) + 1;
4019 memcpy (p, attr->s, len);
4020 p += len;
4023 return p;
4026 /* Write the contents of the eabi attributes section to p. */
4027 void
4028 elf32_arm_set_eabi_attr_contents (bfd *abfd, bfd_byte *contents, bfd_vma size)
4030 bfd_byte *p;
4031 aeabi_attribute *attr;
4032 aeabi_attribute_list *list;
4033 int i;
4035 p = contents;
4036 *(p++) = 'A';
4037 bfd_put_32 (abfd, size - 1, p);
4038 p += 4;
4039 memcpy (p, "aeabi", 6);
4040 p += 6;
4041 *(p++) = Tag_File;
4042 bfd_put_32 (abfd, size - 11, p);
4043 p += 4;
4045 attr = elf32_arm_tdata (abfd)->known_eabi_attributes;
4046 for (i = 4; i < NUM_KNOWN_ATTRIBUTES; i++)
4047 p = write_eabi_attribute (p, i, &attr[i]);
4049 for (list = elf32_arm_tdata (abfd)->other_eabi_attributes;
4050 list;
4051 list = list->next)
4052 p = write_eabi_attribute (p, list->tag, &list->attr);
4055 /* Override final_link to handle EABI object attribute sections. */
4057 static bfd_boolean
4058 elf32_arm_bfd_final_link (bfd *abfd, struct bfd_link_info *info)
4060 asection *o;
4061 struct bfd_link_order *p;
4062 asection *attr_section = NULL;
4063 bfd_byte *contents;
4064 bfd_vma size = 0;
4066 /* elf32_arm_merge_private_bfd_data will already have merged the
4067 object attributes. Remove the input sections from the link, and set
4068 the contents of the output secton. */
4069 for (o = abfd->sections; o != NULL; o = o->next)
4071 if (strcmp (o->name, ".ARM.attributes") == 0)
4073 for (p = o->map_head.link_order; p != NULL; p = p->next)
4075 asection *input_section;
4077 if (p->type != bfd_indirect_link_order)
4078 continue;
4079 input_section = p->u.indirect.section;
4080 /* Hack: reset the SEC_HAS_CONTENTS flag so that
4081 elf_link_input_bfd ignores this section. */
4082 input_section->flags &= ~SEC_HAS_CONTENTS;
4085 size = elf32_arm_eabi_attr_size (abfd);
4086 bfd_set_section_size (abfd, o, size);
4087 attr_section = o;
4088 /* Skip this section later on. */
4089 o->map_head.link_order = NULL;
4092 /* Invoke the ELF linker to do all the work. */
4093 if (!bfd_elf_final_link (abfd, info))
4094 return FALSE;
4096 if (attr_section)
4098 contents = bfd_malloc(size);
4099 if (contents == NULL)
4100 return FALSE;
4101 elf32_arm_set_eabi_attr_contents (abfd, contents, size);
4102 bfd_set_section_contents (abfd, attr_section, contents, 0, size);
4103 free (contents);
4105 return TRUE;
4109 /* Add INCREMENT to the reloc (of type HOWTO) at ADDRESS. */
4110 static void
4111 arm_add_to_rel (bfd * abfd,
4112 bfd_byte * address,
4113 reloc_howto_type * howto,
4114 bfd_signed_vma increment)
4116 bfd_signed_vma addend;
4118 if (howto->type == R_ARM_THM_CALL)
4120 int upper_insn, lower_insn;
4121 int upper, lower;
4123 upper_insn = bfd_get_16 (abfd, address);
4124 lower_insn = bfd_get_16 (abfd, address + 2);
4125 upper = upper_insn & 0x7ff;
4126 lower = lower_insn & 0x7ff;
4128 addend = (upper << 12) | (lower << 1);
4129 addend += increment;
4130 addend >>= 1;
4132 upper_insn = (upper_insn & 0xf800) | ((addend >> 11) & 0x7ff);
4133 lower_insn = (lower_insn & 0xf800) | (addend & 0x7ff);
4135 bfd_put_16 (abfd, (bfd_vma) upper_insn, address);
4136 bfd_put_16 (abfd, (bfd_vma) lower_insn, address + 2);
4138 else
4140 bfd_vma contents;
4142 contents = bfd_get_32 (abfd, address);
4144 /* Get the (signed) value from the instruction. */
4145 addend = contents & howto->src_mask;
4146 if (addend & ((howto->src_mask + 1) >> 1))
4148 bfd_signed_vma mask;
4150 mask = -1;
4151 mask &= ~ howto->src_mask;
4152 addend |= mask;
4155 /* Add in the increment, (which is a byte value). */
4156 switch (howto->type)
4158 default:
4159 addend += increment;
4160 break;
4162 case R_ARM_PC24:
4163 case R_ARM_PLT32:
4164 case R_ARM_CALL:
4165 case R_ARM_JUMP24:
4166 addend <<= howto->size;
4167 addend += increment;
4169 /* Should we check for overflow here ? */
4171 /* Drop any undesired bits. */
4172 addend >>= howto->rightshift;
4173 break;
4176 contents = (contents & ~ howto->dst_mask) | (addend & howto->dst_mask);
4178 bfd_put_32 (abfd, contents, address);
4182 #define IS_ARM_TLS_RELOC(R_TYPE) \
4183 ((R_TYPE) == R_ARM_TLS_GD32 \
4184 || (R_TYPE) == R_ARM_TLS_LDO32 \
4185 || (R_TYPE) == R_ARM_TLS_LDM32 \
4186 || (R_TYPE) == R_ARM_TLS_DTPOFF32 \
4187 || (R_TYPE) == R_ARM_TLS_DTPMOD32 \
4188 || (R_TYPE) == R_ARM_TLS_TPOFF32 \
4189 || (R_TYPE) == R_ARM_TLS_LE32 \
4190 || (R_TYPE) == R_ARM_TLS_IE32)
4192 /* Relocate an ARM ELF section. */
4193 static bfd_boolean
4194 elf32_arm_relocate_section (bfd * output_bfd,
4195 struct bfd_link_info * info,
4196 bfd * input_bfd,
4197 asection * input_section,
4198 bfd_byte * contents,
4199 Elf_Internal_Rela * relocs,
4200 Elf_Internal_Sym * local_syms,
4201 asection ** local_sections)
4203 Elf_Internal_Shdr *symtab_hdr;
4204 struct elf_link_hash_entry **sym_hashes;
4205 Elf_Internal_Rela *rel;
4206 Elf_Internal_Rela *relend;
4207 const char *name;
4208 struct elf32_arm_link_hash_table * globals;
4210 globals = elf32_arm_hash_table (info);
4211 if (info->relocatable && !globals->use_rel)
4212 return TRUE;
4214 symtab_hdr = & elf_tdata (input_bfd)->symtab_hdr;
4215 sym_hashes = elf_sym_hashes (input_bfd);
4217 rel = relocs;
4218 relend = relocs + input_section->reloc_count;
4219 for (; rel < relend; rel++)
4221 int r_type;
4222 reloc_howto_type * howto;
4223 unsigned long r_symndx;
4224 Elf_Internal_Sym * sym;
4225 asection * sec;
4226 struct elf_link_hash_entry * h;
4227 bfd_vma relocation;
4228 bfd_reloc_status_type r;
4229 arelent bfd_reloc;
4230 char sym_type;
4231 bfd_boolean unresolved_reloc = FALSE;
4233 r_symndx = ELF32_R_SYM (rel->r_info);
4234 r_type = ELF32_R_TYPE (rel->r_info);
4235 r_type = arm_real_reloc_type (globals, r_type);
4237 if ( r_type == R_ARM_GNU_VTENTRY
4238 || r_type == R_ARM_GNU_VTINHERIT)
4239 continue;
4241 bfd_reloc.howto = elf32_arm_howto_from_type (r_type);
4242 howto = bfd_reloc.howto;
4244 if (info->relocatable && globals->use_rel)
4246 /* This is a relocatable link. We don't have to change
4247 anything, unless the reloc is against a section symbol,
4248 in which case we have to adjust according to where the
4249 section symbol winds up in the output section. */
4250 if (r_symndx < symtab_hdr->sh_info)
4252 sym = local_syms + r_symndx;
4253 if (ELF_ST_TYPE (sym->st_info) == STT_SECTION)
4255 sec = local_sections[r_symndx];
4256 arm_add_to_rel (input_bfd, contents + rel->r_offset,
4257 howto,
4258 (bfd_signed_vma) (sec->output_offset
4259 + sym->st_value));
4263 continue;
4266 /* This is a final link. */
4267 h = NULL;
4268 sym = NULL;
4269 sec = NULL;
4271 if (r_symndx < symtab_hdr->sh_info)
4273 sym = local_syms + r_symndx;
4274 sym_type = ELF32_ST_TYPE (sym->st_info);
4275 sec = local_sections[r_symndx];
4276 if (globals->use_rel)
4278 relocation = (sec->output_section->vma
4279 + sec->output_offset
4280 + sym->st_value);
4281 if ((sec->flags & SEC_MERGE)
4282 && ELF_ST_TYPE (sym->st_info) == STT_SECTION)
4284 asection *msec;
4285 bfd_vma addend, value;
4287 if (howto->rightshift)
4289 (*_bfd_error_handler)
4290 (_("%B(%A+0x%lx): %s relocation against SEC_MERGE section"),
4291 input_bfd, input_section,
4292 (long) rel->r_offset, howto->name);
4293 return FALSE;
4296 value = bfd_get_32 (input_bfd, contents + rel->r_offset);
4298 /* Get the (signed) value from the instruction. */
4299 addend = value & howto->src_mask;
4300 if (addend & ((howto->src_mask + 1) >> 1))
4302 bfd_signed_vma mask;
4304 mask = -1;
4305 mask &= ~ howto->src_mask;
4306 addend |= mask;
4308 msec = sec;
4309 addend =
4310 _bfd_elf_rel_local_sym (output_bfd, sym, &msec, addend)
4311 - relocation;
4312 addend += msec->output_section->vma + msec->output_offset;
4313 value = (value & ~ howto->dst_mask) | (addend & howto->dst_mask);
4314 bfd_put_32 (input_bfd, value, contents + rel->r_offset);
4317 else
4318 relocation = _bfd_elf_rela_local_sym (output_bfd, sym, &sec, rel);
4320 else
4322 bfd_boolean warned;
4324 RELOC_FOR_GLOBAL_SYMBOL (info, input_bfd, input_section, rel,
4325 r_symndx, symtab_hdr, sym_hashes,
4326 h, sec, relocation,
4327 unresolved_reloc, warned);
4329 sym_type = h->type;
4332 if (h != NULL)
4333 name = h->root.root.string;
4334 else
4336 name = (bfd_elf_string_from_elf_section
4337 (input_bfd, symtab_hdr->sh_link, sym->st_name));
4338 if (name == NULL || *name == '\0')
4339 name = bfd_section_name (input_bfd, sec);
4342 if (r_symndx != 0
4343 && r_type != R_ARM_NONE
4344 && (h == NULL
4345 || h->root.type == bfd_link_hash_defined
4346 || h->root.type == bfd_link_hash_defweak)
4347 && IS_ARM_TLS_RELOC (r_type) != (sym_type == STT_TLS))
4349 (*_bfd_error_handler)
4350 ((sym_type == STT_TLS
4351 ? _("%B(%A+0x%lx): %s used with TLS symbol %s")
4352 : _("%B(%A+0x%lx): %s used with non-TLS symbol %s")),
4353 input_bfd,
4354 input_section,
4355 (long) rel->r_offset,
4356 howto->name,
4357 name);
4360 r = elf32_arm_final_link_relocate (howto, input_bfd, output_bfd,
4361 input_section, contents, rel,
4362 relocation, info, sec, name,
4363 (h ? ELF_ST_TYPE (h->type) :
4364 ELF_ST_TYPE (sym->st_info)), h,
4365 &unresolved_reloc);
4367 /* Dynamic relocs are not propagated for SEC_DEBUGGING sections
4368 because such sections are not SEC_ALLOC and thus ld.so will
4369 not process them. */
4370 if (unresolved_reloc
4371 && !((input_section->flags & SEC_DEBUGGING) != 0
4372 && h->def_dynamic))
4374 (*_bfd_error_handler)
4375 (_("%B(%A+0x%lx): unresolvable %s relocation against symbol `%s'"),
4376 input_bfd,
4377 input_section,
4378 (long) rel->r_offset,
4379 howto->name,
4380 h->root.root.string);
4381 return FALSE;
4384 if (r != bfd_reloc_ok)
4386 const char * msg = (const char *) 0;
4388 switch (r)
4390 case bfd_reloc_overflow:
4391 /* If the overflowing reloc was to an undefined symbol,
4392 we have already printed one error message and there
4393 is no point complaining again. */
4394 if ((! h ||
4395 h->root.type != bfd_link_hash_undefined)
4396 && (!((*info->callbacks->reloc_overflow)
4397 (info, (h ? &h->root : NULL), name, howto->name,
4398 (bfd_vma) 0, input_bfd, input_section,
4399 rel->r_offset))))
4400 return FALSE;
4401 break;
4403 case bfd_reloc_undefined:
4404 if (!((*info->callbacks->undefined_symbol)
4405 (info, name, input_bfd, input_section,
4406 rel->r_offset, TRUE)))
4407 return FALSE;
4408 break;
4410 case bfd_reloc_outofrange:
4411 msg = _("internal error: out of range error");
4412 goto common_error;
4414 case bfd_reloc_notsupported:
4415 msg = _("internal error: unsupported relocation error");
4416 goto common_error;
4418 case bfd_reloc_dangerous:
4419 msg = _("internal error: dangerous error");
4420 goto common_error;
4422 default:
4423 msg = _("internal error: unknown error");
4424 /* fall through */
4426 common_error:
4427 if (!((*info->callbacks->warning)
4428 (info, msg, name, input_bfd, input_section,
4429 rel->r_offset)))
4430 return FALSE;
4431 break;
4436 return TRUE;
4439 /* Allocate/find an object attribute. */
4440 static aeabi_attribute *
4441 elf32_arm_new_eabi_attr (bfd *abfd, int tag)
4443 aeabi_attribute *attr;
4444 aeabi_attribute_list *list;
4445 aeabi_attribute_list *p;
4446 aeabi_attribute_list **lastp;
4449 if (tag < NUM_KNOWN_ATTRIBUTES)
4451 /* Knwon tags are preallocated. */
4452 attr = &elf32_arm_tdata (abfd)->known_eabi_attributes[tag];
4454 else
4456 /* Create a new tag. */
4457 list = (aeabi_attribute_list *)
4458 bfd_alloc (abfd, sizeof (aeabi_attribute_list));
4459 memset (list, 0, sizeof (aeabi_attribute_list));
4460 list->tag = tag;
4461 /* Keep the tag list in order. */
4462 lastp = &elf32_arm_tdata (abfd)->other_eabi_attributes;
4463 for (p = *lastp; p; p = p->next)
4465 if (tag < p->tag)
4466 break;
4467 lastp = &p->next;
4469 list->next = *lastp;
4470 *lastp = list;
4471 attr = &list->attr;
4474 return attr;
4477 void
4478 elf32_arm_add_eabi_attr_int (bfd *abfd, int tag, unsigned int i)
4480 aeabi_attribute *attr;
4482 attr = elf32_arm_new_eabi_attr (abfd, tag);
4483 attr->type = 1;
4484 attr->i = i;
4487 static char *
4488 attr_strdup (bfd *abfd, const char * s)
4490 char * p;
4491 int len;
4493 len = strlen (s) + 1;
4494 p = (char *)bfd_alloc(abfd, len);
4495 return memcpy (p, s, len);
4498 void
4499 elf32_arm_add_eabi_attr_string (bfd *abfd, int tag, const char *s)
4501 aeabi_attribute *attr;
4503 attr = elf32_arm_new_eabi_attr (abfd, tag);
4504 attr->type = 2;
4505 attr->s = attr_strdup (abfd, s);
4508 void
4509 elf32_arm_add_eabi_attr_compat (bfd *abfd, unsigned int i, const char *s)
4511 aeabi_attribute_list *list;
4512 aeabi_attribute_list *p;
4513 aeabi_attribute_list **lastp;
4515 list = (aeabi_attribute_list *)
4516 bfd_alloc (abfd, sizeof (aeabi_attribute_list));
4517 memset (list, 0, sizeof (aeabi_attribute_list));
4518 list->tag = Tag_compatibility;
4519 list->attr.type = 3;
4520 list->attr.i = i;
4521 list->attr.s = attr_strdup (abfd, s);
4523 lastp = &elf32_arm_tdata (abfd)->other_eabi_attributes;
4524 for (p = *lastp; p; p = p->next)
4526 int cmp;
4527 if (p->tag != Tag_compatibility)
4528 break;
4529 cmp = strcmp(s, p->attr.s);
4530 if (cmp < 0 || (cmp == 0 && i < p->attr.i))
4531 break;
4532 lastp = &p->next;
4534 list->next = *lastp;
4535 *lastp = list;
4538 /* Set the right machine number. */
4540 static bfd_boolean
4541 elf32_arm_object_p (bfd *abfd)
4543 unsigned int mach;
4545 mach = bfd_arm_get_mach_from_notes (abfd, ARM_NOTE_SECTION);
4547 if (mach != bfd_mach_arm_unknown)
4548 bfd_default_set_arch_mach (abfd, bfd_arch_arm, mach);
4550 else if (elf_elfheader (abfd)->e_flags & EF_ARM_MAVERICK_FLOAT)
4551 bfd_default_set_arch_mach (abfd, bfd_arch_arm, bfd_mach_arm_ep9312);
4553 else
4554 bfd_default_set_arch_mach (abfd, bfd_arch_arm, mach);
4556 return TRUE;
4559 /* Function to keep ARM specific flags in the ELF header. */
4561 static bfd_boolean
4562 elf32_arm_set_private_flags (bfd *abfd, flagword flags)
4564 if (elf_flags_init (abfd)
4565 && elf_elfheader (abfd)->e_flags != flags)
4567 if (EF_ARM_EABI_VERSION (flags) == EF_ARM_EABI_UNKNOWN)
4569 if (flags & EF_ARM_INTERWORK)
4570 (*_bfd_error_handler)
4571 (_("Warning: Not setting interworking flag of %B since it has already been specified as non-interworking"),
4572 abfd);
4573 else
4574 _bfd_error_handler
4575 (_("Warning: Clearing the interworking flag of %B due to outside request"),
4576 abfd);
4579 else
4581 elf_elfheader (abfd)->e_flags = flags;
4582 elf_flags_init (abfd) = TRUE;
4585 return TRUE;
4588 /* Copy the eabi object attribute from IBFD to OBFD. */
4589 static void
4590 copy_eabi_attributes (bfd *ibfd, bfd *obfd)
4592 aeabi_attribute *in_attr;
4593 aeabi_attribute *out_attr;
4594 aeabi_attribute_list *list;
4595 int i;
4597 in_attr = elf32_arm_tdata (ibfd)->known_eabi_attributes;
4598 out_attr = elf32_arm_tdata (obfd)->known_eabi_attributes;
4599 for (i = 4; i < NUM_KNOWN_ATTRIBUTES; i++)
4601 out_attr->i = in_attr->i;
4602 if (in_attr->s && *in_attr->s)
4603 out_attr->s = attr_strdup (obfd, in_attr->s);
4604 in_attr++;
4605 out_attr++;
4608 for (list = elf32_arm_tdata (ibfd)->other_eabi_attributes;
4609 list;
4610 list = list->next)
4612 in_attr = &list->attr;
4613 switch (in_attr->type)
4615 case 1:
4616 elf32_arm_add_eabi_attr_int (obfd, list->tag, in_attr->i);
4617 break;
4618 case 2:
4619 elf32_arm_add_eabi_attr_string (obfd, list->tag, in_attr->s);
4620 break;
4621 case 3:
4622 elf32_arm_add_eabi_attr_compat (obfd, in_attr->i, in_attr->s);
4623 break;
4624 default:
4625 abort();
4631 /* Copy backend specific data from one object module to another. */
4633 static bfd_boolean
4634 elf32_arm_copy_private_bfd_data (bfd *ibfd, bfd *obfd)
4636 flagword in_flags;
4637 flagword out_flags;
4639 if ( bfd_get_flavour (ibfd) != bfd_target_elf_flavour
4640 || bfd_get_flavour (obfd) != bfd_target_elf_flavour)
4641 return TRUE;
4643 in_flags = elf_elfheader (ibfd)->e_flags;
4644 out_flags = elf_elfheader (obfd)->e_flags;
4646 if (elf_flags_init (obfd)
4647 && EF_ARM_EABI_VERSION (out_flags) == EF_ARM_EABI_UNKNOWN
4648 && in_flags != out_flags)
4650 /* Cannot mix APCS26 and APCS32 code. */
4651 if ((in_flags & EF_ARM_APCS_26) != (out_flags & EF_ARM_APCS_26))
4652 return FALSE;
4654 /* Cannot mix float APCS and non-float APCS code. */
4655 if ((in_flags & EF_ARM_APCS_FLOAT) != (out_flags & EF_ARM_APCS_FLOAT))
4656 return FALSE;
4658 /* If the src and dest have different interworking flags
4659 then turn off the interworking bit. */
4660 if ((in_flags & EF_ARM_INTERWORK) != (out_flags & EF_ARM_INTERWORK))
4662 if (out_flags & EF_ARM_INTERWORK)
4663 _bfd_error_handler
4664 (_("Warning: Clearing the interworking flag of %B because non-interworking code in %B has been linked with it"),
4665 obfd, ibfd);
4667 in_flags &= ~EF_ARM_INTERWORK;
4670 /* Likewise for PIC, though don't warn for this case. */
4671 if ((in_flags & EF_ARM_PIC) != (out_flags & EF_ARM_PIC))
4672 in_flags &= ~EF_ARM_PIC;
4675 elf_elfheader (obfd)->e_flags = in_flags;
4676 elf_flags_init (obfd) = TRUE;
4678 /* Also copy the EI_OSABI field. */
4679 elf_elfheader (obfd)->e_ident[EI_OSABI] =
4680 elf_elfheader (ibfd)->e_ident[EI_OSABI];
4682 /* Copy EABI object attributes. */
4683 copy_eabi_attributes (ibfd, obfd);
4685 return TRUE;
4688 /* Values for Tag_ABI_PCS_R9_use. */
4689 enum
4691 AEABI_R9_V6,
4692 AEABI_R9_SB,
4693 AEABI_R9_TLS,
4694 AEABI_R9_unused
4697 /* Values for Tag_ABI_PCS_RW_data. */
4698 enum
4700 AEABI_PCS_RW_data_absolute,
4701 AEABI_PCS_RW_data_PCrel,
4702 AEABI_PCS_RW_data_SBrel,
4703 AEABI_PCS_RW_data_unused
4706 /* Values for Tag_ABI_enum_size. */
4707 enum
4709 AEABI_enum_unused,
4710 AEABI_enum_short,
4711 AEABI_enum_wide,
4712 AEABI_enum_forced_wide
4715 /* Merge EABI object attributes from IBFD into OBFD. Raise an error if there
4716 are conflicting attributes. */
4717 static bfd_boolean
4718 elf32_arm_merge_eabi_attributes (bfd *ibfd, bfd *obfd)
4720 aeabi_attribute *in_attr;
4721 aeabi_attribute *out_attr;
4722 aeabi_attribute_list *in_list;
4723 aeabi_attribute_list *out_list;
4724 /* Some tags have 0 = don't care, 1 = strong requirement,
4725 2 = weak requirement. */
4726 static const int order_312[3] = {3, 1, 2};
4727 int i;
4729 if (!elf32_arm_tdata (ibfd)->known_eabi_attributes[0].i)
4731 /* This is the first object. Copy the attributes. */
4732 copy_eabi_attributes (ibfd, obfd);
4733 return TRUE;
4736 /* Use the Tag_null value to indicate the attributes have been
4737 initialized. */
4738 elf32_arm_tdata (ibfd)->known_eabi_attributes[0].i = 1;
4740 in_attr = elf32_arm_tdata (ibfd)->known_eabi_attributes;
4741 out_attr = elf32_arm_tdata (obfd)->known_eabi_attributes;
4742 /* This needs to happen before Tag_ABI_FP_number_model is merged. */
4743 if (in_attr[Tag_ABI_VFP_args].i != out_attr[Tag_ABI_VFP_args].i)
4745 /* Ignore mismatches if teh object doesn't use floating point. */
4746 if (out_attr[Tag_ABI_FP_number_model].i == 0)
4747 out_attr[Tag_ABI_VFP_args].i = in_attr[Tag_ABI_VFP_args].i;
4748 else if (in_attr[Tag_ABI_FP_number_model].i != 0)
4750 _bfd_error_handler
4751 (_("ERROR: %B uses VFP register arguments, %B does not"),
4752 ibfd, obfd);
4753 return FALSE;
4757 for (i = 4; i < NUM_KNOWN_ATTRIBUTES; i++)
4759 /* Merge this attribute with existing attributes. */
4760 switch (i)
4762 case Tag_CPU_raw_name:
4763 case Tag_CPU_name:
4764 /* Use whichever has the greatest architecture requirements. */
4765 if (in_attr[Tag_CPU_arch].i > out_attr[Tag_CPU_arch].i)
4766 out_attr[i].s = attr_strdup(obfd, in_attr[i].s);
4767 break;
4769 case Tag_ABI_optimization_goals:
4770 case Tag_ABI_FP_optimization_goals:
4771 /* Use the first value seen. */
4772 break;
4774 case Tag_CPU_arch:
4775 case Tag_ARM_ISA_use:
4776 case Tag_THUMB_ISA_use:
4777 case Tag_VFP_arch:
4778 case Tag_WMMX_arch:
4779 case Tag_NEON_arch:
4780 /* ??? Do NEON and WMMX conflict? */
4781 case Tag_ABI_FP_rounding:
4782 case Tag_ABI_FP_denormal:
4783 case Tag_ABI_FP_exceptions:
4784 case Tag_ABI_FP_user_exceptions:
4785 case Tag_ABI_FP_number_model:
4786 case Tag_ABI_align8_preserved:
4787 case Tag_ABI_HardFP_use:
4788 /* Use the largest value specified. */
4789 if (in_attr[i].i > out_attr[i].i)
4790 out_attr[i].i = in_attr[i].i;
4791 break;
4793 case Tag_CPU_arch_profile:
4794 /* Warn if conflicting architecture profiles used. */
4795 if (out_attr[i].i && in_attr[i].i && in_attr[i].i != out_attr[i].i)
4797 _bfd_error_handler
4798 (_("ERROR: %B: Conflicting architecture profiles %c/%c"),
4799 ibfd, in_attr[i].i, out_attr[i].i);
4800 return FALSE;
4802 if (in_attr[i].i)
4803 out_attr[i].i = in_attr[i].i;
4804 break;
4805 case Tag_PCS_config:
4806 if (out_attr[i].i == 0)
4807 out_attr[i].i = in_attr[i].i;
4808 else if (in_attr[i].i != 0 && out_attr[i].i != 0)
4810 /* It's sometimes ok to mix different configs, so this is only
4811 a warning. */
4812 _bfd_error_handler
4813 (_("Warning: %B: Conflicting platform configuration"), ibfd);
4815 break;
4816 case Tag_ABI_PCS_R9_use:
4817 if (out_attr[i].i != AEABI_R9_unused
4818 && in_attr[i].i != AEABI_R9_unused)
4820 _bfd_error_handler
4821 (_("ERROR: %B: Conflicting use of R9"), ibfd);
4822 return FALSE;
4824 if (out_attr[i].i == AEABI_R9_unused)
4825 out_attr[i].i = in_attr[i].i;
4826 break;
4827 case Tag_ABI_PCS_RW_data:
4828 if (in_attr[i].i == AEABI_PCS_RW_data_SBrel
4829 && out_attr[Tag_ABI_PCS_R9_use].i != AEABI_R9_SB
4830 && out_attr[Tag_ABI_PCS_R9_use].i != AEABI_R9_unused)
4832 _bfd_error_handler
4833 (_("ERROR: %B: SB relative addressing conflicts with use of R9"),
4834 ibfd);
4835 return FALSE;
4837 /* Use the smallest value specified. */
4838 if (in_attr[i].i < out_attr[i].i)
4839 out_attr[i].i = in_attr[i].i;
4840 break;
4841 case Tag_ABI_PCS_RO_data:
4842 /* Use the smallest value specified. */
4843 if (in_attr[i].i < out_attr[i].i)
4844 out_attr[i].i = in_attr[i].i;
4845 break;
4846 case Tag_ABI_PCS_GOT_use:
4847 if (in_attr[i].i > 2 || out_attr[i].i > 2
4848 || order_312[in_attr[i].i] < order_312[out_attr[i].i])
4849 out_attr[i].i = in_attr[i].i;
4850 break;
4851 case Tag_ABI_PCS_wchar_t:
4852 if (out_attr[i].i && in_attr[i].i && out_attr[i].i != in_attr[i].i)
4854 _bfd_error_handler
4855 (_("ERROR: %B: Conflicting definitions of wchar_t"), ibfd);
4856 return FALSE;
4858 if (in_attr[i].i)
4859 out_attr[i].i = in_attr[i].i;
4860 break;
4861 case Tag_ABI_align8_needed:
4862 /* ??? Check against Tag_ABI_align8_preserved. */
4863 if (in_attr[i].i > 2 || out_attr[i].i > 2
4864 || order_312[in_attr[i].i] < order_312[out_attr[i].i])
4865 out_attr[i].i = in_attr[i].i;
4866 break;
4867 case Tag_ABI_enum_size:
4868 if (in_attr[i].i != AEABI_enum_unused)
4870 if (out_attr[i].i == AEABI_enum_unused
4871 || out_attr[i].i == AEABI_enum_forced_wide)
4873 /* The existing object is compatible with anything.
4874 Use whatever requirements the new object has. */
4875 out_attr[i].i = in_attr[i].i;
4877 else if (in_attr[i].i != AEABI_enum_forced_wide
4878 && out_attr[i].i != in_attr[i].i)
4880 _bfd_error_handler
4881 (_("ERROR: %B: Conflicting enum sizes"), ibfd);
4884 break;
4885 case Tag_ABI_VFP_args:
4886 /* Aready done. */
4887 break;
4888 case Tag_ABI_WMMX_args:
4889 if (in_attr[i].i != out_attr[i].i)
4891 _bfd_error_handler
4892 (_("ERROR: %B uses iWMMXt register arguments, %B does not"),
4893 ibfd, obfd);
4894 return FALSE;
4896 break;
4897 default: /* All known attributes should be explicitly covered. */
4898 abort ();
4902 in_list = elf32_arm_tdata (ibfd)->other_eabi_attributes;
4903 out_list = elf32_arm_tdata (ibfd)->other_eabi_attributes;
4904 while (in_list && in_list->tag == Tag_compatibility)
4906 in_attr = &in_list->attr;
4907 if (in_attr->i == 0)
4908 continue;
4909 if (in_attr->i == 1)
4911 _bfd_error_handler
4912 (_("ERROR: %B: Must be processed by '%s' toolchain"),
4913 ibfd, in_attr->s);
4914 return FALSE;
4916 if (!out_list || out_list->tag != Tag_compatibility
4917 || strcmp (in_attr->s, out_list->attr.s) != 0)
4919 /* Add this compatibility tag to the output. */
4920 elf32_arm_add_eabi_attr_compat (obfd, in_attr->i, in_attr->s);
4921 continue;
4923 out_attr = &out_list->attr;
4924 /* Check all the input tags with the same identifier. */
4925 for (;;)
4927 if (out_list->tag != Tag_compatibility
4928 || in_attr->i != out_attr->i
4929 || strcmp (in_attr->s, out_attr->s) != 0)
4931 _bfd_error_handler
4932 (_("ERROR: %B: Incompatible object tag '%s':%d"),
4933 ibfd, in_attr->s, in_attr->i);
4934 return FALSE;
4936 in_list = in_list->next;
4937 if (in_list->tag != Tag_compatibility
4938 || strcmp (in_attr->s, in_list->attr.s) != 0)
4939 break;
4940 in_attr = &in_list->attr;
4941 out_list = out_list->next;
4942 if (out_list)
4943 out_attr = &out_list->attr;
4946 /* Check the output doesn't have extra tags with this identifier. */
4947 if (out_list && out_list->tag == Tag_compatibility
4948 && strcmp (in_attr->s, out_list->attr.s) == 0)
4950 _bfd_error_handler
4951 (_("ERROR: %B: Incompatible object tag '%s':%d"),
4952 ibfd, in_attr->s, out_list->attr.i);
4953 return FALSE;
4957 for (; in_list; in_list = in_list->next)
4959 if ((in_list->tag & 128) < 64)
4960 _bfd_error_handler
4961 (_("Warning: %B: Unknown EABI object attribute %d"),
4962 ibfd, in_list->tag);
4963 break;
4965 return TRUE;
4968 /* Merge backend specific data from an object file to the output
4969 object file when linking. */
4971 static bfd_boolean
4972 elf32_arm_merge_private_bfd_data (bfd * ibfd, bfd * obfd)
4974 flagword out_flags;
4975 flagword in_flags;
4976 bfd_boolean flags_compatible = TRUE;
4977 asection *sec;
4979 /* Check if we have the same endianess. */
4980 if (! _bfd_generic_verify_endian_match (ibfd, obfd))
4981 return FALSE;
4983 if ( bfd_get_flavour (ibfd) != bfd_target_elf_flavour
4984 || bfd_get_flavour (obfd) != bfd_target_elf_flavour)
4985 return TRUE;
4987 if (!elf32_arm_merge_eabi_attributes (ibfd, obfd))
4988 return FALSE;
4990 /* The input BFD must have had its flags initialised. */
4991 /* The following seems bogus to me -- The flags are initialized in
4992 the assembler but I don't think an elf_flags_init field is
4993 written into the object. */
4994 /* BFD_ASSERT (elf_flags_init (ibfd)); */
4996 in_flags = elf_elfheader (ibfd)->e_flags;
4997 out_flags = elf_elfheader (obfd)->e_flags;
4999 if (!elf_flags_init (obfd))
5001 /* If the input is the default architecture and had the default
5002 flags then do not bother setting the flags for the output
5003 architecture, instead allow future merges to do this. If no
5004 future merges ever set these flags then they will retain their
5005 uninitialised values, which surprise surprise, correspond
5006 to the default values. */
5007 if (bfd_get_arch_info (ibfd)->the_default
5008 && elf_elfheader (ibfd)->e_flags == 0)
5009 return TRUE;
5011 elf_flags_init (obfd) = TRUE;
5012 elf_elfheader (obfd)->e_flags = in_flags;
5014 if (bfd_get_arch (obfd) == bfd_get_arch (ibfd)
5015 && bfd_get_arch_info (obfd)->the_default)
5016 return bfd_set_arch_mach (obfd, bfd_get_arch (ibfd), bfd_get_mach (ibfd));
5018 return TRUE;
5021 /* Determine what should happen if the input ARM architecture
5022 does not match the output ARM architecture. */
5023 if (! bfd_arm_merge_machines (ibfd, obfd))
5024 return FALSE;
5026 /* Identical flags must be compatible. */
5027 if (in_flags == out_flags)
5028 return TRUE;
5030 /* Check to see if the input BFD actually contains any sections. If
5031 not, its flags may not have been initialised either, but it
5032 cannot actually cause any incompatiblity. Do not short-circuit
5033 dynamic objects; their section list may be emptied by
5034 elf_link_add_object_symbols.
5036 Also check to see if there are no code sections in the input.
5037 In this case there is no need to check for code specific flags.
5038 XXX - do we need to worry about floating-point format compatability
5039 in data sections ? */
5040 if (!(ibfd->flags & DYNAMIC))
5042 bfd_boolean null_input_bfd = TRUE;
5043 bfd_boolean only_data_sections = TRUE;
5045 for (sec = ibfd->sections; sec != NULL; sec = sec->next)
5047 /* Ignore synthetic glue sections. */
5048 if (strcmp (sec->name, ".glue_7")
5049 && strcmp (sec->name, ".glue_7t"))
5051 if ((bfd_get_section_flags (ibfd, sec)
5052 & (SEC_LOAD | SEC_CODE | SEC_HAS_CONTENTS))
5053 == (SEC_LOAD | SEC_CODE | SEC_HAS_CONTENTS))
5054 only_data_sections = FALSE;
5056 null_input_bfd = FALSE;
5057 break;
5061 if (null_input_bfd || only_data_sections)
5062 return TRUE;
5065 /* Complain about various flag mismatches. */
5066 if (EF_ARM_EABI_VERSION (in_flags) != EF_ARM_EABI_VERSION (out_flags))
5068 _bfd_error_handler
5069 (_("ERROR: Source object %B has EABI version %d, but target %B has EABI version %d"),
5070 ibfd, obfd,
5071 (in_flags & EF_ARM_EABIMASK) >> 24,
5072 (out_flags & EF_ARM_EABIMASK) >> 24);
5073 return FALSE;
5076 /* Not sure what needs to be checked for EABI versions >= 1. */
5077 if (EF_ARM_EABI_VERSION (in_flags) == EF_ARM_EABI_UNKNOWN)
5079 if ((in_flags & EF_ARM_APCS_26) != (out_flags & EF_ARM_APCS_26))
5081 _bfd_error_handler
5082 (_("ERROR: %B is compiled for APCS-%d, whereas target %B uses APCS-%d"),
5083 ibfd, obfd,
5084 in_flags & EF_ARM_APCS_26 ? 26 : 32,
5085 out_flags & EF_ARM_APCS_26 ? 26 : 32);
5086 flags_compatible = FALSE;
5089 if ((in_flags & EF_ARM_APCS_FLOAT) != (out_flags & EF_ARM_APCS_FLOAT))
5091 if (in_flags & EF_ARM_APCS_FLOAT)
5092 _bfd_error_handler
5093 (_("ERROR: %B passes floats in float registers, whereas %B passes them in integer registers"),
5094 ibfd, obfd);
5095 else
5096 _bfd_error_handler
5097 (_("ERROR: %B passes floats in integer registers, whereas %B passes them in float registers"),
5098 ibfd, obfd);
5100 flags_compatible = FALSE;
5103 if ((in_flags & EF_ARM_VFP_FLOAT) != (out_flags & EF_ARM_VFP_FLOAT))
5105 if (in_flags & EF_ARM_VFP_FLOAT)
5106 _bfd_error_handler
5107 (_("ERROR: %B uses VFP instructions, whereas %B does not"),
5108 ibfd, obfd);
5109 else
5110 _bfd_error_handler
5111 (_("ERROR: %B uses FPA instructions, whereas %B does not"),
5112 ibfd, obfd);
5114 flags_compatible = FALSE;
5117 if ((in_flags & EF_ARM_MAVERICK_FLOAT) != (out_flags & EF_ARM_MAVERICK_FLOAT))
5119 if (in_flags & EF_ARM_MAVERICK_FLOAT)
5120 _bfd_error_handler
5121 (_("ERROR: %B uses Maverick instructions, whereas %B does not"),
5122 ibfd, obfd);
5123 else
5124 _bfd_error_handler
5125 (_("ERROR: %B does not use Maverick instructions, whereas %B does"),
5126 ibfd, obfd);
5128 flags_compatible = FALSE;
5131 #ifdef EF_ARM_SOFT_FLOAT
5132 if ((in_flags & EF_ARM_SOFT_FLOAT) != (out_flags & EF_ARM_SOFT_FLOAT))
5134 /* We can allow interworking between code that is VFP format
5135 layout, and uses either soft float or integer regs for
5136 passing floating point arguments and results. We already
5137 know that the APCS_FLOAT flags match; similarly for VFP
5138 flags. */
5139 if ((in_flags & EF_ARM_APCS_FLOAT) != 0
5140 || (in_flags & EF_ARM_VFP_FLOAT) == 0)
5142 if (in_flags & EF_ARM_SOFT_FLOAT)
5143 _bfd_error_handler
5144 (_("ERROR: %B uses software FP, whereas %B uses hardware FP"),
5145 ibfd, obfd);
5146 else
5147 _bfd_error_handler
5148 (_("ERROR: %B uses hardware FP, whereas %B uses software FP"),
5149 ibfd, obfd);
5151 flags_compatible = FALSE;
5154 #endif
5156 /* Interworking mismatch is only a warning. */
5157 if ((in_flags & EF_ARM_INTERWORK) != (out_flags & EF_ARM_INTERWORK))
5159 if (in_flags & EF_ARM_INTERWORK)
5161 _bfd_error_handler
5162 (_("Warning: %B supports interworking, whereas %B does not"),
5163 ibfd, obfd);
5165 else
5167 _bfd_error_handler
5168 (_("Warning: %B does not support interworking, whereas %B does"),
5169 ibfd, obfd);
5174 return flags_compatible;
5177 /* Display the flags field. */
5179 static bfd_boolean
5180 elf32_arm_print_private_bfd_data (bfd *abfd, void * ptr)
5182 FILE * file = (FILE *) ptr;
5183 unsigned long flags;
5185 BFD_ASSERT (abfd != NULL && ptr != NULL);
5187 /* Print normal ELF private data. */
5188 _bfd_elf_print_private_bfd_data (abfd, ptr);
5190 flags = elf_elfheader (abfd)->e_flags;
5191 /* Ignore init flag - it may not be set, despite the flags field
5192 containing valid data. */
5194 /* xgettext:c-format */
5195 fprintf (file, _("private flags = %lx:"), elf_elfheader (abfd)->e_flags);
5197 switch (EF_ARM_EABI_VERSION (flags))
5199 case EF_ARM_EABI_UNKNOWN:
5200 /* The following flag bits are GNU extensions and not part of the
5201 official ARM ELF extended ABI. Hence they are only decoded if
5202 the EABI version is not set. */
5203 if (flags & EF_ARM_INTERWORK)
5204 fprintf (file, _(" [interworking enabled]"));
5206 if (flags & EF_ARM_APCS_26)
5207 fprintf (file, " [APCS-26]");
5208 else
5209 fprintf (file, " [APCS-32]");
5211 if (flags & EF_ARM_VFP_FLOAT)
5212 fprintf (file, _(" [VFP float format]"));
5213 else if (flags & EF_ARM_MAVERICK_FLOAT)
5214 fprintf (file, _(" [Maverick float format]"));
5215 else
5216 fprintf (file, _(" [FPA float format]"));
5218 if (flags & EF_ARM_APCS_FLOAT)
5219 fprintf (file, _(" [floats passed in float registers]"));
5221 if (flags & EF_ARM_PIC)
5222 fprintf (file, _(" [position independent]"));
5224 if (flags & EF_ARM_NEW_ABI)
5225 fprintf (file, _(" [new ABI]"));
5227 if (flags & EF_ARM_OLD_ABI)
5228 fprintf (file, _(" [old ABI]"));
5230 if (flags & EF_ARM_SOFT_FLOAT)
5231 fprintf (file, _(" [software FP]"));
5233 flags &= ~(EF_ARM_INTERWORK | EF_ARM_APCS_26 | EF_ARM_APCS_FLOAT
5234 | EF_ARM_PIC | EF_ARM_NEW_ABI | EF_ARM_OLD_ABI
5235 | EF_ARM_SOFT_FLOAT | EF_ARM_VFP_FLOAT
5236 | EF_ARM_MAVERICK_FLOAT);
5237 break;
5239 case EF_ARM_EABI_VER1:
5240 fprintf (file, _(" [Version1 EABI]"));
5242 if (flags & EF_ARM_SYMSARESORTED)
5243 fprintf (file, _(" [sorted symbol table]"));
5244 else
5245 fprintf (file, _(" [unsorted symbol table]"));
5247 flags &= ~ EF_ARM_SYMSARESORTED;
5248 break;
5250 case EF_ARM_EABI_VER2:
5251 fprintf (file, _(" [Version2 EABI]"));
5253 if (flags & EF_ARM_SYMSARESORTED)
5254 fprintf (file, _(" [sorted symbol table]"));
5255 else
5256 fprintf (file, _(" [unsorted symbol table]"));
5258 if (flags & EF_ARM_DYNSYMSUSESEGIDX)
5259 fprintf (file, _(" [dynamic symbols use segment index]"));
5261 if (flags & EF_ARM_MAPSYMSFIRST)
5262 fprintf (file, _(" [mapping symbols precede others]"));
5264 flags &= ~(EF_ARM_SYMSARESORTED | EF_ARM_DYNSYMSUSESEGIDX
5265 | EF_ARM_MAPSYMSFIRST);
5266 break;
5268 case EF_ARM_EABI_VER3:
5269 fprintf (file, _(" [Version3 EABI]"));
5270 break;
5272 case EF_ARM_EABI_VER4:
5273 fprintf (file, _(" [Version4 EABI]"));
5275 if (flags & EF_ARM_BE8)
5276 fprintf (file, _(" [BE8]"));
5278 if (flags & EF_ARM_LE8)
5279 fprintf (file, _(" [LE8]"));
5281 flags &= ~(EF_ARM_LE8 | EF_ARM_BE8);
5282 break;
5284 default:
5285 fprintf (file, _(" <EABI version unrecognised>"));
5286 break;
5289 flags &= ~ EF_ARM_EABIMASK;
5291 if (flags & EF_ARM_RELEXEC)
5292 fprintf (file, _(" [relocatable executable]"));
5294 if (flags & EF_ARM_HASENTRY)
5295 fprintf (file, _(" [has entry point]"));
5297 flags &= ~ (EF_ARM_RELEXEC | EF_ARM_HASENTRY);
5299 if (flags)
5300 fprintf (file, _("<Unrecognised flag bits set>"));
5302 fputc ('\n', file);
5304 return TRUE;
5307 static int
5308 elf32_arm_get_symbol_type (Elf_Internal_Sym * elf_sym, int type)
5310 switch (ELF_ST_TYPE (elf_sym->st_info))
5312 case STT_ARM_TFUNC:
5313 return ELF_ST_TYPE (elf_sym->st_info);
5315 case STT_ARM_16BIT:
5316 /* If the symbol is not an object, return the STT_ARM_16BIT flag.
5317 This allows us to distinguish between data used by Thumb instructions
5318 and non-data (which is probably code) inside Thumb regions of an
5319 executable. */
5320 if (type != STT_OBJECT)
5321 return ELF_ST_TYPE (elf_sym->st_info);
5322 break;
5324 default:
5325 break;
5328 return type;
5331 static asection *
5332 elf32_arm_gc_mark_hook (asection * sec,
5333 struct bfd_link_info * info ATTRIBUTE_UNUSED,
5334 Elf_Internal_Rela * rel,
5335 struct elf_link_hash_entry * h,
5336 Elf_Internal_Sym * sym)
5338 if (h != NULL)
5340 switch (ELF32_R_TYPE (rel->r_info))
5342 case R_ARM_GNU_VTINHERIT:
5343 case R_ARM_GNU_VTENTRY:
5344 break;
5346 default:
5347 switch (h->root.type)
5349 case bfd_link_hash_defined:
5350 case bfd_link_hash_defweak:
5351 return h->root.u.def.section;
5353 case bfd_link_hash_common:
5354 return h->root.u.c.p->section;
5356 default:
5357 break;
5361 else
5362 return bfd_section_from_elf_index (sec->owner, sym->st_shndx);
5364 return NULL;
5367 /* Update the got entry reference counts for the section being removed. */
5369 static bfd_boolean
5370 elf32_arm_gc_sweep_hook (bfd * abfd,
5371 struct bfd_link_info * info,
5372 asection * sec,
5373 const Elf_Internal_Rela * relocs)
5375 Elf_Internal_Shdr *symtab_hdr;
5376 struct elf_link_hash_entry **sym_hashes;
5377 bfd_signed_vma *local_got_refcounts;
5378 const Elf_Internal_Rela *rel, *relend;
5379 struct elf32_arm_link_hash_table * globals;
5381 globals = elf32_arm_hash_table (info);
5383 elf_section_data (sec)->local_dynrel = NULL;
5385 symtab_hdr = &elf_tdata (abfd)->symtab_hdr;
5386 sym_hashes = elf_sym_hashes (abfd);
5387 local_got_refcounts = elf_local_got_refcounts (abfd);
5389 relend = relocs + sec->reloc_count;
5390 for (rel = relocs; rel < relend; rel++)
5392 unsigned long r_symndx;
5393 struct elf_link_hash_entry *h = NULL;
5394 int r_type;
5396 r_symndx = ELF32_R_SYM (rel->r_info);
5397 if (r_symndx >= symtab_hdr->sh_info)
5399 h = sym_hashes[r_symndx - symtab_hdr->sh_info];
5400 while (h->root.type == bfd_link_hash_indirect
5401 || h->root.type == bfd_link_hash_warning)
5402 h = (struct elf_link_hash_entry *) h->root.u.i.link;
5405 r_type = ELF32_R_TYPE (rel->r_info);
5406 r_type = arm_real_reloc_type (globals, r_type);
5407 switch (r_type)
5409 case R_ARM_GOT32:
5410 case R_ARM_GOT_PREL:
5411 case R_ARM_TLS_GD32:
5412 case R_ARM_TLS_IE32:
5413 if (h != NULL)
5415 if (h->got.refcount > 0)
5416 h->got.refcount -= 1;
5418 else if (local_got_refcounts != NULL)
5420 if (local_got_refcounts[r_symndx] > 0)
5421 local_got_refcounts[r_symndx] -= 1;
5423 break;
5425 case R_ARM_TLS_LDM32:
5426 elf32_arm_hash_table (info)->tls_ldm_got.refcount -= 1;
5427 break;
5429 case R_ARM_ABS32:
5430 case R_ARM_REL32:
5431 case R_ARM_PC24:
5432 case R_ARM_PLT32:
5433 case R_ARM_CALL:
5434 case R_ARM_JUMP24:
5435 case R_ARM_PREL31:
5436 case R_ARM_THM_CALL:
5437 /* Should the interworking branches be here also? */
5439 if (h != NULL)
5441 struct elf32_arm_link_hash_entry *eh;
5442 struct elf32_arm_relocs_copied **pp;
5443 struct elf32_arm_relocs_copied *p;
5445 eh = (struct elf32_arm_link_hash_entry *) h;
5447 if (h->plt.refcount > 0)
5449 h->plt.refcount -= 1;
5450 if (ELF32_R_TYPE (rel->r_info) == R_ARM_THM_CALL)
5451 eh->plt_thumb_refcount--;
5454 if (r_type == R_ARM_ABS32
5455 || r_type == R_ARM_REL32)
5457 for (pp = &eh->relocs_copied; (p = *pp) != NULL;
5458 pp = &p->next)
5459 if (p->section == sec)
5461 p->count -= 1;
5462 if (ELF32_R_TYPE (rel->r_info) == R_ARM_REL32)
5463 p->pc_count -= 1;
5464 if (p->count == 0)
5465 *pp = p->next;
5466 break;
5470 break;
5472 default:
5473 break;
5477 return TRUE;
5480 /* Look through the relocs for a section during the first phase. */
5482 static bfd_boolean
5483 elf32_arm_check_relocs (bfd *abfd, struct bfd_link_info *info,
5484 asection *sec, const Elf_Internal_Rela *relocs)
5486 Elf_Internal_Shdr *symtab_hdr;
5487 struct elf_link_hash_entry **sym_hashes;
5488 struct elf_link_hash_entry **sym_hashes_end;
5489 const Elf_Internal_Rela *rel;
5490 const Elf_Internal_Rela *rel_end;
5491 bfd *dynobj;
5492 asection *sreloc;
5493 bfd_vma *local_got_offsets;
5494 struct elf32_arm_link_hash_table *htab;
5496 if (info->relocatable)
5497 return TRUE;
5499 htab = elf32_arm_hash_table (info);
5500 sreloc = NULL;
5502 /* Create dynamic sections for relocatable executables so that we can
5503 copy relocations. */
5504 if (htab->root.is_relocatable_executable
5505 && ! htab->root.dynamic_sections_created)
5507 if (! _bfd_elf_link_create_dynamic_sections (abfd, info))
5508 return FALSE;
5511 dynobj = elf_hash_table (info)->dynobj;
5512 local_got_offsets = elf_local_got_offsets (abfd);
5514 symtab_hdr = &elf_tdata (abfd)->symtab_hdr;
5515 sym_hashes = elf_sym_hashes (abfd);
5516 sym_hashes_end = sym_hashes
5517 + symtab_hdr->sh_size / sizeof (Elf32_External_Sym);
5519 if (!elf_bad_symtab (abfd))
5520 sym_hashes_end -= symtab_hdr->sh_info;
5522 rel_end = relocs + sec->reloc_count;
5523 for (rel = relocs; rel < rel_end; rel++)
5525 struct elf_link_hash_entry *h;
5526 struct elf32_arm_link_hash_entry *eh;
5527 unsigned long r_symndx;
5528 int r_type;
5530 r_symndx = ELF32_R_SYM (rel->r_info);
5531 r_type = ELF32_R_TYPE (rel->r_info);
5532 r_type = arm_real_reloc_type (htab, r_type);
5534 if (r_symndx >= NUM_SHDR_ENTRIES (symtab_hdr))
5536 (*_bfd_error_handler) (_("%B: bad symbol index: %d"), abfd,
5537 r_symndx);
5538 return FALSE;
5541 if (r_symndx < symtab_hdr->sh_info)
5542 h = NULL;
5543 else
5545 h = sym_hashes[r_symndx - symtab_hdr->sh_info];
5546 while (h->root.type == bfd_link_hash_indirect
5547 || h->root.type == bfd_link_hash_warning)
5548 h = (struct elf_link_hash_entry *) h->root.u.i.link;
5551 eh = (struct elf32_arm_link_hash_entry *) h;
5553 switch (r_type)
5555 case R_ARM_GOT32:
5556 case R_ARM_GOT_PREL:
5557 case R_ARM_TLS_GD32:
5558 case R_ARM_TLS_IE32:
5559 /* This symbol requires a global offset table entry. */
5561 int tls_type, old_tls_type;
5563 switch (r_type)
5565 case R_ARM_TLS_GD32: tls_type = GOT_TLS_GD; break;
5566 case R_ARM_TLS_IE32: tls_type = GOT_TLS_IE; break;
5567 default: tls_type = GOT_NORMAL; break;
5570 if (h != NULL)
5572 h->got.refcount++;
5573 old_tls_type = elf32_arm_hash_entry (h)->tls_type;
5575 else
5577 bfd_signed_vma *local_got_refcounts;
5579 /* This is a global offset table entry for a local symbol. */
5580 local_got_refcounts = elf_local_got_refcounts (abfd);
5581 if (local_got_refcounts == NULL)
5583 bfd_size_type size;
5585 size = symtab_hdr->sh_info;
5586 size *= (sizeof (bfd_signed_vma) + sizeof(char));
5587 local_got_refcounts = bfd_zalloc (abfd, size);
5588 if (local_got_refcounts == NULL)
5589 return FALSE;
5590 elf_local_got_refcounts (abfd) = local_got_refcounts;
5591 elf32_arm_local_got_tls_type (abfd)
5592 = (char *) (local_got_refcounts + symtab_hdr->sh_info);
5594 local_got_refcounts[r_symndx] += 1;
5595 old_tls_type = elf32_arm_local_got_tls_type (abfd) [r_symndx];
5598 /* We will already have issued an error message if there is a
5599 TLS / non-TLS mismatch, based on the symbol type. We don't
5600 support any linker relaxations. So just combine any TLS
5601 types needed. */
5602 if (old_tls_type != GOT_UNKNOWN && old_tls_type != GOT_NORMAL
5603 && tls_type != GOT_NORMAL)
5604 tls_type |= old_tls_type;
5606 if (old_tls_type != tls_type)
5608 if (h != NULL)
5609 elf32_arm_hash_entry (h)->tls_type = tls_type;
5610 else
5611 elf32_arm_local_got_tls_type (abfd) [r_symndx] = tls_type;
5614 /* Fall through */
5616 case R_ARM_TLS_LDM32:
5617 if (r_type == R_ARM_TLS_LDM32)
5618 htab->tls_ldm_got.refcount++;
5619 /* Fall through */
5621 case R_ARM_GOTOFF32:
5622 case R_ARM_GOTPC:
5623 if (htab->sgot == NULL)
5625 if (htab->root.dynobj == NULL)
5626 htab->root.dynobj = abfd;
5627 if (!create_got_section (htab->root.dynobj, info))
5628 return FALSE;
5630 break;
5632 case R_ARM_ABS32:
5633 case R_ARM_REL32:
5634 case R_ARM_PC24:
5635 case R_ARM_PLT32:
5636 case R_ARM_CALL:
5637 case R_ARM_JUMP24:
5638 case R_ARM_PREL31:
5639 case R_ARM_THM_CALL:
5640 /* Should the interworking branches be listed here? */
5641 if (h != NULL)
5643 /* If this reloc is in a read-only section, we might
5644 need a copy reloc. We can't check reliably at this
5645 stage whether the section is read-only, as input
5646 sections have not yet been mapped to output sections.
5647 Tentatively set the flag for now, and correct in
5648 adjust_dynamic_symbol. */
5649 if (!info->shared)
5650 h->non_got_ref = 1;
5652 /* We may need a .plt entry if the function this reloc
5653 refers to is in a different object. We can't tell for
5654 sure yet, because something later might force the
5655 symbol local. */
5656 if (r_type == R_ARM_PC24
5657 || r_type == R_ARM_CALL
5658 || r_type == R_ARM_JUMP24
5659 || r_type == R_ARM_PREL31
5660 || r_type == R_ARM_PLT32
5661 || r_type == R_ARM_THM_CALL)
5662 h->needs_plt = 1;
5664 /* If we create a PLT entry, this relocation will reference
5665 it, even if it's an ABS32 relocation. */
5666 h->plt.refcount += 1;
5668 if (r_type == R_ARM_THM_CALL)
5669 eh->plt_thumb_refcount += 1;
5672 /* If we are creating a shared library or relocatable executable,
5673 and this is a reloc against a global symbol, or a non PC
5674 relative reloc against a local symbol, then we need to copy
5675 the reloc into the shared library. However, if we are linking
5676 with -Bsymbolic, we do not need to copy a reloc against a
5677 global symbol which is defined in an object we are
5678 including in the link (i.e., DEF_REGULAR is set). At
5679 this point we have not seen all the input files, so it is
5680 possible that DEF_REGULAR is not set now but will be set
5681 later (it is never cleared). We account for that
5682 possibility below by storing information in the
5683 relocs_copied field of the hash table entry. */
5684 if ((info->shared || htab->root.is_relocatable_executable)
5685 && (sec->flags & SEC_ALLOC) != 0
5686 && (r_type == R_ARM_ABS32
5687 || (h != NULL && ! h->needs_plt
5688 && (! info->symbolic || ! h->def_regular))))
5690 struct elf32_arm_relocs_copied *p, **head;
5692 /* When creating a shared object, we must copy these
5693 reloc types into the output file. We create a reloc
5694 section in dynobj and make room for this reloc. */
5695 if (sreloc == NULL)
5697 const char * name;
5699 name = (bfd_elf_string_from_elf_section
5700 (abfd,
5701 elf_elfheader (abfd)->e_shstrndx,
5702 elf_section_data (sec)->rel_hdr.sh_name));
5703 if (name == NULL)
5704 return FALSE;
5706 BFD_ASSERT (strncmp (name, ".rel", 4) == 0
5707 && strcmp (bfd_get_section_name (abfd, sec),
5708 name + 4) == 0);
5710 sreloc = bfd_get_section_by_name (dynobj, name);
5711 if (sreloc == NULL)
5713 flagword flags;
5715 flags = (SEC_HAS_CONTENTS | SEC_READONLY
5716 | SEC_IN_MEMORY | SEC_LINKER_CREATED);
5717 if ((sec->flags & SEC_ALLOC) != 0
5718 /* BPABI objects never have dynamic
5719 relocations mapped. */
5720 && !htab->symbian_p)
5721 flags |= SEC_ALLOC | SEC_LOAD;
5722 sreloc = bfd_make_section_with_flags (dynobj,
5723 name,
5724 flags);
5725 if (sreloc == NULL
5726 || ! bfd_set_section_alignment (dynobj, sreloc, 2))
5727 return FALSE;
5730 elf_section_data (sec)->sreloc = sreloc;
5733 /* If this is a global symbol, we count the number of
5734 relocations we need for this symbol. */
5735 if (h != NULL)
5737 head = &((struct elf32_arm_link_hash_entry *) h)->relocs_copied;
5739 else
5741 /* Track dynamic relocs needed for local syms too.
5742 We really need local syms available to do this
5743 easily. Oh well. */
5745 asection *s;
5746 void *vpp;
5748 s = bfd_section_from_r_symndx (abfd, &htab->sym_sec,
5749 sec, r_symndx);
5750 if (s == NULL)
5751 return FALSE;
5753 vpp = &elf_section_data (s)->local_dynrel;
5754 head = (struct elf32_arm_relocs_copied **) vpp;
5757 p = *head;
5758 if (p == NULL || p->section != sec)
5760 bfd_size_type amt = sizeof *p;
5762 p = bfd_alloc (htab->root.dynobj, amt);
5763 if (p == NULL)
5764 return FALSE;
5765 p->next = *head;
5766 *head = p;
5767 p->section = sec;
5768 p->count = 0;
5769 p->pc_count = 0;
5772 if (r_type == R_ARM_REL32)
5773 p->pc_count += 1;
5774 p->count += 1;
5776 break;
5778 /* This relocation describes the C++ object vtable hierarchy.
5779 Reconstruct it for later use during GC. */
5780 case R_ARM_GNU_VTINHERIT:
5781 if (!bfd_elf_gc_record_vtinherit (abfd, sec, h, rel->r_offset))
5782 return FALSE;
5783 break;
5785 /* This relocation describes which C++ vtable entries are actually
5786 used. Record for later use during GC. */
5787 case R_ARM_GNU_VTENTRY:
5788 if (!bfd_elf_gc_record_vtentry (abfd, sec, h, rel->r_offset))
5789 return FALSE;
5790 break;
5794 return TRUE;
5797 /* Treat mapping symbols as special target symbols. */
5799 static bfd_boolean
5800 elf32_arm_is_target_special_symbol (bfd * abfd ATTRIBUTE_UNUSED, asymbol * sym)
5802 return bfd_is_arm_mapping_symbol_name (sym->name);
5805 /* This is a copy of elf_find_function() from elf.c except that
5806 ARM mapping symbols are ignored when looking for function names
5807 and STT_ARM_TFUNC is considered to a function type. */
5809 static bfd_boolean
5810 arm_elf_find_function (bfd * abfd ATTRIBUTE_UNUSED,
5811 asection * section,
5812 asymbol ** symbols,
5813 bfd_vma offset,
5814 const char ** filename_ptr,
5815 const char ** functionname_ptr)
5817 const char * filename = NULL;
5818 asymbol * func = NULL;
5819 bfd_vma low_func = 0;
5820 asymbol ** p;
5822 for (p = symbols; *p != NULL; p++)
5824 elf_symbol_type *q;
5826 q = (elf_symbol_type *) *p;
5828 switch (ELF_ST_TYPE (q->internal_elf_sym.st_info))
5830 default:
5831 break;
5832 case STT_FILE:
5833 filename = bfd_asymbol_name (&q->symbol);
5834 break;
5835 case STT_FUNC:
5836 case STT_ARM_TFUNC:
5837 case STT_NOTYPE:
5838 /* Skip $a and $t symbols. */
5839 if ((q->symbol.flags & BSF_LOCAL)
5840 && bfd_is_arm_mapping_symbol_name (q->symbol.name))
5841 continue;
5842 /* Fall through. */
5843 if (bfd_get_section (&q->symbol) == section
5844 && q->symbol.value >= low_func
5845 && q->symbol.value <= offset)
5847 func = (asymbol *) q;
5848 low_func = q->symbol.value;
5850 break;
5854 if (func == NULL)
5855 return FALSE;
5857 if (filename_ptr)
5858 *filename_ptr = filename;
5859 if (functionname_ptr)
5860 *functionname_ptr = bfd_asymbol_name (func);
5862 return TRUE;
5866 /* Find the nearest line to a particular section and offset, for error
5867 reporting. This code is a duplicate of the code in elf.c, except
5868 that it uses arm_elf_find_function. */
5870 static bfd_boolean
5871 elf32_arm_find_nearest_line (bfd * abfd,
5872 asection * section,
5873 asymbol ** symbols,
5874 bfd_vma offset,
5875 const char ** filename_ptr,
5876 const char ** functionname_ptr,
5877 unsigned int * line_ptr)
5879 bfd_boolean found = FALSE;
5881 /* We skip _bfd_dwarf1_find_nearest_line since no known ARM toolchain uses it. */
5883 if (_bfd_dwarf2_find_nearest_line (abfd, section, symbols, offset,
5884 filename_ptr, functionname_ptr,
5885 line_ptr, 0,
5886 & elf_tdata (abfd)->dwarf2_find_line_info))
5888 if (!*functionname_ptr)
5889 arm_elf_find_function (abfd, section, symbols, offset,
5890 *filename_ptr ? NULL : filename_ptr,
5891 functionname_ptr);
5893 return TRUE;
5896 if (! _bfd_stab_section_find_nearest_line (abfd, symbols, section, offset,
5897 & found, filename_ptr,
5898 functionname_ptr, line_ptr,
5899 & elf_tdata (abfd)->line_info))
5900 return FALSE;
5902 if (found && (*functionname_ptr || *line_ptr))
5903 return TRUE;
5905 if (symbols == NULL)
5906 return FALSE;
5908 if (! arm_elf_find_function (abfd, section, symbols, offset,
5909 filename_ptr, functionname_ptr))
5910 return FALSE;
5912 *line_ptr = 0;
5913 return TRUE;
5916 static bfd_boolean
5917 elf32_arm_find_inliner_info (bfd * abfd,
5918 const char ** filename_ptr,
5919 const char ** functionname_ptr,
5920 unsigned int * line_ptr)
5922 bfd_boolean found;
5923 found = _bfd_dwarf2_find_inliner_info (abfd, filename_ptr,
5924 functionname_ptr, line_ptr,
5925 & elf_tdata (abfd)->dwarf2_find_line_info);
5926 return found;
5929 /* Adjust a symbol defined by a dynamic object and referenced by a
5930 regular object. The current definition is in some section of the
5931 dynamic object, but we're not including those sections. We have to
5932 change the definition to something the rest of the link can
5933 understand. */
5935 static bfd_boolean
5936 elf32_arm_adjust_dynamic_symbol (struct bfd_link_info * info,
5937 struct elf_link_hash_entry * h)
5939 bfd * dynobj;
5940 asection * s;
5941 unsigned int power_of_two;
5942 struct elf32_arm_link_hash_entry * eh;
5943 struct elf32_arm_link_hash_table *globals;
5945 globals = elf32_arm_hash_table (info);
5946 dynobj = elf_hash_table (info)->dynobj;
5948 /* Make sure we know what is going on here. */
5949 BFD_ASSERT (dynobj != NULL
5950 && (h->needs_plt
5951 || h->u.weakdef != NULL
5952 || (h->def_dynamic
5953 && h->ref_regular
5954 && !h->def_regular)));
5956 eh = (struct elf32_arm_link_hash_entry *) h;
5958 /* If this is a function, put it in the procedure linkage table. We
5959 will fill in the contents of the procedure linkage table later,
5960 when we know the address of the .got section. */
5961 if (h->type == STT_FUNC || h->type == STT_ARM_TFUNC
5962 || h->needs_plt)
5964 if (h->plt.refcount <= 0
5965 || SYMBOL_CALLS_LOCAL (info, h)
5966 || (ELF_ST_VISIBILITY (h->other) != STV_DEFAULT
5967 && h->root.type == bfd_link_hash_undefweak))
5969 /* This case can occur if we saw a PLT32 reloc in an input
5970 file, but the symbol was never referred to by a dynamic
5971 object, or if all references were garbage collected. In
5972 such a case, we don't actually need to build a procedure
5973 linkage table, and we can just do a PC24 reloc instead. */
5974 h->plt.offset = (bfd_vma) -1;
5975 eh->plt_thumb_refcount = 0;
5976 h->needs_plt = 0;
5979 return TRUE;
5981 else
5983 /* It's possible that we incorrectly decided a .plt reloc was
5984 needed for an R_ARM_PC24 or similar reloc to a non-function sym
5985 in check_relocs. We can't decide accurately between function
5986 and non-function syms in check-relocs; Objects loaded later in
5987 the link may change h->type. So fix it now. */
5988 h->plt.offset = (bfd_vma) -1;
5989 eh->plt_thumb_refcount = 0;
5992 /* If this is a weak symbol, and there is a real definition, the
5993 processor independent code will have arranged for us to see the
5994 real definition first, and we can just use the same value. */
5995 if (h->u.weakdef != NULL)
5997 BFD_ASSERT (h->u.weakdef->root.type == bfd_link_hash_defined
5998 || h->u.weakdef->root.type == bfd_link_hash_defweak);
5999 h->root.u.def.section = h->u.weakdef->root.u.def.section;
6000 h->root.u.def.value = h->u.weakdef->root.u.def.value;
6001 return TRUE;
6004 /* If there are no non-GOT references, we do not need a copy
6005 relocation. */
6006 if (!h->non_got_ref)
6007 return TRUE;
6009 /* This is a reference to a symbol defined by a dynamic object which
6010 is not a function. */
6012 /* If we are creating a shared library, we must presume that the
6013 only references to the symbol are via the global offset table.
6014 For such cases we need not do anything here; the relocations will
6015 be handled correctly by relocate_section. Relocatable executables
6016 can reference data in shared objects directly, so we don't need to
6017 do anything here. */
6018 if (info->shared || globals->root.is_relocatable_executable)
6019 return TRUE;
6021 if (h->size == 0)
6023 (*_bfd_error_handler) (_("dynamic variable `%s' is zero size"),
6024 h->root.root.string);
6025 return TRUE;
6028 /* We must allocate the symbol in our .dynbss section, which will
6029 become part of the .bss section of the executable. There will be
6030 an entry for this symbol in the .dynsym section. The dynamic
6031 object will contain position independent code, so all references
6032 from the dynamic object to this symbol will go through the global
6033 offset table. The dynamic linker will use the .dynsym entry to
6034 determine the address it must put in the global offset table, so
6035 both the dynamic object and the regular object will refer to the
6036 same memory location for the variable. */
6037 s = bfd_get_section_by_name (dynobj, ".dynbss");
6038 BFD_ASSERT (s != NULL);
6040 /* We must generate a R_ARM_COPY reloc to tell the dynamic linker to
6041 copy the initial value out of the dynamic object and into the
6042 runtime process image. We need to remember the offset into the
6043 .rel.bss section we are going to use. */
6044 if ((h->root.u.def.section->flags & SEC_ALLOC) != 0)
6046 asection *srel;
6048 srel = bfd_get_section_by_name (dynobj, ".rel.bss");
6049 BFD_ASSERT (srel != NULL);
6050 srel->size += sizeof (Elf32_External_Rel);
6051 h->needs_copy = 1;
6054 /* We need to figure out the alignment required for this symbol. I
6055 have no idea how ELF linkers handle this. */
6056 power_of_two = bfd_log2 (h->size);
6057 if (power_of_two > 3)
6058 power_of_two = 3;
6060 /* Apply the required alignment. */
6061 s->size = BFD_ALIGN (s->size, (bfd_size_type) (1 << power_of_two));
6062 if (power_of_two > bfd_get_section_alignment (dynobj, s))
6064 if (! bfd_set_section_alignment (dynobj, s, power_of_two))
6065 return FALSE;
6068 /* Define the symbol as being at this point in the section. */
6069 h->root.u.def.section = s;
6070 h->root.u.def.value = s->size;
6072 /* Increment the section size to make room for the symbol. */
6073 s->size += h->size;
6075 return TRUE;
6078 /* Allocate space in .plt, .got and associated reloc sections for
6079 dynamic relocs. */
6081 static bfd_boolean
6082 allocate_dynrelocs (struct elf_link_hash_entry *h, void * inf)
6084 struct bfd_link_info *info;
6085 struct elf32_arm_link_hash_table *htab;
6086 struct elf32_arm_link_hash_entry *eh;
6087 struct elf32_arm_relocs_copied *p;
6089 eh = (struct elf32_arm_link_hash_entry *) h;
6091 if (h->root.type == bfd_link_hash_indirect)
6092 return TRUE;
6094 if (h->root.type == bfd_link_hash_warning)
6095 /* When warning symbols are created, they **replace** the "real"
6096 entry in the hash table, thus we never get to see the real
6097 symbol in a hash traversal. So look at it now. */
6098 h = (struct elf_link_hash_entry *) h->root.u.i.link;
6100 info = (struct bfd_link_info *) inf;
6101 htab = elf32_arm_hash_table (info);
6103 if (htab->root.dynamic_sections_created
6104 && h->plt.refcount > 0)
6106 /* Make sure this symbol is output as a dynamic symbol.
6107 Undefined weak syms won't yet be marked as dynamic. */
6108 if (h->dynindx == -1
6109 && !h->forced_local)
6111 if (! bfd_elf_link_record_dynamic_symbol (info, h))
6112 return FALSE;
6115 if (info->shared
6116 || WILL_CALL_FINISH_DYNAMIC_SYMBOL (1, 0, h))
6118 asection *s = htab->splt;
6120 /* If this is the first .plt entry, make room for the special
6121 first entry. */
6122 if (s->size == 0)
6123 s->size += htab->plt_header_size;
6125 h->plt.offset = s->size;
6127 /* If we will insert a Thumb trampoline before this PLT, leave room
6128 for it. */
6129 if (!htab->use_blx && eh->plt_thumb_refcount > 0)
6131 h->plt.offset += PLT_THUMB_STUB_SIZE;
6132 s->size += PLT_THUMB_STUB_SIZE;
6135 /* If this symbol is not defined in a regular file, and we are
6136 not generating a shared library, then set the symbol to this
6137 location in the .plt. This is required to make function
6138 pointers compare as equal between the normal executable and
6139 the shared library. */
6140 if (! info->shared
6141 && !h->def_regular)
6143 h->root.u.def.section = s;
6144 h->root.u.def.value = h->plt.offset;
6146 /* Make sure the function is not marked as Thumb, in case
6147 it is the target of an ABS32 relocation, which will
6148 point to the PLT entry. */
6149 if (ELF_ST_TYPE (h->type) == STT_ARM_TFUNC)
6150 h->type = ELF_ST_INFO (ELF_ST_BIND (h->type), STT_FUNC);
6153 /* Make room for this entry. */
6154 s->size += htab->plt_entry_size;
6156 if (!htab->symbian_p)
6158 /* We also need to make an entry in the .got.plt section, which
6159 will be placed in the .got section by the linker script. */
6160 eh->plt_got_offset = htab->sgotplt->size;
6161 htab->sgotplt->size += 4;
6164 /* We also need to make an entry in the .rel.plt section. */
6165 htab->srelplt->size += sizeof (Elf32_External_Rel);
6167 else
6169 h->plt.offset = (bfd_vma) -1;
6170 h->needs_plt = 0;
6173 else
6175 h->plt.offset = (bfd_vma) -1;
6176 h->needs_plt = 0;
6179 if (h->got.refcount > 0)
6181 asection *s;
6182 bfd_boolean dyn;
6183 int tls_type = elf32_arm_hash_entry (h)->tls_type;
6184 int indx;
6186 /* Make sure this symbol is output as a dynamic symbol.
6187 Undefined weak syms won't yet be marked as dynamic. */
6188 if (h->dynindx == -1
6189 && !h->forced_local)
6191 if (! bfd_elf_link_record_dynamic_symbol (info, h))
6192 return FALSE;
6195 if (!htab->symbian_p)
6197 s = htab->sgot;
6198 h->got.offset = s->size;
6200 if (tls_type == GOT_UNKNOWN)
6201 abort ();
6203 if (tls_type == GOT_NORMAL)
6204 /* Non-TLS symbols need one GOT slot. */
6205 s->size += 4;
6206 else
6208 if (tls_type & GOT_TLS_GD)
6209 /* R_ARM_TLS_GD32 needs 2 consecutive GOT slots. */
6210 s->size += 8;
6211 if (tls_type & GOT_TLS_IE)
6212 /* R_ARM_TLS_IE32 needs one GOT slot. */
6213 s->size += 4;
6216 dyn = htab->root.dynamic_sections_created;
6218 indx = 0;
6219 if (WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn, info->shared, h)
6220 && (!info->shared
6221 || !SYMBOL_REFERENCES_LOCAL (info, h)))
6222 indx = h->dynindx;
6224 if (tls_type != GOT_NORMAL
6225 && (info->shared || indx != 0)
6226 && (ELF_ST_VISIBILITY (h->other) == STV_DEFAULT
6227 || h->root.type != bfd_link_hash_undefweak))
6229 if (tls_type & GOT_TLS_IE)
6230 htab->srelgot->size += sizeof (Elf32_External_Rel);
6232 if (tls_type & GOT_TLS_GD)
6233 htab->srelgot->size += sizeof (Elf32_External_Rel);
6235 if ((tls_type & GOT_TLS_GD) && indx != 0)
6236 htab->srelgot->size += sizeof (Elf32_External_Rel);
6238 else if ((ELF_ST_VISIBILITY (h->other) == STV_DEFAULT
6239 || h->root.type != bfd_link_hash_undefweak)
6240 && (info->shared
6241 || WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn, 0, h)))
6242 htab->srelgot->size += sizeof (Elf32_External_Rel);
6245 else
6246 h->got.offset = (bfd_vma) -1;
6248 if (eh->relocs_copied == NULL)
6249 return TRUE;
6251 /* In the shared -Bsymbolic case, discard space allocated for
6252 dynamic pc-relative relocs against symbols which turn out to be
6253 defined in regular objects. For the normal shared case, discard
6254 space for pc-relative relocs that have become local due to symbol
6255 visibility changes. */
6257 if (info->shared || htab->root.is_relocatable_executable)
6259 /* The only reloc that uses pc_count is R_ARM_REL32, which will
6260 appear on something like ".long foo - .". We want calls to
6261 protected symbols to resolve directly to the function rather
6262 than going via the plt. If people want function pointer
6263 comparisons to work as expected then they should avoid
6264 writing assembly like ".long foo - .". */
6265 if (SYMBOL_CALLS_LOCAL (info, h))
6267 struct elf32_arm_relocs_copied **pp;
6269 for (pp = &eh->relocs_copied; (p = *pp) != NULL; )
6271 p->count -= p->pc_count;
6272 p->pc_count = 0;
6273 if (p->count == 0)
6274 *pp = p->next;
6275 else
6276 pp = &p->next;
6280 /* Also discard relocs on undefined weak syms with non-default
6281 visibility. */
6282 if (ELF_ST_VISIBILITY (h->other) != STV_DEFAULT
6283 && h->root.type == bfd_link_hash_undefweak)
6284 eh->relocs_copied = NULL;
6285 else if (htab->root.is_relocatable_executable && h->dynindx == -1
6286 && h->root.type == bfd_link_hash_new)
6288 /* Output absolute symbols so that we can create relocations
6289 against them. For normal symbols we output a relocation
6290 against the section that contains them. */
6291 if (! bfd_elf_link_record_dynamic_symbol (info, h))
6292 return FALSE;
6296 else
6298 /* For the non-shared case, discard space for relocs against
6299 symbols which turn out to need copy relocs or are not
6300 dynamic. */
6302 if (!h->non_got_ref
6303 && ((h->def_dynamic
6304 && !h->def_regular)
6305 || (htab->root.dynamic_sections_created
6306 && (h->root.type == bfd_link_hash_undefweak
6307 || h->root.type == bfd_link_hash_undefined))))
6309 /* Make sure this symbol is output as a dynamic symbol.
6310 Undefined weak syms won't yet be marked as dynamic. */
6311 if (h->dynindx == -1
6312 && !h->forced_local)
6314 if (! bfd_elf_link_record_dynamic_symbol (info, h))
6315 return FALSE;
6318 /* If that succeeded, we know we'll be keeping all the
6319 relocs. */
6320 if (h->dynindx != -1)
6321 goto keep;
6324 eh->relocs_copied = NULL;
6326 keep: ;
6329 /* Finally, allocate space. */
6330 for (p = eh->relocs_copied; p != NULL; p = p->next)
6332 asection *sreloc = elf_section_data (p->section)->sreloc;
6333 sreloc->size += p->count * sizeof (Elf32_External_Rel);
6336 return TRUE;
6339 /* Find any dynamic relocs that apply to read-only sections. */
6341 static bfd_boolean
6342 elf32_arm_readonly_dynrelocs (struct elf_link_hash_entry *h, PTR inf)
6344 struct elf32_arm_link_hash_entry *eh;
6345 struct elf32_arm_relocs_copied *p;
6347 if (h->root.type == bfd_link_hash_warning)
6348 h = (struct elf_link_hash_entry *) h->root.u.i.link;
6350 eh = (struct elf32_arm_link_hash_entry *) h;
6351 for (p = eh->relocs_copied; p != NULL; p = p->next)
6353 asection *s = p->section;
6355 if (s != NULL && (s->flags & SEC_READONLY) != 0)
6357 struct bfd_link_info *info = (struct bfd_link_info *) inf;
6359 info->flags |= DF_TEXTREL;
6361 /* Not an error, just cut short the traversal. */
6362 return FALSE;
6365 return TRUE;
6368 /* Set the sizes of the dynamic sections. */
6370 static bfd_boolean
6371 elf32_arm_size_dynamic_sections (bfd * output_bfd ATTRIBUTE_UNUSED,
6372 struct bfd_link_info * info)
6374 bfd * dynobj;
6375 asection * s;
6376 bfd_boolean plt;
6377 bfd_boolean relocs;
6378 bfd *ibfd;
6379 struct elf32_arm_link_hash_table *htab;
6381 htab = elf32_arm_hash_table (info);
6382 dynobj = elf_hash_table (info)->dynobj;
6383 BFD_ASSERT (dynobj != NULL);
6385 if (elf_hash_table (info)->dynamic_sections_created)
6387 /* Set the contents of the .interp section to the interpreter. */
6388 if (info->executable)
6390 s = bfd_get_section_by_name (dynobj, ".interp");
6391 BFD_ASSERT (s != NULL);
6392 s->size = sizeof ELF_DYNAMIC_INTERPRETER;
6393 s->contents = (unsigned char *) ELF_DYNAMIC_INTERPRETER;
6397 /* Set up .got offsets for local syms, and space for local dynamic
6398 relocs. */
6399 for (ibfd = info->input_bfds; ibfd != NULL; ibfd = ibfd->link_next)
6401 bfd_signed_vma *local_got;
6402 bfd_signed_vma *end_local_got;
6403 char *local_tls_type;
6404 bfd_size_type locsymcount;
6405 Elf_Internal_Shdr *symtab_hdr;
6406 asection *srel;
6408 if (bfd_get_flavour (ibfd) != bfd_target_elf_flavour)
6409 continue;
6411 for (s = ibfd->sections; s != NULL; s = s->next)
6413 struct elf32_arm_relocs_copied *p;
6415 for (p = elf_section_data (s)->local_dynrel; p != NULL; p = p->next)
6417 if (!bfd_is_abs_section (p->section)
6418 && bfd_is_abs_section (p->section->output_section))
6420 /* Input section has been discarded, either because
6421 it is a copy of a linkonce section or due to
6422 linker script /DISCARD/, so we'll be discarding
6423 the relocs too. */
6425 else if (p->count != 0)
6427 srel = elf_section_data (p->section)->sreloc;
6428 srel->size += p->count * sizeof (Elf32_External_Rel);
6429 if ((p->section->output_section->flags & SEC_READONLY) != 0)
6430 info->flags |= DF_TEXTREL;
6435 local_got = elf_local_got_refcounts (ibfd);
6436 if (!local_got)
6437 continue;
6439 symtab_hdr = &elf_tdata (ibfd)->symtab_hdr;
6440 locsymcount = symtab_hdr->sh_info;
6441 end_local_got = local_got + locsymcount;
6442 local_tls_type = elf32_arm_local_got_tls_type (ibfd);
6443 s = htab->sgot;
6444 srel = htab->srelgot;
6445 for (; local_got < end_local_got; ++local_got, ++local_tls_type)
6447 if (*local_got > 0)
6449 *local_got = s->size;
6450 if (*local_tls_type & GOT_TLS_GD)
6451 /* TLS_GD relocs need an 8-byte structure in the GOT. */
6452 s->size += 8;
6453 if (*local_tls_type & GOT_TLS_IE)
6454 s->size += 4;
6455 if (*local_tls_type == GOT_NORMAL)
6456 s->size += 4;
6458 if (info->shared || *local_tls_type == GOT_TLS_GD)
6459 srel->size += sizeof (Elf32_External_Rel);
6461 else
6462 *local_got = (bfd_vma) -1;
6466 if (htab->tls_ldm_got.refcount > 0)
6468 /* Allocate two GOT entries and one dynamic relocation (if necessary)
6469 for R_ARM_TLS_LDM32 relocations. */
6470 htab->tls_ldm_got.offset = htab->sgot->size;
6471 htab->sgot->size += 8;
6472 if (info->shared)
6473 htab->srelgot->size += sizeof (Elf32_External_Rel);
6475 else
6476 htab->tls_ldm_got.offset = -1;
6478 /* Allocate global sym .plt and .got entries, and space for global
6479 sym dynamic relocs. */
6480 elf_link_hash_traverse (& htab->root, allocate_dynrelocs, info);
6482 /* The check_relocs and adjust_dynamic_symbol entry points have
6483 determined the sizes of the various dynamic sections. Allocate
6484 memory for them. */
6485 plt = FALSE;
6486 relocs = FALSE;
6487 for (s = dynobj->sections; s != NULL; s = s->next)
6489 const char * name;
6491 if ((s->flags & SEC_LINKER_CREATED) == 0)
6492 continue;
6494 /* It's OK to base decisions on the section name, because none
6495 of the dynobj section names depend upon the input files. */
6496 name = bfd_get_section_name (dynobj, s);
6498 if (strcmp (name, ".plt") == 0)
6500 /* Remember whether there is a PLT. */
6501 plt = s->size != 0;
6503 else if (strncmp (name, ".rel", 4) == 0)
6505 if (s->size != 0)
6507 /* Remember whether there are any reloc sections other
6508 than .rel.plt. */
6509 if (strcmp (name, ".rel.plt") != 0)
6510 relocs = TRUE;
6512 /* We use the reloc_count field as a counter if we need
6513 to copy relocs into the output file. */
6514 s->reloc_count = 0;
6517 else if (strncmp (name, ".got", 4) != 0
6518 && strcmp (name, ".dynbss") != 0)
6520 /* It's not one of our sections, so don't allocate space. */
6521 continue;
6524 if (s->size == 0)
6526 /* If we don't need this section, strip it from the
6527 output file. This is mostly to handle .rel.bss and
6528 .rel.plt. We must create both sections in
6529 create_dynamic_sections, because they must be created
6530 before the linker maps input sections to output
6531 sections. The linker does that before
6532 adjust_dynamic_symbol is called, and it is that
6533 function which decides whether anything needs to go
6534 into these sections. */
6535 s->flags |= SEC_EXCLUDE;
6536 continue;
6539 if ((s->flags & SEC_HAS_CONTENTS) == 0)
6540 continue;
6542 /* Allocate memory for the section contents. */
6543 s->contents = (bfd_byte *) bfd_zalloc (dynobj, s->size);
6544 if (s->contents == NULL)
6545 return FALSE;
6548 if (elf_hash_table (info)->dynamic_sections_created)
6550 /* Add some entries to the .dynamic section. We fill in the
6551 values later, in elf32_arm_finish_dynamic_sections, but we
6552 must add the entries now so that we get the correct size for
6553 the .dynamic section. The DT_DEBUG entry is filled in by the
6554 dynamic linker and used by the debugger. */
6555 #define add_dynamic_entry(TAG, VAL) \
6556 _bfd_elf_add_dynamic_entry (info, TAG, VAL)
6558 if (info->executable)
6560 if (!add_dynamic_entry (DT_DEBUG, 0))
6561 return FALSE;
6564 if (plt)
6566 if ( !add_dynamic_entry (DT_PLTGOT, 0)
6567 || !add_dynamic_entry (DT_PLTRELSZ, 0)
6568 || !add_dynamic_entry (DT_PLTREL, DT_REL)
6569 || !add_dynamic_entry (DT_JMPREL, 0))
6570 return FALSE;
6573 if (relocs)
6575 if ( !add_dynamic_entry (DT_REL, 0)
6576 || !add_dynamic_entry (DT_RELSZ, 0)
6577 || !add_dynamic_entry (DT_RELENT, sizeof (Elf32_External_Rel)))
6578 return FALSE;
6581 /* If any dynamic relocs apply to a read-only section,
6582 then we need a DT_TEXTREL entry. */
6583 if ((info->flags & DF_TEXTREL) == 0)
6584 elf_link_hash_traverse (&htab->root, elf32_arm_readonly_dynrelocs,
6585 (PTR) info);
6587 if ((info->flags & DF_TEXTREL) != 0)
6589 if (!add_dynamic_entry (DT_TEXTREL, 0))
6590 return FALSE;
6593 #undef add_dynamic_entry
6595 return TRUE;
6598 /* Finish up dynamic symbol handling. We set the contents of various
6599 dynamic sections here. */
6601 static bfd_boolean
6602 elf32_arm_finish_dynamic_symbol (bfd * output_bfd, struct bfd_link_info * info,
6603 struct elf_link_hash_entry * h, Elf_Internal_Sym * sym)
6605 bfd * dynobj;
6606 struct elf32_arm_link_hash_table *htab;
6607 struct elf32_arm_link_hash_entry *eh;
6609 dynobj = elf_hash_table (info)->dynobj;
6610 htab = elf32_arm_hash_table (info);
6611 eh = (struct elf32_arm_link_hash_entry *) h;
6613 if (h->plt.offset != (bfd_vma) -1)
6615 asection * splt;
6616 asection * srel;
6617 bfd_byte *loc;
6618 bfd_vma plt_index;
6619 Elf_Internal_Rela rel;
6621 /* This symbol has an entry in the procedure linkage table. Set
6622 it up. */
6624 BFD_ASSERT (h->dynindx != -1);
6626 splt = bfd_get_section_by_name (dynobj, ".plt");
6627 srel = bfd_get_section_by_name (dynobj, ".rel.plt");
6628 BFD_ASSERT (splt != NULL && srel != NULL);
6630 /* Fill in the entry in the procedure linkage table. */
6631 if (htab->symbian_p)
6633 unsigned i;
6634 for (i = 0; i < htab->plt_entry_size / 4; ++i)
6635 bfd_put_32 (output_bfd,
6636 elf32_arm_symbian_plt_entry[i],
6637 splt->contents + h->plt.offset + 4 * i);
6639 /* Fill in the entry in the .rel.plt section. */
6640 rel.r_offset = (splt->output_section->vma
6641 + splt->output_offset
6642 + h->plt.offset + 4 * (i - 1));
6643 rel.r_info = ELF32_R_INFO (h->dynindx, R_ARM_GLOB_DAT);
6645 /* Get the index in the procedure linkage table which
6646 corresponds to this symbol. This is the index of this symbol
6647 in all the symbols for which we are making plt entries. The
6648 first entry in the procedure linkage table is reserved. */
6649 plt_index = ((h->plt.offset - htab->plt_header_size)
6650 / htab->plt_entry_size);
6652 else
6654 bfd_vma got_offset;
6655 bfd_vma got_displacement;
6656 asection * sgot;
6658 sgot = bfd_get_section_by_name (dynobj, ".got.plt");
6659 BFD_ASSERT (sgot != NULL);
6661 /* Get the offset into the .got.plt table of the entry that
6662 corresponds to this function. */
6663 got_offset = eh->plt_got_offset;
6665 /* Get the index in the procedure linkage table which
6666 corresponds to this symbol. This is the index of this symbol
6667 in all the symbols for which we are making plt entries. The
6668 first three entries in .got.plt are reserved; after that
6669 symbols appear in the same order as in .plt. */
6670 plt_index = (got_offset - 12) / 4;
6672 /* Calculate the displacement between the PLT slot and the
6673 entry in the GOT. The eight-byte offset accounts for the
6674 value produced by adding to pc in the first instruction
6675 of the PLT stub. */
6676 got_displacement = (sgot->output_section->vma
6677 + sgot->output_offset
6678 + got_offset
6679 - splt->output_section->vma
6680 - splt->output_offset
6681 - h->plt.offset
6682 - 8);
6684 BFD_ASSERT ((got_displacement & 0xf0000000) == 0);
6686 if (!htab->use_blx && eh->plt_thumb_refcount > 0)
6688 bfd_put_16 (output_bfd, elf32_arm_plt_thumb_stub[0],
6689 splt->contents + h->plt.offset - 4);
6690 bfd_put_16 (output_bfd, elf32_arm_plt_thumb_stub[1],
6691 splt->contents + h->plt.offset - 2);
6694 bfd_put_32 (output_bfd, elf32_arm_plt_entry[0] | ((got_displacement & 0x0ff00000) >> 20),
6695 splt->contents + h->plt.offset + 0);
6696 bfd_put_32 (output_bfd, elf32_arm_plt_entry[1] | ((got_displacement & 0x000ff000) >> 12),
6697 splt->contents + h->plt.offset + 4);
6698 bfd_put_32 (output_bfd, elf32_arm_plt_entry[2] | (got_displacement & 0x00000fff),
6699 splt->contents + h->plt.offset + 8);
6700 #ifdef FOUR_WORD_PLT
6701 bfd_put_32 (output_bfd, elf32_arm_plt_entry[3],
6702 splt->contents + h->plt.offset + 12);
6703 #endif
6705 /* Fill in the entry in the global offset table. */
6706 bfd_put_32 (output_bfd,
6707 (splt->output_section->vma
6708 + splt->output_offset),
6709 sgot->contents + got_offset);
6711 /* Fill in the entry in the .rel.plt section. */
6712 rel.r_offset = (sgot->output_section->vma
6713 + sgot->output_offset
6714 + got_offset);
6715 rel.r_info = ELF32_R_INFO (h->dynindx, R_ARM_JUMP_SLOT);
6718 loc = srel->contents + plt_index * sizeof (Elf32_External_Rel);
6719 bfd_elf32_swap_reloc_out (output_bfd, &rel, loc);
6721 if (!h->def_regular)
6723 /* Mark the symbol as undefined, rather than as defined in
6724 the .plt section. Leave the value alone. */
6725 sym->st_shndx = SHN_UNDEF;
6726 /* If the symbol is weak, we do need to clear the value.
6727 Otherwise, the PLT entry would provide a definition for
6728 the symbol even if the symbol wasn't defined anywhere,
6729 and so the symbol would never be NULL. */
6730 if (!h->ref_regular_nonweak)
6731 sym->st_value = 0;
6735 if (h->got.offset != (bfd_vma) -1
6736 && (elf32_arm_hash_entry (h)->tls_type & GOT_TLS_GD) == 0
6737 && (elf32_arm_hash_entry (h)->tls_type & GOT_TLS_IE) == 0)
6739 asection * sgot;
6740 asection * srel;
6741 Elf_Internal_Rela rel;
6742 bfd_byte *loc;
6744 /* This symbol has an entry in the global offset table. Set it
6745 up. */
6746 sgot = bfd_get_section_by_name (dynobj, ".got");
6747 srel = bfd_get_section_by_name (dynobj, ".rel.got");
6748 BFD_ASSERT (sgot != NULL && srel != NULL);
6750 rel.r_offset = (sgot->output_section->vma
6751 + sgot->output_offset
6752 + (h->got.offset &~ (bfd_vma) 1));
6754 /* If this is a static link, or it is a -Bsymbolic link and the
6755 symbol is defined locally or was forced to be local because
6756 of a version file, we just want to emit a RELATIVE reloc.
6757 The entry in the global offset table will already have been
6758 initialized in the relocate_section function. */
6759 if (info->shared
6760 && SYMBOL_REFERENCES_LOCAL (info, h))
6762 BFD_ASSERT((h->got.offset & 1) != 0);
6763 rel.r_info = ELF32_R_INFO (0, R_ARM_RELATIVE);
6765 else
6767 BFD_ASSERT((h->got.offset & 1) == 0);
6768 bfd_put_32 (output_bfd, (bfd_vma) 0, sgot->contents + h->got.offset);
6769 rel.r_info = ELF32_R_INFO (h->dynindx, R_ARM_GLOB_DAT);
6772 loc = srel->contents + srel->reloc_count++ * sizeof (Elf32_External_Rel);
6773 bfd_elf32_swap_reloc_out (output_bfd, &rel, loc);
6776 if (h->needs_copy)
6778 asection * s;
6779 Elf_Internal_Rela rel;
6780 bfd_byte *loc;
6782 /* This symbol needs a copy reloc. Set it up. */
6783 BFD_ASSERT (h->dynindx != -1
6784 && (h->root.type == bfd_link_hash_defined
6785 || h->root.type == bfd_link_hash_defweak));
6787 s = bfd_get_section_by_name (h->root.u.def.section->owner,
6788 ".rel.bss");
6789 BFD_ASSERT (s != NULL);
6791 rel.r_offset = (h->root.u.def.value
6792 + h->root.u.def.section->output_section->vma
6793 + h->root.u.def.section->output_offset);
6794 rel.r_info = ELF32_R_INFO (h->dynindx, R_ARM_COPY);
6795 loc = s->contents + s->reloc_count++ * sizeof (Elf32_External_Rel);
6796 bfd_elf32_swap_reloc_out (output_bfd, &rel, loc);
6799 /* Mark _DYNAMIC and _GLOBAL_OFFSET_TABLE_ as absolute. */
6800 if (strcmp (h->root.root.string, "_DYNAMIC") == 0
6801 || strcmp (h->root.root.string, "_GLOBAL_OFFSET_TABLE_") == 0)
6802 sym->st_shndx = SHN_ABS;
6804 return TRUE;
6807 /* Finish up the dynamic sections. */
6809 static bfd_boolean
6810 elf32_arm_finish_dynamic_sections (bfd * output_bfd, struct bfd_link_info * info)
6812 bfd * dynobj;
6813 asection * sgot;
6814 asection * sdyn;
6816 dynobj = elf_hash_table (info)->dynobj;
6818 sgot = bfd_get_section_by_name (dynobj, ".got.plt");
6819 BFD_ASSERT (elf32_arm_hash_table (info)->symbian_p || sgot != NULL);
6820 sdyn = bfd_get_section_by_name (dynobj, ".dynamic");
6822 if (elf_hash_table (info)->dynamic_sections_created)
6824 asection *splt;
6825 Elf32_External_Dyn *dyncon, *dynconend;
6826 struct elf32_arm_link_hash_table *htab;
6828 htab = elf32_arm_hash_table (info);
6829 splt = bfd_get_section_by_name (dynobj, ".plt");
6830 BFD_ASSERT (splt != NULL && sdyn != NULL);
6832 dyncon = (Elf32_External_Dyn *) sdyn->contents;
6833 dynconend = (Elf32_External_Dyn *) (sdyn->contents + sdyn->size);
6835 for (; dyncon < dynconend; dyncon++)
6837 Elf_Internal_Dyn dyn;
6838 const char * name;
6839 asection * s;
6841 bfd_elf32_swap_dyn_in (dynobj, dyncon, &dyn);
6843 switch (dyn.d_tag)
6845 unsigned int type;
6847 default:
6848 break;
6850 case DT_HASH:
6851 name = ".hash";
6852 goto get_vma_if_bpabi;
6853 case DT_STRTAB:
6854 name = ".dynstr";
6855 goto get_vma_if_bpabi;
6856 case DT_SYMTAB:
6857 name = ".dynsym";
6858 goto get_vma_if_bpabi;
6859 case DT_VERSYM:
6860 name = ".gnu.version";
6861 goto get_vma_if_bpabi;
6862 case DT_VERDEF:
6863 name = ".gnu.version_d";
6864 goto get_vma_if_bpabi;
6865 case DT_VERNEED:
6866 name = ".gnu.version_r";
6867 goto get_vma_if_bpabi;
6869 case DT_PLTGOT:
6870 name = ".got";
6871 goto get_vma;
6872 case DT_JMPREL:
6873 name = ".rel.plt";
6874 get_vma:
6875 s = bfd_get_section_by_name (output_bfd, name);
6876 BFD_ASSERT (s != NULL);
6877 if (!htab->symbian_p)
6878 dyn.d_un.d_ptr = s->vma;
6879 else
6880 /* In the BPABI, tags in the PT_DYNAMIC section point
6881 at the file offset, not the memory address, for the
6882 convenience of the post linker. */
6883 dyn.d_un.d_ptr = s->filepos;
6884 bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon);
6885 break;
6887 get_vma_if_bpabi:
6888 if (htab->symbian_p)
6889 goto get_vma;
6890 break;
6892 case DT_PLTRELSZ:
6893 s = bfd_get_section_by_name (output_bfd, ".rel.plt");
6894 BFD_ASSERT (s != NULL);
6895 dyn.d_un.d_val = s->size;
6896 bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon);
6897 break;
6899 case DT_RELSZ:
6900 if (!htab->symbian_p)
6902 /* My reading of the SVR4 ABI indicates that the
6903 procedure linkage table relocs (DT_JMPREL) should be
6904 included in the overall relocs (DT_REL). This is
6905 what Solaris does. However, UnixWare can not handle
6906 that case. Therefore, we override the DT_RELSZ entry
6907 here to make it not include the JMPREL relocs. Since
6908 the linker script arranges for .rel.plt to follow all
6909 other relocation sections, we don't have to worry
6910 about changing the DT_REL entry. */
6911 s = bfd_get_section_by_name (output_bfd, ".rel.plt");
6912 if (s != NULL)
6913 dyn.d_un.d_val -= s->size;
6914 bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon);
6915 break;
6917 /* Fall through */
6919 case DT_REL:
6920 case DT_RELA:
6921 case DT_RELASZ:
6922 /* In the BPABI, the DT_REL tag must point at the file
6923 offset, not the VMA, of the first relocation
6924 section. So, we use code similar to that in
6925 elflink.c, but do not check for SHF_ALLOC on the
6926 relcoation section, since relocations sections are
6927 never allocated under the BPABI. The comments above
6928 about Unixware notwithstanding, we include all of the
6929 relocations here. */
6930 if (htab->symbian_p)
6932 unsigned int i;
6933 type = ((dyn.d_tag == DT_REL || dyn.d_tag == DT_RELSZ)
6934 ? SHT_REL : SHT_RELA);
6935 dyn.d_un.d_val = 0;
6936 for (i = 1; i < elf_numsections (output_bfd); i++)
6938 Elf_Internal_Shdr *hdr
6939 = elf_elfsections (output_bfd)[i];
6940 if (hdr->sh_type == type)
6942 if (dyn.d_tag == DT_RELSZ
6943 || dyn.d_tag == DT_RELASZ)
6944 dyn.d_un.d_val += hdr->sh_size;
6945 else if ((ufile_ptr) hdr->sh_offset
6946 <= dyn.d_un.d_val - 1)
6947 dyn.d_un.d_val = hdr->sh_offset;
6950 bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon);
6952 break;
6954 /* Set the bottom bit of DT_INIT/FINI if the
6955 corresponding function is Thumb. */
6956 case DT_INIT:
6957 name = info->init_function;
6958 goto get_sym;
6959 case DT_FINI:
6960 name = info->fini_function;
6961 get_sym:
6962 /* If it wasn't set by elf_bfd_final_link
6963 then there is nothing to adjust. */
6964 if (dyn.d_un.d_val != 0)
6966 struct elf_link_hash_entry * eh;
6968 eh = elf_link_hash_lookup (elf_hash_table (info), name,
6969 FALSE, FALSE, TRUE);
6970 if (eh != (struct elf_link_hash_entry *) NULL
6971 && ELF_ST_TYPE (eh->type) == STT_ARM_TFUNC)
6973 dyn.d_un.d_val |= 1;
6974 bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon);
6977 break;
6981 /* Fill in the first entry in the procedure linkage table. */
6982 if (splt->size > 0 && elf32_arm_hash_table (info)->plt_header_size)
6984 bfd_vma got_displacement;
6986 /* Calculate the displacement between the PLT slot and &GOT[0]. */
6987 got_displacement = (sgot->output_section->vma
6988 + sgot->output_offset
6989 - splt->output_section->vma
6990 - splt->output_offset
6991 - 16);
6993 bfd_put_32 (output_bfd, elf32_arm_plt0_entry[0], splt->contents + 0);
6994 bfd_put_32 (output_bfd, elf32_arm_plt0_entry[1], splt->contents + 4);
6995 bfd_put_32 (output_bfd, elf32_arm_plt0_entry[2], splt->contents + 8);
6996 bfd_put_32 (output_bfd, elf32_arm_plt0_entry[3], splt->contents + 12);
6997 #ifdef FOUR_WORD_PLT
6998 /* The displacement value goes in the otherwise-unused last word of
6999 the second entry. */
7000 bfd_put_32 (output_bfd, got_displacement, splt->contents + 28);
7001 #else
7002 bfd_put_32 (output_bfd, got_displacement, splt->contents + 16);
7003 #endif
7006 /* UnixWare sets the entsize of .plt to 4, although that doesn't
7007 really seem like the right value. */
7008 elf_section_data (splt->output_section)->this_hdr.sh_entsize = 4;
7011 /* Fill in the first three entries in the global offset table. */
7012 if (sgot)
7014 if (sgot->size > 0)
7016 if (sdyn == NULL)
7017 bfd_put_32 (output_bfd, (bfd_vma) 0, sgot->contents);
7018 else
7019 bfd_put_32 (output_bfd,
7020 sdyn->output_section->vma + sdyn->output_offset,
7021 sgot->contents);
7022 bfd_put_32 (output_bfd, (bfd_vma) 0, sgot->contents + 4);
7023 bfd_put_32 (output_bfd, (bfd_vma) 0, sgot->contents + 8);
7026 elf_section_data (sgot->output_section)->this_hdr.sh_entsize = 4;
7029 return TRUE;
7032 static void
7033 elf32_arm_post_process_headers (bfd * abfd, struct bfd_link_info * link_info ATTRIBUTE_UNUSED)
7035 Elf_Internal_Ehdr * i_ehdrp; /* ELF file header, internal form. */
7036 struct elf32_arm_link_hash_table *globals;
7038 i_ehdrp = elf_elfheader (abfd);
7040 if (EF_ARM_EABI_VERSION (i_ehdrp->e_flags) == EF_ARM_EABI_UNKNOWN)
7041 i_ehdrp->e_ident[EI_OSABI] = ELFOSABI_ARM;
7042 else
7043 i_ehdrp->e_ident[EI_OSABI] = 0;
7044 i_ehdrp->e_ident[EI_ABIVERSION] = ARM_ELF_ABI_VERSION;
7046 if (link_info)
7048 globals = elf32_arm_hash_table (link_info);
7049 if (globals->byteswap_code)
7050 i_ehdrp->e_flags |= EF_ARM_BE8;
7054 static enum elf_reloc_type_class
7055 elf32_arm_reloc_type_class (const Elf_Internal_Rela *rela)
7057 switch ((int) ELF32_R_TYPE (rela->r_info))
7059 case R_ARM_RELATIVE:
7060 return reloc_class_relative;
7061 case R_ARM_JUMP_SLOT:
7062 return reloc_class_plt;
7063 case R_ARM_COPY:
7064 return reloc_class_copy;
7065 default:
7066 return reloc_class_normal;
7070 /* Set the right machine number for an Arm ELF file. */
7072 static bfd_boolean
7073 elf32_arm_section_flags (flagword *flags, const Elf_Internal_Shdr *hdr)
7075 if (hdr->sh_type == SHT_NOTE)
7076 *flags |= SEC_LINK_ONCE | SEC_LINK_DUPLICATES_SAME_CONTENTS;
7078 return TRUE;
7081 static void
7082 elf32_arm_final_write_processing (bfd *abfd, bfd_boolean linker ATTRIBUTE_UNUSED)
7084 bfd_arm_update_notes (abfd, ARM_NOTE_SECTION);
7087 /* Return TRUE if this is an unwinding table entry. */
7089 static bfd_boolean
7090 is_arm_elf_unwind_section_name (bfd * abfd ATTRIBUTE_UNUSED, const char * name)
7092 size_t len1, len2;
7094 len1 = sizeof (ELF_STRING_ARM_unwind) - 1;
7095 len2 = sizeof (ELF_STRING_ARM_unwind_once) - 1;
7096 return (strncmp (name, ELF_STRING_ARM_unwind, len1) == 0
7097 || strncmp (name, ELF_STRING_ARM_unwind_once, len2) == 0);
7101 /* Set the type and flags for an ARM section. We do this by
7102 the section name, which is a hack, but ought to work. */
7104 static bfd_boolean
7105 elf32_arm_fake_sections (bfd * abfd, Elf_Internal_Shdr * hdr, asection * sec)
7107 const char * name;
7109 name = bfd_get_section_name (abfd, sec);
7111 if (is_arm_elf_unwind_section_name (abfd, name))
7113 hdr->sh_type = SHT_ARM_EXIDX;
7114 hdr->sh_flags |= SHF_LINK_ORDER;
7116 else if (strcmp(name, ".ARM.attributes") == 0)
7118 hdr->sh_type = SHT_ARM_ATTRIBUTES;
7120 return TRUE;
7123 /* Parse an Arm EABI attributes section. */
7124 static void
7125 elf32_arm_parse_attributes (bfd *abfd, Elf_Internal_Shdr * hdr)
7127 bfd_byte *contents;
7128 bfd_byte *p;
7129 bfd_vma len;
7131 contents = bfd_malloc (hdr->sh_size);
7132 if (!contents)
7133 return;
7134 if (!bfd_get_section_contents (abfd, hdr->bfd_section, contents, 0,
7135 hdr->sh_size))
7137 free (contents);
7138 return;
7140 p = contents;
7141 if (*(p++) == 'A')
7143 len = hdr->sh_size - 1;
7144 while (len > 0)
7146 int namelen;
7147 bfd_vma section_len;
7149 section_len = bfd_get_32 (abfd, p);
7150 p += 4;
7151 if (section_len > len)
7152 section_len = len;
7153 len -= section_len;
7154 namelen = strlen ((char *)p) + 1;
7155 section_len -= namelen + 4;
7156 if (strcmp((char *)p, "aeabi") != 0)
7158 /* Vendor section. Ignore it. */
7159 p += namelen + section_len;
7161 else
7163 p += namelen;
7164 while (section_len > 0)
7166 int tag;
7167 unsigned int n;
7168 unsigned int val;
7169 bfd_vma subsection_len;
7170 bfd_byte *end;
7172 tag = read_unsigned_leb128 (abfd, p, &n);
7173 p += n;
7174 subsection_len = bfd_get_32 (abfd, p);
7175 p += 4;
7176 if (subsection_len > section_len)
7177 subsection_len = section_len;
7178 section_len -= subsection_len;
7179 subsection_len -= n + 4;
7180 end = p + subsection_len;
7181 switch (tag)
7183 case Tag_File:
7184 while (p < end)
7186 bfd_boolean is_string;
7188 tag = read_unsigned_leb128 (abfd, p, &n);
7189 p += n;
7190 if (tag == 4 || tag == 5)
7191 is_string = 1;
7192 else if (tag < 32)
7193 is_string = 0;
7194 else
7195 is_string = (tag & 1) != 0;
7196 if (tag == Tag_compatibility)
7198 val = read_unsigned_leb128 (abfd, p, &n);
7199 p += n;
7200 elf32_arm_add_eabi_attr_compat (abfd, val,
7201 (char *)p);
7202 p += strlen ((char *)p) + 1;
7204 else if (is_string)
7206 elf32_arm_add_eabi_attr_string (abfd, tag,
7207 (char *)p);
7208 p += strlen ((char *)p) + 1;
7210 else
7212 val = read_unsigned_leb128 (abfd, p, &n);
7213 p += n;
7214 elf32_arm_add_eabi_attr_int (abfd, tag, val);
7217 break;
7218 case Tag_Section:
7219 case Tag_Symbol:
7220 /* Don't have anywhere convenient to attach these.
7221 Fall through for now. */
7222 default:
7223 /* Ignore things we don't kow about. */
7224 p += subsection_len;
7225 subsection_len = 0;
7226 break;
7232 free (contents);
7235 /* Handle an ARM specific section when reading an object file. This is
7236 called when bfd_section_from_shdr finds a section with an unknown
7237 type. */
7239 static bfd_boolean
7240 elf32_arm_section_from_shdr (bfd *abfd,
7241 Elf_Internal_Shdr * hdr,
7242 const char *name,
7243 int shindex)
7245 /* There ought to be a place to keep ELF backend specific flags, but
7246 at the moment there isn't one. We just keep track of the
7247 sections by their name, instead. Fortunately, the ABI gives
7248 names for all the ARM specific sections, so we will probably get
7249 away with this. */
7250 switch (hdr->sh_type)
7252 case SHT_ARM_EXIDX:
7253 case SHT_ARM_PREEMPTMAP:
7254 case SHT_ARM_ATTRIBUTES:
7255 break;
7257 default:
7258 return FALSE;
7261 if (! _bfd_elf_make_section_from_shdr (abfd, hdr, name, shindex))
7262 return FALSE;
7264 if (hdr->sh_type == SHT_ARM_ATTRIBUTES)
7265 elf32_arm_parse_attributes(abfd, hdr);
7266 return TRUE;
7269 /* A structure used to record a list of sections, independently
7270 of the next and prev fields in the asection structure. */
7271 typedef struct section_list
7273 asection * sec;
7274 struct section_list * next;
7275 struct section_list * prev;
7277 section_list;
7279 /* Unfortunately we need to keep a list of sections for which
7280 an _arm_elf_section_data structure has been allocated. This
7281 is because it is possible for functions like elf32_arm_write_section
7282 to be called on a section which has had an elf_data_structure
7283 allocated for it (and so the used_by_bfd field is valid) but
7284 for which the ARM extended version of this structure - the
7285 _arm_elf_section_data structure - has not been allocated. */
7286 static section_list * sections_with_arm_elf_section_data = NULL;
7288 static void
7289 record_section_with_arm_elf_section_data (asection * sec)
7291 struct section_list * entry;
7293 entry = bfd_malloc (sizeof (* entry));
7294 if (entry == NULL)
7295 return;
7296 entry->sec = sec;
7297 entry->next = sections_with_arm_elf_section_data;
7298 entry->prev = NULL;
7299 if (entry->next != NULL)
7300 entry->next->prev = entry;
7301 sections_with_arm_elf_section_data = entry;
7304 static struct section_list *
7305 find_arm_elf_section_entry (asection * sec)
7307 struct section_list * entry;
7308 static struct section_list * last_entry = NULL;
7310 /* This is a short cut for the typical case where the sections are added
7311 to the sections_with_arm_elf_section_data list in forward order and
7312 then looked up here in backwards order. This makes a real difference
7313 to the ld-srec/sec64k.exp linker test. */
7314 entry = sections_with_arm_elf_section_data;
7315 if (last_entry != NULL)
7317 if (last_entry->sec == sec)
7318 entry = last_entry;
7319 else if (last_entry->next != NULL
7320 && last_entry->next->sec == sec)
7321 entry = last_entry->next;
7324 for (; entry; entry = entry->next)
7325 if (entry->sec == sec)
7326 break;
7328 if (entry)
7329 /* Record the entry prior to this one - it is the entry we are most
7330 likely to want to locate next time. Also this way if we have been
7331 called from unrecord_section_with_arm_elf_section_data() we will not
7332 be caching a pointer that is about to be freed. */
7333 last_entry = entry->prev;
7335 return entry;
7338 static _arm_elf_section_data *
7339 get_arm_elf_section_data (asection * sec)
7341 struct section_list * entry;
7343 entry = find_arm_elf_section_entry (sec);
7345 if (entry)
7346 return elf32_arm_section_data (entry->sec);
7347 else
7348 return NULL;
7351 static void
7352 unrecord_section_with_arm_elf_section_data (asection * sec)
7354 struct section_list * entry;
7356 entry = find_arm_elf_section_entry (sec);
7358 if (entry)
7360 if (entry->prev != NULL)
7361 entry->prev->next = entry->next;
7362 if (entry->next != NULL)
7363 entry->next->prev = entry->prev;
7364 if (entry == sections_with_arm_elf_section_data)
7365 sections_with_arm_elf_section_data = entry->next;
7366 free (entry);
7370 /* Called for each symbol. Builds a section map based on mapping symbols.
7371 Does not alter any of the symbols. */
7373 static bfd_boolean
7374 elf32_arm_output_symbol_hook (struct bfd_link_info *info,
7375 const char *name,
7376 Elf_Internal_Sym *elfsym,
7377 asection *input_sec,
7378 struct elf_link_hash_entry *h ATTRIBUTE_UNUSED)
7380 int mapcount;
7381 elf32_arm_section_map *map;
7382 elf32_arm_section_map *newmap;
7383 _arm_elf_section_data *arm_data;
7384 struct elf32_arm_link_hash_table *globals;
7386 /* Only do this on final link. */
7387 if (info->relocatable)
7388 return TRUE;
7390 /* Only build a map if we need to byteswap code. */
7391 globals = elf32_arm_hash_table (info);
7392 if (!globals->byteswap_code)
7393 return TRUE;
7395 /* We only want mapping symbols. */
7396 if (! bfd_is_arm_mapping_symbol_name (name))
7397 return TRUE;
7399 /* If this section has not been allocated an _arm_elf_section_data
7400 structure then we cannot record anything. */
7401 arm_data = get_arm_elf_section_data (input_sec);
7402 if (arm_data == NULL)
7403 return TRUE;
7405 mapcount = arm_data->mapcount + 1;
7406 map = arm_data->map;
7407 /* TODO: This may be inefficient, but we probably don't usually have many
7408 mapping symbols per section. */
7409 newmap = bfd_realloc (map, mapcount * sizeof (* map));
7410 if (newmap != NULL)
7412 arm_data->map = newmap;
7413 arm_data->mapcount = mapcount;
7415 map[mapcount - 1].vma = elfsym->st_value;
7416 map[mapcount - 1].type = name[1];
7419 return TRUE;
7422 /* Allocate target specific section data. */
7424 static bfd_boolean
7425 elf32_arm_new_section_hook (bfd *abfd, asection *sec)
7427 _arm_elf_section_data *sdata;
7428 bfd_size_type amt = sizeof (*sdata);
7430 sdata = bfd_zalloc (abfd, amt);
7431 if (sdata == NULL)
7432 return FALSE;
7433 sec->used_by_bfd = sdata;
7435 record_section_with_arm_elf_section_data (sec);
7437 return _bfd_elf_new_section_hook (abfd, sec);
7441 /* Used to order a list of mapping symbols by address. */
7443 static int
7444 elf32_arm_compare_mapping (const void * a, const void * b)
7446 return ((const elf32_arm_section_map *) a)->vma
7447 > ((const elf32_arm_section_map *) b)->vma;
7451 /* Do code byteswapping. Return FALSE afterwards so that the section is
7452 written out as normal. */
7454 static bfd_boolean
7455 elf32_arm_write_section (bfd *output_bfd ATTRIBUTE_UNUSED, asection *sec,
7456 bfd_byte *contents)
7458 int mapcount;
7459 _arm_elf_section_data *arm_data;
7460 elf32_arm_section_map *map;
7461 bfd_vma ptr;
7462 bfd_vma end;
7463 bfd_vma offset;
7464 bfd_byte tmp;
7465 int i;
7467 /* If this section has not been allocated an _arm_elf_section_data
7468 structure then we cannot record anything. */
7469 arm_data = get_arm_elf_section_data (sec);
7470 if (arm_data == NULL)
7471 return FALSE;
7473 mapcount = arm_data->mapcount;
7474 map = arm_data->map;
7476 if (mapcount == 0)
7477 return FALSE;
7479 qsort (map, mapcount, sizeof (* map), elf32_arm_compare_mapping);
7481 offset = sec->output_section->vma + sec->output_offset;
7482 ptr = map[0].vma - offset;
7483 for (i = 0; i < mapcount; i++)
7485 if (i == mapcount - 1)
7486 end = sec->size;
7487 else
7488 end = map[i + 1].vma - offset;
7490 switch (map[i].type)
7492 case 'a':
7493 /* Byte swap code words. */
7494 while (ptr + 3 < end)
7496 tmp = contents[ptr];
7497 contents[ptr] = contents[ptr + 3];
7498 contents[ptr + 3] = tmp;
7499 tmp = contents[ptr + 1];
7500 contents[ptr + 1] = contents[ptr + 2];
7501 contents[ptr + 2] = tmp;
7502 ptr += 4;
7504 break;
7506 case 't':
7507 /* Byte swap code halfwords. */
7508 while (ptr + 1 < end)
7510 tmp = contents[ptr];
7511 contents[ptr] = contents[ptr + 1];
7512 contents[ptr + 1] = tmp;
7513 ptr += 2;
7515 break;
7517 case 'd':
7518 /* Leave data alone. */
7519 break;
7521 ptr = end;
7524 free (map);
7525 arm_data->mapcount = 0;
7526 arm_data->map = NULL;
7527 unrecord_section_with_arm_elf_section_data (sec);
7529 return FALSE;
7532 static void
7533 unrecord_section_via_map_over_sections (bfd * abfd ATTRIBUTE_UNUSED,
7534 asection * sec,
7535 void * ignore ATTRIBUTE_UNUSED)
7537 unrecord_section_with_arm_elf_section_data (sec);
7540 static bfd_boolean
7541 elf32_arm_close_and_cleanup (bfd * abfd)
7543 bfd_map_over_sections (abfd, unrecord_section_via_map_over_sections, NULL);
7545 return _bfd_elf_close_and_cleanup (abfd);
7548 /* Display STT_ARM_TFUNC symbols as functions. */
7550 static void
7551 elf32_arm_symbol_processing (bfd *abfd ATTRIBUTE_UNUSED,
7552 asymbol *asym)
7554 elf_symbol_type *elfsym = (elf_symbol_type *) asym;
7556 if (ELF_ST_TYPE (elfsym->internal_elf_sym.st_info) == STT_ARM_TFUNC)
7557 elfsym->symbol.flags |= BSF_FUNCTION;
7561 /* Mangle thumb function symbols as we read them in. */
7563 static void
7564 elf32_arm_swap_symbol_in (bfd * abfd,
7565 const void *psrc,
7566 const void *pshn,
7567 Elf_Internal_Sym *dst)
7569 bfd_elf32_swap_symbol_in (abfd, psrc, pshn, dst);
7571 /* New EABI objects mark thumb function symbols by setting the low bit of
7572 the address. Turn these into STT_ARM_TFUNC. */
7573 if (ELF_ST_TYPE (dst->st_info) == STT_FUNC
7574 && (dst->st_value & 1))
7576 dst->st_info = ELF_ST_INFO (ELF_ST_BIND (dst->st_info), STT_ARM_TFUNC);
7577 dst->st_value &= ~(bfd_vma) 1;
7582 /* Mangle thumb function symbols as we write them out. */
7584 static void
7585 elf32_arm_swap_symbol_out (bfd *abfd,
7586 const Elf_Internal_Sym *src,
7587 void *cdst,
7588 void *shndx)
7590 Elf_Internal_Sym newsym;
7592 /* We convert STT_ARM_TFUNC symbols into STT_FUNC with the low bit
7593 of the address set, as per the new EABI. We do this unconditionally
7594 because objcopy does not set the elf header flags until after
7595 it writes out the symbol table. */
7596 if (ELF_ST_TYPE (src->st_info) == STT_ARM_TFUNC)
7598 newsym = *src;
7599 newsym.st_info = ELF_ST_INFO (ELF_ST_BIND (src->st_info), STT_FUNC);
7600 newsym.st_value |= 1;
7602 src = &newsym;
7604 bfd_elf32_swap_symbol_out (abfd, src, cdst, shndx);
7607 /* Add the PT_ARM_EXIDX program header. */
7609 static bfd_boolean
7610 elf32_arm_modify_segment_map (bfd *abfd,
7611 struct bfd_link_info *info ATTRIBUTE_UNUSED)
7613 struct elf_segment_map *m;
7614 asection *sec;
7616 sec = bfd_get_section_by_name (abfd, ".ARM.exidx");
7617 if (sec != NULL && (sec->flags & SEC_LOAD) != 0)
7619 /* If there is already a PT_ARM_EXIDX header, then we do not
7620 want to add another one. This situation arises when running
7621 "strip"; the input binary already has the header. */
7622 m = elf_tdata (abfd)->segment_map;
7623 while (m && m->p_type != PT_ARM_EXIDX)
7624 m = m->next;
7625 if (!m)
7627 m = bfd_zalloc (abfd, sizeof (struct elf_segment_map));
7628 if (m == NULL)
7629 return FALSE;
7630 m->p_type = PT_ARM_EXIDX;
7631 m->count = 1;
7632 m->sections[0] = sec;
7634 m->next = elf_tdata (abfd)->segment_map;
7635 elf_tdata (abfd)->segment_map = m;
7639 return TRUE;
7642 /* We may add a PT_ARM_EXIDX program header. */
7644 static int
7645 elf32_arm_additional_program_headers (bfd *abfd)
7647 asection *sec;
7649 sec = bfd_get_section_by_name (abfd, ".ARM.exidx");
7650 if (sec != NULL && (sec->flags & SEC_LOAD) != 0)
7651 return 1;
7652 else
7653 return 0;
7656 /* We use this to override swap_symbol_in and swap_symbol_out. */
7657 const struct elf_size_info elf32_arm_size_info = {
7658 sizeof (Elf32_External_Ehdr),
7659 sizeof (Elf32_External_Phdr),
7660 sizeof (Elf32_External_Shdr),
7661 sizeof (Elf32_External_Rel),
7662 sizeof (Elf32_External_Rela),
7663 sizeof (Elf32_External_Sym),
7664 sizeof (Elf32_External_Dyn),
7665 sizeof (Elf_External_Note),
7668 32, 2,
7669 ELFCLASS32, EV_CURRENT,
7670 bfd_elf32_write_out_phdrs,
7671 bfd_elf32_write_shdrs_and_ehdr,
7672 bfd_elf32_write_relocs,
7673 elf32_arm_swap_symbol_in,
7674 elf32_arm_swap_symbol_out,
7675 bfd_elf32_slurp_reloc_table,
7676 bfd_elf32_slurp_symbol_table,
7677 bfd_elf32_swap_dyn_in,
7678 bfd_elf32_swap_dyn_out,
7679 bfd_elf32_swap_reloc_in,
7680 bfd_elf32_swap_reloc_out,
7681 bfd_elf32_swap_reloca_in,
7682 bfd_elf32_swap_reloca_out
7685 #define ELF_ARCH bfd_arch_arm
7686 #define ELF_MACHINE_CODE EM_ARM
7687 #ifdef __QNXTARGET__
7688 #define ELF_MAXPAGESIZE 0x1000
7689 #else
7690 #define ELF_MAXPAGESIZE 0x8000
7691 #endif
7692 #define ELF_MINPAGESIZE 0x1000
7694 #define bfd_elf32_mkobject elf32_arm_mkobject
7696 #define bfd_elf32_bfd_copy_private_bfd_data elf32_arm_copy_private_bfd_data
7697 #define bfd_elf32_bfd_merge_private_bfd_data elf32_arm_merge_private_bfd_data
7698 #define bfd_elf32_bfd_set_private_flags elf32_arm_set_private_flags
7699 #define bfd_elf32_bfd_print_private_bfd_data elf32_arm_print_private_bfd_data
7700 #define bfd_elf32_bfd_link_hash_table_create elf32_arm_link_hash_table_create
7701 #define bfd_elf32_bfd_reloc_type_lookup elf32_arm_reloc_type_lookup
7702 #define bfd_elf32_find_nearest_line elf32_arm_find_nearest_line
7703 #define bfd_elf32_find_inliner_info elf32_arm_find_inliner_info
7704 #define bfd_elf32_new_section_hook elf32_arm_new_section_hook
7705 #define bfd_elf32_bfd_is_target_special_symbol elf32_arm_is_target_special_symbol
7706 #define bfd_elf32_close_and_cleanup elf32_arm_close_and_cleanup
7707 #define bfd_elf32_bfd_final_link elf32_arm_bfd_final_link
7709 #define elf_backend_get_symbol_type elf32_arm_get_symbol_type
7710 #define elf_backend_gc_mark_hook elf32_arm_gc_mark_hook
7711 #define elf_backend_gc_sweep_hook elf32_arm_gc_sweep_hook
7712 #define elf_backend_check_relocs elf32_arm_check_relocs
7713 #define elf_backend_relocate_section elf32_arm_relocate_section
7714 #define elf_backend_write_section elf32_arm_write_section
7715 #define elf_backend_adjust_dynamic_symbol elf32_arm_adjust_dynamic_symbol
7716 #define elf_backend_create_dynamic_sections elf32_arm_create_dynamic_sections
7717 #define elf_backend_finish_dynamic_symbol elf32_arm_finish_dynamic_symbol
7718 #define elf_backend_finish_dynamic_sections elf32_arm_finish_dynamic_sections
7719 #define elf_backend_link_output_symbol_hook elf32_arm_output_symbol_hook
7720 #define elf_backend_size_dynamic_sections elf32_arm_size_dynamic_sections
7721 #define elf_backend_post_process_headers elf32_arm_post_process_headers
7722 #define elf_backend_reloc_type_class elf32_arm_reloc_type_class
7723 #define elf_backend_object_p elf32_arm_object_p
7724 #define elf_backend_section_flags elf32_arm_section_flags
7725 #define elf_backend_fake_sections elf32_arm_fake_sections
7726 #define elf_backend_section_from_shdr elf32_arm_section_from_shdr
7727 #define elf_backend_final_write_processing elf32_arm_final_write_processing
7728 #define elf_backend_copy_indirect_symbol elf32_arm_copy_indirect_symbol
7729 #define elf_backend_symbol_processing elf32_arm_symbol_processing
7730 #define elf_backend_size_info elf32_arm_size_info
7731 #define elf_backend_modify_segment_map elf32_arm_modify_segment_map
7732 #define elf_backend_additional_program_headers \
7733 elf32_arm_additional_program_headers
7735 #define elf_backend_can_refcount 1
7736 #define elf_backend_can_gc_sections 1
7737 #define elf_backend_plt_readonly 1
7738 #define elf_backend_want_got_plt 1
7739 #define elf_backend_want_plt_sym 0
7740 #define elf_backend_may_use_rel_p 1
7741 #define elf_backend_may_use_rela_p 0
7742 #define elf_backend_default_use_rela_p 0
7743 #define elf_backend_rela_normal 0
7745 #define elf_backend_got_header_size 12
7747 #include "elf32-target.h"
7749 /* VxWorks Targets */
7751 #undef TARGET_LITTLE_SYM
7752 #define TARGET_LITTLE_SYM bfd_elf32_littlearm_vxworks_vec
7753 #undef TARGET_LITTLE_NAME
7754 #define TARGET_LITTLE_NAME "elf32-littlearm-vxworks"
7755 #undef TARGET_BIG_SYM
7756 #define TARGET_BIG_SYM bfd_elf32_bigarm_vxworks_vec
7757 #undef TARGET_BIG_NAME
7758 #define TARGET_BIG_NAME "elf32-bigarm-vxworks"
7760 /* Like elf32_arm_link_hash_table_create -- but overrides
7761 appropriately for VxWorks. */
7762 static struct bfd_link_hash_table *
7763 elf32_arm_vxworks_link_hash_table_create (bfd *abfd)
7765 struct bfd_link_hash_table *ret;
7767 ret = elf32_arm_link_hash_table_create (abfd);
7768 if (ret)
7770 struct elf32_arm_link_hash_table *htab
7771 = (struct elf32_arm_link_hash_table *)ret;
7772 htab->use_rel = 0;
7774 return ret;
7777 #undef elf32_bed
7778 #define elf32_bed elf32_arm_vxworks_bed
7780 #undef bfd_elf32_bfd_link_hash_table_create
7781 #define bfd_elf32_bfd_link_hash_table_create \
7782 elf32_arm_vxworks_link_hash_table_create
7784 #undef elf_backend_may_use_rel_p
7785 #define elf_backend_may_use_rel_p 0
7786 #undef elf_backend_may_use_rela_p
7787 #define elf_backend_may_use_rela_p 1
7788 #undef elf_backend_default_use_rela_p
7789 #define elf_backend_default_use_rela_p 1
7790 #undef elf_backend_rela_normal
7791 #define elf_backend_rela_normal 1
7793 #include "elf32-target.h"
7796 /* Symbian OS Targets */
7798 #undef TARGET_LITTLE_SYM
7799 #define TARGET_LITTLE_SYM bfd_elf32_littlearm_symbian_vec
7800 #undef TARGET_LITTLE_NAME
7801 #define TARGET_LITTLE_NAME "elf32-littlearm-symbian"
7802 #undef TARGET_BIG_SYM
7803 #define TARGET_BIG_SYM bfd_elf32_bigarm_symbian_vec
7804 #undef TARGET_BIG_NAME
7805 #define TARGET_BIG_NAME "elf32-bigarm-symbian"
7807 /* Like elf32_arm_link_hash_table_create -- but overrides
7808 appropriately for Symbian OS. */
7809 static struct bfd_link_hash_table *
7810 elf32_arm_symbian_link_hash_table_create (bfd *abfd)
7812 struct bfd_link_hash_table *ret;
7814 ret = elf32_arm_link_hash_table_create (abfd);
7815 if (ret)
7817 struct elf32_arm_link_hash_table *htab
7818 = (struct elf32_arm_link_hash_table *)ret;
7819 /* There is no PLT header for Symbian OS. */
7820 htab->plt_header_size = 0;
7821 /* The PLT entries are each three instructions. */
7822 htab->plt_entry_size = 4 * NUM_ELEM (elf32_arm_symbian_plt_entry);
7823 htab->symbian_p = 1;
7824 /* Symbian uses armv5t or above, so use_blx is always true. */
7825 htab->use_blx = 1;
7826 htab->root.is_relocatable_executable = 1;
7828 return ret;
7831 static const struct bfd_elf_special_section
7832 elf32_arm_symbian_special_sections[] =
7834 /* In a BPABI executable, the dynamic linking sections do not go in
7835 the loadable read-only segment. The post-linker may wish to
7836 refer to these sections, but they are not part of the final
7837 program image. */
7838 { ".dynamic", 8, 0, SHT_DYNAMIC, 0 },
7839 { ".dynstr", 7, 0, SHT_STRTAB, 0 },
7840 { ".dynsym", 7, 0, SHT_DYNSYM, 0 },
7841 { ".got", 4, 0, SHT_PROGBITS, 0 },
7842 { ".hash", 5, 0, SHT_HASH, 0 },
7843 /* These sections do not need to be writable as the SymbianOS
7844 postlinker will arrange things so that no dynamic relocation is
7845 required. */
7846 { ".init_array", 11, 0, SHT_INIT_ARRAY, SHF_ALLOC },
7847 { ".fini_array", 11, 0, SHT_FINI_ARRAY, SHF_ALLOC },
7848 { ".preinit_array", 14, 0, SHT_PREINIT_ARRAY, SHF_ALLOC },
7849 { NULL, 0, 0, 0, 0 }
7852 static void
7853 elf32_arm_symbian_begin_write_processing (bfd *abfd,
7854 struct bfd_link_info *link_info
7855 ATTRIBUTE_UNUSED)
7857 /* BPABI objects are never loaded directly by an OS kernel; they are
7858 processed by a postlinker first, into an OS-specific format. If
7859 the D_PAGED bit is set on the file, BFD will align segments on
7860 page boundaries, so that an OS can directly map the file. With
7861 BPABI objects, that just results in wasted space. In addition,
7862 because we clear the D_PAGED bit, map_sections_to_segments will
7863 recognize that the program headers should not be mapped into any
7864 loadable segment. */
7865 abfd->flags &= ~D_PAGED;
7868 static bfd_boolean
7869 elf32_arm_symbian_modify_segment_map (bfd *abfd,
7870 struct bfd_link_info *info)
7872 struct elf_segment_map *m;
7873 asection *dynsec;
7875 /* BPABI shared libraries and executables should have a PT_DYNAMIC
7876 segment. However, because the .dynamic section is not marked
7877 with SEC_LOAD, the generic ELF code will not create such a
7878 segment. */
7879 dynsec = bfd_get_section_by_name (abfd, ".dynamic");
7880 if (dynsec)
7882 m = _bfd_elf_make_dynamic_segment (abfd, dynsec);
7883 m->next = elf_tdata (abfd)->segment_map;
7884 elf_tdata (abfd)->segment_map = m;
7887 /* Also call the generic arm routine. */
7888 return elf32_arm_modify_segment_map (abfd, info);
7891 #undef elf32_bed
7892 #define elf32_bed elf32_arm_symbian_bed
7894 /* The dynamic sections are not allocated on SymbianOS; the postlinker
7895 will process them and then discard them. */
7896 #undef ELF_DYNAMIC_SEC_FLAGS
7897 #define ELF_DYNAMIC_SEC_FLAGS \
7898 (SEC_HAS_CONTENTS | SEC_IN_MEMORY | SEC_LINKER_CREATED)
7900 #undef bfd_elf32_bfd_link_hash_table_create
7901 #define bfd_elf32_bfd_link_hash_table_create \
7902 elf32_arm_symbian_link_hash_table_create
7904 #undef elf_backend_special_sections
7905 #define elf_backend_special_sections elf32_arm_symbian_special_sections
7907 #undef elf_backend_begin_write_processing
7908 #define elf_backend_begin_write_processing \
7909 elf32_arm_symbian_begin_write_processing
7911 #undef elf_backend_modify_segment_map
7912 #define elf_backend_modify_segment_map elf32_arm_symbian_modify_segment_map
7914 /* There is no .got section for BPABI objects, and hence no header. */
7915 #undef elf_backend_got_header_size
7916 #define elf_backend_got_header_size 0
7918 /* Similarly, there is no .got.plt section. */
7919 #undef elf_backend_want_got_plt
7920 #define elf_backend_want_got_plt 0
7922 #undef elf_backend_may_use_rel_p
7923 #define elf_backend_may_use_rel_p 1
7924 #undef elf_backend_may_use_rela_p
7925 #define elf_backend_may_use_rela_p 0
7926 #undef elf_backend_default_use_rela_p
7927 #define elf_backend_default_use_rela_p 0
7928 #undef elf_backend_rela_normal
7929 #define elf_backend_rela_normal 0
7931 #include "elf32-target.h"