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