1 /* 32-bit ELF support for ARM
2 Copyright 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006
3 Free Software Foundation, Inc.
4
5 This file is part of BFD, the Binary File Descriptor library.
6
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
11
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA. */
20
21 #include "bfd.h"
22 #include "sysdep.h"
23 #include "libiberty.h"
24 #include "libbfd.h"
25 #include "elf-bfd.h"
26 #include "elf-vxworks.h"
27 #include "elf/arm.h"
28
29 #ifndef NUM_ELEM
30 #define NUM_ELEM(a) (sizeof (a) / (sizeof (a)[0]))
31 #endif
32
33 /* Return the relocation section associated with NAME. HTAB is the
34 bfd's elf32_arm_link_hash_entry. */
35 #define RELOC_SECTION(HTAB, NAME) \
36 ((HTAB)->use_rel ? ".rel" NAME : ".rela" NAME)
37
38 /* Return size of a relocation entry. HTAB is the bfd's
39 elf32_arm_link_hash_entry. */
40 #define RELOC_SIZE(HTAB) \
41 ((HTAB)->use_rel \
42 ? sizeof (Elf32_External_Rel) \
43 : sizeof (Elf32_External_Rela))
44
45 /* Return function to swap relocations in. HTAB is the bfd's
46 elf32_arm_link_hash_entry. */
47 #define SWAP_RELOC_IN(HTAB) \
48 ((HTAB)->use_rel \
49 ? bfd_elf32_swap_reloc_in \
50 : bfd_elf32_swap_reloca_in)
51
52 /* Return function to swap relocations out. HTAB is the bfd's
53 elf32_arm_link_hash_entry. */
54 #define SWAP_RELOC_OUT(HTAB) \
55 ((HTAB)->use_rel \
56 ? bfd_elf32_swap_reloc_out \
57 : bfd_elf32_swap_reloca_out)
58
59 #define elf_info_to_howto 0
60 #define elf_info_to_howto_rel elf32_arm_info_to_howto
61
62 #define ARM_ELF_ABI_VERSION 0
63 #define ARM_ELF_OS_ABI_VERSION ELFOSABI_ARM
64
65 static const 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_PC13, /* type */
134 0, /* rightshift */
135 0, /* size (0 = byte, 1 = short, 2 = long) */
136 8, /* bitsize */
137 FALSE, /* pc_relative */
138 0, /* bitpos */
139 complain_overflow_bitfield,/* complain_on_overflow */
140 bfd_elf_generic_reloc, /* special_function */
141 "R_ARM_PC13", /* name */
142 FALSE, /* partial_inplace */
143 0x000000ff, /* src_mask */
144 0x000000ff, /* dst_mask */
145 FALSE), /* 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 /* FIXME: Has two more bits of offset in Thumb32. */
221 HOWTO (R_ARM_THM_CALL, /* type */
222 1, /* rightshift */
223 2, /* size (0 = byte, 1 = short, 2 = long) */
224 23, /* bitsize */
225 TRUE, /* pc_relative */
226 0, /* bitpos */
227 complain_overflow_signed,/* complain_on_overflow */
228 bfd_elf_generic_reloc, /* special_function */
229 "R_ARM_THM_CALL", /* name */
230 FALSE, /* partial_inplace */
231 0x07ff07ff, /* src_mask */
232 0x07ff07ff, /* dst_mask */
233 TRUE), /* pcrel_offset */
234
235 HOWTO (R_ARM_THM_PC8, /* type */
236 1, /* rightshift */
237 1, /* size (0 = byte, 1 = short, 2 = long) */
238 8, /* bitsize */
239 TRUE, /* pc_relative */
240 0, /* bitpos */
241 complain_overflow_signed,/* complain_on_overflow */
242 bfd_elf_generic_reloc, /* special_function */
243 "R_ARM_THM_PC8", /* name */
244 FALSE, /* partial_inplace */
245 0x000000ff, /* src_mask */
246 0x000000ff, /* dst_mask */
247 TRUE), /* pcrel_offset */
248
249 HOWTO (R_ARM_BREL_ADJ, /* type */
250 1, /* rightshift */
251 1, /* size (0 = byte, 1 = short, 2 = long) */
252 32, /* bitsize */
253 FALSE, /* pc_relative */
254 0, /* bitpos */
255 complain_overflow_signed,/* complain_on_overflow */
256 bfd_elf_generic_reloc, /* special_function */
257 "R_ARM_BREL_ADJ", /* name */
258 FALSE, /* partial_inplace */
259 0xffffffff, /* src_mask */
260 0xffffffff, /* dst_mask */
261 FALSE), /* pcrel_offset */
262
263 HOWTO (R_ARM_SWI24, /* type */
264 0, /* rightshift */
265 0, /* size (0 = byte, 1 = short, 2 = long) */
266 0, /* bitsize */
267 FALSE, /* pc_relative */
268 0, /* bitpos */
269 complain_overflow_signed,/* complain_on_overflow */
270 bfd_elf_generic_reloc, /* special_function */
271 "R_ARM_SWI24", /* name */
272 FALSE, /* partial_inplace */
273 0x00000000, /* src_mask */
274 0x00000000, /* dst_mask */
275 FALSE), /* pcrel_offset */
276
277 HOWTO (R_ARM_THM_SWI8, /* type */
278 0, /* rightshift */
279 0, /* size (0 = byte, 1 = short, 2 = long) */
280 0, /* bitsize */
281 FALSE, /* pc_relative */
282 0, /* bitpos */
283 complain_overflow_signed,/* complain_on_overflow */
284 bfd_elf_generic_reloc, /* special_function */
285 "R_ARM_SWI8", /* name */
286 FALSE, /* partial_inplace */
287 0x00000000, /* src_mask */
288 0x00000000, /* dst_mask */
289 FALSE), /* pcrel_offset */
290
291 /* BLX instruction for the ARM. */
292 HOWTO (R_ARM_XPC25, /* type */
293 2, /* rightshift */
294 2, /* size (0 = byte, 1 = short, 2 = long) */
295 25, /* bitsize */
296 TRUE, /* pc_relative */
297 0, /* bitpos */
298 complain_overflow_signed,/* complain_on_overflow */
299 bfd_elf_generic_reloc, /* special_function */
300 "R_ARM_XPC25", /* name */
301 FALSE, /* partial_inplace */
302 0x00ffffff, /* src_mask */
303 0x00ffffff, /* dst_mask */
304 TRUE), /* pcrel_offset */
305
306 /* BLX instruction for the Thumb. */
307 HOWTO (R_ARM_THM_XPC22, /* type */
308 2, /* rightshift */
309 2, /* size (0 = byte, 1 = short, 2 = long) */
310 22, /* bitsize */
311 TRUE, /* pc_relative */
312 0, /* bitpos */
313 complain_overflow_signed,/* complain_on_overflow */
314 bfd_elf_generic_reloc, /* special_function */
315 "R_ARM_THM_XPC22", /* name */
316 FALSE, /* partial_inplace */
317 0x07ff07ff, /* src_mask */
318 0x07ff07ff, /* dst_mask */
319 TRUE), /* pcrel_offset */
320
321 /* Dynamic TLS relocations. */
322
323 HOWTO (R_ARM_TLS_DTPMOD32, /* type */
324 0, /* rightshift */
325 2, /* size (0 = byte, 1 = short, 2 = long) */
326 32, /* bitsize */
327 FALSE, /* pc_relative */
328 0, /* bitpos */
329 complain_overflow_bitfield,/* complain_on_overflow */
330 bfd_elf_generic_reloc, /* special_function */
331 "R_ARM_TLS_DTPMOD32", /* name */
332 TRUE, /* partial_inplace */
333 0xffffffff, /* src_mask */
334 0xffffffff, /* dst_mask */
335 FALSE), /* pcrel_offset */
336
337 HOWTO (R_ARM_TLS_DTPOFF32, /* type */
338 0, /* rightshift */
339 2, /* size (0 = byte, 1 = short, 2 = long) */
340 32, /* bitsize */
341 FALSE, /* pc_relative */
342 0, /* bitpos */
343 complain_overflow_bitfield,/* complain_on_overflow */
344 bfd_elf_generic_reloc, /* special_function */
345 "R_ARM_TLS_DTPOFF32", /* name */
346 TRUE, /* partial_inplace */
347 0xffffffff, /* src_mask */
348 0xffffffff, /* dst_mask */
349 FALSE), /* pcrel_offset */
350
351 HOWTO (R_ARM_TLS_TPOFF32, /* type */
352 0, /* rightshift */
353 2, /* size (0 = byte, 1 = short, 2 = long) */
354 32, /* bitsize */
355 FALSE, /* pc_relative */
356 0, /* bitpos */
357 complain_overflow_bitfield,/* complain_on_overflow */
358 bfd_elf_generic_reloc, /* special_function */
359 "R_ARM_TLS_TPOFF32", /* name */
360 TRUE, /* partial_inplace */
361 0xffffffff, /* src_mask */
362 0xffffffff, /* dst_mask */
363 FALSE), /* pcrel_offset */
364
365 /* Relocs used in ARM Linux */
366
367 HOWTO (R_ARM_COPY, /* type */
368 0, /* rightshift */
369 2, /* size (0 = byte, 1 = short, 2 = long) */
370 32, /* bitsize */
371 FALSE, /* pc_relative */
372 0, /* bitpos */
373 complain_overflow_bitfield,/* complain_on_overflow */
374 bfd_elf_generic_reloc, /* special_function */
375 "R_ARM_COPY", /* name */
376 TRUE, /* partial_inplace */
377 0xffffffff, /* src_mask */
378 0xffffffff, /* dst_mask */
379 FALSE), /* pcrel_offset */
380
381 HOWTO (R_ARM_GLOB_DAT, /* type */
382 0, /* rightshift */
383 2, /* size (0 = byte, 1 = short, 2 = long) */
384 32, /* bitsize */
385 FALSE, /* pc_relative */
386 0, /* bitpos */
387 complain_overflow_bitfield,/* complain_on_overflow */
388 bfd_elf_generic_reloc, /* special_function */
389 "R_ARM_GLOB_DAT", /* name */
390 TRUE, /* partial_inplace */
391 0xffffffff, /* src_mask */
392 0xffffffff, /* dst_mask */
393 FALSE), /* pcrel_offset */
394
395 HOWTO (R_ARM_JUMP_SLOT, /* type */
396 0, /* rightshift */
397 2, /* size (0 = byte, 1 = short, 2 = long) */
398 32, /* bitsize */
399 FALSE, /* pc_relative */
400 0, /* bitpos */
401 complain_overflow_bitfield,/* complain_on_overflow */
402 bfd_elf_generic_reloc, /* special_function */
403 "R_ARM_JUMP_SLOT", /* name */
404 TRUE, /* partial_inplace */
405 0xffffffff, /* src_mask */
406 0xffffffff, /* dst_mask */
407 FALSE), /* pcrel_offset */
408
409 HOWTO (R_ARM_RELATIVE, /* type */
410 0, /* rightshift */
411 2, /* size (0 = byte, 1 = short, 2 = long) */
412 32, /* bitsize */
413 FALSE, /* pc_relative */
414 0, /* bitpos */
415 complain_overflow_bitfield,/* complain_on_overflow */
416 bfd_elf_generic_reloc, /* special_function */
417 "R_ARM_RELATIVE", /* name */
418 TRUE, /* partial_inplace */
419 0xffffffff, /* src_mask */
420 0xffffffff, /* dst_mask */
421 FALSE), /* pcrel_offset */
422
423 HOWTO (R_ARM_GOTOFF32, /* type */
424 0, /* rightshift */
425 2, /* size (0 = byte, 1 = short, 2 = long) */
426 32, /* bitsize */
427 FALSE, /* pc_relative */
428 0, /* bitpos */
429 complain_overflow_bitfield,/* complain_on_overflow */
430 bfd_elf_generic_reloc, /* special_function */
431 "R_ARM_GOTOFF32", /* name */
432 TRUE, /* partial_inplace */
433 0xffffffff, /* src_mask */
434 0xffffffff, /* dst_mask */
435 FALSE), /* pcrel_offset */
436
437 HOWTO (R_ARM_GOTPC, /* type */
438 0, /* rightshift */
439 2, /* size (0 = byte, 1 = short, 2 = long) */
440 32, /* bitsize */
441 TRUE, /* pc_relative */
442 0, /* bitpos */
443 complain_overflow_bitfield,/* complain_on_overflow */
444 bfd_elf_generic_reloc, /* special_function */
445 "R_ARM_GOTPC", /* name */
446 TRUE, /* partial_inplace */
447 0xffffffff, /* src_mask */
448 0xffffffff, /* dst_mask */
449 TRUE), /* pcrel_offset */
450
451 HOWTO (R_ARM_GOT32, /* type */
452 0, /* rightshift */
453 2, /* size (0 = byte, 1 = short, 2 = long) */
454 32, /* bitsize */
455 FALSE, /* pc_relative */
456 0, /* bitpos */
457 complain_overflow_bitfield,/* complain_on_overflow */
458 bfd_elf_generic_reloc, /* special_function */
459 "R_ARM_GOT32", /* name */
460 TRUE, /* partial_inplace */
461 0xffffffff, /* src_mask */
462 0xffffffff, /* dst_mask */
463 FALSE), /* pcrel_offset */
464
465 HOWTO (R_ARM_PLT32, /* type */
466 2, /* rightshift */
467 2, /* size (0 = byte, 1 = short, 2 = long) */
468 24, /* bitsize */
469 TRUE, /* pc_relative */
470 0, /* bitpos */
471 complain_overflow_bitfield,/* complain_on_overflow */
472 bfd_elf_generic_reloc, /* special_function */
473 "R_ARM_PLT32", /* name */
474 FALSE, /* partial_inplace */
475 0x00ffffff, /* src_mask */
476 0x00ffffff, /* dst_mask */
477 TRUE), /* pcrel_offset */
478
479 HOWTO (R_ARM_CALL, /* type */
480 2, /* rightshift */
481 2, /* size (0 = byte, 1 = short, 2 = long) */
482 24, /* bitsize */
483 TRUE, /* pc_relative */
484 0, /* bitpos */
485 complain_overflow_signed,/* complain_on_overflow */
486 bfd_elf_generic_reloc, /* special_function */
487 "R_ARM_CALL", /* name */
488 FALSE, /* partial_inplace */
489 0x00ffffff, /* src_mask */
490 0x00ffffff, /* dst_mask */
491 TRUE), /* pcrel_offset */
492
493 HOWTO (R_ARM_JUMP24, /* type */
494 2, /* rightshift */
495 2, /* size (0 = byte, 1 = short, 2 = long) */
496 24, /* bitsize */
497 TRUE, /* pc_relative */
498 0, /* bitpos */
499 complain_overflow_signed,/* complain_on_overflow */
500 bfd_elf_generic_reloc, /* special_function */
501 "R_ARM_JUMP24", /* name */
502 FALSE, /* partial_inplace */
503 0x00ffffff, /* src_mask */
504 0x00ffffff, /* dst_mask */
505 TRUE), /* pcrel_offset */
506
507 HOWTO (R_ARM_THM_JUMP24, /* type */
508 1, /* rightshift */
509 2, /* size (0 = byte, 1 = short, 2 = long) */
510 24, /* bitsize */
511 TRUE, /* pc_relative */
512 0, /* bitpos */
513 complain_overflow_signed,/* complain_on_overflow */
514 bfd_elf_generic_reloc, /* special_function */
515 "R_ARM_THM_JUMP24", /* name */
516 FALSE, /* partial_inplace */
517 0x07ff2fff, /* src_mask */
518 0x07ff2fff, /* dst_mask */
519 TRUE), /* pcrel_offset */
520
521 HOWTO (R_ARM_BASE_ABS, /* type */
522 0, /* rightshift */
523 2, /* size (0 = byte, 1 = short, 2 = long) */
524 32, /* bitsize */
525 FALSE, /* pc_relative */
526 0, /* bitpos */
527 complain_overflow_dont,/* complain_on_overflow */
528 bfd_elf_generic_reloc, /* special_function */
529 "R_ARM_BASE_ABS", /* name */
530 FALSE, /* partial_inplace */
531 0xffffffff, /* src_mask */
532 0xffffffff, /* dst_mask */
533 FALSE), /* pcrel_offset */
534
535 HOWTO (R_ARM_ALU_PCREL7_0, /* type */
536 0, /* rightshift */
537 2, /* size (0 = byte, 1 = short, 2 = long) */
538 12, /* bitsize */
539 TRUE, /* pc_relative */
540 0, /* bitpos */
541 complain_overflow_dont,/* complain_on_overflow */
542 bfd_elf_generic_reloc, /* special_function */
543 "R_ARM_ALU_PCREL_7_0", /* name */
544 FALSE, /* partial_inplace */
545 0x00000fff, /* src_mask */
546 0x00000fff, /* dst_mask */
547 TRUE), /* pcrel_offset */
548
549 HOWTO (R_ARM_ALU_PCREL15_8, /* type */
550 0, /* rightshift */
551 2, /* size (0 = byte, 1 = short, 2 = long) */
552 12, /* bitsize */
553 TRUE, /* pc_relative */
554 8, /* bitpos */
555 complain_overflow_dont,/* complain_on_overflow */
556 bfd_elf_generic_reloc, /* special_function */
557 "R_ARM_ALU_PCREL_15_8",/* name */
558 FALSE, /* partial_inplace */
559 0x00000fff, /* src_mask */
560 0x00000fff, /* dst_mask */
561 TRUE), /* pcrel_offset */
562
563 HOWTO (R_ARM_ALU_PCREL23_15, /* type */
564 0, /* rightshift */
565 2, /* size (0 = byte, 1 = short, 2 = long) */
566 12, /* bitsize */
567 TRUE, /* pc_relative */
568 16, /* bitpos */
569 complain_overflow_dont,/* complain_on_overflow */
570 bfd_elf_generic_reloc, /* special_function */
571 "R_ARM_ALU_PCREL_23_15",/* name */
572 FALSE, /* partial_inplace */
573 0x00000fff, /* src_mask */
574 0x00000fff, /* dst_mask */
575 TRUE), /* pcrel_offset */
576
577 HOWTO (R_ARM_LDR_SBREL_11_0, /* type */
578 0, /* rightshift */
579 2, /* size (0 = byte, 1 = short, 2 = long) */
580 12, /* bitsize */
581 FALSE, /* pc_relative */
582 0, /* bitpos */
583 complain_overflow_dont,/* complain_on_overflow */
584 bfd_elf_generic_reloc, /* special_function */
585 "R_ARM_LDR_SBREL_11_0",/* name */
586 FALSE, /* partial_inplace */
587 0x00000fff, /* src_mask */
588 0x00000fff, /* dst_mask */
589 FALSE), /* pcrel_offset */
590
591 HOWTO (R_ARM_ALU_SBREL_19_12, /* type */
592 0, /* rightshift */
593 2, /* size (0 = byte, 1 = short, 2 = long) */
594 8, /* bitsize */
595 FALSE, /* pc_relative */
596 12, /* bitpos */
597 complain_overflow_dont,/* complain_on_overflow */
598 bfd_elf_generic_reloc, /* special_function */
599 "R_ARM_ALU_SBREL_19_12",/* name */
600 FALSE, /* partial_inplace */
601 0x000ff000, /* src_mask */
602 0x000ff000, /* dst_mask */
603 FALSE), /* pcrel_offset */
604
605 HOWTO (R_ARM_ALU_SBREL_27_20, /* type */
606 0, /* rightshift */
607 2, /* size (0 = byte, 1 = short, 2 = long) */
608 8, /* bitsize */
609 FALSE, /* pc_relative */
610 20, /* bitpos */
611 complain_overflow_dont,/* complain_on_overflow */
612 bfd_elf_generic_reloc, /* special_function */
613 "R_ARM_ALU_SBREL_27_20",/* name */
614 FALSE, /* partial_inplace */
615 0x0ff00000, /* src_mask */
616 0x0ff00000, /* dst_mask */
617 FALSE), /* pcrel_offset */
618
619 HOWTO (R_ARM_TARGET1, /* type */
620 0, /* rightshift */
621 2, /* size (0 = byte, 1 = short, 2 = long) */
622 32, /* bitsize */
623 FALSE, /* pc_relative */
624 0, /* bitpos */
625 complain_overflow_dont,/* complain_on_overflow */
626 bfd_elf_generic_reloc, /* special_function */
627 "R_ARM_TARGET1", /* name */
628 FALSE, /* partial_inplace */
629 0xffffffff, /* src_mask */
630 0xffffffff, /* dst_mask */
631 FALSE), /* pcrel_offset */
632
633 HOWTO (R_ARM_ROSEGREL32, /* type */
634 0, /* rightshift */
635 2, /* size (0 = byte, 1 = short, 2 = long) */
636 32, /* bitsize */
637 FALSE, /* pc_relative */
638 0, /* bitpos */
639 complain_overflow_dont,/* complain_on_overflow */
640 bfd_elf_generic_reloc, /* special_function */
641 "R_ARM_ROSEGREL32", /* name */
642 FALSE, /* partial_inplace */
643 0xffffffff, /* src_mask */
644 0xffffffff, /* dst_mask */
645 FALSE), /* pcrel_offset */
646
647 HOWTO (R_ARM_V4BX, /* type */
648 0, /* rightshift */
649 2, /* size (0 = byte, 1 = short, 2 = long) */
650 32, /* bitsize */
651 FALSE, /* pc_relative */
652 0, /* bitpos */
653 complain_overflow_dont,/* complain_on_overflow */
654 bfd_elf_generic_reloc, /* special_function */
655 "R_ARM_V4BX", /* name */
656 FALSE, /* partial_inplace */
657 0xffffffff, /* src_mask */
658 0xffffffff, /* dst_mask */
659 FALSE), /* pcrel_offset */
660
661 HOWTO (R_ARM_TARGET2, /* type */
662 0, /* rightshift */
663 2, /* size (0 = byte, 1 = short, 2 = long) */
664 32, /* bitsize */
665 FALSE, /* pc_relative */
666 0, /* bitpos */
667 complain_overflow_signed,/* complain_on_overflow */
668 bfd_elf_generic_reloc, /* special_function */
669 "R_ARM_TARGET2", /* name */
670 FALSE, /* partial_inplace */
671 0xffffffff, /* src_mask */
672 0xffffffff, /* dst_mask */
673 TRUE), /* pcrel_offset */
674
675 HOWTO (R_ARM_PREL31, /* type */
676 0, /* rightshift */
677 2, /* size (0 = byte, 1 = short, 2 = long) */
678 31, /* bitsize */
679 TRUE, /* pc_relative */
680 0, /* bitpos */
681 complain_overflow_signed,/* complain_on_overflow */
682 bfd_elf_generic_reloc, /* special_function */
683 "R_ARM_PREL31", /* name */
684 FALSE, /* partial_inplace */
685 0x7fffffff, /* src_mask */
686 0x7fffffff, /* dst_mask */
687 TRUE), /* pcrel_offset */
688
689 HOWTO (R_ARM_MOVW_ABS_NC, /* type */
690 0, /* rightshift */
691 2, /* size (0 = byte, 1 = short, 2 = long) */
692 16, /* bitsize */
693 FALSE, /* pc_relative */
694 0, /* bitpos */
695 complain_overflow_dont,/* complain_on_overflow */
696 bfd_elf_generic_reloc, /* special_function */
697 "R_ARM_MOVW_ABS_NC", /* name */
698 FALSE, /* partial_inplace */
699 0x0000ffff, /* src_mask */
700 0x0000ffff, /* dst_mask */
701 FALSE), /* pcrel_offset */
702
703 HOWTO (R_ARM_MOVT_ABS, /* type */
704 0, /* rightshift */
705 2, /* size (0 = byte, 1 = short, 2 = long) */
706 16, /* bitsize */
707 FALSE, /* pc_relative */
708 0, /* bitpos */
709 complain_overflow_bitfield,/* complain_on_overflow */
710 bfd_elf_generic_reloc, /* special_function */
711 "R_ARM_MOVT_ABS", /* name */
712 FALSE, /* partial_inplace */
713 0x0000ffff, /* src_mask */
714 0x0000ffff, /* dst_mask */
715 FALSE), /* pcrel_offset */
716
717 HOWTO (R_ARM_MOVW_PREL_NC, /* type */
718 0, /* rightshift */
719 2, /* size (0 = byte, 1 = short, 2 = long) */
720 16, /* bitsize */
721 TRUE, /* pc_relative */
722 0, /* bitpos */
723 complain_overflow_dont,/* complain_on_overflow */
724 bfd_elf_generic_reloc, /* special_function */
725 "R_ARM_MOVW_PREL_NC", /* name */
726 FALSE, /* partial_inplace */
727 0x0000ffff, /* src_mask */
728 0x0000ffff, /* dst_mask */
729 TRUE), /* pcrel_offset */
730
731 HOWTO (R_ARM_MOVT_PREL, /* type */
732 0, /* rightshift */
733 2, /* size (0 = byte, 1 = short, 2 = long) */
734 16, /* bitsize */
735 TRUE, /* pc_relative */
736 0, /* bitpos */
737 complain_overflow_bitfield,/* complain_on_overflow */
738 bfd_elf_generic_reloc, /* special_function */
739 "R_ARM_MOVT_PREL", /* name */
740 FALSE, /* partial_inplace */
741 0x0000ffff, /* src_mask */
742 0x0000ffff, /* dst_mask */
743 TRUE), /* pcrel_offset */
744
745 HOWTO (R_ARM_THM_MOVW_ABS_NC, /* type */
746 0, /* rightshift */
747 2, /* size (0 = byte, 1 = short, 2 = long) */
748 16, /* bitsize */
749 FALSE, /* pc_relative */
750 0, /* bitpos */
751 complain_overflow_dont,/* complain_on_overflow */
752 bfd_elf_generic_reloc, /* special_function */
753 "R_ARM_THM_MOVW_ABS_NC",/* name */
754 FALSE, /* partial_inplace */
755 0x040f70ff, /* src_mask */
756 0x040f70ff, /* dst_mask */
757 FALSE), /* pcrel_offset */
758
759 HOWTO (R_ARM_THM_MOVT_ABS, /* type */
760 0, /* rightshift */
761 2, /* size (0 = byte, 1 = short, 2 = long) */
762 16, /* bitsize */
763 FALSE, /* pc_relative */
764 0, /* bitpos */
765 complain_overflow_bitfield,/* complain_on_overflow */
766 bfd_elf_generic_reloc, /* special_function */
767 "R_ARM_THM_MOVT_ABS", /* name */
768 FALSE, /* partial_inplace */
769 0x040f70ff, /* src_mask */
770 0x040f70ff, /* dst_mask */
771 FALSE), /* pcrel_offset */
772
773 HOWTO (R_ARM_THM_MOVW_PREL_NC,/* type */
774 0, /* rightshift */
775 2, /* size (0 = byte, 1 = short, 2 = long) */
776 16, /* bitsize */
777 TRUE, /* pc_relative */
778 0, /* bitpos */
779 complain_overflow_dont,/* complain_on_overflow */
780 bfd_elf_generic_reloc, /* special_function */
781 "R_ARM_THM_MOVW_PREL_NC",/* name */
782 FALSE, /* partial_inplace */
783 0x040f70ff, /* src_mask */
784 0x040f70ff, /* dst_mask */
785 TRUE), /* pcrel_offset */
786
787 HOWTO (R_ARM_THM_MOVT_PREL, /* type */
788 0, /* rightshift */
789 2, /* size (0 = byte, 1 = short, 2 = long) */
790 16, /* bitsize */
791 TRUE, /* pc_relative */
792 0, /* bitpos */
793 complain_overflow_bitfield,/* complain_on_overflow */
794 bfd_elf_generic_reloc, /* special_function */
795 "R_ARM_THM_MOVT_PREL", /* name */
796 FALSE, /* partial_inplace */
797 0x040f70ff, /* src_mask */
798 0x040f70ff, /* dst_mask */
799 TRUE), /* pcrel_offset */
800
801 HOWTO (R_ARM_THM_JUMP19, /* type */
802 1, /* rightshift */
803 2, /* size (0 = byte, 1 = short, 2 = long) */
804 19, /* bitsize */
805 TRUE, /* pc_relative */
806 0, /* bitpos */
807 complain_overflow_signed,/* complain_on_overflow */
808 bfd_elf_generic_reloc, /* special_function */
809 "R_ARM_THM_JUMP19", /* name */
810 FALSE, /* partial_inplace */
811 0x043f2fff, /* src_mask */
812 0x043f2fff, /* dst_mask */
813 TRUE), /* pcrel_offset */
814
815 HOWTO (R_ARM_THM_JUMP6, /* type */
816 1, /* rightshift */
817 1, /* size (0 = byte, 1 = short, 2 = long) */
818 6, /* bitsize */
819 TRUE, /* pc_relative */
820 0, /* bitpos */
821 complain_overflow_unsigned,/* complain_on_overflow */
822 bfd_elf_generic_reloc, /* special_function */
823 "R_ARM_THM_JUMP6", /* name */
824 FALSE, /* partial_inplace */
825 0x02f8, /* src_mask */
826 0x02f8, /* dst_mask */
827 TRUE), /* pcrel_offset */
828
829 /* These are declared as 13-bit signed relocations because we can
830 address -4095 .. 4095(base) by altering ADDW to SUBW or vice
831 versa. */
832 HOWTO (R_ARM_THM_ALU_PREL_11_0,/* type */
833 0, /* rightshift */
834 2, /* size (0 = byte, 1 = short, 2 = long) */
835 13, /* bitsize */
836 TRUE, /* pc_relative */
837 0, /* bitpos */
838 complain_overflow_signed,/* complain_on_overflow */
839 bfd_elf_generic_reloc, /* special_function */
840 "R_ARM_THM_ALU_PREL_11_0",/* name */
841 FALSE, /* partial_inplace */
842 0x040070ff, /* src_mask */
843 0x040070ff, /* dst_mask */
844 TRUE), /* pcrel_offset */
845
846 HOWTO (R_ARM_THM_PC12, /* type */
847 0, /* rightshift */
848 2, /* size (0 = byte, 1 = short, 2 = long) */
849 13, /* bitsize */
850 TRUE, /* pc_relative */
851 0, /* bitpos */
852 complain_overflow_signed,/* complain_on_overflow */
853 bfd_elf_generic_reloc, /* special_function */
854 "R_ARM_THM_PC12", /* name */
855 FALSE, /* partial_inplace */
856 0x040070ff, /* src_mask */
857 0x040070ff, /* dst_mask */
858 TRUE), /* pcrel_offset */
859
860 HOWTO (R_ARM_ABS32_NOI, /* type */
861 0, /* rightshift */
862 2, /* size (0 = byte, 1 = short, 2 = long) */
863 32, /* bitsize */
864 FALSE, /* pc_relative */
865 0, /* bitpos */
866 complain_overflow_dont,/* complain_on_overflow */
867 bfd_elf_generic_reloc, /* special_function */
868 "R_ARM_ABS32_NOI", /* name */
869 FALSE, /* partial_inplace */
870 0xffffffff, /* src_mask */
871 0xffffffff, /* dst_mask */
872 FALSE), /* pcrel_offset */
873
874 HOWTO (R_ARM_REL32_NOI, /* type */
875 0, /* rightshift */
876 2, /* size (0 = byte, 1 = short, 2 = long) */
877 32, /* bitsize */
878 TRUE, /* pc_relative */
879 0, /* bitpos */
880 complain_overflow_dont,/* complain_on_overflow */
881 bfd_elf_generic_reloc, /* special_function */
882 "R_ARM_REL32_NOI", /* name */
883 FALSE, /* partial_inplace */
884 0xffffffff, /* src_mask */
885 0xffffffff, /* dst_mask */
886 FALSE), /* pcrel_offset */
887 };
888
889 /* Relocations 57 .. 83 are the "group relocations" which we do not
890 support. */
891
892 static reloc_howto_type elf32_arm_howto_table_2[] =
893 {
894 HOWTO (R_ARM_MOVW_BREL_NC, /* type */
895 0, /* rightshift */
896 2, /* size (0 = byte, 1 = short, 2 = long) */
897 16, /* bitsize */
898 FALSE, /* pc_relative */
899 0, /* bitpos */
900 complain_overflow_dont,/* complain_on_overflow */
901 bfd_elf_generic_reloc, /* special_function */
902 "R_ARM_MOVW_BREL_NC", /* name */
903 FALSE, /* partial_inplace */
904 0x0000ffff, /* src_mask */
905 0x0000ffff, /* dst_mask */
906 FALSE), /* pcrel_offset */
907
908 HOWTO (R_ARM_MOVT_BREL, /* type */
909 0, /* rightshift */
910 2, /* size (0 = byte, 1 = short, 2 = long) */
911 16, /* bitsize */
912 FALSE, /* pc_relative */
913 0, /* bitpos */
914 complain_overflow_bitfield,/* complain_on_overflow */
915 bfd_elf_generic_reloc, /* special_function */
916 "R_ARM_MOVT_BREL", /* name */
917 FALSE, /* partial_inplace */
918 0x0000ffff, /* src_mask */
919 0x0000ffff, /* dst_mask */
920 FALSE), /* pcrel_offset */
921
922 HOWTO (R_ARM_MOVW_BREL, /* type */
923 0, /* rightshift */
924 2, /* size (0 = byte, 1 = short, 2 = long) */
925 16, /* bitsize */
926 FALSE, /* pc_relative */
927 0, /* bitpos */
928 complain_overflow_dont,/* complain_on_overflow */
929 bfd_elf_generic_reloc, /* special_function */
930 "R_ARM_MOVW_BREL", /* name */
931 FALSE, /* partial_inplace */
932 0x0000ffff, /* src_mask */
933 0x0000ffff, /* dst_mask */
934 FALSE), /* pcrel_offset */
935
936 HOWTO (R_ARM_THM_MOVW_BREL_NC,/* type */
937 0, /* rightshift */
938 2, /* size (0 = byte, 1 = short, 2 = long) */
939 16, /* bitsize */
940 FALSE, /* pc_relative */
941 0, /* bitpos */
942 complain_overflow_dont,/* complain_on_overflow */
943 bfd_elf_generic_reloc, /* special_function */
944 "R_ARM_THM_MOVW_BREL_NC",/* name */
945 FALSE, /* partial_inplace */
946 0x040f70ff, /* src_mask */
947 0x040f70ff, /* dst_mask */
948 FALSE), /* pcrel_offset */
949
950 HOWTO (R_ARM_THM_MOVT_BREL, /* type */
951 0, /* rightshift */
952 2, /* size (0 = byte, 1 = short, 2 = long) */
953 16, /* bitsize */
954 FALSE, /* pc_relative */
955 0, /* bitpos */
956 complain_overflow_bitfield,/* complain_on_overflow */
957 bfd_elf_generic_reloc, /* special_function */
958 "R_ARM_THM_MOVT_BREL", /* name */
959 FALSE, /* partial_inplace */
960 0x040f70ff, /* src_mask */
961 0x040f70ff, /* dst_mask */
962 FALSE), /* pcrel_offset */
963
964 HOWTO (R_ARM_THM_MOVW_BREL, /* type */
965 0, /* rightshift */
966 2, /* size (0 = byte, 1 = short, 2 = long) */
967 16, /* bitsize */
968 FALSE, /* pc_relative */
969 0, /* bitpos */
970 complain_overflow_dont,/* complain_on_overflow */
971 bfd_elf_generic_reloc, /* special_function */
972 "R_ARM_THM_MOVW_BREL", /* name */
973 FALSE, /* partial_inplace */
974 0x040f70ff, /* src_mask */
975 0x040f70ff, /* dst_mask */
976 FALSE), /* pcrel_offset */
977
978 EMPTY_HOWTO (90), /* unallocated */
979 EMPTY_HOWTO (91),
980 EMPTY_HOWTO (92),
981 EMPTY_HOWTO (93),
982
983 HOWTO (R_ARM_PLT32_ABS, /* type */
984 0, /* rightshift */
985 2, /* size (0 = byte, 1 = short, 2 = long) */
986 32, /* bitsize */
987 FALSE, /* pc_relative */
988 0, /* bitpos */
989 complain_overflow_dont,/* complain_on_overflow */
990 bfd_elf_generic_reloc, /* special_function */
991 "R_ARM_PLT32_ABS", /* name */
992 FALSE, /* partial_inplace */
993 0xffffffff, /* src_mask */
994 0xffffffff, /* dst_mask */
995 FALSE), /* pcrel_offset */
996
997 HOWTO (R_ARM_GOT_ABS, /* type */
998 0, /* rightshift */
999 2, /* size (0 = byte, 1 = short, 2 = long) */
1000 32, /* bitsize */
1001 FALSE, /* pc_relative */
1002 0, /* bitpos */
1003 complain_overflow_dont,/* complain_on_overflow */
1004 bfd_elf_generic_reloc, /* special_function */
1005 "R_ARM_GOT_ABS", /* name */
1006 FALSE, /* partial_inplace */
1007 0xffffffff, /* src_mask */
1008 0xffffffff, /* dst_mask */
1009 FALSE), /* pcrel_offset */
1010
1011 HOWTO (R_ARM_GOT_PREL, /* type */
1012 0, /* rightshift */
1013 2, /* size (0 = byte, 1 = short, 2 = long) */
1014 32, /* bitsize */
1015 TRUE, /* pc_relative */
1016 0, /* bitpos */
1017 complain_overflow_dont, /* complain_on_overflow */
1018 bfd_elf_generic_reloc, /* special_function */
1019 "R_ARM_GOT_PREL", /* name */
1020 FALSE, /* partial_inplace */
1021 0xffffffff, /* src_mask */
1022 0xffffffff, /* dst_mask */
1023 TRUE), /* pcrel_offset */
1024
1025 HOWTO (R_ARM_GOT_BREL12, /* type */
1026 0, /* rightshift */
1027 2, /* size (0 = byte, 1 = short, 2 = long) */
1028 12, /* bitsize */
1029 FALSE, /* pc_relative */
1030 0, /* bitpos */
1031 complain_overflow_bitfield,/* complain_on_overflow */
1032 bfd_elf_generic_reloc, /* special_function */
1033 "R_ARM_GOT_BREL12", /* name */
1034 FALSE, /* partial_inplace */
1035 0x00000fff, /* src_mask */
1036 0x00000fff, /* dst_mask */
1037 FALSE), /* pcrel_offset */
1038
1039 HOWTO (R_ARM_GOTOFF12, /* type */
1040 0, /* rightshift */
1041 2, /* size (0 = byte, 1 = short, 2 = long) */
1042 12, /* bitsize */
1043 FALSE, /* pc_relative */
1044 0, /* bitpos */
1045 complain_overflow_bitfield,/* complain_on_overflow */
1046 bfd_elf_generic_reloc, /* special_function */
1047 "R_ARM_GOTOFF12", /* name */
1048 FALSE, /* partial_inplace */
1049 0x00000fff, /* src_mask */
1050 0x00000fff, /* dst_mask */
1051 FALSE), /* pcrel_offset */
1052
1053 EMPTY_HOWTO (R_ARM_GOTRELAX), /* reserved for future GOT-load optimizations */
1054
1055 /* GNU extension to record C++ vtable member usage */
1056 HOWTO (R_ARM_GNU_VTENTRY, /* type */
1057 0, /* rightshift */
1058 2, /* size (0 = byte, 1 = short, 2 = long) */
1059 0, /* bitsize */
1060 FALSE, /* pc_relative */
1061 0, /* bitpos */
1062 complain_overflow_dont, /* complain_on_overflow */
1063 _bfd_elf_rel_vtable_reloc_fn, /* special_function */
1064 "R_ARM_GNU_VTENTRY", /* name */
1065 FALSE, /* partial_inplace */
1066 0, /* src_mask */
1067 0, /* dst_mask */
1068 FALSE), /* pcrel_offset */
1069
1070 /* GNU extension to record C++ vtable hierarchy */
1071 HOWTO (R_ARM_GNU_VTINHERIT, /* type */
1072 0, /* rightshift */
1073 2, /* size (0 = byte, 1 = short, 2 = long) */
1074 0, /* bitsize */
1075 FALSE, /* pc_relative */
1076 0, /* bitpos */
1077 complain_overflow_dont, /* complain_on_overflow */
1078 NULL, /* special_function */
1079 "R_ARM_GNU_VTINHERIT", /* name */
1080 FALSE, /* partial_inplace */
1081 0, /* src_mask */
1082 0, /* dst_mask */
1083 FALSE), /* pcrel_offset */
1084
1085 HOWTO (R_ARM_THM_JUMP11, /* type */
1086 1, /* rightshift */
1087 1, /* size (0 = byte, 1 = short, 2 = long) */
1088 11, /* bitsize */
1089 TRUE, /* pc_relative */
1090 0, /* bitpos */
1091 complain_overflow_signed, /* complain_on_overflow */
1092 bfd_elf_generic_reloc, /* special_function */
1093 "R_ARM_THM_JUMP11", /* name */
1094 FALSE, /* partial_inplace */
1095 0x000007ff, /* src_mask */
1096 0x000007ff, /* dst_mask */
1097 TRUE), /* pcrel_offset */
1098
1099 HOWTO (R_ARM_THM_JUMP8, /* type */
1100 1, /* rightshift */
1101 1, /* size (0 = byte, 1 = short, 2 = long) */
1102 8, /* bitsize */
1103 TRUE, /* pc_relative */
1104 0, /* bitpos */
1105 complain_overflow_signed, /* complain_on_overflow */
1106 bfd_elf_generic_reloc, /* special_function */
1107 "R_ARM_THM_JUMP8", /* name */
1108 FALSE, /* partial_inplace */
1109 0x000000ff, /* src_mask */
1110 0x000000ff, /* dst_mask */
1111 TRUE), /* pcrel_offset */
1112
1113 /* TLS relocations */
1114 HOWTO (R_ARM_TLS_GD32, /* type */
1115 0, /* rightshift */
1116 2, /* size (0 = byte, 1 = short, 2 = long) */
1117 32, /* bitsize */
1118 FALSE, /* pc_relative */
1119 0, /* bitpos */
1120 complain_overflow_bitfield,/* complain_on_overflow */
1121 NULL, /* special_function */
1122 "R_ARM_TLS_GD32", /* name */
1123 TRUE, /* partial_inplace */
1124 0xffffffff, /* src_mask */
1125 0xffffffff, /* dst_mask */
1126 FALSE), /* pcrel_offset */
1127
1128 HOWTO (R_ARM_TLS_LDM32, /* type */
1129 0, /* rightshift */
1130 2, /* size (0 = byte, 1 = short, 2 = long) */
1131 32, /* bitsize */
1132 FALSE, /* pc_relative */
1133 0, /* bitpos */
1134 complain_overflow_bitfield,/* complain_on_overflow */
1135 bfd_elf_generic_reloc, /* special_function */
1136 "R_ARM_TLS_LDM32", /* name */
1137 TRUE, /* partial_inplace */
1138 0xffffffff, /* src_mask */
1139 0xffffffff, /* dst_mask */
1140 FALSE), /* pcrel_offset */
1141
1142 HOWTO (R_ARM_TLS_LDO32, /* type */
1143 0, /* rightshift */
1144 2, /* size (0 = byte, 1 = short, 2 = long) */
1145 32, /* bitsize */
1146 FALSE, /* pc_relative */
1147 0, /* bitpos */
1148 complain_overflow_bitfield,/* complain_on_overflow */
1149 bfd_elf_generic_reloc, /* special_function */
1150 "R_ARM_TLS_LDO32", /* name */
1151 TRUE, /* partial_inplace */
1152 0xffffffff, /* src_mask */
1153 0xffffffff, /* dst_mask */
1154 FALSE), /* pcrel_offset */
1155
1156 HOWTO (R_ARM_TLS_IE32, /* type */
1157 0, /* rightshift */
1158 2, /* size (0 = byte, 1 = short, 2 = long) */
1159 32, /* bitsize */
1160 FALSE, /* pc_relative */
1161 0, /* bitpos */
1162 complain_overflow_bitfield,/* complain_on_overflow */
1163 NULL, /* special_function */
1164 "R_ARM_TLS_IE32", /* name */
1165 TRUE, /* partial_inplace */
1166 0xffffffff, /* src_mask */
1167 0xffffffff, /* dst_mask */
1168 FALSE), /* pcrel_offset */
1169
1170 HOWTO (R_ARM_TLS_LE32, /* type */
1171 0, /* rightshift */
1172 2, /* size (0 = byte, 1 = short, 2 = long) */
1173 32, /* bitsize */
1174 FALSE, /* pc_relative */
1175 0, /* bitpos */
1176 complain_overflow_bitfield,/* complain_on_overflow */
1177 bfd_elf_generic_reloc, /* special_function */
1178 "R_ARM_TLS_LE32", /* name */
1179 TRUE, /* partial_inplace */
1180 0xffffffff, /* src_mask */
1181 0xffffffff, /* dst_mask */
1182 FALSE), /* pcrel_offset */
1183
1184 HOWTO (R_ARM_TLS_LDO12, /* type */
1185 0, /* rightshift */
1186 2, /* size (0 = byte, 1 = short, 2 = long) */
1187 12, /* bitsize */
1188 FALSE, /* pc_relative */
1189 0, /* bitpos */
1190 complain_overflow_bitfield,/* complain_on_overflow */
1191 bfd_elf_generic_reloc, /* special_function */
1192 "R_ARM_TLS_LDO12", /* name */
1193 FALSE, /* partial_inplace */
1194 0x00000fff, /* src_mask */
1195 0x00000fff, /* dst_mask */
1196 FALSE), /* pcrel_offset */
1197
1198 HOWTO (R_ARM_TLS_LE12, /* type */
1199 0, /* rightshift */
1200 2, /* size (0 = byte, 1 = short, 2 = long) */
1201 12, /* bitsize */
1202 FALSE, /* pc_relative */
1203 0, /* bitpos */
1204 complain_overflow_bitfield,/* complain_on_overflow */
1205 bfd_elf_generic_reloc, /* special_function */
1206 "R_ARM_TLS_LE12", /* name */
1207 FALSE, /* partial_inplace */
1208 0x00000fff, /* src_mask */
1209 0x00000fff, /* dst_mask */
1210 FALSE), /* pcrel_offset */
1211
1212 HOWTO (R_ARM_TLS_IE12GP, /* type */
1213 0, /* rightshift */
1214 2, /* size (0 = byte, 1 = short, 2 = long) */
1215 12, /* bitsize */
1216 FALSE, /* pc_relative */
1217 0, /* bitpos */
1218 complain_overflow_bitfield,/* complain_on_overflow */
1219 bfd_elf_generic_reloc, /* special_function */
1220 "R_ARM_TLS_IE12GP", /* name */
1221 FALSE, /* partial_inplace */
1222 0x00000fff, /* src_mask */
1223 0x00000fff, /* dst_mask */
1224 FALSE), /* pcrel_offset */
1225 };
1226
1227 /* 112-127 private relocations
1228 128 R_ARM_ME_TOO, obsolete
1229 129-255 unallocated in AAELF.
1230
1231 249-255 extended, currently unused, relocations: */
1232
1233 static reloc_howto_type elf32_arm_howto_table_3[4] =
1234 {
1235 HOWTO (R_ARM_RREL32, /* type */
1236 0, /* rightshift */
1237 0, /* size (0 = byte, 1 = short, 2 = long) */
1238 0, /* bitsize */
1239 FALSE, /* pc_relative */
1240 0, /* bitpos */
1241 complain_overflow_dont,/* complain_on_overflow */
1242 bfd_elf_generic_reloc, /* special_function */
1243 "R_ARM_RREL32", /* name */
1244 FALSE, /* partial_inplace */
1245 0, /* src_mask */
1246 0, /* dst_mask */
1247 FALSE), /* pcrel_offset */
1248
1249 HOWTO (R_ARM_RABS32, /* type */
1250 0, /* rightshift */
1251 0, /* size (0 = byte, 1 = short, 2 = long) */
1252 0, /* bitsize */
1253 FALSE, /* pc_relative */
1254 0, /* bitpos */
1255 complain_overflow_dont,/* complain_on_overflow */
1256 bfd_elf_generic_reloc, /* special_function */
1257 "R_ARM_RABS32", /* name */
1258 FALSE, /* partial_inplace */
1259 0, /* src_mask */
1260 0, /* dst_mask */
1261 FALSE), /* pcrel_offset */
1262
1263 HOWTO (R_ARM_RPC24, /* type */
1264 0, /* rightshift */
1265 0, /* size (0 = byte, 1 = short, 2 = long) */
1266 0, /* bitsize */
1267 FALSE, /* pc_relative */
1268 0, /* bitpos */
1269 complain_overflow_dont,/* complain_on_overflow */
1270 bfd_elf_generic_reloc, /* special_function */
1271 "R_ARM_RPC24", /* name */
1272 FALSE, /* partial_inplace */
1273 0, /* src_mask */
1274 0, /* dst_mask */
1275 FALSE), /* pcrel_offset */
1276
1277 HOWTO (R_ARM_RBASE, /* type */
1278 0, /* rightshift */
1279 0, /* size (0 = byte, 1 = short, 2 = long) */
1280 0, /* bitsize */
1281 FALSE, /* pc_relative */
1282 0, /* bitpos */
1283 complain_overflow_dont,/* complain_on_overflow */
1284 bfd_elf_generic_reloc, /* special_function */
1285 "R_ARM_RBASE", /* name */
1286 FALSE, /* partial_inplace */
1287 0, /* src_mask */
1288 0, /* dst_mask */
1289 FALSE) /* pcrel_offset */
1290 };
1291
1292 static reloc_howto_type *
elf32_arm_howto_from_type(unsigned int r_type)1293 elf32_arm_howto_from_type (unsigned int r_type)
1294 {
1295 if (r_type < NUM_ELEM (elf32_arm_howto_table_1))
1296 return &elf32_arm_howto_table_1[r_type];
1297
1298 if (r_type >= R_ARM_MOVW_BREL_NC
1299 && r_type < R_ARM_MOVW_BREL_NC + NUM_ELEM (elf32_arm_howto_table_2))
1300 return &elf32_arm_howto_table_2[r_type - R_ARM_MOVW_BREL_NC];
1301
1302 if (r_type >= R_ARM_RREL32
1303 && r_type < R_ARM_RREL32 + NUM_ELEM (elf32_arm_howto_table_2))
1304 return &elf32_arm_howto_table_3[r_type - R_ARM_RREL32];
1305
1306 return NULL;
1307 }
1308
1309 static void
elf32_arm_info_to_howto(bfd * abfd ATTRIBUTE_UNUSED,arelent * bfd_reloc,Elf_Internal_Rela * elf_reloc)1310 elf32_arm_info_to_howto (bfd * abfd ATTRIBUTE_UNUSED, arelent * bfd_reloc,
1311 Elf_Internal_Rela * elf_reloc)
1312 {
1313 unsigned int r_type;
1314
1315 r_type = ELF32_R_TYPE (elf_reloc->r_info);
1316 bfd_reloc->howto = elf32_arm_howto_from_type (r_type);
1317 }
1318
1319 struct elf32_arm_reloc_map
1320 {
1321 bfd_reloc_code_real_type bfd_reloc_val;
1322 unsigned char elf_reloc_val;
1323 };
1324
1325 /* All entries in this list must also be present in elf32_arm_howto_table. */
1326 static const struct elf32_arm_reloc_map elf32_arm_reloc_map[] =
1327 {
1328 {BFD_RELOC_NONE, R_ARM_NONE},
1329 {BFD_RELOC_ARM_PCREL_BRANCH, R_ARM_PC24},
1330 {BFD_RELOC_ARM_PCREL_CALL, R_ARM_CALL},
1331 {BFD_RELOC_ARM_PCREL_JUMP, R_ARM_JUMP24},
1332 {BFD_RELOC_ARM_PCREL_BLX, R_ARM_XPC25},
1333 {BFD_RELOC_THUMB_PCREL_BLX, R_ARM_THM_XPC22},
1334 {BFD_RELOC_32, R_ARM_ABS32},
1335 {BFD_RELOC_32_PCREL, R_ARM_REL32},
1336 {BFD_RELOC_8, R_ARM_ABS8},
1337 {BFD_RELOC_16, R_ARM_ABS16},
1338 {BFD_RELOC_ARM_OFFSET_IMM, R_ARM_ABS12},
1339 {BFD_RELOC_ARM_THUMB_OFFSET, R_ARM_THM_ABS5},
1340 {BFD_RELOC_THUMB_PCREL_BRANCH25, R_ARM_THM_JUMP24},
1341 {BFD_RELOC_THUMB_PCREL_BRANCH23, R_ARM_THM_CALL},
1342 {BFD_RELOC_THUMB_PCREL_BRANCH12, R_ARM_THM_JUMP11},
1343 {BFD_RELOC_THUMB_PCREL_BRANCH20, R_ARM_THM_JUMP19},
1344 {BFD_RELOC_THUMB_PCREL_BRANCH9, R_ARM_THM_JUMP8},
1345 {BFD_RELOC_THUMB_PCREL_BRANCH7, R_ARM_THM_JUMP6},
1346 {BFD_RELOC_ARM_GLOB_DAT, R_ARM_GLOB_DAT},
1347 {BFD_RELOC_ARM_JUMP_SLOT, R_ARM_JUMP_SLOT},
1348 {BFD_RELOC_ARM_RELATIVE, R_ARM_RELATIVE},
1349 {BFD_RELOC_ARM_GOTOFF, R_ARM_GOTOFF32},
1350 {BFD_RELOC_ARM_GOTPC, R_ARM_GOTPC},
1351 {BFD_RELOC_ARM_GOT32, R_ARM_GOT32},
1352 {BFD_RELOC_ARM_PLT32, R_ARM_PLT32},
1353 {BFD_RELOC_ARM_TARGET1, R_ARM_TARGET1},
1354 {BFD_RELOC_ARM_ROSEGREL32, R_ARM_ROSEGREL32},
1355 {BFD_RELOC_ARM_SBREL32, R_ARM_SBREL32},
1356 {BFD_RELOC_ARM_PREL31, R_ARM_PREL31},
1357 {BFD_RELOC_ARM_TARGET2, R_ARM_TARGET2},
1358 {BFD_RELOC_ARM_PLT32, R_ARM_PLT32},
1359 {BFD_RELOC_ARM_TLS_GD32, R_ARM_TLS_GD32},
1360 {BFD_RELOC_ARM_TLS_LDO32, R_ARM_TLS_LDO32},
1361 {BFD_RELOC_ARM_TLS_LDM32, R_ARM_TLS_LDM32},
1362 {BFD_RELOC_ARM_TLS_DTPMOD32, R_ARM_TLS_DTPMOD32},
1363 {BFD_RELOC_ARM_TLS_DTPOFF32, R_ARM_TLS_DTPOFF32},
1364 {BFD_RELOC_ARM_TLS_TPOFF32, R_ARM_TLS_TPOFF32},
1365 {BFD_RELOC_ARM_TLS_IE32, R_ARM_TLS_IE32},
1366 {BFD_RELOC_ARM_TLS_LE32, R_ARM_TLS_LE32},
1367 {BFD_RELOC_VTABLE_INHERIT, R_ARM_GNU_VTINHERIT},
1368 {BFD_RELOC_VTABLE_ENTRY, R_ARM_GNU_VTENTRY},
1369 {BFD_RELOC_ARM_MOVW, R_ARM_MOVW_ABS_NC},
1370 {BFD_RELOC_ARM_MOVT, R_ARM_MOVT_ABS},
1371 {BFD_RELOC_ARM_MOVW_PCREL, R_ARM_MOVW_PREL_NC},
1372 {BFD_RELOC_ARM_MOVT_PCREL, R_ARM_MOVT_PREL},
1373 {BFD_RELOC_ARM_THUMB_MOVW, R_ARM_THM_MOVW_ABS_NC},
1374 {BFD_RELOC_ARM_THUMB_MOVT, R_ARM_THM_MOVT_ABS},
1375 {BFD_RELOC_ARM_THUMB_MOVW_PCREL, R_ARM_THM_MOVW_PREL_NC},
1376 {BFD_RELOC_ARM_THUMB_MOVT_PCREL, R_ARM_THM_MOVT_PREL},
1377 };
1378
1379 static reloc_howto_type *
elf32_arm_reloc_type_lookup(bfd * abfd ATTRIBUTE_UNUSED,bfd_reloc_code_real_type code)1380 elf32_arm_reloc_type_lookup (bfd *abfd ATTRIBUTE_UNUSED,
1381 bfd_reloc_code_real_type code)
1382 {
1383 unsigned int i;
1384 for (i = 0; i < NUM_ELEM (elf32_arm_reloc_map); i ++)
1385 if (elf32_arm_reloc_map[i].bfd_reloc_val == code)
1386 return elf32_arm_howto_from_type (elf32_arm_reloc_map[i].elf_reloc_val);
1387
1388 return NULL;
1389 }
1390
1391 /* Support for core dump NOTE sections */
1392 static bfd_boolean
elf32_arm_nabi_grok_prstatus(bfd * abfd,Elf_Internal_Note * note)1393 elf32_arm_nabi_grok_prstatus (bfd *abfd, Elf_Internal_Note *note)
1394 {
1395 int offset;
1396 size_t size;
1397
1398 switch (note->descsz)
1399 {
1400 default:
1401 return FALSE;
1402
1403 case 148: /* Linux/ARM 32-bit*/
1404 /* pr_cursig */
1405 elf_tdata (abfd)->core_signal = bfd_get_16 (abfd, note->descdata + 12);
1406
1407 /* pr_pid */
1408 elf_tdata (abfd)->core_pid = bfd_get_32 (abfd, note->descdata + 24);
1409
1410 /* pr_reg */
1411 offset = 72;
1412 size = 72;
1413
1414 break;
1415 }
1416
1417 /* Make a ".reg/999" section. */
1418 return _bfd_elfcore_make_pseudosection (abfd, ".reg",
1419 size, note->descpos + offset);
1420 }
1421
1422 static bfd_boolean
elf32_arm_nabi_grok_psinfo(bfd * abfd,Elf_Internal_Note * note)1423 elf32_arm_nabi_grok_psinfo (bfd *abfd, Elf_Internal_Note *note)
1424 {
1425 switch (note->descsz)
1426 {
1427 default:
1428 return FALSE;
1429
1430 case 124: /* Linux/ARM elf_prpsinfo */
1431 elf_tdata (abfd)->core_program
1432 = _bfd_elfcore_strndup (abfd, note->descdata + 28, 16);
1433 elf_tdata (abfd)->core_command
1434 = _bfd_elfcore_strndup (abfd, note->descdata + 44, 80);
1435 }
1436
1437 /* Note that for some reason, a spurious space is tacked
1438 onto the end of the args in some (at least one anyway)
1439 implementations, so strip it off if it exists. */
1440
1441 {
1442 char *command = elf_tdata (abfd)->core_command;
1443 int n = strlen (command);
1444
1445 if (0 < n && command[n - 1] == ' ')
1446 command[n - 1] = '\0';
1447 }
1448
1449 return TRUE;
1450 }
1451
1452 #define TARGET_LITTLE_SYM bfd_elf32_littlearm_vec
1453 #define TARGET_LITTLE_NAME "elf32-littlearm"
1454 #define TARGET_BIG_SYM bfd_elf32_bigarm_vec
1455 #define TARGET_BIG_NAME "elf32-bigarm"
1456
1457 #define elf_backend_grok_prstatus elf32_arm_nabi_grok_prstatus
1458 #define elf_backend_grok_psinfo elf32_arm_nabi_grok_psinfo
1459
1460 typedef unsigned long int insn32;
1461 typedef unsigned short int insn16;
1462
1463 /* In lieu of proper flags, assume all EABIv4 or later objects are
1464 interworkable. */
1465 #define INTERWORK_FLAG(abfd) \
1466 (EF_ARM_EABI_VERSION (elf_elfheader (abfd)->e_flags) >= EF_ARM_EABI_VER4 \
1467 || (elf_elfheader (abfd)->e_flags & EF_ARM_INTERWORK))
1468
1469 /* The linker script knows the section names for placement.
1470 The entry_names are used to do simple name mangling on the stubs.
1471 Given a function name, and its type, the stub can be found. The
1472 name can be changed. The only requirement is the %s be present. */
1473 #define THUMB2ARM_GLUE_SECTION_NAME ".glue_7t"
1474 #define THUMB2ARM_GLUE_ENTRY_NAME "__%s_from_thumb"
1475
1476 #define ARM2THUMB_GLUE_SECTION_NAME ".glue_7"
1477 #define ARM2THUMB_GLUE_ENTRY_NAME "__%s_from_arm"
1478
1479 /* The name of the dynamic interpreter. This is put in the .interp
1480 section. */
1481 #define ELF_DYNAMIC_INTERPRETER "/usr/lib/ld.so.1"
1482
1483 #ifdef FOUR_WORD_PLT
1484
1485 /* The first entry in a procedure linkage table looks like
1486 this. It is set up so that any shared library function that is
1487 called before the relocation has been set up calls the dynamic
1488 linker first. */
1489 static const bfd_vma elf32_arm_plt0_entry [] =
1490 {
1491 0xe52de004, /* str lr, [sp, #-4]! */
1492 0xe59fe010, /* ldr lr, [pc, #16] */
1493 0xe08fe00e, /* add lr, pc, lr */
1494 0xe5bef008, /* ldr pc, [lr, #8]! */
1495 };
1496
1497 /* Subsequent entries in a procedure linkage table look like
1498 this. */
1499 static const bfd_vma elf32_arm_plt_entry [] =
1500 {
1501 0xe28fc600, /* add ip, pc, #NN */
1502 0xe28cca00, /* add ip, ip, #NN */
1503 0xe5bcf000, /* ldr pc, [ip, #NN]! */
1504 0x00000000, /* unused */
1505 };
1506
1507 #else
1508
1509 /* The first entry in a procedure linkage table looks like
1510 this. It is set up so that any shared library function that is
1511 called before the relocation has been set up calls the dynamic
1512 linker first. */
1513 static const bfd_vma elf32_arm_plt0_entry [] =
1514 {
1515 0xe52de004, /* str lr, [sp, #-4]! */
1516 0xe59fe004, /* ldr lr, [pc, #4] */
1517 0xe08fe00e, /* add lr, pc, lr */
1518 0xe5bef008, /* ldr pc, [lr, #8]! */
1519 0x00000000, /* &GOT[0] - . */
1520 };
1521
1522 /* Subsequent entries in a procedure linkage table look like
1523 this. */
1524 static const bfd_vma elf32_arm_plt_entry [] =
1525 {
1526 0xe28fc600, /* add ip, pc, #0xNN00000 */
1527 0xe28cca00, /* add ip, ip, #0xNN000 */
1528 0xe5bcf000, /* ldr pc, [ip, #0xNNN]! */
1529 };
1530
1531 #endif
1532
1533 /* The format of the first entry in the procedure linkage table
1534 for a VxWorks executable. */
1535 static const bfd_vma elf32_arm_vxworks_exec_plt0_entry[] =
1536 {
1537 0xe52dc008, /* str ip,[sp,#-8]! */
1538 0xe59fc000, /* ldr ip,[pc] */
1539 0xe59cf008, /* ldr pc,[ip,#8] */
1540 0x00000000, /* .long _GLOBAL_OFFSET_TABLE_ */
1541 };
1542
1543 /* The format of subsequent entries in a VxWorks executable. */
1544 static const bfd_vma elf32_arm_vxworks_exec_plt_entry[] =
1545 {
1546 0xe59fc000, /* ldr ip,[pc] */
1547 0xe59cf000, /* ldr pc,[ip] */
1548 0x00000000, /* .long @got */
1549 0xe59fc000, /* ldr ip,[pc] */
1550 0xea000000, /* b _PLT */
1551 0x00000000, /* .long @pltindex*sizeof(Elf32_Rela) */
1552 };
1553
1554 /* The format of entries in a VxWorks shared library. */
1555 static const bfd_vma elf32_arm_vxworks_shared_plt_entry[] =
1556 {
1557 0xe59fc000, /* ldr ip,[pc] */
1558 0xe79cf009, /* ldr pc,[ip,r9] */
1559 0x00000000, /* .long @got */
1560 0xe59fc000, /* ldr ip,[pc] */
1561 0xe599f008, /* ldr pc,[r9,#8] */
1562 0x00000000, /* .long @pltindex*sizeof(Elf32_Rela) */
1563 };
1564
1565 /* An initial stub used if the PLT entry is referenced from Thumb code. */
1566 #define PLT_THUMB_STUB_SIZE 4
1567 static const bfd_vma elf32_arm_plt_thumb_stub [] =
1568 {
1569 0x4778, /* bx pc */
1570 0x46c0 /* nop */
1571 };
1572
1573 /* The entries in a PLT when using a DLL-based target with multiple
1574 address spaces. */
1575 static const bfd_vma elf32_arm_symbian_plt_entry [] =
1576 {
1577 0xe51ff004, /* ldr pc, [pc, #-4] */
1578 0x00000000, /* dcd R_ARM_GLOB_DAT(X) */
1579 };
1580
1581 /* Used to build a map of a section. This is required for mixed-endian
1582 code/data. */
1583
1584 typedef struct elf32_elf_section_map
1585 {
1586 bfd_vma vma;
1587 char type;
1588 }
1589 elf32_arm_section_map;
1590
1591 typedef struct _arm_elf_section_data
1592 {
1593 struct bfd_elf_section_data elf;
1594 unsigned int mapcount;
1595 elf32_arm_section_map *map;
1596 }
1597 _arm_elf_section_data;
1598
1599 #define elf32_arm_section_data(sec) \
1600 ((_arm_elf_section_data *) elf_section_data (sec))
1601
1602 /* The size of the thread control block. */
1603 #define TCB_SIZE 8
1604
1605 #define NUM_KNOWN_ATTRIBUTES 32
1606
1607 typedef struct aeabi_attribute
1608 {
1609 int type;
1610 unsigned int i;
1611 char *s;
1612 } aeabi_attribute;
1613
1614 typedef struct aeabi_attribute_list
1615 {
1616 struct aeabi_attribute_list *next;
1617 int tag;
1618 aeabi_attribute attr;
1619 } aeabi_attribute_list;
1620
1621 struct elf32_arm_obj_tdata
1622 {
1623 struct elf_obj_tdata root;
1624
1625 /* tls_type for each local got entry. */
1626 char *local_got_tls_type;
1627
1628 aeabi_attribute known_eabi_attributes[NUM_KNOWN_ATTRIBUTES];
1629 aeabi_attribute_list *other_eabi_attributes;
1630 };
1631
1632 #define elf32_arm_tdata(abfd) \
1633 ((struct elf32_arm_obj_tdata *) (abfd)->tdata.any)
1634
1635 #define elf32_arm_local_got_tls_type(abfd) \
1636 (elf32_arm_tdata (abfd)->local_got_tls_type)
1637
1638 static bfd_boolean
elf32_arm_mkobject(bfd * abfd)1639 elf32_arm_mkobject (bfd *abfd)
1640 {
1641 bfd_size_type amt = sizeof (struct elf32_arm_obj_tdata);
1642 abfd->tdata.any = bfd_zalloc (abfd, amt);
1643 if (abfd->tdata.any == NULL)
1644 return FALSE;
1645 return TRUE;
1646 }
1647
1648 /* The ARM linker needs to keep track of the number of relocs that it
1649 decides to copy in check_relocs for each symbol. This is so that
1650 it can discard PC relative relocs if it doesn't need them when
1651 linking with -Bsymbolic. We store the information in a field
1652 extending the regular ELF linker hash table. */
1653
1654 /* This structure keeps track of the number of relocs we have copied
1655 for a given symbol. */
1656 struct elf32_arm_relocs_copied
1657 {
1658 /* Next section. */
1659 struct elf32_arm_relocs_copied * next;
1660 /* A section in dynobj. */
1661 asection * section;
1662 /* Number of relocs copied in this section. */
1663 bfd_size_type count;
1664 /* Number of PC-relative relocs copied in this section. */
1665 bfd_size_type pc_count;
1666 };
1667
1668 #define elf32_arm_hash_entry(ent) ((struct elf32_arm_link_hash_entry *)(ent))
1669
1670 /* Arm ELF linker hash entry. */
1671 struct elf32_arm_link_hash_entry
1672 {
1673 struct elf_link_hash_entry root;
1674
1675 /* Number of PC relative relocs copied for this symbol. */
1676 struct elf32_arm_relocs_copied * relocs_copied;
1677
1678 /* We reference count Thumb references to a PLT entry separately,
1679 so that we can emit the Thumb trampoline only if needed. */
1680 bfd_signed_vma plt_thumb_refcount;
1681
1682 /* Since PLT entries have variable size if the Thumb prologue is
1683 used, we need to record the index into .got.plt instead of
1684 recomputing it from the PLT offset. */
1685 bfd_signed_vma plt_got_offset;
1686
1687 #define GOT_UNKNOWN 0
1688 #define GOT_NORMAL 1
1689 #define GOT_TLS_GD 2
1690 #define GOT_TLS_IE 4
1691 unsigned char tls_type;
1692 };
1693
1694 /* Traverse an arm ELF linker hash table. */
1695 #define elf32_arm_link_hash_traverse(table, func, info) \
1696 (elf_link_hash_traverse \
1697 (&(table)->root, \
1698 (bfd_boolean (*) (struct elf_link_hash_entry *, void *)) (func), \
1699 (info)))
1700
1701 /* Get the ARM elf linker hash table from a link_info structure. */
1702 #define elf32_arm_hash_table(info) \
1703 ((struct elf32_arm_link_hash_table *) ((info)->hash))
1704
1705 /* ARM ELF linker hash table. */
1706 struct elf32_arm_link_hash_table
1707 {
1708 /* The main hash table. */
1709 struct elf_link_hash_table root;
1710
1711 /* The size in bytes of the section containing the Thumb-to-ARM glue. */
1712 bfd_size_type thumb_glue_size;
1713
1714 /* The size in bytes of the section containing the ARM-to-Thumb glue. */
1715 bfd_size_type arm_glue_size;
1716
1717 /* An arbitrary input BFD chosen to hold the glue sections. */
1718 bfd * bfd_of_glue_owner;
1719
1720 /* Nonzero to output a BE8 image. */
1721 int byteswap_code;
1722
1723 /* Zero if R_ARM_TARGET1 means R_ARM_ABS32.
1724 Nonzero if R_ARM_TARGET1 means R_ARM_ABS32. */
1725 int target1_is_rel;
1726
1727 /* The relocation to use for R_ARM_TARGET2 relocations. */
1728 int target2_reloc;
1729
1730 /* Nonzero to fix BX instructions for ARMv4 targets. */
1731 int fix_v4bx;
1732
1733 /* Nonzero if the ARM/Thumb BLX instructions are available for use. */
1734 int use_blx;
1735
1736 /* The number of bytes in the initial entry in the PLT. */
1737 bfd_size_type plt_header_size;
1738
1739 /* The number of bytes in the subsequent PLT etries. */
1740 bfd_size_type plt_entry_size;
1741
1742 /* True if the target system is VxWorks. */
1743 int vxworks_p;
1744
1745 /* True if the target system is Symbian OS. */
1746 int symbian_p;
1747
1748 /* True if the target uses REL relocations. */
1749 int use_rel;
1750
1751 /* Short-cuts to get to dynamic linker sections. */
1752 asection *sgot;
1753 asection *sgotplt;
1754 asection *srelgot;
1755 asection *splt;
1756 asection *srelplt;
1757 asection *sdynbss;
1758 asection *srelbss;
1759
1760 /* The (unloaded but important) VxWorks .rela.plt.unloaded section. */
1761 asection *srelplt2;
1762
1763 /* Data for R_ARM_TLS_LDM32 relocations. */
1764 union {
1765 bfd_signed_vma refcount;
1766 bfd_vma offset;
1767 } tls_ldm_got;
1768
1769 /* Small local sym to section mapping cache. */
1770 struct sym_sec_cache sym_sec;
1771
1772 /* For convenience in allocate_dynrelocs. */
1773 bfd * obfd;
1774 };
1775
1776 /* Create an entry in an ARM ELF linker hash table. */
1777
1778 static struct bfd_hash_entry *
elf32_arm_link_hash_newfunc(struct bfd_hash_entry * entry,struct bfd_hash_table * table,const char * string)1779 elf32_arm_link_hash_newfunc (struct bfd_hash_entry * entry,
1780 struct bfd_hash_table * table,
1781 const char * string)
1782 {
1783 struct elf32_arm_link_hash_entry * ret =
1784 (struct elf32_arm_link_hash_entry *) entry;
1785
1786 /* Allocate the structure if it has not already been allocated by a
1787 subclass. */
1788 if (ret == (struct elf32_arm_link_hash_entry *) NULL)
1789 ret = bfd_hash_allocate (table, sizeof (struct elf32_arm_link_hash_entry));
1790 if (ret == NULL)
1791 return (struct bfd_hash_entry *) ret;
1792
1793 /* Call the allocation method of the superclass. */
1794 ret = ((struct elf32_arm_link_hash_entry *)
1795 _bfd_elf_link_hash_newfunc ((struct bfd_hash_entry *) ret,
1796 table, string));
1797 if (ret != NULL)
1798 {
1799 ret->relocs_copied = NULL;
1800 ret->tls_type = GOT_UNKNOWN;
1801 ret->plt_thumb_refcount = 0;
1802 ret->plt_got_offset = -1;
1803 }
1804
1805 return (struct bfd_hash_entry *) ret;
1806 }
1807
1808 /* Return true if NAME is the name of the relocation section associated
1809 with S. */
1810
1811 static bfd_boolean
reloc_section_p(struct elf32_arm_link_hash_table * htab,const char * name,asection * s)1812 reloc_section_p (struct elf32_arm_link_hash_table *htab,
1813 const char *name, asection *s)
1814 {
1815 if (htab->use_rel)
1816 return strncmp (name, ".rel", 4) == 0 && strcmp (s->name, name + 4) == 0;
1817 else
1818 return strncmp (name, ".rela", 5) == 0 && strcmp (s->name, name + 5) == 0;
1819 }
1820
1821 /* Create .got, .gotplt, and .rel(a).got sections in DYNOBJ, and set up
1822 shortcuts to them in our hash table. */
1823
1824 static bfd_boolean
create_got_section(bfd * dynobj,struct bfd_link_info * info)1825 create_got_section (bfd *dynobj, struct bfd_link_info *info)
1826 {
1827 struct elf32_arm_link_hash_table *htab;
1828
1829 htab = elf32_arm_hash_table (info);
1830 /* BPABI objects never have a GOT, or associated sections. */
1831 if (htab->symbian_p)
1832 return TRUE;
1833
1834 if (! _bfd_elf_create_got_section (dynobj, info))
1835 return FALSE;
1836
1837 htab->sgot = bfd_get_section_by_name (dynobj, ".got");
1838 htab->sgotplt = bfd_get_section_by_name (dynobj, ".got.plt");
1839 if (!htab->sgot || !htab->sgotplt)
1840 abort ();
1841
1842 htab->srelgot = bfd_make_section_with_flags (dynobj,
1843 RELOC_SECTION (htab, ".got"),
1844 (SEC_ALLOC | SEC_LOAD
1845 | SEC_HAS_CONTENTS
1846 | SEC_IN_MEMORY
1847 | SEC_LINKER_CREATED
1848 | SEC_READONLY));
1849 if (htab->srelgot == NULL
1850 || ! bfd_set_section_alignment (dynobj, htab->srelgot, 2))
1851 return FALSE;
1852 return TRUE;
1853 }
1854
1855 /* Create .plt, .rel(a).plt, .got, .got.plt, .rel(a).got, .dynbss, and
1856 .rel(a).bss sections in DYNOBJ, and set up shortcuts to them in our
1857 hash table. */
1858
1859 static bfd_boolean
elf32_arm_create_dynamic_sections(bfd * dynobj,struct bfd_link_info * info)1860 elf32_arm_create_dynamic_sections (bfd *dynobj, struct bfd_link_info *info)
1861 {
1862 struct elf32_arm_link_hash_table *htab;
1863
1864 htab = elf32_arm_hash_table (info);
1865 if (!htab->sgot && !create_got_section (dynobj, info))
1866 return FALSE;
1867
1868 if (!_bfd_elf_create_dynamic_sections (dynobj, info))
1869 return FALSE;
1870
1871 htab->splt = bfd_get_section_by_name (dynobj, ".plt");
1872 htab->srelplt = bfd_get_section_by_name (dynobj,
1873 RELOC_SECTION (htab, ".plt"));
1874 htab->sdynbss = bfd_get_section_by_name (dynobj, ".dynbss");
1875 if (!info->shared)
1876 htab->srelbss = bfd_get_section_by_name (dynobj,
1877 RELOC_SECTION (htab, ".bss"));
1878
1879 if (htab->vxworks_p)
1880 {
1881 if (!elf_vxworks_create_dynamic_sections (dynobj, info, &htab->srelplt2))
1882 return FALSE;
1883
1884 if (info->shared)
1885 {
1886 htab->plt_header_size = 0;
1887 htab->plt_entry_size
1888 = 4 * ARRAY_SIZE (elf32_arm_vxworks_shared_plt_entry);
1889 }
1890 else
1891 {
1892 htab->plt_header_size
1893 = 4 * ARRAY_SIZE (elf32_arm_vxworks_exec_plt0_entry);
1894 htab->plt_entry_size
1895 = 4 * ARRAY_SIZE (elf32_arm_vxworks_exec_plt_entry);
1896 }
1897 }
1898
1899 if (!htab->splt
1900 || !htab->srelplt
1901 || !htab->sdynbss
1902 || (!info->shared && !htab->srelbss))
1903 abort ();
1904
1905 return TRUE;
1906 }
1907
1908 /* Copy the extra info we tack onto an elf_link_hash_entry. */
1909
1910 static void
elf32_arm_copy_indirect_symbol(struct bfd_link_info * info,struct elf_link_hash_entry * dir,struct elf_link_hash_entry * ind)1911 elf32_arm_copy_indirect_symbol (struct bfd_link_info *info,
1912 struct elf_link_hash_entry *dir,
1913 struct elf_link_hash_entry *ind)
1914 {
1915 struct elf32_arm_link_hash_entry *edir, *eind;
1916
1917 edir = (struct elf32_arm_link_hash_entry *) dir;
1918 eind = (struct elf32_arm_link_hash_entry *) ind;
1919
1920 if (eind->relocs_copied != NULL)
1921 {
1922 if (edir->relocs_copied != NULL)
1923 {
1924 struct elf32_arm_relocs_copied **pp;
1925 struct elf32_arm_relocs_copied *p;
1926
1927 /* Add reloc counts against the indirect sym to the direct sym
1928 list. Merge any entries against the same section. */
1929 for (pp = &eind->relocs_copied; (p = *pp) != NULL; )
1930 {
1931 struct elf32_arm_relocs_copied *q;
1932
1933 for (q = edir->relocs_copied; q != NULL; q = q->next)
1934 if (q->section == p->section)
1935 {
1936 q->pc_count += p->pc_count;
1937 q->count += p->count;
1938 *pp = p->next;
1939 break;
1940 }
1941 if (q == NULL)
1942 pp = &p->next;
1943 }
1944 *pp = edir->relocs_copied;
1945 }
1946
1947 edir->relocs_copied = eind->relocs_copied;
1948 eind->relocs_copied = NULL;
1949 }
1950
1951 /* Copy over PLT info. */
1952 edir->plt_thumb_refcount += eind->plt_thumb_refcount;
1953 eind->plt_thumb_refcount = 0;
1954
1955 if (ind->root.type == bfd_link_hash_indirect
1956 && dir->got.refcount <= 0)
1957 {
1958 edir->tls_type = eind->tls_type;
1959 eind->tls_type = GOT_UNKNOWN;
1960 }
1961
1962 _bfd_elf_link_hash_copy_indirect (info, dir, ind);
1963 }
1964
1965 /* Create an ARM elf linker hash table. */
1966
1967 static struct bfd_link_hash_table *
elf32_arm_link_hash_table_create(bfd * abfd)1968 elf32_arm_link_hash_table_create (bfd *abfd)
1969 {
1970 struct elf32_arm_link_hash_table *ret;
1971 bfd_size_type amt = sizeof (struct elf32_arm_link_hash_table);
1972
1973 ret = bfd_malloc (amt);
1974 if (ret == NULL)
1975 return NULL;
1976
1977 if (!_bfd_elf_link_hash_table_init (& ret->root, abfd,
1978 elf32_arm_link_hash_newfunc,
1979 sizeof (struct elf32_arm_link_hash_entry)))
1980 {
1981 free (ret);
1982 return NULL;
1983 }
1984
1985 ret->sgot = NULL;
1986 ret->sgotplt = NULL;
1987 ret->srelgot = NULL;
1988 ret->splt = NULL;
1989 ret->srelplt = NULL;
1990 ret->sdynbss = NULL;
1991 ret->srelbss = NULL;
1992 ret->srelplt2 = NULL;
1993 ret->thumb_glue_size = 0;
1994 ret->arm_glue_size = 0;
1995 ret->bfd_of_glue_owner = NULL;
1996 ret->byteswap_code = 0;
1997 ret->target1_is_rel = 0;
1998 ret->target2_reloc = R_ARM_NONE;
1999 #ifdef FOUR_WORD_PLT
2000 ret->plt_header_size = 16;
2001 ret->plt_entry_size = 16;
2002 #else
2003 ret->plt_header_size = 20;
2004 ret->plt_entry_size = 12;
2005 #endif
2006 ret->fix_v4bx = 0;
2007 ret->use_blx = 0;
2008 ret->vxworks_p = 0;
2009 ret->symbian_p = 0;
2010 ret->use_rel = 1;
2011 ret->sym_sec.abfd = NULL;
2012 ret->obfd = abfd;
2013 ret->tls_ldm_got.refcount = 0;
2014
2015 return &ret->root.root;
2016 }
2017
2018 /* Locate the Thumb encoded calling stub for NAME. */
2019
2020 static struct elf_link_hash_entry *
find_thumb_glue(struct bfd_link_info * link_info,const char * name,bfd * input_bfd)2021 find_thumb_glue (struct bfd_link_info *link_info,
2022 const char *name,
2023 bfd *input_bfd)
2024 {
2025 char *tmp_name;
2026 struct elf_link_hash_entry *hash;
2027 struct elf32_arm_link_hash_table *hash_table;
2028
2029 /* We need a pointer to the armelf specific hash table. */
2030 hash_table = elf32_arm_hash_table (link_info);
2031
2032 tmp_name = bfd_malloc ((bfd_size_type) strlen (name)
2033 + strlen (THUMB2ARM_GLUE_ENTRY_NAME) + 1);
2034
2035 BFD_ASSERT (tmp_name);
2036
2037 sprintf (tmp_name, THUMB2ARM_GLUE_ENTRY_NAME, name);
2038
2039 hash = elf_link_hash_lookup
2040 (&(hash_table)->root, tmp_name, FALSE, FALSE, TRUE);
2041
2042 if (hash == NULL)
2043 /* xgettext:c-format */
2044 (*_bfd_error_handler) (_("%B: unable to find THUMB glue '%s' for `%s'"),
2045 input_bfd, tmp_name, name);
2046
2047 free (tmp_name);
2048
2049 return hash;
2050 }
2051
2052 /* Locate the ARM encoded calling stub for NAME. */
2053
2054 static struct elf_link_hash_entry *
find_arm_glue(struct bfd_link_info * link_info,const char * name,bfd * input_bfd)2055 find_arm_glue (struct bfd_link_info *link_info,
2056 const char *name,
2057 bfd *input_bfd)
2058 {
2059 char *tmp_name;
2060 struct elf_link_hash_entry *myh;
2061 struct elf32_arm_link_hash_table *hash_table;
2062
2063 /* We need a pointer to the elfarm specific hash table. */
2064 hash_table = elf32_arm_hash_table (link_info);
2065
2066 tmp_name = bfd_malloc ((bfd_size_type) strlen (name)
2067 + strlen (ARM2THUMB_GLUE_ENTRY_NAME) + 1);
2068
2069 BFD_ASSERT (tmp_name);
2070
2071 sprintf (tmp_name, ARM2THUMB_GLUE_ENTRY_NAME, name);
2072
2073 myh = elf_link_hash_lookup
2074 (&(hash_table)->root, tmp_name, FALSE, FALSE, TRUE);
2075
2076 if (myh == NULL)
2077 /* xgettext:c-format */
2078 (*_bfd_error_handler) (_("%B: unable to find ARM glue '%s' for `%s'"),
2079 input_bfd, tmp_name, name);
2080
2081 free (tmp_name);
2082
2083 return myh;
2084 }
2085
2086 /* ARM->Thumb glue (static images):
2087
2088 .arm
2089 __func_from_arm:
2090 ldr r12, __func_addr
2091 bx r12
2092 __func_addr:
2093 .word func @ behave as if you saw a ARM_32 reloc.
2094
2095 (relocatable images)
2096 .arm
2097 __func_from_arm:
2098 ldr r12, __func_offset
2099 add r12, r12, pc
2100 bx r12
2101 __func_offset:
2102 .word func - .
2103 */
2104
2105 #define ARM2THUMB_STATIC_GLUE_SIZE 12
2106 static const insn32 a2t1_ldr_insn = 0xe59fc000;
2107 static const insn32 a2t2_bx_r12_insn = 0xe12fff1c;
2108 static const insn32 a2t3_func_addr_insn = 0x00000001;
2109
2110 #define ARM2THUMB_PIC_GLUE_SIZE 16
2111 static const insn32 a2t1p_ldr_insn = 0xe59fc004;
2112 static const insn32 a2t2p_add_pc_insn = 0xe08cc00f;
2113 static const insn32 a2t3p_bx_r12_insn = 0xe12fff1c;
2114
2115 /* Thumb->ARM: Thumb->(non-interworking aware) ARM
2116
2117 .thumb .thumb
2118 .align 2 .align 2
2119 __func_from_thumb: __func_from_thumb:
2120 bx pc push {r6, lr}
2121 nop ldr r6, __func_addr
2122 .arm mov lr, pc
2123 __func_change_to_arm: bx r6
2124 b func .arm
2125 __func_back_to_thumb:
2126 ldmia r13! {r6, lr}
2127 bx lr
2128 __func_addr:
2129 .word func */
2130
2131 #define THUMB2ARM_GLUE_SIZE 8
2132 static const insn16 t2a1_bx_pc_insn = 0x4778;
2133 static const insn16 t2a2_noop_insn = 0x46c0;
2134 static const insn32 t2a3_b_insn = 0xea000000;
2135
2136 #ifndef ELFARM_NABI_C_INCLUDED
2137 bfd_boolean
bfd_elf32_arm_allocate_interworking_sections(struct bfd_link_info * info)2138 bfd_elf32_arm_allocate_interworking_sections (struct bfd_link_info * info)
2139 {
2140 asection * s;
2141 bfd_byte * foo;
2142 struct elf32_arm_link_hash_table * globals;
2143
2144 globals = elf32_arm_hash_table (info);
2145
2146 BFD_ASSERT (globals != NULL);
2147
2148 if (globals->arm_glue_size != 0)
2149 {
2150 BFD_ASSERT (globals->bfd_of_glue_owner != NULL);
2151
2152 s = bfd_get_section_by_name (globals->bfd_of_glue_owner,
2153 ARM2THUMB_GLUE_SECTION_NAME);
2154
2155 BFD_ASSERT (s != NULL);
2156
2157 foo = bfd_alloc (globals->bfd_of_glue_owner, globals->arm_glue_size);
2158
2159 s->size = globals->arm_glue_size;
2160 s->contents = foo;
2161 }
2162
2163 if (globals->thumb_glue_size != 0)
2164 {
2165 BFD_ASSERT (globals->bfd_of_glue_owner != NULL);
2166
2167 s = bfd_get_section_by_name
2168 (globals->bfd_of_glue_owner, THUMB2ARM_GLUE_SECTION_NAME);
2169
2170 BFD_ASSERT (s != NULL);
2171
2172 foo = bfd_alloc (globals->bfd_of_glue_owner, globals->thumb_glue_size);
2173
2174 s->size = globals->thumb_glue_size;
2175 s->contents = foo;
2176 }
2177
2178 return TRUE;
2179 }
2180
2181 static void
record_arm_to_thumb_glue(struct bfd_link_info * link_info,struct elf_link_hash_entry * h)2182 record_arm_to_thumb_glue (struct bfd_link_info * link_info,
2183 struct elf_link_hash_entry * h)
2184 {
2185 const char * name = h->root.root.string;
2186 asection * s;
2187 char * tmp_name;
2188 struct elf_link_hash_entry * myh;
2189 struct bfd_link_hash_entry * bh;
2190 struct elf32_arm_link_hash_table * globals;
2191 bfd_vma val;
2192
2193 globals = elf32_arm_hash_table (link_info);
2194
2195 BFD_ASSERT (globals != NULL);
2196 BFD_ASSERT (globals->bfd_of_glue_owner != NULL);
2197
2198 s = bfd_get_section_by_name
2199 (globals->bfd_of_glue_owner, ARM2THUMB_GLUE_SECTION_NAME);
2200
2201 BFD_ASSERT (s != NULL);
2202
2203 tmp_name = bfd_malloc ((bfd_size_type) strlen (name) + strlen (ARM2THUMB_GLUE_ENTRY_NAME) + 1);
2204
2205 BFD_ASSERT (tmp_name);
2206
2207 sprintf (tmp_name, ARM2THUMB_GLUE_ENTRY_NAME, name);
2208
2209 myh = elf_link_hash_lookup
2210 (&(globals)->root, tmp_name, FALSE, FALSE, TRUE);
2211
2212 if (myh != NULL)
2213 {
2214 /* We've already seen this guy. */
2215 free (tmp_name);
2216 return;
2217 }
2218
2219 /* The only trick here is using hash_table->arm_glue_size as the value.
2220 Even though the section isn't allocated yet, this is where we will be
2221 putting it. */
2222 bh = NULL;
2223 val = globals->arm_glue_size + 1;
2224 _bfd_generic_link_add_one_symbol (link_info, globals->bfd_of_glue_owner,
2225 tmp_name, BSF_GLOBAL, s, val,
2226 NULL, TRUE, FALSE, &bh);
2227
2228 myh = (struct elf_link_hash_entry *) bh;
2229 myh->type = ELF_ST_INFO (STB_LOCAL, STT_FUNC);
2230 myh->forced_local = 1;
2231
2232 free (tmp_name);
2233
2234 if ((link_info->shared || globals->root.is_relocatable_executable))
2235 globals->arm_glue_size += ARM2THUMB_PIC_GLUE_SIZE;
2236 else
2237 globals->arm_glue_size += ARM2THUMB_STATIC_GLUE_SIZE;
2238
2239 return;
2240 }
2241
2242 static void
record_thumb_to_arm_glue(struct bfd_link_info * link_info,struct elf_link_hash_entry * h)2243 record_thumb_to_arm_glue (struct bfd_link_info *link_info,
2244 struct elf_link_hash_entry *h)
2245 {
2246 const char *name = h->root.root.string;
2247 asection *s;
2248 char *tmp_name;
2249 struct elf_link_hash_entry *myh;
2250 struct bfd_link_hash_entry *bh;
2251 struct elf32_arm_link_hash_table *hash_table;
2252 bfd_vma val;
2253
2254 hash_table = elf32_arm_hash_table (link_info);
2255
2256 BFD_ASSERT (hash_table != NULL);
2257 BFD_ASSERT (hash_table->bfd_of_glue_owner != NULL);
2258
2259 s = bfd_get_section_by_name
2260 (hash_table->bfd_of_glue_owner, THUMB2ARM_GLUE_SECTION_NAME);
2261
2262 BFD_ASSERT (s != NULL);
2263
2264 tmp_name = bfd_malloc ((bfd_size_type) strlen (name)
2265 + strlen (THUMB2ARM_GLUE_ENTRY_NAME) + 1);
2266
2267 BFD_ASSERT (tmp_name);
2268
2269 sprintf (tmp_name, THUMB2ARM_GLUE_ENTRY_NAME, name);
2270
2271 myh = elf_link_hash_lookup
2272 (&(hash_table)->root, tmp_name, FALSE, FALSE, TRUE);
2273
2274 if (myh != NULL)
2275 {
2276 /* We've already seen this guy. */
2277 free (tmp_name);
2278 return;
2279 }
2280
2281 bh = NULL;
2282 val = hash_table->thumb_glue_size + 1;
2283 _bfd_generic_link_add_one_symbol (link_info, hash_table->bfd_of_glue_owner,
2284 tmp_name, BSF_GLOBAL, s, val,
2285 NULL, TRUE, FALSE, &bh);
2286
2287 /* If we mark it 'Thumb', the disassembler will do a better job. */
2288 myh = (struct elf_link_hash_entry *) bh;
2289 myh->type = ELF_ST_INFO (STB_LOCAL, STT_ARM_TFUNC);
2290 myh->forced_local = 1;
2291
2292 free (tmp_name);
2293
2294 #define CHANGE_TO_ARM "__%s_change_to_arm"
2295 #define BACK_FROM_ARM "__%s_back_from_arm"
2296
2297 /* Allocate another symbol to mark where we switch to Arm mode. */
2298 tmp_name = bfd_malloc ((bfd_size_type) strlen (name)
2299 + strlen (CHANGE_TO_ARM) + 1);
2300
2301 BFD_ASSERT (tmp_name);
2302
2303 sprintf (tmp_name, CHANGE_TO_ARM, name);
2304
2305 bh = NULL;
2306 val = hash_table->thumb_glue_size + 4,
2307 _bfd_generic_link_add_one_symbol (link_info, hash_table->bfd_of_glue_owner,
2308 tmp_name, BSF_LOCAL, s, val,
2309 NULL, TRUE, FALSE, &bh);
2310
2311 free (tmp_name);
2312
2313 hash_table->thumb_glue_size += THUMB2ARM_GLUE_SIZE;
2314
2315 return;
2316 }
2317
2318 /* Add the glue sections to ABFD. This function is called from the
2319 linker scripts in ld/emultempl/{armelf}.em. */
2320
2321 bfd_boolean
bfd_elf32_arm_add_glue_sections_to_bfd(bfd * abfd,struct bfd_link_info * info)2322 bfd_elf32_arm_add_glue_sections_to_bfd (bfd *abfd,
2323 struct bfd_link_info *info)
2324 {
2325 flagword flags;
2326 asection *sec;
2327
2328 /* If we are only performing a partial
2329 link do not bother adding the glue. */
2330 if (info->relocatable)
2331 return TRUE;
2332
2333 sec = bfd_get_section_by_name (abfd, ARM2THUMB_GLUE_SECTION_NAME);
2334
2335 if (sec == NULL)
2336 {
2337 /* Note: we do not include the flag SEC_LINKER_CREATED, as this
2338 will prevent elf_link_input_bfd() from processing the contents
2339 of this section. */
2340 flags = SEC_ALLOC | SEC_LOAD | SEC_HAS_CONTENTS | SEC_IN_MEMORY | SEC_CODE | SEC_READONLY;
2341
2342 sec = bfd_make_section_with_flags (abfd,
2343 ARM2THUMB_GLUE_SECTION_NAME,
2344 flags);
2345
2346 if (sec == NULL
2347 || !bfd_set_section_alignment (abfd, sec, 2))
2348 return FALSE;
2349
2350 /* Set the gc mark to prevent the section from being removed by garbage
2351 collection, despite the fact that no relocs refer to this section. */
2352 sec->gc_mark = 1;
2353 }
2354
2355 sec = bfd_get_section_by_name (abfd, THUMB2ARM_GLUE_SECTION_NAME);
2356
2357 if (sec == NULL)
2358 {
2359 flags = SEC_ALLOC | SEC_LOAD | SEC_HAS_CONTENTS | SEC_IN_MEMORY
2360 | SEC_CODE | SEC_READONLY;
2361
2362 sec = bfd_make_section_with_flags (abfd,
2363 THUMB2ARM_GLUE_SECTION_NAME,
2364 flags);
2365
2366 if (sec == NULL
2367 || !bfd_set_section_alignment (abfd, sec, 2))
2368 return FALSE;
2369
2370 sec->gc_mark = 1;
2371 }
2372
2373 return TRUE;
2374 }
2375
2376 /* Select a BFD to be used to hold the sections used by the glue code.
2377 This function is called from the linker scripts in ld/emultempl/
2378 {armelf/pe}.em */
2379
2380 bfd_boolean
bfd_elf32_arm_get_bfd_for_interworking(bfd * abfd,struct bfd_link_info * info)2381 bfd_elf32_arm_get_bfd_for_interworking (bfd *abfd, struct bfd_link_info *info)
2382 {
2383 struct elf32_arm_link_hash_table *globals;
2384
2385 /* If we are only performing a partial link
2386 do not bother getting a bfd to hold the glue. */
2387 if (info->relocatable)
2388 return TRUE;
2389
2390 /* Make sure we don't attach the glue sections to a dynamic object. */
2391 BFD_ASSERT (!(abfd->flags & DYNAMIC));
2392
2393 globals = elf32_arm_hash_table (info);
2394
2395 BFD_ASSERT (globals != NULL);
2396
2397 if (globals->bfd_of_glue_owner != NULL)
2398 return TRUE;
2399
2400 /* Save the bfd for later use. */
2401 globals->bfd_of_glue_owner = abfd;
2402
2403 return TRUE;
2404 }
2405
check_use_blx(struct elf32_arm_link_hash_table * globals)2406 static void check_use_blx(struct elf32_arm_link_hash_table *globals)
2407 {
2408 if (elf32_arm_get_eabi_attr_int (globals->obfd, Tag_CPU_arch) > 2)
2409 globals->use_blx = 1;
2410 }
2411
2412 bfd_boolean
bfd_elf32_arm_process_before_allocation(bfd * abfd,struct bfd_link_info * link_info,int byteswap_code)2413 bfd_elf32_arm_process_before_allocation (bfd *abfd,
2414 struct bfd_link_info *link_info,
2415 int byteswap_code)
2416 {
2417 Elf_Internal_Shdr *symtab_hdr;
2418 Elf_Internal_Rela *internal_relocs = NULL;
2419 Elf_Internal_Rela *irel, *irelend;
2420 bfd_byte *contents = NULL;
2421
2422 asection *sec;
2423 struct elf32_arm_link_hash_table *globals;
2424
2425 /* If we are only performing a partial link do not bother
2426 to construct any glue. */
2427 if (link_info->relocatable)
2428 return TRUE;
2429
2430 /* Here we have a bfd that is to be included on the link. We have a hook
2431 to do reloc rummaging, before section sizes are nailed down. */
2432 globals = elf32_arm_hash_table (link_info);
2433 check_use_blx (globals);
2434
2435 BFD_ASSERT (globals != NULL);
2436 BFD_ASSERT (globals->bfd_of_glue_owner != NULL);
2437
2438 if (byteswap_code && !bfd_big_endian (abfd))
2439 {
2440 _bfd_error_handler (_("%B: BE8 images only valid in big-endian mode."),
2441 abfd);
2442 return FALSE;
2443 }
2444 globals->byteswap_code = byteswap_code;
2445
2446 /* Rummage around all the relocs and map the glue vectors. */
2447 sec = abfd->sections;
2448
2449 if (sec == NULL)
2450 return TRUE;
2451
2452 for (; sec != NULL; sec = sec->next)
2453 {
2454 if (sec->reloc_count == 0)
2455 continue;
2456
2457 symtab_hdr = &elf_tdata (abfd)->symtab_hdr;
2458
2459 /* Load the relocs. */
2460 internal_relocs
2461 = _bfd_elf_link_read_relocs (abfd, sec, (void *) NULL,
2462 (Elf_Internal_Rela *) NULL, FALSE);
2463
2464 if (internal_relocs == NULL)
2465 goto error_return;
2466
2467 irelend = internal_relocs + sec->reloc_count;
2468 for (irel = internal_relocs; irel < irelend; irel++)
2469 {
2470 long r_type;
2471 unsigned long r_index;
2472
2473 struct elf_link_hash_entry *h;
2474
2475 r_type = ELF32_R_TYPE (irel->r_info);
2476 r_index = ELF32_R_SYM (irel->r_info);
2477
2478 /* These are the only relocation types we care about. */
2479 if ( r_type != R_ARM_PC24
2480 && r_type != R_ARM_PLT32
2481 && r_type != R_ARM_CALL
2482 && r_type != R_ARM_JUMP24
2483 && r_type != R_ARM_THM_CALL)
2484 continue;
2485
2486 /* Get the section contents if we haven't done so already. */
2487 if (contents == NULL)
2488 {
2489 /* Get cached copy if it exists. */
2490 if (elf_section_data (sec)->this_hdr.contents != NULL)
2491 contents = elf_section_data (sec)->this_hdr.contents;
2492 else
2493 {
2494 /* Go get them off disk. */
2495 if (! bfd_malloc_and_get_section (abfd, sec, &contents))
2496 goto error_return;
2497 }
2498 }
2499
2500 /* If the relocation is not against a symbol it cannot concern us. */
2501 h = NULL;
2502
2503 /* We don't care about local symbols. */
2504 if (r_index < symtab_hdr->sh_info)
2505 continue;
2506
2507 /* This is an external symbol. */
2508 r_index -= symtab_hdr->sh_info;
2509 h = (struct elf_link_hash_entry *)
2510 elf_sym_hashes (abfd)[r_index];
2511
2512 /* If the relocation is against a static symbol it must be within
2513 the current section and so cannot be a cross ARM/Thumb relocation. */
2514 if (h == NULL)
2515 continue;
2516
2517 /* If the call will go through a PLT entry then we do not need
2518 glue. */
2519 if (globals->splt != NULL && h->plt.offset != (bfd_vma) -1)
2520 continue;
2521
2522 switch (r_type)
2523 {
2524 case R_ARM_PC24:
2525 case R_ARM_PLT32:
2526 case R_ARM_CALL:
2527 case R_ARM_JUMP24:
2528 /* This one is a call from arm code. We need to look up
2529 the target of the call. If it is a thumb target, we
2530 insert glue. */
2531 if (ELF_ST_TYPE(h->type) == STT_ARM_TFUNC
2532 && !(r_type == R_ARM_CALL && globals->use_blx))
2533 record_arm_to_thumb_glue (link_info, h);
2534 break;
2535
2536 case R_ARM_THM_CALL:
2537 /* This one is a call from thumb code. We look
2538 up the target of the call. If it is not a thumb
2539 target, we insert glue. */
2540 if (ELF_ST_TYPE (h->type) != STT_ARM_TFUNC && !globals->use_blx)
2541 record_thumb_to_arm_glue (link_info, h);
2542 break;
2543
2544 default:
2545 abort ();
2546 }
2547 }
2548
2549 if (contents != NULL
2550 && elf_section_data (sec)->this_hdr.contents != contents)
2551 free (contents);
2552 contents = NULL;
2553
2554 if (internal_relocs != NULL
2555 && elf_section_data (sec)->relocs != internal_relocs)
2556 free (internal_relocs);
2557 internal_relocs = NULL;
2558 }
2559
2560 return TRUE;
2561
2562 error_return:
2563 if (contents != NULL
2564 && elf_section_data (sec)->this_hdr.contents != contents)
2565 free (contents);
2566 if (internal_relocs != NULL
2567 && elf_section_data (sec)->relocs != internal_relocs)
2568 free (internal_relocs);
2569
2570 return FALSE;
2571 }
2572 #endif
2573
2574
2575 /* Set target relocation values needed during linking. */
2576
2577 void
bfd_elf32_arm_set_target_relocs(struct bfd_link_info * link_info,int target1_is_rel,char * target2_type,int fix_v4bx,int use_blx)2578 bfd_elf32_arm_set_target_relocs (struct bfd_link_info *link_info,
2579 int target1_is_rel,
2580 char * target2_type,
2581 int fix_v4bx,
2582 int use_blx)
2583 {
2584 struct elf32_arm_link_hash_table *globals;
2585
2586 globals = elf32_arm_hash_table (link_info);
2587
2588 globals->target1_is_rel = target1_is_rel;
2589 if (strcmp (target2_type, "rel") == 0)
2590 globals->target2_reloc = R_ARM_REL32;
2591 else if (strcmp (target2_type, "abs") == 0)
2592 globals->target2_reloc = R_ARM_ABS32;
2593 else if (strcmp (target2_type, "got-rel") == 0)
2594 globals->target2_reloc = R_ARM_GOT_PREL;
2595 else
2596 {
2597 _bfd_error_handler (_("Invalid TARGET2 relocation type '%s'."),
2598 target2_type);
2599 }
2600 globals->fix_v4bx = fix_v4bx;
2601 globals->use_blx |= use_blx;
2602 }
2603
2604 /* The thumb form of a long branch is a bit finicky, because the offset
2605 encoding is split over two fields, each in it's own instruction. They
2606 can occur in any order. So given a thumb form of long branch, and an
2607 offset, insert the offset into the thumb branch and return finished
2608 instruction.
2609
2610 It takes two thumb instructions to encode the target address. Each has
2611 11 bits to invest. The upper 11 bits are stored in one (identified by
2612 H-0.. see below), the lower 11 bits are stored in the other (identified
2613 by H-1).
2614
2615 Combine together and shifted left by 1 (it's a half word address) and
2616 there you have it.
2617
2618 Op: 1111 = F,
2619 H-0, upper address-0 = 000
2620 Op: 1111 = F,
2621 H-1, lower address-0 = 800
2622
2623 They can be ordered either way, but the arm tools I've seen always put
2624 the lower one first. It probably doesn't matter. krk@cygnus.com
2625
2626 XXX: Actually the order does matter. The second instruction (H-1)
2627 moves the computed address into the PC, so it must be the second one
2628 in the sequence. The problem, however is that whilst little endian code
2629 stores the instructions in HI then LOW order, big endian code does the
2630 reverse. nickc@cygnus.com. */
2631
2632 #define LOW_HI_ORDER 0xF800F000
2633 #define HI_LOW_ORDER 0xF000F800
2634
2635 static insn32
insert_thumb_branch(insn32 br_insn,int rel_off)2636 insert_thumb_branch (insn32 br_insn, int rel_off)
2637 {
2638 unsigned int low_bits;
2639 unsigned int high_bits;
2640
2641 BFD_ASSERT ((rel_off & 1) != 1);
2642
2643 rel_off >>= 1; /* Half word aligned address. */
2644 low_bits = rel_off & 0x000007FF; /* The bottom 11 bits. */
2645 high_bits = (rel_off >> 11) & 0x000007FF; /* The top 11 bits. */
2646
2647 if ((br_insn & LOW_HI_ORDER) == LOW_HI_ORDER)
2648 br_insn = LOW_HI_ORDER | (low_bits << 16) | high_bits;
2649 else if ((br_insn & HI_LOW_ORDER) == HI_LOW_ORDER)
2650 br_insn = HI_LOW_ORDER | (high_bits << 16) | low_bits;
2651 else
2652 /* FIXME: abort is probably not the right call. krk@cygnus.com */
2653 abort (); /* Error - not a valid branch instruction form. */
2654
2655 return br_insn;
2656 }
2657
2658 /* Thumb code calling an ARM function. */
2659
2660 static int
elf32_thumb_to_arm_stub(struct bfd_link_info * info,const char * name,bfd * input_bfd,bfd * output_bfd,asection * input_section,bfd_byte * hit_data,asection * sym_sec,bfd_vma offset,bfd_signed_vma addend,bfd_vma val)2661 elf32_thumb_to_arm_stub (struct bfd_link_info * info,
2662 const char * name,
2663 bfd * input_bfd,
2664 bfd * output_bfd,
2665 asection * input_section,
2666 bfd_byte * hit_data,
2667 asection * sym_sec,
2668 bfd_vma offset,
2669 bfd_signed_vma addend,
2670 bfd_vma val)
2671 {
2672 asection * s = 0;
2673 bfd_vma my_offset;
2674 unsigned long int tmp;
2675 long int ret_offset;
2676 struct elf_link_hash_entry * myh;
2677 struct elf32_arm_link_hash_table * globals;
2678
2679 myh = find_thumb_glue (info, name, input_bfd);
2680 if (myh == NULL)
2681 return FALSE;
2682
2683 globals = elf32_arm_hash_table (info);
2684
2685 BFD_ASSERT (globals != NULL);
2686 BFD_ASSERT (globals->bfd_of_glue_owner != NULL);
2687
2688 my_offset = myh->root.u.def.value;
2689
2690 s = bfd_get_section_by_name (globals->bfd_of_glue_owner,
2691 THUMB2ARM_GLUE_SECTION_NAME);
2692
2693 BFD_ASSERT (s != NULL);
2694 BFD_ASSERT (s->contents != NULL);
2695 BFD_ASSERT (s->output_section != NULL);
2696
2697 if ((my_offset & 0x01) == 0x01)
2698 {
2699 if (sym_sec != NULL
2700 && sym_sec->owner != NULL
2701 && !INTERWORK_FLAG (sym_sec->owner))
2702 {
2703 (*_bfd_error_handler)
2704 (_("%B(%s): warning: interworking not enabled.\n"
2705 " first occurrence: %B: thumb call to arm"),
2706 sym_sec->owner, input_bfd, name);
2707
2708 return FALSE;
2709 }
2710
2711 --my_offset;
2712 myh->root.u.def.value = my_offset;
2713
2714 bfd_put_16 (output_bfd, (bfd_vma) t2a1_bx_pc_insn,
2715 s->contents + my_offset);
2716
2717 bfd_put_16 (output_bfd, (bfd_vma) t2a2_noop_insn,
2718 s->contents + my_offset + 2);
2719
2720 ret_offset =
2721 /* Address of destination of the stub. */
2722 ((bfd_signed_vma) val)
2723 - ((bfd_signed_vma)
2724 /* Offset from the start of the current section
2725 to the start of the stubs. */
2726 (s->output_offset
2727 /* Offset of the start of this stub from the start of the stubs. */
2728 + my_offset
2729 /* Address of the start of the current section. */
2730 + s->output_section->vma)
2731 /* The branch instruction is 4 bytes into the stub. */
2732 + 4
2733 /* ARM branches work from the pc of the instruction + 8. */
2734 + 8);
2735
2736 bfd_put_32 (output_bfd,
2737 (bfd_vma) t2a3_b_insn | ((ret_offset >> 2) & 0x00FFFFFF),
2738 s->contents + my_offset + 4);
2739 }
2740
2741 BFD_ASSERT (my_offset <= globals->thumb_glue_size);
2742
2743 /* Now go back and fix up the original BL insn to point to here. */
2744 ret_offset =
2745 /* Address of where the stub is located. */
2746 (s->output_section->vma + s->output_offset + my_offset)
2747 /* Address of where the BL is located. */
2748 - (input_section->output_section->vma + input_section->output_offset
2749 + offset)
2750 /* Addend in the relocation. */
2751 - addend
2752 /* Biassing for PC-relative addressing. */
2753 - 8;
2754
2755 tmp = bfd_get_32 (input_bfd, hit_data
2756 - input_section->vma);
2757
2758 bfd_put_32 (output_bfd,
2759 (bfd_vma) insert_thumb_branch (tmp, ret_offset),
2760 hit_data - input_section->vma);
2761
2762 return TRUE;
2763 }
2764
2765 /* Arm code calling a Thumb function. */
2766
2767 static int
elf32_arm_to_thumb_stub(struct bfd_link_info * info,const char * name,bfd * input_bfd,bfd * output_bfd,asection * input_section,bfd_byte * hit_data,asection * sym_sec,bfd_vma offset,bfd_signed_vma addend,bfd_vma val)2768 elf32_arm_to_thumb_stub (struct bfd_link_info * info,
2769 const char * name,
2770 bfd * input_bfd,
2771 bfd * output_bfd,
2772 asection * input_section,
2773 bfd_byte * hit_data,
2774 asection * sym_sec,
2775 bfd_vma offset,
2776 bfd_signed_vma addend,
2777 bfd_vma val)
2778 {
2779 unsigned long int tmp;
2780 bfd_vma my_offset;
2781 asection * s;
2782 long int ret_offset;
2783 struct elf_link_hash_entry * myh;
2784 struct elf32_arm_link_hash_table * globals;
2785
2786 myh = find_arm_glue (info, name, input_bfd);
2787 if (myh == NULL)
2788 return FALSE;
2789
2790 globals = elf32_arm_hash_table (info);
2791
2792 BFD_ASSERT (globals != NULL);
2793 BFD_ASSERT (globals->bfd_of_glue_owner != NULL);
2794
2795 my_offset = myh->root.u.def.value;
2796 s = bfd_get_section_by_name (globals->bfd_of_glue_owner,
2797 ARM2THUMB_GLUE_SECTION_NAME);
2798 BFD_ASSERT (s != NULL);
2799 BFD_ASSERT (s->contents != NULL);
2800 BFD_ASSERT (s->output_section != NULL);
2801
2802 if ((my_offset & 0x01) == 0x01)
2803 {
2804 if (sym_sec != NULL
2805 && sym_sec->owner != NULL
2806 && !INTERWORK_FLAG (sym_sec->owner))
2807 {
2808 (*_bfd_error_handler)
2809 (_("%B(%s): warning: interworking not enabled.\n"
2810 " first occurrence: %B: arm call to thumb"),
2811 sym_sec->owner, input_bfd, name);
2812 }
2813
2814 --my_offset;
2815 myh->root.u.def.value = my_offset;
2816
2817 if ((info->shared || globals->root.is_relocatable_executable))
2818 {
2819 /* For relocatable objects we can't use absolute addresses,
2820 so construct the address from a relative offset. */
2821 /* TODO: If the offset is small it's probably worth
2822 constructing the address with adds. */
2823 bfd_put_32 (output_bfd, (bfd_vma) a2t1p_ldr_insn,
2824 s->contents + my_offset);
2825 bfd_put_32 (output_bfd, (bfd_vma) a2t2p_add_pc_insn,
2826 s->contents + my_offset + 4);
2827 bfd_put_32 (output_bfd, (bfd_vma) a2t3p_bx_r12_insn,
2828 s->contents + my_offset + 8);
2829 /* Adjust the offset by 4 for the position of the add,
2830 and 8 for the pipeline offset. */
2831 ret_offset = (val - (s->output_offset
2832 + s->output_section->vma
2833 + my_offset + 12))
2834 | 1;
2835 bfd_put_32 (output_bfd, ret_offset,
2836 s->contents + my_offset + 12);
2837 }
2838 else
2839 {
2840 bfd_put_32 (output_bfd, (bfd_vma) a2t1_ldr_insn,
2841 s->contents + my_offset);
2842
2843 bfd_put_32 (output_bfd, (bfd_vma) a2t2_bx_r12_insn,
2844 s->contents + my_offset + 4);
2845
2846 /* It's a thumb address. Add the low order bit. */
2847 bfd_put_32 (output_bfd, val | a2t3_func_addr_insn,
2848 s->contents + my_offset + 8);
2849 }
2850 }
2851
2852 BFD_ASSERT (my_offset <= globals->arm_glue_size);
2853
2854 tmp = bfd_get_32 (input_bfd, hit_data);
2855 tmp = tmp & 0xFF000000;
2856
2857 /* Somehow these are both 4 too far, so subtract 8. */
2858 ret_offset = (s->output_offset
2859 + my_offset
2860 + s->output_section->vma
2861 - (input_section->output_offset
2862 + input_section->output_section->vma
2863 + offset + addend)
2864 - 8);
2865
2866 tmp = tmp | ((ret_offset >> 2) & 0x00FFFFFF);
2867
2868 bfd_put_32 (output_bfd, (bfd_vma) tmp, hit_data - input_section->vma);
2869
2870 return TRUE;
2871 }
2872
2873 /* Some relocations map to different relocations depending on the
2874 target. Return the real relocation. */
2875 static int
arm_real_reloc_type(struct elf32_arm_link_hash_table * globals,int r_type)2876 arm_real_reloc_type (struct elf32_arm_link_hash_table * globals,
2877 int r_type)
2878 {
2879 switch (r_type)
2880 {
2881 case R_ARM_TARGET1:
2882 if (globals->target1_is_rel)
2883 return R_ARM_REL32;
2884 else
2885 return R_ARM_ABS32;
2886
2887 case R_ARM_TARGET2:
2888 return globals->target2_reloc;
2889
2890 default:
2891 return r_type;
2892 }
2893 }
2894
2895 /* Return the base VMA address which should be subtracted from real addresses
2896 when resolving @dtpoff relocation.
2897 This is PT_TLS segment p_vaddr. */
2898
2899 static bfd_vma
dtpoff_base(struct bfd_link_info * info)2900 dtpoff_base (struct bfd_link_info *info)
2901 {
2902 /* If tls_sec is NULL, we should have signalled an error already. */
2903 if (elf_hash_table (info)->tls_sec == NULL)
2904 return 0;
2905 return elf_hash_table (info)->tls_sec->vma;
2906 }
2907
2908 /* Return the relocation value for @tpoff relocation
2909 if STT_TLS virtual address is ADDRESS. */
2910
2911 static bfd_vma
tpoff(struct bfd_link_info * info,bfd_vma address)2912 tpoff (struct bfd_link_info *info, bfd_vma address)
2913 {
2914 struct elf_link_hash_table *htab = elf_hash_table (info);
2915 bfd_vma base;
2916
2917 /* If tls_sec is NULL, we should have signalled an error already. */
2918 if (htab->tls_sec == NULL)
2919 return 0;
2920 base = align_power ((bfd_vma) TCB_SIZE, htab->tls_sec->alignment_power);
2921 return address - htab->tls_sec->vma + base;
2922 }
2923
2924 /* Perform an R_ARM_ABS12 relocation on the field pointed to by DATA.
2925 VALUE is the relocation value. */
2926
2927 static bfd_reloc_status_type
elf32_arm_abs12_reloc(bfd * abfd,void * data,bfd_vma value)2928 elf32_arm_abs12_reloc (bfd *abfd, void *data, bfd_vma value)
2929 {
2930 if (value > 0xfff)
2931 return bfd_reloc_overflow;
2932
2933 value |= bfd_get_32 (abfd, data) & 0xfffff000;
2934 bfd_put_32 (abfd, value, data);
2935 return bfd_reloc_ok;
2936 }
2937
2938 /* Perform a relocation as part of a final link. */
2939
2940 static bfd_reloc_status_type
elf32_arm_final_link_relocate(reloc_howto_type * howto,bfd * input_bfd,bfd * output_bfd,asection * input_section,bfd_byte * contents,Elf_Internal_Rela * rel,bfd_vma value,struct bfd_link_info * info,asection * sym_sec,const char * sym_name,int sym_flags,struct elf_link_hash_entry * h,bfd_boolean * unresolved_reloc_p)2941 elf32_arm_final_link_relocate (reloc_howto_type * howto,
2942 bfd * input_bfd,
2943 bfd * output_bfd,
2944 asection * input_section,
2945 bfd_byte * contents,
2946 Elf_Internal_Rela * rel,
2947 bfd_vma value,
2948 struct bfd_link_info * info,
2949 asection * sym_sec,
2950 const char * sym_name,
2951 int sym_flags,
2952 struct elf_link_hash_entry * h,
2953 bfd_boolean * unresolved_reloc_p)
2954 {
2955 unsigned long r_type = howto->type;
2956 unsigned long r_symndx;
2957 bfd_byte * hit_data = contents + rel->r_offset;
2958 bfd * dynobj = NULL;
2959 Elf_Internal_Shdr * symtab_hdr;
2960 struct elf_link_hash_entry ** sym_hashes;
2961 bfd_vma * local_got_offsets;
2962 asection * sgot = NULL;
2963 asection * splt = NULL;
2964 asection * sreloc = NULL;
2965 bfd_vma addend;
2966 bfd_signed_vma signed_addend;
2967 struct elf32_arm_link_hash_table * globals;
2968
2969 globals = elf32_arm_hash_table (info);
2970
2971 /* Some relocation type map to different relocations depending on the
2972 target. We pick the right one here. */
2973 r_type = arm_real_reloc_type (globals, r_type);
2974 if (r_type != howto->type)
2975 howto = elf32_arm_howto_from_type (r_type);
2976
2977 /* If the start address has been set, then set the EF_ARM_HASENTRY
2978 flag. Setting this more than once is redundant, but the cost is
2979 not too high, and it keeps the code simple.
2980
2981 The test is done here, rather than somewhere else, because the
2982 start address is only set just before the final link commences.
2983
2984 Note - if the user deliberately sets a start address of 0, the
2985 flag will not be set. */
2986 if (bfd_get_start_address (output_bfd) != 0)
2987 elf_elfheader (output_bfd)->e_flags |= EF_ARM_HASENTRY;
2988
2989 dynobj = elf_hash_table (info)->dynobj;
2990 if (dynobj)
2991 {
2992 sgot = bfd_get_section_by_name (dynobj, ".got");
2993 splt = bfd_get_section_by_name (dynobj, ".plt");
2994 }
2995 symtab_hdr = & elf_tdata (input_bfd)->symtab_hdr;
2996 sym_hashes = elf_sym_hashes (input_bfd);
2997 local_got_offsets = elf_local_got_offsets (input_bfd);
2998 r_symndx = ELF32_R_SYM (rel->r_info);
2999
3000 if (globals->use_rel)
3001 {
3002 addend = bfd_get_32 (input_bfd, hit_data) & howto->src_mask;
3003
3004 if (addend & ((howto->src_mask + 1) >> 1))
3005 {
3006 signed_addend = -1;
3007 signed_addend &= ~ howto->src_mask;
3008 signed_addend |= addend;
3009 }
3010 else
3011 signed_addend = addend;
3012 }
3013 else
3014 addend = signed_addend = rel->r_addend;
3015
3016 switch (r_type)
3017 {
3018 case R_ARM_NONE:
3019 /* We don't need to find a value for this symbol. It's just a
3020 marker. */
3021 *unresolved_reloc_p = FALSE;
3022 return bfd_reloc_ok;
3023
3024 case R_ARM_ABS12:
3025 if (!globals->vxworks_p)
3026 return elf32_arm_abs12_reloc (input_bfd, hit_data, value + addend);
3027
3028 case R_ARM_PC24:
3029 case R_ARM_ABS32:
3030 case R_ARM_REL32:
3031 case R_ARM_CALL:
3032 case R_ARM_JUMP24:
3033 case R_ARM_XPC25:
3034 case R_ARM_PREL31:
3035 case R_ARM_PLT32:
3036 /* r_symndx will be zero only for relocs against symbols
3037 from removed linkonce sections, or sections discarded by
3038 a linker script. */
3039 if (r_symndx == 0)
3040 return bfd_reloc_ok;
3041
3042 /* Handle relocations which should use the PLT entry. ABS32/REL32
3043 will use the symbol's value, which may point to a PLT entry, but we
3044 don't need to handle that here. If we created a PLT entry, all
3045 branches in this object should go to it. */
3046 if ((r_type != R_ARM_ABS32 && r_type != R_ARM_REL32)
3047 && h != NULL
3048 && splt != NULL
3049 && h->plt.offset != (bfd_vma) -1)
3050 {
3051 /* If we've created a .plt section, and assigned a PLT entry to
3052 this function, it should not be known to bind locally. If
3053 it were, we would have cleared the PLT entry. */
3054 BFD_ASSERT (!SYMBOL_CALLS_LOCAL (info, h));
3055
3056 value = (splt->output_section->vma
3057 + splt->output_offset
3058 + h->plt.offset);
3059 *unresolved_reloc_p = FALSE;
3060 return _bfd_final_link_relocate (howto, input_bfd, input_section,
3061 contents, rel->r_offset, value,
3062 rel->r_addend);
3063 }
3064
3065 /* When generating a shared object or relocatable executable, these
3066 relocations are copied into the output file to be resolved at
3067 run time. */
3068 if ((info->shared || globals->root.is_relocatable_executable)
3069 && (input_section->flags & SEC_ALLOC)
3070 && (r_type != R_ARM_REL32
3071 || !SYMBOL_CALLS_LOCAL (info, h))
3072 && (h == NULL
3073 || ELF_ST_VISIBILITY (h->other) == STV_DEFAULT
3074 || h->root.type != bfd_link_hash_undefweak)
3075 && r_type != R_ARM_PC24
3076 && r_type != R_ARM_CALL
3077 && r_type != R_ARM_JUMP24
3078 && r_type != R_ARM_PREL31
3079 && r_type != R_ARM_PLT32)
3080 {
3081 Elf_Internal_Rela outrel;
3082 bfd_byte *loc;
3083 bfd_boolean skip, relocate;
3084
3085 *unresolved_reloc_p = FALSE;
3086
3087 if (sreloc == NULL)
3088 {
3089 const char * name;
3090
3091 name = (bfd_elf_string_from_elf_section
3092 (input_bfd,
3093 elf_elfheader (input_bfd)->e_shstrndx,
3094 elf_section_data (input_section)->rel_hdr.sh_name));
3095 if (name == NULL)
3096 return bfd_reloc_notsupported;
3097
3098 BFD_ASSERT (reloc_section_p (globals, name, input_section));
3099
3100 sreloc = bfd_get_section_by_name (dynobj, name);
3101 BFD_ASSERT (sreloc != NULL);
3102 }
3103
3104 skip = FALSE;
3105 relocate = FALSE;
3106
3107 outrel.r_addend = addend;
3108 outrel.r_offset =
3109 _bfd_elf_section_offset (output_bfd, info, input_section,
3110 rel->r_offset);
3111 if (outrel.r_offset == (bfd_vma) -1)
3112 skip = TRUE;
3113 else if (outrel.r_offset == (bfd_vma) -2)
3114 skip = TRUE, relocate = TRUE;
3115 outrel.r_offset += (input_section->output_section->vma
3116 + input_section->output_offset);
3117
3118 if (skip)
3119 memset (&outrel, 0, sizeof outrel);
3120 else if (h != NULL
3121 && h->dynindx != -1
3122 && (!info->shared
3123 || !info->symbolic
3124 || !h->def_regular))
3125 outrel.r_info = ELF32_R_INFO (h->dynindx, r_type);
3126 else
3127 {
3128 int symbol;
3129
3130 /* This symbol is local, or marked to become local. */
3131 if (sym_flags == STT_ARM_TFUNC)
3132 value |= 1;
3133 if (globals->symbian_p)
3134 {
3135 /* On Symbian OS, the data segment and text segement
3136 can be relocated independently. Therefore, we
3137 must indicate the segment to which this
3138 relocation is relative. The BPABI allows us to
3139 use any symbol in the right segment; we just use
3140 the section symbol as it is convenient. (We
3141 cannot use the symbol given by "h" directly as it
3142 will not appear in the dynamic symbol table.) */
3143 if (sym_sec)
3144 symbol = elf_section_data (sym_sec->output_section)->dynindx;
3145 else
3146 symbol = elf_section_data (input_section->output_section)->dynindx;
3147 BFD_ASSERT (symbol != 0);
3148 }
3149 else
3150 /* On SVR4-ish systems, the dynamic loader cannot
3151 relocate the text and data segments independently,
3152 so the symbol does not matter. */
3153 symbol = 0;
3154 outrel.r_info = ELF32_R_INFO (symbol, R_ARM_RELATIVE);
3155 if (globals->use_rel)
3156 relocate = TRUE;
3157 else
3158 outrel.r_addend += value;
3159 }
3160
3161 loc = sreloc->contents;
3162 loc += sreloc->reloc_count++ * RELOC_SIZE (globals);
3163 SWAP_RELOC_OUT (globals) (output_bfd, &outrel, loc);
3164
3165 /* If this reloc is against an external symbol, we do not want to
3166 fiddle with the addend. Otherwise, we need to include the symbol
3167 value so that it becomes an addend for the dynamic reloc. */
3168 if (! relocate)
3169 return bfd_reloc_ok;
3170
3171 return _bfd_final_link_relocate (howto, input_bfd, input_section,
3172 contents, rel->r_offset, value,
3173 (bfd_vma) 0);
3174 }
3175 else switch (r_type)
3176 {
3177 case R_ARM_ABS12:
3178 return elf32_arm_abs12_reloc (input_bfd, hit_data, value + addend);
3179
3180 case R_ARM_XPC25: /* Arm BLX instruction. */
3181 case R_ARM_CALL:
3182 case R_ARM_JUMP24:
3183 case R_ARM_PC24: /* Arm B/BL instruction */
3184 case R_ARM_PLT32:
3185 if (r_type == R_ARM_XPC25)
3186 {
3187 /* Check for Arm calling Arm function. */
3188 /* FIXME: Should we translate the instruction into a BL
3189 instruction instead ? */
3190 if (sym_flags != STT_ARM_TFUNC)
3191 (*_bfd_error_handler)
3192 (_("\%B: Warning: Arm BLX instruction targets Arm function '%s'."),
3193 input_bfd,
3194 h ? h->root.root.string : "(local)");
3195 }
3196 else if (r_type != R_ARM_CALL || !globals->use_blx)
3197 {
3198 /* Check for Arm calling Thumb function. */
3199 if (sym_flags == STT_ARM_TFUNC)
3200 {
3201 elf32_arm_to_thumb_stub (info, sym_name, input_bfd,
3202 output_bfd, input_section,
3203 hit_data, sym_sec, rel->r_offset,
3204 signed_addend, value);
3205 return bfd_reloc_ok;
3206 }
3207 }
3208
3209 /* The ARM ELF ABI says that this reloc is computed as: S - P + A
3210 where:
3211 S is the address of the symbol in the relocation.
3212 P is address of the instruction being relocated.
3213 A is the addend (extracted from the instruction) in bytes.
3214
3215 S is held in 'value'.
3216 P is the base address of the section containing the
3217 instruction plus the offset of the reloc into that
3218 section, ie:
3219 (input_section->output_section->vma +
3220 input_section->output_offset +
3221 rel->r_offset).
3222 A is the addend, converted into bytes, ie:
3223 (signed_addend * 4)
3224
3225 Note: None of these operations have knowledge of the pipeline
3226 size of the processor, thus it is up to the assembler to
3227 encode this information into the addend. */
3228 value -= (input_section->output_section->vma
3229 + input_section->output_offset);
3230 value -= rel->r_offset;
3231 if (globals->use_rel)
3232 value += (signed_addend << howto->size);
3233 else
3234 /* RELA addends do not have to be adjusted by howto->size. */
3235 value += signed_addend;
3236
3237 signed_addend = value;
3238 signed_addend >>= howto->rightshift;
3239
3240 /* It is not an error for an undefined weak reference to be
3241 out of range. Any program that branches to such a symbol
3242 is going to crash anyway, so there is no point worrying
3243 about getting the destination exactly right. */
3244 if (! h || h->root.type != bfd_link_hash_undefweak)
3245 {
3246 /* Perform a signed range check. */
3247 if ( signed_addend > ((bfd_signed_vma) (howto->dst_mask >> 1))
3248 || signed_addend < - ((bfd_signed_vma) ((howto->dst_mask + 1) >> 1)))
3249 return bfd_reloc_overflow;
3250 }
3251
3252 addend = (value & 2);
3253
3254 value = (signed_addend & howto->dst_mask)
3255 | (bfd_get_32 (input_bfd, hit_data) & (~ howto->dst_mask));
3256
3257 /* Set the H bit in the BLX instruction. */
3258 if (sym_flags == STT_ARM_TFUNC)
3259 {
3260 if (addend)
3261 value |= (1 << 24);
3262 else
3263 value &= ~(bfd_vma)(1 << 24);
3264 }
3265 if (r_type == R_ARM_CALL)
3266 {
3267 /* Select the correct instruction (BL or BLX). */
3268 if (sym_flags == STT_ARM_TFUNC)
3269 value |= (1 << 28);
3270 else
3271 {
3272 value &= ~(bfd_vma)(1 << 28);
3273 value |= (1 << 24);
3274 }
3275 }
3276 break;
3277
3278 case R_ARM_ABS32:
3279 value += addend;
3280 if (sym_flags == STT_ARM_TFUNC)
3281 value |= 1;
3282 break;
3283
3284 case R_ARM_REL32:
3285 value += addend;
3286 if (sym_flags == STT_ARM_TFUNC)
3287 value |= 1;
3288 value -= (input_section->output_section->vma
3289 + input_section->output_offset + rel->r_offset);
3290 break;
3291
3292 case R_ARM_PREL31:
3293 value -= (input_section->output_section->vma
3294 + input_section->output_offset + rel->r_offset);
3295 value += signed_addend;
3296 if (! h || h->root.type != bfd_link_hash_undefweak)
3297 {
3298 /* Check for overflow */
3299 if ((value ^ (value >> 1)) & (1 << 30))
3300 return bfd_reloc_overflow;
3301 }
3302 value &= 0x7fffffff;
3303 value |= (bfd_get_32 (input_bfd, hit_data) & 0x80000000);
3304 if (sym_flags == STT_ARM_TFUNC)
3305 value |= 1;
3306 break;
3307 }
3308
3309 bfd_put_32 (input_bfd, value, hit_data);
3310 return bfd_reloc_ok;
3311
3312 case R_ARM_ABS8:
3313 value += addend;
3314 if ((long) value > 0x7f || (long) value < -0x80)
3315 return bfd_reloc_overflow;
3316
3317 bfd_put_8 (input_bfd, value, hit_data);
3318 return bfd_reloc_ok;
3319
3320 case R_ARM_ABS16:
3321 value += addend;
3322
3323 if ((long) value > 0x7fff || (long) value < -0x8000)
3324 return bfd_reloc_overflow;
3325
3326 bfd_put_16 (input_bfd, value, hit_data);
3327 return bfd_reloc_ok;
3328
3329 case R_ARM_THM_ABS5:
3330 /* Support ldr and str instructions for the thumb. */
3331 if (globals->use_rel)
3332 {
3333 /* Need to refetch addend. */
3334 addend = bfd_get_16 (input_bfd, hit_data) & howto->src_mask;
3335 /* ??? Need to determine shift amount from operand size. */
3336 addend >>= howto->rightshift;
3337 }
3338 value += addend;
3339
3340 /* ??? Isn't value unsigned? */
3341 if ((long) value > 0x1f || (long) value < -0x10)
3342 return bfd_reloc_overflow;
3343
3344 /* ??? Value needs to be properly shifted into place first. */
3345 value |= bfd_get_16 (input_bfd, hit_data) & 0xf83f;
3346 bfd_put_16 (input_bfd, value, hit_data);
3347 return bfd_reloc_ok;
3348
3349 case R_ARM_THM_XPC22:
3350 case R_ARM_THM_CALL:
3351 /* Thumb BL (branch long instruction). */
3352 {
3353 bfd_vma relocation;
3354 bfd_boolean overflow = FALSE;
3355 bfd_vma upper_insn = bfd_get_16 (input_bfd, hit_data);
3356 bfd_vma lower_insn = bfd_get_16 (input_bfd, hit_data + 2);
3357 bfd_signed_vma reloc_signed_max = ((1 << (howto->bitsize - 1)) - 1) >> howto->rightshift;
3358 bfd_signed_vma reloc_signed_min = ~ reloc_signed_max;
3359 bfd_vma check;
3360 bfd_signed_vma signed_check;
3361
3362 /* Need to refetch the addend and squish the two 11 bit pieces
3363 together. */
3364 if (globals->use_rel)
3365 {
3366 bfd_vma upper = upper_insn & 0x7ff;
3367 bfd_vma lower = lower_insn & 0x7ff;
3368 upper = (upper ^ 0x400) - 0x400; /* Sign extend. */
3369 addend = (upper << 12) | (lower << 1);
3370 signed_addend = addend;
3371 }
3372
3373 if (r_type == R_ARM_THM_XPC22)
3374 {
3375 /* Check for Thumb to Thumb call. */
3376 /* FIXME: Should we translate the instruction into a BL
3377 instruction instead ? */
3378 if (sym_flags == STT_ARM_TFUNC)
3379 (*_bfd_error_handler)
3380 (_("%B: Warning: Thumb BLX instruction targets thumb function '%s'."),
3381 input_bfd,
3382 h ? h->root.root.string : "(local)");
3383 }
3384 else
3385 {
3386 /* If it is not a call to Thumb, assume call to Arm.
3387 If it is a call relative to a section name, then it is not a
3388 function call at all, but rather a long jump. Calls through
3389 the PLT do not require stubs. */
3390 if (sym_flags != STT_ARM_TFUNC && sym_flags != STT_SECTION
3391 && (h == NULL || splt == NULL
3392 || h->plt.offset == (bfd_vma) -1))
3393 {
3394 if (globals->use_blx)
3395 {
3396 /* Convert BL to BLX. */
3397 lower_insn = (lower_insn & ~0x1000) | 0x0800;
3398 }
3399 else if (elf32_thumb_to_arm_stub
3400 (info, sym_name, input_bfd, output_bfd, input_section,
3401 hit_data, sym_sec, rel->r_offset, signed_addend, value))
3402 return bfd_reloc_ok;
3403 else
3404 return bfd_reloc_dangerous;
3405 }
3406 else if (sym_flags == STT_ARM_TFUNC && globals->use_blx)
3407 {
3408 /* Make sure this is a BL. */
3409 lower_insn |= 0x1800;
3410 }
3411 }
3412
3413 /* Handle calls via the PLT. */
3414 if (h != NULL && splt != NULL && h->plt.offset != (bfd_vma) -1)
3415 {
3416 value = (splt->output_section->vma
3417 + splt->output_offset
3418 + h->plt.offset);
3419 if (globals->use_blx)
3420 {
3421 /* If the Thumb BLX instruction is available, convert the
3422 BL to a BLX instruction to call the ARM-mode PLT entry. */
3423 lower_insn = (lower_insn & ~0x1000) | 0x0800;
3424 }
3425 else
3426 /* Target the Thumb stub before the ARM PLT entry. */
3427 value -= PLT_THUMB_STUB_SIZE;
3428 *unresolved_reloc_p = FALSE;
3429 }
3430
3431 relocation = value + signed_addend;
3432
3433 relocation -= (input_section->output_section->vma
3434 + input_section->output_offset
3435 + rel->r_offset);
3436
3437 check = relocation >> howto->rightshift;
3438
3439 /* If this is a signed value, the rightshift just dropped
3440 leading 1 bits (assuming twos complement). */
3441 if ((bfd_signed_vma) relocation >= 0)
3442 signed_check = check;
3443 else
3444 signed_check = check | ~((bfd_vma) -1 >> howto->rightshift);
3445
3446 /* Assumes two's complement. */
3447 if (signed_check > reloc_signed_max || signed_check < reloc_signed_min)
3448 overflow = TRUE;
3449
3450 if ((lower_insn & 0x1800) == 0x0800)
3451 /* For a BLX instruction, make sure that the relocation is rounded up
3452 to a word boundary. This follows the semantics of the instruction
3453 which specifies that bit 1 of the target address will come from bit
3454 1 of the base address. */
3455 relocation = (relocation + 2) & ~ 3;
3456
3457 /* Put RELOCATION back into the insn. */
3458 upper_insn = (upper_insn & ~(bfd_vma) 0x7ff) | ((relocation >> 12) & 0x7ff);
3459 lower_insn = (lower_insn & ~(bfd_vma) 0x7ff) | ((relocation >> 1) & 0x7ff);
3460
3461 /* Put the relocated value back in the object file: */
3462 bfd_put_16 (input_bfd, upper_insn, hit_data);
3463 bfd_put_16 (input_bfd, lower_insn, hit_data + 2);
3464
3465 return (overflow ? bfd_reloc_overflow : bfd_reloc_ok);
3466 }
3467 break;
3468
3469 case R_ARM_THM_JUMP24:
3470 /* Thumb32 unconditional branch instruction. */
3471 {
3472 bfd_vma relocation;
3473 bfd_boolean overflow = FALSE;
3474 bfd_vma upper_insn = bfd_get_16 (input_bfd, hit_data);
3475 bfd_vma lower_insn = bfd_get_16 (input_bfd, hit_data + 2);
3476 bfd_signed_vma reloc_signed_max = ((1 << (howto->bitsize - 1)) - 1) >> howto->rightshift;
3477 bfd_signed_vma reloc_signed_min = ~ reloc_signed_max;
3478 bfd_vma check;
3479 bfd_signed_vma signed_check;
3480
3481 /* Need to refetch the addend, reconstruct the top three bits, and glue the
3482 two pieces together. */
3483 if (globals->use_rel)
3484 {
3485 bfd_vma S = (upper_insn & 0x0400) >> 10;
3486 bfd_vma hi = (upper_insn & 0x03ff);
3487 bfd_vma I1 = (lower_insn & 0x2000) >> 13;
3488 bfd_vma I2 = (lower_insn & 0x0800) >> 11;
3489 bfd_vma lo = (lower_insn & 0x07ff);
3490
3491 I1 = !(I1 ^ S);
3492 I2 = !(I2 ^ S);
3493 S = !S;
3494
3495 signed_addend = (S << 24) | (I1 << 23) | (I2 << 22) | (hi << 12) | (lo << 1);
3496 signed_addend -= (1 << 24); /* Sign extend. */
3497 }
3498
3499 /* ??? Should handle interworking? GCC might someday try to
3500 use this for tail calls. */
3501
3502 relocation = value + signed_addend;
3503 relocation -= (input_section->output_section->vma
3504 + input_section->output_offset
3505 + rel->r_offset);
3506
3507 check = relocation >> howto->rightshift;
3508
3509 /* If this is a signed value, the rightshift just dropped
3510 leading 1 bits (assuming twos complement). */
3511 if ((bfd_signed_vma) relocation >= 0)
3512 signed_check = check;
3513 else
3514 signed_check = check | ~((bfd_vma) -1 >> howto->rightshift);
3515
3516 /* Assumes two's complement. */
3517 if (signed_check > reloc_signed_max || signed_check < reloc_signed_min)
3518 overflow = TRUE;
3519
3520 /* Put RELOCATION back into the insn. */
3521 {
3522 bfd_vma S = (relocation & 0x01000000) >> 24;
3523 bfd_vma I1 = (relocation & 0x00800000) >> 23;
3524 bfd_vma I2 = (relocation & 0x00400000) >> 22;
3525 bfd_vma hi = (relocation & 0x003ff000) >> 12;
3526 bfd_vma lo = (relocation & 0x00000ffe) >> 1;
3527
3528 I1 = !(I1 ^ S);
3529 I2 = !(I2 ^ S);
3530
3531 upper_insn = (upper_insn & (bfd_vma) 0xf800) | (S << 10) | hi;
3532 lower_insn = (lower_insn & (bfd_vma) 0xd000) | (I1 << 13) | (I2 << 11) | lo;
3533 }
3534
3535 /* Put the relocated value back in the object file: */
3536 bfd_put_16 (input_bfd, upper_insn, hit_data);
3537 bfd_put_16 (input_bfd, lower_insn, hit_data + 2);
3538
3539 return (overflow ? bfd_reloc_overflow : bfd_reloc_ok);
3540 }
3541
3542 case R_ARM_THM_JUMP19:
3543 /* Thumb32 conditional branch instruction. */
3544 {
3545 bfd_vma relocation;
3546 bfd_boolean overflow = FALSE;
3547 bfd_vma upper_insn = bfd_get_16 (input_bfd, hit_data);
3548 bfd_vma lower_insn = bfd_get_16 (input_bfd, hit_data + 2);
3549 bfd_signed_vma reloc_signed_max = ((1 << (howto->bitsize - 1)) - 1) >> howto->rightshift;
3550 bfd_signed_vma reloc_signed_min = ~ reloc_signed_max;
3551 bfd_vma check;
3552 bfd_signed_vma signed_check;
3553
3554 /* Need to refetch the addend, reconstruct the top three bits,
3555 and squish the two 11 bit pieces together. */
3556 if (globals->use_rel)
3557 {
3558 bfd_vma S = (upper_insn & 0x0400) >> 10;
3559 bfd_vma upper = (upper_insn & 0x001f);
3560 bfd_vma J1 = (lower_insn & 0x2000) >> 13;
3561 bfd_vma J2 = (lower_insn & 0x0800) >> 11;
3562 bfd_vma lower = (lower_insn & 0x07ff);
3563
3564 upper |= J2 << 6;
3565 upper |= J1 << 7;
3566 upper |= ~S << 8;
3567 upper -= 0x0100; /* Sign extend. */
3568
3569 addend = (upper << 12) | (lower << 1);
3570 signed_addend = addend;
3571 }
3572
3573 /* ??? Should handle interworking? GCC might someday try to
3574 use this for tail calls. */
3575
3576 relocation = value + signed_addend;
3577 relocation -= (input_section->output_section->vma
3578 + input_section->output_offset
3579 + rel->r_offset);
3580
3581 check = relocation >> howto->rightshift;
3582
3583 /* If this is a signed value, the rightshift just dropped
3584 leading 1 bits (assuming twos complement). */
3585 if ((bfd_signed_vma) relocation >= 0)
3586 signed_check = check;
3587 else
3588 signed_check = check | ~((bfd_vma) -1 >> howto->rightshift);
3589
3590 /* Assumes two's complement. */
3591 if (signed_check > reloc_signed_max || signed_check < reloc_signed_min)
3592 overflow = TRUE;
3593
3594 /* Put RELOCATION back into the insn. */
3595 {
3596 bfd_vma S = (relocation & 0x00100000) >> 20;
3597 bfd_vma J2 = (relocation & 0x00080000) >> 19;
3598 bfd_vma J1 = (relocation & 0x00040000) >> 18;
3599 bfd_vma hi = (relocation & 0x0003f000) >> 12;
3600 bfd_vma lo = (relocation & 0x00000ffe) >> 1;
3601
3602 upper_insn = (upper_insn & 0xfb30) | (S << 10) | hi;
3603 lower_insn = (lower_insn & 0xd000) | (J1 << 13) | (J2 << 11) | lo;
3604 }
3605
3606 /* Put the relocated value back in the object file: */
3607 bfd_put_16 (input_bfd, upper_insn, hit_data);
3608 bfd_put_16 (input_bfd, lower_insn, hit_data + 2);
3609
3610 return (overflow ? bfd_reloc_overflow : bfd_reloc_ok);
3611 }
3612
3613 case R_ARM_THM_JUMP11:
3614 case R_ARM_THM_JUMP8:
3615 case R_ARM_THM_JUMP6:
3616 /* Thumb B (branch) instruction). */
3617 {
3618 bfd_signed_vma relocation;
3619 bfd_signed_vma reloc_signed_max = (1 << (howto->bitsize - 1)) - 1;
3620 bfd_signed_vma reloc_signed_min = ~ reloc_signed_max;
3621 bfd_signed_vma signed_check;
3622
3623 /* CZB cannot jump backward. */
3624 if (r_type == R_ARM_THM_JUMP6)
3625 reloc_signed_min = 0;
3626
3627 if (globals->use_rel)
3628 {
3629 /* Need to refetch addend. */
3630 addend = bfd_get_16 (input_bfd, hit_data) & howto->src_mask;
3631 if (addend & ((howto->src_mask + 1) >> 1))
3632 {
3633 signed_addend = -1;
3634 signed_addend &= ~ howto->src_mask;
3635 signed_addend |= addend;
3636 }
3637 else
3638 signed_addend = addend;
3639 /* The value in the insn has been right shifted. We need to
3640 undo this, so that we can perform the address calculation
3641 in terms of bytes. */
3642 signed_addend <<= howto->rightshift;
3643 }
3644 relocation = value + signed_addend;
3645
3646 relocation -= (input_section->output_section->vma
3647 + input_section->output_offset
3648 + rel->r_offset);
3649
3650 relocation >>= howto->rightshift;
3651 signed_check = relocation;
3652
3653 if (r_type == R_ARM_THM_JUMP6)
3654 relocation = ((relocation & 0x0020) << 4) | ((relocation & 0x001f) << 3);
3655 else
3656 relocation &= howto->dst_mask;
3657 relocation |= (bfd_get_16 (input_bfd, hit_data) & (~ howto->dst_mask));
3658
3659 bfd_put_16 (input_bfd, relocation, hit_data);
3660
3661 /* Assumes two's complement. */
3662 if (signed_check > reloc_signed_max || signed_check < reloc_signed_min)
3663 return bfd_reloc_overflow;
3664
3665 return bfd_reloc_ok;
3666 }
3667
3668 case R_ARM_ALU_PCREL7_0:
3669 case R_ARM_ALU_PCREL15_8:
3670 case R_ARM_ALU_PCREL23_15:
3671 {
3672 bfd_vma insn;
3673 bfd_vma relocation;
3674
3675 insn = bfd_get_32 (input_bfd, hit_data);
3676 if (globals->use_rel)
3677 {
3678 /* Extract the addend. */
3679 addend = (insn & 0xff) << ((insn & 0xf00) >> 7);
3680 signed_addend = addend;
3681 }
3682 relocation = value + signed_addend;
3683
3684 relocation -= (input_section->output_section->vma
3685 + input_section->output_offset
3686 + rel->r_offset);
3687 insn = (insn & ~0xfff)
3688 | ((howto->bitpos << 7) & 0xf00)
3689 | ((relocation >> howto->bitpos) & 0xff);
3690 bfd_put_32 (input_bfd, value, hit_data);
3691 }
3692 return bfd_reloc_ok;
3693
3694 case R_ARM_GNU_VTINHERIT:
3695 case R_ARM_GNU_VTENTRY:
3696 return bfd_reloc_ok;
3697
3698 case R_ARM_GOTOFF32:
3699 /* Relocation is relative to the start of the
3700 global offset table. */
3701
3702 BFD_ASSERT (sgot != NULL);
3703 if (sgot == NULL)
3704 return bfd_reloc_notsupported;
3705
3706 /* If we are addressing a Thumb function, we need to adjust the
3707 address by one, so that attempts to call the function pointer will
3708 correctly interpret it as Thumb code. */
3709 if (sym_flags == STT_ARM_TFUNC)
3710 value += 1;
3711
3712 /* Note that sgot->output_offset is not involved in this
3713 calculation. We always want the start of .got. If we
3714 define _GLOBAL_OFFSET_TABLE in a different way, as is
3715 permitted by the ABI, we might have to change this
3716 calculation. */
3717 value -= sgot->output_section->vma;
3718 return _bfd_final_link_relocate (howto, input_bfd, input_section,
3719 contents, rel->r_offset, value,
3720 rel->r_addend);
3721
3722 case R_ARM_GOTPC:
3723 /* Use global offset table as symbol value. */
3724 BFD_ASSERT (sgot != NULL);
3725
3726 if (sgot == NULL)
3727 return bfd_reloc_notsupported;
3728
3729 *unresolved_reloc_p = FALSE;
3730 value = sgot->output_section->vma;
3731 return _bfd_final_link_relocate (howto, input_bfd, input_section,
3732 contents, rel->r_offset, value,
3733 rel->r_addend);
3734
3735 case R_ARM_GOT32:
3736 case R_ARM_GOT_PREL:
3737 /* Relocation is to the entry for this symbol in the
3738 global offset table. */
3739 if (sgot == NULL)
3740 return bfd_reloc_notsupported;
3741
3742 if (h != NULL)
3743 {
3744 bfd_vma off;
3745 bfd_boolean dyn;
3746
3747 off = h->got.offset;
3748 BFD_ASSERT (off != (bfd_vma) -1);
3749 dyn = globals->root.dynamic_sections_created;
3750
3751 if (! WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn, info->shared, h)
3752 || (info->shared
3753 && SYMBOL_REFERENCES_LOCAL (info, h))
3754 || (ELF_ST_VISIBILITY (h->other)
3755 && h->root.type == bfd_link_hash_undefweak))
3756 {
3757 /* This is actually a static link, or it is a -Bsymbolic link
3758 and the symbol is defined locally. We must initialize this
3759 entry in the global offset table. Since the offset must
3760 always be a multiple of 4, we use the least significant bit
3761 to record whether we have initialized it already.
3762
3763 When doing a dynamic link, we create a .rel(a).got relocation
3764 entry to initialize the value. This is done in the
3765 finish_dynamic_symbol routine. */
3766 if ((off & 1) != 0)
3767 off &= ~1;
3768 else
3769 {
3770 /* If we are addressing a Thumb function, we need to
3771 adjust the address by one, so that attempts to
3772 call the function pointer will correctly
3773 interpret it as Thumb code. */
3774 if (sym_flags == STT_ARM_TFUNC)
3775 value |= 1;
3776
3777 bfd_put_32 (output_bfd, value, sgot->contents + off);
3778 h->got.offset |= 1;
3779 }
3780 }
3781 else
3782 *unresolved_reloc_p = FALSE;
3783
3784 value = sgot->output_offset + off;
3785 }
3786 else
3787 {
3788 bfd_vma off;
3789
3790 BFD_ASSERT (local_got_offsets != NULL &&
3791 local_got_offsets[r_symndx] != (bfd_vma) -1);
3792
3793 off = local_got_offsets[r_symndx];
3794
3795 /* The offset must always be a multiple of 4. We use the
3796 least significant bit to record whether we have already
3797 generated the necessary reloc. */
3798 if ((off & 1) != 0)
3799 off &= ~1;
3800 else
3801 {
3802 /* If we are addressing a Thumb function, we need to
3803 adjust the address by one, so that attempts to
3804 call the function pointer will correctly
3805 interpret it as Thumb code. */
3806 if (sym_flags == STT_ARM_TFUNC)
3807 value |= 1;
3808
3809 if (globals->use_rel)
3810 bfd_put_32 (output_bfd, value, sgot->contents + off);
3811
3812 if (info->shared)
3813 {
3814 asection * srelgot;
3815 Elf_Internal_Rela outrel;
3816 bfd_byte *loc;
3817
3818 srelgot = (bfd_get_section_by_name
3819 (dynobj, RELOC_SECTION (globals, ".got")));
3820 BFD_ASSERT (srelgot != NULL);
3821
3822 outrel.r_addend = addend + value;
3823 outrel.r_offset = (sgot->output_section->vma
3824 + sgot->output_offset
3825 + off);
3826 outrel.r_info = ELF32_R_INFO (0, R_ARM_RELATIVE);
3827 loc = srelgot->contents;
3828 loc += srelgot->reloc_count++ * RELOC_SIZE (globals);
3829 SWAP_RELOC_OUT (globals) (output_bfd, &outrel, loc);
3830 }
3831
3832 local_got_offsets[r_symndx] |= 1;
3833 }
3834
3835 value = sgot->output_offset + off;
3836 }
3837 if (r_type != R_ARM_GOT32)
3838 value += sgot->output_section->vma;
3839
3840 return _bfd_final_link_relocate (howto, input_bfd, input_section,
3841 contents, rel->r_offset, value,
3842 rel->r_addend);
3843
3844 case R_ARM_TLS_LDO32:
3845 value = value - dtpoff_base (info);
3846
3847 return _bfd_final_link_relocate (howto, input_bfd, input_section,
3848 contents, rel->r_offset, value,
3849 rel->r_addend);
3850
3851 case R_ARM_TLS_LDM32:
3852 {
3853 bfd_vma off;
3854
3855 if (globals->sgot == NULL)
3856 abort ();
3857
3858 off = globals->tls_ldm_got.offset;
3859
3860 if ((off & 1) != 0)
3861 off &= ~1;
3862 else
3863 {
3864 /* If we don't know the module number, create a relocation
3865 for it. */
3866 if (info->shared)
3867 {
3868 Elf_Internal_Rela outrel;
3869 bfd_byte *loc;
3870
3871 if (globals->srelgot == NULL)
3872 abort ();
3873
3874 outrel.r_addend = 0;
3875 outrel.r_offset = (globals->sgot->output_section->vma
3876 + globals->sgot->output_offset + off);
3877 outrel.r_info = ELF32_R_INFO (0, R_ARM_TLS_DTPMOD32);
3878
3879 if (globals->use_rel)
3880 bfd_put_32 (output_bfd, outrel.r_addend,
3881 globals->sgot->contents + off);
3882
3883 loc = globals->srelgot->contents;
3884 loc += globals->srelgot->reloc_count++ * RELOC_SIZE (globals);
3885 SWAP_RELOC_OUT (globals) (output_bfd, &outrel, loc);
3886 }
3887 else
3888 bfd_put_32 (output_bfd, 1, globals->sgot->contents + off);
3889
3890 globals->tls_ldm_got.offset |= 1;
3891 }
3892
3893 value = globals->sgot->output_section->vma + globals->sgot->output_offset + off
3894 - (input_section->output_section->vma + input_section->output_offset + rel->r_offset);
3895
3896 return _bfd_final_link_relocate (howto, input_bfd, input_section,
3897 contents, rel->r_offset, value,
3898 rel->r_addend);
3899 }
3900
3901 case R_ARM_TLS_GD32:
3902 case R_ARM_TLS_IE32:
3903 {
3904 bfd_vma off;
3905 int indx;
3906 char tls_type;
3907
3908 if (globals->sgot == NULL)
3909 abort ();
3910
3911 indx = 0;
3912 if (h != NULL)
3913 {
3914 bfd_boolean dyn;
3915 dyn = globals->root.dynamic_sections_created;
3916 if (WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn, info->shared, h)
3917 && (!info->shared
3918 || !SYMBOL_REFERENCES_LOCAL (info, h)))
3919 {
3920 *unresolved_reloc_p = FALSE;
3921 indx = h->dynindx;
3922 }
3923 off = h->got.offset;
3924 tls_type = ((struct elf32_arm_link_hash_entry *) h)->tls_type;
3925 }
3926 else
3927 {
3928 if (local_got_offsets == NULL)
3929 abort ();
3930 off = local_got_offsets[r_symndx];
3931 tls_type = elf32_arm_local_got_tls_type (input_bfd)[r_symndx];
3932 }
3933
3934 if (tls_type == GOT_UNKNOWN)
3935 abort ();
3936
3937 if ((off & 1) != 0)
3938 off &= ~1;
3939 else
3940 {
3941 bfd_boolean need_relocs = FALSE;
3942 Elf_Internal_Rela outrel;
3943 bfd_byte *loc = NULL;
3944 int cur_off = off;
3945
3946 /* The GOT entries have not been initialized yet. Do it
3947 now, and emit any relocations. If both an IE GOT and a
3948 GD GOT are necessary, we emit the GD first. */
3949
3950 if ((info->shared || indx != 0)
3951 && (h == NULL
3952 || ELF_ST_VISIBILITY (h->other) == STV_DEFAULT
3953 || h->root.type != bfd_link_hash_undefweak))
3954 {
3955 need_relocs = TRUE;
3956 if (globals->srelgot == NULL)
3957 abort ();
3958 loc = globals->srelgot->contents;
3959 loc += globals->srelgot->reloc_count * RELOC_SIZE (globals);
3960 }
3961
3962 if (tls_type & GOT_TLS_GD)
3963 {
3964 if (need_relocs)
3965 {
3966 outrel.r_addend = 0;
3967 outrel.r_offset = (globals->sgot->output_section->vma
3968 + globals->sgot->output_offset
3969 + cur_off);
3970 outrel.r_info = ELF32_R_INFO (indx, R_ARM_TLS_DTPMOD32);
3971
3972 if (globals->use_rel)
3973 bfd_put_32 (output_bfd, outrel.r_addend,
3974 globals->sgot->contents + cur_off);
3975
3976 SWAP_RELOC_OUT (globals) (output_bfd, &outrel, loc);
3977 globals->srelgot->reloc_count++;
3978 loc += RELOC_SIZE (globals);
3979
3980 if (indx == 0)
3981 bfd_put_32 (output_bfd, value - dtpoff_base (info),
3982 globals->sgot->contents + cur_off + 4);
3983 else
3984 {
3985 outrel.r_addend = 0;
3986 outrel.r_info = ELF32_R_INFO (indx,
3987 R_ARM_TLS_DTPOFF32);
3988 outrel.r_offset += 4;
3989
3990 if (globals->use_rel)
3991 bfd_put_32 (output_bfd, outrel.r_addend,
3992 globals->sgot->contents + cur_off + 4);
3993
3994
3995 SWAP_RELOC_OUT (globals) (output_bfd, &outrel, loc);
3996 globals->srelgot->reloc_count++;
3997 loc += RELOC_SIZE (globals);
3998 }
3999 }
4000 else
4001 {
4002 /* If we are not emitting relocations for a
4003 general dynamic reference, then we must be in a
4004 static link or an executable link with the
4005 symbol binding locally. Mark it as belonging
4006 to module 1, the executable. */
4007 bfd_put_32 (output_bfd, 1,
4008 globals->sgot->contents + cur_off);
4009 bfd_put_32 (output_bfd, value - dtpoff_base (info),
4010 globals->sgot->contents + cur_off + 4);
4011 }
4012
4013 cur_off += 8;
4014 }
4015
4016 if (tls_type & GOT_TLS_IE)
4017 {
4018 if (need_relocs)
4019 {
4020 if (indx == 0)
4021 outrel.r_addend = value - dtpoff_base (info);
4022 else
4023 outrel.r_addend = 0;
4024 outrel.r_offset = (globals->sgot->output_section->vma
4025 + globals->sgot->output_offset
4026 + cur_off);
4027 outrel.r_info = ELF32_R_INFO (indx, R_ARM_TLS_TPOFF32);
4028
4029 if (globals->use_rel)
4030 bfd_put_32 (output_bfd, outrel.r_addend,
4031 globals->sgot->contents + cur_off);
4032
4033 SWAP_RELOC_OUT (globals) (output_bfd, &outrel, loc);
4034 globals->srelgot->reloc_count++;
4035 loc += RELOC_SIZE (globals);
4036 }
4037 else
4038 bfd_put_32 (output_bfd, tpoff (info, value),
4039 globals->sgot->contents + cur_off);
4040 cur_off += 4;
4041 }
4042
4043 if (h != NULL)
4044 h->got.offset |= 1;
4045 else
4046 local_got_offsets[r_symndx] |= 1;
4047 }
4048
4049 if ((tls_type & GOT_TLS_GD) && r_type != R_ARM_TLS_GD32)
4050 off += 8;
4051 value = globals->sgot->output_section->vma + globals->sgot->output_offset + off
4052 - (input_section->output_section->vma + input_section->output_offset + rel->r_offset);
4053
4054 return _bfd_final_link_relocate (howto, input_bfd, input_section,
4055 contents, rel->r_offset, value,
4056 rel->r_addend);
4057 }
4058
4059 case R_ARM_TLS_LE32:
4060 if (info->shared)
4061 {
4062 (*_bfd_error_handler)
4063 (_("%B(%A+0x%lx): R_ARM_TLS_LE32 relocation not permitted in shared object"),
4064 input_bfd, input_section,
4065 (long) rel->r_offset, howto->name);
4066 return FALSE;
4067 }
4068 else
4069 value = tpoff (info, value);
4070
4071 return _bfd_final_link_relocate (howto, input_bfd, input_section,
4072 contents, rel->r_offset, value,
4073 rel->r_addend);
4074
4075 case R_ARM_V4BX:
4076 if (globals->fix_v4bx)
4077 {
4078 bfd_vma insn = bfd_get_32 (input_bfd, hit_data);
4079
4080 /* Ensure that we have a BX instruction. */
4081 BFD_ASSERT ((insn & 0x0ffffff0) == 0x012fff10);
4082
4083 /* Preserve Rm (lowest four bits) and the condition code
4084 (highest four bits). Other bits encode MOV PC,Rm. */
4085 insn = (insn & 0xf000000f) | 0x01a0f000;
4086
4087 bfd_put_32 (input_bfd, insn, hit_data);
4088 }
4089 return bfd_reloc_ok;
4090
4091 case R_ARM_MOVW_ABS_NC:
4092 case R_ARM_MOVT_ABS:
4093 case R_ARM_MOVW_PREL_NC:
4094 case R_ARM_MOVT_PREL:
4095 /* Until we properly support segment-base-relative addressing then
4096 we assume the segment base to be zero, as for the group relocations.
4097 Thus R_ARM_MOVW_BREL_NC has the same semantics as R_ARM_MOVW_ABS_NC
4098 and R_ARM_MOVT_BREL has the same semantics as R_ARM_MOVT_ABS. */
4099 case R_ARM_MOVW_BREL_NC:
4100 case R_ARM_MOVW_BREL:
4101 case R_ARM_MOVT_BREL:
4102 {
4103 bfd_vma insn = bfd_get_32 (input_bfd, hit_data);
4104
4105 if (globals->use_rel)
4106 {
4107 addend = ((insn >> 4) & 0xf000) | (insn & 0xfff);
4108 signed_addend = (addend ^ 0x8000) - 0x8000;
4109 }
4110
4111 value += signed_addend;
4112
4113 if (r_type == R_ARM_MOVW_PREL_NC || r_type == R_ARM_MOVT_PREL)
4114 value -= (input_section->output_section->vma
4115 + input_section->output_offset + rel->r_offset);
4116
4117 if (r_type == R_ARM_MOVW_BREL && value >= 0x10000)
4118 return bfd_reloc_overflow;
4119
4120 if (sym_flags == STT_ARM_TFUNC)
4121 value |= 1;
4122
4123 if (r_type == R_ARM_MOVT_ABS || r_type == R_ARM_MOVT_PREL
4124 || r_type == R_ARM_MOVT_BREL)
4125 value >>= 16;
4126
4127 insn &= 0xfff0f000;
4128 insn |= value & 0xfff;
4129 insn |= (value & 0xf000) << 4;
4130 bfd_put_32 (input_bfd, insn, hit_data);
4131 }
4132 return bfd_reloc_ok;
4133
4134 default:
4135 return bfd_reloc_notsupported;
4136 }
4137 }
4138
4139
4140 static int
uleb128_size(unsigned int i)4141 uleb128_size (unsigned int i)
4142 {
4143 int size;
4144 size = 1;
4145 while (i >= 0x80)
4146 {
4147 i >>= 7;
4148 size++;
4149 }
4150 return size;
4151 }
4152
4153 /* Return TRUE if the attribute has the default value (0/""). */
4154 static bfd_boolean
is_default_attr(aeabi_attribute * attr)4155 is_default_attr (aeabi_attribute *attr)
4156 {
4157 if ((attr->type & 1) && attr->i != 0)
4158 return FALSE;
4159 if ((attr->type & 2) && attr->s && *attr->s)
4160 return FALSE;
4161
4162 return TRUE;
4163 }
4164
4165 /* Return the size of a single attribute. */
4166 static bfd_vma
eabi_attr_size(int tag,aeabi_attribute * attr)4167 eabi_attr_size(int tag, aeabi_attribute *attr)
4168 {
4169 bfd_vma size;
4170
4171 if (is_default_attr (attr))
4172 return 0;
4173
4174 size = uleb128_size (tag);
4175 if (attr->type & 1)
4176 size += uleb128_size (attr->i);
4177 if (attr->type & 2)
4178 size += strlen ((char *)attr->s) + 1;
4179 return size;
4180 }
4181
4182 /* Returns the size of the eabi object attributess section. */
4183 bfd_vma
elf32_arm_eabi_attr_size(bfd * abfd)4184 elf32_arm_eabi_attr_size (bfd *abfd)
4185 {
4186 bfd_vma size;
4187 aeabi_attribute *attr;
4188 aeabi_attribute_list *list;
4189 int i;
4190
4191 attr = elf32_arm_tdata (abfd)->known_eabi_attributes;
4192 size = 16; /* 'A' <size> "aeabi" 0x1 <size>. */
4193 for (i = 4; i < NUM_KNOWN_ATTRIBUTES; i++)
4194 size += eabi_attr_size (i, &attr[i]);
4195
4196 for (list = elf32_arm_tdata (abfd)->other_eabi_attributes;
4197 list;
4198 list = list->next)
4199 size += eabi_attr_size (list->tag, &list->attr);
4200
4201 return size;
4202 }
4203
4204 static bfd_byte *
write_uleb128(bfd_byte * p,unsigned int val)4205 write_uleb128 (bfd_byte *p, unsigned int val)
4206 {
4207 bfd_byte c;
4208 do
4209 {
4210 c = val & 0x7f;
4211 val >>= 7;
4212 if (val)
4213 c |= 0x80;
4214 *(p++) = c;
4215 }
4216 while (val);
4217 return p;
4218 }
4219
4220 /* Write attribute ATTR to butter P, and return a pointer to the following
4221 byte. */
4222 static bfd_byte *
write_eabi_attribute(bfd_byte * p,int tag,aeabi_attribute * attr)4223 write_eabi_attribute (bfd_byte *p, int tag, aeabi_attribute *attr)
4224 {
4225 /* Suppress default entries. */
4226 if (is_default_attr(attr))
4227 return p;
4228
4229 p = write_uleb128 (p, tag);
4230 if (attr->type & 1)
4231 p = write_uleb128 (p, attr->i);
4232 if (attr->type & 2)
4233 {
4234 int len;
4235
4236 len = strlen (attr->s) + 1;
4237 memcpy (p, attr->s, len);
4238 p += len;
4239 }
4240
4241 return p;
4242 }
4243
4244 /* Write the contents of the eabi attributes section to p. */
4245 void
elf32_arm_set_eabi_attr_contents(bfd * abfd,bfd_byte * contents,bfd_vma size)4246 elf32_arm_set_eabi_attr_contents (bfd *abfd, bfd_byte *contents, bfd_vma size)
4247 {
4248 bfd_byte *p;
4249 aeabi_attribute *attr;
4250 aeabi_attribute_list *list;
4251 int i;
4252
4253 p = contents;
4254 *(p++) = 'A';
4255 bfd_put_32 (abfd, size - 1, p);
4256 p += 4;
4257 memcpy (p, "aeabi", 6);
4258 p += 6;
4259 *(p++) = Tag_File;
4260 bfd_put_32 (abfd, size - 11, p);
4261 p += 4;
4262
4263 attr = elf32_arm_tdata (abfd)->known_eabi_attributes;
4264 for (i = 4; i < NUM_KNOWN_ATTRIBUTES; i++)
4265 p = write_eabi_attribute (p, i, &attr[i]);
4266
4267 for (list = elf32_arm_tdata (abfd)->other_eabi_attributes;
4268 list;
4269 list = list->next)
4270 p = write_eabi_attribute (p, list->tag, &list->attr);
4271 }
4272
4273 /* Override final_link to handle EABI object attribute sections. */
4274
4275 static bfd_boolean
elf32_arm_bfd_final_link(bfd * abfd,struct bfd_link_info * info)4276 elf32_arm_bfd_final_link (bfd *abfd, struct bfd_link_info *info)
4277 {
4278 asection *o;
4279 struct bfd_link_order *p;
4280 asection *attr_section = NULL;
4281 bfd_byte *contents;
4282 bfd_vma size = 0;
4283
4284 /* elf32_arm_merge_private_bfd_data will already have merged the
4285 object attributes. Remove the input sections from the link, and set
4286 the contents of the output secton. */
4287 for (o = abfd->sections; o != NULL; o = o->next)
4288 {
4289 if (strcmp (o->name, ".ARM.attributes") == 0)
4290 {
4291 for (p = o->map_head.link_order; p != NULL; p = p->next)
4292 {
4293 asection *input_section;
4294
4295 if (p->type != bfd_indirect_link_order)
4296 continue;
4297 input_section = p->u.indirect.section;
4298 /* Hack: reset the SEC_HAS_CONTENTS flag so that
4299 elf_link_input_bfd ignores this section. */
4300 input_section->flags &= ~SEC_HAS_CONTENTS;
4301 }
4302
4303 size = elf32_arm_eabi_attr_size (abfd);
4304 bfd_set_section_size (abfd, o, size);
4305 attr_section = o;
4306 /* Skip this section later on. */
4307 o->map_head.link_order = NULL;
4308 }
4309 }
4310 /* Invoke the ELF linker to do all the work. */
4311 if (!bfd_elf_final_link (abfd, info))
4312 return FALSE;
4313
4314 if (attr_section)
4315 {
4316 contents = bfd_malloc(size);
4317 if (contents == NULL)
4318 return FALSE;
4319 elf32_arm_set_eabi_attr_contents (abfd, contents, size);
4320 bfd_set_section_contents (abfd, attr_section, contents, 0, size);
4321 free (contents);
4322 }
4323 return TRUE;
4324 }
4325
4326
4327 /* Add INCREMENT to the reloc (of type HOWTO) at ADDRESS. */
4328 static void
arm_add_to_rel(bfd * abfd,bfd_byte * address,reloc_howto_type * howto,bfd_signed_vma increment)4329 arm_add_to_rel (bfd * abfd,
4330 bfd_byte * address,
4331 reloc_howto_type * howto,
4332 bfd_signed_vma increment)
4333 {
4334 bfd_signed_vma addend;
4335
4336 if (howto->type == R_ARM_THM_CALL)
4337 {
4338 int upper_insn, lower_insn;
4339 int upper, lower;
4340
4341 upper_insn = bfd_get_16 (abfd, address);
4342 lower_insn = bfd_get_16 (abfd, address + 2);
4343 upper = upper_insn & 0x7ff;
4344 lower = lower_insn & 0x7ff;
4345
4346 addend = (upper << 12) | (lower << 1);
4347 addend += increment;
4348 addend >>= 1;
4349
4350 upper_insn = (upper_insn & 0xf800) | ((addend >> 11) & 0x7ff);
4351 lower_insn = (lower_insn & 0xf800) | (addend & 0x7ff);
4352
4353 bfd_put_16 (abfd, (bfd_vma) upper_insn, address);
4354 bfd_put_16 (abfd, (bfd_vma) lower_insn, address + 2);
4355 }
4356 else
4357 {
4358 bfd_vma contents;
4359
4360 contents = bfd_get_32 (abfd, address);
4361
4362 /* Get the (signed) value from the instruction. */
4363 addend = contents & howto->src_mask;
4364 if (addend & ((howto->src_mask + 1) >> 1))
4365 {
4366 bfd_signed_vma mask;
4367
4368 mask = -1;
4369 mask &= ~ howto->src_mask;
4370 addend |= mask;
4371 }
4372
4373 /* Add in the increment, (which is a byte value). */
4374 switch (howto->type)
4375 {
4376 default:
4377 addend += increment;
4378 break;
4379
4380 case R_ARM_PC24:
4381 case R_ARM_PLT32:
4382 case R_ARM_CALL:
4383 case R_ARM_JUMP24:
4384 addend <<= howto->size;
4385 addend += increment;
4386
4387 /* Should we check for overflow here ? */
4388
4389 /* Drop any undesired bits. */
4390 addend >>= howto->rightshift;
4391 break;
4392 }
4393
4394 contents = (contents & ~ howto->dst_mask) | (addend & howto->dst_mask);
4395
4396 bfd_put_32 (abfd, contents, address);
4397 }
4398 }
4399
4400 #define IS_ARM_TLS_RELOC(R_TYPE) \
4401 ((R_TYPE) == R_ARM_TLS_GD32 \
4402 || (R_TYPE) == R_ARM_TLS_LDO32 \
4403 || (R_TYPE) == R_ARM_TLS_LDM32 \
4404 || (R_TYPE) == R_ARM_TLS_DTPOFF32 \
4405 || (R_TYPE) == R_ARM_TLS_DTPMOD32 \
4406 || (R_TYPE) == R_ARM_TLS_TPOFF32 \
4407 || (R_TYPE) == R_ARM_TLS_LE32 \
4408 || (R_TYPE) == R_ARM_TLS_IE32)
4409
4410 /* Relocate an ARM ELF section. */
4411 static bfd_boolean
elf32_arm_relocate_section(bfd * output_bfd,struct bfd_link_info * info,bfd * input_bfd,asection * input_section,bfd_byte * contents,Elf_Internal_Rela * relocs,Elf_Internal_Sym * local_syms,asection ** local_sections)4412 elf32_arm_relocate_section (bfd * output_bfd,
4413 struct bfd_link_info * info,
4414 bfd * input_bfd,
4415 asection * input_section,
4416 bfd_byte * contents,
4417 Elf_Internal_Rela * relocs,
4418 Elf_Internal_Sym * local_syms,
4419 asection ** local_sections)
4420 {
4421 Elf_Internal_Shdr *symtab_hdr;
4422 struct elf_link_hash_entry **sym_hashes;
4423 Elf_Internal_Rela *rel;
4424 Elf_Internal_Rela *relend;
4425 const char *name;
4426 struct elf32_arm_link_hash_table * globals;
4427
4428 globals = elf32_arm_hash_table (info);
4429 if (info->relocatable && !globals->use_rel)
4430 return TRUE;
4431
4432 symtab_hdr = & elf_tdata (input_bfd)->symtab_hdr;
4433 sym_hashes = elf_sym_hashes (input_bfd);
4434
4435 rel = relocs;
4436 relend = relocs + input_section->reloc_count;
4437 for (; rel < relend; rel++)
4438 {
4439 int r_type;
4440 reloc_howto_type * howto;
4441 unsigned long r_symndx;
4442 Elf_Internal_Sym * sym;
4443 asection * sec;
4444 struct elf_link_hash_entry * h;
4445 bfd_vma relocation;
4446 bfd_reloc_status_type r;
4447 arelent bfd_reloc;
4448 char sym_type;
4449 bfd_boolean unresolved_reloc = FALSE;
4450
4451 r_symndx = ELF32_R_SYM (rel->r_info);
4452 r_type = ELF32_R_TYPE (rel->r_info);
4453 r_type = arm_real_reloc_type (globals, r_type);
4454
4455 if ( r_type == R_ARM_GNU_VTENTRY
4456 || r_type == R_ARM_GNU_VTINHERIT)
4457 continue;
4458
4459 bfd_reloc.howto = elf32_arm_howto_from_type (r_type);
4460 howto = bfd_reloc.howto;
4461
4462 if (info->relocatable && globals->use_rel)
4463 {
4464 /* This is a relocatable link. We don't have to change
4465 anything, unless the reloc is against a section symbol,
4466 in which case we have to adjust according to where the
4467 section symbol winds up in the output section. */
4468 if (r_symndx < symtab_hdr->sh_info)
4469 {
4470 sym = local_syms + r_symndx;
4471 if (ELF_ST_TYPE (sym->st_info) == STT_SECTION)
4472 {
4473 sec = local_sections[r_symndx];
4474 arm_add_to_rel (input_bfd, contents + rel->r_offset,
4475 howto,
4476 (bfd_signed_vma) (sec->output_offset
4477 + sym->st_value));
4478 }
4479 }
4480
4481 continue;
4482 }
4483
4484 /* This is a final link. */
4485 h = NULL;
4486 sym = NULL;
4487 sec = NULL;
4488
4489 if (r_symndx < symtab_hdr->sh_info)
4490 {
4491 sym = local_syms + r_symndx;
4492 sym_type = ELF32_ST_TYPE (sym->st_info);
4493 sec = local_sections[r_symndx];
4494 if (globals->use_rel)
4495 {
4496 relocation = (sec->output_section->vma
4497 + sec->output_offset
4498 + sym->st_value);
4499 if ((sec->flags & SEC_MERGE)
4500 && ELF_ST_TYPE (sym->st_info) == STT_SECTION)
4501 {
4502 asection *msec;
4503 bfd_vma addend, value;
4504
4505 if (howto->rightshift)
4506 {
4507 (*_bfd_error_handler)
4508 (_("%B(%A+0x%lx): %s relocation against SEC_MERGE section"),
4509 input_bfd, input_section,
4510 (long) rel->r_offset, howto->name);
4511 return FALSE;
4512 }
4513
4514 value = bfd_get_32 (input_bfd, contents + rel->r_offset);
4515
4516 /* Get the (signed) value from the instruction. */
4517 addend = value & howto->src_mask;
4518 if (addend & ((howto->src_mask + 1) >> 1))
4519 {
4520 bfd_signed_vma mask;
4521
4522 mask = -1;
4523 mask &= ~ howto->src_mask;
4524 addend |= mask;
4525 }
4526 msec = sec;
4527 addend =
4528 _bfd_elf_rel_local_sym (output_bfd, sym, &msec, addend)
4529 - relocation;
4530 addend += msec->output_section->vma + msec->output_offset;
4531 value = (value & ~ howto->dst_mask) | (addend & howto->dst_mask);
4532 bfd_put_32 (input_bfd, value, contents + rel->r_offset);
4533 }
4534 }
4535 else
4536 relocation = _bfd_elf_rela_local_sym (output_bfd, sym, &sec, rel);
4537 }
4538 else
4539 {
4540 bfd_boolean warned;
4541
4542 RELOC_FOR_GLOBAL_SYMBOL (info, input_bfd, input_section, rel,
4543 r_symndx, symtab_hdr, sym_hashes,
4544 h, sec, relocation,
4545 unresolved_reloc, warned);
4546
4547 sym_type = h->type;
4548 }
4549
4550 if (h != NULL)
4551 name = h->root.root.string;
4552 else
4553 {
4554 name = (bfd_elf_string_from_elf_section
4555 (input_bfd, symtab_hdr->sh_link, sym->st_name));
4556 if (name == NULL || *name == '\0')
4557 name = bfd_section_name (input_bfd, sec);
4558 }
4559
4560 if (r_symndx != 0
4561 && r_type != R_ARM_NONE
4562 && (h == NULL
4563 || h->root.type == bfd_link_hash_defined
4564 || h->root.type == bfd_link_hash_defweak)
4565 && IS_ARM_TLS_RELOC (r_type) != (sym_type == STT_TLS))
4566 {
4567 (*_bfd_error_handler)
4568 ((sym_type == STT_TLS
4569 ? _("%B(%A+0x%lx): %s used with TLS symbol %s")
4570 : _("%B(%A+0x%lx): %s used with non-TLS symbol %s")),
4571 input_bfd,
4572 input_section,
4573 (long) rel->r_offset,
4574 howto->name,
4575 name);
4576 }
4577
4578 r = elf32_arm_final_link_relocate (howto, input_bfd, output_bfd,
4579 input_section, contents, rel,
4580 relocation, info, sec, name,
4581 (h ? ELF_ST_TYPE (h->type) :
4582 ELF_ST_TYPE (sym->st_info)), h,
4583 &unresolved_reloc);
4584
4585 /* Dynamic relocs are not propagated for SEC_DEBUGGING sections
4586 because such sections are not SEC_ALLOC and thus ld.so will
4587 not process them. */
4588 if (unresolved_reloc
4589 && !((input_section->flags & SEC_DEBUGGING) != 0
4590 && h->def_dynamic))
4591 {
4592 (*_bfd_error_handler)
4593 (_("%B(%A+0x%lx): unresolvable %s relocation against symbol `%s'"),
4594 input_bfd,
4595 input_section,
4596 (long) rel->r_offset,
4597 howto->name,
4598 h->root.root.string);
4599 return FALSE;
4600 }
4601
4602 if (r != bfd_reloc_ok)
4603 {
4604 const char * msg = (const char *) 0;
4605
4606 switch (r)
4607 {
4608 case bfd_reloc_overflow:
4609 /* If the overflowing reloc was to an undefined symbol,
4610 we have already printed one error message and there
4611 is no point complaining again. */
4612 if ((! h ||
4613 h->root.type != bfd_link_hash_undefined)
4614 && (!((*info->callbacks->reloc_overflow)
4615 (info, (h ? &h->root : NULL), name, howto->name,
4616 (bfd_vma) 0, input_bfd, input_section,
4617 rel->r_offset))))
4618 return FALSE;
4619 break;
4620
4621 case bfd_reloc_undefined:
4622 if (!((*info->callbacks->undefined_symbol)
4623 (info, name, input_bfd, input_section,
4624 rel->r_offset, TRUE)))
4625 return FALSE;
4626 break;
4627
4628 case bfd_reloc_outofrange:
4629 msg = _("internal error: out of range error");
4630 goto common_error;
4631
4632 case bfd_reloc_notsupported:
4633 msg = _("internal error: unsupported relocation error");
4634 goto common_error;
4635
4636 case bfd_reloc_dangerous:
4637 msg = _("internal error: dangerous error");
4638 goto common_error;
4639
4640 default:
4641 msg = _("internal error: unknown error");
4642 /* fall through */
4643
4644 common_error:
4645 if (!((*info->callbacks->warning)
4646 (info, msg, name, input_bfd, input_section,
4647 rel->r_offset)))
4648 return FALSE;
4649 break;
4650 }
4651 }
4652 }
4653
4654 return TRUE;
4655 }
4656
4657 /* Allocate/find an object attribute. */
4658 static aeabi_attribute *
elf32_arm_new_eabi_attr(bfd * abfd,int tag)4659 elf32_arm_new_eabi_attr (bfd *abfd, int tag)
4660 {
4661 aeabi_attribute *attr;
4662 aeabi_attribute_list *list;
4663 aeabi_attribute_list *p;
4664 aeabi_attribute_list **lastp;
4665
4666
4667 if (tag < NUM_KNOWN_ATTRIBUTES)
4668 {
4669 /* Knwon tags are preallocated. */
4670 attr = &elf32_arm_tdata (abfd)->known_eabi_attributes[tag];
4671 }
4672 else
4673 {
4674 /* Create a new tag. */
4675 list = (aeabi_attribute_list *)
4676 bfd_alloc (abfd, sizeof (aeabi_attribute_list));
4677 memset (list, 0, sizeof (aeabi_attribute_list));
4678 list->tag = tag;
4679 /* Keep the tag list in order. */
4680 lastp = &elf32_arm_tdata (abfd)->other_eabi_attributes;
4681 for (p = *lastp; p; p = p->next)
4682 {
4683 if (tag < p->tag)
4684 break;
4685 lastp = &p->next;
4686 }
4687 list->next = *lastp;
4688 *lastp = list;
4689 attr = &list->attr;
4690 }
4691
4692 return attr;
4693 }
4694
4695 int
elf32_arm_get_eabi_attr_int(bfd * abfd,int tag)4696 elf32_arm_get_eabi_attr_int (bfd *abfd, int tag)
4697 {
4698 aeabi_attribute_list *p;
4699
4700 if (tag < NUM_KNOWN_ATTRIBUTES)
4701 {
4702 /* Knwon tags are preallocated. */
4703 return elf32_arm_tdata (abfd)->known_eabi_attributes[tag].i;
4704 }
4705 else
4706 {
4707 for (p = elf32_arm_tdata (abfd)->other_eabi_attributes;
4708 p;
4709 p = p->next)
4710 {
4711 if (tag == p->tag)
4712 return p->attr.i;
4713 if (tag < p->tag)
4714 break;
4715 }
4716 return 0;
4717 }
4718 }
4719
4720 void
elf32_arm_add_eabi_attr_int(bfd * abfd,int tag,unsigned int i)4721 elf32_arm_add_eabi_attr_int (bfd *abfd, int tag, unsigned int i)
4722 {
4723 aeabi_attribute *attr;
4724
4725 attr = elf32_arm_new_eabi_attr (abfd, tag);
4726 attr->type = 1;
4727 attr->i = i;
4728 }
4729
4730 static char *
attr_strdup(bfd * abfd,const char * s)4731 attr_strdup (bfd *abfd, const char * s)
4732 {
4733 char * p;
4734 int len;
4735
4736 len = strlen (s) + 1;
4737 p = (char *)bfd_alloc(abfd, len);
4738 return memcpy (p, s, len);
4739 }
4740
4741 void
elf32_arm_add_eabi_attr_string(bfd * abfd,int tag,const char * s)4742 elf32_arm_add_eabi_attr_string (bfd *abfd, int tag, const char *s)
4743 {
4744 aeabi_attribute *attr;
4745
4746 attr = elf32_arm_new_eabi_attr (abfd, tag);
4747 attr->type = 2;
4748 attr->s = attr_strdup (abfd, s);
4749 }
4750
4751 void
elf32_arm_add_eabi_attr_compat(bfd * abfd,unsigned int i,const char * s)4752 elf32_arm_add_eabi_attr_compat (bfd *abfd, unsigned int i, const char *s)
4753 {
4754 aeabi_attribute_list *list;
4755 aeabi_attribute_list *p;
4756 aeabi_attribute_list **lastp;
4757
4758 list = (aeabi_attribute_list *)
4759 bfd_alloc (abfd, sizeof (aeabi_attribute_list));
4760 memset (list, 0, sizeof (aeabi_attribute_list));
4761 list->tag = Tag_compatibility;
4762 list->attr.type = 3;
4763 list->attr.i = i;
4764 list->attr.s = attr_strdup (abfd, s);
4765
4766 lastp = &elf32_arm_tdata (abfd)->other_eabi_attributes;
4767 for (p = *lastp; p; p = p->next)
4768 {
4769 int cmp;
4770 if (p->tag != Tag_compatibility)
4771 break;
4772 cmp = strcmp(s, p->attr.s);
4773 if (cmp < 0 || (cmp == 0 && i < p->attr.i))
4774 break;
4775 lastp = &p->next;
4776 }
4777 list->next = *lastp;
4778 *lastp = list;
4779 }
4780
4781 /* Set the right machine number. */
4782
4783 static bfd_boolean
elf32_arm_object_p(bfd * abfd)4784 elf32_arm_object_p (bfd *abfd)
4785 {
4786 unsigned int mach;
4787
4788 mach = bfd_arm_get_mach_from_notes (abfd, ARM_NOTE_SECTION);
4789
4790 if (mach != bfd_mach_arm_unknown)
4791 bfd_default_set_arch_mach (abfd, bfd_arch_arm, mach);
4792
4793 else if (elf_elfheader (abfd)->e_flags & EF_ARM_MAVERICK_FLOAT)
4794 bfd_default_set_arch_mach (abfd, bfd_arch_arm, bfd_mach_arm_ep9312);
4795
4796 else
4797 bfd_default_set_arch_mach (abfd, bfd_arch_arm, mach);
4798
4799 return TRUE;
4800 }
4801
4802 /* Function to keep ARM specific flags in the ELF header. */
4803
4804 static bfd_boolean
elf32_arm_set_private_flags(bfd * abfd,flagword flags)4805 elf32_arm_set_private_flags (bfd *abfd, flagword flags)
4806 {
4807 if (elf_flags_init (abfd)
4808 && elf_elfheader (abfd)->e_flags != flags)
4809 {
4810 if (EF_ARM_EABI_VERSION (flags) == EF_ARM_EABI_UNKNOWN)
4811 {
4812 if (flags & EF_ARM_INTERWORK)
4813 (*_bfd_error_handler)
4814 (_("Warning: Not setting interworking flag of %B since it has already been specified as non-interworking"),
4815 abfd);
4816 else
4817 _bfd_error_handler
4818 (_("Warning: Clearing the interworking flag of %B due to outside request"),
4819 abfd);
4820 }
4821 }
4822 else
4823 {
4824 elf_elfheader (abfd)->e_flags = flags;
4825 elf_flags_init (abfd) = TRUE;
4826 }
4827
4828 return TRUE;
4829 }
4830
4831 /* Copy the eabi object attribute from IBFD to OBFD. */
4832 static void
copy_eabi_attributes(bfd * ibfd,bfd * obfd)4833 copy_eabi_attributes (bfd *ibfd, bfd *obfd)
4834 {
4835 aeabi_attribute *in_attr;
4836 aeabi_attribute *out_attr;
4837 aeabi_attribute_list *list;
4838 int i;
4839
4840 in_attr = elf32_arm_tdata (ibfd)->known_eabi_attributes;
4841 out_attr = elf32_arm_tdata (obfd)->known_eabi_attributes;
4842 for (i = 4; i < NUM_KNOWN_ATTRIBUTES; i++)
4843 {
4844 out_attr->i = in_attr->i;
4845 if (in_attr->s && *in_attr->s)
4846 out_attr->s = attr_strdup (obfd, in_attr->s);
4847 in_attr++;
4848 out_attr++;
4849 }
4850
4851 for (list = elf32_arm_tdata (ibfd)->other_eabi_attributes;
4852 list;
4853 list = list->next)
4854 {
4855 in_attr = &list->attr;
4856 switch (in_attr->type)
4857 {
4858 case 1:
4859 elf32_arm_add_eabi_attr_int (obfd, list->tag, in_attr->i);
4860 break;
4861 case 2:
4862 elf32_arm_add_eabi_attr_string (obfd, list->tag, in_attr->s);
4863 break;
4864 case 3:
4865 elf32_arm_add_eabi_attr_compat (obfd, in_attr->i, in_attr->s);
4866 break;
4867 default:
4868 abort();
4869 }
4870 }
4871 }
4872
4873
4874 /* Copy backend specific data from one object module to another. */
4875
4876 static bfd_boolean
elf32_arm_copy_private_bfd_data(bfd * ibfd,bfd * obfd)4877 elf32_arm_copy_private_bfd_data (bfd *ibfd, bfd *obfd)
4878 {
4879 flagword in_flags;
4880 flagword out_flags;
4881
4882 if ( bfd_get_flavour (ibfd) != bfd_target_elf_flavour
4883 || bfd_get_flavour (obfd) != bfd_target_elf_flavour)
4884 return TRUE;
4885
4886 in_flags = elf_elfheader (ibfd)->e_flags;
4887 out_flags = elf_elfheader (obfd)->e_flags;
4888
4889 if (elf_flags_init (obfd)
4890 && EF_ARM_EABI_VERSION (out_flags) == EF_ARM_EABI_UNKNOWN
4891 && in_flags != out_flags)
4892 {
4893 /* Cannot mix APCS26 and APCS32 code. */
4894 if ((in_flags & EF_ARM_APCS_26) != (out_flags & EF_ARM_APCS_26))
4895 return FALSE;
4896
4897 /* Cannot mix float APCS and non-float APCS code. */
4898 if ((in_flags & EF_ARM_APCS_FLOAT) != (out_flags & EF_ARM_APCS_FLOAT))
4899 return FALSE;
4900
4901 /* If the src and dest have different interworking flags
4902 then turn off the interworking bit. */
4903 if ((in_flags & EF_ARM_INTERWORK) != (out_flags & EF_ARM_INTERWORK))
4904 {
4905 if (out_flags & EF_ARM_INTERWORK)
4906 _bfd_error_handler
4907 (_("Warning: Clearing the interworking flag of %B because non-interworking code in %B has been linked with it"),
4908 obfd, ibfd);
4909
4910 in_flags &= ~EF_ARM_INTERWORK;
4911 }
4912
4913 /* Likewise for PIC, though don't warn for this case. */
4914 if ((in_flags & EF_ARM_PIC) != (out_flags & EF_ARM_PIC))
4915 in_flags &= ~EF_ARM_PIC;
4916 }
4917
4918 elf_elfheader (obfd)->e_flags = in_flags;
4919 elf_flags_init (obfd) = TRUE;
4920
4921 /* Also copy the EI_OSABI field. */
4922 elf_elfheader (obfd)->e_ident[EI_OSABI] =
4923 elf_elfheader (ibfd)->e_ident[EI_OSABI];
4924
4925 /* Copy EABI object attributes. */
4926 copy_eabi_attributes (ibfd, obfd);
4927
4928 return TRUE;
4929 }
4930
4931 /* Values for Tag_ABI_PCS_R9_use. */
4932 enum
4933 {
4934 AEABI_R9_V6,
4935 AEABI_R9_SB,
4936 AEABI_R9_TLS,
4937 AEABI_R9_unused
4938 };
4939
4940 /* Values for Tag_ABI_PCS_RW_data. */
4941 enum
4942 {
4943 AEABI_PCS_RW_data_absolute,
4944 AEABI_PCS_RW_data_PCrel,
4945 AEABI_PCS_RW_data_SBrel,
4946 AEABI_PCS_RW_data_unused
4947 };
4948
4949 /* Values for Tag_ABI_enum_size. */
4950 enum
4951 {
4952 AEABI_enum_unused,
4953 AEABI_enum_short,
4954 AEABI_enum_wide,
4955 AEABI_enum_forced_wide
4956 };
4957
4958 /* Merge EABI object attributes from IBFD into OBFD. Raise an error if there
4959 are conflicting attributes. */
4960 static bfd_boolean
elf32_arm_merge_eabi_attributes(bfd * ibfd,bfd * obfd)4961 elf32_arm_merge_eabi_attributes (bfd *ibfd, bfd *obfd)
4962 {
4963 aeabi_attribute *in_attr;
4964 aeabi_attribute *out_attr;
4965 aeabi_attribute_list *in_list;
4966 aeabi_attribute_list *out_list;
4967 /* Some tags have 0 = don't care, 1 = strong requirement,
4968 2 = weak requirement. */
4969 static const int order_312[3] = {3, 1, 2};
4970 int i;
4971
4972 if (!elf32_arm_tdata (ibfd)->known_eabi_attributes[0].i)
4973 {
4974 /* This is the first object. Copy the attributes. */
4975 copy_eabi_attributes (ibfd, obfd);
4976 return TRUE;
4977 }
4978
4979 /* Use the Tag_null value to indicate the attributes have been
4980 initialized. */
4981 elf32_arm_tdata (ibfd)->known_eabi_attributes[0].i = 1;
4982
4983 in_attr = elf32_arm_tdata (ibfd)->known_eabi_attributes;
4984 out_attr = elf32_arm_tdata (obfd)->known_eabi_attributes;
4985 /* This needs to happen before Tag_ABI_FP_number_model is merged. */
4986 if (in_attr[Tag_ABI_VFP_args].i != out_attr[Tag_ABI_VFP_args].i)
4987 {
4988 /* Ignore mismatches if teh object doesn't use floating point. */
4989 if (out_attr[Tag_ABI_FP_number_model].i == 0)
4990 out_attr[Tag_ABI_VFP_args].i = in_attr[Tag_ABI_VFP_args].i;
4991 else if (in_attr[Tag_ABI_FP_number_model].i != 0)
4992 {
4993 _bfd_error_handler
4994 (_("ERROR: %B uses VFP register arguments, %B does not"),
4995 ibfd, obfd);
4996 return FALSE;
4997 }
4998 }
4999
5000 for (i = 4; i < NUM_KNOWN_ATTRIBUTES; i++)
5001 {
5002 /* Merge this attribute with existing attributes. */
5003 switch (i)
5004 {
5005 case Tag_CPU_raw_name:
5006 case Tag_CPU_name:
5007 /* Use whichever has the greatest architecture requirements. */
5008 if (in_attr[Tag_CPU_arch].i > out_attr[Tag_CPU_arch].i)
5009 out_attr[i].s = attr_strdup(obfd, in_attr[i].s);
5010 break;
5011
5012 case Tag_ABI_optimization_goals:
5013 case Tag_ABI_FP_optimization_goals:
5014 /* Use the first value seen. */
5015 break;
5016
5017 case Tag_CPU_arch:
5018 case Tag_ARM_ISA_use:
5019 case Tag_THUMB_ISA_use:
5020 case Tag_VFP_arch:
5021 case Tag_WMMX_arch:
5022 case Tag_NEON_arch:
5023 /* ??? Do NEON and WMMX conflict? */
5024 case Tag_ABI_FP_rounding:
5025 case Tag_ABI_FP_denormal:
5026 case Tag_ABI_FP_exceptions:
5027 case Tag_ABI_FP_user_exceptions:
5028 case Tag_ABI_FP_number_model:
5029 case Tag_ABI_align8_preserved:
5030 case Tag_ABI_HardFP_use:
5031 /* Use the largest value specified. */
5032 if (in_attr[i].i > out_attr[i].i)
5033 out_attr[i].i = in_attr[i].i;
5034 break;
5035
5036 case Tag_CPU_arch_profile:
5037 /* Warn if conflicting architecture profiles used. */
5038 if (out_attr[i].i && in_attr[i].i && in_attr[i].i != out_attr[i].i)
5039 {
5040 _bfd_error_handler
5041 (_("ERROR: %B: Conflicting architecture profiles %c/%c"),
5042 ibfd, in_attr[i].i, out_attr[i].i);
5043 return FALSE;
5044 }
5045 if (in_attr[i].i)
5046 out_attr[i].i = in_attr[i].i;
5047 break;
5048 case Tag_PCS_config:
5049 if (out_attr[i].i == 0)
5050 out_attr[i].i = in_attr[i].i;
5051 else if (in_attr[i].i != 0 && out_attr[i].i != 0)
5052 {
5053 /* It's sometimes ok to mix different configs, so this is only
5054 a warning. */
5055 _bfd_error_handler
5056 (_("Warning: %B: Conflicting platform configuration"), ibfd);
5057 }
5058 break;
5059 case Tag_ABI_PCS_R9_use:
5060 if (out_attr[i].i != AEABI_R9_unused
5061 && in_attr[i].i != AEABI_R9_unused)
5062 {
5063 _bfd_error_handler
5064 (_("ERROR: %B: Conflicting use of R9"), ibfd);
5065 return FALSE;
5066 }
5067 if (out_attr[i].i == AEABI_R9_unused)
5068 out_attr[i].i = in_attr[i].i;
5069 break;
5070 case Tag_ABI_PCS_RW_data:
5071 if (in_attr[i].i == AEABI_PCS_RW_data_SBrel
5072 && out_attr[Tag_ABI_PCS_R9_use].i != AEABI_R9_SB
5073 && out_attr[Tag_ABI_PCS_R9_use].i != AEABI_R9_unused)
5074 {
5075 _bfd_error_handler
5076 (_("ERROR: %B: SB relative addressing conflicts with use of R9"),
5077 ibfd);
5078 return FALSE;
5079 }
5080 /* Use the smallest value specified. */
5081 if (in_attr[i].i < out_attr[i].i)
5082 out_attr[i].i = in_attr[i].i;
5083 break;
5084 case Tag_ABI_PCS_RO_data:
5085 /* Use the smallest value specified. */
5086 if (in_attr[i].i < out_attr[i].i)
5087 out_attr[i].i = in_attr[i].i;
5088 break;
5089 case Tag_ABI_PCS_GOT_use:
5090 if (in_attr[i].i > 2 || out_attr[i].i > 2
5091 || order_312[in_attr[i].i] < order_312[out_attr[i].i])
5092 out_attr[i].i = in_attr[i].i;
5093 break;
5094 case Tag_ABI_PCS_wchar_t:
5095 if (out_attr[i].i && in_attr[i].i && out_attr[i].i != in_attr[i].i)
5096 {
5097 _bfd_error_handler
5098 (_("ERROR: %B: Conflicting definitions of wchar_t"), ibfd);
5099 return FALSE;
5100 }
5101 if (in_attr[i].i)
5102 out_attr[i].i = in_attr[i].i;
5103 break;
5104 case Tag_ABI_align8_needed:
5105 /* ??? Check against Tag_ABI_align8_preserved. */
5106 if (in_attr[i].i > 2 || out_attr[i].i > 2
5107 || order_312[in_attr[i].i] < order_312[out_attr[i].i])
5108 out_attr[i].i = in_attr[i].i;
5109 break;
5110 case Tag_ABI_enum_size:
5111 if (in_attr[i].i != AEABI_enum_unused)
5112 {
5113 if (out_attr[i].i == AEABI_enum_unused
5114 || out_attr[i].i == AEABI_enum_forced_wide)
5115 {
5116 /* The existing object is compatible with anything.
5117 Use whatever requirements the new object has. */
5118 out_attr[i].i = in_attr[i].i;
5119 }
5120 else if (in_attr[i].i != AEABI_enum_forced_wide
5121 && out_attr[i].i != in_attr[i].i)
5122 {
5123 _bfd_error_handler
5124 (_("ERROR: %B: Conflicting enum sizes"), ibfd);
5125 }
5126 }
5127 break;
5128 case Tag_ABI_VFP_args:
5129 /* Aready done. */
5130 break;
5131 case Tag_ABI_WMMX_args:
5132 if (in_attr[i].i != out_attr[i].i)
5133 {
5134 _bfd_error_handler
5135 (_("ERROR: %B uses iWMMXt register arguments, %B does not"),
5136 ibfd, obfd);
5137 return FALSE;
5138 }
5139 break;
5140 default: /* All known attributes should be explicitly covered. */
5141 abort ();
5142 }
5143 }
5144
5145 in_list = elf32_arm_tdata (ibfd)->other_eabi_attributes;
5146 out_list = elf32_arm_tdata (ibfd)->other_eabi_attributes;
5147 while (in_list && in_list->tag == Tag_compatibility)
5148 {
5149 in_attr = &in_list->attr;
5150 if (in_attr->i == 0)
5151 continue;
5152 if (in_attr->i == 1)
5153 {
5154 _bfd_error_handler
5155 (_("ERROR: %B: Must be processed by '%s' toolchain"),
5156 ibfd, in_attr->s);
5157 return FALSE;
5158 }
5159 if (!out_list || out_list->tag != Tag_compatibility
5160 || strcmp (in_attr->s, out_list->attr.s) != 0)
5161 {
5162 /* Add this compatibility tag to the output. */
5163 elf32_arm_add_eabi_attr_compat (obfd, in_attr->i, in_attr->s);
5164 continue;
5165 }
5166 out_attr = &out_list->attr;
5167 /* Check all the input tags with the same identifier. */
5168 for (;;)
5169 {
5170 if (out_list->tag != Tag_compatibility
5171 || in_attr->i != out_attr->i
5172 || strcmp (in_attr->s, out_attr->s) != 0)
5173 {
5174 _bfd_error_handler
5175 (_("ERROR: %B: Incompatible object tag '%s':%d"),
5176 ibfd, in_attr->s, in_attr->i);
5177 return FALSE;
5178 }
5179 in_list = in_list->next;
5180 if (in_list->tag != Tag_compatibility
5181 || strcmp (in_attr->s, in_list->attr.s) != 0)
5182 break;
5183 in_attr = &in_list->attr;
5184 out_list = out_list->next;
5185 if (out_list)
5186 out_attr = &out_list->attr;
5187 }
5188
5189 /* Check the output doesn't have extra tags with this identifier. */
5190 if (out_list && out_list->tag == Tag_compatibility
5191 && strcmp (in_attr->s, out_list->attr.s) == 0)
5192 {
5193 _bfd_error_handler
5194 (_("ERROR: %B: Incompatible object tag '%s':%d"),
5195 ibfd, in_attr->s, out_list->attr.i);
5196 return FALSE;
5197 }
5198 }
5199
5200 for (; in_list; in_list = in_list->next)
5201 {
5202 if ((in_list->tag & 128) < 64)
5203 {
5204 _bfd_error_handler
5205 (_("Warning: %B: Unknown EABI object attribute %d"),
5206 ibfd, in_list->tag);
5207 break;
5208 }
5209 }
5210 return TRUE;
5211 }
5212
5213
5214 /* Return TRUE if the two EABI versions are incompatible. */
5215
5216 static bfd_boolean
elf32_arm_versions_compatible(unsigned iver,unsigned over)5217 elf32_arm_versions_compatible (unsigned iver, unsigned over)
5218 {
5219 /* v4 and v5 are the same spec before and after it was released,
5220 so allow mixing them. */
5221 if ((iver == EF_ARM_EABI_VER4 && over == EF_ARM_EABI_VER5)
5222 || (iver == EF_ARM_EABI_VER5 && over == EF_ARM_EABI_VER4))
5223 return TRUE;
5224
5225 return (iver == over);
5226 }
5227
5228 /* Merge backend specific data from an object file to the output
5229 object file when linking. */
5230
5231 static bfd_boolean
elf32_arm_merge_private_bfd_data(bfd * ibfd,bfd * obfd)5232 elf32_arm_merge_private_bfd_data (bfd * ibfd, bfd * obfd)
5233 {
5234 flagword out_flags;
5235 flagword in_flags;
5236 bfd_boolean flags_compatible = TRUE;
5237 asection *sec;
5238
5239 /* Check if we have the same endianess. */
5240 if (! _bfd_generic_verify_endian_match (ibfd, obfd))
5241 return FALSE;
5242
5243 if ( bfd_get_flavour (ibfd) != bfd_target_elf_flavour
5244 || bfd_get_flavour (obfd) != bfd_target_elf_flavour)
5245 return TRUE;
5246
5247 if (!elf32_arm_merge_eabi_attributes (ibfd, obfd))
5248 return FALSE;
5249
5250 /* The input BFD must have had its flags initialised. */
5251 /* The following seems bogus to me -- The flags are initialized in
5252 the assembler but I don't think an elf_flags_init field is
5253 written into the object. */
5254 /* BFD_ASSERT (elf_flags_init (ibfd)); */
5255
5256 in_flags = elf_elfheader (ibfd)->e_flags;
5257 out_flags = elf_elfheader (obfd)->e_flags;
5258
5259 if (!elf_flags_init (obfd))
5260 {
5261 /* If the input is the default architecture and had the default
5262 flags then do not bother setting the flags for the output
5263 architecture, instead allow future merges to do this. If no
5264 future merges ever set these flags then they will retain their
5265 uninitialised values, which surprise surprise, correspond
5266 to the default values. */
5267 if (bfd_get_arch_info (ibfd)->the_default
5268 && elf_elfheader (ibfd)->e_flags == 0)
5269 return TRUE;
5270
5271 elf_flags_init (obfd) = TRUE;
5272 elf_elfheader (obfd)->e_flags = in_flags;
5273
5274 if (bfd_get_arch (obfd) == bfd_get_arch (ibfd)
5275 && bfd_get_arch_info (obfd)->the_default)
5276 return bfd_set_arch_mach (obfd, bfd_get_arch (ibfd), bfd_get_mach (ibfd));
5277
5278 return TRUE;
5279 }
5280
5281 /* Determine what should happen if the input ARM architecture
5282 does not match the output ARM architecture. */
5283 if (! bfd_arm_merge_machines (ibfd, obfd))
5284 return FALSE;
5285
5286 /* Identical flags must be compatible. */
5287 if (in_flags == out_flags)
5288 return TRUE;
5289
5290 /* Check to see if the input BFD actually contains any sections. If
5291 not, its flags may not have been initialised either, but it
5292 cannot actually cause any incompatiblity. Do not short-circuit
5293 dynamic objects; their section list may be emptied by
5294 elf_link_add_object_symbols.
5295
5296 Also check to see if there are no code sections in the input.
5297 In this case there is no need to check for code specific flags.
5298 XXX - do we need to worry about floating-point format compatability
5299 in data sections ? */
5300 if (!(ibfd->flags & DYNAMIC))
5301 {
5302 bfd_boolean null_input_bfd = TRUE;
5303 bfd_boolean only_data_sections = TRUE;
5304
5305 for (sec = ibfd->sections; sec != NULL; sec = sec->next)
5306 {
5307 /* Ignore synthetic glue sections. */
5308 if (strcmp (sec->name, ".glue_7")
5309 && strcmp (sec->name, ".glue_7t"))
5310 {
5311 if ((bfd_get_section_flags (ibfd, sec)
5312 & (SEC_LOAD | SEC_CODE | SEC_HAS_CONTENTS))
5313 == (SEC_LOAD | SEC_CODE | SEC_HAS_CONTENTS))
5314 only_data_sections = FALSE;
5315
5316 null_input_bfd = FALSE;
5317 break;
5318 }
5319 }
5320
5321 if (null_input_bfd || only_data_sections)
5322 return TRUE;
5323 }
5324
5325 /* Complain about various flag mismatches. */
5326 if (!elf32_arm_versions_compatible (EF_ARM_EABI_VERSION (in_flags),
5327 EF_ARM_EABI_VERSION (out_flags)))
5328 {
5329 _bfd_error_handler
5330 (_("ERROR: Source object %B has EABI version %d, but target %B has EABI version %d"),
5331 ibfd, obfd,
5332 (in_flags & EF_ARM_EABIMASK) >> 24,
5333 (out_flags & EF_ARM_EABIMASK) >> 24);
5334 return FALSE;
5335 }
5336
5337 /* Not sure what needs to be checked for EABI versions >= 1. */
5338 /* VxWorks libraries do not use these flags. */
5339 if (get_elf_backend_data (obfd) != &elf32_arm_vxworks_bed
5340 && get_elf_backend_data (ibfd) != &elf32_arm_vxworks_bed
5341 && EF_ARM_EABI_VERSION (in_flags) == EF_ARM_EABI_UNKNOWN)
5342 {
5343 if ((in_flags & EF_ARM_APCS_26) != (out_flags & EF_ARM_APCS_26))
5344 {
5345 _bfd_error_handler
5346 (_("ERROR: %B is compiled for APCS-%d, whereas target %B uses APCS-%d"),
5347 ibfd, obfd,
5348 in_flags & EF_ARM_APCS_26 ? 26 : 32,
5349 out_flags & EF_ARM_APCS_26 ? 26 : 32);
5350 flags_compatible = FALSE;
5351 }
5352
5353 if ((in_flags & EF_ARM_APCS_FLOAT) != (out_flags & EF_ARM_APCS_FLOAT))
5354 {
5355 if (in_flags & EF_ARM_APCS_FLOAT)
5356 _bfd_error_handler
5357 (_("ERROR: %B passes floats in float registers, whereas %B passes them in integer registers"),
5358 ibfd, obfd);
5359 else
5360 _bfd_error_handler
5361 (_("ERROR: %B passes floats in integer registers, whereas %B passes them in float registers"),
5362 ibfd, obfd);
5363
5364 flags_compatible = FALSE;
5365 }
5366
5367 if ((in_flags & EF_ARM_VFP_FLOAT) != (out_flags & EF_ARM_VFP_FLOAT))
5368 {
5369 if (in_flags & EF_ARM_VFP_FLOAT)
5370 _bfd_error_handler
5371 (_("ERROR: %B uses VFP instructions, whereas %B does not"),
5372 ibfd, obfd);
5373 else
5374 _bfd_error_handler
5375 (_("ERROR: %B uses FPA instructions, whereas %B does not"),
5376 ibfd, obfd);
5377
5378 flags_compatible = FALSE;
5379 }
5380
5381 if ((in_flags & EF_ARM_MAVERICK_FLOAT) != (out_flags & EF_ARM_MAVERICK_FLOAT))
5382 {
5383 if (in_flags & EF_ARM_MAVERICK_FLOAT)
5384 _bfd_error_handler
5385 (_("ERROR: %B uses Maverick instructions, whereas %B does not"),
5386 ibfd, obfd);
5387 else
5388 _bfd_error_handler
5389 (_("ERROR: %B does not use Maverick instructions, whereas %B does"),
5390 ibfd, obfd);
5391
5392 flags_compatible = FALSE;
5393 }
5394
5395 #ifdef EF_ARM_SOFT_FLOAT
5396 if ((in_flags & EF_ARM_SOFT_FLOAT) != (out_flags & EF_ARM_SOFT_FLOAT))
5397 {
5398 /* We can allow interworking between code that is VFP format
5399 layout, and uses either soft float or integer regs for
5400 passing floating point arguments and results. We already
5401 know that the APCS_FLOAT flags match; similarly for VFP
5402 flags. */
5403 if ((in_flags & EF_ARM_APCS_FLOAT) != 0
5404 || (in_flags & EF_ARM_VFP_FLOAT) == 0)
5405 {
5406 if (in_flags & EF_ARM_SOFT_FLOAT)
5407 _bfd_error_handler
5408 (_("ERROR: %B uses software FP, whereas %B uses hardware FP"),
5409 ibfd, obfd);
5410 else
5411 _bfd_error_handler
5412 (_("ERROR: %B uses hardware FP, whereas %B uses software FP"),
5413 ibfd, obfd);
5414
5415 flags_compatible = FALSE;
5416 }
5417 }
5418 #endif
5419
5420 /* Interworking mismatch is only a warning. */
5421 if ((in_flags & EF_ARM_INTERWORK) != (out_flags & EF_ARM_INTERWORK))
5422 {
5423 if (in_flags & EF_ARM_INTERWORK)
5424 {
5425 _bfd_error_handler
5426 (_("Warning: %B supports interworking, whereas %B does not"),
5427 ibfd, obfd);
5428 }
5429 else
5430 {
5431 _bfd_error_handler
5432 (_("Warning: %B does not support interworking, whereas %B does"),
5433 ibfd, obfd);
5434 }
5435 }
5436 }
5437
5438 return flags_compatible;
5439 }
5440
5441 /* Display the flags field. */
5442
5443 static bfd_boolean
elf32_arm_print_private_bfd_data(bfd * abfd,void * ptr)5444 elf32_arm_print_private_bfd_data (bfd *abfd, void * ptr)
5445 {
5446 FILE * file = (FILE *) ptr;
5447 unsigned long flags;
5448
5449 BFD_ASSERT (abfd != NULL && ptr != NULL);
5450
5451 /* Print normal ELF private data. */
5452 _bfd_elf_print_private_bfd_data (abfd, ptr);
5453
5454 flags = elf_elfheader (abfd)->e_flags;
5455 /* Ignore init flag - it may not be set, despite the flags field
5456 containing valid data. */
5457
5458 /* xgettext:c-format */
5459 fprintf (file, _("private flags = %lx:"), elf_elfheader (abfd)->e_flags);
5460
5461 switch (EF_ARM_EABI_VERSION (flags))
5462 {
5463 case EF_ARM_EABI_UNKNOWN:
5464 /* The following flag bits are GNU extensions and not part of the
5465 official ARM ELF extended ABI. Hence they are only decoded if
5466 the EABI version is not set. */
5467 if (flags & EF_ARM_INTERWORK)
5468 fprintf (file, _(" [interworking enabled]"));
5469
5470 if (flags & EF_ARM_APCS_26)
5471 fprintf (file, " [APCS-26]");
5472 else
5473 fprintf (file, " [APCS-32]");
5474
5475 if (flags & EF_ARM_VFP_FLOAT)
5476 fprintf (file, _(" [VFP float format]"));
5477 else if (flags & EF_ARM_MAVERICK_FLOAT)
5478 fprintf (file, _(" [Maverick float format]"));
5479 else
5480 fprintf (file, _(" [FPA float format]"));
5481
5482 if (flags & EF_ARM_APCS_FLOAT)
5483 fprintf (file, _(" [floats passed in float registers]"));
5484
5485 if (flags & EF_ARM_PIC)
5486 fprintf (file, _(" [position independent]"));
5487
5488 if (flags & EF_ARM_NEW_ABI)
5489 fprintf (file, _(" [new ABI]"));
5490
5491 if (flags & EF_ARM_OLD_ABI)
5492 fprintf (file, _(" [old ABI]"));
5493
5494 if (flags & EF_ARM_SOFT_FLOAT)
5495 fprintf (file, _(" [software FP]"));
5496
5497 flags &= ~(EF_ARM_INTERWORK | EF_ARM_APCS_26 | EF_ARM_APCS_FLOAT
5498 | EF_ARM_PIC | EF_ARM_NEW_ABI | EF_ARM_OLD_ABI
5499 | EF_ARM_SOFT_FLOAT | EF_ARM_VFP_FLOAT
5500 | EF_ARM_MAVERICK_FLOAT);
5501 break;
5502
5503 case EF_ARM_EABI_VER1:
5504 fprintf (file, _(" [Version1 EABI]"));
5505
5506 if (flags & EF_ARM_SYMSARESORTED)
5507 fprintf (file, _(" [sorted symbol table]"));
5508 else
5509 fprintf (file, _(" [unsorted symbol table]"));
5510
5511 flags &= ~ EF_ARM_SYMSARESORTED;
5512 break;
5513
5514 case EF_ARM_EABI_VER2:
5515 fprintf (file, _(" [Version2 EABI]"));
5516
5517 if (flags & EF_ARM_SYMSARESORTED)
5518 fprintf (file, _(" [sorted symbol table]"));
5519 else
5520 fprintf (file, _(" [unsorted symbol table]"));
5521
5522 if (flags & EF_ARM_DYNSYMSUSESEGIDX)
5523 fprintf (file, _(" [dynamic symbols use segment index]"));
5524
5525 if (flags & EF_ARM_MAPSYMSFIRST)
5526 fprintf (file, _(" [mapping symbols precede others]"));
5527
5528 flags &= ~(EF_ARM_SYMSARESORTED | EF_ARM_DYNSYMSUSESEGIDX
5529 | EF_ARM_MAPSYMSFIRST);
5530 break;
5531
5532 case EF_ARM_EABI_VER3:
5533 fprintf (file, _(" [Version3 EABI]"));
5534 break;
5535
5536 case EF_ARM_EABI_VER4:
5537 fprintf (file, _(" [Version4 EABI]"));
5538 goto eabi;
5539
5540 case EF_ARM_EABI_VER5:
5541 fprintf (file, _(" [Version5 EABI]"));
5542 eabi:
5543 if (flags & EF_ARM_BE8)
5544 fprintf (file, _(" [BE8]"));
5545
5546 if (flags & EF_ARM_LE8)
5547 fprintf (file, _(" [LE8]"));
5548
5549 flags &= ~(EF_ARM_LE8 | EF_ARM_BE8);
5550 break;
5551
5552 default:
5553 fprintf (file, _(" <EABI version unrecognised>"));
5554 break;
5555 }
5556
5557 flags &= ~ EF_ARM_EABIMASK;
5558
5559 if (flags & EF_ARM_RELEXEC)
5560 fprintf (file, _(" [relocatable executable]"));
5561
5562 if (flags & EF_ARM_HASENTRY)
5563 fprintf (file, _(" [has entry point]"));
5564
5565 flags &= ~ (EF_ARM_RELEXEC | EF_ARM_HASENTRY);
5566
5567 if (flags)
5568 fprintf (file, _("<Unrecognised flag bits set>"));
5569
5570 fputc ('\n', file);
5571
5572 return TRUE;
5573 }
5574
5575 static int
elf32_arm_get_symbol_type(Elf_Internal_Sym * elf_sym,int type)5576 elf32_arm_get_symbol_type (Elf_Internal_Sym * elf_sym, int type)
5577 {
5578 switch (ELF_ST_TYPE (elf_sym->st_info))
5579 {
5580 case STT_ARM_TFUNC:
5581 return ELF_ST_TYPE (elf_sym->st_info);
5582
5583 case STT_ARM_16BIT:
5584 /* If the symbol is not an object, return the STT_ARM_16BIT flag.
5585 This allows us to distinguish between data used by Thumb instructions
5586 and non-data (which is probably code) inside Thumb regions of an
5587 executable. */
5588 if (type != STT_OBJECT && type != STT_TLS)
5589 return ELF_ST_TYPE (elf_sym->st_info);
5590 break;
5591
5592 default:
5593 break;
5594 }
5595
5596 return type;
5597 }
5598
5599 static asection *
elf32_arm_gc_mark_hook(asection * sec,struct bfd_link_info * info ATTRIBUTE_UNUSED,Elf_Internal_Rela * rel,struct elf_link_hash_entry * h,Elf_Internal_Sym * sym)5600 elf32_arm_gc_mark_hook (asection * sec,
5601 struct bfd_link_info * info ATTRIBUTE_UNUSED,
5602 Elf_Internal_Rela * rel,
5603 struct elf_link_hash_entry * h,
5604 Elf_Internal_Sym * sym)
5605 {
5606 if (h != NULL)
5607 {
5608 switch (ELF32_R_TYPE (rel->r_info))
5609 {
5610 case R_ARM_GNU_VTINHERIT:
5611 case R_ARM_GNU_VTENTRY:
5612 break;
5613
5614 default:
5615 switch (h->root.type)
5616 {
5617 case bfd_link_hash_defined:
5618 case bfd_link_hash_defweak:
5619 return h->root.u.def.section;
5620
5621 case bfd_link_hash_common:
5622 return h->root.u.c.p->section;
5623
5624 default:
5625 break;
5626 }
5627 }
5628 }
5629 else
5630 return bfd_section_from_elf_index (sec->owner, sym->st_shndx);
5631
5632 return NULL;
5633 }
5634
5635 /* Update the got entry reference counts for the section being removed. */
5636
5637 static bfd_boolean
elf32_arm_gc_sweep_hook(bfd * abfd,struct bfd_link_info * info,asection * sec,const Elf_Internal_Rela * relocs)5638 elf32_arm_gc_sweep_hook (bfd * abfd,
5639 struct bfd_link_info * info,
5640 asection * sec,
5641 const Elf_Internal_Rela * relocs)
5642 {
5643 Elf_Internal_Shdr *symtab_hdr;
5644 struct elf_link_hash_entry **sym_hashes;
5645 bfd_signed_vma *local_got_refcounts;
5646 const Elf_Internal_Rela *rel, *relend;
5647 struct elf32_arm_link_hash_table * globals;
5648
5649 globals = elf32_arm_hash_table (info);
5650
5651 elf_section_data (sec)->local_dynrel = NULL;
5652
5653 symtab_hdr = &elf_tdata (abfd)->symtab_hdr;
5654 sym_hashes = elf_sym_hashes (abfd);
5655 local_got_refcounts = elf_local_got_refcounts (abfd);
5656
5657 relend = relocs + sec->reloc_count;
5658 for (rel = relocs; rel < relend; rel++)
5659 {
5660 unsigned long r_symndx;
5661 struct elf_link_hash_entry *h = NULL;
5662 int r_type;
5663
5664 r_symndx = ELF32_R_SYM (rel->r_info);
5665 if (r_symndx >= symtab_hdr->sh_info)
5666 {
5667 h = sym_hashes[r_symndx - symtab_hdr->sh_info];
5668 while (h->root.type == bfd_link_hash_indirect
5669 || h->root.type == bfd_link_hash_warning)
5670 h = (struct elf_link_hash_entry *) h->root.u.i.link;
5671 }
5672
5673 r_type = ELF32_R_TYPE (rel->r_info);
5674 r_type = arm_real_reloc_type (globals, r_type);
5675 switch (r_type)
5676 {
5677 case R_ARM_GOT32:
5678 case R_ARM_GOT_PREL:
5679 case R_ARM_TLS_GD32:
5680 case R_ARM_TLS_IE32:
5681 if (h != NULL)
5682 {
5683 if (h->got.refcount > 0)
5684 h->got.refcount -= 1;
5685 }
5686 else if (local_got_refcounts != NULL)
5687 {
5688 if (local_got_refcounts[r_symndx] > 0)
5689 local_got_refcounts[r_symndx] -= 1;
5690 }
5691 break;
5692
5693 case R_ARM_TLS_LDM32:
5694 elf32_arm_hash_table (info)->tls_ldm_got.refcount -= 1;
5695 break;
5696
5697 case R_ARM_ABS32:
5698 case R_ARM_REL32:
5699 case R_ARM_PC24:
5700 case R_ARM_PLT32:
5701 case R_ARM_CALL:
5702 case R_ARM_JUMP24:
5703 case R_ARM_PREL31:
5704 case R_ARM_THM_CALL:
5705 case R_ARM_MOVW_ABS_NC:
5706 case R_ARM_MOVT_ABS:
5707 case R_ARM_MOVW_PREL_NC:
5708 case R_ARM_MOVT_PREL:
5709 /* Should the interworking branches be here also? */
5710
5711 if (h != NULL)
5712 {
5713 struct elf32_arm_link_hash_entry *eh;
5714 struct elf32_arm_relocs_copied **pp;
5715 struct elf32_arm_relocs_copied *p;
5716
5717 eh = (struct elf32_arm_link_hash_entry *) h;
5718
5719 if (h->plt.refcount > 0)
5720 {
5721 h->plt.refcount -= 1;
5722 if (ELF32_R_TYPE (rel->r_info) == R_ARM_THM_CALL)
5723 eh->plt_thumb_refcount--;
5724 }
5725
5726 if (r_type == R_ARM_ABS32
5727 || r_type == R_ARM_REL32)
5728 {
5729 for (pp = &eh->relocs_copied; (p = *pp) != NULL;
5730 pp = &p->next)
5731 if (p->section == sec)
5732 {
5733 p->count -= 1;
5734 if (ELF32_R_TYPE (rel->r_info) == R_ARM_REL32)
5735 p->pc_count -= 1;
5736 if (p->count == 0)
5737 *pp = p->next;
5738 break;
5739 }
5740 }
5741 }
5742 break;
5743
5744 default:
5745 break;
5746 }
5747 }
5748
5749 return TRUE;
5750 }
5751
5752 /* Look through the relocs for a section during the first phase. */
5753
5754 static bfd_boolean
elf32_arm_check_relocs(bfd * abfd,struct bfd_link_info * info,asection * sec,const Elf_Internal_Rela * relocs)5755 elf32_arm_check_relocs (bfd *abfd, struct bfd_link_info *info,
5756 asection *sec, const Elf_Internal_Rela *relocs)
5757 {
5758 Elf_Internal_Shdr *symtab_hdr;
5759 struct elf_link_hash_entry **sym_hashes;
5760 struct elf_link_hash_entry **sym_hashes_end;
5761 const Elf_Internal_Rela *rel;
5762 const Elf_Internal_Rela *rel_end;
5763 bfd *dynobj;
5764 asection *sreloc;
5765 bfd_vma *local_got_offsets;
5766 struct elf32_arm_link_hash_table *htab;
5767
5768 if (info->relocatable)
5769 return TRUE;
5770
5771 htab = elf32_arm_hash_table (info);
5772 sreloc = NULL;
5773
5774 /* Create dynamic sections for relocatable executables so that we can
5775 copy relocations. */
5776 if (htab->root.is_relocatable_executable
5777 && ! htab->root.dynamic_sections_created)
5778 {
5779 if (! _bfd_elf_link_create_dynamic_sections (abfd, info))
5780 return FALSE;
5781 }
5782
5783 dynobj = elf_hash_table (info)->dynobj;
5784 local_got_offsets = elf_local_got_offsets (abfd);
5785
5786 symtab_hdr = &elf_tdata (abfd)->symtab_hdr;
5787 sym_hashes = elf_sym_hashes (abfd);
5788 sym_hashes_end = sym_hashes
5789 + symtab_hdr->sh_size / sizeof (Elf32_External_Sym);
5790
5791 if (!elf_bad_symtab (abfd))
5792 sym_hashes_end -= symtab_hdr->sh_info;
5793
5794 rel_end = relocs + sec->reloc_count;
5795 for (rel = relocs; rel < rel_end; rel++)
5796 {
5797 struct elf_link_hash_entry *h;
5798 struct elf32_arm_link_hash_entry *eh;
5799 unsigned long r_symndx;
5800 int r_type;
5801
5802 r_symndx = ELF32_R_SYM (rel->r_info);
5803 r_type = ELF32_R_TYPE (rel->r_info);
5804 r_type = arm_real_reloc_type (htab, r_type);
5805
5806 if (r_symndx >= NUM_SHDR_ENTRIES (symtab_hdr))
5807 {
5808 (*_bfd_error_handler) (_("%B: bad symbol index: %d"), abfd,
5809 r_symndx);
5810 return FALSE;
5811 }
5812
5813 if (r_symndx < symtab_hdr->sh_info)
5814 h = NULL;
5815 else
5816 {
5817 h = sym_hashes[r_symndx - symtab_hdr->sh_info];
5818 while (h->root.type == bfd_link_hash_indirect
5819 || h->root.type == bfd_link_hash_warning)
5820 h = (struct elf_link_hash_entry *) h->root.u.i.link;
5821 }
5822
5823 eh = (struct elf32_arm_link_hash_entry *) h;
5824
5825 switch (r_type)
5826 {
5827 case R_ARM_GOT32:
5828 case R_ARM_GOT_PREL:
5829 case R_ARM_TLS_GD32:
5830 case R_ARM_TLS_IE32:
5831 /* This symbol requires a global offset table entry. */
5832 {
5833 int tls_type, old_tls_type;
5834
5835 switch (r_type)
5836 {
5837 case R_ARM_TLS_GD32: tls_type = GOT_TLS_GD; break;
5838 case R_ARM_TLS_IE32: tls_type = GOT_TLS_IE; break;
5839 default: tls_type = GOT_NORMAL; break;
5840 }
5841
5842 if (h != NULL)
5843 {
5844 h->got.refcount++;
5845 old_tls_type = elf32_arm_hash_entry (h)->tls_type;
5846 }
5847 else
5848 {
5849 bfd_signed_vma *local_got_refcounts;
5850
5851 /* This is a global offset table entry for a local symbol. */
5852 local_got_refcounts = elf_local_got_refcounts (abfd);
5853 if (local_got_refcounts == NULL)
5854 {
5855 bfd_size_type size;
5856
5857 size = symtab_hdr->sh_info;
5858 size *= (sizeof (bfd_signed_vma) + sizeof(char));
5859 local_got_refcounts = bfd_zalloc (abfd, size);
5860 if (local_got_refcounts == NULL)
5861 return FALSE;
5862 elf_local_got_refcounts (abfd) = local_got_refcounts;
5863 elf32_arm_local_got_tls_type (abfd)
5864 = (char *) (local_got_refcounts + symtab_hdr->sh_info);
5865 }
5866 local_got_refcounts[r_symndx] += 1;
5867 old_tls_type = elf32_arm_local_got_tls_type (abfd) [r_symndx];
5868 }
5869
5870 /* We will already have issued an error message if there is a
5871 TLS / non-TLS mismatch, based on the symbol type. We don't
5872 support any linker relaxations. So just combine any TLS
5873 types needed. */
5874 if (old_tls_type != GOT_UNKNOWN && old_tls_type != GOT_NORMAL
5875 && tls_type != GOT_NORMAL)
5876 tls_type |= old_tls_type;
5877
5878 if (old_tls_type != tls_type)
5879 {
5880 if (h != NULL)
5881 elf32_arm_hash_entry (h)->tls_type = tls_type;
5882 else
5883 elf32_arm_local_got_tls_type (abfd) [r_symndx] = tls_type;
5884 }
5885 }
5886 /* Fall through */
5887
5888 case R_ARM_TLS_LDM32:
5889 if (r_type == R_ARM_TLS_LDM32)
5890 htab->tls_ldm_got.refcount++;
5891 /* Fall through */
5892
5893 case R_ARM_GOTOFF32:
5894 case R_ARM_GOTPC:
5895 if (htab->sgot == NULL)
5896 {
5897 if (htab->root.dynobj == NULL)
5898 htab->root.dynobj = abfd;
5899 if (!create_got_section (htab->root.dynobj, info))
5900 return FALSE;
5901 }
5902 break;
5903
5904 case R_ARM_ABS12:
5905 /* VxWorks uses dynamic R_ARM_ABS12 relocations for
5906 ldr __GOTT_INDEX__ offsets. */
5907 if (!htab->vxworks_p)
5908 break;
5909 /* Fall through */
5910
5911 case R_ARM_ABS32:
5912 case R_ARM_REL32:
5913 case R_ARM_PC24:
5914 case R_ARM_PLT32:
5915 case R_ARM_CALL:
5916 case R_ARM_JUMP24:
5917 case R_ARM_PREL31:
5918 case R_ARM_THM_CALL:
5919 case R_ARM_MOVW_ABS_NC:
5920 case R_ARM_MOVT_ABS:
5921 case R_ARM_MOVW_PREL_NC:
5922 case R_ARM_MOVT_PREL:
5923 /* Should the interworking branches be listed here? */
5924 if (h != NULL)
5925 {
5926 /* If this reloc is in a read-only section, we might
5927 need a copy reloc. We can't check reliably at this
5928 stage whether the section is read-only, as input
5929 sections have not yet been mapped to output sections.
5930 Tentatively set the flag for now, and correct in
5931 adjust_dynamic_symbol. */
5932 if (!info->shared)
5933 h->non_got_ref = 1;
5934
5935 /* We may need a .plt entry if the function this reloc
5936 refers to is in a different object. We can't tell for
5937 sure yet, because something later might force the
5938 symbol local. */
5939 if (r_type == R_ARM_PC24
5940 || r_type == R_ARM_CALL
5941 || r_type == R_ARM_JUMP24
5942 || r_type == R_ARM_PREL31
5943 || r_type == R_ARM_PLT32
5944 || r_type == R_ARM_THM_CALL)
5945 h->needs_plt = 1;
5946
5947 /* If we create a PLT entry, this relocation will reference
5948 it, even if it's an ABS32 relocation. */
5949 h->plt.refcount += 1;
5950
5951 if (r_type == R_ARM_THM_CALL)
5952 eh->plt_thumb_refcount += 1;
5953 }
5954
5955 /* If we are creating a shared library or relocatable executable,
5956 and this is a reloc against a global symbol, or a non PC
5957 relative reloc against a local symbol, then we need to copy
5958 the reloc into the shared library. However, if we are linking
5959 with -Bsymbolic, we do not need to copy a reloc against a
5960 global symbol which is defined in an object we are
5961 including in the link (i.e., DEF_REGULAR is set). At
5962 this point we have not seen all the input files, so it is
5963 possible that DEF_REGULAR is not set now but will be set
5964 later (it is never cleared). We account for that
5965 possibility below by storing information in the
5966 relocs_copied field of the hash table entry. */
5967 if ((info->shared || htab->root.is_relocatable_executable)
5968 && (sec->flags & SEC_ALLOC) != 0
5969 && (r_type == R_ARM_ABS32
5970 || (h != NULL && ! h->needs_plt
5971 && (! info->symbolic || ! h->def_regular))))
5972 {
5973 struct elf32_arm_relocs_copied *p, **head;
5974
5975 /* When creating a shared object, we must copy these
5976 reloc types into the output file. We create a reloc
5977 section in dynobj and make room for this reloc. */
5978 if (sreloc == NULL)
5979 {
5980 const char * name;
5981
5982 name = (bfd_elf_string_from_elf_section
5983 (abfd,
5984 elf_elfheader (abfd)->e_shstrndx,
5985 elf_section_data (sec)->rel_hdr.sh_name));
5986 if (name == NULL)
5987 return FALSE;
5988
5989 BFD_ASSERT (reloc_section_p (htab, name, sec));
5990
5991 sreloc = bfd_get_section_by_name (dynobj, name);
5992 if (sreloc == NULL)
5993 {
5994 flagword flags;
5995
5996 flags = (SEC_HAS_CONTENTS | SEC_READONLY
5997 | SEC_IN_MEMORY | SEC_LINKER_CREATED);
5998 if ((sec->flags & SEC_ALLOC) != 0
5999 /* BPABI objects never have dynamic
6000 relocations mapped. */
6001 && !htab->symbian_p)
6002 flags |= SEC_ALLOC | SEC_LOAD;
6003 sreloc = bfd_make_section_with_flags (dynobj,
6004 name,
6005 flags);
6006 if (sreloc == NULL
6007 || ! bfd_set_section_alignment (dynobj, sreloc, 2))
6008 return FALSE;
6009 }
6010
6011 elf_section_data (sec)->sreloc = sreloc;
6012 }
6013
6014 /* If this is a global symbol, we count the number of
6015 relocations we need for this symbol. */
6016 if (h != NULL)
6017 {
6018 head = &((struct elf32_arm_link_hash_entry *) h)->relocs_copied;
6019 }
6020 else
6021 {
6022 /* Track dynamic relocs needed for local syms too.
6023 We really need local syms available to do this
6024 easily. Oh well. */
6025
6026 asection *s;
6027 void *vpp;
6028
6029 s = bfd_section_from_r_symndx (abfd, &htab->sym_sec,
6030 sec, r_symndx);
6031 if (s == NULL)
6032 return FALSE;
6033
6034 vpp = &elf_section_data (s)->local_dynrel;
6035 head = (struct elf32_arm_relocs_copied **) vpp;
6036 }
6037
6038 p = *head;
6039 if (p == NULL || p->section != sec)
6040 {
6041 bfd_size_type amt = sizeof *p;
6042
6043 p = bfd_alloc (htab->root.dynobj, amt);
6044 if (p == NULL)
6045 return FALSE;
6046 p->next = *head;
6047 *head = p;
6048 p->section = sec;
6049 p->count = 0;
6050 p->pc_count = 0;
6051 }
6052
6053 if (r_type == R_ARM_REL32)
6054 p->pc_count += 1;
6055 p->count += 1;
6056 }
6057 break;
6058
6059 /* This relocation describes the C++ object vtable hierarchy.
6060 Reconstruct it for later use during GC. */
6061 case R_ARM_GNU_VTINHERIT:
6062 if (!bfd_elf_gc_record_vtinherit (abfd, sec, h, rel->r_offset))
6063 return FALSE;
6064 break;
6065
6066 /* This relocation describes which C++ vtable entries are actually
6067 used. Record for later use during GC. */
6068 case R_ARM_GNU_VTENTRY:
6069 if (!bfd_elf_gc_record_vtentry (abfd, sec, h, rel->r_offset))
6070 return FALSE;
6071 break;
6072 }
6073 }
6074
6075 return TRUE;
6076 }
6077
6078 /* Treat mapping symbols as special target symbols. */
6079
6080 static bfd_boolean
elf32_arm_is_target_special_symbol(bfd * abfd ATTRIBUTE_UNUSED,asymbol * sym)6081 elf32_arm_is_target_special_symbol (bfd * abfd ATTRIBUTE_UNUSED, asymbol * sym)
6082 {
6083 return bfd_is_arm_mapping_symbol_name (sym->name);
6084 }
6085
6086 /* This is a copy of elf_find_function() from elf.c except that
6087 ARM mapping symbols are ignored when looking for function names
6088 and STT_ARM_TFUNC is considered to a function type. */
6089
6090 static bfd_boolean
arm_elf_find_function(bfd * abfd ATTRIBUTE_UNUSED,asection * section,asymbol ** symbols,bfd_vma offset,const char ** filename_ptr,const char ** functionname_ptr)6091 arm_elf_find_function (bfd * abfd ATTRIBUTE_UNUSED,
6092 asection * section,
6093 asymbol ** symbols,
6094 bfd_vma offset,
6095 const char ** filename_ptr,
6096 const char ** functionname_ptr)
6097 {
6098 const char * filename = NULL;
6099 asymbol * func = NULL;
6100 bfd_vma low_func = 0;
6101 asymbol ** p;
6102
6103 for (p = symbols; *p != NULL; p++)
6104 {
6105 elf_symbol_type *q;
6106
6107 q = (elf_symbol_type *) *p;
6108
6109 switch (ELF_ST_TYPE (q->internal_elf_sym.st_info))
6110 {
6111 default:
6112 break;
6113 case STT_FILE:
6114 filename = bfd_asymbol_name (&q->symbol);
6115 break;
6116 case STT_FUNC:
6117 case STT_ARM_TFUNC:
6118 case STT_NOTYPE:
6119 /* Skip $a and $t symbols. */
6120 if ((q->symbol.flags & BSF_LOCAL)
6121 && bfd_is_arm_mapping_symbol_name (q->symbol.name))
6122 continue;
6123 /* Fall through. */
6124 if (bfd_get_section (&q->symbol) == section
6125 && q->symbol.value >= low_func
6126 && q->symbol.value <= offset)
6127 {
6128 func = (asymbol *) q;
6129 low_func = q->symbol.value;
6130 }
6131 break;
6132 }
6133 }
6134
6135 if (func == NULL)
6136 return FALSE;
6137
6138 if (filename_ptr)
6139 *filename_ptr = filename;
6140 if (functionname_ptr)
6141 *functionname_ptr = bfd_asymbol_name (func);
6142
6143 return TRUE;
6144 }
6145
6146
6147 /* Find the nearest line to a particular section and offset, for error
6148 reporting. This code is a duplicate of the code in elf.c, except
6149 that it uses arm_elf_find_function. */
6150
6151 static bfd_boolean
elf32_arm_find_nearest_line(bfd * abfd,asection * section,asymbol ** symbols,bfd_vma offset,const char ** filename_ptr,const char ** functionname_ptr,unsigned int * line_ptr)6152 elf32_arm_find_nearest_line (bfd * abfd,
6153 asection * section,
6154 asymbol ** symbols,
6155 bfd_vma offset,
6156 const char ** filename_ptr,
6157 const char ** functionname_ptr,
6158 unsigned int * line_ptr)
6159 {
6160 bfd_boolean found = FALSE;
6161
6162 /* We skip _bfd_dwarf1_find_nearest_line since no known ARM toolchain uses it. */
6163
6164 if (_bfd_dwarf2_find_nearest_line (abfd, section, symbols, offset,
6165 filename_ptr, functionname_ptr,
6166 line_ptr, 0,
6167 & elf_tdata (abfd)->dwarf2_find_line_info))
6168 {
6169 if (!*functionname_ptr)
6170 arm_elf_find_function (abfd, section, symbols, offset,
6171 *filename_ptr ? NULL : filename_ptr,
6172 functionname_ptr);
6173
6174 return TRUE;
6175 }
6176
6177 if (! _bfd_stab_section_find_nearest_line (abfd, symbols, section, offset,
6178 & found, filename_ptr,
6179 functionname_ptr, line_ptr,
6180 & elf_tdata (abfd)->line_info))
6181 return FALSE;
6182
6183 if (found && (*functionname_ptr || *line_ptr))
6184 return TRUE;
6185
6186 if (symbols == NULL)
6187 return FALSE;
6188
6189 if (! arm_elf_find_function (abfd, section, symbols, offset,
6190 filename_ptr, functionname_ptr))
6191 return FALSE;
6192
6193 *line_ptr = 0;
6194 return TRUE;
6195 }
6196
6197 static bfd_boolean
elf32_arm_find_inliner_info(bfd * abfd,const char ** filename_ptr,const char ** functionname_ptr,unsigned int * line_ptr)6198 elf32_arm_find_inliner_info (bfd * abfd,
6199 const char ** filename_ptr,
6200 const char ** functionname_ptr,
6201 unsigned int * line_ptr)
6202 {
6203 bfd_boolean found;
6204 found = _bfd_dwarf2_find_inliner_info (abfd, filename_ptr,
6205 functionname_ptr, line_ptr,
6206 & elf_tdata (abfd)->dwarf2_find_line_info);
6207 return found;
6208 }
6209
6210 /* Adjust a symbol defined by a dynamic object and referenced by a
6211 regular object. The current definition is in some section of the
6212 dynamic object, but we're not including those sections. We have to
6213 change the definition to something the rest of the link can
6214 understand. */
6215
6216 static bfd_boolean
elf32_arm_adjust_dynamic_symbol(struct bfd_link_info * info,struct elf_link_hash_entry * h)6217 elf32_arm_adjust_dynamic_symbol (struct bfd_link_info * info,
6218 struct elf_link_hash_entry * h)
6219 {
6220 bfd * dynobj;
6221 asection * s;
6222 unsigned int power_of_two;
6223 struct elf32_arm_link_hash_entry * eh;
6224 struct elf32_arm_link_hash_table *globals;
6225
6226 globals = elf32_arm_hash_table (info);
6227 dynobj = elf_hash_table (info)->dynobj;
6228
6229 /* Make sure we know what is going on here. */
6230 BFD_ASSERT (dynobj != NULL
6231 && (h->needs_plt
6232 || h->u.weakdef != NULL
6233 || (h->def_dynamic
6234 && h->ref_regular
6235 && !h->def_regular)));
6236
6237 eh = (struct elf32_arm_link_hash_entry *) h;
6238
6239 /* If this is a function, put it in the procedure linkage table. We
6240 will fill in the contents of the procedure linkage table later,
6241 when we know the address of the .got section. */
6242 if (h->type == STT_FUNC || h->type == STT_ARM_TFUNC
6243 || h->needs_plt)
6244 {
6245 if (h->plt.refcount <= 0
6246 || SYMBOL_CALLS_LOCAL (info, h)
6247 || (ELF_ST_VISIBILITY (h->other) != STV_DEFAULT
6248 && h->root.type == bfd_link_hash_undefweak))
6249 {
6250 /* This case can occur if we saw a PLT32 reloc in an input
6251 file, but the symbol was never referred to by a dynamic
6252 object, or if all references were garbage collected. In
6253 such a case, we don't actually need to build a procedure
6254 linkage table, and we can just do a PC24 reloc instead. */
6255 h->plt.offset = (bfd_vma) -1;
6256 eh->plt_thumb_refcount = 0;
6257 h->needs_plt = 0;
6258 }
6259
6260 return TRUE;
6261 }
6262 else
6263 {
6264 /* It's possible that we incorrectly decided a .plt reloc was
6265 needed for an R_ARM_PC24 or similar reloc to a non-function sym
6266 in check_relocs. We can't decide accurately between function
6267 and non-function syms in check-relocs; Objects loaded later in
6268 the link may change h->type. So fix it now. */
6269 h->plt.offset = (bfd_vma) -1;
6270 eh->plt_thumb_refcount = 0;
6271 }
6272
6273 /* If this is a weak symbol, and there is a real definition, the
6274 processor independent code will have arranged for us to see the
6275 real definition first, and we can just use the same value. */
6276 if (h->u.weakdef != NULL)
6277 {
6278 BFD_ASSERT (h->u.weakdef->root.type == bfd_link_hash_defined
6279 || h->u.weakdef->root.type == bfd_link_hash_defweak);
6280 h->root.u.def.section = h->u.weakdef->root.u.def.section;
6281 h->root.u.def.value = h->u.weakdef->root.u.def.value;
6282 return TRUE;
6283 }
6284
6285 /* If there are no non-GOT references, we do not need a copy
6286 relocation. */
6287 if (!h->non_got_ref)
6288 return TRUE;
6289
6290 /* This is a reference to a symbol defined by a dynamic object which
6291 is not a function. */
6292
6293 /* If we are creating a shared library, we must presume that the
6294 only references to the symbol are via the global offset table.
6295 For such cases we need not do anything here; the relocations will
6296 be handled correctly by relocate_section. Relocatable executables
6297 can reference data in shared objects directly, so we don't need to
6298 do anything here. */
6299 if (info->shared || globals->root.is_relocatable_executable)
6300 return TRUE;
6301
6302 if (h->size == 0)
6303 {
6304 (*_bfd_error_handler) (_("dynamic variable `%s' is zero size"),
6305 h->root.root.string);
6306 return TRUE;
6307 }
6308
6309 /* We must allocate the symbol in our .dynbss section, which will
6310 become part of the .bss section of the executable. There will be
6311 an entry for this symbol in the .dynsym section. The dynamic
6312 object will contain position independent code, so all references
6313 from the dynamic object to this symbol will go through the global
6314 offset table. The dynamic linker will use the .dynsym entry to
6315 determine the address it must put in the global offset table, so
6316 both the dynamic object and the regular object will refer to the
6317 same memory location for the variable. */
6318 s = bfd_get_section_by_name (dynobj, ".dynbss");
6319 BFD_ASSERT (s != NULL);
6320
6321 /* We must generate a R_ARM_COPY reloc to tell the dynamic linker to
6322 copy the initial value out of the dynamic object and into the
6323 runtime process image. We need to remember the offset into the
6324 .rel(a).bss section we are going to use. */
6325 if ((h->root.u.def.section->flags & SEC_ALLOC) != 0)
6326 {
6327 asection *srel;
6328
6329 srel = bfd_get_section_by_name (dynobj, RELOC_SECTION (globals, ".bss"));
6330 BFD_ASSERT (srel != NULL);
6331 srel->size += RELOC_SIZE (globals);
6332 h->needs_copy = 1;
6333 }
6334
6335 /* We need to figure out the alignment required for this symbol. I
6336 have no idea how ELF linkers handle this. */
6337 power_of_two = bfd_log2 (h->size);
6338 if (power_of_two > 3)
6339 power_of_two = 3;
6340
6341 /* Apply the required alignment. */
6342 s->size = BFD_ALIGN (s->size, (bfd_size_type) (1 << power_of_two));
6343 if (power_of_two > bfd_get_section_alignment (dynobj, s))
6344 {
6345 if (! bfd_set_section_alignment (dynobj, s, power_of_two))
6346 return FALSE;
6347 }
6348
6349 /* Define the symbol as being at this point in the section. */
6350 h->root.u.def.section = s;
6351 h->root.u.def.value = s->size;
6352
6353 /* Increment the section size to make room for the symbol. */
6354 s->size += h->size;
6355
6356 return TRUE;
6357 }
6358
6359 /* Allocate space in .plt, .got and associated reloc sections for
6360 dynamic relocs. */
6361
6362 static bfd_boolean
allocate_dynrelocs(struct elf_link_hash_entry * h,void * inf)6363 allocate_dynrelocs (struct elf_link_hash_entry *h, void * inf)
6364 {
6365 struct bfd_link_info *info;
6366 struct elf32_arm_link_hash_table *htab;
6367 struct elf32_arm_link_hash_entry *eh;
6368 struct elf32_arm_relocs_copied *p;
6369
6370 eh = (struct elf32_arm_link_hash_entry *) h;
6371
6372 if (h->root.type == bfd_link_hash_indirect)
6373 return TRUE;
6374
6375 if (h->root.type == bfd_link_hash_warning)
6376 /* When warning symbols are created, they **replace** the "real"
6377 entry in the hash table, thus we never get to see the real
6378 symbol in a hash traversal. So look at it now. */
6379 h = (struct elf_link_hash_entry *) h->root.u.i.link;
6380
6381 info = (struct bfd_link_info *) inf;
6382 htab = elf32_arm_hash_table (info);
6383
6384 if (htab->root.dynamic_sections_created
6385 && h->plt.refcount > 0)
6386 {
6387 /* Make sure this symbol is output as a dynamic symbol.
6388 Undefined weak syms won't yet be marked as dynamic. */
6389 if (h->dynindx == -1
6390 && !h->forced_local)
6391 {
6392 if (! bfd_elf_link_record_dynamic_symbol (info, h))
6393 return FALSE;
6394 }
6395
6396 if (info->shared
6397 || WILL_CALL_FINISH_DYNAMIC_SYMBOL (1, 0, h))
6398 {
6399 asection *s = htab->splt;
6400
6401 /* If this is the first .plt entry, make room for the special
6402 first entry. */
6403 if (s->size == 0)
6404 s->size += htab->plt_header_size;
6405
6406 h->plt.offset = s->size;
6407
6408 /* If we will insert a Thumb trampoline before this PLT, leave room
6409 for it. */
6410 if (!htab->use_blx && eh->plt_thumb_refcount > 0)
6411 {
6412 h->plt.offset += PLT_THUMB_STUB_SIZE;
6413 s->size += PLT_THUMB_STUB_SIZE;
6414 }
6415
6416 /* If this symbol is not defined in a regular file, and we are
6417 not generating a shared library, then set the symbol to this
6418 location in the .plt. This is required to make function
6419 pointers compare as equal between the normal executable and
6420 the shared library. */
6421 if (! info->shared
6422 && !h->def_regular)
6423 {
6424 h->root.u.def.section = s;
6425 h->root.u.def.value = h->plt.offset;
6426
6427 /* Make sure the function is not marked as Thumb, in case
6428 it is the target of an ABS32 relocation, which will
6429 point to the PLT entry. */
6430 if (ELF_ST_TYPE (h->type) == STT_ARM_TFUNC)
6431 h->type = ELF_ST_INFO (ELF_ST_BIND (h->type), STT_FUNC);
6432 }
6433
6434 /* Make room for this entry. */
6435 s->size += htab->plt_entry_size;
6436
6437 if (!htab->symbian_p)
6438 {
6439 /* We also need to make an entry in the .got.plt section, which
6440 will be placed in the .got section by the linker script. */
6441 eh->plt_got_offset = htab->sgotplt->size;
6442 htab->sgotplt->size += 4;
6443 }
6444
6445 /* We also need to make an entry in the .rel(a).plt section. */
6446 htab->srelplt->size += RELOC_SIZE (htab);
6447
6448 /* VxWorks executables have a second set of relocations for
6449 each PLT entry. They go in a separate relocation section,
6450 which is processed by the kernel loader. */
6451 if (htab->vxworks_p && !info->shared)
6452 {
6453 /* There is a relocation for the initial PLT entry:
6454 an R_ARM_32 relocation for _GLOBAL_OFFSET_TABLE_. */
6455 if (h->plt.offset == htab->plt_header_size)
6456 htab->srelplt2->size += RELOC_SIZE (htab);
6457
6458 /* There are two extra relocations for each subsequent
6459 PLT entry: an R_ARM_32 relocation for the GOT entry,
6460 and an R_ARM_32 relocation for the PLT entry. */
6461 htab->srelplt2->size += RELOC_SIZE (htab) * 2;
6462 }
6463 }
6464 else
6465 {
6466 h->plt.offset = (bfd_vma) -1;
6467 h->needs_plt = 0;
6468 }
6469 }
6470 else
6471 {
6472 h->plt.offset = (bfd_vma) -1;
6473 h->needs_plt = 0;
6474 }
6475
6476 if (h->got.refcount > 0)
6477 {
6478 asection *s;
6479 bfd_boolean dyn;
6480 int tls_type = elf32_arm_hash_entry (h)->tls_type;
6481 int indx;
6482
6483 /* Make sure this symbol is output as a dynamic symbol.
6484 Undefined weak syms won't yet be marked as dynamic. */
6485 if (h->dynindx == -1
6486 && !h->forced_local)
6487 {
6488 if (! bfd_elf_link_record_dynamic_symbol (info, h))
6489 return FALSE;
6490 }
6491
6492 if (!htab->symbian_p)
6493 {
6494 s = htab->sgot;
6495 h->got.offset = s->size;
6496
6497 if (tls_type == GOT_UNKNOWN)
6498 abort ();
6499
6500 if (tls_type == GOT_NORMAL)
6501 /* Non-TLS symbols need one GOT slot. */
6502 s->size += 4;
6503 else
6504 {
6505 if (tls_type & GOT_TLS_GD)
6506 /* R_ARM_TLS_GD32 needs 2 consecutive GOT slots. */
6507 s->size += 8;
6508 if (tls_type & GOT_TLS_IE)
6509 /* R_ARM_TLS_IE32 needs one GOT slot. */
6510 s->size += 4;
6511 }
6512
6513 dyn = htab->root.dynamic_sections_created;
6514
6515 indx = 0;
6516 if (WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn, info->shared, h)
6517 && (!info->shared
6518 || !SYMBOL_REFERENCES_LOCAL (info, h)))
6519 indx = h->dynindx;
6520
6521 if (tls_type != GOT_NORMAL
6522 && (info->shared || indx != 0)
6523 && (ELF_ST_VISIBILITY (h->other) == STV_DEFAULT
6524 || h->root.type != bfd_link_hash_undefweak))
6525 {
6526 if (tls_type & GOT_TLS_IE)
6527 htab->srelgot->size += RELOC_SIZE (htab);
6528
6529 if (tls_type & GOT_TLS_GD)
6530 htab->srelgot->size += RELOC_SIZE (htab);
6531
6532 if ((tls_type & GOT_TLS_GD) && indx != 0)
6533 htab->srelgot->size += RELOC_SIZE (htab);
6534 }
6535 else if ((ELF_ST_VISIBILITY (h->other) == STV_DEFAULT
6536 || h->root.type != bfd_link_hash_undefweak)
6537 && (info->shared
6538 || WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn, 0, h)))
6539 htab->srelgot->size += RELOC_SIZE (htab);
6540 }
6541 }
6542 else
6543 h->got.offset = (bfd_vma) -1;
6544
6545 if (eh->relocs_copied == NULL)
6546 return TRUE;
6547
6548 /* In the shared -Bsymbolic case, discard space allocated for
6549 dynamic pc-relative relocs against symbols which turn out to be
6550 defined in regular objects. For the normal shared case, discard
6551 space for pc-relative relocs that have become local due to symbol
6552 visibility changes. */
6553
6554 if (info->shared || htab->root.is_relocatable_executable)
6555 {
6556 /* The only reloc that uses pc_count is R_ARM_REL32, which will
6557 appear on something like ".long foo - .". We want calls to
6558 protected symbols to resolve directly to the function rather
6559 than going via the plt. If people want function pointer
6560 comparisons to work as expected then they should avoid
6561 writing assembly like ".long foo - .". */
6562 if (SYMBOL_CALLS_LOCAL (info, h))
6563 {
6564 struct elf32_arm_relocs_copied **pp;
6565
6566 for (pp = &eh->relocs_copied; (p = *pp) != NULL; )
6567 {
6568 p->count -= p->pc_count;
6569 p->pc_count = 0;
6570 if (p->count == 0)
6571 *pp = p->next;
6572 else
6573 pp = &p->next;
6574 }
6575 }
6576
6577 /* Also discard relocs on undefined weak syms with non-default
6578 visibility. */
6579 if (eh->relocs_copied != NULL
6580 && h->root.type == bfd_link_hash_undefweak)
6581 {
6582 if (ELF_ST_VISIBILITY (h->other) != STV_DEFAULT)
6583 eh->relocs_copied = NULL;
6584
6585 /* Make sure undefined weak symbols are output as a dynamic
6586 symbol in PIEs. */
6587 else if (h->dynindx == -1
6588 && !h->forced_local)
6589 {
6590 if (! bfd_elf_link_record_dynamic_symbol (info, h))
6591 return FALSE;
6592 }
6593 }
6594
6595 else if (htab->root.is_relocatable_executable && h->dynindx == -1
6596 && h->root.type == bfd_link_hash_new)
6597 {
6598 /* Output absolute symbols so that we can create relocations
6599 against them. For normal symbols we output a relocation
6600 against the section that contains them. */
6601 if (! bfd_elf_link_record_dynamic_symbol (info, h))
6602 return FALSE;
6603 }
6604
6605 }
6606 else
6607 {
6608 /* For the non-shared case, discard space for relocs against
6609 symbols which turn out to need copy relocs or are not
6610 dynamic. */
6611
6612 if (!h->non_got_ref
6613 && ((h->def_dynamic
6614 && !h->def_regular)
6615 || (htab->root.dynamic_sections_created
6616 && (h->root.type == bfd_link_hash_undefweak
6617 || h->root.type == bfd_link_hash_undefined))))
6618 {
6619 /* Make sure this symbol is output as a dynamic symbol.
6620 Undefined weak syms won't yet be marked as dynamic. */
6621 if (h->dynindx == -1
6622 && !h->forced_local)
6623 {
6624 if (! bfd_elf_link_record_dynamic_symbol (info, h))
6625 return FALSE;
6626 }
6627
6628 /* If that succeeded, we know we'll be keeping all the
6629 relocs. */
6630 if (h->dynindx != -1)
6631 goto keep;
6632 }
6633
6634 eh->relocs_copied = NULL;
6635
6636 keep: ;
6637 }
6638
6639 /* Finally, allocate space. */
6640 for (p = eh->relocs_copied; p != NULL; p = p->next)
6641 {
6642 asection *sreloc = elf_section_data (p->section)->sreloc;
6643 sreloc->size += p->count * RELOC_SIZE (htab);
6644 }
6645
6646 return TRUE;
6647 }
6648
6649 /* Find any dynamic relocs that apply to read-only sections. */
6650
6651 static bfd_boolean
elf32_arm_readonly_dynrelocs(struct elf_link_hash_entry * h,PTR inf)6652 elf32_arm_readonly_dynrelocs (struct elf_link_hash_entry *h, PTR inf)
6653 {
6654 struct elf32_arm_link_hash_entry *eh;
6655 struct elf32_arm_relocs_copied *p;
6656
6657 if (h->root.type == bfd_link_hash_warning)
6658 h = (struct elf_link_hash_entry *) h->root.u.i.link;
6659
6660 eh = (struct elf32_arm_link_hash_entry *) h;
6661 for (p = eh->relocs_copied; p != NULL; p = p->next)
6662 {
6663 asection *s = p->section;
6664
6665 if (s != NULL && (s->flags & SEC_READONLY) != 0)
6666 {
6667 struct bfd_link_info *info = (struct bfd_link_info *) inf;
6668
6669 info->flags |= DF_TEXTREL;
6670
6671 /* Not an error, just cut short the traversal. */
6672 return FALSE;
6673 }
6674 }
6675 return TRUE;
6676 }
6677
6678 /* Set the sizes of the dynamic sections. */
6679
6680 static bfd_boolean
elf32_arm_size_dynamic_sections(bfd * output_bfd ATTRIBUTE_UNUSED,struct bfd_link_info * info)6681 elf32_arm_size_dynamic_sections (bfd * output_bfd ATTRIBUTE_UNUSED,
6682 struct bfd_link_info * info)
6683 {
6684 bfd * dynobj;
6685 asection * s;
6686 bfd_boolean plt;
6687 bfd_boolean relocs;
6688 bfd *ibfd;
6689 struct elf32_arm_link_hash_table *htab;
6690
6691 htab = elf32_arm_hash_table (info);
6692 dynobj = elf_hash_table (info)->dynobj;
6693 BFD_ASSERT (dynobj != NULL);
6694 check_use_blx (htab);
6695
6696 if (elf_hash_table (info)->dynamic_sections_created)
6697 {
6698 /* Set the contents of the .interp section to the interpreter. */
6699 if (info->executable && !info->static_link)
6700 {
6701 s = bfd_get_section_by_name (dynobj, ".interp");
6702 BFD_ASSERT (s != NULL);
6703 s->size = sizeof ELF_DYNAMIC_INTERPRETER;
6704 s->contents = (unsigned char *) ELF_DYNAMIC_INTERPRETER;
6705 }
6706 }
6707
6708 /* Set up .got offsets for local syms, and space for local dynamic
6709 relocs. */
6710 for (ibfd = info->input_bfds; ibfd != NULL; ibfd = ibfd->link_next)
6711 {
6712 bfd_signed_vma *local_got;
6713 bfd_signed_vma *end_local_got;
6714 char *local_tls_type;
6715 bfd_size_type locsymcount;
6716 Elf_Internal_Shdr *symtab_hdr;
6717 asection *srel;
6718
6719 if (bfd_get_flavour (ibfd) != bfd_target_elf_flavour)
6720 continue;
6721
6722 for (s = ibfd->sections; s != NULL; s = s->next)
6723 {
6724 struct elf32_arm_relocs_copied *p;
6725
6726 for (p = elf_section_data (s)->local_dynrel; p != NULL; p = p->next)
6727 {
6728 if (!bfd_is_abs_section (p->section)
6729 && bfd_is_abs_section (p->section->output_section))
6730 {
6731 /* Input section has been discarded, either because
6732 it is a copy of a linkonce section or due to
6733 linker script /DISCARD/, so we'll be discarding
6734 the relocs too. */
6735 }
6736 else if (p->count != 0)
6737 {
6738 srel = elf_section_data (p->section)->sreloc;
6739 srel->size += p->count * RELOC_SIZE (htab);
6740 if ((p->section->output_section->flags & SEC_READONLY) != 0)
6741 info->flags |= DF_TEXTREL;
6742 }
6743 }
6744 }
6745
6746 local_got = elf_local_got_refcounts (ibfd);
6747 if (!local_got)
6748 continue;
6749
6750 symtab_hdr = &elf_tdata (ibfd)->symtab_hdr;
6751 locsymcount = symtab_hdr->sh_info;
6752 end_local_got = local_got + locsymcount;
6753 local_tls_type = elf32_arm_local_got_tls_type (ibfd);
6754 s = htab->sgot;
6755 srel = htab->srelgot;
6756 for (; local_got < end_local_got; ++local_got, ++local_tls_type)
6757 {
6758 if (*local_got > 0)
6759 {
6760 *local_got = s->size;
6761 if (*local_tls_type & GOT_TLS_GD)
6762 /* TLS_GD relocs need an 8-byte structure in the GOT. */
6763 s->size += 8;
6764 if (*local_tls_type & GOT_TLS_IE)
6765 s->size += 4;
6766 if (*local_tls_type == GOT_NORMAL)
6767 s->size += 4;
6768
6769 if (info->shared || *local_tls_type == GOT_TLS_GD)
6770 srel->size += RELOC_SIZE (htab);
6771 }
6772 else
6773 *local_got = (bfd_vma) -1;
6774 }
6775 }
6776
6777 if (htab->tls_ldm_got.refcount > 0)
6778 {
6779 /* Allocate two GOT entries and one dynamic relocation (if necessary)
6780 for R_ARM_TLS_LDM32 relocations. */
6781 htab->tls_ldm_got.offset = htab->sgot->size;
6782 htab->sgot->size += 8;
6783 if (info->shared)
6784 htab->srelgot->size += RELOC_SIZE (htab);
6785 }
6786 else
6787 htab->tls_ldm_got.offset = -1;
6788
6789 /* Allocate global sym .plt and .got entries, and space for global
6790 sym dynamic relocs. */
6791 elf_link_hash_traverse (& htab->root, allocate_dynrelocs, info);
6792
6793 /* The check_relocs and adjust_dynamic_symbol entry points have
6794 determined the sizes of the various dynamic sections. Allocate
6795 memory for them. */
6796 plt = FALSE;
6797 relocs = FALSE;
6798 for (s = dynobj->sections; s != NULL; s = s->next)
6799 {
6800 const char * name;
6801
6802 if ((s->flags & SEC_LINKER_CREATED) == 0)
6803 continue;
6804
6805 /* It's OK to base decisions on the section name, because none
6806 of the dynobj section names depend upon the input files. */
6807 name = bfd_get_section_name (dynobj, s);
6808
6809 if (strcmp (name, ".plt") == 0)
6810 {
6811 /* Remember whether there is a PLT. */
6812 plt = s->size != 0;
6813 }
6814 else if (strncmp (name, ".rel", 4) == 0)
6815 {
6816 if (s->size != 0)
6817 {
6818 /* Remember whether there are any reloc sections other
6819 than .rel(a).plt and .rela.plt.unloaded. */
6820 if (s != htab->srelplt && s != htab->srelplt2)
6821 relocs = TRUE;
6822
6823 /* We use the reloc_count field as a counter if we need
6824 to copy relocs into the output file. */
6825 s->reloc_count = 0;
6826 }
6827 }
6828 else if (strncmp (name, ".got", 4) != 0
6829 && strcmp (name, ".dynbss") != 0)
6830 {
6831 /* It's not one of our sections, so don't allocate space. */
6832 continue;
6833 }
6834
6835 if (s->size == 0)
6836 {
6837 /* If we don't need this section, strip it from the
6838 output file. This is mostly to handle .rel(a).bss and
6839 .rel(a).plt. We must create both sections in
6840 create_dynamic_sections, because they must be created
6841 before the linker maps input sections to output
6842 sections. The linker does that before
6843 adjust_dynamic_symbol is called, and it is that
6844 function which decides whether anything needs to go
6845 into these sections. */
6846 s->flags |= SEC_EXCLUDE;
6847 continue;
6848 }
6849
6850 if ((s->flags & SEC_HAS_CONTENTS) == 0)
6851 continue;
6852
6853 /* Allocate memory for the section contents. */
6854 s->contents = (bfd_byte *) bfd_zalloc (dynobj, s->size);
6855 if (s->contents == NULL)
6856 return FALSE;
6857 }
6858
6859 if (elf_hash_table (info)->dynamic_sections_created)
6860 {
6861 /* Add some entries to the .dynamic section. We fill in the
6862 values later, in elf32_arm_finish_dynamic_sections, but we
6863 must add the entries now so that we get the correct size for
6864 the .dynamic section. The DT_DEBUG entry is filled in by the
6865 dynamic linker and used by the debugger. */
6866 #define add_dynamic_entry(TAG, VAL) \
6867 _bfd_elf_add_dynamic_entry (info, TAG, VAL)
6868
6869 if (info->executable)
6870 {
6871 if (!add_dynamic_entry (DT_DEBUG, 0))
6872 return FALSE;
6873 }
6874
6875 if (plt)
6876 {
6877 if ( !add_dynamic_entry (DT_PLTGOT, 0)
6878 || !add_dynamic_entry (DT_PLTRELSZ, 0)
6879 || !add_dynamic_entry (DT_PLTREL,
6880 htab->use_rel ? DT_REL : DT_RELA)
6881 || !add_dynamic_entry (DT_JMPREL, 0))
6882 return FALSE;
6883 }
6884
6885 if (relocs)
6886 {
6887 if (htab->use_rel)
6888 {
6889 if (!add_dynamic_entry (DT_REL, 0)
6890 || !add_dynamic_entry (DT_RELSZ, 0)
6891 || !add_dynamic_entry (DT_RELENT, RELOC_SIZE (htab)))
6892 return FALSE;
6893 }
6894 else
6895 {
6896 if (!add_dynamic_entry (DT_RELA, 0)
6897 || !add_dynamic_entry (DT_RELASZ, 0)
6898 || !add_dynamic_entry (DT_RELAENT, RELOC_SIZE (htab)))
6899 return FALSE;
6900 }
6901 }
6902
6903 /* If any dynamic relocs apply to a read-only section,
6904 then we need a DT_TEXTREL entry. */
6905 if ((info->flags & DF_TEXTREL) == 0)
6906 elf_link_hash_traverse (&htab->root, elf32_arm_readonly_dynrelocs,
6907 (PTR) info);
6908
6909 if ((info->flags & DF_TEXTREL) != 0)
6910 {
6911 if (!add_dynamic_entry (DT_TEXTREL, 0))
6912 return FALSE;
6913 }
6914 }
6915 #undef add_dynamic_entry
6916
6917 return TRUE;
6918 }
6919
6920 /* Finish up dynamic symbol handling. We set the contents of various
6921 dynamic sections here. */
6922
6923 static bfd_boolean
elf32_arm_finish_dynamic_symbol(bfd * output_bfd,struct bfd_link_info * info,struct elf_link_hash_entry * h,Elf_Internal_Sym * sym)6924 elf32_arm_finish_dynamic_symbol (bfd * output_bfd, struct bfd_link_info * info,
6925 struct elf_link_hash_entry * h, Elf_Internal_Sym * sym)
6926 {
6927 bfd * dynobj;
6928 struct elf32_arm_link_hash_table *htab;
6929 struct elf32_arm_link_hash_entry *eh;
6930
6931 dynobj = elf_hash_table (info)->dynobj;
6932 htab = elf32_arm_hash_table (info);
6933 eh = (struct elf32_arm_link_hash_entry *) h;
6934
6935 if (h->plt.offset != (bfd_vma) -1)
6936 {
6937 asection * splt;
6938 asection * srel;
6939 bfd_byte *loc;
6940 bfd_vma plt_index;
6941 Elf_Internal_Rela rel;
6942
6943 /* This symbol has an entry in the procedure linkage table. Set
6944 it up. */
6945
6946 BFD_ASSERT (h->dynindx != -1);
6947
6948 splt = bfd_get_section_by_name (dynobj, ".plt");
6949 srel = bfd_get_section_by_name (dynobj, RELOC_SECTION (htab, ".plt"));
6950 BFD_ASSERT (splt != NULL && srel != NULL);
6951
6952 /* Fill in the entry in the procedure linkage table. */
6953 if (htab->symbian_p)
6954 {
6955 unsigned i;
6956 for (i = 0; i < htab->plt_entry_size / 4; ++i)
6957 bfd_put_32 (output_bfd,
6958 elf32_arm_symbian_plt_entry[i],
6959 splt->contents + h->plt.offset + 4 * i);
6960
6961 /* Fill in the entry in the .rel.plt section. */
6962 rel.r_offset = (splt->output_section->vma
6963 + splt->output_offset
6964 + h->plt.offset + 4 * (i - 1));
6965 rel.r_info = ELF32_R_INFO (h->dynindx, R_ARM_GLOB_DAT);
6966
6967 /* Get the index in the procedure linkage table which
6968 corresponds to this symbol. This is the index of this symbol
6969 in all the symbols for which we are making plt entries. The
6970 first entry in the procedure linkage table is reserved. */
6971 plt_index = ((h->plt.offset - htab->plt_header_size)
6972 / htab->plt_entry_size);
6973 }
6974 else
6975 {
6976 bfd_vma got_offset, got_address, plt_address;
6977 bfd_vma got_displacement;
6978 asection * sgot;
6979
6980 sgot = bfd_get_section_by_name (dynobj, ".got.plt");
6981 BFD_ASSERT (sgot != NULL);
6982
6983 /* Get the offset into the .got.plt table of the entry that
6984 corresponds to this function. */
6985 got_offset = eh->plt_got_offset;
6986
6987 /* Get the index in the procedure linkage table which
6988 corresponds to this symbol. This is the index of this symbol
6989 in all the symbols for which we are making plt entries. The
6990 first three entries in .got.plt are reserved; after that
6991 symbols appear in the same order as in .plt. */
6992 plt_index = (got_offset - 12) / 4;
6993
6994 /* Calculate the address of the GOT entry. */
6995 got_address = (sgot->output_section->vma
6996 + sgot->output_offset
6997 + got_offset);
6998
6999 /* ...and the address of the PLT entry. */
7000 plt_address = (splt->output_section->vma
7001 + splt->output_offset
7002 + h->plt.offset);
7003
7004 if (htab->vxworks_p && info->shared)
7005 {
7006 unsigned int i;
7007 bfd_vma val;
7008
7009 for (i = 0; i != htab->plt_entry_size / 4; i++)
7010 {
7011 val = elf32_arm_vxworks_shared_plt_entry[i];
7012 if (i == 2)
7013 val |= got_address - sgot->output_section->vma;
7014 if (i == 5)
7015 val |= plt_index * RELOC_SIZE (htab);
7016 bfd_put_32 (output_bfd, val,
7017 htab->splt->contents + h->plt.offset + i * 4);
7018 }
7019 }
7020 else if (htab->vxworks_p)
7021 {
7022 unsigned int i;
7023 bfd_vma val;
7024
7025 for (i = 0; i != htab->plt_entry_size / 4; i++)
7026 {
7027 val = elf32_arm_vxworks_exec_plt_entry[i];
7028 if (i == 2)
7029 val |= got_address;
7030 if (i == 4)
7031 val |= 0xffffff & -((h->plt.offset + i * 4 + 8) >> 2);
7032 if (i == 5)
7033 val |= plt_index * RELOC_SIZE (htab);
7034 bfd_put_32 (output_bfd, val,
7035 htab->splt->contents + h->plt.offset + i * 4);
7036 }
7037
7038 loc = (htab->srelplt2->contents
7039 + (plt_index * 2 + 1) * RELOC_SIZE (htab));
7040
7041 /* Create the .rela.plt.unloaded R_ARM_ABS32 relocation
7042 referencing the GOT for this PLT entry. */
7043 rel.r_offset = plt_address + 8;
7044 rel.r_info = ELF32_R_INFO (htab->root.hgot->indx, R_ARM_ABS32);
7045 rel.r_addend = got_offset;
7046 SWAP_RELOC_OUT (htab) (output_bfd, &rel, loc);
7047 loc += RELOC_SIZE (htab);
7048
7049 /* Create the R_ARM_ABS32 relocation referencing the
7050 beginning of the PLT for this GOT entry. */
7051 rel.r_offset = got_address;
7052 rel.r_info = ELF32_R_INFO (htab->root.hplt->indx, R_ARM_ABS32);
7053 rel.r_addend = 0;
7054 SWAP_RELOC_OUT (htab) (output_bfd, &rel, loc);
7055 }
7056 else
7057 {
7058 /* Calculate the displacement between the PLT slot and the
7059 entry in the GOT. The eight-byte offset accounts for the
7060 value produced by adding to pc in the first instruction
7061 of the PLT stub. */
7062 got_displacement = got_address - (plt_address + 8);
7063
7064 BFD_ASSERT ((got_displacement & 0xf0000000) == 0);
7065
7066 if (!htab->use_blx && eh->plt_thumb_refcount > 0)
7067 {
7068 bfd_put_16 (output_bfd, elf32_arm_plt_thumb_stub[0],
7069 splt->contents + h->plt.offset - 4);
7070 bfd_put_16 (output_bfd, elf32_arm_plt_thumb_stub[1],
7071 splt->contents + h->plt.offset - 2);
7072 }
7073
7074 bfd_put_32 (output_bfd,
7075 elf32_arm_plt_entry[0]
7076 | ((got_displacement & 0x0ff00000) >> 20),
7077 splt->contents + h->plt.offset + 0);
7078 bfd_put_32 (output_bfd,
7079 elf32_arm_plt_entry[1]
7080 | ((got_displacement & 0x000ff000) >> 12),
7081 splt->contents + h->plt.offset + 4);
7082 bfd_put_32 (output_bfd,
7083 elf32_arm_plt_entry[2]
7084 | (got_displacement & 0x00000fff),
7085 splt->contents + h->plt.offset + 8);
7086 #ifdef FOUR_WORD_PLT
7087 bfd_put_32 (output_bfd, elf32_arm_plt_entry[3],
7088 splt->contents + h->plt.offset + 12);
7089 #endif
7090 }
7091
7092 /* Fill in the entry in the global offset table. */
7093 bfd_put_32 (output_bfd,
7094 (splt->output_section->vma
7095 + splt->output_offset),
7096 sgot->contents + got_offset);
7097
7098 /* Fill in the entry in the .rel(a).plt section. */
7099 rel.r_addend = 0;
7100 rel.r_offset = got_address;
7101 rel.r_info = ELF32_R_INFO (h->dynindx, R_ARM_JUMP_SLOT);
7102 }
7103
7104 loc = srel->contents + plt_index * RELOC_SIZE (htab);
7105 SWAP_RELOC_OUT (htab) (output_bfd, &rel, loc);
7106
7107 if (!h->def_regular)
7108 {
7109 /* Mark the symbol as undefined, rather than as defined in
7110 the .plt section. Leave the value alone. */
7111 sym->st_shndx = SHN_UNDEF;
7112 /* If the symbol is weak, we do need to clear the value.
7113 Otherwise, the PLT entry would provide a definition for
7114 the symbol even if the symbol wasn't defined anywhere,
7115 and so the symbol would never be NULL. */
7116 if (!h->ref_regular_nonweak)
7117 sym->st_value = 0;
7118 }
7119 }
7120
7121 if (h->got.offset != (bfd_vma) -1
7122 && (elf32_arm_hash_entry (h)->tls_type & GOT_TLS_GD) == 0
7123 && (elf32_arm_hash_entry (h)->tls_type & GOT_TLS_IE) == 0)
7124 {
7125 asection * sgot;
7126 asection * srel;
7127 Elf_Internal_Rela rel;
7128 bfd_byte *loc;
7129 bfd_vma offset;
7130
7131 /* This symbol has an entry in the global offset table. Set it
7132 up. */
7133 sgot = bfd_get_section_by_name (dynobj, ".got");
7134 srel = bfd_get_section_by_name (dynobj, RELOC_SECTION (htab, ".got"));
7135 BFD_ASSERT (sgot != NULL && srel != NULL);
7136
7137 offset = (h->got.offset & ~(bfd_vma) 1);
7138 rel.r_addend = 0;
7139 rel.r_offset = (sgot->output_section->vma
7140 + sgot->output_offset
7141 + offset);
7142
7143 /* If this is a static link, or it is a -Bsymbolic link and the
7144 symbol is defined locally or was forced to be local because
7145 of a version file, we just want to emit a RELATIVE reloc.
7146 The entry in the global offset table will already have been
7147 initialized in the relocate_section function. */
7148 if (info->shared
7149 && SYMBOL_REFERENCES_LOCAL (info, h))
7150 {
7151 BFD_ASSERT((h->got.offset & 1) != 0);
7152 rel.r_info = ELF32_R_INFO (0, R_ARM_RELATIVE);
7153 if (!htab->use_rel)
7154 {
7155 rel.r_addend = bfd_get_32 (output_bfd, sgot->contents + offset);
7156 bfd_put_32 (output_bfd, (bfd_vma) 0, sgot->contents + offset);
7157 }
7158 }
7159 else
7160 {
7161 BFD_ASSERT((h->got.offset & 1) == 0);
7162 bfd_put_32 (output_bfd, (bfd_vma) 0, sgot->contents + offset);
7163 rel.r_info = ELF32_R_INFO (h->dynindx, R_ARM_GLOB_DAT);
7164 }
7165
7166 loc = srel->contents + srel->reloc_count++ * RELOC_SIZE (htab);
7167 SWAP_RELOC_OUT (htab) (output_bfd, &rel, loc);
7168 }
7169
7170 if (h->needs_copy)
7171 {
7172 asection * s;
7173 Elf_Internal_Rela rel;
7174 bfd_byte *loc;
7175
7176 /* This symbol needs a copy reloc. Set it up. */
7177 BFD_ASSERT (h->dynindx != -1
7178 && (h->root.type == bfd_link_hash_defined
7179 || h->root.type == bfd_link_hash_defweak));
7180
7181 s = bfd_get_section_by_name (h->root.u.def.section->owner,
7182 RELOC_SECTION (htab, ".bss"));
7183 BFD_ASSERT (s != NULL);
7184
7185 rel.r_addend = 0;
7186 rel.r_offset = (h->root.u.def.value
7187 + h->root.u.def.section->output_section->vma
7188 + h->root.u.def.section->output_offset);
7189 rel.r_info = ELF32_R_INFO (h->dynindx, R_ARM_COPY);
7190 loc = s->contents + s->reloc_count++ * RELOC_SIZE (htab);
7191 SWAP_RELOC_OUT (htab) (output_bfd, &rel, loc);
7192 }
7193
7194 /* Mark _DYNAMIC and _GLOBAL_OFFSET_TABLE_ as absolute. On VxWorks,
7195 the _GLOBAL_OFFSET_TABLE_ symbol is not absolute: it is relative
7196 to the ".got" section. */
7197 if (strcmp (h->root.root.string, "_DYNAMIC") == 0
7198 || (!htab->vxworks_p && h == htab->root.hgot))
7199 sym->st_shndx = SHN_ABS;
7200
7201 return TRUE;
7202 }
7203
7204 /* Finish up the dynamic sections. */
7205
7206 static bfd_boolean
elf32_arm_finish_dynamic_sections(bfd * output_bfd,struct bfd_link_info * info)7207 elf32_arm_finish_dynamic_sections (bfd * output_bfd, struct bfd_link_info * info)
7208 {
7209 bfd * dynobj;
7210 asection * sgot;
7211 asection * sdyn;
7212
7213 dynobj = elf_hash_table (info)->dynobj;
7214
7215 sgot = bfd_get_section_by_name (dynobj, ".got.plt");
7216 BFD_ASSERT (elf32_arm_hash_table (info)->symbian_p || sgot != NULL);
7217 sdyn = bfd_get_section_by_name (dynobj, ".dynamic");
7218
7219 if (elf_hash_table (info)->dynamic_sections_created)
7220 {
7221 asection *splt;
7222 Elf32_External_Dyn *dyncon, *dynconend;
7223 struct elf32_arm_link_hash_table *htab;
7224
7225 htab = elf32_arm_hash_table (info);
7226 splt = bfd_get_section_by_name (dynobj, ".plt");
7227 BFD_ASSERT (splt != NULL && sdyn != NULL);
7228
7229 dyncon = (Elf32_External_Dyn *) sdyn->contents;
7230 dynconend = (Elf32_External_Dyn *) (sdyn->contents + sdyn->size);
7231
7232 for (; dyncon < dynconend; dyncon++)
7233 {
7234 Elf_Internal_Dyn dyn;
7235 const char * name;
7236 asection * s;
7237
7238 bfd_elf32_swap_dyn_in (dynobj, dyncon, &dyn);
7239
7240 switch (dyn.d_tag)
7241 {
7242 unsigned int type;
7243
7244 default:
7245 break;
7246
7247 case DT_HASH:
7248 name = ".hash";
7249 goto get_vma_if_bpabi;
7250 case DT_STRTAB:
7251 name = ".dynstr";
7252 goto get_vma_if_bpabi;
7253 case DT_SYMTAB:
7254 name = ".dynsym";
7255 goto get_vma_if_bpabi;
7256 case DT_VERSYM:
7257 name = ".gnu.version";
7258 goto get_vma_if_bpabi;
7259 case DT_VERDEF:
7260 name = ".gnu.version_d";
7261 goto get_vma_if_bpabi;
7262 case DT_VERNEED:
7263 name = ".gnu.version_r";
7264 goto get_vma_if_bpabi;
7265
7266 case DT_PLTGOT:
7267 name = ".got";
7268 goto get_vma;
7269 case DT_JMPREL:
7270 name = RELOC_SECTION (htab, ".plt");
7271 get_vma:
7272 s = bfd_get_section_by_name (output_bfd, name);
7273 BFD_ASSERT (s != NULL);
7274 if (!htab->symbian_p)
7275 dyn.d_un.d_ptr = s->vma;
7276 else
7277 /* In the BPABI, tags in the PT_DYNAMIC section point
7278 at the file offset, not the memory address, for the
7279 convenience of the post linker. */
7280 dyn.d_un.d_ptr = s->filepos;
7281 bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon);
7282 break;
7283
7284 get_vma_if_bpabi:
7285 if (htab->symbian_p)
7286 goto get_vma;
7287 break;
7288
7289 case DT_PLTRELSZ:
7290 s = bfd_get_section_by_name (output_bfd,
7291 RELOC_SECTION (htab, ".plt"));
7292 BFD_ASSERT (s != NULL);
7293 dyn.d_un.d_val = s->size;
7294 bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon);
7295 break;
7296
7297 case DT_RELSZ:
7298 case DT_RELASZ:
7299 if (!htab->symbian_p)
7300 {
7301 /* My reading of the SVR4 ABI indicates that the
7302 procedure linkage table relocs (DT_JMPREL) should be
7303 included in the overall relocs (DT_REL). This is
7304 what Solaris does. However, UnixWare can not handle
7305 that case. Therefore, we override the DT_RELSZ entry
7306 here to make it not include the JMPREL relocs. Since
7307 the linker script arranges for .rel(a).plt to follow all
7308 other relocation sections, we don't have to worry
7309 about changing the DT_REL entry. */
7310 s = bfd_get_section_by_name (output_bfd,
7311 RELOC_SECTION (htab, ".plt"));
7312 if (s != NULL)
7313 dyn.d_un.d_val -= s->size;
7314 bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon);
7315 break;
7316 }
7317 /* Fall through */
7318
7319 case DT_REL:
7320 case DT_RELA:
7321 /* In the BPABI, the DT_REL tag must point at the file
7322 offset, not the VMA, of the first relocation
7323 section. So, we use code similar to that in
7324 elflink.c, but do not check for SHF_ALLOC on the
7325 relcoation section, since relocations sections are
7326 never allocated under the BPABI. The comments above
7327 about Unixware notwithstanding, we include all of the
7328 relocations here. */
7329 if (htab->symbian_p)
7330 {
7331 unsigned int i;
7332 type = ((dyn.d_tag == DT_REL || dyn.d_tag == DT_RELSZ)
7333 ? SHT_REL : SHT_RELA);
7334 dyn.d_un.d_val = 0;
7335 for (i = 1; i < elf_numsections (output_bfd); i++)
7336 {
7337 Elf_Internal_Shdr *hdr
7338 = elf_elfsections (output_bfd)[i];
7339 if (hdr->sh_type == type)
7340 {
7341 if (dyn.d_tag == DT_RELSZ
7342 || dyn.d_tag == DT_RELASZ)
7343 dyn.d_un.d_val += hdr->sh_size;
7344 else if ((ufile_ptr) hdr->sh_offset
7345 <= dyn.d_un.d_val - 1)
7346 dyn.d_un.d_val = hdr->sh_offset;
7347 }
7348 }
7349 bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon);
7350 }
7351 break;
7352
7353 /* Set the bottom bit of DT_INIT/FINI if the
7354 corresponding function is Thumb. */
7355 case DT_INIT:
7356 name = info->init_function;
7357 goto get_sym;
7358 case DT_FINI:
7359 name = info->fini_function;
7360 get_sym:
7361 /* If it wasn't set by elf_bfd_final_link
7362 then there is nothing to adjust. */
7363 if (dyn.d_un.d_val != 0)
7364 {
7365 struct elf_link_hash_entry * eh;
7366
7367 eh = elf_link_hash_lookup (elf_hash_table (info), name,
7368 FALSE, FALSE, TRUE);
7369 if (eh != (struct elf_link_hash_entry *) NULL
7370 && ELF_ST_TYPE (eh->type) == STT_ARM_TFUNC)
7371 {
7372 dyn.d_un.d_val |= 1;
7373 bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon);
7374 }
7375 }
7376 break;
7377 }
7378 }
7379
7380 /* Fill in the first entry in the procedure linkage table. */
7381 if (splt->size > 0 && elf32_arm_hash_table (info)->plt_header_size)
7382 {
7383 const bfd_vma *plt0_entry;
7384 bfd_vma got_address, plt_address, got_displacement;
7385
7386 /* Calculate the addresses of the GOT and PLT. */
7387 got_address = sgot->output_section->vma + sgot->output_offset;
7388 plt_address = splt->output_section->vma + splt->output_offset;
7389
7390 if (htab->vxworks_p)
7391 {
7392 /* The VxWorks GOT is relocated by the dynamic linker.
7393 Therefore, we must emit relocations rather than simply
7394 computing the values now. */
7395 Elf_Internal_Rela rel;
7396
7397 plt0_entry = elf32_arm_vxworks_exec_plt0_entry;
7398 bfd_put_32 (output_bfd, plt0_entry[0], splt->contents + 0);
7399 bfd_put_32 (output_bfd, plt0_entry[1], splt->contents + 4);
7400 bfd_put_32 (output_bfd, plt0_entry[2], splt->contents + 8);
7401 bfd_put_32 (output_bfd, got_address, splt->contents + 12);
7402
7403 /* Generate a relocation for _GLOBAL_OFFSET_TABLE_. */
7404 rel.r_offset = plt_address + 12;
7405 rel.r_info = ELF32_R_INFO (htab->root.hgot->indx, R_ARM_ABS32);
7406 rel.r_addend = 0;
7407 SWAP_RELOC_OUT (htab) (output_bfd, &rel,
7408 htab->srelplt2->contents);
7409 }
7410 else
7411 {
7412 got_displacement = got_address - (plt_address + 16);
7413
7414 plt0_entry = elf32_arm_plt0_entry;
7415 bfd_put_32 (output_bfd, plt0_entry[0], splt->contents + 0);
7416 bfd_put_32 (output_bfd, plt0_entry[1], splt->contents + 4);
7417 bfd_put_32 (output_bfd, plt0_entry[2], splt->contents + 8);
7418 bfd_put_32 (output_bfd, plt0_entry[3], splt->contents + 12);
7419
7420 #ifdef FOUR_WORD_PLT
7421 /* The displacement value goes in the otherwise-unused
7422 last word of the second entry. */
7423 bfd_put_32 (output_bfd, got_displacement, splt->contents + 28);
7424 #else
7425 bfd_put_32 (output_bfd, got_displacement, splt->contents + 16);
7426 #endif
7427 }
7428 }
7429
7430 /* UnixWare sets the entsize of .plt to 4, although that doesn't
7431 really seem like the right value. */
7432 elf_section_data (splt->output_section)->this_hdr.sh_entsize = 4;
7433
7434 if (htab->vxworks_p && !info->shared && htab->splt->size > 0)
7435 {
7436 /* Correct the .rel(a).plt.unloaded relocations. They will have
7437 incorrect symbol indexes. */
7438 int num_plts;
7439 unsigned char *p;
7440
7441 num_plts = ((htab->splt->size - htab->plt_header_size)
7442 / htab->plt_entry_size);
7443 p = htab->srelplt2->contents + RELOC_SIZE (htab);
7444
7445 for (; num_plts; num_plts--)
7446 {
7447 Elf_Internal_Rela rel;
7448
7449 SWAP_RELOC_IN (htab) (output_bfd, p, &rel);
7450 rel.r_info = ELF32_R_INFO (htab->root.hgot->indx, R_ARM_ABS32);
7451 SWAP_RELOC_OUT (htab) (output_bfd, &rel, p);
7452 p += RELOC_SIZE (htab);
7453
7454 SWAP_RELOC_IN (htab) (output_bfd, p, &rel);
7455 rel.r_info = ELF32_R_INFO (htab->root.hplt->indx, R_ARM_ABS32);
7456 SWAP_RELOC_OUT (htab) (output_bfd, &rel, p);
7457 p += RELOC_SIZE (htab);
7458 }
7459 }
7460 }
7461
7462 /* Fill in the first three entries in the global offset table. */
7463 if (sgot)
7464 {
7465 if (sgot->size > 0)
7466 {
7467 if (sdyn == NULL)
7468 bfd_put_32 (output_bfd, (bfd_vma) 0, sgot->contents);
7469 else
7470 bfd_put_32 (output_bfd,
7471 sdyn->output_section->vma + sdyn->output_offset,
7472 sgot->contents);
7473 bfd_put_32 (output_bfd, (bfd_vma) 0, sgot->contents + 4);
7474 bfd_put_32 (output_bfd, (bfd_vma) 0, sgot->contents + 8);
7475 }
7476
7477 elf_section_data (sgot->output_section)->this_hdr.sh_entsize = 4;
7478 }
7479
7480 return TRUE;
7481 }
7482
7483 static void
elf32_arm_post_process_headers(bfd * abfd,struct bfd_link_info * link_info ATTRIBUTE_UNUSED)7484 elf32_arm_post_process_headers (bfd * abfd, struct bfd_link_info * link_info ATTRIBUTE_UNUSED)
7485 {
7486 Elf_Internal_Ehdr * i_ehdrp; /* ELF file header, internal form. */
7487 struct elf32_arm_link_hash_table *globals;
7488
7489 i_ehdrp = elf_elfheader (abfd);
7490
7491 if (EF_ARM_EABI_VERSION (i_ehdrp->e_flags) == EF_ARM_EABI_UNKNOWN)
7492 i_ehdrp->e_ident[EI_OSABI] = ELFOSABI_ARM;
7493 else
7494 i_ehdrp->e_ident[EI_OSABI] = 0;
7495 i_ehdrp->e_ident[EI_ABIVERSION] = ARM_ELF_ABI_VERSION;
7496
7497 if (link_info)
7498 {
7499 globals = elf32_arm_hash_table (link_info);
7500 if (globals->byteswap_code)
7501 i_ehdrp->e_flags |= EF_ARM_BE8;
7502 }
7503 }
7504
7505 static enum elf_reloc_type_class
elf32_arm_reloc_type_class(const Elf_Internal_Rela * rela)7506 elf32_arm_reloc_type_class (const Elf_Internal_Rela *rela)
7507 {
7508 switch ((int) ELF32_R_TYPE (rela->r_info))
7509 {
7510 case R_ARM_RELATIVE:
7511 return reloc_class_relative;
7512 case R_ARM_JUMP_SLOT:
7513 return reloc_class_plt;
7514 case R_ARM_COPY:
7515 return reloc_class_copy;
7516 default:
7517 return reloc_class_normal;
7518 }
7519 }
7520
7521 /* Set the right machine number for an Arm ELF file. */
7522
7523 static bfd_boolean
elf32_arm_section_flags(flagword * flags,const Elf_Internal_Shdr * hdr)7524 elf32_arm_section_flags (flagword *flags, const Elf_Internal_Shdr *hdr)
7525 {
7526 if (hdr->sh_type == SHT_NOTE)
7527 *flags |= SEC_LINK_ONCE | SEC_LINK_DUPLICATES_SAME_CONTENTS;
7528
7529 return TRUE;
7530 }
7531
7532 static void
elf32_arm_final_write_processing(bfd * abfd,bfd_boolean linker ATTRIBUTE_UNUSED)7533 elf32_arm_final_write_processing (bfd *abfd, bfd_boolean linker ATTRIBUTE_UNUSED)
7534 {
7535 bfd_arm_update_notes (abfd, ARM_NOTE_SECTION);
7536 }
7537
7538 /* Return TRUE if this is an unwinding table entry. */
7539
7540 static bfd_boolean
is_arm_elf_unwind_section_name(bfd * abfd ATTRIBUTE_UNUSED,const char * name)7541 is_arm_elf_unwind_section_name (bfd * abfd ATTRIBUTE_UNUSED, const char * name)
7542 {
7543 size_t len1, len2;
7544
7545 len1 = sizeof (ELF_STRING_ARM_unwind) - 1;
7546 len2 = sizeof (ELF_STRING_ARM_unwind_once) - 1;
7547 return (strncmp (name, ELF_STRING_ARM_unwind, len1) == 0
7548 || strncmp (name, ELF_STRING_ARM_unwind_once, len2) == 0);
7549 }
7550
7551
7552 /* Set the type and flags for an ARM section. We do this by
7553 the section name, which is a hack, but ought to work. */
7554
7555 static bfd_boolean
elf32_arm_fake_sections(bfd * abfd,Elf_Internal_Shdr * hdr,asection * sec)7556 elf32_arm_fake_sections (bfd * abfd, Elf_Internal_Shdr * hdr, asection * sec)
7557 {
7558 const char * name;
7559
7560 name = bfd_get_section_name (abfd, sec);
7561
7562 if (is_arm_elf_unwind_section_name (abfd, name))
7563 {
7564 hdr->sh_type = SHT_ARM_EXIDX;
7565 hdr->sh_flags |= SHF_LINK_ORDER;
7566 }
7567 else if (strcmp(name, ".ARM.attributes") == 0)
7568 {
7569 hdr->sh_type = SHT_ARM_ATTRIBUTES;
7570 }
7571 return TRUE;
7572 }
7573
7574 /* Parse an Arm EABI attributes section. */
7575 static void
elf32_arm_parse_attributes(bfd * abfd,Elf_Internal_Shdr * hdr)7576 elf32_arm_parse_attributes (bfd *abfd, Elf_Internal_Shdr * hdr)
7577 {
7578 bfd_byte *contents;
7579 bfd_byte *p;
7580 bfd_vma len;
7581
7582 contents = bfd_malloc (hdr->sh_size);
7583 if (!contents)
7584 return;
7585 if (!bfd_get_section_contents (abfd, hdr->bfd_section, contents, 0,
7586 hdr->sh_size))
7587 {
7588 free (contents);
7589 return;
7590 }
7591 p = contents;
7592 if (*(p++) == 'A')
7593 {
7594 len = hdr->sh_size - 1;
7595 while (len > 0)
7596 {
7597 int namelen;
7598 bfd_vma section_len;
7599
7600 section_len = bfd_get_32 (abfd, p);
7601 p += 4;
7602 if (section_len > len)
7603 section_len = len;
7604 len -= section_len;
7605 namelen = strlen ((char *)p) + 1;
7606 section_len -= namelen + 4;
7607 if (strcmp((char *)p, "aeabi") != 0)
7608 {
7609 /* Vendor section. Ignore it. */
7610 p += namelen + section_len;
7611 }
7612 else
7613 {
7614 p += namelen;
7615 while (section_len > 0)
7616 {
7617 int tag;
7618 unsigned int n;
7619 unsigned int val;
7620 bfd_vma subsection_len;
7621 bfd_byte *end;
7622
7623 tag = read_unsigned_leb128 (abfd, p, &n);
7624 p += n;
7625 subsection_len = bfd_get_32 (abfd, p);
7626 p += 4;
7627 if (subsection_len > section_len)
7628 subsection_len = section_len;
7629 section_len -= subsection_len;
7630 subsection_len -= n + 4;
7631 end = p + subsection_len;
7632 switch (tag)
7633 {
7634 case Tag_File:
7635 while (p < end)
7636 {
7637 bfd_boolean is_string;
7638
7639 tag = read_unsigned_leb128 (abfd, p, &n);
7640 p += n;
7641 if (tag == 4 || tag == 5)
7642 is_string = 1;
7643 else if (tag < 32)
7644 is_string = 0;
7645 else
7646 is_string = (tag & 1) != 0;
7647 if (tag == Tag_compatibility)
7648 {
7649 val = read_unsigned_leb128 (abfd, p, &n);
7650 p += n;
7651 elf32_arm_add_eabi_attr_compat (abfd, val,
7652 (char *)p);
7653 p += strlen ((char *)p) + 1;
7654 }
7655 else if (is_string)
7656 {
7657 elf32_arm_add_eabi_attr_string (abfd, tag,
7658 (char *)p);
7659 p += strlen ((char *)p) + 1;
7660 }
7661 else
7662 {
7663 val = read_unsigned_leb128 (abfd, p, &n);
7664 p += n;
7665 elf32_arm_add_eabi_attr_int (abfd, tag, val);
7666 }
7667 }
7668 break;
7669 case Tag_Section:
7670 case Tag_Symbol:
7671 /* Don't have anywhere convenient to attach these.
7672 Fall through for now. */
7673 default:
7674 /* Ignore things we don't kow about. */
7675 p += subsection_len;
7676 subsection_len = 0;
7677 break;
7678 }
7679 }
7680 }
7681 }
7682 }
7683 free (contents);
7684 }
7685
7686 /* Handle an ARM specific section when reading an object file. This is
7687 called when bfd_section_from_shdr finds a section with an unknown
7688 type. */
7689
7690 static bfd_boolean
elf32_arm_section_from_shdr(bfd * abfd,Elf_Internal_Shdr * hdr,const char * name,int shindex)7691 elf32_arm_section_from_shdr (bfd *abfd,
7692 Elf_Internal_Shdr * hdr,
7693 const char *name,
7694 int shindex)
7695 {
7696 /* There ought to be a place to keep ELF backend specific flags, but
7697 at the moment there isn't one. We just keep track of the
7698 sections by their name, instead. Fortunately, the ABI gives
7699 names for all the ARM specific sections, so we will probably get
7700 away with this. */
7701 switch (hdr->sh_type)
7702 {
7703 case SHT_ARM_EXIDX:
7704 case SHT_ARM_PREEMPTMAP:
7705 case SHT_ARM_ATTRIBUTES:
7706 break;
7707
7708 default:
7709 return FALSE;
7710 }
7711
7712 if (! _bfd_elf_make_section_from_shdr (abfd, hdr, name, shindex))
7713 return FALSE;
7714
7715 if (hdr->sh_type == SHT_ARM_ATTRIBUTES)
7716 elf32_arm_parse_attributes(abfd, hdr);
7717 return TRUE;
7718 }
7719
7720 /* A structure used to record a list of sections, independently
7721 of the next and prev fields in the asection structure. */
7722 typedef struct section_list
7723 {
7724 asection * sec;
7725 struct section_list * next;
7726 struct section_list * prev;
7727 }
7728 section_list;
7729
7730 /* Unfortunately we need to keep a list of sections for which
7731 an _arm_elf_section_data structure has been allocated. This
7732 is because it is possible for functions like elf32_arm_write_section
7733 to be called on a section which has had an elf_data_structure
7734 allocated for it (and so the used_by_bfd field is valid) but
7735 for which the ARM extended version of this structure - the
7736 _arm_elf_section_data structure - has not been allocated. */
7737 static section_list * sections_with_arm_elf_section_data = NULL;
7738
7739 static void
record_section_with_arm_elf_section_data(asection * sec)7740 record_section_with_arm_elf_section_data (asection * sec)
7741 {
7742 struct section_list * entry;
7743
7744 entry = bfd_malloc (sizeof (* entry));
7745 if (entry == NULL)
7746 return;
7747 entry->sec = sec;
7748 entry->next = sections_with_arm_elf_section_data;
7749 entry->prev = NULL;
7750 if (entry->next != NULL)
7751 entry->next->prev = entry;
7752 sections_with_arm_elf_section_data = entry;
7753 }
7754
7755 static struct section_list *
find_arm_elf_section_entry(asection * sec)7756 find_arm_elf_section_entry (asection * sec)
7757 {
7758 struct section_list * entry;
7759 static struct section_list * last_entry = NULL;
7760
7761 /* This is a short cut for the typical case where the sections are added
7762 to the sections_with_arm_elf_section_data list in forward order and
7763 then looked up here in backwards order. This makes a real difference
7764 to the ld-srec/sec64k.exp linker test. */
7765 entry = sections_with_arm_elf_section_data;
7766 if (last_entry != NULL)
7767 {
7768 if (last_entry->sec == sec)
7769 entry = last_entry;
7770 else if (last_entry->next != NULL
7771 && last_entry->next->sec == sec)
7772 entry = last_entry->next;
7773 }
7774
7775 for (; entry; entry = entry->next)
7776 if (entry->sec == sec)
7777 break;
7778
7779 if (entry)
7780 /* Record the entry prior to this one - it is the entry we are most
7781 likely to want to locate next time. Also this way if we have been
7782 called from unrecord_section_with_arm_elf_section_data() we will not
7783 be caching a pointer that is about to be freed. */
7784 last_entry = entry->prev;
7785
7786 return entry;
7787 }
7788
7789 static _arm_elf_section_data *
get_arm_elf_section_data(asection * sec)7790 get_arm_elf_section_data (asection * sec)
7791 {
7792 struct section_list * entry;
7793
7794 entry = find_arm_elf_section_entry (sec);
7795
7796 if (entry)
7797 return elf32_arm_section_data (entry->sec);
7798 else
7799 return NULL;
7800 }
7801
7802 static void
unrecord_section_with_arm_elf_section_data(asection * sec)7803 unrecord_section_with_arm_elf_section_data (asection * sec)
7804 {
7805 struct section_list * entry;
7806
7807 entry = find_arm_elf_section_entry (sec);
7808
7809 if (entry)
7810 {
7811 if (entry->prev != NULL)
7812 entry->prev->next = entry->next;
7813 if (entry->next != NULL)
7814 entry->next->prev = entry->prev;
7815 if (entry == sections_with_arm_elf_section_data)
7816 sections_with_arm_elf_section_data = entry->next;
7817 free (entry);
7818 }
7819 }
7820
7821 /* Called for each symbol. Builds a section map based on mapping symbols.
7822 Does not alter any of the symbols. */
7823
7824 static bfd_boolean
elf32_arm_output_symbol_hook(struct bfd_link_info * info,const char * name,Elf_Internal_Sym * elfsym,asection * input_sec,struct elf_link_hash_entry * h)7825 elf32_arm_output_symbol_hook (struct bfd_link_info *info,
7826 const char *name,
7827 Elf_Internal_Sym *elfsym,
7828 asection *input_sec,
7829 struct elf_link_hash_entry *h)
7830 {
7831 int mapcount;
7832 elf32_arm_section_map *map;
7833 elf32_arm_section_map *newmap;
7834 _arm_elf_section_data *arm_data;
7835 struct elf32_arm_link_hash_table *globals;
7836
7837 globals = elf32_arm_hash_table (info);
7838 if (globals->vxworks_p
7839 && !elf_vxworks_link_output_symbol_hook (info, name, elfsym,
7840 input_sec, h))
7841 return FALSE;
7842
7843 /* Only do this on final link. */
7844 if (info->relocatable)
7845 return TRUE;
7846
7847 /* Only build a map if we need to byteswap code. */
7848 if (!globals->byteswap_code)
7849 return TRUE;
7850
7851 /* We only want mapping symbols. */
7852 if (! bfd_is_arm_mapping_symbol_name (name))
7853 return TRUE;
7854
7855 /* If this section has not been allocated an _arm_elf_section_data
7856 structure then we cannot record anything. */
7857 arm_data = get_arm_elf_section_data (input_sec);
7858 if (arm_data == NULL)
7859 return TRUE;
7860
7861 mapcount = arm_data->mapcount + 1;
7862 map = arm_data->map;
7863
7864 /* TODO: This may be inefficient, but we probably don't usually have many
7865 mapping symbols per section. */
7866 newmap = bfd_realloc (map, mapcount * sizeof (* map));
7867 if (newmap != NULL)
7868 {
7869 arm_data->map = newmap;
7870 arm_data->mapcount = mapcount;
7871
7872 newmap[mapcount - 1].vma = elfsym->st_value;
7873 newmap[mapcount - 1].type = name[1];
7874 }
7875
7876 return TRUE;
7877 }
7878
7879 /* Allocate target specific section data. */
7880
7881 static bfd_boolean
elf32_arm_new_section_hook(bfd * abfd,asection * sec)7882 elf32_arm_new_section_hook (bfd *abfd, asection *sec)
7883 {
7884 _arm_elf_section_data *sdata;
7885 bfd_size_type amt = sizeof (*sdata);
7886
7887 sdata = bfd_zalloc (abfd, amt);
7888 if (sdata == NULL)
7889 return FALSE;
7890 sec->used_by_bfd = sdata;
7891
7892 record_section_with_arm_elf_section_data (sec);
7893
7894 return _bfd_elf_new_section_hook (abfd, sec);
7895 }
7896
7897
7898 /* Used to order a list of mapping symbols by address. */
7899
7900 static int
elf32_arm_compare_mapping(const void * a,const void * b)7901 elf32_arm_compare_mapping (const void * a, const void * b)
7902 {
7903 return ((const elf32_arm_section_map *) a)->vma
7904 > ((const elf32_arm_section_map *) b)->vma;
7905 }
7906
7907
7908 /* Do code byteswapping. Return FALSE afterwards so that the section is
7909 written out as normal. */
7910
7911 static bfd_boolean
elf32_arm_write_section(bfd * output_bfd ATTRIBUTE_UNUSED,asection * sec,bfd_byte * contents)7912 elf32_arm_write_section (bfd *output_bfd ATTRIBUTE_UNUSED, asection *sec,
7913 bfd_byte *contents)
7914 {
7915 int mapcount;
7916 _arm_elf_section_data *arm_data;
7917 elf32_arm_section_map *map;
7918 bfd_vma ptr;
7919 bfd_vma end;
7920 bfd_vma offset;
7921 bfd_byte tmp;
7922 int i;
7923
7924 /* If this section has not been allocated an _arm_elf_section_data
7925 structure then we cannot record anything. */
7926 arm_data = get_arm_elf_section_data (sec);
7927 if (arm_data == NULL)
7928 return FALSE;
7929
7930 mapcount = arm_data->mapcount;
7931 map = arm_data->map;
7932
7933 if (mapcount == 0)
7934 return FALSE;
7935
7936 qsort (map, mapcount, sizeof (* map), elf32_arm_compare_mapping);
7937
7938 offset = sec->output_section->vma + sec->output_offset;
7939 ptr = map[0].vma - offset;
7940 for (i = 0; i < mapcount; i++)
7941 {
7942 if (i == mapcount - 1)
7943 end = sec->size;
7944 else
7945 end = map[i + 1].vma - offset;
7946
7947 switch (map[i].type)
7948 {
7949 case 'a':
7950 /* Byte swap code words. */
7951 while (ptr + 3 < end)
7952 {
7953 tmp = contents[ptr];
7954 contents[ptr] = contents[ptr + 3];
7955 contents[ptr + 3] = tmp;
7956 tmp = contents[ptr + 1];
7957 contents[ptr + 1] = contents[ptr + 2];
7958 contents[ptr + 2] = tmp;
7959 ptr += 4;
7960 }
7961 break;
7962
7963 case 't':
7964 /* Byte swap code halfwords. */
7965 while (ptr + 1 < end)
7966 {
7967 tmp = contents[ptr];
7968 contents[ptr] = contents[ptr + 1];
7969 contents[ptr + 1] = tmp;
7970 ptr += 2;
7971 }
7972 break;
7973
7974 case 'd':
7975 /* Leave data alone. */
7976 break;
7977 }
7978 ptr = end;
7979 }
7980
7981 free (map);
7982 arm_data->mapcount = 0;
7983 arm_data->map = NULL;
7984 unrecord_section_with_arm_elf_section_data (sec);
7985
7986 return FALSE;
7987 }
7988
7989 static void
unrecord_section_via_map_over_sections(bfd * abfd ATTRIBUTE_UNUSED,asection * sec,void * ignore ATTRIBUTE_UNUSED)7990 unrecord_section_via_map_over_sections (bfd * abfd ATTRIBUTE_UNUSED,
7991 asection * sec,
7992 void * ignore ATTRIBUTE_UNUSED)
7993 {
7994 unrecord_section_with_arm_elf_section_data (sec);
7995 }
7996
7997 static bfd_boolean
elf32_arm_close_and_cleanup(bfd * abfd)7998 elf32_arm_close_and_cleanup (bfd * abfd)
7999 {
8000 bfd_map_over_sections (abfd, unrecord_section_via_map_over_sections, NULL);
8001
8002 return _bfd_elf_close_and_cleanup (abfd);
8003 }
8004
8005 /* Display STT_ARM_TFUNC symbols as functions. */
8006
8007 static void
elf32_arm_symbol_processing(bfd * abfd ATTRIBUTE_UNUSED,asymbol * asym)8008 elf32_arm_symbol_processing (bfd *abfd ATTRIBUTE_UNUSED,
8009 asymbol *asym)
8010 {
8011 elf_symbol_type *elfsym = (elf_symbol_type *) asym;
8012
8013 if (ELF_ST_TYPE (elfsym->internal_elf_sym.st_info) == STT_ARM_TFUNC)
8014 elfsym->symbol.flags |= BSF_FUNCTION;
8015 }
8016
8017
8018 /* Mangle thumb function symbols as we read them in. */
8019
8020 static void
elf32_arm_swap_symbol_in(bfd * abfd,const void * psrc,const void * pshn,Elf_Internal_Sym * dst)8021 elf32_arm_swap_symbol_in (bfd * abfd,
8022 const void *psrc,
8023 const void *pshn,
8024 Elf_Internal_Sym *dst)
8025 {
8026 bfd_elf32_swap_symbol_in (abfd, psrc, pshn, dst);
8027
8028 /* New EABI objects mark thumb function symbols by setting the low bit of
8029 the address. Turn these into STT_ARM_TFUNC. */
8030 if (ELF_ST_TYPE (dst->st_info) == STT_FUNC
8031 && (dst->st_value & 1))
8032 {
8033 dst->st_info = ELF_ST_INFO (ELF_ST_BIND (dst->st_info), STT_ARM_TFUNC);
8034 dst->st_value &= ~(bfd_vma) 1;
8035 }
8036 }
8037
8038
8039 /* Mangle thumb function symbols as we write them out. */
8040
8041 static void
elf32_arm_swap_symbol_out(bfd * abfd,const Elf_Internal_Sym * src,void * cdst,void * shndx)8042 elf32_arm_swap_symbol_out (bfd *abfd,
8043 const Elf_Internal_Sym *src,
8044 void *cdst,
8045 void *shndx)
8046 {
8047 Elf_Internal_Sym newsym;
8048
8049 /* We convert STT_ARM_TFUNC symbols into STT_FUNC with the low bit
8050 of the address set, as per the new EABI. We do this unconditionally
8051 because objcopy does not set the elf header flags until after
8052 it writes out the symbol table. */
8053 if (ELF_ST_TYPE (src->st_info) == STT_ARM_TFUNC)
8054 {
8055 newsym = *src;
8056 newsym.st_info = ELF_ST_INFO (ELF_ST_BIND (src->st_info), STT_FUNC);
8057 newsym.st_value |= 1;
8058
8059 src = &newsym;
8060 }
8061 bfd_elf32_swap_symbol_out (abfd, src, cdst, shndx);
8062 }
8063
8064 /* Add the PT_ARM_EXIDX program header. */
8065
8066 static bfd_boolean
elf32_arm_modify_segment_map(bfd * abfd,struct bfd_link_info * info ATTRIBUTE_UNUSED)8067 elf32_arm_modify_segment_map (bfd *abfd,
8068 struct bfd_link_info *info ATTRIBUTE_UNUSED)
8069 {
8070 struct elf_segment_map *m;
8071 asection *sec;
8072
8073 sec = bfd_get_section_by_name (abfd, ".ARM.exidx");
8074 if (sec != NULL && (sec->flags & SEC_LOAD) != 0)
8075 {
8076 /* If there is already a PT_ARM_EXIDX header, then we do not
8077 want to add another one. This situation arises when running
8078 "strip"; the input binary already has the header. */
8079 m = elf_tdata (abfd)->segment_map;
8080 while (m && m->p_type != PT_ARM_EXIDX)
8081 m = m->next;
8082 if (!m)
8083 {
8084 m = bfd_zalloc (abfd, sizeof (struct elf_segment_map));
8085 if (m == NULL)
8086 return FALSE;
8087 m->p_type = PT_ARM_EXIDX;
8088 m->count = 1;
8089 m->sections[0] = sec;
8090
8091 m->next = elf_tdata (abfd)->segment_map;
8092 elf_tdata (abfd)->segment_map = m;
8093 }
8094 }
8095
8096 return TRUE;
8097 }
8098
8099 /* We may add a PT_ARM_EXIDX program header. */
8100
8101 static int
elf32_arm_additional_program_headers(bfd * abfd)8102 elf32_arm_additional_program_headers (bfd *abfd)
8103 {
8104 asection *sec;
8105
8106 sec = bfd_get_section_by_name (abfd, ".ARM.exidx");
8107 if (sec != NULL && (sec->flags & SEC_LOAD) != 0)
8108 return 1;
8109 else
8110 return 0;
8111 }
8112
8113 /* We use this to override swap_symbol_in and swap_symbol_out. */
8114 const struct elf_size_info elf32_arm_size_info = {
8115 sizeof (Elf32_External_Ehdr),
8116 sizeof (Elf32_External_Phdr),
8117 sizeof (Elf32_External_Shdr),
8118 sizeof (Elf32_External_Rel),
8119 sizeof (Elf32_External_Rela),
8120 sizeof (Elf32_External_Sym),
8121 sizeof (Elf32_External_Dyn),
8122 sizeof (Elf_External_Note),
8123 4,
8124 1,
8125 32, 2,
8126 ELFCLASS32, EV_CURRENT,
8127 bfd_elf32_write_out_phdrs,
8128 bfd_elf32_write_shdrs_and_ehdr,
8129 bfd_elf32_write_relocs,
8130 elf32_arm_swap_symbol_in,
8131 elf32_arm_swap_symbol_out,
8132 bfd_elf32_slurp_reloc_table,
8133 bfd_elf32_slurp_symbol_table,
8134 bfd_elf32_swap_dyn_in,
8135 bfd_elf32_swap_dyn_out,
8136 bfd_elf32_swap_reloc_in,
8137 bfd_elf32_swap_reloc_out,
8138 bfd_elf32_swap_reloca_in,
8139 bfd_elf32_swap_reloca_out
8140 };
8141
8142 #define ELF_ARCH bfd_arch_arm
8143 #define ELF_MACHINE_CODE EM_ARM
8144 #ifdef __QNXTARGET__
8145 #define ELF_MAXPAGESIZE 0x1000
8146 #else
8147 #define ELF_MAXPAGESIZE 0x8000
8148 #endif
8149 #define ELF_MINPAGESIZE 0x1000
8150
8151 #define bfd_elf32_mkobject elf32_arm_mkobject
8152
8153 #define bfd_elf32_bfd_copy_private_bfd_data elf32_arm_copy_private_bfd_data
8154 #define bfd_elf32_bfd_merge_private_bfd_data elf32_arm_merge_private_bfd_data
8155 #define bfd_elf32_bfd_set_private_flags elf32_arm_set_private_flags
8156 #define bfd_elf32_bfd_print_private_bfd_data elf32_arm_print_private_bfd_data
8157 #define bfd_elf32_bfd_link_hash_table_create elf32_arm_link_hash_table_create
8158 #define bfd_elf32_bfd_reloc_type_lookup elf32_arm_reloc_type_lookup
8159 #define bfd_elf32_find_nearest_line elf32_arm_find_nearest_line
8160 #define bfd_elf32_find_inliner_info elf32_arm_find_inliner_info
8161 #define bfd_elf32_new_section_hook elf32_arm_new_section_hook
8162 #define bfd_elf32_bfd_is_target_special_symbol elf32_arm_is_target_special_symbol
8163 #define bfd_elf32_close_and_cleanup elf32_arm_close_and_cleanup
8164 #define bfd_elf32_bfd_final_link elf32_arm_bfd_final_link
8165
8166 #define elf_backend_get_symbol_type elf32_arm_get_symbol_type
8167 #define elf_backend_gc_mark_hook elf32_arm_gc_mark_hook
8168 #define elf_backend_gc_sweep_hook elf32_arm_gc_sweep_hook
8169 #define elf_backend_check_relocs elf32_arm_check_relocs
8170 #define elf_backend_relocate_section elf32_arm_relocate_section
8171 #define elf_backend_write_section elf32_arm_write_section
8172 #define elf_backend_adjust_dynamic_symbol elf32_arm_adjust_dynamic_symbol
8173 #define elf_backend_create_dynamic_sections elf32_arm_create_dynamic_sections
8174 #define elf_backend_finish_dynamic_symbol elf32_arm_finish_dynamic_symbol
8175 #define elf_backend_finish_dynamic_sections elf32_arm_finish_dynamic_sections
8176 #define elf_backend_link_output_symbol_hook elf32_arm_output_symbol_hook
8177 #define elf_backend_size_dynamic_sections elf32_arm_size_dynamic_sections
8178 #define elf_backend_post_process_headers elf32_arm_post_process_headers
8179 #define elf_backend_reloc_type_class elf32_arm_reloc_type_class
8180 #define elf_backend_object_p elf32_arm_object_p
8181 #define elf_backend_section_flags elf32_arm_section_flags
8182 #define elf_backend_fake_sections elf32_arm_fake_sections
8183 #define elf_backend_section_from_shdr elf32_arm_section_from_shdr
8184 #define elf_backend_final_write_processing elf32_arm_final_write_processing
8185 #define elf_backend_copy_indirect_symbol elf32_arm_copy_indirect_symbol
8186 #define elf_backend_symbol_processing elf32_arm_symbol_processing
8187 #define elf_backend_size_info elf32_arm_size_info
8188 #define elf_backend_modify_segment_map elf32_arm_modify_segment_map
8189 #define elf_backend_additional_program_headers \
8190 elf32_arm_additional_program_headers
8191
8192 #define elf_backend_can_refcount 1
8193 #define elf_backend_can_gc_sections 1
8194 #define elf_backend_plt_readonly 1
8195 #define elf_backend_want_got_plt 1
8196 #define elf_backend_want_plt_sym 0
8197 #define elf_backend_may_use_rel_p 1
8198 #define elf_backend_may_use_rela_p 0
8199 #define elf_backend_default_use_rela_p 0
8200 #define elf_backend_rela_normal 0
8201
8202 #define elf_backend_got_header_size 12
8203
8204 #include "elf32-target.h"
8205
8206 /* VxWorks Targets */
8207
8208 #undef TARGET_LITTLE_SYM
8209 #define TARGET_LITTLE_SYM bfd_elf32_littlearm_vxworks_vec
8210 #undef TARGET_LITTLE_NAME
8211 #define TARGET_LITTLE_NAME "elf32-littlearm-vxworks"
8212 #undef TARGET_BIG_SYM
8213 #define TARGET_BIG_SYM bfd_elf32_bigarm_vxworks_vec
8214 #undef TARGET_BIG_NAME
8215 #define TARGET_BIG_NAME "elf32-bigarm-vxworks"
8216
8217 /* Like elf32_arm_link_hash_table_create -- but overrides
8218 appropriately for VxWorks. */
8219 static struct bfd_link_hash_table *
elf32_arm_vxworks_link_hash_table_create(bfd * abfd)8220 elf32_arm_vxworks_link_hash_table_create (bfd *abfd)
8221 {
8222 struct bfd_link_hash_table *ret;
8223
8224 ret = elf32_arm_link_hash_table_create (abfd);
8225 if (ret)
8226 {
8227 struct elf32_arm_link_hash_table *htab
8228 = (struct elf32_arm_link_hash_table *) ret;
8229 htab->use_rel = 0;
8230 htab->vxworks_p = 1;
8231 }
8232 return ret;
8233 }
8234
8235 static void
elf32_arm_vxworks_final_write_processing(bfd * abfd,bfd_boolean linker)8236 elf32_arm_vxworks_final_write_processing (bfd *abfd, bfd_boolean linker)
8237 {
8238 elf32_arm_final_write_processing (abfd, linker);
8239 elf_vxworks_final_write_processing (abfd, linker);
8240 }
8241
8242 #undef elf32_bed
8243 #define elf32_bed elf32_arm_vxworks_bed
8244
8245 #undef bfd_elf32_bfd_link_hash_table_create
8246 #define bfd_elf32_bfd_link_hash_table_create \
8247 elf32_arm_vxworks_link_hash_table_create
8248 #undef elf_backend_add_symbol_hook
8249 #define elf_backend_add_symbol_hook \
8250 elf_vxworks_add_symbol_hook
8251 #undef elf_backend_final_write_processing
8252 #define elf_backend_final_write_processing \
8253 elf32_arm_vxworks_final_write_processing
8254 #undef elf_backend_emit_relocs
8255 #define elf_backend_emit_relocs \
8256 elf_vxworks_emit_relocs
8257
8258 #undef elf_backend_may_use_rel_p
8259 #define elf_backend_may_use_rel_p 0
8260 #undef elf_backend_may_use_rela_p
8261 #define elf_backend_may_use_rela_p 1
8262 #undef elf_backend_default_use_rela_p
8263 #define elf_backend_default_use_rela_p 1
8264 #undef elf_backend_rela_normal
8265 #define elf_backend_rela_normal 1
8266 #undef elf_backend_want_plt_sym
8267 #define elf_backend_want_plt_sym 1
8268 #undef ELF_MAXPAGESIZE
8269 #define ELF_MAXPAGESIZE 0x1000
8270
8271 #include "elf32-target.h"
8272
8273
8274 /* Symbian OS Targets */
8275
8276 #undef TARGET_LITTLE_SYM
8277 #define TARGET_LITTLE_SYM bfd_elf32_littlearm_symbian_vec
8278 #undef TARGET_LITTLE_NAME
8279 #define TARGET_LITTLE_NAME "elf32-littlearm-symbian"
8280 #undef TARGET_BIG_SYM
8281 #define TARGET_BIG_SYM bfd_elf32_bigarm_symbian_vec
8282 #undef TARGET_BIG_NAME
8283 #define TARGET_BIG_NAME "elf32-bigarm-symbian"
8284
8285 /* Like elf32_arm_link_hash_table_create -- but overrides
8286 appropriately for Symbian OS. */
8287 static struct bfd_link_hash_table *
elf32_arm_symbian_link_hash_table_create(bfd * abfd)8288 elf32_arm_symbian_link_hash_table_create (bfd *abfd)
8289 {
8290 struct bfd_link_hash_table *ret;
8291
8292 ret = elf32_arm_link_hash_table_create (abfd);
8293 if (ret)
8294 {
8295 struct elf32_arm_link_hash_table *htab
8296 = (struct elf32_arm_link_hash_table *)ret;
8297 /* There is no PLT header for Symbian OS. */
8298 htab->plt_header_size = 0;
8299 /* The PLT entries are each three instructions. */
8300 htab->plt_entry_size = 4 * NUM_ELEM (elf32_arm_symbian_plt_entry);
8301 htab->symbian_p = 1;
8302 /* Symbian uses armv5t or above, so use_blx is always true. */
8303 htab->use_blx = 1;
8304 htab->root.is_relocatable_executable = 1;
8305 }
8306 return ret;
8307 }
8308
8309 static const struct bfd_elf_special_section
8310 elf32_arm_symbian_special_sections[] =
8311 {
8312 /* In a BPABI executable, the dynamic linking sections do not go in
8313 the loadable read-only segment. The post-linker may wish to
8314 refer to these sections, but they are not part of the final
8315 program image. */
8316 { ".dynamic", 8, 0, SHT_DYNAMIC, 0 },
8317 { ".dynstr", 7, 0, SHT_STRTAB, 0 },
8318 { ".dynsym", 7, 0, SHT_DYNSYM, 0 },
8319 { ".got", 4, 0, SHT_PROGBITS, 0 },
8320 { ".hash", 5, 0, SHT_HASH, 0 },
8321 /* These sections do not need to be writable as the SymbianOS
8322 postlinker will arrange things so that no dynamic relocation is
8323 required. */
8324 { ".init_array", 11, 0, SHT_INIT_ARRAY, SHF_ALLOC },
8325 { ".fini_array", 11, 0, SHT_FINI_ARRAY, SHF_ALLOC },
8326 { ".preinit_array", 14, 0, SHT_PREINIT_ARRAY, SHF_ALLOC },
8327 { NULL, 0, 0, 0, 0 }
8328 };
8329
8330 static void
elf32_arm_symbian_begin_write_processing(bfd * abfd,struct bfd_link_info * link_info ATTRIBUTE_UNUSED)8331 elf32_arm_symbian_begin_write_processing (bfd *abfd,
8332 struct bfd_link_info *link_info
8333 ATTRIBUTE_UNUSED)
8334 {
8335 /* BPABI objects are never loaded directly by an OS kernel; they are
8336 processed by a postlinker first, into an OS-specific format. If
8337 the D_PAGED bit is set on the file, BFD will align segments on
8338 page boundaries, so that an OS can directly map the file. With
8339 BPABI objects, that just results in wasted space. In addition,
8340 because we clear the D_PAGED bit, map_sections_to_segments will
8341 recognize that the program headers should not be mapped into any
8342 loadable segment. */
8343 abfd->flags &= ~D_PAGED;
8344 }
8345
8346 static bfd_boolean
elf32_arm_symbian_modify_segment_map(bfd * abfd,struct bfd_link_info * info)8347 elf32_arm_symbian_modify_segment_map (bfd *abfd,
8348 struct bfd_link_info *info)
8349 {
8350 struct elf_segment_map *m;
8351 asection *dynsec;
8352
8353 /* BPABI shared libraries and executables should have a PT_DYNAMIC
8354 segment. However, because the .dynamic section is not marked
8355 with SEC_LOAD, the generic ELF code will not create such a
8356 segment. */
8357 dynsec = bfd_get_section_by_name (abfd, ".dynamic");
8358 if (dynsec)
8359 {
8360 m = _bfd_elf_make_dynamic_segment (abfd, dynsec);
8361 m->next = elf_tdata (abfd)->segment_map;
8362 elf_tdata (abfd)->segment_map = m;
8363 }
8364
8365 /* Also call the generic arm routine. */
8366 return elf32_arm_modify_segment_map (abfd, info);
8367 }
8368
8369 #undef elf32_bed
8370 #define elf32_bed elf32_arm_symbian_bed
8371
8372 /* The dynamic sections are not allocated on SymbianOS; the postlinker
8373 will process them and then discard them. */
8374 #undef ELF_DYNAMIC_SEC_FLAGS
8375 #define ELF_DYNAMIC_SEC_FLAGS \
8376 (SEC_HAS_CONTENTS | SEC_IN_MEMORY | SEC_LINKER_CREATED)
8377
8378 #undef bfd_elf32_bfd_link_hash_table_create
8379 #define bfd_elf32_bfd_link_hash_table_create \
8380 elf32_arm_symbian_link_hash_table_create
8381 #undef elf_backend_add_symbol_hook
8382
8383 #undef elf_backend_special_sections
8384 #define elf_backend_special_sections elf32_arm_symbian_special_sections
8385
8386 #undef elf_backend_begin_write_processing
8387 #define elf_backend_begin_write_processing \
8388 elf32_arm_symbian_begin_write_processing
8389 #undef elf_backend_final_write_processing
8390 #define elf_backend_final_write_processing \
8391 elf32_arm_final_write_processing
8392 #undef elf_backend_emit_relocs
8393
8394 #undef elf_backend_modify_segment_map
8395 #define elf_backend_modify_segment_map elf32_arm_symbian_modify_segment_map
8396
8397 /* There is no .got section for BPABI objects, and hence no header. */
8398 #undef elf_backend_got_header_size
8399 #define elf_backend_got_header_size 0
8400
8401 /* Similarly, there is no .got.plt section. */
8402 #undef elf_backend_want_got_plt
8403 #define elf_backend_want_got_plt 0
8404
8405 #undef elf_backend_may_use_rel_p
8406 #define elf_backend_may_use_rel_p 1
8407 #undef elf_backend_may_use_rela_p
8408 #define elf_backend_may_use_rela_p 0
8409 #undef elf_backend_default_use_rela_p
8410 #define elf_backend_default_use_rela_p 0
8411 #undef elf_backend_rela_normal
8412 #define elf_backend_rela_normal 0
8413 #undef elf_backend_want_plt_sym
8414 #define elf_backend_want_plt_sym 0
8415 #undef ELF_MAXPAGESIZE
8416 #define ELF_MAXPAGESIZE 0x8000
8417
8418 #include "elf32-target.h"
8419