]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blame - bfd/elf32-arm.c
* defs.h (struct continuation_arg): Fix typo in comment.
[thirdparty/binutils-gdb.git] / bfd / elf32-arm.c
CommitLineData
252b5132 1/* 32-bit ELF support for ARM
ab96bf03 2 Copyright 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007
d1f161ea 3 Free Software Foundation, Inc.
252b5132
RH
4
5 This file is part of BFD, the Binary File Descriptor library.
6
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
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
2068struct elf32_arm_obj_tdata
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
2079#define elf32_arm_tdata(abfd) \
2080 ((struct elf32_arm_obj_tdata *) (abfd)->tdata.any)
2081
2082#define elf32_arm_local_got_tls_type(abfd) \
2083 (elf32_arm_tdata (abfd)->local_got_tls_type)
2084
2085static bfd_boolean
2086elf32_arm_mkobject (bfd *abfd)
2087{
ba93b8ac 2088 if (abfd->tdata.any == NULL)
62d7a5f6
AM
2089 {
2090 bfd_size_type amt = sizeof (struct elf32_arm_obj_tdata);
2091 abfd->tdata.any = bfd_zalloc (abfd, amt);
2092 if (abfd->tdata.any == NULL)
2093 return FALSE;
2094 }
2095 return bfd_elf_mkobject (abfd);
ba93b8ac
DJ
2096}
2097
252b5132
RH
2098/* The ARM linker needs to keep track of the number of relocs that it
2099 decides to copy in check_relocs for each symbol. This is so that
2100 it can discard PC relative relocs if it doesn't need them when
2101 linking with -Bsymbolic. We store the information in a field
2102 extending the regular ELF linker hash table. */
2103
ba93b8ac
DJ
2104/* This structure keeps track of the number of relocs we have copied
2105 for a given symbol. */
5e681ec4 2106struct elf32_arm_relocs_copied
917583ad
NC
2107 {
2108 /* Next section. */
5e681ec4 2109 struct elf32_arm_relocs_copied * next;
917583ad
NC
2110 /* A section in dynobj. */
2111 asection * section;
2112 /* Number of relocs copied in this section. */
2113 bfd_size_type count;
ba93b8ac
DJ
2114 /* Number of PC-relative relocs copied in this section. */
2115 bfd_size_type pc_count;
917583ad 2116 };
252b5132 2117
ba93b8ac
DJ
2118#define elf32_arm_hash_entry(ent) ((struct elf32_arm_link_hash_entry *)(ent))
2119
ba96a88f 2120/* Arm ELF linker hash entry. */
252b5132 2121struct elf32_arm_link_hash_entry
917583ad
NC
2122 {
2123 struct elf_link_hash_entry root;
252b5132 2124
917583ad 2125 /* Number of PC relative relocs copied for this symbol. */
5e681ec4 2126 struct elf32_arm_relocs_copied * relocs_copied;
b7693d02
DJ
2127
2128 /* We reference count Thumb references to a PLT entry separately,
2129 so that we can emit the Thumb trampoline only if needed. */
2130 bfd_signed_vma plt_thumb_refcount;
2131
bd97cb95
DJ
2132 /* Some references from Thumb code may be eliminated by BL->BLX
2133 conversion, so record them separately. */
2134 bfd_signed_vma plt_maybe_thumb_refcount;
2135
b7693d02
DJ
2136 /* Since PLT entries have variable size if the Thumb prologue is
2137 used, we need to record the index into .got.plt instead of
2138 recomputing it from the PLT offset. */
2139 bfd_signed_vma plt_got_offset;
ba93b8ac
DJ
2140
2141#define GOT_UNKNOWN 0
2142#define GOT_NORMAL 1
2143#define GOT_TLS_GD 2
2144#define GOT_TLS_IE 4
2145 unsigned char tls_type;
a4fd1a8e
PB
2146
2147 /* The symbol marking the real symbol location for exported thumb
2148 symbols with Arm stubs. */
2149 struct elf_link_hash_entry *export_glue;
917583ad 2150 };
252b5132 2151
252b5132 2152/* Traverse an arm ELF linker hash table. */
252b5132
RH
2153#define elf32_arm_link_hash_traverse(table, func, info) \
2154 (elf_link_hash_traverse \
2155 (&(table)->root, \
b7693d02 2156 (bfd_boolean (*) (struct elf_link_hash_entry *, void *)) (func), \
252b5132
RH
2157 (info)))
2158
2159/* Get the ARM elf linker hash table from a link_info structure. */
2160#define elf32_arm_hash_table(info) \
2161 ((struct elf32_arm_link_hash_table *) ((info)->hash))
2162
9b485d32 2163/* ARM ELF linker hash table. */
252b5132 2164struct elf32_arm_link_hash_table
917583ad
NC
2165 {
2166 /* The main hash table. */
2167 struct elf_link_hash_table root;
252b5132 2168
4cc11e76 2169 /* The size in bytes of the section containing the Thumb-to-ARM glue. */
dc810e39 2170 bfd_size_type thumb_glue_size;
252b5132 2171
4cc11e76 2172 /* The size in bytes of the section containing the ARM-to-Thumb glue. */
dc810e39 2173 bfd_size_type arm_glue_size;
252b5132 2174
c7b8f16e
JB
2175 /* The size in bytes of the section containing glue for VFP11 erratum
2176 veneers. */
2177 bfd_size_type vfp11_erratum_glue_size;
2178
4cc11e76 2179 /* An arbitrary input BFD chosen to hold the glue sections. */
917583ad 2180 bfd * bfd_of_glue_owner;
ba96a88f 2181
e489d0ae
PB
2182 /* Nonzero to output a BE8 image. */
2183 int byteswap_code;
2184
9c504268 2185 /* Zero if R_ARM_TARGET1 means R_ARM_ABS32.
87bc043a 2186 Nonzero if R_ARM_TARGET1 means R_ARM_REL32. */
9c504268
PB
2187 int target1_is_rel;
2188
eb043451
PB
2189 /* The relocation to use for R_ARM_TARGET2 relocations. */
2190 int target2_reloc;
2191
319850b4
JB
2192 /* Nonzero to fix BX instructions for ARMv4 targets. */
2193 int fix_v4bx;
2194
33bfe774
JB
2195 /* Nonzero if the ARM/Thumb BLX instructions are available for use. */
2196 int use_blx;
2197
c7b8f16e
JB
2198 /* What sort of code sequences we should look for which may trigger the
2199 VFP11 denorm erratum. */
2200 bfd_arm_vfp11_fix vfp11_fix;
2201
2202 /* Global counter for the number of fixes we have emitted. */
2203 int num_vfp11_fixes;
2204
27e55c4d
PB
2205 /* Nonzero to force PIC branch veneers. */
2206 int pic_veneer;
2207
e5a52504
MM
2208 /* The number of bytes in the initial entry in the PLT. */
2209 bfd_size_type plt_header_size;
2210
2211 /* The number of bytes in the subsequent PLT etries. */
2212 bfd_size_type plt_entry_size;
2213
00a97672
RS
2214 /* True if the target system is VxWorks. */
2215 int vxworks_p;
2216
e5a52504
MM
2217 /* True if the target system is Symbian OS. */
2218 int symbian_p;
2219
4e7fd91e
PB
2220 /* True if the target uses REL relocations. */
2221 int use_rel;
2222
5e681ec4
PB
2223 /* Short-cuts to get to dynamic linker sections. */
2224 asection *sgot;
2225 asection *sgotplt;
2226 asection *srelgot;
2227 asection *splt;
2228 asection *srelplt;
2229 asection *sdynbss;
2230 asection *srelbss;
2231
00a97672
RS
2232 /* The (unloaded but important) VxWorks .rela.plt.unloaded section. */
2233 asection *srelplt2;
2234
ba93b8ac
DJ
2235 /* Data for R_ARM_TLS_LDM32 relocations. */
2236 union {
2237 bfd_signed_vma refcount;
2238 bfd_vma offset;
2239 } tls_ldm_got;
2240
5e681ec4
PB
2241 /* Small local sym to section mapping cache. */
2242 struct sym_sec_cache sym_sec;
b7693d02
DJ
2243
2244 /* For convenience in allocate_dynrelocs. */
2245 bfd * obfd;
917583ad 2246 };
252b5132 2247
780a67af
NC
2248/* Create an entry in an ARM ELF linker hash table. */
2249
2250static struct bfd_hash_entry *
57e8b36a
NC
2251elf32_arm_link_hash_newfunc (struct bfd_hash_entry * entry,
2252 struct bfd_hash_table * table,
2253 const char * string)
780a67af
NC
2254{
2255 struct elf32_arm_link_hash_entry * ret =
2256 (struct elf32_arm_link_hash_entry *) entry;
2257
2258 /* Allocate the structure if it has not already been allocated by a
2259 subclass. */
2260 if (ret == (struct elf32_arm_link_hash_entry *) NULL)
57e8b36a
NC
2261 ret = bfd_hash_allocate (table, sizeof (struct elf32_arm_link_hash_entry));
2262 if (ret == NULL)
780a67af
NC
2263 return (struct bfd_hash_entry *) ret;
2264
2265 /* Call the allocation method of the superclass. */
2266 ret = ((struct elf32_arm_link_hash_entry *)
2267 _bfd_elf_link_hash_newfunc ((struct bfd_hash_entry *) ret,
2268 table, string));
57e8b36a 2269 if (ret != NULL)
b7693d02
DJ
2270 {
2271 ret->relocs_copied = NULL;
ba93b8ac 2272 ret->tls_type = GOT_UNKNOWN;
b7693d02 2273 ret->plt_thumb_refcount = 0;
bd97cb95 2274 ret->plt_maybe_thumb_refcount = 0;
b7693d02 2275 ret->plt_got_offset = -1;
a4fd1a8e 2276 ret->export_glue = NULL;
b7693d02 2277 }
780a67af
NC
2278
2279 return (struct bfd_hash_entry *) ret;
2280}
2281
00a97672
RS
2282/* Return true if NAME is the name of the relocation section associated
2283 with S. */
2284
2285static bfd_boolean
2286reloc_section_p (struct elf32_arm_link_hash_table *htab,
2287 const char *name, asection *s)
2288{
2289 if (htab->use_rel)
0112cd26 2290 return CONST_STRNEQ (name, ".rel") && strcmp (s->name, name + 4) == 0;
00a97672 2291 else
0112cd26 2292 return CONST_STRNEQ (name, ".rela") && strcmp (s->name, name + 5) == 0;
00a97672
RS
2293}
2294
2295/* Create .got, .gotplt, and .rel(a).got sections in DYNOBJ, and set up
5e681ec4
PB
2296 shortcuts to them in our hash table. */
2297
2298static bfd_boolean
57e8b36a 2299create_got_section (bfd *dynobj, struct bfd_link_info *info)
5e681ec4
PB
2300{
2301 struct elf32_arm_link_hash_table *htab;
2302
e5a52504
MM
2303 htab = elf32_arm_hash_table (info);
2304 /* BPABI objects never have a GOT, or associated sections. */
2305 if (htab->symbian_p)
2306 return TRUE;
2307
5e681ec4
PB
2308 if (! _bfd_elf_create_got_section (dynobj, info))
2309 return FALSE;
2310
5e681ec4
PB
2311 htab->sgot = bfd_get_section_by_name (dynobj, ".got");
2312 htab->sgotplt = bfd_get_section_by_name (dynobj, ".got.plt");
2313 if (!htab->sgot || !htab->sgotplt)
2314 abort ();
2315
00a97672
RS
2316 htab->srelgot = bfd_make_section_with_flags (dynobj,
2317 RELOC_SECTION (htab, ".got"),
3496cb2a
L
2318 (SEC_ALLOC | SEC_LOAD
2319 | SEC_HAS_CONTENTS
2320 | SEC_IN_MEMORY
2321 | SEC_LINKER_CREATED
2322 | SEC_READONLY));
5e681ec4 2323 if (htab->srelgot == NULL
5e681ec4
PB
2324 || ! bfd_set_section_alignment (dynobj, htab->srelgot, 2))
2325 return FALSE;
2326 return TRUE;
2327}
2328
00a97672
RS
2329/* Create .plt, .rel(a).plt, .got, .got.plt, .rel(a).got, .dynbss, and
2330 .rel(a).bss sections in DYNOBJ, and set up shortcuts to them in our
5e681ec4
PB
2331 hash table. */
2332
2333static bfd_boolean
57e8b36a 2334elf32_arm_create_dynamic_sections (bfd *dynobj, struct bfd_link_info *info)
5e681ec4
PB
2335{
2336 struct elf32_arm_link_hash_table *htab;
2337
2338 htab = elf32_arm_hash_table (info);
2339 if (!htab->sgot && !create_got_section (dynobj, info))
2340 return FALSE;
2341
2342 if (!_bfd_elf_create_dynamic_sections (dynobj, info))
2343 return FALSE;
2344
2345 htab->splt = bfd_get_section_by_name (dynobj, ".plt");
00a97672
RS
2346 htab->srelplt = bfd_get_section_by_name (dynobj,
2347 RELOC_SECTION (htab, ".plt"));
5e681ec4
PB
2348 htab->sdynbss = bfd_get_section_by_name (dynobj, ".dynbss");
2349 if (!info->shared)
00a97672
RS
2350 htab->srelbss = bfd_get_section_by_name (dynobj,
2351 RELOC_SECTION (htab, ".bss"));
2352
2353 if (htab->vxworks_p)
2354 {
2355 if (!elf_vxworks_create_dynamic_sections (dynobj, info, &htab->srelplt2))
2356 return FALSE;
2357
2358 if (info->shared)
2359 {
2360 htab->plt_header_size = 0;
2361 htab->plt_entry_size
2362 = 4 * ARRAY_SIZE (elf32_arm_vxworks_shared_plt_entry);
2363 }
2364 else
2365 {
2366 htab->plt_header_size
2367 = 4 * ARRAY_SIZE (elf32_arm_vxworks_exec_plt0_entry);
2368 htab->plt_entry_size
2369 = 4 * ARRAY_SIZE (elf32_arm_vxworks_exec_plt_entry);
2370 }
2371 }
5e681ec4 2372
e5a52504
MM
2373 if (!htab->splt
2374 || !htab->srelplt
2375 || !htab->sdynbss
5e681ec4
PB
2376 || (!info->shared && !htab->srelbss))
2377 abort ();
2378
2379 return TRUE;
2380}
2381
2382/* Copy the extra info we tack onto an elf_link_hash_entry. */
2383
2384static void
fcfa13d2 2385elf32_arm_copy_indirect_symbol (struct bfd_link_info *info,
5e681ec4
PB
2386 struct elf_link_hash_entry *dir,
2387 struct elf_link_hash_entry *ind)
2388{
2389 struct elf32_arm_link_hash_entry *edir, *eind;
2390
2391 edir = (struct elf32_arm_link_hash_entry *) dir;
2392 eind = (struct elf32_arm_link_hash_entry *) ind;
2393
2394 if (eind->relocs_copied != NULL)
2395 {
2396 if (edir->relocs_copied != NULL)
2397 {
2398 struct elf32_arm_relocs_copied **pp;
2399 struct elf32_arm_relocs_copied *p;
2400
fcfa13d2 2401 /* Add reloc counts against the indirect sym to the direct sym
5e681ec4
PB
2402 list. Merge any entries against the same section. */
2403 for (pp = &eind->relocs_copied; (p = *pp) != NULL; )
2404 {
2405 struct elf32_arm_relocs_copied *q;
2406
2407 for (q = edir->relocs_copied; q != NULL; q = q->next)
2408 if (q->section == p->section)
2409 {
ba93b8ac 2410 q->pc_count += p->pc_count;
5e681ec4
PB
2411 q->count += p->count;
2412 *pp = p->next;
2413 break;
2414 }
2415 if (q == NULL)
2416 pp = &p->next;
2417 }
2418 *pp = edir->relocs_copied;
2419 }
2420
2421 edir->relocs_copied = eind->relocs_copied;
2422 eind->relocs_copied = NULL;
2423 }
2424
b34b2d70 2425 if (ind->root.type == bfd_link_hash_indirect)
ba93b8ac 2426 {
b34b2d70
DJ
2427 /* Copy over PLT info. */
2428 edir->plt_thumb_refcount += eind->plt_thumb_refcount;
2429 eind->plt_thumb_refcount = 0;
bd97cb95
DJ
2430 edir->plt_maybe_thumb_refcount += eind->plt_maybe_thumb_refcount;
2431 eind->plt_maybe_thumb_refcount = 0;
b34b2d70
DJ
2432
2433 if (dir->got.refcount <= 0)
2434 {
2435 edir->tls_type = eind->tls_type;
2436 eind->tls_type = GOT_UNKNOWN;
2437 }
ba93b8ac
DJ
2438 }
2439
fcfa13d2 2440 _bfd_elf_link_hash_copy_indirect (info, dir, ind);
5e681ec4
PB
2441}
2442
9b485d32 2443/* Create an ARM elf linker hash table. */
252b5132
RH
2444
2445static struct bfd_link_hash_table *
57e8b36a 2446elf32_arm_link_hash_table_create (bfd *abfd)
252b5132
RH
2447{
2448 struct elf32_arm_link_hash_table *ret;
dc810e39 2449 bfd_size_type amt = sizeof (struct elf32_arm_link_hash_table);
252b5132 2450
57e8b36a
NC
2451 ret = bfd_malloc (amt);
2452 if (ret == NULL)
252b5132
RH
2453 return NULL;
2454
57e8b36a 2455 if (!_bfd_elf_link_hash_table_init (& ret->root, abfd,
66eb6687
AM
2456 elf32_arm_link_hash_newfunc,
2457 sizeof (struct elf32_arm_link_hash_entry)))
252b5132 2458 {
e2d34d7d 2459 free (ret);
252b5132
RH
2460 return NULL;
2461 }
2462
5e681ec4
PB
2463 ret->sgot = NULL;
2464 ret->sgotplt = NULL;
2465 ret->srelgot = NULL;
2466 ret->splt = NULL;
2467 ret->srelplt = NULL;
2468 ret->sdynbss = NULL;
2469 ret->srelbss = NULL;
00a97672 2470 ret->srelplt2 = NULL;
252b5132
RH
2471 ret->thumb_glue_size = 0;
2472 ret->arm_glue_size = 0;
c7b8f16e
JB
2473 ret->vfp11_fix = BFD_ARM_VFP11_FIX_NONE;
2474 ret->vfp11_erratum_glue_size = 0;
2475 ret->num_vfp11_fixes = 0;
252b5132 2476 ret->bfd_of_glue_owner = NULL;
e489d0ae 2477 ret->byteswap_code = 0;
9c504268 2478 ret->target1_is_rel = 0;
eb043451 2479 ret->target2_reloc = R_ARM_NONE;
e5a52504
MM
2480#ifdef FOUR_WORD_PLT
2481 ret->plt_header_size = 16;
2482 ret->plt_entry_size = 16;
2483#else
2484 ret->plt_header_size = 20;
2485 ret->plt_entry_size = 12;
2486#endif
33bfe774
JB
2487 ret->fix_v4bx = 0;
2488 ret->use_blx = 0;
00a97672 2489 ret->vxworks_p = 0;
e5a52504 2490 ret->symbian_p = 0;
4e7fd91e 2491 ret->use_rel = 1;
5e681ec4 2492 ret->sym_sec.abfd = NULL;
b7693d02 2493 ret->obfd = abfd;
ba93b8ac 2494 ret->tls_ldm_got.refcount = 0;
252b5132
RH
2495
2496 return &ret->root.root;
2497}
2498
9b485d32
NC
2499/* Locate the Thumb encoded calling stub for NAME. */
2500
252b5132 2501static struct elf_link_hash_entry *
57e8b36a
NC
2502find_thumb_glue (struct bfd_link_info *link_info,
2503 const char *name,
f2a9dd69 2504 char **error_message)
252b5132
RH
2505{
2506 char *tmp_name;
2507 struct elf_link_hash_entry *hash;
2508 struct elf32_arm_link_hash_table *hash_table;
2509
2510 /* We need a pointer to the armelf specific hash table. */
2511 hash_table = elf32_arm_hash_table (link_info);
2512
57e8b36a
NC
2513 tmp_name = bfd_malloc ((bfd_size_type) strlen (name)
2514 + strlen (THUMB2ARM_GLUE_ENTRY_NAME) + 1);
252b5132
RH
2515
2516 BFD_ASSERT (tmp_name);
2517
2518 sprintf (tmp_name, THUMB2ARM_GLUE_ENTRY_NAME, name);
2519
2520 hash = elf_link_hash_lookup
b34976b6 2521 (&(hash_table)->root, tmp_name, FALSE, FALSE, TRUE);
252b5132 2522
b1657152
AM
2523 if (hash == NULL
2524 && asprintf (error_message, _("unable to find THUMB glue '%s' for '%s'"),
2525 tmp_name, name) == -1)
2526 *error_message = (char *) bfd_errmsg (bfd_error_system_call);
252b5132
RH
2527
2528 free (tmp_name);
2529
2530 return hash;
2531}
2532
9b485d32
NC
2533/* Locate the ARM encoded calling stub for NAME. */
2534
252b5132 2535static struct elf_link_hash_entry *
57e8b36a
NC
2536find_arm_glue (struct bfd_link_info *link_info,
2537 const char *name,
f2a9dd69 2538 char **error_message)
252b5132
RH
2539{
2540 char *tmp_name;
2541 struct elf_link_hash_entry *myh;
2542 struct elf32_arm_link_hash_table *hash_table;
2543
2544 /* We need a pointer to the elfarm specific hash table. */
2545 hash_table = elf32_arm_hash_table (link_info);
2546
57e8b36a
NC
2547 tmp_name = bfd_malloc ((bfd_size_type) strlen (name)
2548 + strlen (ARM2THUMB_GLUE_ENTRY_NAME) + 1);
252b5132
RH
2549
2550 BFD_ASSERT (tmp_name);
2551
2552 sprintf (tmp_name, ARM2THUMB_GLUE_ENTRY_NAME, name);
2553
2554 myh = elf_link_hash_lookup
b34976b6 2555 (&(hash_table)->root, tmp_name, FALSE, FALSE, TRUE);
252b5132 2556
b1657152
AM
2557 if (myh == NULL
2558 && asprintf (error_message, _("unable to find ARM glue '%s' for '%s'"),
2559 tmp_name, name) == -1)
2560 *error_message = (char *) bfd_errmsg (bfd_error_system_call);
252b5132
RH
2561
2562 free (tmp_name);
2563
2564 return myh;
2565}
2566
8f6277f5 2567/* ARM->Thumb glue (static images):
252b5132
RH
2568
2569 .arm
2570 __func_from_arm:
2571 ldr r12, __func_addr
2572 bx r12
2573 __func_addr:
8f6277f5 2574 .word func @ behave as if you saw a ARM_32 reloc.
252b5132 2575
26079076
PB
2576 (v5t static images)
2577 .arm
2578 __func_from_arm:
2579 ldr pc, __func_addr
2580 __func_addr:
2581 .word func @ behave as if you saw a ARM_32 reloc.
2582
8f6277f5
PB
2583 (relocatable images)
2584 .arm
2585 __func_from_arm:
2586 ldr r12, __func_offset
2587 add r12, r12, pc
2588 bx r12
2589 __func_offset:
2590 .word func - .
2591 */
2592
2593#define ARM2THUMB_STATIC_GLUE_SIZE 12
252b5132
RH
2594static const insn32 a2t1_ldr_insn = 0xe59fc000;
2595static const insn32 a2t2_bx_r12_insn = 0xe12fff1c;
2596static const insn32 a2t3_func_addr_insn = 0x00000001;
2597
26079076
PB
2598#define ARM2THUMB_V5_STATIC_GLUE_SIZE 8
2599static const insn32 a2t1v5_ldr_insn = 0xe51ff004;
2600static const insn32 a2t2v5_func_addr_insn = 0x00000001;
2601
8f6277f5
PB
2602#define ARM2THUMB_PIC_GLUE_SIZE 16
2603static const insn32 a2t1p_ldr_insn = 0xe59fc004;
2604static const insn32 a2t2p_add_pc_insn = 0xe08cc00f;
2605static const insn32 a2t3p_bx_r12_insn = 0xe12fff1c;
2606
9b485d32 2607/* Thumb->ARM: Thumb->(non-interworking aware) ARM
252b5132
RH
2608
2609 .thumb .thumb
2610 .align 2 .align 2
2611 __func_from_thumb: __func_from_thumb:
2612 bx pc push {r6, lr}
2613 nop ldr r6, __func_addr
2614 .arm mov lr, pc
2615 __func_change_to_arm: bx r6
2616 b func .arm
2617 __func_back_to_thumb:
2618 ldmia r13! {r6, lr}
2619 bx lr
2620 __func_addr:
9b485d32 2621 .word func */
252b5132
RH
2622
2623#define THUMB2ARM_GLUE_SIZE 8
2624static const insn16 t2a1_bx_pc_insn = 0x4778;
2625static const insn16 t2a2_noop_insn = 0x46c0;
2626static const insn32 t2a3_b_insn = 0xea000000;
2627
c7b8f16e
JB
2628#define VFP11_ERRATUM_VENEER_SIZE 8
2629
7e392df6 2630#ifndef ELFARM_NABI_C_INCLUDED
b34976b6 2631bfd_boolean
57e8b36a 2632bfd_elf32_arm_allocate_interworking_sections (struct bfd_link_info * info)
252b5132
RH
2633{
2634 asection * s;
2635 bfd_byte * foo;
2636 struct elf32_arm_link_hash_table * globals;
2637
2638 globals = elf32_arm_hash_table (info);
2639
2640 BFD_ASSERT (globals != NULL);
2641
2642 if (globals->arm_glue_size != 0)
2643 {
2644 BFD_ASSERT (globals->bfd_of_glue_owner != NULL);
2645
dc810e39
AM
2646 s = bfd_get_section_by_name (globals->bfd_of_glue_owner,
2647 ARM2THUMB_GLUE_SECTION_NAME);
252b5132
RH
2648
2649 BFD_ASSERT (s != NULL);
2650
57e8b36a 2651 foo = bfd_alloc (globals->bfd_of_glue_owner, globals->arm_glue_size);
252b5132 2652
2f475487 2653 BFD_ASSERT (s->size == globals->arm_glue_size);
252b5132
RH
2654 s->contents = foo;
2655 }
2656
2657 if (globals->thumb_glue_size != 0)
2658 {
2659 BFD_ASSERT (globals->bfd_of_glue_owner != NULL);
2660
2661 s = bfd_get_section_by_name
2662 (globals->bfd_of_glue_owner, THUMB2ARM_GLUE_SECTION_NAME);
2663
2664 BFD_ASSERT (s != NULL);
2665
57e8b36a 2666 foo = bfd_alloc (globals->bfd_of_glue_owner, globals->thumb_glue_size);
252b5132 2667
2f475487 2668 BFD_ASSERT (s->size == globals->thumb_glue_size);
252b5132
RH
2669 s->contents = foo;
2670 }
c7b8f16e
JB
2671
2672 if (globals->vfp11_erratum_glue_size != 0)
2673 {
2674 BFD_ASSERT (globals->bfd_of_glue_owner != NULL);
2675
2676 s = bfd_get_section_by_name
2677 (globals->bfd_of_glue_owner, VFP11_ERRATUM_VENEER_SECTION_NAME);
2678
2679 BFD_ASSERT (s != NULL);
2680
2681 foo = bfd_alloc (globals->bfd_of_glue_owner,
2682 globals->vfp11_erratum_glue_size);
2683
2684 BFD_ASSERT (s->size == globals->vfp11_erratum_glue_size);
2685 s->contents = foo;
2686 }
252b5132 2687
b34976b6 2688 return TRUE;
252b5132
RH
2689}
2690
a4fd1a8e
PB
2691/* Allocate space and symbols for calling a Thumb function from Arm mode.
2692 returns the symbol identifying teh stub. */
2693static struct elf_link_hash_entry *
57e8b36a
NC
2694record_arm_to_thumb_glue (struct bfd_link_info * link_info,
2695 struct elf_link_hash_entry * h)
252b5132
RH
2696{
2697 const char * name = h->root.root.string;
63b0f745 2698 asection * s;
252b5132
RH
2699 char * tmp_name;
2700 struct elf_link_hash_entry * myh;
14a793b2 2701 struct bfd_link_hash_entry * bh;
252b5132 2702 struct elf32_arm_link_hash_table * globals;
dc810e39 2703 bfd_vma val;
2f475487 2704 bfd_size_type size;
252b5132
RH
2705
2706 globals = elf32_arm_hash_table (link_info);
2707
2708 BFD_ASSERT (globals != NULL);
2709 BFD_ASSERT (globals->bfd_of_glue_owner != NULL);
2710
2711 s = bfd_get_section_by_name
2712 (globals->bfd_of_glue_owner, ARM2THUMB_GLUE_SECTION_NAME);
2713
252b5132
RH
2714 BFD_ASSERT (s != NULL);
2715
57e8b36a 2716 tmp_name = bfd_malloc ((bfd_size_type) strlen (name) + strlen (ARM2THUMB_GLUE_ENTRY_NAME) + 1);
252b5132
RH
2717
2718 BFD_ASSERT (tmp_name);
2719
2720 sprintf (tmp_name, ARM2THUMB_GLUE_ENTRY_NAME, name);
2721
2722 myh = elf_link_hash_lookup
b34976b6 2723 (&(globals)->root, tmp_name, FALSE, FALSE, TRUE);
252b5132
RH
2724
2725 if (myh != NULL)
2726 {
9b485d32 2727 /* We've already seen this guy. */
252b5132 2728 free (tmp_name);
a4fd1a8e 2729 return myh;
252b5132
RH
2730 }
2731
57e8b36a
NC
2732 /* The only trick here is using hash_table->arm_glue_size as the value.
2733 Even though the section isn't allocated yet, this is where we will be
2734 putting it. */
14a793b2 2735 bh = NULL;
dc810e39
AM
2736 val = globals->arm_glue_size + 1;
2737 _bfd_generic_link_add_one_symbol (link_info, globals->bfd_of_glue_owner,
2738 tmp_name, BSF_GLOBAL, s, val,
b34976b6 2739 NULL, TRUE, FALSE, &bh);
252b5132 2740
b7693d02
DJ
2741 myh = (struct elf_link_hash_entry *) bh;
2742 myh->type = ELF_ST_INFO (STB_LOCAL, STT_FUNC);
2743 myh->forced_local = 1;
2744
252b5132
RH
2745 free (tmp_name);
2746
27e55c4d
PB
2747 if (link_info->shared || globals->root.is_relocatable_executable
2748 || globals->pic_veneer)
2f475487 2749 size = ARM2THUMB_PIC_GLUE_SIZE;
26079076
PB
2750 else if (globals->use_blx)
2751 size = ARM2THUMB_V5_STATIC_GLUE_SIZE;
8f6277f5 2752 else
2f475487
AM
2753 size = ARM2THUMB_STATIC_GLUE_SIZE;
2754
2755 s->size += size;
2756 globals->arm_glue_size += size;
252b5132 2757
a4fd1a8e 2758 return myh;
252b5132
RH
2759}
2760
2761static void
57e8b36a
NC
2762record_thumb_to_arm_glue (struct bfd_link_info *link_info,
2763 struct elf_link_hash_entry *h)
252b5132
RH
2764{
2765 const char *name = h->root.root.string;
63b0f745 2766 asection *s;
252b5132
RH
2767 char *tmp_name;
2768 struct elf_link_hash_entry *myh;
14a793b2 2769 struct bfd_link_hash_entry *bh;
252b5132 2770 struct elf32_arm_link_hash_table *hash_table;
dc810e39 2771 bfd_vma val;
252b5132
RH
2772
2773 hash_table = elf32_arm_hash_table (link_info);
2774
2775 BFD_ASSERT (hash_table != NULL);
2776 BFD_ASSERT (hash_table->bfd_of_glue_owner != NULL);
2777
2778 s = bfd_get_section_by_name
2779 (hash_table->bfd_of_glue_owner, THUMB2ARM_GLUE_SECTION_NAME);
2780
2781 BFD_ASSERT (s != NULL);
2782
57e8b36a
NC
2783 tmp_name = bfd_malloc ((bfd_size_type) strlen (name)
2784 + strlen (THUMB2ARM_GLUE_ENTRY_NAME) + 1);
252b5132
RH
2785
2786 BFD_ASSERT (tmp_name);
2787
2788 sprintf (tmp_name, THUMB2ARM_GLUE_ENTRY_NAME, name);
2789
2790 myh = elf_link_hash_lookup
b34976b6 2791 (&(hash_table)->root, tmp_name, FALSE, FALSE, TRUE);
252b5132
RH
2792
2793 if (myh != NULL)
2794 {
9b485d32 2795 /* We've already seen this guy. */
252b5132 2796 free (tmp_name);
9b485d32 2797 return;
252b5132
RH
2798 }
2799
14a793b2 2800 bh = NULL;
dc810e39
AM
2801 val = hash_table->thumb_glue_size + 1;
2802 _bfd_generic_link_add_one_symbol (link_info, hash_table->bfd_of_glue_owner,
2803 tmp_name, BSF_GLOBAL, s, val,
b34976b6 2804 NULL, TRUE, FALSE, &bh);
252b5132 2805
9b485d32 2806 /* If we mark it 'Thumb', the disassembler will do a better job. */
14a793b2 2807 myh = (struct elf_link_hash_entry *) bh;
b7693d02
DJ
2808 myh->type = ELF_ST_INFO (STB_LOCAL, STT_ARM_TFUNC);
2809 myh->forced_local = 1;
252b5132
RH
2810
2811 free (tmp_name);
2812
252b5132
RH
2813#define CHANGE_TO_ARM "__%s_change_to_arm"
2814#define BACK_FROM_ARM "__%s_back_from_arm"
2815
9b485d32 2816 /* Allocate another symbol to mark where we switch to Arm mode. */
57e8b36a
NC
2817 tmp_name = bfd_malloc ((bfd_size_type) strlen (name)
2818 + strlen (CHANGE_TO_ARM) + 1);
252b5132
RH
2819
2820 BFD_ASSERT (tmp_name);
2821
2822 sprintf (tmp_name, CHANGE_TO_ARM, name);
2823
14a793b2 2824 bh = NULL;
dc810e39
AM
2825 val = hash_table->thumb_glue_size + 4,
2826 _bfd_generic_link_add_one_symbol (link_info, hash_table->bfd_of_glue_owner,
2827 tmp_name, BSF_LOCAL, s, val,
b34976b6 2828 NULL, TRUE, FALSE, &bh);
252b5132
RH
2829
2830 free (tmp_name);
2831
2f475487 2832 s->size += THUMB2ARM_GLUE_SIZE;
252b5132
RH
2833 hash_table->thumb_glue_size += THUMB2ARM_GLUE_SIZE;
2834
2835 return;
2836}
2837
c7b8f16e
JB
2838
2839/* Add an entry to the code/data map for section SEC. */
2840
2841static void
2842elf32_arm_section_map_add (asection *sec, char type, bfd_vma vma)
2843{
2844 struct _arm_elf_section_data *sec_data = elf32_arm_section_data (sec);
2845 unsigned int newidx;
2846
2847 if (sec_data->map == NULL)
2848 {
2849 sec_data->map = bfd_malloc (sizeof (elf32_arm_section_map));
2850 sec_data->mapcount = 0;
2851 sec_data->mapsize = 1;
2852 }
2853
2854 newidx = sec_data->mapcount++;
2855
2856 if (sec_data->mapcount > sec_data->mapsize)
2857 {
2858 sec_data->mapsize *= 2;
2859 sec_data->map = bfd_realloc (sec_data->map, sec_data->mapsize
2860 * sizeof (elf32_arm_section_map));
2861 }
2862
2863 sec_data->map[newidx].vma = vma;
2864 sec_data->map[newidx].type = type;
2865}
2866
2867
2868/* Record information about a VFP11 denorm-erratum veneer. Only ARM-mode
2869 veneers are handled for now. */
2870
2871static bfd_vma
2872record_vfp11_erratum_veneer (struct bfd_link_info *link_info,
2873 elf32_vfp11_erratum_list *branch,
2874 bfd *branch_bfd,
2875 asection *branch_sec,
2876 unsigned int offset)
2877{
2878 asection *s;
2879 struct elf32_arm_link_hash_table *hash_table;
2880 char *tmp_name;
2881 struct elf_link_hash_entry *myh;
2882 struct bfd_link_hash_entry *bh;
2883 bfd_vma val;
2884 struct _arm_elf_section_data *sec_data;
2885 int errcount;
2886 elf32_vfp11_erratum_list *newerr;
2887
2888 hash_table = elf32_arm_hash_table (link_info);
2889
2890 BFD_ASSERT (hash_table != NULL);
2891 BFD_ASSERT (hash_table->bfd_of_glue_owner != NULL);
2892
2893 s = bfd_get_section_by_name
2894 (hash_table->bfd_of_glue_owner, VFP11_ERRATUM_VENEER_SECTION_NAME);
2895
2896 sec_data = elf32_arm_section_data (s);
2897
2898 BFD_ASSERT (s != NULL);
2899
2900 tmp_name = bfd_malloc ((bfd_size_type) strlen
2901 (VFP11_ERRATUM_VENEER_ENTRY_NAME) + 10);
2902
2903 BFD_ASSERT (tmp_name);
2904
2905 sprintf (tmp_name, VFP11_ERRATUM_VENEER_ENTRY_NAME,
2906 hash_table->num_vfp11_fixes);
2907
2908 myh = elf_link_hash_lookup
2909 (&(hash_table)->root, tmp_name, FALSE, FALSE, FALSE);
2910
2911 BFD_ASSERT (myh == NULL);
2912
2913 bh = NULL;
2914 val = hash_table->vfp11_erratum_glue_size;
2915 _bfd_generic_link_add_one_symbol (link_info, hash_table->bfd_of_glue_owner,
2916 tmp_name, BSF_FUNCTION | BSF_LOCAL, s, val,
2917 NULL, TRUE, FALSE, &bh);
2918
2919 myh = (struct elf_link_hash_entry *) bh;
2920 myh->type = ELF_ST_INFO (STB_LOCAL, STT_FUNC);
2921 myh->forced_local = 1;
2922
2923 /* Link veneer back to calling location. */
2924 errcount = ++(sec_data->erratumcount);
2925 newerr = bfd_zmalloc (sizeof (elf32_vfp11_erratum_list));
2926
2927 newerr->type = VFP11_ERRATUM_ARM_VENEER;
2928 newerr->vma = -1;
2929 newerr->u.v.branch = branch;
2930 newerr->u.v.id = hash_table->num_vfp11_fixes;
2931 branch->u.b.veneer = newerr;
2932
2933 newerr->next = sec_data->erratumlist;
2934 sec_data->erratumlist = newerr;
2935
2936 /* A symbol for the return from the veneer. */
2937 sprintf (tmp_name, VFP11_ERRATUM_VENEER_ENTRY_NAME "_r",
2938 hash_table->num_vfp11_fixes);
2939
2940 myh = elf_link_hash_lookup
2941 (&(hash_table)->root, tmp_name, FALSE, FALSE, FALSE);
2942
2943 if (myh != NULL)
2944 abort ();
2945
2946 bh = NULL;
2947 val = offset + 4;
2948 _bfd_generic_link_add_one_symbol (link_info, branch_bfd, tmp_name, BSF_LOCAL,
2949 branch_sec, val, NULL, TRUE, FALSE, &bh);
2950
2951 myh = (struct elf_link_hash_entry *) bh;
2952 myh->type = ELF_ST_INFO (STB_LOCAL, STT_FUNC);
2953 myh->forced_local = 1;
2954
2955 free (tmp_name);
2956
2957 /* Generate a mapping symbol for the veneer section, and explicitly add an
2958 entry for that symbol to the code/data map for the section. */
2959 if (hash_table->vfp11_erratum_glue_size == 0)
2960 {
2961 bh = NULL;
2962 /* FIXME: Creates an ARM symbol. Thumb mode will need attention if it
2963 ever requires this erratum fix. */
2964 _bfd_generic_link_add_one_symbol (link_info,
2965 hash_table->bfd_of_glue_owner, "$a",
2966 BSF_LOCAL, s, 0, NULL,
2967 TRUE, FALSE, &bh);
2968
2969 myh = (struct elf_link_hash_entry *) bh;
2970 myh->type = ELF_ST_INFO (STB_LOCAL, STT_NOTYPE);
2971 myh->forced_local = 1;
2972
2973 /* The elf32_arm_init_maps function only cares about symbols from input
2974 BFDs. We must make a note of this generated mapping symbol
2975 ourselves so that code byteswapping works properly in
2976 elf32_arm_write_section. */
2977 elf32_arm_section_map_add (s, 'a', 0);
2978 }
2979
2980 s->size += VFP11_ERRATUM_VENEER_SIZE;
2981 hash_table->vfp11_erratum_glue_size += VFP11_ERRATUM_VENEER_SIZE;
2982 hash_table->num_vfp11_fixes++;
2983
2984 /* The offset of the veneer. */
2985 return val;
2986}
2987
8afb0e02
NC
2988/* Add the glue sections to ABFD. This function is called from the
2989 linker scripts in ld/emultempl/{armelf}.em. */
9b485d32 2990
b34976b6 2991bfd_boolean
57e8b36a
NC
2992bfd_elf32_arm_add_glue_sections_to_bfd (bfd *abfd,
2993 struct bfd_link_info *info)
252b5132 2994{
252b5132
RH
2995 flagword flags;
2996 asection *sec;
2997
8afb0e02
NC
2998 /* If we are only performing a partial
2999 link do not bother adding the glue. */
1049f94e 3000 if (info->relocatable)
b34976b6 3001 return TRUE;
252b5132 3002
252b5132
RH
3003 sec = bfd_get_section_by_name (abfd, ARM2THUMB_GLUE_SECTION_NAME);
3004
3005 if (sec == NULL)
3006 {
57db232e
NC
3007 /* Note: we do not include the flag SEC_LINKER_CREATED, as this
3008 will prevent elf_link_input_bfd() from processing the contents
3009 of this section. */
2f475487
AM
3010 flags = (SEC_ALLOC | SEC_LOAD | SEC_HAS_CONTENTS | SEC_IN_MEMORY
3011 | SEC_CODE | SEC_READONLY);
252b5132 3012
3496cb2a
L
3013 sec = bfd_make_section_with_flags (abfd,
3014 ARM2THUMB_GLUE_SECTION_NAME,
3015 flags);
252b5132
RH
3016
3017 if (sec == NULL
252b5132 3018 || !bfd_set_section_alignment (abfd, sec, 2))
b34976b6 3019 return FALSE;
9a5aca8c 3020
57db232e
NC
3021 /* Set the gc mark to prevent the section from being removed by garbage
3022 collection, despite the fact that no relocs refer to this section. */
3023 sec->gc_mark = 1;
252b5132
RH
3024 }
3025
3026 sec = bfd_get_section_by_name (abfd, THUMB2ARM_GLUE_SECTION_NAME);
3027
3028 if (sec == NULL)
3029 {
2f475487
AM
3030 flags = (SEC_ALLOC | SEC_LOAD | SEC_HAS_CONTENTS | SEC_IN_MEMORY
3031 | SEC_CODE | SEC_READONLY);
252b5132 3032
3496cb2a
L
3033 sec = bfd_make_section_with_flags (abfd,
3034 THUMB2ARM_GLUE_SECTION_NAME,
3035 flags);
252b5132
RH
3036
3037 if (sec == NULL
252b5132 3038 || !bfd_set_section_alignment (abfd, sec, 2))
b34976b6 3039 return FALSE;
9a5aca8c 3040
57db232e 3041 sec->gc_mark = 1;
252b5132
RH
3042 }
3043
c7b8f16e
JB
3044 sec = bfd_get_section_by_name (abfd, VFP11_ERRATUM_VENEER_SECTION_NAME);
3045
3046 if (sec == NULL)
3047 {
3048 flags = (SEC_ALLOC | SEC_LOAD | SEC_HAS_CONTENTS | SEC_IN_MEMORY
3049 | SEC_CODE | SEC_READONLY);
3050
3051 sec = bfd_make_section_with_flags (abfd,
3052 VFP11_ERRATUM_VENEER_SECTION_NAME,
3053 flags);
3054
3055 if (sec == NULL
3056 || !bfd_set_section_alignment (abfd, sec, 2))
3057 return FALSE;
3058
3059 sec->gc_mark = 1;
3060 }
3061
b34976b6 3062 return TRUE;
8afb0e02
NC
3063}
3064
3065/* Select a BFD to be used to hold the sections used by the glue code.
3066 This function is called from the linker scripts in ld/emultempl/
3067 {armelf/pe}.em */
3068
b34976b6 3069bfd_boolean
57e8b36a 3070bfd_elf32_arm_get_bfd_for_interworking (bfd *abfd, struct bfd_link_info *info)
8afb0e02
NC
3071{
3072 struct elf32_arm_link_hash_table *globals;
3073
3074 /* If we are only performing a partial link
3075 do not bother getting a bfd to hold the glue. */
1049f94e 3076 if (info->relocatable)
b34976b6 3077 return TRUE;
8afb0e02 3078
b7693d02
DJ
3079 /* Make sure we don't attach the glue sections to a dynamic object. */
3080 BFD_ASSERT (!(abfd->flags & DYNAMIC));
3081
8afb0e02
NC
3082 globals = elf32_arm_hash_table (info);
3083
3084 BFD_ASSERT (globals != NULL);
3085
3086 if (globals->bfd_of_glue_owner != NULL)
b34976b6 3087 return TRUE;
8afb0e02 3088
252b5132
RH
3089 /* Save the bfd for later use. */
3090 globals->bfd_of_glue_owner = abfd;
cedb70c5 3091
b34976b6 3092 return TRUE;
252b5132
RH
3093}
3094
39b41c9c
PB
3095static void check_use_blx(struct elf32_arm_link_hash_table *globals)
3096{
104d59d1
JM
3097 if (bfd_elf_get_obj_attr_int (globals->obfd, OBJ_ATTR_PROC,
3098 Tag_CPU_arch) > 2)
39b41c9c
PB
3099 globals->use_blx = 1;
3100}
3101
b34976b6 3102bfd_boolean
57e8b36a 3103bfd_elf32_arm_process_before_allocation (bfd *abfd,
d504ffc8 3104 struct bfd_link_info *link_info)
252b5132
RH
3105{
3106 Elf_Internal_Shdr *symtab_hdr;
6cdc0ccc 3107 Elf_Internal_Rela *internal_relocs = NULL;
252b5132
RH
3108 Elf_Internal_Rela *irel, *irelend;
3109 bfd_byte *contents = NULL;
252b5132
RH
3110
3111 asection *sec;
3112 struct elf32_arm_link_hash_table *globals;
3113
3114 /* If we are only performing a partial link do not bother
3115 to construct any glue. */
1049f94e 3116 if (link_info->relocatable)
b34976b6 3117 return TRUE;
252b5132 3118
39ce1a6a
NC
3119 /* Here we have a bfd that is to be included on the link. We have a
3120 hook to do reloc rummaging, before section sizes are nailed down. */
252b5132
RH
3121 globals = elf32_arm_hash_table (link_info);
3122
3123 BFD_ASSERT (globals != NULL);
39ce1a6a
NC
3124
3125 check_use_blx (globals);
252b5132 3126
d504ffc8 3127 if (globals->byteswap_code && !bfd_big_endian (abfd))
e489d0ae 3128 {
d003868e
AM
3129 _bfd_error_handler (_("%B: BE8 images only valid in big-endian mode."),
3130 abfd);
e489d0ae
PB
3131 return FALSE;
3132 }
f21f3fe0 3133
39ce1a6a
NC
3134 /* PR 5398: If we have not decided to include any loadable sections in
3135 the output then we will not have a glue owner bfd. This is OK, it
3136 just means that there is nothing else for us to do here. */
3137 if (globals->bfd_of_glue_owner == NULL)
3138 return TRUE;
3139
252b5132
RH
3140 /* Rummage around all the relocs and map the glue vectors. */
3141 sec = abfd->sections;
3142
3143 if (sec == NULL)
b34976b6 3144 return TRUE;
252b5132
RH
3145
3146 for (; sec != NULL; sec = sec->next)
3147 {
3148 if (sec->reloc_count == 0)
3149 continue;
3150
2f475487
AM
3151 if ((sec->flags & SEC_EXCLUDE) != 0)
3152 continue;
3153
252b5132 3154 symtab_hdr = &elf_tdata (abfd)->symtab_hdr;
252b5132 3155
9b485d32 3156 /* Load the relocs. */
6cdc0ccc 3157 internal_relocs
57e8b36a 3158 = _bfd_elf_link_read_relocs (abfd, sec, (void *) NULL,
45d6a902 3159 (Elf_Internal_Rela *) NULL, FALSE);
252b5132 3160
6cdc0ccc
AM
3161 if (internal_relocs == NULL)
3162 goto error_return;
252b5132 3163
6cdc0ccc
AM
3164 irelend = internal_relocs + sec->reloc_count;
3165 for (irel = internal_relocs; irel < irelend; irel++)
252b5132
RH
3166 {
3167 long r_type;
3168 unsigned long r_index;
252b5132
RH
3169
3170 struct elf_link_hash_entry *h;
3171
3172 r_type = ELF32_R_TYPE (irel->r_info);
3173 r_index = ELF32_R_SYM (irel->r_info);
3174
9b485d32 3175 /* These are the only relocation types we care about. */
ba96a88f 3176 if ( r_type != R_ARM_PC24
b7693d02 3177 && r_type != R_ARM_PLT32
5b5bb741
PB
3178 && r_type != R_ARM_CALL
3179 && r_type != R_ARM_JUMP24
bd97cb95
DJ
3180 && r_type != R_ARM_THM_CALL
3181 && r_type != R_ARM_THM_JUMP24)
252b5132
RH
3182 continue;
3183
3184 /* Get the section contents if we haven't done so already. */
3185 if (contents == NULL)
3186 {
3187 /* Get cached copy if it exists. */
3188 if (elf_section_data (sec)->this_hdr.contents != NULL)
3189 contents = elf_section_data (sec)->this_hdr.contents;
3190 else
3191 {
3192 /* Go get them off disk. */
57e8b36a 3193 if (! bfd_malloc_and_get_section (abfd, sec, &contents))
252b5132
RH
3194 goto error_return;
3195 }
3196 }
3197
a7c10850 3198 /* If the relocation is not against a symbol it cannot concern us. */
252b5132
RH
3199 h = NULL;
3200
9b485d32 3201 /* We don't care about local symbols. */
252b5132
RH
3202 if (r_index < symtab_hdr->sh_info)
3203 continue;
3204
9b485d32 3205 /* This is an external symbol. */
252b5132
RH
3206 r_index -= symtab_hdr->sh_info;
3207 h = (struct elf_link_hash_entry *)
3208 elf_sym_hashes (abfd)[r_index];
3209
3210 /* If the relocation is against a static symbol it must be within
3211 the current section and so cannot be a cross ARM/Thumb relocation. */
3212 if (h == NULL)
3213 continue;
3214
d504ffc8
DJ
3215 /* If the call will go through a PLT entry then we do not need
3216 glue. */
3217 if (globals->splt != NULL && h->plt.offset != (bfd_vma) -1)
b7693d02
DJ
3218 continue;
3219
252b5132
RH
3220 switch (r_type)
3221 {
3222 case R_ARM_PC24:
c6596c5e 3223 case R_ARM_PLT32:
5b5bb741
PB
3224 case R_ARM_CALL:
3225 case R_ARM_JUMP24:
252b5132 3226 /* This one is a call from arm code. We need to look up
2f0ca46a 3227 the target of the call. If it is a thumb target, we
252b5132 3228 insert glue. */
39b41c9c
PB
3229 if (ELF_ST_TYPE(h->type) == STT_ARM_TFUNC
3230 && !(r_type == R_ARM_CALL && globals->use_blx))
252b5132
RH
3231 record_arm_to_thumb_glue (link_info, h);
3232 break;
3233
c19d1205 3234 case R_ARM_THM_CALL:
bd97cb95 3235 case R_ARM_THM_JUMP24:
f21f3fe0 3236 /* This one is a call from thumb code. We look
2f0ca46a 3237 up the target of the call. If it is not a thumb
bcbdc74c 3238 target, we insert glue. */
bd97cb95
DJ
3239 if (ELF_ST_TYPE (h->type) != STT_ARM_TFUNC
3240 && !(globals->use_blx && r_type == R_ARM_THM_CALL)
5ab79981 3241 && h->root.type != bfd_link_hash_undefweak)
252b5132
RH
3242 record_thumb_to_arm_glue (link_info, h);
3243 break;
3244
3245 default:
c6596c5e 3246 abort ();
252b5132
RH
3247 }
3248 }
6cdc0ccc
AM
3249
3250 if (contents != NULL
3251 && elf_section_data (sec)->this_hdr.contents != contents)
3252 free (contents);
3253 contents = NULL;
3254
3255 if (internal_relocs != NULL
3256 && elf_section_data (sec)->relocs != internal_relocs)
3257 free (internal_relocs);
3258 internal_relocs = NULL;
252b5132
RH
3259 }
3260
b34976b6 3261 return TRUE;
9a5aca8c 3262
252b5132 3263error_return:
6cdc0ccc
AM
3264 if (contents != NULL
3265 && elf_section_data (sec)->this_hdr.contents != contents)
3266 free (contents);
3267 if (internal_relocs != NULL
3268 && elf_section_data (sec)->relocs != internal_relocs)
3269 free (internal_relocs);
9a5aca8c 3270
b34976b6 3271 return FALSE;
252b5132 3272}
7e392df6 3273#endif
252b5132 3274
eb043451 3275
c7b8f16e
JB
3276/* Initialise maps of ARM/Thumb/data for input BFDs. */
3277
3278void
3279bfd_elf32_arm_init_maps (bfd *abfd)
3280{
3281 Elf_Internal_Sym *isymbuf;
3282 Elf_Internal_Shdr *hdr;
3283 unsigned int i, localsyms;
3284
3285 if ((abfd->flags & DYNAMIC) != 0)
3286 return;
3287
3288 hdr = &elf_tdata (abfd)->symtab_hdr;
3289 localsyms = hdr->sh_info;
3290
3291 /* Obtain a buffer full of symbols for this BFD. The hdr->sh_info field
3292 should contain the number of local symbols, which should come before any
3293 global symbols. Mapping symbols are always local. */
3294 isymbuf = bfd_elf_get_elf_syms (abfd, hdr, localsyms, 0, NULL, NULL,
3295 NULL);
3296
3297 /* No internal symbols read? Skip this BFD. */
3298 if (isymbuf == NULL)
3299 return;
3300
3301 for (i = 0; i < localsyms; i++)
3302 {
3303 Elf_Internal_Sym *isym = &isymbuf[i];
3304 asection *sec = bfd_section_from_elf_index (abfd, isym->st_shndx);
3305 const char *name;
3306
3307 if (sec != NULL
3308 && ELF_ST_BIND (isym->st_info) == STB_LOCAL)
3309 {
3310 name = bfd_elf_string_from_elf_section (abfd,
3311 hdr->sh_link, isym->st_name);
3312
3313 if (bfd_is_arm_special_symbol_name (name,
3314 BFD_ARM_SPECIAL_SYM_TYPE_MAP))
3315 elf32_arm_section_map_add (sec, name[1], isym->st_value);
3316 }
3317 }
3318}
3319
3320
3321void
3322bfd_elf32_arm_set_vfp11_fix (bfd *obfd, struct bfd_link_info *link_info)
3323{
3324 struct elf32_arm_link_hash_table *globals = elf32_arm_hash_table (link_info);
104d59d1 3325 obj_attribute *out_attr = elf_known_obj_attributes_proc (obfd);
c7b8f16e
JB
3326
3327 /* We assume that ARMv7+ does not need the VFP11 denorm erratum fix. */
3328 if (out_attr[Tag_CPU_arch].i >= TAG_CPU_ARCH_V7)
3329 {
3330 switch (globals->vfp11_fix)
3331 {
3332 case BFD_ARM_VFP11_FIX_DEFAULT:
3333 case BFD_ARM_VFP11_FIX_NONE:
3334 globals->vfp11_fix = BFD_ARM_VFP11_FIX_NONE;
3335 break;
3336
3337 default:
3338 /* Give a warning, but do as the user requests anyway. */
3339 (*_bfd_error_handler) (_("%B: warning: selected VFP11 erratum "
3340 "workaround is not necessary for target architecture"), obfd);
3341 }
3342 }
3343 else if (globals->vfp11_fix == BFD_ARM_VFP11_FIX_DEFAULT)
3344 /* For earlier architectures, we might need the workaround, but do not
3345 enable it by default. If users is running with broken hardware, they
3346 must enable the erratum fix explicitly. */
3347 globals->vfp11_fix = BFD_ARM_VFP11_FIX_NONE;
3348}
3349
3350
3351enum bfd_arm_vfp11_pipe {
3352 VFP11_FMAC,
3353 VFP11_LS,
3354 VFP11_DS,
3355 VFP11_BAD
3356};
3357
3358/* Return a VFP register number. This is encoded as RX:X for single-precision
3359 registers, or X:RX for double-precision registers, where RX is the group of
3360 four bits in the instruction encoding and X is the single extension bit.
3361 RX and X fields are specified using their lowest (starting) bit. The return
3362 value is:
3363
3364 0...31: single-precision registers s0...s31
3365 32...63: double-precision registers d0...d31.
3366
3367 Although X should be zero for VFP11 (encoding d0...d15 only), we might
3368 encounter VFP3 instructions, so we allow the full range for DP registers. */
3369
3370static unsigned int
3371bfd_arm_vfp11_regno (unsigned int insn, bfd_boolean is_double, unsigned int rx,
3372 unsigned int x)
3373{
3374 if (is_double)
3375 return (((insn >> rx) & 0xf) | (((insn >> x) & 1) << 4)) + 32;
3376 else
3377 return (((insn >> rx) & 0xf) << 1) | ((insn >> x) & 1);
3378}
3379
3380/* Set bits in *WMASK according to a register number REG as encoded by
3381 bfd_arm_vfp11_regno(). Ignore d16-d31. */
3382
3383static void
3384bfd_arm_vfp11_write_mask (unsigned int *wmask, unsigned int reg)
3385{
3386 if (reg < 32)
3387 *wmask |= 1 << reg;
3388 else if (reg < 48)
3389 *wmask |= 3 << ((reg - 32) * 2);
3390}
3391
3392/* Return TRUE if WMASK overwrites anything in REGS. */
3393
3394static bfd_boolean
3395bfd_arm_vfp11_antidependency (unsigned int wmask, int *regs, int numregs)
3396{
3397 int i;
3398
3399 for (i = 0; i < numregs; i++)
3400 {
3401 unsigned int reg = regs[i];
3402
3403 if (reg < 32 && (wmask & (1 << reg)) != 0)
3404 return TRUE;
3405
3406 reg -= 32;
3407
3408 if (reg >= 16)
3409 continue;
3410
3411 if ((wmask & (3 << (reg * 2))) != 0)
3412 return TRUE;
3413 }
3414
3415 return FALSE;
3416}
3417
3418/* In this function, we're interested in two things: finding input registers
3419 for VFP data-processing instructions, and finding the set of registers which
3420 arbitrary VFP instructions may write to. We use a 32-bit unsigned int to
3421 hold the written set, so FLDM etc. are easy to deal with (we're only
3422 interested in 32 SP registers or 16 dp registers, due to the VFP version
3423 implemented by the chip in question). DP registers are marked by setting
3424 both SP registers in the write mask). */
3425
3426static enum bfd_arm_vfp11_pipe
3427bfd_arm_vfp11_insn_decode (unsigned int insn, unsigned int *destmask, int *regs,
3428 int *numregs)
3429{
3430 enum bfd_arm_vfp11_pipe pipe = VFP11_BAD;
3431 bfd_boolean is_double = ((insn & 0xf00) == 0xb00) ? 1 : 0;
3432
3433 if ((insn & 0x0f000e10) == 0x0e000a00) /* A data-processing insn. */
3434 {
3435 unsigned int pqrs;
3436 unsigned int fd = bfd_arm_vfp11_regno (insn, is_double, 12, 22);
3437 unsigned int fm = bfd_arm_vfp11_regno (insn, is_double, 0, 5);
3438
3439 pqrs = ((insn & 0x00800000) >> 20)
3440 | ((insn & 0x00300000) >> 19)
3441 | ((insn & 0x00000040) >> 6);
3442
3443 switch (pqrs)
3444 {
3445 case 0: /* fmac[sd]. */
3446 case 1: /* fnmac[sd]. */
3447 case 2: /* fmsc[sd]. */
3448 case 3: /* fnmsc[sd]. */
3449 pipe = VFP11_FMAC;
3450 bfd_arm_vfp11_write_mask (destmask, fd);
3451 regs[0] = fd;
3452 regs[1] = bfd_arm_vfp11_regno (insn, is_double, 16, 7); /* Fn. */
3453 regs[2] = fm;
3454 *numregs = 3;
3455 break;
3456
3457 case 4: /* fmul[sd]. */
3458 case 5: /* fnmul[sd]. */
3459 case 6: /* fadd[sd]. */
3460 case 7: /* fsub[sd]. */
3461 pipe = VFP11_FMAC;
3462 goto vfp_binop;
3463
3464 case 8: /* fdiv[sd]. */
3465 pipe = VFP11_DS;
3466 vfp_binop:
3467 bfd_arm_vfp11_write_mask (destmask, fd);
3468 regs[0] = bfd_arm_vfp11_regno (insn, is_double, 16, 7); /* Fn. */
3469 regs[1] = fm;
3470 *numregs = 2;
3471 break;
3472
3473 case 15: /* extended opcode. */
3474 {
3475 unsigned int extn = ((insn >> 15) & 0x1e)
3476 | ((insn >> 7) & 1);
3477
3478 switch (extn)
3479 {
3480 case 0: /* fcpy[sd]. */
3481 case 1: /* fabs[sd]. */
3482 case 2: /* fneg[sd]. */
3483 case 8: /* fcmp[sd]. */
3484 case 9: /* fcmpe[sd]. */
3485 case 10: /* fcmpz[sd]. */
3486 case 11: /* fcmpez[sd]. */
3487 case 16: /* fuito[sd]. */
3488 case 17: /* fsito[sd]. */
3489 case 24: /* ftoui[sd]. */
3490 case 25: /* ftouiz[sd]. */
3491 case 26: /* ftosi[sd]. */
3492 case 27: /* ftosiz[sd]. */
3493 /* These instructions will not bounce due to underflow. */
3494 *numregs = 0;
3495 pipe = VFP11_FMAC;
3496 break;
3497
3498 case 3: /* fsqrt[sd]. */
3499 /* fsqrt cannot underflow, but it can (perhaps) overwrite
3500 registers to cause the erratum in previous instructions. */
3501 bfd_arm_vfp11_write_mask (destmask, fd);
3502 pipe = VFP11_DS;
3503 break;
3504
3505 case 15: /* fcvt{ds,sd}. */
3506 {
3507 int rnum = 0;
3508
3509 bfd_arm_vfp11_write_mask (destmask, fd);
3510
3511 /* Only FCVTSD can underflow. */
3512 if ((insn & 0x100) != 0)
3513 regs[rnum++] = fm;
3514
3515 *numregs = rnum;
3516
3517 pipe = VFP11_FMAC;
3518 }
3519 break;
3520
3521 default:
3522 return VFP11_BAD;
3523 }
3524 }
3525 break;
3526
3527 default:
3528 return VFP11_BAD;
3529 }
3530 }
3531 /* Two-register transfer. */
3532 else if ((insn & 0x0fe00ed0) == 0x0c400a10)
3533 {
3534 unsigned int fm = bfd_arm_vfp11_regno (insn, is_double, 0, 5);
3535
3536 if ((insn & 0x100000) == 0)
3537 {
3538 if (is_double)
3539 bfd_arm_vfp11_write_mask (destmask, fm);
3540 else
3541 {
3542 bfd_arm_vfp11_write_mask (destmask, fm);
3543 bfd_arm_vfp11_write_mask (destmask, fm + 1);
3544 }
3545 }
3546
3547 pipe = VFP11_LS;
3548 }
3549 else if ((insn & 0x0e100e00) == 0x0c100a00) /* A load insn. */
3550 {
3551 int fd = bfd_arm_vfp11_regno (insn, is_double, 12, 22);
3552 unsigned int puw = ((insn >> 21) & 0x1) | (((insn >> 23) & 3) << 1);
3553
3554 switch (puw)
3555 {
3556 case 0: /* Two-reg transfer. We should catch these above. */
3557 abort ();
3558
3559 case 2: /* fldm[sdx]. */
3560 case 3:
3561 case 5:
3562 {
3563 unsigned int i, offset = insn & 0xff;
3564
3565 if (is_double)
3566 offset >>= 1;
3567
3568 for (i = fd; i < fd + offset; i++)
3569 bfd_arm_vfp11_write_mask (destmask, i);
3570 }
3571 break;
3572
3573 case 4: /* fld[sd]. */
3574 case 6:
3575 bfd_arm_vfp11_write_mask (destmask, fd);
3576 break;
3577
3578 default:
3579 return VFP11_BAD;
3580 }
3581
3582 pipe = VFP11_LS;
3583 }
3584 /* Single-register transfer. Note L==0. */
3585 else if ((insn & 0x0f100e10) == 0x0e000a10)
3586 {
3587 unsigned int opcode = (insn >> 21) & 7;
3588 unsigned int fn = bfd_arm_vfp11_regno (insn, is_double, 16, 7);
3589
3590 switch (opcode)
3591 {
3592 case 0: /* fmsr/fmdlr. */
3593 case 1: /* fmdhr. */
3594 /* Mark fmdhr and fmdlr as writing to the whole of the DP
3595 destination register. I don't know if this is exactly right,
3596 but it is the conservative choice. */
3597 bfd_arm_vfp11_write_mask (destmask, fn);
3598 break;
3599
3600 case 7: /* fmxr. */
3601 break;
3602 }
3603
3604 pipe = VFP11_LS;
3605 }
3606
3607 return pipe;
3608}
3609
3610
3611static int elf32_arm_compare_mapping (const void * a, const void * b);
3612
3613
3614/* Look for potentially-troublesome code sequences which might trigger the
3615 VFP11 denormal/antidependency erratum. See, e.g., the ARM1136 errata sheet
3616 (available from ARM) for details of the erratum. A short version is
3617 described in ld.texinfo. */
3618
3619bfd_boolean
3620bfd_elf32_arm_vfp11_erratum_scan (bfd *abfd, struct bfd_link_info *link_info)
3621{
3622 asection *sec;
3623 bfd_byte *contents = NULL;
3624 int state = 0;
3625 int regs[3], numregs = 0;
3626 struct elf32_arm_link_hash_table *globals = elf32_arm_hash_table (link_info);
3627 int use_vector = (globals->vfp11_fix == BFD_ARM_VFP11_FIX_VECTOR);
3628
3629 /* We use a simple FSM to match troublesome VFP11 instruction sequences.
3630 The states transition as follows:
3631
3632 0 -> 1 (vector) or 0 -> 2 (scalar)
3633 A VFP FMAC-pipeline instruction has been seen. Fill
3634 regs[0]..regs[numregs-1] with its input operands. Remember this
3635 instruction in 'first_fmac'.
3636
3637 1 -> 2
3638 Any instruction, except for a VFP instruction which overwrites
3639 regs[*].
3640
3641 1 -> 3 [ -> 0 ] or
3642 2 -> 3 [ -> 0 ]
3643 A VFP instruction has been seen which overwrites any of regs[*].
3644 We must make a veneer! Reset state to 0 before examining next
3645 instruction.
3646
3647 2 -> 0
3648 If we fail to match anything in state 2, reset to state 0 and reset
3649 the instruction pointer to the instruction after 'first_fmac'.
3650
3651 If the VFP11 vector mode is in use, there must be at least two unrelated
3652 instructions between anti-dependent VFP11 instructions to properly avoid
3653 triggering the erratum, hence the use of the extra state 1.
3654 */
3655
3656 /* If we are only performing a partial link do not bother
3657 to construct any glue. */
3658 if (link_info->relocatable)
3659 return TRUE;
3660
3661 /* We should have chosen a fix type by the time we get here. */
3662 BFD_ASSERT (globals->vfp11_fix != BFD_ARM_VFP11_FIX_DEFAULT);
3663
3664 if (globals->vfp11_fix == BFD_ARM_VFP11_FIX_NONE)
3665 return TRUE;
2e6030b9
MS
3666
3667 /* Skip if this bfd does not correspond to an ELF image. */
3668 if (bfd_get_flavour (abfd) != bfd_target_elf_flavour)
3669 return TRUE;
c7b8f16e
JB
3670
3671 for (sec = abfd->sections; sec != NULL; sec = sec->next)
3672 {
3673 unsigned int i, span, first_fmac = 0, veneer_of_insn = 0;
3674 struct _arm_elf_section_data *sec_data;
3675
3676 /* If we don't have executable progbits, we're not interested in this
3677 section. Also skip if section is to be excluded. */
3678 if (elf_section_type (sec) != SHT_PROGBITS
3679 || (elf_section_flags (sec) & SHF_EXECINSTR) == 0
3680 || (sec->flags & SEC_EXCLUDE) != 0
3681 || strcmp (sec->name, VFP11_ERRATUM_VENEER_SECTION_NAME) == 0)
3682 continue;
3683
3684 sec_data = elf32_arm_section_data (sec);
3685
3686 if (sec_data->mapcount == 0)
3687 continue;
3688
3689 if (elf_section_data (sec)->this_hdr.contents != NULL)
3690 contents = elf_section_data (sec)->this_hdr.contents;
3691 else if (! bfd_malloc_and_get_section (abfd, sec, &contents))
3692 goto error_return;
3693
3694 qsort (sec_data->map, sec_data->mapcount, sizeof (elf32_arm_section_map),
3695 elf32_arm_compare_mapping);
3696
3697 for (span = 0; span < sec_data->mapcount; span++)
3698 {
3699 unsigned int span_start = sec_data->map[span].vma;
3700 unsigned int span_end = (span == sec_data->mapcount - 1)
3701 ? sec->size : sec_data->map[span + 1].vma;
3702 char span_type = sec_data->map[span].type;
3703
3704 /* FIXME: Only ARM mode is supported at present. We may need to
3705 support Thumb-2 mode also at some point. */
3706 if (span_type != 'a')
3707 continue;
3708
3709 for (i = span_start; i < span_end;)
3710 {
3711 unsigned int next_i = i + 4;
3712 unsigned int insn = bfd_big_endian (abfd)
3713 ? (contents[i] << 24)
3714 | (contents[i + 1] << 16)
3715 | (contents[i + 2] << 8)
3716 | contents[i + 3]
3717 : (contents[i + 3] << 24)
3718 | (contents[i + 2] << 16)
3719 | (contents[i + 1] << 8)
3720 | contents[i];
3721 unsigned int writemask = 0;
3722 enum bfd_arm_vfp11_pipe pipe;
3723
3724 switch (state)
3725 {
3726 case 0:
3727 pipe = bfd_arm_vfp11_insn_decode (insn, &writemask, regs,
3728 &numregs);
3729 /* I'm assuming the VFP11 erratum can trigger with denorm
3730 operands on either the FMAC or the DS pipeline. This might
3731 lead to slightly overenthusiastic veneer insertion. */
3732 if (pipe == VFP11_FMAC || pipe == VFP11_DS)
3733 {
3734 state = use_vector ? 1 : 2;
3735 first_fmac = i;
3736 veneer_of_insn = insn;
3737 }
3738 break;
3739
3740 case 1:
3741 {
3742 int other_regs[3], other_numregs;
3743 pipe = bfd_arm_vfp11_insn_decode (insn, &writemask,
3744 other_regs,
3745 &other_numregs);
3746 if (pipe != VFP11_BAD
3747 && bfd_arm_vfp11_antidependency (writemask, regs,
3748 numregs))
3749 state = 3;
3750 else
3751 state = 2;
3752 }
3753 break;
3754
3755 case 2:
3756 {
3757 int other_regs[3], other_numregs;
3758 pipe = bfd_arm_vfp11_insn_decode (insn, &writemask,
3759 other_regs,
3760 &other_numregs);
3761 if (pipe != VFP11_BAD
3762 && bfd_arm_vfp11_antidependency (writemask, regs,
3763 numregs))
3764 state = 3;
3765 else
3766 {
3767 state = 0;
3768 next_i = first_fmac + 4;
3769 }
3770 }
3771 break;
3772
3773 case 3:
3774 abort (); /* Should be unreachable. */
3775 }
3776
3777 if (state == 3)
3778 {
3779 elf32_vfp11_erratum_list *newerr
3780 = bfd_zmalloc (sizeof (elf32_vfp11_erratum_list));
3781 int errcount;
3782
3783 errcount = ++(elf32_arm_section_data (sec)->erratumcount);
3784
3785 newerr->u.b.vfp_insn = veneer_of_insn;
3786
3787 switch (span_type)
3788 {
3789 case 'a':
3790 newerr->type = VFP11_ERRATUM_BRANCH_TO_ARM_VENEER;
3791 break;
3792
3793 default:
3794 abort ();
3795 }
3796
3797 record_vfp11_erratum_veneer (link_info, newerr, abfd, sec,
3798 first_fmac);
3799
3800 newerr->vma = -1;
3801
3802 newerr->next = sec_data->erratumlist;
3803 sec_data->erratumlist = newerr;
3804
3805 state = 0;
3806 }
3807
3808 i = next_i;
3809 }
3810 }
3811
3812 if (contents != NULL
3813 && elf_section_data (sec)->this_hdr.contents != contents)
3814 free (contents);
3815 contents = NULL;
3816 }
3817
3818 return TRUE;
3819
3820error_return:
3821 if (contents != NULL
3822 && elf_section_data (sec)->this_hdr.contents != contents)
3823 free (contents);
3824
3825 return FALSE;
3826}
3827
3828/* Find virtual-memory addresses for VFP11 erratum veneers and return locations
3829 after sections have been laid out, using specially-named symbols. */
3830
3831void
3832bfd_elf32_arm_vfp11_fix_veneer_locations (bfd *abfd,
3833 struct bfd_link_info *link_info)
3834{
3835 asection *sec;
3836 struct elf32_arm_link_hash_table *globals;
3837 char *tmp_name;
3838
3839 if (link_info->relocatable)
3840 return;
2e6030b9
MS
3841
3842 /* Skip if this bfd does not correspond to an ELF image. */
3843 if (bfd_get_flavour (abfd) != bfd_target_elf_flavour)
3844 return;
3845
c7b8f16e
JB
3846 globals = elf32_arm_hash_table (link_info);
3847
3848 tmp_name = bfd_malloc ((bfd_size_type) strlen
3849 (VFP11_ERRATUM_VENEER_ENTRY_NAME) + 10);
3850
3851 for (sec = abfd->sections; sec != NULL; sec = sec->next)
3852 {
3853 struct _arm_elf_section_data *sec_data = elf32_arm_section_data (sec);
3854 elf32_vfp11_erratum_list *errnode = sec_data->erratumlist;
3855
3856 for (; errnode != NULL; errnode = errnode->next)
3857 {
3858 struct elf_link_hash_entry *myh;
3859 bfd_vma vma;
3860
3861 switch (errnode->type)
3862 {
3863 case VFP11_ERRATUM_BRANCH_TO_ARM_VENEER:
3864 case VFP11_ERRATUM_BRANCH_TO_THUMB_VENEER:
3865 /* Find veneer symbol. */
3866 sprintf (tmp_name, VFP11_ERRATUM_VENEER_ENTRY_NAME,
3867 errnode->u.b.veneer->u.v.id);
3868
3869 myh = elf_link_hash_lookup
3870 (&(globals)->root, tmp_name, FALSE, FALSE, TRUE);
3871
3872 if (myh == NULL)
3873 (*_bfd_error_handler) (_("%B: unable to find VFP11 veneer "
3874 "`%s'"), abfd, tmp_name);
3875
3876 vma = myh->root.u.def.section->output_section->vma
3877 + myh->root.u.def.section->output_offset
3878 + myh->root.u.def.value;
3879
3880 errnode->u.b.veneer->vma = vma;
3881 break;
3882
3883 case VFP11_ERRATUM_ARM_VENEER:
3884 case VFP11_ERRATUM_THUMB_VENEER:
3885 /* Find return location. */
3886 sprintf (tmp_name, VFP11_ERRATUM_VENEER_ENTRY_NAME "_r",
3887 errnode->u.v.id);
3888
3889 myh = elf_link_hash_lookup
3890 (&(globals)->root, tmp_name, FALSE, FALSE, TRUE);
3891
3892 if (myh == NULL)
3893 (*_bfd_error_handler) (_("%B: unable to find VFP11 veneer "
3894 "`%s'"), abfd, tmp_name);
3895
3896 vma = myh->root.u.def.section->output_section->vma
3897 + myh->root.u.def.section->output_offset
3898 + myh->root.u.def.value;
3899
3900 errnode->u.v.branch->vma = vma;
3901 break;
3902
3903 default:
3904 abort ();
3905 }
3906 }
3907 }
3908
3909 free (tmp_name);
3910}
3911
3912
eb043451
PB
3913/* Set target relocation values needed during linking. */
3914
3915void
bf21ed78
MS
3916bfd_elf32_arm_set_target_relocs (struct bfd *output_bfd,
3917 struct bfd_link_info *link_info,
eb043451 3918 int target1_is_rel,
319850b4 3919 char * target2_type,
33bfe774 3920 int fix_v4bx,
c7b8f16e 3921 int use_blx,
bf21ed78 3922 bfd_arm_vfp11_fix vfp11_fix,
27e55c4d 3923 int no_enum_warn, int pic_veneer)
eb043451
PB
3924{
3925 struct elf32_arm_link_hash_table *globals;
3926
3927 globals = elf32_arm_hash_table (link_info);
3928
3929 globals->target1_is_rel = target1_is_rel;
3930 if (strcmp (target2_type, "rel") == 0)
3931 globals->target2_reloc = R_ARM_REL32;
eeac373a
PB
3932 else if (strcmp (target2_type, "abs") == 0)
3933 globals->target2_reloc = R_ARM_ABS32;
eb043451
PB
3934 else if (strcmp (target2_type, "got-rel") == 0)
3935 globals->target2_reloc = R_ARM_GOT_PREL;
3936 else
3937 {
3938 _bfd_error_handler (_("Invalid TARGET2 relocation type '%s'."),
3939 target2_type);
3940 }
319850b4 3941 globals->fix_v4bx = fix_v4bx;
33bfe774 3942 globals->use_blx |= use_blx;
c7b8f16e 3943 globals->vfp11_fix = vfp11_fix;
27e55c4d 3944 globals->pic_veneer = pic_veneer;
bf21ed78
MS
3945
3946 elf32_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
9c504268
PB
4531 /* Some relocation type map to different relocations depending on the
4532 target. We pick the right one here. */
eb043451
PB
4533 r_type = arm_real_reloc_type (globals, r_type);
4534 if (r_type != howto->type)
4535 howto = elf32_arm_howto_from_type (r_type);
9c504268 4536
cac15327
NC
4537 /* If the start address has been set, then set the EF_ARM_HASENTRY
4538 flag. Setting this more than once is redundant, but the cost is
4539 not too high, and it keeps the code simple.
99e4ae17 4540
cac15327
NC
4541 The test is done here, rather than somewhere else, because the
4542 start address is only set just before the final link commences.
4543
4544 Note - if the user deliberately sets a start address of 0, the
4545 flag will not be set. */
4546 if (bfd_get_start_address (output_bfd) != 0)
4547 elf_elfheader (output_bfd)->e_flags |= EF_ARM_HASENTRY;
99e4ae17 4548
252b5132
RH
4549 dynobj = elf_hash_table (info)->dynobj;
4550 if (dynobj)
4551 {
4552 sgot = bfd_get_section_by_name (dynobj, ".got");
4553 splt = bfd_get_section_by_name (dynobj, ".plt");
4554 }
4555 symtab_hdr = & elf_tdata (input_bfd)->symtab_hdr;
4556 sym_hashes = elf_sym_hashes (input_bfd);
4557 local_got_offsets = elf_local_got_offsets (input_bfd);
4558 r_symndx = ELF32_R_SYM (rel->r_info);
4559
4e7fd91e 4560 if (globals->use_rel)
ba96a88f 4561 {
4e7fd91e
PB
4562 addend = bfd_get_32 (input_bfd, hit_data) & howto->src_mask;
4563
4564 if (addend & ((howto->src_mask + 1) >> 1))
4565 {
4566 signed_addend = -1;
4567 signed_addend &= ~ howto->src_mask;
4568 signed_addend |= addend;
4569 }
4570 else
4571 signed_addend = addend;
ba96a88f
NC
4572 }
4573 else
4e7fd91e 4574 addend = signed_addend = rel->r_addend;
f21f3fe0 4575
252b5132
RH
4576 switch (r_type)
4577 {
4578 case R_ARM_NONE:
28a094c2
DJ
4579 /* We don't need to find a value for this symbol. It's just a
4580 marker. */
4581 *unresolved_reloc_p = FALSE;
252b5132
RH
4582 return bfd_reloc_ok;
4583
00a97672
RS
4584 case R_ARM_ABS12:
4585 if (!globals->vxworks_p)
4586 return elf32_arm_abs12_reloc (input_bfd, hit_data, value + addend);
4587
252b5132
RH
4588 case R_ARM_PC24:
4589 case R_ARM_ABS32:
bb224fc3 4590 case R_ARM_ABS32_NOI:
252b5132 4591 case R_ARM_REL32:
bb224fc3 4592 case R_ARM_REL32_NOI:
5b5bb741
PB
4593 case R_ARM_CALL:
4594 case R_ARM_JUMP24:
dfc5f959 4595 case R_ARM_XPC25:
eb043451 4596 case R_ARM_PREL31:
7359ea65 4597 case R_ARM_PLT32:
7359ea65
DJ
4598 /* Handle relocations which should use the PLT entry. ABS32/REL32
4599 will use the symbol's value, which may point to a PLT entry, but we
4600 don't need to handle that here. If we created a PLT entry, all
4601 branches in this object should go to it. */
bb224fc3
MS
4602 if ((r_type != R_ARM_ABS32 && r_type != R_ARM_REL32
4603 && r_type != R_ARM_ABS32_NOI && r_type != R_ARM_REL32_NOI)
7359ea65 4604 && h != NULL
c84cd8ee 4605 && splt != NULL
7359ea65
DJ
4606 && h->plt.offset != (bfd_vma) -1)
4607 {
c84cd8ee
DJ
4608 /* If we've created a .plt section, and assigned a PLT entry to
4609 this function, it should not be known to bind locally. If
4610 it were, we would have cleared the PLT entry. */
7359ea65
DJ
4611 BFD_ASSERT (!SYMBOL_CALLS_LOCAL (info, h));
4612
4613 value = (splt->output_section->vma
4614 + splt->output_offset
4615 + h->plt.offset);
0945cdfd 4616 *unresolved_reloc_p = FALSE;
7359ea65
DJ
4617 return _bfd_final_link_relocate (howto, input_bfd, input_section,
4618 contents, rel->r_offset, value,
00a97672 4619 rel->r_addend);
7359ea65
DJ
4620 }
4621
67687978
PB
4622 /* When generating a shared object or relocatable executable, these
4623 relocations are copied into the output file to be resolved at
4624 run time. */
4625 if ((info->shared || globals->root.is_relocatable_executable)
7359ea65 4626 && (input_section->flags & SEC_ALLOC)
bb224fc3 4627 && ((r_type != R_ARM_REL32 && r_type != R_ARM_REL32_NOI)
ee06dc07 4628 || !SYMBOL_CALLS_LOCAL (info, h))
7359ea65
DJ
4629 && (h == NULL
4630 || ELF_ST_VISIBILITY (h->other) == STV_DEFAULT
4631 || h->root.type != bfd_link_hash_undefweak)
4632 && r_type != R_ARM_PC24
5b5bb741
PB
4633 && r_type != R_ARM_CALL
4634 && r_type != R_ARM_JUMP24
ee06dc07 4635 && r_type != R_ARM_PREL31
7359ea65 4636 && r_type != R_ARM_PLT32)
252b5132 4637 {
947216bf
AM
4638 Elf_Internal_Rela outrel;
4639 bfd_byte *loc;
b34976b6 4640 bfd_boolean skip, relocate;
f21f3fe0 4641
0945cdfd
DJ
4642 *unresolved_reloc_p = FALSE;
4643
252b5132
RH
4644 if (sreloc == NULL)
4645 {
4646 const char * name;
f21f3fe0 4647
252b5132
RH
4648 name = (bfd_elf_string_from_elf_section
4649 (input_bfd,
4650 elf_elfheader (input_bfd)->e_shstrndx,
4651 elf_section_data (input_section)->rel_hdr.sh_name));
4652 if (name == NULL)
4653 return bfd_reloc_notsupported;
f21f3fe0 4654
00a97672 4655 BFD_ASSERT (reloc_section_p (globals, name, input_section));
f21f3fe0 4656
252b5132
RH
4657 sreloc = bfd_get_section_by_name (dynobj, name);
4658 BFD_ASSERT (sreloc != NULL);
4659 }
f21f3fe0 4660
b34976b6
AM
4661 skip = FALSE;
4662 relocate = FALSE;
f21f3fe0 4663
00a97672 4664 outrel.r_addend = addend;
c629eae0
JJ
4665 outrel.r_offset =
4666 _bfd_elf_section_offset (output_bfd, info, input_section,
4667 rel->r_offset);
4668 if (outrel.r_offset == (bfd_vma) -1)
b34976b6 4669 skip = TRUE;
0bb2d96a 4670 else if (outrel.r_offset == (bfd_vma) -2)
b34976b6 4671 skip = TRUE, relocate = TRUE;
252b5132
RH
4672 outrel.r_offset += (input_section->output_section->vma
4673 + input_section->output_offset);
f21f3fe0 4674
252b5132 4675 if (skip)
0bb2d96a 4676 memset (&outrel, 0, sizeof outrel);
5e681ec4
PB
4677 else if (h != NULL
4678 && h->dynindx != -1
7359ea65 4679 && (!info->shared
5e681ec4 4680 || !info->symbolic
f5385ebf 4681 || !h->def_regular))
5e681ec4 4682 outrel.r_info = ELF32_R_INFO (h->dynindx, r_type);
252b5132
RH
4683 else
4684 {
a16385dc
MM
4685 int symbol;
4686
5e681ec4 4687 /* This symbol is local, or marked to become local. */
b7693d02
DJ
4688 if (sym_flags == STT_ARM_TFUNC)
4689 value |= 1;
a16385dc 4690 if (globals->symbian_p)
6366ff1e 4691 {
74541ad4
AM
4692 asection *osec;
4693
6366ff1e
MM
4694 /* On Symbian OS, the data segment and text segement
4695 can be relocated independently. Therefore, we
4696 must indicate the segment to which this
4697 relocation is relative. The BPABI allows us to
4698 use any symbol in the right segment; we just use
4699 the section symbol as it is convenient. (We
4700 cannot use the symbol given by "h" directly as it
74541ad4
AM
4701 will not appear in the dynamic symbol table.)
4702
4703 Note that the dynamic linker ignores the section
4704 symbol value, so we don't subtract osec->vma
4705 from the emitted reloc addend. */
10dbd1f3 4706 if (sym_sec)
74541ad4 4707 osec = sym_sec->output_section;
10dbd1f3 4708 else
74541ad4
AM
4709 osec = input_section->output_section;
4710 symbol = elf_section_data (osec)->dynindx;
4711 if (symbol == 0)
4712 {
4713 struct elf_link_hash_table *htab = elf_hash_table (info);
4714
4715 if ((osec->flags & SEC_READONLY) == 0
4716 && htab->data_index_section != NULL)
4717 osec = htab->data_index_section;
4718 else
4719 osec = htab->text_index_section;
4720 symbol = elf_section_data (osec)->dynindx;
4721 }
6366ff1e
MM
4722 BFD_ASSERT (symbol != 0);
4723 }
a16385dc
MM
4724 else
4725 /* On SVR4-ish systems, the dynamic loader cannot
4726 relocate the text and data segments independently,
4727 so the symbol does not matter. */
4728 symbol = 0;
4729 outrel.r_info = ELF32_R_INFO (symbol, R_ARM_RELATIVE);
00a97672
RS
4730 if (globals->use_rel)
4731 relocate = TRUE;
4732 else
4733 outrel.r_addend += value;
252b5132 4734 }
f21f3fe0 4735
947216bf 4736 loc = sreloc->contents;
00a97672
RS
4737 loc += sreloc->reloc_count++ * RELOC_SIZE (globals);
4738 SWAP_RELOC_OUT (globals) (output_bfd, &outrel, loc);
9a5aca8c 4739
f21f3fe0 4740 /* If this reloc is against an external symbol, we do not want to
252b5132 4741 fiddle with the addend. Otherwise, we need to include the symbol
9b485d32 4742 value so that it becomes an addend for the dynamic reloc. */
252b5132
RH
4743 if (! relocate)
4744 return bfd_reloc_ok;
9a5aca8c 4745
f21f3fe0 4746 return _bfd_final_link_relocate (howto, input_bfd, input_section,
252b5132
RH
4747 contents, rel->r_offset, value,
4748 (bfd_vma) 0);
4749 }
4750 else switch (r_type)
4751 {
00a97672
RS
4752 case R_ARM_ABS12:
4753 return elf32_arm_abs12_reloc (input_bfd, hit_data, value + addend);
4754
dfc5f959 4755 case R_ARM_XPC25: /* Arm BLX instruction. */
5b5bb741
PB
4756 case R_ARM_CALL:
4757 case R_ARM_JUMP24:
dfc5f959 4758 case R_ARM_PC24: /* Arm B/BL instruction */
7359ea65 4759 case R_ARM_PLT32:
dfc5f959 4760 if (r_type == R_ARM_XPC25)
252b5132 4761 {
dfc5f959
NC
4762 /* Check for Arm calling Arm function. */
4763 /* FIXME: Should we translate the instruction into a BL
4764 instruction instead ? */
4765 if (sym_flags != STT_ARM_TFUNC)
d003868e
AM
4766 (*_bfd_error_handler)
4767 (_("\%B: Warning: Arm BLX instruction targets Arm function '%s'."),
4768 input_bfd,
4769 h ? h->root.root.string : "(local)");
dfc5f959 4770 }
39b41c9c 4771 else if (r_type != R_ARM_CALL || !globals->use_blx)
dfc5f959
NC
4772 {
4773 /* Check for Arm calling Thumb function. */
4774 if (sym_flags == STT_ARM_TFUNC)
4775 {
f2a9dd69
DJ
4776 if (elf32_arm_to_thumb_stub (info, sym_name, input_bfd,
4777 output_bfd, input_section,
4778 hit_data, sym_sec, rel->r_offset,
4779 signed_addend, value,
4780 error_message))
4781 return bfd_reloc_ok;
4782 else
4783 return bfd_reloc_dangerous;
dfc5f959 4784 }
252b5132 4785 }
ba96a88f 4786
dea514f5
PB
4787 /* The ARM ELF ABI says that this reloc is computed as: S - P + A
4788 where:
4789 S is the address of the symbol in the relocation.
4790 P is address of the instruction being relocated.
4791 A is the addend (extracted from the instruction) in bytes.
4792
4793 S is held in 'value'.
4794 P is the base address of the section containing the
4795 instruction plus the offset of the reloc into that
4796 section, ie:
4797 (input_section->output_section->vma +
4798 input_section->output_offset +
4799 rel->r_offset).
4800 A is the addend, converted into bytes, ie:
4801 (signed_addend * 4)
4802
4803 Note: None of these operations have knowledge of the pipeline
4804 size of the processor, thus it is up to the assembler to
4805 encode this information into the addend. */
4806 value -= (input_section->output_section->vma
4807 + input_section->output_offset);
4808 value -= rel->r_offset;
4e7fd91e
PB
4809 if (globals->use_rel)
4810 value += (signed_addend << howto->size);
4811 else
4812 /* RELA addends do not have to be adjusted by howto->size. */
4813 value += signed_addend;
23080146 4814
dcb5e6e6
NC
4815 signed_addend = value;
4816 signed_addend >>= howto->rightshift;
9a5aca8c 4817
5ab79981
PB
4818 /* A branch to an undefined weak symbol is turned into a jump to
4819 the next instruction. */
4820 if (h && h->root.type == bfd_link_hash_undefweak)
4821 {
4822 value = (bfd_get_32 (input_bfd, hit_data) & 0xf0000000)
4823 | 0x0affffff;
4824 }
4825 else
59f2c4e7 4826 {
9b485d32 4827 /* Perform a signed range check. */
dcb5e6e6 4828 if ( signed_addend > ((bfd_signed_vma) (howto->dst_mask >> 1))
59f2c4e7
NC
4829 || signed_addend < - ((bfd_signed_vma) ((howto->dst_mask + 1) >> 1)))
4830 return bfd_reloc_overflow;
9a5aca8c 4831
5ab79981 4832 addend = (value & 2);
39b41c9c 4833
5ab79981
PB
4834 value = (signed_addend & howto->dst_mask)
4835 | (bfd_get_32 (input_bfd, hit_data) & (~ howto->dst_mask));
39b41c9c 4836
5ab79981 4837 /* Set the H bit in the BLX instruction. */
39b41c9c 4838 if (sym_flags == STT_ARM_TFUNC)
39b41c9c 4839 {
5ab79981
PB
4840 if (addend)
4841 value |= (1 << 24);
4842 else
4843 value &= ~(bfd_vma)(1 << 24);
4844 }
4845 if (r_type == R_ARM_CALL)
4846 {
4847 /* Select the correct instruction (BL or BLX). */
4848 if (sym_flags == STT_ARM_TFUNC)
4849 value |= (1 << 28);
4850 else
4851 {
4852 value &= ~(bfd_vma)(1 << 28);
4853 value |= (1 << 24);
4854 }
39b41c9c
PB
4855 }
4856 }
252b5132 4857 break;
f21f3fe0 4858
252b5132
RH
4859 case R_ARM_ABS32:
4860 value += addend;
4861 if (sym_flags == STT_ARM_TFUNC)
4862 value |= 1;
4863 break;
f21f3fe0 4864
bb224fc3
MS
4865 case R_ARM_ABS32_NOI:
4866 value += addend;
4867 break;
4868
252b5132 4869 case R_ARM_REL32:
a8bc6c78
PB
4870 value += addend;
4871 if (sym_flags == STT_ARM_TFUNC)
4872 value |= 1;
252b5132 4873 value -= (input_section->output_section->vma
62efb346 4874 + input_section->output_offset + rel->r_offset);
252b5132 4875 break;
eb043451 4876
bb224fc3
MS
4877 case R_ARM_REL32_NOI:
4878 value += addend;
4879 value -= (input_section->output_section->vma
4880 + input_section->output_offset + rel->r_offset);
4881 break;
4882
eb043451
PB
4883 case R_ARM_PREL31:
4884 value -= (input_section->output_section->vma
4885 + input_section->output_offset + rel->r_offset);
4886 value += signed_addend;
4887 if (! h || h->root.type != bfd_link_hash_undefweak)
4888 {
4889 /* Check for overflow */
4890 if ((value ^ (value >> 1)) & (1 << 30))
4891 return bfd_reloc_overflow;
4892 }
4893 value &= 0x7fffffff;
4894 value |= (bfd_get_32 (input_bfd, hit_data) & 0x80000000);
4895 if (sym_flags == STT_ARM_TFUNC)
4896 value |= 1;
4897 break;
252b5132 4898 }
f21f3fe0 4899
252b5132
RH
4900 bfd_put_32 (input_bfd, value, hit_data);
4901 return bfd_reloc_ok;
4902
4903 case R_ARM_ABS8:
4904 value += addend;
4905 if ((long) value > 0x7f || (long) value < -0x80)
4906 return bfd_reloc_overflow;
4907
4908 bfd_put_8 (input_bfd, value, hit_data);
4909 return bfd_reloc_ok;
4910
4911 case R_ARM_ABS16:
4912 value += addend;
4913
4914 if ((long) value > 0x7fff || (long) value < -0x8000)
4915 return bfd_reloc_overflow;
4916
4917 bfd_put_16 (input_bfd, value, hit_data);
4918 return bfd_reloc_ok;
4919
252b5132 4920 case R_ARM_THM_ABS5:
9b485d32 4921 /* Support ldr and str instructions for the thumb. */
4e7fd91e
PB
4922 if (globals->use_rel)
4923 {
4924 /* Need to refetch addend. */
4925 addend = bfd_get_16 (input_bfd, hit_data) & howto->src_mask;
4926 /* ??? Need to determine shift amount from operand size. */
4927 addend >>= howto->rightshift;
4928 }
252b5132
RH
4929 value += addend;
4930
4931 /* ??? Isn't value unsigned? */
4932 if ((long) value > 0x1f || (long) value < -0x10)
4933 return bfd_reloc_overflow;
4934
4935 /* ??? Value needs to be properly shifted into place first. */
4936 value |= bfd_get_16 (input_bfd, hit_data) & 0xf83f;
4937 bfd_put_16 (input_bfd, value, hit_data);
4938 return bfd_reloc_ok;
4939
2cab6cc3
MS
4940 case R_ARM_THM_ALU_PREL_11_0:
4941 /* Corresponds to: addw.w reg, pc, #offset (and similarly for subw). */
4942 {
4943 bfd_vma insn;
4944 bfd_signed_vma relocation;
4945
4946 insn = (bfd_get_16 (input_bfd, hit_data) << 16)
4947 | bfd_get_16 (input_bfd, hit_data + 2);
4948
4949 if (globals->use_rel)
4950 {
4951 signed_addend = (insn & 0xff) | ((insn & 0x7000) >> 4)
4952 | ((insn & (1 << 26)) >> 15);
4953 if (insn & 0xf00000)
4954 signed_addend = -signed_addend;
4955 }
4956
4957 relocation = value + signed_addend;
4958 relocation -= (input_section->output_section->vma
4959 + input_section->output_offset
4960 + rel->r_offset);
4961
4962 value = abs (relocation);
4963
4964 if (value >= 0x1000)
4965 return bfd_reloc_overflow;
4966
4967 insn = (insn & 0xfb0f8f00) | (value & 0xff)
4968 | ((value & 0x700) << 4)
4969 | ((value & 0x800) << 15);
4970 if (relocation < 0)
4971 insn |= 0xa00000;
4972
4973 bfd_put_16 (input_bfd, insn >> 16, hit_data);
4974 bfd_put_16 (input_bfd, insn & 0xffff, hit_data + 2);
4975
4976 return bfd_reloc_ok;
4977 }
4978
4979 case R_ARM_THM_PC12:
4980 /* Corresponds to: ldr.w reg, [pc, #offset]. */
4981 {
4982 bfd_vma insn;
4983 bfd_signed_vma relocation;
4984
4985 insn = (bfd_get_16 (input_bfd, hit_data) << 16)
4986 | bfd_get_16 (input_bfd, hit_data + 2);
4987
4988 if (globals->use_rel)
4989 {
4990 signed_addend = insn & 0xfff;
4991 if (!(insn & (1 << 23)))
4992 signed_addend = -signed_addend;
4993 }
4994
4995 relocation = value + signed_addend;
4996 relocation -= (input_section->output_section->vma
4997 + input_section->output_offset
4998 + rel->r_offset);
4999
5000 value = abs (relocation);
5001
5002 if (value >= 0x1000)
5003 return bfd_reloc_overflow;
5004
5005 insn = (insn & 0xff7ff000) | value;
5006 if (relocation >= 0)
5007 insn |= (1 << 23);
5008
5009 bfd_put_16 (input_bfd, insn >> 16, hit_data);
5010 bfd_put_16 (input_bfd, insn & 0xffff, hit_data + 2);
5011
5012 return bfd_reloc_ok;
5013 }
5014
dfc5f959 5015 case R_ARM_THM_XPC22:
c19d1205 5016 case R_ARM_THM_CALL:
bd97cb95 5017 case R_ARM_THM_JUMP24:
dfc5f959 5018 /* Thumb BL (branch long instruction). */
252b5132 5019 {
b34976b6 5020 bfd_vma relocation;
e95de063 5021 bfd_vma reloc_sign;
b34976b6
AM
5022 bfd_boolean overflow = FALSE;
5023 bfd_vma upper_insn = bfd_get_16 (input_bfd, hit_data);
5024 bfd_vma lower_insn = bfd_get_16 (input_bfd, hit_data + 2);
e95de063
MS
5025 bfd_signed_vma reloc_signed_max;
5026 bfd_signed_vma reloc_signed_min;
b34976b6 5027 bfd_vma check;
252b5132 5028 bfd_signed_vma signed_check;
e95de063
MS
5029 int bitsize;
5030 int thumb2 = using_thumb2 (globals);
252b5132 5031
5ab79981
PB
5032 /* A branch to an undefined weak symbol is turned into a jump to
5033 the next instruction. */
5034 if (h && h->root.type == bfd_link_hash_undefweak)
5035 {
5036 bfd_put_16 (input_bfd, 0xe000, hit_data);
5037 bfd_put_16 (input_bfd, 0xbf00, hit_data + 2);
5038 return bfd_reloc_ok;
5039 }
5040
e95de063
MS
5041 /* Fetch the addend. We use the Thumb-2 encoding (backwards compatible
5042 with Thumb-1) involving the J1 and J2 bits. */
4e7fd91e
PB
5043 if (globals->use_rel)
5044 {
e95de063
MS
5045 bfd_vma s = (upper_insn & (1 << 10)) >> 10;
5046 bfd_vma upper = upper_insn & 0x3ff;
5047 bfd_vma lower = lower_insn & 0x7ff;
5048 bfd_vma j1 = (lower_insn & (1 << 13)) >> 13;
5049 bfd_vma j2 = (lower_insn & (1 << 11)) >> 11;
5050 bfd_vma i1 = j1 ^ s ? 0 : 1;
5051 bfd_vma i2 = j2 ^ s ? 0 : 1;
5052
5053 addend = (i1 << 23) | (i2 << 22) | (upper << 12) | (lower << 1);
5054 /* Sign extend. */
5055 addend = (addend | ((s ? 0 : 1) << 24)) - (1 << 24);
5056
4e7fd91e
PB
5057 signed_addend = addend;
5058 }
cb1afa5c 5059
dfc5f959
NC
5060 if (r_type == R_ARM_THM_XPC22)
5061 {
5062 /* Check for Thumb to Thumb call. */
5063 /* FIXME: Should we translate the instruction into a BL
5064 instruction instead ? */
5065 if (sym_flags == STT_ARM_TFUNC)
d003868e
AM
5066 (*_bfd_error_handler)
5067 (_("%B: Warning: Thumb BLX instruction targets thumb function '%s'."),
5068 input_bfd,
5069 h ? h->root.root.string : "(local)");
dfc5f959
NC
5070 }
5071 else
252b5132 5072 {
dfc5f959
NC
5073 /* If it is not a call to Thumb, assume call to Arm.
5074 If it is a call relative to a section name, then it is not a
b7693d02
DJ
5075 function call at all, but rather a long jump. Calls through
5076 the PLT do not require stubs. */
5077 if (sym_flags != STT_ARM_TFUNC && sym_flags != STT_SECTION
5078 && (h == NULL || splt == NULL
5079 || h->plt.offset == (bfd_vma) -1))
dfc5f959 5080 {
bd97cb95 5081 if (globals->use_blx && r_type == R_ARM_THM_CALL)
39b41c9c
PB
5082 {
5083 /* Convert BL to BLX. */
5084 lower_insn = (lower_insn & ~0x1000) | 0x0800;
5085 }
5086 else if (elf32_thumb_to_arm_stub
dfc5f959 5087 (info, sym_name, input_bfd, output_bfd, input_section,
f2a9dd69
DJ
5088 hit_data, sym_sec, rel->r_offset, signed_addend, value,
5089 error_message))
dfc5f959
NC
5090 return bfd_reloc_ok;
5091 else
5092 return bfd_reloc_dangerous;
5093 }
bd97cb95
DJ
5094 else if (sym_flags == STT_ARM_TFUNC && globals->use_blx
5095 && r_type == R_ARM_THM_CALL)
39b41c9c
PB
5096 {
5097 /* Make sure this is a BL. */
5098 lower_insn |= 0x1800;
5099 }
252b5132 5100 }
f21f3fe0 5101
b7693d02
DJ
5102 /* Handle calls via the PLT. */
5103 if (h != NULL && splt != NULL && h->plt.offset != (bfd_vma) -1)
5104 {
5105 value = (splt->output_section->vma
5106 + splt->output_offset
5107 + h->plt.offset);
bd97cb95 5108 if (globals->use_blx && r_type == R_ARM_THM_CALL)
33bfe774
JB
5109 {
5110 /* If the Thumb BLX instruction is available, convert the
5111 BL to a BLX instruction to call the ARM-mode PLT entry. */
39b41c9c 5112 lower_insn = (lower_insn & ~0x1000) | 0x0800;
33bfe774
JB
5113 }
5114 else
5115 /* Target the Thumb stub before the ARM PLT entry. */
5116 value -= PLT_THUMB_STUB_SIZE;
0945cdfd 5117 *unresolved_reloc_p = FALSE;
b7693d02
DJ
5118 }
5119
ba96a88f 5120 relocation = value + signed_addend;
f21f3fe0 5121
252b5132 5122 relocation -= (input_section->output_section->vma
ba96a88f
NC
5123 + input_section->output_offset
5124 + rel->r_offset);
9a5aca8c 5125
252b5132
RH
5126 check = relocation >> howto->rightshift;
5127
5128 /* If this is a signed value, the rightshift just dropped
5129 leading 1 bits (assuming twos complement). */
5130 if ((bfd_signed_vma) relocation >= 0)
5131 signed_check = check;
5132 else
5133 signed_check = check | ~((bfd_vma) -1 >> howto->rightshift);
5134
e95de063
MS
5135 /* Calculate the permissable maximum and minimum values for
5136 this relocation according to whether we're relocating for
5137 Thumb-2 or not. */
5138 bitsize = howto->bitsize;
5139 if (!thumb2)
5140 bitsize -= 2;
5141 reloc_signed_max = ((1 << (bitsize - 1)) - 1) >> howto->rightshift;
5142 reloc_signed_min = ~reloc_signed_max;
5143
252b5132 5144 /* Assumes two's complement. */
ba96a88f 5145 if (signed_check > reloc_signed_max || signed_check < reloc_signed_min)
b34976b6 5146 overflow = TRUE;
252b5132 5147
bd97cb95 5148 if ((lower_insn & 0x5000) == 0x4000)
c62e1cc3
NC
5149 /* For a BLX instruction, make sure that the relocation is rounded up
5150 to a word boundary. This follows the semantics of the instruction
5151 which specifies that bit 1 of the target address will come from bit
5152 1 of the base address. */
5153 relocation = (relocation + 2) & ~ 3;
cb1afa5c 5154
e95de063
MS
5155 /* Put RELOCATION back into the insn. Assumes two's complement.
5156 We use the Thumb-2 encoding, which is safe even if dealing with
5157 a Thumb-1 instruction by virtue of our overflow check above. */
5158 reloc_sign = (signed_check < 0) ? 1 : 0;
5159 upper_insn = (upper_insn & ~(bfd_vma) 0x7ff)
5160 | ((relocation >> 12) & 0x3ff)
5161 | (reloc_sign << 10);
5162 lower_insn = (lower_insn & ~(bfd_vma) 0x2fff)
5163 | (((!((relocation >> 23) & 1)) ^ reloc_sign) << 13)
5164 | (((!((relocation >> 22) & 1)) ^ reloc_sign) << 11)
5165 | ((relocation >> 1) & 0x7ff);
c62e1cc3 5166
252b5132
RH
5167 /* Put the relocated value back in the object file: */
5168 bfd_put_16 (input_bfd, upper_insn, hit_data);
5169 bfd_put_16 (input_bfd, lower_insn, hit_data + 2);
5170
5171 return (overflow ? bfd_reloc_overflow : bfd_reloc_ok);
5172 }
5173 break;
5174
c19d1205
ZW
5175 case R_ARM_THM_JUMP19:
5176 /* Thumb32 conditional branch instruction. */
5177 {
5178 bfd_vma relocation;
5179 bfd_boolean overflow = FALSE;
5180 bfd_vma upper_insn = bfd_get_16 (input_bfd, hit_data);
5181 bfd_vma lower_insn = bfd_get_16 (input_bfd, hit_data + 2);
a00a1f35
MS
5182 bfd_signed_vma reloc_signed_max = 0xffffe;
5183 bfd_signed_vma reloc_signed_min = -0x100000;
c19d1205
ZW
5184 bfd_signed_vma signed_check;
5185
5186 /* Need to refetch the addend, reconstruct the top three bits,
5187 and squish the two 11 bit pieces together. */
5188 if (globals->use_rel)
5189 {
5190 bfd_vma S = (upper_insn & 0x0400) >> 10;
a00a1f35 5191 bfd_vma upper = (upper_insn & 0x003f);
c19d1205
ZW
5192 bfd_vma J1 = (lower_insn & 0x2000) >> 13;
5193 bfd_vma J2 = (lower_insn & 0x0800) >> 11;
5194 bfd_vma lower = (lower_insn & 0x07ff);
5195
a00a1f35
MS
5196 upper |= J1 << 6;
5197 upper |= J2 << 7;
5198 upper |= (!S) << 8;
c19d1205
ZW
5199 upper -= 0x0100; /* Sign extend. */
5200
5201 addend = (upper << 12) | (lower << 1);
5202 signed_addend = addend;
5203 }
5204
bd97cb95
DJ
5205 /* Handle calls via the PLT. */
5206 if (h != NULL && splt != NULL && h->plt.offset != (bfd_vma) -1)
5207 {
5208 value = (splt->output_section->vma
5209 + splt->output_offset
5210 + h->plt.offset);
5211 /* Target the Thumb stub before the ARM PLT entry. */
5212 value -= PLT_THUMB_STUB_SIZE;
5213 *unresolved_reloc_p = FALSE;
5214 }
5215
c19d1205
ZW
5216 /* ??? Should handle interworking? GCC might someday try to
5217 use this for tail calls. */
5218
5219 relocation = value + signed_addend;
5220 relocation -= (input_section->output_section->vma
5221 + input_section->output_offset
5222 + rel->r_offset);
a00a1f35 5223 signed_check = (bfd_signed_vma) relocation;
c19d1205 5224
c19d1205
ZW
5225 if (signed_check > reloc_signed_max || signed_check < reloc_signed_min)
5226 overflow = TRUE;
5227
5228 /* Put RELOCATION back into the insn. */
5229 {
5230 bfd_vma S = (relocation & 0x00100000) >> 20;
5231 bfd_vma J2 = (relocation & 0x00080000) >> 19;
5232 bfd_vma J1 = (relocation & 0x00040000) >> 18;
5233 bfd_vma hi = (relocation & 0x0003f000) >> 12;
5234 bfd_vma lo = (relocation & 0x00000ffe) >> 1;
5235
a00a1f35 5236 upper_insn = (upper_insn & 0xfbc0) | (S << 10) | hi;
c19d1205
ZW
5237 lower_insn = (lower_insn & 0xd000) | (J1 << 13) | (J2 << 11) | lo;
5238 }
5239
5240 /* Put the relocated value back in the object file: */
5241 bfd_put_16 (input_bfd, upper_insn, hit_data);
5242 bfd_put_16 (input_bfd, lower_insn, hit_data + 2);
5243
5244 return (overflow ? bfd_reloc_overflow : bfd_reloc_ok);
5245 }
5246
5247 case R_ARM_THM_JUMP11:
5248 case R_ARM_THM_JUMP8:
5249 case R_ARM_THM_JUMP6:
51c5503b
NC
5250 /* Thumb B (branch) instruction). */
5251 {
6cf9e9fe 5252 bfd_signed_vma relocation;
51c5503b
NC
5253 bfd_signed_vma reloc_signed_max = (1 << (howto->bitsize - 1)) - 1;
5254 bfd_signed_vma reloc_signed_min = ~ reloc_signed_max;
51c5503b
NC
5255 bfd_signed_vma signed_check;
5256
c19d1205
ZW
5257 /* CZB cannot jump backward. */
5258 if (r_type == R_ARM_THM_JUMP6)
5259 reloc_signed_min = 0;
5260
4e7fd91e 5261 if (globals->use_rel)
6cf9e9fe 5262 {
4e7fd91e
PB
5263 /* Need to refetch addend. */
5264 addend = bfd_get_16 (input_bfd, hit_data) & howto->src_mask;
5265 if (addend & ((howto->src_mask + 1) >> 1))
5266 {
5267 signed_addend = -1;
5268 signed_addend &= ~ howto->src_mask;
5269 signed_addend |= addend;
5270 }
5271 else
5272 signed_addend = addend;
5273 /* The value in the insn has been right shifted. We need to
5274 undo this, so that we can perform the address calculation
5275 in terms of bytes. */
5276 signed_addend <<= howto->rightshift;
6cf9e9fe 5277 }
6cf9e9fe 5278 relocation = value + signed_addend;
51c5503b
NC
5279
5280 relocation -= (input_section->output_section->vma
5281 + input_section->output_offset
5282 + rel->r_offset);
5283
6cf9e9fe
NC
5284 relocation >>= howto->rightshift;
5285 signed_check = relocation;
c19d1205
ZW
5286
5287 if (r_type == R_ARM_THM_JUMP6)
5288 relocation = ((relocation & 0x0020) << 4) | ((relocation & 0x001f) << 3);
5289 else
5290 relocation &= howto->dst_mask;
51c5503b 5291 relocation |= (bfd_get_16 (input_bfd, hit_data) & (~ howto->dst_mask));
cedb70c5 5292
51c5503b
NC
5293 bfd_put_16 (input_bfd, relocation, hit_data);
5294
5295 /* Assumes two's complement. */
5296 if (signed_check > reloc_signed_max || signed_check < reloc_signed_min)
5297 return bfd_reloc_overflow;
5298
5299 return bfd_reloc_ok;
5300 }
cedb70c5 5301
8375c36b
PB
5302 case R_ARM_ALU_PCREL7_0:
5303 case R_ARM_ALU_PCREL15_8:
5304 case R_ARM_ALU_PCREL23_15:
5305 {
5306 bfd_vma insn;
5307 bfd_vma relocation;
5308
5309 insn = bfd_get_32 (input_bfd, hit_data);
4e7fd91e
PB
5310 if (globals->use_rel)
5311 {
5312 /* Extract the addend. */
5313 addend = (insn & 0xff) << ((insn & 0xf00) >> 7);
5314 signed_addend = addend;
5315 }
8375c36b
PB
5316 relocation = value + signed_addend;
5317
5318 relocation -= (input_section->output_section->vma
5319 + input_section->output_offset
5320 + rel->r_offset);
5321 insn = (insn & ~0xfff)
5322 | ((howto->bitpos << 7) & 0xf00)
5323 | ((relocation >> howto->bitpos) & 0xff);
5324 bfd_put_32 (input_bfd, value, hit_data);
5325 }
5326 return bfd_reloc_ok;
5327
252b5132
RH
5328 case R_ARM_GNU_VTINHERIT:
5329 case R_ARM_GNU_VTENTRY:
5330 return bfd_reloc_ok;
5331
c19d1205 5332 case R_ARM_GOTOFF32:
252b5132
RH
5333 /* Relocation is relative to the start of the
5334 global offset table. */
5335
5336 BFD_ASSERT (sgot != NULL);
5337 if (sgot == NULL)
5338 return bfd_reloc_notsupported;
9a5aca8c 5339
cedb70c5 5340 /* If we are addressing a Thumb function, we need to adjust the
ee29b9fb
RE
5341 address by one, so that attempts to call the function pointer will
5342 correctly interpret it as Thumb code. */
5343 if (sym_flags == STT_ARM_TFUNC)
5344 value += 1;
5345
252b5132
RH
5346 /* Note that sgot->output_offset is not involved in this
5347 calculation. We always want the start of .got. If we
5348 define _GLOBAL_OFFSET_TABLE in a different way, as is
5349 permitted by the ABI, we might have to change this
9b485d32 5350 calculation. */
252b5132 5351 value -= sgot->output_section->vma;
f21f3fe0 5352 return _bfd_final_link_relocate (howto, input_bfd, input_section,
99e4ae17 5353 contents, rel->r_offset, value,
00a97672 5354 rel->r_addend);
252b5132
RH
5355
5356 case R_ARM_GOTPC:
a7c10850 5357 /* Use global offset table as symbol value. */
252b5132 5358 BFD_ASSERT (sgot != NULL);
f21f3fe0 5359
252b5132
RH
5360 if (sgot == NULL)
5361 return bfd_reloc_notsupported;
5362
0945cdfd 5363 *unresolved_reloc_p = FALSE;
252b5132 5364 value = sgot->output_section->vma;
f21f3fe0 5365 return _bfd_final_link_relocate (howto, input_bfd, input_section,
99e4ae17 5366 contents, rel->r_offset, value,
00a97672 5367 rel->r_addend);
f21f3fe0 5368
252b5132 5369 case R_ARM_GOT32:
eb043451 5370 case R_ARM_GOT_PREL:
252b5132 5371 /* Relocation is to the entry for this symbol in the
9b485d32 5372 global offset table. */
252b5132
RH
5373 if (sgot == NULL)
5374 return bfd_reloc_notsupported;
f21f3fe0 5375
252b5132
RH
5376 if (h != NULL)
5377 {
5378 bfd_vma off;
5e681ec4 5379 bfd_boolean dyn;
f21f3fe0 5380
252b5132
RH
5381 off = h->got.offset;
5382 BFD_ASSERT (off != (bfd_vma) -1);
5e681ec4 5383 dyn = globals->root.dynamic_sections_created;
f21f3fe0 5384
5e681ec4 5385 if (! WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn, info->shared, h)
50d6c878 5386 || (info->shared
5e681ec4
PB
5387 && SYMBOL_REFERENCES_LOCAL (info, h))
5388 || (ELF_ST_VISIBILITY (h->other)
5389 && h->root.type == bfd_link_hash_undefweak))
252b5132
RH
5390 {
5391 /* This is actually a static link, or it is a -Bsymbolic link
5392 and the symbol is defined locally. We must initialize this
5393 entry in the global offset table. Since the offset must
5394 always be a multiple of 4, we use the least significant bit
5395 to record whether we have initialized it already.
f21f3fe0 5396
00a97672 5397 When doing a dynamic link, we create a .rel(a).got relocation
f21f3fe0 5398 entry to initialize the value. This is done in the
9b485d32 5399 finish_dynamic_symbol routine. */
252b5132
RH
5400 if ((off & 1) != 0)
5401 off &= ~1;
5402 else
5403 {
ee29b9fb
RE
5404 /* If we are addressing a Thumb function, we need to
5405 adjust the address by one, so that attempts to
5406 call the function pointer will correctly
5407 interpret it as Thumb code. */
5408 if (sym_flags == STT_ARM_TFUNC)
5409 value |= 1;
5410
252b5132
RH
5411 bfd_put_32 (output_bfd, value, sgot->contents + off);
5412 h->got.offset |= 1;
5413 }
5414 }
0945cdfd
DJ
5415 else
5416 *unresolved_reloc_p = FALSE;
f21f3fe0 5417
252b5132
RH
5418 value = sgot->output_offset + off;
5419 }
5420 else
5421 {
5422 bfd_vma off;
f21f3fe0 5423
252b5132
RH
5424 BFD_ASSERT (local_got_offsets != NULL &&
5425 local_got_offsets[r_symndx] != (bfd_vma) -1);
f21f3fe0 5426
252b5132 5427 off = local_got_offsets[r_symndx];
f21f3fe0 5428
252b5132
RH
5429 /* The offset must always be a multiple of 4. We use the
5430 least significant bit to record whether we have already
9b485d32 5431 generated the necessary reloc. */
252b5132
RH
5432 if ((off & 1) != 0)
5433 off &= ~1;
5434 else
5435 {
b7693d02
DJ
5436 /* If we are addressing a Thumb function, we need to
5437 adjust the address by one, so that attempts to
5438 call the function pointer will correctly
5439 interpret it as Thumb code. */
5440 if (sym_flags == STT_ARM_TFUNC)
5441 value |= 1;
5442
00a97672
RS
5443 if (globals->use_rel)
5444 bfd_put_32 (output_bfd, value, sgot->contents + off);
f21f3fe0 5445
252b5132
RH
5446 if (info->shared)
5447 {
5448 asection * srelgot;
947216bf
AM
5449 Elf_Internal_Rela outrel;
5450 bfd_byte *loc;
f21f3fe0 5451
00a97672
RS
5452 srelgot = (bfd_get_section_by_name
5453 (dynobj, RELOC_SECTION (globals, ".got")));
252b5132 5454 BFD_ASSERT (srelgot != NULL);
f21f3fe0 5455
00a97672 5456 outrel.r_addend = addend + value;
252b5132 5457 outrel.r_offset = (sgot->output_section->vma
f21f3fe0 5458 + sgot->output_offset
252b5132
RH
5459 + off);
5460 outrel.r_info = ELF32_R_INFO (0, R_ARM_RELATIVE);
947216bf 5461 loc = srelgot->contents;
00a97672
RS
5462 loc += srelgot->reloc_count++ * RELOC_SIZE (globals);
5463 SWAP_RELOC_OUT (globals) (output_bfd, &outrel, loc);
252b5132 5464 }
f21f3fe0 5465
252b5132
RH
5466 local_got_offsets[r_symndx] |= 1;
5467 }
f21f3fe0 5468
252b5132
RH
5469 value = sgot->output_offset + off;
5470 }
eb043451
PB
5471 if (r_type != R_ARM_GOT32)
5472 value += sgot->output_section->vma;
9a5aca8c 5473
f21f3fe0 5474 return _bfd_final_link_relocate (howto, input_bfd, input_section,
99e4ae17 5475 contents, rel->r_offset, value,
00a97672 5476 rel->r_addend);
f21f3fe0 5477
ba93b8ac
DJ
5478 case R_ARM_TLS_LDO32:
5479 value = value - dtpoff_base (info);
5480
5481 return _bfd_final_link_relocate (howto, input_bfd, input_section,
00a97672
RS
5482 contents, rel->r_offset, value,
5483 rel->r_addend);
ba93b8ac
DJ
5484
5485 case R_ARM_TLS_LDM32:
5486 {
5487 bfd_vma off;
5488
5489 if (globals->sgot == NULL)
5490 abort ();
5491
5492 off = globals->tls_ldm_got.offset;
5493
5494 if ((off & 1) != 0)
5495 off &= ~1;
5496 else
5497 {
5498 /* If we don't know the module number, create a relocation
5499 for it. */
5500 if (info->shared)
5501 {
5502 Elf_Internal_Rela outrel;
5503 bfd_byte *loc;
5504
5505 if (globals->srelgot == NULL)
5506 abort ();
5507
00a97672 5508 outrel.r_addend = 0;
ba93b8ac
DJ
5509 outrel.r_offset = (globals->sgot->output_section->vma
5510 + globals->sgot->output_offset + off);
5511 outrel.r_info = ELF32_R_INFO (0, R_ARM_TLS_DTPMOD32);
5512
00a97672
RS
5513 if (globals->use_rel)
5514 bfd_put_32 (output_bfd, outrel.r_addend,
5515 globals->sgot->contents + off);
ba93b8ac
DJ
5516
5517 loc = globals->srelgot->contents;
00a97672
RS
5518 loc += globals->srelgot->reloc_count++ * RELOC_SIZE (globals);
5519 SWAP_RELOC_OUT (globals) (output_bfd, &outrel, loc);
ba93b8ac
DJ
5520 }
5521 else
5522 bfd_put_32 (output_bfd, 1, globals->sgot->contents + off);
5523
5524 globals->tls_ldm_got.offset |= 1;
5525 }
5526
5527 value = globals->sgot->output_section->vma + globals->sgot->output_offset + off
5528 - (input_section->output_section->vma + input_section->output_offset + rel->r_offset);
5529
5530 return _bfd_final_link_relocate (howto, input_bfd, input_section,
5531 contents, rel->r_offset, value,
00a97672 5532 rel->r_addend);
ba93b8ac
DJ
5533 }
5534
5535 case R_ARM_TLS_GD32:
5536 case R_ARM_TLS_IE32:
5537 {
5538 bfd_vma off;
5539 int indx;
5540 char tls_type;
5541
5542 if (globals->sgot == NULL)
5543 abort ();
5544
5545 indx = 0;
5546 if (h != NULL)
5547 {
5548 bfd_boolean dyn;
5549 dyn = globals->root.dynamic_sections_created;
5550 if (WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn, info->shared, h)
5551 && (!info->shared
5552 || !SYMBOL_REFERENCES_LOCAL (info, h)))
5553 {
5554 *unresolved_reloc_p = FALSE;
5555 indx = h->dynindx;
5556 }
5557 off = h->got.offset;
5558 tls_type = ((struct elf32_arm_link_hash_entry *) h)->tls_type;
5559 }
5560 else
5561 {
5562 if (local_got_offsets == NULL)
5563 abort ();
5564 off = local_got_offsets[r_symndx];
5565 tls_type = elf32_arm_local_got_tls_type (input_bfd)[r_symndx];
5566 }
5567
5568 if (tls_type == GOT_UNKNOWN)
5569 abort ();
5570
5571 if ((off & 1) != 0)
5572 off &= ~1;
5573 else
5574 {
5575 bfd_boolean need_relocs = FALSE;
5576 Elf_Internal_Rela outrel;
5577 bfd_byte *loc = NULL;
5578 int cur_off = off;
5579
5580 /* The GOT entries have not been initialized yet. Do it
5581 now, and emit any relocations. If both an IE GOT and a
5582 GD GOT are necessary, we emit the GD first. */
5583
5584 if ((info->shared || indx != 0)
5585 && (h == NULL
5586 || ELF_ST_VISIBILITY (h->other) == STV_DEFAULT
5587 || h->root.type != bfd_link_hash_undefweak))
5588 {
5589 need_relocs = TRUE;
5590 if (globals->srelgot == NULL)
5591 abort ();
5592 loc = globals->srelgot->contents;
00a97672 5593 loc += globals->srelgot->reloc_count * RELOC_SIZE (globals);
ba93b8ac
DJ
5594 }
5595
5596 if (tls_type & GOT_TLS_GD)
5597 {
5598 if (need_relocs)
5599 {
00a97672 5600 outrel.r_addend = 0;
ba93b8ac 5601 outrel.r_offset = (globals->sgot->output_section->vma
00a97672
RS
5602 + globals->sgot->output_offset
5603 + cur_off);
ba93b8ac 5604 outrel.r_info = ELF32_R_INFO (indx, R_ARM_TLS_DTPMOD32);
ba93b8ac 5605
00a97672
RS
5606 if (globals->use_rel)
5607 bfd_put_32 (output_bfd, outrel.r_addend,
5608 globals->sgot->contents + cur_off);
5609
5610 SWAP_RELOC_OUT (globals) (output_bfd, &outrel, loc);
ba93b8ac 5611 globals->srelgot->reloc_count++;
00a97672 5612 loc += RELOC_SIZE (globals);
ba93b8ac
DJ
5613
5614 if (indx == 0)
5615 bfd_put_32 (output_bfd, value - dtpoff_base (info),
5616 globals->sgot->contents + cur_off + 4);
5617 else
5618 {
00a97672 5619 outrel.r_addend = 0;
ba93b8ac
DJ
5620 outrel.r_info = ELF32_R_INFO (indx,
5621 R_ARM_TLS_DTPOFF32);
5622 outrel.r_offset += 4;
00a97672
RS
5623
5624 if (globals->use_rel)
5625 bfd_put_32 (output_bfd, outrel.r_addend,
5626 globals->sgot->contents + cur_off + 4);
5627
5628
5629 SWAP_RELOC_OUT (globals) (output_bfd, &outrel, loc);
ba93b8ac 5630 globals->srelgot->reloc_count++;
00a97672 5631 loc += RELOC_SIZE (globals);
ba93b8ac
DJ
5632 }
5633 }
5634 else
5635 {
5636 /* If we are not emitting relocations for a
5637 general dynamic reference, then we must be in a
5638 static link or an executable link with the
5639 symbol binding locally. Mark it as belonging
5640 to module 1, the executable. */
5641 bfd_put_32 (output_bfd, 1,
5642 globals->sgot->contents + cur_off);
5643 bfd_put_32 (output_bfd, value - dtpoff_base (info),
5644 globals->sgot->contents + cur_off + 4);
5645 }
5646
5647 cur_off += 8;
5648 }
5649
5650 if (tls_type & GOT_TLS_IE)
5651 {
5652 if (need_relocs)
5653 {
00a97672
RS
5654 if (indx == 0)
5655 outrel.r_addend = value - dtpoff_base (info);
5656 else
5657 outrel.r_addend = 0;
ba93b8ac
DJ
5658 outrel.r_offset = (globals->sgot->output_section->vma
5659 + globals->sgot->output_offset
5660 + cur_off);
5661 outrel.r_info = ELF32_R_INFO (indx, R_ARM_TLS_TPOFF32);
5662
00a97672
RS
5663 if (globals->use_rel)
5664 bfd_put_32 (output_bfd, outrel.r_addend,
ba93b8ac
DJ
5665 globals->sgot->contents + cur_off);
5666
00a97672 5667 SWAP_RELOC_OUT (globals) (output_bfd, &outrel, loc);
ba93b8ac 5668 globals->srelgot->reloc_count++;
00a97672 5669 loc += RELOC_SIZE (globals);
ba93b8ac
DJ
5670 }
5671 else
5672 bfd_put_32 (output_bfd, tpoff (info, value),
5673 globals->sgot->contents + cur_off);
5674 cur_off += 4;
5675 }
5676
5677 if (h != NULL)
5678 h->got.offset |= 1;
5679 else
5680 local_got_offsets[r_symndx] |= 1;
5681 }
5682
5683 if ((tls_type & GOT_TLS_GD) && r_type != R_ARM_TLS_GD32)
5684 off += 8;
5685 value = globals->sgot->output_section->vma + globals->sgot->output_offset + off
5686 - (input_section->output_section->vma + input_section->output_offset + rel->r_offset);
5687
5688 return _bfd_final_link_relocate (howto, input_bfd, input_section,
5689 contents, rel->r_offset, value,
00a97672 5690 rel->r_addend);
ba93b8ac
DJ
5691 }
5692
5693 case R_ARM_TLS_LE32:
5694 if (info->shared)
5695 {
5696 (*_bfd_error_handler)
5697 (_("%B(%A+0x%lx): R_ARM_TLS_LE32 relocation not permitted in shared object"),
5698 input_bfd, input_section,
5699 (long) rel->r_offset, howto->name);
5700 return FALSE;
5701 }
5702 else
5703 value = tpoff (info, value);
5704
5705 return _bfd_final_link_relocate (howto, input_bfd, input_section,
00a97672
RS
5706 contents, rel->r_offset, value,
5707 rel->r_addend);
ba93b8ac 5708
319850b4
JB
5709 case R_ARM_V4BX:
5710 if (globals->fix_v4bx)
5711 {
5712 bfd_vma insn = bfd_get_32 (input_bfd, hit_data);
5713
5714 /* Ensure that we have a BX instruction. */
5715 BFD_ASSERT ((insn & 0x0ffffff0) == 0x012fff10);
5716
5717 /* Preserve Rm (lowest four bits) and the condition code
5718 (highest four bits). Other bits encode MOV PC,Rm. */
5719 insn = (insn & 0xf000000f) | 0x01a0f000;
5720
5721 bfd_put_32 (input_bfd, insn, hit_data);
5722 }
5723 return bfd_reloc_ok;
5724
b6895b4f
PB
5725 case R_ARM_MOVW_ABS_NC:
5726 case R_ARM_MOVT_ABS:
5727 case R_ARM_MOVW_PREL_NC:
5728 case R_ARM_MOVT_PREL:
92f5d02b
MS
5729 /* Until we properly support segment-base-relative addressing then
5730 we assume the segment base to be zero, as for the group relocations.
5731 Thus R_ARM_MOVW_BREL_NC has the same semantics as R_ARM_MOVW_ABS_NC
5732 and R_ARM_MOVT_BREL has the same semantics as R_ARM_MOVT_ABS. */
5733 case R_ARM_MOVW_BREL_NC:
5734 case R_ARM_MOVW_BREL:
5735 case R_ARM_MOVT_BREL:
b6895b4f
PB
5736 {
5737 bfd_vma insn = bfd_get_32 (input_bfd, hit_data);
5738
5739 if (globals->use_rel)
5740 {
5741 addend = ((insn >> 4) & 0xf000) | (insn & 0xfff);
5742 signed_addend = (addend ^ 0x10000) - 0x10000;
5743 }
92f5d02b 5744
b6895b4f 5745 value += signed_addend;
b6895b4f
PB
5746
5747 if (r_type == R_ARM_MOVW_PREL_NC || r_type == R_ARM_MOVT_PREL)
5748 value -= (input_section->output_section->vma
5749 + input_section->output_offset + rel->r_offset);
5750
92f5d02b
MS
5751 if (r_type == R_ARM_MOVW_BREL && value >= 0x10000)
5752 return bfd_reloc_overflow;
5753
5754 if (sym_flags == STT_ARM_TFUNC)
5755 value |= 1;
5756
5757 if (r_type == R_ARM_MOVT_ABS || r_type == R_ARM_MOVT_PREL
5758 || r_type == R_ARM_MOVT_BREL)
b6895b4f
PB
5759 value >>= 16;
5760
5761 insn &= 0xfff0f000;
5762 insn |= value & 0xfff;
5763 insn |= (value & 0xf000) << 4;
5764 bfd_put_32 (input_bfd, insn, hit_data);
5765 }
5766 return bfd_reloc_ok;
5767
5768 case R_ARM_THM_MOVW_ABS_NC:
5769 case R_ARM_THM_MOVT_ABS:
5770 case R_ARM_THM_MOVW_PREL_NC:
5771 case R_ARM_THM_MOVT_PREL:
92f5d02b
MS
5772 /* Until we properly support segment-base-relative addressing then
5773 we assume the segment base to be zero, as for the above relocations.
5774 Thus R_ARM_THM_MOVW_BREL_NC has the same semantics as
5775 R_ARM_THM_MOVW_ABS_NC and R_ARM_THM_MOVT_BREL has the same semantics
5776 as R_ARM_THM_MOVT_ABS. */
5777 case R_ARM_THM_MOVW_BREL_NC:
5778 case R_ARM_THM_MOVW_BREL:
5779 case R_ARM_THM_MOVT_BREL:
b6895b4f
PB
5780 {
5781 bfd_vma insn;
5782
5783 insn = bfd_get_16 (input_bfd, hit_data) << 16;
5784 insn |= bfd_get_16 (input_bfd, hit_data + 2);
5785
5786 if (globals->use_rel)
5787 {
5788 addend = ((insn >> 4) & 0xf000)
5789 | ((insn >> 15) & 0x0800)
5790 | ((insn >> 4) & 0x0700)
5791 | (insn & 0x00ff);
5792 signed_addend = (addend ^ 0x10000) - 0x10000;
5793 }
92f5d02b 5794
b6895b4f 5795 value += signed_addend;
b6895b4f
PB
5796
5797 if (r_type == R_ARM_THM_MOVW_PREL_NC || r_type == R_ARM_THM_MOVT_PREL)
5798 value -= (input_section->output_section->vma
5799 + input_section->output_offset + rel->r_offset);
5800
92f5d02b
MS
5801 if (r_type == R_ARM_THM_MOVW_BREL && value >= 0x10000)
5802 return bfd_reloc_overflow;
5803
5804 if (sym_flags == STT_ARM_TFUNC)
5805 value |= 1;
5806
5807 if (r_type == R_ARM_THM_MOVT_ABS || r_type == R_ARM_THM_MOVT_PREL
5808 || r_type == R_ARM_THM_MOVT_BREL)
b6895b4f
PB
5809 value >>= 16;
5810
5811 insn &= 0xfbf08f00;
5812 insn |= (value & 0xf000) << 4;
5813 insn |= (value & 0x0800) << 15;
5814 insn |= (value & 0x0700) << 4;
5815 insn |= (value & 0x00ff);
5816
5817 bfd_put_16 (input_bfd, insn >> 16, hit_data);
5818 bfd_put_16 (input_bfd, insn & 0xffff, hit_data + 2);
5819 }
5820 return bfd_reloc_ok;
5821
4962c51a
MS
5822 case R_ARM_ALU_PC_G0_NC:
5823 case R_ARM_ALU_PC_G1_NC:
5824 case R_ARM_ALU_PC_G0:
5825 case R_ARM_ALU_PC_G1:
5826 case R_ARM_ALU_PC_G2:
5827 case R_ARM_ALU_SB_G0_NC:
5828 case R_ARM_ALU_SB_G1_NC:
5829 case R_ARM_ALU_SB_G0:
5830 case R_ARM_ALU_SB_G1:
5831 case R_ARM_ALU_SB_G2:
5832 {
5833 bfd_vma insn = bfd_get_32 (input_bfd, hit_data);
5834 bfd_vma pc = input_section->output_section->vma
5835 + input_section->output_offset + rel->r_offset;
5836 /* sb should be the origin of the *segment* containing the symbol.
5837 It is not clear how to obtain this OS-dependent value, so we
5838 make an arbitrary choice of zero. */
5839 bfd_vma sb = 0;
5840 bfd_vma residual;
5841 bfd_vma g_n;
5842 bfd_signed_vma signed_value;
5843 int group = 0;
5844
5845 /* Determine which group of bits to select. */
5846 switch (r_type)
5847 {
5848 case R_ARM_ALU_PC_G0_NC:
5849 case R_ARM_ALU_PC_G0:
5850 case R_ARM_ALU_SB_G0_NC:
5851 case R_ARM_ALU_SB_G0:
5852 group = 0;
5853 break;
5854
5855 case R_ARM_ALU_PC_G1_NC:
5856 case R_ARM_ALU_PC_G1:
5857 case R_ARM_ALU_SB_G1_NC:
5858 case R_ARM_ALU_SB_G1:
5859 group = 1;
5860 break;
5861
5862 case R_ARM_ALU_PC_G2:
5863 case R_ARM_ALU_SB_G2:
5864 group = 2;
5865 break;
5866
5867 default:
5868 abort();
5869 }
5870
5871 /* If REL, extract the addend from the insn. If RELA, it will
5872 have already been fetched for us. */
5873 if (globals->use_rel)
5874 {
5875 int negative;
5876 bfd_vma constant = insn & 0xff;
5877 bfd_vma rotation = (insn & 0xf00) >> 8;
5878
5879 if (rotation == 0)
5880 signed_addend = constant;
5881 else
5882 {
5883 /* Compensate for the fact that in the instruction, the
5884 rotation is stored in multiples of 2 bits. */
5885 rotation *= 2;
5886
5887 /* Rotate "constant" right by "rotation" bits. */
5888 signed_addend = (constant >> rotation) |
5889 (constant << (8 * sizeof (bfd_vma) - rotation));
5890 }
5891
5892 /* Determine if the instruction is an ADD or a SUB.
5893 (For REL, this determines the sign of the addend.) */
5894 negative = identify_add_or_sub (insn);
5895 if (negative == 0)
5896 {
5897 (*_bfd_error_handler)
5898 (_("%B(%A+0x%lx): Only ADD or SUB instructions are allowed for ALU group relocations"),
5899 input_bfd, input_section,
5900 (long) rel->r_offset, howto->name);
5901 return bfd_reloc_overflow;
5902 }
5903
5904 signed_addend *= negative;
5905 }
5906
5907 /* Compute the value (X) to go in the place. */
5908 if (r_type == R_ARM_ALU_PC_G0_NC
5909 || r_type == R_ARM_ALU_PC_G1_NC
5910 || r_type == R_ARM_ALU_PC_G0
5911 || r_type == R_ARM_ALU_PC_G1
5912 || r_type == R_ARM_ALU_PC_G2)
5913 /* PC relative. */
5914 signed_value = value - pc + signed_addend;
5915 else
5916 /* Section base relative. */
5917 signed_value = value - sb + signed_addend;
5918
5919 /* If the target symbol is a Thumb function, then set the
5920 Thumb bit in the address. */
5921 if (sym_flags == STT_ARM_TFUNC)
5922 signed_value |= 1;
5923
5924 /* Calculate the value of the relevant G_n, in encoded
5925 constant-with-rotation format. */
5926 g_n = calculate_group_reloc_mask (abs (signed_value), group,
5927 &residual);
5928
5929 /* Check for overflow if required. */
5930 if ((r_type == R_ARM_ALU_PC_G0
5931 || r_type == R_ARM_ALU_PC_G1
5932 || r_type == R_ARM_ALU_PC_G2
5933 || r_type == R_ARM_ALU_SB_G0
5934 || r_type == R_ARM_ALU_SB_G1
5935 || r_type == R_ARM_ALU_SB_G2) && residual != 0)
5936 {
5937 (*_bfd_error_handler)
5938 (_("%B(%A+0x%lx): Overflow whilst splitting 0x%lx for group relocation %s"),
5939 input_bfd, input_section,
5940 (long) rel->r_offset, abs (signed_value), howto->name);
5941 return bfd_reloc_overflow;
5942 }
5943
5944 /* Mask out the value and the ADD/SUB part of the opcode; take care
5945 not to destroy the S bit. */
5946 insn &= 0xff1ff000;
5947
5948 /* Set the opcode according to whether the value to go in the
5949 place is negative. */
5950 if (signed_value < 0)
5951 insn |= 1 << 22;
5952 else
5953 insn |= 1 << 23;
5954
5955 /* Encode the offset. */
5956 insn |= g_n;
5957
5958 bfd_put_32 (input_bfd, insn, hit_data);
5959 }
5960 return bfd_reloc_ok;
5961
5962 case R_ARM_LDR_PC_G0:
5963 case R_ARM_LDR_PC_G1:
5964 case R_ARM_LDR_PC_G2:
5965 case R_ARM_LDR_SB_G0:
5966 case R_ARM_LDR_SB_G1:
5967 case R_ARM_LDR_SB_G2:
5968 {
5969 bfd_vma insn = bfd_get_32 (input_bfd, hit_data);
5970 bfd_vma pc = input_section->output_section->vma
5971 + input_section->output_offset + rel->r_offset;
5972 bfd_vma sb = 0; /* See note above. */
5973 bfd_vma residual;
5974 bfd_signed_vma signed_value;
5975 int group = 0;
5976
5977 /* Determine which groups of bits to calculate. */
5978 switch (r_type)
5979 {
5980 case R_ARM_LDR_PC_G0:
5981 case R_ARM_LDR_SB_G0:
5982 group = 0;
5983 break;
5984
5985 case R_ARM_LDR_PC_G1:
5986 case R_ARM_LDR_SB_G1:
5987 group = 1;
5988 break;
5989
5990 case R_ARM_LDR_PC_G2:
5991 case R_ARM_LDR_SB_G2:
5992 group = 2;
5993 break;
5994
5995 default:
5996 abort();
5997 }
5998
5999 /* If REL, extract the addend from the insn. If RELA, it will
6000 have already been fetched for us. */
6001 if (globals->use_rel)
6002 {
6003 int negative = (insn & (1 << 23)) ? 1 : -1;
6004 signed_addend = negative * (insn & 0xfff);
6005 }
6006
6007 /* Compute the value (X) to go in the place. */
6008 if (r_type == R_ARM_LDR_PC_G0
6009 || r_type == R_ARM_LDR_PC_G1
6010 || r_type == R_ARM_LDR_PC_G2)
6011 /* PC relative. */
6012 signed_value = value - pc + signed_addend;
6013 else
6014 /* Section base relative. */
6015 signed_value = value - sb + signed_addend;
6016
6017 /* Calculate the value of the relevant G_{n-1} to obtain
6018 the residual at that stage. */
6019 calculate_group_reloc_mask (abs (signed_value), group - 1, &residual);
6020
6021 /* Check for overflow. */
6022 if (residual >= 0x1000)
6023 {
6024 (*_bfd_error_handler)
6025 (_("%B(%A+0x%lx): Overflow whilst splitting 0x%lx for group relocation %s"),
6026 input_bfd, input_section,
6027 (long) rel->r_offset, abs (signed_value), howto->name);
6028 return bfd_reloc_overflow;
6029 }
6030
6031 /* Mask out the value and U bit. */
6032 insn &= 0xff7ff000;
6033
6034 /* Set the U bit if the value to go in the place is non-negative. */
6035 if (signed_value >= 0)
6036 insn |= 1 << 23;
6037
6038 /* Encode the offset. */
6039 insn |= residual;
6040
6041 bfd_put_32 (input_bfd, insn, hit_data);
6042 }
6043 return bfd_reloc_ok;
6044
6045 case R_ARM_LDRS_PC_G0:
6046 case R_ARM_LDRS_PC_G1:
6047 case R_ARM_LDRS_PC_G2:
6048 case R_ARM_LDRS_SB_G0:
6049 case R_ARM_LDRS_SB_G1:
6050 case R_ARM_LDRS_SB_G2:
6051 {
6052 bfd_vma insn = bfd_get_32 (input_bfd, hit_data);
6053 bfd_vma pc = input_section->output_section->vma
6054 + input_section->output_offset + rel->r_offset;
6055 bfd_vma sb = 0; /* See note above. */
6056 bfd_vma residual;
6057 bfd_signed_vma signed_value;
6058 int group = 0;
6059
6060 /* Determine which groups of bits to calculate. */
6061 switch (r_type)
6062 {
6063 case R_ARM_LDRS_PC_G0:
6064 case R_ARM_LDRS_SB_G0:
6065 group = 0;
6066 break;
6067
6068 case R_ARM_LDRS_PC_G1:
6069 case R_ARM_LDRS_SB_G1:
6070 group = 1;
6071 break;
6072
6073 case R_ARM_LDRS_PC_G2:
6074 case R_ARM_LDRS_SB_G2:
6075 group = 2;
6076 break;
6077
6078 default:
6079 abort();
6080 }
6081
6082 /* If REL, extract the addend from the insn. If RELA, it will
6083 have already been fetched for us. */
6084 if (globals->use_rel)
6085 {
6086 int negative = (insn & (1 << 23)) ? 1 : -1;
6087 signed_addend = negative * (((insn & 0xf00) >> 4) + (insn & 0xf));
6088 }
6089
6090 /* Compute the value (X) to go in the place. */
6091 if (r_type == R_ARM_LDRS_PC_G0
6092 || r_type == R_ARM_LDRS_PC_G1
6093 || r_type == R_ARM_LDRS_PC_G2)
6094 /* PC relative. */
6095 signed_value = value - pc + signed_addend;
6096 else
6097 /* Section base relative. */
6098 signed_value = value - sb + signed_addend;
6099
6100 /* Calculate the value of the relevant G_{n-1} to obtain
6101 the residual at that stage. */
6102 calculate_group_reloc_mask (abs (signed_value), group - 1, &residual);
6103
6104 /* Check for overflow. */
6105 if (residual >= 0x100)
6106 {
6107 (*_bfd_error_handler)
6108 (_("%B(%A+0x%lx): Overflow whilst splitting 0x%lx for group relocation %s"),
6109 input_bfd, input_section,
6110 (long) rel->r_offset, abs (signed_value), howto->name);
6111 return bfd_reloc_overflow;
6112 }
6113
6114 /* Mask out the value and U bit. */
6115 insn &= 0xff7ff0f0;
6116
6117 /* Set the U bit if the value to go in the place is non-negative. */
6118 if (signed_value >= 0)
6119 insn |= 1 << 23;
6120
6121 /* Encode the offset. */
6122 insn |= ((residual & 0xf0) << 4) | (residual & 0xf);
6123
6124 bfd_put_32 (input_bfd, insn, hit_data);
6125 }
6126 return bfd_reloc_ok;
6127
6128 case R_ARM_LDC_PC_G0:
6129 case R_ARM_LDC_PC_G1:
6130 case R_ARM_LDC_PC_G2:
6131 case R_ARM_LDC_SB_G0:
6132 case R_ARM_LDC_SB_G1:
6133 case R_ARM_LDC_SB_G2:
6134 {
6135 bfd_vma insn = bfd_get_32 (input_bfd, hit_data);
6136 bfd_vma pc = input_section->output_section->vma
6137 + input_section->output_offset + rel->r_offset;
6138 bfd_vma sb = 0; /* See note above. */
6139 bfd_vma residual;
6140 bfd_signed_vma signed_value;
6141 int group = 0;
6142
6143 /* Determine which groups of bits to calculate. */
6144 switch (r_type)
6145 {
6146 case R_ARM_LDC_PC_G0:
6147 case R_ARM_LDC_SB_G0:
6148 group = 0;
6149 break;
6150
6151 case R_ARM_LDC_PC_G1:
6152 case R_ARM_LDC_SB_G1:
6153 group = 1;
6154 break;
6155
6156 case R_ARM_LDC_PC_G2:
6157 case R_ARM_LDC_SB_G2:
6158 group = 2;
6159 break;
6160
6161 default:
6162 abort();
6163 }
6164
6165 /* If REL, extract the addend from the insn. If RELA, it will
6166 have already been fetched for us. */
6167 if (globals->use_rel)
6168 {
6169 int negative = (insn & (1 << 23)) ? 1 : -1;
6170 signed_addend = negative * ((insn & 0xff) << 2);
6171 }
6172
6173 /* Compute the value (X) to go in the place. */
6174 if (r_type == R_ARM_LDC_PC_G0
6175 || r_type == R_ARM_LDC_PC_G1
6176 || r_type == R_ARM_LDC_PC_G2)
6177 /* PC relative. */
6178 signed_value = value - pc + signed_addend;
6179 else
6180 /* Section base relative. */
6181 signed_value = value - sb + signed_addend;
6182
6183 /* Calculate the value of the relevant G_{n-1} to obtain
6184 the residual at that stage. */
6185 calculate_group_reloc_mask (abs (signed_value), group - 1, &residual);
6186
6187 /* Check for overflow. (The absolute value to go in the place must be
6188 divisible by four and, after having been divided by four, must
6189 fit in eight bits.) */
6190 if ((residual & 0x3) != 0 || residual >= 0x400)
6191 {
6192 (*_bfd_error_handler)
6193 (_("%B(%A+0x%lx): Overflow whilst splitting 0x%lx for group relocation %s"),
6194 input_bfd, input_section,
6195 (long) rel->r_offset, abs (signed_value), howto->name);
6196 return bfd_reloc_overflow;
6197 }
6198
6199 /* Mask out the value and U bit. */
6200 insn &= 0xff7fff00;
6201
6202 /* Set the U bit if the value to go in the place is non-negative. */
6203 if (signed_value >= 0)
6204 insn |= 1 << 23;
6205
6206 /* Encode the offset. */
6207 insn |= residual >> 2;
6208
6209 bfd_put_32 (input_bfd, insn, hit_data);
6210 }
6211 return bfd_reloc_ok;
6212
252b5132
RH
6213 default:
6214 return bfd_reloc_notsupported;
6215 }
6216}
6217
98c1d4aa
NC
6218/* Add INCREMENT to the reloc (of type HOWTO) at ADDRESS. */
6219static void
57e8b36a
NC
6220arm_add_to_rel (bfd * abfd,
6221 bfd_byte * address,
6222 reloc_howto_type * howto,
6223 bfd_signed_vma increment)
98c1d4aa 6224{
98c1d4aa
NC
6225 bfd_signed_vma addend;
6226
bd97cb95
DJ
6227 if (howto->type == R_ARM_THM_CALL
6228 || howto->type == R_ARM_THM_JUMP24)
98c1d4aa 6229 {
9a5aca8c
AM
6230 int upper_insn, lower_insn;
6231 int upper, lower;
98c1d4aa 6232
9a5aca8c
AM
6233 upper_insn = bfd_get_16 (abfd, address);
6234 lower_insn = bfd_get_16 (abfd, address + 2);
6235 upper = upper_insn & 0x7ff;
6236 lower = lower_insn & 0x7ff;
6237
6238 addend = (upper << 12) | (lower << 1);
ddda4409 6239 addend += increment;
9a5aca8c 6240 addend >>= 1;
98c1d4aa 6241
9a5aca8c
AM
6242 upper_insn = (upper_insn & 0xf800) | ((addend >> 11) & 0x7ff);
6243 lower_insn = (lower_insn & 0xf800) | (addend & 0x7ff);
6244
dc810e39
AM
6245 bfd_put_16 (abfd, (bfd_vma) upper_insn, address);
6246 bfd_put_16 (abfd, (bfd_vma) lower_insn, address + 2);
9a5aca8c
AM
6247 }
6248 else
6249 {
6250 bfd_vma contents;
6251
6252 contents = bfd_get_32 (abfd, address);
6253
6254 /* Get the (signed) value from the instruction. */
6255 addend = contents & howto->src_mask;
6256 if (addend & ((howto->src_mask + 1) >> 1))
6257 {
6258 bfd_signed_vma mask;
6259
6260 mask = -1;
6261 mask &= ~ howto->src_mask;
6262 addend |= mask;
6263 }
6264
6265 /* Add in the increment, (which is a byte value). */
6266 switch (howto->type)
6267 {
6268 default:
6269 addend += increment;
6270 break;
6271
6272 case R_ARM_PC24:
c6596c5e 6273 case R_ARM_PLT32:
5b5bb741
PB
6274 case R_ARM_CALL:
6275 case R_ARM_JUMP24:
9a5aca8c 6276 addend <<= howto->size;
dc810e39 6277 addend += increment;
9a5aca8c
AM
6278
6279 /* Should we check for overflow here ? */
6280
6281 /* Drop any undesired bits. */
6282 addend >>= howto->rightshift;
6283 break;
6284 }
6285
6286 contents = (contents & ~ howto->dst_mask) | (addend & howto->dst_mask);
6287
6288 bfd_put_32 (abfd, contents, address);
ddda4409 6289 }
98c1d4aa 6290}
252b5132 6291
ba93b8ac
DJ
6292#define IS_ARM_TLS_RELOC(R_TYPE) \
6293 ((R_TYPE) == R_ARM_TLS_GD32 \
6294 || (R_TYPE) == R_ARM_TLS_LDO32 \
6295 || (R_TYPE) == R_ARM_TLS_LDM32 \
6296 || (R_TYPE) == R_ARM_TLS_DTPOFF32 \
6297 || (R_TYPE) == R_ARM_TLS_DTPMOD32 \
6298 || (R_TYPE) == R_ARM_TLS_TPOFF32 \
6299 || (R_TYPE) == R_ARM_TLS_LE32 \
6300 || (R_TYPE) == R_ARM_TLS_IE32)
6301
252b5132 6302/* Relocate an ARM ELF section. */
b34976b6 6303static bfd_boolean
57e8b36a
NC
6304elf32_arm_relocate_section (bfd * output_bfd,
6305 struct bfd_link_info * info,
6306 bfd * input_bfd,
6307 asection * input_section,
6308 bfd_byte * contents,
6309 Elf_Internal_Rela * relocs,
6310 Elf_Internal_Sym * local_syms,
6311 asection ** local_sections)
252b5132 6312{
b34976b6
AM
6313 Elf_Internal_Shdr *symtab_hdr;
6314 struct elf_link_hash_entry **sym_hashes;
6315 Elf_Internal_Rela *rel;
6316 Elf_Internal_Rela *relend;
6317 const char *name;
b32d3aa2 6318 struct elf32_arm_link_hash_table * globals;
252b5132 6319
4e7fd91e 6320 globals = elf32_arm_hash_table (info);
b491616a 6321
252b5132
RH
6322 symtab_hdr = & elf_tdata (input_bfd)->symtab_hdr;
6323 sym_hashes = elf_sym_hashes (input_bfd);
6324
6325 rel = relocs;
6326 relend = relocs + input_section->reloc_count;
6327 for (; rel < relend; rel++)
6328 {
ba96a88f
NC
6329 int r_type;
6330 reloc_howto_type * howto;
6331 unsigned long r_symndx;
6332 Elf_Internal_Sym * sym;
6333 asection * sec;
252b5132 6334 struct elf_link_hash_entry * h;
ba96a88f
NC
6335 bfd_vma relocation;
6336 bfd_reloc_status_type r;
6337 arelent bfd_reloc;
ba93b8ac 6338 char sym_type;
0945cdfd 6339 bfd_boolean unresolved_reloc = FALSE;
f2a9dd69 6340 char *error_message = NULL;
f21f3fe0 6341
252b5132 6342 r_symndx = ELF32_R_SYM (rel->r_info);
ba96a88f 6343 r_type = ELF32_R_TYPE (rel->r_info);
b32d3aa2 6344 r_type = arm_real_reloc_type (globals, r_type);
252b5132 6345
ba96a88f
NC
6346 if ( r_type == R_ARM_GNU_VTENTRY
6347 || r_type == R_ARM_GNU_VTINHERIT)
252b5132
RH
6348 continue;
6349
b32d3aa2 6350 bfd_reloc.howto = elf32_arm_howto_from_type (r_type);
ba96a88f 6351 howto = bfd_reloc.howto;
252b5132 6352
252b5132
RH
6353 h = NULL;
6354 sym = NULL;
6355 sec = NULL;
9b485d32 6356
252b5132
RH
6357 if (r_symndx < symtab_hdr->sh_info)
6358 {
6359 sym = local_syms + r_symndx;
ba93b8ac 6360 sym_type = ELF32_ST_TYPE (sym->st_info);
252b5132 6361 sec = local_sections[r_symndx];
4e7fd91e 6362 if (globals->use_rel)
f8df10f4 6363 {
4e7fd91e
PB
6364 relocation = (sec->output_section->vma
6365 + sec->output_offset
6366 + sym->st_value);
ab96bf03
AM
6367 if (!info->relocatable
6368 && (sec->flags & SEC_MERGE)
6369 && ELF_ST_TYPE (sym->st_info) == STT_SECTION)
f8df10f4 6370 {
4e7fd91e
PB
6371 asection *msec;
6372 bfd_vma addend, value;
6373
6374 if (howto->rightshift)
6375 {
6376 (*_bfd_error_handler)
6377 (_("%B(%A+0x%lx): %s relocation against SEC_MERGE section"),
6378 input_bfd, input_section,
6379 (long) rel->r_offset, howto->name);
6380 return FALSE;
6381 }
f8df10f4 6382
4e7fd91e 6383 value = bfd_get_32 (input_bfd, contents + rel->r_offset);
f8df10f4 6384
4e7fd91e
PB
6385 /* Get the (signed) value from the instruction. */
6386 addend = value & howto->src_mask;
6387 if (addend & ((howto->src_mask + 1) >> 1))
6388 {
6389 bfd_signed_vma mask;
f8df10f4 6390
4e7fd91e
PB
6391 mask = -1;
6392 mask &= ~ howto->src_mask;
6393 addend |= mask;
6394 }
6395 msec = sec;
6396 addend =
6397 _bfd_elf_rel_local_sym (output_bfd, sym, &msec, addend)
6398 - relocation;
6399 addend += msec->output_section->vma + msec->output_offset;
6400 value = (value & ~ howto->dst_mask) | (addend & howto->dst_mask);
6401 bfd_put_32 (input_bfd, value, contents + rel->r_offset);
f8df10f4 6402 }
f8df10f4 6403 }
4e7fd91e
PB
6404 else
6405 relocation = _bfd_elf_rela_local_sym (output_bfd, sym, &sec, rel);
252b5132
RH
6406 }
6407 else
6408 {
560e09e9 6409 bfd_boolean warned;
560e09e9 6410
b2a8e766
AM
6411 RELOC_FOR_GLOBAL_SYMBOL (info, input_bfd, input_section, rel,
6412 r_symndx, symtab_hdr, sym_hashes,
6413 h, sec, relocation,
6414 unresolved_reloc, warned);
ba93b8ac
DJ
6415
6416 sym_type = h->type;
252b5132
RH
6417 }
6418
ab96bf03
AM
6419 if (sec != NULL && elf_discarded_section (sec))
6420 {
6421 /* For relocs against symbols from removed linkonce sections,
6422 or sections discarded by a linker script, we just want the
6423 section contents zeroed. Avoid any special processing. */
6424 _bfd_clear_contents (howto, input_bfd, contents + rel->r_offset);
6425 rel->r_info = 0;
6426 rel->r_addend = 0;
6427 continue;
6428 }
6429
6430 if (info->relocatable)
6431 {
6432 /* This is a relocatable link. We don't have to change
6433 anything, unless the reloc is against a section symbol,
6434 in which case we have to adjust according to where the
6435 section symbol winds up in the output section. */
6436 if (sym != NULL && ELF_ST_TYPE (sym->st_info) == STT_SECTION)
6437 {
6438 if (globals->use_rel)
6439 arm_add_to_rel (input_bfd, contents + rel->r_offset,
6440 howto, (bfd_signed_vma) sec->output_offset);
6441 else
6442 rel->r_addend += sec->output_offset;
6443 }
6444 continue;
6445 }
6446
252b5132
RH
6447 if (h != NULL)
6448 name = h->root.root.string;
6449 else
6450 {
6451 name = (bfd_elf_string_from_elf_section
6452 (input_bfd, symtab_hdr->sh_link, sym->st_name));
6453 if (name == NULL || *name == '\0')
6454 name = bfd_section_name (input_bfd, sec);
6455 }
f21f3fe0 6456
ba93b8ac
DJ
6457 if (r_symndx != 0
6458 && r_type != R_ARM_NONE
6459 && (h == NULL
6460 || h->root.type == bfd_link_hash_defined
6461 || h->root.type == bfd_link_hash_defweak)
6462 && IS_ARM_TLS_RELOC (r_type) != (sym_type == STT_TLS))
6463 {
6464 (*_bfd_error_handler)
6465 ((sym_type == STT_TLS
6466 ? _("%B(%A+0x%lx): %s used with TLS symbol %s")
6467 : _("%B(%A+0x%lx): %s used with non-TLS symbol %s")),
6468 input_bfd,
6469 input_section,
6470 (long) rel->r_offset,
6471 howto->name,
6472 name);
6473 }
6474
252b5132
RH
6475 r = elf32_arm_final_link_relocate (howto, input_bfd, output_bfd,
6476 input_section, contents, rel,
6477 relocation, info, sec, name,
6478 (h ? ELF_ST_TYPE (h->type) :
0945cdfd 6479 ELF_ST_TYPE (sym->st_info)), h,
f2a9dd69 6480 &unresolved_reloc, &error_message);
0945cdfd
DJ
6481
6482 /* Dynamic relocs are not propagated for SEC_DEBUGGING sections
6483 because such sections are not SEC_ALLOC and thus ld.so will
6484 not process them. */
6485 if (unresolved_reloc
6486 && !((input_section->flags & SEC_DEBUGGING) != 0
6487 && h->def_dynamic))
6488 {
6489 (*_bfd_error_handler)
843fe662
L
6490 (_("%B(%A+0x%lx): unresolvable %s relocation against symbol `%s'"),
6491 input_bfd,
6492 input_section,
6493 (long) rel->r_offset,
6494 howto->name,
6495 h->root.root.string);
0945cdfd
DJ
6496 return FALSE;
6497 }
252b5132
RH
6498
6499 if (r != bfd_reloc_ok)
6500 {
252b5132
RH
6501 switch (r)
6502 {
6503 case bfd_reloc_overflow:
cf919dfd
PB
6504 /* If the overflowing reloc was to an undefined symbol,
6505 we have already printed one error message and there
6506 is no point complaining again. */
6507 if ((! h ||
6508 h->root.type != bfd_link_hash_undefined)
6509 && (!((*info->callbacks->reloc_overflow)
dfeffb9f
L
6510 (info, (h ? &h->root : NULL), name, howto->name,
6511 (bfd_vma) 0, input_bfd, input_section,
6512 rel->r_offset))))
b34976b6 6513 return FALSE;
252b5132
RH
6514 break;
6515
6516 case bfd_reloc_undefined:
6517 if (!((*info->callbacks->undefined_symbol)
6518 (info, name, input_bfd, input_section,
b34976b6
AM
6519 rel->r_offset, TRUE)))
6520 return FALSE;
252b5132
RH
6521 break;
6522
6523 case bfd_reloc_outofrange:
f2a9dd69 6524 error_message = _("out of range");
252b5132
RH
6525 goto common_error;
6526
6527 case bfd_reloc_notsupported:
f2a9dd69 6528 error_message = _("unsupported relocation");
252b5132
RH
6529 goto common_error;
6530
6531 case bfd_reloc_dangerous:
f2a9dd69 6532 /* error_message should already be set. */
252b5132
RH
6533 goto common_error;
6534
6535 default:
f2a9dd69 6536 error_message = _("unknown error");
252b5132
RH
6537 /* fall through */
6538
6539 common_error:
f2a9dd69
DJ
6540 BFD_ASSERT (error_message != NULL);
6541 if (!((*info->callbacks->reloc_dangerous)
6542 (info, error_message, input_bfd, input_section,
252b5132 6543 rel->r_offset)))
b34976b6 6544 return FALSE;
252b5132
RH
6545 break;
6546 }
6547 }
6548 }
6549
b34976b6 6550 return TRUE;
252b5132
RH
6551}
6552
c178919b
NC
6553/* Set the right machine number. */
6554
6555static bfd_boolean
57e8b36a 6556elf32_arm_object_p (bfd *abfd)
c178919b 6557{
5a6c6817 6558 unsigned int mach;
57e8b36a 6559
5a6c6817 6560 mach = bfd_arm_get_mach_from_notes (abfd, ARM_NOTE_SECTION);
c178919b 6561
5a6c6817
NC
6562 if (mach != bfd_mach_arm_unknown)
6563 bfd_default_set_arch_mach (abfd, bfd_arch_arm, mach);
6564
6565 else if (elf_elfheader (abfd)->e_flags & EF_ARM_MAVERICK_FLOAT)
6566 bfd_default_set_arch_mach (abfd, bfd_arch_arm, bfd_mach_arm_ep9312);
e16bb312 6567
e16bb312 6568 else
5a6c6817 6569 bfd_default_set_arch_mach (abfd, bfd_arch_arm, mach);
c178919b
NC
6570
6571 return TRUE;
6572}
6573
fc830a83 6574/* Function to keep ARM specific flags in the ELF header. */
3c9458e9 6575
b34976b6 6576static bfd_boolean
57e8b36a 6577elf32_arm_set_private_flags (bfd *abfd, flagword flags)
252b5132
RH
6578{
6579 if (elf_flags_init (abfd)
6580 && elf_elfheader (abfd)->e_flags != flags)
6581 {
fc830a83
NC
6582 if (EF_ARM_EABI_VERSION (flags) == EF_ARM_EABI_UNKNOWN)
6583 {
fd2ec330 6584 if (flags & EF_ARM_INTERWORK)
d003868e
AM
6585 (*_bfd_error_handler)
6586 (_("Warning: Not setting interworking flag of %B since it has already been specified as non-interworking"),
6587 abfd);
fc830a83 6588 else
d003868e
AM
6589 _bfd_error_handler
6590 (_("Warning: Clearing the interworking flag of %B due to outside request"),
6591 abfd);
fc830a83 6592 }
252b5132
RH
6593 }
6594 else
6595 {
6596 elf_elfheader (abfd)->e_flags = flags;
b34976b6 6597 elf_flags_init (abfd) = TRUE;
252b5132
RH
6598 }
6599
b34976b6 6600 return TRUE;
252b5132
RH
6601}
6602
fc830a83 6603/* Copy backend specific data from one object module to another. */
9b485d32 6604
b34976b6 6605static bfd_boolean
57e8b36a 6606elf32_arm_copy_private_bfd_data (bfd *ibfd, bfd *obfd)
252b5132
RH
6607{
6608 flagword in_flags;
6609 flagword out_flags;
6610
fc830a83 6611 if ( bfd_get_flavour (ibfd) != bfd_target_elf_flavour
252b5132 6612 || bfd_get_flavour (obfd) != bfd_target_elf_flavour)
b34976b6 6613 return TRUE;
252b5132 6614
fc830a83 6615 in_flags = elf_elfheader (ibfd)->e_flags;
252b5132
RH
6616 out_flags = elf_elfheader (obfd)->e_flags;
6617
fc830a83
NC
6618 if (elf_flags_init (obfd)
6619 && EF_ARM_EABI_VERSION (out_flags) == EF_ARM_EABI_UNKNOWN
6620 && in_flags != out_flags)
252b5132 6621 {
252b5132 6622 /* Cannot mix APCS26 and APCS32 code. */
fd2ec330 6623 if ((in_flags & EF_ARM_APCS_26) != (out_flags & EF_ARM_APCS_26))
b34976b6 6624 return FALSE;
252b5132
RH
6625
6626 /* Cannot mix float APCS and non-float APCS code. */
fd2ec330 6627 if ((in_flags & EF_ARM_APCS_FLOAT) != (out_flags & EF_ARM_APCS_FLOAT))
b34976b6 6628 return FALSE;
252b5132
RH
6629
6630 /* If the src and dest have different interworking flags
6631 then turn off the interworking bit. */
fd2ec330 6632 if ((in_flags & EF_ARM_INTERWORK) != (out_flags & EF_ARM_INTERWORK))
252b5132 6633 {
fd2ec330 6634 if (out_flags & EF_ARM_INTERWORK)
d003868e
AM
6635 _bfd_error_handler
6636 (_("Warning: Clearing the interworking flag of %B because non-interworking code in %B has been linked with it"),
6637 obfd, ibfd);
252b5132 6638
fd2ec330 6639 in_flags &= ~EF_ARM_INTERWORK;
252b5132 6640 }
1006ba19
PB
6641
6642 /* Likewise for PIC, though don't warn for this case. */
fd2ec330
PB
6643 if ((in_flags & EF_ARM_PIC) != (out_flags & EF_ARM_PIC))
6644 in_flags &= ~EF_ARM_PIC;
252b5132
RH
6645 }
6646
6647 elf_elfheader (obfd)->e_flags = in_flags;
b34976b6 6648 elf_flags_init (obfd) = TRUE;
252b5132 6649
94a3258f
PB
6650 /* Also copy the EI_OSABI field. */
6651 elf_elfheader (obfd)->e_ident[EI_OSABI] =
6652 elf_elfheader (ibfd)->e_ident[EI_OSABI];
6653
104d59d1
JM
6654 /* Copy object attributes. */
6655 _bfd_elf_copy_obj_attributes (ibfd, obfd);
ee065d83
PB
6656
6657 return TRUE;
6658}
6659
6660/* Values for Tag_ABI_PCS_R9_use. */
6661enum
6662{
6663 AEABI_R9_V6,
6664 AEABI_R9_SB,
6665 AEABI_R9_TLS,
6666 AEABI_R9_unused
6667};
6668
6669/* Values for Tag_ABI_PCS_RW_data. */
6670enum
6671{
6672 AEABI_PCS_RW_data_absolute,
6673 AEABI_PCS_RW_data_PCrel,
6674 AEABI_PCS_RW_data_SBrel,
6675 AEABI_PCS_RW_data_unused
6676};
6677
6678/* Values for Tag_ABI_enum_size. */
6679enum
6680{
6681 AEABI_enum_unused,
6682 AEABI_enum_short,
6683 AEABI_enum_wide,
6684 AEABI_enum_forced_wide
6685};
6686
104d59d1
JM
6687/* Determine whether an object attribute tag takes an integer, a
6688 string or both. */
6689static int
6690elf32_arm_obj_attrs_arg_type (int tag)
6691{
6692 if (tag == Tag_compatibility)
6693 return 3;
6694 else if (tag == 4 || tag == 5)
6695 return 2;
6696 else if (tag < 32)
6697 return 1;
6698 else
6699 return (tag & 1) != 0 ? 2 : 1;
6700}
6701
ee065d83
PB
6702/* Merge EABI object attributes from IBFD into OBFD. Raise an error if there
6703 are conflicting attributes. */
6704static bfd_boolean
6705elf32_arm_merge_eabi_attributes (bfd *ibfd, bfd *obfd)
6706{
104d59d1
JM
6707 obj_attribute *in_attr;
6708 obj_attribute *out_attr;
6709 obj_attribute_list *in_list;
ee065d83
PB
6710 /* Some tags have 0 = don't care, 1 = strong requirement,
6711 2 = weak requirement. */
6712 static const int order_312[3] = {3, 1, 2};
6713 int i;
6714
104d59d1 6715 if (!elf_known_obj_attributes_proc (obfd)[0].i)
ee065d83
PB
6716 {
6717 /* This is the first object. Copy the attributes. */
104d59d1 6718 _bfd_elf_copy_obj_attributes (ibfd, obfd);
004ae526
PB
6719
6720 /* Use the Tag_null value to indicate the attributes have been
6721 initialized. */
104d59d1 6722 elf_known_obj_attributes_proc (obfd)[0].i = 1;
004ae526 6723
ee065d83
PB
6724 return TRUE;
6725 }
6726
104d59d1
JM
6727 in_attr = elf_known_obj_attributes_proc (ibfd);
6728 out_attr = elf_known_obj_attributes_proc (obfd);
ee065d83
PB
6729 /* This needs to happen before Tag_ABI_FP_number_model is merged. */
6730 if (in_attr[Tag_ABI_VFP_args].i != out_attr[Tag_ABI_VFP_args].i)
6731 {
6732 /* Ignore mismatches if teh object doesn't use floating point. */
6733 if (out_attr[Tag_ABI_FP_number_model].i == 0)
6734 out_attr[Tag_ABI_VFP_args].i = in_attr[Tag_ABI_VFP_args].i;
6735 else if (in_attr[Tag_ABI_FP_number_model].i != 0)
6736 {
6737 _bfd_error_handler
6738 (_("ERROR: %B uses VFP register arguments, %B does not"),
6739 ibfd, obfd);
6740 return FALSE;
6741 }
6742 }
6743
104d59d1 6744 for (i = 4; i < NUM_KNOWN_OBJ_ATTRIBUTES; i++)
ee065d83
PB
6745 {
6746 /* Merge this attribute with existing attributes. */
6747 switch (i)
6748 {
6749 case Tag_CPU_raw_name:
6750 case Tag_CPU_name:
004ae526
PB
6751 /* Use whichever has the greatest architecture requirements. We
6752 won't necessarily have both the above tags, so make sure input
6753 name is non-NULL. */
6754 if (in_attr[Tag_CPU_arch].i > out_attr[Tag_CPU_arch].i
6755 && in_attr[i].s)
104d59d1 6756 out_attr[i].s = _bfd_elf_attr_strdup (obfd, in_attr[i].s);
ee065d83
PB
6757 break;
6758
6759 case Tag_ABI_optimization_goals:
6760 case Tag_ABI_FP_optimization_goals:
6761 /* Use the first value seen. */
6762 break;
6763
6764 case Tag_CPU_arch:
6765 case Tag_ARM_ISA_use:
6766 case Tag_THUMB_ISA_use:
6767 case Tag_VFP_arch:
6768 case Tag_WMMX_arch:
6769 case Tag_NEON_arch:
6770 /* ??? Do NEON and WMMX conflict? */
6771 case Tag_ABI_FP_rounding:
6772 case Tag_ABI_FP_denormal:
6773 case Tag_ABI_FP_exceptions:
6774 case Tag_ABI_FP_user_exceptions:
6775 case Tag_ABI_FP_number_model:
6776 case Tag_ABI_align8_preserved:
6777 case Tag_ABI_HardFP_use:
6778 /* Use the largest value specified. */
6779 if (in_attr[i].i > out_attr[i].i)
6780 out_attr[i].i = in_attr[i].i;
6781 break;
6782
6783 case Tag_CPU_arch_profile:
6784 /* Warn if conflicting architecture profiles used. */
6785 if (out_attr[i].i && in_attr[i].i && in_attr[i].i != out_attr[i].i)
6786 {
6787 _bfd_error_handler
6788 (_("ERROR: %B: Conflicting architecture profiles %c/%c"),
6789 ibfd, in_attr[i].i, out_attr[i].i);
6790 return FALSE;
6791 }
6792 if (in_attr[i].i)
6793 out_attr[i].i = in_attr[i].i;
6794 break;
6795 case Tag_PCS_config:
6796 if (out_attr[i].i == 0)
6797 out_attr[i].i = in_attr[i].i;
6798 else if (in_attr[i].i != 0 && out_attr[i].i != 0)
6799 {
6800 /* It's sometimes ok to mix different configs, so this is only
6801 a warning. */
6802 _bfd_error_handler
6803 (_("Warning: %B: Conflicting platform configuration"), ibfd);
6804 }
6805 break;
6806 case Tag_ABI_PCS_R9_use:
004ae526
PB
6807 if (in_attr[i].i != out_attr[i].i
6808 && out_attr[i].i != AEABI_R9_unused
ee065d83
PB
6809 && in_attr[i].i != AEABI_R9_unused)
6810 {
6811 _bfd_error_handler
6812 (_("ERROR: %B: Conflicting use of R9"), ibfd);
6813 return FALSE;
6814 }
6815 if (out_attr[i].i == AEABI_R9_unused)
6816 out_attr[i].i = in_attr[i].i;
6817 break;
6818 case Tag_ABI_PCS_RW_data:
6819 if (in_attr[i].i == AEABI_PCS_RW_data_SBrel
6820 && out_attr[Tag_ABI_PCS_R9_use].i != AEABI_R9_SB
6821 && out_attr[Tag_ABI_PCS_R9_use].i != AEABI_R9_unused)
6822 {
6823 _bfd_error_handler
6824 (_("ERROR: %B: SB relative addressing conflicts with use of R9"),
6825 ibfd);
6826 return FALSE;
6827 }
6828 /* Use the smallest value specified. */
6829 if (in_attr[i].i < out_attr[i].i)
6830 out_attr[i].i = in_attr[i].i;
6831 break;
6832 case Tag_ABI_PCS_RO_data:
6833 /* Use the smallest value specified. */
6834 if (in_attr[i].i < out_attr[i].i)
6835 out_attr[i].i = in_attr[i].i;
6836 break;
6837 case Tag_ABI_PCS_GOT_use:
6838 if (in_attr[i].i > 2 || out_attr[i].i > 2
6839 || order_312[in_attr[i].i] < order_312[out_attr[i].i])
6840 out_attr[i].i = in_attr[i].i;
6841 break;
6842 case Tag_ABI_PCS_wchar_t:
6843 if (out_attr[i].i && in_attr[i].i && out_attr[i].i != in_attr[i].i)
6844 {
6845 _bfd_error_handler
6846 (_("ERROR: %B: Conflicting definitions of wchar_t"), ibfd);
6847 return FALSE;
6848 }
6849 if (in_attr[i].i)
6850 out_attr[i].i = in_attr[i].i;
6851 break;
6852 case Tag_ABI_align8_needed:
6853 /* ??? Check against Tag_ABI_align8_preserved. */
6854 if (in_attr[i].i > 2 || out_attr[i].i > 2
6855 || order_312[in_attr[i].i] < order_312[out_attr[i].i])
6856 out_attr[i].i = in_attr[i].i;
6857 break;
6858 case Tag_ABI_enum_size:
6859 if (in_attr[i].i != AEABI_enum_unused)
6860 {
6861 if (out_attr[i].i == AEABI_enum_unused
6862 || out_attr[i].i == AEABI_enum_forced_wide)
6863 {
6864 /* The existing object is compatible with anything.
6865 Use whatever requirements the new object has. */
6866 out_attr[i].i = in_attr[i].i;
6867 }
6868 else if (in_attr[i].i != AEABI_enum_forced_wide
bf21ed78
MS
6869 && out_attr[i].i != in_attr[i].i
6870 && !elf32_arm_tdata (obfd)->no_enum_size_warning)
ee065d83 6871 {
bf21ed78
MS
6872 const char *aeabi_enum_names[] =
6873 { "", "variable-size", "32-bit", "" };
ee065d83 6874 _bfd_error_handler
bf21ed78
MS
6875 (_("warning: %B uses %s enums yet the output is to use %s enums; use of enum values across objects may fail"),
6876 ibfd, aeabi_enum_names[in_attr[i].i],
6877 aeabi_enum_names[out_attr[i].i]);
ee065d83
PB
6878 }
6879 }
6880 break;
6881 case Tag_ABI_VFP_args:
6882 /* Aready done. */
6883 break;
6884 case Tag_ABI_WMMX_args:
6885 if (in_attr[i].i != out_attr[i].i)
6886 {
6887 _bfd_error_handler
6888 (_("ERROR: %B uses iWMMXt register arguments, %B does not"),
6889 ibfd, obfd);
6890 return FALSE;
6891 }
6892 break;
6893 default: /* All known attributes should be explicitly covered. */
6894 abort ();
6895 }
3cfad14c
JM
6896
6897 if (in_attr[i].type && !out_attr[i].type)
6898 switch (in_attr[i].type)
6899 {
6900 case 1:
6901 if (out_attr[i].i)
6902 out_attr[i].type = 1;
6903 break;
6904
6905 case 2:
6906 if (out_attr[i].s)
6907 out_attr[i].type = 2;
6908 break;
6909
6910 default:
6911 abort ();
6912 }
ee065d83
PB
6913 }
6914
104d59d1
JM
6915 /* Merge Tag_compatibility attributes and any common GNU ones. */
6916 _bfd_elf_merge_object_attributes (ibfd, obfd);
ee065d83 6917
104d59d1
JM
6918 /* Check for any attributes not known on ARM. */
6919 in_list = elf_other_obj_attributes_proc (ibfd);
6920 while (in_list && in_list->tag == Tag_compatibility)
6921 in_list = in_list->next;
ee065d83
PB
6922
6923 for (; in_list; in_list = in_list->next)
6924 {
6925 if ((in_list->tag & 128) < 64)
eb111b1f
BE
6926 {
6927 _bfd_error_handler
6928 (_("Warning: %B: Unknown EABI object attribute %d"),
6929 ibfd, in_list->tag);
6930 break;
6931 }
ee065d83 6932 }
b34976b6 6933 return TRUE;
252b5132
RH
6934}
6935
3a4a14e9
PB
6936
6937/* Return TRUE if the two EABI versions are incompatible. */
6938
6939static bfd_boolean
6940elf32_arm_versions_compatible (unsigned iver, unsigned over)
6941{
6942 /* v4 and v5 are the same spec before and after it was released,
6943 so allow mixing them. */
6944 if ((iver == EF_ARM_EABI_VER4 && over == EF_ARM_EABI_VER5)
6945 || (iver == EF_ARM_EABI_VER5 && over == EF_ARM_EABI_VER4))
6946 return TRUE;
6947
6948 return (iver == over);
6949}
6950
252b5132
RH
6951/* Merge backend specific data from an object file to the output
6952 object file when linking. */
9b485d32 6953
b34976b6 6954static bfd_boolean
57e8b36a 6955elf32_arm_merge_private_bfd_data (bfd * ibfd, bfd * obfd)
252b5132
RH
6956{
6957 flagword out_flags;
6958 flagword in_flags;
b34976b6 6959 bfd_boolean flags_compatible = TRUE;
cf919dfd 6960 asection *sec;
252b5132 6961
9b485d32 6962 /* Check if we have the same endianess. */
82e51918 6963 if (! _bfd_generic_verify_endian_match (ibfd, obfd))
b34976b6 6964 return FALSE;
1fe494a5 6965
252b5132
RH
6966 if ( bfd_get_flavour (ibfd) != bfd_target_elf_flavour
6967 || bfd_get_flavour (obfd) != bfd_target_elf_flavour)
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
7354 globals = elf32_arm_hash_table (info);
5e681ec4
PB
7355
7356 elf_section_data (sec)->local_dynrel = NULL;
7357
7358 symtab_hdr = &elf_tdata (abfd)->symtab_hdr;
7359 sym_hashes = elf_sym_hashes (abfd);
7360 local_got_refcounts = elf_local_got_refcounts (abfd);
7361
bd97cb95
DJ
7362 check_use_blx(globals);
7363
5e681ec4
PB
7364 relend = relocs + sec->reloc_count;
7365 for (rel = relocs; rel < relend; rel++)
eb043451 7366 {
3eb128b2
AM
7367 unsigned long r_symndx;
7368 struct elf_link_hash_entry *h = NULL;
eb043451 7369 int r_type;
5e681ec4 7370
3eb128b2
AM
7371 r_symndx = ELF32_R_SYM (rel->r_info);
7372 if (r_symndx >= symtab_hdr->sh_info)
7373 {
7374 h = sym_hashes[r_symndx - symtab_hdr->sh_info];
7375 while (h->root.type == bfd_link_hash_indirect
7376 || h->root.type == bfd_link_hash_warning)
7377 h = (struct elf_link_hash_entry *) h->root.u.i.link;
7378 }
7379
eb043451 7380 r_type = ELF32_R_TYPE (rel->r_info);
eb043451 7381 r_type = arm_real_reloc_type (globals, r_type);
eb043451
PB
7382 switch (r_type)
7383 {
7384 case R_ARM_GOT32:
eb043451 7385 case R_ARM_GOT_PREL:
ba93b8ac
DJ
7386 case R_ARM_TLS_GD32:
7387 case R_ARM_TLS_IE32:
3eb128b2 7388 if (h != NULL)
eb043451 7389 {
eb043451
PB
7390 if (h->got.refcount > 0)
7391 h->got.refcount -= 1;
7392 }
7393 else if (local_got_refcounts != NULL)
7394 {
7395 if (local_got_refcounts[r_symndx] > 0)
7396 local_got_refcounts[r_symndx] -= 1;
7397 }
7398 break;
7399
ba93b8ac
DJ
7400 case R_ARM_TLS_LDM32:
7401 elf32_arm_hash_table (info)->tls_ldm_got.refcount -= 1;
7402 break;
7403
eb043451 7404 case R_ARM_ABS32:
bb224fc3 7405 case R_ARM_ABS32_NOI:
eb043451 7406 case R_ARM_REL32:
bb224fc3 7407 case R_ARM_REL32_NOI:
eb043451
PB
7408 case R_ARM_PC24:
7409 case R_ARM_PLT32:
5b5bb741
PB
7410 case R_ARM_CALL:
7411 case R_ARM_JUMP24:
eb043451 7412 case R_ARM_PREL31:
c19d1205 7413 case R_ARM_THM_CALL:
bd97cb95
DJ
7414 case R_ARM_THM_JUMP24:
7415 case R_ARM_THM_JUMP19:
b6895b4f
PB
7416 case R_ARM_MOVW_ABS_NC:
7417 case R_ARM_MOVT_ABS:
7418 case R_ARM_MOVW_PREL_NC:
7419 case R_ARM_MOVT_PREL:
7420 case R_ARM_THM_MOVW_ABS_NC:
7421 case R_ARM_THM_MOVT_ABS:
7422 case R_ARM_THM_MOVW_PREL_NC:
7423 case R_ARM_THM_MOVT_PREL:
b7693d02
DJ
7424 /* Should the interworking branches be here also? */
7425
3eb128b2 7426 if (h != NULL)
eb043451
PB
7427 {
7428 struct elf32_arm_link_hash_entry *eh;
7429 struct elf32_arm_relocs_copied **pp;
7430 struct elf32_arm_relocs_copied *p;
5e681ec4 7431
b7693d02 7432 eh = (struct elf32_arm_link_hash_entry *) h;
5e681ec4 7433
eb043451 7434 if (h->plt.refcount > 0)
b7693d02
DJ
7435 {
7436 h->plt.refcount -= 1;
bd97cb95
DJ
7437 if (r_type == R_ARM_THM_CALL)
7438 eh->plt_maybe_thumb_refcount--;
7439
7440 if (r_type == R_ARM_THM_JUMP24
7441 || r_type == R_ARM_THM_JUMP19)
b7693d02
DJ
7442 eh->plt_thumb_refcount--;
7443 }
5e681ec4 7444
eb043451 7445 if (r_type == R_ARM_ABS32
bb224fc3
MS
7446 || r_type == R_ARM_REL32
7447 || r_type == R_ARM_ABS32_NOI
7448 || r_type == R_ARM_REL32_NOI)
eb043451 7449 {
eb043451
PB
7450 for (pp = &eh->relocs_copied; (p = *pp) != NULL;
7451 pp = &p->next)
7452 if (p->section == sec)
7453 {
7454 p->count -= 1;
bb224fc3
MS
7455 if (ELF32_R_TYPE (rel->r_info) == R_ARM_REL32
7456 || ELF32_R_TYPE (rel->r_info) == R_ARM_REL32_NOI)
ba93b8ac 7457 p->pc_count -= 1;
eb043451
PB
7458 if (p->count == 0)
7459 *pp = p->next;
7460 break;
7461 }
7462 }
7463 }
7464 break;
5e681ec4 7465
eb043451
PB
7466 default:
7467 break;
7468 }
7469 }
5e681ec4 7470
b34976b6 7471 return TRUE;
252b5132
RH
7472}
7473
780a67af
NC
7474/* Look through the relocs for a section during the first phase. */
7475
b34976b6 7476static bfd_boolean
57e8b36a
NC
7477elf32_arm_check_relocs (bfd *abfd, struct bfd_link_info *info,
7478 asection *sec, const Elf_Internal_Rela *relocs)
252b5132 7479{
b34976b6
AM
7480 Elf_Internal_Shdr *symtab_hdr;
7481 struct elf_link_hash_entry **sym_hashes;
b34976b6
AM
7482 const Elf_Internal_Rela *rel;
7483 const Elf_Internal_Rela *rel_end;
7484 bfd *dynobj;
5e681ec4 7485 asection *sreloc;
b34976b6 7486 bfd_vma *local_got_offsets;
5e681ec4 7487 struct elf32_arm_link_hash_table *htab;
9a5aca8c 7488
1049f94e 7489 if (info->relocatable)
b34976b6 7490 return TRUE;
9a5aca8c 7491
5e681ec4
PB
7492 htab = elf32_arm_hash_table (info);
7493 sreloc = NULL;
9a5aca8c 7494
67687978
PB
7495 /* Create dynamic sections for relocatable executables so that we can
7496 copy relocations. */
7497 if (htab->root.is_relocatable_executable
7498 && ! htab->root.dynamic_sections_created)
7499 {
7500 if (! _bfd_elf_link_create_dynamic_sections (abfd, info))
7501 return FALSE;
7502 }
7503
252b5132
RH
7504 dynobj = elf_hash_table (info)->dynobj;
7505 local_got_offsets = elf_local_got_offsets (abfd);
f21f3fe0 7506
252b5132
RH
7507 symtab_hdr = &elf_tdata (abfd)->symtab_hdr;
7508 sym_hashes = elf_sym_hashes (abfd);
9b485d32 7509
252b5132
RH
7510 rel_end = relocs + sec->reloc_count;
7511 for (rel = relocs; rel < rel_end; rel++)
7512 {
7513 struct elf_link_hash_entry *h;
b7693d02 7514 struct elf32_arm_link_hash_entry *eh;
252b5132 7515 unsigned long r_symndx;
eb043451 7516 int r_type;
9a5aca8c 7517
252b5132 7518 r_symndx = ELF32_R_SYM (rel->r_info);
eb043451 7519 r_type = ELF32_R_TYPE (rel->r_info);
eb043451 7520 r_type = arm_real_reloc_type (htab, r_type);
ba93b8ac
DJ
7521
7522 if (r_symndx >= NUM_SHDR_ENTRIES (symtab_hdr))
7523 {
7524 (*_bfd_error_handler) (_("%B: bad symbol index: %d"), abfd,
7525 r_symndx);
7526 return FALSE;
7527 }
7528
252b5132
RH
7529 if (r_symndx < symtab_hdr->sh_info)
7530 h = NULL;
7531 else
973a3492
L
7532 {
7533 h = sym_hashes[r_symndx - symtab_hdr->sh_info];
7534 while (h->root.type == bfd_link_hash_indirect
7535 || h->root.type == bfd_link_hash_warning)
7536 h = (struct elf_link_hash_entry *) h->root.u.i.link;
7537 }
9a5aca8c 7538
b7693d02
DJ
7539 eh = (struct elf32_arm_link_hash_entry *) h;
7540
eb043451 7541 switch (r_type)
252b5132 7542 {
5e681ec4 7543 case R_ARM_GOT32:
eb043451 7544 case R_ARM_GOT_PREL:
ba93b8ac
DJ
7545 case R_ARM_TLS_GD32:
7546 case R_ARM_TLS_IE32:
5e681ec4 7547 /* This symbol requires a global offset table entry. */
ba93b8ac
DJ
7548 {
7549 int tls_type, old_tls_type;
5e681ec4 7550
ba93b8ac
DJ
7551 switch (r_type)
7552 {
7553 case R_ARM_TLS_GD32: tls_type = GOT_TLS_GD; break;
7554 case R_ARM_TLS_IE32: tls_type = GOT_TLS_IE; break;
7555 default: tls_type = GOT_NORMAL; break;
7556 }
252b5132 7557
ba93b8ac
DJ
7558 if (h != NULL)
7559 {
7560 h->got.refcount++;
7561 old_tls_type = elf32_arm_hash_entry (h)->tls_type;
7562 }
7563 else
7564 {
7565 bfd_signed_vma *local_got_refcounts;
7566
7567 /* This is a global offset table entry for a local symbol. */
7568 local_got_refcounts = elf_local_got_refcounts (abfd);
7569 if (local_got_refcounts == NULL)
7570 {
7571 bfd_size_type size;
7572
7573 size = symtab_hdr->sh_info;
7574 size *= (sizeof (bfd_signed_vma) + sizeof(char));
7575 local_got_refcounts = bfd_zalloc (abfd, size);
7576 if (local_got_refcounts == NULL)
7577 return FALSE;
7578 elf_local_got_refcounts (abfd) = local_got_refcounts;
7579 elf32_arm_local_got_tls_type (abfd)
7580 = (char *) (local_got_refcounts + symtab_hdr->sh_info);
7581 }
7582 local_got_refcounts[r_symndx] += 1;
7583 old_tls_type = elf32_arm_local_got_tls_type (abfd) [r_symndx];
7584 }
7585
7586 /* We will already have issued an error message if there is a
7587 TLS / non-TLS mismatch, based on the symbol type. We don't
7588 support any linker relaxations. So just combine any TLS
7589 types needed. */
7590 if (old_tls_type != GOT_UNKNOWN && old_tls_type != GOT_NORMAL
7591 && tls_type != GOT_NORMAL)
7592 tls_type |= old_tls_type;
7593
7594 if (old_tls_type != tls_type)
7595 {
7596 if (h != NULL)
7597 elf32_arm_hash_entry (h)->tls_type = tls_type;
7598 else
7599 elf32_arm_local_got_tls_type (abfd) [r_symndx] = tls_type;
7600 }
7601 }
7602 /* Fall through */
7603
7604 case R_ARM_TLS_LDM32:
7605 if (r_type == R_ARM_TLS_LDM32)
7606 htab->tls_ldm_got.refcount++;
7607 /* Fall through */
252b5132 7608
c19d1205 7609 case R_ARM_GOTOFF32:
5e681ec4
PB
7610 case R_ARM_GOTPC:
7611 if (htab->sgot == NULL)
7612 {
7613 if (htab->root.dynobj == NULL)
7614 htab->root.dynobj = abfd;
7615 if (!create_got_section (htab->root.dynobj, info))
7616 return FALSE;
7617 }
252b5132
RH
7618 break;
7619
00a97672
RS
7620 case R_ARM_ABS12:
7621 /* VxWorks uses dynamic R_ARM_ABS12 relocations for
7622 ldr __GOTT_INDEX__ offsets. */
7623 if (!htab->vxworks_p)
7624 break;
7625 /* Fall through */
7626
252b5132 7627 case R_ARM_ABS32:
bb224fc3 7628 case R_ARM_ABS32_NOI:
252b5132 7629 case R_ARM_REL32:
bb224fc3 7630 case R_ARM_REL32_NOI:
252b5132 7631 case R_ARM_PC24:
7359ea65 7632 case R_ARM_PLT32:
5b5bb741
PB
7633 case R_ARM_CALL:
7634 case R_ARM_JUMP24:
eb043451 7635 case R_ARM_PREL31:
c19d1205 7636 case R_ARM_THM_CALL:
bd97cb95
DJ
7637 case R_ARM_THM_JUMP24:
7638 case R_ARM_THM_JUMP19:
b6895b4f
PB
7639 case R_ARM_MOVW_ABS_NC:
7640 case R_ARM_MOVT_ABS:
7641 case R_ARM_MOVW_PREL_NC:
7642 case R_ARM_MOVT_PREL:
7643 case R_ARM_THM_MOVW_ABS_NC:
7644 case R_ARM_THM_MOVT_ABS:
7645 case R_ARM_THM_MOVW_PREL_NC:
7646 case R_ARM_THM_MOVT_PREL:
b7693d02 7647 /* Should the interworking branches be listed here? */
7359ea65 7648 if (h != NULL)
5e681ec4
PB
7649 {
7650 /* If this reloc is in a read-only section, we might
7651 need a copy reloc. We can't check reliably at this
7652 stage whether the section is read-only, as input
7653 sections have not yet been mapped to output sections.
7654 Tentatively set the flag for now, and correct in
7655 adjust_dynamic_symbol. */
7359ea65 7656 if (!info->shared)
f5385ebf 7657 h->non_got_ref = 1;
7359ea65 7658
5e681ec4 7659 /* We may need a .plt entry if the function this reloc
c84cd8ee
DJ
7660 refers to is in a different object. We can't tell for
7661 sure yet, because something later might force the
7662 symbol local. */
bb224fc3
MS
7663 if (r_type != R_ARM_ABS32
7664 && r_type != R_ARM_REL32
7665 && r_type != R_ARM_ABS32_NOI
d3753b85
RS
7666 && r_type != R_ARM_REL32_NOI
7667 && r_type != R_ARM_ABS12)
f5385ebf 7668 h->needs_plt = 1;
4f199be3
DJ
7669
7670 /* If we create a PLT entry, this relocation will reference
7671 it, even if it's an ABS32 relocation. */
7672 h->plt.refcount += 1;
b7693d02 7673
bd97cb95
DJ
7674 /* It's too early to use htab->use_blx here, so we have to
7675 record possible blx references separately from
7676 relocs that definitely need a thumb stub. */
7677
c19d1205 7678 if (r_type == R_ARM_THM_CALL)
bd97cb95
DJ
7679 eh->plt_maybe_thumb_refcount += 1;
7680
7681 if (r_type == R_ARM_THM_JUMP24
7682 || r_type == R_ARM_THM_JUMP19)
b7693d02 7683 eh->plt_thumb_refcount += 1;
5e681ec4
PB
7684 }
7685
67687978
PB
7686 /* If we are creating a shared library or relocatable executable,
7687 and this is a reloc against a global symbol, or a non PC
7688 relative reloc against a local symbol, then we need to copy
7689 the reloc into the shared library. However, if we are linking
7690 with -Bsymbolic, we do not need to copy a reloc against a
252b5132
RH
7691 global symbol which is defined in an object we are
7692 including in the link (i.e., DEF_REGULAR is set). At
7693 this point we have not seen all the input files, so it is
7694 possible that DEF_REGULAR is not set now but will be set
7695 later (it is never cleared). We account for that
7696 possibility below by storing information in the
5e681ec4 7697 relocs_copied field of the hash table entry. */
67687978 7698 if ((info->shared || htab->root.is_relocatable_executable)
5e681ec4 7699 && (sec->flags & SEC_ALLOC) != 0
bb224fc3 7700 && ((r_type == R_ARM_ABS32 || r_type == R_ARM_ABS32_NOI)
71a976dd
DJ
7701 || (h != NULL && ! h->needs_plt
7702 && (! info->symbolic || ! h->def_regular))))
252b5132 7703 {
5e681ec4
PB
7704 struct elf32_arm_relocs_copied *p, **head;
7705
252b5132
RH
7706 /* When creating a shared object, we must copy these
7707 reloc types into the output file. We create a reloc
7708 section in dynobj and make room for this reloc. */
7709 if (sreloc == NULL)
7710 {
7711 const char * name;
7712
7713 name = (bfd_elf_string_from_elf_section
7714 (abfd,
7715 elf_elfheader (abfd)->e_shstrndx,
7716 elf_section_data (sec)->rel_hdr.sh_name));
7717 if (name == NULL)
b34976b6 7718 return FALSE;
252b5132 7719
00a97672 7720 BFD_ASSERT (reloc_section_p (htab, name, sec));
252b5132
RH
7721
7722 sreloc = bfd_get_section_by_name (dynobj, name);
7723 if (sreloc == NULL)
7724 {
7725 flagword flags;
7726
252b5132
RH
7727 flags = (SEC_HAS_CONTENTS | SEC_READONLY
7728 | SEC_IN_MEMORY | SEC_LINKER_CREATED);
e5a52504
MM
7729 if ((sec->flags & SEC_ALLOC) != 0
7730 /* BPABI objects never have dynamic
7731 relocations mapped. */
7732 && !htab->symbian_p)
252b5132 7733 flags |= SEC_ALLOC | SEC_LOAD;
3496cb2a
L
7734 sreloc = bfd_make_section_with_flags (dynobj,
7735 name,
7736 flags);
252b5132 7737 if (sreloc == NULL
252b5132 7738 || ! bfd_set_section_alignment (dynobj, sreloc, 2))
b34976b6 7739 return FALSE;
252b5132 7740 }
5e681ec4
PB
7741
7742 elf_section_data (sec)->sreloc = sreloc;
252b5132
RH
7743 }
7744
5e681ec4
PB
7745 /* If this is a global symbol, we count the number of
7746 relocations we need for this symbol. */
7747 if (h != NULL)
252b5132 7748 {
5e681ec4
PB
7749 head = &((struct elf32_arm_link_hash_entry *) h)->relocs_copied;
7750 }
7751 else
7752 {
7753 /* Track dynamic relocs needed for local syms too.
7754 We really need local syms available to do this
7755 easily. Oh well. */
57e8b36a 7756
5e681ec4 7757 asection *s;
6edfbbad
DJ
7758 void *vpp;
7759
5e681ec4
PB
7760 s = bfd_section_from_r_symndx (abfd, &htab->sym_sec,
7761 sec, r_symndx);
7762 if (s == NULL)
7763 return FALSE;
57e8b36a 7764
6edfbbad
DJ
7765 vpp = &elf_section_data (s)->local_dynrel;
7766 head = (struct elf32_arm_relocs_copied **) vpp;
5e681ec4 7767 }
57e8b36a 7768
5e681ec4
PB
7769 p = *head;
7770 if (p == NULL || p->section != sec)
7771 {
7772 bfd_size_type amt = sizeof *p;
57e8b36a 7773
5e681ec4 7774 p = bfd_alloc (htab->root.dynobj, amt);
252b5132 7775 if (p == NULL)
5e681ec4
PB
7776 return FALSE;
7777 p->next = *head;
7778 *head = p;
7779 p->section = sec;
7780 p->count = 0;
ba93b8ac 7781 p->pc_count = 0;
252b5132 7782 }
57e8b36a 7783
bb224fc3 7784 if (r_type == R_ARM_REL32 || r_type == R_ARM_REL32_NOI)
ba93b8ac 7785 p->pc_count += 1;
71a976dd 7786 p->count += 1;
252b5132
RH
7787 }
7788 break;
7789
7790 /* This relocation describes the C++ object vtable hierarchy.
7791 Reconstruct it for later use during GC. */
7792 case R_ARM_GNU_VTINHERIT:
c152c796 7793 if (!bfd_elf_gc_record_vtinherit (abfd, sec, h, rel->r_offset))
b34976b6 7794 return FALSE;
252b5132 7795 break;
9a5aca8c 7796
252b5132
RH
7797 /* This relocation describes which C++ vtable entries are actually
7798 used. Record for later use during GC. */
7799 case R_ARM_GNU_VTENTRY:
d17e0c6e
JB
7800 BFD_ASSERT (h != NULL);
7801 if (h != NULL
7802 && !bfd_elf_gc_record_vtentry (abfd, sec, h, rel->r_offset))
b34976b6 7803 return FALSE;
252b5132
RH
7804 break;
7805 }
7806 }
f21f3fe0 7807
b34976b6 7808 return TRUE;
252b5132
RH
7809}
7810
6a5bb875
PB
7811/* Unwinding tables are not referenced directly. This pass marks them as
7812 required if the corresponding code section is marked. */
7813
7814static bfd_boolean
7815elf32_arm_gc_mark_extra_sections(struct bfd_link_info *info,
7816 elf_gc_mark_hook_fn gc_mark_hook)
7817{
7818 bfd *sub;
7819 Elf_Internal_Shdr **elf_shdrp;
7820 bfd_boolean again;
7821
7822 /* Marking EH data may cause additional code sections to be marked,
7823 requiring multiple passes. */
7824 again = TRUE;
7825 while (again)
7826 {
7827 again = FALSE;
7828 for (sub = info->input_bfds; sub != NULL; sub = sub->link_next)
7829 {
7830 asection *o;
7831
7832 if (bfd_get_flavour (sub) != bfd_target_elf_flavour)
7833 continue;
7834
7835 elf_shdrp = elf_elfsections (sub);
7836 for (o = sub->sections; o != NULL; o = o->next)
7837 {
7838 Elf_Internal_Shdr *hdr;
7839 hdr = &elf_section_data (o)->this_hdr;
7840 if (hdr->sh_type == SHT_ARM_EXIDX && hdr->sh_link
7841 && !o->gc_mark
7842 && elf_shdrp[hdr->sh_link]->bfd_section->gc_mark)
7843 {
7844 again = TRUE;
7845 if (!_bfd_elf_gc_mark (info, o, gc_mark_hook))
7846 return FALSE;
7847 }
7848 }
7849 }
7850 }
7851
7852 return TRUE;
7853}
7854
3c9458e9
NC
7855/* Treat mapping symbols as special target symbols. */
7856
7857static bfd_boolean
7858elf32_arm_is_target_special_symbol (bfd * abfd ATTRIBUTE_UNUSED, asymbol * sym)
7859{
b0796911
PB
7860 return bfd_is_arm_special_symbol_name (sym->name,
7861 BFD_ARM_SPECIAL_SYM_TYPE_ANY);
3c9458e9
NC
7862}
7863
0367ecfb
NC
7864/* This is a copy of elf_find_function() from elf.c except that
7865 ARM mapping symbols are ignored when looking for function names
7866 and STT_ARM_TFUNC is considered to a function type. */
252b5132 7867
0367ecfb
NC
7868static bfd_boolean
7869arm_elf_find_function (bfd * abfd ATTRIBUTE_UNUSED,
7870 asection * section,
7871 asymbol ** symbols,
7872 bfd_vma offset,
7873 const char ** filename_ptr,
7874 const char ** functionname_ptr)
7875{
7876 const char * filename = NULL;
7877 asymbol * func = NULL;
7878 bfd_vma low_func = 0;
7879 asymbol ** p;
252b5132
RH
7880
7881 for (p = symbols; *p != NULL; p++)
7882 {
7883 elf_symbol_type *q;
7884
7885 q = (elf_symbol_type *) *p;
7886
252b5132
RH
7887 switch (ELF_ST_TYPE (q->internal_elf_sym.st_info))
7888 {
7889 default:
7890 break;
7891 case STT_FILE:
7892 filename = bfd_asymbol_name (&q->symbol);
7893 break;
252b5132
RH
7894 case STT_FUNC:
7895 case STT_ARM_TFUNC:
9d2da7ca 7896 case STT_NOTYPE:
b0796911 7897 /* Skip mapping symbols. */
0367ecfb 7898 if ((q->symbol.flags & BSF_LOCAL)
b0796911
PB
7899 && bfd_is_arm_special_symbol_name (q->symbol.name,
7900 BFD_ARM_SPECIAL_SYM_TYPE_ANY))
0367ecfb
NC
7901 continue;
7902 /* Fall through. */
6b40fcba 7903 if (bfd_get_section (&q->symbol) == section
252b5132
RH
7904 && q->symbol.value >= low_func
7905 && q->symbol.value <= offset)
7906 {
7907 func = (asymbol *) q;
7908 low_func = q->symbol.value;
7909 }
7910 break;
7911 }
7912 }
7913
7914 if (func == NULL)
b34976b6 7915 return FALSE;
252b5132 7916
0367ecfb
NC
7917 if (filename_ptr)
7918 *filename_ptr = filename;
7919 if (functionname_ptr)
7920 *functionname_ptr = bfd_asymbol_name (func);
7921
7922 return TRUE;
7923}
7924
7925
7926/* Find the nearest line to a particular section and offset, for error
7927 reporting. This code is a duplicate of the code in elf.c, except
7928 that it uses arm_elf_find_function. */
7929
7930static bfd_boolean
7931elf32_arm_find_nearest_line (bfd * abfd,
7932 asection * section,
7933 asymbol ** symbols,
7934 bfd_vma offset,
7935 const char ** filename_ptr,
7936 const char ** functionname_ptr,
7937 unsigned int * line_ptr)
7938{
7939 bfd_boolean found = FALSE;
7940
7941 /* We skip _bfd_dwarf1_find_nearest_line since no known ARM toolchain uses it. */
7942
7943 if (_bfd_dwarf2_find_nearest_line (abfd, section, symbols, offset,
7944 filename_ptr, functionname_ptr,
7945 line_ptr, 0,
7946 & elf_tdata (abfd)->dwarf2_find_line_info))
7947 {
7948 if (!*functionname_ptr)
7949 arm_elf_find_function (abfd, section, symbols, offset,
7950 *filename_ptr ? NULL : filename_ptr,
7951 functionname_ptr);
f21f3fe0 7952
0367ecfb
NC
7953 return TRUE;
7954 }
7955
7956 if (! _bfd_stab_section_find_nearest_line (abfd, symbols, section, offset,
7957 & found, filename_ptr,
7958 functionname_ptr, line_ptr,
7959 & elf_tdata (abfd)->line_info))
7960 return FALSE;
7961
7962 if (found && (*functionname_ptr || *line_ptr))
7963 return TRUE;
7964
7965 if (symbols == NULL)
7966 return FALSE;
7967
7968 if (! arm_elf_find_function (abfd, section, symbols, offset,
7969 filename_ptr, functionname_ptr))
7970 return FALSE;
7971
7972 *line_ptr = 0;
b34976b6 7973 return TRUE;
252b5132
RH
7974}
7975
4ab527b0
FF
7976static bfd_boolean
7977elf32_arm_find_inliner_info (bfd * abfd,
7978 const char ** filename_ptr,
7979 const char ** functionname_ptr,
7980 unsigned int * line_ptr)
7981{
7982 bfd_boolean found;
7983 found = _bfd_dwarf2_find_inliner_info (abfd, filename_ptr,
7984 functionname_ptr, line_ptr,
7985 & elf_tdata (abfd)->dwarf2_find_line_info);
7986 return found;
7987}
7988
252b5132
RH
7989/* Adjust a symbol defined by a dynamic object and referenced by a
7990 regular object. The current definition is in some section of the
7991 dynamic object, but we're not including those sections. We have to
7992 change the definition to something the rest of the link can
7993 understand. */
7994
b34976b6 7995static bfd_boolean
57e8b36a
NC
7996elf32_arm_adjust_dynamic_symbol (struct bfd_link_info * info,
7997 struct elf_link_hash_entry * h)
252b5132
RH
7998{
7999 bfd * dynobj;
8000 asection * s;
b7693d02 8001 struct elf32_arm_link_hash_entry * eh;
67687978 8002 struct elf32_arm_link_hash_table *globals;
252b5132 8003
67687978 8004 globals = elf32_arm_hash_table (info);
252b5132
RH
8005 dynobj = elf_hash_table (info)->dynobj;
8006
8007 /* Make sure we know what is going on here. */
8008 BFD_ASSERT (dynobj != NULL
f5385ebf 8009 && (h->needs_plt
f6e332e6 8010 || h->u.weakdef != NULL
f5385ebf
AM
8011 || (h->def_dynamic
8012 && h->ref_regular
8013 && !h->def_regular)));
252b5132 8014
b7693d02
DJ
8015 eh = (struct elf32_arm_link_hash_entry *) h;
8016
252b5132
RH
8017 /* If this is a function, put it in the procedure linkage table. We
8018 will fill in the contents of the procedure linkage table later,
8019 when we know the address of the .got section. */
b7693d02 8020 if (h->type == STT_FUNC || h->type == STT_ARM_TFUNC
f5385ebf 8021 || h->needs_plt)
252b5132 8022 {
5e681ec4
PB
8023 if (h->plt.refcount <= 0
8024 || SYMBOL_CALLS_LOCAL (info, h)
8025 || (ELF_ST_VISIBILITY (h->other) != STV_DEFAULT
8026 && h->root.type == bfd_link_hash_undefweak))
252b5132
RH
8027 {
8028 /* This case can occur if we saw a PLT32 reloc in an input
5e681ec4
PB
8029 file, but the symbol was never referred to by a dynamic
8030 object, or if all references were garbage collected. In
8031 such a case, we don't actually need to build a procedure
8032 linkage table, and we can just do a PC24 reloc instead. */
8033 h->plt.offset = (bfd_vma) -1;
b7693d02 8034 eh->plt_thumb_refcount = 0;
bd97cb95 8035 eh->plt_maybe_thumb_refcount = 0;
f5385ebf 8036 h->needs_plt = 0;
252b5132
RH
8037 }
8038
b34976b6 8039 return TRUE;
252b5132 8040 }
5e681ec4 8041 else
b7693d02
DJ
8042 {
8043 /* It's possible that we incorrectly decided a .plt reloc was
8044 needed for an R_ARM_PC24 or similar reloc to a non-function sym
8045 in check_relocs. We can't decide accurately between function
8046 and non-function syms in check-relocs; Objects loaded later in
8047 the link may change h->type. So fix it now. */
8048 h->plt.offset = (bfd_vma) -1;
8049 eh->plt_thumb_refcount = 0;
bd97cb95 8050 eh->plt_maybe_thumb_refcount = 0;
b7693d02 8051 }
252b5132
RH
8052
8053 /* If this is a weak symbol, and there is a real definition, the
8054 processor independent code will have arranged for us to see the
8055 real definition first, and we can just use the same value. */
f6e332e6 8056 if (h->u.weakdef != NULL)
252b5132 8057 {
f6e332e6
AM
8058 BFD_ASSERT (h->u.weakdef->root.type == bfd_link_hash_defined
8059 || h->u.weakdef->root.type == bfd_link_hash_defweak);
8060 h->root.u.def.section = h->u.weakdef->root.u.def.section;
8061 h->root.u.def.value = h->u.weakdef->root.u.def.value;
b34976b6 8062 return TRUE;
252b5132
RH
8063 }
8064
ba93b8ac
DJ
8065 /* If there are no non-GOT references, we do not need a copy
8066 relocation. */
8067 if (!h->non_got_ref)
8068 return TRUE;
8069
252b5132
RH
8070 /* This is a reference to a symbol defined by a dynamic object which
8071 is not a function. */
8072
8073 /* If we are creating a shared library, we must presume that the
8074 only references to the symbol are via the global offset table.
8075 For such cases we need not do anything here; the relocations will
67687978
PB
8076 be handled correctly by relocate_section. Relocatable executables
8077 can reference data in shared objects directly, so we don't need to
8078 do anything here. */
8079 if (info->shared || globals->root.is_relocatable_executable)
b34976b6 8080 return TRUE;
252b5132 8081
909272ee
AM
8082 if (h->size == 0)
8083 {
8084 (*_bfd_error_handler) (_("dynamic variable `%s' is zero size"),
8085 h->root.root.string);
8086 return TRUE;
8087 }
8088
252b5132
RH
8089 /* We must allocate the symbol in our .dynbss section, which will
8090 become part of the .bss section of the executable. There will be
8091 an entry for this symbol in the .dynsym section. The dynamic
8092 object will contain position independent code, so all references
8093 from the dynamic object to this symbol will go through the global
8094 offset table. The dynamic linker will use the .dynsym entry to
8095 determine the address it must put in the global offset table, so
8096 both the dynamic object and the regular object will refer to the
8097 same memory location for the variable. */
252b5132
RH
8098 s = bfd_get_section_by_name (dynobj, ".dynbss");
8099 BFD_ASSERT (s != NULL);
8100
8101 /* We must generate a R_ARM_COPY reloc to tell the dynamic linker to
8102 copy the initial value out of the dynamic object and into the
8103 runtime process image. We need to remember the offset into the
00a97672 8104 .rel(a).bss section we are going to use. */
252b5132
RH
8105 if ((h->root.u.def.section->flags & SEC_ALLOC) != 0)
8106 {
8107 asection *srel;
8108
00a97672 8109 srel = bfd_get_section_by_name (dynobj, RELOC_SECTION (globals, ".bss"));
252b5132 8110 BFD_ASSERT (srel != NULL);
00a97672 8111 srel->size += RELOC_SIZE (globals);
f5385ebf 8112 h->needs_copy = 1;
252b5132
RH
8113 }
8114
027297b7 8115 return _bfd_elf_adjust_dynamic_copy (h, s);
252b5132
RH
8116}
8117
5e681ec4
PB
8118/* Allocate space in .plt, .got and associated reloc sections for
8119 dynamic relocs. */
8120
8121static bfd_boolean
57e8b36a 8122allocate_dynrelocs (struct elf_link_hash_entry *h, void * inf)
5e681ec4
PB
8123{
8124 struct bfd_link_info *info;
8125 struct elf32_arm_link_hash_table *htab;
8126 struct elf32_arm_link_hash_entry *eh;
8127 struct elf32_arm_relocs_copied *p;
bd97cb95 8128 bfd_signed_vma thumb_refs;
5e681ec4 8129
b7693d02
DJ
8130 eh = (struct elf32_arm_link_hash_entry *) h;
8131
5e681ec4
PB
8132 if (h->root.type == bfd_link_hash_indirect)
8133 return TRUE;
8134
8135 if (h->root.type == bfd_link_hash_warning)
8136 /* When warning symbols are created, they **replace** the "real"
8137 entry in the hash table, thus we never get to see the real
8138 symbol in a hash traversal. So look at it now. */
8139 h = (struct elf_link_hash_entry *) h->root.u.i.link;
8140
8141 info = (struct bfd_link_info *) inf;
8142 htab = elf32_arm_hash_table (info);
8143
8144 if (htab->root.dynamic_sections_created
8145 && h->plt.refcount > 0)
8146 {
8147 /* Make sure this symbol is output as a dynamic symbol.
8148 Undefined weak syms won't yet be marked as dynamic. */
8149 if (h->dynindx == -1
f5385ebf 8150 && !h->forced_local)
5e681ec4 8151 {
c152c796 8152 if (! bfd_elf_link_record_dynamic_symbol (info, h))
5e681ec4
PB
8153 return FALSE;
8154 }
8155
8156 if (info->shared
7359ea65 8157 || WILL_CALL_FINISH_DYNAMIC_SYMBOL (1, 0, h))
5e681ec4
PB
8158 {
8159 asection *s = htab->splt;
8160
8161 /* If this is the first .plt entry, make room for the special
8162 first entry. */
eea6121a 8163 if (s->size == 0)
e5a52504 8164 s->size += htab->plt_header_size;
5e681ec4 8165
eea6121a 8166 h->plt.offset = s->size;
5e681ec4 8167
b7693d02
DJ
8168 /* If we will insert a Thumb trampoline before this PLT, leave room
8169 for it. */
bd97cb95
DJ
8170 thumb_refs = eh->plt_thumb_refcount;
8171 if (!htab->use_blx)
8172 thumb_refs += eh->plt_maybe_thumb_refcount;
8173
8174 if (thumb_refs > 0)
b7693d02
DJ
8175 {
8176 h->plt.offset += PLT_THUMB_STUB_SIZE;
8177 s->size += PLT_THUMB_STUB_SIZE;
8178 }
8179
5e681ec4
PB
8180 /* If this symbol is not defined in a regular file, and we are
8181 not generating a shared library, then set the symbol to this
8182 location in the .plt. This is required to make function
8183 pointers compare as equal between the normal executable and
8184 the shared library. */
8185 if (! info->shared
f5385ebf 8186 && !h->def_regular)
5e681ec4
PB
8187 {
8188 h->root.u.def.section = s;
8189 h->root.u.def.value = h->plt.offset;
b7693d02
DJ
8190
8191 /* Make sure the function is not marked as Thumb, in case
8192 it is the target of an ABS32 relocation, which will
8193 point to the PLT entry. */
8194 if (ELF_ST_TYPE (h->type) == STT_ARM_TFUNC)
8195 h->type = ELF_ST_INFO (ELF_ST_BIND (h->type), STT_FUNC);
5e681ec4
PB
8196 }
8197
8198 /* Make room for this entry. */
e5a52504 8199 s->size += htab->plt_entry_size;
5e681ec4 8200
e5a52504 8201 if (!htab->symbian_p)
b7693d02
DJ
8202 {
8203 /* We also need to make an entry in the .got.plt section, which
8204 will be placed in the .got section by the linker script. */
8205 eh->plt_got_offset = htab->sgotplt->size;
8206 htab->sgotplt->size += 4;
8207 }
5e681ec4 8208
00a97672
RS
8209 /* We also need to make an entry in the .rel(a).plt section. */
8210 htab->srelplt->size += RELOC_SIZE (htab);
8211
8212 /* VxWorks executables have a second set of relocations for
8213 each PLT entry. They go in a separate relocation section,
8214 which is processed by the kernel loader. */
8215 if (htab->vxworks_p && !info->shared)
8216 {
8217 /* There is a relocation for the initial PLT entry:
8218 an R_ARM_32 relocation for _GLOBAL_OFFSET_TABLE_. */
8219 if (h->plt.offset == htab->plt_header_size)
8220 htab->srelplt2->size += RELOC_SIZE (htab);
8221
8222 /* There are two extra relocations for each subsequent
8223 PLT entry: an R_ARM_32 relocation for the GOT entry,
8224 and an R_ARM_32 relocation for the PLT entry. */
8225 htab->srelplt2->size += RELOC_SIZE (htab) * 2;
8226 }
5e681ec4
PB
8227 }
8228 else
8229 {
8230 h->plt.offset = (bfd_vma) -1;
f5385ebf 8231 h->needs_plt = 0;
5e681ec4
PB
8232 }
8233 }
8234 else
8235 {
8236 h->plt.offset = (bfd_vma) -1;
f5385ebf 8237 h->needs_plt = 0;
5e681ec4
PB
8238 }
8239
8240 if (h->got.refcount > 0)
8241 {
8242 asection *s;
8243 bfd_boolean dyn;
ba93b8ac
DJ
8244 int tls_type = elf32_arm_hash_entry (h)->tls_type;
8245 int indx;
5e681ec4
PB
8246
8247 /* Make sure this symbol is output as a dynamic symbol.
8248 Undefined weak syms won't yet be marked as dynamic. */
8249 if (h->dynindx == -1
f5385ebf 8250 && !h->forced_local)
5e681ec4 8251 {
c152c796 8252 if (! bfd_elf_link_record_dynamic_symbol (info, h))
5e681ec4
PB
8253 return FALSE;
8254 }
8255
e5a52504
MM
8256 if (!htab->symbian_p)
8257 {
8258 s = htab->sgot;
8259 h->got.offset = s->size;
ba93b8ac
DJ
8260
8261 if (tls_type == GOT_UNKNOWN)
8262 abort ();
8263
8264 if (tls_type == GOT_NORMAL)
8265 /* Non-TLS symbols need one GOT slot. */
8266 s->size += 4;
8267 else
8268 {
8269 if (tls_type & GOT_TLS_GD)
8270 /* R_ARM_TLS_GD32 needs 2 consecutive GOT slots. */
8271 s->size += 8;
8272 if (tls_type & GOT_TLS_IE)
8273 /* R_ARM_TLS_IE32 needs one GOT slot. */
8274 s->size += 4;
8275 }
8276
e5a52504 8277 dyn = htab->root.dynamic_sections_created;
ba93b8ac
DJ
8278
8279 indx = 0;
8280 if (WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn, info->shared, h)
8281 && (!info->shared
8282 || !SYMBOL_REFERENCES_LOCAL (info, h)))
8283 indx = h->dynindx;
8284
8285 if (tls_type != GOT_NORMAL
8286 && (info->shared || indx != 0)
8287 && (ELF_ST_VISIBILITY (h->other) == STV_DEFAULT
8288 || h->root.type != bfd_link_hash_undefweak))
8289 {
8290 if (tls_type & GOT_TLS_IE)
00a97672 8291 htab->srelgot->size += RELOC_SIZE (htab);
ba93b8ac
DJ
8292
8293 if (tls_type & GOT_TLS_GD)
00a97672 8294 htab->srelgot->size += RELOC_SIZE (htab);
ba93b8ac
DJ
8295
8296 if ((tls_type & GOT_TLS_GD) && indx != 0)
00a97672 8297 htab->srelgot->size += RELOC_SIZE (htab);
ba93b8ac
DJ
8298 }
8299 else if ((ELF_ST_VISIBILITY (h->other) == STV_DEFAULT
8300 || h->root.type != bfd_link_hash_undefweak)
8301 && (info->shared
8302 || WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn, 0, h)))
00a97672 8303 htab->srelgot->size += RELOC_SIZE (htab);
e5a52504 8304 }
5e681ec4
PB
8305 }
8306 else
8307 h->got.offset = (bfd_vma) -1;
8308
a4fd1a8e
PB
8309 /* Allocate stubs for exported Thumb functions on v4t. */
8310 if (!htab->use_blx && h->dynindx != -1
0eaedd0e 8311 && h->def_regular
a4fd1a8e
PB
8312 && ELF_ST_TYPE (h->type) == STT_ARM_TFUNC
8313 && ELF_ST_VISIBILITY (h->other) == STV_DEFAULT)
8314 {
8315 struct elf_link_hash_entry * th;
8316 struct bfd_link_hash_entry * bh;
8317 struct elf_link_hash_entry * myh;
8318 char name[1024];
8319 asection *s;
8320 bh = NULL;
8321 /* Create a new symbol to regist the real location of the function. */
8322 s = h->root.u.def.section;
8323 sprintf(name, "__real_%s", h->root.root.string);
8324 _bfd_generic_link_add_one_symbol (info, s->owner,
8325 name, BSF_GLOBAL, s,
8326 h->root.u.def.value,
8327 NULL, TRUE, FALSE, &bh);
8328
8329 myh = (struct elf_link_hash_entry *) bh;
8330 myh->type = ELF_ST_INFO (STB_LOCAL, STT_ARM_TFUNC);
8331 myh->forced_local = 1;
8332 eh->export_glue = myh;
8333 th = record_arm_to_thumb_glue (info, h);
8334 /* Point the symbol at the stub. */
8335 h->type = ELF_ST_INFO (ELF_ST_BIND (h->type), STT_FUNC);
8336 h->root.u.def.section = th->root.u.def.section;
8337 h->root.u.def.value = th->root.u.def.value & ~1;
8338 }
8339
5e681ec4
PB
8340 if (eh->relocs_copied == NULL)
8341 return TRUE;
8342
8343 /* In the shared -Bsymbolic case, discard space allocated for
8344 dynamic pc-relative relocs against symbols which turn out to be
8345 defined in regular objects. For the normal shared case, discard
8346 space for pc-relative relocs that have become local due to symbol
8347 visibility changes. */
8348
67687978 8349 if (info->shared || htab->root.is_relocatable_executable)
5e681ec4 8350 {
7bdca076 8351 /* The only relocs that use pc_count are R_ARM_REL32 and
bb224fc3
MS
8352 R_ARM_REL32_NOI, which will appear on something like
8353 ".long foo - .". We want calls to protected symbols to resolve
8354 directly to the function rather than going via the plt. If people
8355 want function pointer comparisons to work as expected then they
8356 should avoid writing assembly like ".long foo - .". */
ba93b8ac
DJ
8357 if (SYMBOL_CALLS_LOCAL (info, h))
8358 {
8359 struct elf32_arm_relocs_copied **pp;
8360
8361 for (pp = &eh->relocs_copied; (p = *pp) != NULL; )
8362 {
8363 p->count -= p->pc_count;
8364 p->pc_count = 0;
8365 if (p->count == 0)
8366 *pp = p->next;
8367 else
8368 pp = &p->next;
8369 }
8370 }
8371
8372 /* Also discard relocs on undefined weak syms with non-default
7359ea65 8373 visibility. */
22d606e9 8374 if (eh->relocs_copied != NULL
5e681ec4 8375 && h->root.type == bfd_link_hash_undefweak)
22d606e9
AM
8376 {
8377 if (ELF_ST_VISIBILITY (h->other) != STV_DEFAULT)
8378 eh->relocs_copied = NULL;
8379
8380 /* Make sure undefined weak symbols are output as a dynamic
8381 symbol in PIEs. */
8382 else if (h->dynindx == -1
8383 && !h->forced_local)
8384 {
8385 if (! bfd_elf_link_record_dynamic_symbol (info, h))
8386 return FALSE;
8387 }
8388 }
8389
67687978
PB
8390 else if (htab->root.is_relocatable_executable && h->dynindx == -1
8391 && h->root.type == bfd_link_hash_new)
8392 {
8393 /* Output absolute symbols so that we can create relocations
8394 against them. For normal symbols we output a relocation
8395 against the section that contains them. */
8396 if (! bfd_elf_link_record_dynamic_symbol (info, h))
8397 return FALSE;
8398 }
8399
5e681ec4
PB
8400 }
8401 else
8402 {
8403 /* For the non-shared case, discard space for relocs against
8404 symbols which turn out to need copy relocs or are not
8405 dynamic. */
8406
f5385ebf
AM
8407 if (!h->non_got_ref
8408 && ((h->def_dynamic
8409 && !h->def_regular)
5e681ec4
PB
8410 || (htab->root.dynamic_sections_created
8411 && (h->root.type == bfd_link_hash_undefweak
8412 || h->root.type == bfd_link_hash_undefined))))
8413 {
8414 /* Make sure this symbol is output as a dynamic symbol.
8415 Undefined weak syms won't yet be marked as dynamic. */
8416 if (h->dynindx == -1
f5385ebf 8417 && !h->forced_local)
5e681ec4 8418 {
c152c796 8419 if (! bfd_elf_link_record_dynamic_symbol (info, h))
5e681ec4
PB
8420 return FALSE;
8421 }
8422
8423 /* If that succeeded, we know we'll be keeping all the
8424 relocs. */
8425 if (h->dynindx != -1)
8426 goto keep;
8427 }
8428
8429 eh->relocs_copied = NULL;
8430
8431 keep: ;
8432 }
8433
8434 /* Finally, allocate space. */
8435 for (p = eh->relocs_copied; p != NULL; p = p->next)
8436 {
8437 asection *sreloc = elf_section_data (p->section)->sreloc;
00a97672 8438 sreloc->size += p->count * RELOC_SIZE (htab);
5e681ec4
PB
8439 }
8440
8441 return TRUE;
8442}
8443
08d1f311
DJ
8444/* Find any dynamic relocs that apply to read-only sections. */
8445
8446static bfd_boolean
8447elf32_arm_readonly_dynrelocs (struct elf_link_hash_entry *h, PTR inf)
8448{
8449 struct elf32_arm_link_hash_entry *eh;
8450 struct elf32_arm_relocs_copied *p;
8451
8452 if (h->root.type == bfd_link_hash_warning)
8453 h = (struct elf_link_hash_entry *) h->root.u.i.link;
8454
8455 eh = (struct elf32_arm_link_hash_entry *) h;
8456 for (p = eh->relocs_copied; p != NULL; p = p->next)
8457 {
8458 asection *s = p->section;
8459
8460 if (s != NULL && (s->flags & SEC_READONLY) != 0)
8461 {
8462 struct bfd_link_info *info = (struct bfd_link_info *) inf;
8463
8464 info->flags |= DF_TEXTREL;
8465
8466 /* Not an error, just cut short the traversal. */
8467 return FALSE;
8468 }
8469 }
8470 return TRUE;
8471}
8472
d504ffc8
DJ
8473void
8474bfd_elf32_arm_set_byteswap_code (struct bfd_link_info *info,
8475 int byteswap_code)
8476{
8477 struct elf32_arm_link_hash_table *globals;
8478
8479 globals = elf32_arm_hash_table (info);
8480 globals->byteswap_code = byteswap_code;
8481}
8482
252b5132
RH
8483/* Set the sizes of the dynamic sections. */
8484
b34976b6 8485static bfd_boolean
57e8b36a
NC
8486elf32_arm_size_dynamic_sections (bfd * output_bfd ATTRIBUTE_UNUSED,
8487 struct bfd_link_info * info)
252b5132
RH
8488{
8489 bfd * dynobj;
8490 asection * s;
b34976b6
AM
8491 bfd_boolean plt;
8492 bfd_boolean relocs;
5e681ec4
PB
8493 bfd *ibfd;
8494 struct elf32_arm_link_hash_table *htab;
252b5132 8495
5e681ec4 8496 htab = elf32_arm_hash_table (info);
252b5132
RH
8497 dynobj = elf_hash_table (info)->dynobj;
8498 BFD_ASSERT (dynobj != NULL);
39b41c9c 8499 check_use_blx (htab);
252b5132
RH
8500
8501 if (elf_hash_table (info)->dynamic_sections_created)
8502 {
8503 /* Set the contents of the .interp section to the interpreter. */
893c4fe2 8504 if (info->executable)
252b5132
RH
8505 {
8506 s = bfd_get_section_by_name (dynobj, ".interp");
8507 BFD_ASSERT (s != NULL);
eea6121a 8508 s->size = sizeof ELF_DYNAMIC_INTERPRETER;
252b5132
RH
8509 s->contents = (unsigned char *) ELF_DYNAMIC_INTERPRETER;
8510 }
8511 }
5e681ec4
PB
8512
8513 /* Set up .got offsets for local syms, and space for local dynamic
8514 relocs. */
8515 for (ibfd = info->input_bfds; ibfd != NULL; ibfd = ibfd->link_next)
252b5132 8516 {
5e681ec4
PB
8517 bfd_signed_vma *local_got;
8518 bfd_signed_vma *end_local_got;
8519 char *local_tls_type;
8520 bfd_size_type locsymcount;
8521 Elf_Internal_Shdr *symtab_hdr;
8522 asection *srel;
8523
8524 if (bfd_get_flavour (ibfd) != bfd_target_elf_flavour)
8525 continue;
8526
8527 for (s = ibfd->sections; s != NULL; s = s->next)
8528 {
8529 struct elf32_arm_relocs_copied *p;
8530
6edfbbad 8531 for (p = elf_section_data (s)->local_dynrel; p != NULL; p = p->next)
5e681ec4
PB
8532 {
8533 if (!bfd_is_abs_section (p->section)
8534 && bfd_is_abs_section (p->section->output_section))
8535 {
8536 /* Input section has been discarded, either because
8537 it is a copy of a linkonce section or due to
8538 linker script /DISCARD/, so we'll be discarding
8539 the relocs too. */
8540 }
8541 else if (p->count != 0)
8542 {
8543 srel = elf_section_data (p->section)->sreloc;
00a97672 8544 srel->size += p->count * RELOC_SIZE (htab);
5e681ec4
PB
8545 if ((p->section->output_section->flags & SEC_READONLY) != 0)
8546 info->flags |= DF_TEXTREL;
8547 }
8548 }
8549 }
8550
8551 local_got = elf_local_got_refcounts (ibfd);
8552 if (!local_got)
8553 continue;
8554
8555 symtab_hdr = &elf_tdata (ibfd)->symtab_hdr;
8556 locsymcount = symtab_hdr->sh_info;
8557 end_local_got = local_got + locsymcount;
ba93b8ac 8558 local_tls_type = elf32_arm_local_got_tls_type (ibfd);
5e681ec4
PB
8559 s = htab->sgot;
8560 srel = htab->srelgot;
8561 for (; local_got < end_local_got; ++local_got, ++local_tls_type)
8562 {
8563 if (*local_got > 0)
8564 {
eea6121a 8565 *local_got = s->size;
ba93b8ac
DJ
8566 if (*local_tls_type & GOT_TLS_GD)
8567 /* TLS_GD relocs need an 8-byte structure in the GOT. */
8568 s->size += 8;
8569 if (*local_tls_type & GOT_TLS_IE)
8570 s->size += 4;
8571 if (*local_tls_type == GOT_NORMAL)
8572 s->size += 4;
8573
8574 if (info->shared || *local_tls_type == GOT_TLS_GD)
00a97672 8575 srel->size += RELOC_SIZE (htab);
5e681ec4
PB
8576 }
8577 else
8578 *local_got = (bfd_vma) -1;
8579 }
252b5132
RH
8580 }
8581
ba93b8ac
DJ
8582 if (htab->tls_ldm_got.refcount > 0)
8583 {
8584 /* Allocate two GOT entries and one dynamic relocation (if necessary)
8585 for R_ARM_TLS_LDM32 relocations. */
8586 htab->tls_ldm_got.offset = htab->sgot->size;
8587 htab->sgot->size += 8;
8588 if (info->shared)
00a97672 8589 htab->srelgot->size += RELOC_SIZE (htab);
ba93b8ac
DJ
8590 }
8591 else
8592 htab->tls_ldm_got.offset = -1;
8593
5e681ec4
PB
8594 /* Allocate global sym .plt and .got entries, and space for global
8595 sym dynamic relocs. */
57e8b36a 8596 elf_link_hash_traverse (& htab->root, allocate_dynrelocs, info);
252b5132 8597
d504ffc8
DJ
8598 /* Here we rummage through the found bfds to collect glue information. */
8599 for (ibfd = info->input_bfds; ibfd != NULL; ibfd = ibfd->link_next)
c7b8f16e
JB
8600 {
8601 /* Initialise mapping tables for code/data. */
8602 bfd_elf32_arm_init_maps (ibfd);
8603
8604 if (!bfd_elf32_arm_process_before_allocation (ibfd, info)
8605 || !bfd_elf32_arm_vfp11_erratum_scan (ibfd, info))
8606 /* xgettext:c-format */
8607 _bfd_error_handler (_("Errors encountered processing file %s"),
8608 ibfd->filename);
8609 }
d504ffc8 8610
252b5132
RH
8611 /* The check_relocs and adjust_dynamic_symbol entry points have
8612 determined the sizes of the various dynamic sections. Allocate
8613 memory for them. */
b34976b6
AM
8614 plt = FALSE;
8615 relocs = FALSE;
252b5132
RH
8616 for (s = dynobj->sections; s != NULL; s = s->next)
8617 {
8618 const char * name;
252b5132
RH
8619
8620 if ((s->flags & SEC_LINKER_CREATED) == 0)
8621 continue;
8622
8623 /* It's OK to base decisions on the section name, because none
8624 of the dynobj section names depend upon the input files. */
8625 name = bfd_get_section_name (dynobj, s);
8626
24a1ba0f 8627 if (strcmp (name, ".plt") == 0)
252b5132 8628 {
c456f082
AM
8629 /* Remember whether there is a PLT. */
8630 plt = s->size != 0;
252b5132 8631 }
0112cd26 8632 else if (CONST_STRNEQ (name, ".rel"))
252b5132 8633 {
c456f082 8634 if (s->size != 0)
252b5132 8635 {
252b5132 8636 /* Remember whether there are any reloc sections other
00a97672
RS
8637 than .rel(a).plt and .rela.plt.unloaded. */
8638 if (s != htab->srelplt && s != htab->srelplt2)
b34976b6 8639 relocs = TRUE;
252b5132
RH
8640
8641 /* We use the reloc_count field as a counter if we need
8642 to copy relocs into the output file. */
8643 s->reloc_count = 0;
8644 }
8645 }
0112cd26 8646 else if (! CONST_STRNEQ (name, ".got")
c456f082 8647 && strcmp (name, ".dynbss") != 0)
252b5132
RH
8648 {
8649 /* It's not one of our sections, so don't allocate space. */
8650 continue;
8651 }
8652
c456f082 8653 if (s->size == 0)
252b5132 8654 {
c456f082 8655 /* If we don't need this section, strip it from the
00a97672
RS
8656 output file. This is mostly to handle .rel(a).bss and
8657 .rel(a).plt. We must create both sections in
c456f082
AM
8658 create_dynamic_sections, because they must be created
8659 before the linker maps input sections to output
8660 sections. The linker does that before
8661 adjust_dynamic_symbol is called, and it is that
8662 function which decides whether anything needs to go
8663 into these sections. */
8423293d 8664 s->flags |= SEC_EXCLUDE;
252b5132
RH
8665 continue;
8666 }
8667
c456f082
AM
8668 if ((s->flags & SEC_HAS_CONTENTS) == 0)
8669 continue;
8670
252b5132 8671 /* Allocate memory for the section contents. */
eea6121a 8672 s->contents = (bfd_byte *) bfd_zalloc (dynobj, s->size);
c456f082 8673 if (s->contents == NULL)
b34976b6 8674 return FALSE;
252b5132
RH
8675 }
8676
8677 if (elf_hash_table (info)->dynamic_sections_created)
8678 {
8679 /* Add some entries to the .dynamic section. We fill in the
8680 values later, in elf32_arm_finish_dynamic_sections, but we
8681 must add the entries now so that we get the correct size for
8682 the .dynamic section. The DT_DEBUG entry is filled in by the
8683 dynamic linker and used by the debugger. */
dc810e39 8684#define add_dynamic_entry(TAG, VAL) \
5a580b3a 8685 _bfd_elf_add_dynamic_entry (info, TAG, VAL)
dc810e39 8686
8532796c 8687 if (info->executable)
252b5132 8688 {
dc810e39 8689 if (!add_dynamic_entry (DT_DEBUG, 0))
b34976b6 8690 return FALSE;
252b5132
RH
8691 }
8692
8693 if (plt)
8694 {
dc810e39
AM
8695 if ( !add_dynamic_entry (DT_PLTGOT, 0)
8696 || !add_dynamic_entry (DT_PLTRELSZ, 0)
00a97672
RS
8697 || !add_dynamic_entry (DT_PLTREL,
8698 htab->use_rel ? DT_REL : DT_RELA)
dc810e39 8699 || !add_dynamic_entry (DT_JMPREL, 0))
b34976b6 8700 return FALSE;
252b5132
RH
8701 }
8702
8703 if (relocs)
8704 {
00a97672
RS
8705 if (htab->use_rel)
8706 {
8707 if (!add_dynamic_entry (DT_REL, 0)
8708 || !add_dynamic_entry (DT_RELSZ, 0)
8709 || !add_dynamic_entry (DT_RELENT, RELOC_SIZE (htab)))
8710 return FALSE;
8711 }
8712 else
8713 {
8714 if (!add_dynamic_entry (DT_RELA, 0)
8715 || !add_dynamic_entry (DT_RELASZ, 0)
8716 || !add_dynamic_entry (DT_RELAENT, RELOC_SIZE (htab)))
8717 return FALSE;
8718 }
252b5132
RH
8719 }
8720
08d1f311
DJ
8721 /* If any dynamic relocs apply to a read-only section,
8722 then we need a DT_TEXTREL entry. */
8723 if ((info->flags & DF_TEXTREL) == 0)
8724 elf_link_hash_traverse (&htab->root, elf32_arm_readonly_dynrelocs,
8725 (PTR) info);
8726
99e4ae17 8727 if ((info->flags & DF_TEXTREL) != 0)
252b5132 8728 {
dc810e39 8729 if (!add_dynamic_entry (DT_TEXTREL, 0))
b34976b6 8730 return FALSE;
252b5132 8731 }
7a2b07ff
NS
8732 if (htab->vxworks_p
8733 && !elf_vxworks_add_dynamic_entries (output_bfd, info))
8734 return FALSE;
252b5132 8735 }
8532796c 8736#undef add_dynamic_entry
252b5132 8737
b34976b6 8738 return TRUE;
252b5132
RH
8739}
8740
252b5132
RH
8741/* Finish up dynamic symbol handling. We set the contents of various
8742 dynamic sections here. */
8743
b34976b6 8744static bfd_boolean
57e8b36a
NC
8745elf32_arm_finish_dynamic_symbol (bfd * output_bfd, struct bfd_link_info * info,
8746 struct elf_link_hash_entry * h, Elf_Internal_Sym * sym)
252b5132
RH
8747{
8748 bfd * dynobj;
e5a52504 8749 struct elf32_arm_link_hash_table *htab;
b7693d02 8750 struct elf32_arm_link_hash_entry *eh;
252b5132
RH
8751
8752 dynobj = elf_hash_table (info)->dynobj;
e5a52504 8753 htab = elf32_arm_hash_table (info);
b7693d02 8754 eh = (struct elf32_arm_link_hash_entry *) h;
252b5132
RH
8755
8756 if (h->plt.offset != (bfd_vma) -1)
8757 {
8758 asection * splt;
252b5132 8759 asection * srel;
e5a52504 8760 bfd_byte *loc;
24a1ba0f 8761 bfd_vma plt_index;
947216bf 8762 Elf_Internal_Rela rel;
252b5132
RH
8763
8764 /* This symbol has an entry in the procedure linkage table. Set
8765 it up. */
8766
8767 BFD_ASSERT (h->dynindx != -1);
8768
8769 splt = bfd_get_section_by_name (dynobj, ".plt");
00a97672 8770 srel = bfd_get_section_by_name (dynobj, RELOC_SECTION (htab, ".plt"));
e5a52504 8771 BFD_ASSERT (splt != NULL && srel != NULL);
252b5132 8772
e5a52504
MM
8773 /* Fill in the entry in the procedure linkage table. */
8774 if (htab->symbian_p)
8775 {
52ab56c2
PB
8776 put_arm_insn (htab, output_bfd,
8777 elf32_arm_symbian_plt_entry[0],
8778 splt->contents + h->plt.offset);
8779 bfd_put_32 (output_bfd,
8780 elf32_arm_symbian_plt_entry[1],
8781 splt->contents + h->plt.offset + 4);
e5a52504
MM
8782
8783 /* Fill in the entry in the .rel.plt section. */
2a1b9a48
MM
8784 rel.r_offset = (splt->output_section->vma
8785 + splt->output_offset
52ab56c2 8786 + h->plt.offset + 4);
e5a52504 8787 rel.r_info = ELF32_R_INFO (h->dynindx, R_ARM_GLOB_DAT);
b7693d02
DJ
8788
8789 /* Get the index in the procedure linkage table which
8790 corresponds to this symbol. This is the index of this symbol
8791 in all the symbols for which we are making plt entries. The
8792 first entry in the procedure linkage table is reserved. */
8793 plt_index = ((h->plt.offset - htab->plt_header_size)
8794 / htab->plt_entry_size);
e5a52504
MM
8795 }
8796 else
8797 {
00a97672 8798 bfd_vma got_offset, got_address, plt_address;
e5a52504
MM
8799 bfd_vma got_displacement;
8800 asection * sgot;
52ab56c2 8801 bfd_byte * ptr;
e5a52504
MM
8802
8803 sgot = bfd_get_section_by_name (dynobj, ".got.plt");
8804 BFD_ASSERT (sgot != NULL);
8805
b7693d02
DJ
8806 /* Get the offset into the .got.plt table of the entry that
8807 corresponds to this function. */
8808 got_offset = eh->plt_got_offset;
8809
8810 /* Get the index in the procedure linkage table which
8811 corresponds to this symbol. This is the index of this symbol
8812 in all the symbols for which we are making plt entries. The
8813 first three entries in .got.plt are reserved; after that
8814 symbols appear in the same order as in .plt. */
8815 plt_index = (got_offset - 12) / 4;
e5a52504 8816
00a97672
RS
8817 /* Calculate the address of the GOT entry. */
8818 got_address = (sgot->output_section->vma
8819 + sgot->output_offset
8820 + got_offset);
5e681ec4 8821
00a97672
RS
8822 /* ...and the address of the PLT entry. */
8823 plt_address = (splt->output_section->vma
8824 + splt->output_offset
8825 + h->plt.offset);
5e681ec4 8826
52ab56c2 8827 ptr = htab->splt->contents + h->plt.offset;
00a97672
RS
8828 if (htab->vxworks_p && info->shared)
8829 {
8830 unsigned int i;
8831 bfd_vma val;
8832
52ab56c2 8833 for (i = 0; i != htab->plt_entry_size / 4; i++, ptr += 4)
00a97672
RS
8834 {
8835 val = elf32_arm_vxworks_shared_plt_entry[i];
8836 if (i == 2)
8837 val |= got_address - sgot->output_section->vma;
8838 if (i == 5)
8839 val |= plt_index * RELOC_SIZE (htab);
52ab56c2
PB
8840 if (i == 2 || i == 5)
8841 bfd_put_32 (output_bfd, val, ptr);
8842 else
8843 put_arm_insn (htab, output_bfd, val, ptr);
00a97672
RS
8844 }
8845 }
8846 else if (htab->vxworks_p)
b7693d02 8847 {
00a97672
RS
8848 unsigned int i;
8849 bfd_vma val;
8850
d3753b85 8851 for (i = 0; i != htab->plt_entry_size / 4; i++, ptr += 4)
00a97672
RS
8852 {
8853 val = elf32_arm_vxworks_exec_plt_entry[i];
8854 if (i == 2)
8855 val |= got_address;
8856 if (i == 4)
8857 val |= 0xffffff & -((h->plt.offset + i * 4 + 8) >> 2);
8858 if (i == 5)
8859 val |= plt_index * RELOC_SIZE (htab);
52ab56c2
PB
8860 if (i == 2 || i == 5)
8861 bfd_put_32 (output_bfd, val, ptr);
8862 else
8863 put_arm_insn (htab, output_bfd, val, ptr);
00a97672
RS
8864 }
8865
8866 loc = (htab->srelplt2->contents
8867 + (plt_index * 2 + 1) * RELOC_SIZE (htab));
8868
8869 /* Create the .rela.plt.unloaded R_ARM_ABS32 relocation
8870 referencing the GOT for this PLT entry. */
8871 rel.r_offset = plt_address + 8;
8872 rel.r_info = ELF32_R_INFO (htab->root.hgot->indx, R_ARM_ABS32);
8873 rel.r_addend = got_offset;
8874 SWAP_RELOC_OUT (htab) (output_bfd, &rel, loc);
8875 loc += RELOC_SIZE (htab);
8876
8877 /* Create the R_ARM_ABS32 relocation referencing the
8878 beginning of the PLT for this GOT entry. */
8879 rel.r_offset = got_address;
8880 rel.r_info = ELF32_R_INFO (htab->root.hplt->indx, R_ARM_ABS32);
8881 rel.r_addend = 0;
8882 SWAP_RELOC_OUT (htab) (output_bfd, &rel, loc);
b7693d02 8883 }
00a97672
RS
8884 else
8885 {
bd97cb95 8886 bfd_signed_vma thumb_refs;
00a97672
RS
8887 /* Calculate the displacement between the PLT slot and the
8888 entry in the GOT. The eight-byte offset accounts for the
8889 value produced by adding to pc in the first instruction
8890 of the PLT stub. */
8891 got_displacement = got_address - (plt_address + 8);
b7693d02 8892
00a97672
RS
8893 BFD_ASSERT ((got_displacement & 0xf0000000) == 0);
8894
bd97cb95
DJ
8895 thumb_refs = eh->plt_thumb_refcount;
8896 if (!htab->use_blx)
8897 thumb_refs += eh->plt_maybe_thumb_refcount;
8898
8899 if (thumb_refs > 0)
00a97672 8900 {
52ab56c2
PB
8901 put_thumb_insn (htab, output_bfd,
8902 elf32_arm_plt_thumb_stub[0], ptr - 4);
8903 put_thumb_insn (htab, output_bfd,
8904 elf32_arm_plt_thumb_stub[1], ptr - 2);
00a97672
RS
8905 }
8906
52ab56c2
PB
8907 put_arm_insn (htab, output_bfd,
8908 elf32_arm_plt_entry[0]
8909 | ((got_displacement & 0x0ff00000) >> 20),
8910 ptr + 0);
8911 put_arm_insn (htab, output_bfd,
8912 elf32_arm_plt_entry[1]
8913 | ((got_displacement & 0x000ff000) >> 12),
8914 ptr+ 4);
8915 put_arm_insn (htab, output_bfd,
8916 elf32_arm_plt_entry[2]
8917 | (got_displacement & 0x00000fff),
8918 ptr + 8);
5e681ec4 8919#ifdef FOUR_WORD_PLT
52ab56c2 8920 bfd_put_32 (output_bfd, elf32_arm_plt_entry[3], ptr + 12);
5e681ec4 8921#endif
00a97672 8922 }
252b5132 8923
e5a52504
MM
8924 /* Fill in the entry in the global offset table. */
8925 bfd_put_32 (output_bfd,
8926 (splt->output_section->vma
8927 + splt->output_offset),
8928 sgot->contents + got_offset);
8929
00a97672
RS
8930 /* Fill in the entry in the .rel(a).plt section. */
8931 rel.r_addend = 0;
8932 rel.r_offset = got_address;
e5a52504
MM
8933 rel.r_info = ELF32_R_INFO (h->dynindx, R_ARM_JUMP_SLOT);
8934 }
57e8b36a 8935
00a97672
RS
8936 loc = srel->contents + plt_index * RELOC_SIZE (htab);
8937 SWAP_RELOC_OUT (htab) (output_bfd, &rel, loc);
252b5132 8938
f5385ebf 8939 if (!h->def_regular)
252b5132
RH
8940 {
8941 /* Mark the symbol as undefined, rather than as defined in
8942 the .plt section. Leave the value alone. */
8943 sym->st_shndx = SHN_UNDEF;
d982ba73
PB
8944 /* If the symbol is weak, we do need to clear the value.
8945 Otherwise, the PLT entry would provide a definition for
8946 the symbol even if the symbol wasn't defined anywhere,
8947 and so the symbol would never be NULL. */
f5385ebf 8948 if (!h->ref_regular_nonweak)
d982ba73 8949 sym->st_value = 0;
252b5132
RH
8950 }
8951 }
8952
ba93b8ac
DJ
8953 if (h->got.offset != (bfd_vma) -1
8954 && (elf32_arm_hash_entry (h)->tls_type & GOT_TLS_GD) == 0
8955 && (elf32_arm_hash_entry (h)->tls_type & GOT_TLS_IE) == 0)
252b5132
RH
8956 {
8957 asection * sgot;
8958 asection * srel;
947216bf
AM
8959 Elf_Internal_Rela rel;
8960 bfd_byte *loc;
00a97672 8961 bfd_vma offset;
252b5132
RH
8962
8963 /* This symbol has an entry in the global offset table. Set it
8964 up. */
252b5132 8965 sgot = bfd_get_section_by_name (dynobj, ".got");
00a97672 8966 srel = bfd_get_section_by_name (dynobj, RELOC_SECTION (htab, ".got"));
252b5132
RH
8967 BFD_ASSERT (sgot != NULL && srel != NULL);
8968
00a97672
RS
8969 offset = (h->got.offset & ~(bfd_vma) 1);
8970 rel.r_addend = 0;
252b5132
RH
8971 rel.r_offset = (sgot->output_section->vma
8972 + sgot->output_offset
00a97672 8973 + offset);
252b5132 8974
5e681ec4
PB
8975 /* If this is a static link, or it is a -Bsymbolic link and the
8976 symbol is defined locally or was forced to be local because
8977 of a version file, we just want to emit a RELATIVE reloc.
8978 The entry in the global offset table will already have been
8979 initialized in the relocate_section function. */
252b5132 8980 if (info->shared
5e681ec4
PB
8981 && SYMBOL_REFERENCES_LOCAL (info, h))
8982 {
8983 BFD_ASSERT((h->got.offset & 1) != 0);
8984 rel.r_info = ELF32_R_INFO (0, R_ARM_RELATIVE);
00a97672
RS
8985 if (!htab->use_rel)
8986 {
8987 rel.r_addend = bfd_get_32 (output_bfd, sgot->contents + offset);
8988 bfd_put_32 (output_bfd, (bfd_vma) 0, sgot->contents + offset);
8989 }
5e681ec4 8990 }
252b5132
RH
8991 else
8992 {
5e681ec4 8993 BFD_ASSERT((h->got.offset & 1) == 0);
00a97672 8994 bfd_put_32 (output_bfd, (bfd_vma) 0, sgot->contents + offset);
252b5132
RH
8995 rel.r_info = ELF32_R_INFO (h->dynindx, R_ARM_GLOB_DAT);
8996 }
8997
00a97672
RS
8998 loc = srel->contents + srel->reloc_count++ * RELOC_SIZE (htab);
8999 SWAP_RELOC_OUT (htab) (output_bfd, &rel, loc);
252b5132
RH
9000 }
9001
f5385ebf 9002 if (h->needs_copy)
252b5132
RH
9003 {
9004 asection * s;
947216bf
AM
9005 Elf_Internal_Rela rel;
9006 bfd_byte *loc;
252b5132
RH
9007
9008 /* This symbol needs a copy reloc. Set it up. */
252b5132
RH
9009 BFD_ASSERT (h->dynindx != -1
9010 && (h->root.type == bfd_link_hash_defined
9011 || h->root.type == bfd_link_hash_defweak));
9012
9013 s = bfd_get_section_by_name (h->root.u.def.section->owner,
00a97672 9014 RELOC_SECTION (htab, ".bss"));
252b5132
RH
9015 BFD_ASSERT (s != NULL);
9016
00a97672 9017 rel.r_addend = 0;
252b5132
RH
9018 rel.r_offset = (h->root.u.def.value
9019 + h->root.u.def.section->output_section->vma
9020 + h->root.u.def.section->output_offset);
9021 rel.r_info = ELF32_R_INFO (h->dynindx, R_ARM_COPY);
00a97672
RS
9022 loc = s->contents + s->reloc_count++ * RELOC_SIZE (htab);
9023 SWAP_RELOC_OUT (htab) (output_bfd, &rel, loc);
252b5132
RH
9024 }
9025
00a97672
RS
9026 /* Mark _DYNAMIC and _GLOBAL_OFFSET_TABLE_ as absolute. On VxWorks,
9027 the _GLOBAL_OFFSET_TABLE_ symbol is not absolute: it is relative
9028 to the ".got" section. */
252b5132 9029 if (strcmp (h->root.root.string, "_DYNAMIC") == 0
00a97672 9030 || (!htab->vxworks_p && h == htab->root.hgot))
252b5132
RH
9031 sym->st_shndx = SHN_ABS;
9032
b34976b6 9033 return TRUE;
252b5132
RH
9034}
9035
9036/* Finish up the dynamic sections. */
9037
b34976b6 9038static bfd_boolean
57e8b36a 9039elf32_arm_finish_dynamic_sections (bfd * output_bfd, struct bfd_link_info * info)
252b5132
RH
9040{
9041 bfd * dynobj;
9042 asection * sgot;
9043 asection * sdyn;
9044
9045 dynobj = elf_hash_table (info)->dynobj;
9046
9047 sgot = bfd_get_section_by_name (dynobj, ".got.plt");
229fcec5 9048 BFD_ASSERT (elf32_arm_hash_table (info)->symbian_p || sgot != NULL);
252b5132
RH
9049 sdyn = bfd_get_section_by_name (dynobj, ".dynamic");
9050
9051 if (elf_hash_table (info)->dynamic_sections_created)
9052 {
9053 asection *splt;
9054 Elf32_External_Dyn *dyncon, *dynconend;
229fcec5 9055 struct elf32_arm_link_hash_table *htab;
252b5132 9056
229fcec5 9057 htab = elf32_arm_hash_table (info);
252b5132 9058 splt = bfd_get_section_by_name (dynobj, ".plt");
24a1ba0f 9059 BFD_ASSERT (splt != NULL && sdyn != NULL);
252b5132
RH
9060
9061 dyncon = (Elf32_External_Dyn *) sdyn->contents;
eea6121a 9062 dynconend = (Elf32_External_Dyn *) (sdyn->contents + sdyn->size);
9b485d32 9063
252b5132
RH
9064 for (; dyncon < dynconend; dyncon++)
9065 {
9066 Elf_Internal_Dyn dyn;
9067 const char * name;
9068 asection * s;
9069
9070 bfd_elf32_swap_dyn_in (dynobj, dyncon, &dyn);
9071
9072 switch (dyn.d_tag)
9073 {
229fcec5
MM
9074 unsigned int type;
9075
252b5132 9076 default:
7a2b07ff
NS
9077 if (htab->vxworks_p
9078 && elf_vxworks_finish_dynamic_entry (output_bfd, &dyn))
9079 bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon);
252b5132
RH
9080 break;
9081
229fcec5
MM
9082 case DT_HASH:
9083 name = ".hash";
9084 goto get_vma_if_bpabi;
9085 case DT_STRTAB:
9086 name = ".dynstr";
9087 goto get_vma_if_bpabi;
9088 case DT_SYMTAB:
9089 name = ".dynsym";
9090 goto get_vma_if_bpabi;
c0042f5d
MM
9091 case DT_VERSYM:
9092 name = ".gnu.version";
9093 goto get_vma_if_bpabi;
9094 case DT_VERDEF:
9095 name = ".gnu.version_d";
9096 goto get_vma_if_bpabi;
9097 case DT_VERNEED:
9098 name = ".gnu.version_r";
9099 goto get_vma_if_bpabi;
9100
252b5132
RH
9101 case DT_PLTGOT:
9102 name = ".got";
9103 goto get_vma;
9104 case DT_JMPREL:
00a97672 9105 name = RELOC_SECTION (htab, ".plt");
252b5132
RH
9106 get_vma:
9107 s = bfd_get_section_by_name (output_bfd, name);
9108 BFD_ASSERT (s != NULL);
229fcec5
MM
9109 if (!htab->symbian_p)
9110 dyn.d_un.d_ptr = s->vma;
9111 else
9112 /* In the BPABI, tags in the PT_DYNAMIC section point
9113 at the file offset, not the memory address, for the
9114 convenience of the post linker. */
9115 dyn.d_un.d_ptr = s->filepos;
252b5132
RH
9116 bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon);
9117 break;
9118
229fcec5
MM
9119 get_vma_if_bpabi:
9120 if (htab->symbian_p)
9121 goto get_vma;
9122 break;
9123
252b5132 9124 case DT_PLTRELSZ:
00a97672
RS
9125 s = bfd_get_section_by_name (output_bfd,
9126 RELOC_SECTION (htab, ".plt"));
252b5132 9127 BFD_ASSERT (s != NULL);
eea6121a 9128 dyn.d_un.d_val = s->size;
252b5132
RH
9129 bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon);
9130 break;
229fcec5 9131
252b5132 9132 case DT_RELSZ:
00a97672 9133 case DT_RELASZ:
229fcec5
MM
9134 if (!htab->symbian_p)
9135 {
9136 /* My reading of the SVR4 ABI indicates that the
9137 procedure linkage table relocs (DT_JMPREL) should be
9138 included in the overall relocs (DT_REL). This is
9139 what Solaris does. However, UnixWare can not handle
9140 that case. Therefore, we override the DT_RELSZ entry
9141 here to make it not include the JMPREL relocs. Since
00a97672 9142 the linker script arranges for .rel(a).plt to follow all
229fcec5
MM
9143 other relocation sections, we don't have to worry
9144 about changing the DT_REL entry. */
00a97672
RS
9145 s = bfd_get_section_by_name (output_bfd,
9146 RELOC_SECTION (htab, ".plt"));
229fcec5
MM
9147 if (s != NULL)
9148 dyn.d_un.d_val -= s->size;
9149 bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon);
9150 break;
9151 }
9152 /* Fall through */
9153
9154 case DT_REL:
9155 case DT_RELA:
229fcec5
MM
9156 /* In the BPABI, the DT_REL tag must point at the file
9157 offset, not the VMA, of the first relocation
9158 section. So, we use code similar to that in
9159 elflink.c, but do not check for SHF_ALLOC on the
9160 relcoation section, since relocations sections are
9161 never allocated under the BPABI. The comments above
9162 about Unixware notwithstanding, we include all of the
9163 relocations here. */
9164 if (htab->symbian_p)
9165 {
9166 unsigned int i;
9167 type = ((dyn.d_tag == DT_REL || dyn.d_tag == DT_RELSZ)
9168 ? SHT_REL : SHT_RELA);
9169 dyn.d_un.d_val = 0;
9170 for (i = 1; i < elf_numsections (output_bfd); i++)
9171 {
9172 Elf_Internal_Shdr *hdr
9173 = elf_elfsections (output_bfd)[i];
9174 if (hdr->sh_type == type)
9175 {
9176 if (dyn.d_tag == DT_RELSZ
9177 || dyn.d_tag == DT_RELASZ)
9178 dyn.d_un.d_val += hdr->sh_size;
de52dba4
AM
9179 else if ((ufile_ptr) hdr->sh_offset
9180 <= dyn.d_un.d_val - 1)
229fcec5
MM
9181 dyn.d_un.d_val = hdr->sh_offset;
9182 }
9183 }
9184 bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon);
9185 }
252b5132 9186 break;
88f7bcd5
NC
9187
9188 /* Set the bottom bit of DT_INIT/FINI if the
9189 corresponding function is Thumb. */
9190 case DT_INIT:
9191 name = info->init_function;
9192 goto get_sym;
9193 case DT_FINI:
9194 name = info->fini_function;
9195 get_sym:
9196 /* If it wasn't set by elf_bfd_final_link
4cc11e76 9197 then there is nothing to adjust. */
88f7bcd5
NC
9198 if (dyn.d_un.d_val != 0)
9199 {
9200 struct elf_link_hash_entry * eh;
9201
9202 eh = elf_link_hash_lookup (elf_hash_table (info), name,
b34976b6 9203 FALSE, FALSE, TRUE);
88f7bcd5
NC
9204 if (eh != (struct elf_link_hash_entry *) NULL
9205 && ELF_ST_TYPE (eh->type) == STT_ARM_TFUNC)
9206 {
9207 dyn.d_un.d_val |= 1;
b34976b6 9208 bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon);
88f7bcd5
NC
9209 }
9210 }
9211 break;
252b5132
RH
9212 }
9213 }
9214
24a1ba0f 9215 /* Fill in the first entry in the procedure linkage table. */
e5a52504 9216 if (splt->size > 0 && elf32_arm_hash_table (info)->plt_header_size)
f7a74f8c 9217 {
00a97672
RS
9218 const bfd_vma *plt0_entry;
9219 bfd_vma got_address, plt_address, got_displacement;
9220
9221 /* Calculate the addresses of the GOT and PLT. */
9222 got_address = sgot->output_section->vma + sgot->output_offset;
9223 plt_address = splt->output_section->vma + splt->output_offset;
9224
9225 if (htab->vxworks_p)
9226 {
9227 /* The VxWorks GOT is relocated by the dynamic linker.
9228 Therefore, we must emit relocations rather than simply
9229 computing the values now. */
9230 Elf_Internal_Rela rel;
9231
9232 plt0_entry = elf32_arm_vxworks_exec_plt0_entry;
52ab56c2
PB
9233 put_arm_insn (htab, output_bfd, plt0_entry[0],
9234 splt->contents + 0);
9235 put_arm_insn (htab, output_bfd, plt0_entry[1],
9236 splt->contents + 4);
9237 put_arm_insn (htab, output_bfd, plt0_entry[2],
9238 splt->contents + 8);
00a97672
RS
9239 bfd_put_32 (output_bfd, got_address, splt->contents + 12);
9240
9241 /* Generate a relocation for _GLOBAL_OFFSET_TABLE_. */
9242 rel.r_offset = plt_address + 12;
9243 rel.r_info = ELF32_R_INFO (htab->root.hgot->indx, R_ARM_ABS32);
9244 rel.r_addend = 0;
9245 SWAP_RELOC_OUT (htab) (output_bfd, &rel,
9246 htab->srelplt2->contents);
9247 }
9248 else
9249 {
9250 got_displacement = got_address - (plt_address + 16);
9251
9252 plt0_entry = elf32_arm_plt0_entry;
52ab56c2
PB
9253 put_arm_insn (htab, output_bfd, plt0_entry[0],
9254 splt->contents + 0);
9255 put_arm_insn (htab, output_bfd, plt0_entry[1],
9256 splt->contents + 4);
9257 put_arm_insn (htab, output_bfd, plt0_entry[2],
9258 splt->contents + 8);
9259 put_arm_insn (htab, output_bfd, plt0_entry[3],
9260 splt->contents + 12);
5e681ec4 9261
5e681ec4 9262#ifdef FOUR_WORD_PLT
00a97672
RS
9263 /* The displacement value goes in the otherwise-unused
9264 last word of the second entry. */
9265 bfd_put_32 (output_bfd, got_displacement, splt->contents + 28);
5e681ec4 9266#else
00a97672 9267 bfd_put_32 (output_bfd, got_displacement, splt->contents + 16);
5e681ec4 9268#endif
00a97672 9269 }
f7a74f8c 9270 }
252b5132
RH
9271
9272 /* UnixWare sets the entsize of .plt to 4, although that doesn't
9273 really seem like the right value. */
74541ad4
AM
9274 if (splt->output_section->owner == output_bfd)
9275 elf_section_data (splt->output_section)->this_hdr.sh_entsize = 4;
00a97672
RS
9276
9277 if (htab->vxworks_p && !info->shared && htab->splt->size > 0)
9278 {
9279 /* Correct the .rel(a).plt.unloaded relocations. They will have
9280 incorrect symbol indexes. */
9281 int num_plts;
eed62c48 9282 unsigned char *p;
00a97672
RS
9283
9284 num_plts = ((htab->splt->size - htab->plt_header_size)
9285 / htab->plt_entry_size);
9286 p = htab->srelplt2->contents + RELOC_SIZE (htab);
9287
9288 for (; num_plts; num_plts--)
9289 {
9290 Elf_Internal_Rela rel;
9291
9292 SWAP_RELOC_IN (htab) (output_bfd, p, &rel);
9293 rel.r_info = ELF32_R_INFO (htab->root.hgot->indx, R_ARM_ABS32);
9294 SWAP_RELOC_OUT (htab) (output_bfd, &rel, p);
9295 p += RELOC_SIZE (htab);
9296
9297 SWAP_RELOC_IN (htab) (output_bfd, p, &rel);
9298 rel.r_info = ELF32_R_INFO (htab->root.hplt->indx, R_ARM_ABS32);
9299 SWAP_RELOC_OUT (htab) (output_bfd, &rel, p);
9300 p += RELOC_SIZE (htab);
9301 }
9302 }
252b5132
RH
9303 }
9304
9305 /* Fill in the first three entries in the global offset table. */
229fcec5 9306 if (sgot)
252b5132 9307 {
229fcec5
MM
9308 if (sgot->size > 0)
9309 {
9310 if (sdyn == NULL)
9311 bfd_put_32 (output_bfd, (bfd_vma) 0, sgot->contents);
9312 else
9313 bfd_put_32 (output_bfd,
9314 sdyn->output_section->vma + sdyn->output_offset,
9315 sgot->contents);
9316 bfd_put_32 (output_bfd, (bfd_vma) 0, sgot->contents + 4);
9317 bfd_put_32 (output_bfd, (bfd_vma) 0, sgot->contents + 8);
9318 }
252b5132 9319
229fcec5
MM
9320 elf_section_data (sgot->output_section)->this_hdr.sh_entsize = 4;
9321 }
252b5132 9322
b34976b6 9323 return TRUE;
252b5132
RH
9324}
9325
ba96a88f 9326static void
57e8b36a 9327elf32_arm_post_process_headers (bfd * abfd, struct bfd_link_info * link_info ATTRIBUTE_UNUSED)
ba96a88f 9328{
9b485d32 9329 Elf_Internal_Ehdr * i_ehdrp; /* ELF file header, internal form. */
e489d0ae 9330 struct elf32_arm_link_hash_table *globals;
ba96a88f
NC
9331
9332 i_ehdrp = elf_elfheader (abfd);
9333
94a3258f
PB
9334 if (EF_ARM_EABI_VERSION (i_ehdrp->e_flags) == EF_ARM_EABI_UNKNOWN)
9335 i_ehdrp->e_ident[EI_OSABI] = ELFOSABI_ARM;
9336 else
9337 i_ehdrp->e_ident[EI_OSABI] = 0;
ba96a88f 9338 i_ehdrp->e_ident[EI_ABIVERSION] = ARM_ELF_ABI_VERSION;
e489d0ae 9339
93204d3a
PB
9340 if (link_info)
9341 {
9342 globals = elf32_arm_hash_table (link_info);
9343 if (globals->byteswap_code)
9344 i_ehdrp->e_flags |= EF_ARM_BE8;
9345 }
ba96a88f
NC
9346}
9347
99e4ae17 9348static enum elf_reloc_type_class
57e8b36a 9349elf32_arm_reloc_type_class (const Elf_Internal_Rela *rela)
99e4ae17 9350{
f51e552e 9351 switch ((int) ELF32_R_TYPE (rela->r_info))
99e4ae17
AJ
9352 {
9353 case R_ARM_RELATIVE:
9354 return reloc_class_relative;
9355 case R_ARM_JUMP_SLOT:
9356 return reloc_class_plt;
9357 case R_ARM_COPY:
9358 return reloc_class_copy;
9359 default:
9360 return reloc_class_normal;
9361 }
9362}
9363
e16bb312
NC
9364/* Set the right machine number for an Arm ELF file. */
9365
9366static bfd_boolean
57e8b36a 9367elf32_arm_section_flags (flagword *flags, const Elf_Internal_Shdr *hdr)
e16bb312
NC
9368{
9369 if (hdr->sh_type == SHT_NOTE)
9370 *flags |= SEC_LINK_ONCE | SEC_LINK_DUPLICATES_SAME_CONTENTS;
9371
9372 return TRUE;
9373}
9374
e489d0ae 9375static void
57e8b36a 9376elf32_arm_final_write_processing (bfd *abfd, bfd_boolean linker ATTRIBUTE_UNUSED)
e16bb312 9377{
5a6c6817 9378 bfd_arm_update_notes (abfd, ARM_NOTE_SECTION);
e16bb312
NC
9379}
9380
40a18ebd
NC
9381/* Return TRUE if this is an unwinding table entry. */
9382
9383static bfd_boolean
9384is_arm_elf_unwind_section_name (bfd * abfd ATTRIBUTE_UNUSED, const char * name)
9385{
0112cd26
NC
9386 return (CONST_STRNEQ (name, ELF_STRING_ARM_unwind)
9387 || CONST_STRNEQ (name, ELF_STRING_ARM_unwind_once));
40a18ebd
NC
9388}
9389
9390
9391/* Set the type and flags for an ARM section. We do this by
9392 the section name, which is a hack, but ought to work. */
9393
9394static bfd_boolean
9395elf32_arm_fake_sections (bfd * abfd, Elf_Internal_Shdr * hdr, asection * sec)
9396{
9397 const char * name;
9398
9399 name = bfd_get_section_name (abfd, sec);
9400
9401 if (is_arm_elf_unwind_section_name (abfd, name))
9402 {
9403 hdr->sh_type = SHT_ARM_EXIDX;
9404 hdr->sh_flags |= SHF_LINK_ORDER;
9405 }
9406 return TRUE;
9407}
9408
6dc132d9
L
9409/* Handle an ARM specific section when reading an object file. This is
9410 called when bfd_section_from_shdr finds a section with an unknown
9411 type. */
40a18ebd
NC
9412
9413static bfd_boolean
9414elf32_arm_section_from_shdr (bfd *abfd,
9415 Elf_Internal_Shdr * hdr,
6dc132d9
L
9416 const char *name,
9417 int shindex)
40a18ebd
NC
9418{
9419 /* There ought to be a place to keep ELF backend specific flags, but
9420 at the moment there isn't one. We just keep track of the
9421 sections by their name, instead. Fortunately, the ABI gives
9422 names for all the ARM specific sections, so we will probably get
9423 away with this. */
9424 switch (hdr->sh_type)
9425 {
9426 case SHT_ARM_EXIDX:
0951f019
RE
9427 case SHT_ARM_PREEMPTMAP:
9428 case SHT_ARM_ATTRIBUTES:
40a18ebd
NC
9429 break;
9430
9431 default:
9432 return FALSE;
9433 }
9434
6dc132d9 9435 if (! _bfd_elf_make_section_from_shdr (abfd, hdr, name, shindex))
40a18ebd
NC
9436 return FALSE;
9437
9438 return TRUE;
9439}
e489d0ae 9440
8e3de13a
NC
9441/* A structure used to record a list of sections, independently
9442 of the next and prev fields in the asection structure. */
9443typedef struct section_list
9444{
9445 asection * sec;
9446 struct section_list * next;
9447 struct section_list * prev;
9448}
9449section_list;
9450
9451/* Unfortunately we need to keep a list of sections for which
9452 an _arm_elf_section_data structure has been allocated. This
9453 is because it is possible for functions like elf32_arm_write_section
9454 to be called on a section which has had an elf_data_structure
9455 allocated for it (and so the used_by_bfd field is valid) but
9456 for which the ARM extended version of this structure - the
9457 _arm_elf_section_data structure - has not been allocated. */
9458static section_list * sections_with_arm_elf_section_data = NULL;
9459
9460static void
957c6e41 9461record_section_with_arm_elf_section_data (asection * sec)
8e3de13a
NC
9462{
9463 struct section_list * entry;
9464
957c6e41 9465 entry = bfd_malloc (sizeof (* entry));
8e3de13a
NC
9466 if (entry == NULL)
9467 return;
9468 entry->sec = sec;
9469 entry->next = sections_with_arm_elf_section_data;
9470 entry->prev = NULL;
9471 if (entry->next != NULL)
9472 entry->next->prev = entry;
9473 sections_with_arm_elf_section_data = entry;
9474}
9475
44444f50
NC
9476static struct section_list *
9477find_arm_elf_section_entry (asection * sec)
8e3de13a
NC
9478{
9479 struct section_list * entry;
bd4aae00 9480 static struct section_list * last_entry = NULL;
8e3de13a 9481
bd4aae00
NC
9482 /* This is a short cut for the typical case where the sections are added
9483 to the sections_with_arm_elf_section_data list in forward order and
9484 then looked up here in backwards order. This makes a real difference
9485 to the ld-srec/sec64k.exp linker test. */
44444f50 9486 entry = sections_with_arm_elf_section_data;
bd4aae00
NC
9487 if (last_entry != NULL)
9488 {
9489 if (last_entry->sec == sec)
44444f50
NC
9490 entry = last_entry;
9491 else if (last_entry->next != NULL
9492 && last_entry->next->sec == sec)
9493 entry = last_entry->next;
bd4aae00 9494 }
44444f50
NC
9495
9496 for (; entry; entry = entry->next)
8e3de13a 9497 if (entry->sec == sec)
44444f50 9498 break;
bd4aae00 9499
44444f50
NC
9500 if (entry)
9501 /* Record the entry prior to this one - it is the entry we are most
9502 likely to want to locate next time. Also this way if we have been
9503 called from unrecord_section_with_arm_elf_section_data() we will not
9504 be caching a pointer that is about to be freed. */
9505 last_entry = entry->prev;
9506
9507 return entry;
9508}
9509
9510static _arm_elf_section_data *
9511get_arm_elf_section_data (asection * sec)
9512{
9513 struct section_list * entry;
9514
9515 entry = find_arm_elf_section_entry (sec);
9516
9517 if (entry)
9518 return elf32_arm_section_data (entry->sec);
9519 else
9520 return NULL;
8e3de13a
NC
9521}
9522
9523static void
9524unrecord_section_with_arm_elf_section_data (asection * sec)
9525{
9526 struct section_list * entry;
9527
44444f50
NC
9528 entry = find_arm_elf_section_entry (sec);
9529
9530 if (entry)
9531 {
9532 if (entry->prev != NULL)
9533 entry->prev->next = entry->next;
9534 if (entry->next != NULL)
9535 entry->next->prev = entry->prev;
9536 if (entry == sections_with_arm_elf_section_data)
9537 sections_with_arm_elf_section_data = entry->next;
9538 free (entry);
9539 }
8e3de13a
NC
9540}
9541
e489d0ae 9542
4e617b1e
PB
9543typedef struct
9544{
9545 void *finfo;
9546 struct bfd_link_info *info;
91a5743d
PB
9547 asection *sec;
9548 int sec_shndx;
4e617b1e
PB
9549 bfd_boolean (*func) (void *, const char *, Elf_Internal_Sym *,
9550 asection *, struct elf_link_hash_entry *);
9551} output_arch_syminfo;
9552
9553enum map_symbol_type
9554{
9555 ARM_MAP_ARM,
9556 ARM_MAP_THUMB,
9557 ARM_MAP_DATA
9558};
9559
9560
9561/* Output a single PLT mapping symbol. */
9562
9563static bfd_boolean
9564elf32_arm_ouput_plt_map_sym (output_arch_syminfo *osi,
9565 enum map_symbol_type type,
9566 bfd_vma offset)
9567{
9568 static const char *names[3] = {"$a", "$t", "$d"};
9569 struct elf32_arm_link_hash_table *htab;
9570 Elf_Internal_Sym sym;
9571
9572 htab = elf32_arm_hash_table (osi->info);
91a5743d
PB
9573 sym.st_value = osi->sec->output_section->vma
9574 + osi->sec->output_offset
9575 + offset;
4e617b1e
PB
9576 sym.st_size = 0;
9577 sym.st_other = 0;
9578 sym.st_info = ELF_ST_INFO (STB_LOCAL, STT_NOTYPE);
91a5743d
PB
9579 sym.st_shndx = osi->sec_shndx;
9580 if (!osi->func (osi->finfo, names[type], &sym, osi->sec, NULL))
4e617b1e
PB
9581 return FALSE;
9582 return TRUE;
9583}
9584
9585
9586/* Output mapping symbols for PLT entries associated with H. */
9587
9588static bfd_boolean
9589elf32_arm_output_plt_map (struct elf_link_hash_entry *h, void *inf)
9590{
9591 output_arch_syminfo *osi = (output_arch_syminfo *) inf;
9592 struct elf32_arm_link_hash_table *htab;
9593 struct elf32_arm_link_hash_entry *eh;
9594 bfd_vma addr;
9595
9596 htab = elf32_arm_hash_table (osi->info);
9597
9598 if (h->root.type == bfd_link_hash_indirect)
9599 return TRUE;
9600
9601 if (h->root.type == bfd_link_hash_warning)
9602 /* When warning symbols are created, they **replace** the "real"
9603 entry in the hash table, thus we never get to see the real
9604 symbol in a hash traversal. So look at it now. */
9605 h = (struct elf_link_hash_entry *) h->root.u.i.link;
9606
9607 if (h->plt.offset == (bfd_vma) -1)
9608 return TRUE;
9609
9610 eh = (struct elf32_arm_link_hash_entry *) h;
9611 addr = h->plt.offset;
9612 if (htab->symbian_p)
9613 {
9614 if (!elf32_arm_ouput_plt_map_sym (osi, ARM_MAP_ARM, addr))
9615 return FALSE;
9616 if (!elf32_arm_ouput_plt_map_sym (osi, ARM_MAP_DATA, addr + 4))
9617 return FALSE;
9618 }
9619 else if (htab->vxworks_p)
9620 {
9621 if (!elf32_arm_ouput_plt_map_sym (osi, ARM_MAP_ARM, addr))
9622 return FALSE;
9623 if (!elf32_arm_ouput_plt_map_sym (osi, ARM_MAP_DATA, addr + 8))
9624 return FALSE;
9625 if (!elf32_arm_ouput_plt_map_sym (osi, ARM_MAP_ARM, addr + 12))
9626 return FALSE;
9627 if (!elf32_arm_ouput_plt_map_sym (osi, ARM_MAP_DATA, addr + 20))
9628 return FALSE;
9629 }
9630 else
9631 {
bd97cb95
DJ
9632 bfd_signed_vma thumb_refs;
9633
9634 thumb_refs = eh->plt_thumb_refcount;
9635 if (!htab->use_blx)
9636 thumb_refs += eh->plt_maybe_thumb_refcount;
4e617b1e 9637
bd97cb95 9638 if (thumb_refs > 0)
4e617b1e
PB
9639 {
9640 if (!elf32_arm_ouput_plt_map_sym (osi, ARM_MAP_THUMB, addr - 4))
9641 return FALSE;
9642 }
9643#ifdef FOUR_WORD_PLT
9644 if (!elf32_arm_ouput_plt_map_sym (osi, ARM_MAP_ARM, addr))
9645 return FALSE;
9646 if (!elf32_arm_ouput_plt_map_sym (osi, ARM_MAP_DATA, addr + 12))
9647 return FALSE;
9648#else
9649 /* A three-word PLT with no Thumb thunk contains only Arm code,
9650 so only need to output a mapping symbol for the first PLT entry and
9651 entries with thumb thunks. */
bd97cb95 9652 if (thumb_refs > 0 || addr == 20)
4e617b1e
PB
9653 {
9654 if (!elf32_arm_ouput_plt_map_sym (osi, ARM_MAP_ARM, addr))
9655 return FALSE;
9656 }
9657#endif
9658 }
9659
9660 return TRUE;
9661}
9662
9663
91a5743d 9664/* Output mapping symbols for linker generated sections. */
4e617b1e
PB
9665
9666static bfd_boolean
9667elf32_arm_output_arch_local_syms (bfd *output_bfd,
9668 struct bfd_link_info *info,
9669 void *finfo, bfd_boolean (*func) (void *, const char *,
9670 Elf_Internal_Sym *,
9671 asection *,
9672 struct elf_link_hash_entry *))
9673{
9674 output_arch_syminfo osi;
9675 struct elf32_arm_link_hash_table *htab;
91a5743d
PB
9676 bfd_vma offset;
9677 bfd_size_type size;
4e617b1e
PB
9678
9679 htab = elf32_arm_hash_table (info);
4e617b1e 9680 check_use_blx(htab);
91a5743d 9681
4e617b1e
PB
9682 osi.finfo = finfo;
9683 osi.info = info;
9684 osi.func = func;
91a5743d
PB
9685
9686 /* ARM->Thumb glue. */
9687 if (htab->arm_glue_size > 0)
9688 {
9689 osi.sec = bfd_get_section_by_name (htab->bfd_of_glue_owner,
9690 ARM2THUMB_GLUE_SECTION_NAME);
9691
9692 osi.sec_shndx = _bfd_elf_section_from_bfd_section
9693 (output_bfd, osi.sec->output_section);
9694 if (info->shared || htab->root.is_relocatable_executable
9695 || htab->pic_veneer)
9696 size = ARM2THUMB_PIC_GLUE_SIZE;
9697 else if (htab->use_blx)
9698 size = ARM2THUMB_V5_STATIC_GLUE_SIZE;
9699 else
9700 size = ARM2THUMB_STATIC_GLUE_SIZE;
4e617b1e 9701
91a5743d
PB
9702 for (offset = 0; offset < htab->arm_glue_size; offset += size)
9703 {
9704 elf32_arm_ouput_plt_map_sym (&osi, ARM_MAP_ARM, offset);
9705 elf32_arm_ouput_plt_map_sym (&osi, ARM_MAP_DATA, offset + size - 4);
9706 }
9707 }
9708
9709 /* Thumb->ARM glue. */
9710 if (htab->thumb_glue_size > 0)
9711 {
9712 osi.sec = bfd_get_section_by_name (htab->bfd_of_glue_owner,
9713 THUMB2ARM_GLUE_SECTION_NAME);
9714
9715 osi.sec_shndx = _bfd_elf_section_from_bfd_section
9716 (output_bfd, osi.sec->output_section);
9717 size = THUMB2ARM_GLUE_SIZE;
9718
9719 for (offset = 0; offset < htab->thumb_glue_size; offset += size)
9720 {
9721 elf32_arm_ouput_plt_map_sym (&osi, ARM_MAP_THUMB, offset);
9722 elf32_arm_ouput_plt_map_sym (&osi, ARM_MAP_ARM, offset + 4);
9723 }
9724 }
9725
9726 /* Finally, output mapping symbols for the PLT. */
9727 if (!htab->splt || htab->splt->size == 0)
9728 return TRUE;
9729
9730 osi.sec_shndx = _bfd_elf_section_from_bfd_section (output_bfd,
9731 htab->splt->output_section);
9732 osi.sec = htab->splt;
4e617b1e
PB
9733 /* Output mapping symbols for the plt header. SymbianOS does not have a
9734 plt header. */
9735 if (htab->vxworks_p)
9736 {
9737 /* VxWorks shared libraries have no PLT header. */
9738 if (!info->shared)
9739 {
9740 if (!elf32_arm_ouput_plt_map_sym (&osi, ARM_MAP_ARM, 0))
9741 return FALSE;
9742 if (!elf32_arm_ouput_plt_map_sym (&osi, ARM_MAP_DATA, 12))
9743 return FALSE;
9744 }
9745 }
9746 else if (!htab->symbian_p)
9747 {
9748 if (!elf32_arm_ouput_plt_map_sym (&osi, ARM_MAP_ARM, 0))
9749 return FALSE;
9750#ifndef FOUR_WORD_PLT
9751 if (!elf32_arm_ouput_plt_map_sym (&osi, ARM_MAP_DATA, 16))
9752 return FALSE;
9753#endif
9754 }
9755
9756 elf_link_hash_traverse (&htab->root, elf32_arm_output_plt_map, (void *) &osi);
9757 return TRUE;
9758}
9759
e489d0ae
PB
9760/* Allocate target specific section data. */
9761
9762static bfd_boolean
9763elf32_arm_new_section_hook (bfd *abfd, asection *sec)
9764{
f592407e
AM
9765 if (!sec->used_by_bfd)
9766 {
9767 _arm_elf_section_data *sdata;
9768 bfd_size_type amt = sizeof (*sdata);
e489d0ae 9769
f592407e
AM
9770 sdata = bfd_zalloc (abfd, amt);
9771 if (sdata == NULL)
9772 return FALSE;
9773 sec->used_by_bfd = sdata;
9774 }
e489d0ae 9775
957c6e41 9776 record_section_with_arm_elf_section_data (sec);
8e3de13a 9777
e489d0ae
PB
9778 return _bfd_elf_new_section_hook (abfd, sec);
9779}
9780
9781
9782/* Used to order a list of mapping symbols by address. */
9783
9784static int
9785elf32_arm_compare_mapping (const void * a, const void * b)
9786{
7f6a71ff
JM
9787 const elf32_arm_section_map *amap = (const elf32_arm_section_map *) a;
9788 const elf32_arm_section_map *bmap = (const elf32_arm_section_map *) b;
9789
9790 if (amap->vma > bmap->vma)
9791 return 1;
9792 else if (amap->vma < bmap->vma)
9793 return -1;
9794 else if (amap->type > bmap->type)
9795 /* Ensure results do not depend on the host qsort for objects with
9796 multiple mapping symbols at the same address by sorting on type
9797 after vma. */
9798 return 1;
9799 else if (amap->type < bmap->type)
9800 return -1;
9801 else
9802 return 0;
e489d0ae
PB
9803}
9804
9805
9806/* Do code byteswapping. Return FALSE afterwards so that the section is
9807 written out as normal. */
9808
9809static bfd_boolean
c7b8f16e
JB
9810elf32_arm_write_section (bfd *output_bfd,
9811 struct bfd_link_info *link_info, asection *sec,
e489d0ae
PB
9812 bfd_byte *contents)
9813{
c7b8f16e 9814 int mapcount, errcount;
8e3de13a 9815 _arm_elf_section_data *arm_data;
c7b8f16e 9816 struct elf32_arm_link_hash_table *globals = elf32_arm_hash_table (link_info);
e489d0ae 9817 elf32_arm_section_map *map;
c7b8f16e 9818 elf32_vfp11_erratum_list *errnode;
e489d0ae
PB
9819 bfd_vma ptr;
9820 bfd_vma end;
c7b8f16e 9821 bfd_vma offset = sec->output_section->vma + sec->output_offset;
e489d0ae
PB
9822 bfd_byte tmp;
9823 int i;
57e8b36a 9824
8e3de13a
NC
9825 /* If this section has not been allocated an _arm_elf_section_data
9826 structure then we cannot record anything. */
9827 arm_data = get_arm_elf_section_data (sec);
9828 if (arm_data == NULL)
9829 return FALSE;
9830
9831 mapcount = arm_data->mapcount;
9832 map = arm_data->map;
c7b8f16e
JB
9833 errcount = arm_data->erratumcount;
9834
9835 if (errcount != 0)
9836 {
9837 unsigned int endianflip = bfd_big_endian (output_bfd) ? 3 : 0;
9838
9839 for (errnode = arm_data->erratumlist; errnode != 0;
9840 errnode = errnode->next)
9841 {
9842 bfd_vma index = errnode->vma - offset;
9843
9844 switch (errnode->type)
9845 {
9846 case VFP11_ERRATUM_BRANCH_TO_ARM_VENEER:
9847 {
9848 bfd_vma branch_to_veneer;
9849 /* Original condition code of instruction, plus bit mask for
9850 ARM B instruction. */
9851 unsigned int insn = (errnode->u.b.vfp_insn & 0xf0000000)
9852 | 0x0a000000;
9853
9854 /* The instruction is before the label. */
9855 index -= 4;
9856
9857 /* Above offset included in -4 below. */
9858 branch_to_veneer = errnode->u.b.veneer->vma
9859 - errnode->vma - 4;
9860
9861 if ((signed) branch_to_veneer < -(1 << 25)
9862 || (signed) branch_to_veneer >= (1 << 25))
9863 (*_bfd_error_handler) (_("%B: error: VFP11 veneer out of "
9864 "range"), output_bfd);
9865
9866 insn |= (branch_to_veneer >> 2) & 0xffffff;
9867 contents[endianflip ^ index] = insn & 0xff;
9868 contents[endianflip ^ (index + 1)] = (insn >> 8) & 0xff;
9869 contents[endianflip ^ (index + 2)] = (insn >> 16) & 0xff;
9870 contents[endianflip ^ (index + 3)] = (insn >> 24) & 0xff;
9871 }
9872 break;
9873
9874 case VFP11_ERRATUM_ARM_VENEER:
9875 {
9876 bfd_vma branch_from_veneer;
9877 unsigned int insn;
9878
9879 /* Take size of veneer into account. */
9880 branch_from_veneer = errnode->u.v.branch->vma
9881 - errnode->vma - 12;
9882
9883 if ((signed) branch_from_veneer < -(1 << 25)
9884 || (signed) branch_from_veneer >= (1 << 25))
9885 (*_bfd_error_handler) (_("%B: error: VFP11 veneer out of "
9886 "range"), output_bfd);
9887
9888 /* Original instruction. */
9889 insn = errnode->u.v.branch->u.b.vfp_insn;
9890 contents[endianflip ^ index] = insn & 0xff;
9891 contents[endianflip ^ (index + 1)] = (insn >> 8) & 0xff;
9892 contents[endianflip ^ (index + 2)] = (insn >> 16) & 0xff;
9893 contents[endianflip ^ (index + 3)] = (insn >> 24) & 0xff;
9894
9895 /* Branch back to insn after original insn. */
9896 insn = 0xea000000 | ((branch_from_veneer >> 2) & 0xffffff);
9897 contents[endianflip ^ (index + 4)] = insn & 0xff;
9898 contents[endianflip ^ (index + 5)] = (insn >> 8) & 0xff;
9899 contents[endianflip ^ (index + 6)] = (insn >> 16) & 0xff;
9900 contents[endianflip ^ (index + 7)] = (insn >> 24) & 0xff;
9901 }
9902 break;
9903
9904 default:
9905 abort ();
9906 }
9907 }
9908 }
e489d0ae
PB
9909
9910 if (mapcount == 0)
9911 return FALSE;
9912
c7b8f16e 9913 if (globals->byteswap_code)
e489d0ae 9914 {
c7b8f16e 9915 qsort (map, mapcount, sizeof (* map), elf32_arm_compare_mapping);
57e8b36a 9916
c7b8f16e
JB
9917 ptr = map[0].vma;
9918 for (i = 0; i < mapcount; i++)
9919 {
9920 if (i == mapcount - 1)
9921 end = sec->size;
9922 else
9923 end = map[i + 1].vma;
e489d0ae 9924
c7b8f16e 9925 switch (map[i].type)
e489d0ae 9926 {
c7b8f16e
JB
9927 case 'a':
9928 /* Byte swap code words. */
9929 while (ptr + 3 < end)
9930 {
9931 tmp = contents[ptr];
9932 contents[ptr] = contents[ptr + 3];
9933 contents[ptr + 3] = tmp;
9934 tmp = contents[ptr + 1];
9935 contents[ptr + 1] = contents[ptr + 2];
9936 contents[ptr + 2] = tmp;
9937 ptr += 4;
9938 }
9939 break;
e489d0ae 9940
c7b8f16e
JB
9941 case 't':
9942 /* Byte swap code halfwords. */
9943 while (ptr + 1 < end)
9944 {
9945 tmp = contents[ptr];
9946 contents[ptr] = contents[ptr + 1];
9947 contents[ptr + 1] = tmp;
9948 ptr += 2;
9949 }
9950 break;
9951
9952 case 'd':
9953 /* Leave data alone. */
9954 break;
9955 }
9956 ptr = end;
9957 }
e489d0ae 9958 }
8e3de13a 9959
93204d3a 9960 free (map);
8e3de13a 9961 arm_data->mapcount = 0;
c7b8f16e 9962 arm_data->mapsize = 0;
8e3de13a
NC
9963 arm_data->map = NULL;
9964 unrecord_section_with_arm_elf_section_data (sec);
9965
e489d0ae
PB
9966 return FALSE;
9967}
9968
957c6e41
NC
9969static void
9970unrecord_section_via_map_over_sections (bfd * abfd ATTRIBUTE_UNUSED,
9971 asection * sec,
9972 void * ignore ATTRIBUTE_UNUSED)
9973{
9974 unrecord_section_with_arm_elf_section_data (sec);
9975}
9976
9977static bfd_boolean
9978elf32_arm_close_and_cleanup (bfd * abfd)
9979{
b25e3d87
L
9980 if (abfd->sections)
9981 bfd_map_over_sections (abfd,
9982 unrecord_section_via_map_over_sections,
9983 NULL);
957c6e41
NC
9984
9985 return _bfd_elf_close_and_cleanup (abfd);
9986}
9987
b25e3d87
L
9988static bfd_boolean
9989elf32_arm_bfd_free_cached_info (bfd * abfd)
9990{
9991 if (abfd->sections)
9992 bfd_map_over_sections (abfd,
9993 unrecord_section_via_map_over_sections,
9994 NULL);
9995
9996 return _bfd_free_cached_info (abfd);
9997}
9998
b7693d02
DJ
9999/* Display STT_ARM_TFUNC symbols as functions. */
10000
10001static void
10002elf32_arm_symbol_processing (bfd *abfd ATTRIBUTE_UNUSED,
10003 asymbol *asym)
10004{
10005 elf_symbol_type *elfsym = (elf_symbol_type *) asym;
10006
10007 if (ELF_ST_TYPE (elfsym->internal_elf_sym.st_info) == STT_ARM_TFUNC)
10008 elfsym->symbol.flags |= BSF_FUNCTION;
10009}
10010
0beaef2b
PB
10011
10012/* Mangle thumb function symbols as we read them in. */
10013
8384fb8f 10014static bfd_boolean
0beaef2b
PB
10015elf32_arm_swap_symbol_in (bfd * abfd,
10016 const void *psrc,
10017 const void *pshn,
10018 Elf_Internal_Sym *dst)
10019{
8384fb8f
AM
10020 if (!bfd_elf32_swap_symbol_in (abfd, psrc, pshn, dst))
10021 return FALSE;
0beaef2b
PB
10022
10023 /* New EABI objects mark thumb function symbols by setting the low bit of
10024 the address. Turn these into STT_ARM_TFUNC. */
10025 if (ELF_ST_TYPE (dst->st_info) == STT_FUNC
10026 && (dst->st_value & 1))
10027 {
10028 dst->st_info = ELF_ST_INFO (ELF_ST_BIND (dst->st_info), STT_ARM_TFUNC);
10029 dst->st_value &= ~(bfd_vma) 1;
10030 }
8384fb8f 10031 return TRUE;
0beaef2b
PB
10032}
10033
10034
10035/* Mangle thumb function symbols as we write them out. */
10036
10037static void
10038elf32_arm_swap_symbol_out (bfd *abfd,
10039 const Elf_Internal_Sym *src,
10040 void *cdst,
10041 void *shndx)
10042{
10043 Elf_Internal_Sym newsym;
10044
10045 /* We convert STT_ARM_TFUNC symbols into STT_FUNC with the low bit
10046 of the address set, as per the new EABI. We do this unconditionally
10047 because objcopy does not set the elf header flags until after
10048 it writes out the symbol table. */
10049 if (ELF_ST_TYPE (src->st_info) == STT_ARM_TFUNC)
10050 {
10051 newsym = *src;
10052 newsym.st_info = ELF_ST_INFO (ELF_ST_BIND (src->st_info), STT_FUNC);
0fa3dcad
PB
10053 if (newsym.st_shndx != SHN_UNDEF)
10054 {
10055 /* Do this only for defined symbols. At link type, the static
10056 linker will simulate the work of dynamic linker of resolving
10057 symbols and will carry over the thumbness of found symbols to
10058 the output symbol table. It's not clear how it happens, but
b0fead2b 10059 the thumbness of undefined symbols can well be different at
0fa3dcad
PB
10060 runtime, and writing '1' for them will be confusing for users
10061 and possibly for dynamic linker itself.
10062 */
10063 newsym.st_value |= 1;
10064 }
0beaef2b
PB
10065
10066 src = &newsym;
10067 }
10068 bfd_elf32_swap_symbol_out (abfd, src, cdst, shndx);
10069}
10070
b294bdf8
MM
10071/* Add the PT_ARM_EXIDX program header. */
10072
10073static bfd_boolean
10074elf32_arm_modify_segment_map (bfd *abfd,
10075 struct bfd_link_info *info ATTRIBUTE_UNUSED)
10076{
10077 struct elf_segment_map *m;
10078 asection *sec;
10079
10080 sec = bfd_get_section_by_name (abfd, ".ARM.exidx");
10081 if (sec != NULL && (sec->flags & SEC_LOAD) != 0)
10082 {
10083 /* If there is already a PT_ARM_EXIDX header, then we do not
10084 want to add another one. This situation arises when running
10085 "strip"; the input binary already has the header. */
10086 m = elf_tdata (abfd)->segment_map;
10087 while (m && m->p_type != PT_ARM_EXIDX)
10088 m = m->next;
10089 if (!m)
10090 {
10091 m = bfd_zalloc (abfd, sizeof (struct elf_segment_map));
10092 if (m == NULL)
10093 return FALSE;
10094 m->p_type = PT_ARM_EXIDX;
10095 m->count = 1;
10096 m->sections[0] = sec;
10097
10098 m->next = elf_tdata (abfd)->segment_map;
10099 elf_tdata (abfd)->segment_map = m;
10100 }
10101 }
10102
10103 return TRUE;
10104}
10105
10106/* We may add a PT_ARM_EXIDX program header. */
10107
10108static int
a6b96beb
AM
10109elf32_arm_additional_program_headers (bfd *abfd,
10110 struct bfd_link_info *info ATTRIBUTE_UNUSED)
b294bdf8
MM
10111{
10112 asection *sec;
10113
10114 sec = bfd_get_section_by_name (abfd, ".ARM.exidx");
10115 if (sec != NULL && (sec->flags & SEC_LOAD) != 0)
10116 return 1;
10117 else
10118 return 0;
10119}
10120
fcb93ecf
PB
10121/* We have two function types: STT_FUNC and STT_ARM_TFUNC. */
10122static bfd_boolean
10123elf32_arm_is_function_type (unsigned int type)
10124{
10125 return (type == STT_FUNC) || (type == STT_ARM_TFUNC);
10126}
10127
0beaef2b
PB
10128/* We use this to override swap_symbol_in and swap_symbol_out. */
10129const struct elf_size_info elf32_arm_size_info = {
10130 sizeof (Elf32_External_Ehdr),
10131 sizeof (Elf32_External_Phdr),
10132 sizeof (Elf32_External_Shdr),
10133 sizeof (Elf32_External_Rel),
10134 sizeof (Elf32_External_Rela),
10135 sizeof (Elf32_External_Sym),
10136 sizeof (Elf32_External_Dyn),
10137 sizeof (Elf_External_Note),
10138 4,
10139 1,
10140 32, 2,
10141 ELFCLASS32, EV_CURRENT,
10142 bfd_elf32_write_out_phdrs,
10143 bfd_elf32_write_shdrs_and_ehdr,
1489a3a0 10144 bfd_elf32_checksum_contents,
0beaef2b
PB
10145 bfd_elf32_write_relocs,
10146 elf32_arm_swap_symbol_in,
10147 elf32_arm_swap_symbol_out,
10148 bfd_elf32_slurp_reloc_table,
10149 bfd_elf32_slurp_symbol_table,
10150 bfd_elf32_swap_dyn_in,
10151 bfd_elf32_swap_dyn_out,
10152 bfd_elf32_swap_reloc_in,
10153 bfd_elf32_swap_reloc_out,
10154 bfd_elf32_swap_reloca_in,
10155 bfd_elf32_swap_reloca_out
10156};
10157
252b5132
RH
10158#define ELF_ARCH bfd_arch_arm
10159#define ELF_MACHINE_CODE EM_ARM
d0facd1b
NC
10160#ifdef __QNXTARGET__
10161#define ELF_MAXPAGESIZE 0x1000
10162#else
f21f3fe0 10163#define ELF_MAXPAGESIZE 0x8000
d0facd1b 10164#endif
b1342370 10165#define ELF_MINPAGESIZE 0x1000
24718e3b 10166#define ELF_COMMONPAGESIZE 0x1000
252b5132 10167
ba93b8ac
DJ
10168#define bfd_elf32_mkobject elf32_arm_mkobject
10169
99e4ae17
AJ
10170#define bfd_elf32_bfd_copy_private_bfd_data elf32_arm_copy_private_bfd_data
10171#define bfd_elf32_bfd_merge_private_bfd_data elf32_arm_merge_private_bfd_data
252b5132
RH
10172#define bfd_elf32_bfd_set_private_flags elf32_arm_set_private_flags
10173#define bfd_elf32_bfd_print_private_bfd_data elf32_arm_print_private_bfd_data
10174#define bfd_elf32_bfd_link_hash_table_create elf32_arm_link_hash_table_create
dc810e39 10175#define bfd_elf32_bfd_reloc_type_lookup elf32_arm_reloc_type_lookup
157090f7 10176#define bfd_elf32_bfd_reloc_name_lookup elf32_arm_reloc_name_lookup
252b5132 10177#define bfd_elf32_find_nearest_line elf32_arm_find_nearest_line
4ab527b0 10178#define bfd_elf32_find_inliner_info elf32_arm_find_inliner_info
e489d0ae 10179#define bfd_elf32_new_section_hook elf32_arm_new_section_hook
3c9458e9 10180#define bfd_elf32_bfd_is_target_special_symbol elf32_arm_is_target_special_symbol
957c6e41 10181#define bfd_elf32_close_and_cleanup elf32_arm_close_and_cleanup
b25e3d87 10182#define bfd_elf32_bfd_free_cached_info elf32_arm_bfd_free_cached_info
252b5132
RH
10183
10184#define elf_backend_get_symbol_type elf32_arm_get_symbol_type
10185#define elf_backend_gc_mark_hook elf32_arm_gc_mark_hook
6a5bb875 10186#define elf_backend_gc_mark_extra_sections elf32_arm_gc_mark_extra_sections
252b5132
RH
10187#define elf_backend_gc_sweep_hook elf32_arm_gc_sweep_hook
10188#define elf_backend_check_relocs elf32_arm_check_relocs
dc810e39 10189#define elf_backend_relocate_section elf32_arm_relocate_section
e489d0ae 10190#define elf_backend_write_section elf32_arm_write_section
252b5132 10191#define elf_backend_adjust_dynamic_symbol elf32_arm_adjust_dynamic_symbol
5e681ec4 10192#define elf_backend_create_dynamic_sections elf32_arm_create_dynamic_sections
252b5132
RH
10193#define elf_backend_finish_dynamic_symbol elf32_arm_finish_dynamic_symbol
10194#define elf_backend_finish_dynamic_sections elf32_arm_finish_dynamic_sections
10195#define elf_backend_size_dynamic_sections elf32_arm_size_dynamic_sections
74541ad4 10196#define elf_backend_init_index_section _bfd_elf_init_2_index_sections
ba96a88f 10197#define elf_backend_post_process_headers elf32_arm_post_process_headers
99e4ae17 10198#define elf_backend_reloc_type_class elf32_arm_reloc_type_class
c178919b 10199#define elf_backend_object_p elf32_arm_object_p
e16bb312 10200#define elf_backend_section_flags elf32_arm_section_flags
40a18ebd
NC
10201#define elf_backend_fake_sections elf32_arm_fake_sections
10202#define elf_backend_section_from_shdr elf32_arm_section_from_shdr
e16bb312 10203#define elf_backend_final_write_processing elf32_arm_final_write_processing
5e681ec4 10204#define elf_backend_copy_indirect_symbol elf32_arm_copy_indirect_symbol
b7693d02 10205#define elf_backend_symbol_processing elf32_arm_symbol_processing
0beaef2b 10206#define elf_backend_size_info elf32_arm_size_info
b294bdf8
MM
10207#define elf_backend_modify_segment_map elf32_arm_modify_segment_map
10208#define elf_backend_additional_program_headers \
10209 elf32_arm_additional_program_headers
4e617b1e
PB
10210#define elf_backend_output_arch_local_syms \
10211 elf32_arm_output_arch_local_syms
a4fd1a8e
PB
10212#define elf_backend_begin_write_processing \
10213 elf32_arm_begin_write_processing
fcb93ecf 10214#define elf_backend_is_function_type elf32_arm_is_function_type
252b5132 10215
5e681ec4 10216#define elf_backend_can_refcount 1
252b5132
RH
10217#define elf_backend_can_gc_sections 1
10218#define elf_backend_plt_readonly 1
10219#define elf_backend_want_got_plt 1
10220#define elf_backend_want_plt_sym 0
4e7fd91e
PB
10221#define elf_backend_may_use_rel_p 1
10222#define elf_backend_may_use_rela_p 0
10223#define elf_backend_default_use_rela_p 0
252b5132 10224
04f7c78d 10225#define elf_backend_got_header_size 12
04f7c78d 10226
104d59d1
JM
10227#undef elf_backend_obj_attrs_vendor
10228#define elf_backend_obj_attrs_vendor "aeabi"
10229#undef elf_backend_obj_attrs_section
10230#define elf_backend_obj_attrs_section ".ARM.attributes"
10231#undef elf_backend_obj_attrs_arg_type
10232#define elf_backend_obj_attrs_arg_type elf32_arm_obj_attrs_arg_type
10233#undef elf_backend_obj_attrs_section_type
10234#define elf_backend_obj_attrs_section_type SHT_ARM_ATTRIBUTES
10235
252b5132 10236#include "elf32-target.h"
7f266840 10237
4e7fd91e
PB
10238/* VxWorks Targets */
10239
10240#undef TARGET_LITTLE_SYM
10241#define TARGET_LITTLE_SYM bfd_elf32_littlearm_vxworks_vec
10242#undef TARGET_LITTLE_NAME
10243#define TARGET_LITTLE_NAME "elf32-littlearm-vxworks"
10244#undef TARGET_BIG_SYM
10245#define TARGET_BIG_SYM bfd_elf32_bigarm_vxworks_vec
10246#undef TARGET_BIG_NAME
10247#define TARGET_BIG_NAME "elf32-bigarm-vxworks"
10248
10249/* Like elf32_arm_link_hash_table_create -- but overrides
10250 appropriately for VxWorks. */
10251static struct bfd_link_hash_table *
10252elf32_arm_vxworks_link_hash_table_create (bfd *abfd)
10253{
10254 struct bfd_link_hash_table *ret;
10255
10256 ret = elf32_arm_link_hash_table_create (abfd);
10257 if (ret)
10258 {
10259 struct elf32_arm_link_hash_table *htab
00a97672 10260 = (struct elf32_arm_link_hash_table *) ret;
4e7fd91e 10261 htab->use_rel = 0;
00a97672 10262 htab->vxworks_p = 1;
4e7fd91e
PB
10263 }
10264 return ret;
10265}
10266
00a97672
RS
10267static void
10268elf32_arm_vxworks_final_write_processing (bfd *abfd, bfd_boolean linker)
10269{
10270 elf32_arm_final_write_processing (abfd, linker);
10271 elf_vxworks_final_write_processing (abfd, linker);
10272}
10273
4e7fd91e
PB
10274#undef elf32_bed
10275#define elf32_bed elf32_arm_vxworks_bed
10276
10277#undef bfd_elf32_bfd_link_hash_table_create
10278#define bfd_elf32_bfd_link_hash_table_create \
10279 elf32_arm_vxworks_link_hash_table_create
00a97672
RS
10280#undef elf_backend_add_symbol_hook
10281#define elf_backend_add_symbol_hook \
10282 elf_vxworks_add_symbol_hook
10283#undef elf_backend_final_write_processing
10284#define elf_backend_final_write_processing \
10285 elf32_arm_vxworks_final_write_processing
10286#undef elf_backend_emit_relocs
10287#define elf_backend_emit_relocs \
10288 elf_vxworks_emit_relocs
4e7fd91e
PB
10289
10290#undef elf_backend_may_use_rel_p
00a97672 10291#define elf_backend_may_use_rel_p 0
4e7fd91e 10292#undef elf_backend_may_use_rela_p
00a97672 10293#define elf_backend_may_use_rela_p 1
4e7fd91e 10294#undef elf_backend_default_use_rela_p
00a97672 10295#define elf_backend_default_use_rela_p 1
00a97672
RS
10296#undef elf_backend_want_plt_sym
10297#define elf_backend_want_plt_sym 1
10298#undef ELF_MAXPAGESIZE
10299#define ELF_MAXPAGESIZE 0x1000
4e7fd91e
PB
10300
10301#include "elf32-target.h"
10302
10303
7f266840
DJ
10304/* Symbian OS Targets */
10305
10306#undef TARGET_LITTLE_SYM
10307#define TARGET_LITTLE_SYM bfd_elf32_littlearm_symbian_vec
10308#undef TARGET_LITTLE_NAME
10309#define TARGET_LITTLE_NAME "elf32-littlearm-symbian"
10310#undef TARGET_BIG_SYM
10311#define TARGET_BIG_SYM bfd_elf32_bigarm_symbian_vec
10312#undef TARGET_BIG_NAME
10313#define TARGET_BIG_NAME "elf32-bigarm-symbian"
10314
10315/* Like elf32_arm_link_hash_table_create -- but overrides
10316 appropriately for Symbian OS. */
10317static struct bfd_link_hash_table *
10318elf32_arm_symbian_link_hash_table_create (bfd *abfd)
10319{
10320 struct bfd_link_hash_table *ret;
10321
10322 ret = elf32_arm_link_hash_table_create (abfd);
10323 if (ret)
10324 {
10325 struct elf32_arm_link_hash_table *htab
10326 = (struct elf32_arm_link_hash_table *)ret;
10327 /* There is no PLT header for Symbian OS. */
10328 htab->plt_header_size = 0;
10329 /* The PLT entries are each three instructions. */
10330 htab->plt_entry_size = 4 * NUM_ELEM (elf32_arm_symbian_plt_entry);
10331 htab->symbian_p = 1;
33bfe774
JB
10332 /* Symbian uses armv5t or above, so use_blx is always true. */
10333 htab->use_blx = 1;
67687978 10334 htab->root.is_relocatable_executable = 1;
7f266840
DJ
10335 }
10336 return ret;
10337}
10338
b35d266b 10339static const struct bfd_elf_special_section
551b43fd 10340elf32_arm_symbian_special_sections[] =
7f266840 10341{
5cd3778d
MM
10342 /* In a BPABI executable, the dynamic linking sections do not go in
10343 the loadable read-only segment. The post-linker may wish to
10344 refer to these sections, but they are not part of the final
10345 program image. */
0112cd26
NC
10346 { STRING_COMMA_LEN (".dynamic"), 0, SHT_DYNAMIC, 0 },
10347 { STRING_COMMA_LEN (".dynstr"), 0, SHT_STRTAB, 0 },
10348 { STRING_COMMA_LEN (".dynsym"), 0, SHT_DYNSYM, 0 },
10349 { STRING_COMMA_LEN (".got"), 0, SHT_PROGBITS, 0 },
10350 { STRING_COMMA_LEN (".hash"), 0, SHT_HASH, 0 },
5cd3778d
MM
10351 /* These sections do not need to be writable as the SymbianOS
10352 postlinker will arrange things so that no dynamic relocation is
10353 required. */
0112cd26
NC
10354 { STRING_COMMA_LEN (".init_array"), 0, SHT_INIT_ARRAY, SHF_ALLOC },
10355 { STRING_COMMA_LEN (".fini_array"), 0, SHT_FINI_ARRAY, SHF_ALLOC },
10356 { STRING_COMMA_LEN (".preinit_array"), 0, SHT_PREINIT_ARRAY, SHF_ALLOC },
10357 { NULL, 0, 0, 0, 0 }
7f266840
DJ
10358};
10359
c3c76620 10360static void
b34af79c 10361elf32_arm_symbian_begin_write_processing (bfd *abfd,
a4fd1a8e 10362 struct bfd_link_info *link_info)
c3c76620
MM
10363{
10364 /* BPABI objects are never loaded directly by an OS kernel; they are
10365 processed by a postlinker first, into an OS-specific format. If
10366 the D_PAGED bit is set on the file, BFD will align segments on
10367 page boundaries, so that an OS can directly map the file. With
10368 BPABI objects, that just results in wasted space. In addition,
10369 because we clear the D_PAGED bit, map_sections_to_segments will
10370 recognize that the program headers should not be mapped into any
10371 loadable segment. */
10372 abfd->flags &= ~D_PAGED;
a4fd1a8e 10373 elf32_arm_begin_write_processing(abfd, link_info);
c3c76620 10374}
7f266840
DJ
10375
10376static bfd_boolean
b34af79c 10377elf32_arm_symbian_modify_segment_map (bfd *abfd,
b294bdf8 10378 struct bfd_link_info *info)
7f266840
DJ
10379{
10380 struct elf_segment_map *m;
10381 asection *dynsec;
10382
7f266840
DJ
10383 /* BPABI shared libraries and executables should have a PT_DYNAMIC
10384 segment. However, because the .dynamic section is not marked
10385 with SEC_LOAD, the generic ELF code will not create such a
10386 segment. */
10387 dynsec = bfd_get_section_by_name (abfd, ".dynamic");
10388 if (dynsec)
10389 {
8ded5a0f
AM
10390 for (m = elf_tdata (abfd)->segment_map; m != NULL; m = m->next)
10391 if (m->p_type == PT_DYNAMIC)
10392 break;
10393
10394 if (m == NULL)
10395 {
10396 m = _bfd_elf_make_dynamic_segment (abfd, dynsec);
10397 m->next = elf_tdata (abfd)->segment_map;
10398 elf_tdata (abfd)->segment_map = m;
10399 }
7f266840
DJ
10400 }
10401
b294bdf8
MM
10402 /* Also call the generic arm routine. */
10403 return elf32_arm_modify_segment_map (abfd, info);
7f266840
DJ
10404}
10405
10406#undef elf32_bed
10407#define elf32_bed elf32_arm_symbian_bed
10408
10409/* The dynamic sections are not allocated on SymbianOS; the postlinker
10410 will process them and then discard them. */
10411#undef ELF_DYNAMIC_SEC_FLAGS
10412#define ELF_DYNAMIC_SEC_FLAGS \
10413 (SEC_HAS_CONTENTS | SEC_IN_MEMORY | SEC_LINKER_CREATED)
10414
10415#undef bfd_elf32_bfd_link_hash_table_create
10416#define bfd_elf32_bfd_link_hash_table_create \
10417 elf32_arm_symbian_link_hash_table_create
00a97672 10418#undef elf_backend_add_symbol_hook
7f266840 10419
29ef7005
L
10420#undef elf_backend_special_sections
10421#define elf_backend_special_sections elf32_arm_symbian_special_sections
7f266840 10422
c3c76620
MM
10423#undef elf_backend_begin_write_processing
10424#define elf_backend_begin_write_processing \
10425 elf32_arm_symbian_begin_write_processing
00a97672
RS
10426#undef elf_backend_final_write_processing
10427#define elf_backend_final_write_processing \
10428 elf32_arm_final_write_processing
10429#undef elf_backend_emit_relocs
c3c76620 10430
7f266840
DJ
10431#undef elf_backend_modify_segment_map
10432#define elf_backend_modify_segment_map elf32_arm_symbian_modify_segment_map
10433
10434/* There is no .got section for BPABI objects, and hence no header. */
10435#undef elf_backend_got_header_size
10436#define elf_backend_got_header_size 0
10437
10438/* Similarly, there is no .got.plt section. */
10439#undef elf_backend_want_got_plt
10440#define elf_backend_want_got_plt 0
10441
4e7fd91e 10442#undef elf_backend_may_use_rel_p
00a97672 10443#define elf_backend_may_use_rel_p 1
4e7fd91e 10444#undef elf_backend_may_use_rela_p
00a97672 10445#define elf_backend_may_use_rela_p 0
4e7fd91e 10446#undef elf_backend_default_use_rela_p
00a97672 10447#define elf_backend_default_use_rela_p 0
00a97672
RS
10448#undef elf_backend_want_plt_sym
10449#define elf_backend_want_plt_sym 0
10450#undef ELF_MAXPAGESIZE
10451#define ELF_MAXPAGESIZE 0x8000
4e7fd91e 10452
7f266840 10453#include "elf32-target.h"