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