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