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