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