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