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