* readelf.c (print_vma): Typo fix.
[deliverable/binutils-gdb.git] / bfd / elf32-arm.c
CommitLineData
252b5132 1/* 32-bit ELF support for ARM
e44a2c9c
AM
2 Copyright 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007,
3 2008 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
cd123cb7 9 the Free Software Foundation; either version 3 of the License, or
252b5132
RH
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
cd123cb7
NC
19 Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
20 MA 02110-1301, USA. */
252b5132 21
7f266840 22#include "sysdep.h"
3db64b00 23#include "bfd.h"
00a97672 24#include "libiberty.h"
7f266840
DJ
25#include "libbfd.h"
26#include "elf-bfd.h"
00a97672 27#include "elf-vxworks.h"
ee065d83 28#include "elf/arm.h"
7f266840 29
00a97672
RS
30/* Return the relocation section associated with NAME. HTAB is the
31 bfd's elf32_arm_link_hash_entry. */
32#define RELOC_SECTION(HTAB, NAME) \
33 ((HTAB)->use_rel ? ".rel" NAME : ".rela" NAME)
34
35/* Return size of a relocation entry. HTAB is the bfd's
36 elf32_arm_link_hash_entry. */
37#define RELOC_SIZE(HTAB) \
38 ((HTAB)->use_rel \
39 ? sizeof (Elf32_External_Rel) \
40 : sizeof (Elf32_External_Rela))
41
42/* Return function to swap relocations in. HTAB is the bfd's
43 elf32_arm_link_hash_entry. */
44#define SWAP_RELOC_IN(HTAB) \
45 ((HTAB)->use_rel \
46 ? bfd_elf32_swap_reloc_in \
47 : bfd_elf32_swap_reloca_in)
48
49/* Return function to swap relocations out. HTAB is the bfd's
50 elf32_arm_link_hash_entry. */
51#define SWAP_RELOC_OUT(HTAB) \
52 ((HTAB)->use_rel \
53 ? bfd_elf32_swap_reloc_out \
54 : bfd_elf32_swap_reloca_out)
55
7f266840
DJ
56#define elf_info_to_howto 0
57#define elf_info_to_howto_rel elf32_arm_info_to_howto
58
59#define ARM_ELF_ABI_VERSION 0
60#define ARM_ELF_OS_ABI_VERSION ELFOSABI_ARM
61
24718e3b 62static struct elf_backend_data elf32_arm_vxworks_bed;
00a97672 63
7f266840
DJ
64/* Note: code such as elf32_arm_reloc_type_lookup expect to use e.g.
65 R_ARM_PC24 as an index into this, and find the R_ARM_PC24 HOWTO
66 in that slot. */
67
c19d1205 68static reloc_howto_type elf32_arm_howto_table_1[] =
7f266840
DJ
69{
70 /* No relocation */
71 HOWTO (R_ARM_NONE, /* type */
72 0, /* rightshift */
73 0, /* size (0 = byte, 1 = short, 2 = long) */
74 0, /* bitsize */
75 FALSE, /* pc_relative */
76 0, /* bitpos */
77 complain_overflow_dont,/* complain_on_overflow */
78 bfd_elf_generic_reloc, /* special_function */
79 "R_ARM_NONE", /* name */
80 FALSE, /* partial_inplace */
81 0, /* src_mask */
82 0, /* dst_mask */
83 FALSE), /* pcrel_offset */
84
85 HOWTO (R_ARM_PC24, /* type */
86 2, /* rightshift */
87 2, /* size (0 = byte, 1 = short, 2 = long) */
88 24, /* bitsize */
89 TRUE, /* pc_relative */
90 0, /* bitpos */
91 complain_overflow_signed,/* complain_on_overflow */
92 bfd_elf_generic_reloc, /* special_function */
93 "R_ARM_PC24", /* name */
94 FALSE, /* partial_inplace */
95 0x00ffffff, /* src_mask */
96 0x00ffffff, /* dst_mask */
97 TRUE), /* pcrel_offset */
98
99 /* 32 bit absolute */
100 HOWTO (R_ARM_ABS32, /* type */
101 0, /* rightshift */
102 2, /* size (0 = byte, 1 = short, 2 = long) */
103 32, /* bitsize */
104 FALSE, /* pc_relative */
105 0, /* bitpos */
106 complain_overflow_bitfield,/* complain_on_overflow */
107 bfd_elf_generic_reloc, /* special_function */
108 "R_ARM_ABS32", /* name */
109 FALSE, /* partial_inplace */
110 0xffffffff, /* src_mask */
111 0xffffffff, /* dst_mask */
112 FALSE), /* pcrel_offset */
113
114 /* standard 32bit pc-relative reloc */
115 HOWTO (R_ARM_REL32, /* type */
116 0, /* rightshift */
117 2, /* size (0 = byte, 1 = short, 2 = long) */
118 32, /* bitsize */
119 TRUE, /* pc_relative */
120 0, /* bitpos */
121 complain_overflow_bitfield,/* complain_on_overflow */
122 bfd_elf_generic_reloc, /* special_function */
123 "R_ARM_REL32", /* name */
124 FALSE, /* partial_inplace */
125 0xffffffff, /* src_mask */
126 0xffffffff, /* dst_mask */
127 TRUE), /* pcrel_offset */
128
c19d1205 129 /* 8 bit absolute - R_ARM_LDR_PC_G0 in AAELF */
4962c51a 130 HOWTO (R_ARM_LDR_PC_G0, /* type */
7f266840
DJ
131 0, /* rightshift */
132 0, /* size (0 = byte, 1 = short, 2 = long) */
4962c51a
MS
133 32, /* bitsize */
134 TRUE, /* pc_relative */
7f266840 135 0, /* bitpos */
4962c51a 136 complain_overflow_dont,/* complain_on_overflow */
7f266840 137 bfd_elf_generic_reloc, /* special_function */
4962c51a 138 "R_ARM_LDR_PC_G0", /* name */
7f266840 139 FALSE, /* partial_inplace */
4962c51a
MS
140 0xffffffff, /* src_mask */
141 0xffffffff, /* dst_mask */
142 TRUE), /* pcrel_offset */
7f266840
DJ
143
144 /* 16 bit absolute */
145 HOWTO (R_ARM_ABS16, /* type */
146 0, /* rightshift */
147 1, /* size (0 = byte, 1 = short, 2 = long) */
148 16, /* bitsize */
149 FALSE, /* pc_relative */
150 0, /* bitpos */
151 complain_overflow_bitfield,/* complain_on_overflow */
152 bfd_elf_generic_reloc, /* special_function */
153 "R_ARM_ABS16", /* name */
154 FALSE, /* partial_inplace */
155 0x0000ffff, /* src_mask */
156 0x0000ffff, /* dst_mask */
157 FALSE), /* pcrel_offset */
158
159 /* 12 bit absolute */
160 HOWTO (R_ARM_ABS12, /* type */
161 0, /* rightshift */
162 2, /* size (0 = byte, 1 = short, 2 = long) */
163 12, /* bitsize */
164 FALSE, /* pc_relative */
165 0, /* bitpos */
166 complain_overflow_bitfield,/* complain_on_overflow */
167 bfd_elf_generic_reloc, /* special_function */
168 "R_ARM_ABS12", /* name */
169 FALSE, /* partial_inplace */
00a97672
RS
170 0x00000fff, /* src_mask */
171 0x00000fff, /* dst_mask */
7f266840
DJ
172 FALSE), /* pcrel_offset */
173
174 HOWTO (R_ARM_THM_ABS5, /* type */
175 6, /* rightshift */
176 1, /* size (0 = byte, 1 = short, 2 = long) */
177 5, /* bitsize */
178 FALSE, /* pc_relative */
179 0, /* bitpos */
180 complain_overflow_bitfield,/* complain_on_overflow */
181 bfd_elf_generic_reloc, /* special_function */
182 "R_ARM_THM_ABS5", /* name */
183 FALSE, /* partial_inplace */
184 0x000007e0, /* src_mask */
185 0x000007e0, /* dst_mask */
186 FALSE), /* pcrel_offset */
187
188 /* 8 bit absolute */
189 HOWTO (R_ARM_ABS8, /* type */
190 0, /* rightshift */
191 0, /* size (0 = byte, 1 = short, 2 = long) */
192 8, /* bitsize */
193 FALSE, /* pc_relative */
194 0, /* bitpos */
195 complain_overflow_bitfield,/* complain_on_overflow */
196 bfd_elf_generic_reloc, /* special_function */
197 "R_ARM_ABS8", /* name */
198 FALSE, /* partial_inplace */
199 0x000000ff, /* src_mask */
200 0x000000ff, /* dst_mask */
201 FALSE), /* pcrel_offset */
202
203 HOWTO (R_ARM_SBREL32, /* type */
204 0, /* rightshift */
205 2, /* size (0 = byte, 1 = short, 2 = long) */
206 32, /* bitsize */
207 FALSE, /* pc_relative */
208 0, /* bitpos */
209 complain_overflow_dont,/* complain_on_overflow */
210 bfd_elf_generic_reloc, /* special_function */
211 "R_ARM_SBREL32", /* name */
212 FALSE, /* partial_inplace */
213 0xffffffff, /* src_mask */
214 0xffffffff, /* dst_mask */
215 FALSE), /* pcrel_offset */
216
c19d1205 217 HOWTO (R_ARM_THM_CALL, /* type */
7f266840
DJ
218 1, /* rightshift */
219 2, /* size (0 = byte, 1 = short, 2 = long) */
e95de063 220 25, /* bitsize */
7f266840
DJ
221 TRUE, /* pc_relative */
222 0, /* bitpos */
223 complain_overflow_signed,/* complain_on_overflow */
224 bfd_elf_generic_reloc, /* special_function */
c19d1205 225 "R_ARM_THM_CALL", /* name */
7f266840
DJ
226 FALSE, /* partial_inplace */
227 0x07ff07ff, /* src_mask */
228 0x07ff07ff, /* dst_mask */
229 TRUE), /* pcrel_offset */
230
231 HOWTO (R_ARM_THM_PC8, /* type */
232 1, /* rightshift */
233 1, /* size (0 = byte, 1 = short, 2 = long) */
234 8, /* bitsize */
235 TRUE, /* pc_relative */
236 0, /* bitpos */
237 complain_overflow_signed,/* complain_on_overflow */
238 bfd_elf_generic_reloc, /* special_function */
239 "R_ARM_THM_PC8", /* name */
240 FALSE, /* partial_inplace */
241 0x000000ff, /* src_mask */
242 0x000000ff, /* dst_mask */
243 TRUE), /* pcrel_offset */
244
c19d1205 245 HOWTO (R_ARM_BREL_ADJ, /* type */
7f266840
DJ
246 1, /* rightshift */
247 1, /* size (0 = byte, 1 = short, 2 = long) */
c19d1205
ZW
248 32, /* bitsize */
249 FALSE, /* pc_relative */
7f266840
DJ
250 0, /* bitpos */
251 complain_overflow_signed,/* complain_on_overflow */
252 bfd_elf_generic_reloc, /* special_function */
c19d1205 253 "R_ARM_BREL_ADJ", /* name */
7f266840 254 FALSE, /* partial_inplace */
c19d1205
ZW
255 0xffffffff, /* src_mask */
256 0xffffffff, /* dst_mask */
257 FALSE), /* pcrel_offset */
7f266840
DJ
258
259 HOWTO (R_ARM_SWI24, /* type */
260 0, /* rightshift */
261 0, /* size (0 = byte, 1 = short, 2 = long) */
262 0, /* bitsize */
263 FALSE, /* pc_relative */
264 0, /* bitpos */
265 complain_overflow_signed,/* complain_on_overflow */
266 bfd_elf_generic_reloc, /* special_function */
267 "R_ARM_SWI24", /* name */
268 FALSE, /* partial_inplace */
269 0x00000000, /* src_mask */
270 0x00000000, /* dst_mask */
271 FALSE), /* pcrel_offset */
272
273 HOWTO (R_ARM_THM_SWI8, /* type */
274 0, /* rightshift */
275 0, /* size (0 = byte, 1 = short, 2 = long) */
276 0, /* bitsize */
277 FALSE, /* pc_relative */
278 0, /* bitpos */
279 complain_overflow_signed,/* complain_on_overflow */
280 bfd_elf_generic_reloc, /* special_function */
281 "R_ARM_SWI8", /* name */
282 FALSE, /* partial_inplace */
283 0x00000000, /* src_mask */
284 0x00000000, /* dst_mask */
285 FALSE), /* pcrel_offset */
286
287 /* BLX instruction for the ARM. */
288 HOWTO (R_ARM_XPC25, /* type */
289 2, /* rightshift */
290 2, /* size (0 = byte, 1 = short, 2 = long) */
291 25, /* bitsize */
292 TRUE, /* pc_relative */
293 0, /* bitpos */
294 complain_overflow_signed,/* complain_on_overflow */
295 bfd_elf_generic_reloc, /* special_function */
296 "R_ARM_XPC25", /* name */
297 FALSE, /* partial_inplace */
298 0x00ffffff, /* src_mask */
299 0x00ffffff, /* dst_mask */
300 TRUE), /* pcrel_offset */
301
302 /* BLX instruction for the Thumb. */
303 HOWTO (R_ARM_THM_XPC22, /* type */
304 2, /* rightshift */
305 2, /* size (0 = byte, 1 = short, 2 = long) */
306 22, /* bitsize */
307 TRUE, /* pc_relative */
308 0, /* bitpos */
309 complain_overflow_signed,/* complain_on_overflow */
310 bfd_elf_generic_reloc, /* special_function */
311 "R_ARM_THM_XPC22", /* name */
312 FALSE, /* partial_inplace */
313 0x07ff07ff, /* src_mask */
314 0x07ff07ff, /* dst_mask */
315 TRUE), /* pcrel_offset */
316
ba93b8ac 317 /* Dynamic TLS relocations. */
7f266840 318
ba93b8ac
DJ
319 HOWTO (R_ARM_TLS_DTPMOD32, /* type */
320 0, /* rightshift */
321 2, /* size (0 = byte, 1 = short, 2 = long) */
322 32, /* bitsize */
323 FALSE, /* pc_relative */
324 0, /* bitpos */
325 complain_overflow_bitfield,/* complain_on_overflow */
326 bfd_elf_generic_reloc, /* special_function */
327 "R_ARM_TLS_DTPMOD32", /* name */
328 TRUE, /* partial_inplace */
329 0xffffffff, /* src_mask */
330 0xffffffff, /* dst_mask */
331 FALSE), /* pcrel_offset */
7f266840 332
ba93b8ac
DJ
333 HOWTO (R_ARM_TLS_DTPOFF32, /* type */
334 0, /* rightshift */
335 2, /* size (0 = byte, 1 = short, 2 = long) */
336 32, /* bitsize */
337 FALSE, /* pc_relative */
338 0, /* bitpos */
339 complain_overflow_bitfield,/* complain_on_overflow */
340 bfd_elf_generic_reloc, /* special_function */
341 "R_ARM_TLS_DTPOFF32", /* name */
342 TRUE, /* partial_inplace */
343 0xffffffff, /* src_mask */
344 0xffffffff, /* dst_mask */
345 FALSE), /* pcrel_offset */
7f266840 346
ba93b8ac
DJ
347 HOWTO (R_ARM_TLS_TPOFF32, /* type */
348 0, /* rightshift */
349 2, /* size (0 = byte, 1 = short, 2 = long) */
350 32, /* bitsize */
351 FALSE, /* pc_relative */
352 0, /* bitpos */
353 complain_overflow_bitfield,/* complain_on_overflow */
354 bfd_elf_generic_reloc, /* special_function */
355 "R_ARM_TLS_TPOFF32", /* name */
356 TRUE, /* partial_inplace */
357 0xffffffff, /* src_mask */
358 0xffffffff, /* dst_mask */
359 FALSE), /* pcrel_offset */
7f266840
DJ
360
361 /* Relocs used in ARM Linux */
362
363 HOWTO (R_ARM_COPY, /* type */
364 0, /* rightshift */
365 2, /* size (0 = byte, 1 = short, 2 = long) */
366 32, /* bitsize */
367 FALSE, /* pc_relative */
368 0, /* bitpos */
369 complain_overflow_bitfield,/* complain_on_overflow */
370 bfd_elf_generic_reloc, /* special_function */
371 "R_ARM_COPY", /* name */
372 TRUE, /* partial_inplace */
373 0xffffffff, /* src_mask */
374 0xffffffff, /* dst_mask */
375 FALSE), /* pcrel_offset */
376
377 HOWTO (R_ARM_GLOB_DAT, /* type */
378 0, /* rightshift */
379 2, /* size (0 = byte, 1 = short, 2 = long) */
380 32, /* bitsize */
381 FALSE, /* pc_relative */
382 0, /* bitpos */
383 complain_overflow_bitfield,/* complain_on_overflow */
384 bfd_elf_generic_reloc, /* special_function */
385 "R_ARM_GLOB_DAT", /* name */
386 TRUE, /* partial_inplace */
387 0xffffffff, /* src_mask */
388 0xffffffff, /* dst_mask */
389 FALSE), /* pcrel_offset */
390
391 HOWTO (R_ARM_JUMP_SLOT, /* type */
392 0, /* rightshift */
393 2, /* size (0 = byte, 1 = short, 2 = long) */
394 32, /* bitsize */
395 FALSE, /* pc_relative */
396 0, /* bitpos */
397 complain_overflow_bitfield,/* complain_on_overflow */
398 bfd_elf_generic_reloc, /* special_function */
399 "R_ARM_JUMP_SLOT", /* name */
400 TRUE, /* partial_inplace */
401 0xffffffff, /* src_mask */
402 0xffffffff, /* dst_mask */
403 FALSE), /* pcrel_offset */
404
405 HOWTO (R_ARM_RELATIVE, /* type */
406 0, /* rightshift */
407 2, /* size (0 = byte, 1 = short, 2 = long) */
408 32, /* bitsize */
409 FALSE, /* pc_relative */
410 0, /* bitpos */
411 complain_overflow_bitfield,/* complain_on_overflow */
412 bfd_elf_generic_reloc, /* special_function */
413 "R_ARM_RELATIVE", /* name */
414 TRUE, /* partial_inplace */
415 0xffffffff, /* src_mask */
416 0xffffffff, /* dst_mask */
417 FALSE), /* pcrel_offset */
418
c19d1205 419 HOWTO (R_ARM_GOTOFF32, /* type */
7f266840
DJ
420 0, /* rightshift */
421 2, /* size (0 = byte, 1 = short, 2 = long) */
422 32, /* bitsize */
423 FALSE, /* pc_relative */
424 0, /* bitpos */
425 complain_overflow_bitfield,/* complain_on_overflow */
426 bfd_elf_generic_reloc, /* special_function */
c19d1205 427 "R_ARM_GOTOFF32", /* name */
7f266840
DJ
428 TRUE, /* partial_inplace */
429 0xffffffff, /* src_mask */
430 0xffffffff, /* dst_mask */
431 FALSE), /* pcrel_offset */
432
433 HOWTO (R_ARM_GOTPC, /* type */
434 0, /* rightshift */
435 2, /* size (0 = byte, 1 = short, 2 = long) */
436 32, /* bitsize */
437 TRUE, /* pc_relative */
438 0, /* bitpos */
439 complain_overflow_bitfield,/* complain_on_overflow */
440 bfd_elf_generic_reloc, /* special_function */
441 "R_ARM_GOTPC", /* name */
442 TRUE, /* partial_inplace */
443 0xffffffff, /* src_mask */
444 0xffffffff, /* dst_mask */
445 TRUE), /* pcrel_offset */
446
447 HOWTO (R_ARM_GOT32, /* type */
448 0, /* rightshift */
449 2, /* size (0 = byte, 1 = short, 2 = long) */
450 32, /* bitsize */
451 FALSE, /* pc_relative */
452 0, /* bitpos */
453 complain_overflow_bitfield,/* complain_on_overflow */
454 bfd_elf_generic_reloc, /* special_function */
455 "R_ARM_GOT32", /* name */
456 TRUE, /* partial_inplace */
457 0xffffffff, /* src_mask */
458 0xffffffff, /* dst_mask */
459 FALSE), /* pcrel_offset */
460
461 HOWTO (R_ARM_PLT32, /* type */
462 2, /* rightshift */
463 2, /* size (0 = byte, 1 = short, 2 = long) */
ce490eda 464 24, /* bitsize */
7f266840
DJ
465 TRUE, /* pc_relative */
466 0, /* bitpos */
467 complain_overflow_bitfield,/* complain_on_overflow */
468 bfd_elf_generic_reloc, /* special_function */
469 "R_ARM_PLT32", /* name */
ce490eda 470 FALSE, /* partial_inplace */
7f266840
DJ
471 0x00ffffff, /* src_mask */
472 0x00ffffff, /* dst_mask */
473 TRUE), /* pcrel_offset */
474
475 HOWTO (R_ARM_CALL, /* type */
476 2, /* rightshift */
477 2, /* size (0 = byte, 1 = short, 2 = long) */
478 24, /* bitsize */
479 TRUE, /* pc_relative */
480 0, /* bitpos */
481 complain_overflow_signed,/* complain_on_overflow */
482 bfd_elf_generic_reloc, /* special_function */
483 "R_ARM_CALL", /* name */
484 FALSE, /* partial_inplace */
485 0x00ffffff, /* src_mask */
486 0x00ffffff, /* dst_mask */
487 TRUE), /* pcrel_offset */
488
489 HOWTO (R_ARM_JUMP24, /* type */
490 2, /* rightshift */
491 2, /* size (0 = byte, 1 = short, 2 = long) */
492 24, /* bitsize */
493 TRUE, /* pc_relative */
494 0, /* bitpos */
495 complain_overflow_signed,/* complain_on_overflow */
496 bfd_elf_generic_reloc, /* special_function */
497 "R_ARM_JUMP24", /* name */
498 FALSE, /* partial_inplace */
499 0x00ffffff, /* src_mask */
500 0x00ffffff, /* dst_mask */
501 TRUE), /* pcrel_offset */
502
c19d1205
ZW
503 HOWTO (R_ARM_THM_JUMP24, /* type */
504 1, /* rightshift */
505 2, /* size (0 = byte, 1 = short, 2 = long) */
506 24, /* bitsize */
507 TRUE, /* pc_relative */
7f266840 508 0, /* bitpos */
c19d1205 509 complain_overflow_signed,/* complain_on_overflow */
7f266840 510 bfd_elf_generic_reloc, /* special_function */
c19d1205 511 "R_ARM_THM_JUMP24", /* name */
7f266840 512 FALSE, /* partial_inplace */
c19d1205
ZW
513 0x07ff2fff, /* src_mask */
514 0x07ff2fff, /* dst_mask */
515 TRUE), /* pcrel_offset */
7f266840 516
c19d1205 517 HOWTO (R_ARM_BASE_ABS, /* type */
7f266840 518 0, /* rightshift */
c19d1205
ZW
519 2, /* size (0 = byte, 1 = short, 2 = long) */
520 32, /* bitsize */
7f266840
DJ
521 FALSE, /* pc_relative */
522 0, /* bitpos */
523 complain_overflow_dont,/* complain_on_overflow */
524 bfd_elf_generic_reloc, /* special_function */
c19d1205 525 "R_ARM_BASE_ABS", /* name */
7f266840 526 FALSE, /* partial_inplace */
c19d1205
ZW
527 0xffffffff, /* src_mask */
528 0xffffffff, /* dst_mask */
7f266840
DJ
529 FALSE), /* pcrel_offset */
530
531 HOWTO (R_ARM_ALU_PCREL7_0, /* type */
532 0, /* rightshift */
533 2, /* size (0 = byte, 1 = short, 2 = long) */
534 12, /* bitsize */
535 TRUE, /* pc_relative */
536 0, /* bitpos */
537 complain_overflow_dont,/* complain_on_overflow */
538 bfd_elf_generic_reloc, /* special_function */
539 "R_ARM_ALU_PCREL_7_0", /* name */
540 FALSE, /* partial_inplace */
541 0x00000fff, /* src_mask */
542 0x00000fff, /* dst_mask */
543 TRUE), /* pcrel_offset */
544
545 HOWTO (R_ARM_ALU_PCREL15_8, /* type */
546 0, /* rightshift */
547 2, /* size (0 = byte, 1 = short, 2 = long) */
548 12, /* bitsize */
549 TRUE, /* pc_relative */
550 8, /* bitpos */
551 complain_overflow_dont,/* complain_on_overflow */
552 bfd_elf_generic_reloc, /* special_function */
553 "R_ARM_ALU_PCREL_15_8",/* name */
554 FALSE, /* partial_inplace */
555 0x00000fff, /* src_mask */
556 0x00000fff, /* dst_mask */
557 TRUE), /* pcrel_offset */
558
559 HOWTO (R_ARM_ALU_PCREL23_15, /* type */
560 0, /* rightshift */
561 2, /* size (0 = byte, 1 = short, 2 = long) */
562 12, /* bitsize */
563 TRUE, /* pc_relative */
564 16, /* bitpos */
565 complain_overflow_dont,/* complain_on_overflow */
566 bfd_elf_generic_reloc, /* special_function */
567 "R_ARM_ALU_PCREL_23_15",/* name */
568 FALSE, /* partial_inplace */
569 0x00000fff, /* src_mask */
570 0x00000fff, /* dst_mask */
571 TRUE), /* pcrel_offset */
572
573 HOWTO (R_ARM_LDR_SBREL_11_0, /* type */
574 0, /* rightshift */
575 2, /* size (0 = byte, 1 = short, 2 = long) */
576 12, /* bitsize */
577 FALSE, /* pc_relative */
578 0, /* bitpos */
579 complain_overflow_dont,/* complain_on_overflow */
580 bfd_elf_generic_reloc, /* special_function */
581 "R_ARM_LDR_SBREL_11_0",/* name */
582 FALSE, /* partial_inplace */
583 0x00000fff, /* src_mask */
584 0x00000fff, /* dst_mask */
585 FALSE), /* pcrel_offset */
586
587 HOWTO (R_ARM_ALU_SBREL_19_12, /* type */
588 0, /* rightshift */
589 2, /* size (0 = byte, 1 = short, 2 = long) */
590 8, /* bitsize */
591 FALSE, /* pc_relative */
592 12, /* bitpos */
593 complain_overflow_dont,/* complain_on_overflow */
594 bfd_elf_generic_reloc, /* special_function */
595 "R_ARM_ALU_SBREL_19_12",/* name */
596 FALSE, /* partial_inplace */
597 0x000ff000, /* src_mask */
598 0x000ff000, /* dst_mask */
599 FALSE), /* pcrel_offset */
600
601 HOWTO (R_ARM_ALU_SBREL_27_20, /* type */
602 0, /* rightshift */
603 2, /* size (0 = byte, 1 = short, 2 = long) */
604 8, /* bitsize */
605 FALSE, /* pc_relative */
606 20, /* bitpos */
607 complain_overflow_dont,/* complain_on_overflow */
608 bfd_elf_generic_reloc, /* special_function */
609 "R_ARM_ALU_SBREL_27_20",/* name */
610 FALSE, /* partial_inplace */
611 0x0ff00000, /* src_mask */
612 0x0ff00000, /* dst_mask */
613 FALSE), /* pcrel_offset */
614
615 HOWTO (R_ARM_TARGET1, /* type */
616 0, /* rightshift */
617 2, /* size (0 = byte, 1 = short, 2 = long) */
618 32, /* bitsize */
619 FALSE, /* pc_relative */
620 0, /* bitpos */
621 complain_overflow_dont,/* complain_on_overflow */
622 bfd_elf_generic_reloc, /* special_function */
623 "R_ARM_TARGET1", /* name */
624 FALSE, /* partial_inplace */
625 0xffffffff, /* src_mask */
626 0xffffffff, /* dst_mask */
627 FALSE), /* pcrel_offset */
628
629 HOWTO (R_ARM_ROSEGREL32, /* type */
630 0, /* rightshift */
631 2, /* size (0 = byte, 1 = short, 2 = long) */
632 32, /* bitsize */
633 FALSE, /* pc_relative */
634 0, /* bitpos */
635 complain_overflow_dont,/* complain_on_overflow */
636 bfd_elf_generic_reloc, /* special_function */
637 "R_ARM_ROSEGREL32", /* name */
638 FALSE, /* partial_inplace */
639 0xffffffff, /* src_mask */
640 0xffffffff, /* dst_mask */
641 FALSE), /* pcrel_offset */
642
643 HOWTO (R_ARM_V4BX, /* type */
644 0, /* rightshift */
645 2, /* size (0 = byte, 1 = short, 2 = long) */
646 32, /* bitsize */
647 FALSE, /* pc_relative */
648 0, /* bitpos */
649 complain_overflow_dont,/* complain_on_overflow */
650 bfd_elf_generic_reloc, /* special_function */
651 "R_ARM_V4BX", /* name */
652 FALSE, /* partial_inplace */
653 0xffffffff, /* src_mask */
654 0xffffffff, /* dst_mask */
655 FALSE), /* pcrel_offset */
656
657 HOWTO (R_ARM_TARGET2, /* type */
658 0, /* rightshift */
659 2, /* size (0 = byte, 1 = short, 2 = long) */
660 32, /* bitsize */
661 FALSE, /* pc_relative */
662 0, /* bitpos */
663 complain_overflow_signed,/* complain_on_overflow */
664 bfd_elf_generic_reloc, /* special_function */
665 "R_ARM_TARGET2", /* name */
666 FALSE, /* partial_inplace */
667 0xffffffff, /* src_mask */
668 0xffffffff, /* dst_mask */
669 TRUE), /* pcrel_offset */
670
671 HOWTO (R_ARM_PREL31, /* type */
672 0, /* rightshift */
673 2, /* size (0 = byte, 1 = short, 2 = long) */
674 31, /* bitsize */
675 TRUE, /* pc_relative */
676 0, /* bitpos */
677 complain_overflow_signed,/* complain_on_overflow */
678 bfd_elf_generic_reloc, /* special_function */
679 "R_ARM_PREL31", /* name */
680 FALSE, /* partial_inplace */
681 0x7fffffff, /* src_mask */
682 0x7fffffff, /* dst_mask */
683 TRUE), /* pcrel_offset */
c19d1205
ZW
684
685 HOWTO (R_ARM_MOVW_ABS_NC, /* type */
686 0, /* rightshift */
687 2, /* size (0 = byte, 1 = short, 2 = long) */
688 16, /* bitsize */
689 FALSE, /* pc_relative */
690 0, /* bitpos */
691 complain_overflow_dont,/* complain_on_overflow */
692 bfd_elf_generic_reloc, /* special_function */
693 "R_ARM_MOVW_ABS_NC", /* name */
694 FALSE, /* partial_inplace */
39623e12
PB
695 0x000f0fff, /* src_mask */
696 0x000f0fff, /* dst_mask */
c19d1205
ZW
697 FALSE), /* pcrel_offset */
698
699 HOWTO (R_ARM_MOVT_ABS, /* type */
700 0, /* rightshift */
701 2, /* size (0 = byte, 1 = short, 2 = long) */
702 16, /* bitsize */
703 FALSE, /* pc_relative */
704 0, /* bitpos */
705 complain_overflow_bitfield,/* complain_on_overflow */
706 bfd_elf_generic_reloc, /* special_function */
707 "R_ARM_MOVT_ABS", /* name */
708 FALSE, /* partial_inplace */
39623e12
PB
709 0x000f0fff, /* src_mask */
710 0x000f0fff, /* dst_mask */
c19d1205
ZW
711 FALSE), /* pcrel_offset */
712
713 HOWTO (R_ARM_MOVW_PREL_NC, /* type */
714 0, /* rightshift */
715 2, /* size (0 = byte, 1 = short, 2 = long) */
716 16, /* bitsize */
717 TRUE, /* pc_relative */
718 0, /* bitpos */
719 complain_overflow_dont,/* complain_on_overflow */
720 bfd_elf_generic_reloc, /* special_function */
721 "R_ARM_MOVW_PREL_NC", /* name */
722 FALSE, /* partial_inplace */
39623e12
PB
723 0x000f0fff, /* src_mask */
724 0x000f0fff, /* dst_mask */
c19d1205
ZW
725 TRUE), /* pcrel_offset */
726
727 HOWTO (R_ARM_MOVT_PREL, /* type */
728 0, /* rightshift */
729 2, /* size (0 = byte, 1 = short, 2 = long) */
730 16, /* bitsize */
731 TRUE, /* pc_relative */
732 0, /* bitpos */
733 complain_overflow_bitfield,/* complain_on_overflow */
734 bfd_elf_generic_reloc, /* special_function */
735 "R_ARM_MOVT_PREL", /* name */
736 FALSE, /* partial_inplace */
39623e12
PB
737 0x000f0fff, /* src_mask */
738 0x000f0fff, /* dst_mask */
c19d1205
ZW
739 TRUE), /* pcrel_offset */
740
741 HOWTO (R_ARM_THM_MOVW_ABS_NC, /* type */
742 0, /* rightshift */
743 2, /* size (0 = byte, 1 = short, 2 = long) */
744 16, /* bitsize */
745 FALSE, /* pc_relative */
746 0, /* bitpos */
747 complain_overflow_dont,/* complain_on_overflow */
748 bfd_elf_generic_reloc, /* special_function */
749 "R_ARM_THM_MOVW_ABS_NC",/* name */
750 FALSE, /* partial_inplace */
751 0x040f70ff, /* src_mask */
752 0x040f70ff, /* dst_mask */
753 FALSE), /* pcrel_offset */
754
755 HOWTO (R_ARM_THM_MOVT_ABS, /* type */
756 0, /* rightshift */
757 2, /* size (0 = byte, 1 = short, 2 = long) */
758 16, /* bitsize */
759 FALSE, /* pc_relative */
760 0, /* bitpos */
761 complain_overflow_bitfield,/* complain_on_overflow */
762 bfd_elf_generic_reloc, /* special_function */
763 "R_ARM_THM_MOVT_ABS", /* name */
764 FALSE, /* partial_inplace */
765 0x040f70ff, /* src_mask */
766 0x040f70ff, /* dst_mask */
767 FALSE), /* pcrel_offset */
768
769 HOWTO (R_ARM_THM_MOVW_PREL_NC,/* type */
770 0, /* rightshift */
771 2, /* size (0 = byte, 1 = short, 2 = long) */
772 16, /* bitsize */
773 TRUE, /* pc_relative */
774 0, /* bitpos */
775 complain_overflow_dont,/* complain_on_overflow */
776 bfd_elf_generic_reloc, /* special_function */
777 "R_ARM_THM_MOVW_PREL_NC",/* name */
778 FALSE, /* partial_inplace */
779 0x040f70ff, /* src_mask */
780 0x040f70ff, /* dst_mask */
781 TRUE), /* pcrel_offset */
782
783 HOWTO (R_ARM_THM_MOVT_PREL, /* type */
784 0, /* rightshift */
785 2, /* size (0 = byte, 1 = short, 2 = long) */
786 16, /* bitsize */
787 TRUE, /* pc_relative */
788 0, /* bitpos */
789 complain_overflow_bitfield,/* complain_on_overflow */
790 bfd_elf_generic_reloc, /* special_function */
791 "R_ARM_THM_MOVT_PREL", /* name */
792 FALSE, /* partial_inplace */
793 0x040f70ff, /* src_mask */
794 0x040f70ff, /* dst_mask */
795 TRUE), /* pcrel_offset */
796
797 HOWTO (R_ARM_THM_JUMP19, /* type */
798 1, /* rightshift */
799 2, /* size (0 = byte, 1 = short, 2 = long) */
800 19, /* bitsize */
801 TRUE, /* pc_relative */
802 0, /* bitpos */
803 complain_overflow_signed,/* complain_on_overflow */
804 bfd_elf_generic_reloc, /* special_function */
805 "R_ARM_THM_JUMP19", /* name */
806 FALSE, /* partial_inplace */
807 0x043f2fff, /* src_mask */
808 0x043f2fff, /* dst_mask */
809 TRUE), /* pcrel_offset */
810
811 HOWTO (R_ARM_THM_JUMP6, /* type */
812 1, /* rightshift */
813 1, /* size (0 = byte, 1 = short, 2 = long) */
814 6, /* bitsize */
815 TRUE, /* pc_relative */
816 0, /* bitpos */
817 complain_overflow_unsigned,/* complain_on_overflow */
818 bfd_elf_generic_reloc, /* special_function */
819 "R_ARM_THM_JUMP6", /* name */
820 FALSE, /* partial_inplace */
821 0x02f8, /* src_mask */
822 0x02f8, /* dst_mask */
823 TRUE), /* pcrel_offset */
824
825 /* These are declared as 13-bit signed relocations because we can
826 address -4095 .. 4095(base) by altering ADDW to SUBW or vice
827 versa. */
828 HOWTO (R_ARM_THM_ALU_PREL_11_0,/* type */
829 0, /* rightshift */
830 2, /* size (0 = byte, 1 = short, 2 = long) */
831 13, /* bitsize */
832 TRUE, /* pc_relative */
833 0, /* bitpos */
2cab6cc3 834 complain_overflow_dont,/* complain_on_overflow */
c19d1205
ZW
835 bfd_elf_generic_reloc, /* special_function */
836 "R_ARM_THM_ALU_PREL_11_0",/* name */
837 FALSE, /* partial_inplace */
2cab6cc3
MS
838 0xffffffff, /* src_mask */
839 0xffffffff, /* dst_mask */
c19d1205
ZW
840 TRUE), /* pcrel_offset */
841
842 HOWTO (R_ARM_THM_PC12, /* type */
843 0, /* rightshift */
844 2, /* size (0 = byte, 1 = short, 2 = long) */
845 13, /* bitsize */
846 TRUE, /* pc_relative */
847 0, /* bitpos */
2cab6cc3 848 complain_overflow_dont,/* complain_on_overflow */
c19d1205
ZW
849 bfd_elf_generic_reloc, /* special_function */
850 "R_ARM_THM_PC12", /* name */
851 FALSE, /* partial_inplace */
2cab6cc3
MS
852 0xffffffff, /* src_mask */
853 0xffffffff, /* dst_mask */
c19d1205
ZW
854 TRUE), /* pcrel_offset */
855
856 HOWTO (R_ARM_ABS32_NOI, /* type */
857 0, /* rightshift */
858 2, /* size (0 = byte, 1 = short, 2 = long) */
859 32, /* bitsize */
860 FALSE, /* pc_relative */
861 0, /* bitpos */
862 complain_overflow_dont,/* complain_on_overflow */
863 bfd_elf_generic_reloc, /* special_function */
864 "R_ARM_ABS32_NOI", /* name */
865 FALSE, /* partial_inplace */
866 0xffffffff, /* src_mask */
867 0xffffffff, /* dst_mask */
868 FALSE), /* pcrel_offset */
869
870 HOWTO (R_ARM_REL32_NOI, /* type */
871 0, /* rightshift */
872 2, /* size (0 = byte, 1 = short, 2 = long) */
873 32, /* bitsize */
874 TRUE, /* pc_relative */
875 0, /* bitpos */
876 complain_overflow_dont,/* complain_on_overflow */
877 bfd_elf_generic_reloc, /* special_function */
878 "R_ARM_REL32_NOI", /* name */
879 FALSE, /* partial_inplace */
880 0xffffffff, /* src_mask */
881 0xffffffff, /* dst_mask */
882 FALSE), /* pcrel_offset */
7f266840 883
4962c51a
MS
884 /* Group relocations. */
885
886 HOWTO (R_ARM_ALU_PC_G0_NC, /* type */
887 0, /* rightshift */
888 2, /* size (0 = byte, 1 = short, 2 = long) */
889 32, /* bitsize */
890 TRUE, /* pc_relative */
891 0, /* bitpos */
892 complain_overflow_dont,/* complain_on_overflow */
893 bfd_elf_generic_reloc, /* special_function */
894 "R_ARM_ALU_PC_G0_NC", /* name */
895 FALSE, /* partial_inplace */
896 0xffffffff, /* src_mask */
897 0xffffffff, /* dst_mask */
898 TRUE), /* pcrel_offset */
899
900 HOWTO (R_ARM_ALU_PC_G0, /* type */
901 0, /* rightshift */
902 2, /* size (0 = byte, 1 = short, 2 = long) */
903 32, /* bitsize */
904 TRUE, /* pc_relative */
905 0, /* bitpos */
906 complain_overflow_dont,/* complain_on_overflow */
907 bfd_elf_generic_reloc, /* special_function */
908 "R_ARM_ALU_PC_G0", /* name */
909 FALSE, /* partial_inplace */
910 0xffffffff, /* src_mask */
911 0xffffffff, /* dst_mask */
912 TRUE), /* pcrel_offset */
913
914 HOWTO (R_ARM_ALU_PC_G1_NC, /* type */
915 0, /* rightshift */
916 2, /* size (0 = byte, 1 = short, 2 = long) */
917 32, /* bitsize */
918 TRUE, /* pc_relative */
919 0, /* bitpos */
920 complain_overflow_dont,/* complain_on_overflow */
921 bfd_elf_generic_reloc, /* special_function */
922 "R_ARM_ALU_PC_G1_NC", /* name */
923 FALSE, /* partial_inplace */
924 0xffffffff, /* src_mask */
925 0xffffffff, /* dst_mask */
926 TRUE), /* pcrel_offset */
927
928 HOWTO (R_ARM_ALU_PC_G1, /* type */
929 0, /* rightshift */
930 2, /* size (0 = byte, 1 = short, 2 = long) */
931 32, /* bitsize */
932 TRUE, /* pc_relative */
933 0, /* bitpos */
934 complain_overflow_dont,/* complain_on_overflow */
935 bfd_elf_generic_reloc, /* special_function */
936 "R_ARM_ALU_PC_G1", /* name */
937 FALSE, /* partial_inplace */
938 0xffffffff, /* src_mask */
939 0xffffffff, /* dst_mask */
940 TRUE), /* pcrel_offset */
941
942 HOWTO (R_ARM_ALU_PC_G2, /* type */
943 0, /* rightshift */
944 2, /* size (0 = byte, 1 = short, 2 = long) */
945 32, /* bitsize */
946 TRUE, /* pc_relative */
947 0, /* bitpos */
948 complain_overflow_dont,/* complain_on_overflow */
949 bfd_elf_generic_reloc, /* special_function */
950 "R_ARM_ALU_PC_G2", /* name */
951 FALSE, /* partial_inplace */
952 0xffffffff, /* src_mask */
953 0xffffffff, /* dst_mask */
954 TRUE), /* pcrel_offset */
955
956 HOWTO (R_ARM_LDR_PC_G1, /* type */
957 0, /* rightshift */
958 2, /* size (0 = byte, 1 = short, 2 = long) */
959 32, /* bitsize */
960 TRUE, /* pc_relative */
961 0, /* bitpos */
962 complain_overflow_dont,/* complain_on_overflow */
963 bfd_elf_generic_reloc, /* special_function */
964 "R_ARM_LDR_PC_G1", /* name */
965 FALSE, /* partial_inplace */
966 0xffffffff, /* src_mask */
967 0xffffffff, /* dst_mask */
968 TRUE), /* pcrel_offset */
969
970 HOWTO (R_ARM_LDR_PC_G2, /* type */
971 0, /* rightshift */
972 2, /* size (0 = byte, 1 = short, 2 = long) */
973 32, /* bitsize */
974 TRUE, /* pc_relative */
975 0, /* bitpos */
976 complain_overflow_dont,/* complain_on_overflow */
977 bfd_elf_generic_reloc, /* special_function */
978 "R_ARM_LDR_PC_G2", /* name */
979 FALSE, /* partial_inplace */
980 0xffffffff, /* src_mask */
981 0xffffffff, /* dst_mask */
982 TRUE), /* pcrel_offset */
983
984 HOWTO (R_ARM_LDRS_PC_G0, /* type */
985 0, /* rightshift */
986 2, /* size (0 = byte, 1 = short, 2 = long) */
987 32, /* bitsize */
988 TRUE, /* pc_relative */
989 0, /* bitpos */
990 complain_overflow_dont,/* complain_on_overflow */
991 bfd_elf_generic_reloc, /* special_function */
992 "R_ARM_LDRS_PC_G0", /* name */
993 FALSE, /* partial_inplace */
994 0xffffffff, /* src_mask */
995 0xffffffff, /* dst_mask */
996 TRUE), /* pcrel_offset */
997
998 HOWTO (R_ARM_LDRS_PC_G1, /* type */
999 0, /* rightshift */
1000 2, /* size (0 = byte, 1 = short, 2 = long) */
1001 32, /* bitsize */
1002 TRUE, /* pc_relative */
1003 0, /* bitpos */
1004 complain_overflow_dont,/* complain_on_overflow */
1005 bfd_elf_generic_reloc, /* special_function */
1006 "R_ARM_LDRS_PC_G1", /* name */
1007 FALSE, /* partial_inplace */
1008 0xffffffff, /* src_mask */
1009 0xffffffff, /* dst_mask */
1010 TRUE), /* pcrel_offset */
1011
1012 HOWTO (R_ARM_LDRS_PC_G2, /* type */
1013 0, /* rightshift */
1014 2, /* size (0 = byte, 1 = short, 2 = long) */
1015 32, /* bitsize */
1016 TRUE, /* pc_relative */
1017 0, /* bitpos */
1018 complain_overflow_dont,/* complain_on_overflow */
1019 bfd_elf_generic_reloc, /* special_function */
1020 "R_ARM_LDRS_PC_G2", /* name */
1021 FALSE, /* partial_inplace */
1022 0xffffffff, /* src_mask */
1023 0xffffffff, /* dst_mask */
1024 TRUE), /* pcrel_offset */
1025
1026 HOWTO (R_ARM_LDC_PC_G0, /* type */
1027 0, /* rightshift */
1028 2, /* size (0 = byte, 1 = short, 2 = long) */
1029 32, /* bitsize */
1030 TRUE, /* pc_relative */
1031 0, /* bitpos */
1032 complain_overflow_dont,/* complain_on_overflow */
1033 bfd_elf_generic_reloc, /* special_function */
1034 "R_ARM_LDC_PC_G0", /* name */
1035 FALSE, /* partial_inplace */
1036 0xffffffff, /* src_mask */
1037 0xffffffff, /* dst_mask */
1038 TRUE), /* pcrel_offset */
1039
1040 HOWTO (R_ARM_LDC_PC_G1, /* type */
1041 0, /* rightshift */
1042 2, /* size (0 = byte, 1 = short, 2 = long) */
1043 32, /* bitsize */
1044 TRUE, /* pc_relative */
1045 0, /* bitpos */
1046 complain_overflow_dont,/* complain_on_overflow */
1047 bfd_elf_generic_reloc, /* special_function */
1048 "R_ARM_LDC_PC_G1", /* name */
1049 FALSE, /* partial_inplace */
1050 0xffffffff, /* src_mask */
1051 0xffffffff, /* dst_mask */
1052 TRUE), /* pcrel_offset */
1053
1054 HOWTO (R_ARM_LDC_PC_G2, /* type */
1055 0, /* rightshift */
1056 2, /* size (0 = byte, 1 = short, 2 = long) */
1057 32, /* bitsize */
1058 TRUE, /* pc_relative */
1059 0, /* bitpos */
1060 complain_overflow_dont,/* complain_on_overflow */
1061 bfd_elf_generic_reloc, /* special_function */
1062 "R_ARM_LDC_PC_G2", /* name */
1063 FALSE, /* partial_inplace */
1064 0xffffffff, /* src_mask */
1065 0xffffffff, /* dst_mask */
1066 TRUE), /* pcrel_offset */
1067
1068 HOWTO (R_ARM_ALU_SB_G0_NC, /* type */
1069 0, /* rightshift */
1070 2, /* size (0 = byte, 1 = short, 2 = long) */
1071 32, /* bitsize */
1072 TRUE, /* pc_relative */
1073 0, /* bitpos */
1074 complain_overflow_dont,/* complain_on_overflow */
1075 bfd_elf_generic_reloc, /* special_function */
1076 "R_ARM_ALU_SB_G0_NC", /* name */
1077 FALSE, /* partial_inplace */
1078 0xffffffff, /* src_mask */
1079 0xffffffff, /* dst_mask */
1080 TRUE), /* pcrel_offset */
1081
1082 HOWTO (R_ARM_ALU_SB_G0, /* type */
1083 0, /* rightshift */
1084 2, /* size (0 = byte, 1 = short, 2 = long) */
1085 32, /* bitsize */
1086 TRUE, /* pc_relative */
1087 0, /* bitpos */
1088 complain_overflow_dont,/* complain_on_overflow */
1089 bfd_elf_generic_reloc, /* special_function */
1090 "R_ARM_ALU_SB_G0", /* name */
1091 FALSE, /* partial_inplace */
1092 0xffffffff, /* src_mask */
1093 0xffffffff, /* dst_mask */
1094 TRUE), /* pcrel_offset */
1095
1096 HOWTO (R_ARM_ALU_SB_G1_NC, /* type */
1097 0, /* rightshift */
1098 2, /* size (0 = byte, 1 = short, 2 = long) */
1099 32, /* bitsize */
1100 TRUE, /* pc_relative */
1101 0, /* bitpos */
1102 complain_overflow_dont,/* complain_on_overflow */
1103 bfd_elf_generic_reloc, /* special_function */
1104 "R_ARM_ALU_SB_G1_NC", /* name */
1105 FALSE, /* partial_inplace */
1106 0xffffffff, /* src_mask */
1107 0xffffffff, /* dst_mask */
1108 TRUE), /* pcrel_offset */
1109
1110 HOWTO (R_ARM_ALU_SB_G1, /* type */
1111 0, /* rightshift */
1112 2, /* size (0 = byte, 1 = short, 2 = long) */
1113 32, /* bitsize */
1114 TRUE, /* pc_relative */
1115 0, /* bitpos */
1116 complain_overflow_dont,/* complain_on_overflow */
1117 bfd_elf_generic_reloc, /* special_function */
1118 "R_ARM_ALU_SB_G1", /* name */
1119 FALSE, /* partial_inplace */
1120 0xffffffff, /* src_mask */
1121 0xffffffff, /* dst_mask */
1122 TRUE), /* pcrel_offset */
1123
1124 HOWTO (R_ARM_ALU_SB_G2, /* type */
1125 0, /* rightshift */
1126 2, /* size (0 = byte, 1 = short, 2 = long) */
1127 32, /* bitsize */
1128 TRUE, /* pc_relative */
1129 0, /* bitpos */
1130 complain_overflow_dont,/* complain_on_overflow */
1131 bfd_elf_generic_reloc, /* special_function */
1132 "R_ARM_ALU_SB_G2", /* name */
1133 FALSE, /* partial_inplace */
1134 0xffffffff, /* src_mask */
1135 0xffffffff, /* dst_mask */
1136 TRUE), /* pcrel_offset */
1137
1138 HOWTO (R_ARM_LDR_SB_G0, /* type */
1139 0, /* rightshift */
1140 2, /* size (0 = byte, 1 = short, 2 = long) */
1141 32, /* bitsize */
1142 TRUE, /* pc_relative */
1143 0, /* bitpos */
1144 complain_overflow_dont,/* complain_on_overflow */
1145 bfd_elf_generic_reloc, /* special_function */
1146 "R_ARM_LDR_SB_G0", /* name */
1147 FALSE, /* partial_inplace */
1148 0xffffffff, /* src_mask */
1149 0xffffffff, /* dst_mask */
1150 TRUE), /* pcrel_offset */
1151
1152 HOWTO (R_ARM_LDR_SB_G1, /* type */
1153 0, /* rightshift */
1154 2, /* size (0 = byte, 1 = short, 2 = long) */
1155 32, /* bitsize */
1156 TRUE, /* pc_relative */
1157 0, /* bitpos */
1158 complain_overflow_dont,/* complain_on_overflow */
1159 bfd_elf_generic_reloc, /* special_function */
1160 "R_ARM_LDR_SB_G1", /* name */
1161 FALSE, /* partial_inplace */
1162 0xffffffff, /* src_mask */
1163 0xffffffff, /* dst_mask */
1164 TRUE), /* pcrel_offset */
1165
1166 HOWTO (R_ARM_LDR_SB_G2, /* type */
1167 0, /* rightshift */
1168 2, /* size (0 = byte, 1 = short, 2 = long) */
1169 32, /* bitsize */
1170 TRUE, /* pc_relative */
1171 0, /* bitpos */
1172 complain_overflow_dont,/* complain_on_overflow */
1173 bfd_elf_generic_reloc, /* special_function */
1174 "R_ARM_LDR_SB_G2", /* name */
1175 FALSE, /* partial_inplace */
1176 0xffffffff, /* src_mask */
1177 0xffffffff, /* dst_mask */
1178 TRUE), /* pcrel_offset */
1179
1180 HOWTO (R_ARM_LDRS_SB_G0, /* type */
1181 0, /* rightshift */
1182 2, /* size (0 = byte, 1 = short, 2 = long) */
1183 32, /* bitsize */
1184 TRUE, /* pc_relative */
1185 0, /* bitpos */
1186 complain_overflow_dont,/* complain_on_overflow */
1187 bfd_elf_generic_reloc, /* special_function */
1188 "R_ARM_LDRS_SB_G0", /* name */
1189 FALSE, /* partial_inplace */
1190 0xffffffff, /* src_mask */
1191 0xffffffff, /* dst_mask */
1192 TRUE), /* pcrel_offset */
1193
1194 HOWTO (R_ARM_LDRS_SB_G1, /* type */
1195 0, /* rightshift */
1196 2, /* size (0 = byte, 1 = short, 2 = long) */
1197 32, /* bitsize */
1198 TRUE, /* pc_relative */
1199 0, /* bitpos */
1200 complain_overflow_dont,/* complain_on_overflow */
1201 bfd_elf_generic_reloc, /* special_function */
1202 "R_ARM_LDRS_SB_G1", /* name */
1203 FALSE, /* partial_inplace */
1204 0xffffffff, /* src_mask */
1205 0xffffffff, /* dst_mask */
1206 TRUE), /* pcrel_offset */
1207
1208 HOWTO (R_ARM_LDRS_SB_G2, /* type */
1209 0, /* rightshift */
1210 2, /* size (0 = byte, 1 = short, 2 = long) */
1211 32, /* bitsize */
1212 TRUE, /* pc_relative */
1213 0, /* bitpos */
1214 complain_overflow_dont,/* complain_on_overflow */
1215 bfd_elf_generic_reloc, /* special_function */
1216 "R_ARM_LDRS_SB_G2", /* name */
1217 FALSE, /* partial_inplace */
1218 0xffffffff, /* src_mask */
1219 0xffffffff, /* dst_mask */
1220 TRUE), /* pcrel_offset */
1221
1222 HOWTO (R_ARM_LDC_SB_G0, /* type */
1223 0, /* rightshift */
1224 2, /* size (0 = byte, 1 = short, 2 = long) */
1225 32, /* bitsize */
1226 TRUE, /* pc_relative */
1227 0, /* bitpos */
1228 complain_overflow_dont,/* complain_on_overflow */
1229 bfd_elf_generic_reloc, /* special_function */
1230 "R_ARM_LDC_SB_G0", /* name */
1231 FALSE, /* partial_inplace */
1232 0xffffffff, /* src_mask */
1233 0xffffffff, /* dst_mask */
1234 TRUE), /* pcrel_offset */
1235
1236 HOWTO (R_ARM_LDC_SB_G1, /* type */
1237 0, /* rightshift */
1238 2, /* size (0 = byte, 1 = short, 2 = long) */
1239 32, /* bitsize */
1240 TRUE, /* pc_relative */
1241 0, /* bitpos */
1242 complain_overflow_dont,/* complain_on_overflow */
1243 bfd_elf_generic_reloc, /* special_function */
1244 "R_ARM_LDC_SB_G1", /* name */
1245 FALSE, /* partial_inplace */
1246 0xffffffff, /* src_mask */
1247 0xffffffff, /* dst_mask */
1248 TRUE), /* pcrel_offset */
1249
1250 HOWTO (R_ARM_LDC_SB_G2, /* type */
1251 0, /* rightshift */
1252 2, /* size (0 = byte, 1 = short, 2 = long) */
1253 32, /* bitsize */
1254 TRUE, /* pc_relative */
1255 0, /* bitpos */
1256 complain_overflow_dont,/* complain_on_overflow */
1257 bfd_elf_generic_reloc, /* special_function */
1258 "R_ARM_LDC_SB_G2", /* name */
1259 FALSE, /* partial_inplace */
1260 0xffffffff, /* src_mask */
1261 0xffffffff, /* dst_mask */
1262 TRUE), /* pcrel_offset */
1263
1264 /* End of group relocations. */
c19d1205 1265
c19d1205
ZW
1266 HOWTO (R_ARM_MOVW_BREL_NC, /* type */
1267 0, /* rightshift */
1268 2, /* size (0 = byte, 1 = short, 2 = long) */
1269 16, /* bitsize */
1270 FALSE, /* pc_relative */
1271 0, /* bitpos */
1272 complain_overflow_dont,/* complain_on_overflow */
1273 bfd_elf_generic_reloc, /* special_function */
1274 "R_ARM_MOVW_BREL_NC", /* name */
1275 FALSE, /* partial_inplace */
1276 0x0000ffff, /* src_mask */
1277 0x0000ffff, /* dst_mask */
1278 FALSE), /* pcrel_offset */
1279
1280 HOWTO (R_ARM_MOVT_BREL, /* type */
1281 0, /* rightshift */
1282 2, /* size (0 = byte, 1 = short, 2 = long) */
1283 16, /* bitsize */
1284 FALSE, /* pc_relative */
1285 0, /* bitpos */
1286 complain_overflow_bitfield,/* complain_on_overflow */
1287 bfd_elf_generic_reloc, /* special_function */
1288 "R_ARM_MOVT_BREL", /* name */
1289 FALSE, /* partial_inplace */
1290 0x0000ffff, /* src_mask */
1291 0x0000ffff, /* dst_mask */
1292 FALSE), /* pcrel_offset */
1293
1294 HOWTO (R_ARM_MOVW_BREL, /* type */
1295 0, /* rightshift */
1296 2, /* size (0 = byte, 1 = short, 2 = long) */
1297 16, /* bitsize */
1298 FALSE, /* pc_relative */
1299 0, /* bitpos */
1300 complain_overflow_dont,/* complain_on_overflow */
1301 bfd_elf_generic_reloc, /* special_function */
1302 "R_ARM_MOVW_BREL", /* name */
1303 FALSE, /* partial_inplace */
1304 0x0000ffff, /* src_mask */
1305 0x0000ffff, /* dst_mask */
1306 FALSE), /* pcrel_offset */
1307
1308 HOWTO (R_ARM_THM_MOVW_BREL_NC,/* type */
1309 0, /* rightshift */
1310 2, /* size (0 = byte, 1 = short, 2 = long) */
1311 16, /* bitsize */
1312 FALSE, /* pc_relative */
1313 0, /* bitpos */
1314 complain_overflow_dont,/* complain_on_overflow */
1315 bfd_elf_generic_reloc, /* special_function */
1316 "R_ARM_THM_MOVW_BREL_NC",/* name */
1317 FALSE, /* partial_inplace */
1318 0x040f70ff, /* src_mask */
1319 0x040f70ff, /* dst_mask */
1320 FALSE), /* pcrel_offset */
1321
1322 HOWTO (R_ARM_THM_MOVT_BREL, /* type */
1323 0, /* rightshift */
1324 2, /* size (0 = byte, 1 = short, 2 = long) */
1325 16, /* bitsize */
1326 FALSE, /* pc_relative */
1327 0, /* bitpos */
1328 complain_overflow_bitfield,/* complain_on_overflow */
1329 bfd_elf_generic_reloc, /* special_function */
1330 "R_ARM_THM_MOVT_BREL", /* name */
1331 FALSE, /* partial_inplace */
1332 0x040f70ff, /* src_mask */
1333 0x040f70ff, /* dst_mask */
1334 FALSE), /* pcrel_offset */
1335
1336 HOWTO (R_ARM_THM_MOVW_BREL, /* type */
1337 0, /* rightshift */
1338 2, /* size (0 = byte, 1 = short, 2 = long) */
1339 16, /* bitsize */
1340 FALSE, /* pc_relative */
1341 0, /* bitpos */
1342 complain_overflow_dont,/* complain_on_overflow */
1343 bfd_elf_generic_reloc, /* special_function */
1344 "R_ARM_THM_MOVW_BREL", /* name */
1345 FALSE, /* partial_inplace */
1346 0x040f70ff, /* src_mask */
1347 0x040f70ff, /* dst_mask */
1348 FALSE), /* pcrel_offset */
1349
1350 EMPTY_HOWTO (90), /* unallocated */
1351 EMPTY_HOWTO (91),
1352 EMPTY_HOWTO (92),
1353 EMPTY_HOWTO (93),
1354
1355 HOWTO (R_ARM_PLT32_ABS, /* type */
1356 0, /* rightshift */
1357 2, /* size (0 = byte, 1 = short, 2 = long) */
1358 32, /* bitsize */
1359 FALSE, /* pc_relative */
1360 0, /* bitpos */
1361 complain_overflow_dont,/* complain_on_overflow */
1362 bfd_elf_generic_reloc, /* special_function */
1363 "R_ARM_PLT32_ABS", /* name */
1364 FALSE, /* partial_inplace */
1365 0xffffffff, /* src_mask */
1366 0xffffffff, /* dst_mask */
1367 FALSE), /* pcrel_offset */
1368
1369 HOWTO (R_ARM_GOT_ABS, /* type */
1370 0, /* rightshift */
1371 2, /* size (0 = byte, 1 = short, 2 = long) */
1372 32, /* bitsize */
1373 FALSE, /* pc_relative */
1374 0, /* bitpos */
1375 complain_overflow_dont,/* complain_on_overflow */
1376 bfd_elf_generic_reloc, /* special_function */
1377 "R_ARM_GOT_ABS", /* name */
1378 FALSE, /* partial_inplace */
1379 0xffffffff, /* src_mask */
1380 0xffffffff, /* dst_mask */
1381 FALSE), /* pcrel_offset */
1382
1383 HOWTO (R_ARM_GOT_PREL, /* type */
1384 0, /* rightshift */
1385 2, /* size (0 = byte, 1 = short, 2 = long) */
1386 32, /* bitsize */
1387 TRUE, /* pc_relative */
1388 0, /* bitpos */
1389 complain_overflow_dont, /* complain_on_overflow */
1390 bfd_elf_generic_reloc, /* special_function */
1391 "R_ARM_GOT_PREL", /* name */
1392 FALSE, /* partial_inplace */
1393 0xffffffff, /* src_mask */
1394 0xffffffff, /* dst_mask */
1395 TRUE), /* pcrel_offset */
1396
1397 HOWTO (R_ARM_GOT_BREL12, /* type */
1398 0, /* rightshift */
1399 2, /* size (0 = byte, 1 = short, 2 = long) */
1400 12, /* bitsize */
1401 FALSE, /* pc_relative */
1402 0, /* bitpos */
1403 complain_overflow_bitfield,/* complain_on_overflow */
1404 bfd_elf_generic_reloc, /* special_function */
1405 "R_ARM_GOT_BREL12", /* name */
1406 FALSE, /* partial_inplace */
1407 0x00000fff, /* src_mask */
1408 0x00000fff, /* dst_mask */
1409 FALSE), /* pcrel_offset */
1410
1411 HOWTO (R_ARM_GOTOFF12, /* type */
1412 0, /* rightshift */
1413 2, /* size (0 = byte, 1 = short, 2 = long) */
1414 12, /* bitsize */
1415 FALSE, /* pc_relative */
1416 0, /* bitpos */
1417 complain_overflow_bitfield,/* complain_on_overflow */
1418 bfd_elf_generic_reloc, /* special_function */
1419 "R_ARM_GOTOFF12", /* name */
1420 FALSE, /* partial_inplace */
1421 0x00000fff, /* src_mask */
1422 0x00000fff, /* dst_mask */
1423 FALSE), /* pcrel_offset */
1424
1425 EMPTY_HOWTO (R_ARM_GOTRELAX), /* reserved for future GOT-load optimizations */
1426
1427 /* GNU extension to record C++ vtable member usage */
1428 HOWTO (R_ARM_GNU_VTENTRY, /* type */
ba93b8ac
DJ
1429 0, /* rightshift */
1430 2, /* size (0 = byte, 1 = short, 2 = long) */
c19d1205 1431 0, /* bitsize */
ba93b8ac
DJ
1432 FALSE, /* pc_relative */
1433 0, /* bitpos */
c19d1205
ZW
1434 complain_overflow_dont, /* complain_on_overflow */
1435 _bfd_elf_rel_vtable_reloc_fn, /* special_function */
1436 "R_ARM_GNU_VTENTRY", /* name */
1437 FALSE, /* partial_inplace */
1438 0, /* src_mask */
1439 0, /* dst_mask */
1440 FALSE), /* pcrel_offset */
1441
1442 /* GNU extension to record C++ vtable hierarchy */
1443 HOWTO (R_ARM_GNU_VTINHERIT, /* type */
1444 0, /* rightshift */
1445 2, /* size (0 = byte, 1 = short, 2 = long) */
1446 0, /* bitsize */
1447 FALSE, /* pc_relative */
1448 0, /* bitpos */
1449 complain_overflow_dont, /* complain_on_overflow */
1450 NULL, /* special_function */
1451 "R_ARM_GNU_VTINHERIT", /* name */
1452 FALSE, /* partial_inplace */
1453 0, /* src_mask */
1454 0, /* dst_mask */
1455 FALSE), /* pcrel_offset */
1456
1457 HOWTO (R_ARM_THM_JUMP11, /* type */
1458 1, /* rightshift */
1459 1, /* size (0 = byte, 1 = short, 2 = long) */
1460 11, /* bitsize */
1461 TRUE, /* pc_relative */
1462 0, /* bitpos */
1463 complain_overflow_signed, /* complain_on_overflow */
1464 bfd_elf_generic_reloc, /* special_function */
1465 "R_ARM_THM_JUMP11", /* name */
1466 FALSE, /* partial_inplace */
1467 0x000007ff, /* src_mask */
1468 0x000007ff, /* dst_mask */
1469 TRUE), /* pcrel_offset */
1470
1471 HOWTO (R_ARM_THM_JUMP8, /* type */
1472 1, /* rightshift */
1473 1, /* size (0 = byte, 1 = short, 2 = long) */
1474 8, /* bitsize */
1475 TRUE, /* pc_relative */
1476 0, /* bitpos */
1477 complain_overflow_signed, /* complain_on_overflow */
1478 bfd_elf_generic_reloc, /* special_function */
1479 "R_ARM_THM_JUMP8", /* name */
1480 FALSE, /* partial_inplace */
1481 0x000000ff, /* src_mask */
1482 0x000000ff, /* dst_mask */
1483 TRUE), /* pcrel_offset */
ba93b8ac 1484
c19d1205
ZW
1485 /* TLS relocations */
1486 HOWTO (R_ARM_TLS_GD32, /* type */
ba93b8ac
DJ
1487 0, /* rightshift */
1488 2, /* size (0 = byte, 1 = short, 2 = long) */
1489 32, /* bitsize */
1490 FALSE, /* pc_relative */
1491 0, /* bitpos */
1492 complain_overflow_bitfield,/* complain_on_overflow */
c19d1205
ZW
1493 NULL, /* special_function */
1494 "R_ARM_TLS_GD32", /* name */
ba93b8ac
DJ
1495 TRUE, /* partial_inplace */
1496 0xffffffff, /* src_mask */
1497 0xffffffff, /* dst_mask */
c19d1205 1498 FALSE), /* pcrel_offset */
ba93b8ac 1499
ba93b8ac
DJ
1500 HOWTO (R_ARM_TLS_LDM32, /* type */
1501 0, /* rightshift */
1502 2, /* size (0 = byte, 1 = short, 2 = long) */
1503 32, /* bitsize */
1504 FALSE, /* pc_relative */
1505 0, /* bitpos */
1506 complain_overflow_bitfield,/* complain_on_overflow */
1507 bfd_elf_generic_reloc, /* special_function */
1508 "R_ARM_TLS_LDM32", /* name */
1509 TRUE, /* partial_inplace */
1510 0xffffffff, /* src_mask */
1511 0xffffffff, /* dst_mask */
c19d1205 1512 FALSE), /* pcrel_offset */
ba93b8ac 1513
c19d1205 1514 HOWTO (R_ARM_TLS_LDO32, /* type */
ba93b8ac
DJ
1515 0, /* rightshift */
1516 2, /* size (0 = byte, 1 = short, 2 = long) */
1517 32, /* bitsize */
1518 FALSE, /* pc_relative */
1519 0, /* bitpos */
1520 complain_overflow_bitfield,/* complain_on_overflow */
1521 bfd_elf_generic_reloc, /* special_function */
c19d1205 1522 "R_ARM_TLS_LDO32", /* name */
ba93b8ac
DJ
1523 TRUE, /* partial_inplace */
1524 0xffffffff, /* src_mask */
1525 0xffffffff, /* dst_mask */
c19d1205 1526 FALSE), /* pcrel_offset */
ba93b8ac 1527
ba93b8ac
DJ
1528 HOWTO (R_ARM_TLS_IE32, /* type */
1529 0, /* rightshift */
1530 2, /* size (0 = byte, 1 = short, 2 = long) */
1531 32, /* bitsize */
1532 FALSE, /* pc_relative */
1533 0, /* bitpos */
1534 complain_overflow_bitfield,/* complain_on_overflow */
1535 NULL, /* special_function */
1536 "R_ARM_TLS_IE32", /* name */
1537 TRUE, /* partial_inplace */
1538 0xffffffff, /* src_mask */
1539 0xffffffff, /* dst_mask */
c19d1205 1540 FALSE), /* pcrel_offset */
7f266840 1541
c19d1205 1542 HOWTO (R_ARM_TLS_LE32, /* type */
7f266840
DJ
1543 0, /* rightshift */
1544 2, /* size (0 = byte, 1 = short, 2 = long) */
c19d1205 1545 32, /* bitsize */
7f266840
DJ
1546 FALSE, /* pc_relative */
1547 0, /* bitpos */
c19d1205
ZW
1548 complain_overflow_bitfield,/* complain_on_overflow */
1549 bfd_elf_generic_reloc, /* special_function */
1550 "R_ARM_TLS_LE32", /* name */
1551 TRUE, /* partial_inplace */
1552 0xffffffff, /* src_mask */
1553 0xffffffff, /* dst_mask */
1554 FALSE), /* pcrel_offset */
7f266840 1555
c19d1205
ZW
1556 HOWTO (R_ARM_TLS_LDO12, /* type */
1557 0, /* rightshift */
1558 2, /* size (0 = byte, 1 = short, 2 = long) */
1559 12, /* bitsize */
1560 FALSE, /* pc_relative */
7f266840 1561 0, /* bitpos */
c19d1205 1562 complain_overflow_bitfield,/* complain_on_overflow */
7f266840 1563 bfd_elf_generic_reloc, /* special_function */
c19d1205 1564 "R_ARM_TLS_LDO12", /* name */
7f266840 1565 FALSE, /* partial_inplace */
c19d1205
ZW
1566 0x00000fff, /* src_mask */
1567 0x00000fff, /* dst_mask */
1568 FALSE), /* pcrel_offset */
7f266840 1569
c19d1205
ZW
1570 HOWTO (R_ARM_TLS_LE12, /* type */
1571 0, /* rightshift */
1572 2, /* size (0 = byte, 1 = short, 2 = long) */
1573 12, /* bitsize */
1574 FALSE, /* pc_relative */
7f266840 1575 0, /* bitpos */
c19d1205 1576 complain_overflow_bitfield,/* complain_on_overflow */
7f266840 1577 bfd_elf_generic_reloc, /* special_function */
c19d1205 1578 "R_ARM_TLS_LE12", /* name */
7f266840 1579 FALSE, /* partial_inplace */
c19d1205
ZW
1580 0x00000fff, /* src_mask */
1581 0x00000fff, /* dst_mask */
1582 FALSE), /* pcrel_offset */
7f266840 1583
c19d1205 1584 HOWTO (R_ARM_TLS_IE12GP, /* type */
7f266840
DJ
1585 0, /* rightshift */
1586 2, /* size (0 = byte, 1 = short, 2 = long) */
c19d1205
ZW
1587 12, /* bitsize */
1588 FALSE, /* pc_relative */
7f266840 1589 0, /* bitpos */
c19d1205 1590 complain_overflow_bitfield,/* complain_on_overflow */
7f266840 1591 bfd_elf_generic_reloc, /* special_function */
c19d1205 1592 "R_ARM_TLS_IE12GP", /* name */
7f266840 1593 FALSE, /* partial_inplace */
c19d1205
ZW
1594 0x00000fff, /* src_mask */
1595 0x00000fff, /* dst_mask */
1596 FALSE), /* pcrel_offset */
1597};
1598
1599/* 112-127 private relocations
1600 128 R_ARM_ME_TOO, obsolete
1601 129-255 unallocated in AAELF.
7f266840 1602
c19d1205
ZW
1603 249-255 extended, currently unused, relocations: */
1604
4962c51a 1605static reloc_howto_type elf32_arm_howto_table_2[4] =
7f266840
DJ
1606{
1607 HOWTO (R_ARM_RREL32, /* type */
1608 0, /* rightshift */
1609 0, /* size (0 = byte, 1 = short, 2 = long) */
1610 0, /* bitsize */
1611 FALSE, /* pc_relative */
1612 0, /* bitpos */
1613 complain_overflow_dont,/* complain_on_overflow */
1614 bfd_elf_generic_reloc, /* special_function */
1615 "R_ARM_RREL32", /* name */
1616 FALSE, /* partial_inplace */
1617 0, /* src_mask */
1618 0, /* dst_mask */
1619 FALSE), /* pcrel_offset */
1620
1621 HOWTO (R_ARM_RABS32, /* type */
1622 0, /* rightshift */
1623 0, /* size (0 = byte, 1 = short, 2 = long) */
1624 0, /* bitsize */
1625 FALSE, /* pc_relative */
1626 0, /* bitpos */
1627 complain_overflow_dont,/* complain_on_overflow */
1628 bfd_elf_generic_reloc, /* special_function */
1629 "R_ARM_RABS32", /* name */
1630 FALSE, /* partial_inplace */
1631 0, /* src_mask */
1632 0, /* dst_mask */
1633 FALSE), /* pcrel_offset */
1634
1635 HOWTO (R_ARM_RPC24, /* type */
1636 0, /* rightshift */
1637 0, /* size (0 = byte, 1 = short, 2 = long) */
1638 0, /* bitsize */
1639 FALSE, /* pc_relative */
1640 0, /* bitpos */
1641 complain_overflow_dont,/* complain_on_overflow */
1642 bfd_elf_generic_reloc, /* special_function */
1643 "R_ARM_RPC24", /* name */
1644 FALSE, /* partial_inplace */
1645 0, /* src_mask */
1646 0, /* dst_mask */
1647 FALSE), /* pcrel_offset */
1648
1649 HOWTO (R_ARM_RBASE, /* type */
1650 0, /* rightshift */
1651 0, /* size (0 = byte, 1 = short, 2 = long) */
1652 0, /* bitsize */
1653 FALSE, /* pc_relative */
1654 0, /* bitpos */
1655 complain_overflow_dont,/* complain_on_overflow */
1656 bfd_elf_generic_reloc, /* special_function */
1657 "R_ARM_RBASE", /* name */
1658 FALSE, /* partial_inplace */
1659 0, /* src_mask */
1660 0, /* dst_mask */
1661 FALSE) /* pcrel_offset */
1662};
1663
1664static reloc_howto_type *
1665elf32_arm_howto_from_type (unsigned int r_type)
1666{
906e58ca 1667 if (r_type < ARRAY_SIZE (elf32_arm_howto_table_1))
c19d1205 1668 return &elf32_arm_howto_table_1[r_type];
ba93b8ac 1669
c19d1205 1670 if (r_type >= R_ARM_RREL32
906e58ca 1671 && r_type < R_ARM_RREL32 + ARRAY_SIZE (elf32_arm_howto_table_2))
4962c51a 1672 return &elf32_arm_howto_table_2[r_type - R_ARM_RREL32];
7f266840 1673
c19d1205 1674 return NULL;
7f266840
DJ
1675}
1676
1677static void
1678elf32_arm_info_to_howto (bfd * abfd ATTRIBUTE_UNUSED, arelent * bfd_reloc,
1679 Elf_Internal_Rela * elf_reloc)
1680{
1681 unsigned int r_type;
1682
1683 r_type = ELF32_R_TYPE (elf_reloc->r_info);
1684 bfd_reloc->howto = elf32_arm_howto_from_type (r_type);
1685}
1686
1687struct elf32_arm_reloc_map
1688 {
1689 bfd_reloc_code_real_type bfd_reloc_val;
1690 unsigned char elf_reloc_val;
1691 };
1692
1693/* All entries in this list must also be present in elf32_arm_howto_table. */
1694static const struct elf32_arm_reloc_map elf32_arm_reloc_map[] =
1695 {
1696 {BFD_RELOC_NONE, R_ARM_NONE},
1697 {BFD_RELOC_ARM_PCREL_BRANCH, R_ARM_PC24},
39b41c9c
PB
1698 {BFD_RELOC_ARM_PCREL_CALL, R_ARM_CALL},
1699 {BFD_RELOC_ARM_PCREL_JUMP, R_ARM_JUMP24},
7f266840
DJ
1700 {BFD_RELOC_ARM_PCREL_BLX, R_ARM_XPC25},
1701 {BFD_RELOC_THUMB_PCREL_BLX, R_ARM_THM_XPC22},
1702 {BFD_RELOC_32, R_ARM_ABS32},
1703 {BFD_RELOC_32_PCREL, R_ARM_REL32},
1704 {BFD_RELOC_8, R_ARM_ABS8},
1705 {BFD_RELOC_16, R_ARM_ABS16},
1706 {BFD_RELOC_ARM_OFFSET_IMM, R_ARM_ABS12},
1707 {BFD_RELOC_ARM_THUMB_OFFSET, R_ARM_THM_ABS5},
c19d1205
ZW
1708 {BFD_RELOC_THUMB_PCREL_BRANCH25, R_ARM_THM_JUMP24},
1709 {BFD_RELOC_THUMB_PCREL_BRANCH23, R_ARM_THM_CALL},
1710 {BFD_RELOC_THUMB_PCREL_BRANCH12, R_ARM_THM_JUMP11},
1711 {BFD_RELOC_THUMB_PCREL_BRANCH20, R_ARM_THM_JUMP19},
1712 {BFD_RELOC_THUMB_PCREL_BRANCH9, R_ARM_THM_JUMP8},
1713 {BFD_RELOC_THUMB_PCREL_BRANCH7, R_ARM_THM_JUMP6},
7f266840
DJ
1714 {BFD_RELOC_ARM_GLOB_DAT, R_ARM_GLOB_DAT},
1715 {BFD_RELOC_ARM_JUMP_SLOT, R_ARM_JUMP_SLOT},
1716 {BFD_RELOC_ARM_RELATIVE, R_ARM_RELATIVE},
c19d1205 1717 {BFD_RELOC_ARM_GOTOFF, R_ARM_GOTOFF32},
7f266840
DJ
1718 {BFD_RELOC_ARM_GOTPC, R_ARM_GOTPC},
1719 {BFD_RELOC_ARM_GOT32, R_ARM_GOT32},
1720 {BFD_RELOC_ARM_PLT32, R_ARM_PLT32},
1721 {BFD_RELOC_ARM_TARGET1, R_ARM_TARGET1},
1722 {BFD_RELOC_ARM_ROSEGREL32, R_ARM_ROSEGREL32},
1723 {BFD_RELOC_ARM_SBREL32, R_ARM_SBREL32},
1724 {BFD_RELOC_ARM_PREL31, R_ARM_PREL31},
ba93b8ac
DJ
1725 {BFD_RELOC_ARM_TARGET2, R_ARM_TARGET2},
1726 {BFD_RELOC_ARM_PLT32, R_ARM_PLT32},
1727 {BFD_RELOC_ARM_TLS_GD32, R_ARM_TLS_GD32},
1728 {BFD_RELOC_ARM_TLS_LDO32, R_ARM_TLS_LDO32},
1729 {BFD_RELOC_ARM_TLS_LDM32, R_ARM_TLS_LDM32},
1730 {BFD_RELOC_ARM_TLS_DTPMOD32, R_ARM_TLS_DTPMOD32},
1731 {BFD_RELOC_ARM_TLS_DTPOFF32, R_ARM_TLS_DTPOFF32},
1732 {BFD_RELOC_ARM_TLS_TPOFF32, R_ARM_TLS_TPOFF32},
1733 {BFD_RELOC_ARM_TLS_IE32, R_ARM_TLS_IE32},
1734 {BFD_RELOC_ARM_TLS_LE32, R_ARM_TLS_LE32},
c19d1205
ZW
1735 {BFD_RELOC_VTABLE_INHERIT, R_ARM_GNU_VTINHERIT},
1736 {BFD_RELOC_VTABLE_ENTRY, R_ARM_GNU_VTENTRY},
b6895b4f
PB
1737 {BFD_RELOC_ARM_MOVW, R_ARM_MOVW_ABS_NC},
1738 {BFD_RELOC_ARM_MOVT, R_ARM_MOVT_ABS},
1739 {BFD_RELOC_ARM_MOVW_PCREL, R_ARM_MOVW_PREL_NC},
1740 {BFD_RELOC_ARM_MOVT_PCREL, R_ARM_MOVT_PREL},
1741 {BFD_RELOC_ARM_THUMB_MOVW, R_ARM_THM_MOVW_ABS_NC},
1742 {BFD_RELOC_ARM_THUMB_MOVT, R_ARM_THM_MOVT_ABS},
1743 {BFD_RELOC_ARM_THUMB_MOVW_PCREL, R_ARM_THM_MOVW_PREL_NC},
1744 {BFD_RELOC_ARM_THUMB_MOVT_PCREL, R_ARM_THM_MOVT_PREL},
4962c51a
MS
1745 {BFD_RELOC_ARM_ALU_PC_G0_NC, R_ARM_ALU_PC_G0_NC},
1746 {BFD_RELOC_ARM_ALU_PC_G0, R_ARM_ALU_PC_G0},
1747 {BFD_RELOC_ARM_ALU_PC_G1_NC, R_ARM_ALU_PC_G1_NC},
1748 {BFD_RELOC_ARM_ALU_PC_G1, R_ARM_ALU_PC_G1},
1749 {BFD_RELOC_ARM_ALU_PC_G2, R_ARM_ALU_PC_G2},
1750 {BFD_RELOC_ARM_LDR_PC_G0, R_ARM_LDR_PC_G0},
1751 {BFD_RELOC_ARM_LDR_PC_G1, R_ARM_LDR_PC_G1},
1752 {BFD_RELOC_ARM_LDR_PC_G2, R_ARM_LDR_PC_G2},
1753 {BFD_RELOC_ARM_LDRS_PC_G0, R_ARM_LDRS_PC_G0},
1754 {BFD_RELOC_ARM_LDRS_PC_G1, R_ARM_LDRS_PC_G1},
1755 {BFD_RELOC_ARM_LDRS_PC_G2, R_ARM_LDRS_PC_G2},
1756 {BFD_RELOC_ARM_LDC_PC_G0, R_ARM_LDC_PC_G0},
1757 {BFD_RELOC_ARM_LDC_PC_G1, R_ARM_LDC_PC_G1},
1758 {BFD_RELOC_ARM_LDC_PC_G2, R_ARM_LDC_PC_G2},
1759 {BFD_RELOC_ARM_ALU_SB_G0_NC, R_ARM_ALU_SB_G0_NC},
1760 {BFD_RELOC_ARM_ALU_SB_G0, R_ARM_ALU_SB_G0},
1761 {BFD_RELOC_ARM_ALU_SB_G1_NC, R_ARM_ALU_SB_G1_NC},
1762 {BFD_RELOC_ARM_ALU_SB_G1, R_ARM_ALU_SB_G1},
1763 {BFD_RELOC_ARM_ALU_SB_G2, R_ARM_ALU_SB_G2},
1764 {BFD_RELOC_ARM_LDR_SB_G0, R_ARM_LDR_SB_G0},
1765 {BFD_RELOC_ARM_LDR_SB_G1, R_ARM_LDR_SB_G1},
1766 {BFD_RELOC_ARM_LDR_SB_G2, R_ARM_LDR_SB_G2},
1767 {BFD_RELOC_ARM_LDRS_SB_G0, R_ARM_LDRS_SB_G0},
1768 {BFD_RELOC_ARM_LDRS_SB_G1, R_ARM_LDRS_SB_G1},
1769 {BFD_RELOC_ARM_LDRS_SB_G2, R_ARM_LDRS_SB_G2},
1770 {BFD_RELOC_ARM_LDC_SB_G0, R_ARM_LDC_SB_G0},
1771 {BFD_RELOC_ARM_LDC_SB_G1, R_ARM_LDC_SB_G1},
845b51d6
PB
1772 {BFD_RELOC_ARM_LDC_SB_G2, R_ARM_LDC_SB_G2},
1773 {BFD_RELOC_ARM_V4BX, R_ARM_V4BX}
7f266840
DJ
1774 };
1775
1776static reloc_howto_type *
f1c71a59
ZW
1777elf32_arm_reloc_type_lookup (bfd *abfd ATTRIBUTE_UNUSED,
1778 bfd_reloc_code_real_type code)
7f266840
DJ
1779{
1780 unsigned int i;
906e58ca 1781 for (i = 0; i < ARRAY_SIZE (elf32_arm_reloc_map); i ++)
c19d1205
ZW
1782 if (elf32_arm_reloc_map[i].bfd_reloc_val == code)
1783 return elf32_arm_howto_from_type (elf32_arm_reloc_map[i].elf_reloc_val);
7f266840 1784
c19d1205 1785 return NULL;
7f266840
DJ
1786}
1787
157090f7
AM
1788static reloc_howto_type *
1789elf32_arm_reloc_name_lookup (bfd *abfd ATTRIBUTE_UNUSED,
1790 const char *r_name)
1791{
1792 unsigned int i;
1793
906e58ca 1794 for (i = 0; i < ARRAY_SIZE (elf32_arm_howto_table_1); i++)
157090f7
AM
1795 if (elf32_arm_howto_table_1[i].name != NULL
1796 && strcasecmp (elf32_arm_howto_table_1[i].name, r_name) == 0)
1797 return &elf32_arm_howto_table_1[i];
1798
906e58ca 1799 for (i = 0; i < ARRAY_SIZE (elf32_arm_howto_table_2); i++)
157090f7
AM
1800 if (elf32_arm_howto_table_2[i].name != NULL
1801 && strcasecmp (elf32_arm_howto_table_2[i].name, r_name) == 0)
1802 return &elf32_arm_howto_table_2[i];
1803
1804 return NULL;
1805}
1806
906e58ca
NC
1807/* Support for core dump NOTE sections. */
1808
7f266840 1809static bfd_boolean
f1c71a59 1810elf32_arm_nabi_grok_prstatus (bfd *abfd, Elf_Internal_Note *note)
7f266840
DJ
1811{
1812 int offset;
1813 size_t size;
1814
1815 switch (note->descsz)
1816 {
1817 default:
1818 return FALSE;
1819
1820 case 148: /* Linux/ARM 32-bit*/
1821 /* pr_cursig */
1822 elf_tdata (abfd)->core_signal = bfd_get_16 (abfd, note->descdata + 12);
1823
1824 /* pr_pid */
1825 elf_tdata (abfd)->core_pid = bfd_get_32 (abfd, note->descdata + 24);
1826
1827 /* pr_reg */
1828 offset = 72;
1829 size = 72;
1830
1831 break;
1832 }
1833
1834 /* Make a ".reg/999" section. */
1835 return _bfd_elfcore_make_pseudosection (abfd, ".reg",
1836 size, note->descpos + offset);
1837}
1838
1839static bfd_boolean
f1c71a59 1840elf32_arm_nabi_grok_psinfo (bfd *abfd, Elf_Internal_Note *note)
7f266840
DJ
1841{
1842 switch (note->descsz)
1843 {
1844 default:
1845 return FALSE;
1846
1847 case 124: /* Linux/ARM elf_prpsinfo */
1848 elf_tdata (abfd)->core_program
1849 = _bfd_elfcore_strndup (abfd, note->descdata + 28, 16);
1850 elf_tdata (abfd)->core_command
1851 = _bfd_elfcore_strndup (abfd, note->descdata + 44, 80);
1852 }
1853
1854 /* Note that for some reason, a spurious space is tacked
1855 onto the end of the args in some (at least one anyway)
1856 implementations, so strip it off if it exists. */
7f266840
DJ
1857 {
1858 char *command = elf_tdata (abfd)->core_command;
1859 int n = strlen (command);
1860
1861 if (0 < n && command[n - 1] == ' ')
1862 command[n - 1] = '\0';
1863 }
1864
1865 return TRUE;
1866}
1867
1868#define TARGET_LITTLE_SYM bfd_elf32_littlearm_vec
1869#define TARGET_LITTLE_NAME "elf32-littlearm"
1870#define TARGET_BIG_SYM bfd_elf32_bigarm_vec
1871#define TARGET_BIG_NAME "elf32-bigarm"
1872
1873#define elf_backend_grok_prstatus elf32_arm_nabi_grok_prstatus
1874#define elf_backend_grok_psinfo elf32_arm_nabi_grok_psinfo
1875
252b5132
RH
1876typedef unsigned long int insn32;
1877typedef unsigned short int insn16;
1878
3a4a14e9
PB
1879/* In lieu of proper flags, assume all EABIv4 or later objects are
1880 interworkable. */
57e8b36a 1881#define INTERWORK_FLAG(abfd) \
3a4a14e9 1882 (EF_ARM_EABI_VERSION (elf_elfheader (abfd)->e_flags) >= EF_ARM_EABI_VER4 \
85a84e7a 1883 || (elf_elfheader (abfd)->e_flags & EF_ARM_INTERWORK))
9b485d32 1884
252b5132
RH
1885/* The linker script knows the section names for placement.
1886 The entry_names are used to do simple name mangling on the stubs.
1887 Given a function name, and its type, the stub can be found. The
9b485d32 1888 name can be changed. The only requirement is the %s be present. */
252b5132
RH
1889#define THUMB2ARM_GLUE_SECTION_NAME ".glue_7t"
1890#define THUMB2ARM_GLUE_ENTRY_NAME "__%s_from_thumb"
1891
1892#define ARM2THUMB_GLUE_SECTION_NAME ".glue_7"
1893#define ARM2THUMB_GLUE_ENTRY_NAME "__%s_from_arm"
1894
c7b8f16e
JB
1895#define VFP11_ERRATUM_VENEER_SECTION_NAME ".vfp11_veneer"
1896#define VFP11_ERRATUM_VENEER_ENTRY_NAME "__vfp11_veneer_%x"
1897
845b51d6
PB
1898#define ARM_BX_GLUE_SECTION_NAME ".v4_bx"
1899#define ARM_BX_GLUE_ENTRY_NAME "__bx_r%d"
1900
7413f23f
DJ
1901#define STUB_ENTRY_NAME "__%s_veneer"
1902
252b5132
RH
1903/* The name of the dynamic interpreter. This is put in the .interp
1904 section. */
1905#define ELF_DYNAMIC_INTERPRETER "/usr/lib/ld.so.1"
1906
5e681ec4
PB
1907#ifdef FOUR_WORD_PLT
1908
252b5132
RH
1909/* The first entry in a procedure linkage table looks like
1910 this. It is set up so that any shared library function that is
59f2c4e7 1911 called before the relocation has been set up calls the dynamic
9b485d32 1912 linker first. */
e5a52504 1913static const bfd_vma elf32_arm_plt0_entry [] =
5e681ec4
PB
1914 {
1915 0xe52de004, /* str lr, [sp, #-4]! */
1916 0xe59fe010, /* ldr lr, [pc, #16] */
1917 0xe08fe00e, /* add lr, pc, lr */
1918 0xe5bef008, /* ldr pc, [lr, #8]! */
1919 };
1920
1921/* Subsequent entries in a procedure linkage table look like
1922 this. */
e5a52504 1923static const bfd_vma elf32_arm_plt_entry [] =
5e681ec4
PB
1924 {
1925 0xe28fc600, /* add ip, pc, #NN */
1926 0xe28cca00, /* add ip, ip, #NN */
1927 0xe5bcf000, /* ldr pc, [ip, #NN]! */
1928 0x00000000, /* unused */
1929 };
1930
1931#else
1932
5e681ec4
PB
1933/* The first entry in a procedure linkage table looks like
1934 this. It is set up so that any shared library function that is
1935 called before the relocation has been set up calls the dynamic
1936 linker first. */
e5a52504 1937static const bfd_vma elf32_arm_plt0_entry [] =
917583ad 1938 {
5e681ec4
PB
1939 0xe52de004, /* str lr, [sp, #-4]! */
1940 0xe59fe004, /* ldr lr, [pc, #4] */
1941 0xe08fe00e, /* add lr, pc, lr */
1942 0xe5bef008, /* ldr pc, [lr, #8]! */
1943 0x00000000, /* &GOT[0] - . */
917583ad 1944 };
252b5132
RH
1945
1946/* Subsequent entries in a procedure linkage table look like
1947 this. */
e5a52504 1948static const bfd_vma elf32_arm_plt_entry [] =
5e681ec4
PB
1949 {
1950 0xe28fc600, /* add ip, pc, #0xNN00000 */
1951 0xe28cca00, /* add ip, ip, #0xNN000 */
1952 0xe5bcf000, /* ldr pc, [ip, #0xNNN]! */
1953 };
1954
1955#endif
252b5132 1956
00a97672
RS
1957/* The format of the first entry in the procedure linkage table
1958 for a VxWorks executable. */
1959static const bfd_vma elf32_arm_vxworks_exec_plt0_entry[] =
1960 {
1961 0xe52dc008, /* str ip,[sp,#-8]! */
1962 0xe59fc000, /* ldr ip,[pc] */
1963 0xe59cf008, /* ldr pc,[ip,#8] */
1964 0x00000000, /* .long _GLOBAL_OFFSET_TABLE_ */
1965 };
1966
1967/* The format of subsequent entries in a VxWorks executable. */
1968static const bfd_vma elf32_arm_vxworks_exec_plt_entry[] =
1969 {
1970 0xe59fc000, /* ldr ip,[pc] */
1971 0xe59cf000, /* ldr pc,[ip] */
1972 0x00000000, /* .long @got */
1973 0xe59fc000, /* ldr ip,[pc] */
1974 0xea000000, /* b _PLT */
1975 0x00000000, /* .long @pltindex*sizeof(Elf32_Rela) */
1976 };
1977
1978/* The format of entries in a VxWorks shared library. */
1979static const bfd_vma elf32_arm_vxworks_shared_plt_entry[] =
1980 {
1981 0xe59fc000, /* ldr ip,[pc] */
1982 0xe79cf009, /* ldr pc,[ip,r9] */
1983 0x00000000, /* .long @got */
1984 0xe59fc000, /* ldr ip,[pc] */
1985 0xe599f008, /* ldr pc,[r9,#8] */
1986 0x00000000, /* .long @pltindex*sizeof(Elf32_Rela) */
1987 };
1988
b7693d02
DJ
1989/* An initial stub used if the PLT entry is referenced from Thumb code. */
1990#define PLT_THUMB_STUB_SIZE 4
1991static const bfd_vma elf32_arm_plt_thumb_stub [] =
1992 {
1993 0x4778, /* bx pc */
1994 0x46c0 /* nop */
1995 };
1996
e5a52504
MM
1997/* The entries in a PLT when using a DLL-based target with multiple
1998 address spaces. */
906e58ca 1999static const bfd_vma elf32_arm_symbian_plt_entry [] =
e5a52504 2000 {
83a358aa 2001 0xe51ff004, /* ldr pc, [pc, #-4] */
e5a52504
MM
2002 0x00000000, /* dcd R_ARM_GLOB_DAT(X) */
2003 };
2004
906e58ca
NC
2005#define ARM_MAX_FWD_BRANCH_OFFSET ((((1 << 23) - 1) << 2) + 8)
2006#define ARM_MAX_BWD_BRANCH_OFFSET ((-((1 << 23) << 2)) + 8)
2007#define THM_MAX_FWD_BRANCH_OFFSET ((1 << 22) -2 + 4)
2008#define THM_MAX_BWD_BRANCH_OFFSET (-(1 << 22) + 4)
2009#define THM2_MAX_FWD_BRANCH_OFFSET (((1 << 24) - 2) + 4)
2010#define THM2_MAX_BWD_BRANCH_OFFSET (-(1 << 24) + 4)
2011
2012static const bfd_vma arm_long_branch_stub[] =
2013 {
2014 0xe51ff004, /* ldr pc, [pc, #-4] */
2015 0x00000000, /* dcd R_ARM_ABS32(X) */
2016 };
2017
2018static const bfd_vma arm_thumb_v4t_long_branch_stub[] =
2019 {
2020 0xe59fc000, /* ldr ip, [pc, #0] */
2021 0xe12fff1c, /* bx ip */
2022 0x00000000, /* dcd R_ARM_ABS32(X) */
2023 };
2024
2025static const bfd_vma arm_thumb_thumb_long_branch_stub[] =
2026 {
2027 0x4e02b540, /* push {r6, lr} */
2028 /* ldr r6, [pc, #8] */
7413f23f
DJ
2029 0x473046fe, /* mov lr, pc */
2030 /* bx r6 */
906e58ca
NC
2031 0xbf00bd40, /* pop {r6, pc} */
2032 /* nop */
2033 0x00000000, /* dcd R_ARM_ABS32(X) */
2034 };
2035
2036static const bfd_vma arm_thumb_arm_v4t_long_branch_stub[] =
2037 {
2038 0x4e03b540, /* push {r6, lr} */
2039 /* ldr r6, [pc, #12] */
2040 0x473046fe, /* mov lr, pc */
2041 /* bx r6 */
2042 0xe8bd4040, /* pop {r6, pc} */
2043 0xe12fff1e, /* bx lr */
2044 0x00000000, /* dcd R_ARM_ABS32(X) */
2045 };
2046
2047static const bfd_vma arm_pic_long_branch_stub[] =
2048 {
2049 0xe59fc000, /* ldr r12, [pc] */
2050 0xe08ff00c, /* add pc, pc, ip */
7413f23f 2051 0x00000000, /* dcd R_ARM_REL32(X) */
906e58ca
NC
2052 };
2053
2054/* Section name for stubs is the associated section name plus this
2055 string. */
2056#define STUB_SUFFIX ".stub"
2057
2058enum elf32_arm_stub_type
2059{
2060 arm_stub_none,
2061 arm_stub_long_branch,
2062 arm_thumb_v4t_stub_long_branch,
2063 arm_thumb_thumb_stub_long_branch,
2064 arm_thumb_arm_v4t_stub_long_branch,
2065 arm_stub_pic_long_branch,
2066};
2067
2068struct elf32_arm_stub_hash_entry
2069{
2070 /* Base hash table entry structure. */
2071 struct bfd_hash_entry root;
2072
2073 /* The stub section. */
2074 asection *stub_sec;
2075
2076 /* Offset within stub_sec of the beginning of this stub. */
2077 bfd_vma stub_offset;
2078
2079 /* Given the symbol's value and its section we can determine its final
2080 value when building the stubs (so the stub knows where to jump). */
2081 bfd_vma target_value;
2082 asection *target_section;
2083
2084 enum elf32_arm_stub_type stub_type;
2085
2086 /* The symbol table entry, if any, that this was derived from. */
2087 struct elf32_arm_link_hash_entry *h;
2088
2089 /* Destination symbol type (STT_ARM_TFUNC, ...) */
2090 unsigned char st_type;
2091
2092 /* Where this stub is being called from, or, in the case of combined
2093 stub sections, the first input section in the group. */
2094 asection *id_sec;
7413f23f
DJ
2095
2096 /* The name for the local symbol at the start of this stub. The
2097 stub name in the hash table has to be unique; this does not, so
2098 it can be friendlier. */
2099 char *output_name;
906e58ca
NC
2100};
2101
e489d0ae
PB
2102/* Used to build a map of a section. This is required for mixed-endian
2103 code/data. */
2104
2105typedef struct elf32_elf_section_map
2106{
2107 bfd_vma vma;
2108 char type;
2109}
2110elf32_arm_section_map;
2111
c7b8f16e
JB
2112/* Information about a VFP11 erratum veneer, or a branch to such a veneer. */
2113
2114typedef enum
2115{
2116 VFP11_ERRATUM_BRANCH_TO_ARM_VENEER,
2117 VFP11_ERRATUM_BRANCH_TO_THUMB_VENEER,
2118 VFP11_ERRATUM_ARM_VENEER,
2119 VFP11_ERRATUM_THUMB_VENEER
2120}
2121elf32_vfp11_erratum_type;
2122
2123typedef struct elf32_vfp11_erratum_list
2124{
2125 struct elf32_vfp11_erratum_list *next;
2126 bfd_vma vma;
2127 union
2128 {
2129 struct
2130 {
2131 struct elf32_vfp11_erratum_list *veneer;
2132 unsigned int vfp_insn;
2133 } b;
2134 struct
2135 {
2136 struct elf32_vfp11_erratum_list *branch;
2137 unsigned int id;
2138 } v;
2139 } u;
2140 elf32_vfp11_erratum_type type;
2141}
2142elf32_vfp11_erratum_list;
2143
8e3de13a 2144typedef struct _arm_elf_section_data
e489d0ae
PB
2145{
2146 struct bfd_elf_section_data elf;
8e3de13a 2147 unsigned int mapcount;
c7b8f16e 2148 unsigned int mapsize;
e489d0ae 2149 elf32_arm_section_map *map;
c7b8f16e
JB
2150 unsigned int erratumcount;
2151 elf32_vfp11_erratum_list *erratumlist;
8e3de13a
NC
2152}
2153_arm_elf_section_data;
e489d0ae
PB
2154
2155#define elf32_arm_section_data(sec) \
8e3de13a 2156 ((_arm_elf_section_data *) elf_section_data (sec))
e489d0ae 2157
ba93b8ac
DJ
2158/* The size of the thread control block. */
2159#define TCB_SIZE 8
2160
0ffa91dd 2161struct elf_arm_obj_tdata
ba93b8ac
DJ
2162{
2163 struct elf_obj_tdata root;
2164
2165 /* tls_type for each local got entry. */
2166 char *local_got_tls_type;
ee065d83 2167
bf21ed78
MS
2168 /* Zero to warn when linking objects with incompatible enum sizes. */
2169 int no_enum_size_warning;
a9dc9481
JM
2170
2171 /* Zero to warn when linking objects with incompatible wchar_t sizes. */
2172 int no_wchar_size_warning;
ba93b8ac
DJ
2173};
2174
0ffa91dd
NC
2175#define elf_arm_tdata(bfd) \
2176 ((struct elf_arm_obj_tdata *) (bfd)->tdata.any)
ba93b8ac 2177
0ffa91dd
NC
2178#define elf32_arm_local_got_tls_type(bfd) \
2179 (elf_arm_tdata (bfd)->local_got_tls_type)
2180
2181#define is_arm_elf(bfd) \
2182 (bfd_get_flavour (bfd) == bfd_target_elf_flavour \
2183 && elf_tdata (bfd) != NULL \
2184 && elf_object_id (bfd) == ARM_ELF_TDATA)
ba93b8ac
DJ
2185
2186static bfd_boolean
2187elf32_arm_mkobject (bfd *abfd)
2188{
0ffa91dd
NC
2189 return bfd_elf_allocate_object (abfd, sizeof (struct elf_arm_obj_tdata),
2190 ARM_ELF_TDATA);
ba93b8ac
DJ
2191}
2192
252b5132
RH
2193/* The ARM linker needs to keep track of the number of relocs that it
2194 decides to copy in check_relocs for each symbol. This is so that
2195 it can discard PC relative relocs if it doesn't need them when
2196 linking with -Bsymbolic. We store the information in a field
2197 extending the regular ELF linker hash table. */
2198
ba93b8ac
DJ
2199/* This structure keeps track of the number of relocs we have copied
2200 for a given symbol. */
5e681ec4 2201struct elf32_arm_relocs_copied
917583ad
NC
2202 {
2203 /* Next section. */
5e681ec4 2204 struct elf32_arm_relocs_copied * next;
917583ad
NC
2205 /* A section in dynobj. */
2206 asection * section;
2207 /* Number of relocs copied in this section. */
2208 bfd_size_type count;
ba93b8ac
DJ
2209 /* Number of PC-relative relocs copied in this section. */
2210 bfd_size_type pc_count;
917583ad 2211 };
252b5132 2212
ba93b8ac
DJ
2213#define elf32_arm_hash_entry(ent) ((struct elf32_arm_link_hash_entry *)(ent))
2214
ba96a88f 2215/* Arm ELF linker hash entry. */
252b5132 2216struct elf32_arm_link_hash_entry
917583ad
NC
2217 {
2218 struct elf_link_hash_entry root;
252b5132 2219
917583ad 2220 /* Number of PC relative relocs copied for this symbol. */
5e681ec4 2221 struct elf32_arm_relocs_copied * relocs_copied;
b7693d02
DJ
2222
2223 /* We reference count Thumb references to a PLT entry separately,
2224 so that we can emit the Thumb trampoline only if needed. */
2225 bfd_signed_vma plt_thumb_refcount;
2226
bd97cb95
DJ
2227 /* Some references from Thumb code may be eliminated by BL->BLX
2228 conversion, so record them separately. */
2229 bfd_signed_vma plt_maybe_thumb_refcount;
2230
b7693d02
DJ
2231 /* Since PLT entries have variable size if the Thumb prologue is
2232 used, we need to record the index into .got.plt instead of
2233 recomputing it from the PLT offset. */
2234 bfd_signed_vma plt_got_offset;
ba93b8ac
DJ
2235
2236#define GOT_UNKNOWN 0
2237#define GOT_NORMAL 1
2238#define GOT_TLS_GD 2
2239#define GOT_TLS_IE 4
2240 unsigned char tls_type;
a4fd1a8e
PB
2241
2242 /* The symbol marking the real symbol location for exported thumb
2243 symbols with Arm stubs. */
2244 struct elf_link_hash_entry *export_glue;
906e58ca 2245
da5938a2 2246 /* A pointer to the most recently used stub hash entry against this
906e58ca 2247 symbol. */
da5938a2 2248 struct elf32_arm_stub_hash_entry *stub_cache;
917583ad 2249 };
252b5132 2250
252b5132 2251/* Traverse an arm ELF linker hash table. */
252b5132
RH
2252#define elf32_arm_link_hash_traverse(table, func, info) \
2253 (elf_link_hash_traverse \
2254 (&(table)->root, \
b7693d02 2255 (bfd_boolean (*) (struct elf_link_hash_entry *, void *)) (func), \
252b5132
RH
2256 (info)))
2257
2258/* Get the ARM elf linker hash table from a link_info structure. */
2259#define elf32_arm_hash_table(info) \
2260 ((struct elf32_arm_link_hash_table *) ((info)->hash))
2261
906e58ca
NC
2262#define arm_stub_hash_lookup(table, string, create, copy) \
2263 ((struct elf32_arm_stub_hash_entry *) \
2264 bfd_hash_lookup ((table), (string), (create), (copy)))
2265
9b485d32 2266/* ARM ELF linker hash table. */
252b5132 2267struct elf32_arm_link_hash_table
906e58ca
NC
2268{
2269 /* The main hash table. */
2270 struct elf_link_hash_table root;
252b5132 2271
906e58ca
NC
2272 /* The size in bytes of the section containing the Thumb-to-ARM glue. */
2273 bfd_size_type thumb_glue_size;
252b5132 2274
906e58ca
NC
2275 /* The size in bytes of the section containing the ARM-to-Thumb glue. */
2276 bfd_size_type arm_glue_size;
252b5132 2277
906e58ca
NC
2278 /* The size in bytes of section containing the ARMv4 BX veneers. */
2279 bfd_size_type bx_glue_size;
845b51d6 2280
906e58ca
NC
2281 /* Offsets of ARMv4 BX veneers. Bit1 set if present, and Bit0 set when
2282 veneer has been populated. */
2283 bfd_vma bx_glue_offset[15];
845b51d6 2284
906e58ca
NC
2285 /* The size in bytes of the section containing glue for VFP11 erratum
2286 veneers. */
2287 bfd_size_type vfp11_erratum_glue_size;
c7b8f16e 2288
906e58ca
NC
2289 /* An arbitrary input BFD chosen to hold the glue sections. */
2290 bfd * bfd_of_glue_owner;
ba96a88f 2291
906e58ca
NC
2292 /* Nonzero to output a BE8 image. */
2293 int byteswap_code;
e489d0ae 2294
906e58ca
NC
2295 /* Zero if R_ARM_TARGET1 means R_ARM_ABS32.
2296 Nonzero if R_ARM_TARGET1 means R_ARM_REL32. */
2297 int target1_is_rel;
9c504268 2298
906e58ca
NC
2299 /* The relocation to use for R_ARM_TARGET2 relocations. */
2300 int target2_reloc;
eb043451 2301
906e58ca
NC
2302 /* 0 = Ignore R_ARM_V4BX.
2303 1 = Convert BX to MOV PC.
2304 2 = Generate v4 interworing stubs. */
2305 int fix_v4bx;
319850b4 2306
906e58ca
NC
2307 /* Nonzero if the ARM/Thumb BLX instructions are available for use. */
2308 int use_blx;
33bfe774 2309
906e58ca
NC
2310 /* What sort of code sequences we should look for which may trigger the
2311 VFP11 denorm erratum. */
2312 bfd_arm_vfp11_fix vfp11_fix;
c7b8f16e 2313
906e58ca
NC
2314 /* Global counter for the number of fixes we have emitted. */
2315 int num_vfp11_fixes;
c7b8f16e 2316
906e58ca
NC
2317 /* Nonzero to force PIC branch veneers. */
2318 int pic_veneer;
27e55c4d 2319
906e58ca
NC
2320 /* The number of bytes in the initial entry in the PLT. */
2321 bfd_size_type plt_header_size;
e5a52504 2322
906e58ca
NC
2323 /* The number of bytes in the subsequent PLT etries. */
2324 bfd_size_type plt_entry_size;
e5a52504 2325
906e58ca
NC
2326 /* True if the target system is VxWorks. */
2327 int vxworks_p;
00a97672 2328
906e58ca
NC
2329 /* True if the target system is Symbian OS. */
2330 int symbian_p;
e5a52504 2331
906e58ca
NC
2332 /* True if the target uses REL relocations. */
2333 int use_rel;
4e7fd91e 2334
906e58ca
NC
2335 /* Short-cuts to get to dynamic linker sections. */
2336 asection *sgot;
2337 asection *sgotplt;
2338 asection *srelgot;
2339 asection *splt;
2340 asection *srelplt;
2341 asection *sdynbss;
2342 asection *srelbss;
5e681ec4 2343
906e58ca
NC
2344 /* The (unloaded but important) VxWorks .rela.plt.unloaded section. */
2345 asection *srelplt2;
00a97672 2346
906e58ca
NC
2347 /* Data for R_ARM_TLS_LDM32 relocations. */
2348 union
2349 {
2350 bfd_signed_vma refcount;
2351 bfd_vma offset;
2352 } tls_ldm_got;
b7693d02 2353
906e58ca
NC
2354 /* Small local sym to section mapping cache. */
2355 struct sym_sec_cache sym_sec;
2356
2357 /* For convenience in allocate_dynrelocs. */
2358 bfd * obfd;
2359
2360 /* The stub hash table. */
2361 struct bfd_hash_table stub_hash_table;
2362
2363 /* Linker stub bfd. */
2364 bfd *stub_bfd;
2365
2366 /* Linker call-backs. */
2367 asection * (*add_stub_section) (const char *, asection *);
2368 void (*layout_sections_again) (void);
2369
2370 /* Array to keep track of which stub sections have been created, and
2371 information on stub grouping. */
2372 struct map_stub
2373 {
2374 /* This is the section to which stubs in the group will be
2375 attached. */
2376 asection *link_sec;
2377 /* The stub section. */
2378 asection *stub_sec;
2379 } *stub_group;
2380
2381 /* Assorted information used by elf32_arm_size_stubs. */
2382 unsigned int bfd_count;
2383 int top_index;
2384 asection **input_list;
2385};
252b5132 2386
780a67af
NC
2387/* Create an entry in an ARM ELF linker hash table. */
2388
2389static struct bfd_hash_entry *
57e8b36a
NC
2390elf32_arm_link_hash_newfunc (struct bfd_hash_entry * entry,
2391 struct bfd_hash_table * table,
2392 const char * string)
780a67af
NC
2393{
2394 struct elf32_arm_link_hash_entry * ret =
2395 (struct elf32_arm_link_hash_entry *) entry;
2396
2397 /* Allocate the structure if it has not already been allocated by a
2398 subclass. */
906e58ca 2399 if (ret == NULL)
57e8b36a
NC
2400 ret = bfd_hash_allocate (table, sizeof (struct elf32_arm_link_hash_entry));
2401 if (ret == NULL)
780a67af
NC
2402 return (struct bfd_hash_entry *) ret;
2403
2404 /* Call the allocation method of the superclass. */
2405 ret = ((struct elf32_arm_link_hash_entry *)
2406 _bfd_elf_link_hash_newfunc ((struct bfd_hash_entry *) ret,
2407 table, string));
57e8b36a 2408 if (ret != NULL)
b7693d02
DJ
2409 {
2410 ret->relocs_copied = NULL;
ba93b8ac 2411 ret->tls_type = GOT_UNKNOWN;
b7693d02 2412 ret->plt_thumb_refcount = 0;
bd97cb95 2413 ret->plt_maybe_thumb_refcount = 0;
b7693d02 2414 ret->plt_got_offset = -1;
a4fd1a8e 2415 ret->export_glue = NULL;
906e58ca
NC
2416
2417 ret->stub_cache = NULL;
b7693d02 2418 }
780a67af
NC
2419
2420 return (struct bfd_hash_entry *) ret;
2421}
2422
906e58ca
NC
2423/* Initialize an entry in the stub hash table. */
2424
2425static struct bfd_hash_entry *
2426stub_hash_newfunc (struct bfd_hash_entry *entry,
2427 struct bfd_hash_table *table,
2428 const char *string)
2429{
2430 /* Allocate the structure if it has not already been allocated by a
2431 subclass. */
2432 if (entry == NULL)
2433 {
2434 entry = bfd_hash_allocate (table,
2435 sizeof (struct elf32_arm_stub_hash_entry));
2436 if (entry == NULL)
2437 return entry;
2438 }
2439
2440 /* Call the allocation method of the superclass. */
2441 entry = bfd_hash_newfunc (entry, table, string);
2442 if (entry != NULL)
2443 {
2444 struct elf32_arm_stub_hash_entry *eh;
2445
2446 /* Initialize the local fields. */
2447 eh = (struct elf32_arm_stub_hash_entry *) entry;
2448 eh->stub_sec = NULL;
2449 eh->stub_offset = 0;
2450 eh->target_value = 0;
2451 eh->target_section = NULL;
2452 eh->stub_type = arm_stub_none;
2453 eh->h = NULL;
2454 eh->id_sec = NULL;
2455 }
2456
2457 return entry;
2458}
2459
00a97672
RS
2460/* Return true if NAME is the name of the relocation section associated
2461 with S. */
2462
2463static bfd_boolean
2464reloc_section_p (struct elf32_arm_link_hash_table *htab,
2465 const char *name, asection *s)
2466{
2467 if (htab->use_rel)
0112cd26 2468 return CONST_STRNEQ (name, ".rel") && strcmp (s->name, name + 4) == 0;
00a97672 2469 else
0112cd26 2470 return CONST_STRNEQ (name, ".rela") && strcmp (s->name, name + 5) == 0;
00a97672
RS
2471}
2472
2473/* Create .got, .gotplt, and .rel(a).got sections in DYNOBJ, and set up
5e681ec4
PB
2474 shortcuts to them in our hash table. */
2475
2476static bfd_boolean
57e8b36a 2477create_got_section (bfd *dynobj, struct bfd_link_info *info)
5e681ec4
PB
2478{
2479 struct elf32_arm_link_hash_table *htab;
2480
e5a52504
MM
2481 htab = elf32_arm_hash_table (info);
2482 /* BPABI objects never have a GOT, or associated sections. */
2483 if (htab->symbian_p)
2484 return TRUE;
2485
5e681ec4
PB
2486 if (! _bfd_elf_create_got_section (dynobj, info))
2487 return FALSE;
2488
5e681ec4
PB
2489 htab->sgot = bfd_get_section_by_name (dynobj, ".got");
2490 htab->sgotplt = bfd_get_section_by_name (dynobj, ".got.plt");
2491 if (!htab->sgot || !htab->sgotplt)
2492 abort ();
2493
00a97672
RS
2494 htab->srelgot = bfd_make_section_with_flags (dynobj,
2495 RELOC_SECTION (htab, ".got"),
3496cb2a
L
2496 (SEC_ALLOC | SEC_LOAD
2497 | SEC_HAS_CONTENTS
2498 | SEC_IN_MEMORY
2499 | SEC_LINKER_CREATED
2500 | SEC_READONLY));
5e681ec4 2501 if (htab->srelgot == NULL
5e681ec4
PB
2502 || ! bfd_set_section_alignment (dynobj, htab->srelgot, 2))
2503 return FALSE;
2504 return TRUE;
2505}
2506
00a97672
RS
2507/* Create .plt, .rel(a).plt, .got, .got.plt, .rel(a).got, .dynbss, and
2508 .rel(a).bss sections in DYNOBJ, and set up shortcuts to them in our
5e681ec4
PB
2509 hash table. */
2510
2511static bfd_boolean
57e8b36a 2512elf32_arm_create_dynamic_sections (bfd *dynobj, struct bfd_link_info *info)
5e681ec4
PB
2513{
2514 struct elf32_arm_link_hash_table *htab;
2515
2516 htab = elf32_arm_hash_table (info);
2517 if (!htab->sgot && !create_got_section (dynobj, info))
2518 return FALSE;
2519
2520 if (!_bfd_elf_create_dynamic_sections (dynobj, info))
2521 return FALSE;
2522
2523 htab->splt = bfd_get_section_by_name (dynobj, ".plt");
00a97672
RS
2524 htab->srelplt = bfd_get_section_by_name (dynobj,
2525 RELOC_SECTION (htab, ".plt"));
5e681ec4
PB
2526 htab->sdynbss = bfd_get_section_by_name (dynobj, ".dynbss");
2527 if (!info->shared)
00a97672
RS
2528 htab->srelbss = bfd_get_section_by_name (dynobj,
2529 RELOC_SECTION (htab, ".bss"));
2530
2531 if (htab->vxworks_p)
2532 {
2533 if (!elf_vxworks_create_dynamic_sections (dynobj, info, &htab->srelplt2))
2534 return FALSE;
2535
2536 if (info->shared)
2537 {
2538 htab->plt_header_size = 0;
2539 htab->plt_entry_size
2540 = 4 * ARRAY_SIZE (elf32_arm_vxworks_shared_plt_entry);
2541 }
2542 else
2543 {
2544 htab->plt_header_size
2545 = 4 * ARRAY_SIZE (elf32_arm_vxworks_exec_plt0_entry);
2546 htab->plt_entry_size
2547 = 4 * ARRAY_SIZE (elf32_arm_vxworks_exec_plt_entry);
2548 }
2549 }
5e681ec4 2550
906e58ca 2551 if (!htab->splt
e5a52504
MM
2552 || !htab->srelplt
2553 || !htab->sdynbss
5e681ec4
PB
2554 || (!info->shared && !htab->srelbss))
2555 abort ();
2556
2557 return TRUE;
2558}
2559
906e58ca
NC
2560/* Copy the extra info we tack onto an elf_link_hash_entry. */
2561
2562static void
2563elf32_arm_copy_indirect_symbol (struct bfd_link_info *info,
2564 struct elf_link_hash_entry *dir,
2565 struct elf_link_hash_entry *ind)
2566{
2567 struct elf32_arm_link_hash_entry *edir, *eind;
2568
2569 edir = (struct elf32_arm_link_hash_entry *) dir;
2570 eind = (struct elf32_arm_link_hash_entry *) ind;
2571
2572 if (eind->relocs_copied != NULL)
2573 {
2574 if (edir->relocs_copied != NULL)
2575 {
2576 struct elf32_arm_relocs_copied **pp;
2577 struct elf32_arm_relocs_copied *p;
2578
2579 /* Add reloc counts against the indirect sym to the direct sym
2580 list. Merge any entries against the same section. */
2581 for (pp = &eind->relocs_copied; (p = *pp) != NULL; )
2582 {
2583 struct elf32_arm_relocs_copied *q;
2584
2585 for (q = edir->relocs_copied; q != NULL; q = q->next)
2586 if (q->section == p->section)
2587 {
2588 q->pc_count += p->pc_count;
2589 q->count += p->count;
2590 *pp = p->next;
2591 break;
2592 }
2593 if (q == NULL)
2594 pp = &p->next;
2595 }
2596 *pp = edir->relocs_copied;
2597 }
2598
2599 edir->relocs_copied = eind->relocs_copied;
2600 eind->relocs_copied = NULL;
2601 }
2602
2603 if (ind->root.type == bfd_link_hash_indirect)
2604 {
2605 /* Copy over PLT info. */
2606 edir->plt_thumb_refcount += eind->plt_thumb_refcount;
2607 eind->plt_thumb_refcount = 0;
2608 edir->plt_maybe_thumb_refcount += eind->plt_maybe_thumb_refcount;
2609 eind->plt_maybe_thumb_refcount = 0;
2610
2611 if (dir->got.refcount <= 0)
2612 {
2613 edir->tls_type = eind->tls_type;
2614 eind->tls_type = GOT_UNKNOWN;
2615 }
2616 }
2617
2618 _bfd_elf_link_hash_copy_indirect (info, dir, ind);
2619}
2620
2621/* Create an ARM elf linker hash table. */
2622
2623static struct bfd_link_hash_table *
2624elf32_arm_link_hash_table_create (bfd *abfd)
2625{
2626 struct elf32_arm_link_hash_table *ret;
2627 bfd_size_type amt = sizeof (struct elf32_arm_link_hash_table);
2628
2629 ret = bfd_malloc (amt);
2630 if (ret == NULL)
2631 return NULL;
2632
2633 if (!_bfd_elf_link_hash_table_init (& ret->root, abfd,
2634 elf32_arm_link_hash_newfunc,
2635 sizeof (struct elf32_arm_link_hash_entry)))
2636 {
2637 free (ret);
2638 return NULL;
2639 }
2640
2641 ret->sgot = NULL;
2642 ret->sgotplt = NULL;
2643 ret->srelgot = NULL;
2644 ret->splt = NULL;
2645 ret->srelplt = NULL;
2646 ret->sdynbss = NULL;
2647 ret->srelbss = NULL;
2648 ret->srelplt2 = NULL;
2649 ret->thumb_glue_size = 0;
2650 ret->arm_glue_size = 0;
2651 ret->bx_glue_size = 0;
2652 memset (ret->bx_glue_offset, 0, sizeof (ret->bx_glue_offset));
2653 ret->vfp11_fix = BFD_ARM_VFP11_FIX_NONE;
2654 ret->vfp11_erratum_glue_size = 0;
2655 ret->num_vfp11_fixes = 0;
2656 ret->bfd_of_glue_owner = NULL;
2657 ret->byteswap_code = 0;
2658 ret->target1_is_rel = 0;
2659 ret->target2_reloc = R_ARM_NONE;
2660#ifdef FOUR_WORD_PLT
2661 ret->plt_header_size = 16;
2662 ret->plt_entry_size = 16;
2663#else
2664 ret->plt_header_size = 20;
2665 ret->plt_entry_size = 12;
2666#endif
2667 ret->fix_v4bx = 0;
2668 ret->use_blx = 0;
2669 ret->vxworks_p = 0;
2670 ret->symbian_p = 0;
2671 ret->use_rel = 1;
2672 ret->sym_sec.abfd = NULL;
2673 ret->obfd = abfd;
2674 ret->tls_ldm_got.refcount = 0;
6cee0a6f
L
2675 ret->stub_bfd = NULL;
2676 ret->add_stub_section = NULL;
2677 ret->layout_sections_again = NULL;
2678 ret->stub_group = NULL;
2679 ret->bfd_count = 0;
2680 ret->top_index = 0;
2681 ret->input_list = NULL;
906e58ca
NC
2682
2683 if (!bfd_hash_table_init (&ret->stub_hash_table, stub_hash_newfunc,
2684 sizeof (struct elf32_arm_stub_hash_entry)))
2685 {
2686 free (ret);
2687 return NULL;
2688 }
2689
2690 return &ret->root.root;
2691}
2692
2693/* Free the derived linker hash table. */
2694
2695static void
2696elf32_arm_hash_table_free (struct bfd_link_hash_table *hash)
2697{
2698 struct elf32_arm_link_hash_table *ret
2699 = (struct elf32_arm_link_hash_table *) hash;
2700
2701 bfd_hash_table_free (&ret->stub_hash_table);
2702 _bfd_generic_link_hash_table_free (hash);
2703}
2704
2705/* Determine if we're dealing with a Thumb only architecture. */
2706
2707static bfd_boolean
2708using_thumb_only (struct elf32_arm_link_hash_table *globals)
2709{
2710 int arch = bfd_elf_get_obj_attr_int (globals->obfd, OBJ_ATTR_PROC,
2711 Tag_CPU_arch);
2712 int profile;
2713
2714 if (arch != TAG_CPU_ARCH_V7)
2715 return FALSE;
2716
2717 profile = bfd_elf_get_obj_attr_int (globals->obfd, OBJ_ATTR_PROC,
2718 Tag_CPU_arch_profile);
2719
2720 return profile == 'M';
2721}
2722
2723/* Determine if we're dealing with a Thumb-2 object. */
2724
2725static bfd_boolean
2726using_thumb2 (struct elf32_arm_link_hash_table *globals)
2727{
2728 int arch = bfd_elf_get_obj_attr_int (globals->obfd, OBJ_ATTR_PROC,
2729 Tag_CPU_arch);
2730 return arch == TAG_CPU_ARCH_V6T2 || arch >= TAG_CPU_ARCH_V7;
2731}
2732
f4ac8484
DJ
2733static bfd_boolean
2734arm_stub_is_thumb (enum elf32_arm_stub_type stub_type)
2735{
2736 switch (stub_type)
2737 {
2738 case arm_thumb_thumb_stub_long_branch:
2739 case arm_thumb_arm_v4t_stub_long_branch:
2740 return TRUE;
2741 case arm_stub_none:
2742 BFD_FAIL ();
2743 return FALSE;
2744 break;
2745 default:
2746 return FALSE;
2747 }
2748}
2749
906e58ca
NC
2750/* Determine the type of stub needed, if any, for a call. */
2751
2752static enum elf32_arm_stub_type
2753arm_type_of_stub (struct bfd_link_info *info,
2754 asection *input_sec,
2755 const Elf_Internal_Rela *rel,
2756 unsigned char st_type,
2757 struct elf32_arm_link_hash_entry *hash,
2758 bfd_vma destination)
2759{
2760 bfd_vma location;
2761 bfd_signed_vma branch_offset;
2762 unsigned int r_type;
2763 struct elf32_arm_link_hash_table * globals;
2764 int thumb2;
2765 int thumb_only;
2766 enum elf32_arm_stub_type stub_type = arm_stub_none;
2767
da5938a2
NC
2768 /* We don't know the actual type of destination in case it is of
2769 type STT_SECTION: give up */
2770 if (st_type == STT_SECTION)
2771 return stub_type;
2772
906e58ca
NC
2773 globals = elf32_arm_hash_table (info);
2774
2775 thumb_only = using_thumb_only (globals);
2776
2777 thumb2 = using_thumb2 (globals);
2778
2779 /* Determine where the call point is. */
2780 location = (input_sec->output_offset
2781 + input_sec->output_section->vma
2782 + rel->r_offset);
2783
2784 branch_offset = (bfd_signed_vma)(destination - location);
2785
2786 r_type = ELF32_R_TYPE (rel->r_info);
2787
2788 /* If the call will go through a PLT entry then we do not need
2789 glue. */
329dcd78 2790 if (globals->splt != NULL && hash != NULL && hash->root.plt.offset != (bfd_vma) -1)
906e58ca
NC
2791 return stub_type;
2792
2793 if (r_type == R_ARM_THM_CALL)
2794 {
2795 if ((!thumb2
2796 && (branch_offset > THM_MAX_FWD_BRANCH_OFFSET
2797 || (branch_offset < THM_MAX_BWD_BRANCH_OFFSET)))
2798 || (thumb2
2799 && (branch_offset > THM2_MAX_FWD_BRANCH_OFFSET
2800 || (branch_offset < THM2_MAX_BWD_BRANCH_OFFSET)))
2801 || ((st_type != STT_ARM_TFUNC) && !globals->use_blx))
2802 {
2803 if (st_type == STT_ARM_TFUNC)
2804 {
2805 /* Thumb to thumb. */
2806 if (!thumb_only)
2807 {
2808 stub_type = (info->shared | globals->pic_veneer)
2809 ? ((globals->use_blx)
2810 ? arm_stub_pic_long_branch
2811 : arm_stub_none)
2812 : (globals->use_blx)
2813 ? arm_stub_long_branch
2814 : arm_stub_none;
2815 }
2816 else
2817 {
2818 stub_type = (info->shared | globals->pic_veneer)
2819 ? arm_stub_none
2820 : (globals->use_blx)
2821 ? arm_thumb_thumb_stub_long_branch
2822 : arm_stub_none;
2823 }
2824 }
2825 else
2826 {
2827 /* Thumb to arm. */
2828 stub_type = (info->shared | globals->pic_veneer)
2829 ? ((globals->use_blx)
2830 ? arm_stub_pic_long_branch
2831 : arm_stub_none)
2832 : (globals->use_blx)
2833 ? arm_stub_long_branch
2834 : arm_thumb_arm_v4t_stub_long_branch;
2835 }
2836 }
2837 }
2838 else if (r_type == R_ARM_CALL)
2839 {
2840 if (st_type == STT_ARM_TFUNC)
2841 {
2842 /* Arm to thumb. */
2843 /* We have an extra 2-bytes reach because of the mode change
2844 (bit 24 (H) of BLX encoding). */
2845 if (branch_offset > (ARM_MAX_FWD_BRANCH_OFFSET + 2)
2846 || (branch_offset < ARM_MAX_BWD_BRANCH_OFFSET)
2847 || !globals->use_blx)
2848 {
2849 stub_type = (info->shared | globals->pic_veneer)
2850 ? arm_stub_pic_long_branch
2851 : (globals->use_blx)
2852 ? arm_stub_long_branch
2853 : arm_thumb_v4t_stub_long_branch;
2854 }
2855 }
2856 else
2857 {
2858 /* Arm to arm. */
2859 if (branch_offset > ARM_MAX_FWD_BRANCH_OFFSET
2860 || (branch_offset < ARM_MAX_BWD_BRANCH_OFFSET))
2861 {
2862 stub_type = (info->shared | globals->pic_veneer)
2863 ? arm_stub_pic_long_branch
2864 : arm_stub_long_branch;
2865 }
2866 }
2867 }
2868
2869 return stub_type;
2870}
2871
2872/* Build a name for an entry in the stub hash table. */
2873
2874static char *
2875elf32_arm_stub_name (const asection *input_section,
2876 const asection *sym_sec,
2877 const struct elf32_arm_link_hash_entry *hash,
2878 const Elf_Internal_Rela *rel)
2879{
2880 char *stub_name;
2881 bfd_size_type len;
2882
2883 if (hash)
2884 {
2885 len = 8 + 1 + strlen (hash->root.root.root.string) + 1 + 8 + 1;
2886 stub_name = bfd_malloc (len);
2887 if (stub_name != NULL)
2888 sprintf (stub_name, "%08x_%s+%x",
2889 input_section->id & 0xffffffff,
2890 hash->root.root.root.string,
2891 (int) rel->r_addend & 0xffffffff);
2892 }
2893 else
2894 {
2895 len = 8 + 1 + 8 + 1 + 8 + 1 + 8 + 1;
2896 stub_name = bfd_malloc (len);
2897 if (stub_name != NULL)
2898 sprintf (stub_name, "%08x_%x:%x+%x",
2899 input_section->id & 0xffffffff,
2900 sym_sec->id & 0xffffffff,
2901 (int) ELF32_R_SYM (rel->r_info) & 0xffffffff,
2902 (int) rel->r_addend & 0xffffffff);
2903 }
2904
2905 return stub_name;
2906}
2907
2908/* Look up an entry in the stub hash. Stub entries are cached because
2909 creating the stub name takes a bit of time. */
2910
2911static struct elf32_arm_stub_hash_entry *
2912elf32_arm_get_stub_entry (const asection *input_section,
2913 const asection *sym_sec,
2914 struct elf_link_hash_entry *hash,
2915 const Elf_Internal_Rela *rel,
2916 struct elf32_arm_link_hash_table *htab)
2917{
2918 struct elf32_arm_stub_hash_entry *stub_entry;
2919 struct elf32_arm_link_hash_entry *h = (struct elf32_arm_link_hash_entry *) hash;
2920 const asection *id_sec;
2921
2922 if ((input_section->flags & SEC_CODE) == 0)
2923 return NULL;
2924
2925 /* If this input section is part of a group of sections sharing one
2926 stub section, then use the id of the first section in the group.
2927 Stub names need to include a section id, as there may well be
2928 more than one stub used to reach say, printf, and we need to
2929 distinguish between them. */
2930 id_sec = htab->stub_group[input_section->id].link_sec;
2931
2932 if (h != NULL && h->stub_cache != NULL
2933 && h->stub_cache->h == h
2934 && h->stub_cache->id_sec == id_sec)
2935 {
2936 stub_entry = h->stub_cache;
2937 }
2938 else
2939 {
2940 char *stub_name;
2941
2942 stub_name = elf32_arm_stub_name (id_sec, sym_sec, h, rel);
2943 if (stub_name == NULL)
2944 return NULL;
2945
2946 stub_entry = arm_stub_hash_lookup (&htab->stub_hash_table,
2947 stub_name, FALSE, FALSE);
2948 if (h != NULL)
2949 h->stub_cache = stub_entry;
2950
2951 free (stub_name);
2952 }
2953
2954 return stub_entry;
2955}
2956
906e58ca
NC
2957/* Add a new stub entry to the stub hash. Not all fields of the new
2958 stub entry are initialised. */
2959
2960static struct elf32_arm_stub_hash_entry *
2961elf32_arm_add_stub (const char *stub_name,
2962 asection *section,
da5938a2 2963 struct elf32_arm_link_hash_table *htab)
906e58ca
NC
2964{
2965 asection *link_sec;
2966 asection *stub_sec;
2967 struct elf32_arm_stub_hash_entry *stub_entry;
2968
2969 link_sec = htab->stub_group[section->id].link_sec;
2970 stub_sec = htab->stub_group[section->id].stub_sec;
2971 if (stub_sec == NULL)
2972 {
2973 stub_sec = htab->stub_group[link_sec->id].stub_sec;
2974 if (stub_sec == NULL)
2975 {
2976 size_t namelen;
2977 bfd_size_type len;
2978 char *s_name;
2979
2980 namelen = strlen (link_sec->name);
2981 len = namelen + sizeof (STUB_SUFFIX);
2982 s_name = bfd_alloc (htab->stub_bfd, len);
2983 if (s_name == NULL)
2984 return NULL;
2985
2986 memcpy (s_name, link_sec->name, namelen);
2987 memcpy (s_name + namelen, STUB_SUFFIX, sizeof (STUB_SUFFIX));
2988 stub_sec = (*htab->add_stub_section) (s_name, link_sec);
2989 if (stub_sec == NULL)
2990 return NULL;
2991 htab->stub_group[link_sec->id].stub_sec = stub_sec;
2992 }
2993 htab->stub_group[section->id].stub_sec = stub_sec;
2994 }
2995
2996 /* Enter this entry into the linker stub hash table. */
2997 stub_entry = arm_stub_hash_lookup (&htab->stub_hash_table, stub_name,
2998 TRUE, FALSE);
2999 if (stub_entry == NULL)
3000 {
3001 (*_bfd_error_handler) (_("%s: cannot create stub entry %s"),
3002 section->owner,
3003 stub_name);
3004 return NULL;
3005 }
3006
3007 stub_entry->stub_sec = stub_sec;
3008 stub_entry->stub_offset = 0;
3009 stub_entry->id_sec = link_sec;
3010
906e58ca
NC
3011 return stub_entry;
3012}
3013
3014/* Store an Arm insn into an output section not processed by
3015 elf32_arm_write_section. */
3016
3017static void
3018put_arm_insn (struct elf32_arm_link_hash_table *htab,
3019 bfd * output_bfd, bfd_vma val, void * ptr)
3020{
3021 if (htab->byteswap_code != bfd_little_endian (output_bfd))
3022 bfd_putl32 (val, ptr);
3023 else
3024 bfd_putb32 (val, ptr);
3025}
3026
3027/* Store a 16-bit Thumb insn into an output section not processed by
3028 elf32_arm_write_section. */
3029
3030static void
3031put_thumb_insn (struct elf32_arm_link_hash_table *htab,
3032 bfd * output_bfd, bfd_vma val, void * ptr)
3033{
3034 if (htab->byteswap_code != bfd_little_endian (output_bfd))
3035 bfd_putl16 (val, ptr);
3036 else
3037 bfd_putb16 (val, ptr);
3038}
3039
3040static bfd_boolean
3041arm_build_one_stub (struct bfd_hash_entry *gen_entry,
3042 void * in_arg)
3043{
3044 struct elf32_arm_stub_hash_entry *stub_entry;
3045 struct bfd_link_info *info;
3046 struct elf32_arm_link_hash_table *htab;
3047 asection *stub_sec;
3048 bfd *stub_bfd;
3049 bfd_vma stub_addr;
3050 bfd_byte *loc;
3051 bfd_vma sym_value;
3052 int template_size;
3053 int size;
3054 const bfd_vma *template;
3055 int i;
3056 struct elf32_arm_link_hash_table * globals;
3057
3058 /* Massage our args to the form they really have. */
3059 stub_entry = (struct elf32_arm_stub_hash_entry *) gen_entry;
3060 info = (struct bfd_link_info *) in_arg;
3061
3062 globals = elf32_arm_hash_table (info);
3063
3064 htab = elf32_arm_hash_table (info);
3065 stub_sec = stub_entry->stub_sec;
3066
3067 /* Make a note of the offset within the stubs for this entry. */
3068 stub_entry->stub_offset = stub_sec->size;
3069 loc = stub_sec->contents + stub_entry->stub_offset;
3070
3071 stub_bfd = stub_sec->owner;
3072
3073 /* This is the address of the start of the stub. */
3074 stub_addr = stub_sec->output_section->vma + stub_sec->output_offset
3075 + stub_entry->stub_offset;
3076
3077 /* This is the address of the stub destination. */
3078 sym_value = (stub_entry->target_value
3079 + stub_entry->target_section->output_offset
3080 + stub_entry->target_section->output_section->vma);
3081
3082 switch (stub_entry->stub_type)
3083 {
3084 case arm_stub_long_branch:
3085 template = arm_long_branch_stub;
3086 template_size = (sizeof (arm_long_branch_stub) / sizeof (bfd_vma)) * 4;
3087 break;
3088 case arm_thumb_v4t_stub_long_branch:
3089 template = arm_thumb_v4t_long_branch_stub;
3090 template_size = (sizeof (arm_thumb_v4t_long_branch_stub) / sizeof (bfd_vma)) * 4;
3091 break;
3092 case arm_thumb_thumb_stub_long_branch:
3093 template = arm_thumb_thumb_long_branch_stub;
3094 template_size = (sizeof (arm_thumb_thumb_long_branch_stub) / sizeof (bfd_vma)) * 4;
3095 break;
3096 case arm_thumb_arm_v4t_stub_long_branch:
3097 template = arm_thumb_arm_v4t_long_branch_stub;
3098 template_size = (sizeof (arm_thumb_arm_v4t_long_branch_stub) / sizeof (bfd_vma)) * 4;
3099 break;
3100 case arm_stub_pic_long_branch:
3101 template = arm_pic_long_branch_stub;
3102 template_size = (sizeof (arm_pic_long_branch_stub) / sizeof (bfd_vma)) * 4;
3103 break;
3104 default:
3105 BFD_FAIL ();
3106 return FALSE;
3107 }
3108
3109 size = 0;
3110 for (i = 0; i < (template_size / 4); i++)
3111 {
3112 /* A 0 pattern is a placeholder, every other pattern is an
3113 instruction. */
3114 if (template[i] != 0)
3115 put_arm_insn (globals, stub_bfd, template[i], loc + size);
3116 else
3117 bfd_put_32 (stub_bfd, template[i], loc + size);
3118
3119 size += 4;
3120 }
3121 stub_sec->size += size;
3122
3123 /* Destination is Thumb. Force bit 0 to 1 to reflect this. */
3124 if (stub_entry->st_type == STT_ARM_TFUNC)
3125 sym_value |= 1;
3126
3127 switch (stub_entry->stub_type)
3128 {
3129 case arm_stub_long_branch:
3130 _bfd_final_link_relocate (elf32_arm_howto_from_type (R_ARM_ABS32),
7413f23f
DJ
3131 stub_bfd, stub_sec, stub_sec->contents,
3132 stub_entry->stub_offset + 4, sym_value, 0);
906e58ca
NC
3133 break;
3134 case arm_thumb_v4t_stub_long_branch:
3135 _bfd_final_link_relocate (elf32_arm_howto_from_type (R_ARM_ABS32),
7413f23f
DJ
3136 stub_bfd, stub_sec, stub_sec->contents,
3137 stub_entry->stub_offset + 8, sym_value, 0);
906e58ca
NC
3138 break;
3139 case arm_thumb_thumb_stub_long_branch:
3140 _bfd_final_link_relocate (elf32_arm_howto_from_type (R_ARM_ABS32),
7413f23f
DJ
3141 stub_bfd, stub_sec, stub_sec->contents,
3142 stub_entry->stub_offset + 12, sym_value, 0);
906e58ca
NC
3143 break;
3144 case arm_thumb_arm_v4t_stub_long_branch:
3145 _bfd_final_link_relocate (elf32_arm_howto_from_type (R_ARM_ABS32),
7413f23f
DJ
3146 stub_bfd, stub_sec, stub_sec->contents,
3147 stub_entry->stub_offset + 16, sym_value, 0);
906e58ca
NC
3148 break;
3149 case arm_stub_pic_long_branch:
3150 /* We want the value relative to the address 8 bytes from the
3151 start of the stub. */
7413f23f
DJ
3152 _bfd_final_link_relocate (elf32_arm_howto_from_type (R_ARM_REL32),
3153 stub_bfd, stub_sec, stub_sec->contents,
3154 stub_entry->stub_offset + 8, sym_value, 0);
906e58ca
NC
3155 break;
3156 default:
3157 break;
3158 }
3159
3160 return TRUE;
3161}
3162
3163/* As above, but don't actually build the stub. Just bump offset so
3164 we know stub section sizes. */
3165
3166static bfd_boolean
3167arm_size_one_stub (struct bfd_hash_entry *gen_entry,
3168 void * in_arg)
3169{
3170 struct elf32_arm_stub_hash_entry *stub_entry;
3171 struct elf32_arm_link_hash_table *htab;
3172 const bfd_vma *template;
3173 int template_size;
3174 int size;
3175 int i;
3176
3177 /* Massage our args to the form they really have. */
3178 stub_entry = (struct elf32_arm_stub_hash_entry *) gen_entry;
3179 htab = (struct elf32_arm_link_hash_table *) in_arg;
3180
3181 switch (stub_entry->stub_type)
3182 {
3183 case arm_stub_long_branch:
3184 template = arm_long_branch_stub;
3185 template_size = (sizeof (arm_long_branch_stub) / sizeof (bfd_vma)) * 4;
3186 break;
3187 case arm_thumb_v4t_stub_long_branch:
3188 template = arm_thumb_v4t_long_branch_stub;
3189 template_size = (sizeof (arm_thumb_v4t_long_branch_stub) / sizeof (bfd_vma)) * 4;
3190 break;
3191 case arm_thumb_thumb_stub_long_branch:
3192 template = arm_thumb_thumb_long_branch_stub;
3193 template_size = (sizeof (arm_thumb_thumb_long_branch_stub) / sizeof (bfd_vma)) * 4;
3194 break;
3195 case arm_thumb_arm_v4t_stub_long_branch:
3196 template = arm_thumb_arm_v4t_long_branch_stub;
3197 template_size = (sizeof (arm_thumb_arm_v4t_long_branch_stub) / sizeof (bfd_vma)) * 4;
3198 break;
3199 case arm_stub_pic_long_branch:
3200 template = arm_pic_long_branch_stub;
3201 template_size = (sizeof (arm_pic_long_branch_stub) / sizeof (bfd_vma)) * 4;
3202 break;
3203 default:
3204 BFD_FAIL ();
3205 return FALSE;
3206 break;
3207 }
3208
3209 size = 0;
3210 for (i = 0; i < (template_size / 4); i++)
3211 size += 4;
3212 size = (size + 7) & ~7;
3213 stub_entry->stub_sec->size += size;
3214 return TRUE;
3215}
3216
3217/* External entry points for sizing and building linker stubs. */
3218
3219/* Set up various things so that we can make a list of input sections
3220 for each output section included in the link. Returns -1 on error,
3221 0 when no stubs will be needed, and 1 on success. */
3222
3223int
3224elf32_arm_setup_section_lists (bfd *output_bfd,
3225 struct bfd_link_info *info)
3226{
3227 bfd *input_bfd;
3228 unsigned int bfd_count;
3229 int top_id, top_index;
3230 asection *section;
3231 asection **input_list, **list;
3232 bfd_size_type amt;
3233 struct elf32_arm_link_hash_table *htab = elf32_arm_hash_table (info);
3234
3235 if (! is_elf_hash_table (htab))
3236 return 0;
3237
3238 /* Count the number of input BFDs and find the top input section id. */
3239 for (input_bfd = info->input_bfds, bfd_count = 0, top_id = 0;
3240 input_bfd != NULL;
3241 input_bfd = input_bfd->link_next)
3242 {
3243 bfd_count += 1;
3244 for (section = input_bfd->sections;
3245 section != NULL;
3246 section = section->next)
3247 {
3248 if (top_id < section->id)
3249 top_id = section->id;
3250 }
3251 }
3252 htab->bfd_count = bfd_count;
3253
3254 amt = sizeof (struct map_stub) * (top_id + 1);
3255 htab->stub_group = bfd_zmalloc (amt);
3256 if (htab->stub_group == NULL)
3257 return -1;
3258
3259 /* We can't use output_bfd->section_count here to find the top output
3260 section index as some sections may have been removed, and
3261 _bfd_strip_section_from_output doesn't renumber the indices. */
3262 for (section = output_bfd->sections, top_index = 0;
3263 section != NULL;
3264 section = section->next)
3265 {
3266 if (top_index < section->index)
3267 top_index = section->index;
3268 }
3269
3270 htab->top_index = top_index;
3271 amt = sizeof (asection *) * (top_index + 1);
3272 input_list = bfd_malloc (amt);
3273 htab->input_list = input_list;
3274 if (input_list == NULL)
3275 return -1;
3276
3277 /* For sections we aren't interested in, mark their entries with a
3278 value we can check later. */
3279 list = input_list + top_index;
3280 do
3281 *list = bfd_abs_section_ptr;
3282 while (list-- != input_list);
3283
3284 for (section = output_bfd->sections;
3285 section != NULL;
3286 section = section->next)
3287 {
3288 if ((section->flags & SEC_CODE) != 0)
3289 input_list[section->index] = NULL;
3290 }
3291
3292 return 1;
3293}
3294
3295/* The linker repeatedly calls this function for each input section,
3296 in the order that input sections are linked into output sections.
3297 Build lists of input sections to determine groupings between which
3298 we may insert linker stubs. */
3299
3300void
3301elf32_arm_next_input_section (struct bfd_link_info *info,
3302 asection *isec)
3303{
3304 struct elf32_arm_link_hash_table *htab = elf32_arm_hash_table (info);
3305
3306 if (isec->output_section->index <= htab->top_index)
3307 {
3308 asection **list = htab->input_list + isec->output_section->index;
3309
3310 if (*list != bfd_abs_section_ptr)
3311 {
3312 /* Steal the link_sec pointer for our list. */
3313#define PREV_SEC(sec) (htab->stub_group[(sec)->id].link_sec)
3314 /* This happens to make the list in reverse order,
3315 which is what we want. */
3316 PREV_SEC (isec) = *list;
3317 *list = isec;
3318 }
3319 }
3320}
3321
3322/* See whether we can group stub sections together. Grouping stub
3323 sections may result in fewer stubs. More importantly, we need to
3324 put all .init* and .fini* stubs at the beginning of the .init or
3325 .fini output sections respectively, because glibc splits the
3326 _init and _fini functions into multiple parts. Putting a stub in
3327 the middle of a function is not a good idea. */
3328
3329static void
3330group_sections (struct elf32_arm_link_hash_table *htab,
3331 bfd_size_type stub_group_size,
3332 bfd_boolean stubs_always_before_branch)
3333{
3334 asection **list = htab->input_list + htab->top_index;
3335
3336 do
3337 {
3338 asection *tail = *list;
3339
3340 if (tail == bfd_abs_section_ptr)
3341 continue;
3342
3343 while (tail != NULL)
3344 {
3345 asection *curr;
3346 asection *prev;
3347 bfd_size_type total;
3348
3349 curr = tail;
3350 total = tail->size;
3351 while ((prev = PREV_SEC (curr)) != NULL
3352 && ((total += curr->output_offset - prev->output_offset)
3353 < stub_group_size))
3354 curr = prev;
3355
3356 /* OK, the size from the start of CURR to the end is less
3357 than stub_group_size and thus can be handled by one stub
7fb9f789 3358 section. (Or the tail section is itself larger than
906e58ca
NC
3359 stub_group_size, in which case we may be toast.)
3360 We should really be keeping track of the total size of
3361 stubs added here, as stubs contribute to the final output
7fb9f789 3362 section size. */
906e58ca
NC
3363 do
3364 {
3365 prev = PREV_SEC (tail);
3366 /* Set up this stub group. */
3367 htab->stub_group[tail->id].link_sec = curr;
3368 }
3369 while (tail != curr && (tail = prev) != NULL);
3370
3371 /* But wait, there's more! Input sections up to stub_group_size
3372 bytes before the stub section can be handled by it too. */
3373 if (!stubs_always_before_branch)
3374 {
3375 total = 0;
3376 while (prev != NULL
3377 && ((total += tail->output_offset - prev->output_offset)
3378 < stub_group_size))
3379 {
3380 tail = prev;
3381 prev = PREV_SEC (tail);
3382 htab->stub_group[tail->id].link_sec = curr;
3383 }
3384 }
3385 tail = prev;
3386 }
3387 }
3388 while (list-- != htab->input_list);
3389
3390 free (htab->input_list);
3391#undef PREV_SEC
3392}
3393
3394/* Determine and set the size of the stub section for a final link.
3395
3396 The basic idea here is to examine all the relocations looking for
3397 PC-relative calls to a target that is unreachable with a "bl"
3398 instruction. */
3399
3400bfd_boolean
3401elf32_arm_size_stubs (bfd *output_bfd,
3402 bfd *stub_bfd,
3403 struct bfd_link_info *info,
3404 bfd_signed_vma group_size,
3405 asection * (*add_stub_section) (const char *, asection *),
3406 void (*layout_sections_again) (void))
3407{
3408 bfd_size_type stub_group_size;
3409 bfd_boolean stubs_always_before_branch;
3410 bfd_boolean stub_changed = 0;
3411 struct elf32_arm_link_hash_table *htab = elf32_arm_hash_table (info);
3412
3413 /* Propagate mach to stub bfd, because it may not have been
3414 finalized when we created stub_bfd. */
3415 bfd_set_arch_mach (stub_bfd, bfd_get_arch (output_bfd),
3416 bfd_get_mach (output_bfd));
3417
3418 /* Stash our params away. */
3419 htab->stub_bfd = stub_bfd;
3420 htab->add_stub_section = add_stub_section;
3421 htab->layout_sections_again = layout_sections_again;
3422 stubs_always_before_branch = group_size < 0;
3423 if (group_size < 0)
3424 stub_group_size = -group_size;
3425 else
3426 stub_group_size = group_size;
3427
3428 if (stub_group_size == 1)
3429 {
3430 /* Default values. */
3431 /* Thumb branch range is +-4MB has to be used as the default
3432 maximum size (a given section can contain both ARM and Thumb
3433 code, so the worst case has to be taken into account).
3434
3435 This value is 24K less than that, which allows for 2025
3436 12-byte stubs. If we exceed that, then we will fail to link.
3437 The user will have to relink with an explicit group size
3438 option. */
3439 stub_group_size = 4170000;
3440 }
3441
3442 group_sections (htab, stub_group_size, stubs_always_before_branch);
3443
3444 while (1)
3445 {
3446 bfd *input_bfd;
3447 unsigned int bfd_indx;
3448 asection *stub_sec;
3449
3450 for (input_bfd = info->input_bfds, bfd_indx = 0;
3451 input_bfd != NULL;
3452 input_bfd = input_bfd->link_next, bfd_indx++)
3453 {
3454 Elf_Internal_Shdr *symtab_hdr;
3455 asection *section;
3456 Elf_Internal_Sym *local_syms = NULL;
3457
3458 /* We'll need the symbol table in a second. */
3459 symtab_hdr = &elf_tdata (input_bfd)->symtab_hdr;
3460 if (symtab_hdr->sh_info == 0)
3461 continue;
3462
3463 /* Walk over each section attached to the input bfd. */
3464 for (section = input_bfd->sections;
3465 section != NULL;
3466 section = section->next)
3467 {
3468 Elf_Internal_Rela *internal_relocs, *irelaend, *irela;
3469
3470 /* If there aren't any relocs, then there's nothing more
3471 to do. */
3472 if ((section->flags & SEC_RELOC) == 0
3473 || section->reloc_count == 0
3474 || (section->flags & SEC_CODE) == 0)
3475 continue;
3476
3477 /* If this section is a link-once section that will be
3478 discarded, then don't create any stubs. */
3479 if (section->output_section == NULL
3480 || section->output_section->owner != output_bfd)
3481 continue;
3482
3483 /* Get the relocs. */
3484 internal_relocs
3485 = _bfd_elf_link_read_relocs (input_bfd, section, NULL,
3486 NULL, info->keep_memory);
3487 if (internal_relocs == NULL)
3488 goto error_ret_free_local;
3489
3490 /* Now examine each relocation. */
3491 irela = internal_relocs;
3492 irelaend = irela + section->reloc_count;
3493 for (; irela < irelaend; irela++)
3494 {
3495 unsigned int r_type, r_indx;
3496 enum elf32_arm_stub_type stub_type;
3497 struct elf32_arm_stub_hash_entry *stub_entry;
3498 asection *sym_sec;
3499 bfd_vma sym_value;
3500 bfd_vma destination;
3501 struct elf32_arm_link_hash_entry *hash;
7413f23f 3502 const char *sym_name;
906e58ca
NC
3503 char *stub_name;
3504 const asection *id_sec;
3505 unsigned char st_type;
3506
3507 r_type = ELF32_R_TYPE (irela->r_info);
3508 r_indx = ELF32_R_SYM (irela->r_info);
3509
3510 if (r_type >= (unsigned int) R_ARM_max)
3511 {
3512 bfd_set_error (bfd_error_bad_value);
3513 error_ret_free_internal:
3514 if (elf_section_data (section)->relocs == NULL)
3515 free (internal_relocs);
3516 goto error_ret_free_local;
3517 }
3518
3519 /* Only look for stubs on call instructions. */
3520 if ((r_type != (unsigned int) R_ARM_CALL)
3521 && (r_type != (unsigned int) R_ARM_THM_CALL))
3522 continue;
3523
3524 /* Now determine the call target, its name, value,
3525 section. */
3526 sym_sec = NULL;
3527 sym_value = 0;
3528 destination = 0;
3529 hash = NULL;
7413f23f 3530 sym_name = NULL;
906e58ca
NC
3531 if (r_indx < symtab_hdr->sh_info)
3532 {
3533 /* It's a local symbol. */
3534 Elf_Internal_Sym *sym;
3535 Elf_Internal_Shdr *hdr;
3536
3537 if (local_syms == NULL)
3538 {
3539 local_syms
3540 = (Elf_Internal_Sym *) symtab_hdr->contents;
3541 if (local_syms == NULL)
3542 local_syms
3543 = bfd_elf_get_elf_syms (input_bfd, symtab_hdr,
3544 symtab_hdr->sh_info, 0,
3545 NULL, NULL, NULL);
3546 if (local_syms == NULL)
3547 goto error_ret_free_internal;
3548 }
3549
3550 sym = local_syms + r_indx;
3551 hdr = elf_elfsections (input_bfd)[sym->st_shndx];
3552 sym_sec = hdr->bfd_section;
3553 if (ELF_ST_TYPE (sym->st_info) != STT_SECTION)
3554 sym_value = sym->st_value;
3555 destination = (sym_value + irela->r_addend
3556 + sym_sec->output_offset
3557 + sym_sec->output_section->vma);
3558 st_type = ELF_ST_TYPE (sym->st_info);
7413f23f
DJ
3559 sym_name
3560 = bfd_elf_string_from_elf_section (input_bfd,
3561 symtab_hdr->sh_link,
3562 sym->st_name);
906e58ca
NC
3563 }
3564 else
3565 {
3566 /* It's an external symbol. */
3567 int e_indx;
3568
3569 e_indx = r_indx - symtab_hdr->sh_info;
3570 hash = ((struct elf32_arm_link_hash_entry *)
3571 elf_sym_hashes (input_bfd)[e_indx]);
3572
3573 while (hash->root.root.type == bfd_link_hash_indirect
3574 || hash->root.root.type == bfd_link_hash_warning)
3575 hash = ((struct elf32_arm_link_hash_entry *)
3576 hash->root.root.u.i.link);
3577
3578 if (hash->root.root.type == bfd_link_hash_defined
3579 || hash->root.root.type == bfd_link_hash_defweak)
3580 {
3581 sym_sec = hash->root.root.u.def.section;
3582 sym_value = hash->root.root.u.def.value;
3583 if (sym_sec->output_section != NULL)
3584 destination = (sym_value + irela->r_addend
3585 + sym_sec->output_offset
3586 + sym_sec->output_section->vma);
3587 }
3588 else if (hash->root.root.type == bfd_link_hash_undefweak
3589 || hash->root.root.type == bfd_link_hash_undefined)
3590 /* For a shared library, these will need a PLT stub,
3591 which is treated separately.
3592 For absolute code, they cannot be handled. */
3593 continue;
3594 else
3595 {
3596 bfd_set_error (bfd_error_bad_value);
3597 goto error_ret_free_internal;
3598 }
3599 st_type = ELF_ST_TYPE (hash->root.type);
7413f23f 3600 sym_name = hash->root.root.root.string;
906e58ca
NC
3601 }
3602
3603 /* Determine what (if any) linker stub is needed. */
3604 stub_type = arm_type_of_stub (info, section, irela, st_type,
3605 hash, destination);
3606 if (stub_type == arm_stub_none)
3607 continue;
5e681ec4 3608
906e58ca
NC
3609 /* Support for grouping stub sections. */
3610 id_sec = htab->stub_group[section->id].link_sec;
5e681ec4 3611
906e58ca
NC
3612 /* Get the name of this stub. */
3613 stub_name = elf32_arm_stub_name (id_sec, sym_sec, hash, irela);
3614 if (!stub_name)
3615 goto error_ret_free_internal;
5e681ec4 3616
906e58ca
NC
3617 stub_entry = arm_stub_hash_lookup (&htab->stub_hash_table,
3618 stub_name,
3619 FALSE, FALSE);
3620 if (stub_entry != NULL)
3621 {
3622 /* The proper stub has already been created. */
3623 free (stub_name);
3624 continue;
3625 }
5e681ec4 3626
da5938a2 3627 stub_entry = elf32_arm_add_stub (stub_name, section, htab);
906e58ca
NC
3628 if (stub_entry == NULL)
3629 {
3630 free (stub_name);
3631 goto error_ret_free_internal;
3632 }
5e681ec4 3633
906e58ca
NC
3634 stub_entry->target_value = sym_value;
3635 stub_entry->target_section = sym_sec;
3636 stub_entry->stub_type = stub_type;
3637 stub_entry->h = hash;
3638 stub_entry->st_type = st_type;
7413f23f
DJ
3639
3640 if (sym_name == NULL)
3641 sym_name = "unnamed";
3642 stub_entry->output_name
3643 = bfd_alloc (htab->stub_bfd,
3644 sizeof (THUMB2ARM_GLUE_ENTRY_NAME)
3645 + strlen (sym_name));
3646 if (stub_entry->output_name == NULL)
3647 {
3648 free (stub_name);
3649 goto error_ret_free_internal;
3650 }
3651
3652 /* For historical reasons, use the existing names for
3653 ARM-to-Thumb and Thumb-to-ARM stubs. */
3654 if (r_type == (unsigned int) R_ARM_THM_CALL
3655 && st_type != STT_ARM_TFUNC)
3656 sprintf (stub_entry->output_name, THUMB2ARM_GLUE_ENTRY_NAME,
3657 sym_name);
3658 else if (r_type == (unsigned int) R_ARM_CALL
3659 && st_type == STT_ARM_TFUNC)
3660 sprintf (stub_entry->output_name, ARM2THUMB_GLUE_ENTRY_NAME,
3661 sym_name);
3662 else
3663 sprintf (stub_entry->output_name, STUB_ENTRY_NAME,
3664 sym_name);
3665
906e58ca
NC
3666 stub_changed = TRUE;
3667 }
3668
3669 /* We're done with the internal relocs, free them. */
3670 if (elf_section_data (section)->relocs == NULL)
3671 free (internal_relocs);
5e681ec4 3672 }
5e681ec4
PB
3673 }
3674
906e58ca
NC
3675 if (!stub_changed)
3676 break;
5e681ec4 3677
906e58ca
NC
3678 /* OK, we've added some stubs. Find out the new size of the
3679 stub sections. */
3680 for (stub_sec = htab->stub_bfd->sections;
3681 stub_sec != NULL;
3682 stub_sec = stub_sec->next)
3683 stub_sec->size = 0;
b34b2d70 3684
906e58ca
NC
3685 bfd_hash_traverse (&htab->stub_hash_table, arm_size_one_stub, htab);
3686
3687 /* Ask the linker to do its stuff. */
3688 (*htab->layout_sections_again) ();
3689 stub_changed = FALSE;
ba93b8ac
DJ
3690 }
3691
906e58ca
NC
3692 return TRUE;
3693
3694 error_ret_free_local:
3695 return FALSE;
5e681ec4
PB
3696}
3697
906e58ca
NC
3698/* Build all the stubs associated with the current output file. The
3699 stubs are kept in a hash table attached to the main linker hash
3700 table. We also set up the .plt entries for statically linked PIC
3701 functions here. This function is called via arm_elf_finish in the
3702 linker. */
252b5132 3703
906e58ca
NC
3704bfd_boolean
3705elf32_arm_build_stubs (struct bfd_link_info *info)
252b5132 3706{
906e58ca
NC
3707 asection *stub_sec;
3708 struct bfd_hash_table *table;
3709 struct elf32_arm_link_hash_table *htab;
252b5132 3710
906e58ca 3711 htab = elf32_arm_hash_table (info);
252b5132 3712
906e58ca
NC
3713 for (stub_sec = htab->stub_bfd->sections;
3714 stub_sec != NULL;
3715 stub_sec = stub_sec->next)
252b5132 3716 {
906e58ca
NC
3717 bfd_size_type size;
3718
3719 /* Ignore non-stub sections */
3720 if (!strstr (stub_sec->name, STUB_SUFFIX))
3721 continue;
3722
3723 /* Allocate memory to hold the linker stubs. */
3724 size = stub_sec->size;
3725 stub_sec->contents = bfd_zalloc (htab->stub_bfd, size);
3726 if (stub_sec->contents == NULL && size != 0)
3727 return FALSE;
3728 stub_sec->size = 0;
252b5132
RH
3729 }
3730
906e58ca
NC
3731 /* Build the stubs as directed by the stub hash table. */
3732 table = &htab->stub_hash_table;
3733 bfd_hash_traverse (table, arm_build_one_stub, info);
252b5132 3734
906e58ca 3735 return TRUE;
252b5132
RH
3736}
3737
9b485d32
NC
3738/* Locate the Thumb encoded calling stub for NAME. */
3739
252b5132 3740static struct elf_link_hash_entry *
57e8b36a
NC
3741find_thumb_glue (struct bfd_link_info *link_info,
3742 const char *name,
f2a9dd69 3743 char **error_message)
252b5132
RH
3744{
3745 char *tmp_name;
3746 struct elf_link_hash_entry *hash;
3747 struct elf32_arm_link_hash_table *hash_table;
3748
3749 /* We need a pointer to the armelf specific hash table. */
3750 hash_table = elf32_arm_hash_table (link_info);
3751
57e8b36a
NC
3752 tmp_name = bfd_malloc ((bfd_size_type) strlen (name)
3753 + strlen (THUMB2ARM_GLUE_ENTRY_NAME) + 1);
252b5132
RH
3754
3755 BFD_ASSERT (tmp_name);
3756
3757 sprintf (tmp_name, THUMB2ARM_GLUE_ENTRY_NAME, name);
3758
3759 hash = elf_link_hash_lookup
b34976b6 3760 (&(hash_table)->root, tmp_name, FALSE, FALSE, TRUE);
252b5132 3761
b1657152
AM
3762 if (hash == NULL
3763 && asprintf (error_message, _("unable to find THUMB glue '%s' for '%s'"),
3764 tmp_name, name) == -1)
3765 *error_message = (char *) bfd_errmsg (bfd_error_system_call);
252b5132
RH
3766
3767 free (tmp_name);
3768
3769 return hash;
3770}
3771
9b485d32
NC
3772/* Locate the ARM encoded calling stub for NAME. */
3773
252b5132 3774static struct elf_link_hash_entry *
57e8b36a
NC
3775find_arm_glue (struct bfd_link_info *link_info,
3776 const char *name,
f2a9dd69 3777 char **error_message)
252b5132
RH
3778{
3779 char *tmp_name;
3780 struct elf_link_hash_entry *myh;
3781 struct elf32_arm_link_hash_table *hash_table;
3782
3783 /* We need a pointer to the elfarm specific hash table. */
3784 hash_table = elf32_arm_hash_table (link_info);
3785
57e8b36a
NC
3786 tmp_name = bfd_malloc ((bfd_size_type) strlen (name)
3787 + strlen (ARM2THUMB_GLUE_ENTRY_NAME) + 1);
252b5132
RH
3788
3789 BFD_ASSERT (tmp_name);
3790
3791 sprintf (tmp_name, ARM2THUMB_GLUE_ENTRY_NAME, name);
3792
3793 myh = elf_link_hash_lookup
b34976b6 3794 (&(hash_table)->root, tmp_name, FALSE, FALSE, TRUE);
252b5132 3795
b1657152
AM
3796 if (myh == NULL
3797 && asprintf (error_message, _("unable to find ARM glue '%s' for '%s'"),
3798 tmp_name, name) == -1)
3799 *error_message = (char *) bfd_errmsg (bfd_error_system_call);
252b5132
RH
3800
3801 free (tmp_name);
3802
3803 return myh;
3804}
3805
8f6277f5 3806/* ARM->Thumb glue (static images):
252b5132
RH
3807
3808 .arm
3809 __func_from_arm:
3810 ldr r12, __func_addr
3811 bx r12
3812 __func_addr:
906e58ca 3813 .word func @ behave as if you saw a ARM_32 reloc.
252b5132 3814
26079076
PB
3815 (v5t static images)
3816 .arm
3817 __func_from_arm:
3818 ldr pc, __func_addr
3819 __func_addr:
906e58ca 3820 .word func @ behave as if you saw a ARM_32 reloc.
26079076 3821
8f6277f5
PB
3822 (relocatable images)
3823 .arm
3824 __func_from_arm:
3825 ldr r12, __func_offset
3826 add r12, r12, pc
3827 bx r12
3828 __func_offset:
3829 .word func - .
3830 */
3831
3832#define ARM2THUMB_STATIC_GLUE_SIZE 12
252b5132
RH
3833static const insn32 a2t1_ldr_insn = 0xe59fc000;
3834static const insn32 a2t2_bx_r12_insn = 0xe12fff1c;
3835static const insn32 a2t3_func_addr_insn = 0x00000001;
3836
26079076
PB
3837#define ARM2THUMB_V5_STATIC_GLUE_SIZE 8
3838static const insn32 a2t1v5_ldr_insn = 0xe51ff004;
3839static const insn32 a2t2v5_func_addr_insn = 0x00000001;
3840
8f6277f5
PB
3841#define ARM2THUMB_PIC_GLUE_SIZE 16
3842static const insn32 a2t1p_ldr_insn = 0xe59fc004;
3843static const insn32 a2t2p_add_pc_insn = 0xe08cc00f;
3844static const insn32 a2t3p_bx_r12_insn = 0xe12fff1c;
3845
9b485d32 3846/* Thumb->ARM: Thumb->(non-interworking aware) ARM
252b5132
RH
3847
3848 .thumb .thumb
3849 .align 2 .align 2
3850 __func_from_thumb: __func_from_thumb:
3851 bx pc push {r6, lr}
3852 nop ldr r6, __func_addr
3853 .arm mov lr, pc
3854 __func_change_to_arm: bx r6
3855 b func .arm
3856 __func_back_to_thumb:
3857 ldmia r13! {r6, lr}
3858 bx lr
3859 __func_addr:
9b485d32 3860 .word func */
252b5132
RH
3861
3862#define THUMB2ARM_GLUE_SIZE 8
3863static const insn16 t2a1_bx_pc_insn = 0x4778;
3864static const insn16 t2a2_noop_insn = 0x46c0;
3865static const insn32 t2a3_b_insn = 0xea000000;
3866
c7b8f16e
JB
3867#define VFP11_ERRATUM_VENEER_SIZE 8
3868
845b51d6
PB
3869#define ARM_BX_VENEER_SIZE 12
3870static const insn32 armbx1_tst_insn = 0xe3100001;
3871static const insn32 armbx2_moveq_insn = 0x01a0f000;
3872static const insn32 armbx3_bx_insn = 0xe12fff10;
3873
7e392df6 3874#ifndef ELFARM_NABI_C_INCLUDED
b34976b6 3875bfd_boolean
57e8b36a 3876bfd_elf32_arm_allocate_interworking_sections (struct bfd_link_info * info)
252b5132
RH
3877{
3878 asection * s;
3879 bfd_byte * foo;
3880 struct elf32_arm_link_hash_table * globals;
3881
3882 globals = elf32_arm_hash_table (info);
3883
3884 BFD_ASSERT (globals != NULL);
3885
3886 if (globals->arm_glue_size != 0)
3887 {
3888 BFD_ASSERT (globals->bfd_of_glue_owner != NULL);
3889
dc810e39
AM
3890 s = bfd_get_section_by_name (globals->bfd_of_glue_owner,
3891 ARM2THUMB_GLUE_SECTION_NAME);
252b5132
RH
3892
3893 BFD_ASSERT (s != NULL);
3894
57e8b36a 3895 foo = bfd_alloc (globals->bfd_of_glue_owner, globals->arm_glue_size);
252b5132 3896
2f475487 3897 BFD_ASSERT (s->size == globals->arm_glue_size);
252b5132
RH
3898 s->contents = foo;
3899 }
3900
3901 if (globals->thumb_glue_size != 0)
3902 {
3903 BFD_ASSERT (globals->bfd_of_glue_owner != NULL);
3904
3905 s = bfd_get_section_by_name
3906 (globals->bfd_of_glue_owner, THUMB2ARM_GLUE_SECTION_NAME);
3907
3908 BFD_ASSERT (s != NULL);
3909
57e8b36a 3910 foo = bfd_alloc (globals->bfd_of_glue_owner, globals->thumb_glue_size);
252b5132 3911
2f475487 3912 BFD_ASSERT (s->size == globals->thumb_glue_size);
252b5132
RH
3913 s->contents = foo;
3914 }
906e58ca 3915
c7b8f16e
JB
3916 if (globals->vfp11_erratum_glue_size != 0)
3917 {
3918 BFD_ASSERT (globals->bfd_of_glue_owner != NULL);
906e58ca 3919
c7b8f16e
JB
3920 s = bfd_get_section_by_name
3921 (globals->bfd_of_glue_owner, VFP11_ERRATUM_VENEER_SECTION_NAME);
906e58ca 3922
c7b8f16e 3923 BFD_ASSERT (s != NULL);
906e58ca 3924
c7b8f16e
JB
3925 foo = bfd_alloc (globals->bfd_of_glue_owner,
3926 globals->vfp11_erratum_glue_size);
906e58ca 3927
c7b8f16e
JB
3928 BFD_ASSERT (s->size == globals->vfp11_erratum_glue_size);
3929 s->contents = foo;
3930 }
252b5132 3931
845b51d6
PB
3932 if (globals->bx_glue_size != 0)
3933 {
3934 BFD_ASSERT (globals->bfd_of_glue_owner != NULL);
3935
3936 s = bfd_get_section_by_name (globals->bfd_of_glue_owner,
3937 ARM_BX_GLUE_SECTION_NAME);
3938
3939 BFD_ASSERT (s != NULL);
3940
3941 foo = bfd_alloc (globals->bfd_of_glue_owner, globals->bx_glue_size);
3942
3943 BFD_ASSERT (s->size == globals->bx_glue_size);
3944 s->contents = foo;
3945 }
3946
b34976b6 3947 return TRUE;
252b5132
RH
3948}
3949
a4fd1a8e 3950/* Allocate space and symbols for calling a Thumb function from Arm mode.
906e58ca
NC
3951 returns the symbol identifying the stub. */
3952
a4fd1a8e 3953static struct elf_link_hash_entry *
57e8b36a
NC
3954record_arm_to_thumb_glue (struct bfd_link_info * link_info,
3955 struct elf_link_hash_entry * h)
252b5132
RH
3956{
3957 const char * name = h->root.root.string;
63b0f745 3958 asection * s;
252b5132
RH
3959 char * tmp_name;
3960 struct elf_link_hash_entry * myh;
14a793b2 3961 struct bfd_link_hash_entry * bh;
252b5132 3962 struct elf32_arm_link_hash_table * globals;
dc810e39 3963 bfd_vma val;
2f475487 3964 bfd_size_type size;
252b5132
RH
3965
3966 globals = elf32_arm_hash_table (link_info);
3967
3968 BFD_ASSERT (globals != NULL);
3969 BFD_ASSERT (globals->bfd_of_glue_owner != NULL);
3970
3971 s = bfd_get_section_by_name
3972 (globals->bfd_of_glue_owner, ARM2THUMB_GLUE_SECTION_NAME);
3973
252b5132
RH
3974 BFD_ASSERT (s != NULL);
3975
57e8b36a 3976 tmp_name = bfd_malloc ((bfd_size_type) strlen (name) + strlen (ARM2THUMB_GLUE_ENTRY_NAME) + 1);
252b5132
RH
3977
3978 BFD_ASSERT (tmp_name);
3979
3980 sprintf (tmp_name, ARM2THUMB_GLUE_ENTRY_NAME, name);
3981
3982 myh = elf_link_hash_lookup
b34976b6 3983 (&(globals)->root, tmp_name, FALSE, FALSE, TRUE);
252b5132
RH
3984
3985 if (myh != NULL)
3986 {
9b485d32 3987 /* We've already seen this guy. */
252b5132 3988 free (tmp_name);
a4fd1a8e 3989 return myh;
252b5132
RH
3990 }
3991
57e8b36a
NC
3992 /* The only trick here is using hash_table->arm_glue_size as the value.
3993 Even though the section isn't allocated yet, this is where we will be
3dccd7b7
DJ
3994 putting it. The +1 on the value marks that the stub has not been
3995 output yet - not that it is a Thumb function. */
14a793b2 3996 bh = NULL;
dc810e39
AM
3997 val = globals->arm_glue_size + 1;
3998 _bfd_generic_link_add_one_symbol (link_info, globals->bfd_of_glue_owner,
3999 tmp_name, BSF_GLOBAL, s, val,
b34976b6 4000 NULL, TRUE, FALSE, &bh);
252b5132 4001
b7693d02
DJ
4002 myh = (struct elf_link_hash_entry *) bh;
4003 myh->type = ELF_ST_INFO (STB_LOCAL, STT_FUNC);
4004 myh->forced_local = 1;
4005
252b5132
RH
4006 free (tmp_name);
4007
27e55c4d
PB
4008 if (link_info->shared || globals->root.is_relocatable_executable
4009 || globals->pic_veneer)
2f475487 4010 size = ARM2THUMB_PIC_GLUE_SIZE;
26079076
PB
4011 else if (globals->use_blx)
4012 size = ARM2THUMB_V5_STATIC_GLUE_SIZE;
8f6277f5 4013 else
2f475487
AM
4014 size = ARM2THUMB_STATIC_GLUE_SIZE;
4015
4016 s->size += size;
4017 globals->arm_glue_size += size;
252b5132 4018
a4fd1a8e 4019 return myh;
252b5132
RH
4020}
4021
4022static void
57e8b36a
NC
4023record_thumb_to_arm_glue (struct bfd_link_info *link_info,
4024 struct elf_link_hash_entry *h)
252b5132
RH
4025{
4026 const char *name = h->root.root.string;
63b0f745 4027 asection *s;
252b5132
RH
4028 char *tmp_name;
4029 struct elf_link_hash_entry *myh;
14a793b2 4030 struct bfd_link_hash_entry *bh;
252b5132 4031 struct elf32_arm_link_hash_table *hash_table;
dc810e39 4032 bfd_vma val;
252b5132
RH
4033
4034 hash_table = elf32_arm_hash_table (link_info);
4035
4036 BFD_ASSERT (hash_table != NULL);
4037 BFD_ASSERT (hash_table->bfd_of_glue_owner != NULL);
4038
4039 s = bfd_get_section_by_name
4040 (hash_table->bfd_of_glue_owner, THUMB2ARM_GLUE_SECTION_NAME);
4041
4042 BFD_ASSERT (s != NULL);
4043
57e8b36a
NC
4044 tmp_name = bfd_malloc ((bfd_size_type) strlen (name)
4045 + strlen (THUMB2ARM_GLUE_ENTRY_NAME) + 1);
252b5132
RH
4046
4047 BFD_ASSERT (tmp_name);
4048
4049 sprintf (tmp_name, THUMB2ARM_GLUE_ENTRY_NAME, name);
4050
4051 myh = elf_link_hash_lookup
b34976b6 4052 (&(hash_table)->root, tmp_name, FALSE, FALSE, TRUE);
252b5132
RH
4053
4054 if (myh != NULL)
4055 {
9b485d32 4056 /* We've already seen this guy. */
252b5132 4057 free (tmp_name);
9b485d32 4058 return;
252b5132
RH
4059 }
4060
3dccd7b7
DJ
4061 /* The only trick here is using hash_table->thumb_glue_size as the value.
4062 Even though the section isn't allocated yet, this is where we will be
4063 putting it. The +1 on the value marks that the stub has not been
4064 output yet - not that it is a Thumb function. */
14a793b2 4065 bh = NULL;
dc810e39
AM
4066 val = hash_table->thumb_glue_size + 1;
4067 _bfd_generic_link_add_one_symbol (link_info, hash_table->bfd_of_glue_owner,
4068 tmp_name, BSF_GLOBAL, s, val,
b34976b6 4069 NULL, TRUE, FALSE, &bh);
252b5132 4070
9b485d32 4071 /* If we mark it 'Thumb', the disassembler will do a better job. */
14a793b2 4072 myh = (struct elf_link_hash_entry *) bh;
b7693d02
DJ
4073 myh->type = ELF_ST_INFO (STB_LOCAL, STT_ARM_TFUNC);
4074 myh->forced_local = 1;
252b5132
RH
4075
4076 free (tmp_name);
4077
252b5132
RH
4078#define CHANGE_TO_ARM "__%s_change_to_arm"
4079#define BACK_FROM_ARM "__%s_back_from_arm"
4080
9b485d32 4081 /* Allocate another symbol to mark where we switch to Arm mode. */
57e8b36a
NC
4082 tmp_name = bfd_malloc ((bfd_size_type) strlen (name)
4083 + strlen (CHANGE_TO_ARM) + 1);
252b5132
RH
4084
4085 BFD_ASSERT (tmp_name);
4086
4087 sprintf (tmp_name, CHANGE_TO_ARM, name);
4088
14a793b2 4089 bh = NULL;
dc810e39
AM
4090 val = hash_table->thumb_glue_size + 4,
4091 _bfd_generic_link_add_one_symbol (link_info, hash_table->bfd_of_glue_owner,
4092 tmp_name, BSF_LOCAL, s, val,
b34976b6 4093 NULL, TRUE, FALSE, &bh);
252b5132
RH
4094
4095 free (tmp_name);
4096
2f475487 4097 s->size += THUMB2ARM_GLUE_SIZE;
252b5132
RH
4098 hash_table->thumb_glue_size += THUMB2ARM_GLUE_SIZE;
4099
4100 return;
4101}
4102
c7b8f16e 4103
845b51d6
PB
4104/* Allocate space for ARMv4 BX veneers. */
4105
4106static void
4107record_arm_bx_glue (struct bfd_link_info * link_info, int reg)
4108{
4109 asection * s;
4110 struct elf32_arm_link_hash_table *globals;
4111 char *tmp_name;
4112 struct elf_link_hash_entry *myh;
4113 struct bfd_link_hash_entry *bh;
4114 bfd_vma val;
4115
4116 /* BX PC does not need a veneer. */
4117 if (reg == 15)
4118 return;
4119
4120 globals = elf32_arm_hash_table (link_info);
4121
4122 BFD_ASSERT (globals != NULL);
4123 BFD_ASSERT (globals->bfd_of_glue_owner != NULL);
4124
4125 /* Check if this veneer has already been allocated. */
4126 if (globals->bx_glue_offset[reg])
4127 return;
4128
4129 s = bfd_get_section_by_name
4130 (globals->bfd_of_glue_owner, ARM_BX_GLUE_SECTION_NAME);
4131
4132 BFD_ASSERT (s != NULL);
4133
4134 /* Add symbol for veneer. */
4135 tmp_name = bfd_malloc ((bfd_size_type) strlen (ARM_BX_GLUE_ENTRY_NAME) + 1);
906e58ca 4136
845b51d6 4137 BFD_ASSERT (tmp_name);
906e58ca 4138
845b51d6 4139 sprintf (tmp_name, ARM_BX_GLUE_ENTRY_NAME, reg);
906e58ca 4140
845b51d6
PB
4141 myh = elf_link_hash_lookup
4142 (&(globals)->root, tmp_name, FALSE, FALSE, FALSE);
906e58ca 4143
845b51d6 4144 BFD_ASSERT (myh == NULL);
906e58ca 4145
845b51d6
PB
4146 bh = NULL;
4147 val = globals->bx_glue_size;
4148 _bfd_generic_link_add_one_symbol (link_info, globals->bfd_of_glue_owner,
4149 tmp_name, BSF_FUNCTION | BSF_LOCAL, s, val,
4150 NULL, TRUE, FALSE, &bh);
4151
4152 myh = (struct elf_link_hash_entry *) bh;
4153 myh->type = ELF_ST_INFO (STB_LOCAL, STT_FUNC);
4154 myh->forced_local = 1;
4155
4156 s->size += ARM_BX_VENEER_SIZE;
4157 globals->bx_glue_offset[reg] = globals->bx_glue_size | 2;
4158 globals->bx_glue_size += ARM_BX_VENEER_SIZE;
4159}
4160
4161
c7b8f16e
JB
4162/* Add an entry to the code/data map for section SEC. */
4163
4164static void
4165elf32_arm_section_map_add (asection *sec, char type, bfd_vma vma)
4166{
4167 struct _arm_elf_section_data *sec_data = elf32_arm_section_data (sec);
4168 unsigned int newidx;
906e58ca 4169
c7b8f16e
JB
4170 if (sec_data->map == NULL)
4171 {
4172 sec_data->map = bfd_malloc (sizeof (elf32_arm_section_map));
4173 sec_data->mapcount = 0;
4174 sec_data->mapsize = 1;
4175 }
906e58ca 4176
c7b8f16e 4177 newidx = sec_data->mapcount++;
906e58ca 4178
c7b8f16e
JB
4179 if (sec_data->mapcount > sec_data->mapsize)
4180 {
4181 sec_data->mapsize *= 2;
515ef31d
NC
4182 sec_data->map = bfd_realloc_or_free (sec_data->map, sec_data->mapsize
4183 * sizeof (elf32_arm_section_map));
4184 }
4185
4186 if (sec_data->map)
4187 {
4188 sec_data->map[newidx].vma = vma;
4189 sec_data->map[newidx].type = type;
c7b8f16e 4190 }
c7b8f16e
JB
4191}
4192
4193
4194/* Record information about a VFP11 denorm-erratum veneer. Only ARM-mode
4195 veneers are handled for now. */
4196
4197static bfd_vma
4198record_vfp11_erratum_veneer (struct bfd_link_info *link_info,
4199 elf32_vfp11_erratum_list *branch,
4200 bfd *branch_bfd,
4201 asection *branch_sec,
4202 unsigned int offset)
4203{
4204 asection *s;
4205 struct elf32_arm_link_hash_table *hash_table;
4206 char *tmp_name;
4207 struct elf_link_hash_entry *myh;
4208 struct bfd_link_hash_entry *bh;
4209 bfd_vma val;
4210 struct _arm_elf_section_data *sec_data;
4211 int errcount;
4212 elf32_vfp11_erratum_list *newerr;
906e58ca 4213
c7b8f16e 4214 hash_table = elf32_arm_hash_table (link_info);
906e58ca 4215
c7b8f16e
JB
4216 BFD_ASSERT (hash_table != NULL);
4217 BFD_ASSERT (hash_table->bfd_of_glue_owner != NULL);
906e58ca 4218
c7b8f16e
JB
4219 s = bfd_get_section_by_name
4220 (hash_table->bfd_of_glue_owner, VFP11_ERRATUM_VENEER_SECTION_NAME);
906e58ca 4221
c7b8f16e 4222 sec_data = elf32_arm_section_data (s);
906e58ca 4223
c7b8f16e 4224 BFD_ASSERT (s != NULL);
906e58ca 4225
c7b8f16e
JB
4226 tmp_name = bfd_malloc ((bfd_size_type) strlen
4227 (VFP11_ERRATUM_VENEER_ENTRY_NAME) + 10);
906e58ca 4228
c7b8f16e 4229 BFD_ASSERT (tmp_name);
906e58ca 4230
c7b8f16e
JB
4231 sprintf (tmp_name, VFP11_ERRATUM_VENEER_ENTRY_NAME,
4232 hash_table->num_vfp11_fixes);
906e58ca 4233
c7b8f16e
JB
4234 myh = elf_link_hash_lookup
4235 (&(hash_table)->root, tmp_name, FALSE, FALSE, FALSE);
906e58ca 4236
c7b8f16e 4237 BFD_ASSERT (myh == NULL);
906e58ca 4238
c7b8f16e
JB
4239 bh = NULL;
4240 val = hash_table->vfp11_erratum_glue_size;
4241 _bfd_generic_link_add_one_symbol (link_info, hash_table->bfd_of_glue_owner,
4242 tmp_name, BSF_FUNCTION | BSF_LOCAL, s, val,
4243 NULL, TRUE, FALSE, &bh);
4244
4245 myh = (struct elf_link_hash_entry *) bh;
4246 myh->type = ELF_ST_INFO (STB_LOCAL, STT_FUNC);
4247 myh->forced_local = 1;
4248
4249 /* Link veneer back to calling location. */
4250 errcount = ++(sec_data->erratumcount);
4251 newerr = bfd_zmalloc (sizeof (elf32_vfp11_erratum_list));
906e58ca 4252
c7b8f16e
JB
4253 newerr->type = VFP11_ERRATUM_ARM_VENEER;
4254 newerr->vma = -1;
4255 newerr->u.v.branch = branch;
4256 newerr->u.v.id = hash_table->num_vfp11_fixes;
4257 branch->u.b.veneer = newerr;
4258
4259 newerr->next = sec_data->erratumlist;
4260 sec_data->erratumlist = newerr;
4261
4262 /* A symbol for the return from the veneer. */
4263 sprintf (tmp_name, VFP11_ERRATUM_VENEER_ENTRY_NAME "_r",
4264 hash_table->num_vfp11_fixes);
4265
4266 myh = elf_link_hash_lookup
4267 (&(hash_table)->root, tmp_name, FALSE, FALSE, FALSE);
906e58ca 4268
c7b8f16e
JB
4269 if (myh != NULL)
4270 abort ();
4271
4272 bh = NULL;
4273 val = offset + 4;
4274 _bfd_generic_link_add_one_symbol (link_info, branch_bfd, tmp_name, BSF_LOCAL,
4275 branch_sec, val, NULL, TRUE, FALSE, &bh);
906e58ca 4276
c7b8f16e
JB
4277 myh = (struct elf_link_hash_entry *) bh;
4278 myh->type = ELF_ST_INFO (STB_LOCAL, STT_FUNC);
4279 myh->forced_local = 1;
4280
4281 free (tmp_name);
906e58ca 4282
c7b8f16e
JB
4283 /* Generate a mapping symbol for the veneer section, and explicitly add an
4284 entry for that symbol to the code/data map for the section. */
4285 if (hash_table->vfp11_erratum_glue_size == 0)
4286 {
4287 bh = NULL;
4288 /* FIXME: Creates an ARM symbol. Thumb mode will need attention if it
4289 ever requires this erratum fix. */
4290 _bfd_generic_link_add_one_symbol (link_info,
4291 hash_table->bfd_of_glue_owner, "$a",
4292 BSF_LOCAL, s, 0, NULL,
4293 TRUE, FALSE, &bh);
4294
4295 myh = (struct elf_link_hash_entry *) bh;
4296 myh->type = ELF_ST_INFO (STB_LOCAL, STT_NOTYPE);
4297 myh->forced_local = 1;
906e58ca 4298
c7b8f16e
JB
4299 /* The elf32_arm_init_maps function only cares about symbols from input
4300 BFDs. We must make a note of this generated mapping symbol
4301 ourselves so that code byteswapping works properly in
4302 elf32_arm_write_section. */
4303 elf32_arm_section_map_add (s, 'a', 0);
4304 }
906e58ca 4305
c7b8f16e
JB
4306 s->size += VFP11_ERRATUM_VENEER_SIZE;
4307 hash_table->vfp11_erratum_glue_size += VFP11_ERRATUM_VENEER_SIZE;
4308 hash_table->num_vfp11_fixes++;
906e58ca 4309
c7b8f16e
JB
4310 /* The offset of the veneer. */
4311 return val;
4312}
4313
8afb0e02
NC
4314/* Add the glue sections to ABFD. This function is called from the
4315 linker scripts in ld/emultempl/{armelf}.em. */
9b485d32 4316
b34976b6 4317bfd_boolean
57e8b36a
NC
4318bfd_elf32_arm_add_glue_sections_to_bfd (bfd *abfd,
4319 struct bfd_link_info *info)
252b5132 4320{
252b5132
RH
4321 flagword flags;
4322 asection *sec;
4323
8afb0e02
NC
4324 /* If we are only performing a partial
4325 link do not bother adding the glue. */
1049f94e 4326 if (info->relocatable)
b34976b6 4327 return TRUE;
252b5132 4328
906e58ca
NC
4329 /* linker stubs don't need glue */
4330 if (!strcmp (abfd->filename, "linker stubs"))
4331 return TRUE;
4332
252b5132
RH
4333 sec = bfd_get_section_by_name (abfd, ARM2THUMB_GLUE_SECTION_NAME);
4334
4335 if (sec == NULL)
4336 {
57db232e
NC
4337 /* Note: we do not include the flag SEC_LINKER_CREATED, as this
4338 will prevent elf_link_input_bfd() from processing the contents
4339 of this section. */
2f475487
AM
4340 flags = (SEC_ALLOC | SEC_LOAD | SEC_HAS_CONTENTS | SEC_IN_MEMORY
4341 | SEC_CODE | SEC_READONLY);
252b5132 4342
3496cb2a
L
4343 sec = bfd_make_section_with_flags (abfd,
4344 ARM2THUMB_GLUE_SECTION_NAME,
4345 flags);
252b5132
RH
4346
4347 if (sec == NULL
252b5132 4348 || !bfd_set_section_alignment (abfd, sec, 2))
b34976b6 4349 return FALSE;
9a5aca8c 4350
57db232e
NC
4351 /* Set the gc mark to prevent the section from being removed by garbage
4352 collection, despite the fact that no relocs refer to this section. */
4353 sec->gc_mark = 1;
252b5132
RH
4354 }
4355
4356 sec = bfd_get_section_by_name (abfd, THUMB2ARM_GLUE_SECTION_NAME);
4357
4358 if (sec == NULL)
4359 {
2f475487
AM
4360 flags = (SEC_ALLOC | SEC_LOAD | SEC_HAS_CONTENTS | SEC_IN_MEMORY
4361 | SEC_CODE | SEC_READONLY);
252b5132 4362
3496cb2a
L
4363 sec = bfd_make_section_with_flags (abfd,
4364 THUMB2ARM_GLUE_SECTION_NAME,
4365 flags);
252b5132
RH
4366
4367 if (sec == NULL
252b5132 4368 || !bfd_set_section_alignment (abfd, sec, 2))
b34976b6 4369 return FALSE;
9a5aca8c 4370
57db232e 4371 sec->gc_mark = 1;
252b5132
RH
4372 }
4373
c7b8f16e
JB
4374 sec = bfd_get_section_by_name (abfd, VFP11_ERRATUM_VENEER_SECTION_NAME);
4375
4376 if (sec == NULL)
4377 {
4378 flags = (SEC_ALLOC | SEC_LOAD | SEC_HAS_CONTENTS | SEC_IN_MEMORY
4379 | SEC_CODE | SEC_READONLY);
4380
4381 sec = bfd_make_section_with_flags (abfd,
4382 VFP11_ERRATUM_VENEER_SECTION_NAME,
4383 flags);
4384
4385 if (sec == NULL
4386 || !bfd_set_section_alignment (abfd, sec, 2))
4387 return FALSE;
4388
4389 sec->gc_mark = 1;
4390 }
4391
845b51d6
PB
4392 sec = bfd_get_section_by_name (abfd, ARM_BX_GLUE_SECTION_NAME);
4393
4394 if (sec == NULL)
4395 {
4396 flags = (SEC_ALLOC | SEC_LOAD | SEC_HAS_CONTENTS | SEC_IN_MEMORY
4397 | SEC_CODE | SEC_READONLY);
4398
4399 sec = bfd_make_section_with_flags (abfd,
4400 ARM_BX_GLUE_SECTION_NAME,
4401 flags);
4402
4403 if (sec == NULL
4404 || !bfd_set_section_alignment (abfd, sec, 2))
4405 return FALSE;
4406
4407 sec->gc_mark = 1;
4408 }
4409
b34976b6 4410 return TRUE;
8afb0e02
NC
4411}
4412
4413/* Select a BFD to be used to hold the sections used by the glue code.
4414 This function is called from the linker scripts in ld/emultempl/
4415 {armelf/pe}.em */
4416
b34976b6 4417bfd_boolean
57e8b36a 4418bfd_elf32_arm_get_bfd_for_interworking (bfd *abfd, struct bfd_link_info *info)
8afb0e02
NC
4419{
4420 struct elf32_arm_link_hash_table *globals;
4421
4422 /* If we are only performing a partial link
4423 do not bother getting a bfd to hold the glue. */
1049f94e 4424 if (info->relocatable)
b34976b6 4425 return TRUE;
8afb0e02 4426
b7693d02
DJ
4427 /* Make sure we don't attach the glue sections to a dynamic object. */
4428 BFD_ASSERT (!(abfd->flags & DYNAMIC));
4429
8afb0e02
NC
4430 globals = elf32_arm_hash_table (info);
4431
4432 BFD_ASSERT (globals != NULL);
4433
4434 if (globals->bfd_of_glue_owner != NULL)
b34976b6 4435 return TRUE;
8afb0e02 4436
252b5132
RH
4437 /* Save the bfd for later use. */
4438 globals->bfd_of_glue_owner = abfd;
cedb70c5 4439
b34976b6 4440 return TRUE;
252b5132
RH
4441}
4442
906e58ca
NC
4443static void
4444check_use_blx (struct elf32_arm_link_hash_table *globals)
39b41c9c 4445{
104d59d1
JM
4446 if (bfd_elf_get_obj_attr_int (globals->obfd, OBJ_ATTR_PROC,
4447 Tag_CPU_arch) > 2)
39b41c9c
PB
4448 globals->use_blx = 1;
4449}
4450
b34976b6 4451bfd_boolean
57e8b36a 4452bfd_elf32_arm_process_before_allocation (bfd *abfd,
d504ffc8 4453 struct bfd_link_info *link_info)
252b5132
RH
4454{
4455 Elf_Internal_Shdr *symtab_hdr;
6cdc0ccc 4456 Elf_Internal_Rela *internal_relocs = NULL;
252b5132
RH
4457 Elf_Internal_Rela *irel, *irelend;
4458 bfd_byte *contents = NULL;
252b5132
RH
4459
4460 asection *sec;
4461 struct elf32_arm_link_hash_table *globals;
4462
4463 /* If we are only performing a partial link do not bother
4464 to construct any glue. */
1049f94e 4465 if (link_info->relocatable)
b34976b6 4466 return TRUE;
252b5132 4467
39ce1a6a
NC
4468 /* Here we have a bfd that is to be included on the link. We have a
4469 hook to do reloc rummaging, before section sizes are nailed down. */
252b5132
RH
4470 globals = elf32_arm_hash_table (link_info);
4471
4472 BFD_ASSERT (globals != NULL);
39ce1a6a
NC
4473
4474 check_use_blx (globals);
252b5132 4475
d504ffc8 4476 if (globals->byteswap_code && !bfd_big_endian (abfd))
e489d0ae 4477 {
d003868e
AM
4478 _bfd_error_handler (_("%B: BE8 images only valid in big-endian mode."),
4479 abfd);
e489d0ae
PB
4480 return FALSE;
4481 }
f21f3fe0 4482
39ce1a6a
NC
4483 /* PR 5398: If we have not decided to include any loadable sections in
4484 the output then we will not have a glue owner bfd. This is OK, it
4485 just means that there is nothing else for us to do here. */
4486 if (globals->bfd_of_glue_owner == NULL)
4487 return TRUE;
4488
252b5132
RH
4489 /* Rummage around all the relocs and map the glue vectors. */
4490 sec = abfd->sections;
4491
4492 if (sec == NULL)
b34976b6 4493 return TRUE;
252b5132
RH
4494
4495 for (; sec != NULL; sec = sec->next)
4496 {
4497 if (sec->reloc_count == 0)
4498 continue;
4499
2f475487
AM
4500 if ((sec->flags & SEC_EXCLUDE) != 0)
4501 continue;
4502
0ffa91dd 4503 symtab_hdr = & elf_symtab_hdr (abfd);
252b5132 4504
9b485d32 4505 /* Load the relocs. */
6cdc0ccc 4506 internal_relocs
906e58ca 4507 = _bfd_elf_link_read_relocs (abfd, sec, NULL, NULL, FALSE);
252b5132 4508
6cdc0ccc
AM
4509 if (internal_relocs == NULL)
4510 goto error_return;
252b5132 4511
6cdc0ccc
AM
4512 irelend = internal_relocs + sec->reloc_count;
4513 for (irel = internal_relocs; irel < irelend; irel++)
252b5132
RH
4514 {
4515 long r_type;
4516 unsigned long r_index;
252b5132
RH
4517
4518 struct elf_link_hash_entry *h;
4519
4520 r_type = ELF32_R_TYPE (irel->r_info);
4521 r_index = ELF32_R_SYM (irel->r_info);
4522
9b485d32 4523 /* These are the only relocation types we care about. */
ba96a88f 4524 if ( r_type != R_ARM_PC24
b7693d02 4525 && r_type != R_ARM_PLT32
5b5bb741 4526 && r_type != R_ARM_JUMP24
845b51d6
PB
4527 && r_type != R_ARM_THM_JUMP24
4528 && (r_type != R_ARM_V4BX || globals->fix_v4bx < 2))
252b5132
RH
4529 continue;
4530
4531 /* Get the section contents if we haven't done so already. */
4532 if (contents == NULL)
4533 {
4534 /* Get cached copy if it exists. */
4535 if (elf_section_data (sec)->this_hdr.contents != NULL)
4536 contents = elf_section_data (sec)->this_hdr.contents;
4537 else
4538 {
4539 /* Go get them off disk. */
57e8b36a 4540 if (! bfd_malloc_and_get_section (abfd, sec, &contents))
252b5132
RH
4541 goto error_return;
4542 }
4543 }
4544
845b51d6
PB
4545 if (r_type == R_ARM_V4BX)
4546 {
4547 int reg;
4548
4549 reg = bfd_get_32 (abfd, contents + irel->r_offset) & 0xf;
4550 record_arm_bx_glue (link_info, reg);
4551 continue;
4552 }
4553
a7c10850 4554 /* If the relocation is not against a symbol it cannot concern us. */
252b5132
RH
4555 h = NULL;
4556
9b485d32 4557 /* We don't care about local symbols. */
252b5132
RH
4558 if (r_index < symtab_hdr->sh_info)
4559 continue;
4560
9b485d32 4561 /* This is an external symbol. */
252b5132
RH
4562 r_index -= symtab_hdr->sh_info;
4563 h = (struct elf_link_hash_entry *)
4564 elf_sym_hashes (abfd)[r_index];
4565
4566 /* If the relocation is against a static symbol it must be within
4567 the current section and so cannot be a cross ARM/Thumb relocation. */
4568 if (h == NULL)
4569 continue;
4570
d504ffc8
DJ
4571 /* If the call will go through a PLT entry then we do not need
4572 glue. */
4573 if (globals->splt != NULL && h->plt.offset != (bfd_vma) -1)
b7693d02
DJ
4574 continue;
4575
252b5132
RH
4576 switch (r_type)
4577 {
4578 case R_ARM_PC24:
c6596c5e 4579 case R_ARM_PLT32:
5b5bb741 4580 case R_ARM_JUMP24:
252b5132 4581 /* This one is a call from arm code. We need to look up
2f0ca46a 4582 the target of the call. If it is a thumb target, we
252b5132 4583 insert glue. */
906e58ca 4584 if (ELF_ST_TYPE (h->type) == STT_ARM_TFUNC
39b41c9c 4585 && !(r_type == R_ARM_CALL && globals->use_blx))
252b5132
RH
4586 record_arm_to_thumb_glue (link_info, h);
4587 break;
4588
bd97cb95 4589 case R_ARM_THM_JUMP24:
f21f3fe0 4590 /* This one is a call from thumb code. We look
2f0ca46a 4591 up the target of the call. If it is not a thumb
bcbdc74c 4592 target, we insert glue. */
bd97cb95
DJ
4593 if (ELF_ST_TYPE (h->type) != STT_ARM_TFUNC
4594 && !(globals->use_blx && r_type == R_ARM_THM_CALL)
5ab79981 4595 && h->root.type != bfd_link_hash_undefweak)
252b5132
RH
4596 record_thumb_to_arm_glue (link_info, h);
4597 break;
4598
4599 default:
c6596c5e 4600 abort ();
252b5132
RH
4601 }
4602 }
6cdc0ccc
AM
4603
4604 if (contents != NULL
4605 && elf_section_data (sec)->this_hdr.contents != contents)
4606 free (contents);
4607 contents = NULL;
4608
4609 if (internal_relocs != NULL
4610 && elf_section_data (sec)->relocs != internal_relocs)
4611 free (internal_relocs);
4612 internal_relocs = NULL;
252b5132
RH
4613 }
4614
b34976b6 4615 return TRUE;
9a5aca8c 4616
252b5132 4617error_return:
6cdc0ccc
AM
4618 if (contents != NULL
4619 && elf_section_data (sec)->this_hdr.contents != contents)
4620 free (contents);
4621 if (internal_relocs != NULL
4622 && elf_section_data (sec)->relocs != internal_relocs)
4623 free (internal_relocs);
9a5aca8c 4624
b34976b6 4625 return FALSE;
252b5132 4626}
7e392df6 4627#endif
252b5132 4628
eb043451 4629
c7b8f16e
JB
4630/* Initialise maps of ARM/Thumb/data for input BFDs. */
4631
4632void
4633bfd_elf32_arm_init_maps (bfd *abfd)
4634{
4635 Elf_Internal_Sym *isymbuf;
4636 Elf_Internal_Shdr *hdr;
4637 unsigned int i, localsyms;
4638
4639 if ((abfd->flags & DYNAMIC) != 0)
4640 return;
4641
0ffa91dd 4642 hdr = & elf_symtab_hdr (abfd);
c7b8f16e
JB
4643 localsyms = hdr->sh_info;
4644
4645 /* Obtain a buffer full of symbols for this BFD. The hdr->sh_info field
4646 should contain the number of local symbols, which should come before any
4647 global symbols. Mapping symbols are always local. */
4648 isymbuf = bfd_elf_get_elf_syms (abfd, hdr, localsyms, 0, NULL, NULL,
4649 NULL);
4650
4651 /* No internal symbols read? Skip this BFD. */
4652 if (isymbuf == NULL)
4653 return;
4654
4655 for (i = 0; i < localsyms; i++)
4656 {
4657 Elf_Internal_Sym *isym = &isymbuf[i];
4658 asection *sec = bfd_section_from_elf_index (abfd, isym->st_shndx);
4659 const char *name;
906e58ca 4660
c7b8f16e
JB
4661 if (sec != NULL
4662 && ELF_ST_BIND (isym->st_info) == STB_LOCAL)
4663 {
4664 name = bfd_elf_string_from_elf_section (abfd,
4665 hdr->sh_link, isym->st_name);
906e58ca 4666
c7b8f16e
JB
4667 if (bfd_is_arm_special_symbol_name (name,
4668 BFD_ARM_SPECIAL_SYM_TYPE_MAP))
4669 elf32_arm_section_map_add (sec, name[1], isym->st_value);
4670 }
4671 }
4672}
4673
4674
4675void
4676bfd_elf32_arm_set_vfp11_fix (bfd *obfd, struct bfd_link_info *link_info)
4677{
4678 struct elf32_arm_link_hash_table *globals = elf32_arm_hash_table (link_info);
104d59d1 4679 obj_attribute *out_attr = elf_known_obj_attributes_proc (obfd);
906e58ca 4680
c7b8f16e
JB
4681 /* We assume that ARMv7+ does not need the VFP11 denorm erratum fix. */
4682 if (out_attr[Tag_CPU_arch].i >= TAG_CPU_ARCH_V7)
4683 {
4684 switch (globals->vfp11_fix)
4685 {
4686 case BFD_ARM_VFP11_FIX_DEFAULT:
4687 case BFD_ARM_VFP11_FIX_NONE:
4688 globals->vfp11_fix = BFD_ARM_VFP11_FIX_NONE;
4689 break;
906e58ca 4690
c7b8f16e
JB
4691 default:
4692 /* Give a warning, but do as the user requests anyway. */
4693 (*_bfd_error_handler) (_("%B: warning: selected VFP11 erratum "
4694 "workaround is not necessary for target architecture"), obfd);
4695 }
4696 }
4697 else if (globals->vfp11_fix == BFD_ARM_VFP11_FIX_DEFAULT)
4698 /* For earlier architectures, we might need the workaround, but do not
4699 enable it by default. If users is running with broken hardware, they
4700 must enable the erratum fix explicitly. */
4701 globals->vfp11_fix = BFD_ARM_VFP11_FIX_NONE;
4702}
4703
4704
906e58ca
NC
4705enum bfd_arm_vfp11_pipe
4706{
c7b8f16e
JB
4707 VFP11_FMAC,
4708 VFP11_LS,
4709 VFP11_DS,
4710 VFP11_BAD
4711};
4712
4713/* Return a VFP register number. This is encoded as RX:X for single-precision
4714 registers, or X:RX for double-precision registers, where RX is the group of
4715 four bits in the instruction encoding and X is the single extension bit.
4716 RX and X fields are specified using their lowest (starting) bit. The return
4717 value is:
4718
4719 0...31: single-precision registers s0...s31
4720 32...63: double-precision registers d0...d31.
906e58ca 4721
c7b8f16e
JB
4722 Although X should be zero for VFP11 (encoding d0...d15 only), we might
4723 encounter VFP3 instructions, so we allow the full range for DP registers. */
906e58ca 4724
c7b8f16e
JB
4725static unsigned int
4726bfd_arm_vfp11_regno (unsigned int insn, bfd_boolean is_double, unsigned int rx,
4727 unsigned int x)
4728{
4729 if (is_double)
4730 return (((insn >> rx) & 0xf) | (((insn >> x) & 1) << 4)) + 32;
4731 else
4732 return (((insn >> rx) & 0xf) << 1) | ((insn >> x) & 1);
4733}
4734
4735/* Set bits in *WMASK according to a register number REG as encoded by
4736 bfd_arm_vfp11_regno(). Ignore d16-d31. */
4737
4738static void
4739bfd_arm_vfp11_write_mask (unsigned int *wmask, unsigned int reg)
4740{
4741 if (reg < 32)
4742 *wmask |= 1 << reg;
4743 else if (reg < 48)
4744 *wmask |= 3 << ((reg - 32) * 2);
4745}
4746
4747/* Return TRUE if WMASK overwrites anything in REGS. */
4748
4749static bfd_boolean
4750bfd_arm_vfp11_antidependency (unsigned int wmask, int *regs, int numregs)
4751{
4752 int i;
906e58ca 4753
c7b8f16e
JB
4754 for (i = 0; i < numregs; i++)
4755 {
4756 unsigned int reg = regs[i];
4757
4758 if (reg < 32 && (wmask & (1 << reg)) != 0)
4759 return TRUE;
906e58ca 4760
c7b8f16e
JB
4761 reg -= 32;
4762
4763 if (reg >= 16)
4764 continue;
906e58ca 4765
c7b8f16e
JB
4766 if ((wmask & (3 << (reg * 2))) != 0)
4767 return TRUE;
4768 }
906e58ca 4769
c7b8f16e
JB
4770 return FALSE;
4771}
4772
4773/* In this function, we're interested in two things: finding input registers
4774 for VFP data-processing instructions, and finding the set of registers which
4775 arbitrary VFP instructions may write to. We use a 32-bit unsigned int to
4776 hold the written set, so FLDM etc. are easy to deal with (we're only
4777 interested in 32 SP registers or 16 dp registers, due to the VFP version
4778 implemented by the chip in question). DP registers are marked by setting
4779 both SP registers in the write mask). */
4780
4781static enum bfd_arm_vfp11_pipe
4782bfd_arm_vfp11_insn_decode (unsigned int insn, unsigned int *destmask, int *regs,
4783 int *numregs)
4784{
4785 enum bfd_arm_vfp11_pipe pipe = VFP11_BAD;
4786 bfd_boolean is_double = ((insn & 0xf00) == 0xb00) ? 1 : 0;
4787
4788 if ((insn & 0x0f000e10) == 0x0e000a00) /* A data-processing insn. */
4789 {
4790 unsigned int pqrs;
4791 unsigned int fd = bfd_arm_vfp11_regno (insn, is_double, 12, 22);
4792 unsigned int fm = bfd_arm_vfp11_regno (insn, is_double, 0, 5);
4793
4794 pqrs = ((insn & 0x00800000) >> 20)
4795 | ((insn & 0x00300000) >> 19)
4796 | ((insn & 0x00000040) >> 6);
4797
4798 switch (pqrs)
4799 {
4800 case 0: /* fmac[sd]. */
4801 case 1: /* fnmac[sd]. */
4802 case 2: /* fmsc[sd]. */
4803 case 3: /* fnmsc[sd]. */
4804 pipe = VFP11_FMAC;
4805 bfd_arm_vfp11_write_mask (destmask, fd);
4806 regs[0] = fd;
4807 regs[1] = bfd_arm_vfp11_regno (insn, is_double, 16, 7); /* Fn. */
4808 regs[2] = fm;
4809 *numregs = 3;
4810 break;
4811
4812 case 4: /* fmul[sd]. */
4813 case 5: /* fnmul[sd]. */
4814 case 6: /* fadd[sd]. */
4815 case 7: /* fsub[sd]. */
4816 pipe = VFP11_FMAC;
4817 goto vfp_binop;
4818
4819 case 8: /* fdiv[sd]. */
4820 pipe = VFP11_DS;
4821 vfp_binop:
4822 bfd_arm_vfp11_write_mask (destmask, fd);
4823 regs[0] = bfd_arm_vfp11_regno (insn, is_double, 16, 7); /* Fn. */
4824 regs[1] = fm;
4825 *numregs = 2;
4826 break;
4827
4828 case 15: /* extended opcode. */
4829 {
4830 unsigned int extn = ((insn >> 15) & 0x1e)
4831 | ((insn >> 7) & 1);
4832
4833 switch (extn)
4834 {
4835 case 0: /* fcpy[sd]. */
4836 case 1: /* fabs[sd]. */
4837 case 2: /* fneg[sd]. */
4838 case 8: /* fcmp[sd]. */
4839 case 9: /* fcmpe[sd]. */
4840 case 10: /* fcmpz[sd]. */
4841 case 11: /* fcmpez[sd]. */
4842 case 16: /* fuito[sd]. */
4843 case 17: /* fsito[sd]. */
4844 case 24: /* ftoui[sd]. */
4845 case 25: /* ftouiz[sd]. */
4846 case 26: /* ftosi[sd]. */
4847 case 27: /* ftosiz[sd]. */
4848 /* These instructions will not bounce due to underflow. */
4849 *numregs = 0;
4850 pipe = VFP11_FMAC;
4851 break;
4852
4853 case 3: /* fsqrt[sd]. */
4854 /* fsqrt cannot underflow, but it can (perhaps) overwrite
4855 registers to cause the erratum in previous instructions. */
4856 bfd_arm_vfp11_write_mask (destmask, fd);
4857 pipe = VFP11_DS;
4858 break;
4859
4860 case 15: /* fcvt{ds,sd}. */
4861 {
4862 int rnum = 0;
4863
4864 bfd_arm_vfp11_write_mask (destmask, fd);
4865
4866 /* Only FCVTSD can underflow. */
4867 if ((insn & 0x100) != 0)
4868 regs[rnum++] = fm;
4869
4870 *numregs = rnum;
4871
4872 pipe = VFP11_FMAC;
4873 }
4874 break;
4875
4876 default:
4877 return VFP11_BAD;
4878 }
4879 }
4880 break;
4881
4882 default:
4883 return VFP11_BAD;
4884 }
4885 }
4886 /* Two-register transfer. */
4887 else if ((insn & 0x0fe00ed0) == 0x0c400a10)
4888 {
4889 unsigned int fm = bfd_arm_vfp11_regno (insn, is_double, 0, 5);
906e58ca 4890
c7b8f16e
JB
4891 if ((insn & 0x100000) == 0)
4892 {
4893 if (is_double)
4894 bfd_arm_vfp11_write_mask (destmask, fm);
4895 else
4896 {
4897 bfd_arm_vfp11_write_mask (destmask, fm);
4898 bfd_arm_vfp11_write_mask (destmask, fm + 1);
4899 }
4900 }
4901
4902 pipe = VFP11_LS;
4903 }
4904 else if ((insn & 0x0e100e00) == 0x0c100a00) /* A load insn. */
4905 {
4906 int fd = bfd_arm_vfp11_regno (insn, is_double, 12, 22);
4907 unsigned int puw = ((insn >> 21) & 0x1) | (((insn >> 23) & 3) << 1);
906e58ca 4908
c7b8f16e
JB
4909 switch (puw)
4910 {
4911 case 0: /* Two-reg transfer. We should catch these above. */
4912 abort ();
906e58ca 4913
c7b8f16e
JB
4914 case 2: /* fldm[sdx]. */
4915 case 3:
4916 case 5:
4917 {
4918 unsigned int i, offset = insn & 0xff;
4919
4920 if (is_double)
4921 offset >>= 1;
4922
4923 for (i = fd; i < fd + offset; i++)
4924 bfd_arm_vfp11_write_mask (destmask, i);
4925 }
4926 break;
906e58ca 4927
c7b8f16e
JB
4928 case 4: /* fld[sd]. */
4929 case 6:
4930 bfd_arm_vfp11_write_mask (destmask, fd);
4931 break;
906e58ca 4932
c7b8f16e
JB
4933 default:
4934 return VFP11_BAD;
4935 }
4936
4937 pipe = VFP11_LS;
4938 }
4939 /* Single-register transfer. Note L==0. */
4940 else if ((insn & 0x0f100e10) == 0x0e000a10)
4941 {
4942 unsigned int opcode = (insn >> 21) & 7;
4943 unsigned int fn = bfd_arm_vfp11_regno (insn, is_double, 16, 7);
4944
4945 switch (opcode)
4946 {
4947 case 0: /* fmsr/fmdlr. */
4948 case 1: /* fmdhr. */
4949 /* Mark fmdhr and fmdlr as writing to the whole of the DP
4950 destination register. I don't know if this is exactly right,
4951 but it is the conservative choice. */
4952 bfd_arm_vfp11_write_mask (destmask, fn);
4953 break;
4954
4955 case 7: /* fmxr. */
4956 break;
4957 }
4958
4959 pipe = VFP11_LS;
4960 }
4961
4962 return pipe;
4963}
4964
4965
4966static int elf32_arm_compare_mapping (const void * a, const void * b);
4967
4968
4969/* Look for potentially-troublesome code sequences which might trigger the
4970 VFP11 denormal/antidependency erratum. See, e.g., the ARM1136 errata sheet
4971 (available from ARM) for details of the erratum. A short version is
4972 described in ld.texinfo. */
4973
4974bfd_boolean
4975bfd_elf32_arm_vfp11_erratum_scan (bfd *abfd, struct bfd_link_info *link_info)
4976{
4977 asection *sec;
4978 bfd_byte *contents = NULL;
4979 int state = 0;
4980 int regs[3], numregs = 0;
4981 struct elf32_arm_link_hash_table *globals = elf32_arm_hash_table (link_info);
4982 int use_vector = (globals->vfp11_fix == BFD_ARM_VFP11_FIX_VECTOR);
906e58ca 4983
c7b8f16e
JB
4984 /* We use a simple FSM to match troublesome VFP11 instruction sequences.
4985 The states transition as follows:
906e58ca 4986
c7b8f16e
JB
4987 0 -> 1 (vector) or 0 -> 2 (scalar)
4988 A VFP FMAC-pipeline instruction has been seen. Fill
4989 regs[0]..regs[numregs-1] with its input operands. Remember this
4990 instruction in 'first_fmac'.
4991
4992 1 -> 2
4993 Any instruction, except for a VFP instruction which overwrites
4994 regs[*].
906e58ca 4995
c7b8f16e
JB
4996 1 -> 3 [ -> 0 ] or
4997 2 -> 3 [ -> 0 ]
4998 A VFP instruction has been seen which overwrites any of regs[*].
4999 We must make a veneer! Reset state to 0 before examining next
5000 instruction.
906e58ca 5001
c7b8f16e
JB
5002 2 -> 0
5003 If we fail to match anything in state 2, reset to state 0 and reset
5004 the instruction pointer to the instruction after 'first_fmac'.
5005
5006 If the VFP11 vector mode is in use, there must be at least two unrelated
5007 instructions between anti-dependent VFP11 instructions to properly avoid
906e58ca 5008 triggering the erratum, hence the use of the extra state 1. */
c7b8f16e
JB
5009
5010 /* If we are only performing a partial link do not bother
5011 to construct any glue. */
5012 if (link_info->relocatable)
5013 return TRUE;
5014
0ffa91dd
NC
5015 /* Skip if this bfd does not correspond to an ELF image. */
5016 if (! is_arm_elf (abfd))
5017 return TRUE;
906e58ca 5018
c7b8f16e
JB
5019 /* We should have chosen a fix type by the time we get here. */
5020 BFD_ASSERT (globals->vfp11_fix != BFD_ARM_VFP11_FIX_DEFAULT);
5021
5022 if (globals->vfp11_fix == BFD_ARM_VFP11_FIX_NONE)
5023 return TRUE;
2e6030b9 5024
c7b8f16e
JB
5025 for (sec = abfd->sections; sec != NULL; sec = sec->next)
5026 {
5027 unsigned int i, span, first_fmac = 0, veneer_of_insn = 0;
5028 struct _arm_elf_section_data *sec_data;
5029
5030 /* If we don't have executable progbits, we're not interested in this
5031 section. Also skip if section is to be excluded. */
5032 if (elf_section_type (sec) != SHT_PROGBITS
5033 || (elf_section_flags (sec) & SHF_EXECINSTR) == 0
5034 || (sec->flags & SEC_EXCLUDE) != 0
5035 || strcmp (sec->name, VFP11_ERRATUM_VENEER_SECTION_NAME) == 0)
5036 continue;
5037
5038 sec_data = elf32_arm_section_data (sec);
906e58ca 5039
c7b8f16e
JB
5040 if (sec_data->mapcount == 0)
5041 continue;
906e58ca 5042
c7b8f16e
JB
5043 if (elf_section_data (sec)->this_hdr.contents != NULL)
5044 contents = elf_section_data (sec)->this_hdr.contents;
5045 else if (! bfd_malloc_and_get_section (abfd, sec, &contents))
5046 goto error_return;
5047
5048 qsort (sec_data->map, sec_data->mapcount, sizeof (elf32_arm_section_map),
5049 elf32_arm_compare_mapping);
5050
5051 for (span = 0; span < sec_data->mapcount; span++)
5052 {
5053 unsigned int span_start = sec_data->map[span].vma;
5054 unsigned int span_end = (span == sec_data->mapcount - 1)
5055 ? sec->size : sec_data->map[span + 1].vma;
5056 char span_type = sec_data->map[span].type;
906e58ca 5057
c7b8f16e
JB
5058 /* FIXME: Only ARM mode is supported at present. We may need to
5059 support Thumb-2 mode also at some point. */
5060 if (span_type != 'a')
5061 continue;
5062
5063 for (i = span_start; i < span_end;)
5064 {
5065 unsigned int next_i = i + 4;
5066 unsigned int insn = bfd_big_endian (abfd)
5067 ? (contents[i] << 24)
5068 | (contents[i + 1] << 16)
5069 | (contents[i + 2] << 8)
5070 | contents[i + 3]
5071 : (contents[i + 3] << 24)
5072 | (contents[i + 2] << 16)
5073 | (contents[i + 1] << 8)
5074 | contents[i];
5075 unsigned int writemask = 0;
5076 enum bfd_arm_vfp11_pipe pipe;
5077
5078 switch (state)
5079 {
5080 case 0:
5081 pipe = bfd_arm_vfp11_insn_decode (insn, &writemask, regs,
5082 &numregs);
5083 /* I'm assuming the VFP11 erratum can trigger with denorm
5084 operands on either the FMAC or the DS pipeline. This might
5085 lead to slightly overenthusiastic veneer insertion. */
5086 if (pipe == VFP11_FMAC || pipe == VFP11_DS)
5087 {
5088 state = use_vector ? 1 : 2;
5089 first_fmac = i;
5090 veneer_of_insn = insn;
5091 }
5092 break;
5093
5094 case 1:
5095 {
5096 int other_regs[3], other_numregs;
5097 pipe = bfd_arm_vfp11_insn_decode (insn, &writemask,
5098 other_regs,
5099 &other_numregs);
5100 if (pipe != VFP11_BAD
5101 && bfd_arm_vfp11_antidependency (writemask, regs,
5102 numregs))
5103 state = 3;
5104 else
5105 state = 2;
5106 }
5107 break;
5108
5109 case 2:
5110 {
5111 int other_regs[3], other_numregs;
5112 pipe = bfd_arm_vfp11_insn_decode (insn, &writemask,
5113 other_regs,
5114 &other_numregs);
5115 if (pipe != VFP11_BAD
5116 && bfd_arm_vfp11_antidependency (writemask, regs,
5117 numregs))
5118 state = 3;
5119 else
5120 {
5121 state = 0;
5122 next_i = first_fmac + 4;
5123 }
5124 }
5125 break;
5126
5127 case 3:
5128 abort (); /* Should be unreachable. */
5129 }
5130
5131 if (state == 3)
5132 {
5133 elf32_vfp11_erratum_list *newerr
5134 = bfd_zmalloc (sizeof (elf32_vfp11_erratum_list));
5135 int errcount;
5136
5137 errcount = ++(elf32_arm_section_data (sec)->erratumcount);
5138
5139 newerr->u.b.vfp_insn = veneer_of_insn;
5140
5141 switch (span_type)
5142 {
5143 case 'a':
5144 newerr->type = VFP11_ERRATUM_BRANCH_TO_ARM_VENEER;
5145 break;
906e58ca 5146
c7b8f16e
JB
5147 default:
5148 abort ();
5149 }
5150
5151 record_vfp11_erratum_veneer (link_info, newerr, abfd, sec,
5152 first_fmac);
5153
5154 newerr->vma = -1;
5155
5156 newerr->next = sec_data->erratumlist;
5157 sec_data->erratumlist = newerr;
5158
5159 state = 0;
5160 }
5161
5162 i = next_i;
5163 }
5164 }
906e58ca 5165
c7b8f16e
JB
5166 if (contents != NULL
5167 && elf_section_data (sec)->this_hdr.contents != contents)
5168 free (contents);
5169 contents = NULL;
5170 }
5171
5172 return TRUE;
5173
5174error_return:
5175 if (contents != NULL
5176 && elf_section_data (sec)->this_hdr.contents != contents)
5177 free (contents);
906e58ca 5178
c7b8f16e
JB
5179 return FALSE;
5180}
5181
5182/* Find virtual-memory addresses for VFP11 erratum veneers and return locations
5183 after sections have been laid out, using specially-named symbols. */
5184
5185void
5186bfd_elf32_arm_vfp11_fix_veneer_locations (bfd *abfd,
5187 struct bfd_link_info *link_info)
5188{
5189 asection *sec;
5190 struct elf32_arm_link_hash_table *globals;
5191 char *tmp_name;
906e58ca 5192
c7b8f16e
JB
5193 if (link_info->relocatable)
5194 return;
2e6030b9
MS
5195
5196 /* Skip if this bfd does not correspond to an ELF image. */
0ffa91dd 5197 if (! is_arm_elf (abfd))
2e6030b9
MS
5198 return;
5199
c7b8f16e 5200 globals = elf32_arm_hash_table (link_info);
906e58ca 5201
c7b8f16e
JB
5202 tmp_name = bfd_malloc ((bfd_size_type) strlen
5203 (VFP11_ERRATUM_VENEER_ENTRY_NAME) + 10);
5204
5205 for (sec = abfd->sections; sec != NULL; sec = sec->next)
5206 {
5207 struct _arm_elf_section_data *sec_data = elf32_arm_section_data (sec);
5208 elf32_vfp11_erratum_list *errnode = sec_data->erratumlist;
906e58ca 5209
c7b8f16e
JB
5210 for (; errnode != NULL; errnode = errnode->next)
5211 {
5212 struct elf_link_hash_entry *myh;
5213 bfd_vma vma;
5214
5215 switch (errnode->type)
5216 {
5217 case VFP11_ERRATUM_BRANCH_TO_ARM_VENEER:
5218 case VFP11_ERRATUM_BRANCH_TO_THUMB_VENEER:
5219 /* Find veneer symbol. */
5220 sprintf (tmp_name, VFP11_ERRATUM_VENEER_ENTRY_NAME,
5221 errnode->u.b.veneer->u.v.id);
5222
5223 myh = elf_link_hash_lookup
5224 (&(globals)->root, tmp_name, FALSE, FALSE, TRUE);
5225
5226 if (myh == NULL)
5227 (*_bfd_error_handler) (_("%B: unable to find VFP11 veneer "
5228 "`%s'"), abfd, tmp_name);
5229
5230 vma = myh->root.u.def.section->output_section->vma
5231 + myh->root.u.def.section->output_offset
5232 + myh->root.u.def.value;
5233
5234 errnode->u.b.veneer->vma = vma;
5235 break;
5236
5237 case VFP11_ERRATUM_ARM_VENEER:
5238 case VFP11_ERRATUM_THUMB_VENEER:
5239 /* Find return location. */
5240 sprintf (tmp_name, VFP11_ERRATUM_VENEER_ENTRY_NAME "_r",
5241 errnode->u.v.id);
5242
5243 myh = elf_link_hash_lookup
5244 (&(globals)->root, tmp_name, FALSE, FALSE, TRUE);
5245
5246 if (myh == NULL)
5247 (*_bfd_error_handler) (_("%B: unable to find VFP11 veneer "
5248 "`%s'"), abfd, tmp_name);
5249
5250 vma = myh->root.u.def.section->output_section->vma
5251 + myh->root.u.def.section->output_offset
5252 + myh->root.u.def.value;
5253
5254 errnode->u.v.branch->vma = vma;
5255 break;
906e58ca 5256
c7b8f16e
JB
5257 default:
5258 abort ();
5259 }
5260 }
5261 }
906e58ca 5262
c7b8f16e
JB
5263 free (tmp_name);
5264}
5265
5266
eb043451
PB
5267/* Set target relocation values needed during linking. */
5268
5269void
bf21ed78
MS
5270bfd_elf32_arm_set_target_relocs (struct bfd *output_bfd,
5271 struct bfd_link_info *link_info,
eb043451 5272 int target1_is_rel,
319850b4 5273 char * target2_type,
33bfe774 5274 int fix_v4bx,
c7b8f16e 5275 int use_blx,
bf21ed78 5276 bfd_arm_vfp11_fix vfp11_fix,
a9dc9481
JM
5277 int no_enum_warn, int no_wchar_warn,
5278 int pic_veneer)
eb043451
PB
5279{
5280 struct elf32_arm_link_hash_table *globals;
5281
5282 globals = elf32_arm_hash_table (link_info);
5283
5284 globals->target1_is_rel = target1_is_rel;
5285 if (strcmp (target2_type, "rel") == 0)
5286 globals->target2_reloc = R_ARM_REL32;
eeac373a
PB
5287 else if (strcmp (target2_type, "abs") == 0)
5288 globals->target2_reloc = R_ARM_ABS32;
eb043451
PB
5289 else if (strcmp (target2_type, "got-rel") == 0)
5290 globals->target2_reloc = R_ARM_GOT_PREL;
5291 else
5292 {
5293 _bfd_error_handler (_("Invalid TARGET2 relocation type '%s'."),
5294 target2_type);
5295 }
319850b4 5296 globals->fix_v4bx = fix_v4bx;
33bfe774 5297 globals->use_blx |= use_blx;
c7b8f16e 5298 globals->vfp11_fix = vfp11_fix;
27e55c4d 5299 globals->pic_veneer = pic_veneer;
bf21ed78 5300
0ffa91dd
NC
5301 BFD_ASSERT (is_arm_elf (output_bfd));
5302 elf_arm_tdata (output_bfd)->no_enum_size_warning = no_enum_warn;
a9dc9481 5303 elf_arm_tdata (output_bfd)->no_wchar_size_warning = no_wchar_warn;
eb043451 5304}
eb043451 5305
12a0a0fd 5306/* Replace the target offset of a Thumb bl or b.w instruction. */
252b5132 5307
12a0a0fd
PB
5308static void
5309insert_thumb_branch (bfd *abfd, long int offset, bfd_byte *insn)
5310{
5311 bfd_vma upper;
5312 bfd_vma lower;
5313 int reloc_sign;
5314
5315 BFD_ASSERT ((offset & 1) == 0);
5316
5317 upper = bfd_get_16 (abfd, insn);
5318 lower = bfd_get_16 (abfd, insn + 2);
5319 reloc_sign = (offset < 0) ? 1 : 0;
5320 upper = (upper & ~(bfd_vma) 0x7ff)
5321 | ((offset >> 12) & 0x3ff)
5322 | (reloc_sign << 10);
906e58ca 5323 lower = (lower & ~(bfd_vma) 0x2fff)
12a0a0fd
PB
5324 | (((!((offset >> 23) & 1)) ^ reloc_sign) << 13)
5325 | (((!((offset >> 22) & 1)) ^ reloc_sign) << 11)
5326 | ((offset >> 1) & 0x7ff);
5327 bfd_put_16 (abfd, upper, insn);
5328 bfd_put_16 (abfd, lower, insn + 2);
252b5132
RH
5329}
5330
9b485d32
NC
5331/* Thumb code calling an ARM function. */
5332
252b5132 5333static int
57e8b36a
NC
5334elf32_thumb_to_arm_stub (struct bfd_link_info * info,
5335 const char * name,
5336 bfd * input_bfd,
5337 bfd * output_bfd,
5338 asection * input_section,
5339 bfd_byte * hit_data,
5340 asection * sym_sec,
5341 bfd_vma offset,
5342 bfd_signed_vma addend,
f2a9dd69
DJ
5343 bfd_vma val,
5344 char **error_message)
252b5132 5345{
bcbdc74c 5346 asection * s = 0;
dc810e39 5347 bfd_vma my_offset;
252b5132 5348 long int ret_offset;
bcbdc74c
NC
5349 struct elf_link_hash_entry * myh;
5350 struct elf32_arm_link_hash_table * globals;
252b5132 5351
f2a9dd69 5352 myh = find_thumb_glue (info, name, error_message);
252b5132 5353 if (myh == NULL)
b34976b6 5354 return FALSE;
252b5132
RH
5355
5356 globals = elf32_arm_hash_table (info);
5357
5358 BFD_ASSERT (globals != NULL);
5359 BFD_ASSERT (globals->bfd_of_glue_owner != NULL);
5360
5361 my_offset = myh->root.u.def.value;
5362
5363 s = bfd_get_section_by_name (globals->bfd_of_glue_owner,
5364 THUMB2ARM_GLUE_SECTION_NAME);
5365
5366 BFD_ASSERT (s != NULL);
5367 BFD_ASSERT (s->contents != NULL);
5368 BFD_ASSERT (s->output_section != NULL);
5369
5370 if ((my_offset & 0x01) == 0x01)
5371 {
5372 if (sym_sec != NULL
5373 && sym_sec->owner != NULL
5374 && !INTERWORK_FLAG (sym_sec->owner))
5375 {
8f615d07 5376 (*_bfd_error_handler)
d003868e
AM
5377 (_("%B(%s): warning: interworking not enabled.\n"
5378 " first occurrence: %B: thumb call to arm"),
5379 sym_sec->owner, input_bfd, name);
252b5132 5380
b34976b6 5381 return FALSE;
252b5132
RH
5382 }
5383
5384 --my_offset;
5385 myh->root.u.def.value = my_offset;
5386
52ab56c2
PB
5387 put_thumb_insn (globals, output_bfd, (bfd_vma) t2a1_bx_pc_insn,
5388 s->contents + my_offset);
252b5132 5389
52ab56c2
PB
5390 put_thumb_insn (globals, output_bfd, (bfd_vma) t2a2_noop_insn,
5391 s->contents + my_offset + 2);
252b5132
RH
5392
5393 ret_offset =
9b485d32
NC
5394 /* Address of destination of the stub. */
5395 ((bfd_signed_vma) val)
252b5132 5396 - ((bfd_signed_vma)
57e8b36a
NC
5397 /* Offset from the start of the current section
5398 to the start of the stubs. */
9b485d32
NC
5399 (s->output_offset
5400 /* Offset of the start of this stub from the start of the stubs. */
5401 + my_offset
5402 /* Address of the start of the current section. */
5403 + s->output_section->vma)
5404 /* The branch instruction is 4 bytes into the stub. */
5405 + 4
5406 /* ARM branches work from the pc of the instruction + 8. */
5407 + 8);
252b5132 5408
52ab56c2
PB
5409 put_arm_insn (globals, output_bfd,
5410 (bfd_vma) t2a3_b_insn | ((ret_offset >> 2) & 0x00FFFFFF),
5411 s->contents + my_offset + 4);
252b5132
RH
5412 }
5413
5414 BFD_ASSERT (my_offset <= globals->thumb_glue_size);
5415
427bfd90
NC
5416 /* Now go back and fix up the original BL insn to point to here. */
5417 ret_offset =
5418 /* Address of where the stub is located. */
5419 (s->output_section->vma + s->output_offset + my_offset)
5420 /* Address of where the BL is located. */
57e8b36a
NC
5421 - (input_section->output_section->vma + input_section->output_offset
5422 + offset)
427bfd90
NC
5423 /* Addend in the relocation. */
5424 - addend
5425 /* Biassing for PC-relative addressing. */
5426 - 8;
252b5132 5427
12a0a0fd 5428 insert_thumb_branch (input_bfd, ret_offset, hit_data - input_section->vma);
252b5132 5429
b34976b6 5430 return TRUE;
252b5132
RH
5431}
5432
a4fd1a8e 5433/* Populate an Arm to Thumb stub. Returns the stub symbol. */
9b485d32 5434
a4fd1a8e
PB
5435static struct elf_link_hash_entry *
5436elf32_arm_create_thumb_stub (struct bfd_link_info * info,
5437 const char * name,
5438 bfd * input_bfd,
5439 bfd * output_bfd,
5440 asection * sym_sec,
5441 bfd_vma val,
f2a9dd69
DJ
5442 asection *s,
5443 char **error_message)
252b5132 5444{
dc810e39 5445 bfd_vma my_offset;
252b5132 5446 long int ret_offset;
bcbdc74c
NC
5447 struct elf_link_hash_entry * myh;
5448 struct elf32_arm_link_hash_table * globals;
252b5132 5449
f2a9dd69 5450 myh = find_arm_glue (info, name, error_message);
252b5132 5451 if (myh == NULL)
a4fd1a8e 5452 return NULL;
252b5132
RH
5453
5454 globals = elf32_arm_hash_table (info);
5455
5456 BFD_ASSERT (globals != NULL);
5457 BFD_ASSERT (globals->bfd_of_glue_owner != NULL);
5458
5459 my_offset = myh->root.u.def.value;
252b5132
RH
5460
5461 if ((my_offset & 0x01) == 0x01)
5462 {
5463 if (sym_sec != NULL
5464 && sym_sec->owner != NULL
5465 && !INTERWORK_FLAG (sym_sec->owner))
5466 {
8f615d07 5467 (*_bfd_error_handler)
d003868e
AM
5468 (_("%B(%s): warning: interworking not enabled.\n"
5469 " first occurrence: %B: arm call to thumb"),
5470 sym_sec->owner, input_bfd, name);
252b5132 5471 }
9b485d32 5472
252b5132
RH
5473 --my_offset;
5474 myh->root.u.def.value = my_offset;
5475
27e55c4d
PB
5476 if (info->shared || globals->root.is_relocatable_executable
5477 || globals->pic_veneer)
8f6277f5
PB
5478 {
5479 /* For relocatable objects we can't use absolute addresses,
5480 so construct the address from a relative offset. */
5481 /* TODO: If the offset is small it's probably worth
5482 constructing the address with adds. */
52ab56c2
PB
5483 put_arm_insn (globals, output_bfd, (bfd_vma) a2t1p_ldr_insn,
5484 s->contents + my_offset);
5485 put_arm_insn (globals, output_bfd, (bfd_vma) a2t2p_add_pc_insn,
5486 s->contents + my_offset + 4);
5487 put_arm_insn (globals, output_bfd, (bfd_vma) a2t3p_bx_r12_insn,
5488 s->contents + my_offset + 8);
8f6277f5
PB
5489 /* Adjust the offset by 4 for the position of the add,
5490 and 8 for the pipeline offset. */
5491 ret_offset = (val - (s->output_offset
5492 + s->output_section->vma
5493 + my_offset + 12))
5494 | 1;
5495 bfd_put_32 (output_bfd, ret_offset,
5496 s->contents + my_offset + 12);
5497 }
26079076
PB
5498 else if (globals->use_blx)
5499 {
5500 put_arm_insn (globals, output_bfd, (bfd_vma) a2t1v5_ldr_insn,
5501 s->contents + my_offset);
5502
5503 /* It's a thumb address. Add the low order bit. */
5504 bfd_put_32 (output_bfd, val | a2t2v5_func_addr_insn,
5505 s->contents + my_offset + 4);
5506 }
8f6277f5
PB
5507 else
5508 {
52ab56c2
PB
5509 put_arm_insn (globals, output_bfd, (bfd_vma) a2t1_ldr_insn,
5510 s->contents + my_offset);
252b5132 5511
52ab56c2
PB
5512 put_arm_insn (globals, output_bfd, (bfd_vma) a2t2_bx_r12_insn,
5513 s->contents + my_offset + 4);
252b5132 5514
8f6277f5
PB
5515 /* It's a thumb address. Add the low order bit. */
5516 bfd_put_32 (output_bfd, val | a2t3_func_addr_insn,
5517 s->contents + my_offset + 8);
5518 }
252b5132
RH
5519 }
5520
5521 BFD_ASSERT (my_offset <= globals->arm_glue_size);
5522
a4fd1a8e
PB
5523 return myh;
5524}
5525
5526/* Arm code calling a Thumb function. */
5527
5528static int
5529elf32_arm_to_thumb_stub (struct bfd_link_info * info,
5530 const char * name,
5531 bfd * input_bfd,
5532 bfd * output_bfd,
5533 asection * input_section,
5534 bfd_byte * hit_data,
5535 asection * sym_sec,
5536 bfd_vma offset,
5537 bfd_signed_vma addend,
f2a9dd69
DJ
5538 bfd_vma val,
5539 char **error_message)
a4fd1a8e
PB
5540{
5541 unsigned long int tmp;
5542 bfd_vma my_offset;
5543 asection * s;
5544 long int ret_offset;
5545 struct elf_link_hash_entry * myh;
5546 struct elf32_arm_link_hash_table * globals;
5547
5548 globals = elf32_arm_hash_table (info);
5549
5550 BFD_ASSERT (globals != NULL);
5551 BFD_ASSERT (globals->bfd_of_glue_owner != NULL);
5552
5553 s = bfd_get_section_by_name (globals->bfd_of_glue_owner,
5554 ARM2THUMB_GLUE_SECTION_NAME);
5555 BFD_ASSERT (s != NULL);
5556 BFD_ASSERT (s->contents != NULL);
5557 BFD_ASSERT (s->output_section != NULL);
5558
5559 myh = elf32_arm_create_thumb_stub (info, name, input_bfd, output_bfd,
f2a9dd69 5560 sym_sec, val, s, error_message);
a4fd1a8e
PB
5561 if (!myh)
5562 return FALSE;
5563
5564 my_offset = myh->root.u.def.value;
252b5132
RH
5565 tmp = bfd_get_32 (input_bfd, hit_data);
5566 tmp = tmp & 0xFF000000;
5567
9b485d32 5568 /* Somehow these are both 4 too far, so subtract 8. */
dc810e39
AM
5569 ret_offset = (s->output_offset
5570 + my_offset
5571 + s->output_section->vma
5572 - (input_section->output_offset
5573 + input_section->output_section->vma
5574 + offset + addend)
5575 - 8);
9a5aca8c 5576
252b5132
RH
5577 tmp = tmp | ((ret_offset >> 2) & 0x00FFFFFF);
5578
dc810e39 5579 bfd_put_32 (output_bfd, (bfd_vma) tmp, hit_data - input_section->vma);
252b5132 5580
b34976b6 5581 return TRUE;
252b5132
RH
5582}
5583
a4fd1a8e
PB
5584/* Populate Arm stub for an exported Thumb function. */
5585
5586static bfd_boolean
5587elf32_arm_to_thumb_export_stub (struct elf_link_hash_entry *h, void * inf)
5588{
5589 struct bfd_link_info * info = (struct bfd_link_info *) inf;
5590 asection * s;
5591 struct elf_link_hash_entry * myh;
5592 struct elf32_arm_link_hash_entry *eh;
5593 struct elf32_arm_link_hash_table * globals;
5594 asection *sec;
5595 bfd_vma val;
f2a9dd69 5596 char *error_message;
a4fd1a8e 5597
906e58ca 5598 eh = elf32_arm_hash_entry (h);
a4fd1a8e
PB
5599 /* Allocate stubs for exported Thumb functions on v4t. */
5600 if (eh->export_glue == NULL)
5601 return TRUE;
5602
5603 globals = elf32_arm_hash_table (info);
5604
5605 BFD_ASSERT (globals != NULL);
5606 BFD_ASSERT (globals->bfd_of_glue_owner != NULL);
5607
5608 s = bfd_get_section_by_name (globals->bfd_of_glue_owner,
5609 ARM2THUMB_GLUE_SECTION_NAME);
5610 BFD_ASSERT (s != NULL);
5611 BFD_ASSERT (s->contents != NULL);
5612 BFD_ASSERT (s->output_section != NULL);
5613
5614 sec = eh->export_glue->root.u.def.section;
0eaedd0e
PB
5615
5616 BFD_ASSERT (sec->output_section != NULL);
5617
a4fd1a8e
PB
5618 val = eh->export_glue->root.u.def.value + sec->output_offset
5619 + sec->output_section->vma;
5620 myh = elf32_arm_create_thumb_stub (info, h->root.root.string,
5621 h->root.u.def.section->owner,
f2a9dd69
DJ
5622 globals->obfd, sec, val, s,
5623 &error_message);
a4fd1a8e
PB
5624 BFD_ASSERT (myh);
5625 return TRUE;
5626}
5627
845b51d6
PB
5628/* Populate ARMv4 BX veneers. Returns the absolute adress of the veneer. */
5629
5630static bfd_vma
5631elf32_arm_bx_glue (struct bfd_link_info * info, int reg)
5632{
5633 bfd_byte *p;
5634 bfd_vma glue_addr;
5635 asection *s;
5636 struct elf32_arm_link_hash_table *globals;
5637
5638 globals = elf32_arm_hash_table (info);
5639
5640 BFD_ASSERT (globals != NULL);
5641 BFD_ASSERT (globals->bfd_of_glue_owner != NULL);
5642
5643 s = bfd_get_section_by_name (globals->bfd_of_glue_owner,
5644 ARM_BX_GLUE_SECTION_NAME);
5645 BFD_ASSERT (s != NULL);
5646 BFD_ASSERT (s->contents != NULL);
5647 BFD_ASSERT (s->output_section != NULL);
5648
5649 BFD_ASSERT (globals->bx_glue_offset[reg] & 2);
5650
5651 glue_addr = globals->bx_glue_offset[reg] & ~(bfd_vma)3;
5652
5653 if ((globals->bx_glue_offset[reg] & 1) == 0)
5654 {
5655 p = s->contents + glue_addr;
5656 bfd_put_32 (globals->obfd, armbx1_tst_insn + (reg << 16), p);
5657 bfd_put_32 (globals->obfd, armbx2_moveq_insn + reg, p + 4);
5658 bfd_put_32 (globals->obfd, armbx3_bx_insn + reg, p + 8);
5659 globals->bx_glue_offset[reg] |= 1;
5660 }
5661
5662 return glue_addr + s->output_section->vma + s->output_offset;
5663}
5664
a4fd1a8e
PB
5665/* Generate Arm stubs for exported Thumb symbols. */
5666static void
906e58ca 5667elf32_arm_begin_write_processing (bfd *abfd ATTRIBUTE_UNUSED,
a4fd1a8e
PB
5668 struct bfd_link_info *link_info)
5669{
5670 struct elf32_arm_link_hash_table * globals;
5671
5672 if (!link_info)
5673 return;
5674
5675 globals = elf32_arm_hash_table (link_info);
84c08195
PB
5676 /* If blx is available then exported Thumb symbols are OK and there is
5677 nothing to do. */
a4fd1a8e
PB
5678 if (globals->use_blx)
5679 return;
5680
5681 elf_link_hash_traverse (&globals->root, elf32_arm_to_thumb_export_stub,
5682 link_info);
5683}
5684
eb043451
PB
5685/* Some relocations map to different relocations depending on the
5686 target. Return the real relocation. */
5687static int
5688arm_real_reloc_type (struct elf32_arm_link_hash_table * globals,
5689 int r_type)
5690{
5691 switch (r_type)
5692 {
5693 case R_ARM_TARGET1:
5694 if (globals->target1_is_rel)
5695 return R_ARM_REL32;
5696 else
5697 return R_ARM_ABS32;
5698
5699 case R_ARM_TARGET2:
5700 return globals->target2_reloc;
5701
5702 default:
5703 return r_type;
5704 }
5705}
eb043451 5706
ba93b8ac
DJ
5707/* Return the base VMA address which should be subtracted from real addresses
5708 when resolving @dtpoff relocation.
5709 This is PT_TLS segment p_vaddr. */
5710
5711static bfd_vma
5712dtpoff_base (struct bfd_link_info *info)
5713{
5714 /* If tls_sec is NULL, we should have signalled an error already. */
5715 if (elf_hash_table (info)->tls_sec == NULL)
5716 return 0;
5717 return elf_hash_table (info)->tls_sec->vma;
5718}
5719
5720/* Return the relocation value for @tpoff relocation
5721 if STT_TLS virtual address is ADDRESS. */
5722
5723static bfd_vma
5724tpoff (struct bfd_link_info *info, bfd_vma address)
5725{
5726 struct elf_link_hash_table *htab = elf_hash_table (info);
5727 bfd_vma base;
5728
5729 /* If tls_sec is NULL, we should have signalled an error already. */
5730 if (htab->tls_sec == NULL)
5731 return 0;
5732 base = align_power ((bfd_vma) TCB_SIZE, htab->tls_sec->alignment_power);
5733 return address - htab->tls_sec->vma + base;
5734}
5735
00a97672
RS
5736/* Perform an R_ARM_ABS12 relocation on the field pointed to by DATA.
5737 VALUE is the relocation value. */
5738
5739static bfd_reloc_status_type
5740elf32_arm_abs12_reloc (bfd *abfd, void *data, bfd_vma value)
5741{
5742 if (value > 0xfff)
5743 return bfd_reloc_overflow;
5744
5745 value |= bfd_get_32 (abfd, data) & 0xfffff000;
5746 bfd_put_32 (abfd, value, data);
5747 return bfd_reloc_ok;
5748}
5749
4962c51a
MS
5750/* For a given value of n, calculate the value of G_n as required to
5751 deal with group relocations. We return it in the form of an
5752 encoded constant-and-rotation, together with the final residual. If n is
5753 specified as less than zero, then final_residual is filled with the
5754 input value and no further action is performed. */
5755
5756static bfd_vma
5757calculate_group_reloc_mask (bfd_vma value, int n, bfd_vma *final_residual)
5758{
5759 int current_n;
5760 bfd_vma g_n;
5761 bfd_vma encoded_g_n = 0;
5762 bfd_vma residual = value; /* Also known as Y_n. */
5763
5764 for (current_n = 0; current_n <= n; current_n++)
5765 {
5766 int shift;
5767
5768 /* Calculate which part of the value to mask. */
5769 if (residual == 0)
5770 shift = 0;
5771 else
5772 {
5773 int msb;
5774
5775 /* Determine the most significant bit in the residual and
5776 align the resulting value to a 2-bit boundary. */
5777 for (msb = 30; msb >= 0; msb -= 2)
5778 if (residual & (3 << msb))
5779 break;
5780
5781 /* The desired shift is now (msb - 6), or zero, whichever
5782 is the greater. */
5783 shift = msb - 6;
5784 if (shift < 0)
5785 shift = 0;
5786 }
5787
5788 /* Calculate g_n in 32-bit as well as encoded constant+rotation form. */
5789 g_n = residual & (0xff << shift);
5790 encoded_g_n = (g_n >> shift)
5791 | ((g_n <= 0xff ? 0 : (32 - shift) / 2) << 8);
5792
5793 /* Calculate the residual for the next time around. */
5794 residual &= ~g_n;
5795 }
5796
5797 *final_residual = residual;
5798
5799 return encoded_g_n;
5800}
5801
5802/* Given an ARM instruction, determine whether it is an ADD or a SUB.
5803 Returns 1 if it is an ADD, -1 if it is a SUB, and 0 otherwise. */
906e58ca 5804
4962c51a 5805static int
906e58ca 5806identify_add_or_sub (bfd_vma insn)
4962c51a
MS
5807{
5808 int opcode = insn & 0x1e00000;
5809
5810 if (opcode == 1 << 23) /* ADD */
5811 return 1;
5812
5813 if (opcode == 1 << 22) /* SUB */
5814 return -1;
5815
5816 return 0;
5817}
5818
252b5132 5819/* Perform a relocation as part of a final link. */
9b485d32 5820
252b5132 5821static bfd_reloc_status_type
57e8b36a
NC
5822elf32_arm_final_link_relocate (reloc_howto_type * howto,
5823 bfd * input_bfd,
5824 bfd * output_bfd,
5825 asection * input_section,
5826 bfd_byte * contents,
5827 Elf_Internal_Rela * rel,
5828 bfd_vma value,
5829 struct bfd_link_info * info,
5830 asection * sym_sec,
5831 const char * sym_name,
5832 int sym_flags,
0945cdfd 5833 struct elf_link_hash_entry * h,
f2a9dd69
DJ
5834 bfd_boolean * unresolved_reloc_p,
5835 char **error_message)
252b5132
RH
5836{
5837 unsigned long r_type = howto->type;
5838 unsigned long r_symndx;
5839 bfd_byte * hit_data = contents + rel->r_offset;
5840 bfd * dynobj = NULL;
5841 Elf_Internal_Shdr * symtab_hdr;
5842 struct elf_link_hash_entry ** sym_hashes;
5843 bfd_vma * local_got_offsets;
5844 asection * sgot = NULL;
5845 asection * splt = NULL;
5846 asection * sreloc = NULL;
252b5132 5847 bfd_vma addend;
ba96a88f
NC
5848 bfd_signed_vma signed_addend;
5849 struct elf32_arm_link_hash_table * globals;
f21f3fe0 5850
9c504268
PB
5851 globals = elf32_arm_hash_table (info);
5852
0ffa91dd
NC
5853 BFD_ASSERT (is_arm_elf (input_bfd));
5854
5855 /* Some relocation types map to different relocations depending on the
9c504268 5856 target. We pick the right one here. */
eb043451
PB
5857 r_type = arm_real_reloc_type (globals, r_type);
5858 if (r_type != howto->type)
5859 howto = elf32_arm_howto_from_type (r_type);
9c504268 5860
cac15327
NC
5861 /* If the start address has been set, then set the EF_ARM_HASENTRY
5862 flag. Setting this more than once is redundant, but the cost is
5863 not too high, and it keeps the code simple.
99e4ae17 5864
cac15327
NC
5865 The test is done here, rather than somewhere else, because the
5866 start address is only set just before the final link commences.
5867
5868 Note - if the user deliberately sets a start address of 0, the
5869 flag will not be set. */
5870 if (bfd_get_start_address (output_bfd) != 0)
5871 elf_elfheader (output_bfd)->e_flags |= EF_ARM_HASENTRY;
99e4ae17 5872
252b5132
RH
5873 dynobj = elf_hash_table (info)->dynobj;
5874 if (dynobj)
5875 {
5876 sgot = bfd_get_section_by_name (dynobj, ".got");
5877 splt = bfd_get_section_by_name (dynobj, ".plt");
5878 }
0ffa91dd 5879 symtab_hdr = & elf_symtab_hdr (input_bfd);
252b5132
RH
5880 sym_hashes = elf_sym_hashes (input_bfd);
5881 local_got_offsets = elf_local_got_offsets (input_bfd);
5882 r_symndx = ELF32_R_SYM (rel->r_info);
5883
4e7fd91e 5884 if (globals->use_rel)
ba96a88f 5885 {
4e7fd91e
PB
5886 addend = bfd_get_32 (input_bfd, hit_data) & howto->src_mask;
5887
5888 if (addend & ((howto->src_mask + 1) >> 1))
5889 {
5890 signed_addend = -1;
5891 signed_addend &= ~ howto->src_mask;
5892 signed_addend |= addend;
5893 }
5894 else
5895 signed_addend = addend;
ba96a88f
NC
5896 }
5897 else
4e7fd91e 5898 addend = signed_addend = rel->r_addend;
f21f3fe0 5899
252b5132
RH
5900 switch (r_type)
5901 {
5902 case R_ARM_NONE:
28a094c2
DJ
5903 /* We don't need to find a value for this symbol. It's just a
5904 marker. */
5905 *unresolved_reloc_p = FALSE;
252b5132
RH
5906 return bfd_reloc_ok;
5907
00a97672
RS
5908 case R_ARM_ABS12:
5909 if (!globals->vxworks_p)
5910 return elf32_arm_abs12_reloc (input_bfd, hit_data, value + addend);
5911
252b5132
RH
5912 case R_ARM_PC24:
5913 case R_ARM_ABS32:
bb224fc3 5914 case R_ARM_ABS32_NOI:
252b5132 5915 case R_ARM_REL32:
bb224fc3 5916 case R_ARM_REL32_NOI:
5b5bb741
PB
5917 case R_ARM_CALL:
5918 case R_ARM_JUMP24:
dfc5f959 5919 case R_ARM_XPC25:
eb043451 5920 case R_ARM_PREL31:
7359ea65 5921 case R_ARM_PLT32:
7359ea65
DJ
5922 /* Handle relocations which should use the PLT entry. ABS32/REL32
5923 will use the symbol's value, which may point to a PLT entry, but we
5924 don't need to handle that here. If we created a PLT entry, all
5925 branches in this object should go to it. */
bb224fc3
MS
5926 if ((r_type != R_ARM_ABS32 && r_type != R_ARM_REL32
5927 && r_type != R_ARM_ABS32_NOI && r_type != R_ARM_REL32_NOI)
7359ea65 5928 && h != NULL
c84cd8ee 5929 && splt != NULL
7359ea65
DJ
5930 && h->plt.offset != (bfd_vma) -1)
5931 {
c84cd8ee
DJ
5932 /* If we've created a .plt section, and assigned a PLT entry to
5933 this function, it should not be known to bind locally. If
5934 it were, we would have cleared the PLT entry. */
7359ea65
DJ
5935 BFD_ASSERT (!SYMBOL_CALLS_LOCAL (info, h));
5936
5937 value = (splt->output_section->vma
5938 + splt->output_offset
5939 + h->plt.offset);
0945cdfd 5940 *unresolved_reloc_p = FALSE;
7359ea65
DJ
5941 return _bfd_final_link_relocate (howto, input_bfd, input_section,
5942 contents, rel->r_offset, value,
00a97672 5943 rel->r_addend);
7359ea65
DJ
5944 }
5945
67687978
PB
5946 /* When generating a shared object or relocatable executable, these
5947 relocations are copied into the output file to be resolved at
5948 run time. */
5949 if ((info->shared || globals->root.is_relocatable_executable)
7359ea65 5950 && (input_section->flags & SEC_ALLOC)
3348747a
NS
5951 && !(elf32_arm_hash_table (info)->vxworks_p
5952 && strcmp (input_section->output_section->name,
5953 ".tls_vars") == 0)
bb224fc3 5954 && ((r_type != R_ARM_REL32 && r_type != R_ARM_REL32_NOI)
ee06dc07 5955 || !SYMBOL_CALLS_LOCAL (info, h))
7359ea65
DJ
5956 && (h == NULL
5957 || ELF_ST_VISIBILITY (h->other) == STV_DEFAULT
5958 || h->root.type != bfd_link_hash_undefweak)
5959 && r_type != R_ARM_PC24
5b5bb741
PB
5960 && r_type != R_ARM_CALL
5961 && r_type != R_ARM_JUMP24
ee06dc07 5962 && r_type != R_ARM_PREL31
7359ea65 5963 && r_type != R_ARM_PLT32)
252b5132 5964 {
947216bf
AM
5965 Elf_Internal_Rela outrel;
5966 bfd_byte *loc;
b34976b6 5967 bfd_boolean skip, relocate;
f21f3fe0 5968
0945cdfd
DJ
5969 *unresolved_reloc_p = FALSE;
5970
252b5132
RH
5971 if (sreloc == NULL)
5972 {
5973 const char * name;
f21f3fe0 5974
252b5132
RH
5975 name = (bfd_elf_string_from_elf_section
5976 (input_bfd,
5977 elf_elfheader (input_bfd)->e_shstrndx,
5978 elf_section_data (input_section)->rel_hdr.sh_name));
5979 if (name == NULL)
5980 return bfd_reloc_notsupported;
f21f3fe0 5981
00a97672 5982 BFD_ASSERT (reloc_section_p (globals, name, input_section));
f21f3fe0 5983
252b5132
RH
5984 sreloc = bfd_get_section_by_name (dynobj, name);
5985 BFD_ASSERT (sreloc != NULL);
5986 }
f21f3fe0 5987
b34976b6
AM
5988 skip = FALSE;
5989 relocate = FALSE;
f21f3fe0 5990
00a97672 5991 outrel.r_addend = addend;
c629eae0
JJ
5992 outrel.r_offset =
5993 _bfd_elf_section_offset (output_bfd, info, input_section,
5994 rel->r_offset);
5995 if (outrel.r_offset == (bfd_vma) -1)
b34976b6 5996 skip = TRUE;
0bb2d96a 5997 else if (outrel.r_offset == (bfd_vma) -2)
b34976b6 5998 skip = TRUE, relocate = TRUE;
252b5132
RH
5999 outrel.r_offset += (input_section->output_section->vma
6000 + input_section->output_offset);
f21f3fe0 6001
252b5132 6002 if (skip)
0bb2d96a 6003 memset (&outrel, 0, sizeof outrel);
5e681ec4
PB
6004 else if (h != NULL
6005 && h->dynindx != -1
7359ea65 6006 && (!info->shared
5e681ec4 6007 || !info->symbolic
f5385ebf 6008 || !h->def_regular))
5e681ec4 6009 outrel.r_info = ELF32_R_INFO (h->dynindx, r_type);
252b5132
RH
6010 else
6011 {
a16385dc
MM
6012 int symbol;
6013
5e681ec4 6014 /* This symbol is local, or marked to become local. */
b7693d02
DJ
6015 if (sym_flags == STT_ARM_TFUNC)
6016 value |= 1;
a16385dc 6017 if (globals->symbian_p)
6366ff1e 6018 {
74541ad4
AM
6019 asection *osec;
6020
6366ff1e
MM
6021 /* On Symbian OS, the data segment and text segement
6022 can be relocated independently. Therefore, we
6023 must indicate the segment to which this
6024 relocation is relative. The BPABI allows us to
6025 use any symbol in the right segment; we just use
6026 the section symbol as it is convenient. (We
6027 cannot use the symbol given by "h" directly as it
74541ad4
AM
6028 will not appear in the dynamic symbol table.)
6029
6030 Note that the dynamic linker ignores the section
6031 symbol value, so we don't subtract osec->vma
6032 from the emitted reloc addend. */
10dbd1f3 6033 if (sym_sec)
74541ad4 6034 osec = sym_sec->output_section;
10dbd1f3 6035 else
74541ad4
AM
6036 osec = input_section->output_section;
6037 symbol = elf_section_data (osec)->dynindx;
6038 if (symbol == 0)
6039 {
6040 struct elf_link_hash_table *htab = elf_hash_table (info);
6041
6042 if ((osec->flags & SEC_READONLY) == 0
6043 && htab->data_index_section != NULL)
6044 osec = htab->data_index_section;
6045 else
6046 osec = htab->text_index_section;
6047 symbol = elf_section_data (osec)->dynindx;
6048 }
6366ff1e
MM
6049 BFD_ASSERT (symbol != 0);
6050 }
a16385dc
MM
6051 else
6052 /* On SVR4-ish systems, the dynamic loader cannot
6053 relocate the text and data segments independently,
6054 so the symbol does not matter. */
6055 symbol = 0;
6056 outrel.r_info = ELF32_R_INFO (symbol, R_ARM_RELATIVE);
00a97672
RS
6057 if (globals->use_rel)
6058 relocate = TRUE;
6059 else
6060 outrel.r_addend += value;
252b5132 6061 }
f21f3fe0 6062
947216bf 6063 loc = sreloc->contents;
00a97672
RS
6064 loc += sreloc->reloc_count++ * RELOC_SIZE (globals);
6065 SWAP_RELOC_OUT (globals) (output_bfd, &outrel, loc);
9a5aca8c 6066
f21f3fe0 6067 /* If this reloc is against an external symbol, we do not want to
252b5132 6068 fiddle with the addend. Otherwise, we need to include the symbol
9b485d32 6069 value so that it becomes an addend for the dynamic reloc. */
252b5132
RH
6070 if (! relocate)
6071 return bfd_reloc_ok;
9a5aca8c 6072
f21f3fe0 6073 return _bfd_final_link_relocate (howto, input_bfd, input_section,
252b5132
RH
6074 contents, rel->r_offset, value,
6075 (bfd_vma) 0);
6076 }
6077 else switch (r_type)
6078 {
00a97672
RS
6079 case R_ARM_ABS12:
6080 return elf32_arm_abs12_reloc (input_bfd, hit_data, value + addend);
6081
dfc5f959 6082 case R_ARM_XPC25: /* Arm BLX instruction. */
5b5bb741
PB
6083 case R_ARM_CALL:
6084 case R_ARM_JUMP24:
dfc5f959 6085 case R_ARM_PC24: /* Arm B/BL instruction */
7359ea65 6086 case R_ARM_PLT32:
906e58ca
NC
6087 {
6088 bfd_vma from;
6089 bfd_signed_vma branch_offset;
6090 struct elf32_arm_stub_hash_entry *stub_entry = NULL;
6091
6092 from = (input_section->output_section->vma
6093 + input_section->output_offset
6094 + rel->r_offset);
6095 branch_offset = (bfd_signed_vma)(value - from);
6096
dfc5f959 6097 if (r_type == R_ARM_XPC25)
252b5132 6098 {
dfc5f959
NC
6099 /* Check for Arm calling Arm function. */
6100 /* FIXME: Should we translate the instruction into a BL
6101 instruction instead ? */
6102 if (sym_flags != STT_ARM_TFUNC)
d003868e
AM
6103 (*_bfd_error_handler)
6104 (_("\%B: Warning: Arm BLX instruction targets Arm function '%s'."),
6105 input_bfd,
6106 h ? h->root.root.string : "(local)");
dfc5f959 6107 }
906e58ca 6108 else if (r_type != R_ARM_CALL)
dfc5f959
NC
6109 {
6110 /* Check for Arm calling Thumb function. */
6111 if (sym_flags == STT_ARM_TFUNC)
6112 {
f2a9dd69
DJ
6113 if (elf32_arm_to_thumb_stub (info, sym_name, input_bfd,
6114 output_bfd, input_section,
6115 hit_data, sym_sec, rel->r_offset,
6116 signed_addend, value,
6117 error_message))
6118 return bfd_reloc_ok;
6119 else
6120 return bfd_reloc_dangerous;
dfc5f959 6121 }
252b5132 6122 }
ba96a88f 6123
906e58ca
NC
6124 /* Check if a stub has to be inserted because the
6125 destination is too far or we are changing mode */
6126 if (r_type == R_ARM_CALL)
6127 {
6128 if (branch_offset > ARM_MAX_FWD_BRANCH_OFFSET
6129 || branch_offset < ARM_MAX_BWD_BRANCH_OFFSET
6130 || sym_flags == STT_ARM_TFUNC)
6131 {
6132 /* The target is out of reach, so redirect the
6133 branch to the local stub for this function. */
6134
6135 stub_entry = elf32_arm_get_stub_entry (input_section,
6136 sym_sec, h,
6137 rel, globals);
6138 if (stub_entry != NULL)
6139 value = (stub_entry->stub_offset
6140 + stub_entry->stub_sec->output_offset
6141 + stub_entry->stub_sec->output_section->vma);
6142 }
6143 }
6144
dea514f5
PB
6145 /* The ARM ELF ABI says that this reloc is computed as: S - P + A
6146 where:
6147 S is the address of the symbol in the relocation.
6148 P is address of the instruction being relocated.
6149 A is the addend (extracted from the instruction) in bytes.
6150
6151 S is held in 'value'.
6152 P is the base address of the section containing the
6153 instruction plus the offset of the reloc into that
6154 section, ie:
6155 (input_section->output_section->vma +
6156 input_section->output_offset +
6157 rel->r_offset).
6158 A is the addend, converted into bytes, ie:
6159 (signed_addend * 4)
6160
6161 Note: None of these operations have knowledge of the pipeline
6162 size of the processor, thus it is up to the assembler to
6163 encode this information into the addend. */
6164 value -= (input_section->output_section->vma
6165 + input_section->output_offset);
6166 value -= rel->r_offset;
4e7fd91e
PB
6167 if (globals->use_rel)
6168 value += (signed_addend << howto->size);
6169 else
6170 /* RELA addends do not have to be adjusted by howto->size. */
6171 value += signed_addend;
23080146 6172
dcb5e6e6
NC
6173 signed_addend = value;
6174 signed_addend >>= howto->rightshift;
9a5aca8c 6175
5ab79981
PB
6176 /* A branch to an undefined weak symbol is turned into a jump to
6177 the next instruction. */
6178 if (h && h->root.type == bfd_link_hash_undefweak)
6179 {
6180 value = (bfd_get_32 (input_bfd, hit_data) & 0xf0000000)
6181 | 0x0affffff;
6182 }
6183 else
59f2c4e7 6184 {
9b485d32 6185 /* Perform a signed range check. */
dcb5e6e6 6186 if ( signed_addend > ((bfd_signed_vma) (howto->dst_mask >> 1))
59f2c4e7
NC
6187 || signed_addend < - ((bfd_signed_vma) ((howto->dst_mask + 1) >> 1)))
6188 return bfd_reloc_overflow;
9a5aca8c 6189
5ab79981 6190 addend = (value & 2);
39b41c9c 6191
5ab79981
PB
6192 value = (signed_addend & howto->dst_mask)
6193 | (bfd_get_32 (input_bfd, hit_data) & (~ howto->dst_mask));
39b41c9c 6194
5ab79981 6195 /* Set the H bit in the BLX instruction. */
39b41c9c 6196 if (sym_flags == STT_ARM_TFUNC)
39b41c9c 6197 {
5ab79981
PB
6198 if (addend)
6199 value |= (1 << 24);
6200 else
6201 value &= ~(bfd_vma)(1 << 24);
6202 }
6203 if (r_type == R_ARM_CALL)
6204 {
6205 /* Select the correct instruction (BL or BLX). */
906e58ca
NC
6206 /* Only if we are not handling a BL to a stub. In this
6207 case, mode switching is performed by the stub. */
6208 if (sym_flags == STT_ARM_TFUNC && !stub_entry)
5ab79981
PB
6209 value |= (1 << 28);
6210 else
6211 {
6212 value &= ~(bfd_vma)(1 << 28);
6213 value |= (1 << 24);
6214 }
39b41c9c
PB
6215 }
6216 }
906e58ca 6217 }
252b5132 6218 break;
f21f3fe0 6219
252b5132
RH
6220 case R_ARM_ABS32:
6221 value += addend;
6222 if (sym_flags == STT_ARM_TFUNC)
6223 value |= 1;
6224 break;
f21f3fe0 6225
bb224fc3
MS
6226 case R_ARM_ABS32_NOI:
6227 value += addend;
6228 break;
6229
252b5132 6230 case R_ARM_REL32:
a8bc6c78
PB
6231 value += addend;
6232 if (sym_flags == STT_ARM_TFUNC)
6233 value |= 1;
252b5132 6234 value -= (input_section->output_section->vma
62efb346 6235 + input_section->output_offset + rel->r_offset);
252b5132 6236 break;
eb043451 6237
bb224fc3
MS
6238 case R_ARM_REL32_NOI:
6239 value += addend;
6240 value -= (input_section->output_section->vma
6241 + input_section->output_offset + rel->r_offset);
6242 break;
6243
eb043451
PB
6244 case R_ARM_PREL31:
6245 value -= (input_section->output_section->vma
6246 + input_section->output_offset + rel->r_offset);
6247 value += signed_addend;
6248 if (! h || h->root.type != bfd_link_hash_undefweak)
6249 {
6250 /* Check for overflow */
6251 if ((value ^ (value >> 1)) & (1 << 30))
6252 return bfd_reloc_overflow;
6253 }
6254 value &= 0x7fffffff;
6255 value |= (bfd_get_32 (input_bfd, hit_data) & 0x80000000);
6256 if (sym_flags == STT_ARM_TFUNC)
6257 value |= 1;
6258 break;
252b5132 6259 }
f21f3fe0 6260
252b5132
RH
6261 bfd_put_32 (input_bfd, value, hit_data);
6262 return bfd_reloc_ok;
6263
6264 case R_ARM_ABS8:
6265 value += addend;
6266 if ((long) value > 0x7f || (long) value < -0x80)
6267 return bfd_reloc_overflow;
6268
6269 bfd_put_8 (input_bfd, value, hit_data);
6270 return bfd_reloc_ok;
6271
6272 case R_ARM_ABS16:
6273 value += addend;
6274
6275 if ((long) value > 0x7fff || (long) value < -0x8000)
6276 return bfd_reloc_overflow;
6277
6278 bfd_put_16 (input_bfd, value, hit_data);
6279 return bfd_reloc_ok;
6280
252b5132 6281 case R_ARM_THM_ABS5:
9b485d32 6282 /* Support ldr and str instructions for the thumb. */
4e7fd91e
PB
6283 if (globals->use_rel)
6284 {
6285 /* Need to refetch addend. */
6286 addend = bfd_get_16 (input_bfd, hit_data) & howto->src_mask;
6287 /* ??? Need to determine shift amount from operand size. */
6288 addend >>= howto->rightshift;
6289 }
252b5132
RH
6290 value += addend;
6291
6292 /* ??? Isn't value unsigned? */
6293 if ((long) value > 0x1f || (long) value < -0x10)
6294 return bfd_reloc_overflow;
6295
6296 /* ??? Value needs to be properly shifted into place first. */
6297 value |= bfd_get_16 (input_bfd, hit_data) & 0xf83f;
6298 bfd_put_16 (input_bfd, value, hit_data);
6299 return bfd_reloc_ok;
6300
2cab6cc3
MS
6301 case R_ARM_THM_ALU_PREL_11_0:
6302 /* Corresponds to: addw.w reg, pc, #offset (and similarly for subw). */
6303 {
6304 bfd_vma insn;
6305 bfd_signed_vma relocation;
6306
6307 insn = (bfd_get_16 (input_bfd, hit_data) << 16)
6308 | bfd_get_16 (input_bfd, hit_data + 2);
6309
6310 if (globals->use_rel)
6311 {
6312 signed_addend = (insn & 0xff) | ((insn & 0x7000) >> 4)
6313 | ((insn & (1 << 26)) >> 15);
6314 if (insn & 0xf00000)
6315 signed_addend = -signed_addend;
6316 }
6317
6318 relocation = value + signed_addend;
6319 relocation -= (input_section->output_section->vma
6320 + input_section->output_offset
6321 + rel->r_offset);
6322
6323 value = abs (relocation);
6324
6325 if (value >= 0x1000)
6326 return bfd_reloc_overflow;
6327
6328 insn = (insn & 0xfb0f8f00) | (value & 0xff)
6329 | ((value & 0x700) << 4)
6330 | ((value & 0x800) << 15);
6331 if (relocation < 0)
6332 insn |= 0xa00000;
6333
6334 bfd_put_16 (input_bfd, insn >> 16, hit_data);
6335 bfd_put_16 (input_bfd, insn & 0xffff, hit_data + 2);
6336
6337 return bfd_reloc_ok;
6338 }
6339
6340 case R_ARM_THM_PC12:
6341 /* Corresponds to: ldr.w reg, [pc, #offset]. */
6342 {
6343 bfd_vma insn;
6344 bfd_signed_vma relocation;
6345
6346 insn = (bfd_get_16 (input_bfd, hit_data) << 16)
6347 | bfd_get_16 (input_bfd, hit_data + 2);
6348
6349 if (globals->use_rel)
6350 {
6351 signed_addend = insn & 0xfff;
6352 if (!(insn & (1 << 23)))
6353 signed_addend = -signed_addend;
6354 }
6355
6356 relocation = value + signed_addend;
6357 relocation -= (input_section->output_section->vma
6358 + input_section->output_offset
6359 + rel->r_offset);
6360
6361 value = abs (relocation);
6362
6363 if (value >= 0x1000)
6364 return bfd_reloc_overflow;
6365
6366 insn = (insn & 0xff7ff000) | value;
6367 if (relocation >= 0)
6368 insn |= (1 << 23);
6369
6370 bfd_put_16 (input_bfd, insn >> 16, hit_data);
6371 bfd_put_16 (input_bfd, insn & 0xffff, hit_data + 2);
6372
6373 return bfd_reloc_ok;
6374 }
6375
dfc5f959 6376 case R_ARM_THM_XPC22:
c19d1205 6377 case R_ARM_THM_CALL:
bd97cb95 6378 case R_ARM_THM_JUMP24:
dfc5f959 6379 /* Thumb BL (branch long instruction). */
252b5132 6380 {
b34976b6 6381 bfd_vma relocation;
e95de063 6382 bfd_vma reloc_sign;
b34976b6
AM
6383 bfd_boolean overflow = FALSE;
6384 bfd_vma upper_insn = bfd_get_16 (input_bfd, hit_data);
6385 bfd_vma lower_insn = bfd_get_16 (input_bfd, hit_data + 2);
e95de063
MS
6386 bfd_signed_vma reloc_signed_max;
6387 bfd_signed_vma reloc_signed_min;
b34976b6 6388 bfd_vma check;
252b5132 6389 bfd_signed_vma signed_check;
e95de063
MS
6390 int bitsize;
6391 int thumb2 = using_thumb2 (globals);
252b5132 6392
5ab79981
PB
6393 /* A branch to an undefined weak symbol is turned into a jump to
6394 the next instruction. */
6395 if (h && h->root.type == bfd_link_hash_undefweak)
6396 {
6397 bfd_put_16 (input_bfd, 0xe000, hit_data);
6398 bfd_put_16 (input_bfd, 0xbf00, hit_data + 2);
6399 return bfd_reloc_ok;
6400 }
6401
e95de063
MS
6402 /* Fetch the addend. We use the Thumb-2 encoding (backwards compatible
6403 with Thumb-1) involving the J1 and J2 bits. */
4e7fd91e
PB
6404 if (globals->use_rel)
6405 {
e95de063
MS
6406 bfd_vma s = (upper_insn & (1 << 10)) >> 10;
6407 bfd_vma upper = upper_insn & 0x3ff;
6408 bfd_vma lower = lower_insn & 0x7ff;
6409 bfd_vma j1 = (lower_insn & (1 << 13)) >> 13;
6410 bfd_vma j2 = (lower_insn & (1 << 11)) >> 11;
6411 bfd_vma i1 = j1 ^ s ? 0 : 1;
6412 bfd_vma i2 = j2 ^ s ? 0 : 1;
6413
6414 addend = (i1 << 23) | (i2 << 22) | (upper << 12) | (lower << 1);
6415 /* Sign extend. */
6416 addend = (addend | ((s ? 0 : 1) << 24)) - (1 << 24);
6417
4e7fd91e
PB
6418 signed_addend = addend;
6419 }
cb1afa5c 6420
dfc5f959
NC
6421 if (r_type == R_ARM_THM_XPC22)
6422 {
6423 /* Check for Thumb to Thumb call. */
6424 /* FIXME: Should we translate the instruction into a BL
6425 instruction instead ? */
6426 if (sym_flags == STT_ARM_TFUNC)
d003868e
AM
6427 (*_bfd_error_handler)
6428 (_("%B: Warning: Thumb BLX instruction targets thumb function '%s'."),
6429 input_bfd,
6430 h ? h->root.root.string : "(local)");
dfc5f959
NC
6431 }
6432 else
252b5132 6433 {
dfc5f959
NC
6434 /* If it is not a call to Thumb, assume call to Arm.
6435 If it is a call relative to a section name, then it is not a
b7693d02
DJ
6436 function call at all, but rather a long jump. Calls through
6437 the PLT do not require stubs. */
6438 if (sym_flags != STT_ARM_TFUNC && sym_flags != STT_SECTION
6439 && (h == NULL || splt == NULL
6440 || h->plt.offset == (bfd_vma) -1))
dfc5f959 6441 {
bd97cb95 6442 if (globals->use_blx && r_type == R_ARM_THM_CALL)
39b41c9c
PB
6443 {
6444 /* Convert BL to BLX. */
6445 lower_insn = (lower_insn & ~0x1000) | 0x0800;
6446 }
da5938a2
NC
6447 else if (r_type != R_ARM_THM_CALL) {
6448 if (elf32_thumb_to_arm_stub
dfc5f959 6449 (info, sym_name, input_bfd, output_bfd, input_section,
f2a9dd69
DJ
6450 hit_data, sym_sec, rel->r_offset, signed_addend, value,
6451 error_message))
dfc5f959
NC
6452 return bfd_reloc_ok;
6453 else
6454 return bfd_reloc_dangerous;
6455 }
da5938a2 6456 }
bd97cb95
DJ
6457 else if (sym_flags == STT_ARM_TFUNC && globals->use_blx
6458 && r_type == R_ARM_THM_CALL)
39b41c9c
PB
6459 {
6460 /* Make sure this is a BL. */
6461 lower_insn |= 0x1800;
6462 }
252b5132 6463 }
f21f3fe0 6464
b7693d02
DJ
6465 /* Handle calls via the PLT. */
6466 if (h != NULL && splt != NULL && h->plt.offset != (bfd_vma) -1)
6467 {
6468 value = (splt->output_section->vma
6469 + splt->output_offset
6470 + h->plt.offset);
bd97cb95 6471 if (globals->use_blx && r_type == R_ARM_THM_CALL)
33bfe774
JB
6472 {
6473 /* If the Thumb BLX instruction is available, convert the
6474 BL to a BLX instruction to call the ARM-mode PLT entry. */
39b41c9c 6475 lower_insn = (lower_insn & ~0x1000) | 0x0800;
33bfe774
JB
6476 }
6477 else
6478 /* Target the Thumb stub before the ARM PLT entry. */
6479 value -= PLT_THUMB_STUB_SIZE;
0945cdfd 6480 *unresolved_reloc_p = FALSE;
b7693d02
DJ
6481 }
6482
906e58ca
NC
6483 if (r_type == R_ARM_THM_CALL)
6484 {
6485 /* Check if a stub has to be inserted because the destination
6486 is too far. */
6487 bfd_vma from;
6488 bfd_signed_vma branch_offset;
6489 struct elf32_arm_stub_hash_entry *stub_entry = NULL;
6490
6491 from = (input_section->output_section->vma
6492 + input_section->output_offset
6493 + rel->r_offset);
6494 branch_offset = (bfd_signed_vma)(value - from);
6495
6496 if ((!thumb2
6497 && (branch_offset > THM_MAX_FWD_BRANCH_OFFSET
6498 || (branch_offset < THM_MAX_BWD_BRANCH_OFFSET)))
6499 ||
6500 (thumb2
6501 && (branch_offset > THM2_MAX_FWD_BRANCH_OFFSET
f4ac8484
DJ
6502 || (branch_offset < THM2_MAX_BWD_BRANCH_OFFSET)))
6503 || ((sym_flags != STT_ARM_TFUNC) && !globals->use_blx))
906e58ca
NC
6504 {
6505 /* The target is out of reach or we are changing modes, so
6506 redirect the branch to the local stub for this
6507 function. */
6508 stub_entry = elf32_arm_get_stub_entry (input_section,
6509 sym_sec, h,
6510 rel, globals);
6511 if (stub_entry != NULL)
6512 value = (stub_entry->stub_offset
6513 + stub_entry->stub_sec->output_offset
6514 + stub_entry->stub_sec->output_section->vma);
6515
f4ac8484
DJ
6516 /* If this call becomes a call to Arm, force BLX. */
6517 if (globals->use_blx)
6518 {
6519 if ((stub_entry
6520 && !arm_stub_is_thumb (stub_entry->stub_type))
6521 || (sym_flags != STT_ARM_TFUNC))
6522 lower_insn = (lower_insn & ~0x1000) | 0x0800;
6523 }
906e58ca
NC
6524 }
6525 }
6526
ba96a88f 6527 relocation = value + signed_addend;
f21f3fe0 6528
252b5132 6529 relocation -= (input_section->output_section->vma
ba96a88f
NC
6530 + input_section->output_offset
6531 + rel->r_offset);
9a5aca8c 6532
252b5132
RH
6533 check = relocation >> howto->rightshift;
6534
6535 /* If this is a signed value, the rightshift just dropped
6536 leading 1 bits (assuming twos complement). */
6537 if ((bfd_signed_vma) relocation >= 0)
6538 signed_check = check;
6539 else
6540 signed_check = check | ~((bfd_vma) -1 >> howto->rightshift);
6541
e95de063
MS
6542 /* Calculate the permissable maximum and minimum values for
6543 this relocation according to whether we're relocating for
6544 Thumb-2 or not. */
6545 bitsize = howto->bitsize;
6546 if (!thumb2)
6547 bitsize -= 2;
6548 reloc_signed_max = ((1 << (bitsize - 1)) - 1) >> howto->rightshift;
6549 reloc_signed_min = ~reloc_signed_max;
6550
252b5132 6551 /* Assumes two's complement. */
ba96a88f 6552 if (signed_check > reloc_signed_max || signed_check < reloc_signed_min)
b34976b6 6553 overflow = TRUE;
252b5132 6554
bd97cb95 6555 if ((lower_insn & 0x5000) == 0x4000)
c62e1cc3
NC
6556 /* For a BLX instruction, make sure that the relocation is rounded up
6557 to a word boundary. This follows the semantics of the instruction
6558 which specifies that bit 1 of the target address will come from bit
6559 1 of the base address. */
6560 relocation = (relocation + 2) & ~ 3;
cb1afa5c 6561
e95de063
MS
6562 /* Put RELOCATION back into the insn. Assumes two's complement.
6563 We use the Thumb-2 encoding, which is safe even if dealing with
6564 a Thumb-1 instruction by virtue of our overflow check above. */
6565 reloc_sign = (signed_check < 0) ? 1 : 0;
6566 upper_insn = (upper_insn & ~(bfd_vma) 0x7ff)
6567 | ((relocation >> 12) & 0x3ff)
6568 | (reloc_sign << 10);
906e58ca 6569 lower_insn = (lower_insn & ~(bfd_vma) 0x2fff)
e95de063
MS
6570 | (((!((relocation >> 23) & 1)) ^ reloc_sign) << 13)
6571 | (((!((relocation >> 22) & 1)) ^ reloc_sign) << 11)
6572 | ((relocation >> 1) & 0x7ff);
c62e1cc3 6573
252b5132
RH
6574 /* Put the relocated value back in the object file: */
6575 bfd_put_16 (input_bfd, upper_insn, hit_data);
6576 bfd_put_16 (input_bfd, lower_insn, hit_data + 2);
6577
6578 return (overflow ? bfd_reloc_overflow : bfd_reloc_ok);
6579 }
6580 break;
6581
c19d1205
ZW
6582 case R_ARM_THM_JUMP19:
6583 /* Thumb32 conditional branch instruction. */
6584 {
6585 bfd_vma relocation;
6586 bfd_boolean overflow = FALSE;
6587 bfd_vma upper_insn = bfd_get_16 (input_bfd, hit_data);
6588 bfd_vma lower_insn = bfd_get_16 (input_bfd, hit_data + 2);
a00a1f35
MS
6589 bfd_signed_vma reloc_signed_max = 0xffffe;
6590 bfd_signed_vma reloc_signed_min = -0x100000;
c19d1205
ZW
6591 bfd_signed_vma signed_check;
6592
6593 /* Need to refetch the addend, reconstruct the top three bits,
6594 and squish the two 11 bit pieces together. */
6595 if (globals->use_rel)
6596 {
6597 bfd_vma S = (upper_insn & 0x0400) >> 10;
a00a1f35 6598 bfd_vma upper = (upper_insn & 0x003f);
c19d1205
ZW
6599 bfd_vma J1 = (lower_insn & 0x2000) >> 13;
6600 bfd_vma J2 = (lower_insn & 0x0800) >> 11;
6601 bfd_vma lower = (lower_insn & 0x07ff);
6602
a00a1f35
MS
6603 upper |= J1 << 6;
6604 upper |= J2 << 7;
6605 upper |= (!S) << 8;
c19d1205
ZW
6606 upper -= 0x0100; /* Sign extend. */
6607
6608 addend = (upper << 12) | (lower << 1);
6609 signed_addend = addend;
6610 }
6611
bd97cb95
DJ
6612 /* Handle calls via the PLT. */
6613 if (h != NULL && splt != NULL && h->plt.offset != (bfd_vma) -1)
6614 {
6615 value = (splt->output_section->vma
6616 + splt->output_offset
6617 + h->plt.offset);
6618 /* Target the Thumb stub before the ARM PLT entry. */
6619 value -= PLT_THUMB_STUB_SIZE;
6620 *unresolved_reloc_p = FALSE;
6621 }
6622
c19d1205
ZW
6623 /* ??? Should handle interworking? GCC might someday try to
6624 use this for tail calls. */
6625
6626 relocation = value + signed_addend;
6627 relocation -= (input_section->output_section->vma
6628 + input_section->output_offset
6629 + rel->r_offset);
a00a1f35 6630 signed_check = (bfd_signed_vma) relocation;
c19d1205 6631
c19d1205
ZW
6632 if (signed_check > reloc_signed_max || signed_check < reloc_signed_min)
6633 overflow = TRUE;
6634
6635 /* Put RELOCATION back into the insn. */
6636 {
6637 bfd_vma S = (relocation & 0x00100000) >> 20;
6638 bfd_vma J2 = (relocation & 0x00080000) >> 19;
6639 bfd_vma J1 = (relocation & 0x00040000) >> 18;
6640 bfd_vma hi = (relocation & 0x0003f000) >> 12;
6641 bfd_vma lo = (relocation & 0x00000ffe) >> 1;
6642
a00a1f35 6643 upper_insn = (upper_insn & 0xfbc0) | (S << 10) | hi;
c19d1205
ZW
6644 lower_insn = (lower_insn & 0xd000) | (J1 << 13) | (J2 << 11) | lo;
6645 }
6646
6647 /* Put the relocated value back in the object file: */
6648 bfd_put_16 (input_bfd, upper_insn, hit_data);
6649 bfd_put_16 (input_bfd, lower_insn, hit_data + 2);
6650
6651 return (overflow ? bfd_reloc_overflow : bfd_reloc_ok);
6652 }
6653
6654 case R_ARM_THM_JUMP11:
6655 case R_ARM_THM_JUMP8:
6656 case R_ARM_THM_JUMP6:
51c5503b
NC
6657 /* Thumb B (branch) instruction). */
6658 {
6cf9e9fe 6659 bfd_signed_vma relocation;
51c5503b
NC
6660 bfd_signed_vma reloc_signed_max = (1 << (howto->bitsize - 1)) - 1;
6661 bfd_signed_vma reloc_signed_min = ~ reloc_signed_max;
51c5503b
NC
6662 bfd_signed_vma signed_check;
6663
c19d1205
ZW
6664 /* CZB cannot jump backward. */
6665 if (r_type == R_ARM_THM_JUMP6)
6666 reloc_signed_min = 0;
6667
4e7fd91e 6668 if (globals->use_rel)
6cf9e9fe 6669 {
4e7fd91e
PB
6670 /* Need to refetch addend. */
6671 addend = bfd_get_16 (input_bfd, hit_data) & howto->src_mask;
6672 if (addend & ((howto->src_mask + 1) >> 1))
6673 {
6674 signed_addend = -1;
6675 signed_addend &= ~ howto->src_mask;
6676 signed_addend |= addend;
6677 }
6678 else
6679 signed_addend = addend;
6680 /* The value in the insn has been right shifted. We need to
6681 undo this, so that we can perform the address calculation
6682 in terms of bytes. */
6683 signed_addend <<= howto->rightshift;
6cf9e9fe 6684 }
6cf9e9fe 6685 relocation = value + signed_addend;
51c5503b
NC
6686
6687 relocation -= (input_section->output_section->vma
6688 + input_section->output_offset
6689 + rel->r_offset);
6690
6cf9e9fe
NC
6691 relocation >>= howto->rightshift;
6692 signed_check = relocation;
c19d1205
ZW
6693
6694 if (r_type == R_ARM_THM_JUMP6)
6695 relocation = ((relocation & 0x0020) << 4) | ((relocation & 0x001f) << 3);
6696 else
6697 relocation &= howto->dst_mask;
51c5503b 6698 relocation |= (bfd_get_16 (input_bfd, hit_data) & (~ howto->dst_mask));
cedb70c5 6699
51c5503b
NC
6700 bfd_put_16 (input_bfd, relocation, hit_data);
6701
6702 /* Assumes two's complement. */
6703 if (signed_check > reloc_signed_max || signed_check < reloc_signed_min)
6704 return bfd_reloc_overflow;
6705
6706 return bfd_reloc_ok;
6707 }
cedb70c5 6708
8375c36b
PB
6709 case R_ARM_ALU_PCREL7_0:
6710 case R_ARM_ALU_PCREL15_8:
6711 case R_ARM_ALU_PCREL23_15:
6712 {
6713 bfd_vma insn;
6714 bfd_vma relocation;
6715
6716 insn = bfd_get_32 (input_bfd, hit_data);
4e7fd91e
PB
6717 if (globals->use_rel)
6718 {
6719 /* Extract the addend. */
6720 addend = (insn & 0xff) << ((insn & 0xf00) >> 7);
6721 signed_addend = addend;
6722 }
8375c36b
PB
6723 relocation = value + signed_addend;
6724
6725 relocation -= (input_section->output_section->vma
6726 + input_section->output_offset
6727 + rel->r_offset);
6728 insn = (insn & ~0xfff)
6729 | ((howto->bitpos << 7) & 0xf00)
6730 | ((relocation >> howto->bitpos) & 0xff);
6731 bfd_put_32 (input_bfd, value, hit_data);
6732 }
6733 return bfd_reloc_ok;
6734
252b5132
RH
6735 case R_ARM_GNU_VTINHERIT:
6736 case R_ARM_GNU_VTENTRY:
6737 return bfd_reloc_ok;
6738
c19d1205 6739 case R_ARM_GOTOFF32:
252b5132
RH
6740 /* Relocation is relative to the start of the
6741 global offset table. */
6742
6743 BFD_ASSERT (sgot != NULL);
6744 if (sgot == NULL)
6745 return bfd_reloc_notsupported;
9a5aca8c 6746
cedb70c5 6747 /* If we are addressing a Thumb function, we need to adjust the
ee29b9fb
RE
6748 address by one, so that attempts to call the function pointer will
6749 correctly interpret it as Thumb code. */
6750 if (sym_flags == STT_ARM_TFUNC)
6751 value += 1;
6752
252b5132
RH
6753 /* Note that sgot->output_offset is not involved in this
6754 calculation. We always want the start of .got. If we
6755 define _GLOBAL_OFFSET_TABLE in a different way, as is
6756 permitted by the ABI, we might have to change this
9b485d32 6757 calculation. */
252b5132 6758 value -= sgot->output_section->vma;
f21f3fe0 6759 return _bfd_final_link_relocate (howto, input_bfd, input_section,
99e4ae17 6760 contents, rel->r_offset, value,
00a97672 6761 rel->r_addend);
252b5132
RH
6762
6763 case R_ARM_GOTPC:
a7c10850 6764 /* Use global offset table as symbol value. */
252b5132 6765 BFD_ASSERT (sgot != NULL);
f21f3fe0 6766
252b5132
RH
6767 if (sgot == NULL)
6768 return bfd_reloc_notsupported;
6769
0945cdfd 6770 *unresolved_reloc_p = FALSE;
252b5132 6771 value = sgot->output_section->vma;
f21f3fe0 6772 return _bfd_final_link_relocate (howto, input_bfd, input_section,
99e4ae17 6773 contents, rel->r_offset, value,
00a97672 6774 rel->r_addend);
f21f3fe0 6775
252b5132 6776 case R_ARM_GOT32:
eb043451 6777 case R_ARM_GOT_PREL:
252b5132 6778 /* Relocation is to the entry for this symbol in the
9b485d32 6779 global offset table. */
252b5132
RH
6780 if (sgot == NULL)
6781 return bfd_reloc_notsupported;
f21f3fe0 6782
252b5132
RH
6783 if (h != NULL)
6784 {
6785 bfd_vma off;
5e681ec4 6786 bfd_boolean dyn;
f21f3fe0 6787
252b5132
RH
6788 off = h->got.offset;
6789 BFD_ASSERT (off != (bfd_vma) -1);
5e681ec4 6790 dyn = globals->root.dynamic_sections_created;
f21f3fe0 6791
5e681ec4 6792 if (! WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn, info->shared, h)
50d6c878 6793 || (info->shared
5e681ec4
PB
6794 && SYMBOL_REFERENCES_LOCAL (info, h))
6795 || (ELF_ST_VISIBILITY (h->other)
6796 && h->root.type == bfd_link_hash_undefweak))
252b5132
RH
6797 {
6798 /* This is actually a static link, or it is a -Bsymbolic link
6799 and the symbol is defined locally. We must initialize this
6800 entry in the global offset table. Since the offset must
6801 always be a multiple of 4, we use the least significant bit
6802 to record whether we have initialized it already.
f21f3fe0 6803
00a97672 6804 When doing a dynamic link, we create a .rel(a).got relocation
f21f3fe0 6805 entry to initialize the value. This is done in the
9b485d32 6806 finish_dynamic_symbol routine. */
252b5132
RH
6807 if ((off & 1) != 0)
6808 off &= ~1;
6809 else
6810 {
ee29b9fb
RE
6811 /* If we are addressing a Thumb function, we need to
6812 adjust the address by one, so that attempts to
6813 call the function pointer will correctly
6814 interpret it as Thumb code. */
6815 if (sym_flags == STT_ARM_TFUNC)
6816 value |= 1;
6817
252b5132
RH
6818 bfd_put_32 (output_bfd, value, sgot->contents + off);
6819 h->got.offset |= 1;
6820 }
6821 }
0945cdfd
DJ
6822 else
6823 *unresolved_reloc_p = FALSE;
f21f3fe0 6824
252b5132
RH
6825 value = sgot->output_offset + off;
6826 }
6827 else
6828 {
6829 bfd_vma off;
f21f3fe0 6830
252b5132
RH
6831 BFD_ASSERT (local_got_offsets != NULL &&
6832 local_got_offsets[r_symndx] != (bfd_vma) -1);
f21f3fe0 6833
252b5132 6834 off = local_got_offsets[r_symndx];
f21f3fe0 6835
252b5132
RH
6836 /* The offset must always be a multiple of 4. We use the
6837 least significant bit to record whether we have already
9b485d32 6838 generated the necessary reloc. */
252b5132
RH
6839 if ((off & 1) != 0)
6840 off &= ~1;
6841 else
6842 {
b7693d02
DJ
6843 /* If we are addressing a Thumb function, we need to
6844 adjust the address by one, so that attempts to
6845 call the function pointer will correctly
6846 interpret it as Thumb code. */
6847 if (sym_flags == STT_ARM_TFUNC)
6848 value |= 1;
6849
00a97672
RS
6850 if (globals->use_rel)
6851 bfd_put_32 (output_bfd, value, sgot->contents + off);
f21f3fe0 6852
252b5132
RH
6853 if (info->shared)
6854 {
6855 asection * srelgot;
947216bf
AM
6856 Elf_Internal_Rela outrel;
6857 bfd_byte *loc;
f21f3fe0 6858
00a97672
RS
6859 srelgot = (bfd_get_section_by_name
6860 (dynobj, RELOC_SECTION (globals, ".got")));
252b5132 6861 BFD_ASSERT (srelgot != NULL);
f21f3fe0 6862
00a97672 6863 outrel.r_addend = addend + value;
252b5132 6864 outrel.r_offset = (sgot->output_section->vma
f21f3fe0 6865 + sgot->output_offset
252b5132
RH
6866 + off);
6867 outrel.r_info = ELF32_R_INFO (0, R_ARM_RELATIVE);
947216bf 6868 loc = srelgot->contents;
00a97672
RS
6869 loc += srelgot->reloc_count++ * RELOC_SIZE (globals);
6870 SWAP_RELOC_OUT (globals) (output_bfd, &outrel, loc);
252b5132 6871 }
f21f3fe0 6872
252b5132
RH
6873 local_got_offsets[r_symndx] |= 1;
6874 }
f21f3fe0 6875
252b5132
RH
6876 value = sgot->output_offset + off;
6877 }
eb043451
PB
6878 if (r_type != R_ARM_GOT32)
6879 value += sgot->output_section->vma;
9a5aca8c 6880
f21f3fe0 6881 return _bfd_final_link_relocate (howto, input_bfd, input_section,
99e4ae17 6882 contents, rel->r_offset, value,
00a97672 6883 rel->r_addend);
f21f3fe0 6884
ba93b8ac
DJ
6885 case R_ARM_TLS_LDO32:
6886 value = value - dtpoff_base (info);
6887
6888 return _bfd_final_link_relocate (howto, input_bfd, input_section,
00a97672
RS
6889 contents, rel->r_offset, value,
6890 rel->r_addend);
ba93b8ac
DJ
6891
6892 case R_ARM_TLS_LDM32:
6893 {
6894 bfd_vma off;
6895
6896 if (globals->sgot == NULL)
6897 abort ();
6898
6899 off = globals->tls_ldm_got.offset;
6900
6901 if ((off & 1) != 0)
6902 off &= ~1;
6903 else
6904 {
6905 /* If we don't know the module number, create a relocation
6906 for it. */
6907 if (info->shared)
6908 {
6909 Elf_Internal_Rela outrel;
6910 bfd_byte *loc;
6911
6912 if (globals->srelgot == NULL)
6913 abort ();
6914
00a97672 6915 outrel.r_addend = 0;
ba93b8ac
DJ
6916 outrel.r_offset = (globals->sgot->output_section->vma
6917 + globals->sgot->output_offset + off);
6918 outrel.r_info = ELF32_R_INFO (0, R_ARM_TLS_DTPMOD32);
6919
00a97672
RS
6920 if (globals->use_rel)
6921 bfd_put_32 (output_bfd, outrel.r_addend,
6922 globals->sgot->contents + off);
ba93b8ac
DJ
6923
6924 loc = globals->srelgot->contents;
00a97672
RS
6925 loc += globals->srelgot->reloc_count++ * RELOC_SIZE (globals);
6926 SWAP_RELOC_OUT (globals) (output_bfd, &outrel, loc);
ba93b8ac
DJ
6927 }
6928 else
6929 bfd_put_32 (output_bfd, 1, globals->sgot->contents + off);
6930
6931 globals->tls_ldm_got.offset |= 1;
6932 }
6933
906e58ca 6934 value = globals->sgot->output_section->vma + globals->sgot->output_offset + off
ba93b8ac
DJ
6935 - (input_section->output_section->vma + input_section->output_offset + rel->r_offset);
6936
6937 return _bfd_final_link_relocate (howto, input_bfd, input_section,
6938 contents, rel->r_offset, value,
00a97672 6939 rel->r_addend);
ba93b8ac
DJ
6940 }
6941
6942 case R_ARM_TLS_GD32:
6943 case R_ARM_TLS_IE32:
6944 {
6945 bfd_vma off;
6946 int indx;
6947 char tls_type;
6948
6949 if (globals->sgot == NULL)
6950 abort ();
6951
6952 indx = 0;
6953 if (h != NULL)
6954 {
6955 bfd_boolean dyn;
6956 dyn = globals->root.dynamic_sections_created;
6957 if (WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn, info->shared, h)
6958 && (!info->shared
6959 || !SYMBOL_REFERENCES_LOCAL (info, h)))
6960 {
6961 *unresolved_reloc_p = FALSE;
6962 indx = h->dynindx;
6963 }
6964 off = h->got.offset;
6965 tls_type = ((struct elf32_arm_link_hash_entry *) h)->tls_type;
6966 }
6967 else
6968 {
6969 if (local_got_offsets == NULL)
6970 abort ();
6971 off = local_got_offsets[r_symndx];
6972 tls_type = elf32_arm_local_got_tls_type (input_bfd)[r_symndx];
6973 }
6974
6975 if (tls_type == GOT_UNKNOWN)
6976 abort ();
6977
6978 if ((off & 1) != 0)
6979 off &= ~1;
6980 else
6981 {
6982 bfd_boolean need_relocs = FALSE;
6983 Elf_Internal_Rela outrel;
6984 bfd_byte *loc = NULL;
6985 int cur_off = off;
6986
6987 /* The GOT entries have not been initialized yet. Do it
6988 now, and emit any relocations. If both an IE GOT and a
6989 GD GOT are necessary, we emit the GD first. */
6990
6991 if ((info->shared || indx != 0)
6992 && (h == NULL
6993 || ELF_ST_VISIBILITY (h->other) == STV_DEFAULT
6994 || h->root.type != bfd_link_hash_undefweak))
6995 {
6996 need_relocs = TRUE;
6997 if (globals->srelgot == NULL)
6998 abort ();
6999 loc = globals->srelgot->contents;
00a97672 7000 loc += globals->srelgot->reloc_count * RELOC_SIZE (globals);
ba93b8ac
DJ
7001 }
7002
7003 if (tls_type & GOT_TLS_GD)
7004 {
7005 if (need_relocs)
7006 {
00a97672 7007 outrel.r_addend = 0;
ba93b8ac 7008 outrel.r_offset = (globals->sgot->output_section->vma
00a97672
RS
7009 + globals->sgot->output_offset
7010 + cur_off);
ba93b8ac 7011 outrel.r_info = ELF32_R_INFO (indx, R_ARM_TLS_DTPMOD32);
ba93b8ac 7012
00a97672
RS
7013 if (globals->use_rel)
7014 bfd_put_32 (output_bfd, outrel.r_addend,
7015 globals->sgot->contents + cur_off);
7016
7017 SWAP_RELOC_OUT (globals) (output_bfd, &outrel, loc);
ba93b8ac 7018 globals->srelgot->reloc_count++;
00a97672 7019 loc += RELOC_SIZE (globals);
ba93b8ac
DJ
7020
7021 if (indx == 0)
7022 bfd_put_32 (output_bfd, value - dtpoff_base (info),
7023 globals->sgot->contents + cur_off + 4);
7024 else
7025 {
00a97672 7026 outrel.r_addend = 0;
ba93b8ac
DJ
7027 outrel.r_info = ELF32_R_INFO (indx,
7028 R_ARM_TLS_DTPOFF32);
7029 outrel.r_offset += 4;
00a97672
RS
7030
7031 if (globals->use_rel)
7032 bfd_put_32 (output_bfd, outrel.r_addend,
7033 globals->sgot->contents + cur_off + 4);
7034
7035
7036 SWAP_RELOC_OUT (globals) (output_bfd, &outrel, loc);
ba93b8ac 7037 globals->srelgot->reloc_count++;
00a97672 7038 loc += RELOC_SIZE (globals);
ba93b8ac
DJ
7039 }
7040 }
7041 else
7042 {
7043 /* If we are not emitting relocations for a
7044 general dynamic reference, then we must be in a
7045 static link or an executable link with the
7046 symbol binding locally. Mark it as belonging
7047 to module 1, the executable. */
7048 bfd_put_32 (output_bfd, 1,
7049 globals->sgot->contents + cur_off);
7050 bfd_put_32 (output_bfd, value - dtpoff_base (info),
7051 globals->sgot->contents + cur_off + 4);
7052 }
7053
7054 cur_off += 8;
7055 }
7056
7057 if (tls_type & GOT_TLS_IE)
7058 {
7059 if (need_relocs)
7060 {
00a97672
RS
7061 if (indx == 0)
7062 outrel.r_addend = value - dtpoff_base (info);
7063 else
7064 outrel.r_addend = 0;
ba93b8ac
DJ
7065 outrel.r_offset = (globals->sgot->output_section->vma
7066 + globals->sgot->output_offset
7067 + cur_off);
7068 outrel.r_info = ELF32_R_INFO (indx, R_ARM_TLS_TPOFF32);
7069
00a97672
RS
7070 if (globals->use_rel)
7071 bfd_put_32 (output_bfd, outrel.r_addend,
ba93b8ac
DJ
7072 globals->sgot->contents + cur_off);
7073
00a97672 7074 SWAP_RELOC_OUT (globals) (output_bfd, &outrel, loc);
ba93b8ac 7075 globals->srelgot->reloc_count++;
00a97672 7076 loc += RELOC_SIZE (globals);
ba93b8ac
DJ
7077 }
7078 else
7079 bfd_put_32 (output_bfd, tpoff (info, value),
7080 globals->sgot->contents + cur_off);
7081 cur_off += 4;
7082 }
7083
7084 if (h != NULL)
7085 h->got.offset |= 1;
7086 else
7087 local_got_offsets[r_symndx] |= 1;
7088 }
7089
7090 if ((tls_type & GOT_TLS_GD) && r_type != R_ARM_TLS_GD32)
7091 off += 8;
906e58ca 7092 value = globals->sgot->output_section->vma + globals->sgot->output_offset + off
ba93b8ac
DJ
7093 - (input_section->output_section->vma + input_section->output_offset + rel->r_offset);
7094
7095 return _bfd_final_link_relocate (howto, input_bfd, input_section,
7096 contents, rel->r_offset, value,
00a97672 7097 rel->r_addend);
ba93b8ac
DJ
7098 }
7099
7100 case R_ARM_TLS_LE32:
7101 if (info->shared)
7102 {
7103 (*_bfd_error_handler)
7104 (_("%B(%A+0x%lx): R_ARM_TLS_LE32 relocation not permitted in shared object"),
7105 input_bfd, input_section,
7106 (long) rel->r_offset, howto->name);
906e58ca 7107 return FALSE;
ba93b8ac
DJ
7108 }
7109 else
7110 value = tpoff (info, value);
906e58ca 7111
ba93b8ac 7112 return _bfd_final_link_relocate (howto, input_bfd, input_section,
00a97672
RS
7113 contents, rel->r_offset, value,
7114 rel->r_addend);
ba93b8ac 7115
319850b4
JB
7116 case R_ARM_V4BX:
7117 if (globals->fix_v4bx)
845b51d6
PB
7118 {
7119 bfd_vma insn = bfd_get_32 (input_bfd, hit_data);
319850b4 7120
845b51d6
PB
7121 /* Ensure that we have a BX instruction. */
7122 BFD_ASSERT ((insn & 0x0ffffff0) == 0x012fff10);
319850b4 7123
845b51d6
PB
7124 if (globals->fix_v4bx == 2 && (insn & 0xf) != 0xf)
7125 {
7126 /* Branch to veneer. */
7127 bfd_vma glue_addr;
7128 glue_addr = elf32_arm_bx_glue (info, insn & 0xf);
7129 glue_addr -= input_section->output_section->vma
7130 + input_section->output_offset
7131 + rel->r_offset + 8;
7132 insn = (insn & 0xf0000000) | 0x0a000000
7133 | ((glue_addr >> 2) & 0x00ffffff);
7134 }
7135 else
7136 {
7137 /* Preserve Rm (lowest four bits) and the condition code
7138 (highest four bits). Other bits encode MOV PC,Rm. */
7139 insn = (insn & 0xf000000f) | 0x01a0f000;
7140 }
319850b4 7141
845b51d6
PB
7142 bfd_put_32 (input_bfd, insn, hit_data);
7143 }
319850b4
JB
7144 return bfd_reloc_ok;
7145
b6895b4f
PB
7146 case R_ARM_MOVW_ABS_NC:
7147 case R_ARM_MOVT_ABS:
7148 case R_ARM_MOVW_PREL_NC:
7149 case R_ARM_MOVT_PREL:
92f5d02b
MS
7150 /* Until we properly support segment-base-relative addressing then
7151 we assume the segment base to be zero, as for the group relocations.
7152 Thus R_ARM_MOVW_BREL_NC has the same semantics as R_ARM_MOVW_ABS_NC
7153 and R_ARM_MOVT_BREL has the same semantics as R_ARM_MOVT_ABS. */
7154 case R_ARM_MOVW_BREL_NC:
7155 case R_ARM_MOVW_BREL:
7156 case R_ARM_MOVT_BREL:
b6895b4f
PB
7157 {
7158 bfd_vma insn = bfd_get_32 (input_bfd, hit_data);
7159
7160 if (globals->use_rel)
7161 {
7162 addend = ((insn >> 4) & 0xf000) | (insn & 0xfff);
39623e12 7163 signed_addend = (addend ^ 0x8000) - 0x8000;
b6895b4f 7164 }
92f5d02b 7165
b6895b4f 7166 value += signed_addend;
b6895b4f
PB
7167
7168 if (r_type == R_ARM_MOVW_PREL_NC || r_type == R_ARM_MOVT_PREL)
7169 value -= (input_section->output_section->vma
7170 + input_section->output_offset + rel->r_offset);
7171
92f5d02b
MS
7172 if (r_type == R_ARM_MOVW_BREL && value >= 0x10000)
7173 return bfd_reloc_overflow;
7174
7175 if (sym_flags == STT_ARM_TFUNC)
7176 value |= 1;
7177
7178 if (r_type == R_ARM_MOVT_ABS || r_type == R_ARM_MOVT_PREL
7179 || r_type == R_ARM_MOVT_BREL)
b6895b4f
PB
7180 value >>= 16;
7181
7182 insn &= 0xfff0f000;
7183 insn |= value & 0xfff;
7184 insn |= (value & 0xf000) << 4;
7185 bfd_put_32 (input_bfd, insn, hit_data);
7186 }
7187 return bfd_reloc_ok;
7188
7189 case R_ARM_THM_MOVW_ABS_NC:
7190 case R_ARM_THM_MOVT_ABS:
7191 case R_ARM_THM_MOVW_PREL_NC:
7192 case R_ARM_THM_MOVT_PREL:
92f5d02b
MS
7193 /* Until we properly support segment-base-relative addressing then
7194 we assume the segment base to be zero, as for the above relocations.
7195 Thus R_ARM_THM_MOVW_BREL_NC has the same semantics as
7196 R_ARM_THM_MOVW_ABS_NC and R_ARM_THM_MOVT_BREL has the same semantics
7197 as R_ARM_THM_MOVT_ABS. */
7198 case R_ARM_THM_MOVW_BREL_NC:
7199 case R_ARM_THM_MOVW_BREL:
7200 case R_ARM_THM_MOVT_BREL:
b6895b4f
PB
7201 {
7202 bfd_vma insn;
906e58ca 7203
b6895b4f
PB
7204 insn = bfd_get_16 (input_bfd, hit_data) << 16;
7205 insn |= bfd_get_16 (input_bfd, hit_data + 2);
7206
7207 if (globals->use_rel)
7208 {
7209 addend = ((insn >> 4) & 0xf000)
7210 | ((insn >> 15) & 0x0800)
7211 | ((insn >> 4) & 0x0700)
7212 | (insn & 0x00ff);
39623e12 7213 signed_addend = (addend ^ 0x8000) - 0x8000;
b6895b4f 7214 }
92f5d02b 7215
b6895b4f 7216 value += signed_addend;
b6895b4f
PB
7217
7218 if (r_type == R_ARM_THM_MOVW_PREL_NC || r_type == R_ARM_THM_MOVT_PREL)
7219 value -= (input_section->output_section->vma
7220 + input_section->output_offset + rel->r_offset);
7221
92f5d02b
MS
7222 if (r_type == R_ARM_THM_MOVW_BREL && value >= 0x10000)
7223 return bfd_reloc_overflow;
7224
7225 if (sym_flags == STT_ARM_TFUNC)
7226 value |= 1;
7227
7228 if (r_type == R_ARM_THM_MOVT_ABS || r_type == R_ARM_THM_MOVT_PREL
7229 || r_type == R_ARM_THM_MOVT_BREL)
b6895b4f
PB
7230 value >>= 16;
7231
7232 insn &= 0xfbf08f00;
7233 insn |= (value & 0xf000) << 4;
7234 insn |= (value & 0x0800) << 15;
7235 insn |= (value & 0x0700) << 4;
7236 insn |= (value & 0x00ff);
7237
7238 bfd_put_16 (input_bfd, insn >> 16, hit_data);
7239 bfd_put_16 (input_bfd, insn & 0xffff, hit_data + 2);
7240 }
7241 return bfd_reloc_ok;
7242
4962c51a
MS
7243 case R_ARM_ALU_PC_G0_NC:
7244 case R_ARM_ALU_PC_G1_NC:
7245 case R_ARM_ALU_PC_G0:
7246 case R_ARM_ALU_PC_G1:
7247 case R_ARM_ALU_PC_G2:
7248 case R_ARM_ALU_SB_G0_NC:
7249 case R_ARM_ALU_SB_G1_NC:
7250 case R_ARM_ALU_SB_G0:
7251 case R_ARM_ALU_SB_G1:
7252 case R_ARM_ALU_SB_G2:
7253 {
7254 bfd_vma insn = bfd_get_32 (input_bfd, hit_data);
7255 bfd_vma pc = input_section->output_section->vma
7256 + input_section->output_offset + rel->r_offset;
7257 /* sb should be the origin of the *segment* containing the symbol.
7258 It is not clear how to obtain this OS-dependent value, so we
7259 make an arbitrary choice of zero. */
7260 bfd_vma sb = 0;
7261 bfd_vma residual;
7262 bfd_vma g_n;
7263 bfd_signed_vma signed_value;
7264 int group = 0;
7265
7266 /* Determine which group of bits to select. */
7267 switch (r_type)
7268 {
7269 case R_ARM_ALU_PC_G0_NC:
7270 case R_ARM_ALU_PC_G0:
7271 case R_ARM_ALU_SB_G0_NC:
7272 case R_ARM_ALU_SB_G0:
7273 group = 0;
7274 break;
7275
7276 case R_ARM_ALU_PC_G1_NC:
7277 case R_ARM_ALU_PC_G1:
7278 case R_ARM_ALU_SB_G1_NC:
7279 case R_ARM_ALU_SB_G1:
7280 group = 1;
7281 break;
7282
7283 case R_ARM_ALU_PC_G2:
7284 case R_ARM_ALU_SB_G2:
7285 group = 2;
7286 break;
7287
7288 default:
906e58ca 7289 abort ();
4962c51a
MS
7290 }
7291
7292 /* If REL, extract the addend from the insn. If RELA, it will
7293 have already been fetched for us. */
7294 if (globals->use_rel)
7295 {
7296 int negative;
7297 bfd_vma constant = insn & 0xff;
7298 bfd_vma rotation = (insn & 0xf00) >> 8;
7299
7300 if (rotation == 0)
7301 signed_addend = constant;
7302 else
7303 {
7304 /* Compensate for the fact that in the instruction, the
7305 rotation is stored in multiples of 2 bits. */
7306 rotation *= 2;
7307
7308 /* Rotate "constant" right by "rotation" bits. */
7309 signed_addend = (constant >> rotation) |
7310 (constant << (8 * sizeof (bfd_vma) - rotation));
7311 }
7312
7313 /* Determine if the instruction is an ADD or a SUB.
7314 (For REL, this determines the sign of the addend.) */
7315 negative = identify_add_or_sub (insn);
7316 if (negative == 0)
7317 {
7318 (*_bfd_error_handler)
7319 (_("%B(%A+0x%lx): Only ADD or SUB instructions are allowed for ALU group relocations"),
7320 input_bfd, input_section,
7321 (long) rel->r_offset, howto->name);
906e58ca 7322 return bfd_reloc_overflow;
4962c51a
MS
7323 }
7324
7325 signed_addend *= negative;
7326 }
7327
7328 /* Compute the value (X) to go in the place. */
7329 if (r_type == R_ARM_ALU_PC_G0_NC
7330 || r_type == R_ARM_ALU_PC_G1_NC
7331 || r_type == R_ARM_ALU_PC_G0
7332 || r_type == R_ARM_ALU_PC_G1
7333 || r_type == R_ARM_ALU_PC_G2)
7334 /* PC relative. */
7335 signed_value = value - pc + signed_addend;
7336 else
7337 /* Section base relative. */
7338 signed_value = value - sb + signed_addend;
7339
7340 /* If the target symbol is a Thumb function, then set the
7341 Thumb bit in the address. */
7342 if (sym_flags == STT_ARM_TFUNC)
7343 signed_value |= 1;
7344
7345 /* Calculate the value of the relevant G_n, in encoded
7346 constant-with-rotation format. */
7347 g_n = calculate_group_reloc_mask (abs (signed_value), group,
7348 &residual);
7349
7350 /* Check for overflow if required. */
7351 if ((r_type == R_ARM_ALU_PC_G0
7352 || r_type == R_ARM_ALU_PC_G1
7353 || r_type == R_ARM_ALU_PC_G2
7354 || r_type == R_ARM_ALU_SB_G0
7355 || r_type == R_ARM_ALU_SB_G1
7356 || r_type == R_ARM_ALU_SB_G2) && residual != 0)
7357 {
7358 (*_bfd_error_handler)
7359 (_("%B(%A+0x%lx): Overflow whilst splitting 0x%lx for group relocation %s"),
7360 input_bfd, input_section,
7361 (long) rel->r_offset, abs (signed_value), howto->name);
7362 return bfd_reloc_overflow;
7363 }
7364
7365 /* Mask out the value and the ADD/SUB part of the opcode; take care
7366 not to destroy the S bit. */
7367 insn &= 0xff1ff000;
7368
7369 /* Set the opcode according to whether the value to go in the
7370 place is negative. */
7371 if (signed_value < 0)
7372 insn |= 1 << 22;
7373 else
7374 insn |= 1 << 23;
7375
7376 /* Encode the offset. */
7377 insn |= g_n;
7378
7379 bfd_put_32 (input_bfd, insn, hit_data);
7380 }
7381 return bfd_reloc_ok;
7382
7383 case R_ARM_LDR_PC_G0:
7384 case R_ARM_LDR_PC_G1:
7385 case R_ARM_LDR_PC_G2:
7386 case R_ARM_LDR_SB_G0:
7387 case R_ARM_LDR_SB_G1:
7388 case R_ARM_LDR_SB_G2:
7389 {
7390 bfd_vma insn = bfd_get_32 (input_bfd, hit_data);
7391 bfd_vma pc = input_section->output_section->vma
7392 + input_section->output_offset + rel->r_offset;
7393 bfd_vma sb = 0; /* See note above. */
7394 bfd_vma residual;
7395 bfd_signed_vma signed_value;
7396 int group = 0;
7397
7398 /* Determine which groups of bits to calculate. */
7399 switch (r_type)
7400 {
7401 case R_ARM_LDR_PC_G0:
7402 case R_ARM_LDR_SB_G0:
7403 group = 0;
7404 break;
7405
7406 case R_ARM_LDR_PC_G1:
7407 case R_ARM_LDR_SB_G1:
7408 group = 1;
7409 break;
7410
7411 case R_ARM_LDR_PC_G2:
7412 case R_ARM_LDR_SB_G2:
7413 group = 2;
7414 break;
7415
7416 default:
906e58ca 7417 abort ();
4962c51a
MS
7418 }
7419
7420 /* If REL, extract the addend from the insn. If RELA, it will
7421 have already been fetched for us. */
7422 if (globals->use_rel)
7423 {
7424 int negative = (insn & (1 << 23)) ? 1 : -1;
7425 signed_addend = negative * (insn & 0xfff);
7426 }
7427
7428 /* Compute the value (X) to go in the place. */
7429 if (r_type == R_ARM_LDR_PC_G0
7430 || r_type == R_ARM_LDR_PC_G1
7431 || r_type == R_ARM_LDR_PC_G2)
7432 /* PC relative. */
7433 signed_value = value - pc + signed_addend;
7434 else
7435 /* Section base relative. */
7436 signed_value = value - sb + signed_addend;
7437
7438 /* Calculate the value of the relevant G_{n-1} to obtain
7439 the residual at that stage. */
7440 calculate_group_reloc_mask (abs (signed_value), group - 1, &residual);
7441
7442 /* Check for overflow. */
7443 if (residual >= 0x1000)
7444 {
7445 (*_bfd_error_handler)
7446 (_("%B(%A+0x%lx): Overflow whilst splitting 0x%lx for group relocation %s"),
7447 input_bfd, input_section,
7448 (long) rel->r_offset, abs (signed_value), howto->name);
7449 return bfd_reloc_overflow;
7450 }
7451
7452 /* Mask out the value and U bit. */
7453 insn &= 0xff7ff000;
7454
7455 /* Set the U bit if the value to go in the place is non-negative. */
7456 if (signed_value >= 0)
7457 insn |= 1 << 23;
7458
7459 /* Encode the offset. */
7460 insn |= residual;
7461
7462 bfd_put_32 (input_bfd, insn, hit_data);
7463 }
7464 return bfd_reloc_ok;
7465
7466 case R_ARM_LDRS_PC_G0:
7467 case R_ARM_LDRS_PC_G1:
7468 case R_ARM_LDRS_PC_G2:
7469 case R_ARM_LDRS_SB_G0:
7470 case R_ARM_LDRS_SB_G1:
7471 case R_ARM_LDRS_SB_G2:
7472 {
7473 bfd_vma insn = bfd_get_32 (input_bfd, hit_data);
7474 bfd_vma pc = input_section->output_section->vma
7475 + input_section->output_offset + rel->r_offset;
7476 bfd_vma sb = 0; /* See note above. */
7477 bfd_vma residual;
7478 bfd_signed_vma signed_value;
7479 int group = 0;
7480
7481 /* Determine which groups of bits to calculate. */
7482 switch (r_type)
7483 {
7484 case R_ARM_LDRS_PC_G0:
7485 case R_ARM_LDRS_SB_G0:
7486 group = 0;
7487 break;
7488
7489 case R_ARM_LDRS_PC_G1:
7490 case R_ARM_LDRS_SB_G1:
7491 group = 1;
7492 break;
7493
7494 case R_ARM_LDRS_PC_G2:
7495 case R_ARM_LDRS_SB_G2:
7496 group = 2;
7497 break;
7498
7499 default:
906e58ca 7500 abort ();
4962c51a
MS
7501 }
7502
7503 /* If REL, extract the addend from the insn. If RELA, it will
7504 have already been fetched for us. */
7505 if (globals->use_rel)
7506 {
7507 int negative = (insn & (1 << 23)) ? 1 : -1;
7508 signed_addend = negative * (((insn & 0xf00) >> 4) + (insn & 0xf));
7509 }
7510
7511 /* Compute the value (X) to go in the place. */
7512 if (r_type == R_ARM_LDRS_PC_G0
7513 || r_type == R_ARM_LDRS_PC_G1
7514 || r_type == R_ARM_LDRS_PC_G2)
7515 /* PC relative. */
7516 signed_value = value - pc + signed_addend;
7517 else
7518 /* Section base relative. */
7519 signed_value = value - sb + signed_addend;
7520
7521 /* Calculate the value of the relevant G_{n-1} to obtain
7522 the residual at that stage. */
7523 calculate_group_reloc_mask (abs (signed_value), group - 1, &residual);
7524
7525 /* Check for overflow. */
7526 if (residual >= 0x100)
7527 {
7528 (*_bfd_error_handler)
7529 (_("%B(%A+0x%lx): Overflow whilst splitting 0x%lx for group relocation %s"),
7530 input_bfd, input_section,
7531 (long) rel->r_offset, abs (signed_value), howto->name);
7532 return bfd_reloc_overflow;
7533 }
7534
7535 /* Mask out the value and U bit. */
7536 insn &= 0xff7ff0f0;
7537
7538 /* Set the U bit if the value to go in the place is non-negative. */
7539 if (signed_value >= 0)
7540 insn |= 1 << 23;
7541
7542 /* Encode the offset. */
7543 insn |= ((residual & 0xf0) << 4) | (residual & 0xf);
7544
7545 bfd_put_32 (input_bfd, insn, hit_data);
7546 }
7547 return bfd_reloc_ok;
7548
7549 case R_ARM_LDC_PC_G0:
7550 case R_ARM_LDC_PC_G1:
7551 case R_ARM_LDC_PC_G2:
7552 case R_ARM_LDC_SB_G0:
7553 case R_ARM_LDC_SB_G1:
7554 case R_ARM_LDC_SB_G2:
7555 {
7556 bfd_vma insn = bfd_get_32 (input_bfd, hit_data);
7557 bfd_vma pc = input_section->output_section->vma
7558 + input_section->output_offset + rel->r_offset;
7559 bfd_vma sb = 0; /* See note above. */
7560 bfd_vma residual;
7561 bfd_signed_vma signed_value;
7562 int group = 0;
7563
7564 /* Determine which groups of bits to calculate. */
7565 switch (r_type)
7566 {
7567 case R_ARM_LDC_PC_G0:
7568 case R_ARM_LDC_SB_G0:
7569 group = 0;
7570 break;
7571
7572 case R_ARM_LDC_PC_G1:
7573 case R_ARM_LDC_SB_G1:
7574 group = 1;
7575 break;
7576
7577 case R_ARM_LDC_PC_G2:
7578 case R_ARM_LDC_SB_G2:
7579 group = 2;
7580 break;
7581
7582 default:
906e58ca 7583 abort ();
4962c51a
MS
7584 }
7585
7586 /* If REL, extract the addend from the insn. If RELA, it will
7587 have already been fetched for us. */
7588 if (globals->use_rel)
7589 {
7590 int negative = (insn & (1 << 23)) ? 1 : -1;
7591 signed_addend = negative * ((insn & 0xff) << 2);
7592 }
7593
7594 /* Compute the value (X) to go in the place. */
7595 if (r_type == R_ARM_LDC_PC_G0
7596 || r_type == R_ARM_LDC_PC_G1
7597 || r_type == R_ARM_LDC_PC_G2)
7598 /* PC relative. */
7599 signed_value = value - pc + signed_addend;
7600 else
7601 /* Section base relative. */
7602 signed_value = value - sb + signed_addend;
7603
7604 /* Calculate the value of the relevant G_{n-1} to obtain
7605 the residual at that stage. */
7606 calculate_group_reloc_mask (abs (signed_value), group - 1, &residual);
7607
7608 /* Check for overflow. (The absolute value to go in the place must be
7609 divisible by four and, after having been divided by four, must
7610 fit in eight bits.) */
7611 if ((residual & 0x3) != 0 || residual >= 0x400)
7612 {
7613 (*_bfd_error_handler)
7614 (_("%B(%A+0x%lx): Overflow whilst splitting 0x%lx for group relocation %s"),
7615 input_bfd, input_section,
7616 (long) rel->r_offset, abs (signed_value), howto->name);
7617 return bfd_reloc_overflow;
7618 }
7619
7620 /* Mask out the value and U bit. */
7621 insn &= 0xff7fff00;
7622
7623 /* Set the U bit if the value to go in the place is non-negative. */
7624 if (signed_value >= 0)
7625 insn |= 1 << 23;
7626
7627 /* Encode the offset. */
7628 insn |= residual >> 2;
7629
7630 bfd_put_32 (input_bfd, insn, hit_data);
7631 }
7632 return bfd_reloc_ok;
7633
252b5132
RH
7634 default:
7635 return bfd_reloc_notsupported;
7636 }
7637}
7638
98c1d4aa
NC
7639/* Add INCREMENT to the reloc (of type HOWTO) at ADDRESS. */
7640static void
57e8b36a
NC
7641arm_add_to_rel (bfd * abfd,
7642 bfd_byte * address,
7643 reloc_howto_type * howto,
7644 bfd_signed_vma increment)
98c1d4aa 7645{
98c1d4aa
NC
7646 bfd_signed_vma addend;
7647
bd97cb95
DJ
7648 if (howto->type == R_ARM_THM_CALL
7649 || howto->type == R_ARM_THM_JUMP24)
98c1d4aa 7650 {
9a5aca8c
AM
7651 int upper_insn, lower_insn;
7652 int upper, lower;
98c1d4aa 7653
9a5aca8c
AM
7654 upper_insn = bfd_get_16 (abfd, address);
7655 lower_insn = bfd_get_16 (abfd, address + 2);
7656 upper = upper_insn & 0x7ff;
7657 lower = lower_insn & 0x7ff;
7658
7659 addend = (upper << 12) | (lower << 1);
ddda4409 7660 addend += increment;
9a5aca8c 7661 addend >>= 1;
98c1d4aa 7662
9a5aca8c
AM
7663 upper_insn = (upper_insn & 0xf800) | ((addend >> 11) & 0x7ff);
7664 lower_insn = (lower_insn & 0xf800) | (addend & 0x7ff);
7665
dc810e39
AM
7666 bfd_put_16 (abfd, (bfd_vma) upper_insn, address);
7667 bfd_put_16 (abfd, (bfd_vma) lower_insn, address + 2);
9a5aca8c
AM
7668 }
7669 else
7670 {
7671 bfd_vma contents;
7672
7673 contents = bfd_get_32 (abfd, address);
7674
7675 /* Get the (signed) value from the instruction. */
7676 addend = contents & howto->src_mask;
7677 if (addend & ((howto->src_mask + 1) >> 1))
7678 {
7679 bfd_signed_vma mask;
7680
7681 mask = -1;
7682 mask &= ~ howto->src_mask;
7683 addend |= mask;
7684 }
7685
7686 /* Add in the increment, (which is a byte value). */
7687 switch (howto->type)
7688 {
7689 default:
7690 addend += increment;
7691 break;
7692
7693 case R_ARM_PC24:
c6596c5e 7694 case R_ARM_PLT32:
5b5bb741
PB
7695 case R_ARM_CALL:
7696 case R_ARM_JUMP24:
9a5aca8c 7697 addend <<= howto->size;
dc810e39 7698 addend += increment;
9a5aca8c
AM
7699
7700 /* Should we check for overflow here ? */
7701
7702 /* Drop any undesired bits. */
7703 addend >>= howto->rightshift;
7704 break;
7705 }
7706
7707 contents = (contents & ~ howto->dst_mask) | (addend & howto->dst_mask);
7708
7709 bfd_put_32 (abfd, contents, address);
ddda4409 7710 }
98c1d4aa 7711}
252b5132 7712
ba93b8ac
DJ
7713#define IS_ARM_TLS_RELOC(R_TYPE) \
7714 ((R_TYPE) == R_ARM_TLS_GD32 \
7715 || (R_TYPE) == R_ARM_TLS_LDO32 \
7716 || (R_TYPE) == R_ARM_TLS_LDM32 \
7717 || (R_TYPE) == R_ARM_TLS_DTPOFF32 \
7718 || (R_TYPE) == R_ARM_TLS_DTPMOD32 \
7719 || (R_TYPE) == R_ARM_TLS_TPOFF32 \
7720 || (R_TYPE) == R_ARM_TLS_LE32 \
7721 || (R_TYPE) == R_ARM_TLS_IE32)
7722
252b5132 7723/* Relocate an ARM ELF section. */
906e58ca 7724
b34976b6 7725static bfd_boolean
57e8b36a
NC
7726elf32_arm_relocate_section (bfd * output_bfd,
7727 struct bfd_link_info * info,
7728 bfd * input_bfd,
7729 asection * input_section,
7730 bfd_byte * contents,
7731 Elf_Internal_Rela * relocs,
7732 Elf_Internal_Sym * local_syms,
7733 asection ** local_sections)
252b5132 7734{
b34976b6
AM
7735 Elf_Internal_Shdr *symtab_hdr;
7736 struct elf_link_hash_entry **sym_hashes;
7737 Elf_Internal_Rela *rel;
7738 Elf_Internal_Rela *relend;
7739 const char *name;
b32d3aa2 7740 struct elf32_arm_link_hash_table * globals;
252b5132 7741
4e7fd91e 7742 globals = elf32_arm_hash_table (info);
b491616a 7743
0ffa91dd 7744 symtab_hdr = & elf_symtab_hdr (input_bfd);
252b5132
RH
7745 sym_hashes = elf_sym_hashes (input_bfd);
7746
7747 rel = relocs;
7748 relend = relocs + input_section->reloc_count;
7749 for (; rel < relend; rel++)
7750 {
ba96a88f
NC
7751 int r_type;
7752 reloc_howto_type * howto;
7753 unsigned long r_symndx;
7754 Elf_Internal_Sym * sym;
7755 asection * sec;
252b5132 7756 struct elf_link_hash_entry * h;
ba96a88f
NC
7757 bfd_vma relocation;
7758 bfd_reloc_status_type r;
7759 arelent bfd_reloc;
ba93b8ac 7760 char sym_type;
0945cdfd 7761 bfd_boolean unresolved_reloc = FALSE;
f2a9dd69 7762 char *error_message = NULL;
f21f3fe0 7763
252b5132 7764 r_symndx = ELF32_R_SYM (rel->r_info);
ba96a88f 7765 r_type = ELF32_R_TYPE (rel->r_info);
b32d3aa2 7766 r_type = arm_real_reloc_type (globals, r_type);
252b5132 7767
ba96a88f
NC
7768 if ( r_type == R_ARM_GNU_VTENTRY
7769 || r_type == R_ARM_GNU_VTINHERIT)
252b5132
RH
7770 continue;
7771
b32d3aa2 7772 bfd_reloc.howto = elf32_arm_howto_from_type (r_type);
ba96a88f 7773 howto = bfd_reloc.howto;
252b5132 7774
252b5132
RH
7775 h = NULL;
7776 sym = NULL;
7777 sec = NULL;
9b485d32 7778
252b5132
RH
7779 if (r_symndx < symtab_hdr->sh_info)
7780 {
7781 sym = local_syms + r_symndx;
ba93b8ac 7782 sym_type = ELF32_ST_TYPE (sym->st_info);
252b5132 7783 sec = local_sections[r_symndx];
4e7fd91e 7784 if (globals->use_rel)
f8df10f4 7785 {
4e7fd91e
PB
7786 relocation = (sec->output_section->vma
7787 + sec->output_offset
7788 + sym->st_value);
ab96bf03
AM
7789 if (!info->relocatable
7790 && (sec->flags & SEC_MERGE)
7791 && ELF_ST_TYPE (sym->st_info) == STT_SECTION)
f8df10f4 7792 {
4e7fd91e
PB
7793 asection *msec;
7794 bfd_vma addend, value;
7795
39623e12 7796 switch (r_type)
4e7fd91e 7797 {
39623e12
PB
7798 case R_ARM_MOVW_ABS_NC:
7799 case R_ARM_MOVT_ABS:
7800 value = bfd_get_32 (input_bfd, contents + rel->r_offset);
7801 addend = ((value & 0xf0000) >> 4) | (value & 0xfff);
7802 addend = (addend ^ 0x8000) - 0x8000;
7803 break;
f8df10f4 7804
39623e12
PB
7805 case R_ARM_THM_MOVW_ABS_NC:
7806 case R_ARM_THM_MOVT_ABS:
7807 value = bfd_get_16 (input_bfd, contents + rel->r_offset)
7808 << 16;
7809 value |= bfd_get_16 (input_bfd,
7810 contents + rel->r_offset + 2);
7811 addend = ((value & 0xf7000) >> 4) | (value & 0xff)
7812 | ((value & 0x04000000) >> 15);
7813 addend = (addend ^ 0x8000) - 0x8000;
7814 break;
f8df10f4 7815
39623e12
PB
7816 default:
7817 if (howto->rightshift
7818 || (howto->src_mask & (howto->src_mask + 1)))
7819 {
7820 (*_bfd_error_handler)
7821 (_("%B(%A+0x%lx): %s relocation against SEC_MERGE section"),
7822 input_bfd, input_section,
7823 (long) rel->r_offset, howto->name);
7824 return FALSE;
7825 }
7826
7827 value = bfd_get_32 (input_bfd, contents + rel->r_offset);
7828
7829 /* Get the (signed) value from the instruction. */
7830 addend = value & howto->src_mask;
7831 if (addend & ((howto->src_mask + 1) >> 1))
7832 {
7833 bfd_signed_vma mask;
7834
7835 mask = -1;
7836 mask &= ~ howto->src_mask;
7837 addend |= mask;
7838 }
7839 break;
4e7fd91e 7840 }
39623e12 7841
4e7fd91e
PB
7842 msec = sec;
7843 addend =
7844 _bfd_elf_rel_local_sym (output_bfd, sym, &msec, addend)
7845 - relocation;
7846 addend += msec->output_section->vma + msec->output_offset;
39623e12
PB
7847
7848 /* Cases here must match those in the preceeding
7849 switch statement. */
7850 switch (r_type)
7851 {
7852 case R_ARM_MOVW_ABS_NC:
7853 case R_ARM_MOVT_ABS:
7854 value = (value & 0xfff0f000) | ((addend & 0xf000) << 4)
7855 | (addend & 0xfff);
7856 bfd_put_32 (input_bfd, value, contents + rel->r_offset);
7857 break;
7858
7859 case R_ARM_THM_MOVW_ABS_NC:
7860 case R_ARM_THM_MOVT_ABS:
7861 value = (value & 0xfbf08f00) | ((addend & 0xf700) << 4)
7862 | (addend & 0xff) | ((addend & 0x0800) << 15);
7863 bfd_put_16 (input_bfd, value >> 16,
7864 contents + rel->r_offset);
7865 bfd_put_16 (input_bfd, value,
7866 contents + rel->r_offset + 2);
7867 break;
7868
7869 default:
7870 value = (value & ~ howto->dst_mask)
7871 | (addend & howto->dst_mask);
7872 bfd_put_32 (input_bfd, value, contents + rel->r_offset);
7873 break;
7874 }
f8df10f4 7875 }
f8df10f4 7876 }
4e7fd91e
PB
7877 else
7878 relocation = _bfd_elf_rela_local_sym (output_bfd, sym, &sec, rel);
252b5132
RH
7879 }
7880 else
7881 {
560e09e9 7882 bfd_boolean warned;
560e09e9 7883
b2a8e766
AM
7884 RELOC_FOR_GLOBAL_SYMBOL (info, input_bfd, input_section, rel,
7885 r_symndx, symtab_hdr, sym_hashes,
7886 h, sec, relocation,
7887 unresolved_reloc, warned);
ba93b8ac
DJ
7888
7889 sym_type = h->type;
252b5132
RH
7890 }
7891
ab96bf03
AM
7892 if (sec != NULL && elf_discarded_section (sec))
7893 {
7894 /* For relocs against symbols from removed linkonce sections,
7895 or sections discarded by a linker script, we just want the
7896 section contents zeroed. Avoid any special processing. */
7897 _bfd_clear_contents (howto, input_bfd, contents + rel->r_offset);
7898 rel->r_info = 0;
7899 rel->r_addend = 0;
7900 continue;
7901 }
7902
7903 if (info->relocatable)
7904 {
7905 /* This is a relocatable link. We don't have to change
7906 anything, unless the reloc is against a section symbol,
7907 in which case we have to adjust according to where the
7908 section symbol winds up in the output section. */
7909 if (sym != NULL && ELF_ST_TYPE (sym->st_info) == STT_SECTION)
7910 {
7911 if (globals->use_rel)
7912 arm_add_to_rel (input_bfd, contents + rel->r_offset,
7913 howto, (bfd_signed_vma) sec->output_offset);
7914 else
7915 rel->r_addend += sec->output_offset;
7916 }
7917 continue;
7918 }
7919
252b5132
RH
7920 if (h != NULL)
7921 name = h->root.root.string;
7922 else
7923 {
7924 name = (bfd_elf_string_from_elf_section
7925 (input_bfd, symtab_hdr->sh_link, sym->st_name));
7926 if (name == NULL || *name == '\0')
7927 name = bfd_section_name (input_bfd, sec);
7928 }
f21f3fe0 7929
ba93b8ac
DJ
7930 if (r_symndx != 0
7931 && r_type != R_ARM_NONE
7932 && (h == NULL
7933 || h->root.type == bfd_link_hash_defined
7934 || h->root.type == bfd_link_hash_defweak)
7935 && IS_ARM_TLS_RELOC (r_type) != (sym_type == STT_TLS))
7936 {
7937 (*_bfd_error_handler)
7938 ((sym_type == STT_TLS
7939 ? _("%B(%A+0x%lx): %s used with TLS symbol %s")
7940 : _("%B(%A+0x%lx): %s used with non-TLS symbol %s")),
7941 input_bfd,
7942 input_section,
7943 (long) rel->r_offset,
7944 howto->name,
7945 name);
7946 }
7947
252b5132
RH
7948 r = elf32_arm_final_link_relocate (howto, input_bfd, output_bfd,
7949 input_section, contents, rel,
7950 relocation, info, sec, name,
7951 (h ? ELF_ST_TYPE (h->type) :
0945cdfd 7952 ELF_ST_TYPE (sym->st_info)), h,
f2a9dd69 7953 &unresolved_reloc, &error_message);
0945cdfd
DJ
7954
7955 /* Dynamic relocs are not propagated for SEC_DEBUGGING sections
7956 because such sections are not SEC_ALLOC and thus ld.so will
7957 not process them. */
7958 if (unresolved_reloc
7959 && !((input_section->flags & SEC_DEBUGGING) != 0
7960 && h->def_dynamic))
7961 {
7962 (*_bfd_error_handler)
843fe662
L
7963 (_("%B(%A+0x%lx): unresolvable %s relocation against symbol `%s'"),
7964 input_bfd,
7965 input_section,
7966 (long) rel->r_offset,
7967 howto->name,
7968 h->root.root.string);
0945cdfd
DJ
7969 return FALSE;
7970 }
252b5132
RH
7971
7972 if (r != bfd_reloc_ok)
7973 {
252b5132
RH
7974 switch (r)
7975 {
7976 case bfd_reloc_overflow:
cf919dfd
PB
7977 /* If the overflowing reloc was to an undefined symbol,
7978 we have already printed one error message and there
7979 is no point complaining again. */
7980 if ((! h ||
7981 h->root.type != bfd_link_hash_undefined)
7982 && (!((*info->callbacks->reloc_overflow)
dfeffb9f
L
7983 (info, (h ? &h->root : NULL), name, howto->name,
7984 (bfd_vma) 0, input_bfd, input_section,
7985 rel->r_offset))))
b34976b6 7986 return FALSE;
252b5132
RH
7987 break;
7988
7989 case bfd_reloc_undefined:
7990 if (!((*info->callbacks->undefined_symbol)
7991 (info, name, input_bfd, input_section,
b34976b6
AM
7992 rel->r_offset, TRUE)))
7993 return FALSE;
252b5132
RH
7994 break;
7995
7996 case bfd_reloc_outofrange:
f2a9dd69 7997 error_message = _("out of range");
252b5132
RH
7998 goto common_error;
7999
8000 case bfd_reloc_notsupported:
f2a9dd69 8001 error_message = _("unsupported relocation");
252b5132
RH
8002 goto common_error;
8003
8004 case bfd_reloc_dangerous:
f2a9dd69 8005 /* error_message should already be set. */
252b5132
RH
8006 goto common_error;
8007
8008 default:
f2a9dd69 8009 error_message = _("unknown error");
252b5132
RH
8010 /* fall through */
8011
8012 common_error:
f2a9dd69
DJ
8013 BFD_ASSERT (error_message != NULL);
8014 if (!((*info->callbacks->reloc_dangerous)
8015 (info, error_message, input_bfd, input_section,
252b5132 8016 rel->r_offset)))
b34976b6 8017 return FALSE;
252b5132
RH
8018 break;
8019 }
8020 }
8021 }
8022
b34976b6 8023 return TRUE;
252b5132
RH
8024}
8025
c178919b
NC
8026/* Set the right machine number. */
8027
8028static bfd_boolean
57e8b36a 8029elf32_arm_object_p (bfd *abfd)
c178919b 8030{
5a6c6817 8031 unsigned int mach;
57e8b36a 8032
5a6c6817 8033 mach = bfd_arm_get_mach_from_notes (abfd, ARM_NOTE_SECTION);
c178919b 8034
5a6c6817
NC
8035 if (mach != bfd_mach_arm_unknown)
8036 bfd_default_set_arch_mach (abfd, bfd_arch_arm, mach);
8037
8038 else if (elf_elfheader (abfd)->e_flags & EF_ARM_MAVERICK_FLOAT)
8039 bfd_default_set_arch_mach (abfd, bfd_arch_arm, bfd_mach_arm_ep9312);
e16bb312 8040
e16bb312 8041 else
5a6c6817 8042 bfd_default_set_arch_mach (abfd, bfd_arch_arm, mach);
c178919b
NC
8043
8044 return TRUE;
8045}
8046
fc830a83 8047/* Function to keep ARM specific flags in the ELF header. */
3c9458e9 8048
b34976b6 8049static bfd_boolean
57e8b36a 8050elf32_arm_set_private_flags (bfd *abfd, flagword flags)
252b5132
RH
8051{
8052 if (elf_flags_init (abfd)
8053 && elf_elfheader (abfd)->e_flags != flags)
8054 {
fc830a83
NC
8055 if (EF_ARM_EABI_VERSION (flags) == EF_ARM_EABI_UNKNOWN)
8056 {
fd2ec330 8057 if (flags & EF_ARM_INTERWORK)
d003868e
AM
8058 (*_bfd_error_handler)
8059 (_("Warning: Not setting interworking flag of %B since it has already been specified as non-interworking"),
8060 abfd);
fc830a83 8061 else
d003868e
AM
8062 _bfd_error_handler
8063 (_("Warning: Clearing the interworking flag of %B due to outside request"),
8064 abfd);
fc830a83 8065 }
252b5132
RH
8066 }
8067 else
8068 {
8069 elf_elfheader (abfd)->e_flags = flags;
b34976b6 8070 elf_flags_init (abfd) = TRUE;
252b5132
RH
8071 }
8072
b34976b6 8073 return TRUE;
252b5132
RH
8074}
8075
fc830a83 8076/* Copy backend specific data from one object module to another. */
9b485d32 8077
b34976b6 8078static bfd_boolean
57e8b36a 8079elf32_arm_copy_private_bfd_data (bfd *ibfd, bfd *obfd)
252b5132
RH
8080{
8081 flagword in_flags;
8082 flagword out_flags;
8083
0ffa91dd 8084 if (! is_arm_elf (ibfd) || ! is_arm_elf (obfd))
b34976b6 8085 return TRUE;
252b5132 8086
fc830a83 8087 in_flags = elf_elfheader (ibfd)->e_flags;
252b5132
RH
8088 out_flags = elf_elfheader (obfd)->e_flags;
8089
fc830a83
NC
8090 if (elf_flags_init (obfd)
8091 && EF_ARM_EABI_VERSION (out_flags) == EF_ARM_EABI_UNKNOWN
8092 && in_flags != out_flags)
252b5132 8093 {
252b5132 8094 /* Cannot mix APCS26 and APCS32 code. */
fd2ec330 8095 if ((in_flags & EF_ARM_APCS_26) != (out_flags & EF_ARM_APCS_26))
b34976b6 8096 return FALSE;
252b5132
RH
8097
8098 /* Cannot mix float APCS and non-float APCS code. */
fd2ec330 8099 if ((in_flags & EF_ARM_APCS_FLOAT) != (out_flags & EF_ARM_APCS_FLOAT))
b34976b6 8100 return FALSE;
252b5132
RH
8101
8102 /* If the src and dest have different interworking flags
8103 then turn off the interworking bit. */
fd2ec330 8104 if ((in_flags & EF_ARM_INTERWORK) != (out_flags & EF_ARM_INTERWORK))
252b5132 8105 {
fd2ec330 8106 if (out_flags & EF_ARM_INTERWORK)
d003868e
AM
8107 _bfd_error_handler
8108 (_("Warning: Clearing the interworking flag of %B because non-interworking code in %B has been linked with it"),
8109 obfd, ibfd);
252b5132 8110
fd2ec330 8111 in_flags &= ~EF_ARM_INTERWORK;
252b5132 8112 }
1006ba19
PB
8113
8114 /* Likewise for PIC, though don't warn for this case. */
fd2ec330
PB
8115 if ((in_flags & EF_ARM_PIC) != (out_flags & EF_ARM_PIC))
8116 in_flags &= ~EF_ARM_PIC;
252b5132
RH
8117 }
8118
8119 elf_elfheader (obfd)->e_flags = in_flags;
b34976b6 8120 elf_flags_init (obfd) = TRUE;
252b5132 8121
94a3258f
PB
8122 /* Also copy the EI_OSABI field. */
8123 elf_elfheader (obfd)->e_ident[EI_OSABI] =
8124 elf_elfheader (ibfd)->e_ident[EI_OSABI];
8125
104d59d1
JM
8126 /* Copy object attributes. */
8127 _bfd_elf_copy_obj_attributes (ibfd, obfd);
ee065d83
PB
8128
8129 return TRUE;
8130}
8131
8132/* Values for Tag_ABI_PCS_R9_use. */
8133enum
8134{
8135 AEABI_R9_V6,
8136 AEABI_R9_SB,
8137 AEABI_R9_TLS,
8138 AEABI_R9_unused
8139};
8140
8141/* Values for Tag_ABI_PCS_RW_data. */
8142enum
8143{
8144 AEABI_PCS_RW_data_absolute,
8145 AEABI_PCS_RW_data_PCrel,
8146 AEABI_PCS_RW_data_SBrel,
8147 AEABI_PCS_RW_data_unused
8148};
8149
8150/* Values for Tag_ABI_enum_size. */
8151enum
8152{
8153 AEABI_enum_unused,
8154 AEABI_enum_short,
8155 AEABI_enum_wide,
8156 AEABI_enum_forced_wide
8157};
8158
104d59d1
JM
8159/* Determine whether an object attribute tag takes an integer, a
8160 string or both. */
906e58ca 8161
104d59d1
JM
8162static int
8163elf32_arm_obj_attrs_arg_type (int tag)
8164{
8165 if (tag == Tag_compatibility)
8166 return 3;
8167 else if (tag == 4 || tag == 5)
8168 return 2;
8169 else if (tag < 32)
8170 return 1;
8171 else
8172 return (tag & 1) != 0 ? 2 : 1;
8173}
8174
ee065d83
PB
8175/* Merge EABI object attributes from IBFD into OBFD. Raise an error if there
8176 are conflicting attributes. */
906e58ca 8177
ee065d83
PB
8178static bfd_boolean
8179elf32_arm_merge_eabi_attributes (bfd *ibfd, bfd *obfd)
8180{
104d59d1
JM
8181 obj_attribute *in_attr;
8182 obj_attribute *out_attr;
8183 obj_attribute_list *in_list;
ee065d83
PB
8184 /* Some tags have 0 = don't care, 1 = strong requirement,
8185 2 = weak requirement. */
8186 static const int order_312[3] = {3, 1, 2};
b1cc4aeb
PB
8187 /* For use with Tag_VFP_arch. */
8188 static const int order_01243[5] = {0, 1, 2, 4, 3};
ee065d83
PB
8189 int i;
8190
104d59d1 8191 if (!elf_known_obj_attributes_proc (obfd)[0].i)
ee065d83
PB
8192 {
8193 /* This is the first object. Copy the attributes. */
104d59d1 8194 _bfd_elf_copy_obj_attributes (ibfd, obfd);
004ae526
PB
8195
8196 /* Use the Tag_null value to indicate the attributes have been
8197 initialized. */
104d59d1 8198 elf_known_obj_attributes_proc (obfd)[0].i = 1;
004ae526 8199
ee065d83
PB
8200 return TRUE;
8201 }
8202
104d59d1
JM
8203 in_attr = elf_known_obj_attributes_proc (ibfd);
8204 out_attr = elf_known_obj_attributes_proc (obfd);
ee065d83
PB
8205 /* This needs to happen before Tag_ABI_FP_number_model is merged. */
8206 if (in_attr[Tag_ABI_VFP_args].i != out_attr[Tag_ABI_VFP_args].i)
8207 {
8208 /* Ignore mismatches if teh object doesn't use floating point. */
8209 if (out_attr[Tag_ABI_FP_number_model].i == 0)
8210 out_attr[Tag_ABI_VFP_args].i = in_attr[Tag_ABI_VFP_args].i;
8211 else if (in_attr[Tag_ABI_FP_number_model].i != 0)
8212 {
8213 _bfd_error_handler
8214 (_("ERROR: %B uses VFP register arguments, %B does not"),
8215 ibfd, obfd);
8216 return FALSE;
8217 }
8218 }
8219
104d59d1 8220 for (i = 4; i < NUM_KNOWN_OBJ_ATTRIBUTES; i++)
ee065d83
PB
8221 {
8222 /* Merge this attribute with existing attributes. */
8223 switch (i)
8224 {
8225 case Tag_CPU_raw_name:
8226 case Tag_CPU_name:
004ae526
PB
8227 /* Use whichever has the greatest architecture requirements. We
8228 won't necessarily have both the above tags, so make sure input
8229 name is non-NULL. */
8230 if (in_attr[Tag_CPU_arch].i > out_attr[Tag_CPU_arch].i
8231 && in_attr[i].s)
104d59d1 8232 out_attr[i].s = _bfd_elf_attr_strdup (obfd, in_attr[i].s);
ee065d83
PB
8233 break;
8234
8235 case Tag_ABI_optimization_goals:
8236 case Tag_ABI_FP_optimization_goals:
8237 /* Use the first value seen. */
8238 break;
8239
8240 case Tag_CPU_arch:
8241 case Tag_ARM_ISA_use:
8242 case Tag_THUMB_ISA_use:
ee065d83
PB
8243 case Tag_WMMX_arch:
8244 case Tag_NEON_arch:
8245 /* ??? Do NEON and WMMX conflict? */
8246 case Tag_ABI_FP_rounding:
8247 case Tag_ABI_FP_denormal:
8248 case Tag_ABI_FP_exceptions:
8249 case Tag_ABI_FP_user_exceptions:
8250 case Tag_ABI_FP_number_model:
8251 case Tag_ABI_align8_preserved:
8252 case Tag_ABI_HardFP_use:
8253 /* Use the largest value specified. */
8254 if (in_attr[i].i > out_attr[i].i)
8255 out_attr[i].i = in_attr[i].i;
8256 break;
8257
8258 case Tag_CPU_arch_profile:
8259 /* Warn if conflicting architecture profiles used. */
8260 if (out_attr[i].i && in_attr[i].i && in_attr[i].i != out_attr[i].i)
8261 {
8262 _bfd_error_handler
8263 (_("ERROR: %B: Conflicting architecture profiles %c/%c"),
8264 ibfd, in_attr[i].i, out_attr[i].i);
8265 return FALSE;
8266 }
8267 if (in_attr[i].i)
8268 out_attr[i].i = in_attr[i].i;
8269 break;
b1cc4aeb
PB
8270 case Tag_VFP_arch:
8271 if (in_attr[i].i > 4 || out_attr[i].i > 4
8272 || order_01243[in_attr[i].i] > order_01243[out_attr[i].i])
8273 out_attr[i].i = in_attr[i].i;
8274 break;
ee065d83
PB
8275 case Tag_PCS_config:
8276 if (out_attr[i].i == 0)
8277 out_attr[i].i = in_attr[i].i;
8278 else if (in_attr[i].i != 0 && out_attr[i].i != 0)
8279 {
8280 /* It's sometimes ok to mix different configs, so this is only
8281 a warning. */
8282 _bfd_error_handler
8283 (_("Warning: %B: Conflicting platform configuration"), ibfd);
8284 }
8285 break;
8286 case Tag_ABI_PCS_R9_use:
004ae526
PB
8287 if (in_attr[i].i != out_attr[i].i
8288 && out_attr[i].i != AEABI_R9_unused
ee065d83
PB
8289 && in_attr[i].i != AEABI_R9_unused)
8290 {
8291 _bfd_error_handler
8292 (_("ERROR: %B: Conflicting use of R9"), ibfd);
8293 return FALSE;
8294 }
8295 if (out_attr[i].i == AEABI_R9_unused)
8296 out_attr[i].i = in_attr[i].i;
8297 break;
8298 case Tag_ABI_PCS_RW_data:
8299 if (in_attr[i].i == AEABI_PCS_RW_data_SBrel
8300 && out_attr[Tag_ABI_PCS_R9_use].i != AEABI_R9_SB
8301 && out_attr[Tag_ABI_PCS_R9_use].i != AEABI_R9_unused)
8302 {
8303 _bfd_error_handler
8304 (_("ERROR: %B: SB relative addressing conflicts with use of R9"),
8305 ibfd);
8306 return FALSE;
8307 }
8308 /* Use the smallest value specified. */
8309 if (in_attr[i].i < out_attr[i].i)
8310 out_attr[i].i = in_attr[i].i;
8311 break;
8312 case Tag_ABI_PCS_RO_data:
8313 /* Use the smallest value specified. */
8314 if (in_attr[i].i < out_attr[i].i)
8315 out_attr[i].i = in_attr[i].i;
8316 break;
8317 case Tag_ABI_PCS_GOT_use:
8318 if (in_attr[i].i > 2 || out_attr[i].i > 2
8319 || order_312[in_attr[i].i] < order_312[out_attr[i].i])
8320 out_attr[i].i = in_attr[i].i;
8321 break;
8322 case Tag_ABI_PCS_wchar_t:
a9dc9481
JM
8323 if (out_attr[i].i && in_attr[i].i && out_attr[i].i != in_attr[i].i
8324 && !elf_arm_tdata (obfd)->no_wchar_size_warning)
ee065d83
PB
8325 {
8326 _bfd_error_handler
a9dc9481
JM
8327 (_("warning: %B uses %u-byte wchar_t yet the output is to use %u-byte wchar_t; use of wchar_t values across objects may fail"),
8328 ibfd, in_attr[i].i, out_attr[i].i);
ee065d83 8329 }
a9dc9481 8330 else if (in_attr[i].i && !out_attr[i].i)
ee065d83
PB
8331 out_attr[i].i = in_attr[i].i;
8332 break;
8333 case Tag_ABI_align8_needed:
8334 /* ??? Check against Tag_ABI_align8_preserved. */
8335 if (in_attr[i].i > 2 || out_attr[i].i > 2
8336 || order_312[in_attr[i].i] < order_312[out_attr[i].i])
8337 out_attr[i].i = in_attr[i].i;
8338 break;
8339 case Tag_ABI_enum_size:
8340 if (in_attr[i].i != AEABI_enum_unused)
8341 {
8342 if (out_attr[i].i == AEABI_enum_unused
8343 || out_attr[i].i == AEABI_enum_forced_wide)
8344 {
8345 /* The existing object is compatible with anything.
8346 Use whatever requirements the new object has. */
8347 out_attr[i].i = in_attr[i].i;
8348 }
8349 else if (in_attr[i].i != AEABI_enum_forced_wide
bf21ed78 8350 && out_attr[i].i != in_attr[i].i
0ffa91dd 8351 && !elf_arm_tdata (obfd)->no_enum_size_warning)
ee065d83 8352 {
bf21ed78
MS
8353 const char *aeabi_enum_names[] =
8354 { "", "variable-size", "32-bit", "" };
ee065d83 8355 _bfd_error_handler
bf21ed78
MS
8356 (_("warning: %B uses %s enums yet the output is to use %s enums; use of enum values across objects may fail"),
8357 ibfd, aeabi_enum_names[in_attr[i].i],
8358 aeabi_enum_names[out_attr[i].i]);
ee065d83
PB
8359 }
8360 }
8361 break;
8362 case Tag_ABI_VFP_args:
8363 /* Aready done. */
8364 break;
8365 case Tag_ABI_WMMX_args:
8366 if (in_attr[i].i != out_attr[i].i)
8367 {
8368 _bfd_error_handler
8369 (_("ERROR: %B uses iWMMXt register arguments, %B does not"),
8370 ibfd, obfd);
8371 return FALSE;
8372 }
8373 break;
8374 default: /* All known attributes should be explicitly covered. */
8375 abort ();
8376 }
3cfad14c
JM
8377
8378 if (in_attr[i].type && !out_attr[i].type)
8379 switch (in_attr[i].type)
8380 {
8381 case 1:
8382 if (out_attr[i].i)
8383 out_attr[i].type = 1;
8384 break;
8385
8386 case 2:
8387 if (out_attr[i].s)
8388 out_attr[i].type = 2;
8389 break;
8390
8391 default:
8392 abort ();
8393 }
ee065d83
PB
8394 }
8395
104d59d1
JM
8396 /* Merge Tag_compatibility attributes and any common GNU ones. */
8397 _bfd_elf_merge_object_attributes (ibfd, obfd);
ee065d83 8398
104d59d1
JM
8399 /* Check for any attributes not known on ARM. */
8400 in_list = elf_other_obj_attributes_proc (ibfd);
8401 while (in_list && in_list->tag == Tag_compatibility)
8402 in_list = in_list->next;
ee065d83
PB
8403
8404 for (; in_list; in_list = in_list->next)
8405 {
8406 if ((in_list->tag & 128) < 64)
eb111b1f
BE
8407 {
8408 _bfd_error_handler
8409 (_("Warning: %B: Unknown EABI object attribute %d"),
8410 ibfd, in_list->tag);
8411 break;
8412 }
ee065d83 8413 }
b34976b6 8414 return TRUE;
252b5132
RH
8415}
8416
3a4a14e9
PB
8417
8418/* Return TRUE if the two EABI versions are incompatible. */
8419
8420static bfd_boolean
8421elf32_arm_versions_compatible (unsigned iver, unsigned over)
8422{
8423 /* v4 and v5 are the same spec before and after it was released,
8424 so allow mixing them. */
8425 if ((iver == EF_ARM_EABI_VER4 && over == EF_ARM_EABI_VER5)
8426 || (iver == EF_ARM_EABI_VER5 && over == EF_ARM_EABI_VER4))
8427 return TRUE;
8428
8429 return (iver == over);
8430}
8431
252b5132
RH
8432/* Merge backend specific data from an object file to the output
8433 object file when linking. */
9b485d32 8434
b34976b6 8435static bfd_boolean
57e8b36a 8436elf32_arm_merge_private_bfd_data (bfd * ibfd, bfd * obfd)
252b5132
RH
8437{
8438 flagword out_flags;
8439 flagword in_flags;
b34976b6 8440 bfd_boolean flags_compatible = TRUE;
cf919dfd 8441 asection *sec;
252b5132 8442
9b485d32 8443 /* Check if we have the same endianess. */
82e51918 8444 if (! _bfd_generic_verify_endian_match (ibfd, obfd))
b34976b6 8445 return FALSE;
1fe494a5 8446
0ffa91dd 8447 if (! is_arm_elf (ibfd) || ! is_arm_elf (obfd))
b34976b6 8448 return TRUE;
252b5132 8449
ee065d83
PB
8450 if (!elf32_arm_merge_eabi_attributes (ibfd, obfd))
8451 return FALSE;
8452
252b5132
RH
8453 /* The input BFD must have had its flags initialised. */
8454 /* The following seems bogus to me -- The flags are initialized in
8455 the assembler but I don't think an elf_flags_init field is
9b485d32 8456 written into the object. */
252b5132
RH
8457 /* BFD_ASSERT (elf_flags_init (ibfd)); */
8458
8459 in_flags = elf_elfheader (ibfd)->e_flags;
8460 out_flags = elf_elfheader (obfd)->e_flags;
8461
23684067
PB
8462 /* In theory there is no reason why we couldn't handle this. However
8463 in practice it isn't even close to working and there is no real
8464 reason to want it. */
8465 if (EF_ARM_EABI_VERSION (in_flags) >= EF_ARM_EABI_VER4
c13bb2ea 8466 && !(ibfd->flags & DYNAMIC)
23684067
PB
8467 && (in_flags & EF_ARM_BE8))
8468 {
8469 _bfd_error_handler (_("ERROR: %B is already in final BE8 format"),
8470 ibfd);
8471 return FALSE;
8472 }
8473
252b5132
RH
8474 if (!elf_flags_init (obfd))
8475 {
fe077fa6
NC
8476 /* If the input is the default architecture and had the default
8477 flags then do not bother setting the flags for the output
8478 architecture, instead allow future merges to do this. If no
8479 future merges ever set these flags then they will retain their
8480 uninitialised values, which surprise surprise, correspond
252b5132 8481 to the default values. */
fe077fa6
NC
8482 if (bfd_get_arch_info (ibfd)->the_default
8483 && elf_elfheader (ibfd)->e_flags == 0)
b34976b6 8484 return TRUE;
252b5132 8485
b34976b6 8486 elf_flags_init (obfd) = TRUE;
252b5132
RH
8487 elf_elfheader (obfd)->e_flags = in_flags;
8488
8489 if (bfd_get_arch (obfd) == bfd_get_arch (ibfd)
8490 && bfd_get_arch_info (obfd)->the_default)
8491 return bfd_set_arch_mach (obfd, bfd_get_arch (ibfd), bfd_get_mach (ibfd));
8492
b34976b6 8493 return TRUE;
252b5132
RH
8494 }
8495
5a6c6817
NC
8496 /* Determine what should happen if the input ARM architecture
8497 does not match the output ARM architecture. */
8498 if (! bfd_arm_merge_machines (ibfd, obfd))
8499 return FALSE;
e16bb312 8500
1006ba19 8501 /* Identical flags must be compatible. */
252b5132 8502 if (in_flags == out_flags)
b34976b6 8503 return TRUE;
252b5132 8504
35a0f415
DJ
8505 /* Check to see if the input BFD actually contains any sections. If
8506 not, its flags may not have been initialised either, but it
8e3de13a 8507 cannot actually cause any incompatiblity. Do not short-circuit
35a0f415 8508 dynamic objects; their section list may be emptied by
d1f161ea 8509 elf_link_add_object_symbols.
35a0f415 8510
d1f161ea
NC
8511 Also check to see if there are no code sections in the input.
8512 In this case there is no need to check for code specific flags.
8513 XXX - do we need to worry about floating-point format compatability
8514 in data sections ? */
35a0f415 8515 if (!(ibfd->flags & DYNAMIC))
cf919dfd 8516 {
35a0f415 8517 bfd_boolean null_input_bfd = TRUE;
d1f161ea 8518 bfd_boolean only_data_sections = TRUE;
35a0f415
DJ
8519
8520 for (sec = ibfd->sections; sec != NULL; sec = sec->next)
cf919dfd 8521 {
35a0f415
DJ
8522 /* Ignore synthetic glue sections. */
8523 if (strcmp (sec->name, ".glue_7")
8524 && strcmp (sec->name, ".glue_7t"))
8525 {
d1f161ea
NC
8526 if ((bfd_get_section_flags (ibfd, sec)
8527 & (SEC_LOAD | SEC_CODE | SEC_HAS_CONTENTS))
8528 == (SEC_LOAD | SEC_CODE | SEC_HAS_CONTENTS))
8529 only_data_sections = FALSE;
8530
35a0f415
DJ
8531 null_input_bfd = FALSE;
8532 break;
8533 }
cf919dfd 8534 }
d1f161ea
NC
8535
8536 if (null_input_bfd || only_data_sections)
35a0f415 8537 return TRUE;
cf919dfd 8538 }
cf919dfd 8539
252b5132 8540 /* Complain about various flag mismatches. */
3a4a14e9
PB
8541 if (!elf32_arm_versions_compatible (EF_ARM_EABI_VERSION (in_flags),
8542 EF_ARM_EABI_VERSION (out_flags)))
fc830a83 8543 {
d003868e 8544 _bfd_error_handler
3656d5e3 8545 (_("ERROR: Source object %B has EABI version %d, but target %B has EABI version %d"),
d003868e
AM
8546 ibfd, obfd,
8547 (in_flags & EF_ARM_EABIMASK) >> 24,
8548 (out_flags & EF_ARM_EABIMASK) >> 24);
b34976b6 8549 return FALSE;
fc830a83 8550 }
252b5132 8551
1006ba19 8552 /* Not sure what needs to be checked for EABI versions >= 1. */
00a97672
RS
8553 /* VxWorks libraries do not use these flags. */
8554 if (get_elf_backend_data (obfd) != &elf32_arm_vxworks_bed
8555 && get_elf_backend_data (ibfd) != &elf32_arm_vxworks_bed
8556 && EF_ARM_EABI_VERSION (in_flags) == EF_ARM_EABI_UNKNOWN)
1006ba19 8557 {
fd2ec330 8558 if ((in_flags & EF_ARM_APCS_26) != (out_flags & EF_ARM_APCS_26))
1006ba19 8559 {
d003868e
AM
8560 _bfd_error_handler
8561 (_("ERROR: %B is compiled for APCS-%d, whereas target %B uses APCS-%d"),
8562 ibfd, obfd,
8563 in_flags & EF_ARM_APCS_26 ? 26 : 32,
8564 out_flags & EF_ARM_APCS_26 ? 26 : 32);
b34976b6 8565 flags_compatible = FALSE;
1006ba19 8566 }
252b5132 8567
fd2ec330 8568 if ((in_flags & EF_ARM_APCS_FLOAT) != (out_flags & EF_ARM_APCS_FLOAT))
1006ba19 8569 {
5eefb65f 8570 if (in_flags & EF_ARM_APCS_FLOAT)
d003868e
AM
8571 _bfd_error_handler
8572 (_("ERROR: %B passes floats in float registers, whereas %B passes them in integer registers"),
8573 ibfd, obfd);
5eefb65f 8574 else
d003868e
AM
8575 _bfd_error_handler
8576 (_("ERROR: %B passes floats in integer registers, whereas %B passes them in float registers"),
8577 ibfd, obfd);
63b0f745 8578
b34976b6 8579 flags_compatible = FALSE;
1006ba19 8580 }
252b5132 8581
96a846ea 8582 if ((in_flags & EF_ARM_VFP_FLOAT) != (out_flags & EF_ARM_VFP_FLOAT))
1006ba19 8583 {
96a846ea 8584 if (in_flags & EF_ARM_VFP_FLOAT)
d003868e
AM
8585 _bfd_error_handler
8586 (_("ERROR: %B uses VFP instructions, whereas %B does not"),
8587 ibfd, obfd);
5eefb65f 8588 else
d003868e
AM
8589 _bfd_error_handler
8590 (_("ERROR: %B uses FPA instructions, whereas %B does not"),
8591 ibfd, obfd);
fde78edd
NC
8592
8593 flags_compatible = FALSE;
8594 }
8595
8596 if ((in_flags & EF_ARM_MAVERICK_FLOAT) != (out_flags & EF_ARM_MAVERICK_FLOAT))
8597 {
8598 if (in_flags & EF_ARM_MAVERICK_FLOAT)
d003868e
AM
8599 _bfd_error_handler
8600 (_("ERROR: %B uses Maverick instructions, whereas %B does not"),
8601 ibfd, obfd);
fde78edd 8602 else
d003868e
AM
8603 _bfd_error_handler
8604 (_("ERROR: %B does not use Maverick instructions, whereas %B does"),
8605 ibfd, obfd);
63b0f745 8606
b34976b6 8607 flags_compatible = FALSE;
1006ba19 8608 }
96a846ea
RE
8609
8610#ifdef EF_ARM_SOFT_FLOAT
8611 if ((in_flags & EF_ARM_SOFT_FLOAT) != (out_flags & EF_ARM_SOFT_FLOAT))
8612 {
8613 /* We can allow interworking between code that is VFP format
8614 layout, and uses either soft float or integer regs for
8615 passing floating point arguments and results. We already
8616 know that the APCS_FLOAT flags match; similarly for VFP
8617 flags. */
8618 if ((in_flags & EF_ARM_APCS_FLOAT) != 0
8619 || (in_flags & EF_ARM_VFP_FLOAT) == 0)
8620 {
8621 if (in_flags & EF_ARM_SOFT_FLOAT)
d003868e
AM
8622 _bfd_error_handler
8623 (_("ERROR: %B uses software FP, whereas %B uses hardware FP"),
8624 ibfd, obfd);
96a846ea 8625 else
d003868e
AM
8626 _bfd_error_handler
8627 (_("ERROR: %B uses hardware FP, whereas %B uses software FP"),
8628 ibfd, obfd);
96a846ea 8629
b34976b6 8630 flags_compatible = FALSE;
96a846ea
RE
8631 }
8632 }
ee43f35e 8633#endif
252b5132 8634
1006ba19 8635 /* Interworking mismatch is only a warning. */
fd2ec330 8636 if ((in_flags & EF_ARM_INTERWORK) != (out_flags & EF_ARM_INTERWORK))
8f615d07 8637 {
e3c8793a
NC
8638 if (in_flags & EF_ARM_INTERWORK)
8639 {
d003868e
AM
8640 _bfd_error_handler
8641 (_("Warning: %B supports interworking, whereas %B does not"),
8642 ibfd, obfd);
e3c8793a
NC
8643 }
8644 else
8645 {
d003868e
AM
8646 _bfd_error_handler
8647 (_("Warning: %B does not support interworking, whereas %B does"),
8648 ibfd, obfd);
e3c8793a 8649 }
8f615d07 8650 }
252b5132 8651 }
63b0f745 8652
1006ba19 8653 return flags_compatible;
252b5132
RH
8654}
8655
9b485d32
NC
8656/* Display the flags field. */
8657
b34976b6 8658static bfd_boolean
57e8b36a 8659elf32_arm_print_private_bfd_data (bfd *abfd, void * ptr)
252b5132 8660{
fc830a83
NC
8661 FILE * file = (FILE *) ptr;
8662 unsigned long flags;
252b5132
RH
8663
8664 BFD_ASSERT (abfd != NULL && ptr != NULL);
8665
8666 /* Print normal ELF private data. */
8667 _bfd_elf_print_private_bfd_data (abfd, ptr);
8668
fc830a83 8669 flags = elf_elfheader (abfd)->e_flags;
9b485d32
NC
8670 /* Ignore init flag - it may not be set, despite the flags field
8671 containing valid data. */
252b5132
RH
8672
8673 /* xgettext:c-format */
9b485d32 8674 fprintf (file, _("private flags = %lx:"), elf_elfheader (abfd)->e_flags);
252b5132 8675
fc830a83
NC
8676 switch (EF_ARM_EABI_VERSION (flags))
8677 {
8678 case EF_ARM_EABI_UNKNOWN:
4cc11e76 8679 /* The following flag bits are GNU extensions and not part of the
fc830a83
NC
8680 official ARM ELF extended ABI. Hence they are only decoded if
8681 the EABI version is not set. */
fd2ec330 8682 if (flags & EF_ARM_INTERWORK)
9b485d32 8683 fprintf (file, _(" [interworking enabled]"));
9a5aca8c 8684
fd2ec330 8685 if (flags & EF_ARM_APCS_26)
6c571f00 8686 fprintf (file, " [APCS-26]");
fc830a83 8687 else
6c571f00 8688 fprintf (file, " [APCS-32]");
9a5aca8c 8689
96a846ea
RE
8690 if (flags & EF_ARM_VFP_FLOAT)
8691 fprintf (file, _(" [VFP float format]"));
fde78edd
NC
8692 else if (flags & EF_ARM_MAVERICK_FLOAT)
8693 fprintf (file, _(" [Maverick float format]"));
96a846ea
RE
8694 else
8695 fprintf (file, _(" [FPA float format]"));
8696
fd2ec330 8697 if (flags & EF_ARM_APCS_FLOAT)
9b485d32 8698 fprintf (file, _(" [floats passed in float registers]"));
9a5aca8c 8699
fd2ec330 8700 if (flags & EF_ARM_PIC)
9b485d32 8701 fprintf (file, _(" [position independent]"));
fc830a83 8702
fd2ec330 8703 if (flags & EF_ARM_NEW_ABI)
9b485d32 8704 fprintf (file, _(" [new ABI]"));
9a5aca8c 8705
fd2ec330 8706 if (flags & EF_ARM_OLD_ABI)
9b485d32 8707 fprintf (file, _(" [old ABI]"));
9a5aca8c 8708
fd2ec330 8709 if (flags & EF_ARM_SOFT_FLOAT)
9b485d32 8710 fprintf (file, _(" [software FP]"));
9a5aca8c 8711
96a846ea
RE
8712 flags &= ~(EF_ARM_INTERWORK | EF_ARM_APCS_26 | EF_ARM_APCS_FLOAT
8713 | EF_ARM_PIC | EF_ARM_NEW_ABI | EF_ARM_OLD_ABI
fde78edd
NC
8714 | EF_ARM_SOFT_FLOAT | EF_ARM_VFP_FLOAT
8715 | EF_ARM_MAVERICK_FLOAT);
fc830a83 8716 break;
9a5aca8c 8717
fc830a83 8718 case EF_ARM_EABI_VER1:
9b485d32 8719 fprintf (file, _(" [Version1 EABI]"));
9a5aca8c 8720
fc830a83 8721 if (flags & EF_ARM_SYMSARESORTED)
9b485d32 8722 fprintf (file, _(" [sorted symbol table]"));
fc830a83 8723 else
9b485d32 8724 fprintf (file, _(" [unsorted symbol table]"));
9a5aca8c 8725
fc830a83
NC
8726 flags &= ~ EF_ARM_SYMSARESORTED;
8727 break;
9a5aca8c 8728
fd2ec330
PB
8729 case EF_ARM_EABI_VER2:
8730 fprintf (file, _(" [Version2 EABI]"));
8731
8732 if (flags & EF_ARM_SYMSARESORTED)
8733 fprintf (file, _(" [sorted symbol table]"));
8734 else
8735 fprintf (file, _(" [unsorted symbol table]"));
8736
8737 if (flags & EF_ARM_DYNSYMSUSESEGIDX)
8738 fprintf (file, _(" [dynamic symbols use segment index]"));
8739
8740 if (flags & EF_ARM_MAPSYMSFIRST)
8741 fprintf (file, _(" [mapping symbols precede others]"));
8742
99e4ae17 8743 flags &= ~(EF_ARM_SYMSARESORTED | EF_ARM_DYNSYMSUSESEGIDX
fd2ec330
PB
8744 | EF_ARM_MAPSYMSFIRST);
8745 break;
8746
d507cf36
PB
8747 case EF_ARM_EABI_VER3:
8748 fprintf (file, _(" [Version3 EABI]"));
8cb51566
PB
8749 break;
8750
8751 case EF_ARM_EABI_VER4:
8752 fprintf (file, _(" [Version4 EABI]"));
3a4a14e9 8753 goto eabi;
d507cf36 8754
3a4a14e9
PB
8755 case EF_ARM_EABI_VER5:
8756 fprintf (file, _(" [Version5 EABI]"));
8757 eabi:
d507cf36
PB
8758 if (flags & EF_ARM_BE8)
8759 fprintf (file, _(" [BE8]"));
8760
8761 if (flags & EF_ARM_LE8)
8762 fprintf (file, _(" [LE8]"));
8763
8764 flags &= ~(EF_ARM_LE8 | EF_ARM_BE8);
8765 break;
8766
fc830a83 8767 default:
9b485d32 8768 fprintf (file, _(" <EABI version unrecognised>"));
fc830a83
NC
8769 break;
8770 }
252b5132 8771
fc830a83 8772 flags &= ~ EF_ARM_EABIMASK;
252b5132 8773
fc830a83 8774 if (flags & EF_ARM_RELEXEC)
9b485d32 8775 fprintf (file, _(" [relocatable executable]"));
252b5132 8776
fc830a83 8777 if (flags & EF_ARM_HASENTRY)
9b485d32 8778 fprintf (file, _(" [has entry point]"));
252b5132 8779
fc830a83
NC
8780 flags &= ~ (EF_ARM_RELEXEC | EF_ARM_HASENTRY);
8781
8782 if (flags)
9b485d32 8783 fprintf (file, _("<Unrecognised flag bits set>"));
9a5aca8c 8784
252b5132
RH
8785 fputc ('\n', file);
8786
b34976b6 8787 return TRUE;
252b5132
RH
8788}
8789
8790static int
57e8b36a 8791elf32_arm_get_symbol_type (Elf_Internal_Sym * elf_sym, int type)
252b5132 8792{
2f0ca46a
NC
8793 switch (ELF_ST_TYPE (elf_sym->st_info))
8794 {
8795 case STT_ARM_TFUNC:
8796 return ELF_ST_TYPE (elf_sym->st_info);
ce855c42 8797
2f0ca46a
NC
8798 case STT_ARM_16BIT:
8799 /* If the symbol is not an object, return the STT_ARM_16BIT flag.
8800 This allows us to distinguish between data used by Thumb instructions
8801 and non-data (which is probably code) inside Thumb regions of an
8802 executable. */
1a0eb693 8803 if (type != STT_OBJECT && type != STT_TLS)
2f0ca46a
NC
8804 return ELF_ST_TYPE (elf_sym->st_info);
8805 break;
9a5aca8c 8806
ce855c42
NC
8807 default:
8808 break;
2f0ca46a
NC
8809 }
8810
8811 return type;
252b5132 8812}
f21f3fe0 8813
252b5132 8814static asection *
07adf181
AM
8815elf32_arm_gc_mark_hook (asection *sec,
8816 struct bfd_link_info *info,
8817 Elf_Internal_Rela *rel,
8818 struct elf_link_hash_entry *h,
8819 Elf_Internal_Sym *sym)
252b5132
RH
8820{
8821 if (h != NULL)
07adf181 8822 switch (ELF32_R_TYPE (rel->r_info))
252b5132
RH
8823 {
8824 case R_ARM_GNU_VTINHERIT:
8825 case R_ARM_GNU_VTENTRY:
07adf181
AM
8826 return NULL;
8827 }
9ad5cbcf 8828
07adf181 8829 return _bfd_elf_gc_mark_hook (sec, info, rel, h, sym);
252b5132
RH
8830}
8831
780a67af
NC
8832/* Update the got entry reference counts for the section being removed. */
8833
b34976b6 8834static bfd_boolean
ba93b8ac
DJ
8835elf32_arm_gc_sweep_hook (bfd * abfd,
8836 struct bfd_link_info * info,
8837 asection * sec,
8838 const Elf_Internal_Rela * relocs)
252b5132 8839{
5e681ec4
PB
8840 Elf_Internal_Shdr *symtab_hdr;
8841 struct elf_link_hash_entry **sym_hashes;
8842 bfd_signed_vma *local_got_refcounts;
8843 const Elf_Internal_Rela *rel, *relend;
eb043451
PB
8844 struct elf32_arm_link_hash_table * globals;
8845
7dda2462
TG
8846 if (info->relocatable)
8847 return TRUE;
8848
eb043451 8849 globals = elf32_arm_hash_table (info);
5e681ec4
PB
8850
8851 elf_section_data (sec)->local_dynrel = NULL;
8852
0ffa91dd 8853 symtab_hdr = & elf_symtab_hdr (abfd);
5e681ec4
PB
8854 sym_hashes = elf_sym_hashes (abfd);
8855 local_got_refcounts = elf_local_got_refcounts (abfd);
8856
906e58ca 8857 check_use_blx (globals);
bd97cb95 8858
5e681ec4
PB
8859 relend = relocs + sec->reloc_count;
8860 for (rel = relocs; rel < relend; rel++)
eb043451 8861 {
3eb128b2
AM
8862 unsigned long r_symndx;
8863 struct elf_link_hash_entry *h = NULL;
eb043451 8864 int r_type;
5e681ec4 8865
3eb128b2
AM
8866 r_symndx = ELF32_R_SYM (rel->r_info);
8867 if (r_symndx >= symtab_hdr->sh_info)
8868 {
8869 h = sym_hashes[r_symndx - symtab_hdr->sh_info];
8870 while (h->root.type == bfd_link_hash_indirect
8871 || h->root.type == bfd_link_hash_warning)
8872 h = (struct elf_link_hash_entry *) h->root.u.i.link;
8873 }
8874
eb043451 8875 r_type = ELF32_R_TYPE (rel->r_info);
eb043451 8876 r_type = arm_real_reloc_type (globals, r_type);
eb043451
PB
8877 switch (r_type)
8878 {
8879 case R_ARM_GOT32:
eb043451 8880 case R_ARM_GOT_PREL:
ba93b8ac
DJ
8881 case R_ARM_TLS_GD32:
8882 case R_ARM_TLS_IE32:
3eb128b2 8883 if (h != NULL)
eb043451 8884 {
eb043451
PB
8885 if (h->got.refcount > 0)
8886 h->got.refcount -= 1;
8887 }
8888 else if (local_got_refcounts != NULL)
8889 {
8890 if (local_got_refcounts[r_symndx] > 0)
8891 local_got_refcounts[r_symndx] -= 1;
8892 }
8893 break;
8894
ba93b8ac
DJ
8895 case R_ARM_TLS_LDM32:
8896 elf32_arm_hash_table (info)->tls_ldm_got.refcount -= 1;
8897 break;
8898
eb043451 8899 case R_ARM_ABS32:
bb224fc3 8900 case R_ARM_ABS32_NOI:
eb043451 8901 case R_ARM_REL32:
bb224fc3 8902 case R_ARM_REL32_NOI:
eb043451
PB
8903 case R_ARM_PC24:
8904 case R_ARM_PLT32:
5b5bb741
PB
8905 case R_ARM_CALL:
8906 case R_ARM_JUMP24:
eb043451 8907 case R_ARM_PREL31:
c19d1205 8908 case R_ARM_THM_CALL:
bd97cb95
DJ
8909 case R_ARM_THM_JUMP24:
8910 case R_ARM_THM_JUMP19:
b6895b4f
PB
8911 case R_ARM_MOVW_ABS_NC:
8912 case R_ARM_MOVT_ABS:
8913 case R_ARM_MOVW_PREL_NC:
8914 case R_ARM_MOVT_PREL:
8915 case R_ARM_THM_MOVW_ABS_NC:
8916 case R_ARM_THM_MOVT_ABS:
8917 case R_ARM_THM_MOVW_PREL_NC:
8918 case R_ARM_THM_MOVT_PREL:
b7693d02
DJ
8919 /* Should the interworking branches be here also? */
8920
3eb128b2 8921 if (h != NULL)
eb043451
PB
8922 {
8923 struct elf32_arm_link_hash_entry *eh;
8924 struct elf32_arm_relocs_copied **pp;
8925 struct elf32_arm_relocs_copied *p;
5e681ec4 8926
b7693d02 8927 eh = (struct elf32_arm_link_hash_entry *) h;
5e681ec4 8928
eb043451 8929 if (h->plt.refcount > 0)
b7693d02
DJ
8930 {
8931 h->plt.refcount -= 1;
bd97cb95
DJ
8932 if (r_type == R_ARM_THM_CALL)
8933 eh->plt_maybe_thumb_refcount--;
8934
8935 if (r_type == R_ARM_THM_JUMP24
8936 || r_type == R_ARM_THM_JUMP19)
b7693d02
DJ
8937 eh->plt_thumb_refcount--;
8938 }
5e681ec4 8939
eb043451 8940 if (r_type == R_ARM_ABS32
bb224fc3
MS
8941 || r_type == R_ARM_REL32
8942 || r_type == R_ARM_ABS32_NOI
8943 || r_type == R_ARM_REL32_NOI)
eb043451 8944 {
eb043451
PB
8945 for (pp = &eh->relocs_copied; (p = *pp) != NULL;
8946 pp = &p->next)
8947 if (p->section == sec)
8948 {
8949 p->count -= 1;
bb224fc3
MS
8950 if (ELF32_R_TYPE (rel->r_info) == R_ARM_REL32
8951 || ELF32_R_TYPE (rel->r_info) == R_ARM_REL32_NOI)
ba93b8ac 8952 p->pc_count -= 1;
eb043451
PB
8953 if (p->count == 0)
8954 *pp = p->next;
8955 break;
8956 }
8957 }
8958 }
8959 break;
5e681ec4 8960
eb043451
PB
8961 default:
8962 break;
8963 }
8964 }
5e681ec4 8965
b34976b6 8966 return TRUE;
252b5132
RH
8967}
8968
780a67af
NC
8969/* Look through the relocs for a section during the first phase. */
8970
b34976b6 8971static bfd_boolean
57e8b36a
NC
8972elf32_arm_check_relocs (bfd *abfd, struct bfd_link_info *info,
8973 asection *sec, const Elf_Internal_Rela *relocs)
252b5132 8974{
b34976b6
AM
8975 Elf_Internal_Shdr *symtab_hdr;
8976 struct elf_link_hash_entry **sym_hashes;
b34976b6
AM
8977 const Elf_Internal_Rela *rel;
8978 const Elf_Internal_Rela *rel_end;
8979 bfd *dynobj;
5e681ec4 8980 asection *sreloc;
b34976b6 8981 bfd_vma *local_got_offsets;
5e681ec4 8982 struct elf32_arm_link_hash_table *htab;
39623e12 8983 bfd_boolean needs_plt;
9a5aca8c 8984
1049f94e 8985 if (info->relocatable)
b34976b6 8986 return TRUE;
9a5aca8c 8987
0ffa91dd
NC
8988 BFD_ASSERT (is_arm_elf (abfd));
8989
5e681ec4
PB
8990 htab = elf32_arm_hash_table (info);
8991 sreloc = NULL;
9a5aca8c 8992
67687978
PB
8993 /* Create dynamic sections for relocatable executables so that we can
8994 copy relocations. */
8995 if (htab->root.is_relocatable_executable
8996 && ! htab->root.dynamic_sections_created)
8997 {
8998 if (! _bfd_elf_link_create_dynamic_sections (abfd, info))
8999 return FALSE;
9000 }
9001
252b5132
RH
9002 dynobj = elf_hash_table (info)->dynobj;
9003 local_got_offsets = elf_local_got_offsets (abfd);
f21f3fe0 9004
0ffa91dd 9005 symtab_hdr = & elf_symtab_hdr (abfd);
252b5132 9006 sym_hashes = elf_sym_hashes (abfd);
9b485d32 9007
252b5132
RH
9008 rel_end = relocs + sec->reloc_count;
9009 for (rel = relocs; rel < rel_end; rel++)
9010 {
9011 struct elf_link_hash_entry *h;
b7693d02 9012 struct elf32_arm_link_hash_entry *eh;
252b5132 9013 unsigned long r_symndx;
eb043451 9014 int r_type;
9a5aca8c 9015
252b5132 9016 r_symndx = ELF32_R_SYM (rel->r_info);
eb043451 9017 r_type = ELF32_R_TYPE (rel->r_info);
eb043451 9018 r_type = arm_real_reloc_type (htab, r_type);
ba93b8ac
DJ
9019
9020 if (r_symndx >= NUM_SHDR_ENTRIES (symtab_hdr))
9021 {
9022 (*_bfd_error_handler) (_("%B: bad symbol index: %d"), abfd,
9023 r_symndx);
9024 return FALSE;
9025 }
9026
252b5132
RH
9027 if (r_symndx < symtab_hdr->sh_info)
9028 h = NULL;
9029 else
973a3492
L
9030 {
9031 h = sym_hashes[r_symndx - symtab_hdr->sh_info];
9032 while (h->root.type == bfd_link_hash_indirect
9033 || h->root.type == bfd_link_hash_warning)
9034 h = (struct elf_link_hash_entry *) h->root.u.i.link;
9035 }
9a5aca8c 9036
b7693d02
DJ
9037 eh = (struct elf32_arm_link_hash_entry *) h;
9038
eb043451 9039 switch (r_type)
252b5132 9040 {
5e681ec4 9041 case R_ARM_GOT32:
eb043451 9042 case R_ARM_GOT_PREL:
ba93b8ac
DJ
9043 case R_ARM_TLS_GD32:
9044 case R_ARM_TLS_IE32:
5e681ec4 9045 /* This symbol requires a global offset table entry. */
ba93b8ac
DJ
9046 {
9047 int tls_type, old_tls_type;
5e681ec4 9048
ba93b8ac
DJ
9049 switch (r_type)
9050 {
9051 case R_ARM_TLS_GD32: tls_type = GOT_TLS_GD; break;
9052 case R_ARM_TLS_IE32: tls_type = GOT_TLS_IE; break;
9053 default: tls_type = GOT_NORMAL; break;
9054 }
252b5132 9055
ba93b8ac
DJ
9056 if (h != NULL)
9057 {
9058 h->got.refcount++;
9059 old_tls_type = elf32_arm_hash_entry (h)->tls_type;
9060 }
9061 else
9062 {
9063 bfd_signed_vma *local_got_refcounts;
9064
9065 /* This is a global offset table entry for a local symbol. */
9066 local_got_refcounts = elf_local_got_refcounts (abfd);
9067 if (local_got_refcounts == NULL)
9068 {
9069 bfd_size_type size;
906e58ca 9070
ba93b8ac 9071 size = symtab_hdr->sh_info;
906e58ca 9072 size *= (sizeof (bfd_signed_vma) + sizeof (char));
ba93b8ac
DJ
9073 local_got_refcounts = bfd_zalloc (abfd, size);
9074 if (local_got_refcounts == NULL)
9075 return FALSE;
9076 elf_local_got_refcounts (abfd) = local_got_refcounts;
9077 elf32_arm_local_got_tls_type (abfd)
9078 = (char *) (local_got_refcounts + symtab_hdr->sh_info);
9079 }
9080 local_got_refcounts[r_symndx] += 1;
9081 old_tls_type = elf32_arm_local_got_tls_type (abfd) [r_symndx];
9082 }
9083
9084 /* We will already have issued an error message if there is a
9085 TLS / non-TLS mismatch, based on the symbol type. We don't
9086 support any linker relaxations. So just combine any TLS
9087 types needed. */
9088 if (old_tls_type != GOT_UNKNOWN && old_tls_type != GOT_NORMAL
9089 && tls_type != GOT_NORMAL)
9090 tls_type |= old_tls_type;
9091
9092 if (old_tls_type != tls_type)
9093 {
9094 if (h != NULL)
9095 elf32_arm_hash_entry (h)->tls_type = tls_type;
9096 else
9097 elf32_arm_local_got_tls_type (abfd) [r_symndx] = tls_type;
9098 }
9099 }
9100 /* Fall through */
9101
9102 case R_ARM_TLS_LDM32:
9103 if (r_type == R_ARM_TLS_LDM32)
9104 htab->tls_ldm_got.refcount++;
9105 /* Fall through */
252b5132 9106
c19d1205 9107 case R_ARM_GOTOFF32:
5e681ec4
PB
9108 case R_ARM_GOTPC:
9109 if (htab->sgot == NULL)
9110 {
9111 if (htab->root.dynobj == NULL)
9112 htab->root.dynobj = abfd;
9113 if (!create_got_section (htab->root.dynobj, info))
9114 return FALSE;
9115 }
252b5132
RH
9116 break;
9117
00a97672
RS
9118 case R_ARM_ABS12:
9119 /* VxWorks uses dynamic R_ARM_ABS12 relocations for
9120 ldr __GOTT_INDEX__ offsets. */
9121 if (!htab->vxworks_p)
9122 break;
9123 /* Fall through */
9124
252b5132 9125 case R_ARM_PC24:
7359ea65 9126 case R_ARM_PLT32:
5b5bb741
PB
9127 case R_ARM_CALL:
9128 case R_ARM_JUMP24:
eb043451 9129 case R_ARM_PREL31:
c19d1205 9130 case R_ARM_THM_CALL:
bd97cb95
DJ
9131 case R_ARM_THM_JUMP24:
9132 case R_ARM_THM_JUMP19:
39623e12
PB
9133 needs_plt = 1;
9134 goto normal_reloc;
9135
9136 case R_ARM_ABS32:
9137 case R_ARM_ABS32_NOI:
9138 case R_ARM_REL32:
9139 case R_ARM_REL32_NOI:
b6895b4f
PB
9140 case R_ARM_MOVW_ABS_NC:
9141 case R_ARM_MOVT_ABS:
9142 case R_ARM_MOVW_PREL_NC:
9143 case R_ARM_MOVT_PREL:
9144 case R_ARM_THM_MOVW_ABS_NC:
9145 case R_ARM_THM_MOVT_ABS:
9146 case R_ARM_THM_MOVW_PREL_NC:
9147 case R_ARM_THM_MOVT_PREL:
39623e12
PB
9148 needs_plt = 0;
9149 normal_reloc:
9150
b7693d02 9151 /* Should the interworking branches be listed here? */
7359ea65 9152 if (h != NULL)
5e681ec4
PB
9153 {
9154 /* If this reloc is in a read-only section, we might
9155 need a copy reloc. We can't check reliably at this
9156 stage whether the section is read-only, as input
9157 sections have not yet been mapped to output sections.
9158 Tentatively set the flag for now, and correct in
9159 adjust_dynamic_symbol. */
7359ea65 9160 if (!info->shared)
f5385ebf 9161 h->non_got_ref = 1;
7359ea65 9162
5e681ec4 9163 /* We may need a .plt entry if the function this reloc
c84cd8ee
DJ
9164 refers to is in a different object. We can't tell for
9165 sure yet, because something later might force the
9166 symbol local. */
39623e12 9167 if (needs_plt)
f5385ebf 9168 h->needs_plt = 1;
4f199be3
DJ
9169
9170 /* If we create a PLT entry, this relocation will reference
9171 it, even if it's an ABS32 relocation. */
9172 h->plt.refcount += 1;
b7693d02 9173
bd97cb95
DJ
9174 /* It's too early to use htab->use_blx here, so we have to
9175 record possible blx references separately from
9176 relocs that definitely need a thumb stub. */
9177
c19d1205 9178 if (r_type == R_ARM_THM_CALL)
bd97cb95
DJ
9179 eh->plt_maybe_thumb_refcount += 1;
9180
9181 if (r_type == R_ARM_THM_JUMP24
9182 || r_type == R_ARM_THM_JUMP19)
b7693d02 9183 eh->plt_thumb_refcount += 1;
5e681ec4
PB
9184 }
9185
67687978
PB
9186 /* If we are creating a shared library or relocatable executable,
9187 and this is a reloc against a global symbol, or a non PC
9188 relative reloc against a local symbol, then we need to copy
9189 the reloc into the shared library. However, if we are linking
9190 with -Bsymbolic, we do not need to copy a reloc against a
252b5132
RH
9191 global symbol which is defined in an object we are
9192 including in the link (i.e., DEF_REGULAR is set). At
9193 this point we have not seen all the input files, so it is
9194 possible that DEF_REGULAR is not set now but will be set
9195 later (it is never cleared). We account for that
9196 possibility below by storing information in the
5e681ec4 9197 relocs_copied field of the hash table entry. */
67687978 9198 if ((info->shared || htab->root.is_relocatable_executable)
5e681ec4 9199 && (sec->flags & SEC_ALLOC) != 0
bb224fc3 9200 && ((r_type == R_ARM_ABS32 || r_type == R_ARM_ABS32_NOI)
71a976dd
DJ
9201 || (h != NULL && ! h->needs_plt
9202 && (! info->symbolic || ! h->def_regular))))
252b5132 9203 {
5e681ec4
PB
9204 struct elf32_arm_relocs_copied *p, **head;
9205
252b5132
RH
9206 /* When creating a shared object, we must copy these
9207 reloc types into the output file. We create a reloc
9208 section in dynobj and make room for this reloc. */
9209 if (sreloc == NULL)
9210 {
9211 const char * name;
9212
9213 name = (bfd_elf_string_from_elf_section
9214 (abfd,
9215 elf_elfheader (abfd)->e_shstrndx,
9216 elf_section_data (sec)->rel_hdr.sh_name));
9217 if (name == NULL)
b34976b6 9218 return FALSE;
252b5132 9219
00a97672 9220 BFD_ASSERT (reloc_section_p (htab, name, sec));
252b5132
RH
9221
9222 sreloc = bfd_get_section_by_name (dynobj, name);
9223 if (sreloc == NULL)
9224 {
9225 flagword flags;
9226
252b5132
RH
9227 flags = (SEC_HAS_CONTENTS | SEC_READONLY
9228 | SEC_IN_MEMORY | SEC_LINKER_CREATED);
e5a52504
MM
9229 if ((sec->flags & SEC_ALLOC) != 0
9230 /* BPABI objects never have dynamic
9231 relocations mapped. */
9232 && !htab->symbian_p)
252b5132 9233 flags |= SEC_ALLOC | SEC_LOAD;
3496cb2a
L
9234 sreloc = bfd_make_section_with_flags (dynobj,
9235 name,
9236 flags);
252b5132 9237 if (sreloc == NULL
252b5132 9238 || ! bfd_set_section_alignment (dynobj, sreloc, 2))
b34976b6 9239 return FALSE;
252b5132 9240 }
5e681ec4
PB
9241
9242 elf_section_data (sec)->sreloc = sreloc;
252b5132
RH
9243 }
9244
5e681ec4
PB
9245 /* If this is a global symbol, we count the number of
9246 relocations we need for this symbol. */
9247 if (h != NULL)
252b5132 9248 {
5e681ec4
PB
9249 head = &((struct elf32_arm_link_hash_entry *) h)->relocs_copied;
9250 }
9251 else
9252 {
9253 /* Track dynamic relocs needed for local syms too.
9254 We really need local syms available to do this
9255 easily. Oh well. */
57e8b36a 9256
5e681ec4 9257 asection *s;
6edfbbad
DJ
9258 void *vpp;
9259
5e681ec4
PB
9260 s = bfd_section_from_r_symndx (abfd, &htab->sym_sec,
9261 sec, r_symndx);
9262 if (s == NULL)
9263 return FALSE;
57e8b36a 9264
6edfbbad
DJ
9265 vpp = &elf_section_data (s)->local_dynrel;
9266 head = (struct elf32_arm_relocs_copied **) vpp;
5e681ec4 9267 }
57e8b36a 9268
5e681ec4
PB
9269 p = *head;
9270 if (p == NULL || p->section != sec)
9271 {
9272 bfd_size_type amt = sizeof *p;
57e8b36a 9273
5e681ec4 9274 p = bfd_alloc (htab->root.dynobj, amt);
252b5132 9275 if (p == NULL)
5e681ec4
PB
9276 return FALSE;
9277 p->next = *head;
9278 *head = p;
9279 p->section = sec;
9280 p->count = 0;
ba93b8ac 9281 p->pc_count = 0;
252b5132 9282 }
57e8b36a 9283
bb224fc3 9284 if (r_type == R_ARM_REL32 || r_type == R_ARM_REL32_NOI)
ba93b8ac 9285 p->pc_count += 1;
71a976dd 9286 p->count += 1;
252b5132
RH
9287 }
9288 break;
9289
9290 /* This relocation describes the C++ object vtable hierarchy.
9291 Reconstruct it for later use during GC. */
9292 case R_ARM_GNU_VTINHERIT:
c152c796 9293 if (!bfd_elf_gc_record_vtinherit (abfd, sec, h, rel->r_offset))
b34976b6 9294 return FALSE;
252b5132 9295 break;
9a5aca8c 9296
252b5132
RH
9297 /* This relocation describes which C++ vtable entries are actually
9298 used. Record for later use during GC. */
9299 case R_ARM_GNU_VTENTRY:
d17e0c6e
JB
9300 BFD_ASSERT (h != NULL);
9301 if (h != NULL
9302 && !bfd_elf_gc_record_vtentry (abfd, sec, h, rel->r_offset))
b34976b6 9303 return FALSE;
252b5132
RH
9304 break;
9305 }
9306 }
f21f3fe0 9307
b34976b6 9308 return TRUE;
252b5132
RH
9309}
9310
6a5bb875
PB
9311/* Unwinding tables are not referenced directly. This pass marks them as
9312 required if the corresponding code section is marked. */
9313
9314static bfd_boolean
906e58ca
NC
9315elf32_arm_gc_mark_extra_sections (struct bfd_link_info *info,
9316 elf_gc_mark_hook_fn gc_mark_hook)
6a5bb875
PB
9317{
9318 bfd *sub;
9319 Elf_Internal_Shdr **elf_shdrp;
9320 bfd_boolean again;
9321
9322 /* Marking EH data may cause additional code sections to be marked,
9323 requiring multiple passes. */
9324 again = TRUE;
9325 while (again)
9326 {
9327 again = FALSE;
9328 for (sub = info->input_bfds; sub != NULL; sub = sub->link_next)
9329 {
9330 asection *o;
9331
0ffa91dd 9332 if (! is_arm_elf (sub))
6a5bb875
PB
9333 continue;
9334
9335 elf_shdrp = elf_elfsections (sub);
9336 for (o = sub->sections; o != NULL; o = o->next)
9337 {
9338 Elf_Internal_Shdr *hdr;
0ffa91dd 9339
6a5bb875 9340 hdr = &elf_section_data (o)->this_hdr;
4fbb74a6
AM
9341 if (hdr->sh_type == SHT_ARM_EXIDX
9342 && hdr->sh_link
9343 && hdr->sh_link < elf_numsections (sub)
6a5bb875
PB
9344 && !o->gc_mark
9345 && elf_shdrp[hdr->sh_link]->bfd_section->gc_mark)
9346 {
9347 again = TRUE;
9348 if (!_bfd_elf_gc_mark (info, o, gc_mark_hook))
9349 return FALSE;
9350 }
9351 }
9352 }
9353 }
9354
9355 return TRUE;
9356}
9357
3c9458e9
NC
9358/* Treat mapping symbols as special target symbols. */
9359
9360static bfd_boolean
9361elf32_arm_is_target_special_symbol (bfd * abfd ATTRIBUTE_UNUSED, asymbol * sym)
9362{
b0796911
PB
9363 return bfd_is_arm_special_symbol_name (sym->name,
9364 BFD_ARM_SPECIAL_SYM_TYPE_ANY);
3c9458e9
NC
9365}
9366
0367ecfb
NC
9367/* This is a copy of elf_find_function() from elf.c except that
9368 ARM mapping symbols are ignored when looking for function names
9369 and STT_ARM_TFUNC is considered to a function type. */
252b5132 9370
0367ecfb
NC
9371static bfd_boolean
9372arm_elf_find_function (bfd * abfd ATTRIBUTE_UNUSED,
9373 asection * section,
9374 asymbol ** symbols,
9375 bfd_vma offset,
9376 const char ** filename_ptr,
9377 const char ** functionname_ptr)
9378{
9379 const char * filename = NULL;
9380 asymbol * func = NULL;
9381 bfd_vma low_func = 0;
9382 asymbol ** p;
252b5132
RH
9383
9384 for (p = symbols; *p != NULL; p++)
9385 {
9386 elf_symbol_type *q;
9387
9388 q = (elf_symbol_type *) *p;
9389
252b5132
RH
9390 switch (ELF_ST_TYPE (q->internal_elf_sym.st_info))
9391 {
9392 default:
9393 break;
9394 case STT_FILE:
9395 filename = bfd_asymbol_name (&q->symbol);
9396 break;
252b5132
RH
9397 case STT_FUNC:
9398 case STT_ARM_TFUNC:
9d2da7ca 9399 case STT_NOTYPE:
b0796911 9400 /* Skip mapping symbols. */
0367ecfb 9401 if ((q->symbol.flags & BSF_LOCAL)
b0796911
PB
9402 && bfd_is_arm_special_symbol_name (q->symbol.name,
9403 BFD_ARM_SPECIAL_SYM_TYPE_ANY))
0367ecfb
NC
9404 continue;
9405 /* Fall through. */
6b40fcba 9406 if (bfd_get_section (&q->symbol) == section
252b5132
RH
9407 && q->symbol.value >= low_func
9408 && q->symbol.value <= offset)
9409 {
9410 func = (asymbol *) q;
9411 low_func = q->symbol.value;
9412 }
9413 break;
9414 }
9415 }
9416
9417 if (func == NULL)
b34976b6 9418 return FALSE;
252b5132 9419
0367ecfb
NC
9420 if (filename_ptr)
9421 *filename_ptr = filename;
9422 if (functionname_ptr)
9423 *functionname_ptr = bfd_asymbol_name (func);
9424
9425 return TRUE;
906e58ca 9426}
0367ecfb
NC
9427
9428
9429/* Find the nearest line to a particular section and offset, for error
9430 reporting. This code is a duplicate of the code in elf.c, except
9431 that it uses arm_elf_find_function. */
9432
9433static bfd_boolean
9434elf32_arm_find_nearest_line (bfd * abfd,
9435 asection * section,
9436 asymbol ** symbols,
9437 bfd_vma offset,
9438 const char ** filename_ptr,
9439 const char ** functionname_ptr,
9440 unsigned int * line_ptr)
9441{
9442 bfd_boolean found = FALSE;
9443
9444 /* We skip _bfd_dwarf1_find_nearest_line since no known ARM toolchain uses it. */
9445
9446 if (_bfd_dwarf2_find_nearest_line (abfd, section, symbols, offset,
9447 filename_ptr, functionname_ptr,
9448 line_ptr, 0,
9449 & elf_tdata (abfd)->dwarf2_find_line_info))
9450 {
9451 if (!*functionname_ptr)
9452 arm_elf_find_function (abfd, section, symbols, offset,
9453 *filename_ptr ? NULL : filename_ptr,
9454 functionname_ptr);
f21f3fe0 9455
0367ecfb
NC
9456 return TRUE;
9457 }
9458
9459 if (! _bfd_stab_section_find_nearest_line (abfd, symbols, section, offset,
9460 & found, filename_ptr,
9461 functionname_ptr, line_ptr,
9462 & elf_tdata (abfd)->line_info))
9463 return FALSE;
9464
9465 if (found && (*functionname_ptr || *line_ptr))
9466 return TRUE;
9467
9468 if (symbols == NULL)
9469 return FALSE;
9470
9471 if (! arm_elf_find_function (abfd, section, symbols, offset,
9472 filename_ptr, functionname_ptr))
9473 return FALSE;
9474
9475 *line_ptr = 0;
b34976b6 9476 return TRUE;
252b5132
RH
9477}
9478
4ab527b0
FF
9479static bfd_boolean
9480elf32_arm_find_inliner_info (bfd * abfd,
9481 const char ** filename_ptr,
9482 const char ** functionname_ptr,
9483 unsigned int * line_ptr)
9484{
9485 bfd_boolean found;
9486 found = _bfd_dwarf2_find_inliner_info (abfd, filename_ptr,
9487 functionname_ptr, line_ptr,
9488 & elf_tdata (abfd)->dwarf2_find_line_info);
9489 return found;
9490}
9491
252b5132
RH
9492/* Adjust a symbol defined by a dynamic object and referenced by a
9493 regular object. The current definition is in some section of the
9494 dynamic object, but we're not including those sections. We have to
9495 change the definition to something the rest of the link can
9496 understand. */
9497
b34976b6 9498static bfd_boolean
57e8b36a
NC
9499elf32_arm_adjust_dynamic_symbol (struct bfd_link_info * info,
9500 struct elf_link_hash_entry * h)
252b5132
RH
9501{
9502 bfd * dynobj;
9503 asection * s;
b7693d02 9504 struct elf32_arm_link_hash_entry * eh;
67687978 9505 struct elf32_arm_link_hash_table *globals;
252b5132 9506
67687978 9507 globals = elf32_arm_hash_table (info);
252b5132
RH
9508 dynobj = elf_hash_table (info)->dynobj;
9509
9510 /* Make sure we know what is going on here. */
9511 BFD_ASSERT (dynobj != NULL
f5385ebf 9512 && (h->needs_plt
f6e332e6 9513 || h->u.weakdef != NULL
f5385ebf
AM
9514 || (h->def_dynamic
9515 && h->ref_regular
9516 && !h->def_regular)));
252b5132 9517
b7693d02
DJ
9518 eh = (struct elf32_arm_link_hash_entry *) h;
9519
252b5132
RH
9520 /* If this is a function, put it in the procedure linkage table. We
9521 will fill in the contents of the procedure linkage table later,
9522 when we know the address of the .got section. */
b7693d02 9523 if (h->type == STT_FUNC || h->type == STT_ARM_TFUNC
f5385ebf 9524 || h->needs_plt)
252b5132 9525 {
5e681ec4
PB
9526 if (h->plt.refcount <= 0
9527 || SYMBOL_CALLS_LOCAL (info, h)
9528 || (ELF_ST_VISIBILITY (h->other) != STV_DEFAULT
9529 && h->root.type == bfd_link_hash_undefweak))
252b5132
RH
9530 {
9531 /* This case can occur if we saw a PLT32 reloc in an input
5e681ec4
PB
9532 file, but the symbol was never referred to by a dynamic
9533 object, or if all references were garbage collected. In
9534 such a case, we don't actually need to build a procedure
9535 linkage table, and we can just do a PC24 reloc instead. */
9536 h->plt.offset = (bfd_vma) -1;
b7693d02 9537 eh->plt_thumb_refcount = 0;
bd97cb95 9538 eh->plt_maybe_thumb_refcount = 0;
f5385ebf 9539 h->needs_plt = 0;
252b5132
RH
9540 }
9541
b34976b6 9542 return TRUE;
252b5132 9543 }
5e681ec4 9544 else
b7693d02
DJ
9545 {
9546 /* It's possible that we incorrectly decided a .plt reloc was
9547 needed for an R_ARM_PC24 or similar reloc to a non-function sym
9548 in check_relocs. We can't decide accurately between function
9549 and non-function syms in check-relocs; Objects loaded later in
9550 the link may change h->type. So fix it now. */
9551 h->plt.offset = (bfd_vma) -1;
9552 eh->plt_thumb_refcount = 0;
bd97cb95 9553 eh->plt_maybe_thumb_refcount = 0;
b7693d02 9554 }
252b5132
RH
9555
9556 /* If this is a weak symbol, and there is a real definition, the
9557 processor independent code will have arranged for us to see the
9558 real definition first, and we can just use the same value. */
f6e332e6 9559 if (h->u.weakdef != NULL)
252b5132 9560 {
f6e332e6
AM
9561 BFD_ASSERT (h->u.weakdef->root.type == bfd_link_hash_defined
9562 || h->u.weakdef->root.type == bfd_link_hash_defweak);
9563 h->root.u.def.section = h->u.weakdef->root.u.def.section;
9564 h->root.u.def.value = h->u.weakdef->root.u.def.value;
b34976b6 9565 return TRUE;
252b5132
RH
9566 }
9567
ba93b8ac
DJ
9568 /* If there are no non-GOT references, we do not need a copy
9569 relocation. */
9570 if (!h->non_got_ref)
9571 return TRUE;
9572
252b5132
RH
9573 /* This is a reference to a symbol defined by a dynamic object which
9574 is not a function. */
9575
9576 /* If we are creating a shared library, we must presume that the
9577 only references to the symbol are via the global offset table.
9578 For such cases we need not do anything here; the relocations will
67687978
PB
9579 be handled correctly by relocate_section. Relocatable executables
9580 can reference data in shared objects directly, so we don't need to
9581 do anything here. */
9582 if (info->shared || globals->root.is_relocatable_executable)
b34976b6 9583 return TRUE;
252b5132 9584
909272ee
AM
9585 if (h->size == 0)
9586 {
9587 (*_bfd_error_handler) (_("dynamic variable `%s' is zero size"),
9588 h->root.root.string);
9589 return TRUE;
9590 }
9591
252b5132
RH
9592 /* We must allocate the symbol in our .dynbss section, which will
9593 become part of the .bss section of the executable. There will be
9594 an entry for this symbol in the .dynsym section. The dynamic
9595 object will contain position independent code, so all references
9596 from the dynamic object to this symbol will go through the global
9597 offset table. The dynamic linker will use the .dynsym entry to
9598 determine the address it must put in the global offset table, so
9599 both the dynamic object and the regular object will refer to the
9600 same memory location for the variable. */
252b5132
RH
9601 s = bfd_get_section_by_name (dynobj, ".dynbss");
9602 BFD_ASSERT (s != NULL);
9603
9604 /* We must generate a R_ARM_COPY reloc to tell the dynamic linker to
9605 copy the initial value out of the dynamic object and into the
9606 runtime process image. We need to remember the offset into the
00a97672 9607 .rel(a).bss section we are going to use. */
252b5132
RH
9608 if ((h->root.u.def.section->flags & SEC_ALLOC) != 0)
9609 {
9610 asection *srel;
9611
00a97672 9612 srel = bfd_get_section_by_name (dynobj, RELOC_SECTION (globals, ".bss"));
252b5132 9613 BFD_ASSERT (srel != NULL);
00a97672 9614 srel->size += RELOC_SIZE (globals);
f5385ebf 9615 h->needs_copy = 1;
252b5132
RH
9616 }
9617
027297b7 9618 return _bfd_elf_adjust_dynamic_copy (h, s);
252b5132
RH
9619}
9620
5e681ec4
PB
9621/* Allocate space in .plt, .got and associated reloc sections for
9622 dynamic relocs. */
9623
9624static bfd_boolean
57e8b36a 9625allocate_dynrelocs (struct elf_link_hash_entry *h, void * inf)
5e681ec4
PB
9626{
9627 struct bfd_link_info *info;
9628 struct elf32_arm_link_hash_table *htab;
9629 struct elf32_arm_link_hash_entry *eh;
9630 struct elf32_arm_relocs_copied *p;
bd97cb95 9631 bfd_signed_vma thumb_refs;
5e681ec4 9632
b7693d02
DJ
9633 eh = (struct elf32_arm_link_hash_entry *) h;
9634
5e681ec4
PB
9635 if (h->root.type == bfd_link_hash_indirect)
9636 return TRUE;
9637
9638 if (h->root.type == bfd_link_hash_warning)
9639 /* When warning symbols are created, they **replace** the "real"
9640 entry in the hash table, thus we never get to see the real
9641 symbol in a hash traversal. So look at it now. */
9642 h = (struct elf_link_hash_entry *) h->root.u.i.link;
9643
9644 info = (struct bfd_link_info *) inf;
9645 htab = elf32_arm_hash_table (info);
9646
9647 if (htab->root.dynamic_sections_created
9648 && h->plt.refcount > 0)
9649 {
9650 /* Make sure this symbol is output as a dynamic symbol.
9651 Undefined weak syms won't yet be marked as dynamic. */
9652 if (h->dynindx == -1
f5385ebf 9653 && !h->forced_local)
5e681ec4 9654 {
c152c796 9655 if (! bfd_elf_link_record_dynamic_symbol (info, h))
5e681ec4
PB
9656 return FALSE;
9657 }
9658
9659 if (info->shared
7359ea65 9660 || WILL_CALL_FINISH_DYNAMIC_SYMBOL (1, 0, h))
5e681ec4
PB
9661 {
9662 asection *s = htab->splt;
9663
9664 /* If this is the first .plt entry, make room for the special
9665 first entry. */
eea6121a 9666 if (s->size == 0)
e5a52504 9667 s->size += htab->plt_header_size;
5e681ec4 9668
eea6121a 9669 h->plt.offset = s->size;
5e681ec4 9670
b7693d02
DJ
9671 /* If we will insert a Thumb trampoline before this PLT, leave room
9672 for it. */
bd97cb95
DJ
9673 thumb_refs = eh->plt_thumb_refcount;
9674 if (!htab->use_blx)
9675 thumb_refs += eh->plt_maybe_thumb_refcount;
9676
9677 if (thumb_refs > 0)
b7693d02
DJ
9678 {
9679 h->plt.offset += PLT_THUMB_STUB_SIZE;
9680 s->size += PLT_THUMB_STUB_SIZE;
9681 }
9682
5e681ec4
PB
9683 /* If this symbol is not defined in a regular file, and we are
9684 not generating a shared library, then set the symbol to this
9685 location in the .plt. This is required to make function
9686 pointers compare as equal between the normal executable and
9687 the shared library. */
9688 if (! info->shared
f5385ebf 9689 && !h->def_regular)
5e681ec4
PB
9690 {
9691 h->root.u.def.section = s;
9692 h->root.u.def.value = h->plt.offset;
b7693d02
DJ
9693
9694 /* Make sure the function is not marked as Thumb, in case
9695 it is the target of an ABS32 relocation, which will
9696 point to the PLT entry. */
9697 if (ELF_ST_TYPE (h->type) == STT_ARM_TFUNC)
9698 h->type = ELF_ST_INFO (ELF_ST_BIND (h->type), STT_FUNC);
5e681ec4
PB
9699 }
9700
9701 /* Make room for this entry. */
e5a52504 9702 s->size += htab->plt_entry_size;
5e681ec4 9703
e5a52504 9704 if (!htab->symbian_p)
b7693d02
DJ
9705 {
9706 /* We also need to make an entry in the .got.plt section, which
9707 will be placed in the .got section by the linker script. */
9708 eh->plt_got_offset = htab->sgotplt->size;
9709 htab->sgotplt->size += 4;
9710 }
5e681ec4 9711
00a97672
RS
9712 /* We also need to make an entry in the .rel(a).plt section. */
9713 htab->srelplt->size += RELOC_SIZE (htab);
9714
9715 /* VxWorks executables have a second set of relocations for
9716 each PLT entry. They go in a separate relocation section,
9717 which is processed by the kernel loader. */
9718 if (htab->vxworks_p && !info->shared)
9719 {
9720 /* There is a relocation for the initial PLT entry:
9721 an R_ARM_32 relocation for _GLOBAL_OFFSET_TABLE_. */
9722 if (h->plt.offset == htab->plt_header_size)
9723 htab->srelplt2->size += RELOC_SIZE (htab);
9724
9725 /* There are two extra relocations for each subsequent
9726 PLT entry: an R_ARM_32 relocation for the GOT entry,
9727 and an R_ARM_32 relocation for the PLT entry. */
9728 htab->srelplt2->size += RELOC_SIZE (htab) * 2;
9729 }
5e681ec4
PB
9730 }
9731 else
9732 {
9733 h->plt.offset = (bfd_vma) -1;
f5385ebf 9734 h->needs_plt = 0;
5e681ec4
PB
9735 }
9736 }
9737 else
9738 {
9739 h->plt.offset = (bfd_vma) -1;
f5385ebf 9740 h->needs_plt = 0;
5e681ec4
PB
9741 }
9742
9743 if (h->got.refcount > 0)
9744 {
9745 asection *s;
9746 bfd_boolean dyn;
ba93b8ac
DJ
9747 int tls_type = elf32_arm_hash_entry (h)->tls_type;
9748 int indx;
5e681ec4
PB
9749
9750 /* Make sure this symbol is output as a dynamic symbol.
9751 Undefined weak syms won't yet be marked as dynamic. */
9752 if (h->dynindx == -1
f5385ebf 9753 && !h->forced_local)
5e681ec4 9754 {
c152c796 9755 if (! bfd_elf_link_record_dynamic_symbol (info, h))
5e681ec4
PB
9756 return FALSE;
9757 }
9758
e5a52504
MM
9759 if (!htab->symbian_p)
9760 {
9761 s = htab->sgot;
9762 h->got.offset = s->size;
ba93b8ac
DJ
9763
9764 if (tls_type == GOT_UNKNOWN)
9765 abort ();
9766
9767 if (tls_type == GOT_NORMAL)
9768 /* Non-TLS symbols need one GOT slot. */
9769 s->size += 4;
9770 else
9771 {
9772 if (tls_type & GOT_TLS_GD)
9773 /* R_ARM_TLS_GD32 needs 2 consecutive GOT slots. */
9774 s->size += 8;
9775 if (tls_type & GOT_TLS_IE)
9776 /* R_ARM_TLS_IE32 needs one GOT slot. */
9777 s->size += 4;
9778 }
9779
e5a52504 9780 dyn = htab->root.dynamic_sections_created;
ba93b8ac
DJ
9781
9782 indx = 0;
9783 if (WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn, info->shared, h)
9784 && (!info->shared
9785 || !SYMBOL_REFERENCES_LOCAL (info, h)))
9786 indx = h->dynindx;
9787
9788 if (tls_type != GOT_NORMAL
9789 && (info->shared || indx != 0)
9790 && (ELF_ST_VISIBILITY (h->other) == STV_DEFAULT
9791 || h->root.type != bfd_link_hash_undefweak))
9792 {
9793 if (tls_type & GOT_TLS_IE)
00a97672 9794 htab->srelgot->size += RELOC_SIZE (htab);
ba93b8ac
DJ
9795
9796 if (tls_type & GOT_TLS_GD)
00a97672 9797 htab->srelgot->size += RELOC_SIZE (htab);
ba93b8ac
DJ
9798
9799 if ((tls_type & GOT_TLS_GD) && indx != 0)
00a97672 9800 htab->srelgot->size += RELOC_SIZE (htab);
ba93b8ac
DJ
9801 }
9802 else if ((ELF_ST_VISIBILITY (h->other) == STV_DEFAULT
9803 || h->root.type != bfd_link_hash_undefweak)
9804 && (info->shared
9805 || WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn, 0, h)))
00a97672 9806 htab->srelgot->size += RELOC_SIZE (htab);
e5a52504 9807 }
5e681ec4
PB
9808 }
9809 else
9810 h->got.offset = (bfd_vma) -1;
9811
a4fd1a8e
PB
9812 /* Allocate stubs for exported Thumb functions on v4t. */
9813 if (!htab->use_blx && h->dynindx != -1
0eaedd0e 9814 && h->def_regular
a4fd1a8e
PB
9815 && ELF_ST_TYPE (h->type) == STT_ARM_TFUNC
9816 && ELF_ST_VISIBILITY (h->other) == STV_DEFAULT)
9817 {
9818 struct elf_link_hash_entry * th;
9819 struct bfd_link_hash_entry * bh;
9820 struct elf_link_hash_entry * myh;
9821 char name[1024];
9822 asection *s;
9823 bh = NULL;
9824 /* Create a new symbol to regist the real location of the function. */
9825 s = h->root.u.def.section;
906e58ca 9826 sprintf (name, "__real_%s", h->root.root.string);
a4fd1a8e
PB
9827 _bfd_generic_link_add_one_symbol (info, s->owner,
9828 name, BSF_GLOBAL, s,
9829 h->root.u.def.value,
9830 NULL, TRUE, FALSE, &bh);
9831
9832 myh = (struct elf_link_hash_entry *) bh;
9833 myh->type = ELF_ST_INFO (STB_LOCAL, STT_ARM_TFUNC);
9834 myh->forced_local = 1;
9835 eh->export_glue = myh;
9836 th = record_arm_to_thumb_glue (info, h);
9837 /* Point the symbol at the stub. */
9838 h->type = ELF_ST_INFO (ELF_ST_BIND (h->type), STT_FUNC);
9839 h->root.u.def.section = th->root.u.def.section;
9840 h->root.u.def.value = th->root.u.def.value & ~1;
9841 }
9842
5e681ec4
PB
9843 if (eh->relocs_copied == NULL)
9844 return TRUE;
9845
9846 /* In the shared -Bsymbolic case, discard space allocated for
9847 dynamic pc-relative relocs against symbols which turn out to be
9848 defined in regular objects. For the normal shared case, discard
9849 space for pc-relative relocs that have become local due to symbol
9850 visibility changes. */
9851
67687978 9852 if (info->shared || htab->root.is_relocatable_executable)
5e681ec4 9853 {
7bdca076 9854 /* The only relocs that use pc_count are R_ARM_REL32 and
bb224fc3
MS
9855 R_ARM_REL32_NOI, which will appear on something like
9856 ".long foo - .". We want calls to protected symbols to resolve
9857 directly to the function rather than going via the plt. If people
9858 want function pointer comparisons to work as expected then they
9859 should avoid writing assembly like ".long foo - .". */
ba93b8ac
DJ
9860 if (SYMBOL_CALLS_LOCAL (info, h))
9861 {
9862 struct elf32_arm_relocs_copied **pp;
9863
9864 for (pp = &eh->relocs_copied; (p = *pp) != NULL; )
9865 {
9866 p->count -= p->pc_count;
9867 p->pc_count = 0;
9868 if (p->count == 0)
9869 *pp = p->next;
9870 else
9871 pp = &p->next;
9872 }
9873 }
9874
3348747a
NS
9875 if (elf32_arm_hash_table (info)->vxworks_p)
9876 {
9877 struct elf32_arm_relocs_copied **pp;
9878
9879 for (pp = &eh->relocs_copied; (p = *pp) != NULL; )
9880 {
9881 if (strcmp (p->section->output_section->name, ".tls_vars") == 0)
9882 *pp = p->next;
9883 else
9884 pp = &p->next;
9885 }
9886 }
9887
ba93b8ac 9888 /* Also discard relocs on undefined weak syms with non-default
7359ea65 9889 visibility. */
22d606e9 9890 if (eh->relocs_copied != NULL
5e681ec4 9891 && h->root.type == bfd_link_hash_undefweak)
22d606e9
AM
9892 {
9893 if (ELF_ST_VISIBILITY (h->other) != STV_DEFAULT)
9894 eh->relocs_copied = NULL;
9895
9896 /* Make sure undefined weak symbols are output as a dynamic
9897 symbol in PIEs. */
9898 else if (h->dynindx == -1
9899 && !h->forced_local)
9900 {
9901 if (! bfd_elf_link_record_dynamic_symbol (info, h))
9902 return FALSE;
9903 }
9904 }
9905
67687978
PB
9906 else if (htab->root.is_relocatable_executable && h->dynindx == -1
9907 && h->root.type == bfd_link_hash_new)
9908 {
9909 /* Output absolute symbols so that we can create relocations
9910 against them. For normal symbols we output a relocation
9911 against the section that contains them. */
9912 if (! bfd_elf_link_record_dynamic_symbol (info, h))
9913 return FALSE;
9914 }
9915
5e681ec4
PB
9916 }
9917 else
9918 {
9919 /* For the non-shared case, discard space for relocs against
9920 symbols which turn out to need copy relocs or are not
9921 dynamic. */
9922
f5385ebf
AM
9923 if (!h->non_got_ref
9924 && ((h->def_dynamic
9925 && !h->def_regular)
5e681ec4
PB
9926 || (htab->root.dynamic_sections_created
9927 && (h->root.type == bfd_link_hash_undefweak
9928 || h->root.type == bfd_link_hash_undefined))))
9929 {
9930 /* Make sure this symbol is output as a dynamic symbol.
9931 Undefined weak syms won't yet be marked as dynamic. */
9932 if (h->dynindx == -1
f5385ebf 9933 && !h->forced_local)
5e681ec4 9934 {
c152c796 9935 if (! bfd_elf_link_record_dynamic_symbol (info, h))
5e681ec4
PB
9936 return FALSE;
9937 }
9938
9939 /* If that succeeded, we know we'll be keeping all the
9940 relocs. */
9941 if (h->dynindx != -1)
9942 goto keep;
9943 }
9944
9945 eh->relocs_copied = NULL;
9946
9947 keep: ;
9948 }
9949
9950 /* Finally, allocate space. */
9951 for (p = eh->relocs_copied; p != NULL; p = p->next)
9952 {
9953 asection *sreloc = elf_section_data (p->section)->sreloc;
00a97672 9954 sreloc->size += p->count * RELOC_SIZE (htab);
5e681ec4
PB
9955 }
9956
9957 return TRUE;
9958}
9959
08d1f311
DJ
9960/* Find any dynamic relocs that apply to read-only sections. */
9961
9962static bfd_boolean
9963elf32_arm_readonly_dynrelocs (struct elf_link_hash_entry *h, PTR inf)
9964{
9965 struct elf32_arm_link_hash_entry *eh;
9966 struct elf32_arm_relocs_copied *p;
9967
9968 if (h->root.type == bfd_link_hash_warning)
9969 h = (struct elf_link_hash_entry *) h->root.u.i.link;
9970
9971 eh = (struct elf32_arm_link_hash_entry *) h;
9972 for (p = eh->relocs_copied; p != NULL; p = p->next)
9973 {
9974 asection *s = p->section;
9975
9976 if (s != NULL && (s->flags & SEC_READONLY) != 0)
9977 {
9978 struct bfd_link_info *info = (struct bfd_link_info *) inf;
9979
9980 info->flags |= DF_TEXTREL;
9981
9982 /* Not an error, just cut short the traversal. */
9983 return FALSE;
9984 }
9985 }
9986 return TRUE;
9987}
9988
d504ffc8
DJ
9989void
9990bfd_elf32_arm_set_byteswap_code (struct bfd_link_info *info,
9991 int byteswap_code)
9992{
9993 struct elf32_arm_link_hash_table *globals;
9994
9995 globals = elf32_arm_hash_table (info);
9996 globals->byteswap_code = byteswap_code;
9997}
9998
252b5132
RH
9999/* Set the sizes of the dynamic sections. */
10000
b34976b6 10001static bfd_boolean
57e8b36a
NC
10002elf32_arm_size_dynamic_sections (bfd * output_bfd ATTRIBUTE_UNUSED,
10003 struct bfd_link_info * info)
252b5132
RH
10004{
10005 bfd * dynobj;
10006 asection * s;
b34976b6
AM
10007 bfd_boolean plt;
10008 bfd_boolean relocs;
5e681ec4
PB
10009 bfd *ibfd;
10010 struct elf32_arm_link_hash_table *htab;
252b5132 10011
5e681ec4 10012 htab = elf32_arm_hash_table (info);
252b5132
RH
10013 dynobj = elf_hash_table (info)->dynobj;
10014 BFD_ASSERT (dynobj != NULL);
39b41c9c 10015 check_use_blx (htab);
252b5132
RH
10016
10017 if (elf_hash_table (info)->dynamic_sections_created)
10018 {
10019 /* Set the contents of the .interp section to the interpreter. */
893c4fe2 10020 if (info->executable)
252b5132
RH
10021 {
10022 s = bfd_get_section_by_name (dynobj, ".interp");
10023 BFD_ASSERT (s != NULL);
eea6121a 10024 s->size = sizeof ELF_DYNAMIC_INTERPRETER;
252b5132
RH
10025 s->contents = (unsigned char *) ELF_DYNAMIC_INTERPRETER;
10026 }
10027 }
5e681ec4
PB
10028
10029 /* Set up .got offsets for local syms, and space for local dynamic
10030 relocs. */
10031 for (ibfd = info->input_bfds; ibfd != NULL; ibfd = ibfd->link_next)
252b5132 10032 {
5e681ec4
PB
10033 bfd_signed_vma *local_got;
10034 bfd_signed_vma *end_local_got;
10035 char *local_tls_type;
10036 bfd_size_type locsymcount;
10037 Elf_Internal_Shdr *symtab_hdr;
10038 asection *srel;
3348747a 10039 bfd_boolean is_vxworks = elf32_arm_hash_table (info)->vxworks_p;
5e681ec4 10040
0ffa91dd 10041 if (! is_arm_elf (ibfd))
5e681ec4
PB
10042 continue;
10043
10044 for (s = ibfd->sections; s != NULL; s = s->next)
10045 {
10046 struct elf32_arm_relocs_copied *p;
10047
6edfbbad 10048 for (p = elf_section_data (s)->local_dynrel; p != NULL; p = p->next)
5e681ec4
PB
10049 {
10050 if (!bfd_is_abs_section (p->section)
10051 && bfd_is_abs_section (p->section->output_section))
10052 {
10053 /* Input section has been discarded, either because
10054 it is a copy of a linkonce section or due to
10055 linker script /DISCARD/, so we'll be discarding
10056 the relocs too. */
10057 }
3348747a
NS
10058 else if (is_vxworks
10059 && strcmp (p->section->output_section->name,
10060 ".tls_vars") == 0)
10061 {
10062 /* Relocations in vxworks .tls_vars sections are
10063 handled specially by the loader. */
10064 }
5e681ec4
PB
10065 else if (p->count != 0)
10066 {
10067 srel = elf_section_data (p->section)->sreloc;
00a97672 10068 srel->size += p->count * RELOC_SIZE (htab);
5e681ec4
PB
10069 if ((p->section->output_section->flags & SEC_READONLY) != 0)
10070 info->flags |= DF_TEXTREL;
10071 }
10072 }
10073 }
10074
10075 local_got = elf_local_got_refcounts (ibfd);
10076 if (!local_got)
10077 continue;
10078
0ffa91dd 10079 symtab_hdr = & elf_symtab_hdr (ibfd);
5e681ec4
PB
10080 locsymcount = symtab_hdr->sh_info;
10081 end_local_got = local_got + locsymcount;
ba93b8ac 10082 local_tls_type = elf32_arm_local_got_tls_type (ibfd);
5e681ec4
PB
10083 s = htab->sgot;
10084 srel = htab->srelgot;
10085 for (; local_got < end_local_got; ++local_got, ++local_tls_type)
10086 {
10087 if (*local_got > 0)
10088 {
eea6121a 10089 *local_got = s->size;
ba93b8ac
DJ
10090 if (*local_tls_type & GOT_TLS_GD)
10091 /* TLS_GD relocs need an 8-byte structure in the GOT. */
10092 s->size += 8;
10093 if (*local_tls_type & GOT_TLS_IE)
10094 s->size += 4;
10095 if (*local_tls_type == GOT_NORMAL)
10096 s->size += 4;
10097
10098 if (info->shared || *local_tls_type == GOT_TLS_GD)
00a97672 10099 srel->size += RELOC_SIZE (htab);
5e681ec4
PB
10100 }
10101 else
10102 *local_got = (bfd_vma) -1;
10103 }
252b5132
RH
10104 }
10105
ba93b8ac
DJ
10106 if (htab->tls_ldm_got.refcount > 0)
10107 {
10108 /* Allocate two GOT entries and one dynamic relocation (if necessary)
10109 for R_ARM_TLS_LDM32 relocations. */
10110 htab->tls_ldm_got.offset = htab->sgot->size;
10111 htab->sgot->size += 8;
10112 if (info->shared)
00a97672 10113 htab->srelgot->size += RELOC_SIZE (htab);
ba93b8ac
DJ
10114 }
10115 else
10116 htab->tls_ldm_got.offset = -1;
10117
5e681ec4
PB
10118 /* Allocate global sym .plt and .got entries, and space for global
10119 sym dynamic relocs. */
57e8b36a 10120 elf_link_hash_traverse (& htab->root, allocate_dynrelocs, info);
252b5132 10121
d504ffc8
DJ
10122 /* Here we rummage through the found bfds to collect glue information. */
10123 for (ibfd = info->input_bfds; ibfd != NULL; ibfd = ibfd->link_next)
c7b8f16e 10124 {
0ffa91dd 10125 if (! is_arm_elf (ibfd))
e44a2c9c
AM
10126 continue;
10127
c7b8f16e
JB
10128 /* Initialise mapping tables for code/data. */
10129 bfd_elf32_arm_init_maps (ibfd);
906e58ca 10130
c7b8f16e
JB
10131 if (!bfd_elf32_arm_process_before_allocation (ibfd, info)
10132 || !bfd_elf32_arm_vfp11_erratum_scan (ibfd, info))
10133 /* xgettext:c-format */
10134 _bfd_error_handler (_("Errors encountered processing file %s"),
10135 ibfd->filename);
10136 }
d504ffc8 10137
252b5132
RH
10138 /* The check_relocs and adjust_dynamic_symbol entry points have
10139 determined the sizes of the various dynamic sections. Allocate
10140 memory for them. */
b34976b6
AM
10141 plt = FALSE;
10142 relocs = FALSE;
252b5132
RH
10143 for (s = dynobj->sections; s != NULL; s = s->next)
10144 {
10145 const char * name;
252b5132
RH
10146
10147 if ((s->flags & SEC_LINKER_CREATED) == 0)
10148 continue;
10149
10150 /* It's OK to base decisions on the section name, because none
10151 of the dynobj section names depend upon the input files. */
10152 name = bfd_get_section_name (dynobj, s);
10153
24a1ba0f 10154 if (strcmp (name, ".plt") == 0)
252b5132 10155 {
c456f082
AM
10156 /* Remember whether there is a PLT. */
10157 plt = s->size != 0;
252b5132 10158 }
0112cd26 10159 else if (CONST_STRNEQ (name, ".rel"))
252b5132 10160 {
c456f082 10161 if (s->size != 0)
252b5132 10162 {
252b5132 10163 /* Remember whether there are any reloc sections other
00a97672
RS
10164 than .rel(a).plt and .rela.plt.unloaded. */
10165 if (s != htab->srelplt && s != htab->srelplt2)
b34976b6 10166 relocs = TRUE;
252b5132
RH
10167
10168 /* We use the reloc_count field as a counter if we need
10169 to copy relocs into the output file. */
10170 s->reloc_count = 0;
10171 }
10172 }
0112cd26 10173 else if (! CONST_STRNEQ (name, ".got")
c456f082 10174 && strcmp (name, ".dynbss") != 0)
252b5132
RH
10175 {
10176 /* It's not one of our sections, so don't allocate space. */
10177 continue;
10178 }
10179
c456f082 10180 if (s->size == 0)
252b5132 10181 {
c456f082 10182 /* If we don't need this section, strip it from the
00a97672
RS
10183 output file. This is mostly to handle .rel(a).bss and
10184 .rel(a).plt. We must create both sections in
c456f082
AM
10185 create_dynamic_sections, because they must be created
10186 before the linker maps input sections to output
10187 sections. The linker does that before
10188 adjust_dynamic_symbol is called, and it is that
10189 function which decides whether anything needs to go
10190 into these sections. */
8423293d 10191 s->flags |= SEC_EXCLUDE;
252b5132
RH
10192 continue;
10193 }
10194
c456f082
AM
10195 if ((s->flags & SEC_HAS_CONTENTS) == 0)
10196 continue;
10197
252b5132 10198 /* Allocate memory for the section contents. */
906e58ca 10199 s->contents = bfd_zalloc (dynobj, s->size);
c456f082 10200 if (s->contents == NULL)
b34976b6 10201 return FALSE;
252b5132
RH
10202 }
10203
10204 if (elf_hash_table (info)->dynamic_sections_created)
10205 {
10206 /* Add some entries to the .dynamic section. We fill in the
10207 values later, in elf32_arm_finish_dynamic_sections, but we
10208 must add the entries now so that we get the correct size for
10209 the .dynamic section. The DT_DEBUG entry is filled in by the
10210 dynamic linker and used by the debugger. */
dc810e39 10211#define add_dynamic_entry(TAG, VAL) \
5a580b3a 10212 _bfd_elf_add_dynamic_entry (info, TAG, VAL)
dc810e39 10213
8532796c 10214 if (info->executable)
252b5132 10215 {
dc810e39 10216 if (!add_dynamic_entry (DT_DEBUG, 0))
b34976b6 10217 return FALSE;
252b5132
RH
10218 }
10219
10220 if (plt)
10221 {
dc810e39
AM
10222 if ( !add_dynamic_entry (DT_PLTGOT, 0)
10223 || !add_dynamic_entry (DT_PLTRELSZ, 0)
00a97672
RS
10224 || !add_dynamic_entry (DT_PLTREL,
10225 htab->use_rel ? DT_REL : DT_RELA)
dc810e39 10226 || !add_dynamic_entry (DT_JMPREL, 0))
b34976b6 10227 return FALSE;
252b5132
RH
10228 }
10229
10230 if (relocs)
10231 {
00a97672
RS
10232 if (htab->use_rel)
10233 {
10234 if (!add_dynamic_entry (DT_REL, 0)
10235 || !add_dynamic_entry (DT_RELSZ, 0)
10236 || !add_dynamic_entry (DT_RELENT, RELOC_SIZE (htab)))
10237 return FALSE;
10238 }
10239 else
10240 {
10241 if (!add_dynamic_entry (DT_RELA, 0)
10242 || !add_dynamic_entry (DT_RELASZ, 0)
10243 || !add_dynamic_entry (DT_RELAENT, RELOC_SIZE (htab)))
10244 return FALSE;
10245 }
252b5132
RH
10246 }
10247
08d1f311
DJ
10248 /* If any dynamic relocs apply to a read-only section,
10249 then we need a DT_TEXTREL entry. */
10250 if ((info->flags & DF_TEXTREL) == 0)
10251 elf_link_hash_traverse (&htab->root, elf32_arm_readonly_dynrelocs,
10252 (PTR) info);
10253
99e4ae17 10254 if ((info->flags & DF_TEXTREL) != 0)
252b5132 10255 {
dc810e39 10256 if (!add_dynamic_entry (DT_TEXTREL, 0))
b34976b6 10257 return FALSE;
252b5132 10258 }
7a2b07ff
NS
10259 if (htab->vxworks_p
10260 && !elf_vxworks_add_dynamic_entries (output_bfd, info))
10261 return FALSE;
252b5132 10262 }
8532796c 10263#undef add_dynamic_entry
252b5132 10264
b34976b6 10265 return TRUE;
252b5132
RH
10266}
10267
252b5132
RH
10268/* Finish up dynamic symbol handling. We set the contents of various
10269 dynamic sections here. */
10270
b34976b6 10271static bfd_boolean
906e58ca
NC
10272elf32_arm_finish_dynamic_symbol (bfd * output_bfd,
10273 struct bfd_link_info * info,
10274 struct elf_link_hash_entry * h,
10275 Elf_Internal_Sym * sym)
252b5132
RH
10276{
10277 bfd * dynobj;
e5a52504 10278 struct elf32_arm_link_hash_table *htab;
b7693d02 10279 struct elf32_arm_link_hash_entry *eh;
252b5132
RH
10280
10281 dynobj = elf_hash_table (info)->dynobj;
e5a52504 10282 htab = elf32_arm_hash_table (info);
b7693d02 10283 eh = (struct elf32_arm_link_hash_entry *) h;
252b5132
RH
10284
10285 if (h->plt.offset != (bfd_vma) -1)
10286 {
10287 asection * splt;
252b5132 10288 asection * srel;
e5a52504 10289 bfd_byte *loc;
24a1ba0f 10290 bfd_vma plt_index;
947216bf 10291 Elf_Internal_Rela rel;
252b5132
RH
10292
10293 /* This symbol has an entry in the procedure linkage table. Set
10294 it up. */
10295
10296 BFD_ASSERT (h->dynindx != -1);
10297
10298 splt = bfd_get_section_by_name (dynobj, ".plt");
00a97672 10299 srel = bfd_get_section_by_name (dynobj, RELOC_SECTION (htab, ".plt"));
e5a52504 10300 BFD_ASSERT (splt != NULL && srel != NULL);
252b5132 10301
e5a52504
MM
10302 /* Fill in the entry in the procedure linkage table. */
10303 if (htab->symbian_p)
10304 {
906e58ca 10305 put_arm_insn (htab, output_bfd,
52ab56c2
PB
10306 elf32_arm_symbian_plt_entry[0],
10307 splt->contents + h->plt.offset);
906e58ca 10308 bfd_put_32 (output_bfd,
52ab56c2
PB
10309 elf32_arm_symbian_plt_entry[1],
10310 splt->contents + h->plt.offset + 4);
906e58ca 10311
e5a52504 10312 /* Fill in the entry in the .rel.plt section. */
2a1b9a48
MM
10313 rel.r_offset = (splt->output_section->vma
10314 + splt->output_offset
52ab56c2 10315 + h->plt.offset + 4);
e5a52504 10316 rel.r_info = ELF32_R_INFO (h->dynindx, R_ARM_GLOB_DAT);
b7693d02
DJ
10317
10318 /* Get the index in the procedure linkage table which
10319 corresponds to this symbol. This is the index of this symbol
10320 in all the symbols for which we are making plt entries. The
10321 first entry in the procedure linkage table is reserved. */
906e58ca 10322 plt_index = ((h->plt.offset - htab->plt_header_size)
b7693d02 10323 / htab->plt_entry_size);
e5a52504
MM
10324 }
10325 else
10326 {
00a97672 10327 bfd_vma got_offset, got_address, plt_address;
e5a52504
MM
10328 bfd_vma got_displacement;
10329 asection * sgot;
52ab56c2 10330 bfd_byte * ptr;
906e58ca 10331
e5a52504
MM
10332 sgot = bfd_get_section_by_name (dynobj, ".got.plt");
10333 BFD_ASSERT (sgot != NULL);
10334
b7693d02
DJ
10335 /* Get the offset into the .got.plt table of the entry that
10336 corresponds to this function. */
10337 got_offset = eh->plt_got_offset;
10338
10339 /* Get the index in the procedure linkage table which
10340 corresponds to this symbol. This is the index of this symbol
10341 in all the symbols for which we are making plt entries. The
10342 first three entries in .got.plt are reserved; after that
10343 symbols appear in the same order as in .plt. */
10344 plt_index = (got_offset - 12) / 4;
e5a52504 10345
00a97672
RS
10346 /* Calculate the address of the GOT entry. */
10347 got_address = (sgot->output_section->vma
10348 + sgot->output_offset
10349 + got_offset);
5e681ec4 10350
00a97672
RS
10351 /* ...and the address of the PLT entry. */
10352 plt_address = (splt->output_section->vma
10353 + splt->output_offset
10354 + h->plt.offset);
5e681ec4 10355
52ab56c2 10356 ptr = htab->splt->contents + h->plt.offset;
00a97672
RS
10357 if (htab->vxworks_p && info->shared)
10358 {
10359 unsigned int i;
10360 bfd_vma val;
10361
52ab56c2 10362 for (i = 0; i != htab->plt_entry_size / 4; i++, ptr += 4)
00a97672
RS
10363 {
10364 val = elf32_arm_vxworks_shared_plt_entry[i];
10365 if (i == 2)
10366 val |= got_address - sgot->output_section->vma;
10367 if (i == 5)
10368 val |= plt_index * RELOC_SIZE (htab);
52ab56c2
PB
10369 if (i == 2 || i == 5)
10370 bfd_put_32 (output_bfd, val, ptr);
10371 else
10372 put_arm_insn (htab, output_bfd, val, ptr);
00a97672
RS
10373 }
10374 }
10375 else if (htab->vxworks_p)
b7693d02 10376 {
00a97672
RS
10377 unsigned int i;
10378 bfd_vma val;
10379
d3753b85 10380 for (i = 0; i != htab->plt_entry_size / 4; i++, ptr += 4)
00a97672
RS
10381 {
10382 val = elf32_arm_vxworks_exec_plt_entry[i];
10383 if (i == 2)
10384 val |= got_address;
10385 if (i == 4)
10386 val |= 0xffffff & -((h->plt.offset + i * 4 + 8) >> 2);
10387 if (i == 5)
10388 val |= plt_index * RELOC_SIZE (htab);
52ab56c2
PB
10389 if (i == 2 || i == 5)
10390 bfd_put_32 (output_bfd, val, ptr);
10391 else
10392 put_arm_insn (htab, output_bfd, val, ptr);
00a97672
RS
10393 }
10394
10395 loc = (htab->srelplt2->contents
10396 + (plt_index * 2 + 1) * RELOC_SIZE (htab));
10397
10398 /* Create the .rela.plt.unloaded R_ARM_ABS32 relocation
10399 referencing the GOT for this PLT entry. */
10400 rel.r_offset = plt_address + 8;
10401 rel.r_info = ELF32_R_INFO (htab->root.hgot->indx, R_ARM_ABS32);
10402 rel.r_addend = got_offset;
10403 SWAP_RELOC_OUT (htab) (output_bfd, &rel, loc);
10404 loc += RELOC_SIZE (htab);
10405
10406 /* Create the R_ARM_ABS32 relocation referencing the
10407 beginning of the PLT for this GOT entry. */
10408 rel.r_offset = got_address;
10409 rel.r_info = ELF32_R_INFO (htab->root.hplt->indx, R_ARM_ABS32);
10410 rel.r_addend = 0;
10411 SWAP_RELOC_OUT (htab) (output_bfd, &rel, loc);
b7693d02 10412 }
00a97672
RS
10413 else
10414 {
bd97cb95 10415 bfd_signed_vma thumb_refs;
00a97672
RS
10416 /* Calculate the displacement between the PLT slot and the
10417 entry in the GOT. The eight-byte offset accounts for the
10418 value produced by adding to pc in the first instruction
10419 of the PLT stub. */
10420 got_displacement = got_address - (plt_address + 8);
b7693d02 10421
00a97672
RS
10422 BFD_ASSERT ((got_displacement & 0xf0000000) == 0);
10423
bd97cb95
DJ
10424 thumb_refs = eh->plt_thumb_refcount;
10425 if (!htab->use_blx)
10426 thumb_refs += eh->plt_maybe_thumb_refcount;
10427
10428 if (thumb_refs > 0)
00a97672 10429 {
52ab56c2
PB
10430 put_thumb_insn (htab, output_bfd,
10431 elf32_arm_plt_thumb_stub[0], ptr - 4);
10432 put_thumb_insn (htab, output_bfd,
10433 elf32_arm_plt_thumb_stub[1], ptr - 2);
00a97672
RS
10434 }
10435
52ab56c2
PB
10436 put_arm_insn (htab, output_bfd,
10437 elf32_arm_plt_entry[0]
10438 | ((got_displacement & 0x0ff00000) >> 20),
10439 ptr + 0);
10440 put_arm_insn (htab, output_bfd,
10441 elf32_arm_plt_entry[1]
10442 | ((got_displacement & 0x000ff000) >> 12),
10443 ptr+ 4);
10444 put_arm_insn (htab, output_bfd,
10445 elf32_arm_plt_entry[2]
10446 | (got_displacement & 0x00000fff),
10447 ptr + 8);
5e681ec4 10448#ifdef FOUR_WORD_PLT
52ab56c2 10449 bfd_put_32 (output_bfd, elf32_arm_plt_entry[3], ptr + 12);
5e681ec4 10450#endif
00a97672 10451 }
252b5132 10452
e5a52504
MM
10453 /* Fill in the entry in the global offset table. */
10454 bfd_put_32 (output_bfd,
10455 (splt->output_section->vma
10456 + splt->output_offset),
10457 sgot->contents + got_offset);
906e58ca 10458
00a97672
RS
10459 /* Fill in the entry in the .rel(a).plt section. */
10460 rel.r_addend = 0;
10461 rel.r_offset = got_address;
e5a52504
MM
10462 rel.r_info = ELF32_R_INFO (h->dynindx, R_ARM_JUMP_SLOT);
10463 }
57e8b36a 10464
00a97672
RS
10465 loc = srel->contents + plt_index * RELOC_SIZE (htab);
10466 SWAP_RELOC_OUT (htab) (output_bfd, &rel, loc);
252b5132 10467
f5385ebf 10468 if (!h->def_regular)
252b5132
RH
10469 {
10470 /* Mark the symbol as undefined, rather than as defined in
10471 the .plt section. Leave the value alone. */
10472 sym->st_shndx = SHN_UNDEF;
d982ba73
PB
10473 /* If the symbol is weak, we do need to clear the value.
10474 Otherwise, the PLT entry would provide a definition for
10475 the symbol even if the symbol wasn't defined anywhere,
10476 and so the symbol would never be NULL. */
f5385ebf 10477 if (!h->ref_regular_nonweak)
d982ba73 10478 sym->st_value = 0;
252b5132
RH
10479 }
10480 }
10481
ba93b8ac
DJ
10482 if (h->got.offset != (bfd_vma) -1
10483 && (elf32_arm_hash_entry (h)->tls_type & GOT_TLS_GD) == 0
10484 && (elf32_arm_hash_entry (h)->tls_type & GOT_TLS_IE) == 0)
252b5132
RH
10485 {
10486 asection * sgot;
10487 asection * srel;
947216bf
AM
10488 Elf_Internal_Rela rel;
10489 bfd_byte *loc;
00a97672 10490 bfd_vma offset;
252b5132
RH
10491
10492 /* This symbol has an entry in the global offset table. Set it
10493 up. */
252b5132 10494 sgot = bfd_get_section_by_name (dynobj, ".got");
00a97672 10495 srel = bfd_get_section_by_name (dynobj, RELOC_SECTION (htab, ".got"));
252b5132
RH
10496 BFD_ASSERT (sgot != NULL && srel != NULL);
10497
00a97672
RS
10498 offset = (h->got.offset & ~(bfd_vma) 1);
10499 rel.r_addend = 0;
252b5132
RH
10500 rel.r_offset = (sgot->output_section->vma
10501 + sgot->output_offset
00a97672 10502 + offset);
252b5132 10503
5e681ec4
PB
10504 /* If this is a static link, or it is a -Bsymbolic link and the
10505 symbol is defined locally or was forced to be local because
10506 of a version file, we just want to emit a RELATIVE reloc.
10507 The entry in the global offset table will already have been
10508 initialized in the relocate_section function. */
252b5132 10509 if (info->shared
5e681ec4
PB
10510 && SYMBOL_REFERENCES_LOCAL (info, h))
10511 {
906e58ca 10512 BFD_ASSERT ((h->got.offset & 1) != 0);
5e681ec4 10513 rel.r_info = ELF32_R_INFO (0, R_ARM_RELATIVE);
00a97672
RS
10514 if (!htab->use_rel)
10515 {
10516 rel.r_addend = bfd_get_32 (output_bfd, sgot->contents + offset);
10517 bfd_put_32 (output_bfd, (bfd_vma) 0, sgot->contents + offset);
10518 }
5e681ec4 10519 }
252b5132
RH
10520 else
10521 {
906e58ca 10522 BFD_ASSERT ((h->got.offset & 1) == 0);
00a97672 10523 bfd_put_32 (output_bfd, (bfd_vma) 0, sgot->contents + offset);
252b5132
RH
10524 rel.r_info = ELF32_R_INFO (h->dynindx, R_ARM_GLOB_DAT);
10525 }
10526
00a97672
RS
10527 loc = srel->contents + srel->reloc_count++ * RELOC_SIZE (htab);
10528 SWAP_RELOC_OUT (htab) (output_bfd, &rel, loc);
252b5132
RH
10529 }
10530
f5385ebf 10531 if (h->needs_copy)
252b5132
RH
10532 {
10533 asection * s;
947216bf
AM
10534 Elf_Internal_Rela rel;
10535 bfd_byte *loc;
252b5132
RH
10536
10537 /* This symbol needs a copy reloc. Set it up. */
252b5132
RH
10538 BFD_ASSERT (h->dynindx != -1
10539 && (h->root.type == bfd_link_hash_defined
10540 || h->root.type == bfd_link_hash_defweak));
10541
10542 s = bfd_get_section_by_name (h->root.u.def.section->owner,
00a97672 10543 RELOC_SECTION (htab, ".bss"));
252b5132
RH
10544 BFD_ASSERT (s != NULL);
10545
00a97672 10546 rel.r_addend = 0;
252b5132
RH
10547 rel.r_offset = (h->root.u.def.value
10548 + h->root.u.def.section->output_section->vma
10549 + h->root.u.def.section->output_offset);
10550 rel.r_info = ELF32_R_INFO (h->dynindx, R_ARM_COPY);
00a97672
RS
10551 loc = s->contents + s->reloc_count++ * RELOC_SIZE (htab);
10552 SWAP_RELOC_OUT (htab) (output_bfd, &rel, loc);
252b5132
RH
10553 }
10554
00a97672
RS
10555 /* Mark _DYNAMIC and _GLOBAL_OFFSET_TABLE_ as absolute. On VxWorks,
10556 the _GLOBAL_OFFSET_TABLE_ symbol is not absolute: it is relative
10557 to the ".got" section. */
252b5132 10558 if (strcmp (h->root.root.string, "_DYNAMIC") == 0
00a97672 10559 || (!htab->vxworks_p && h == htab->root.hgot))
252b5132
RH
10560 sym->st_shndx = SHN_ABS;
10561
b34976b6 10562 return TRUE;
252b5132
RH
10563}
10564
10565/* Finish up the dynamic sections. */
10566
b34976b6 10567static bfd_boolean
57e8b36a 10568elf32_arm_finish_dynamic_sections (bfd * output_bfd, struct bfd_link_info * info)
252b5132
RH
10569{
10570 bfd * dynobj;
10571 asection * sgot;
10572 asection * sdyn;
10573
10574 dynobj = elf_hash_table (info)->dynobj;
10575
10576 sgot = bfd_get_section_by_name (dynobj, ".got.plt");
229fcec5 10577 BFD_ASSERT (elf32_arm_hash_table (info)->symbian_p || sgot != NULL);
252b5132
RH
10578 sdyn = bfd_get_section_by_name (dynobj, ".dynamic");
10579
10580 if (elf_hash_table (info)->dynamic_sections_created)
10581 {
10582 asection *splt;
10583 Elf32_External_Dyn *dyncon, *dynconend;
229fcec5 10584 struct elf32_arm_link_hash_table *htab;
252b5132 10585
229fcec5 10586 htab = elf32_arm_hash_table (info);
252b5132 10587 splt = bfd_get_section_by_name (dynobj, ".plt");
24a1ba0f 10588 BFD_ASSERT (splt != NULL && sdyn != NULL);
252b5132
RH
10589
10590 dyncon = (Elf32_External_Dyn *) sdyn->contents;
eea6121a 10591 dynconend = (Elf32_External_Dyn *) (sdyn->contents + sdyn->size);
9b485d32 10592
252b5132
RH
10593 for (; dyncon < dynconend; dyncon++)
10594 {
10595 Elf_Internal_Dyn dyn;
10596 const char * name;
10597 asection * s;
10598
10599 bfd_elf32_swap_dyn_in (dynobj, dyncon, &dyn);
10600
10601 switch (dyn.d_tag)
10602 {
229fcec5
MM
10603 unsigned int type;
10604
252b5132 10605 default:
7a2b07ff
NS
10606 if (htab->vxworks_p
10607 && elf_vxworks_finish_dynamic_entry (output_bfd, &dyn))
10608 bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon);
252b5132
RH
10609 break;
10610
229fcec5
MM
10611 case DT_HASH:
10612 name = ".hash";
10613 goto get_vma_if_bpabi;
10614 case DT_STRTAB:
10615 name = ".dynstr";
10616 goto get_vma_if_bpabi;
10617 case DT_SYMTAB:
10618 name = ".dynsym";
10619 goto get_vma_if_bpabi;
c0042f5d
MM
10620 case DT_VERSYM:
10621 name = ".gnu.version";
10622 goto get_vma_if_bpabi;
10623 case DT_VERDEF:
10624 name = ".gnu.version_d";
10625 goto get_vma_if_bpabi;
10626 case DT_VERNEED:
10627 name = ".gnu.version_r";
10628 goto get_vma_if_bpabi;
10629
252b5132
RH
10630 case DT_PLTGOT:
10631 name = ".got";
10632 goto get_vma;
10633 case DT_JMPREL:
00a97672 10634 name = RELOC_SECTION (htab, ".plt");
252b5132
RH
10635 get_vma:
10636 s = bfd_get_section_by_name (output_bfd, name);
10637 BFD_ASSERT (s != NULL);
229fcec5
MM
10638 if (!htab->symbian_p)
10639 dyn.d_un.d_ptr = s->vma;
10640 else
10641 /* In the BPABI, tags in the PT_DYNAMIC section point
10642 at the file offset, not the memory address, for the
10643 convenience of the post linker. */
10644 dyn.d_un.d_ptr = s->filepos;
252b5132
RH
10645 bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon);
10646 break;
10647
229fcec5
MM
10648 get_vma_if_bpabi:
10649 if (htab->symbian_p)
10650 goto get_vma;
10651 break;
10652
252b5132 10653 case DT_PLTRELSZ:
00a97672
RS
10654 s = bfd_get_section_by_name (output_bfd,
10655 RELOC_SECTION (htab, ".plt"));
252b5132 10656 BFD_ASSERT (s != NULL);
eea6121a 10657 dyn.d_un.d_val = s->size;
252b5132
RH
10658 bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon);
10659 break;
906e58ca 10660
252b5132 10661 case DT_RELSZ:
00a97672 10662 case DT_RELASZ:
229fcec5
MM
10663 if (!htab->symbian_p)
10664 {
10665 /* My reading of the SVR4 ABI indicates that the
10666 procedure linkage table relocs (DT_JMPREL) should be
10667 included in the overall relocs (DT_REL). This is
10668 what Solaris does. However, UnixWare can not handle
10669 that case. Therefore, we override the DT_RELSZ entry
10670 here to make it not include the JMPREL relocs. Since
00a97672 10671 the linker script arranges for .rel(a).plt to follow all
229fcec5
MM
10672 other relocation sections, we don't have to worry
10673 about changing the DT_REL entry. */
00a97672
RS
10674 s = bfd_get_section_by_name (output_bfd,
10675 RELOC_SECTION (htab, ".plt"));
229fcec5
MM
10676 if (s != NULL)
10677 dyn.d_un.d_val -= s->size;
10678 bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon);
10679 break;
10680 }
10681 /* Fall through */
10682
10683 case DT_REL:
10684 case DT_RELA:
229fcec5
MM
10685 /* In the BPABI, the DT_REL tag must point at the file
10686 offset, not the VMA, of the first relocation
10687 section. So, we use code similar to that in
10688 elflink.c, but do not check for SHF_ALLOC on the
10689 relcoation section, since relocations sections are
10690 never allocated under the BPABI. The comments above
10691 about Unixware notwithstanding, we include all of the
10692 relocations here. */
10693 if (htab->symbian_p)
10694 {
10695 unsigned int i;
10696 type = ((dyn.d_tag == DT_REL || dyn.d_tag == DT_RELSZ)
10697 ? SHT_REL : SHT_RELA);
10698 dyn.d_un.d_val = 0;
10699 for (i = 1; i < elf_numsections (output_bfd); i++)
10700 {
906e58ca 10701 Elf_Internal_Shdr *hdr
229fcec5
MM
10702 = elf_elfsections (output_bfd)[i];
10703 if (hdr->sh_type == type)
10704 {
906e58ca 10705 if (dyn.d_tag == DT_RELSZ
229fcec5
MM
10706 || dyn.d_tag == DT_RELASZ)
10707 dyn.d_un.d_val += hdr->sh_size;
de52dba4
AM
10708 else if ((ufile_ptr) hdr->sh_offset
10709 <= dyn.d_un.d_val - 1)
229fcec5
MM
10710 dyn.d_un.d_val = hdr->sh_offset;
10711 }
10712 }
10713 bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon);
10714 }
252b5132 10715 break;
88f7bcd5
NC
10716
10717 /* Set the bottom bit of DT_INIT/FINI if the
10718 corresponding function is Thumb. */
10719 case DT_INIT:
10720 name = info->init_function;
10721 goto get_sym;
10722 case DT_FINI:
10723 name = info->fini_function;
10724 get_sym:
10725 /* If it wasn't set by elf_bfd_final_link
4cc11e76 10726 then there is nothing to adjust. */
88f7bcd5
NC
10727 if (dyn.d_un.d_val != 0)
10728 {
10729 struct elf_link_hash_entry * eh;
10730
10731 eh = elf_link_hash_lookup (elf_hash_table (info), name,
b34976b6 10732 FALSE, FALSE, TRUE);
906e58ca 10733 if (eh != NULL
88f7bcd5
NC
10734 && ELF_ST_TYPE (eh->type) == STT_ARM_TFUNC)
10735 {
10736 dyn.d_un.d_val |= 1;
b34976b6 10737 bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon);
88f7bcd5
NC
10738 }
10739 }
10740 break;
252b5132
RH
10741 }
10742 }
10743
24a1ba0f 10744 /* Fill in the first entry in the procedure linkage table. */
e5a52504 10745 if (splt->size > 0 && elf32_arm_hash_table (info)->plt_header_size)
f7a74f8c 10746 {
00a97672
RS
10747 const bfd_vma *plt0_entry;
10748 bfd_vma got_address, plt_address, got_displacement;
10749
10750 /* Calculate the addresses of the GOT and PLT. */
10751 got_address = sgot->output_section->vma + sgot->output_offset;
10752 plt_address = splt->output_section->vma + splt->output_offset;
10753
10754 if (htab->vxworks_p)
10755 {
10756 /* The VxWorks GOT is relocated by the dynamic linker.
10757 Therefore, we must emit relocations rather than simply
10758 computing the values now. */
10759 Elf_Internal_Rela rel;
10760
10761 plt0_entry = elf32_arm_vxworks_exec_plt0_entry;
52ab56c2
PB
10762 put_arm_insn (htab, output_bfd, plt0_entry[0],
10763 splt->contents + 0);
10764 put_arm_insn (htab, output_bfd, plt0_entry[1],
10765 splt->contents + 4);
10766 put_arm_insn (htab, output_bfd, plt0_entry[2],
10767 splt->contents + 8);
00a97672
RS
10768 bfd_put_32 (output_bfd, got_address, splt->contents + 12);
10769
10770 /* Generate a relocation for _GLOBAL_OFFSET_TABLE_. */
10771 rel.r_offset = plt_address + 12;
10772 rel.r_info = ELF32_R_INFO (htab->root.hgot->indx, R_ARM_ABS32);
10773 rel.r_addend = 0;
10774 SWAP_RELOC_OUT (htab) (output_bfd, &rel,
10775 htab->srelplt2->contents);
10776 }
10777 else
10778 {
10779 got_displacement = got_address - (plt_address + 16);
10780
10781 plt0_entry = elf32_arm_plt0_entry;
52ab56c2
PB
10782 put_arm_insn (htab, output_bfd, plt0_entry[0],
10783 splt->contents + 0);
10784 put_arm_insn (htab, output_bfd, plt0_entry[1],
10785 splt->contents + 4);
10786 put_arm_insn (htab, output_bfd, plt0_entry[2],
10787 splt->contents + 8);
10788 put_arm_insn (htab, output_bfd, plt0_entry[3],
10789 splt->contents + 12);
5e681ec4 10790
5e681ec4 10791#ifdef FOUR_WORD_PLT
00a97672
RS
10792 /* The displacement value goes in the otherwise-unused
10793 last word of the second entry. */
10794 bfd_put_32 (output_bfd, got_displacement, splt->contents + 28);
5e681ec4 10795#else
00a97672 10796 bfd_put_32 (output_bfd, got_displacement, splt->contents + 16);
5e681ec4 10797#endif
00a97672 10798 }
f7a74f8c 10799 }
252b5132
RH
10800
10801 /* UnixWare sets the entsize of .plt to 4, although that doesn't
10802 really seem like the right value. */
74541ad4
AM
10803 if (splt->output_section->owner == output_bfd)
10804 elf_section_data (splt->output_section)->this_hdr.sh_entsize = 4;
00a97672
RS
10805
10806 if (htab->vxworks_p && !info->shared && htab->splt->size > 0)
10807 {
10808 /* Correct the .rel(a).plt.unloaded relocations. They will have
10809 incorrect symbol indexes. */
10810 int num_plts;
eed62c48 10811 unsigned char *p;
00a97672
RS
10812
10813 num_plts = ((htab->splt->size - htab->plt_header_size)
10814 / htab->plt_entry_size);
10815 p = htab->srelplt2->contents + RELOC_SIZE (htab);
10816
10817 for (; num_plts; num_plts--)
10818 {
10819 Elf_Internal_Rela rel;
10820
10821 SWAP_RELOC_IN (htab) (output_bfd, p, &rel);
10822 rel.r_info = ELF32_R_INFO (htab->root.hgot->indx, R_ARM_ABS32);
10823 SWAP_RELOC_OUT (htab) (output_bfd, &rel, p);
10824 p += RELOC_SIZE (htab);
10825
10826 SWAP_RELOC_IN (htab) (output_bfd, p, &rel);
10827 rel.r_info = ELF32_R_INFO (htab->root.hplt->indx, R_ARM_ABS32);
10828 SWAP_RELOC_OUT (htab) (output_bfd, &rel, p);
10829 p += RELOC_SIZE (htab);
10830 }
10831 }
252b5132
RH
10832 }
10833
10834 /* Fill in the first three entries in the global offset table. */
229fcec5 10835 if (sgot)
252b5132 10836 {
229fcec5
MM
10837 if (sgot->size > 0)
10838 {
10839 if (sdyn == NULL)
10840 bfd_put_32 (output_bfd, (bfd_vma) 0, sgot->contents);
10841 else
10842 bfd_put_32 (output_bfd,
10843 sdyn->output_section->vma + sdyn->output_offset,
10844 sgot->contents);
10845 bfd_put_32 (output_bfd, (bfd_vma) 0, sgot->contents + 4);
10846 bfd_put_32 (output_bfd, (bfd_vma) 0, sgot->contents + 8);
10847 }
252b5132 10848
229fcec5
MM
10849 elf_section_data (sgot->output_section)->this_hdr.sh_entsize = 4;
10850 }
252b5132 10851
b34976b6 10852 return TRUE;
252b5132
RH
10853}
10854
ba96a88f 10855static void
57e8b36a 10856elf32_arm_post_process_headers (bfd * abfd, struct bfd_link_info * link_info ATTRIBUTE_UNUSED)
ba96a88f 10857{
9b485d32 10858 Elf_Internal_Ehdr * i_ehdrp; /* ELF file header, internal form. */
e489d0ae 10859 struct elf32_arm_link_hash_table *globals;
ba96a88f
NC
10860
10861 i_ehdrp = elf_elfheader (abfd);
10862
94a3258f
PB
10863 if (EF_ARM_EABI_VERSION (i_ehdrp->e_flags) == EF_ARM_EABI_UNKNOWN)
10864 i_ehdrp->e_ident[EI_OSABI] = ELFOSABI_ARM;
10865 else
10866 i_ehdrp->e_ident[EI_OSABI] = 0;
ba96a88f 10867 i_ehdrp->e_ident[EI_ABIVERSION] = ARM_ELF_ABI_VERSION;
e489d0ae 10868
93204d3a
PB
10869 if (link_info)
10870 {
10871 globals = elf32_arm_hash_table (link_info);
10872 if (globals->byteswap_code)
10873 i_ehdrp->e_flags |= EF_ARM_BE8;
10874 }
ba96a88f
NC
10875}
10876
99e4ae17 10877static enum elf_reloc_type_class
57e8b36a 10878elf32_arm_reloc_type_class (const Elf_Internal_Rela *rela)
99e4ae17 10879{
f51e552e 10880 switch ((int) ELF32_R_TYPE (rela->r_info))
99e4ae17
AJ
10881 {
10882 case R_ARM_RELATIVE:
10883 return reloc_class_relative;
10884 case R_ARM_JUMP_SLOT:
10885 return reloc_class_plt;
10886 case R_ARM_COPY:
10887 return reloc_class_copy;
10888 default:
10889 return reloc_class_normal;
10890 }
10891}
10892
e16bb312
NC
10893/* Set the right machine number for an Arm ELF file. */
10894
10895static bfd_boolean
57e8b36a 10896elf32_arm_section_flags (flagword *flags, const Elf_Internal_Shdr *hdr)
e16bb312
NC
10897{
10898 if (hdr->sh_type == SHT_NOTE)
10899 *flags |= SEC_LINK_ONCE | SEC_LINK_DUPLICATES_SAME_CONTENTS;
10900
10901 return TRUE;
10902}
10903
e489d0ae 10904static void
57e8b36a 10905elf32_arm_final_write_processing (bfd *abfd, bfd_boolean linker ATTRIBUTE_UNUSED)
e16bb312 10906{
5a6c6817 10907 bfd_arm_update_notes (abfd, ARM_NOTE_SECTION);
e16bb312
NC
10908}
10909
40a18ebd
NC
10910/* Return TRUE if this is an unwinding table entry. */
10911
10912static bfd_boolean
10913is_arm_elf_unwind_section_name (bfd * abfd ATTRIBUTE_UNUSED, const char * name)
10914{
0112cd26
NC
10915 return (CONST_STRNEQ (name, ELF_STRING_ARM_unwind)
10916 || CONST_STRNEQ (name, ELF_STRING_ARM_unwind_once));
40a18ebd
NC
10917}
10918
10919
10920/* Set the type and flags for an ARM section. We do this by
10921 the section name, which is a hack, but ought to work. */
10922
10923static bfd_boolean
10924elf32_arm_fake_sections (bfd * abfd, Elf_Internal_Shdr * hdr, asection * sec)
10925{
10926 const char * name;
10927
10928 name = bfd_get_section_name (abfd, sec);
10929
10930 if (is_arm_elf_unwind_section_name (abfd, name))
10931 {
10932 hdr->sh_type = SHT_ARM_EXIDX;
10933 hdr->sh_flags |= SHF_LINK_ORDER;
10934 }
10935 return TRUE;
10936}
10937
6dc132d9
L
10938/* Handle an ARM specific section when reading an object file. This is
10939 called when bfd_section_from_shdr finds a section with an unknown
10940 type. */
40a18ebd
NC
10941
10942static bfd_boolean
10943elf32_arm_section_from_shdr (bfd *abfd,
10944 Elf_Internal_Shdr * hdr,
6dc132d9
L
10945 const char *name,
10946 int shindex)
40a18ebd
NC
10947{
10948 /* There ought to be a place to keep ELF backend specific flags, but
10949 at the moment there isn't one. We just keep track of the
10950 sections by their name, instead. Fortunately, the ABI gives
10951 names for all the ARM specific sections, so we will probably get
10952 away with this. */
10953 switch (hdr->sh_type)
10954 {
10955 case SHT_ARM_EXIDX:
0951f019
RE
10956 case SHT_ARM_PREEMPTMAP:
10957 case SHT_ARM_ATTRIBUTES:
40a18ebd
NC
10958 break;
10959
10960 default:
10961 return FALSE;
10962 }
10963
6dc132d9 10964 if (! _bfd_elf_make_section_from_shdr (abfd, hdr, name, shindex))
40a18ebd
NC
10965 return FALSE;
10966
10967 return TRUE;
10968}
e489d0ae 10969
8e3de13a
NC
10970/* A structure used to record a list of sections, independently
10971 of the next and prev fields in the asection structure. */
10972typedef struct section_list
10973{
10974 asection * sec;
10975 struct section_list * next;
10976 struct section_list * prev;
10977}
10978section_list;
10979
10980/* Unfortunately we need to keep a list of sections for which
10981 an _arm_elf_section_data structure has been allocated. This
10982 is because it is possible for functions like elf32_arm_write_section
10983 to be called on a section which has had an elf_data_structure
10984 allocated for it (and so the used_by_bfd field is valid) but
10985 for which the ARM extended version of this structure - the
10986 _arm_elf_section_data structure - has not been allocated. */
10987static section_list * sections_with_arm_elf_section_data = NULL;
10988
10989static void
957c6e41 10990record_section_with_arm_elf_section_data (asection * sec)
8e3de13a
NC
10991{
10992 struct section_list * entry;
10993
957c6e41 10994 entry = bfd_malloc (sizeof (* entry));
8e3de13a
NC
10995 if (entry == NULL)
10996 return;
10997 entry->sec = sec;
10998 entry->next = sections_with_arm_elf_section_data;
10999 entry->prev = NULL;
11000 if (entry->next != NULL)
11001 entry->next->prev = entry;
11002 sections_with_arm_elf_section_data = entry;
11003}
11004
44444f50
NC
11005static struct section_list *
11006find_arm_elf_section_entry (asection * sec)
8e3de13a
NC
11007{
11008 struct section_list * entry;
bd4aae00 11009 static struct section_list * last_entry = NULL;
8e3de13a 11010
bd4aae00
NC
11011 /* This is a short cut for the typical case where the sections are added
11012 to the sections_with_arm_elf_section_data list in forward order and
11013 then looked up here in backwards order. This makes a real difference
11014 to the ld-srec/sec64k.exp linker test. */
44444f50 11015 entry = sections_with_arm_elf_section_data;
bd4aae00
NC
11016 if (last_entry != NULL)
11017 {
11018 if (last_entry->sec == sec)
44444f50
NC
11019 entry = last_entry;
11020 else if (last_entry->next != NULL
11021 && last_entry->next->sec == sec)
11022 entry = last_entry->next;
bd4aae00 11023 }
44444f50
NC
11024
11025 for (; entry; entry = entry->next)
8e3de13a 11026 if (entry->sec == sec)
44444f50 11027 break;
bd4aae00 11028
44444f50
NC
11029 if (entry)
11030 /* Record the entry prior to this one - it is the entry we are most
11031 likely to want to locate next time. Also this way if we have been
11032 called from unrecord_section_with_arm_elf_section_data() we will not
11033 be caching a pointer that is about to be freed. */
11034 last_entry = entry->prev;
11035
11036 return entry;
11037}
11038
11039static _arm_elf_section_data *
11040get_arm_elf_section_data (asection * sec)
11041{
11042 struct section_list * entry;
11043
11044 entry = find_arm_elf_section_entry (sec);
11045
11046 if (entry)
11047 return elf32_arm_section_data (entry->sec);
11048 else
11049 return NULL;
8e3de13a
NC
11050}
11051
11052static void
11053unrecord_section_with_arm_elf_section_data (asection * sec)
11054{
11055 struct section_list * entry;
11056
44444f50
NC
11057 entry = find_arm_elf_section_entry (sec);
11058
11059 if (entry)
11060 {
11061 if (entry->prev != NULL)
11062 entry->prev->next = entry->next;
11063 if (entry->next != NULL)
11064 entry->next->prev = entry->prev;
11065 if (entry == sections_with_arm_elf_section_data)
11066 sections_with_arm_elf_section_data = entry->next;
11067 free (entry);
11068 }
8e3de13a
NC
11069}
11070
e489d0ae 11071
4e617b1e
PB
11072typedef struct
11073{
11074 void *finfo;
11075 struct bfd_link_info *info;
91a5743d
PB
11076 asection *sec;
11077 int sec_shndx;
4e617b1e
PB
11078 bfd_boolean (*func) (void *, const char *, Elf_Internal_Sym *,
11079 asection *, struct elf_link_hash_entry *);
11080} output_arch_syminfo;
11081
11082enum map_symbol_type
11083{
11084 ARM_MAP_ARM,
11085 ARM_MAP_THUMB,
11086 ARM_MAP_DATA
11087};
11088
11089
7413f23f 11090/* Output a single mapping symbol. */
4e617b1e
PB
11091
11092static bfd_boolean
7413f23f
DJ
11093elf32_arm_output_map_sym (output_arch_syminfo *osi,
11094 enum map_symbol_type type,
11095 bfd_vma offset)
4e617b1e
PB
11096{
11097 static const char *names[3] = {"$a", "$t", "$d"};
11098 struct elf32_arm_link_hash_table *htab;
11099 Elf_Internal_Sym sym;
11100
11101 htab = elf32_arm_hash_table (osi->info);
91a5743d
PB
11102 sym.st_value = osi->sec->output_section->vma
11103 + osi->sec->output_offset
11104 + offset;
4e617b1e
PB
11105 sym.st_size = 0;
11106 sym.st_other = 0;
11107 sym.st_info = ELF_ST_INFO (STB_LOCAL, STT_NOTYPE);
91a5743d
PB
11108 sym.st_shndx = osi->sec_shndx;
11109 if (!osi->func (osi->finfo, names[type], &sym, osi->sec, NULL))
4e617b1e
PB
11110 return FALSE;
11111 return TRUE;
11112}
11113
11114
11115/* Output mapping symbols for PLT entries associated with H. */
11116
11117static bfd_boolean
11118elf32_arm_output_plt_map (struct elf_link_hash_entry *h, void *inf)
11119{
11120 output_arch_syminfo *osi = (output_arch_syminfo *) inf;
11121 struct elf32_arm_link_hash_table *htab;
11122 struct elf32_arm_link_hash_entry *eh;
11123 bfd_vma addr;
11124
11125 htab = elf32_arm_hash_table (osi->info);
11126
11127 if (h->root.type == bfd_link_hash_indirect)
11128 return TRUE;
11129
11130 if (h->root.type == bfd_link_hash_warning)
11131 /* When warning symbols are created, they **replace** the "real"
11132 entry in the hash table, thus we never get to see the real
11133 symbol in a hash traversal. So look at it now. */
11134 h = (struct elf_link_hash_entry *) h->root.u.i.link;
11135
11136 if (h->plt.offset == (bfd_vma) -1)
11137 return TRUE;
11138
11139 eh = (struct elf32_arm_link_hash_entry *) h;
11140 addr = h->plt.offset;
11141 if (htab->symbian_p)
11142 {
7413f23f 11143 if (!elf32_arm_output_map_sym (osi, ARM_MAP_ARM, addr))
4e617b1e 11144 return FALSE;
7413f23f 11145 if (!elf32_arm_output_map_sym (osi, ARM_MAP_DATA, addr + 4))
4e617b1e
PB
11146 return FALSE;
11147 }
11148 else if (htab->vxworks_p)
11149 {
7413f23f 11150 if (!elf32_arm_output_map_sym (osi, ARM_MAP_ARM, addr))
4e617b1e 11151 return FALSE;
7413f23f 11152 if (!elf32_arm_output_map_sym (osi, ARM_MAP_DATA, addr + 8))
4e617b1e 11153 return FALSE;
7413f23f 11154 if (!elf32_arm_output_map_sym (osi, ARM_MAP_ARM, addr + 12))
4e617b1e 11155 return FALSE;
7413f23f 11156 if (!elf32_arm_output_map_sym (osi, ARM_MAP_DATA, addr + 20))
4e617b1e
PB
11157 return FALSE;
11158 }
11159 else
11160 {
bd97cb95
DJ
11161 bfd_signed_vma thumb_refs;
11162
11163 thumb_refs = eh->plt_thumb_refcount;
11164 if (!htab->use_blx)
11165 thumb_refs += eh->plt_maybe_thumb_refcount;
4e617b1e 11166
bd97cb95 11167 if (thumb_refs > 0)
4e617b1e 11168 {
7413f23f 11169 if (!elf32_arm_output_map_sym (osi, ARM_MAP_THUMB, addr - 4))
4e617b1e
PB
11170 return FALSE;
11171 }
11172#ifdef FOUR_WORD_PLT
7413f23f 11173 if (!elf32_arm_output_map_sym (osi, ARM_MAP_ARM, addr))
4e617b1e 11174 return FALSE;
7413f23f 11175 if (!elf32_arm_output_map_sym (osi, ARM_MAP_DATA, addr + 12))
4e617b1e
PB
11176 return FALSE;
11177#else
906e58ca 11178 /* A three-word PLT with no Thumb thunk contains only Arm code,
4e617b1e
PB
11179 so only need to output a mapping symbol for the first PLT entry and
11180 entries with thumb thunks. */
bd97cb95 11181 if (thumb_refs > 0 || addr == 20)
4e617b1e 11182 {
7413f23f 11183 if (!elf32_arm_output_map_sym (osi, ARM_MAP_ARM, addr))
4e617b1e
PB
11184 return FALSE;
11185 }
11186#endif
11187 }
11188
11189 return TRUE;
11190}
11191
7413f23f
DJ
11192/* Output a single local symbol for a generated stub. */
11193
11194static bfd_boolean
11195elf32_arm_output_stub_sym (output_arch_syminfo *osi, const char *name,
11196 bfd_vma offset, bfd_vma size)
11197{
11198 struct elf32_arm_link_hash_table *htab;
11199 Elf_Internal_Sym sym;
11200
11201 htab = elf32_arm_hash_table (osi->info);
11202 sym.st_value = osi->sec->output_section->vma
11203 + osi->sec->output_offset
11204 + offset;
11205 sym.st_size = size;
11206 sym.st_other = 0;
11207 sym.st_info = ELF_ST_INFO (STB_LOCAL, STT_FUNC);
11208 sym.st_shndx = osi->sec_shndx;
11209 if (!osi->func (osi->finfo, name, &sym, osi->sec, NULL))
11210 return FALSE;
11211 return TRUE;
11212}
4e617b1e 11213
da5938a2
NC
11214static bfd_boolean
11215arm_map_one_stub (struct bfd_hash_entry *gen_entry,
11216 PTR in_arg)
11217{
11218 struct elf32_arm_stub_hash_entry *stub_entry;
11219 struct bfd_link_info *info;
11220 struct elf32_arm_link_hash_table *htab;
11221 asection *stub_sec;
11222 bfd_vma addr;
7413f23f 11223 char *stub_name;
da5938a2
NC
11224
11225 /* Massage our args to the form they really have. */
11226 stub_entry = (struct elf32_arm_stub_hash_entry *) gen_entry;
11227
11228 output_arch_syminfo *osi = (output_arch_syminfo *) in_arg;
11229 info = osi->info;
11230
11231 htab = elf32_arm_hash_table (info);
11232 stub_sec = stub_entry->stub_sec;
11233
11234 /* Ensure this stub is attached to the current section being
7413f23f 11235 processed. */
da5938a2
NC
11236 if (stub_sec != osi->sec)
11237 return TRUE;
11238
7413f23f
DJ
11239 addr = (bfd_vma) stub_entry->stub_offset;
11240 stub_name = stub_entry->output_name;
da5938a2 11241
7413f23f
DJ
11242 switch (stub_entry->stub_type)
11243 {
da5938a2 11244 case arm_stub_long_branch:
7413f23f 11245 if (!elf32_arm_output_stub_sym (osi, stub_name, addr, 8))
da5938a2 11246 return FALSE;
7413f23f
DJ
11247 if (!elf32_arm_output_map_sym (osi, ARM_MAP_ARM, addr))
11248 return FALSE;
11249 if (!elf32_arm_output_map_sym (osi, ARM_MAP_DATA, addr + 4))
da5938a2
NC
11250 return FALSE;
11251 break;
11252 case arm_thumb_v4t_stub_long_branch:
7413f23f
DJ
11253 if (!elf32_arm_output_stub_sym (osi, stub_name, addr, 12))
11254 return FALSE;
11255 if (!elf32_arm_output_map_sym (osi, ARM_MAP_ARM, addr))
da5938a2 11256 return FALSE;
7413f23f 11257 if (!elf32_arm_output_map_sym (osi, ARM_MAP_DATA, addr + 8))
da5938a2
NC
11258 return FALSE;
11259 break;
11260 case arm_thumb_thumb_stub_long_branch:
3dccd7b7 11261 if (!elf32_arm_output_stub_sym (osi, stub_name, addr | 1, 16))
da5938a2 11262 return FALSE;
7413f23f
DJ
11263 if (!elf32_arm_output_map_sym (osi, ARM_MAP_THUMB, addr))
11264 return FALSE;
11265 if (!elf32_arm_output_map_sym (osi, ARM_MAP_DATA, addr + 12))
da5938a2
NC
11266 return FALSE;
11267 break;
11268 case arm_thumb_arm_v4t_stub_long_branch:
3dccd7b7 11269 if (!elf32_arm_output_stub_sym (osi, stub_name, addr | 1, 20))
7413f23f
DJ
11270 return FALSE;
11271 if (!elf32_arm_output_map_sym (osi, ARM_MAP_THUMB, addr))
da5938a2 11272 return FALSE;
7413f23f 11273 if (!elf32_arm_output_map_sym (osi, ARM_MAP_ARM, addr + 8))
da5938a2 11274 return FALSE;
7413f23f 11275 if (!elf32_arm_output_map_sym (osi, ARM_MAP_DATA, addr + 16))
da5938a2
NC
11276 return FALSE;
11277 break;
11278 case arm_stub_pic_long_branch:
7413f23f
DJ
11279 if (!elf32_arm_output_stub_sym (osi, stub_name, addr, 12))
11280 return FALSE;
11281 if (!elf32_arm_output_map_sym (osi, ARM_MAP_ARM, addr))
da5938a2 11282 return FALSE;
7413f23f 11283 if (!elf32_arm_output_map_sym (osi, ARM_MAP_DATA, addr + 8))
da5938a2
NC
11284 return FALSE;
11285 break;
11286 default:
11287 BFD_FAIL ();
7413f23f 11288 }
da5938a2
NC
11289
11290 return TRUE;
11291}
11292
91a5743d 11293/* Output mapping symbols for linker generated sections. */
4e617b1e
PB
11294
11295static bfd_boolean
11296elf32_arm_output_arch_local_syms (bfd *output_bfd,
906e58ca
NC
11297 struct bfd_link_info *info,
11298 void *finfo,
11299 bfd_boolean (*func) (void *, const char *,
11300 Elf_Internal_Sym *,
11301 asection *,
11302 struct elf_link_hash_entry *))
4e617b1e
PB
11303{
11304 output_arch_syminfo osi;
11305 struct elf32_arm_link_hash_table *htab;
91a5743d
PB
11306 bfd_vma offset;
11307 bfd_size_type size;
4e617b1e
PB
11308
11309 htab = elf32_arm_hash_table (info);
906e58ca 11310 check_use_blx (htab);
91a5743d 11311
4e617b1e
PB
11312 osi.finfo = finfo;
11313 osi.info = info;
11314 osi.func = func;
906e58ca 11315
91a5743d
PB
11316 /* ARM->Thumb glue. */
11317 if (htab->arm_glue_size > 0)
11318 {
11319 osi.sec = bfd_get_section_by_name (htab->bfd_of_glue_owner,
11320 ARM2THUMB_GLUE_SECTION_NAME);
11321
11322 osi.sec_shndx = _bfd_elf_section_from_bfd_section
11323 (output_bfd, osi.sec->output_section);
11324 if (info->shared || htab->root.is_relocatable_executable
11325 || htab->pic_veneer)
11326 size = ARM2THUMB_PIC_GLUE_SIZE;
11327 else if (htab->use_blx)
11328 size = ARM2THUMB_V5_STATIC_GLUE_SIZE;
11329 else
11330 size = ARM2THUMB_STATIC_GLUE_SIZE;
4e617b1e 11331
91a5743d
PB
11332 for (offset = 0; offset < htab->arm_glue_size; offset += size)
11333 {
7413f23f
DJ
11334 elf32_arm_output_map_sym (&osi, ARM_MAP_ARM, offset);
11335 elf32_arm_output_map_sym (&osi, ARM_MAP_DATA, offset + size - 4);
91a5743d
PB
11336 }
11337 }
11338
11339 /* Thumb->ARM glue. */
11340 if (htab->thumb_glue_size > 0)
11341 {
11342 osi.sec = bfd_get_section_by_name (htab->bfd_of_glue_owner,
11343 THUMB2ARM_GLUE_SECTION_NAME);
11344
11345 osi.sec_shndx = _bfd_elf_section_from_bfd_section
11346 (output_bfd, osi.sec->output_section);
11347 size = THUMB2ARM_GLUE_SIZE;
11348
11349 for (offset = 0; offset < htab->thumb_glue_size; offset += size)
11350 {
7413f23f
DJ
11351 elf32_arm_output_map_sym (&osi, ARM_MAP_THUMB, offset);
11352 elf32_arm_output_map_sym (&osi, ARM_MAP_ARM, offset + 4);
91a5743d
PB
11353 }
11354 }
11355
845b51d6
PB
11356 /* ARMv4 BX veneers. */
11357 if (htab->bx_glue_size > 0)
11358 {
11359 osi.sec = bfd_get_section_by_name (htab->bfd_of_glue_owner,
11360 ARM_BX_GLUE_SECTION_NAME);
11361
11362 osi.sec_shndx = _bfd_elf_section_from_bfd_section
11363 (output_bfd, osi.sec->output_section);
11364
7413f23f 11365 elf32_arm_output_map_sym (&osi, ARM_MAP_ARM, 0);
845b51d6
PB
11366 }
11367
da5938a2
NC
11368 /* Long calls stubs. */
11369 if (htab->stub_bfd && htab->stub_bfd->sections) {
11370 asection* stub_sec;
11371 for (stub_sec = htab->stub_bfd->sections;
11372 stub_sec != NULL;
11373 stub_sec = stub_sec->next) {
11374
11375 /* Ignore non-stub sections */
11376 if (!strstr(stub_sec->name, STUB_SUFFIX))
11377 continue;
11378
11379 osi.sec = stub_sec;
11380
11381 osi.sec_shndx = _bfd_elf_section_from_bfd_section
11382 (output_bfd, osi.sec->output_section);
11383
11384 bfd_hash_traverse (&htab->stub_hash_table, arm_map_one_stub, &osi);
11385 }
11386 }
11387
91a5743d
PB
11388 /* Finally, output mapping symbols for the PLT. */
11389 if (!htab->splt || htab->splt->size == 0)
11390 return TRUE;
11391
11392 osi.sec_shndx = _bfd_elf_section_from_bfd_section (output_bfd,
11393 htab->splt->output_section);
11394 osi.sec = htab->splt;
4e617b1e
PB
11395 /* Output mapping symbols for the plt header. SymbianOS does not have a
11396 plt header. */
11397 if (htab->vxworks_p)
11398 {
11399 /* VxWorks shared libraries have no PLT header. */
11400 if (!info->shared)
11401 {
7413f23f 11402 if (!elf32_arm_output_map_sym (&osi, ARM_MAP_ARM, 0))
4e617b1e 11403 return FALSE;
7413f23f 11404 if (!elf32_arm_output_map_sym (&osi, ARM_MAP_DATA, 12))
4e617b1e
PB
11405 return FALSE;
11406 }
11407 }
11408 else if (!htab->symbian_p)
11409 {
7413f23f 11410 if (!elf32_arm_output_map_sym (&osi, ARM_MAP_ARM, 0))
4e617b1e
PB
11411 return FALSE;
11412#ifndef FOUR_WORD_PLT
7413f23f 11413 if (!elf32_arm_output_map_sym (&osi, ARM_MAP_DATA, 16))
4e617b1e
PB
11414 return FALSE;
11415#endif
11416 }
11417
11418 elf_link_hash_traverse (&htab->root, elf32_arm_output_plt_map, (void *) &osi);
11419 return TRUE;
11420}
11421
e489d0ae
PB
11422/* Allocate target specific section data. */
11423
11424static bfd_boolean
11425elf32_arm_new_section_hook (bfd *abfd, asection *sec)
11426{
f592407e
AM
11427 if (!sec->used_by_bfd)
11428 {
11429 _arm_elf_section_data *sdata;
11430 bfd_size_type amt = sizeof (*sdata);
e489d0ae 11431
f592407e
AM
11432 sdata = bfd_zalloc (abfd, amt);
11433 if (sdata == NULL)
11434 return FALSE;
11435 sec->used_by_bfd = sdata;
11436 }
e489d0ae 11437
957c6e41 11438 record_section_with_arm_elf_section_data (sec);
8e3de13a 11439
e489d0ae
PB
11440 return _bfd_elf_new_section_hook (abfd, sec);
11441}
11442
11443
11444/* Used to order a list of mapping symbols by address. */
11445
11446static int
11447elf32_arm_compare_mapping (const void * a, const void * b)
11448{
7f6a71ff
JM
11449 const elf32_arm_section_map *amap = (const elf32_arm_section_map *) a;
11450 const elf32_arm_section_map *bmap = (const elf32_arm_section_map *) b;
11451
11452 if (amap->vma > bmap->vma)
11453 return 1;
11454 else if (amap->vma < bmap->vma)
11455 return -1;
11456 else if (amap->type > bmap->type)
11457 /* Ensure results do not depend on the host qsort for objects with
11458 multiple mapping symbols at the same address by sorting on type
11459 after vma. */
11460 return 1;
11461 else if (amap->type < bmap->type)
11462 return -1;
11463 else
11464 return 0;
e489d0ae
PB
11465}
11466
11467
11468/* Do code byteswapping. Return FALSE afterwards so that the section is
11469 written out as normal. */
11470
11471static bfd_boolean
c7b8f16e
JB
11472elf32_arm_write_section (bfd *output_bfd,
11473 struct bfd_link_info *link_info, asection *sec,
e489d0ae
PB
11474 bfd_byte *contents)
11475{
c7b8f16e 11476 int mapcount, errcount;
8e3de13a 11477 _arm_elf_section_data *arm_data;
c7b8f16e 11478 struct elf32_arm_link_hash_table *globals = elf32_arm_hash_table (link_info);
e489d0ae 11479 elf32_arm_section_map *map;
c7b8f16e 11480 elf32_vfp11_erratum_list *errnode;
e489d0ae
PB
11481 bfd_vma ptr;
11482 bfd_vma end;
c7b8f16e 11483 bfd_vma offset = sec->output_section->vma + sec->output_offset;
e489d0ae
PB
11484 bfd_byte tmp;
11485 int i;
57e8b36a 11486
8e3de13a
NC
11487 /* If this section has not been allocated an _arm_elf_section_data
11488 structure then we cannot record anything. */
11489 arm_data = get_arm_elf_section_data (sec);
11490 if (arm_data == NULL)
11491 return FALSE;
11492
11493 mapcount = arm_data->mapcount;
11494 map = arm_data->map;
c7b8f16e
JB
11495 errcount = arm_data->erratumcount;
11496
11497 if (errcount != 0)
11498 {
11499 unsigned int endianflip = bfd_big_endian (output_bfd) ? 3 : 0;
11500
11501 for (errnode = arm_data->erratumlist; errnode != 0;
11502 errnode = errnode->next)
11503 {
11504 bfd_vma index = errnode->vma - offset;
11505
11506 switch (errnode->type)
11507 {
11508 case VFP11_ERRATUM_BRANCH_TO_ARM_VENEER:
11509 {
11510 bfd_vma branch_to_veneer;
11511 /* Original condition code of instruction, plus bit mask for
11512 ARM B instruction. */
11513 unsigned int insn = (errnode->u.b.vfp_insn & 0xf0000000)
11514 | 0x0a000000;
11515
11516 /* The instruction is before the label. */
11517 index -= 4;
11518
11519 /* Above offset included in -4 below. */
11520 branch_to_veneer = errnode->u.b.veneer->vma
11521 - errnode->vma - 4;
11522
11523 if ((signed) branch_to_veneer < -(1 << 25)
11524 || (signed) branch_to_veneer >= (1 << 25))
11525 (*_bfd_error_handler) (_("%B: error: VFP11 veneer out of "
11526 "range"), output_bfd);
11527
11528 insn |= (branch_to_veneer >> 2) & 0xffffff;
11529 contents[endianflip ^ index] = insn & 0xff;
11530 contents[endianflip ^ (index + 1)] = (insn >> 8) & 0xff;
11531 contents[endianflip ^ (index + 2)] = (insn >> 16) & 0xff;
11532 contents[endianflip ^ (index + 3)] = (insn >> 24) & 0xff;
11533 }
11534 break;
11535
11536 case VFP11_ERRATUM_ARM_VENEER:
11537 {
11538 bfd_vma branch_from_veneer;
11539 unsigned int insn;
11540
11541 /* Take size of veneer into account. */
11542 branch_from_veneer = errnode->u.v.branch->vma
11543 - errnode->vma - 12;
11544
11545 if ((signed) branch_from_veneer < -(1 << 25)
11546 || (signed) branch_from_veneer >= (1 << 25))
11547 (*_bfd_error_handler) (_("%B: error: VFP11 veneer out of "
11548 "range"), output_bfd);
11549
11550 /* Original instruction. */
11551 insn = errnode->u.v.branch->u.b.vfp_insn;
11552 contents[endianflip ^ index] = insn & 0xff;
11553 contents[endianflip ^ (index + 1)] = (insn >> 8) & 0xff;
11554 contents[endianflip ^ (index + 2)] = (insn >> 16) & 0xff;
11555 contents[endianflip ^ (index + 3)] = (insn >> 24) & 0xff;
11556
11557 /* Branch back to insn after original insn. */
11558 insn = 0xea000000 | ((branch_from_veneer >> 2) & 0xffffff);
11559 contents[endianflip ^ (index + 4)] = insn & 0xff;
11560 contents[endianflip ^ (index + 5)] = (insn >> 8) & 0xff;
11561 contents[endianflip ^ (index + 6)] = (insn >> 16) & 0xff;
11562 contents[endianflip ^ (index + 7)] = (insn >> 24) & 0xff;
11563 }
11564 break;
11565
11566 default:
11567 abort ();
11568 }
11569 }
11570 }
e489d0ae
PB
11571
11572 if (mapcount == 0)
11573 return FALSE;
11574
c7b8f16e 11575 if (globals->byteswap_code)
e489d0ae 11576 {
c7b8f16e 11577 qsort (map, mapcount, sizeof (* map), elf32_arm_compare_mapping);
57e8b36a 11578
c7b8f16e
JB
11579 ptr = map[0].vma;
11580 for (i = 0; i < mapcount; i++)
11581 {
11582 if (i == mapcount - 1)
11583 end = sec->size;
11584 else
11585 end = map[i + 1].vma;
e489d0ae 11586
c7b8f16e 11587 switch (map[i].type)
e489d0ae 11588 {
c7b8f16e
JB
11589 case 'a':
11590 /* Byte swap code words. */
11591 while (ptr + 3 < end)
11592 {
11593 tmp = contents[ptr];
11594 contents[ptr] = contents[ptr + 3];
11595 contents[ptr + 3] = tmp;
11596 tmp = contents[ptr + 1];
11597 contents[ptr + 1] = contents[ptr + 2];
11598 contents[ptr + 2] = tmp;
11599 ptr += 4;
11600 }
11601 break;
e489d0ae 11602
c7b8f16e
JB
11603 case 't':
11604 /* Byte swap code halfwords. */
11605 while (ptr + 1 < end)
11606 {
11607 tmp = contents[ptr];
11608 contents[ptr] = contents[ptr + 1];
11609 contents[ptr + 1] = tmp;
11610 ptr += 2;
11611 }
11612 break;
11613
11614 case 'd':
11615 /* Leave data alone. */
11616 break;
11617 }
11618 ptr = end;
11619 }
e489d0ae 11620 }
8e3de13a 11621
93204d3a 11622 free (map);
8e3de13a 11623 arm_data->mapcount = 0;
c7b8f16e 11624 arm_data->mapsize = 0;
8e3de13a
NC
11625 arm_data->map = NULL;
11626 unrecord_section_with_arm_elf_section_data (sec);
11627
e489d0ae
PB
11628 return FALSE;
11629}
11630
957c6e41
NC
11631static void
11632unrecord_section_via_map_over_sections (bfd * abfd ATTRIBUTE_UNUSED,
11633 asection * sec,
11634 void * ignore ATTRIBUTE_UNUSED)
11635{
11636 unrecord_section_with_arm_elf_section_data (sec);
11637}
11638
11639static bfd_boolean
11640elf32_arm_close_and_cleanup (bfd * abfd)
11641{
b25e3d87
L
11642 if (abfd->sections)
11643 bfd_map_over_sections (abfd,
11644 unrecord_section_via_map_over_sections,
11645 NULL);
957c6e41
NC
11646
11647 return _bfd_elf_close_and_cleanup (abfd);
11648}
11649
b25e3d87
L
11650static bfd_boolean
11651elf32_arm_bfd_free_cached_info (bfd * abfd)
11652{
11653 if (abfd->sections)
11654 bfd_map_over_sections (abfd,
11655 unrecord_section_via_map_over_sections,
11656 NULL);
11657
11658 return _bfd_free_cached_info (abfd);
11659}
11660
b7693d02
DJ
11661/* Display STT_ARM_TFUNC symbols as functions. */
11662
11663static void
11664elf32_arm_symbol_processing (bfd *abfd ATTRIBUTE_UNUSED,
11665 asymbol *asym)
11666{
11667 elf_symbol_type *elfsym = (elf_symbol_type *) asym;
11668
11669 if (ELF_ST_TYPE (elfsym->internal_elf_sym.st_info) == STT_ARM_TFUNC)
11670 elfsym->symbol.flags |= BSF_FUNCTION;
11671}
11672
0beaef2b
PB
11673
11674/* Mangle thumb function symbols as we read them in. */
11675
8384fb8f 11676static bfd_boolean
0beaef2b
PB
11677elf32_arm_swap_symbol_in (bfd * abfd,
11678 const void *psrc,
11679 const void *pshn,
11680 Elf_Internal_Sym *dst)
11681{
8384fb8f
AM
11682 if (!bfd_elf32_swap_symbol_in (abfd, psrc, pshn, dst))
11683 return FALSE;
0beaef2b
PB
11684
11685 /* New EABI objects mark thumb function symbols by setting the low bit of
11686 the address. Turn these into STT_ARM_TFUNC. */
11687 if (ELF_ST_TYPE (dst->st_info) == STT_FUNC
11688 && (dst->st_value & 1))
11689 {
11690 dst->st_info = ELF_ST_INFO (ELF_ST_BIND (dst->st_info), STT_ARM_TFUNC);
11691 dst->st_value &= ~(bfd_vma) 1;
11692 }
8384fb8f 11693 return TRUE;
0beaef2b
PB
11694}
11695
11696
11697/* Mangle thumb function symbols as we write them out. */
11698
11699static void
11700elf32_arm_swap_symbol_out (bfd *abfd,
11701 const Elf_Internal_Sym *src,
11702 void *cdst,
11703 void *shndx)
11704{
11705 Elf_Internal_Sym newsym;
11706
11707 /* We convert STT_ARM_TFUNC symbols into STT_FUNC with the low bit
11708 of the address set, as per the new EABI. We do this unconditionally
11709 because objcopy does not set the elf header flags until after
11710 it writes out the symbol table. */
11711 if (ELF_ST_TYPE (src->st_info) == STT_ARM_TFUNC)
11712 {
11713 newsym = *src;
11714 newsym.st_info = ELF_ST_INFO (ELF_ST_BIND (src->st_info), STT_FUNC);
0fa3dcad
PB
11715 if (newsym.st_shndx != SHN_UNDEF)
11716 {
11717 /* Do this only for defined symbols. At link type, the static
11718 linker will simulate the work of dynamic linker of resolving
11719 symbols and will carry over the thumbness of found symbols to
11720 the output symbol table. It's not clear how it happens, but
b0fead2b 11721 the thumbness of undefined symbols can well be different at
0fa3dcad
PB
11722 runtime, and writing '1' for them will be confusing for users
11723 and possibly for dynamic linker itself.
11724 */
11725 newsym.st_value |= 1;
11726 }
906e58ca 11727
0beaef2b
PB
11728 src = &newsym;
11729 }
11730 bfd_elf32_swap_symbol_out (abfd, src, cdst, shndx);
11731}
11732
b294bdf8
MM
11733/* Add the PT_ARM_EXIDX program header. */
11734
11735static bfd_boolean
906e58ca 11736elf32_arm_modify_segment_map (bfd *abfd,
b294bdf8
MM
11737 struct bfd_link_info *info ATTRIBUTE_UNUSED)
11738{
11739 struct elf_segment_map *m;
11740 asection *sec;
11741
11742 sec = bfd_get_section_by_name (abfd, ".ARM.exidx");
11743 if (sec != NULL && (sec->flags & SEC_LOAD) != 0)
11744 {
11745 /* If there is already a PT_ARM_EXIDX header, then we do not
11746 want to add another one. This situation arises when running
11747 "strip"; the input binary already has the header. */
11748 m = elf_tdata (abfd)->segment_map;
11749 while (m && m->p_type != PT_ARM_EXIDX)
11750 m = m->next;
11751 if (!m)
11752 {
11753 m = bfd_zalloc (abfd, sizeof (struct elf_segment_map));
11754 if (m == NULL)
11755 return FALSE;
11756 m->p_type = PT_ARM_EXIDX;
11757 m->count = 1;
11758 m->sections[0] = sec;
11759
11760 m->next = elf_tdata (abfd)->segment_map;
11761 elf_tdata (abfd)->segment_map = m;
11762 }
11763 }
11764
11765 return TRUE;
11766}
11767
11768/* We may add a PT_ARM_EXIDX program header. */
11769
11770static int
a6b96beb
AM
11771elf32_arm_additional_program_headers (bfd *abfd,
11772 struct bfd_link_info *info ATTRIBUTE_UNUSED)
b294bdf8
MM
11773{
11774 asection *sec;
11775
11776 sec = bfd_get_section_by_name (abfd, ".ARM.exidx");
11777 if (sec != NULL && (sec->flags & SEC_LOAD) != 0)
11778 return 1;
11779 else
11780 return 0;
11781}
11782
fcb93ecf 11783/* We have two function types: STT_FUNC and STT_ARM_TFUNC. */
906e58ca 11784
fcb93ecf
PB
11785static bfd_boolean
11786elf32_arm_is_function_type (unsigned int type)
11787{
11788 return (type == STT_FUNC) || (type == STT_ARM_TFUNC);
11789}
11790
0beaef2b 11791/* We use this to override swap_symbol_in and swap_symbol_out. */
906e58ca
NC
11792const struct elf_size_info elf32_arm_size_info =
11793{
0beaef2b
PB
11794 sizeof (Elf32_External_Ehdr),
11795 sizeof (Elf32_External_Phdr),
11796 sizeof (Elf32_External_Shdr),
11797 sizeof (Elf32_External_Rel),
11798 sizeof (Elf32_External_Rela),
11799 sizeof (Elf32_External_Sym),
11800 sizeof (Elf32_External_Dyn),
11801 sizeof (Elf_External_Note),
11802 4,
11803 1,
11804 32, 2,
11805 ELFCLASS32, EV_CURRENT,
11806 bfd_elf32_write_out_phdrs,
11807 bfd_elf32_write_shdrs_and_ehdr,
1489a3a0 11808 bfd_elf32_checksum_contents,
0beaef2b
PB
11809 bfd_elf32_write_relocs,
11810 elf32_arm_swap_symbol_in,
11811 elf32_arm_swap_symbol_out,
11812 bfd_elf32_slurp_reloc_table,
11813 bfd_elf32_slurp_symbol_table,
11814 bfd_elf32_swap_dyn_in,
11815 bfd_elf32_swap_dyn_out,
11816 bfd_elf32_swap_reloc_in,
11817 bfd_elf32_swap_reloc_out,
11818 bfd_elf32_swap_reloca_in,
11819 bfd_elf32_swap_reloca_out
11820};
11821
252b5132
RH
11822#define ELF_ARCH bfd_arch_arm
11823#define ELF_MACHINE_CODE EM_ARM
d0facd1b
NC
11824#ifdef __QNXTARGET__
11825#define ELF_MAXPAGESIZE 0x1000
11826#else
f21f3fe0 11827#define ELF_MAXPAGESIZE 0x8000
d0facd1b 11828#endif
b1342370 11829#define ELF_MINPAGESIZE 0x1000
24718e3b 11830#define ELF_COMMONPAGESIZE 0x1000
252b5132 11831
ba93b8ac
DJ
11832#define bfd_elf32_mkobject elf32_arm_mkobject
11833
99e4ae17
AJ
11834#define bfd_elf32_bfd_copy_private_bfd_data elf32_arm_copy_private_bfd_data
11835#define bfd_elf32_bfd_merge_private_bfd_data elf32_arm_merge_private_bfd_data
252b5132
RH
11836#define bfd_elf32_bfd_set_private_flags elf32_arm_set_private_flags
11837#define bfd_elf32_bfd_print_private_bfd_data elf32_arm_print_private_bfd_data
11838#define bfd_elf32_bfd_link_hash_table_create elf32_arm_link_hash_table_create
906e58ca 11839#define bfd_elf32_bfd_link_hash_table_free elf32_arm_hash_table_free
dc810e39 11840#define bfd_elf32_bfd_reloc_type_lookup elf32_arm_reloc_type_lookup
157090f7 11841#define bfd_elf32_bfd_reloc_name_lookup elf32_arm_reloc_name_lookup
252b5132 11842#define bfd_elf32_find_nearest_line elf32_arm_find_nearest_line
4ab527b0 11843#define bfd_elf32_find_inliner_info elf32_arm_find_inliner_info
e489d0ae 11844#define bfd_elf32_new_section_hook elf32_arm_new_section_hook
3c9458e9 11845#define bfd_elf32_bfd_is_target_special_symbol elf32_arm_is_target_special_symbol
957c6e41 11846#define bfd_elf32_close_and_cleanup elf32_arm_close_and_cleanup
b25e3d87 11847#define bfd_elf32_bfd_free_cached_info elf32_arm_bfd_free_cached_info
252b5132
RH
11848
11849#define elf_backend_get_symbol_type elf32_arm_get_symbol_type
11850#define elf_backend_gc_mark_hook elf32_arm_gc_mark_hook
6a5bb875 11851#define elf_backend_gc_mark_extra_sections elf32_arm_gc_mark_extra_sections
252b5132
RH
11852#define elf_backend_gc_sweep_hook elf32_arm_gc_sweep_hook
11853#define elf_backend_check_relocs elf32_arm_check_relocs
dc810e39 11854#define elf_backend_relocate_section elf32_arm_relocate_section
e489d0ae 11855#define elf_backend_write_section elf32_arm_write_section
252b5132 11856#define elf_backend_adjust_dynamic_symbol elf32_arm_adjust_dynamic_symbol
5e681ec4 11857#define elf_backend_create_dynamic_sections elf32_arm_create_dynamic_sections
252b5132
RH
11858#define elf_backend_finish_dynamic_symbol elf32_arm_finish_dynamic_symbol
11859#define elf_backend_finish_dynamic_sections elf32_arm_finish_dynamic_sections
11860#define elf_backend_size_dynamic_sections elf32_arm_size_dynamic_sections
74541ad4 11861#define elf_backend_init_index_section _bfd_elf_init_2_index_sections
ba96a88f 11862#define elf_backend_post_process_headers elf32_arm_post_process_headers
99e4ae17 11863#define elf_backend_reloc_type_class elf32_arm_reloc_type_class
c178919b 11864#define elf_backend_object_p elf32_arm_object_p
e16bb312 11865#define elf_backend_section_flags elf32_arm_section_flags
40a18ebd
NC
11866#define elf_backend_fake_sections elf32_arm_fake_sections
11867#define elf_backend_section_from_shdr elf32_arm_section_from_shdr
e16bb312 11868#define elf_backend_final_write_processing elf32_arm_final_write_processing
5e681ec4 11869#define elf_backend_copy_indirect_symbol elf32_arm_copy_indirect_symbol
b7693d02 11870#define elf_backend_symbol_processing elf32_arm_symbol_processing
0beaef2b 11871#define elf_backend_size_info elf32_arm_size_info
b294bdf8 11872#define elf_backend_modify_segment_map elf32_arm_modify_segment_map
906e58ca
NC
11873#define elf_backend_additional_program_headers elf32_arm_additional_program_headers
11874#define elf_backend_output_arch_local_syms elf32_arm_output_arch_local_syms
11875#define elf_backend_begin_write_processing elf32_arm_begin_write_processing
11876#define elf_backend_is_function_type elf32_arm_is_function_type
11877
11878#define elf_backend_can_refcount 1
11879#define elf_backend_can_gc_sections 1
11880#define elf_backend_plt_readonly 1
11881#define elf_backend_want_got_plt 1
11882#define elf_backend_want_plt_sym 0
11883#define elf_backend_may_use_rel_p 1
11884#define elf_backend_may_use_rela_p 0
4e7fd91e 11885#define elf_backend_default_use_rela_p 0
252b5132 11886
04f7c78d 11887#define elf_backend_got_header_size 12
04f7c78d 11888
906e58ca
NC
11889#undef elf_backend_obj_attrs_vendor
11890#define elf_backend_obj_attrs_vendor "aeabi"
11891#undef elf_backend_obj_attrs_section
11892#define elf_backend_obj_attrs_section ".ARM.attributes"
11893#undef elf_backend_obj_attrs_arg_type
11894#define elf_backend_obj_attrs_arg_type elf32_arm_obj_attrs_arg_type
11895#undef elf_backend_obj_attrs_section_type
104d59d1
JM
11896#define elf_backend_obj_attrs_section_type SHT_ARM_ATTRIBUTES
11897
252b5132 11898#include "elf32-target.h"
7f266840 11899
906e58ca 11900/* VxWorks Targets. */
4e7fd91e 11901
906e58ca 11902#undef TARGET_LITTLE_SYM
4e7fd91e 11903#define TARGET_LITTLE_SYM bfd_elf32_littlearm_vxworks_vec
906e58ca 11904#undef TARGET_LITTLE_NAME
4e7fd91e 11905#define TARGET_LITTLE_NAME "elf32-littlearm-vxworks"
906e58ca 11906#undef TARGET_BIG_SYM
4e7fd91e 11907#define TARGET_BIG_SYM bfd_elf32_bigarm_vxworks_vec
906e58ca 11908#undef TARGET_BIG_NAME
4e7fd91e
PB
11909#define TARGET_BIG_NAME "elf32-bigarm-vxworks"
11910
11911/* Like elf32_arm_link_hash_table_create -- but overrides
11912 appropriately for VxWorks. */
906e58ca 11913
4e7fd91e
PB
11914static struct bfd_link_hash_table *
11915elf32_arm_vxworks_link_hash_table_create (bfd *abfd)
11916{
11917 struct bfd_link_hash_table *ret;
11918
11919 ret = elf32_arm_link_hash_table_create (abfd);
11920 if (ret)
11921 {
11922 struct elf32_arm_link_hash_table *htab
00a97672 11923 = (struct elf32_arm_link_hash_table *) ret;
4e7fd91e 11924 htab->use_rel = 0;
00a97672 11925 htab->vxworks_p = 1;
4e7fd91e
PB
11926 }
11927 return ret;
906e58ca 11928}
4e7fd91e 11929
00a97672
RS
11930static void
11931elf32_arm_vxworks_final_write_processing (bfd *abfd, bfd_boolean linker)
11932{
11933 elf32_arm_final_write_processing (abfd, linker);
11934 elf_vxworks_final_write_processing (abfd, linker);
11935}
11936
906e58ca 11937#undef elf32_bed
4e7fd91e
PB
11938#define elf32_bed elf32_arm_vxworks_bed
11939
906e58ca
NC
11940#undef bfd_elf32_bfd_link_hash_table_create
11941#define bfd_elf32_bfd_link_hash_table_create elf32_arm_vxworks_link_hash_table_create
11942#undef elf_backend_add_symbol_hook
11943#define elf_backend_add_symbol_hook elf_vxworks_add_symbol_hook
11944#undef elf_backend_final_write_processing
11945#define elf_backend_final_write_processing elf32_arm_vxworks_final_write_processing
11946#undef elf_backend_emit_relocs
11947#define elf_backend_emit_relocs elf_vxworks_emit_relocs
4e7fd91e 11948
906e58ca 11949#undef elf_backend_may_use_rel_p
00a97672 11950#define elf_backend_may_use_rel_p 0
906e58ca 11951#undef elf_backend_may_use_rela_p
00a97672 11952#define elf_backend_may_use_rela_p 1
906e58ca 11953#undef elf_backend_default_use_rela_p
00a97672 11954#define elf_backend_default_use_rela_p 1
906e58ca 11955#undef elf_backend_want_plt_sym
00a97672 11956#define elf_backend_want_plt_sym 1
906e58ca 11957#undef ELF_MAXPAGESIZE
00a97672 11958#define ELF_MAXPAGESIZE 0x1000
4e7fd91e
PB
11959
11960#include "elf32-target.h"
11961
11962
906e58ca 11963/* Symbian OS Targets. */
7f266840 11964
906e58ca 11965#undef TARGET_LITTLE_SYM
7f266840 11966#define TARGET_LITTLE_SYM bfd_elf32_littlearm_symbian_vec
906e58ca 11967#undef TARGET_LITTLE_NAME
7f266840 11968#define TARGET_LITTLE_NAME "elf32-littlearm-symbian"
906e58ca 11969#undef TARGET_BIG_SYM
7f266840 11970#define TARGET_BIG_SYM bfd_elf32_bigarm_symbian_vec
906e58ca 11971#undef TARGET_BIG_NAME
7f266840
DJ
11972#define TARGET_BIG_NAME "elf32-bigarm-symbian"
11973
11974/* Like elf32_arm_link_hash_table_create -- but overrides
11975 appropriately for Symbian OS. */
906e58ca 11976
7f266840
DJ
11977static struct bfd_link_hash_table *
11978elf32_arm_symbian_link_hash_table_create (bfd *abfd)
11979{
11980 struct bfd_link_hash_table *ret;
11981
11982 ret = elf32_arm_link_hash_table_create (abfd);
11983 if (ret)
11984 {
11985 struct elf32_arm_link_hash_table *htab
11986 = (struct elf32_arm_link_hash_table *)ret;
11987 /* There is no PLT header for Symbian OS. */
11988 htab->plt_header_size = 0;
95720a86
DJ
11989 /* The PLT entries are each one instruction and one word. */
11990 htab->plt_entry_size = 4 * ARRAY_SIZE (elf32_arm_symbian_plt_entry);
7f266840 11991 htab->symbian_p = 1;
33bfe774
JB
11992 /* Symbian uses armv5t or above, so use_blx is always true. */
11993 htab->use_blx = 1;
67687978 11994 htab->root.is_relocatable_executable = 1;
7f266840
DJ
11995 }
11996 return ret;
906e58ca 11997}
7f266840 11998
b35d266b 11999static const struct bfd_elf_special_section
551b43fd 12000elf32_arm_symbian_special_sections[] =
7f266840 12001{
5cd3778d
MM
12002 /* In a BPABI executable, the dynamic linking sections do not go in
12003 the loadable read-only segment. The post-linker may wish to
12004 refer to these sections, but they are not part of the final
12005 program image. */
0112cd26
NC
12006 { STRING_COMMA_LEN (".dynamic"), 0, SHT_DYNAMIC, 0 },
12007 { STRING_COMMA_LEN (".dynstr"), 0, SHT_STRTAB, 0 },
12008 { STRING_COMMA_LEN (".dynsym"), 0, SHT_DYNSYM, 0 },
12009 { STRING_COMMA_LEN (".got"), 0, SHT_PROGBITS, 0 },
12010 { STRING_COMMA_LEN (".hash"), 0, SHT_HASH, 0 },
5cd3778d
MM
12011 /* These sections do not need to be writable as the SymbianOS
12012 postlinker will arrange things so that no dynamic relocation is
12013 required. */
0112cd26
NC
12014 { STRING_COMMA_LEN (".init_array"), 0, SHT_INIT_ARRAY, SHF_ALLOC },
12015 { STRING_COMMA_LEN (".fini_array"), 0, SHT_FINI_ARRAY, SHF_ALLOC },
12016 { STRING_COMMA_LEN (".preinit_array"), 0, SHT_PREINIT_ARRAY, SHF_ALLOC },
12017 { NULL, 0, 0, 0, 0 }
7f266840
DJ
12018};
12019
c3c76620 12020static void
906e58ca 12021elf32_arm_symbian_begin_write_processing (bfd *abfd,
a4fd1a8e 12022 struct bfd_link_info *link_info)
c3c76620
MM
12023{
12024 /* BPABI objects are never loaded directly by an OS kernel; they are
12025 processed by a postlinker first, into an OS-specific format. If
12026 the D_PAGED bit is set on the file, BFD will align segments on
12027 page boundaries, so that an OS can directly map the file. With
12028 BPABI objects, that just results in wasted space. In addition,
12029 because we clear the D_PAGED bit, map_sections_to_segments will
12030 recognize that the program headers should not be mapped into any
12031 loadable segment. */
12032 abfd->flags &= ~D_PAGED;
906e58ca 12033 elf32_arm_begin_write_processing (abfd, link_info);
c3c76620 12034}
7f266840
DJ
12035
12036static bfd_boolean
906e58ca 12037elf32_arm_symbian_modify_segment_map (bfd *abfd,
b294bdf8 12038 struct bfd_link_info *info)
7f266840
DJ
12039{
12040 struct elf_segment_map *m;
12041 asection *dynsec;
12042
7f266840
DJ
12043 /* BPABI shared libraries and executables should have a PT_DYNAMIC
12044 segment. However, because the .dynamic section is not marked
12045 with SEC_LOAD, the generic ELF code will not create such a
12046 segment. */
12047 dynsec = bfd_get_section_by_name (abfd, ".dynamic");
12048 if (dynsec)
12049 {
8ded5a0f
AM
12050 for (m = elf_tdata (abfd)->segment_map; m != NULL; m = m->next)
12051 if (m->p_type == PT_DYNAMIC)
12052 break;
12053
12054 if (m == NULL)
12055 {
12056 m = _bfd_elf_make_dynamic_segment (abfd, dynsec);
12057 m->next = elf_tdata (abfd)->segment_map;
12058 elf_tdata (abfd)->segment_map = m;
12059 }
7f266840
DJ
12060 }
12061
b294bdf8
MM
12062 /* Also call the generic arm routine. */
12063 return elf32_arm_modify_segment_map (abfd, info);
7f266840
DJ
12064}
12065
95720a86
DJ
12066/* Return address for Ith PLT stub in section PLT, for relocation REL
12067 or (bfd_vma) -1 if it should not be included. */
12068
12069static bfd_vma
12070elf32_arm_symbian_plt_sym_val (bfd_vma i, const asection *plt,
12071 const arelent *rel ATTRIBUTE_UNUSED)
12072{
12073 return plt->vma + 4 * ARRAY_SIZE (elf32_arm_symbian_plt_entry) * i;
12074}
12075
12076
7f266840
DJ
12077#undef elf32_bed
12078#define elf32_bed elf32_arm_symbian_bed
12079
12080/* The dynamic sections are not allocated on SymbianOS; the postlinker
12081 will process them and then discard them. */
906e58ca 12082#undef ELF_DYNAMIC_SEC_FLAGS
7f266840
DJ
12083#define ELF_DYNAMIC_SEC_FLAGS \
12084 (SEC_HAS_CONTENTS | SEC_IN_MEMORY | SEC_LINKER_CREATED)
12085
00a97672 12086#undef elf_backend_add_symbol_hook
00a97672 12087#undef elf_backend_emit_relocs
c3c76620 12088
906e58ca
NC
12089#undef bfd_elf32_bfd_link_hash_table_create
12090#define bfd_elf32_bfd_link_hash_table_create elf32_arm_symbian_link_hash_table_create
12091#undef elf_backend_special_sections
12092#define elf_backend_special_sections elf32_arm_symbian_special_sections
12093#undef elf_backend_begin_write_processing
12094#define elf_backend_begin_write_processing elf32_arm_symbian_begin_write_processing
12095#undef elf_backend_final_write_processing
12096#define elf_backend_final_write_processing elf32_arm_final_write_processing
12097
12098#undef elf_backend_modify_segment_map
7f266840
DJ
12099#define elf_backend_modify_segment_map elf32_arm_symbian_modify_segment_map
12100
12101/* There is no .got section for BPABI objects, and hence no header. */
906e58ca 12102#undef elf_backend_got_header_size
7f266840
DJ
12103#define elf_backend_got_header_size 0
12104
12105/* Similarly, there is no .got.plt section. */
906e58ca 12106#undef elf_backend_want_got_plt
7f266840
DJ
12107#define elf_backend_want_got_plt 0
12108
906e58ca 12109#undef elf_backend_plt_sym_val
95720a86
DJ
12110#define elf_backend_plt_sym_val elf32_arm_symbian_plt_sym_val
12111
906e58ca 12112#undef elf_backend_may_use_rel_p
00a97672 12113#define elf_backend_may_use_rel_p 1
906e58ca 12114#undef elf_backend_may_use_rela_p
00a97672 12115#define elf_backend_may_use_rela_p 0
906e58ca 12116#undef elf_backend_default_use_rela_p
00a97672 12117#define elf_backend_default_use_rela_p 0
906e58ca 12118#undef elf_backend_want_plt_sym
00a97672 12119#define elf_backend_want_plt_sym 0
906e58ca 12120#undef ELF_MAXPAGESIZE
00a97672 12121#define ELF_MAXPAGESIZE 0x8000
4e7fd91e 12122
7f266840 12123#include "elf32-target.h"
This page took 1.442431 seconds and 4 git commands to generate.