gas/
[binutils.git] / bfd / elf32-arm.c
blobaf46138baa64f1ba7d1ddf930eda52537d02d9c5
1 /* 32-bit ELF support for ARM
2 Copyright 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005
3 Free Software Foundation, Inc.
5 This file is part of BFD, the Binary File Descriptor library.
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA. */
21 #include "elf/arm.h"
22 #include "bfd.h"
23 #include "sysdep.h"
24 #include "libbfd.h"
25 #include "elf-bfd.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 static reloc_howto_type * elf32_arm_reloc_type_lookup
38 PARAMS ((bfd * abfd, bfd_reloc_code_real_type code));
39 static bfd_boolean elf32_arm_nabi_grok_prstatus
40 PARAMS ((bfd *abfd, Elf_Internal_Note *note));
41 static bfd_boolean elf32_arm_nabi_grok_psinfo
42 PARAMS ((bfd *abfd, Elf_Internal_Note *note));
44 /* Note: code such as elf32_arm_reloc_type_lookup expect to use e.g.
45 R_ARM_PC24 as an index into this, and find the R_ARM_PC24 HOWTO
46 in that slot. */
48 static reloc_howto_type elf32_arm_howto_table_1[] =
50 /* No relocation */
51 HOWTO (R_ARM_NONE, /* type */
52 0, /* rightshift */
53 0, /* size (0 = byte, 1 = short, 2 = long) */
54 0, /* bitsize */
55 FALSE, /* pc_relative */
56 0, /* bitpos */
57 complain_overflow_dont,/* complain_on_overflow */
58 bfd_elf_generic_reloc, /* special_function */
59 "R_ARM_NONE", /* name */
60 FALSE, /* partial_inplace */
61 0, /* src_mask */
62 0, /* dst_mask */
63 FALSE), /* pcrel_offset */
65 HOWTO (R_ARM_PC24, /* type */
66 2, /* rightshift */
67 2, /* size (0 = byte, 1 = short, 2 = long) */
68 24, /* bitsize */
69 TRUE, /* pc_relative */
70 0, /* bitpos */
71 complain_overflow_signed,/* complain_on_overflow */
72 bfd_elf_generic_reloc, /* special_function */
73 "R_ARM_PC24", /* name */
74 FALSE, /* partial_inplace */
75 0x00ffffff, /* src_mask */
76 0x00ffffff, /* dst_mask */
77 TRUE), /* pcrel_offset */
79 /* 32 bit absolute */
80 HOWTO (R_ARM_ABS32, /* type */
81 0, /* rightshift */
82 2, /* size (0 = byte, 1 = short, 2 = long) */
83 32, /* bitsize */
84 FALSE, /* pc_relative */
85 0, /* bitpos */
86 complain_overflow_bitfield,/* complain_on_overflow */
87 bfd_elf_generic_reloc, /* special_function */
88 "R_ARM_ABS32", /* name */
89 FALSE, /* partial_inplace */
90 0xffffffff, /* src_mask */
91 0xffffffff, /* dst_mask */
92 FALSE), /* pcrel_offset */
94 /* standard 32bit pc-relative reloc */
95 HOWTO (R_ARM_REL32, /* type */
96 0, /* rightshift */
97 2, /* size (0 = byte, 1 = short, 2 = long) */
98 32, /* bitsize */
99 TRUE, /* pc_relative */
100 0, /* bitpos */
101 complain_overflow_bitfield,/* complain_on_overflow */
102 bfd_elf_generic_reloc, /* special_function */
103 "R_ARM_REL32", /* name */
104 FALSE, /* partial_inplace */
105 0xffffffff, /* src_mask */
106 0xffffffff, /* dst_mask */
107 TRUE), /* pcrel_offset */
109 /* 8 bit absolute - R_ARM_LDR_PC_G0 in AAELF */
110 HOWTO (R_ARM_PC13, /* type */
111 0, /* rightshift */
112 0, /* size (0 = byte, 1 = short, 2 = long) */
113 8, /* bitsize */
114 FALSE, /* pc_relative */
115 0, /* bitpos */
116 complain_overflow_bitfield,/* complain_on_overflow */
117 bfd_elf_generic_reloc, /* special_function */
118 "R_ARM_PC13", /* name */
119 FALSE, /* partial_inplace */
120 0x000000ff, /* src_mask */
121 0x000000ff, /* dst_mask */
122 FALSE), /* pcrel_offset */
124 /* 16 bit absolute */
125 HOWTO (R_ARM_ABS16, /* type */
126 0, /* rightshift */
127 1, /* size (0 = byte, 1 = short, 2 = long) */
128 16, /* bitsize */
129 FALSE, /* pc_relative */
130 0, /* bitpos */
131 complain_overflow_bitfield,/* complain_on_overflow */
132 bfd_elf_generic_reloc, /* special_function */
133 "R_ARM_ABS16", /* name */
134 FALSE, /* partial_inplace */
135 0x0000ffff, /* src_mask */
136 0x0000ffff, /* dst_mask */
137 FALSE), /* pcrel_offset */
139 /* 12 bit absolute */
140 HOWTO (R_ARM_ABS12, /* type */
141 0, /* rightshift */
142 2, /* size (0 = byte, 1 = short, 2 = long) */
143 12, /* bitsize */
144 FALSE, /* pc_relative */
145 0, /* bitpos */
146 complain_overflow_bitfield,/* complain_on_overflow */
147 bfd_elf_generic_reloc, /* special_function */
148 "R_ARM_ABS12", /* name */
149 FALSE, /* partial_inplace */
150 0x000008ff, /* src_mask */
151 0x000008ff, /* dst_mask */
152 FALSE), /* pcrel_offset */
154 HOWTO (R_ARM_THM_ABS5, /* type */
155 6, /* rightshift */
156 1, /* size (0 = byte, 1 = short, 2 = long) */
157 5, /* bitsize */
158 FALSE, /* pc_relative */
159 0, /* bitpos */
160 complain_overflow_bitfield,/* complain_on_overflow */
161 bfd_elf_generic_reloc, /* special_function */
162 "R_ARM_THM_ABS5", /* name */
163 FALSE, /* partial_inplace */
164 0x000007e0, /* src_mask */
165 0x000007e0, /* dst_mask */
166 FALSE), /* pcrel_offset */
168 /* 8 bit absolute */
169 HOWTO (R_ARM_ABS8, /* type */
170 0, /* rightshift */
171 0, /* size (0 = byte, 1 = short, 2 = long) */
172 8, /* bitsize */
173 FALSE, /* pc_relative */
174 0, /* bitpos */
175 complain_overflow_bitfield,/* complain_on_overflow */
176 bfd_elf_generic_reloc, /* special_function */
177 "R_ARM_ABS8", /* name */
178 FALSE, /* partial_inplace */
179 0x000000ff, /* src_mask */
180 0x000000ff, /* dst_mask */
181 FALSE), /* pcrel_offset */
183 HOWTO (R_ARM_SBREL32, /* type */
184 0, /* rightshift */
185 2, /* size (0 = byte, 1 = short, 2 = long) */
186 32, /* bitsize */
187 FALSE, /* pc_relative */
188 0, /* bitpos */
189 complain_overflow_dont,/* complain_on_overflow */
190 bfd_elf_generic_reloc, /* special_function */
191 "R_ARM_SBREL32", /* name */
192 FALSE, /* partial_inplace */
193 0xffffffff, /* src_mask */
194 0xffffffff, /* dst_mask */
195 FALSE), /* pcrel_offset */
197 /* FIXME: Has two more bits of offset in Thumb32. */
198 HOWTO (R_ARM_THM_CALL, /* type */
199 1, /* rightshift */
200 2, /* size (0 = byte, 1 = short, 2 = long) */
201 23, /* bitsize */
202 TRUE, /* pc_relative */
203 0, /* bitpos */
204 complain_overflow_signed,/* complain_on_overflow */
205 bfd_elf_generic_reloc, /* special_function */
206 "R_ARM_THM_CALL", /* name */
207 FALSE, /* partial_inplace */
208 0x07ff07ff, /* src_mask */
209 0x07ff07ff, /* dst_mask */
210 TRUE), /* pcrel_offset */
212 HOWTO (R_ARM_THM_PC8, /* type */
213 1, /* rightshift */
214 1, /* size (0 = byte, 1 = short, 2 = long) */
215 8, /* bitsize */
216 TRUE, /* pc_relative */
217 0, /* bitpos */
218 complain_overflow_signed,/* complain_on_overflow */
219 bfd_elf_generic_reloc, /* special_function */
220 "R_ARM_THM_PC8", /* name */
221 FALSE, /* partial_inplace */
222 0x000000ff, /* src_mask */
223 0x000000ff, /* dst_mask */
224 TRUE), /* pcrel_offset */
226 HOWTO (R_ARM_BREL_ADJ, /* type */
227 1, /* rightshift */
228 1, /* size (0 = byte, 1 = short, 2 = long) */
229 32, /* bitsize */
230 FALSE, /* pc_relative */
231 0, /* bitpos */
232 complain_overflow_signed,/* complain_on_overflow */
233 bfd_elf_generic_reloc, /* special_function */
234 "R_ARM_BREL_ADJ", /* name */
235 FALSE, /* partial_inplace */
236 0xffffffff, /* src_mask */
237 0xffffffff, /* dst_mask */
238 FALSE), /* pcrel_offset */
240 HOWTO (R_ARM_SWI24, /* type */
241 0, /* rightshift */
242 0, /* size (0 = byte, 1 = short, 2 = long) */
243 0, /* bitsize */
244 FALSE, /* pc_relative */
245 0, /* bitpos */
246 complain_overflow_signed,/* complain_on_overflow */
247 bfd_elf_generic_reloc, /* special_function */
248 "R_ARM_SWI24", /* name */
249 FALSE, /* partial_inplace */
250 0x00000000, /* src_mask */
251 0x00000000, /* dst_mask */
252 FALSE), /* pcrel_offset */
254 HOWTO (R_ARM_THM_SWI8, /* type */
255 0, /* rightshift */
256 0, /* size (0 = byte, 1 = short, 2 = long) */
257 0, /* bitsize */
258 FALSE, /* pc_relative */
259 0, /* bitpos */
260 complain_overflow_signed,/* complain_on_overflow */
261 bfd_elf_generic_reloc, /* special_function */
262 "R_ARM_SWI8", /* name */
263 FALSE, /* partial_inplace */
264 0x00000000, /* src_mask */
265 0x00000000, /* dst_mask */
266 FALSE), /* pcrel_offset */
268 /* BLX instruction for the ARM. */
269 HOWTO (R_ARM_XPC25, /* type */
270 2, /* rightshift */
271 2, /* size (0 = byte, 1 = short, 2 = long) */
272 25, /* bitsize */
273 TRUE, /* pc_relative */
274 0, /* bitpos */
275 complain_overflow_signed,/* complain_on_overflow */
276 bfd_elf_generic_reloc, /* special_function */
277 "R_ARM_XPC25", /* name */
278 FALSE, /* partial_inplace */
279 0x00ffffff, /* src_mask */
280 0x00ffffff, /* dst_mask */
281 TRUE), /* pcrel_offset */
283 /* BLX instruction for the Thumb. */
284 HOWTO (R_ARM_THM_XPC22, /* type */
285 2, /* rightshift */
286 2, /* size (0 = byte, 1 = short, 2 = long) */
287 22, /* bitsize */
288 TRUE, /* pc_relative */
289 0, /* bitpos */
290 complain_overflow_signed,/* complain_on_overflow */
291 bfd_elf_generic_reloc, /* special_function */
292 "R_ARM_THM_XPC22", /* name */
293 FALSE, /* partial_inplace */
294 0x07ff07ff, /* src_mask */
295 0x07ff07ff, /* dst_mask */
296 TRUE), /* pcrel_offset */
298 /* Dynamic TLS relocations. */
300 HOWTO (R_ARM_TLS_DTPMOD32, /* type */
301 0, /* rightshift */
302 2, /* size (0 = byte, 1 = short, 2 = long) */
303 32, /* bitsize */
304 FALSE, /* pc_relative */
305 0, /* bitpos */
306 complain_overflow_bitfield,/* complain_on_overflow */
307 bfd_elf_generic_reloc, /* special_function */
308 "R_ARM_TLS_DTPMOD32", /* name */
309 TRUE, /* partial_inplace */
310 0xffffffff, /* src_mask */
311 0xffffffff, /* dst_mask */
312 FALSE), /* pcrel_offset */
314 HOWTO (R_ARM_TLS_DTPOFF32, /* type */
315 0, /* rightshift */
316 2, /* size (0 = byte, 1 = short, 2 = long) */
317 32, /* bitsize */
318 FALSE, /* pc_relative */
319 0, /* bitpos */
320 complain_overflow_bitfield,/* complain_on_overflow */
321 bfd_elf_generic_reloc, /* special_function */
322 "R_ARM_TLS_DTPOFF32", /* name */
323 TRUE, /* partial_inplace */
324 0xffffffff, /* src_mask */
325 0xffffffff, /* dst_mask */
326 FALSE), /* pcrel_offset */
328 HOWTO (R_ARM_TLS_TPOFF32, /* type */
329 0, /* rightshift */
330 2, /* size (0 = byte, 1 = short, 2 = long) */
331 32, /* bitsize */
332 FALSE, /* pc_relative */
333 0, /* bitpos */
334 complain_overflow_bitfield,/* complain_on_overflow */
335 bfd_elf_generic_reloc, /* special_function */
336 "R_ARM_TLS_TPOFF32", /* name */
337 TRUE, /* partial_inplace */
338 0xffffffff, /* src_mask */
339 0xffffffff, /* dst_mask */
340 FALSE), /* pcrel_offset */
342 /* Relocs used in ARM Linux */
344 HOWTO (R_ARM_COPY, /* type */
345 0, /* rightshift */
346 2, /* size (0 = byte, 1 = short, 2 = long) */
347 32, /* bitsize */
348 FALSE, /* pc_relative */
349 0, /* bitpos */
350 complain_overflow_bitfield,/* complain_on_overflow */
351 bfd_elf_generic_reloc, /* special_function */
352 "R_ARM_COPY", /* name */
353 TRUE, /* partial_inplace */
354 0xffffffff, /* src_mask */
355 0xffffffff, /* dst_mask */
356 FALSE), /* pcrel_offset */
358 HOWTO (R_ARM_GLOB_DAT, /* type */
359 0, /* rightshift */
360 2, /* size (0 = byte, 1 = short, 2 = long) */
361 32, /* bitsize */
362 FALSE, /* pc_relative */
363 0, /* bitpos */
364 complain_overflow_bitfield,/* complain_on_overflow */
365 bfd_elf_generic_reloc, /* special_function */
366 "R_ARM_GLOB_DAT", /* name */
367 TRUE, /* partial_inplace */
368 0xffffffff, /* src_mask */
369 0xffffffff, /* dst_mask */
370 FALSE), /* pcrel_offset */
372 HOWTO (R_ARM_JUMP_SLOT, /* type */
373 0, /* rightshift */
374 2, /* size (0 = byte, 1 = short, 2 = long) */
375 32, /* bitsize */
376 FALSE, /* pc_relative */
377 0, /* bitpos */
378 complain_overflow_bitfield,/* complain_on_overflow */
379 bfd_elf_generic_reloc, /* special_function */
380 "R_ARM_JUMP_SLOT", /* name */
381 TRUE, /* partial_inplace */
382 0xffffffff, /* src_mask */
383 0xffffffff, /* dst_mask */
384 FALSE), /* pcrel_offset */
386 HOWTO (R_ARM_RELATIVE, /* type */
387 0, /* rightshift */
388 2, /* size (0 = byte, 1 = short, 2 = long) */
389 32, /* bitsize */
390 FALSE, /* pc_relative */
391 0, /* bitpos */
392 complain_overflow_bitfield,/* complain_on_overflow */
393 bfd_elf_generic_reloc, /* special_function */
394 "R_ARM_RELATIVE", /* name */
395 TRUE, /* partial_inplace */
396 0xffffffff, /* src_mask */
397 0xffffffff, /* dst_mask */
398 FALSE), /* pcrel_offset */
400 HOWTO (R_ARM_GOTOFF32, /* type */
401 0, /* rightshift */
402 2, /* size (0 = byte, 1 = short, 2 = long) */
403 32, /* bitsize */
404 FALSE, /* pc_relative */
405 0, /* bitpos */
406 complain_overflow_bitfield,/* complain_on_overflow */
407 bfd_elf_generic_reloc, /* special_function */
408 "R_ARM_GOTOFF32", /* name */
409 TRUE, /* partial_inplace */
410 0xffffffff, /* src_mask */
411 0xffffffff, /* dst_mask */
412 FALSE), /* pcrel_offset */
414 HOWTO (R_ARM_GOTPC, /* type */
415 0, /* rightshift */
416 2, /* size (0 = byte, 1 = short, 2 = long) */
417 32, /* bitsize */
418 TRUE, /* pc_relative */
419 0, /* bitpos */
420 complain_overflow_bitfield,/* complain_on_overflow */
421 bfd_elf_generic_reloc, /* special_function */
422 "R_ARM_GOTPC", /* name */
423 TRUE, /* partial_inplace */
424 0xffffffff, /* src_mask */
425 0xffffffff, /* dst_mask */
426 TRUE), /* pcrel_offset */
428 HOWTO (R_ARM_GOT32, /* type */
429 0, /* rightshift */
430 2, /* size (0 = byte, 1 = short, 2 = long) */
431 32, /* bitsize */
432 FALSE, /* pc_relative */
433 0, /* bitpos */
434 complain_overflow_bitfield,/* complain_on_overflow */
435 bfd_elf_generic_reloc, /* special_function */
436 "R_ARM_GOT32", /* name */
437 TRUE, /* partial_inplace */
438 0xffffffff, /* src_mask */
439 0xffffffff, /* dst_mask */
440 FALSE), /* pcrel_offset */
442 HOWTO (R_ARM_PLT32, /* type */
443 2, /* rightshift */
444 2, /* size (0 = byte, 1 = short, 2 = long) */
445 26, /* bitsize */
446 TRUE, /* pc_relative */
447 0, /* bitpos */
448 complain_overflow_bitfield,/* complain_on_overflow */
449 bfd_elf_generic_reloc, /* special_function */
450 "R_ARM_PLT32", /* name */
451 TRUE, /* partial_inplace */
452 0x00ffffff, /* src_mask */
453 0x00ffffff, /* dst_mask */
454 TRUE), /* pcrel_offset */
456 HOWTO (R_ARM_CALL, /* type */
457 2, /* rightshift */
458 2, /* size (0 = byte, 1 = short, 2 = long) */
459 24, /* bitsize */
460 TRUE, /* pc_relative */
461 0, /* bitpos */
462 complain_overflow_signed,/* complain_on_overflow */
463 bfd_elf_generic_reloc, /* special_function */
464 "R_ARM_CALL", /* name */
465 FALSE, /* partial_inplace */
466 0x00ffffff, /* src_mask */
467 0x00ffffff, /* dst_mask */
468 TRUE), /* pcrel_offset */
470 HOWTO (R_ARM_JUMP24, /* type */
471 2, /* rightshift */
472 2, /* size (0 = byte, 1 = short, 2 = long) */
473 24, /* bitsize */
474 TRUE, /* pc_relative */
475 0, /* bitpos */
476 complain_overflow_signed,/* complain_on_overflow */
477 bfd_elf_generic_reloc, /* special_function */
478 "R_ARM_JUMP24", /* name */
479 FALSE, /* partial_inplace */
480 0x00ffffff, /* src_mask */
481 0x00ffffff, /* dst_mask */
482 TRUE), /* pcrel_offset */
484 HOWTO (R_ARM_THM_JUMP24, /* type */
485 1, /* rightshift */
486 2, /* size (0 = byte, 1 = short, 2 = long) */
487 24, /* bitsize */
488 TRUE, /* pc_relative */
489 0, /* bitpos */
490 complain_overflow_signed,/* complain_on_overflow */
491 bfd_elf_generic_reloc, /* special_function */
492 "R_ARM_THM_JUMP24", /* name */
493 FALSE, /* partial_inplace */
494 0x07ff2fff, /* src_mask */
495 0x07ff2fff, /* dst_mask */
496 TRUE), /* pcrel_offset */
498 HOWTO (R_ARM_BASE_ABS, /* type */
499 0, /* rightshift */
500 2, /* size (0 = byte, 1 = short, 2 = long) */
501 32, /* bitsize */
502 FALSE, /* pc_relative */
503 0, /* bitpos */
504 complain_overflow_dont,/* complain_on_overflow */
505 bfd_elf_generic_reloc, /* special_function */
506 "R_ARM_BASE_ABS", /* name */
507 FALSE, /* partial_inplace */
508 0xffffffff, /* src_mask */
509 0xffffffff, /* dst_mask */
510 FALSE), /* pcrel_offset */
512 HOWTO (R_ARM_ALU_PCREL7_0, /* type */
513 0, /* rightshift */
514 2, /* size (0 = byte, 1 = short, 2 = long) */
515 12, /* bitsize */
516 TRUE, /* pc_relative */
517 0, /* bitpos */
518 complain_overflow_dont,/* complain_on_overflow */
519 bfd_elf_generic_reloc, /* special_function */
520 "R_ARM_ALU_PCREL_7_0", /* name */
521 FALSE, /* partial_inplace */
522 0x00000fff, /* src_mask */
523 0x00000fff, /* dst_mask */
524 TRUE), /* pcrel_offset */
526 HOWTO (R_ARM_ALU_PCREL15_8, /* type */
527 0, /* rightshift */
528 2, /* size (0 = byte, 1 = short, 2 = long) */
529 12, /* bitsize */
530 TRUE, /* pc_relative */
531 8, /* bitpos */
532 complain_overflow_dont,/* complain_on_overflow */
533 bfd_elf_generic_reloc, /* special_function */
534 "R_ARM_ALU_PCREL_15_8",/* name */
535 FALSE, /* partial_inplace */
536 0x00000fff, /* src_mask */
537 0x00000fff, /* dst_mask */
538 TRUE), /* pcrel_offset */
540 HOWTO (R_ARM_ALU_PCREL23_15, /* type */
541 0, /* rightshift */
542 2, /* size (0 = byte, 1 = short, 2 = long) */
543 12, /* bitsize */
544 TRUE, /* pc_relative */
545 16, /* bitpos */
546 complain_overflow_dont,/* complain_on_overflow */
547 bfd_elf_generic_reloc, /* special_function */
548 "R_ARM_ALU_PCREL_23_15",/* name */
549 FALSE, /* partial_inplace */
550 0x00000fff, /* src_mask */
551 0x00000fff, /* dst_mask */
552 TRUE), /* pcrel_offset */
554 HOWTO (R_ARM_LDR_SBREL_11_0, /* type */
555 0, /* rightshift */
556 2, /* size (0 = byte, 1 = short, 2 = long) */
557 12, /* bitsize */
558 FALSE, /* pc_relative */
559 0, /* bitpos */
560 complain_overflow_dont,/* complain_on_overflow */
561 bfd_elf_generic_reloc, /* special_function */
562 "R_ARM_LDR_SBREL_11_0",/* name */
563 FALSE, /* partial_inplace */
564 0x00000fff, /* src_mask */
565 0x00000fff, /* dst_mask */
566 FALSE), /* pcrel_offset */
568 HOWTO (R_ARM_ALU_SBREL_19_12, /* type */
569 0, /* rightshift */
570 2, /* size (0 = byte, 1 = short, 2 = long) */
571 8, /* bitsize */
572 FALSE, /* pc_relative */
573 12, /* bitpos */
574 complain_overflow_dont,/* complain_on_overflow */
575 bfd_elf_generic_reloc, /* special_function */
576 "R_ARM_ALU_SBREL_19_12",/* name */
577 FALSE, /* partial_inplace */
578 0x000ff000, /* src_mask */
579 0x000ff000, /* dst_mask */
580 FALSE), /* pcrel_offset */
582 HOWTO (R_ARM_ALU_SBREL_27_20, /* type */
583 0, /* rightshift */
584 2, /* size (0 = byte, 1 = short, 2 = long) */
585 8, /* bitsize */
586 FALSE, /* pc_relative */
587 20, /* bitpos */
588 complain_overflow_dont,/* complain_on_overflow */
589 bfd_elf_generic_reloc, /* special_function */
590 "R_ARM_ALU_SBREL_27_20",/* name */
591 FALSE, /* partial_inplace */
592 0x0ff00000, /* src_mask */
593 0x0ff00000, /* dst_mask */
594 FALSE), /* pcrel_offset */
596 HOWTO (R_ARM_TARGET1, /* type */
597 0, /* rightshift */
598 2, /* size (0 = byte, 1 = short, 2 = long) */
599 32, /* bitsize */
600 FALSE, /* pc_relative */
601 0, /* bitpos */
602 complain_overflow_dont,/* complain_on_overflow */
603 bfd_elf_generic_reloc, /* special_function */
604 "R_ARM_TARGET1", /* name */
605 FALSE, /* partial_inplace */
606 0xffffffff, /* src_mask */
607 0xffffffff, /* dst_mask */
608 FALSE), /* pcrel_offset */
610 HOWTO (R_ARM_ROSEGREL32, /* type */
611 0, /* rightshift */
612 2, /* size (0 = byte, 1 = short, 2 = long) */
613 32, /* bitsize */
614 FALSE, /* pc_relative */
615 0, /* bitpos */
616 complain_overflow_dont,/* complain_on_overflow */
617 bfd_elf_generic_reloc, /* special_function */
618 "R_ARM_ROSEGREL32", /* name */
619 FALSE, /* partial_inplace */
620 0xffffffff, /* src_mask */
621 0xffffffff, /* dst_mask */
622 FALSE), /* pcrel_offset */
624 HOWTO (R_ARM_V4BX, /* type */
625 0, /* rightshift */
626 2, /* size (0 = byte, 1 = short, 2 = long) */
627 32, /* bitsize */
628 FALSE, /* pc_relative */
629 0, /* bitpos */
630 complain_overflow_dont,/* complain_on_overflow */
631 bfd_elf_generic_reloc, /* special_function */
632 "R_ARM_V4BX", /* name */
633 FALSE, /* partial_inplace */
634 0xffffffff, /* src_mask */
635 0xffffffff, /* dst_mask */
636 FALSE), /* pcrel_offset */
638 HOWTO (R_ARM_TARGET2, /* type */
639 0, /* rightshift */
640 2, /* size (0 = byte, 1 = short, 2 = long) */
641 32, /* bitsize */
642 FALSE, /* pc_relative */
643 0, /* bitpos */
644 complain_overflow_signed,/* complain_on_overflow */
645 bfd_elf_generic_reloc, /* special_function */
646 "R_ARM_TARGET2", /* name */
647 FALSE, /* partial_inplace */
648 0xffffffff, /* src_mask */
649 0xffffffff, /* dst_mask */
650 TRUE), /* pcrel_offset */
652 HOWTO (R_ARM_PREL31, /* type */
653 0, /* rightshift */
654 2, /* size (0 = byte, 1 = short, 2 = long) */
655 31, /* bitsize */
656 TRUE, /* pc_relative */
657 0, /* bitpos */
658 complain_overflow_signed,/* complain_on_overflow */
659 bfd_elf_generic_reloc, /* special_function */
660 "R_ARM_PREL31", /* name */
661 FALSE, /* partial_inplace */
662 0x7fffffff, /* src_mask */
663 0x7fffffff, /* dst_mask */
664 TRUE), /* pcrel_offset */
666 HOWTO (R_ARM_MOVW_ABS_NC, /* type */
667 0, /* rightshift */
668 2, /* size (0 = byte, 1 = short, 2 = long) */
669 16, /* bitsize */
670 FALSE, /* pc_relative */
671 0, /* bitpos */
672 complain_overflow_dont,/* complain_on_overflow */
673 bfd_elf_generic_reloc, /* special_function */
674 "R_ARM_MOVW_ABS_NC", /* name */
675 FALSE, /* partial_inplace */
676 0x0000ffff, /* src_mask */
677 0x0000ffff, /* dst_mask */
678 FALSE), /* pcrel_offset */
680 HOWTO (R_ARM_MOVT_ABS, /* type */
681 0, /* rightshift */
682 2, /* size (0 = byte, 1 = short, 2 = long) */
683 16, /* bitsize */
684 FALSE, /* pc_relative */
685 0, /* bitpos */
686 complain_overflow_bitfield,/* complain_on_overflow */
687 bfd_elf_generic_reloc, /* special_function */
688 "R_ARM_MOVT_ABS", /* name */
689 FALSE, /* partial_inplace */
690 0x0000ffff, /* src_mask */
691 0x0000ffff, /* dst_mask */
692 FALSE), /* pcrel_offset */
694 HOWTO (R_ARM_MOVW_PREL_NC, /* type */
695 0, /* rightshift */
696 2, /* size (0 = byte, 1 = short, 2 = long) */
697 16, /* bitsize */
698 TRUE, /* pc_relative */
699 0, /* bitpos */
700 complain_overflow_dont,/* complain_on_overflow */
701 bfd_elf_generic_reloc, /* special_function */
702 "R_ARM_MOVW_PREL_NC", /* name */
703 FALSE, /* partial_inplace */
704 0x0000ffff, /* src_mask */
705 0x0000ffff, /* dst_mask */
706 TRUE), /* pcrel_offset */
708 HOWTO (R_ARM_MOVT_PREL, /* type */
709 0, /* rightshift */
710 2, /* size (0 = byte, 1 = short, 2 = long) */
711 16, /* bitsize */
712 TRUE, /* pc_relative */
713 0, /* bitpos */
714 complain_overflow_bitfield,/* complain_on_overflow */
715 bfd_elf_generic_reloc, /* special_function */
716 "R_ARM_MOVT_PREL", /* name */
717 FALSE, /* partial_inplace */
718 0x0000ffff, /* src_mask */
719 0x0000ffff, /* dst_mask */
720 TRUE), /* pcrel_offset */
722 HOWTO (R_ARM_THM_MOVW_ABS_NC, /* type */
723 0, /* rightshift */
724 2, /* size (0 = byte, 1 = short, 2 = long) */
725 16, /* bitsize */
726 FALSE, /* pc_relative */
727 0, /* bitpos */
728 complain_overflow_dont,/* complain_on_overflow */
729 bfd_elf_generic_reloc, /* special_function */
730 "R_ARM_THM_MOVW_ABS_NC",/* name */
731 FALSE, /* partial_inplace */
732 0x040f70ff, /* src_mask */
733 0x040f70ff, /* dst_mask */
734 FALSE), /* pcrel_offset */
736 HOWTO (R_ARM_THM_MOVT_ABS, /* type */
737 0, /* rightshift */
738 2, /* size (0 = byte, 1 = short, 2 = long) */
739 16, /* bitsize */
740 FALSE, /* pc_relative */
741 0, /* bitpos */
742 complain_overflow_bitfield,/* complain_on_overflow */
743 bfd_elf_generic_reloc, /* special_function */
744 "R_ARM_THM_MOVT_ABS", /* name */
745 FALSE, /* partial_inplace */
746 0x040f70ff, /* src_mask */
747 0x040f70ff, /* dst_mask */
748 FALSE), /* pcrel_offset */
750 HOWTO (R_ARM_THM_MOVW_PREL_NC,/* type */
751 0, /* rightshift */
752 2, /* size (0 = byte, 1 = short, 2 = long) */
753 16, /* bitsize */
754 TRUE, /* pc_relative */
755 0, /* bitpos */
756 complain_overflow_dont,/* complain_on_overflow */
757 bfd_elf_generic_reloc, /* special_function */
758 "R_ARM_THM_MOVW_PREL_NC",/* name */
759 FALSE, /* partial_inplace */
760 0x040f70ff, /* src_mask */
761 0x040f70ff, /* dst_mask */
762 TRUE), /* pcrel_offset */
764 HOWTO (R_ARM_THM_MOVT_PREL, /* type */
765 0, /* rightshift */
766 2, /* size (0 = byte, 1 = short, 2 = long) */
767 16, /* bitsize */
768 TRUE, /* pc_relative */
769 0, /* bitpos */
770 complain_overflow_bitfield,/* complain_on_overflow */
771 bfd_elf_generic_reloc, /* special_function */
772 "R_ARM_THM_MOVT_PREL", /* name */
773 FALSE, /* partial_inplace */
774 0x040f70ff, /* src_mask */
775 0x040f70ff, /* dst_mask */
776 TRUE), /* pcrel_offset */
778 HOWTO (R_ARM_THM_JUMP19, /* type */
779 1, /* rightshift */
780 2, /* size (0 = byte, 1 = short, 2 = long) */
781 19, /* bitsize */
782 TRUE, /* pc_relative */
783 0, /* bitpos */
784 complain_overflow_signed,/* complain_on_overflow */
785 bfd_elf_generic_reloc, /* special_function */
786 "R_ARM_THM_JUMP19", /* name */
787 FALSE, /* partial_inplace */
788 0x043f2fff, /* src_mask */
789 0x043f2fff, /* dst_mask */
790 TRUE), /* pcrel_offset */
792 HOWTO (R_ARM_THM_JUMP6, /* type */
793 1, /* rightshift */
794 1, /* size (0 = byte, 1 = short, 2 = long) */
795 6, /* bitsize */
796 TRUE, /* pc_relative */
797 0, /* bitpos */
798 complain_overflow_unsigned,/* complain_on_overflow */
799 bfd_elf_generic_reloc, /* special_function */
800 "R_ARM_THM_JUMP6", /* name */
801 FALSE, /* partial_inplace */
802 0x02f8, /* src_mask */
803 0x02f8, /* dst_mask */
804 TRUE), /* pcrel_offset */
806 /* These are declared as 13-bit signed relocations because we can
807 address -4095 .. 4095(base) by altering ADDW to SUBW or vice
808 versa. */
809 HOWTO (R_ARM_THM_ALU_PREL_11_0,/* type */
810 0, /* rightshift */
811 2, /* size (0 = byte, 1 = short, 2 = long) */
812 13, /* bitsize */
813 TRUE, /* pc_relative */
814 0, /* bitpos */
815 complain_overflow_signed,/* complain_on_overflow */
816 bfd_elf_generic_reloc, /* special_function */
817 "R_ARM_THM_ALU_PREL_11_0",/* name */
818 FALSE, /* partial_inplace */
819 0x040070ff, /* src_mask */
820 0x040070ff, /* dst_mask */
821 TRUE), /* pcrel_offset */
823 HOWTO (R_ARM_THM_PC12, /* type */
824 0, /* rightshift */
825 2, /* size (0 = byte, 1 = short, 2 = long) */
826 13, /* bitsize */
827 TRUE, /* pc_relative */
828 0, /* bitpos */
829 complain_overflow_signed,/* complain_on_overflow */
830 bfd_elf_generic_reloc, /* special_function */
831 "R_ARM_THM_PC12", /* name */
832 FALSE, /* partial_inplace */
833 0x040070ff, /* src_mask */
834 0x040070ff, /* dst_mask */
835 TRUE), /* pcrel_offset */
837 HOWTO (R_ARM_ABS32_NOI, /* type */
838 0, /* rightshift */
839 2, /* size (0 = byte, 1 = short, 2 = long) */
840 32, /* bitsize */
841 FALSE, /* pc_relative */
842 0, /* bitpos */
843 complain_overflow_dont,/* complain_on_overflow */
844 bfd_elf_generic_reloc, /* special_function */
845 "R_ARM_ABS32_NOI", /* name */
846 FALSE, /* partial_inplace */
847 0xffffffff, /* src_mask */
848 0xffffffff, /* dst_mask */
849 FALSE), /* pcrel_offset */
851 HOWTO (R_ARM_REL32_NOI, /* type */
852 0, /* rightshift */
853 2, /* size (0 = byte, 1 = short, 2 = long) */
854 32, /* bitsize */
855 TRUE, /* pc_relative */
856 0, /* bitpos */
857 complain_overflow_dont,/* complain_on_overflow */
858 bfd_elf_generic_reloc, /* special_function */
859 "R_ARM_REL32_NOI", /* name */
860 FALSE, /* partial_inplace */
861 0xffffffff, /* src_mask */
862 0xffffffff, /* dst_mask */
863 FALSE), /* pcrel_offset */
866 /* Relocations 57 .. 83 are the "group relocations" which we do not
867 support. */
869 static reloc_howto_type elf32_arm_howto_table_2[] =
871 HOWTO (R_ARM_MOVW_BREL_NC, /* type */
872 0, /* rightshift */
873 2, /* size (0 = byte, 1 = short, 2 = long) */
874 16, /* bitsize */
875 FALSE, /* pc_relative */
876 0, /* bitpos */
877 complain_overflow_dont,/* complain_on_overflow */
878 bfd_elf_generic_reloc, /* special_function */
879 "R_ARM_MOVW_BREL_NC", /* name */
880 FALSE, /* partial_inplace */
881 0x0000ffff, /* src_mask */
882 0x0000ffff, /* dst_mask */
883 FALSE), /* pcrel_offset */
885 HOWTO (R_ARM_MOVT_BREL, /* type */
886 0, /* rightshift */
887 2, /* size (0 = byte, 1 = short, 2 = long) */
888 16, /* bitsize */
889 FALSE, /* pc_relative */
890 0, /* bitpos */
891 complain_overflow_bitfield,/* complain_on_overflow */
892 bfd_elf_generic_reloc, /* special_function */
893 "R_ARM_MOVT_BREL", /* name */
894 FALSE, /* partial_inplace */
895 0x0000ffff, /* src_mask */
896 0x0000ffff, /* dst_mask */
897 FALSE), /* pcrel_offset */
899 HOWTO (R_ARM_MOVW_BREL, /* type */
900 0, /* rightshift */
901 2, /* size (0 = byte, 1 = short, 2 = long) */
902 16, /* bitsize */
903 FALSE, /* pc_relative */
904 0, /* bitpos */
905 complain_overflow_dont,/* complain_on_overflow */
906 bfd_elf_generic_reloc, /* special_function */
907 "R_ARM_MOVW_BREL", /* name */
908 FALSE, /* partial_inplace */
909 0x0000ffff, /* src_mask */
910 0x0000ffff, /* dst_mask */
911 FALSE), /* pcrel_offset */
913 HOWTO (R_ARM_THM_MOVW_BREL_NC,/* type */
914 0, /* rightshift */
915 2, /* size (0 = byte, 1 = short, 2 = long) */
916 16, /* bitsize */
917 FALSE, /* pc_relative */
918 0, /* bitpos */
919 complain_overflow_dont,/* complain_on_overflow */
920 bfd_elf_generic_reloc, /* special_function */
921 "R_ARM_THM_MOVW_BREL_NC",/* name */
922 FALSE, /* partial_inplace */
923 0x040f70ff, /* src_mask */
924 0x040f70ff, /* dst_mask */
925 FALSE), /* pcrel_offset */
927 HOWTO (R_ARM_THM_MOVT_BREL, /* type */
928 0, /* rightshift */
929 2, /* size (0 = byte, 1 = short, 2 = long) */
930 16, /* bitsize */
931 FALSE, /* pc_relative */
932 0, /* bitpos */
933 complain_overflow_bitfield,/* complain_on_overflow */
934 bfd_elf_generic_reloc, /* special_function */
935 "R_ARM_THM_MOVT_BREL", /* name */
936 FALSE, /* partial_inplace */
937 0x040f70ff, /* src_mask */
938 0x040f70ff, /* dst_mask */
939 FALSE), /* pcrel_offset */
941 HOWTO (R_ARM_THM_MOVW_BREL, /* type */
942 0, /* rightshift */
943 2, /* size (0 = byte, 1 = short, 2 = long) */
944 16, /* bitsize */
945 FALSE, /* pc_relative */
946 0, /* bitpos */
947 complain_overflow_dont,/* complain_on_overflow */
948 bfd_elf_generic_reloc, /* special_function */
949 "R_ARM_THM_MOVW_BREL", /* name */
950 FALSE, /* partial_inplace */
951 0x040f70ff, /* src_mask */
952 0x040f70ff, /* dst_mask */
953 FALSE), /* pcrel_offset */
955 EMPTY_HOWTO (90), /* unallocated */
956 EMPTY_HOWTO (91),
957 EMPTY_HOWTO (92),
958 EMPTY_HOWTO (93),
960 HOWTO (R_ARM_PLT32_ABS, /* type */
961 0, /* rightshift */
962 2, /* size (0 = byte, 1 = short, 2 = long) */
963 32, /* bitsize */
964 FALSE, /* pc_relative */
965 0, /* bitpos */
966 complain_overflow_dont,/* complain_on_overflow */
967 bfd_elf_generic_reloc, /* special_function */
968 "R_ARM_PLT32_ABS", /* name */
969 FALSE, /* partial_inplace */
970 0xffffffff, /* src_mask */
971 0xffffffff, /* dst_mask */
972 FALSE), /* pcrel_offset */
974 HOWTO (R_ARM_GOT_ABS, /* type */
975 0, /* rightshift */
976 2, /* size (0 = byte, 1 = short, 2 = long) */
977 32, /* bitsize */
978 FALSE, /* pc_relative */
979 0, /* bitpos */
980 complain_overflow_dont,/* complain_on_overflow */
981 bfd_elf_generic_reloc, /* special_function */
982 "R_ARM_GOT_ABS", /* name */
983 FALSE, /* partial_inplace */
984 0xffffffff, /* src_mask */
985 0xffffffff, /* dst_mask */
986 FALSE), /* pcrel_offset */
988 HOWTO (R_ARM_GOT_PREL, /* type */
989 0, /* rightshift */
990 2, /* size (0 = byte, 1 = short, 2 = long) */
991 32, /* bitsize */
992 TRUE, /* pc_relative */
993 0, /* bitpos */
994 complain_overflow_dont, /* complain_on_overflow */
995 bfd_elf_generic_reloc, /* special_function */
996 "R_ARM_GOT_PREL", /* name */
997 FALSE, /* partial_inplace */
998 0xffffffff, /* src_mask */
999 0xffffffff, /* dst_mask */
1000 TRUE), /* pcrel_offset */
1002 HOWTO (R_ARM_GOT_BREL12, /* type */
1003 0, /* rightshift */
1004 2, /* size (0 = byte, 1 = short, 2 = long) */
1005 12, /* bitsize */
1006 FALSE, /* pc_relative */
1007 0, /* bitpos */
1008 complain_overflow_bitfield,/* complain_on_overflow */
1009 bfd_elf_generic_reloc, /* special_function */
1010 "R_ARM_GOT_BREL12", /* name */
1011 FALSE, /* partial_inplace */
1012 0x00000fff, /* src_mask */
1013 0x00000fff, /* dst_mask */
1014 FALSE), /* pcrel_offset */
1016 HOWTO (R_ARM_GOTOFF12, /* type */
1017 0, /* rightshift */
1018 2, /* size (0 = byte, 1 = short, 2 = long) */
1019 12, /* bitsize */
1020 FALSE, /* pc_relative */
1021 0, /* bitpos */
1022 complain_overflow_bitfield,/* complain_on_overflow */
1023 bfd_elf_generic_reloc, /* special_function */
1024 "R_ARM_GOTOFF12", /* name */
1025 FALSE, /* partial_inplace */
1026 0x00000fff, /* src_mask */
1027 0x00000fff, /* dst_mask */
1028 FALSE), /* pcrel_offset */
1030 EMPTY_HOWTO (R_ARM_GOTRELAX), /* reserved for future GOT-load optimizations */
1032 /* GNU extension to record C++ vtable member usage */
1033 HOWTO (R_ARM_GNU_VTENTRY, /* type */
1034 0, /* rightshift */
1035 2, /* size (0 = byte, 1 = short, 2 = long) */
1036 0, /* bitsize */
1037 FALSE, /* pc_relative */
1038 0, /* bitpos */
1039 complain_overflow_dont, /* complain_on_overflow */
1040 _bfd_elf_rel_vtable_reloc_fn, /* special_function */
1041 "R_ARM_GNU_VTENTRY", /* name */
1042 FALSE, /* partial_inplace */
1043 0, /* src_mask */
1044 0, /* dst_mask */
1045 FALSE), /* pcrel_offset */
1047 /* GNU extension to record C++ vtable hierarchy */
1048 HOWTO (R_ARM_GNU_VTINHERIT, /* type */
1049 0, /* rightshift */
1050 2, /* size (0 = byte, 1 = short, 2 = long) */
1051 0, /* bitsize */
1052 FALSE, /* pc_relative */
1053 0, /* bitpos */
1054 complain_overflow_dont, /* complain_on_overflow */
1055 NULL, /* special_function */
1056 "R_ARM_GNU_VTINHERIT", /* name */
1057 FALSE, /* partial_inplace */
1058 0, /* src_mask */
1059 0, /* dst_mask */
1060 FALSE), /* pcrel_offset */
1062 HOWTO (R_ARM_THM_JUMP11, /* type */
1063 1, /* rightshift */
1064 1, /* size (0 = byte, 1 = short, 2 = long) */
1065 11, /* bitsize */
1066 TRUE, /* pc_relative */
1067 0, /* bitpos */
1068 complain_overflow_signed, /* complain_on_overflow */
1069 bfd_elf_generic_reloc, /* special_function */
1070 "R_ARM_THM_JUMP11", /* name */
1071 FALSE, /* partial_inplace */
1072 0x000007ff, /* src_mask */
1073 0x000007ff, /* dst_mask */
1074 TRUE), /* pcrel_offset */
1076 HOWTO (R_ARM_THM_JUMP8, /* type */
1077 1, /* rightshift */
1078 1, /* size (0 = byte, 1 = short, 2 = long) */
1079 8, /* bitsize */
1080 TRUE, /* pc_relative */
1081 0, /* bitpos */
1082 complain_overflow_signed, /* complain_on_overflow */
1083 bfd_elf_generic_reloc, /* special_function */
1084 "R_ARM_THM_JUMP8", /* name */
1085 FALSE, /* partial_inplace */
1086 0x000000ff, /* src_mask */
1087 0x000000ff, /* dst_mask */
1088 TRUE), /* pcrel_offset */
1090 /* TLS relocations */
1091 HOWTO (R_ARM_TLS_GD32, /* type */
1092 0, /* rightshift */
1093 2, /* size (0 = byte, 1 = short, 2 = long) */
1094 32, /* bitsize */
1095 FALSE, /* pc_relative */
1096 0, /* bitpos */
1097 complain_overflow_bitfield,/* complain_on_overflow */
1098 NULL, /* special_function */
1099 "R_ARM_TLS_GD32", /* name */
1100 TRUE, /* partial_inplace */
1101 0xffffffff, /* src_mask */
1102 0xffffffff, /* dst_mask */
1103 FALSE), /* pcrel_offset */
1105 HOWTO (R_ARM_TLS_LDM32, /* type */
1106 0, /* rightshift */
1107 2, /* size (0 = byte, 1 = short, 2 = long) */
1108 32, /* bitsize */
1109 FALSE, /* pc_relative */
1110 0, /* bitpos */
1111 complain_overflow_bitfield,/* complain_on_overflow */
1112 bfd_elf_generic_reloc, /* special_function */
1113 "R_ARM_TLS_LDM32", /* name */
1114 TRUE, /* partial_inplace */
1115 0xffffffff, /* src_mask */
1116 0xffffffff, /* dst_mask */
1117 FALSE), /* pcrel_offset */
1119 HOWTO (R_ARM_TLS_LDO32, /* type */
1120 0, /* rightshift */
1121 2, /* size (0 = byte, 1 = short, 2 = long) */
1122 32, /* bitsize */
1123 FALSE, /* pc_relative */
1124 0, /* bitpos */
1125 complain_overflow_bitfield,/* complain_on_overflow */
1126 bfd_elf_generic_reloc, /* special_function */
1127 "R_ARM_TLS_LDO32", /* name */
1128 TRUE, /* partial_inplace */
1129 0xffffffff, /* src_mask */
1130 0xffffffff, /* dst_mask */
1131 FALSE), /* pcrel_offset */
1133 HOWTO (R_ARM_TLS_IE32, /* type */
1134 0, /* rightshift */
1135 2, /* size (0 = byte, 1 = short, 2 = long) */
1136 32, /* bitsize */
1137 FALSE, /* pc_relative */
1138 0, /* bitpos */
1139 complain_overflow_bitfield,/* complain_on_overflow */
1140 NULL, /* special_function */
1141 "R_ARM_TLS_IE32", /* name */
1142 TRUE, /* partial_inplace */
1143 0xffffffff, /* src_mask */
1144 0xffffffff, /* dst_mask */
1145 FALSE), /* pcrel_offset */
1147 HOWTO (R_ARM_TLS_LE32, /* type */
1148 0, /* rightshift */
1149 2, /* size (0 = byte, 1 = short, 2 = long) */
1150 32, /* bitsize */
1151 FALSE, /* pc_relative */
1152 0, /* bitpos */
1153 complain_overflow_bitfield,/* complain_on_overflow */
1154 bfd_elf_generic_reloc, /* special_function */
1155 "R_ARM_TLS_LE32", /* name */
1156 TRUE, /* partial_inplace */
1157 0xffffffff, /* src_mask */
1158 0xffffffff, /* dst_mask */
1159 FALSE), /* pcrel_offset */
1161 HOWTO (R_ARM_TLS_LDO12, /* type */
1162 0, /* rightshift */
1163 2, /* size (0 = byte, 1 = short, 2 = long) */
1164 12, /* bitsize */
1165 FALSE, /* pc_relative */
1166 0, /* bitpos */
1167 complain_overflow_bitfield,/* complain_on_overflow */
1168 bfd_elf_generic_reloc, /* special_function */
1169 "R_ARM_TLS_LDO12", /* name */
1170 FALSE, /* partial_inplace */
1171 0x00000fff, /* src_mask */
1172 0x00000fff, /* dst_mask */
1173 FALSE), /* pcrel_offset */
1175 HOWTO (R_ARM_TLS_LE12, /* type */
1176 0, /* rightshift */
1177 2, /* size (0 = byte, 1 = short, 2 = long) */
1178 12, /* bitsize */
1179 FALSE, /* pc_relative */
1180 0, /* bitpos */
1181 complain_overflow_bitfield,/* complain_on_overflow */
1182 bfd_elf_generic_reloc, /* special_function */
1183 "R_ARM_TLS_LE12", /* name */
1184 FALSE, /* partial_inplace */
1185 0x00000fff, /* src_mask */
1186 0x00000fff, /* dst_mask */
1187 FALSE), /* pcrel_offset */
1189 HOWTO (R_ARM_TLS_IE12GP, /* type */
1190 0, /* rightshift */
1191 2, /* size (0 = byte, 1 = short, 2 = long) */
1192 12, /* bitsize */
1193 FALSE, /* pc_relative */
1194 0, /* bitpos */
1195 complain_overflow_bitfield,/* complain_on_overflow */
1196 bfd_elf_generic_reloc, /* special_function */
1197 "R_ARM_TLS_IE12GP", /* name */
1198 FALSE, /* partial_inplace */
1199 0x00000fff, /* src_mask */
1200 0x00000fff, /* dst_mask */
1201 FALSE), /* pcrel_offset */
1204 /* 112-127 private relocations
1205 128 R_ARM_ME_TOO, obsolete
1206 129-255 unallocated in AAELF.
1208 249-255 extended, currently unused, relocations: */
1210 static reloc_howto_type elf32_arm_howto_table_3[4] =
1212 HOWTO (R_ARM_RREL32, /* type */
1213 0, /* rightshift */
1214 0, /* size (0 = byte, 1 = short, 2 = long) */
1215 0, /* bitsize */
1216 FALSE, /* pc_relative */
1217 0, /* bitpos */
1218 complain_overflow_dont,/* complain_on_overflow */
1219 bfd_elf_generic_reloc, /* special_function */
1220 "R_ARM_RREL32", /* name */
1221 FALSE, /* partial_inplace */
1222 0, /* src_mask */
1223 0, /* dst_mask */
1224 FALSE), /* pcrel_offset */
1226 HOWTO (R_ARM_RABS32, /* type */
1227 0, /* rightshift */
1228 0, /* size (0 = byte, 1 = short, 2 = long) */
1229 0, /* bitsize */
1230 FALSE, /* pc_relative */
1231 0, /* bitpos */
1232 complain_overflow_dont,/* complain_on_overflow */
1233 bfd_elf_generic_reloc, /* special_function */
1234 "R_ARM_RABS32", /* name */
1235 FALSE, /* partial_inplace */
1236 0, /* src_mask */
1237 0, /* dst_mask */
1238 FALSE), /* pcrel_offset */
1240 HOWTO (R_ARM_RPC24, /* type */
1241 0, /* rightshift */
1242 0, /* size (0 = byte, 1 = short, 2 = long) */
1243 0, /* bitsize */
1244 FALSE, /* pc_relative */
1245 0, /* bitpos */
1246 complain_overflow_dont,/* complain_on_overflow */
1247 bfd_elf_generic_reloc, /* special_function */
1248 "R_ARM_RPC24", /* name */
1249 FALSE, /* partial_inplace */
1250 0, /* src_mask */
1251 0, /* dst_mask */
1252 FALSE), /* pcrel_offset */
1254 HOWTO (R_ARM_RBASE, /* type */
1255 0, /* rightshift */
1256 0, /* size (0 = byte, 1 = short, 2 = long) */
1257 0, /* bitsize */
1258 FALSE, /* pc_relative */
1259 0, /* bitpos */
1260 complain_overflow_dont,/* complain_on_overflow */
1261 bfd_elf_generic_reloc, /* special_function */
1262 "R_ARM_RBASE", /* name */
1263 FALSE, /* partial_inplace */
1264 0, /* src_mask */
1265 0, /* dst_mask */
1266 FALSE) /* pcrel_offset */
1269 static reloc_howto_type *
1270 elf32_arm_howto_from_type (unsigned int r_type)
1272 if (r_type < NUM_ELEM (elf32_arm_howto_table_1))
1273 return &elf32_arm_howto_table_1[r_type];
1275 if (r_type >= R_ARM_MOVW_BREL_NC
1276 && r_type < R_ARM_MOVW_BREL_NC + NUM_ELEM (elf32_arm_howto_table_2))
1277 return &elf32_arm_howto_table_2[r_type - R_ARM_MOVW_BREL_NC];
1279 if (r_type >= R_ARM_RREL32
1280 && r_type < R_ARM_RREL32 + NUM_ELEM (elf32_arm_howto_table_2))
1281 return &elf32_arm_howto_table_3[r_type - R_ARM_RREL32];
1283 return NULL;
1286 static void
1287 elf32_arm_info_to_howto (bfd * abfd ATTRIBUTE_UNUSED, arelent * bfd_reloc,
1288 Elf_Internal_Rela * elf_reloc)
1290 unsigned int r_type;
1292 r_type = ELF32_R_TYPE (elf_reloc->r_info);
1293 bfd_reloc->howto = elf32_arm_howto_from_type (r_type);
1296 struct elf32_arm_reloc_map
1298 bfd_reloc_code_real_type bfd_reloc_val;
1299 unsigned char elf_reloc_val;
1302 /* All entries in this list must also be present in elf32_arm_howto_table. */
1303 static const struct elf32_arm_reloc_map elf32_arm_reloc_map[] =
1305 {BFD_RELOC_NONE, R_ARM_NONE},
1306 {BFD_RELOC_ARM_PCREL_BRANCH, R_ARM_PC24},
1307 {BFD_RELOC_ARM_PCREL_BLX, R_ARM_XPC25},
1308 {BFD_RELOC_THUMB_PCREL_BLX, R_ARM_THM_XPC22},
1309 {BFD_RELOC_32, R_ARM_ABS32},
1310 {BFD_RELOC_32_PCREL, R_ARM_REL32},
1311 {BFD_RELOC_8, R_ARM_ABS8},
1312 {BFD_RELOC_16, R_ARM_ABS16},
1313 {BFD_RELOC_ARM_OFFSET_IMM, R_ARM_ABS12},
1314 {BFD_RELOC_ARM_THUMB_OFFSET, R_ARM_THM_ABS5},
1315 {BFD_RELOC_THUMB_PCREL_BRANCH25, R_ARM_THM_JUMP24},
1316 {BFD_RELOC_THUMB_PCREL_BRANCH23, R_ARM_THM_CALL},
1317 {BFD_RELOC_THUMB_PCREL_BRANCH12, R_ARM_THM_JUMP11},
1318 {BFD_RELOC_THUMB_PCREL_BRANCH20, R_ARM_THM_JUMP19},
1319 {BFD_RELOC_THUMB_PCREL_BRANCH9, R_ARM_THM_JUMP8},
1320 {BFD_RELOC_THUMB_PCREL_BRANCH7, R_ARM_THM_JUMP6},
1321 {BFD_RELOC_ARM_GLOB_DAT, R_ARM_GLOB_DAT},
1322 {BFD_RELOC_ARM_JUMP_SLOT, R_ARM_JUMP_SLOT},
1323 {BFD_RELOC_ARM_RELATIVE, R_ARM_RELATIVE},
1324 {BFD_RELOC_ARM_GOTOFF, R_ARM_GOTOFF32},
1325 {BFD_RELOC_ARM_GOTPC, R_ARM_GOTPC},
1326 {BFD_RELOC_ARM_GOT32, R_ARM_GOT32},
1327 {BFD_RELOC_ARM_PLT32, R_ARM_PLT32},
1328 {BFD_RELOC_ARM_TARGET1, R_ARM_TARGET1},
1329 {BFD_RELOC_ARM_ROSEGREL32, R_ARM_ROSEGREL32},
1330 {BFD_RELOC_ARM_SBREL32, R_ARM_SBREL32},
1331 {BFD_RELOC_ARM_PREL31, R_ARM_PREL31},
1332 {BFD_RELOC_ARM_TARGET2, R_ARM_TARGET2},
1333 {BFD_RELOC_ARM_PLT32, R_ARM_PLT32},
1334 {BFD_RELOC_ARM_TLS_GD32, R_ARM_TLS_GD32},
1335 {BFD_RELOC_ARM_TLS_LDO32, R_ARM_TLS_LDO32},
1336 {BFD_RELOC_ARM_TLS_LDM32, R_ARM_TLS_LDM32},
1337 {BFD_RELOC_ARM_TLS_DTPMOD32, R_ARM_TLS_DTPMOD32},
1338 {BFD_RELOC_ARM_TLS_DTPOFF32, R_ARM_TLS_DTPOFF32},
1339 {BFD_RELOC_ARM_TLS_TPOFF32, R_ARM_TLS_TPOFF32},
1340 {BFD_RELOC_ARM_TLS_IE32, R_ARM_TLS_IE32},
1341 {BFD_RELOC_ARM_TLS_LE32, R_ARM_TLS_LE32},
1342 {BFD_RELOC_VTABLE_INHERIT, R_ARM_GNU_VTINHERIT},
1343 {BFD_RELOC_VTABLE_ENTRY, R_ARM_GNU_VTENTRY},
1346 static reloc_howto_type *
1347 elf32_arm_reloc_type_lookup (abfd, code)
1348 bfd *abfd ATTRIBUTE_UNUSED;
1349 bfd_reloc_code_real_type code;
1351 unsigned int i;
1352 for (i = 0; i < NUM_ELEM (elf32_arm_reloc_map); i ++)
1353 if (elf32_arm_reloc_map[i].bfd_reloc_val == code)
1354 return elf32_arm_howto_from_type (elf32_arm_reloc_map[i].elf_reloc_val);
1356 return NULL;
1359 /* Support for core dump NOTE sections */
1360 static bfd_boolean
1361 elf32_arm_nabi_grok_prstatus (abfd, note)
1362 bfd *abfd;
1363 Elf_Internal_Note *note;
1365 int offset;
1366 size_t size;
1368 switch (note->descsz)
1370 default:
1371 return FALSE;
1373 case 148: /* Linux/ARM 32-bit*/
1374 /* pr_cursig */
1375 elf_tdata (abfd)->core_signal = bfd_get_16 (abfd, note->descdata + 12);
1377 /* pr_pid */
1378 elf_tdata (abfd)->core_pid = bfd_get_32 (abfd, note->descdata + 24);
1380 /* pr_reg */
1381 offset = 72;
1382 size = 72;
1384 break;
1387 /* Make a ".reg/999" section. */
1388 return _bfd_elfcore_make_pseudosection (abfd, ".reg",
1389 size, note->descpos + offset);
1392 static bfd_boolean
1393 elf32_arm_nabi_grok_psinfo (abfd, note)
1394 bfd *abfd;
1395 Elf_Internal_Note *note;
1397 switch (note->descsz)
1399 default:
1400 return FALSE;
1402 case 124: /* Linux/ARM elf_prpsinfo */
1403 elf_tdata (abfd)->core_program
1404 = _bfd_elfcore_strndup (abfd, note->descdata + 28, 16);
1405 elf_tdata (abfd)->core_command
1406 = _bfd_elfcore_strndup (abfd, note->descdata + 44, 80);
1409 /* Note that for some reason, a spurious space is tacked
1410 onto the end of the args in some (at least one anyway)
1411 implementations, so strip it off if it exists. */
1414 char *command = elf_tdata (abfd)->core_command;
1415 int n = strlen (command);
1417 if (0 < n && command[n - 1] == ' ')
1418 command[n - 1] = '\0';
1421 return TRUE;
1424 #define TARGET_LITTLE_SYM bfd_elf32_littlearm_vec
1425 #define TARGET_LITTLE_NAME "elf32-littlearm"
1426 #define TARGET_BIG_SYM bfd_elf32_bigarm_vec
1427 #define TARGET_BIG_NAME "elf32-bigarm"
1429 #define elf_backend_grok_prstatus elf32_arm_nabi_grok_prstatus
1430 #define elf_backend_grok_psinfo elf32_arm_nabi_grok_psinfo
1432 typedef unsigned long int insn32;
1433 typedef unsigned short int insn16;
1435 /* In lieu of proper flags, assume all EABIv4 objects are interworkable. */
1436 #define INTERWORK_FLAG(abfd) \
1437 (EF_ARM_EABI_VERSION (elf_elfheader (abfd)->e_flags) == EF_ARM_EABI_VER4 \
1438 || (elf_elfheader (abfd)->e_flags & EF_ARM_INTERWORK))
1440 /* The linker script knows the section names for placement.
1441 The entry_names are used to do simple name mangling on the stubs.
1442 Given a function name, and its type, the stub can be found. The
1443 name can be changed. The only requirement is the %s be present. */
1444 #define THUMB2ARM_GLUE_SECTION_NAME ".glue_7t"
1445 #define THUMB2ARM_GLUE_ENTRY_NAME "__%s_from_thumb"
1447 #define ARM2THUMB_GLUE_SECTION_NAME ".glue_7"
1448 #define ARM2THUMB_GLUE_ENTRY_NAME "__%s_from_arm"
1450 /* The name of the dynamic interpreter. This is put in the .interp
1451 section. */
1452 #define ELF_DYNAMIC_INTERPRETER "/usr/lib/ld.so.1"
1454 #ifdef FOUR_WORD_PLT
1456 /* The first entry in a procedure linkage table looks like
1457 this. It is set up so that any shared library function that is
1458 called before the relocation has been set up calls the dynamic
1459 linker first. */
1460 static const bfd_vma elf32_arm_plt0_entry [] =
1462 0xe52de004, /* str lr, [sp, #-4]! */
1463 0xe59fe010, /* ldr lr, [pc, #16] */
1464 0xe08fe00e, /* add lr, pc, lr */
1465 0xe5bef008, /* ldr pc, [lr, #8]! */
1468 /* Subsequent entries in a procedure linkage table look like
1469 this. */
1470 static const bfd_vma elf32_arm_plt_entry [] =
1472 0xe28fc600, /* add ip, pc, #NN */
1473 0xe28cca00, /* add ip, ip, #NN */
1474 0xe5bcf000, /* ldr pc, [ip, #NN]! */
1475 0x00000000, /* unused */
1478 #else
1480 /* The first entry in a procedure linkage table looks like
1481 this. It is set up so that any shared library function that is
1482 called before the relocation has been set up calls the dynamic
1483 linker first. */
1484 static const bfd_vma elf32_arm_plt0_entry [] =
1486 0xe52de004, /* str lr, [sp, #-4]! */
1487 0xe59fe004, /* ldr lr, [pc, #4] */
1488 0xe08fe00e, /* add lr, pc, lr */
1489 0xe5bef008, /* ldr pc, [lr, #8]! */
1490 0x00000000, /* &GOT[0] - . */
1493 /* Subsequent entries in a procedure linkage table look like
1494 this. */
1495 static const bfd_vma elf32_arm_plt_entry [] =
1497 0xe28fc600, /* add ip, pc, #0xNN00000 */
1498 0xe28cca00, /* add ip, ip, #0xNN000 */
1499 0xe5bcf000, /* ldr pc, [ip, #0xNNN]! */
1502 #endif
1504 /* An initial stub used if the PLT entry is referenced from Thumb code. */
1505 #define PLT_THUMB_STUB_SIZE 4
1506 static const bfd_vma elf32_arm_plt_thumb_stub [] =
1508 0x4778, /* bx pc */
1509 0x46c0 /* nop */
1512 /* The entries in a PLT when using a DLL-based target with multiple
1513 address spaces. */
1514 static const bfd_vma elf32_arm_symbian_plt_entry [] =
1516 0xe51ff004, /* ldr pc, [pc, #-4] */
1517 0x00000000, /* dcd R_ARM_GLOB_DAT(X) */
1520 /* Used to build a map of a section. This is required for mixed-endian
1521 code/data. */
1523 typedef struct elf32_elf_section_map
1525 bfd_vma vma;
1526 char type;
1528 elf32_arm_section_map;
1530 struct _arm_elf_section_data
1532 struct bfd_elf_section_data elf;
1533 int mapcount;
1534 elf32_arm_section_map *map;
1537 #define elf32_arm_section_data(sec) \
1538 ((struct _arm_elf_section_data *) elf_section_data (sec))
1540 /* The size of the thread control block. */
1541 #define TCB_SIZE 8
1543 struct elf32_arm_obj_tdata
1545 struct elf_obj_tdata root;
1547 /* tls_type for each local got entry. */
1548 char *local_got_tls_type;
1551 #define elf32_arm_tdata(abfd) \
1552 ((struct elf32_arm_obj_tdata *) (abfd)->tdata.any)
1554 #define elf32_arm_local_got_tls_type(abfd) \
1555 (elf32_arm_tdata (abfd)->local_got_tls_type)
1557 static bfd_boolean
1558 elf32_arm_mkobject (bfd *abfd)
1560 bfd_size_type amt = sizeof (struct elf32_arm_obj_tdata);
1561 abfd->tdata.any = bfd_zalloc (abfd, amt);
1562 if (abfd->tdata.any == NULL)
1563 return FALSE;
1564 return TRUE;
1567 /* The ARM linker needs to keep track of the number of relocs that it
1568 decides to copy in check_relocs for each symbol. This is so that
1569 it can discard PC relative relocs if it doesn't need them when
1570 linking with -Bsymbolic. We store the information in a field
1571 extending the regular ELF linker hash table. */
1573 /* This structure keeps track of the number of relocs we have copied
1574 for a given symbol. */
1575 struct elf32_arm_relocs_copied
1577 /* Next section. */
1578 struct elf32_arm_relocs_copied * next;
1579 /* A section in dynobj. */
1580 asection * section;
1581 /* Number of relocs copied in this section. */
1582 bfd_size_type count;
1583 /* Number of PC-relative relocs copied in this section. */
1584 bfd_size_type pc_count;
1587 #define elf32_arm_hash_entry(ent) ((struct elf32_arm_link_hash_entry *)(ent))
1589 /* Arm ELF linker hash entry. */
1590 struct elf32_arm_link_hash_entry
1592 struct elf_link_hash_entry root;
1594 /* Number of PC relative relocs copied for this symbol. */
1595 struct elf32_arm_relocs_copied * relocs_copied;
1597 /* We reference count Thumb references to a PLT entry separately,
1598 so that we can emit the Thumb trampoline only if needed. */
1599 bfd_signed_vma plt_thumb_refcount;
1601 /* Since PLT entries have variable size if the Thumb prologue is
1602 used, we need to record the index into .got.plt instead of
1603 recomputing it from the PLT offset. */
1604 bfd_signed_vma plt_got_offset;
1606 #define GOT_UNKNOWN 0
1607 #define GOT_NORMAL 1
1608 #define GOT_TLS_GD 2
1609 #define GOT_TLS_IE 4
1610 unsigned char tls_type;
1613 /* Traverse an arm ELF linker hash table. */
1614 #define elf32_arm_link_hash_traverse(table, func, info) \
1615 (elf_link_hash_traverse \
1616 (&(table)->root, \
1617 (bfd_boolean (*) (struct elf_link_hash_entry *, void *)) (func), \
1618 (info)))
1620 /* Get the ARM elf linker hash table from a link_info structure. */
1621 #define elf32_arm_hash_table(info) \
1622 ((struct elf32_arm_link_hash_table *) ((info)->hash))
1624 /* ARM ELF linker hash table. */
1625 struct elf32_arm_link_hash_table
1627 /* The main hash table. */
1628 struct elf_link_hash_table root;
1630 /* The size in bytes of the section containing the Thumb-to-ARM glue. */
1631 bfd_size_type thumb_glue_size;
1633 /* The size in bytes of the section containing the ARM-to-Thumb glue. */
1634 bfd_size_type arm_glue_size;
1636 /* An arbitrary input BFD chosen to hold the glue sections. */
1637 bfd * bfd_of_glue_owner;
1639 /* Nonzero to output a BE8 image. */
1640 int byteswap_code;
1642 /* Zero if R_ARM_TARGET1 means R_ARM_ABS32.
1643 Nonzero if R_ARM_TARGET1 means R_ARM_ABS32. */
1644 int target1_is_rel;
1646 /* The relocation to use for R_ARM_TARGET2 relocations. */
1647 int target2_reloc;
1649 /* Nonzero to fix BX instructions for ARMv4 targets. */
1650 int fix_v4bx;
1652 /* Nonzero if the ARM/Thumb BLX instructions are available for use. */
1653 int use_blx;
1655 /* The number of bytes in the initial entry in the PLT. */
1656 bfd_size_type plt_header_size;
1658 /* The number of bytes in the subsequent PLT etries. */
1659 bfd_size_type plt_entry_size;
1661 /* True if the target system is Symbian OS. */
1662 int symbian_p;
1664 /* True if the target uses REL relocations. */
1665 int use_rel;
1667 /* Short-cuts to get to dynamic linker sections. */
1668 asection *sgot;
1669 asection *sgotplt;
1670 asection *srelgot;
1671 asection *splt;
1672 asection *srelplt;
1673 asection *sdynbss;
1674 asection *srelbss;
1676 /* Data for R_ARM_TLS_LDM32 relocations. */
1677 union {
1678 bfd_signed_vma refcount;
1679 bfd_vma offset;
1680 } tls_ldm_got;
1682 /* Small local sym to section mapping cache. */
1683 struct sym_sec_cache sym_sec;
1685 /* For convenience in allocate_dynrelocs. */
1686 bfd * obfd;
1689 /* Create an entry in an ARM ELF linker hash table. */
1691 static struct bfd_hash_entry *
1692 elf32_arm_link_hash_newfunc (struct bfd_hash_entry * entry,
1693 struct bfd_hash_table * table,
1694 const char * string)
1696 struct elf32_arm_link_hash_entry * ret =
1697 (struct elf32_arm_link_hash_entry *) entry;
1699 /* Allocate the structure if it has not already been allocated by a
1700 subclass. */
1701 if (ret == (struct elf32_arm_link_hash_entry *) NULL)
1702 ret = bfd_hash_allocate (table, sizeof (struct elf32_arm_link_hash_entry));
1703 if (ret == NULL)
1704 return (struct bfd_hash_entry *) ret;
1706 /* Call the allocation method of the superclass. */
1707 ret = ((struct elf32_arm_link_hash_entry *)
1708 _bfd_elf_link_hash_newfunc ((struct bfd_hash_entry *) ret,
1709 table, string));
1710 if (ret != NULL)
1712 ret->relocs_copied = NULL;
1713 ret->tls_type = GOT_UNKNOWN;
1714 ret->plt_thumb_refcount = 0;
1715 ret->plt_got_offset = -1;
1718 return (struct bfd_hash_entry *) ret;
1721 /* Create .got, .gotplt, and .rel.got sections in DYNOBJ, and set up
1722 shortcuts to them in our hash table. */
1724 static bfd_boolean
1725 create_got_section (bfd *dynobj, struct bfd_link_info *info)
1727 struct elf32_arm_link_hash_table *htab;
1729 htab = elf32_arm_hash_table (info);
1730 /* BPABI objects never have a GOT, or associated sections. */
1731 if (htab->symbian_p)
1732 return TRUE;
1734 if (! _bfd_elf_create_got_section (dynobj, info))
1735 return FALSE;
1737 htab->sgot = bfd_get_section_by_name (dynobj, ".got");
1738 htab->sgotplt = bfd_get_section_by_name (dynobj, ".got.plt");
1739 if (!htab->sgot || !htab->sgotplt)
1740 abort ();
1742 htab->srelgot = bfd_make_section_with_flags (dynobj, ".rel.got",
1743 (SEC_ALLOC | SEC_LOAD
1744 | SEC_HAS_CONTENTS
1745 | SEC_IN_MEMORY
1746 | SEC_LINKER_CREATED
1747 | SEC_READONLY));
1748 if (htab->srelgot == NULL
1749 || ! bfd_set_section_alignment (dynobj, htab->srelgot, 2))
1750 return FALSE;
1751 return TRUE;
1754 /* Create .plt, .rel.plt, .got, .got.plt, .rel.got, .dynbss, and
1755 .rel.bss sections in DYNOBJ, and set up shortcuts to them in our
1756 hash table. */
1758 static bfd_boolean
1759 elf32_arm_create_dynamic_sections (bfd *dynobj, struct bfd_link_info *info)
1761 struct elf32_arm_link_hash_table *htab;
1763 htab = elf32_arm_hash_table (info);
1764 if (!htab->sgot && !create_got_section (dynobj, info))
1765 return FALSE;
1767 if (!_bfd_elf_create_dynamic_sections (dynobj, info))
1768 return FALSE;
1770 htab->splt = bfd_get_section_by_name (dynobj, ".plt");
1771 htab->srelplt = bfd_get_section_by_name (dynobj, ".rel.plt");
1772 htab->sdynbss = bfd_get_section_by_name (dynobj, ".dynbss");
1773 if (!info->shared)
1774 htab->srelbss = bfd_get_section_by_name (dynobj, ".rel.bss");
1776 if (!htab->splt
1777 || !htab->srelplt
1778 || !htab->sdynbss
1779 || (!info->shared && !htab->srelbss))
1780 abort ();
1782 return TRUE;
1785 /* Copy the extra info we tack onto an elf_link_hash_entry. */
1787 static void
1788 elf32_arm_copy_indirect_symbol (const struct elf_backend_data *bed,
1789 struct elf_link_hash_entry *dir,
1790 struct elf_link_hash_entry *ind)
1792 struct elf32_arm_link_hash_entry *edir, *eind;
1794 edir = (struct elf32_arm_link_hash_entry *) dir;
1795 eind = (struct elf32_arm_link_hash_entry *) ind;
1797 if (eind->relocs_copied != NULL)
1799 if (edir->relocs_copied != NULL)
1801 struct elf32_arm_relocs_copied **pp;
1802 struct elf32_arm_relocs_copied *p;
1804 if (ind->root.type == bfd_link_hash_indirect)
1805 abort ();
1807 /* Add reloc counts against the weak sym to the strong sym
1808 list. Merge any entries against the same section. */
1809 for (pp = &eind->relocs_copied; (p = *pp) != NULL; )
1811 struct elf32_arm_relocs_copied *q;
1813 for (q = edir->relocs_copied; q != NULL; q = q->next)
1814 if (q->section == p->section)
1816 q->pc_count += p->pc_count;
1817 q->count += p->count;
1818 *pp = p->next;
1819 break;
1821 if (q == NULL)
1822 pp = &p->next;
1824 *pp = edir->relocs_copied;
1827 edir->relocs_copied = eind->relocs_copied;
1828 eind->relocs_copied = NULL;
1831 /* If the direct symbol already has an associated PLT entry, the
1832 indirect symbol should not. If it doesn't, swap refcount information
1833 from the indirect symbol. */
1834 if (edir->plt_thumb_refcount == 0)
1836 edir->plt_thumb_refcount = eind->plt_thumb_refcount;
1837 eind->plt_thumb_refcount = 0;
1839 else
1840 BFD_ASSERT (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 (bed, 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 bfd_boolean
2291 bfd_elf32_arm_process_before_allocation (bfd *abfd,
2292 struct bfd_link_info *link_info,
2293 int byteswap_code)
2295 Elf_Internal_Shdr *symtab_hdr;
2296 Elf_Internal_Rela *internal_relocs = NULL;
2297 Elf_Internal_Rela *irel, *irelend;
2298 bfd_byte *contents = NULL;
2300 asection *sec;
2301 struct elf32_arm_link_hash_table *globals;
2303 /* If we are only performing a partial link do not bother
2304 to construct any glue. */
2305 if (link_info->relocatable)
2306 return TRUE;
2308 /* Here we have a bfd that is to be included on the link. We have a hook
2309 to do reloc rummaging, before section sizes are nailed down. */
2310 globals = elf32_arm_hash_table (link_info);
2312 BFD_ASSERT (globals != NULL);
2313 BFD_ASSERT (globals->bfd_of_glue_owner != NULL);
2315 if (byteswap_code && !bfd_big_endian (abfd))
2317 _bfd_error_handler (_("%B: BE8 images only valid in big-endian mode."),
2318 abfd);
2319 return FALSE;
2321 globals->byteswap_code = byteswap_code;
2323 /* Rummage around all the relocs and map the glue vectors. */
2324 sec = abfd->sections;
2326 if (sec == NULL)
2327 return TRUE;
2329 for (; sec != NULL; sec = sec->next)
2331 if (sec->reloc_count == 0)
2332 continue;
2334 symtab_hdr = &elf_tdata (abfd)->symtab_hdr;
2336 /* Load the relocs. */
2337 internal_relocs
2338 = _bfd_elf_link_read_relocs (abfd, sec, (void *) NULL,
2339 (Elf_Internal_Rela *) NULL, FALSE);
2341 if (internal_relocs == NULL)
2342 goto error_return;
2344 irelend = internal_relocs + sec->reloc_count;
2345 for (irel = internal_relocs; irel < irelend; irel++)
2347 long r_type;
2348 unsigned long r_index;
2350 struct elf_link_hash_entry *h;
2352 r_type = ELF32_R_TYPE (irel->r_info);
2353 r_index = ELF32_R_SYM (irel->r_info);
2355 /* These are the only relocation types we care about. */
2356 if ( r_type != R_ARM_PC24
2357 && r_type != R_ARM_PLT32
2358 && r_type != R_ARM_CALL
2359 && r_type != R_ARM_JUMP24
2360 && r_type != R_ARM_THM_CALL)
2361 continue;
2363 /* Get the section contents if we haven't done so already. */
2364 if (contents == NULL)
2366 /* Get cached copy if it exists. */
2367 if (elf_section_data (sec)->this_hdr.contents != NULL)
2368 contents = elf_section_data (sec)->this_hdr.contents;
2369 else
2371 /* Go get them off disk. */
2372 if (! bfd_malloc_and_get_section (abfd, sec, &contents))
2373 goto error_return;
2377 /* If the relocation is not against a symbol it cannot concern us. */
2378 h = NULL;
2380 /* We don't care about local symbols. */
2381 if (r_index < symtab_hdr->sh_info)
2382 continue;
2384 /* This is an external symbol. */
2385 r_index -= symtab_hdr->sh_info;
2386 h = (struct elf_link_hash_entry *)
2387 elf_sym_hashes (abfd)[r_index];
2389 /* If the relocation is against a static symbol it must be within
2390 the current section and so cannot be a cross ARM/Thumb relocation. */
2391 if (h == NULL)
2392 continue;
2394 /* If the call will go through a PLT entry then we do not need
2395 glue. */
2396 if (globals->splt != NULL && h->plt.offset != (bfd_vma) -1)
2397 continue;
2399 switch (r_type)
2401 case R_ARM_PC24:
2402 case R_ARM_PLT32:
2403 case R_ARM_CALL:
2404 case R_ARM_JUMP24:
2405 /* This one is a call from arm code. We need to look up
2406 the target of the call. If it is a thumb target, we
2407 insert glue. */
2408 if (ELF_ST_TYPE(h->type) == STT_ARM_TFUNC)
2409 record_arm_to_thumb_glue (link_info, h);
2410 break;
2412 case R_ARM_THM_CALL:
2413 /* This one is a call from thumb code. We look
2414 up the target of the call. If it is not a thumb
2415 target, we insert glue. */
2416 if (ELF_ST_TYPE (h->type) != STT_ARM_TFUNC)
2417 record_thumb_to_arm_glue (link_info, h);
2418 break;
2420 default:
2421 abort ();
2425 if (contents != NULL
2426 && elf_section_data (sec)->this_hdr.contents != contents)
2427 free (contents);
2428 contents = NULL;
2430 if (internal_relocs != NULL
2431 && elf_section_data (sec)->relocs != internal_relocs)
2432 free (internal_relocs);
2433 internal_relocs = NULL;
2436 return TRUE;
2438 error_return:
2439 if (contents != NULL
2440 && elf_section_data (sec)->this_hdr.contents != contents)
2441 free (contents);
2442 if (internal_relocs != NULL
2443 && elf_section_data (sec)->relocs != internal_relocs)
2444 free (internal_relocs);
2446 return FALSE;
2448 #endif
2451 /* Set target relocation values needed during linking. */
2453 void
2454 bfd_elf32_arm_set_target_relocs (struct bfd_link_info *link_info,
2455 int target1_is_rel,
2456 char * target2_type,
2457 int fix_v4bx,
2458 int use_blx)
2460 struct elf32_arm_link_hash_table *globals;
2462 globals = elf32_arm_hash_table (link_info);
2464 globals->target1_is_rel = target1_is_rel;
2465 if (strcmp (target2_type, "rel") == 0)
2466 globals->target2_reloc = R_ARM_REL32;
2467 else if (strcmp (target2_type, "abs") == 0)
2468 globals->target2_reloc = R_ARM_ABS32;
2469 else if (strcmp (target2_type, "got-rel") == 0)
2470 globals->target2_reloc = R_ARM_GOT_PREL;
2471 else
2473 _bfd_error_handler (_("Invalid TARGET2 relocation type '%s'."),
2474 target2_type);
2476 globals->fix_v4bx = fix_v4bx;
2477 globals->use_blx |= use_blx;
2480 /* The thumb form of a long branch is a bit finicky, because the offset
2481 encoding is split over two fields, each in it's own instruction. They
2482 can occur in any order. So given a thumb form of long branch, and an
2483 offset, insert the offset into the thumb branch and return finished
2484 instruction.
2486 It takes two thumb instructions to encode the target address. Each has
2487 11 bits to invest. The upper 11 bits are stored in one (identified by
2488 H-0.. see below), the lower 11 bits are stored in the other (identified
2489 by H-1).
2491 Combine together and shifted left by 1 (it's a half word address) and
2492 there you have it.
2494 Op: 1111 = F,
2495 H-0, upper address-0 = 000
2496 Op: 1111 = F,
2497 H-1, lower address-0 = 800
2499 They can be ordered either way, but the arm tools I've seen always put
2500 the lower one first. It probably doesn't matter. krk@cygnus.com
2502 XXX: Actually the order does matter. The second instruction (H-1)
2503 moves the computed address into the PC, so it must be the second one
2504 in the sequence. The problem, however is that whilst little endian code
2505 stores the instructions in HI then LOW order, big endian code does the
2506 reverse. nickc@cygnus.com. */
2508 #define LOW_HI_ORDER 0xF800F000
2509 #define HI_LOW_ORDER 0xF000F800
2511 static insn32
2512 insert_thumb_branch (insn32 br_insn, int rel_off)
2514 unsigned int low_bits;
2515 unsigned int high_bits;
2517 BFD_ASSERT ((rel_off & 1) != 1);
2519 rel_off >>= 1; /* Half word aligned address. */
2520 low_bits = rel_off & 0x000007FF; /* The bottom 11 bits. */
2521 high_bits = (rel_off >> 11) & 0x000007FF; /* The top 11 bits. */
2523 if ((br_insn & LOW_HI_ORDER) == LOW_HI_ORDER)
2524 br_insn = LOW_HI_ORDER | (low_bits << 16) | high_bits;
2525 else if ((br_insn & HI_LOW_ORDER) == HI_LOW_ORDER)
2526 br_insn = HI_LOW_ORDER | (high_bits << 16) | low_bits;
2527 else
2528 /* FIXME: abort is probably not the right call. krk@cygnus.com */
2529 abort (); /* Error - not a valid branch instruction form. */
2531 return br_insn;
2534 /* Thumb code calling an ARM function. */
2536 static int
2537 elf32_thumb_to_arm_stub (struct bfd_link_info * info,
2538 const char * name,
2539 bfd * input_bfd,
2540 bfd * output_bfd,
2541 asection * input_section,
2542 bfd_byte * hit_data,
2543 asection * sym_sec,
2544 bfd_vma offset,
2545 bfd_signed_vma addend,
2546 bfd_vma val)
2548 asection * s = 0;
2549 bfd_vma my_offset;
2550 unsigned long int tmp;
2551 long int ret_offset;
2552 struct elf_link_hash_entry * myh;
2553 struct elf32_arm_link_hash_table * globals;
2555 myh = find_thumb_glue (info, name, input_bfd);
2556 if (myh == NULL)
2557 return FALSE;
2559 globals = elf32_arm_hash_table (info);
2561 BFD_ASSERT (globals != NULL);
2562 BFD_ASSERT (globals->bfd_of_glue_owner != NULL);
2564 my_offset = myh->root.u.def.value;
2566 s = bfd_get_section_by_name (globals->bfd_of_glue_owner,
2567 THUMB2ARM_GLUE_SECTION_NAME);
2569 BFD_ASSERT (s != NULL);
2570 BFD_ASSERT (s->contents != NULL);
2571 BFD_ASSERT (s->output_section != NULL);
2573 if ((my_offset & 0x01) == 0x01)
2575 if (sym_sec != NULL
2576 && sym_sec->owner != NULL
2577 && !INTERWORK_FLAG (sym_sec->owner))
2579 (*_bfd_error_handler)
2580 (_("%B(%s): warning: interworking not enabled.\n"
2581 " first occurrence: %B: thumb call to arm"),
2582 sym_sec->owner, input_bfd, name);
2584 return FALSE;
2587 --my_offset;
2588 myh->root.u.def.value = my_offset;
2590 bfd_put_16 (output_bfd, (bfd_vma) t2a1_bx_pc_insn,
2591 s->contents + my_offset);
2593 bfd_put_16 (output_bfd, (bfd_vma) t2a2_noop_insn,
2594 s->contents + my_offset + 2);
2596 ret_offset =
2597 /* Address of destination of the stub. */
2598 ((bfd_signed_vma) val)
2599 - ((bfd_signed_vma)
2600 /* Offset from the start of the current section
2601 to the start of the stubs. */
2602 (s->output_offset
2603 /* Offset of the start of this stub from the start of the stubs. */
2604 + my_offset
2605 /* Address of the start of the current section. */
2606 + s->output_section->vma)
2607 /* The branch instruction is 4 bytes into the stub. */
2609 /* ARM branches work from the pc of the instruction + 8. */
2610 + 8);
2612 bfd_put_32 (output_bfd,
2613 (bfd_vma) t2a3_b_insn | ((ret_offset >> 2) & 0x00FFFFFF),
2614 s->contents + my_offset + 4);
2617 BFD_ASSERT (my_offset <= globals->thumb_glue_size);
2619 /* Now go back and fix up the original BL insn to point to here. */
2620 ret_offset =
2621 /* Address of where the stub is located. */
2622 (s->output_section->vma + s->output_offset + my_offset)
2623 /* Address of where the BL is located. */
2624 - (input_section->output_section->vma + input_section->output_offset
2625 + offset)
2626 /* Addend in the relocation. */
2627 - addend
2628 /* Biassing for PC-relative addressing. */
2629 - 8;
2631 tmp = bfd_get_32 (input_bfd, hit_data
2632 - input_section->vma);
2634 bfd_put_32 (output_bfd,
2635 (bfd_vma) insert_thumb_branch (tmp, ret_offset),
2636 hit_data - input_section->vma);
2638 return TRUE;
2641 /* Arm code calling a Thumb function. */
2643 static int
2644 elf32_arm_to_thumb_stub (struct bfd_link_info * info,
2645 const char * name,
2646 bfd * input_bfd,
2647 bfd * output_bfd,
2648 asection * input_section,
2649 bfd_byte * hit_data,
2650 asection * sym_sec,
2651 bfd_vma offset,
2652 bfd_signed_vma addend,
2653 bfd_vma val)
2655 unsigned long int tmp;
2656 bfd_vma my_offset;
2657 asection * s;
2658 long int ret_offset;
2659 struct elf_link_hash_entry * myh;
2660 struct elf32_arm_link_hash_table * globals;
2662 myh = find_arm_glue (info, name, input_bfd);
2663 if (myh == NULL)
2664 return FALSE;
2666 globals = elf32_arm_hash_table (info);
2668 BFD_ASSERT (globals != NULL);
2669 BFD_ASSERT (globals->bfd_of_glue_owner != NULL);
2671 my_offset = myh->root.u.def.value;
2672 s = bfd_get_section_by_name (globals->bfd_of_glue_owner,
2673 ARM2THUMB_GLUE_SECTION_NAME);
2674 BFD_ASSERT (s != NULL);
2675 BFD_ASSERT (s->contents != NULL);
2676 BFD_ASSERT (s->output_section != NULL);
2678 if ((my_offset & 0x01) == 0x01)
2680 if (sym_sec != NULL
2681 && sym_sec->owner != NULL
2682 && !INTERWORK_FLAG (sym_sec->owner))
2684 (*_bfd_error_handler)
2685 (_("%B(%s): warning: interworking not enabled.\n"
2686 " first occurrence: %B: arm call to thumb"),
2687 sym_sec->owner, input_bfd, name);
2690 --my_offset;
2691 myh->root.u.def.value = my_offset;
2693 if ((info->shared || globals->root.is_relocatable_executable))
2695 /* For relocatable objects we can't use absolute addresses,
2696 so construct the address from a relative offset. */
2697 /* TODO: If the offset is small it's probably worth
2698 constructing the address with adds. */
2699 bfd_put_32 (output_bfd, (bfd_vma) a2t1p_ldr_insn,
2700 s->contents + my_offset);
2701 bfd_put_32 (output_bfd, (bfd_vma) a2t2p_add_pc_insn,
2702 s->contents + my_offset + 4);
2703 bfd_put_32 (output_bfd, (bfd_vma) a2t3p_bx_r12_insn,
2704 s->contents + my_offset + 8);
2705 /* Adjust the offset by 4 for the position of the add,
2706 and 8 for the pipeline offset. */
2707 ret_offset = (val - (s->output_offset
2708 + s->output_section->vma
2709 + my_offset + 12))
2710 | 1;
2711 bfd_put_32 (output_bfd, ret_offset,
2712 s->contents + my_offset + 12);
2714 else
2716 bfd_put_32 (output_bfd, (bfd_vma) a2t1_ldr_insn,
2717 s->contents + my_offset);
2719 bfd_put_32 (output_bfd, (bfd_vma) a2t2_bx_r12_insn,
2720 s->contents + my_offset + 4);
2722 /* It's a thumb address. Add the low order bit. */
2723 bfd_put_32 (output_bfd, val | a2t3_func_addr_insn,
2724 s->contents + my_offset + 8);
2728 BFD_ASSERT (my_offset <= globals->arm_glue_size);
2730 tmp = bfd_get_32 (input_bfd, hit_data);
2731 tmp = tmp & 0xFF000000;
2733 /* Somehow these are both 4 too far, so subtract 8. */
2734 ret_offset = (s->output_offset
2735 + my_offset
2736 + s->output_section->vma
2737 - (input_section->output_offset
2738 + input_section->output_section->vma
2739 + offset + addend)
2740 - 8);
2742 tmp = tmp | ((ret_offset >> 2) & 0x00FFFFFF);
2744 bfd_put_32 (output_bfd, (bfd_vma) tmp, hit_data - input_section->vma);
2746 return TRUE;
2749 /* Some relocations map to different relocations depending on the
2750 target. Return the real relocation. */
2751 static int
2752 arm_real_reloc_type (struct elf32_arm_link_hash_table * globals,
2753 int r_type)
2755 switch (r_type)
2757 case R_ARM_TARGET1:
2758 if (globals->target1_is_rel)
2759 return R_ARM_REL32;
2760 else
2761 return R_ARM_ABS32;
2763 case R_ARM_TARGET2:
2764 return globals->target2_reloc;
2766 default:
2767 return r_type;
2771 /* Return the base VMA address which should be subtracted from real addresses
2772 when resolving @dtpoff relocation.
2773 This is PT_TLS segment p_vaddr. */
2775 static bfd_vma
2776 dtpoff_base (struct bfd_link_info *info)
2778 /* If tls_sec is NULL, we should have signalled an error already. */
2779 if (elf_hash_table (info)->tls_sec == NULL)
2780 return 0;
2781 return elf_hash_table (info)->tls_sec->vma;
2784 /* Return the relocation value for @tpoff relocation
2785 if STT_TLS virtual address is ADDRESS. */
2787 static bfd_vma
2788 tpoff (struct bfd_link_info *info, bfd_vma address)
2790 struct elf_link_hash_table *htab = elf_hash_table (info);
2791 bfd_vma base;
2793 /* If tls_sec is NULL, we should have signalled an error already. */
2794 if (htab->tls_sec == NULL)
2795 return 0;
2796 base = align_power ((bfd_vma) TCB_SIZE, htab->tls_sec->alignment_power);
2797 return address - htab->tls_sec->vma + base;
2800 /* Perform a relocation as part of a final link. */
2802 static bfd_reloc_status_type
2803 elf32_arm_final_link_relocate (reloc_howto_type * howto,
2804 bfd * input_bfd,
2805 bfd * output_bfd,
2806 asection * input_section,
2807 bfd_byte * contents,
2808 Elf_Internal_Rela * rel,
2809 bfd_vma value,
2810 struct bfd_link_info * info,
2811 asection * sym_sec,
2812 const char * sym_name,
2813 int sym_flags,
2814 struct elf_link_hash_entry * h,
2815 bfd_boolean * unresolved_reloc_p)
2817 unsigned long r_type = howto->type;
2818 unsigned long r_symndx;
2819 bfd_byte * hit_data = contents + rel->r_offset;
2820 bfd * dynobj = NULL;
2821 Elf_Internal_Shdr * symtab_hdr;
2822 struct elf_link_hash_entry ** sym_hashes;
2823 bfd_vma * local_got_offsets;
2824 asection * sgot = NULL;
2825 asection * splt = NULL;
2826 asection * sreloc = NULL;
2827 bfd_vma addend;
2828 bfd_signed_vma signed_addend;
2829 struct elf32_arm_link_hash_table * globals;
2831 globals = elf32_arm_hash_table (info);
2833 /* Some relocation type map to different relocations depending on the
2834 target. We pick the right one here. */
2835 r_type = arm_real_reloc_type (globals, r_type);
2836 if (r_type != howto->type)
2837 howto = elf32_arm_howto_from_type (r_type);
2839 /* If the start address has been set, then set the EF_ARM_HASENTRY
2840 flag. Setting this more than once is redundant, but the cost is
2841 not too high, and it keeps the code simple.
2843 The test is done here, rather than somewhere else, because the
2844 start address is only set just before the final link commences.
2846 Note - if the user deliberately sets a start address of 0, the
2847 flag will not be set. */
2848 if (bfd_get_start_address (output_bfd) != 0)
2849 elf_elfheader (output_bfd)->e_flags |= EF_ARM_HASENTRY;
2851 dynobj = elf_hash_table (info)->dynobj;
2852 if (dynobj)
2854 sgot = bfd_get_section_by_name (dynobj, ".got");
2855 splt = bfd_get_section_by_name (dynobj, ".plt");
2857 symtab_hdr = & elf_tdata (input_bfd)->symtab_hdr;
2858 sym_hashes = elf_sym_hashes (input_bfd);
2859 local_got_offsets = elf_local_got_offsets (input_bfd);
2860 r_symndx = ELF32_R_SYM (rel->r_info);
2862 if (globals->use_rel)
2864 addend = bfd_get_32 (input_bfd, hit_data) & howto->src_mask;
2866 if (addend & ((howto->src_mask + 1) >> 1))
2868 signed_addend = -1;
2869 signed_addend &= ~ howto->src_mask;
2870 signed_addend |= addend;
2872 else
2873 signed_addend = addend;
2875 else
2876 addend = signed_addend = rel->r_addend;
2878 switch (r_type)
2880 case R_ARM_NONE:
2881 /* We don't need to find a value for this symbol. It's just a
2882 marker. */
2883 *unresolved_reloc_p = FALSE;
2884 return bfd_reloc_ok;
2886 case R_ARM_PC24:
2887 case R_ARM_ABS32:
2888 case R_ARM_REL32:
2889 case R_ARM_CALL:
2890 case R_ARM_JUMP24:
2891 case R_ARM_XPC25:
2892 case R_ARM_PREL31:
2893 case R_ARM_PLT32:
2894 /* r_symndx will be zero only for relocs against symbols
2895 from removed linkonce sections, or sections discarded by
2896 a linker script. */
2897 if (r_symndx == 0)
2898 return bfd_reloc_ok;
2900 /* Handle relocations which should use the PLT entry. ABS32/REL32
2901 will use the symbol's value, which may point to a PLT entry, but we
2902 don't need to handle that here. If we created a PLT entry, all
2903 branches in this object should go to it. */
2904 if ((r_type != R_ARM_ABS32 && r_type != R_ARM_REL32)
2905 && h != NULL
2906 && splt != NULL
2907 && h->plt.offset != (bfd_vma) -1)
2909 /* If we've created a .plt section, and assigned a PLT entry to
2910 this function, it should not be known to bind locally. If
2911 it were, we would have cleared the PLT entry. */
2912 BFD_ASSERT (!SYMBOL_CALLS_LOCAL (info, h));
2914 value = (splt->output_section->vma
2915 + splt->output_offset
2916 + h->plt.offset);
2917 *unresolved_reloc_p = FALSE;
2918 return _bfd_final_link_relocate (howto, input_bfd, input_section,
2919 contents, rel->r_offset, value,
2920 (bfd_vma) 0);
2923 /* When generating a shared object or relocatable executable, these
2924 relocations are copied into the output file to be resolved at
2925 run time. */
2926 if ((info->shared || globals->root.is_relocatable_executable)
2927 && (input_section->flags & SEC_ALLOC)
2928 && (r_type != R_ARM_REL32
2929 || !SYMBOL_CALLS_LOCAL (info, h))
2930 && (h == NULL
2931 || ELF_ST_VISIBILITY (h->other) == STV_DEFAULT
2932 || h->root.type != bfd_link_hash_undefweak)
2933 && r_type != R_ARM_PC24
2934 && r_type != R_ARM_CALL
2935 && r_type != R_ARM_JUMP24
2936 && r_type != R_ARM_PREL31
2937 && r_type != R_ARM_PLT32)
2939 Elf_Internal_Rela outrel;
2940 bfd_byte *loc;
2941 bfd_boolean skip, relocate;
2943 *unresolved_reloc_p = FALSE;
2945 if (sreloc == NULL)
2947 const char * name;
2949 name = (bfd_elf_string_from_elf_section
2950 (input_bfd,
2951 elf_elfheader (input_bfd)->e_shstrndx,
2952 elf_section_data (input_section)->rel_hdr.sh_name));
2953 if (name == NULL)
2954 return bfd_reloc_notsupported;
2956 BFD_ASSERT (strncmp (name, ".rel", 4) == 0
2957 && strcmp (bfd_get_section_name (input_bfd,
2958 input_section),
2959 name + 4) == 0);
2961 sreloc = bfd_get_section_by_name (dynobj, name);
2962 BFD_ASSERT (sreloc != NULL);
2965 skip = FALSE;
2966 relocate = FALSE;
2968 outrel.r_offset =
2969 _bfd_elf_section_offset (output_bfd, info, input_section,
2970 rel->r_offset);
2971 if (outrel.r_offset == (bfd_vma) -1)
2972 skip = TRUE;
2973 else if (outrel.r_offset == (bfd_vma) -2)
2974 skip = TRUE, relocate = TRUE;
2975 outrel.r_offset += (input_section->output_section->vma
2976 + input_section->output_offset);
2978 if (skip)
2979 memset (&outrel, 0, sizeof outrel);
2980 else if (h != NULL
2981 && h->dynindx != -1
2982 && (!info->shared
2983 || !info->symbolic
2984 || !h->def_regular))
2985 outrel.r_info = ELF32_R_INFO (h->dynindx, r_type);
2986 else
2988 int symbol;
2990 /* This symbol is local, or marked to become local. */
2991 relocate = TRUE;
2992 if (sym_flags == STT_ARM_TFUNC)
2993 value |= 1;
2994 if (globals->symbian_p)
2996 /* On Symbian OS, the data segment and text segement
2997 can be relocated independently. Therefore, we
2998 must indicate the segment to which this
2999 relocation is relative. The BPABI allows us to
3000 use any symbol in the right segment; we just use
3001 the section symbol as it is convenient. (We
3002 cannot use the symbol given by "h" directly as it
3003 will not appear in the dynamic symbol table.) */
3004 if (sym_sec)
3005 symbol = elf_section_data (sym_sec->output_section)->dynindx;
3006 else
3007 symbol = elf_section_data (input_section->output_section)->dynindx;
3008 BFD_ASSERT (symbol != 0);
3010 else
3011 /* On SVR4-ish systems, the dynamic loader cannot
3012 relocate the text and data segments independently,
3013 so the symbol does not matter. */
3014 symbol = 0;
3015 outrel.r_info = ELF32_R_INFO (symbol, R_ARM_RELATIVE);
3018 loc = sreloc->contents;
3019 loc += sreloc->reloc_count++ * sizeof (Elf32_External_Rel);
3020 bfd_elf32_swap_reloc_out (output_bfd, &outrel, loc);
3022 /* If this reloc is against an external symbol, we do not want to
3023 fiddle with the addend. Otherwise, we need to include the symbol
3024 value so that it becomes an addend for the dynamic reloc. */
3025 if (! relocate)
3026 return bfd_reloc_ok;
3028 return _bfd_final_link_relocate (howto, input_bfd, input_section,
3029 contents, rel->r_offset, value,
3030 (bfd_vma) 0);
3032 else switch (r_type)
3034 case R_ARM_XPC25: /* Arm BLX instruction. */
3035 case R_ARM_CALL:
3036 case R_ARM_JUMP24:
3037 case R_ARM_PC24: /* Arm B/BL instruction */
3038 case R_ARM_PLT32:
3039 if (r_type == R_ARM_XPC25)
3041 /* Check for Arm calling Arm function. */
3042 /* FIXME: Should we translate the instruction into a BL
3043 instruction instead ? */
3044 if (sym_flags != STT_ARM_TFUNC)
3045 (*_bfd_error_handler)
3046 (_("\%B: Warning: Arm BLX instruction targets Arm function '%s'."),
3047 input_bfd,
3048 h ? h->root.root.string : "(local)");
3050 else
3052 /* Check for Arm calling Thumb function. */
3053 if (sym_flags == STT_ARM_TFUNC)
3055 elf32_arm_to_thumb_stub (info, sym_name, input_bfd,
3056 output_bfd, input_section,
3057 hit_data, sym_sec, rel->r_offset,
3058 signed_addend, value);
3059 return bfd_reloc_ok;
3063 /* The ARM ELF ABI says that this reloc is computed as: S - P + A
3064 where:
3065 S is the address of the symbol in the relocation.
3066 P is address of the instruction being relocated.
3067 A is the addend (extracted from the instruction) in bytes.
3069 S is held in 'value'.
3070 P is the base address of the section containing the
3071 instruction plus the offset of the reloc into that
3072 section, ie:
3073 (input_section->output_section->vma +
3074 input_section->output_offset +
3075 rel->r_offset).
3076 A is the addend, converted into bytes, ie:
3077 (signed_addend * 4)
3079 Note: None of these operations have knowledge of the pipeline
3080 size of the processor, thus it is up to the assembler to
3081 encode this information into the addend. */
3082 value -= (input_section->output_section->vma
3083 + input_section->output_offset);
3084 value -= rel->r_offset;
3085 if (globals->use_rel)
3086 value += (signed_addend << howto->size);
3087 else
3088 /* RELA addends do not have to be adjusted by howto->size. */
3089 value += signed_addend;
3091 signed_addend = value;
3092 signed_addend >>= howto->rightshift;
3094 /* It is not an error for an undefined weak reference to be
3095 out of range. Any program that branches to such a symbol
3096 is going to crash anyway, so there is no point worrying
3097 about getting the destination exactly right. */
3098 if (! h || h->root.type != bfd_link_hash_undefweak)
3100 /* Perform a signed range check. */
3101 if ( signed_addend > ((bfd_signed_vma) (howto->dst_mask >> 1))
3102 || signed_addend < - ((bfd_signed_vma) ((howto->dst_mask + 1) >> 1)))
3103 return bfd_reloc_overflow;
3106 /* If necessary set the H bit in the BLX instruction. */
3107 if (r_type == R_ARM_XPC25 && ((value & 2) == 2))
3108 value = (signed_addend & howto->dst_mask)
3109 | (bfd_get_32 (input_bfd, hit_data) & (~ howto->dst_mask))
3110 | (1 << 24);
3111 else
3112 value = (signed_addend & howto->dst_mask)
3113 | (bfd_get_32 (input_bfd, hit_data) & (~ howto->dst_mask));
3114 break;
3116 case R_ARM_ABS32:
3117 value += addend;
3118 if (sym_flags == STT_ARM_TFUNC)
3119 value |= 1;
3120 break;
3122 case R_ARM_REL32:
3123 value -= (input_section->output_section->vma
3124 + input_section->output_offset + rel->r_offset);
3125 value += addend;
3126 break;
3128 case R_ARM_PREL31:
3129 value -= (input_section->output_section->vma
3130 + input_section->output_offset + rel->r_offset);
3131 value += signed_addend;
3132 if (! h || h->root.type != bfd_link_hash_undefweak)
3134 /* Check for overflow */
3135 if ((value ^ (value >> 1)) & (1 << 30))
3136 return bfd_reloc_overflow;
3138 value &= 0x7fffffff;
3139 value |= (bfd_get_32 (input_bfd, hit_data) & 0x80000000);
3140 if (sym_flags == STT_ARM_TFUNC)
3141 value |= 1;
3142 break;
3145 bfd_put_32 (input_bfd, value, hit_data);
3146 return bfd_reloc_ok;
3148 case R_ARM_ABS8:
3149 value += addend;
3150 if ((long) value > 0x7f || (long) value < -0x80)
3151 return bfd_reloc_overflow;
3153 bfd_put_8 (input_bfd, value, hit_data);
3154 return bfd_reloc_ok;
3156 case R_ARM_ABS16:
3157 value += addend;
3159 if ((long) value > 0x7fff || (long) value < -0x8000)
3160 return bfd_reloc_overflow;
3162 bfd_put_16 (input_bfd, value, hit_data);
3163 return bfd_reloc_ok;
3165 case R_ARM_ABS12:
3166 /* Support ldr and str instruction for the arm */
3167 /* Also thumb b (unconditional branch). ??? Really? */
3168 value += addend;
3170 if ((long) value > 0x7ff || (long) value < -0x800)
3171 return bfd_reloc_overflow;
3173 value |= (bfd_get_32 (input_bfd, hit_data) & 0xfffff000);
3174 bfd_put_32 (input_bfd, value, hit_data);
3175 return bfd_reloc_ok;
3177 case R_ARM_THM_ABS5:
3178 /* Support ldr and str instructions for the thumb. */
3179 if (globals->use_rel)
3181 /* Need to refetch addend. */
3182 addend = bfd_get_16 (input_bfd, hit_data) & howto->src_mask;
3183 /* ??? Need to determine shift amount from operand size. */
3184 addend >>= howto->rightshift;
3186 value += addend;
3188 /* ??? Isn't value unsigned? */
3189 if ((long) value > 0x1f || (long) value < -0x10)
3190 return bfd_reloc_overflow;
3192 /* ??? Value needs to be properly shifted into place first. */
3193 value |= bfd_get_16 (input_bfd, hit_data) & 0xf83f;
3194 bfd_put_16 (input_bfd, value, hit_data);
3195 return bfd_reloc_ok;
3197 case R_ARM_THM_XPC22:
3198 case R_ARM_THM_CALL:
3199 /* Thumb BL (branch long instruction). */
3201 bfd_vma relocation;
3202 bfd_boolean overflow = FALSE;
3203 bfd_vma upper_insn = bfd_get_16 (input_bfd, hit_data);
3204 bfd_vma lower_insn = bfd_get_16 (input_bfd, hit_data + 2);
3205 bfd_signed_vma reloc_signed_max = ((1 << (howto->bitsize - 1)) - 1) >> howto->rightshift;
3206 bfd_signed_vma reloc_signed_min = ~ reloc_signed_max;
3207 bfd_vma check;
3208 bfd_signed_vma signed_check;
3209 bfd_boolean thumb_plt_call = FALSE;
3211 /* Need to refetch the addend and squish the two 11 bit pieces
3212 together. */
3213 if (globals->use_rel)
3215 bfd_vma upper = upper_insn & 0x7ff;
3216 bfd_vma lower = lower_insn & 0x7ff;
3217 upper = (upper ^ 0x400) - 0x400; /* Sign extend. */
3218 addend = (upper << 12) | (lower << 1);
3219 signed_addend = addend;
3222 if (r_type == R_ARM_THM_XPC22)
3224 /* Check for Thumb to Thumb call. */
3225 /* FIXME: Should we translate the instruction into a BL
3226 instruction instead ? */
3227 if (sym_flags == STT_ARM_TFUNC)
3228 (*_bfd_error_handler)
3229 (_("%B: Warning: Thumb BLX instruction targets thumb function '%s'."),
3230 input_bfd,
3231 h ? h->root.root.string : "(local)");
3233 else
3235 /* If it is not a call to Thumb, assume call to Arm.
3236 If it is a call relative to a section name, then it is not a
3237 function call at all, but rather a long jump. Calls through
3238 the PLT do not require stubs. */
3239 if (sym_flags != STT_ARM_TFUNC && sym_flags != STT_SECTION
3240 && (h == NULL || splt == NULL
3241 || h->plt.offset == (bfd_vma) -1))
3243 if (elf32_thumb_to_arm_stub
3244 (info, sym_name, input_bfd, output_bfd, input_section,
3245 hit_data, sym_sec, rel->r_offset, signed_addend, value))
3246 return bfd_reloc_ok;
3247 else
3248 return bfd_reloc_dangerous;
3252 /* Handle calls via the PLT. */
3253 if (h != NULL && splt != NULL && h->plt.offset != (bfd_vma) -1)
3255 value = (splt->output_section->vma
3256 + splt->output_offset
3257 + h->plt.offset);
3258 if (globals->use_blx)
3260 /* If the Thumb BLX instruction is available, convert the
3261 BL to a BLX instruction to call the ARM-mode PLT entry. */
3262 if ((lower_insn & (0x3 << 11)) == 0x3 << 11)
3264 lower_insn = (lower_insn & ~(0x3 << 11)) | 0x1 << 11;
3265 thumb_plt_call = TRUE;
3268 else
3269 /* Target the Thumb stub before the ARM PLT entry. */
3270 value -= PLT_THUMB_STUB_SIZE;
3271 *unresolved_reloc_p = FALSE;
3274 relocation = value + signed_addend;
3276 relocation -= (input_section->output_section->vma
3277 + input_section->output_offset
3278 + rel->r_offset);
3280 check = relocation >> howto->rightshift;
3282 /* If this is a signed value, the rightshift just dropped
3283 leading 1 bits (assuming twos complement). */
3284 if ((bfd_signed_vma) relocation >= 0)
3285 signed_check = check;
3286 else
3287 signed_check = check | ~((bfd_vma) -1 >> howto->rightshift);
3289 /* Assumes two's complement. */
3290 if (signed_check > reloc_signed_max || signed_check < reloc_signed_min)
3291 overflow = TRUE;
3293 if ((r_type == R_ARM_THM_XPC22
3294 && ((lower_insn & 0x1800) == 0x0800))
3295 || thumb_plt_call)
3296 /* For a BLX instruction, make sure that the relocation is rounded up
3297 to a word boundary. This follows the semantics of the instruction
3298 which specifies that bit 1 of the target address will come from bit
3299 1 of the base address. */
3300 relocation = (relocation + 2) & ~ 3;
3302 /* Put RELOCATION back into the insn. */
3303 upper_insn = (upper_insn & ~(bfd_vma) 0x7ff) | ((relocation >> 12) & 0x7ff);
3304 lower_insn = (lower_insn & ~(bfd_vma) 0x7ff) | ((relocation >> 1) & 0x7ff);
3306 /* Put the relocated value back in the object file: */
3307 bfd_put_16 (input_bfd, upper_insn, hit_data);
3308 bfd_put_16 (input_bfd, lower_insn, hit_data + 2);
3310 return (overflow ? bfd_reloc_overflow : bfd_reloc_ok);
3312 break;
3314 case R_ARM_THM_JUMP24:
3315 /* Thumb32 unconditional branch instruction. */
3317 bfd_vma relocation;
3318 bfd_boolean overflow = FALSE;
3319 bfd_vma upper_insn = bfd_get_16 (input_bfd, hit_data);
3320 bfd_vma lower_insn = bfd_get_16 (input_bfd, hit_data + 2);
3321 bfd_signed_vma reloc_signed_max = ((1 << (howto->bitsize - 1)) - 1) >> howto->rightshift;
3322 bfd_signed_vma reloc_signed_min = ~ reloc_signed_max;
3323 bfd_vma check;
3324 bfd_signed_vma signed_check;
3326 /* Need to refetch the addend, reconstruct the top three bits, and glue the
3327 two pieces together. */
3328 if (globals->use_rel)
3330 bfd_vma S = (upper_insn & 0x0400) >> 10;
3331 bfd_vma hi = (upper_insn & 0x03ff);
3332 bfd_vma I1 = (lower_insn & 0x2000) >> 13;
3333 bfd_vma I2 = (lower_insn & 0x0800) >> 11;
3334 bfd_vma lo = (lower_insn & 0x07ff);
3336 I1 = !(I1 ^ S);
3337 I2 = !(I2 ^ S);
3338 S = !S;
3340 signed_addend = (S << 24) | (I1 << 23) | (I2 << 22) | (hi << 12) | (lo << 1);
3341 signed_addend -= (1 << 24); /* Sign extend. */
3344 /* ??? Should handle interworking? GCC might someday try to
3345 use this for tail calls. */
3347 relocation = value + signed_addend;
3348 relocation -= (input_section->output_section->vma
3349 + input_section->output_offset
3350 + rel->r_offset);
3352 check = relocation >> howto->rightshift;
3354 /* If this is a signed value, the rightshift just dropped
3355 leading 1 bits (assuming twos complement). */
3356 if ((bfd_signed_vma) relocation >= 0)
3357 signed_check = check;
3358 else
3359 signed_check = check | ~((bfd_vma) -1 >> howto->rightshift);
3361 /* Assumes two's complement. */
3362 if (signed_check > reloc_signed_max || signed_check < reloc_signed_min)
3363 overflow = TRUE;
3365 /* Put RELOCATION back into the insn. */
3367 bfd_vma S = (relocation & 0x01000000) >> 24;
3368 bfd_vma I1 = (relocation & 0x00800000) >> 23;
3369 bfd_vma I2 = (relocation & 0x00400000) >> 22;
3370 bfd_vma hi = (relocation & 0x003ff000) >> 12;
3371 bfd_vma lo = (relocation & 0x00000ffe) >> 1;
3373 I1 = !(I1 ^ S);
3374 I2 = !(I2 ^ S);
3376 upper_insn = (upper_insn & (bfd_vma) 0xf800) | (S << 10) | hi;
3377 lower_insn = (lower_insn & (bfd_vma) 0xd000) | (I1 << 13) | (I2 << 11) | lo;
3380 /* Put the relocated value back in the object file: */
3381 bfd_put_16 (input_bfd, upper_insn, hit_data);
3382 bfd_put_16 (input_bfd, lower_insn, hit_data + 2);
3384 return (overflow ? bfd_reloc_overflow : bfd_reloc_ok);
3387 case R_ARM_THM_JUMP19:
3388 /* Thumb32 conditional branch instruction. */
3390 bfd_vma relocation;
3391 bfd_boolean overflow = FALSE;
3392 bfd_vma upper_insn = bfd_get_16 (input_bfd, hit_data);
3393 bfd_vma lower_insn = bfd_get_16 (input_bfd, hit_data + 2);
3394 bfd_signed_vma reloc_signed_max = ((1 << (howto->bitsize - 1)) - 1) >> howto->rightshift;
3395 bfd_signed_vma reloc_signed_min = ~ reloc_signed_max;
3396 bfd_vma check;
3397 bfd_signed_vma signed_check;
3399 /* Need to refetch the addend, reconstruct the top three bits,
3400 and squish the two 11 bit pieces together. */
3401 if (globals->use_rel)
3403 bfd_vma S = (upper_insn & 0x0400) >> 10;
3404 bfd_vma upper = (upper_insn & 0x001f);
3405 bfd_vma J1 = (lower_insn & 0x2000) >> 13;
3406 bfd_vma J2 = (lower_insn & 0x0800) >> 11;
3407 bfd_vma lower = (lower_insn & 0x07ff);
3409 upper |= J2 << 6;
3410 upper |= J1 << 7;
3411 upper |= ~S << 8;
3412 upper -= 0x0100; /* Sign extend. */
3414 addend = (upper << 12) | (lower << 1);
3415 signed_addend = addend;
3418 /* ??? Should handle interworking? GCC might someday try to
3419 use this for tail calls. */
3421 relocation = value + signed_addend;
3422 relocation -= (input_section->output_section->vma
3423 + input_section->output_offset
3424 + rel->r_offset);
3426 check = relocation >> howto->rightshift;
3428 /* If this is a signed value, the rightshift just dropped
3429 leading 1 bits (assuming twos complement). */
3430 if ((bfd_signed_vma) relocation >= 0)
3431 signed_check = check;
3432 else
3433 signed_check = check | ~((bfd_vma) -1 >> howto->rightshift);
3435 /* Assumes two's complement. */
3436 if (signed_check > reloc_signed_max || signed_check < reloc_signed_min)
3437 overflow = TRUE;
3439 /* Put RELOCATION back into the insn. */
3441 bfd_vma S = (relocation & 0x00100000) >> 20;
3442 bfd_vma J2 = (relocation & 0x00080000) >> 19;
3443 bfd_vma J1 = (relocation & 0x00040000) >> 18;
3444 bfd_vma hi = (relocation & 0x0003f000) >> 12;
3445 bfd_vma lo = (relocation & 0x00000ffe) >> 1;
3447 upper_insn = (upper_insn & 0xfb30) | (S << 10) | hi;
3448 lower_insn = (lower_insn & 0xd000) | (J1 << 13) | (J2 << 11) | lo;
3451 /* Put the relocated value back in the object file: */
3452 bfd_put_16 (input_bfd, upper_insn, hit_data);
3453 bfd_put_16 (input_bfd, lower_insn, hit_data + 2);
3455 return (overflow ? bfd_reloc_overflow : bfd_reloc_ok);
3458 case R_ARM_THM_JUMP11:
3459 case R_ARM_THM_JUMP8:
3460 case R_ARM_THM_JUMP6:
3461 /* Thumb B (branch) instruction). */
3463 bfd_signed_vma relocation;
3464 bfd_signed_vma reloc_signed_max = (1 << (howto->bitsize - 1)) - 1;
3465 bfd_signed_vma reloc_signed_min = ~ reloc_signed_max;
3466 bfd_signed_vma signed_check;
3468 /* CZB cannot jump backward. */
3469 if (r_type == R_ARM_THM_JUMP6)
3470 reloc_signed_min = 0;
3472 if (globals->use_rel)
3474 /* Need to refetch addend. */
3475 addend = bfd_get_16 (input_bfd, hit_data) & howto->src_mask;
3476 if (addend & ((howto->src_mask + 1) >> 1))
3478 signed_addend = -1;
3479 signed_addend &= ~ howto->src_mask;
3480 signed_addend |= addend;
3482 else
3483 signed_addend = addend;
3484 /* The value in the insn has been right shifted. We need to
3485 undo this, so that we can perform the address calculation
3486 in terms of bytes. */
3487 signed_addend <<= howto->rightshift;
3489 relocation = value + signed_addend;
3491 relocation -= (input_section->output_section->vma
3492 + input_section->output_offset
3493 + rel->r_offset);
3495 relocation >>= howto->rightshift;
3496 signed_check = relocation;
3498 if (r_type == R_ARM_THM_JUMP6)
3499 relocation = ((relocation & 0x0020) << 4) | ((relocation & 0x001f) << 3);
3500 else
3501 relocation &= howto->dst_mask;
3502 relocation |= (bfd_get_16 (input_bfd, hit_data) & (~ howto->dst_mask));
3504 bfd_put_16 (input_bfd, relocation, hit_data);
3506 /* Assumes two's complement. */
3507 if (signed_check > reloc_signed_max || signed_check < reloc_signed_min)
3508 return bfd_reloc_overflow;
3510 return bfd_reloc_ok;
3513 case R_ARM_ALU_PCREL7_0:
3514 case R_ARM_ALU_PCREL15_8:
3515 case R_ARM_ALU_PCREL23_15:
3517 bfd_vma insn;
3518 bfd_vma relocation;
3520 insn = bfd_get_32 (input_bfd, hit_data);
3521 if (globals->use_rel)
3523 /* Extract the addend. */
3524 addend = (insn & 0xff) << ((insn & 0xf00) >> 7);
3525 signed_addend = addend;
3527 relocation = value + signed_addend;
3529 relocation -= (input_section->output_section->vma
3530 + input_section->output_offset
3531 + rel->r_offset);
3532 insn = (insn & ~0xfff)
3533 | ((howto->bitpos << 7) & 0xf00)
3534 | ((relocation >> howto->bitpos) & 0xff);
3535 bfd_put_32 (input_bfd, value, hit_data);
3537 return bfd_reloc_ok;
3539 case R_ARM_GNU_VTINHERIT:
3540 case R_ARM_GNU_VTENTRY:
3541 return bfd_reloc_ok;
3543 case R_ARM_GOTOFF32:
3544 /* Relocation is relative to the start of the
3545 global offset table. */
3547 BFD_ASSERT (sgot != NULL);
3548 if (sgot == NULL)
3549 return bfd_reloc_notsupported;
3551 /* If we are addressing a Thumb function, we need to adjust the
3552 address by one, so that attempts to call the function pointer will
3553 correctly interpret it as Thumb code. */
3554 if (sym_flags == STT_ARM_TFUNC)
3555 value += 1;
3557 /* Note that sgot->output_offset is not involved in this
3558 calculation. We always want the start of .got. If we
3559 define _GLOBAL_OFFSET_TABLE in a different way, as is
3560 permitted by the ABI, we might have to change this
3561 calculation. */
3562 value -= sgot->output_section->vma;
3563 return _bfd_final_link_relocate (howto, input_bfd, input_section,
3564 contents, rel->r_offset, value,
3565 (bfd_vma) 0);
3567 case R_ARM_GOTPC:
3568 /* Use global offset table as symbol value. */
3569 BFD_ASSERT (sgot != NULL);
3571 if (sgot == NULL)
3572 return bfd_reloc_notsupported;
3574 *unresolved_reloc_p = FALSE;
3575 value = sgot->output_section->vma;
3576 return _bfd_final_link_relocate (howto, input_bfd, input_section,
3577 contents, rel->r_offset, value,
3578 (bfd_vma) 0);
3580 case R_ARM_GOT32:
3581 case R_ARM_GOT_PREL:
3582 /* Relocation is to the entry for this symbol in the
3583 global offset table. */
3584 if (sgot == NULL)
3585 return bfd_reloc_notsupported;
3587 if (h != NULL)
3589 bfd_vma off;
3590 bfd_boolean dyn;
3592 off = h->got.offset;
3593 BFD_ASSERT (off != (bfd_vma) -1);
3594 dyn = globals->root.dynamic_sections_created;
3596 if (! WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn, info->shared, h)
3597 || (info->shared
3598 && SYMBOL_REFERENCES_LOCAL (info, h))
3599 || (ELF_ST_VISIBILITY (h->other)
3600 && h->root.type == bfd_link_hash_undefweak))
3602 /* This is actually a static link, or it is a -Bsymbolic link
3603 and the symbol is defined locally. We must initialize this
3604 entry in the global offset table. Since the offset must
3605 always be a multiple of 4, we use the least significant bit
3606 to record whether we have initialized it already.
3608 When doing a dynamic link, we create a .rel.got relocation
3609 entry to initialize the value. This is done in the
3610 finish_dynamic_symbol routine. */
3611 if ((off & 1) != 0)
3612 off &= ~1;
3613 else
3615 /* If we are addressing a Thumb function, we need to
3616 adjust the address by one, so that attempts to
3617 call the function pointer will correctly
3618 interpret it as Thumb code. */
3619 if (sym_flags == STT_ARM_TFUNC)
3620 value |= 1;
3622 bfd_put_32 (output_bfd, value, sgot->contents + off);
3623 h->got.offset |= 1;
3626 else
3627 *unresolved_reloc_p = FALSE;
3629 value = sgot->output_offset + off;
3631 else
3633 bfd_vma off;
3635 BFD_ASSERT (local_got_offsets != NULL &&
3636 local_got_offsets[r_symndx] != (bfd_vma) -1);
3638 off = local_got_offsets[r_symndx];
3640 /* The offset must always be a multiple of 4. We use the
3641 least significant bit to record whether we have already
3642 generated the necessary reloc. */
3643 if ((off & 1) != 0)
3644 off &= ~1;
3645 else
3647 /* If we are addressing a Thumb function, we need to
3648 adjust the address by one, so that attempts to
3649 call the function pointer will correctly
3650 interpret it as Thumb code. */
3651 if (sym_flags == STT_ARM_TFUNC)
3652 value |= 1;
3654 bfd_put_32 (output_bfd, value, sgot->contents + off);
3656 if (info->shared)
3658 asection * srelgot;
3659 Elf_Internal_Rela outrel;
3660 bfd_byte *loc;
3662 srelgot = bfd_get_section_by_name (dynobj, ".rel.got");
3663 BFD_ASSERT (srelgot != NULL);
3665 outrel.r_offset = (sgot->output_section->vma
3666 + sgot->output_offset
3667 + off);
3668 outrel.r_info = ELF32_R_INFO (0, R_ARM_RELATIVE);
3669 loc = srelgot->contents;
3670 loc += srelgot->reloc_count++ * sizeof (Elf32_External_Rel);
3671 bfd_elf32_swap_reloc_out (output_bfd, &outrel, loc);
3674 local_got_offsets[r_symndx] |= 1;
3677 value = sgot->output_offset + off;
3679 if (r_type != R_ARM_GOT32)
3680 value += sgot->output_section->vma;
3682 return _bfd_final_link_relocate (howto, input_bfd, input_section,
3683 contents, rel->r_offset, value,
3684 (bfd_vma) 0);
3686 case R_ARM_TLS_LDO32:
3687 value = value - dtpoff_base (info);
3689 return _bfd_final_link_relocate (howto, input_bfd, input_section,
3690 contents, rel->r_offset, value, (bfd_vma) 0);
3692 case R_ARM_TLS_LDM32:
3694 bfd_vma off;
3696 if (globals->sgot == NULL)
3697 abort ();
3699 off = globals->tls_ldm_got.offset;
3701 if ((off & 1) != 0)
3702 off &= ~1;
3703 else
3705 /* If we don't know the module number, create a relocation
3706 for it. */
3707 if (info->shared)
3709 Elf_Internal_Rela outrel;
3710 bfd_byte *loc;
3712 if (globals->srelgot == NULL)
3713 abort ();
3715 outrel.r_offset = (globals->sgot->output_section->vma
3716 + globals->sgot->output_offset + off);
3717 outrel.r_info = ELF32_R_INFO (0, R_ARM_TLS_DTPMOD32);
3719 bfd_put_32 (output_bfd, 0, globals->sgot->contents + off);
3721 loc = globals->srelgot->contents;
3722 loc += globals->srelgot->reloc_count++ * sizeof (Elf32_External_Rel);
3723 bfd_elf32_swap_reloc_out (output_bfd, &outrel, loc);
3725 else
3726 bfd_put_32 (output_bfd, 1, globals->sgot->contents + off);
3728 globals->tls_ldm_got.offset |= 1;
3731 value = globals->sgot->output_section->vma + globals->sgot->output_offset + off
3732 - (input_section->output_section->vma + input_section->output_offset + rel->r_offset);
3734 return _bfd_final_link_relocate (howto, input_bfd, input_section,
3735 contents, rel->r_offset, value,
3736 (bfd_vma) 0);
3739 case R_ARM_TLS_GD32:
3740 case R_ARM_TLS_IE32:
3742 bfd_vma off;
3743 int indx;
3744 char tls_type;
3746 if (globals->sgot == NULL)
3747 abort ();
3749 indx = 0;
3750 if (h != NULL)
3752 bfd_boolean dyn;
3753 dyn = globals->root.dynamic_sections_created;
3754 if (WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn, info->shared, h)
3755 && (!info->shared
3756 || !SYMBOL_REFERENCES_LOCAL (info, h)))
3758 *unresolved_reloc_p = FALSE;
3759 indx = h->dynindx;
3761 off = h->got.offset;
3762 tls_type = ((struct elf32_arm_link_hash_entry *) h)->tls_type;
3764 else
3766 if (local_got_offsets == NULL)
3767 abort ();
3768 off = local_got_offsets[r_symndx];
3769 tls_type = elf32_arm_local_got_tls_type (input_bfd)[r_symndx];
3772 if (tls_type == GOT_UNKNOWN)
3773 abort ();
3775 if ((off & 1) != 0)
3776 off &= ~1;
3777 else
3779 bfd_boolean need_relocs = FALSE;
3780 Elf_Internal_Rela outrel;
3781 bfd_byte *loc = NULL;
3782 int cur_off = off;
3784 /* The GOT entries have not been initialized yet. Do it
3785 now, and emit any relocations. If both an IE GOT and a
3786 GD GOT are necessary, we emit the GD first. */
3788 if ((info->shared || indx != 0)
3789 && (h == NULL
3790 || ELF_ST_VISIBILITY (h->other) == STV_DEFAULT
3791 || h->root.type != bfd_link_hash_undefweak))
3793 need_relocs = TRUE;
3794 if (globals->srelgot == NULL)
3795 abort ();
3796 loc = globals->srelgot->contents;
3797 loc += globals->srelgot->reloc_count * sizeof (Elf32_External_Rel);
3800 if (tls_type & GOT_TLS_GD)
3802 if (need_relocs)
3804 outrel.r_offset = (globals->sgot->output_section->vma
3805 + globals->sgot->output_offset + cur_off);
3806 outrel.r_info = ELF32_R_INFO (indx, R_ARM_TLS_DTPMOD32);
3807 bfd_put_32 (output_bfd, 0, globals->sgot->contents + cur_off);
3809 bfd_elf32_swap_reloc_out (output_bfd, &outrel, loc);
3810 globals->srelgot->reloc_count++;
3811 loc += sizeof (Elf32_External_Rel);
3813 if (indx == 0)
3814 bfd_put_32 (output_bfd, value - dtpoff_base (info),
3815 globals->sgot->contents + cur_off + 4);
3816 else
3818 bfd_put_32 (output_bfd, 0,
3819 globals->sgot->contents + cur_off + 4);
3821 outrel.r_info = ELF32_R_INFO (indx,
3822 R_ARM_TLS_DTPOFF32);
3823 outrel.r_offset += 4;
3824 bfd_elf32_swap_reloc_out (output_bfd, &outrel, loc);
3825 globals->srelgot->reloc_count++;
3826 loc += sizeof (Elf32_External_Rel);
3829 else
3831 /* If we are not emitting relocations for a
3832 general dynamic reference, then we must be in a
3833 static link or an executable link with the
3834 symbol binding locally. Mark it as belonging
3835 to module 1, the executable. */
3836 bfd_put_32 (output_bfd, 1,
3837 globals->sgot->contents + cur_off);
3838 bfd_put_32 (output_bfd, value - dtpoff_base (info),
3839 globals->sgot->contents + cur_off + 4);
3842 cur_off += 8;
3845 if (tls_type & GOT_TLS_IE)
3847 if (need_relocs)
3849 outrel.r_offset = (globals->sgot->output_section->vma
3850 + globals->sgot->output_offset
3851 + cur_off);
3852 outrel.r_info = ELF32_R_INFO (indx, R_ARM_TLS_TPOFF32);
3854 if (indx == 0)
3855 bfd_put_32 (output_bfd, value - dtpoff_base (info),
3856 globals->sgot->contents + cur_off);
3857 else
3858 bfd_put_32 (output_bfd, 0,
3859 globals->sgot->contents + cur_off);
3861 bfd_elf32_swap_reloc_out (output_bfd, &outrel, loc);
3862 globals->srelgot->reloc_count++;
3863 loc += sizeof (Elf32_External_Rel);
3865 else
3866 bfd_put_32 (output_bfd, tpoff (info, value),
3867 globals->sgot->contents + cur_off);
3868 cur_off += 4;
3871 if (h != NULL)
3872 h->got.offset |= 1;
3873 else
3874 local_got_offsets[r_symndx] |= 1;
3877 if ((tls_type & GOT_TLS_GD) && r_type != R_ARM_TLS_GD32)
3878 off += 8;
3879 value = globals->sgot->output_section->vma + globals->sgot->output_offset + off
3880 - (input_section->output_section->vma + input_section->output_offset + rel->r_offset);
3882 return _bfd_final_link_relocate (howto, input_bfd, input_section,
3883 contents, rel->r_offset, value,
3884 (bfd_vma) 0);
3887 case R_ARM_TLS_LE32:
3888 if (info->shared)
3890 (*_bfd_error_handler)
3891 (_("%B(%A+0x%lx): R_ARM_TLS_LE32 relocation not permitted in shared object"),
3892 input_bfd, input_section,
3893 (long) rel->r_offset, howto->name);
3894 return FALSE;
3896 else
3897 value = tpoff (info, value);
3899 return _bfd_final_link_relocate (howto, input_bfd, input_section,
3900 contents, rel->r_offset, value, (bfd_vma) 0);
3902 case R_ARM_V4BX:
3903 if (globals->fix_v4bx)
3905 bfd_vma insn = bfd_get_32 (input_bfd, hit_data);
3907 /* Ensure that we have a BX instruction. */
3908 BFD_ASSERT ((insn & 0x0ffffff0) == 0x012fff10);
3910 /* Preserve Rm (lowest four bits) and the condition code
3911 (highest four bits). Other bits encode MOV PC,Rm. */
3912 insn = (insn & 0xf000000f) | 0x01a0f000;
3914 bfd_put_32 (input_bfd, insn, hit_data);
3916 return bfd_reloc_ok;
3918 default:
3919 return bfd_reloc_notsupported;
3923 /* Add INCREMENT to the reloc (of type HOWTO) at ADDRESS. */
3924 static void
3925 arm_add_to_rel (bfd * abfd,
3926 bfd_byte * address,
3927 reloc_howto_type * howto,
3928 bfd_signed_vma increment)
3930 bfd_signed_vma addend;
3932 if (howto->type == R_ARM_THM_CALL)
3934 int upper_insn, lower_insn;
3935 int upper, lower;
3937 upper_insn = bfd_get_16 (abfd, address);
3938 lower_insn = bfd_get_16 (abfd, address + 2);
3939 upper = upper_insn & 0x7ff;
3940 lower = lower_insn & 0x7ff;
3942 addend = (upper << 12) | (lower << 1);
3943 addend += increment;
3944 addend >>= 1;
3946 upper_insn = (upper_insn & 0xf800) | ((addend >> 11) & 0x7ff);
3947 lower_insn = (lower_insn & 0xf800) | (addend & 0x7ff);
3949 bfd_put_16 (abfd, (bfd_vma) upper_insn, address);
3950 bfd_put_16 (abfd, (bfd_vma) lower_insn, address + 2);
3952 else
3954 bfd_vma contents;
3956 contents = bfd_get_32 (abfd, address);
3958 /* Get the (signed) value from the instruction. */
3959 addend = contents & howto->src_mask;
3960 if (addend & ((howto->src_mask + 1) >> 1))
3962 bfd_signed_vma mask;
3964 mask = -1;
3965 mask &= ~ howto->src_mask;
3966 addend |= mask;
3969 /* Add in the increment, (which is a byte value). */
3970 switch (howto->type)
3972 default:
3973 addend += increment;
3974 break;
3976 case R_ARM_PC24:
3977 case R_ARM_PLT32:
3978 case R_ARM_CALL:
3979 case R_ARM_JUMP24:
3980 addend <<= howto->size;
3981 addend += increment;
3983 /* Should we check for overflow here ? */
3985 /* Drop any undesired bits. */
3986 addend >>= howto->rightshift;
3987 break;
3990 contents = (contents & ~ howto->dst_mask) | (addend & howto->dst_mask);
3992 bfd_put_32 (abfd, contents, address);
3996 #define IS_ARM_TLS_RELOC(R_TYPE) \
3997 ((R_TYPE) == R_ARM_TLS_GD32 \
3998 || (R_TYPE) == R_ARM_TLS_LDO32 \
3999 || (R_TYPE) == R_ARM_TLS_LDM32 \
4000 || (R_TYPE) == R_ARM_TLS_DTPOFF32 \
4001 || (R_TYPE) == R_ARM_TLS_DTPMOD32 \
4002 || (R_TYPE) == R_ARM_TLS_TPOFF32 \
4003 || (R_TYPE) == R_ARM_TLS_LE32 \
4004 || (R_TYPE) == R_ARM_TLS_IE32)
4006 /* Relocate an ARM ELF section. */
4007 static bfd_boolean
4008 elf32_arm_relocate_section (bfd * output_bfd,
4009 struct bfd_link_info * info,
4010 bfd * input_bfd,
4011 asection * input_section,
4012 bfd_byte * contents,
4013 Elf_Internal_Rela * relocs,
4014 Elf_Internal_Sym * local_syms,
4015 asection ** local_sections)
4017 Elf_Internal_Shdr *symtab_hdr;
4018 struct elf_link_hash_entry **sym_hashes;
4019 Elf_Internal_Rela *rel;
4020 Elf_Internal_Rela *relend;
4021 const char *name;
4022 struct elf32_arm_link_hash_table * globals;
4024 globals = elf32_arm_hash_table (info);
4025 if (info->relocatable && !globals->use_rel)
4026 return TRUE;
4028 symtab_hdr = & elf_tdata (input_bfd)->symtab_hdr;
4029 sym_hashes = elf_sym_hashes (input_bfd);
4031 rel = relocs;
4032 relend = relocs + input_section->reloc_count;
4033 for (; rel < relend; rel++)
4035 int r_type;
4036 reloc_howto_type * howto;
4037 unsigned long r_symndx;
4038 Elf_Internal_Sym * sym;
4039 asection * sec;
4040 struct elf_link_hash_entry * h;
4041 bfd_vma relocation;
4042 bfd_reloc_status_type r;
4043 arelent bfd_reloc;
4044 char sym_type;
4045 bfd_boolean unresolved_reloc = FALSE;
4047 r_symndx = ELF32_R_SYM (rel->r_info);
4048 r_type = ELF32_R_TYPE (rel->r_info);
4049 r_type = arm_real_reloc_type (globals, r_type);
4051 if ( r_type == R_ARM_GNU_VTENTRY
4052 || r_type == R_ARM_GNU_VTINHERIT)
4053 continue;
4055 bfd_reloc.howto = elf32_arm_howto_from_type (r_type);
4056 howto = bfd_reloc.howto;
4058 if (info->relocatable && globals->use_rel)
4060 /* This is a relocatable link. We don't have to change
4061 anything, unless the reloc is against a section symbol,
4062 in which case we have to adjust according to where the
4063 section symbol winds up in the output section. */
4064 if (r_symndx < symtab_hdr->sh_info)
4066 sym = local_syms + r_symndx;
4067 if (ELF_ST_TYPE (sym->st_info) == STT_SECTION)
4069 sec = local_sections[r_symndx];
4070 arm_add_to_rel (input_bfd, contents + rel->r_offset,
4071 howto,
4072 (bfd_signed_vma) (sec->output_offset
4073 + sym->st_value));
4077 continue;
4080 /* This is a final link. */
4081 h = NULL;
4082 sym = NULL;
4083 sec = NULL;
4085 if (r_symndx < symtab_hdr->sh_info)
4087 sym = local_syms + r_symndx;
4088 sym_type = ELF32_ST_TYPE (sym->st_info);
4089 sec = local_sections[r_symndx];
4090 if (globals->use_rel)
4092 relocation = (sec->output_section->vma
4093 + sec->output_offset
4094 + sym->st_value);
4095 if ((sec->flags & SEC_MERGE)
4096 && ELF_ST_TYPE (sym->st_info) == STT_SECTION)
4098 asection *msec;
4099 bfd_vma addend, value;
4101 if (howto->rightshift)
4103 (*_bfd_error_handler)
4104 (_("%B(%A+0x%lx): %s relocation against SEC_MERGE section"),
4105 input_bfd, input_section,
4106 (long) rel->r_offset, howto->name);
4107 return FALSE;
4110 value = bfd_get_32 (input_bfd, contents + rel->r_offset);
4112 /* Get the (signed) value from the instruction. */
4113 addend = value & howto->src_mask;
4114 if (addend & ((howto->src_mask + 1) >> 1))
4116 bfd_signed_vma mask;
4118 mask = -1;
4119 mask &= ~ howto->src_mask;
4120 addend |= mask;
4122 msec = sec;
4123 addend =
4124 _bfd_elf_rel_local_sym (output_bfd, sym, &msec, addend)
4125 - relocation;
4126 addend += msec->output_section->vma + msec->output_offset;
4127 value = (value & ~ howto->dst_mask) | (addend & howto->dst_mask);
4128 bfd_put_32 (input_bfd, value, contents + rel->r_offset);
4131 else
4132 relocation = _bfd_elf_rela_local_sym (output_bfd, sym, &sec, rel);
4134 else
4136 bfd_boolean warned;
4138 RELOC_FOR_GLOBAL_SYMBOL (info, input_bfd, input_section, rel,
4139 r_symndx, symtab_hdr, sym_hashes,
4140 h, sec, relocation,
4141 unresolved_reloc, warned);
4143 sym_type = h->type;
4146 if (h != NULL)
4147 name = h->root.root.string;
4148 else
4150 name = (bfd_elf_string_from_elf_section
4151 (input_bfd, symtab_hdr->sh_link, sym->st_name));
4152 if (name == NULL || *name == '\0')
4153 name = bfd_section_name (input_bfd, sec);
4156 if (r_symndx != 0
4157 && r_type != R_ARM_NONE
4158 && (h == NULL
4159 || h->root.type == bfd_link_hash_defined
4160 || h->root.type == bfd_link_hash_defweak)
4161 && IS_ARM_TLS_RELOC (r_type) != (sym_type == STT_TLS))
4163 (*_bfd_error_handler)
4164 ((sym_type == STT_TLS
4165 ? _("%B(%A+0x%lx): %s used with TLS symbol %s")
4166 : _("%B(%A+0x%lx): %s used with non-TLS symbol %s")),
4167 input_bfd,
4168 input_section,
4169 (long) rel->r_offset,
4170 howto->name,
4171 name);
4174 r = elf32_arm_final_link_relocate (howto, input_bfd, output_bfd,
4175 input_section, contents, rel,
4176 relocation, info, sec, name,
4177 (h ? ELF_ST_TYPE (h->type) :
4178 ELF_ST_TYPE (sym->st_info)), h,
4179 &unresolved_reloc);
4181 /* Dynamic relocs are not propagated for SEC_DEBUGGING sections
4182 because such sections are not SEC_ALLOC and thus ld.so will
4183 not process them. */
4184 if (unresolved_reloc
4185 && !((input_section->flags & SEC_DEBUGGING) != 0
4186 && h->def_dynamic))
4188 (*_bfd_error_handler)
4189 (_("%B(%A+0x%lx): warning: unresolvable relocation %d against symbol `%s'"),
4190 input_bfd, input_section, (long) rel->r_offset,
4191 r_type, h->root.root.string);
4192 return FALSE;
4195 if (r != bfd_reloc_ok)
4197 const char * msg = (const char *) 0;
4199 switch (r)
4201 case bfd_reloc_overflow:
4202 /* If the overflowing reloc was to an undefined symbol,
4203 we have already printed one error message and there
4204 is no point complaining again. */
4205 if ((! h ||
4206 h->root.type != bfd_link_hash_undefined)
4207 && (!((*info->callbacks->reloc_overflow)
4208 (info, (h ? &h->root : NULL), name, howto->name,
4209 (bfd_vma) 0, input_bfd, input_section,
4210 rel->r_offset))))
4211 return FALSE;
4212 break;
4214 case bfd_reloc_undefined:
4215 if (!((*info->callbacks->undefined_symbol)
4216 (info, name, input_bfd, input_section,
4217 rel->r_offset, TRUE)))
4218 return FALSE;
4219 break;
4221 case bfd_reloc_outofrange:
4222 msg = _("internal error: out of range error");
4223 goto common_error;
4225 case bfd_reloc_notsupported:
4226 msg = _("internal error: unsupported relocation error");
4227 goto common_error;
4229 case bfd_reloc_dangerous:
4230 msg = _("internal error: dangerous error");
4231 goto common_error;
4233 default:
4234 msg = _("internal error: unknown error");
4235 /* fall through */
4237 common_error:
4238 if (!((*info->callbacks->warning)
4239 (info, msg, name, input_bfd, input_section,
4240 rel->r_offset)))
4241 return FALSE;
4242 break;
4247 return TRUE;
4250 /* Set the right machine number. */
4252 static bfd_boolean
4253 elf32_arm_object_p (bfd *abfd)
4255 unsigned int mach;
4257 mach = bfd_arm_get_mach_from_notes (abfd, ARM_NOTE_SECTION);
4259 if (mach != bfd_mach_arm_unknown)
4260 bfd_default_set_arch_mach (abfd, bfd_arch_arm, mach);
4262 else if (elf_elfheader (abfd)->e_flags & EF_ARM_MAVERICK_FLOAT)
4263 bfd_default_set_arch_mach (abfd, bfd_arch_arm, bfd_mach_arm_ep9312);
4265 else
4266 bfd_default_set_arch_mach (abfd, bfd_arch_arm, mach);
4268 return TRUE;
4271 /* Function to keep ARM specific flags in the ELF header. */
4273 static bfd_boolean
4274 elf32_arm_set_private_flags (bfd *abfd, flagword flags)
4276 if (elf_flags_init (abfd)
4277 && elf_elfheader (abfd)->e_flags != flags)
4279 if (EF_ARM_EABI_VERSION (flags) == EF_ARM_EABI_UNKNOWN)
4281 if (flags & EF_ARM_INTERWORK)
4282 (*_bfd_error_handler)
4283 (_("Warning: Not setting interworking flag of %B since it has already been specified as non-interworking"),
4284 abfd);
4285 else
4286 _bfd_error_handler
4287 (_("Warning: Clearing the interworking flag of %B due to outside request"),
4288 abfd);
4291 else
4293 elf_elfheader (abfd)->e_flags = flags;
4294 elf_flags_init (abfd) = TRUE;
4297 return TRUE;
4300 /* Copy backend specific data from one object module to another. */
4302 static bfd_boolean
4303 elf32_arm_copy_private_bfd_data (bfd *ibfd, bfd *obfd)
4305 flagword in_flags;
4306 flagword out_flags;
4308 if ( bfd_get_flavour (ibfd) != bfd_target_elf_flavour
4309 || bfd_get_flavour (obfd) != bfd_target_elf_flavour)
4310 return TRUE;
4312 in_flags = elf_elfheader (ibfd)->e_flags;
4313 out_flags = elf_elfheader (obfd)->e_flags;
4315 if (elf_flags_init (obfd)
4316 && EF_ARM_EABI_VERSION (out_flags) == EF_ARM_EABI_UNKNOWN
4317 && in_flags != out_flags)
4319 /* Cannot mix APCS26 and APCS32 code. */
4320 if ((in_flags & EF_ARM_APCS_26) != (out_flags & EF_ARM_APCS_26))
4321 return FALSE;
4323 /* Cannot mix float APCS and non-float APCS code. */
4324 if ((in_flags & EF_ARM_APCS_FLOAT) != (out_flags & EF_ARM_APCS_FLOAT))
4325 return FALSE;
4327 /* If the src and dest have different interworking flags
4328 then turn off the interworking bit. */
4329 if ((in_flags & EF_ARM_INTERWORK) != (out_flags & EF_ARM_INTERWORK))
4331 if (out_flags & EF_ARM_INTERWORK)
4332 _bfd_error_handler
4333 (_("Warning: Clearing the interworking flag of %B because non-interworking code in %B has been linked with it"),
4334 obfd, ibfd);
4336 in_flags &= ~EF_ARM_INTERWORK;
4339 /* Likewise for PIC, though don't warn for this case. */
4340 if ((in_flags & EF_ARM_PIC) != (out_flags & EF_ARM_PIC))
4341 in_flags &= ~EF_ARM_PIC;
4344 elf_elfheader (obfd)->e_flags = in_flags;
4345 elf_flags_init (obfd) = TRUE;
4347 /* Also copy the EI_OSABI field. */
4348 elf_elfheader (obfd)->e_ident[EI_OSABI] =
4349 elf_elfheader (ibfd)->e_ident[EI_OSABI];
4351 return TRUE;
4354 /* Merge backend specific data from an object file to the output
4355 object file when linking. */
4357 static bfd_boolean
4358 elf32_arm_merge_private_bfd_data (bfd * ibfd, bfd * obfd)
4360 flagword out_flags;
4361 flagword in_flags;
4362 bfd_boolean flags_compatible = TRUE;
4363 asection *sec;
4365 /* Check if we have the same endianess. */
4366 if (! _bfd_generic_verify_endian_match (ibfd, obfd))
4367 return FALSE;
4369 if ( bfd_get_flavour (ibfd) != bfd_target_elf_flavour
4370 || bfd_get_flavour (obfd) != bfd_target_elf_flavour)
4371 return TRUE;
4373 /* The input BFD must have had its flags initialised. */
4374 /* The following seems bogus to me -- The flags are initialized in
4375 the assembler but I don't think an elf_flags_init field is
4376 written into the object. */
4377 /* BFD_ASSERT (elf_flags_init (ibfd)); */
4379 in_flags = elf_elfheader (ibfd)->e_flags;
4380 out_flags = elf_elfheader (obfd)->e_flags;
4382 if (!elf_flags_init (obfd))
4384 /* If the input is the default architecture and had the default
4385 flags then do not bother setting the flags for the output
4386 architecture, instead allow future merges to do this. If no
4387 future merges ever set these flags then they will retain their
4388 uninitialised values, which surprise surprise, correspond
4389 to the default values. */
4390 if (bfd_get_arch_info (ibfd)->the_default
4391 && elf_elfheader (ibfd)->e_flags == 0)
4392 return TRUE;
4394 elf_flags_init (obfd) = TRUE;
4395 elf_elfheader (obfd)->e_flags = in_flags;
4397 if (bfd_get_arch (obfd) == bfd_get_arch (ibfd)
4398 && bfd_get_arch_info (obfd)->the_default)
4399 return bfd_set_arch_mach (obfd, bfd_get_arch (ibfd), bfd_get_mach (ibfd));
4401 return TRUE;
4404 /* Determine what should happen if the input ARM architecture
4405 does not match the output ARM architecture. */
4406 if (! bfd_arm_merge_machines (ibfd, obfd))
4407 return FALSE;
4409 /* Identical flags must be compatible. */
4410 if (in_flags == out_flags)
4411 return TRUE;
4413 /* Check to see if the input BFD actually contains any sections. If
4414 not, its flags may not have been initialised either, but it
4415 cannot actually cause any incompatibility. Do not short-circuit
4416 dynamic objects; their section list may be emptied by
4417 elf_link_add_object_symbols.
4419 Also check to see if there are no code sections in the input.
4420 In this case there is no need to check for code specific flags.
4421 XXX - do we need to worry about floating-point format compatability
4422 in data sections ? */
4423 if (!(ibfd->flags & DYNAMIC))
4425 bfd_boolean null_input_bfd = TRUE;
4426 bfd_boolean only_data_sections = TRUE;
4428 for (sec = ibfd->sections; sec != NULL; sec = sec->next)
4430 /* Ignore synthetic glue sections. */
4431 if (strcmp (sec->name, ".glue_7")
4432 && strcmp (sec->name, ".glue_7t"))
4434 if ((bfd_get_section_flags (ibfd, sec)
4435 & (SEC_LOAD | SEC_CODE | SEC_HAS_CONTENTS))
4436 == (SEC_LOAD | SEC_CODE | SEC_HAS_CONTENTS))
4437 only_data_sections = FALSE;
4439 null_input_bfd = FALSE;
4440 break;
4444 if (null_input_bfd || only_data_sections)
4445 return TRUE;
4448 /* Complain about various flag mismatches. */
4449 if (EF_ARM_EABI_VERSION (in_flags) != EF_ARM_EABI_VERSION (out_flags))
4451 _bfd_error_handler
4452 (_("ERROR: Source object %B has EABI version %d, but target %B has EABI version %d"),
4453 ibfd, obfd,
4454 (in_flags & EF_ARM_EABIMASK) >> 24,
4455 (out_flags & EF_ARM_EABIMASK) >> 24);
4456 return FALSE;
4459 /* Not sure what needs to be checked for EABI versions >= 1. */
4460 if (EF_ARM_EABI_VERSION (in_flags) == EF_ARM_EABI_UNKNOWN)
4462 if ((in_flags & EF_ARM_APCS_26) != (out_flags & EF_ARM_APCS_26))
4464 _bfd_error_handler
4465 (_("ERROR: %B is compiled for APCS-%d, whereas target %B uses APCS-%d"),
4466 ibfd, obfd,
4467 in_flags & EF_ARM_APCS_26 ? 26 : 32,
4468 out_flags & EF_ARM_APCS_26 ? 26 : 32);
4469 flags_compatible = FALSE;
4472 if ((in_flags & EF_ARM_APCS_FLOAT) != (out_flags & EF_ARM_APCS_FLOAT))
4474 if (in_flags & EF_ARM_APCS_FLOAT)
4475 _bfd_error_handler
4476 (_("ERROR: %B passes floats in float registers, whereas %B passes them in integer registers"),
4477 ibfd, obfd);
4478 else
4479 _bfd_error_handler
4480 (_("ERROR: %B passes floats in integer registers, whereas %B passes them in float registers"),
4481 ibfd, obfd);
4483 flags_compatible = FALSE;
4486 if ((in_flags & EF_ARM_VFP_FLOAT) != (out_flags & EF_ARM_VFP_FLOAT))
4488 if (in_flags & EF_ARM_VFP_FLOAT)
4489 _bfd_error_handler
4490 (_("ERROR: %B uses VFP instructions, whereas %B does not"),
4491 ibfd, obfd);
4492 else
4493 _bfd_error_handler
4494 (_("ERROR: %B uses FPA instructions, whereas %B does not"),
4495 ibfd, obfd);
4497 flags_compatible = FALSE;
4500 if ((in_flags & EF_ARM_MAVERICK_FLOAT) != (out_flags & EF_ARM_MAVERICK_FLOAT))
4502 if (in_flags & EF_ARM_MAVERICK_FLOAT)
4503 _bfd_error_handler
4504 (_("ERROR: %B uses Maverick instructions, whereas %B does not"),
4505 ibfd, obfd);
4506 else
4507 _bfd_error_handler
4508 (_("ERROR: %B does not use Maverick instructions, whereas %B does"),
4509 ibfd, obfd);
4511 flags_compatible = FALSE;
4514 #ifdef EF_ARM_SOFT_FLOAT
4515 if ((in_flags & EF_ARM_SOFT_FLOAT) != (out_flags & EF_ARM_SOFT_FLOAT))
4517 /* We can allow interworking between code that is VFP format
4518 layout, and uses either soft float or integer regs for
4519 passing floating point arguments and results. We already
4520 know that the APCS_FLOAT flags match; similarly for VFP
4521 flags. */
4522 if ((in_flags & EF_ARM_APCS_FLOAT) != 0
4523 || (in_flags & EF_ARM_VFP_FLOAT) == 0)
4525 if (in_flags & EF_ARM_SOFT_FLOAT)
4526 _bfd_error_handler
4527 (_("ERROR: %B uses software FP, whereas %B uses hardware FP"),
4528 ibfd, obfd);
4529 else
4530 _bfd_error_handler
4531 (_("ERROR: %B uses hardware FP, whereas %B uses software FP"),
4532 ibfd, obfd);
4534 flags_compatible = FALSE;
4537 #endif
4539 /* Interworking mismatch is only a warning. */
4540 if ((in_flags & EF_ARM_INTERWORK) != (out_flags & EF_ARM_INTERWORK))
4542 if (in_flags & EF_ARM_INTERWORK)
4544 _bfd_error_handler
4545 (_("Warning: %B supports interworking, whereas %B does not"),
4546 ibfd, obfd);
4548 else
4550 _bfd_error_handler
4551 (_("Warning: %B does not support interworking, whereas %B does"),
4552 ibfd, obfd);
4557 return flags_compatible;
4560 /* Display the flags field. */
4562 static bfd_boolean
4563 elf32_arm_print_private_bfd_data (bfd *abfd, void * ptr)
4565 FILE * file = (FILE *) ptr;
4566 unsigned long flags;
4568 BFD_ASSERT (abfd != NULL && ptr != NULL);
4570 /* Print normal ELF private data. */
4571 _bfd_elf_print_private_bfd_data (abfd, ptr);
4573 flags = elf_elfheader (abfd)->e_flags;
4574 /* Ignore init flag - it may not be set, despite the flags field
4575 containing valid data. */
4577 /* xgettext:c-format */
4578 fprintf (file, _("private flags = %lx:"), elf_elfheader (abfd)->e_flags);
4580 switch (EF_ARM_EABI_VERSION (flags))
4582 case EF_ARM_EABI_UNKNOWN:
4583 /* The following flag bits are GNU extensions and not part of the
4584 official ARM ELF extended ABI. Hence they are only decoded if
4585 the EABI version is not set. */
4586 if (flags & EF_ARM_INTERWORK)
4587 fprintf (file, _(" [interworking enabled]"));
4589 if (flags & EF_ARM_APCS_26)
4590 fprintf (file, " [APCS-26]");
4591 else
4592 fprintf (file, " [APCS-32]");
4594 if (flags & EF_ARM_VFP_FLOAT)
4595 fprintf (file, _(" [VFP float format]"));
4596 else if (flags & EF_ARM_MAVERICK_FLOAT)
4597 fprintf (file, _(" [Maverick float format]"));
4598 else
4599 fprintf (file, _(" [FPA float format]"));
4601 if (flags & EF_ARM_APCS_FLOAT)
4602 fprintf (file, _(" [floats passed in float registers]"));
4604 if (flags & EF_ARM_PIC)
4605 fprintf (file, _(" [position independent]"));
4607 if (flags & EF_ARM_NEW_ABI)
4608 fprintf (file, _(" [new ABI]"));
4610 if (flags & EF_ARM_OLD_ABI)
4611 fprintf (file, _(" [old ABI]"));
4613 if (flags & EF_ARM_SOFT_FLOAT)
4614 fprintf (file, _(" [software FP]"));
4616 flags &= ~(EF_ARM_INTERWORK | EF_ARM_APCS_26 | EF_ARM_APCS_FLOAT
4617 | EF_ARM_PIC | EF_ARM_NEW_ABI | EF_ARM_OLD_ABI
4618 | EF_ARM_SOFT_FLOAT | EF_ARM_VFP_FLOAT
4619 | EF_ARM_MAVERICK_FLOAT);
4620 break;
4622 case EF_ARM_EABI_VER1:
4623 fprintf (file, _(" [Version1 EABI]"));
4625 if (flags & EF_ARM_SYMSARESORTED)
4626 fprintf (file, _(" [sorted symbol table]"));
4627 else
4628 fprintf (file, _(" [unsorted symbol table]"));
4630 flags &= ~ EF_ARM_SYMSARESORTED;
4631 break;
4633 case EF_ARM_EABI_VER2:
4634 fprintf (file, _(" [Version2 EABI]"));
4636 if (flags & EF_ARM_SYMSARESORTED)
4637 fprintf (file, _(" [sorted symbol table]"));
4638 else
4639 fprintf (file, _(" [unsorted symbol table]"));
4641 if (flags & EF_ARM_DYNSYMSUSESEGIDX)
4642 fprintf (file, _(" [dynamic symbols use segment index]"));
4644 if (flags & EF_ARM_MAPSYMSFIRST)
4645 fprintf (file, _(" [mapping symbols precede others]"));
4647 flags &= ~(EF_ARM_SYMSARESORTED | EF_ARM_DYNSYMSUSESEGIDX
4648 | EF_ARM_MAPSYMSFIRST);
4649 break;
4651 case EF_ARM_EABI_VER3:
4652 fprintf (file, _(" [Version3 EABI]"));
4653 break;
4655 case EF_ARM_EABI_VER4:
4656 fprintf (file, _(" [Version4 EABI]"));
4658 if (flags & EF_ARM_BE8)
4659 fprintf (file, _(" [BE8]"));
4661 if (flags & EF_ARM_LE8)
4662 fprintf (file, _(" [LE8]"));
4664 flags &= ~(EF_ARM_LE8 | EF_ARM_BE8);
4665 break;
4667 default:
4668 fprintf (file, _(" <EABI version unrecognised>"));
4669 break;
4672 flags &= ~ EF_ARM_EABIMASK;
4674 if (flags & EF_ARM_RELEXEC)
4675 fprintf (file, _(" [relocatable executable]"));
4677 if (flags & EF_ARM_HASENTRY)
4678 fprintf (file, _(" [has entry point]"));
4680 flags &= ~ (EF_ARM_RELEXEC | EF_ARM_HASENTRY);
4682 if (flags)
4683 fprintf (file, _("<Unrecognised flag bits set>"));
4685 fputc ('\n', file);
4687 return TRUE;
4690 static int
4691 elf32_arm_get_symbol_type (Elf_Internal_Sym * elf_sym, int type)
4693 switch (ELF_ST_TYPE (elf_sym->st_info))
4695 case STT_ARM_TFUNC:
4696 return ELF_ST_TYPE (elf_sym->st_info);
4698 case STT_ARM_16BIT:
4699 /* If the symbol is not an object, return the STT_ARM_16BIT flag.
4700 This allows us to distinguish between data used by Thumb instructions
4701 and non-data (which is probably code) inside Thumb regions of an
4702 executable. */
4703 if (type != STT_OBJECT)
4704 return ELF_ST_TYPE (elf_sym->st_info);
4705 break;
4707 default:
4708 break;
4711 return type;
4714 static asection *
4715 elf32_arm_gc_mark_hook (asection * sec,
4716 struct bfd_link_info * info ATTRIBUTE_UNUSED,
4717 Elf_Internal_Rela * rel,
4718 struct elf_link_hash_entry * h,
4719 Elf_Internal_Sym * sym)
4721 if (h != NULL)
4723 switch (ELF32_R_TYPE (rel->r_info))
4725 case R_ARM_GNU_VTINHERIT:
4726 case R_ARM_GNU_VTENTRY:
4727 break;
4729 default:
4730 switch (h->root.type)
4732 case bfd_link_hash_defined:
4733 case bfd_link_hash_defweak:
4734 return h->root.u.def.section;
4736 case bfd_link_hash_common:
4737 return h->root.u.c.p->section;
4739 default:
4740 break;
4744 else
4745 return bfd_section_from_elf_index (sec->owner, sym->st_shndx);
4747 return NULL;
4750 /* Update the got entry reference counts for the section being removed. */
4752 static bfd_boolean
4753 elf32_arm_gc_sweep_hook (bfd * abfd,
4754 struct bfd_link_info * info,
4755 asection * sec,
4756 const Elf_Internal_Rela * relocs)
4758 Elf_Internal_Shdr *symtab_hdr;
4759 struct elf_link_hash_entry **sym_hashes;
4760 bfd_signed_vma *local_got_refcounts;
4761 const Elf_Internal_Rela *rel, *relend;
4762 struct elf32_arm_link_hash_table * globals;
4764 globals = elf32_arm_hash_table (info);
4766 elf_section_data (sec)->local_dynrel = NULL;
4768 symtab_hdr = &elf_tdata (abfd)->symtab_hdr;
4769 sym_hashes = elf_sym_hashes (abfd);
4770 local_got_refcounts = elf_local_got_refcounts (abfd);
4772 relend = relocs + sec->reloc_count;
4773 for (rel = relocs; rel < relend; rel++)
4775 unsigned long r_symndx;
4776 struct elf_link_hash_entry *h = NULL;
4777 int r_type;
4779 r_symndx = ELF32_R_SYM (rel->r_info);
4780 if (r_symndx >= symtab_hdr->sh_info)
4782 h = sym_hashes[r_symndx - symtab_hdr->sh_info];
4783 while (h->root.type == bfd_link_hash_indirect
4784 || h->root.type == bfd_link_hash_warning)
4785 h = (struct elf_link_hash_entry *) h->root.u.i.link;
4788 r_type = ELF32_R_TYPE (rel->r_info);
4789 r_type = arm_real_reloc_type (globals, r_type);
4790 switch (r_type)
4792 case R_ARM_GOT32:
4793 case R_ARM_GOT_PREL:
4794 case R_ARM_TLS_GD32:
4795 case R_ARM_TLS_IE32:
4796 if (h != NULL)
4798 if (h->got.refcount > 0)
4799 h->got.refcount -= 1;
4801 else if (local_got_refcounts != NULL)
4803 if (local_got_refcounts[r_symndx] > 0)
4804 local_got_refcounts[r_symndx] -= 1;
4806 break;
4808 case R_ARM_TLS_LDM32:
4809 elf32_arm_hash_table (info)->tls_ldm_got.refcount -= 1;
4810 break;
4812 case R_ARM_ABS32:
4813 case R_ARM_REL32:
4814 case R_ARM_PC24:
4815 case R_ARM_PLT32:
4816 case R_ARM_CALL:
4817 case R_ARM_JUMP24:
4818 case R_ARM_PREL31:
4819 case R_ARM_THM_CALL:
4820 /* Should the interworking branches be here also? */
4822 if (h != NULL)
4824 struct elf32_arm_link_hash_entry *eh;
4825 struct elf32_arm_relocs_copied **pp;
4826 struct elf32_arm_relocs_copied *p;
4828 eh = (struct elf32_arm_link_hash_entry *) h;
4830 if (h->plt.refcount > 0)
4832 h->plt.refcount -= 1;
4833 if (ELF32_R_TYPE (rel->r_info) == R_ARM_THM_CALL)
4834 eh->plt_thumb_refcount--;
4837 if (r_type == R_ARM_ABS32
4838 || r_type == R_ARM_REL32)
4840 for (pp = &eh->relocs_copied; (p = *pp) != NULL;
4841 pp = &p->next)
4842 if (p->section == sec)
4844 p->count -= 1;
4845 if (ELF32_R_TYPE (rel->r_info) == R_ARM_REL32)
4846 p->pc_count -= 1;
4847 if (p->count == 0)
4848 *pp = p->next;
4849 break;
4853 break;
4855 default:
4856 break;
4860 return TRUE;
4863 /* Look through the relocs for a section during the first phase. */
4865 static bfd_boolean
4866 elf32_arm_check_relocs (bfd *abfd, struct bfd_link_info *info,
4867 asection *sec, const Elf_Internal_Rela *relocs)
4869 Elf_Internal_Shdr *symtab_hdr;
4870 struct elf_link_hash_entry **sym_hashes;
4871 struct elf_link_hash_entry **sym_hashes_end;
4872 const Elf_Internal_Rela *rel;
4873 const Elf_Internal_Rela *rel_end;
4874 bfd *dynobj;
4875 asection *sreloc;
4876 bfd_vma *local_got_offsets;
4877 struct elf32_arm_link_hash_table *htab;
4879 if (info->relocatable)
4880 return TRUE;
4882 htab = elf32_arm_hash_table (info);
4883 sreloc = NULL;
4885 /* Create dynamic sections for relocatable executables so that we can
4886 copy relocations. */
4887 if (htab->root.is_relocatable_executable
4888 && ! htab->root.dynamic_sections_created)
4890 if (! _bfd_elf_link_create_dynamic_sections (abfd, info))
4891 return FALSE;
4894 dynobj = elf_hash_table (info)->dynobj;
4895 local_got_offsets = elf_local_got_offsets (abfd);
4897 symtab_hdr = &elf_tdata (abfd)->symtab_hdr;
4898 sym_hashes = elf_sym_hashes (abfd);
4899 sym_hashes_end = sym_hashes
4900 + symtab_hdr->sh_size / sizeof (Elf32_External_Sym);
4902 if (!elf_bad_symtab (abfd))
4903 sym_hashes_end -= symtab_hdr->sh_info;
4905 rel_end = relocs + sec->reloc_count;
4906 for (rel = relocs; rel < rel_end; rel++)
4908 struct elf_link_hash_entry *h;
4909 struct elf32_arm_link_hash_entry *eh;
4910 unsigned long r_symndx;
4911 int r_type;
4913 r_symndx = ELF32_R_SYM (rel->r_info);
4914 r_type = ELF32_R_TYPE (rel->r_info);
4915 r_type = arm_real_reloc_type (htab, r_type);
4917 if (r_symndx >= NUM_SHDR_ENTRIES (symtab_hdr))
4919 (*_bfd_error_handler) (_("%B: bad symbol index: %d"), abfd,
4920 r_symndx);
4921 return FALSE;
4924 if (r_symndx < symtab_hdr->sh_info)
4925 h = NULL;
4926 else
4927 h = sym_hashes[r_symndx - symtab_hdr->sh_info];
4929 eh = (struct elf32_arm_link_hash_entry *) h;
4931 switch (r_type)
4933 case R_ARM_GOT32:
4934 case R_ARM_GOT_PREL:
4935 case R_ARM_TLS_GD32:
4936 case R_ARM_TLS_IE32:
4937 /* This symbol requires a global offset table entry. */
4939 int tls_type, old_tls_type;
4941 switch (r_type)
4943 case R_ARM_TLS_GD32: tls_type = GOT_TLS_GD; break;
4944 case R_ARM_TLS_IE32: tls_type = GOT_TLS_IE; break;
4945 default: tls_type = GOT_NORMAL; break;
4948 if (h != NULL)
4950 h->got.refcount++;
4951 old_tls_type = elf32_arm_hash_entry (h)->tls_type;
4953 else
4955 bfd_signed_vma *local_got_refcounts;
4957 /* This is a global offset table entry for a local symbol. */
4958 local_got_refcounts = elf_local_got_refcounts (abfd);
4959 if (local_got_refcounts == NULL)
4961 bfd_size_type size;
4963 size = symtab_hdr->sh_info;
4964 size *= (sizeof (bfd_signed_vma) + sizeof(char));
4965 local_got_refcounts = bfd_zalloc (abfd, size);
4966 if (local_got_refcounts == NULL)
4967 return FALSE;
4968 elf_local_got_refcounts (abfd) = local_got_refcounts;
4969 elf32_arm_local_got_tls_type (abfd)
4970 = (char *) (local_got_refcounts + symtab_hdr->sh_info);
4972 local_got_refcounts[r_symndx] += 1;
4973 old_tls_type = elf32_arm_local_got_tls_type (abfd) [r_symndx];
4976 /* We will already have issued an error message if there is a
4977 TLS / non-TLS mismatch, based on the symbol type. We don't
4978 support any linker relaxations. So just combine any TLS
4979 types needed. */
4980 if (old_tls_type != GOT_UNKNOWN && old_tls_type != GOT_NORMAL
4981 && tls_type != GOT_NORMAL)
4982 tls_type |= old_tls_type;
4984 if (old_tls_type != tls_type)
4986 if (h != NULL)
4987 elf32_arm_hash_entry (h)->tls_type = tls_type;
4988 else
4989 elf32_arm_local_got_tls_type (abfd) [r_symndx] = tls_type;
4992 /* Fall through */
4994 case R_ARM_TLS_LDM32:
4995 if (r_type == R_ARM_TLS_LDM32)
4996 htab->tls_ldm_got.refcount++;
4997 /* Fall through */
4999 case R_ARM_GOTOFF32:
5000 case R_ARM_GOTPC:
5001 if (htab->sgot == NULL)
5003 if (htab->root.dynobj == NULL)
5004 htab->root.dynobj = abfd;
5005 if (!create_got_section (htab->root.dynobj, info))
5006 return FALSE;
5008 break;
5010 case R_ARM_ABS32:
5011 case R_ARM_REL32:
5012 case R_ARM_PC24:
5013 case R_ARM_PLT32:
5014 case R_ARM_CALL:
5015 case R_ARM_JUMP24:
5016 case R_ARM_PREL31:
5017 case R_ARM_THM_CALL:
5018 /* Should the interworking branches be listed here? */
5019 if (h != NULL)
5021 /* If this reloc is in a read-only section, we might
5022 need a copy reloc. We can't check reliably at this
5023 stage whether the section is read-only, as input
5024 sections have not yet been mapped to output sections.
5025 Tentatively set the flag for now, and correct in
5026 adjust_dynamic_symbol. */
5027 if (!info->shared)
5028 h->non_got_ref = 1;
5030 /* We may need a .plt entry if the function this reloc
5031 refers to is in a different object. We can't tell for
5032 sure yet, because something later might force the
5033 symbol local. */
5034 if (r_type == R_ARM_PC24
5035 || r_type == R_ARM_CALL
5036 || r_type == R_ARM_JUMP24
5037 || r_type == R_ARM_PREL31
5038 || r_type == R_ARM_PLT32
5039 || r_type == R_ARM_THM_CALL)
5040 h->needs_plt = 1;
5042 /* If we create a PLT entry, this relocation will reference
5043 it, even if it's an ABS32 relocation. */
5044 h->plt.refcount += 1;
5046 if (r_type == R_ARM_THM_CALL)
5047 eh->plt_thumb_refcount += 1;
5050 /* If we are creating a shared library or relocatable executable,
5051 and this is a reloc against a global symbol, or a non PC
5052 relative reloc against a local symbol, then we need to copy
5053 the reloc into the shared library. However, if we are linking
5054 with -Bsymbolic, we do not need to copy a reloc against a
5055 global symbol which is defined in an object we are
5056 including in the link (i.e., DEF_REGULAR is set). At
5057 this point we have not seen all the input files, so it is
5058 possible that DEF_REGULAR is not set now but will be set
5059 later (it is never cleared). We account for that
5060 possibility below by storing information in the
5061 relocs_copied field of the hash table entry. */
5062 if ((info->shared || htab->root.is_relocatable_executable)
5063 && (sec->flags & SEC_ALLOC) != 0
5064 && (r_type == R_ARM_ABS32
5065 || (h != NULL && ! h->needs_plt
5066 && (! info->symbolic || ! h->def_regular))))
5068 struct elf32_arm_relocs_copied *p, **head;
5070 /* When creating a shared object, we must copy these
5071 reloc types into the output file. We create a reloc
5072 section in dynobj and make room for this reloc. */
5073 if (sreloc == NULL)
5075 const char * name;
5077 name = (bfd_elf_string_from_elf_section
5078 (abfd,
5079 elf_elfheader (abfd)->e_shstrndx,
5080 elf_section_data (sec)->rel_hdr.sh_name));
5081 if (name == NULL)
5082 return FALSE;
5084 BFD_ASSERT (strncmp (name, ".rel", 4) == 0
5085 && strcmp (bfd_get_section_name (abfd, sec),
5086 name + 4) == 0);
5088 sreloc = bfd_get_section_by_name (dynobj, name);
5089 if (sreloc == NULL)
5091 flagword flags;
5093 flags = (SEC_HAS_CONTENTS | SEC_READONLY
5094 | SEC_IN_MEMORY | SEC_LINKER_CREATED);
5095 if ((sec->flags & SEC_ALLOC) != 0
5096 /* BPABI objects never have dynamic
5097 relocations mapped. */
5098 && !htab->symbian_p)
5099 flags |= SEC_ALLOC | SEC_LOAD;
5100 sreloc = bfd_make_section_with_flags (dynobj,
5101 name,
5102 flags);
5103 if (sreloc == NULL
5104 || ! bfd_set_section_alignment (dynobj, sreloc, 2))
5105 return FALSE;
5108 elf_section_data (sec)->sreloc = sreloc;
5111 /* If this is a global symbol, we count the number of
5112 relocations we need for this symbol. */
5113 if (h != NULL)
5115 head = &((struct elf32_arm_link_hash_entry *) h)->relocs_copied;
5117 else
5119 /* Track dynamic relocs needed for local syms too.
5120 We really need local syms available to do this
5121 easily. Oh well. */
5123 asection *s;
5124 s = bfd_section_from_r_symndx (abfd, &htab->sym_sec,
5125 sec, r_symndx);
5126 if (s == NULL)
5127 return FALSE;
5129 head = ((struct elf32_arm_relocs_copied **)
5130 &elf_section_data (s)->local_dynrel);
5133 p = *head;
5134 if (p == NULL || p->section != sec)
5136 bfd_size_type amt = sizeof *p;
5138 p = bfd_alloc (htab->root.dynobj, amt);
5139 if (p == NULL)
5140 return FALSE;
5141 p->next = *head;
5142 *head = p;
5143 p->section = sec;
5144 p->count = 0;
5145 p->pc_count = 0;
5148 if (r_type == R_ARM_REL32)
5149 p->pc_count += 1;
5150 p->count += 1;
5152 break;
5154 /* This relocation describes the C++ object vtable hierarchy.
5155 Reconstruct it for later use during GC. */
5156 case R_ARM_GNU_VTINHERIT:
5157 if (!bfd_elf_gc_record_vtinherit (abfd, sec, h, rel->r_offset))
5158 return FALSE;
5159 break;
5161 /* This relocation describes which C++ vtable entries are actually
5162 used. Record for later use during GC. */
5163 case R_ARM_GNU_VTENTRY:
5164 if (!bfd_elf_gc_record_vtentry (abfd, sec, h, rel->r_offset))
5165 return FALSE;
5166 break;
5170 return TRUE;
5173 /* Treat mapping symbols as special target symbols. */
5175 static bfd_boolean
5176 elf32_arm_is_target_special_symbol (bfd * abfd ATTRIBUTE_UNUSED, asymbol * sym)
5178 return bfd_is_arm_mapping_symbol_name (sym->name);
5181 /* This is a copy of elf_find_function() from elf.c except that
5182 ARM mapping symbols are ignored when looking for function names
5183 and STT_ARM_TFUNC is considered to a function type. */
5185 static bfd_boolean
5186 arm_elf_find_function (bfd * abfd ATTRIBUTE_UNUSED,
5187 asection * section,
5188 asymbol ** symbols,
5189 bfd_vma offset,
5190 const char ** filename_ptr,
5191 const char ** functionname_ptr)
5193 const char * filename = NULL;
5194 asymbol * func = NULL;
5195 bfd_vma low_func = 0;
5196 asymbol ** p;
5198 for (p = symbols; *p != NULL; p++)
5200 elf_symbol_type *q;
5202 q = (elf_symbol_type *) *p;
5204 switch (ELF_ST_TYPE (q->internal_elf_sym.st_info))
5206 default:
5207 break;
5208 case STT_FILE:
5209 filename = bfd_asymbol_name (&q->symbol);
5210 break;
5211 case STT_FUNC:
5212 case STT_ARM_TFUNC:
5213 case STT_NOTYPE:
5214 /* Skip $a and $t symbols. */
5215 if ((q->symbol.flags & BSF_LOCAL)
5216 && bfd_is_arm_mapping_symbol_name (q->symbol.name))
5217 continue;
5218 /* Fall through. */
5219 if (bfd_get_section (&q->symbol) == section
5220 && q->symbol.value >= low_func
5221 && q->symbol.value <= offset)
5223 func = (asymbol *) q;
5224 low_func = q->symbol.value;
5226 break;
5230 if (func == NULL)
5231 return FALSE;
5233 if (filename_ptr)
5234 *filename_ptr = filename;
5235 if (functionname_ptr)
5236 *functionname_ptr = bfd_asymbol_name (func);
5238 return TRUE;
5242 /* Find the nearest line to a particular section and offset, for error
5243 reporting. This code is a duplicate of the code in elf.c, except
5244 that it uses arm_elf_find_function. */
5246 static bfd_boolean
5247 elf32_arm_find_nearest_line (bfd * abfd,
5248 asection * section,
5249 asymbol ** symbols,
5250 bfd_vma offset,
5251 const char ** filename_ptr,
5252 const char ** functionname_ptr,
5253 unsigned int * line_ptr)
5255 bfd_boolean found = FALSE;
5257 /* We skip _bfd_dwarf1_find_nearest_line since no known ARM toolchain uses it. */
5259 if (_bfd_dwarf2_find_nearest_line (abfd, section, symbols, offset,
5260 filename_ptr, functionname_ptr,
5261 line_ptr, 0,
5262 & elf_tdata (abfd)->dwarf2_find_line_info))
5264 if (!*functionname_ptr)
5265 arm_elf_find_function (abfd, section, symbols, offset,
5266 *filename_ptr ? NULL : filename_ptr,
5267 functionname_ptr);
5269 return TRUE;
5272 if (! _bfd_stab_section_find_nearest_line (abfd, symbols, section, offset,
5273 & found, filename_ptr,
5274 functionname_ptr, line_ptr,
5275 & elf_tdata (abfd)->line_info))
5276 return FALSE;
5278 if (found && (*functionname_ptr || *line_ptr))
5279 return TRUE;
5281 if (symbols == NULL)
5282 return FALSE;
5284 if (! arm_elf_find_function (abfd, section, symbols, offset,
5285 filename_ptr, functionname_ptr))
5286 return FALSE;
5288 *line_ptr = 0;
5289 return TRUE;
5292 static bfd_boolean
5293 elf32_arm_find_inliner_info (bfd * abfd,
5294 const char ** filename_ptr,
5295 const char ** functionname_ptr,
5296 unsigned int * line_ptr)
5298 bfd_boolean found;
5299 found = _bfd_dwarf2_find_inliner_info (abfd, filename_ptr,
5300 functionname_ptr, line_ptr,
5301 & elf_tdata (abfd)->dwarf2_find_line_info);
5302 return found;
5305 /* Adjust a symbol defined by a dynamic object and referenced by a
5306 regular object. The current definition is in some section of the
5307 dynamic object, but we're not including those sections. We have to
5308 change the definition to something the rest of the link can
5309 understand. */
5311 static bfd_boolean
5312 elf32_arm_adjust_dynamic_symbol (struct bfd_link_info * info,
5313 struct elf_link_hash_entry * h)
5315 bfd * dynobj;
5316 asection * s;
5317 unsigned int power_of_two;
5318 struct elf32_arm_link_hash_entry * eh;
5319 struct elf32_arm_link_hash_table *globals;
5321 globals = elf32_arm_hash_table (info);
5322 dynobj = elf_hash_table (info)->dynobj;
5324 /* Make sure we know what is going on here. */
5325 BFD_ASSERT (dynobj != NULL
5326 && (h->needs_plt
5327 || h->u.weakdef != NULL
5328 || (h->def_dynamic
5329 && h->ref_regular
5330 && !h->def_regular)));
5332 eh = (struct elf32_arm_link_hash_entry *) h;
5334 /* If this is a function, put it in the procedure linkage table. We
5335 will fill in the contents of the procedure linkage table later,
5336 when we know the address of the .got section. */
5337 if (h->type == STT_FUNC || h->type == STT_ARM_TFUNC
5338 || h->needs_plt)
5340 if (h->plt.refcount <= 0
5341 || SYMBOL_CALLS_LOCAL (info, h)
5342 || (ELF_ST_VISIBILITY (h->other) != STV_DEFAULT
5343 && h->root.type == bfd_link_hash_undefweak))
5345 /* This case can occur if we saw a PLT32 reloc in an input
5346 file, but the symbol was never referred to by a dynamic
5347 object, or if all references were garbage collected. In
5348 such a case, we don't actually need to build a procedure
5349 linkage table, and we can just do a PC24 reloc instead. */
5350 h->plt.offset = (bfd_vma) -1;
5351 eh->plt_thumb_refcount = 0;
5352 h->needs_plt = 0;
5355 return TRUE;
5357 else
5359 /* It's possible that we incorrectly decided a .plt reloc was
5360 needed for an R_ARM_PC24 or similar reloc to a non-function sym
5361 in check_relocs. We can't decide accurately between function
5362 and non-function syms in check-relocs; Objects loaded later in
5363 the link may change h->type. So fix it now. */
5364 h->plt.offset = (bfd_vma) -1;
5365 eh->plt_thumb_refcount = 0;
5368 /* If this is a weak symbol, and there is a real definition, the
5369 processor independent code will have arranged for us to see the
5370 real definition first, and we can just use the same value. */
5371 if (h->u.weakdef != NULL)
5373 BFD_ASSERT (h->u.weakdef->root.type == bfd_link_hash_defined
5374 || h->u.weakdef->root.type == bfd_link_hash_defweak);
5375 h->root.u.def.section = h->u.weakdef->root.u.def.section;
5376 h->root.u.def.value = h->u.weakdef->root.u.def.value;
5377 return TRUE;
5380 /* If there are no non-GOT references, we do not need a copy
5381 relocation. */
5382 if (!h->non_got_ref)
5383 return TRUE;
5385 /* This is a reference to a symbol defined by a dynamic object which
5386 is not a function. */
5388 /* If we are creating a shared library, we must presume that the
5389 only references to the symbol are via the global offset table.
5390 For such cases we need not do anything here; the relocations will
5391 be handled correctly by relocate_section. Relocatable executables
5392 can reference data in shared objects directly, so we don't need to
5393 do anything here. */
5394 if (info->shared || globals->root.is_relocatable_executable)
5395 return TRUE;
5397 /* We must allocate the symbol in our .dynbss section, which will
5398 become part of the .bss section of the executable. There will be
5399 an entry for this symbol in the .dynsym section. The dynamic
5400 object will contain position independent code, so all references
5401 from the dynamic object to this symbol will go through the global
5402 offset table. The dynamic linker will use the .dynsym entry to
5403 determine the address it must put in the global offset table, so
5404 both the dynamic object and the regular object will refer to the
5405 same memory location for the variable. */
5406 s = bfd_get_section_by_name (dynobj, ".dynbss");
5407 BFD_ASSERT (s != NULL);
5409 /* We must generate a R_ARM_COPY reloc to tell the dynamic linker to
5410 copy the initial value out of the dynamic object and into the
5411 runtime process image. We need to remember the offset into the
5412 .rel.bss section we are going to use. */
5413 if ((h->root.u.def.section->flags & SEC_ALLOC) != 0)
5415 asection *srel;
5417 srel = bfd_get_section_by_name (dynobj, ".rel.bss");
5418 BFD_ASSERT (srel != NULL);
5419 srel->size += sizeof (Elf32_External_Rel);
5420 h->needs_copy = 1;
5423 /* We need to figure out the alignment required for this symbol. I
5424 have no idea how ELF linkers handle this. */
5425 power_of_two = bfd_log2 (h->size);
5426 if (power_of_two > 3)
5427 power_of_two = 3;
5429 /* Apply the required alignment. */
5430 s->size = BFD_ALIGN (s->size, (bfd_size_type) (1 << power_of_two));
5431 if (power_of_two > bfd_get_section_alignment (dynobj, s))
5433 if (! bfd_set_section_alignment (dynobj, s, power_of_two))
5434 return FALSE;
5437 /* Define the symbol as being at this point in the section. */
5438 h->root.u.def.section = s;
5439 h->root.u.def.value = s->size;
5441 /* Increment the section size to make room for the symbol. */
5442 s->size += h->size;
5444 return TRUE;
5447 /* Allocate space in .plt, .got and associated reloc sections for
5448 dynamic relocs. */
5450 static bfd_boolean
5451 allocate_dynrelocs (struct elf_link_hash_entry *h, void * inf)
5453 struct bfd_link_info *info;
5454 struct elf32_arm_link_hash_table *htab;
5455 struct elf32_arm_link_hash_entry *eh;
5456 struct elf32_arm_relocs_copied *p;
5458 eh = (struct elf32_arm_link_hash_entry *) h;
5460 if (h->root.type == bfd_link_hash_indirect)
5461 return TRUE;
5463 if (h->root.type == bfd_link_hash_warning)
5464 /* When warning symbols are created, they **replace** the "real"
5465 entry in the hash table, thus we never get to see the real
5466 symbol in a hash traversal. So look at it now. */
5467 h = (struct elf_link_hash_entry *) h->root.u.i.link;
5469 info = (struct bfd_link_info *) inf;
5470 htab = elf32_arm_hash_table (info);
5472 if (htab->root.dynamic_sections_created
5473 && h->plt.refcount > 0)
5475 /* Make sure this symbol is output as a dynamic symbol.
5476 Undefined weak syms won't yet be marked as dynamic. */
5477 if (h->dynindx == -1
5478 && !h->forced_local)
5480 if (! bfd_elf_link_record_dynamic_symbol (info, h))
5481 return FALSE;
5484 if (info->shared
5485 || WILL_CALL_FINISH_DYNAMIC_SYMBOL (1, 0, h))
5487 asection *s = htab->splt;
5489 /* If this is the first .plt entry, make room for the special
5490 first entry. */
5491 if (s->size == 0)
5492 s->size += htab->plt_header_size;
5494 h->plt.offset = s->size;
5496 /* If we will insert a Thumb trampoline before this PLT, leave room
5497 for it. */
5498 if (!htab->use_blx && eh->plt_thumb_refcount > 0)
5500 h->plt.offset += PLT_THUMB_STUB_SIZE;
5501 s->size += PLT_THUMB_STUB_SIZE;
5504 /* If this symbol is not defined in a regular file, and we are
5505 not generating a shared library, then set the symbol to this
5506 location in the .plt. This is required to make function
5507 pointers compare as equal between the normal executable and
5508 the shared library. */
5509 if (! info->shared
5510 && !h->def_regular)
5512 h->root.u.def.section = s;
5513 h->root.u.def.value = h->plt.offset;
5515 /* Make sure the function is not marked as Thumb, in case
5516 it is the target of an ABS32 relocation, which will
5517 point to the PLT entry. */
5518 if (ELF_ST_TYPE (h->type) == STT_ARM_TFUNC)
5519 h->type = ELF_ST_INFO (ELF_ST_BIND (h->type), STT_FUNC);
5522 /* Make room for this entry. */
5523 s->size += htab->plt_entry_size;
5525 if (!htab->symbian_p)
5527 /* We also need to make an entry in the .got.plt section, which
5528 will be placed in the .got section by the linker script. */
5529 eh->plt_got_offset = htab->sgotplt->size;
5530 htab->sgotplt->size += 4;
5533 /* We also need to make an entry in the .rel.plt section. */
5534 htab->srelplt->size += sizeof (Elf32_External_Rel);
5536 else
5538 h->plt.offset = (bfd_vma) -1;
5539 h->needs_plt = 0;
5542 else
5544 h->plt.offset = (bfd_vma) -1;
5545 h->needs_plt = 0;
5548 if (h->got.refcount > 0)
5550 asection *s;
5551 bfd_boolean dyn;
5552 int tls_type = elf32_arm_hash_entry (h)->tls_type;
5553 int indx;
5555 /* Make sure this symbol is output as a dynamic symbol.
5556 Undefined weak syms won't yet be marked as dynamic. */
5557 if (h->dynindx == -1
5558 && !h->forced_local)
5560 if (! bfd_elf_link_record_dynamic_symbol (info, h))
5561 return FALSE;
5564 if (!htab->symbian_p)
5566 s = htab->sgot;
5567 h->got.offset = s->size;
5569 if (tls_type == GOT_UNKNOWN)
5570 abort ();
5572 if (tls_type == GOT_NORMAL)
5573 /* Non-TLS symbols need one GOT slot. */
5574 s->size += 4;
5575 else
5577 if (tls_type & GOT_TLS_GD)
5578 /* R_ARM_TLS_GD32 needs 2 consecutive GOT slots. */
5579 s->size += 8;
5580 if (tls_type & GOT_TLS_IE)
5581 /* R_ARM_TLS_IE32 needs one GOT slot. */
5582 s->size += 4;
5585 dyn = htab->root.dynamic_sections_created;
5587 indx = 0;
5588 if (WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn, info->shared, h)
5589 && (!info->shared
5590 || !SYMBOL_REFERENCES_LOCAL (info, h)))
5591 indx = h->dynindx;
5593 if (tls_type != GOT_NORMAL
5594 && (info->shared || indx != 0)
5595 && (ELF_ST_VISIBILITY (h->other) == STV_DEFAULT
5596 || h->root.type != bfd_link_hash_undefweak))
5598 if (tls_type & GOT_TLS_IE)
5599 htab->srelgot->size += sizeof (Elf32_External_Rel);
5601 if (tls_type & GOT_TLS_GD)
5602 htab->srelgot->size += sizeof (Elf32_External_Rel);
5604 if ((tls_type & GOT_TLS_GD) && indx != 0)
5605 htab->srelgot->size += sizeof (Elf32_External_Rel);
5607 else if ((ELF_ST_VISIBILITY (h->other) == STV_DEFAULT
5608 || h->root.type != bfd_link_hash_undefweak)
5609 && (info->shared
5610 || WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn, 0, h)))
5611 htab->srelgot->size += sizeof (Elf32_External_Rel);
5614 else
5615 h->got.offset = (bfd_vma) -1;
5617 if (eh->relocs_copied == NULL)
5618 return TRUE;
5620 /* In the shared -Bsymbolic case, discard space allocated for
5621 dynamic pc-relative relocs against symbols which turn out to be
5622 defined in regular objects. For the normal shared case, discard
5623 space for pc-relative relocs that have become local due to symbol
5624 visibility changes. */
5626 if (info->shared || htab->root.is_relocatable_executable)
5628 /* The only reloc that uses pc_count is R_ARM_REL32, which will
5629 appear on something like ".long foo - .". We want calls to
5630 protected symbols to resolve directly to the function rather
5631 than going via the plt. If people want function pointer
5632 comparisons to work as expected then they should avoid
5633 writing assembly like ".long foo - .". */
5634 if (SYMBOL_CALLS_LOCAL (info, h))
5636 struct elf32_arm_relocs_copied **pp;
5638 for (pp = &eh->relocs_copied; (p = *pp) != NULL; )
5640 p->count -= p->pc_count;
5641 p->pc_count = 0;
5642 if (p->count == 0)
5643 *pp = p->next;
5644 else
5645 pp = &p->next;
5649 /* Also discard relocs on undefined weak syms with non-default
5650 visibility. */
5651 if (ELF_ST_VISIBILITY (h->other) != STV_DEFAULT
5652 && h->root.type == bfd_link_hash_undefweak)
5653 eh->relocs_copied = NULL;
5654 else if (htab->root.is_relocatable_executable && h->dynindx == -1
5655 && h->root.type == bfd_link_hash_new)
5657 /* Output absolute symbols so that we can create relocations
5658 against them. For normal symbols we output a relocation
5659 against the section that contains them. */
5660 if (! bfd_elf_link_record_dynamic_symbol (info, h))
5661 return FALSE;
5665 else
5667 /* For the non-shared case, discard space for relocs against
5668 symbols which turn out to need copy relocs or are not
5669 dynamic. */
5671 if (!h->non_got_ref
5672 && ((h->def_dynamic
5673 && !h->def_regular)
5674 || (htab->root.dynamic_sections_created
5675 && (h->root.type == bfd_link_hash_undefweak
5676 || h->root.type == bfd_link_hash_undefined))))
5678 /* Make sure this symbol is output as a dynamic symbol.
5679 Undefined weak syms won't yet be marked as dynamic. */
5680 if (h->dynindx == -1
5681 && !h->forced_local)
5683 if (! bfd_elf_link_record_dynamic_symbol (info, h))
5684 return FALSE;
5687 /* If that succeeded, we know we'll be keeping all the
5688 relocs. */
5689 if (h->dynindx != -1)
5690 goto keep;
5693 eh->relocs_copied = NULL;
5695 keep: ;
5698 /* Finally, allocate space. */
5699 for (p = eh->relocs_copied; p != NULL; p = p->next)
5701 asection *sreloc = elf_section_data (p->section)->sreloc;
5702 sreloc->size += p->count * sizeof (Elf32_External_Rel);
5705 return TRUE;
5708 /* Find any dynamic relocs that apply to read-only sections. */
5710 static bfd_boolean
5711 elf32_arm_readonly_dynrelocs (struct elf_link_hash_entry *h, PTR inf)
5713 struct elf32_arm_link_hash_entry *eh;
5714 struct elf32_arm_relocs_copied *p;
5716 if (h->root.type == bfd_link_hash_warning)
5717 h = (struct elf_link_hash_entry *) h->root.u.i.link;
5719 eh = (struct elf32_arm_link_hash_entry *) h;
5720 for (p = eh->relocs_copied; p != NULL; p = p->next)
5722 asection *s = p->section;
5724 if (s != NULL && (s->flags & SEC_READONLY) != 0)
5726 struct bfd_link_info *info = (struct bfd_link_info *) inf;
5728 info->flags |= DF_TEXTREL;
5730 /* Not an error, just cut short the traversal. */
5731 return FALSE;
5734 return TRUE;
5737 /* Set the sizes of the dynamic sections. */
5739 static bfd_boolean
5740 elf32_arm_size_dynamic_sections (bfd * output_bfd ATTRIBUTE_UNUSED,
5741 struct bfd_link_info * info)
5743 bfd * dynobj;
5744 asection * s;
5745 bfd_boolean plt;
5746 bfd_boolean relocs;
5747 bfd *ibfd;
5748 struct elf32_arm_link_hash_table *htab;
5750 htab = elf32_arm_hash_table (info);
5751 dynobj = elf_hash_table (info)->dynobj;
5752 BFD_ASSERT (dynobj != NULL);
5754 if (elf_hash_table (info)->dynamic_sections_created)
5756 /* Set the contents of the .interp section to the interpreter. */
5757 if (info->executable)
5759 s = bfd_get_section_by_name (dynobj, ".interp");
5760 BFD_ASSERT (s != NULL);
5761 s->size = sizeof ELF_DYNAMIC_INTERPRETER;
5762 s->contents = (unsigned char *) ELF_DYNAMIC_INTERPRETER;
5766 /* Set up .got offsets for local syms, and space for local dynamic
5767 relocs. */
5768 for (ibfd = info->input_bfds; ibfd != NULL; ibfd = ibfd->link_next)
5770 bfd_signed_vma *local_got;
5771 bfd_signed_vma *end_local_got;
5772 char *local_tls_type;
5773 bfd_size_type locsymcount;
5774 Elf_Internal_Shdr *symtab_hdr;
5775 asection *srel;
5777 if (bfd_get_flavour (ibfd) != bfd_target_elf_flavour)
5778 continue;
5780 for (s = ibfd->sections; s != NULL; s = s->next)
5782 struct elf32_arm_relocs_copied *p;
5784 for (p = *((struct elf32_arm_relocs_copied **)
5785 &elf_section_data (s)->local_dynrel);
5786 p != NULL;
5787 p = p->next)
5789 if (!bfd_is_abs_section (p->section)
5790 && bfd_is_abs_section (p->section->output_section))
5792 /* Input section has been discarded, either because
5793 it is a copy of a linkonce section or due to
5794 linker script /DISCARD/, so we'll be discarding
5795 the relocs too. */
5797 else if (p->count != 0)
5799 srel = elf_section_data (p->section)->sreloc;
5800 srel->size += p->count * sizeof (Elf32_External_Rel);
5801 if ((p->section->output_section->flags & SEC_READONLY) != 0)
5802 info->flags |= DF_TEXTREL;
5807 local_got = elf_local_got_refcounts (ibfd);
5808 if (!local_got)
5809 continue;
5811 symtab_hdr = &elf_tdata (ibfd)->symtab_hdr;
5812 locsymcount = symtab_hdr->sh_info;
5813 end_local_got = local_got + locsymcount;
5814 local_tls_type = elf32_arm_local_got_tls_type (ibfd);
5815 s = htab->sgot;
5816 srel = htab->srelgot;
5817 for (; local_got < end_local_got; ++local_got, ++local_tls_type)
5819 if (*local_got > 0)
5821 *local_got = s->size;
5822 if (*local_tls_type & GOT_TLS_GD)
5823 /* TLS_GD relocs need an 8-byte structure in the GOT. */
5824 s->size += 8;
5825 if (*local_tls_type & GOT_TLS_IE)
5826 s->size += 4;
5827 if (*local_tls_type == GOT_NORMAL)
5828 s->size += 4;
5830 if (info->shared || *local_tls_type == GOT_TLS_GD)
5831 srel->size += sizeof (Elf32_External_Rel);
5833 else
5834 *local_got = (bfd_vma) -1;
5838 if (htab->tls_ldm_got.refcount > 0)
5840 /* Allocate two GOT entries and one dynamic relocation (if necessary)
5841 for R_ARM_TLS_LDM32 relocations. */
5842 htab->tls_ldm_got.offset = htab->sgot->size;
5843 htab->sgot->size += 8;
5844 if (info->shared)
5845 htab->srelgot->size += sizeof (Elf32_External_Rel);
5847 else
5848 htab->tls_ldm_got.offset = -1;
5850 /* Allocate global sym .plt and .got entries, and space for global
5851 sym dynamic relocs. */
5852 elf_link_hash_traverse (& htab->root, allocate_dynrelocs, info);
5854 /* The check_relocs and adjust_dynamic_symbol entry points have
5855 determined the sizes of the various dynamic sections. Allocate
5856 memory for them. */
5857 plt = FALSE;
5858 relocs = FALSE;
5859 for (s = dynobj->sections; s != NULL; s = s->next)
5861 const char * name;
5862 bfd_boolean strip;
5864 if ((s->flags & SEC_LINKER_CREATED) == 0)
5865 continue;
5867 /* It's OK to base decisions on the section name, because none
5868 of the dynobj section names depend upon the input files. */
5869 name = bfd_get_section_name (dynobj, s);
5871 strip = FALSE;
5873 if (strcmp (name, ".plt") == 0)
5875 if (s->size == 0)
5877 /* Strip this section if we don't need it; see the
5878 comment below. */
5879 strip = TRUE;
5881 else
5883 /* Remember whether there is a PLT. */
5884 plt = TRUE;
5887 else if (strncmp (name, ".rel", 4) == 0)
5889 if (s->size == 0)
5891 /* If we don't need this section, strip it from the
5892 output file. This is mostly to handle .rel.bss and
5893 .rel.plt. We must create both sections in
5894 create_dynamic_sections, because they must be created
5895 before the linker maps input sections to output
5896 sections. The linker does that before
5897 adjust_dynamic_symbol is called, and it is that
5898 function which decides whether anything needs to go
5899 into these sections. */
5900 strip = TRUE;
5902 else
5904 /* Remember whether there are any reloc sections other
5905 than .rel.plt. */
5906 if (strcmp (name, ".rel.plt") != 0)
5907 relocs = TRUE;
5909 /* We use the reloc_count field as a counter if we need
5910 to copy relocs into the output file. */
5911 s->reloc_count = 0;
5914 else if (strncmp (name, ".got", 4) != 0)
5916 /* It's not one of our sections, so don't allocate space. */
5917 continue;
5920 if (strip)
5922 s->flags |= SEC_EXCLUDE;
5923 continue;
5926 /* Allocate memory for the section contents. */
5927 s->contents = (bfd_byte *) bfd_zalloc (dynobj, s->size);
5928 if (s->contents == NULL && s->size != 0)
5929 return FALSE;
5932 if (elf_hash_table (info)->dynamic_sections_created)
5934 /* Add some entries to the .dynamic section. We fill in the
5935 values later, in elf32_arm_finish_dynamic_sections, but we
5936 must add the entries now so that we get the correct size for
5937 the .dynamic section. The DT_DEBUG entry is filled in by the
5938 dynamic linker and used by the debugger. */
5939 #define add_dynamic_entry(TAG, VAL) \
5940 _bfd_elf_add_dynamic_entry (info, TAG, VAL)
5942 if (!info->shared)
5944 if (!add_dynamic_entry (DT_DEBUG, 0))
5945 return FALSE;
5948 if (plt)
5950 if ( !add_dynamic_entry (DT_PLTGOT, 0)
5951 || !add_dynamic_entry (DT_PLTRELSZ, 0)
5952 || !add_dynamic_entry (DT_PLTREL, DT_REL)
5953 || !add_dynamic_entry (DT_JMPREL, 0))
5954 return FALSE;
5957 if (relocs)
5959 if ( !add_dynamic_entry (DT_REL, 0)
5960 || !add_dynamic_entry (DT_RELSZ, 0)
5961 || !add_dynamic_entry (DT_RELENT, sizeof (Elf32_External_Rel)))
5962 return FALSE;
5965 /* If any dynamic relocs apply to a read-only section,
5966 then we need a DT_TEXTREL entry. */
5967 if ((info->flags & DF_TEXTREL) == 0)
5968 elf_link_hash_traverse (&htab->root, elf32_arm_readonly_dynrelocs,
5969 (PTR) info);
5971 if ((info->flags & DF_TEXTREL) != 0)
5973 if (!add_dynamic_entry (DT_TEXTREL, 0))
5974 return FALSE;
5975 info->flags |= DF_TEXTREL;
5978 #undef add_synamic_entry
5980 return TRUE;
5983 /* Finish up dynamic symbol handling. We set the contents of various
5984 dynamic sections here. */
5986 static bfd_boolean
5987 elf32_arm_finish_dynamic_symbol (bfd * output_bfd, struct bfd_link_info * info,
5988 struct elf_link_hash_entry * h, Elf_Internal_Sym * sym)
5990 bfd * dynobj;
5991 struct elf32_arm_link_hash_table *htab;
5992 struct elf32_arm_link_hash_entry *eh;
5994 dynobj = elf_hash_table (info)->dynobj;
5995 htab = elf32_arm_hash_table (info);
5996 eh = (struct elf32_arm_link_hash_entry *) h;
5998 if (h->plt.offset != (bfd_vma) -1)
6000 asection * splt;
6001 asection * srel;
6002 bfd_byte *loc;
6003 bfd_vma plt_index;
6004 Elf_Internal_Rela rel;
6006 /* This symbol has an entry in the procedure linkage table. Set
6007 it up. */
6009 BFD_ASSERT (h->dynindx != -1);
6011 splt = bfd_get_section_by_name (dynobj, ".plt");
6012 srel = bfd_get_section_by_name (dynobj, ".rel.plt");
6013 BFD_ASSERT (splt != NULL && srel != NULL);
6015 /* Fill in the entry in the procedure linkage table. */
6016 if (htab->symbian_p)
6018 unsigned i;
6019 for (i = 0; i < htab->plt_entry_size / 4; ++i)
6020 bfd_put_32 (output_bfd,
6021 elf32_arm_symbian_plt_entry[i],
6022 splt->contents + h->plt.offset + 4 * i);
6024 /* Fill in the entry in the .rel.plt section. */
6025 rel.r_offset = (splt->output_section->vma
6026 + splt->output_offset
6027 + h->plt.offset + 4 * (i - 1));
6028 rel.r_info = ELF32_R_INFO (h->dynindx, R_ARM_GLOB_DAT);
6030 /* Get the index in the procedure linkage table which
6031 corresponds to this symbol. This is the index of this symbol
6032 in all the symbols for which we are making plt entries. The
6033 first entry in the procedure linkage table is reserved. */
6034 plt_index = ((h->plt.offset - htab->plt_header_size)
6035 / htab->plt_entry_size);
6037 else
6039 bfd_vma got_offset;
6040 bfd_vma got_displacement;
6041 asection * sgot;
6043 sgot = bfd_get_section_by_name (dynobj, ".got.plt");
6044 BFD_ASSERT (sgot != NULL);
6046 /* Get the offset into the .got.plt table of the entry that
6047 corresponds to this function. */
6048 got_offset = eh->plt_got_offset;
6050 /* Get the index in the procedure linkage table which
6051 corresponds to this symbol. This is the index of this symbol
6052 in all the symbols for which we are making plt entries. The
6053 first three entries in .got.plt are reserved; after that
6054 symbols appear in the same order as in .plt. */
6055 plt_index = (got_offset - 12) / 4;
6057 /* Calculate the displacement between the PLT slot and the
6058 entry in the GOT. The eight-byte offset accounts for the
6059 value produced by adding to pc in the first instruction
6060 of the PLT stub. */
6061 got_displacement = (sgot->output_section->vma
6062 + sgot->output_offset
6063 + got_offset
6064 - splt->output_section->vma
6065 - splt->output_offset
6066 - h->plt.offset
6067 - 8);
6069 BFD_ASSERT ((got_displacement & 0xf0000000) == 0);
6071 if (!htab->use_blx && eh->plt_thumb_refcount > 0)
6073 bfd_put_16 (output_bfd, elf32_arm_plt_thumb_stub[0],
6074 splt->contents + h->plt.offset - 4);
6075 bfd_put_16 (output_bfd, elf32_arm_plt_thumb_stub[1],
6076 splt->contents + h->plt.offset - 2);
6079 bfd_put_32 (output_bfd, elf32_arm_plt_entry[0] | ((got_displacement & 0x0ff00000) >> 20),
6080 splt->contents + h->plt.offset + 0);
6081 bfd_put_32 (output_bfd, elf32_arm_plt_entry[1] | ((got_displacement & 0x000ff000) >> 12),
6082 splt->contents + h->plt.offset + 4);
6083 bfd_put_32 (output_bfd, elf32_arm_plt_entry[2] | (got_displacement & 0x00000fff),
6084 splt->contents + h->plt.offset + 8);
6085 #ifdef FOUR_WORD_PLT
6086 bfd_put_32 (output_bfd, elf32_arm_plt_entry[3],
6087 splt->contents + h->plt.offset + 12);
6088 #endif
6090 /* Fill in the entry in the global offset table. */
6091 bfd_put_32 (output_bfd,
6092 (splt->output_section->vma
6093 + splt->output_offset),
6094 sgot->contents + got_offset);
6096 /* Fill in the entry in the .rel.plt section. */
6097 rel.r_offset = (sgot->output_section->vma
6098 + sgot->output_offset
6099 + got_offset);
6100 rel.r_info = ELF32_R_INFO (h->dynindx, R_ARM_JUMP_SLOT);
6103 loc = srel->contents + plt_index * sizeof (Elf32_External_Rel);
6104 bfd_elf32_swap_reloc_out (output_bfd, &rel, loc);
6106 if (!h->def_regular)
6108 /* Mark the symbol as undefined, rather than as defined in
6109 the .plt section. Leave the value alone. */
6110 sym->st_shndx = SHN_UNDEF;
6111 /* If the symbol is weak, we do need to clear the value.
6112 Otherwise, the PLT entry would provide a definition for
6113 the symbol even if the symbol wasn't defined anywhere,
6114 and so the symbol would never be NULL. */
6115 if (!h->ref_regular_nonweak)
6116 sym->st_value = 0;
6120 if (h->got.offset != (bfd_vma) -1
6121 && (elf32_arm_hash_entry (h)->tls_type & GOT_TLS_GD) == 0
6122 && (elf32_arm_hash_entry (h)->tls_type & GOT_TLS_IE) == 0)
6124 asection * sgot;
6125 asection * srel;
6126 Elf_Internal_Rela rel;
6127 bfd_byte *loc;
6129 /* This symbol has an entry in the global offset table. Set it
6130 up. */
6131 sgot = bfd_get_section_by_name (dynobj, ".got");
6132 srel = bfd_get_section_by_name (dynobj, ".rel.got");
6133 BFD_ASSERT (sgot != NULL && srel != NULL);
6135 rel.r_offset = (sgot->output_section->vma
6136 + sgot->output_offset
6137 + (h->got.offset &~ (bfd_vma) 1));
6139 /* If this is a static link, or it is a -Bsymbolic link and the
6140 symbol is defined locally or was forced to be local because
6141 of a version file, we just want to emit a RELATIVE reloc.
6142 The entry in the global offset table will already have been
6143 initialized in the relocate_section function. */
6144 if (info->shared
6145 && SYMBOL_REFERENCES_LOCAL (info, h))
6147 BFD_ASSERT((h->got.offset & 1) != 0);
6148 rel.r_info = ELF32_R_INFO (0, R_ARM_RELATIVE);
6150 else
6152 BFD_ASSERT((h->got.offset & 1) == 0);
6153 bfd_put_32 (output_bfd, (bfd_vma) 0, sgot->contents + h->got.offset);
6154 rel.r_info = ELF32_R_INFO (h->dynindx, R_ARM_GLOB_DAT);
6157 loc = srel->contents + srel->reloc_count++ * sizeof (Elf32_External_Rel);
6158 bfd_elf32_swap_reloc_out (output_bfd, &rel, loc);
6161 if (h->needs_copy)
6163 asection * s;
6164 Elf_Internal_Rela rel;
6165 bfd_byte *loc;
6167 /* This symbol needs a copy reloc. Set it up. */
6168 BFD_ASSERT (h->dynindx != -1
6169 && (h->root.type == bfd_link_hash_defined
6170 || h->root.type == bfd_link_hash_defweak));
6172 s = bfd_get_section_by_name (h->root.u.def.section->owner,
6173 ".rel.bss");
6174 BFD_ASSERT (s != NULL);
6176 rel.r_offset = (h->root.u.def.value
6177 + h->root.u.def.section->output_section->vma
6178 + h->root.u.def.section->output_offset);
6179 rel.r_info = ELF32_R_INFO (h->dynindx, R_ARM_COPY);
6180 loc = s->contents + s->reloc_count++ * sizeof (Elf32_External_Rel);
6181 bfd_elf32_swap_reloc_out (output_bfd, &rel, loc);
6184 /* Mark _DYNAMIC and _GLOBAL_OFFSET_TABLE_ as absolute. */
6185 if (strcmp (h->root.root.string, "_DYNAMIC") == 0
6186 || strcmp (h->root.root.string, "_GLOBAL_OFFSET_TABLE_") == 0)
6187 sym->st_shndx = SHN_ABS;
6189 return TRUE;
6192 /* Finish up the dynamic sections. */
6194 static bfd_boolean
6195 elf32_arm_finish_dynamic_sections (bfd * output_bfd, struct bfd_link_info * info)
6197 bfd * dynobj;
6198 asection * sgot;
6199 asection * sdyn;
6201 dynobj = elf_hash_table (info)->dynobj;
6203 sgot = bfd_get_section_by_name (dynobj, ".got.plt");
6204 BFD_ASSERT (elf32_arm_hash_table (info)->symbian_p || sgot != NULL);
6205 sdyn = bfd_get_section_by_name (dynobj, ".dynamic");
6207 if (elf_hash_table (info)->dynamic_sections_created)
6209 asection *splt;
6210 Elf32_External_Dyn *dyncon, *dynconend;
6211 struct elf32_arm_link_hash_table *htab;
6213 htab = elf32_arm_hash_table (info);
6214 splt = bfd_get_section_by_name (dynobj, ".plt");
6215 BFD_ASSERT (splt != NULL && sdyn != NULL);
6217 dyncon = (Elf32_External_Dyn *) sdyn->contents;
6218 dynconend = (Elf32_External_Dyn *) (sdyn->contents + sdyn->size);
6220 for (; dyncon < dynconend; dyncon++)
6222 Elf_Internal_Dyn dyn;
6223 const char * name;
6224 asection * s;
6226 bfd_elf32_swap_dyn_in (dynobj, dyncon, &dyn);
6228 switch (dyn.d_tag)
6230 unsigned int type;
6232 default:
6233 break;
6235 case DT_HASH:
6236 name = ".hash";
6237 goto get_vma_if_bpabi;
6238 case DT_STRTAB:
6239 name = ".dynstr";
6240 goto get_vma_if_bpabi;
6241 case DT_SYMTAB:
6242 name = ".dynsym";
6243 goto get_vma_if_bpabi;
6244 case DT_VERSYM:
6245 name = ".gnu.version";
6246 goto get_vma_if_bpabi;
6247 case DT_VERDEF:
6248 name = ".gnu.version_d";
6249 goto get_vma_if_bpabi;
6250 case DT_VERNEED:
6251 name = ".gnu.version_r";
6252 goto get_vma_if_bpabi;
6254 case DT_PLTGOT:
6255 name = ".got";
6256 goto get_vma;
6257 case DT_JMPREL:
6258 name = ".rel.plt";
6259 get_vma:
6260 s = bfd_get_section_by_name (output_bfd, name);
6261 BFD_ASSERT (s != NULL);
6262 if (!htab->symbian_p)
6263 dyn.d_un.d_ptr = s->vma;
6264 else
6265 /* In the BPABI, tags in the PT_DYNAMIC section point
6266 at the file offset, not the memory address, for the
6267 convenience of the post linker. */
6268 dyn.d_un.d_ptr = s->filepos;
6269 bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon);
6270 break;
6272 get_vma_if_bpabi:
6273 if (htab->symbian_p)
6274 goto get_vma;
6275 break;
6277 case DT_PLTRELSZ:
6278 s = bfd_get_section_by_name (output_bfd, ".rel.plt");
6279 BFD_ASSERT (s != NULL);
6280 dyn.d_un.d_val = s->size;
6281 bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon);
6282 break;
6284 case DT_RELSZ:
6285 if (!htab->symbian_p)
6287 /* My reading of the SVR4 ABI indicates that the
6288 procedure linkage table relocs (DT_JMPREL) should be
6289 included in the overall relocs (DT_REL). This is
6290 what Solaris does. However, UnixWare can not handle
6291 that case. Therefore, we override the DT_RELSZ entry
6292 here to make it not include the JMPREL relocs. Since
6293 the linker script arranges for .rel.plt to follow all
6294 other relocation sections, we don't have to worry
6295 about changing the DT_REL entry. */
6296 s = bfd_get_section_by_name (output_bfd, ".rel.plt");
6297 if (s != NULL)
6298 dyn.d_un.d_val -= s->size;
6299 bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon);
6300 break;
6302 /* Fall through */
6304 case DT_REL:
6305 case DT_RELA:
6306 case DT_RELASZ:
6307 /* In the BPABI, the DT_REL tag must point at the file
6308 offset, not the VMA, of the first relocation
6309 section. So, we use code similar to that in
6310 elflink.c, but do not check for SHF_ALLOC on the
6311 relcoation section, since relocations sections are
6312 never allocated under the BPABI. The comments above
6313 about Unixware notwithstanding, we include all of the
6314 relocations here. */
6315 if (htab->symbian_p)
6317 unsigned int i;
6318 type = ((dyn.d_tag == DT_REL || dyn.d_tag == DT_RELSZ)
6319 ? SHT_REL : SHT_RELA);
6320 dyn.d_un.d_val = 0;
6321 for (i = 1; i < elf_numsections (output_bfd); i++)
6323 Elf_Internal_Shdr *hdr
6324 = elf_elfsections (output_bfd)[i];
6325 if (hdr->sh_type == type)
6327 if (dyn.d_tag == DT_RELSZ
6328 || dyn.d_tag == DT_RELASZ)
6329 dyn.d_un.d_val += hdr->sh_size;
6330 else if ((ufile_ptr) hdr->sh_offset
6331 <= dyn.d_un.d_val - 1)
6332 dyn.d_un.d_val = hdr->sh_offset;
6335 bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon);
6337 break;
6339 /* Set the bottom bit of DT_INIT/FINI if the
6340 corresponding function is Thumb. */
6341 case DT_INIT:
6342 name = info->init_function;
6343 goto get_sym;
6344 case DT_FINI:
6345 name = info->fini_function;
6346 get_sym:
6347 /* If it wasn't set by elf_bfd_final_link
6348 then there is nothing to adjust. */
6349 if (dyn.d_un.d_val != 0)
6351 struct elf_link_hash_entry * eh;
6353 eh = elf_link_hash_lookup (elf_hash_table (info), name,
6354 FALSE, FALSE, TRUE);
6355 if (eh != (struct elf_link_hash_entry *) NULL
6356 && ELF_ST_TYPE (eh->type) == STT_ARM_TFUNC)
6358 dyn.d_un.d_val |= 1;
6359 bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon);
6362 break;
6366 /* Fill in the first entry in the procedure linkage table. */
6367 if (splt->size > 0 && elf32_arm_hash_table (info)->plt_header_size)
6369 bfd_vma got_displacement;
6371 /* Calculate the displacement between the PLT slot and &GOT[0]. */
6372 got_displacement = (sgot->output_section->vma
6373 + sgot->output_offset
6374 - splt->output_section->vma
6375 - splt->output_offset
6376 - 16);
6378 bfd_put_32 (output_bfd, elf32_arm_plt0_entry[0], splt->contents + 0);
6379 bfd_put_32 (output_bfd, elf32_arm_plt0_entry[1], splt->contents + 4);
6380 bfd_put_32 (output_bfd, elf32_arm_plt0_entry[2], splt->contents + 8);
6381 bfd_put_32 (output_bfd, elf32_arm_plt0_entry[3], splt->contents + 12);
6382 #ifdef FOUR_WORD_PLT
6383 /* The displacement value goes in the otherwise-unused last word of
6384 the second entry. */
6385 bfd_put_32 (output_bfd, got_displacement, splt->contents + 28);
6386 #else
6387 bfd_put_32 (output_bfd, got_displacement, splt->contents + 16);
6388 #endif
6391 /* UnixWare sets the entsize of .plt to 4, although that doesn't
6392 really seem like the right value. */
6393 elf_section_data (splt->output_section)->this_hdr.sh_entsize = 4;
6396 /* Fill in the first three entries in the global offset table. */
6397 if (sgot)
6399 if (sgot->size > 0)
6401 if (sdyn == NULL)
6402 bfd_put_32 (output_bfd, (bfd_vma) 0, sgot->contents);
6403 else
6404 bfd_put_32 (output_bfd,
6405 sdyn->output_section->vma + sdyn->output_offset,
6406 sgot->contents);
6407 bfd_put_32 (output_bfd, (bfd_vma) 0, sgot->contents + 4);
6408 bfd_put_32 (output_bfd, (bfd_vma) 0, sgot->contents + 8);
6411 elf_section_data (sgot->output_section)->this_hdr.sh_entsize = 4;
6414 return TRUE;
6417 static void
6418 elf32_arm_post_process_headers (bfd * abfd, struct bfd_link_info * link_info ATTRIBUTE_UNUSED)
6420 Elf_Internal_Ehdr * i_ehdrp; /* ELF file header, internal form. */
6421 struct elf32_arm_link_hash_table *globals;
6423 i_ehdrp = elf_elfheader (abfd);
6425 if (EF_ARM_EABI_VERSION (i_ehdrp->e_flags) == EF_ARM_EABI_UNKNOWN)
6426 i_ehdrp->e_ident[EI_OSABI] = ELFOSABI_ARM;
6427 else
6428 i_ehdrp->e_ident[EI_OSABI] = 0;
6429 i_ehdrp->e_ident[EI_ABIVERSION] = ARM_ELF_ABI_VERSION;
6431 if (link_info)
6433 globals = elf32_arm_hash_table (link_info);
6434 if (globals->byteswap_code)
6435 i_ehdrp->e_flags |= EF_ARM_BE8;
6439 static enum elf_reloc_type_class
6440 elf32_arm_reloc_type_class (const Elf_Internal_Rela *rela)
6442 switch ((int) ELF32_R_TYPE (rela->r_info))
6444 case R_ARM_RELATIVE:
6445 return reloc_class_relative;
6446 case R_ARM_JUMP_SLOT:
6447 return reloc_class_plt;
6448 case R_ARM_COPY:
6449 return reloc_class_copy;
6450 default:
6451 return reloc_class_normal;
6455 /* Set the right machine number for an Arm ELF file. */
6457 static bfd_boolean
6458 elf32_arm_section_flags (flagword *flags, const Elf_Internal_Shdr *hdr)
6460 if (hdr->sh_type == SHT_NOTE)
6461 *flags |= SEC_LINK_ONCE | SEC_LINK_DUPLICATES_SAME_CONTENTS;
6463 return TRUE;
6466 static void
6467 elf32_arm_final_write_processing (bfd *abfd, bfd_boolean linker ATTRIBUTE_UNUSED)
6469 bfd_arm_update_notes (abfd, ARM_NOTE_SECTION);
6472 /* Return TRUE if this is an unwinding table entry. */
6474 static bfd_boolean
6475 is_arm_elf_unwind_section_name (bfd * abfd ATTRIBUTE_UNUSED, const char * name)
6477 size_t len1, len2;
6479 len1 = sizeof (ELF_STRING_ARM_unwind) - 1;
6480 len2 = sizeof (ELF_STRING_ARM_unwind_once) - 1;
6481 return (strncmp (name, ELF_STRING_ARM_unwind, len1) == 0
6482 || strncmp (name, ELF_STRING_ARM_unwind_once, len2) == 0);
6486 /* Set the type and flags for an ARM section. We do this by
6487 the section name, which is a hack, but ought to work. */
6489 static bfd_boolean
6490 elf32_arm_fake_sections (bfd * abfd, Elf_Internal_Shdr * hdr, asection * sec)
6492 const char * name;
6494 name = bfd_get_section_name (abfd, sec);
6496 if (is_arm_elf_unwind_section_name (abfd, name))
6498 hdr->sh_type = SHT_ARM_EXIDX;
6499 hdr->sh_flags |= SHF_LINK_ORDER;
6501 return TRUE;
6504 /* Handle an ARM specific section when reading an object file. This is
6505 called when bfd_section_from_shdr finds a section with an unknown
6506 type. */
6508 static bfd_boolean
6509 elf32_arm_section_from_shdr (bfd *abfd,
6510 Elf_Internal_Shdr * hdr,
6511 const char *name,
6512 int shindex)
6514 /* There ought to be a place to keep ELF backend specific flags, but
6515 at the moment there isn't one. We just keep track of the
6516 sections by their name, instead. Fortunately, the ABI gives
6517 names for all the ARM specific sections, so we will probably get
6518 away with this. */
6519 switch (hdr->sh_type)
6521 case SHT_ARM_EXIDX:
6522 break;
6524 default:
6525 return FALSE;
6528 if (! _bfd_elf_make_section_from_shdr (abfd, hdr, name, shindex))
6529 return FALSE;
6531 return TRUE;
6534 /* Called for each symbol. Builds a section map based on mapping symbols.
6535 Does not alter any of the symbols. */
6537 static bfd_boolean
6538 elf32_arm_output_symbol_hook (struct bfd_link_info *info,
6539 const char *name,
6540 Elf_Internal_Sym *elfsym,
6541 asection *input_sec,
6542 struct elf_link_hash_entry *h ATTRIBUTE_UNUSED)
6544 int mapcount;
6545 elf32_arm_section_map *map;
6546 struct elf32_arm_link_hash_table *globals;
6548 /* Only do this on final link. */
6549 if (info->relocatable)
6550 return TRUE;
6552 /* Only build a map if we need to byteswap code. */
6553 globals = elf32_arm_hash_table (info);
6554 if (!globals->byteswap_code)
6555 return TRUE;
6557 /* We only want mapping symbols. */
6558 if (! bfd_is_arm_mapping_symbol_name (name))
6559 return TRUE;
6561 mapcount = ++(elf32_arm_section_data (input_sec)->mapcount);
6562 map = elf32_arm_section_data (input_sec)->map;
6563 /* TODO: This may be inefficient, but we probably don't usually have many
6564 mapping symbols per section. */
6565 map = bfd_realloc (map, mapcount * sizeof (elf32_arm_section_map));
6566 elf32_arm_section_data (input_sec)->map = map;
6568 map[mapcount - 1].vma = elfsym->st_value;
6569 map[mapcount - 1].type = name[1];
6570 return TRUE;
6574 /* Allocate target specific section data. */
6576 static bfd_boolean
6577 elf32_arm_new_section_hook (bfd *abfd, asection *sec)
6579 struct _arm_elf_section_data *sdata;
6580 bfd_size_type amt = sizeof (*sdata);
6582 sdata = bfd_zalloc (abfd, amt);
6583 if (sdata == NULL)
6584 return FALSE;
6585 sec->used_by_bfd = sdata;
6587 return _bfd_elf_new_section_hook (abfd, sec);
6591 /* Used to order a list of mapping symbols by address. */
6593 static int
6594 elf32_arm_compare_mapping (const void * a, const void * b)
6596 return ((const elf32_arm_section_map *) a)->vma
6597 > ((const elf32_arm_section_map *) b)->vma;
6601 /* Do code byteswapping. Return FALSE afterwards so that the section is
6602 written out as normal. */
6604 static bfd_boolean
6605 elf32_arm_write_section (bfd *output_bfd ATTRIBUTE_UNUSED, asection *sec,
6606 bfd_byte *contents)
6608 int mapcount;
6609 elf32_arm_section_map *map;
6610 bfd_vma ptr;
6611 bfd_vma end;
6612 bfd_vma offset;
6613 bfd_byte tmp;
6614 int i;
6616 mapcount = elf32_arm_section_data (sec)->mapcount;
6617 map = elf32_arm_section_data (sec)->map;
6619 if (mapcount == 0)
6620 return FALSE;
6622 qsort (map, mapcount, sizeof (elf32_arm_section_map),
6623 elf32_arm_compare_mapping);
6625 offset = sec->output_section->vma + sec->output_offset;
6626 ptr = map[0].vma - offset;
6627 for (i = 0; i < mapcount; i++)
6629 if (i == mapcount - 1)
6630 end = sec->size;
6631 else
6632 end = map[i + 1].vma - offset;
6634 switch (map[i].type)
6636 case 'a':
6637 /* Byte swap code words. */
6638 while (ptr + 3 < end)
6640 tmp = contents[ptr];
6641 contents[ptr] = contents[ptr + 3];
6642 contents[ptr + 3] = tmp;
6643 tmp = contents[ptr + 1];
6644 contents[ptr + 1] = contents[ptr + 2];
6645 contents[ptr + 2] = tmp;
6646 ptr += 4;
6648 break;
6650 case 't':
6651 /* Byte swap code halfwords. */
6652 while (ptr + 1 < end)
6654 tmp = contents[ptr];
6655 contents[ptr] = contents[ptr + 1];
6656 contents[ptr + 1] = tmp;
6657 ptr += 2;
6659 break;
6661 case 'd':
6662 /* Leave data alone. */
6663 break;
6665 ptr = end;
6667 free (map);
6668 return FALSE;
6671 /* Display STT_ARM_TFUNC symbols as functions. */
6673 static void
6674 elf32_arm_symbol_processing (bfd *abfd ATTRIBUTE_UNUSED,
6675 asymbol *asym)
6677 elf_symbol_type *elfsym = (elf_symbol_type *) asym;
6679 if (ELF_ST_TYPE (elfsym->internal_elf_sym.st_info) == STT_ARM_TFUNC)
6680 elfsym->symbol.flags |= BSF_FUNCTION;
6684 /* Mangle thumb function symbols as we read them in. */
6686 static void
6687 elf32_arm_swap_symbol_in (bfd * abfd,
6688 const void *psrc,
6689 const void *pshn,
6690 Elf_Internal_Sym *dst)
6692 bfd_elf32_swap_symbol_in (abfd, psrc, pshn, dst);
6694 /* New EABI objects mark thumb function symbols by setting the low bit of
6695 the address. Turn these into STT_ARM_TFUNC. */
6696 if (ELF_ST_TYPE (dst->st_info) == STT_FUNC
6697 && (dst->st_value & 1))
6699 dst->st_info = ELF_ST_INFO (ELF_ST_BIND (dst->st_info), STT_ARM_TFUNC);
6700 dst->st_value &= ~(bfd_vma) 1;
6705 /* Mangle thumb function symbols as we write them out. */
6707 static void
6708 elf32_arm_swap_symbol_out (bfd *abfd,
6709 const Elf_Internal_Sym *src,
6710 void *cdst,
6711 void *shndx)
6713 Elf_Internal_Sym newsym;
6715 /* We convert STT_ARM_TFUNC symbols into STT_FUNC with the low bit
6716 of the address set, as per the new EABI. We do this unconditionally
6717 because objcopy does not set the elf header flags until after
6718 it writes out the symbol table. */
6719 if (ELF_ST_TYPE (src->st_info) == STT_ARM_TFUNC)
6721 newsym = *src;
6722 newsym.st_info = ELF_ST_INFO (ELF_ST_BIND (src->st_info), STT_FUNC);
6723 newsym.st_value |= 1;
6725 src = &newsym;
6727 bfd_elf32_swap_symbol_out (abfd, src, cdst, shndx);
6730 /* Add the PT_ARM_EXIDX program header. */
6732 static bfd_boolean
6733 elf32_arm_modify_segment_map (bfd *abfd,
6734 struct bfd_link_info *info ATTRIBUTE_UNUSED)
6736 struct elf_segment_map *m;
6737 asection *sec;
6739 sec = bfd_get_section_by_name (abfd, ".ARM.exidx");
6740 if (sec != NULL && (sec->flags & SEC_LOAD) != 0)
6742 /* If there is already a PT_ARM_EXIDX header, then we do not
6743 want to add another one. This situation arises when running
6744 "strip"; the input binary already has the header. */
6745 m = elf_tdata (abfd)->segment_map;
6746 while (m && m->p_type != PT_ARM_EXIDX)
6747 m = m->next;
6748 if (!m)
6750 m = bfd_zalloc (abfd, sizeof (struct elf_segment_map));
6751 if (m == NULL)
6752 return FALSE;
6753 m->p_type = PT_ARM_EXIDX;
6754 m->count = 1;
6755 m->sections[0] = sec;
6757 m->next = elf_tdata (abfd)->segment_map;
6758 elf_tdata (abfd)->segment_map = m;
6762 return TRUE;
6765 /* We may add a PT_ARM_EXIDX program header. */
6767 static int
6768 elf32_arm_additional_program_headers (bfd *abfd)
6770 asection *sec;
6772 sec = bfd_get_section_by_name (abfd, ".ARM.exidx");
6773 if (sec != NULL && (sec->flags & SEC_LOAD) != 0)
6774 return 1;
6775 else
6776 return 0;
6779 /* We use this to override swap_symbol_in and swap_symbol_out. */
6780 const struct elf_size_info elf32_arm_size_info = {
6781 sizeof (Elf32_External_Ehdr),
6782 sizeof (Elf32_External_Phdr),
6783 sizeof (Elf32_External_Shdr),
6784 sizeof (Elf32_External_Rel),
6785 sizeof (Elf32_External_Rela),
6786 sizeof (Elf32_External_Sym),
6787 sizeof (Elf32_External_Dyn),
6788 sizeof (Elf_External_Note),
6791 32, 2,
6792 ELFCLASS32, EV_CURRENT,
6793 bfd_elf32_write_out_phdrs,
6794 bfd_elf32_write_shdrs_and_ehdr,
6795 bfd_elf32_write_relocs,
6796 elf32_arm_swap_symbol_in,
6797 elf32_arm_swap_symbol_out,
6798 bfd_elf32_slurp_reloc_table,
6799 bfd_elf32_slurp_symbol_table,
6800 bfd_elf32_swap_dyn_in,
6801 bfd_elf32_swap_dyn_out,
6802 bfd_elf32_swap_reloc_in,
6803 bfd_elf32_swap_reloc_out,
6804 bfd_elf32_swap_reloca_in,
6805 bfd_elf32_swap_reloca_out
6808 #define ELF_ARCH bfd_arch_arm
6809 #define ELF_MACHINE_CODE EM_ARM
6810 #ifdef __QNXTARGET__
6811 #define ELF_MAXPAGESIZE 0x1000
6812 #else
6813 #define ELF_MAXPAGESIZE 0x8000
6814 #endif
6815 #define ELF_MINPAGESIZE 0x1000
6817 #define bfd_elf32_mkobject elf32_arm_mkobject
6819 #define bfd_elf32_bfd_copy_private_bfd_data elf32_arm_copy_private_bfd_data
6820 #define bfd_elf32_bfd_merge_private_bfd_data elf32_arm_merge_private_bfd_data
6821 #define bfd_elf32_bfd_set_private_flags elf32_arm_set_private_flags
6822 #define bfd_elf32_bfd_print_private_bfd_data elf32_arm_print_private_bfd_data
6823 #define bfd_elf32_bfd_link_hash_table_create elf32_arm_link_hash_table_create
6824 #define bfd_elf32_bfd_reloc_type_lookup elf32_arm_reloc_type_lookup
6825 #define bfd_elf32_find_nearest_line elf32_arm_find_nearest_line
6826 #define bfd_elf32_find_inliner_info elf32_arm_find_inliner_info
6827 #define bfd_elf32_new_section_hook elf32_arm_new_section_hook
6828 #define bfd_elf32_bfd_is_target_special_symbol elf32_arm_is_target_special_symbol
6830 #define elf_backend_get_symbol_type elf32_arm_get_symbol_type
6831 #define elf_backend_gc_mark_hook elf32_arm_gc_mark_hook
6832 #define elf_backend_gc_sweep_hook elf32_arm_gc_sweep_hook
6833 #define elf_backend_check_relocs elf32_arm_check_relocs
6834 #define elf_backend_relocate_section elf32_arm_relocate_section
6835 #define elf_backend_write_section elf32_arm_write_section
6836 #define elf_backend_adjust_dynamic_symbol elf32_arm_adjust_dynamic_symbol
6837 #define elf_backend_create_dynamic_sections elf32_arm_create_dynamic_sections
6838 #define elf_backend_finish_dynamic_symbol elf32_arm_finish_dynamic_symbol
6839 #define elf_backend_finish_dynamic_sections elf32_arm_finish_dynamic_sections
6840 #define elf_backend_link_output_symbol_hook elf32_arm_output_symbol_hook
6841 #define elf_backend_size_dynamic_sections elf32_arm_size_dynamic_sections
6842 #define elf_backend_post_process_headers elf32_arm_post_process_headers
6843 #define elf_backend_reloc_type_class elf32_arm_reloc_type_class
6844 #define elf_backend_object_p elf32_arm_object_p
6845 #define elf_backend_section_flags elf32_arm_section_flags
6846 #define elf_backend_fake_sections elf32_arm_fake_sections
6847 #define elf_backend_section_from_shdr elf32_arm_section_from_shdr
6848 #define elf_backend_final_write_processing elf32_arm_final_write_processing
6849 #define elf_backend_copy_indirect_symbol elf32_arm_copy_indirect_symbol
6850 #define elf_backend_symbol_processing elf32_arm_symbol_processing
6851 #define elf_backend_size_info elf32_arm_size_info
6852 #define elf_backend_modify_segment_map elf32_arm_modify_segment_map
6853 #define elf_backend_additional_program_headers \
6854 elf32_arm_additional_program_headers
6856 #define elf_backend_can_refcount 1
6857 #define elf_backend_can_gc_sections 1
6858 #define elf_backend_plt_readonly 1
6859 #define elf_backend_want_got_plt 1
6860 #define elf_backend_want_plt_sym 0
6861 #define elf_backend_may_use_rel_p 1
6862 #define elf_backend_may_use_rela_p 0
6863 #define elf_backend_default_use_rela_p 0
6864 #define elf_backend_rela_normal 0
6866 #define elf_backend_got_header_size 12
6868 #include "elf32-target.h"
6870 /* VxWorks Targets */
6872 #undef TARGET_LITTLE_SYM
6873 #define TARGET_LITTLE_SYM bfd_elf32_littlearm_vxworks_vec
6874 #undef TARGET_LITTLE_NAME
6875 #define TARGET_LITTLE_NAME "elf32-littlearm-vxworks"
6876 #undef TARGET_BIG_SYM
6877 #define TARGET_BIG_SYM bfd_elf32_bigarm_vxworks_vec
6878 #undef TARGET_BIG_NAME
6879 #define TARGET_BIG_NAME "elf32-bigarm-vxworks"
6881 /* Like elf32_arm_link_hash_table_create -- but overrides
6882 appropriately for VxWorks. */
6883 static struct bfd_link_hash_table *
6884 elf32_arm_vxworks_link_hash_table_create (bfd *abfd)
6886 struct bfd_link_hash_table *ret;
6888 ret = elf32_arm_link_hash_table_create (abfd);
6889 if (ret)
6891 struct elf32_arm_link_hash_table *htab
6892 = (struct elf32_arm_link_hash_table *)ret;
6893 htab->use_rel = 0;
6895 return ret;
6898 #undef elf32_bed
6899 #define elf32_bed elf32_arm_vxworks_bed
6901 #undef bfd_elf32_bfd_link_hash_table_create
6902 #define bfd_elf32_bfd_link_hash_table_create \
6903 elf32_arm_vxworks_link_hash_table_create
6905 #undef elf_backend_may_use_rel_p
6906 #define elf_backend_may_use_rel_p 0
6907 #undef elf_backend_may_use_rela_p
6908 #define elf_backend_may_use_rela_p 1
6909 #undef elf_backend_default_use_rela_p
6910 #define elf_backend_default_use_rela_p 1
6911 #undef elf_backend_rela_normal
6912 #define elf_backend_rela_normal 1
6914 #include "elf32-target.h"
6917 /* Symbian OS Targets */
6919 #undef TARGET_LITTLE_SYM
6920 #define TARGET_LITTLE_SYM bfd_elf32_littlearm_symbian_vec
6921 #undef TARGET_LITTLE_NAME
6922 #define TARGET_LITTLE_NAME "elf32-littlearm-symbian"
6923 #undef TARGET_BIG_SYM
6924 #define TARGET_BIG_SYM bfd_elf32_bigarm_symbian_vec
6925 #undef TARGET_BIG_NAME
6926 #define TARGET_BIG_NAME "elf32-bigarm-symbian"
6928 /* Like elf32_arm_link_hash_table_create -- but overrides
6929 appropriately for Symbian OS. */
6930 static struct bfd_link_hash_table *
6931 elf32_arm_symbian_link_hash_table_create (bfd *abfd)
6933 struct bfd_link_hash_table *ret;
6935 ret = elf32_arm_link_hash_table_create (abfd);
6936 if (ret)
6938 struct elf32_arm_link_hash_table *htab
6939 = (struct elf32_arm_link_hash_table *)ret;
6940 /* There is no PLT header for Symbian OS. */
6941 htab->plt_header_size = 0;
6942 /* The PLT entries are each three instructions. */
6943 htab->plt_entry_size = 4 * NUM_ELEM (elf32_arm_symbian_plt_entry);
6944 htab->symbian_p = 1;
6945 /* Symbian uses armv5t or above, so use_blx is always true. */
6946 htab->use_blx = 1;
6947 htab->root.is_relocatable_executable = 1;
6949 return ret;
6952 static struct bfd_elf_special_section const
6953 symbian_special_sections_d[]=
6955 /* In a BPABI executable, the dynamic linking sections do not go in
6956 the loadable read-only segment. The post-linker may wish to
6957 refer to these sections, but they are not part of the final
6958 program image. */
6959 { ".dynamic", 8, 0, SHT_DYNAMIC, 0 },
6960 { ".dynstr", 7, 0, SHT_STRTAB, 0 },
6961 { ".dynsym", 7, 0, SHT_DYNSYM, 0 },
6962 { NULL, 0, 0, 0, 0 }
6965 static struct bfd_elf_special_section const
6966 symbian_special_sections_g[]=
6968 /* In a BPABI executable, the dynamic linking sections do not go in
6969 the loadable read-only segment. The post-linker may wish to
6970 refer to these sections, but they are not part of the final
6971 program image. */
6972 { ".got", 4, 0, SHT_PROGBITS, 0 },
6973 { NULL, 0, 0, 0, 0 }
6976 static struct bfd_elf_special_section const
6977 symbian_special_sections_h[]=
6979 /* In a BPABI executable, the dynamic linking sections do not go in
6980 the loadable read-only segment. The post-linker may wish to
6981 refer to these sections, but they are not part of the final
6982 program image. */
6983 { ".hash", 5, 0, SHT_HASH, 0 },
6984 { NULL, 0, 0, 0, 0 }
6987 static struct bfd_elf_special_section const
6988 symbian_special_sections_i[]=
6990 /* These sections do not need to be writable as the SymbianOS
6991 postlinker will arrange things so that no dynamic relocation is
6992 required. */
6993 { ".init_array", 11, 0, SHT_INIT_ARRAY, SHF_ALLOC },
6994 { NULL, 0, 0, 0, 0 }
6997 static struct bfd_elf_special_section const
6998 symbian_special_sections_f[]=
7000 /* These sections do not need to be writable as the SymbianOS
7001 postlinker will arrange things so that no dynamic relocation is
7002 required. */
7003 { ".fini_array", 11, 0, SHT_FINI_ARRAY, SHF_ALLOC },
7004 { NULL, 0, 0, 0, 0 }
7007 static struct bfd_elf_special_section const
7008 symbian_special_sections_p[]=
7010 /* These sections do not need to be writable as the SymbianOS
7011 postlinker will arrange things so that no dynamic relocation is
7012 required. */
7013 { ".preinit_array", 14, 0, SHT_PREINIT_ARRAY, SHF_ALLOC },
7014 { NULL, 0, 0, 0, 0 }
7017 static struct bfd_elf_special_section const *
7018 elf32_arm_symbian_special_sections[27]=
7020 NULL, /* 'a' */
7021 NULL, /* 'b' */
7022 NULL, /* 'c' */
7023 symbian_special_sections_d, /* 'd' */
7024 NULL, /* 'e' */
7025 symbian_special_sections_f, /* 'f' */
7026 symbian_special_sections_g, /* 'g' */
7027 symbian_special_sections_h, /* 'h' */
7028 symbian_special_sections_i, /* 'i' */
7029 NULL, /* 'j' */
7030 NULL, /* 'k' */
7031 NULL, /* 'l' */
7032 NULL, /* 'm' */
7033 NULL, /* 'n' */
7034 NULL, /* 'o' */
7035 symbian_special_sections_p, /* 'p' */
7036 NULL, /* 'q' */
7037 NULL, /* 'r' */
7038 NULL, /* 's' */
7039 NULL, /* 't' */
7040 NULL, /* 'u' */
7041 NULL, /* 'v' */
7042 NULL, /* 'w' */
7043 NULL, /* 'x' */
7044 NULL, /* 'y' */
7045 NULL, /* 'z' */
7046 NULL /* other */
7049 static void
7050 elf32_arm_symbian_begin_write_processing (bfd *abfd,
7051 struct bfd_link_info *link_info
7052 ATTRIBUTE_UNUSED)
7054 /* BPABI objects are never loaded directly by an OS kernel; they are
7055 processed by a postlinker first, into an OS-specific format. If
7056 the D_PAGED bit is set on the file, BFD will align segments on
7057 page boundaries, so that an OS can directly map the file. With
7058 BPABI objects, that just results in wasted space. In addition,
7059 because we clear the D_PAGED bit, map_sections_to_segments will
7060 recognize that the program headers should not be mapped into any
7061 loadable segment. */
7062 abfd->flags &= ~D_PAGED;
7065 static bfd_boolean
7066 elf32_arm_symbian_modify_segment_map (bfd *abfd,
7067 struct bfd_link_info *info)
7069 struct elf_segment_map *m;
7070 asection *dynsec;
7072 /* BPABI shared libraries and executables should have a PT_DYNAMIC
7073 segment. However, because the .dynamic section is not marked
7074 with SEC_LOAD, the generic ELF code will not create such a
7075 segment. */
7076 dynsec = bfd_get_section_by_name (abfd, ".dynamic");
7077 if (dynsec)
7079 m = _bfd_elf_make_dynamic_segment (abfd, dynsec);
7080 m->next = elf_tdata (abfd)->segment_map;
7081 elf_tdata (abfd)->segment_map = m;
7084 /* Also call the generic arm routine. */
7085 return elf32_arm_modify_segment_map (abfd, info);
7088 #undef elf32_bed
7089 #define elf32_bed elf32_arm_symbian_bed
7091 /* The dynamic sections are not allocated on SymbianOS; the postlinker
7092 will process them and then discard them. */
7093 #undef ELF_DYNAMIC_SEC_FLAGS
7094 #define ELF_DYNAMIC_SEC_FLAGS \
7095 (SEC_HAS_CONTENTS | SEC_IN_MEMORY | SEC_LINKER_CREATED)
7097 #undef bfd_elf32_bfd_link_hash_table_create
7098 #define bfd_elf32_bfd_link_hash_table_create \
7099 elf32_arm_symbian_link_hash_table_create
7101 #undef elf_backend_special_sections
7102 #define elf_backend_special_sections elf32_arm_symbian_special_sections
7104 #undef elf_backend_begin_write_processing
7105 #define elf_backend_begin_write_processing \
7106 elf32_arm_symbian_begin_write_processing
7108 #undef elf_backend_modify_segment_map
7109 #define elf_backend_modify_segment_map elf32_arm_symbian_modify_segment_map
7111 /* There is no .got section for BPABI objects, and hence no header. */
7112 #undef elf_backend_got_header_size
7113 #define elf_backend_got_header_size 0
7115 /* Similarly, there is no .got.plt section. */
7116 #undef elf_backend_want_got_plt
7117 #define elf_backend_want_got_plt 0
7119 #undef elf_backend_may_use_rel_p
7120 #define elf_backend_may_use_rel_p 1
7121 #undef elf_backend_may_use_rela_p
7122 #define elf_backend_may_use_rela_p 0
7123 #undef elf_backend_default_use_rela_p
7124 #define elf_backend_default_use_rela_p 0
7125 #undef elf_backend_rela_normal
7126 #define elf_backend_rela_normal 0
7128 #include "elf32-target.h"