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