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