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