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