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