* elf32-arm.c (elf32_arm_final_link_relocate): Add
[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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
20
21 #include "elf/arm.h"
22 #include "bfd.h"
23 #include "sysdep.h"
24 #include "libbfd.h"
25 #include "elf-bfd.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 static reloc_howto_type * elf32_arm_reloc_type_lookup
38 PARAMS ((bfd * abfd, bfd_reloc_code_real_type code));
39 static bfd_boolean elf32_arm_nabi_grok_prstatus
40 PARAMS ((bfd *abfd, Elf_Internal_Note *note));
41 static bfd_boolean elf32_arm_nabi_grok_psinfo
42 PARAMS ((bfd *abfd, Elf_Internal_Note *note));
43
44 /* Note: code such as elf32_arm_reloc_type_lookup expect to use e.g.
45 R_ARM_PC24 as an index into this, and find the R_ARM_PC24 HOWTO
46 in that slot. */
47
48 static reloc_howto_type elf32_arm_howto_table[] =
49 {
50 /* No relocation */
51 HOWTO (R_ARM_NONE, /* type */
52 0, /* rightshift */
53 0, /* size (0 = byte, 1 = short, 2 = long) */
54 0, /* bitsize */
55 FALSE, /* pc_relative */
56 0, /* bitpos */
57 complain_overflow_dont,/* complain_on_overflow */
58 bfd_elf_generic_reloc, /* special_function */
59 "R_ARM_NONE", /* name */
60 FALSE, /* partial_inplace */
61 0, /* src_mask */
62 0, /* dst_mask */
63 FALSE), /* pcrel_offset */
64
65 HOWTO (R_ARM_PC24, /* type */
66 2, /* rightshift */
67 2, /* size (0 = byte, 1 = short, 2 = long) */
68 24, /* bitsize */
69 TRUE, /* pc_relative */
70 0, /* bitpos */
71 complain_overflow_signed,/* complain_on_overflow */
72 bfd_elf_generic_reloc, /* special_function */
73 "R_ARM_PC24", /* name */
74 FALSE, /* partial_inplace */
75 0x00ffffff, /* src_mask */
76 0x00ffffff, /* dst_mask */
77 TRUE), /* pcrel_offset */
78
79 /* 32 bit absolute */
80 HOWTO (R_ARM_ABS32, /* type */
81 0, /* rightshift */
82 2, /* size (0 = byte, 1 = short, 2 = long) */
83 32, /* bitsize */
84 FALSE, /* pc_relative */
85 0, /* bitpos */
86 complain_overflow_bitfield,/* complain_on_overflow */
87 bfd_elf_generic_reloc, /* special_function */
88 "R_ARM_ABS32", /* name */
89 FALSE, /* partial_inplace */
90 0xffffffff, /* src_mask */
91 0xffffffff, /* dst_mask */
92 FALSE), /* pcrel_offset */
93
94 /* standard 32bit pc-relative reloc */
95 HOWTO (R_ARM_REL32, /* type */
96 0, /* rightshift */
97 2, /* size (0 = byte, 1 = short, 2 = long) */
98 32, /* bitsize */
99 TRUE, /* pc_relative */
100 0, /* bitpos */
101 complain_overflow_bitfield,/* complain_on_overflow */
102 bfd_elf_generic_reloc, /* special_function */
103 "R_ARM_REL32", /* name */
104 FALSE, /* partial_inplace */
105 0xffffffff, /* src_mask */
106 0xffffffff, /* dst_mask */
107 TRUE), /* pcrel_offset */
108
109 /* 8 bit absolute */
110 HOWTO (R_ARM_PC13, /* type */
111 0, /* rightshift */
112 0, /* size (0 = byte, 1 = short, 2 = long) */
113 8, /* bitsize */
114 FALSE, /* pc_relative */
115 0, /* bitpos */
116 complain_overflow_bitfield,/* complain_on_overflow */
117 bfd_elf_generic_reloc, /* special_function */
118 "R_ARM_PC13", /* name */
119 FALSE, /* partial_inplace */
120 0x000000ff, /* src_mask */
121 0x000000ff, /* dst_mask */
122 FALSE), /* pcrel_offset */
123
124 /* 16 bit absolute */
125 HOWTO (R_ARM_ABS16, /* type */
126 0, /* rightshift */
127 1, /* size (0 = byte, 1 = short, 2 = long) */
128 16, /* bitsize */
129 FALSE, /* pc_relative */
130 0, /* bitpos */
131 complain_overflow_bitfield,/* complain_on_overflow */
132 bfd_elf_generic_reloc, /* special_function */
133 "R_ARM_ABS16", /* name */
134 FALSE, /* partial_inplace */
135 0x0000ffff, /* src_mask */
136 0x0000ffff, /* dst_mask */
137 FALSE), /* pcrel_offset */
138
139 /* 12 bit absolute */
140 HOWTO (R_ARM_ABS12, /* type */
141 0, /* rightshift */
142 2, /* size (0 = byte, 1 = short, 2 = long) */
143 12, /* bitsize */
144 FALSE, /* pc_relative */
145 0, /* bitpos */
146 complain_overflow_bitfield,/* complain_on_overflow */
147 bfd_elf_generic_reloc, /* special_function */
148 "R_ARM_ABS12", /* name */
149 FALSE, /* partial_inplace */
150 0x000008ff, /* src_mask */
151 0x000008ff, /* dst_mask */
152 FALSE), /* pcrel_offset */
153
154 HOWTO (R_ARM_THM_ABS5, /* type */
155 6, /* rightshift */
156 1, /* size (0 = byte, 1 = short, 2 = long) */
157 5, /* bitsize */
158 FALSE, /* pc_relative */
159 0, /* bitpos */
160 complain_overflow_bitfield,/* complain_on_overflow */
161 bfd_elf_generic_reloc, /* special_function */
162 "R_ARM_THM_ABS5", /* name */
163 FALSE, /* partial_inplace */
164 0x000007e0, /* src_mask */
165 0x000007e0, /* dst_mask */
166 FALSE), /* pcrel_offset */
167
168 /* 8 bit absolute */
169 HOWTO (R_ARM_ABS8, /* type */
170 0, /* rightshift */
171 0, /* size (0 = byte, 1 = short, 2 = long) */
172 8, /* bitsize */
173 FALSE, /* pc_relative */
174 0, /* bitpos */
175 complain_overflow_bitfield,/* complain_on_overflow */
176 bfd_elf_generic_reloc, /* special_function */
177 "R_ARM_ABS8", /* name */
178 FALSE, /* partial_inplace */
179 0x000000ff, /* src_mask */
180 0x000000ff, /* dst_mask */
181 FALSE), /* pcrel_offset */
182
183 HOWTO (R_ARM_SBREL32, /* type */
184 0, /* rightshift */
185 2, /* size (0 = byte, 1 = short, 2 = long) */
186 32, /* bitsize */
187 FALSE, /* pc_relative */
188 0, /* bitpos */
189 complain_overflow_dont,/* complain_on_overflow */
190 bfd_elf_generic_reloc, /* special_function */
191 "R_ARM_SBREL32", /* name */
192 FALSE, /* partial_inplace */
193 0xffffffff, /* src_mask */
194 0xffffffff, /* dst_mask */
195 FALSE), /* pcrel_offset */
196
197 HOWTO (R_ARM_THM_PC22, /* type */
198 1, /* rightshift */
199 2, /* size (0 = byte, 1 = short, 2 = long) */
200 23, /* bitsize */
201 TRUE, /* pc_relative */
202 0, /* bitpos */
203 complain_overflow_signed,/* complain_on_overflow */
204 bfd_elf_generic_reloc, /* special_function */
205 "R_ARM_THM_PC22", /* name */
206 FALSE, /* partial_inplace */
207 0x07ff07ff, /* src_mask */
208 0x07ff07ff, /* dst_mask */
209 TRUE), /* pcrel_offset */
210
211 HOWTO (R_ARM_THM_PC8, /* type */
212 1, /* rightshift */
213 1, /* size (0 = byte, 1 = short, 2 = long) */
214 8, /* bitsize */
215 TRUE, /* pc_relative */
216 0, /* bitpos */
217 complain_overflow_signed,/* complain_on_overflow */
218 bfd_elf_generic_reloc, /* special_function */
219 "R_ARM_THM_PC8", /* name */
220 FALSE, /* partial_inplace */
221 0x000000ff, /* src_mask */
222 0x000000ff, /* dst_mask */
223 TRUE), /* pcrel_offset */
224
225 HOWTO (R_ARM_AMP_VCALL9, /* type */
226 1, /* rightshift */
227 1, /* size (0 = byte, 1 = short, 2 = long) */
228 8, /* bitsize */
229 TRUE, /* pc_relative */
230 0, /* bitpos */
231 complain_overflow_signed,/* complain_on_overflow */
232 bfd_elf_generic_reloc, /* special_function */
233 "R_ARM_AMP_VCALL9", /* name */
234 FALSE, /* partial_inplace */
235 0x000000ff, /* src_mask */
236 0x000000ff, /* dst_mask */
237 TRUE), /* pcrel_offset */
238
239 HOWTO (R_ARM_SWI24, /* type */
240 0, /* rightshift */
241 0, /* size (0 = byte, 1 = short, 2 = long) */
242 0, /* bitsize */
243 FALSE, /* pc_relative */
244 0, /* bitpos */
245 complain_overflow_signed,/* complain_on_overflow */
246 bfd_elf_generic_reloc, /* special_function */
247 "R_ARM_SWI24", /* name */
248 FALSE, /* partial_inplace */
249 0x00000000, /* src_mask */
250 0x00000000, /* dst_mask */
251 FALSE), /* pcrel_offset */
252
253 HOWTO (R_ARM_THM_SWI8, /* type */
254 0, /* rightshift */
255 0, /* size (0 = byte, 1 = short, 2 = long) */
256 0, /* bitsize */
257 FALSE, /* pc_relative */
258 0, /* bitpos */
259 complain_overflow_signed,/* complain_on_overflow */
260 bfd_elf_generic_reloc, /* special_function */
261 "R_ARM_SWI8", /* name */
262 FALSE, /* partial_inplace */
263 0x00000000, /* src_mask */
264 0x00000000, /* dst_mask */
265 FALSE), /* pcrel_offset */
266
267 /* BLX instruction for the ARM. */
268 HOWTO (R_ARM_XPC25, /* type */
269 2, /* rightshift */
270 2, /* size (0 = byte, 1 = short, 2 = long) */
271 25, /* bitsize */
272 TRUE, /* pc_relative */
273 0, /* bitpos */
274 complain_overflow_signed,/* complain_on_overflow */
275 bfd_elf_generic_reloc, /* special_function */
276 "R_ARM_XPC25", /* name */
277 FALSE, /* partial_inplace */
278 0x00ffffff, /* src_mask */
279 0x00ffffff, /* dst_mask */
280 TRUE), /* pcrel_offset */
281
282 /* BLX instruction for the Thumb. */
283 HOWTO (R_ARM_THM_XPC22, /* type */
284 2, /* rightshift */
285 2, /* size (0 = byte, 1 = short, 2 = long) */
286 22, /* bitsize */
287 TRUE, /* pc_relative */
288 0, /* bitpos */
289 complain_overflow_signed,/* complain_on_overflow */
290 bfd_elf_generic_reloc, /* special_function */
291 "R_ARM_THM_XPC22", /* name */
292 FALSE, /* partial_inplace */
293 0x07ff07ff, /* src_mask */
294 0x07ff07ff, /* dst_mask */
295 TRUE), /* pcrel_offset */
296
297 /* These next three relocs are not defined, but we need to fill the space. */
298
299 HOWTO (R_ARM_NONE, /* type */
300 0, /* rightshift */
301 0, /* size (0 = byte, 1 = short, 2 = long) */
302 0, /* bitsize */
303 FALSE, /* pc_relative */
304 0, /* bitpos */
305 complain_overflow_dont,/* complain_on_overflow */
306 bfd_elf_generic_reloc, /* special_function */
307 "R_ARM_unknown_17", /* name */
308 FALSE, /* partial_inplace */
309 0, /* src_mask */
310 0, /* dst_mask */
311 FALSE), /* pcrel_offset */
312
313 HOWTO (R_ARM_NONE, /* type */
314 0, /* rightshift */
315 0, /* size (0 = byte, 1 = short, 2 = long) */
316 0, /* bitsize */
317 FALSE, /* pc_relative */
318 0, /* bitpos */
319 complain_overflow_dont,/* complain_on_overflow */
320 bfd_elf_generic_reloc, /* special_function */
321 "R_ARM_unknown_18", /* name */
322 FALSE, /* partial_inplace */
323 0, /* src_mask */
324 0, /* dst_mask */
325 FALSE), /* pcrel_offset */
326
327 HOWTO (R_ARM_NONE, /* type */
328 0, /* rightshift */
329 0, /* size (0 = byte, 1 = short, 2 = long) */
330 0, /* bitsize */
331 FALSE, /* pc_relative */
332 0, /* bitpos */
333 complain_overflow_dont,/* complain_on_overflow */
334 bfd_elf_generic_reloc, /* special_function */
335 "R_ARM_unknown_19", /* name */
336 FALSE, /* partial_inplace */
337 0, /* src_mask */
338 0, /* dst_mask */
339 FALSE), /* pcrel_offset */
340
341 /* Relocs used in ARM Linux */
342
343 HOWTO (R_ARM_COPY, /* type */
344 0, /* rightshift */
345 2, /* size (0 = byte, 1 = short, 2 = long) */
346 32, /* bitsize */
347 FALSE, /* pc_relative */
348 0, /* bitpos */
349 complain_overflow_bitfield,/* complain_on_overflow */
350 bfd_elf_generic_reloc, /* special_function */
351 "R_ARM_COPY", /* name */
352 TRUE, /* partial_inplace */
353 0xffffffff, /* src_mask */
354 0xffffffff, /* dst_mask */
355 FALSE), /* pcrel_offset */
356
357 HOWTO (R_ARM_GLOB_DAT, /* type */
358 0, /* rightshift */
359 2, /* size (0 = byte, 1 = short, 2 = long) */
360 32, /* bitsize */
361 FALSE, /* pc_relative */
362 0, /* bitpos */
363 complain_overflow_bitfield,/* complain_on_overflow */
364 bfd_elf_generic_reloc, /* special_function */
365 "R_ARM_GLOB_DAT", /* name */
366 TRUE, /* partial_inplace */
367 0xffffffff, /* src_mask */
368 0xffffffff, /* dst_mask */
369 FALSE), /* pcrel_offset */
370
371 HOWTO (R_ARM_JUMP_SLOT, /* type */
372 0, /* rightshift */
373 2, /* size (0 = byte, 1 = short, 2 = long) */
374 32, /* bitsize */
375 FALSE, /* pc_relative */
376 0, /* bitpos */
377 complain_overflow_bitfield,/* complain_on_overflow */
378 bfd_elf_generic_reloc, /* special_function */
379 "R_ARM_JUMP_SLOT", /* name */
380 TRUE, /* partial_inplace */
381 0xffffffff, /* src_mask */
382 0xffffffff, /* dst_mask */
383 FALSE), /* pcrel_offset */
384
385 HOWTO (R_ARM_RELATIVE, /* type */
386 0, /* rightshift */
387 2, /* size (0 = byte, 1 = short, 2 = long) */
388 32, /* bitsize */
389 FALSE, /* pc_relative */
390 0, /* bitpos */
391 complain_overflow_bitfield,/* complain_on_overflow */
392 bfd_elf_generic_reloc, /* special_function */
393 "R_ARM_RELATIVE", /* name */
394 TRUE, /* partial_inplace */
395 0xffffffff, /* src_mask */
396 0xffffffff, /* dst_mask */
397 FALSE), /* pcrel_offset */
398
399 HOWTO (R_ARM_GOTOFF, /* type */
400 0, /* rightshift */
401 2, /* size (0 = byte, 1 = short, 2 = long) */
402 32, /* bitsize */
403 FALSE, /* pc_relative */
404 0, /* bitpos */
405 complain_overflow_bitfield,/* complain_on_overflow */
406 bfd_elf_generic_reloc, /* special_function */
407 "R_ARM_GOTOFF", /* name */
408 TRUE, /* partial_inplace */
409 0xffffffff, /* src_mask */
410 0xffffffff, /* dst_mask */
411 FALSE), /* pcrel_offset */
412
413 HOWTO (R_ARM_GOTPC, /* type */
414 0, /* rightshift */
415 2, /* size (0 = byte, 1 = short, 2 = long) */
416 32, /* bitsize */
417 TRUE, /* pc_relative */
418 0, /* bitpos */
419 complain_overflow_bitfield,/* complain_on_overflow */
420 bfd_elf_generic_reloc, /* special_function */
421 "R_ARM_GOTPC", /* name */
422 TRUE, /* partial_inplace */
423 0xffffffff, /* src_mask */
424 0xffffffff, /* dst_mask */
425 TRUE), /* pcrel_offset */
426
427 HOWTO (R_ARM_GOT32, /* type */
428 0, /* rightshift */
429 2, /* size (0 = byte, 1 = short, 2 = long) */
430 32, /* bitsize */
431 FALSE, /* pc_relative */
432 0, /* bitpos */
433 complain_overflow_bitfield,/* complain_on_overflow */
434 bfd_elf_generic_reloc, /* special_function */
435 "R_ARM_GOT32", /* name */
436 TRUE, /* partial_inplace */
437 0xffffffff, /* src_mask */
438 0xffffffff, /* dst_mask */
439 FALSE), /* pcrel_offset */
440
441 HOWTO (R_ARM_PLT32, /* type */
442 2, /* rightshift */
443 2, /* size (0 = byte, 1 = short, 2 = long) */
444 26, /* bitsize */
445 TRUE, /* pc_relative */
446 0, /* bitpos */
447 complain_overflow_bitfield,/* complain_on_overflow */
448 bfd_elf_generic_reloc, /* special_function */
449 "R_ARM_PLT32", /* name */
450 TRUE, /* partial_inplace */
451 0x00ffffff, /* src_mask */
452 0x00ffffff, /* dst_mask */
453 TRUE), /* pcrel_offset */
454
455 HOWTO (R_ARM_CALL, /* type */
456 2, /* rightshift */
457 2, /* size (0 = byte, 1 = short, 2 = long) */
458 24, /* bitsize */
459 TRUE, /* pc_relative */
460 0, /* bitpos */
461 complain_overflow_signed,/* complain_on_overflow */
462 bfd_elf_generic_reloc, /* special_function */
463 "R_ARM_CALL", /* name */
464 FALSE, /* partial_inplace */
465 0x00ffffff, /* src_mask */
466 0x00ffffff, /* dst_mask */
467 TRUE), /* pcrel_offset */
468
469 HOWTO (R_ARM_JUMP24, /* type */
470 2, /* rightshift */
471 2, /* size (0 = byte, 1 = short, 2 = long) */
472 24, /* bitsize */
473 TRUE, /* pc_relative */
474 0, /* bitpos */
475 complain_overflow_signed,/* complain_on_overflow */
476 bfd_elf_generic_reloc, /* special_function */
477 "R_ARM_JUMP24", /* name */
478 FALSE, /* partial_inplace */
479 0x00ffffff, /* src_mask */
480 0x00ffffff, /* dst_mask */
481 TRUE), /* pcrel_offset */
482
483 HOWTO (R_ARM_NONE, /* type */
484 0, /* rightshift */
485 0, /* size (0 = byte, 1 = short, 2 = long) */
486 0, /* bitsize */
487 FALSE, /* pc_relative */
488 0, /* bitpos */
489 complain_overflow_dont,/* complain_on_overflow */
490 bfd_elf_generic_reloc, /* special_function */
491 "R_ARM_unknown_30", /* name */
492 FALSE, /* partial_inplace */
493 0, /* src_mask */
494 0, /* dst_mask */
495 FALSE), /* pcrel_offset */
496
497 HOWTO (R_ARM_NONE, /* type */
498 0, /* rightshift */
499 0, /* size (0 = byte, 1 = short, 2 = long) */
500 0, /* bitsize */
501 FALSE, /* pc_relative */
502 0, /* bitpos */
503 complain_overflow_dont,/* complain_on_overflow */
504 bfd_elf_generic_reloc, /* special_function */
505 "R_ARM_unknown_31", /* name */
506 FALSE, /* partial_inplace */
507 0, /* src_mask */
508 0, /* dst_mask */
509 FALSE), /* pcrel_offset */
510
511 HOWTO (R_ARM_ALU_PCREL7_0, /* type */
512 0, /* rightshift */
513 2, /* size (0 = byte, 1 = short, 2 = long) */
514 12, /* bitsize */
515 TRUE, /* pc_relative */
516 0, /* bitpos */
517 complain_overflow_dont,/* complain_on_overflow */
518 bfd_elf_generic_reloc, /* special_function */
519 "R_ARM_ALU_PCREL_7_0", /* name */
520 FALSE, /* partial_inplace */
521 0x00000fff, /* src_mask */
522 0x00000fff, /* dst_mask */
523 TRUE), /* pcrel_offset */
524
525 HOWTO (R_ARM_ALU_PCREL15_8, /* type */
526 0, /* rightshift */
527 2, /* size (0 = byte, 1 = short, 2 = long) */
528 12, /* bitsize */
529 TRUE, /* pc_relative */
530 8, /* bitpos */
531 complain_overflow_dont,/* complain_on_overflow */
532 bfd_elf_generic_reloc, /* special_function */
533 "R_ARM_ALU_PCREL_15_8",/* name */
534 FALSE, /* partial_inplace */
535 0x00000fff, /* src_mask */
536 0x00000fff, /* dst_mask */
537 TRUE), /* pcrel_offset */
538
539 HOWTO (R_ARM_ALU_PCREL23_15, /* type */
540 0, /* rightshift */
541 2, /* size (0 = byte, 1 = short, 2 = long) */
542 12, /* bitsize */
543 TRUE, /* pc_relative */
544 16, /* bitpos */
545 complain_overflow_dont,/* complain_on_overflow */
546 bfd_elf_generic_reloc, /* special_function */
547 "R_ARM_ALU_PCREL_23_15",/* name */
548 FALSE, /* partial_inplace */
549 0x00000fff, /* src_mask */
550 0x00000fff, /* dst_mask */
551 TRUE), /* pcrel_offset */
552
553 HOWTO (R_ARM_LDR_SBREL_11_0, /* type */
554 0, /* rightshift */
555 2, /* size (0 = byte, 1 = short, 2 = long) */
556 12, /* bitsize */
557 FALSE, /* pc_relative */
558 0, /* bitpos */
559 complain_overflow_dont,/* complain_on_overflow */
560 bfd_elf_generic_reloc, /* special_function */
561 "R_ARM_LDR_SBREL_11_0",/* name */
562 FALSE, /* partial_inplace */
563 0x00000fff, /* src_mask */
564 0x00000fff, /* dst_mask */
565 FALSE), /* pcrel_offset */
566
567 HOWTO (R_ARM_ALU_SBREL_19_12, /* type */
568 0, /* rightshift */
569 2, /* size (0 = byte, 1 = short, 2 = long) */
570 8, /* bitsize */
571 FALSE, /* pc_relative */
572 12, /* bitpos */
573 complain_overflow_dont,/* complain_on_overflow */
574 bfd_elf_generic_reloc, /* special_function */
575 "R_ARM_ALU_SBREL_19_12",/* name */
576 FALSE, /* partial_inplace */
577 0x000ff000, /* src_mask */
578 0x000ff000, /* dst_mask */
579 FALSE), /* pcrel_offset */
580
581 HOWTO (R_ARM_ALU_SBREL_27_20, /* type */
582 0, /* rightshift */
583 2, /* size (0 = byte, 1 = short, 2 = long) */
584 8, /* bitsize */
585 FALSE, /* pc_relative */
586 20, /* bitpos */
587 complain_overflow_dont,/* complain_on_overflow */
588 bfd_elf_generic_reloc, /* special_function */
589 "R_ARM_ALU_SBREL_27_20",/* name */
590 FALSE, /* partial_inplace */
591 0x0ff00000, /* src_mask */
592 0x0ff00000, /* dst_mask */
593 FALSE), /* pcrel_offset */
594
595 HOWTO (R_ARM_TARGET1, /* type */
596 0, /* rightshift */
597 2, /* size (0 = byte, 1 = short, 2 = long) */
598 32, /* bitsize */
599 FALSE, /* pc_relative */
600 0, /* bitpos */
601 complain_overflow_dont,/* complain_on_overflow */
602 bfd_elf_generic_reloc, /* special_function */
603 "R_ARM_TARGET1", /* name */
604 FALSE, /* partial_inplace */
605 0xffffffff, /* src_mask */
606 0xffffffff, /* dst_mask */
607 FALSE), /* pcrel_offset */
608
609 HOWTO (R_ARM_ROSEGREL32, /* type */
610 0, /* rightshift */
611 2, /* size (0 = byte, 1 = short, 2 = long) */
612 32, /* bitsize */
613 FALSE, /* pc_relative */
614 0, /* bitpos */
615 complain_overflow_dont,/* complain_on_overflow */
616 bfd_elf_generic_reloc, /* special_function */
617 "R_ARM_ROSEGREL32", /* name */
618 FALSE, /* partial_inplace */
619 0xffffffff, /* src_mask */
620 0xffffffff, /* dst_mask */
621 FALSE), /* pcrel_offset */
622
623 HOWTO (R_ARM_V4BX, /* type */
624 0, /* rightshift */
625 2, /* size (0 = byte, 1 = short, 2 = long) */
626 32, /* bitsize */
627 FALSE, /* pc_relative */
628 0, /* bitpos */
629 complain_overflow_dont,/* complain_on_overflow */
630 bfd_elf_generic_reloc, /* special_function */
631 "R_ARM_V4BX", /* name */
632 FALSE, /* partial_inplace */
633 0xffffffff, /* src_mask */
634 0xffffffff, /* dst_mask */
635 FALSE), /* pcrel_offset */
636
637 HOWTO (R_ARM_TARGET2, /* type */
638 0, /* rightshift */
639 2, /* size (0 = byte, 1 = short, 2 = long) */
640 32, /* bitsize */
641 FALSE, /* pc_relative */
642 0, /* bitpos */
643 complain_overflow_signed,/* complain_on_overflow */
644 bfd_elf_generic_reloc, /* special_function */
645 "R_ARM_TARGET2", /* name */
646 FALSE, /* partial_inplace */
647 0xffffffff, /* src_mask */
648 0xffffffff, /* dst_mask */
649 TRUE), /* pcrel_offset */
650
651 HOWTO (R_ARM_PREL31, /* type */
652 0, /* rightshift */
653 2, /* size (0 = byte, 1 = short, 2 = long) */
654 31, /* bitsize */
655 TRUE, /* pc_relative */
656 0, /* bitpos */
657 complain_overflow_signed,/* complain_on_overflow */
658 bfd_elf_generic_reloc, /* special_function */
659 "R_ARM_PREL31", /* name */
660 FALSE, /* partial_inplace */
661 0x7fffffff, /* src_mask */
662 0x7fffffff, /* dst_mask */
663 TRUE), /* pcrel_offset */
664 };
665
666 /* GNU extension to record C++ vtable hierarchy */
667 static reloc_howto_type elf32_arm_vtinherit_howto =
668 HOWTO (R_ARM_GNU_VTINHERIT, /* type */
669 0, /* rightshift */
670 2, /* size (0 = byte, 1 = short, 2 = long) */
671 0, /* bitsize */
672 FALSE, /* pc_relative */
673 0, /* bitpos */
674 complain_overflow_dont, /* complain_on_overflow */
675 NULL, /* special_function */
676 "R_ARM_GNU_VTINHERIT", /* name */
677 FALSE, /* partial_inplace */
678 0, /* src_mask */
679 0, /* dst_mask */
680 FALSE); /* pcrel_offset */
681
682 /* GNU extension to record C++ vtable member usage */
683 static reloc_howto_type elf32_arm_vtentry_howto =
684 HOWTO (R_ARM_GNU_VTENTRY, /* type */
685 0, /* rightshift */
686 2, /* size (0 = byte, 1 = short, 2 = long) */
687 0, /* bitsize */
688 FALSE, /* pc_relative */
689 0, /* bitpos */
690 complain_overflow_dont, /* complain_on_overflow */
691 _bfd_elf_rel_vtable_reloc_fn, /* special_function */
692 "R_ARM_GNU_VTENTRY", /* name */
693 FALSE, /* partial_inplace */
694 0, /* src_mask */
695 0, /* dst_mask */
696 FALSE); /* pcrel_offset */
697
698 /* 12 bit pc relative */
699 static reloc_howto_type elf32_arm_thm_pc11_howto =
700 HOWTO (R_ARM_THM_PC11, /* type */
701 1, /* rightshift */
702 1, /* size (0 = byte, 1 = short, 2 = long) */
703 11, /* bitsize */
704 TRUE, /* pc_relative */
705 0, /* bitpos */
706 complain_overflow_signed, /* complain_on_overflow */
707 bfd_elf_generic_reloc, /* special_function */
708 "R_ARM_THM_PC11", /* name */
709 FALSE, /* partial_inplace */
710 0x000007ff, /* src_mask */
711 0x000007ff, /* dst_mask */
712 TRUE); /* pcrel_offset */
713
714 /* 12 bit pc relative */
715 static reloc_howto_type elf32_arm_thm_pc9_howto =
716 HOWTO (R_ARM_THM_PC9, /* type */
717 1, /* rightshift */
718 1, /* size (0 = byte, 1 = short, 2 = long) */
719 8, /* bitsize */
720 TRUE, /* pc_relative */
721 0, /* bitpos */
722 complain_overflow_signed, /* complain_on_overflow */
723 bfd_elf_generic_reloc, /* special_function */
724 "R_ARM_THM_PC9", /* name */
725 FALSE, /* partial_inplace */
726 0x000000ff, /* src_mask */
727 0x000000ff, /* dst_mask */
728 TRUE); /* pcrel_offset */
729
730 /* Place relative GOT-indirect. */
731 static reloc_howto_type elf32_arm_got_prel =
732 HOWTO (R_ARM_GOT_PREL, /* type */
733 0, /* rightshift */
734 2, /* size (0 = byte, 1 = short, 2 = long) */
735 32, /* bitsize */
736 TRUE, /* pc_relative */
737 0, /* bitpos */
738 complain_overflow_dont, /* complain_on_overflow */
739 bfd_elf_generic_reloc, /* special_function */
740 "R_ARM_GOT_PREL", /* name */
741 FALSE, /* partial_inplace */
742 0xffffffff, /* src_mask */
743 0xffffffff, /* dst_mask */
744 TRUE); /* pcrel_offset */
745
746 /* Currently unused relocations. */
747 static reloc_howto_type elf32_arm_r_howto[4] =
748 {
749 HOWTO (R_ARM_RREL32, /* type */
750 0, /* rightshift */
751 0, /* size (0 = byte, 1 = short, 2 = long) */
752 0, /* bitsize */
753 FALSE, /* pc_relative */
754 0, /* bitpos */
755 complain_overflow_dont,/* complain_on_overflow */
756 bfd_elf_generic_reloc, /* special_function */
757 "R_ARM_RREL32", /* name */
758 FALSE, /* partial_inplace */
759 0, /* src_mask */
760 0, /* dst_mask */
761 FALSE), /* pcrel_offset */
762
763 HOWTO (R_ARM_RABS32, /* type */
764 0, /* rightshift */
765 0, /* size (0 = byte, 1 = short, 2 = long) */
766 0, /* bitsize */
767 FALSE, /* pc_relative */
768 0, /* bitpos */
769 complain_overflow_dont,/* complain_on_overflow */
770 bfd_elf_generic_reloc, /* special_function */
771 "R_ARM_RABS32", /* name */
772 FALSE, /* partial_inplace */
773 0, /* src_mask */
774 0, /* dst_mask */
775 FALSE), /* pcrel_offset */
776
777 HOWTO (R_ARM_RPC24, /* type */
778 0, /* rightshift */
779 0, /* size (0 = byte, 1 = short, 2 = long) */
780 0, /* bitsize */
781 FALSE, /* pc_relative */
782 0, /* bitpos */
783 complain_overflow_dont,/* complain_on_overflow */
784 bfd_elf_generic_reloc, /* special_function */
785 "R_ARM_RPC24", /* name */
786 FALSE, /* partial_inplace */
787 0, /* src_mask */
788 0, /* dst_mask */
789 FALSE), /* pcrel_offset */
790
791 HOWTO (R_ARM_RBASE, /* type */
792 0, /* rightshift */
793 0, /* size (0 = byte, 1 = short, 2 = long) */
794 0, /* bitsize */
795 FALSE, /* pc_relative */
796 0, /* bitpos */
797 complain_overflow_dont,/* complain_on_overflow */
798 bfd_elf_generic_reloc, /* special_function */
799 "R_ARM_RBASE", /* name */
800 FALSE, /* partial_inplace */
801 0, /* src_mask */
802 0, /* dst_mask */
803 FALSE) /* pcrel_offset */
804 };
805
806 static reloc_howto_type *
807 elf32_arm_howto_from_type (unsigned int r_type)
808 {
809 if (r_type < NUM_ELEM (elf32_arm_howto_table))
810 return &elf32_arm_howto_table[r_type];
811
812 switch (r_type)
813 {
814 case R_ARM_GOT_PREL:
815 return &elf32_arm_got_prel;
816
817 case R_ARM_GNU_VTINHERIT:
818 return &elf32_arm_vtinherit_howto;
819
820 case R_ARM_GNU_VTENTRY:
821 return &elf32_arm_vtentry_howto;
822
823 case R_ARM_THM_PC11:
824 return &elf32_arm_thm_pc11_howto;
825
826 case R_ARM_THM_PC9:
827 return &elf32_arm_thm_pc9_howto;
828
829 case R_ARM_RREL32:
830 case R_ARM_RABS32:
831 case R_ARM_RPC24:
832 case R_ARM_RBASE:
833 return &elf32_arm_r_howto[r_type - R_ARM_RREL32];
834
835 default:
836 return NULL;
837 }
838 }
839
840 static void
841 elf32_arm_info_to_howto (bfd * abfd ATTRIBUTE_UNUSED, arelent * bfd_reloc,
842 Elf_Internal_Rela * elf_reloc)
843 {
844 unsigned int r_type;
845
846 r_type = ELF32_R_TYPE (elf_reloc->r_info);
847 bfd_reloc->howto = elf32_arm_howto_from_type (r_type);
848 }
849
850 struct elf32_arm_reloc_map
851 {
852 bfd_reloc_code_real_type bfd_reloc_val;
853 unsigned char elf_reloc_val;
854 };
855
856 /* All entries in this list must also be present in elf32_arm_howto_table. */
857 static const struct elf32_arm_reloc_map elf32_arm_reloc_map[] =
858 {
859 {BFD_RELOC_NONE, R_ARM_NONE},
860 {BFD_RELOC_ARM_PCREL_BRANCH, R_ARM_PC24},
861 {BFD_RELOC_ARM_PCREL_BLX, R_ARM_XPC25},
862 {BFD_RELOC_THUMB_PCREL_BLX, R_ARM_THM_XPC22},
863 {BFD_RELOC_32, R_ARM_ABS32},
864 {BFD_RELOC_32_PCREL, R_ARM_REL32},
865 {BFD_RELOC_8, R_ARM_ABS8},
866 {BFD_RELOC_16, R_ARM_ABS16},
867 {BFD_RELOC_ARM_OFFSET_IMM, R_ARM_ABS12},
868 {BFD_RELOC_ARM_THUMB_OFFSET, R_ARM_THM_ABS5},
869 {BFD_RELOC_THUMB_PCREL_BRANCH23, R_ARM_THM_PC22},
870 {BFD_RELOC_ARM_COPY, R_ARM_COPY},
871 {BFD_RELOC_ARM_GLOB_DAT, R_ARM_GLOB_DAT},
872 {BFD_RELOC_ARM_JUMP_SLOT, R_ARM_JUMP_SLOT},
873 {BFD_RELOC_ARM_RELATIVE, R_ARM_RELATIVE},
874 {BFD_RELOC_ARM_GOTOFF, R_ARM_GOTOFF},
875 {BFD_RELOC_ARM_GOTPC, R_ARM_GOTPC},
876 {BFD_RELOC_ARM_GOT32, R_ARM_GOT32},
877 {BFD_RELOC_ARM_PLT32, R_ARM_PLT32},
878 {BFD_RELOC_ARM_TARGET1, R_ARM_TARGET1},
879 {BFD_RELOC_ARM_ROSEGREL32, R_ARM_ROSEGREL32},
880 {BFD_RELOC_ARM_SBREL32, R_ARM_SBREL32},
881 {BFD_RELOC_ARM_PREL31, R_ARM_PREL31},
882 {BFD_RELOC_ARM_TARGET2, R_ARM_TARGET2}
883 };
884
885 static reloc_howto_type *
886 elf32_arm_reloc_type_lookup (abfd, code)
887 bfd *abfd ATTRIBUTE_UNUSED;
888 bfd_reloc_code_real_type code;
889 {
890 unsigned int i;
891
892 switch (code)
893 {
894 case BFD_RELOC_VTABLE_INHERIT:
895 return & elf32_arm_vtinherit_howto;
896
897 case BFD_RELOC_VTABLE_ENTRY:
898 return & elf32_arm_vtentry_howto;
899
900 case BFD_RELOC_THUMB_PCREL_BRANCH12:
901 return & elf32_arm_thm_pc11_howto;
902
903 case BFD_RELOC_THUMB_PCREL_BRANCH9:
904 return & elf32_arm_thm_pc9_howto;
905
906 default:
907 for (i = 0; i < NUM_ELEM (elf32_arm_reloc_map); i ++)
908 if (elf32_arm_reloc_map[i].bfd_reloc_val == code)
909 return & elf32_arm_howto_table[elf32_arm_reloc_map[i].elf_reloc_val];
910
911 return NULL;
912 }
913 }
914
915 /* Support for core dump NOTE sections */
916 static bfd_boolean
917 elf32_arm_nabi_grok_prstatus (abfd, note)
918 bfd *abfd;
919 Elf_Internal_Note *note;
920 {
921 int offset;
922 size_t size;
923
924 switch (note->descsz)
925 {
926 default:
927 return FALSE;
928
929 case 148: /* Linux/ARM 32-bit*/
930 /* pr_cursig */
931 elf_tdata (abfd)->core_signal = bfd_get_16 (abfd, note->descdata + 12);
932
933 /* pr_pid */
934 elf_tdata (abfd)->core_pid = bfd_get_32 (abfd, note->descdata + 24);
935
936 /* pr_reg */
937 offset = 72;
938 size = 72;
939
940 break;
941 }
942
943 /* Make a ".reg/999" section. */
944 return _bfd_elfcore_make_pseudosection (abfd, ".reg",
945 size, note->descpos + offset);
946 }
947
948 static bfd_boolean
949 elf32_arm_nabi_grok_psinfo (abfd, note)
950 bfd *abfd;
951 Elf_Internal_Note *note;
952 {
953 switch (note->descsz)
954 {
955 default:
956 return FALSE;
957
958 case 124: /* Linux/ARM elf_prpsinfo */
959 elf_tdata (abfd)->core_program
960 = _bfd_elfcore_strndup (abfd, note->descdata + 28, 16);
961 elf_tdata (abfd)->core_command
962 = _bfd_elfcore_strndup (abfd, note->descdata + 44, 80);
963 }
964
965 /* Note that for some reason, a spurious space is tacked
966 onto the end of the args in some (at least one anyway)
967 implementations, so strip it off if it exists. */
968
969 {
970 char *command = elf_tdata (abfd)->core_command;
971 int n = strlen (command);
972
973 if (0 < n && command[n - 1] == ' ')
974 command[n - 1] = '\0';
975 }
976
977 return TRUE;
978 }
979
980 #define TARGET_LITTLE_SYM bfd_elf32_littlearm_vec
981 #define TARGET_LITTLE_NAME "elf32-littlearm"
982 #define TARGET_BIG_SYM bfd_elf32_bigarm_vec
983 #define TARGET_BIG_NAME "elf32-bigarm"
984
985 #define elf_backend_grok_prstatus elf32_arm_nabi_grok_prstatus
986 #define elf_backend_grok_psinfo elf32_arm_nabi_grok_psinfo
987
988 typedef unsigned long int insn32;
989 typedef unsigned short int insn16;
990
991 /* In lieu of proper flags, assume all EABIv4 objects are interworkable. */
992 #define INTERWORK_FLAG(abfd) \
993 (EF_ARM_EABI_VERSION (elf_elfheader (abfd)->e_flags) == EF_ARM_EABI_VER4 \
994 || (elf_elfheader (abfd)->e_flags & EF_ARM_INTERWORK))
995
996 /* The linker script knows the section names for placement.
997 The entry_names are used to do simple name mangling on the stubs.
998 Given a function name, and its type, the stub can be found. The
999 name can be changed. The only requirement is the %s be present. */
1000 #define THUMB2ARM_GLUE_SECTION_NAME ".glue_7t"
1001 #define THUMB2ARM_GLUE_ENTRY_NAME "__%s_from_thumb"
1002
1003 #define ARM2THUMB_GLUE_SECTION_NAME ".glue_7"
1004 #define ARM2THUMB_GLUE_ENTRY_NAME "__%s_from_arm"
1005
1006 /* The name of the dynamic interpreter. This is put in the .interp
1007 section. */
1008 #define ELF_DYNAMIC_INTERPRETER "/usr/lib/ld.so.1"
1009
1010 #ifdef FOUR_WORD_PLT
1011
1012 /* The first entry in a procedure linkage table looks like
1013 this. It is set up so that any shared library function that is
1014 called before the relocation has been set up calls the dynamic
1015 linker first. */
1016 static const bfd_vma elf32_arm_plt0_entry [] =
1017 {
1018 0xe52de004, /* str lr, [sp, #-4]! */
1019 0xe59fe010, /* ldr lr, [pc, #16] */
1020 0xe08fe00e, /* add lr, pc, lr */
1021 0xe5bef008, /* ldr pc, [lr, #8]! */
1022 };
1023
1024 /* Subsequent entries in a procedure linkage table look like
1025 this. */
1026 static const bfd_vma elf32_arm_plt_entry [] =
1027 {
1028 0xe28fc600, /* add ip, pc, #NN */
1029 0xe28cca00, /* add ip, ip, #NN */
1030 0xe5bcf000, /* ldr pc, [ip, #NN]! */
1031 0x00000000, /* unused */
1032 };
1033
1034 #else
1035
1036 /* The first entry in a procedure linkage table looks like
1037 this. It is set up so that any shared library function that is
1038 called before the relocation has been set up calls the dynamic
1039 linker first. */
1040 static const bfd_vma elf32_arm_plt0_entry [] =
1041 {
1042 0xe52de004, /* str lr, [sp, #-4]! */
1043 0xe59fe004, /* ldr lr, [pc, #4] */
1044 0xe08fe00e, /* add lr, pc, lr */
1045 0xe5bef008, /* ldr pc, [lr, #8]! */
1046 0x00000000, /* &GOT[0] - . */
1047 };
1048
1049 /* Subsequent entries in a procedure linkage table look like
1050 this. */
1051 static const bfd_vma elf32_arm_plt_entry [] =
1052 {
1053 0xe28fc600, /* add ip, pc, #0xNN00000 */
1054 0xe28cca00, /* add ip, ip, #0xNN000 */
1055 0xe5bcf000, /* ldr pc, [ip, #0xNNN]! */
1056 };
1057
1058 #endif
1059
1060 /* An initial stub used if the PLT entry is referenced from Thumb code. */
1061 #define PLT_THUMB_STUB_SIZE 4
1062 static const bfd_vma elf32_arm_plt_thumb_stub [] =
1063 {
1064 0x4778, /* bx pc */
1065 0x46c0 /* nop */
1066 };
1067
1068 /* The entries in a PLT when using a DLL-based target with multiple
1069 address spaces. */
1070 static const bfd_vma elf32_arm_symbian_plt_entry [] =
1071 {
1072 0xe51ff004, /* ldr pc, [pc, #-4] */
1073 0x00000000, /* dcd R_ARM_GLOB_DAT(X) */
1074 };
1075
1076 /* Used to build a map of a section. This is required for mixed-endian
1077 code/data. */
1078
1079 typedef struct elf32_elf_section_map
1080 {
1081 bfd_vma vma;
1082 char type;
1083 }
1084 elf32_arm_section_map;
1085
1086 struct _arm_elf_section_data
1087 {
1088 struct bfd_elf_section_data elf;
1089 int mapcount;
1090 elf32_arm_section_map *map;
1091 };
1092
1093 #define elf32_arm_section_data(sec) \
1094 ((struct _arm_elf_section_data *) elf_section_data (sec))
1095
1096 /* The ARM linker needs to keep track of the number of relocs that it
1097 decides to copy in check_relocs for each symbol. This is so that
1098 it can discard PC relative relocs if it doesn't need them when
1099 linking with -Bsymbolic. We store the information in a field
1100 extending the regular ELF linker hash table. */
1101
1102 /* This structure keeps track of the number of PC relative relocs we
1103 have copied for a given symbol. */
1104 struct elf32_arm_relocs_copied
1105 {
1106 /* Next section. */
1107 struct elf32_arm_relocs_copied * next;
1108 /* A section in dynobj. */
1109 asection * section;
1110 /* Number of relocs copied in this section. */
1111 bfd_size_type count;
1112 };
1113
1114 /* Arm ELF linker hash entry. */
1115 struct elf32_arm_link_hash_entry
1116 {
1117 struct elf_link_hash_entry root;
1118
1119 /* Number of PC relative relocs copied for this symbol. */
1120 struct elf32_arm_relocs_copied * relocs_copied;
1121
1122 /* We reference count Thumb references to a PLT entry separately,
1123 so that we can emit the Thumb trampoline only if needed. */
1124 bfd_signed_vma plt_thumb_refcount;
1125
1126 /* Since PLT entries have variable size if the Thumb prologue is
1127 used, we need to record the index into .got.plt instead of
1128 recomputing it from the PLT offset. */
1129 bfd_signed_vma plt_got_offset;
1130 };
1131
1132 /* Traverse an arm ELF linker hash table. */
1133 #define elf32_arm_link_hash_traverse(table, func, info) \
1134 (elf_link_hash_traverse \
1135 (&(table)->root, \
1136 (bfd_boolean (*) (struct elf_link_hash_entry *, void *)) (func), \
1137 (info)))
1138
1139 /* Get the ARM elf linker hash table from a link_info structure. */
1140 #define elf32_arm_hash_table(info) \
1141 ((struct elf32_arm_link_hash_table *) ((info)->hash))
1142
1143 /* ARM ELF linker hash table. */
1144 struct elf32_arm_link_hash_table
1145 {
1146 /* The main hash table. */
1147 struct elf_link_hash_table root;
1148
1149 /* The size in bytes of the section containing the Thumb-to-ARM glue. */
1150 bfd_size_type thumb_glue_size;
1151
1152 /* The size in bytes of the section containing the ARM-to-Thumb glue. */
1153 bfd_size_type arm_glue_size;
1154
1155 /* An arbitrary input BFD chosen to hold the glue sections. */
1156 bfd * bfd_of_glue_owner;
1157
1158 /* Nonzero to output a BE8 image. */
1159 int byteswap_code;
1160
1161 /* Zero if R_ARM_TARGET1 means R_ARM_ABS32.
1162 Nonzero if R_ARM_TARGET1 means R_ARM_ABS32. */
1163 int target1_is_rel;
1164
1165 /* The relocation to use for R_ARM_TARGET2 relocations. */
1166 int target2_reloc;
1167
1168 /* Nonzero to fix BX instructions for ARMv4 targets. */
1169 int fix_v4bx;
1170
1171 /* The number of bytes in the initial entry in the PLT. */
1172 bfd_size_type plt_header_size;
1173
1174 /* The number of bytes in the subsequent PLT etries. */
1175 bfd_size_type plt_entry_size;
1176
1177 /* True if the target system is Symbian OS. */
1178 int symbian_p;
1179
1180 /* True if the target uses REL relocations. */
1181 int use_rel;
1182
1183 /* Short-cuts to get to dynamic linker sections. */
1184 asection *sgot;
1185 asection *sgotplt;
1186 asection *srelgot;
1187 asection *splt;
1188 asection *srelplt;
1189 asection *sdynbss;
1190 asection *srelbss;
1191
1192 /* Small local sym to section mapping cache. */
1193 struct sym_sec_cache sym_sec;
1194
1195 /* For convenience in allocate_dynrelocs. */
1196 bfd * obfd;
1197 };
1198
1199 /* Create an entry in an ARM ELF linker hash table. */
1200
1201 static struct bfd_hash_entry *
1202 elf32_arm_link_hash_newfunc (struct bfd_hash_entry * entry,
1203 struct bfd_hash_table * table,
1204 const char * string)
1205 {
1206 struct elf32_arm_link_hash_entry * ret =
1207 (struct elf32_arm_link_hash_entry *) entry;
1208
1209 /* Allocate the structure if it has not already been allocated by a
1210 subclass. */
1211 if (ret == (struct elf32_arm_link_hash_entry *) NULL)
1212 ret = bfd_hash_allocate (table, sizeof (struct elf32_arm_link_hash_entry));
1213 if (ret == NULL)
1214 return (struct bfd_hash_entry *) ret;
1215
1216 /* Call the allocation method of the superclass. */
1217 ret = ((struct elf32_arm_link_hash_entry *)
1218 _bfd_elf_link_hash_newfunc ((struct bfd_hash_entry *) ret,
1219 table, string));
1220 if (ret != NULL)
1221 {
1222 ret->relocs_copied = NULL;
1223 ret->plt_thumb_refcount = 0;
1224 ret->plt_got_offset = -1;
1225 }
1226
1227 return (struct bfd_hash_entry *) ret;
1228 }
1229
1230 /* Create .got, .gotplt, and .rel.got sections in DYNOBJ, and set up
1231 shortcuts to them in our hash table. */
1232
1233 static bfd_boolean
1234 create_got_section (bfd *dynobj, struct bfd_link_info *info)
1235 {
1236 struct elf32_arm_link_hash_table *htab;
1237
1238 htab = elf32_arm_hash_table (info);
1239 /* BPABI objects never have a GOT, or associated sections. */
1240 if (htab->symbian_p)
1241 return TRUE;
1242
1243 if (! _bfd_elf_create_got_section (dynobj, info))
1244 return FALSE;
1245
1246 htab->sgot = bfd_get_section_by_name (dynobj, ".got");
1247 htab->sgotplt = bfd_get_section_by_name (dynobj, ".got.plt");
1248 if (!htab->sgot || !htab->sgotplt)
1249 abort ();
1250
1251 htab->srelgot = bfd_make_section (dynobj, ".rel.got");
1252 if (htab->srelgot == NULL
1253 || ! bfd_set_section_flags (dynobj, htab->srelgot,
1254 (SEC_ALLOC | SEC_LOAD | SEC_HAS_CONTENTS
1255 | SEC_IN_MEMORY | SEC_LINKER_CREATED
1256 | SEC_READONLY))
1257 || ! bfd_set_section_alignment (dynobj, htab->srelgot, 2))
1258 return FALSE;
1259 return TRUE;
1260 }
1261
1262 /* Create .plt, .rel.plt, .got, .got.plt, .rel.got, .dynbss, and
1263 .rel.bss sections in DYNOBJ, and set up shortcuts to them in our
1264 hash table. */
1265
1266 static bfd_boolean
1267 elf32_arm_create_dynamic_sections (bfd *dynobj, struct bfd_link_info *info)
1268 {
1269 struct elf32_arm_link_hash_table *htab;
1270
1271 htab = elf32_arm_hash_table (info);
1272 if (!htab->sgot && !create_got_section (dynobj, info))
1273 return FALSE;
1274
1275 if (!_bfd_elf_create_dynamic_sections (dynobj, info))
1276 return FALSE;
1277
1278 htab->splt = bfd_get_section_by_name (dynobj, ".plt");
1279 htab->srelplt = bfd_get_section_by_name (dynobj, ".rel.plt");
1280 htab->sdynbss = bfd_get_section_by_name (dynobj, ".dynbss");
1281 if (!info->shared)
1282 htab->srelbss = bfd_get_section_by_name (dynobj, ".rel.bss");
1283
1284 if (!htab->splt
1285 || !htab->srelplt
1286 || !htab->sdynbss
1287 || (!info->shared && !htab->srelbss))
1288 abort ();
1289
1290 return TRUE;
1291 }
1292
1293 /* Copy the extra info we tack onto an elf_link_hash_entry. */
1294
1295 static void
1296 elf32_arm_copy_indirect_symbol (const struct elf_backend_data *bed,
1297 struct elf_link_hash_entry *dir,
1298 struct elf_link_hash_entry *ind)
1299 {
1300 struct elf32_arm_link_hash_entry *edir, *eind;
1301
1302 edir = (struct elf32_arm_link_hash_entry *) dir;
1303 eind = (struct elf32_arm_link_hash_entry *) ind;
1304
1305 if (eind->relocs_copied != NULL)
1306 {
1307 if (edir->relocs_copied != NULL)
1308 {
1309 struct elf32_arm_relocs_copied **pp;
1310 struct elf32_arm_relocs_copied *p;
1311
1312 if (ind->root.type == bfd_link_hash_indirect)
1313 abort ();
1314
1315 /* Add reloc counts against the weak sym to the strong sym
1316 list. Merge any entries against the same section. */
1317 for (pp = &eind->relocs_copied; (p = *pp) != NULL; )
1318 {
1319 struct elf32_arm_relocs_copied *q;
1320
1321 for (q = edir->relocs_copied; q != NULL; q = q->next)
1322 if (q->section == p->section)
1323 {
1324 q->count += p->count;
1325 *pp = p->next;
1326 break;
1327 }
1328 if (q == NULL)
1329 pp = &p->next;
1330 }
1331 *pp = edir->relocs_copied;
1332 }
1333
1334 edir->relocs_copied = eind->relocs_copied;
1335 eind->relocs_copied = NULL;
1336 }
1337
1338 /* If the direct symbol already has an associated PLT entry, the
1339 indirect symbol should not. If it doesn't, swap refcount information
1340 from the indirect symbol. */
1341 if (edir->plt_thumb_refcount == 0)
1342 {
1343 edir->plt_thumb_refcount = eind->plt_thumb_refcount;
1344 eind->plt_thumb_refcount = 0;
1345 }
1346 else
1347 BFD_ASSERT (eind->plt_thumb_refcount == 0);
1348
1349 _bfd_elf_link_hash_copy_indirect (bed, dir, ind);
1350 }
1351
1352 /* Create an ARM elf linker hash table. */
1353
1354 static struct bfd_link_hash_table *
1355 elf32_arm_link_hash_table_create (bfd *abfd)
1356 {
1357 struct elf32_arm_link_hash_table *ret;
1358 bfd_size_type amt = sizeof (struct elf32_arm_link_hash_table);
1359
1360 ret = bfd_malloc (amt);
1361 if (ret == NULL)
1362 return NULL;
1363
1364 if (!_bfd_elf_link_hash_table_init (& ret->root, abfd,
1365 elf32_arm_link_hash_newfunc))
1366 {
1367 free (ret);
1368 return NULL;
1369 }
1370
1371 ret->sgot = NULL;
1372 ret->sgotplt = NULL;
1373 ret->srelgot = NULL;
1374 ret->splt = NULL;
1375 ret->srelplt = NULL;
1376 ret->sdynbss = NULL;
1377 ret->srelbss = NULL;
1378 ret->thumb_glue_size = 0;
1379 ret->arm_glue_size = 0;
1380 ret->bfd_of_glue_owner = NULL;
1381 ret->byteswap_code = 0;
1382 ret->target1_is_rel = 0;
1383 ret->target2_reloc = R_ARM_NONE;
1384 #ifdef FOUR_WORD_PLT
1385 ret->plt_header_size = 16;
1386 ret->plt_entry_size = 16;
1387 #else
1388 ret->plt_header_size = 20;
1389 ret->plt_entry_size = 12;
1390 #endif
1391 ret->symbian_p = 0;
1392 ret->use_rel = 1;
1393 ret->sym_sec.abfd = NULL;
1394 ret->obfd = abfd;
1395
1396 return &ret->root.root;
1397 }
1398
1399 /* Locate the Thumb encoded calling stub for NAME. */
1400
1401 static struct elf_link_hash_entry *
1402 find_thumb_glue (struct bfd_link_info *link_info,
1403 const char *name,
1404 bfd *input_bfd)
1405 {
1406 char *tmp_name;
1407 struct elf_link_hash_entry *hash;
1408 struct elf32_arm_link_hash_table *hash_table;
1409
1410 /* We need a pointer to the armelf specific hash table. */
1411 hash_table = elf32_arm_hash_table (link_info);
1412
1413 tmp_name = bfd_malloc ((bfd_size_type) strlen (name)
1414 + strlen (THUMB2ARM_GLUE_ENTRY_NAME) + 1);
1415
1416 BFD_ASSERT (tmp_name);
1417
1418 sprintf (tmp_name, THUMB2ARM_GLUE_ENTRY_NAME, name);
1419
1420 hash = elf_link_hash_lookup
1421 (&(hash_table)->root, tmp_name, FALSE, FALSE, TRUE);
1422
1423 if (hash == NULL)
1424 /* xgettext:c-format */
1425 (*_bfd_error_handler) (_("%B: unable to find THUMB glue '%s' for `%s'"),
1426 input_bfd, tmp_name, name);
1427
1428 free (tmp_name);
1429
1430 return hash;
1431 }
1432
1433 /* Locate the ARM encoded calling stub for NAME. */
1434
1435 static struct elf_link_hash_entry *
1436 find_arm_glue (struct bfd_link_info *link_info,
1437 const char *name,
1438 bfd *input_bfd)
1439 {
1440 char *tmp_name;
1441 struct elf_link_hash_entry *myh;
1442 struct elf32_arm_link_hash_table *hash_table;
1443
1444 /* We need a pointer to the elfarm specific hash table. */
1445 hash_table = elf32_arm_hash_table (link_info);
1446
1447 tmp_name = bfd_malloc ((bfd_size_type) strlen (name)
1448 + strlen (ARM2THUMB_GLUE_ENTRY_NAME) + 1);
1449
1450 BFD_ASSERT (tmp_name);
1451
1452 sprintf (tmp_name, ARM2THUMB_GLUE_ENTRY_NAME, name);
1453
1454 myh = elf_link_hash_lookup
1455 (&(hash_table)->root, tmp_name, FALSE, FALSE, TRUE);
1456
1457 if (myh == NULL)
1458 /* xgettext:c-format */
1459 (*_bfd_error_handler) (_("%B: unable to find ARM glue '%s' for `%s'"),
1460 input_bfd, tmp_name, name);
1461
1462 free (tmp_name);
1463
1464 return myh;
1465 }
1466
1467 /* ARM->Thumb glue:
1468
1469 .arm
1470 __func_from_arm:
1471 ldr r12, __func_addr
1472 bx r12
1473 __func_addr:
1474 .word func @ behave as if you saw a ARM_32 reloc. */
1475
1476 #define ARM2THUMB_GLUE_SIZE 12
1477 static const insn32 a2t1_ldr_insn = 0xe59fc000;
1478 static const insn32 a2t2_bx_r12_insn = 0xe12fff1c;
1479 static const insn32 a2t3_func_addr_insn = 0x00000001;
1480
1481 /* Thumb->ARM: Thumb->(non-interworking aware) ARM
1482
1483 .thumb .thumb
1484 .align 2 .align 2
1485 __func_from_thumb: __func_from_thumb:
1486 bx pc push {r6, lr}
1487 nop ldr r6, __func_addr
1488 .arm mov lr, pc
1489 __func_change_to_arm: bx r6
1490 b func .arm
1491 __func_back_to_thumb:
1492 ldmia r13! {r6, lr}
1493 bx lr
1494 __func_addr:
1495 .word func */
1496
1497 #define THUMB2ARM_GLUE_SIZE 8
1498 static const insn16 t2a1_bx_pc_insn = 0x4778;
1499 static const insn16 t2a2_noop_insn = 0x46c0;
1500 static const insn32 t2a3_b_insn = 0xea000000;
1501
1502 #ifndef ELFARM_NABI_C_INCLUDED
1503 bfd_boolean
1504 bfd_elf32_arm_allocate_interworking_sections (struct bfd_link_info * info)
1505 {
1506 asection * s;
1507 bfd_byte * foo;
1508 struct elf32_arm_link_hash_table * globals;
1509
1510 globals = elf32_arm_hash_table (info);
1511
1512 BFD_ASSERT (globals != NULL);
1513
1514 if (globals->arm_glue_size != 0)
1515 {
1516 BFD_ASSERT (globals->bfd_of_glue_owner != NULL);
1517
1518 s = bfd_get_section_by_name (globals->bfd_of_glue_owner,
1519 ARM2THUMB_GLUE_SECTION_NAME);
1520
1521 BFD_ASSERT (s != NULL);
1522
1523 foo = bfd_alloc (globals->bfd_of_glue_owner, globals->arm_glue_size);
1524
1525 s->size = globals->arm_glue_size;
1526 s->contents = foo;
1527 }
1528
1529 if (globals->thumb_glue_size != 0)
1530 {
1531 BFD_ASSERT (globals->bfd_of_glue_owner != NULL);
1532
1533 s = bfd_get_section_by_name
1534 (globals->bfd_of_glue_owner, THUMB2ARM_GLUE_SECTION_NAME);
1535
1536 BFD_ASSERT (s != NULL);
1537
1538 foo = bfd_alloc (globals->bfd_of_glue_owner, globals->thumb_glue_size);
1539
1540 s->size = globals->thumb_glue_size;
1541 s->contents = foo;
1542 }
1543
1544 return TRUE;
1545 }
1546
1547 static void
1548 record_arm_to_thumb_glue (struct bfd_link_info * link_info,
1549 struct elf_link_hash_entry * h)
1550 {
1551 const char * name = h->root.root.string;
1552 asection * s;
1553 char * tmp_name;
1554 struct elf_link_hash_entry * myh;
1555 struct bfd_link_hash_entry * bh;
1556 struct elf32_arm_link_hash_table * globals;
1557 bfd_vma val;
1558
1559 globals = elf32_arm_hash_table (link_info);
1560
1561 BFD_ASSERT (globals != NULL);
1562 BFD_ASSERT (globals->bfd_of_glue_owner != NULL);
1563
1564 s = bfd_get_section_by_name
1565 (globals->bfd_of_glue_owner, ARM2THUMB_GLUE_SECTION_NAME);
1566
1567 BFD_ASSERT (s != NULL);
1568
1569 tmp_name = bfd_malloc ((bfd_size_type) strlen (name) + strlen (ARM2THUMB_GLUE_ENTRY_NAME) + 1);
1570
1571 BFD_ASSERT (tmp_name);
1572
1573 sprintf (tmp_name, ARM2THUMB_GLUE_ENTRY_NAME, name);
1574
1575 myh = elf_link_hash_lookup
1576 (&(globals)->root, tmp_name, FALSE, FALSE, TRUE);
1577
1578 if (myh != NULL)
1579 {
1580 /* We've already seen this guy. */
1581 free (tmp_name);
1582 return;
1583 }
1584
1585 /* The only trick here is using hash_table->arm_glue_size as the value.
1586 Even though the section isn't allocated yet, this is where we will be
1587 putting it. */
1588 bh = NULL;
1589 val = globals->arm_glue_size + 1;
1590 _bfd_generic_link_add_one_symbol (link_info, globals->bfd_of_glue_owner,
1591 tmp_name, BSF_GLOBAL, s, val,
1592 NULL, TRUE, FALSE, &bh);
1593
1594 myh = (struct elf_link_hash_entry *) bh;
1595 myh->type = ELF_ST_INFO (STB_LOCAL, STT_FUNC);
1596 myh->forced_local = 1;
1597
1598 free (tmp_name);
1599
1600 globals->arm_glue_size += ARM2THUMB_GLUE_SIZE;
1601
1602 return;
1603 }
1604
1605 static void
1606 record_thumb_to_arm_glue (struct bfd_link_info *link_info,
1607 struct elf_link_hash_entry *h)
1608 {
1609 const char *name = h->root.root.string;
1610 asection *s;
1611 char *tmp_name;
1612 struct elf_link_hash_entry *myh;
1613 struct bfd_link_hash_entry *bh;
1614 struct elf32_arm_link_hash_table *hash_table;
1615 bfd_vma val;
1616
1617 hash_table = elf32_arm_hash_table (link_info);
1618
1619 BFD_ASSERT (hash_table != NULL);
1620 BFD_ASSERT (hash_table->bfd_of_glue_owner != NULL);
1621
1622 s = bfd_get_section_by_name
1623 (hash_table->bfd_of_glue_owner, THUMB2ARM_GLUE_SECTION_NAME);
1624
1625 BFD_ASSERT (s != NULL);
1626
1627 tmp_name = bfd_malloc ((bfd_size_type) strlen (name)
1628 + strlen (THUMB2ARM_GLUE_ENTRY_NAME) + 1);
1629
1630 BFD_ASSERT (tmp_name);
1631
1632 sprintf (tmp_name, THUMB2ARM_GLUE_ENTRY_NAME, name);
1633
1634 myh = elf_link_hash_lookup
1635 (&(hash_table)->root, tmp_name, FALSE, FALSE, TRUE);
1636
1637 if (myh != NULL)
1638 {
1639 /* We've already seen this guy. */
1640 free (tmp_name);
1641 return;
1642 }
1643
1644 bh = NULL;
1645 val = hash_table->thumb_glue_size + 1;
1646 _bfd_generic_link_add_one_symbol (link_info, hash_table->bfd_of_glue_owner,
1647 tmp_name, BSF_GLOBAL, s, val,
1648 NULL, TRUE, FALSE, &bh);
1649
1650 /* If we mark it 'Thumb', the disassembler will do a better job. */
1651 myh = (struct elf_link_hash_entry *) bh;
1652 myh->type = ELF_ST_INFO (STB_LOCAL, STT_ARM_TFUNC);
1653 myh->forced_local = 1;
1654
1655 free (tmp_name);
1656
1657 #define CHANGE_TO_ARM "__%s_change_to_arm"
1658 #define BACK_FROM_ARM "__%s_back_from_arm"
1659
1660 /* Allocate another symbol to mark where we switch to Arm mode. */
1661 tmp_name = bfd_malloc ((bfd_size_type) strlen (name)
1662 + strlen (CHANGE_TO_ARM) + 1);
1663
1664 BFD_ASSERT (tmp_name);
1665
1666 sprintf (tmp_name, CHANGE_TO_ARM, name);
1667
1668 bh = NULL;
1669 val = hash_table->thumb_glue_size + 4,
1670 _bfd_generic_link_add_one_symbol (link_info, hash_table->bfd_of_glue_owner,
1671 tmp_name, BSF_LOCAL, s, val,
1672 NULL, TRUE, FALSE, &bh);
1673
1674 free (tmp_name);
1675
1676 hash_table->thumb_glue_size += THUMB2ARM_GLUE_SIZE;
1677
1678 return;
1679 }
1680
1681 /* Add the glue sections to ABFD. This function is called from the
1682 linker scripts in ld/emultempl/{armelf}.em. */
1683
1684 bfd_boolean
1685 bfd_elf32_arm_add_glue_sections_to_bfd (bfd *abfd,
1686 struct bfd_link_info *info)
1687 {
1688 flagword flags;
1689 asection *sec;
1690
1691 /* If we are only performing a partial
1692 link do not bother adding the glue. */
1693 if (info->relocatable)
1694 return TRUE;
1695
1696 sec = bfd_get_section_by_name (abfd, ARM2THUMB_GLUE_SECTION_NAME);
1697
1698 if (sec == NULL)
1699 {
1700 /* Note: we do not include the flag SEC_LINKER_CREATED, as this
1701 will prevent elf_link_input_bfd() from processing the contents
1702 of this section. */
1703 flags = SEC_ALLOC | SEC_LOAD | SEC_HAS_CONTENTS | SEC_IN_MEMORY | SEC_CODE | SEC_READONLY;
1704
1705 sec = bfd_make_section (abfd, ARM2THUMB_GLUE_SECTION_NAME);
1706
1707 if (sec == NULL
1708 || !bfd_set_section_flags (abfd, sec, flags)
1709 || !bfd_set_section_alignment (abfd, sec, 2))
1710 return FALSE;
1711
1712 /* Set the gc mark to prevent the section from being removed by garbage
1713 collection, despite the fact that no relocs refer to this section. */
1714 sec->gc_mark = 1;
1715 }
1716
1717 sec = bfd_get_section_by_name (abfd, THUMB2ARM_GLUE_SECTION_NAME);
1718
1719 if (sec == NULL)
1720 {
1721 flags = SEC_ALLOC | SEC_LOAD | SEC_HAS_CONTENTS | SEC_IN_MEMORY
1722 | SEC_CODE | SEC_READONLY;
1723
1724 sec = bfd_make_section (abfd, THUMB2ARM_GLUE_SECTION_NAME);
1725
1726 if (sec == NULL
1727 || !bfd_set_section_flags (abfd, sec, flags)
1728 || !bfd_set_section_alignment (abfd, sec, 2))
1729 return FALSE;
1730
1731 sec->gc_mark = 1;
1732 }
1733
1734 return TRUE;
1735 }
1736
1737 /* Select a BFD to be used to hold the sections used by the glue code.
1738 This function is called from the linker scripts in ld/emultempl/
1739 {armelf/pe}.em */
1740
1741 bfd_boolean
1742 bfd_elf32_arm_get_bfd_for_interworking (bfd *abfd, struct bfd_link_info *info)
1743 {
1744 struct elf32_arm_link_hash_table *globals;
1745
1746 /* If we are only performing a partial link
1747 do not bother getting a bfd to hold the glue. */
1748 if (info->relocatable)
1749 return TRUE;
1750
1751 /* Make sure we don't attach the glue sections to a dynamic object. */
1752 BFD_ASSERT (!(abfd->flags & DYNAMIC));
1753
1754 globals = elf32_arm_hash_table (info);
1755
1756 BFD_ASSERT (globals != NULL);
1757
1758 if (globals->bfd_of_glue_owner != NULL)
1759 return TRUE;
1760
1761 /* Save the bfd for later use. */
1762 globals->bfd_of_glue_owner = abfd;
1763
1764 return TRUE;
1765 }
1766
1767 bfd_boolean
1768 bfd_elf32_arm_process_before_allocation (bfd *abfd,
1769 struct bfd_link_info *link_info,
1770 int byteswap_code)
1771 {
1772 Elf_Internal_Shdr *symtab_hdr;
1773 Elf_Internal_Rela *internal_relocs = NULL;
1774 Elf_Internal_Rela *irel, *irelend;
1775 bfd_byte *contents = NULL;
1776
1777 asection *sec;
1778 struct elf32_arm_link_hash_table *globals;
1779
1780 /* If we are only performing a partial link do not bother
1781 to construct any glue. */
1782 if (link_info->relocatable)
1783 return TRUE;
1784
1785 /* Here we have a bfd that is to be included on the link. We have a hook
1786 to do reloc rummaging, before section sizes are nailed down. */
1787 globals = elf32_arm_hash_table (link_info);
1788
1789 BFD_ASSERT (globals != NULL);
1790 BFD_ASSERT (globals->bfd_of_glue_owner != NULL);
1791
1792 if (byteswap_code && !bfd_big_endian (abfd))
1793 {
1794 _bfd_error_handler (_("%B: BE8 images only valid in big-endian mode."),
1795 abfd);
1796 return FALSE;
1797 }
1798 globals->byteswap_code = byteswap_code;
1799
1800 /* Rummage around all the relocs and map the glue vectors. */
1801 sec = abfd->sections;
1802
1803 if (sec == NULL)
1804 return TRUE;
1805
1806 for (; sec != NULL; sec = sec->next)
1807 {
1808 if (sec->reloc_count == 0)
1809 continue;
1810
1811 symtab_hdr = &elf_tdata (abfd)->symtab_hdr;
1812
1813 /* Load the relocs. */
1814 internal_relocs
1815 = _bfd_elf_link_read_relocs (abfd, sec, (void *) NULL,
1816 (Elf_Internal_Rela *) NULL, FALSE);
1817
1818 if (internal_relocs == NULL)
1819 goto error_return;
1820
1821 irelend = internal_relocs + sec->reloc_count;
1822 for (irel = internal_relocs; irel < irelend; irel++)
1823 {
1824 long r_type;
1825 unsigned long r_index;
1826
1827 struct elf_link_hash_entry *h;
1828
1829 r_type = ELF32_R_TYPE (irel->r_info);
1830 r_index = ELF32_R_SYM (irel->r_info);
1831
1832 /* These are the only relocation types we care about. */
1833 if ( r_type != R_ARM_PC24
1834 && r_type != R_ARM_PLT32
1835 #ifndef OLD_ARM_ABI
1836 && r_type != R_ARM_CALL
1837 && r_type != R_ARM_JUMP24
1838 #endif
1839 && r_type != R_ARM_THM_PC22)
1840 continue;
1841
1842 /* Get the section contents if we haven't done so already. */
1843 if (contents == NULL)
1844 {
1845 /* Get cached copy if it exists. */
1846 if (elf_section_data (sec)->this_hdr.contents != NULL)
1847 contents = elf_section_data (sec)->this_hdr.contents;
1848 else
1849 {
1850 /* Go get them off disk. */
1851 if (! bfd_malloc_and_get_section (abfd, sec, &contents))
1852 goto error_return;
1853 }
1854 }
1855
1856 /* If the relocation is not against a symbol it cannot concern us. */
1857 h = NULL;
1858
1859 /* We don't care about local symbols. */
1860 if (r_index < symtab_hdr->sh_info)
1861 continue;
1862
1863 /* This is an external symbol. */
1864 r_index -= symtab_hdr->sh_info;
1865 h = (struct elf_link_hash_entry *)
1866 elf_sym_hashes (abfd)[r_index];
1867
1868 /* If the relocation is against a static symbol it must be within
1869 the current section and so cannot be a cross ARM/Thumb relocation. */
1870 if (h == NULL)
1871 continue;
1872
1873 /* If the call will go through a PLT entry then we do not need
1874 glue. */
1875 if (globals->splt != NULL && h->plt.offset != (bfd_vma) -1)
1876 continue;
1877
1878 switch (r_type)
1879 {
1880 case R_ARM_PC24:
1881 #ifndef OLD_ARM_ABI
1882 case R_ARM_CALL:
1883 case R_ARM_JUMP24:
1884 #endif
1885 /* This one is a call from arm code. We need to look up
1886 the target of the call. If it is a thumb target, we
1887 insert glue. */
1888 if (ELF_ST_TYPE(h->type) == STT_ARM_TFUNC)
1889 record_arm_to_thumb_glue (link_info, h);
1890 break;
1891
1892 case R_ARM_THM_PC22:
1893 /* This one is a call from thumb code. We look
1894 up the target of the call. If it is not a thumb
1895 target, we insert glue. */
1896 if (ELF_ST_TYPE (h->type) != STT_ARM_TFUNC)
1897 record_thumb_to_arm_glue (link_info, h);
1898 break;
1899
1900 default:
1901 break;
1902 }
1903 }
1904
1905 if (contents != NULL
1906 && elf_section_data (sec)->this_hdr.contents != contents)
1907 free (contents);
1908 contents = NULL;
1909
1910 if (internal_relocs != NULL
1911 && elf_section_data (sec)->relocs != internal_relocs)
1912 free (internal_relocs);
1913 internal_relocs = NULL;
1914 }
1915
1916 return TRUE;
1917
1918 error_return:
1919 if (contents != NULL
1920 && elf_section_data (sec)->this_hdr.contents != contents)
1921 free (contents);
1922 if (internal_relocs != NULL
1923 && elf_section_data (sec)->relocs != internal_relocs)
1924 free (internal_relocs);
1925
1926 return FALSE;
1927 }
1928 #endif
1929
1930
1931 #ifndef OLD_ARM_ABI
1932 /* Set target relocation values needed during linking. */
1933
1934 void
1935 bfd_elf32_arm_set_target_relocs (struct bfd_link_info *link_info,
1936 int target1_is_rel,
1937 char * target2_type,
1938 int fix_v4bx)
1939 {
1940 struct elf32_arm_link_hash_table *globals;
1941
1942 globals = elf32_arm_hash_table (link_info);
1943
1944 globals->target1_is_rel = target1_is_rel;
1945 if (strcmp (target2_type, "rel") == 0)
1946 globals->target2_reloc = R_ARM_REL32;
1947 else if (strcmp (target2_type, "abs") == 0)
1948 globals->target2_reloc = R_ARM_ABS32;
1949 else if (strcmp (target2_type, "got-rel") == 0)
1950 globals->target2_reloc = R_ARM_GOT_PREL;
1951 else
1952 {
1953 _bfd_error_handler (_("Invalid TARGET2 relocation type '%s'."),
1954 target2_type);
1955 }
1956 globals->fix_v4bx = fix_v4bx;
1957 }
1958 #endif
1959
1960 /* The thumb form of a long branch is a bit finicky, because the offset
1961 encoding is split over two fields, each in it's own instruction. They
1962 can occur in any order. So given a thumb form of long branch, and an
1963 offset, insert the offset into the thumb branch and return finished
1964 instruction.
1965
1966 It takes two thumb instructions to encode the target address. Each has
1967 11 bits to invest. The upper 11 bits are stored in one (identified by
1968 H-0.. see below), the lower 11 bits are stored in the other (identified
1969 by H-1).
1970
1971 Combine together and shifted left by 1 (it's a half word address) and
1972 there you have it.
1973
1974 Op: 1111 = F,
1975 H-0, upper address-0 = 000
1976 Op: 1111 = F,
1977 H-1, lower address-0 = 800
1978
1979 They can be ordered either way, but the arm tools I've seen always put
1980 the lower one first. It probably doesn't matter. krk@cygnus.com
1981
1982 XXX: Actually the order does matter. The second instruction (H-1)
1983 moves the computed address into the PC, so it must be the second one
1984 in the sequence. The problem, however is that whilst little endian code
1985 stores the instructions in HI then LOW order, big endian code does the
1986 reverse. nickc@cygnus.com. */
1987
1988 #define LOW_HI_ORDER 0xF800F000
1989 #define HI_LOW_ORDER 0xF000F800
1990
1991 static insn32
1992 insert_thumb_branch (insn32 br_insn, int rel_off)
1993 {
1994 unsigned int low_bits;
1995 unsigned int high_bits;
1996
1997 BFD_ASSERT ((rel_off & 1) != 1);
1998
1999 rel_off >>= 1; /* Half word aligned address. */
2000 low_bits = rel_off & 0x000007FF; /* The bottom 11 bits. */
2001 high_bits = (rel_off >> 11) & 0x000007FF; /* The top 11 bits. */
2002
2003 if ((br_insn & LOW_HI_ORDER) == LOW_HI_ORDER)
2004 br_insn = LOW_HI_ORDER | (low_bits << 16) | high_bits;
2005 else if ((br_insn & HI_LOW_ORDER) == HI_LOW_ORDER)
2006 br_insn = HI_LOW_ORDER | (high_bits << 16) | low_bits;
2007 else
2008 /* FIXME: abort is probably not the right call. krk@cygnus.com */
2009 abort (); /* Error - not a valid branch instruction form. */
2010
2011 return br_insn;
2012 }
2013
2014 /* Thumb code calling an ARM function. */
2015
2016 static int
2017 elf32_thumb_to_arm_stub (struct bfd_link_info * info,
2018 const char * name,
2019 bfd * input_bfd,
2020 bfd * output_bfd,
2021 asection * input_section,
2022 bfd_byte * hit_data,
2023 asection * sym_sec,
2024 bfd_vma offset,
2025 bfd_signed_vma addend,
2026 bfd_vma val)
2027 {
2028 asection * s = 0;
2029 bfd_vma my_offset;
2030 unsigned long int tmp;
2031 long int ret_offset;
2032 struct elf_link_hash_entry * myh;
2033 struct elf32_arm_link_hash_table * globals;
2034
2035 myh = find_thumb_glue (info, name, input_bfd);
2036 if (myh == NULL)
2037 return FALSE;
2038
2039 globals = elf32_arm_hash_table (info);
2040
2041 BFD_ASSERT (globals != NULL);
2042 BFD_ASSERT (globals->bfd_of_glue_owner != NULL);
2043
2044 my_offset = myh->root.u.def.value;
2045
2046 s = bfd_get_section_by_name (globals->bfd_of_glue_owner,
2047 THUMB2ARM_GLUE_SECTION_NAME);
2048
2049 BFD_ASSERT (s != NULL);
2050 BFD_ASSERT (s->contents != NULL);
2051 BFD_ASSERT (s->output_section != NULL);
2052
2053 if ((my_offset & 0x01) == 0x01)
2054 {
2055 if (sym_sec != NULL
2056 && sym_sec->owner != NULL
2057 && !INTERWORK_FLAG (sym_sec->owner))
2058 {
2059 (*_bfd_error_handler)
2060 (_("%B(%s): warning: interworking not enabled.\n"
2061 " first occurrence: %B: thumb call to arm"),
2062 sym_sec->owner, input_bfd, name);
2063
2064 return FALSE;
2065 }
2066
2067 --my_offset;
2068 myh->root.u.def.value = my_offset;
2069
2070 bfd_put_16 (output_bfd, (bfd_vma) t2a1_bx_pc_insn,
2071 s->contents + my_offset);
2072
2073 bfd_put_16 (output_bfd, (bfd_vma) t2a2_noop_insn,
2074 s->contents + my_offset + 2);
2075
2076 ret_offset =
2077 /* Address of destination of the stub. */
2078 ((bfd_signed_vma) val)
2079 - ((bfd_signed_vma)
2080 /* Offset from the start of the current section
2081 to the start of the stubs. */
2082 (s->output_offset
2083 /* Offset of the start of this stub from the start of the stubs. */
2084 + my_offset
2085 /* Address of the start of the current section. */
2086 + s->output_section->vma)
2087 /* The branch instruction is 4 bytes into the stub. */
2088 + 4
2089 /* ARM branches work from the pc of the instruction + 8. */
2090 + 8);
2091
2092 bfd_put_32 (output_bfd,
2093 (bfd_vma) t2a3_b_insn | ((ret_offset >> 2) & 0x00FFFFFF),
2094 s->contents + my_offset + 4);
2095 }
2096
2097 BFD_ASSERT (my_offset <= globals->thumb_glue_size);
2098
2099 /* Now go back and fix up the original BL insn to point to here. */
2100 ret_offset =
2101 /* Address of where the stub is located. */
2102 (s->output_section->vma + s->output_offset + my_offset)
2103 /* Address of where the BL is located. */
2104 - (input_section->output_section->vma + input_section->output_offset
2105 + offset)
2106 /* Addend in the relocation. */
2107 - addend
2108 /* Biassing for PC-relative addressing. */
2109 - 8;
2110
2111 tmp = bfd_get_32 (input_bfd, hit_data
2112 - input_section->vma);
2113
2114 bfd_put_32 (output_bfd,
2115 (bfd_vma) insert_thumb_branch (tmp, ret_offset),
2116 hit_data - input_section->vma);
2117
2118 return TRUE;
2119 }
2120
2121 /* Arm code calling a Thumb function. */
2122
2123 static int
2124 elf32_arm_to_thumb_stub (struct bfd_link_info * info,
2125 const char * name,
2126 bfd * input_bfd,
2127 bfd * output_bfd,
2128 asection * input_section,
2129 bfd_byte * hit_data,
2130 asection * sym_sec,
2131 bfd_vma offset,
2132 bfd_signed_vma addend,
2133 bfd_vma val)
2134 {
2135 unsigned long int tmp;
2136 bfd_vma my_offset;
2137 asection * s;
2138 long int ret_offset;
2139 struct elf_link_hash_entry * myh;
2140 struct elf32_arm_link_hash_table * globals;
2141
2142 myh = find_arm_glue (info, name, input_bfd);
2143 if (myh == NULL)
2144 return FALSE;
2145
2146 globals = elf32_arm_hash_table (info);
2147
2148 BFD_ASSERT (globals != NULL);
2149 BFD_ASSERT (globals->bfd_of_glue_owner != NULL);
2150
2151 my_offset = myh->root.u.def.value;
2152 s = bfd_get_section_by_name (globals->bfd_of_glue_owner,
2153 ARM2THUMB_GLUE_SECTION_NAME);
2154 BFD_ASSERT (s != NULL);
2155 BFD_ASSERT (s->contents != NULL);
2156 BFD_ASSERT (s->output_section != NULL);
2157
2158 if ((my_offset & 0x01) == 0x01)
2159 {
2160 if (sym_sec != NULL
2161 && sym_sec->owner != NULL
2162 && !INTERWORK_FLAG (sym_sec->owner))
2163 {
2164 (*_bfd_error_handler)
2165 (_("%B(%s): warning: interworking not enabled.\n"
2166 " first occurrence: %B: arm call to thumb"),
2167 sym_sec->owner, input_bfd, name);
2168 }
2169
2170 --my_offset;
2171 myh->root.u.def.value = my_offset;
2172
2173 bfd_put_32 (output_bfd, (bfd_vma) a2t1_ldr_insn,
2174 s->contents + my_offset);
2175
2176 bfd_put_32 (output_bfd, (bfd_vma) a2t2_bx_r12_insn,
2177 s->contents + my_offset + 4);
2178
2179 /* It's a thumb address. Add the low order bit. */
2180 bfd_put_32 (output_bfd, val | a2t3_func_addr_insn,
2181 s->contents + my_offset + 8);
2182 }
2183
2184 BFD_ASSERT (my_offset <= globals->arm_glue_size);
2185
2186 tmp = bfd_get_32 (input_bfd, hit_data);
2187 tmp = tmp & 0xFF000000;
2188
2189 /* Somehow these are both 4 too far, so subtract 8. */
2190 ret_offset = (s->output_offset
2191 + my_offset
2192 + s->output_section->vma
2193 - (input_section->output_offset
2194 + input_section->output_section->vma
2195 + offset + addend)
2196 - 8);
2197
2198 tmp = tmp | ((ret_offset >> 2) & 0x00FFFFFF);
2199
2200 bfd_put_32 (output_bfd, (bfd_vma) tmp, hit_data - input_section->vma);
2201
2202 return TRUE;
2203 }
2204
2205
2206 #ifndef OLD_ARM_ABI
2207 /* Some relocations map to different relocations depending on the
2208 target. Return the real relocation. */
2209 static int
2210 arm_real_reloc_type (struct elf32_arm_link_hash_table * globals,
2211 int r_type)
2212 {
2213 switch (r_type)
2214 {
2215 case R_ARM_TARGET1:
2216 if (globals->target1_is_rel)
2217 return R_ARM_REL32;
2218 else
2219 return R_ARM_ABS32;
2220
2221 case R_ARM_TARGET2:
2222 return globals->target2_reloc;
2223
2224 default:
2225 return r_type;
2226 }
2227 }
2228 #endif /* OLD_ARM_ABI */
2229
2230
2231 /* Perform a relocation as part of a final link. */
2232
2233 static bfd_reloc_status_type
2234 elf32_arm_final_link_relocate (reloc_howto_type * howto,
2235 bfd * input_bfd,
2236 bfd * output_bfd,
2237 asection * input_section,
2238 bfd_byte * contents,
2239 Elf_Internal_Rela * rel,
2240 bfd_vma value,
2241 struct bfd_link_info * info,
2242 asection * sym_sec,
2243 const char * sym_name,
2244 int sym_flags,
2245 struct elf_link_hash_entry * h,
2246 bfd_boolean * unresolved_reloc_p)
2247 {
2248 unsigned long r_type = howto->type;
2249 unsigned long r_symndx;
2250 bfd_byte * hit_data = contents + rel->r_offset;
2251 bfd * dynobj = NULL;
2252 Elf_Internal_Shdr * symtab_hdr;
2253 struct elf_link_hash_entry ** sym_hashes;
2254 bfd_vma * local_got_offsets;
2255 asection * sgot = NULL;
2256 asection * splt = NULL;
2257 asection * sreloc = NULL;
2258 bfd_vma addend;
2259 bfd_signed_vma signed_addend;
2260 struct elf32_arm_link_hash_table * globals;
2261
2262 globals = elf32_arm_hash_table (info);
2263
2264 #ifndef OLD_ARM_ABI
2265 /* Some relocation type map to different relocations depending on the
2266 target. We pick the right one here. */
2267 r_type = arm_real_reloc_type (globals, r_type);
2268 if (r_type != howto->type)
2269 howto = elf32_arm_howto_from_type (r_type);
2270 #endif /* OLD_ARM_ABI */
2271
2272 /* If the start address has been set, then set the EF_ARM_HASENTRY
2273 flag. Setting this more than once is redundant, but the cost is
2274 not too high, and it keeps the code simple.
2275
2276 The test is done here, rather than somewhere else, because the
2277 start address is only set just before the final link commences.
2278
2279 Note - if the user deliberately sets a start address of 0, the
2280 flag will not be set. */
2281 if (bfd_get_start_address (output_bfd) != 0)
2282 elf_elfheader (output_bfd)->e_flags |= EF_ARM_HASENTRY;
2283
2284 dynobj = elf_hash_table (info)->dynobj;
2285 if (dynobj)
2286 {
2287 sgot = bfd_get_section_by_name (dynobj, ".got");
2288 splt = bfd_get_section_by_name (dynobj, ".plt");
2289 }
2290 symtab_hdr = & elf_tdata (input_bfd)->symtab_hdr;
2291 sym_hashes = elf_sym_hashes (input_bfd);
2292 local_got_offsets = elf_local_got_offsets (input_bfd);
2293 r_symndx = ELF32_R_SYM (rel->r_info);
2294
2295 if (globals->use_rel)
2296 {
2297 addend = bfd_get_32 (input_bfd, hit_data) & howto->src_mask;
2298
2299 if (addend & ((howto->src_mask + 1) >> 1))
2300 {
2301 signed_addend = -1;
2302 signed_addend &= ~ howto->src_mask;
2303 signed_addend |= addend;
2304 }
2305 else
2306 signed_addend = addend;
2307 }
2308 else
2309 addend = signed_addend = rel->r_addend;
2310
2311 switch (r_type)
2312 {
2313 case R_ARM_NONE:
2314 return bfd_reloc_ok;
2315
2316 case R_ARM_PC24:
2317 case R_ARM_ABS32:
2318 case R_ARM_REL32:
2319 #ifndef OLD_ARM_ABI
2320 case R_ARM_CALL:
2321 case R_ARM_JUMP24:
2322 case R_ARM_XPC25:
2323 case R_ARM_PREL31:
2324 #endif
2325 case R_ARM_PLT32:
2326 /* r_symndx will be zero only for relocs against symbols
2327 from removed linkonce sections, or sections discarded by
2328 a linker script. */
2329 if (r_symndx == 0)
2330 return bfd_reloc_ok;
2331
2332 /* Handle relocations which should use the PLT entry. ABS32/REL32
2333 will use the symbol's value, which may point to a PLT entry, but we
2334 don't need to handle that here. If we created a PLT entry, all
2335 branches in this object should go to it. */
2336 if ((r_type != R_ARM_ABS32 && r_type != R_ARM_REL32)
2337 && h != NULL
2338 && splt != NULL
2339 && h->plt.offset != (bfd_vma) -1)
2340 {
2341 /* If we've created a .plt section, and assigned a PLT entry to
2342 this function, it should not be known to bind locally. If
2343 it were, we would have cleared the PLT entry. */
2344 BFD_ASSERT (!SYMBOL_CALLS_LOCAL (info, h));
2345
2346 value = (splt->output_section->vma
2347 + splt->output_offset
2348 + h->plt.offset);
2349 *unresolved_reloc_p = FALSE;
2350 return _bfd_final_link_relocate (howto, input_bfd, input_section,
2351 contents, rel->r_offset, value,
2352 (bfd_vma) 0);
2353 }
2354
2355 /* When generating a shared object or relocatable executable, these
2356 relocations are copied into the output file to be resolved at
2357 run time. */
2358 if ((info->shared || globals->root.is_relocatable_executable)
2359 && (input_section->flags & SEC_ALLOC)
2360 && (r_type != R_ARM_REL32
2361 || !SYMBOL_CALLS_LOCAL (info, h))
2362 && (h == NULL
2363 || ELF_ST_VISIBILITY (h->other) == STV_DEFAULT
2364 || h->root.type != bfd_link_hash_undefweak)
2365 && r_type != R_ARM_PC24
2366 #ifndef OLD_ARM_ABI
2367 && r_type != R_ARM_CALL
2368 && r_type != R_ARM_JUMP24
2369 && r_type != R_ARM_PREL31
2370 #endif
2371 && r_type != R_ARM_PLT32)
2372 {
2373 Elf_Internal_Rela outrel;
2374 bfd_byte *loc;
2375 bfd_boolean skip, relocate;
2376
2377 *unresolved_reloc_p = FALSE;
2378
2379 if (sreloc == NULL)
2380 {
2381 const char * name;
2382
2383 name = (bfd_elf_string_from_elf_section
2384 (input_bfd,
2385 elf_elfheader (input_bfd)->e_shstrndx,
2386 elf_section_data (input_section)->rel_hdr.sh_name));
2387 if (name == NULL)
2388 return bfd_reloc_notsupported;
2389
2390 BFD_ASSERT (strncmp (name, ".rel", 4) == 0
2391 && strcmp (bfd_get_section_name (input_bfd,
2392 input_section),
2393 name + 4) == 0);
2394
2395 sreloc = bfd_get_section_by_name (dynobj, name);
2396 BFD_ASSERT (sreloc != NULL);
2397 }
2398
2399 skip = FALSE;
2400 relocate = FALSE;
2401
2402 outrel.r_offset =
2403 _bfd_elf_section_offset (output_bfd, info, input_section,
2404 rel->r_offset);
2405 if (outrel.r_offset == (bfd_vma) -1)
2406 skip = TRUE;
2407 else if (outrel.r_offset == (bfd_vma) -2)
2408 skip = TRUE, relocate = TRUE;
2409 outrel.r_offset += (input_section->output_section->vma
2410 + input_section->output_offset);
2411
2412 if (skip)
2413 memset (&outrel, 0, sizeof outrel);
2414 else if (h != NULL
2415 && h->dynindx != -1
2416 && (!info->shared
2417 || !info->symbolic
2418 || !h->def_regular))
2419 outrel.r_info = ELF32_R_INFO (h->dynindx, r_type);
2420 else
2421 {
2422 int symbol;
2423
2424 /* This symbol is local, or marked to become local. */
2425 relocate = TRUE;
2426 if (sym_flags == STT_ARM_TFUNC)
2427 value |= 1;
2428 if (globals->symbian_p)
2429 {
2430 /* On Symbian OS, the data segment and text segement
2431 can be relocated independently. Therefore, we
2432 must indicate the segment to which this
2433 relocation is relative. The BPABI allows us to
2434 use any symbol in the right segment; we just use
2435 the section symbol as it is convenient. (We
2436 cannot use the symbol given by "h" directly as it
2437 will not appear in the dynamic symbol table.) */
2438 symbol = elf_section_data (sym_sec->output_section)->dynindx;
2439 BFD_ASSERT (symbol != 0);
2440 }
2441 else
2442 /* On SVR4-ish systems, the dynamic loader cannot
2443 relocate the text and data segments independently,
2444 so the symbol does not matter. */
2445 symbol = 0;
2446 outrel.r_info = ELF32_R_INFO (symbol, R_ARM_RELATIVE);
2447 }
2448
2449 loc = sreloc->contents;
2450 loc += sreloc->reloc_count++ * sizeof (Elf32_External_Rel);
2451 bfd_elf32_swap_reloc_out (output_bfd, &outrel, loc);
2452
2453 /* If this reloc is against an external symbol, we do not want to
2454 fiddle with the addend. Otherwise, we need to include the symbol
2455 value so that it becomes an addend for the dynamic reloc. */
2456 if (! relocate)
2457 return bfd_reloc_ok;
2458
2459 return _bfd_final_link_relocate (howto, input_bfd, input_section,
2460 contents, rel->r_offset, value,
2461 (bfd_vma) 0);
2462 }
2463 else switch (r_type)
2464 {
2465 #ifndef OLD_ARM_ABI
2466 case R_ARM_XPC25: /* Arm BLX instruction. */
2467 case R_ARM_CALL:
2468 case R_ARM_JUMP24:
2469 #endif
2470 case R_ARM_PC24: /* Arm B/BL instruction */
2471 case R_ARM_PLT32:
2472 #ifndef OLD_ARM_ABI
2473 if (r_type == R_ARM_XPC25)
2474 {
2475 /* Check for Arm calling Arm function. */
2476 /* FIXME: Should we translate the instruction into a BL
2477 instruction instead ? */
2478 if (sym_flags != STT_ARM_TFUNC)
2479 (*_bfd_error_handler)
2480 (_("\%B: Warning: Arm BLX instruction targets Arm function '%s'."),
2481 input_bfd,
2482 h ? h->root.root.string : "(local)");
2483 }
2484 else
2485 #endif
2486 {
2487 /* Check for Arm calling Thumb function. */
2488 if (sym_flags == STT_ARM_TFUNC)
2489 {
2490 elf32_arm_to_thumb_stub (info, sym_name, input_bfd,
2491 output_bfd, input_section,
2492 hit_data, sym_sec, rel->r_offset,
2493 signed_addend, value);
2494 return bfd_reloc_ok;
2495 }
2496 }
2497
2498 /* The ARM ELF ABI says that this reloc is computed as: S - P + A
2499 where:
2500 S is the address of the symbol in the relocation.
2501 P is address of the instruction being relocated.
2502 A is the addend (extracted from the instruction) in bytes.
2503
2504 S is held in 'value'.
2505 P is the base address of the section containing the
2506 instruction plus the offset of the reloc into that
2507 section, ie:
2508 (input_section->output_section->vma +
2509 input_section->output_offset +
2510 rel->r_offset).
2511 A is the addend, converted into bytes, ie:
2512 (signed_addend * 4)
2513
2514 Note: None of these operations have knowledge of the pipeline
2515 size of the processor, thus it is up to the assembler to
2516 encode this information into the addend. */
2517 value -= (input_section->output_section->vma
2518 + input_section->output_offset);
2519 value -= rel->r_offset;
2520 if (globals->use_rel)
2521 value += (signed_addend << howto->size);
2522 else
2523 /* RELA addends do not have to be adjusted by howto->size. */
2524 value += signed_addend;
2525
2526 signed_addend = value;
2527 signed_addend >>= howto->rightshift;
2528
2529 /* It is not an error for an undefined weak reference to be
2530 out of range. Any program that branches to such a symbol
2531 is going to crash anyway, so there is no point worrying
2532 about getting the destination exactly right. */
2533 if (! h || h->root.type != bfd_link_hash_undefweak)
2534 {
2535 /* Perform a signed range check. */
2536 if ( signed_addend > ((bfd_signed_vma) (howto->dst_mask >> 1))
2537 || signed_addend < - ((bfd_signed_vma) ((howto->dst_mask + 1) >> 1)))
2538 return bfd_reloc_overflow;
2539 }
2540
2541 #ifndef OLD_ARM_ABI
2542 /* If necessary set the H bit in the BLX instruction. */
2543 if (r_type == R_ARM_XPC25 && ((value & 2) == 2))
2544 value = (signed_addend & howto->dst_mask)
2545 | (bfd_get_32 (input_bfd, hit_data) & (~ howto->dst_mask))
2546 | (1 << 24);
2547 else
2548 #endif
2549 value = (signed_addend & howto->dst_mask)
2550 | (bfd_get_32 (input_bfd, hit_data) & (~ howto->dst_mask));
2551 break;
2552
2553 case R_ARM_ABS32:
2554 value += addend;
2555 if (sym_flags == STT_ARM_TFUNC)
2556 value |= 1;
2557 break;
2558
2559 case R_ARM_REL32:
2560 value -= (input_section->output_section->vma
2561 + input_section->output_offset + rel->r_offset);
2562 value += addend;
2563 break;
2564
2565 #ifndef OLD_ARM_ABI
2566 case R_ARM_PREL31:
2567 value -= (input_section->output_section->vma
2568 + input_section->output_offset + rel->r_offset);
2569 value += signed_addend;
2570 if (! h || h->root.type != bfd_link_hash_undefweak)
2571 {
2572 /* Check for overflow */
2573 if ((value ^ (value >> 1)) & (1 << 30))
2574 return bfd_reloc_overflow;
2575 }
2576 value &= 0x7fffffff;
2577 value |= (bfd_get_32 (input_bfd, hit_data) & 0x80000000);
2578 if (sym_flags == STT_ARM_TFUNC)
2579 value |= 1;
2580 break;
2581 #endif
2582 }
2583
2584 bfd_put_32 (input_bfd, value, hit_data);
2585 return bfd_reloc_ok;
2586
2587 case R_ARM_ABS8:
2588 value += addend;
2589 if ((long) value > 0x7f || (long) value < -0x80)
2590 return bfd_reloc_overflow;
2591
2592 bfd_put_8 (input_bfd, value, hit_data);
2593 return bfd_reloc_ok;
2594
2595 case R_ARM_ABS16:
2596 value += addend;
2597
2598 if ((long) value > 0x7fff || (long) value < -0x8000)
2599 return bfd_reloc_overflow;
2600
2601 bfd_put_16 (input_bfd, value, hit_data);
2602 return bfd_reloc_ok;
2603
2604 case R_ARM_ABS12:
2605 /* Support ldr and str instruction for the arm */
2606 /* Also thumb b (unconditional branch). ??? Really? */
2607 value += addend;
2608
2609 if ((long) value > 0x7ff || (long) value < -0x800)
2610 return bfd_reloc_overflow;
2611
2612 value |= (bfd_get_32 (input_bfd, hit_data) & 0xfffff000);
2613 bfd_put_32 (input_bfd, value, hit_data);
2614 return bfd_reloc_ok;
2615
2616 case R_ARM_THM_ABS5:
2617 /* Support ldr and str instructions for the thumb. */
2618 if (globals->use_rel)
2619 {
2620 /* Need to refetch addend. */
2621 addend = bfd_get_16 (input_bfd, hit_data) & howto->src_mask;
2622 /* ??? Need to determine shift amount from operand size. */
2623 addend >>= howto->rightshift;
2624 }
2625 value += addend;
2626
2627 /* ??? Isn't value unsigned? */
2628 if ((long) value > 0x1f || (long) value < -0x10)
2629 return bfd_reloc_overflow;
2630
2631 /* ??? Value needs to be properly shifted into place first. */
2632 value |= bfd_get_16 (input_bfd, hit_data) & 0xf83f;
2633 bfd_put_16 (input_bfd, value, hit_data);
2634 return bfd_reloc_ok;
2635
2636 #ifndef OLD_ARM_ABI
2637 case R_ARM_THM_XPC22:
2638 #endif
2639 case R_ARM_THM_PC22:
2640 /* Thumb BL (branch long instruction). */
2641 {
2642 bfd_vma relocation;
2643 bfd_boolean overflow = FALSE;
2644 bfd_vma upper_insn = bfd_get_16 (input_bfd, hit_data);
2645 bfd_vma lower_insn = bfd_get_16 (input_bfd, hit_data + 2);
2646 bfd_signed_vma reloc_signed_max = ((1 << (howto->bitsize - 1)) - 1) >> howto->rightshift;
2647 bfd_signed_vma reloc_signed_min = ~ reloc_signed_max;
2648 bfd_vma check;
2649 bfd_signed_vma signed_check;
2650
2651 /* Need to refetch the addend and squish the two 11 bit pieces
2652 together. */
2653 if (globals->use_rel)
2654 {
2655 bfd_vma upper = upper_insn & 0x7ff;
2656 bfd_vma lower = lower_insn & 0x7ff;
2657 upper = (upper ^ 0x400) - 0x400; /* Sign extend. */
2658 addend = (upper << 12) | (lower << 1);
2659 signed_addend = addend;
2660 }
2661 #ifndef OLD_ARM_ABI
2662 if (r_type == R_ARM_THM_XPC22)
2663 {
2664 /* Check for Thumb to Thumb call. */
2665 /* FIXME: Should we translate the instruction into a BL
2666 instruction instead ? */
2667 if (sym_flags == STT_ARM_TFUNC)
2668 (*_bfd_error_handler)
2669 (_("%B: Warning: Thumb BLX instruction targets thumb function '%s'."),
2670 input_bfd,
2671 h ? h->root.root.string : "(local)");
2672 }
2673 else
2674 #endif
2675 {
2676 /* If it is not a call to Thumb, assume call to Arm.
2677 If it is a call relative to a section name, then it is not a
2678 function call at all, but rather a long jump. Calls through
2679 the PLT do not require stubs. */
2680 if (sym_flags != STT_ARM_TFUNC && sym_flags != STT_SECTION
2681 && (h == NULL || splt == NULL
2682 || h->plt.offset == (bfd_vma) -1))
2683 {
2684 if (elf32_thumb_to_arm_stub
2685 (info, sym_name, input_bfd, output_bfd, input_section,
2686 hit_data, sym_sec, rel->r_offset, signed_addend, value))
2687 return bfd_reloc_ok;
2688 else
2689 return bfd_reloc_dangerous;
2690 }
2691 }
2692
2693 /* Handle calls via the PLT. */
2694 if (h != NULL && splt != NULL && h->plt.offset != (bfd_vma) -1)
2695 {
2696 value = (splt->output_section->vma
2697 + splt->output_offset
2698 + h->plt.offset);
2699 /* Target the Thumb stub before the ARM PLT entry. */
2700 value -= 4;
2701 *unresolved_reloc_p = FALSE;
2702 }
2703
2704 relocation = value + signed_addend;
2705
2706 relocation -= (input_section->output_section->vma
2707 + input_section->output_offset
2708 + rel->r_offset);
2709
2710 check = relocation >> howto->rightshift;
2711
2712 /* If this is a signed value, the rightshift just dropped
2713 leading 1 bits (assuming twos complement). */
2714 if ((bfd_signed_vma) relocation >= 0)
2715 signed_check = check;
2716 else
2717 signed_check = check | ~((bfd_vma) -1 >> howto->rightshift);
2718
2719 /* Assumes two's complement. */
2720 if (signed_check > reloc_signed_max || signed_check < reloc_signed_min)
2721 overflow = TRUE;
2722
2723 #ifndef OLD_ARM_ABI
2724 if (r_type == R_ARM_THM_XPC22
2725 && ((lower_insn & 0x1800) == 0x0800))
2726 /* For a BLX instruction, make sure that the relocation is rounded up
2727 to a word boundary. This follows the semantics of the instruction
2728 which specifies that bit 1 of the target address will come from bit
2729 1 of the base address. */
2730 relocation = (relocation + 2) & ~ 3;
2731 #endif
2732 /* Put RELOCATION back into the insn. */
2733 upper_insn = (upper_insn & ~(bfd_vma) 0x7ff) | ((relocation >> 12) & 0x7ff);
2734 lower_insn = (lower_insn & ~(bfd_vma) 0x7ff) | ((relocation >> 1) & 0x7ff);
2735
2736 /* Put the relocated value back in the object file: */
2737 bfd_put_16 (input_bfd, upper_insn, hit_data);
2738 bfd_put_16 (input_bfd, lower_insn, hit_data + 2);
2739
2740 return (overflow ? bfd_reloc_overflow : bfd_reloc_ok);
2741 }
2742 break;
2743
2744 case R_ARM_THM_PC11:
2745 case R_ARM_THM_PC9:
2746 /* Thumb B (branch) instruction). */
2747 {
2748 bfd_signed_vma relocation;
2749 bfd_signed_vma reloc_signed_max = (1 << (howto->bitsize - 1)) - 1;
2750 bfd_signed_vma reloc_signed_min = ~ reloc_signed_max;
2751 bfd_signed_vma signed_check;
2752
2753 if (globals->use_rel)
2754 {
2755 /* Need to refetch addend. */
2756 addend = bfd_get_16 (input_bfd, hit_data) & howto->src_mask;
2757 if (addend & ((howto->src_mask + 1) >> 1))
2758 {
2759 signed_addend = -1;
2760 signed_addend &= ~ howto->src_mask;
2761 signed_addend |= addend;
2762 }
2763 else
2764 signed_addend = addend;
2765 /* The value in the insn has been right shifted. We need to
2766 undo this, so that we can perform the address calculation
2767 in terms of bytes. */
2768 signed_addend <<= howto->rightshift;
2769 }
2770 relocation = value + signed_addend;
2771
2772 relocation -= (input_section->output_section->vma
2773 + input_section->output_offset
2774 + rel->r_offset);
2775
2776 relocation >>= howto->rightshift;
2777 signed_check = relocation;
2778 relocation &= howto->dst_mask;
2779 relocation |= (bfd_get_16 (input_bfd, hit_data) & (~ howto->dst_mask));
2780
2781 bfd_put_16 (input_bfd, relocation, hit_data);
2782
2783 /* Assumes two's complement. */
2784 if (signed_check > reloc_signed_max || signed_check < reloc_signed_min)
2785 return bfd_reloc_overflow;
2786
2787 return bfd_reloc_ok;
2788 }
2789
2790 #ifndef OLD_ARM_ABI
2791 case R_ARM_ALU_PCREL7_0:
2792 case R_ARM_ALU_PCREL15_8:
2793 case R_ARM_ALU_PCREL23_15:
2794 {
2795 bfd_vma insn;
2796 bfd_vma relocation;
2797
2798 insn = bfd_get_32 (input_bfd, hit_data);
2799 if (globals->use_rel)
2800 {
2801 /* Extract the addend. */
2802 addend = (insn & 0xff) << ((insn & 0xf00) >> 7);
2803 signed_addend = addend;
2804 }
2805 relocation = value + signed_addend;
2806
2807 relocation -= (input_section->output_section->vma
2808 + input_section->output_offset
2809 + rel->r_offset);
2810 insn = (insn & ~0xfff)
2811 | ((howto->bitpos << 7) & 0xf00)
2812 | ((relocation >> howto->bitpos) & 0xff);
2813 bfd_put_32 (input_bfd, value, hit_data);
2814 }
2815 return bfd_reloc_ok;
2816 #endif
2817
2818 case R_ARM_GNU_VTINHERIT:
2819 case R_ARM_GNU_VTENTRY:
2820 return bfd_reloc_ok;
2821
2822 case R_ARM_COPY:
2823 return bfd_reloc_notsupported;
2824
2825 case R_ARM_GLOB_DAT:
2826 return bfd_reloc_notsupported;
2827
2828 case R_ARM_JUMP_SLOT:
2829 return bfd_reloc_notsupported;
2830
2831 case R_ARM_RELATIVE:
2832 return bfd_reloc_notsupported;
2833
2834 case R_ARM_GOTOFF:
2835 /* Relocation is relative to the start of the
2836 global offset table. */
2837
2838 BFD_ASSERT (sgot != NULL);
2839 if (sgot == NULL)
2840 return bfd_reloc_notsupported;
2841
2842 /* If we are addressing a Thumb function, we need to adjust the
2843 address by one, so that attempts to call the function pointer will
2844 correctly interpret it as Thumb code. */
2845 if (sym_flags == STT_ARM_TFUNC)
2846 value += 1;
2847
2848 /* Note that sgot->output_offset is not involved in this
2849 calculation. We always want the start of .got. If we
2850 define _GLOBAL_OFFSET_TABLE in a different way, as is
2851 permitted by the ABI, we might have to change this
2852 calculation. */
2853 value -= sgot->output_section->vma;
2854 return _bfd_final_link_relocate (howto, input_bfd, input_section,
2855 contents, rel->r_offset, value,
2856 (bfd_vma) 0);
2857
2858 case R_ARM_GOTPC:
2859 /* Use global offset table as symbol value. */
2860 BFD_ASSERT (sgot != NULL);
2861
2862 if (sgot == NULL)
2863 return bfd_reloc_notsupported;
2864
2865 *unresolved_reloc_p = FALSE;
2866 value = sgot->output_section->vma;
2867 return _bfd_final_link_relocate (howto, input_bfd, input_section,
2868 contents, rel->r_offset, value,
2869 (bfd_vma) 0);
2870
2871 case R_ARM_GOT32:
2872 #ifndef OLD_ARM_ABI
2873 case R_ARM_GOT_PREL:
2874 #endif
2875 /* Relocation is to the entry for this symbol in the
2876 global offset table. */
2877 if (sgot == NULL)
2878 return bfd_reloc_notsupported;
2879
2880 if (h != NULL)
2881 {
2882 bfd_vma off;
2883 bfd_boolean dyn;
2884
2885 off = h->got.offset;
2886 BFD_ASSERT (off != (bfd_vma) -1);
2887 dyn = globals->root.dynamic_sections_created;
2888
2889 if (! WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn, info->shared, h)
2890 || (info->shared
2891 && SYMBOL_REFERENCES_LOCAL (info, h))
2892 || (ELF_ST_VISIBILITY (h->other)
2893 && h->root.type == bfd_link_hash_undefweak))
2894 {
2895 /* This is actually a static link, or it is a -Bsymbolic link
2896 and the symbol is defined locally. We must initialize this
2897 entry in the global offset table. Since the offset must
2898 always be a multiple of 4, we use the least significant bit
2899 to record whether we have initialized it already.
2900
2901 When doing a dynamic link, we create a .rel.got relocation
2902 entry to initialize the value. This is done in the
2903 finish_dynamic_symbol routine. */
2904 if ((off & 1) != 0)
2905 off &= ~1;
2906 else
2907 {
2908 /* If we are addressing a Thumb function, we need to
2909 adjust the address by one, so that attempts to
2910 call the function pointer will correctly
2911 interpret it as Thumb code. */
2912 if (sym_flags == STT_ARM_TFUNC)
2913 value |= 1;
2914
2915 bfd_put_32 (output_bfd, value, sgot->contents + off);
2916 h->got.offset |= 1;
2917 }
2918 }
2919 else
2920 *unresolved_reloc_p = FALSE;
2921
2922 value = sgot->output_offset + off;
2923 }
2924 else
2925 {
2926 bfd_vma off;
2927
2928 BFD_ASSERT (local_got_offsets != NULL &&
2929 local_got_offsets[r_symndx] != (bfd_vma) -1);
2930
2931 off = local_got_offsets[r_symndx];
2932
2933 /* The offset must always be a multiple of 4. We use the
2934 least significant bit to record whether we have already
2935 generated the necessary reloc. */
2936 if ((off & 1) != 0)
2937 off &= ~1;
2938 else
2939 {
2940 /* If we are addressing a Thumb function, we need to
2941 adjust the address by one, so that attempts to
2942 call the function pointer will correctly
2943 interpret it as Thumb code. */
2944 if (sym_flags == STT_ARM_TFUNC)
2945 value |= 1;
2946
2947 bfd_put_32 (output_bfd, value, sgot->contents + off);
2948
2949 if (info->shared)
2950 {
2951 asection * srelgot;
2952 Elf_Internal_Rela outrel;
2953 bfd_byte *loc;
2954
2955 srelgot = bfd_get_section_by_name (dynobj, ".rel.got");
2956 BFD_ASSERT (srelgot != NULL);
2957
2958 outrel.r_offset = (sgot->output_section->vma
2959 + sgot->output_offset
2960 + off);
2961 outrel.r_info = ELF32_R_INFO (0, R_ARM_RELATIVE);
2962 loc = srelgot->contents;
2963 loc += srelgot->reloc_count++ * sizeof (Elf32_External_Rel);
2964 bfd_elf32_swap_reloc_out (output_bfd, &outrel, loc);
2965 }
2966
2967 local_got_offsets[r_symndx] |= 1;
2968 }
2969
2970 value = sgot->output_offset + off;
2971 }
2972 if (r_type != R_ARM_GOT32)
2973 value += sgot->output_section->vma;
2974
2975 return _bfd_final_link_relocate (howto, input_bfd, input_section,
2976 contents, rel->r_offset, value,
2977 (bfd_vma) 0);
2978
2979 case R_ARM_SBREL32:
2980 return bfd_reloc_notsupported;
2981
2982 case R_ARM_AMP_VCALL9:
2983 return bfd_reloc_notsupported;
2984
2985 case R_ARM_RSBREL32:
2986 return bfd_reloc_notsupported;
2987
2988 case R_ARM_THM_RPC22:
2989 return bfd_reloc_notsupported;
2990
2991 case R_ARM_RREL32:
2992 return bfd_reloc_notsupported;
2993
2994 case R_ARM_RABS32:
2995 return bfd_reloc_notsupported;
2996
2997 case R_ARM_RPC24:
2998 return bfd_reloc_notsupported;
2999
3000 case R_ARM_RBASE:
3001 return bfd_reloc_notsupported;
3002
3003 case R_ARM_V4BX:
3004 if (globals->fix_v4bx)
3005 {
3006 bfd_vma insn = bfd_get_32 (input_bfd, hit_data);
3007
3008 /* Ensure that we have a BX instruction. */
3009 BFD_ASSERT ((insn & 0x0ffffff0) == 0x012fff10);
3010
3011 /* Preserve Rm (lowest four bits) and the condition code
3012 (highest four bits). Other bits encode MOV PC,Rm. */
3013 insn = (insn & 0xf000000f) | 0x01a0f000;
3014
3015 bfd_put_32 (input_bfd, insn, hit_data);
3016 }
3017 return bfd_reloc_ok;
3018
3019 default:
3020 return bfd_reloc_notsupported;
3021 }
3022 }
3023
3024 /* Add INCREMENT to the reloc (of type HOWTO) at ADDRESS. */
3025 static void
3026 arm_add_to_rel (bfd * abfd,
3027 bfd_byte * address,
3028 reloc_howto_type * howto,
3029 bfd_signed_vma increment)
3030 {
3031 bfd_signed_vma addend;
3032
3033 if (howto->type == R_ARM_THM_PC22)
3034 {
3035 int upper_insn, lower_insn;
3036 int upper, lower;
3037
3038 upper_insn = bfd_get_16 (abfd, address);
3039 lower_insn = bfd_get_16 (abfd, address + 2);
3040 upper = upper_insn & 0x7ff;
3041 lower = lower_insn & 0x7ff;
3042
3043 addend = (upper << 12) | (lower << 1);
3044 addend += increment;
3045 addend >>= 1;
3046
3047 upper_insn = (upper_insn & 0xf800) | ((addend >> 11) & 0x7ff);
3048 lower_insn = (lower_insn & 0xf800) | (addend & 0x7ff);
3049
3050 bfd_put_16 (abfd, (bfd_vma) upper_insn, address);
3051 bfd_put_16 (abfd, (bfd_vma) lower_insn, address + 2);
3052 }
3053 else
3054 {
3055 bfd_vma contents;
3056
3057 contents = bfd_get_32 (abfd, address);
3058
3059 /* Get the (signed) value from the instruction. */
3060 addend = contents & howto->src_mask;
3061 if (addend & ((howto->src_mask + 1) >> 1))
3062 {
3063 bfd_signed_vma mask;
3064
3065 mask = -1;
3066 mask &= ~ howto->src_mask;
3067 addend |= mask;
3068 }
3069
3070 /* Add in the increment, (which is a byte value). */
3071 switch (howto->type)
3072 {
3073 default:
3074 addend += increment;
3075 break;
3076
3077 case R_ARM_PC24:
3078 #ifndef OLD_ARM_ABI
3079 case R_ARM_CALL:
3080 case R_ARM_JUMP24:
3081 #endif
3082 addend <<= howto->size;
3083 addend += increment;
3084
3085 /* Should we check for overflow here ? */
3086
3087 /* Drop any undesired bits. */
3088 addend >>= howto->rightshift;
3089 break;
3090 }
3091
3092 contents = (contents & ~ howto->dst_mask) | (addend & howto->dst_mask);
3093
3094 bfd_put_32 (abfd, contents, address);
3095 }
3096 }
3097
3098 /* Relocate an ARM ELF section. */
3099 static bfd_boolean
3100 elf32_arm_relocate_section (bfd * output_bfd,
3101 struct bfd_link_info * info,
3102 bfd * input_bfd,
3103 asection * input_section,
3104 bfd_byte * contents,
3105 Elf_Internal_Rela * relocs,
3106 Elf_Internal_Sym * local_syms,
3107 asection ** local_sections)
3108 {
3109 Elf_Internal_Shdr *symtab_hdr;
3110 struct elf_link_hash_entry **sym_hashes;
3111 Elf_Internal_Rela *rel;
3112 Elf_Internal_Rela *relend;
3113 const char *name;
3114 struct elf32_arm_link_hash_table * globals;
3115
3116 globals = elf32_arm_hash_table (info);
3117 if (info->relocatable && !globals->use_rel)
3118 return TRUE;
3119
3120 symtab_hdr = & elf_tdata (input_bfd)->symtab_hdr;
3121 sym_hashes = elf_sym_hashes (input_bfd);
3122
3123 rel = relocs;
3124 relend = relocs + input_section->reloc_count;
3125 for (; rel < relend; rel++)
3126 {
3127 int r_type;
3128 reloc_howto_type * howto;
3129 unsigned long r_symndx;
3130 Elf_Internal_Sym * sym;
3131 asection * sec;
3132 struct elf_link_hash_entry * h;
3133 bfd_vma relocation;
3134 bfd_reloc_status_type r;
3135 arelent bfd_reloc;
3136 bfd_boolean unresolved_reloc = FALSE;
3137
3138 r_symndx = ELF32_R_SYM (rel->r_info);
3139 r_type = ELF32_R_TYPE (rel->r_info);
3140 r_type = arm_real_reloc_type (globals, r_type);
3141
3142 if ( r_type == R_ARM_GNU_VTENTRY
3143 || r_type == R_ARM_GNU_VTINHERIT)
3144 continue;
3145
3146 bfd_reloc.howto = elf32_arm_howto_from_type (r_type);
3147 howto = bfd_reloc.howto;
3148
3149 if (info->relocatable && globals->use_rel)
3150 {
3151 /* This is a relocatable link. We don't have to change
3152 anything, unless the reloc is against a section symbol,
3153 in which case we have to adjust according to where the
3154 section symbol winds up in the output section. */
3155 if (r_symndx < symtab_hdr->sh_info)
3156 {
3157 sym = local_syms + r_symndx;
3158 if (ELF_ST_TYPE (sym->st_info) == STT_SECTION)
3159 {
3160 sec = local_sections[r_symndx];
3161 arm_add_to_rel (input_bfd, contents + rel->r_offset,
3162 howto,
3163 (bfd_signed_vma) (sec->output_offset
3164 + sym->st_value));
3165 }
3166 }
3167
3168 continue;
3169 }
3170
3171 /* This is a final link. */
3172 h = NULL;
3173 sym = NULL;
3174 sec = NULL;
3175
3176 if (r_symndx < symtab_hdr->sh_info)
3177 {
3178 sym = local_syms + r_symndx;
3179 sec = local_sections[r_symndx];
3180 if (globals->use_rel)
3181 {
3182 relocation = (sec->output_section->vma
3183 + sec->output_offset
3184 + sym->st_value);
3185 if ((sec->flags & SEC_MERGE)
3186 && ELF_ST_TYPE (sym->st_info) == STT_SECTION)
3187 {
3188 asection *msec;
3189 bfd_vma addend, value;
3190
3191 if (howto->rightshift)
3192 {
3193 (*_bfd_error_handler)
3194 (_("%B(%A+0x%lx): %s relocation against SEC_MERGE section"),
3195 input_bfd, input_section,
3196 (long) rel->r_offset, howto->name);
3197 return FALSE;
3198 }
3199
3200 value = bfd_get_32 (input_bfd, contents + rel->r_offset);
3201
3202 /* Get the (signed) value from the instruction. */
3203 addend = value & howto->src_mask;
3204 if (addend & ((howto->src_mask + 1) >> 1))
3205 {
3206 bfd_signed_vma mask;
3207
3208 mask = -1;
3209 mask &= ~ howto->src_mask;
3210 addend |= mask;
3211 }
3212 msec = sec;
3213 addend =
3214 _bfd_elf_rel_local_sym (output_bfd, sym, &msec, addend)
3215 - relocation;
3216 addend += msec->output_section->vma + msec->output_offset;
3217 value = (value & ~ howto->dst_mask) | (addend & howto->dst_mask);
3218 bfd_put_32 (input_bfd, value, contents + rel->r_offset);
3219 }
3220 }
3221 else
3222 relocation = _bfd_elf_rela_local_sym (output_bfd, sym, &sec, rel);
3223 }
3224 else
3225 {
3226 bfd_boolean warned;
3227
3228 RELOC_FOR_GLOBAL_SYMBOL (info, input_bfd, input_section, rel,
3229 r_symndx, symtab_hdr, sym_hashes,
3230 h, sec, relocation,
3231 unresolved_reloc, warned);
3232 }
3233
3234 if (h != NULL)
3235 name = h->root.root.string;
3236 else
3237 {
3238 name = (bfd_elf_string_from_elf_section
3239 (input_bfd, symtab_hdr->sh_link, sym->st_name));
3240 if (name == NULL || *name == '\0')
3241 name = bfd_section_name (input_bfd, sec);
3242 }
3243
3244 r = elf32_arm_final_link_relocate (howto, input_bfd, output_bfd,
3245 input_section, contents, rel,
3246 relocation, info, sec, name,
3247 (h ? ELF_ST_TYPE (h->type) :
3248 ELF_ST_TYPE (sym->st_info)), h,
3249 &unresolved_reloc);
3250
3251 /* Dynamic relocs are not propagated for SEC_DEBUGGING sections
3252 because such sections are not SEC_ALLOC and thus ld.so will
3253 not process them. */
3254 if (unresolved_reloc
3255 && !((input_section->flags & SEC_DEBUGGING) != 0
3256 && h->def_dynamic))
3257 {
3258 (*_bfd_error_handler)
3259 (_("%B(%A+0x%lx): warning: unresolvable relocation %d against symbol `%s'"),
3260 input_bfd, input_section, (long) rel->r_offset,
3261 r_type, h->root.root.string);
3262 return FALSE;
3263 }
3264
3265 if (r != bfd_reloc_ok)
3266 {
3267 const char * msg = (const char *) 0;
3268
3269 switch (r)
3270 {
3271 case bfd_reloc_overflow:
3272 /* If the overflowing reloc was to an undefined symbol,
3273 we have already printed one error message and there
3274 is no point complaining again. */
3275 if ((! h ||
3276 h->root.type != bfd_link_hash_undefined)
3277 && (!((*info->callbacks->reloc_overflow)
3278 (info, (h ? &h->root : NULL), name, howto->name,
3279 (bfd_vma) 0, input_bfd, input_section,
3280 rel->r_offset))))
3281 return FALSE;
3282 break;
3283
3284 case bfd_reloc_undefined:
3285 if (!((*info->callbacks->undefined_symbol)
3286 (info, name, input_bfd, input_section,
3287 rel->r_offset, TRUE)))
3288 return FALSE;
3289 break;
3290
3291 case bfd_reloc_outofrange:
3292 msg = _("internal error: out of range error");
3293 goto common_error;
3294
3295 case bfd_reloc_notsupported:
3296 msg = _("internal error: unsupported relocation error");
3297 goto common_error;
3298
3299 case bfd_reloc_dangerous:
3300 msg = _("internal error: dangerous error");
3301 goto common_error;
3302
3303 default:
3304 msg = _("internal error: unknown error");
3305 /* fall through */
3306
3307 common_error:
3308 if (!((*info->callbacks->warning)
3309 (info, msg, name, input_bfd, input_section,
3310 rel->r_offset)))
3311 return FALSE;
3312 break;
3313 }
3314 }
3315 }
3316
3317 return TRUE;
3318 }
3319
3320 /* Set the right machine number. */
3321
3322 static bfd_boolean
3323 elf32_arm_object_p (bfd *abfd)
3324 {
3325 unsigned int mach;
3326
3327 mach = bfd_arm_get_mach_from_notes (abfd, ARM_NOTE_SECTION);
3328
3329 if (mach != bfd_mach_arm_unknown)
3330 bfd_default_set_arch_mach (abfd, bfd_arch_arm, mach);
3331
3332 else if (elf_elfheader (abfd)->e_flags & EF_ARM_MAVERICK_FLOAT)
3333 bfd_default_set_arch_mach (abfd, bfd_arch_arm, bfd_mach_arm_ep9312);
3334
3335 else
3336 bfd_default_set_arch_mach (abfd, bfd_arch_arm, mach);
3337
3338 return TRUE;
3339 }
3340
3341 /* Function to keep ARM specific flags in the ELF header. */
3342
3343 static bfd_boolean
3344 elf32_arm_set_private_flags (bfd *abfd, flagword flags)
3345 {
3346 if (elf_flags_init (abfd)
3347 && elf_elfheader (abfd)->e_flags != flags)
3348 {
3349 if (EF_ARM_EABI_VERSION (flags) == EF_ARM_EABI_UNKNOWN)
3350 {
3351 if (flags & EF_ARM_INTERWORK)
3352 (*_bfd_error_handler)
3353 (_("Warning: Not setting interworking flag of %B since it has already been specified as non-interworking"),
3354 abfd);
3355 else
3356 _bfd_error_handler
3357 (_("Warning: Clearing the interworking flag of %B due to outside request"),
3358 abfd);
3359 }
3360 }
3361 else
3362 {
3363 elf_elfheader (abfd)->e_flags = flags;
3364 elf_flags_init (abfd) = TRUE;
3365 }
3366
3367 return TRUE;
3368 }
3369
3370 /* Copy backend specific data from one object module to another. */
3371
3372 static bfd_boolean
3373 elf32_arm_copy_private_bfd_data (bfd *ibfd, bfd *obfd)
3374 {
3375 flagword in_flags;
3376 flagword out_flags;
3377
3378 if ( bfd_get_flavour (ibfd) != bfd_target_elf_flavour
3379 || bfd_get_flavour (obfd) != bfd_target_elf_flavour)
3380 return TRUE;
3381
3382 in_flags = elf_elfheader (ibfd)->e_flags;
3383 out_flags = elf_elfheader (obfd)->e_flags;
3384
3385 if (elf_flags_init (obfd)
3386 && EF_ARM_EABI_VERSION (out_flags) == EF_ARM_EABI_UNKNOWN
3387 && in_flags != out_flags)
3388 {
3389 /* Cannot mix APCS26 and APCS32 code. */
3390 if ((in_flags & EF_ARM_APCS_26) != (out_flags & EF_ARM_APCS_26))
3391 return FALSE;
3392
3393 /* Cannot mix float APCS and non-float APCS code. */
3394 if ((in_flags & EF_ARM_APCS_FLOAT) != (out_flags & EF_ARM_APCS_FLOAT))
3395 return FALSE;
3396
3397 /* If the src and dest have different interworking flags
3398 then turn off the interworking bit. */
3399 if ((in_flags & EF_ARM_INTERWORK) != (out_flags & EF_ARM_INTERWORK))
3400 {
3401 if (out_flags & EF_ARM_INTERWORK)
3402 _bfd_error_handler
3403 (_("Warning: Clearing the interworking flag of %B because non-interworking code in %B has been linked with it"),
3404 obfd, ibfd);
3405
3406 in_flags &= ~EF_ARM_INTERWORK;
3407 }
3408
3409 /* Likewise for PIC, though don't warn for this case. */
3410 if ((in_flags & EF_ARM_PIC) != (out_flags & EF_ARM_PIC))
3411 in_flags &= ~EF_ARM_PIC;
3412 }
3413
3414 elf_elfheader (obfd)->e_flags = in_flags;
3415 elf_flags_init (obfd) = TRUE;
3416
3417 /* Also copy the EI_OSABI field. */
3418 elf_elfheader (obfd)->e_ident[EI_OSABI] =
3419 elf_elfheader (ibfd)->e_ident[EI_OSABI];
3420
3421 return TRUE;
3422 }
3423
3424 /* Merge backend specific data from an object file to the output
3425 object file when linking. */
3426
3427 static bfd_boolean
3428 elf32_arm_merge_private_bfd_data (bfd * ibfd, bfd * obfd)
3429 {
3430 flagword out_flags;
3431 flagword in_flags;
3432 bfd_boolean flags_compatible = TRUE;
3433 asection *sec;
3434
3435 /* Check if we have the same endianess. */
3436 if (! _bfd_generic_verify_endian_match (ibfd, obfd))
3437 return FALSE;
3438
3439 if ( bfd_get_flavour (ibfd) != bfd_target_elf_flavour
3440 || bfd_get_flavour (obfd) != bfd_target_elf_flavour)
3441 return TRUE;
3442
3443 /* The input BFD must have had its flags initialised. */
3444 /* The following seems bogus to me -- The flags are initialized in
3445 the assembler but I don't think an elf_flags_init field is
3446 written into the object. */
3447 /* BFD_ASSERT (elf_flags_init (ibfd)); */
3448
3449 in_flags = elf_elfheader (ibfd)->e_flags;
3450 out_flags = elf_elfheader (obfd)->e_flags;
3451
3452 if (!elf_flags_init (obfd))
3453 {
3454 /* If the input is the default architecture and had the default
3455 flags then do not bother setting the flags for the output
3456 architecture, instead allow future merges to do this. If no
3457 future merges ever set these flags then they will retain their
3458 uninitialised values, which surprise surprise, correspond
3459 to the default values. */
3460 if (bfd_get_arch_info (ibfd)->the_default
3461 && elf_elfheader (ibfd)->e_flags == 0)
3462 return TRUE;
3463
3464 elf_flags_init (obfd) = TRUE;
3465 elf_elfheader (obfd)->e_flags = in_flags;
3466
3467 if (bfd_get_arch (obfd) == bfd_get_arch (ibfd)
3468 && bfd_get_arch_info (obfd)->the_default)
3469 return bfd_set_arch_mach (obfd, bfd_get_arch (ibfd), bfd_get_mach (ibfd));
3470
3471 return TRUE;
3472 }
3473
3474 /* Determine what should happen if the input ARM architecture
3475 does not match the output ARM architecture. */
3476 if (! bfd_arm_merge_machines (ibfd, obfd))
3477 return FALSE;
3478
3479 /* Identical flags must be compatible. */
3480 if (in_flags == out_flags)
3481 return TRUE;
3482
3483 /* Check to see if the input BFD actually contains any sections. If
3484 not, its flags may not have been initialised either, but it
3485 cannot actually cause any incompatibility. Do not short-circuit
3486 dynamic objects; their section list may be emptied by
3487 elf_link_add_object_symbols.
3488
3489 Also check to see if there are no code sections in the input.
3490 In this case there is no need to check for code specific flags.
3491 XXX - do we need to worry about floating-point format compatability
3492 in data sections ? */
3493 if (!(ibfd->flags & DYNAMIC))
3494 {
3495 bfd_boolean null_input_bfd = TRUE;
3496 bfd_boolean only_data_sections = TRUE;
3497
3498 for (sec = ibfd->sections; sec != NULL; sec = sec->next)
3499 {
3500 /* Ignore synthetic glue sections. */
3501 if (strcmp (sec->name, ".glue_7")
3502 && strcmp (sec->name, ".glue_7t"))
3503 {
3504 if ((bfd_get_section_flags (ibfd, sec)
3505 & (SEC_LOAD | SEC_CODE | SEC_HAS_CONTENTS))
3506 == (SEC_LOAD | SEC_CODE | SEC_HAS_CONTENTS))
3507 only_data_sections = FALSE;
3508
3509 null_input_bfd = FALSE;
3510 break;
3511 }
3512 }
3513
3514 if (null_input_bfd || only_data_sections)
3515 return TRUE;
3516 }
3517
3518 /* Complain about various flag mismatches. */
3519 if (EF_ARM_EABI_VERSION (in_flags) != EF_ARM_EABI_VERSION (out_flags))
3520 {
3521 _bfd_error_handler
3522 (_("ERROR: Source object %B has EABI version %d, but target %B has EABI version %d"),
3523 ibfd, obfd,
3524 (in_flags & EF_ARM_EABIMASK) >> 24,
3525 (out_flags & EF_ARM_EABIMASK) >> 24);
3526 return FALSE;
3527 }
3528
3529 /* Not sure what needs to be checked for EABI versions >= 1. */
3530 if (EF_ARM_EABI_VERSION (in_flags) == EF_ARM_EABI_UNKNOWN)
3531 {
3532 if ((in_flags & EF_ARM_APCS_26) != (out_flags & EF_ARM_APCS_26))
3533 {
3534 _bfd_error_handler
3535 (_("ERROR: %B is compiled for APCS-%d, whereas target %B uses APCS-%d"),
3536 ibfd, obfd,
3537 in_flags & EF_ARM_APCS_26 ? 26 : 32,
3538 out_flags & EF_ARM_APCS_26 ? 26 : 32);
3539 flags_compatible = FALSE;
3540 }
3541
3542 if ((in_flags & EF_ARM_APCS_FLOAT) != (out_flags & EF_ARM_APCS_FLOAT))
3543 {
3544 if (in_flags & EF_ARM_APCS_FLOAT)
3545 _bfd_error_handler
3546 (_("ERROR: %B passes floats in float registers, whereas %B passes them in integer registers"),
3547 ibfd, obfd);
3548 else
3549 _bfd_error_handler
3550 (_("ERROR: %B passes floats in integer registers, whereas %B passes them in float registers"),
3551 ibfd, obfd);
3552
3553 flags_compatible = FALSE;
3554 }
3555
3556 if ((in_flags & EF_ARM_VFP_FLOAT) != (out_flags & EF_ARM_VFP_FLOAT))
3557 {
3558 if (in_flags & EF_ARM_VFP_FLOAT)
3559 _bfd_error_handler
3560 (_("ERROR: %B uses VFP instructions, whereas %B does not"),
3561 ibfd, obfd);
3562 else
3563 _bfd_error_handler
3564 (_("ERROR: %B uses FPA instructions, whereas %B does not"),
3565 ibfd, obfd);
3566
3567 flags_compatible = FALSE;
3568 }
3569
3570 if ((in_flags & EF_ARM_MAVERICK_FLOAT) != (out_flags & EF_ARM_MAVERICK_FLOAT))
3571 {
3572 if (in_flags & EF_ARM_MAVERICK_FLOAT)
3573 _bfd_error_handler
3574 (_("ERROR: %B uses Maverick instructions, whereas %B does not"),
3575 ibfd, obfd);
3576 else
3577 _bfd_error_handler
3578 (_("ERROR: %B does not use Maverick instructions, whereas %B does"),
3579 ibfd, obfd);
3580
3581 flags_compatible = FALSE;
3582 }
3583
3584 #ifdef EF_ARM_SOFT_FLOAT
3585 if ((in_flags & EF_ARM_SOFT_FLOAT) != (out_flags & EF_ARM_SOFT_FLOAT))
3586 {
3587 /* We can allow interworking between code that is VFP format
3588 layout, and uses either soft float or integer regs for
3589 passing floating point arguments and results. We already
3590 know that the APCS_FLOAT flags match; similarly for VFP
3591 flags. */
3592 if ((in_flags & EF_ARM_APCS_FLOAT) != 0
3593 || (in_flags & EF_ARM_VFP_FLOAT) == 0)
3594 {
3595 if (in_flags & EF_ARM_SOFT_FLOAT)
3596 _bfd_error_handler
3597 (_("ERROR: %B uses software FP, whereas %B uses hardware FP"),
3598 ibfd, obfd);
3599 else
3600 _bfd_error_handler
3601 (_("ERROR: %B uses hardware FP, whereas %B uses software FP"),
3602 ibfd, obfd);
3603
3604 flags_compatible = FALSE;
3605 }
3606 }
3607 #endif
3608
3609 /* Interworking mismatch is only a warning. */
3610 if ((in_flags & EF_ARM_INTERWORK) != (out_flags & EF_ARM_INTERWORK))
3611 {
3612 if (in_flags & EF_ARM_INTERWORK)
3613 {
3614 _bfd_error_handler
3615 (_("Warning: %B supports interworking, whereas %B does not"),
3616 ibfd, obfd);
3617 }
3618 else
3619 {
3620 _bfd_error_handler
3621 (_("Warning: %B does not support interworking, whereas %B does"),
3622 ibfd, obfd);
3623 }
3624 }
3625 }
3626
3627 return flags_compatible;
3628 }
3629
3630 /* Display the flags field. */
3631
3632 static bfd_boolean
3633 elf32_arm_print_private_bfd_data (bfd *abfd, void * ptr)
3634 {
3635 FILE * file = (FILE *) ptr;
3636 unsigned long flags;
3637
3638 BFD_ASSERT (abfd != NULL && ptr != NULL);
3639
3640 /* Print normal ELF private data. */
3641 _bfd_elf_print_private_bfd_data (abfd, ptr);
3642
3643 flags = elf_elfheader (abfd)->e_flags;
3644 /* Ignore init flag - it may not be set, despite the flags field
3645 containing valid data. */
3646
3647 /* xgettext:c-format */
3648 fprintf (file, _("private flags = %lx:"), elf_elfheader (abfd)->e_flags);
3649
3650 switch (EF_ARM_EABI_VERSION (flags))
3651 {
3652 case EF_ARM_EABI_UNKNOWN:
3653 /* The following flag bits are GNU extensions and not part of the
3654 official ARM ELF extended ABI. Hence they are only decoded if
3655 the EABI version is not set. */
3656 if (flags & EF_ARM_INTERWORK)
3657 fprintf (file, _(" [interworking enabled]"));
3658
3659 if (flags & EF_ARM_APCS_26)
3660 fprintf (file, " [APCS-26]");
3661 else
3662 fprintf (file, " [APCS-32]");
3663
3664 if (flags & EF_ARM_VFP_FLOAT)
3665 fprintf (file, _(" [VFP float format]"));
3666 else if (flags & EF_ARM_MAVERICK_FLOAT)
3667 fprintf (file, _(" [Maverick float format]"));
3668 else
3669 fprintf (file, _(" [FPA float format]"));
3670
3671 if (flags & EF_ARM_APCS_FLOAT)
3672 fprintf (file, _(" [floats passed in float registers]"));
3673
3674 if (flags & EF_ARM_PIC)
3675 fprintf (file, _(" [position independent]"));
3676
3677 if (flags & EF_ARM_NEW_ABI)
3678 fprintf (file, _(" [new ABI]"));
3679
3680 if (flags & EF_ARM_OLD_ABI)
3681 fprintf (file, _(" [old ABI]"));
3682
3683 if (flags & EF_ARM_SOFT_FLOAT)
3684 fprintf (file, _(" [software FP]"));
3685
3686 flags &= ~(EF_ARM_INTERWORK | EF_ARM_APCS_26 | EF_ARM_APCS_FLOAT
3687 | EF_ARM_PIC | EF_ARM_NEW_ABI | EF_ARM_OLD_ABI
3688 | EF_ARM_SOFT_FLOAT | EF_ARM_VFP_FLOAT
3689 | EF_ARM_MAVERICK_FLOAT);
3690 break;
3691
3692 case EF_ARM_EABI_VER1:
3693 fprintf (file, _(" [Version1 EABI]"));
3694
3695 if (flags & EF_ARM_SYMSARESORTED)
3696 fprintf (file, _(" [sorted symbol table]"));
3697 else
3698 fprintf (file, _(" [unsorted symbol table]"));
3699
3700 flags &= ~ EF_ARM_SYMSARESORTED;
3701 break;
3702
3703 case EF_ARM_EABI_VER2:
3704 fprintf (file, _(" [Version2 EABI]"));
3705
3706 if (flags & EF_ARM_SYMSARESORTED)
3707 fprintf (file, _(" [sorted symbol table]"));
3708 else
3709 fprintf (file, _(" [unsorted symbol table]"));
3710
3711 if (flags & EF_ARM_DYNSYMSUSESEGIDX)
3712 fprintf (file, _(" [dynamic symbols use segment index]"));
3713
3714 if (flags & EF_ARM_MAPSYMSFIRST)
3715 fprintf (file, _(" [mapping symbols precede others]"));
3716
3717 flags &= ~(EF_ARM_SYMSARESORTED | EF_ARM_DYNSYMSUSESEGIDX
3718 | EF_ARM_MAPSYMSFIRST);
3719 break;
3720
3721 case EF_ARM_EABI_VER3:
3722 fprintf (file, _(" [Version3 EABI]"));
3723 break;
3724
3725 case EF_ARM_EABI_VER4:
3726 fprintf (file, _(" [Version4 EABI]"));
3727
3728 if (flags & EF_ARM_BE8)
3729 fprintf (file, _(" [BE8]"));
3730
3731 if (flags & EF_ARM_LE8)
3732 fprintf (file, _(" [LE8]"));
3733
3734 flags &= ~(EF_ARM_LE8 | EF_ARM_BE8);
3735 break;
3736
3737 default:
3738 fprintf (file, _(" <EABI version unrecognised>"));
3739 break;
3740 }
3741
3742 flags &= ~ EF_ARM_EABIMASK;
3743
3744 if (flags & EF_ARM_RELEXEC)
3745 fprintf (file, _(" [relocatable executable]"));
3746
3747 if (flags & EF_ARM_HASENTRY)
3748 fprintf (file, _(" [has entry point]"));
3749
3750 flags &= ~ (EF_ARM_RELEXEC | EF_ARM_HASENTRY);
3751
3752 if (flags)
3753 fprintf (file, _("<Unrecognised flag bits set>"));
3754
3755 fputc ('\n', file);
3756
3757 return TRUE;
3758 }
3759
3760 static int
3761 elf32_arm_get_symbol_type (Elf_Internal_Sym * elf_sym, int type)
3762 {
3763 switch (ELF_ST_TYPE (elf_sym->st_info))
3764 {
3765 case STT_ARM_TFUNC:
3766 return ELF_ST_TYPE (elf_sym->st_info);
3767
3768 case STT_ARM_16BIT:
3769 /* If the symbol is not an object, return the STT_ARM_16BIT flag.
3770 This allows us to distinguish between data used by Thumb instructions
3771 and non-data (which is probably code) inside Thumb regions of an
3772 executable. */
3773 if (type != STT_OBJECT)
3774 return ELF_ST_TYPE (elf_sym->st_info);
3775 break;
3776
3777 default:
3778 break;
3779 }
3780
3781 return type;
3782 }
3783
3784 static asection *
3785 elf32_arm_gc_mark_hook (asection * sec,
3786 struct bfd_link_info * info ATTRIBUTE_UNUSED,
3787 Elf_Internal_Rela * rel,
3788 struct elf_link_hash_entry * h,
3789 Elf_Internal_Sym * sym)
3790 {
3791 if (h != NULL)
3792 {
3793 switch (ELF32_R_TYPE (rel->r_info))
3794 {
3795 case R_ARM_GNU_VTINHERIT:
3796 case R_ARM_GNU_VTENTRY:
3797 break;
3798
3799 default:
3800 switch (h->root.type)
3801 {
3802 case bfd_link_hash_defined:
3803 case bfd_link_hash_defweak:
3804 return h->root.u.def.section;
3805
3806 case bfd_link_hash_common:
3807 return h->root.u.c.p->section;
3808
3809 default:
3810 break;
3811 }
3812 }
3813 }
3814 else
3815 return bfd_section_from_elf_index (sec->owner, sym->st_shndx);
3816
3817 return NULL;
3818 }
3819
3820 /* Update the got entry reference counts for the section being removed. */
3821
3822 static bfd_boolean
3823 elf32_arm_gc_sweep_hook (bfd * abfd ATTRIBUTE_UNUSED,
3824 struct bfd_link_info * info ATTRIBUTE_UNUSED,
3825 asection * sec ATTRIBUTE_UNUSED,
3826 const Elf_Internal_Rela * relocs ATTRIBUTE_UNUSED)
3827 {
3828 Elf_Internal_Shdr *symtab_hdr;
3829 struct elf_link_hash_entry **sym_hashes;
3830 bfd_signed_vma *local_got_refcounts;
3831 const Elf_Internal_Rela *rel, *relend;
3832 struct elf32_arm_link_hash_table * globals;
3833
3834 globals = elf32_arm_hash_table (info);
3835
3836 elf_section_data (sec)->local_dynrel = NULL;
3837
3838 symtab_hdr = &elf_tdata (abfd)->symtab_hdr;
3839 sym_hashes = elf_sym_hashes (abfd);
3840 local_got_refcounts = elf_local_got_refcounts (abfd);
3841
3842 relend = relocs + sec->reloc_count;
3843 for (rel = relocs; rel < relend; rel++)
3844 {
3845 unsigned long r_symndx;
3846 struct elf_link_hash_entry *h = NULL;
3847 int r_type;
3848
3849 r_symndx = ELF32_R_SYM (rel->r_info);
3850 if (r_symndx >= symtab_hdr->sh_info)
3851 {
3852 h = sym_hashes[r_symndx - symtab_hdr->sh_info];
3853 while (h->root.type == bfd_link_hash_indirect
3854 || h->root.type == bfd_link_hash_warning)
3855 h = (struct elf_link_hash_entry *) h->root.u.i.link;
3856 }
3857
3858 r_type = ELF32_R_TYPE (rel->r_info);
3859 #ifndef OLD_ARM_ABI
3860 r_type = arm_real_reloc_type (globals, r_type);
3861 #endif
3862 switch (r_type)
3863 {
3864 case R_ARM_GOT32:
3865 #ifndef OLD_ARM_ABI
3866 case R_ARM_GOT_PREL:
3867 #endif
3868 if (h != NULL)
3869 {
3870 if (h->got.refcount > 0)
3871 h->got.refcount -= 1;
3872 }
3873 else if (local_got_refcounts != NULL)
3874 {
3875 if (local_got_refcounts[r_symndx] > 0)
3876 local_got_refcounts[r_symndx] -= 1;
3877 }
3878 break;
3879
3880 case R_ARM_ABS32:
3881 case R_ARM_REL32:
3882 case R_ARM_PC24:
3883 case R_ARM_PLT32:
3884 #ifndef OLD_ARM_ABI
3885 case R_ARM_CALL:
3886 case R_ARM_JUMP24:
3887 case R_ARM_PREL31:
3888 #endif
3889 case R_ARM_THM_PC22:
3890 /* Should the interworking branches be here also? */
3891
3892 if (h != NULL)
3893 {
3894 struct elf32_arm_link_hash_entry *eh;
3895 struct elf32_arm_relocs_copied **pp;
3896 struct elf32_arm_relocs_copied *p;
3897
3898 eh = (struct elf32_arm_link_hash_entry *) h;
3899
3900 if (h->plt.refcount > 0)
3901 {
3902 h->plt.refcount -= 1;
3903 if (ELF32_R_TYPE (rel->r_info) == R_ARM_THM_PC22)
3904 eh->plt_thumb_refcount--;
3905 }
3906
3907 if (r_type == R_ARM_ABS32
3908 || r_type == R_ARM_REL32)
3909 {
3910 for (pp = &eh->relocs_copied; (p = *pp) != NULL;
3911 pp = &p->next)
3912 if (p->section == sec)
3913 {
3914 p->count -= 1;
3915 if (p->count == 0)
3916 *pp = p->next;
3917 break;
3918 }
3919 }
3920 }
3921 break;
3922
3923 default:
3924 break;
3925 }
3926 }
3927
3928 return TRUE;
3929 }
3930
3931 /* Look through the relocs for a section during the first phase. */
3932
3933 static bfd_boolean
3934 elf32_arm_check_relocs (bfd *abfd, struct bfd_link_info *info,
3935 asection *sec, const Elf_Internal_Rela *relocs)
3936 {
3937 Elf_Internal_Shdr *symtab_hdr;
3938 struct elf_link_hash_entry **sym_hashes;
3939 struct elf_link_hash_entry **sym_hashes_end;
3940 const Elf_Internal_Rela *rel;
3941 const Elf_Internal_Rela *rel_end;
3942 bfd *dynobj;
3943 asection *sreloc;
3944 bfd_vma *local_got_offsets;
3945 struct elf32_arm_link_hash_table *htab;
3946
3947 if (info->relocatable)
3948 return TRUE;
3949
3950 htab = elf32_arm_hash_table (info);
3951 sreloc = NULL;
3952
3953 /* Create dynamic sections for relocatable executables so that we can
3954 copy relocations. */
3955 if (htab->root.is_relocatable_executable
3956 && ! htab->root.dynamic_sections_created)
3957 {
3958 if (! _bfd_elf_link_create_dynamic_sections (abfd, info))
3959 return FALSE;
3960 }
3961
3962 dynobj = elf_hash_table (info)->dynobj;
3963 local_got_offsets = elf_local_got_offsets (abfd);
3964
3965 symtab_hdr = &elf_tdata (abfd)->symtab_hdr;
3966 sym_hashes = elf_sym_hashes (abfd);
3967 sym_hashes_end = sym_hashes
3968 + symtab_hdr->sh_size / sizeof (Elf32_External_Sym);
3969
3970 if (!elf_bad_symtab (abfd))
3971 sym_hashes_end -= symtab_hdr->sh_info;
3972
3973 rel_end = relocs + sec->reloc_count;
3974 for (rel = relocs; rel < rel_end; rel++)
3975 {
3976 struct elf_link_hash_entry *h;
3977 struct elf32_arm_link_hash_entry *eh;
3978 unsigned long r_symndx;
3979 int r_type;
3980
3981 r_symndx = ELF32_R_SYM (rel->r_info);
3982 r_type = ELF32_R_TYPE (rel->r_info);
3983 #ifndef OLD_ARM_ABI
3984 r_type = arm_real_reloc_type (htab, r_type);
3985 #endif
3986 if (r_symndx < symtab_hdr->sh_info)
3987 h = NULL;
3988 else
3989 h = sym_hashes[r_symndx - symtab_hdr->sh_info];
3990
3991 eh = (struct elf32_arm_link_hash_entry *) h;
3992
3993 switch (r_type)
3994 {
3995 case R_ARM_GOT32:
3996 #ifndef OLD_ARM_ABI
3997 case R_ARM_GOT_PREL:
3998 #endif
3999 /* This symbol requires a global offset table entry. */
4000 if (h != NULL)
4001 {
4002 h->got.refcount++;
4003 }
4004 else
4005 {
4006 bfd_signed_vma *local_got_refcounts;
4007
4008 /* This is a global offset table entry for a local symbol. */
4009 local_got_refcounts = elf_local_got_refcounts (abfd);
4010 if (local_got_refcounts == NULL)
4011 {
4012 bfd_size_type size;
4013
4014 size = symtab_hdr->sh_info;
4015 size *= (sizeof (bfd_signed_vma) + sizeof (char));
4016 local_got_refcounts = bfd_zalloc (abfd, size);
4017 if (local_got_refcounts == NULL)
4018 return FALSE;
4019 elf_local_got_refcounts (abfd) = local_got_refcounts;
4020 }
4021 local_got_refcounts[r_symndx] += 1;
4022 }
4023 if (r_type == R_ARM_GOT32)
4024 break;
4025 /* Fall through. */
4026
4027 case R_ARM_GOTOFF:
4028 case R_ARM_GOTPC:
4029 if (htab->sgot == NULL)
4030 {
4031 if (htab->root.dynobj == NULL)
4032 htab->root.dynobj = abfd;
4033 if (!create_got_section (htab->root.dynobj, info))
4034 return FALSE;
4035 }
4036 break;
4037
4038 case R_ARM_ABS32:
4039 case R_ARM_REL32:
4040 case R_ARM_PC24:
4041 case R_ARM_PLT32:
4042 #ifndef OLD_ARM_ABI
4043 case R_ARM_CALL:
4044 case R_ARM_JUMP24:
4045 case R_ARM_PREL31:
4046 #endif
4047 case R_ARM_THM_PC22:
4048 /* Should the interworking branches be listed here? */
4049 if (h != NULL)
4050 {
4051 /* If this reloc is in a read-only section, we might
4052 need a copy reloc. We can't check reliably at this
4053 stage whether the section is read-only, as input
4054 sections have not yet been mapped to output sections.
4055 Tentatively set the flag for now, and correct in
4056 adjust_dynamic_symbol. */
4057 if (!info->shared)
4058 h->non_got_ref = 1;
4059
4060 /* We may need a .plt entry if the function this reloc
4061 refers to is in a different object. We can't tell for
4062 sure yet, because something later might force the
4063 symbol local. */
4064 if (r_type == R_ARM_PC24
4065 #ifndef OLD_ARM_ABI
4066 || r_type == R_ARM_CALL
4067 || r_type == R_ARM_JUMP24
4068 || r_type == R_ARM_PREL31
4069 #endif
4070 || r_type == R_ARM_PLT32
4071 || r_type == R_ARM_THM_PC22)
4072 h->needs_plt = 1;
4073
4074 /* If we create a PLT entry, this relocation will reference
4075 it, even if it's an ABS32 relocation. */
4076 h->plt.refcount += 1;
4077
4078 if (r_type == R_ARM_THM_PC22)
4079 eh->plt_thumb_refcount += 1;
4080 }
4081
4082 /* If we are creating a shared library or relocatable executable,
4083 and this is a reloc against a global symbol, or a non PC
4084 relative reloc against a local symbol, then we need to copy
4085 the reloc into the shared library. However, if we are linking
4086 with -Bsymbolic, we do not need to copy a reloc against a
4087 global symbol which is defined in an object we are
4088 including in the link (i.e., DEF_REGULAR is set). At
4089 this point we have not seen all the input files, so it is
4090 possible that DEF_REGULAR is not set now but will be set
4091 later (it is never cleared). We account for that
4092 possibility below by storing information in the
4093 relocs_copied field of the hash table entry. */
4094 if ((info->shared || htab->root.is_relocatable_executable)
4095 && (sec->flags & SEC_ALLOC) != 0
4096 && ((r_type != R_ARM_PC24
4097 && r_type != R_ARM_PLT32
4098 #ifndef OLD_ARM_ABI
4099 && r_type != R_ARM_CALL
4100 && r_type != R_ARM_JUMP24
4101 && r_type != R_ARM_PREL31
4102 #endif
4103 && r_type != R_ARM_REL32
4104 && r_type != R_ARM_THM_PC22)
4105 || (h != NULL
4106 && (! info->symbolic
4107 || !h->def_regular))))
4108 {
4109 struct elf32_arm_relocs_copied *p, **head;
4110
4111 /* When creating a shared object, we must copy these
4112 reloc types into the output file. We create a reloc
4113 section in dynobj and make room for this reloc. */
4114 if (sreloc == NULL)
4115 {
4116 const char * name;
4117
4118 name = (bfd_elf_string_from_elf_section
4119 (abfd,
4120 elf_elfheader (abfd)->e_shstrndx,
4121 elf_section_data (sec)->rel_hdr.sh_name));
4122 if (name == NULL)
4123 return FALSE;
4124
4125 BFD_ASSERT (strncmp (name, ".rel", 4) == 0
4126 && strcmp (bfd_get_section_name (abfd, sec),
4127 name + 4) == 0);
4128
4129 sreloc = bfd_get_section_by_name (dynobj, name);
4130 if (sreloc == NULL)
4131 {
4132 flagword flags;
4133
4134 sreloc = bfd_make_section (dynobj, name);
4135 flags = (SEC_HAS_CONTENTS | SEC_READONLY
4136 | SEC_IN_MEMORY | SEC_LINKER_CREATED);
4137 if ((sec->flags & SEC_ALLOC) != 0
4138 /* BPABI objects never have dynamic
4139 relocations mapped. */
4140 && !htab->symbian_p)
4141 flags |= SEC_ALLOC | SEC_LOAD;
4142 if (sreloc == NULL
4143 || ! bfd_set_section_flags (dynobj, sreloc, flags)
4144 || ! bfd_set_section_alignment (dynobj, sreloc, 2))
4145 return FALSE;
4146 }
4147
4148 elf_section_data (sec)->sreloc = sreloc;
4149 }
4150
4151 /* If this is a global symbol, we count the number of
4152 relocations we need for this symbol. */
4153 if (h != NULL)
4154 {
4155 head = &((struct elf32_arm_link_hash_entry *) h)->relocs_copied;
4156 }
4157 else
4158 {
4159 /* Track dynamic relocs needed for local syms too.
4160 We really need local syms available to do this
4161 easily. Oh well. */
4162
4163 asection *s;
4164 s = bfd_section_from_r_symndx (abfd, &htab->sym_sec,
4165 sec, r_symndx);
4166 if (s == NULL)
4167 return FALSE;
4168
4169 head = ((struct elf32_arm_relocs_copied **)
4170 &elf_section_data (s)->local_dynrel);
4171 }
4172
4173 p = *head;
4174 if (p == NULL || p->section != sec)
4175 {
4176 bfd_size_type amt = sizeof *p;
4177
4178 p = bfd_alloc (htab->root.dynobj, amt);
4179 if (p == NULL)
4180 return FALSE;
4181 p->next = *head;
4182 *head = p;
4183 p->section = sec;
4184 p->count = 0;
4185 }
4186
4187 if (r_type == R_ARM_ABS32
4188 || r_type == R_ARM_REL32)
4189 p->count += 1;
4190 }
4191 break;
4192
4193 /* This relocation describes the C++ object vtable hierarchy.
4194 Reconstruct it for later use during GC. */
4195 case R_ARM_GNU_VTINHERIT:
4196 if (!bfd_elf_gc_record_vtinherit (abfd, sec, h, rel->r_offset))
4197 return FALSE;
4198 break;
4199
4200 /* This relocation describes which C++ vtable entries are actually
4201 used. Record for later use during GC. */
4202 case R_ARM_GNU_VTENTRY:
4203 if (!bfd_elf_gc_record_vtentry (abfd, sec, h, rel->r_offset))
4204 return FALSE;
4205 break;
4206 }
4207 }
4208
4209 return TRUE;
4210 }
4211
4212 static bfd_boolean
4213 is_arm_mapping_symbol_name (const char * name)
4214 {
4215 return (name != NULL)
4216 && (name[0] == '$')
4217 && ((name[1] == 'a') || (name[1] == 't') || (name[1] == 'd'))
4218 && (name[2] == 0);
4219 }
4220
4221 /* Treat mapping symbols as special target symbols. */
4222
4223 static bfd_boolean
4224 elf32_arm_is_target_special_symbol (bfd * abfd ATTRIBUTE_UNUSED, asymbol * sym)
4225 {
4226 return is_arm_mapping_symbol_name (sym->name);
4227 }
4228
4229 /* This is a copy of elf_find_function() from elf.c except that
4230 ARM mapping symbols are ignored when looking for function names
4231 and STT_ARM_TFUNC is considered to a function type. */
4232
4233 static bfd_boolean
4234 arm_elf_find_function (bfd * abfd ATTRIBUTE_UNUSED,
4235 asection * section,
4236 asymbol ** symbols,
4237 bfd_vma offset,
4238 const char ** filename_ptr,
4239 const char ** functionname_ptr)
4240 {
4241 const char * filename = NULL;
4242 asymbol * func = NULL;
4243 bfd_vma low_func = 0;
4244 asymbol ** p;
4245
4246 for (p = symbols; *p != NULL; p++)
4247 {
4248 elf_symbol_type *q;
4249
4250 q = (elf_symbol_type *) *p;
4251
4252 switch (ELF_ST_TYPE (q->internal_elf_sym.st_info))
4253 {
4254 default:
4255 break;
4256 case STT_FILE:
4257 filename = bfd_asymbol_name (&q->symbol);
4258 break;
4259 case STT_FUNC:
4260 case STT_ARM_TFUNC:
4261 /* Skip $a and $t symbols. */
4262 if ((q->symbol.flags & BSF_LOCAL)
4263 && is_arm_mapping_symbol_name (q->symbol.name))
4264 continue;
4265 /* Fall through. */
4266 case STT_NOTYPE:
4267 if (bfd_get_section (&q->symbol) == section
4268 && q->symbol.value >= low_func
4269 && q->symbol.value <= offset)
4270 {
4271 func = (asymbol *) q;
4272 low_func = q->symbol.value;
4273 }
4274 break;
4275 }
4276 }
4277
4278 if (func == NULL)
4279 return FALSE;
4280
4281 if (filename_ptr)
4282 *filename_ptr = filename;
4283 if (functionname_ptr)
4284 *functionname_ptr = bfd_asymbol_name (func);
4285
4286 return TRUE;
4287 }
4288
4289
4290 /* Find the nearest line to a particular section and offset, for error
4291 reporting. This code is a duplicate of the code in elf.c, except
4292 that it uses arm_elf_find_function. */
4293
4294 static bfd_boolean
4295 elf32_arm_find_nearest_line (bfd * abfd,
4296 asection * section,
4297 asymbol ** symbols,
4298 bfd_vma offset,
4299 const char ** filename_ptr,
4300 const char ** functionname_ptr,
4301 unsigned int * line_ptr)
4302 {
4303 bfd_boolean found = FALSE;
4304
4305 /* We skip _bfd_dwarf1_find_nearest_line since no known ARM toolchain uses it. */
4306
4307 if (_bfd_dwarf2_find_nearest_line (abfd, section, symbols, offset,
4308 filename_ptr, functionname_ptr,
4309 line_ptr, 0,
4310 & elf_tdata (abfd)->dwarf2_find_line_info))
4311 {
4312 if (!*functionname_ptr)
4313 arm_elf_find_function (abfd, section, symbols, offset,
4314 *filename_ptr ? NULL : filename_ptr,
4315 functionname_ptr);
4316
4317 return TRUE;
4318 }
4319
4320 if (! _bfd_stab_section_find_nearest_line (abfd, symbols, section, offset,
4321 & found, filename_ptr,
4322 functionname_ptr, line_ptr,
4323 & elf_tdata (abfd)->line_info))
4324 return FALSE;
4325
4326 if (found && (*functionname_ptr || *line_ptr))
4327 return TRUE;
4328
4329 if (symbols == NULL)
4330 return FALSE;
4331
4332 if (! arm_elf_find_function (abfd, section, symbols, offset,
4333 filename_ptr, functionname_ptr))
4334 return FALSE;
4335
4336 *line_ptr = 0;
4337 return TRUE;
4338 }
4339
4340 /* Adjust a symbol defined by a dynamic object and referenced by a
4341 regular object. The current definition is in some section of the
4342 dynamic object, but we're not including those sections. We have to
4343 change the definition to something the rest of the link can
4344 understand. */
4345
4346 static bfd_boolean
4347 elf32_arm_adjust_dynamic_symbol (struct bfd_link_info * info,
4348 struct elf_link_hash_entry * h)
4349 {
4350 bfd * dynobj;
4351 asection * s;
4352 unsigned int power_of_two;
4353 struct elf32_arm_link_hash_entry * eh;
4354 struct elf32_arm_link_hash_table *globals;
4355
4356 globals = elf32_arm_hash_table (info);
4357 dynobj = elf_hash_table (info)->dynobj;
4358
4359 /* Make sure we know what is going on here. */
4360 BFD_ASSERT (dynobj != NULL
4361 && (h->needs_plt
4362 || h->u.weakdef != NULL
4363 || (h->def_dynamic
4364 && h->ref_regular
4365 && !h->def_regular)));
4366
4367 eh = (struct elf32_arm_link_hash_entry *) h;
4368
4369 /* If this is a function, put it in the procedure linkage table. We
4370 will fill in the contents of the procedure linkage table later,
4371 when we know the address of the .got section. */
4372 if (h->type == STT_FUNC || h->type == STT_ARM_TFUNC
4373 || h->needs_plt)
4374 {
4375 if (h->plt.refcount <= 0
4376 || SYMBOL_CALLS_LOCAL (info, h)
4377 || (ELF_ST_VISIBILITY (h->other) != STV_DEFAULT
4378 && h->root.type == bfd_link_hash_undefweak))
4379 {
4380 /* This case can occur if we saw a PLT32 reloc in an input
4381 file, but the symbol was never referred to by a dynamic
4382 object, or if all references were garbage collected. In
4383 such a case, we don't actually need to build a procedure
4384 linkage table, and we can just do a PC24 reloc instead. */
4385 h->plt.offset = (bfd_vma) -1;
4386 eh->plt_thumb_refcount = 0;
4387 h->needs_plt = 0;
4388 }
4389
4390 return TRUE;
4391 }
4392 else
4393 {
4394 /* It's possible that we incorrectly decided a .plt reloc was
4395 needed for an R_ARM_PC24 or similar reloc to a non-function sym
4396 in check_relocs. We can't decide accurately between function
4397 and non-function syms in check-relocs; Objects loaded later in
4398 the link may change h->type. So fix it now. */
4399 h->plt.offset = (bfd_vma) -1;
4400 eh->plt_thumb_refcount = 0;
4401 }
4402
4403 /* If this is a weak symbol, and there is a real definition, the
4404 processor independent code will have arranged for us to see the
4405 real definition first, and we can just use the same value. */
4406 if (h->u.weakdef != NULL)
4407 {
4408 BFD_ASSERT (h->u.weakdef->root.type == bfd_link_hash_defined
4409 || h->u.weakdef->root.type == bfd_link_hash_defweak);
4410 h->root.u.def.section = h->u.weakdef->root.u.def.section;
4411 h->root.u.def.value = h->u.weakdef->root.u.def.value;
4412 return TRUE;
4413 }
4414
4415 /* This is a reference to a symbol defined by a dynamic object which
4416 is not a function. */
4417
4418 /* If we are creating a shared library, we must presume that the
4419 only references to the symbol are via the global offset table.
4420 For such cases we need not do anything here; the relocations will
4421 be handled correctly by relocate_section. Relocatable executables
4422 can reference data in shared objects directly, so we don't need to
4423 do anything here. */
4424 if (info->shared || globals->root.is_relocatable_executable)
4425 return TRUE;
4426
4427 /* We must allocate the symbol in our .dynbss section, which will
4428 become part of the .bss section of the executable. There will be
4429 an entry for this symbol in the .dynsym section. The dynamic
4430 object will contain position independent code, so all references
4431 from the dynamic object to this symbol will go through the global
4432 offset table. The dynamic linker will use the .dynsym entry to
4433 determine the address it must put in the global offset table, so
4434 both the dynamic object and the regular object will refer to the
4435 same memory location for the variable. */
4436 s = bfd_get_section_by_name (dynobj, ".dynbss");
4437 BFD_ASSERT (s != NULL);
4438
4439 /* We must generate a R_ARM_COPY reloc to tell the dynamic linker to
4440 copy the initial value out of the dynamic object and into the
4441 runtime process image. We need to remember the offset into the
4442 .rel.bss section we are going to use. */
4443 if ((h->root.u.def.section->flags & SEC_ALLOC) != 0)
4444 {
4445 asection *srel;
4446
4447 srel = bfd_get_section_by_name (dynobj, ".rel.bss");
4448 BFD_ASSERT (srel != NULL);
4449 srel->size += sizeof (Elf32_External_Rel);
4450 h->needs_copy = 1;
4451 }
4452
4453 /* We need to figure out the alignment required for this symbol. I
4454 have no idea how ELF linkers handle this. */
4455 power_of_two = bfd_log2 (h->size);
4456 if (power_of_two > 3)
4457 power_of_two = 3;
4458
4459 /* Apply the required alignment. */
4460 s->size = BFD_ALIGN (s->size, (bfd_size_type) (1 << power_of_two));
4461 if (power_of_two > bfd_get_section_alignment (dynobj, s))
4462 {
4463 if (! bfd_set_section_alignment (dynobj, s, power_of_two))
4464 return FALSE;
4465 }
4466
4467 /* Define the symbol as being at this point in the section. */
4468 h->root.u.def.section = s;
4469 h->root.u.def.value = s->size;
4470
4471 /* Increment the section size to make room for the symbol. */
4472 s->size += h->size;
4473
4474 return TRUE;
4475 }
4476
4477 /* Allocate space in .plt, .got and associated reloc sections for
4478 dynamic relocs. */
4479
4480 static bfd_boolean
4481 allocate_dynrelocs (struct elf_link_hash_entry *h, void * inf)
4482 {
4483 struct bfd_link_info *info;
4484 struct elf32_arm_link_hash_table *htab;
4485 struct elf32_arm_link_hash_entry *eh;
4486 struct elf32_arm_relocs_copied *p;
4487
4488 eh = (struct elf32_arm_link_hash_entry *) h;
4489
4490 if (h->root.type == bfd_link_hash_indirect)
4491 return TRUE;
4492
4493 if (h->root.type == bfd_link_hash_warning)
4494 /* When warning symbols are created, they **replace** the "real"
4495 entry in the hash table, thus we never get to see the real
4496 symbol in a hash traversal. So look at it now. */
4497 h = (struct elf_link_hash_entry *) h->root.u.i.link;
4498
4499 info = (struct bfd_link_info *) inf;
4500 htab = elf32_arm_hash_table (info);
4501
4502 if (htab->root.dynamic_sections_created
4503 && h->plt.refcount > 0)
4504 {
4505 /* Make sure this symbol is output as a dynamic symbol.
4506 Undefined weak syms won't yet be marked as dynamic. */
4507 if (h->dynindx == -1
4508 && !h->forced_local)
4509 {
4510 if (! bfd_elf_link_record_dynamic_symbol (info, h))
4511 return FALSE;
4512 }
4513
4514 if (info->shared
4515 || WILL_CALL_FINISH_DYNAMIC_SYMBOL (1, 0, h))
4516 {
4517 asection *s = htab->splt;
4518
4519 /* If this is the first .plt entry, make room for the special
4520 first entry. */
4521 if (s->size == 0)
4522 s->size += htab->plt_header_size;
4523
4524 h->plt.offset = s->size;
4525
4526 /* If we will insert a Thumb trampoline before this PLT, leave room
4527 for it. */
4528 if (!htab->symbian_p && eh->plt_thumb_refcount > 0)
4529 {
4530 h->plt.offset += PLT_THUMB_STUB_SIZE;
4531 s->size += PLT_THUMB_STUB_SIZE;
4532 }
4533
4534 /* If this symbol is not defined in a regular file, and we are
4535 not generating a shared library, then set the symbol to this
4536 location in the .plt. This is required to make function
4537 pointers compare as equal between the normal executable and
4538 the shared library. */
4539 if (! info->shared
4540 && !h->def_regular)
4541 {
4542 h->root.u.def.section = s;
4543 h->root.u.def.value = h->plt.offset;
4544
4545 /* Make sure the function is not marked as Thumb, in case
4546 it is the target of an ABS32 relocation, which will
4547 point to the PLT entry. */
4548 if (ELF_ST_TYPE (h->type) == STT_ARM_TFUNC)
4549 h->type = ELF_ST_INFO (ELF_ST_BIND (h->type), STT_FUNC);
4550 }
4551
4552 /* Make room for this entry. */
4553 s->size += htab->plt_entry_size;
4554
4555 if (!htab->symbian_p)
4556 {
4557 /* We also need to make an entry in the .got.plt section, which
4558 will be placed in the .got section by the linker script. */
4559 eh->plt_got_offset = htab->sgotplt->size;
4560 htab->sgotplt->size += 4;
4561 }
4562
4563 /* We also need to make an entry in the .rel.plt section. */
4564 htab->srelplt->size += sizeof (Elf32_External_Rel);
4565 }
4566 else
4567 {
4568 h->plt.offset = (bfd_vma) -1;
4569 h->needs_plt = 0;
4570 }
4571 }
4572 else
4573 {
4574 h->plt.offset = (bfd_vma) -1;
4575 h->needs_plt = 0;
4576 }
4577
4578 if (h->got.refcount > 0)
4579 {
4580 asection *s;
4581 bfd_boolean dyn;
4582
4583 /* Make sure this symbol is output as a dynamic symbol.
4584 Undefined weak syms won't yet be marked as dynamic. */
4585 if (h->dynindx == -1
4586 && !h->forced_local)
4587 {
4588 if (! bfd_elf_link_record_dynamic_symbol (info, h))
4589 return FALSE;
4590 }
4591
4592 if (!htab->symbian_p)
4593 {
4594 s = htab->sgot;
4595 h->got.offset = s->size;
4596 s->size += 4;
4597 dyn = htab->root.dynamic_sections_created;
4598 if ((ELF_ST_VISIBILITY (h->other) == STV_DEFAULT
4599 || h->root.type != bfd_link_hash_undefweak)
4600 && (info->shared
4601 || WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn, 0, h)))
4602 htab->srelgot->size += sizeof (Elf32_External_Rel);
4603 }
4604 }
4605 else
4606 h->got.offset = (bfd_vma) -1;
4607
4608 if (eh->relocs_copied == NULL)
4609 return TRUE;
4610
4611 /* In the shared -Bsymbolic case, discard space allocated for
4612 dynamic pc-relative relocs against symbols which turn out to be
4613 defined in regular objects. For the normal shared case, discard
4614 space for pc-relative relocs that have become local due to symbol
4615 visibility changes. */
4616
4617 if (info->shared || htab->root.is_relocatable_executable)
4618 {
4619 /* Discard relocs on undefined weak syms with non-default
4620 visibility. */
4621 if (ELF_ST_VISIBILITY (h->other) != STV_DEFAULT
4622 && h->root.type == bfd_link_hash_undefweak)
4623 eh->relocs_copied = NULL;
4624 else if (htab->root.is_relocatable_executable && h->dynindx == -1
4625 && h->root.type == bfd_link_hash_new)
4626 {
4627 /* Output absolute symbols so that we can create relocations
4628 against them. For normal symbols we output a relocation
4629 against the section that contains them. */
4630 if (! bfd_elf_link_record_dynamic_symbol (info, h))
4631 return FALSE;
4632 }
4633
4634 }
4635 else
4636 {
4637 /* For the non-shared case, discard space for relocs against
4638 symbols which turn out to need copy relocs or are not
4639 dynamic. */
4640
4641 if (!h->non_got_ref
4642 && ((h->def_dynamic
4643 && !h->def_regular)
4644 || (htab->root.dynamic_sections_created
4645 && (h->root.type == bfd_link_hash_undefweak
4646 || h->root.type == bfd_link_hash_undefined))))
4647 {
4648 /* Make sure this symbol is output as a dynamic symbol.
4649 Undefined weak syms won't yet be marked as dynamic. */
4650 if (h->dynindx == -1
4651 && !h->forced_local)
4652 {
4653 if (! bfd_elf_link_record_dynamic_symbol (info, h))
4654 return FALSE;
4655 }
4656
4657 /* If that succeeded, we know we'll be keeping all the
4658 relocs. */
4659 if (h->dynindx != -1)
4660 goto keep;
4661 }
4662
4663 eh->relocs_copied = NULL;
4664
4665 keep: ;
4666 }
4667
4668 /* Finally, allocate space. */
4669 for (p = eh->relocs_copied; p != NULL; p = p->next)
4670 {
4671 asection *sreloc = elf_section_data (p->section)->sreloc;
4672 sreloc->size += p->count * sizeof (Elf32_External_Rel);
4673 }
4674
4675 return TRUE;
4676 }
4677
4678 /* Find any dynamic relocs that apply to read-only sections. */
4679
4680 static bfd_boolean
4681 elf32_arm_readonly_dynrelocs (struct elf_link_hash_entry *h, PTR inf)
4682 {
4683 struct elf32_arm_link_hash_entry *eh;
4684 struct elf32_arm_relocs_copied *p;
4685
4686 if (h->root.type == bfd_link_hash_warning)
4687 h = (struct elf_link_hash_entry *) h->root.u.i.link;
4688
4689 eh = (struct elf32_arm_link_hash_entry *) h;
4690 for (p = eh->relocs_copied; p != NULL; p = p->next)
4691 {
4692 asection *s = p->section;
4693
4694 if (s != NULL && (s->flags & SEC_READONLY) != 0)
4695 {
4696 struct bfd_link_info *info = (struct bfd_link_info *) inf;
4697
4698 info->flags |= DF_TEXTREL;
4699
4700 /* Not an error, just cut short the traversal. */
4701 return FALSE;
4702 }
4703 }
4704 return TRUE;
4705 }
4706
4707 /* Set the sizes of the dynamic sections. */
4708
4709 static bfd_boolean
4710 elf32_arm_size_dynamic_sections (bfd * output_bfd ATTRIBUTE_UNUSED,
4711 struct bfd_link_info * info)
4712 {
4713 bfd * dynobj;
4714 asection * s;
4715 bfd_boolean plt;
4716 bfd_boolean relocs;
4717 bfd *ibfd;
4718 struct elf32_arm_link_hash_table *htab;
4719
4720 htab = elf32_arm_hash_table (info);
4721 dynobj = elf_hash_table (info)->dynobj;
4722 BFD_ASSERT (dynobj != NULL);
4723
4724 if (elf_hash_table (info)->dynamic_sections_created)
4725 {
4726 /* Set the contents of the .interp section to the interpreter. */
4727 if (info->executable)
4728 {
4729 s = bfd_get_section_by_name (dynobj, ".interp");
4730 BFD_ASSERT (s != NULL);
4731 s->size = sizeof ELF_DYNAMIC_INTERPRETER;
4732 s->contents = (unsigned char *) ELF_DYNAMIC_INTERPRETER;
4733 }
4734 }
4735
4736 /* Set up .got offsets for local syms, and space for local dynamic
4737 relocs. */
4738 for (ibfd = info->input_bfds; ibfd != NULL; ibfd = ibfd->link_next)
4739 {
4740 bfd_signed_vma *local_got;
4741 bfd_signed_vma *end_local_got;
4742 char *local_tls_type;
4743 bfd_size_type locsymcount;
4744 Elf_Internal_Shdr *symtab_hdr;
4745 asection *srel;
4746
4747 if (bfd_get_flavour (ibfd) != bfd_target_elf_flavour)
4748 continue;
4749
4750 for (s = ibfd->sections; s != NULL; s = s->next)
4751 {
4752 struct elf32_arm_relocs_copied *p;
4753
4754 for (p = *((struct elf32_arm_relocs_copied **)
4755 &elf_section_data (s)->local_dynrel);
4756 p != NULL;
4757 p = p->next)
4758 {
4759 if (!bfd_is_abs_section (p->section)
4760 && bfd_is_abs_section (p->section->output_section))
4761 {
4762 /* Input section has been discarded, either because
4763 it is a copy of a linkonce section or due to
4764 linker script /DISCARD/, so we'll be discarding
4765 the relocs too. */
4766 }
4767 else if (p->count != 0)
4768 {
4769 srel = elf_section_data (p->section)->sreloc;
4770 srel->size += p->count * sizeof (Elf32_External_Rel);
4771 if ((p->section->output_section->flags & SEC_READONLY) != 0)
4772 info->flags |= DF_TEXTREL;
4773 }
4774 }
4775 }
4776
4777 local_got = elf_local_got_refcounts (ibfd);
4778 if (!local_got)
4779 continue;
4780
4781 symtab_hdr = &elf_tdata (ibfd)->symtab_hdr;
4782 locsymcount = symtab_hdr->sh_info;
4783 end_local_got = local_got + locsymcount;
4784 s = htab->sgot;
4785 srel = htab->srelgot;
4786 for (; local_got < end_local_got; ++local_got, ++local_tls_type)
4787 {
4788 if (*local_got > 0)
4789 {
4790 *local_got = s->size;
4791 s->size += 4;
4792 if (info->shared)
4793 srel->size += sizeof (Elf32_External_Rel);
4794 }
4795 else
4796 *local_got = (bfd_vma) -1;
4797 }
4798 }
4799
4800 /* Allocate global sym .plt and .got entries, and space for global
4801 sym dynamic relocs. */
4802 elf_link_hash_traverse (& htab->root, allocate_dynrelocs, info);
4803
4804 /* The check_relocs and adjust_dynamic_symbol entry points have
4805 determined the sizes of the various dynamic sections. Allocate
4806 memory for them. */
4807 plt = FALSE;
4808 relocs = FALSE;
4809 for (s = dynobj->sections; s != NULL; s = s->next)
4810 {
4811 const char * name;
4812 bfd_boolean strip;
4813
4814 if ((s->flags & SEC_LINKER_CREATED) == 0)
4815 continue;
4816
4817 /* It's OK to base decisions on the section name, because none
4818 of the dynobj section names depend upon the input files. */
4819 name = bfd_get_section_name (dynobj, s);
4820
4821 strip = FALSE;
4822
4823 if (strcmp (name, ".plt") == 0)
4824 {
4825 if (s->size == 0)
4826 {
4827 /* Strip this section if we don't need it; see the
4828 comment below. */
4829 strip = TRUE;
4830 }
4831 else
4832 {
4833 /* Remember whether there is a PLT. */
4834 plt = TRUE;
4835 }
4836 }
4837 else if (strncmp (name, ".rel", 4) == 0)
4838 {
4839 if (s->size == 0)
4840 {
4841 /* If we don't need this section, strip it from the
4842 output file. This is mostly to handle .rel.bss and
4843 .rel.plt. We must create both sections in
4844 create_dynamic_sections, because they must be created
4845 before the linker maps input sections to output
4846 sections. The linker does that before
4847 adjust_dynamic_symbol is called, and it is that
4848 function which decides whether anything needs to go
4849 into these sections. */
4850 strip = TRUE;
4851 }
4852 else
4853 {
4854 /* Remember whether there are any reloc sections other
4855 than .rel.plt. */
4856 if (strcmp (name, ".rel.plt") != 0)
4857 relocs = TRUE;
4858
4859 /* We use the reloc_count field as a counter if we need
4860 to copy relocs into the output file. */
4861 s->reloc_count = 0;
4862 }
4863 }
4864 else if (strncmp (name, ".got", 4) != 0)
4865 {
4866 /* It's not one of our sections, so don't allocate space. */
4867 continue;
4868 }
4869
4870 if (strip)
4871 {
4872 _bfd_strip_section_from_output (info, s);
4873 continue;
4874 }
4875
4876 /* Allocate memory for the section contents. */
4877 s->contents = (bfd_byte *) bfd_zalloc (dynobj, s->size);
4878 if (s->contents == NULL && s->size != 0)
4879 return FALSE;
4880 }
4881
4882 if (elf_hash_table (info)->dynamic_sections_created)
4883 {
4884 /* Add some entries to the .dynamic section. We fill in the
4885 values later, in elf32_arm_finish_dynamic_sections, but we
4886 must add the entries now so that we get the correct size for
4887 the .dynamic section. The DT_DEBUG entry is filled in by the
4888 dynamic linker and used by the debugger. */
4889 #define add_dynamic_entry(TAG, VAL) \
4890 _bfd_elf_add_dynamic_entry (info, TAG, VAL)
4891
4892 if (!info->shared)
4893 {
4894 if (!add_dynamic_entry (DT_DEBUG, 0))
4895 return FALSE;
4896 }
4897
4898 if (plt)
4899 {
4900 if ( !add_dynamic_entry (DT_PLTGOT, 0)
4901 || !add_dynamic_entry (DT_PLTRELSZ, 0)
4902 || !add_dynamic_entry (DT_PLTREL, DT_REL)
4903 || !add_dynamic_entry (DT_JMPREL, 0))
4904 return FALSE;
4905 }
4906
4907 if (relocs)
4908 {
4909 if ( !add_dynamic_entry (DT_REL, 0)
4910 || !add_dynamic_entry (DT_RELSZ, 0)
4911 || !add_dynamic_entry (DT_RELENT, sizeof (Elf32_External_Rel)))
4912 return FALSE;
4913 }
4914
4915 /* If any dynamic relocs apply to a read-only section,
4916 then we need a DT_TEXTREL entry. */
4917 if ((info->flags & DF_TEXTREL) == 0)
4918 elf_link_hash_traverse (&htab->root, elf32_arm_readonly_dynrelocs,
4919 (PTR) info);
4920
4921 if ((info->flags & DF_TEXTREL) != 0)
4922 {
4923 if (!add_dynamic_entry (DT_TEXTREL, 0))
4924 return FALSE;
4925 info->flags |= DF_TEXTREL;
4926 }
4927 }
4928 #undef add_synamic_entry
4929
4930 return TRUE;
4931 }
4932
4933 /* Finish up dynamic symbol handling. We set the contents of various
4934 dynamic sections here. */
4935
4936 static bfd_boolean
4937 elf32_arm_finish_dynamic_symbol (bfd * output_bfd, struct bfd_link_info * info,
4938 struct elf_link_hash_entry * h, Elf_Internal_Sym * sym)
4939 {
4940 bfd * dynobj;
4941 struct elf32_arm_link_hash_table *htab;
4942 struct elf32_arm_link_hash_entry *eh;
4943
4944 dynobj = elf_hash_table (info)->dynobj;
4945 htab = elf32_arm_hash_table (info);
4946 eh = (struct elf32_arm_link_hash_entry *) h;
4947
4948 if (h->plt.offset != (bfd_vma) -1)
4949 {
4950 asection * splt;
4951 asection * srel;
4952 bfd_byte *loc;
4953 bfd_vma plt_index;
4954 Elf_Internal_Rela rel;
4955
4956 /* This symbol has an entry in the procedure linkage table. Set
4957 it up. */
4958
4959 BFD_ASSERT (h->dynindx != -1);
4960
4961 splt = bfd_get_section_by_name (dynobj, ".plt");
4962 srel = bfd_get_section_by_name (dynobj, ".rel.plt");
4963 BFD_ASSERT (splt != NULL && srel != NULL);
4964
4965 /* Fill in the entry in the procedure linkage table. */
4966 if (htab->symbian_p)
4967 {
4968 unsigned i;
4969 for (i = 0; i < htab->plt_entry_size / 4; ++i)
4970 bfd_put_32 (output_bfd,
4971 elf32_arm_symbian_plt_entry[i],
4972 splt->contents + h->plt.offset + 4 * i);
4973
4974 /* Fill in the entry in the .rel.plt section. */
4975 rel.r_offset = (splt->output_section->vma
4976 + splt->output_offset
4977 + h->plt.offset + 4 * (i - 1));
4978 rel.r_info = ELF32_R_INFO (h->dynindx, R_ARM_GLOB_DAT);
4979
4980 /* Get the index in the procedure linkage table which
4981 corresponds to this symbol. This is the index of this symbol
4982 in all the symbols for which we are making plt entries. The
4983 first entry in the procedure linkage table is reserved. */
4984 plt_index = ((h->plt.offset - htab->plt_header_size)
4985 / htab->plt_entry_size);
4986 }
4987 else
4988 {
4989 bfd_vma got_offset;
4990 bfd_vma got_displacement;
4991 asection * sgot;
4992
4993 sgot = bfd_get_section_by_name (dynobj, ".got.plt");
4994 BFD_ASSERT (sgot != NULL);
4995
4996 /* Get the offset into the .got.plt table of the entry that
4997 corresponds to this function. */
4998 got_offset = eh->plt_got_offset;
4999
5000 /* Get the index in the procedure linkage table which
5001 corresponds to this symbol. This is the index of this symbol
5002 in all the symbols for which we are making plt entries. The
5003 first three entries in .got.plt are reserved; after that
5004 symbols appear in the same order as in .plt. */
5005 plt_index = (got_offset - 12) / 4;
5006
5007 /* Calculate the displacement between the PLT slot and the
5008 entry in the GOT. The eight-byte offset accounts for the
5009 value produced by adding to pc in the first instruction
5010 of the PLT stub. */
5011 got_displacement = (sgot->output_section->vma
5012 + sgot->output_offset
5013 + got_offset
5014 - splt->output_section->vma
5015 - splt->output_offset
5016 - h->plt.offset
5017 - 8);
5018
5019 BFD_ASSERT ((got_displacement & 0xf0000000) == 0);
5020
5021 if (eh->plt_thumb_refcount > 0)
5022 {
5023 bfd_put_16 (output_bfd, elf32_arm_plt_thumb_stub[0],
5024 splt->contents + h->plt.offset - 4);
5025 bfd_put_16 (output_bfd, elf32_arm_plt_thumb_stub[1],
5026 splt->contents + h->plt.offset - 2);
5027 }
5028
5029 bfd_put_32 (output_bfd, elf32_arm_plt_entry[0] | ((got_displacement & 0x0ff00000) >> 20),
5030 splt->contents + h->plt.offset + 0);
5031 bfd_put_32 (output_bfd, elf32_arm_plt_entry[1] | ((got_displacement & 0x000ff000) >> 12),
5032 splt->contents + h->plt.offset + 4);
5033 bfd_put_32 (output_bfd, elf32_arm_plt_entry[2] | (got_displacement & 0x00000fff),
5034 splt->contents + h->plt.offset + 8);
5035 #ifdef FOUR_WORD_PLT
5036 bfd_put_32 (output_bfd, elf32_arm_plt_entry[3],
5037 splt->contents + h->plt.offset + 12);
5038 #endif
5039
5040 /* Fill in the entry in the global offset table. */
5041 bfd_put_32 (output_bfd,
5042 (splt->output_section->vma
5043 + splt->output_offset),
5044 sgot->contents + got_offset);
5045
5046 /* Fill in the entry in the .rel.plt section. */
5047 rel.r_offset = (sgot->output_section->vma
5048 + sgot->output_offset
5049 + got_offset);
5050 rel.r_info = ELF32_R_INFO (h->dynindx, R_ARM_JUMP_SLOT);
5051 }
5052
5053 loc = srel->contents + plt_index * sizeof (Elf32_External_Rel);
5054 bfd_elf32_swap_reloc_out (output_bfd, &rel, loc);
5055
5056 if (!h->def_regular)
5057 {
5058 /* Mark the symbol as undefined, rather than as defined in
5059 the .plt section. Leave the value alone. */
5060 sym->st_shndx = SHN_UNDEF;
5061 /* If the symbol is weak, we do need to clear the value.
5062 Otherwise, the PLT entry would provide a definition for
5063 the symbol even if the symbol wasn't defined anywhere,
5064 and so the symbol would never be NULL. */
5065 if (!h->ref_regular_nonweak)
5066 sym->st_value = 0;
5067 }
5068 }
5069
5070 if (h->got.offset != (bfd_vma) -1)
5071 {
5072 asection * sgot;
5073 asection * srel;
5074 Elf_Internal_Rela rel;
5075 bfd_byte *loc;
5076
5077 /* This symbol has an entry in the global offset table. Set it
5078 up. */
5079 sgot = bfd_get_section_by_name (dynobj, ".got");
5080 srel = bfd_get_section_by_name (dynobj, ".rel.got");
5081 BFD_ASSERT (sgot != NULL && srel != NULL);
5082
5083 rel.r_offset = (sgot->output_section->vma
5084 + sgot->output_offset
5085 + (h->got.offset &~ (bfd_vma) 1));
5086
5087 /* If this is a static link, or it is a -Bsymbolic link and the
5088 symbol is defined locally or was forced to be local because
5089 of a version file, we just want to emit a RELATIVE reloc.
5090 The entry in the global offset table will already have been
5091 initialized in the relocate_section function. */
5092 if (info->shared
5093 && SYMBOL_REFERENCES_LOCAL (info, h))
5094 {
5095 BFD_ASSERT((h->got.offset & 1) != 0);
5096 rel.r_info = ELF32_R_INFO (0, R_ARM_RELATIVE);
5097 }
5098 else
5099 {
5100 BFD_ASSERT((h->got.offset & 1) == 0);
5101 bfd_put_32 (output_bfd, (bfd_vma) 0, sgot->contents + h->got.offset);
5102 rel.r_info = ELF32_R_INFO (h->dynindx, R_ARM_GLOB_DAT);
5103 }
5104
5105 loc = srel->contents + srel->reloc_count++ * sizeof (Elf32_External_Rel);
5106 bfd_elf32_swap_reloc_out (output_bfd, &rel, loc);
5107 }
5108
5109 if (h->needs_copy)
5110 {
5111 asection * s;
5112 Elf_Internal_Rela rel;
5113 bfd_byte *loc;
5114
5115 /* This symbol needs a copy reloc. Set it up. */
5116 BFD_ASSERT (h->dynindx != -1
5117 && (h->root.type == bfd_link_hash_defined
5118 || h->root.type == bfd_link_hash_defweak));
5119
5120 s = bfd_get_section_by_name (h->root.u.def.section->owner,
5121 ".rel.bss");
5122 BFD_ASSERT (s != NULL);
5123
5124 rel.r_offset = (h->root.u.def.value
5125 + h->root.u.def.section->output_section->vma
5126 + h->root.u.def.section->output_offset);
5127 rel.r_info = ELF32_R_INFO (h->dynindx, R_ARM_COPY);
5128 loc = s->contents + s->reloc_count++ * sizeof (Elf32_External_Rel);
5129 bfd_elf32_swap_reloc_out (output_bfd, &rel, loc);
5130 }
5131
5132 /* Mark _DYNAMIC and _GLOBAL_OFFSET_TABLE_ as absolute. */
5133 if (strcmp (h->root.root.string, "_DYNAMIC") == 0
5134 || strcmp (h->root.root.string, "_GLOBAL_OFFSET_TABLE_") == 0)
5135 sym->st_shndx = SHN_ABS;
5136
5137 return TRUE;
5138 }
5139
5140 /* Finish up the dynamic sections. */
5141
5142 static bfd_boolean
5143 elf32_arm_finish_dynamic_sections (bfd * output_bfd, struct bfd_link_info * info)
5144 {
5145 bfd * dynobj;
5146 asection * sgot;
5147 asection * sdyn;
5148
5149 dynobj = elf_hash_table (info)->dynobj;
5150
5151 sgot = bfd_get_section_by_name (dynobj, ".got.plt");
5152 BFD_ASSERT (elf32_arm_hash_table (info)->symbian_p || sgot != NULL);
5153 sdyn = bfd_get_section_by_name (dynobj, ".dynamic");
5154
5155 if (elf_hash_table (info)->dynamic_sections_created)
5156 {
5157 asection *splt;
5158 Elf32_External_Dyn *dyncon, *dynconend;
5159 struct elf32_arm_link_hash_table *htab;
5160
5161 htab = elf32_arm_hash_table (info);
5162 splt = bfd_get_section_by_name (dynobj, ".plt");
5163 BFD_ASSERT (splt != NULL && sdyn != NULL);
5164
5165 dyncon = (Elf32_External_Dyn *) sdyn->contents;
5166 dynconend = (Elf32_External_Dyn *) (sdyn->contents + sdyn->size);
5167
5168 for (; dyncon < dynconend; dyncon++)
5169 {
5170 Elf_Internal_Dyn dyn;
5171 const char * name;
5172 asection * s;
5173
5174 bfd_elf32_swap_dyn_in (dynobj, dyncon, &dyn);
5175
5176 switch (dyn.d_tag)
5177 {
5178 unsigned int type;
5179
5180 default:
5181 break;
5182
5183 case DT_HASH:
5184 name = ".hash";
5185 goto get_vma_if_bpabi;
5186 case DT_STRTAB:
5187 name = ".dynstr";
5188 goto get_vma_if_bpabi;
5189 case DT_SYMTAB:
5190 name = ".dynsym";
5191 goto get_vma_if_bpabi;
5192 case DT_VERSYM:
5193 name = ".gnu.version";
5194 goto get_vma_if_bpabi;
5195 case DT_VERDEF:
5196 name = ".gnu.version_d";
5197 goto get_vma_if_bpabi;
5198 case DT_VERNEED:
5199 name = ".gnu.version_r";
5200 goto get_vma_if_bpabi;
5201
5202 case DT_PLTGOT:
5203 name = ".got";
5204 goto get_vma;
5205 case DT_JMPREL:
5206 name = ".rel.plt";
5207 get_vma:
5208 s = bfd_get_section_by_name (output_bfd, name);
5209 BFD_ASSERT (s != NULL);
5210 if (!htab->symbian_p)
5211 dyn.d_un.d_ptr = s->vma;
5212 else
5213 /* In the BPABI, tags in the PT_DYNAMIC section point
5214 at the file offset, not the memory address, for the
5215 convenience of the post linker. */
5216 dyn.d_un.d_ptr = s->filepos;
5217 bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon);
5218 break;
5219
5220 get_vma_if_bpabi:
5221 if (htab->symbian_p)
5222 goto get_vma;
5223 break;
5224
5225 case DT_PLTRELSZ:
5226 s = bfd_get_section_by_name (output_bfd, ".rel.plt");
5227 BFD_ASSERT (s != NULL);
5228 dyn.d_un.d_val = s->size;
5229 bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon);
5230 break;
5231
5232 case DT_RELSZ:
5233 if (!htab->symbian_p)
5234 {
5235 /* My reading of the SVR4 ABI indicates that the
5236 procedure linkage table relocs (DT_JMPREL) should be
5237 included in the overall relocs (DT_REL). This is
5238 what Solaris does. However, UnixWare can not handle
5239 that case. Therefore, we override the DT_RELSZ entry
5240 here to make it not include the JMPREL relocs. Since
5241 the linker script arranges for .rel.plt to follow all
5242 other relocation sections, we don't have to worry
5243 about changing the DT_REL entry. */
5244 s = bfd_get_section_by_name (output_bfd, ".rel.plt");
5245 if (s != NULL)
5246 dyn.d_un.d_val -= s->size;
5247 bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon);
5248 break;
5249 }
5250 /* Fall through */
5251
5252 case DT_REL:
5253 case DT_RELA:
5254 case DT_RELASZ:
5255 /* In the BPABI, the DT_REL tag must point at the file
5256 offset, not the VMA, of the first relocation
5257 section. So, we use code similar to that in
5258 elflink.c, but do not check for SHF_ALLOC on the
5259 relcoation section, since relocations sections are
5260 never allocated under the BPABI. The comments above
5261 about Unixware notwithstanding, we include all of the
5262 relocations here. */
5263 if (htab->symbian_p)
5264 {
5265 unsigned int i;
5266 type = ((dyn.d_tag == DT_REL || dyn.d_tag == DT_RELSZ)
5267 ? SHT_REL : SHT_RELA);
5268 dyn.d_un.d_val = 0;
5269 for (i = 1; i < elf_numsections (output_bfd); i++)
5270 {
5271 Elf_Internal_Shdr *hdr
5272 = elf_elfsections (output_bfd)[i];
5273 if (hdr->sh_type == type)
5274 {
5275 if (dyn.d_tag == DT_RELSZ
5276 || dyn.d_tag == DT_RELASZ)
5277 dyn.d_un.d_val += hdr->sh_size;
5278 else if ((ufile_ptr) hdr->sh_offset
5279 <= dyn.d_un.d_val - 1)
5280 dyn.d_un.d_val = hdr->sh_offset;
5281 }
5282 }
5283 bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon);
5284 }
5285 break;
5286
5287 /* Set the bottom bit of DT_INIT/FINI if the
5288 corresponding function is Thumb. */
5289 case DT_INIT:
5290 name = info->init_function;
5291 goto get_sym;
5292 case DT_FINI:
5293 name = info->fini_function;
5294 get_sym:
5295 /* If it wasn't set by elf_bfd_final_link
5296 then there is nothing to adjust. */
5297 if (dyn.d_un.d_val != 0)
5298 {
5299 struct elf_link_hash_entry * eh;
5300
5301 eh = elf_link_hash_lookup (elf_hash_table (info), name,
5302 FALSE, FALSE, TRUE);
5303 if (eh != (struct elf_link_hash_entry *) NULL
5304 && ELF_ST_TYPE (eh->type) == STT_ARM_TFUNC)
5305 {
5306 dyn.d_un.d_val |= 1;
5307 bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon);
5308 }
5309 }
5310 break;
5311 }
5312 }
5313
5314 /* Fill in the first entry in the procedure linkage table. */
5315 if (splt->size > 0 && elf32_arm_hash_table (info)->plt_header_size)
5316 {
5317 bfd_vma got_displacement;
5318
5319 /* Calculate the displacement between the PLT slot and &GOT[0]. */
5320 got_displacement = (sgot->output_section->vma
5321 + sgot->output_offset
5322 - splt->output_section->vma
5323 - splt->output_offset
5324 - 16);
5325
5326 bfd_put_32 (output_bfd, elf32_arm_plt0_entry[0], splt->contents + 0);
5327 bfd_put_32 (output_bfd, elf32_arm_plt0_entry[1], splt->contents + 4);
5328 bfd_put_32 (output_bfd, elf32_arm_plt0_entry[2], splt->contents + 8);
5329 bfd_put_32 (output_bfd, elf32_arm_plt0_entry[3], splt->contents + 12);
5330 #ifdef FOUR_WORD_PLT
5331 /* The displacement value goes in the otherwise-unused last word of
5332 the second entry. */
5333 bfd_put_32 (output_bfd, got_displacement, splt->contents + 28);
5334 #else
5335 bfd_put_32 (output_bfd, got_displacement, splt->contents + 16);
5336 #endif
5337 }
5338
5339 /* UnixWare sets the entsize of .plt to 4, although that doesn't
5340 really seem like the right value. */
5341 elf_section_data (splt->output_section)->this_hdr.sh_entsize = 4;
5342 }
5343
5344 /* Fill in the first three entries in the global offset table. */
5345 if (sgot)
5346 {
5347 if (sgot->size > 0)
5348 {
5349 if (sdyn == NULL)
5350 bfd_put_32 (output_bfd, (bfd_vma) 0, sgot->contents);
5351 else
5352 bfd_put_32 (output_bfd,
5353 sdyn->output_section->vma + sdyn->output_offset,
5354 sgot->contents);
5355 bfd_put_32 (output_bfd, (bfd_vma) 0, sgot->contents + 4);
5356 bfd_put_32 (output_bfd, (bfd_vma) 0, sgot->contents + 8);
5357 }
5358
5359 elf_section_data (sgot->output_section)->this_hdr.sh_entsize = 4;
5360 }
5361
5362 return TRUE;
5363 }
5364
5365 static void
5366 elf32_arm_post_process_headers (bfd * abfd, struct bfd_link_info * link_info ATTRIBUTE_UNUSED)
5367 {
5368 Elf_Internal_Ehdr * i_ehdrp; /* ELF file header, internal form. */
5369 struct elf32_arm_link_hash_table *globals;
5370
5371 i_ehdrp = elf_elfheader (abfd);
5372
5373 if (EF_ARM_EABI_VERSION (i_ehdrp->e_flags) == EF_ARM_EABI_UNKNOWN)
5374 i_ehdrp->e_ident[EI_OSABI] = ELFOSABI_ARM;
5375 else
5376 i_ehdrp->e_ident[EI_OSABI] = 0;
5377 i_ehdrp->e_ident[EI_ABIVERSION] = ARM_ELF_ABI_VERSION;
5378
5379 if (link_info)
5380 {
5381 globals = elf32_arm_hash_table (link_info);
5382 if (globals->byteswap_code)
5383 i_ehdrp->e_flags |= EF_ARM_BE8;
5384 }
5385 }
5386
5387 static enum elf_reloc_type_class
5388 elf32_arm_reloc_type_class (const Elf_Internal_Rela *rela)
5389 {
5390 switch ((int) ELF32_R_TYPE (rela->r_info))
5391 {
5392 case R_ARM_RELATIVE:
5393 return reloc_class_relative;
5394 case R_ARM_JUMP_SLOT:
5395 return reloc_class_plt;
5396 case R_ARM_COPY:
5397 return reloc_class_copy;
5398 default:
5399 return reloc_class_normal;
5400 }
5401 }
5402
5403 /* Set the right machine number for an Arm ELF file. */
5404
5405 static bfd_boolean
5406 elf32_arm_section_flags (flagword *flags, const Elf_Internal_Shdr *hdr)
5407 {
5408 if (hdr->sh_type == SHT_NOTE)
5409 *flags |= SEC_LINK_ONCE | SEC_LINK_DUPLICATES_SAME_CONTENTS;
5410
5411 return TRUE;
5412 }
5413
5414 static void
5415 elf32_arm_final_write_processing (bfd *abfd, bfd_boolean linker ATTRIBUTE_UNUSED)
5416 {
5417 bfd_arm_update_notes (abfd, ARM_NOTE_SECTION);
5418 }
5419
5420 /* Return TRUE if this is an unwinding table entry. */
5421
5422 static bfd_boolean
5423 is_arm_elf_unwind_section_name (bfd * abfd ATTRIBUTE_UNUSED, const char * name)
5424 {
5425 size_t len1, len2;
5426
5427 len1 = sizeof (ELF_STRING_ARM_unwind) - 1;
5428 len2 = sizeof (ELF_STRING_ARM_unwind_once) - 1;
5429 return (strncmp (name, ELF_STRING_ARM_unwind, len1) == 0
5430 || strncmp (name, ELF_STRING_ARM_unwind_once, len2) == 0);
5431 }
5432
5433
5434 /* Set the type and flags for an ARM section. We do this by
5435 the section name, which is a hack, but ought to work. */
5436
5437 static bfd_boolean
5438 elf32_arm_fake_sections (bfd * abfd, Elf_Internal_Shdr * hdr, asection * sec)
5439 {
5440 const char * name;
5441
5442 name = bfd_get_section_name (abfd, sec);
5443
5444 if (is_arm_elf_unwind_section_name (abfd, name))
5445 {
5446 hdr->sh_type = SHT_ARM_EXIDX;
5447 hdr->sh_flags |= SHF_LINK_ORDER;
5448 }
5449 return TRUE;
5450 }
5451
5452 /* Handle an ARM specific section when reading an object file. This is
5453 called when bfd_section_from_shdr finds a section with an unknown
5454 type. */
5455
5456 static bfd_boolean
5457 elf32_arm_section_from_shdr (bfd *abfd,
5458 Elf_Internal_Shdr * hdr,
5459 const char *name,
5460 int shindex)
5461 {
5462 /* There ought to be a place to keep ELF backend specific flags, but
5463 at the moment there isn't one. We just keep track of the
5464 sections by their name, instead. Fortunately, the ABI gives
5465 names for all the ARM specific sections, so we will probably get
5466 away with this. */
5467 switch (hdr->sh_type)
5468 {
5469 case SHT_ARM_EXIDX:
5470 break;
5471
5472 default:
5473 return FALSE;
5474 }
5475
5476 if (! _bfd_elf_make_section_from_shdr (abfd, hdr, name, shindex))
5477 return FALSE;
5478
5479 return TRUE;
5480 }
5481
5482 /* Called for each symbol. Builds a section map based on mapping symbols.
5483 Does not alter any of the symbols. */
5484
5485 static bfd_boolean
5486 elf32_arm_output_symbol_hook (struct bfd_link_info *info,
5487 const char *name,
5488 Elf_Internal_Sym *elfsym,
5489 asection *input_sec,
5490 struct elf_link_hash_entry *h ATTRIBUTE_UNUSED)
5491 {
5492 int mapcount;
5493 elf32_arm_section_map *map;
5494 struct elf32_arm_link_hash_table *globals;
5495
5496 /* Only do this on final link. */
5497 if (info->relocatable)
5498 return TRUE;
5499
5500 /* Only build a map if we need to byteswap code. */
5501 globals = elf32_arm_hash_table (info);
5502 if (!globals->byteswap_code)
5503 return TRUE;
5504
5505 /* We only want mapping symbols. */
5506 if (! is_arm_mapping_symbol_name (name))
5507 return TRUE;
5508
5509 mapcount = ++(elf32_arm_section_data (input_sec)->mapcount);
5510 map = elf32_arm_section_data (input_sec)->map;
5511 /* TODO: This may be inefficient, but we probably don't usually have many
5512 mapping symbols per section. */
5513 map = bfd_realloc (map, mapcount * sizeof (elf32_arm_section_map));
5514 elf32_arm_section_data (input_sec)->map = map;
5515
5516 map[mapcount - 1].vma = elfsym->st_value;
5517 map[mapcount - 1].type = name[1];
5518 return TRUE;
5519 }
5520
5521
5522 /* Allocate target specific section data. */
5523
5524 static bfd_boolean
5525 elf32_arm_new_section_hook (bfd *abfd, asection *sec)
5526 {
5527 struct _arm_elf_section_data *sdata;
5528 bfd_size_type amt = sizeof (*sdata);
5529
5530 sdata = bfd_zalloc (abfd, amt);
5531 if (sdata == NULL)
5532 return FALSE;
5533 sec->used_by_bfd = sdata;
5534
5535 return _bfd_elf_new_section_hook (abfd, sec);
5536 }
5537
5538
5539 /* Used to order a list of mapping symbols by address. */
5540
5541 static int
5542 elf32_arm_compare_mapping (const void * a, const void * b)
5543 {
5544 return ((const elf32_arm_section_map *) a)->vma
5545 > ((const elf32_arm_section_map *) b)->vma;
5546 }
5547
5548
5549 /* Do code byteswapping. Return FALSE afterwards so that the section is
5550 written out as normal. */
5551
5552 static bfd_boolean
5553 elf32_arm_write_section (bfd *output_bfd ATTRIBUTE_UNUSED, asection *sec,
5554 bfd_byte *contents)
5555 {
5556 int mapcount;
5557 elf32_arm_section_map *map;
5558 bfd_vma ptr;
5559 bfd_vma end;
5560 bfd_vma offset;
5561 bfd_byte tmp;
5562 int i;
5563
5564 mapcount = elf32_arm_section_data (sec)->mapcount;
5565 map = elf32_arm_section_data (sec)->map;
5566
5567 if (mapcount == 0)
5568 return FALSE;
5569
5570 qsort (map, mapcount, sizeof (elf32_arm_section_map),
5571 elf32_arm_compare_mapping);
5572
5573 offset = sec->output_section->vma + sec->output_offset;
5574 ptr = map[0].vma - offset;
5575 for (i = 0; i < mapcount; i++)
5576 {
5577 if (i == mapcount - 1)
5578 end = sec->size;
5579 else
5580 end = map[i + 1].vma - offset;
5581
5582 switch (map[i].type)
5583 {
5584 case 'a':
5585 /* Byte swap code words. */
5586 while (ptr + 3 < end)
5587 {
5588 tmp = contents[ptr];
5589 contents[ptr] = contents[ptr + 3];
5590 contents[ptr + 3] = tmp;
5591 tmp = contents[ptr + 1];
5592 contents[ptr + 1] = contents[ptr + 2];
5593 contents[ptr + 2] = tmp;
5594 ptr += 4;
5595 }
5596 break;
5597
5598 case 't':
5599 /* Byte swap code halfwords. */
5600 while (ptr + 1 < end)
5601 {
5602 tmp = contents[ptr];
5603 contents[ptr] = contents[ptr + 1];
5604 contents[ptr + 1] = tmp;
5605 ptr += 2;
5606 }
5607 break;
5608
5609 case 'd':
5610 /* Leave data alone. */
5611 break;
5612 }
5613 ptr = end;
5614 }
5615 free (map);
5616 return FALSE;
5617 }
5618
5619 /* Display STT_ARM_TFUNC symbols as functions. */
5620
5621 static void
5622 elf32_arm_symbol_processing (bfd *abfd ATTRIBUTE_UNUSED,
5623 asymbol *asym)
5624 {
5625 elf_symbol_type *elfsym = (elf_symbol_type *) asym;
5626
5627 if (ELF_ST_TYPE (elfsym->internal_elf_sym.st_info) == STT_ARM_TFUNC)
5628 elfsym->symbol.flags |= BSF_FUNCTION;
5629 }
5630
5631
5632 /* Mangle thumb function symbols as we read them in. */
5633
5634 static void
5635 elf32_arm_swap_symbol_in (bfd * abfd,
5636 const void *psrc,
5637 const void *pshn,
5638 Elf_Internal_Sym *dst)
5639 {
5640 bfd_elf32_swap_symbol_in (abfd, psrc, pshn, dst);
5641
5642 /* New EABI objects mark thumb function symbols by setting the low bit of
5643 the address. Turn these into STT_ARM_TFUNC. */
5644 if (ELF_ST_TYPE (dst->st_info) == STT_FUNC
5645 && (dst->st_value & 1))
5646 {
5647 dst->st_info = ELF_ST_INFO (ELF_ST_BIND (dst->st_info), STT_ARM_TFUNC);
5648 dst->st_value &= ~(bfd_vma) 1;
5649 }
5650 }
5651
5652
5653 /* Mangle thumb function symbols as we write them out. */
5654
5655 static void
5656 elf32_arm_swap_symbol_out (bfd *abfd,
5657 const Elf_Internal_Sym *src,
5658 void *cdst,
5659 void *shndx)
5660 {
5661 Elf_Internal_Sym newsym;
5662
5663 /* We convert STT_ARM_TFUNC symbols into STT_FUNC with the low bit
5664 of the address set, as per the new EABI. We do this unconditionally
5665 because objcopy does not set the elf header flags until after
5666 it writes out the symbol table. */
5667 if (ELF_ST_TYPE (src->st_info) == STT_ARM_TFUNC)
5668 {
5669 newsym = *src;
5670 newsym.st_info = ELF_ST_INFO (ELF_ST_BIND (src->st_info), STT_FUNC);
5671 newsym.st_value |= 1;
5672
5673 src = &newsym;
5674 }
5675 bfd_elf32_swap_symbol_out (abfd, src, cdst, shndx);
5676 }
5677
5678 /* Add the PT_ARM_EXIDX program header. */
5679
5680 static bfd_boolean
5681 elf32_arm_modify_segment_map (bfd *abfd,
5682 struct bfd_link_info *info ATTRIBUTE_UNUSED)
5683 {
5684 struct elf_segment_map *m;
5685 asection *sec;
5686
5687 sec = bfd_get_section_by_name (abfd, ".ARM.exidx");
5688 if (sec != NULL && (sec->flags & SEC_LOAD) != 0)
5689 {
5690 /* If there is already a PT_ARM_EXIDX header, then we do not
5691 want to add another one. This situation arises when running
5692 "strip"; the input binary already has the header. */
5693 m = elf_tdata (abfd)->segment_map;
5694 while (m && m->p_type != PT_ARM_EXIDX)
5695 m = m->next;
5696 if (!m)
5697 {
5698 m = bfd_zalloc (abfd, sizeof (struct elf_segment_map));
5699 if (m == NULL)
5700 return FALSE;
5701 m->p_type = PT_ARM_EXIDX;
5702 m->count = 1;
5703 m->sections[0] = sec;
5704
5705 m->next = elf_tdata (abfd)->segment_map;
5706 elf_tdata (abfd)->segment_map = m;
5707 }
5708 }
5709
5710 return TRUE;
5711 }
5712
5713 /* We may add a PT_ARM_EXIDX program header. */
5714
5715 static int
5716 elf32_arm_additional_program_headers (bfd *abfd)
5717 {
5718 asection *sec;
5719
5720 sec = bfd_get_section_by_name (abfd, ".ARM.exidx");
5721 if (sec != NULL && (sec->flags & SEC_LOAD) != 0)
5722 return 1;
5723 else
5724 return 0;
5725 }
5726
5727 /* We use this to override swap_symbol_in and swap_symbol_out. */
5728 const struct elf_size_info elf32_arm_size_info = {
5729 sizeof (Elf32_External_Ehdr),
5730 sizeof (Elf32_External_Phdr),
5731 sizeof (Elf32_External_Shdr),
5732 sizeof (Elf32_External_Rel),
5733 sizeof (Elf32_External_Rela),
5734 sizeof (Elf32_External_Sym),
5735 sizeof (Elf32_External_Dyn),
5736 sizeof (Elf_External_Note),
5737 4,
5738 1,
5739 32, 2,
5740 ELFCLASS32, EV_CURRENT,
5741 bfd_elf32_write_out_phdrs,
5742 bfd_elf32_write_shdrs_and_ehdr,
5743 bfd_elf32_write_relocs,
5744 elf32_arm_swap_symbol_in,
5745 elf32_arm_swap_symbol_out,
5746 bfd_elf32_slurp_reloc_table,
5747 bfd_elf32_slurp_symbol_table,
5748 bfd_elf32_swap_dyn_in,
5749 bfd_elf32_swap_dyn_out,
5750 bfd_elf32_swap_reloc_in,
5751 bfd_elf32_swap_reloc_out,
5752 bfd_elf32_swap_reloca_in,
5753 bfd_elf32_swap_reloca_out
5754 };
5755
5756 #define ELF_ARCH bfd_arch_arm
5757 #define ELF_MACHINE_CODE EM_ARM
5758 #ifdef __QNXTARGET__
5759 #define ELF_MAXPAGESIZE 0x1000
5760 #else
5761 #define ELF_MAXPAGESIZE 0x8000
5762 #endif
5763 #define ELF_MINPAGESIZE 0x1000
5764
5765 #define bfd_elf32_bfd_copy_private_bfd_data elf32_arm_copy_private_bfd_data
5766 #define bfd_elf32_bfd_merge_private_bfd_data elf32_arm_merge_private_bfd_data
5767 #define bfd_elf32_bfd_set_private_flags elf32_arm_set_private_flags
5768 #define bfd_elf32_bfd_print_private_bfd_data elf32_arm_print_private_bfd_data
5769 #define bfd_elf32_bfd_link_hash_table_create elf32_arm_link_hash_table_create
5770 #define bfd_elf32_bfd_reloc_type_lookup elf32_arm_reloc_type_lookup
5771 #define bfd_elf32_find_nearest_line elf32_arm_find_nearest_line
5772 #define bfd_elf32_new_section_hook elf32_arm_new_section_hook
5773 #define bfd_elf32_bfd_is_target_special_symbol elf32_arm_is_target_special_symbol
5774
5775 #define elf_backend_get_symbol_type elf32_arm_get_symbol_type
5776 #define elf_backend_gc_mark_hook elf32_arm_gc_mark_hook
5777 #define elf_backend_gc_sweep_hook elf32_arm_gc_sweep_hook
5778 #define elf_backend_check_relocs elf32_arm_check_relocs
5779 #define elf_backend_relocate_section elf32_arm_relocate_section
5780 #define elf_backend_write_section elf32_arm_write_section
5781 #define elf_backend_adjust_dynamic_symbol elf32_arm_adjust_dynamic_symbol
5782 #define elf_backend_create_dynamic_sections elf32_arm_create_dynamic_sections
5783 #define elf_backend_finish_dynamic_symbol elf32_arm_finish_dynamic_symbol
5784 #define elf_backend_finish_dynamic_sections elf32_arm_finish_dynamic_sections
5785 #define elf_backend_link_output_symbol_hook elf32_arm_output_symbol_hook
5786 #define elf_backend_size_dynamic_sections elf32_arm_size_dynamic_sections
5787 #define elf_backend_post_process_headers elf32_arm_post_process_headers
5788 #define elf_backend_reloc_type_class elf32_arm_reloc_type_class
5789 #define elf_backend_object_p elf32_arm_object_p
5790 #define elf_backend_section_flags elf32_arm_section_flags
5791 #define elf_backend_fake_sections elf32_arm_fake_sections
5792 #define elf_backend_section_from_shdr elf32_arm_section_from_shdr
5793 #define elf_backend_final_write_processing elf32_arm_final_write_processing
5794 #define elf_backend_copy_indirect_symbol elf32_arm_copy_indirect_symbol
5795 #define elf_backend_symbol_processing elf32_arm_symbol_processing
5796 #define elf_backend_size_info elf32_arm_size_info
5797 #define elf_backend_modify_segment_map elf32_arm_modify_segment_map
5798 #define elf_backend_additional_program_headers \
5799 elf32_arm_additional_program_headers
5800
5801 #define elf_backend_can_refcount 1
5802 #define elf_backend_can_gc_sections 1
5803 #define elf_backend_plt_readonly 1
5804 #define elf_backend_want_got_plt 1
5805 #define elf_backend_want_plt_sym 0
5806 #define elf_backend_may_use_rel_p 1
5807 #define elf_backend_may_use_rela_p 0
5808 #define elf_backend_default_use_rela_p 0
5809 #define elf_backend_rela_normal 0
5810
5811 #define elf_backend_got_header_size 12
5812
5813 #include "elf32-target.h"
5814
5815 /* VxWorks Targets */
5816
5817 #undef TARGET_LITTLE_SYM
5818 #define TARGET_LITTLE_SYM bfd_elf32_littlearm_vxworks_vec
5819 #undef TARGET_LITTLE_NAME
5820 #define TARGET_LITTLE_NAME "elf32-littlearm-vxworks"
5821 #undef TARGET_BIG_SYM
5822 #define TARGET_BIG_SYM bfd_elf32_bigarm_vxworks_vec
5823 #undef TARGET_BIG_NAME
5824 #define TARGET_BIG_NAME "elf32-bigarm-vxworks"
5825
5826 /* Like elf32_arm_link_hash_table_create -- but overrides
5827 appropriately for VxWorks. */
5828 static struct bfd_link_hash_table *
5829 elf32_arm_vxworks_link_hash_table_create (bfd *abfd)
5830 {
5831 struct bfd_link_hash_table *ret;
5832
5833 ret = elf32_arm_link_hash_table_create (abfd);
5834 if (ret)
5835 {
5836 struct elf32_arm_link_hash_table *htab
5837 = (struct elf32_arm_link_hash_table *)ret;
5838 htab->use_rel = 0;
5839 }
5840 return ret;
5841 }
5842
5843 #undef elf32_bed
5844 #define elf32_bed elf32_arm_vxworks_bed
5845
5846 #undef bfd_elf32_bfd_link_hash_table_create
5847 #define bfd_elf32_bfd_link_hash_table_create \
5848 elf32_arm_vxworks_link_hash_table_create
5849
5850 #undef elf_backend_may_use_rel_p
5851 #define elf_backend_may_use_rel_p 0
5852 #undef elf_backend_may_use_rela_p
5853 #define elf_backend_may_use_rela_p 1
5854 #undef elf_backend_default_use_rela_p
5855 #define elf_backend_default_use_rela_p 1
5856 #undef elf_backend_rela_normal
5857 #define elf_backend_rela_normal 1
5858
5859 #include "elf32-target.h"
5860
5861
5862 /* Symbian OS Targets */
5863
5864 #undef TARGET_LITTLE_SYM
5865 #define TARGET_LITTLE_SYM bfd_elf32_littlearm_symbian_vec
5866 #undef TARGET_LITTLE_NAME
5867 #define TARGET_LITTLE_NAME "elf32-littlearm-symbian"
5868 #undef TARGET_BIG_SYM
5869 #define TARGET_BIG_SYM bfd_elf32_bigarm_symbian_vec
5870 #undef TARGET_BIG_NAME
5871 #define TARGET_BIG_NAME "elf32-bigarm-symbian"
5872
5873 /* Like elf32_arm_link_hash_table_create -- but overrides
5874 appropriately for Symbian OS. */
5875 static struct bfd_link_hash_table *
5876 elf32_arm_symbian_link_hash_table_create (bfd *abfd)
5877 {
5878 struct bfd_link_hash_table *ret;
5879
5880 ret = elf32_arm_link_hash_table_create (abfd);
5881 if (ret)
5882 {
5883 struct elf32_arm_link_hash_table *htab
5884 = (struct elf32_arm_link_hash_table *)ret;
5885 /* There is no PLT header for Symbian OS. */
5886 htab->plt_header_size = 0;
5887 /* The PLT entries are each three instructions. */
5888 htab->plt_entry_size = 4 * NUM_ELEM (elf32_arm_symbian_plt_entry);
5889 htab->symbian_p = 1;
5890 htab->root.is_relocatable_executable = 1;
5891 }
5892 return ret;
5893 }
5894
5895 static struct bfd_elf_special_section const
5896 elf32_arm_symbian_special_sections[]=
5897 {
5898 /* In a BPABI executable, the dynamic linking sections do not go in
5899 the loadable read-only segment. The post-linker may wish to
5900 refer to these sections, but they are not part of the final
5901 program image. */
5902 { ".dynamic", 8, 0, SHT_DYNAMIC, 0 },
5903 { ".dynstr", 7, 0, SHT_STRTAB, 0 },
5904 { ".dynsym", 7, 0, SHT_DYNSYM, 0 },
5905 { ".got", 4, 0, SHT_PROGBITS, 0 },
5906 { ".hash", 5, 0, SHT_HASH, 0 },
5907 /* These sections do not need to be writable as the SymbianOS
5908 postlinker will arrange things so that no dynamic relocation is
5909 required. */
5910 { ".init_array", 11, 0, SHT_INIT_ARRAY, SHF_ALLOC },
5911 { ".fini_array", 11, 0, SHT_FINI_ARRAY, SHF_ALLOC },
5912 { ".preinit_array", 14, 0, SHT_PREINIT_ARRAY, SHF_ALLOC },
5913 { NULL, 0, 0, 0, 0 }
5914 };
5915
5916 static void
5917 elf32_arm_symbian_begin_write_processing (bfd *abfd,
5918 struct bfd_link_info *link_info
5919 ATTRIBUTE_UNUSED)
5920 {
5921 /* BPABI objects are never loaded directly by an OS kernel; they are
5922 processed by a postlinker first, into an OS-specific format. If
5923 the D_PAGED bit is set on the file, BFD will align segments on
5924 page boundaries, so that an OS can directly map the file. With
5925 BPABI objects, that just results in wasted space. In addition,
5926 because we clear the D_PAGED bit, map_sections_to_segments will
5927 recognize that the program headers should not be mapped into any
5928 loadable segment. */
5929 abfd->flags &= ~D_PAGED;
5930 }
5931
5932 static bfd_boolean
5933 elf32_arm_symbian_modify_segment_map (bfd *abfd,
5934 struct bfd_link_info *info)
5935 {
5936 struct elf_segment_map *m;
5937 asection *dynsec;
5938
5939 /* BPABI shared libraries and executables should have a PT_DYNAMIC
5940 segment. However, because the .dynamic section is not marked
5941 with SEC_LOAD, the generic ELF code will not create such a
5942 segment. */
5943 dynsec = bfd_get_section_by_name (abfd, ".dynamic");
5944 if (dynsec)
5945 {
5946 m = _bfd_elf_make_dynamic_segment (abfd, dynsec);
5947 m->next = elf_tdata (abfd)->segment_map;
5948 elf_tdata (abfd)->segment_map = m;
5949 }
5950
5951 /* Also call the generic arm routine. */
5952 return elf32_arm_modify_segment_map (abfd, info);
5953 }
5954
5955 #undef elf32_bed
5956 #define elf32_bed elf32_arm_symbian_bed
5957
5958 /* The dynamic sections are not allocated on SymbianOS; the postlinker
5959 will process them and then discard them. */
5960 #undef ELF_DYNAMIC_SEC_FLAGS
5961 #define ELF_DYNAMIC_SEC_FLAGS \
5962 (SEC_HAS_CONTENTS | SEC_IN_MEMORY | SEC_LINKER_CREATED)
5963
5964 #undef bfd_elf32_bfd_link_hash_table_create
5965 #define bfd_elf32_bfd_link_hash_table_create \
5966 elf32_arm_symbian_link_hash_table_create
5967
5968 #undef elf_backend_special_sections
5969 #define elf_backend_special_sections elf32_arm_symbian_special_sections
5970
5971 #undef elf_backend_begin_write_processing
5972 #define elf_backend_begin_write_processing \
5973 elf32_arm_symbian_begin_write_processing
5974
5975 #undef elf_backend_modify_segment_map
5976 #define elf_backend_modify_segment_map elf32_arm_symbian_modify_segment_map
5977
5978 /* There is no .got section for BPABI objects, and hence no header. */
5979 #undef elf_backend_got_header_size
5980 #define elf_backend_got_header_size 0
5981
5982 /* Similarly, there is no .got.plt section. */
5983 #undef elf_backend_want_got_plt
5984 #define elf_backend_want_got_plt 0
5985
5986 #undef elf_backend_may_use_rel_p
5987 #define elf_backend_may_use_rel_p 1
5988 #undef elf_backend_may_use_rela_p
5989 #define elf_backend_may_use_rela_p 0
5990 #undef elf_backend_default_use_rela_p
5991 #define elf_backend_default_use_rela_p 0
5992 #undef elf_backend_rela_normal
5993 #define elf_backend_rela_normal 0
5994
5995 #include "elf32-target.h"
This page took 0.15385 seconds and 5 git commands to generate.