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