* elf.c (rewrite_elf_program_header): Don't wrap p_paddr to
[deliverable/binutils-gdb.git] / bfd / elf32-arm.c
1 /* 32-bit ELF support for ARM
2 Copyright 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007,
3 2008 Free Software Foundation, Inc.
4
5 This file is part of BFD, the Binary File Descriptor library.
6
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 3 of the License, or
10 (at your option) any later version.
11
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.
16
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,
20 MA 02110-1301, USA. */
21
22 #include "sysdep.h"
23 #include "bfd.h"
24 #include "libiberty.h"
25 #include "libbfd.h"
26 #include "elf-bfd.h"
27 #include "elf-vxworks.h"
28 #include "elf/arm.h"
29
30 /* Return the relocation section associated with NAME. HTAB is the
31 bfd's elf32_arm_link_hash_entry. */
32 #define RELOC_SECTION(HTAB, NAME) \
33 ((HTAB)->use_rel ? ".rel" NAME : ".rela" NAME)
34
35 /* Return size of a relocation entry. HTAB is the bfd's
36 elf32_arm_link_hash_entry. */
37 #define RELOC_SIZE(HTAB) \
38 ((HTAB)->use_rel \
39 ? sizeof (Elf32_External_Rel) \
40 : sizeof (Elf32_External_Rela))
41
42 /* Return function to swap relocations in. HTAB is the bfd's
43 elf32_arm_link_hash_entry. */
44 #define SWAP_RELOC_IN(HTAB) \
45 ((HTAB)->use_rel \
46 ? bfd_elf32_swap_reloc_in \
47 : bfd_elf32_swap_reloca_in)
48
49 /* Return function to swap relocations out. HTAB is the bfd's
50 elf32_arm_link_hash_entry. */
51 #define SWAP_RELOC_OUT(HTAB) \
52 ((HTAB)->use_rel \
53 ? bfd_elf32_swap_reloc_out \
54 : bfd_elf32_swap_reloca_out)
55
56 #define elf_info_to_howto 0
57 #define elf_info_to_howto_rel elf32_arm_info_to_howto
58
59 #define ARM_ELF_ABI_VERSION 0
60 #define ARM_ELF_OS_ABI_VERSION ELFOSABI_ARM
61
62 static struct elf_backend_data elf32_arm_vxworks_bed;
63
64 /* Note: code such as elf32_arm_reloc_type_lookup expect to use e.g.
65 R_ARM_PC24 as an index into this, and find the R_ARM_PC24 HOWTO
66 in that slot. */
67
68 static reloc_howto_type elf32_arm_howto_table_1[] =
69 {
70 /* No relocation */
71 HOWTO (R_ARM_NONE, /* type */
72 0, /* rightshift */
73 0, /* size (0 = byte, 1 = short, 2 = long) */
74 0, /* bitsize */
75 FALSE, /* pc_relative */
76 0, /* bitpos */
77 complain_overflow_dont,/* complain_on_overflow */
78 bfd_elf_generic_reloc, /* special_function */
79 "R_ARM_NONE", /* name */
80 FALSE, /* partial_inplace */
81 0, /* src_mask */
82 0, /* dst_mask */
83 FALSE), /* pcrel_offset */
84
85 HOWTO (R_ARM_PC24, /* type */
86 2, /* rightshift */
87 2, /* size (0 = byte, 1 = short, 2 = long) */
88 24, /* bitsize */
89 TRUE, /* pc_relative */
90 0, /* bitpos */
91 complain_overflow_signed,/* complain_on_overflow */
92 bfd_elf_generic_reloc, /* special_function */
93 "R_ARM_PC24", /* name */
94 FALSE, /* partial_inplace */
95 0x00ffffff, /* src_mask */
96 0x00ffffff, /* dst_mask */
97 TRUE), /* pcrel_offset */
98
99 /* 32 bit absolute */
100 HOWTO (R_ARM_ABS32, /* type */
101 0, /* rightshift */
102 2, /* size (0 = byte, 1 = short, 2 = long) */
103 32, /* bitsize */
104 FALSE, /* pc_relative */
105 0, /* bitpos */
106 complain_overflow_bitfield,/* complain_on_overflow */
107 bfd_elf_generic_reloc, /* special_function */
108 "R_ARM_ABS32", /* name */
109 FALSE, /* partial_inplace */
110 0xffffffff, /* src_mask */
111 0xffffffff, /* dst_mask */
112 FALSE), /* pcrel_offset */
113
114 /* standard 32bit pc-relative reloc */
115 HOWTO (R_ARM_REL32, /* type */
116 0, /* rightshift */
117 2, /* size (0 = byte, 1 = short, 2 = long) */
118 32, /* bitsize */
119 TRUE, /* pc_relative */
120 0, /* bitpos */
121 complain_overflow_bitfield,/* complain_on_overflow */
122 bfd_elf_generic_reloc, /* special_function */
123 "R_ARM_REL32", /* name */
124 FALSE, /* partial_inplace */
125 0xffffffff, /* src_mask */
126 0xffffffff, /* dst_mask */
127 TRUE), /* pcrel_offset */
128
129 /* 8 bit absolute - R_ARM_LDR_PC_G0 in AAELF */
130 HOWTO (R_ARM_LDR_PC_G0, /* type */
131 0, /* rightshift */
132 0, /* size (0 = byte, 1 = short, 2 = long) */
133 32, /* bitsize */
134 TRUE, /* pc_relative */
135 0, /* bitpos */
136 complain_overflow_dont,/* complain_on_overflow */
137 bfd_elf_generic_reloc, /* special_function */
138 "R_ARM_LDR_PC_G0", /* name */
139 FALSE, /* partial_inplace */
140 0xffffffff, /* src_mask */
141 0xffffffff, /* dst_mask */
142 TRUE), /* pcrel_offset */
143
144 /* 16 bit absolute */
145 HOWTO (R_ARM_ABS16, /* type */
146 0, /* rightshift */
147 1, /* size (0 = byte, 1 = short, 2 = long) */
148 16, /* bitsize */
149 FALSE, /* pc_relative */
150 0, /* bitpos */
151 complain_overflow_bitfield,/* complain_on_overflow */
152 bfd_elf_generic_reloc, /* special_function */
153 "R_ARM_ABS16", /* name */
154 FALSE, /* partial_inplace */
155 0x0000ffff, /* src_mask */
156 0x0000ffff, /* dst_mask */
157 FALSE), /* pcrel_offset */
158
159 /* 12 bit absolute */
160 HOWTO (R_ARM_ABS12, /* type */
161 0, /* rightshift */
162 2, /* size (0 = byte, 1 = short, 2 = long) */
163 12, /* bitsize */
164 FALSE, /* pc_relative */
165 0, /* bitpos */
166 complain_overflow_bitfield,/* complain_on_overflow */
167 bfd_elf_generic_reloc, /* special_function */
168 "R_ARM_ABS12", /* name */
169 FALSE, /* partial_inplace */
170 0x00000fff, /* src_mask */
171 0x00000fff, /* dst_mask */
172 FALSE), /* pcrel_offset */
173
174 HOWTO (R_ARM_THM_ABS5, /* type */
175 6, /* rightshift */
176 1, /* size (0 = byte, 1 = short, 2 = long) */
177 5, /* bitsize */
178 FALSE, /* pc_relative */
179 0, /* bitpos */
180 complain_overflow_bitfield,/* complain_on_overflow */
181 bfd_elf_generic_reloc, /* special_function */
182 "R_ARM_THM_ABS5", /* name */
183 FALSE, /* partial_inplace */
184 0x000007e0, /* src_mask */
185 0x000007e0, /* dst_mask */
186 FALSE), /* pcrel_offset */
187
188 /* 8 bit absolute */
189 HOWTO (R_ARM_ABS8, /* type */
190 0, /* rightshift */
191 0, /* size (0 = byte, 1 = short, 2 = long) */
192 8, /* bitsize */
193 FALSE, /* pc_relative */
194 0, /* bitpos */
195 complain_overflow_bitfield,/* complain_on_overflow */
196 bfd_elf_generic_reloc, /* special_function */
197 "R_ARM_ABS8", /* name */
198 FALSE, /* partial_inplace */
199 0x000000ff, /* src_mask */
200 0x000000ff, /* dst_mask */
201 FALSE), /* pcrel_offset */
202
203 HOWTO (R_ARM_SBREL32, /* type */
204 0, /* rightshift */
205 2, /* size (0 = byte, 1 = short, 2 = long) */
206 32, /* bitsize */
207 FALSE, /* pc_relative */
208 0, /* bitpos */
209 complain_overflow_dont,/* complain_on_overflow */
210 bfd_elf_generic_reloc, /* special_function */
211 "R_ARM_SBREL32", /* name */
212 FALSE, /* partial_inplace */
213 0xffffffff, /* src_mask */
214 0xffffffff, /* dst_mask */
215 FALSE), /* pcrel_offset */
216
217 HOWTO (R_ARM_THM_CALL, /* type */
218 1, /* rightshift */
219 2, /* size (0 = byte, 1 = short, 2 = long) */
220 25, /* bitsize */
221 TRUE, /* pc_relative */
222 0, /* bitpos */
223 complain_overflow_signed,/* complain_on_overflow */
224 bfd_elf_generic_reloc, /* special_function */
225 "R_ARM_THM_CALL", /* name */
226 FALSE, /* partial_inplace */
227 0x07ff07ff, /* src_mask */
228 0x07ff07ff, /* dst_mask */
229 TRUE), /* pcrel_offset */
230
231 HOWTO (R_ARM_THM_PC8, /* type */
232 1, /* rightshift */
233 1, /* size (0 = byte, 1 = short, 2 = long) */
234 8, /* bitsize */
235 TRUE, /* pc_relative */
236 0, /* bitpos */
237 complain_overflow_signed,/* complain_on_overflow */
238 bfd_elf_generic_reloc, /* special_function */
239 "R_ARM_THM_PC8", /* name */
240 FALSE, /* partial_inplace */
241 0x000000ff, /* src_mask */
242 0x000000ff, /* dst_mask */
243 TRUE), /* pcrel_offset */
244
245 HOWTO (R_ARM_BREL_ADJ, /* type */
246 1, /* rightshift */
247 1, /* size (0 = byte, 1 = short, 2 = long) */
248 32, /* bitsize */
249 FALSE, /* pc_relative */
250 0, /* bitpos */
251 complain_overflow_signed,/* complain_on_overflow */
252 bfd_elf_generic_reloc, /* special_function */
253 "R_ARM_BREL_ADJ", /* name */
254 FALSE, /* partial_inplace */
255 0xffffffff, /* src_mask */
256 0xffffffff, /* dst_mask */
257 FALSE), /* pcrel_offset */
258
259 HOWTO (R_ARM_SWI24, /* type */
260 0, /* rightshift */
261 0, /* size (0 = byte, 1 = short, 2 = long) */
262 0, /* bitsize */
263 FALSE, /* pc_relative */
264 0, /* bitpos */
265 complain_overflow_signed,/* complain_on_overflow */
266 bfd_elf_generic_reloc, /* special_function */
267 "R_ARM_SWI24", /* name */
268 FALSE, /* partial_inplace */
269 0x00000000, /* src_mask */
270 0x00000000, /* dst_mask */
271 FALSE), /* pcrel_offset */
272
273 HOWTO (R_ARM_THM_SWI8, /* type */
274 0, /* rightshift */
275 0, /* size (0 = byte, 1 = short, 2 = long) */
276 0, /* bitsize */
277 FALSE, /* pc_relative */
278 0, /* bitpos */
279 complain_overflow_signed,/* complain_on_overflow */
280 bfd_elf_generic_reloc, /* special_function */
281 "R_ARM_SWI8", /* name */
282 FALSE, /* partial_inplace */
283 0x00000000, /* src_mask */
284 0x00000000, /* dst_mask */
285 FALSE), /* pcrel_offset */
286
287 /* BLX instruction for the ARM. */
288 HOWTO (R_ARM_XPC25, /* type */
289 2, /* rightshift */
290 2, /* size (0 = byte, 1 = short, 2 = long) */
291 25, /* bitsize */
292 TRUE, /* pc_relative */
293 0, /* bitpos */
294 complain_overflow_signed,/* complain_on_overflow */
295 bfd_elf_generic_reloc, /* special_function */
296 "R_ARM_XPC25", /* name */
297 FALSE, /* partial_inplace */
298 0x00ffffff, /* src_mask */
299 0x00ffffff, /* dst_mask */
300 TRUE), /* pcrel_offset */
301
302 /* BLX instruction for the Thumb. */
303 HOWTO (R_ARM_THM_XPC22, /* type */
304 2, /* rightshift */
305 2, /* size (0 = byte, 1 = short, 2 = long) */
306 22, /* bitsize */
307 TRUE, /* pc_relative */
308 0, /* bitpos */
309 complain_overflow_signed,/* complain_on_overflow */
310 bfd_elf_generic_reloc, /* special_function */
311 "R_ARM_THM_XPC22", /* name */
312 FALSE, /* partial_inplace */
313 0x07ff07ff, /* src_mask */
314 0x07ff07ff, /* dst_mask */
315 TRUE), /* pcrel_offset */
316
317 /* Dynamic TLS relocations. */
318
319 HOWTO (R_ARM_TLS_DTPMOD32, /* type */
320 0, /* rightshift */
321 2, /* size (0 = byte, 1 = short, 2 = long) */
322 32, /* bitsize */
323 FALSE, /* pc_relative */
324 0, /* bitpos */
325 complain_overflow_bitfield,/* complain_on_overflow */
326 bfd_elf_generic_reloc, /* special_function */
327 "R_ARM_TLS_DTPMOD32", /* name */
328 TRUE, /* partial_inplace */
329 0xffffffff, /* src_mask */
330 0xffffffff, /* dst_mask */
331 FALSE), /* pcrel_offset */
332
333 HOWTO (R_ARM_TLS_DTPOFF32, /* type */
334 0, /* rightshift */
335 2, /* size (0 = byte, 1 = short, 2 = long) */
336 32, /* bitsize */
337 FALSE, /* pc_relative */
338 0, /* bitpos */
339 complain_overflow_bitfield,/* complain_on_overflow */
340 bfd_elf_generic_reloc, /* special_function */
341 "R_ARM_TLS_DTPOFF32", /* name */
342 TRUE, /* partial_inplace */
343 0xffffffff, /* src_mask */
344 0xffffffff, /* dst_mask */
345 FALSE), /* pcrel_offset */
346
347 HOWTO (R_ARM_TLS_TPOFF32, /* type */
348 0, /* rightshift */
349 2, /* size (0 = byte, 1 = short, 2 = long) */
350 32, /* bitsize */
351 FALSE, /* pc_relative */
352 0, /* bitpos */
353 complain_overflow_bitfield,/* complain_on_overflow */
354 bfd_elf_generic_reloc, /* special_function */
355 "R_ARM_TLS_TPOFF32", /* name */
356 TRUE, /* partial_inplace */
357 0xffffffff, /* src_mask */
358 0xffffffff, /* dst_mask */
359 FALSE), /* pcrel_offset */
360
361 /* Relocs used in ARM Linux */
362
363 HOWTO (R_ARM_COPY, /* type */
364 0, /* rightshift */
365 2, /* size (0 = byte, 1 = short, 2 = long) */
366 32, /* bitsize */
367 FALSE, /* pc_relative */
368 0, /* bitpos */
369 complain_overflow_bitfield,/* complain_on_overflow */
370 bfd_elf_generic_reloc, /* special_function */
371 "R_ARM_COPY", /* name */
372 TRUE, /* partial_inplace */
373 0xffffffff, /* src_mask */
374 0xffffffff, /* dst_mask */
375 FALSE), /* pcrel_offset */
376
377 HOWTO (R_ARM_GLOB_DAT, /* type */
378 0, /* rightshift */
379 2, /* size (0 = byte, 1 = short, 2 = long) */
380 32, /* bitsize */
381 FALSE, /* pc_relative */
382 0, /* bitpos */
383 complain_overflow_bitfield,/* complain_on_overflow */
384 bfd_elf_generic_reloc, /* special_function */
385 "R_ARM_GLOB_DAT", /* name */
386 TRUE, /* partial_inplace */
387 0xffffffff, /* src_mask */
388 0xffffffff, /* dst_mask */
389 FALSE), /* pcrel_offset */
390
391 HOWTO (R_ARM_JUMP_SLOT, /* type */
392 0, /* rightshift */
393 2, /* size (0 = byte, 1 = short, 2 = long) */
394 32, /* bitsize */
395 FALSE, /* pc_relative */
396 0, /* bitpos */
397 complain_overflow_bitfield,/* complain_on_overflow */
398 bfd_elf_generic_reloc, /* special_function */
399 "R_ARM_JUMP_SLOT", /* name */
400 TRUE, /* partial_inplace */
401 0xffffffff, /* src_mask */
402 0xffffffff, /* dst_mask */
403 FALSE), /* pcrel_offset */
404
405 HOWTO (R_ARM_RELATIVE, /* type */
406 0, /* rightshift */
407 2, /* size (0 = byte, 1 = short, 2 = long) */
408 32, /* bitsize */
409 FALSE, /* pc_relative */
410 0, /* bitpos */
411 complain_overflow_bitfield,/* complain_on_overflow */
412 bfd_elf_generic_reloc, /* special_function */
413 "R_ARM_RELATIVE", /* name */
414 TRUE, /* partial_inplace */
415 0xffffffff, /* src_mask */
416 0xffffffff, /* dst_mask */
417 FALSE), /* pcrel_offset */
418
419 HOWTO (R_ARM_GOTOFF32, /* type */
420 0, /* rightshift */
421 2, /* size (0 = byte, 1 = short, 2 = long) */
422 32, /* bitsize */
423 FALSE, /* pc_relative */
424 0, /* bitpos */
425 complain_overflow_bitfield,/* complain_on_overflow */
426 bfd_elf_generic_reloc, /* special_function */
427 "R_ARM_GOTOFF32", /* name */
428 TRUE, /* partial_inplace */
429 0xffffffff, /* src_mask */
430 0xffffffff, /* dst_mask */
431 FALSE), /* pcrel_offset */
432
433 HOWTO (R_ARM_GOTPC, /* type */
434 0, /* rightshift */
435 2, /* size (0 = byte, 1 = short, 2 = long) */
436 32, /* bitsize */
437 TRUE, /* pc_relative */
438 0, /* bitpos */
439 complain_overflow_bitfield,/* complain_on_overflow */
440 bfd_elf_generic_reloc, /* special_function */
441 "R_ARM_GOTPC", /* name */
442 TRUE, /* partial_inplace */
443 0xffffffff, /* src_mask */
444 0xffffffff, /* dst_mask */
445 TRUE), /* pcrel_offset */
446
447 HOWTO (R_ARM_GOT32, /* type */
448 0, /* rightshift */
449 2, /* size (0 = byte, 1 = short, 2 = long) */
450 32, /* bitsize */
451 FALSE, /* pc_relative */
452 0, /* bitpos */
453 complain_overflow_bitfield,/* complain_on_overflow */
454 bfd_elf_generic_reloc, /* special_function */
455 "R_ARM_GOT32", /* name */
456 TRUE, /* partial_inplace */
457 0xffffffff, /* src_mask */
458 0xffffffff, /* dst_mask */
459 FALSE), /* pcrel_offset */
460
461 HOWTO (R_ARM_PLT32, /* type */
462 2, /* rightshift */
463 2, /* size (0 = byte, 1 = short, 2 = long) */
464 24, /* bitsize */
465 TRUE, /* pc_relative */
466 0, /* bitpos */
467 complain_overflow_bitfield,/* complain_on_overflow */
468 bfd_elf_generic_reloc, /* special_function */
469 "R_ARM_PLT32", /* name */
470 FALSE, /* partial_inplace */
471 0x00ffffff, /* src_mask */
472 0x00ffffff, /* dst_mask */
473 TRUE), /* pcrel_offset */
474
475 HOWTO (R_ARM_CALL, /* type */
476 2, /* rightshift */
477 2, /* size (0 = byte, 1 = short, 2 = long) */
478 24, /* bitsize */
479 TRUE, /* pc_relative */
480 0, /* bitpos */
481 complain_overflow_signed,/* complain_on_overflow */
482 bfd_elf_generic_reloc, /* special_function */
483 "R_ARM_CALL", /* name */
484 FALSE, /* partial_inplace */
485 0x00ffffff, /* src_mask */
486 0x00ffffff, /* dst_mask */
487 TRUE), /* pcrel_offset */
488
489 HOWTO (R_ARM_JUMP24, /* type */
490 2, /* rightshift */
491 2, /* size (0 = byte, 1 = short, 2 = long) */
492 24, /* bitsize */
493 TRUE, /* pc_relative */
494 0, /* bitpos */
495 complain_overflow_signed,/* complain_on_overflow */
496 bfd_elf_generic_reloc, /* special_function */
497 "R_ARM_JUMP24", /* name */
498 FALSE, /* partial_inplace */
499 0x00ffffff, /* src_mask */
500 0x00ffffff, /* dst_mask */
501 TRUE), /* pcrel_offset */
502
503 HOWTO (R_ARM_THM_JUMP24, /* type */
504 1, /* rightshift */
505 2, /* size (0 = byte, 1 = short, 2 = long) */
506 24, /* bitsize */
507 TRUE, /* pc_relative */
508 0, /* bitpos */
509 complain_overflow_signed,/* complain_on_overflow */
510 bfd_elf_generic_reloc, /* special_function */
511 "R_ARM_THM_JUMP24", /* name */
512 FALSE, /* partial_inplace */
513 0x07ff2fff, /* src_mask */
514 0x07ff2fff, /* dst_mask */
515 TRUE), /* pcrel_offset */
516
517 HOWTO (R_ARM_BASE_ABS, /* type */
518 0, /* rightshift */
519 2, /* size (0 = byte, 1 = short, 2 = long) */
520 32, /* bitsize */
521 FALSE, /* pc_relative */
522 0, /* bitpos */
523 complain_overflow_dont,/* complain_on_overflow */
524 bfd_elf_generic_reloc, /* special_function */
525 "R_ARM_BASE_ABS", /* name */
526 FALSE, /* partial_inplace */
527 0xffffffff, /* src_mask */
528 0xffffffff, /* dst_mask */
529 FALSE), /* pcrel_offset */
530
531 HOWTO (R_ARM_ALU_PCREL7_0, /* type */
532 0, /* rightshift */
533 2, /* size (0 = byte, 1 = short, 2 = long) */
534 12, /* bitsize */
535 TRUE, /* pc_relative */
536 0, /* bitpos */
537 complain_overflow_dont,/* complain_on_overflow */
538 bfd_elf_generic_reloc, /* special_function */
539 "R_ARM_ALU_PCREL_7_0", /* name */
540 FALSE, /* partial_inplace */
541 0x00000fff, /* src_mask */
542 0x00000fff, /* dst_mask */
543 TRUE), /* pcrel_offset */
544
545 HOWTO (R_ARM_ALU_PCREL15_8, /* type */
546 0, /* rightshift */
547 2, /* size (0 = byte, 1 = short, 2 = long) */
548 12, /* bitsize */
549 TRUE, /* pc_relative */
550 8, /* bitpos */
551 complain_overflow_dont,/* complain_on_overflow */
552 bfd_elf_generic_reloc, /* special_function */
553 "R_ARM_ALU_PCREL_15_8",/* name */
554 FALSE, /* partial_inplace */
555 0x00000fff, /* src_mask */
556 0x00000fff, /* dst_mask */
557 TRUE), /* pcrel_offset */
558
559 HOWTO (R_ARM_ALU_PCREL23_15, /* type */
560 0, /* rightshift */
561 2, /* size (0 = byte, 1 = short, 2 = long) */
562 12, /* bitsize */
563 TRUE, /* pc_relative */
564 16, /* bitpos */
565 complain_overflow_dont,/* complain_on_overflow */
566 bfd_elf_generic_reloc, /* special_function */
567 "R_ARM_ALU_PCREL_23_15",/* name */
568 FALSE, /* partial_inplace */
569 0x00000fff, /* src_mask */
570 0x00000fff, /* dst_mask */
571 TRUE), /* pcrel_offset */
572
573 HOWTO (R_ARM_LDR_SBREL_11_0, /* type */
574 0, /* rightshift */
575 2, /* size (0 = byte, 1 = short, 2 = long) */
576 12, /* bitsize */
577 FALSE, /* pc_relative */
578 0, /* bitpos */
579 complain_overflow_dont,/* complain_on_overflow */
580 bfd_elf_generic_reloc, /* special_function */
581 "R_ARM_LDR_SBREL_11_0",/* name */
582 FALSE, /* partial_inplace */
583 0x00000fff, /* src_mask */
584 0x00000fff, /* dst_mask */
585 FALSE), /* pcrel_offset */
586
587 HOWTO (R_ARM_ALU_SBREL_19_12, /* type */
588 0, /* rightshift */
589 2, /* size (0 = byte, 1 = short, 2 = long) */
590 8, /* bitsize */
591 FALSE, /* pc_relative */
592 12, /* bitpos */
593 complain_overflow_dont,/* complain_on_overflow */
594 bfd_elf_generic_reloc, /* special_function */
595 "R_ARM_ALU_SBREL_19_12",/* name */
596 FALSE, /* partial_inplace */
597 0x000ff000, /* src_mask */
598 0x000ff000, /* dst_mask */
599 FALSE), /* pcrel_offset */
600
601 HOWTO (R_ARM_ALU_SBREL_27_20, /* type */
602 0, /* rightshift */
603 2, /* size (0 = byte, 1 = short, 2 = long) */
604 8, /* bitsize */
605 FALSE, /* pc_relative */
606 20, /* bitpos */
607 complain_overflow_dont,/* complain_on_overflow */
608 bfd_elf_generic_reloc, /* special_function */
609 "R_ARM_ALU_SBREL_27_20",/* name */
610 FALSE, /* partial_inplace */
611 0x0ff00000, /* src_mask */
612 0x0ff00000, /* dst_mask */
613 FALSE), /* pcrel_offset */
614
615 HOWTO (R_ARM_TARGET1, /* type */
616 0, /* rightshift */
617 2, /* size (0 = byte, 1 = short, 2 = long) */
618 32, /* bitsize */
619 FALSE, /* pc_relative */
620 0, /* bitpos */
621 complain_overflow_dont,/* complain_on_overflow */
622 bfd_elf_generic_reloc, /* special_function */
623 "R_ARM_TARGET1", /* name */
624 FALSE, /* partial_inplace */
625 0xffffffff, /* src_mask */
626 0xffffffff, /* dst_mask */
627 FALSE), /* pcrel_offset */
628
629 HOWTO (R_ARM_ROSEGREL32, /* type */
630 0, /* rightshift */
631 2, /* size (0 = byte, 1 = short, 2 = long) */
632 32, /* bitsize */
633 FALSE, /* pc_relative */
634 0, /* bitpos */
635 complain_overflow_dont,/* complain_on_overflow */
636 bfd_elf_generic_reloc, /* special_function */
637 "R_ARM_ROSEGREL32", /* name */
638 FALSE, /* partial_inplace */
639 0xffffffff, /* src_mask */
640 0xffffffff, /* dst_mask */
641 FALSE), /* pcrel_offset */
642
643 HOWTO (R_ARM_V4BX, /* type */
644 0, /* rightshift */
645 2, /* size (0 = byte, 1 = short, 2 = long) */
646 32, /* bitsize */
647 FALSE, /* pc_relative */
648 0, /* bitpos */
649 complain_overflow_dont,/* complain_on_overflow */
650 bfd_elf_generic_reloc, /* special_function */
651 "R_ARM_V4BX", /* name */
652 FALSE, /* partial_inplace */
653 0xffffffff, /* src_mask */
654 0xffffffff, /* dst_mask */
655 FALSE), /* pcrel_offset */
656
657 HOWTO (R_ARM_TARGET2, /* type */
658 0, /* rightshift */
659 2, /* size (0 = byte, 1 = short, 2 = long) */
660 32, /* bitsize */
661 FALSE, /* pc_relative */
662 0, /* bitpos */
663 complain_overflow_signed,/* complain_on_overflow */
664 bfd_elf_generic_reloc, /* special_function */
665 "R_ARM_TARGET2", /* name */
666 FALSE, /* partial_inplace */
667 0xffffffff, /* src_mask */
668 0xffffffff, /* dst_mask */
669 TRUE), /* pcrel_offset */
670
671 HOWTO (R_ARM_PREL31, /* type */
672 0, /* rightshift */
673 2, /* size (0 = byte, 1 = short, 2 = long) */
674 31, /* bitsize */
675 TRUE, /* pc_relative */
676 0, /* bitpos */
677 complain_overflow_signed,/* complain_on_overflow */
678 bfd_elf_generic_reloc, /* special_function */
679 "R_ARM_PREL31", /* name */
680 FALSE, /* partial_inplace */
681 0x7fffffff, /* src_mask */
682 0x7fffffff, /* dst_mask */
683 TRUE), /* pcrel_offset */
684
685 HOWTO (R_ARM_MOVW_ABS_NC, /* type */
686 0, /* rightshift */
687 2, /* size (0 = byte, 1 = short, 2 = long) */
688 16, /* bitsize */
689 FALSE, /* pc_relative */
690 0, /* bitpos */
691 complain_overflow_dont,/* complain_on_overflow */
692 bfd_elf_generic_reloc, /* special_function */
693 "R_ARM_MOVW_ABS_NC", /* name */
694 FALSE, /* partial_inplace */
695 0x000f0fff, /* src_mask */
696 0x000f0fff, /* dst_mask */
697 FALSE), /* pcrel_offset */
698
699 HOWTO (R_ARM_MOVT_ABS, /* type */
700 0, /* rightshift */
701 2, /* size (0 = byte, 1 = short, 2 = long) */
702 16, /* bitsize */
703 FALSE, /* pc_relative */
704 0, /* bitpos */
705 complain_overflow_bitfield,/* complain_on_overflow */
706 bfd_elf_generic_reloc, /* special_function */
707 "R_ARM_MOVT_ABS", /* name */
708 FALSE, /* partial_inplace */
709 0x000f0fff, /* src_mask */
710 0x000f0fff, /* dst_mask */
711 FALSE), /* pcrel_offset */
712
713 HOWTO (R_ARM_MOVW_PREL_NC, /* type */
714 0, /* rightshift */
715 2, /* size (0 = byte, 1 = short, 2 = long) */
716 16, /* bitsize */
717 TRUE, /* pc_relative */
718 0, /* bitpos */
719 complain_overflow_dont,/* complain_on_overflow */
720 bfd_elf_generic_reloc, /* special_function */
721 "R_ARM_MOVW_PREL_NC", /* name */
722 FALSE, /* partial_inplace */
723 0x000f0fff, /* src_mask */
724 0x000f0fff, /* dst_mask */
725 TRUE), /* pcrel_offset */
726
727 HOWTO (R_ARM_MOVT_PREL, /* type */
728 0, /* rightshift */
729 2, /* size (0 = byte, 1 = short, 2 = long) */
730 16, /* bitsize */
731 TRUE, /* pc_relative */
732 0, /* bitpos */
733 complain_overflow_bitfield,/* complain_on_overflow */
734 bfd_elf_generic_reloc, /* special_function */
735 "R_ARM_MOVT_PREL", /* name */
736 FALSE, /* partial_inplace */
737 0x000f0fff, /* src_mask */
738 0x000f0fff, /* dst_mask */
739 TRUE), /* pcrel_offset */
740
741 HOWTO (R_ARM_THM_MOVW_ABS_NC, /* type */
742 0, /* rightshift */
743 2, /* size (0 = byte, 1 = short, 2 = long) */
744 16, /* bitsize */
745 FALSE, /* pc_relative */
746 0, /* bitpos */
747 complain_overflow_dont,/* complain_on_overflow */
748 bfd_elf_generic_reloc, /* special_function */
749 "R_ARM_THM_MOVW_ABS_NC",/* name */
750 FALSE, /* partial_inplace */
751 0x040f70ff, /* src_mask */
752 0x040f70ff, /* dst_mask */
753 FALSE), /* pcrel_offset */
754
755 HOWTO (R_ARM_THM_MOVT_ABS, /* type */
756 0, /* rightshift */
757 2, /* size (0 = byte, 1 = short, 2 = long) */
758 16, /* bitsize */
759 FALSE, /* pc_relative */
760 0, /* bitpos */
761 complain_overflow_bitfield,/* complain_on_overflow */
762 bfd_elf_generic_reloc, /* special_function */
763 "R_ARM_THM_MOVT_ABS", /* name */
764 FALSE, /* partial_inplace */
765 0x040f70ff, /* src_mask */
766 0x040f70ff, /* dst_mask */
767 FALSE), /* pcrel_offset */
768
769 HOWTO (R_ARM_THM_MOVW_PREL_NC,/* type */
770 0, /* rightshift */
771 2, /* size (0 = byte, 1 = short, 2 = long) */
772 16, /* bitsize */
773 TRUE, /* pc_relative */
774 0, /* bitpos */
775 complain_overflow_dont,/* complain_on_overflow */
776 bfd_elf_generic_reloc, /* special_function */
777 "R_ARM_THM_MOVW_PREL_NC",/* name */
778 FALSE, /* partial_inplace */
779 0x040f70ff, /* src_mask */
780 0x040f70ff, /* dst_mask */
781 TRUE), /* pcrel_offset */
782
783 HOWTO (R_ARM_THM_MOVT_PREL, /* type */
784 0, /* rightshift */
785 2, /* size (0 = byte, 1 = short, 2 = long) */
786 16, /* bitsize */
787 TRUE, /* pc_relative */
788 0, /* bitpos */
789 complain_overflow_bitfield,/* complain_on_overflow */
790 bfd_elf_generic_reloc, /* special_function */
791 "R_ARM_THM_MOVT_PREL", /* name */
792 FALSE, /* partial_inplace */
793 0x040f70ff, /* src_mask */
794 0x040f70ff, /* dst_mask */
795 TRUE), /* pcrel_offset */
796
797 HOWTO (R_ARM_THM_JUMP19, /* type */
798 1, /* rightshift */
799 2, /* size (0 = byte, 1 = short, 2 = long) */
800 19, /* bitsize */
801 TRUE, /* pc_relative */
802 0, /* bitpos */
803 complain_overflow_signed,/* complain_on_overflow */
804 bfd_elf_generic_reloc, /* special_function */
805 "R_ARM_THM_JUMP19", /* name */
806 FALSE, /* partial_inplace */
807 0x043f2fff, /* src_mask */
808 0x043f2fff, /* dst_mask */
809 TRUE), /* pcrel_offset */
810
811 HOWTO (R_ARM_THM_JUMP6, /* type */
812 1, /* rightshift */
813 1, /* size (0 = byte, 1 = short, 2 = long) */
814 6, /* bitsize */
815 TRUE, /* pc_relative */
816 0, /* bitpos */
817 complain_overflow_unsigned,/* complain_on_overflow */
818 bfd_elf_generic_reloc, /* special_function */
819 "R_ARM_THM_JUMP6", /* name */
820 FALSE, /* partial_inplace */
821 0x02f8, /* src_mask */
822 0x02f8, /* dst_mask */
823 TRUE), /* pcrel_offset */
824
825 /* These are declared as 13-bit signed relocations because we can
826 address -4095 .. 4095(base) by altering ADDW to SUBW or vice
827 versa. */
828 HOWTO (R_ARM_THM_ALU_PREL_11_0,/* type */
829 0, /* rightshift */
830 2, /* size (0 = byte, 1 = short, 2 = long) */
831 13, /* bitsize */
832 TRUE, /* pc_relative */
833 0, /* bitpos */
834 complain_overflow_dont,/* complain_on_overflow */
835 bfd_elf_generic_reloc, /* special_function */
836 "R_ARM_THM_ALU_PREL_11_0",/* name */
837 FALSE, /* partial_inplace */
838 0xffffffff, /* src_mask */
839 0xffffffff, /* dst_mask */
840 TRUE), /* pcrel_offset */
841
842 HOWTO (R_ARM_THM_PC12, /* type */
843 0, /* rightshift */
844 2, /* size (0 = byte, 1 = short, 2 = long) */
845 13, /* bitsize */
846 TRUE, /* pc_relative */
847 0, /* bitpos */
848 complain_overflow_dont,/* complain_on_overflow */
849 bfd_elf_generic_reloc, /* special_function */
850 "R_ARM_THM_PC12", /* name */
851 FALSE, /* partial_inplace */
852 0xffffffff, /* src_mask */
853 0xffffffff, /* dst_mask */
854 TRUE), /* pcrel_offset */
855
856 HOWTO (R_ARM_ABS32_NOI, /* type */
857 0, /* rightshift */
858 2, /* size (0 = byte, 1 = short, 2 = long) */
859 32, /* bitsize */
860 FALSE, /* pc_relative */
861 0, /* bitpos */
862 complain_overflow_dont,/* complain_on_overflow */
863 bfd_elf_generic_reloc, /* special_function */
864 "R_ARM_ABS32_NOI", /* name */
865 FALSE, /* partial_inplace */
866 0xffffffff, /* src_mask */
867 0xffffffff, /* dst_mask */
868 FALSE), /* pcrel_offset */
869
870 HOWTO (R_ARM_REL32_NOI, /* type */
871 0, /* rightshift */
872 2, /* size (0 = byte, 1 = short, 2 = long) */
873 32, /* bitsize */
874 TRUE, /* pc_relative */
875 0, /* bitpos */
876 complain_overflow_dont,/* complain_on_overflow */
877 bfd_elf_generic_reloc, /* special_function */
878 "R_ARM_REL32_NOI", /* name */
879 FALSE, /* partial_inplace */
880 0xffffffff, /* src_mask */
881 0xffffffff, /* dst_mask */
882 FALSE), /* pcrel_offset */
883
884 /* Group relocations. */
885
886 HOWTO (R_ARM_ALU_PC_G0_NC, /* type */
887 0, /* rightshift */
888 2, /* size (0 = byte, 1 = short, 2 = long) */
889 32, /* bitsize */
890 TRUE, /* pc_relative */
891 0, /* bitpos */
892 complain_overflow_dont,/* complain_on_overflow */
893 bfd_elf_generic_reloc, /* special_function */
894 "R_ARM_ALU_PC_G0_NC", /* name */
895 FALSE, /* partial_inplace */
896 0xffffffff, /* src_mask */
897 0xffffffff, /* dst_mask */
898 TRUE), /* pcrel_offset */
899
900 HOWTO (R_ARM_ALU_PC_G0, /* type */
901 0, /* rightshift */
902 2, /* size (0 = byte, 1 = short, 2 = long) */
903 32, /* bitsize */
904 TRUE, /* pc_relative */
905 0, /* bitpos */
906 complain_overflow_dont,/* complain_on_overflow */
907 bfd_elf_generic_reloc, /* special_function */
908 "R_ARM_ALU_PC_G0", /* name */
909 FALSE, /* partial_inplace */
910 0xffffffff, /* src_mask */
911 0xffffffff, /* dst_mask */
912 TRUE), /* pcrel_offset */
913
914 HOWTO (R_ARM_ALU_PC_G1_NC, /* type */
915 0, /* rightshift */
916 2, /* size (0 = byte, 1 = short, 2 = long) */
917 32, /* bitsize */
918 TRUE, /* pc_relative */
919 0, /* bitpos */
920 complain_overflow_dont,/* complain_on_overflow */
921 bfd_elf_generic_reloc, /* special_function */
922 "R_ARM_ALU_PC_G1_NC", /* name */
923 FALSE, /* partial_inplace */
924 0xffffffff, /* src_mask */
925 0xffffffff, /* dst_mask */
926 TRUE), /* pcrel_offset */
927
928 HOWTO (R_ARM_ALU_PC_G1, /* type */
929 0, /* rightshift */
930 2, /* size (0 = byte, 1 = short, 2 = long) */
931 32, /* bitsize */
932 TRUE, /* pc_relative */
933 0, /* bitpos */
934 complain_overflow_dont,/* complain_on_overflow */
935 bfd_elf_generic_reloc, /* special_function */
936 "R_ARM_ALU_PC_G1", /* name */
937 FALSE, /* partial_inplace */
938 0xffffffff, /* src_mask */
939 0xffffffff, /* dst_mask */
940 TRUE), /* pcrel_offset */
941
942 HOWTO (R_ARM_ALU_PC_G2, /* type */
943 0, /* rightshift */
944 2, /* size (0 = byte, 1 = short, 2 = long) */
945 32, /* bitsize */
946 TRUE, /* pc_relative */
947 0, /* bitpos */
948 complain_overflow_dont,/* complain_on_overflow */
949 bfd_elf_generic_reloc, /* special_function */
950 "R_ARM_ALU_PC_G2", /* name */
951 FALSE, /* partial_inplace */
952 0xffffffff, /* src_mask */
953 0xffffffff, /* dst_mask */
954 TRUE), /* pcrel_offset */
955
956 HOWTO (R_ARM_LDR_PC_G1, /* type */
957 0, /* rightshift */
958 2, /* size (0 = byte, 1 = short, 2 = long) */
959 32, /* bitsize */
960 TRUE, /* pc_relative */
961 0, /* bitpos */
962 complain_overflow_dont,/* complain_on_overflow */
963 bfd_elf_generic_reloc, /* special_function */
964 "R_ARM_LDR_PC_G1", /* name */
965 FALSE, /* partial_inplace */
966 0xffffffff, /* src_mask */
967 0xffffffff, /* dst_mask */
968 TRUE), /* pcrel_offset */
969
970 HOWTO (R_ARM_LDR_PC_G2, /* type */
971 0, /* rightshift */
972 2, /* size (0 = byte, 1 = short, 2 = long) */
973 32, /* bitsize */
974 TRUE, /* pc_relative */
975 0, /* bitpos */
976 complain_overflow_dont,/* complain_on_overflow */
977 bfd_elf_generic_reloc, /* special_function */
978 "R_ARM_LDR_PC_G2", /* name */
979 FALSE, /* partial_inplace */
980 0xffffffff, /* src_mask */
981 0xffffffff, /* dst_mask */
982 TRUE), /* pcrel_offset */
983
984 HOWTO (R_ARM_LDRS_PC_G0, /* type */
985 0, /* rightshift */
986 2, /* size (0 = byte, 1 = short, 2 = long) */
987 32, /* bitsize */
988 TRUE, /* pc_relative */
989 0, /* bitpos */
990 complain_overflow_dont,/* complain_on_overflow */
991 bfd_elf_generic_reloc, /* special_function */
992 "R_ARM_LDRS_PC_G0", /* name */
993 FALSE, /* partial_inplace */
994 0xffffffff, /* src_mask */
995 0xffffffff, /* dst_mask */
996 TRUE), /* pcrel_offset */
997
998 HOWTO (R_ARM_LDRS_PC_G1, /* type */
999 0, /* rightshift */
1000 2, /* size (0 = byte, 1 = short, 2 = long) */
1001 32, /* bitsize */
1002 TRUE, /* pc_relative */
1003 0, /* bitpos */
1004 complain_overflow_dont,/* complain_on_overflow */
1005 bfd_elf_generic_reloc, /* special_function */
1006 "R_ARM_LDRS_PC_G1", /* name */
1007 FALSE, /* partial_inplace */
1008 0xffffffff, /* src_mask */
1009 0xffffffff, /* dst_mask */
1010 TRUE), /* pcrel_offset */
1011
1012 HOWTO (R_ARM_LDRS_PC_G2, /* type */
1013 0, /* rightshift */
1014 2, /* size (0 = byte, 1 = short, 2 = long) */
1015 32, /* bitsize */
1016 TRUE, /* pc_relative */
1017 0, /* bitpos */
1018 complain_overflow_dont,/* complain_on_overflow */
1019 bfd_elf_generic_reloc, /* special_function */
1020 "R_ARM_LDRS_PC_G2", /* name */
1021 FALSE, /* partial_inplace */
1022 0xffffffff, /* src_mask */
1023 0xffffffff, /* dst_mask */
1024 TRUE), /* pcrel_offset */
1025
1026 HOWTO (R_ARM_LDC_PC_G0, /* type */
1027 0, /* rightshift */
1028 2, /* size (0 = byte, 1 = short, 2 = long) */
1029 32, /* bitsize */
1030 TRUE, /* pc_relative */
1031 0, /* bitpos */
1032 complain_overflow_dont,/* complain_on_overflow */
1033 bfd_elf_generic_reloc, /* special_function */
1034 "R_ARM_LDC_PC_G0", /* name */
1035 FALSE, /* partial_inplace */
1036 0xffffffff, /* src_mask */
1037 0xffffffff, /* dst_mask */
1038 TRUE), /* pcrel_offset */
1039
1040 HOWTO (R_ARM_LDC_PC_G1, /* type */
1041 0, /* rightshift */
1042 2, /* size (0 = byte, 1 = short, 2 = long) */
1043 32, /* bitsize */
1044 TRUE, /* pc_relative */
1045 0, /* bitpos */
1046 complain_overflow_dont,/* complain_on_overflow */
1047 bfd_elf_generic_reloc, /* special_function */
1048 "R_ARM_LDC_PC_G1", /* name */
1049 FALSE, /* partial_inplace */
1050 0xffffffff, /* src_mask */
1051 0xffffffff, /* dst_mask */
1052 TRUE), /* pcrel_offset */
1053
1054 HOWTO (R_ARM_LDC_PC_G2, /* type */
1055 0, /* rightshift */
1056 2, /* size (0 = byte, 1 = short, 2 = long) */
1057 32, /* bitsize */
1058 TRUE, /* pc_relative */
1059 0, /* bitpos */
1060 complain_overflow_dont,/* complain_on_overflow */
1061 bfd_elf_generic_reloc, /* special_function */
1062 "R_ARM_LDC_PC_G2", /* name */
1063 FALSE, /* partial_inplace */
1064 0xffffffff, /* src_mask */
1065 0xffffffff, /* dst_mask */
1066 TRUE), /* pcrel_offset */
1067
1068 HOWTO (R_ARM_ALU_SB_G0_NC, /* type */
1069 0, /* rightshift */
1070 2, /* size (0 = byte, 1 = short, 2 = long) */
1071 32, /* bitsize */
1072 TRUE, /* pc_relative */
1073 0, /* bitpos */
1074 complain_overflow_dont,/* complain_on_overflow */
1075 bfd_elf_generic_reloc, /* special_function */
1076 "R_ARM_ALU_SB_G0_NC", /* name */
1077 FALSE, /* partial_inplace */
1078 0xffffffff, /* src_mask */
1079 0xffffffff, /* dst_mask */
1080 TRUE), /* pcrel_offset */
1081
1082 HOWTO (R_ARM_ALU_SB_G0, /* type */
1083 0, /* rightshift */
1084 2, /* size (0 = byte, 1 = short, 2 = long) */
1085 32, /* bitsize */
1086 TRUE, /* pc_relative */
1087 0, /* bitpos */
1088 complain_overflow_dont,/* complain_on_overflow */
1089 bfd_elf_generic_reloc, /* special_function */
1090 "R_ARM_ALU_SB_G0", /* name */
1091 FALSE, /* partial_inplace */
1092 0xffffffff, /* src_mask */
1093 0xffffffff, /* dst_mask */
1094 TRUE), /* pcrel_offset */
1095
1096 HOWTO (R_ARM_ALU_SB_G1_NC, /* type */
1097 0, /* rightshift */
1098 2, /* size (0 = byte, 1 = short, 2 = long) */
1099 32, /* bitsize */
1100 TRUE, /* pc_relative */
1101 0, /* bitpos */
1102 complain_overflow_dont,/* complain_on_overflow */
1103 bfd_elf_generic_reloc, /* special_function */
1104 "R_ARM_ALU_SB_G1_NC", /* name */
1105 FALSE, /* partial_inplace */
1106 0xffffffff, /* src_mask */
1107 0xffffffff, /* dst_mask */
1108 TRUE), /* pcrel_offset */
1109
1110 HOWTO (R_ARM_ALU_SB_G1, /* type */
1111 0, /* rightshift */
1112 2, /* size (0 = byte, 1 = short, 2 = long) */
1113 32, /* bitsize */
1114 TRUE, /* pc_relative */
1115 0, /* bitpos */
1116 complain_overflow_dont,/* complain_on_overflow */
1117 bfd_elf_generic_reloc, /* special_function */
1118 "R_ARM_ALU_SB_G1", /* name */
1119 FALSE, /* partial_inplace */
1120 0xffffffff, /* src_mask */
1121 0xffffffff, /* dst_mask */
1122 TRUE), /* pcrel_offset */
1123
1124 HOWTO (R_ARM_ALU_SB_G2, /* type */
1125 0, /* rightshift */
1126 2, /* size (0 = byte, 1 = short, 2 = long) */
1127 32, /* bitsize */
1128 TRUE, /* pc_relative */
1129 0, /* bitpos */
1130 complain_overflow_dont,/* complain_on_overflow */
1131 bfd_elf_generic_reloc, /* special_function */
1132 "R_ARM_ALU_SB_G2", /* name */
1133 FALSE, /* partial_inplace */
1134 0xffffffff, /* src_mask */
1135 0xffffffff, /* dst_mask */
1136 TRUE), /* pcrel_offset */
1137
1138 HOWTO (R_ARM_LDR_SB_G0, /* type */
1139 0, /* rightshift */
1140 2, /* size (0 = byte, 1 = short, 2 = long) */
1141 32, /* bitsize */
1142 TRUE, /* pc_relative */
1143 0, /* bitpos */
1144 complain_overflow_dont,/* complain_on_overflow */
1145 bfd_elf_generic_reloc, /* special_function */
1146 "R_ARM_LDR_SB_G0", /* name */
1147 FALSE, /* partial_inplace */
1148 0xffffffff, /* src_mask */
1149 0xffffffff, /* dst_mask */
1150 TRUE), /* pcrel_offset */
1151
1152 HOWTO (R_ARM_LDR_SB_G1, /* type */
1153 0, /* rightshift */
1154 2, /* size (0 = byte, 1 = short, 2 = long) */
1155 32, /* bitsize */
1156 TRUE, /* pc_relative */
1157 0, /* bitpos */
1158 complain_overflow_dont,/* complain_on_overflow */
1159 bfd_elf_generic_reloc, /* special_function */
1160 "R_ARM_LDR_SB_G1", /* name */
1161 FALSE, /* partial_inplace */
1162 0xffffffff, /* src_mask */
1163 0xffffffff, /* dst_mask */
1164 TRUE), /* pcrel_offset */
1165
1166 HOWTO (R_ARM_LDR_SB_G2, /* type */
1167 0, /* rightshift */
1168 2, /* size (0 = byte, 1 = short, 2 = long) */
1169 32, /* bitsize */
1170 TRUE, /* pc_relative */
1171 0, /* bitpos */
1172 complain_overflow_dont,/* complain_on_overflow */
1173 bfd_elf_generic_reloc, /* special_function */
1174 "R_ARM_LDR_SB_G2", /* name */
1175 FALSE, /* partial_inplace */
1176 0xffffffff, /* src_mask */
1177 0xffffffff, /* dst_mask */
1178 TRUE), /* pcrel_offset */
1179
1180 HOWTO (R_ARM_LDRS_SB_G0, /* type */
1181 0, /* rightshift */
1182 2, /* size (0 = byte, 1 = short, 2 = long) */
1183 32, /* bitsize */
1184 TRUE, /* pc_relative */
1185 0, /* bitpos */
1186 complain_overflow_dont,/* complain_on_overflow */
1187 bfd_elf_generic_reloc, /* special_function */
1188 "R_ARM_LDRS_SB_G0", /* name */
1189 FALSE, /* partial_inplace */
1190 0xffffffff, /* src_mask */
1191 0xffffffff, /* dst_mask */
1192 TRUE), /* pcrel_offset */
1193
1194 HOWTO (R_ARM_LDRS_SB_G1, /* type */
1195 0, /* rightshift */
1196 2, /* size (0 = byte, 1 = short, 2 = long) */
1197 32, /* bitsize */
1198 TRUE, /* pc_relative */
1199 0, /* bitpos */
1200 complain_overflow_dont,/* complain_on_overflow */
1201 bfd_elf_generic_reloc, /* special_function */
1202 "R_ARM_LDRS_SB_G1", /* name */
1203 FALSE, /* partial_inplace */
1204 0xffffffff, /* src_mask */
1205 0xffffffff, /* dst_mask */
1206 TRUE), /* pcrel_offset */
1207
1208 HOWTO (R_ARM_LDRS_SB_G2, /* type */
1209 0, /* rightshift */
1210 2, /* size (0 = byte, 1 = short, 2 = long) */
1211 32, /* bitsize */
1212 TRUE, /* pc_relative */
1213 0, /* bitpos */
1214 complain_overflow_dont,/* complain_on_overflow */
1215 bfd_elf_generic_reloc, /* special_function */
1216 "R_ARM_LDRS_SB_G2", /* name */
1217 FALSE, /* partial_inplace */
1218 0xffffffff, /* src_mask */
1219 0xffffffff, /* dst_mask */
1220 TRUE), /* pcrel_offset */
1221
1222 HOWTO (R_ARM_LDC_SB_G0, /* type */
1223 0, /* rightshift */
1224 2, /* size (0 = byte, 1 = short, 2 = long) */
1225 32, /* bitsize */
1226 TRUE, /* pc_relative */
1227 0, /* bitpos */
1228 complain_overflow_dont,/* complain_on_overflow */
1229 bfd_elf_generic_reloc, /* special_function */
1230 "R_ARM_LDC_SB_G0", /* name */
1231 FALSE, /* partial_inplace */
1232 0xffffffff, /* src_mask */
1233 0xffffffff, /* dst_mask */
1234 TRUE), /* pcrel_offset */
1235
1236 HOWTO (R_ARM_LDC_SB_G1, /* type */
1237 0, /* rightshift */
1238 2, /* size (0 = byte, 1 = short, 2 = long) */
1239 32, /* bitsize */
1240 TRUE, /* pc_relative */
1241 0, /* bitpos */
1242 complain_overflow_dont,/* complain_on_overflow */
1243 bfd_elf_generic_reloc, /* special_function */
1244 "R_ARM_LDC_SB_G1", /* name */
1245 FALSE, /* partial_inplace */
1246 0xffffffff, /* src_mask */
1247 0xffffffff, /* dst_mask */
1248 TRUE), /* pcrel_offset */
1249
1250 HOWTO (R_ARM_LDC_SB_G2, /* type */
1251 0, /* rightshift */
1252 2, /* size (0 = byte, 1 = short, 2 = long) */
1253 32, /* bitsize */
1254 TRUE, /* pc_relative */
1255 0, /* bitpos */
1256 complain_overflow_dont,/* complain_on_overflow */
1257 bfd_elf_generic_reloc, /* special_function */
1258 "R_ARM_LDC_SB_G2", /* name */
1259 FALSE, /* partial_inplace */
1260 0xffffffff, /* src_mask */
1261 0xffffffff, /* dst_mask */
1262 TRUE), /* pcrel_offset */
1263
1264 /* End of group relocations. */
1265
1266 HOWTO (R_ARM_MOVW_BREL_NC, /* type */
1267 0, /* rightshift */
1268 2, /* size (0 = byte, 1 = short, 2 = long) */
1269 16, /* bitsize */
1270 FALSE, /* pc_relative */
1271 0, /* bitpos */
1272 complain_overflow_dont,/* complain_on_overflow */
1273 bfd_elf_generic_reloc, /* special_function */
1274 "R_ARM_MOVW_BREL_NC", /* name */
1275 FALSE, /* partial_inplace */
1276 0x0000ffff, /* src_mask */
1277 0x0000ffff, /* dst_mask */
1278 FALSE), /* pcrel_offset */
1279
1280 HOWTO (R_ARM_MOVT_BREL, /* type */
1281 0, /* rightshift */
1282 2, /* size (0 = byte, 1 = short, 2 = long) */
1283 16, /* bitsize */
1284 FALSE, /* pc_relative */
1285 0, /* bitpos */
1286 complain_overflow_bitfield,/* complain_on_overflow */
1287 bfd_elf_generic_reloc, /* special_function */
1288 "R_ARM_MOVT_BREL", /* name */
1289 FALSE, /* partial_inplace */
1290 0x0000ffff, /* src_mask */
1291 0x0000ffff, /* dst_mask */
1292 FALSE), /* pcrel_offset */
1293
1294 HOWTO (R_ARM_MOVW_BREL, /* type */
1295 0, /* rightshift */
1296 2, /* size (0 = byte, 1 = short, 2 = long) */
1297 16, /* bitsize */
1298 FALSE, /* pc_relative */
1299 0, /* bitpos */
1300 complain_overflow_dont,/* complain_on_overflow */
1301 bfd_elf_generic_reloc, /* special_function */
1302 "R_ARM_MOVW_BREL", /* name */
1303 FALSE, /* partial_inplace */
1304 0x0000ffff, /* src_mask */
1305 0x0000ffff, /* dst_mask */
1306 FALSE), /* pcrel_offset */
1307
1308 HOWTO (R_ARM_THM_MOVW_BREL_NC,/* type */
1309 0, /* rightshift */
1310 2, /* size (0 = byte, 1 = short, 2 = long) */
1311 16, /* bitsize */
1312 FALSE, /* pc_relative */
1313 0, /* bitpos */
1314 complain_overflow_dont,/* complain_on_overflow */
1315 bfd_elf_generic_reloc, /* special_function */
1316 "R_ARM_THM_MOVW_BREL_NC",/* name */
1317 FALSE, /* partial_inplace */
1318 0x040f70ff, /* src_mask */
1319 0x040f70ff, /* dst_mask */
1320 FALSE), /* pcrel_offset */
1321
1322 HOWTO (R_ARM_THM_MOVT_BREL, /* type */
1323 0, /* rightshift */
1324 2, /* size (0 = byte, 1 = short, 2 = long) */
1325 16, /* bitsize */
1326 FALSE, /* pc_relative */
1327 0, /* bitpos */
1328 complain_overflow_bitfield,/* complain_on_overflow */
1329 bfd_elf_generic_reloc, /* special_function */
1330 "R_ARM_THM_MOVT_BREL", /* name */
1331 FALSE, /* partial_inplace */
1332 0x040f70ff, /* src_mask */
1333 0x040f70ff, /* dst_mask */
1334 FALSE), /* pcrel_offset */
1335
1336 HOWTO (R_ARM_THM_MOVW_BREL, /* type */
1337 0, /* rightshift */
1338 2, /* size (0 = byte, 1 = short, 2 = long) */
1339 16, /* bitsize */
1340 FALSE, /* pc_relative */
1341 0, /* bitpos */
1342 complain_overflow_dont,/* complain_on_overflow */
1343 bfd_elf_generic_reloc, /* special_function */
1344 "R_ARM_THM_MOVW_BREL", /* name */
1345 FALSE, /* partial_inplace */
1346 0x040f70ff, /* src_mask */
1347 0x040f70ff, /* dst_mask */
1348 FALSE), /* pcrel_offset */
1349
1350 EMPTY_HOWTO (90), /* unallocated */
1351 EMPTY_HOWTO (91),
1352 EMPTY_HOWTO (92),
1353 EMPTY_HOWTO (93),
1354
1355 HOWTO (R_ARM_PLT32_ABS, /* type */
1356 0, /* rightshift */
1357 2, /* size (0 = byte, 1 = short, 2 = long) */
1358 32, /* bitsize */
1359 FALSE, /* pc_relative */
1360 0, /* bitpos */
1361 complain_overflow_dont,/* complain_on_overflow */
1362 bfd_elf_generic_reloc, /* special_function */
1363 "R_ARM_PLT32_ABS", /* name */
1364 FALSE, /* partial_inplace */
1365 0xffffffff, /* src_mask */
1366 0xffffffff, /* dst_mask */
1367 FALSE), /* pcrel_offset */
1368
1369 HOWTO (R_ARM_GOT_ABS, /* type */
1370 0, /* rightshift */
1371 2, /* size (0 = byte, 1 = short, 2 = long) */
1372 32, /* bitsize */
1373 FALSE, /* pc_relative */
1374 0, /* bitpos */
1375 complain_overflow_dont,/* complain_on_overflow */
1376 bfd_elf_generic_reloc, /* special_function */
1377 "R_ARM_GOT_ABS", /* name */
1378 FALSE, /* partial_inplace */
1379 0xffffffff, /* src_mask */
1380 0xffffffff, /* dst_mask */
1381 FALSE), /* pcrel_offset */
1382
1383 HOWTO (R_ARM_GOT_PREL, /* type */
1384 0, /* rightshift */
1385 2, /* size (0 = byte, 1 = short, 2 = long) */
1386 32, /* bitsize */
1387 TRUE, /* pc_relative */
1388 0, /* bitpos */
1389 complain_overflow_dont, /* complain_on_overflow */
1390 bfd_elf_generic_reloc, /* special_function */
1391 "R_ARM_GOT_PREL", /* name */
1392 FALSE, /* partial_inplace */
1393 0xffffffff, /* src_mask */
1394 0xffffffff, /* dst_mask */
1395 TRUE), /* pcrel_offset */
1396
1397 HOWTO (R_ARM_GOT_BREL12, /* type */
1398 0, /* rightshift */
1399 2, /* size (0 = byte, 1 = short, 2 = long) */
1400 12, /* bitsize */
1401 FALSE, /* pc_relative */
1402 0, /* bitpos */
1403 complain_overflow_bitfield,/* complain_on_overflow */
1404 bfd_elf_generic_reloc, /* special_function */
1405 "R_ARM_GOT_BREL12", /* name */
1406 FALSE, /* partial_inplace */
1407 0x00000fff, /* src_mask */
1408 0x00000fff, /* dst_mask */
1409 FALSE), /* pcrel_offset */
1410
1411 HOWTO (R_ARM_GOTOFF12, /* type */
1412 0, /* rightshift */
1413 2, /* size (0 = byte, 1 = short, 2 = long) */
1414 12, /* bitsize */
1415 FALSE, /* pc_relative */
1416 0, /* bitpos */
1417 complain_overflow_bitfield,/* complain_on_overflow */
1418 bfd_elf_generic_reloc, /* special_function */
1419 "R_ARM_GOTOFF12", /* name */
1420 FALSE, /* partial_inplace */
1421 0x00000fff, /* src_mask */
1422 0x00000fff, /* dst_mask */
1423 FALSE), /* pcrel_offset */
1424
1425 EMPTY_HOWTO (R_ARM_GOTRELAX), /* reserved for future GOT-load optimizations */
1426
1427 /* GNU extension to record C++ vtable member usage */
1428 HOWTO (R_ARM_GNU_VTENTRY, /* type */
1429 0, /* rightshift */
1430 2, /* size (0 = byte, 1 = short, 2 = long) */
1431 0, /* bitsize */
1432 FALSE, /* pc_relative */
1433 0, /* bitpos */
1434 complain_overflow_dont, /* complain_on_overflow */
1435 _bfd_elf_rel_vtable_reloc_fn, /* special_function */
1436 "R_ARM_GNU_VTENTRY", /* name */
1437 FALSE, /* partial_inplace */
1438 0, /* src_mask */
1439 0, /* dst_mask */
1440 FALSE), /* pcrel_offset */
1441
1442 /* GNU extension to record C++ vtable hierarchy */
1443 HOWTO (R_ARM_GNU_VTINHERIT, /* type */
1444 0, /* rightshift */
1445 2, /* size (0 = byte, 1 = short, 2 = long) */
1446 0, /* bitsize */
1447 FALSE, /* pc_relative */
1448 0, /* bitpos */
1449 complain_overflow_dont, /* complain_on_overflow */
1450 NULL, /* special_function */
1451 "R_ARM_GNU_VTINHERIT", /* name */
1452 FALSE, /* partial_inplace */
1453 0, /* src_mask */
1454 0, /* dst_mask */
1455 FALSE), /* pcrel_offset */
1456
1457 HOWTO (R_ARM_THM_JUMP11, /* type */
1458 1, /* rightshift */
1459 1, /* size (0 = byte, 1 = short, 2 = long) */
1460 11, /* bitsize */
1461 TRUE, /* pc_relative */
1462 0, /* bitpos */
1463 complain_overflow_signed, /* complain_on_overflow */
1464 bfd_elf_generic_reloc, /* special_function */
1465 "R_ARM_THM_JUMP11", /* name */
1466 FALSE, /* partial_inplace */
1467 0x000007ff, /* src_mask */
1468 0x000007ff, /* dst_mask */
1469 TRUE), /* pcrel_offset */
1470
1471 HOWTO (R_ARM_THM_JUMP8, /* type */
1472 1, /* rightshift */
1473 1, /* size (0 = byte, 1 = short, 2 = long) */
1474 8, /* bitsize */
1475 TRUE, /* pc_relative */
1476 0, /* bitpos */
1477 complain_overflow_signed, /* complain_on_overflow */
1478 bfd_elf_generic_reloc, /* special_function */
1479 "R_ARM_THM_JUMP8", /* name */
1480 FALSE, /* partial_inplace */
1481 0x000000ff, /* src_mask */
1482 0x000000ff, /* dst_mask */
1483 TRUE), /* pcrel_offset */
1484
1485 /* TLS relocations */
1486 HOWTO (R_ARM_TLS_GD32, /* type */
1487 0, /* rightshift */
1488 2, /* size (0 = byte, 1 = short, 2 = long) */
1489 32, /* bitsize */
1490 FALSE, /* pc_relative */
1491 0, /* bitpos */
1492 complain_overflow_bitfield,/* complain_on_overflow */
1493 NULL, /* special_function */
1494 "R_ARM_TLS_GD32", /* name */
1495 TRUE, /* partial_inplace */
1496 0xffffffff, /* src_mask */
1497 0xffffffff, /* dst_mask */
1498 FALSE), /* pcrel_offset */
1499
1500 HOWTO (R_ARM_TLS_LDM32, /* type */
1501 0, /* rightshift */
1502 2, /* size (0 = byte, 1 = short, 2 = long) */
1503 32, /* bitsize */
1504 FALSE, /* pc_relative */
1505 0, /* bitpos */
1506 complain_overflow_bitfield,/* complain_on_overflow */
1507 bfd_elf_generic_reloc, /* special_function */
1508 "R_ARM_TLS_LDM32", /* name */
1509 TRUE, /* partial_inplace */
1510 0xffffffff, /* src_mask */
1511 0xffffffff, /* dst_mask */
1512 FALSE), /* pcrel_offset */
1513
1514 HOWTO (R_ARM_TLS_LDO32, /* type */
1515 0, /* rightshift */
1516 2, /* size (0 = byte, 1 = short, 2 = long) */
1517 32, /* bitsize */
1518 FALSE, /* pc_relative */
1519 0, /* bitpos */
1520 complain_overflow_bitfield,/* complain_on_overflow */
1521 bfd_elf_generic_reloc, /* special_function */
1522 "R_ARM_TLS_LDO32", /* name */
1523 TRUE, /* partial_inplace */
1524 0xffffffff, /* src_mask */
1525 0xffffffff, /* dst_mask */
1526 FALSE), /* pcrel_offset */
1527
1528 HOWTO (R_ARM_TLS_IE32, /* type */
1529 0, /* rightshift */
1530 2, /* size (0 = byte, 1 = short, 2 = long) */
1531 32, /* bitsize */
1532 FALSE, /* pc_relative */
1533 0, /* bitpos */
1534 complain_overflow_bitfield,/* complain_on_overflow */
1535 NULL, /* special_function */
1536 "R_ARM_TLS_IE32", /* name */
1537 TRUE, /* partial_inplace */
1538 0xffffffff, /* src_mask */
1539 0xffffffff, /* dst_mask */
1540 FALSE), /* pcrel_offset */
1541
1542 HOWTO (R_ARM_TLS_LE32, /* type */
1543 0, /* rightshift */
1544 2, /* size (0 = byte, 1 = short, 2 = long) */
1545 32, /* bitsize */
1546 FALSE, /* pc_relative */
1547 0, /* bitpos */
1548 complain_overflow_bitfield,/* complain_on_overflow */
1549 bfd_elf_generic_reloc, /* special_function */
1550 "R_ARM_TLS_LE32", /* name */
1551 TRUE, /* partial_inplace */
1552 0xffffffff, /* src_mask */
1553 0xffffffff, /* dst_mask */
1554 FALSE), /* pcrel_offset */
1555
1556 HOWTO (R_ARM_TLS_LDO12, /* type */
1557 0, /* rightshift */
1558 2, /* size (0 = byte, 1 = short, 2 = long) */
1559 12, /* bitsize */
1560 FALSE, /* pc_relative */
1561 0, /* bitpos */
1562 complain_overflow_bitfield,/* complain_on_overflow */
1563 bfd_elf_generic_reloc, /* special_function */
1564 "R_ARM_TLS_LDO12", /* name */
1565 FALSE, /* partial_inplace */
1566 0x00000fff, /* src_mask */
1567 0x00000fff, /* dst_mask */
1568 FALSE), /* pcrel_offset */
1569
1570 HOWTO (R_ARM_TLS_LE12, /* type */
1571 0, /* rightshift */
1572 2, /* size (0 = byte, 1 = short, 2 = long) */
1573 12, /* bitsize */
1574 FALSE, /* pc_relative */
1575 0, /* bitpos */
1576 complain_overflow_bitfield,/* complain_on_overflow */
1577 bfd_elf_generic_reloc, /* special_function */
1578 "R_ARM_TLS_LE12", /* name */
1579 FALSE, /* partial_inplace */
1580 0x00000fff, /* src_mask */
1581 0x00000fff, /* dst_mask */
1582 FALSE), /* pcrel_offset */
1583
1584 HOWTO (R_ARM_TLS_IE12GP, /* type */
1585 0, /* rightshift */
1586 2, /* size (0 = byte, 1 = short, 2 = long) */
1587 12, /* bitsize */
1588 FALSE, /* pc_relative */
1589 0, /* bitpos */
1590 complain_overflow_bitfield,/* complain_on_overflow */
1591 bfd_elf_generic_reloc, /* special_function */
1592 "R_ARM_TLS_IE12GP", /* name */
1593 FALSE, /* partial_inplace */
1594 0x00000fff, /* src_mask */
1595 0x00000fff, /* dst_mask */
1596 FALSE), /* pcrel_offset */
1597 };
1598
1599 /* 112-127 private relocations
1600 128 R_ARM_ME_TOO, obsolete
1601 129-255 unallocated in AAELF.
1602
1603 249-255 extended, currently unused, relocations: */
1604
1605 static reloc_howto_type elf32_arm_howto_table_2[4] =
1606 {
1607 HOWTO (R_ARM_RREL32, /* type */
1608 0, /* rightshift */
1609 0, /* size (0 = byte, 1 = short, 2 = long) */
1610 0, /* bitsize */
1611 FALSE, /* pc_relative */
1612 0, /* bitpos */
1613 complain_overflow_dont,/* complain_on_overflow */
1614 bfd_elf_generic_reloc, /* special_function */
1615 "R_ARM_RREL32", /* name */
1616 FALSE, /* partial_inplace */
1617 0, /* src_mask */
1618 0, /* dst_mask */
1619 FALSE), /* pcrel_offset */
1620
1621 HOWTO (R_ARM_RABS32, /* type */
1622 0, /* rightshift */
1623 0, /* size (0 = byte, 1 = short, 2 = long) */
1624 0, /* bitsize */
1625 FALSE, /* pc_relative */
1626 0, /* bitpos */
1627 complain_overflow_dont,/* complain_on_overflow */
1628 bfd_elf_generic_reloc, /* special_function */
1629 "R_ARM_RABS32", /* name */
1630 FALSE, /* partial_inplace */
1631 0, /* src_mask */
1632 0, /* dst_mask */
1633 FALSE), /* pcrel_offset */
1634
1635 HOWTO (R_ARM_RPC24, /* type */
1636 0, /* rightshift */
1637 0, /* size (0 = byte, 1 = short, 2 = long) */
1638 0, /* bitsize */
1639 FALSE, /* pc_relative */
1640 0, /* bitpos */
1641 complain_overflow_dont,/* complain_on_overflow */
1642 bfd_elf_generic_reloc, /* special_function */
1643 "R_ARM_RPC24", /* name */
1644 FALSE, /* partial_inplace */
1645 0, /* src_mask */
1646 0, /* dst_mask */
1647 FALSE), /* pcrel_offset */
1648
1649 HOWTO (R_ARM_RBASE, /* type */
1650 0, /* rightshift */
1651 0, /* size (0 = byte, 1 = short, 2 = long) */
1652 0, /* bitsize */
1653 FALSE, /* pc_relative */
1654 0, /* bitpos */
1655 complain_overflow_dont,/* complain_on_overflow */
1656 bfd_elf_generic_reloc, /* special_function */
1657 "R_ARM_RBASE", /* name */
1658 FALSE, /* partial_inplace */
1659 0, /* src_mask */
1660 0, /* dst_mask */
1661 FALSE) /* pcrel_offset */
1662 };
1663
1664 static reloc_howto_type *
1665 elf32_arm_howto_from_type (unsigned int r_type)
1666 {
1667 if (r_type < ARRAY_SIZE (elf32_arm_howto_table_1))
1668 return &elf32_arm_howto_table_1[r_type];
1669
1670 if (r_type >= R_ARM_RREL32
1671 && r_type < R_ARM_RREL32 + ARRAY_SIZE (elf32_arm_howto_table_2))
1672 return &elf32_arm_howto_table_2[r_type - R_ARM_RREL32];
1673
1674 return NULL;
1675 }
1676
1677 static void
1678 elf32_arm_info_to_howto (bfd * abfd ATTRIBUTE_UNUSED, arelent * bfd_reloc,
1679 Elf_Internal_Rela * elf_reloc)
1680 {
1681 unsigned int r_type;
1682
1683 r_type = ELF32_R_TYPE (elf_reloc->r_info);
1684 bfd_reloc->howto = elf32_arm_howto_from_type (r_type);
1685 }
1686
1687 struct elf32_arm_reloc_map
1688 {
1689 bfd_reloc_code_real_type bfd_reloc_val;
1690 unsigned char elf_reloc_val;
1691 };
1692
1693 /* All entries in this list must also be present in elf32_arm_howto_table. */
1694 static const struct elf32_arm_reloc_map elf32_arm_reloc_map[] =
1695 {
1696 {BFD_RELOC_NONE, R_ARM_NONE},
1697 {BFD_RELOC_ARM_PCREL_BRANCH, R_ARM_PC24},
1698 {BFD_RELOC_ARM_PCREL_CALL, R_ARM_CALL},
1699 {BFD_RELOC_ARM_PCREL_JUMP, R_ARM_JUMP24},
1700 {BFD_RELOC_ARM_PCREL_BLX, R_ARM_XPC25},
1701 {BFD_RELOC_THUMB_PCREL_BLX, R_ARM_THM_XPC22},
1702 {BFD_RELOC_32, R_ARM_ABS32},
1703 {BFD_RELOC_32_PCREL, R_ARM_REL32},
1704 {BFD_RELOC_8, R_ARM_ABS8},
1705 {BFD_RELOC_16, R_ARM_ABS16},
1706 {BFD_RELOC_ARM_OFFSET_IMM, R_ARM_ABS12},
1707 {BFD_RELOC_ARM_THUMB_OFFSET, R_ARM_THM_ABS5},
1708 {BFD_RELOC_THUMB_PCREL_BRANCH25, R_ARM_THM_JUMP24},
1709 {BFD_RELOC_THUMB_PCREL_BRANCH23, R_ARM_THM_CALL},
1710 {BFD_RELOC_THUMB_PCREL_BRANCH12, R_ARM_THM_JUMP11},
1711 {BFD_RELOC_THUMB_PCREL_BRANCH20, R_ARM_THM_JUMP19},
1712 {BFD_RELOC_THUMB_PCREL_BRANCH9, R_ARM_THM_JUMP8},
1713 {BFD_RELOC_THUMB_PCREL_BRANCH7, R_ARM_THM_JUMP6},
1714 {BFD_RELOC_ARM_GLOB_DAT, R_ARM_GLOB_DAT},
1715 {BFD_RELOC_ARM_JUMP_SLOT, R_ARM_JUMP_SLOT},
1716 {BFD_RELOC_ARM_RELATIVE, R_ARM_RELATIVE},
1717 {BFD_RELOC_ARM_GOTOFF, R_ARM_GOTOFF32},
1718 {BFD_RELOC_ARM_GOTPC, R_ARM_GOTPC},
1719 {BFD_RELOC_ARM_GOT32, R_ARM_GOT32},
1720 {BFD_RELOC_ARM_PLT32, R_ARM_PLT32},
1721 {BFD_RELOC_ARM_TARGET1, R_ARM_TARGET1},
1722 {BFD_RELOC_ARM_ROSEGREL32, R_ARM_ROSEGREL32},
1723 {BFD_RELOC_ARM_SBREL32, R_ARM_SBREL32},
1724 {BFD_RELOC_ARM_PREL31, R_ARM_PREL31},
1725 {BFD_RELOC_ARM_TARGET2, R_ARM_TARGET2},
1726 {BFD_RELOC_ARM_PLT32, R_ARM_PLT32},
1727 {BFD_RELOC_ARM_TLS_GD32, R_ARM_TLS_GD32},
1728 {BFD_RELOC_ARM_TLS_LDO32, R_ARM_TLS_LDO32},
1729 {BFD_RELOC_ARM_TLS_LDM32, R_ARM_TLS_LDM32},
1730 {BFD_RELOC_ARM_TLS_DTPMOD32, R_ARM_TLS_DTPMOD32},
1731 {BFD_RELOC_ARM_TLS_DTPOFF32, R_ARM_TLS_DTPOFF32},
1732 {BFD_RELOC_ARM_TLS_TPOFF32, R_ARM_TLS_TPOFF32},
1733 {BFD_RELOC_ARM_TLS_IE32, R_ARM_TLS_IE32},
1734 {BFD_RELOC_ARM_TLS_LE32, R_ARM_TLS_LE32},
1735 {BFD_RELOC_VTABLE_INHERIT, R_ARM_GNU_VTINHERIT},
1736 {BFD_RELOC_VTABLE_ENTRY, R_ARM_GNU_VTENTRY},
1737 {BFD_RELOC_ARM_MOVW, R_ARM_MOVW_ABS_NC},
1738 {BFD_RELOC_ARM_MOVT, R_ARM_MOVT_ABS},
1739 {BFD_RELOC_ARM_MOVW_PCREL, R_ARM_MOVW_PREL_NC},
1740 {BFD_RELOC_ARM_MOVT_PCREL, R_ARM_MOVT_PREL},
1741 {BFD_RELOC_ARM_THUMB_MOVW, R_ARM_THM_MOVW_ABS_NC},
1742 {BFD_RELOC_ARM_THUMB_MOVT, R_ARM_THM_MOVT_ABS},
1743 {BFD_RELOC_ARM_THUMB_MOVW_PCREL, R_ARM_THM_MOVW_PREL_NC},
1744 {BFD_RELOC_ARM_THUMB_MOVT_PCREL, R_ARM_THM_MOVT_PREL},
1745 {BFD_RELOC_ARM_ALU_PC_G0_NC, R_ARM_ALU_PC_G0_NC},
1746 {BFD_RELOC_ARM_ALU_PC_G0, R_ARM_ALU_PC_G0},
1747 {BFD_RELOC_ARM_ALU_PC_G1_NC, R_ARM_ALU_PC_G1_NC},
1748 {BFD_RELOC_ARM_ALU_PC_G1, R_ARM_ALU_PC_G1},
1749 {BFD_RELOC_ARM_ALU_PC_G2, R_ARM_ALU_PC_G2},
1750 {BFD_RELOC_ARM_LDR_PC_G0, R_ARM_LDR_PC_G0},
1751 {BFD_RELOC_ARM_LDR_PC_G1, R_ARM_LDR_PC_G1},
1752 {BFD_RELOC_ARM_LDR_PC_G2, R_ARM_LDR_PC_G2},
1753 {BFD_RELOC_ARM_LDRS_PC_G0, R_ARM_LDRS_PC_G0},
1754 {BFD_RELOC_ARM_LDRS_PC_G1, R_ARM_LDRS_PC_G1},
1755 {BFD_RELOC_ARM_LDRS_PC_G2, R_ARM_LDRS_PC_G2},
1756 {BFD_RELOC_ARM_LDC_PC_G0, R_ARM_LDC_PC_G0},
1757 {BFD_RELOC_ARM_LDC_PC_G1, R_ARM_LDC_PC_G1},
1758 {BFD_RELOC_ARM_LDC_PC_G2, R_ARM_LDC_PC_G2},
1759 {BFD_RELOC_ARM_ALU_SB_G0_NC, R_ARM_ALU_SB_G0_NC},
1760 {BFD_RELOC_ARM_ALU_SB_G0, R_ARM_ALU_SB_G0},
1761 {BFD_RELOC_ARM_ALU_SB_G1_NC, R_ARM_ALU_SB_G1_NC},
1762 {BFD_RELOC_ARM_ALU_SB_G1, R_ARM_ALU_SB_G1},
1763 {BFD_RELOC_ARM_ALU_SB_G2, R_ARM_ALU_SB_G2},
1764 {BFD_RELOC_ARM_LDR_SB_G0, R_ARM_LDR_SB_G0},
1765 {BFD_RELOC_ARM_LDR_SB_G1, R_ARM_LDR_SB_G1},
1766 {BFD_RELOC_ARM_LDR_SB_G2, R_ARM_LDR_SB_G2},
1767 {BFD_RELOC_ARM_LDRS_SB_G0, R_ARM_LDRS_SB_G0},
1768 {BFD_RELOC_ARM_LDRS_SB_G1, R_ARM_LDRS_SB_G1},
1769 {BFD_RELOC_ARM_LDRS_SB_G2, R_ARM_LDRS_SB_G2},
1770 {BFD_RELOC_ARM_LDC_SB_G0, R_ARM_LDC_SB_G0},
1771 {BFD_RELOC_ARM_LDC_SB_G1, R_ARM_LDC_SB_G1},
1772 {BFD_RELOC_ARM_LDC_SB_G2, R_ARM_LDC_SB_G2},
1773 {BFD_RELOC_ARM_V4BX, R_ARM_V4BX}
1774 };
1775
1776 static reloc_howto_type *
1777 elf32_arm_reloc_type_lookup (bfd *abfd ATTRIBUTE_UNUSED,
1778 bfd_reloc_code_real_type code)
1779 {
1780 unsigned int i;
1781 for (i = 0; i < ARRAY_SIZE (elf32_arm_reloc_map); i ++)
1782 if (elf32_arm_reloc_map[i].bfd_reloc_val == code)
1783 return elf32_arm_howto_from_type (elf32_arm_reloc_map[i].elf_reloc_val);
1784
1785 return NULL;
1786 }
1787
1788 static reloc_howto_type *
1789 elf32_arm_reloc_name_lookup (bfd *abfd ATTRIBUTE_UNUSED,
1790 const char *r_name)
1791 {
1792 unsigned int i;
1793
1794 for (i = 0; i < ARRAY_SIZE (elf32_arm_howto_table_1); i++)
1795 if (elf32_arm_howto_table_1[i].name != NULL
1796 && strcasecmp (elf32_arm_howto_table_1[i].name, r_name) == 0)
1797 return &elf32_arm_howto_table_1[i];
1798
1799 for (i = 0; i < ARRAY_SIZE (elf32_arm_howto_table_2); i++)
1800 if (elf32_arm_howto_table_2[i].name != NULL
1801 && strcasecmp (elf32_arm_howto_table_2[i].name, r_name) == 0)
1802 return &elf32_arm_howto_table_2[i];
1803
1804 return NULL;
1805 }
1806
1807 /* Support for core dump NOTE sections. */
1808
1809 static bfd_boolean
1810 elf32_arm_nabi_grok_prstatus (bfd *abfd, Elf_Internal_Note *note)
1811 {
1812 int offset;
1813 size_t size;
1814
1815 switch (note->descsz)
1816 {
1817 default:
1818 return FALSE;
1819
1820 case 148: /* Linux/ARM 32-bit*/
1821 /* pr_cursig */
1822 elf_tdata (abfd)->core_signal = bfd_get_16 (abfd, note->descdata + 12);
1823
1824 /* pr_pid */
1825 elf_tdata (abfd)->core_pid = bfd_get_32 (abfd, note->descdata + 24);
1826
1827 /* pr_reg */
1828 offset = 72;
1829 size = 72;
1830
1831 break;
1832 }
1833
1834 /* Make a ".reg/999" section. */
1835 return _bfd_elfcore_make_pseudosection (abfd, ".reg",
1836 size, note->descpos + offset);
1837 }
1838
1839 static bfd_boolean
1840 elf32_arm_nabi_grok_psinfo (bfd *abfd, Elf_Internal_Note *note)
1841 {
1842 switch (note->descsz)
1843 {
1844 default:
1845 return FALSE;
1846
1847 case 124: /* Linux/ARM elf_prpsinfo */
1848 elf_tdata (abfd)->core_program
1849 = _bfd_elfcore_strndup (abfd, note->descdata + 28, 16);
1850 elf_tdata (abfd)->core_command
1851 = _bfd_elfcore_strndup (abfd, note->descdata + 44, 80);
1852 }
1853
1854 /* Note that for some reason, a spurious space is tacked
1855 onto the end of the args in some (at least one anyway)
1856 implementations, so strip it off if it exists. */
1857 {
1858 char *command = elf_tdata (abfd)->core_command;
1859 int n = strlen (command);
1860
1861 if (0 < n && command[n - 1] == ' ')
1862 command[n - 1] = '\0';
1863 }
1864
1865 return TRUE;
1866 }
1867
1868 #define TARGET_LITTLE_SYM bfd_elf32_littlearm_vec
1869 #define TARGET_LITTLE_NAME "elf32-littlearm"
1870 #define TARGET_BIG_SYM bfd_elf32_bigarm_vec
1871 #define TARGET_BIG_NAME "elf32-bigarm"
1872
1873 #define elf_backend_grok_prstatus elf32_arm_nabi_grok_prstatus
1874 #define elf_backend_grok_psinfo elf32_arm_nabi_grok_psinfo
1875
1876 typedef unsigned long int insn32;
1877 typedef unsigned short int insn16;
1878
1879 /* In lieu of proper flags, assume all EABIv4 or later objects are
1880 interworkable. */
1881 #define INTERWORK_FLAG(abfd) \
1882 (EF_ARM_EABI_VERSION (elf_elfheader (abfd)->e_flags) >= EF_ARM_EABI_VER4 \
1883 || (elf_elfheader (abfd)->e_flags & EF_ARM_INTERWORK))
1884
1885 /* The linker script knows the section names for placement.
1886 The entry_names are used to do simple name mangling on the stubs.
1887 Given a function name, and its type, the stub can be found. The
1888 name can be changed. The only requirement is the %s be present. */
1889 #define THUMB2ARM_GLUE_SECTION_NAME ".glue_7t"
1890 #define THUMB2ARM_GLUE_ENTRY_NAME "__%s_from_thumb"
1891
1892 #define ARM2THUMB_GLUE_SECTION_NAME ".glue_7"
1893 #define ARM2THUMB_GLUE_ENTRY_NAME "__%s_from_arm"
1894
1895 #define VFP11_ERRATUM_VENEER_SECTION_NAME ".vfp11_veneer"
1896 #define VFP11_ERRATUM_VENEER_ENTRY_NAME "__vfp11_veneer_%x"
1897
1898 #define ARM_BX_GLUE_SECTION_NAME ".v4_bx"
1899 #define ARM_BX_GLUE_ENTRY_NAME "__bx_r%d"
1900
1901 #define STUB_ENTRY_NAME "__%s_veneer"
1902
1903 /* The name of the dynamic interpreter. This is put in the .interp
1904 section. */
1905 #define ELF_DYNAMIC_INTERPRETER "/usr/lib/ld.so.1"
1906
1907 #ifdef FOUR_WORD_PLT
1908
1909 /* The first entry in a procedure linkage table looks like
1910 this. It is set up so that any shared library function that is
1911 called before the relocation has been set up calls the dynamic
1912 linker first. */
1913 static const bfd_vma elf32_arm_plt0_entry [] =
1914 {
1915 0xe52de004, /* str lr, [sp, #-4]! */
1916 0xe59fe010, /* ldr lr, [pc, #16] */
1917 0xe08fe00e, /* add lr, pc, lr */
1918 0xe5bef008, /* ldr pc, [lr, #8]! */
1919 };
1920
1921 /* Subsequent entries in a procedure linkage table look like
1922 this. */
1923 static const bfd_vma elf32_arm_plt_entry [] =
1924 {
1925 0xe28fc600, /* add ip, pc, #NN */
1926 0xe28cca00, /* add ip, ip, #NN */
1927 0xe5bcf000, /* ldr pc, [ip, #NN]! */
1928 0x00000000, /* unused */
1929 };
1930
1931 #else
1932
1933 /* The first entry in a procedure linkage table looks like
1934 this. It is set up so that any shared library function that is
1935 called before the relocation has been set up calls the dynamic
1936 linker first. */
1937 static const bfd_vma elf32_arm_plt0_entry [] =
1938 {
1939 0xe52de004, /* str lr, [sp, #-4]! */
1940 0xe59fe004, /* ldr lr, [pc, #4] */
1941 0xe08fe00e, /* add lr, pc, lr */
1942 0xe5bef008, /* ldr pc, [lr, #8]! */
1943 0x00000000, /* &GOT[0] - . */
1944 };
1945
1946 /* Subsequent entries in a procedure linkage table look like
1947 this. */
1948 static const bfd_vma elf32_arm_plt_entry [] =
1949 {
1950 0xe28fc600, /* add ip, pc, #0xNN00000 */
1951 0xe28cca00, /* add ip, ip, #0xNN000 */
1952 0xe5bcf000, /* ldr pc, [ip, #0xNNN]! */
1953 };
1954
1955 #endif
1956
1957 /* The format of the first entry in the procedure linkage table
1958 for a VxWorks executable. */
1959 static const bfd_vma elf32_arm_vxworks_exec_plt0_entry[] =
1960 {
1961 0xe52dc008, /* str ip,[sp,#-8]! */
1962 0xe59fc000, /* ldr ip,[pc] */
1963 0xe59cf008, /* ldr pc,[ip,#8] */
1964 0x00000000, /* .long _GLOBAL_OFFSET_TABLE_ */
1965 };
1966
1967 /* The format of subsequent entries in a VxWorks executable. */
1968 static const bfd_vma elf32_arm_vxworks_exec_plt_entry[] =
1969 {
1970 0xe59fc000, /* ldr ip,[pc] */
1971 0xe59cf000, /* ldr pc,[ip] */
1972 0x00000000, /* .long @got */
1973 0xe59fc000, /* ldr ip,[pc] */
1974 0xea000000, /* b _PLT */
1975 0x00000000, /* .long @pltindex*sizeof(Elf32_Rela) */
1976 };
1977
1978 /* The format of entries in a VxWorks shared library. */
1979 static const bfd_vma elf32_arm_vxworks_shared_plt_entry[] =
1980 {
1981 0xe59fc000, /* ldr ip,[pc] */
1982 0xe79cf009, /* ldr pc,[ip,r9] */
1983 0x00000000, /* .long @got */
1984 0xe59fc000, /* ldr ip,[pc] */
1985 0xe599f008, /* ldr pc,[r9,#8] */
1986 0x00000000, /* .long @pltindex*sizeof(Elf32_Rela) */
1987 };
1988
1989 /* An initial stub used if the PLT entry is referenced from Thumb code. */
1990 #define PLT_THUMB_STUB_SIZE 4
1991 static const bfd_vma elf32_arm_plt_thumb_stub [] =
1992 {
1993 0x4778, /* bx pc */
1994 0x46c0 /* nop */
1995 };
1996
1997 /* The entries in a PLT when using a DLL-based target with multiple
1998 address spaces. */
1999 static const bfd_vma elf32_arm_symbian_plt_entry [] =
2000 {
2001 0xe51ff004, /* ldr pc, [pc, #-4] */
2002 0x00000000, /* dcd R_ARM_GLOB_DAT(X) */
2003 };
2004
2005 #define ARM_MAX_FWD_BRANCH_OFFSET ((((1 << 23) - 1) << 2) + 8)
2006 #define ARM_MAX_BWD_BRANCH_OFFSET ((-((1 << 23) << 2)) + 8)
2007 #define THM_MAX_FWD_BRANCH_OFFSET ((1 << 22) -2 + 4)
2008 #define THM_MAX_BWD_BRANCH_OFFSET (-(1 << 22) + 4)
2009 #define THM2_MAX_FWD_BRANCH_OFFSET (((1 << 24) - 2) + 4)
2010 #define THM2_MAX_BWD_BRANCH_OFFSET (-(1 << 24) + 4)
2011
2012 static const bfd_vma arm_long_branch_stub[] =
2013 {
2014 0xe51ff004, /* ldr pc, [pc, #-4] */
2015 0x00000000, /* dcd R_ARM_ABS32(X) */
2016 };
2017
2018 static const bfd_vma arm_thumb_v4t_long_branch_stub[] =
2019 {
2020 0xe59fc000, /* ldr ip, [pc, #0] */
2021 0xe12fff1c, /* bx ip */
2022 0x00000000, /* dcd R_ARM_ABS32(X) */
2023 };
2024
2025 static const bfd_vma arm_thumb_thumb_long_branch_stub[] =
2026 {
2027 0x4e02b540, /* push {r6, lr} */
2028 /* ldr r6, [pc, #8] */
2029 0x473046fe, /* mov lr, pc */
2030 /* bx r6 */
2031 0xbf00bd40, /* pop {r6, pc} */
2032 /* nop */
2033 0x00000000, /* dcd R_ARM_ABS32(X) */
2034 };
2035
2036 static const bfd_vma arm_thumb_arm_v4t_long_branch_stub[] =
2037 {
2038 0x4e03b540, /* push {r6, lr} */
2039 /* ldr r6, [pc, #12] */
2040 0x473046fe, /* mov lr, pc */
2041 /* bx r6 */
2042 0xe8bd4040, /* pop {r6, pc} */
2043 0xe12fff1e, /* bx lr */
2044 0x00000000, /* dcd R_ARM_ABS32(X) */
2045 };
2046
2047 static const bfd_vma arm_pic_long_branch_stub[] =
2048 {
2049 0xe59fc000, /* ldr r12, [pc] */
2050 0xe08ff00c, /* add pc, pc, ip */
2051 0x00000000, /* dcd R_ARM_REL32(X) */
2052 };
2053
2054 /* Section name for stubs is the associated section name plus this
2055 string. */
2056 #define STUB_SUFFIX ".stub"
2057
2058 enum elf32_arm_stub_type
2059 {
2060 arm_stub_none,
2061 arm_stub_long_branch,
2062 arm_thumb_v4t_stub_long_branch,
2063 arm_thumb_thumb_stub_long_branch,
2064 arm_thumb_arm_v4t_stub_long_branch,
2065 arm_stub_pic_long_branch,
2066 };
2067
2068 struct elf32_arm_stub_hash_entry
2069 {
2070 /* Base hash table entry structure. */
2071 struct bfd_hash_entry root;
2072
2073 /* The stub section. */
2074 asection *stub_sec;
2075
2076 /* Offset within stub_sec of the beginning of this stub. */
2077 bfd_vma stub_offset;
2078
2079 /* Given the symbol's value and its section we can determine its final
2080 value when building the stubs (so the stub knows where to jump). */
2081 bfd_vma target_value;
2082 asection *target_section;
2083
2084 enum elf32_arm_stub_type stub_type;
2085
2086 /* The symbol table entry, if any, that this was derived from. */
2087 struct elf32_arm_link_hash_entry *h;
2088
2089 /* Destination symbol type (STT_ARM_TFUNC, ...) */
2090 unsigned char st_type;
2091
2092 /* Where this stub is being called from, or, in the case of combined
2093 stub sections, the first input section in the group. */
2094 asection *id_sec;
2095
2096 /* The name for the local symbol at the start of this stub. The
2097 stub name in the hash table has to be unique; this does not, so
2098 it can be friendlier. */
2099 char *output_name;
2100 };
2101
2102 /* Used to build a map of a section. This is required for mixed-endian
2103 code/data. */
2104
2105 typedef struct elf32_elf_section_map
2106 {
2107 bfd_vma vma;
2108 char type;
2109 }
2110 elf32_arm_section_map;
2111
2112 /* Information about a VFP11 erratum veneer, or a branch to such a veneer. */
2113
2114 typedef enum
2115 {
2116 VFP11_ERRATUM_BRANCH_TO_ARM_VENEER,
2117 VFP11_ERRATUM_BRANCH_TO_THUMB_VENEER,
2118 VFP11_ERRATUM_ARM_VENEER,
2119 VFP11_ERRATUM_THUMB_VENEER
2120 }
2121 elf32_vfp11_erratum_type;
2122
2123 typedef struct elf32_vfp11_erratum_list
2124 {
2125 struct elf32_vfp11_erratum_list *next;
2126 bfd_vma vma;
2127 union
2128 {
2129 struct
2130 {
2131 struct elf32_vfp11_erratum_list *veneer;
2132 unsigned int vfp_insn;
2133 } b;
2134 struct
2135 {
2136 struct elf32_vfp11_erratum_list *branch;
2137 unsigned int id;
2138 } v;
2139 } u;
2140 elf32_vfp11_erratum_type type;
2141 }
2142 elf32_vfp11_erratum_list;
2143
2144 typedef struct _arm_elf_section_data
2145 {
2146 struct bfd_elf_section_data elf;
2147 unsigned int mapcount;
2148 unsigned int mapsize;
2149 elf32_arm_section_map *map;
2150 unsigned int erratumcount;
2151 elf32_vfp11_erratum_list *erratumlist;
2152 }
2153 _arm_elf_section_data;
2154
2155 #define elf32_arm_section_data(sec) \
2156 ((_arm_elf_section_data *) elf_section_data (sec))
2157
2158 /* The size of the thread control block. */
2159 #define TCB_SIZE 8
2160
2161 struct elf_arm_obj_tdata
2162 {
2163 struct elf_obj_tdata root;
2164
2165 /* tls_type for each local got entry. */
2166 char *local_got_tls_type;
2167
2168 /* Zero to warn when linking objects with incompatible enum sizes. */
2169 int no_enum_size_warning;
2170
2171 /* Zero to warn when linking objects with incompatible wchar_t sizes. */
2172 int no_wchar_size_warning;
2173 };
2174
2175 #define elf_arm_tdata(bfd) \
2176 ((struct elf_arm_obj_tdata *) (bfd)->tdata.any)
2177
2178 #define elf32_arm_local_got_tls_type(bfd) \
2179 (elf_arm_tdata (bfd)->local_got_tls_type)
2180
2181 #define is_arm_elf(bfd) \
2182 (bfd_get_flavour (bfd) == bfd_target_elf_flavour \
2183 && elf_tdata (bfd) != NULL \
2184 && elf_object_id (bfd) == ARM_ELF_TDATA)
2185
2186 static bfd_boolean
2187 elf32_arm_mkobject (bfd *abfd)
2188 {
2189 return bfd_elf_allocate_object (abfd, sizeof (struct elf_arm_obj_tdata),
2190 ARM_ELF_TDATA);
2191 }
2192
2193 /* The ARM linker needs to keep track of the number of relocs that it
2194 decides to copy in check_relocs for each symbol. This is so that
2195 it can discard PC relative relocs if it doesn't need them when
2196 linking with -Bsymbolic. We store the information in a field
2197 extending the regular ELF linker hash table. */
2198
2199 /* This structure keeps track of the number of relocs we have copied
2200 for a given symbol. */
2201 struct elf32_arm_relocs_copied
2202 {
2203 /* Next section. */
2204 struct elf32_arm_relocs_copied * next;
2205 /* A section in dynobj. */
2206 asection * section;
2207 /* Number of relocs copied in this section. */
2208 bfd_size_type count;
2209 /* Number of PC-relative relocs copied in this section. */
2210 bfd_size_type pc_count;
2211 };
2212
2213 #define elf32_arm_hash_entry(ent) ((struct elf32_arm_link_hash_entry *)(ent))
2214
2215 /* Arm ELF linker hash entry. */
2216 struct elf32_arm_link_hash_entry
2217 {
2218 struct elf_link_hash_entry root;
2219
2220 /* Number of PC relative relocs copied for this symbol. */
2221 struct elf32_arm_relocs_copied * relocs_copied;
2222
2223 /* We reference count Thumb references to a PLT entry separately,
2224 so that we can emit the Thumb trampoline only if needed. */
2225 bfd_signed_vma plt_thumb_refcount;
2226
2227 /* Some references from Thumb code may be eliminated by BL->BLX
2228 conversion, so record them separately. */
2229 bfd_signed_vma plt_maybe_thumb_refcount;
2230
2231 /* Since PLT entries have variable size if the Thumb prologue is
2232 used, we need to record the index into .got.plt instead of
2233 recomputing it from the PLT offset. */
2234 bfd_signed_vma plt_got_offset;
2235
2236 #define GOT_UNKNOWN 0
2237 #define GOT_NORMAL 1
2238 #define GOT_TLS_GD 2
2239 #define GOT_TLS_IE 4
2240 unsigned char tls_type;
2241
2242 /* The symbol marking the real symbol location for exported thumb
2243 symbols with Arm stubs. */
2244 struct elf_link_hash_entry *export_glue;
2245
2246 /* A pointer to the most recently used stub hash entry against this
2247 symbol. */
2248 struct elf32_arm_stub_hash_entry *stub_cache;
2249 };
2250
2251 /* Traverse an arm ELF linker hash table. */
2252 #define elf32_arm_link_hash_traverse(table, func, info) \
2253 (elf_link_hash_traverse \
2254 (&(table)->root, \
2255 (bfd_boolean (*) (struct elf_link_hash_entry *, void *)) (func), \
2256 (info)))
2257
2258 /* Get the ARM elf linker hash table from a link_info structure. */
2259 #define elf32_arm_hash_table(info) \
2260 ((struct elf32_arm_link_hash_table *) ((info)->hash))
2261
2262 #define arm_stub_hash_lookup(table, string, create, copy) \
2263 ((struct elf32_arm_stub_hash_entry *) \
2264 bfd_hash_lookup ((table), (string), (create), (copy)))
2265
2266 /* ARM ELF linker hash table. */
2267 struct elf32_arm_link_hash_table
2268 {
2269 /* The main hash table. */
2270 struct elf_link_hash_table root;
2271
2272 /* The size in bytes of the section containing the Thumb-to-ARM glue. */
2273 bfd_size_type thumb_glue_size;
2274
2275 /* The size in bytes of the section containing the ARM-to-Thumb glue. */
2276 bfd_size_type arm_glue_size;
2277
2278 /* The size in bytes of section containing the ARMv4 BX veneers. */
2279 bfd_size_type bx_glue_size;
2280
2281 /* Offsets of ARMv4 BX veneers. Bit1 set if present, and Bit0 set when
2282 veneer has been populated. */
2283 bfd_vma bx_glue_offset[15];
2284
2285 /* The size in bytes of the section containing glue for VFP11 erratum
2286 veneers. */
2287 bfd_size_type vfp11_erratum_glue_size;
2288
2289 /* An arbitrary input BFD chosen to hold the glue sections. */
2290 bfd * bfd_of_glue_owner;
2291
2292 /* Nonzero to output a BE8 image. */
2293 int byteswap_code;
2294
2295 /* Zero if R_ARM_TARGET1 means R_ARM_ABS32.
2296 Nonzero if R_ARM_TARGET1 means R_ARM_REL32. */
2297 int target1_is_rel;
2298
2299 /* The relocation to use for R_ARM_TARGET2 relocations. */
2300 int target2_reloc;
2301
2302 /* 0 = Ignore R_ARM_V4BX.
2303 1 = Convert BX to MOV PC.
2304 2 = Generate v4 interworing stubs. */
2305 int fix_v4bx;
2306
2307 /* Nonzero if the ARM/Thumb BLX instructions are available for use. */
2308 int use_blx;
2309
2310 /* What sort of code sequences we should look for which may trigger the
2311 VFP11 denorm erratum. */
2312 bfd_arm_vfp11_fix vfp11_fix;
2313
2314 /* Global counter for the number of fixes we have emitted. */
2315 int num_vfp11_fixes;
2316
2317 /* Nonzero to force PIC branch veneers. */
2318 int pic_veneer;
2319
2320 /* The number of bytes in the initial entry in the PLT. */
2321 bfd_size_type plt_header_size;
2322
2323 /* The number of bytes in the subsequent PLT etries. */
2324 bfd_size_type plt_entry_size;
2325
2326 /* True if the target system is VxWorks. */
2327 int vxworks_p;
2328
2329 /* True if the target system is Symbian OS. */
2330 int symbian_p;
2331
2332 /* True if the target uses REL relocations. */
2333 int use_rel;
2334
2335 /* Short-cuts to get to dynamic linker sections. */
2336 asection *sgot;
2337 asection *sgotplt;
2338 asection *srelgot;
2339 asection *splt;
2340 asection *srelplt;
2341 asection *sdynbss;
2342 asection *srelbss;
2343
2344 /* The (unloaded but important) VxWorks .rela.plt.unloaded section. */
2345 asection *srelplt2;
2346
2347 /* Data for R_ARM_TLS_LDM32 relocations. */
2348 union
2349 {
2350 bfd_signed_vma refcount;
2351 bfd_vma offset;
2352 } tls_ldm_got;
2353
2354 /* Small local sym to section mapping cache. */
2355 struct sym_sec_cache sym_sec;
2356
2357 /* For convenience in allocate_dynrelocs. */
2358 bfd * obfd;
2359
2360 /* The stub hash table. */
2361 struct bfd_hash_table stub_hash_table;
2362
2363 /* Linker stub bfd. */
2364 bfd *stub_bfd;
2365
2366 /* Linker call-backs. */
2367 asection * (*add_stub_section) (const char *, asection *);
2368 void (*layout_sections_again) (void);
2369
2370 /* Array to keep track of which stub sections have been created, and
2371 information on stub grouping. */
2372 struct map_stub
2373 {
2374 /* This is the section to which stubs in the group will be
2375 attached. */
2376 asection *link_sec;
2377 /* The stub section. */
2378 asection *stub_sec;
2379 } *stub_group;
2380
2381 /* Assorted information used by elf32_arm_size_stubs. */
2382 unsigned int bfd_count;
2383 int top_index;
2384 asection **input_list;
2385 };
2386
2387 /* Create an entry in an ARM ELF linker hash table. */
2388
2389 static struct bfd_hash_entry *
2390 elf32_arm_link_hash_newfunc (struct bfd_hash_entry * entry,
2391 struct bfd_hash_table * table,
2392 const char * string)
2393 {
2394 struct elf32_arm_link_hash_entry * ret =
2395 (struct elf32_arm_link_hash_entry *) entry;
2396
2397 /* Allocate the structure if it has not already been allocated by a
2398 subclass. */
2399 if (ret == NULL)
2400 ret = bfd_hash_allocate (table, sizeof (struct elf32_arm_link_hash_entry));
2401 if (ret == NULL)
2402 return (struct bfd_hash_entry *) ret;
2403
2404 /* Call the allocation method of the superclass. */
2405 ret = ((struct elf32_arm_link_hash_entry *)
2406 _bfd_elf_link_hash_newfunc ((struct bfd_hash_entry *) ret,
2407 table, string));
2408 if (ret != NULL)
2409 {
2410 ret->relocs_copied = NULL;
2411 ret->tls_type = GOT_UNKNOWN;
2412 ret->plt_thumb_refcount = 0;
2413 ret->plt_maybe_thumb_refcount = 0;
2414 ret->plt_got_offset = -1;
2415 ret->export_glue = NULL;
2416
2417 ret->stub_cache = NULL;
2418 }
2419
2420 return (struct bfd_hash_entry *) ret;
2421 }
2422
2423 /* Initialize an entry in the stub hash table. */
2424
2425 static struct bfd_hash_entry *
2426 stub_hash_newfunc (struct bfd_hash_entry *entry,
2427 struct bfd_hash_table *table,
2428 const char *string)
2429 {
2430 /* Allocate the structure if it has not already been allocated by a
2431 subclass. */
2432 if (entry == NULL)
2433 {
2434 entry = bfd_hash_allocate (table,
2435 sizeof (struct elf32_arm_stub_hash_entry));
2436 if (entry == NULL)
2437 return entry;
2438 }
2439
2440 /* Call the allocation method of the superclass. */
2441 entry = bfd_hash_newfunc (entry, table, string);
2442 if (entry != NULL)
2443 {
2444 struct elf32_arm_stub_hash_entry *eh;
2445
2446 /* Initialize the local fields. */
2447 eh = (struct elf32_arm_stub_hash_entry *) entry;
2448 eh->stub_sec = NULL;
2449 eh->stub_offset = 0;
2450 eh->target_value = 0;
2451 eh->target_section = NULL;
2452 eh->stub_type = arm_stub_none;
2453 eh->h = NULL;
2454 eh->id_sec = NULL;
2455 }
2456
2457 return entry;
2458 }
2459
2460 /* Return true if NAME is the name of the relocation section associated
2461 with S. */
2462
2463 static bfd_boolean
2464 reloc_section_p (struct elf32_arm_link_hash_table *htab,
2465 const char *name, asection *s)
2466 {
2467 if (htab->use_rel)
2468 return CONST_STRNEQ (name, ".rel") && strcmp (s->name, name + 4) == 0;
2469 else
2470 return CONST_STRNEQ (name, ".rela") && strcmp (s->name, name + 5) == 0;
2471 }
2472
2473 /* Create .got, .gotplt, and .rel(a).got sections in DYNOBJ, and set up
2474 shortcuts to them in our hash table. */
2475
2476 static bfd_boolean
2477 create_got_section (bfd *dynobj, struct bfd_link_info *info)
2478 {
2479 struct elf32_arm_link_hash_table *htab;
2480
2481 htab = elf32_arm_hash_table (info);
2482 /* BPABI objects never have a GOT, or associated sections. */
2483 if (htab->symbian_p)
2484 return TRUE;
2485
2486 if (! _bfd_elf_create_got_section (dynobj, info))
2487 return FALSE;
2488
2489 htab->sgot = bfd_get_section_by_name (dynobj, ".got");
2490 htab->sgotplt = bfd_get_section_by_name (dynobj, ".got.plt");
2491 if (!htab->sgot || !htab->sgotplt)
2492 abort ();
2493
2494 htab->srelgot = bfd_make_section_with_flags (dynobj,
2495 RELOC_SECTION (htab, ".got"),
2496 (SEC_ALLOC | SEC_LOAD
2497 | SEC_HAS_CONTENTS
2498 | SEC_IN_MEMORY
2499 | SEC_LINKER_CREATED
2500 | SEC_READONLY));
2501 if (htab->srelgot == NULL
2502 || ! bfd_set_section_alignment (dynobj, htab->srelgot, 2))
2503 return FALSE;
2504 return TRUE;
2505 }
2506
2507 /* Create .plt, .rel(a).plt, .got, .got.plt, .rel(a).got, .dynbss, and
2508 .rel(a).bss sections in DYNOBJ, and set up shortcuts to them in our
2509 hash table. */
2510
2511 static bfd_boolean
2512 elf32_arm_create_dynamic_sections (bfd *dynobj, struct bfd_link_info *info)
2513 {
2514 struct elf32_arm_link_hash_table *htab;
2515
2516 htab = elf32_arm_hash_table (info);
2517 if (!htab->sgot && !create_got_section (dynobj, info))
2518 return FALSE;
2519
2520 if (!_bfd_elf_create_dynamic_sections (dynobj, info))
2521 return FALSE;
2522
2523 htab->splt = bfd_get_section_by_name (dynobj, ".plt");
2524 htab->srelplt = bfd_get_section_by_name (dynobj,
2525 RELOC_SECTION (htab, ".plt"));
2526 htab->sdynbss = bfd_get_section_by_name (dynobj, ".dynbss");
2527 if (!info->shared)
2528 htab->srelbss = bfd_get_section_by_name (dynobj,
2529 RELOC_SECTION (htab, ".bss"));
2530
2531 if (htab->vxworks_p)
2532 {
2533 if (!elf_vxworks_create_dynamic_sections (dynobj, info, &htab->srelplt2))
2534 return FALSE;
2535
2536 if (info->shared)
2537 {
2538 htab->plt_header_size = 0;
2539 htab->plt_entry_size
2540 = 4 * ARRAY_SIZE (elf32_arm_vxworks_shared_plt_entry);
2541 }
2542 else
2543 {
2544 htab->plt_header_size
2545 = 4 * ARRAY_SIZE (elf32_arm_vxworks_exec_plt0_entry);
2546 htab->plt_entry_size
2547 = 4 * ARRAY_SIZE (elf32_arm_vxworks_exec_plt_entry);
2548 }
2549 }
2550
2551 if (!htab->splt
2552 || !htab->srelplt
2553 || !htab->sdynbss
2554 || (!info->shared && !htab->srelbss))
2555 abort ();
2556
2557 return TRUE;
2558 }
2559
2560 /* Copy the extra info we tack onto an elf_link_hash_entry. */
2561
2562 static void
2563 elf32_arm_copy_indirect_symbol (struct bfd_link_info *info,
2564 struct elf_link_hash_entry *dir,
2565 struct elf_link_hash_entry *ind)
2566 {
2567 struct elf32_arm_link_hash_entry *edir, *eind;
2568
2569 edir = (struct elf32_arm_link_hash_entry *) dir;
2570 eind = (struct elf32_arm_link_hash_entry *) ind;
2571
2572 if (eind->relocs_copied != NULL)
2573 {
2574 if (edir->relocs_copied != NULL)
2575 {
2576 struct elf32_arm_relocs_copied **pp;
2577 struct elf32_arm_relocs_copied *p;
2578
2579 /* Add reloc counts against the indirect sym to the direct sym
2580 list. Merge any entries against the same section. */
2581 for (pp = &eind->relocs_copied; (p = *pp) != NULL; )
2582 {
2583 struct elf32_arm_relocs_copied *q;
2584
2585 for (q = edir->relocs_copied; q != NULL; q = q->next)
2586 if (q->section == p->section)
2587 {
2588 q->pc_count += p->pc_count;
2589 q->count += p->count;
2590 *pp = p->next;
2591 break;
2592 }
2593 if (q == NULL)
2594 pp = &p->next;
2595 }
2596 *pp = edir->relocs_copied;
2597 }
2598
2599 edir->relocs_copied = eind->relocs_copied;
2600 eind->relocs_copied = NULL;
2601 }
2602
2603 if (ind->root.type == bfd_link_hash_indirect)
2604 {
2605 /* Copy over PLT info. */
2606 edir->plt_thumb_refcount += eind->plt_thumb_refcount;
2607 eind->plt_thumb_refcount = 0;
2608 edir->plt_maybe_thumb_refcount += eind->plt_maybe_thumb_refcount;
2609 eind->plt_maybe_thumb_refcount = 0;
2610
2611 if (dir->got.refcount <= 0)
2612 {
2613 edir->tls_type = eind->tls_type;
2614 eind->tls_type = GOT_UNKNOWN;
2615 }
2616 }
2617
2618 _bfd_elf_link_hash_copy_indirect (info, dir, ind);
2619 }
2620
2621 /* Create an ARM elf linker hash table. */
2622
2623 static struct bfd_link_hash_table *
2624 elf32_arm_link_hash_table_create (bfd *abfd)
2625 {
2626 struct elf32_arm_link_hash_table *ret;
2627 bfd_size_type amt = sizeof (struct elf32_arm_link_hash_table);
2628
2629 ret = bfd_malloc (amt);
2630 if (ret == NULL)
2631 return NULL;
2632
2633 if (!_bfd_elf_link_hash_table_init (& ret->root, abfd,
2634 elf32_arm_link_hash_newfunc,
2635 sizeof (struct elf32_arm_link_hash_entry)))
2636 {
2637 free (ret);
2638 return NULL;
2639 }
2640
2641 ret->sgot = NULL;
2642 ret->sgotplt = NULL;
2643 ret->srelgot = NULL;
2644 ret->splt = NULL;
2645 ret->srelplt = NULL;
2646 ret->sdynbss = NULL;
2647 ret->srelbss = NULL;
2648 ret->srelplt2 = NULL;
2649 ret->thumb_glue_size = 0;
2650 ret->arm_glue_size = 0;
2651 ret->bx_glue_size = 0;
2652 memset (ret->bx_glue_offset, 0, sizeof (ret->bx_glue_offset));
2653 ret->vfp11_fix = BFD_ARM_VFP11_FIX_NONE;
2654 ret->vfp11_erratum_glue_size = 0;
2655 ret->num_vfp11_fixes = 0;
2656 ret->bfd_of_glue_owner = NULL;
2657 ret->byteswap_code = 0;
2658 ret->target1_is_rel = 0;
2659 ret->target2_reloc = R_ARM_NONE;
2660 #ifdef FOUR_WORD_PLT
2661 ret->plt_header_size = 16;
2662 ret->plt_entry_size = 16;
2663 #else
2664 ret->plt_header_size = 20;
2665 ret->plt_entry_size = 12;
2666 #endif
2667 ret->fix_v4bx = 0;
2668 ret->use_blx = 0;
2669 ret->vxworks_p = 0;
2670 ret->symbian_p = 0;
2671 ret->use_rel = 1;
2672 ret->sym_sec.abfd = NULL;
2673 ret->obfd = abfd;
2674 ret->tls_ldm_got.refcount = 0;
2675 ret->stub_bfd = NULL;
2676 ret->add_stub_section = NULL;
2677 ret->layout_sections_again = NULL;
2678 ret->stub_group = NULL;
2679 ret->bfd_count = 0;
2680 ret->top_index = 0;
2681 ret->input_list = NULL;
2682
2683 if (!bfd_hash_table_init (&ret->stub_hash_table, stub_hash_newfunc,
2684 sizeof (struct elf32_arm_stub_hash_entry)))
2685 {
2686 free (ret);
2687 return NULL;
2688 }
2689
2690 return &ret->root.root;
2691 }
2692
2693 /* Free the derived linker hash table. */
2694
2695 static void
2696 elf32_arm_hash_table_free (struct bfd_link_hash_table *hash)
2697 {
2698 struct elf32_arm_link_hash_table *ret
2699 = (struct elf32_arm_link_hash_table *) hash;
2700
2701 bfd_hash_table_free (&ret->stub_hash_table);
2702 _bfd_generic_link_hash_table_free (hash);
2703 }
2704
2705 /* Determine if we're dealing with a Thumb only architecture. */
2706
2707 static bfd_boolean
2708 using_thumb_only (struct elf32_arm_link_hash_table *globals)
2709 {
2710 int arch = bfd_elf_get_obj_attr_int (globals->obfd, OBJ_ATTR_PROC,
2711 Tag_CPU_arch);
2712 int profile;
2713
2714 if (arch != TAG_CPU_ARCH_V7)
2715 return FALSE;
2716
2717 profile = bfd_elf_get_obj_attr_int (globals->obfd, OBJ_ATTR_PROC,
2718 Tag_CPU_arch_profile);
2719
2720 return profile == 'M';
2721 }
2722
2723 /* Determine if we're dealing with a Thumb-2 object. */
2724
2725 static bfd_boolean
2726 using_thumb2 (struct elf32_arm_link_hash_table *globals)
2727 {
2728 int arch = bfd_elf_get_obj_attr_int (globals->obfd, OBJ_ATTR_PROC,
2729 Tag_CPU_arch);
2730 return arch == TAG_CPU_ARCH_V6T2 || arch >= TAG_CPU_ARCH_V7;
2731 }
2732
2733 static bfd_boolean
2734 arm_stub_is_thumb (enum elf32_arm_stub_type stub_type)
2735 {
2736 switch (stub_type)
2737 {
2738 case arm_thumb_thumb_stub_long_branch:
2739 case arm_thumb_arm_v4t_stub_long_branch:
2740 return TRUE;
2741 case arm_stub_none:
2742 BFD_FAIL ();
2743 return FALSE;
2744 break;
2745 default:
2746 return FALSE;
2747 }
2748 }
2749
2750 /* Determine the type of stub needed, if any, for a call. */
2751
2752 static enum elf32_arm_stub_type
2753 arm_type_of_stub (struct bfd_link_info *info,
2754 asection *input_sec,
2755 const Elf_Internal_Rela *rel,
2756 unsigned char st_type,
2757 struct elf32_arm_link_hash_entry *hash,
2758 bfd_vma destination)
2759 {
2760 bfd_vma location;
2761 bfd_signed_vma branch_offset;
2762 unsigned int r_type;
2763 struct elf32_arm_link_hash_table * globals;
2764 int thumb2;
2765 int thumb_only;
2766 enum elf32_arm_stub_type stub_type = arm_stub_none;
2767
2768 /* We don't know the actual type of destination in case it is of
2769 type STT_SECTION: give up */
2770 if (st_type == STT_SECTION)
2771 return stub_type;
2772
2773 globals = elf32_arm_hash_table (info);
2774
2775 thumb_only = using_thumb_only (globals);
2776
2777 thumb2 = using_thumb2 (globals);
2778
2779 /* Determine where the call point is. */
2780 location = (input_sec->output_offset
2781 + input_sec->output_section->vma
2782 + rel->r_offset);
2783
2784 branch_offset = (bfd_signed_vma)(destination - location);
2785
2786 r_type = ELF32_R_TYPE (rel->r_info);
2787
2788 /* If the call will go through a PLT entry then we do not need
2789 glue. */
2790 if (globals->splt != NULL && hash != NULL && hash->root.plt.offset != (bfd_vma) -1)
2791 return stub_type;
2792
2793 if (r_type == R_ARM_THM_CALL)
2794 {
2795 if ((!thumb2
2796 && (branch_offset > THM_MAX_FWD_BRANCH_OFFSET
2797 || (branch_offset < THM_MAX_BWD_BRANCH_OFFSET)))
2798 || (thumb2
2799 && (branch_offset > THM2_MAX_FWD_BRANCH_OFFSET
2800 || (branch_offset < THM2_MAX_BWD_BRANCH_OFFSET)))
2801 || ((st_type != STT_ARM_TFUNC) && !globals->use_blx))
2802 {
2803 if (st_type == STT_ARM_TFUNC)
2804 {
2805 /* Thumb to thumb. */
2806 if (!thumb_only)
2807 {
2808 stub_type = (info->shared | globals->pic_veneer)
2809 ? ((globals->use_blx)
2810 ? arm_stub_pic_long_branch
2811 : arm_stub_none)
2812 : (globals->use_blx)
2813 ? arm_stub_long_branch
2814 : arm_stub_none;
2815 }
2816 else
2817 {
2818 stub_type = (info->shared | globals->pic_veneer)
2819 ? arm_stub_none
2820 : (globals->use_blx)
2821 ? arm_thumb_thumb_stub_long_branch
2822 : arm_stub_none;
2823 }
2824 }
2825 else
2826 {
2827 /* Thumb to arm. */
2828 stub_type = (info->shared | globals->pic_veneer)
2829 ? ((globals->use_blx)
2830 ? arm_stub_pic_long_branch
2831 : arm_stub_none)
2832 : (globals->use_blx)
2833 ? arm_stub_long_branch
2834 : arm_thumb_arm_v4t_stub_long_branch;
2835 }
2836 }
2837 }
2838 else if (r_type == R_ARM_CALL)
2839 {
2840 if (st_type == STT_ARM_TFUNC)
2841 {
2842 /* Arm to thumb. */
2843 /* We have an extra 2-bytes reach because of the mode change
2844 (bit 24 (H) of BLX encoding). */
2845 if (branch_offset > (ARM_MAX_FWD_BRANCH_OFFSET + 2)
2846 || (branch_offset < ARM_MAX_BWD_BRANCH_OFFSET)
2847 || !globals->use_blx)
2848 {
2849 stub_type = (info->shared | globals->pic_veneer)
2850 ? arm_stub_pic_long_branch
2851 : (globals->use_blx)
2852 ? arm_stub_long_branch
2853 : arm_thumb_v4t_stub_long_branch;
2854 }
2855 }
2856 else
2857 {
2858 /* Arm to arm. */
2859 if (branch_offset > ARM_MAX_FWD_BRANCH_OFFSET
2860 || (branch_offset < ARM_MAX_BWD_BRANCH_OFFSET))
2861 {
2862 stub_type = (info->shared | globals->pic_veneer)
2863 ? arm_stub_pic_long_branch
2864 : arm_stub_long_branch;
2865 }
2866 }
2867 }
2868
2869 return stub_type;
2870 }
2871
2872 /* Build a name for an entry in the stub hash table. */
2873
2874 static char *
2875 elf32_arm_stub_name (const asection *input_section,
2876 const asection *sym_sec,
2877 const struct elf32_arm_link_hash_entry *hash,
2878 const Elf_Internal_Rela *rel)
2879 {
2880 char *stub_name;
2881 bfd_size_type len;
2882
2883 if (hash)
2884 {
2885 len = 8 + 1 + strlen (hash->root.root.root.string) + 1 + 8 + 1;
2886 stub_name = bfd_malloc (len);
2887 if (stub_name != NULL)
2888 sprintf (stub_name, "%08x_%s+%x",
2889 input_section->id & 0xffffffff,
2890 hash->root.root.root.string,
2891 (int) rel->r_addend & 0xffffffff);
2892 }
2893 else
2894 {
2895 len = 8 + 1 + 8 + 1 + 8 + 1 + 8 + 1;
2896 stub_name = bfd_malloc (len);
2897 if (stub_name != NULL)
2898 sprintf (stub_name, "%08x_%x:%x+%x",
2899 input_section->id & 0xffffffff,
2900 sym_sec->id & 0xffffffff,
2901 (int) ELF32_R_SYM (rel->r_info) & 0xffffffff,
2902 (int) rel->r_addend & 0xffffffff);
2903 }
2904
2905 return stub_name;
2906 }
2907
2908 /* Look up an entry in the stub hash. Stub entries are cached because
2909 creating the stub name takes a bit of time. */
2910
2911 static struct elf32_arm_stub_hash_entry *
2912 elf32_arm_get_stub_entry (const asection *input_section,
2913 const asection *sym_sec,
2914 struct elf_link_hash_entry *hash,
2915 const Elf_Internal_Rela *rel,
2916 struct elf32_arm_link_hash_table *htab)
2917 {
2918 struct elf32_arm_stub_hash_entry *stub_entry;
2919 struct elf32_arm_link_hash_entry *h = (struct elf32_arm_link_hash_entry *) hash;
2920 const asection *id_sec;
2921
2922 if ((input_section->flags & SEC_CODE) == 0)
2923 return NULL;
2924
2925 /* If this input section is part of a group of sections sharing one
2926 stub section, then use the id of the first section in the group.
2927 Stub names need to include a section id, as there may well be
2928 more than one stub used to reach say, printf, and we need to
2929 distinguish between them. */
2930 id_sec = htab->stub_group[input_section->id].link_sec;
2931
2932 if (h != NULL && h->stub_cache != NULL
2933 && h->stub_cache->h == h
2934 && h->stub_cache->id_sec == id_sec)
2935 {
2936 stub_entry = h->stub_cache;
2937 }
2938 else
2939 {
2940 char *stub_name;
2941
2942 stub_name = elf32_arm_stub_name (id_sec, sym_sec, h, rel);
2943 if (stub_name == NULL)
2944 return NULL;
2945
2946 stub_entry = arm_stub_hash_lookup (&htab->stub_hash_table,
2947 stub_name, FALSE, FALSE);
2948 if (h != NULL)
2949 h->stub_cache = stub_entry;
2950
2951 free (stub_name);
2952 }
2953
2954 return stub_entry;
2955 }
2956
2957 /* Add a new stub entry to the stub hash. Not all fields of the new
2958 stub entry are initialised. */
2959
2960 static struct elf32_arm_stub_hash_entry *
2961 elf32_arm_add_stub (const char *stub_name,
2962 asection *section,
2963 struct elf32_arm_link_hash_table *htab)
2964 {
2965 asection *link_sec;
2966 asection *stub_sec;
2967 struct elf32_arm_stub_hash_entry *stub_entry;
2968
2969 link_sec = htab->stub_group[section->id].link_sec;
2970 stub_sec = htab->stub_group[section->id].stub_sec;
2971 if (stub_sec == NULL)
2972 {
2973 stub_sec = htab->stub_group[link_sec->id].stub_sec;
2974 if (stub_sec == NULL)
2975 {
2976 size_t namelen;
2977 bfd_size_type len;
2978 char *s_name;
2979
2980 namelen = strlen (link_sec->name);
2981 len = namelen + sizeof (STUB_SUFFIX);
2982 s_name = bfd_alloc (htab->stub_bfd, len);
2983 if (s_name == NULL)
2984 return NULL;
2985
2986 memcpy (s_name, link_sec->name, namelen);
2987 memcpy (s_name + namelen, STUB_SUFFIX, sizeof (STUB_SUFFIX));
2988 stub_sec = (*htab->add_stub_section) (s_name, link_sec);
2989 if (stub_sec == NULL)
2990 return NULL;
2991 htab->stub_group[link_sec->id].stub_sec = stub_sec;
2992 }
2993 htab->stub_group[section->id].stub_sec = stub_sec;
2994 }
2995
2996 /* Enter this entry into the linker stub hash table. */
2997 stub_entry = arm_stub_hash_lookup (&htab->stub_hash_table, stub_name,
2998 TRUE, FALSE);
2999 if (stub_entry == NULL)
3000 {
3001 (*_bfd_error_handler) (_("%s: cannot create stub entry %s"),
3002 section->owner,
3003 stub_name);
3004 return NULL;
3005 }
3006
3007 stub_entry->stub_sec = stub_sec;
3008 stub_entry->stub_offset = 0;
3009 stub_entry->id_sec = link_sec;
3010
3011 return stub_entry;
3012 }
3013
3014 /* Store an Arm insn into an output section not processed by
3015 elf32_arm_write_section. */
3016
3017 static void
3018 put_arm_insn (struct elf32_arm_link_hash_table *htab,
3019 bfd * output_bfd, bfd_vma val, void * ptr)
3020 {
3021 if (htab->byteswap_code != bfd_little_endian (output_bfd))
3022 bfd_putl32 (val, ptr);
3023 else
3024 bfd_putb32 (val, ptr);
3025 }
3026
3027 /* Store a 16-bit Thumb insn into an output section not processed by
3028 elf32_arm_write_section. */
3029
3030 static void
3031 put_thumb_insn (struct elf32_arm_link_hash_table *htab,
3032 bfd * output_bfd, bfd_vma val, void * ptr)
3033 {
3034 if (htab->byteswap_code != bfd_little_endian (output_bfd))
3035 bfd_putl16 (val, ptr);
3036 else
3037 bfd_putb16 (val, ptr);
3038 }
3039
3040 static bfd_boolean
3041 arm_build_one_stub (struct bfd_hash_entry *gen_entry,
3042 void * in_arg)
3043 {
3044 struct elf32_arm_stub_hash_entry *stub_entry;
3045 struct bfd_link_info *info;
3046 struct elf32_arm_link_hash_table *htab;
3047 asection *stub_sec;
3048 bfd *stub_bfd;
3049 bfd_vma stub_addr;
3050 bfd_byte *loc;
3051 bfd_vma sym_value;
3052 int template_size;
3053 int size;
3054 const bfd_vma *template;
3055 int i;
3056 struct elf32_arm_link_hash_table * globals;
3057
3058 /* Massage our args to the form they really have. */
3059 stub_entry = (struct elf32_arm_stub_hash_entry *) gen_entry;
3060 info = (struct bfd_link_info *) in_arg;
3061
3062 globals = elf32_arm_hash_table (info);
3063
3064 htab = elf32_arm_hash_table (info);
3065 stub_sec = stub_entry->stub_sec;
3066
3067 /* Make a note of the offset within the stubs for this entry. */
3068 stub_entry->stub_offset = stub_sec->size;
3069 loc = stub_sec->contents + stub_entry->stub_offset;
3070
3071 stub_bfd = stub_sec->owner;
3072
3073 /* This is the address of the start of the stub. */
3074 stub_addr = stub_sec->output_section->vma + stub_sec->output_offset
3075 + stub_entry->stub_offset;
3076
3077 /* This is the address of the stub destination. */
3078 sym_value = (stub_entry->target_value
3079 + stub_entry->target_section->output_offset
3080 + stub_entry->target_section->output_section->vma);
3081
3082 switch (stub_entry->stub_type)
3083 {
3084 case arm_stub_long_branch:
3085 template = arm_long_branch_stub;
3086 template_size = (sizeof (arm_long_branch_stub) / sizeof (bfd_vma)) * 4;
3087 break;
3088 case arm_thumb_v4t_stub_long_branch:
3089 template = arm_thumb_v4t_long_branch_stub;
3090 template_size = (sizeof (arm_thumb_v4t_long_branch_stub) / sizeof (bfd_vma)) * 4;
3091 break;
3092 case arm_thumb_thumb_stub_long_branch:
3093 template = arm_thumb_thumb_long_branch_stub;
3094 template_size = (sizeof (arm_thumb_thumb_long_branch_stub) / sizeof (bfd_vma)) * 4;
3095 break;
3096 case arm_thumb_arm_v4t_stub_long_branch:
3097 template = arm_thumb_arm_v4t_long_branch_stub;
3098 template_size = (sizeof (arm_thumb_arm_v4t_long_branch_stub) / sizeof (bfd_vma)) * 4;
3099 break;
3100 case arm_stub_pic_long_branch:
3101 template = arm_pic_long_branch_stub;
3102 template_size = (sizeof (arm_pic_long_branch_stub) / sizeof (bfd_vma)) * 4;
3103 break;
3104 default:
3105 BFD_FAIL ();
3106 return FALSE;
3107 }
3108
3109 size = 0;
3110 for (i = 0; i < (template_size / 4); i++)
3111 {
3112 /* A 0 pattern is a placeholder, every other pattern is an
3113 instruction. */
3114 if (template[i] != 0)
3115 put_arm_insn (globals, stub_bfd, template[i], loc + size);
3116 else
3117 bfd_put_32 (stub_bfd, template[i], loc + size);
3118
3119 size += 4;
3120 }
3121 stub_sec->size += size;
3122
3123 /* Destination is Thumb. Force bit 0 to 1 to reflect this. */
3124 if (stub_entry->st_type == STT_ARM_TFUNC)
3125 sym_value |= 1;
3126
3127 switch (stub_entry->stub_type)
3128 {
3129 case arm_stub_long_branch:
3130 _bfd_final_link_relocate (elf32_arm_howto_from_type (R_ARM_ABS32),
3131 stub_bfd, stub_sec, stub_sec->contents,
3132 stub_entry->stub_offset + 4, sym_value, 0);
3133 break;
3134 case arm_thumb_v4t_stub_long_branch:
3135 _bfd_final_link_relocate (elf32_arm_howto_from_type (R_ARM_ABS32),
3136 stub_bfd, stub_sec, stub_sec->contents,
3137 stub_entry->stub_offset + 8, sym_value, 0);
3138 break;
3139 case arm_thumb_thumb_stub_long_branch:
3140 _bfd_final_link_relocate (elf32_arm_howto_from_type (R_ARM_ABS32),
3141 stub_bfd, stub_sec, stub_sec->contents,
3142 stub_entry->stub_offset + 12, sym_value, 0);
3143 break;
3144 case arm_thumb_arm_v4t_stub_long_branch:
3145 _bfd_final_link_relocate (elf32_arm_howto_from_type (R_ARM_ABS32),
3146 stub_bfd, stub_sec, stub_sec->contents,
3147 stub_entry->stub_offset + 16, sym_value, 0);
3148 break;
3149 case arm_stub_pic_long_branch:
3150 /* We want the value relative to the address 8 bytes from the
3151 start of the stub. */
3152 _bfd_final_link_relocate (elf32_arm_howto_from_type (R_ARM_REL32),
3153 stub_bfd, stub_sec, stub_sec->contents,
3154 stub_entry->stub_offset + 8, sym_value, 0);
3155 break;
3156 default:
3157 break;
3158 }
3159
3160 return TRUE;
3161 }
3162
3163 /* As above, but don't actually build the stub. Just bump offset so
3164 we know stub section sizes. */
3165
3166 static bfd_boolean
3167 arm_size_one_stub (struct bfd_hash_entry *gen_entry,
3168 void * in_arg)
3169 {
3170 struct elf32_arm_stub_hash_entry *stub_entry;
3171 struct elf32_arm_link_hash_table *htab;
3172 const bfd_vma *template;
3173 int template_size;
3174 int size;
3175 int i;
3176
3177 /* Massage our args to the form they really have. */
3178 stub_entry = (struct elf32_arm_stub_hash_entry *) gen_entry;
3179 htab = (struct elf32_arm_link_hash_table *) in_arg;
3180
3181 switch (stub_entry->stub_type)
3182 {
3183 case arm_stub_long_branch:
3184 template = arm_long_branch_stub;
3185 template_size = (sizeof (arm_long_branch_stub) / sizeof (bfd_vma)) * 4;
3186 break;
3187 case arm_thumb_v4t_stub_long_branch:
3188 template = arm_thumb_v4t_long_branch_stub;
3189 template_size = (sizeof (arm_thumb_v4t_long_branch_stub) / sizeof (bfd_vma)) * 4;
3190 break;
3191 case arm_thumb_thumb_stub_long_branch:
3192 template = arm_thumb_thumb_long_branch_stub;
3193 template_size = (sizeof (arm_thumb_thumb_long_branch_stub) / sizeof (bfd_vma)) * 4;
3194 break;
3195 case arm_thumb_arm_v4t_stub_long_branch:
3196 template = arm_thumb_arm_v4t_long_branch_stub;
3197 template_size = (sizeof (arm_thumb_arm_v4t_long_branch_stub) / sizeof (bfd_vma)) * 4;
3198 break;
3199 case arm_stub_pic_long_branch:
3200 template = arm_pic_long_branch_stub;
3201 template_size = (sizeof (arm_pic_long_branch_stub) / sizeof (bfd_vma)) * 4;
3202 break;
3203 default:
3204 BFD_FAIL ();
3205 return FALSE;
3206 break;
3207 }
3208
3209 size = 0;
3210 for (i = 0; i < (template_size / 4); i++)
3211 size += 4;
3212 size = (size + 7) & ~7;
3213 stub_entry->stub_sec->size += size;
3214 return TRUE;
3215 }
3216
3217 /* External entry points for sizing and building linker stubs. */
3218
3219 /* Set up various things so that we can make a list of input sections
3220 for each output section included in the link. Returns -1 on error,
3221 0 when no stubs will be needed, and 1 on success. */
3222
3223 int
3224 elf32_arm_setup_section_lists (bfd *output_bfd,
3225 struct bfd_link_info *info)
3226 {
3227 bfd *input_bfd;
3228 unsigned int bfd_count;
3229 int top_id, top_index;
3230 asection *section;
3231 asection **input_list, **list;
3232 bfd_size_type amt;
3233 struct elf32_arm_link_hash_table *htab = elf32_arm_hash_table (info);
3234
3235 if (! is_elf_hash_table (htab))
3236 return 0;
3237
3238 /* Count the number of input BFDs and find the top input section id. */
3239 for (input_bfd = info->input_bfds, bfd_count = 0, top_id = 0;
3240 input_bfd != NULL;
3241 input_bfd = input_bfd->link_next)
3242 {
3243 bfd_count += 1;
3244 for (section = input_bfd->sections;
3245 section != NULL;
3246 section = section->next)
3247 {
3248 if (top_id < section->id)
3249 top_id = section->id;
3250 }
3251 }
3252 htab->bfd_count = bfd_count;
3253
3254 amt = sizeof (struct map_stub) * (top_id + 1);
3255 htab->stub_group = bfd_zmalloc (amt);
3256 if (htab->stub_group == NULL)
3257 return -1;
3258
3259 /* We can't use output_bfd->section_count here to find the top output
3260 section index as some sections may have been removed, and
3261 _bfd_strip_section_from_output doesn't renumber the indices. */
3262 for (section = output_bfd->sections, top_index = 0;
3263 section != NULL;
3264 section = section->next)
3265 {
3266 if (top_index < section->index)
3267 top_index = section->index;
3268 }
3269
3270 htab->top_index = top_index;
3271 amt = sizeof (asection *) * (top_index + 1);
3272 input_list = bfd_malloc (amt);
3273 htab->input_list = input_list;
3274 if (input_list == NULL)
3275 return -1;
3276
3277 /* For sections we aren't interested in, mark their entries with a
3278 value we can check later. */
3279 list = input_list + top_index;
3280 do
3281 *list = bfd_abs_section_ptr;
3282 while (list-- != input_list);
3283
3284 for (section = output_bfd->sections;
3285 section != NULL;
3286 section = section->next)
3287 {
3288 if ((section->flags & SEC_CODE) != 0)
3289 input_list[section->index] = NULL;
3290 }
3291
3292 return 1;
3293 }
3294
3295 /* The linker repeatedly calls this function for each input section,
3296 in the order that input sections are linked into output sections.
3297 Build lists of input sections to determine groupings between which
3298 we may insert linker stubs. */
3299
3300 void
3301 elf32_arm_next_input_section (struct bfd_link_info *info,
3302 asection *isec)
3303 {
3304 struct elf32_arm_link_hash_table *htab = elf32_arm_hash_table (info);
3305
3306 if (isec->output_section->index <= htab->top_index)
3307 {
3308 asection **list = htab->input_list + isec->output_section->index;
3309
3310 if (*list != bfd_abs_section_ptr)
3311 {
3312 /* Steal the link_sec pointer for our list. */
3313 #define PREV_SEC(sec) (htab->stub_group[(sec)->id].link_sec)
3314 /* This happens to make the list in reverse order,
3315 which is what we want. */
3316 PREV_SEC (isec) = *list;
3317 *list = isec;
3318 }
3319 }
3320 }
3321
3322 /* See whether we can group stub sections together. Grouping stub
3323 sections may result in fewer stubs. More importantly, we need to
3324 put all .init* and .fini* stubs at the beginning of the .init or
3325 .fini output sections respectively, because glibc splits the
3326 _init and _fini functions into multiple parts. Putting a stub in
3327 the middle of a function is not a good idea. */
3328
3329 static void
3330 group_sections (struct elf32_arm_link_hash_table *htab,
3331 bfd_size_type stub_group_size,
3332 bfd_boolean stubs_always_before_branch)
3333 {
3334 asection **list = htab->input_list + htab->top_index;
3335
3336 do
3337 {
3338 asection *tail = *list;
3339
3340 if (tail == bfd_abs_section_ptr)
3341 continue;
3342
3343 while (tail != NULL)
3344 {
3345 asection *curr;
3346 asection *prev;
3347 bfd_size_type total;
3348
3349 curr = tail;
3350 total = tail->size;
3351 while ((prev = PREV_SEC (curr)) != NULL
3352 && ((total += curr->output_offset - prev->output_offset)
3353 < stub_group_size))
3354 curr = prev;
3355
3356 /* OK, the size from the start of CURR to the end is less
3357 than stub_group_size and thus can be handled by one stub
3358 section. (Or the tail section is itself larger than
3359 stub_group_size, in which case we may be toast.)
3360 We should really be keeping track of the total size of
3361 stubs added here, as stubs contribute to the final output
3362 section size. */
3363 do
3364 {
3365 prev = PREV_SEC (tail);
3366 /* Set up this stub group. */
3367 htab->stub_group[tail->id].link_sec = curr;
3368 }
3369 while (tail != curr && (tail = prev) != NULL);
3370
3371 /* But wait, there's more! Input sections up to stub_group_size
3372 bytes before the stub section can be handled by it too. */
3373 if (!stubs_always_before_branch)
3374 {
3375 total = 0;
3376 while (prev != NULL
3377 && ((total += tail->output_offset - prev->output_offset)
3378 < stub_group_size))
3379 {
3380 tail = prev;
3381 prev = PREV_SEC (tail);
3382 htab->stub_group[tail->id].link_sec = curr;
3383 }
3384 }
3385 tail = prev;
3386 }
3387 }
3388 while (list-- != htab->input_list);
3389
3390 free (htab->input_list);
3391 #undef PREV_SEC
3392 }
3393
3394 /* Determine and set the size of the stub section for a final link.
3395
3396 The basic idea here is to examine all the relocations looking for
3397 PC-relative calls to a target that is unreachable with a "bl"
3398 instruction. */
3399
3400 bfd_boolean
3401 elf32_arm_size_stubs (bfd *output_bfd,
3402 bfd *stub_bfd,
3403 struct bfd_link_info *info,
3404 bfd_signed_vma group_size,
3405 asection * (*add_stub_section) (const char *, asection *),
3406 void (*layout_sections_again) (void))
3407 {
3408 bfd_size_type stub_group_size;
3409 bfd_boolean stubs_always_before_branch;
3410 bfd_boolean stub_changed = 0;
3411 struct elf32_arm_link_hash_table *htab = elf32_arm_hash_table (info);
3412
3413 /* Propagate mach to stub bfd, because it may not have been
3414 finalized when we created stub_bfd. */
3415 bfd_set_arch_mach (stub_bfd, bfd_get_arch (output_bfd),
3416 bfd_get_mach (output_bfd));
3417
3418 /* Stash our params away. */
3419 htab->stub_bfd = stub_bfd;
3420 htab->add_stub_section = add_stub_section;
3421 htab->layout_sections_again = layout_sections_again;
3422 stubs_always_before_branch = group_size < 0;
3423 if (group_size < 0)
3424 stub_group_size = -group_size;
3425 else
3426 stub_group_size = group_size;
3427
3428 if (stub_group_size == 1)
3429 {
3430 /* Default values. */
3431 /* Thumb branch range is +-4MB has to be used as the default
3432 maximum size (a given section can contain both ARM and Thumb
3433 code, so the worst case has to be taken into account).
3434
3435 This value is 24K less than that, which allows for 2025
3436 12-byte stubs. If we exceed that, then we will fail to link.
3437 The user will have to relink with an explicit group size
3438 option. */
3439 stub_group_size = 4170000;
3440 }
3441
3442 group_sections (htab, stub_group_size, stubs_always_before_branch);
3443
3444 while (1)
3445 {
3446 bfd *input_bfd;
3447 unsigned int bfd_indx;
3448 asection *stub_sec;
3449
3450 for (input_bfd = info->input_bfds, bfd_indx = 0;
3451 input_bfd != NULL;
3452 input_bfd = input_bfd->link_next, bfd_indx++)
3453 {
3454 Elf_Internal_Shdr *symtab_hdr;
3455 asection *section;
3456 Elf_Internal_Sym *local_syms = NULL;
3457
3458 /* We'll need the symbol table in a second. */
3459 symtab_hdr = &elf_tdata (input_bfd)->symtab_hdr;
3460 if (symtab_hdr->sh_info == 0)
3461 continue;
3462
3463 /* Walk over each section attached to the input bfd. */
3464 for (section = input_bfd->sections;
3465 section != NULL;
3466 section = section->next)
3467 {
3468 Elf_Internal_Rela *internal_relocs, *irelaend, *irela;
3469
3470 /* If there aren't any relocs, then there's nothing more
3471 to do. */
3472 if ((section->flags & SEC_RELOC) == 0
3473 || section->reloc_count == 0
3474 || (section->flags & SEC_CODE) == 0)
3475 continue;
3476
3477 /* If this section is a link-once section that will be
3478 discarded, then don't create any stubs. */
3479 if (section->output_section == NULL
3480 || section->output_section->owner != output_bfd)
3481 continue;
3482
3483 /* Get the relocs. */
3484 internal_relocs
3485 = _bfd_elf_link_read_relocs (input_bfd, section, NULL,
3486 NULL, info->keep_memory);
3487 if (internal_relocs == NULL)
3488 goto error_ret_free_local;
3489
3490 /* Now examine each relocation. */
3491 irela = internal_relocs;
3492 irelaend = irela + section->reloc_count;
3493 for (; irela < irelaend; irela++)
3494 {
3495 unsigned int r_type, r_indx;
3496 enum elf32_arm_stub_type stub_type;
3497 struct elf32_arm_stub_hash_entry *stub_entry;
3498 asection *sym_sec;
3499 bfd_vma sym_value;
3500 bfd_vma destination;
3501 struct elf32_arm_link_hash_entry *hash;
3502 const char *sym_name;
3503 char *stub_name;
3504 const asection *id_sec;
3505 unsigned char st_type;
3506
3507 r_type = ELF32_R_TYPE (irela->r_info);
3508 r_indx = ELF32_R_SYM (irela->r_info);
3509
3510 if (r_type >= (unsigned int) R_ARM_max)
3511 {
3512 bfd_set_error (bfd_error_bad_value);
3513 error_ret_free_internal:
3514 if (elf_section_data (section)->relocs == NULL)
3515 free (internal_relocs);
3516 goto error_ret_free_local;
3517 }
3518
3519 /* Only look for stubs on call instructions. */
3520 if ((r_type != (unsigned int) R_ARM_CALL)
3521 && (r_type != (unsigned int) R_ARM_THM_CALL))
3522 continue;
3523
3524 /* Now determine the call target, its name, value,
3525 section. */
3526 sym_sec = NULL;
3527 sym_value = 0;
3528 destination = 0;
3529 hash = NULL;
3530 sym_name = NULL;
3531 if (r_indx < symtab_hdr->sh_info)
3532 {
3533 /* It's a local symbol. */
3534 Elf_Internal_Sym *sym;
3535 Elf_Internal_Shdr *hdr;
3536
3537 if (local_syms == NULL)
3538 {
3539 local_syms
3540 = (Elf_Internal_Sym *) symtab_hdr->contents;
3541 if (local_syms == NULL)
3542 local_syms
3543 = bfd_elf_get_elf_syms (input_bfd, symtab_hdr,
3544 symtab_hdr->sh_info, 0,
3545 NULL, NULL, NULL);
3546 if (local_syms == NULL)
3547 goto error_ret_free_internal;
3548 }
3549
3550 sym = local_syms + r_indx;
3551 hdr = elf_elfsections (input_bfd)[sym->st_shndx];
3552 sym_sec = hdr->bfd_section;
3553 if (ELF_ST_TYPE (sym->st_info) != STT_SECTION)
3554 sym_value = sym->st_value;
3555 destination = (sym_value + irela->r_addend
3556 + sym_sec->output_offset
3557 + sym_sec->output_section->vma);
3558 st_type = ELF_ST_TYPE (sym->st_info);
3559 sym_name
3560 = bfd_elf_string_from_elf_section (input_bfd,
3561 symtab_hdr->sh_link,
3562 sym->st_name);
3563 }
3564 else
3565 {
3566 /* It's an external symbol. */
3567 int e_indx;
3568
3569 e_indx = r_indx - symtab_hdr->sh_info;
3570 hash = ((struct elf32_arm_link_hash_entry *)
3571 elf_sym_hashes (input_bfd)[e_indx]);
3572
3573 while (hash->root.root.type == bfd_link_hash_indirect
3574 || hash->root.root.type == bfd_link_hash_warning)
3575 hash = ((struct elf32_arm_link_hash_entry *)
3576 hash->root.root.u.i.link);
3577
3578 if (hash->root.root.type == bfd_link_hash_defined
3579 || hash->root.root.type == bfd_link_hash_defweak)
3580 {
3581 sym_sec = hash->root.root.u.def.section;
3582 sym_value = hash->root.root.u.def.value;
3583 if (sym_sec->output_section != NULL)
3584 destination = (sym_value + irela->r_addend
3585 + sym_sec->output_offset
3586 + sym_sec->output_section->vma);
3587 }
3588 else if (hash->root.root.type == bfd_link_hash_undefweak
3589 || hash->root.root.type == bfd_link_hash_undefined)
3590 /* For a shared library, these will need a PLT stub,
3591 which is treated separately.
3592 For absolute code, they cannot be handled. */
3593 continue;
3594 else
3595 {
3596 bfd_set_error (bfd_error_bad_value);
3597 goto error_ret_free_internal;
3598 }
3599 st_type = ELF_ST_TYPE (hash->root.type);
3600 sym_name = hash->root.root.root.string;
3601 }
3602
3603 /* Determine what (if any) linker stub is needed. */
3604 stub_type = arm_type_of_stub (info, section, irela, st_type,
3605 hash, destination);
3606 if (stub_type == arm_stub_none)
3607 continue;
3608
3609 /* Support for grouping stub sections. */
3610 id_sec = htab->stub_group[section->id].link_sec;
3611
3612 /* Get the name of this stub. */
3613 stub_name = elf32_arm_stub_name (id_sec, sym_sec, hash, irela);
3614 if (!stub_name)
3615 goto error_ret_free_internal;
3616
3617 stub_entry = arm_stub_hash_lookup (&htab->stub_hash_table,
3618 stub_name,
3619 FALSE, FALSE);
3620 if (stub_entry != NULL)
3621 {
3622 /* The proper stub has already been created. */
3623 free (stub_name);
3624 continue;
3625 }
3626
3627 stub_entry = elf32_arm_add_stub (stub_name, section, htab);
3628 if (stub_entry == NULL)
3629 {
3630 free (stub_name);
3631 goto error_ret_free_internal;
3632 }
3633
3634 stub_entry->target_value = sym_value;
3635 stub_entry->target_section = sym_sec;
3636 stub_entry->stub_type = stub_type;
3637 stub_entry->h = hash;
3638 stub_entry->st_type = st_type;
3639
3640 if (sym_name == NULL)
3641 sym_name = "unnamed";
3642 stub_entry->output_name
3643 = bfd_alloc (htab->stub_bfd,
3644 sizeof (THUMB2ARM_GLUE_ENTRY_NAME)
3645 + strlen (sym_name));
3646 if (stub_entry->output_name == NULL)
3647 {
3648 free (stub_name);
3649 goto error_ret_free_internal;
3650 }
3651
3652 /* For historical reasons, use the existing names for
3653 ARM-to-Thumb and Thumb-to-ARM stubs. */
3654 if (r_type == (unsigned int) R_ARM_THM_CALL
3655 && st_type != STT_ARM_TFUNC)
3656 sprintf (stub_entry->output_name, THUMB2ARM_GLUE_ENTRY_NAME,
3657 sym_name);
3658 else if (r_type == (unsigned int) R_ARM_CALL
3659 && st_type == STT_ARM_TFUNC)
3660 sprintf (stub_entry->output_name, ARM2THUMB_GLUE_ENTRY_NAME,
3661 sym_name);
3662 else
3663 sprintf (stub_entry->output_name, STUB_ENTRY_NAME,
3664 sym_name);
3665
3666 stub_changed = TRUE;
3667 }
3668
3669 /* We're done with the internal relocs, free them. */
3670 if (elf_section_data (section)->relocs == NULL)
3671 free (internal_relocs);
3672 }
3673 }
3674
3675 if (!stub_changed)
3676 break;
3677
3678 /* OK, we've added some stubs. Find out the new size of the
3679 stub sections. */
3680 for (stub_sec = htab->stub_bfd->sections;
3681 stub_sec != NULL;
3682 stub_sec = stub_sec->next)
3683 stub_sec->size = 0;
3684
3685 bfd_hash_traverse (&htab->stub_hash_table, arm_size_one_stub, htab);
3686
3687 /* Ask the linker to do its stuff. */
3688 (*htab->layout_sections_again) ();
3689 stub_changed = FALSE;
3690 }
3691
3692 return TRUE;
3693
3694 error_ret_free_local:
3695 return FALSE;
3696 }
3697
3698 /* Build all the stubs associated with the current output file. The
3699 stubs are kept in a hash table attached to the main linker hash
3700 table. We also set up the .plt entries for statically linked PIC
3701 functions here. This function is called via arm_elf_finish in the
3702 linker. */
3703
3704 bfd_boolean
3705 elf32_arm_build_stubs (struct bfd_link_info *info)
3706 {
3707 asection *stub_sec;
3708 struct bfd_hash_table *table;
3709 struct elf32_arm_link_hash_table *htab;
3710
3711 htab = elf32_arm_hash_table (info);
3712
3713 for (stub_sec = htab->stub_bfd->sections;
3714 stub_sec != NULL;
3715 stub_sec = stub_sec->next)
3716 {
3717 bfd_size_type size;
3718
3719 /* Ignore non-stub sections */
3720 if (!strstr (stub_sec->name, STUB_SUFFIX))
3721 continue;
3722
3723 /* Allocate memory to hold the linker stubs. */
3724 size = stub_sec->size;
3725 stub_sec->contents = bfd_zalloc (htab->stub_bfd, size);
3726 if (stub_sec->contents == NULL && size != 0)
3727 return FALSE;
3728 stub_sec->size = 0;
3729 }
3730
3731 /* Build the stubs as directed by the stub hash table. */
3732 table = &htab->stub_hash_table;
3733 bfd_hash_traverse (table, arm_build_one_stub, info);
3734
3735 return TRUE;
3736 }
3737
3738 /* Locate the Thumb encoded calling stub for NAME. */
3739
3740 static struct elf_link_hash_entry *
3741 find_thumb_glue (struct bfd_link_info *link_info,
3742 const char *name,
3743 char **error_message)
3744 {
3745 char *tmp_name;
3746 struct elf_link_hash_entry *hash;
3747 struct elf32_arm_link_hash_table *hash_table;
3748
3749 /* We need a pointer to the armelf specific hash table. */
3750 hash_table = elf32_arm_hash_table (link_info);
3751
3752 tmp_name = bfd_malloc ((bfd_size_type) strlen (name)
3753 + strlen (THUMB2ARM_GLUE_ENTRY_NAME) + 1);
3754
3755 BFD_ASSERT (tmp_name);
3756
3757 sprintf (tmp_name, THUMB2ARM_GLUE_ENTRY_NAME, name);
3758
3759 hash = elf_link_hash_lookup
3760 (&(hash_table)->root, tmp_name, FALSE, FALSE, TRUE);
3761
3762 if (hash == NULL
3763 && asprintf (error_message, _("unable to find THUMB glue '%s' for '%s'"),
3764 tmp_name, name) == -1)
3765 *error_message = (char *) bfd_errmsg (bfd_error_system_call);
3766
3767 free (tmp_name);
3768
3769 return hash;
3770 }
3771
3772 /* Locate the ARM encoded calling stub for NAME. */
3773
3774 static struct elf_link_hash_entry *
3775 find_arm_glue (struct bfd_link_info *link_info,
3776 const char *name,
3777 char **error_message)
3778 {
3779 char *tmp_name;
3780 struct elf_link_hash_entry *myh;
3781 struct elf32_arm_link_hash_table *hash_table;
3782
3783 /* We need a pointer to the elfarm specific hash table. */
3784 hash_table = elf32_arm_hash_table (link_info);
3785
3786 tmp_name = bfd_malloc ((bfd_size_type) strlen (name)
3787 + strlen (ARM2THUMB_GLUE_ENTRY_NAME) + 1);
3788
3789 BFD_ASSERT (tmp_name);
3790
3791 sprintf (tmp_name, ARM2THUMB_GLUE_ENTRY_NAME, name);
3792
3793 myh = elf_link_hash_lookup
3794 (&(hash_table)->root, tmp_name, FALSE, FALSE, TRUE);
3795
3796 if (myh == NULL
3797 && asprintf (error_message, _("unable to find ARM glue '%s' for '%s'"),
3798 tmp_name, name) == -1)
3799 *error_message = (char *) bfd_errmsg (bfd_error_system_call);
3800
3801 free (tmp_name);
3802
3803 return myh;
3804 }
3805
3806 /* ARM->Thumb glue (static images):
3807
3808 .arm
3809 __func_from_arm:
3810 ldr r12, __func_addr
3811 bx r12
3812 __func_addr:
3813 .word func @ behave as if you saw a ARM_32 reloc.
3814
3815 (v5t static images)
3816 .arm
3817 __func_from_arm:
3818 ldr pc, __func_addr
3819 __func_addr:
3820 .word func @ behave as if you saw a ARM_32 reloc.
3821
3822 (relocatable images)
3823 .arm
3824 __func_from_arm:
3825 ldr r12, __func_offset
3826 add r12, r12, pc
3827 bx r12
3828 __func_offset:
3829 .word func - .
3830 */
3831
3832 #define ARM2THUMB_STATIC_GLUE_SIZE 12
3833 static const insn32 a2t1_ldr_insn = 0xe59fc000;
3834 static const insn32 a2t2_bx_r12_insn = 0xe12fff1c;
3835 static const insn32 a2t3_func_addr_insn = 0x00000001;
3836
3837 #define ARM2THUMB_V5_STATIC_GLUE_SIZE 8
3838 static const insn32 a2t1v5_ldr_insn = 0xe51ff004;
3839 static const insn32 a2t2v5_func_addr_insn = 0x00000001;
3840
3841 #define ARM2THUMB_PIC_GLUE_SIZE 16
3842 static const insn32 a2t1p_ldr_insn = 0xe59fc004;
3843 static const insn32 a2t2p_add_pc_insn = 0xe08cc00f;
3844 static const insn32 a2t3p_bx_r12_insn = 0xe12fff1c;
3845
3846 /* Thumb->ARM: Thumb->(non-interworking aware) ARM
3847
3848 .thumb .thumb
3849 .align 2 .align 2
3850 __func_from_thumb: __func_from_thumb:
3851 bx pc push {r6, lr}
3852 nop ldr r6, __func_addr
3853 .arm mov lr, pc
3854 __func_change_to_arm: bx r6
3855 b func .arm
3856 __func_back_to_thumb:
3857 ldmia r13! {r6, lr}
3858 bx lr
3859 __func_addr:
3860 .word func */
3861
3862 #define THUMB2ARM_GLUE_SIZE 8
3863 static const insn16 t2a1_bx_pc_insn = 0x4778;
3864 static const insn16 t2a2_noop_insn = 0x46c0;
3865 static const insn32 t2a3_b_insn = 0xea000000;
3866
3867 #define VFP11_ERRATUM_VENEER_SIZE 8
3868
3869 #define ARM_BX_VENEER_SIZE 12
3870 static const insn32 armbx1_tst_insn = 0xe3100001;
3871 static const insn32 armbx2_moveq_insn = 0x01a0f000;
3872 static const insn32 armbx3_bx_insn = 0xe12fff10;
3873
3874 #ifndef ELFARM_NABI_C_INCLUDED
3875 bfd_boolean
3876 bfd_elf32_arm_allocate_interworking_sections (struct bfd_link_info * info)
3877 {
3878 asection * s;
3879 bfd_byte * foo;
3880 struct elf32_arm_link_hash_table * globals;
3881
3882 globals = elf32_arm_hash_table (info);
3883
3884 BFD_ASSERT (globals != NULL);
3885
3886 if (globals->arm_glue_size != 0)
3887 {
3888 BFD_ASSERT (globals->bfd_of_glue_owner != NULL);
3889
3890 s = bfd_get_section_by_name (globals->bfd_of_glue_owner,
3891 ARM2THUMB_GLUE_SECTION_NAME);
3892
3893 BFD_ASSERT (s != NULL);
3894
3895 foo = bfd_alloc (globals->bfd_of_glue_owner, globals->arm_glue_size);
3896
3897 BFD_ASSERT (s->size == globals->arm_glue_size);
3898 s->contents = foo;
3899 }
3900
3901 if (globals->thumb_glue_size != 0)
3902 {
3903 BFD_ASSERT (globals->bfd_of_glue_owner != NULL);
3904
3905 s = bfd_get_section_by_name
3906 (globals->bfd_of_glue_owner, THUMB2ARM_GLUE_SECTION_NAME);
3907
3908 BFD_ASSERT (s != NULL);
3909
3910 foo = bfd_alloc (globals->bfd_of_glue_owner, globals->thumb_glue_size);
3911
3912 BFD_ASSERT (s->size == globals->thumb_glue_size);
3913 s->contents = foo;
3914 }
3915
3916 if (globals->vfp11_erratum_glue_size != 0)
3917 {
3918 BFD_ASSERT (globals->bfd_of_glue_owner != NULL);
3919
3920 s = bfd_get_section_by_name
3921 (globals->bfd_of_glue_owner, VFP11_ERRATUM_VENEER_SECTION_NAME);
3922
3923 BFD_ASSERT (s != NULL);
3924
3925 foo = bfd_alloc (globals->bfd_of_glue_owner,
3926 globals->vfp11_erratum_glue_size);
3927
3928 BFD_ASSERT (s->size == globals->vfp11_erratum_glue_size);
3929 s->contents = foo;
3930 }
3931
3932 if (globals->bx_glue_size != 0)
3933 {
3934 BFD_ASSERT (globals->bfd_of_glue_owner != NULL);
3935
3936 s = bfd_get_section_by_name (globals->bfd_of_glue_owner,
3937 ARM_BX_GLUE_SECTION_NAME);
3938
3939 BFD_ASSERT (s != NULL);
3940
3941 foo = bfd_alloc (globals->bfd_of_glue_owner, globals->bx_glue_size);
3942
3943 BFD_ASSERT (s->size == globals->bx_glue_size);
3944 s->contents = foo;
3945 }
3946
3947 return TRUE;
3948 }
3949
3950 /* Allocate space and symbols for calling a Thumb function from Arm mode.
3951 returns the symbol identifying the stub. */
3952
3953 static struct elf_link_hash_entry *
3954 record_arm_to_thumb_glue (struct bfd_link_info * link_info,
3955 struct elf_link_hash_entry * h)
3956 {
3957 const char * name = h->root.root.string;
3958 asection * s;
3959 char * tmp_name;
3960 struct elf_link_hash_entry * myh;
3961 struct bfd_link_hash_entry * bh;
3962 struct elf32_arm_link_hash_table * globals;
3963 bfd_vma val;
3964 bfd_size_type size;
3965
3966 globals = elf32_arm_hash_table (link_info);
3967
3968 BFD_ASSERT (globals != NULL);
3969 BFD_ASSERT (globals->bfd_of_glue_owner != NULL);
3970
3971 s = bfd_get_section_by_name
3972 (globals->bfd_of_glue_owner, ARM2THUMB_GLUE_SECTION_NAME);
3973
3974 BFD_ASSERT (s != NULL);
3975
3976 tmp_name = bfd_malloc ((bfd_size_type) strlen (name) + strlen (ARM2THUMB_GLUE_ENTRY_NAME) + 1);
3977
3978 BFD_ASSERT (tmp_name);
3979
3980 sprintf (tmp_name, ARM2THUMB_GLUE_ENTRY_NAME, name);
3981
3982 myh = elf_link_hash_lookup
3983 (&(globals)->root, tmp_name, FALSE, FALSE, TRUE);
3984
3985 if (myh != NULL)
3986 {
3987 /* We've already seen this guy. */
3988 free (tmp_name);
3989 return myh;
3990 }
3991
3992 /* The only trick here is using hash_table->arm_glue_size as the value.
3993 Even though the section isn't allocated yet, this is where we will be
3994 putting it. The +1 on the value marks that the stub has not been
3995 output yet - not that it is a Thumb function. */
3996 bh = NULL;
3997 val = globals->arm_glue_size + 1;
3998 _bfd_generic_link_add_one_symbol (link_info, globals->bfd_of_glue_owner,
3999 tmp_name, BSF_GLOBAL, s, val,
4000 NULL, TRUE, FALSE, &bh);
4001
4002 myh = (struct elf_link_hash_entry *) bh;
4003 myh->type = ELF_ST_INFO (STB_LOCAL, STT_FUNC);
4004 myh->forced_local = 1;
4005
4006 free (tmp_name);
4007
4008 if (link_info->shared || globals->root.is_relocatable_executable
4009 || globals->pic_veneer)
4010 size = ARM2THUMB_PIC_GLUE_SIZE;
4011 else if (globals->use_blx)
4012 size = ARM2THUMB_V5_STATIC_GLUE_SIZE;
4013 else
4014 size = ARM2THUMB_STATIC_GLUE_SIZE;
4015
4016 s->size += size;
4017 globals->arm_glue_size += size;
4018
4019 return myh;
4020 }
4021
4022 static void
4023 record_thumb_to_arm_glue (struct bfd_link_info *link_info,
4024 struct elf_link_hash_entry *h)
4025 {
4026 const char *name = h->root.root.string;
4027 asection *s;
4028 char *tmp_name;
4029 struct elf_link_hash_entry *myh;
4030 struct bfd_link_hash_entry *bh;
4031 struct elf32_arm_link_hash_table *hash_table;
4032 bfd_vma val;
4033
4034 hash_table = elf32_arm_hash_table (link_info);
4035
4036 BFD_ASSERT (hash_table != NULL);
4037 BFD_ASSERT (hash_table->bfd_of_glue_owner != NULL);
4038
4039 s = bfd_get_section_by_name
4040 (hash_table->bfd_of_glue_owner, THUMB2ARM_GLUE_SECTION_NAME);
4041
4042 BFD_ASSERT (s != NULL);
4043
4044 tmp_name = bfd_malloc ((bfd_size_type) strlen (name)
4045 + strlen (THUMB2ARM_GLUE_ENTRY_NAME) + 1);
4046
4047 BFD_ASSERT (tmp_name);
4048
4049 sprintf (tmp_name, THUMB2ARM_GLUE_ENTRY_NAME, name);
4050
4051 myh = elf_link_hash_lookup
4052 (&(hash_table)->root, tmp_name, FALSE, FALSE, TRUE);
4053
4054 if (myh != NULL)
4055 {
4056 /* We've already seen this guy. */
4057 free (tmp_name);
4058 return;
4059 }
4060
4061 /* The only trick here is using hash_table->thumb_glue_size as the value.
4062 Even though the section isn't allocated yet, this is where we will be
4063 putting it. The +1 on the value marks that the stub has not been
4064 output yet - not that it is a Thumb function. */
4065 bh = NULL;
4066 val = hash_table->thumb_glue_size + 1;
4067 _bfd_generic_link_add_one_symbol (link_info, hash_table->bfd_of_glue_owner,
4068 tmp_name, BSF_GLOBAL, s, val,
4069 NULL, TRUE, FALSE, &bh);
4070
4071 /* If we mark it 'Thumb', the disassembler will do a better job. */
4072 myh = (struct elf_link_hash_entry *) bh;
4073 myh->type = ELF_ST_INFO (STB_LOCAL, STT_ARM_TFUNC);
4074 myh->forced_local = 1;
4075
4076 free (tmp_name);
4077
4078 #define CHANGE_TO_ARM "__%s_change_to_arm"
4079 #define BACK_FROM_ARM "__%s_back_from_arm"
4080
4081 /* Allocate another symbol to mark where we switch to Arm mode. */
4082 tmp_name = bfd_malloc ((bfd_size_type) strlen (name)
4083 + strlen (CHANGE_TO_ARM) + 1);
4084
4085 BFD_ASSERT (tmp_name);
4086
4087 sprintf (tmp_name, CHANGE_TO_ARM, name);
4088
4089 bh = NULL;
4090 val = hash_table->thumb_glue_size + 4,
4091 _bfd_generic_link_add_one_symbol (link_info, hash_table->bfd_of_glue_owner,
4092 tmp_name, BSF_LOCAL, s, val,
4093 NULL, TRUE, FALSE, &bh);
4094
4095 free (tmp_name);
4096
4097 s->size += THUMB2ARM_GLUE_SIZE;
4098 hash_table->thumb_glue_size += THUMB2ARM_GLUE_SIZE;
4099
4100 return;
4101 }
4102
4103
4104 /* Allocate space for ARMv4 BX veneers. */
4105
4106 static void
4107 record_arm_bx_glue (struct bfd_link_info * link_info, int reg)
4108 {
4109 asection * s;
4110 struct elf32_arm_link_hash_table *globals;
4111 char *tmp_name;
4112 struct elf_link_hash_entry *myh;
4113 struct bfd_link_hash_entry *bh;
4114 bfd_vma val;
4115
4116 /* BX PC does not need a veneer. */
4117 if (reg == 15)
4118 return;
4119
4120 globals = elf32_arm_hash_table (link_info);
4121
4122 BFD_ASSERT (globals != NULL);
4123 BFD_ASSERT (globals->bfd_of_glue_owner != NULL);
4124
4125 /* Check if this veneer has already been allocated. */
4126 if (globals->bx_glue_offset[reg])
4127 return;
4128
4129 s = bfd_get_section_by_name
4130 (globals->bfd_of_glue_owner, ARM_BX_GLUE_SECTION_NAME);
4131
4132 BFD_ASSERT (s != NULL);
4133
4134 /* Add symbol for veneer. */
4135 tmp_name = bfd_malloc ((bfd_size_type) strlen (ARM_BX_GLUE_ENTRY_NAME) + 1);
4136
4137 BFD_ASSERT (tmp_name);
4138
4139 sprintf (tmp_name, ARM_BX_GLUE_ENTRY_NAME, reg);
4140
4141 myh = elf_link_hash_lookup
4142 (&(globals)->root, tmp_name, FALSE, FALSE, FALSE);
4143
4144 BFD_ASSERT (myh == NULL);
4145
4146 bh = NULL;
4147 val = globals->bx_glue_size;
4148 _bfd_generic_link_add_one_symbol (link_info, globals->bfd_of_glue_owner,
4149 tmp_name, BSF_FUNCTION | BSF_LOCAL, s, val,
4150 NULL, TRUE, FALSE, &bh);
4151
4152 myh = (struct elf_link_hash_entry *) bh;
4153 myh->type = ELF_ST_INFO (STB_LOCAL, STT_FUNC);
4154 myh->forced_local = 1;
4155
4156 s->size += ARM_BX_VENEER_SIZE;
4157 globals->bx_glue_offset[reg] = globals->bx_glue_size | 2;
4158 globals->bx_glue_size += ARM_BX_VENEER_SIZE;
4159 }
4160
4161
4162 /* Add an entry to the code/data map for section SEC. */
4163
4164 static void
4165 elf32_arm_section_map_add (asection *sec, char type, bfd_vma vma)
4166 {
4167 struct _arm_elf_section_data *sec_data = elf32_arm_section_data (sec);
4168 unsigned int newidx;
4169
4170 if (sec_data->map == NULL)
4171 {
4172 sec_data->map = bfd_malloc (sizeof (elf32_arm_section_map));
4173 sec_data->mapcount = 0;
4174 sec_data->mapsize = 1;
4175 }
4176
4177 newidx = sec_data->mapcount++;
4178
4179 if (sec_data->mapcount > sec_data->mapsize)
4180 {
4181 sec_data->mapsize *= 2;
4182 sec_data->map = bfd_realloc_or_free (sec_data->map, sec_data->mapsize
4183 * sizeof (elf32_arm_section_map));
4184 }
4185
4186 if (sec_data->map)
4187 {
4188 sec_data->map[newidx].vma = vma;
4189 sec_data->map[newidx].type = type;
4190 }
4191 }
4192
4193
4194 /* Record information about a VFP11 denorm-erratum veneer. Only ARM-mode
4195 veneers are handled for now. */
4196
4197 static bfd_vma
4198 record_vfp11_erratum_veneer (struct bfd_link_info *link_info,
4199 elf32_vfp11_erratum_list *branch,
4200 bfd *branch_bfd,
4201 asection *branch_sec,
4202 unsigned int offset)
4203 {
4204 asection *s;
4205 struct elf32_arm_link_hash_table *hash_table;
4206 char *tmp_name;
4207 struct elf_link_hash_entry *myh;
4208 struct bfd_link_hash_entry *bh;
4209 bfd_vma val;
4210 struct _arm_elf_section_data *sec_data;
4211 int errcount;
4212 elf32_vfp11_erratum_list *newerr;
4213
4214 hash_table = elf32_arm_hash_table (link_info);
4215
4216 BFD_ASSERT (hash_table != NULL);
4217 BFD_ASSERT (hash_table->bfd_of_glue_owner != NULL);
4218
4219 s = bfd_get_section_by_name
4220 (hash_table->bfd_of_glue_owner, VFP11_ERRATUM_VENEER_SECTION_NAME);
4221
4222 sec_data = elf32_arm_section_data (s);
4223
4224 BFD_ASSERT (s != NULL);
4225
4226 tmp_name = bfd_malloc ((bfd_size_type) strlen
4227 (VFP11_ERRATUM_VENEER_ENTRY_NAME) + 10);
4228
4229 BFD_ASSERT (tmp_name);
4230
4231 sprintf (tmp_name, VFP11_ERRATUM_VENEER_ENTRY_NAME,
4232 hash_table->num_vfp11_fixes);
4233
4234 myh = elf_link_hash_lookup
4235 (&(hash_table)->root, tmp_name, FALSE, FALSE, FALSE);
4236
4237 BFD_ASSERT (myh == NULL);
4238
4239 bh = NULL;
4240 val = hash_table->vfp11_erratum_glue_size;
4241 _bfd_generic_link_add_one_symbol (link_info, hash_table->bfd_of_glue_owner,
4242 tmp_name, BSF_FUNCTION | BSF_LOCAL, s, val,
4243 NULL, TRUE, FALSE, &bh);
4244
4245 myh = (struct elf_link_hash_entry *) bh;
4246 myh->type = ELF_ST_INFO (STB_LOCAL, STT_FUNC);
4247 myh->forced_local = 1;
4248
4249 /* Link veneer back to calling location. */
4250 errcount = ++(sec_data->erratumcount);
4251 newerr = bfd_zmalloc (sizeof (elf32_vfp11_erratum_list));
4252
4253 newerr->type = VFP11_ERRATUM_ARM_VENEER;
4254 newerr->vma = -1;
4255 newerr->u.v.branch = branch;
4256 newerr->u.v.id = hash_table->num_vfp11_fixes;
4257 branch->u.b.veneer = newerr;
4258
4259 newerr->next = sec_data->erratumlist;
4260 sec_data->erratumlist = newerr;
4261
4262 /* A symbol for the return from the veneer. */
4263 sprintf (tmp_name, VFP11_ERRATUM_VENEER_ENTRY_NAME "_r",
4264 hash_table->num_vfp11_fixes);
4265
4266 myh = elf_link_hash_lookup
4267 (&(hash_table)->root, tmp_name, FALSE, FALSE, FALSE);
4268
4269 if (myh != NULL)
4270 abort ();
4271
4272 bh = NULL;
4273 val = offset + 4;
4274 _bfd_generic_link_add_one_symbol (link_info, branch_bfd, tmp_name, BSF_LOCAL,
4275 branch_sec, val, NULL, TRUE, FALSE, &bh);
4276
4277 myh = (struct elf_link_hash_entry *) bh;
4278 myh->type = ELF_ST_INFO (STB_LOCAL, STT_FUNC);
4279 myh->forced_local = 1;
4280
4281 free (tmp_name);
4282
4283 /* Generate a mapping symbol for the veneer section, and explicitly add an
4284 entry for that symbol to the code/data map for the section. */
4285 if (hash_table->vfp11_erratum_glue_size == 0)
4286 {
4287 bh = NULL;
4288 /* FIXME: Creates an ARM symbol. Thumb mode will need attention if it
4289 ever requires this erratum fix. */
4290 _bfd_generic_link_add_one_symbol (link_info,
4291 hash_table->bfd_of_glue_owner, "$a",
4292 BSF_LOCAL, s, 0, NULL,
4293 TRUE, FALSE, &bh);
4294
4295 myh = (struct elf_link_hash_entry *) bh;
4296 myh->type = ELF_ST_INFO (STB_LOCAL, STT_NOTYPE);
4297 myh->forced_local = 1;
4298
4299 /* The elf32_arm_init_maps function only cares about symbols from input
4300 BFDs. We must make a note of this generated mapping symbol
4301 ourselves so that code byteswapping works properly in
4302 elf32_arm_write_section. */
4303 elf32_arm_section_map_add (s, 'a', 0);
4304 }
4305
4306 s->size += VFP11_ERRATUM_VENEER_SIZE;
4307 hash_table->vfp11_erratum_glue_size += VFP11_ERRATUM_VENEER_SIZE;
4308 hash_table->num_vfp11_fixes++;
4309
4310 /* The offset of the veneer. */
4311 return val;
4312 }
4313
4314 /* Add the glue sections to ABFD. This function is called from the
4315 linker scripts in ld/emultempl/{armelf}.em. */
4316
4317 bfd_boolean
4318 bfd_elf32_arm_add_glue_sections_to_bfd (bfd *abfd,
4319 struct bfd_link_info *info)
4320 {
4321 flagword flags;
4322 asection *sec;
4323
4324 /* If we are only performing a partial
4325 link do not bother adding the glue. */
4326 if (info->relocatable)
4327 return TRUE;
4328
4329 /* linker stubs don't need glue */
4330 if (!strcmp (abfd->filename, "linker stubs"))
4331 return TRUE;
4332
4333 sec = bfd_get_section_by_name (abfd, ARM2THUMB_GLUE_SECTION_NAME);
4334
4335 if (sec == NULL)
4336 {
4337 /* Note: we do not include the flag SEC_LINKER_CREATED, as this
4338 will prevent elf_link_input_bfd() from processing the contents
4339 of this section. */
4340 flags = (SEC_ALLOC | SEC_LOAD | SEC_HAS_CONTENTS | SEC_IN_MEMORY
4341 | SEC_CODE | SEC_READONLY);
4342
4343 sec = bfd_make_section_with_flags (abfd,
4344 ARM2THUMB_GLUE_SECTION_NAME,
4345 flags);
4346
4347 if (sec == NULL
4348 || !bfd_set_section_alignment (abfd, sec, 2))
4349 return FALSE;
4350
4351 /* Set the gc mark to prevent the section from being removed by garbage
4352 collection, despite the fact that no relocs refer to this section. */
4353 sec->gc_mark = 1;
4354 }
4355
4356 sec = bfd_get_section_by_name (abfd, THUMB2ARM_GLUE_SECTION_NAME);
4357
4358 if (sec == NULL)
4359 {
4360 flags = (SEC_ALLOC | SEC_LOAD | SEC_HAS_CONTENTS | SEC_IN_MEMORY
4361 | SEC_CODE | SEC_READONLY);
4362
4363 sec = bfd_make_section_with_flags (abfd,
4364 THUMB2ARM_GLUE_SECTION_NAME,
4365 flags);
4366
4367 if (sec == NULL
4368 || !bfd_set_section_alignment (abfd, sec, 2))
4369 return FALSE;
4370
4371 sec->gc_mark = 1;
4372 }
4373
4374 sec = bfd_get_section_by_name (abfd, VFP11_ERRATUM_VENEER_SECTION_NAME);
4375
4376 if (sec == NULL)
4377 {
4378 flags = (SEC_ALLOC | SEC_LOAD | SEC_HAS_CONTENTS | SEC_IN_MEMORY
4379 | SEC_CODE | SEC_READONLY);
4380
4381 sec = bfd_make_section_with_flags (abfd,
4382 VFP11_ERRATUM_VENEER_SECTION_NAME,
4383 flags);
4384
4385 if (sec == NULL
4386 || !bfd_set_section_alignment (abfd, sec, 2))
4387 return FALSE;
4388
4389 sec->gc_mark = 1;
4390 }
4391
4392 sec = bfd_get_section_by_name (abfd, ARM_BX_GLUE_SECTION_NAME);
4393
4394 if (sec == NULL)
4395 {
4396 flags = (SEC_ALLOC | SEC_LOAD | SEC_HAS_CONTENTS | SEC_IN_MEMORY
4397 | SEC_CODE | SEC_READONLY);
4398
4399 sec = bfd_make_section_with_flags (abfd,
4400 ARM_BX_GLUE_SECTION_NAME,
4401 flags);
4402
4403 if (sec == NULL
4404 || !bfd_set_section_alignment (abfd, sec, 2))
4405 return FALSE;
4406
4407 sec->gc_mark = 1;
4408 }
4409
4410 return TRUE;
4411 }
4412
4413 /* Select a BFD to be used to hold the sections used by the glue code.
4414 This function is called from the linker scripts in ld/emultempl/
4415 {armelf/pe}.em */
4416
4417 bfd_boolean
4418 bfd_elf32_arm_get_bfd_for_interworking (bfd *abfd, struct bfd_link_info *info)
4419 {
4420 struct elf32_arm_link_hash_table *globals;
4421
4422 /* If we are only performing a partial link
4423 do not bother getting a bfd to hold the glue. */
4424 if (info->relocatable)
4425 return TRUE;
4426
4427 /* Make sure we don't attach the glue sections to a dynamic object. */
4428 BFD_ASSERT (!(abfd->flags & DYNAMIC));
4429
4430 globals = elf32_arm_hash_table (info);
4431
4432 BFD_ASSERT (globals != NULL);
4433
4434 if (globals->bfd_of_glue_owner != NULL)
4435 return TRUE;
4436
4437 /* Save the bfd for later use. */
4438 globals->bfd_of_glue_owner = abfd;
4439
4440 return TRUE;
4441 }
4442
4443 static void
4444 check_use_blx (struct elf32_arm_link_hash_table *globals)
4445 {
4446 if (bfd_elf_get_obj_attr_int (globals->obfd, OBJ_ATTR_PROC,
4447 Tag_CPU_arch) > 2)
4448 globals->use_blx = 1;
4449 }
4450
4451 bfd_boolean
4452 bfd_elf32_arm_process_before_allocation (bfd *abfd,
4453 struct bfd_link_info *link_info)
4454 {
4455 Elf_Internal_Shdr *symtab_hdr;
4456 Elf_Internal_Rela *internal_relocs = NULL;
4457 Elf_Internal_Rela *irel, *irelend;
4458 bfd_byte *contents = NULL;
4459
4460 asection *sec;
4461 struct elf32_arm_link_hash_table *globals;
4462
4463 /* If we are only performing a partial link do not bother
4464 to construct any glue. */
4465 if (link_info->relocatable)
4466 return TRUE;
4467
4468 /* Here we have a bfd that is to be included on the link. We have a
4469 hook to do reloc rummaging, before section sizes are nailed down. */
4470 globals = elf32_arm_hash_table (link_info);
4471
4472 BFD_ASSERT (globals != NULL);
4473
4474 check_use_blx (globals);
4475
4476 if (globals->byteswap_code && !bfd_big_endian (abfd))
4477 {
4478 _bfd_error_handler (_("%B: BE8 images only valid in big-endian mode."),
4479 abfd);
4480 return FALSE;
4481 }
4482
4483 /* PR 5398: If we have not decided to include any loadable sections in
4484 the output then we will not have a glue owner bfd. This is OK, it
4485 just means that there is nothing else for us to do here. */
4486 if (globals->bfd_of_glue_owner == NULL)
4487 return TRUE;
4488
4489 /* Rummage around all the relocs and map the glue vectors. */
4490 sec = abfd->sections;
4491
4492 if (sec == NULL)
4493 return TRUE;
4494
4495 for (; sec != NULL; sec = sec->next)
4496 {
4497 if (sec->reloc_count == 0)
4498 continue;
4499
4500 if ((sec->flags & SEC_EXCLUDE) != 0)
4501 continue;
4502
4503 symtab_hdr = & elf_symtab_hdr (abfd);
4504
4505 /* Load the relocs. */
4506 internal_relocs
4507 = _bfd_elf_link_read_relocs (abfd, sec, NULL, NULL, FALSE);
4508
4509 if (internal_relocs == NULL)
4510 goto error_return;
4511
4512 irelend = internal_relocs + sec->reloc_count;
4513 for (irel = internal_relocs; irel < irelend; irel++)
4514 {
4515 long r_type;
4516 unsigned long r_index;
4517
4518 struct elf_link_hash_entry *h;
4519
4520 r_type = ELF32_R_TYPE (irel->r_info);
4521 r_index = ELF32_R_SYM (irel->r_info);
4522
4523 /* These are the only relocation types we care about. */
4524 if ( r_type != R_ARM_PC24
4525 && r_type != R_ARM_PLT32
4526 && r_type != R_ARM_JUMP24
4527 && r_type != R_ARM_THM_JUMP24
4528 && (r_type != R_ARM_V4BX || globals->fix_v4bx < 2))
4529 continue;
4530
4531 /* Get the section contents if we haven't done so already. */
4532 if (contents == NULL)
4533 {
4534 /* Get cached copy if it exists. */
4535 if (elf_section_data (sec)->this_hdr.contents != NULL)
4536 contents = elf_section_data (sec)->this_hdr.contents;
4537 else
4538 {
4539 /* Go get them off disk. */
4540 if (! bfd_malloc_and_get_section (abfd, sec, &contents))
4541 goto error_return;
4542 }
4543 }
4544
4545 if (r_type == R_ARM_V4BX)
4546 {
4547 int reg;
4548
4549 reg = bfd_get_32 (abfd, contents + irel->r_offset) & 0xf;
4550 record_arm_bx_glue (link_info, reg);
4551 continue;
4552 }
4553
4554 /* If the relocation is not against a symbol it cannot concern us. */
4555 h = NULL;
4556
4557 /* We don't care about local symbols. */
4558 if (r_index < symtab_hdr->sh_info)
4559 continue;
4560
4561 /* This is an external symbol. */
4562 r_index -= symtab_hdr->sh_info;
4563 h = (struct elf_link_hash_entry *)
4564 elf_sym_hashes (abfd)[r_index];
4565
4566 /* If the relocation is against a static symbol it must be within
4567 the current section and so cannot be a cross ARM/Thumb relocation. */
4568 if (h == NULL)
4569 continue;
4570
4571 /* If the call will go through a PLT entry then we do not need
4572 glue. */
4573 if (globals->splt != NULL && h->plt.offset != (bfd_vma) -1)
4574 continue;
4575
4576 switch (r_type)
4577 {
4578 case R_ARM_PC24:
4579 case R_ARM_PLT32:
4580 case R_ARM_JUMP24:
4581 /* This one is a call from arm code. We need to look up
4582 the target of the call. If it is a thumb target, we
4583 insert glue. */
4584 if (ELF_ST_TYPE (h->type) == STT_ARM_TFUNC
4585 && !(r_type == R_ARM_CALL && globals->use_blx))
4586 record_arm_to_thumb_glue (link_info, h);
4587 break;
4588
4589 case R_ARM_THM_JUMP24:
4590 /* This one is a call from thumb code. We look
4591 up the target of the call. If it is not a thumb
4592 target, we insert glue. */
4593 if (ELF_ST_TYPE (h->type) != STT_ARM_TFUNC
4594 && !(globals->use_blx && r_type == R_ARM_THM_CALL)
4595 && h->root.type != bfd_link_hash_undefweak)
4596 record_thumb_to_arm_glue (link_info, h);
4597 break;
4598
4599 default:
4600 abort ();
4601 }
4602 }
4603
4604 if (contents != NULL
4605 && elf_section_data (sec)->this_hdr.contents != contents)
4606 free (contents);
4607 contents = NULL;
4608
4609 if (internal_relocs != NULL
4610 && elf_section_data (sec)->relocs != internal_relocs)
4611 free (internal_relocs);
4612 internal_relocs = NULL;
4613 }
4614
4615 return TRUE;
4616
4617 error_return:
4618 if (contents != NULL
4619 && elf_section_data (sec)->this_hdr.contents != contents)
4620 free (contents);
4621 if (internal_relocs != NULL
4622 && elf_section_data (sec)->relocs != internal_relocs)
4623 free (internal_relocs);
4624
4625 return FALSE;
4626 }
4627 #endif
4628
4629
4630 /* Initialise maps of ARM/Thumb/data for input BFDs. */
4631
4632 void
4633 bfd_elf32_arm_init_maps (bfd *abfd)
4634 {
4635 Elf_Internal_Sym *isymbuf;
4636 Elf_Internal_Shdr *hdr;
4637 unsigned int i, localsyms;
4638
4639 if ((abfd->flags & DYNAMIC) != 0)
4640 return;
4641
4642 hdr = & elf_symtab_hdr (abfd);
4643 localsyms = hdr->sh_info;
4644
4645 /* Obtain a buffer full of symbols for this BFD. The hdr->sh_info field
4646 should contain the number of local symbols, which should come before any
4647 global symbols. Mapping symbols are always local. */
4648 isymbuf = bfd_elf_get_elf_syms (abfd, hdr, localsyms, 0, NULL, NULL,
4649 NULL);
4650
4651 /* No internal symbols read? Skip this BFD. */
4652 if (isymbuf == NULL)
4653 return;
4654
4655 for (i = 0; i < localsyms; i++)
4656 {
4657 Elf_Internal_Sym *isym = &isymbuf[i];
4658 asection *sec = bfd_section_from_elf_index (abfd, isym->st_shndx);
4659 const char *name;
4660
4661 if (sec != NULL
4662 && ELF_ST_BIND (isym->st_info) == STB_LOCAL)
4663 {
4664 name = bfd_elf_string_from_elf_section (abfd,
4665 hdr->sh_link, isym->st_name);
4666
4667 if (bfd_is_arm_special_symbol_name (name,
4668 BFD_ARM_SPECIAL_SYM_TYPE_MAP))
4669 elf32_arm_section_map_add (sec, name[1], isym->st_value);
4670 }
4671 }
4672 }
4673
4674
4675 void
4676 bfd_elf32_arm_set_vfp11_fix (bfd *obfd, struct bfd_link_info *link_info)
4677 {
4678 struct elf32_arm_link_hash_table *globals = elf32_arm_hash_table (link_info);
4679 obj_attribute *out_attr = elf_known_obj_attributes_proc (obfd);
4680
4681 /* We assume that ARMv7+ does not need the VFP11 denorm erratum fix. */
4682 if (out_attr[Tag_CPU_arch].i >= TAG_CPU_ARCH_V7)
4683 {
4684 switch (globals->vfp11_fix)
4685 {
4686 case BFD_ARM_VFP11_FIX_DEFAULT:
4687 case BFD_ARM_VFP11_FIX_NONE:
4688 globals->vfp11_fix = BFD_ARM_VFP11_FIX_NONE;
4689 break;
4690
4691 default:
4692 /* Give a warning, but do as the user requests anyway. */
4693 (*_bfd_error_handler) (_("%B: warning: selected VFP11 erratum "
4694 "workaround is not necessary for target architecture"), obfd);
4695 }
4696 }
4697 else if (globals->vfp11_fix == BFD_ARM_VFP11_FIX_DEFAULT)
4698 /* For earlier architectures, we might need the workaround, but do not
4699 enable it by default. If users is running with broken hardware, they
4700 must enable the erratum fix explicitly. */
4701 globals->vfp11_fix = BFD_ARM_VFP11_FIX_NONE;
4702 }
4703
4704
4705 enum bfd_arm_vfp11_pipe
4706 {
4707 VFP11_FMAC,
4708 VFP11_LS,
4709 VFP11_DS,
4710 VFP11_BAD
4711 };
4712
4713 /* Return a VFP register number. This is encoded as RX:X for single-precision
4714 registers, or X:RX for double-precision registers, where RX is the group of
4715 four bits in the instruction encoding and X is the single extension bit.
4716 RX and X fields are specified using their lowest (starting) bit. The return
4717 value is:
4718
4719 0...31: single-precision registers s0...s31
4720 32...63: double-precision registers d0...d31.
4721
4722 Although X should be zero for VFP11 (encoding d0...d15 only), we might
4723 encounter VFP3 instructions, so we allow the full range for DP registers. */
4724
4725 static unsigned int
4726 bfd_arm_vfp11_regno (unsigned int insn, bfd_boolean is_double, unsigned int rx,
4727 unsigned int x)
4728 {
4729 if (is_double)
4730 return (((insn >> rx) & 0xf) | (((insn >> x) & 1) << 4)) + 32;
4731 else
4732 return (((insn >> rx) & 0xf) << 1) | ((insn >> x) & 1);
4733 }
4734
4735 /* Set bits in *WMASK according to a register number REG as encoded by
4736 bfd_arm_vfp11_regno(). Ignore d16-d31. */
4737
4738 static void
4739 bfd_arm_vfp11_write_mask (unsigned int *wmask, unsigned int reg)
4740 {
4741 if (reg < 32)
4742 *wmask |= 1 << reg;
4743 else if (reg < 48)
4744 *wmask |= 3 << ((reg - 32) * 2);
4745 }
4746
4747 /* Return TRUE if WMASK overwrites anything in REGS. */
4748
4749 static bfd_boolean
4750 bfd_arm_vfp11_antidependency (unsigned int wmask, int *regs, int numregs)
4751 {
4752 int i;
4753
4754 for (i = 0; i < numregs; i++)
4755 {
4756 unsigned int reg = regs[i];
4757
4758 if (reg < 32 && (wmask & (1 << reg)) != 0)
4759 return TRUE;
4760
4761 reg -= 32;
4762
4763 if (reg >= 16)
4764 continue;
4765
4766 if ((wmask & (3 << (reg * 2))) != 0)
4767 return TRUE;
4768 }
4769
4770 return FALSE;
4771 }
4772
4773 /* In this function, we're interested in two things: finding input registers
4774 for VFP data-processing instructions, and finding the set of registers which
4775 arbitrary VFP instructions may write to. We use a 32-bit unsigned int to
4776 hold the written set, so FLDM etc. are easy to deal with (we're only
4777 interested in 32 SP registers or 16 dp registers, due to the VFP version
4778 implemented by the chip in question). DP registers are marked by setting
4779 both SP registers in the write mask). */
4780
4781 static enum bfd_arm_vfp11_pipe
4782 bfd_arm_vfp11_insn_decode (unsigned int insn, unsigned int *destmask, int *regs,
4783 int *numregs)
4784 {
4785 enum bfd_arm_vfp11_pipe pipe = VFP11_BAD;
4786 bfd_boolean is_double = ((insn & 0xf00) == 0xb00) ? 1 : 0;
4787
4788 if ((insn & 0x0f000e10) == 0x0e000a00) /* A data-processing insn. */
4789 {
4790 unsigned int pqrs;
4791 unsigned int fd = bfd_arm_vfp11_regno (insn, is_double, 12, 22);
4792 unsigned int fm = bfd_arm_vfp11_regno (insn, is_double, 0, 5);
4793
4794 pqrs = ((insn & 0x00800000) >> 20)
4795 | ((insn & 0x00300000) >> 19)
4796 | ((insn & 0x00000040) >> 6);
4797
4798 switch (pqrs)
4799 {
4800 case 0: /* fmac[sd]. */
4801 case 1: /* fnmac[sd]. */
4802 case 2: /* fmsc[sd]. */
4803 case 3: /* fnmsc[sd]. */
4804 pipe = VFP11_FMAC;
4805 bfd_arm_vfp11_write_mask (destmask, fd);
4806 regs[0] = fd;
4807 regs[1] = bfd_arm_vfp11_regno (insn, is_double, 16, 7); /* Fn. */
4808 regs[2] = fm;
4809 *numregs = 3;
4810 break;
4811
4812 case 4: /* fmul[sd]. */
4813 case 5: /* fnmul[sd]. */
4814 case 6: /* fadd[sd]. */
4815 case 7: /* fsub[sd]. */
4816 pipe = VFP11_FMAC;
4817 goto vfp_binop;
4818
4819 case 8: /* fdiv[sd]. */
4820 pipe = VFP11_DS;
4821 vfp_binop:
4822 bfd_arm_vfp11_write_mask (destmask, fd);
4823 regs[0] = bfd_arm_vfp11_regno (insn, is_double, 16, 7); /* Fn. */
4824 regs[1] = fm;
4825 *numregs = 2;
4826 break;
4827
4828 case 15: /* extended opcode. */
4829 {
4830 unsigned int extn = ((insn >> 15) & 0x1e)
4831 | ((insn >> 7) & 1);
4832
4833 switch (extn)
4834 {
4835 case 0: /* fcpy[sd]. */
4836 case 1: /* fabs[sd]. */
4837 case 2: /* fneg[sd]. */
4838 case 8: /* fcmp[sd]. */
4839 case 9: /* fcmpe[sd]. */
4840 case 10: /* fcmpz[sd]. */
4841 case 11: /* fcmpez[sd]. */
4842 case 16: /* fuito[sd]. */
4843 case 17: /* fsito[sd]. */
4844 case 24: /* ftoui[sd]. */
4845 case 25: /* ftouiz[sd]. */
4846 case 26: /* ftosi[sd]. */
4847 case 27: /* ftosiz[sd]. */
4848 /* These instructions will not bounce due to underflow. */
4849 *numregs = 0;
4850 pipe = VFP11_FMAC;
4851 break;
4852
4853 case 3: /* fsqrt[sd]. */
4854 /* fsqrt cannot underflow, but it can (perhaps) overwrite
4855 registers to cause the erratum in previous instructions. */
4856 bfd_arm_vfp11_write_mask (destmask, fd);
4857 pipe = VFP11_DS;
4858 break;
4859
4860 case 15: /* fcvt{ds,sd}. */
4861 {
4862 int rnum = 0;
4863
4864 bfd_arm_vfp11_write_mask (destmask, fd);
4865
4866 /* Only FCVTSD can underflow. */
4867 if ((insn & 0x100) != 0)
4868 regs[rnum++] = fm;
4869
4870 *numregs = rnum;
4871
4872 pipe = VFP11_FMAC;
4873 }
4874 break;
4875
4876 default:
4877 return VFP11_BAD;
4878 }
4879 }
4880 break;
4881
4882 default:
4883 return VFP11_BAD;
4884 }
4885 }
4886 /* Two-register transfer. */
4887 else if ((insn & 0x0fe00ed0) == 0x0c400a10)
4888 {
4889 unsigned int fm = bfd_arm_vfp11_regno (insn, is_double, 0, 5);
4890
4891 if ((insn & 0x100000) == 0)
4892 {
4893 if (is_double)
4894 bfd_arm_vfp11_write_mask (destmask, fm);
4895 else
4896 {
4897 bfd_arm_vfp11_write_mask (destmask, fm);
4898 bfd_arm_vfp11_write_mask (destmask, fm + 1);
4899 }
4900 }
4901
4902 pipe = VFP11_LS;
4903 }
4904 else if ((insn & 0x0e100e00) == 0x0c100a00) /* A load insn. */
4905 {
4906 int fd = bfd_arm_vfp11_regno (insn, is_double, 12, 22);
4907 unsigned int puw = ((insn >> 21) & 0x1) | (((insn >> 23) & 3) << 1);
4908
4909 switch (puw)
4910 {
4911 case 0: /* Two-reg transfer. We should catch these above. */
4912 abort ();
4913
4914 case 2: /* fldm[sdx]. */
4915 case 3:
4916 case 5:
4917 {
4918 unsigned int i, offset = insn & 0xff;
4919
4920 if (is_double)
4921 offset >>= 1;
4922
4923 for (i = fd; i < fd + offset; i++)
4924 bfd_arm_vfp11_write_mask (destmask, i);
4925 }
4926 break;
4927
4928 case 4: /* fld[sd]. */
4929 case 6:
4930 bfd_arm_vfp11_write_mask (destmask, fd);
4931 break;
4932
4933 default:
4934 return VFP11_BAD;
4935 }
4936
4937 pipe = VFP11_LS;
4938 }
4939 /* Single-register transfer. Note L==0. */
4940 else if ((insn & 0x0f100e10) == 0x0e000a10)
4941 {
4942 unsigned int opcode = (insn >> 21) & 7;
4943 unsigned int fn = bfd_arm_vfp11_regno (insn, is_double, 16, 7);
4944
4945 switch (opcode)
4946 {
4947 case 0: /* fmsr/fmdlr. */
4948 case 1: /* fmdhr. */
4949 /* Mark fmdhr and fmdlr as writing to the whole of the DP
4950 destination register. I don't know if this is exactly right,
4951 but it is the conservative choice. */
4952 bfd_arm_vfp11_write_mask (destmask, fn);
4953 break;
4954
4955 case 7: /* fmxr. */
4956 break;
4957 }
4958
4959 pipe = VFP11_LS;
4960 }
4961
4962 return pipe;
4963 }
4964
4965
4966 static int elf32_arm_compare_mapping (const void * a, const void * b);
4967
4968
4969 /* Look for potentially-troublesome code sequences which might trigger the
4970 VFP11 denormal/antidependency erratum. See, e.g., the ARM1136 errata sheet
4971 (available from ARM) for details of the erratum. A short version is
4972 described in ld.texinfo. */
4973
4974 bfd_boolean
4975 bfd_elf32_arm_vfp11_erratum_scan (bfd *abfd, struct bfd_link_info *link_info)
4976 {
4977 asection *sec;
4978 bfd_byte *contents = NULL;
4979 int state = 0;
4980 int regs[3], numregs = 0;
4981 struct elf32_arm_link_hash_table *globals = elf32_arm_hash_table (link_info);
4982 int use_vector = (globals->vfp11_fix == BFD_ARM_VFP11_FIX_VECTOR);
4983
4984 /* We use a simple FSM to match troublesome VFP11 instruction sequences.
4985 The states transition as follows:
4986
4987 0 -> 1 (vector) or 0 -> 2 (scalar)
4988 A VFP FMAC-pipeline instruction has been seen. Fill
4989 regs[0]..regs[numregs-1] with its input operands. Remember this
4990 instruction in 'first_fmac'.
4991
4992 1 -> 2
4993 Any instruction, except for a VFP instruction which overwrites
4994 regs[*].
4995
4996 1 -> 3 [ -> 0 ] or
4997 2 -> 3 [ -> 0 ]
4998 A VFP instruction has been seen which overwrites any of regs[*].
4999 We must make a veneer! Reset state to 0 before examining next
5000 instruction.
5001
5002 2 -> 0
5003 If we fail to match anything in state 2, reset to state 0 and reset
5004 the instruction pointer to the instruction after 'first_fmac'.
5005
5006 If the VFP11 vector mode is in use, there must be at least two unrelated
5007 instructions between anti-dependent VFP11 instructions to properly avoid
5008 triggering the erratum, hence the use of the extra state 1. */
5009
5010 /* If we are only performing a partial link do not bother
5011 to construct any glue. */
5012 if (link_info->relocatable)
5013 return TRUE;
5014
5015 /* Skip if this bfd does not correspond to an ELF image. */
5016 if (! is_arm_elf (abfd))
5017 return TRUE;
5018
5019 /* We should have chosen a fix type by the time we get here. */
5020 BFD_ASSERT (globals->vfp11_fix != BFD_ARM_VFP11_FIX_DEFAULT);
5021
5022 if (globals->vfp11_fix == BFD_ARM_VFP11_FIX_NONE)
5023 return TRUE;
5024
5025 for (sec = abfd->sections; sec != NULL; sec = sec->next)
5026 {
5027 unsigned int i, span, first_fmac = 0, veneer_of_insn = 0;
5028 struct _arm_elf_section_data *sec_data;
5029
5030 /* If we don't have executable progbits, we're not interested in this
5031 section. Also skip if section is to be excluded. */
5032 if (elf_section_type (sec) != SHT_PROGBITS
5033 || (elf_section_flags (sec) & SHF_EXECINSTR) == 0
5034 || (sec->flags & SEC_EXCLUDE) != 0
5035 || strcmp (sec->name, VFP11_ERRATUM_VENEER_SECTION_NAME) == 0)
5036 continue;
5037
5038 sec_data = elf32_arm_section_data (sec);
5039
5040 if (sec_data->mapcount == 0)
5041 continue;
5042
5043 if (elf_section_data (sec)->this_hdr.contents != NULL)
5044 contents = elf_section_data (sec)->this_hdr.contents;
5045 else if (! bfd_malloc_and_get_section (abfd, sec, &contents))
5046 goto error_return;
5047
5048 qsort (sec_data->map, sec_data->mapcount, sizeof (elf32_arm_section_map),
5049 elf32_arm_compare_mapping);
5050
5051 for (span = 0; span < sec_data->mapcount; span++)
5052 {
5053 unsigned int span_start = sec_data->map[span].vma;
5054 unsigned int span_end = (span == sec_data->mapcount - 1)
5055 ? sec->size : sec_data->map[span + 1].vma;
5056 char span_type = sec_data->map[span].type;
5057
5058 /* FIXME: Only ARM mode is supported at present. We may need to
5059 support Thumb-2 mode also at some point. */
5060 if (span_type != 'a')
5061 continue;
5062
5063 for (i = span_start; i < span_end;)
5064 {
5065 unsigned int next_i = i + 4;
5066 unsigned int insn = bfd_big_endian (abfd)
5067 ? (contents[i] << 24)
5068 | (contents[i + 1] << 16)
5069 | (contents[i + 2] << 8)
5070 | contents[i + 3]
5071 : (contents[i + 3] << 24)
5072 | (contents[i + 2] << 16)
5073 | (contents[i + 1] << 8)
5074 | contents[i];
5075 unsigned int writemask = 0;
5076 enum bfd_arm_vfp11_pipe pipe;
5077
5078 switch (state)
5079 {
5080 case 0:
5081 pipe = bfd_arm_vfp11_insn_decode (insn, &writemask, regs,
5082 &numregs);
5083 /* I'm assuming the VFP11 erratum can trigger with denorm
5084 operands on either the FMAC or the DS pipeline. This might
5085 lead to slightly overenthusiastic veneer insertion. */
5086 if (pipe == VFP11_FMAC || pipe == VFP11_DS)
5087 {
5088 state = use_vector ? 1 : 2;
5089 first_fmac = i;
5090 veneer_of_insn = insn;
5091 }
5092 break;
5093
5094 case 1:
5095 {
5096 int other_regs[3], other_numregs;
5097 pipe = bfd_arm_vfp11_insn_decode (insn, &writemask,
5098 other_regs,
5099 &other_numregs);
5100 if (pipe != VFP11_BAD
5101 && bfd_arm_vfp11_antidependency (writemask, regs,
5102 numregs))
5103 state = 3;
5104 else
5105 state = 2;
5106 }
5107 break;
5108
5109 case 2:
5110 {
5111 int other_regs[3], other_numregs;
5112 pipe = bfd_arm_vfp11_insn_decode (insn, &writemask,
5113 other_regs,
5114 &other_numregs);
5115 if (pipe != VFP11_BAD
5116 && bfd_arm_vfp11_antidependency (writemask, regs,
5117 numregs))
5118 state = 3;
5119 else
5120 {
5121 state = 0;
5122 next_i = first_fmac + 4;
5123 }
5124 }
5125 break;
5126
5127 case 3:
5128 abort (); /* Should be unreachable. */
5129 }
5130
5131 if (state == 3)
5132 {
5133 elf32_vfp11_erratum_list *newerr
5134 = bfd_zmalloc (sizeof (elf32_vfp11_erratum_list));
5135 int errcount;
5136
5137 errcount = ++(elf32_arm_section_data (sec)->erratumcount);
5138
5139 newerr->u.b.vfp_insn = veneer_of_insn;
5140
5141 switch (span_type)
5142 {
5143 case 'a':
5144 newerr->type = VFP11_ERRATUM_BRANCH_TO_ARM_VENEER;
5145 break;
5146
5147 default:
5148 abort ();
5149 }
5150
5151 record_vfp11_erratum_veneer (link_info, newerr, abfd, sec,
5152 first_fmac);
5153
5154 newerr->vma = -1;
5155
5156 newerr->next = sec_data->erratumlist;
5157 sec_data->erratumlist = newerr;
5158
5159 state = 0;
5160 }
5161
5162 i = next_i;
5163 }
5164 }
5165
5166 if (contents != NULL
5167 && elf_section_data (sec)->this_hdr.contents != contents)
5168 free (contents);
5169 contents = NULL;
5170 }
5171
5172 return TRUE;
5173
5174 error_return:
5175 if (contents != NULL
5176 && elf_section_data (sec)->this_hdr.contents != contents)
5177 free (contents);
5178
5179 return FALSE;
5180 }
5181
5182 /* Find virtual-memory addresses for VFP11 erratum veneers and return locations
5183 after sections have been laid out, using specially-named symbols. */
5184
5185 void
5186 bfd_elf32_arm_vfp11_fix_veneer_locations (bfd *abfd,
5187 struct bfd_link_info *link_info)
5188 {
5189 asection *sec;
5190 struct elf32_arm_link_hash_table *globals;
5191 char *tmp_name;
5192
5193 if (link_info->relocatable)
5194 return;
5195
5196 /* Skip if this bfd does not correspond to an ELF image. */
5197 if (! is_arm_elf (abfd))
5198 return;
5199
5200 globals = elf32_arm_hash_table (link_info);
5201
5202 tmp_name = bfd_malloc ((bfd_size_type) strlen
5203 (VFP11_ERRATUM_VENEER_ENTRY_NAME) + 10);
5204
5205 for (sec = abfd->sections; sec != NULL; sec = sec->next)
5206 {
5207 struct _arm_elf_section_data *sec_data = elf32_arm_section_data (sec);
5208 elf32_vfp11_erratum_list *errnode = sec_data->erratumlist;
5209
5210 for (; errnode != NULL; errnode = errnode->next)
5211 {
5212 struct elf_link_hash_entry *myh;
5213 bfd_vma vma;
5214
5215 switch (errnode->type)
5216 {
5217 case VFP11_ERRATUM_BRANCH_TO_ARM_VENEER:
5218 case VFP11_ERRATUM_BRANCH_TO_THUMB_VENEER:
5219 /* Find veneer symbol. */
5220 sprintf (tmp_name, VFP11_ERRATUM_VENEER_ENTRY_NAME,
5221 errnode->u.b.veneer->u.v.id);
5222
5223 myh = elf_link_hash_lookup
5224 (&(globals)->root, tmp_name, FALSE, FALSE, TRUE);
5225
5226 if (myh == NULL)
5227 (*_bfd_error_handler) (_("%B: unable to find VFP11 veneer "
5228 "`%s'"), abfd, tmp_name);
5229
5230 vma = myh->root.u.def.section->output_section->vma
5231 + myh->root.u.def.section->output_offset
5232 + myh->root.u.def.value;
5233
5234 errnode->u.b.veneer->vma = vma;
5235 break;
5236
5237 case VFP11_ERRATUM_ARM_VENEER:
5238 case VFP11_ERRATUM_THUMB_VENEER:
5239 /* Find return location. */
5240 sprintf (tmp_name, VFP11_ERRATUM_VENEER_ENTRY_NAME "_r",
5241 errnode->u.v.id);
5242
5243 myh = elf_link_hash_lookup
5244 (&(globals)->root, tmp_name, FALSE, FALSE, TRUE);
5245
5246 if (myh == NULL)
5247 (*_bfd_error_handler) (_("%B: unable to find VFP11 veneer "
5248 "`%s'"), abfd, tmp_name);
5249
5250 vma = myh->root.u.def.section->output_section->vma
5251 + myh->root.u.def.section->output_offset
5252 + myh->root.u.def.value;
5253
5254 errnode->u.v.branch->vma = vma;
5255 break;
5256
5257 default:
5258 abort ();
5259 }
5260 }
5261 }
5262
5263 free (tmp_name);
5264 }
5265
5266
5267 /* Set target relocation values needed during linking. */
5268
5269 void
5270 bfd_elf32_arm_set_target_relocs (struct bfd *output_bfd,
5271 struct bfd_link_info *link_info,
5272 int target1_is_rel,
5273 char * target2_type,
5274 int fix_v4bx,
5275 int use_blx,
5276 bfd_arm_vfp11_fix vfp11_fix,
5277 int no_enum_warn, int no_wchar_warn,
5278 int pic_veneer)
5279 {
5280 struct elf32_arm_link_hash_table *globals;
5281
5282 globals = elf32_arm_hash_table (link_info);
5283
5284 globals->target1_is_rel = target1_is_rel;
5285 if (strcmp (target2_type, "rel") == 0)
5286 globals->target2_reloc = R_ARM_REL32;
5287 else if (strcmp (target2_type, "abs") == 0)
5288 globals->target2_reloc = R_ARM_ABS32;
5289 else if (strcmp (target2_type, "got-rel") == 0)
5290 globals->target2_reloc = R_ARM_GOT_PREL;
5291 else
5292 {
5293 _bfd_error_handler (_("Invalid TARGET2 relocation type '%s'."),
5294 target2_type);
5295 }
5296 globals->fix_v4bx = fix_v4bx;
5297 globals->use_blx |= use_blx;
5298 globals->vfp11_fix = vfp11_fix;
5299 globals->pic_veneer = pic_veneer;
5300
5301 BFD_ASSERT (is_arm_elf (output_bfd));
5302 elf_arm_tdata (output_bfd)->no_enum_size_warning = no_enum_warn;
5303 elf_arm_tdata (output_bfd)->no_wchar_size_warning = no_wchar_warn;
5304 }
5305
5306 /* Replace the target offset of a Thumb bl or b.w instruction. */
5307
5308 static void
5309 insert_thumb_branch (bfd *abfd, long int offset, bfd_byte *insn)
5310 {
5311 bfd_vma upper;
5312 bfd_vma lower;
5313 int reloc_sign;
5314
5315 BFD_ASSERT ((offset & 1) == 0);
5316
5317 upper = bfd_get_16 (abfd, insn);
5318 lower = bfd_get_16 (abfd, insn + 2);
5319 reloc_sign = (offset < 0) ? 1 : 0;
5320 upper = (upper & ~(bfd_vma) 0x7ff)
5321 | ((offset >> 12) & 0x3ff)
5322 | (reloc_sign << 10);
5323 lower = (lower & ~(bfd_vma) 0x2fff)
5324 | (((!((offset >> 23) & 1)) ^ reloc_sign) << 13)
5325 | (((!((offset >> 22) & 1)) ^ reloc_sign) << 11)
5326 | ((offset >> 1) & 0x7ff);
5327 bfd_put_16 (abfd, upper, insn);
5328 bfd_put_16 (abfd, lower, insn + 2);
5329 }
5330
5331 /* Thumb code calling an ARM function. */
5332
5333 static int
5334 elf32_thumb_to_arm_stub (struct bfd_link_info * info,
5335 const char * name,
5336 bfd * input_bfd,
5337 bfd * output_bfd,
5338 asection * input_section,
5339 bfd_byte * hit_data,
5340 asection * sym_sec,
5341 bfd_vma offset,
5342 bfd_signed_vma addend,
5343 bfd_vma val,
5344 char **error_message)
5345 {
5346 asection * s = 0;
5347 bfd_vma my_offset;
5348 long int ret_offset;
5349 struct elf_link_hash_entry * myh;
5350 struct elf32_arm_link_hash_table * globals;
5351
5352 myh = find_thumb_glue (info, name, error_message);
5353 if (myh == NULL)
5354 return FALSE;
5355
5356 globals = elf32_arm_hash_table (info);
5357
5358 BFD_ASSERT (globals != NULL);
5359 BFD_ASSERT (globals->bfd_of_glue_owner != NULL);
5360
5361 my_offset = myh->root.u.def.value;
5362
5363 s = bfd_get_section_by_name (globals->bfd_of_glue_owner,
5364 THUMB2ARM_GLUE_SECTION_NAME);
5365
5366 BFD_ASSERT (s != NULL);
5367 BFD_ASSERT (s->contents != NULL);
5368 BFD_ASSERT (s->output_section != NULL);
5369
5370 if ((my_offset & 0x01) == 0x01)
5371 {
5372 if (sym_sec != NULL
5373 && sym_sec->owner != NULL
5374 && !INTERWORK_FLAG (sym_sec->owner))
5375 {
5376 (*_bfd_error_handler)
5377 (_("%B(%s): warning: interworking not enabled.\n"
5378 " first occurrence: %B: thumb call to arm"),
5379 sym_sec->owner, input_bfd, name);
5380
5381 return FALSE;
5382 }
5383
5384 --my_offset;
5385 myh->root.u.def.value = my_offset;
5386
5387 put_thumb_insn (globals, output_bfd, (bfd_vma) t2a1_bx_pc_insn,
5388 s->contents + my_offset);
5389
5390 put_thumb_insn (globals, output_bfd, (bfd_vma) t2a2_noop_insn,
5391 s->contents + my_offset + 2);
5392
5393 ret_offset =
5394 /* Address of destination of the stub. */
5395 ((bfd_signed_vma) val)
5396 - ((bfd_signed_vma)
5397 /* Offset from the start of the current section
5398 to the start of the stubs. */
5399 (s->output_offset
5400 /* Offset of the start of this stub from the start of the stubs. */
5401 + my_offset
5402 /* Address of the start of the current section. */
5403 + s->output_section->vma)
5404 /* The branch instruction is 4 bytes into the stub. */
5405 + 4
5406 /* ARM branches work from the pc of the instruction + 8. */
5407 + 8);
5408
5409 put_arm_insn (globals, output_bfd,
5410 (bfd_vma) t2a3_b_insn | ((ret_offset >> 2) & 0x00FFFFFF),
5411 s->contents + my_offset + 4);
5412 }
5413
5414 BFD_ASSERT (my_offset <= globals->thumb_glue_size);
5415
5416 /* Now go back and fix up the original BL insn to point to here. */
5417 ret_offset =
5418 /* Address of where the stub is located. */
5419 (s->output_section->vma + s->output_offset + my_offset)
5420 /* Address of where the BL is located. */
5421 - (input_section->output_section->vma + input_section->output_offset
5422 + offset)
5423 /* Addend in the relocation. */
5424 - addend
5425 /* Biassing for PC-relative addressing. */
5426 - 8;
5427
5428 insert_thumb_branch (input_bfd, ret_offset, hit_data - input_section->vma);
5429
5430 return TRUE;
5431 }
5432
5433 /* Populate an Arm to Thumb stub. Returns the stub symbol. */
5434
5435 static struct elf_link_hash_entry *
5436 elf32_arm_create_thumb_stub (struct bfd_link_info * info,
5437 const char * name,
5438 bfd * input_bfd,
5439 bfd * output_bfd,
5440 asection * sym_sec,
5441 bfd_vma val,
5442 asection *s,
5443 char **error_message)
5444 {
5445 bfd_vma my_offset;
5446 long int ret_offset;
5447 struct elf_link_hash_entry * myh;
5448 struct elf32_arm_link_hash_table * globals;
5449
5450 myh = find_arm_glue (info, name, error_message);
5451 if (myh == NULL)
5452 return NULL;
5453
5454 globals = elf32_arm_hash_table (info);
5455
5456 BFD_ASSERT (globals != NULL);
5457 BFD_ASSERT (globals->bfd_of_glue_owner != NULL);
5458
5459 my_offset = myh->root.u.def.value;
5460
5461 if ((my_offset & 0x01) == 0x01)
5462 {
5463 if (sym_sec != NULL
5464 && sym_sec->owner != NULL
5465 && !INTERWORK_FLAG (sym_sec->owner))
5466 {
5467 (*_bfd_error_handler)
5468 (_("%B(%s): warning: interworking not enabled.\n"
5469 " first occurrence: %B: arm call to thumb"),
5470 sym_sec->owner, input_bfd, name);
5471 }
5472
5473 --my_offset;
5474 myh->root.u.def.value = my_offset;
5475
5476 if (info->shared || globals->root.is_relocatable_executable
5477 || globals->pic_veneer)
5478 {
5479 /* For relocatable objects we can't use absolute addresses,
5480 so construct the address from a relative offset. */
5481 /* TODO: If the offset is small it's probably worth
5482 constructing the address with adds. */
5483 put_arm_insn (globals, output_bfd, (bfd_vma) a2t1p_ldr_insn,
5484 s->contents + my_offset);
5485 put_arm_insn (globals, output_bfd, (bfd_vma) a2t2p_add_pc_insn,
5486 s->contents + my_offset + 4);
5487 put_arm_insn (globals, output_bfd, (bfd_vma) a2t3p_bx_r12_insn,
5488 s->contents + my_offset + 8);
5489 /* Adjust the offset by 4 for the position of the add,
5490 and 8 for the pipeline offset. */
5491 ret_offset = (val - (s->output_offset
5492 + s->output_section->vma
5493 + my_offset + 12))
5494 | 1;
5495 bfd_put_32 (output_bfd, ret_offset,
5496 s->contents + my_offset + 12);
5497 }
5498 else if (globals->use_blx)
5499 {
5500 put_arm_insn (globals, output_bfd, (bfd_vma) a2t1v5_ldr_insn,
5501 s->contents + my_offset);
5502
5503 /* It's a thumb address. Add the low order bit. */
5504 bfd_put_32 (output_bfd, val | a2t2v5_func_addr_insn,
5505 s->contents + my_offset + 4);
5506 }
5507 else
5508 {
5509 put_arm_insn (globals, output_bfd, (bfd_vma) a2t1_ldr_insn,
5510 s->contents + my_offset);
5511
5512 put_arm_insn (globals, output_bfd, (bfd_vma) a2t2_bx_r12_insn,
5513 s->contents + my_offset + 4);
5514
5515 /* It's a thumb address. Add the low order bit. */
5516 bfd_put_32 (output_bfd, val | a2t3_func_addr_insn,
5517 s->contents + my_offset + 8);
5518 }
5519 }
5520
5521 BFD_ASSERT (my_offset <= globals->arm_glue_size);
5522
5523 return myh;
5524 }
5525
5526 /* Arm code calling a Thumb function. */
5527
5528 static int
5529 elf32_arm_to_thumb_stub (struct bfd_link_info * info,
5530 const char * name,
5531 bfd * input_bfd,
5532 bfd * output_bfd,
5533 asection * input_section,
5534 bfd_byte * hit_data,
5535 asection * sym_sec,
5536 bfd_vma offset,
5537 bfd_signed_vma addend,
5538 bfd_vma val,
5539 char **error_message)
5540 {
5541 unsigned long int tmp;
5542 bfd_vma my_offset;
5543 asection * s;
5544 long int ret_offset;
5545 struct elf_link_hash_entry * myh;
5546 struct elf32_arm_link_hash_table * globals;
5547
5548 globals = elf32_arm_hash_table (info);
5549
5550 BFD_ASSERT (globals != NULL);
5551 BFD_ASSERT (globals->bfd_of_glue_owner != NULL);
5552
5553 s = bfd_get_section_by_name (globals->bfd_of_glue_owner,
5554 ARM2THUMB_GLUE_SECTION_NAME);
5555 BFD_ASSERT (s != NULL);
5556 BFD_ASSERT (s->contents != NULL);
5557 BFD_ASSERT (s->output_section != NULL);
5558
5559 myh = elf32_arm_create_thumb_stub (info, name, input_bfd, output_bfd,
5560 sym_sec, val, s, error_message);
5561 if (!myh)
5562 return FALSE;
5563
5564 my_offset = myh->root.u.def.value;
5565 tmp = bfd_get_32 (input_bfd, hit_data);
5566 tmp = tmp & 0xFF000000;
5567
5568 /* Somehow these are both 4 too far, so subtract 8. */
5569 ret_offset = (s->output_offset
5570 + my_offset
5571 + s->output_section->vma
5572 - (input_section->output_offset
5573 + input_section->output_section->vma
5574 + offset + addend)
5575 - 8);
5576
5577 tmp = tmp | ((ret_offset >> 2) & 0x00FFFFFF);
5578
5579 bfd_put_32 (output_bfd, (bfd_vma) tmp, hit_data - input_section->vma);
5580
5581 return TRUE;
5582 }
5583
5584 /* Populate Arm stub for an exported Thumb function. */
5585
5586 static bfd_boolean
5587 elf32_arm_to_thumb_export_stub (struct elf_link_hash_entry *h, void * inf)
5588 {
5589 struct bfd_link_info * info = (struct bfd_link_info *) inf;
5590 asection * s;
5591 struct elf_link_hash_entry * myh;
5592 struct elf32_arm_link_hash_entry *eh;
5593 struct elf32_arm_link_hash_table * globals;
5594 asection *sec;
5595 bfd_vma val;
5596 char *error_message;
5597
5598 eh = elf32_arm_hash_entry (h);
5599 /* Allocate stubs for exported Thumb functions on v4t. */
5600 if (eh->export_glue == NULL)
5601 return TRUE;
5602
5603 globals = elf32_arm_hash_table (info);
5604
5605 BFD_ASSERT (globals != NULL);
5606 BFD_ASSERT (globals->bfd_of_glue_owner != NULL);
5607
5608 s = bfd_get_section_by_name (globals->bfd_of_glue_owner,
5609 ARM2THUMB_GLUE_SECTION_NAME);
5610 BFD_ASSERT (s != NULL);
5611 BFD_ASSERT (s->contents != NULL);
5612 BFD_ASSERT (s->output_section != NULL);
5613
5614 sec = eh->export_glue->root.u.def.section;
5615
5616 BFD_ASSERT (sec->output_section != NULL);
5617
5618 val = eh->export_glue->root.u.def.value + sec->output_offset
5619 + sec->output_section->vma;
5620 myh = elf32_arm_create_thumb_stub (info, h->root.root.string,
5621 h->root.u.def.section->owner,
5622 globals->obfd, sec, val, s,
5623 &error_message);
5624 BFD_ASSERT (myh);
5625 return TRUE;
5626 }
5627
5628 /* Populate ARMv4 BX veneers. Returns the absolute adress of the veneer. */
5629
5630 static bfd_vma
5631 elf32_arm_bx_glue (struct bfd_link_info * info, int reg)
5632 {
5633 bfd_byte *p;
5634 bfd_vma glue_addr;
5635 asection *s;
5636 struct elf32_arm_link_hash_table *globals;
5637
5638 globals = elf32_arm_hash_table (info);
5639
5640 BFD_ASSERT (globals != NULL);
5641 BFD_ASSERT (globals->bfd_of_glue_owner != NULL);
5642
5643 s = bfd_get_section_by_name (globals->bfd_of_glue_owner,
5644 ARM_BX_GLUE_SECTION_NAME);
5645 BFD_ASSERT (s != NULL);
5646 BFD_ASSERT (s->contents != NULL);
5647 BFD_ASSERT (s->output_section != NULL);
5648
5649 BFD_ASSERT (globals->bx_glue_offset[reg] & 2);
5650
5651 glue_addr = globals->bx_glue_offset[reg] & ~(bfd_vma)3;
5652
5653 if ((globals->bx_glue_offset[reg] & 1) == 0)
5654 {
5655 p = s->contents + glue_addr;
5656 bfd_put_32 (globals->obfd, armbx1_tst_insn + (reg << 16), p);
5657 bfd_put_32 (globals->obfd, armbx2_moveq_insn + reg, p + 4);
5658 bfd_put_32 (globals->obfd, armbx3_bx_insn + reg, p + 8);
5659 globals->bx_glue_offset[reg] |= 1;
5660 }
5661
5662 return glue_addr + s->output_section->vma + s->output_offset;
5663 }
5664
5665 /* Generate Arm stubs for exported Thumb symbols. */
5666 static void
5667 elf32_arm_begin_write_processing (bfd *abfd ATTRIBUTE_UNUSED,
5668 struct bfd_link_info *link_info)
5669 {
5670 struct elf32_arm_link_hash_table * globals;
5671
5672 if (!link_info)
5673 return;
5674
5675 globals = elf32_arm_hash_table (link_info);
5676 /* If blx is available then exported Thumb symbols are OK and there is
5677 nothing to do. */
5678 if (globals->use_blx)
5679 return;
5680
5681 elf_link_hash_traverse (&globals->root, elf32_arm_to_thumb_export_stub,
5682 link_info);
5683 }
5684
5685 /* Some relocations map to different relocations depending on the
5686 target. Return the real relocation. */
5687 static int
5688 arm_real_reloc_type (struct elf32_arm_link_hash_table * globals,
5689 int r_type)
5690 {
5691 switch (r_type)
5692 {
5693 case R_ARM_TARGET1:
5694 if (globals->target1_is_rel)
5695 return R_ARM_REL32;
5696 else
5697 return R_ARM_ABS32;
5698
5699 case R_ARM_TARGET2:
5700 return globals->target2_reloc;
5701
5702 default:
5703 return r_type;
5704 }
5705 }
5706
5707 /* Return the base VMA address which should be subtracted from real addresses
5708 when resolving @dtpoff relocation.
5709 This is PT_TLS segment p_vaddr. */
5710
5711 static bfd_vma
5712 dtpoff_base (struct bfd_link_info *info)
5713 {
5714 /* If tls_sec is NULL, we should have signalled an error already. */
5715 if (elf_hash_table (info)->tls_sec == NULL)
5716 return 0;
5717 return elf_hash_table (info)->tls_sec->vma;
5718 }
5719
5720 /* Return the relocation value for @tpoff relocation
5721 if STT_TLS virtual address is ADDRESS. */
5722
5723 static bfd_vma
5724 tpoff (struct bfd_link_info *info, bfd_vma address)
5725 {
5726 struct elf_link_hash_table *htab = elf_hash_table (info);
5727 bfd_vma base;
5728
5729 /* If tls_sec is NULL, we should have signalled an error already. */
5730 if (htab->tls_sec == NULL)
5731 return 0;
5732 base = align_power ((bfd_vma) TCB_SIZE, htab->tls_sec->alignment_power);
5733 return address - htab->tls_sec->vma + base;
5734 }
5735
5736 /* Perform an R_ARM_ABS12 relocation on the field pointed to by DATA.
5737 VALUE is the relocation value. */
5738
5739 static bfd_reloc_status_type
5740 elf32_arm_abs12_reloc (bfd *abfd, void *data, bfd_vma value)
5741 {
5742 if (value > 0xfff)
5743 return bfd_reloc_overflow;
5744
5745 value |= bfd_get_32 (abfd, data) & 0xfffff000;
5746 bfd_put_32 (abfd, value, data);
5747 return bfd_reloc_ok;
5748 }
5749
5750 /* For a given value of n, calculate the value of G_n as required to
5751 deal with group relocations. We return it in the form of an
5752 encoded constant-and-rotation, together with the final residual. If n is
5753 specified as less than zero, then final_residual is filled with the
5754 input value and no further action is performed. */
5755
5756 static bfd_vma
5757 calculate_group_reloc_mask (bfd_vma value, int n, bfd_vma *final_residual)
5758 {
5759 int current_n;
5760 bfd_vma g_n;
5761 bfd_vma encoded_g_n = 0;
5762 bfd_vma residual = value; /* Also known as Y_n. */
5763
5764 for (current_n = 0; current_n <= n; current_n++)
5765 {
5766 int shift;
5767
5768 /* Calculate which part of the value to mask. */
5769 if (residual == 0)
5770 shift = 0;
5771 else
5772 {
5773 int msb;
5774
5775 /* Determine the most significant bit in the residual and
5776 align the resulting value to a 2-bit boundary. */
5777 for (msb = 30; msb >= 0; msb -= 2)
5778 if (residual & (3 << msb))
5779 break;
5780
5781 /* The desired shift is now (msb - 6), or zero, whichever
5782 is the greater. */
5783 shift = msb - 6;
5784 if (shift < 0)
5785 shift = 0;
5786 }
5787
5788 /* Calculate g_n in 32-bit as well as encoded constant+rotation form. */
5789 g_n = residual & (0xff << shift);
5790 encoded_g_n = (g_n >> shift)
5791 | ((g_n <= 0xff ? 0 : (32 - shift) / 2) << 8);
5792
5793 /* Calculate the residual for the next time around. */
5794 residual &= ~g_n;
5795 }
5796
5797 *final_residual = residual;
5798
5799 return encoded_g_n;
5800 }
5801
5802 /* Given an ARM instruction, determine whether it is an ADD or a SUB.
5803 Returns 1 if it is an ADD, -1 if it is a SUB, and 0 otherwise. */
5804
5805 static int
5806 identify_add_or_sub (bfd_vma insn)
5807 {
5808 int opcode = insn & 0x1e00000;
5809
5810 if (opcode == 1 << 23) /* ADD */
5811 return 1;
5812
5813 if (opcode == 1 << 22) /* SUB */
5814 return -1;
5815
5816 return 0;
5817 }
5818
5819 /* Perform a relocation as part of a final link. */
5820
5821 static bfd_reloc_status_type
5822 elf32_arm_final_link_relocate (reloc_howto_type * howto,
5823 bfd * input_bfd,
5824 bfd * output_bfd,
5825 asection * input_section,
5826 bfd_byte * contents,
5827 Elf_Internal_Rela * rel,
5828 bfd_vma value,
5829 struct bfd_link_info * info,
5830 asection * sym_sec,
5831 const char * sym_name,
5832 int sym_flags,
5833 struct elf_link_hash_entry * h,
5834 bfd_boolean * unresolved_reloc_p,
5835 char **error_message)
5836 {
5837 unsigned long r_type = howto->type;
5838 unsigned long r_symndx;
5839 bfd_byte * hit_data = contents + rel->r_offset;
5840 bfd * dynobj = NULL;
5841 Elf_Internal_Shdr * symtab_hdr;
5842 struct elf_link_hash_entry ** sym_hashes;
5843 bfd_vma * local_got_offsets;
5844 asection * sgot = NULL;
5845 asection * splt = NULL;
5846 asection * sreloc = NULL;
5847 bfd_vma addend;
5848 bfd_signed_vma signed_addend;
5849 struct elf32_arm_link_hash_table * globals;
5850
5851 globals = elf32_arm_hash_table (info);
5852
5853 BFD_ASSERT (is_arm_elf (input_bfd));
5854
5855 /* Some relocation types map to different relocations depending on the
5856 target. We pick the right one here. */
5857 r_type = arm_real_reloc_type (globals, r_type);
5858 if (r_type != howto->type)
5859 howto = elf32_arm_howto_from_type (r_type);
5860
5861 /* If the start address has been set, then set the EF_ARM_HASENTRY
5862 flag. Setting this more than once is redundant, but the cost is
5863 not too high, and it keeps the code simple.
5864
5865 The test is done here, rather than somewhere else, because the
5866 start address is only set just before the final link commences.
5867
5868 Note - if the user deliberately sets a start address of 0, the
5869 flag will not be set. */
5870 if (bfd_get_start_address (output_bfd) != 0)
5871 elf_elfheader (output_bfd)->e_flags |= EF_ARM_HASENTRY;
5872
5873 dynobj = elf_hash_table (info)->dynobj;
5874 if (dynobj)
5875 {
5876 sgot = bfd_get_section_by_name (dynobj, ".got");
5877 splt = bfd_get_section_by_name (dynobj, ".plt");
5878 }
5879 symtab_hdr = & elf_symtab_hdr (input_bfd);
5880 sym_hashes = elf_sym_hashes (input_bfd);
5881 local_got_offsets = elf_local_got_offsets (input_bfd);
5882 r_symndx = ELF32_R_SYM (rel->r_info);
5883
5884 if (globals->use_rel)
5885 {
5886 addend = bfd_get_32 (input_bfd, hit_data) & howto->src_mask;
5887
5888 if (addend & ((howto->src_mask + 1) >> 1))
5889 {
5890 signed_addend = -1;
5891 signed_addend &= ~ howto->src_mask;
5892 signed_addend |= addend;
5893 }
5894 else
5895 signed_addend = addend;
5896 }
5897 else
5898 addend = signed_addend = rel->r_addend;
5899
5900 switch (r_type)
5901 {
5902 case R_ARM_NONE:
5903 /* We don't need to find a value for this symbol. It's just a
5904 marker. */
5905 *unresolved_reloc_p = FALSE;
5906 return bfd_reloc_ok;
5907
5908 case R_ARM_ABS12:
5909 if (!globals->vxworks_p)
5910 return elf32_arm_abs12_reloc (input_bfd, hit_data, value + addend);
5911
5912 case R_ARM_PC24:
5913 case R_ARM_ABS32:
5914 case R_ARM_ABS32_NOI:
5915 case R_ARM_REL32:
5916 case R_ARM_REL32_NOI:
5917 case R_ARM_CALL:
5918 case R_ARM_JUMP24:
5919 case R_ARM_XPC25:
5920 case R_ARM_PREL31:
5921 case R_ARM_PLT32:
5922 /* Handle relocations which should use the PLT entry. ABS32/REL32
5923 will use the symbol's value, which may point to a PLT entry, but we
5924 don't need to handle that here. If we created a PLT entry, all
5925 branches in this object should go to it. */
5926 if ((r_type != R_ARM_ABS32 && r_type != R_ARM_REL32
5927 && r_type != R_ARM_ABS32_NOI && r_type != R_ARM_REL32_NOI)
5928 && h != NULL
5929 && splt != NULL
5930 && h->plt.offset != (bfd_vma) -1)
5931 {
5932 /* If we've created a .plt section, and assigned a PLT entry to
5933 this function, it should not be known to bind locally. If
5934 it were, we would have cleared the PLT entry. */
5935 BFD_ASSERT (!SYMBOL_CALLS_LOCAL (info, h));
5936
5937 value = (splt->output_section->vma
5938 + splt->output_offset
5939 + h->plt.offset);
5940 *unresolved_reloc_p = FALSE;
5941 return _bfd_final_link_relocate (howto, input_bfd, input_section,
5942 contents, rel->r_offset, value,
5943 rel->r_addend);
5944 }
5945
5946 /* When generating a shared object or relocatable executable, these
5947 relocations are copied into the output file to be resolved at
5948 run time. */
5949 if ((info->shared || globals->root.is_relocatable_executable)
5950 && (input_section->flags & SEC_ALLOC)
5951 && !(elf32_arm_hash_table (info)->vxworks_p
5952 && strcmp (input_section->output_section->name,
5953 ".tls_vars") == 0)
5954 && ((r_type != R_ARM_REL32 && r_type != R_ARM_REL32_NOI)
5955 || !SYMBOL_CALLS_LOCAL (info, h))
5956 && (h == NULL
5957 || ELF_ST_VISIBILITY (h->other) == STV_DEFAULT
5958 || h->root.type != bfd_link_hash_undefweak)
5959 && r_type != R_ARM_PC24
5960 && r_type != R_ARM_CALL
5961 && r_type != R_ARM_JUMP24
5962 && r_type != R_ARM_PREL31
5963 && r_type != R_ARM_PLT32)
5964 {
5965 Elf_Internal_Rela outrel;
5966 bfd_byte *loc;
5967 bfd_boolean skip, relocate;
5968
5969 *unresolved_reloc_p = FALSE;
5970
5971 if (sreloc == NULL)
5972 {
5973 const char * name;
5974
5975 name = (bfd_elf_string_from_elf_section
5976 (input_bfd,
5977 elf_elfheader (input_bfd)->e_shstrndx,
5978 elf_section_data (input_section)->rel_hdr.sh_name));
5979 if (name == NULL)
5980 return bfd_reloc_notsupported;
5981
5982 BFD_ASSERT (reloc_section_p (globals, name, input_section));
5983
5984 sreloc = bfd_get_section_by_name (dynobj, name);
5985 BFD_ASSERT (sreloc != NULL);
5986 }
5987
5988 skip = FALSE;
5989 relocate = FALSE;
5990
5991 outrel.r_addend = addend;
5992 outrel.r_offset =
5993 _bfd_elf_section_offset (output_bfd, info, input_section,
5994 rel->r_offset);
5995 if (outrel.r_offset == (bfd_vma) -1)
5996 skip = TRUE;
5997 else if (outrel.r_offset == (bfd_vma) -2)
5998 skip = TRUE, relocate = TRUE;
5999 outrel.r_offset += (input_section->output_section->vma
6000 + input_section->output_offset);
6001
6002 if (skip)
6003 memset (&outrel, 0, sizeof outrel);
6004 else if (h != NULL
6005 && h->dynindx != -1
6006 && (!info->shared
6007 || !info->symbolic
6008 || !h->def_regular))
6009 outrel.r_info = ELF32_R_INFO (h->dynindx, r_type);
6010 else
6011 {
6012 int symbol;
6013
6014 /* This symbol is local, or marked to become local. */
6015 if (sym_flags == STT_ARM_TFUNC)
6016 value |= 1;
6017 if (globals->symbian_p)
6018 {
6019 asection *osec;
6020
6021 /* On Symbian OS, the data segment and text segement
6022 can be relocated independently. Therefore, we
6023 must indicate the segment to which this
6024 relocation is relative. The BPABI allows us to
6025 use any symbol in the right segment; we just use
6026 the section symbol as it is convenient. (We
6027 cannot use the symbol given by "h" directly as it
6028 will not appear in the dynamic symbol table.)
6029
6030 Note that the dynamic linker ignores the section
6031 symbol value, so we don't subtract osec->vma
6032 from the emitted reloc addend. */
6033 if (sym_sec)
6034 osec = sym_sec->output_section;
6035 else
6036 osec = input_section->output_section;
6037 symbol = elf_section_data (osec)->dynindx;
6038 if (symbol == 0)
6039 {
6040 struct elf_link_hash_table *htab = elf_hash_table (info);
6041
6042 if ((osec->flags & SEC_READONLY) == 0
6043 && htab->data_index_section != NULL)
6044 osec = htab->data_index_section;
6045 else
6046 osec = htab->text_index_section;
6047 symbol = elf_section_data (osec)->dynindx;
6048 }
6049 BFD_ASSERT (symbol != 0);
6050 }
6051 else
6052 /* On SVR4-ish systems, the dynamic loader cannot
6053 relocate the text and data segments independently,
6054 so the symbol does not matter. */
6055 symbol = 0;
6056 outrel.r_info = ELF32_R_INFO (symbol, R_ARM_RELATIVE);
6057 if (globals->use_rel)
6058 relocate = TRUE;
6059 else
6060 outrel.r_addend += value;
6061 }
6062
6063 loc = sreloc->contents;
6064 loc += sreloc->reloc_count++ * RELOC_SIZE (globals);
6065 SWAP_RELOC_OUT (globals) (output_bfd, &outrel, loc);
6066
6067 /* If this reloc is against an external symbol, we do not want to
6068 fiddle with the addend. Otherwise, we need to include the symbol
6069 value so that it becomes an addend for the dynamic reloc. */
6070 if (! relocate)
6071 return bfd_reloc_ok;
6072
6073 return _bfd_final_link_relocate (howto, input_bfd, input_section,
6074 contents, rel->r_offset, value,
6075 (bfd_vma) 0);
6076 }
6077 else switch (r_type)
6078 {
6079 case R_ARM_ABS12:
6080 return elf32_arm_abs12_reloc (input_bfd, hit_data, value + addend);
6081
6082 case R_ARM_XPC25: /* Arm BLX instruction. */
6083 case R_ARM_CALL:
6084 case R_ARM_JUMP24:
6085 case R_ARM_PC24: /* Arm B/BL instruction */
6086 case R_ARM_PLT32:
6087 {
6088 bfd_vma from;
6089 bfd_signed_vma branch_offset;
6090 struct elf32_arm_stub_hash_entry *stub_entry = NULL;
6091
6092 from = (input_section->output_section->vma
6093 + input_section->output_offset
6094 + rel->r_offset);
6095 branch_offset = (bfd_signed_vma)(value - from);
6096
6097 if (r_type == R_ARM_XPC25)
6098 {
6099 /* Check for Arm calling Arm function. */
6100 /* FIXME: Should we translate the instruction into a BL
6101 instruction instead ? */
6102 if (sym_flags != STT_ARM_TFUNC)
6103 (*_bfd_error_handler)
6104 (_("\%B: Warning: Arm BLX instruction targets Arm function '%s'."),
6105 input_bfd,
6106 h ? h->root.root.string : "(local)");
6107 }
6108 else if (r_type != R_ARM_CALL)
6109 {
6110 /* Check for Arm calling Thumb function. */
6111 if (sym_flags == STT_ARM_TFUNC)
6112 {
6113 if (elf32_arm_to_thumb_stub (info, sym_name, input_bfd,
6114 output_bfd, input_section,
6115 hit_data, sym_sec, rel->r_offset,
6116 signed_addend, value,
6117 error_message))
6118 return bfd_reloc_ok;
6119 else
6120 return bfd_reloc_dangerous;
6121 }
6122 }
6123
6124 /* Check if a stub has to be inserted because the
6125 destination is too far or we are changing mode */
6126 if (r_type == R_ARM_CALL)
6127 {
6128 if (branch_offset > ARM_MAX_FWD_BRANCH_OFFSET
6129 || branch_offset < ARM_MAX_BWD_BRANCH_OFFSET
6130 || sym_flags == STT_ARM_TFUNC)
6131 {
6132 /* The target is out of reach, so redirect the
6133 branch to the local stub for this function. */
6134
6135 stub_entry = elf32_arm_get_stub_entry (input_section,
6136 sym_sec, h,
6137 rel, globals);
6138 if (stub_entry != NULL)
6139 value = (stub_entry->stub_offset
6140 + stub_entry->stub_sec->output_offset
6141 + stub_entry->stub_sec->output_section->vma);
6142 }
6143 }
6144
6145 /* The ARM ELF ABI says that this reloc is computed as: S - P + A
6146 where:
6147 S is the address of the symbol in the relocation.
6148 P is address of the instruction being relocated.
6149 A is the addend (extracted from the instruction) in bytes.
6150
6151 S is held in 'value'.
6152 P is the base address of the section containing the
6153 instruction plus the offset of the reloc into that
6154 section, ie:
6155 (input_section->output_section->vma +
6156 input_section->output_offset +
6157 rel->r_offset).
6158 A is the addend, converted into bytes, ie:
6159 (signed_addend * 4)
6160
6161 Note: None of these operations have knowledge of the pipeline
6162 size of the processor, thus it is up to the assembler to
6163 encode this information into the addend. */
6164 value -= (input_section->output_section->vma
6165 + input_section->output_offset);
6166 value -= rel->r_offset;
6167 if (globals->use_rel)
6168 value += (signed_addend << howto->size);
6169 else
6170 /* RELA addends do not have to be adjusted by howto->size. */
6171 value += signed_addend;
6172
6173 signed_addend = value;
6174 signed_addend >>= howto->rightshift;
6175
6176 /* A branch to an undefined weak symbol is turned into a jump to
6177 the next instruction. */
6178 if (h && h->root.type == bfd_link_hash_undefweak)
6179 {
6180 value = (bfd_get_32 (input_bfd, hit_data) & 0xf0000000)
6181 | 0x0affffff;
6182 }
6183 else
6184 {
6185 /* Perform a signed range check. */
6186 if ( signed_addend > ((bfd_signed_vma) (howto->dst_mask >> 1))
6187 || signed_addend < - ((bfd_signed_vma) ((howto->dst_mask + 1) >> 1)))
6188 return bfd_reloc_overflow;
6189
6190 addend = (value & 2);
6191
6192 value = (signed_addend & howto->dst_mask)
6193 | (bfd_get_32 (input_bfd, hit_data) & (~ howto->dst_mask));
6194
6195 /* Set the H bit in the BLX instruction. */
6196 if (sym_flags == STT_ARM_TFUNC)
6197 {
6198 if (addend)
6199 value |= (1 << 24);
6200 else
6201 value &= ~(bfd_vma)(1 << 24);
6202 }
6203 if (r_type == R_ARM_CALL)
6204 {
6205 /* Select the correct instruction (BL or BLX). */
6206 /* Only if we are not handling a BL to a stub. In this
6207 case, mode switching is performed by the stub. */
6208 if (sym_flags == STT_ARM_TFUNC && !stub_entry)
6209 value |= (1 << 28);
6210 else
6211 {
6212 value &= ~(bfd_vma)(1 << 28);
6213 value |= (1 << 24);
6214 }
6215 }
6216 }
6217 }
6218 break;
6219
6220 case R_ARM_ABS32:
6221 value += addend;
6222 if (sym_flags == STT_ARM_TFUNC)
6223 value |= 1;
6224 break;
6225
6226 case R_ARM_ABS32_NOI:
6227 value += addend;
6228 break;
6229
6230 case R_ARM_REL32:
6231 value += addend;
6232 if (sym_flags == STT_ARM_TFUNC)
6233 value |= 1;
6234 value -= (input_section->output_section->vma
6235 + input_section->output_offset + rel->r_offset);
6236 break;
6237
6238 case R_ARM_REL32_NOI:
6239 value += addend;
6240 value -= (input_section->output_section->vma
6241 + input_section->output_offset + rel->r_offset);
6242 break;
6243
6244 case R_ARM_PREL31:
6245 value -= (input_section->output_section->vma
6246 + input_section->output_offset + rel->r_offset);
6247 value += signed_addend;
6248 if (! h || h->root.type != bfd_link_hash_undefweak)
6249 {
6250 /* Check for overflow */
6251 if ((value ^ (value >> 1)) & (1 << 30))
6252 return bfd_reloc_overflow;
6253 }
6254 value &= 0x7fffffff;
6255 value |= (bfd_get_32 (input_bfd, hit_data) & 0x80000000);
6256 if (sym_flags == STT_ARM_TFUNC)
6257 value |= 1;
6258 break;
6259 }
6260
6261 bfd_put_32 (input_bfd, value, hit_data);
6262 return bfd_reloc_ok;
6263
6264 case R_ARM_ABS8:
6265 value += addend;
6266 if ((long) value > 0x7f || (long) value < -0x80)
6267 return bfd_reloc_overflow;
6268
6269 bfd_put_8 (input_bfd, value, hit_data);
6270 return bfd_reloc_ok;
6271
6272 case R_ARM_ABS16:
6273 value += addend;
6274
6275 if ((long) value > 0x7fff || (long) value < -0x8000)
6276 return bfd_reloc_overflow;
6277
6278 bfd_put_16 (input_bfd, value, hit_data);
6279 return bfd_reloc_ok;
6280
6281 case R_ARM_THM_ABS5:
6282 /* Support ldr and str instructions for the thumb. */
6283 if (globals->use_rel)
6284 {
6285 /* Need to refetch addend. */
6286 addend = bfd_get_16 (input_bfd, hit_data) & howto->src_mask;
6287 /* ??? Need to determine shift amount from operand size. */
6288 addend >>= howto->rightshift;
6289 }
6290 value += addend;
6291
6292 /* ??? Isn't value unsigned? */
6293 if ((long) value > 0x1f || (long) value < -0x10)
6294 return bfd_reloc_overflow;
6295
6296 /* ??? Value needs to be properly shifted into place first. */
6297 value |= bfd_get_16 (input_bfd, hit_data) & 0xf83f;
6298 bfd_put_16 (input_bfd, value, hit_data);
6299 return bfd_reloc_ok;
6300
6301 case R_ARM_THM_ALU_PREL_11_0:
6302 /* Corresponds to: addw.w reg, pc, #offset (and similarly for subw). */
6303 {
6304 bfd_vma insn;
6305 bfd_signed_vma relocation;
6306
6307 insn = (bfd_get_16 (input_bfd, hit_data) << 16)
6308 | bfd_get_16 (input_bfd, hit_data + 2);
6309
6310 if (globals->use_rel)
6311 {
6312 signed_addend = (insn & 0xff) | ((insn & 0x7000) >> 4)
6313 | ((insn & (1 << 26)) >> 15);
6314 if (insn & 0xf00000)
6315 signed_addend = -signed_addend;
6316 }
6317
6318 relocation = value + signed_addend;
6319 relocation -= (input_section->output_section->vma
6320 + input_section->output_offset
6321 + rel->r_offset);
6322
6323 value = abs (relocation);
6324
6325 if (value >= 0x1000)
6326 return bfd_reloc_overflow;
6327
6328 insn = (insn & 0xfb0f8f00) | (value & 0xff)
6329 | ((value & 0x700) << 4)
6330 | ((value & 0x800) << 15);
6331 if (relocation < 0)
6332 insn |= 0xa00000;
6333
6334 bfd_put_16 (input_bfd, insn >> 16, hit_data);
6335 bfd_put_16 (input_bfd, insn & 0xffff, hit_data + 2);
6336
6337 return bfd_reloc_ok;
6338 }
6339
6340 case R_ARM_THM_PC12:
6341 /* Corresponds to: ldr.w reg, [pc, #offset]. */
6342 {
6343 bfd_vma insn;
6344 bfd_signed_vma relocation;
6345
6346 insn = (bfd_get_16 (input_bfd, hit_data) << 16)
6347 | bfd_get_16 (input_bfd, hit_data + 2);
6348
6349 if (globals->use_rel)
6350 {
6351 signed_addend = insn & 0xfff;
6352 if (!(insn & (1 << 23)))
6353 signed_addend = -signed_addend;
6354 }
6355
6356 relocation = value + signed_addend;
6357 relocation -= (input_section->output_section->vma
6358 + input_section->output_offset
6359 + rel->r_offset);
6360
6361 value = abs (relocation);
6362
6363 if (value >= 0x1000)
6364 return bfd_reloc_overflow;
6365
6366 insn = (insn & 0xff7ff000) | value;
6367 if (relocation >= 0)
6368 insn |= (1 << 23);
6369
6370 bfd_put_16 (input_bfd, insn >> 16, hit_data);
6371 bfd_put_16 (input_bfd, insn & 0xffff, hit_data + 2);
6372
6373 return bfd_reloc_ok;
6374 }
6375
6376 case R_ARM_THM_XPC22:
6377 case R_ARM_THM_CALL:
6378 case R_ARM_THM_JUMP24:
6379 /* Thumb BL (branch long instruction). */
6380 {
6381 bfd_vma relocation;
6382 bfd_vma reloc_sign;
6383 bfd_boolean overflow = FALSE;
6384 bfd_vma upper_insn = bfd_get_16 (input_bfd, hit_data);
6385 bfd_vma lower_insn = bfd_get_16 (input_bfd, hit_data + 2);
6386 bfd_signed_vma reloc_signed_max;
6387 bfd_signed_vma reloc_signed_min;
6388 bfd_vma check;
6389 bfd_signed_vma signed_check;
6390 int bitsize;
6391 int thumb2 = using_thumb2 (globals);
6392
6393 /* A branch to an undefined weak symbol is turned into a jump to
6394 the next instruction. */
6395 if (h && h->root.type == bfd_link_hash_undefweak)
6396 {
6397 bfd_put_16 (input_bfd, 0xe000, hit_data);
6398 bfd_put_16 (input_bfd, 0xbf00, hit_data + 2);
6399 return bfd_reloc_ok;
6400 }
6401
6402 /* Fetch the addend. We use the Thumb-2 encoding (backwards compatible
6403 with Thumb-1) involving the J1 and J2 bits. */
6404 if (globals->use_rel)
6405 {
6406 bfd_vma s = (upper_insn & (1 << 10)) >> 10;
6407 bfd_vma upper = upper_insn & 0x3ff;
6408 bfd_vma lower = lower_insn & 0x7ff;
6409 bfd_vma j1 = (lower_insn & (1 << 13)) >> 13;
6410 bfd_vma j2 = (lower_insn & (1 << 11)) >> 11;
6411 bfd_vma i1 = j1 ^ s ? 0 : 1;
6412 bfd_vma i2 = j2 ^ s ? 0 : 1;
6413
6414 addend = (i1 << 23) | (i2 << 22) | (upper << 12) | (lower << 1);
6415 /* Sign extend. */
6416 addend = (addend | ((s ? 0 : 1) << 24)) - (1 << 24);
6417
6418 signed_addend = addend;
6419 }
6420
6421 if (r_type == R_ARM_THM_XPC22)
6422 {
6423 /* Check for Thumb to Thumb call. */
6424 /* FIXME: Should we translate the instruction into a BL
6425 instruction instead ? */
6426 if (sym_flags == STT_ARM_TFUNC)
6427 (*_bfd_error_handler)
6428 (_("%B: Warning: Thumb BLX instruction targets thumb function '%s'."),
6429 input_bfd,
6430 h ? h->root.root.string : "(local)");
6431 }
6432 else
6433 {
6434 /* If it is not a call to Thumb, assume call to Arm.
6435 If it is a call relative to a section name, then it is not a
6436 function call at all, but rather a long jump. Calls through
6437 the PLT do not require stubs. */
6438 if (sym_flags != STT_ARM_TFUNC && sym_flags != STT_SECTION
6439 && (h == NULL || splt == NULL
6440 || h->plt.offset == (bfd_vma) -1))
6441 {
6442 if (globals->use_blx && r_type == R_ARM_THM_CALL)
6443 {
6444 /* Convert BL to BLX. */
6445 lower_insn = (lower_insn & ~0x1000) | 0x0800;
6446 }
6447 else if (r_type != R_ARM_THM_CALL) {
6448 if (elf32_thumb_to_arm_stub
6449 (info, sym_name, input_bfd, output_bfd, input_section,
6450 hit_data, sym_sec, rel->r_offset, signed_addend, value,
6451 error_message))
6452 return bfd_reloc_ok;
6453 else
6454 return bfd_reloc_dangerous;
6455 }
6456 }
6457 else if (sym_flags == STT_ARM_TFUNC && globals->use_blx
6458 && r_type == R_ARM_THM_CALL)
6459 {
6460 /* Make sure this is a BL. */
6461 lower_insn |= 0x1800;
6462 }
6463 }
6464
6465 /* Handle calls via the PLT. */
6466 if (h != NULL && splt != NULL && h->plt.offset != (bfd_vma) -1)
6467 {
6468 value = (splt->output_section->vma
6469 + splt->output_offset
6470 + h->plt.offset);
6471 if (globals->use_blx && r_type == R_ARM_THM_CALL)
6472 {
6473 /* If the Thumb BLX instruction is available, convert the
6474 BL to a BLX instruction to call the ARM-mode PLT entry. */
6475 lower_insn = (lower_insn & ~0x1000) | 0x0800;
6476 }
6477 else
6478 /* Target the Thumb stub before the ARM PLT entry. */
6479 value -= PLT_THUMB_STUB_SIZE;
6480 *unresolved_reloc_p = FALSE;
6481 }
6482
6483 if (r_type == R_ARM_THM_CALL)
6484 {
6485 /* Check if a stub has to be inserted because the destination
6486 is too far. */
6487 bfd_vma from;
6488 bfd_signed_vma branch_offset;
6489 struct elf32_arm_stub_hash_entry *stub_entry = NULL;
6490
6491 from = (input_section->output_section->vma
6492 + input_section->output_offset
6493 + rel->r_offset);
6494 branch_offset = (bfd_signed_vma)(value - from);
6495
6496 if ((!thumb2
6497 && (branch_offset > THM_MAX_FWD_BRANCH_OFFSET
6498 || (branch_offset < THM_MAX_BWD_BRANCH_OFFSET)))
6499 ||
6500 (thumb2
6501 && (branch_offset > THM2_MAX_FWD_BRANCH_OFFSET
6502 || (branch_offset < THM2_MAX_BWD_BRANCH_OFFSET)))
6503 || ((sym_flags != STT_ARM_TFUNC) && !globals->use_blx))
6504 {
6505 /* The target is out of reach or we are changing modes, so
6506 redirect the branch to the local stub for this
6507 function. */
6508 stub_entry = elf32_arm_get_stub_entry (input_section,
6509 sym_sec, h,
6510 rel, globals);
6511 if (stub_entry != NULL)
6512 value = (stub_entry->stub_offset
6513 + stub_entry->stub_sec->output_offset
6514 + stub_entry->stub_sec->output_section->vma);
6515
6516 /* If this call becomes a call to Arm, force BLX. */
6517 if (globals->use_blx)
6518 {
6519 if ((stub_entry
6520 && !arm_stub_is_thumb (stub_entry->stub_type))
6521 || (sym_flags != STT_ARM_TFUNC))
6522 lower_insn = (lower_insn & ~0x1000) | 0x0800;
6523 }
6524 }
6525 }
6526
6527 relocation = value + signed_addend;
6528
6529 relocation -= (input_section->output_section->vma
6530 + input_section->output_offset
6531 + rel->r_offset);
6532
6533 check = relocation >> howto->rightshift;
6534
6535 /* If this is a signed value, the rightshift just dropped
6536 leading 1 bits (assuming twos complement). */
6537 if ((bfd_signed_vma) relocation >= 0)
6538 signed_check = check;
6539 else
6540 signed_check = check | ~((bfd_vma) -1 >> howto->rightshift);
6541
6542 /* Calculate the permissable maximum and minimum values for
6543 this relocation according to whether we're relocating for
6544 Thumb-2 or not. */
6545 bitsize = howto->bitsize;
6546 if (!thumb2)
6547 bitsize -= 2;
6548 reloc_signed_max = ((1 << (bitsize - 1)) - 1) >> howto->rightshift;
6549 reloc_signed_min = ~reloc_signed_max;
6550
6551 /* Assumes two's complement. */
6552 if (signed_check > reloc_signed_max || signed_check < reloc_signed_min)
6553 overflow = TRUE;
6554
6555 if ((lower_insn & 0x5000) == 0x4000)
6556 /* For a BLX instruction, make sure that the relocation is rounded up
6557 to a word boundary. This follows the semantics of the instruction
6558 which specifies that bit 1 of the target address will come from bit
6559 1 of the base address. */
6560 relocation = (relocation + 2) & ~ 3;
6561
6562 /* Put RELOCATION back into the insn. Assumes two's complement.
6563 We use the Thumb-2 encoding, which is safe even if dealing with
6564 a Thumb-1 instruction by virtue of our overflow check above. */
6565 reloc_sign = (signed_check < 0) ? 1 : 0;
6566 upper_insn = (upper_insn & ~(bfd_vma) 0x7ff)
6567 | ((relocation >> 12) & 0x3ff)
6568 | (reloc_sign << 10);
6569 lower_insn = (lower_insn & ~(bfd_vma) 0x2fff)
6570 | (((!((relocation >> 23) & 1)) ^ reloc_sign) << 13)
6571 | (((!((relocation >> 22) & 1)) ^ reloc_sign) << 11)
6572 | ((relocation >> 1) & 0x7ff);
6573
6574 /* Put the relocated value back in the object file: */
6575 bfd_put_16 (input_bfd, upper_insn, hit_data);
6576 bfd_put_16 (input_bfd, lower_insn, hit_data + 2);
6577
6578 return (overflow ? bfd_reloc_overflow : bfd_reloc_ok);
6579 }
6580 break;
6581
6582 case R_ARM_THM_JUMP19:
6583 /* Thumb32 conditional branch instruction. */
6584 {
6585 bfd_vma relocation;
6586 bfd_boolean overflow = FALSE;
6587 bfd_vma upper_insn = bfd_get_16 (input_bfd, hit_data);
6588 bfd_vma lower_insn = bfd_get_16 (input_bfd, hit_data + 2);
6589 bfd_signed_vma reloc_signed_max = 0xffffe;
6590 bfd_signed_vma reloc_signed_min = -0x100000;
6591 bfd_signed_vma signed_check;
6592
6593 /* Need to refetch the addend, reconstruct the top three bits,
6594 and squish the two 11 bit pieces together. */
6595 if (globals->use_rel)
6596 {
6597 bfd_vma S = (upper_insn & 0x0400) >> 10;
6598 bfd_vma upper = (upper_insn & 0x003f);
6599 bfd_vma J1 = (lower_insn & 0x2000) >> 13;
6600 bfd_vma J2 = (lower_insn & 0x0800) >> 11;
6601 bfd_vma lower = (lower_insn & 0x07ff);
6602
6603 upper |= J1 << 6;
6604 upper |= J2 << 7;
6605 upper |= (!S) << 8;
6606 upper -= 0x0100; /* Sign extend. */
6607
6608 addend = (upper << 12) | (lower << 1);
6609 signed_addend = addend;
6610 }
6611
6612 /* Handle calls via the PLT. */
6613 if (h != NULL && splt != NULL && h->plt.offset != (bfd_vma) -1)
6614 {
6615 value = (splt->output_section->vma
6616 + splt->output_offset
6617 + h->plt.offset);
6618 /* Target the Thumb stub before the ARM PLT entry. */
6619 value -= PLT_THUMB_STUB_SIZE;
6620 *unresolved_reloc_p = FALSE;
6621 }
6622
6623 /* ??? Should handle interworking? GCC might someday try to
6624 use this for tail calls. */
6625
6626 relocation = value + signed_addend;
6627 relocation -= (input_section->output_section->vma
6628 + input_section->output_offset
6629 + rel->r_offset);
6630 signed_check = (bfd_signed_vma) relocation;
6631
6632 if (signed_check > reloc_signed_max || signed_check < reloc_signed_min)
6633 overflow = TRUE;
6634
6635 /* Put RELOCATION back into the insn. */
6636 {
6637 bfd_vma S = (relocation & 0x00100000) >> 20;
6638 bfd_vma J2 = (relocation & 0x00080000) >> 19;
6639 bfd_vma J1 = (relocation & 0x00040000) >> 18;
6640 bfd_vma hi = (relocation & 0x0003f000) >> 12;
6641 bfd_vma lo = (relocation & 0x00000ffe) >> 1;
6642
6643 upper_insn = (upper_insn & 0xfbc0) | (S << 10) | hi;
6644 lower_insn = (lower_insn & 0xd000) | (J1 << 13) | (J2 << 11) | lo;
6645 }
6646
6647 /* Put the relocated value back in the object file: */
6648 bfd_put_16 (input_bfd, upper_insn, hit_data);
6649 bfd_put_16 (input_bfd, lower_insn, hit_data + 2);
6650
6651 return (overflow ? bfd_reloc_overflow : bfd_reloc_ok);
6652 }
6653
6654 case R_ARM_THM_JUMP11:
6655 case R_ARM_THM_JUMP8:
6656 case R_ARM_THM_JUMP6:
6657 /* Thumb B (branch) instruction). */
6658 {
6659 bfd_signed_vma relocation;
6660 bfd_signed_vma reloc_signed_max = (1 << (howto->bitsize - 1)) - 1;
6661 bfd_signed_vma reloc_signed_min = ~ reloc_signed_max;
6662 bfd_signed_vma signed_check;
6663
6664 /* CZB cannot jump backward. */
6665 if (r_type == R_ARM_THM_JUMP6)
6666 reloc_signed_min = 0;
6667
6668 if (globals->use_rel)
6669 {
6670 /* Need to refetch addend. */
6671 addend = bfd_get_16 (input_bfd, hit_data) & howto->src_mask;
6672 if (addend & ((howto->src_mask + 1) >> 1))
6673 {
6674 signed_addend = -1;
6675 signed_addend &= ~ howto->src_mask;
6676 signed_addend |= addend;
6677 }
6678 else
6679 signed_addend = addend;
6680 /* The value in the insn has been right shifted. We need to
6681 undo this, so that we can perform the address calculation
6682 in terms of bytes. */
6683 signed_addend <<= howto->rightshift;
6684 }
6685 relocation = value + signed_addend;
6686
6687 relocation -= (input_section->output_section->vma
6688 + input_section->output_offset
6689 + rel->r_offset);
6690
6691 relocation >>= howto->rightshift;
6692 signed_check = relocation;
6693
6694 if (r_type == R_ARM_THM_JUMP6)
6695 relocation = ((relocation & 0x0020) << 4) | ((relocation & 0x001f) << 3);
6696 else
6697 relocation &= howto->dst_mask;
6698 relocation |= (bfd_get_16 (input_bfd, hit_data) & (~ howto->dst_mask));
6699
6700 bfd_put_16 (input_bfd, relocation, hit_data);
6701
6702 /* Assumes two's complement. */
6703 if (signed_check > reloc_signed_max || signed_check < reloc_signed_min)
6704 return bfd_reloc_overflow;
6705
6706 return bfd_reloc_ok;
6707 }
6708
6709 case R_ARM_ALU_PCREL7_0:
6710 case R_ARM_ALU_PCREL15_8:
6711 case R_ARM_ALU_PCREL23_15:
6712 {
6713 bfd_vma insn;
6714 bfd_vma relocation;
6715
6716 insn = bfd_get_32 (input_bfd, hit_data);
6717 if (globals->use_rel)
6718 {
6719 /* Extract the addend. */
6720 addend = (insn & 0xff) << ((insn & 0xf00) >> 7);
6721 signed_addend = addend;
6722 }
6723 relocation = value + signed_addend;
6724
6725 relocation -= (input_section->output_section->vma
6726 + input_section->output_offset
6727 + rel->r_offset);
6728 insn = (insn & ~0xfff)
6729 | ((howto->bitpos << 7) & 0xf00)
6730 | ((relocation >> howto->bitpos) & 0xff);
6731 bfd_put_32 (input_bfd, value, hit_data);
6732 }
6733 return bfd_reloc_ok;
6734
6735 case R_ARM_GNU_VTINHERIT:
6736 case R_ARM_GNU_VTENTRY:
6737 return bfd_reloc_ok;
6738
6739 case R_ARM_GOTOFF32:
6740 /* Relocation is relative to the start of the
6741 global offset table. */
6742
6743 BFD_ASSERT (sgot != NULL);
6744 if (sgot == NULL)
6745 return bfd_reloc_notsupported;
6746
6747 /* If we are addressing a Thumb function, we need to adjust the
6748 address by one, so that attempts to call the function pointer will
6749 correctly interpret it as Thumb code. */
6750 if (sym_flags == STT_ARM_TFUNC)
6751 value += 1;
6752
6753 /* Note that sgot->output_offset is not involved in this
6754 calculation. We always want the start of .got. If we
6755 define _GLOBAL_OFFSET_TABLE in a different way, as is
6756 permitted by the ABI, we might have to change this
6757 calculation. */
6758 value -= sgot->output_section->vma;
6759 return _bfd_final_link_relocate (howto, input_bfd, input_section,
6760 contents, rel->r_offset, value,
6761 rel->r_addend);
6762
6763 case R_ARM_GOTPC:
6764 /* Use global offset table as symbol value. */
6765 BFD_ASSERT (sgot != NULL);
6766
6767 if (sgot == NULL)
6768 return bfd_reloc_notsupported;
6769
6770 *unresolved_reloc_p = FALSE;
6771 value = sgot->output_section->vma;
6772 return _bfd_final_link_relocate (howto, input_bfd, input_section,
6773 contents, rel->r_offset, value,
6774 rel->r_addend);
6775
6776 case R_ARM_GOT32:
6777 case R_ARM_GOT_PREL:
6778 /* Relocation is to the entry for this symbol in the
6779 global offset table. */
6780 if (sgot == NULL)
6781 return bfd_reloc_notsupported;
6782
6783 if (h != NULL)
6784 {
6785 bfd_vma off;
6786 bfd_boolean dyn;
6787
6788 off = h->got.offset;
6789 BFD_ASSERT (off != (bfd_vma) -1);
6790 dyn = globals->root.dynamic_sections_created;
6791
6792 if (! WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn, info->shared, h)
6793 || (info->shared
6794 && SYMBOL_REFERENCES_LOCAL (info, h))
6795 || (ELF_ST_VISIBILITY (h->other)
6796 && h->root.type == bfd_link_hash_undefweak))
6797 {
6798 /* This is actually a static link, or it is a -Bsymbolic link
6799 and the symbol is defined locally. We must initialize this
6800 entry in the global offset table. Since the offset must
6801 always be a multiple of 4, we use the least significant bit
6802 to record whether we have initialized it already.
6803
6804 When doing a dynamic link, we create a .rel(a).got relocation
6805 entry to initialize the value. This is done in the
6806 finish_dynamic_symbol routine. */
6807 if ((off & 1) != 0)
6808 off &= ~1;
6809 else
6810 {
6811 /* If we are addressing a Thumb function, we need to
6812 adjust the address by one, so that attempts to
6813 call the function pointer will correctly
6814 interpret it as Thumb code. */
6815 if (sym_flags == STT_ARM_TFUNC)
6816 value |= 1;
6817
6818 bfd_put_32 (output_bfd, value, sgot->contents + off);
6819 h->got.offset |= 1;
6820 }
6821 }
6822 else
6823 *unresolved_reloc_p = FALSE;
6824
6825 value = sgot->output_offset + off;
6826 }
6827 else
6828 {
6829 bfd_vma off;
6830
6831 BFD_ASSERT (local_got_offsets != NULL &&
6832 local_got_offsets[r_symndx] != (bfd_vma) -1);
6833
6834 off = local_got_offsets[r_symndx];
6835
6836 /* The offset must always be a multiple of 4. We use the
6837 least significant bit to record whether we have already
6838 generated the necessary reloc. */
6839 if ((off & 1) != 0)
6840 off &= ~1;
6841 else
6842 {
6843 /* If we are addressing a Thumb function, we need to
6844 adjust the address by one, so that attempts to
6845 call the function pointer will correctly
6846 interpret it as Thumb code. */
6847 if (sym_flags == STT_ARM_TFUNC)
6848 value |= 1;
6849
6850 if (globals->use_rel)
6851 bfd_put_32 (output_bfd, value, sgot->contents + off);
6852
6853 if (info->shared)
6854 {
6855 asection * srelgot;
6856 Elf_Internal_Rela outrel;
6857 bfd_byte *loc;
6858
6859 srelgot = (bfd_get_section_by_name
6860 (dynobj, RELOC_SECTION (globals, ".got")));
6861 BFD_ASSERT (srelgot != NULL);
6862
6863 outrel.r_addend = addend + value;
6864 outrel.r_offset = (sgot->output_section->vma
6865 + sgot->output_offset
6866 + off);
6867 outrel.r_info = ELF32_R_INFO (0, R_ARM_RELATIVE);
6868 loc = srelgot->contents;
6869 loc += srelgot->reloc_count++ * RELOC_SIZE (globals);
6870 SWAP_RELOC_OUT (globals) (output_bfd, &outrel, loc);
6871 }
6872
6873 local_got_offsets[r_symndx] |= 1;
6874 }
6875
6876 value = sgot->output_offset + off;
6877 }
6878 if (r_type != R_ARM_GOT32)
6879 value += sgot->output_section->vma;
6880
6881 return _bfd_final_link_relocate (howto, input_bfd, input_section,
6882 contents, rel->r_offset, value,
6883 rel->r_addend);
6884
6885 case R_ARM_TLS_LDO32:
6886 value = value - dtpoff_base (info);
6887
6888 return _bfd_final_link_relocate (howto, input_bfd, input_section,
6889 contents, rel->r_offset, value,
6890 rel->r_addend);
6891
6892 case R_ARM_TLS_LDM32:
6893 {
6894 bfd_vma off;
6895
6896 if (globals->sgot == NULL)
6897 abort ();
6898
6899 off = globals->tls_ldm_got.offset;
6900
6901 if ((off & 1) != 0)
6902 off &= ~1;
6903 else
6904 {
6905 /* If we don't know the module number, create a relocation
6906 for it. */
6907 if (info->shared)
6908 {
6909 Elf_Internal_Rela outrel;
6910 bfd_byte *loc;
6911
6912 if (globals->srelgot == NULL)
6913 abort ();
6914
6915 outrel.r_addend = 0;
6916 outrel.r_offset = (globals->sgot->output_section->vma
6917 + globals->sgot->output_offset + off);
6918 outrel.r_info = ELF32_R_INFO (0, R_ARM_TLS_DTPMOD32);
6919
6920 if (globals->use_rel)
6921 bfd_put_32 (output_bfd, outrel.r_addend,
6922 globals->sgot->contents + off);
6923
6924 loc = globals->srelgot->contents;
6925 loc += globals->srelgot->reloc_count++ * RELOC_SIZE (globals);
6926 SWAP_RELOC_OUT (globals) (output_bfd, &outrel, loc);
6927 }
6928 else
6929 bfd_put_32 (output_bfd, 1, globals->sgot->contents + off);
6930
6931 globals->tls_ldm_got.offset |= 1;
6932 }
6933
6934 value = globals->sgot->output_section->vma + globals->sgot->output_offset + off
6935 - (input_section->output_section->vma + input_section->output_offset + rel->r_offset);
6936
6937 return _bfd_final_link_relocate (howto, input_bfd, input_section,
6938 contents, rel->r_offset, value,
6939 rel->r_addend);
6940 }
6941
6942 case R_ARM_TLS_GD32:
6943 case R_ARM_TLS_IE32:
6944 {
6945 bfd_vma off;
6946 int indx;
6947 char tls_type;
6948
6949 if (globals->sgot == NULL)
6950 abort ();
6951
6952 indx = 0;
6953 if (h != NULL)
6954 {
6955 bfd_boolean dyn;
6956 dyn = globals->root.dynamic_sections_created;
6957 if (WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn, info->shared, h)
6958 && (!info->shared
6959 || !SYMBOL_REFERENCES_LOCAL (info, h)))
6960 {
6961 *unresolved_reloc_p = FALSE;
6962 indx = h->dynindx;
6963 }
6964 off = h->got.offset;
6965 tls_type = ((struct elf32_arm_link_hash_entry *) h)->tls_type;
6966 }
6967 else
6968 {
6969 if (local_got_offsets == NULL)
6970 abort ();
6971 off = local_got_offsets[r_symndx];
6972 tls_type = elf32_arm_local_got_tls_type (input_bfd)[r_symndx];
6973 }
6974
6975 if (tls_type == GOT_UNKNOWN)
6976 abort ();
6977
6978 if ((off & 1) != 0)
6979 off &= ~1;
6980 else
6981 {
6982 bfd_boolean need_relocs = FALSE;
6983 Elf_Internal_Rela outrel;
6984 bfd_byte *loc = NULL;
6985 int cur_off = off;
6986
6987 /* The GOT entries have not been initialized yet. Do it
6988 now, and emit any relocations. If both an IE GOT and a
6989 GD GOT are necessary, we emit the GD first. */
6990
6991 if ((info->shared || indx != 0)
6992 && (h == NULL
6993 || ELF_ST_VISIBILITY (h->other) == STV_DEFAULT
6994 || h->root.type != bfd_link_hash_undefweak))
6995 {
6996 need_relocs = TRUE;
6997 if (globals->srelgot == NULL)
6998 abort ();
6999 loc = globals->srelgot->contents;
7000 loc += globals->srelgot->reloc_count * RELOC_SIZE (globals);
7001 }
7002
7003 if (tls_type & GOT_TLS_GD)
7004 {
7005 if (need_relocs)
7006 {
7007 outrel.r_addend = 0;
7008 outrel.r_offset = (globals->sgot->output_section->vma
7009 + globals->sgot->output_offset
7010 + cur_off);
7011 outrel.r_info = ELF32_R_INFO (indx, R_ARM_TLS_DTPMOD32);
7012
7013 if (globals->use_rel)
7014 bfd_put_32 (output_bfd, outrel.r_addend,
7015 globals->sgot->contents + cur_off);
7016
7017 SWAP_RELOC_OUT (globals) (output_bfd, &outrel, loc);
7018 globals->srelgot->reloc_count++;
7019 loc += RELOC_SIZE (globals);
7020
7021 if (indx == 0)
7022 bfd_put_32 (output_bfd, value - dtpoff_base (info),
7023 globals->sgot->contents + cur_off + 4);
7024 else
7025 {
7026 outrel.r_addend = 0;
7027 outrel.r_info = ELF32_R_INFO (indx,
7028 R_ARM_TLS_DTPOFF32);
7029 outrel.r_offset += 4;
7030
7031 if (globals->use_rel)
7032 bfd_put_32 (output_bfd, outrel.r_addend,
7033 globals->sgot->contents + cur_off + 4);
7034
7035
7036 SWAP_RELOC_OUT (globals) (output_bfd, &outrel, loc);
7037 globals->srelgot->reloc_count++;
7038 loc += RELOC_SIZE (globals);
7039 }
7040 }
7041 else
7042 {
7043 /* If we are not emitting relocations for a
7044 general dynamic reference, then we must be in a
7045 static link or an executable link with the
7046 symbol binding locally. Mark it as belonging
7047 to module 1, the executable. */
7048 bfd_put_32 (output_bfd, 1,
7049 globals->sgot->contents + cur_off);
7050 bfd_put_32 (output_bfd, value - dtpoff_base (info),
7051 globals->sgot->contents + cur_off + 4);
7052 }
7053
7054 cur_off += 8;
7055 }
7056
7057 if (tls_type & GOT_TLS_IE)
7058 {
7059 if (need_relocs)
7060 {
7061 if (indx == 0)
7062 outrel.r_addend = value - dtpoff_base (info);
7063 else
7064 outrel.r_addend = 0;
7065 outrel.r_offset = (globals->sgot->output_section->vma
7066 + globals->sgot->output_offset
7067 + cur_off);
7068 outrel.r_info = ELF32_R_INFO (indx, R_ARM_TLS_TPOFF32);
7069
7070 if (globals->use_rel)
7071 bfd_put_32 (output_bfd, outrel.r_addend,
7072 globals->sgot->contents + cur_off);
7073
7074 SWAP_RELOC_OUT (globals) (output_bfd, &outrel, loc);
7075 globals->srelgot->reloc_count++;
7076 loc += RELOC_SIZE (globals);
7077 }
7078 else
7079 bfd_put_32 (output_bfd, tpoff (info, value),
7080 globals->sgot->contents + cur_off);
7081 cur_off += 4;
7082 }
7083
7084 if (h != NULL)
7085 h->got.offset |= 1;
7086 else
7087 local_got_offsets[r_symndx] |= 1;
7088 }
7089
7090 if ((tls_type & GOT_TLS_GD) && r_type != R_ARM_TLS_GD32)
7091 off += 8;
7092 value = globals->sgot->output_section->vma + globals->sgot->output_offset + off
7093 - (input_section->output_section->vma + input_section->output_offset + rel->r_offset);
7094
7095 return _bfd_final_link_relocate (howto, input_bfd, input_section,
7096 contents, rel->r_offset, value,
7097 rel->r_addend);
7098 }
7099
7100 case R_ARM_TLS_LE32:
7101 if (info->shared)
7102 {
7103 (*_bfd_error_handler)
7104 (_("%B(%A+0x%lx): R_ARM_TLS_LE32 relocation not permitted in shared object"),
7105 input_bfd, input_section,
7106 (long) rel->r_offset, howto->name);
7107 return FALSE;
7108 }
7109 else
7110 value = tpoff (info, value);
7111
7112 return _bfd_final_link_relocate (howto, input_bfd, input_section,
7113 contents, rel->r_offset, value,
7114 rel->r_addend);
7115
7116 case R_ARM_V4BX:
7117 if (globals->fix_v4bx)
7118 {
7119 bfd_vma insn = bfd_get_32 (input_bfd, hit_data);
7120
7121 /* Ensure that we have a BX instruction. */
7122 BFD_ASSERT ((insn & 0x0ffffff0) == 0x012fff10);
7123
7124 if (globals->fix_v4bx == 2 && (insn & 0xf) != 0xf)
7125 {
7126 /* Branch to veneer. */
7127 bfd_vma glue_addr;
7128 glue_addr = elf32_arm_bx_glue (info, insn & 0xf);
7129 glue_addr -= input_section->output_section->vma
7130 + input_section->output_offset
7131 + rel->r_offset + 8;
7132 insn = (insn & 0xf0000000) | 0x0a000000
7133 | ((glue_addr >> 2) & 0x00ffffff);
7134 }
7135 else
7136 {
7137 /* Preserve Rm (lowest four bits) and the condition code
7138 (highest four bits). Other bits encode MOV PC,Rm. */
7139 insn = (insn & 0xf000000f) | 0x01a0f000;
7140 }
7141
7142 bfd_put_32 (input_bfd, insn, hit_data);
7143 }
7144 return bfd_reloc_ok;
7145
7146 case R_ARM_MOVW_ABS_NC:
7147 case R_ARM_MOVT_ABS:
7148 case R_ARM_MOVW_PREL_NC:
7149 case R_ARM_MOVT_PREL:
7150 /* Until we properly support segment-base-relative addressing then
7151 we assume the segment base to be zero, as for the group relocations.
7152 Thus R_ARM_MOVW_BREL_NC has the same semantics as R_ARM_MOVW_ABS_NC
7153 and R_ARM_MOVT_BREL has the same semantics as R_ARM_MOVT_ABS. */
7154 case R_ARM_MOVW_BREL_NC:
7155 case R_ARM_MOVW_BREL:
7156 case R_ARM_MOVT_BREL:
7157 {
7158 bfd_vma insn = bfd_get_32 (input_bfd, hit_data);
7159
7160 if (globals->use_rel)
7161 {
7162 addend = ((insn >> 4) & 0xf000) | (insn & 0xfff);
7163 signed_addend = (addend ^ 0x8000) - 0x8000;
7164 }
7165
7166 value += signed_addend;
7167
7168 if (r_type == R_ARM_MOVW_PREL_NC || r_type == R_ARM_MOVT_PREL)
7169 value -= (input_section->output_section->vma
7170 + input_section->output_offset + rel->r_offset);
7171
7172 if (r_type == R_ARM_MOVW_BREL && value >= 0x10000)
7173 return bfd_reloc_overflow;
7174
7175 if (sym_flags == STT_ARM_TFUNC)
7176 value |= 1;
7177
7178 if (r_type == R_ARM_MOVT_ABS || r_type == R_ARM_MOVT_PREL
7179 || r_type == R_ARM_MOVT_BREL)
7180 value >>= 16;
7181
7182 insn &= 0xfff0f000;
7183 insn |= value & 0xfff;
7184 insn |= (value & 0xf000) << 4;
7185 bfd_put_32 (input_bfd, insn, hit_data);
7186 }
7187 return bfd_reloc_ok;
7188
7189 case R_ARM_THM_MOVW_ABS_NC:
7190 case R_ARM_THM_MOVT_ABS:
7191 case R_ARM_THM_MOVW_PREL_NC:
7192 case R_ARM_THM_MOVT_PREL:
7193 /* Until we properly support segment-base-relative addressing then
7194 we assume the segment base to be zero, as for the above relocations.
7195 Thus R_ARM_THM_MOVW_BREL_NC has the same semantics as
7196 R_ARM_THM_MOVW_ABS_NC and R_ARM_THM_MOVT_BREL has the same semantics
7197 as R_ARM_THM_MOVT_ABS. */
7198 case R_ARM_THM_MOVW_BREL_NC:
7199 case R_ARM_THM_MOVW_BREL:
7200 case R_ARM_THM_MOVT_BREL:
7201 {
7202 bfd_vma insn;
7203
7204 insn = bfd_get_16 (input_bfd, hit_data) << 16;
7205 insn |= bfd_get_16 (input_bfd, hit_data + 2);
7206
7207 if (globals->use_rel)
7208 {
7209 addend = ((insn >> 4) & 0xf000)
7210 | ((insn >> 15) & 0x0800)
7211 | ((insn >> 4) & 0x0700)
7212 | (insn & 0x00ff);
7213 signed_addend = (addend ^ 0x8000) - 0x8000;
7214 }
7215
7216 value += signed_addend;
7217
7218 if (r_type == R_ARM_THM_MOVW_PREL_NC || r_type == R_ARM_THM_MOVT_PREL)
7219 value -= (input_section->output_section->vma
7220 + input_section->output_offset + rel->r_offset);
7221
7222 if (r_type == R_ARM_THM_MOVW_BREL && value >= 0x10000)
7223 return bfd_reloc_overflow;
7224
7225 if (sym_flags == STT_ARM_TFUNC)
7226 value |= 1;
7227
7228 if (r_type == R_ARM_THM_MOVT_ABS || r_type == R_ARM_THM_MOVT_PREL
7229 || r_type == R_ARM_THM_MOVT_BREL)
7230 value >>= 16;
7231
7232 insn &= 0xfbf08f00;
7233 insn |= (value & 0xf000) << 4;
7234 insn |= (value & 0x0800) << 15;
7235 insn |= (value & 0x0700) << 4;
7236 insn |= (value & 0x00ff);
7237
7238 bfd_put_16 (input_bfd, insn >> 16, hit_data);
7239 bfd_put_16 (input_bfd, insn & 0xffff, hit_data + 2);
7240 }
7241 return bfd_reloc_ok;
7242
7243 case R_ARM_ALU_PC_G0_NC:
7244 case R_ARM_ALU_PC_G1_NC:
7245 case R_ARM_ALU_PC_G0:
7246 case R_ARM_ALU_PC_G1:
7247 case R_ARM_ALU_PC_G2:
7248 case R_ARM_ALU_SB_G0_NC:
7249 case R_ARM_ALU_SB_G1_NC:
7250 case R_ARM_ALU_SB_G0:
7251 case R_ARM_ALU_SB_G1:
7252 case R_ARM_ALU_SB_G2:
7253 {
7254 bfd_vma insn = bfd_get_32 (input_bfd, hit_data);
7255 bfd_vma pc = input_section->output_section->vma
7256 + input_section->output_offset + rel->r_offset;
7257 /* sb should be the origin of the *segment* containing the symbol.
7258 It is not clear how to obtain this OS-dependent value, so we
7259 make an arbitrary choice of zero. */
7260 bfd_vma sb = 0;
7261 bfd_vma residual;
7262 bfd_vma g_n;
7263 bfd_signed_vma signed_value;
7264 int group = 0;
7265
7266 /* Determine which group of bits to select. */
7267 switch (r_type)
7268 {
7269 case R_ARM_ALU_PC_G0_NC:
7270 case R_ARM_ALU_PC_G0:
7271 case R_ARM_ALU_SB_G0_NC:
7272 case R_ARM_ALU_SB_G0:
7273 group = 0;
7274 break;
7275
7276 case R_ARM_ALU_PC_G1_NC:
7277 case R_ARM_ALU_PC_G1:
7278 case R_ARM_ALU_SB_G1_NC:
7279 case R_ARM_ALU_SB_G1:
7280 group = 1;
7281 break;
7282
7283 case R_ARM_ALU_PC_G2:
7284 case R_ARM_ALU_SB_G2:
7285 group = 2;
7286 break;
7287
7288 default:
7289 abort ();
7290 }
7291
7292 /* If REL, extract the addend from the insn. If RELA, it will
7293 have already been fetched for us. */
7294 if (globals->use_rel)
7295 {
7296 int negative;
7297 bfd_vma constant = insn & 0xff;
7298 bfd_vma rotation = (insn & 0xf00) >> 8;
7299
7300 if (rotation == 0)
7301 signed_addend = constant;
7302 else
7303 {
7304 /* Compensate for the fact that in the instruction, the
7305 rotation is stored in multiples of 2 bits. */
7306 rotation *= 2;
7307
7308 /* Rotate "constant" right by "rotation" bits. */
7309 signed_addend = (constant >> rotation) |
7310 (constant << (8 * sizeof (bfd_vma) - rotation));
7311 }
7312
7313 /* Determine if the instruction is an ADD or a SUB.
7314 (For REL, this determines the sign of the addend.) */
7315 negative = identify_add_or_sub (insn);
7316 if (negative == 0)
7317 {
7318 (*_bfd_error_handler)
7319 (_("%B(%A+0x%lx): Only ADD or SUB instructions are allowed for ALU group relocations"),
7320 input_bfd, input_section,
7321 (long) rel->r_offset, howto->name);
7322 return bfd_reloc_overflow;
7323 }
7324
7325 signed_addend *= negative;
7326 }
7327
7328 /* Compute the value (X) to go in the place. */
7329 if (r_type == R_ARM_ALU_PC_G0_NC
7330 || r_type == R_ARM_ALU_PC_G1_NC
7331 || r_type == R_ARM_ALU_PC_G0
7332 || r_type == R_ARM_ALU_PC_G1
7333 || r_type == R_ARM_ALU_PC_G2)
7334 /* PC relative. */
7335 signed_value = value - pc + signed_addend;
7336 else
7337 /* Section base relative. */
7338 signed_value = value - sb + signed_addend;
7339
7340 /* If the target symbol is a Thumb function, then set the
7341 Thumb bit in the address. */
7342 if (sym_flags == STT_ARM_TFUNC)
7343 signed_value |= 1;
7344
7345 /* Calculate the value of the relevant G_n, in encoded
7346 constant-with-rotation format. */
7347 g_n = calculate_group_reloc_mask (abs (signed_value), group,
7348 &residual);
7349
7350 /* Check for overflow if required. */
7351 if ((r_type == R_ARM_ALU_PC_G0
7352 || r_type == R_ARM_ALU_PC_G1
7353 || r_type == R_ARM_ALU_PC_G2
7354 || r_type == R_ARM_ALU_SB_G0
7355 || r_type == R_ARM_ALU_SB_G1
7356 || r_type == R_ARM_ALU_SB_G2) && residual != 0)
7357 {
7358 (*_bfd_error_handler)
7359 (_("%B(%A+0x%lx): Overflow whilst splitting 0x%lx for group relocation %s"),
7360 input_bfd, input_section,
7361 (long) rel->r_offset, abs (signed_value), howto->name);
7362 return bfd_reloc_overflow;
7363 }
7364
7365 /* Mask out the value and the ADD/SUB part of the opcode; take care
7366 not to destroy the S bit. */
7367 insn &= 0xff1ff000;
7368
7369 /* Set the opcode according to whether the value to go in the
7370 place is negative. */
7371 if (signed_value < 0)
7372 insn |= 1 << 22;
7373 else
7374 insn |= 1 << 23;
7375
7376 /* Encode the offset. */
7377 insn |= g_n;
7378
7379 bfd_put_32 (input_bfd, insn, hit_data);
7380 }
7381 return bfd_reloc_ok;
7382
7383 case R_ARM_LDR_PC_G0:
7384 case R_ARM_LDR_PC_G1:
7385 case R_ARM_LDR_PC_G2:
7386 case R_ARM_LDR_SB_G0:
7387 case R_ARM_LDR_SB_G1:
7388 case R_ARM_LDR_SB_G2:
7389 {
7390 bfd_vma insn = bfd_get_32 (input_bfd, hit_data);
7391 bfd_vma pc = input_section->output_section->vma
7392 + input_section->output_offset + rel->r_offset;
7393 bfd_vma sb = 0; /* See note above. */
7394 bfd_vma residual;
7395 bfd_signed_vma signed_value;
7396 int group = 0;
7397
7398 /* Determine which groups of bits to calculate. */
7399 switch (r_type)
7400 {
7401 case R_ARM_LDR_PC_G0:
7402 case R_ARM_LDR_SB_G0:
7403 group = 0;
7404 break;
7405
7406 case R_ARM_LDR_PC_G1:
7407 case R_ARM_LDR_SB_G1:
7408 group = 1;
7409 break;
7410
7411 case R_ARM_LDR_PC_G2:
7412 case R_ARM_LDR_SB_G2:
7413 group = 2;
7414 break;
7415
7416 default:
7417 abort ();
7418 }
7419
7420 /* If REL, extract the addend from the insn. If RELA, it will
7421 have already been fetched for us. */
7422 if (globals->use_rel)
7423 {
7424 int negative = (insn & (1 << 23)) ? 1 : -1;
7425 signed_addend = negative * (insn & 0xfff);
7426 }
7427
7428 /* Compute the value (X) to go in the place. */
7429 if (r_type == R_ARM_LDR_PC_G0
7430 || r_type == R_ARM_LDR_PC_G1
7431 || r_type == R_ARM_LDR_PC_G2)
7432 /* PC relative. */
7433 signed_value = value - pc + signed_addend;
7434 else
7435 /* Section base relative. */
7436 signed_value = value - sb + signed_addend;
7437
7438 /* Calculate the value of the relevant G_{n-1} to obtain
7439 the residual at that stage. */
7440 calculate_group_reloc_mask (abs (signed_value), group - 1, &residual);
7441
7442 /* Check for overflow. */
7443 if (residual >= 0x1000)
7444 {
7445 (*_bfd_error_handler)
7446 (_("%B(%A+0x%lx): Overflow whilst splitting 0x%lx for group relocation %s"),
7447 input_bfd, input_section,
7448 (long) rel->r_offset, abs (signed_value), howto->name);
7449 return bfd_reloc_overflow;
7450 }
7451
7452 /* Mask out the value and U bit. */
7453 insn &= 0xff7ff000;
7454
7455 /* Set the U bit if the value to go in the place is non-negative. */
7456 if (signed_value >= 0)
7457 insn |= 1 << 23;
7458
7459 /* Encode the offset. */
7460 insn |= residual;
7461
7462 bfd_put_32 (input_bfd, insn, hit_data);
7463 }
7464 return bfd_reloc_ok;
7465
7466 case R_ARM_LDRS_PC_G0:
7467 case R_ARM_LDRS_PC_G1:
7468 case R_ARM_LDRS_PC_G2:
7469 case R_ARM_LDRS_SB_G0:
7470 case R_ARM_LDRS_SB_G1:
7471 case R_ARM_LDRS_SB_G2:
7472 {
7473 bfd_vma insn = bfd_get_32 (input_bfd, hit_data);
7474 bfd_vma pc = input_section->output_section->vma
7475 + input_section->output_offset + rel->r_offset;
7476 bfd_vma sb = 0; /* See note above. */
7477 bfd_vma residual;
7478 bfd_signed_vma signed_value;
7479 int group = 0;
7480
7481 /* Determine which groups of bits to calculate. */
7482 switch (r_type)
7483 {
7484 case R_ARM_LDRS_PC_G0:
7485 case R_ARM_LDRS_SB_G0:
7486 group = 0;
7487 break;
7488
7489 case R_ARM_LDRS_PC_G1:
7490 case R_ARM_LDRS_SB_G1:
7491 group = 1;
7492 break;
7493
7494 case R_ARM_LDRS_PC_G2:
7495 case R_ARM_LDRS_SB_G2:
7496 group = 2;
7497 break;
7498
7499 default:
7500 abort ();
7501 }
7502
7503 /* If REL, extract the addend from the insn. If RELA, it will
7504 have already been fetched for us. */
7505 if (globals->use_rel)
7506 {
7507 int negative = (insn & (1 << 23)) ? 1 : -1;
7508 signed_addend = negative * (((insn & 0xf00) >> 4) + (insn & 0xf));
7509 }
7510
7511 /* Compute the value (X) to go in the place. */
7512 if (r_type == R_ARM_LDRS_PC_G0
7513 || r_type == R_ARM_LDRS_PC_G1
7514 || r_type == R_ARM_LDRS_PC_G2)
7515 /* PC relative. */
7516 signed_value = value - pc + signed_addend;
7517 else
7518 /* Section base relative. */
7519 signed_value = value - sb + signed_addend;
7520
7521 /* Calculate the value of the relevant G_{n-1} to obtain
7522 the residual at that stage. */
7523 calculate_group_reloc_mask (abs (signed_value), group - 1, &residual);
7524
7525 /* Check for overflow. */
7526 if (residual >= 0x100)
7527 {
7528 (*_bfd_error_handler)
7529 (_("%B(%A+0x%lx): Overflow whilst splitting 0x%lx for group relocation %s"),
7530 input_bfd, input_section,
7531 (long) rel->r_offset, abs (signed_value), howto->name);
7532 return bfd_reloc_overflow;
7533 }
7534
7535 /* Mask out the value and U bit. */
7536 insn &= 0xff7ff0f0;
7537
7538 /* Set the U bit if the value to go in the place is non-negative. */
7539 if (signed_value >= 0)
7540 insn |= 1 << 23;
7541
7542 /* Encode the offset. */
7543 insn |= ((residual & 0xf0) << 4) | (residual & 0xf);
7544
7545 bfd_put_32 (input_bfd, insn, hit_data);
7546 }
7547 return bfd_reloc_ok;
7548
7549 case R_ARM_LDC_PC_G0:
7550 case R_ARM_LDC_PC_G1:
7551 case R_ARM_LDC_PC_G2:
7552 case R_ARM_LDC_SB_G0:
7553 case R_ARM_LDC_SB_G1:
7554 case R_ARM_LDC_SB_G2:
7555 {
7556 bfd_vma insn = bfd_get_32 (input_bfd, hit_data);
7557 bfd_vma pc = input_section->output_section->vma
7558 + input_section->output_offset + rel->r_offset;
7559 bfd_vma sb = 0; /* See note above. */
7560 bfd_vma residual;
7561 bfd_signed_vma signed_value;
7562 int group = 0;
7563
7564 /* Determine which groups of bits to calculate. */
7565 switch (r_type)
7566 {
7567 case R_ARM_LDC_PC_G0:
7568 case R_ARM_LDC_SB_G0:
7569 group = 0;
7570 break;
7571
7572 case R_ARM_LDC_PC_G1:
7573 case R_ARM_LDC_SB_G1:
7574 group = 1;
7575 break;
7576
7577 case R_ARM_LDC_PC_G2:
7578 case R_ARM_LDC_SB_G2:
7579 group = 2;
7580 break;
7581
7582 default:
7583 abort ();
7584 }
7585
7586 /* If REL, extract the addend from the insn. If RELA, it will
7587 have already been fetched for us. */
7588 if (globals->use_rel)
7589 {
7590 int negative = (insn & (1 << 23)) ? 1 : -1;
7591 signed_addend = negative * ((insn & 0xff) << 2);
7592 }
7593
7594 /* Compute the value (X) to go in the place. */
7595 if (r_type == R_ARM_LDC_PC_G0
7596 || r_type == R_ARM_LDC_PC_G1
7597 || r_type == R_ARM_LDC_PC_G2)
7598 /* PC relative. */
7599 signed_value = value - pc + signed_addend;
7600 else
7601 /* Section base relative. */
7602 signed_value = value - sb + signed_addend;
7603
7604 /* Calculate the value of the relevant G_{n-1} to obtain
7605 the residual at that stage. */
7606 calculate_group_reloc_mask (abs (signed_value), group - 1, &residual);
7607
7608 /* Check for overflow. (The absolute value to go in the place must be
7609 divisible by four and, after having been divided by four, must
7610 fit in eight bits.) */
7611 if ((residual & 0x3) != 0 || residual >= 0x400)
7612 {
7613 (*_bfd_error_handler)
7614 (_("%B(%A+0x%lx): Overflow whilst splitting 0x%lx for group relocation %s"),
7615 input_bfd, input_section,
7616 (long) rel->r_offset, abs (signed_value), howto->name);
7617 return bfd_reloc_overflow;
7618 }
7619
7620 /* Mask out the value and U bit. */
7621 insn &= 0xff7fff00;
7622
7623 /* Set the U bit if the value to go in the place is non-negative. */
7624 if (signed_value >= 0)
7625 insn |= 1 << 23;
7626
7627 /* Encode the offset. */
7628 insn |= residual >> 2;
7629
7630 bfd_put_32 (input_bfd, insn, hit_data);
7631 }
7632 return bfd_reloc_ok;
7633
7634 default:
7635 return bfd_reloc_notsupported;
7636 }
7637 }
7638
7639 /* Add INCREMENT to the reloc (of type HOWTO) at ADDRESS. */
7640 static void
7641 arm_add_to_rel (bfd * abfd,
7642 bfd_byte * address,
7643 reloc_howto_type * howto,
7644 bfd_signed_vma increment)
7645 {
7646 bfd_signed_vma addend;
7647
7648 if (howto->type == R_ARM_THM_CALL
7649 || howto->type == R_ARM_THM_JUMP24)
7650 {
7651 int upper_insn, lower_insn;
7652 int upper, lower;
7653
7654 upper_insn = bfd_get_16 (abfd, address);
7655 lower_insn = bfd_get_16 (abfd, address + 2);
7656 upper = upper_insn & 0x7ff;
7657 lower = lower_insn & 0x7ff;
7658
7659 addend = (upper << 12) | (lower << 1);
7660 addend += increment;
7661 addend >>= 1;
7662
7663 upper_insn = (upper_insn & 0xf800) | ((addend >> 11) & 0x7ff);
7664 lower_insn = (lower_insn & 0xf800) | (addend & 0x7ff);
7665
7666 bfd_put_16 (abfd, (bfd_vma) upper_insn, address);
7667 bfd_put_16 (abfd, (bfd_vma) lower_insn, address + 2);
7668 }
7669 else
7670 {
7671 bfd_vma contents;
7672
7673 contents = bfd_get_32 (abfd, address);
7674
7675 /* Get the (signed) value from the instruction. */
7676 addend = contents & howto->src_mask;
7677 if (addend & ((howto->src_mask + 1) >> 1))
7678 {
7679 bfd_signed_vma mask;
7680
7681 mask = -1;
7682 mask &= ~ howto->src_mask;
7683 addend |= mask;
7684 }
7685
7686 /* Add in the increment, (which is a byte value). */
7687 switch (howto->type)
7688 {
7689 default:
7690 addend += increment;
7691 break;
7692
7693 case R_ARM_PC24:
7694 case R_ARM_PLT32:
7695 case R_ARM_CALL:
7696 case R_ARM_JUMP24:
7697 addend <<= howto->size;
7698 addend += increment;
7699
7700 /* Should we check for overflow here ? */
7701
7702 /* Drop any undesired bits. */
7703 addend >>= howto->rightshift;
7704 break;
7705 }
7706
7707 contents = (contents & ~ howto->dst_mask) | (addend & howto->dst_mask);
7708
7709 bfd_put_32 (abfd, contents, address);
7710 }
7711 }
7712
7713 #define IS_ARM_TLS_RELOC(R_TYPE) \
7714 ((R_TYPE) == R_ARM_TLS_GD32 \
7715 || (R_TYPE) == R_ARM_TLS_LDO32 \
7716 || (R_TYPE) == R_ARM_TLS_LDM32 \
7717 || (R_TYPE) == R_ARM_TLS_DTPOFF32 \
7718 || (R_TYPE) == R_ARM_TLS_DTPMOD32 \
7719 || (R_TYPE) == R_ARM_TLS_TPOFF32 \
7720 || (R_TYPE) == R_ARM_TLS_LE32 \
7721 || (R_TYPE) == R_ARM_TLS_IE32)
7722
7723 /* Relocate an ARM ELF section. */
7724
7725 static bfd_boolean
7726 elf32_arm_relocate_section (bfd * output_bfd,
7727 struct bfd_link_info * info,
7728 bfd * input_bfd,
7729 asection * input_section,
7730 bfd_byte * contents,
7731 Elf_Internal_Rela * relocs,
7732 Elf_Internal_Sym * local_syms,
7733 asection ** local_sections)
7734 {
7735 Elf_Internal_Shdr *symtab_hdr;
7736 struct elf_link_hash_entry **sym_hashes;
7737 Elf_Internal_Rela *rel;
7738 Elf_Internal_Rela *relend;
7739 const char *name;
7740 struct elf32_arm_link_hash_table * globals;
7741
7742 globals = elf32_arm_hash_table (info);
7743
7744 symtab_hdr = & elf_symtab_hdr (input_bfd);
7745 sym_hashes = elf_sym_hashes (input_bfd);
7746
7747 rel = relocs;
7748 relend = relocs + input_section->reloc_count;
7749 for (; rel < relend; rel++)
7750 {
7751 int r_type;
7752 reloc_howto_type * howto;
7753 unsigned long r_symndx;
7754 Elf_Internal_Sym * sym;
7755 asection * sec;
7756 struct elf_link_hash_entry * h;
7757 bfd_vma relocation;
7758 bfd_reloc_status_type r;
7759 arelent bfd_reloc;
7760 char sym_type;
7761 bfd_boolean unresolved_reloc = FALSE;
7762 char *error_message = NULL;
7763
7764 r_symndx = ELF32_R_SYM (rel->r_info);
7765 r_type = ELF32_R_TYPE (rel->r_info);
7766 r_type = arm_real_reloc_type (globals, r_type);
7767
7768 if ( r_type == R_ARM_GNU_VTENTRY
7769 || r_type == R_ARM_GNU_VTINHERIT)
7770 continue;
7771
7772 bfd_reloc.howto = elf32_arm_howto_from_type (r_type);
7773 howto = bfd_reloc.howto;
7774
7775 h = NULL;
7776 sym = NULL;
7777 sec = NULL;
7778
7779 if (r_symndx < symtab_hdr->sh_info)
7780 {
7781 sym = local_syms + r_symndx;
7782 sym_type = ELF32_ST_TYPE (sym->st_info);
7783 sec = local_sections[r_symndx];
7784 if (globals->use_rel)
7785 {
7786 relocation = (sec->output_section->vma
7787 + sec->output_offset
7788 + sym->st_value);
7789 if (!info->relocatable
7790 && (sec->flags & SEC_MERGE)
7791 && ELF_ST_TYPE (sym->st_info) == STT_SECTION)
7792 {
7793 asection *msec;
7794 bfd_vma addend, value;
7795
7796 switch (r_type)
7797 {
7798 case R_ARM_MOVW_ABS_NC:
7799 case R_ARM_MOVT_ABS:
7800 value = bfd_get_32 (input_bfd, contents + rel->r_offset);
7801 addend = ((value & 0xf0000) >> 4) | (value & 0xfff);
7802 addend = (addend ^ 0x8000) - 0x8000;
7803 break;
7804
7805 case R_ARM_THM_MOVW_ABS_NC:
7806 case R_ARM_THM_MOVT_ABS:
7807 value = bfd_get_16 (input_bfd, contents + rel->r_offset)
7808 << 16;
7809 value |= bfd_get_16 (input_bfd,
7810 contents + rel->r_offset + 2);
7811 addend = ((value & 0xf7000) >> 4) | (value & 0xff)
7812 | ((value & 0x04000000) >> 15);
7813 addend = (addend ^ 0x8000) - 0x8000;
7814 break;
7815
7816 default:
7817 if (howto->rightshift
7818 || (howto->src_mask & (howto->src_mask + 1)))
7819 {
7820 (*_bfd_error_handler)
7821 (_("%B(%A+0x%lx): %s relocation against SEC_MERGE section"),
7822 input_bfd, input_section,
7823 (long) rel->r_offset, howto->name);
7824 return FALSE;
7825 }
7826
7827 value = bfd_get_32 (input_bfd, contents + rel->r_offset);
7828
7829 /* Get the (signed) value from the instruction. */
7830 addend = value & howto->src_mask;
7831 if (addend & ((howto->src_mask + 1) >> 1))
7832 {
7833 bfd_signed_vma mask;
7834
7835 mask = -1;
7836 mask &= ~ howto->src_mask;
7837 addend |= mask;
7838 }
7839 break;
7840 }
7841
7842 msec = sec;
7843 addend =
7844 _bfd_elf_rel_local_sym (output_bfd, sym, &msec, addend)
7845 - relocation;
7846 addend += msec->output_section->vma + msec->output_offset;
7847
7848 /* Cases here must match those in the preceeding
7849 switch statement. */
7850 switch (r_type)
7851 {
7852 case R_ARM_MOVW_ABS_NC:
7853 case R_ARM_MOVT_ABS:
7854 value = (value & 0xfff0f000) | ((addend & 0xf000) << 4)
7855 | (addend & 0xfff);
7856 bfd_put_32 (input_bfd, value, contents + rel->r_offset);
7857 break;
7858
7859 case R_ARM_THM_MOVW_ABS_NC:
7860 case R_ARM_THM_MOVT_ABS:
7861 value = (value & 0xfbf08f00) | ((addend & 0xf700) << 4)
7862 | (addend & 0xff) | ((addend & 0x0800) << 15);
7863 bfd_put_16 (input_bfd, value >> 16,
7864 contents + rel->r_offset);
7865 bfd_put_16 (input_bfd, value,
7866 contents + rel->r_offset + 2);
7867 break;
7868
7869 default:
7870 value = (value & ~ howto->dst_mask)
7871 | (addend & howto->dst_mask);
7872 bfd_put_32 (input_bfd, value, contents + rel->r_offset);
7873 break;
7874 }
7875 }
7876 }
7877 else
7878 relocation = _bfd_elf_rela_local_sym (output_bfd, sym, &sec, rel);
7879 }
7880 else
7881 {
7882 bfd_boolean warned;
7883
7884 RELOC_FOR_GLOBAL_SYMBOL (info, input_bfd, input_section, rel,
7885 r_symndx, symtab_hdr, sym_hashes,
7886 h, sec, relocation,
7887 unresolved_reloc, warned);
7888
7889 sym_type = h->type;
7890 }
7891
7892 if (sec != NULL && elf_discarded_section (sec))
7893 {
7894 /* For relocs against symbols from removed linkonce sections,
7895 or sections discarded by a linker script, we just want the
7896 section contents zeroed. Avoid any special processing. */
7897 _bfd_clear_contents (howto, input_bfd, contents + rel->r_offset);
7898 rel->r_info = 0;
7899 rel->r_addend = 0;
7900 continue;
7901 }
7902
7903 if (info->relocatable)
7904 {
7905 /* This is a relocatable link. We don't have to change
7906 anything, unless the reloc is against a section symbol,
7907 in which case we have to adjust according to where the
7908 section symbol winds up in the output section. */
7909 if (sym != NULL && ELF_ST_TYPE (sym->st_info) == STT_SECTION)
7910 {
7911 if (globals->use_rel)
7912 arm_add_to_rel (input_bfd, contents + rel->r_offset,
7913 howto, (bfd_signed_vma) sec->output_offset);
7914 else
7915 rel->r_addend += sec->output_offset;
7916 }
7917 continue;
7918 }
7919
7920 if (h != NULL)
7921 name = h->root.root.string;
7922 else
7923 {
7924 name = (bfd_elf_string_from_elf_section
7925 (input_bfd, symtab_hdr->sh_link, sym->st_name));
7926 if (name == NULL || *name == '\0')
7927 name = bfd_section_name (input_bfd, sec);
7928 }
7929
7930 if (r_symndx != 0
7931 && r_type != R_ARM_NONE
7932 && (h == NULL
7933 || h->root.type == bfd_link_hash_defined
7934 || h->root.type == bfd_link_hash_defweak)
7935 && IS_ARM_TLS_RELOC (r_type) != (sym_type == STT_TLS))
7936 {
7937 (*_bfd_error_handler)
7938 ((sym_type == STT_TLS
7939 ? _("%B(%A+0x%lx): %s used with TLS symbol %s")
7940 : _("%B(%A+0x%lx): %s used with non-TLS symbol %s")),
7941 input_bfd,
7942 input_section,
7943 (long) rel->r_offset,
7944 howto->name,
7945 name);
7946 }
7947
7948 r = elf32_arm_final_link_relocate (howto, input_bfd, output_bfd,
7949 input_section, contents, rel,
7950 relocation, info, sec, name,
7951 (h ? ELF_ST_TYPE (h->type) :
7952 ELF_ST_TYPE (sym->st_info)), h,
7953 &unresolved_reloc, &error_message);
7954
7955 /* Dynamic relocs are not propagated for SEC_DEBUGGING sections
7956 because such sections are not SEC_ALLOC and thus ld.so will
7957 not process them. */
7958 if (unresolved_reloc
7959 && !((input_section->flags & SEC_DEBUGGING) != 0
7960 && h->def_dynamic))
7961 {
7962 (*_bfd_error_handler)
7963 (_("%B(%A+0x%lx): unresolvable %s relocation against symbol `%s'"),
7964 input_bfd,
7965 input_section,
7966 (long) rel->r_offset,
7967 howto->name,
7968 h->root.root.string);
7969 return FALSE;
7970 }
7971
7972 if (r != bfd_reloc_ok)
7973 {
7974 switch (r)
7975 {
7976 case bfd_reloc_overflow:
7977 /* If the overflowing reloc was to an undefined symbol,
7978 we have already printed one error message and there
7979 is no point complaining again. */
7980 if ((! h ||
7981 h->root.type != bfd_link_hash_undefined)
7982 && (!((*info->callbacks->reloc_overflow)
7983 (info, (h ? &h->root : NULL), name, howto->name,
7984 (bfd_vma) 0, input_bfd, input_section,
7985 rel->r_offset))))
7986 return FALSE;
7987 break;
7988
7989 case bfd_reloc_undefined:
7990 if (!((*info->callbacks->undefined_symbol)
7991 (info, name, input_bfd, input_section,
7992 rel->r_offset, TRUE)))
7993 return FALSE;
7994 break;
7995
7996 case bfd_reloc_outofrange:
7997 error_message = _("out of range");
7998 goto common_error;
7999
8000 case bfd_reloc_notsupported:
8001 error_message = _("unsupported relocation");
8002 goto common_error;
8003
8004 case bfd_reloc_dangerous:
8005 /* error_message should already be set. */
8006 goto common_error;
8007
8008 default:
8009 error_message = _("unknown error");
8010 /* fall through */
8011
8012 common_error:
8013 BFD_ASSERT (error_message != NULL);
8014 if (!((*info->callbacks->reloc_dangerous)
8015 (info, error_message, input_bfd, input_section,
8016 rel->r_offset)))
8017 return FALSE;
8018 break;
8019 }
8020 }
8021 }
8022
8023 return TRUE;
8024 }
8025
8026 /* Set the right machine number. */
8027
8028 static bfd_boolean
8029 elf32_arm_object_p (bfd *abfd)
8030 {
8031 unsigned int mach;
8032
8033 mach = bfd_arm_get_mach_from_notes (abfd, ARM_NOTE_SECTION);
8034
8035 if (mach != bfd_mach_arm_unknown)
8036 bfd_default_set_arch_mach (abfd, bfd_arch_arm, mach);
8037
8038 else if (elf_elfheader (abfd)->e_flags & EF_ARM_MAVERICK_FLOAT)
8039 bfd_default_set_arch_mach (abfd, bfd_arch_arm, bfd_mach_arm_ep9312);
8040
8041 else
8042 bfd_default_set_arch_mach (abfd, bfd_arch_arm, mach);
8043
8044 return TRUE;
8045 }
8046
8047 /* Function to keep ARM specific flags in the ELF header. */
8048
8049 static bfd_boolean
8050 elf32_arm_set_private_flags (bfd *abfd, flagword flags)
8051 {
8052 if (elf_flags_init (abfd)
8053 && elf_elfheader (abfd)->e_flags != flags)
8054 {
8055 if (EF_ARM_EABI_VERSION (flags) == EF_ARM_EABI_UNKNOWN)
8056 {
8057 if (flags & EF_ARM_INTERWORK)
8058 (*_bfd_error_handler)
8059 (_("Warning: Not setting interworking flag of %B since it has already been specified as non-interworking"),
8060 abfd);
8061 else
8062 _bfd_error_handler
8063 (_("Warning: Clearing the interworking flag of %B due to outside request"),
8064 abfd);
8065 }
8066 }
8067 else
8068 {
8069 elf_elfheader (abfd)->e_flags = flags;
8070 elf_flags_init (abfd) = TRUE;
8071 }
8072
8073 return TRUE;
8074 }
8075
8076 /* Copy backend specific data from one object module to another. */
8077
8078 static bfd_boolean
8079 elf32_arm_copy_private_bfd_data (bfd *ibfd, bfd *obfd)
8080 {
8081 flagword in_flags;
8082 flagword out_flags;
8083
8084 if (! is_arm_elf (ibfd) || ! is_arm_elf (obfd))
8085 return TRUE;
8086
8087 in_flags = elf_elfheader (ibfd)->e_flags;
8088 out_flags = elf_elfheader (obfd)->e_flags;
8089
8090 if (elf_flags_init (obfd)
8091 && EF_ARM_EABI_VERSION (out_flags) == EF_ARM_EABI_UNKNOWN
8092 && in_flags != out_flags)
8093 {
8094 /* Cannot mix APCS26 and APCS32 code. */
8095 if ((in_flags & EF_ARM_APCS_26) != (out_flags & EF_ARM_APCS_26))
8096 return FALSE;
8097
8098 /* Cannot mix float APCS and non-float APCS code. */
8099 if ((in_flags & EF_ARM_APCS_FLOAT) != (out_flags & EF_ARM_APCS_FLOAT))
8100 return FALSE;
8101
8102 /* If the src and dest have different interworking flags
8103 then turn off the interworking bit. */
8104 if ((in_flags & EF_ARM_INTERWORK) != (out_flags & EF_ARM_INTERWORK))
8105 {
8106 if (out_flags & EF_ARM_INTERWORK)
8107 _bfd_error_handler
8108 (_("Warning: Clearing the interworking flag of %B because non-interworking code in %B has been linked with it"),
8109 obfd, ibfd);
8110
8111 in_flags &= ~EF_ARM_INTERWORK;
8112 }
8113
8114 /* Likewise for PIC, though don't warn for this case. */
8115 if ((in_flags & EF_ARM_PIC) != (out_flags & EF_ARM_PIC))
8116 in_flags &= ~EF_ARM_PIC;
8117 }
8118
8119 elf_elfheader (obfd)->e_flags = in_flags;
8120 elf_flags_init (obfd) = TRUE;
8121
8122 /* Also copy the EI_OSABI field. */
8123 elf_elfheader (obfd)->e_ident[EI_OSABI] =
8124 elf_elfheader (ibfd)->e_ident[EI_OSABI];
8125
8126 /* Copy object attributes. */
8127 _bfd_elf_copy_obj_attributes (ibfd, obfd);
8128
8129 return TRUE;
8130 }
8131
8132 /* Values for Tag_ABI_PCS_R9_use. */
8133 enum
8134 {
8135 AEABI_R9_V6,
8136 AEABI_R9_SB,
8137 AEABI_R9_TLS,
8138 AEABI_R9_unused
8139 };
8140
8141 /* Values for Tag_ABI_PCS_RW_data. */
8142 enum
8143 {
8144 AEABI_PCS_RW_data_absolute,
8145 AEABI_PCS_RW_data_PCrel,
8146 AEABI_PCS_RW_data_SBrel,
8147 AEABI_PCS_RW_data_unused
8148 };
8149
8150 /* Values for Tag_ABI_enum_size. */
8151 enum
8152 {
8153 AEABI_enum_unused,
8154 AEABI_enum_short,
8155 AEABI_enum_wide,
8156 AEABI_enum_forced_wide
8157 };
8158
8159 /* Determine whether an object attribute tag takes an integer, a
8160 string or both. */
8161
8162 static int
8163 elf32_arm_obj_attrs_arg_type (int tag)
8164 {
8165 if (tag == Tag_compatibility)
8166 return 3;
8167 else if (tag == 4 || tag == 5)
8168 return 2;
8169 else if (tag < 32)
8170 return 1;
8171 else
8172 return (tag & 1) != 0 ? 2 : 1;
8173 }
8174
8175 /* Merge EABI object attributes from IBFD into OBFD. Raise an error if there
8176 are conflicting attributes. */
8177
8178 static bfd_boolean
8179 elf32_arm_merge_eabi_attributes (bfd *ibfd, bfd *obfd)
8180 {
8181 obj_attribute *in_attr;
8182 obj_attribute *out_attr;
8183 obj_attribute_list *in_list;
8184 /* Some tags have 0 = don't care, 1 = strong requirement,
8185 2 = weak requirement. */
8186 static const int order_312[3] = {3, 1, 2};
8187 /* For use with Tag_VFP_arch. */
8188 static const int order_01243[5] = {0, 1, 2, 4, 3};
8189 int i;
8190
8191 if (!elf_known_obj_attributes_proc (obfd)[0].i)
8192 {
8193 /* This is the first object. Copy the attributes. */
8194 _bfd_elf_copy_obj_attributes (ibfd, obfd);
8195
8196 /* Use the Tag_null value to indicate the attributes have been
8197 initialized. */
8198 elf_known_obj_attributes_proc (obfd)[0].i = 1;
8199
8200 return TRUE;
8201 }
8202
8203 in_attr = elf_known_obj_attributes_proc (ibfd);
8204 out_attr = elf_known_obj_attributes_proc (obfd);
8205 /* This needs to happen before Tag_ABI_FP_number_model is merged. */
8206 if (in_attr[Tag_ABI_VFP_args].i != out_attr[Tag_ABI_VFP_args].i)
8207 {
8208 /* Ignore mismatches if teh object doesn't use floating point. */
8209 if (out_attr[Tag_ABI_FP_number_model].i == 0)
8210 out_attr[Tag_ABI_VFP_args].i = in_attr[Tag_ABI_VFP_args].i;
8211 else if (in_attr[Tag_ABI_FP_number_model].i != 0)
8212 {
8213 _bfd_error_handler
8214 (_("ERROR: %B uses VFP register arguments, %B does not"),
8215 ibfd, obfd);
8216 return FALSE;
8217 }
8218 }
8219
8220 for (i = 4; i < NUM_KNOWN_OBJ_ATTRIBUTES; i++)
8221 {
8222 /* Merge this attribute with existing attributes. */
8223 switch (i)
8224 {
8225 case Tag_CPU_raw_name:
8226 case Tag_CPU_name:
8227 /* Use whichever has the greatest architecture requirements. We
8228 won't necessarily have both the above tags, so make sure input
8229 name is non-NULL. */
8230 if (in_attr[Tag_CPU_arch].i > out_attr[Tag_CPU_arch].i
8231 && in_attr[i].s)
8232 out_attr[i].s = _bfd_elf_attr_strdup (obfd, in_attr[i].s);
8233 break;
8234
8235 case Tag_ABI_optimization_goals:
8236 case Tag_ABI_FP_optimization_goals:
8237 /* Use the first value seen. */
8238 break;
8239
8240 case Tag_CPU_arch:
8241 case Tag_ARM_ISA_use:
8242 case Tag_THUMB_ISA_use:
8243 case Tag_WMMX_arch:
8244 case Tag_NEON_arch:
8245 /* ??? Do NEON and WMMX conflict? */
8246 case Tag_ABI_FP_rounding:
8247 case Tag_ABI_FP_denormal:
8248 case Tag_ABI_FP_exceptions:
8249 case Tag_ABI_FP_user_exceptions:
8250 case Tag_ABI_FP_number_model:
8251 case Tag_ABI_align8_preserved:
8252 case Tag_ABI_HardFP_use:
8253 /* Use the largest value specified. */
8254 if (in_attr[i].i > out_attr[i].i)
8255 out_attr[i].i = in_attr[i].i;
8256 break;
8257
8258 case Tag_CPU_arch_profile:
8259 /* Warn if conflicting architecture profiles used. */
8260 if (out_attr[i].i && in_attr[i].i && in_attr[i].i != out_attr[i].i)
8261 {
8262 _bfd_error_handler
8263 (_("ERROR: %B: Conflicting architecture profiles %c/%c"),
8264 ibfd, in_attr[i].i, out_attr[i].i);
8265 return FALSE;
8266 }
8267 if (in_attr[i].i)
8268 out_attr[i].i = in_attr[i].i;
8269 break;
8270 case Tag_VFP_arch:
8271 if (in_attr[i].i > 4 || out_attr[i].i > 4
8272 || order_01243[in_attr[i].i] > order_01243[out_attr[i].i])
8273 out_attr[i].i = in_attr[i].i;
8274 break;
8275 case Tag_PCS_config:
8276 if (out_attr[i].i == 0)
8277 out_attr[i].i = in_attr[i].i;
8278 else if (in_attr[i].i != 0 && out_attr[i].i != 0)
8279 {
8280 /* It's sometimes ok to mix different configs, so this is only
8281 a warning. */
8282 _bfd_error_handler
8283 (_("Warning: %B: Conflicting platform configuration"), ibfd);
8284 }
8285 break;
8286 case Tag_ABI_PCS_R9_use:
8287 if (in_attr[i].i != out_attr[i].i
8288 && out_attr[i].i != AEABI_R9_unused
8289 && in_attr[i].i != AEABI_R9_unused)
8290 {
8291 _bfd_error_handler
8292 (_("ERROR: %B: Conflicting use of R9"), ibfd);
8293 return FALSE;
8294 }
8295 if (out_attr[i].i == AEABI_R9_unused)
8296 out_attr[i].i = in_attr[i].i;
8297 break;
8298 case Tag_ABI_PCS_RW_data:
8299 if (in_attr[i].i == AEABI_PCS_RW_data_SBrel
8300 && out_attr[Tag_ABI_PCS_R9_use].i != AEABI_R9_SB
8301 && out_attr[Tag_ABI_PCS_R9_use].i != AEABI_R9_unused)
8302 {
8303 _bfd_error_handler
8304 (_("ERROR: %B: SB relative addressing conflicts with use of R9"),
8305 ibfd);
8306 return FALSE;
8307 }
8308 /* Use the smallest value specified. */
8309 if (in_attr[i].i < out_attr[i].i)
8310 out_attr[i].i = in_attr[i].i;
8311 break;
8312 case Tag_ABI_PCS_RO_data:
8313 /* Use the smallest value specified. */
8314 if (in_attr[i].i < out_attr[i].i)
8315 out_attr[i].i = in_attr[i].i;
8316 break;
8317 case Tag_ABI_PCS_GOT_use:
8318 if (in_attr[i].i > 2 || out_attr[i].i > 2
8319 || order_312[in_attr[i].i] < order_312[out_attr[i].i])
8320 out_attr[i].i = in_attr[i].i;
8321 break;
8322 case Tag_ABI_PCS_wchar_t:
8323 if (out_attr[i].i && in_attr[i].i && out_attr[i].i != in_attr[i].i
8324 && !elf_arm_tdata (obfd)->no_wchar_size_warning)
8325 {
8326 _bfd_error_handler
8327 (_("warning: %B uses %u-byte wchar_t yet the output is to use %u-byte wchar_t; use of wchar_t values across objects may fail"),
8328 ibfd, in_attr[i].i, out_attr[i].i);
8329 }
8330 else if (in_attr[i].i && !out_attr[i].i)
8331 out_attr[i].i = in_attr[i].i;
8332 break;
8333 case Tag_ABI_align8_needed:
8334 /* ??? Check against Tag_ABI_align8_preserved. */
8335 if (in_attr[i].i > 2 || out_attr[i].i > 2
8336 || order_312[in_attr[i].i] < order_312[out_attr[i].i])
8337 out_attr[i].i = in_attr[i].i;
8338 break;
8339 case Tag_ABI_enum_size:
8340 if (in_attr[i].i != AEABI_enum_unused)
8341 {
8342 if (out_attr[i].i == AEABI_enum_unused
8343 || out_attr[i].i == AEABI_enum_forced_wide)
8344 {
8345 /* The existing object is compatible with anything.
8346 Use whatever requirements the new object has. */
8347 out_attr[i].i = in_attr[i].i;
8348 }
8349 else if (in_attr[i].i != AEABI_enum_forced_wide
8350 && out_attr[i].i != in_attr[i].i
8351 && !elf_arm_tdata (obfd)->no_enum_size_warning)
8352 {
8353 const char *aeabi_enum_names[] =
8354 { "", "variable-size", "32-bit", "" };
8355 _bfd_error_handler
8356 (_("warning: %B uses %s enums yet the output is to use %s enums; use of enum values across objects may fail"),
8357 ibfd, aeabi_enum_names[in_attr[i].i],
8358 aeabi_enum_names[out_attr[i].i]);
8359 }
8360 }
8361 break;
8362 case Tag_ABI_VFP_args:
8363 /* Aready done. */
8364 break;
8365 case Tag_ABI_WMMX_args:
8366 if (in_attr[i].i != out_attr[i].i)
8367 {
8368 _bfd_error_handler
8369 (_("ERROR: %B uses iWMMXt register arguments, %B does not"),
8370 ibfd, obfd);
8371 return FALSE;
8372 }
8373 break;
8374 default: /* All known attributes should be explicitly covered. */
8375 abort ();
8376 }
8377
8378 if (in_attr[i].type && !out_attr[i].type)
8379 switch (in_attr[i].type)
8380 {
8381 case 1:
8382 if (out_attr[i].i)
8383 out_attr[i].type = 1;
8384 break;
8385
8386 case 2:
8387 if (out_attr[i].s)
8388 out_attr[i].type = 2;
8389 break;
8390
8391 default:
8392 abort ();
8393 }
8394 }
8395
8396 /* Merge Tag_compatibility attributes and any common GNU ones. */
8397 _bfd_elf_merge_object_attributes (ibfd, obfd);
8398
8399 /* Check for any attributes not known on ARM. */
8400 in_list = elf_other_obj_attributes_proc (ibfd);
8401 while (in_list && in_list->tag == Tag_compatibility)
8402 in_list = in_list->next;
8403
8404 for (; in_list; in_list = in_list->next)
8405 {
8406 if ((in_list->tag & 128) < 64)
8407 {
8408 _bfd_error_handler
8409 (_("Warning: %B: Unknown EABI object attribute %d"),
8410 ibfd, in_list->tag);
8411 break;
8412 }
8413 }
8414 return TRUE;
8415 }
8416
8417
8418 /* Return TRUE if the two EABI versions are incompatible. */
8419
8420 static bfd_boolean
8421 elf32_arm_versions_compatible (unsigned iver, unsigned over)
8422 {
8423 /* v4 and v5 are the same spec before and after it was released,
8424 so allow mixing them. */
8425 if ((iver == EF_ARM_EABI_VER4 && over == EF_ARM_EABI_VER5)
8426 || (iver == EF_ARM_EABI_VER5 && over == EF_ARM_EABI_VER4))
8427 return TRUE;
8428
8429 return (iver == over);
8430 }
8431
8432 /* Merge backend specific data from an object file to the output
8433 object file when linking. */
8434
8435 static bfd_boolean
8436 elf32_arm_merge_private_bfd_data (bfd * ibfd, bfd * obfd)
8437 {
8438 flagword out_flags;
8439 flagword in_flags;
8440 bfd_boolean flags_compatible = TRUE;
8441 asection *sec;
8442
8443 /* Check if we have the same endianess. */
8444 if (! _bfd_generic_verify_endian_match (ibfd, obfd))
8445 return FALSE;
8446
8447 if (! is_arm_elf (ibfd) || ! is_arm_elf (obfd))
8448 return TRUE;
8449
8450 if (!elf32_arm_merge_eabi_attributes (ibfd, obfd))
8451 return FALSE;
8452
8453 /* The input BFD must have had its flags initialised. */
8454 /* The following seems bogus to me -- The flags are initialized in
8455 the assembler but I don't think an elf_flags_init field is
8456 written into the object. */
8457 /* BFD_ASSERT (elf_flags_init (ibfd)); */
8458
8459 in_flags = elf_elfheader (ibfd)->e_flags;
8460 out_flags = elf_elfheader (obfd)->e_flags;
8461
8462 /* In theory there is no reason why we couldn't handle this. However
8463 in practice it isn't even close to working and there is no real
8464 reason to want it. */
8465 if (EF_ARM_EABI_VERSION (in_flags) >= EF_ARM_EABI_VER4
8466 && !(ibfd->flags & DYNAMIC)
8467 && (in_flags & EF_ARM_BE8))
8468 {
8469 _bfd_error_handler (_("ERROR: %B is already in final BE8 format"),
8470 ibfd);
8471 return FALSE;
8472 }
8473
8474 if (!elf_flags_init (obfd))
8475 {
8476 /* If the input is the default architecture and had the default
8477 flags then do not bother setting the flags for the output
8478 architecture, instead allow future merges to do this. If no
8479 future merges ever set these flags then they will retain their
8480 uninitialised values, which surprise surprise, correspond
8481 to the default values. */
8482 if (bfd_get_arch_info (ibfd)->the_default
8483 && elf_elfheader (ibfd)->e_flags == 0)
8484 return TRUE;
8485
8486 elf_flags_init (obfd) = TRUE;
8487 elf_elfheader (obfd)->e_flags = in_flags;
8488
8489 if (bfd_get_arch (obfd) == bfd_get_arch (ibfd)
8490 && bfd_get_arch_info (obfd)->the_default)
8491 return bfd_set_arch_mach (obfd, bfd_get_arch (ibfd), bfd_get_mach (ibfd));
8492
8493 return TRUE;
8494 }
8495
8496 /* Determine what should happen if the input ARM architecture
8497 does not match the output ARM architecture. */
8498 if (! bfd_arm_merge_machines (ibfd, obfd))
8499 return FALSE;
8500
8501 /* Identical flags must be compatible. */
8502 if (in_flags == out_flags)
8503 return TRUE;
8504
8505 /* Check to see if the input BFD actually contains any sections. If
8506 not, its flags may not have been initialised either, but it
8507 cannot actually cause any incompatiblity. Do not short-circuit
8508 dynamic objects; their section list may be emptied by
8509 elf_link_add_object_symbols.
8510
8511 Also check to see if there are no code sections in the input.
8512 In this case there is no need to check for code specific flags.
8513 XXX - do we need to worry about floating-point format compatability
8514 in data sections ? */
8515 if (!(ibfd->flags & DYNAMIC))
8516 {
8517 bfd_boolean null_input_bfd = TRUE;
8518 bfd_boolean only_data_sections = TRUE;
8519
8520 for (sec = ibfd->sections; sec != NULL; sec = sec->next)
8521 {
8522 /* Ignore synthetic glue sections. */
8523 if (strcmp (sec->name, ".glue_7")
8524 && strcmp (sec->name, ".glue_7t"))
8525 {
8526 if ((bfd_get_section_flags (ibfd, sec)
8527 & (SEC_LOAD | SEC_CODE | SEC_HAS_CONTENTS))
8528 == (SEC_LOAD | SEC_CODE | SEC_HAS_CONTENTS))
8529 only_data_sections = FALSE;
8530
8531 null_input_bfd = FALSE;
8532 break;
8533 }
8534 }
8535
8536 if (null_input_bfd || only_data_sections)
8537 return TRUE;
8538 }
8539
8540 /* Complain about various flag mismatches. */
8541 if (!elf32_arm_versions_compatible (EF_ARM_EABI_VERSION (in_flags),
8542 EF_ARM_EABI_VERSION (out_flags)))
8543 {
8544 _bfd_error_handler
8545 (_("ERROR: Source object %B has EABI version %d, but target %B has EABI version %d"),
8546 ibfd, obfd,
8547 (in_flags & EF_ARM_EABIMASK) >> 24,
8548 (out_flags & EF_ARM_EABIMASK) >> 24);
8549 return FALSE;
8550 }
8551
8552 /* Not sure what needs to be checked for EABI versions >= 1. */
8553 /* VxWorks libraries do not use these flags. */
8554 if (get_elf_backend_data (obfd) != &elf32_arm_vxworks_bed
8555 && get_elf_backend_data (ibfd) != &elf32_arm_vxworks_bed
8556 && EF_ARM_EABI_VERSION (in_flags) == EF_ARM_EABI_UNKNOWN)
8557 {
8558 if ((in_flags & EF_ARM_APCS_26) != (out_flags & EF_ARM_APCS_26))
8559 {
8560 _bfd_error_handler
8561 (_("ERROR: %B is compiled for APCS-%d, whereas target %B uses APCS-%d"),
8562 ibfd, obfd,
8563 in_flags & EF_ARM_APCS_26 ? 26 : 32,
8564 out_flags & EF_ARM_APCS_26 ? 26 : 32);
8565 flags_compatible = FALSE;
8566 }
8567
8568 if ((in_flags & EF_ARM_APCS_FLOAT) != (out_flags & EF_ARM_APCS_FLOAT))
8569 {
8570 if (in_flags & EF_ARM_APCS_FLOAT)
8571 _bfd_error_handler
8572 (_("ERROR: %B passes floats in float registers, whereas %B passes them in integer registers"),
8573 ibfd, obfd);
8574 else
8575 _bfd_error_handler
8576 (_("ERROR: %B passes floats in integer registers, whereas %B passes them in float registers"),
8577 ibfd, obfd);
8578
8579 flags_compatible = FALSE;
8580 }
8581
8582 if ((in_flags & EF_ARM_VFP_FLOAT) != (out_flags & EF_ARM_VFP_FLOAT))
8583 {
8584 if (in_flags & EF_ARM_VFP_FLOAT)
8585 _bfd_error_handler
8586 (_("ERROR: %B uses VFP instructions, whereas %B does not"),
8587 ibfd, obfd);
8588 else
8589 _bfd_error_handler
8590 (_("ERROR: %B uses FPA instructions, whereas %B does not"),
8591 ibfd, obfd);
8592
8593 flags_compatible = FALSE;
8594 }
8595
8596 if ((in_flags & EF_ARM_MAVERICK_FLOAT) != (out_flags & EF_ARM_MAVERICK_FLOAT))
8597 {
8598 if (in_flags & EF_ARM_MAVERICK_FLOAT)
8599 _bfd_error_handler
8600 (_("ERROR: %B uses Maverick instructions, whereas %B does not"),
8601 ibfd, obfd);
8602 else
8603 _bfd_error_handler
8604 (_("ERROR: %B does not use Maverick instructions, whereas %B does"),
8605 ibfd, obfd);
8606
8607 flags_compatible = FALSE;
8608 }
8609
8610 #ifdef EF_ARM_SOFT_FLOAT
8611 if ((in_flags & EF_ARM_SOFT_FLOAT) != (out_flags & EF_ARM_SOFT_FLOAT))
8612 {
8613 /* We can allow interworking between code that is VFP format
8614 layout, and uses either soft float or integer regs for
8615 passing floating point arguments and results. We already
8616 know that the APCS_FLOAT flags match; similarly for VFP
8617 flags. */
8618 if ((in_flags & EF_ARM_APCS_FLOAT) != 0
8619 || (in_flags & EF_ARM_VFP_FLOAT) == 0)
8620 {
8621 if (in_flags & EF_ARM_SOFT_FLOAT)
8622 _bfd_error_handler
8623 (_("ERROR: %B uses software FP, whereas %B uses hardware FP"),
8624 ibfd, obfd);
8625 else
8626 _bfd_error_handler
8627 (_("ERROR: %B uses hardware FP, whereas %B uses software FP"),
8628 ibfd, obfd);
8629
8630 flags_compatible = FALSE;
8631 }
8632 }
8633 #endif
8634
8635 /* Interworking mismatch is only a warning. */
8636 if ((in_flags & EF_ARM_INTERWORK) != (out_flags & EF_ARM_INTERWORK))
8637 {
8638 if (in_flags & EF_ARM_INTERWORK)
8639 {
8640 _bfd_error_handler
8641 (_("Warning: %B supports interworking, whereas %B does not"),
8642 ibfd, obfd);
8643 }
8644 else
8645 {
8646 _bfd_error_handler
8647 (_("Warning: %B does not support interworking, whereas %B does"),
8648 ibfd, obfd);
8649 }
8650 }
8651 }
8652
8653 return flags_compatible;
8654 }
8655
8656 /* Display the flags field. */
8657
8658 static bfd_boolean
8659 elf32_arm_print_private_bfd_data (bfd *abfd, void * ptr)
8660 {
8661 FILE * file = (FILE *) ptr;
8662 unsigned long flags;
8663
8664 BFD_ASSERT (abfd != NULL && ptr != NULL);
8665
8666 /* Print normal ELF private data. */
8667 _bfd_elf_print_private_bfd_data (abfd, ptr);
8668
8669 flags = elf_elfheader (abfd)->e_flags;
8670 /* Ignore init flag - it may not be set, despite the flags field
8671 containing valid data. */
8672
8673 /* xgettext:c-format */
8674 fprintf (file, _("private flags = %lx:"), elf_elfheader (abfd)->e_flags);
8675
8676 switch (EF_ARM_EABI_VERSION (flags))
8677 {
8678 case EF_ARM_EABI_UNKNOWN:
8679 /* The following flag bits are GNU extensions and not part of the
8680 official ARM ELF extended ABI. Hence they are only decoded if
8681 the EABI version is not set. */
8682 if (flags & EF_ARM_INTERWORK)
8683 fprintf (file, _(" [interworking enabled]"));
8684
8685 if (flags & EF_ARM_APCS_26)
8686 fprintf (file, " [APCS-26]");
8687 else
8688 fprintf (file, " [APCS-32]");
8689
8690 if (flags & EF_ARM_VFP_FLOAT)
8691 fprintf (file, _(" [VFP float format]"));
8692 else if (flags & EF_ARM_MAVERICK_FLOAT)
8693 fprintf (file, _(" [Maverick float format]"));
8694 else
8695 fprintf (file, _(" [FPA float format]"));
8696
8697 if (flags & EF_ARM_APCS_FLOAT)
8698 fprintf (file, _(" [floats passed in float registers]"));
8699
8700 if (flags & EF_ARM_PIC)
8701 fprintf (file, _(" [position independent]"));
8702
8703 if (flags & EF_ARM_NEW_ABI)
8704 fprintf (file, _(" [new ABI]"));
8705
8706 if (flags & EF_ARM_OLD_ABI)
8707 fprintf (file, _(" [old ABI]"));
8708
8709 if (flags & EF_ARM_SOFT_FLOAT)
8710 fprintf (file, _(" [software FP]"));
8711
8712 flags &= ~(EF_ARM_INTERWORK | EF_ARM_APCS_26 | EF_ARM_APCS_FLOAT
8713 | EF_ARM_PIC | EF_ARM_NEW_ABI | EF_ARM_OLD_ABI
8714 | EF_ARM_SOFT_FLOAT | EF_ARM_VFP_FLOAT
8715 | EF_ARM_MAVERICK_FLOAT);
8716 break;
8717
8718 case EF_ARM_EABI_VER1:
8719 fprintf (file, _(" [Version1 EABI]"));
8720
8721 if (flags & EF_ARM_SYMSARESORTED)
8722 fprintf (file, _(" [sorted symbol table]"));
8723 else
8724 fprintf (file, _(" [unsorted symbol table]"));
8725
8726 flags &= ~ EF_ARM_SYMSARESORTED;
8727 break;
8728
8729 case EF_ARM_EABI_VER2:
8730 fprintf (file, _(" [Version2 EABI]"));
8731
8732 if (flags & EF_ARM_SYMSARESORTED)
8733 fprintf (file, _(" [sorted symbol table]"));
8734 else
8735 fprintf (file, _(" [unsorted symbol table]"));
8736
8737 if (flags & EF_ARM_DYNSYMSUSESEGIDX)
8738 fprintf (file, _(" [dynamic symbols use segment index]"));
8739
8740 if (flags & EF_ARM_MAPSYMSFIRST)
8741 fprintf (file, _(" [mapping symbols precede others]"));
8742
8743 flags &= ~(EF_ARM_SYMSARESORTED | EF_ARM_DYNSYMSUSESEGIDX
8744 | EF_ARM_MAPSYMSFIRST);
8745 break;
8746
8747 case EF_ARM_EABI_VER3:
8748 fprintf (file, _(" [Version3 EABI]"));
8749 break;
8750
8751 case EF_ARM_EABI_VER4:
8752 fprintf (file, _(" [Version4 EABI]"));
8753 goto eabi;
8754
8755 case EF_ARM_EABI_VER5:
8756 fprintf (file, _(" [Version5 EABI]"));
8757 eabi:
8758 if (flags & EF_ARM_BE8)
8759 fprintf (file, _(" [BE8]"));
8760
8761 if (flags & EF_ARM_LE8)
8762 fprintf (file, _(" [LE8]"));
8763
8764 flags &= ~(EF_ARM_LE8 | EF_ARM_BE8);
8765 break;
8766
8767 default:
8768 fprintf (file, _(" <EABI version unrecognised>"));
8769 break;
8770 }
8771
8772 flags &= ~ EF_ARM_EABIMASK;
8773
8774 if (flags & EF_ARM_RELEXEC)
8775 fprintf (file, _(" [relocatable executable]"));
8776
8777 if (flags & EF_ARM_HASENTRY)
8778 fprintf (file, _(" [has entry point]"));
8779
8780 flags &= ~ (EF_ARM_RELEXEC | EF_ARM_HASENTRY);
8781
8782 if (flags)
8783 fprintf (file, _("<Unrecognised flag bits set>"));
8784
8785 fputc ('\n', file);
8786
8787 return TRUE;
8788 }
8789
8790 static int
8791 elf32_arm_get_symbol_type (Elf_Internal_Sym * elf_sym, int type)
8792 {
8793 switch (ELF_ST_TYPE (elf_sym->st_info))
8794 {
8795 case STT_ARM_TFUNC:
8796 return ELF_ST_TYPE (elf_sym->st_info);
8797
8798 case STT_ARM_16BIT:
8799 /* If the symbol is not an object, return the STT_ARM_16BIT flag.
8800 This allows us to distinguish between data used by Thumb instructions
8801 and non-data (which is probably code) inside Thumb regions of an
8802 executable. */
8803 if (type != STT_OBJECT && type != STT_TLS)
8804 return ELF_ST_TYPE (elf_sym->st_info);
8805 break;
8806
8807 default:
8808 break;
8809 }
8810
8811 return type;
8812 }
8813
8814 static asection *
8815 elf32_arm_gc_mark_hook (asection *sec,
8816 struct bfd_link_info *info,
8817 Elf_Internal_Rela *rel,
8818 struct elf_link_hash_entry *h,
8819 Elf_Internal_Sym *sym)
8820 {
8821 if (h != NULL)
8822 switch (ELF32_R_TYPE (rel->r_info))
8823 {
8824 case R_ARM_GNU_VTINHERIT:
8825 case R_ARM_GNU_VTENTRY:
8826 return NULL;
8827 }
8828
8829 return _bfd_elf_gc_mark_hook (sec, info, rel, h, sym);
8830 }
8831
8832 /* Update the got entry reference counts for the section being removed. */
8833
8834 static bfd_boolean
8835 elf32_arm_gc_sweep_hook (bfd * abfd,
8836 struct bfd_link_info * info,
8837 asection * sec,
8838 const Elf_Internal_Rela * relocs)
8839 {
8840 Elf_Internal_Shdr *symtab_hdr;
8841 struct elf_link_hash_entry **sym_hashes;
8842 bfd_signed_vma *local_got_refcounts;
8843 const Elf_Internal_Rela *rel, *relend;
8844 struct elf32_arm_link_hash_table * globals;
8845
8846 if (info->relocatable)
8847 return TRUE;
8848
8849 globals = elf32_arm_hash_table (info);
8850
8851 elf_section_data (sec)->local_dynrel = NULL;
8852
8853 symtab_hdr = & elf_symtab_hdr (abfd);
8854 sym_hashes = elf_sym_hashes (abfd);
8855 local_got_refcounts = elf_local_got_refcounts (abfd);
8856
8857 check_use_blx (globals);
8858
8859 relend = relocs + sec->reloc_count;
8860 for (rel = relocs; rel < relend; rel++)
8861 {
8862 unsigned long r_symndx;
8863 struct elf_link_hash_entry *h = NULL;
8864 int r_type;
8865
8866 r_symndx = ELF32_R_SYM (rel->r_info);
8867 if (r_symndx >= symtab_hdr->sh_info)
8868 {
8869 h = sym_hashes[r_symndx - symtab_hdr->sh_info];
8870 while (h->root.type == bfd_link_hash_indirect
8871 || h->root.type == bfd_link_hash_warning)
8872 h = (struct elf_link_hash_entry *) h->root.u.i.link;
8873 }
8874
8875 r_type = ELF32_R_TYPE (rel->r_info);
8876 r_type = arm_real_reloc_type (globals, r_type);
8877 switch (r_type)
8878 {
8879 case R_ARM_GOT32:
8880 case R_ARM_GOT_PREL:
8881 case R_ARM_TLS_GD32:
8882 case R_ARM_TLS_IE32:
8883 if (h != NULL)
8884 {
8885 if (h->got.refcount > 0)
8886 h->got.refcount -= 1;
8887 }
8888 else if (local_got_refcounts != NULL)
8889 {
8890 if (local_got_refcounts[r_symndx] > 0)
8891 local_got_refcounts[r_symndx] -= 1;
8892 }
8893 break;
8894
8895 case R_ARM_TLS_LDM32:
8896 elf32_arm_hash_table (info)->tls_ldm_got.refcount -= 1;
8897 break;
8898
8899 case R_ARM_ABS32:
8900 case R_ARM_ABS32_NOI:
8901 case R_ARM_REL32:
8902 case R_ARM_REL32_NOI:
8903 case R_ARM_PC24:
8904 case R_ARM_PLT32:
8905 case R_ARM_CALL:
8906 case R_ARM_JUMP24:
8907 case R_ARM_PREL31:
8908 case R_ARM_THM_CALL:
8909 case R_ARM_THM_JUMP24:
8910 case R_ARM_THM_JUMP19:
8911 case R_ARM_MOVW_ABS_NC:
8912 case R_ARM_MOVT_ABS:
8913 case R_ARM_MOVW_PREL_NC:
8914 case R_ARM_MOVT_PREL:
8915 case R_ARM_THM_MOVW_ABS_NC:
8916 case R_ARM_THM_MOVT_ABS:
8917 case R_ARM_THM_MOVW_PREL_NC:
8918 case R_ARM_THM_MOVT_PREL:
8919 /* Should the interworking branches be here also? */
8920
8921 if (h != NULL)
8922 {
8923 struct elf32_arm_link_hash_entry *eh;
8924 struct elf32_arm_relocs_copied **pp;
8925 struct elf32_arm_relocs_copied *p;
8926
8927 eh = (struct elf32_arm_link_hash_entry *) h;
8928
8929 if (h->plt.refcount > 0)
8930 {
8931 h->plt.refcount -= 1;
8932 if (r_type == R_ARM_THM_CALL)
8933 eh->plt_maybe_thumb_refcount--;
8934
8935 if (r_type == R_ARM_THM_JUMP24
8936 || r_type == R_ARM_THM_JUMP19)
8937 eh->plt_thumb_refcount--;
8938 }
8939
8940 if (r_type == R_ARM_ABS32
8941 || r_type == R_ARM_REL32
8942 || r_type == R_ARM_ABS32_NOI
8943 || r_type == R_ARM_REL32_NOI)
8944 {
8945 for (pp = &eh->relocs_copied; (p = *pp) != NULL;
8946 pp = &p->next)
8947 if (p->section == sec)
8948 {
8949 p->count -= 1;
8950 if (ELF32_R_TYPE (rel->r_info) == R_ARM_REL32
8951 || ELF32_R_TYPE (rel->r_info) == R_ARM_REL32_NOI)
8952 p->pc_count -= 1;
8953 if (p->count == 0)
8954 *pp = p->next;
8955 break;
8956 }
8957 }
8958 }
8959 break;
8960
8961 default:
8962 break;
8963 }
8964 }
8965
8966 return TRUE;
8967 }
8968
8969 /* Look through the relocs for a section during the first phase. */
8970
8971 static bfd_boolean
8972 elf32_arm_check_relocs (bfd *abfd, struct bfd_link_info *info,
8973 asection *sec, const Elf_Internal_Rela *relocs)
8974 {
8975 Elf_Internal_Shdr *symtab_hdr;
8976 struct elf_link_hash_entry **sym_hashes;
8977 const Elf_Internal_Rela *rel;
8978 const Elf_Internal_Rela *rel_end;
8979 bfd *dynobj;
8980 asection *sreloc;
8981 bfd_vma *local_got_offsets;
8982 struct elf32_arm_link_hash_table *htab;
8983 bfd_boolean needs_plt;
8984
8985 if (info->relocatable)
8986 return TRUE;
8987
8988 BFD_ASSERT (is_arm_elf (abfd));
8989
8990 htab = elf32_arm_hash_table (info);
8991 sreloc = NULL;
8992
8993 /* Create dynamic sections for relocatable executables so that we can
8994 copy relocations. */
8995 if (htab->root.is_relocatable_executable
8996 && ! htab->root.dynamic_sections_created)
8997 {
8998 if (! _bfd_elf_link_create_dynamic_sections (abfd, info))
8999 return FALSE;
9000 }
9001
9002 dynobj = elf_hash_table (info)->dynobj;
9003 local_got_offsets = elf_local_got_offsets (abfd);
9004
9005 symtab_hdr = & elf_symtab_hdr (abfd);
9006 sym_hashes = elf_sym_hashes (abfd);
9007
9008 rel_end = relocs + sec->reloc_count;
9009 for (rel = relocs; rel < rel_end; rel++)
9010 {
9011 struct elf_link_hash_entry *h;
9012 struct elf32_arm_link_hash_entry *eh;
9013 unsigned long r_symndx;
9014 int r_type;
9015
9016 r_symndx = ELF32_R_SYM (rel->r_info);
9017 r_type = ELF32_R_TYPE (rel->r_info);
9018 r_type = arm_real_reloc_type (htab, r_type);
9019
9020 if (r_symndx >= NUM_SHDR_ENTRIES (symtab_hdr))
9021 {
9022 (*_bfd_error_handler) (_("%B: bad symbol index: %d"), abfd,
9023 r_symndx);
9024 return FALSE;
9025 }
9026
9027 if (r_symndx < symtab_hdr->sh_info)
9028 h = NULL;
9029 else
9030 {
9031 h = sym_hashes[r_symndx - symtab_hdr->sh_info];
9032 while (h->root.type == bfd_link_hash_indirect
9033 || h->root.type == bfd_link_hash_warning)
9034 h = (struct elf_link_hash_entry *) h->root.u.i.link;
9035 }
9036
9037 eh = (struct elf32_arm_link_hash_entry *) h;
9038
9039 switch (r_type)
9040 {
9041 case R_ARM_GOT32:
9042 case R_ARM_GOT_PREL:
9043 case R_ARM_TLS_GD32:
9044 case R_ARM_TLS_IE32:
9045 /* This symbol requires a global offset table entry. */
9046 {
9047 int tls_type, old_tls_type;
9048
9049 switch (r_type)
9050 {
9051 case R_ARM_TLS_GD32: tls_type = GOT_TLS_GD; break;
9052 case R_ARM_TLS_IE32: tls_type = GOT_TLS_IE; break;
9053 default: tls_type = GOT_NORMAL; break;
9054 }
9055
9056 if (h != NULL)
9057 {
9058 h->got.refcount++;
9059 old_tls_type = elf32_arm_hash_entry (h)->tls_type;
9060 }
9061 else
9062 {
9063 bfd_signed_vma *local_got_refcounts;
9064
9065 /* This is a global offset table entry for a local symbol. */
9066 local_got_refcounts = elf_local_got_refcounts (abfd);
9067 if (local_got_refcounts == NULL)
9068 {
9069 bfd_size_type size;
9070
9071 size = symtab_hdr->sh_info;
9072 size *= (sizeof (bfd_signed_vma) + sizeof (char));
9073 local_got_refcounts = bfd_zalloc (abfd, size);
9074 if (local_got_refcounts == NULL)
9075 return FALSE;
9076 elf_local_got_refcounts (abfd) = local_got_refcounts;
9077 elf32_arm_local_got_tls_type (abfd)
9078 = (char *) (local_got_refcounts + symtab_hdr->sh_info);
9079 }
9080 local_got_refcounts[r_symndx] += 1;
9081 old_tls_type = elf32_arm_local_got_tls_type (abfd) [r_symndx];
9082 }
9083
9084 /* We will already have issued an error message if there is a
9085 TLS / non-TLS mismatch, based on the symbol type. We don't
9086 support any linker relaxations. So just combine any TLS
9087 types needed. */
9088 if (old_tls_type != GOT_UNKNOWN && old_tls_type != GOT_NORMAL
9089 && tls_type != GOT_NORMAL)
9090 tls_type |= old_tls_type;
9091
9092 if (old_tls_type != tls_type)
9093 {
9094 if (h != NULL)
9095 elf32_arm_hash_entry (h)->tls_type = tls_type;
9096 else
9097 elf32_arm_local_got_tls_type (abfd) [r_symndx] = tls_type;
9098 }
9099 }
9100 /* Fall through */
9101
9102 case R_ARM_TLS_LDM32:
9103 if (r_type == R_ARM_TLS_LDM32)
9104 htab->tls_ldm_got.refcount++;
9105 /* Fall through */
9106
9107 case R_ARM_GOTOFF32:
9108 case R_ARM_GOTPC:
9109 if (htab->sgot == NULL)
9110 {
9111 if (htab->root.dynobj == NULL)
9112 htab->root.dynobj = abfd;
9113 if (!create_got_section (htab->root.dynobj, info))
9114 return FALSE;
9115 }
9116 break;
9117
9118 case R_ARM_ABS12:
9119 /* VxWorks uses dynamic R_ARM_ABS12 relocations for
9120 ldr __GOTT_INDEX__ offsets. */
9121 if (!htab->vxworks_p)
9122 break;
9123 /* Fall through */
9124
9125 case R_ARM_PC24:
9126 case R_ARM_PLT32:
9127 case R_ARM_CALL:
9128 case R_ARM_JUMP24:
9129 case R_ARM_PREL31:
9130 case R_ARM_THM_CALL:
9131 case R_ARM_THM_JUMP24:
9132 case R_ARM_THM_JUMP19:
9133 needs_plt = 1;
9134 goto normal_reloc;
9135
9136 case R_ARM_ABS32:
9137 case R_ARM_ABS32_NOI:
9138 case R_ARM_REL32:
9139 case R_ARM_REL32_NOI:
9140 case R_ARM_MOVW_ABS_NC:
9141 case R_ARM_MOVT_ABS:
9142 case R_ARM_MOVW_PREL_NC:
9143 case R_ARM_MOVT_PREL:
9144 case R_ARM_THM_MOVW_ABS_NC:
9145 case R_ARM_THM_MOVT_ABS:
9146 case R_ARM_THM_MOVW_PREL_NC:
9147 case R_ARM_THM_MOVT_PREL:
9148 needs_plt = 0;
9149 normal_reloc:
9150
9151 /* Should the interworking branches be listed here? */
9152 if (h != NULL)
9153 {
9154 /* If this reloc is in a read-only section, we might
9155 need a copy reloc. We can't check reliably at this
9156 stage whether the section is read-only, as input
9157 sections have not yet been mapped to output sections.
9158 Tentatively set the flag for now, and correct in
9159 adjust_dynamic_symbol. */
9160 if (!info->shared)
9161 h->non_got_ref = 1;
9162
9163 /* We may need a .plt entry if the function this reloc
9164 refers to is in a different object. We can't tell for
9165 sure yet, because something later might force the
9166 symbol local. */
9167 if (needs_plt)
9168 h->needs_plt = 1;
9169
9170 /* If we create a PLT entry, this relocation will reference
9171 it, even if it's an ABS32 relocation. */
9172 h->plt.refcount += 1;
9173
9174 /* It's too early to use htab->use_blx here, so we have to
9175 record possible blx references separately from
9176 relocs that definitely need a thumb stub. */
9177
9178 if (r_type == R_ARM_THM_CALL)
9179 eh->plt_maybe_thumb_refcount += 1;
9180
9181 if (r_type == R_ARM_THM_JUMP24
9182 || r_type == R_ARM_THM_JUMP19)
9183 eh->plt_thumb_refcount += 1;
9184 }
9185
9186 /* If we are creating a shared library or relocatable executable,
9187 and this is a reloc against a global symbol, or a non PC
9188 relative reloc against a local symbol, then we need to copy
9189 the reloc into the shared library. However, if we are linking
9190 with -Bsymbolic, we do not need to copy a reloc against a
9191 global symbol which is defined in an object we are
9192 including in the link (i.e., DEF_REGULAR is set). At
9193 this point we have not seen all the input files, so it is
9194 possible that DEF_REGULAR is not set now but will be set
9195 later (it is never cleared). We account for that
9196 possibility below by storing information in the
9197 relocs_copied field of the hash table entry. */
9198 if ((info->shared || htab->root.is_relocatable_executable)
9199 && (sec->flags & SEC_ALLOC) != 0
9200 && ((r_type == R_ARM_ABS32 || r_type == R_ARM_ABS32_NOI)
9201 || (h != NULL && ! h->needs_plt
9202 && (! info->symbolic || ! h->def_regular))))
9203 {
9204 struct elf32_arm_relocs_copied *p, **head;
9205
9206 /* When creating a shared object, we must copy these
9207 reloc types into the output file. We create a reloc
9208 section in dynobj and make room for this reloc. */
9209 if (sreloc == NULL)
9210 {
9211 const char * name;
9212
9213 name = (bfd_elf_string_from_elf_section
9214 (abfd,
9215 elf_elfheader (abfd)->e_shstrndx,
9216 elf_section_data (sec)->rel_hdr.sh_name));
9217 if (name == NULL)
9218 return FALSE;
9219
9220 BFD_ASSERT (reloc_section_p (htab, name, sec));
9221
9222 sreloc = bfd_get_section_by_name (dynobj, name);
9223 if (sreloc == NULL)
9224 {
9225 flagword flags;
9226
9227 flags = (SEC_HAS_CONTENTS | SEC_READONLY
9228 | SEC_IN_MEMORY | SEC_LINKER_CREATED);
9229 if ((sec->flags & SEC_ALLOC) != 0
9230 /* BPABI objects never have dynamic
9231 relocations mapped. */
9232 && !htab->symbian_p)
9233 flags |= SEC_ALLOC | SEC_LOAD;
9234 sreloc = bfd_make_section_with_flags (dynobj,
9235 name,
9236 flags);
9237 if (sreloc == NULL
9238 || ! bfd_set_section_alignment (dynobj, sreloc, 2))
9239 return FALSE;
9240 }
9241
9242 elf_section_data (sec)->sreloc = sreloc;
9243 }
9244
9245 /* If this is a global symbol, we count the number of
9246 relocations we need for this symbol. */
9247 if (h != NULL)
9248 {
9249 head = &((struct elf32_arm_link_hash_entry *) h)->relocs_copied;
9250 }
9251 else
9252 {
9253 /* Track dynamic relocs needed for local syms too.
9254 We really need local syms available to do this
9255 easily. Oh well. */
9256
9257 asection *s;
9258 void *vpp;
9259
9260 s = bfd_section_from_r_symndx (abfd, &htab->sym_sec,
9261 sec, r_symndx);
9262 if (s == NULL)
9263 return FALSE;
9264
9265 vpp = &elf_section_data (s)->local_dynrel;
9266 head = (struct elf32_arm_relocs_copied **) vpp;
9267 }
9268
9269 p = *head;
9270 if (p == NULL || p->section != sec)
9271 {
9272 bfd_size_type amt = sizeof *p;
9273
9274 p = bfd_alloc (htab->root.dynobj, amt);
9275 if (p == NULL)
9276 return FALSE;
9277 p->next = *head;
9278 *head = p;
9279 p->section = sec;
9280 p->count = 0;
9281 p->pc_count = 0;
9282 }
9283
9284 if (r_type == R_ARM_REL32 || r_type == R_ARM_REL32_NOI)
9285 p->pc_count += 1;
9286 p->count += 1;
9287 }
9288 break;
9289
9290 /* This relocation describes the C++ object vtable hierarchy.
9291 Reconstruct it for later use during GC. */
9292 case R_ARM_GNU_VTINHERIT:
9293 if (!bfd_elf_gc_record_vtinherit (abfd, sec, h, rel->r_offset))
9294 return FALSE;
9295 break;
9296
9297 /* This relocation describes which C++ vtable entries are actually
9298 used. Record for later use during GC. */
9299 case R_ARM_GNU_VTENTRY:
9300 BFD_ASSERT (h != NULL);
9301 if (h != NULL
9302 && !bfd_elf_gc_record_vtentry (abfd, sec, h, rel->r_offset))
9303 return FALSE;
9304 break;
9305 }
9306 }
9307
9308 return TRUE;
9309 }
9310
9311 /* Unwinding tables are not referenced directly. This pass marks them as
9312 required if the corresponding code section is marked. */
9313
9314 static bfd_boolean
9315 elf32_arm_gc_mark_extra_sections (struct bfd_link_info *info,
9316 elf_gc_mark_hook_fn gc_mark_hook)
9317 {
9318 bfd *sub;
9319 Elf_Internal_Shdr **elf_shdrp;
9320 bfd_boolean again;
9321
9322 /* Marking EH data may cause additional code sections to be marked,
9323 requiring multiple passes. */
9324 again = TRUE;
9325 while (again)
9326 {
9327 again = FALSE;
9328 for (sub = info->input_bfds; sub != NULL; sub = sub->link_next)
9329 {
9330 asection *o;
9331
9332 if (! is_arm_elf (sub))
9333 continue;
9334
9335 elf_shdrp = elf_elfsections (sub);
9336 for (o = sub->sections; o != NULL; o = o->next)
9337 {
9338 Elf_Internal_Shdr *hdr;
9339
9340 hdr = &elf_section_data (o)->this_hdr;
9341 if (hdr->sh_type == SHT_ARM_EXIDX
9342 && hdr->sh_link
9343 && hdr->sh_link < elf_numsections (sub)
9344 && !o->gc_mark
9345 && elf_shdrp[hdr->sh_link]->bfd_section->gc_mark)
9346 {
9347 again = TRUE;
9348 if (!_bfd_elf_gc_mark (info, o, gc_mark_hook))
9349 return FALSE;
9350 }
9351 }
9352 }
9353 }
9354
9355 return TRUE;
9356 }
9357
9358 /* Treat mapping symbols as special target symbols. */
9359
9360 static bfd_boolean
9361 elf32_arm_is_target_special_symbol (bfd * abfd ATTRIBUTE_UNUSED, asymbol * sym)
9362 {
9363 return bfd_is_arm_special_symbol_name (sym->name,
9364 BFD_ARM_SPECIAL_SYM_TYPE_ANY);
9365 }
9366
9367 /* This is a copy of elf_find_function() from elf.c except that
9368 ARM mapping symbols are ignored when looking for function names
9369 and STT_ARM_TFUNC is considered to a function type. */
9370
9371 static bfd_boolean
9372 arm_elf_find_function (bfd * abfd ATTRIBUTE_UNUSED,
9373 asection * section,
9374 asymbol ** symbols,
9375 bfd_vma offset,
9376 const char ** filename_ptr,
9377 const char ** functionname_ptr)
9378 {
9379 const char * filename = NULL;
9380 asymbol * func = NULL;
9381 bfd_vma low_func = 0;
9382 asymbol ** p;
9383
9384 for (p = symbols; *p != NULL; p++)
9385 {
9386 elf_symbol_type *q;
9387
9388 q = (elf_symbol_type *) *p;
9389
9390 switch (ELF_ST_TYPE (q->internal_elf_sym.st_info))
9391 {
9392 default:
9393 break;
9394 case STT_FILE:
9395 filename = bfd_asymbol_name (&q->symbol);
9396 break;
9397 case STT_FUNC:
9398 case STT_ARM_TFUNC:
9399 case STT_NOTYPE:
9400 /* Skip mapping symbols. */
9401 if ((q->symbol.flags & BSF_LOCAL)
9402 && bfd_is_arm_special_symbol_name (q->symbol.name,
9403 BFD_ARM_SPECIAL_SYM_TYPE_ANY))
9404 continue;
9405 /* Fall through. */
9406 if (bfd_get_section (&q->symbol) == section
9407 && q->symbol.value >= low_func
9408 && q->symbol.value <= offset)
9409 {
9410 func = (asymbol *) q;
9411 low_func = q->symbol.value;
9412 }
9413 break;
9414 }
9415 }
9416
9417 if (func == NULL)
9418 return FALSE;
9419
9420 if (filename_ptr)
9421 *filename_ptr = filename;
9422 if (functionname_ptr)
9423 *functionname_ptr = bfd_asymbol_name (func);
9424
9425 return TRUE;
9426 }
9427
9428
9429 /* Find the nearest line to a particular section and offset, for error
9430 reporting. This code is a duplicate of the code in elf.c, except
9431 that it uses arm_elf_find_function. */
9432
9433 static bfd_boolean
9434 elf32_arm_find_nearest_line (bfd * abfd,
9435 asection * section,
9436 asymbol ** symbols,
9437 bfd_vma offset,
9438 const char ** filename_ptr,
9439 const char ** functionname_ptr,
9440 unsigned int * line_ptr)
9441 {
9442 bfd_boolean found = FALSE;
9443
9444 /* We skip _bfd_dwarf1_find_nearest_line since no known ARM toolchain uses it. */
9445
9446 if (_bfd_dwarf2_find_nearest_line (abfd, section, symbols, offset,
9447 filename_ptr, functionname_ptr,
9448 line_ptr, 0,
9449 & elf_tdata (abfd)->dwarf2_find_line_info))
9450 {
9451 if (!*functionname_ptr)
9452 arm_elf_find_function (abfd, section, symbols, offset,
9453 *filename_ptr ? NULL : filename_ptr,
9454 functionname_ptr);
9455
9456 return TRUE;
9457 }
9458
9459 if (! _bfd_stab_section_find_nearest_line (abfd, symbols, section, offset,
9460 & found, filename_ptr,
9461 functionname_ptr, line_ptr,
9462 & elf_tdata (abfd)->line_info))
9463 return FALSE;
9464
9465 if (found && (*functionname_ptr || *line_ptr))
9466 return TRUE;
9467
9468 if (symbols == NULL)
9469 return FALSE;
9470
9471 if (! arm_elf_find_function (abfd, section, symbols, offset,
9472 filename_ptr, functionname_ptr))
9473 return FALSE;
9474
9475 *line_ptr = 0;
9476 return TRUE;
9477 }
9478
9479 static bfd_boolean
9480 elf32_arm_find_inliner_info (bfd * abfd,
9481 const char ** filename_ptr,
9482 const char ** functionname_ptr,
9483 unsigned int * line_ptr)
9484 {
9485 bfd_boolean found;
9486 found = _bfd_dwarf2_find_inliner_info (abfd, filename_ptr,
9487 functionname_ptr, line_ptr,
9488 & elf_tdata (abfd)->dwarf2_find_line_info);
9489 return found;
9490 }
9491
9492 /* Adjust a symbol defined by a dynamic object and referenced by a
9493 regular object. The current definition is in some section of the
9494 dynamic object, but we're not including those sections. We have to
9495 change the definition to something the rest of the link can
9496 understand. */
9497
9498 static bfd_boolean
9499 elf32_arm_adjust_dynamic_symbol (struct bfd_link_info * info,
9500 struct elf_link_hash_entry * h)
9501 {
9502 bfd * dynobj;
9503 asection * s;
9504 struct elf32_arm_link_hash_entry * eh;
9505 struct elf32_arm_link_hash_table *globals;
9506
9507 globals = elf32_arm_hash_table (info);
9508 dynobj = elf_hash_table (info)->dynobj;
9509
9510 /* Make sure we know what is going on here. */
9511 BFD_ASSERT (dynobj != NULL
9512 && (h->needs_plt
9513 || h->u.weakdef != NULL
9514 || (h->def_dynamic
9515 && h->ref_regular
9516 && !h->def_regular)));
9517
9518 eh = (struct elf32_arm_link_hash_entry *) h;
9519
9520 /* If this is a function, put it in the procedure linkage table. We
9521 will fill in the contents of the procedure linkage table later,
9522 when we know the address of the .got section. */
9523 if (h->type == STT_FUNC || h->type == STT_ARM_TFUNC
9524 || h->needs_plt)
9525 {
9526 if (h->plt.refcount <= 0
9527 || SYMBOL_CALLS_LOCAL (info, h)
9528 || (ELF_ST_VISIBILITY (h->other) != STV_DEFAULT
9529 && h->root.type == bfd_link_hash_undefweak))
9530 {
9531 /* This case can occur if we saw a PLT32 reloc in an input
9532 file, but the symbol was never referred to by a dynamic
9533 object, or if all references were garbage collected. In
9534 such a case, we don't actually need to build a procedure
9535 linkage table, and we can just do a PC24 reloc instead. */
9536 h->plt.offset = (bfd_vma) -1;
9537 eh->plt_thumb_refcount = 0;
9538 eh->plt_maybe_thumb_refcount = 0;
9539 h->needs_plt = 0;
9540 }
9541
9542 return TRUE;
9543 }
9544 else
9545 {
9546 /* It's possible that we incorrectly decided a .plt reloc was
9547 needed for an R_ARM_PC24 or similar reloc to a non-function sym
9548 in check_relocs. We can't decide accurately between function
9549 and non-function syms in check-relocs; Objects loaded later in
9550 the link may change h->type. So fix it now. */
9551 h->plt.offset = (bfd_vma) -1;
9552 eh->plt_thumb_refcount = 0;
9553 eh->plt_maybe_thumb_refcount = 0;
9554 }
9555
9556 /* If this is a weak symbol, and there is a real definition, the
9557 processor independent code will have arranged for us to see the
9558 real definition first, and we can just use the same value. */
9559 if (h->u.weakdef != NULL)
9560 {
9561 BFD_ASSERT (h->u.weakdef->root.type == bfd_link_hash_defined
9562 || h->u.weakdef->root.type == bfd_link_hash_defweak);
9563 h->root.u.def.section = h->u.weakdef->root.u.def.section;
9564 h->root.u.def.value = h->u.weakdef->root.u.def.value;
9565 return TRUE;
9566 }
9567
9568 /* If there are no non-GOT references, we do not need a copy
9569 relocation. */
9570 if (!h->non_got_ref)
9571 return TRUE;
9572
9573 /* This is a reference to a symbol defined by a dynamic object which
9574 is not a function. */
9575
9576 /* If we are creating a shared library, we must presume that the
9577 only references to the symbol are via the global offset table.
9578 For such cases we need not do anything here; the relocations will
9579 be handled correctly by relocate_section. Relocatable executables
9580 can reference data in shared objects directly, so we don't need to
9581 do anything here. */
9582 if (info->shared || globals->root.is_relocatable_executable)
9583 return TRUE;
9584
9585 if (h->size == 0)
9586 {
9587 (*_bfd_error_handler) (_("dynamic variable `%s' is zero size"),
9588 h->root.root.string);
9589 return TRUE;
9590 }
9591
9592 /* We must allocate the symbol in our .dynbss section, which will
9593 become part of the .bss section of the executable. There will be
9594 an entry for this symbol in the .dynsym section. The dynamic
9595 object will contain position independent code, so all references
9596 from the dynamic object to this symbol will go through the global
9597 offset table. The dynamic linker will use the .dynsym entry to
9598 determine the address it must put in the global offset table, so
9599 both the dynamic object and the regular object will refer to the
9600 same memory location for the variable. */
9601 s = bfd_get_section_by_name (dynobj, ".dynbss");
9602 BFD_ASSERT (s != NULL);
9603
9604 /* We must generate a R_ARM_COPY reloc to tell the dynamic linker to
9605 copy the initial value out of the dynamic object and into the
9606 runtime process image. We need to remember the offset into the
9607 .rel(a).bss section we are going to use. */
9608 if ((h->root.u.def.section->flags & SEC_ALLOC) != 0)
9609 {
9610 asection *srel;
9611
9612 srel = bfd_get_section_by_name (dynobj, RELOC_SECTION (globals, ".bss"));
9613 BFD_ASSERT (srel != NULL);
9614 srel->size += RELOC_SIZE (globals);
9615 h->needs_copy = 1;
9616 }
9617
9618 return _bfd_elf_adjust_dynamic_copy (h, s);
9619 }
9620
9621 /* Allocate space in .plt, .got and associated reloc sections for
9622 dynamic relocs. */
9623
9624 static bfd_boolean
9625 allocate_dynrelocs (struct elf_link_hash_entry *h, void * inf)
9626 {
9627 struct bfd_link_info *info;
9628 struct elf32_arm_link_hash_table *htab;
9629 struct elf32_arm_link_hash_entry *eh;
9630 struct elf32_arm_relocs_copied *p;
9631 bfd_signed_vma thumb_refs;
9632
9633 eh = (struct elf32_arm_link_hash_entry *) h;
9634
9635 if (h->root.type == bfd_link_hash_indirect)
9636 return TRUE;
9637
9638 if (h->root.type == bfd_link_hash_warning)
9639 /* When warning symbols are created, they **replace** the "real"
9640 entry in the hash table, thus we never get to see the real
9641 symbol in a hash traversal. So look at it now. */
9642 h = (struct elf_link_hash_entry *) h->root.u.i.link;
9643
9644 info = (struct bfd_link_info *) inf;
9645 htab = elf32_arm_hash_table (info);
9646
9647 if (htab->root.dynamic_sections_created
9648 && h->plt.refcount > 0)
9649 {
9650 /* Make sure this symbol is output as a dynamic symbol.
9651 Undefined weak syms won't yet be marked as dynamic. */
9652 if (h->dynindx == -1
9653 && !h->forced_local)
9654 {
9655 if (! bfd_elf_link_record_dynamic_symbol (info, h))
9656 return FALSE;
9657 }
9658
9659 if (info->shared
9660 || WILL_CALL_FINISH_DYNAMIC_SYMBOL (1, 0, h))
9661 {
9662 asection *s = htab->splt;
9663
9664 /* If this is the first .plt entry, make room for the special
9665 first entry. */
9666 if (s->size == 0)
9667 s->size += htab->plt_header_size;
9668
9669 h->plt.offset = s->size;
9670
9671 /* If we will insert a Thumb trampoline before this PLT, leave room
9672 for it. */
9673 thumb_refs = eh->plt_thumb_refcount;
9674 if (!htab->use_blx)
9675 thumb_refs += eh->plt_maybe_thumb_refcount;
9676
9677 if (thumb_refs > 0)
9678 {
9679 h->plt.offset += PLT_THUMB_STUB_SIZE;
9680 s->size += PLT_THUMB_STUB_SIZE;
9681 }
9682
9683 /* If this symbol is not defined in a regular file, and we are
9684 not generating a shared library, then set the symbol to this
9685 location in the .plt. This is required to make function
9686 pointers compare as equal between the normal executable and
9687 the shared library. */
9688 if (! info->shared
9689 && !h->def_regular)
9690 {
9691 h->root.u.def.section = s;
9692 h->root.u.def.value = h->plt.offset;
9693
9694 /* Make sure the function is not marked as Thumb, in case
9695 it is the target of an ABS32 relocation, which will
9696 point to the PLT entry. */
9697 if (ELF_ST_TYPE (h->type) == STT_ARM_TFUNC)
9698 h->type = ELF_ST_INFO (ELF_ST_BIND (h->type), STT_FUNC);
9699 }
9700
9701 /* Make room for this entry. */
9702 s->size += htab->plt_entry_size;
9703
9704 if (!htab->symbian_p)
9705 {
9706 /* We also need to make an entry in the .got.plt section, which
9707 will be placed in the .got section by the linker script. */
9708 eh->plt_got_offset = htab->sgotplt->size;
9709 htab->sgotplt->size += 4;
9710 }
9711
9712 /* We also need to make an entry in the .rel(a).plt section. */
9713 htab->srelplt->size += RELOC_SIZE (htab);
9714
9715 /* VxWorks executables have a second set of relocations for
9716 each PLT entry. They go in a separate relocation section,
9717 which is processed by the kernel loader. */
9718 if (htab->vxworks_p && !info->shared)
9719 {
9720 /* There is a relocation for the initial PLT entry:
9721 an R_ARM_32 relocation for _GLOBAL_OFFSET_TABLE_. */
9722 if (h->plt.offset == htab->plt_header_size)
9723 htab->srelplt2->size += RELOC_SIZE (htab);
9724
9725 /* There are two extra relocations for each subsequent
9726 PLT entry: an R_ARM_32 relocation for the GOT entry,
9727 and an R_ARM_32 relocation for the PLT entry. */
9728 htab->srelplt2->size += RELOC_SIZE (htab) * 2;
9729 }
9730 }
9731 else
9732 {
9733 h->plt.offset = (bfd_vma) -1;
9734 h->needs_plt = 0;
9735 }
9736 }
9737 else
9738 {
9739 h->plt.offset = (bfd_vma) -1;
9740 h->needs_plt = 0;
9741 }
9742
9743 if (h->got.refcount > 0)
9744 {
9745 asection *s;
9746 bfd_boolean dyn;
9747 int tls_type = elf32_arm_hash_entry (h)->tls_type;
9748 int indx;
9749
9750 /* Make sure this symbol is output as a dynamic symbol.
9751 Undefined weak syms won't yet be marked as dynamic. */
9752 if (h->dynindx == -1
9753 && !h->forced_local)
9754 {
9755 if (! bfd_elf_link_record_dynamic_symbol (info, h))
9756 return FALSE;
9757 }
9758
9759 if (!htab->symbian_p)
9760 {
9761 s = htab->sgot;
9762 h->got.offset = s->size;
9763
9764 if (tls_type == GOT_UNKNOWN)
9765 abort ();
9766
9767 if (tls_type == GOT_NORMAL)
9768 /* Non-TLS symbols need one GOT slot. */
9769 s->size += 4;
9770 else
9771 {
9772 if (tls_type & GOT_TLS_GD)
9773 /* R_ARM_TLS_GD32 needs 2 consecutive GOT slots. */
9774 s->size += 8;
9775 if (tls_type & GOT_TLS_IE)
9776 /* R_ARM_TLS_IE32 needs one GOT slot. */
9777 s->size += 4;
9778 }
9779
9780 dyn = htab->root.dynamic_sections_created;
9781
9782 indx = 0;
9783 if (WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn, info->shared, h)
9784 && (!info->shared
9785 || !SYMBOL_REFERENCES_LOCAL (info, h)))
9786 indx = h->dynindx;
9787
9788 if (tls_type != GOT_NORMAL
9789 && (info->shared || indx != 0)
9790 && (ELF_ST_VISIBILITY (h->other) == STV_DEFAULT
9791 || h->root.type != bfd_link_hash_undefweak))
9792 {
9793 if (tls_type & GOT_TLS_IE)
9794 htab->srelgot->size += RELOC_SIZE (htab);
9795
9796 if (tls_type & GOT_TLS_GD)
9797 htab->srelgot->size += RELOC_SIZE (htab);
9798
9799 if ((tls_type & GOT_TLS_GD) && indx != 0)
9800 htab->srelgot->size += RELOC_SIZE (htab);
9801 }
9802 else if ((ELF_ST_VISIBILITY (h->other) == STV_DEFAULT
9803 || h->root.type != bfd_link_hash_undefweak)
9804 && (info->shared
9805 || WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn, 0, h)))
9806 htab->srelgot->size += RELOC_SIZE (htab);
9807 }
9808 }
9809 else
9810 h->got.offset = (bfd_vma) -1;
9811
9812 /* Allocate stubs for exported Thumb functions on v4t. */
9813 if (!htab->use_blx && h->dynindx != -1
9814 && h->def_regular
9815 && ELF_ST_TYPE (h->type) == STT_ARM_TFUNC
9816 && ELF_ST_VISIBILITY (h->other) == STV_DEFAULT)
9817 {
9818 struct elf_link_hash_entry * th;
9819 struct bfd_link_hash_entry * bh;
9820 struct elf_link_hash_entry * myh;
9821 char name[1024];
9822 asection *s;
9823 bh = NULL;
9824 /* Create a new symbol to regist the real location of the function. */
9825 s = h->root.u.def.section;
9826 sprintf (name, "__real_%s", h->root.root.string);
9827 _bfd_generic_link_add_one_symbol (info, s->owner,
9828 name, BSF_GLOBAL, s,
9829 h->root.u.def.value,
9830 NULL, TRUE, FALSE, &bh);
9831
9832 myh = (struct elf_link_hash_entry *) bh;
9833 myh->type = ELF_ST_INFO (STB_LOCAL, STT_ARM_TFUNC);
9834 myh->forced_local = 1;
9835 eh->export_glue = myh;
9836 th = record_arm_to_thumb_glue (info, h);
9837 /* Point the symbol at the stub. */
9838 h->type = ELF_ST_INFO (ELF_ST_BIND (h->type), STT_FUNC);
9839 h->root.u.def.section = th->root.u.def.section;
9840 h->root.u.def.value = th->root.u.def.value & ~1;
9841 }
9842
9843 if (eh->relocs_copied == NULL)
9844 return TRUE;
9845
9846 /* In the shared -Bsymbolic case, discard space allocated for
9847 dynamic pc-relative relocs against symbols which turn out to be
9848 defined in regular objects. For the normal shared case, discard
9849 space for pc-relative relocs that have become local due to symbol
9850 visibility changes. */
9851
9852 if (info->shared || htab->root.is_relocatable_executable)
9853 {
9854 /* The only relocs that use pc_count are R_ARM_REL32 and
9855 R_ARM_REL32_NOI, which will appear on something like
9856 ".long foo - .". We want calls to protected symbols to resolve
9857 directly to the function rather than going via the plt. If people
9858 want function pointer comparisons to work as expected then they
9859 should avoid writing assembly like ".long foo - .". */
9860 if (SYMBOL_CALLS_LOCAL (info, h))
9861 {
9862 struct elf32_arm_relocs_copied **pp;
9863
9864 for (pp = &eh->relocs_copied; (p = *pp) != NULL; )
9865 {
9866 p->count -= p->pc_count;
9867 p->pc_count = 0;
9868 if (p->count == 0)
9869 *pp = p->next;
9870 else
9871 pp = &p->next;
9872 }
9873 }
9874
9875 if (elf32_arm_hash_table (info)->vxworks_p)
9876 {
9877 struct elf32_arm_relocs_copied **pp;
9878
9879 for (pp = &eh->relocs_copied; (p = *pp) != NULL; )
9880 {
9881 if (strcmp (p->section->output_section->name, ".tls_vars") == 0)
9882 *pp = p->next;
9883 else
9884 pp = &p->next;
9885 }
9886 }
9887
9888 /* Also discard relocs on undefined weak syms with non-default
9889 visibility. */
9890 if (eh->relocs_copied != NULL
9891 && h->root.type == bfd_link_hash_undefweak)
9892 {
9893 if (ELF_ST_VISIBILITY (h->other) != STV_DEFAULT)
9894 eh->relocs_copied = NULL;
9895
9896 /* Make sure undefined weak symbols are output as a dynamic
9897 symbol in PIEs. */
9898 else if (h->dynindx == -1
9899 && !h->forced_local)
9900 {
9901 if (! bfd_elf_link_record_dynamic_symbol (info, h))
9902 return FALSE;
9903 }
9904 }
9905
9906 else if (htab->root.is_relocatable_executable && h->dynindx == -1
9907 && h->root.type == bfd_link_hash_new)
9908 {
9909 /* Output absolute symbols so that we can create relocations
9910 against them. For normal symbols we output a relocation
9911 against the section that contains them. */
9912 if (! bfd_elf_link_record_dynamic_symbol (info, h))
9913 return FALSE;
9914 }
9915
9916 }
9917 else
9918 {
9919 /* For the non-shared case, discard space for relocs against
9920 symbols which turn out to need copy relocs or are not
9921 dynamic. */
9922
9923 if (!h->non_got_ref
9924 && ((h->def_dynamic
9925 && !h->def_regular)
9926 || (htab->root.dynamic_sections_created
9927 && (h->root.type == bfd_link_hash_undefweak
9928 || h->root.type == bfd_link_hash_undefined))))
9929 {
9930 /* Make sure this symbol is output as a dynamic symbol.
9931 Undefined weak syms won't yet be marked as dynamic. */
9932 if (h->dynindx == -1
9933 && !h->forced_local)
9934 {
9935 if (! bfd_elf_link_record_dynamic_symbol (info, h))
9936 return FALSE;
9937 }
9938
9939 /* If that succeeded, we know we'll be keeping all the
9940 relocs. */
9941 if (h->dynindx != -1)
9942 goto keep;
9943 }
9944
9945 eh->relocs_copied = NULL;
9946
9947 keep: ;
9948 }
9949
9950 /* Finally, allocate space. */
9951 for (p = eh->relocs_copied; p != NULL; p = p->next)
9952 {
9953 asection *sreloc = elf_section_data (p->section)->sreloc;
9954 sreloc->size += p->count * RELOC_SIZE (htab);
9955 }
9956
9957 return TRUE;
9958 }
9959
9960 /* Find any dynamic relocs that apply to read-only sections. */
9961
9962 static bfd_boolean
9963 elf32_arm_readonly_dynrelocs (struct elf_link_hash_entry *h, PTR inf)
9964 {
9965 struct elf32_arm_link_hash_entry *eh;
9966 struct elf32_arm_relocs_copied *p;
9967
9968 if (h->root.type == bfd_link_hash_warning)
9969 h = (struct elf_link_hash_entry *) h->root.u.i.link;
9970
9971 eh = (struct elf32_arm_link_hash_entry *) h;
9972 for (p = eh->relocs_copied; p != NULL; p = p->next)
9973 {
9974 asection *s = p->section;
9975
9976 if (s != NULL && (s->flags & SEC_READONLY) != 0)
9977 {
9978 struct bfd_link_info *info = (struct bfd_link_info *) inf;
9979
9980 info->flags |= DF_TEXTREL;
9981
9982 /* Not an error, just cut short the traversal. */
9983 return FALSE;
9984 }
9985 }
9986 return TRUE;
9987 }
9988
9989 void
9990 bfd_elf32_arm_set_byteswap_code (struct bfd_link_info *info,
9991 int byteswap_code)
9992 {
9993 struct elf32_arm_link_hash_table *globals;
9994
9995 globals = elf32_arm_hash_table (info);
9996 globals->byteswap_code = byteswap_code;
9997 }
9998
9999 /* Set the sizes of the dynamic sections. */
10000
10001 static bfd_boolean
10002 elf32_arm_size_dynamic_sections (bfd * output_bfd ATTRIBUTE_UNUSED,
10003 struct bfd_link_info * info)
10004 {
10005 bfd * dynobj;
10006 asection * s;
10007 bfd_boolean plt;
10008 bfd_boolean relocs;
10009 bfd *ibfd;
10010 struct elf32_arm_link_hash_table *htab;
10011
10012 htab = elf32_arm_hash_table (info);
10013 dynobj = elf_hash_table (info)->dynobj;
10014 BFD_ASSERT (dynobj != NULL);
10015 check_use_blx (htab);
10016
10017 if (elf_hash_table (info)->dynamic_sections_created)
10018 {
10019 /* Set the contents of the .interp section to the interpreter. */
10020 if (info->executable)
10021 {
10022 s = bfd_get_section_by_name (dynobj, ".interp");
10023 BFD_ASSERT (s != NULL);
10024 s->size = sizeof ELF_DYNAMIC_INTERPRETER;
10025 s->contents = (unsigned char *) ELF_DYNAMIC_INTERPRETER;
10026 }
10027 }
10028
10029 /* Set up .got offsets for local syms, and space for local dynamic
10030 relocs. */
10031 for (ibfd = info->input_bfds; ibfd != NULL; ibfd = ibfd->link_next)
10032 {
10033 bfd_signed_vma *local_got;
10034 bfd_signed_vma *end_local_got;
10035 char *local_tls_type;
10036 bfd_size_type locsymcount;
10037 Elf_Internal_Shdr *symtab_hdr;
10038 asection *srel;
10039 bfd_boolean is_vxworks = elf32_arm_hash_table (info)->vxworks_p;
10040
10041 if (! is_arm_elf (ibfd))
10042 continue;
10043
10044 for (s = ibfd->sections; s != NULL; s = s->next)
10045 {
10046 struct elf32_arm_relocs_copied *p;
10047
10048 for (p = elf_section_data (s)->local_dynrel; p != NULL; p = p->next)
10049 {
10050 if (!bfd_is_abs_section (p->section)
10051 && bfd_is_abs_section (p->section->output_section))
10052 {
10053 /* Input section has been discarded, either because
10054 it is a copy of a linkonce section or due to
10055 linker script /DISCARD/, so we'll be discarding
10056 the relocs too. */
10057 }
10058 else if (is_vxworks
10059 && strcmp (p->section->output_section->name,
10060 ".tls_vars") == 0)
10061 {
10062 /* Relocations in vxworks .tls_vars sections are
10063 handled specially by the loader. */
10064 }
10065 else if (p->count != 0)
10066 {
10067 srel = elf_section_data (p->section)->sreloc;
10068 srel->size += p->count * RELOC_SIZE (htab);
10069 if ((p->section->output_section->flags & SEC_READONLY) != 0)
10070 info->flags |= DF_TEXTREL;
10071 }
10072 }
10073 }
10074
10075 local_got = elf_local_got_refcounts (ibfd);
10076 if (!local_got)
10077 continue;
10078
10079 symtab_hdr = & elf_symtab_hdr (ibfd);
10080 locsymcount = symtab_hdr->sh_info;
10081 end_local_got = local_got + locsymcount;
10082 local_tls_type = elf32_arm_local_got_tls_type (ibfd);
10083 s = htab->sgot;
10084 srel = htab->srelgot;
10085 for (; local_got < end_local_got; ++local_got, ++local_tls_type)
10086 {
10087 if (*local_got > 0)
10088 {
10089 *local_got = s->size;
10090 if (*local_tls_type & GOT_TLS_GD)
10091 /* TLS_GD relocs need an 8-byte structure in the GOT. */
10092 s->size += 8;
10093 if (*local_tls_type & GOT_TLS_IE)
10094 s->size += 4;
10095 if (*local_tls_type == GOT_NORMAL)
10096 s->size += 4;
10097
10098 if (info->shared || *local_tls_type == GOT_TLS_GD)
10099 srel->size += RELOC_SIZE (htab);
10100 }
10101 else
10102 *local_got = (bfd_vma) -1;
10103 }
10104 }
10105
10106 if (htab->tls_ldm_got.refcount > 0)
10107 {
10108 /* Allocate two GOT entries and one dynamic relocation (if necessary)
10109 for R_ARM_TLS_LDM32 relocations. */
10110 htab->tls_ldm_got.offset = htab->sgot->size;
10111 htab->sgot->size += 8;
10112 if (info->shared)
10113 htab->srelgot->size += RELOC_SIZE (htab);
10114 }
10115 else
10116 htab->tls_ldm_got.offset = -1;
10117
10118 /* Allocate global sym .plt and .got entries, and space for global
10119 sym dynamic relocs. */
10120 elf_link_hash_traverse (& htab->root, allocate_dynrelocs, info);
10121
10122 /* Here we rummage through the found bfds to collect glue information. */
10123 for (ibfd = info->input_bfds; ibfd != NULL; ibfd = ibfd->link_next)
10124 {
10125 if (! is_arm_elf (ibfd))
10126 continue;
10127
10128 /* Initialise mapping tables for code/data. */
10129 bfd_elf32_arm_init_maps (ibfd);
10130
10131 if (!bfd_elf32_arm_process_before_allocation (ibfd, info)
10132 || !bfd_elf32_arm_vfp11_erratum_scan (ibfd, info))
10133 /* xgettext:c-format */
10134 _bfd_error_handler (_("Errors encountered processing file %s"),
10135 ibfd->filename);
10136 }
10137
10138 /* The check_relocs and adjust_dynamic_symbol entry points have
10139 determined the sizes of the various dynamic sections. Allocate
10140 memory for them. */
10141 plt = FALSE;
10142 relocs = FALSE;
10143 for (s = dynobj->sections; s != NULL; s = s->next)
10144 {
10145 const char * name;
10146
10147 if ((s->flags & SEC_LINKER_CREATED) == 0)
10148 continue;
10149
10150 /* It's OK to base decisions on the section name, because none
10151 of the dynobj section names depend upon the input files. */
10152 name = bfd_get_section_name (dynobj, s);
10153
10154 if (strcmp (name, ".plt") == 0)
10155 {
10156 /* Remember whether there is a PLT. */
10157 plt = s->size != 0;
10158 }
10159 else if (CONST_STRNEQ (name, ".rel"))
10160 {
10161 if (s->size != 0)
10162 {
10163 /* Remember whether there are any reloc sections other
10164 than .rel(a).plt and .rela.plt.unloaded. */
10165 if (s != htab->srelplt && s != htab->srelplt2)
10166 relocs = TRUE;
10167
10168 /* We use the reloc_count field as a counter if we need
10169 to copy relocs into the output file. */
10170 s->reloc_count = 0;
10171 }
10172 }
10173 else if (! CONST_STRNEQ (name, ".got")
10174 && strcmp (name, ".dynbss") != 0)
10175 {
10176 /* It's not one of our sections, so don't allocate space. */
10177 continue;
10178 }
10179
10180 if (s->size == 0)
10181 {
10182 /* If we don't need this section, strip it from the
10183 output file. This is mostly to handle .rel(a).bss and
10184 .rel(a).plt. We must create both sections in
10185 create_dynamic_sections, because they must be created
10186 before the linker maps input sections to output
10187 sections. The linker does that before
10188 adjust_dynamic_symbol is called, and it is that
10189 function which decides whether anything needs to go
10190 into these sections. */
10191 s->flags |= SEC_EXCLUDE;
10192 continue;
10193 }
10194
10195 if ((s->flags & SEC_HAS_CONTENTS) == 0)
10196 continue;
10197
10198 /* Allocate memory for the section contents. */
10199 s->contents = bfd_zalloc (dynobj, s->size);
10200 if (s->contents == NULL)
10201 return FALSE;
10202 }
10203
10204 if (elf_hash_table (info)->dynamic_sections_created)
10205 {
10206 /* Add some entries to the .dynamic section. We fill in the
10207 values later, in elf32_arm_finish_dynamic_sections, but we
10208 must add the entries now so that we get the correct size for
10209 the .dynamic section. The DT_DEBUG entry is filled in by the
10210 dynamic linker and used by the debugger. */
10211 #define add_dynamic_entry(TAG, VAL) \
10212 _bfd_elf_add_dynamic_entry (info, TAG, VAL)
10213
10214 if (info->executable)
10215 {
10216 if (!add_dynamic_entry (DT_DEBUG, 0))
10217 return FALSE;
10218 }
10219
10220 if (plt)
10221 {
10222 if ( !add_dynamic_entry (DT_PLTGOT, 0)
10223 || !add_dynamic_entry (DT_PLTRELSZ, 0)
10224 || !add_dynamic_entry (DT_PLTREL,
10225 htab->use_rel ? DT_REL : DT_RELA)
10226 || !add_dynamic_entry (DT_JMPREL, 0))
10227 return FALSE;
10228 }
10229
10230 if (relocs)
10231 {
10232 if (htab->use_rel)
10233 {
10234 if (!add_dynamic_entry (DT_REL, 0)
10235 || !add_dynamic_entry (DT_RELSZ, 0)
10236 || !add_dynamic_entry (DT_RELENT, RELOC_SIZE (htab)))
10237 return FALSE;
10238 }
10239 else
10240 {
10241 if (!add_dynamic_entry (DT_RELA, 0)
10242 || !add_dynamic_entry (DT_RELASZ, 0)
10243 || !add_dynamic_entry (DT_RELAENT, RELOC_SIZE (htab)))
10244 return FALSE;
10245 }
10246 }
10247
10248 /* If any dynamic relocs apply to a read-only section,
10249 then we need a DT_TEXTREL entry. */
10250 if ((info->flags & DF_TEXTREL) == 0)
10251 elf_link_hash_traverse (&htab->root, elf32_arm_readonly_dynrelocs,
10252 (PTR) info);
10253
10254 if ((info->flags & DF_TEXTREL) != 0)
10255 {
10256 if (!add_dynamic_entry (DT_TEXTREL, 0))
10257 return FALSE;
10258 }
10259 if (htab->vxworks_p
10260 && !elf_vxworks_add_dynamic_entries (output_bfd, info))
10261 return FALSE;
10262 }
10263 #undef add_dynamic_entry
10264
10265 return TRUE;
10266 }
10267
10268 /* Finish up dynamic symbol handling. We set the contents of various
10269 dynamic sections here. */
10270
10271 static bfd_boolean
10272 elf32_arm_finish_dynamic_symbol (bfd * output_bfd,
10273 struct bfd_link_info * info,
10274 struct elf_link_hash_entry * h,
10275 Elf_Internal_Sym * sym)
10276 {
10277 bfd * dynobj;
10278 struct elf32_arm_link_hash_table *htab;
10279 struct elf32_arm_link_hash_entry *eh;
10280
10281 dynobj = elf_hash_table (info)->dynobj;
10282 htab = elf32_arm_hash_table (info);
10283 eh = (struct elf32_arm_link_hash_entry *) h;
10284
10285 if (h->plt.offset != (bfd_vma) -1)
10286 {
10287 asection * splt;
10288 asection * srel;
10289 bfd_byte *loc;
10290 bfd_vma plt_index;
10291 Elf_Internal_Rela rel;
10292
10293 /* This symbol has an entry in the procedure linkage table. Set
10294 it up. */
10295
10296 BFD_ASSERT (h->dynindx != -1);
10297
10298 splt = bfd_get_section_by_name (dynobj, ".plt");
10299 srel = bfd_get_section_by_name (dynobj, RELOC_SECTION (htab, ".plt"));
10300 BFD_ASSERT (splt != NULL && srel != NULL);
10301
10302 /* Fill in the entry in the procedure linkage table. */
10303 if (htab->symbian_p)
10304 {
10305 put_arm_insn (htab, output_bfd,
10306 elf32_arm_symbian_plt_entry[0],
10307 splt->contents + h->plt.offset);
10308 bfd_put_32 (output_bfd,
10309 elf32_arm_symbian_plt_entry[1],
10310 splt->contents + h->plt.offset + 4);
10311
10312 /* Fill in the entry in the .rel.plt section. */
10313 rel.r_offset = (splt->output_section->vma
10314 + splt->output_offset
10315 + h->plt.offset + 4);
10316 rel.r_info = ELF32_R_INFO (h->dynindx, R_ARM_GLOB_DAT);
10317
10318 /* Get the index in the procedure linkage table which
10319 corresponds to this symbol. This is the index of this symbol
10320 in all the symbols for which we are making plt entries. The
10321 first entry in the procedure linkage table is reserved. */
10322 plt_index = ((h->plt.offset - htab->plt_header_size)
10323 / htab->plt_entry_size);
10324 }
10325 else
10326 {
10327 bfd_vma got_offset, got_address, plt_address;
10328 bfd_vma got_displacement;
10329 asection * sgot;
10330 bfd_byte * ptr;
10331
10332 sgot = bfd_get_section_by_name (dynobj, ".got.plt");
10333 BFD_ASSERT (sgot != NULL);
10334
10335 /* Get the offset into the .got.plt table of the entry that
10336 corresponds to this function. */
10337 got_offset = eh->plt_got_offset;
10338
10339 /* Get the index in the procedure linkage table which
10340 corresponds to this symbol. This is the index of this symbol
10341 in all the symbols for which we are making plt entries. The
10342 first three entries in .got.plt are reserved; after that
10343 symbols appear in the same order as in .plt. */
10344 plt_index = (got_offset - 12) / 4;
10345
10346 /* Calculate the address of the GOT entry. */
10347 got_address = (sgot->output_section->vma
10348 + sgot->output_offset
10349 + got_offset);
10350
10351 /* ...and the address of the PLT entry. */
10352 plt_address = (splt->output_section->vma
10353 + splt->output_offset
10354 + h->plt.offset);
10355
10356 ptr = htab->splt->contents + h->plt.offset;
10357 if (htab->vxworks_p && info->shared)
10358 {
10359 unsigned int i;
10360 bfd_vma val;
10361
10362 for (i = 0; i != htab->plt_entry_size / 4; i++, ptr += 4)
10363 {
10364 val = elf32_arm_vxworks_shared_plt_entry[i];
10365 if (i == 2)
10366 val |= got_address - sgot->output_section->vma;
10367 if (i == 5)
10368 val |= plt_index * RELOC_SIZE (htab);
10369 if (i == 2 || i == 5)
10370 bfd_put_32 (output_bfd, val, ptr);
10371 else
10372 put_arm_insn (htab, output_bfd, val, ptr);
10373 }
10374 }
10375 else if (htab->vxworks_p)
10376 {
10377 unsigned int i;
10378 bfd_vma val;
10379
10380 for (i = 0; i != htab->plt_entry_size / 4; i++, ptr += 4)
10381 {
10382 val = elf32_arm_vxworks_exec_plt_entry[i];
10383 if (i == 2)
10384 val |= got_address;
10385 if (i == 4)
10386 val |= 0xffffff & -((h->plt.offset + i * 4 + 8) >> 2);
10387 if (i == 5)
10388 val |= plt_index * RELOC_SIZE (htab);
10389 if (i == 2 || i == 5)
10390 bfd_put_32 (output_bfd, val, ptr);
10391 else
10392 put_arm_insn (htab, output_bfd, val, ptr);
10393 }
10394
10395 loc = (htab->srelplt2->contents
10396 + (plt_index * 2 + 1) * RELOC_SIZE (htab));
10397
10398 /* Create the .rela.plt.unloaded R_ARM_ABS32 relocation
10399 referencing the GOT for this PLT entry. */
10400 rel.r_offset = plt_address + 8;
10401 rel.r_info = ELF32_R_INFO (htab->root.hgot->indx, R_ARM_ABS32);
10402 rel.r_addend = got_offset;
10403 SWAP_RELOC_OUT (htab) (output_bfd, &rel, loc);
10404 loc += RELOC_SIZE (htab);
10405
10406 /* Create the R_ARM_ABS32 relocation referencing the
10407 beginning of the PLT for this GOT entry. */
10408 rel.r_offset = got_address;
10409 rel.r_info = ELF32_R_INFO (htab->root.hplt->indx, R_ARM_ABS32);
10410 rel.r_addend = 0;
10411 SWAP_RELOC_OUT (htab) (output_bfd, &rel, loc);
10412 }
10413 else
10414 {
10415 bfd_signed_vma thumb_refs;
10416 /* Calculate the displacement between the PLT slot and the
10417 entry in the GOT. The eight-byte offset accounts for the
10418 value produced by adding to pc in the first instruction
10419 of the PLT stub. */
10420 got_displacement = got_address - (plt_address + 8);
10421
10422 BFD_ASSERT ((got_displacement & 0xf0000000) == 0);
10423
10424 thumb_refs = eh->plt_thumb_refcount;
10425 if (!htab->use_blx)
10426 thumb_refs += eh->plt_maybe_thumb_refcount;
10427
10428 if (thumb_refs > 0)
10429 {
10430 put_thumb_insn (htab, output_bfd,
10431 elf32_arm_plt_thumb_stub[0], ptr - 4);
10432 put_thumb_insn (htab, output_bfd,
10433 elf32_arm_plt_thumb_stub[1], ptr - 2);
10434 }
10435
10436 put_arm_insn (htab, output_bfd,
10437 elf32_arm_plt_entry[0]
10438 | ((got_displacement & 0x0ff00000) >> 20),
10439 ptr + 0);
10440 put_arm_insn (htab, output_bfd,
10441 elf32_arm_plt_entry[1]
10442 | ((got_displacement & 0x000ff000) >> 12),
10443 ptr+ 4);
10444 put_arm_insn (htab, output_bfd,
10445 elf32_arm_plt_entry[2]
10446 | (got_displacement & 0x00000fff),
10447 ptr + 8);
10448 #ifdef FOUR_WORD_PLT
10449 bfd_put_32 (output_bfd, elf32_arm_plt_entry[3], ptr + 12);
10450 #endif
10451 }
10452
10453 /* Fill in the entry in the global offset table. */
10454 bfd_put_32 (output_bfd,
10455 (splt->output_section->vma
10456 + splt->output_offset),
10457 sgot->contents + got_offset);
10458
10459 /* Fill in the entry in the .rel(a).plt section. */
10460 rel.r_addend = 0;
10461 rel.r_offset = got_address;
10462 rel.r_info = ELF32_R_INFO (h->dynindx, R_ARM_JUMP_SLOT);
10463 }
10464
10465 loc = srel->contents + plt_index * RELOC_SIZE (htab);
10466 SWAP_RELOC_OUT (htab) (output_bfd, &rel, loc);
10467
10468 if (!h->def_regular)
10469 {
10470 /* Mark the symbol as undefined, rather than as defined in
10471 the .plt section. Leave the value alone. */
10472 sym->st_shndx = SHN_UNDEF;
10473 /* If the symbol is weak, we do need to clear the value.
10474 Otherwise, the PLT entry would provide a definition for
10475 the symbol even if the symbol wasn't defined anywhere,
10476 and so the symbol would never be NULL. */
10477 if (!h->ref_regular_nonweak)
10478 sym->st_value = 0;
10479 }
10480 }
10481
10482 if (h->got.offset != (bfd_vma) -1
10483 && (elf32_arm_hash_entry (h)->tls_type & GOT_TLS_GD) == 0
10484 && (elf32_arm_hash_entry (h)->tls_type & GOT_TLS_IE) == 0)
10485 {
10486 asection * sgot;
10487 asection * srel;
10488 Elf_Internal_Rela rel;
10489 bfd_byte *loc;
10490 bfd_vma offset;
10491
10492 /* This symbol has an entry in the global offset table. Set it
10493 up. */
10494 sgot = bfd_get_section_by_name (dynobj, ".got");
10495 srel = bfd_get_section_by_name (dynobj, RELOC_SECTION (htab, ".got"));
10496 BFD_ASSERT (sgot != NULL && srel != NULL);
10497
10498 offset = (h->got.offset & ~(bfd_vma) 1);
10499 rel.r_addend = 0;
10500 rel.r_offset = (sgot->output_section->vma
10501 + sgot->output_offset
10502 + offset);
10503
10504 /* If this is a static link, or it is a -Bsymbolic link and the
10505 symbol is defined locally or was forced to be local because
10506 of a version file, we just want to emit a RELATIVE reloc.
10507 The entry in the global offset table will already have been
10508 initialized in the relocate_section function. */
10509 if (info->shared
10510 && SYMBOL_REFERENCES_LOCAL (info, h))
10511 {
10512 BFD_ASSERT ((h->got.offset & 1) != 0);
10513 rel.r_info = ELF32_R_INFO (0, R_ARM_RELATIVE);
10514 if (!htab->use_rel)
10515 {
10516 rel.r_addend = bfd_get_32 (output_bfd, sgot->contents + offset);
10517 bfd_put_32 (output_bfd, (bfd_vma) 0, sgot->contents + offset);
10518 }
10519 }
10520 else
10521 {
10522 BFD_ASSERT ((h->got.offset & 1) == 0);
10523 bfd_put_32 (output_bfd, (bfd_vma) 0, sgot->contents + offset);
10524 rel.r_info = ELF32_R_INFO (h->dynindx, R_ARM_GLOB_DAT);
10525 }
10526
10527 loc = srel->contents + srel->reloc_count++ * RELOC_SIZE (htab);
10528 SWAP_RELOC_OUT (htab) (output_bfd, &rel, loc);
10529 }
10530
10531 if (h->needs_copy)
10532 {
10533 asection * s;
10534 Elf_Internal_Rela rel;
10535 bfd_byte *loc;
10536
10537 /* This symbol needs a copy reloc. Set it up. */
10538 BFD_ASSERT (h->dynindx != -1
10539 && (h->root.type == bfd_link_hash_defined
10540 || h->root.type == bfd_link_hash_defweak));
10541
10542 s = bfd_get_section_by_name (h->root.u.def.section->owner,
10543 RELOC_SECTION (htab, ".bss"));
10544 BFD_ASSERT (s != NULL);
10545
10546 rel.r_addend = 0;
10547 rel.r_offset = (h->root.u.def.value
10548 + h->root.u.def.section->output_section->vma
10549 + h->root.u.def.section->output_offset);
10550 rel.r_info = ELF32_R_INFO (h->dynindx, R_ARM_COPY);
10551 loc = s->contents + s->reloc_count++ * RELOC_SIZE (htab);
10552 SWAP_RELOC_OUT (htab) (output_bfd, &rel, loc);
10553 }
10554
10555 /* Mark _DYNAMIC and _GLOBAL_OFFSET_TABLE_ as absolute. On VxWorks,
10556 the _GLOBAL_OFFSET_TABLE_ symbol is not absolute: it is relative
10557 to the ".got" section. */
10558 if (strcmp (h->root.root.string, "_DYNAMIC") == 0
10559 || (!htab->vxworks_p && h == htab->root.hgot))
10560 sym->st_shndx = SHN_ABS;
10561
10562 return TRUE;
10563 }
10564
10565 /* Finish up the dynamic sections. */
10566
10567 static bfd_boolean
10568 elf32_arm_finish_dynamic_sections (bfd * output_bfd, struct bfd_link_info * info)
10569 {
10570 bfd * dynobj;
10571 asection * sgot;
10572 asection * sdyn;
10573
10574 dynobj = elf_hash_table (info)->dynobj;
10575
10576 sgot = bfd_get_section_by_name (dynobj, ".got.plt");
10577 BFD_ASSERT (elf32_arm_hash_table (info)->symbian_p || sgot != NULL);
10578 sdyn = bfd_get_section_by_name (dynobj, ".dynamic");
10579
10580 if (elf_hash_table (info)->dynamic_sections_created)
10581 {
10582 asection *splt;
10583 Elf32_External_Dyn *dyncon, *dynconend;
10584 struct elf32_arm_link_hash_table *htab;
10585
10586 htab = elf32_arm_hash_table (info);
10587 splt = bfd_get_section_by_name (dynobj, ".plt");
10588 BFD_ASSERT (splt != NULL && sdyn != NULL);
10589
10590 dyncon = (Elf32_External_Dyn *) sdyn->contents;
10591 dynconend = (Elf32_External_Dyn *) (sdyn->contents + sdyn->size);
10592
10593 for (; dyncon < dynconend; dyncon++)
10594 {
10595 Elf_Internal_Dyn dyn;
10596 const char * name;
10597 asection * s;
10598
10599 bfd_elf32_swap_dyn_in (dynobj, dyncon, &dyn);
10600
10601 switch (dyn.d_tag)
10602 {
10603 unsigned int type;
10604
10605 default:
10606 if (htab->vxworks_p
10607 && elf_vxworks_finish_dynamic_entry (output_bfd, &dyn))
10608 bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon);
10609 break;
10610
10611 case DT_HASH:
10612 name = ".hash";
10613 goto get_vma_if_bpabi;
10614 case DT_STRTAB:
10615 name = ".dynstr";
10616 goto get_vma_if_bpabi;
10617 case DT_SYMTAB:
10618 name = ".dynsym";
10619 goto get_vma_if_bpabi;
10620 case DT_VERSYM:
10621 name = ".gnu.version";
10622 goto get_vma_if_bpabi;
10623 case DT_VERDEF:
10624 name = ".gnu.version_d";
10625 goto get_vma_if_bpabi;
10626 case DT_VERNEED:
10627 name = ".gnu.version_r";
10628 goto get_vma_if_bpabi;
10629
10630 case DT_PLTGOT:
10631 name = ".got";
10632 goto get_vma;
10633 case DT_JMPREL:
10634 name = RELOC_SECTION (htab, ".plt");
10635 get_vma:
10636 s = bfd_get_section_by_name (output_bfd, name);
10637 BFD_ASSERT (s != NULL);
10638 if (!htab->symbian_p)
10639 dyn.d_un.d_ptr = s->vma;
10640 else
10641 /* In the BPABI, tags in the PT_DYNAMIC section point
10642 at the file offset, not the memory address, for the
10643 convenience of the post linker. */
10644 dyn.d_un.d_ptr = s->filepos;
10645 bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon);
10646 break;
10647
10648 get_vma_if_bpabi:
10649 if (htab->symbian_p)
10650 goto get_vma;
10651 break;
10652
10653 case DT_PLTRELSZ:
10654 s = bfd_get_section_by_name (output_bfd,
10655 RELOC_SECTION (htab, ".plt"));
10656 BFD_ASSERT (s != NULL);
10657 dyn.d_un.d_val = s->size;
10658 bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon);
10659 break;
10660
10661 case DT_RELSZ:
10662 case DT_RELASZ:
10663 if (!htab->symbian_p)
10664 {
10665 /* My reading of the SVR4 ABI indicates that the
10666 procedure linkage table relocs (DT_JMPREL) should be
10667 included in the overall relocs (DT_REL). This is
10668 what Solaris does. However, UnixWare can not handle
10669 that case. Therefore, we override the DT_RELSZ entry
10670 here to make it not include the JMPREL relocs. Since
10671 the linker script arranges for .rel(a).plt to follow all
10672 other relocation sections, we don't have to worry
10673 about changing the DT_REL entry. */
10674 s = bfd_get_section_by_name (output_bfd,
10675 RELOC_SECTION (htab, ".plt"));
10676 if (s != NULL)
10677 dyn.d_un.d_val -= s->size;
10678 bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon);
10679 break;
10680 }
10681 /* Fall through */
10682
10683 case DT_REL:
10684 case DT_RELA:
10685 /* In the BPABI, the DT_REL tag must point at the file
10686 offset, not the VMA, of the first relocation
10687 section. So, we use code similar to that in
10688 elflink.c, but do not check for SHF_ALLOC on the
10689 relcoation section, since relocations sections are
10690 never allocated under the BPABI. The comments above
10691 about Unixware notwithstanding, we include all of the
10692 relocations here. */
10693 if (htab->symbian_p)
10694 {
10695 unsigned int i;
10696 type = ((dyn.d_tag == DT_REL || dyn.d_tag == DT_RELSZ)
10697 ? SHT_REL : SHT_RELA);
10698 dyn.d_un.d_val = 0;
10699 for (i = 1; i < elf_numsections (output_bfd); i++)
10700 {
10701 Elf_Internal_Shdr *hdr
10702 = elf_elfsections (output_bfd)[i];
10703 if (hdr->sh_type == type)
10704 {
10705 if (dyn.d_tag == DT_RELSZ
10706 || dyn.d_tag == DT_RELASZ)
10707 dyn.d_un.d_val += hdr->sh_size;
10708 else if ((ufile_ptr) hdr->sh_offset
10709 <= dyn.d_un.d_val - 1)
10710 dyn.d_un.d_val = hdr->sh_offset;
10711 }
10712 }
10713 bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon);
10714 }
10715 break;
10716
10717 /* Set the bottom bit of DT_INIT/FINI if the
10718 corresponding function is Thumb. */
10719 case DT_INIT:
10720 name = info->init_function;
10721 goto get_sym;
10722 case DT_FINI:
10723 name = info->fini_function;
10724 get_sym:
10725 /* If it wasn't set by elf_bfd_final_link
10726 then there is nothing to adjust. */
10727 if (dyn.d_un.d_val != 0)
10728 {
10729 struct elf_link_hash_entry * eh;
10730
10731 eh = elf_link_hash_lookup (elf_hash_table (info), name,
10732 FALSE, FALSE, TRUE);
10733 if (eh != NULL
10734 && ELF_ST_TYPE (eh->type) == STT_ARM_TFUNC)
10735 {
10736 dyn.d_un.d_val |= 1;
10737 bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon);
10738 }
10739 }
10740 break;
10741 }
10742 }
10743
10744 /* Fill in the first entry in the procedure linkage table. */
10745 if (splt->size > 0 && elf32_arm_hash_table (info)->plt_header_size)
10746 {
10747 const bfd_vma *plt0_entry;
10748 bfd_vma got_address, plt_address, got_displacement;
10749
10750 /* Calculate the addresses of the GOT and PLT. */
10751 got_address = sgot->output_section->vma + sgot->output_offset;
10752 plt_address = splt->output_section->vma + splt->output_offset;
10753
10754 if (htab->vxworks_p)
10755 {
10756 /* The VxWorks GOT is relocated by the dynamic linker.
10757 Therefore, we must emit relocations rather than simply
10758 computing the values now. */
10759 Elf_Internal_Rela rel;
10760
10761 plt0_entry = elf32_arm_vxworks_exec_plt0_entry;
10762 put_arm_insn (htab, output_bfd, plt0_entry[0],
10763 splt->contents + 0);
10764 put_arm_insn (htab, output_bfd, plt0_entry[1],
10765 splt->contents + 4);
10766 put_arm_insn (htab, output_bfd, plt0_entry[2],
10767 splt->contents + 8);
10768 bfd_put_32 (output_bfd, got_address, splt->contents + 12);
10769
10770 /* Generate a relocation for _GLOBAL_OFFSET_TABLE_. */
10771 rel.r_offset = plt_address + 12;
10772 rel.r_info = ELF32_R_INFO (htab->root.hgot->indx, R_ARM_ABS32);
10773 rel.r_addend = 0;
10774 SWAP_RELOC_OUT (htab) (output_bfd, &rel,
10775 htab->srelplt2->contents);
10776 }
10777 else
10778 {
10779 got_displacement = got_address - (plt_address + 16);
10780
10781 plt0_entry = elf32_arm_plt0_entry;
10782 put_arm_insn (htab, output_bfd, plt0_entry[0],
10783 splt->contents + 0);
10784 put_arm_insn (htab, output_bfd, plt0_entry[1],
10785 splt->contents + 4);
10786 put_arm_insn (htab, output_bfd, plt0_entry[2],
10787 splt->contents + 8);
10788 put_arm_insn (htab, output_bfd, plt0_entry[3],
10789 splt->contents + 12);
10790
10791 #ifdef FOUR_WORD_PLT
10792 /* The displacement value goes in the otherwise-unused
10793 last word of the second entry. */
10794 bfd_put_32 (output_bfd, got_displacement, splt->contents + 28);
10795 #else
10796 bfd_put_32 (output_bfd, got_displacement, splt->contents + 16);
10797 #endif
10798 }
10799 }
10800
10801 /* UnixWare sets the entsize of .plt to 4, although that doesn't
10802 really seem like the right value. */
10803 if (splt->output_section->owner == output_bfd)
10804 elf_section_data (splt->output_section)->this_hdr.sh_entsize = 4;
10805
10806 if (htab->vxworks_p && !info->shared && htab->splt->size > 0)
10807 {
10808 /* Correct the .rel(a).plt.unloaded relocations. They will have
10809 incorrect symbol indexes. */
10810 int num_plts;
10811 unsigned char *p;
10812
10813 num_plts = ((htab->splt->size - htab->plt_header_size)
10814 / htab->plt_entry_size);
10815 p = htab->srelplt2->contents + RELOC_SIZE (htab);
10816
10817 for (; num_plts; num_plts--)
10818 {
10819 Elf_Internal_Rela rel;
10820
10821 SWAP_RELOC_IN (htab) (output_bfd, p, &rel);
10822 rel.r_info = ELF32_R_INFO (htab->root.hgot->indx, R_ARM_ABS32);
10823 SWAP_RELOC_OUT (htab) (output_bfd, &rel, p);
10824 p += RELOC_SIZE (htab);
10825
10826 SWAP_RELOC_IN (htab) (output_bfd, p, &rel);
10827 rel.r_info = ELF32_R_INFO (htab->root.hplt->indx, R_ARM_ABS32);
10828 SWAP_RELOC_OUT (htab) (output_bfd, &rel, p);
10829 p += RELOC_SIZE (htab);
10830 }
10831 }
10832 }
10833
10834 /* Fill in the first three entries in the global offset table. */
10835 if (sgot)
10836 {
10837 if (sgot->size > 0)
10838 {
10839 if (sdyn == NULL)
10840 bfd_put_32 (output_bfd, (bfd_vma) 0, sgot->contents);
10841 else
10842 bfd_put_32 (output_bfd,
10843 sdyn->output_section->vma + sdyn->output_offset,
10844 sgot->contents);
10845 bfd_put_32 (output_bfd, (bfd_vma) 0, sgot->contents + 4);
10846 bfd_put_32 (output_bfd, (bfd_vma) 0, sgot->contents + 8);
10847 }
10848
10849 elf_section_data (sgot->output_section)->this_hdr.sh_entsize = 4;
10850 }
10851
10852 return TRUE;
10853 }
10854
10855 static void
10856 elf32_arm_post_process_headers (bfd * abfd, struct bfd_link_info * link_info ATTRIBUTE_UNUSED)
10857 {
10858 Elf_Internal_Ehdr * i_ehdrp; /* ELF file header, internal form. */
10859 struct elf32_arm_link_hash_table *globals;
10860
10861 i_ehdrp = elf_elfheader (abfd);
10862
10863 if (EF_ARM_EABI_VERSION (i_ehdrp->e_flags) == EF_ARM_EABI_UNKNOWN)
10864 i_ehdrp->e_ident[EI_OSABI] = ELFOSABI_ARM;
10865 else
10866 i_ehdrp->e_ident[EI_OSABI] = 0;
10867 i_ehdrp->e_ident[EI_ABIVERSION] = ARM_ELF_ABI_VERSION;
10868
10869 if (link_info)
10870 {
10871 globals = elf32_arm_hash_table (link_info);
10872 if (globals->byteswap_code)
10873 i_ehdrp->e_flags |= EF_ARM_BE8;
10874 }
10875 }
10876
10877 static enum elf_reloc_type_class
10878 elf32_arm_reloc_type_class (const Elf_Internal_Rela *rela)
10879 {
10880 switch ((int) ELF32_R_TYPE (rela->r_info))
10881 {
10882 case R_ARM_RELATIVE:
10883 return reloc_class_relative;
10884 case R_ARM_JUMP_SLOT:
10885 return reloc_class_plt;
10886 case R_ARM_COPY:
10887 return reloc_class_copy;
10888 default:
10889 return reloc_class_normal;
10890 }
10891 }
10892
10893 /* Set the right machine number for an Arm ELF file. */
10894
10895 static bfd_boolean
10896 elf32_arm_section_flags (flagword *flags, const Elf_Internal_Shdr *hdr)
10897 {
10898 if (hdr->sh_type == SHT_NOTE)
10899 *flags |= SEC_LINK_ONCE | SEC_LINK_DUPLICATES_SAME_CONTENTS;
10900
10901 return TRUE;
10902 }
10903
10904 static void
10905 elf32_arm_final_write_processing (bfd *abfd, bfd_boolean linker ATTRIBUTE_UNUSED)
10906 {
10907 bfd_arm_update_notes (abfd, ARM_NOTE_SECTION);
10908 }
10909
10910 /* Return TRUE if this is an unwinding table entry. */
10911
10912 static bfd_boolean
10913 is_arm_elf_unwind_section_name (bfd * abfd ATTRIBUTE_UNUSED, const char * name)
10914 {
10915 return (CONST_STRNEQ (name, ELF_STRING_ARM_unwind)
10916 || CONST_STRNEQ (name, ELF_STRING_ARM_unwind_once));
10917 }
10918
10919
10920 /* Set the type and flags for an ARM section. We do this by
10921 the section name, which is a hack, but ought to work. */
10922
10923 static bfd_boolean
10924 elf32_arm_fake_sections (bfd * abfd, Elf_Internal_Shdr * hdr, asection * sec)
10925 {
10926 const char * name;
10927
10928 name = bfd_get_section_name (abfd, sec);
10929
10930 if (is_arm_elf_unwind_section_name (abfd, name))
10931 {
10932 hdr->sh_type = SHT_ARM_EXIDX;
10933 hdr->sh_flags |= SHF_LINK_ORDER;
10934 }
10935 return TRUE;
10936 }
10937
10938 /* Handle an ARM specific section when reading an object file. This is
10939 called when bfd_section_from_shdr finds a section with an unknown
10940 type. */
10941
10942 static bfd_boolean
10943 elf32_arm_section_from_shdr (bfd *abfd,
10944 Elf_Internal_Shdr * hdr,
10945 const char *name,
10946 int shindex)
10947 {
10948 /* There ought to be a place to keep ELF backend specific flags, but
10949 at the moment there isn't one. We just keep track of the
10950 sections by their name, instead. Fortunately, the ABI gives
10951 names for all the ARM specific sections, so we will probably get
10952 away with this. */
10953 switch (hdr->sh_type)
10954 {
10955 case SHT_ARM_EXIDX:
10956 case SHT_ARM_PREEMPTMAP:
10957 case SHT_ARM_ATTRIBUTES:
10958 break;
10959
10960 default:
10961 return FALSE;
10962 }
10963
10964 if (! _bfd_elf_make_section_from_shdr (abfd, hdr, name, shindex))
10965 return FALSE;
10966
10967 return TRUE;
10968 }
10969
10970 /* A structure used to record a list of sections, independently
10971 of the next and prev fields in the asection structure. */
10972 typedef struct section_list
10973 {
10974 asection * sec;
10975 struct section_list * next;
10976 struct section_list * prev;
10977 }
10978 section_list;
10979
10980 /* Unfortunately we need to keep a list of sections for which
10981 an _arm_elf_section_data structure has been allocated. This
10982 is because it is possible for functions like elf32_arm_write_section
10983 to be called on a section which has had an elf_data_structure
10984 allocated for it (and so the used_by_bfd field is valid) but
10985 for which the ARM extended version of this structure - the
10986 _arm_elf_section_data structure - has not been allocated. */
10987 static section_list * sections_with_arm_elf_section_data = NULL;
10988
10989 static void
10990 record_section_with_arm_elf_section_data (asection * sec)
10991 {
10992 struct section_list * entry;
10993
10994 entry = bfd_malloc (sizeof (* entry));
10995 if (entry == NULL)
10996 return;
10997 entry->sec = sec;
10998 entry->next = sections_with_arm_elf_section_data;
10999 entry->prev = NULL;
11000 if (entry->next != NULL)
11001 entry->next->prev = entry;
11002 sections_with_arm_elf_section_data = entry;
11003 }
11004
11005 static struct section_list *
11006 find_arm_elf_section_entry (asection * sec)
11007 {
11008 struct section_list * entry;
11009 static struct section_list * last_entry = NULL;
11010
11011 /* This is a short cut for the typical case where the sections are added
11012 to the sections_with_arm_elf_section_data list in forward order and
11013 then looked up here in backwards order. This makes a real difference
11014 to the ld-srec/sec64k.exp linker test. */
11015 entry = sections_with_arm_elf_section_data;
11016 if (last_entry != NULL)
11017 {
11018 if (last_entry->sec == sec)
11019 entry = last_entry;
11020 else if (last_entry->next != NULL
11021 && last_entry->next->sec == sec)
11022 entry = last_entry->next;
11023 }
11024
11025 for (; entry; entry = entry->next)
11026 if (entry->sec == sec)
11027 break;
11028
11029 if (entry)
11030 /* Record the entry prior to this one - it is the entry we are most
11031 likely to want to locate next time. Also this way if we have been
11032 called from unrecord_section_with_arm_elf_section_data() we will not
11033 be caching a pointer that is about to be freed. */
11034 last_entry = entry->prev;
11035
11036 return entry;
11037 }
11038
11039 static _arm_elf_section_data *
11040 get_arm_elf_section_data (asection * sec)
11041 {
11042 struct section_list * entry;
11043
11044 entry = find_arm_elf_section_entry (sec);
11045
11046 if (entry)
11047 return elf32_arm_section_data (entry->sec);
11048 else
11049 return NULL;
11050 }
11051
11052 static void
11053 unrecord_section_with_arm_elf_section_data (asection * sec)
11054 {
11055 struct section_list * entry;
11056
11057 entry = find_arm_elf_section_entry (sec);
11058
11059 if (entry)
11060 {
11061 if (entry->prev != NULL)
11062 entry->prev->next = entry->next;
11063 if (entry->next != NULL)
11064 entry->next->prev = entry->prev;
11065 if (entry == sections_with_arm_elf_section_data)
11066 sections_with_arm_elf_section_data = entry->next;
11067 free (entry);
11068 }
11069 }
11070
11071
11072 typedef struct
11073 {
11074 void *finfo;
11075 struct bfd_link_info *info;
11076 asection *sec;
11077 int sec_shndx;
11078 bfd_boolean (*func) (void *, const char *, Elf_Internal_Sym *,
11079 asection *, struct elf_link_hash_entry *);
11080 } output_arch_syminfo;
11081
11082 enum map_symbol_type
11083 {
11084 ARM_MAP_ARM,
11085 ARM_MAP_THUMB,
11086 ARM_MAP_DATA
11087 };
11088
11089
11090 /* Output a single mapping symbol. */
11091
11092 static bfd_boolean
11093 elf32_arm_output_map_sym (output_arch_syminfo *osi,
11094 enum map_symbol_type type,
11095 bfd_vma offset)
11096 {
11097 static const char *names[3] = {"$a", "$t", "$d"};
11098 struct elf32_arm_link_hash_table *htab;
11099 Elf_Internal_Sym sym;
11100
11101 htab = elf32_arm_hash_table (osi->info);
11102 sym.st_value = osi->sec->output_section->vma
11103 + osi->sec->output_offset
11104 + offset;
11105 sym.st_size = 0;
11106 sym.st_other = 0;
11107 sym.st_info = ELF_ST_INFO (STB_LOCAL, STT_NOTYPE);
11108 sym.st_shndx = osi->sec_shndx;
11109 if (!osi->func (osi->finfo, names[type], &sym, osi->sec, NULL))
11110 return FALSE;
11111 return TRUE;
11112 }
11113
11114
11115 /* Output mapping symbols for PLT entries associated with H. */
11116
11117 static bfd_boolean
11118 elf32_arm_output_plt_map (struct elf_link_hash_entry *h, void *inf)
11119 {
11120 output_arch_syminfo *osi = (output_arch_syminfo *) inf;
11121 struct elf32_arm_link_hash_table *htab;
11122 struct elf32_arm_link_hash_entry *eh;
11123 bfd_vma addr;
11124
11125 htab = elf32_arm_hash_table (osi->info);
11126
11127 if (h->root.type == bfd_link_hash_indirect)
11128 return TRUE;
11129
11130 if (h->root.type == bfd_link_hash_warning)
11131 /* When warning symbols are created, they **replace** the "real"
11132 entry in the hash table, thus we never get to see the real
11133 symbol in a hash traversal. So look at it now. */
11134 h = (struct elf_link_hash_entry *) h->root.u.i.link;
11135
11136 if (h->plt.offset == (bfd_vma) -1)
11137 return TRUE;
11138
11139 eh = (struct elf32_arm_link_hash_entry *) h;
11140 addr = h->plt.offset;
11141 if (htab->symbian_p)
11142 {
11143 if (!elf32_arm_output_map_sym (osi, ARM_MAP_ARM, addr))
11144 return FALSE;
11145 if (!elf32_arm_output_map_sym (osi, ARM_MAP_DATA, addr + 4))
11146 return FALSE;
11147 }
11148 else if (htab->vxworks_p)
11149 {
11150 if (!elf32_arm_output_map_sym (osi, ARM_MAP_ARM, addr))
11151 return FALSE;
11152 if (!elf32_arm_output_map_sym (osi, ARM_MAP_DATA, addr + 8))
11153 return FALSE;
11154 if (!elf32_arm_output_map_sym (osi, ARM_MAP_ARM, addr + 12))
11155 return FALSE;
11156 if (!elf32_arm_output_map_sym (osi, ARM_MAP_DATA, addr + 20))
11157 return FALSE;
11158 }
11159 else
11160 {
11161 bfd_signed_vma thumb_refs;
11162
11163 thumb_refs = eh->plt_thumb_refcount;
11164 if (!htab->use_blx)
11165 thumb_refs += eh->plt_maybe_thumb_refcount;
11166
11167 if (thumb_refs > 0)
11168 {
11169 if (!elf32_arm_output_map_sym (osi, ARM_MAP_THUMB, addr - 4))
11170 return FALSE;
11171 }
11172 #ifdef FOUR_WORD_PLT
11173 if (!elf32_arm_output_map_sym (osi, ARM_MAP_ARM, addr))
11174 return FALSE;
11175 if (!elf32_arm_output_map_sym (osi, ARM_MAP_DATA, addr + 12))
11176 return FALSE;
11177 #else
11178 /* A three-word PLT with no Thumb thunk contains only Arm code,
11179 so only need to output a mapping symbol for the first PLT entry and
11180 entries with thumb thunks. */
11181 if (thumb_refs > 0 || addr == 20)
11182 {
11183 if (!elf32_arm_output_map_sym (osi, ARM_MAP_ARM, addr))
11184 return FALSE;
11185 }
11186 #endif
11187 }
11188
11189 return TRUE;
11190 }
11191
11192 /* Output a single local symbol for a generated stub. */
11193
11194 static bfd_boolean
11195 elf32_arm_output_stub_sym (output_arch_syminfo *osi, const char *name,
11196 bfd_vma offset, bfd_vma size)
11197 {
11198 struct elf32_arm_link_hash_table *htab;
11199 Elf_Internal_Sym sym;
11200
11201 htab = elf32_arm_hash_table (osi->info);
11202 sym.st_value = osi->sec->output_section->vma
11203 + osi->sec->output_offset
11204 + offset;
11205 sym.st_size = size;
11206 sym.st_other = 0;
11207 sym.st_info = ELF_ST_INFO (STB_LOCAL, STT_FUNC);
11208 sym.st_shndx = osi->sec_shndx;
11209 if (!osi->func (osi->finfo, name, &sym, osi->sec, NULL))
11210 return FALSE;
11211 return TRUE;
11212 }
11213
11214 static bfd_boolean
11215 arm_map_one_stub (struct bfd_hash_entry *gen_entry,
11216 PTR in_arg)
11217 {
11218 struct elf32_arm_stub_hash_entry *stub_entry;
11219 struct bfd_link_info *info;
11220 struct elf32_arm_link_hash_table *htab;
11221 asection *stub_sec;
11222 bfd_vma addr;
11223 char *stub_name;
11224 output_arch_syminfo *osi;
11225
11226 /* Massage our args to the form they really have. */
11227 stub_entry = (struct elf32_arm_stub_hash_entry *) gen_entry;
11228 osi = (output_arch_syminfo *) in_arg;
11229
11230 info = osi->info;
11231
11232 htab = elf32_arm_hash_table (info);
11233 stub_sec = stub_entry->stub_sec;
11234
11235 /* Ensure this stub is attached to the current section being
11236 processed. */
11237 if (stub_sec != osi->sec)
11238 return TRUE;
11239
11240 addr = (bfd_vma) stub_entry->stub_offset;
11241 stub_name = stub_entry->output_name;
11242
11243 switch (stub_entry->stub_type)
11244 {
11245 case arm_stub_long_branch:
11246 if (!elf32_arm_output_stub_sym (osi, stub_name, addr, 8))
11247 return FALSE;
11248 if (!elf32_arm_output_map_sym (osi, ARM_MAP_ARM, addr))
11249 return FALSE;
11250 if (!elf32_arm_output_map_sym (osi, ARM_MAP_DATA, addr + 4))
11251 return FALSE;
11252 break;
11253 case arm_thumb_v4t_stub_long_branch:
11254 if (!elf32_arm_output_stub_sym (osi, stub_name, addr, 12))
11255 return FALSE;
11256 if (!elf32_arm_output_map_sym (osi, ARM_MAP_ARM, addr))
11257 return FALSE;
11258 if (!elf32_arm_output_map_sym (osi, ARM_MAP_DATA, addr + 8))
11259 return FALSE;
11260 break;
11261 case arm_thumb_thumb_stub_long_branch:
11262 if (!elf32_arm_output_stub_sym (osi, stub_name, addr | 1, 16))
11263 return FALSE;
11264 if (!elf32_arm_output_map_sym (osi, ARM_MAP_THUMB, addr))
11265 return FALSE;
11266 if (!elf32_arm_output_map_sym (osi, ARM_MAP_DATA, addr + 12))
11267 return FALSE;
11268 break;
11269 case arm_thumb_arm_v4t_stub_long_branch:
11270 if (!elf32_arm_output_stub_sym (osi, stub_name, addr | 1, 20))
11271 return FALSE;
11272 if (!elf32_arm_output_map_sym (osi, ARM_MAP_THUMB, addr))
11273 return FALSE;
11274 if (!elf32_arm_output_map_sym (osi, ARM_MAP_ARM, addr + 8))
11275 return FALSE;
11276 if (!elf32_arm_output_map_sym (osi, ARM_MAP_DATA, addr + 16))
11277 return FALSE;
11278 break;
11279 case arm_stub_pic_long_branch:
11280 if (!elf32_arm_output_stub_sym (osi, stub_name, addr, 12))
11281 return FALSE;
11282 if (!elf32_arm_output_map_sym (osi, ARM_MAP_ARM, addr))
11283 return FALSE;
11284 if (!elf32_arm_output_map_sym (osi, ARM_MAP_DATA, addr + 8))
11285 return FALSE;
11286 break;
11287 default:
11288 BFD_FAIL ();
11289 }
11290
11291 return TRUE;
11292 }
11293
11294 /* Output mapping symbols for linker generated sections. */
11295
11296 static bfd_boolean
11297 elf32_arm_output_arch_local_syms (bfd *output_bfd,
11298 struct bfd_link_info *info,
11299 void *finfo,
11300 bfd_boolean (*func) (void *, const char *,
11301 Elf_Internal_Sym *,
11302 asection *,
11303 struct elf_link_hash_entry *))
11304 {
11305 output_arch_syminfo osi;
11306 struct elf32_arm_link_hash_table *htab;
11307 bfd_vma offset;
11308 bfd_size_type size;
11309
11310 htab = elf32_arm_hash_table (info);
11311 check_use_blx (htab);
11312
11313 osi.finfo = finfo;
11314 osi.info = info;
11315 osi.func = func;
11316
11317 /* ARM->Thumb glue. */
11318 if (htab->arm_glue_size > 0)
11319 {
11320 osi.sec = bfd_get_section_by_name (htab->bfd_of_glue_owner,
11321 ARM2THUMB_GLUE_SECTION_NAME);
11322
11323 osi.sec_shndx = _bfd_elf_section_from_bfd_section
11324 (output_bfd, osi.sec->output_section);
11325 if (info->shared || htab->root.is_relocatable_executable
11326 || htab->pic_veneer)
11327 size = ARM2THUMB_PIC_GLUE_SIZE;
11328 else if (htab->use_blx)
11329 size = ARM2THUMB_V5_STATIC_GLUE_SIZE;
11330 else
11331 size = ARM2THUMB_STATIC_GLUE_SIZE;
11332
11333 for (offset = 0; offset < htab->arm_glue_size; offset += size)
11334 {
11335 elf32_arm_output_map_sym (&osi, ARM_MAP_ARM, offset);
11336 elf32_arm_output_map_sym (&osi, ARM_MAP_DATA, offset + size - 4);
11337 }
11338 }
11339
11340 /* Thumb->ARM glue. */
11341 if (htab->thumb_glue_size > 0)
11342 {
11343 osi.sec = bfd_get_section_by_name (htab->bfd_of_glue_owner,
11344 THUMB2ARM_GLUE_SECTION_NAME);
11345
11346 osi.sec_shndx = _bfd_elf_section_from_bfd_section
11347 (output_bfd, osi.sec->output_section);
11348 size = THUMB2ARM_GLUE_SIZE;
11349
11350 for (offset = 0; offset < htab->thumb_glue_size; offset += size)
11351 {
11352 elf32_arm_output_map_sym (&osi, ARM_MAP_THUMB, offset);
11353 elf32_arm_output_map_sym (&osi, ARM_MAP_ARM, offset + 4);
11354 }
11355 }
11356
11357 /* ARMv4 BX veneers. */
11358 if (htab->bx_glue_size > 0)
11359 {
11360 osi.sec = bfd_get_section_by_name (htab->bfd_of_glue_owner,
11361 ARM_BX_GLUE_SECTION_NAME);
11362
11363 osi.sec_shndx = _bfd_elf_section_from_bfd_section
11364 (output_bfd, osi.sec->output_section);
11365
11366 elf32_arm_output_map_sym (&osi, ARM_MAP_ARM, 0);
11367 }
11368
11369 /* Long calls stubs. */
11370 if (htab->stub_bfd && htab->stub_bfd->sections) {
11371 asection* stub_sec;
11372 for (stub_sec = htab->stub_bfd->sections;
11373 stub_sec != NULL;
11374 stub_sec = stub_sec->next) {
11375
11376 /* Ignore non-stub sections */
11377 if (!strstr(stub_sec->name, STUB_SUFFIX))
11378 continue;
11379
11380 osi.sec = stub_sec;
11381
11382 osi.sec_shndx = _bfd_elf_section_from_bfd_section
11383 (output_bfd, osi.sec->output_section);
11384
11385 bfd_hash_traverse (&htab->stub_hash_table, arm_map_one_stub, &osi);
11386 }
11387 }
11388
11389 /* Finally, output mapping symbols for the PLT. */
11390 if (!htab->splt || htab->splt->size == 0)
11391 return TRUE;
11392
11393 osi.sec_shndx = _bfd_elf_section_from_bfd_section (output_bfd,
11394 htab->splt->output_section);
11395 osi.sec = htab->splt;
11396 /* Output mapping symbols for the plt header. SymbianOS does not have a
11397 plt header. */
11398 if (htab->vxworks_p)
11399 {
11400 /* VxWorks shared libraries have no PLT header. */
11401 if (!info->shared)
11402 {
11403 if (!elf32_arm_output_map_sym (&osi, ARM_MAP_ARM, 0))
11404 return FALSE;
11405 if (!elf32_arm_output_map_sym (&osi, ARM_MAP_DATA, 12))
11406 return FALSE;
11407 }
11408 }
11409 else if (!htab->symbian_p)
11410 {
11411 if (!elf32_arm_output_map_sym (&osi, ARM_MAP_ARM, 0))
11412 return FALSE;
11413 #ifndef FOUR_WORD_PLT
11414 if (!elf32_arm_output_map_sym (&osi, ARM_MAP_DATA, 16))
11415 return FALSE;
11416 #endif
11417 }
11418
11419 elf_link_hash_traverse (&htab->root, elf32_arm_output_plt_map, (void *) &osi);
11420 return TRUE;
11421 }
11422
11423 /* Allocate target specific section data. */
11424
11425 static bfd_boolean
11426 elf32_arm_new_section_hook (bfd *abfd, asection *sec)
11427 {
11428 if (!sec->used_by_bfd)
11429 {
11430 _arm_elf_section_data *sdata;
11431 bfd_size_type amt = sizeof (*sdata);
11432
11433 sdata = bfd_zalloc (abfd, amt);
11434 if (sdata == NULL)
11435 return FALSE;
11436 sec->used_by_bfd = sdata;
11437 }
11438
11439 record_section_with_arm_elf_section_data (sec);
11440
11441 return _bfd_elf_new_section_hook (abfd, sec);
11442 }
11443
11444
11445 /* Used to order a list of mapping symbols by address. */
11446
11447 static int
11448 elf32_arm_compare_mapping (const void * a, const void * b)
11449 {
11450 const elf32_arm_section_map *amap = (const elf32_arm_section_map *) a;
11451 const elf32_arm_section_map *bmap = (const elf32_arm_section_map *) b;
11452
11453 if (amap->vma > bmap->vma)
11454 return 1;
11455 else if (amap->vma < bmap->vma)
11456 return -1;
11457 else if (amap->type > bmap->type)
11458 /* Ensure results do not depend on the host qsort for objects with
11459 multiple mapping symbols at the same address by sorting on type
11460 after vma. */
11461 return 1;
11462 else if (amap->type < bmap->type)
11463 return -1;
11464 else
11465 return 0;
11466 }
11467
11468
11469 /* Do code byteswapping. Return FALSE afterwards so that the section is
11470 written out as normal. */
11471
11472 static bfd_boolean
11473 elf32_arm_write_section (bfd *output_bfd,
11474 struct bfd_link_info *link_info, asection *sec,
11475 bfd_byte *contents)
11476 {
11477 int mapcount, errcount;
11478 _arm_elf_section_data *arm_data;
11479 struct elf32_arm_link_hash_table *globals = elf32_arm_hash_table (link_info);
11480 elf32_arm_section_map *map;
11481 elf32_vfp11_erratum_list *errnode;
11482 bfd_vma ptr;
11483 bfd_vma end;
11484 bfd_vma offset = sec->output_section->vma + sec->output_offset;
11485 bfd_byte tmp;
11486 int i;
11487
11488 /* If this section has not been allocated an _arm_elf_section_data
11489 structure then we cannot record anything. */
11490 arm_data = get_arm_elf_section_data (sec);
11491 if (arm_data == NULL)
11492 return FALSE;
11493
11494 mapcount = arm_data->mapcount;
11495 map = arm_data->map;
11496 errcount = arm_data->erratumcount;
11497
11498 if (errcount != 0)
11499 {
11500 unsigned int endianflip = bfd_big_endian (output_bfd) ? 3 : 0;
11501
11502 for (errnode = arm_data->erratumlist; errnode != 0;
11503 errnode = errnode->next)
11504 {
11505 bfd_vma index = errnode->vma - offset;
11506
11507 switch (errnode->type)
11508 {
11509 case VFP11_ERRATUM_BRANCH_TO_ARM_VENEER:
11510 {
11511 bfd_vma branch_to_veneer;
11512 /* Original condition code of instruction, plus bit mask for
11513 ARM B instruction. */
11514 unsigned int insn = (errnode->u.b.vfp_insn & 0xf0000000)
11515 | 0x0a000000;
11516
11517 /* The instruction is before the label. */
11518 index -= 4;
11519
11520 /* Above offset included in -4 below. */
11521 branch_to_veneer = errnode->u.b.veneer->vma
11522 - errnode->vma - 4;
11523
11524 if ((signed) branch_to_veneer < -(1 << 25)
11525 || (signed) branch_to_veneer >= (1 << 25))
11526 (*_bfd_error_handler) (_("%B: error: VFP11 veneer out of "
11527 "range"), output_bfd);
11528
11529 insn |= (branch_to_veneer >> 2) & 0xffffff;
11530 contents[endianflip ^ index] = insn & 0xff;
11531 contents[endianflip ^ (index + 1)] = (insn >> 8) & 0xff;
11532 contents[endianflip ^ (index + 2)] = (insn >> 16) & 0xff;
11533 contents[endianflip ^ (index + 3)] = (insn >> 24) & 0xff;
11534 }
11535 break;
11536
11537 case VFP11_ERRATUM_ARM_VENEER:
11538 {
11539 bfd_vma branch_from_veneer;
11540 unsigned int insn;
11541
11542 /* Take size of veneer into account. */
11543 branch_from_veneer = errnode->u.v.branch->vma
11544 - errnode->vma - 12;
11545
11546 if ((signed) branch_from_veneer < -(1 << 25)
11547 || (signed) branch_from_veneer >= (1 << 25))
11548 (*_bfd_error_handler) (_("%B: error: VFP11 veneer out of "
11549 "range"), output_bfd);
11550
11551 /* Original instruction. */
11552 insn = errnode->u.v.branch->u.b.vfp_insn;
11553 contents[endianflip ^ index] = insn & 0xff;
11554 contents[endianflip ^ (index + 1)] = (insn >> 8) & 0xff;
11555 contents[endianflip ^ (index + 2)] = (insn >> 16) & 0xff;
11556 contents[endianflip ^ (index + 3)] = (insn >> 24) & 0xff;
11557
11558 /* Branch back to insn after original insn. */
11559 insn = 0xea000000 | ((branch_from_veneer >> 2) & 0xffffff);
11560 contents[endianflip ^ (index + 4)] = insn & 0xff;
11561 contents[endianflip ^ (index + 5)] = (insn >> 8) & 0xff;
11562 contents[endianflip ^ (index + 6)] = (insn >> 16) & 0xff;
11563 contents[endianflip ^ (index + 7)] = (insn >> 24) & 0xff;
11564 }
11565 break;
11566
11567 default:
11568 abort ();
11569 }
11570 }
11571 }
11572
11573 if (mapcount == 0)
11574 return FALSE;
11575
11576 if (globals->byteswap_code)
11577 {
11578 qsort (map, mapcount, sizeof (* map), elf32_arm_compare_mapping);
11579
11580 ptr = map[0].vma;
11581 for (i = 0; i < mapcount; i++)
11582 {
11583 if (i == mapcount - 1)
11584 end = sec->size;
11585 else
11586 end = map[i + 1].vma;
11587
11588 switch (map[i].type)
11589 {
11590 case 'a':
11591 /* Byte swap code words. */
11592 while (ptr + 3 < end)
11593 {
11594 tmp = contents[ptr];
11595 contents[ptr] = contents[ptr + 3];
11596 contents[ptr + 3] = tmp;
11597 tmp = contents[ptr + 1];
11598 contents[ptr + 1] = contents[ptr + 2];
11599 contents[ptr + 2] = tmp;
11600 ptr += 4;
11601 }
11602 break;
11603
11604 case 't':
11605 /* Byte swap code halfwords. */
11606 while (ptr + 1 < end)
11607 {
11608 tmp = contents[ptr];
11609 contents[ptr] = contents[ptr + 1];
11610 contents[ptr + 1] = tmp;
11611 ptr += 2;
11612 }
11613 break;
11614
11615 case 'd':
11616 /* Leave data alone. */
11617 break;
11618 }
11619 ptr = end;
11620 }
11621 }
11622
11623 free (map);
11624 arm_data->mapcount = 0;
11625 arm_data->mapsize = 0;
11626 arm_data->map = NULL;
11627 unrecord_section_with_arm_elf_section_data (sec);
11628
11629 return FALSE;
11630 }
11631
11632 static void
11633 unrecord_section_via_map_over_sections (bfd * abfd ATTRIBUTE_UNUSED,
11634 asection * sec,
11635 void * ignore ATTRIBUTE_UNUSED)
11636 {
11637 unrecord_section_with_arm_elf_section_data (sec);
11638 }
11639
11640 static bfd_boolean
11641 elf32_arm_close_and_cleanup (bfd * abfd)
11642 {
11643 if (abfd->sections)
11644 bfd_map_over_sections (abfd,
11645 unrecord_section_via_map_over_sections,
11646 NULL);
11647
11648 return _bfd_elf_close_and_cleanup (abfd);
11649 }
11650
11651 static bfd_boolean
11652 elf32_arm_bfd_free_cached_info (bfd * abfd)
11653 {
11654 if (abfd->sections)
11655 bfd_map_over_sections (abfd,
11656 unrecord_section_via_map_over_sections,
11657 NULL);
11658
11659 return _bfd_free_cached_info (abfd);
11660 }
11661
11662 /* Display STT_ARM_TFUNC symbols as functions. */
11663
11664 static void
11665 elf32_arm_symbol_processing (bfd *abfd ATTRIBUTE_UNUSED,
11666 asymbol *asym)
11667 {
11668 elf_symbol_type *elfsym = (elf_symbol_type *) asym;
11669
11670 if (ELF_ST_TYPE (elfsym->internal_elf_sym.st_info) == STT_ARM_TFUNC)
11671 elfsym->symbol.flags |= BSF_FUNCTION;
11672 }
11673
11674
11675 /* Mangle thumb function symbols as we read them in. */
11676
11677 static bfd_boolean
11678 elf32_arm_swap_symbol_in (bfd * abfd,
11679 const void *psrc,
11680 const void *pshn,
11681 Elf_Internal_Sym *dst)
11682 {
11683 if (!bfd_elf32_swap_symbol_in (abfd, psrc, pshn, dst))
11684 return FALSE;
11685
11686 /* New EABI objects mark thumb function symbols by setting the low bit of
11687 the address. Turn these into STT_ARM_TFUNC. */
11688 if (ELF_ST_TYPE (dst->st_info) == STT_FUNC
11689 && (dst->st_value & 1))
11690 {
11691 dst->st_info = ELF_ST_INFO (ELF_ST_BIND (dst->st_info), STT_ARM_TFUNC);
11692 dst->st_value &= ~(bfd_vma) 1;
11693 }
11694 return TRUE;
11695 }
11696
11697
11698 /* Mangle thumb function symbols as we write them out. */
11699
11700 static void
11701 elf32_arm_swap_symbol_out (bfd *abfd,
11702 const Elf_Internal_Sym *src,
11703 void *cdst,
11704 void *shndx)
11705 {
11706 Elf_Internal_Sym newsym;
11707
11708 /* We convert STT_ARM_TFUNC symbols into STT_FUNC with the low bit
11709 of the address set, as per the new EABI. We do this unconditionally
11710 because objcopy does not set the elf header flags until after
11711 it writes out the symbol table. */
11712 if (ELF_ST_TYPE (src->st_info) == STT_ARM_TFUNC)
11713 {
11714 newsym = *src;
11715 newsym.st_info = ELF_ST_INFO (ELF_ST_BIND (src->st_info), STT_FUNC);
11716 if (newsym.st_shndx != SHN_UNDEF)
11717 {
11718 /* Do this only for defined symbols. At link type, the static
11719 linker will simulate the work of dynamic linker of resolving
11720 symbols and will carry over the thumbness of found symbols to
11721 the output symbol table. It's not clear how it happens, but
11722 the thumbness of undefined symbols can well be different at
11723 runtime, and writing '1' for them will be confusing for users
11724 and possibly for dynamic linker itself.
11725 */
11726 newsym.st_value |= 1;
11727 }
11728
11729 src = &newsym;
11730 }
11731 bfd_elf32_swap_symbol_out (abfd, src, cdst, shndx);
11732 }
11733
11734 /* Add the PT_ARM_EXIDX program header. */
11735
11736 static bfd_boolean
11737 elf32_arm_modify_segment_map (bfd *abfd,
11738 struct bfd_link_info *info ATTRIBUTE_UNUSED)
11739 {
11740 struct elf_segment_map *m;
11741 asection *sec;
11742
11743 sec = bfd_get_section_by_name (abfd, ".ARM.exidx");
11744 if (sec != NULL && (sec->flags & SEC_LOAD) != 0)
11745 {
11746 /* If there is already a PT_ARM_EXIDX header, then we do not
11747 want to add another one. This situation arises when running
11748 "strip"; the input binary already has the header. */
11749 m = elf_tdata (abfd)->segment_map;
11750 while (m && m->p_type != PT_ARM_EXIDX)
11751 m = m->next;
11752 if (!m)
11753 {
11754 m = bfd_zalloc (abfd, sizeof (struct elf_segment_map));
11755 if (m == NULL)
11756 return FALSE;
11757 m->p_type = PT_ARM_EXIDX;
11758 m->count = 1;
11759 m->sections[0] = sec;
11760
11761 m->next = elf_tdata (abfd)->segment_map;
11762 elf_tdata (abfd)->segment_map = m;
11763 }
11764 }
11765
11766 return TRUE;
11767 }
11768
11769 /* We may add a PT_ARM_EXIDX program header. */
11770
11771 static int
11772 elf32_arm_additional_program_headers (bfd *abfd,
11773 struct bfd_link_info *info ATTRIBUTE_UNUSED)
11774 {
11775 asection *sec;
11776
11777 sec = bfd_get_section_by_name (abfd, ".ARM.exidx");
11778 if (sec != NULL && (sec->flags & SEC_LOAD) != 0)
11779 return 1;
11780 else
11781 return 0;
11782 }
11783
11784 /* We have two function types: STT_FUNC and STT_ARM_TFUNC. */
11785
11786 static bfd_boolean
11787 elf32_arm_is_function_type (unsigned int type)
11788 {
11789 return (type == STT_FUNC) || (type == STT_ARM_TFUNC);
11790 }
11791
11792 /* We use this to override swap_symbol_in and swap_symbol_out. */
11793 const struct elf_size_info elf32_arm_size_info =
11794 {
11795 sizeof (Elf32_External_Ehdr),
11796 sizeof (Elf32_External_Phdr),
11797 sizeof (Elf32_External_Shdr),
11798 sizeof (Elf32_External_Rel),
11799 sizeof (Elf32_External_Rela),
11800 sizeof (Elf32_External_Sym),
11801 sizeof (Elf32_External_Dyn),
11802 sizeof (Elf_External_Note),
11803 4,
11804 1,
11805 32, 2,
11806 ELFCLASS32, EV_CURRENT,
11807 bfd_elf32_write_out_phdrs,
11808 bfd_elf32_write_shdrs_and_ehdr,
11809 bfd_elf32_checksum_contents,
11810 bfd_elf32_write_relocs,
11811 elf32_arm_swap_symbol_in,
11812 elf32_arm_swap_symbol_out,
11813 bfd_elf32_slurp_reloc_table,
11814 bfd_elf32_slurp_symbol_table,
11815 bfd_elf32_swap_dyn_in,
11816 bfd_elf32_swap_dyn_out,
11817 bfd_elf32_swap_reloc_in,
11818 bfd_elf32_swap_reloc_out,
11819 bfd_elf32_swap_reloca_in,
11820 bfd_elf32_swap_reloca_out
11821 };
11822
11823 #define ELF_ARCH bfd_arch_arm
11824 #define ELF_MACHINE_CODE EM_ARM
11825 #ifdef __QNXTARGET__
11826 #define ELF_MAXPAGESIZE 0x1000
11827 #else
11828 #define ELF_MAXPAGESIZE 0x8000
11829 #endif
11830 #define ELF_MINPAGESIZE 0x1000
11831 #define ELF_COMMONPAGESIZE 0x1000
11832
11833 #define bfd_elf32_mkobject elf32_arm_mkobject
11834
11835 #define bfd_elf32_bfd_copy_private_bfd_data elf32_arm_copy_private_bfd_data
11836 #define bfd_elf32_bfd_merge_private_bfd_data elf32_arm_merge_private_bfd_data
11837 #define bfd_elf32_bfd_set_private_flags elf32_arm_set_private_flags
11838 #define bfd_elf32_bfd_print_private_bfd_data elf32_arm_print_private_bfd_data
11839 #define bfd_elf32_bfd_link_hash_table_create elf32_arm_link_hash_table_create
11840 #define bfd_elf32_bfd_link_hash_table_free elf32_arm_hash_table_free
11841 #define bfd_elf32_bfd_reloc_type_lookup elf32_arm_reloc_type_lookup
11842 #define bfd_elf32_bfd_reloc_name_lookup elf32_arm_reloc_name_lookup
11843 #define bfd_elf32_find_nearest_line elf32_arm_find_nearest_line
11844 #define bfd_elf32_find_inliner_info elf32_arm_find_inliner_info
11845 #define bfd_elf32_new_section_hook elf32_arm_new_section_hook
11846 #define bfd_elf32_bfd_is_target_special_symbol elf32_arm_is_target_special_symbol
11847 #define bfd_elf32_close_and_cleanup elf32_arm_close_and_cleanup
11848 #define bfd_elf32_bfd_free_cached_info elf32_arm_bfd_free_cached_info
11849
11850 #define elf_backend_get_symbol_type elf32_arm_get_symbol_type
11851 #define elf_backend_gc_mark_hook elf32_arm_gc_mark_hook
11852 #define elf_backend_gc_mark_extra_sections elf32_arm_gc_mark_extra_sections
11853 #define elf_backend_gc_sweep_hook elf32_arm_gc_sweep_hook
11854 #define elf_backend_check_relocs elf32_arm_check_relocs
11855 #define elf_backend_relocate_section elf32_arm_relocate_section
11856 #define elf_backend_write_section elf32_arm_write_section
11857 #define elf_backend_adjust_dynamic_symbol elf32_arm_adjust_dynamic_symbol
11858 #define elf_backend_create_dynamic_sections elf32_arm_create_dynamic_sections
11859 #define elf_backend_finish_dynamic_symbol elf32_arm_finish_dynamic_symbol
11860 #define elf_backend_finish_dynamic_sections elf32_arm_finish_dynamic_sections
11861 #define elf_backend_size_dynamic_sections elf32_arm_size_dynamic_sections
11862 #define elf_backend_init_index_section _bfd_elf_init_2_index_sections
11863 #define elf_backend_post_process_headers elf32_arm_post_process_headers
11864 #define elf_backend_reloc_type_class elf32_arm_reloc_type_class
11865 #define elf_backend_object_p elf32_arm_object_p
11866 #define elf_backend_section_flags elf32_arm_section_flags
11867 #define elf_backend_fake_sections elf32_arm_fake_sections
11868 #define elf_backend_section_from_shdr elf32_arm_section_from_shdr
11869 #define elf_backend_final_write_processing elf32_arm_final_write_processing
11870 #define elf_backend_copy_indirect_symbol elf32_arm_copy_indirect_symbol
11871 #define elf_backend_symbol_processing elf32_arm_symbol_processing
11872 #define elf_backend_size_info elf32_arm_size_info
11873 #define elf_backend_modify_segment_map elf32_arm_modify_segment_map
11874 #define elf_backend_additional_program_headers elf32_arm_additional_program_headers
11875 #define elf_backend_output_arch_local_syms elf32_arm_output_arch_local_syms
11876 #define elf_backend_begin_write_processing elf32_arm_begin_write_processing
11877 #define elf_backend_is_function_type elf32_arm_is_function_type
11878
11879 #define elf_backend_can_refcount 1
11880 #define elf_backend_can_gc_sections 1
11881 #define elf_backend_plt_readonly 1
11882 #define elf_backend_want_got_plt 1
11883 #define elf_backend_want_plt_sym 0
11884 #define elf_backend_may_use_rel_p 1
11885 #define elf_backend_may_use_rela_p 0
11886 #define elf_backend_default_use_rela_p 0
11887
11888 #define elf_backend_got_header_size 12
11889
11890 #undef elf_backend_obj_attrs_vendor
11891 #define elf_backend_obj_attrs_vendor "aeabi"
11892 #undef elf_backend_obj_attrs_section
11893 #define elf_backend_obj_attrs_section ".ARM.attributes"
11894 #undef elf_backend_obj_attrs_arg_type
11895 #define elf_backend_obj_attrs_arg_type elf32_arm_obj_attrs_arg_type
11896 #undef elf_backend_obj_attrs_section_type
11897 #define elf_backend_obj_attrs_section_type SHT_ARM_ATTRIBUTES
11898
11899 #include "elf32-target.h"
11900
11901 /* VxWorks Targets. */
11902
11903 #undef TARGET_LITTLE_SYM
11904 #define TARGET_LITTLE_SYM bfd_elf32_littlearm_vxworks_vec
11905 #undef TARGET_LITTLE_NAME
11906 #define TARGET_LITTLE_NAME "elf32-littlearm-vxworks"
11907 #undef TARGET_BIG_SYM
11908 #define TARGET_BIG_SYM bfd_elf32_bigarm_vxworks_vec
11909 #undef TARGET_BIG_NAME
11910 #define TARGET_BIG_NAME "elf32-bigarm-vxworks"
11911
11912 /* Like elf32_arm_link_hash_table_create -- but overrides
11913 appropriately for VxWorks. */
11914
11915 static struct bfd_link_hash_table *
11916 elf32_arm_vxworks_link_hash_table_create (bfd *abfd)
11917 {
11918 struct bfd_link_hash_table *ret;
11919
11920 ret = elf32_arm_link_hash_table_create (abfd);
11921 if (ret)
11922 {
11923 struct elf32_arm_link_hash_table *htab
11924 = (struct elf32_arm_link_hash_table *) ret;
11925 htab->use_rel = 0;
11926 htab->vxworks_p = 1;
11927 }
11928 return ret;
11929 }
11930
11931 static void
11932 elf32_arm_vxworks_final_write_processing (bfd *abfd, bfd_boolean linker)
11933 {
11934 elf32_arm_final_write_processing (abfd, linker);
11935 elf_vxworks_final_write_processing (abfd, linker);
11936 }
11937
11938 #undef elf32_bed
11939 #define elf32_bed elf32_arm_vxworks_bed
11940
11941 #undef bfd_elf32_bfd_link_hash_table_create
11942 #define bfd_elf32_bfd_link_hash_table_create elf32_arm_vxworks_link_hash_table_create
11943 #undef elf_backend_add_symbol_hook
11944 #define elf_backend_add_symbol_hook elf_vxworks_add_symbol_hook
11945 #undef elf_backend_final_write_processing
11946 #define elf_backend_final_write_processing elf32_arm_vxworks_final_write_processing
11947 #undef elf_backend_emit_relocs
11948 #define elf_backend_emit_relocs elf_vxworks_emit_relocs
11949
11950 #undef elf_backend_may_use_rel_p
11951 #define elf_backend_may_use_rel_p 0
11952 #undef elf_backend_may_use_rela_p
11953 #define elf_backend_may_use_rela_p 1
11954 #undef elf_backend_default_use_rela_p
11955 #define elf_backend_default_use_rela_p 1
11956 #undef elf_backend_want_plt_sym
11957 #define elf_backend_want_plt_sym 1
11958 #undef ELF_MAXPAGESIZE
11959 #define ELF_MAXPAGESIZE 0x1000
11960
11961 #include "elf32-target.h"
11962
11963
11964 /* Symbian OS Targets. */
11965
11966 #undef TARGET_LITTLE_SYM
11967 #define TARGET_LITTLE_SYM bfd_elf32_littlearm_symbian_vec
11968 #undef TARGET_LITTLE_NAME
11969 #define TARGET_LITTLE_NAME "elf32-littlearm-symbian"
11970 #undef TARGET_BIG_SYM
11971 #define TARGET_BIG_SYM bfd_elf32_bigarm_symbian_vec
11972 #undef TARGET_BIG_NAME
11973 #define TARGET_BIG_NAME "elf32-bigarm-symbian"
11974
11975 /* Like elf32_arm_link_hash_table_create -- but overrides
11976 appropriately for Symbian OS. */
11977
11978 static struct bfd_link_hash_table *
11979 elf32_arm_symbian_link_hash_table_create (bfd *abfd)
11980 {
11981 struct bfd_link_hash_table *ret;
11982
11983 ret = elf32_arm_link_hash_table_create (abfd);
11984 if (ret)
11985 {
11986 struct elf32_arm_link_hash_table *htab
11987 = (struct elf32_arm_link_hash_table *)ret;
11988 /* There is no PLT header for Symbian OS. */
11989 htab->plt_header_size = 0;
11990 /* The PLT entries are each one instruction and one word. */
11991 htab->plt_entry_size = 4 * ARRAY_SIZE (elf32_arm_symbian_plt_entry);
11992 htab->symbian_p = 1;
11993 /* Symbian uses armv5t or above, so use_blx is always true. */
11994 htab->use_blx = 1;
11995 htab->root.is_relocatable_executable = 1;
11996 }
11997 return ret;
11998 }
11999
12000 static const struct bfd_elf_special_section
12001 elf32_arm_symbian_special_sections[] =
12002 {
12003 /* In a BPABI executable, the dynamic linking sections do not go in
12004 the loadable read-only segment. The post-linker may wish to
12005 refer to these sections, but they are not part of the final
12006 program image. */
12007 { STRING_COMMA_LEN (".dynamic"), 0, SHT_DYNAMIC, 0 },
12008 { STRING_COMMA_LEN (".dynstr"), 0, SHT_STRTAB, 0 },
12009 { STRING_COMMA_LEN (".dynsym"), 0, SHT_DYNSYM, 0 },
12010 { STRING_COMMA_LEN (".got"), 0, SHT_PROGBITS, 0 },
12011 { STRING_COMMA_LEN (".hash"), 0, SHT_HASH, 0 },
12012 /* These sections do not need to be writable as the SymbianOS
12013 postlinker will arrange things so that no dynamic relocation is
12014 required. */
12015 { STRING_COMMA_LEN (".init_array"), 0, SHT_INIT_ARRAY, SHF_ALLOC },
12016 { STRING_COMMA_LEN (".fini_array"), 0, SHT_FINI_ARRAY, SHF_ALLOC },
12017 { STRING_COMMA_LEN (".preinit_array"), 0, SHT_PREINIT_ARRAY, SHF_ALLOC },
12018 { NULL, 0, 0, 0, 0 }
12019 };
12020
12021 static void
12022 elf32_arm_symbian_begin_write_processing (bfd *abfd,
12023 struct bfd_link_info *link_info)
12024 {
12025 /* BPABI objects are never loaded directly by an OS kernel; they are
12026 processed by a postlinker first, into an OS-specific format. If
12027 the D_PAGED bit is set on the file, BFD will align segments on
12028 page boundaries, so that an OS can directly map the file. With
12029 BPABI objects, that just results in wasted space. In addition,
12030 because we clear the D_PAGED bit, map_sections_to_segments will
12031 recognize that the program headers should not be mapped into any
12032 loadable segment. */
12033 abfd->flags &= ~D_PAGED;
12034 elf32_arm_begin_write_processing (abfd, link_info);
12035 }
12036
12037 static bfd_boolean
12038 elf32_arm_symbian_modify_segment_map (bfd *abfd,
12039 struct bfd_link_info *info)
12040 {
12041 struct elf_segment_map *m;
12042 asection *dynsec;
12043
12044 /* BPABI shared libraries and executables should have a PT_DYNAMIC
12045 segment. However, because the .dynamic section is not marked
12046 with SEC_LOAD, the generic ELF code will not create such a
12047 segment. */
12048 dynsec = bfd_get_section_by_name (abfd, ".dynamic");
12049 if (dynsec)
12050 {
12051 for (m = elf_tdata (abfd)->segment_map; m != NULL; m = m->next)
12052 if (m->p_type == PT_DYNAMIC)
12053 break;
12054
12055 if (m == NULL)
12056 {
12057 m = _bfd_elf_make_dynamic_segment (abfd, dynsec);
12058 m->next = elf_tdata (abfd)->segment_map;
12059 elf_tdata (abfd)->segment_map = m;
12060 }
12061 }
12062
12063 /* Also call the generic arm routine. */
12064 return elf32_arm_modify_segment_map (abfd, info);
12065 }
12066
12067 /* Return address for Ith PLT stub in section PLT, for relocation REL
12068 or (bfd_vma) -1 if it should not be included. */
12069
12070 static bfd_vma
12071 elf32_arm_symbian_plt_sym_val (bfd_vma i, const asection *plt,
12072 const arelent *rel ATTRIBUTE_UNUSED)
12073 {
12074 return plt->vma + 4 * ARRAY_SIZE (elf32_arm_symbian_plt_entry) * i;
12075 }
12076
12077
12078 #undef elf32_bed
12079 #define elf32_bed elf32_arm_symbian_bed
12080
12081 /* The dynamic sections are not allocated on SymbianOS; the postlinker
12082 will process them and then discard them. */
12083 #undef ELF_DYNAMIC_SEC_FLAGS
12084 #define ELF_DYNAMIC_SEC_FLAGS \
12085 (SEC_HAS_CONTENTS | SEC_IN_MEMORY | SEC_LINKER_CREATED)
12086
12087 #undef elf_backend_add_symbol_hook
12088 #undef elf_backend_emit_relocs
12089
12090 #undef bfd_elf32_bfd_link_hash_table_create
12091 #define bfd_elf32_bfd_link_hash_table_create elf32_arm_symbian_link_hash_table_create
12092 #undef elf_backend_special_sections
12093 #define elf_backend_special_sections elf32_arm_symbian_special_sections
12094 #undef elf_backend_begin_write_processing
12095 #define elf_backend_begin_write_processing elf32_arm_symbian_begin_write_processing
12096 #undef elf_backend_final_write_processing
12097 #define elf_backend_final_write_processing elf32_arm_final_write_processing
12098
12099 #undef elf_backend_modify_segment_map
12100 #define elf_backend_modify_segment_map elf32_arm_symbian_modify_segment_map
12101
12102 /* There is no .got section for BPABI objects, and hence no header. */
12103 #undef elf_backend_got_header_size
12104 #define elf_backend_got_header_size 0
12105
12106 /* Similarly, there is no .got.plt section. */
12107 #undef elf_backend_want_got_plt
12108 #define elf_backend_want_got_plt 0
12109
12110 #undef elf_backend_plt_sym_val
12111 #define elf_backend_plt_sym_val elf32_arm_symbian_plt_sym_val
12112
12113 #undef elf_backend_may_use_rel_p
12114 #define elf_backend_may_use_rel_p 1
12115 #undef elf_backend_may_use_rela_p
12116 #define elf_backend_may_use_rela_p 0
12117 #undef elf_backend_default_use_rela_p
12118 #define elf_backend_default_use_rela_p 0
12119 #undef elf_backend_want_plt_sym
12120 #define elf_backend_want_plt_sym 0
12121 #undef ELF_MAXPAGESIZE
12122 #define ELF_MAXPAGESIZE 0x8000
12123
12124 #include "elf32-target.h"
This page took 0.361179 seconds and 4 git commands to generate.