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