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