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