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