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