PR ld/2218
[binutils.git] / bfd / elf32-arm.c
blobf9887168e0f96adcd906b03255097fa4a5253f8f
1 /* 32-bit ELF support for ARM
2 Copyright 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006
3 Free Software Foundation, Inc.
5 This file is part of BFD, the Binary File Descriptor library.
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA. */
21 #include "bfd.h"
22 #include "sysdep.h"
23 #include "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_CALL, R_ARM_CALL},
1301 {BFD_RELOC_ARM_PCREL_JUMP, R_ARM_JUMP24},
1302 {BFD_RELOC_ARM_PCREL_BLX, R_ARM_XPC25},
1303 {BFD_RELOC_THUMB_PCREL_BLX, R_ARM_THM_XPC22},
1304 {BFD_RELOC_32, R_ARM_ABS32},
1305 {BFD_RELOC_32_PCREL, R_ARM_REL32},
1306 {BFD_RELOC_8, R_ARM_ABS8},
1307 {BFD_RELOC_16, R_ARM_ABS16},
1308 {BFD_RELOC_ARM_OFFSET_IMM, R_ARM_ABS12},
1309 {BFD_RELOC_ARM_THUMB_OFFSET, R_ARM_THM_ABS5},
1310 {BFD_RELOC_THUMB_PCREL_BRANCH25, R_ARM_THM_JUMP24},
1311 {BFD_RELOC_THUMB_PCREL_BRANCH23, R_ARM_THM_CALL},
1312 {BFD_RELOC_THUMB_PCREL_BRANCH12, R_ARM_THM_JUMP11},
1313 {BFD_RELOC_THUMB_PCREL_BRANCH20, R_ARM_THM_JUMP19},
1314 {BFD_RELOC_THUMB_PCREL_BRANCH9, R_ARM_THM_JUMP8},
1315 {BFD_RELOC_THUMB_PCREL_BRANCH7, R_ARM_THM_JUMP6},
1316 {BFD_RELOC_ARM_GLOB_DAT, R_ARM_GLOB_DAT},
1317 {BFD_RELOC_ARM_JUMP_SLOT, R_ARM_JUMP_SLOT},
1318 {BFD_RELOC_ARM_RELATIVE, R_ARM_RELATIVE},
1319 {BFD_RELOC_ARM_GOTOFF, R_ARM_GOTOFF32},
1320 {BFD_RELOC_ARM_GOTPC, R_ARM_GOTPC},
1321 {BFD_RELOC_ARM_GOT32, R_ARM_GOT32},
1322 {BFD_RELOC_ARM_PLT32, R_ARM_PLT32},
1323 {BFD_RELOC_ARM_TARGET1, R_ARM_TARGET1},
1324 {BFD_RELOC_ARM_ROSEGREL32, R_ARM_ROSEGREL32},
1325 {BFD_RELOC_ARM_SBREL32, R_ARM_SBREL32},
1326 {BFD_RELOC_ARM_PREL31, R_ARM_PREL31},
1327 {BFD_RELOC_ARM_TARGET2, R_ARM_TARGET2},
1328 {BFD_RELOC_ARM_PLT32, R_ARM_PLT32},
1329 {BFD_RELOC_ARM_TLS_GD32, R_ARM_TLS_GD32},
1330 {BFD_RELOC_ARM_TLS_LDO32, R_ARM_TLS_LDO32},
1331 {BFD_RELOC_ARM_TLS_LDM32, R_ARM_TLS_LDM32},
1332 {BFD_RELOC_ARM_TLS_DTPMOD32, R_ARM_TLS_DTPMOD32},
1333 {BFD_RELOC_ARM_TLS_DTPOFF32, R_ARM_TLS_DTPOFF32},
1334 {BFD_RELOC_ARM_TLS_TPOFF32, R_ARM_TLS_TPOFF32},
1335 {BFD_RELOC_ARM_TLS_IE32, R_ARM_TLS_IE32},
1336 {BFD_RELOC_ARM_TLS_LE32, R_ARM_TLS_LE32},
1337 {BFD_RELOC_VTABLE_INHERIT, R_ARM_GNU_VTINHERIT},
1338 {BFD_RELOC_VTABLE_ENTRY, R_ARM_GNU_VTENTRY},
1341 static reloc_howto_type *
1342 elf32_arm_reloc_type_lookup (bfd *abfd ATTRIBUTE_UNUSED,
1343 bfd_reloc_code_real_type code)
1345 unsigned int i;
1346 for (i = 0; i < NUM_ELEM (elf32_arm_reloc_map); i ++)
1347 if (elf32_arm_reloc_map[i].bfd_reloc_val == code)
1348 return elf32_arm_howto_from_type (elf32_arm_reloc_map[i].elf_reloc_val);
1350 return NULL;
1353 /* Support for core dump NOTE sections */
1354 static bfd_boolean
1355 elf32_arm_nabi_grok_prstatus (bfd *abfd, Elf_Internal_Note *note)
1357 int offset;
1358 size_t size;
1360 switch (note->descsz)
1362 default:
1363 return FALSE;
1365 case 148: /* Linux/ARM 32-bit*/
1366 /* pr_cursig */
1367 elf_tdata (abfd)->core_signal = bfd_get_16 (abfd, note->descdata + 12);
1369 /* pr_pid */
1370 elf_tdata (abfd)->core_pid = bfd_get_32 (abfd, note->descdata + 24);
1372 /* pr_reg */
1373 offset = 72;
1374 size = 72;
1376 break;
1379 /* Make a ".reg/999" section. */
1380 return _bfd_elfcore_make_pseudosection (abfd, ".reg",
1381 size, note->descpos + offset);
1384 static bfd_boolean
1385 elf32_arm_nabi_grok_psinfo (bfd *abfd, Elf_Internal_Note *note)
1387 switch (note->descsz)
1389 default:
1390 return FALSE;
1392 case 124: /* Linux/ARM elf_prpsinfo */
1393 elf_tdata (abfd)->core_program
1394 = _bfd_elfcore_strndup (abfd, note->descdata + 28, 16);
1395 elf_tdata (abfd)->core_command
1396 = _bfd_elfcore_strndup (abfd, note->descdata + 44, 80);
1399 /* Note that for some reason, a spurious space is tacked
1400 onto the end of the args in some (at least one anyway)
1401 implementations, so strip it off if it exists. */
1404 char *command = elf_tdata (abfd)->core_command;
1405 int n = strlen (command);
1407 if (0 < n && command[n - 1] == ' ')
1408 command[n - 1] = '\0';
1411 return TRUE;
1414 #define TARGET_LITTLE_SYM bfd_elf32_littlearm_vec
1415 #define TARGET_LITTLE_NAME "elf32-littlearm"
1416 #define TARGET_BIG_SYM bfd_elf32_bigarm_vec
1417 #define TARGET_BIG_NAME "elf32-bigarm"
1419 #define elf_backend_grok_prstatus elf32_arm_nabi_grok_prstatus
1420 #define elf_backend_grok_psinfo elf32_arm_nabi_grok_psinfo
1422 typedef unsigned long int insn32;
1423 typedef unsigned short int insn16;
1425 /* In lieu of proper flags, assume all EABIv4 objects are interworkable. */
1426 #define INTERWORK_FLAG(abfd) \
1427 (EF_ARM_EABI_VERSION (elf_elfheader (abfd)->e_flags) == EF_ARM_EABI_VER4 \
1428 || (elf_elfheader (abfd)->e_flags & EF_ARM_INTERWORK))
1430 /* The linker script knows the section names for placement.
1431 The entry_names are used to do simple name mangling on the stubs.
1432 Given a function name, and its type, the stub can be found. The
1433 name can be changed. The only requirement is the %s be present. */
1434 #define THUMB2ARM_GLUE_SECTION_NAME ".glue_7t"
1435 #define THUMB2ARM_GLUE_ENTRY_NAME "__%s_from_thumb"
1437 #define ARM2THUMB_GLUE_SECTION_NAME ".glue_7"
1438 #define ARM2THUMB_GLUE_ENTRY_NAME "__%s_from_arm"
1440 /* The name of the dynamic interpreter. This is put in the .interp
1441 section. */
1442 #define ELF_DYNAMIC_INTERPRETER "/usr/lib/ld.so.1"
1444 #ifdef FOUR_WORD_PLT
1446 /* The first entry in a procedure linkage table looks like
1447 this. It is set up so that any shared library function that is
1448 called before the relocation has been set up calls the dynamic
1449 linker first. */
1450 static const bfd_vma elf32_arm_plt0_entry [] =
1452 0xe52de004, /* str lr, [sp, #-4]! */
1453 0xe59fe010, /* ldr lr, [pc, #16] */
1454 0xe08fe00e, /* add lr, pc, lr */
1455 0xe5bef008, /* ldr pc, [lr, #8]! */
1458 /* Subsequent entries in a procedure linkage table look like
1459 this. */
1460 static const bfd_vma elf32_arm_plt_entry [] =
1462 0xe28fc600, /* add ip, pc, #NN */
1463 0xe28cca00, /* add ip, ip, #NN */
1464 0xe5bcf000, /* ldr pc, [ip, #NN]! */
1465 0x00000000, /* unused */
1468 #else
1470 /* The first entry in a procedure linkage table looks like
1471 this. It is set up so that any shared library function that is
1472 called before the relocation has been set up calls the dynamic
1473 linker first. */
1474 static const bfd_vma elf32_arm_plt0_entry [] =
1476 0xe52de004, /* str lr, [sp, #-4]! */
1477 0xe59fe004, /* ldr lr, [pc, #4] */
1478 0xe08fe00e, /* add lr, pc, lr */
1479 0xe5bef008, /* ldr pc, [lr, #8]! */
1480 0x00000000, /* &GOT[0] - . */
1483 /* Subsequent entries in a procedure linkage table look like
1484 this. */
1485 static const bfd_vma elf32_arm_plt_entry [] =
1487 0xe28fc600, /* add ip, pc, #0xNN00000 */
1488 0xe28cca00, /* add ip, ip, #0xNN000 */
1489 0xe5bcf000, /* ldr pc, [ip, #0xNNN]! */
1492 #endif
1494 /* An initial stub used if the PLT entry is referenced from Thumb code. */
1495 #define PLT_THUMB_STUB_SIZE 4
1496 static const bfd_vma elf32_arm_plt_thumb_stub [] =
1498 0x4778, /* bx pc */
1499 0x46c0 /* nop */
1502 /* The entries in a PLT when using a DLL-based target with multiple
1503 address spaces. */
1504 static const bfd_vma elf32_arm_symbian_plt_entry [] =
1506 0xe51ff004, /* ldr pc, [pc, #-4] */
1507 0x00000000, /* dcd R_ARM_GLOB_DAT(X) */
1510 /* Used to build a map of a section. This is required for mixed-endian
1511 code/data. */
1513 typedef struct elf32_elf_section_map
1515 bfd_vma vma;
1516 char type;
1518 elf32_arm_section_map;
1520 typedef struct _arm_elf_section_data
1522 struct bfd_elf_section_data elf;
1523 unsigned int mapcount;
1524 elf32_arm_section_map *map;
1526 _arm_elf_section_data;
1528 #define elf32_arm_section_data(sec) \
1529 ((_arm_elf_section_data *) elf_section_data (sec))
1531 /* The size of the thread control block. */
1532 #define TCB_SIZE 8
1534 #define NUM_KNOWN_ATTRIBUTES 32
1536 typedef struct aeabi_attribute
1538 int type;
1539 unsigned int i;
1540 char *s;
1541 } aeabi_attribute;
1543 typedef struct aeabi_attribute_list
1545 struct aeabi_attribute_list *next;
1546 int tag;
1547 aeabi_attribute attr;
1548 } aeabi_attribute_list;
1550 struct elf32_arm_obj_tdata
1552 struct elf_obj_tdata root;
1554 /* tls_type for each local got entry. */
1555 char *local_got_tls_type;
1557 aeabi_attribute known_eabi_attributes[NUM_KNOWN_ATTRIBUTES];
1558 aeabi_attribute_list *other_eabi_attributes;
1561 #define elf32_arm_tdata(abfd) \
1562 ((struct elf32_arm_obj_tdata *) (abfd)->tdata.any)
1564 #define elf32_arm_local_got_tls_type(abfd) \
1565 (elf32_arm_tdata (abfd)->local_got_tls_type)
1567 static bfd_boolean
1568 elf32_arm_mkobject (bfd *abfd)
1570 bfd_size_type amt = sizeof (struct elf32_arm_obj_tdata);
1571 abfd->tdata.any = bfd_zalloc (abfd, amt);
1572 if (abfd->tdata.any == NULL)
1573 return FALSE;
1574 return TRUE;
1577 /* The ARM linker needs to keep track of the number of relocs that it
1578 decides to copy in check_relocs for each symbol. This is so that
1579 it can discard PC relative relocs if it doesn't need them when
1580 linking with -Bsymbolic. We store the information in a field
1581 extending the regular ELF linker hash table. */
1583 /* This structure keeps track of the number of relocs we have copied
1584 for a given symbol. */
1585 struct elf32_arm_relocs_copied
1587 /* Next section. */
1588 struct elf32_arm_relocs_copied * next;
1589 /* A section in dynobj. */
1590 asection * section;
1591 /* Number of relocs copied in this section. */
1592 bfd_size_type count;
1593 /* Number of PC-relative relocs copied in this section. */
1594 bfd_size_type pc_count;
1597 #define elf32_arm_hash_entry(ent) ((struct elf32_arm_link_hash_entry *)(ent))
1599 /* Arm ELF linker hash entry. */
1600 struct elf32_arm_link_hash_entry
1602 struct elf_link_hash_entry root;
1604 /* Number of PC relative relocs copied for this symbol. */
1605 struct elf32_arm_relocs_copied * relocs_copied;
1607 /* We reference count Thumb references to a PLT entry separately,
1608 so that we can emit the Thumb trampoline only if needed. */
1609 bfd_signed_vma plt_thumb_refcount;
1611 /* Since PLT entries have variable size if the Thumb prologue is
1612 used, we need to record the index into .got.plt instead of
1613 recomputing it from the PLT offset. */
1614 bfd_signed_vma plt_got_offset;
1616 #define GOT_UNKNOWN 0
1617 #define GOT_NORMAL 1
1618 #define GOT_TLS_GD 2
1619 #define GOT_TLS_IE 4
1620 unsigned char tls_type;
1623 /* Traverse an arm ELF linker hash table. */
1624 #define elf32_arm_link_hash_traverse(table, func, info) \
1625 (elf_link_hash_traverse \
1626 (&(table)->root, \
1627 (bfd_boolean (*) (struct elf_link_hash_entry *, void *)) (func), \
1628 (info)))
1630 /* Get the ARM elf linker hash table from a link_info structure. */
1631 #define elf32_arm_hash_table(info) \
1632 ((struct elf32_arm_link_hash_table *) ((info)->hash))
1634 /* ARM ELF linker hash table. */
1635 struct elf32_arm_link_hash_table
1637 /* The main hash table. */
1638 struct elf_link_hash_table root;
1640 /* The size in bytes of the section containing the Thumb-to-ARM glue. */
1641 bfd_size_type thumb_glue_size;
1643 /* The size in bytes of the section containing the ARM-to-Thumb glue. */
1644 bfd_size_type arm_glue_size;
1646 /* An arbitrary input BFD chosen to hold the glue sections. */
1647 bfd * bfd_of_glue_owner;
1649 /* Nonzero to output a BE8 image. */
1650 int byteswap_code;
1652 /* Zero if R_ARM_TARGET1 means R_ARM_ABS32.
1653 Nonzero if R_ARM_TARGET1 means R_ARM_ABS32. */
1654 int target1_is_rel;
1656 /* The relocation to use for R_ARM_TARGET2 relocations. */
1657 int target2_reloc;
1659 /* Nonzero to fix BX instructions for ARMv4 targets. */
1660 int fix_v4bx;
1662 /* Nonzero if the ARM/Thumb BLX instructions are available for use. */
1663 int use_blx;
1665 /* The number of bytes in the initial entry in the PLT. */
1666 bfd_size_type plt_header_size;
1668 /* The number of bytes in the subsequent PLT etries. */
1669 bfd_size_type plt_entry_size;
1671 /* True if the target system is Symbian OS. */
1672 int symbian_p;
1674 /* True if the target uses REL relocations. */
1675 int use_rel;
1677 /* Short-cuts to get to dynamic linker sections. */
1678 asection *sgot;
1679 asection *sgotplt;
1680 asection *srelgot;
1681 asection *splt;
1682 asection *srelplt;
1683 asection *sdynbss;
1684 asection *srelbss;
1686 /* Data for R_ARM_TLS_LDM32 relocations. */
1687 union {
1688 bfd_signed_vma refcount;
1689 bfd_vma offset;
1690 } tls_ldm_got;
1692 /* Small local sym to section mapping cache. */
1693 struct sym_sec_cache sym_sec;
1695 /* For convenience in allocate_dynrelocs. */
1696 bfd * obfd;
1699 /* Create an entry in an ARM ELF linker hash table. */
1701 static struct bfd_hash_entry *
1702 elf32_arm_link_hash_newfunc (struct bfd_hash_entry * entry,
1703 struct bfd_hash_table * table,
1704 const char * string)
1706 struct elf32_arm_link_hash_entry * ret =
1707 (struct elf32_arm_link_hash_entry *) entry;
1709 /* Allocate the structure if it has not already been allocated by a
1710 subclass. */
1711 if (ret == (struct elf32_arm_link_hash_entry *) NULL)
1712 ret = bfd_hash_allocate (table, sizeof (struct elf32_arm_link_hash_entry));
1713 if (ret == NULL)
1714 return (struct bfd_hash_entry *) ret;
1716 /* Call the allocation method of the superclass. */
1717 ret = ((struct elf32_arm_link_hash_entry *)
1718 _bfd_elf_link_hash_newfunc ((struct bfd_hash_entry *) ret,
1719 table, string));
1720 if (ret != NULL)
1722 ret->relocs_copied = NULL;
1723 ret->tls_type = GOT_UNKNOWN;
1724 ret->plt_thumb_refcount = 0;
1725 ret->plt_got_offset = -1;
1728 return (struct bfd_hash_entry *) ret;
1731 /* Create .got, .gotplt, and .rel.got sections in DYNOBJ, and set up
1732 shortcuts to them in our hash table. */
1734 static bfd_boolean
1735 create_got_section (bfd *dynobj, struct bfd_link_info *info)
1737 struct elf32_arm_link_hash_table *htab;
1739 htab = elf32_arm_hash_table (info);
1740 /* BPABI objects never have a GOT, or associated sections. */
1741 if (htab->symbian_p)
1742 return TRUE;
1744 if (! _bfd_elf_create_got_section (dynobj, info))
1745 return FALSE;
1747 htab->sgot = bfd_get_section_by_name (dynobj, ".got");
1748 htab->sgotplt = bfd_get_section_by_name (dynobj, ".got.plt");
1749 if (!htab->sgot || !htab->sgotplt)
1750 abort ();
1752 htab->srelgot = bfd_make_section_with_flags (dynobj, ".rel.got",
1753 (SEC_ALLOC | SEC_LOAD
1754 | SEC_HAS_CONTENTS
1755 | SEC_IN_MEMORY
1756 | SEC_LINKER_CREATED
1757 | SEC_READONLY));
1758 if (htab->srelgot == NULL
1759 || ! bfd_set_section_alignment (dynobj, htab->srelgot, 2))
1760 return FALSE;
1761 return TRUE;
1764 /* Create .plt, .rel.plt, .got, .got.plt, .rel.got, .dynbss, and
1765 .rel.bss sections in DYNOBJ, and set up shortcuts to them in our
1766 hash table. */
1768 static bfd_boolean
1769 elf32_arm_create_dynamic_sections (bfd *dynobj, struct bfd_link_info *info)
1771 struct elf32_arm_link_hash_table *htab;
1773 htab = elf32_arm_hash_table (info);
1774 if (!htab->sgot && !create_got_section (dynobj, info))
1775 return FALSE;
1777 if (!_bfd_elf_create_dynamic_sections (dynobj, info))
1778 return FALSE;
1780 htab->splt = bfd_get_section_by_name (dynobj, ".plt");
1781 htab->srelplt = bfd_get_section_by_name (dynobj, ".rel.plt");
1782 htab->sdynbss = bfd_get_section_by_name (dynobj, ".dynbss");
1783 if (!info->shared)
1784 htab->srelbss = bfd_get_section_by_name (dynobj, ".rel.bss");
1786 if (!htab->splt
1787 || !htab->srelplt
1788 || !htab->sdynbss
1789 || (!info->shared && !htab->srelbss))
1790 abort ();
1792 return TRUE;
1795 /* Copy the extra info we tack onto an elf_link_hash_entry. */
1797 static void
1798 elf32_arm_copy_indirect_symbol (struct bfd_link_info *info,
1799 struct elf_link_hash_entry *dir,
1800 struct elf_link_hash_entry *ind)
1802 struct elf32_arm_link_hash_entry *edir, *eind;
1804 edir = (struct elf32_arm_link_hash_entry *) dir;
1805 eind = (struct elf32_arm_link_hash_entry *) ind;
1807 if (eind->relocs_copied != NULL)
1809 if (edir->relocs_copied != NULL)
1811 struct elf32_arm_relocs_copied **pp;
1812 struct elf32_arm_relocs_copied *p;
1814 /* Add reloc counts against the indirect sym to the direct sym
1815 list. Merge any entries against the same section. */
1816 for (pp = &eind->relocs_copied; (p = *pp) != NULL; )
1818 struct elf32_arm_relocs_copied *q;
1820 for (q = edir->relocs_copied; q != NULL; q = q->next)
1821 if (q->section == p->section)
1823 q->pc_count += p->pc_count;
1824 q->count += p->count;
1825 *pp = p->next;
1826 break;
1828 if (q == NULL)
1829 pp = &p->next;
1831 *pp = edir->relocs_copied;
1834 edir->relocs_copied = eind->relocs_copied;
1835 eind->relocs_copied = NULL;
1838 /* Copy over PLT info. */
1839 edir->plt_thumb_refcount += eind->plt_thumb_refcount;
1840 eind->plt_thumb_refcount = 0;
1842 if (ind->root.type == bfd_link_hash_indirect
1843 && dir->got.refcount <= 0)
1845 edir->tls_type = eind->tls_type;
1846 eind->tls_type = GOT_UNKNOWN;
1849 _bfd_elf_link_hash_copy_indirect (info, dir, ind);
1852 /* Create an ARM elf linker hash table. */
1854 static struct bfd_link_hash_table *
1855 elf32_arm_link_hash_table_create (bfd *abfd)
1857 struct elf32_arm_link_hash_table *ret;
1858 bfd_size_type amt = sizeof (struct elf32_arm_link_hash_table);
1860 ret = bfd_malloc (amt);
1861 if (ret == NULL)
1862 return NULL;
1864 if (!_bfd_elf_link_hash_table_init (& ret->root, abfd,
1865 elf32_arm_link_hash_newfunc))
1867 free (ret);
1868 return NULL;
1871 ret->sgot = NULL;
1872 ret->sgotplt = NULL;
1873 ret->srelgot = NULL;
1874 ret->splt = NULL;
1875 ret->srelplt = NULL;
1876 ret->sdynbss = NULL;
1877 ret->srelbss = NULL;
1878 ret->thumb_glue_size = 0;
1879 ret->arm_glue_size = 0;
1880 ret->bfd_of_glue_owner = NULL;
1881 ret->byteswap_code = 0;
1882 ret->target1_is_rel = 0;
1883 ret->target2_reloc = R_ARM_NONE;
1884 #ifdef FOUR_WORD_PLT
1885 ret->plt_header_size = 16;
1886 ret->plt_entry_size = 16;
1887 #else
1888 ret->plt_header_size = 20;
1889 ret->plt_entry_size = 12;
1890 #endif
1891 ret->fix_v4bx = 0;
1892 ret->use_blx = 0;
1893 ret->symbian_p = 0;
1894 ret->use_rel = 1;
1895 ret->sym_sec.abfd = NULL;
1896 ret->obfd = abfd;
1897 ret->tls_ldm_got.refcount = 0;
1899 return &ret->root.root;
1902 /* Locate the Thumb encoded calling stub for NAME. */
1904 static struct elf_link_hash_entry *
1905 find_thumb_glue (struct bfd_link_info *link_info,
1906 const char *name,
1907 bfd *input_bfd)
1909 char *tmp_name;
1910 struct elf_link_hash_entry *hash;
1911 struct elf32_arm_link_hash_table *hash_table;
1913 /* We need a pointer to the armelf specific hash table. */
1914 hash_table = elf32_arm_hash_table (link_info);
1916 tmp_name = bfd_malloc ((bfd_size_type) strlen (name)
1917 + strlen (THUMB2ARM_GLUE_ENTRY_NAME) + 1);
1919 BFD_ASSERT (tmp_name);
1921 sprintf (tmp_name, THUMB2ARM_GLUE_ENTRY_NAME, name);
1923 hash = elf_link_hash_lookup
1924 (&(hash_table)->root, tmp_name, FALSE, FALSE, TRUE);
1926 if (hash == NULL)
1927 /* xgettext:c-format */
1928 (*_bfd_error_handler) (_("%B: unable to find THUMB glue '%s' for `%s'"),
1929 input_bfd, tmp_name, name);
1931 free (tmp_name);
1933 return hash;
1936 /* Locate the ARM encoded calling stub for NAME. */
1938 static struct elf_link_hash_entry *
1939 find_arm_glue (struct bfd_link_info *link_info,
1940 const char *name,
1941 bfd *input_bfd)
1943 char *tmp_name;
1944 struct elf_link_hash_entry *myh;
1945 struct elf32_arm_link_hash_table *hash_table;
1947 /* We need a pointer to the elfarm specific hash table. */
1948 hash_table = elf32_arm_hash_table (link_info);
1950 tmp_name = bfd_malloc ((bfd_size_type) strlen (name)
1951 + strlen (ARM2THUMB_GLUE_ENTRY_NAME) + 1);
1953 BFD_ASSERT (tmp_name);
1955 sprintf (tmp_name, ARM2THUMB_GLUE_ENTRY_NAME, name);
1957 myh = elf_link_hash_lookup
1958 (&(hash_table)->root, tmp_name, FALSE, FALSE, TRUE);
1960 if (myh == NULL)
1961 /* xgettext:c-format */
1962 (*_bfd_error_handler) (_("%B: unable to find ARM glue '%s' for `%s'"),
1963 input_bfd, tmp_name, name);
1965 free (tmp_name);
1967 return myh;
1970 /* ARM->Thumb glue (static images):
1972 .arm
1973 __func_from_arm:
1974 ldr r12, __func_addr
1975 bx r12
1976 __func_addr:
1977 .word func @ behave as if you saw a ARM_32 reloc.
1979 (relocatable images)
1980 .arm
1981 __func_from_arm:
1982 ldr r12, __func_offset
1983 add r12, r12, pc
1984 bx r12
1985 __func_offset:
1986 .word func - .
1989 #define ARM2THUMB_STATIC_GLUE_SIZE 12
1990 static const insn32 a2t1_ldr_insn = 0xe59fc000;
1991 static const insn32 a2t2_bx_r12_insn = 0xe12fff1c;
1992 static const insn32 a2t3_func_addr_insn = 0x00000001;
1994 #define ARM2THUMB_PIC_GLUE_SIZE 16
1995 static const insn32 a2t1p_ldr_insn = 0xe59fc004;
1996 static const insn32 a2t2p_add_pc_insn = 0xe08cc00f;
1997 static const insn32 a2t3p_bx_r12_insn = 0xe12fff1c;
1999 /* Thumb->ARM: Thumb->(non-interworking aware) ARM
2001 .thumb .thumb
2002 .align 2 .align 2
2003 __func_from_thumb: __func_from_thumb:
2004 bx pc push {r6, lr}
2005 nop ldr r6, __func_addr
2006 .arm mov lr, pc
2007 __func_change_to_arm: bx r6
2008 b func .arm
2009 __func_back_to_thumb:
2010 ldmia r13! {r6, lr}
2011 bx lr
2012 __func_addr:
2013 .word func */
2015 #define THUMB2ARM_GLUE_SIZE 8
2016 static const insn16 t2a1_bx_pc_insn = 0x4778;
2017 static const insn16 t2a2_noop_insn = 0x46c0;
2018 static const insn32 t2a3_b_insn = 0xea000000;
2020 #ifndef ELFARM_NABI_C_INCLUDED
2021 bfd_boolean
2022 bfd_elf32_arm_allocate_interworking_sections (struct bfd_link_info * info)
2024 asection * s;
2025 bfd_byte * foo;
2026 struct elf32_arm_link_hash_table * globals;
2028 globals = elf32_arm_hash_table (info);
2030 BFD_ASSERT (globals != NULL);
2032 if (globals->arm_glue_size != 0)
2034 BFD_ASSERT (globals->bfd_of_glue_owner != NULL);
2036 s = bfd_get_section_by_name (globals->bfd_of_glue_owner,
2037 ARM2THUMB_GLUE_SECTION_NAME);
2039 BFD_ASSERT (s != NULL);
2041 foo = bfd_alloc (globals->bfd_of_glue_owner, globals->arm_glue_size);
2043 s->size = globals->arm_glue_size;
2044 s->contents = foo;
2047 if (globals->thumb_glue_size != 0)
2049 BFD_ASSERT (globals->bfd_of_glue_owner != NULL);
2051 s = bfd_get_section_by_name
2052 (globals->bfd_of_glue_owner, THUMB2ARM_GLUE_SECTION_NAME);
2054 BFD_ASSERT (s != NULL);
2056 foo = bfd_alloc (globals->bfd_of_glue_owner, globals->thumb_glue_size);
2058 s->size = globals->thumb_glue_size;
2059 s->contents = foo;
2062 return TRUE;
2065 static void
2066 record_arm_to_thumb_glue (struct bfd_link_info * link_info,
2067 struct elf_link_hash_entry * h)
2069 const char * name = h->root.root.string;
2070 asection * s;
2071 char * tmp_name;
2072 struct elf_link_hash_entry * myh;
2073 struct bfd_link_hash_entry * bh;
2074 struct elf32_arm_link_hash_table * globals;
2075 bfd_vma val;
2077 globals = elf32_arm_hash_table (link_info);
2079 BFD_ASSERT (globals != NULL);
2080 BFD_ASSERT (globals->bfd_of_glue_owner != NULL);
2082 s = bfd_get_section_by_name
2083 (globals->bfd_of_glue_owner, ARM2THUMB_GLUE_SECTION_NAME);
2085 BFD_ASSERT (s != NULL);
2087 tmp_name = bfd_malloc ((bfd_size_type) strlen (name) + strlen (ARM2THUMB_GLUE_ENTRY_NAME) + 1);
2089 BFD_ASSERT (tmp_name);
2091 sprintf (tmp_name, ARM2THUMB_GLUE_ENTRY_NAME, name);
2093 myh = elf_link_hash_lookup
2094 (&(globals)->root, tmp_name, FALSE, FALSE, TRUE);
2096 if (myh != NULL)
2098 /* We've already seen this guy. */
2099 free (tmp_name);
2100 return;
2103 /* The only trick here is using hash_table->arm_glue_size as the value.
2104 Even though the section isn't allocated yet, this is where we will be
2105 putting it. */
2106 bh = NULL;
2107 val = globals->arm_glue_size + 1;
2108 _bfd_generic_link_add_one_symbol (link_info, globals->bfd_of_glue_owner,
2109 tmp_name, BSF_GLOBAL, s, val,
2110 NULL, TRUE, FALSE, &bh);
2112 myh = (struct elf_link_hash_entry *) bh;
2113 myh->type = ELF_ST_INFO (STB_LOCAL, STT_FUNC);
2114 myh->forced_local = 1;
2116 free (tmp_name);
2118 if ((link_info->shared || globals->root.is_relocatable_executable))
2119 globals->arm_glue_size += ARM2THUMB_PIC_GLUE_SIZE;
2120 else
2121 globals->arm_glue_size += ARM2THUMB_STATIC_GLUE_SIZE;
2123 return;
2126 static void
2127 record_thumb_to_arm_glue (struct bfd_link_info *link_info,
2128 struct elf_link_hash_entry *h)
2130 const char *name = h->root.root.string;
2131 asection *s;
2132 char *tmp_name;
2133 struct elf_link_hash_entry *myh;
2134 struct bfd_link_hash_entry *bh;
2135 struct elf32_arm_link_hash_table *hash_table;
2136 bfd_vma val;
2138 hash_table = elf32_arm_hash_table (link_info);
2140 BFD_ASSERT (hash_table != NULL);
2141 BFD_ASSERT (hash_table->bfd_of_glue_owner != NULL);
2143 s = bfd_get_section_by_name
2144 (hash_table->bfd_of_glue_owner, THUMB2ARM_GLUE_SECTION_NAME);
2146 BFD_ASSERT (s != NULL);
2148 tmp_name = bfd_malloc ((bfd_size_type) strlen (name)
2149 + strlen (THUMB2ARM_GLUE_ENTRY_NAME) + 1);
2151 BFD_ASSERT (tmp_name);
2153 sprintf (tmp_name, THUMB2ARM_GLUE_ENTRY_NAME, name);
2155 myh = elf_link_hash_lookup
2156 (&(hash_table)->root, tmp_name, FALSE, FALSE, TRUE);
2158 if (myh != NULL)
2160 /* We've already seen this guy. */
2161 free (tmp_name);
2162 return;
2165 bh = NULL;
2166 val = hash_table->thumb_glue_size + 1;
2167 _bfd_generic_link_add_one_symbol (link_info, hash_table->bfd_of_glue_owner,
2168 tmp_name, BSF_GLOBAL, s, val,
2169 NULL, TRUE, FALSE, &bh);
2171 /* If we mark it 'Thumb', the disassembler will do a better job. */
2172 myh = (struct elf_link_hash_entry *) bh;
2173 myh->type = ELF_ST_INFO (STB_LOCAL, STT_ARM_TFUNC);
2174 myh->forced_local = 1;
2176 free (tmp_name);
2178 #define CHANGE_TO_ARM "__%s_change_to_arm"
2179 #define BACK_FROM_ARM "__%s_back_from_arm"
2181 /* Allocate another symbol to mark where we switch to Arm mode. */
2182 tmp_name = bfd_malloc ((bfd_size_type) strlen (name)
2183 + strlen (CHANGE_TO_ARM) + 1);
2185 BFD_ASSERT (tmp_name);
2187 sprintf (tmp_name, CHANGE_TO_ARM, name);
2189 bh = NULL;
2190 val = hash_table->thumb_glue_size + 4,
2191 _bfd_generic_link_add_one_symbol (link_info, hash_table->bfd_of_glue_owner,
2192 tmp_name, BSF_LOCAL, s, val,
2193 NULL, TRUE, FALSE, &bh);
2195 free (tmp_name);
2197 hash_table->thumb_glue_size += THUMB2ARM_GLUE_SIZE;
2199 return;
2202 /* Add the glue sections to ABFD. This function is called from the
2203 linker scripts in ld/emultempl/{armelf}.em. */
2205 bfd_boolean
2206 bfd_elf32_arm_add_glue_sections_to_bfd (bfd *abfd,
2207 struct bfd_link_info *info)
2209 flagword flags;
2210 asection *sec;
2212 /* If we are only performing a partial
2213 link do not bother adding the glue. */
2214 if (info->relocatable)
2215 return TRUE;
2217 sec = bfd_get_section_by_name (abfd, ARM2THUMB_GLUE_SECTION_NAME);
2219 if (sec == NULL)
2221 /* Note: we do not include the flag SEC_LINKER_CREATED, as this
2222 will prevent elf_link_input_bfd() from processing the contents
2223 of this section. */
2224 flags = SEC_ALLOC | SEC_LOAD | SEC_HAS_CONTENTS | SEC_IN_MEMORY | SEC_CODE | SEC_READONLY;
2226 sec = bfd_make_section_with_flags (abfd,
2227 ARM2THUMB_GLUE_SECTION_NAME,
2228 flags);
2230 if (sec == NULL
2231 || !bfd_set_section_alignment (abfd, sec, 2))
2232 return FALSE;
2234 /* Set the gc mark to prevent the section from being removed by garbage
2235 collection, despite the fact that no relocs refer to this section. */
2236 sec->gc_mark = 1;
2239 sec = bfd_get_section_by_name (abfd, THUMB2ARM_GLUE_SECTION_NAME);
2241 if (sec == NULL)
2243 flags = SEC_ALLOC | SEC_LOAD | SEC_HAS_CONTENTS | SEC_IN_MEMORY
2244 | SEC_CODE | SEC_READONLY;
2246 sec = bfd_make_section_with_flags (abfd,
2247 THUMB2ARM_GLUE_SECTION_NAME,
2248 flags);
2250 if (sec == NULL
2251 || !bfd_set_section_alignment (abfd, sec, 2))
2252 return FALSE;
2254 sec->gc_mark = 1;
2257 return TRUE;
2260 /* Select a BFD to be used to hold the sections used by the glue code.
2261 This function is called from the linker scripts in ld/emultempl/
2262 {armelf/pe}.em */
2264 bfd_boolean
2265 bfd_elf32_arm_get_bfd_for_interworking (bfd *abfd, struct bfd_link_info *info)
2267 struct elf32_arm_link_hash_table *globals;
2269 /* If we are only performing a partial link
2270 do not bother getting a bfd to hold the glue. */
2271 if (info->relocatable)
2272 return TRUE;
2274 /* Make sure we don't attach the glue sections to a dynamic object. */
2275 BFD_ASSERT (!(abfd->flags & DYNAMIC));
2277 globals = elf32_arm_hash_table (info);
2279 BFD_ASSERT (globals != NULL);
2281 if (globals->bfd_of_glue_owner != NULL)
2282 return TRUE;
2284 /* Save the bfd for later use. */
2285 globals->bfd_of_glue_owner = abfd;
2287 return TRUE;
2290 static void check_use_blx(struct elf32_arm_link_hash_table *globals)
2292 if (elf32_arm_get_eabi_attr_int (globals->obfd, Tag_CPU_arch) > 2)
2293 globals->use_blx = 1;
2296 bfd_boolean
2297 bfd_elf32_arm_process_before_allocation (bfd *abfd,
2298 struct bfd_link_info *link_info,
2299 int byteswap_code)
2301 Elf_Internal_Shdr *symtab_hdr;
2302 Elf_Internal_Rela *internal_relocs = NULL;
2303 Elf_Internal_Rela *irel, *irelend;
2304 bfd_byte *contents = NULL;
2306 asection *sec;
2307 struct elf32_arm_link_hash_table *globals;
2309 /* If we are only performing a partial link do not bother
2310 to construct any glue. */
2311 if (link_info->relocatable)
2312 return TRUE;
2314 /* Here we have a bfd that is to be included on the link. We have a hook
2315 to do reloc rummaging, before section sizes are nailed down. */
2316 globals = elf32_arm_hash_table (link_info);
2317 check_use_blx (globals);
2319 BFD_ASSERT (globals != NULL);
2320 BFD_ASSERT (globals->bfd_of_glue_owner != NULL);
2322 if (byteswap_code && !bfd_big_endian (abfd))
2324 _bfd_error_handler (_("%B: BE8 images only valid in big-endian mode."),
2325 abfd);
2326 return FALSE;
2328 globals->byteswap_code = byteswap_code;
2330 /* Rummage around all the relocs and map the glue vectors. */
2331 sec = abfd->sections;
2333 if (sec == NULL)
2334 return TRUE;
2336 for (; sec != NULL; sec = sec->next)
2338 if (sec->reloc_count == 0)
2339 continue;
2341 symtab_hdr = &elf_tdata (abfd)->symtab_hdr;
2343 /* Load the relocs. */
2344 internal_relocs
2345 = _bfd_elf_link_read_relocs (abfd, sec, (void *) NULL,
2346 (Elf_Internal_Rela *) NULL, FALSE);
2348 if (internal_relocs == NULL)
2349 goto error_return;
2351 irelend = internal_relocs + sec->reloc_count;
2352 for (irel = internal_relocs; irel < irelend; irel++)
2354 long r_type;
2355 unsigned long r_index;
2357 struct elf_link_hash_entry *h;
2359 r_type = ELF32_R_TYPE (irel->r_info);
2360 r_index = ELF32_R_SYM (irel->r_info);
2362 /* These are the only relocation types we care about. */
2363 if ( r_type != R_ARM_PC24
2364 && r_type != R_ARM_PLT32
2365 && r_type != R_ARM_CALL
2366 && r_type != R_ARM_JUMP24
2367 && r_type != R_ARM_THM_CALL)
2368 continue;
2370 /* Get the section contents if we haven't done so already. */
2371 if (contents == NULL)
2373 /* Get cached copy if it exists. */
2374 if (elf_section_data (sec)->this_hdr.contents != NULL)
2375 contents = elf_section_data (sec)->this_hdr.contents;
2376 else
2378 /* Go get them off disk. */
2379 if (! bfd_malloc_and_get_section (abfd, sec, &contents))
2380 goto error_return;
2384 /* If the relocation is not against a symbol it cannot concern us. */
2385 h = NULL;
2387 /* We don't care about local symbols. */
2388 if (r_index < symtab_hdr->sh_info)
2389 continue;
2391 /* This is an external symbol. */
2392 r_index -= symtab_hdr->sh_info;
2393 h = (struct elf_link_hash_entry *)
2394 elf_sym_hashes (abfd)[r_index];
2396 /* If the relocation is against a static symbol it must be within
2397 the current section and so cannot be a cross ARM/Thumb relocation. */
2398 if (h == NULL)
2399 continue;
2401 /* If the call will go through a PLT entry then we do not need
2402 glue. */
2403 if (globals->splt != NULL && h->plt.offset != (bfd_vma) -1)
2404 continue;
2406 switch (r_type)
2408 case R_ARM_PC24:
2409 case R_ARM_PLT32:
2410 case R_ARM_CALL:
2411 case R_ARM_JUMP24:
2412 /* This one is a call from arm code. We need to look up
2413 the target of the call. If it is a thumb target, we
2414 insert glue. */
2415 if (ELF_ST_TYPE(h->type) == STT_ARM_TFUNC
2416 && !(r_type == R_ARM_CALL && globals->use_blx))
2417 record_arm_to_thumb_glue (link_info, h);
2418 break;
2420 case R_ARM_THM_CALL:
2421 /* This one is a call from thumb code. We look
2422 up the target of the call. If it is not a thumb
2423 target, we insert glue. */
2424 if (ELF_ST_TYPE (h->type) != STT_ARM_TFUNC && !globals->use_blx)
2425 record_thumb_to_arm_glue (link_info, h);
2426 break;
2428 default:
2429 abort ();
2433 if (contents != NULL
2434 && elf_section_data (sec)->this_hdr.contents != contents)
2435 free (contents);
2436 contents = NULL;
2438 if (internal_relocs != NULL
2439 && elf_section_data (sec)->relocs != internal_relocs)
2440 free (internal_relocs);
2441 internal_relocs = NULL;
2444 return TRUE;
2446 error_return:
2447 if (contents != NULL
2448 && elf_section_data (sec)->this_hdr.contents != contents)
2449 free (contents);
2450 if (internal_relocs != NULL
2451 && elf_section_data (sec)->relocs != internal_relocs)
2452 free (internal_relocs);
2454 return FALSE;
2456 #endif
2459 /* Set target relocation values needed during linking. */
2461 void
2462 bfd_elf32_arm_set_target_relocs (struct bfd_link_info *link_info,
2463 int target1_is_rel,
2464 char * target2_type,
2465 int fix_v4bx,
2466 int use_blx)
2468 struct elf32_arm_link_hash_table *globals;
2470 globals = elf32_arm_hash_table (link_info);
2472 globals->target1_is_rel = target1_is_rel;
2473 if (strcmp (target2_type, "rel") == 0)
2474 globals->target2_reloc = R_ARM_REL32;
2475 else if (strcmp (target2_type, "abs") == 0)
2476 globals->target2_reloc = R_ARM_ABS32;
2477 else if (strcmp (target2_type, "got-rel") == 0)
2478 globals->target2_reloc = R_ARM_GOT_PREL;
2479 else
2481 _bfd_error_handler (_("Invalid TARGET2 relocation type '%s'."),
2482 target2_type);
2484 globals->fix_v4bx = fix_v4bx;
2485 globals->use_blx |= use_blx;
2488 /* The thumb form of a long branch is a bit finicky, because the offset
2489 encoding is split over two fields, each in it's own instruction. They
2490 can occur in any order. So given a thumb form of long branch, and an
2491 offset, insert the offset into the thumb branch and return finished
2492 instruction.
2494 It takes two thumb instructions to encode the target address. Each has
2495 11 bits to invest. The upper 11 bits are stored in one (identified by
2496 H-0.. see below), the lower 11 bits are stored in the other (identified
2497 by H-1).
2499 Combine together and shifted left by 1 (it's a half word address) and
2500 there you have it.
2502 Op: 1111 = F,
2503 H-0, upper address-0 = 000
2504 Op: 1111 = F,
2505 H-1, lower address-0 = 800
2507 They can be ordered either way, but the arm tools I've seen always put
2508 the lower one first. It probably doesn't matter. krk@cygnus.com
2510 XXX: Actually the order does matter. The second instruction (H-1)
2511 moves the computed address into the PC, so it must be the second one
2512 in the sequence. The problem, however is that whilst little endian code
2513 stores the instructions in HI then LOW order, big endian code does the
2514 reverse. nickc@cygnus.com. */
2516 #define LOW_HI_ORDER 0xF800F000
2517 #define HI_LOW_ORDER 0xF000F800
2519 static insn32
2520 insert_thumb_branch (insn32 br_insn, int rel_off)
2522 unsigned int low_bits;
2523 unsigned int high_bits;
2525 BFD_ASSERT ((rel_off & 1) != 1);
2527 rel_off >>= 1; /* Half word aligned address. */
2528 low_bits = rel_off & 0x000007FF; /* The bottom 11 bits. */
2529 high_bits = (rel_off >> 11) & 0x000007FF; /* The top 11 bits. */
2531 if ((br_insn & LOW_HI_ORDER) == LOW_HI_ORDER)
2532 br_insn = LOW_HI_ORDER | (low_bits << 16) | high_bits;
2533 else if ((br_insn & HI_LOW_ORDER) == HI_LOW_ORDER)
2534 br_insn = HI_LOW_ORDER | (high_bits << 16) | low_bits;
2535 else
2536 /* FIXME: abort is probably not the right call. krk@cygnus.com */
2537 abort (); /* Error - not a valid branch instruction form. */
2539 return br_insn;
2542 /* Thumb code calling an ARM function. */
2544 static int
2545 elf32_thumb_to_arm_stub (struct bfd_link_info * info,
2546 const char * name,
2547 bfd * input_bfd,
2548 bfd * output_bfd,
2549 asection * input_section,
2550 bfd_byte * hit_data,
2551 asection * sym_sec,
2552 bfd_vma offset,
2553 bfd_signed_vma addend,
2554 bfd_vma val)
2556 asection * s = 0;
2557 bfd_vma my_offset;
2558 unsigned long int tmp;
2559 long int ret_offset;
2560 struct elf_link_hash_entry * myh;
2561 struct elf32_arm_link_hash_table * globals;
2563 myh = find_thumb_glue (info, name, input_bfd);
2564 if (myh == NULL)
2565 return FALSE;
2567 globals = elf32_arm_hash_table (info);
2569 BFD_ASSERT (globals != NULL);
2570 BFD_ASSERT (globals->bfd_of_glue_owner != NULL);
2572 my_offset = myh->root.u.def.value;
2574 s = bfd_get_section_by_name (globals->bfd_of_glue_owner,
2575 THUMB2ARM_GLUE_SECTION_NAME);
2577 BFD_ASSERT (s != NULL);
2578 BFD_ASSERT (s->contents != NULL);
2579 BFD_ASSERT (s->output_section != NULL);
2581 if ((my_offset & 0x01) == 0x01)
2583 if (sym_sec != NULL
2584 && sym_sec->owner != NULL
2585 && !INTERWORK_FLAG (sym_sec->owner))
2587 (*_bfd_error_handler)
2588 (_("%B(%s): warning: interworking not enabled.\n"
2589 " first occurrence: %B: thumb call to arm"),
2590 sym_sec->owner, input_bfd, name);
2592 return FALSE;
2595 --my_offset;
2596 myh->root.u.def.value = my_offset;
2598 bfd_put_16 (output_bfd, (bfd_vma) t2a1_bx_pc_insn,
2599 s->contents + my_offset);
2601 bfd_put_16 (output_bfd, (bfd_vma) t2a2_noop_insn,
2602 s->contents + my_offset + 2);
2604 ret_offset =
2605 /* Address of destination of the stub. */
2606 ((bfd_signed_vma) val)
2607 - ((bfd_signed_vma)
2608 /* Offset from the start of the current section
2609 to the start of the stubs. */
2610 (s->output_offset
2611 /* Offset of the start of this stub from the start of the stubs. */
2612 + my_offset
2613 /* Address of the start of the current section. */
2614 + s->output_section->vma)
2615 /* The branch instruction is 4 bytes into the stub. */
2617 /* ARM branches work from the pc of the instruction + 8. */
2618 + 8);
2620 bfd_put_32 (output_bfd,
2621 (bfd_vma) t2a3_b_insn | ((ret_offset >> 2) & 0x00FFFFFF),
2622 s->contents + my_offset + 4);
2625 BFD_ASSERT (my_offset <= globals->thumb_glue_size);
2627 /* Now go back and fix up the original BL insn to point to here. */
2628 ret_offset =
2629 /* Address of where the stub is located. */
2630 (s->output_section->vma + s->output_offset + my_offset)
2631 /* Address of where the BL is located. */
2632 - (input_section->output_section->vma + input_section->output_offset
2633 + offset)
2634 /* Addend in the relocation. */
2635 - addend
2636 /* Biassing for PC-relative addressing. */
2637 - 8;
2639 tmp = bfd_get_32 (input_bfd, hit_data
2640 - input_section->vma);
2642 bfd_put_32 (output_bfd,
2643 (bfd_vma) insert_thumb_branch (tmp, ret_offset),
2644 hit_data - input_section->vma);
2646 return TRUE;
2649 /* Arm code calling a Thumb function. */
2651 static int
2652 elf32_arm_to_thumb_stub (struct bfd_link_info * info,
2653 const char * name,
2654 bfd * input_bfd,
2655 bfd * output_bfd,
2656 asection * input_section,
2657 bfd_byte * hit_data,
2658 asection * sym_sec,
2659 bfd_vma offset,
2660 bfd_signed_vma addend,
2661 bfd_vma val)
2663 unsigned long int tmp;
2664 bfd_vma my_offset;
2665 asection * s;
2666 long int ret_offset;
2667 struct elf_link_hash_entry * myh;
2668 struct elf32_arm_link_hash_table * globals;
2670 myh = find_arm_glue (info, name, input_bfd);
2671 if (myh == NULL)
2672 return FALSE;
2674 globals = elf32_arm_hash_table (info);
2676 BFD_ASSERT (globals != NULL);
2677 BFD_ASSERT (globals->bfd_of_glue_owner != NULL);
2679 my_offset = myh->root.u.def.value;
2680 s = bfd_get_section_by_name (globals->bfd_of_glue_owner,
2681 ARM2THUMB_GLUE_SECTION_NAME);
2682 BFD_ASSERT (s != NULL);
2683 BFD_ASSERT (s->contents != NULL);
2684 BFD_ASSERT (s->output_section != NULL);
2686 if ((my_offset & 0x01) == 0x01)
2688 if (sym_sec != NULL
2689 && sym_sec->owner != NULL
2690 && !INTERWORK_FLAG (sym_sec->owner))
2692 (*_bfd_error_handler)
2693 (_("%B(%s): warning: interworking not enabled.\n"
2694 " first occurrence: %B: arm call to thumb"),
2695 sym_sec->owner, input_bfd, name);
2698 --my_offset;
2699 myh->root.u.def.value = my_offset;
2701 if ((info->shared || globals->root.is_relocatable_executable))
2703 /* For relocatable objects we can't use absolute addresses,
2704 so construct the address from a relative offset. */
2705 /* TODO: If the offset is small it's probably worth
2706 constructing the address with adds. */
2707 bfd_put_32 (output_bfd, (bfd_vma) a2t1p_ldr_insn,
2708 s->contents + my_offset);
2709 bfd_put_32 (output_bfd, (bfd_vma) a2t2p_add_pc_insn,
2710 s->contents + my_offset + 4);
2711 bfd_put_32 (output_bfd, (bfd_vma) a2t3p_bx_r12_insn,
2712 s->contents + my_offset + 8);
2713 /* Adjust the offset by 4 for the position of the add,
2714 and 8 for the pipeline offset. */
2715 ret_offset = (val - (s->output_offset
2716 + s->output_section->vma
2717 + my_offset + 12))
2718 | 1;
2719 bfd_put_32 (output_bfd, ret_offset,
2720 s->contents + my_offset + 12);
2722 else
2724 bfd_put_32 (output_bfd, (bfd_vma) a2t1_ldr_insn,
2725 s->contents + my_offset);
2727 bfd_put_32 (output_bfd, (bfd_vma) a2t2_bx_r12_insn,
2728 s->contents + my_offset + 4);
2730 /* It's a thumb address. Add the low order bit. */
2731 bfd_put_32 (output_bfd, val | a2t3_func_addr_insn,
2732 s->contents + my_offset + 8);
2736 BFD_ASSERT (my_offset <= globals->arm_glue_size);
2738 tmp = bfd_get_32 (input_bfd, hit_data);
2739 tmp = tmp & 0xFF000000;
2741 /* Somehow these are both 4 too far, so subtract 8. */
2742 ret_offset = (s->output_offset
2743 + my_offset
2744 + s->output_section->vma
2745 - (input_section->output_offset
2746 + input_section->output_section->vma
2747 + offset + addend)
2748 - 8);
2750 tmp = tmp | ((ret_offset >> 2) & 0x00FFFFFF);
2752 bfd_put_32 (output_bfd, (bfd_vma) tmp, hit_data - input_section->vma);
2754 return TRUE;
2757 /* Some relocations map to different relocations depending on the
2758 target. Return the real relocation. */
2759 static int
2760 arm_real_reloc_type (struct elf32_arm_link_hash_table * globals,
2761 int r_type)
2763 switch (r_type)
2765 case R_ARM_TARGET1:
2766 if (globals->target1_is_rel)
2767 return R_ARM_REL32;
2768 else
2769 return R_ARM_ABS32;
2771 case R_ARM_TARGET2:
2772 return globals->target2_reloc;
2774 default:
2775 return r_type;
2779 /* Return the base VMA address which should be subtracted from real addresses
2780 when resolving @dtpoff relocation.
2781 This is PT_TLS segment p_vaddr. */
2783 static bfd_vma
2784 dtpoff_base (struct bfd_link_info *info)
2786 /* If tls_sec is NULL, we should have signalled an error already. */
2787 if (elf_hash_table (info)->tls_sec == NULL)
2788 return 0;
2789 return elf_hash_table (info)->tls_sec->vma;
2792 /* Return the relocation value for @tpoff relocation
2793 if STT_TLS virtual address is ADDRESS. */
2795 static bfd_vma
2796 tpoff (struct bfd_link_info *info, bfd_vma address)
2798 struct elf_link_hash_table *htab = elf_hash_table (info);
2799 bfd_vma base;
2801 /* If tls_sec is NULL, we should have signalled an error already. */
2802 if (htab->tls_sec == NULL)
2803 return 0;
2804 base = align_power ((bfd_vma) TCB_SIZE, htab->tls_sec->alignment_power);
2805 return address - htab->tls_sec->vma + base;
2808 /* Perform a relocation as part of a final link. */
2810 static bfd_reloc_status_type
2811 elf32_arm_final_link_relocate (reloc_howto_type * howto,
2812 bfd * input_bfd,
2813 bfd * output_bfd,
2814 asection * input_section,
2815 bfd_byte * contents,
2816 Elf_Internal_Rela * rel,
2817 bfd_vma value,
2818 struct bfd_link_info * info,
2819 asection * sym_sec,
2820 const char * sym_name,
2821 int sym_flags,
2822 struct elf_link_hash_entry * h,
2823 bfd_boolean * unresolved_reloc_p)
2825 unsigned long r_type = howto->type;
2826 unsigned long r_symndx;
2827 bfd_byte * hit_data = contents + rel->r_offset;
2828 bfd * dynobj = NULL;
2829 Elf_Internal_Shdr * symtab_hdr;
2830 struct elf_link_hash_entry ** sym_hashes;
2831 bfd_vma * local_got_offsets;
2832 asection * sgot = NULL;
2833 asection * splt = NULL;
2834 asection * sreloc = NULL;
2835 bfd_vma addend;
2836 bfd_signed_vma signed_addend;
2837 struct elf32_arm_link_hash_table * globals;
2839 globals = elf32_arm_hash_table (info);
2841 /* Some relocation type map to different relocations depending on the
2842 target. We pick the right one here. */
2843 r_type = arm_real_reloc_type (globals, r_type);
2844 if (r_type != howto->type)
2845 howto = elf32_arm_howto_from_type (r_type);
2847 /* If the start address has been set, then set the EF_ARM_HASENTRY
2848 flag. Setting this more than once is redundant, but the cost is
2849 not too high, and it keeps the code simple.
2851 The test is done here, rather than somewhere else, because the
2852 start address is only set just before the final link commences.
2854 Note - if the user deliberately sets a start address of 0, the
2855 flag will not be set. */
2856 if (bfd_get_start_address (output_bfd) != 0)
2857 elf_elfheader (output_bfd)->e_flags |= EF_ARM_HASENTRY;
2859 dynobj = elf_hash_table (info)->dynobj;
2860 if (dynobj)
2862 sgot = bfd_get_section_by_name (dynobj, ".got");
2863 splt = bfd_get_section_by_name (dynobj, ".plt");
2865 symtab_hdr = & elf_tdata (input_bfd)->symtab_hdr;
2866 sym_hashes = elf_sym_hashes (input_bfd);
2867 local_got_offsets = elf_local_got_offsets (input_bfd);
2868 r_symndx = ELF32_R_SYM (rel->r_info);
2870 if (globals->use_rel)
2872 addend = bfd_get_32 (input_bfd, hit_data) & howto->src_mask;
2874 if (addend & ((howto->src_mask + 1) >> 1))
2876 signed_addend = -1;
2877 signed_addend &= ~ howto->src_mask;
2878 signed_addend |= addend;
2880 else
2881 signed_addend = addend;
2883 else
2884 addend = signed_addend = rel->r_addend;
2886 switch (r_type)
2888 case R_ARM_NONE:
2889 /* We don't need to find a value for this symbol. It's just a
2890 marker. */
2891 *unresolved_reloc_p = FALSE;
2892 return bfd_reloc_ok;
2894 case R_ARM_PC24:
2895 case R_ARM_ABS32:
2896 case R_ARM_REL32:
2897 case R_ARM_CALL:
2898 case R_ARM_JUMP24:
2899 case R_ARM_XPC25:
2900 case R_ARM_PREL31:
2901 case R_ARM_PLT32:
2902 /* r_symndx will be zero only for relocs against symbols
2903 from removed linkonce sections, or sections discarded by
2904 a linker script. */
2905 if (r_symndx == 0)
2906 return bfd_reloc_ok;
2908 /* Handle relocations which should use the PLT entry. ABS32/REL32
2909 will use the symbol's value, which may point to a PLT entry, but we
2910 don't need to handle that here. If we created a PLT entry, all
2911 branches in this object should go to it. */
2912 if ((r_type != R_ARM_ABS32 && r_type != R_ARM_REL32)
2913 && h != NULL
2914 && splt != NULL
2915 && h->plt.offset != (bfd_vma) -1)
2917 /* If we've created a .plt section, and assigned a PLT entry to
2918 this function, it should not be known to bind locally. If
2919 it were, we would have cleared the PLT entry. */
2920 BFD_ASSERT (!SYMBOL_CALLS_LOCAL (info, h));
2922 value = (splt->output_section->vma
2923 + splt->output_offset
2924 + h->plt.offset);
2925 *unresolved_reloc_p = FALSE;
2926 return _bfd_final_link_relocate (howto, input_bfd, input_section,
2927 contents, rel->r_offset, value,
2928 (bfd_vma) 0);
2931 /* When generating a shared object or relocatable executable, these
2932 relocations are copied into the output file to be resolved at
2933 run time. */
2934 if ((info->shared || globals->root.is_relocatable_executable)
2935 && (input_section->flags & SEC_ALLOC)
2936 && (r_type != R_ARM_REL32
2937 || !SYMBOL_CALLS_LOCAL (info, h))
2938 && (h == NULL
2939 || ELF_ST_VISIBILITY (h->other) == STV_DEFAULT
2940 || h->root.type != bfd_link_hash_undefweak)
2941 && r_type != R_ARM_PC24
2942 && r_type != R_ARM_CALL
2943 && r_type != R_ARM_JUMP24
2944 && r_type != R_ARM_PREL31
2945 && r_type != R_ARM_PLT32)
2947 Elf_Internal_Rela outrel;
2948 bfd_byte *loc;
2949 bfd_boolean skip, relocate;
2951 *unresolved_reloc_p = FALSE;
2953 if (sreloc == NULL)
2955 const char * name;
2957 name = (bfd_elf_string_from_elf_section
2958 (input_bfd,
2959 elf_elfheader (input_bfd)->e_shstrndx,
2960 elf_section_data (input_section)->rel_hdr.sh_name));
2961 if (name == NULL)
2962 return bfd_reloc_notsupported;
2964 BFD_ASSERT (strncmp (name, ".rel", 4) == 0
2965 && strcmp (bfd_get_section_name (input_bfd,
2966 input_section),
2967 name + 4) == 0);
2969 sreloc = bfd_get_section_by_name (dynobj, name);
2970 BFD_ASSERT (sreloc != NULL);
2973 skip = FALSE;
2974 relocate = FALSE;
2976 outrel.r_offset =
2977 _bfd_elf_section_offset (output_bfd, info, input_section,
2978 rel->r_offset);
2979 if (outrel.r_offset == (bfd_vma) -1)
2980 skip = TRUE;
2981 else if (outrel.r_offset == (bfd_vma) -2)
2982 skip = TRUE, relocate = TRUE;
2983 outrel.r_offset += (input_section->output_section->vma
2984 + input_section->output_offset);
2986 if (skip)
2987 memset (&outrel, 0, sizeof outrel);
2988 else if (h != NULL
2989 && h->dynindx != -1
2990 && (!info->shared
2991 || !info->symbolic
2992 || !h->def_regular))
2993 outrel.r_info = ELF32_R_INFO (h->dynindx, r_type);
2994 else
2996 int symbol;
2998 /* This symbol is local, or marked to become local. */
2999 relocate = TRUE;
3000 if (sym_flags == STT_ARM_TFUNC)
3001 value |= 1;
3002 if (globals->symbian_p)
3004 /* On Symbian OS, the data segment and text segement
3005 can be relocated independently. Therefore, we
3006 must indicate the segment to which this
3007 relocation is relative. The BPABI allows us to
3008 use any symbol in the right segment; we just use
3009 the section symbol as it is convenient. (We
3010 cannot use the symbol given by "h" directly as it
3011 will not appear in the dynamic symbol table.) */
3012 if (sym_sec)
3013 symbol = elf_section_data (sym_sec->output_section)->dynindx;
3014 else
3015 symbol = elf_section_data (input_section->output_section)->dynindx;
3016 BFD_ASSERT (symbol != 0);
3018 else
3019 /* On SVR4-ish systems, the dynamic loader cannot
3020 relocate the text and data segments independently,
3021 so the symbol does not matter. */
3022 symbol = 0;
3023 outrel.r_info = ELF32_R_INFO (symbol, R_ARM_RELATIVE);
3026 loc = sreloc->contents;
3027 loc += sreloc->reloc_count++ * sizeof (Elf32_External_Rel);
3028 bfd_elf32_swap_reloc_out (output_bfd, &outrel, loc);
3030 /* If this reloc is against an external symbol, we do not want to
3031 fiddle with the addend. Otherwise, we need to include the symbol
3032 value so that it becomes an addend for the dynamic reloc. */
3033 if (! relocate)
3034 return bfd_reloc_ok;
3036 return _bfd_final_link_relocate (howto, input_bfd, input_section,
3037 contents, rel->r_offset, value,
3038 (bfd_vma) 0);
3040 else switch (r_type)
3042 case R_ARM_XPC25: /* Arm BLX instruction. */
3043 case R_ARM_CALL:
3044 case R_ARM_JUMP24:
3045 case R_ARM_PC24: /* Arm B/BL instruction */
3046 case R_ARM_PLT32:
3047 if (r_type == R_ARM_XPC25)
3049 /* Check for Arm calling Arm function. */
3050 /* FIXME: Should we translate the instruction into a BL
3051 instruction instead ? */
3052 if (sym_flags != STT_ARM_TFUNC)
3053 (*_bfd_error_handler)
3054 (_("\%B: Warning: Arm BLX instruction targets Arm function '%s'."),
3055 input_bfd,
3056 h ? h->root.root.string : "(local)");
3058 else if (r_type != R_ARM_CALL || !globals->use_blx)
3060 /* Check for Arm calling Thumb function. */
3061 if (sym_flags == STT_ARM_TFUNC)
3063 elf32_arm_to_thumb_stub (info, sym_name, input_bfd,
3064 output_bfd, input_section,
3065 hit_data, sym_sec, rel->r_offset,
3066 signed_addend, value);
3067 return bfd_reloc_ok;
3071 /* The ARM ELF ABI says that this reloc is computed as: S - P + A
3072 where:
3073 S is the address of the symbol in the relocation.
3074 P is address of the instruction being relocated.
3075 A is the addend (extracted from the instruction) in bytes.
3077 S is held in 'value'.
3078 P is the base address of the section containing the
3079 instruction plus the offset of the reloc into that
3080 section, ie:
3081 (input_section->output_section->vma +
3082 input_section->output_offset +
3083 rel->r_offset).
3084 A is the addend, converted into bytes, ie:
3085 (signed_addend * 4)
3087 Note: None of these operations have knowledge of the pipeline
3088 size of the processor, thus it is up to the assembler to
3089 encode this information into the addend. */
3090 value -= (input_section->output_section->vma
3091 + input_section->output_offset);
3092 value -= rel->r_offset;
3093 if (globals->use_rel)
3094 value += (signed_addend << howto->size);
3095 else
3096 /* RELA addends do not have to be adjusted by howto->size. */
3097 value += signed_addend;
3099 signed_addend = value;
3100 signed_addend >>= howto->rightshift;
3102 /* It is not an error for an undefined weak reference to be
3103 out of range. Any program that branches to such a symbol
3104 is going to crash anyway, so there is no point worrying
3105 about getting the destination exactly right. */
3106 if (! h || h->root.type != bfd_link_hash_undefweak)
3108 /* Perform a signed range check. */
3109 if ( signed_addend > ((bfd_signed_vma) (howto->dst_mask >> 1))
3110 || signed_addend < - ((bfd_signed_vma) ((howto->dst_mask + 1) >> 1)))
3111 return bfd_reloc_overflow;
3114 addend = (value & 2);
3116 value = (signed_addend & howto->dst_mask)
3117 | (bfd_get_32 (input_bfd, hit_data) & (~ howto->dst_mask));
3119 /* Set the H bit in the BLX instruction. */
3120 if (sym_flags == STT_ARM_TFUNC)
3122 if (addend)
3123 value |= (1 << 24);
3124 else
3125 value &= ~(bfd_vma)(1 << 24);
3127 if (r_type == R_ARM_CALL)
3129 /* Select the correct instruction (BL or BLX). */
3130 if (sym_flags == STT_ARM_TFUNC)
3131 value |= (1 << 28);
3132 else
3134 value &= ~(bfd_vma)(1 << 28);
3135 value |= (1 << 24);
3138 break;
3140 case R_ARM_ABS32:
3141 value += addend;
3142 if (sym_flags == STT_ARM_TFUNC)
3143 value |= 1;
3144 break;
3146 case R_ARM_REL32:
3147 value -= (input_section->output_section->vma
3148 + input_section->output_offset + rel->r_offset);
3149 value += addend;
3150 break;
3152 case R_ARM_PREL31:
3153 value -= (input_section->output_section->vma
3154 + input_section->output_offset + rel->r_offset);
3155 value += signed_addend;
3156 if (! h || h->root.type != bfd_link_hash_undefweak)
3158 /* Check for overflow */
3159 if ((value ^ (value >> 1)) & (1 << 30))
3160 return bfd_reloc_overflow;
3162 value &= 0x7fffffff;
3163 value |= (bfd_get_32 (input_bfd, hit_data) & 0x80000000);
3164 if (sym_flags == STT_ARM_TFUNC)
3165 value |= 1;
3166 break;
3169 bfd_put_32 (input_bfd, value, hit_data);
3170 return bfd_reloc_ok;
3172 case R_ARM_ABS8:
3173 value += addend;
3174 if ((long) value > 0x7f || (long) value < -0x80)
3175 return bfd_reloc_overflow;
3177 bfd_put_8 (input_bfd, value, hit_data);
3178 return bfd_reloc_ok;
3180 case R_ARM_ABS16:
3181 value += addend;
3183 if ((long) value > 0x7fff || (long) value < -0x8000)
3184 return bfd_reloc_overflow;
3186 bfd_put_16 (input_bfd, value, hit_data);
3187 return bfd_reloc_ok;
3189 case R_ARM_ABS12:
3190 /* Support ldr and str instruction for the arm */
3191 /* Also thumb b (unconditional branch). ??? Really? */
3192 value += addend;
3194 if ((long) value > 0x7ff || (long) value < -0x800)
3195 return bfd_reloc_overflow;
3197 value |= (bfd_get_32 (input_bfd, hit_data) & 0xfffff000);
3198 bfd_put_32 (input_bfd, value, hit_data);
3199 return bfd_reloc_ok;
3201 case R_ARM_THM_ABS5:
3202 /* Support ldr and str instructions for the thumb. */
3203 if (globals->use_rel)
3205 /* Need to refetch addend. */
3206 addend = bfd_get_16 (input_bfd, hit_data) & howto->src_mask;
3207 /* ??? Need to determine shift amount from operand size. */
3208 addend >>= howto->rightshift;
3210 value += addend;
3212 /* ??? Isn't value unsigned? */
3213 if ((long) value > 0x1f || (long) value < -0x10)
3214 return bfd_reloc_overflow;
3216 /* ??? Value needs to be properly shifted into place first. */
3217 value |= bfd_get_16 (input_bfd, hit_data) & 0xf83f;
3218 bfd_put_16 (input_bfd, value, hit_data);
3219 return bfd_reloc_ok;
3221 case R_ARM_THM_XPC22:
3222 case R_ARM_THM_CALL:
3223 /* Thumb BL (branch long instruction). */
3225 bfd_vma relocation;
3226 bfd_boolean overflow = FALSE;
3227 bfd_vma upper_insn = bfd_get_16 (input_bfd, hit_data);
3228 bfd_vma lower_insn = bfd_get_16 (input_bfd, hit_data + 2);
3229 bfd_signed_vma reloc_signed_max = ((1 << (howto->bitsize - 1)) - 1) >> howto->rightshift;
3230 bfd_signed_vma reloc_signed_min = ~ reloc_signed_max;
3231 bfd_vma check;
3232 bfd_signed_vma signed_check;
3234 /* Need to refetch the addend and squish the two 11 bit pieces
3235 together. */
3236 if (globals->use_rel)
3238 bfd_vma upper = upper_insn & 0x7ff;
3239 bfd_vma lower = lower_insn & 0x7ff;
3240 upper = (upper ^ 0x400) - 0x400; /* Sign extend. */
3241 addend = (upper << 12) | (lower << 1);
3242 signed_addend = addend;
3245 if (r_type == R_ARM_THM_XPC22)
3247 /* Check for Thumb to Thumb call. */
3248 /* FIXME: Should we translate the instruction into a BL
3249 instruction instead ? */
3250 if (sym_flags == STT_ARM_TFUNC)
3251 (*_bfd_error_handler)
3252 (_("%B: Warning: Thumb BLX instruction targets thumb function '%s'."),
3253 input_bfd,
3254 h ? h->root.root.string : "(local)");
3256 else
3258 /* If it is not a call to Thumb, assume call to Arm.
3259 If it is a call relative to a section name, then it is not a
3260 function call at all, but rather a long jump. Calls through
3261 the PLT do not require stubs. */
3262 if (sym_flags != STT_ARM_TFUNC && sym_flags != STT_SECTION
3263 && (h == NULL || splt == NULL
3264 || h->plt.offset == (bfd_vma) -1))
3266 if (globals->use_blx)
3268 /* Convert BL to BLX. */
3269 lower_insn = (lower_insn & ~0x1000) | 0x0800;
3271 else if (elf32_thumb_to_arm_stub
3272 (info, sym_name, input_bfd, output_bfd, input_section,
3273 hit_data, sym_sec, rel->r_offset, signed_addend, value))
3274 return bfd_reloc_ok;
3275 else
3276 return bfd_reloc_dangerous;
3278 else if (sym_flags == STT_ARM_TFUNC && globals->use_blx)
3280 /* Make sure this is a BL. */
3281 lower_insn |= 0x1800;
3285 /* Handle calls via the PLT. */
3286 if (h != NULL && splt != NULL && h->plt.offset != (bfd_vma) -1)
3288 value = (splt->output_section->vma
3289 + splt->output_offset
3290 + h->plt.offset);
3291 if (globals->use_blx)
3293 /* If the Thumb BLX instruction is available, convert the
3294 BL to a BLX instruction to call the ARM-mode PLT entry. */
3295 lower_insn = (lower_insn & ~0x1000) | 0x0800;
3297 else
3298 /* Target the Thumb stub before the ARM PLT entry. */
3299 value -= PLT_THUMB_STUB_SIZE;
3300 *unresolved_reloc_p = FALSE;
3303 relocation = value + signed_addend;
3305 relocation -= (input_section->output_section->vma
3306 + input_section->output_offset
3307 + rel->r_offset);
3309 check = relocation >> howto->rightshift;
3311 /* If this is a signed value, the rightshift just dropped
3312 leading 1 bits (assuming twos complement). */
3313 if ((bfd_signed_vma) relocation >= 0)
3314 signed_check = check;
3315 else
3316 signed_check = check | ~((bfd_vma) -1 >> howto->rightshift);
3318 /* Assumes two's complement. */
3319 if (signed_check > reloc_signed_max || signed_check < reloc_signed_min)
3320 overflow = TRUE;
3322 if ((lower_insn & 0x1800) == 0x0800)
3323 /* For a BLX instruction, make sure that the relocation is rounded up
3324 to a word boundary. This follows the semantics of the instruction
3325 which specifies that bit 1 of the target address will come from bit
3326 1 of the base address. */
3327 relocation = (relocation + 2) & ~ 3;
3329 /* Put RELOCATION back into the insn. */
3330 upper_insn = (upper_insn & ~(bfd_vma) 0x7ff) | ((relocation >> 12) & 0x7ff);
3331 lower_insn = (lower_insn & ~(bfd_vma) 0x7ff) | ((relocation >> 1) & 0x7ff);
3333 /* Put the relocated value back in the object file: */
3334 bfd_put_16 (input_bfd, upper_insn, hit_data);
3335 bfd_put_16 (input_bfd, lower_insn, hit_data + 2);
3337 return (overflow ? bfd_reloc_overflow : bfd_reloc_ok);
3339 break;
3341 case R_ARM_THM_JUMP24:
3342 /* Thumb32 unconditional branch instruction. */
3344 bfd_vma relocation;
3345 bfd_boolean overflow = FALSE;
3346 bfd_vma upper_insn = bfd_get_16 (input_bfd, hit_data);
3347 bfd_vma lower_insn = bfd_get_16 (input_bfd, hit_data + 2);
3348 bfd_signed_vma reloc_signed_max = ((1 << (howto->bitsize - 1)) - 1) >> howto->rightshift;
3349 bfd_signed_vma reloc_signed_min = ~ reloc_signed_max;
3350 bfd_vma check;
3351 bfd_signed_vma signed_check;
3353 /* Need to refetch the addend, reconstruct the top three bits, and glue the
3354 two pieces together. */
3355 if (globals->use_rel)
3357 bfd_vma S = (upper_insn & 0x0400) >> 10;
3358 bfd_vma hi = (upper_insn & 0x03ff);
3359 bfd_vma I1 = (lower_insn & 0x2000) >> 13;
3360 bfd_vma I2 = (lower_insn & 0x0800) >> 11;
3361 bfd_vma lo = (lower_insn & 0x07ff);
3363 I1 = !(I1 ^ S);
3364 I2 = !(I2 ^ S);
3365 S = !S;
3367 signed_addend = (S << 24) | (I1 << 23) | (I2 << 22) | (hi << 12) | (lo << 1);
3368 signed_addend -= (1 << 24); /* Sign extend. */
3371 /* ??? Should handle interworking? GCC might someday try to
3372 use this for tail calls. */
3374 relocation = value + signed_addend;
3375 relocation -= (input_section->output_section->vma
3376 + input_section->output_offset
3377 + rel->r_offset);
3379 check = relocation >> howto->rightshift;
3381 /* If this is a signed value, the rightshift just dropped
3382 leading 1 bits (assuming twos complement). */
3383 if ((bfd_signed_vma) relocation >= 0)
3384 signed_check = check;
3385 else
3386 signed_check = check | ~((bfd_vma) -1 >> howto->rightshift);
3388 /* Assumes two's complement. */
3389 if (signed_check > reloc_signed_max || signed_check < reloc_signed_min)
3390 overflow = TRUE;
3392 /* Put RELOCATION back into the insn. */
3394 bfd_vma S = (relocation & 0x01000000) >> 24;
3395 bfd_vma I1 = (relocation & 0x00800000) >> 23;
3396 bfd_vma I2 = (relocation & 0x00400000) >> 22;
3397 bfd_vma hi = (relocation & 0x003ff000) >> 12;
3398 bfd_vma lo = (relocation & 0x00000ffe) >> 1;
3400 I1 = !(I1 ^ S);
3401 I2 = !(I2 ^ S);
3403 upper_insn = (upper_insn & (bfd_vma) 0xf800) | (S << 10) | hi;
3404 lower_insn = (lower_insn & (bfd_vma) 0xd000) | (I1 << 13) | (I2 << 11) | lo;
3407 /* Put the relocated value back in the object file: */
3408 bfd_put_16 (input_bfd, upper_insn, hit_data);
3409 bfd_put_16 (input_bfd, lower_insn, hit_data + 2);
3411 return (overflow ? bfd_reloc_overflow : bfd_reloc_ok);
3414 case R_ARM_THM_JUMP19:
3415 /* Thumb32 conditional branch instruction. */
3417 bfd_vma relocation;
3418 bfd_boolean overflow = FALSE;
3419 bfd_vma upper_insn = bfd_get_16 (input_bfd, hit_data);
3420 bfd_vma lower_insn = bfd_get_16 (input_bfd, hit_data + 2);
3421 bfd_signed_vma reloc_signed_max = ((1 << (howto->bitsize - 1)) - 1) >> howto->rightshift;
3422 bfd_signed_vma reloc_signed_min = ~ reloc_signed_max;
3423 bfd_vma check;
3424 bfd_signed_vma signed_check;
3426 /* Need to refetch the addend, reconstruct the top three bits,
3427 and squish the two 11 bit pieces together. */
3428 if (globals->use_rel)
3430 bfd_vma S = (upper_insn & 0x0400) >> 10;
3431 bfd_vma upper = (upper_insn & 0x001f);
3432 bfd_vma J1 = (lower_insn & 0x2000) >> 13;
3433 bfd_vma J2 = (lower_insn & 0x0800) >> 11;
3434 bfd_vma lower = (lower_insn & 0x07ff);
3436 upper |= J2 << 6;
3437 upper |= J1 << 7;
3438 upper |= ~S << 8;
3439 upper -= 0x0100; /* Sign extend. */
3441 addend = (upper << 12) | (lower << 1);
3442 signed_addend = addend;
3445 /* ??? Should handle interworking? GCC might someday try to
3446 use this for tail calls. */
3448 relocation = value + signed_addend;
3449 relocation -= (input_section->output_section->vma
3450 + input_section->output_offset
3451 + rel->r_offset);
3453 check = relocation >> howto->rightshift;
3455 /* If this is a signed value, the rightshift just dropped
3456 leading 1 bits (assuming twos complement). */
3457 if ((bfd_signed_vma) relocation >= 0)
3458 signed_check = check;
3459 else
3460 signed_check = check | ~((bfd_vma) -1 >> howto->rightshift);
3462 /* Assumes two's complement. */
3463 if (signed_check > reloc_signed_max || signed_check < reloc_signed_min)
3464 overflow = TRUE;
3466 /* Put RELOCATION back into the insn. */
3468 bfd_vma S = (relocation & 0x00100000) >> 20;
3469 bfd_vma J2 = (relocation & 0x00080000) >> 19;
3470 bfd_vma J1 = (relocation & 0x00040000) >> 18;
3471 bfd_vma hi = (relocation & 0x0003f000) >> 12;
3472 bfd_vma lo = (relocation & 0x00000ffe) >> 1;
3474 upper_insn = (upper_insn & 0xfb30) | (S << 10) | hi;
3475 lower_insn = (lower_insn & 0xd000) | (J1 << 13) | (J2 << 11) | lo;
3478 /* Put the relocated value back in the object file: */
3479 bfd_put_16 (input_bfd, upper_insn, hit_data);
3480 bfd_put_16 (input_bfd, lower_insn, hit_data + 2);
3482 return (overflow ? bfd_reloc_overflow : bfd_reloc_ok);
3485 case R_ARM_THM_JUMP11:
3486 case R_ARM_THM_JUMP8:
3487 case R_ARM_THM_JUMP6:
3488 /* Thumb B (branch) instruction). */
3490 bfd_signed_vma relocation;
3491 bfd_signed_vma reloc_signed_max = (1 << (howto->bitsize - 1)) - 1;
3492 bfd_signed_vma reloc_signed_min = ~ reloc_signed_max;
3493 bfd_signed_vma signed_check;
3495 /* CZB cannot jump backward. */
3496 if (r_type == R_ARM_THM_JUMP6)
3497 reloc_signed_min = 0;
3499 if (globals->use_rel)
3501 /* Need to refetch addend. */
3502 addend = bfd_get_16 (input_bfd, hit_data) & howto->src_mask;
3503 if (addend & ((howto->src_mask + 1) >> 1))
3505 signed_addend = -1;
3506 signed_addend &= ~ howto->src_mask;
3507 signed_addend |= addend;
3509 else
3510 signed_addend = addend;
3511 /* The value in the insn has been right shifted. We need to
3512 undo this, so that we can perform the address calculation
3513 in terms of bytes. */
3514 signed_addend <<= howto->rightshift;
3516 relocation = value + signed_addend;
3518 relocation -= (input_section->output_section->vma
3519 + input_section->output_offset
3520 + rel->r_offset);
3522 relocation >>= howto->rightshift;
3523 signed_check = relocation;
3525 if (r_type == R_ARM_THM_JUMP6)
3526 relocation = ((relocation & 0x0020) << 4) | ((relocation & 0x001f) << 3);
3527 else
3528 relocation &= howto->dst_mask;
3529 relocation |= (bfd_get_16 (input_bfd, hit_data) & (~ howto->dst_mask));
3531 bfd_put_16 (input_bfd, relocation, hit_data);
3533 /* Assumes two's complement. */
3534 if (signed_check > reloc_signed_max || signed_check < reloc_signed_min)
3535 return bfd_reloc_overflow;
3537 return bfd_reloc_ok;
3540 case R_ARM_ALU_PCREL7_0:
3541 case R_ARM_ALU_PCREL15_8:
3542 case R_ARM_ALU_PCREL23_15:
3544 bfd_vma insn;
3545 bfd_vma relocation;
3547 insn = bfd_get_32 (input_bfd, hit_data);
3548 if (globals->use_rel)
3550 /* Extract the addend. */
3551 addend = (insn & 0xff) << ((insn & 0xf00) >> 7);
3552 signed_addend = addend;
3554 relocation = value + signed_addend;
3556 relocation -= (input_section->output_section->vma
3557 + input_section->output_offset
3558 + rel->r_offset);
3559 insn = (insn & ~0xfff)
3560 | ((howto->bitpos << 7) & 0xf00)
3561 | ((relocation >> howto->bitpos) & 0xff);
3562 bfd_put_32 (input_bfd, value, hit_data);
3564 return bfd_reloc_ok;
3566 case R_ARM_GNU_VTINHERIT:
3567 case R_ARM_GNU_VTENTRY:
3568 return bfd_reloc_ok;
3570 case R_ARM_GOTOFF32:
3571 /* Relocation is relative to the start of the
3572 global offset table. */
3574 BFD_ASSERT (sgot != NULL);
3575 if (sgot == NULL)
3576 return bfd_reloc_notsupported;
3578 /* If we are addressing a Thumb function, we need to adjust the
3579 address by one, so that attempts to call the function pointer will
3580 correctly interpret it as Thumb code. */
3581 if (sym_flags == STT_ARM_TFUNC)
3582 value += 1;
3584 /* Note that sgot->output_offset is not involved in this
3585 calculation. We always want the start of .got. If we
3586 define _GLOBAL_OFFSET_TABLE in a different way, as is
3587 permitted by the ABI, we might have to change this
3588 calculation. */
3589 value -= sgot->output_section->vma;
3590 return _bfd_final_link_relocate (howto, input_bfd, input_section,
3591 contents, rel->r_offset, value,
3592 (bfd_vma) 0);
3594 case R_ARM_GOTPC:
3595 /* Use global offset table as symbol value. */
3596 BFD_ASSERT (sgot != NULL);
3598 if (sgot == NULL)
3599 return bfd_reloc_notsupported;
3601 *unresolved_reloc_p = FALSE;
3602 value = sgot->output_section->vma;
3603 return _bfd_final_link_relocate (howto, input_bfd, input_section,
3604 contents, rel->r_offset, value,
3605 (bfd_vma) 0);
3607 case R_ARM_GOT32:
3608 case R_ARM_GOT_PREL:
3609 /* Relocation is to the entry for this symbol in the
3610 global offset table. */
3611 if (sgot == NULL)
3612 return bfd_reloc_notsupported;
3614 if (h != NULL)
3616 bfd_vma off;
3617 bfd_boolean dyn;
3619 off = h->got.offset;
3620 BFD_ASSERT (off != (bfd_vma) -1);
3621 dyn = globals->root.dynamic_sections_created;
3623 if (! WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn, info->shared, h)
3624 || (info->shared
3625 && SYMBOL_REFERENCES_LOCAL (info, h))
3626 || (ELF_ST_VISIBILITY (h->other)
3627 && h->root.type == bfd_link_hash_undefweak))
3629 /* This is actually a static link, or it is a -Bsymbolic link
3630 and the symbol is defined locally. We must initialize this
3631 entry in the global offset table. Since the offset must
3632 always be a multiple of 4, we use the least significant bit
3633 to record whether we have initialized it already.
3635 When doing a dynamic link, we create a .rel.got relocation
3636 entry to initialize the value. This is done in the
3637 finish_dynamic_symbol routine. */
3638 if ((off & 1) != 0)
3639 off &= ~1;
3640 else
3642 /* If we are addressing a Thumb function, we need to
3643 adjust the address by one, so that attempts to
3644 call the function pointer will correctly
3645 interpret it as Thumb code. */
3646 if (sym_flags == STT_ARM_TFUNC)
3647 value |= 1;
3649 bfd_put_32 (output_bfd, value, sgot->contents + off);
3650 h->got.offset |= 1;
3653 else
3654 *unresolved_reloc_p = FALSE;
3656 value = sgot->output_offset + off;
3658 else
3660 bfd_vma off;
3662 BFD_ASSERT (local_got_offsets != NULL &&
3663 local_got_offsets[r_symndx] != (bfd_vma) -1);
3665 off = local_got_offsets[r_symndx];
3667 /* The offset must always be a multiple of 4. We use the
3668 least significant bit to record whether we have already
3669 generated the necessary reloc. */
3670 if ((off & 1) != 0)
3671 off &= ~1;
3672 else
3674 /* If we are addressing a Thumb function, we need to
3675 adjust the address by one, so that attempts to
3676 call the function pointer will correctly
3677 interpret it as Thumb code. */
3678 if (sym_flags == STT_ARM_TFUNC)
3679 value |= 1;
3681 bfd_put_32 (output_bfd, value, sgot->contents + off);
3683 if (info->shared)
3685 asection * srelgot;
3686 Elf_Internal_Rela outrel;
3687 bfd_byte *loc;
3689 srelgot = bfd_get_section_by_name (dynobj, ".rel.got");
3690 BFD_ASSERT (srelgot != NULL);
3692 outrel.r_offset = (sgot->output_section->vma
3693 + sgot->output_offset
3694 + off);
3695 outrel.r_info = ELF32_R_INFO (0, R_ARM_RELATIVE);
3696 loc = srelgot->contents;
3697 loc += srelgot->reloc_count++ * sizeof (Elf32_External_Rel);
3698 bfd_elf32_swap_reloc_out (output_bfd, &outrel, loc);
3701 local_got_offsets[r_symndx] |= 1;
3704 value = sgot->output_offset + off;
3706 if (r_type != R_ARM_GOT32)
3707 value += sgot->output_section->vma;
3709 return _bfd_final_link_relocate (howto, input_bfd, input_section,
3710 contents, rel->r_offset, value,
3711 (bfd_vma) 0);
3713 case R_ARM_TLS_LDO32:
3714 value = value - dtpoff_base (info);
3716 return _bfd_final_link_relocate (howto, input_bfd, input_section,
3717 contents, rel->r_offset, value, (bfd_vma) 0);
3719 case R_ARM_TLS_LDM32:
3721 bfd_vma off;
3723 if (globals->sgot == NULL)
3724 abort ();
3726 off = globals->tls_ldm_got.offset;
3728 if ((off & 1) != 0)
3729 off &= ~1;
3730 else
3732 /* If we don't know the module number, create a relocation
3733 for it. */
3734 if (info->shared)
3736 Elf_Internal_Rela outrel;
3737 bfd_byte *loc;
3739 if (globals->srelgot == NULL)
3740 abort ();
3742 outrel.r_offset = (globals->sgot->output_section->vma
3743 + globals->sgot->output_offset + off);
3744 outrel.r_info = ELF32_R_INFO (0, R_ARM_TLS_DTPMOD32);
3746 bfd_put_32 (output_bfd, 0, globals->sgot->contents + off);
3748 loc = globals->srelgot->contents;
3749 loc += globals->srelgot->reloc_count++ * sizeof (Elf32_External_Rel);
3750 bfd_elf32_swap_reloc_out (output_bfd, &outrel, loc);
3752 else
3753 bfd_put_32 (output_bfd, 1, globals->sgot->contents + off);
3755 globals->tls_ldm_got.offset |= 1;
3758 value = globals->sgot->output_section->vma + globals->sgot->output_offset + off
3759 - (input_section->output_section->vma + input_section->output_offset + rel->r_offset);
3761 return _bfd_final_link_relocate (howto, input_bfd, input_section,
3762 contents, rel->r_offset, value,
3763 (bfd_vma) 0);
3766 case R_ARM_TLS_GD32:
3767 case R_ARM_TLS_IE32:
3769 bfd_vma off;
3770 int indx;
3771 char tls_type;
3773 if (globals->sgot == NULL)
3774 abort ();
3776 indx = 0;
3777 if (h != NULL)
3779 bfd_boolean dyn;
3780 dyn = globals->root.dynamic_sections_created;
3781 if (WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn, info->shared, h)
3782 && (!info->shared
3783 || !SYMBOL_REFERENCES_LOCAL (info, h)))
3785 *unresolved_reloc_p = FALSE;
3786 indx = h->dynindx;
3788 off = h->got.offset;
3789 tls_type = ((struct elf32_arm_link_hash_entry *) h)->tls_type;
3791 else
3793 if (local_got_offsets == NULL)
3794 abort ();
3795 off = local_got_offsets[r_symndx];
3796 tls_type = elf32_arm_local_got_tls_type (input_bfd)[r_symndx];
3799 if (tls_type == GOT_UNKNOWN)
3800 abort ();
3802 if ((off & 1) != 0)
3803 off &= ~1;
3804 else
3806 bfd_boolean need_relocs = FALSE;
3807 Elf_Internal_Rela outrel;
3808 bfd_byte *loc = NULL;
3809 int cur_off = off;
3811 /* The GOT entries have not been initialized yet. Do it
3812 now, and emit any relocations. If both an IE GOT and a
3813 GD GOT are necessary, we emit the GD first. */
3815 if ((info->shared || indx != 0)
3816 && (h == NULL
3817 || ELF_ST_VISIBILITY (h->other) == STV_DEFAULT
3818 || h->root.type != bfd_link_hash_undefweak))
3820 need_relocs = TRUE;
3821 if (globals->srelgot == NULL)
3822 abort ();
3823 loc = globals->srelgot->contents;
3824 loc += globals->srelgot->reloc_count * sizeof (Elf32_External_Rel);
3827 if (tls_type & GOT_TLS_GD)
3829 if (need_relocs)
3831 outrel.r_offset = (globals->sgot->output_section->vma
3832 + globals->sgot->output_offset + cur_off);
3833 outrel.r_info = ELF32_R_INFO (indx, R_ARM_TLS_DTPMOD32);
3834 bfd_put_32 (output_bfd, 0, globals->sgot->contents + cur_off);
3836 bfd_elf32_swap_reloc_out (output_bfd, &outrel, loc);
3837 globals->srelgot->reloc_count++;
3838 loc += sizeof (Elf32_External_Rel);
3840 if (indx == 0)
3841 bfd_put_32 (output_bfd, value - dtpoff_base (info),
3842 globals->sgot->contents + cur_off + 4);
3843 else
3845 bfd_put_32 (output_bfd, 0,
3846 globals->sgot->contents + cur_off + 4);
3848 outrel.r_info = ELF32_R_INFO (indx,
3849 R_ARM_TLS_DTPOFF32);
3850 outrel.r_offset += 4;
3851 bfd_elf32_swap_reloc_out (output_bfd, &outrel, loc);
3852 globals->srelgot->reloc_count++;
3853 loc += sizeof (Elf32_External_Rel);
3856 else
3858 /* If we are not emitting relocations for a
3859 general dynamic reference, then we must be in a
3860 static link or an executable link with the
3861 symbol binding locally. Mark it as belonging
3862 to module 1, the executable. */
3863 bfd_put_32 (output_bfd, 1,
3864 globals->sgot->contents + cur_off);
3865 bfd_put_32 (output_bfd, value - dtpoff_base (info),
3866 globals->sgot->contents + cur_off + 4);
3869 cur_off += 8;
3872 if (tls_type & GOT_TLS_IE)
3874 if (need_relocs)
3876 outrel.r_offset = (globals->sgot->output_section->vma
3877 + globals->sgot->output_offset
3878 + cur_off);
3879 outrel.r_info = ELF32_R_INFO (indx, R_ARM_TLS_TPOFF32);
3881 if (indx == 0)
3882 bfd_put_32 (output_bfd, value - dtpoff_base (info),
3883 globals->sgot->contents + cur_off);
3884 else
3885 bfd_put_32 (output_bfd, 0,
3886 globals->sgot->contents + cur_off);
3888 bfd_elf32_swap_reloc_out (output_bfd, &outrel, loc);
3889 globals->srelgot->reloc_count++;
3890 loc += sizeof (Elf32_External_Rel);
3892 else
3893 bfd_put_32 (output_bfd, tpoff (info, value),
3894 globals->sgot->contents + cur_off);
3895 cur_off += 4;
3898 if (h != NULL)
3899 h->got.offset |= 1;
3900 else
3901 local_got_offsets[r_symndx] |= 1;
3904 if ((tls_type & GOT_TLS_GD) && r_type != R_ARM_TLS_GD32)
3905 off += 8;
3906 value = globals->sgot->output_section->vma + globals->sgot->output_offset + off
3907 - (input_section->output_section->vma + input_section->output_offset + rel->r_offset);
3909 return _bfd_final_link_relocate (howto, input_bfd, input_section,
3910 contents, rel->r_offset, value,
3911 (bfd_vma) 0);
3914 case R_ARM_TLS_LE32:
3915 if (info->shared)
3917 (*_bfd_error_handler)
3918 (_("%B(%A+0x%lx): R_ARM_TLS_LE32 relocation not permitted in shared object"),
3919 input_bfd, input_section,
3920 (long) rel->r_offset, howto->name);
3921 return FALSE;
3923 else
3924 value = tpoff (info, value);
3926 return _bfd_final_link_relocate (howto, input_bfd, input_section,
3927 contents, rel->r_offset, value, (bfd_vma) 0);
3929 case R_ARM_V4BX:
3930 if (globals->fix_v4bx)
3932 bfd_vma insn = bfd_get_32 (input_bfd, hit_data);
3934 /* Ensure that we have a BX instruction. */
3935 BFD_ASSERT ((insn & 0x0ffffff0) == 0x012fff10);
3937 /* Preserve Rm (lowest four bits) and the condition code
3938 (highest four bits). Other bits encode MOV PC,Rm. */
3939 insn = (insn & 0xf000000f) | 0x01a0f000;
3941 bfd_put_32 (input_bfd, insn, hit_data);
3943 return bfd_reloc_ok;
3945 default:
3946 return bfd_reloc_notsupported;
3951 static int
3952 uleb128_size (unsigned int i)
3954 int size;
3955 size = 1;
3956 while (i >= 0x80)
3958 i >>= 7;
3959 size++;
3961 return size;
3964 /* Return TRUE if the attribute has the default value (0/""). */
3965 static bfd_boolean
3966 is_default_attr (aeabi_attribute *attr)
3968 if ((attr->type & 1) && attr->i != 0)
3969 return FALSE;
3970 if ((attr->type & 2) && attr->s && *attr->s)
3971 return FALSE;
3973 return TRUE;
3976 /* Return the size of a single attribute. */
3977 static bfd_vma
3978 eabi_attr_size(int tag, aeabi_attribute *attr)
3980 bfd_vma size;
3982 if (is_default_attr (attr))
3983 return 0;
3985 size = uleb128_size (tag);
3986 if (attr->type & 1)
3987 size += uleb128_size (attr->i);
3988 if (attr->type & 2)
3989 size += strlen ((char *)attr->s) + 1;
3990 return size;
3993 /* Returns the size of the eabi object attributess section. */
3994 bfd_vma
3995 elf32_arm_eabi_attr_size (bfd *abfd)
3997 bfd_vma size;
3998 aeabi_attribute *attr;
3999 aeabi_attribute_list *list;
4000 int i;
4002 attr = elf32_arm_tdata (abfd)->known_eabi_attributes;
4003 size = 16; /* 'A' <size> "aeabi" 0x1 <size>. */
4004 for (i = 4; i < NUM_KNOWN_ATTRIBUTES; i++)
4005 size += eabi_attr_size (i, &attr[i]);
4007 for (list = elf32_arm_tdata (abfd)->other_eabi_attributes;
4008 list;
4009 list = list->next)
4010 size += eabi_attr_size (list->tag, &list->attr);
4012 return size;
4015 static bfd_byte *
4016 write_uleb128 (bfd_byte *p, unsigned int val)
4018 bfd_byte c;
4021 c = val & 0x7f;
4022 val >>= 7;
4023 if (val)
4024 c |= 0x80;
4025 *(p++) = c;
4027 while (val);
4028 return p;
4031 /* Write attribute ATTR to butter P, and return a pointer to the following
4032 byte. */
4033 static bfd_byte *
4034 write_eabi_attribute (bfd_byte *p, int tag, aeabi_attribute *attr)
4036 /* Suppress default entries. */
4037 if (is_default_attr(attr))
4038 return p;
4040 p = write_uleb128 (p, tag);
4041 if (attr->type & 1)
4042 p = write_uleb128 (p, attr->i);
4043 if (attr->type & 2)
4045 int len;
4047 len = strlen (attr->s) + 1;
4048 memcpy (p, attr->s, len);
4049 p += len;
4052 return p;
4055 /* Write the contents of the eabi attributes section to p. */
4056 void
4057 elf32_arm_set_eabi_attr_contents (bfd *abfd, bfd_byte *contents, bfd_vma size)
4059 bfd_byte *p;
4060 aeabi_attribute *attr;
4061 aeabi_attribute_list *list;
4062 int i;
4064 p = contents;
4065 *(p++) = 'A';
4066 bfd_put_32 (abfd, size - 1, p);
4067 p += 4;
4068 memcpy (p, "aeabi", 6);
4069 p += 6;
4070 *(p++) = Tag_File;
4071 bfd_put_32 (abfd, size - 11, p);
4072 p += 4;
4074 attr = elf32_arm_tdata (abfd)->known_eabi_attributes;
4075 for (i = 4; i < NUM_KNOWN_ATTRIBUTES; i++)
4076 p = write_eabi_attribute (p, i, &attr[i]);
4078 for (list = elf32_arm_tdata (abfd)->other_eabi_attributes;
4079 list;
4080 list = list->next)
4081 p = write_eabi_attribute (p, list->tag, &list->attr);
4084 /* Override final_link to handle EABI object attribute sections. */
4086 static bfd_boolean
4087 elf32_arm_bfd_final_link (bfd *abfd, struct bfd_link_info *info)
4089 asection *o;
4090 struct bfd_link_order *p;
4091 asection *attr_section = NULL;
4092 bfd_byte *contents;
4093 bfd_vma size = 0;
4095 /* elf32_arm_merge_private_bfd_data will already have merged the
4096 object attributes. Remove the input sections from the link, and set
4097 the contents of the output secton. */
4098 for (o = abfd->sections; o != NULL; o = o->next)
4100 if (strcmp (o->name, ".ARM.attributes") == 0)
4102 for (p = o->map_head.link_order; p != NULL; p = p->next)
4104 asection *input_section;
4106 if (p->type != bfd_indirect_link_order)
4107 continue;
4108 input_section = p->u.indirect.section;
4109 /* Hack: reset the SEC_HAS_CONTENTS flag so that
4110 elf_link_input_bfd ignores this section. */
4111 input_section->flags &= ~SEC_HAS_CONTENTS;
4114 size = elf32_arm_eabi_attr_size (abfd);
4115 bfd_set_section_size (abfd, o, size);
4116 attr_section = o;
4117 /* Skip this section later on. */
4118 o->map_head.link_order = NULL;
4121 /* Invoke the ELF linker to do all the work. */
4122 if (!bfd_elf_final_link (abfd, info))
4123 return FALSE;
4125 if (attr_section)
4127 contents = bfd_malloc(size);
4128 if (contents == NULL)
4129 return FALSE;
4130 elf32_arm_set_eabi_attr_contents (abfd, contents, size);
4131 bfd_set_section_contents (abfd, attr_section, contents, 0, size);
4132 free (contents);
4134 return TRUE;
4138 /* Add INCREMENT to the reloc (of type HOWTO) at ADDRESS. */
4139 static void
4140 arm_add_to_rel (bfd * abfd,
4141 bfd_byte * address,
4142 reloc_howto_type * howto,
4143 bfd_signed_vma increment)
4145 bfd_signed_vma addend;
4147 if (howto->type == R_ARM_THM_CALL)
4149 int upper_insn, lower_insn;
4150 int upper, lower;
4152 upper_insn = bfd_get_16 (abfd, address);
4153 lower_insn = bfd_get_16 (abfd, address + 2);
4154 upper = upper_insn & 0x7ff;
4155 lower = lower_insn & 0x7ff;
4157 addend = (upper << 12) | (lower << 1);
4158 addend += increment;
4159 addend >>= 1;
4161 upper_insn = (upper_insn & 0xf800) | ((addend >> 11) & 0x7ff);
4162 lower_insn = (lower_insn & 0xf800) | (addend & 0x7ff);
4164 bfd_put_16 (abfd, (bfd_vma) upper_insn, address);
4165 bfd_put_16 (abfd, (bfd_vma) lower_insn, address + 2);
4167 else
4169 bfd_vma contents;
4171 contents = bfd_get_32 (abfd, address);
4173 /* Get the (signed) value from the instruction. */
4174 addend = contents & howto->src_mask;
4175 if (addend & ((howto->src_mask + 1) >> 1))
4177 bfd_signed_vma mask;
4179 mask = -1;
4180 mask &= ~ howto->src_mask;
4181 addend |= mask;
4184 /* Add in the increment, (which is a byte value). */
4185 switch (howto->type)
4187 default:
4188 addend += increment;
4189 break;
4191 case R_ARM_PC24:
4192 case R_ARM_PLT32:
4193 case R_ARM_CALL:
4194 case R_ARM_JUMP24:
4195 addend <<= howto->size;
4196 addend += increment;
4198 /* Should we check for overflow here ? */
4200 /* Drop any undesired bits. */
4201 addend >>= howto->rightshift;
4202 break;
4205 contents = (contents & ~ howto->dst_mask) | (addend & howto->dst_mask);
4207 bfd_put_32 (abfd, contents, address);
4211 #define IS_ARM_TLS_RELOC(R_TYPE) \
4212 ((R_TYPE) == R_ARM_TLS_GD32 \
4213 || (R_TYPE) == R_ARM_TLS_LDO32 \
4214 || (R_TYPE) == R_ARM_TLS_LDM32 \
4215 || (R_TYPE) == R_ARM_TLS_DTPOFF32 \
4216 || (R_TYPE) == R_ARM_TLS_DTPMOD32 \
4217 || (R_TYPE) == R_ARM_TLS_TPOFF32 \
4218 || (R_TYPE) == R_ARM_TLS_LE32 \
4219 || (R_TYPE) == R_ARM_TLS_IE32)
4221 /* Relocate an ARM ELF section. */
4222 static bfd_boolean
4223 elf32_arm_relocate_section (bfd * output_bfd,
4224 struct bfd_link_info * info,
4225 bfd * input_bfd,
4226 asection * input_section,
4227 bfd_byte * contents,
4228 Elf_Internal_Rela * relocs,
4229 Elf_Internal_Sym * local_syms,
4230 asection ** local_sections)
4232 Elf_Internal_Shdr *symtab_hdr;
4233 struct elf_link_hash_entry **sym_hashes;
4234 Elf_Internal_Rela *rel;
4235 Elf_Internal_Rela *relend;
4236 const char *name;
4237 struct elf32_arm_link_hash_table * globals;
4239 globals = elf32_arm_hash_table (info);
4240 if (info->relocatable && !globals->use_rel)
4241 return TRUE;
4243 symtab_hdr = & elf_tdata (input_bfd)->symtab_hdr;
4244 sym_hashes = elf_sym_hashes (input_bfd);
4246 rel = relocs;
4247 relend = relocs + input_section->reloc_count;
4248 for (; rel < relend; rel++)
4250 int r_type;
4251 reloc_howto_type * howto;
4252 unsigned long r_symndx;
4253 Elf_Internal_Sym * sym;
4254 asection * sec;
4255 struct elf_link_hash_entry * h;
4256 bfd_vma relocation;
4257 bfd_reloc_status_type r;
4258 arelent bfd_reloc;
4259 char sym_type;
4260 bfd_boolean unresolved_reloc = FALSE;
4262 r_symndx = ELF32_R_SYM (rel->r_info);
4263 r_type = ELF32_R_TYPE (rel->r_info);
4264 r_type = arm_real_reloc_type (globals, r_type);
4266 if ( r_type == R_ARM_GNU_VTENTRY
4267 || r_type == R_ARM_GNU_VTINHERIT)
4268 continue;
4270 bfd_reloc.howto = elf32_arm_howto_from_type (r_type);
4271 howto = bfd_reloc.howto;
4273 if (info->relocatable && globals->use_rel)
4275 /* This is a relocatable link. We don't have to change
4276 anything, unless the reloc is against a section symbol,
4277 in which case we have to adjust according to where the
4278 section symbol winds up in the output section. */
4279 if (r_symndx < symtab_hdr->sh_info)
4281 sym = local_syms + r_symndx;
4282 if (ELF_ST_TYPE (sym->st_info) == STT_SECTION)
4284 sec = local_sections[r_symndx];
4285 arm_add_to_rel (input_bfd, contents + rel->r_offset,
4286 howto,
4287 (bfd_signed_vma) (sec->output_offset
4288 + sym->st_value));
4292 continue;
4295 /* This is a final link. */
4296 h = NULL;
4297 sym = NULL;
4298 sec = NULL;
4300 if (r_symndx < symtab_hdr->sh_info)
4302 sym = local_syms + r_symndx;
4303 sym_type = ELF32_ST_TYPE (sym->st_info);
4304 sec = local_sections[r_symndx];
4305 if (globals->use_rel)
4307 relocation = (sec->output_section->vma
4308 + sec->output_offset
4309 + sym->st_value);
4310 if ((sec->flags & SEC_MERGE)
4311 && ELF_ST_TYPE (sym->st_info) == STT_SECTION)
4313 asection *msec;
4314 bfd_vma addend, value;
4316 if (howto->rightshift)
4318 (*_bfd_error_handler)
4319 (_("%B(%A+0x%lx): %s relocation against SEC_MERGE section"),
4320 input_bfd, input_section,
4321 (long) rel->r_offset, howto->name);
4322 return FALSE;
4325 value = bfd_get_32 (input_bfd, contents + rel->r_offset);
4327 /* Get the (signed) value from the instruction. */
4328 addend = value & howto->src_mask;
4329 if (addend & ((howto->src_mask + 1) >> 1))
4331 bfd_signed_vma mask;
4333 mask = -1;
4334 mask &= ~ howto->src_mask;
4335 addend |= mask;
4337 msec = sec;
4338 addend =
4339 _bfd_elf_rel_local_sym (output_bfd, sym, &msec, addend)
4340 - relocation;
4341 addend += msec->output_section->vma + msec->output_offset;
4342 value = (value & ~ howto->dst_mask) | (addend & howto->dst_mask);
4343 bfd_put_32 (input_bfd, value, contents + rel->r_offset);
4346 else
4347 relocation = _bfd_elf_rela_local_sym (output_bfd, sym, &sec, rel);
4349 else
4351 bfd_boolean warned;
4353 RELOC_FOR_GLOBAL_SYMBOL (info, input_bfd, input_section, rel,
4354 r_symndx, symtab_hdr, sym_hashes,
4355 h, sec, relocation,
4356 unresolved_reloc, warned);
4358 sym_type = h->type;
4361 if (h != NULL)
4362 name = h->root.root.string;
4363 else
4365 name = (bfd_elf_string_from_elf_section
4366 (input_bfd, symtab_hdr->sh_link, sym->st_name));
4367 if (name == NULL || *name == '\0')
4368 name = bfd_section_name (input_bfd, sec);
4371 if (r_symndx != 0
4372 && r_type != R_ARM_NONE
4373 && (h == NULL
4374 || h->root.type == bfd_link_hash_defined
4375 || h->root.type == bfd_link_hash_defweak)
4376 && IS_ARM_TLS_RELOC (r_type) != (sym_type == STT_TLS))
4378 (*_bfd_error_handler)
4379 ((sym_type == STT_TLS
4380 ? _("%B(%A+0x%lx): %s used with TLS symbol %s")
4381 : _("%B(%A+0x%lx): %s used with non-TLS symbol %s")),
4382 input_bfd,
4383 input_section,
4384 (long) rel->r_offset,
4385 howto->name,
4386 name);
4389 r = elf32_arm_final_link_relocate (howto, input_bfd, output_bfd,
4390 input_section, contents, rel,
4391 relocation, info, sec, name,
4392 (h ? ELF_ST_TYPE (h->type) :
4393 ELF_ST_TYPE (sym->st_info)), h,
4394 &unresolved_reloc);
4396 /* Dynamic relocs are not propagated for SEC_DEBUGGING sections
4397 because such sections are not SEC_ALLOC and thus ld.so will
4398 not process them. */
4399 if (unresolved_reloc
4400 && !((input_section->flags & SEC_DEBUGGING) != 0
4401 && h->def_dynamic))
4403 (*_bfd_error_handler)
4404 (_("%B(%A+0x%lx): unresolvable %s relocation against symbol `%s'"),
4405 input_bfd,
4406 input_section,
4407 (long) rel->r_offset,
4408 howto->name,
4409 h->root.root.string);
4410 return FALSE;
4413 if (r != bfd_reloc_ok)
4415 const char * msg = (const char *) 0;
4417 switch (r)
4419 case bfd_reloc_overflow:
4420 /* If the overflowing reloc was to an undefined symbol,
4421 we have already printed one error message and there
4422 is no point complaining again. */
4423 if ((! h ||
4424 h->root.type != bfd_link_hash_undefined)
4425 && (!((*info->callbacks->reloc_overflow)
4426 (info, (h ? &h->root : NULL), name, howto->name,
4427 (bfd_vma) 0, input_bfd, input_section,
4428 rel->r_offset))))
4429 return FALSE;
4430 break;
4432 case bfd_reloc_undefined:
4433 if (!((*info->callbacks->undefined_symbol)
4434 (info, name, input_bfd, input_section,
4435 rel->r_offset, TRUE)))
4436 return FALSE;
4437 break;
4439 case bfd_reloc_outofrange:
4440 msg = _("internal error: out of range error");
4441 goto common_error;
4443 case bfd_reloc_notsupported:
4444 msg = _("internal error: unsupported relocation error");
4445 goto common_error;
4447 case bfd_reloc_dangerous:
4448 msg = _("internal error: dangerous error");
4449 goto common_error;
4451 default:
4452 msg = _("internal error: unknown error");
4453 /* fall through */
4455 common_error:
4456 if (!((*info->callbacks->warning)
4457 (info, msg, name, input_bfd, input_section,
4458 rel->r_offset)))
4459 return FALSE;
4460 break;
4465 return TRUE;
4468 /* Allocate/find an object attribute. */
4469 static aeabi_attribute *
4470 elf32_arm_new_eabi_attr (bfd *abfd, int tag)
4472 aeabi_attribute *attr;
4473 aeabi_attribute_list *list;
4474 aeabi_attribute_list *p;
4475 aeabi_attribute_list **lastp;
4478 if (tag < NUM_KNOWN_ATTRIBUTES)
4480 /* Knwon tags are preallocated. */
4481 attr = &elf32_arm_tdata (abfd)->known_eabi_attributes[tag];
4483 else
4485 /* Create a new tag. */
4486 list = (aeabi_attribute_list *)
4487 bfd_alloc (abfd, sizeof (aeabi_attribute_list));
4488 memset (list, 0, sizeof (aeabi_attribute_list));
4489 list->tag = tag;
4490 /* Keep the tag list in order. */
4491 lastp = &elf32_arm_tdata (abfd)->other_eabi_attributes;
4492 for (p = *lastp; p; p = p->next)
4494 if (tag < p->tag)
4495 break;
4496 lastp = &p->next;
4498 list->next = *lastp;
4499 *lastp = list;
4500 attr = &list->attr;
4503 return attr;
4507 elf32_arm_get_eabi_attr_int (bfd *abfd, int tag)
4509 aeabi_attribute_list *p;
4511 if (tag < NUM_KNOWN_ATTRIBUTES)
4513 /* Knwon tags are preallocated. */
4514 return elf32_arm_tdata (abfd)->known_eabi_attributes[tag].i;
4516 else
4518 for (p = elf32_arm_tdata (abfd)->other_eabi_attributes;
4520 p = p->next)
4522 if (tag == p->tag)
4523 return p->attr.i;
4524 if (tag < p->tag)
4525 break;
4527 return 0;
4531 void
4532 elf32_arm_add_eabi_attr_int (bfd *abfd, int tag, unsigned int i)
4534 aeabi_attribute *attr;
4536 attr = elf32_arm_new_eabi_attr (abfd, tag);
4537 attr->type = 1;
4538 attr->i = i;
4541 static char *
4542 attr_strdup (bfd *abfd, const char * s)
4544 char * p;
4545 int len;
4547 len = strlen (s) + 1;
4548 p = (char *)bfd_alloc(abfd, len);
4549 return memcpy (p, s, len);
4552 void
4553 elf32_arm_add_eabi_attr_string (bfd *abfd, int tag, const char *s)
4555 aeabi_attribute *attr;
4557 attr = elf32_arm_new_eabi_attr (abfd, tag);
4558 attr->type = 2;
4559 attr->s = attr_strdup (abfd, s);
4562 void
4563 elf32_arm_add_eabi_attr_compat (bfd *abfd, unsigned int i, const char *s)
4565 aeabi_attribute_list *list;
4566 aeabi_attribute_list *p;
4567 aeabi_attribute_list **lastp;
4569 list = (aeabi_attribute_list *)
4570 bfd_alloc (abfd, sizeof (aeabi_attribute_list));
4571 memset (list, 0, sizeof (aeabi_attribute_list));
4572 list->tag = Tag_compatibility;
4573 list->attr.type = 3;
4574 list->attr.i = i;
4575 list->attr.s = attr_strdup (abfd, s);
4577 lastp = &elf32_arm_tdata (abfd)->other_eabi_attributes;
4578 for (p = *lastp; p; p = p->next)
4580 int cmp;
4581 if (p->tag != Tag_compatibility)
4582 break;
4583 cmp = strcmp(s, p->attr.s);
4584 if (cmp < 0 || (cmp == 0 && i < p->attr.i))
4585 break;
4586 lastp = &p->next;
4588 list->next = *lastp;
4589 *lastp = list;
4592 /* Set the right machine number. */
4594 static bfd_boolean
4595 elf32_arm_object_p (bfd *abfd)
4597 unsigned int mach;
4599 mach = bfd_arm_get_mach_from_notes (abfd, ARM_NOTE_SECTION);
4601 if (mach != bfd_mach_arm_unknown)
4602 bfd_default_set_arch_mach (abfd, bfd_arch_arm, mach);
4604 else if (elf_elfheader (abfd)->e_flags & EF_ARM_MAVERICK_FLOAT)
4605 bfd_default_set_arch_mach (abfd, bfd_arch_arm, bfd_mach_arm_ep9312);
4607 else
4608 bfd_default_set_arch_mach (abfd, bfd_arch_arm, mach);
4610 return TRUE;
4613 /* Function to keep ARM specific flags in the ELF header. */
4615 static bfd_boolean
4616 elf32_arm_set_private_flags (bfd *abfd, flagword flags)
4618 if (elf_flags_init (abfd)
4619 && elf_elfheader (abfd)->e_flags != flags)
4621 if (EF_ARM_EABI_VERSION (flags) == EF_ARM_EABI_UNKNOWN)
4623 if (flags & EF_ARM_INTERWORK)
4624 (*_bfd_error_handler)
4625 (_("Warning: Not setting interworking flag of %B since it has already been specified as non-interworking"),
4626 abfd);
4627 else
4628 _bfd_error_handler
4629 (_("Warning: Clearing the interworking flag of %B due to outside request"),
4630 abfd);
4633 else
4635 elf_elfheader (abfd)->e_flags = flags;
4636 elf_flags_init (abfd) = TRUE;
4639 return TRUE;
4642 /* Copy the eabi object attribute from IBFD to OBFD. */
4643 static void
4644 copy_eabi_attributes (bfd *ibfd, bfd *obfd)
4646 aeabi_attribute *in_attr;
4647 aeabi_attribute *out_attr;
4648 aeabi_attribute_list *list;
4649 int i;
4651 in_attr = elf32_arm_tdata (ibfd)->known_eabi_attributes;
4652 out_attr = elf32_arm_tdata (obfd)->known_eabi_attributes;
4653 for (i = 4; i < NUM_KNOWN_ATTRIBUTES; i++)
4655 out_attr->i = in_attr->i;
4656 if (in_attr->s && *in_attr->s)
4657 out_attr->s = attr_strdup (obfd, in_attr->s);
4658 in_attr++;
4659 out_attr++;
4662 for (list = elf32_arm_tdata (ibfd)->other_eabi_attributes;
4663 list;
4664 list = list->next)
4666 in_attr = &list->attr;
4667 switch (in_attr->type)
4669 case 1:
4670 elf32_arm_add_eabi_attr_int (obfd, list->tag, in_attr->i);
4671 break;
4672 case 2:
4673 elf32_arm_add_eabi_attr_string (obfd, list->tag, in_attr->s);
4674 break;
4675 case 3:
4676 elf32_arm_add_eabi_attr_compat (obfd, in_attr->i, in_attr->s);
4677 break;
4678 default:
4679 abort();
4685 /* Copy backend specific data from one object module to another. */
4687 static bfd_boolean
4688 elf32_arm_copy_private_bfd_data (bfd *ibfd, bfd *obfd)
4690 flagword in_flags;
4691 flagword out_flags;
4693 if ( bfd_get_flavour (ibfd) != bfd_target_elf_flavour
4694 || bfd_get_flavour (obfd) != bfd_target_elf_flavour)
4695 return TRUE;
4697 in_flags = elf_elfheader (ibfd)->e_flags;
4698 out_flags = elf_elfheader (obfd)->e_flags;
4700 if (elf_flags_init (obfd)
4701 && EF_ARM_EABI_VERSION (out_flags) == EF_ARM_EABI_UNKNOWN
4702 && in_flags != out_flags)
4704 /* Cannot mix APCS26 and APCS32 code. */
4705 if ((in_flags & EF_ARM_APCS_26) != (out_flags & EF_ARM_APCS_26))
4706 return FALSE;
4708 /* Cannot mix float APCS and non-float APCS code. */
4709 if ((in_flags & EF_ARM_APCS_FLOAT) != (out_flags & EF_ARM_APCS_FLOAT))
4710 return FALSE;
4712 /* If the src and dest have different interworking flags
4713 then turn off the interworking bit. */
4714 if ((in_flags & EF_ARM_INTERWORK) != (out_flags & EF_ARM_INTERWORK))
4716 if (out_flags & EF_ARM_INTERWORK)
4717 _bfd_error_handler
4718 (_("Warning: Clearing the interworking flag of %B because non-interworking code in %B has been linked with it"),
4719 obfd, ibfd);
4721 in_flags &= ~EF_ARM_INTERWORK;
4724 /* Likewise for PIC, though don't warn for this case. */
4725 if ((in_flags & EF_ARM_PIC) != (out_flags & EF_ARM_PIC))
4726 in_flags &= ~EF_ARM_PIC;
4729 elf_elfheader (obfd)->e_flags = in_flags;
4730 elf_flags_init (obfd) = TRUE;
4732 /* Also copy the EI_OSABI field. */
4733 elf_elfheader (obfd)->e_ident[EI_OSABI] =
4734 elf_elfheader (ibfd)->e_ident[EI_OSABI];
4736 /* Copy EABI object attributes. */
4737 copy_eabi_attributes (ibfd, obfd);
4739 return TRUE;
4742 /* Values for Tag_ABI_PCS_R9_use. */
4743 enum
4745 AEABI_R9_V6,
4746 AEABI_R9_SB,
4747 AEABI_R9_TLS,
4748 AEABI_R9_unused
4751 /* Values for Tag_ABI_PCS_RW_data. */
4752 enum
4754 AEABI_PCS_RW_data_absolute,
4755 AEABI_PCS_RW_data_PCrel,
4756 AEABI_PCS_RW_data_SBrel,
4757 AEABI_PCS_RW_data_unused
4760 /* Values for Tag_ABI_enum_size. */
4761 enum
4763 AEABI_enum_unused,
4764 AEABI_enum_short,
4765 AEABI_enum_wide,
4766 AEABI_enum_forced_wide
4769 /* Merge EABI object attributes from IBFD into OBFD. Raise an error if there
4770 are conflicting attributes. */
4771 static bfd_boolean
4772 elf32_arm_merge_eabi_attributes (bfd *ibfd, bfd *obfd)
4774 aeabi_attribute *in_attr;
4775 aeabi_attribute *out_attr;
4776 aeabi_attribute_list *in_list;
4777 aeabi_attribute_list *out_list;
4778 /* Some tags have 0 = don't care, 1 = strong requirement,
4779 2 = weak requirement. */
4780 static const int order_312[3] = {3, 1, 2};
4781 int i;
4783 if (!elf32_arm_tdata (ibfd)->known_eabi_attributes[0].i)
4785 /* This is the first object. Copy the attributes. */
4786 copy_eabi_attributes (ibfd, obfd);
4787 return TRUE;
4790 /* Use the Tag_null value to indicate the attributes have been
4791 initialized. */
4792 elf32_arm_tdata (ibfd)->known_eabi_attributes[0].i = 1;
4794 in_attr = elf32_arm_tdata (ibfd)->known_eabi_attributes;
4795 out_attr = elf32_arm_tdata (obfd)->known_eabi_attributes;
4796 /* This needs to happen before Tag_ABI_FP_number_model is merged. */
4797 if (in_attr[Tag_ABI_VFP_args].i != out_attr[Tag_ABI_VFP_args].i)
4799 /* Ignore mismatches if teh object doesn't use floating point. */
4800 if (out_attr[Tag_ABI_FP_number_model].i == 0)
4801 out_attr[Tag_ABI_VFP_args].i = in_attr[Tag_ABI_VFP_args].i;
4802 else if (in_attr[Tag_ABI_FP_number_model].i != 0)
4804 _bfd_error_handler
4805 (_("ERROR: %B uses VFP register arguments, %B does not"),
4806 ibfd, obfd);
4807 return FALSE;
4811 for (i = 4; i < NUM_KNOWN_ATTRIBUTES; i++)
4813 /* Merge this attribute with existing attributes. */
4814 switch (i)
4816 case Tag_CPU_raw_name:
4817 case Tag_CPU_name:
4818 /* Use whichever has the greatest architecture requirements. */
4819 if (in_attr[Tag_CPU_arch].i > out_attr[Tag_CPU_arch].i)
4820 out_attr[i].s = attr_strdup(obfd, in_attr[i].s);
4821 break;
4823 case Tag_ABI_optimization_goals:
4824 case Tag_ABI_FP_optimization_goals:
4825 /* Use the first value seen. */
4826 break;
4828 case Tag_CPU_arch:
4829 case Tag_ARM_ISA_use:
4830 case Tag_THUMB_ISA_use:
4831 case Tag_VFP_arch:
4832 case Tag_WMMX_arch:
4833 case Tag_NEON_arch:
4834 /* ??? Do NEON and WMMX conflict? */
4835 case Tag_ABI_FP_rounding:
4836 case Tag_ABI_FP_denormal:
4837 case Tag_ABI_FP_exceptions:
4838 case Tag_ABI_FP_user_exceptions:
4839 case Tag_ABI_FP_number_model:
4840 case Tag_ABI_align8_preserved:
4841 case Tag_ABI_HardFP_use:
4842 /* Use the largest value specified. */
4843 if (in_attr[i].i > out_attr[i].i)
4844 out_attr[i].i = in_attr[i].i;
4845 break;
4847 case Tag_CPU_arch_profile:
4848 /* Warn if conflicting architecture profiles used. */
4849 if (out_attr[i].i && in_attr[i].i && in_attr[i].i != out_attr[i].i)
4851 _bfd_error_handler
4852 (_("ERROR: %B: Conflicting architecture profiles %c/%c"),
4853 ibfd, in_attr[i].i, out_attr[i].i);
4854 return FALSE;
4856 if (in_attr[i].i)
4857 out_attr[i].i = in_attr[i].i;
4858 break;
4859 case Tag_PCS_config:
4860 if (out_attr[i].i == 0)
4861 out_attr[i].i = in_attr[i].i;
4862 else if (in_attr[i].i != 0 && out_attr[i].i != 0)
4864 /* It's sometimes ok to mix different configs, so this is only
4865 a warning. */
4866 _bfd_error_handler
4867 (_("Warning: %B: Conflicting platform configuration"), ibfd);
4869 break;
4870 case Tag_ABI_PCS_R9_use:
4871 if (out_attr[i].i != AEABI_R9_unused
4872 && in_attr[i].i != AEABI_R9_unused)
4874 _bfd_error_handler
4875 (_("ERROR: %B: Conflicting use of R9"), ibfd);
4876 return FALSE;
4878 if (out_attr[i].i == AEABI_R9_unused)
4879 out_attr[i].i = in_attr[i].i;
4880 break;
4881 case Tag_ABI_PCS_RW_data:
4882 if (in_attr[i].i == AEABI_PCS_RW_data_SBrel
4883 && out_attr[Tag_ABI_PCS_R9_use].i != AEABI_R9_SB
4884 && out_attr[Tag_ABI_PCS_R9_use].i != AEABI_R9_unused)
4886 _bfd_error_handler
4887 (_("ERROR: %B: SB relative addressing conflicts with use of R9"),
4888 ibfd);
4889 return FALSE;
4891 /* Use the smallest value specified. */
4892 if (in_attr[i].i < out_attr[i].i)
4893 out_attr[i].i = in_attr[i].i;
4894 break;
4895 case Tag_ABI_PCS_RO_data:
4896 /* Use the smallest value specified. */
4897 if (in_attr[i].i < out_attr[i].i)
4898 out_attr[i].i = in_attr[i].i;
4899 break;
4900 case Tag_ABI_PCS_GOT_use:
4901 if (in_attr[i].i > 2 || out_attr[i].i > 2
4902 || order_312[in_attr[i].i] < order_312[out_attr[i].i])
4903 out_attr[i].i = in_attr[i].i;
4904 break;
4905 case Tag_ABI_PCS_wchar_t:
4906 if (out_attr[i].i && in_attr[i].i && out_attr[i].i != in_attr[i].i)
4908 _bfd_error_handler
4909 (_("ERROR: %B: Conflicting definitions of wchar_t"), ibfd);
4910 return FALSE;
4912 if (in_attr[i].i)
4913 out_attr[i].i = in_attr[i].i;
4914 break;
4915 case Tag_ABI_align8_needed:
4916 /* ??? Check against Tag_ABI_align8_preserved. */
4917 if (in_attr[i].i > 2 || out_attr[i].i > 2
4918 || order_312[in_attr[i].i] < order_312[out_attr[i].i])
4919 out_attr[i].i = in_attr[i].i;
4920 break;
4921 case Tag_ABI_enum_size:
4922 if (in_attr[i].i != AEABI_enum_unused)
4924 if (out_attr[i].i == AEABI_enum_unused
4925 || out_attr[i].i == AEABI_enum_forced_wide)
4927 /* The existing object is compatible with anything.
4928 Use whatever requirements the new object has. */
4929 out_attr[i].i = in_attr[i].i;
4931 else if (in_attr[i].i != AEABI_enum_forced_wide
4932 && out_attr[i].i != in_attr[i].i)
4934 _bfd_error_handler
4935 (_("ERROR: %B: Conflicting enum sizes"), ibfd);
4938 break;
4939 case Tag_ABI_VFP_args:
4940 /* Aready done. */
4941 break;
4942 case Tag_ABI_WMMX_args:
4943 if (in_attr[i].i != out_attr[i].i)
4945 _bfd_error_handler
4946 (_("ERROR: %B uses iWMMXt register arguments, %B does not"),
4947 ibfd, obfd);
4948 return FALSE;
4950 break;
4951 default: /* All known attributes should be explicitly covered. */
4952 abort ();
4956 in_list = elf32_arm_tdata (ibfd)->other_eabi_attributes;
4957 out_list = elf32_arm_tdata (ibfd)->other_eabi_attributes;
4958 while (in_list && in_list->tag == Tag_compatibility)
4960 in_attr = &in_list->attr;
4961 if (in_attr->i == 0)
4962 continue;
4963 if (in_attr->i == 1)
4965 _bfd_error_handler
4966 (_("ERROR: %B: Must be processed by '%s' toolchain"),
4967 ibfd, in_attr->s);
4968 return FALSE;
4970 if (!out_list || out_list->tag != Tag_compatibility
4971 || strcmp (in_attr->s, out_list->attr.s) != 0)
4973 /* Add this compatibility tag to the output. */
4974 elf32_arm_add_eabi_attr_compat (obfd, in_attr->i, in_attr->s);
4975 continue;
4977 out_attr = &out_list->attr;
4978 /* Check all the input tags with the same identifier. */
4979 for (;;)
4981 if (out_list->tag != Tag_compatibility
4982 || in_attr->i != out_attr->i
4983 || strcmp (in_attr->s, out_attr->s) != 0)
4985 _bfd_error_handler
4986 (_("ERROR: %B: Incompatible object tag '%s':%d"),
4987 ibfd, in_attr->s, in_attr->i);
4988 return FALSE;
4990 in_list = in_list->next;
4991 if (in_list->tag != Tag_compatibility
4992 || strcmp (in_attr->s, in_list->attr.s) != 0)
4993 break;
4994 in_attr = &in_list->attr;
4995 out_list = out_list->next;
4996 if (out_list)
4997 out_attr = &out_list->attr;
5000 /* Check the output doesn't have extra tags with this identifier. */
5001 if (out_list && out_list->tag == Tag_compatibility
5002 && strcmp (in_attr->s, out_list->attr.s) == 0)
5004 _bfd_error_handler
5005 (_("ERROR: %B: Incompatible object tag '%s':%d"),
5006 ibfd, in_attr->s, out_list->attr.i);
5007 return FALSE;
5011 for (; in_list; in_list = in_list->next)
5013 if ((in_list->tag & 128) < 64)
5014 _bfd_error_handler
5015 (_("Warning: %B: Unknown EABI object attribute %d"),
5016 ibfd, in_list->tag);
5017 break;
5019 return TRUE;
5022 /* Merge backend specific data from an object file to the output
5023 object file when linking. */
5025 static bfd_boolean
5026 elf32_arm_merge_private_bfd_data (bfd * ibfd, bfd * obfd)
5028 flagword out_flags;
5029 flagword in_flags;
5030 bfd_boolean flags_compatible = TRUE;
5031 asection *sec;
5033 /* Check if we have the same endianess. */
5034 if (! _bfd_generic_verify_endian_match (ibfd, obfd))
5035 return FALSE;
5037 if ( bfd_get_flavour (ibfd) != bfd_target_elf_flavour
5038 || bfd_get_flavour (obfd) != bfd_target_elf_flavour)
5039 return TRUE;
5041 if (!elf32_arm_merge_eabi_attributes (ibfd, obfd))
5042 return FALSE;
5044 /* The input BFD must have had its flags initialised. */
5045 /* The following seems bogus to me -- The flags are initialized in
5046 the assembler but I don't think an elf_flags_init field is
5047 written into the object. */
5048 /* BFD_ASSERT (elf_flags_init (ibfd)); */
5050 in_flags = elf_elfheader (ibfd)->e_flags;
5051 out_flags = elf_elfheader (obfd)->e_flags;
5053 if (!elf_flags_init (obfd))
5055 /* If the input is the default architecture and had the default
5056 flags then do not bother setting the flags for the output
5057 architecture, instead allow future merges to do this. If no
5058 future merges ever set these flags then they will retain their
5059 uninitialised values, which surprise surprise, correspond
5060 to the default values. */
5061 if (bfd_get_arch_info (ibfd)->the_default
5062 && elf_elfheader (ibfd)->e_flags == 0)
5063 return TRUE;
5065 elf_flags_init (obfd) = TRUE;
5066 elf_elfheader (obfd)->e_flags = in_flags;
5068 if (bfd_get_arch (obfd) == bfd_get_arch (ibfd)
5069 && bfd_get_arch_info (obfd)->the_default)
5070 return bfd_set_arch_mach (obfd, bfd_get_arch (ibfd), bfd_get_mach (ibfd));
5072 return TRUE;
5075 /* Determine what should happen if the input ARM architecture
5076 does not match the output ARM architecture. */
5077 if (! bfd_arm_merge_machines (ibfd, obfd))
5078 return FALSE;
5080 /* Identical flags must be compatible. */
5081 if (in_flags == out_flags)
5082 return TRUE;
5084 /* Check to see if the input BFD actually contains any sections. If
5085 not, its flags may not have been initialised either, but it
5086 cannot actually cause any incompatiblity. Do not short-circuit
5087 dynamic objects; their section list may be emptied by
5088 elf_link_add_object_symbols.
5090 Also check to see if there are no code sections in the input.
5091 In this case there is no need to check for code specific flags.
5092 XXX - do we need to worry about floating-point format compatability
5093 in data sections ? */
5094 if (!(ibfd->flags & DYNAMIC))
5096 bfd_boolean null_input_bfd = TRUE;
5097 bfd_boolean only_data_sections = TRUE;
5099 for (sec = ibfd->sections; sec != NULL; sec = sec->next)
5101 /* Ignore synthetic glue sections. */
5102 if (strcmp (sec->name, ".glue_7")
5103 && strcmp (sec->name, ".glue_7t"))
5105 if ((bfd_get_section_flags (ibfd, sec)
5106 & (SEC_LOAD | SEC_CODE | SEC_HAS_CONTENTS))
5107 == (SEC_LOAD | SEC_CODE | SEC_HAS_CONTENTS))
5108 only_data_sections = FALSE;
5110 null_input_bfd = FALSE;
5111 break;
5115 if (null_input_bfd || only_data_sections)
5116 return TRUE;
5119 /* Complain about various flag mismatches. */
5120 if (EF_ARM_EABI_VERSION (in_flags) != EF_ARM_EABI_VERSION (out_flags))
5122 _bfd_error_handler
5123 (_("ERROR: Source object %B has EABI version %d, but target %B has EABI version %d"),
5124 ibfd, obfd,
5125 (in_flags & EF_ARM_EABIMASK) >> 24,
5126 (out_flags & EF_ARM_EABIMASK) >> 24);
5127 return FALSE;
5130 /* Not sure what needs to be checked for EABI versions >= 1. */
5131 if (EF_ARM_EABI_VERSION (in_flags) == EF_ARM_EABI_UNKNOWN)
5133 if ((in_flags & EF_ARM_APCS_26) != (out_flags & EF_ARM_APCS_26))
5135 _bfd_error_handler
5136 (_("ERROR: %B is compiled for APCS-%d, whereas target %B uses APCS-%d"),
5137 ibfd, obfd,
5138 in_flags & EF_ARM_APCS_26 ? 26 : 32,
5139 out_flags & EF_ARM_APCS_26 ? 26 : 32);
5140 flags_compatible = FALSE;
5143 if ((in_flags & EF_ARM_APCS_FLOAT) != (out_flags & EF_ARM_APCS_FLOAT))
5145 if (in_flags & EF_ARM_APCS_FLOAT)
5146 _bfd_error_handler
5147 (_("ERROR: %B passes floats in float registers, whereas %B passes them in integer registers"),
5148 ibfd, obfd);
5149 else
5150 _bfd_error_handler
5151 (_("ERROR: %B passes floats in integer registers, whereas %B passes them in float registers"),
5152 ibfd, obfd);
5154 flags_compatible = FALSE;
5157 if ((in_flags & EF_ARM_VFP_FLOAT) != (out_flags & EF_ARM_VFP_FLOAT))
5159 if (in_flags & EF_ARM_VFP_FLOAT)
5160 _bfd_error_handler
5161 (_("ERROR: %B uses VFP instructions, whereas %B does not"),
5162 ibfd, obfd);
5163 else
5164 _bfd_error_handler
5165 (_("ERROR: %B uses FPA instructions, whereas %B does not"),
5166 ibfd, obfd);
5168 flags_compatible = FALSE;
5171 if ((in_flags & EF_ARM_MAVERICK_FLOAT) != (out_flags & EF_ARM_MAVERICK_FLOAT))
5173 if (in_flags & EF_ARM_MAVERICK_FLOAT)
5174 _bfd_error_handler
5175 (_("ERROR: %B uses Maverick instructions, whereas %B does not"),
5176 ibfd, obfd);
5177 else
5178 _bfd_error_handler
5179 (_("ERROR: %B does not use Maverick instructions, whereas %B does"),
5180 ibfd, obfd);
5182 flags_compatible = FALSE;
5185 #ifdef EF_ARM_SOFT_FLOAT
5186 if ((in_flags & EF_ARM_SOFT_FLOAT) != (out_flags & EF_ARM_SOFT_FLOAT))
5188 /* We can allow interworking between code that is VFP format
5189 layout, and uses either soft float or integer regs for
5190 passing floating point arguments and results. We already
5191 know that the APCS_FLOAT flags match; similarly for VFP
5192 flags. */
5193 if ((in_flags & EF_ARM_APCS_FLOAT) != 0
5194 || (in_flags & EF_ARM_VFP_FLOAT) == 0)
5196 if (in_flags & EF_ARM_SOFT_FLOAT)
5197 _bfd_error_handler
5198 (_("ERROR: %B uses software FP, whereas %B uses hardware FP"),
5199 ibfd, obfd);
5200 else
5201 _bfd_error_handler
5202 (_("ERROR: %B uses hardware FP, whereas %B uses software FP"),
5203 ibfd, obfd);
5205 flags_compatible = FALSE;
5208 #endif
5210 /* Interworking mismatch is only a warning. */
5211 if ((in_flags & EF_ARM_INTERWORK) != (out_flags & EF_ARM_INTERWORK))
5213 if (in_flags & EF_ARM_INTERWORK)
5215 _bfd_error_handler
5216 (_("Warning: %B supports interworking, whereas %B does not"),
5217 ibfd, obfd);
5219 else
5221 _bfd_error_handler
5222 (_("Warning: %B does not support interworking, whereas %B does"),
5223 ibfd, obfd);
5228 return flags_compatible;
5231 /* Display the flags field. */
5233 static bfd_boolean
5234 elf32_arm_print_private_bfd_data (bfd *abfd, void * ptr)
5236 FILE * file = (FILE *) ptr;
5237 unsigned long flags;
5239 BFD_ASSERT (abfd != NULL && ptr != NULL);
5241 /* Print normal ELF private data. */
5242 _bfd_elf_print_private_bfd_data (abfd, ptr);
5244 flags = elf_elfheader (abfd)->e_flags;
5245 /* Ignore init flag - it may not be set, despite the flags field
5246 containing valid data. */
5248 /* xgettext:c-format */
5249 fprintf (file, _("private flags = %lx:"), elf_elfheader (abfd)->e_flags);
5251 switch (EF_ARM_EABI_VERSION (flags))
5253 case EF_ARM_EABI_UNKNOWN:
5254 /* The following flag bits are GNU extensions and not part of the
5255 official ARM ELF extended ABI. Hence they are only decoded if
5256 the EABI version is not set. */
5257 if (flags & EF_ARM_INTERWORK)
5258 fprintf (file, _(" [interworking enabled]"));
5260 if (flags & EF_ARM_APCS_26)
5261 fprintf (file, " [APCS-26]");
5262 else
5263 fprintf (file, " [APCS-32]");
5265 if (flags & EF_ARM_VFP_FLOAT)
5266 fprintf (file, _(" [VFP float format]"));
5267 else if (flags & EF_ARM_MAVERICK_FLOAT)
5268 fprintf (file, _(" [Maverick float format]"));
5269 else
5270 fprintf (file, _(" [FPA float format]"));
5272 if (flags & EF_ARM_APCS_FLOAT)
5273 fprintf (file, _(" [floats passed in float registers]"));
5275 if (flags & EF_ARM_PIC)
5276 fprintf (file, _(" [position independent]"));
5278 if (flags & EF_ARM_NEW_ABI)
5279 fprintf (file, _(" [new ABI]"));
5281 if (flags & EF_ARM_OLD_ABI)
5282 fprintf (file, _(" [old ABI]"));
5284 if (flags & EF_ARM_SOFT_FLOAT)
5285 fprintf (file, _(" [software FP]"));
5287 flags &= ~(EF_ARM_INTERWORK | EF_ARM_APCS_26 | EF_ARM_APCS_FLOAT
5288 | EF_ARM_PIC | EF_ARM_NEW_ABI | EF_ARM_OLD_ABI
5289 | EF_ARM_SOFT_FLOAT | EF_ARM_VFP_FLOAT
5290 | EF_ARM_MAVERICK_FLOAT);
5291 break;
5293 case EF_ARM_EABI_VER1:
5294 fprintf (file, _(" [Version1 EABI]"));
5296 if (flags & EF_ARM_SYMSARESORTED)
5297 fprintf (file, _(" [sorted symbol table]"));
5298 else
5299 fprintf (file, _(" [unsorted symbol table]"));
5301 flags &= ~ EF_ARM_SYMSARESORTED;
5302 break;
5304 case EF_ARM_EABI_VER2:
5305 fprintf (file, _(" [Version2 EABI]"));
5307 if (flags & EF_ARM_SYMSARESORTED)
5308 fprintf (file, _(" [sorted symbol table]"));
5309 else
5310 fprintf (file, _(" [unsorted symbol table]"));
5312 if (flags & EF_ARM_DYNSYMSUSESEGIDX)
5313 fprintf (file, _(" [dynamic symbols use segment index]"));
5315 if (flags & EF_ARM_MAPSYMSFIRST)
5316 fprintf (file, _(" [mapping symbols precede others]"));
5318 flags &= ~(EF_ARM_SYMSARESORTED | EF_ARM_DYNSYMSUSESEGIDX
5319 | EF_ARM_MAPSYMSFIRST);
5320 break;
5322 case EF_ARM_EABI_VER3:
5323 fprintf (file, _(" [Version3 EABI]"));
5324 break;
5326 case EF_ARM_EABI_VER4:
5327 fprintf (file, _(" [Version4 EABI]"));
5329 if (flags & EF_ARM_BE8)
5330 fprintf (file, _(" [BE8]"));
5332 if (flags & EF_ARM_LE8)
5333 fprintf (file, _(" [LE8]"));
5335 flags &= ~(EF_ARM_LE8 | EF_ARM_BE8);
5336 break;
5338 default:
5339 fprintf (file, _(" <EABI version unrecognised>"));
5340 break;
5343 flags &= ~ EF_ARM_EABIMASK;
5345 if (flags & EF_ARM_RELEXEC)
5346 fprintf (file, _(" [relocatable executable]"));
5348 if (flags & EF_ARM_HASENTRY)
5349 fprintf (file, _(" [has entry point]"));
5351 flags &= ~ (EF_ARM_RELEXEC | EF_ARM_HASENTRY);
5353 if (flags)
5354 fprintf (file, _("<Unrecognised flag bits set>"));
5356 fputc ('\n', file);
5358 return TRUE;
5361 static int
5362 elf32_arm_get_symbol_type (Elf_Internal_Sym * elf_sym, int type)
5364 switch (ELF_ST_TYPE (elf_sym->st_info))
5366 case STT_ARM_TFUNC:
5367 return ELF_ST_TYPE (elf_sym->st_info);
5369 case STT_ARM_16BIT:
5370 /* If the symbol is not an object, return the STT_ARM_16BIT flag.
5371 This allows us to distinguish between data used by Thumb instructions
5372 and non-data (which is probably code) inside Thumb regions of an
5373 executable. */
5374 if (type != STT_OBJECT && type != STT_TLS)
5375 return ELF_ST_TYPE (elf_sym->st_info);
5376 break;
5378 default:
5379 break;
5382 return type;
5385 static asection *
5386 elf32_arm_gc_mark_hook (asection * sec,
5387 struct bfd_link_info * info ATTRIBUTE_UNUSED,
5388 Elf_Internal_Rela * rel,
5389 struct elf_link_hash_entry * h,
5390 Elf_Internal_Sym * sym)
5392 if (h != NULL)
5394 switch (ELF32_R_TYPE (rel->r_info))
5396 case R_ARM_GNU_VTINHERIT:
5397 case R_ARM_GNU_VTENTRY:
5398 break;
5400 default:
5401 switch (h->root.type)
5403 case bfd_link_hash_defined:
5404 case bfd_link_hash_defweak:
5405 return h->root.u.def.section;
5407 case bfd_link_hash_common:
5408 return h->root.u.c.p->section;
5410 default:
5411 break;
5415 else
5416 return bfd_section_from_elf_index (sec->owner, sym->st_shndx);
5418 return NULL;
5421 /* Update the got entry reference counts for the section being removed. */
5423 static bfd_boolean
5424 elf32_arm_gc_sweep_hook (bfd * abfd,
5425 struct bfd_link_info * info,
5426 asection * sec,
5427 const Elf_Internal_Rela * relocs)
5429 Elf_Internal_Shdr *symtab_hdr;
5430 struct elf_link_hash_entry **sym_hashes;
5431 bfd_signed_vma *local_got_refcounts;
5432 const Elf_Internal_Rela *rel, *relend;
5433 struct elf32_arm_link_hash_table * globals;
5435 globals = elf32_arm_hash_table (info);
5437 elf_section_data (sec)->local_dynrel = NULL;
5439 symtab_hdr = &elf_tdata (abfd)->symtab_hdr;
5440 sym_hashes = elf_sym_hashes (abfd);
5441 local_got_refcounts = elf_local_got_refcounts (abfd);
5443 relend = relocs + sec->reloc_count;
5444 for (rel = relocs; rel < relend; rel++)
5446 unsigned long r_symndx;
5447 struct elf_link_hash_entry *h = NULL;
5448 int r_type;
5450 r_symndx = ELF32_R_SYM (rel->r_info);
5451 if (r_symndx >= symtab_hdr->sh_info)
5453 h = sym_hashes[r_symndx - symtab_hdr->sh_info];
5454 while (h->root.type == bfd_link_hash_indirect
5455 || h->root.type == bfd_link_hash_warning)
5456 h = (struct elf_link_hash_entry *) h->root.u.i.link;
5459 r_type = ELF32_R_TYPE (rel->r_info);
5460 r_type = arm_real_reloc_type (globals, r_type);
5461 switch (r_type)
5463 case R_ARM_GOT32:
5464 case R_ARM_GOT_PREL:
5465 case R_ARM_TLS_GD32:
5466 case R_ARM_TLS_IE32:
5467 if (h != NULL)
5469 if (h->got.refcount > 0)
5470 h->got.refcount -= 1;
5472 else if (local_got_refcounts != NULL)
5474 if (local_got_refcounts[r_symndx] > 0)
5475 local_got_refcounts[r_symndx] -= 1;
5477 break;
5479 case R_ARM_TLS_LDM32:
5480 elf32_arm_hash_table (info)->tls_ldm_got.refcount -= 1;
5481 break;
5483 case R_ARM_ABS32:
5484 case R_ARM_REL32:
5485 case R_ARM_PC24:
5486 case R_ARM_PLT32:
5487 case R_ARM_CALL:
5488 case R_ARM_JUMP24:
5489 case R_ARM_PREL31:
5490 case R_ARM_THM_CALL:
5491 /* Should the interworking branches be here also? */
5493 if (h != NULL)
5495 struct elf32_arm_link_hash_entry *eh;
5496 struct elf32_arm_relocs_copied **pp;
5497 struct elf32_arm_relocs_copied *p;
5499 eh = (struct elf32_arm_link_hash_entry *) h;
5501 if (h->plt.refcount > 0)
5503 h->plt.refcount -= 1;
5504 if (ELF32_R_TYPE (rel->r_info) == R_ARM_THM_CALL)
5505 eh->plt_thumb_refcount--;
5508 if (r_type == R_ARM_ABS32
5509 || r_type == R_ARM_REL32)
5511 for (pp = &eh->relocs_copied; (p = *pp) != NULL;
5512 pp = &p->next)
5513 if (p->section == sec)
5515 p->count -= 1;
5516 if (ELF32_R_TYPE (rel->r_info) == R_ARM_REL32)
5517 p->pc_count -= 1;
5518 if (p->count == 0)
5519 *pp = p->next;
5520 break;
5524 break;
5526 default:
5527 break;
5531 return TRUE;
5534 /* Look through the relocs for a section during the first phase. */
5536 static bfd_boolean
5537 elf32_arm_check_relocs (bfd *abfd, struct bfd_link_info *info,
5538 asection *sec, const Elf_Internal_Rela *relocs)
5540 Elf_Internal_Shdr *symtab_hdr;
5541 struct elf_link_hash_entry **sym_hashes;
5542 struct elf_link_hash_entry **sym_hashes_end;
5543 const Elf_Internal_Rela *rel;
5544 const Elf_Internal_Rela *rel_end;
5545 bfd *dynobj;
5546 asection *sreloc;
5547 bfd_vma *local_got_offsets;
5548 struct elf32_arm_link_hash_table *htab;
5550 if (info->relocatable)
5551 return TRUE;
5553 htab = elf32_arm_hash_table (info);
5554 sreloc = NULL;
5556 /* Create dynamic sections for relocatable executables so that we can
5557 copy relocations. */
5558 if (htab->root.is_relocatable_executable
5559 && ! htab->root.dynamic_sections_created)
5561 if (! _bfd_elf_link_create_dynamic_sections (abfd, info))
5562 return FALSE;
5565 dynobj = elf_hash_table (info)->dynobj;
5566 local_got_offsets = elf_local_got_offsets (abfd);
5568 symtab_hdr = &elf_tdata (abfd)->symtab_hdr;
5569 sym_hashes = elf_sym_hashes (abfd);
5570 sym_hashes_end = sym_hashes
5571 + symtab_hdr->sh_size / sizeof (Elf32_External_Sym);
5573 if (!elf_bad_symtab (abfd))
5574 sym_hashes_end -= symtab_hdr->sh_info;
5576 rel_end = relocs + sec->reloc_count;
5577 for (rel = relocs; rel < rel_end; rel++)
5579 struct elf_link_hash_entry *h;
5580 struct elf32_arm_link_hash_entry *eh;
5581 unsigned long r_symndx;
5582 int r_type;
5584 r_symndx = ELF32_R_SYM (rel->r_info);
5585 r_type = ELF32_R_TYPE (rel->r_info);
5586 r_type = arm_real_reloc_type (htab, r_type);
5588 if (r_symndx >= NUM_SHDR_ENTRIES (symtab_hdr))
5590 (*_bfd_error_handler) (_("%B: bad symbol index: %d"), abfd,
5591 r_symndx);
5592 return FALSE;
5595 if (r_symndx < symtab_hdr->sh_info)
5596 h = NULL;
5597 else
5599 h = sym_hashes[r_symndx - symtab_hdr->sh_info];
5600 while (h->root.type == bfd_link_hash_indirect
5601 || h->root.type == bfd_link_hash_warning)
5602 h = (struct elf_link_hash_entry *) h->root.u.i.link;
5605 eh = (struct elf32_arm_link_hash_entry *) h;
5607 switch (r_type)
5609 case R_ARM_GOT32:
5610 case R_ARM_GOT_PREL:
5611 case R_ARM_TLS_GD32:
5612 case R_ARM_TLS_IE32:
5613 /* This symbol requires a global offset table entry. */
5615 int tls_type, old_tls_type;
5617 switch (r_type)
5619 case R_ARM_TLS_GD32: tls_type = GOT_TLS_GD; break;
5620 case R_ARM_TLS_IE32: tls_type = GOT_TLS_IE; break;
5621 default: tls_type = GOT_NORMAL; break;
5624 if (h != NULL)
5626 h->got.refcount++;
5627 old_tls_type = elf32_arm_hash_entry (h)->tls_type;
5629 else
5631 bfd_signed_vma *local_got_refcounts;
5633 /* This is a global offset table entry for a local symbol. */
5634 local_got_refcounts = elf_local_got_refcounts (abfd);
5635 if (local_got_refcounts == NULL)
5637 bfd_size_type size;
5639 size = symtab_hdr->sh_info;
5640 size *= (sizeof (bfd_signed_vma) + sizeof(char));
5641 local_got_refcounts = bfd_zalloc (abfd, size);
5642 if (local_got_refcounts == NULL)
5643 return FALSE;
5644 elf_local_got_refcounts (abfd) = local_got_refcounts;
5645 elf32_arm_local_got_tls_type (abfd)
5646 = (char *) (local_got_refcounts + symtab_hdr->sh_info);
5648 local_got_refcounts[r_symndx] += 1;
5649 old_tls_type = elf32_arm_local_got_tls_type (abfd) [r_symndx];
5652 /* We will already have issued an error message if there is a
5653 TLS / non-TLS mismatch, based on the symbol type. We don't
5654 support any linker relaxations. So just combine any TLS
5655 types needed. */
5656 if (old_tls_type != GOT_UNKNOWN && old_tls_type != GOT_NORMAL
5657 && tls_type != GOT_NORMAL)
5658 tls_type |= old_tls_type;
5660 if (old_tls_type != tls_type)
5662 if (h != NULL)
5663 elf32_arm_hash_entry (h)->tls_type = tls_type;
5664 else
5665 elf32_arm_local_got_tls_type (abfd) [r_symndx] = tls_type;
5668 /* Fall through */
5670 case R_ARM_TLS_LDM32:
5671 if (r_type == R_ARM_TLS_LDM32)
5672 htab->tls_ldm_got.refcount++;
5673 /* Fall through */
5675 case R_ARM_GOTOFF32:
5676 case R_ARM_GOTPC:
5677 if (htab->sgot == NULL)
5679 if (htab->root.dynobj == NULL)
5680 htab->root.dynobj = abfd;
5681 if (!create_got_section (htab->root.dynobj, info))
5682 return FALSE;
5684 break;
5686 case R_ARM_ABS32:
5687 case R_ARM_REL32:
5688 case R_ARM_PC24:
5689 case R_ARM_PLT32:
5690 case R_ARM_CALL:
5691 case R_ARM_JUMP24:
5692 case R_ARM_PREL31:
5693 case R_ARM_THM_CALL:
5694 /* Should the interworking branches be listed here? */
5695 if (h != NULL)
5697 /* If this reloc is in a read-only section, we might
5698 need a copy reloc. We can't check reliably at this
5699 stage whether the section is read-only, as input
5700 sections have not yet been mapped to output sections.
5701 Tentatively set the flag for now, and correct in
5702 adjust_dynamic_symbol. */
5703 if (!info->shared)
5704 h->non_got_ref = 1;
5706 /* We may need a .plt entry if the function this reloc
5707 refers to is in a different object. We can't tell for
5708 sure yet, because something later might force the
5709 symbol local. */
5710 if (r_type == R_ARM_PC24
5711 || r_type == R_ARM_CALL
5712 || r_type == R_ARM_JUMP24
5713 || r_type == R_ARM_PREL31
5714 || r_type == R_ARM_PLT32
5715 || r_type == R_ARM_THM_CALL)
5716 h->needs_plt = 1;
5718 /* If we create a PLT entry, this relocation will reference
5719 it, even if it's an ABS32 relocation. */
5720 h->plt.refcount += 1;
5722 if (r_type == R_ARM_THM_CALL)
5723 eh->plt_thumb_refcount += 1;
5726 /* If we are creating a shared library or relocatable executable,
5727 and this is a reloc against a global symbol, or a non PC
5728 relative reloc against a local symbol, then we need to copy
5729 the reloc into the shared library. However, if we are linking
5730 with -Bsymbolic, we do not need to copy a reloc against a
5731 global symbol which is defined in an object we are
5732 including in the link (i.e., DEF_REGULAR is set). At
5733 this point we have not seen all the input files, so it is
5734 possible that DEF_REGULAR is not set now but will be set
5735 later (it is never cleared). We account for that
5736 possibility below by storing information in the
5737 relocs_copied field of the hash table entry. */
5738 if ((info->shared || htab->root.is_relocatable_executable)
5739 && (sec->flags & SEC_ALLOC) != 0
5740 && (r_type == R_ARM_ABS32
5741 || (h != NULL && ! h->needs_plt
5742 && (! info->symbolic || ! h->def_regular))))
5744 struct elf32_arm_relocs_copied *p, **head;
5746 /* When creating a shared object, we must copy these
5747 reloc types into the output file. We create a reloc
5748 section in dynobj and make room for this reloc. */
5749 if (sreloc == NULL)
5751 const char * name;
5753 name = (bfd_elf_string_from_elf_section
5754 (abfd,
5755 elf_elfheader (abfd)->e_shstrndx,
5756 elf_section_data (sec)->rel_hdr.sh_name));
5757 if (name == NULL)
5758 return FALSE;
5760 BFD_ASSERT (strncmp (name, ".rel", 4) == 0
5761 && strcmp (bfd_get_section_name (abfd, sec),
5762 name + 4) == 0);
5764 sreloc = bfd_get_section_by_name (dynobj, name);
5765 if (sreloc == NULL)
5767 flagword flags;
5769 flags = (SEC_HAS_CONTENTS | SEC_READONLY
5770 | SEC_IN_MEMORY | SEC_LINKER_CREATED);
5771 if ((sec->flags & SEC_ALLOC) != 0
5772 /* BPABI objects never have dynamic
5773 relocations mapped. */
5774 && !htab->symbian_p)
5775 flags |= SEC_ALLOC | SEC_LOAD;
5776 sreloc = bfd_make_section_with_flags (dynobj,
5777 name,
5778 flags);
5779 if (sreloc == NULL
5780 || ! bfd_set_section_alignment (dynobj, sreloc, 2))
5781 return FALSE;
5784 elf_section_data (sec)->sreloc = sreloc;
5787 /* If this is a global symbol, we count the number of
5788 relocations we need for this symbol. */
5789 if (h != NULL)
5791 head = &((struct elf32_arm_link_hash_entry *) h)->relocs_copied;
5793 else
5795 /* Track dynamic relocs needed for local syms too.
5796 We really need local syms available to do this
5797 easily. Oh well. */
5799 asection *s;
5800 void *vpp;
5802 s = bfd_section_from_r_symndx (abfd, &htab->sym_sec,
5803 sec, r_symndx);
5804 if (s == NULL)
5805 return FALSE;
5807 vpp = &elf_section_data (s)->local_dynrel;
5808 head = (struct elf32_arm_relocs_copied **) vpp;
5811 p = *head;
5812 if (p == NULL || p->section != sec)
5814 bfd_size_type amt = sizeof *p;
5816 p = bfd_alloc (htab->root.dynobj, amt);
5817 if (p == NULL)
5818 return FALSE;
5819 p->next = *head;
5820 *head = p;
5821 p->section = sec;
5822 p->count = 0;
5823 p->pc_count = 0;
5826 if (r_type == R_ARM_REL32)
5827 p->pc_count += 1;
5828 p->count += 1;
5830 break;
5832 /* This relocation describes the C++ object vtable hierarchy.
5833 Reconstruct it for later use during GC. */
5834 case R_ARM_GNU_VTINHERIT:
5835 if (!bfd_elf_gc_record_vtinherit (abfd, sec, h, rel->r_offset))
5836 return FALSE;
5837 break;
5839 /* This relocation describes which C++ vtable entries are actually
5840 used. Record for later use during GC. */
5841 case R_ARM_GNU_VTENTRY:
5842 if (!bfd_elf_gc_record_vtentry (abfd, sec, h, rel->r_offset))
5843 return FALSE;
5844 break;
5848 return TRUE;
5851 /* Treat mapping symbols as special target symbols. */
5853 static bfd_boolean
5854 elf32_arm_is_target_special_symbol (bfd * abfd ATTRIBUTE_UNUSED, asymbol * sym)
5856 return bfd_is_arm_mapping_symbol_name (sym->name);
5859 /* This is a copy of elf_find_function() from elf.c except that
5860 ARM mapping symbols are ignored when looking for function names
5861 and STT_ARM_TFUNC is considered to a function type. */
5863 static bfd_boolean
5864 arm_elf_find_function (bfd * abfd ATTRIBUTE_UNUSED,
5865 asection * section,
5866 asymbol ** symbols,
5867 bfd_vma offset,
5868 const char ** filename_ptr,
5869 const char ** functionname_ptr)
5871 const char * filename = NULL;
5872 asymbol * func = NULL;
5873 bfd_vma low_func = 0;
5874 asymbol ** p;
5876 for (p = symbols; *p != NULL; p++)
5878 elf_symbol_type *q;
5880 q = (elf_symbol_type *) *p;
5882 switch (ELF_ST_TYPE (q->internal_elf_sym.st_info))
5884 default:
5885 break;
5886 case STT_FILE:
5887 filename = bfd_asymbol_name (&q->symbol);
5888 break;
5889 case STT_FUNC:
5890 case STT_ARM_TFUNC:
5891 case STT_NOTYPE:
5892 /* Skip $a and $t symbols. */
5893 if ((q->symbol.flags & BSF_LOCAL)
5894 && bfd_is_arm_mapping_symbol_name (q->symbol.name))
5895 continue;
5896 /* Fall through. */
5897 if (bfd_get_section (&q->symbol) == section
5898 && q->symbol.value >= low_func
5899 && q->symbol.value <= offset)
5901 func = (asymbol *) q;
5902 low_func = q->symbol.value;
5904 break;
5908 if (func == NULL)
5909 return FALSE;
5911 if (filename_ptr)
5912 *filename_ptr = filename;
5913 if (functionname_ptr)
5914 *functionname_ptr = bfd_asymbol_name (func);
5916 return TRUE;
5920 /* Find the nearest line to a particular section and offset, for error
5921 reporting. This code is a duplicate of the code in elf.c, except
5922 that it uses arm_elf_find_function. */
5924 static bfd_boolean
5925 elf32_arm_find_nearest_line (bfd * abfd,
5926 asection * section,
5927 asymbol ** symbols,
5928 bfd_vma offset,
5929 const char ** filename_ptr,
5930 const char ** functionname_ptr,
5931 unsigned int * line_ptr)
5933 bfd_boolean found = FALSE;
5935 /* We skip _bfd_dwarf1_find_nearest_line since no known ARM toolchain uses it. */
5937 if (_bfd_dwarf2_find_nearest_line (abfd, section, symbols, offset,
5938 filename_ptr, functionname_ptr,
5939 line_ptr, 0,
5940 & elf_tdata (abfd)->dwarf2_find_line_info))
5942 if (!*functionname_ptr)
5943 arm_elf_find_function (abfd, section, symbols, offset,
5944 *filename_ptr ? NULL : filename_ptr,
5945 functionname_ptr);
5947 return TRUE;
5950 if (! _bfd_stab_section_find_nearest_line (abfd, symbols, section, offset,
5951 & found, filename_ptr,
5952 functionname_ptr, line_ptr,
5953 & elf_tdata (abfd)->line_info))
5954 return FALSE;
5956 if (found && (*functionname_ptr || *line_ptr))
5957 return TRUE;
5959 if (symbols == NULL)
5960 return FALSE;
5962 if (! arm_elf_find_function (abfd, section, symbols, offset,
5963 filename_ptr, functionname_ptr))
5964 return FALSE;
5966 *line_ptr = 0;
5967 return TRUE;
5970 static bfd_boolean
5971 elf32_arm_find_inliner_info (bfd * abfd,
5972 const char ** filename_ptr,
5973 const char ** functionname_ptr,
5974 unsigned int * line_ptr)
5976 bfd_boolean found;
5977 found = _bfd_dwarf2_find_inliner_info (abfd, filename_ptr,
5978 functionname_ptr, line_ptr,
5979 & elf_tdata (abfd)->dwarf2_find_line_info);
5980 return found;
5983 /* Adjust a symbol defined by a dynamic object and referenced by a
5984 regular object. The current definition is in some section of the
5985 dynamic object, but we're not including those sections. We have to
5986 change the definition to something the rest of the link can
5987 understand. */
5989 static bfd_boolean
5990 elf32_arm_adjust_dynamic_symbol (struct bfd_link_info * info,
5991 struct elf_link_hash_entry * h)
5993 bfd * dynobj;
5994 asection * s;
5995 unsigned int power_of_two;
5996 struct elf32_arm_link_hash_entry * eh;
5997 struct elf32_arm_link_hash_table *globals;
5999 globals = elf32_arm_hash_table (info);
6000 dynobj = elf_hash_table (info)->dynobj;
6002 /* Make sure we know what is going on here. */
6003 BFD_ASSERT (dynobj != NULL
6004 && (h->needs_plt
6005 || h->u.weakdef != NULL
6006 || (h->def_dynamic
6007 && h->ref_regular
6008 && !h->def_regular)));
6010 eh = (struct elf32_arm_link_hash_entry *) h;
6012 /* If this is a function, put it in the procedure linkage table. We
6013 will fill in the contents of the procedure linkage table later,
6014 when we know the address of the .got section. */
6015 if (h->type == STT_FUNC || h->type == STT_ARM_TFUNC
6016 || h->needs_plt)
6018 if (h->plt.refcount <= 0
6019 || SYMBOL_CALLS_LOCAL (info, h)
6020 || (ELF_ST_VISIBILITY (h->other) != STV_DEFAULT
6021 && h->root.type == bfd_link_hash_undefweak))
6023 /* This case can occur if we saw a PLT32 reloc in an input
6024 file, but the symbol was never referred to by a dynamic
6025 object, or if all references were garbage collected. In
6026 such a case, we don't actually need to build a procedure
6027 linkage table, and we can just do a PC24 reloc instead. */
6028 h->plt.offset = (bfd_vma) -1;
6029 eh->plt_thumb_refcount = 0;
6030 h->needs_plt = 0;
6033 return TRUE;
6035 else
6037 /* It's possible that we incorrectly decided a .plt reloc was
6038 needed for an R_ARM_PC24 or similar reloc to a non-function sym
6039 in check_relocs. We can't decide accurately between function
6040 and non-function syms in check-relocs; Objects loaded later in
6041 the link may change h->type. So fix it now. */
6042 h->plt.offset = (bfd_vma) -1;
6043 eh->plt_thumb_refcount = 0;
6046 /* If this is a weak symbol, and there is a real definition, the
6047 processor independent code will have arranged for us to see the
6048 real definition first, and we can just use the same value. */
6049 if (h->u.weakdef != NULL)
6051 BFD_ASSERT (h->u.weakdef->root.type == bfd_link_hash_defined
6052 || h->u.weakdef->root.type == bfd_link_hash_defweak);
6053 h->root.u.def.section = h->u.weakdef->root.u.def.section;
6054 h->root.u.def.value = h->u.weakdef->root.u.def.value;
6055 return TRUE;
6058 /* If there are no non-GOT references, we do not need a copy
6059 relocation. */
6060 if (!h->non_got_ref)
6061 return TRUE;
6063 /* This is a reference to a symbol defined by a dynamic object which
6064 is not a function. */
6066 /* If we are creating a shared library, we must presume that the
6067 only references to the symbol are via the global offset table.
6068 For such cases we need not do anything here; the relocations will
6069 be handled correctly by relocate_section. Relocatable executables
6070 can reference data in shared objects directly, so we don't need to
6071 do anything here. */
6072 if (info->shared || globals->root.is_relocatable_executable)
6073 return TRUE;
6075 if (h->size == 0)
6077 (*_bfd_error_handler) (_("dynamic variable `%s' is zero size"),
6078 h->root.root.string);
6079 return TRUE;
6082 /* We must allocate the symbol in our .dynbss section, which will
6083 become part of the .bss section of the executable. There will be
6084 an entry for this symbol in the .dynsym section. The dynamic
6085 object will contain position independent code, so all references
6086 from the dynamic object to this symbol will go through the global
6087 offset table. The dynamic linker will use the .dynsym entry to
6088 determine the address it must put in the global offset table, so
6089 both the dynamic object and the regular object will refer to the
6090 same memory location for the variable. */
6091 s = bfd_get_section_by_name (dynobj, ".dynbss");
6092 BFD_ASSERT (s != NULL);
6094 /* We must generate a R_ARM_COPY reloc to tell the dynamic linker to
6095 copy the initial value out of the dynamic object and into the
6096 runtime process image. We need to remember the offset into the
6097 .rel.bss section we are going to use. */
6098 if ((h->root.u.def.section->flags & SEC_ALLOC) != 0)
6100 asection *srel;
6102 srel = bfd_get_section_by_name (dynobj, ".rel.bss");
6103 BFD_ASSERT (srel != NULL);
6104 srel->size += sizeof (Elf32_External_Rel);
6105 h->needs_copy = 1;
6108 /* We need to figure out the alignment required for this symbol. I
6109 have no idea how ELF linkers handle this. */
6110 power_of_two = bfd_log2 (h->size);
6111 if (power_of_two > 3)
6112 power_of_two = 3;
6114 /* Apply the required alignment. */
6115 s->size = BFD_ALIGN (s->size, (bfd_size_type) (1 << power_of_two));
6116 if (power_of_two > bfd_get_section_alignment (dynobj, s))
6118 if (! bfd_set_section_alignment (dynobj, s, power_of_two))
6119 return FALSE;
6122 /* Define the symbol as being at this point in the section. */
6123 h->root.u.def.section = s;
6124 h->root.u.def.value = s->size;
6126 /* Increment the section size to make room for the symbol. */
6127 s->size += h->size;
6129 return TRUE;
6132 /* Allocate space in .plt, .got and associated reloc sections for
6133 dynamic relocs. */
6135 static bfd_boolean
6136 allocate_dynrelocs (struct elf_link_hash_entry *h, void * inf)
6138 struct bfd_link_info *info;
6139 struct elf32_arm_link_hash_table *htab;
6140 struct elf32_arm_link_hash_entry *eh;
6141 struct elf32_arm_relocs_copied *p;
6143 eh = (struct elf32_arm_link_hash_entry *) h;
6145 if (h->root.type == bfd_link_hash_indirect)
6146 return TRUE;
6148 if (h->root.type == bfd_link_hash_warning)
6149 /* When warning symbols are created, they **replace** the "real"
6150 entry in the hash table, thus we never get to see the real
6151 symbol in a hash traversal. So look at it now. */
6152 h = (struct elf_link_hash_entry *) h->root.u.i.link;
6154 info = (struct bfd_link_info *) inf;
6155 htab = elf32_arm_hash_table (info);
6157 if (htab->root.dynamic_sections_created
6158 && h->plt.refcount > 0)
6160 /* Make sure this symbol is output as a dynamic symbol.
6161 Undefined weak syms won't yet be marked as dynamic. */
6162 if (h->dynindx == -1
6163 && !h->forced_local)
6165 if (! bfd_elf_link_record_dynamic_symbol (info, h))
6166 return FALSE;
6169 if (info->shared
6170 || WILL_CALL_FINISH_DYNAMIC_SYMBOL (1, 0, h))
6172 asection *s = htab->splt;
6174 /* If this is the first .plt entry, make room for the special
6175 first entry. */
6176 if (s->size == 0)
6177 s->size += htab->plt_header_size;
6179 h->plt.offset = s->size;
6181 /* If we will insert a Thumb trampoline before this PLT, leave room
6182 for it. */
6183 if (!htab->use_blx && eh->plt_thumb_refcount > 0)
6185 h->plt.offset += PLT_THUMB_STUB_SIZE;
6186 s->size += PLT_THUMB_STUB_SIZE;
6189 /* If this symbol is not defined in a regular file, and we are
6190 not generating a shared library, then set the symbol to this
6191 location in the .plt. This is required to make function
6192 pointers compare as equal between the normal executable and
6193 the shared library. */
6194 if (! info->shared
6195 && !h->def_regular)
6197 h->root.u.def.section = s;
6198 h->root.u.def.value = h->plt.offset;
6200 /* Make sure the function is not marked as Thumb, in case
6201 it is the target of an ABS32 relocation, which will
6202 point to the PLT entry. */
6203 if (ELF_ST_TYPE (h->type) == STT_ARM_TFUNC)
6204 h->type = ELF_ST_INFO (ELF_ST_BIND (h->type), STT_FUNC);
6207 /* Make room for this entry. */
6208 s->size += htab->plt_entry_size;
6210 if (!htab->symbian_p)
6212 /* We also need to make an entry in the .got.plt section, which
6213 will be placed in the .got section by the linker script. */
6214 eh->plt_got_offset = htab->sgotplt->size;
6215 htab->sgotplt->size += 4;
6218 /* We also need to make an entry in the .rel.plt section. */
6219 htab->srelplt->size += sizeof (Elf32_External_Rel);
6221 else
6223 h->plt.offset = (bfd_vma) -1;
6224 h->needs_plt = 0;
6227 else
6229 h->plt.offset = (bfd_vma) -1;
6230 h->needs_plt = 0;
6233 if (h->got.refcount > 0)
6235 asection *s;
6236 bfd_boolean dyn;
6237 int tls_type = elf32_arm_hash_entry (h)->tls_type;
6238 int indx;
6240 /* Make sure this symbol is output as a dynamic symbol.
6241 Undefined weak syms won't yet be marked as dynamic. */
6242 if (h->dynindx == -1
6243 && !h->forced_local)
6245 if (! bfd_elf_link_record_dynamic_symbol (info, h))
6246 return FALSE;
6249 if (!htab->symbian_p)
6251 s = htab->sgot;
6252 h->got.offset = s->size;
6254 if (tls_type == GOT_UNKNOWN)
6255 abort ();
6257 if (tls_type == GOT_NORMAL)
6258 /* Non-TLS symbols need one GOT slot. */
6259 s->size += 4;
6260 else
6262 if (tls_type & GOT_TLS_GD)
6263 /* R_ARM_TLS_GD32 needs 2 consecutive GOT slots. */
6264 s->size += 8;
6265 if (tls_type & GOT_TLS_IE)
6266 /* R_ARM_TLS_IE32 needs one GOT slot. */
6267 s->size += 4;
6270 dyn = htab->root.dynamic_sections_created;
6272 indx = 0;
6273 if (WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn, info->shared, h)
6274 && (!info->shared
6275 || !SYMBOL_REFERENCES_LOCAL (info, h)))
6276 indx = h->dynindx;
6278 if (tls_type != GOT_NORMAL
6279 && (info->shared || indx != 0)
6280 && (ELF_ST_VISIBILITY (h->other) == STV_DEFAULT
6281 || h->root.type != bfd_link_hash_undefweak))
6283 if (tls_type & GOT_TLS_IE)
6284 htab->srelgot->size += sizeof (Elf32_External_Rel);
6286 if (tls_type & GOT_TLS_GD)
6287 htab->srelgot->size += sizeof (Elf32_External_Rel);
6289 if ((tls_type & GOT_TLS_GD) && indx != 0)
6290 htab->srelgot->size += sizeof (Elf32_External_Rel);
6292 else if ((ELF_ST_VISIBILITY (h->other) == STV_DEFAULT
6293 || h->root.type != bfd_link_hash_undefweak)
6294 && (info->shared
6295 || WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn, 0, h)))
6296 htab->srelgot->size += sizeof (Elf32_External_Rel);
6299 else
6300 h->got.offset = (bfd_vma) -1;
6302 if (eh->relocs_copied == NULL)
6303 return TRUE;
6305 /* In the shared -Bsymbolic case, discard space allocated for
6306 dynamic pc-relative relocs against symbols which turn out to be
6307 defined in regular objects. For the normal shared case, discard
6308 space for pc-relative relocs that have become local due to symbol
6309 visibility changes. */
6311 if (info->shared || htab->root.is_relocatable_executable)
6313 /* The only reloc that uses pc_count is R_ARM_REL32, which will
6314 appear on something like ".long foo - .". We want calls to
6315 protected symbols to resolve directly to the function rather
6316 than going via the plt. If people want function pointer
6317 comparisons to work as expected then they should avoid
6318 writing assembly like ".long foo - .". */
6319 if (SYMBOL_CALLS_LOCAL (info, h))
6321 struct elf32_arm_relocs_copied **pp;
6323 for (pp = &eh->relocs_copied; (p = *pp) != NULL; )
6325 p->count -= p->pc_count;
6326 p->pc_count = 0;
6327 if (p->count == 0)
6328 *pp = p->next;
6329 else
6330 pp = &p->next;
6334 /* Also discard relocs on undefined weak syms with non-default
6335 visibility. */
6336 if (eh->relocs_copied != NULL
6337 && h->root.type == bfd_link_hash_undefweak)
6339 if (ELF_ST_VISIBILITY (h->other) != STV_DEFAULT)
6340 eh->relocs_copied = NULL;
6342 /* Make sure undefined weak symbols are output as a dynamic
6343 symbol in PIEs. */
6344 else if (h->dynindx == -1
6345 && !h->forced_local)
6347 if (! bfd_elf_link_record_dynamic_symbol (info, h))
6348 return FALSE;
6352 else if (htab->root.is_relocatable_executable && h->dynindx == -1
6353 && h->root.type == bfd_link_hash_new)
6355 /* Output absolute symbols so that we can create relocations
6356 against them. For normal symbols we output a relocation
6357 against the section that contains them. */
6358 if (! bfd_elf_link_record_dynamic_symbol (info, h))
6359 return FALSE;
6363 else
6365 /* For the non-shared case, discard space for relocs against
6366 symbols which turn out to need copy relocs or are not
6367 dynamic. */
6369 if (!h->non_got_ref
6370 && ((h->def_dynamic
6371 && !h->def_regular)
6372 || (htab->root.dynamic_sections_created
6373 && (h->root.type == bfd_link_hash_undefweak
6374 || h->root.type == bfd_link_hash_undefined))))
6376 /* Make sure this symbol is output as a dynamic symbol.
6377 Undefined weak syms won't yet be marked as dynamic. */
6378 if (h->dynindx == -1
6379 && !h->forced_local)
6381 if (! bfd_elf_link_record_dynamic_symbol (info, h))
6382 return FALSE;
6385 /* If that succeeded, we know we'll be keeping all the
6386 relocs. */
6387 if (h->dynindx != -1)
6388 goto keep;
6391 eh->relocs_copied = NULL;
6393 keep: ;
6396 /* Finally, allocate space. */
6397 for (p = eh->relocs_copied; p != NULL; p = p->next)
6399 asection *sreloc = elf_section_data (p->section)->sreloc;
6400 sreloc->size += p->count * sizeof (Elf32_External_Rel);
6403 return TRUE;
6406 /* Find any dynamic relocs that apply to read-only sections. */
6408 static bfd_boolean
6409 elf32_arm_readonly_dynrelocs (struct elf_link_hash_entry *h, PTR inf)
6411 struct elf32_arm_link_hash_entry *eh;
6412 struct elf32_arm_relocs_copied *p;
6414 if (h->root.type == bfd_link_hash_warning)
6415 h = (struct elf_link_hash_entry *) h->root.u.i.link;
6417 eh = (struct elf32_arm_link_hash_entry *) h;
6418 for (p = eh->relocs_copied; p != NULL; p = p->next)
6420 asection *s = p->section;
6422 if (s != NULL && (s->flags & SEC_READONLY) != 0)
6424 struct bfd_link_info *info = (struct bfd_link_info *) inf;
6426 info->flags |= DF_TEXTREL;
6428 /* Not an error, just cut short the traversal. */
6429 return FALSE;
6432 return TRUE;
6435 /* Set the sizes of the dynamic sections. */
6437 static bfd_boolean
6438 elf32_arm_size_dynamic_sections (bfd * output_bfd ATTRIBUTE_UNUSED,
6439 struct bfd_link_info * info)
6441 bfd * dynobj;
6442 asection * s;
6443 bfd_boolean plt;
6444 bfd_boolean relocs;
6445 bfd *ibfd;
6446 struct elf32_arm_link_hash_table *htab;
6448 htab = elf32_arm_hash_table (info);
6449 dynobj = elf_hash_table (info)->dynobj;
6450 BFD_ASSERT (dynobj != NULL);
6451 check_use_blx (htab);
6453 if (elf_hash_table (info)->dynamic_sections_created)
6455 /* Set the contents of the .interp section to the interpreter. */
6456 if (info->executable)
6458 s = bfd_get_section_by_name (dynobj, ".interp");
6459 BFD_ASSERT (s != NULL);
6460 s->size = sizeof ELF_DYNAMIC_INTERPRETER;
6461 s->contents = (unsigned char *) ELF_DYNAMIC_INTERPRETER;
6465 /* Set up .got offsets for local syms, and space for local dynamic
6466 relocs. */
6467 for (ibfd = info->input_bfds; ibfd != NULL; ibfd = ibfd->link_next)
6469 bfd_signed_vma *local_got;
6470 bfd_signed_vma *end_local_got;
6471 char *local_tls_type;
6472 bfd_size_type locsymcount;
6473 Elf_Internal_Shdr *symtab_hdr;
6474 asection *srel;
6476 if (bfd_get_flavour (ibfd) != bfd_target_elf_flavour)
6477 continue;
6479 for (s = ibfd->sections; s != NULL; s = s->next)
6481 struct elf32_arm_relocs_copied *p;
6483 for (p = elf_section_data (s)->local_dynrel; p != NULL; p = p->next)
6485 if (!bfd_is_abs_section (p->section)
6486 && bfd_is_abs_section (p->section->output_section))
6488 /* Input section has been discarded, either because
6489 it is a copy of a linkonce section or due to
6490 linker script /DISCARD/, so we'll be discarding
6491 the relocs too. */
6493 else if (p->count != 0)
6495 srel = elf_section_data (p->section)->sreloc;
6496 srel->size += p->count * sizeof (Elf32_External_Rel);
6497 if ((p->section->output_section->flags & SEC_READONLY) != 0)
6498 info->flags |= DF_TEXTREL;
6503 local_got = elf_local_got_refcounts (ibfd);
6504 if (!local_got)
6505 continue;
6507 symtab_hdr = &elf_tdata (ibfd)->symtab_hdr;
6508 locsymcount = symtab_hdr->sh_info;
6509 end_local_got = local_got + locsymcount;
6510 local_tls_type = elf32_arm_local_got_tls_type (ibfd);
6511 s = htab->sgot;
6512 srel = htab->srelgot;
6513 for (; local_got < end_local_got; ++local_got, ++local_tls_type)
6515 if (*local_got > 0)
6517 *local_got = s->size;
6518 if (*local_tls_type & GOT_TLS_GD)
6519 /* TLS_GD relocs need an 8-byte structure in the GOT. */
6520 s->size += 8;
6521 if (*local_tls_type & GOT_TLS_IE)
6522 s->size += 4;
6523 if (*local_tls_type == GOT_NORMAL)
6524 s->size += 4;
6526 if (info->shared || *local_tls_type == GOT_TLS_GD)
6527 srel->size += sizeof (Elf32_External_Rel);
6529 else
6530 *local_got = (bfd_vma) -1;
6534 if (htab->tls_ldm_got.refcount > 0)
6536 /* Allocate two GOT entries and one dynamic relocation (if necessary)
6537 for R_ARM_TLS_LDM32 relocations. */
6538 htab->tls_ldm_got.offset = htab->sgot->size;
6539 htab->sgot->size += 8;
6540 if (info->shared)
6541 htab->srelgot->size += sizeof (Elf32_External_Rel);
6543 else
6544 htab->tls_ldm_got.offset = -1;
6546 /* Allocate global sym .plt and .got entries, and space for global
6547 sym dynamic relocs. */
6548 elf_link_hash_traverse (& htab->root, allocate_dynrelocs, info);
6550 /* The check_relocs and adjust_dynamic_symbol entry points have
6551 determined the sizes of the various dynamic sections. Allocate
6552 memory for them. */
6553 plt = FALSE;
6554 relocs = FALSE;
6555 for (s = dynobj->sections; s != NULL; s = s->next)
6557 const char * name;
6559 if ((s->flags & SEC_LINKER_CREATED) == 0)
6560 continue;
6562 /* It's OK to base decisions on the section name, because none
6563 of the dynobj section names depend upon the input files. */
6564 name = bfd_get_section_name (dynobj, s);
6566 if (strcmp (name, ".plt") == 0)
6568 /* Remember whether there is a PLT. */
6569 plt = s->size != 0;
6571 else if (strncmp (name, ".rel", 4) == 0)
6573 if (s->size != 0)
6575 /* Remember whether there are any reloc sections other
6576 than .rel.plt. */
6577 if (strcmp (name, ".rel.plt") != 0)
6578 relocs = TRUE;
6580 /* We use the reloc_count field as a counter if we need
6581 to copy relocs into the output file. */
6582 s->reloc_count = 0;
6585 else if (strncmp (name, ".got", 4) != 0
6586 && strcmp (name, ".dynbss") != 0)
6588 /* It's not one of our sections, so don't allocate space. */
6589 continue;
6592 if (s->size == 0)
6594 /* If we don't need this section, strip it from the
6595 output file. This is mostly to handle .rel.bss and
6596 .rel.plt. We must create both sections in
6597 create_dynamic_sections, because they must be created
6598 before the linker maps input sections to output
6599 sections. The linker does that before
6600 adjust_dynamic_symbol is called, and it is that
6601 function which decides whether anything needs to go
6602 into these sections. */
6603 s->flags |= SEC_EXCLUDE;
6604 continue;
6607 if ((s->flags & SEC_HAS_CONTENTS) == 0)
6608 continue;
6610 /* Allocate memory for the section contents. */
6611 s->contents = (bfd_byte *) bfd_zalloc (dynobj, s->size);
6612 if (s->contents == NULL)
6613 return FALSE;
6616 if (elf_hash_table (info)->dynamic_sections_created)
6618 /* Add some entries to the .dynamic section. We fill in the
6619 values later, in elf32_arm_finish_dynamic_sections, but we
6620 must add the entries now so that we get the correct size for
6621 the .dynamic section. The DT_DEBUG entry is filled in by the
6622 dynamic linker and used by the debugger. */
6623 #define add_dynamic_entry(TAG, VAL) \
6624 _bfd_elf_add_dynamic_entry (info, TAG, VAL)
6626 if (info->executable)
6628 if (!add_dynamic_entry (DT_DEBUG, 0))
6629 return FALSE;
6632 if (plt)
6634 if ( !add_dynamic_entry (DT_PLTGOT, 0)
6635 || !add_dynamic_entry (DT_PLTRELSZ, 0)
6636 || !add_dynamic_entry (DT_PLTREL, DT_REL)
6637 || !add_dynamic_entry (DT_JMPREL, 0))
6638 return FALSE;
6641 if (relocs)
6643 if ( !add_dynamic_entry (DT_REL, 0)
6644 || !add_dynamic_entry (DT_RELSZ, 0)
6645 || !add_dynamic_entry (DT_RELENT, sizeof (Elf32_External_Rel)))
6646 return FALSE;
6649 /* If any dynamic relocs apply to a read-only section,
6650 then we need a DT_TEXTREL entry. */
6651 if ((info->flags & DF_TEXTREL) == 0)
6652 elf_link_hash_traverse (&htab->root, elf32_arm_readonly_dynrelocs,
6653 (PTR) info);
6655 if ((info->flags & DF_TEXTREL) != 0)
6657 if (!add_dynamic_entry (DT_TEXTREL, 0))
6658 return FALSE;
6661 #undef add_dynamic_entry
6663 return TRUE;
6666 /* Finish up dynamic symbol handling. We set the contents of various
6667 dynamic sections here. */
6669 static bfd_boolean
6670 elf32_arm_finish_dynamic_symbol (bfd * output_bfd, struct bfd_link_info * info,
6671 struct elf_link_hash_entry * h, Elf_Internal_Sym * sym)
6673 bfd * dynobj;
6674 struct elf32_arm_link_hash_table *htab;
6675 struct elf32_arm_link_hash_entry *eh;
6677 dynobj = elf_hash_table (info)->dynobj;
6678 htab = elf32_arm_hash_table (info);
6679 eh = (struct elf32_arm_link_hash_entry *) h;
6681 if (h->plt.offset != (bfd_vma) -1)
6683 asection * splt;
6684 asection * srel;
6685 bfd_byte *loc;
6686 bfd_vma plt_index;
6687 Elf_Internal_Rela rel;
6689 /* This symbol has an entry in the procedure linkage table. Set
6690 it up. */
6692 BFD_ASSERT (h->dynindx != -1);
6694 splt = bfd_get_section_by_name (dynobj, ".plt");
6695 srel = bfd_get_section_by_name (dynobj, ".rel.plt");
6696 BFD_ASSERT (splt != NULL && srel != NULL);
6698 /* Fill in the entry in the procedure linkage table. */
6699 if (htab->symbian_p)
6701 unsigned i;
6702 for (i = 0; i < htab->plt_entry_size / 4; ++i)
6703 bfd_put_32 (output_bfd,
6704 elf32_arm_symbian_plt_entry[i],
6705 splt->contents + h->plt.offset + 4 * i);
6707 /* Fill in the entry in the .rel.plt section. */
6708 rel.r_offset = (splt->output_section->vma
6709 + splt->output_offset
6710 + h->plt.offset + 4 * (i - 1));
6711 rel.r_info = ELF32_R_INFO (h->dynindx, R_ARM_GLOB_DAT);
6713 /* Get the index in the procedure linkage table which
6714 corresponds to this symbol. This is the index of this symbol
6715 in all the symbols for which we are making plt entries. The
6716 first entry in the procedure linkage table is reserved. */
6717 plt_index = ((h->plt.offset - htab->plt_header_size)
6718 / htab->plt_entry_size);
6720 else
6722 bfd_vma got_offset;
6723 bfd_vma got_displacement;
6724 asection * sgot;
6726 sgot = bfd_get_section_by_name (dynobj, ".got.plt");
6727 BFD_ASSERT (sgot != NULL);
6729 /* Get the offset into the .got.plt table of the entry that
6730 corresponds to this function. */
6731 got_offset = eh->plt_got_offset;
6733 /* Get the index in the procedure linkage table which
6734 corresponds to this symbol. This is the index of this symbol
6735 in all the symbols for which we are making plt entries. The
6736 first three entries in .got.plt are reserved; after that
6737 symbols appear in the same order as in .plt. */
6738 plt_index = (got_offset - 12) / 4;
6740 /* Calculate the displacement between the PLT slot and the
6741 entry in the GOT. The eight-byte offset accounts for the
6742 value produced by adding to pc in the first instruction
6743 of the PLT stub. */
6744 got_displacement = (sgot->output_section->vma
6745 + sgot->output_offset
6746 + got_offset
6747 - splt->output_section->vma
6748 - splt->output_offset
6749 - h->plt.offset
6750 - 8);
6752 BFD_ASSERT ((got_displacement & 0xf0000000) == 0);
6754 if (!htab->use_blx && eh->plt_thumb_refcount > 0)
6756 bfd_put_16 (output_bfd, elf32_arm_plt_thumb_stub[0],
6757 splt->contents + h->plt.offset - 4);
6758 bfd_put_16 (output_bfd, elf32_arm_plt_thumb_stub[1],
6759 splt->contents + h->plt.offset - 2);
6762 bfd_put_32 (output_bfd, elf32_arm_plt_entry[0] | ((got_displacement & 0x0ff00000) >> 20),
6763 splt->contents + h->plt.offset + 0);
6764 bfd_put_32 (output_bfd, elf32_arm_plt_entry[1] | ((got_displacement & 0x000ff000) >> 12),
6765 splt->contents + h->plt.offset + 4);
6766 bfd_put_32 (output_bfd, elf32_arm_plt_entry[2] | (got_displacement & 0x00000fff),
6767 splt->contents + h->plt.offset + 8);
6768 #ifdef FOUR_WORD_PLT
6769 bfd_put_32 (output_bfd, elf32_arm_plt_entry[3],
6770 splt->contents + h->plt.offset + 12);
6771 #endif
6773 /* Fill in the entry in the global offset table. */
6774 bfd_put_32 (output_bfd,
6775 (splt->output_section->vma
6776 + splt->output_offset),
6777 sgot->contents + got_offset);
6779 /* Fill in the entry in the .rel.plt section. */
6780 rel.r_offset = (sgot->output_section->vma
6781 + sgot->output_offset
6782 + got_offset);
6783 rel.r_info = ELF32_R_INFO (h->dynindx, R_ARM_JUMP_SLOT);
6786 loc = srel->contents + plt_index * sizeof (Elf32_External_Rel);
6787 bfd_elf32_swap_reloc_out (output_bfd, &rel, loc);
6789 if (!h->def_regular)
6791 /* Mark the symbol as undefined, rather than as defined in
6792 the .plt section. Leave the value alone. */
6793 sym->st_shndx = SHN_UNDEF;
6794 /* If the symbol is weak, we do need to clear the value.
6795 Otherwise, the PLT entry would provide a definition for
6796 the symbol even if the symbol wasn't defined anywhere,
6797 and so the symbol would never be NULL. */
6798 if (!h->ref_regular_nonweak)
6799 sym->st_value = 0;
6803 if (h->got.offset != (bfd_vma) -1
6804 && (elf32_arm_hash_entry (h)->tls_type & GOT_TLS_GD) == 0
6805 && (elf32_arm_hash_entry (h)->tls_type & GOT_TLS_IE) == 0)
6807 asection * sgot;
6808 asection * srel;
6809 Elf_Internal_Rela rel;
6810 bfd_byte *loc;
6812 /* This symbol has an entry in the global offset table. Set it
6813 up. */
6814 sgot = bfd_get_section_by_name (dynobj, ".got");
6815 srel = bfd_get_section_by_name (dynobj, ".rel.got");
6816 BFD_ASSERT (sgot != NULL && srel != NULL);
6818 rel.r_offset = (sgot->output_section->vma
6819 + sgot->output_offset
6820 + (h->got.offset &~ (bfd_vma) 1));
6822 /* If this is a static link, or it is a -Bsymbolic link and the
6823 symbol is defined locally or was forced to be local because
6824 of a version file, we just want to emit a RELATIVE reloc.
6825 The entry in the global offset table will already have been
6826 initialized in the relocate_section function. */
6827 if (info->shared
6828 && SYMBOL_REFERENCES_LOCAL (info, h))
6830 BFD_ASSERT((h->got.offset & 1) != 0);
6831 rel.r_info = ELF32_R_INFO (0, R_ARM_RELATIVE);
6833 else
6835 BFD_ASSERT((h->got.offset & 1) == 0);
6836 bfd_put_32 (output_bfd, (bfd_vma) 0, sgot->contents + h->got.offset);
6837 rel.r_info = ELF32_R_INFO (h->dynindx, R_ARM_GLOB_DAT);
6840 loc = srel->contents + srel->reloc_count++ * sizeof (Elf32_External_Rel);
6841 bfd_elf32_swap_reloc_out (output_bfd, &rel, loc);
6844 if (h->needs_copy)
6846 asection * s;
6847 Elf_Internal_Rela rel;
6848 bfd_byte *loc;
6850 /* This symbol needs a copy reloc. Set it up. */
6851 BFD_ASSERT (h->dynindx != -1
6852 && (h->root.type == bfd_link_hash_defined
6853 || h->root.type == bfd_link_hash_defweak));
6855 s = bfd_get_section_by_name (h->root.u.def.section->owner,
6856 ".rel.bss");
6857 BFD_ASSERT (s != NULL);
6859 rel.r_offset = (h->root.u.def.value
6860 + h->root.u.def.section->output_section->vma
6861 + h->root.u.def.section->output_offset);
6862 rel.r_info = ELF32_R_INFO (h->dynindx, R_ARM_COPY);
6863 loc = s->contents + s->reloc_count++ * sizeof (Elf32_External_Rel);
6864 bfd_elf32_swap_reloc_out (output_bfd, &rel, loc);
6867 /* Mark _DYNAMIC and _GLOBAL_OFFSET_TABLE_ as absolute. */
6868 if (strcmp (h->root.root.string, "_DYNAMIC") == 0
6869 || strcmp (h->root.root.string, "_GLOBAL_OFFSET_TABLE_") == 0)
6870 sym->st_shndx = SHN_ABS;
6872 return TRUE;
6875 /* Finish up the dynamic sections. */
6877 static bfd_boolean
6878 elf32_arm_finish_dynamic_sections (bfd * output_bfd, struct bfd_link_info * info)
6880 bfd * dynobj;
6881 asection * sgot;
6882 asection * sdyn;
6884 dynobj = elf_hash_table (info)->dynobj;
6886 sgot = bfd_get_section_by_name (dynobj, ".got.plt");
6887 BFD_ASSERT (elf32_arm_hash_table (info)->symbian_p || sgot != NULL);
6888 sdyn = bfd_get_section_by_name (dynobj, ".dynamic");
6890 if (elf_hash_table (info)->dynamic_sections_created)
6892 asection *splt;
6893 Elf32_External_Dyn *dyncon, *dynconend;
6894 struct elf32_arm_link_hash_table *htab;
6896 htab = elf32_arm_hash_table (info);
6897 splt = bfd_get_section_by_name (dynobj, ".plt");
6898 BFD_ASSERT (splt != NULL && sdyn != NULL);
6900 dyncon = (Elf32_External_Dyn *) sdyn->contents;
6901 dynconend = (Elf32_External_Dyn *) (sdyn->contents + sdyn->size);
6903 for (; dyncon < dynconend; dyncon++)
6905 Elf_Internal_Dyn dyn;
6906 const char * name;
6907 asection * s;
6909 bfd_elf32_swap_dyn_in (dynobj, dyncon, &dyn);
6911 switch (dyn.d_tag)
6913 unsigned int type;
6915 default:
6916 break;
6918 case DT_HASH:
6919 name = ".hash";
6920 goto get_vma_if_bpabi;
6921 case DT_STRTAB:
6922 name = ".dynstr";
6923 goto get_vma_if_bpabi;
6924 case DT_SYMTAB:
6925 name = ".dynsym";
6926 goto get_vma_if_bpabi;
6927 case DT_VERSYM:
6928 name = ".gnu.version";
6929 goto get_vma_if_bpabi;
6930 case DT_VERDEF:
6931 name = ".gnu.version_d";
6932 goto get_vma_if_bpabi;
6933 case DT_VERNEED:
6934 name = ".gnu.version_r";
6935 goto get_vma_if_bpabi;
6937 case DT_PLTGOT:
6938 name = ".got";
6939 goto get_vma;
6940 case DT_JMPREL:
6941 name = ".rel.plt";
6942 get_vma:
6943 s = bfd_get_section_by_name (output_bfd, name);
6944 BFD_ASSERT (s != NULL);
6945 if (!htab->symbian_p)
6946 dyn.d_un.d_ptr = s->vma;
6947 else
6948 /* In the BPABI, tags in the PT_DYNAMIC section point
6949 at the file offset, not the memory address, for the
6950 convenience of the post linker. */
6951 dyn.d_un.d_ptr = s->filepos;
6952 bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon);
6953 break;
6955 get_vma_if_bpabi:
6956 if (htab->symbian_p)
6957 goto get_vma;
6958 break;
6960 case DT_PLTRELSZ:
6961 s = bfd_get_section_by_name (output_bfd, ".rel.plt");
6962 BFD_ASSERT (s != NULL);
6963 dyn.d_un.d_val = s->size;
6964 bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon);
6965 break;
6967 case DT_RELSZ:
6968 if (!htab->symbian_p)
6970 /* My reading of the SVR4 ABI indicates that the
6971 procedure linkage table relocs (DT_JMPREL) should be
6972 included in the overall relocs (DT_REL). This is
6973 what Solaris does. However, UnixWare can not handle
6974 that case. Therefore, we override the DT_RELSZ entry
6975 here to make it not include the JMPREL relocs. Since
6976 the linker script arranges for .rel.plt to follow all
6977 other relocation sections, we don't have to worry
6978 about changing the DT_REL entry. */
6979 s = bfd_get_section_by_name (output_bfd, ".rel.plt");
6980 if (s != NULL)
6981 dyn.d_un.d_val -= s->size;
6982 bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon);
6983 break;
6985 /* Fall through */
6987 case DT_REL:
6988 case DT_RELA:
6989 case DT_RELASZ:
6990 /* In the BPABI, the DT_REL tag must point at the file
6991 offset, not the VMA, of the first relocation
6992 section. So, we use code similar to that in
6993 elflink.c, but do not check for SHF_ALLOC on the
6994 relcoation section, since relocations sections are
6995 never allocated under the BPABI. The comments above
6996 about Unixware notwithstanding, we include all of the
6997 relocations here. */
6998 if (htab->symbian_p)
7000 unsigned int i;
7001 type = ((dyn.d_tag == DT_REL || dyn.d_tag == DT_RELSZ)
7002 ? SHT_REL : SHT_RELA);
7003 dyn.d_un.d_val = 0;
7004 for (i = 1; i < elf_numsections (output_bfd); i++)
7006 Elf_Internal_Shdr *hdr
7007 = elf_elfsections (output_bfd)[i];
7008 if (hdr->sh_type == type)
7010 if (dyn.d_tag == DT_RELSZ
7011 || dyn.d_tag == DT_RELASZ)
7012 dyn.d_un.d_val += hdr->sh_size;
7013 else if ((ufile_ptr) hdr->sh_offset
7014 <= dyn.d_un.d_val - 1)
7015 dyn.d_un.d_val = hdr->sh_offset;
7018 bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon);
7020 break;
7022 /* Set the bottom bit of DT_INIT/FINI if the
7023 corresponding function is Thumb. */
7024 case DT_INIT:
7025 name = info->init_function;
7026 goto get_sym;
7027 case DT_FINI:
7028 name = info->fini_function;
7029 get_sym:
7030 /* If it wasn't set by elf_bfd_final_link
7031 then there is nothing to adjust. */
7032 if (dyn.d_un.d_val != 0)
7034 struct elf_link_hash_entry * eh;
7036 eh = elf_link_hash_lookup (elf_hash_table (info), name,
7037 FALSE, FALSE, TRUE);
7038 if (eh != (struct elf_link_hash_entry *) NULL
7039 && ELF_ST_TYPE (eh->type) == STT_ARM_TFUNC)
7041 dyn.d_un.d_val |= 1;
7042 bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon);
7045 break;
7049 /* Fill in the first entry in the procedure linkage table. */
7050 if (splt->size > 0 && elf32_arm_hash_table (info)->plt_header_size)
7052 bfd_vma got_displacement;
7054 /* Calculate the displacement between the PLT slot and &GOT[0]. */
7055 got_displacement = (sgot->output_section->vma
7056 + sgot->output_offset
7057 - splt->output_section->vma
7058 - splt->output_offset
7059 - 16);
7061 bfd_put_32 (output_bfd, elf32_arm_plt0_entry[0], splt->contents + 0);
7062 bfd_put_32 (output_bfd, elf32_arm_plt0_entry[1], splt->contents + 4);
7063 bfd_put_32 (output_bfd, elf32_arm_plt0_entry[2], splt->contents + 8);
7064 bfd_put_32 (output_bfd, elf32_arm_plt0_entry[3], splt->contents + 12);
7065 #ifdef FOUR_WORD_PLT
7066 /* The displacement value goes in the otherwise-unused last word of
7067 the second entry. */
7068 bfd_put_32 (output_bfd, got_displacement, splt->contents + 28);
7069 #else
7070 bfd_put_32 (output_bfd, got_displacement, splt->contents + 16);
7071 #endif
7074 /* UnixWare sets the entsize of .plt to 4, although that doesn't
7075 really seem like the right value. */
7076 elf_section_data (splt->output_section)->this_hdr.sh_entsize = 4;
7079 /* Fill in the first three entries in the global offset table. */
7080 if (sgot)
7082 if (sgot->size > 0)
7084 if (sdyn == NULL)
7085 bfd_put_32 (output_bfd, (bfd_vma) 0, sgot->contents);
7086 else
7087 bfd_put_32 (output_bfd,
7088 sdyn->output_section->vma + sdyn->output_offset,
7089 sgot->contents);
7090 bfd_put_32 (output_bfd, (bfd_vma) 0, sgot->contents + 4);
7091 bfd_put_32 (output_bfd, (bfd_vma) 0, sgot->contents + 8);
7094 elf_section_data (sgot->output_section)->this_hdr.sh_entsize = 4;
7097 return TRUE;
7100 static void
7101 elf32_arm_post_process_headers (bfd * abfd, struct bfd_link_info * link_info ATTRIBUTE_UNUSED)
7103 Elf_Internal_Ehdr * i_ehdrp; /* ELF file header, internal form. */
7104 struct elf32_arm_link_hash_table *globals;
7106 i_ehdrp = elf_elfheader (abfd);
7108 if (EF_ARM_EABI_VERSION (i_ehdrp->e_flags) == EF_ARM_EABI_UNKNOWN)
7109 i_ehdrp->e_ident[EI_OSABI] = ELFOSABI_ARM;
7110 else
7111 i_ehdrp->e_ident[EI_OSABI] = 0;
7112 i_ehdrp->e_ident[EI_ABIVERSION] = ARM_ELF_ABI_VERSION;
7114 if (link_info)
7116 globals = elf32_arm_hash_table (link_info);
7117 if (globals->byteswap_code)
7118 i_ehdrp->e_flags |= EF_ARM_BE8;
7122 static enum elf_reloc_type_class
7123 elf32_arm_reloc_type_class (const Elf_Internal_Rela *rela)
7125 switch ((int) ELF32_R_TYPE (rela->r_info))
7127 case R_ARM_RELATIVE:
7128 return reloc_class_relative;
7129 case R_ARM_JUMP_SLOT:
7130 return reloc_class_plt;
7131 case R_ARM_COPY:
7132 return reloc_class_copy;
7133 default:
7134 return reloc_class_normal;
7138 /* Set the right machine number for an Arm ELF file. */
7140 static bfd_boolean
7141 elf32_arm_section_flags (flagword *flags, const Elf_Internal_Shdr *hdr)
7143 if (hdr->sh_type == SHT_NOTE)
7144 *flags |= SEC_LINK_ONCE | SEC_LINK_DUPLICATES_SAME_CONTENTS;
7146 return TRUE;
7149 static void
7150 elf32_arm_final_write_processing (bfd *abfd, bfd_boolean linker ATTRIBUTE_UNUSED)
7152 bfd_arm_update_notes (abfd, ARM_NOTE_SECTION);
7155 /* Return TRUE if this is an unwinding table entry. */
7157 static bfd_boolean
7158 is_arm_elf_unwind_section_name (bfd * abfd ATTRIBUTE_UNUSED, const char * name)
7160 size_t len1, len2;
7162 len1 = sizeof (ELF_STRING_ARM_unwind) - 1;
7163 len2 = sizeof (ELF_STRING_ARM_unwind_once) - 1;
7164 return (strncmp (name, ELF_STRING_ARM_unwind, len1) == 0
7165 || strncmp (name, ELF_STRING_ARM_unwind_once, len2) == 0);
7169 /* Set the type and flags for an ARM section. We do this by
7170 the section name, which is a hack, but ought to work. */
7172 static bfd_boolean
7173 elf32_arm_fake_sections (bfd * abfd, Elf_Internal_Shdr * hdr, asection * sec)
7175 const char * name;
7177 name = bfd_get_section_name (abfd, sec);
7179 if (is_arm_elf_unwind_section_name (abfd, name))
7181 hdr->sh_type = SHT_ARM_EXIDX;
7182 hdr->sh_flags |= SHF_LINK_ORDER;
7184 else if (strcmp(name, ".ARM.attributes") == 0)
7186 hdr->sh_type = SHT_ARM_ATTRIBUTES;
7188 return TRUE;
7191 /* Parse an Arm EABI attributes section. */
7192 static void
7193 elf32_arm_parse_attributes (bfd *abfd, Elf_Internal_Shdr * hdr)
7195 bfd_byte *contents;
7196 bfd_byte *p;
7197 bfd_vma len;
7199 contents = bfd_malloc (hdr->sh_size);
7200 if (!contents)
7201 return;
7202 if (!bfd_get_section_contents (abfd, hdr->bfd_section, contents, 0,
7203 hdr->sh_size))
7205 free (contents);
7206 return;
7208 p = contents;
7209 if (*(p++) == 'A')
7211 len = hdr->sh_size - 1;
7212 while (len > 0)
7214 int namelen;
7215 bfd_vma section_len;
7217 section_len = bfd_get_32 (abfd, p);
7218 p += 4;
7219 if (section_len > len)
7220 section_len = len;
7221 len -= section_len;
7222 namelen = strlen ((char *)p) + 1;
7223 section_len -= namelen + 4;
7224 if (strcmp((char *)p, "aeabi") != 0)
7226 /* Vendor section. Ignore it. */
7227 p += namelen + section_len;
7229 else
7231 p += namelen;
7232 while (section_len > 0)
7234 int tag;
7235 unsigned int n;
7236 unsigned int val;
7237 bfd_vma subsection_len;
7238 bfd_byte *end;
7240 tag = read_unsigned_leb128 (abfd, p, &n);
7241 p += n;
7242 subsection_len = bfd_get_32 (abfd, p);
7243 p += 4;
7244 if (subsection_len > section_len)
7245 subsection_len = section_len;
7246 section_len -= subsection_len;
7247 subsection_len -= n + 4;
7248 end = p + subsection_len;
7249 switch (tag)
7251 case Tag_File:
7252 while (p < end)
7254 bfd_boolean is_string;
7256 tag = read_unsigned_leb128 (abfd, p, &n);
7257 p += n;
7258 if (tag == 4 || tag == 5)
7259 is_string = 1;
7260 else if (tag < 32)
7261 is_string = 0;
7262 else
7263 is_string = (tag & 1) != 0;
7264 if (tag == Tag_compatibility)
7266 val = read_unsigned_leb128 (abfd, p, &n);
7267 p += n;
7268 elf32_arm_add_eabi_attr_compat (abfd, val,
7269 (char *)p);
7270 p += strlen ((char *)p) + 1;
7272 else if (is_string)
7274 elf32_arm_add_eabi_attr_string (abfd, tag,
7275 (char *)p);
7276 p += strlen ((char *)p) + 1;
7278 else
7280 val = read_unsigned_leb128 (abfd, p, &n);
7281 p += n;
7282 elf32_arm_add_eabi_attr_int (abfd, tag, val);
7285 break;
7286 case Tag_Section:
7287 case Tag_Symbol:
7288 /* Don't have anywhere convenient to attach these.
7289 Fall through for now. */
7290 default:
7291 /* Ignore things we don't kow about. */
7292 p += subsection_len;
7293 subsection_len = 0;
7294 break;
7300 free (contents);
7303 /* Handle an ARM specific section when reading an object file. This is
7304 called when bfd_section_from_shdr finds a section with an unknown
7305 type. */
7307 static bfd_boolean
7308 elf32_arm_section_from_shdr (bfd *abfd,
7309 Elf_Internal_Shdr * hdr,
7310 const char *name,
7311 int shindex)
7313 /* There ought to be a place to keep ELF backend specific flags, but
7314 at the moment there isn't one. We just keep track of the
7315 sections by their name, instead. Fortunately, the ABI gives
7316 names for all the ARM specific sections, so we will probably get
7317 away with this. */
7318 switch (hdr->sh_type)
7320 case SHT_ARM_EXIDX:
7321 case SHT_ARM_PREEMPTMAP:
7322 case SHT_ARM_ATTRIBUTES:
7323 break;
7325 default:
7326 return FALSE;
7329 if (! _bfd_elf_make_section_from_shdr (abfd, hdr, name, shindex))
7330 return FALSE;
7332 if (hdr->sh_type == SHT_ARM_ATTRIBUTES)
7333 elf32_arm_parse_attributes(abfd, hdr);
7334 return TRUE;
7337 /* A structure used to record a list of sections, independently
7338 of the next and prev fields in the asection structure. */
7339 typedef struct section_list
7341 asection * sec;
7342 struct section_list * next;
7343 struct section_list * prev;
7345 section_list;
7347 /* Unfortunately we need to keep a list of sections for which
7348 an _arm_elf_section_data structure has been allocated. This
7349 is because it is possible for functions like elf32_arm_write_section
7350 to be called on a section which has had an elf_data_structure
7351 allocated for it (and so the used_by_bfd field is valid) but
7352 for which the ARM extended version of this structure - the
7353 _arm_elf_section_data structure - has not been allocated. */
7354 static section_list * sections_with_arm_elf_section_data = NULL;
7356 static void
7357 record_section_with_arm_elf_section_data (asection * sec)
7359 struct section_list * entry;
7361 entry = bfd_malloc (sizeof (* entry));
7362 if (entry == NULL)
7363 return;
7364 entry->sec = sec;
7365 entry->next = sections_with_arm_elf_section_data;
7366 entry->prev = NULL;
7367 if (entry->next != NULL)
7368 entry->next->prev = entry;
7369 sections_with_arm_elf_section_data = entry;
7372 static struct section_list *
7373 find_arm_elf_section_entry (asection * sec)
7375 struct section_list * entry;
7376 static struct section_list * last_entry = NULL;
7378 /* This is a short cut for the typical case where the sections are added
7379 to the sections_with_arm_elf_section_data list in forward order and
7380 then looked up here in backwards order. This makes a real difference
7381 to the ld-srec/sec64k.exp linker test. */
7382 entry = sections_with_arm_elf_section_data;
7383 if (last_entry != NULL)
7385 if (last_entry->sec == sec)
7386 entry = last_entry;
7387 else if (last_entry->next != NULL
7388 && last_entry->next->sec == sec)
7389 entry = last_entry->next;
7392 for (; entry; entry = entry->next)
7393 if (entry->sec == sec)
7394 break;
7396 if (entry)
7397 /* Record the entry prior to this one - it is the entry we are most
7398 likely to want to locate next time. Also this way if we have been
7399 called from unrecord_section_with_arm_elf_section_data() we will not
7400 be caching a pointer that is about to be freed. */
7401 last_entry = entry->prev;
7403 return entry;
7406 static _arm_elf_section_data *
7407 get_arm_elf_section_data (asection * sec)
7409 struct section_list * entry;
7411 entry = find_arm_elf_section_entry (sec);
7413 if (entry)
7414 return elf32_arm_section_data (entry->sec);
7415 else
7416 return NULL;
7419 static void
7420 unrecord_section_with_arm_elf_section_data (asection * sec)
7422 struct section_list * entry;
7424 entry = find_arm_elf_section_entry (sec);
7426 if (entry)
7428 if (entry->prev != NULL)
7429 entry->prev->next = entry->next;
7430 if (entry->next != NULL)
7431 entry->next->prev = entry->prev;
7432 if (entry == sections_with_arm_elf_section_data)
7433 sections_with_arm_elf_section_data = entry->next;
7434 free (entry);
7438 /* Called for each symbol. Builds a section map based on mapping symbols.
7439 Does not alter any of the symbols. */
7441 static bfd_boolean
7442 elf32_arm_output_symbol_hook (struct bfd_link_info *info,
7443 const char *name,
7444 Elf_Internal_Sym *elfsym,
7445 asection *input_sec,
7446 struct elf_link_hash_entry *h ATTRIBUTE_UNUSED)
7448 int mapcount;
7449 elf32_arm_section_map *map;
7450 elf32_arm_section_map *newmap;
7451 _arm_elf_section_data *arm_data;
7452 struct elf32_arm_link_hash_table *globals;
7454 /* Only do this on final link. */
7455 if (info->relocatable)
7456 return TRUE;
7458 /* Only build a map if we need to byteswap code. */
7459 globals = elf32_arm_hash_table (info);
7460 if (!globals->byteswap_code)
7461 return TRUE;
7463 /* We only want mapping symbols. */
7464 if (! bfd_is_arm_mapping_symbol_name (name))
7465 return TRUE;
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 (input_sec);
7470 if (arm_data == NULL)
7471 return TRUE;
7473 mapcount = arm_data->mapcount + 1;
7474 map = arm_data->map;
7476 /* TODO: This may be inefficient, but we probably don't usually have many
7477 mapping symbols per section. */
7478 newmap = bfd_realloc (map, mapcount * sizeof (* map));
7479 if (newmap != NULL)
7481 arm_data->map = newmap;
7482 arm_data->mapcount = mapcount;
7484 newmap[mapcount - 1].vma = elfsym->st_value;
7485 newmap[mapcount - 1].type = name[1];
7488 return TRUE;
7491 /* Allocate target specific section data. */
7493 static bfd_boolean
7494 elf32_arm_new_section_hook (bfd *abfd, asection *sec)
7496 _arm_elf_section_data *sdata;
7497 bfd_size_type amt = sizeof (*sdata);
7499 sdata = bfd_zalloc (abfd, amt);
7500 if (sdata == NULL)
7501 return FALSE;
7502 sec->used_by_bfd = sdata;
7504 record_section_with_arm_elf_section_data (sec);
7506 return _bfd_elf_new_section_hook (abfd, sec);
7510 /* Used to order a list of mapping symbols by address. */
7512 static int
7513 elf32_arm_compare_mapping (const void * a, const void * b)
7515 return ((const elf32_arm_section_map *) a)->vma
7516 > ((const elf32_arm_section_map *) b)->vma;
7520 /* Do code byteswapping. Return FALSE afterwards so that the section is
7521 written out as normal. */
7523 static bfd_boolean
7524 elf32_arm_write_section (bfd *output_bfd ATTRIBUTE_UNUSED, asection *sec,
7525 bfd_byte *contents)
7527 int mapcount;
7528 _arm_elf_section_data *arm_data;
7529 elf32_arm_section_map *map;
7530 bfd_vma ptr;
7531 bfd_vma end;
7532 bfd_vma offset;
7533 bfd_byte tmp;
7534 int i;
7536 /* If this section has not been allocated an _arm_elf_section_data
7537 structure then we cannot record anything. */
7538 arm_data = get_arm_elf_section_data (sec);
7539 if (arm_data == NULL)
7540 return FALSE;
7542 mapcount = arm_data->mapcount;
7543 map = arm_data->map;
7545 if (mapcount == 0)
7546 return FALSE;
7548 qsort (map, mapcount, sizeof (* map), elf32_arm_compare_mapping);
7550 offset = sec->output_section->vma + sec->output_offset;
7551 ptr = map[0].vma - offset;
7552 for (i = 0; i < mapcount; i++)
7554 if (i == mapcount - 1)
7555 end = sec->size;
7556 else
7557 end = map[i + 1].vma - offset;
7559 switch (map[i].type)
7561 case 'a':
7562 /* Byte swap code words. */
7563 while (ptr + 3 < end)
7565 tmp = contents[ptr];
7566 contents[ptr] = contents[ptr + 3];
7567 contents[ptr + 3] = tmp;
7568 tmp = contents[ptr + 1];
7569 contents[ptr + 1] = contents[ptr + 2];
7570 contents[ptr + 2] = tmp;
7571 ptr += 4;
7573 break;
7575 case 't':
7576 /* Byte swap code halfwords. */
7577 while (ptr + 1 < end)
7579 tmp = contents[ptr];
7580 contents[ptr] = contents[ptr + 1];
7581 contents[ptr + 1] = tmp;
7582 ptr += 2;
7584 break;
7586 case 'd':
7587 /* Leave data alone. */
7588 break;
7590 ptr = end;
7593 free (map);
7594 arm_data->mapcount = 0;
7595 arm_data->map = NULL;
7596 unrecord_section_with_arm_elf_section_data (sec);
7598 return FALSE;
7601 static void
7602 unrecord_section_via_map_over_sections (bfd * abfd ATTRIBUTE_UNUSED,
7603 asection * sec,
7604 void * ignore ATTRIBUTE_UNUSED)
7606 unrecord_section_with_arm_elf_section_data (sec);
7609 static bfd_boolean
7610 elf32_arm_close_and_cleanup (bfd * abfd)
7612 bfd_map_over_sections (abfd, unrecord_section_via_map_over_sections, NULL);
7614 return _bfd_elf_close_and_cleanup (abfd);
7617 /* Display STT_ARM_TFUNC symbols as functions. */
7619 static void
7620 elf32_arm_symbol_processing (bfd *abfd ATTRIBUTE_UNUSED,
7621 asymbol *asym)
7623 elf_symbol_type *elfsym = (elf_symbol_type *) asym;
7625 if (ELF_ST_TYPE (elfsym->internal_elf_sym.st_info) == STT_ARM_TFUNC)
7626 elfsym->symbol.flags |= BSF_FUNCTION;
7630 /* Mangle thumb function symbols as we read them in. */
7632 static void
7633 elf32_arm_swap_symbol_in (bfd * abfd,
7634 const void *psrc,
7635 const void *pshn,
7636 Elf_Internal_Sym *dst)
7638 bfd_elf32_swap_symbol_in (abfd, psrc, pshn, dst);
7640 /* New EABI objects mark thumb function symbols by setting the low bit of
7641 the address. Turn these into STT_ARM_TFUNC. */
7642 if (ELF_ST_TYPE (dst->st_info) == STT_FUNC
7643 && (dst->st_value & 1))
7645 dst->st_info = ELF_ST_INFO (ELF_ST_BIND (dst->st_info), STT_ARM_TFUNC);
7646 dst->st_value &= ~(bfd_vma) 1;
7651 /* Mangle thumb function symbols as we write them out. */
7653 static void
7654 elf32_arm_swap_symbol_out (bfd *abfd,
7655 const Elf_Internal_Sym *src,
7656 void *cdst,
7657 void *shndx)
7659 Elf_Internal_Sym newsym;
7661 /* We convert STT_ARM_TFUNC symbols into STT_FUNC with the low bit
7662 of the address set, as per the new EABI. We do this unconditionally
7663 because objcopy does not set the elf header flags until after
7664 it writes out the symbol table. */
7665 if (ELF_ST_TYPE (src->st_info) == STT_ARM_TFUNC)
7667 newsym = *src;
7668 newsym.st_info = ELF_ST_INFO (ELF_ST_BIND (src->st_info), STT_FUNC);
7669 newsym.st_value |= 1;
7671 src = &newsym;
7673 bfd_elf32_swap_symbol_out (abfd, src, cdst, shndx);
7676 /* Add the PT_ARM_EXIDX program header. */
7678 static bfd_boolean
7679 elf32_arm_modify_segment_map (bfd *abfd,
7680 struct bfd_link_info *info ATTRIBUTE_UNUSED)
7682 struct elf_segment_map *m;
7683 asection *sec;
7685 sec = bfd_get_section_by_name (abfd, ".ARM.exidx");
7686 if (sec != NULL && (sec->flags & SEC_LOAD) != 0)
7688 /* If there is already a PT_ARM_EXIDX header, then we do not
7689 want to add another one. This situation arises when running
7690 "strip"; the input binary already has the header. */
7691 m = elf_tdata (abfd)->segment_map;
7692 while (m && m->p_type != PT_ARM_EXIDX)
7693 m = m->next;
7694 if (!m)
7696 m = bfd_zalloc (abfd, sizeof (struct elf_segment_map));
7697 if (m == NULL)
7698 return FALSE;
7699 m->p_type = PT_ARM_EXIDX;
7700 m->count = 1;
7701 m->sections[0] = sec;
7703 m->next = elf_tdata (abfd)->segment_map;
7704 elf_tdata (abfd)->segment_map = m;
7708 return TRUE;
7711 /* We may add a PT_ARM_EXIDX program header. */
7713 static int
7714 elf32_arm_additional_program_headers (bfd *abfd)
7716 asection *sec;
7718 sec = bfd_get_section_by_name (abfd, ".ARM.exidx");
7719 if (sec != NULL && (sec->flags & SEC_LOAD) != 0)
7720 return 1;
7721 else
7722 return 0;
7725 /* We use this to override swap_symbol_in and swap_symbol_out. */
7726 const struct elf_size_info elf32_arm_size_info = {
7727 sizeof (Elf32_External_Ehdr),
7728 sizeof (Elf32_External_Phdr),
7729 sizeof (Elf32_External_Shdr),
7730 sizeof (Elf32_External_Rel),
7731 sizeof (Elf32_External_Rela),
7732 sizeof (Elf32_External_Sym),
7733 sizeof (Elf32_External_Dyn),
7734 sizeof (Elf_External_Note),
7737 32, 2,
7738 ELFCLASS32, EV_CURRENT,
7739 bfd_elf32_write_out_phdrs,
7740 bfd_elf32_write_shdrs_and_ehdr,
7741 bfd_elf32_write_relocs,
7742 elf32_arm_swap_symbol_in,
7743 elf32_arm_swap_symbol_out,
7744 bfd_elf32_slurp_reloc_table,
7745 bfd_elf32_slurp_symbol_table,
7746 bfd_elf32_swap_dyn_in,
7747 bfd_elf32_swap_dyn_out,
7748 bfd_elf32_swap_reloc_in,
7749 bfd_elf32_swap_reloc_out,
7750 bfd_elf32_swap_reloca_in,
7751 bfd_elf32_swap_reloca_out
7754 #define ELF_ARCH bfd_arch_arm
7755 #define ELF_MACHINE_CODE EM_ARM
7756 #ifdef __QNXTARGET__
7757 #define ELF_MAXPAGESIZE 0x1000
7758 #else
7759 #define ELF_MAXPAGESIZE 0x8000
7760 #endif
7761 #define ELF_MINPAGESIZE 0x1000
7763 #define bfd_elf32_mkobject elf32_arm_mkobject
7765 #define bfd_elf32_bfd_copy_private_bfd_data elf32_arm_copy_private_bfd_data
7766 #define bfd_elf32_bfd_merge_private_bfd_data elf32_arm_merge_private_bfd_data
7767 #define bfd_elf32_bfd_set_private_flags elf32_arm_set_private_flags
7768 #define bfd_elf32_bfd_print_private_bfd_data elf32_arm_print_private_bfd_data
7769 #define bfd_elf32_bfd_link_hash_table_create elf32_arm_link_hash_table_create
7770 #define bfd_elf32_bfd_reloc_type_lookup elf32_arm_reloc_type_lookup
7771 #define bfd_elf32_find_nearest_line elf32_arm_find_nearest_line
7772 #define bfd_elf32_find_inliner_info elf32_arm_find_inliner_info
7773 #define bfd_elf32_new_section_hook elf32_arm_new_section_hook
7774 #define bfd_elf32_bfd_is_target_special_symbol elf32_arm_is_target_special_symbol
7775 #define bfd_elf32_close_and_cleanup elf32_arm_close_and_cleanup
7776 #define bfd_elf32_bfd_final_link elf32_arm_bfd_final_link
7778 #define elf_backend_get_symbol_type elf32_arm_get_symbol_type
7779 #define elf_backend_gc_mark_hook elf32_arm_gc_mark_hook
7780 #define elf_backend_gc_sweep_hook elf32_arm_gc_sweep_hook
7781 #define elf_backend_check_relocs elf32_arm_check_relocs
7782 #define elf_backend_relocate_section elf32_arm_relocate_section
7783 #define elf_backend_write_section elf32_arm_write_section
7784 #define elf_backend_adjust_dynamic_symbol elf32_arm_adjust_dynamic_symbol
7785 #define elf_backend_create_dynamic_sections elf32_arm_create_dynamic_sections
7786 #define elf_backend_finish_dynamic_symbol elf32_arm_finish_dynamic_symbol
7787 #define elf_backend_finish_dynamic_sections elf32_arm_finish_dynamic_sections
7788 #define elf_backend_link_output_symbol_hook elf32_arm_output_symbol_hook
7789 #define elf_backend_size_dynamic_sections elf32_arm_size_dynamic_sections
7790 #define elf_backend_post_process_headers elf32_arm_post_process_headers
7791 #define elf_backend_reloc_type_class elf32_arm_reloc_type_class
7792 #define elf_backend_object_p elf32_arm_object_p
7793 #define elf_backend_section_flags elf32_arm_section_flags
7794 #define elf_backend_fake_sections elf32_arm_fake_sections
7795 #define elf_backend_section_from_shdr elf32_arm_section_from_shdr
7796 #define elf_backend_final_write_processing elf32_arm_final_write_processing
7797 #define elf_backend_copy_indirect_symbol elf32_arm_copy_indirect_symbol
7798 #define elf_backend_symbol_processing elf32_arm_symbol_processing
7799 #define elf_backend_size_info elf32_arm_size_info
7800 #define elf_backend_modify_segment_map elf32_arm_modify_segment_map
7801 #define elf_backend_additional_program_headers \
7802 elf32_arm_additional_program_headers
7804 #define elf_backend_can_refcount 1
7805 #define elf_backend_can_gc_sections 1
7806 #define elf_backend_plt_readonly 1
7807 #define elf_backend_want_got_plt 1
7808 #define elf_backend_want_plt_sym 0
7809 #define elf_backend_may_use_rel_p 1
7810 #define elf_backend_may_use_rela_p 0
7811 #define elf_backend_default_use_rela_p 0
7812 #define elf_backend_rela_normal 0
7814 #define elf_backend_got_header_size 12
7816 #include "elf32-target.h"
7818 /* VxWorks Targets */
7820 #undef TARGET_LITTLE_SYM
7821 #define TARGET_LITTLE_SYM bfd_elf32_littlearm_vxworks_vec
7822 #undef TARGET_LITTLE_NAME
7823 #define TARGET_LITTLE_NAME "elf32-littlearm-vxworks"
7824 #undef TARGET_BIG_SYM
7825 #define TARGET_BIG_SYM bfd_elf32_bigarm_vxworks_vec
7826 #undef TARGET_BIG_NAME
7827 #define TARGET_BIG_NAME "elf32-bigarm-vxworks"
7829 /* Like elf32_arm_link_hash_table_create -- but overrides
7830 appropriately for VxWorks. */
7831 static struct bfd_link_hash_table *
7832 elf32_arm_vxworks_link_hash_table_create (bfd *abfd)
7834 struct bfd_link_hash_table *ret;
7836 ret = elf32_arm_link_hash_table_create (abfd);
7837 if (ret)
7839 struct elf32_arm_link_hash_table *htab
7840 = (struct elf32_arm_link_hash_table *)ret;
7841 htab->use_rel = 0;
7843 return ret;
7846 #undef elf32_bed
7847 #define elf32_bed elf32_arm_vxworks_bed
7849 #undef bfd_elf32_bfd_link_hash_table_create
7850 #define bfd_elf32_bfd_link_hash_table_create \
7851 elf32_arm_vxworks_link_hash_table_create
7853 #undef elf_backend_may_use_rel_p
7854 #define elf_backend_may_use_rel_p 0
7855 #undef elf_backend_may_use_rela_p
7856 #define elf_backend_may_use_rela_p 1
7857 #undef elf_backend_default_use_rela_p
7858 #define elf_backend_default_use_rela_p 1
7859 #undef elf_backend_rela_normal
7860 #define elf_backend_rela_normal 1
7862 #include "elf32-target.h"
7865 /* Symbian OS Targets */
7867 #undef TARGET_LITTLE_SYM
7868 #define TARGET_LITTLE_SYM bfd_elf32_littlearm_symbian_vec
7869 #undef TARGET_LITTLE_NAME
7870 #define TARGET_LITTLE_NAME "elf32-littlearm-symbian"
7871 #undef TARGET_BIG_SYM
7872 #define TARGET_BIG_SYM bfd_elf32_bigarm_symbian_vec
7873 #undef TARGET_BIG_NAME
7874 #define TARGET_BIG_NAME "elf32-bigarm-symbian"
7876 /* Like elf32_arm_link_hash_table_create -- but overrides
7877 appropriately for Symbian OS. */
7878 static struct bfd_link_hash_table *
7879 elf32_arm_symbian_link_hash_table_create (bfd *abfd)
7881 struct bfd_link_hash_table *ret;
7883 ret = elf32_arm_link_hash_table_create (abfd);
7884 if (ret)
7886 struct elf32_arm_link_hash_table *htab
7887 = (struct elf32_arm_link_hash_table *)ret;
7888 /* There is no PLT header for Symbian OS. */
7889 htab->plt_header_size = 0;
7890 /* The PLT entries are each three instructions. */
7891 htab->plt_entry_size = 4 * NUM_ELEM (elf32_arm_symbian_plt_entry);
7892 htab->symbian_p = 1;
7893 /* Symbian uses armv5t or above, so use_blx is always true. */
7894 htab->use_blx = 1;
7895 htab->root.is_relocatable_executable = 1;
7897 return ret;
7900 static const struct bfd_elf_special_section
7901 elf32_arm_symbian_special_sections[] =
7903 /* In a BPABI executable, the dynamic linking sections do not go in
7904 the loadable read-only segment. The post-linker may wish to
7905 refer to these sections, but they are not part of the final
7906 program image. */
7907 { ".dynamic", 8, 0, SHT_DYNAMIC, 0 },
7908 { ".dynstr", 7, 0, SHT_STRTAB, 0 },
7909 { ".dynsym", 7, 0, SHT_DYNSYM, 0 },
7910 { ".got", 4, 0, SHT_PROGBITS, 0 },
7911 { ".hash", 5, 0, SHT_HASH, 0 },
7912 /* These sections do not need to be writable as the SymbianOS
7913 postlinker will arrange things so that no dynamic relocation is
7914 required. */
7915 { ".init_array", 11, 0, SHT_INIT_ARRAY, SHF_ALLOC },
7916 { ".fini_array", 11, 0, SHT_FINI_ARRAY, SHF_ALLOC },
7917 { ".preinit_array", 14, 0, SHT_PREINIT_ARRAY, SHF_ALLOC },
7918 { NULL, 0, 0, 0, 0 }
7921 static void
7922 elf32_arm_symbian_begin_write_processing (bfd *abfd,
7923 struct bfd_link_info *link_info
7924 ATTRIBUTE_UNUSED)
7926 /* BPABI objects are never loaded directly by an OS kernel; they are
7927 processed by a postlinker first, into an OS-specific format. If
7928 the D_PAGED bit is set on the file, BFD will align segments on
7929 page boundaries, so that an OS can directly map the file. With
7930 BPABI objects, that just results in wasted space. In addition,
7931 because we clear the D_PAGED bit, map_sections_to_segments will
7932 recognize that the program headers should not be mapped into any
7933 loadable segment. */
7934 abfd->flags &= ~D_PAGED;
7937 static bfd_boolean
7938 elf32_arm_symbian_modify_segment_map (bfd *abfd,
7939 struct bfd_link_info *info)
7941 struct elf_segment_map *m;
7942 asection *dynsec;
7944 /* BPABI shared libraries and executables should have a PT_DYNAMIC
7945 segment. However, because the .dynamic section is not marked
7946 with SEC_LOAD, the generic ELF code will not create such a
7947 segment. */
7948 dynsec = bfd_get_section_by_name (abfd, ".dynamic");
7949 if (dynsec)
7951 m = _bfd_elf_make_dynamic_segment (abfd, dynsec);
7952 m->next = elf_tdata (abfd)->segment_map;
7953 elf_tdata (abfd)->segment_map = m;
7956 /* Also call the generic arm routine. */
7957 return elf32_arm_modify_segment_map (abfd, info);
7960 #undef elf32_bed
7961 #define elf32_bed elf32_arm_symbian_bed
7963 /* The dynamic sections are not allocated on SymbianOS; the postlinker
7964 will process them and then discard them. */
7965 #undef ELF_DYNAMIC_SEC_FLAGS
7966 #define ELF_DYNAMIC_SEC_FLAGS \
7967 (SEC_HAS_CONTENTS | SEC_IN_MEMORY | SEC_LINKER_CREATED)
7969 #undef bfd_elf32_bfd_link_hash_table_create
7970 #define bfd_elf32_bfd_link_hash_table_create \
7971 elf32_arm_symbian_link_hash_table_create
7973 #undef elf_backend_special_sections
7974 #define elf_backend_special_sections elf32_arm_symbian_special_sections
7976 #undef elf_backend_begin_write_processing
7977 #define elf_backend_begin_write_processing \
7978 elf32_arm_symbian_begin_write_processing
7980 #undef elf_backend_modify_segment_map
7981 #define elf_backend_modify_segment_map elf32_arm_symbian_modify_segment_map
7983 /* There is no .got section for BPABI objects, and hence no header. */
7984 #undef elf_backend_got_header_size
7985 #define elf_backend_got_header_size 0
7987 /* Similarly, there is no .got.plt section. */
7988 #undef elf_backend_want_got_plt
7989 #define elf_backend_want_got_plt 0
7991 #undef elf_backend_may_use_rel_p
7992 #define elf_backend_may_use_rel_p 1
7993 #undef elf_backend_may_use_rela_p
7994 #define elf_backend_may_use_rela_p 0
7995 #undef elf_backend_default_use_rela_p
7996 #define elf_backend_default_use_rela_p 0
7997 #undef elf_backend_rela_normal
7998 #define elf_backend_rela_normal 0
8000 #include "elf32-target.h"