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