* elf_hppa_add_symbol_hook (elf_hppa_add_symbol_hook): Move to
[deliverable/binutils-gdb.git] / bfd / elf32-arm.c
CommitLineData
252b5132 1/* 32-bit ELF support for ARM
e44a2c9c
AM
2 Copyright 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007,
3 2008 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
cd123cb7 9 the Free Software Foundation; either version 3 of the License, or
252b5132
RH
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
cd123cb7
NC
19 Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
20 MA 02110-1301, USA. */
252b5132 21
7f266840 22#include "sysdep.h"
3db64b00 23#include "bfd.h"
00a97672 24#include "libiberty.h"
7f266840
DJ
25#include "libbfd.h"
26#include "elf-bfd.h"
00a97672 27#include "elf-vxworks.h"
ee065d83 28#include "elf/arm.h"
7f266840 29
00a97672
RS
30/* Return the relocation section associated with NAME. HTAB is the
31 bfd's elf32_arm_link_hash_entry. */
32#define RELOC_SECTION(HTAB, NAME) \
33 ((HTAB)->use_rel ? ".rel" NAME : ".rela" NAME)
34
35/* Return size of a relocation entry. HTAB is the bfd's
36 elf32_arm_link_hash_entry. */
37#define RELOC_SIZE(HTAB) \
38 ((HTAB)->use_rel \
39 ? sizeof (Elf32_External_Rel) \
40 : sizeof (Elf32_External_Rela))
41
42/* Return function to swap relocations in. HTAB is the bfd's
43 elf32_arm_link_hash_entry. */
44#define SWAP_RELOC_IN(HTAB) \
45 ((HTAB)->use_rel \
46 ? bfd_elf32_swap_reloc_in \
47 : bfd_elf32_swap_reloca_in)
48
49/* Return function to swap relocations out. HTAB is the bfd's
50 elf32_arm_link_hash_entry. */
51#define SWAP_RELOC_OUT(HTAB) \
52 ((HTAB)->use_rel \
53 ? bfd_elf32_swap_reloc_out \
54 : bfd_elf32_swap_reloca_out)
55
7f266840
DJ
56#define elf_info_to_howto 0
57#define elf_info_to_howto_rel elf32_arm_info_to_howto
58
59#define ARM_ELF_ABI_VERSION 0
60#define ARM_ELF_OS_ABI_VERSION ELFOSABI_ARM
61
24718e3b 62static struct elf_backend_data elf32_arm_vxworks_bed;
00a97672 63
7f266840
DJ
64/* Note: code such as elf32_arm_reloc_type_lookup expect to use e.g.
65 R_ARM_PC24 as an index into this, and find the R_ARM_PC24 HOWTO
66 in that slot. */
67
c19d1205 68static reloc_howto_type elf32_arm_howto_table_1[] =
7f266840 69{
8029a119 70 /* No relocation. */
7f266840
DJ
71 HOWTO (R_ARM_NONE, /* type */
72 0, /* rightshift */
73 0, /* size (0 = byte, 1 = short, 2 = long) */
74 0, /* bitsize */
75 FALSE, /* pc_relative */
76 0, /* bitpos */
77 complain_overflow_dont,/* complain_on_overflow */
78 bfd_elf_generic_reloc, /* special_function */
79 "R_ARM_NONE", /* name */
80 FALSE, /* partial_inplace */
81 0, /* src_mask */
82 0, /* dst_mask */
83 FALSE), /* pcrel_offset */
84
85 HOWTO (R_ARM_PC24, /* type */
86 2, /* rightshift */
87 2, /* size (0 = byte, 1 = short, 2 = long) */
88 24, /* bitsize */
89 TRUE, /* pc_relative */
90 0, /* bitpos */
91 complain_overflow_signed,/* complain_on_overflow */
92 bfd_elf_generic_reloc, /* special_function */
93 "R_ARM_PC24", /* name */
94 FALSE, /* partial_inplace */
95 0x00ffffff, /* src_mask */
96 0x00ffffff, /* dst_mask */
97 TRUE), /* pcrel_offset */
98
99 /* 32 bit absolute */
100 HOWTO (R_ARM_ABS32, /* type */
101 0, /* rightshift */
102 2, /* size (0 = byte, 1 = short, 2 = long) */
103 32, /* bitsize */
104 FALSE, /* pc_relative */
105 0, /* bitpos */
106 complain_overflow_bitfield,/* complain_on_overflow */
107 bfd_elf_generic_reloc, /* special_function */
108 "R_ARM_ABS32", /* name */
109 FALSE, /* partial_inplace */
110 0xffffffff, /* src_mask */
111 0xffffffff, /* dst_mask */
112 FALSE), /* pcrel_offset */
113
114 /* standard 32bit pc-relative reloc */
115 HOWTO (R_ARM_REL32, /* type */
116 0, /* rightshift */
117 2, /* size (0 = byte, 1 = short, 2 = long) */
118 32, /* bitsize */
119 TRUE, /* pc_relative */
120 0, /* bitpos */
121 complain_overflow_bitfield,/* complain_on_overflow */
122 bfd_elf_generic_reloc, /* special_function */
123 "R_ARM_REL32", /* name */
124 FALSE, /* partial_inplace */
125 0xffffffff, /* src_mask */
126 0xffffffff, /* dst_mask */
127 TRUE), /* pcrel_offset */
128
c19d1205 129 /* 8 bit absolute - R_ARM_LDR_PC_G0 in AAELF */
4962c51a 130 HOWTO (R_ARM_LDR_PC_G0, /* type */
7f266840
DJ
131 0, /* rightshift */
132 0, /* size (0 = byte, 1 = short, 2 = long) */
4962c51a
MS
133 32, /* bitsize */
134 TRUE, /* pc_relative */
7f266840 135 0, /* bitpos */
4962c51a 136 complain_overflow_dont,/* complain_on_overflow */
7f266840 137 bfd_elf_generic_reloc, /* special_function */
4962c51a 138 "R_ARM_LDR_PC_G0", /* name */
7f266840 139 FALSE, /* partial_inplace */
4962c51a
MS
140 0xffffffff, /* src_mask */
141 0xffffffff, /* dst_mask */
142 TRUE), /* pcrel_offset */
7f266840
DJ
143
144 /* 16 bit absolute */
145 HOWTO (R_ARM_ABS16, /* type */
146 0, /* rightshift */
147 1, /* size (0 = byte, 1 = short, 2 = long) */
148 16, /* bitsize */
149 FALSE, /* pc_relative */
150 0, /* bitpos */
151 complain_overflow_bitfield,/* complain_on_overflow */
152 bfd_elf_generic_reloc, /* special_function */
153 "R_ARM_ABS16", /* name */
154 FALSE, /* partial_inplace */
155 0x0000ffff, /* src_mask */
156 0x0000ffff, /* dst_mask */
157 FALSE), /* pcrel_offset */
158
159 /* 12 bit absolute */
160 HOWTO (R_ARM_ABS12, /* type */
161 0, /* rightshift */
162 2, /* size (0 = byte, 1 = short, 2 = long) */
163 12, /* bitsize */
164 FALSE, /* pc_relative */
165 0, /* bitpos */
166 complain_overflow_bitfield,/* complain_on_overflow */
167 bfd_elf_generic_reloc, /* special_function */
168 "R_ARM_ABS12", /* name */
169 FALSE, /* partial_inplace */
00a97672
RS
170 0x00000fff, /* src_mask */
171 0x00000fff, /* dst_mask */
7f266840
DJ
172 FALSE), /* pcrel_offset */
173
174 HOWTO (R_ARM_THM_ABS5, /* type */
175 6, /* rightshift */
176 1, /* size (0 = byte, 1 = short, 2 = long) */
177 5, /* bitsize */
178 FALSE, /* pc_relative */
179 0, /* bitpos */
180 complain_overflow_bitfield,/* complain_on_overflow */
181 bfd_elf_generic_reloc, /* special_function */
182 "R_ARM_THM_ABS5", /* name */
183 FALSE, /* partial_inplace */
184 0x000007e0, /* src_mask */
185 0x000007e0, /* dst_mask */
186 FALSE), /* pcrel_offset */
187
188 /* 8 bit absolute */
189 HOWTO (R_ARM_ABS8, /* type */
190 0, /* rightshift */
191 0, /* size (0 = byte, 1 = short, 2 = long) */
192 8, /* bitsize */
193 FALSE, /* pc_relative */
194 0, /* bitpos */
195 complain_overflow_bitfield,/* complain_on_overflow */
196 bfd_elf_generic_reloc, /* special_function */
197 "R_ARM_ABS8", /* name */
198 FALSE, /* partial_inplace */
199 0x000000ff, /* src_mask */
200 0x000000ff, /* dst_mask */
201 FALSE), /* pcrel_offset */
202
203 HOWTO (R_ARM_SBREL32, /* type */
204 0, /* rightshift */
205 2, /* size (0 = byte, 1 = short, 2 = long) */
206 32, /* bitsize */
207 FALSE, /* pc_relative */
208 0, /* bitpos */
209 complain_overflow_dont,/* complain_on_overflow */
210 bfd_elf_generic_reloc, /* special_function */
211 "R_ARM_SBREL32", /* name */
212 FALSE, /* partial_inplace */
213 0xffffffff, /* src_mask */
214 0xffffffff, /* dst_mask */
215 FALSE), /* pcrel_offset */
216
c19d1205 217 HOWTO (R_ARM_THM_CALL, /* type */
7f266840
DJ
218 1, /* rightshift */
219 2, /* size (0 = byte, 1 = short, 2 = long) */
e95de063 220 25, /* bitsize */
7f266840
DJ
221 TRUE, /* pc_relative */
222 0, /* bitpos */
223 complain_overflow_signed,/* complain_on_overflow */
224 bfd_elf_generic_reloc, /* special_function */
c19d1205 225 "R_ARM_THM_CALL", /* name */
7f266840
DJ
226 FALSE, /* partial_inplace */
227 0x07ff07ff, /* src_mask */
228 0x07ff07ff, /* dst_mask */
229 TRUE), /* pcrel_offset */
230
231 HOWTO (R_ARM_THM_PC8, /* type */
232 1, /* rightshift */
233 1, /* size (0 = byte, 1 = short, 2 = long) */
234 8, /* bitsize */
235 TRUE, /* pc_relative */
236 0, /* bitpos */
237 complain_overflow_signed,/* complain_on_overflow */
238 bfd_elf_generic_reloc, /* special_function */
239 "R_ARM_THM_PC8", /* name */
240 FALSE, /* partial_inplace */
241 0x000000ff, /* src_mask */
242 0x000000ff, /* dst_mask */
243 TRUE), /* pcrel_offset */
244
c19d1205 245 HOWTO (R_ARM_BREL_ADJ, /* type */
7f266840
DJ
246 1, /* rightshift */
247 1, /* size (0 = byte, 1 = short, 2 = long) */
c19d1205
ZW
248 32, /* bitsize */
249 FALSE, /* pc_relative */
7f266840
DJ
250 0, /* bitpos */
251 complain_overflow_signed,/* complain_on_overflow */
252 bfd_elf_generic_reloc, /* special_function */
c19d1205 253 "R_ARM_BREL_ADJ", /* name */
7f266840 254 FALSE, /* partial_inplace */
c19d1205
ZW
255 0xffffffff, /* src_mask */
256 0xffffffff, /* dst_mask */
257 FALSE), /* pcrel_offset */
7f266840
DJ
258
259 HOWTO (R_ARM_SWI24, /* type */
260 0, /* rightshift */
261 0, /* size (0 = byte, 1 = short, 2 = long) */
262 0, /* bitsize */
263 FALSE, /* pc_relative */
264 0, /* bitpos */
265 complain_overflow_signed,/* complain_on_overflow */
266 bfd_elf_generic_reloc, /* special_function */
267 "R_ARM_SWI24", /* name */
268 FALSE, /* partial_inplace */
269 0x00000000, /* src_mask */
270 0x00000000, /* dst_mask */
271 FALSE), /* pcrel_offset */
272
273 HOWTO (R_ARM_THM_SWI8, /* type */
274 0, /* rightshift */
275 0, /* size (0 = byte, 1 = short, 2 = long) */
276 0, /* bitsize */
277 FALSE, /* pc_relative */
278 0, /* bitpos */
279 complain_overflow_signed,/* complain_on_overflow */
280 bfd_elf_generic_reloc, /* special_function */
281 "R_ARM_SWI8", /* name */
282 FALSE, /* partial_inplace */
283 0x00000000, /* src_mask */
284 0x00000000, /* dst_mask */
285 FALSE), /* pcrel_offset */
286
287 /* BLX instruction for the ARM. */
288 HOWTO (R_ARM_XPC25, /* type */
289 2, /* rightshift */
290 2, /* size (0 = byte, 1 = short, 2 = long) */
291 25, /* bitsize */
292 TRUE, /* pc_relative */
293 0, /* bitpos */
294 complain_overflow_signed,/* complain_on_overflow */
295 bfd_elf_generic_reloc, /* special_function */
296 "R_ARM_XPC25", /* name */
297 FALSE, /* partial_inplace */
298 0x00ffffff, /* src_mask */
299 0x00ffffff, /* dst_mask */
300 TRUE), /* pcrel_offset */
301
302 /* BLX instruction for the Thumb. */
303 HOWTO (R_ARM_THM_XPC22, /* type */
304 2, /* rightshift */
305 2, /* size (0 = byte, 1 = short, 2 = long) */
306 22, /* bitsize */
307 TRUE, /* pc_relative */
308 0, /* bitpos */
309 complain_overflow_signed,/* complain_on_overflow */
310 bfd_elf_generic_reloc, /* special_function */
311 "R_ARM_THM_XPC22", /* name */
312 FALSE, /* partial_inplace */
313 0x07ff07ff, /* src_mask */
314 0x07ff07ff, /* dst_mask */
315 TRUE), /* pcrel_offset */
316
ba93b8ac 317 /* Dynamic TLS relocations. */
7f266840 318
ba93b8ac
DJ
319 HOWTO (R_ARM_TLS_DTPMOD32, /* type */
320 0, /* rightshift */
321 2, /* size (0 = byte, 1 = short, 2 = long) */
322 32, /* bitsize */
323 FALSE, /* pc_relative */
324 0, /* bitpos */
325 complain_overflow_bitfield,/* complain_on_overflow */
326 bfd_elf_generic_reloc, /* special_function */
327 "R_ARM_TLS_DTPMOD32", /* name */
328 TRUE, /* partial_inplace */
329 0xffffffff, /* src_mask */
330 0xffffffff, /* dst_mask */
331 FALSE), /* pcrel_offset */
7f266840 332
ba93b8ac
DJ
333 HOWTO (R_ARM_TLS_DTPOFF32, /* type */
334 0, /* rightshift */
335 2, /* size (0 = byte, 1 = short, 2 = long) */
336 32, /* bitsize */
337 FALSE, /* pc_relative */
338 0, /* bitpos */
339 complain_overflow_bitfield,/* complain_on_overflow */
340 bfd_elf_generic_reloc, /* special_function */
341 "R_ARM_TLS_DTPOFF32", /* name */
342 TRUE, /* partial_inplace */
343 0xffffffff, /* src_mask */
344 0xffffffff, /* dst_mask */
345 FALSE), /* pcrel_offset */
7f266840 346
ba93b8ac
DJ
347 HOWTO (R_ARM_TLS_TPOFF32, /* type */
348 0, /* rightshift */
349 2, /* size (0 = byte, 1 = short, 2 = long) */
350 32, /* bitsize */
351 FALSE, /* pc_relative */
352 0, /* bitpos */
353 complain_overflow_bitfield,/* complain_on_overflow */
354 bfd_elf_generic_reloc, /* special_function */
355 "R_ARM_TLS_TPOFF32", /* name */
356 TRUE, /* partial_inplace */
357 0xffffffff, /* src_mask */
358 0xffffffff, /* dst_mask */
359 FALSE), /* pcrel_offset */
7f266840
DJ
360
361 /* Relocs used in ARM Linux */
362
363 HOWTO (R_ARM_COPY, /* type */
364 0, /* rightshift */
365 2, /* size (0 = byte, 1 = short, 2 = long) */
366 32, /* bitsize */
367 FALSE, /* pc_relative */
368 0, /* bitpos */
369 complain_overflow_bitfield,/* complain_on_overflow */
370 bfd_elf_generic_reloc, /* special_function */
371 "R_ARM_COPY", /* name */
372 TRUE, /* partial_inplace */
373 0xffffffff, /* src_mask */
374 0xffffffff, /* dst_mask */
375 FALSE), /* pcrel_offset */
376
377 HOWTO (R_ARM_GLOB_DAT, /* type */
378 0, /* rightshift */
379 2, /* size (0 = byte, 1 = short, 2 = long) */
380 32, /* bitsize */
381 FALSE, /* pc_relative */
382 0, /* bitpos */
383 complain_overflow_bitfield,/* complain_on_overflow */
384 bfd_elf_generic_reloc, /* special_function */
385 "R_ARM_GLOB_DAT", /* name */
386 TRUE, /* partial_inplace */
387 0xffffffff, /* src_mask */
388 0xffffffff, /* dst_mask */
389 FALSE), /* pcrel_offset */
390
391 HOWTO (R_ARM_JUMP_SLOT, /* type */
392 0, /* rightshift */
393 2, /* size (0 = byte, 1 = short, 2 = long) */
394 32, /* bitsize */
395 FALSE, /* pc_relative */
396 0, /* bitpos */
397 complain_overflow_bitfield,/* complain_on_overflow */
398 bfd_elf_generic_reloc, /* special_function */
399 "R_ARM_JUMP_SLOT", /* name */
400 TRUE, /* partial_inplace */
401 0xffffffff, /* src_mask */
402 0xffffffff, /* dst_mask */
403 FALSE), /* pcrel_offset */
404
405 HOWTO (R_ARM_RELATIVE, /* type */
406 0, /* rightshift */
407 2, /* size (0 = byte, 1 = short, 2 = long) */
408 32, /* bitsize */
409 FALSE, /* pc_relative */
410 0, /* bitpos */
411 complain_overflow_bitfield,/* complain_on_overflow */
412 bfd_elf_generic_reloc, /* special_function */
413 "R_ARM_RELATIVE", /* name */
414 TRUE, /* partial_inplace */
415 0xffffffff, /* src_mask */
416 0xffffffff, /* dst_mask */
417 FALSE), /* pcrel_offset */
418
c19d1205 419 HOWTO (R_ARM_GOTOFF32, /* type */
7f266840
DJ
420 0, /* rightshift */
421 2, /* size (0 = byte, 1 = short, 2 = long) */
422 32, /* bitsize */
423 FALSE, /* pc_relative */
424 0, /* bitpos */
425 complain_overflow_bitfield,/* complain_on_overflow */
426 bfd_elf_generic_reloc, /* special_function */
c19d1205 427 "R_ARM_GOTOFF32", /* name */
7f266840
DJ
428 TRUE, /* partial_inplace */
429 0xffffffff, /* src_mask */
430 0xffffffff, /* dst_mask */
431 FALSE), /* pcrel_offset */
432
433 HOWTO (R_ARM_GOTPC, /* type */
434 0, /* rightshift */
435 2, /* size (0 = byte, 1 = short, 2 = long) */
436 32, /* bitsize */
437 TRUE, /* pc_relative */
438 0, /* bitpos */
439 complain_overflow_bitfield,/* complain_on_overflow */
440 bfd_elf_generic_reloc, /* special_function */
441 "R_ARM_GOTPC", /* name */
442 TRUE, /* partial_inplace */
443 0xffffffff, /* src_mask */
444 0xffffffff, /* dst_mask */
445 TRUE), /* pcrel_offset */
446
447 HOWTO (R_ARM_GOT32, /* type */
448 0, /* rightshift */
449 2, /* size (0 = byte, 1 = short, 2 = long) */
450 32, /* bitsize */
451 FALSE, /* pc_relative */
452 0, /* bitpos */
453 complain_overflow_bitfield,/* complain_on_overflow */
454 bfd_elf_generic_reloc, /* special_function */
455 "R_ARM_GOT32", /* name */
456 TRUE, /* partial_inplace */
457 0xffffffff, /* src_mask */
458 0xffffffff, /* dst_mask */
459 FALSE), /* pcrel_offset */
460
461 HOWTO (R_ARM_PLT32, /* type */
462 2, /* rightshift */
463 2, /* size (0 = byte, 1 = short, 2 = long) */
ce490eda 464 24, /* bitsize */
7f266840
DJ
465 TRUE, /* pc_relative */
466 0, /* bitpos */
467 complain_overflow_bitfield,/* complain_on_overflow */
468 bfd_elf_generic_reloc, /* special_function */
469 "R_ARM_PLT32", /* name */
ce490eda 470 FALSE, /* partial_inplace */
7f266840
DJ
471 0x00ffffff, /* src_mask */
472 0x00ffffff, /* dst_mask */
473 TRUE), /* pcrel_offset */
474
475 HOWTO (R_ARM_CALL, /* type */
476 2, /* rightshift */
477 2, /* size (0 = byte, 1 = short, 2 = long) */
478 24, /* bitsize */
479 TRUE, /* pc_relative */
480 0, /* bitpos */
481 complain_overflow_signed,/* complain_on_overflow */
482 bfd_elf_generic_reloc, /* special_function */
483 "R_ARM_CALL", /* name */
484 FALSE, /* partial_inplace */
485 0x00ffffff, /* src_mask */
486 0x00ffffff, /* dst_mask */
487 TRUE), /* pcrel_offset */
488
489 HOWTO (R_ARM_JUMP24, /* type */
490 2, /* rightshift */
491 2, /* size (0 = byte, 1 = short, 2 = long) */
492 24, /* bitsize */
493 TRUE, /* pc_relative */
494 0, /* bitpos */
495 complain_overflow_signed,/* complain_on_overflow */
496 bfd_elf_generic_reloc, /* special_function */
497 "R_ARM_JUMP24", /* name */
498 FALSE, /* partial_inplace */
499 0x00ffffff, /* src_mask */
500 0x00ffffff, /* dst_mask */
501 TRUE), /* pcrel_offset */
502
c19d1205
ZW
503 HOWTO (R_ARM_THM_JUMP24, /* type */
504 1, /* rightshift */
505 2, /* size (0 = byte, 1 = short, 2 = long) */
506 24, /* bitsize */
507 TRUE, /* pc_relative */
7f266840 508 0, /* bitpos */
c19d1205 509 complain_overflow_signed,/* complain_on_overflow */
7f266840 510 bfd_elf_generic_reloc, /* special_function */
c19d1205 511 "R_ARM_THM_JUMP24", /* name */
7f266840 512 FALSE, /* partial_inplace */
c19d1205
ZW
513 0x07ff2fff, /* src_mask */
514 0x07ff2fff, /* dst_mask */
515 TRUE), /* pcrel_offset */
7f266840 516
c19d1205 517 HOWTO (R_ARM_BASE_ABS, /* type */
7f266840 518 0, /* rightshift */
c19d1205
ZW
519 2, /* size (0 = byte, 1 = short, 2 = long) */
520 32, /* bitsize */
7f266840
DJ
521 FALSE, /* pc_relative */
522 0, /* bitpos */
523 complain_overflow_dont,/* complain_on_overflow */
524 bfd_elf_generic_reloc, /* special_function */
c19d1205 525 "R_ARM_BASE_ABS", /* name */
7f266840 526 FALSE, /* partial_inplace */
c19d1205
ZW
527 0xffffffff, /* src_mask */
528 0xffffffff, /* dst_mask */
7f266840
DJ
529 FALSE), /* pcrel_offset */
530
531 HOWTO (R_ARM_ALU_PCREL7_0, /* type */
532 0, /* rightshift */
533 2, /* size (0 = byte, 1 = short, 2 = long) */
534 12, /* bitsize */
535 TRUE, /* pc_relative */
536 0, /* bitpos */
537 complain_overflow_dont,/* complain_on_overflow */
538 bfd_elf_generic_reloc, /* special_function */
539 "R_ARM_ALU_PCREL_7_0", /* name */
540 FALSE, /* partial_inplace */
541 0x00000fff, /* src_mask */
542 0x00000fff, /* dst_mask */
543 TRUE), /* pcrel_offset */
544
545 HOWTO (R_ARM_ALU_PCREL15_8, /* type */
546 0, /* rightshift */
547 2, /* size (0 = byte, 1 = short, 2 = long) */
548 12, /* bitsize */
549 TRUE, /* pc_relative */
550 8, /* bitpos */
551 complain_overflow_dont,/* complain_on_overflow */
552 bfd_elf_generic_reloc, /* special_function */
553 "R_ARM_ALU_PCREL_15_8",/* name */
554 FALSE, /* partial_inplace */
555 0x00000fff, /* src_mask */
556 0x00000fff, /* dst_mask */
557 TRUE), /* pcrel_offset */
558
559 HOWTO (R_ARM_ALU_PCREL23_15, /* type */
560 0, /* rightshift */
561 2, /* size (0 = byte, 1 = short, 2 = long) */
562 12, /* bitsize */
563 TRUE, /* pc_relative */
564 16, /* bitpos */
565 complain_overflow_dont,/* complain_on_overflow */
566 bfd_elf_generic_reloc, /* special_function */
567 "R_ARM_ALU_PCREL_23_15",/* name */
568 FALSE, /* partial_inplace */
569 0x00000fff, /* src_mask */
570 0x00000fff, /* dst_mask */
571 TRUE), /* pcrel_offset */
572
573 HOWTO (R_ARM_LDR_SBREL_11_0, /* type */
574 0, /* rightshift */
575 2, /* size (0 = byte, 1 = short, 2 = long) */
576 12, /* bitsize */
577 FALSE, /* pc_relative */
578 0, /* bitpos */
579 complain_overflow_dont,/* complain_on_overflow */
580 bfd_elf_generic_reloc, /* special_function */
581 "R_ARM_LDR_SBREL_11_0",/* name */
582 FALSE, /* partial_inplace */
583 0x00000fff, /* src_mask */
584 0x00000fff, /* dst_mask */
585 FALSE), /* pcrel_offset */
586
587 HOWTO (R_ARM_ALU_SBREL_19_12, /* type */
588 0, /* rightshift */
589 2, /* size (0 = byte, 1 = short, 2 = long) */
590 8, /* bitsize */
591 FALSE, /* pc_relative */
592 12, /* bitpos */
593 complain_overflow_dont,/* complain_on_overflow */
594 bfd_elf_generic_reloc, /* special_function */
595 "R_ARM_ALU_SBREL_19_12",/* name */
596 FALSE, /* partial_inplace */
597 0x000ff000, /* src_mask */
598 0x000ff000, /* dst_mask */
599 FALSE), /* pcrel_offset */
600
601 HOWTO (R_ARM_ALU_SBREL_27_20, /* type */
602 0, /* rightshift */
603 2, /* size (0 = byte, 1 = short, 2 = long) */
604 8, /* bitsize */
605 FALSE, /* pc_relative */
606 20, /* bitpos */
607 complain_overflow_dont,/* complain_on_overflow */
608 bfd_elf_generic_reloc, /* special_function */
609 "R_ARM_ALU_SBREL_27_20",/* name */
610 FALSE, /* partial_inplace */
611 0x0ff00000, /* src_mask */
612 0x0ff00000, /* dst_mask */
613 FALSE), /* pcrel_offset */
614
615 HOWTO (R_ARM_TARGET1, /* type */
616 0, /* rightshift */
617 2, /* size (0 = byte, 1 = short, 2 = long) */
618 32, /* bitsize */
619 FALSE, /* pc_relative */
620 0, /* bitpos */
621 complain_overflow_dont,/* complain_on_overflow */
622 bfd_elf_generic_reloc, /* special_function */
623 "R_ARM_TARGET1", /* name */
624 FALSE, /* partial_inplace */
625 0xffffffff, /* src_mask */
626 0xffffffff, /* dst_mask */
627 FALSE), /* pcrel_offset */
628
629 HOWTO (R_ARM_ROSEGREL32, /* type */
630 0, /* rightshift */
631 2, /* size (0 = byte, 1 = short, 2 = long) */
632 32, /* bitsize */
633 FALSE, /* pc_relative */
634 0, /* bitpos */
635 complain_overflow_dont,/* complain_on_overflow */
636 bfd_elf_generic_reloc, /* special_function */
637 "R_ARM_ROSEGREL32", /* name */
638 FALSE, /* partial_inplace */
639 0xffffffff, /* src_mask */
640 0xffffffff, /* dst_mask */
641 FALSE), /* pcrel_offset */
642
643 HOWTO (R_ARM_V4BX, /* type */
644 0, /* rightshift */
645 2, /* size (0 = byte, 1 = short, 2 = long) */
646 32, /* bitsize */
647 FALSE, /* pc_relative */
648 0, /* bitpos */
649 complain_overflow_dont,/* complain_on_overflow */
650 bfd_elf_generic_reloc, /* special_function */
651 "R_ARM_V4BX", /* name */
652 FALSE, /* partial_inplace */
653 0xffffffff, /* src_mask */
654 0xffffffff, /* dst_mask */
655 FALSE), /* pcrel_offset */
656
657 HOWTO (R_ARM_TARGET2, /* type */
658 0, /* rightshift */
659 2, /* size (0 = byte, 1 = short, 2 = long) */
660 32, /* bitsize */
661 FALSE, /* pc_relative */
662 0, /* bitpos */
663 complain_overflow_signed,/* complain_on_overflow */
664 bfd_elf_generic_reloc, /* special_function */
665 "R_ARM_TARGET2", /* name */
666 FALSE, /* partial_inplace */
667 0xffffffff, /* src_mask */
668 0xffffffff, /* dst_mask */
669 TRUE), /* pcrel_offset */
670
671 HOWTO (R_ARM_PREL31, /* type */
672 0, /* rightshift */
673 2, /* size (0 = byte, 1 = short, 2 = long) */
674 31, /* bitsize */
675 TRUE, /* pc_relative */
676 0, /* bitpos */
677 complain_overflow_signed,/* complain_on_overflow */
678 bfd_elf_generic_reloc, /* special_function */
679 "R_ARM_PREL31", /* name */
680 FALSE, /* partial_inplace */
681 0x7fffffff, /* src_mask */
682 0x7fffffff, /* dst_mask */
683 TRUE), /* pcrel_offset */
c19d1205
ZW
684
685 HOWTO (R_ARM_MOVW_ABS_NC, /* type */
686 0, /* rightshift */
687 2, /* size (0 = byte, 1 = short, 2 = long) */
688 16, /* bitsize */
689 FALSE, /* pc_relative */
690 0, /* bitpos */
691 complain_overflow_dont,/* complain_on_overflow */
692 bfd_elf_generic_reloc, /* special_function */
693 "R_ARM_MOVW_ABS_NC", /* name */
694 FALSE, /* partial_inplace */
39623e12
PB
695 0x000f0fff, /* src_mask */
696 0x000f0fff, /* dst_mask */
c19d1205
ZW
697 FALSE), /* pcrel_offset */
698
699 HOWTO (R_ARM_MOVT_ABS, /* type */
700 0, /* rightshift */
701 2, /* size (0 = byte, 1 = short, 2 = long) */
702 16, /* bitsize */
703 FALSE, /* pc_relative */
704 0, /* bitpos */
705 complain_overflow_bitfield,/* complain_on_overflow */
706 bfd_elf_generic_reloc, /* special_function */
707 "R_ARM_MOVT_ABS", /* name */
708 FALSE, /* partial_inplace */
39623e12
PB
709 0x000f0fff, /* src_mask */
710 0x000f0fff, /* dst_mask */
c19d1205
ZW
711 FALSE), /* pcrel_offset */
712
713 HOWTO (R_ARM_MOVW_PREL_NC, /* type */
714 0, /* rightshift */
715 2, /* size (0 = byte, 1 = short, 2 = long) */
716 16, /* bitsize */
717 TRUE, /* pc_relative */
718 0, /* bitpos */
719 complain_overflow_dont,/* complain_on_overflow */
720 bfd_elf_generic_reloc, /* special_function */
721 "R_ARM_MOVW_PREL_NC", /* name */
722 FALSE, /* partial_inplace */
39623e12
PB
723 0x000f0fff, /* src_mask */
724 0x000f0fff, /* dst_mask */
c19d1205
ZW
725 TRUE), /* pcrel_offset */
726
727 HOWTO (R_ARM_MOVT_PREL, /* type */
728 0, /* rightshift */
729 2, /* size (0 = byte, 1 = short, 2 = long) */
730 16, /* bitsize */
731 TRUE, /* pc_relative */
732 0, /* bitpos */
733 complain_overflow_bitfield,/* complain_on_overflow */
734 bfd_elf_generic_reloc, /* special_function */
735 "R_ARM_MOVT_PREL", /* name */
736 FALSE, /* partial_inplace */
39623e12
PB
737 0x000f0fff, /* src_mask */
738 0x000f0fff, /* dst_mask */
c19d1205
ZW
739 TRUE), /* pcrel_offset */
740
741 HOWTO (R_ARM_THM_MOVW_ABS_NC, /* type */
742 0, /* rightshift */
743 2, /* size (0 = byte, 1 = short, 2 = long) */
744 16, /* bitsize */
745 FALSE, /* pc_relative */
746 0, /* bitpos */
747 complain_overflow_dont,/* complain_on_overflow */
748 bfd_elf_generic_reloc, /* special_function */
749 "R_ARM_THM_MOVW_ABS_NC",/* name */
750 FALSE, /* partial_inplace */
751 0x040f70ff, /* src_mask */
752 0x040f70ff, /* dst_mask */
753 FALSE), /* pcrel_offset */
754
755 HOWTO (R_ARM_THM_MOVT_ABS, /* type */
756 0, /* rightshift */
757 2, /* size (0 = byte, 1 = short, 2 = long) */
758 16, /* bitsize */
759 FALSE, /* pc_relative */
760 0, /* bitpos */
761 complain_overflow_bitfield,/* complain_on_overflow */
762 bfd_elf_generic_reloc, /* special_function */
763 "R_ARM_THM_MOVT_ABS", /* name */
764 FALSE, /* partial_inplace */
765 0x040f70ff, /* src_mask */
766 0x040f70ff, /* dst_mask */
767 FALSE), /* pcrel_offset */
768
769 HOWTO (R_ARM_THM_MOVW_PREL_NC,/* type */
770 0, /* rightshift */
771 2, /* size (0 = byte, 1 = short, 2 = long) */
772 16, /* bitsize */
773 TRUE, /* pc_relative */
774 0, /* bitpos */
775 complain_overflow_dont,/* complain_on_overflow */
776 bfd_elf_generic_reloc, /* special_function */
777 "R_ARM_THM_MOVW_PREL_NC",/* name */
778 FALSE, /* partial_inplace */
779 0x040f70ff, /* src_mask */
780 0x040f70ff, /* dst_mask */
781 TRUE), /* pcrel_offset */
782
783 HOWTO (R_ARM_THM_MOVT_PREL, /* type */
784 0, /* rightshift */
785 2, /* size (0 = byte, 1 = short, 2 = long) */
786 16, /* bitsize */
787 TRUE, /* pc_relative */
788 0, /* bitpos */
789 complain_overflow_bitfield,/* complain_on_overflow */
790 bfd_elf_generic_reloc, /* special_function */
791 "R_ARM_THM_MOVT_PREL", /* name */
792 FALSE, /* partial_inplace */
793 0x040f70ff, /* src_mask */
794 0x040f70ff, /* dst_mask */
795 TRUE), /* pcrel_offset */
796
797 HOWTO (R_ARM_THM_JUMP19, /* type */
798 1, /* rightshift */
799 2, /* size (0 = byte, 1 = short, 2 = long) */
800 19, /* bitsize */
801 TRUE, /* pc_relative */
802 0, /* bitpos */
803 complain_overflow_signed,/* complain_on_overflow */
804 bfd_elf_generic_reloc, /* special_function */
805 "R_ARM_THM_JUMP19", /* name */
806 FALSE, /* partial_inplace */
807 0x043f2fff, /* src_mask */
808 0x043f2fff, /* dst_mask */
809 TRUE), /* pcrel_offset */
810
811 HOWTO (R_ARM_THM_JUMP6, /* type */
812 1, /* rightshift */
813 1, /* size (0 = byte, 1 = short, 2 = long) */
814 6, /* bitsize */
815 TRUE, /* pc_relative */
816 0, /* bitpos */
817 complain_overflow_unsigned,/* complain_on_overflow */
818 bfd_elf_generic_reloc, /* special_function */
819 "R_ARM_THM_JUMP6", /* name */
820 FALSE, /* partial_inplace */
821 0x02f8, /* src_mask */
822 0x02f8, /* dst_mask */
823 TRUE), /* pcrel_offset */
824
825 /* These are declared as 13-bit signed relocations because we can
826 address -4095 .. 4095(base) by altering ADDW to SUBW or vice
827 versa. */
828 HOWTO (R_ARM_THM_ALU_PREL_11_0,/* type */
829 0, /* rightshift */
830 2, /* size (0 = byte, 1 = short, 2 = long) */
831 13, /* bitsize */
832 TRUE, /* pc_relative */
833 0, /* bitpos */
2cab6cc3 834 complain_overflow_dont,/* complain_on_overflow */
c19d1205
ZW
835 bfd_elf_generic_reloc, /* special_function */
836 "R_ARM_THM_ALU_PREL_11_0",/* name */
837 FALSE, /* partial_inplace */
2cab6cc3
MS
838 0xffffffff, /* src_mask */
839 0xffffffff, /* dst_mask */
c19d1205
ZW
840 TRUE), /* pcrel_offset */
841
842 HOWTO (R_ARM_THM_PC12, /* type */
843 0, /* rightshift */
844 2, /* size (0 = byte, 1 = short, 2 = long) */
845 13, /* bitsize */
846 TRUE, /* pc_relative */
847 0, /* bitpos */
2cab6cc3 848 complain_overflow_dont,/* complain_on_overflow */
c19d1205
ZW
849 bfd_elf_generic_reloc, /* special_function */
850 "R_ARM_THM_PC12", /* name */
851 FALSE, /* partial_inplace */
2cab6cc3
MS
852 0xffffffff, /* src_mask */
853 0xffffffff, /* dst_mask */
c19d1205
ZW
854 TRUE), /* pcrel_offset */
855
856 HOWTO (R_ARM_ABS32_NOI, /* type */
857 0, /* rightshift */
858 2, /* size (0 = byte, 1 = short, 2 = long) */
859 32, /* bitsize */
860 FALSE, /* pc_relative */
861 0, /* bitpos */
862 complain_overflow_dont,/* complain_on_overflow */
863 bfd_elf_generic_reloc, /* special_function */
864 "R_ARM_ABS32_NOI", /* name */
865 FALSE, /* partial_inplace */
866 0xffffffff, /* src_mask */
867 0xffffffff, /* dst_mask */
868 FALSE), /* pcrel_offset */
869
870 HOWTO (R_ARM_REL32_NOI, /* type */
871 0, /* rightshift */
872 2, /* size (0 = byte, 1 = short, 2 = long) */
873 32, /* bitsize */
874 TRUE, /* pc_relative */
875 0, /* bitpos */
876 complain_overflow_dont,/* complain_on_overflow */
877 bfd_elf_generic_reloc, /* special_function */
878 "R_ARM_REL32_NOI", /* name */
879 FALSE, /* partial_inplace */
880 0xffffffff, /* src_mask */
881 0xffffffff, /* dst_mask */
882 FALSE), /* pcrel_offset */
7f266840 883
4962c51a
MS
884 /* Group relocations. */
885
886 HOWTO (R_ARM_ALU_PC_G0_NC, /* type */
887 0, /* rightshift */
888 2, /* size (0 = byte, 1 = short, 2 = long) */
889 32, /* bitsize */
890 TRUE, /* pc_relative */
891 0, /* bitpos */
892 complain_overflow_dont,/* complain_on_overflow */
893 bfd_elf_generic_reloc, /* special_function */
894 "R_ARM_ALU_PC_G0_NC", /* name */
895 FALSE, /* partial_inplace */
896 0xffffffff, /* src_mask */
897 0xffffffff, /* dst_mask */
898 TRUE), /* pcrel_offset */
899
900 HOWTO (R_ARM_ALU_PC_G0, /* type */
901 0, /* rightshift */
902 2, /* size (0 = byte, 1 = short, 2 = long) */
903 32, /* bitsize */
904 TRUE, /* pc_relative */
905 0, /* bitpos */
906 complain_overflow_dont,/* complain_on_overflow */
907 bfd_elf_generic_reloc, /* special_function */
908 "R_ARM_ALU_PC_G0", /* name */
909 FALSE, /* partial_inplace */
910 0xffffffff, /* src_mask */
911 0xffffffff, /* dst_mask */
912 TRUE), /* pcrel_offset */
913
914 HOWTO (R_ARM_ALU_PC_G1_NC, /* type */
915 0, /* rightshift */
916 2, /* size (0 = byte, 1 = short, 2 = long) */
917 32, /* bitsize */
918 TRUE, /* pc_relative */
919 0, /* bitpos */
920 complain_overflow_dont,/* complain_on_overflow */
921 bfd_elf_generic_reloc, /* special_function */
922 "R_ARM_ALU_PC_G1_NC", /* name */
923 FALSE, /* partial_inplace */
924 0xffffffff, /* src_mask */
925 0xffffffff, /* dst_mask */
926 TRUE), /* pcrel_offset */
927
928 HOWTO (R_ARM_ALU_PC_G1, /* type */
929 0, /* rightshift */
930 2, /* size (0 = byte, 1 = short, 2 = long) */
931 32, /* bitsize */
932 TRUE, /* pc_relative */
933 0, /* bitpos */
934 complain_overflow_dont,/* complain_on_overflow */
935 bfd_elf_generic_reloc, /* special_function */
936 "R_ARM_ALU_PC_G1", /* name */
937 FALSE, /* partial_inplace */
938 0xffffffff, /* src_mask */
939 0xffffffff, /* dst_mask */
940 TRUE), /* pcrel_offset */
941
942 HOWTO (R_ARM_ALU_PC_G2, /* type */
943 0, /* rightshift */
944 2, /* size (0 = byte, 1 = short, 2 = long) */
945 32, /* bitsize */
946 TRUE, /* pc_relative */
947 0, /* bitpos */
948 complain_overflow_dont,/* complain_on_overflow */
949 bfd_elf_generic_reloc, /* special_function */
950 "R_ARM_ALU_PC_G2", /* name */
951 FALSE, /* partial_inplace */
952 0xffffffff, /* src_mask */
953 0xffffffff, /* dst_mask */
954 TRUE), /* pcrel_offset */
955
956 HOWTO (R_ARM_LDR_PC_G1, /* type */
957 0, /* rightshift */
958 2, /* size (0 = byte, 1 = short, 2 = long) */
959 32, /* bitsize */
960 TRUE, /* pc_relative */
961 0, /* bitpos */
962 complain_overflow_dont,/* complain_on_overflow */
963 bfd_elf_generic_reloc, /* special_function */
964 "R_ARM_LDR_PC_G1", /* name */
965 FALSE, /* partial_inplace */
966 0xffffffff, /* src_mask */
967 0xffffffff, /* dst_mask */
968 TRUE), /* pcrel_offset */
969
970 HOWTO (R_ARM_LDR_PC_G2, /* type */
971 0, /* rightshift */
972 2, /* size (0 = byte, 1 = short, 2 = long) */
973 32, /* bitsize */
974 TRUE, /* pc_relative */
975 0, /* bitpos */
976 complain_overflow_dont,/* complain_on_overflow */
977 bfd_elf_generic_reloc, /* special_function */
978 "R_ARM_LDR_PC_G2", /* name */
979 FALSE, /* partial_inplace */
980 0xffffffff, /* src_mask */
981 0xffffffff, /* dst_mask */
982 TRUE), /* pcrel_offset */
983
984 HOWTO (R_ARM_LDRS_PC_G0, /* type */
985 0, /* rightshift */
986 2, /* size (0 = byte, 1 = short, 2 = long) */
987 32, /* bitsize */
988 TRUE, /* pc_relative */
989 0, /* bitpos */
990 complain_overflow_dont,/* complain_on_overflow */
991 bfd_elf_generic_reloc, /* special_function */
992 "R_ARM_LDRS_PC_G0", /* name */
993 FALSE, /* partial_inplace */
994 0xffffffff, /* src_mask */
995 0xffffffff, /* dst_mask */
996 TRUE), /* pcrel_offset */
997
998 HOWTO (R_ARM_LDRS_PC_G1, /* type */
999 0, /* rightshift */
1000 2, /* size (0 = byte, 1 = short, 2 = long) */
1001 32, /* bitsize */
1002 TRUE, /* pc_relative */
1003 0, /* bitpos */
1004 complain_overflow_dont,/* complain_on_overflow */
1005 bfd_elf_generic_reloc, /* special_function */
1006 "R_ARM_LDRS_PC_G1", /* name */
1007 FALSE, /* partial_inplace */
1008 0xffffffff, /* src_mask */
1009 0xffffffff, /* dst_mask */
1010 TRUE), /* pcrel_offset */
1011
1012 HOWTO (R_ARM_LDRS_PC_G2, /* type */
1013 0, /* rightshift */
1014 2, /* size (0 = byte, 1 = short, 2 = long) */
1015 32, /* bitsize */
1016 TRUE, /* pc_relative */
1017 0, /* bitpos */
1018 complain_overflow_dont,/* complain_on_overflow */
1019 bfd_elf_generic_reloc, /* special_function */
1020 "R_ARM_LDRS_PC_G2", /* name */
1021 FALSE, /* partial_inplace */
1022 0xffffffff, /* src_mask */
1023 0xffffffff, /* dst_mask */
1024 TRUE), /* pcrel_offset */
1025
1026 HOWTO (R_ARM_LDC_PC_G0, /* type */
1027 0, /* rightshift */
1028 2, /* size (0 = byte, 1 = short, 2 = long) */
1029 32, /* bitsize */
1030 TRUE, /* pc_relative */
1031 0, /* bitpos */
1032 complain_overflow_dont,/* complain_on_overflow */
1033 bfd_elf_generic_reloc, /* special_function */
1034 "R_ARM_LDC_PC_G0", /* name */
1035 FALSE, /* partial_inplace */
1036 0xffffffff, /* src_mask */
1037 0xffffffff, /* dst_mask */
1038 TRUE), /* pcrel_offset */
1039
1040 HOWTO (R_ARM_LDC_PC_G1, /* type */
1041 0, /* rightshift */
1042 2, /* size (0 = byte, 1 = short, 2 = long) */
1043 32, /* bitsize */
1044 TRUE, /* pc_relative */
1045 0, /* bitpos */
1046 complain_overflow_dont,/* complain_on_overflow */
1047 bfd_elf_generic_reloc, /* special_function */
1048 "R_ARM_LDC_PC_G1", /* name */
1049 FALSE, /* partial_inplace */
1050 0xffffffff, /* src_mask */
1051 0xffffffff, /* dst_mask */
1052 TRUE), /* pcrel_offset */
1053
1054 HOWTO (R_ARM_LDC_PC_G2, /* type */
1055 0, /* rightshift */
1056 2, /* size (0 = byte, 1 = short, 2 = long) */
1057 32, /* bitsize */
1058 TRUE, /* pc_relative */
1059 0, /* bitpos */
1060 complain_overflow_dont,/* complain_on_overflow */
1061 bfd_elf_generic_reloc, /* special_function */
1062 "R_ARM_LDC_PC_G2", /* name */
1063 FALSE, /* partial_inplace */
1064 0xffffffff, /* src_mask */
1065 0xffffffff, /* dst_mask */
1066 TRUE), /* pcrel_offset */
1067
1068 HOWTO (R_ARM_ALU_SB_G0_NC, /* type */
1069 0, /* rightshift */
1070 2, /* size (0 = byte, 1 = short, 2 = long) */
1071 32, /* bitsize */
1072 TRUE, /* pc_relative */
1073 0, /* bitpos */
1074 complain_overflow_dont,/* complain_on_overflow */
1075 bfd_elf_generic_reloc, /* special_function */
1076 "R_ARM_ALU_SB_G0_NC", /* name */
1077 FALSE, /* partial_inplace */
1078 0xffffffff, /* src_mask */
1079 0xffffffff, /* dst_mask */
1080 TRUE), /* pcrel_offset */
1081
1082 HOWTO (R_ARM_ALU_SB_G0, /* type */
1083 0, /* rightshift */
1084 2, /* size (0 = byte, 1 = short, 2 = long) */
1085 32, /* bitsize */
1086 TRUE, /* pc_relative */
1087 0, /* bitpos */
1088 complain_overflow_dont,/* complain_on_overflow */
1089 bfd_elf_generic_reloc, /* special_function */
1090 "R_ARM_ALU_SB_G0", /* name */
1091 FALSE, /* partial_inplace */
1092 0xffffffff, /* src_mask */
1093 0xffffffff, /* dst_mask */
1094 TRUE), /* pcrel_offset */
1095
1096 HOWTO (R_ARM_ALU_SB_G1_NC, /* type */
1097 0, /* rightshift */
1098 2, /* size (0 = byte, 1 = short, 2 = long) */
1099 32, /* bitsize */
1100 TRUE, /* pc_relative */
1101 0, /* bitpos */
1102 complain_overflow_dont,/* complain_on_overflow */
1103 bfd_elf_generic_reloc, /* special_function */
1104 "R_ARM_ALU_SB_G1_NC", /* name */
1105 FALSE, /* partial_inplace */
1106 0xffffffff, /* src_mask */
1107 0xffffffff, /* dst_mask */
1108 TRUE), /* pcrel_offset */
1109
1110 HOWTO (R_ARM_ALU_SB_G1, /* type */
1111 0, /* rightshift */
1112 2, /* size (0 = byte, 1 = short, 2 = long) */
1113 32, /* bitsize */
1114 TRUE, /* pc_relative */
1115 0, /* bitpos */
1116 complain_overflow_dont,/* complain_on_overflow */
1117 bfd_elf_generic_reloc, /* special_function */
1118 "R_ARM_ALU_SB_G1", /* name */
1119 FALSE, /* partial_inplace */
1120 0xffffffff, /* src_mask */
1121 0xffffffff, /* dst_mask */
1122 TRUE), /* pcrel_offset */
1123
1124 HOWTO (R_ARM_ALU_SB_G2, /* type */
1125 0, /* rightshift */
1126 2, /* size (0 = byte, 1 = short, 2 = long) */
1127 32, /* bitsize */
1128 TRUE, /* pc_relative */
1129 0, /* bitpos */
1130 complain_overflow_dont,/* complain_on_overflow */
1131 bfd_elf_generic_reloc, /* special_function */
1132 "R_ARM_ALU_SB_G2", /* name */
1133 FALSE, /* partial_inplace */
1134 0xffffffff, /* src_mask */
1135 0xffffffff, /* dst_mask */
1136 TRUE), /* pcrel_offset */
1137
1138 HOWTO (R_ARM_LDR_SB_G0, /* type */
1139 0, /* rightshift */
1140 2, /* size (0 = byte, 1 = short, 2 = long) */
1141 32, /* bitsize */
1142 TRUE, /* pc_relative */
1143 0, /* bitpos */
1144 complain_overflow_dont,/* complain_on_overflow */
1145 bfd_elf_generic_reloc, /* special_function */
1146 "R_ARM_LDR_SB_G0", /* name */
1147 FALSE, /* partial_inplace */
1148 0xffffffff, /* src_mask */
1149 0xffffffff, /* dst_mask */
1150 TRUE), /* pcrel_offset */
1151
1152 HOWTO (R_ARM_LDR_SB_G1, /* type */
1153 0, /* rightshift */
1154 2, /* size (0 = byte, 1 = short, 2 = long) */
1155 32, /* bitsize */
1156 TRUE, /* pc_relative */
1157 0, /* bitpos */
1158 complain_overflow_dont,/* complain_on_overflow */
1159 bfd_elf_generic_reloc, /* special_function */
1160 "R_ARM_LDR_SB_G1", /* name */
1161 FALSE, /* partial_inplace */
1162 0xffffffff, /* src_mask */
1163 0xffffffff, /* dst_mask */
1164 TRUE), /* pcrel_offset */
1165
1166 HOWTO (R_ARM_LDR_SB_G2, /* type */
1167 0, /* rightshift */
1168 2, /* size (0 = byte, 1 = short, 2 = long) */
1169 32, /* bitsize */
1170 TRUE, /* pc_relative */
1171 0, /* bitpos */
1172 complain_overflow_dont,/* complain_on_overflow */
1173 bfd_elf_generic_reloc, /* special_function */
1174 "R_ARM_LDR_SB_G2", /* name */
1175 FALSE, /* partial_inplace */
1176 0xffffffff, /* src_mask */
1177 0xffffffff, /* dst_mask */
1178 TRUE), /* pcrel_offset */
1179
1180 HOWTO (R_ARM_LDRS_SB_G0, /* type */
1181 0, /* rightshift */
1182 2, /* size (0 = byte, 1 = short, 2 = long) */
1183 32, /* bitsize */
1184 TRUE, /* pc_relative */
1185 0, /* bitpos */
1186 complain_overflow_dont,/* complain_on_overflow */
1187 bfd_elf_generic_reloc, /* special_function */
1188 "R_ARM_LDRS_SB_G0", /* name */
1189 FALSE, /* partial_inplace */
1190 0xffffffff, /* src_mask */
1191 0xffffffff, /* dst_mask */
1192 TRUE), /* pcrel_offset */
1193
1194 HOWTO (R_ARM_LDRS_SB_G1, /* type */
1195 0, /* rightshift */
1196 2, /* size (0 = byte, 1 = short, 2 = long) */
1197 32, /* bitsize */
1198 TRUE, /* pc_relative */
1199 0, /* bitpos */
1200 complain_overflow_dont,/* complain_on_overflow */
1201 bfd_elf_generic_reloc, /* special_function */
1202 "R_ARM_LDRS_SB_G1", /* name */
1203 FALSE, /* partial_inplace */
1204 0xffffffff, /* src_mask */
1205 0xffffffff, /* dst_mask */
1206 TRUE), /* pcrel_offset */
1207
1208 HOWTO (R_ARM_LDRS_SB_G2, /* type */
1209 0, /* rightshift */
1210 2, /* size (0 = byte, 1 = short, 2 = long) */
1211 32, /* bitsize */
1212 TRUE, /* pc_relative */
1213 0, /* bitpos */
1214 complain_overflow_dont,/* complain_on_overflow */
1215 bfd_elf_generic_reloc, /* special_function */
1216 "R_ARM_LDRS_SB_G2", /* name */
1217 FALSE, /* partial_inplace */
1218 0xffffffff, /* src_mask */
1219 0xffffffff, /* dst_mask */
1220 TRUE), /* pcrel_offset */
1221
1222 HOWTO (R_ARM_LDC_SB_G0, /* type */
1223 0, /* rightshift */
1224 2, /* size (0 = byte, 1 = short, 2 = long) */
1225 32, /* bitsize */
1226 TRUE, /* pc_relative */
1227 0, /* bitpos */
1228 complain_overflow_dont,/* complain_on_overflow */
1229 bfd_elf_generic_reloc, /* special_function */
1230 "R_ARM_LDC_SB_G0", /* name */
1231 FALSE, /* partial_inplace */
1232 0xffffffff, /* src_mask */
1233 0xffffffff, /* dst_mask */
1234 TRUE), /* pcrel_offset */
1235
1236 HOWTO (R_ARM_LDC_SB_G1, /* type */
1237 0, /* rightshift */
1238 2, /* size (0 = byte, 1 = short, 2 = long) */
1239 32, /* bitsize */
1240 TRUE, /* pc_relative */
1241 0, /* bitpos */
1242 complain_overflow_dont,/* complain_on_overflow */
1243 bfd_elf_generic_reloc, /* special_function */
1244 "R_ARM_LDC_SB_G1", /* name */
1245 FALSE, /* partial_inplace */
1246 0xffffffff, /* src_mask */
1247 0xffffffff, /* dst_mask */
1248 TRUE), /* pcrel_offset */
1249
1250 HOWTO (R_ARM_LDC_SB_G2, /* type */
1251 0, /* rightshift */
1252 2, /* size (0 = byte, 1 = short, 2 = long) */
1253 32, /* bitsize */
1254 TRUE, /* pc_relative */
1255 0, /* bitpos */
1256 complain_overflow_dont,/* complain_on_overflow */
1257 bfd_elf_generic_reloc, /* special_function */
1258 "R_ARM_LDC_SB_G2", /* name */
1259 FALSE, /* partial_inplace */
1260 0xffffffff, /* src_mask */
1261 0xffffffff, /* dst_mask */
1262 TRUE), /* pcrel_offset */
1263
1264 /* End of group relocations. */
c19d1205 1265
c19d1205
ZW
1266 HOWTO (R_ARM_MOVW_BREL_NC, /* type */
1267 0, /* rightshift */
1268 2, /* size (0 = byte, 1 = short, 2 = long) */
1269 16, /* bitsize */
1270 FALSE, /* pc_relative */
1271 0, /* bitpos */
1272 complain_overflow_dont,/* complain_on_overflow */
1273 bfd_elf_generic_reloc, /* special_function */
1274 "R_ARM_MOVW_BREL_NC", /* name */
1275 FALSE, /* partial_inplace */
1276 0x0000ffff, /* src_mask */
1277 0x0000ffff, /* dst_mask */
1278 FALSE), /* pcrel_offset */
1279
1280 HOWTO (R_ARM_MOVT_BREL, /* type */
1281 0, /* rightshift */
1282 2, /* size (0 = byte, 1 = short, 2 = long) */
1283 16, /* bitsize */
1284 FALSE, /* pc_relative */
1285 0, /* bitpos */
1286 complain_overflow_bitfield,/* complain_on_overflow */
1287 bfd_elf_generic_reloc, /* special_function */
1288 "R_ARM_MOVT_BREL", /* name */
1289 FALSE, /* partial_inplace */
1290 0x0000ffff, /* src_mask */
1291 0x0000ffff, /* dst_mask */
1292 FALSE), /* pcrel_offset */
1293
1294 HOWTO (R_ARM_MOVW_BREL, /* type */
1295 0, /* rightshift */
1296 2, /* size (0 = byte, 1 = short, 2 = long) */
1297 16, /* bitsize */
1298 FALSE, /* pc_relative */
1299 0, /* bitpos */
1300 complain_overflow_dont,/* complain_on_overflow */
1301 bfd_elf_generic_reloc, /* special_function */
1302 "R_ARM_MOVW_BREL", /* name */
1303 FALSE, /* partial_inplace */
1304 0x0000ffff, /* src_mask */
1305 0x0000ffff, /* dst_mask */
1306 FALSE), /* pcrel_offset */
1307
1308 HOWTO (R_ARM_THM_MOVW_BREL_NC,/* type */
1309 0, /* rightshift */
1310 2, /* size (0 = byte, 1 = short, 2 = long) */
1311 16, /* bitsize */
1312 FALSE, /* pc_relative */
1313 0, /* bitpos */
1314 complain_overflow_dont,/* complain_on_overflow */
1315 bfd_elf_generic_reloc, /* special_function */
1316 "R_ARM_THM_MOVW_BREL_NC",/* name */
1317 FALSE, /* partial_inplace */
1318 0x040f70ff, /* src_mask */
1319 0x040f70ff, /* dst_mask */
1320 FALSE), /* pcrel_offset */
1321
1322 HOWTO (R_ARM_THM_MOVT_BREL, /* type */
1323 0, /* rightshift */
1324 2, /* size (0 = byte, 1 = short, 2 = long) */
1325 16, /* bitsize */
1326 FALSE, /* pc_relative */
1327 0, /* bitpos */
1328 complain_overflow_bitfield,/* complain_on_overflow */
1329 bfd_elf_generic_reloc, /* special_function */
1330 "R_ARM_THM_MOVT_BREL", /* name */
1331 FALSE, /* partial_inplace */
1332 0x040f70ff, /* src_mask */
1333 0x040f70ff, /* dst_mask */
1334 FALSE), /* pcrel_offset */
1335
1336 HOWTO (R_ARM_THM_MOVW_BREL, /* type */
1337 0, /* rightshift */
1338 2, /* size (0 = byte, 1 = short, 2 = long) */
1339 16, /* bitsize */
1340 FALSE, /* pc_relative */
1341 0, /* bitpos */
1342 complain_overflow_dont,/* complain_on_overflow */
1343 bfd_elf_generic_reloc, /* special_function */
1344 "R_ARM_THM_MOVW_BREL", /* name */
1345 FALSE, /* partial_inplace */
1346 0x040f70ff, /* src_mask */
1347 0x040f70ff, /* dst_mask */
1348 FALSE), /* pcrel_offset */
1349
8029a119 1350 EMPTY_HOWTO (90), /* Unallocated. */
c19d1205
ZW
1351 EMPTY_HOWTO (91),
1352 EMPTY_HOWTO (92),
1353 EMPTY_HOWTO (93),
1354
1355 HOWTO (R_ARM_PLT32_ABS, /* type */
1356 0, /* rightshift */
1357 2, /* size (0 = byte, 1 = short, 2 = long) */
1358 32, /* bitsize */
1359 FALSE, /* pc_relative */
1360 0, /* bitpos */
1361 complain_overflow_dont,/* complain_on_overflow */
1362 bfd_elf_generic_reloc, /* special_function */
1363 "R_ARM_PLT32_ABS", /* name */
1364 FALSE, /* partial_inplace */
1365 0xffffffff, /* src_mask */
1366 0xffffffff, /* dst_mask */
1367 FALSE), /* pcrel_offset */
1368
1369 HOWTO (R_ARM_GOT_ABS, /* type */
1370 0, /* rightshift */
1371 2, /* size (0 = byte, 1 = short, 2 = long) */
1372 32, /* bitsize */
1373 FALSE, /* pc_relative */
1374 0, /* bitpos */
1375 complain_overflow_dont,/* complain_on_overflow */
1376 bfd_elf_generic_reloc, /* special_function */
1377 "R_ARM_GOT_ABS", /* name */
1378 FALSE, /* partial_inplace */
1379 0xffffffff, /* src_mask */
1380 0xffffffff, /* dst_mask */
1381 FALSE), /* pcrel_offset */
1382
1383 HOWTO (R_ARM_GOT_PREL, /* type */
1384 0, /* rightshift */
1385 2, /* size (0 = byte, 1 = short, 2 = long) */
1386 32, /* bitsize */
1387 TRUE, /* pc_relative */
1388 0, /* bitpos */
1389 complain_overflow_dont, /* complain_on_overflow */
1390 bfd_elf_generic_reloc, /* special_function */
1391 "R_ARM_GOT_PREL", /* name */
1392 FALSE, /* partial_inplace */
1393 0xffffffff, /* src_mask */
1394 0xffffffff, /* dst_mask */
1395 TRUE), /* pcrel_offset */
1396
1397 HOWTO (R_ARM_GOT_BREL12, /* type */
1398 0, /* rightshift */
1399 2, /* size (0 = byte, 1 = short, 2 = long) */
1400 12, /* bitsize */
1401 FALSE, /* pc_relative */
1402 0, /* bitpos */
1403 complain_overflow_bitfield,/* complain_on_overflow */
1404 bfd_elf_generic_reloc, /* special_function */
1405 "R_ARM_GOT_BREL12", /* name */
1406 FALSE, /* partial_inplace */
1407 0x00000fff, /* src_mask */
1408 0x00000fff, /* dst_mask */
1409 FALSE), /* pcrel_offset */
1410
1411 HOWTO (R_ARM_GOTOFF12, /* type */
1412 0, /* rightshift */
1413 2, /* size (0 = byte, 1 = short, 2 = long) */
1414 12, /* bitsize */
1415 FALSE, /* pc_relative */
1416 0, /* bitpos */
1417 complain_overflow_bitfield,/* complain_on_overflow */
1418 bfd_elf_generic_reloc, /* special_function */
1419 "R_ARM_GOTOFF12", /* name */
1420 FALSE, /* partial_inplace */
1421 0x00000fff, /* src_mask */
1422 0x00000fff, /* dst_mask */
1423 FALSE), /* pcrel_offset */
1424
1425 EMPTY_HOWTO (R_ARM_GOTRELAX), /* reserved for future GOT-load optimizations */
1426
1427 /* GNU extension to record C++ vtable member usage */
1428 HOWTO (R_ARM_GNU_VTENTRY, /* type */
ba93b8ac
DJ
1429 0, /* rightshift */
1430 2, /* size (0 = byte, 1 = short, 2 = long) */
c19d1205 1431 0, /* bitsize */
ba93b8ac
DJ
1432 FALSE, /* pc_relative */
1433 0, /* bitpos */
c19d1205
ZW
1434 complain_overflow_dont, /* complain_on_overflow */
1435 _bfd_elf_rel_vtable_reloc_fn, /* special_function */
1436 "R_ARM_GNU_VTENTRY", /* name */
1437 FALSE, /* partial_inplace */
1438 0, /* src_mask */
1439 0, /* dst_mask */
1440 FALSE), /* pcrel_offset */
1441
1442 /* GNU extension to record C++ vtable hierarchy */
1443 HOWTO (R_ARM_GNU_VTINHERIT, /* type */
1444 0, /* rightshift */
1445 2, /* size (0 = byte, 1 = short, 2 = long) */
1446 0, /* bitsize */
1447 FALSE, /* pc_relative */
1448 0, /* bitpos */
1449 complain_overflow_dont, /* complain_on_overflow */
1450 NULL, /* special_function */
1451 "R_ARM_GNU_VTINHERIT", /* name */
1452 FALSE, /* partial_inplace */
1453 0, /* src_mask */
1454 0, /* dst_mask */
1455 FALSE), /* pcrel_offset */
1456
1457 HOWTO (R_ARM_THM_JUMP11, /* type */
1458 1, /* rightshift */
1459 1, /* size (0 = byte, 1 = short, 2 = long) */
1460 11, /* bitsize */
1461 TRUE, /* pc_relative */
1462 0, /* bitpos */
1463 complain_overflow_signed, /* complain_on_overflow */
1464 bfd_elf_generic_reloc, /* special_function */
1465 "R_ARM_THM_JUMP11", /* name */
1466 FALSE, /* partial_inplace */
1467 0x000007ff, /* src_mask */
1468 0x000007ff, /* dst_mask */
1469 TRUE), /* pcrel_offset */
1470
1471 HOWTO (R_ARM_THM_JUMP8, /* type */
1472 1, /* rightshift */
1473 1, /* size (0 = byte, 1 = short, 2 = long) */
1474 8, /* bitsize */
1475 TRUE, /* pc_relative */
1476 0, /* bitpos */
1477 complain_overflow_signed, /* complain_on_overflow */
1478 bfd_elf_generic_reloc, /* special_function */
1479 "R_ARM_THM_JUMP8", /* name */
1480 FALSE, /* partial_inplace */
1481 0x000000ff, /* src_mask */
1482 0x000000ff, /* dst_mask */
1483 TRUE), /* pcrel_offset */
ba93b8ac 1484
c19d1205
ZW
1485 /* TLS relocations */
1486 HOWTO (R_ARM_TLS_GD32, /* type */
ba93b8ac
DJ
1487 0, /* rightshift */
1488 2, /* size (0 = byte, 1 = short, 2 = long) */
1489 32, /* bitsize */
1490 FALSE, /* pc_relative */
1491 0, /* bitpos */
1492 complain_overflow_bitfield,/* complain_on_overflow */
c19d1205
ZW
1493 NULL, /* special_function */
1494 "R_ARM_TLS_GD32", /* name */
ba93b8ac
DJ
1495 TRUE, /* partial_inplace */
1496 0xffffffff, /* src_mask */
1497 0xffffffff, /* dst_mask */
c19d1205 1498 FALSE), /* pcrel_offset */
ba93b8ac 1499
ba93b8ac
DJ
1500 HOWTO (R_ARM_TLS_LDM32, /* type */
1501 0, /* rightshift */
1502 2, /* size (0 = byte, 1 = short, 2 = long) */
1503 32, /* bitsize */
1504 FALSE, /* pc_relative */
1505 0, /* bitpos */
1506 complain_overflow_bitfield,/* complain_on_overflow */
1507 bfd_elf_generic_reloc, /* special_function */
1508 "R_ARM_TLS_LDM32", /* name */
1509 TRUE, /* partial_inplace */
1510 0xffffffff, /* src_mask */
1511 0xffffffff, /* dst_mask */
c19d1205 1512 FALSE), /* pcrel_offset */
ba93b8ac 1513
c19d1205 1514 HOWTO (R_ARM_TLS_LDO32, /* type */
ba93b8ac
DJ
1515 0, /* rightshift */
1516 2, /* size (0 = byte, 1 = short, 2 = long) */
1517 32, /* bitsize */
1518 FALSE, /* pc_relative */
1519 0, /* bitpos */
1520 complain_overflow_bitfield,/* complain_on_overflow */
1521 bfd_elf_generic_reloc, /* special_function */
c19d1205 1522 "R_ARM_TLS_LDO32", /* name */
ba93b8ac
DJ
1523 TRUE, /* partial_inplace */
1524 0xffffffff, /* src_mask */
1525 0xffffffff, /* dst_mask */
c19d1205 1526 FALSE), /* pcrel_offset */
ba93b8ac 1527
ba93b8ac
DJ
1528 HOWTO (R_ARM_TLS_IE32, /* type */
1529 0, /* rightshift */
1530 2, /* size (0 = byte, 1 = short, 2 = long) */
1531 32, /* bitsize */
1532 FALSE, /* pc_relative */
1533 0, /* bitpos */
1534 complain_overflow_bitfield,/* complain_on_overflow */
1535 NULL, /* special_function */
1536 "R_ARM_TLS_IE32", /* name */
1537 TRUE, /* partial_inplace */
1538 0xffffffff, /* src_mask */
1539 0xffffffff, /* dst_mask */
c19d1205 1540 FALSE), /* pcrel_offset */
7f266840 1541
c19d1205 1542 HOWTO (R_ARM_TLS_LE32, /* type */
7f266840
DJ
1543 0, /* rightshift */
1544 2, /* size (0 = byte, 1 = short, 2 = long) */
c19d1205 1545 32, /* bitsize */
7f266840
DJ
1546 FALSE, /* pc_relative */
1547 0, /* bitpos */
c19d1205
ZW
1548 complain_overflow_bitfield,/* complain_on_overflow */
1549 bfd_elf_generic_reloc, /* special_function */
1550 "R_ARM_TLS_LE32", /* name */
1551 TRUE, /* partial_inplace */
1552 0xffffffff, /* src_mask */
1553 0xffffffff, /* dst_mask */
1554 FALSE), /* pcrel_offset */
7f266840 1555
c19d1205
ZW
1556 HOWTO (R_ARM_TLS_LDO12, /* type */
1557 0, /* rightshift */
1558 2, /* size (0 = byte, 1 = short, 2 = long) */
1559 12, /* bitsize */
1560 FALSE, /* pc_relative */
7f266840 1561 0, /* bitpos */
c19d1205 1562 complain_overflow_bitfield,/* complain_on_overflow */
7f266840 1563 bfd_elf_generic_reloc, /* special_function */
c19d1205 1564 "R_ARM_TLS_LDO12", /* name */
7f266840 1565 FALSE, /* partial_inplace */
c19d1205
ZW
1566 0x00000fff, /* src_mask */
1567 0x00000fff, /* dst_mask */
1568 FALSE), /* pcrel_offset */
7f266840 1569
c19d1205
ZW
1570 HOWTO (R_ARM_TLS_LE12, /* type */
1571 0, /* rightshift */
1572 2, /* size (0 = byte, 1 = short, 2 = long) */
1573 12, /* bitsize */
1574 FALSE, /* pc_relative */
7f266840 1575 0, /* bitpos */
c19d1205 1576 complain_overflow_bitfield,/* complain_on_overflow */
7f266840 1577 bfd_elf_generic_reloc, /* special_function */
c19d1205 1578 "R_ARM_TLS_LE12", /* name */
7f266840 1579 FALSE, /* partial_inplace */
c19d1205
ZW
1580 0x00000fff, /* src_mask */
1581 0x00000fff, /* dst_mask */
1582 FALSE), /* pcrel_offset */
7f266840 1583
c19d1205 1584 HOWTO (R_ARM_TLS_IE12GP, /* type */
7f266840
DJ
1585 0, /* rightshift */
1586 2, /* size (0 = byte, 1 = short, 2 = long) */
c19d1205
ZW
1587 12, /* bitsize */
1588 FALSE, /* pc_relative */
7f266840 1589 0, /* bitpos */
c19d1205 1590 complain_overflow_bitfield,/* complain_on_overflow */
7f266840 1591 bfd_elf_generic_reloc, /* special_function */
c19d1205 1592 "R_ARM_TLS_IE12GP", /* name */
7f266840 1593 FALSE, /* partial_inplace */
c19d1205
ZW
1594 0x00000fff, /* src_mask */
1595 0x00000fff, /* dst_mask */
1596 FALSE), /* pcrel_offset */
1597};
1598
1599/* 112-127 private relocations
1600 128 R_ARM_ME_TOO, obsolete
1601 129-255 unallocated in AAELF.
7f266840 1602
c19d1205
ZW
1603 249-255 extended, currently unused, relocations: */
1604
4962c51a 1605static reloc_howto_type elf32_arm_howto_table_2[4] =
7f266840
DJ
1606{
1607 HOWTO (R_ARM_RREL32, /* type */
1608 0, /* rightshift */
1609 0, /* size (0 = byte, 1 = short, 2 = long) */
1610 0, /* bitsize */
1611 FALSE, /* pc_relative */
1612 0, /* bitpos */
1613 complain_overflow_dont,/* complain_on_overflow */
1614 bfd_elf_generic_reloc, /* special_function */
1615 "R_ARM_RREL32", /* name */
1616 FALSE, /* partial_inplace */
1617 0, /* src_mask */
1618 0, /* dst_mask */
1619 FALSE), /* pcrel_offset */
1620
1621 HOWTO (R_ARM_RABS32, /* type */
1622 0, /* rightshift */
1623 0, /* size (0 = byte, 1 = short, 2 = long) */
1624 0, /* bitsize */
1625 FALSE, /* pc_relative */
1626 0, /* bitpos */
1627 complain_overflow_dont,/* complain_on_overflow */
1628 bfd_elf_generic_reloc, /* special_function */
1629 "R_ARM_RABS32", /* name */
1630 FALSE, /* partial_inplace */
1631 0, /* src_mask */
1632 0, /* dst_mask */
1633 FALSE), /* pcrel_offset */
1634
1635 HOWTO (R_ARM_RPC24, /* type */
1636 0, /* rightshift */
1637 0, /* size (0 = byte, 1 = short, 2 = long) */
1638 0, /* bitsize */
1639 FALSE, /* pc_relative */
1640 0, /* bitpos */
1641 complain_overflow_dont,/* complain_on_overflow */
1642 bfd_elf_generic_reloc, /* special_function */
1643 "R_ARM_RPC24", /* name */
1644 FALSE, /* partial_inplace */
1645 0, /* src_mask */
1646 0, /* dst_mask */
1647 FALSE), /* pcrel_offset */
1648
1649 HOWTO (R_ARM_RBASE, /* type */
1650 0, /* rightshift */
1651 0, /* size (0 = byte, 1 = short, 2 = long) */
1652 0, /* bitsize */
1653 FALSE, /* pc_relative */
1654 0, /* bitpos */
1655 complain_overflow_dont,/* complain_on_overflow */
1656 bfd_elf_generic_reloc, /* special_function */
1657 "R_ARM_RBASE", /* name */
1658 FALSE, /* partial_inplace */
1659 0, /* src_mask */
1660 0, /* dst_mask */
1661 FALSE) /* pcrel_offset */
1662};
1663
1664static reloc_howto_type *
1665elf32_arm_howto_from_type (unsigned int r_type)
1666{
906e58ca 1667 if (r_type < ARRAY_SIZE (elf32_arm_howto_table_1))
c19d1205 1668 return &elf32_arm_howto_table_1[r_type];
ba93b8ac 1669
c19d1205 1670 if (r_type >= R_ARM_RREL32
906e58ca 1671 && r_type < R_ARM_RREL32 + ARRAY_SIZE (elf32_arm_howto_table_2))
4962c51a 1672 return &elf32_arm_howto_table_2[r_type - R_ARM_RREL32];
7f266840 1673
c19d1205 1674 return NULL;
7f266840
DJ
1675}
1676
1677static void
1678elf32_arm_info_to_howto (bfd * abfd ATTRIBUTE_UNUSED, arelent * bfd_reloc,
1679 Elf_Internal_Rela * elf_reloc)
1680{
1681 unsigned int r_type;
1682
1683 r_type = ELF32_R_TYPE (elf_reloc->r_info);
1684 bfd_reloc->howto = elf32_arm_howto_from_type (r_type);
1685}
1686
1687struct elf32_arm_reloc_map
1688 {
1689 bfd_reloc_code_real_type bfd_reloc_val;
1690 unsigned char elf_reloc_val;
1691 };
1692
1693/* All entries in this list must also be present in elf32_arm_howto_table. */
1694static const struct elf32_arm_reloc_map elf32_arm_reloc_map[] =
1695 {
1696 {BFD_RELOC_NONE, R_ARM_NONE},
1697 {BFD_RELOC_ARM_PCREL_BRANCH, R_ARM_PC24},
39b41c9c
PB
1698 {BFD_RELOC_ARM_PCREL_CALL, R_ARM_CALL},
1699 {BFD_RELOC_ARM_PCREL_JUMP, R_ARM_JUMP24},
7f266840
DJ
1700 {BFD_RELOC_ARM_PCREL_BLX, R_ARM_XPC25},
1701 {BFD_RELOC_THUMB_PCREL_BLX, R_ARM_THM_XPC22},
1702 {BFD_RELOC_32, R_ARM_ABS32},
1703 {BFD_RELOC_32_PCREL, R_ARM_REL32},
1704 {BFD_RELOC_8, R_ARM_ABS8},
1705 {BFD_RELOC_16, R_ARM_ABS16},
1706 {BFD_RELOC_ARM_OFFSET_IMM, R_ARM_ABS12},
1707 {BFD_RELOC_ARM_THUMB_OFFSET, R_ARM_THM_ABS5},
c19d1205
ZW
1708 {BFD_RELOC_THUMB_PCREL_BRANCH25, R_ARM_THM_JUMP24},
1709 {BFD_RELOC_THUMB_PCREL_BRANCH23, R_ARM_THM_CALL},
1710 {BFD_RELOC_THUMB_PCREL_BRANCH12, R_ARM_THM_JUMP11},
1711 {BFD_RELOC_THUMB_PCREL_BRANCH20, R_ARM_THM_JUMP19},
1712 {BFD_RELOC_THUMB_PCREL_BRANCH9, R_ARM_THM_JUMP8},
1713 {BFD_RELOC_THUMB_PCREL_BRANCH7, R_ARM_THM_JUMP6},
7f266840
DJ
1714 {BFD_RELOC_ARM_GLOB_DAT, R_ARM_GLOB_DAT},
1715 {BFD_RELOC_ARM_JUMP_SLOT, R_ARM_JUMP_SLOT},
1716 {BFD_RELOC_ARM_RELATIVE, R_ARM_RELATIVE},
c19d1205 1717 {BFD_RELOC_ARM_GOTOFF, R_ARM_GOTOFF32},
7f266840
DJ
1718 {BFD_RELOC_ARM_GOTPC, R_ARM_GOTPC},
1719 {BFD_RELOC_ARM_GOT32, R_ARM_GOT32},
1720 {BFD_RELOC_ARM_PLT32, R_ARM_PLT32},
1721 {BFD_RELOC_ARM_TARGET1, R_ARM_TARGET1},
1722 {BFD_RELOC_ARM_ROSEGREL32, R_ARM_ROSEGREL32},
1723 {BFD_RELOC_ARM_SBREL32, R_ARM_SBREL32},
1724 {BFD_RELOC_ARM_PREL31, R_ARM_PREL31},
ba93b8ac
DJ
1725 {BFD_RELOC_ARM_TARGET2, R_ARM_TARGET2},
1726 {BFD_RELOC_ARM_PLT32, R_ARM_PLT32},
1727 {BFD_RELOC_ARM_TLS_GD32, R_ARM_TLS_GD32},
1728 {BFD_RELOC_ARM_TLS_LDO32, R_ARM_TLS_LDO32},
1729 {BFD_RELOC_ARM_TLS_LDM32, R_ARM_TLS_LDM32},
1730 {BFD_RELOC_ARM_TLS_DTPMOD32, R_ARM_TLS_DTPMOD32},
1731 {BFD_RELOC_ARM_TLS_DTPOFF32, R_ARM_TLS_DTPOFF32},
1732 {BFD_RELOC_ARM_TLS_TPOFF32, R_ARM_TLS_TPOFF32},
1733 {BFD_RELOC_ARM_TLS_IE32, R_ARM_TLS_IE32},
1734 {BFD_RELOC_ARM_TLS_LE32, R_ARM_TLS_LE32},
c19d1205
ZW
1735 {BFD_RELOC_VTABLE_INHERIT, R_ARM_GNU_VTINHERIT},
1736 {BFD_RELOC_VTABLE_ENTRY, R_ARM_GNU_VTENTRY},
b6895b4f
PB
1737 {BFD_RELOC_ARM_MOVW, R_ARM_MOVW_ABS_NC},
1738 {BFD_RELOC_ARM_MOVT, R_ARM_MOVT_ABS},
1739 {BFD_RELOC_ARM_MOVW_PCREL, R_ARM_MOVW_PREL_NC},
1740 {BFD_RELOC_ARM_MOVT_PCREL, R_ARM_MOVT_PREL},
1741 {BFD_RELOC_ARM_THUMB_MOVW, R_ARM_THM_MOVW_ABS_NC},
1742 {BFD_RELOC_ARM_THUMB_MOVT, R_ARM_THM_MOVT_ABS},
1743 {BFD_RELOC_ARM_THUMB_MOVW_PCREL, R_ARM_THM_MOVW_PREL_NC},
1744 {BFD_RELOC_ARM_THUMB_MOVT_PCREL, R_ARM_THM_MOVT_PREL},
4962c51a
MS
1745 {BFD_RELOC_ARM_ALU_PC_G0_NC, R_ARM_ALU_PC_G0_NC},
1746 {BFD_RELOC_ARM_ALU_PC_G0, R_ARM_ALU_PC_G0},
1747 {BFD_RELOC_ARM_ALU_PC_G1_NC, R_ARM_ALU_PC_G1_NC},
1748 {BFD_RELOC_ARM_ALU_PC_G1, R_ARM_ALU_PC_G1},
1749 {BFD_RELOC_ARM_ALU_PC_G2, R_ARM_ALU_PC_G2},
1750 {BFD_RELOC_ARM_LDR_PC_G0, R_ARM_LDR_PC_G0},
1751 {BFD_RELOC_ARM_LDR_PC_G1, R_ARM_LDR_PC_G1},
1752 {BFD_RELOC_ARM_LDR_PC_G2, R_ARM_LDR_PC_G2},
1753 {BFD_RELOC_ARM_LDRS_PC_G0, R_ARM_LDRS_PC_G0},
1754 {BFD_RELOC_ARM_LDRS_PC_G1, R_ARM_LDRS_PC_G1},
1755 {BFD_RELOC_ARM_LDRS_PC_G2, R_ARM_LDRS_PC_G2},
1756 {BFD_RELOC_ARM_LDC_PC_G0, R_ARM_LDC_PC_G0},
1757 {BFD_RELOC_ARM_LDC_PC_G1, R_ARM_LDC_PC_G1},
1758 {BFD_RELOC_ARM_LDC_PC_G2, R_ARM_LDC_PC_G2},
1759 {BFD_RELOC_ARM_ALU_SB_G0_NC, R_ARM_ALU_SB_G0_NC},
1760 {BFD_RELOC_ARM_ALU_SB_G0, R_ARM_ALU_SB_G0},
1761 {BFD_RELOC_ARM_ALU_SB_G1_NC, R_ARM_ALU_SB_G1_NC},
1762 {BFD_RELOC_ARM_ALU_SB_G1, R_ARM_ALU_SB_G1},
1763 {BFD_RELOC_ARM_ALU_SB_G2, R_ARM_ALU_SB_G2},
1764 {BFD_RELOC_ARM_LDR_SB_G0, R_ARM_LDR_SB_G0},
1765 {BFD_RELOC_ARM_LDR_SB_G1, R_ARM_LDR_SB_G1},
1766 {BFD_RELOC_ARM_LDR_SB_G2, R_ARM_LDR_SB_G2},
1767 {BFD_RELOC_ARM_LDRS_SB_G0, R_ARM_LDRS_SB_G0},
1768 {BFD_RELOC_ARM_LDRS_SB_G1, R_ARM_LDRS_SB_G1},
1769 {BFD_RELOC_ARM_LDRS_SB_G2, R_ARM_LDRS_SB_G2},
1770 {BFD_RELOC_ARM_LDC_SB_G0, R_ARM_LDC_SB_G0},
1771 {BFD_RELOC_ARM_LDC_SB_G1, R_ARM_LDC_SB_G1},
845b51d6
PB
1772 {BFD_RELOC_ARM_LDC_SB_G2, R_ARM_LDC_SB_G2},
1773 {BFD_RELOC_ARM_V4BX, R_ARM_V4BX}
7f266840
DJ
1774 };
1775
1776static reloc_howto_type *
f1c71a59
ZW
1777elf32_arm_reloc_type_lookup (bfd *abfd ATTRIBUTE_UNUSED,
1778 bfd_reloc_code_real_type code)
7f266840
DJ
1779{
1780 unsigned int i;
8029a119 1781
906e58ca 1782 for (i = 0; i < ARRAY_SIZE (elf32_arm_reloc_map); i ++)
c19d1205
ZW
1783 if (elf32_arm_reloc_map[i].bfd_reloc_val == code)
1784 return elf32_arm_howto_from_type (elf32_arm_reloc_map[i].elf_reloc_val);
7f266840 1785
c19d1205 1786 return NULL;
7f266840
DJ
1787}
1788
157090f7
AM
1789static reloc_howto_type *
1790elf32_arm_reloc_name_lookup (bfd *abfd ATTRIBUTE_UNUSED,
1791 const char *r_name)
1792{
1793 unsigned int i;
1794
906e58ca 1795 for (i = 0; i < ARRAY_SIZE (elf32_arm_howto_table_1); i++)
157090f7
AM
1796 if (elf32_arm_howto_table_1[i].name != NULL
1797 && strcasecmp (elf32_arm_howto_table_1[i].name, r_name) == 0)
1798 return &elf32_arm_howto_table_1[i];
1799
906e58ca 1800 for (i = 0; i < ARRAY_SIZE (elf32_arm_howto_table_2); i++)
157090f7
AM
1801 if (elf32_arm_howto_table_2[i].name != NULL
1802 && strcasecmp (elf32_arm_howto_table_2[i].name, r_name) == 0)
1803 return &elf32_arm_howto_table_2[i];
1804
1805 return NULL;
1806}
1807
906e58ca
NC
1808/* Support for core dump NOTE sections. */
1809
7f266840 1810static bfd_boolean
f1c71a59 1811elf32_arm_nabi_grok_prstatus (bfd *abfd, Elf_Internal_Note *note)
7f266840
DJ
1812{
1813 int offset;
1814 size_t size;
1815
1816 switch (note->descsz)
1817 {
1818 default:
1819 return FALSE;
1820
8029a119 1821 case 148: /* Linux/ARM 32-bit. */
7f266840
DJ
1822 /* pr_cursig */
1823 elf_tdata (abfd)->core_signal = bfd_get_16 (abfd, note->descdata + 12);
1824
1825 /* pr_pid */
1826 elf_tdata (abfd)->core_pid = bfd_get_32 (abfd, note->descdata + 24);
1827
1828 /* pr_reg */
1829 offset = 72;
1830 size = 72;
1831
1832 break;
1833 }
1834
1835 /* Make a ".reg/999" section. */
1836 return _bfd_elfcore_make_pseudosection (abfd, ".reg",
1837 size, note->descpos + offset);
1838}
1839
1840static bfd_boolean
f1c71a59 1841elf32_arm_nabi_grok_psinfo (bfd *abfd, Elf_Internal_Note *note)
7f266840
DJ
1842{
1843 switch (note->descsz)
1844 {
1845 default:
1846 return FALSE;
1847
8029a119 1848 case 124: /* Linux/ARM elf_prpsinfo. */
7f266840
DJ
1849 elf_tdata (abfd)->core_program
1850 = _bfd_elfcore_strndup (abfd, note->descdata + 28, 16);
1851 elf_tdata (abfd)->core_command
1852 = _bfd_elfcore_strndup (abfd, note->descdata + 44, 80);
1853 }
1854
1855 /* Note that for some reason, a spurious space is tacked
1856 onto the end of the args in some (at least one anyway)
1857 implementations, so strip it off if it exists. */
7f266840
DJ
1858 {
1859 char *command = elf_tdata (abfd)->core_command;
1860 int n = strlen (command);
1861
1862 if (0 < n && command[n - 1] == ' ')
1863 command[n - 1] = '\0';
1864 }
1865
1866 return TRUE;
1867}
1868
1869#define TARGET_LITTLE_SYM bfd_elf32_littlearm_vec
1870#define TARGET_LITTLE_NAME "elf32-littlearm"
1871#define TARGET_BIG_SYM bfd_elf32_bigarm_vec
1872#define TARGET_BIG_NAME "elf32-bigarm"
1873
1874#define elf_backend_grok_prstatus elf32_arm_nabi_grok_prstatus
1875#define elf_backend_grok_psinfo elf32_arm_nabi_grok_psinfo
1876
252b5132
RH
1877typedef unsigned long int insn32;
1878typedef unsigned short int insn16;
1879
3a4a14e9
PB
1880/* In lieu of proper flags, assume all EABIv4 or later objects are
1881 interworkable. */
57e8b36a 1882#define INTERWORK_FLAG(abfd) \
3a4a14e9 1883 (EF_ARM_EABI_VERSION (elf_elfheader (abfd)->e_flags) >= EF_ARM_EABI_VER4 \
85a84e7a 1884 || (elf_elfheader (abfd)->e_flags & EF_ARM_INTERWORK))
9b485d32 1885
252b5132
RH
1886/* The linker script knows the section names for placement.
1887 The entry_names are used to do simple name mangling on the stubs.
1888 Given a function name, and its type, the stub can be found. The
9b485d32 1889 name can be changed. The only requirement is the %s be present. */
252b5132
RH
1890#define THUMB2ARM_GLUE_SECTION_NAME ".glue_7t"
1891#define THUMB2ARM_GLUE_ENTRY_NAME "__%s_from_thumb"
1892
1893#define ARM2THUMB_GLUE_SECTION_NAME ".glue_7"
1894#define ARM2THUMB_GLUE_ENTRY_NAME "__%s_from_arm"
1895
c7b8f16e
JB
1896#define VFP11_ERRATUM_VENEER_SECTION_NAME ".vfp11_veneer"
1897#define VFP11_ERRATUM_VENEER_ENTRY_NAME "__vfp11_veneer_%x"
1898
845b51d6
PB
1899#define ARM_BX_GLUE_SECTION_NAME ".v4_bx"
1900#define ARM_BX_GLUE_ENTRY_NAME "__bx_r%d"
1901
7413f23f
DJ
1902#define STUB_ENTRY_NAME "__%s_veneer"
1903
252b5132
RH
1904/* The name of the dynamic interpreter. This is put in the .interp
1905 section. */
1906#define ELF_DYNAMIC_INTERPRETER "/usr/lib/ld.so.1"
1907
5e681ec4
PB
1908#ifdef FOUR_WORD_PLT
1909
252b5132
RH
1910/* The first entry in a procedure linkage table looks like
1911 this. It is set up so that any shared library function that is
59f2c4e7 1912 called before the relocation has been set up calls the dynamic
9b485d32 1913 linker first. */
e5a52504 1914static const bfd_vma elf32_arm_plt0_entry [] =
5e681ec4
PB
1915 {
1916 0xe52de004, /* str lr, [sp, #-4]! */
1917 0xe59fe010, /* ldr lr, [pc, #16] */
1918 0xe08fe00e, /* add lr, pc, lr */
1919 0xe5bef008, /* ldr pc, [lr, #8]! */
1920 };
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, #NN */
1927 0xe28cca00, /* add ip, ip, #NN */
1928 0xe5bcf000, /* ldr pc, [ip, #NN]! */
1929 0x00000000, /* unused */
1930 };
1931
1932#else
1933
5e681ec4
PB
1934/* The first entry in a procedure linkage table looks like
1935 this. It is set up so that any shared library function that is
1936 called before the relocation has been set up calls the dynamic
1937 linker first. */
e5a52504 1938static const bfd_vma elf32_arm_plt0_entry [] =
917583ad 1939 {
5e681ec4
PB
1940 0xe52de004, /* str lr, [sp, #-4]! */
1941 0xe59fe004, /* ldr lr, [pc, #4] */
1942 0xe08fe00e, /* add lr, pc, lr */
1943 0xe5bef008, /* ldr pc, [lr, #8]! */
1944 0x00000000, /* &GOT[0] - . */
917583ad 1945 };
252b5132
RH
1946
1947/* Subsequent entries in a procedure linkage table look like
1948 this. */
e5a52504 1949static const bfd_vma elf32_arm_plt_entry [] =
5e681ec4
PB
1950 {
1951 0xe28fc600, /* add ip, pc, #0xNN00000 */
1952 0xe28cca00, /* add ip, ip, #0xNN000 */
1953 0xe5bcf000, /* ldr pc, [ip, #0xNNN]! */
1954 };
1955
1956#endif
252b5132 1957
00a97672
RS
1958/* The format of the first entry in the procedure linkage table
1959 for a VxWorks executable. */
1960static const bfd_vma elf32_arm_vxworks_exec_plt0_entry[] =
1961 {
1962 0xe52dc008, /* str ip,[sp,#-8]! */
1963 0xe59fc000, /* ldr ip,[pc] */
1964 0xe59cf008, /* ldr pc,[ip,#8] */
1965 0x00000000, /* .long _GLOBAL_OFFSET_TABLE_ */
1966 };
1967
1968/* The format of subsequent entries in a VxWorks executable. */
1969static const bfd_vma elf32_arm_vxworks_exec_plt_entry[] =
1970 {
1971 0xe59fc000, /* ldr ip,[pc] */
1972 0xe59cf000, /* ldr pc,[ip] */
1973 0x00000000, /* .long @got */
1974 0xe59fc000, /* ldr ip,[pc] */
1975 0xea000000, /* b _PLT */
1976 0x00000000, /* .long @pltindex*sizeof(Elf32_Rela) */
1977 };
1978
1979/* The format of entries in a VxWorks shared library. */
1980static const bfd_vma elf32_arm_vxworks_shared_plt_entry[] =
1981 {
1982 0xe59fc000, /* ldr ip,[pc] */
1983 0xe79cf009, /* ldr pc,[ip,r9] */
1984 0x00000000, /* .long @got */
1985 0xe59fc000, /* ldr ip,[pc] */
1986 0xe599f008, /* ldr pc,[r9,#8] */
1987 0x00000000, /* .long @pltindex*sizeof(Elf32_Rela) */
1988 };
1989
b7693d02
DJ
1990/* An initial stub used if the PLT entry is referenced from Thumb code. */
1991#define PLT_THUMB_STUB_SIZE 4
1992static const bfd_vma elf32_arm_plt_thumb_stub [] =
1993 {
1994 0x4778, /* bx pc */
1995 0x46c0 /* nop */
1996 };
1997
e5a52504
MM
1998/* The entries in a PLT when using a DLL-based target with multiple
1999 address spaces. */
906e58ca 2000static const bfd_vma elf32_arm_symbian_plt_entry [] =
e5a52504 2001 {
83a358aa 2002 0xe51ff004, /* ldr pc, [pc, #-4] */
e5a52504
MM
2003 0x00000000, /* dcd R_ARM_GLOB_DAT(X) */
2004 };
2005
906e58ca
NC
2006#define ARM_MAX_FWD_BRANCH_OFFSET ((((1 << 23) - 1) << 2) + 8)
2007#define ARM_MAX_BWD_BRANCH_OFFSET ((-((1 << 23) << 2)) + 8)
2008#define THM_MAX_FWD_BRANCH_OFFSET ((1 << 22) -2 + 4)
2009#define THM_MAX_BWD_BRANCH_OFFSET (-(1 << 22) + 4)
2010#define THM2_MAX_FWD_BRANCH_OFFSET (((1 << 24) - 2) + 4)
2011#define THM2_MAX_BWD_BRANCH_OFFSET (-(1 << 24) + 4)
2012
461a49ca
DJ
2013enum stub_insn_type
2014 {
2015 THUMB16_TYPE = 1,
2016 THUMB32_TYPE,
2017 ARM_TYPE,
2018 DATA_TYPE
2019 };
2020
461a49ca
DJ
2021#define THUMB16_INSN(X) {(X), THUMB16_TYPE, R_ARM_NONE, 0}
2022#define THUMB32_INSN(X) {(X), THUMB32_TYPE, R_ARM_NONE, 0}
2023#define ARM_INSN(X) {(X), ARM_TYPE, R_ARM_NONE, 0}
2024#define ARM_REL_INSN(X, Z) {(X), ARM_TYPE, R_ARM_JUMP24, (Z)}
2025#define DATA_WORD(X,Y,Z) {(X), DATA_TYPE, (Y), (Z)}
2026
2027typedef struct
2028{
2029 bfd_vma data;
2030 enum stub_insn_type type;
ebe24dd4 2031 unsigned int r_type;
461a49ca
DJ
2032 int reloc_addend;
2033} insn_sequence;
2034
fea2b4d6
CL
2035/* Arm/Thumb -> Arm/Thumb long branch stub. On V5T and above, use blx
2036 to reach the stub if necessary. */
461a49ca 2037static const insn_sequence elf32_arm_stub_long_branch_any_any[] =
906e58ca 2038 {
461a49ca
DJ
2039 ARM_INSN(0xe51ff004), /* ldr pc, [pc, #-4] */
2040 DATA_WORD(0, R_ARM_ABS32, 0), /* dcd R_ARM_ABS32(X) */
906e58ca
NC
2041 };
2042
fea2b4d6
CL
2043/* V4T Arm -> Thumb long branch stub. Used on V4T where blx is not
2044 available. */
461a49ca 2045static const insn_sequence elf32_arm_stub_long_branch_v4t_arm_thumb[] =
906e58ca 2046 {
461a49ca
DJ
2047 ARM_INSN(0xe59fc000), /* ldr ip, [pc, #0] */
2048 ARM_INSN(0xe12fff1c), /* bx ip */
2049 DATA_WORD(0, R_ARM_ABS32, 0), /* dcd R_ARM_ABS32(X) */
906e58ca
NC
2050 };
2051
fea2b4d6
CL
2052/* Thumb -> Thumb long branch stub. Used on architectures which
2053 support only this mode, or on V4T where it is expensive to switch
2054 to ARM. */
461a49ca 2055static const insn_sequence elf32_arm_stub_long_branch_thumb_only[] =
906e58ca 2056 {
461a49ca
DJ
2057 THUMB16_INSN(0xb401), /* push {r0} */
2058 THUMB16_INSN(0x4802), /* ldr r0, [pc, #8] */
2059 THUMB16_INSN(0x4684), /* mov ip, r0 */
2060 THUMB16_INSN(0xbc01), /* pop {r0} */
2061 THUMB16_INSN(0x4760), /* bx ip */
2062 THUMB16_INSN(0xbf00), /* nop */
2063 DATA_WORD(0, R_ARM_ABS32, 0), /* dcd R_ARM_ABS32(X) */
906e58ca
NC
2064 };
2065
fea2b4d6
CL
2066/* V4T Thumb -> ARM long branch stub. Used on V4T where blx is not
2067 available. */
461a49ca 2068static const insn_sequence elf32_arm_stub_long_branch_v4t_thumb_arm[] =
906e58ca 2069 {
461a49ca
DJ
2070 THUMB16_INSN(0x4778), /* bx pc */
2071 THUMB16_INSN(0x46c0), /* nop */
2072 ARM_INSN(0xe51ff004), /* ldr pc, [pc, #-4] */
2073 DATA_WORD(0, R_ARM_ABS32, 0), /* dcd R_ARM_ABS32(X) */
906e58ca
NC
2074 };
2075
fea2b4d6
CL
2076/* V4T Thumb -> ARM short branch stub. Shorter variant of the above
2077 one, when the destination is close enough. */
461a49ca 2078static const insn_sequence elf32_arm_stub_short_branch_v4t_thumb_arm[] =
c820be07 2079 {
461a49ca
DJ
2080 THUMB16_INSN(0x4778), /* bx pc */
2081 THUMB16_INSN(0x46c0), /* nop */
2082 ARM_REL_INSN(0xea000000, -8), /* b (X-8) */
c820be07
NC
2083 };
2084
cf3eccff 2085/* ARM/Thumb -> ARM long branch stub, PIC. On V5T and above, use
fea2b4d6 2086 blx to reach the stub if necessary. */
cf3eccff 2087static const insn_sequence elf32_arm_stub_long_branch_any_arm_pic[] =
906e58ca 2088 {
461a49ca
DJ
2089 ARM_INSN(0xe59fc000), /* ldr r12, [pc] */
2090 ARM_INSN(0xe08ff00c), /* add pc, pc, ip */
2091 DATA_WORD(0, R_ARM_REL32, -4), /* dcd R_ARM_REL32(X-4) */
906e58ca
NC
2092 };
2093
cf3eccff
DJ
2094/* ARM/Thumb -> Thumb long branch stub, PIC. On V5T and above, use
2095 blx to reach the stub if necessary. We can not add into pc;
2096 it is not guaranteed to mode switch (different in ARMv6 and
2097 ARMv7). */
2098static const insn_sequence elf32_arm_stub_long_branch_any_thumb_pic[] =
2099 {
2100 ARM_INSN(0xe59fc004), /* ldr r12, [pc, #4] */
2101 ARM_INSN(0xe08fc00c), /* add ip, pc, ip */
2102 ARM_INSN(0xe12fff1c), /* bx ip */
2103 DATA_WORD(0, R_ARM_REL32, 0), /* dcd R_ARM_REL32(X) */
2104 };
2105
ebe24dd4
CL
2106/* V4T ARM -> ARM long branch stub, PIC. */
2107static const insn_sequence elf32_arm_stub_long_branch_v4t_arm_thumb_pic[] =
2108 {
2109 ARM_INSN(0xe59fc004), /* ldr ip, [pc, #4] */
2110 ARM_INSN(0xe08fc00c), /* add ip, pc, ip */
2111 ARM_INSN(0xe12fff1c), /* bx ip */
2112 DATA_WORD(0, R_ARM_REL32, 0), /* dcd R_ARM_REL32(X) */
2113 };
2114
2115/* V4T Thumb -> ARM long branch stub, PIC. */
2116static const insn_sequence elf32_arm_stub_long_branch_v4t_thumb_arm_pic[] =
2117 {
2118 THUMB16_INSN(0x4778), /* bx pc */
2119 THUMB16_INSN(0x46c0), /* nop */
2120 ARM_INSN(0xe59fc000), /* ldr ip, [pc, #0] */
2121 ARM_INSN(0xe08cf00f), /* add pc, ip, pc */
2122 DATA_WORD(0, R_ARM_REL32, -4), /* dcd R_ARM_REL32(X) */
2123 };
2124
2125/* Thumb -> Thumb long branch stub, PIC. Used on architectures which
2126 support only this mode, or on V4T where it is expensive to switch
2127 to ARM. */
2128static const insn_sequence elf32_arm_stub_long_branch_thumb_only_pic[] =
2129 {
2130 THUMB16_INSN(0xb401), /* push {r0} */
2131 THUMB16_INSN(0x4802), /* ldr r0, [pc, #8] */
2132 THUMB16_INSN(0x46fc), /* mov ip, pc */
2133 THUMB16_INSN(0x4484), /* add ip, r0 */
2134 THUMB16_INSN(0xbc01), /* pop {r0} */
2135 THUMB16_INSN(0x4760), /* bx ip */
2136 DATA_WORD(0, R_ARM_REL32, 4), /* dcd R_ARM_REL32(X) */
2137 };
2138
906e58ca
NC
2139/* Section name for stubs is the associated section name plus this
2140 string. */
2141#define STUB_SUFFIX ".stub"
2142
2143enum elf32_arm_stub_type
2144{
2145 arm_stub_none,
fea2b4d6
CL
2146 arm_stub_long_branch_any_any,
2147 arm_stub_long_branch_v4t_arm_thumb,
2148 arm_stub_long_branch_thumb_only,
2149 arm_stub_long_branch_v4t_thumb_arm,
2150 arm_stub_short_branch_v4t_thumb_arm,
cf3eccff
DJ
2151 arm_stub_long_branch_any_arm_pic,
2152 arm_stub_long_branch_any_thumb_pic,
ebe24dd4
CL
2153 arm_stub_long_branch_v4t_arm_thumb_pic,
2154 arm_stub_long_branch_v4t_thumb_arm_pic,
2155 arm_stub_long_branch_thumb_only_pic,
906e58ca
NC
2156};
2157
2158struct elf32_arm_stub_hash_entry
2159{
2160 /* Base hash table entry structure. */
2161 struct bfd_hash_entry root;
2162
2163 /* The stub section. */
2164 asection *stub_sec;
2165
2166 /* Offset within stub_sec of the beginning of this stub. */
2167 bfd_vma stub_offset;
2168
2169 /* Given the symbol's value and its section we can determine its final
2170 value when building the stubs (so the stub knows where to jump). */
2171 bfd_vma target_value;
2172 asection *target_section;
2173
461a49ca 2174 /* The stub type. */
906e58ca 2175 enum elf32_arm_stub_type stub_type;
461a49ca
DJ
2176 /* Its encoding size in bytes. */
2177 int stub_size;
2178 /* Its template. */
2179 const insn_sequence *stub_template;
2180 /* The size of the template (number of entries). */
2181 int stub_template_size;
906e58ca
NC
2182
2183 /* The symbol table entry, if any, that this was derived from. */
2184 struct elf32_arm_link_hash_entry *h;
2185
2186 /* Destination symbol type (STT_ARM_TFUNC, ...) */
2187 unsigned char st_type;
2188
2189 /* Where this stub is being called from, or, in the case of combined
2190 stub sections, the first input section in the group. */
2191 asection *id_sec;
7413f23f
DJ
2192
2193 /* The name for the local symbol at the start of this stub. The
2194 stub name in the hash table has to be unique; this does not, so
2195 it can be friendlier. */
2196 char *output_name;
906e58ca
NC
2197};
2198
e489d0ae
PB
2199/* Used to build a map of a section. This is required for mixed-endian
2200 code/data. */
2201
2202typedef struct elf32_elf_section_map
2203{
2204 bfd_vma vma;
2205 char type;
2206}
2207elf32_arm_section_map;
2208
c7b8f16e
JB
2209/* Information about a VFP11 erratum veneer, or a branch to such a veneer. */
2210
2211typedef enum
2212{
2213 VFP11_ERRATUM_BRANCH_TO_ARM_VENEER,
2214 VFP11_ERRATUM_BRANCH_TO_THUMB_VENEER,
2215 VFP11_ERRATUM_ARM_VENEER,
2216 VFP11_ERRATUM_THUMB_VENEER
2217}
2218elf32_vfp11_erratum_type;
2219
2220typedef struct elf32_vfp11_erratum_list
2221{
2222 struct elf32_vfp11_erratum_list *next;
2223 bfd_vma vma;
2224 union
2225 {
2226 struct
2227 {
2228 struct elf32_vfp11_erratum_list *veneer;
2229 unsigned int vfp_insn;
2230 } b;
2231 struct
2232 {
2233 struct elf32_vfp11_erratum_list *branch;
2234 unsigned int id;
2235 } v;
2236 } u;
2237 elf32_vfp11_erratum_type type;
2238}
2239elf32_vfp11_erratum_list;
2240
8e3de13a 2241typedef struct _arm_elf_section_data
e489d0ae
PB
2242{
2243 struct bfd_elf_section_data elf;
8e3de13a 2244 unsigned int mapcount;
c7b8f16e 2245 unsigned int mapsize;
e489d0ae 2246 elf32_arm_section_map *map;
c7b8f16e
JB
2247 unsigned int erratumcount;
2248 elf32_vfp11_erratum_list *erratumlist;
8e3de13a
NC
2249}
2250_arm_elf_section_data;
e489d0ae
PB
2251
2252#define elf32_arm_section_data(sec) \
8e3de13a 2253 ((_arm_elf_section_data *) elf_section_data (sec))
e489d0ae 2254
ba93b8ac
DJ
2255/* The size of the thread control block. */
2256#define TCB_SIZE 8
2257
0ffa91dd 2258struct elf_arm_obj_tdata
ba93b8ac
DJ
2259{
2260 struct elf_obj_tdata root;
2261
2262 /* tls_type for each local got entry. */
2263 char *local_got_tls_type;
ee065d83 2264
bf21ed78
MS
2265 /* Zero to warn when linking objects with incompatible enum sizes. */
2266 int no_enum_size_warning;
a9dc9481
JM
2267
2268 /* Zero to warn when linking objects with incompatible wchar_t sizes. */
2269 int no_wchar_size_warning;
ba93b8ac
DJ
2270};
2271
0ffa91dd
NC
2272#define elf_arm_tdata(bfd) \
2273 ((struct elf_arm_obj_tdata *) (bfd)->tdata.any)
ba93b8ac 2274
0ffa91dd
NC
2275#define elf32_arm_local_got_tls_type(bfd) \
2276 (elf_arm_tdata (bfd)->local_got_tls_type)
2277
2278#define is_arm_elf(bfd) \
2279 (bfd_get_flavour (bfd) == bfd_target_elf_flavour \
2280 && elf_tdata (bfd) != NULL \
2281 && elf_object_id (bfd) == ARM_ELF_TDATA)
ba93b8ac
DJ
2282
2283static bfd_boolean
2284elf32_arm_mkobject (bfd *abfd)
2285{
0ffa91dd
NC
2286 return bfd_elf_allocate_object (abfd, sizeof (struct elf_arm_obj_tdata),
2287 ARM_ELF_TDATA);
ba93b8ac
DJ
2288}
2289
252b5132
RH
2290/* The ARM linker needs to keep track of the number of relocs that it
2291 decides to copy in check_relocs for each symbol. This is so that
2292 it can discard PC relative relocs if it doesn't need them when
2293 linking with -Bsymbolic. We store the information in a field
2294 extending the regular ELF linker hash table. */
2295
ba93b8ac
DJ
2296/* This structure keeps track of the number of relocs we have copied
2297 for a given symbol. */
5e681ec4 2298struct elf32_arm_relocs_copied
917583ad
NC
2299 {
2300 /* Next section. */
5e681ec4 2301 struct elf32_arm_relocs_copied * next;
917583ad
NC
2302 /* A section in dynobj. */
2303 asection * section;
2304 /* Number of relocs copied in this section. */
2305 bfd_size_type count;
ba93b8ac
DJ
2306 /* Number of PC-relative relocs copied in this section. */
2307 bfd_size_type pc_count;
917583ad 2308 };
252b5132 2309
ba93b8ac
DJ
2310#define elf32_arm_hash_entry(ent) ((struct elf32_arm_link_hash_entry *)(ent))
2311
ba96a88f 2312/* Arm ELF linker hash entry. */
252b5132 2313struct elf32_arm_link_hash_entry
917583ad
NC
2314 {
2315 struct elf_link_hash_entry root;
252b5132 2316
917583ad 2317 /* Number of PC relative relocs copied for this symbol. */
5e681ec4 2318 struct elf32_arm_relocs_copied * relocs_copied;
b7693d02
DJ
2319
2320 /* We reference count Thumb references to a PLT entry separately,
2321 so that we can emit the Thumb trampoline only if needed. */
2322 bfd_signed_vma plt_thumb_refcount;
2323
bd97cb95
DJ
2324 /* Some references from Thumb code may be eliminated by BL->BLX
2325 conversion, so record them separately. */
2326 bfd_signed_vma plt_maybe_thumb_refcount;
2327
b7693d02
DJ
2328 /* Since PLT entries have variable size if the Thumb prologue is
2329 used, we need to record the index into .got.plt instead of
2330 recomputing it from the PLT offset. */
2331 bfd_signed_vma plt_got_offset;
ba93b8ac
DJ
2332
2333#define GOT_UNKNOWN 0
2334#define GOT_NORMAL 1
2335#define GOT_TLS_GD 2
2336#define GOT_TLS_IE 4
2337 unsigned char tls_type;
a4fd1a8e
PB
2338
2339 /* The symbol marking the real symbol location for exported thumb
2340 symbols with Arm stubs. */
2341 struct elf_link_hash_entry *export_glue;
906e58ca 2342
da5938a2 2343 /* A pointer to the most recently used stub hash entry against this
8029a119 2344 symbol. */
da5938a2 2345 struct elf32_arm_stub_hash_entry *stub_cache;
917583ad 2346 };
252b5132 2347
252b5132 2348/* Traverse an arm ELF linker hash table. */
252b5132
RH
2349#define elf32_arm_link_hash_traverse(table, func, info) \
2350 (elf_link_hash_traverse \
2351 (&(table)->root, \
b7693d02 2352 (bfd_boolean (*) (struct elf_link_hash_entry *, void *)) (func), \
252b5132
RH
2353 (info)))
2354
2355/* Get the ARM elf linker hash table from a link_info structure. */
2356#define elf32_arm_hash_table(info) \
2357 ((struct elf32_arm_link_hash_table *) ((info)->hash))
2358
906e58ca
NC
2359#define arm_stub_hash_lookup(table, string, create, copy) \
2360 ((struct elf32_arm_stub_hash_entry *) \
2361 bfd_hash_lookup ((table), (string), (create), (copy)))
2362
9b485d32 2363/* ARM ELF linker hash table. */
252b5132 2364struct elf32_arm_link_hash_table
906e58ca
NC
2365{
2366 /* The main hash table. */
2367 struct elf_link_hash_table root;
252b5132 2368
906e58ca
NC
2369 /* The size in bytes of the section containing the Thumb-to-ARM glue. */
2370 bfd_size_type thumb_glue_size;
252b5132 2371
906e58ca
NC
2372 /* The size in bytes of the section containing the ARM-to-Thumb glue. */
2373 bfd_size_type arm_glue_size;
252b5132 2374
906e58ca
NC
2375 /* The size in bytes of section containing the ARMv4 BX veneers. */
2376 bfd_size_type bx_glue_size;
845b51d6 2377
906e58ca
NC
2378 /* Offsets of ARMv4 BX veneers. Bit1 set if present, and Bit0 set when
2379 veneer has been populated. */
2380 bfd_vma bx_glue_offset[15];
845b51d6 2381
906e58ca
NC
2382 /* The size in bytes of the section containing glue for VFP11 erratum
2383 veneers. */
2384 bfd_size_type vfp11_erratum_glue_size;
c7b8f16e 2385
906e58ca
NC
2386 /* An arbitrary input BFD chosen to hold the glue sections. */
2387 bfd * bfd_of_glue_owner;
ba96a88f 2388
906e58ca
NC
2389 /* Nonzero to output a BE8 image. */
2390 int byteswap_code;
e489d0ae 2391
906e58ca
NC
2392 /* Zero if R_ARM_TARGET1 means R_ARM_ABS32.
2393 Nonzero if R_ARM_TARGET1 means R_ARM_REL32. */
2394 int target1_is_rel;
9c504268 2395
906e58ca
NC
2396 /* The relocation to use for R_ARM_TARGET2 relocations. */
2397 int target2_reloc;
eb043451 2398
906e58ca
NC
2399 /* 0 = Ignore R_ARM_V4BX.
2400 1 = Convert BX to MOV PC.
2401 2 = Generate v4 interworing stubs. */
2402 int fix_v4bx;
319850b4 2403
906e58ca
NC
2404 /* Nonzero if the ARM/Thumb BLX instructions are available for use. */
2405 int use_blx;
33bfe774 2406
906e58ca
NC
2407 /* What sort of code sequences we should look for which may trigger the
2408 VFP11 denorm erratum. */
2409 bfd_arm_vfp11_fix vfp11_fix;
c7b8f16e 2410
906e58ca
NC
2411 /* Global counter for the number of fixes we have emitted. */
2412 int num_vfp11_fixes;
c7b8f16e 2413
906e58ca
NC
2414 /* Nonzero to force PIC branch veneers. */
2415 int pic_veneer;
27e55c4d 2416
906e58ca
NC
2417 /* The number of bytes in the initial entry in the PLT. */
2418 bfd_size_type plt_header_size;
e5a52504 2419
906e58ca
NC
2420 /* The number of bytes in the subsequent PLT etries. */
2421 bfd_size_type plt_entry_size;
e5a52504 2422
906e58ca
NC
2423 /* True if the target system is VxWorks. */
2424 int vxworks_p;
00a97672 2425
906e58ca
NC
2426 /* True if the target system is Symbian OS. */
2427 int symbian_p;
e5a52504 2428
906e58ca
NC
2429 /* True if the target uses REL relocations. */
2430 int use_rel;
4e7fd91e 2431
906e58ca
NC
2432 /* Short-cuts to get to dynamic linker sections. */
2433 asection *sgot;
2434 asection *sgotplt;
2435 asection *srelgot;
2436 asection *splt;
2437 asection *srelplt;
2438 asection *sdynbss;
2439 asection *srelbss;
5e681ec4 2440
906e58ca
NC
2441 /* The (unloaded but important) VxWorks .rela.plt.unloaded section. */
2442 asection *srelplt2;
00a97672 2443
906e58ca
NC
2444 /* Data for R_ARM_TLS_LDM32 relocations. */
2445 union
2446 {
2447 bfd_signed_vma refcount;
2448 bfd_vma offset;
2449 } tls_ldm_got;
b7693d02 2450
906e58ca
NC
2451 /* Small local sym to section mapping cache. */
2452 struct sym_sec_cache sym_sec;
2453
2454 /* For convenience in allocate_dynrelocs. */
2455 bfd * obfd;
2456
2457 /* The stub hash table. */
2458 struct bfd_hash_table stub_hash_table;
2459
2460 /* Linker stub bfd. */
2461 bfd *stub_bfd;
2462
2463 /* Linker call-backs. */
2464 asection * (*add_stub_section) (const char *, asection *);
2465 void (*layout_sections_again) (void);
2466
2467 /* Array to keep track of which stub sections have been created, and
2468 information on stub grouping. */
2469 struct map_stub
2470 {
2471 /* This is the section to which stubs in the group will be
2472 attached. */
2473 asection *link_sec;
2474 /* The stub section. */
2475 asection *stub_sec;
2476 } *stub_group;
2477
2478 /* Assorted information used by elf32_arm_size_stubs. */
2479 unsigned int bfd_count;
2480 int top_index;
2481 asection **input_list;
2482};
252b5132 2483
780a67af
NC
2484/* Create an entry in an ARM ELF linker hash table. */
2485
2486static struct bfd_hash_entry *
57e8b36a
NC
2487elf32_arm_link_hash_newfunc (struct bfd_hash_entry * entry,
2488 struct bfd_hash_table * table,
2489 const char * string)
780a67af
NC
2490{
2491 struct elf32_arm_link_hash_entry * ret =
2492 (struct elf32_arm_link_hash_entry *) entry;
2493
2494 /* Allocate the structure if it has not already been allocated by a
2495 subclass. */
906e58ca 2496 if (ret == NULL)
57e8b36a
NC
2497 ret = bfd_hash_allocate (table, sizeof (struct elf32_arm_link_hash_entry));
2498 if (ret == NULL)
780a67af
NC
2499 return (struct bfd_hash_entry *) ret;
2500
2501 /* Call the allocation method of the superclass. */
2502 ret = ((struct elf32_arm_link_hash_entry *)
2503 _bfd_elf_link_hash_newfunc ((struct bfd_hash_entry *) ret,
2504 table, string));
57e8b36a 2505 if (ret != NULL)
b7693d02
DJ
2506 {
2507 ret->relocs_copied = NULL;
ba93b8ac 2508 ret->tls_type = GOT_UNKNOWN;
b7693d02 2509 ret->plt_thumb_refcount = 0;
bd97cb95 2510 ret->plt_maybe_thumb_refcount = 0;
b7693d02 2511 ret->plt_got_offset = -1;
a4fd1a8e 2512 ret->export_glue = NULL;
906e58ca
NC
2513
2514 ret->stub_cache = NULL;
b7693d02 2515 }
780a67af
NC
2516
2517 return (struct bfd_hash_entry *) ret;
2518}
2519
906e58ca
NC
2520/* Initialize an entry in the stub hash table. */
2521
2522static struct bfd_hash_entry *
2523stub_hash_newfunc (struct bfd_hash_entry *entry,
2524 struct bfd_hash_table *table,
2525 const char *string)
2526{
2527 /* Allocate the structure if it has not already been allocated by a
2528 subclass. */
2529 if (entry == NULL)
2530 {
2531 entry = bfd_hash_allocate (table,
2532 sizeof (struct elf32_arm_stub_hash_entry));
2533 if (entry == NULL)
2534 return entry;
2535 }
2536
2537 /* Call the allocation method of the superclass. */
2538 entry = bfd_hash_newfunc (entry, table, string);
2539 if (entry != NULL)
2540 {
2541 struct elf32_arm_stub_hash_entry *eh;
2542
2543 /* Initialize the local fields. */
2544 eh = (struct elf32_arm_stub_hash_entry *) entry;
2545 eh->stub_sec = NULL;
2546 eh->stub_offset = 0;
2547 eh->target_value = 0;
2548 eh->target_section = NULL;
2549 eh->stub_type = arm_stub_none;
461a49ca
DJ
2550 eh->stub_size = 0;
2551 eh->stub_template = NULL;
2552 eh->stub_template_size = 0;
906e58ca
NC
2553 eh->h = NULL;
2554 eh->id_sec = NULL;
2555 }
2556
2557 return entry;
2558}
2559
00a97672 2560/* Create .got, .gotplt, and .rel(a).got sections in DYNOBJ, and set up
5e681ec4
PB
2561 shortcuts to them in our hash table. */
2562
2563static bfd_boolean
57e8b36a 2564create_got_section (bfd *dynobj, struct bfd_link_info *info)
5e681ec4
PB
2565{
2566 struct elf32_arm_link_hash_table *htab;
2567
e5a52504
MM
2568 htab = elf32_arm_hash_table (info);
2569 /* BPABI objects never have a GOT, or associated sections. */
2570 if (htab->symbian_p)
2571 return TRUE;
2572
5e681ec4
PB
2573 if (! _bfd_elf_create_got_section (dynobj, info))
2574 return FALSE;
2575
5e681ec4
PB
2576 htab->sgot = bfd_get_section_by_name (dynobj, ".got");
2577 htab->sgotplt = bfd_get_section_by_name (dynobj, ".got.plt");
2578 if (!htab->sgot || !htab->sgotplt)
2579 abort ();
2580
00a97672
RS
2581 htab->srelgot = bfd_make_section_with_flags (dynobj,
2582 RELOC_SECTION (htab, ".got"),
3496cb2a
L
2583 (SEC_ALLOC | SEC_LOAD
2584 | SEC_HAS_CONTENTS
2585 | SEC_IN_MEMORY
2586 | SEC_LINKER_CREATED
2587 | SEC_READONLY));
5e681ec4 2588 if (htab->srelgot == NULL
5e681ec4
PB
2589 || ! bfd_set_section_alignment (dynobj, htab->srelgot, 2))
2590 return FALSE;
2591 return TRUE;
2592}
2593
00a97672
RS
2594/* Create .plt, .rel(a).plt, .got, .got.plt, .rel(a).got, .dynbss, and
2595 .rel(a).bss sections in DYNOBJ, and set up shortcuts to them in our
5e681ec4
PB
2596 hash table. */
2597
2598static bfd_boolean
57e8b36a 2599elf32_arm_create_dynamic_sections (bfd *dynobj, struct bfd_link_info *info)
5e681ec4
PB
2600{
2601 struct elf32_arm_link_hash_table *htab;
2602
2603 htab = elf32_arm_hash_table (info);
2604 if (!htab->sgot && !create_got_section (dynobj, info))
2605 return FALSE;
2606
2607 if (!_bfd_elf_create_dynamic_sections (dynobj, info))
2608 return FALSE;
2609
2610 htab->splt = bfd_get_section_by_name (dynobj, ".plt");
00a97672
RS
2611 htab->srelplt = bfd_get_section_by_name (dynobj,
2612 RELOC_SECTION (htab, ".plt"));
5e681ec4
PB
2613 htab->sdynbss = bfd_get_section_by_name (dynobj, ".dynbss");
2614 if (!info->shared)
00a97672
RS
2615 htab->srelbss = bfd_get_section_by_name (dynobj,
2616 RELOC_SECTION (htab, ".bss"));
2617
2618 if (htab->vxworks_p)
2619 {
2620 if (!elf_vxworks_create_dynamic_sections (dynobj, info, &htab->srelplt2))
2621 return FALSE;
2622
2623 if (info->shared)
2624 {
2625 htab->plt_header_size = 0;
2626 htab->plt_entry_size
2627 = 4 * ARRAY_SIZE (elf32_arm_vxworks_shared_plt_entry);
2628 }
2629 else
2630 {
2631 htab->plt_header_size
2632 = 4 * ARRAY_SIZE (elf32_arm_vxworks_exec_plt0_entry);
2633 htab->plt_entry_size
2634 = 4 * ARRAY_SIZE (elf32_arm_vxworks_exec_plt_entry);
2635 }
2636 }
5e681ec4 2637
906e58ca 2638 if (!htab->splt
e5a52504
MM
2639 || !htab->srelplt
2640 || !htab->sdynbss
5e681ec4
PB
2641 || (!info->shared && !htab->srelbss))
2642 abort ();
2643
2644 return TRUE;
2645}
2646
906e58ca
NC
2647/* Copy the extra info we tack onto an elf_link_hash_entry. */
2648
2649static void
2650elf32_arm_copy_indirect_symbol (struct bfd_link_info *info,
2651 struct elf_link_hash_entry *dir,
2652 struct elf_link_hash_entry *ind)
2653{
2654 struct elf32_arm_link_hash_entry *edir, *eind;
2655
2656 edir = (struct elf32_arm_link_hash_entry *) dir;
2657 eind = (struct elf32_arm_link_hash_entry *) ind;
2658
2659 if (eind->relocs_copied != NULL)
2660 {
2661 if (edir->relocs_copied != NULL)
2662 {
2663 struct elf32_arm_relocs_copied **pp;
2664 struct elf32_arm_relocs_copied *p;
2665
2666 /* Add reloc counts against the indirect sym to the direct sym
2667 list. Merge any entries against the same section. */
2668 for (pp = &eind->relocs_copied; (p = *pp) != NULL; )
2669 {
2670 struct elf32_arm_relocs_copied *q;
2671
2672 for (q = edir->relocs_copied; q != NULL; q = q->next)
2673 if (q->section == p->section)
2674 {
2675 q->pc_count += p->pc_count;
2676 q->count += p->count;
2677 *pp = p->next;
2678 break;
2679 }
2680 if (q == NULL)
2681 pp = &p->next;
2682 }
2683 *pp = edir->relocs_copied;
2684 }
2685
2686 edir->relocs_copied = eind->relocs_copied;
2687 eind->relocs_copied = NULL;
2688 }
2689
2690 if (ind->root.type == bfd_link_hash_indirect)
2691 {
2692 /* Copy over PLT info. */
2693 edir->plt_thumb_refcount += eind->plt_thumb_refcount;
2694 eind->plt_thumb_refcount = 0;
2695 edir->plt_maybe_thumb_refcount += eind->plt_maybe_thumb_refcount;
2696 eind->plt_maybe_thumb_refcount = 0;
2697
2698 if (dir->got.refcount <= 0)
2699 {
2700 edir->tls_type = eind->tls_type;
2701 eind->tls_type = GOT_UNKNOWN;
2702 }
2703 }
2704
2705 _bfd_elf_link_hash_copy_indirect (info, dir, ind);
2706}
2707
2708/* Create an ARM elf linker hash table. */
2709
2710static struct bfd_link_hash_table *
2711elf32_arm_link_hash_table_create (bfd *abfd)
2712{
2713 struct elf32_arm_link_hash_table *ret;
2714 bfd_size_type amt = sizeof (struct elf32_arm_link_hash_table);
2715
2716 ret = bfd_malloc (amt);
2717 if (ret == NULL)
2718 return NULL;
2719
2720 if (!_bfd_elf_link_hash_table_init (& ret->root, abfd,
2721 elf32_arm_link_hash_newfunc,
2722 sizeof (struct elf32_arm_link_hash_entry)))
2723 {
2724 free (ret);
2725 return NULL;
2726 }
2727
2728 ret->sgot = NULL;
2729 ret->sgotplt = NULL;
2730 ret->srelgot = NULL;
2731 ret->splt = NULL;
2732 ret->srelplt = NULL;
2733 ret->sdynbss = NULL;
2734 ret->srelbss = NULL;
2735 ret->srelplt2 = NULL;
2736 ret->thumb_glue_size = 0;
2737 ret->arm_glue_size = 0;
2738 ret->bx_glue_size = 0;
2739 memset (ret->bx_glue_offset, 0, sizeof (ret->bx_glue_offset));
2740 ret->vfp11_fix = BFD_ARM_VFP11_FIX_NONE;
2741 ret->vfp11_erratum_glue_size = 0;
2742 ret->num_vfp11_fixes = 0;
2743 ret->bfd_of_glue_owner = NULL;
2744 ret->byteswap_code = 0;
2745 ret->target1_is_rel = 0;
2746 ret->target2_reloc = R_ARM_NONE;
2747#ifdef FOUR_WORD_PLT
2748 ret->plt_header_size = 16;
2749 ret->plt_entry_size = 16;
2750#else
2751 ret->plt_header_size = 20;
2752 ret->plt_entry_size = 12;
2753#endif
2754 ret->fix_v4bx = 0;
2755 ret->use_blx = 0;
2756 ret->vxworks_p = 0;
2757 ret->symbian_p = 0;
2758 ret->use_rel = 1;
2759 ret->sym_sec.abfd = NULL;
2760 ret->obfd = abfd;
2761 ret->tls_ldm_got.refcount = 0;
6cee0a6f
L
2762 ret->stub_bfd = NULL;
2763 ret->add_stub_section = NULL;
2764 ret->layout_sections_again = NULL;
2765 ret->stub_group = NULL;
2766 ret->bfd_count = 0;
2767 ret->top_index = 0;
2768 ret->input_list = NULL;
906e58ca
NC
2769
2770 if (!bfd_hash_table_init (&ret->stub_hash_table, stub_hash_newfunc,
2771 sizeof (struct elf32_arm_stub_hash_entry)))
2772 {
2773 free (ret);
2774 return NULL;
2775 }
2776
2777 return &ret->root.root;
2778}
2779
2780/* Free the derived linker hash table. */
2781
2782static void
2783elf32_arm_hash_table_free (struct bfd_link_hash_table *hash)
2784{
2785 struct elf32_arm_link_hash_table *ret
2786 = (struct elf32_arm_link_hash_table *) hash;
2787
2788 bfd_hash_table_free (&ret->stub_hash_table);
2789 _bfd_generic_link_hash_table_free (hash);
2790}
2791
2792/* Determine if we're dealing with a Thumb only architecture. */
2793
2794static bfd_boolean
2795using_thumb_only (struct elf32_arm_link_hash_table *globals)
2796{
2797 int arch = bfd_elf_get_obj_attr_int (globals->obfd, OBJ_ATTR_PROC,
2798 Tag_CPU_arch);
2799 int profile;
2800
2801 if (arch != TAG_CPU_ARCH_V7)
2802 return FALSE;
2803
2804 profile = bfd_elf_get_obj_attr_int (globals->obfd, OBJ_ATTR_PROC,
2805 Tag_CPU_arch_profile);
2806
2807 return profile == 'M';
2808}
2809
2810/* Determine if we're dealing with a Thumb-2 object. */
2811
2812static bfd_boolean
2813using_thumb2 (struct elf32_arm_link_hash_table *globals)
2814{
2815 int arch = bfd_elf_get_obj_attr_int (globals->obfd, OBJ_ATTR_PROC,
2816 Tag_CPU_arch);
2817 return arch == TAG_CPU_ARCH_V6T2 || arch >= TAG_CPU_ARCH_V7;
2818}
2819
f4ac8484
DJ
2820static bfd_boolean
2821arm_stub_is_thumb (enum elf32_arm_stub_type stub_type)
2822{
2823 switch (stub_type)
2824 {
fea2b4d6
CL
2825 case arm_stub_long_branch_thumb_only:
2826 case arm_stub_long_branch_v4t_thumb_arm:
2827 case arm_stub_short_branch_v4t_thumb_arm:
ebe24dd4
CL
2828 case arm_stub_long_branch_v4t_thumb_arm_pic:
2829 case arm_stub_long_branch_thumb_only_pic:
f4ac8484
DJ
2830 return TRUE;
2831 case arm_stub_none:
2832 BFD_FAIL ();
2833 return FALSE;
2834 break;
2835 default:
2836 return FALSE;
2837 }
2838}
2839
906e58ca
NC
2840/* Determine the type of stub needed, if any, for a call. */
2841
2842static enum elf32_arm_stub_type
2843arm_type_of_stub (struct bfd_link_info *info,
2844 asection *input_sec,
2845 const Elf_Internal_Rela *rel,
2846 unsigned char st_type,
2847 struct elf32_arm_link_hash_entry *hash,
c820be07
NC
2848 bfd_vma destination,
2849 asection *sym_sec,
2850 bfd *input_bfd,
2851 const char *name)
906e58ca
NC
2852{
2853 bfd_vma location;
2854 bfd_signed_vma branch_offset;
2855 unsigned int r_type;
2856 struct elf32_arm_link_hash_table * globals;
2857 int thumb2;
2858 int thumb_only;
2859 enum elf32_arm_stub_type stub_type = arm_stub_none;
2860
da5938a2 2861 /* We don't know the actual type of destination in case it is of
8029a119 2862 type STT_SECTION: give up. */
da5938a2
NC
2863 if (st_type == STT_SECTION)
2864 return stub_type;
2865
906e58ca
NC
2866 globals = elf32_arm_hash_table (info);
2867
2868 thumb_only = using_thumb_only (globals);
2869
2870 thumb2 = using_thumb2 (globals);
2871
2872 /* Determine where the call point is. */
2873 location = (input_sec->output_offset
2874 + input_sec->output_section->vma
2875 + rel->r_offset);
2876
2877 branch_offset = (bfd_signed_vma)(destination - location);
2878
2879 r_type = ELF32_R_TYPE (rel->r_info);
2880
2881 /* If the call will go through a PLT entry then we do not need
2882 glue. */
329dcd78 2883 if (globals->splt != NULL && hash != NULL && hash->root.plt.offset != (bfd_vma) -1)
906e58ca
NC
2884 return stub_type;
2885
2886 if (r_type == R_ARM_THM_CALL)
2887 {
2888 if ((!thumb2
2889 && (branch_offset > THM_MAX_FWD_BRANCH_OFFSET
2890 || (branch_offset < THM_MAX_BWD_BRANCH_OFFSET)))
2891 || (thumb2
2892 && (branch_offset > THM2_MAX_FWD_BRANCH_OFFSET
2893 || (branch_offset < THM2_MAX_BWD_BRANCH_OFFSET)))
2894 || ((st_type != STT_ARM_TFUNC) && !globals->use_blx))
2895 {
2896 if (st_type == STT_ARM_TFUNC)
2897 {
2898 /* Thumb to thumb. */
2899 if (!thumb_only)
2900 {
2901 stub_type = (info->shared | globals->pic_veneer)
c2b4a39d 2902 /* PIC stubs. */
906e58ca 2903 ? ((globals->use_blx)
c2b4a39d 2904 /* V5T and above. */
cf3eccff 2905 ? arm_stub_long_branch_any_thumb_pic
ebe24dd4
CL
2906 /* On V4T, use Thumb code only. */
2907 : arm_stub_long_branch_thumb_only_pic)
c2b4a39d
CL
2908
2909 /* non-PIC stubs. */
2910 : ((globals->use_blx)
2911 /* V5T and above. */
2912 ? arm_stub_long_branch_any_any
2913 /* V4T. */
2914 : arm_stub_long_branch_thumb_only);
906e58ca
NC
2915 }
2916 else
2917 {
2918 stub_type = (info->shared | globals->pic_veneer)
ebe24dd4
CL
2919 /* PIC stub. */
2920 ? arm_stub_long_branch_thumb_only_pic
c2b4a39d
CL
2921 /* non-PIC stub. */
2922 : arm_stub_long_branch_thumb_only;
906e58ca
NC
2923 }
2924 }
2925 else
2926 {
2927 /* Thumb to arm. */
c820be07
NC
2928 if (sym_sec != NULL
2929 && sym_sec->owner != NULL
2930 && !INTERWORK_FLAG (sym_sec->owner))
2931 {
2932 (*_bfd_error_handler)
2933 (_("%B(%s): warning: interworking not enabled.\n"
2934 " first occurrence: %B: Thumb call to ARM"),
2935 sym_sec->owner, input_bfd, name);
2936 }
2937
906e58ca 2938 stub_type = (info->shared | globals->pic_veneer)
c2b4a39d 2939 /* PIC stubs. */
906e58ca 2940 ? ((globals->use_blx)
c2b4a39d 2941 /* V5T and above. */
cf3eccff 2942 ? arm_stub_long_branch_any_arm_pic
ebe24dd4
CL
2943 /* V4T PIC stub. */
2944 : arm_stub_long_branch_v4t_thumb_arm_pic)
c2b4a39d
CL
2945
2946 /* non-PIC stubs. */
2947 : ((globals->use_blx)
2948 /* V5T and above. */
2949 ? arm_stub_long_branch_any_any
2950 /* V4T. */
2951 : arm_stub_long_branch_v4t_thumb_arm);
c820be07
NC
2952
2953 /* Handle v4t short branches. */
fea2b4d6 2954 if ((stub_type == arm_stub_long_branch_v4t_thumb_arm)
c820be07
NC
2955 && (branch_offset <= THM_MAX_FWD_BRANCH_OFFSET)
2956 && (branch_offset >= THM_MAX_BWD_BRANCH_OFFSET))
fea2b4d6 2957 stub_type = arm_stub_short_branch_v4t_thumb_arm;
906e58ca
NC
2958 }
2959 }
2960 }
2961 else if (r_type == R_ARM_CALL)
2962 {
2963 if (st_type == STT_ARM_TFUNC)
2964 {
2965 /* Arm to thumb. */
c820be07
NC
2966
2967 if (sym_sec != NULL
2968 && sym_sec->owner != NULL
2969 && !INTERWORK_FLAG (sym_sec->owner))
2970 {
2971 (*_bfd_error_handler)
2972 (_("%B(%s): warning: interworking not enabled.\n"
c2b4a39d 2973 " first occurrence: %B: ARM call to Thumb"),
c820be07
NC
2974 sym_sec->owner, input_bfd, name);
2975 }
2976
2977 /* We have an extra 2-bytes reach because of
2978 the mode change (bit 24 (H) of BLX encoding). */
906e58ca
NC
2979 if (branch_offset > (ARM_MAX_FWD_BRANCH_OFFSET + 2)
2980 || (branch_offset < ARM_MAX_BWD_BRANCH_OFFSET)
2981 || !globals->use_blx)
2982 {
2983 stub_type = (info->shared | globals->pic_veneer)
c2b4a39d 2984 /* PIC stubs. */
ebe24dd4
CL
2985 ? ((globals->use_blx)
2986 /* V5T and above. */
2987 ? arm_stub_long_branch_any_thumb_pic
2988 /* V4T stub. */
2989 : arm_stub_long_branch_v4t_arm_thumb_pic)
2990
c2b4a39d
CL
2991 /* non-PIC stubs. */
2992 : ((globals->use_blx)
2993 /* V5T and above. */
2994 ? arm_stub_long_branch_any_any
2995 /* V4T. */
2996 : arm_stub_long_branch_v4t_arm_thumb);
906e58ca
NC
2997 }
2998 }
2999 else
3000 {
3001 /* Arm to arm. */
3002 if (branch_offset > ARM_MAX_FWD_BRANCH_OFFSET
3003 || (branch_offset < ARM_MAX_BWD_BRANCH_OFFSET))
3004 {
3005 stub_type = (info->shared | globals->pic_veneer)
c2b4a39d 3006 /* PIC stubs. */
cf3eccff 3007 ? arm_stub_long_branch_any_arm_pic
c2b4a39d 3008 /* non-PIC stubs. */
fea2b4d6 3009 : arm_stub_long_branch_any_any;
906e58ca
NC
3010 }
3011 }
3012 }
3013
3014 return stub_type;
3015}
3016
3017/* Build a name for an entry in the stub hash table. */
3018
3019static char *
3020elf32_arm_stub_name (const asection *input_section,
3021 const asection *sym_sec,
3022 const struct elf32_arm_link_hash_entry *hash,
3023 const Elf_Internal_Rela *rel)
3024{
3025 char *stub_name;
3026 bfd_size_type len;
3027
3028 if (hash)
3029 {
3030 len = 8 + 1 + strlen (hash->root.root.root.string) + 1 + 8 + 1;
3031 stub_name = bfd_malloc (len);
3032 if (stub_name != NULL)
3033 sprintf (stub_name, "%08x_%s+%x",
3034 input_section->id & 0xffffffff,
3035 hash->root.root.root.string,
3036 (int) rel->r_addend & 0xffffffff);
3037 }
3038 else
3039 {
3040 len = 8 + 1 + 8 + 1 + 8 + 1 + 8 + 1;
3041 stub_name = bfd_malloc (len);
3042 if (stub_name != NULL)
3043 sprintf (stub_name, "%08x_%x:%x+%x",
3044 input_section->id & 0xffffffff,
3045 sym_sec->id & 0xffffffff,
3046 (int) ELF32_R_SYM (rel->r_info) & 0xffffffff,
3047 (int) rel->r_addend & 0xffffffff);
3048 }
3049
3050 return stub_name;
3051}
3052
3053/* Look up an entry in the stub hash. Stub entries are cached because
3054 creating the stub name takes a bit of time. */
3055
3056static struct elf32_arm_stub_hash_entry *
3057elf32_arm_get_stub_entry (const asection *input_section,
3058 const asection *sym_sec,
3059 struct elf_link_hash_entry *hash,
3060 const Elf_Internal_Rela *rel,
3061 struct elf32_arm_link_hash_table *htab)
3062{
3063 struct elf32_arm_stub_hash_entry *stub_entry;
3064 struct elf32_arm_link_hash_entry *h = (struct elf32_arm_link_hash_entry *) hash;
3065 const asection *id_sec;
3066
3067 if ((input_section->flags & SEC_CODE) == 0)
3068 return NULL;
3069
3070 /* If this input section is part of a group of sections sharing one
3071 stub section, then use the id of the first section in the group.
3072 Stub names need to include a section id, as there may well be
3073 more than one stub used to reach say, printf, and we need to
3074 distinguish between them. */
3075 id_sec = htab->stub_group[input_section->id].link_sec;
3076
3077 if (h != NULL && h->stub_cache != NULL
3078 && h->stub_cache->h == h
3079 && h->stub_cache->id_sec == id_sec)
3080 {
3081 stub_entry = h->stub_cache;
3082 }
3083 else
3084 {
3085 char *stub_name;
3086
3087 stub_name = elf32_arm_stub_name (id_sec, sym_sec, h, rel);
3088 if (stub_name == NULL)
3089 return NULL;
3090
3091 stub_entry = arm_stub_hash_lookup (&htab->stub_hash_table,
3092 stub_name, FALSE, FALSE);
3093 if (h != NULL)
3094 h->stub_cache = stub_entry;
3095
3096 free (stub_name);
3097 }
3098
3099 return stub_entry;
3100}
3101
906e58ca
NC
3102/* Add a new stub entry to the stub hash. Not all fields of the new
3103 stub entry are initialised. */
3104
3105static struct elf32_arm_stub_hash_entry *
3106elf32_arm_add_stub (const char *stub_name,
3107 asection *section,
da5938a2 3108 struct elf32_arm_link_hash_table *htab)
906e58ca
NC
3109{
3110 asection *link_sec;
3111 asection *stub_sec;
3112 struct elf32_arm_stub_hash_entry *stub_entry;
3113
3114 link_sec = htab->stub_group[section->id].link_sec;
3115 stub_sec = htab->stub_group[section->id].stub_sec;
3116 if (stub_sec == NULL)
3117 {
3118 stub_sec = htab->stub_group[link_sec->id].stub_sec;
3119 if (stub_sec == NULL)
3120 {
3121 size_t namelen;
3122 bfd_size_type len;
3123 char *s_name;
3124
3125 namelen = strlen (link_sec->name);
3126 len = namelen + sizeof (STUB_SUFFIX);
3127 s_name = bfd_alloc (htab->stub_bfd, len);
3128 if (s_name == NULL)
3129 return NULL;
3130
3131 memcpy (s_name, link_sec->name, namelen);
3132 memcpy (s_name + namelen, STUB_SUFFIX, sizeof (STUB_SUFFIX));
3133 stub_sec = (*htab->add_stub_section) (s_name, link_sec);
3134 if (stub_sec == NULL)
3135 return NULL;
3136 htab->stub_group[link_sec->id].stub_sec = stub_sec;
3137 }
3138 htab->stub_group[section->id].stub_sec = stub_sec;
3139 }
3140
3141 /* Enter this entry into the linker stub hash table. */
3142 stub_entry = arm_stub_hash_lookup (&htab->stub_hash_table, stub_name,
3143 TRUE, FALSE);
3144 if (stub_entry == NULL)
3145 {
3146 (*_bfd_error_handler) (_("%s: cannot create stub entry %s"),
3147 section->owner,
3148 stub_name);
3149 return NULL;
3150 }
3151
3152 stub_entry->stub_sec = stub_sec;
3153 stub_entry->stub_offset = 0;
3154 stub_entry->id_sec = link_sec;
3155
906e58ca
NC
3156 return stub_entry;
3157}
3158
3159/* Store an Arm insn into an output section not processed by
3160 elf32_arm_write_section. */
3161
3162static void
8029a119
NC
3163put_arm_insn (struct elf32_arm_link_hash_table * htab,
3164 bfd * output_bfd, bfd_vma val, void * ptr)
906e58ca
NC
3165{
3166 if (htab->byteswap_code != bfd_little_endian (output_bfd))
3167 bfd_putl32 (val, ptr);
3168 else
3169 bfd_putb32 (val, ptr);
3170}
3171
3172/* Store a 16-bit Thumb insn into an output section not processed by
3173 elf32_arm_write_section. */
3174
3175static void
8029a119
NC
3176put_thumb_insn (struct elf32_arm_link_hash_table * htab,
3177 bfd * output_bfd, bfd_vma val, void * ptr)
906e58ca
NC
3178{
3179 if (htab->byteswap_code != bfd_little_endian (output_bfd))
3180 bfd_putl16 (val, ptr);
3181 else
3182 bfd_putb16 (val, ptr);
3183}
3184
3185static bfd_boolean
3186arm_build_one_stub (struct bfd_hash_entry *gen_entry,
3187 void * in_arg)
3188{
3189 struct elf32_arm_stub_hash_entry *stub_entry;
3190 struct bfd_link_info *info;
3191 struct elf32_arm_link_hash_table *htab;
3192 asection *stub_sec;
3193 bfd *stub_bfd;
3194 bfd_vma stub_addr;
3195 bfd_byte *loc;
3196 bfd_vma sym_value;
3197 int template_size;
3198 int size;
461a49ca 3199 const insn_sequence *template;
906e58ca
NC
3200 int i;
3201 struct elf32_arm_link_hash_table * globals;
461a49ca 3202 int stub_reloc_idx = -1;
4e31c731 3203 int stub_reloc_offset = 0;
906e58ca
NC
3204
3205 /* Massage our args to the form they really have. */
3206 stub_entry = (struct elf32_arm_stub_hash_entry *) gen_entry;
3207 info = (struct bfd_link_info *) in_arg;
3208
3209 globals = elf32_arm_hash_table (info);
3210
3211 htab = elf32_arm_hash_table (info);
3212 stub_sec = stub_entry->stub_sec;
3213
3214 /* Make a note of the offset within the stubs for this entry. */
3215 stub_entry->stub_offset = stub_sec->size;
3216 loc = stub_sec->contents + stub_entry->stub_offset;
3217
3218 stub_bfd = stub_sec->owner;
3219
3220 /* This is the address of the start of the stub. */
3221 stub_addr = stub_sec->output_section->vma + stub_sec->output_offset
3222 + stub_entry->stub_offset;
3223
3224 /* This is the address of the stub destination. */
3225 sym_value = (stub_entry->target_value
3226 + stub_entry->target_section->output_offset
3227 + stub_entry->target_section->output_section->vma);
3228
461a49ca
DJ
3229 template = stub_entry->stub_template;
3230 template_size = stub_entry->stub_template_size;
906e58ca
NC
3231
3232 size = 0;
461a49ca 3233 for (i = 0; i < template_size; i++)
906e58ca 3234 {
4e31c731 3235 switch (template[i].type)
461a49ca
DJ
3236 {
3237 case THUMB16_TYPE:
3238 put_thumb_insn (globals, stub_bfd, template[i].data, loc + size);
3239 size += 2;
3240 break;
906e58ca 3241
461a49ca
DJ
3242 case ARM_TYPE:
3243 put_arm_insn (globals, stub_bfd, template[i].data, loc + size);
3244 /* Handle cases where the target is encoded within the
3245 instruction. */
ebe24dd4 3246 if (template[i].r_type == R_ARM_JUMP24)
461a49ca
DJ
3247 {
3248 stub_reloc_idx = i;
3249 stub_reloc_offset = size;
3250 }
3251 size += 4;
3252 break;
3253
3254 case DATA_TYPE:
3255 bfd_put_32 (stub_bfd, template[i].data, loc + size);
3256 stub_reloc_idx = i;
3257 stub_reloc_offset = size;
3258 size += 4;
3259 break;
3260
3261 default:
3262 BFD_FAIL ();
3263 return FALSE;
3264 }
906e58ca 3265 }
461a49ca 3266
906e58ca
NC
3267 stub_sec->size += size;
3268
461a49ca
DJ
3269 /* Stub size has already been computed in arm_size_one_stub. Check
3270 consistency. */
3271 BFD_ASSERT (size == stub_entry->stub_size);
3272
906e58ca
NC
3273 /* Destination is Thumb. Force bit 0 to 1 to reflect this. */
3274 if (stub_entry->st_type == STT_ARM_TFUNC)
3275 sym_value |= 1;
3276
461a49ca
DJ
3277 /* Assume there is one and only one entry to relocate in each stub. */
3278 BFD_ASSERT (stub_reloc_idx != -1);
c820be07 3279
ebe24dd4 3280 _bfd_final_link_relocate (elf32_arm_howto_from_type (template[stub_reloc_idx].r_type),
461a49ca
DJ
3281 stub_bfd, stub_sec, stub_sec->contents,
3282 stub_entry->stub_offset + stub_reloc_offset,
3283 sym_value, template[stub_reloc_idx].reloc_addend);
906e58ca
NC
3284
3285 return TRUE;
3286}
3287
3288/* As above, but don't actually build the stub. Just bump offset so
3289 we know stub section sizes. */
3290
3291static bfd_boolean
3292arm_size_one_stub (struct bfd_hash_entry *gen_entry,
3293 void * in_arg)
3294{
3295 struct elf32_arm_stub_hash_entry *stub_entry;
3296 struct elf32_arm_link_hash_table *htab;
461a49ca 3297 const insn_sequence *template;
906e58ca
NC
3298 int template_size;
3299 int size;
3300 int i;
3301
3302 /* Massage our args to the form they really have. */
3303 stub_entry = (struct elf32_arm_stub_hash_entry *) gen_entry;
3304 htab = (struct elf32_arm_link_hash_table *) in_arg;
3305
3306 switch (stub_entry->stub_type)
3307 {
fea2b4d6
CL
3308 case arm_stub_long_branch_any_any:
3309 template = elf32_arm_stub_long_branch_any_any;
ebe24dd4 3310 template_size = ARRAY_SIZE (elf32_arm_stub_long_branch_any_any);
906e58ca 3311 break;
fea2b4d6
CL
3312 case arm_stub_long_branch_v4t_arm_thumb:
3313 template = elf32_arm_stub_long_branch_v4t_arm_thumb;
ebe24dd4 3314 template_size = ARRAY_SIZE (elf32_arm_stub_long_branch_v4t_arm_thumb);
906e58ca 3315 break;
fea2b4d6
CL
3316 case arm_stub_long_branch_thumb_only:
3317 template = elf32_arm_stub_long_branch_thumb_only;
ebe24dd4 3318 template_size = ARRAY_SIZE (elf32_arm_stub_long_branch_thumb_only);
906e58ca 3319 break;
fea2b4d6
CL
3320 case arm_stub_long_branch_v4t_thumb_arm:
3321 template = elf32_arm_stub_long_branch_v4t_thumb_arm;
ebe24dd4 3322 template_size = ARRAY_SIZE (elf32_arm_stub_long_branch_v4t_thumb_arm);
906e58ca 3323 break;
fea2b4d6
CL
3324 case arm_stub_short_branch_v4t_thumb_arm:
3325 template = elf32_arm_stub_short_branch_v4t_thumb_arm;
ebe24dd4 3326 template_size = ARRAY_SIZE (elf32_arm_stub_short_branch_v4t_thumb_arm);
c820be07 3327 break;
cf3eccff
DJ
3328 case arm_stub_long_branch_any_arm_pic:
3329 template = elf32_arm_stub_long_branch_any_arm_pic;
ebe24dd4 3330 template_size = ARRAY_SIZE (elf32_arm_stub_long_branch_any_arm_pic);
cf3eccff
DJ
3331 break;
3332 case arm_stub_long_branch_any_thumb_pic:
3333 template = elf32_arm_stub_long_branch_any_thumb_pic;
ebe24dd4
CL
3334 template_size = ARRAY_SIZE (elf32_arm_stub_long_branch_any_thumb_pic);
3335 break;
3336 case arm_stub_long_branch_v4t_arm_thumb_pic:
3337 template = elf32_arm_stub_long_branch_v4t_arm_thumb_pic;
3338 template_size = ARRAY_SIZE (elf32_arm_stub_long_branch_v4t_arm_thumb_pic);
3339 break;
3340 case arm_stub_long_branch_v4t_thumb_arm_pic:
3341 template = elf32_arm_stub_long_branch_v4t_thumb_arm_pic;
3342 template_size = ARRAY_SIZE (elf32_arm_stub_long_branch_v4t_thumb_arm_pic);
3343 break;
3344 case arm_stub_long_branch_thumb_only_pic:
3345 template = elf32_arm_stub_long_branch_thumb_only_pic;
3346 template_size = ARRAY_SIZE (elf32_arm_stub_long_branch_thumb_only_pic);
906e58ca
NC
3347 break;
3348 default:
3349 BFD_FAIL ();
3350 return FALSE;
906e58ca
NC
3351 }
3352
3353 size = 0;
461a49ca
DJ
3354 for (i = 0; i < template_size; i++)
3355 {
4e31c731 3356 switch (template[i].type)
461a49ca
DJ
3357 {
3358 case THUMB16_TYPE:
3359 size += 2;
3360 break;
3361
3362 case ARM_TYPE:
3363 size += 4;
3364 break;
3365
3366 case DATA_TYPE:
3367 size += 4;
3368 break;
3369
3370 default:
3371 BFD_FAIL ();
3372 return FALSE;
3373 }
3374 }
3375
3376 stub_entry->stub_size = size;
3377 stub_entry->stub_template = template;
3378 stub_entry->stub_template_size = template_size;
3379
906e58ca
NC
3380 size = (size + 7) & ~7;
3381 stub_entry->stub_sec->size += size;
461a49ca 3382
906e58ca
NC
3383 return TRUE;
3384}
3385
3386/* External entry points for sizing and building linker stubs. */
3387
3388/* Set up various things so that we can make a list of input sections
3389 for each output section included in the link. Returns -1 on error,
3390 0 when no stubs will be needed, and 1 on success. */
3391
3392int
3393elf32_arm_setup_section_lists (bfd *output_bfd,
3394 struct bfd_link_info *info)
3395{
3396 bfd *input_bfd;
3397 unsigned int bfd_count;
3398 int top_id, top_index;
3399 asection *section;
3400 asection **input_list, **list;
3401 bfd_size_type amt;
3402 struct elf32_arm_link_hash_table *htab = elf32_arm_hash_table (info);
3403
3404 if (! is_elf_hash_table (htab))
3405 return 0;
3406
3407 /* Count the number of input BFDs and find the top input section id. */
3408 for (input_bfd = info->input_bfds, bfd_count = 0, top_id = 0;
3409 input_bfd != NULL;
3410 input_bfd = input_bfd->link_next)
3411 {
3412 bfd_count += 1;
3413 for (section = input_bfd->sections;
3414 section != NULL;
3415 section = section->next)
3416 {
3417 if (top_id < section->id)
3418 top_id = section->id;
3419 }
3420 }
3421 htab->bfd_count = bfd_count;
3422
3423 amt = sizeof (struct map_stub) * (top_id + 1);
3424 htab->stub_group = bfd_zmalloc (amt);
3425 if (htab->stub_group == NULL)
3426 return -1;
3427
3428 /* We can't use output_bfd->section_count here to find the top output
3429 section index as some sections may have been removed, and
3430 _bfd_strip_section_from_output doesn't renumber the indices. */
3431 for (section = output_bfd->sections, top_index = 0;
3432 section != NULL;
3433 section = section->next)
3434 {
3435 if (top_index < section->index)
3436 top_index = section->index;
3437 }
3438
3439 htab->top_index = top_index;
3440 amt = sizeof (asection *) * (top_index + 1);
3441 input_list = bfd_malloc (amt);
3442 htab->input_list = input_list;
3443 if (input_list == NULL)
3444 return -1;
3445
3446 /* For sections we aren't interested in, mark their entries with a
3447 value we can check later. */
3448 list = input_list + top_index;
3449 do
3450 *list = bfd_abs_section_ptr;
3451 while (list-- != input_list);
3452
3453 for (section = output_bfd->sections;
3454 section != NULL;
3455 section = section->next)
3456 {
3457 if ((section->flags & SEC_CODE) != 0)
3458 input_list[section->index] = NULL;
3459 }
3460
3461 return 1;
3462}
3463
3464/* The linker repeatedly calls this function for each input section,
3465 in the order that input sections are linked into output sections.
3466 Build lists of input sections to determine groupings between which
3467 we may insert linker stubs. */
3468
3469void
3470elf32_arm_next_input_section (struct bfd_link_info *info,
3471 asection *isec)
3472{
3473 struct elf32_arm_link_hash_table *htab = elf32_arm_hash_table (info);
3474
3475 if (isec->output_section->index <= htab->top_index)
3476 {
3477 asection **list = htab->input_list + isec->output_section->index;
3478
3479 if (*list != bfd_abs_section_ptr)
3480 {
3481 /* Steal the link_sec pointer for our list. */
3482#define PREV_SEC(sec) (htab->stub_group[(sec)->id].link_sec)
3483 /* This happens to make the list in reverse order,
07d72278 3484 which we reverse later. */
906e58ca
NC
3485 PREV_SEC (isec) = *list;
3486 *list = isec;
3487 }
3488 }
3489}
3490
3491/* See whether we can group stub sections together. Grouping stub
3492 sections may result in fewer stubs. More importantly, we need to
07d72278 3493 put all .init* and .fini* stubs at the end of the .init or
906e58ca
NC
3494 .fini output sections respectively, because glibc splits the
3495 _init and _fini functions into multiple parts. Putting a stub in
3496 the middle of a function is not a good idea. */
3497
3498static void
3499group_sections (struct elf32_arm_link_hash_table *htab,
3500 bfd_size_type stub_group_size,
07d72278 3501 bfd_boolean stubs_always_after_branch)
906e58ca 3502{
07d72278 3503 asection **list = htab->input_list;
906e58ca
NC
3504
3505 do
3506 {
3507 asection *tail = *list;
07d72278
DJ
3508 asection *head;
3509 asection *tp;
906e58ca
NC
3510
3511 if (tail == bfd_abs_section_ptr)
3512 continue;
3513
07d72278
DJ
3514 /* Reverse the list: we must avoid placing stubs at the
3515 beginning of the section because the beginning of the text
3516 section may be required for an interrupt vector in bare metal
3517 code. */
3518#define NEXT_SEC PREV_SEC
3519 head = tail;
3520 tp = NULL;
3521 for (;;)
3522 {
3523 asection *h = PREV_SEC (head);
3524 NEXT_SEC (head) = tp;
3525 if (h == NULL)
3526 break;
3527 tp = head;
3528 head = h;
3529 }
3530
3531 while (head != NULL)
906e58ca
NC
3532 {
3533 asection *curr;
07d72278 3534 asection *next;
906e58ca
NC
3535 bfd_size_type total;
3536
07d72278
DJ
3537 curr = head;
3538 total = head->size;
3539 while ((next = NEXT_SEC (curr)) != NULL
3540 && ((total += next->output_offset - curr->output_offset)
906e58ca 3541 < stub_group_size))
07d72278 3542 curr = next;
906e58ca 3543
07d72278 3544 /* OK, the size from the start to the start of CURR is less
906e58ca 3545 than stub_group_size and thus can be handled by one stub
07d72278 3546 section. (Or the head section is itself larger than
906e58ca
NC
3547 stub_group_size, in which case we may be toast.)
3548 We should really be keeping track of the total size of
3549 stubs added here, as stubs contribute to the final output
7fb9f789 3550 section size. */
906e58ca
NC
3551 do
3552 {
07d72278 3553 next = NEXT_SEC (head);
906e58ca 3554 /* Set up this stub group. */
07d72278 3555 htab->stub_group[head->id].link_sec = curr;
906e58ca 3556 }
07d72278 3557 while (head != curr && (head = next) != NULL);
906e58ca
NC
3558
3559 /* But wait, there's more! Input sections up to stub_group_size
07d72278
DJ
3560 bytes after the stub section can be handled by it too. */
3561 if (!stubs_always_after_branch)
906e58ca
NC
3562 {
3563 total = 0;
07d72278
DJ
3564 while (next != NULL
3565 && ((total += next->output_offset - head->output_offset)
906e58ca
NC
3566 < stub_group_size))
3567 {
07d72278
DJ
3568 head = next;
3569 next = NEXT_SEC (head);
3570 htab->stub_group[head->id].link_sec = curr;
906e58ca
NC
3571 }
3572 }
07d72278 3573 head = next;
906e58ca
NC
3574 }
3575 }
07d72278 3576 while (list++ != htab->input_list + htab->top_index);
906e58ca
NC
3577
3578 free (htab->input_list);
3579#undef PREV_SEC
07d72278 3580#undef NEXT_SEC
906e58ca
NC
3581}
3582
3583/* Determine and set the size of the stub section for a final link.
3584
3585 The basic idea here is to examine all the relocations looking for
3586 PC-relative calls to a target that is unreachable with a "bl"
3587 instruction. */
3588
3589bfd_boolean
3590elf32_arm_size_stubs (bfd *output_bfd,
3591 bfd *stub_bfd,
3592 struct bfd_link_info *info,
3593 bfd_signed_vma group_size,
3594 asection * (*add_stub_section) (const char *, asection *),
3595 void (*layout_sections_again) (void))
3596{
3597 bfd_size_type stub_group_size;
07d72278 3598 bfd_boolean stubs_always_after_branch;
906e58ca
NC
3599 bfd_boolean stub_changed = 0;
3600 struct elf32_arm_link_hash_table *htab = elf32_arm_hash_table (info);
3601
3602 /* Propagate mach to stub bfd, because it may not have been
3603 finalized when we created stub_bfd. */
3604 bfd_set_arch_mach (stub_bfd, bfd_get_arch (output_bfd),
3605 bfd_get_mach (output_bfd));
3606
3607 /* Stash our params away. */
3608 htab->stub_bfd = stub_bfd;
3609 htab->add_stub_section = add_stub_section;
3610 htab->layout_sections_again = layout_sections_again;
07d72278 3611 stubs_always_after_branch = group_size < 0;
906e58ca
NC
3612 if (group_size < 0)
3613 stub_group_size = -group_size;
3614 else
3615 stub_group_size = group_size;
3616
3617 if (stub_group_size == 1)
3618 {
3619 /* Default values. */
3620 /* Thumb branch range is +-4MB has to be used as the default
3621 maximum size (a given section can contain both ARM and Thumb
3622 code, so the worst case has to be taken into account).
3623
3624 This value is 24K less than that, which allows for 2025
3625 12-byte stubs. If we exceed that, then we will fail to link.
3626 The user will have to relink with an explicit group size
3627 option. */
3628 stub_group_size = 4170000;
3629 }
3630
07d72278 3631 group_sections (htab, stub_group_size, stubs_always_after_branch);
906e58ca
NC
3632
3633 while (1)
3634 {
3635 bfd *input_bfd;
3636 unsigned int bfd_indx;
3637 asection *stub_sec;
3638
3639 for (input_bfd = info->input_bfds, bfd_indx = 0;
3640 input_bfd != NULL;
3641 input_bfd = input_bfd->link_next, bfd_indx++)
3642 {
3643 Elf_Internal_Shdr *symtab_hdr;
3644 asection *section;
3645 Elf_Internal_Sym *local_syms = NULL;
3646
3647 /* We'll need the symbol table in a second. */
3648 symtab_hdr = &elf_tdata (input_bfd)->symtab_hdr;
3649 if (symtab_hdr->sh_info == 0)
3650 continue;
3651
3652 /* Walk over each section attached to the input bfd. */
3653 for (section = input_bfd->sections;
3654 section != NULL;
3655 section = section->next)
3656 {
3657 Elf_Internal_Rela *internal_relocs, *irelaend, *irela;
3658
3659 /* If there aren't any relocs, then there's nothing more
3660 to do. */
3661 if ((section->flags & SEC_RELOC) == 0
3662 || section->reloc_count == 0
3663 || (section->flags & SEC_CODE) == 0)
3664 continue;
3665
3666 /* If this section is a link-once section that will be
3667 discarded, then don't create any stubs. */
3668 if (section->output_section == NULL
3669 || section->output_section->owner != output_bfd)
3670 continue;
3671
3672 /* Get the relocs. */
3673 internal_relocs
3674 = _bfd_elf_link_read_relocs (input_bfd, section, NULL,
3675 NULL, info->keep_memory);
3676 if (internal_relocs == NULL)
3677 goto error_ret_free_local;
3678
3679 /* Now examine each relocation. */
3680 irela = internal_relocs;
3681 irelaend = irela + section->reloc_count;
3682 for (; irela < irelaend; irela++)
3683 {
3684 unsigned int r_type, r_indx;
3685 enum elf32_arm_stub_type stub_type;
3686 struct elf32_arm_stub_hash_entry *stub_entry;
3687 asection *sym_sec;
3688 bfd_vma sym_value;
3689 bfd_vma destination;
3690 struct elf32_arm_link_hash_entry *hash;
7413f23f 3691 const char *sym_name;
906e58ca
NC
3692 char *stub_name;
3693 const asection *id_sec;
3694 unsigned char st_type;
3695
3696 r_type = ELF32_R_TYPE (irela->r_info);
3697 r_indx = ELF32_R_SYM (irela->r_info);
3698
3699 if (r_type >= (unsigned int) R_ARM_max)
3700 {
3701 bfd_set_error (bfd_error_bad_value);
3702 error_ret_free_internal:
3703 if (elf_section_data (section)->relocs == NULL)
3704 free (internal_relocs);
3705 goto error_ret_free_local;
3706 }
3707
3708 /* Only look for stubs on call instructions. */
3709 if ((r_type != (unsigned int) R_ARM_CALL)
3710 && (r_type != (unsigned int) R_ARM_THM_CALL))
3711 continue;
3712
3713 /* Now determine the call target, its name, value,
3714 section. */
3715 sym_sec = NULL;
3716 sym_value = 0;
3717 destination = 0;
3718 hash = NULL;
7413f23f 3719 sym_name = NULL;
906e58ca
NC
3720 if (r_indx < symtab_hdr->sh_info)
3721 {
3722 /* It's a local symbol. */
3723 Elf_Internal_Sym *sym;
3724 Elf_Internal_Shdr *hdr;
3725
3726 if (local_syms == NULL)
3727 {
3728 local_syms
3729 = (Elf_Internal_Sym *) symtab_hdr->contents;
3730 if (local_syms == NULL)
3731 local_syms
3732 = bfd_elf_get_elf_syms (input_bfd, symtab_hdr,
3733 symtab_hdr->sh_info, 0,
3734 NULL, NULL, NULL);
3735 if (local_syms == NULL)
3736 goto error_ret_free_internal;
3737 }
3738
3739 sym = local_syms + r_indx;
3740 hdr = elf_elfsections (input_bfd)[sym->st_shndx];
3741 sym_sec = hdr->bfd_section;
3742 if (ELF_ST_TYPE (sym->st_info) != STT_SECTION)
3743 sym_value = sym->st_value;
3744 destination = (sym_value + irela->r_addend
3745 + sym_sec->output_offset
3746 + sym_sec->output_section->vma);
3747 st_type = ELF_ST_TYPE (sym->st_info);
7413f23f
DJ
3748 sym_name
3749 = bfd_elf_string_from_elf_section (input_bfd,
3750 symtab_hdr->sh_link,
3751 sym->st_name);
906e58ca
NC
3752 }
3753 else
3754 {
3755 /* It's an external symbol. */
3756 int e_indx;
3757
3758 e_indx = r_indx - symtab_hdr->sh_info;
3759 hash = ((struct elf32_arm_link_hash_entry *)
3760 elf_sym_hashes (input_bfd)[e_indx]);
3761
3762 while (hash->root.root.type == bfd_link_hash_indirect
3763 || hash->root.root.type == bfd_link_hash_warning)
3764 hash = ((struct elf32_arm_link_hash_entry *)
3765 hash->root.root.u.i.link);
3766
3767 if (hash->root.root.type == bfd_link_hash_defined
3768 || hash->root.root.type == bfd_link_hash_defweak)
3769 {
3770 sym_sec = hash->root.root.u.def.section;
3771 sym_value = hash->root.root.u.def.value;
3772 if (sym_sec->output_section != NULL)
3773 destination = (sym_value + irela->r_addend
3774 + sym_sec->output_offset
3775 + sym_sec->output_section->vma);
3776 }
3777 else if (hash->root.root.type == bfd_link_hash_undefweak
3778 || hash->root.root.type == bfd_link_hash_undefined)
3779 /* For a shared library, these will need a PLT stub,
3780 which is treated separately.
3781 For absolute code, they cannot be handled. */
3782 continue;
3783 else
3784 {
3785 bfd_set_error (bfd_error_bad_value);
3786 goto error_ret_free_internal;
3787 }
3788 st_type = ELF_ST_TYPE (hash->root.type);
7413f23f 3789 sym_name = hash->root.root.root.string;
906e58ca
NC
3790 }
3791
3792 /* Determine what (if any) linker stub is needed. */
3793 stub_type = arm_type_of_stub (info, section, irela, st_type,
c820be07
NC
3794 hash, destination, sym_sec,
3795 input_bfd, sym_name);
906e58ca
NC
3796 if (stub_type == arm_stub_none)
3797 continue;
5e681ec4 3798
906e58ca
NC
3799 /* Support for grouping stub sections. */
3800 id_sec = htab->stub_group[section->id].link_sec;
5e681ec4 3801
906e58ca
NC
3802 /* Get the name of this stub. */
3803 stub_name = elf32_arm_stub_name (id_sec, sym_sec, hash, irela);
3804 if (!stub_name)
3805 goto error_ret_free_internal;
5e681ec4 3806
906e58ca
NC
3807 stub_entry = arm_stub_hash_lookup (&htab->stub_hash_table,
3808 stub_name,
3809 FALSE, FALSE);
3810 if (stub_entry != NULL)
3811 {
3812 /* The proper stub has already been created. */
3813 free (stub_name);
3814 continue;
3815 }
5e681ec4 3816
da5938a2 3817 stub_entry = elf32_arm_add_stub (stub_name, section, htab);
906e58ca
NC
3818 if (stub_entry == NULL)
3819 {
3820 free (stub_name);
3821 goto error_ret_free_internal;
3822 }
5e681ec4 3823
906e58ca
NC
3824 stub_entry->target_value = sym_value;
3825 stub_entry->target_section = sym_sec;
3826 stub_entry->stub_type = stub_type;
3827 stub_entry->h = hash;
3828 stub_entry->st_type = st_type;
7413f23f
DJ
3829
3830 if (sym_name == NULL)
3831 sym_name = "unnamed";
3832 stub_entry->output_name
3833 = bfd_alloc (htab->stub_bfd,
3834 sizeof (THUMB2ARM_GLUE_ENTRY_NAME)
3835 + strlen (sym_name));
3836 if (stub_entry->output_name == NULL)
3837 {
3838 free (stub_name);
3839 goto error_ret_free_internal;
3840 }
3841
3842 /* For historical reasons, use the existing names for
3843 ARM-to-Thumb and Thumb-to-ARM stubs. */
3844 if (r_type == (unsigned int) R_ARM_THM_CALL
3845 && st_type != STT_ARM_TFUNC)
3846 sprintf (stub_entry->output_name, THUMB2ARM_GLUE_ENTRY_NAME,
3847 sym_name);
3848 else if (r_type == (unsigned int) R_ARM_CALL
3849 && st_type == STT_ARM_TFUNC)
3850 sprintf (stub_entry->output_name, ARM2THUMB_GLUE_ENTRY_NAME,
3851 sym_name);
3852 else
3853 sprintf (stub_entry->output_name, STUB_ENTRY_NAME,
3854 sym_name);
3855
906e58ca
NC
3856 stub_changed = TRUE;
3857 }
3858
3859 /* We're done with the internal relocs, free them. */
3860 if (elf_section_data (section)->relocs == NULL)
3861 free (internal_relocs);
5e681ec4 3862 }
5e681ec4
PB
3863 }
3864
906e58ca
NC
3865 if (!stub_changed)
3866 break;
5e681ec4 3867
906e58ca
NC
3868 /* OK, we've added some stubs. Find out the new size of the
3869 stub sections. */
3870 for (stub_sec = htab->stub_bfd->sections;
3871 stub_sec != NULL;
3872 stub_sec = stub_sec->next)
3873 stub_sec->size = 0;
b34b2d70 3874
906e58ca
NC
3875 bfd_hash_traverse (&htab->stub_hash_table, arm_size_one_stub, htab);
3876
3877 /* Ask the linker to do its stuff. */
3878 (*htab->layout_sections_again) ();
3879 stub_changed = FALSE;
ba93b8ac
DJ
3880 }
3881
906e58ca
NC
3882 return TRUE;
3883
3884 error_ret_free_local:
3885 return FALSE;
5e681ec4
PB
3886}
3887
906e58ca
NC
3888/* Build all the stubs associated with the current output file. The
3889 stubs are kept in a hash table attached to the main linker hash
3890 table. We also set up the .plt entries for statically linked PIC
3891 functions here. This function is called via arm_elf_finish in the
3892 linker. */
252b5132 3893
906e58ca
NC
3894bfd_boolean
3895elf32_arm_build_stubs (struct bfd_link_info *info)
252b5132 3896{
906e58ca
NC
3897 asection *stub_sec;
3898 struct bfd_hash_table *table;
3899 struct elf32_arm_link_hash_table *htab;
252b5132 3900
906e58ca 3901 htab = elf32_arm_hash_table (info);
252b5132 3902
906e58ca
NC
3903 for (stub_sec = htab->stub_bfd->sections;
3904 stub_sec != NULL;
3905 stub_sec = stub_sec->next)
252b5132 3906 {
906e58ca
NC
3907 bfd_size_type size;
3908
8029a119 3909 /* Ignore non-stub sections. */
906e58ca
NC
3910 if (!strstr (stub_sec->name, STUB_SUFFIX))
3911 continue;
3912
3913 /* Allocate memory to hold the linker stubs. */
3914 size = stub_sec->size;
3915 stub_sec->contents = bfd_zalloc (htab->stub_bfd, size);
3916 if (stub_sec->contents == NULL && size != 0)
3917 return FALSE;
3918 stub_sec->size = 0;
252b5132
RH
3919 }
3920
906e58ca
NC
3921 /* Build the stubs as directed by the stub hash table. */
3922 table = &htab->stub_hash_table;
3923 bfd_hash_traverse (table, arm_build_one_stub, info);
252b5132 3924
906e58ca 3925 return TRUE;
252b5132
RH
3926}
3927
9b485d32
NC
3928/* Locate the Thumb encoded calling stub for NAME. */
3929
252b5132 3930static struct elf_link_hash_entry *
57e8b36a
NC
3931find_thumb_glue (struct bfd_link_info *link_info,
3932 const char *name,
f2a9dd69 3933 char **error_message)
252b5132
RH
3934{
3935 char *tmp_name;
3936 struct elf_link_hash_entry *hash;
3937 struct elf32_arm_link_hash_table *hash_table;
3938
3939 /* We need a pointer to the armelf specific hash table. */
3940 hash_table = elf32_arm_hash_table (link_info);
3941
57e8b36a
NC
3942 tmp_name = bfd_malloc ((bfd_size_type) strlen (name)
3943 + strlen (THUMB2ARM_GLUE_ENTRY_NAME) + 1);
252b5132
RH
3944
3945 BFD_ASSERT (tmp_name);
3946
3947 sprintf (tmp_name, THUMB2ARM_GLUE_ENTRY_NAME, name);
3948
3949 hash = elf_link_hash_lookup
b34976b6 3950 (&(hash_table)->root, tmp_name, FALSE, FALSE, TRUE);
252b5132 3951
b1657152
AM
3952 if (hash == NULL
3953 && asprintf (error_message, _("unable to find THUMB glue '%s' for '%s'"),
3954 tmp_name, name) == -1)
3955 *error_message = (char *) bfd_errmsg (bfd_error_system_call);
252b5132
RH
3956
3957 free (tmp_name);
3958
3959 return hash;
3960}
3961
9b485d32
NC
3962/* Locate the ARM encoded calling stub for NAME. */
3963
252b5132 3964static struct elf_link_hash_entry *
57e8b36a
NC
3965find_arm_glue (struct bfd_link_info *link_info,
3966 const char *name,
f2a9dd69 3967 char **error_message)
252b5132
RH
3968{
3969 char *tmp_name;
3970 struct elf_link_hash_entry *myh;
3971 struct elf32_arm_link_hash_table *hash_table;
3972
3973 /* We need a pointer to the elfarm specific hash table. */
3974 hash_table = elf32_arm_hash_table (link_info);
3975
57e8b36a
NC
3976 tmp_name = bfd_malloc ((bfd_size_type) strlen (name)
3977 + strlen (ARM2THUMB_GLUE_ENTRY_NAME) + 1);
252b5132
RH
3978
3979 BFD_ASSERT (tmp_name);
3980
3981 sprintf (tmp_name, ARM2THUMB_GLUE_ENTRY_NAME, name);
3982
3983 myh = elf_link_hash_lookup
b34976b6 3984 (&(hash_table)->root, tmp_name, FALSE, FALSE, TRUE);
252b5132 3985
b1657152
AM
3986 if (myh == NULL
3987 && asprintf (error_message, _("unable to find ARM glue '%s' for '%s'"),
3988 tmp_name, name) == -1)
3989 *error_message = (char *) bfd_errmsg (bfd_error_system_call);
252b5132
RH
3990
3991 free (tmp_name);
3992
3993 return myh;
3994}
3995
8f6277f5 3996/* ARM->Thumb glue (static images):
252b5132
RH
3997
3998 .arm
3999 __func_from_arm:
4000 ldr r12, __func_addr
4001 bx r12
4002 __func_addr:
906e58ca 4003 .word func @ behave as if you saw a ARM_32 reloc.
252b5132 4004
26079076
PB
4005 (v5t static images)
4006 .arm
4007 __func_from_arm:
4008 ldr pc, __func_addr
4009 __func_addr:
906e58ca 4010 .word func @ behave as if you saw a ARM_32 reloc.
26079076 4011
8f6277f5
PB
4012 (relocatable images)
4013 .arm
4014 __func_from_arm:
4015 ldr r12, __func_offset
4016 add r12, r12, pc
4017 bx r12
4018 __func_offset:
8029a119 4019 .word func - . */
8f6277f5
PB
4020
4021#define ARM2THUMB_STATIC_GLUE_SIZE 12
252b5132
RH
4022static const insn32 a2t1_ldr_insn = 0xe59fc000;
4023static const insn32 a2t2_bx_r12_insn = 0xe12fff1c;
4024static const insn32 a2t3_func_addr_insn = 0x00000001;
4025
26079076
PB
4026#define ARM2THUMB_V5_STATIC_GLUE_SIZE 8
4027static const insn32 a2t1v5_ldr_insn = 0xe51ff004;
4028static const insn32 a2t2v5_func_addr_insn = 0x00000001;
4029
8f6277f5
PB
4030#define ARM2THUMB_PIC_GLUE_SIZE 16
4031static const insn32 a2t1p_ldr_insn = 0xe59fc004;
4032static const insn32 a2t2p_add_pc_insn = 0xe08cc00f;
4033static const insn32 a2t3p_bx_r12_insn = 0xe12fff1c;
4034
9b485d32 4035/* Thumb->ARM: Thumb->(non-interworking aware) ARM
252b5132 4036
8029a119
NC
4037 .thumb .thumb
4038 .align 2 .align 2
4039 __func_from_thumb: __func_from_thumb:
4040 bx pc push {r6, lr}
4041 nop ldr r6, __func_addr
4042 .arm mov lr, pc
4043 b func bx r6
fcef9eb7
NC
4044 .arm
4045 ;; back_to_thumb
4046 ldmia r13! {r6, lr}
4047 bx lr
8029a119
NC
4048 __func_addr:
4049 .word func */
252b5132
RH
4050
4051#define THUMB2ARM_GLUE_SIZE 8
4052static const insn16 t2a1_bx_pc_insn = 0x4778;
4053static const insn16 t2a2_noop_insn = 0x46c0;
4054static const insn32 t2a3_b_insn = 0xea000000;
4055
c7b8f16e
JB
4056#define VFP11_ERRATUM_VENEER_SIZE 8
4057
845b51d6
PB
4058#define ARM_BX_VENEER_SIZE 12
4059static const insn32 armbx1_tst_insn = 0xe3100001;
4060static const insn32 armbx2_moveq_insn = 0x01a0f000;
4061static const insn32 armbx3_bx_insn = 0xe12fff10;
4062
7e392df6 4063#ifndef ELFARM_NABI_C_INCLUDED
8029a119
NC
4064static void
4065arm_allocate_glue_section_space (bfd * abfd, bfd_size_type size, const char * name)
252b5132
RH
4066{
4067 asection * s;
8029a119 4068 bfd_byte * contents;
252b5132 4069
8029a119
NC
4070 if (size == 0)
4071 return;
252b5132 4072
8029a119 4073 BFD_ASSERT (abfd != NULL);
252b5132 4074
8029a119
NC
4075 s = bfd_get_section_by_name (abfd, name);
4076 BFD_ASSERT (s != NULL);
252b5132 4077
8029a119 4078 contents = bfd_alloc (abfd, size);
252b5132 4079
8029a119
NC
4080 BFD_ASSERT (s->size == size);
4081 s->contents = contents;
4082}
906e58ca 4083
8029a119
NC
4084bfd_boolean
4085bfd_elf32_arm_allocate_interworking_sections (struct bfd_link_info * info)
4086{
4087 struct elf32_arm_link_hash_table * globals;
906e58ca 4088
8029a119
NC
4089 globals = elf32_arm_hash_table (info);
4090 BFD_ASSERT (globals != NULL);
906e58ca 4091
8029a119
NC
4092 arm_allocate_glue_section_space (globals->bfd_of_glue_owner,
4093 globals->arm_glue_size,
4094 ARM2THUMB_GLUE_SECTION_NAME);
906e58ca 4095
8029a119
NC
4096 arm_allocate_glue_section_space (globals->bfd_of_glue_owner,
4097 globals->thumb_glue_size,
4098 THUMB2ARM_GLUE_SECTION_NAME);
252b5132 4099
8029a119
NC
4100 arm_allocate_glue_section_space (globals->bfd_of_glue_owner,
4101 globals->vfp11_erratum_glue_size,
4102 VFP11_ERRATUM_VENEER_SECTION_NAME);
845b51d6 4103
8029a119
NC
4104 arm_allocate_glue_section_space (globals->bfd_of_glue_owner,
4105 globals->bx_glue_size,
845b51d6
PB
4106 ARM_BX_GLUE_SECTION_NAME);
4107
b34976b6 4108 return TRUE;
252b5132
RH
4109}
4110
a4fd1a8e 4111/* Allocate space and symbols for calling a Thumb function from Arm mode.
906e58ca
NC
4112 returns the symbol identifying the stub. */
4113
a4fd1a8e 4114static struct elf_link_hash_entry *
57e8b36a
NC
4115record_arm_to_thumb_glue (struct bfd_link_info * link_info,
4116 struct elf_link_hash_entry * h)
252b5132
RH
4117{
4118 const char * name = h->root.root.string;
63b0f745 4119 asection * s;
252b5132
RH
4120 char * tmp_name;
4121 struct elf_link_hash_entry * myh;
14a793b2 4122 struct bfd_link_hash_entry * bh;
252b5132 4123 struct elf32_arm_link_hash_table * globals;
dc810e39 4124 bfd_vma val;
2f475487 4125 bfd_size_type size;
252b5132
RH
4126
4127 globals = elf32_arm_hash_table (link_info);
4128
4129 BFD_ASSERT (globals != NULL);
4130 BFD_ASSERT (globals->bfd_of_glue_owner != NULL);
4131
4132 s = bfd_get_section_by_name
4133 (globals->bfd_of_glue_owner, ARM2THUMB_GLUE_SECTION_NAME);
4134
252b5132
RH
4135 BFD_ASSERT (s != NULL);
4136
57e8b36a 4137 tmp_name = bfd_malloc ((bfd_size_type) strlen (name) + strlen (ARM2THUMB_GLUE_ENTRY_NAME) + 1);
252b5132
RH
4138
4139 BFD_ASSERT (tmp_name);
4140
4141 sprintf (tmp_name, ARM2THUMB_GLUE_ENTRY_NAME, name);
4142
4143 myh = elf_link_hash_lookup
b34976b6 4144 (&(globals)->root, tmp_name, FALSE, FALSE, TRUE);
252b5132
RH
4145
4146 if (myh != NULL)
4147 {
9b485d32 4148 /* We've already seen this guy. */
252b5132 4149 free (tmp_name);
a4fd1a8e 4150 return myh;
252b5132
RH
4151 }
4152
57e8b36a
NC
4153 /* The only trick here is using hash_table->arm_glue_size as the value.
4154 Even though the section isn't allocated yet, this is where we will be
3dccd7b7
DJ
4155 putting it. The +1 on the value marks that the stub has not been
4156 output yet - not that it is a Thumb function. */
14a793b2 4157 bh = NULL;
dc810e39
AM
4158 val = globals->arm_glue_size + 1;
4159 _bfd_generic_link_add_one_symbol (link_info, globals->bfd_of_glue_owner,
4160 tmp_name, BSF_GLOBAL, s, val,
b34976b6 4161 NULL, TRUE, FALSE, &bh);
252b5132 4162
b7693d02
DJ
4163 myh = (struct elf_link_hash_entry *) bh;
4164 myh->type = ELF_ST_INFO (STB_LOCAL, STT_FUNC);
4165 myh->forced_local = 1;
4166
252b5132
RH
4167 free (tmp_name);
4168
27e55c4d
PB
4169 if (link_info->shared || globals->root.is_relocatable_executable
4170 || globals->pic_veneer)
2f475487 4171 size = ARM2THUMB_PIC_GLUE_SIZE;
26079076
PB
4172 else if (globals->use_blx)
4173 size = ARM2THUMB_V5_STATIC_GLUE_SIZE;
8f6277f5 4174 else
2f475487
AM
4175 size = ARM2THUMB_STATIC_GLUE_SIZE;
4176
4177 s->size += size;
4178 globals->arm_glue_size += size;
252b5132 4179
a4fd1a8e 4180 return myh;
252b5132
RH
4181}
4182
4183static void
57e8b36a
NC
4184record_thumb_to_arm_glue (struct bfd_link_info *link_info,
4185 struct elf_link_hash_entry *h)
252b5132
RH
4186{
4187 const char *name = h->root.root.string;
63b0f745 4188 asection *s;
252b5132
RH
4189 char *tmp_name;
4190 struct elf_link_hash_entry *myh;
14a793b2 4191 struct bfd_link_hash_entry *bh;
252b5132 4192 struct elf32_arm_link_hash_table *hash_table;
dc810e39 4193 bfd_vma val;
252b5132
RH
4194
4195 hash_table = elf32_arm_hash_table (link_info);
4196
4197 BFD_ASSERT (hash_table != NULL);
4198 BFD_ASSERT (hash_table->bfd_of_glue_owner != NULL);
4199
4200 s = bfd_get_section_by_name
4201 (hash_table->bfd_of_glue_owner, THUMB2ARM_GLUE_SECTION_NAME);
4202
4203 BFD_ASSERT (s != NULL);
4204
57e8b36a
NC
4205 tmp_name = bfd_malloc ((bfd_size_type) strlen (name)
4206 + strlen (THUMB2ARM_GLUE_ENTRY_NAME) + 1);
252b5132
RH
4207
4208 BFD_ASSERT (tmp_name);
4209
4210 sprintf (tmp_name, THUMB2ARM_GLUE_ENTRY_NAME, name);
4211
4212 myh = elf_link_hash_lookup
b34976b6 4213 (&(hash_table)->root, tmp_name, FALSE, FALSE, TRUE);
252b5132
RH
4214
4215 if (myh != NULL)
4216 {
9b485d32 4217 /* We've already seen this guy. */
252b5132 4218 free (tmp_name);
9b485d32 4219 return;
252b5132
RH
4220 }
4221
3dccd7b7
DJ
4222 /* The only trick here is using hash_table->thumb_glue_size as the value.
4223 Even though the section isn't allocated yet, this is where we will be
4224 putting it. The +1 on the value marks that the stub has not been
4225 output yet - not that it is a Thumb function. */
14a793b2 4226 bh = NULL;
dc810e39
AM
4227 val = hash_table->thumb_glue_size + 1;
4228 _bfd_generic_link_add_one_symbol (link_info, hash_table->bfd_of_glue_owner,
4229 tmp_name, BSF_GLOBAL, s, val,
b34976b6 4230 NULL, TRUE, FALSE, &bh);
252b5132 4231
9b485d32 4232 /* If we mark it 'Thumb', the disassembler will do a better job. */
14a793b2 4233 myh = (struct elf_link_hash_entry *) bh;
b7693d02
DJ
4234 myh->type = ELF_ST_INFO (STB_LOCAL, STT_ARM_TFUNC);
4235 myh->forced_local = 1;
252b5132
RH
4236
4237 free (tmp_name);
4238
252b5132
RH
4239#define CHANGE_TO_ARM "__%s_change_to_arm"
4240#define BACK_FROM_ARM "__%s_back_from_arm"
4241
9b485d32 4242 /* Allocate another symbol to mark where we switch to Arm mode. */
57e8b36a
NC
4243 tmp_name = bfd_malloc ((bfd_size_type) strlen (name)
4244 + strlen (CHANGE_TO_ARM) + 1);
252b5132
RH
4245
4246 BFD_ASSERT (tmp_name);
4247
4248 sprintf (tmp_name, CHANGE_TO_ARM, name);
4249
14a793b2 4250 bh = NULL;
dc810e39
AM
4251 val = hash_table->thumb_glue_size + 4,
4252 _bfd_generic_link_add_one_symbol (link_info, hash_table->bfd_of_glue_owner,
4253 tmp_name, BSF_LOCAL, s, val,
b34976b6 4254 NULL, TRUE, FALSE, &bh);
252b5132
RH
4255
4256 free (tmp_name);
4257
2f475487 4258 s->size += THUMB2ARM_GLUE_SIZE;
252b5132 4259 hash_table->thumb_glue_size += THUMB2ARM_GLUE_SIZE;
252b5132
RH
4260}
4261
c7b8f16e 4262
845b51d6
PB
4263/* Allocate space for ARMv4 BX veneers. */
4264
4265static void
4266record_arm_bx_glue (struct bfd_link_info * link_info, int reg)
4267{
4268 asection * s;
4269 struct elf32_arm_link_hash_table *globals;
4270 char *tmp_name;
4271 struct elf_link_hash_entry *myh;
4272 struct bfd_link_hash_entry *bh;
4273 bfd_vma val;
4274
4275 /* BX PC does not need a veneer. */
4276 if (reg == 15)
4277 return;
4278
4279 globals = elf32_arm_hash_table (link_info);
4280
4281 BFD_ASSERT (globals != NULL);
4282 BFD_ASSERT (globals->bfd_of_glue_owner != NULL);
4283
4284 /* Check if this veneer has already been allocated. */
4285 if (globals->bx_glue_offset[reg])
4286 return;
4287
4288 s = bfd_get_section_by_name
4289 (globals->bfd_of_glue_owner, ARM_BX_GLUE_SECTION_NAME);
4290
4291 BFD_ASSERT (s != NULL);
4292
4293 /* Add symbol for veneer. */
4294 tmp_name = bfd_malloc ((bfd_size_type) strlen (ARM_BX_GLUE_ENTRY_NAME) + 1);
906e58ca 4295
845b51d6 4296 BFD_ASSERT (tmp_name);
906e58ca 4297
845b51d6 4298 sprintf (tmp_name, ARM_BX_GLUE_ENTRY_NAME, reg);
906e58ca 4299
845b51d6
PB
4300 myh = elf_link_hash_lookup
4301 (&(globals)->root, tmp_name, FALSE, FALSE, FALSE);
906e58ca 4302
845b51d6 4303 BFD_ASSERT (myh == NULL);
906e58ca 4304
845b51d6
PB
4305 bh = NULL;
4306 val = globals->bx_glue_size;
4307 _bfd_generic_link_add_one_symbol (link_info, globals->bfd_of_glue_owner,
4308 tmp_name, BSF_FUNCTION | BSF_LOCAL, s, val,
4309 NULL, TRUE, FALSE, &bh);
4310
4311 myh = (struct elf_link_hash_entry *) bh;
4312 myh->type = ELF_ST_INFO (STB_LOCAL, STT_FUNC);
4313 myh->forced_local = 1;
4314
4315 s->size += ARM_BX_VENEER_SIZE;
4316 globals->bx_glue_offset[reg] = globals->bx_glue_size | 2;
4317 globals->bx_glue_size += ARM_BX_VENEER_SIZE;
4318}
4319
4320
c7b8f16e
JB
4321/* Add an entry to the code/data map for section SEC. */
4322
4323static void
4324elf32_arm_section_map_add (asection *sec, char type, bfd_vma vma)
4325{
4326 struct _arm_elf_section_data *sec_data = elf32_arm_section_data (sec);
4327 unsigned int newidx;
906e58ca 4328
c7b8f16e
JB
4329 if (sec_data->map == NULL)
4330 {
4331 sec_data->map = bfd_malloc (sizeof (elf32_arm_section_map));
4332 sec_data->mapcount = 0;
4333 sec_data->mapsize = 1;
4334 }
906e58ca 4335
c7b8f16e 4336 newidx = sec_data->mapcount++;
906e58ca 4337
c7b8f16e
JB
4338 if (sec_data->mapcount > sec_data->mapsize)
4339 {
4340 sec_data->mapsize *= 2;
515ef31d
NC
4341 sec_data->map = bfd_realloc_or_free (sec_data->map, sec_data->mapsize
4342 * sizeof (elf32_arm_section_map));
4343 }
4344
4345 if (sec_data->map)
4346 {
4347 sec_data->map[newidx].vma = vma;
4348 sec_data->map[newidx].type = type;
c7b8f16e 4349 }
c7b8f16e
JB
4350}
4351
4352
4353/* Record information about a VFP11 denorm-erratum veneer. Only ARM-mode
4354 veneers are handled for now. */
4355
4356static bfd_vma
4357record_vfp11_erratum_veneer (struct bfd_link_info *link_info,
4358 elf32_vfp11_erratum_list *branch,
4359 bfd *branch_bfd,
4360 asection *branch_sec,
4361 unsigned int offset)
4362{
4363 asection *s;
4364 struct elf32_arm_link_hash_table *hash_table;
4365 char *tmp_name;
4366 struct elf_link_hash_entry *myh;
4367 struct bfd_link_hash_entry *bh;
4368 bfd_vma val;
4369 struct _arm_elf_section_data *sec_data;
4370 int errcount;
4371 elf32_vfp11_erratum_list *newerr;
906e58ca 4372
c7b8f16e 4373 hash_table = elf32_arm_hash_table (link_info);
906e58ca 4374
c7b8f16e
JB
4375 BFD_ASSERT (hash_table != NULL);
4376 BFD_ASSERT (hash_table->bfd_of_glue_owner != NULL);
906e58ca 4377
c7b8f16e
JB
4378 s = bfd_get_section_by_name
4379 (hash_table->bfd_of_glue_owner, VFP11_ERRATUM_VENEER_SECTION_NAME);
906e58ca 4380
c7b8f16e 4381 sec_data = elf32_arm_section_data (s);
906e58ca 4382
c7b8f16e 4383 BFD_ASSERT (s != NULL);
906e58ca 4384
c7b8f16e
JB
4385 tmp_name = bfd_malloc ((bfd_size_type) strlen
4386 (VFP11_ERRATUM_VENEER_ENTRY_NAME) + 10);
906e58ca 4387
c7b8f16e 4388 BFD_ASSERT (tmp_name);
906e58ca 4389
c7b8f16e
JB
4390 sprintf (tmp_name, VFP11_ERRATUM_VENEER_ENTRY_NAME,
4391 hash_table->num_vfp11_fixes);
906e58ca 4392
c7b8f16e
JB
4393 myh = elf_link_hash_lookup
4394 (&(hash_table)->root, tmp_name, FALSE, FALSE, FALSE);
906e58ca 4395
c7b8f16e 4396 BFD_ASSERT (myh == NULL);
906e58ca 4397
c7b8f16e
JB
4398 bh = NULL;
4399 val = hash_table->vfp11_erratum_glue_size;
4400 _bfd_generic_link_add_one_symbol (link_info, hash_table->bfd_of_glue_owner,
4401 tmp_name, BSF_FUNCTION | BSF_LOCAL, s, val,
4402 NULL, TRUE, FALSE, &bh);
4403
4404 myh = (struct elf_link_hash_entry *) bh;
4405 myh->type = ELF_ST_INFO (STB_LOCAL, STT_FUNC);
4406 myh->forced_local = 1;
4407
4408 /* Link veneer back to calling location. */
4409 errcount = ++(sec_data->erratumcount);
4410 newerr = bfd_zmalloc (sizeof (elf32_vfp11_erratum_list));
906e58ca 4411
c7b8f16e
JB
4412 newerr->type = VFP11_ERRATUM_ARM_VENEER;
4413 newerr->vma = -1;
4414 newerr->u.v.branch = branch;
4415 newerr->u.v.id = hash_table->num_vfp11_fixes;
4416 branch->u.b.veneer = newerr;
4417
4418 newerr->next = sec_data->erratumlist;
4419 sec_data->erratumlist = newerr;
4420
4421 /* A symbol for the return from the veneer. */
4422 sprintf (tmp_name, VFP11_ERRATUM_VENEER_ENTRY_NAME "_r",
4423 hash_table->num_vfp11_fixes);
4424
4425 myh = elf_link_hash_lookup
4426 (&(hash_table)->root, tmp_name, FALSE, FALSE, FALSE);
906e58ca 4427
c7b8f16e
JB
4428 if (myh != NULL)
4429 abort ();
4430
4431 bh = NULL;
4432 val = offset + 4;
4433 _bfd_generic_link_add_one_symbol (link_info, branch_bfd, tmp_name, BSF_LOCAL,
4434 branch_sec, val, NULL, TRUE, FALSE, &bh);
906e58ca 4435
c7b8f16e
JB
4436 myh = (struct elf_link_hash_entry *) bh;
4437 myh->type = ELF_ST_INFO (STB_LOCAL, STT_FUNC);
4438 myh->forced_local = 1;
4439
4440 free (tmp_name);
906e58ca 4441
c7b8f16e
JB
4442 /* Generate a mapping symbol for the veneer section, and explicitly add an
4443 entry for that symbol to the code/data map for the section. */
4444 if (hash_table->vfp11_erratum_glue_size == 0)
4445 {
4446 bh = NULL;
4447 /* FIXME: Creates an ARM symbol. Thumb mode will need attention if it
4448 ever requires this erratum fix. */
4449 _bfd_generic_link_add_one_symbol (link_info,
4450 hash_table->bfd_of_glue_owner, "$a",
4451 BSF_LOCAL, s, 0, NULL,
4452 TRUE, FALSE, &bh);
4453
4454 myh = (struct elf_link_hash_entry *) bh;
4455 myh->type = ELF_ST_INFO (STB_LOCAL, STT_NOTYPE);
4456 myh->forced_local = 1;
906e58ca 4457
c7b8f16e
JB
4458 /* The elf32_arm_init_maps function only cares about symbols from input
4459 BFDs. We must make a note of this generated mapping symbol
4460 ourselves so that code byteswapping works properly in
4461 elf32_arm_write_section. */
4462 elf32_arm_section_map_add (s, 'a', 0);
4463 }
906e58ca 4464
c7b8f16e
JB
4465 s->size += VFP11_ERRATUM_VENEER_SIZE;
4466 hash_table->vfp11_erratum_glue_size += VFP11_ERRATUM_VENEER_SIZE;
4467 hash_table->num_vfp11_fixes++;
906e58ca 4468
c7b8f16e
JB
4469 /* The offset of the veneer. */
4470 return val;
4471}
4472
8029a119
NC
4473/* Note: we do not include the flag SEC_LINKER_CREATED, as that
4474 would prevent elf_link_input_bfd() from processing the contents
4475 of the section. */
4476#define ARM_GLUE_SECTION_FLAGS \
4477 (SEC_ALLOC | SEC_LOAD | SEC_HAS_CONTENTS | SEC_IN_MEMORY | SEC_CODE | SEC_READONLY)
4478
4479/* Create a fake section for use by the ARM backend of the linker. */
4480
4481static bfd_boolean
4482arm_make_glue_section (bfd * abfd, const char * name)
4483{
4484 asection * sec;
4485
4486 sec = bfd_get_section_by_name (abfd, name);
4487 if (sec != NULL)
4488 /* Already made. */
4489 return TRUE;
4490
4491 sec = bfd_make_section_with_flags (abfd, name, ARM_GLUE_SECTION_FLAGS);
4492
4493 if (sec == NULL
4494 || !bfd_set_section_alignment (abfd, sec, 2))
4495 return FALSE;
4496
4497 /* Set the gc mark to prevent the section from being removed by garbage
4498 collection, despite the fact that no relocs refer to this section. */
4499 sec->gc_mark = 1;
4500
4501 return TRUE;
4502}
4503
8afb0e02
NC
4504/* Add the glue sections to ABFD. This function is called from the
4505 linker scripts in ld/emultempl/{armelf}.em. */
9b485d32 4506
b34976b6 4507bfd_boolean
57e8b36a
NC
4508bfd_elf32_arm_add_glue_sections_to_bfd (bfd *abfd,
4509 struct bfd_link_info *info)
252b5132 4510{
8afb0e02
NC
4511 /* If we are only performing a partial
4512 link do not bother adding the glue. */
1049f94e 4513 if (info->relocatable)
b34976b6 4514 return TRUE;
252b5132 4515
8029a119 4516 /* Linker stubs don't need glue. */
906e58ca
NC
4517 if (!strcmp (abfd->filename, "linker stubs"))
4518 return TRUE;
4519
8029a119
NC
4520 return arm_make_glue_section (abfd, ARM2THUMB_GLUE_SECTION_NAME)
4521 && arm_make_glue_section (abfd, THUMB2ARM_GLUE_SECTION_NAME)
4522 && arm_make_glue_section (abfd, VFP11_ERRATUM_VENEER_SECTION_NAME)
4523 && arm_make_glue_section (abfd, ARM_BX_GLUE_SECTION_NAME);
8afb0e02
NC
4524}
4525
4526/* Select a BFD to be used to hold the sections used by the glue code.
4527 This function is called from the linker scripts in ld/emultempl/
8029a119 4528 {armelf/pe}.em. */
8afb0e02 4529
b34976b6 4530bfd_boolean
57e8b36a 4531bfd_elf32_arm_get_bfd_for_interworking (bfd *abfd, struct bfd_link_info *info)
8afb0e02
NC
4532{
4533 struct elf32_arm_link_hash_table *globals;
4534
4535 /* If we are only performing a partial link
4536 do not bother getting a bfd to hold the glue. */
1049f94e 4537 if (info->relocatable)
b34976b6 4538 return TRUE;
8afb0e02 4539
b7693d02
DJ
4540 /* Make sure we don't attach the glue sections to a dynamic object. */
4541 BFD_ASSERT (!(abfd->flags & DYNAMIC));
4542
8afb0e02
NC
4543 globals = elf32_arm_hash_table (info);
4544
4545 BFD_ASSERT (globals != NULL);
4546
4547 if (globals->bfd_of_glue_owner != NULL)
b34976b6 4548 return TRUE;
8afb0e02 4549
252b5132
RH
4550 /* Save the bfd for later use. */
4551 globals->bfd_of_glue_owner = abfd;
cedb70c5 4552
b34976b6 4553 return TRUE;
252b5132
RH
4554}
4555
906e58ca
NC
4556static void
4557check_use_blx (struct elf32_arm_link_hash_table *globals)
39b41c9c 4558{
104d59d1
JM
4559 if (bfd_elf_get_obj_attr_int (globals->obfd, OBJ_ATTR_PROC,
4560 Tag_CPU_arch) > 2)
39b41c9c
PB
4561 globals->use_blx = 1;
4562}
4563
b34976b6 4564bfd_boolean
57e8b36a 4565bfd_elf32_arm_process_before_allocation (bfd *abfd,
d504ffc8 4566 struct bfd_link_info *link_info)
252b5132
RH
4567{
4568 Elf_Internal_Shdr *symtab_hdr;
6cdc0ccc 4569 Elf_Internal_Rela *internal_relocs = NULL;
252b5132
RH
4570 Elf_Internal_Rela *irel, *irelend;
4571 bfd_byte *contents = NULL;
252b5132
RH
4572
4573 asection *sec;
4574 struct elf32_arm_link_hash_table *globals;
4575
4576 /* If we are only performing a partial link do not bother
4577 to construct any glue. */
1049f94e 4578 if (link_info->relocatable)
b34976b6 4579 return TRUE;
252b5132 4580
39ce1a6a
NC
4581 /* Here we have a bfd that is to be included on the link. We have a
4582 hook to do reloc rummaging, before section sizes are nailed down. */
252b5132
RH
4583 globals = elf32_arm_hash_table (link_info);
4584
4585 BFD_ASSERT (globals != NULL);
39ce1a6a
NC
4586
4587 check_use_blx (globals);
252b5132 4588
d504ffc8 4589 if (globals->byteswap_code && !bfd_big_endian (abfd))
e489d0ae 4590 {
d003868e
AM
4591 _bfd_error_handler (_("%B: BE8 images only valid in big-endian mode."),
4592 abfd);
e489d0ae
PB
4593 return FALSE;
4594 }
f21f3fe0 4595
39ce1a6a
NC
4596 /* PR 5398: If we have not decided to include any loadable sections in
4597 the output then we will not have a glue owner bfd. This is OK, it
4598 just means that there is nothing else for us to do here. */
4599 if (globals->bfd_of_glue_owner == NULL)
4600 return TRUE;
4601
252b5132
RH
4602 /* Rummage around all the relocs and map the glue vectors. */
4603 sec = abfd->sections;
4604
4605 if (sec == NULL)
b34976b6 4606 return TRUE;
252b5132
RH
4607
4608 for (; sec != NULL; sec = sec->next)
4609 {
4610 if (sec->reloc_count == 0)
4611 continue;
4612
2f475487
AM
4613 if ((sec->flags & SEC_EXCLUDE) != 0)
4614 continue;
4615
0ffa91dd 4616 symtab_hdr = & elf_symtab_hdr (abfd);
252b5132 4617
9b485d32 4618 /* Load the relocs. */
6cdc0ccc 4619 internal_relocs
906e58ca 4620 = _bfd_elf_link_read_relocs (abfd, sec, NULL, NULL, FALSE);
252b5132 4621
6cdc0ccc
AM
4622 if (internal_relocs == NULL)
4623 goto error_return;
252b5132 4624
6cdc0ccc
AM
4625 irelend = internal_relocs + sec->reloc_count;
4626 for (irel = internal_relocs; irel < irelend; irel++)
252b5132
RH
4627 {
4628 long r_type;
4629 unsigned long r_index;
252b5132
RH
4630
4631 struct elf_link_hash_entry *h;
4632
4633 r_type = ELF32_R_TYPE (irel->r_info);
4634 r_index = ELF32_R_SYM (irel->r_info);
4635
9b485d32 4636 /* These are the only relocation types we care about. */
ba96a88f 4637 if ( r_type != R_ARM_PC24
b7693d02 4638 && r_type != R_ARM_PLT32
5b5bb741 4639 && r_type != R_ARM_JUMP24
845b51d6
PB
4640 && r_type != R_ARM_THM_JUMP24
4641 && (r_type != R_ARM_V4BX || globals->fix_v4bx < 2))
252b5132
RH
4642 continue;
4643
4644 /* Get the section contents if we haven't done so already. */
4645 if (contents == NULL)
4646 {
4647 /* Get cached copy if it exists. */
4648 if (elf_section_data (sec)->this_hdr.contents != NULL)
4649 contents = elf_section_data (sec)->this_hdr.contents;
4650 else
4651 {
4652 /* Go get them off disk. */
57e8b36a 4653 if (! bfd_malloc_and_get_section (abfd, sec, &contents))
252b5132
RH
4654 goto error_return;
4655 }
4656 }
4657
845b51d6
PB
4658 if (r_type == R_ARM_V4BX)
4659 {
4660 int reg;
4661
4662 reg = bfd_get_32 (abfd, contents + irel->r_offset) & 0xf;
4663 record_arm_bx_glue (link_info, reg);
4664 continue;
4665 }
4666
a7c10850 4667 /* If the relocation is not against a symbol it cannot concern us. */
252b5132
RH
4668 h = NULL;
4669
9b485d32 4670 /* We don't care about local symbols. */
252b5132
RH
4671 if (r_index < symtab_hdr->sh_info)
4672 continue;
4673
9b485d32 4674 /* This is an external symbol. */
252b5132
RH
4675 r_index -= symtab_hdr->sh_info;
4676 h = (struct elf_link_hash_entry *)
4677 elf_sym_hashes (abfd)[r_index];
4678
4679 /* If the relocation is against a static symbol it must be within
4680 the current section and so cannot be a cross ARM/Thumb relocation. */
4681 if (h == NULL)
4682 continue;
4683
d504ffc8
DJ
4684 /* If the call will go through a PLT entry then we do not need
4685 glue. */
4686 if (globals->splt != NULL && h->plt.offset != (bfd_vma) -1)
b7693d02
DJ
4687 continue;
4688
252b5132
RH
4689 switch (r_type)
4690 {
4691 case R_ARM_PC24:
c6596c5e 4692 case R_ARM_PLT32:
5b5bb741 4693 case R_ARM_JUMP24:
252b5132 4694 /* This one is a call from arm code. We need to look up
2f0ca46a 4695 the target of the call. If it is a thumb target, we
252b5132 4696 insert glue. */
ebe24dd4 4697 if (ELF_ST_TYPE (h->type) == STT_ARM_TFUNC)
252b5132
RH
4698 record_arm_to_thumb_glue (link_info, h);
4699 break;
4700
bd97cb95 4701 case R_ARM_THM_JUMP24:
f21f3fe0 4702 /* This one is a call from thumb code. We look
2f0ca46a 4703 up the target of the call. If it is not a thumb
bcbdc74c 4704 target, we insert glue. */
bd97cb95
DJ
4705 if (ELF_ST_TYPE (h->type) != STT_ARM_TFUNC
4706 && !(globals->use_blx && r_type == R_ARM_THM_CALL)
5ab79981 4707 && h->root.type != bfd_link_hash_undefweak)
252b5132
RH
4708 record_thumb_to_arm_glue (link_info, h);
4709 break;
4710
4711 default:
c6596c5e 4712 abort ();
252b5132
RH
4713 }
4714 }
6cdc0ccc
AM
4715
4716 if (contents != NULL
4717 && elf_section_data (sec)->this_hdr.contents != contents)
4718 free (contents);
4719 contents = NULL;
4720
4721 if (internal_relocs != NULL
4722 && elf_section_data (sec)->relocs != internal_relocs)
4723 free (internal_relocs);
4724 internal_relocs = NULL;
252b5132
RH
4725 }
4726
b34976b6 4727 return TRUE;
9a5aca8c 4728
252b5132 4729error_return:
6cdc0ccc
AM
4730 if (contents != NULL
4731 && elf_section_data (sec)->this_hdr.contents != contents)
4732 free (contents);
4733 if (internal_relocs != NULL
4734 && elf_section_data (sec)->relocs != internal_relocs)
4735 free (internal_relocs);
9a5aca8c 4736
b34976b6 4737 return FALSE;
252b5132 4738}
7e392df6 4739#endif
252b5132 4740
eb043451 4741
c7b8f16e
JB
4742/* Initialise maps of ARM/Thumb/data for input BFDs. */
4743
4744void
4745bfd_elf32_arm_init_maps (bfd *abfd)
4746{
4747 Elf_Internal_Sym *isymbuf;
4748 Elf_Internal_Shdr *hdr;
4749 unsigned int i, localsyms;
4750
af1f4419
NC
4751 /* PR 7093: Make sure that we are dealing with an arm elf binary. */
4752 if (! is_arm_elf (abfd))
4753 return;
4754
c7b8f16e
JB
4755 if ((abfd->flags & DYNAMIC) != 0)
4756 return;
4757
0ffa91dd 4758 hdr = & elf_symtab_hdr (abfd);
c7b8f16e
JB
4759 localsyms = hdr->sh_info;
4760
4761 /* Obtain a buffer full of symbols for this BFD. The hdr->sh_info field
4762 should contain the number of local symbols, which should come before any
4763 global symbols. Mapping symbols are always local. */
4764 isymbuf = bfd_elf_get_elf_syms (abfd, hdr, localsyms, 0, NULL, NULL,
4765 NULL);
4766
4767 /* No internal symbols read? Skip this BFD. */
4768 if (isymbuf == NULL)
4769 return;
4770
4771 for (i = 0; i < localsyms; i++)
4772 {
4773 Elf_Internal_Sym *isym = &isymbuf[i];
4774 asection *sec = bfd_section_from_elf_index (abfd, isym->st_shndx);
4775 const char *name;
906e58ca 4776
c7b8f16e
JB
4777 if (sec != NULL
4778 && ELF_ST_BIND (isym->st_info) == STB_LOCAL)
4779 {
4780 name = bfd_elf_string_from_elf_section (abfd,
4781 hdr->sh_link, isym->st_name);
906e58ca 4782
c7b8f16e
JB
4783 if (bfd_is_arm_special_symbol_name (name,
4784 BFD_ARM_SPECIAL_SYM_TYPE_MAP))
4785 elf32_arm_section_map_add (sec, name[1], isym->st_value);
4786 }
4787 }
4788}
4789
4790
4791void
4792bfd_elf32_arm_set_vfp11_fix (bfd *obfd, struct bfd_link_info *link_info)
4793{
4794 struct elf32_arm_link_hash_table *globals = elf32_arm_hash_table (link_info);
104d59d1 4795 obj_attribute *out_attr = elf_known_obj_attributes_proc (obfd);
906e58ca 4796
c7b8f16e
JB
4797 /* We assume that ARMv7+ does not need the VFP11 denorm erratum fix. */
4798 if (out_attr[Tag_CPU_arch].i >= TAG_CPU_ARCH_V7)
4799 {
4800 switch (globals->vfp11_fix)
4801 {
4802 case BFD_ARM_VFP11_FIX_DEFAULT:
4803 case BFD_ARM_VFP11_FIX_NONE:
4804 globals->vfp11_fix = BFD_ARM_VFP11_FIX_NONE;
4805 break;
906e58ca 4806
c7b8f16e
JB
4807 default:
4808 /* Give a warning, but do as the user requests anyway. */
4809 (*_bfd_error_handler) (_("%B: warning: selected VFP11 erratum "
4810 "workaround is not necessary for target architecture"), obfd);
4811 }
4812 }
4813 else if (globals->vfp11_fix == BFD_ARM_VFP11_FIX_DEFAULT)
4814 /* For earlier architectures, we might need the workaround, but do not
4815 enable it by default. If users is running with broken hardware, they
4816 must enable the erratum fix explicitly. */
4817 globals->vfp11_fix = BFD_ARM_VFP11_FIX_NONE;
4818}
4819
4820
906e58ca
NC
4821enum bfd_arm_vfp11_pipe
4822{
c7b8f16e
JB
4823 VFP11_FMAC,
4824 VFP11_LS,
4825 VFP11_DS,
4826 VFP11_BAD
4827};
4828
4829/* Return a VFP register number. This is encoded as RX:X for single-precision
4830 registers, or X:RX for double-precision registers, where RX is the group of
4831 four bits in the instruction encoding and X is the single extension bit.
4832 RX and X fields are specified using their lowest (starting) bit. The return
4833 value is:
4834
4835 0...31: single-precision registers s0...s31
4836 32...63: double-precision registers d0...d31.
906e58ca 4837
c7b8f16e
JB
4838 Although X should be zero for VFP11 (encoding d0...d15 only), we might
4839 encounter VFP3 instructions, so we allow the full range for DP registers. */
906e58ca 4840
c7b8f16e
JB
4841static unsigned int
4842bfd_arm_vfp11_regno (unsigned int insn, bfd_boolean is_double, unsigned int rx,
4843 unsigned int x)
4844{
4845 if (is_double)
4846 return (((insn >> rx) & 0xf) | (((insn >> x) & 1) << 4)) + 32;
4847 else
4848 return (((insn >> rx) & 0xf) << 1) | ((insn >> x) & 1);
4849}
4850
4851/* Set bits in *WMASK according to a register number REG as encoded by
4852 bfd_arm_vfp11_regno(). Ignore d16-d31. */
4853
4854static void
4855bfd_arm_vfp11_write_mask (unsigned int *wmask, unsigned int reg)
4856{
4857 if (reg < 32)
4858 *wmask |= 1 << reg;
4859 else if (reg < 48)
4860 *wmask |= 3 << ((reg - 32) * 2);
4861}
4862
4863/* Return TRUE if WMASK overwrites anything in REGS. */
4864
4865static bfd_boolean
4866bfd_arm_vfp11_antidependency (unsigned int wmask, int *regs, int numregs)
4867{
4868 int i;
906e58ca 4869
c7b8f16e
JB
4870 for (i = 0; i < numregs; i++)
4871 {
4872 unsigned int reg = regs[i];
4873
4874 if (reg < 32 && (wmask & (1 << reg)) != 0)
4875 return TRUE;
906e58ca 4876
c7b8f16e
JB
4877 reg -= 32;
4878
4879 if (reg >= 16)
4880 continue;
906e58ca 4881
c7b8f16e
JB
4882 if ((wmask & (3 << (reg * 2))) != 0)
4883 return TRUE;
4884 }
906e58ca 4885
c7b8f16e
JB
4886 return FALSE;
4887}
4888
4889/* In this function, we're interested in two things: finding input registers
4890 for VFP data-processing instructions, and finding the set of registers which
4891 arbitrary VFP instructions may write to. We use a 32-bit unsigned int to
4892 hold the written set, so FLDM etc. are easy to deal with (we're only
4893 interested in 32 SP registers or 16 dp registers, due to the VFP version
4894 implemented by the chip in question). DP registers are marked by setting
4895 both SP registers in the write mask). */
4896
4897static enum bfd_arm_vfp11_pipe
4898bfd_arm_vfp11_insn_decode (unsigned int insn, unsigned int *destmask, int *regs,
4899 int *numregs)
4900{
4901 enum bfd_arm_vfp11_pipe pipe = VFP11_BAD;
4902 bfd_boolean is_double = ((insn & 0xf00) == 0xb00) ? 1 : 0;
4903
4904 if ((insn & 0x0f000e10) == 0x0e000a00) /* A data-processing insn. */
4905 {
4906 unsigned int pqrs;
4907 unsigned int fd = bfd_arm_vfp11_regno (insn, is_double, 12, 22);
4908 unsigned int fm = bfd_arm_vfp11_regno (insn, is_double, 0, 5);
4909
4910 pqrs = ((insn & 0x00800000) >> 20)
4911 | ((insn & 0x00300000) >> 19)
4912 | ((insn & 0x00000040) >> 6);
4913
4914 switch (pqrs)
4915 {
4916 case 0: /* fmac[sd]. */
4917 case 1: /* fnmac[sd]. */
4918 case 2: /* fmsc[sd]. */
4919 case 3: /* fnmsc[sd]. */
4920 pipe = VFP11_FMAC;
4921 bfd_arm_vfp11_write_mask (destmask, fd);
4922 regs[0] = fd;
4923 regs[1] = bfd_arm_vfp11_regno (insn, is_double, 16, 7); /* Fn. */
4924 regs[2] = fm;
4925 *numregs = 3;
4926 break;
4927
4928 case 4: /* fmul[sd]. */
4929 case 5: /* fnmul[sd]. */
4930 case 6: /* fadd[sd]. */
4931 case 7: /* fsub[sd]. */
4932 pipe = VFP11_FMAC;
4933 goto vfp_binop;
4934
4935 case 8: /* fdiv[sd]. */
4936 pipe = VFP11_DS;
4937 vfp_binop:
4938 bfd_arm_vfp11_write_mask (destmask, fd);
4939 regs[0] = bfd_arm_vfp11_regno (insn, is_double, 16, 7); /* Fn. */
4940 regs[1] = fm;
4941 *numregs = 2;
4942 break;
4943
4944 case 15: /* extended opcode. */
4945 {
4946 unsigned int extn = ((insn >> 15) & 0x1e)
4947 | ((insn >> 7) & 1);
4948
4949 switch (extn)
4950 {
4951 case 0: /* fcpy[sd]. */
4952 case 1: /* fabs[sd]. */
4953 case 2: /* fneg[sd]. */
4954 case 8: /* fcmp[sd]. */
4955 case 9: /* fcmpe[sd]. */
4956 case 10: /* fcmpz[sd]. */
4957 case 11: /* fcmpez[sd]. */
4958 case 16: /* fuito[sd]. */
4959 case 17: /* fsito[sd]. */
4960 case 24: /* ftoui[sd]. */
4961 case 25: /* ftouiz[sd]. */
4962 case 26: /* ftosi[sd]. */
4963 case 27: /* ftosiz[sd]. */
4964 /* These instructions will not bounce due to underflow. */
4965 *numregs = 0;
4966 pipe = VFP11_FMAC;
4967 break;
4968
4969 case 3: /* fsqrt[sd]. */
4970 /* fsqrt cannot underflow, but it can (perhaps) overwrite
4971 registers to cause the erratum in previous instructions. */
4972 bfd_arm_vfp11_write_mask (destmask, fd);
4973 pipe = VFP11_DS;
4974 break;
4975
4976 case 15: /* fcvt{ds,sd}. */
4977 {
4978 int rnum = 0;
4979
4980 bfd_arm_vfp11_write_mask (destmask, fd);
4981
4982 /* Only FCVTSD can underflow. */
4983 if ((insn & 0x100) != 0)
4984 regs[rnum++] = fm;
4985
4986 *numregs = rnum;
4987
4988 pipe = VFP11_FMAC;
4989 }
4990 break;
4991
4992 default:
4993 return VFP11_BAD;
4994 }
4995 }
4996 break;
4997
4998 default:
4999 return VFP11_BAD;
5000 }
5001 }
5002 /* Two-register transfer. */
5003 else if ((insn & 0x0fe00ed0) == 0x0c400a10)
5004 {
5005 unsigned int fm = bfd_arm_vfp11_regno (insn, is_double, 0, 5);
906e58ca 5006
c7b8f16e
JB
5007 if ((insn & 0x100000) == 0)
5008 {
5009 if (is_double)
5010 bfd_arm_vfp11_write_mask (destmask, fm);
5011 else
5012 {
5013 bfd_arm_vfp11_write_mask (destmask, fm);
5014 bfd_arm_vfp11_write_mask (destmask, fm + 1);
5015 }
5016 }
5017
5018 pipe = VFP11_LS;
5019 }
5020 else if ((insn & 0x0e100e00) == 0x0c100a00) /* A load insn. */
5021 {
5022 int fd = bfd_arm_vfp11_regno (insn, is_double, 12, 22);
5023 unsigned int puw = ((insn >> 21) & 0x1) | (((insn >> 23) & 3) << 1);
906e58ca 5024
c7b8f16e
JB
5025 switch (puw)
5026 {
5027 case 0: /* Two-reg transfer. We should catch these above. */
5028 abort ();
906e58ca 5029
c7b8f16e
JB
5030 case 2: /* fldm[sdx]. */
5031 case 3:
5032 case 5:
5033 {
5034 unsigned int i, offset = insn & 0xff;
5035
5036 if (is_double)
5037 offset >>= 1;
5038
5039 for (i = fd; i < fd + offset; i++)
5040 bfd_arm_vfp11_write_mask (destmask, i);
5041 }
5042 break;
906e58ca 5043
c7b8f16e
JB
5044 case 4: /* fld[sd]. */
5045 case 6:
5046 bfd_arm_vfp11_write_mask (destmask, fd);
5047 break;
906e58ca 5048
c7b8f16e
JB
5049 default:
5050 return VFP11_BAD;
5051 }
5052
5053 pipe = VFP11_LS;
5054 }
5055 /* Single-register transfer. Note L==0. */
5056 else if ((insn & 0x0f100e10) == 0x0e000a10)
5057 {
5058 unsigned int opcode = (insn >> 21) & 7;
5059 unsigned int fn = bfd_arm_vfp11_regno (insn, is_double, 16, 7);
5060
5061 switch (opcode)
5062 {
5063 case 0: /* fmsr/fmdlr. */
5064 case 1: /* fmdhr. */
5065 /* Mark fmdhr and fmdlr as writing to the whole of the DP
5066 destination register. I don't know if this is exactly right,
5067 but it is the conservative choice. */
5068 bfd_arm_vfp11_write_mask (destmask, fn);
5069 break;
5070
5071 case 7: /* fmxr. */
5072 break;
5073 }
5074
5075 pipe = VFP11_LS;
5076 }
5077
5078 return pipe;
5079}
5080
5081
5082static int elf32_arm_compare_mapping (const void * a, const void * b);
5083
5084
5085/* Look for potentially-troublesome code sequences which might trigger the
5086 VFP11 denormal/antidependency erratum. See, e.g., the ARM1136 errata sheet
5087 (available from ARM) for details of the erratum. A short version is
5088 described in ld.texinfo. */
5089
5090bfd_boolean
5091bfd_elf32_arm_vfp11_erratum_scan (bfd *abfd, struct bfd_link_info *link_info)
5092{
5093 asection *sec;
5094 bfd_byte *contents = NULL;
5095 int state = 0;
5096 int regs[3], numregs = 0;
5097 struct elf32_arm_link_hash_table *globals = elf32_arm_hash_table (link_info);
5098 int use_vector = (globals->vfp11_fix == BFD_ARM_VFP11_FIX_VECTOR);
906e58ca 5099
c7b8f16e
JB
5100 /* We use a simple FSM to match troublesome VFP11 instruction sequences.
5101 The states transition as follows:
906e58ca 5102
c7b8f16e
JB
5103 0 -> 1 (vector) or 0 -> 2 (scalar)
5104 A VFP FMAC-pipeline instruction has been seen. Fill
5105 regs[0]..regs[numregs-1] with its input operands. Remember this
5106 instruction in 'first_fmac'.
5107
5108 1 -> 2
5109 Any instruction, except for a VFP instruction which overwrites
5110 regs[*].
906e58ca 5111
c7b8f16e
JB
5112 1 -> 3 [ -> 0 ] or
5113 2 -> 3 [ -> 0 ]
5114 A VFP instruction has been seen which overwrites any of regs[*].
5115 We must make a veneer! Reset state to 0 before examining next
5116 instruction.
906e58ca 5117
c7b8f16e
JB
5118 2 -> 0
5119 If we fail to match anything in state 2, reset to state 0 and reset
5120 the instruction pointer to the instruction after 'first_fmac'.
5121
5122 If the VFP11 vector mode is in use, there must be at least two unrelated
5123 instructions between anti-dependent VFP11 instructions to properly avoid
906e58ca 5124 triggering the erratum, hence the use of the extra state 1. */
c7b8f16e
JB
5125
5126 /* If we are only performing a partial link do not bother
5127 to construct any glue. */
5128 if (link_info->relocatable)
5129 return TRUE;
5130
0ffa91dd
NC
5131 /* Skip if this bfd does not correspond to an ELF image. */
5132 if (! is_arm_elf (abfd))
5133 return TRUE;
906e58ca 5134
c7b8f16e
JB
5135 /* We should have chosen a fix type by the time we get here. */
5136 BFD_ASSERT (globals->vfp11_fix != BFD_ARM_VFP11_FIX_DEFAULT);
5137
5138 if (globals->vfp11_fix == BFD_ARM_VFP11_FIX_NONE)
5139 return TRUE;
2e6030b9 5140
33a7ffc2
JM
5141 /* Skip this BFD if it corresponds to an executable or dynamic object. */
5142 if ((abfd->flags & (EXEC_P | DYNAMIC)) != 0)
5143 return TRUE;
5144
c7b8f16e
JB
5145 for (sec = abfd->sections; sec != NULL; sec = sec->next)
5146 {
5147 unsigned int i, span, first_fmac = 0, veneer_of_insn = 0;
5148 struct _arm_elf_section_data *sec_data;
5149
5150 /* If we don't have executable progbits, we're not interested in this
5151 section. Also skip if section is to be excluded. */
5152 if (elf_section_type (sec) != SHT_PROGBITS
5153 || (elf_section_flags (sec) & SHF_EXECINSTR) == 0
5154 || (sec->flags & SEC_EXCLUDE) != 0
33a7ffc2
JM
5155 || sec->sec_info_type == ELF_INFO_TYPE_JUST_SYMS
5156 || sec->output_section == bfd_abs_section_ptr
c7b8f16e
JB
5157 || strcmp (sec->name, VFP11_ERRATUM_VENEER_SECTION_NAME) == 0)
5158 continue;
5159
5160 sec_data = elf32_arm_section_data (sec);
906e58ca 5161
c7b8f16e
JB
5162 if (sec_data->mapcount == 0)
5163 continue;
906e58ca 5164
c7b8f16e
JB
5165 if (elf_section_data (sec)->this_hdr.contents != NULL)
5166 contents = elf_section_data (sec)->this_hdr.contents;
5167 else if (! bfd_malloc_and_get_section (abfd, sec, &contents))
5168 goto error_return;
5169
5170 qsort (sec_data->map, sec_data->mapcount, sizeof (elf32_arm_section_map),
5171 elf32_arm_compare_mapping);
5172
5173 for (span = 0; span < sec_data->mapcount; span++)
5174 {
5175 unsigned int span_start = sec_data->map[span].vma;
5176 unsigned int span_end = (span == sec_data->mapcount - 1)
5177 ? sec->size : sec_data->map[span + 1].vma;
5178 char span_type = sec_data->map[span].type;
906e58ca 5179
c7b8f16e
JB
5180 /* FIXME: Only ARM mode is supported at present. We may need to
5181 support Thumb-2 mode also at some point. */
5182 if (span_type != 'a')
5183 continue;
5184
5185 for (i = span_start; i < span_end;)
5186 {
5187 unsigned int next_i = i + 4;
5188 unsigned int insn = bfd_big_endian (abfd)
5189 ? (contents[i] << 24)
5190 | (contents[i + 1] << 16)
5191 | (contents[i + 2] << 8)
5192 | contents[i + 3]
5193 : (contents[i + 3] << 24)
5194 | (contents[i + 2] << 16)
5195 | (contents[i + 1] << 8)
5196 | contents[i];
5197 unsigned int writemask = 0;
5198 enum bfd_arm_vfp11_pipe pipe;
5199
5200 switch (state)
5201 {
5202 case 0:
5203 pipe = bfd_arm_vfp11_insn_decode (insn, &writemask, regs,
5204 &numregs);
5205 /* I'm assuming the VFP11 erratum can trigger with denorm
5206 operands on either the FMAC or the DS pipeline. This might
5207 lead to slightly overenthusiastic veneer insertion. */
5208 if (pipe == VFP11_FMAC || pipe == VFP11_DS)
5209 {
5210 state = use_vector ? 1 : 2;
5211 first_fmac = i;
5212 veneer_of_insn = insn;
5213 }
5214 break;
5215
5216 case 1:
5217 {
5218 int other_regs[3], other_numregs;
5219 pipe = bfd_arm_vfp11_insn_decode (insn, &writemask,
5220 other_regs,
5221 &other_numregs);
5222 if (pipe != VFP11_BAD
5223 && bfd_arm_vfp11_antidependency (writemask, regs,
5224 numregs))
5225 state = 3;
5226 else
5227 state = 2;
5228 }
5229 break;
5230
5231 case 2:
5232 {
5233 int other_regs[3], other_numregs;
5234 pipe = bfd_arm_vfp11_insn_decode (insn, &writemask,
5235 other_regs,
5236 &other_numregs);
5237 if (pipe != VFP11_BAD
5238 && bfd_arm_vfp11_antidependency (writemask, regs,
5239 numregs))
5240 state = 3;
5241 else
5242 {
5243 state = 0;
5244 next_i = first_fmac + 4;
5245 }
5246 }
5247 break;
5248
5249 case 3:
5250 abort (); /* Should be unreachable. */
5251 }
5252
5253 if (state == 3)
5254 {
5255 elf32_vfp11_erratum_list *newerr
5256 = bfd_zmalloc (sizeof (elf32_vfp11_erratum_list));
5257 int errcount;
5258
5259 errcount = ++(elf32_arm_section_data (sec)->erratumcount);
5260
5261 newerr->u.b.vfp_insn = veneer_of_insn;
5262
5263 switch (span_type)
5264 {
5265 case 'a':
5266 newerr->type = VFP11_ERRATUM_BRANCH_TO_ARM_VENEER;
5267 break;
906e58ca 5268
c7b8f16e
JB
5269 default:
5270 abort ();
5271 }
5272
5273 record_vfp11_erratum_veneer (link_info, newerr, abfd, sec,
5274 first_fmac);
5275
5276 newerr->vma = -1;
5277
5278 newerr->next = sec_data->erratumlist;
5279 sec_data->erratumlist = newerr;
5280
5281 state = 0;
5282 }
5283
5284 i = next_i;
5285 }
5286 }
906e58ca 5287
c7b8f16e
JB
5288 if (contents != NULL
5289 && elf_section_data (sec)->this_hdr.contents != contents)
5290 free (contents);
5291 contents = NULL;
5292 }
5293
5294 return TRUE;
5295
5296error_return:
5297 if (contents != NULL
5298 && elf_section_data (sec)->this_hdr.contents != contents)
5299 free (contents);
906e58ca 5300
c7b8f16e
JB
5301 return FALSE;
5302}
5303
5304/* Find virtual-memory addresses for VFP11 erratum veneers and return locations
5305 after sections have been laid out, using specially-named symbols. */
5306
5307void
5308bfd_elf32_arm_vfp11_fix_veneer_locations (bfd *abfd,
5309 struct bfd_link_info *link_info)
5310{
5311 asection *sec;
5312 struct elf32_arm_link_hash_table *globals;
5313 char *tmp_name;
906e58ca 5314
c7b8f16e
JB
5315 if (link_info->relocatable)
5316 return;
2e6030b9
MS
5317
5318 /* Skip if this bfd does not correspond to an ELF image. */
0ffa91dd 5319 if (! is_arm_elf (abfd))
2e6030b9
MS
5320 return;
5321
c7b8f16e 5322 globals = elf32_arm_hash_table (link_info);
906e58ca 5323
c7b8f16e
JB
5324 tmp_name = bfd_malloc ((bfd_size_type) strlen
5325 (VFP11_ERRATUM_VENEER_ENTRY_NAME) + 10);
5326
5327 for (sec = abfd->sections; sec != NULL; sec = sec->next)
5328 {
5329 struct _arm_elf_section_data *sec_data = elf32_arm_section_data (sec);
5330 elf32_vfp11_erratum_list *errnode = sec_data->erratumlist;
906e58ca 5331
c7b8f16e
JB
5332 for (; errnode != NULL; errnode = errnode->next)
5333 {
5334 struct elf_link_hash_entry *myh;
5335 bfd_vma vma;
5336
5337 switch (errnode->type)
5338 {
5339 case VFP11_ERRATUM_BRANCH_TO_ARM_VENEER:
5340 case VFP11_ERRATUM_BRANCH_TO_THUMB_VENEER:
5341 /* Find veneer symbol. */
5342 sprintf (tmp_name, VFP11_ERRATUM_VENEER_ENTRY_NAME,
5343 errnode->u.b.veneer->u.v.id);
5344
5345 myh = elf_link_hash_lookup
5346 (&(globals)->root, tmp_name, FALSE, FALSE, TRUE);
5347
5348 if (myh == NULL)
5349 (*_bfd_error_handler) (_("%B: unable to find VFP11 veneer "
5350 "`%s'"), abfd, tmp_name);
5351
5352 vma = myh->root.u.def.section->output_section->vma
5353 + myh->root.u.def.section->output_offset
5354 + myh->root.u.def.value;
5355
5356 errnode->u.b.veneer->vma = vma;
5357 break;
5358
5359 case VFP11_ERRATUM_ARM_VENEER:
5360 case VFP11_ERRATUM_THUMB_VENEER:
5361 /* Find return location. */
5362 sprintf (tmp_name, VFP11_ERRATUM_VENEER_ENTRY_NAME "_r",
5363 errnode->u.v.id);
5364
5365 myh = elf_link_hash_lookup
5366 (&(globals)->root, tmp_name, FALSE, FALSE, TRUE);
5367
5368 if (myh == NULL)
5369 (*_bfd_error_handler) (_("%B: unable to find VFP11 veneer "
5370 "`%s'"), abfd, tmp_name);
5371
5372 vma = myh->root.u.def.section->output_section->vma
5373 + myh->root.u.def.section->output_offset
5374 + myh->root.u.def.value;
5375
5376 errnode->u.v.branch->vma = vma;
5377 break;
906e58ca 5378
c7b8f16e
JB
5379 default:
5380 abort ();
5381 }
5382 }
5383 }
906e58ca 5384
c7b8f16e
JB
5385 free (tmp_name);
5386}
5387
5388
eb043451
PB
5389/* Set target relocation values needed during linking. */
5390
5391void
bf21ed78
MS
5392bfd_elf32_arm_set_target_relocs (struct bfd *output_bfd,
5393 struct bfd_link_info *link_info,
eb043451 5394 int target1_is_rel,
319850b4 5395 char * target2_type,
33bfe774 5396 int fix_v4bx,
c7b8f16e 5397 int use_blx,
bf21ed78 5398 bfd_arm_vfp11_fix vfp11_fix,
a9dc9481
JM
5399 int no_enum_warn, int no_wchar_warn,
5400 int pic_veneer)
eb043451
PB
5401{
5402 struct elf32_arm_link_hash_table *globals;
5403
5404 globals = elf32_arm_hash_table (link_info);
5405
5406 globals->target1_is_rel = target1_is_rel;
5407 if (strcmp (target2_type, "rel") == 0)
5408 globals->target2_reloc = R_ARM_REL32;
eeac373a
PB
5409 else if (strcmp (target2_type, "abs") == 0)
5410 globals->target2_reloc = R_ARM_ABS32;
eb043451
PB
5411 else if (strcmp (target2_type, "got-rel") == 0)
5412 globals->target2_reloc = R_ARM_GOT_PREL;
5413 else
5414 {
5415 _bfd_error_handler (_("Invalid TARGET2 relocation type '%s'."),
5416 target2_type);
5417 }
319850b4 5418 globals->fix_v4bx = fix_v4bx;
33bfe774 5419 globals->use_blx |= use_blx;
c7b8f16e 5420 globals->vfp11_fix = vfp11_fix;
27e55c4d 5421 globals->pic_veneer = pic_veneer;
bf21ed78 5422
0ffa91dd
NC
5423 BFD_ASSERT (is_arm_elf (output_bfd));
5424 elf_arm_tdata (output_bfd)->no_enum_size_warning = no_enum_warn;
a9dc9481 5425 elf_arm_tdata (output_bfd)->no_wchar_size_warning = no_wchar_warn;
eb043451 5426}
eb043451 5427
12a0a0fd 5428/* Replace the target offset of a Thumb bl or b.w instruction. */
252b5132 5429
12a0a0fd
PB
5430static void
5431insert_thumb_branch (bfd *abfd, long int offset, bfd_byte *insn)
5432{
5433 bfd_vma upper;
5434 bfd_vma lower;
5435 int reloc_sign;
5436
5437 BFD_ASSERT ((offset & 1) == 0);
5438
5439 upper = bfd_get_16 (abfd, insn);
5440 lower = bfd_get_16 (abfd, insn + 2);
5441 reloc_sign = (offset < 0) ? 1 : 0;
5442 upper = (upper & ~(bfd_vma) 0x7ff)
5443 | ((offset >> 12) & 0x3ff)
5444 | (reloc_sign << 10);
906e58ca 5445 lower = (lower & ~(bfd_vma) 0x2fff)
12a0a0fd
PB
5446 | (((!((offset >> 23) & 1)) ^ reloc_sign) << 13)
5447 | (((!((offset >> 22) & 1)) ^ reloc_sign) << 11)
5448 | ((offset >> 1) & 0x7ff);
5449 bfd_put_16 (abfd, upper, insn);
5450 bfd_put_16 (abfd, lower, insn + 2);
252b5132
RH
5451}
5452
9b485d32
NC
5453/* Thumb code calling an ARM function. */
5454
252b5132 5455static int
57e8b36a
NC
5456elf32_thumb_to_arm_stub (struct bfd_link_info * info,
5457 const char * name,
5458 bfd * input_bfd,
5459 bfd * output_bfd,
5460 asection * input_section,
5461 bfd_byte * hit_data,
5462 asection * sym_sec,
5463 bfd_vma offset,
5464 bfd_signed_vma addend,
f2a9dd69
DJ
5465 bfd_vma val,
5466 char **error_message)
252b5132 5467{
bcbdc74c 5468 asection * s = 0;
dc810e39 5469 bfd_vma my_offset;
252b5132 5470 long int ret_offset;
bcbdc74c
NC
5471 struct elf_link_hash_entry * myh;
5472 struct elf32_arm_link_hash_table * globals;
252b5132 5473
f2a9dd69 5474 myh = find_thumb_glue (info, name, error_message);
252b5132 5475 if (myh == NULL)
b34976b6 5476 return FALSE;
252b5132
RH
5477
5478 globals = elf32_arm_hash_table (info);
5479
5480 BFD_ASSERT (globals != NULL);
5481 BFD_ASSERT (globals->bfd_of_glue_owner != NULL);
5482
5483 my_offset = myh->root.u.def.value;
5484
5485 s = bfd_get_section_by_name (globals->bfd_of_glue_owner,
5486 THUMB2ARM_GLUE_SECTION_NAME);
5487
5488 BFD_ASSERT (s != NULL);
5489 BFD_ASSERT (s->contents != NULL);
5490 BFD_ASSERT (s->output_section != NULL);
5491
5492 if ((my_offset & 0x01) == 0x01)
5493 {
5494 if (sym_sec != NULL
5495 && sym_sec->owner != NULL
5496 && !INTERWORK_FLAG (sym_sec->owner))
5497 {
8f615d07 5498 (*_bfd_error_handler)
d003868e
AM
5499 (_("%B(%s): warning: interworking not enabled.\n"
5500 " first occurrence: %B: thumb call to arm"),
5501 sym_sec->owner, input_bfd, name);
252b5132 5502
b34976b6 5503 return FALSE;
252b5132
RH
5504 }
5505
5506 --my_offset;
5507 myh->root.u.def.value = my_offset;
5508
52ab56c2
PB
5509 put_thumb_insn (globals, output_bfd, (bfd_vma) t2a1_bx_pc_insn,
5510 s->contents + my_offset);
252b5132 5511
52ab56c2
PB
5512 put_thumb_insn (globals, output_bfd, (bfd_vma) t2a2_noop_insn,
5513 s->contents + my_offset + 2);
252b5132
RH
5514
5515 ret_offset =
9b485d32
NC
5516 /* Address of destination of the stub. */
5517 ((bfd_signed_vma) val)
252b5132 5518 - ((bfd_signed_vma)
57e8b36a
NC
5519 /* Offset from the start of the current section
5520 to the start of the stubs. */
9b485d32
NC
5521 (s->output_offset
5522 /* Offset of the start of this stub from the start of the stubs. */
5523 + my_offset
5524 /* Address of the start of the current section. */
5525 + s->output_section->vma)
5526 /* The branch instruction is 4 bytes into the stub. */
5527 + 4
5528 /* ARM branches work from the pc of the instruction + 8. */
5529 + 8);
252b5132 5530
52ab56c2
PB
5531 put_arm_insn (globals, output_bfd,
5532 (bfd_vma) t2a3_b_insn | ((ret_offset >> 2) & 0x00FFFFFF),
5533 s->contents + my_offset + 4);
252b5132
RH
5534 }
5535
5536 BFD_ASSERT (my_offset <= globals->thumb_glue_size);
5537
427bfd90
NC
5538 /* Now go back and fix up the original BL insn to point to here. */
5539 ret_offset =
5540 /* Address of where the stub is located. */
5541 (s->output_section->vma + s->output_offset + my_offset)
5542 /* Address of where the BL is located. */
57e8b36a
NC
5543 - (input_section->output_section->vma + input_section->output_offset
5544 + offset)
427bfd90
NC
5545 /* Addend in the relocation. */
5546 - addend
5547 /* Biassing for PC-relative addressing. */
5548 - 8;
252b5132 5549
12a0a0fd 5550 insert_thumb_branch (input_bfd, ret_offset, hit_data - input_section->vma);
252b5132 5551
b34976b6 5552 return TRUE;
252b5132
RH
5553}
5554
a4fd1a8e 5555/* Populate an Arm to Thumb stub. Returns the stub symbol. */
9b485d32 5556
a4fd1a8e
PB
5557static struct elf_link_hash_entry *
5558elf32_arm_create_thumb_stub (struct bfd_link_info * info,
5559 const char * name,
5560 bfd * input_bfd,
5561 bfd * output_bfd,
5562 asection * sym_sec,
5563 bfd_vma val,
8029a119
NC
5564 asection * s,
5565 char ** error_message)
252b5132 5566{
dc810e39 5567 bfd_vma my_offset;
252b5132 5568 long int ret_offset;
bcbdc74c
NC
5569 struct elf_link_hash_entry * myh;
5570 struct elf32_arm_link_hash_table * globals;
252b5132 5571
f2a9dd69 5572 myh = find_arm_glue (info, name, error_message);
252b5132 5573 if (myh == NULL)
a4fd1a8e 5574 return NULL;
252b5132
RH
5575
5576 globals = elf32_arm_hash_table (info);
5577
5578 BFD_ASSERT (globals != NULL);
5579 BFD_ASSERT (globals->bfd_of_glue_owner != NULL);
5580
5581 my_offset = myh->root.u.def.value;
252b5132
RH
5582
5583 if ((my_offset & 0x01) == 0x01)
5584 {
5585 if (sym_sec != NULL
5586 && sym_sec->owner != NULL
5587 && !INTERWORK_FLAG (sym_sec->owner))
5588 {
8f615d07 5589 (*_bfd_error_handler)
d003868e
AM
5590 (_("%B(%s): warning: interworking not enabled.\n"
5591 " first occurrence: %B: arm call to thumb"),
5592 sym_sec->owner, input_bfd, name);
252b5132 5593 }
9b485d32 5594
252b5132
RH
5595 --my_offset;
5596 myh->root.u.def.value = my_offset;
5597
27e55c4d
PB
5598 if (info->shared || globals->root.is_relocatable_executable
5599 || globals->pic_veneer)
8f6277f5
PB
5600 {
5601 /* For relocatable objects we can't use absolute addresses,
5602 so construct the address from a relative offset. */
5603 /* TODO: If the offset is small it's probably worth
5604 constructing the address with adds. */
52ab56c2
PB
5605 put_arm_insn (globals, output_bfd, (bfd_vma) a2t1p_ldr_insn,
5606 s->contents + my_offset);
5607 put_arm_insn (globals, output_bfd, (bfd_vma) a2t2p_add_pc_insn,
5608 s->contents + my_offset + 4);
5609 put_arm_insn (globals, output_bfd, (bfd_vma) a2t3p_bx_r12_insn,
5610 s->contents + my_offset + 8);
8f6277f5
PB
5611 /* Adjust the offset by 4 for the position of the add,
5612 and 8 for the pipeline offset. */
5613 ret_offset = (val - (s->output_offset
5614 + s->output_section->vma
5615 + my_offset + 12))
5616 | 1;
5617 bfd_put_32 (output_bfd, ret_offset,
5618 s->contents + my_offset + 12);
5619 }
26079076
PB
5620 else if (globals->use_blx)
5621 {
5622 put_arm_insn (globals, output_bfd, (bfd_vma) a2t1v5_ldr_insn,
5623 s->contents + my_offset);
5624
5625 /* It's a thumb address. Add the low order bit. */
5626 bfd_put_32 (output_bfd, val | a2t2v5_func_addr_insn,
5627 s->contents + my_offset + 4);
5628 }
8f6277f5
PB
5629 else
5630 {
52ab56c2
PB
5631 put_arm_insn (globals, output_bfd, (bfd_vma) a2t1_ldr_insn,
5632 s->contents + my_offset);
252b5132 5633
52ab56c2
PB
5634 put_arm_insn (globals, output_bfd, (bfd_vma) a2t2_bx_r12_insn,
5635 s->contents + my_offset + 4);
252b5132 5636
8f6277f5
PB
5637 /* It's a thumb address. Add the low order bit. */
5638 bfd_put_32 (output_bfd, val | a2t3_func_addr_insn,
5639 s->contents + my_offset + 8);
8029a119
NC
5640
5641 my_offset += 12;
8f6277f5 5642 }
252b5132
RH
5643 }
5644
5645 BFD_ASSERT (my_offset <= globals->arm_glue_size);
5646
a4fd1a8e
PB
5647 return myh;
5648}
5649
5650/* Arm code calling a Thumb function. */
5651
5652static int
5653elf32_arm_to_thumb_stub (struct bfd_link_info * info,
5654 const char * name,
5655 bfd * input_bfd,
5656 bfd * output_bfd,
5657 asection * input_section,
5658 bfd_byte * hit_data,
5659 asection * sym_sec,
5660 bfd_vma offset,
5661 bfd_signed_vma addend,
f2a9dd69
DJ
5662 bfd_vma val,
5663 char **error_message)
a4fd1a8e
PB
5664{
5665 unsigned long int tmp;
5666 bfd_vma my_offset;
5667 asection * s;
5668 long int ret_offset;
5669 struct elf_link_hash_entry * myh;
5670 struct elf32_arm_link_hash_table * globals;
5671
5672 globals = elf32_arm_hash_table (info);
5673
5674 BFD_ASSERT (globals != NULL);
5675 BFD_ASSERT (globals->bfd_of_glue_owner != NULL);
5676
5677 s = bfd_get_section_by_name (globals->bfd_of_glue_owner,
5678 ARM2THUMB_GLUE_SECTION_NAME);
5679 BFD_ASSERT (s != NULL);
5680 BFD_ASSERT (s->contents != NULL);
5681 BFD_ASSERT (s->output_section != NULL);
5682
5683 myh = elf32_arm_create_thumb_stub (info, name, input_bfd, output_bfd,
f2a9dd69 5684 sym_sec, val, s, error_message);
a4fd1a8e
PB
5685 if (!myh)
5686 return FALSE;
5687
5688 my_offset = myh->root.u.def.value;
252b5132
RH
5689 tmp = bfd_get_32 (input_bfd, hit_data);
5690 tmp = tmp & 0xFF000000;
5691
9b485d32 5692 /* Somehow these are both 4 too far, so subtract 8. */
dc810e39
AM
5693 ret_offset = (s->output_offset
5694 + my_offset
5695 + s->output_section->vma
5696 - (input_section->output_offset
5697 + input_section->output_section->vma
5698 + offset + addend)
5699 - 8);
9a5aca8c 5700
252b5132
RH
5701 tmp = tmp | ((ret_offset >> 2) & 0x00FFFFFF);
5702
dc810e39 5703 bfd_put_32 (output_bfd, (bfd_vma) tmp, hit_data - input_section->vma);
252b5132 5704
b34976b6 5705 return TRUE;
252b5132
RH
5706}
5707
a4fd1a8e
PB
5708/* Populate Arm stub for an exported Thumb function. */
5709
5710static bfd_boolean
5711elf32_arm_to_thumb_export_stub (struct elf_link_hash_entry *h, void * inf)
5712{
5713 struct bfd_link_info * info = (struct bfd_link_info *) inf;
5714 asection * s;
5715 struct elf_link_hash_entry * myh;
5716 struct elf32_arm_link_hash_entry *eh;
5717 struct elf32_arm_link_hash_table * globals;
5718 asection *sec;
5719 bfd_vma val;
f2a9dd69 5720 char *error_message;
a4fd1a8e 5721
906e58ca 5722 eh = elf32_arm_hash_entry (h);
a4fd1a8e
PB
5723 /* Allocate stubs for exported Thumb functions on v4t. */
5724 if (eh->export_glue == NULL)
5725 return TRUE;
5726
5727 globals = elf32_arm_hash_table (info);
5728
5729 BFD_ASSERT (globals != NULL);
5730 BFD_ASSERT (globals->bfd_of_glue_owner != NULL);
5731
5732 s = bfd_get_section_by_name (globals->bfd_of_glue_owner,
5733 ARM2THUMB_GLUE_SECTION_NAME);
5734 BFD_ASSERT (s != NULL);
5735 BFD_ASSERT (s->contents != NULL);
5736 BFD_ASSERT (s->output_section != NULL);
5737
5738 sec = eh->export_glue->root.u.def.section;
0eaedd0e
PB
5739
5740 BFD_ASSERT (sec->output_section != NULL);
5741
a4fd1a8e
PB
5742 val = eh->export_glue->root.u.def.value + sec->output_offset
5743 + sec->output_section->vma;
8029a119 5744
a4fd1a8e
PB
5745 myh = elf32_arm_create_thumb_stub (info, h->root.root.string,
5746 h->root.u.def.section->owner,
f2a9dd69
DJ
5747 globals->obfd, sec, val, s,
5748 &error_message);
a4fd1a8e
PB
5749 BFD_ASSERT (myh);
5750 return TRUE;
5751}
5752
845b51d6
PB
5753/* Populate ARMv4 BX veneers. Returns the absolute adress of the veneer. */
5754
5755static bfd_vma
5756elf32_arm_bx_glue (struct bfd_link_info * info, int reg)
5757{
5758 bfd_byte *p;
5759 bfd_vma glue_addr;
5760 asection *s;
5761 struct elf32_arm_link_hash_table *globals;
5762
5763 globals = elf32_arm_hash_table (info);
5764
5765 BFD_ASSERT (globals != NULL);
5766 BFD_ASSERT (globals->bfd_of_glue_owner != NULL);
5767
5768 s = bfd_get_section_by_name (globals->bfd_of_glue_owner,
5769 ARM_BX_GLUE_SECTION_NAME);
5770 BFD_ASSERT (s != NULL);
5771 BFD_ASSERT (s->contents != NULL);
5772 BFD_ASSERT (s->output_section != NULL);
5773
5774 BFD_ASSERT (globals->bx_glue_offset[reg] & 2);
5775
5776 glue_addr = globals->bx_glue_offset[reg] & ~(bfd_vma)3;
5777
5778 if ((globals->bx_glue_offset[reg] & 1) == 0)
5779 {
5780 p = s->contents + glue_addr;
5781 bfd_put_32 (globals->obfd, armbx1_tst_insn + (reg << 16), p);
5782 bfd_put_32 (globals->obfd, armbx2_moveq_insn + reg, p + 4);
5783 bfd_put_32 (globals->obfd, armbx3_bx_insn + reg, p + 8);
5784 globals->bx_glue_offset[reg] |= 1;
5785 }
5786
5787 return glue_addr + s->output_section->vma + s->output_offset;
5788}
5789
a4fd1a8e
PB
5790/* Generate Arm stubs for exported Thumb symbols. */
5791static void
906e58ca 5792elf32_arm_begin_write_processing (bfd *abfd ATTRIBUTE_UNUSED,
a4fd1a8e
PB
5793 struct bfd_link_info *link_info)
5794{
5795 struct elf32_arm_link_hash_table * globals;
5796
8029a119
NC
5797 if (link_info == NULL)
5798 /* Ignore this if we are not called by the ELF backend linker. */
a4fd1a8e
PB
5799 return;
5800
5801 globals = elf32_arm_hash_table (link_info);
84c08195
PB
5802 /* If blx is available then exported Thumb symbols are OK and there is
5803 nothing to do. */
a4fd1a8e
PB
5804 if (globals->use_blx)
5805 return;
5806
5807 elf_link_hash_traverse (&globals->root, elf32_arm_to_thumb_export_stub,
5808 link_info);
5809}
5810
eb043451
PB
5811/* Some relocations map to different relocations depending on the
5812 target. Return the real relocation. */
8029a119 5813
eb043451
PB
5814static int
5815arm_real_reloc_type (struct elf32_arm_link_hash_table * globals,
5816 int r_type)
5817{
5818 switch (r_type)
5819 {
5820 case R_ARM_TARGET1:
5821 if (globals->target1_is_rel)
5822 return R_ARM_REL32;
5823 else
5824 return R_ARM_ABS32;
5825
5826 case R_ARM_TARGET2:
5827 return globals->target2_reloc;
5828
5829 default:
5830 return r_type;
5831 }
5832}
eb043451 5833
ba93b8ac
DJ
5834/* Return the base VMA address which should be subtracted from real addresses
5835 when resolving @dtpoff relocation.
5836 This is PT_TLS segment p_vaddr. */
5837
5838static bfd_vma
5839dtpoff_base (struct bfd_link_info *info)
5840{
5841 /* If tls_sec is NULL, we should have signalled an error already. */
5842 if (elf_hash_table (info)->tls_sec == NULL)
5843 return 0;
5844 return elf_hash_table (info)->tls_sec->vma;
5845}
5846
5847/* Return the relocation value for @tpoff relocation
5848 if STT_TLS virtual address is ADDRESS. */
5849
5850static bfd_vma
5851tpoff (struct bfd_link_info *info, bfd_vma address)
5852{
5853 struct elf_link_hash_table *htab = elf_hash_table (info);
5854 bfd_vma base;
5855
5856 /* If tls_sec is NULL, we should have signalled an error already. */
5857 if (htab->tls_sec == NULL)
5858 return 0;
5859 base = align_power ((bfd_vma) TCB_SIZE, htab->tls_sec->alignment_power);
5860 return address - htab->tls_sec->vma + base;
5861}
5862
00a97672
RS
5863/* Perform an R_ARM_ABS12 relocation on the field pointed to by DATA.
5864 VALUE is the relocation value. */
5865
5866static bfd_reloc_status_type
5867elf32_arm_abs12_reloc (bfd *abfd, void *data, bfd_vma value)
5868{
5869 if (value > 0xfff)
5870 return bfd_reloc_overflow;
5871
5872 value |= bfd_get_32 (abfd, data) & 0xfffff000;
5873 bfd_put_32 (abfd, value, data);
5874 return bfd_reloc_ok;
5875}
5876
4962c51a
MS
5877/* For a given value of n, calculate the value of G_n as required to
5878 deal with group relocations. We return it in the form of an
5879 encoded constant-and-rotation, together with the final residual. If n is
5880 specified as less than zero, then final_residual is filled with the
5881 input value and no further action is performed. */
5882
5883static bfd_vma
5884calculate_group_reloc_mask (bfd_vma value, int n, bfd_vma *final_residual)
5885{
5886 int current_n;
5887 bfd_vma g_n;
5888 bfd_vma encoded_g_n = 0;
5889 bfd_vma residual = value; /* Also known as Y_n. */
5890
5891 for (current_n = 0; current_n <= n; current_n++)
5892 {
5893 int shift;
5894
5895 /* Calculate which part of the value to mask. */
5896 if (residual == 0)
5897 shift = 0;
5898 else
5899 {
5900 int msb;
5901
5902 /* Determine the most significant bit in the residual and
5903 align the resulting value to a 2-bit boundary. */
5904 for (msb = 30; msb >= 0; msb -= 2)
5905 if (residual & (3 << msb))
5906 break;
5907
5908 /* The desired shift is now (msb - 6), or zero, whichever
5909 is the greater. */
5910 shift = msb - 6;
5911 if (shift < 0)
5912 shift = 0;
5913 }
5914
5915 /* Calculate g_n in 32-bit as well as encoded constant+rotation form. */
5916 g_n = residual & (0xff << shift);
5917 encoded_g_n = (g_n >> shift)
5918 | ((g_n <= 0xff ? 0 : (32 - shift) / 2) << 8);
5919
5920 /* Calculate the residual for the next time around. */
5921 residual &= ~g_n;
5922 }
5923
5924 *final_residual = residual;
5925
5926 return encoded_g_n;
5927}
5928
5929/* Given an ARM instruction, determine whether it is an ADD or a SUB.
5930 Returns 1 if it is an ADD, -1 if it is a SUB, and 0 otherwise. */
906e58ca 5931
4962c51a 5932static int
906e58ca 5933identify_add_or_sub (bfd_vma insn)
4962c51a
MS
5934{
5935 int opcode = insn & 0x1e00000;
5936
5937 if (opcode == 1 << 23) /* ADD */
5938 return 1;
5939
5940 if (opcode == 1 << 22) /* SUB */
5941 return -1;
5942
5943 return 0;
5944}
5945
252b5132 5946/* Perform a relocation as part of a final link. */
9b485d32 5947
252b5132 5948static bfd_reloc_status_type
57e8b36a
NC
5949elf32_arm_final_link_relocate (reloc_howto_type * howto,
5950 bfd * input_bfd,
5951 bfd * output_bfd,
5952 asection * input_section,
5953 bfd_byte * contents,
5954 Elf_Internal_Rela * rel,
5955 bfd_vma value,
5956 struct bfd_link_info * info,
5957 asection * sym_sec,
5958 const char * sym_name,
5959 int sym_flags,
0945cdfd 5960 struct elf_link_hash_entry * h,
f2a9dd69 5961 bfd_boolean * unresolved_reloc_p,
8029a119 5962 char ** error_message)
252b5132
RH
5963{
5964 unsigned long r_type = howto->type;
5965 unsigned long r_symndx;
5966 bfd_byte * hit_data = contents + rel->r_offset;
5967 bfd * dynobj = NULL;
5968 Elf_Internal_Shdr * symtab_hdr;
5969 struct elf_link_hash_entry ** sym_hashes;
5970 bfd_vma * local_got_offsets;
5971 asection * sgot = NULL;
5972 asection * splt = NULL;
5973 asection * sreloc = NULL;
252b5132 5974 bfd_vma addend;
ba96a88f
NC
5975 bfd_signed_vma signed_addend;
5976 struct elf32_arm_link_hash_table * globals;
f21f3fe0 5977
9c504268
PB
5978 globals = elf32_arm_hash_table (info);
5979
0ffa91dd
NC
5980 BFD_ASSERT (is_arm_elf (input_bfd));
5981
5982 /* Some relocation types map to different relocations depending on the
9c504268 5983 target. We pick the right one here. */
eb043451
PB
5984 r_type = arm_real_reloc_type (globals, r_type);
5985 if (r_type != howto->type)
5986 howto = elf32_arm_howto_from_type (r_type);
9c504268 5987
cac15327
NC
5988 /* If the start address has been set, then set the EF_ARM_HASENTRY
5989 flag. Setting this more than once is redundant, but the cost is
5990 not too high, and it keeps the code simple.
99e4ae17 5991
cac15327
NC
5992 The test is done here, rather than somewhere else, because the
5993 start address is only set just before the final link commences.
5994
5995 Note - if the user deliberately sets a start address of 0, the
5996 flag will not be set. */
5997 if (bfd_get_start_address (output_bfd) != 0)
5998 elf_elfheader (output_bfd)->e_flags |= EF_ARM_HASENTRY;
99e4ae17 5999
252b5132
RH
6000 dynobj = elf_hash_table (info)->dynobj;
6001 if (dynobj)
6002 {
6003 sgot = bfd_get_section_by_name (dynobj, ".got");
6004 splt = bfd_get_section_by_name (dynobj, ".plt");
6005 }
0ffa91dd 6006 symtab_hdr = & elf_symtab_hdr (input_bfd);
252b5132
RH
6007 sym_hashes = elf_sym_hashes (input_bfd);
6008 local_got_offsets = elf_local_got_offsets (input_bfd);
6009 r_symndx = ELF32_R_SYM (rel->r_info);
6010
4e7fd91e 6011 if (globals->use_rel)
ba96a88f 6012 {
4e7fd91e
PB
6013 addend = bfd_get_32 (input_bfd, hit_data) & howto->src_mask;
6014
6015 if (addend & ((howto->src_mask + 1) >> 1))
6016 {
6017 signed_addend = -1;
6018 signed_addend &= ~ howto->src_mask;
6019 signed_addend |= addend;
6020 }
6021 else
6022 signed_addend = addend;
ba96a88f
NC
6023 }
6024 else
4e7fd91e 6025 addend = signed_addend = rel->r_addend;
f21f3fe0 6026
252b5132
RH
6027 switch (r_type)
6028 {
6029 case R_ARM_NONE:
28a094c2
DJ
6030 /* We don't need to find a value for this symbol. It's just a
6031 marker. */
6032 *unresolved_reloc_p = FALSE;
252b5132
RH
6033 return bfd_reloc_ok;
6034
00a97672
RS
6035 case R_ARM_ABS12:
6036 if (!globals->vxworks_p)
6037 return elf32_arm_abs12_reloc (input_bfd, hit_data, value + addend);
6038
252b5132
RH
6039 case R_ARM_PC24:
6040 case R_ARM_ABS32:
bb224fc3 6041 case R_ARM_ABS32_NOI:
252b5132 6042 case R_ARM_REL32:
bb224fc3 6043 case R_ARM_REL32_NOI:
5b5bb741
PB
6044 case R_ARM_CALL:
6045 case R_ARM_JUMP24:
dfc5f959 6046 case R_ARM_XPC25:
eb043451 6047 case R_ARM_PREL31:
7359ea65 6048 case R_ARM_PLT32:
7359ea65
DJ
6049 /* Handle relocations which should use the PLT entry. ABS32/REL32
6050 will use the symbol's value, which may point to a PLT entry, but we
6051 don't need to handle that here. If we created a PLT entry, all
6052 branches in this object should go to it. */
bb224fc3
MS
6053 if ((r_type != R_ARM_ABS32 && r_type != R_ARM_REL32
6054 && r_type != R_ARM_ABS32_NOI && r_type != R_ARM_REL32_NOI)
7359ea65 6055 && h != NULL
c84cd8ee 6056 && splt != NULL
7359ea65
DJ
6057 && h->plt.offset != (bfd_vma) -1)
6058 {
c84cd8ee
DJ
6059 /* If we've created a .plt section, and assigned a PLT entry to
6060 this function, it should not be known to bind locally. If
6061 it were, we would have cleared the PLT entry. */
7359ea65
DJ
6062 BFD_ASSERT (!SYMBOL_CALLS_LOCAL (info, h));
6063
6064 value = (splt->output_section->vma
6065 + splt->output_offset
6066 + h->plt.offset);
0945cdfd 6067 *unresolved_reloc_p = FALSE;
7359ea65
DJ
6068 return _bfd_final_link_relocate (howto, input_bfd, input_section,
6069 contents, rel->r_offset, value,
00a97672 6070 rel->r_addend);
7359ea65
DJ
6071 }
6072
67687978
PB
6073 /* When generating a shared object or relocatable executable, these
6074 relocations are copied into the output file to be resolved at
6075 run time. */
6076 if ((info->shared || globals->root.is_relocatable_executable)
7359ea65 6077 && (input_section->flags & SEC_ALLOC)
3348747a
NS
6078 && !(elf32_arm_hash_table (info)->vxworks_p
6079 && strcmp (input_section->output_section->name,
6080 ".tls_vars") == 0)
bb224fc3 6081 && ((r_type != R_ARM_REL32 && r_type != R_ARM_REL32_NOI)
ee06dc07 6082 || !SYMBOL_CALLS_LOCAL (info, h))
7359ea65
DJ
6083 && (h == NULL
6084 || ELF_ST_VISIBILITY (h->other) == STV_DEFAULT
6085 || h->root.type != bfd_link_hash_undefweak)
6086 && r_type != R_ARM_PC24
5b5bb741
PB
6087 && r_type != R_ARM_CALL
6088 && r_type != R_ARM_JUMP24
ee06dc07 6089 && r_type != R_ARM_PREL31
7359ea65 6090 && r_type != R_ARM_PLT32)
252b5132 6091 {
947216bf
AM
6092 Elf_Internal_Rela outrel;
6093 bfd_byte *loc;
b34976b6 6094 bfd_boolean skip, relocate;
f21f3fe0 6095
0945cdfd
DJ
6096 *unresolved_reloc_p = FALSE;
6097
252b5132
RH
6098 if (sreloc == NULL)
6099 {
83bac4b0
NC
6100 sreloc = _bfd_elf_get_dynamic_reloc_section (input_bfd, input_section,
6101 ! globals->use_rel);
f21f3fe0 6102
83bac4b0 6103 if (sreloc == NULL)
252b5132 6104 return bfd_reloc_notsupported;
252b5132 6105 }
f21f3fe0 6106
b34976b6
AM
6107 skip = FALSE;
6108 relocate = FALSE;
f21f3fe0 6109
00a97672 6110 outrel.r_addend = addend;
c629eae0
JJ
6111 outrel.r_offset =
6112 _bfd_elf_section_offset (output_bfd, info, input_section,
6113 rel->r_offset);
6114 if (outrel.r_offset == (bfd_vma) -1)
b34976b6 6115 skip = TRUE;
0bb2d96a 6116 else if (outrel.r_offset == (bfd_vma) -2)
b34976b6 6117 skip = TRUE, relocate = TRUE;
252b5132
RH
6118 outrel.r_offset += (input_section->output_section->vma
6119 + input_section->output_offset);
f21f3fe0 6120
252b5132 6121 if (skip)
0bb2d96a 6122 memset (&outrel, 0, sizeof outrel);
5e681ec4
PB
6123 else if (h != NULL
6124 && h->dynindx != -1
7359ea65 6125 && (!info->shared
5e681ec4 6126 || !info->symbolic
f5385ebf 6127 || !h->def_regular))
5e681ec4 6128 outrel.r_info = ELF32_R_INFO (h->dynindx, r_type);
252b5132
RH
6129 else
6130 {
a16385dc
MM
6131 int symbol;
6132
5e681ec4 6133 /* This symbol is local, or marked to become local. */
b7693d02
DJ
6134 if (sym_flags == STT_ARM_TFUNC)
6135 value |= 1;
a16385dc 6136 if (globals->symbian_p)
6366ff1e 6137 {
74541ad4
AM
6138 asection *osec;
6139
6366ff1e
MM
6140 /* On Symbian OS, the data segment and text segement
6141 can be relocated independently. Therefore, we
6142 must indicate the segment to which this
6143 relocation is relative. The BPABI allows us to
6144 use any symbol in the right segment; we just use
6145 the section symbol as it is convenient. (We
6146 cannot use the symbol given by "h" directly as it
74541ad4
AM
6147 will not appear in the dynamic symbol table.)
6148
6149 Note that the dynamic linker ignores the section
6150 symbol value, so we don't subtract osec->vma
6151 from the emitted reloc addend. */
10dbd1f3 6152 if (sym_sec)
74541ad4 6153 osec = sym_sec->output_section;
10dbd1f3 6154 else
74541ad4
AM
6155 osec = input_section->output_section;
6156 symbol = elf_section_data (osec)->dynindx;
6157 if (symbol == 0)
6158 {
6159 struct elf_link_hash_table *htab = elf_hash_table (info);
6160
6161 if ((osec->flags & SEC_READONLY) == 0
6162 && htab->data_index_section != NULL)
6163 osec = htab->data_index_section;
6164 else
6165 osec = htab->text_index_section;
6166 symbol = elf_section_data (osec)->dynindx;
6167 }
6366ff1e
MM
6168 BFD_ASSERT (symbol != 0);
6169 }
a16385dc
MM
6170 else
6171 /* On SVR4-ish systems, the dynamic loader cannot
6172 relocate the text and data segments independently,
6173 so the symbol does not matter. */
6174 symbol = 0;
6175 outrel.r_info = ELF32_R_INFO (symbol, R_ARM_RELATIVE);
00a97672
RS
6176 if (globals->use_rel)
6177 relocate = TRUE;
6178 else
6179 outrel.r_addend += value;
252b5132 6180 }
f21f3fe0 6181
947216bf 6182 loc = sreloc->contents;
00a97672
RS
6183 loc += sreloc->reloc_count++ * RELOC_SIZE (globals);
6184 SWAP_RELOC_OUT (globals) (output_bfd, &outrel, loc);
9a5aca8c 6185
f21f3fe0 6186 /* If this reloc is against an external symbol, we do not want to
252b5132 6187 fiddle with the addend. Otherwise, we need to include the symbol
9b485d32 6188 value so that it becomes an addend for the dynamic reloc. */
252b5132
RH
6189 if (! relocate)
6190 return bfd_reloc_ok;
9a5aca8c 6191
f21f3fe0 6192 return _bfd_final_link_relocate (howto, input_bfd, input_section,
252b5132
RH
6193 contents, rel->r_offset, value,
6194 (bfd_vma) 0);
6195 }
6196 else switch (r_type)
6197 {
00a97672
RS
6198 case R_ARM_ABS12:
6199 return elf32_arm_abs12_reloc (input_bfd, hit_data, value + addend);
6200
dfc5f959 6201 case R_ARM_XPC25: /* Arm BLX instruction. */
5b5bb741
PB
6202 case R_ARM_CALL:
6203 case R_ARM_JUMP24:
8029a119 6204 case R_ARM_PC24: /* Arm B/BL instruction. */
7359ea65 6205 case R_ARM_PLT32:
906e58ca
NC
6206 {
6207 bfd_vma from;
6208 bfd_signed_vma branch_offset;
6209 struct elf32_arm_stub_hash_entry *stub_entry = NULL;
6210
6211 from = (input_section->output_section->vma
6212 + input_section->output_offset
6213 + rel->r_offset);
6214 branch_offset = (bfd_signed_vma)(value - from);
6215
dfc5f959 6216 if (r_type == R_ARM_XPC25)
252b5132 6217 {
dfc5f959
NC
6218 /* Check for Arm calling Arm function. */
6219 /* FIXME: Should we translate the instruction into a BL
6220 instruction instead ? */
6221 if (sym_flags != STT_ARM_TFUNC)
d003868e
AM
6222 (*_bfd_error_handler)
6223 (_("\%B: Warning: Arm BLX instruction targets Arm function '%s'."),
6224 input_bfd,
6225 h ? h->root.root.string : "(local)");
dfc5f959 6226 }
906e58ca 6227 else if (r_type != R_ARM_CALL)
dfc5f959
NC
6228 {
6229 /* Check for Arm calling Thumb function. */
6230 if (sym_flags == STT_ARM_TFUNC)
6231 {
f2a9dd69
DJ
6232 if (elf32_arm_to_thumb_stub (info, sym_name, input_bfd,
6233 output_bfd, input_section,
6234 hit_data, sym_sec, rel->r_offset,
6235 signed_addend, value,
6236 error_message))
6237 return bfd_reloc_ok;
6238 else
6239 return bfd_reloc_dangerous;
dfc5f959 6240 }
252b5132 6241 }
ba96a88f 6242
906e58ca 6243 /* Check if a stub has to be inserted because the
8029a119 6244 destination is too far or we are changing mode. */
906e58ca
NC
6245 if (r_type == R_ARM_CALL)
6246 {
6247 if (branch_offset > ARM_MAX_FWD_BRANCH_OFFSET
6248 || branch_offset < ARM_MAX_BWD_BRANCH_OFFSET
6249 || sym_flags == STT_ARM_TFUNC)
6250 {
6251 /* The target is out of reach, so redirect the
6252 branch to the local stub for this function. */
6253
6254 stub_entry = elf32_arm_get_stub_entry (input_section,
6255 sym_sec, h,
6256 rel, globals);
6257 if (stub_entry != NULL)
6258 value = (stub_entry->stub_offset
6259 + stub_entry->stub_sec->output_offset
6260 + stub_entry->stub_sec->output_section->vma);
6261 }
6262 }
6263
dea514f5
PB
6264 /* The ARM ELF ABI says that this reloc is computed as: S - P + A
6265 where:
6266 S is the address of the symbol in the relocation.
6267 P is address of the instruction being relocated.
6268 A is the addend (extracted from the instruction) in bytes.
6269
6270 S is held in 'value'.
6271 P is the base address of the section containing the
6272 instruction plus the offset of the reloc into that
6273 section, ie:
6274 (input_section->output_section->vma +
6275 input_section->output_offset +
6276 rel->r_offset).
6277 A is the addend, converted into bytes, ie:
6278 (signed_addend * 4)
6279
6280 Note: None of these operations have knowledge of the pipeline
6281 size of the processor, thus it is up to the assembler to
6282 encode this information into the addend. */
6283 value -= (input_section->output_section->vma
6284 + input_section->output_offset);
6285 value -= rel->r_offset;
4e7fd91e
PB
6286 if (globals->use_rel)
6287 value += (signed_addend << howto->size);
6288 else
6289 /* RELA addends do not have to be adjusted by howto->size. */
6290 value += signed_addend;
23080146 6291
dcb5e6e6
NC
6292 signed_addend = value;
6293 signed_addend >>= howto->rightshift;
9a5aca8c 6294
5ab79981
PB
6295 /* A branch to an undefined weak symbol is turned into a jump to
6296 the next instruction. */
6297 if (h && h->root.type == bfd_link_hash_undefweak)
6298 {
6299 value = (bfd_get_32 (input_bfd, hit_data) & 0xf0000000)
6300 | 0x0affffff;
6301 }
6302 else
59f2c4e7 6303 {
9b485d32 6304 /* Perform a signed range check. */
dcb5e6e6 6305 if ( signed_addend > ((bfd_signed_vma) (howto->dst_mask >> 1))
59f2c4e7
NC
6306 || signed_addend < - ((bfd_signed_vma) ((howto->dst_mask + 1) >> 1)))
6307 return bfd_reloc_overflow;
9a5aca8c 6308
5ab79981 6309 addend = (value & 2);
39b41c9c 6310
5ab79981
PB
6311 value = (signed_addend & howto->dst_mask)
6312 | (bfd_get_32 (input_bfd, hit_data) & (~ howto->dst_mask));
39b41c9c 6313
5ab79981 6314 /* Set the H bit in the BLX instruction. */
39b41c9c 6315 if (sym_flags == STT_ARM_TFUNC)
39b41c9c 6316 {
5ab79981
PB
6317 if (addend)
6318 value |= (1 << 24);
6319 else
6320 value &= ~(bfd_vma)(1 << 24);
6321 }
6322 if (r_type == R_ARM_CALL)
6323 {
6324 /* Select the correct instruction (BL or BLX). */
906e58ca 6325 /* Only if we are not handling a BL to a stub. In this
8029a119 6326 case, mode switching is performed by the stub. */
906e58ca 6327 if (sym_flags == STT_ARM_TFUNC && !stub_entry)
5ab79981
PB
6328 value |= (1 << 28);
6329 else
6330 {
6331 value &= ~(bfd_vma)(1 << 28);
6332 value |= (1 << 24);
6333 }
39b41c9c
PB
6334 }
6335 }
906e58ca 6336 }
252b5132 6337 break;
f21f3fe0 6338
252b5132
RH
6339 case R_ARM_ABS32:
6340 value += addend;
6341 if (sym_flags == STT_ARM_TFUNC)
6342 value |= 1;
6343 break;
f21f3fe0 6344
bb224fc3
MS
6345 case R_ARM_ABS32_NOI:
6346 value += addend;
6347 break;
6348
252b5132 6349 case R_ARM_REL32:
a8bc6c78
PB
6350 value += addend;
6351 if (sym_flags == STT_ARM_TFUNC)
6352 value |= 1;
252b5132 6353 value -= (input_section->output_section->vma
62efb346 6354 + input_section->output_offset + rel->r_offset);
252b5132 6355 break;
eb043451 6356
bb224fc3
MS
6357 case R_ARM_REL32_NOI:
6358 value += addend;
6359 value -= (input_section->output_section->vma
6360 + input_section->output_offset + rel->r_offset);
6361 break;
6362
eb043451
PB
6363 case R_ARM_PREL31:
6364 value -= (input_section->output_section->vma
6365 + input_section->output_offset + rel->r_offset);
6366 value += signed_addend;
6367 if (! h || h->root.type != bfd_link_hash_undefweak)
6368 {
8029a119 6369 /* Check for overflow. */
eb043451
PB
6370 if ((value ^ (value >> 1)) & (1 << 30))
6371 return bfd_reloc_overflow;
6372 }
6373 value &= 0x7fffffff;
6374 value |= (bfd_get_32 (input_bfd, hit_data) & 0x80000000);
6375 if (sym_flags == STT_ARM_TFUNC)
6376 value |= 1;
6377 break;
252b5132 6378 }
f21f3fe0 6379
252b5132
RH
6380 bfd_put_32 (input_bfd, value, hit_data);
6381 return bfd_reloc_ok;
6382
6383 case R_ARM_ABS8:
6384 value += addend;
6385 if ((long) value > 0x7f || (long) value < -0x80)
6386 return bfd_reloc_overflow;
6387
6388 bfd_put_8 (input_bfd, value, hit_data);
6389 return bfd_reloc_ok;
6390
6391 case R_ARM_ABS16:
6392 value += addend;
6393
6394 if ((long) value > 0x7fff || (long) value < -0x8000)
6395 return bfd_reloc_overflow;
6396
6397 bfd_put_16 (input_bfd, value, hit_data);
6398 return bfd_reloc_ok;
6399
252b5132 6400 case R_ARM_THM_ABS5:
9b485d32 6401 /* Support ldr and str instructions for the thumb. */
4e7fd91e
PB
6402 if (globals->use_rel)
6403 {
6404 /* Need to refetch addend. */
6405 addend = bfd_get_16 (input_bfd, hit_data) & howto->src_mask;
6406 /* ??? Need to determine shift amount from operand size. */
6407 addend >>= howto->rightshift;
6408 }
252b5132
RH
6409 value += addend;
6410
6411 /* ??? Isn't value unsigned? */
6412 if ((long) value > 0x1f || (long) value < -0x10)
6413 return bfd_reloc_overflow;
6414
6415 /* ??? Value needs to be properly shifted into place first. */
6416 value |= bfd_get_16 (input_bfd, hit_data) & 0xf83f;
6417 bfd_put_16 (input_bfd, value, hit_data);
6418 return bfd_reloc_ok;
6419
2cab6cc3
MS
6420 case R_ARM_THM_ALU_PREL_11_0:
6421 /* Corresponds to: addw.w reg, pc, #offset (and similarly for subw). */
6422 {
6423 bfd_vma insn;
6424 bfd_signed_vma relocation;
6425
6426 insn = (bfd_get_16 (input_bfd, hit_data) << 16)
6427 | bfd_get_16 (input_bfd, hit_data + 2);
6428
6429 if (globals->use_rel)
6430 {
6431 signed_addend = (insn & 0xff) | ((insn & 0x7000) >> 4)
6432 | ((insn & (1 << 26)) >> 15);
6433 if (insn & 0xf00000)
6434 signed_addend = -signed_addend;
6435 }
6436
6437 relocation = value + signed_addend;
6438 relocation -= (input_section->output_section->vma
6439 + input_section->output_offset
6440 + rel->r_offset);
6441
6442 value = abs (relocation);
6443
6444 if (value >= 0x1000)
6445 return bfd_reloc_overflow;
6446
6447 insn = (insn & 0xfb0f8f00) | (value & 0xff)
6448 | ((value & 0x700) << 4)
6449 | ((value & 0x800) << 15);
6450 if (relocation < 0)
6451 insn |= 0xa00000;
6452
6453 bfd_put_16 (input_bfd, insn >> 16, hit_data);
6454 bfd_put_16 (input_bfd, insn & 0xffff, hit_data + 2);
6455
6456 return bfd_reloc_ok;
6457 }
6458
6459 case R_ARM_THM_PC12:
6460 /* Corresponds to: ldr.w reg, [pc, #offset]. */
6461 {
6462 bfd_vma insn;
6463 bfd_signed_vma relocation;
6464
6465 insn = (bfd_get_16 (input_bfd, hit_data) << 16)
6466 | bfd_get_16 (input_bfd, hit_data + 2);
6467
6468 if (globals->use_rel)
6469 {
6470 signed_addend = insn & 0xfff;
6471 if (!(insn & (1 << 23)))
6472 signed_addend = -signed_addend;
6473 }
6474
6475 relocation = value + signed_addend;
6476 relocation -= (input_section->output_section->vma
6477 + input_section->output_offset
6478 + rel->r_offset);
6479
6480 value = abs (relocation);
6481
6482 if (value >= 0x1000)
6483 return bfd_reloc_overflow;
6484
6485 insn = (insn & 0xff7ff000) | value;
6486 if (relocation >= 0)
6487 insn |= (1 << 23);
6488
6489 bfd_put_16 (input_bfd, insn >> 16, hit_data);
6490 bfd_put_16 (input_bfd, insn & 0xffff, hit_data + 2);
6491
6492 return bfd_reloc_ok;
6493 }
6494
dfc5f959 6495 case R_ARM_THM_XPC22:
c19d1205 6496 case R_ARM_THM_CALL:
bd97cb95 6497 case R_ARM_THM_JUMP24:
dfc5f959 6498 /* Thumb BL (branch long instruction). */
252b5132 6499 {
b34976b6 6500 bfd_vma relocation;
e95de063 6501 bfd_vma reloc_sign;
b34976b6
AM
6502 bfd_boolean overflow = FALSE;
6503 bfd_vma upper_insn = bfd_get_16 (input_bfd, hit_data);
6504 bfd_vma lower_insn = bfd_get_16 (input_bfd, hit_data + 2);
e95de063
MS
6505 bfd_signed_vma reloc_signed_max;
6506 bfd_signed_vma reloc_signed_min;
b34976b6 6507 bfd_vma check;
252b5132 6508 bfd_signed_vma signed_check;
e95de063
MS
6509 int bitsize;
6510 int thumb2 = using_thumb2 (globals);
252b5132 6511
5ab79981 6512 /* A branch to an undefined weak symbol is turned into a jump to
19540007
JM
6513 the next instruction unless a PLT entry will be created. */
6514 if (h && h->root.type == bfd_link_hash_undefweak
6515 && !(splt != NULL && h->plt.offset != (bfd_vma) -1))
5ab79981
PB
6516 {
6517 bfd_put_16 (input_bfd, 0xe000, hit_data);
6518 bfd_put_16 (input_bfd, 0xbf00, hit_data + 2);
6519 return bfd_reloc_ok;
6520 }
6521
e95de063
MS
6522 /* Fetch the addend. We use the Thumb-2 encoding (backwards compatible
6523 with Thumb-1) involving the J1 and J2 bits. */
4e7fd91e
PB
6524 if (globals->use_rel)
6525 {
e95de063
MS
6526 bfd_vma s = (upper_insn & (1 << 10)) >> 10;
6527 bfd_vma upper = upper_insn & 0x3ff;
6528 bfd_vma lower = lower_insn & 0x7ff;
6529 bfd_vma j1 = (lower_insn & (1 << 13)) >> 13;
6530 bfd_vma j2 = (lower_insn & (1 << 11)) >> 11;
6531 bfd_vma i1 = j1 ^ s ? 0 : 1;
6532 bfd_vma i2 = j2 ^ s ? 0 : 1;
6533
6534 addend = (i1 << 23) | (i2 << 22) | (upper << 12) | (lower << 1);
6535 /* Sign extend. */
6536 addend = (addend | ((s ? 0 : 1) << 24)) - (1 << 24);
6537
4e7fd91e
PB
6538 signed_addend = addend;
6539 }
cb1afa5c 6540
dfc5f959
NC
6541 if (r_type == R_ARM_THM_XPC22)
6542 {
6543 /* Check for Thumb to Thumb call. */
6544 /* FIXME: Should we translate the instruction into a BL
6545 instruction instead ? */
6546 if (sym_flags == STT_ARM_TFUNC)
d003868e
AM
6547 (*_bfd_error_handler)
6548 (_("%B: Warning: Thumb BLX instruction targets thumb function '%s'."),
6549 input_bfd,
6550 h ? h->root.root.string : "(local)");
dfc5f959
NC
6551 }
6552 else
252b5132 6553 {
dfc5f959
NC
6554 /* If it is not a call to Thumb, assume call to Arm.
6555 If it is a call relative to a section name, then it is not a
b7693d02
DJ
6556 function call at all, but rather a long jump. Calls through
6557 the PLT do not require stubs. */
6558 if (sym_flags != STT_ARM_TFUNC && sym_flags != STT_SECTION
6559 && (h == NULL || splt == NULL
6560 || h->plt.offset == (bfd_vma) -1))
dfc5f959 6561 {
bd97cb95 6562 if (globals->use_blx && r_type == R_ARM_THM_CALL)
39b41c9c
PB
6563 {
6564 /* Convert BL to BLX. */
6565 lower_insn = (lower_insn & ~0x1000) | 0x0800;
6566 }
8029a119
NC
6567 else if (r_type != R_ARM_THM_CALL)
6568 {
6569 if (elf32_thumb_to_arm_stub
6570 (info, sym_name, input_bfd, output_bfd, input_section,
6571 hit_data, sym_sec, rel->r_offset, signed_addend, value,
6572 error_message))
6573 return bfd_reloc_ok;
6574 else
6575 return bfd_reloc_dangerous;
6576 }
da5938a2 6577 }
bd97cb95
DJ
6578 else if (sym_flags == STT_ARM_TFUNC && globals->use_blx
6579 && r_type == R_ARM_THM_CALL)
39b41c9c
PB
6580 {
6581 /* Make sure this is a BL. */
6582 lower_insn |= 0x1800;
6583 }
252b5132 6584 }
f21f3fe0 6585
b7693d02
DJ
6586 /* Handle calls via the PLT. */
6587 if (h != NULL && splt != NULL && h->plt.offset != (bfd_vma) -1)
6588 {
6589 value = (splt->output_section->vma
6590 + splt->output_offset
6591 + h->plt.offset);
bd97cb95 6592 if (globals->use_blx && r_type == R_ARM_THM_CALL)
33bfe774
JB
6593 {
6594 /* If the Thumb BLX instruction is available, convert the
6595 BL to a BLX instruction to call the ARM-mode PLT entry. */
39b41c9c 6596 lower_insn = (lower_insn & ~0x1000) | 0x0800;
33bfe774
JB
6597 }
6598 else
6599 /* Target the Thumb stub before the ARM PLT entry. */
6600 value -= PLT_THUMB_STUB_SIZE;
0945cdfd 6601 *unresolved_reloc_p = FALSE;
b7693d02
DJ
6602 }
6603
906e58ca
NC
6604 if (r_type == R_ARM_THM_CALL)
6605 {
6606 /* Check if a stub has to be inserted because the destination
8029a119 6607 is too far. */
906e58ca
NC
6608 bfd_vma from;
6609 bfd_signed_vma branch_offset;
6610 struct elf32_arm_stub_hash_entry *stub_entry = NULL;
6611
6612 from = (input_section->output_section->vma
6613 + input_section->output_offset
6614 + rel->r_offset);
6615 branch_offset = (bfd_signed_vma)(value - from);
6616
6617 if ((!thumb2
6618 && (branch_offset > THM_MAX_FWD_BRANCH_OFFSET
6619 || (branch_offset < THM_MAX_BWD_BRANCH_OFFSET)))
6620 ||
6621 (thumb2
6622 && (branch_offset > THM2_MAX_FWD_BRANCH_OFFSET
f4ac8484
DJ
6623 || (branch_offset < THM2_MAX_BWD_BRANCH_OFFSET)))
6624 || ((sym_flags != STT_ARM_TFUNC) && !globals->use_blx))
906e58ca
NC
6625 {
6626 /* The target is out of reach or we are changing modes, so
6627 redirect the branch to the local stub for this
6628 function. */
6629 stub_entry = elf32_arm_get_stub_entry (input_section,
6630 sym_sec, h,
6631 rel, globals);
6632 if (stub_entry != NULL)
6633 value = (stub_entry->stub_offset
6634 + stub_entry->stub_sec->output_offset
6635 + stub_entry->stub_sec->output_section->vma);
6636
f4ac8484
DJ
6637 /* If this call becomes a call to Arm, force BLX. */
6638 if (globals->use_blx)
6639 {
6640 if ((stub_entry
6641 && !arm_stub_is_thumb (stub_entry->stub_type))
6642 || (sym_flags != STT_ARM_TFUNC))
6643 lower_insn = (lower_insn & ~0x1000) | 0x0800;
6644 }
906e58ca
NC
6645 }
6646 }
6647
ba96a88f 6648 relocation = value + signed_addend;
f21f3fe0 6649
252b5132 6650 relocation -= (input_section->output_section->vma
ba96a88f
NC
6651 + input_section->output_offset
6652 + rel->r_offset);
9a5aca8c 6653
252b5132
RH
6654 check = relocation >> howto->rightshift;
6655
6656 /* If this is a signed value, the rightshift just dropped
6657 leading 1 bits (assuming twos complement). */
6658 if ((bfd_signed_vma) relocation >= 0)
6659 signed_check = check;
6660 else
6661 signed_check = check | ~((bfd_vma) -1 >> howto->rightshift);
6662
e95de063
MS
6663 /* Calculate the permissable maximum and minimum values for
6664 this relocation according to whether we're relocating for
6665 Thumb-2 or not. */
6666 bitsize = howto->bitsize;
6667 if (!thumb2)
6668 bitsize -= 2;
6669 reloc_signed_max = ((1 << (bitsize - 1)) - 1) >> howto->rightshift;
6670 reloc_signed_min = ~reloc_signed_max;
6671
252b5132 6672 /* Assumes two's complement. */
ba96a88f 6673 if (signed_check > reloc_signed_max || signed_check < reloc_signed_min)
b34976b6 6674 overflow = TRUE;
252b5132 6675
bd97cb95 6676 if ((lower_insn & 0x5000) == 0x4000)
c62e1cc3
NC
6677 /* For a BLX instruction, make sure that the relocation is rounded up
6678 to a word boundary. This follows the semantics of the instruction
6679 which specifies that bit 1 of the target address will come from bit
6680 1 of the base address. */
6681 relocation = (relocation + 2) & ~ 3;
cb1afa5c 6682
e95de063
MS
6683 /* Put RELOCATION back into the insn. Assumes two's complement.
6684 We use the Thumb-2 encoding, which is safe even if dealing with
6685 a Thumb-1 instruction by virtue of our overflow check above. */
6686 reloc_sign = (signed_check < 0) ? 1 : 0;
6687 upper_insn = (upper_insn & ~(bfd_vma) 0x7ff)
6688 | ((relocation >> 12) & 0x3ff)
6689 | (reloc_sign << 10);
906e58ca 6690 lower_insn = (lower_insn & ~(bfd_vma) 0x2fff)
e95de063
MS
6691 | (((!((relocation >> 23) & 1)) ^ reloc_sign) << 13)
6692 | (((!((relocation >> 22) & 1)) ^ reloc_sign) << 11)
6693 | ((relocation >> 1) & 0x7ff);
c62e1cc3 6694
252b5132
RH
6695 /* Put the relocated value back in the object file: */
6696 bfd_put_16 (input_bfd, upper_insn, hit_data);
6697 bfd_put_16 (input_bfd, lower_insn, hit_data + 2);
6698
6699 return (overflow ? bfd_reloc_overflow : bfd_reloc_ok);
6700 }
6701 break;
6702
c19d1205
ZW
6703 case R_ARM_THM_JUMP19:
6704 /* Thumb32 conditional branch instruction. */
6705 {
6706 bfd_vma relocation;
6707 bfd_boolean overflow = FALSE;
6708 bfd_vma upper_insn = bfd_get_16 (input_bfd, hit_data);
6709 bfd_vma lower_insn = bfd_get_16 (input_bfd, hit_data + 2);
a00a1f35
MS
6710 bfd_signed_vma reloc_signed_max = 0xffffe;
6711 bfd_signed_vma reloc_signed_min = -0x100000;
c19d1205
ZW
6712 bfd_signed_vma signed_check;
6713
6714 /* Need to refetch the addend, reconstruct the top three bits,
6715 and squish the two 11 bit pieces together. */
6716 if (globals->use_rel)
6717 {
6718 bfd_vma S = (upper_insn & 0x0400) >> 10;
a00a1f35 6719 bfd_vma upper = (upper_insn & 0x003f);
c19d1205
ZW
6720 bfd_vma J1 = (lower_insn & 0x2000) >> 13;
6721 bfd_vma J2 = (lower_insn & 0x0800) >> 11;
6722 bfd_vma lower = (lower_insn & 0x07ff);
6723
a00a1f35
MS
6724 upper |= J1 << 6;
6725 upper |= J2 << 7;
6726 upper |= (!S) << 8;
c19d1205
ZW
6727 upper -= 0x0100; /* Sign extend. */
6728
6729 addend = (upper << 12) | (lower << 1);
6730 signed_addend = addend;
6731 }
6732
bd97cb95
DJ
6733 /* Handle calls via the PLT. */
6734 if (h != NULL && splt != NULL && h->plt.offset != (bfd_vma) -1)
6735 {
6736 value = (splt->output_section->vma
6737 + splt->output_offset
6738 + h->plt.offset);
6739 /* Target the Thumb stub before the ARM PLT entry. */
6740 value -= PLT_THUMB_STUB_SIZE;
6741 *unresolved_reloc_p = FALSE;
6742 }
6743
c19d1205
ZW
6744 /* ??? Should handle interworking? GCC might someday try to
6745 use this for tail calls. */
6746
6747 relocation = value + signed_addend;
6748 relocation -= (input_section->output_section->vma
6749 + input_section->output_offset
6750 + rel->r_offset);
a00a1f35 6751 signed_check = (bfd_signed_vma) relocation;
c19d1205 6752
c19d1205
ZW
6753 if (signed_check > reloc_signed_max || signed_check < reloc_signed_min)
6754 overflow = TRUE;
6755
6756 /* Put RELOCATION back into the insn. */
6757 {
6758 bfd_vma S = (relocation & 0x00100000) >> 20;
6759 bfd_vma J2 = (relocation & 0x00080000) >> 19;
6760 bfd_vma J1 = (relocation & 0x00040000) >> 18;
6761 bfd_vma hi = (relocation & 0x0003f000) >> 12;
6762 bfd_vma lo = (relocation & 0x00000ffe) >> 1;
6763
a00a1f35 6764 upper_insn = (upper_insn & 0xfbc0) | (S << 10) | hi;
c19d1205
ZW
6765 lower_insn = (lower_insn & 0xd000) | (J1 << 13) | (J2 << 11) | lo;
6766 }
6767
6768 /* Put the relocated value back in the object file: */
6769 bfd_put_16 (input_bfd, upper_insn, hit_data);
6770 bfd_put_16 (input_bfd, lower_insn, hit_data + 2);
6771
6772 return (overflow ? bfd_reloc_overflow : bfd_reloc_ok);
6773 }
6774
6775 case R_ARM_THM_JUMP11:
6776 case R_ARM_THM_JUMP8:
6777 case R_ARM_THM_JUMP6:
51c5503b
NC
6778 /* Thumb B (branch) instruction). */
6779 {
6cf9e9fe 6780 bfd_signed_vma relocation;
51c5503b
NC
6781 bfd_signed_vma reloc_signed_max = (1 << (howto->bitsize - 1)) - 1;
6782 bfd_signed_vma reloc_signed_min = ~ reloc_signed_max;
51c5503b
NC
6783 bfd_signed_vma signed_check;
6784
c19d1205
ZW
6785 /* CZB cannot jump backward. */
6786 if (r_type == R_ARM_THM_JUMP6)
6787 reloc_signed_min = 0;
6788
4e7fd91e 6789 if (globals->use_rel)
6cf9e9fe 6790 {
4e7fd91e
PB
6791 /* Need to refetch addend. */
6792 addend = bfd_get_16 (input_bfd, hit_data) & howto->src_mask;
6793 if (addend & ((howto->src_mask + 1) >> 1))
6794 {
6795 signed_addend = -1;
6796 signed_addend &= ~ howto->src_mask;
6797 signed_addend |= addend;
6798 }
6799 else
6800 signed_addend = addend;
6801 /* The value in the insn has been right shifted. We need to
6802 undo this, so that we can perform the address calculation
6803 in terms of bytes. */
6804 signed_addend <<= howto->rightshift;
6cf9e9fe 6805 }
6cf9e9fe 6806 relocation = value + signed_addend;
51c5503b
NC
6807
6808 relocation -= (input_section->output_section->vma
6809 + input_section->output_offset
6810 + rel->r_offset);
6811
6cf9e9fe
NC
6812 relocation >>= howto->rightshift;
6813 signed_check = relocation;
c19d1205
ZW
6814
6815 if (r_type == R_ARM_THM_JUMP6)
6816 relocation = ((relocation & 0x0020) << 4) | ((relocation & 0x001f) << 3);
6817 else
6818 relocation &= howto->dst_mask;
51c5503b 6819 relocation |= (bfd_get_16 (input_bfd, hit_data) & (~ howto->dst_mask));
cedb70c5 6820
51c5503b
NC
6821 bfd_put_16 (input_bfd, relocation, hit_data);
6822
6823 /* Assumes two's complement. */
6824 if (signed_check > reloc_signed_max || signed_check < reloc_signed_min)
6825 return bfd_reloc_overflow;
6826
6827 return bfd_reloc_ok;
6828 }
cedb70c5 6829
8375c36b
PB
6830 case R_ARM_ALU_PCREL7_0:
6831 case R_ARM_ALU_PCREL15_8:
6832 case R_ARM_ALU_PCREL23_15:
6833 {
6834 bfd_vma insn;
6835 bfd_vma relocation;
6836
6837 insn = bfd_get_32 (input_bfd, hit_data);
4e7fd91e
PB
6838 if (globals->use_rel)
6839 {
6840 /* Extract the addend. */
6841 addend = (insn & 0xff) << ((insn & 0xf00) >> 7);
6842 signed_addend = addend;
6843 }
8375c36b
PB
6844 relocation = value + signed_addend;
6845
6846 relocation -= (input_section->output_section->vma
6847 + input_section->output_offset
6848 + rel->r_offset);
6849 insn = (insn & ~0xfff)
6850 | ((howto->bitpos << 7) & 0xf00)
6851 | ((relocation >> howto->bitpos) & 0xff);
6852 bfd_put_32 (input_bfd, value, hit_data);
6853 }
6854 return bfd_reloc_ok;
6855
252b5132
RH
6856 case R_ARM_GNU_VTINHERIT:
6857 case R_ARM_GNU_VTENTRY:
6858 return bfd_reloc_ok;
6859
c19d1205 6860 case R_ARM_GOTOFF32:
252b5132
RH
6861 /* Relocation is relative to the start of the
6862 global offset table. */
6863
6864 BFD_ASSERT (sgot != NULL);
6865 if (sgot == NULL)
6866 return bfd_reloc_notsupported;
9a5aca8c 6867
cedb70c5 6868 /* If we are addressing a Thumb function, we need to adjust the
ee29b9fb
RE
6869 address by one, so that attempts to call the function pointer will
6870 correctly interpret it as Thumb code. */
6871 if (sym_flags == STT_ARM_TFUNC)
6872 value += 1;
6873
252b5132
RH
6874 /* Note that sgot->output_offset is not involved in this
6875 calculation. We always want the start of .got. If we
6876 define _GLOBAL_OFFSET_TABLE in a different way, as is
6877 permitted by the ABI, we might have to change this
9b485d32 6878 calculation. */
252b5132 6879 value -= sgot->output_section->vma;
f21f3fe0 6880 return _bfd_final_link_relocate (howto, input_bfd, input_section,
99e4ae17 6881 contents, rel->r_offset, value,
00a97672 6882 rel->r_addend);
252b5132
RH
6883
6884 case R_ARM_GOTPC:
a7c10850 6885 /* Use global offset table as symbol value. */
252b5132 6886 BFD_ASSERT (sgot != NULL);
f21f3fe0 6887
252b5132
RH
6888 if (sgot == NULL)
6889 return bfd_reloc_notsupported;
6890
0945cdfd 6891 *unresolved_reloc_p = FALSE;
252b5132 6892 value = sgot->output_section->vma;
f21f3fe0 6893 return _bfd_final_link_relocate (howto, input_bfd, input_section,
99e4ae17 6894 contents, rel->r_offset, value,
00a97672 6895 rel->r_addend);
f21f3fe0 6896
252b5132 6897 case R_ARM_GOT32:
eb043451 6898 case R_ARM_GOT_PREL:
252b5132 6899 /* Relocation is to the entry for this symbol in the
9b485d32 6900 global offset table. */
252b5132
RH
6901 if (sgot == NULL)
6902 return bfd_reloc_notsupported;
f21f3fe0 6903
252b5132
RH
6904 if (h != NULL)
6905 {
6906 bfd_vma off;
5e681ec4 6907 bfd_boolean dyn;
f21f3fe0 6908
252b5132
RH
6909 off = h->got.offset;
6910 BFD_ASSERT (off != (bfd_vma) -1);
5e681ec4 6911 dyn = globals->root.dynamic_sections_created;
f21f3fe0 6912
5e681ec4 6913 if (! WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn, info->shared, h)
50d6c878 6914 || (info->shared
5e681ec4
PB
6915 && SYMBOL_REFERENCES_LOCAL (info, h))
6916 || (ELF_ST_VISIBILITY (h->other)
6917 && h->root.type == bfd_link_hash_undefweak))
252b5132
RH
6918 {
6919 /* This is actually a static link, or it is a -Bsymbolic link
6920 and the symbol is defined locally. We must initialize this
6921 entry in the global offset table. Since the offset must
6922 always be a multiple of 4, we use the least significant bit
6923 to record whether we have initialized it already.
f21f3fe0 6924
00a97672 6925 When doing a dynamic link, we create a .rel(a).got relocation
f21f3fe0 6926 entry to initialize the value. This is done in the
9b485d32 6927 finish_dynamic_symbol routine. */
252b5132
RH
6928 if ((off & 1) != 0)
6929 off &= ~1;
6930 else
6931 {
ee29b9fb
RE
6932 /* If we are addressing a Thumb function, we need to
6933 adjust the address by one, so that attempts to
6934 call the function pointer will correctly
6935 interpret it as Thumb code. */
6936 if (sym_flags == STT_ARM_TFUNC)
6937 value |= 1;
6938
252b5132
RH
6939 bfd_put_32 (output_bfd, value, sgot->contents + off);
6940 h->got.offset |= 1;
6941 }
6942 }
0945cdfd
DJ
6943 else
6944 *unresolved_reloc_p = FALSE;
f21f3fe0 6945
252b5132
RH
6946 value = sgot->output_offset + off;
6947 }
6948 else
6949 {
6950 bfd_vma off;
f21f3fe0 6951
252b5132
RH
6952 BFD_ASSERT (local_got_offsets != NULL &&
6953 local_got_offsets[r_symndx] != (bfd_vma) -1);
f21f3fe0 6954
252b5132 6955 off = local_got_offsets[r_symndx];
f21f3fe0 6956
252b5132
RH
6957 /* The offset must always be a multiple of 4. We use the
6958 least significant bit to record whether we have already
9b485d32 6959 generated the necessary reloc. */
252b5132
RH
6960 if ((off & 1) != 0)
6961 off &= ~1;
6962 else
6963 {
b7693d02
DJ
6964 /* If we are addressing a Thumb function, we need to
6965 adjust the address by one, so that attempts to
6966 call the function pointer will correctly
6967 interpret it as Thumb code. */
6968 if (sym_flags == STT_ARM_TFUNC)
6969 value |= 1;
6970
00a97672
RS
6971 if (globals->use_rel)
6972 bfd_put_32 (output_bfd, value, sgot->contents + off);
f21f3fe0 6973
252b5132
RH
6974 if (info->shared)
6975 {
6976 asection * srelgot;
947216bf
AM
6977 Elf_Internal_Rela outrel;
6978 bfd_byte *loc;
f21f3fe0 6979
00a97672
RS
6980 srelgot = (bfd_get_section_by_name
6981 (dynobj, RELOC_SECTION (globals, ".got")));
252b5132 6982 BFD_ASSERT (srelgot != NULL);
f21f3fe0 6983
00a97672 6984 outrel.r_addend = addend + value;
252b5132 6985 outrel.r_offset = (sgot->output_section->vma
f21f3fe0 6986 + sgot->output_offset
252b5132
RH
6987 + off);
6988 outrel.r_info = ELF32_R_INFO (0, R_ARM_RELATIVE);
947216bf 6989 loc = srelgot->contents;
00a97672
RS
6990 loc += srelgot->reloc_count++ * RELOC_SIZE (globals);
6991 SWAP_RELOC_OUT (globals) (output_bfd, &outrel, loc);
252b5132 6992 }
f21f3fe0 6993
252b5132
RH
6994 local_got_offsets[r_symndx] |= 1;
6995 }
f21f3fe0 6996
252b5132
RH
6997 value = sgot->output_offset + off;
6998 }
eb043451
PB
6999 if (r_type != R_ARM_GOT32)
7000 value += sgot->output_section->vma;
9a5aca8c 7001
f21f3fe0 7002 return _bfd_final_link_relocate (howto, input_bfd, input_section,
99e4ae17 7003 contents, rel->r_offset, value,
00a97672 7004 rel->r_addend);
f21f3fe0 7005
ba93b8ac
DJ
7006 case R_ARM_TLS_LDO32:
7007 value = value - dtpoff_base (info);
7008
7009 return _bfd_final_link_relocate (howto, input_bfd, input_section,
00a97672
RS
7010 contents, rel->r_offset, value,
7011 rel->r_addend);
ba93b8ac
DJ
7012
7013 case R_ARM_TLS_LDM32:
7014 {
7015 bfd_vma off;
7016
7017 if (globals->sgot == NULL)
7018 abort ();
7019
7020 off = globals->tls_ldm_got.offset;
7021
7022 if ((off & 1) != 0)
7023 off &= ~1;
7024 else
7025 {
7026 /* If we don't know the module number, create a relocation
7027 for it. */
7028 if (info->shared)
7029 {
7030 Elf_Internal_Rela outrel;
7031 bfd_byte *loc;
7032
7033 if (globals->srelgot == NULL)
7034 abort ();
7035
00a97672 7036 outrel.r_addend = 0;
ba93b8ac
DJ
7037 outrel.r_offset = (globals->sgot->output_section->vma
7038 + globals->sgot->output_offset + off);
7039 outrel.r_info = ELF32_R_INFO (0, R_ARM_TLS_DTPMOD32);
7040
00a97672
RS
7041 if (globals->use_rel)
7042 bfd_put_32 (output_bfd, outrel.r_addend,
7043 globals->sgot->contents + off);
ba93b8ac
DJ
7044
7045 loc = globals->srelgot->contents;
00a97672
RS
7046 loc += globals->srelgot->reloc_count++ * RELOC_SIZE (globals);
7047 SWAP_RELOC_OUT (globals) (output_bfd, &outrel, loc);
ba93b8ac
DJ
7048 }
7049 else
7050 bfd_put_32 (output_bfd, 1, globals->sgot->contents + off);
7051
7052 globals->tls_ldm_got.offset |= 1;
7053 }
7054
906e58ca 7055 value = globals->sgot->output_section->vma + globals->sgot->output_offset + off
ba93b8ac
DJ
7056 - (input_section->output_section->vma + input_section->output_offset + rel->r_offset);
7057
7058 return _bfd_final_link_relocate (howto, input_bfd, input_section,
7059 contents, rel->r_offset, value,
00a97672 7060 rel->r_addend);
ba93b8ac
DJ
7061 }
7062
7063 case R_ARM_TLS_GD32:
7064 case R_ARM_TLS_IE32:
7065 {
7066 bfd_vma off;
7067 int indx;
7068 char tls_type;
7069
7070 if (globals->sgot == NULL)
7071 abort ();
7072
7073 indx = 0;
7074 if (h != NULL)
7075 {
7076 bfd_boolean dyn;
7077 dyn = globals->root.dynamic_sections_created;
7078 if (WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn, info->shared, h)
7079 && (!info->shared
7080 || !SYMBOL_REFERENCES_LOCAL (info, h)))
7081 {
7082 *unresolved_reloc_p = FALSE;
7083 indx = h->dynindx;
7084 }
7085 off = h->got.offset;
7086 tls_type = ((struct elf32_arm_link_hash_entry *) h)->tls_type;
7087 }
7088 else
7089 {
7090 if (local_got_offsets == NULL)
7091 abort ();
7092 off = local_got_offsets[r_symndx];
7093 tls_type = elf32_arm_local_got_tls_type (input_bfd)[r_symndx];
7094 }
7095
7096 if (tls_type == GOT_UNKNOWN)
7097 abort ();
7098
7099 if ((off & 1) != 0)
7100 off &= ~1;
7101 else
7102 {
7103 bfd_boolean need_relocs = FALSE;
7104 Elf_Internal_Rela outrel;
7105 bfd_byte *loc = NULL;
7106 int cur_off = off;
7107
7108 /* The GOT entries have not been initialized yet. Do it
7109 now, and emit any relocations. If both an IE GOT and a
7110 GD GOT are necessary, we emit the GD first. */
7111
7112 if ((info->shared || indx != 0)
7113 && (h == NULL
7114 || ELF_ST_VISIBILITY (h->other) == STV_DEFAULT
7115 || h->root.type != bfd_link_hash_undefweak))
7116 {
7117 need_relocs = TRUE;
7118 if (globals->srelgot == NULL)
7119 abort ();
7120 loc = globals->srelgot->contents;
00a97672 7121 loc += globals->srelgot->reloc_count * RELOC_SIZE (globals);
ba93b8ac
DJ
7122 }
7123
7124 if (tls_type & GOT_TLS_GD)
7125 {
7126 if (need_relocs)
7127 {
00a97672 7128 outrel.r_addend = 0;
ba93b8ac 7129 outrel.r_offset = (globals->sgot->output_section->vma
00a97672
RS
7130 + globals->sgot->output_offset
7131 + cur_off);
ba93b8ac 7132 outrel.r_info = ELF32_R_INFO (indx, R_ARM_TLS_DTPMOD32);
ba93b8ac 7133
00a97672
RS
7134 if (globals->use_rel)
7135 bfd_put_32 (output_bfd, outrel.r_addend,
7136 globals->sgot->contents + cur_off);
7137
7138 SWAP_RELOC_OUT (globals) (output_bfd, &outrel, loc);
ba93b8ac 7139 globals->srelgot->reloc_count++;
00a97672 7140 loc += RELOC_SIZE (globals);
ba93b8ac
DJ
7141
7142 if (indx == 0)
7143 bfd_put_32 (output_bfd, value - dtpoff_base (info),
7144 globals->sgot->contents + cur_off + 4);
7145 else
7146 {
00a97672 7147 outrel.r_addend = 0;
ba93b8ac
DJ
7148 outrel.r_info = ELF32_R_INFO (indx,
7149 R_ARM_TLS_DTPOFF32);
7150 outrel.r_offset += 4;
00a97672
RS
7151
7152 if (globals->use_rel)
7153 bfd_put_32 (output_bfd, outrel.r_addend,
7154 globals->sgot->contents + cur_off + 4);
7155
7156
7157 SWAP_RELOC_OUT (globals) (output_bfd, &outrel, loc);
ba93b8ac 7158 globals->srelgot->reloc_count++;
00a97672 7159 loc += RELOC_SIZE (globals);
ba93b8ac
DJ
7160 }
7161 }
7162 else
7163 {
7164 /* If we are not emitting relocations for a
7165 general dynamic reference, then we must be in a
7166 static link or an executable link with the
7167 symbol binding locally. Mark it as belonging
7168 to module 1, the executable. */
7169 bfd_put_32 (output_bfd, 1,
7170 globals->sgot->contents + cur_off);
7171 bfd_put_32 (output_bfd, value - dtpoff_base (info),
7172 globals->sgot->contents + cur_off + 4);
7173 }
7174
7175 cur_off += 8;
7176 }
7177
7178 if (tls_type & GOT_TLS_IE)
7179 {
7180 if (need_relocs)
7181 {
00a97672
RS
7182 if (indx == 0)
7183 outrel.r_addend = value - dtpoff_base (info);
7184 else
7185 outrel.r_addend = 0;
ba93b8ac
DJ
7186 outrel.r_offset = (globals->sgot->output_section->vma
7187 + globals->sgot->output_offset
7188 + cur_off);
7189 outrel.r_info = ELF32_R_INFO (indx, R_ARM_TLS_TPOFF32);
7190
00a97672
RS
7191 if (globals->use_rel)
7192 bfd_put_32 (output_bfd, outrel.r_addend,
ba93b8ac
DJ
7193 globals->sgot->contents + cur_off);
7194
00a97672 7195 SWAP_RELOC_OUT (globals) (output_bfd, &outrel, loc);
ba93b8ac 7196 globals->srelgot->reloc_count++;
00a97672 7197 loc += RELOC_SIZE (globals);
ba93b8ac
DJ
7198 }
7199 else
7200 bfd_put_32 (output_bfd, tpoff (info, value),
7201 globals->sgot->contents + cur_off);
7202 cur_off += 4;
7203 }
7204
7205 if (h != NULL)
7206 h->got.offset |= 1;
7207 else
7208 local_got_offsets[r_symndx] |= 1;
7209 }
7210
7211 if ((tls_type & GOT_TLS_GD) && r_type != R_ARM_TLS_GD32)
7212 off += 8;
906e58ca 7213 value = globals->sgot->output_section->vma + globals->sgot->output_offset + off
ba93b8ac
DJ
7214 - (input_section->output_section->vma + input_section->output_offset + rel->r_offset);
7215
7216 return _bfd_final_link_relocate (howto, input_bfd, input_section,
7217 contents, rel->r_offset, value,
00a97672 7218 rel->r_addend);
ba93b8ac
DJ
7219 }
7220
7221 case R_ARM_TLS_LE32:
7222 if (info->shared)
7223 {
7224 (*_bfd_error_handler)
7225 (_("%B(%A+0x%lx): R_ARM_TLS_LE32 relocation not permitted in shared object"),
7226 input_bfd, input_section,
7227 (long) rel->r_offset, howto->name);
906e58ca 7228 return FALSE;
ba93b8ac
DJ
7229 }
7230 else
7231 value = tpoff (info, value);
906e58ca 7232
ba93b8ac 7233 return _bfd_final_link_relocate (howto, input_bfd, input_section,
00a97672
RS
7234 contents, rel->r_offset, value,
7235 rel->r_addend);
ba93b8ac 7236
319850b4
JB
7237 case R_ARM_V4BX:
7238 if (globals->fix_v4bx)
845b51d6
PB
7239 {
7240 bfd_vma insn = bfd_get_32 (input_bfd, hit_data);
319850b4 7241
845b51d6
PB
7242 /* Ensure that we have a BX instruction. */
7243 BFD_ASSERT ((insn & 0x0ffffff0) == 0x012fff10);
319850b4 7244
845b51d6
PB
7245 if (globals->fix_v4bx == 2 && (insn & 0xf) != 0xf)
7246 {
7247 /* Branch to veneer. */
7248 bfd_vma glue_addr;
7249 glue_addr = elf32_arm_bx_glue (info, insn & 0xf);
7250 glue_addr -= input_section->output_section->vma
7251 + input_section->output_offset
7252 + rel->r_offset + 8;
7253 insn = (insn & 0xf0000000) | 0x0a000000
7254 | ((glue_addr >> 2) & 0x00ffffff);
7255 }
7256 else
7257 {
7258 /* Preserve Rm (lowest four bits) and the condition code
7259 (highest four bits). Other bits encode MOV PC,Rm. */
7260 insn = (insn & 0xf000000f) | 0x01a0f000;
7261 }
319850b4 7262
845b51d6
PB
7263 bfd_put_32 (input_bfd, insn, hit_data);
7264 }
319850b4
JB
7265 return bfd_reloc_ok;
7266
b6895b4f
PB
7267 case R_ARM_MOVW_ABS_NC:
7268 case R_ARM_MOVT_ABS:
7269 case R_ARM_MOVW_PREL_NC:
7270 case R_ARM_MOVT_PREL:
92f5d02b
MS
7271 /* Until we properly support segment-base-relative addressing then
7272 we assume the segment base to be zero, as for the group relocations.
7273 Thus R_ARM_MOVW_BREL_NC has the same semantics as R_ARM_MOVW_ABS_NC
7274 and R_ARM_MOVT_BREL has the same semantics as R_ARM_MOVT_ABS. */
7275 case R_ARM_MOVW_BREL_NC:
7276 case R_ARM_MOVW_BREL:
7277 case R_ARM_MOVT_BREL:
b6895b4f
PB
7278 {
7279 bfd_vma insn = bfd_get_32 (input_bfd, hit_data);
7280
7281 if (globals->use_rel)
7282 {
7283 addend = ((insn >> 4) & 0xf000) | (insn & 0xfff);
39623e12 7284 signed_addend = (addend ^ 0x8000) - 0x8000;
b6895b4f 7285 }
92f5d02b 7286
b6895b4f 7287 value += signed_addend;
b6895b4f
PB
7288
7289 if (r_type == R_ARM_MOVW_PREL_NC || r_type == R_ARM_MOVT_PREL)
7290 value -= (input_section->output_section->vma
7291 + input_section->output_offset + rel->r_offset);
7292
92f5d02b
MS
7293 if (r_type == R_ARM_MOVW_BREL && value >= 0x10000)
7294 return bfd_reloc_overflow;
7295
7296 if (sym_flags == STT_ARM_TFUNC)
7297 value |= 1;
7298
7299 if (r_type == R_ARM_MOVT_ABS || r_type == R_ARM_MOVT_PREL
7300 || r_type == R_ARM_MOVT_BREL)
b6895b4f
PB
7301 value >>= 16;
7302
7303 insn &= 0xfff0f000;
7304 insn |= value & 0xfff;
7305 insn |= (value & 0xf000) << 4;
7306 bfd_put_32 (input_bfd, insn, hit_data);
7307 }
7308 return bfd_reloc_ok;
7309
7310 case R_ARM_THM_MOVW_ABS_NC:
7311 case R_ARM_THM_MOVT_ABS:
7312 case R_ARM_THM_MOVW_PREL_NC:
7313 case R_ARM_THM_MOVT_PREL:
92f5d02b
MS
7314 /* Until we properly support segment-base-relative addressing then
7315 we assume the segment base to be zero, as for the above relocations.
7316 Thus R_ARM_THM_MOVW_BREL_NC has the same semantics as
7317 R_ARM_THM_MOVW_ABS_NC and R_ARM_THM_MOVT_BREL has the same semantics
7318 as R_ARM_THM_MOVT_ABS. */
7319 case R_ARM_THM_MOVW_BREL_NC:
7320 case R_ARM_THM_MOVW_BREL:
7321 case R_ARM_THM_MOVT_BREL:
b6895b4f
PB
7322 {
7323 bfd_vma insn;
906e58ca 7324
b6895b4f
PB
7325 insn = bfd_get_16 (input_bfd, hit_data) << 16;
7326 insn |= bfd_get_16 (input_bfd, hit_data + 2);
7327
7328 if (globals->use_rel)
7329 {
7330 addend = ((insn >> 4) & 0xf000)
7331 | ((insn >> 15) & 0x0800)
7332 | ((insn >> 4) & 0x0700)
7333 | (insn & 0x00ff);
39623e12 7334 signed_addend = (addend ^ 0x8000) - 0x8000;
b6895b4f 7335 }
92f5d02b 7336
b6895b4f 7337 value += signed_addend;
b6895b4f
PB
7338
7339 if (r_type == R_ARM_THM_MOVW_PREL_NC || r_type == R_ARM_THM_MOVT_PREL)
7340 value -= (input_section->output_section->vma
7341 + input_section->output_offset + rel->r_offset);
7342
92f5d02b
MS
7343 if (r_type == R_ARM_THM_MOVW_BREL && value >= 0x10000)
7344 return bfd_reloc_overflow;
7345
7346 if (sym_flags == STT_ARM_TFUNC)
7347 value |= 1;
7348
7349 if (r_type == R_ARM_THM_MOVT_ABS || r_type == R_ARM_THM_MOVT_PREL
7350 || r_type == R_ARM_THM_MOVT_BREL)
b6895b4f
PB
7351 value >>= 16;
7352
7353 insn &= 0xfbf08f00;
7354 insn |= (value & 0xf000) << 4;
7355 insn |= (value & 0x0800) << 15;
7356 insn |= (value & 0x0700) << 4;
7357 insn |= (value & 0x00ff);
7358
7359 bfd_put_16 (input_bfd, insn >> 16, hit_data);
7360 bfd_put_16 (input_bfd, insn & 0xffff, hit_data + 2);
7361 }
7362 return bfd_reloc_ok;
7363
4962c51a
MS
7364 case R_ARM_ALU_PC_G0_NC:
7365 case R_ARM_ALU_PC_G1_NC:
7366 case R_ARM_ALU_PC_G0:
7367 case R_ARM_ALU_PC_G1:
7368 case R_ARM_ALU_PC_G2:
7369 case R_ARM_ALU_SB_G0_NC:
7370 case R_ARM_ALU_SB_G1_NC:
7371 case R_ARM_ALU_SB_G0:
7372 case R_ARM_ALU_SB_G1:
7373 case R_ARM_ALU_SB_G2:
7374 {
7375 bfd_vma insn = bfd_get_32 (input_bfd, hit_data);
7376 bfd_vma pc = input_section->output_section->vma
7377 + input_section->output_offset + rel->r_offset;
7378 /* sb should be the origin of the *segment* containing the symbol.
7379 It is not clear how to obtain this OS-dependent value, so we
7380 make an arbitrary choice of zero. */
7381 bfd_vma sb = 0;
7382 bfd_vma residual;
7383 bfd_vma g_n;
7384 bfd_signed_vma signed_value;
7385 int group = 0;
7386
7387 /* Determine which group of bits to select. */
7388 switch (r_type)
7389 {
7390 case R_ARM_ALU_PC_G0_NC:
7391 case R_ARM_ALU_PC_G0:
7392 case R_ARM_ALU_SB_G0_NC:
7393 case R_ARM_ALU_SB_G0:
7394 group = 0;
7395 break;
7396
7397 case R_ARM_ALU_PC_G1_NC:
7398 case R_ARM_ALU_PC_G1:
7399 case R_ARM_ALU_SB_G1_NC:
7400 case R_ARM_ALU_SB_G1:
7401 group = 1;
7402 break;
7403
7404 case R_ARM_ALU_PC_G2:
7405 case R_ARM_ALU_SB_G2:
7406 group = 2;
7407 break;
7408
7409 default:
906e58ca 7410 abort ();
4962c51a
MS
7411 }
7412
7413 /* If REL, extract the addend from the insn. If RELA, it will
7414 have already been fetched for us. */
7415 if (globals->use_rel)
7416 {
7417 int negative;
7418 bfd_vma constant = insn & 0xff;
7419 bfd_vma rotation = (insn & 0xf00) >> 8;
7420
7421 if (rotation == 0)
7422 signed_addend = constant;
7423 else
7424 {
7425 /* Compensate for the fact that in the instruction, the
7426 rotation is stored in multiples of 2 bits. */
7427 rotation *= 2;
7428
7429 /* Rotate "constant" right by "rotation" bits. */
7430 signed_addend = (constant >> rotation) |
7431 (constant << (8 * sizeof (bfd_vma) - rotation));
7432 }
7433
7434 /* Determine if the instruction is an ADD or a SUB.
7435 (For REL, this determines the sign of the addend.) */
7436 negative = identify_add_or_sub (insn);
7437 if (negative == 0)
7438 {
7439 (*_bfd_error_handler)
7440 (_("%B(%A+0x%lx): Only ADD or SUB instructions are allowed for ALU group relocations"),
7441 input_bfd, input_section,
7442 (long) rel->r_offset, howto->name);
906e58ca 7443 return bfd_reloc_overflow;
4962c51a
MS
7444 }
7445
7446 signed_addend *= negative;
7447 }
7448
7449 /* Compute the value (X) to go in the place. */
7450 if (r_type == R_ARM_ALU_PC_G0_NC
7451 || r_type == R_ARM_ALU_PC_G1_NC
7452 || r_type == R_ARM_ALU_PC_G0
7453 || r_type == R_ARM_ALU_PC_G1
7454 || r_type == R_ARM_ALU_PC_G2)
7455 /* PC relative. */
7456 signed_value = value - pc + signed_addend;
7457 else
7458 /* Section base relative. */
7459 signed_value = value - sb + signed_addend;
7460
7461 /* If the target symbol is a Thumb function, then set the
7462 Thumb bit in the address. */
7463 if (sym_flags == STT_ARM_TFUNC)
7464 signed_value |= 1;
7465
7466 /* Calculate the value of the relevant G_n, in encoded
7467 constant-with-rotation format. */
7468 g_n = calculate_group_reloc_mask (abs (signed_value), group,
7469 &residual);
7470
7471 /* Check for overflow if required. */
7472 if ((r_type == R_ARM_ALU_PC_G0
7473 || r_type == R_ARM_ALU_PC_G1
7474 || r_type == R_ARM_ALU_PC_G2
7475 || r_type == R_ARM_ALU_SB_G0
7476 || r_type == R_ARM_ALU_SB_G1
7477 || r_type == R_ARM_ALU_SB_G2) && residual != 0)
7478 {
7479 (*_bfd_error_handler)
7480 (_("%B(%A+0x%lx): Overflow whilst splitting 0x%lx for group relocation %s"),
7481 input_bfd, input_section,
7482 (long) rel->r_offset, abs (signed_value), howto->name);
7483 return bfd_reloc_overflow;
7484 }
7485
7486 /* Mask out the value and the ADD/SUB part of the opcode; take care
7487 not to destroy the S bit. */
7488 insn &= 0xff1ff000;
7489
7490 /* Set the opcode according to whether the value to go in the
7491 place is negative. */
7492 if (signed_value < 0)
7493 insn |= 1 << 22;
7494 else
7495 insn |= 1 << 23;
7496
7497 /* Encode the offset. */
7498 insn |= g_n;
7499
7500 bfd_put_32 (input_bfd, insn, hit_data);
7501 }
7502 return bfd_reloc_ok;
7503
7504 case R_ARM_LDR_PC_G0:
7505 case R_ARM_LDR_PC_G1:
7506 case R_ARM_LDR_PC_G2:
7507 case R_ARM_LDR_SB_G0:
7508 case R_ARM_LDR_SB_G1:
7509 case R_ARM_LDR_SB_G2:
7510 {
7511 bfd_vma insn = bfd_get_32 (input_bfd, hit_data);
7512 bfd_vma pc = input_section->output_section->vma
7513 + input_section->output_offset + rel->r_offset;
7514 bfd_vma sb = 0; /* See note above. */
7515 bfd_vma residual;
7516 bfd_signed_vma signed_value;
7517 int group = 0;
7518
7519 /* Determine which groups of bits to calculate. */
7520 switch (r_type)
7521 {
7522 case R_ARM_LDR_PC_G0:
7523 case R_ARM_LDR_SB_G0:
7524 group = 0;
7525 break;
7526
7527 case R_ARM_LDR_PC_G1:
7528 case R_ARM_LDR_SB_G1:
7529 group = 1;
7530 break;
7531
7532 case R_ARM_LDR_PC_G2:
7533 case R_ARM_LDR_SB_G2:
7534 group = 2;
7535 break;
7536
7537 default:
906e58ca 7538 abort ();
4962c51a
MS
7539 }
7540
7541 /* If REL, extract the addend from the insn. If RELA, it will
7542 have already been fetched for us. */
7543 if (globals->use_rel)
7544 {
7545 int negative = (insn & (1 << 23)) ? 1 : -1;
7546 signed_addend = negative * (insn & 0xfff);
7547 }
7548
7549 /* Compute the value (X) to go in the place. */
7550 if (r_type == R_ARM_LDR_PC_G0
7551 || r_type == R_ARM_LDR_PC_G1
7552 || r_type == R_ARM_LDR_PC_G2)
7553 /* PC relative. */
7554 signed_value = value - pc + signed_addend;
7555 else
7556 /* Section base relative. */
7557 signed_value = value - sb + signed_addend;
7558
7559 /* Calculate the value of the relevant G_{n-1} to obtain
7560 the residual at that stage. */
7561 calculate_group_reloc_mask (abs (signed_value), group - 1, &residual);
7562
7563 /* Check for overflow. */
7564 if (residual >= 0x1000)
7565 {
7566 (*_bfd_error_handler)
7567 (_("%B(%A+0x%lx): Overflow whilst splitting 0x%lx for group relocation %s"),
7568 input_bfd, input_section,
7569 (long) rel->r_offset, abs (signed_value), howto->name);
7570 return bfd_reloc_overflow;
7571 }
7572
7573 /* Mask out the value and U bit. */
7574 insn &= 0xff7ff000;
7575
7576 /* Set the U bit if the value to go in the place is non-negative. */
7577 if (signed_value >= 0)
7578 insn |= 1 << 23;
7579
7580 /* Encode the offset. */
7581 insn |= residual;
7582
7583 bfd_put_32 (input_bfd, insn, hit_data);
7584 }
7585 return bfd_reloc_ok;
7586
7587 case R_ARM_LDRS_PC_G0:
7588 case R_ARM_LDRS_PC_G1:
7589 case R_ARM_LDRS_PC_G2:
7590 case R_ARM_LDRS_SB_G0:
7591 case R_ARM_LDRS_SB_G1:
7592 case R_ARM_LDRS_SB_G2:
7593 {
7594 bfd_vma insn = bfd_get_32 (input_bfd, hit_data);
7595 bfd_vma pc = input_section->output_section->vma
7596 + input_section->output_offset + rel->r_offset;
7597 bfd_vma sb = 0; /* See note above. */
7598 bfd_vma residual;
7599 bfd_signed_vma signed_value;
7600 int group = 0;
7601
7602 /* Determine which groups of bits to calculate. */
7603 switch (r_type)
7604 {
7605 case R_ARM_LDRS_PC_G0:
7606 case R_ARM_LDRS_SB_G0:
7607 group = 0;
7608 break;
7609
7610 case R_ARM_LDRS_PC_G1:
7611 case R_ARM_LDRS_SB_G1:
7612 group = 1;
7613 break;
7614
7615 case R_ARM_LDRS_PC_G2:
7616 case R_ARM_LDRS_SB_G2:
7617 group = 2;
7618 break;
7619
7620 default:
906e58ca 7621 abort ();
4962c51a
MS
7622 }
7623
7624 /* If REL, extract the addend from the insn. If RELA, it will
7625 have already been fetched for us. */
7626 if (globals->use_rel)
7627 {
7628 int negative = (insn & (1 << 23)) ? 1 : -1;
7629 signed_addend = negative * (((insn & 0xf00) >> 4) + (insn & 0xf));
7630 }
7631
7632 /* Compute the value (X) to go in the place. */
7633 if (r_type == R_ARM_LDRS_PC_G0
7634 || r_type == R_ARM_LDRS_PC_G1
7635 || r_type == R_ARM_LDRS_PC_G2)
7636 /* PC relative. */
7637 signed_value = value - pc + signed_addend;
7638 else
7639 /* Section base relative. */
7640 signed_value = value - sb + signed_addend;
7641
7642 /* Calculate the value of the relevant G_{n-1} to obtain
7643 the residual at that stage. */
7644 calculate_group_reloc_mask (abs (signed_value), group - 1, &residual);
7645
7646 /* Check for overflow. */
7647 if (residual >= 0x100)
7648 {
7649 (*_bfd_error_handler)
7650 (_("%B(%A+0x%lx): Overflow whilst splitting 0x%lx for group relocation %s"),
7651 input_bfd, input_section,
7652 (long) rel->r_offset, abs (signed_value), howto->name);
7653 return bfd_reloc_overflow;
7654 }
7655
7656 /* Mask out the value and U bit. */
7657 insn &= 0xff7ff0f0;
7658
7659 /* Set the U bit if the value to go in the place is non-negative. */
7660 if (signed_value >= 0)
7661 insn |= 1 << 23;
7662
7663 /* Encode the offset. */
7664 insn |= ((residual & 0xf0) << 4) | (residual & 0xf);
7665
7666 bfd_put_32 (input_bfd, insn, hit_data);
7667 }
7668 return bfd_reloc_ok;
7669
7670 case R_ARM_LDC_PC_G0:
7671 case R_ARM_LDC_PC_G1:
7672 case R_ARM_LDC_PC_G2:
7673 case R_ARM_LDC_SB_G0:
7674 case R_ARM_LDC_SB_G1:
7675 case R_ARM_LDC_SB_G2:
7676 {
7677 bfd_vma insn = bfd_get_32 (input_bfd, hit_data);
7678 bfd_vma pc = input_section->output_section->vma
7679 + input_section->output_offset + rel->r_offset;
7680 bfd_vma sb = 0; /* See note above. */
7681 bfd_vma residual;
7682 bfd_signed_vma signed_value;
7683 int group = 0;
7684
7685 /* Determine which groups of bits to calculate. */
7686 switch (r_type)
7687 {
7688 case R_ARM_LDC_PC_G0:
7689 case R_ARM_LDC_SB_G0:
7690 group = 0;
7691 break;
7692
7693 case R_ARM_LDC_PC_G1:
7694 case R_ARM_LDC_SB_G1:
7695 group = 1;
7696 break;
7697
7698 case R_ARM_LDC_PC_G2:
7699 case R_ARM_LDC_SB_G2:
7700 group = 2;
7701 break;
7702
7703 default:
906e58ca 7704 abort ();
4962c51a
MS
7705 }
7706
7707 /* If REL, extract the addend from the insn. If RELA, it will
7708 have already been fetched for us. */
7709 if (globals->use_rel)
7710 {
7711 int negative = (insn & (1 << 23)) ? 1 : -1;
7712 signed_addend = negative * ((insn & 0xff) << 2);
7713 }
7714
7715 /* Compute the value (X) to go in the place. */
7716 if (r_type == R_ARM_LDC_PC_G0
7717 || r_type == R_ARM_LDC_PC_G1
7718 || r_type == R_ARM_LDC_PC_G2)
7719 /* PC relative. */
7720 signed_value = value - pc + signed_addend;
7721 else
7722 /* Section base relative. */
7723 signed_value = value - sb + signed_addend;
7724
7725 /* Calculate the value of the relevant G_{n-1} to obtain
7726 the residual at that stage. */
7727 calculate_group_reloc_mask (abs (signed_value), group - 1, &residual);
7728
7729 /* Check for overflow. (The absolute value to go in the place must be
7730 divisible by four and, after having been divided by four, must
7731 fit in eight bits.) */
7732 if ((residual & 0x3) != 0 || residual >= 0x400)
7733 {
7734 (*_bfd_error_handler)
7735 (_("%B(%A+0x%lx): Overflow whilst splitting 0x%lx for group relocation %s"),
7736 input_bfd, input_section,
7737 (long) rel->r_offset, abs (signed_value), howto->name);
7738 return bfd_reloc_overflow;
7739 }
7740
7741 /* Mask out the value and U bit. */
7742 insn &= 0xff7fff00;
7743
7744 /* Set the U bit if the value to go in the place is non-negative. */
7745 if (signed_value >= 0)
7746 insn |= 1 << 23;
7747
7748 /* Encode the offset. */
7749 insn |= residual >> 2;
7750
7751 bfd_put_32 (input_bfd, insn, hit_data);
7752 }
7753 return bfd_reloc_ok;
7754
252b5132
RH
7755 default:
7756 return bfd_reloc_notsupported;
7757 }
7758}
7759
98c1d4aa
NC
7760/* Add INCREMENT to the reloc (of type HOWTO) at ADDRESS. */
7761static void
57e8b36a
NC
7762arm_add_to_rel (bfd * abfd,
7763 bfd_byte * address,
7764 reloc_howto_type * howto,
7765 bfd_signed_vma increment)
98c1d4aa 7766{
98c1d4aa
NC
7767 bfd_signed_vma addend;
7768
bd97cb95
DJ
7769 if (howto->type == R_ARM_THM_CALL
7770 || howto->type == R_ARM_THM_JUMP24)
98c1d4aa 7771 {
9a5aca8c
AM
7772 int upper_insn, lower_insn;
7773 int upper, lower;
98c1d4aa 7774
9a5aca8c
AM
7775 upper_insn = bfd_get_16 (abfd, address);
7776 lower_insn = bfd_get_16 (abfd, address + 2);
7777 upper = upper_insn & 0x7ff;
7778 lower = lower_insn & 0x7ff;
7779
7780 addend = (upper << 12) | (lower << 1);
ddda4409 7781 addend += increment;
9a5aca8c 7782 addend >>= 1;
98c1d4aa 7783
9a5aca8c
AM
7784 upper_insn = (upper_insn & 0xf800) | ((addend >> 11) & 0x7ff);
7785 lower_insn = (lower_insn & 0xf800) | (addend & 0x7ff);
7786
dc810e39
AM
7787 bfd_put_16 (abfd, (bfd_vma) upper_insn, address);
7788 bfd_put_16 (abfd, (bfd_vma) lower_insn, address + 2);
9a5aca8c
AM
7789 }
7790 else
7791 {
7792 bfd_vma contents;
7793
7794 contents = bfd_get_32 (abfd, address);
7795
7796 /* Get the (signed) value from the instruction. */
7797 addend = contents & howto->src_mask;
7798 if (addend & ((howto->src_mask + 1) >> 1))
7799 {
7800 bfd_signed_vma mask;
7801
7802 mask = -1;
7803 mask &= ~ howto->src_mask;
7804 addend |= mask;
7805 }
7806
7807 /* Add in the increment, (which is a byte value). */
7808 switch (howto->type)
7809 {
7810 default:
7811 addend += increment;
7812 break;
7813
7814 case R_ARM_PC24:
c6596c5e 7815 case R_ARM_PLT32:
5b5bb741
PB
7816 case R_ARM_CALL:
7817 case R_ARM_JUMP24:
9a5aca8c 7818 addend <<= howto->size;
dc810e39 7819 addend += increment;
9a5aca8c
AM
7820
7821 /* Should we check for overflow here ? */
7822
7823 /* Drop any undesired bits. */
7824 addend >>= howto->rightshift;
7825 break;
7826 }
7827
7828 contents = (contents & ~ howto->dst_mask) | (addend & howto->dst_mask);
7829
7830 bfd_put_32 (abfd, contents, address);
ddda4409 7831 }
98c1d4aa 7832}
252b5132 7833
ba93b8ac
DJ
7834#define IS_ARM_TLS_RELOC(R_TYPE) \
7835 ((R_TYPE) == R_ARM_TLS_GD32 \
7836 || (R_TYPE) == R_ARM_TLS_LDO32 \
7837 || (R_TYPE) == R_ARM_TLS_LDM32 \
7838 || (R_TYPE) == R_ARM_TLS_DTPOFF32 \
7839 || (R_TYPE) == R_ARM_TLS_DTPMOD32 \
7840 || (R_TYPE) == R_ARM_TLS_TPOFF32 \
7841 || (R_TYPE) == R_ARM_TLS_LE32 \
7842 || (R_TYPE) == R_ARM_TLS_IE32)
7843
252b5132 7844/* Relocate an ARM ELF section. */
906e58ca 7845
b34976b6 7846static bfd_boolean
57e8b36a
NC
7847elf32_arm_relocate_section (bfd * output_bfd,
7848 struct bfd_link_info * info,
7849 bfd * input_bfd,
7850 asection * input_section,
7851 bfd_byte * contents,
7852 Elf_Internal_Rela * relocs,
7853 Elf_Internal_Sym * local_syms,
7854 asection ** local_sections)
252b5132 7855{
b34976b6
AM
7856 Elf_Internal_Shdr *symtab_hdr;
7857 struct elf_link_hash_entry **sym_hashes;
7858 Elf_Internal_Rela *rel;
7859 Elf_Internal_Rela *relend;
7860 const char *name;
b32d3aa2 7861 struct elf32_arm_link_hash_table * globals;
252b5132 7862
4e7fd91e 7863 globals = elf32_arm_hash_table (info);
b491616a 7864
0ffa91dd 7865 symtab_hdr = & elf_symtab_hdr (input_bfd);
252b5132
RH
7866 sym_hashes = elf_sym_hashes (input_bfd);
7867
7868 rel = relocs;
7869 relend = relocs + input_section->reloc_count;
7870 for (; rel < relend; rel++)
7871 {
ba96a88f
NC
7872 int r_type;
7873 reloc_howto_type * howto;
7874 unsigned long r_symndx;
7875 Elf_Internal_Sym * sym;
7876 asection * sec;
252b5132 7877 struct elf_link_hash_entry * h;
ba96a88f
NC
7878 bfd_vma relocation;
7879 bfd_reloc_status_type r;
7880 arelent bfd_reloc;
ba93b8ac 7881 char sym_type;
0945cdfd 7882 bfd_boolean unresolved_reloc = FALSE;
f2a9dd69 7883 char *error_message = NULL;
f21f3fe0 7884
252b5132 7885 r_symndx = ELF32_R_SYM (rel->r_info);
ba96a88f 7886 r_type = ELF32_R_TYPE (rel->r_info);
b32d3aa2 7887 r_type = arm_real_reloc_type (globals, r_type);
252b5132 7888
ba96a88f
NC
7889 if ( r_type == R_ARM_GNU_VTENTRY
7890 || r_type == R_ARM_GNU_VTINHERIT)
252b5132
RH
7891 continue;
7892
b32d3aa2 7893 bfd_reloc.howto = elf32_arm_howto_from_type (r_type);
ba96a88f 7894 howto = bfd_reloc.howto;
252b5132 7895
252b5132
RH
7896 h = NULL;
7897 sym = NULL;
7898 sec = NULL;
9b485d32 7899
252b5132
RH
7900 if (r_symndx < symtab_hdr->sh_info)
7901 {
7902 sym = local_syms + r_symndx;
ba93b8ac 7903 sym_type = ELF32_ST_TYPE (sym->st_info);
252b5132 7904 sec = local_sections[r_symndx];
4e7fd91e 7905 if (globals->use_rel)
f8df10f4 7906 {
4e7fd91e
PB
7907 relocation = (sec->output_section->vma
7908 + sec->output_offset
7909 + sym->st_value);
ab96bf03
AM
7910 if (!info->relocatable
7911 && (sec->flags & SEC_MERGE)
7912 && ELF_ST_TYPE (sym->st_info) == STT_SECTION)
f8df10f4 7913 {
4e7fd91e
PB
7914 asection *msec;
7915 bfd_vma addend, value;
7916
39623e12 7917 switch (r_type)
4e7fd91e 7918 {
39623e12
PB
7919 case R_ARM_MOVW_ABS_NC:
7920 case R_ARM_MOVT_ABS:
7921 value = bfd_get_32 (input_bfd, contents + rel->r_offset);
7922 addend = ((value & 0xf0000) >> 4) | (value & 0xfff);
7923 addend = (addend ^ 0x8000) - 0x8000;
7924 break;
f8df10f4 7925
39623e12
PB
7926 case R_ARM_THM_MOVW_ABS_NC:
7927 case R_ARM_THM_MOVT_ABS:
7928 value = bfd_get_16 (input_bfd, contents + rel->r_offset)
7929 << 16;
7930 value |= bfd_get_16 (input_bfd,
7931 contents + rel->r_offset + 2);
7932 addend = ((value & 0xf7000) >> 4) | (value & 0xff)
7933 | ((value & 0x04000000) >> 15);
7934 addend = (addend ^ 0x8000) - 0x8000;
7935 break;
f8df10f4 7936
39623e12
PB
7937 default:
7938 if (howto->rightshift
7939 || (howto->src_mask & (howto->src_mask + 1)))
7940 {
7941 (*_bfd_error_handler)
7942 (_("%B(%A+0x%lx): %s relocation against SEC_MERGE section"),
7943 input_bfd, input_section,
7944 (long) rel->r_offset, howto->name);
7945 return FALSE;
7946 }
7947
7948 value = bfd_get_32 (input_bfd, contents + rel->r_offset);
7949
7950 /* Get the (signed) value from the instruction. */
7951 addend = value & howto->src_mask;
7952 if (addend & ((howto->src_mask + 1) >> 1))
7953 {
7954 bfd_signed_vma mask;
7955
7956 mask = -1;
7957 mask &= ~ howto->src_mask;
7958 addend |= mask;
7959 }
7960 break;
4e7fd91e 7961 }
39623e12 7962
4e7fd91e
PB
7963 msec = sec;
7964 addend =
7965 _bfd_elf_rel_local_sym (output_bfd, sym, &msec, addend)
7966 - relocation;
7967 addend += msec->output_section->vma + msec->output_offset;
39623e12
PB
7968
7969 /* Cases here must match those in the preceeding
7970 switch statement. */
7971 switch (r_type)
7972 {
7973 case R_ARM_MOVW_ABS_NC:
7974 case R_ARM_MOVT_ABS:
7975 value = (value & 0xfff0f000) | ((addend & 0xf000) << 4)
7976 | (addend & 0xfff);
7977 bfd_put_32 (input_bfd, value, contents + rel->r_offset);
7978 break;
7979
7980 case R_ARM_THM_MOVW_ABS_NC:
7981 case R_ARM_THM_MOVT_ABS:
7982 value = (value & 0xfbf08f00) | ((addend & 0xf700) << 4)
7983 | (addend & 0xff) | ((addend & 0x0800) << 15);
7984 bfd_put_16 (input_bfd, value >> 16,
7985 contents + rel->r_offset);
7986 bfd_put_16 (input_bfd, value,
7987 contents + rel->r_offset + 2);
7988 break;
7989
7990 default:
7991 value = (value & ~ howto->dst_mask)
7992 | (addend & howto->dst_mask);
7993 bfd_put_32 (input_bfd, value, contents + rel->r_offset);
7994 break;
7995 }
f8df10f4 7996 }
f8df10f4 7997 }
4e7fd91e
PB
7998 else
7999 relocation = _bfd_elf_rela_local_sym (output_bfd, sym, &sec, rel);
252b5132
RH
8000 }
8001 else
8002 {
560e09e9 8003 bfd_boolean warned;
560e09e9 8004
b2a8e766
AM
8005 RELOC_FOR_GLOBAL_SYMBOL (info, input_bfd, input_section, rel,
8006 r_symndx, symtab_hdr, sym_hashes,
8007 h, sec, relocation,
8008 unresolved_reloc, warned);
ba93b8ac
DJ
8009
8010 sym_type = h->type;
252b5132
RH
8011 }
8012
ab96bf03
AM
8013 if (sec != NULL && elf_discarded_section (sec))
8014 {
8015 /* For relocs against symbols from removed linkonce sections,
8016 or sections discarded by a linker script, we just want the
8017 section contents zeroed. Avoid any special processing. */
8018 _bfd_clear_contents (howto, input_bfd, contents + rel->r_offset);
8019 rel->r_info = 0;
8020 rel->r_addend = 0;
8021 continue;
8022 }
8023
8024 if (info->relocatable)
8025 {
8026 /* This is a relocatable link. We don't have to change
8027 anything, unless the reloc is against a section symbol,
8028 in which case we have to adjust according to where the
8029 section symbol winds up in the output section. */
8030 if (sym != NULL && ELF_ST_TYPE (sym->st_info) == STT_SECTION)
8031 {
8032 if (globals->use_rel)
8033 arm_add_to_rel (input_bfd, contents + rel->r_offset,
8034 howto, (bfd_signed_vma) sec->output_offset);
8035 else
8036 rel->r_addend += sec->output_offset;
8037 }
8038 continue;
8039 }
8040
252b5132
RH
8041 if (h != NULL)
8042 name = h->root.root.string;
8043 else
8044 {
8045 name = (bfd_elf_string_from_elf_section
8046 (input_bfd, symtab_hdr->sh_link, sym->st_name));
8047 if (name == NULL || *name == '\0')
8048 name = bfd_section_name (input_bfd, sec);
8049 }
f21f3fe0 8050
ba93b8ac
DJ
8051 if (r_symndx != 0
8052 && r_type != R_ARM_NONE
8053 && (h == NULL
8054 || h->root.type == bfd_link_hash_defined
8055 || h->root.type == bfd_link_hash_defweak)
8056 && IS_ARM_TLS_RELOC (r_type) != (sym_type == STT_TLS))
8057 {
8058 (*_bfd_error_handler)
8059 ((sym_type == STT_TLS
8060 ? _("%B(%A+0x%lx): %s used with TLS symbol %s")
8061 : _("%B(%A+0x%lx): %s used with non-TLS symbol %s")),
8062 input_bfd,
8063 input_section,
8064 (long) rel->r_offset,
8065 howto->name,
8066 name);
8067 }
8068
252b5132
RH
8069 r = elf32_arm_final_link_relocate (howto, input_bfd, output_bfd,
8070 input_section, contents, rel,
8071 relocation, info, sec, name,
8072 (h ? ELF_ST_TYPE (h->type) :
0945cdfd 8073 ELF_ST_TYPE (sym->st_info)), h,
f2a9dd69 8074 &unresolved_reloc, &error_message);
0945cdfd
DJ
8075
8076 /* Dynamic relocs are not propagated for SEC_DEBUGGING sections
8077 because such sections are not SEC_ALLOC and thus ld.so will
8078 not process them. */
8079 if (unresolved_reloc
8080 && !((input_section->flags & SEC_DEBUGGING) != 0
8081 && h->def_dynamic))
8082 {
8083 (*_bfd_error_handler)
843fe662
L
8084 (_("%B(%A+0x%lx): unresolvable %s relocation against symbol `%s'"),
8085 input_bfd,
8086 input_section,
8087 (long) rel->r_offset,
8088 howto->name,
8089 h->root.root.string);
0945cdfd
DJ
8090 return FALSE;
8091 }
252b5132
RH
8092
8093 if (r != bfd_reloc_ok)
8094 {
252b5132
RH
8095 switch (r)
8096 {
8097 case bfd_reloc_overflow:
cf919dfd
PB
8098 /* If the overflowing reloc was to an undefined symbol,
8099 we have already printed one error message and there
8100 is no point complaining again. */
8101 if ((! h ||
8102 h->root.type != bfd_link_hash_undefined)
8103 && (!((*info->callbacks->reloc_overflow)
dfeffb9f
L
8104 (info, (h ? &h->root : NULL), name, howto->name,
8105 (bfd_vma) 0, input_bfd, input_section,
8106 rel->r_offset))))
b34976b6 8107 return FALSE;
252b5132
RH
8108 break;
8109
8110 case bfd_reloc_undefined:
8111 if (!((*info->callbacks->undefined_symbol)
8112 (info, name, input_bfd, input_section,
b34976b6
AM
8113 rel->r_offset, TRUE)))
8114 return FALSE;
252b5132
RH
8115 break;
8116
8117 case bfd_reloc_outofrange:
f2a9dd69 8118 error_message = _("out of range");
252b5132
RH
8119 goto common_error;
8120
8121 case bfd_reloc_notsupported:
f2a9dd69 8122 error_message = _("unsupported relocation");
252b5132
RH
8123 goto common_error;
8124
8125 case bfd_reloc_dangerous:
f2a9dd69 8126 /* error_message should already be set. */
252b5132
RH
8127 goto common_error;
8128
8129 default:
f2a9dd69 8130 error_message = _("unknown error");
8029a119 8131 /* Fall through. */
252b5132
RH
8132
8133 common_error:
f2a9dd69
DJ
8134 BFD_ASSERT (error_message != NULL);
8135 if (!((*info->callbacks->reloc_dangerous)
8136 (info, error_message, input_bfd, input_section,
252b5132 8137 rel->r_offset)))
b34976b6 8138 return FALSE;
252b5132
RH
8139 break;
8140 }
8141 }
8142 }
8143
b34976b6 8144 return TRUE;
252b5132
RH
8145}
8146
c178919b
NC
8147/* Set the right machine number. */
8148
8149static bfd_boolean
57e8b36a 8150elf32_arm_object_p (bfd *abfd)
c178919b 8151{
5a6c6817 8152 unsigned int mach;
57e8b36a 8153
5a6c6817 8154 mach = bfd_arm_get_mach_from_notes (abfd, ARM_NOTE_SECTION);
c178919b 8155
5a6c6817
NC
8156 if (mach != bfd_mach_arm_unknown)
8157 bfd_default_set_arch_mach (abfd, bfd_arch_arm, mach);
8158
8159 else if (elf_elfheader (abfd)->e_flags & EF_ARM_MAVERICK_FLOAT)
8160 bfd_default_set_arch_mach (abfd, bfd_arch_arm, bfd_mach_arm_ep9312);
e16bb312 8161
e16bb312 8162 else
5a6c6817 8163 bfd_default_set_arch_mach (abfd, bfd_arch_arm, mach);
c178919b
NC
8164
8165 return TRUE;
8166}
8167
fc830a83 8168/* Function to keep ARM specific flags in the ELF header. */
3c9458e9 8169
b34976b6 8170static bfd_boolean
57e8b36a 8171elf32_arm_set_private_flags (bfd *abfd, flagword flags)
252b5132
RH
8172{
8173 if (elf_flags_init (abfd)
8174 && elf_elfheader (abfd)->e_flags != flags)
8175 {
fc830a83
NC
8176 if (EF_ARM_EABI_VERSION (flags) == EF_ARM_EABI_UNKNOWN)
8177 {
fd2ec330 8178 if (flags & EF_ARM_INTERWORK)
d003868e
AM
8179 (*_bfd_error_handler)
8180 (_("Warning: Not setting interworking flag of %B since it has already been specified as non-interworking"),
8181 abfd);
fc830a83 8182 else
d003868e
AM
8183 _bfd_error_handler
8184 (_("Warning: Clearing the interworking flag of %B due to outside request"),
8185 abfd);
fc830a83 8186 }
252b5132
RH
8187 }
8188 else
8189 {
8190 elf_elfheader (abfd)->e_flags = flags;
b34976b6 8191 elf_flags_init (abfd) = TRUE;
252b5132
RH
8192 }
8193
b34976b6 8194 return TRUE;
252b5132
RH
8195}
8196
fc830a83 8197/* Copy backend specific data from one object module to another. */
9b485d32 8198
b34976b6 8199static bfd_boolean
57e8b36a 8200elf32_arm_copy_private_bfd_data (bfd *ibfd, bfd *obfd)
252b5132
RH
8201{
8202 flagword in_flags;
8203 flagword out_flags;
8204
0ffa91dd 8205 if (! is_arm_elf (ibfd) || ! is_arm_elf (obfd))
b34976b6 8206 return TRUE;
252b5132 8207
fc830a83 8208 in_flags = elf_elfheader (ibfd)->e_flags;
252b5132
RH
8209 out_flags = elf_elfheader (obfd)->e_flags;
8210
fc830a83
NC
8211 if (elf_flags_init (obfd)
8212 && EF_ARM_EABI_VERSION (out_flags) == EF_ARM_EABI_UNKNOWN
8213 && in_flags != out_flags)
252b5132 8214 {
252b5132 8215 /* Cannot mix APCS26 and APCS32 code. */
fd2ec330 8216 if ((in_flags & EF_ARM_APCS_26) != (out_flags & EF_ARM_APCS_26))
b34976b6 8217 return FALSE;
252b5132
RH
8218
8219 /* Cannot mix float APCS and non-float APCS code. */
fd2ec330 8220 if ((in_flags & EF_ARM_APCS_FLOAT) != (out_flags & EF_ARM_APCS_FLOAT))
b34976b6 8221 return FALSE;
252b5132
RH
8222
8223 /* If the src and dest have different interworking flags
8224 then turn off the interworking bit. */
fd2ec330 8225 if ((in_flags & EF_ARM_INTERWORK) != (out_flags & EF_ARM_INTERWORK))
252b5132 8226 {
fd2ec330 8227 if (out_flags & EF_ARM_INTERWORK)
d003868e
AM
8228 _bfd_error_handler
8229 (_("Warning: Clearing the interworking flag of %B because non-interworking code in %B has been linked with it"),
8230 obfd, ibfd);
252b5132 8231
fd2ec330 8232 in_flags &= ~EF_ARM_INTERWORK;
252b5132 8233 }
1006ba19
PB
8234
8235 /* Likewise for PIC, though don't warn for this case. */
fd2ec330
PB
8236 if ((in_flags & EF_ARM_PIC) != (out_flags & EF_ARM_PIC))
8237 in_flags &= ~EF_ARM_PIC;
252b5132
RH
8238 }
8239
8240 elf_elfheader (obfd)->e_flags = in_flags;
b34976b6 8241 elf_flags_init (obfd) = TRUE;
252b5132 8242
94a3258f
PB
8243 /* Also copy the EI_OSABI field. */
8244 elf_elfheader (obfd)->e_ident[EI_OSABI] =
8245 elf_elfheader (ibfd)->e_ident[EI_OSABI];
8246
104d59d1
JM
8247 /* Copy object attributes. */
8248 _bfd_elf_copy_obj_attributes (ibfd, obfd);
ee065d83
PB
8249
8250 return TRUE;
8251}
8252
8253/* Values for Tag_ABI_PCS_R9_use. */
8254enum
8255{
8256 AEABI_R9_V6,
8257 AEABI_R9_SB,
8258 AEABI_R9_TLS,
8259 AEABI_R9_unused
8260};
8261
8262/* Values for Tag_ABI_PCS_RW_data. */
8263enum
8264{
8265 AEABI_PCS_RW_data_absolute,
8266 AEABI_PCS_RW_data_PCrel,
8267 AEABI_PCS_RW_data_SBrel,
8268 AEABI_PCS_RW_data_unused
8269};
8270
8271/* Values for Tag_ABI_enum_size. */
8272enum
8273{
8274 AEABI_enum_unused,
8275 AEABI_enum_short,
8276 AEABI_enum_wide,
8277 AEABI_enum_forced_wide
8278};
8279
104d59d1
JM
8280/* Determine whether an object attribute tag takes an integer, a
8281 string or both. */
906e58ca 8282
104d59d1
JM
8283static int
8284elf32_arm_obj_attrs_arg_type (int tag)
8285{
8286 if (tag == Tag_compatibility)
3483fe2e 8287 return ATTR_TYPE_FLAG_INT_VAL | ATTR_TYPE_FLAG_STR_VAL;
2d0bb761 8288 else if (tag == Tag_nodefaults)
3483fe2e
AS
8289 return ATTR_TYPE_FLAG_INT_VAL | ATTR_TYPE_FLAG_NO_DEFAULT;
8290 else if (tag == Tag_CPU_raw_name || tag == Tag_CPU_name)
8291 return ATTR_TYPE_FLAG_STR_VAL;
104d59d1 8292 else if (tag < 32)
3483fe2e 8293 return ATTR_TYPE_FLAG_INT_VAL;
104d59d1 8294 else
3483fe2e 8295 return (tag & 1) != 0 ? ATTR_TYPE_FLAG_STR_VAL : ATTR_TYPE_FLAG_INT_VAL;
104d59d1
JM
8296}
8297
5aa6ff7c
AS
8298/* The ABI defines that Tag_conformance should be emitted first, and that
8299 Tag_nodefaults should be second (if either is defined). This sets those
8300 two positions, and bumps up the position of all the remaining tags to
8301 compensate. */
8302static int
8303elf32_arm_obj_attrs_order (int num)
8304{
8305 if (num == 4)
8306 return Tag_conformance;
8307 if (num == 5)
8308 return Tag_nodefaults;
8309 if ((num - 2) < Tag_nodefaults)
8310 return num - 2;
8311 if ((num - 1) < Tag_conformance)
8312 return num - 1;
8313 return num;
8314}
8315
91e22acd
AS
8316/* Read the architecture from the Tag_also_compatible_with attribute, if any.
8317 Returns -1 if no architecture could be read. */
8318
8319static int
8320get_secondary_compatible_arch (bfd *abfd)
8321{
8322 obj_attribute *attr =
8323 &elf_known_obj_attributes_proc (abfd)[Tag_also_compatible_with];
8324
8325 /* Note: the tag and its argument below are uleb128 values, though
8326 currently-defined values fit in one byte for each. */
8327 if (attr->s
8328 && attr->s[0] == Tag_CPU_arch
8329 && (attr->s[1] & 128) != 128
8330 && attr->s[2] == 0)
8331 return attr->s[1];
8332
8333 /* This tag is "safely ignorable", so don't complain if it looks funny. */
8334 return -1;
8335}
8336
8337/* Set, or unset, the architecture of the Tag_also_compatible_with attribute.
8338 The tag is removed if ARCH is -1. */
8339
8e79c3df 8340static void
91e22acd 8341set_secondary_compatible_arch (bfd *abfd, int arch)
8e79c3df 8342{
91e22acd
AS
8343 obj_attribute *attr =
8344 &elf_known_obj_attributes_proc (abfd)[Tag_also_compatible_with];
8e79c3df 8345
91e22acd
AS
8346 if (arch == -1)
8347 {
8348 attr->s = NULL;
8349 return;
8e79c3df 8350 }
91e22acd
AS
8351
8352 /* Note: the tag and its argument below are uleb128 values, though
8353 currently-defined values fit in one byte for each. */
8354 if (!attr->s)
8355 attr->s = bfd_alloc (abfd, 3);
8356 attr->s[0] = Tag_CPU_arch;
8357 attr->s[1] = arch;
8358 attr->s[2] = '\0';
8e79c3df
CM
8359}
8360
91e22acd
AS
8361/* Combine two values for Tag_CPU_arch, taking secondary compatibility tags
8362 into account. */
8363
8364static int
8365tag_cpu_arch_combine (bfd *ibfd, int oldtag, int *secondary_compat_out,
8366 int newtag, int secondary_compat)
8e79c3df 8367{
91e22acd
AS
8368#define T(X) TAG_CPU_ARCH_##X
8369 int tagl, tagh, result;
8370 const int v6t2[] =
8371 {
8372 T(V6T2), /* PRE_V4. */
8373 T(V6T2), /* V4. */
8374 T(V6T2), /* V4T. */
8375 T(V6T2), /* V5T. */
8376 T(V6T2), /* V5TE. */
8377 T(V6T2), /* V5TEJ. */
8378 T(V6T2), /* V6. */
8379 T(V7), /* V6KZ. */
8380 T(V6T2) /* V6T2. */
8381 };
8382 const int v6k[] =
8383 {
8384 T(V6K), /* PRE_V4. */
8385 T(V6K), /* V4. */
8386 T(V6K), /* V4T. */
8387 T(V6K), /* V5T. */
8388 T(V6K), /* V5TE. */
8389 T(V6K), /* V5TEJ. */
8390 T(V6K), /* V6. */
8391 T(V6KZ), /* V6KZ. */
8392 T(V7), /* V6T2. */
8393 T(V6K) /* V6K. */
8394 };
8395 const int v7[] =
8396 {
8397 T(V7), /* PRE_V4. */
8398 T(V7), /* V4. */
8399 T(V7), /* V4T. */
8400 T(V7), /* V5T. */
8401 T(V7), /* V5TE. */
8402 T(V7), /* V5TEJ. */
8403 T(V7), /* V6. */
8404 T(V7), /* V6KZ. */
8405 T(V7), /* V6T2. */
8406 T(V7), /* V6K. */
8407 T(V7) /* V7. */
8408 };
8409 const int v6_m[] =
8410 {
8411 -1, /* PRE_V4. */
8412 -1, /* V4. */
8413 T(V6K), /* V4T. */
8414 T(V6K), /* V5T. */
8415 T(V6K), /* V5TE. */
8416 T(V6K), /* V5TEJ. */
8417 T(V6K), /* V6. */
8418 T(V6KZ), /* V6KZ. */
8419 T(V7), /* V6T2. */
8420 T(V6K), /* V6K. */
8421 T(V7), /* V7. */
8422 T(V6_M) /* V6_M. */
8423 };
8424 const int v6s_m[] =
8425 {
8426 -1, /* PRE_V4. */
8427 -1, /* V4. */
8428 T(V6K), /* V4T. */
8429 T(V6K), /* V5T. */
8430 T(V6K), /* V5TE. */
8431 T(V6K), /* V5TEJ. */
8432 T(V6K), /* V6. */
8433 T(V6KZ), /* V6KZ. */
8434 T(V7), /* V6T2. */
8435 T(V6K), /* V6K. */
8436 T(V7), /* V7. */
8437 T(V6S_M), /* V6_M. */
8438 T(V6S_M) /* V6S_M. */
8439 };
8440 const int v4t_plus_v6_m[] =
8441 {
8442 -1, /* PRE_V4. */
8443 -1, /* V4. */
8444 T(V4T), /* V4T. */
8445 T(V5T), /* V5T. */
8446 T(V5TE), /* V5TE. */
8447 T(V5TEJ), /* V5TEJ. */
8448 T(V6), /* V6. */
8449 T(V6KZ), /* V6KZ. */
8450 T(V6T2), /* V6T2. */
8451 T(V6K), /* V6K. */
8452 T(V7), /* V7. */
8453 T(V6_M), /* V6_M. */
8454 T(V6S_M), /* V6S_M. */
8455 T(V4T_PLUS_V6_M) /* V4T plus V6_M. */
8456 };
8457 const int *comb[] =
8458 {
8459 v6t2,
8460 v6k,
8461 v7,
8462 v6_m,
8463 v6s_m,
8464 /* Pseudo-architecture. */
8465 v4t_plus_v6_m
8466 };
8467
8468 /* Check we've not got a higher architecture than we know about. */
8469
8470 if (oldtag >= MAX_TAG_CPU_ARCH || newtag >= MAX_TAG_CPU_ARCH)
8471 {
8472 _bfd_error_handler (_("ERROR: %B: Unknown CPU architecture"), ibfd);
8473 return -1;
8474 }
8475
8476 /* Override old tag if we have a Tag_also_compatible_with on the output. */
8477
8478 if ((oldtag == T(V6_M) && *secondary_compat_out == T(V4T))
8479 || (oldtag == T(V4T) && *secondary_compat_out == T(V6_M)))
8480 oldtag = T(V4T_PLUS_V6_M);
8481
8482 /* And override the new tag if we have a Tag_also_compatible_with on the
8483 input. */
8484
8485 if ((newtag == T(V6_M) && secondary_compat == T(V4T))
8486 || (newtag == T(V4T) && secondary_compat == T(V6_M)))
8487 newtag = T(V4T_PLUS_V6_M);
8488
8489 tagl = (oldtag < newtag) ? oldtag : newtag;
8490 result = tagh = (oldtag > newtag) ? oldtag : newtag;
8491
8492 /* Architectures before V6KZ add features monotonically. */
8493 if (tagh <= TAG_CPU_ARCH_V6KZ)
8494 return result;
8495
8496 result = comb[tagh - T(V6T2)][tagl];
8497
8498 /* Use Tag_CPU_arch == V4T and Tag_also_compatible_with (Tag_CPU_arch V6_M)
8499 as the canonical version. */
8500 if (result == T(V4T_PLUS_V6_M))
8501 {
8502 result = T(V4T);
8503 *secondary_compat_out = T(V6_M);
8504 }
8505 else
8506 *secondary_compat_out = -1;
8507
8508 if (result == -1)
8509 {
8510 _bfd_error_handler (_("ERROR: %B: Conflicting CPU architectures %d/%d"),
8511 ibfd, oldtag, newtag);
8512 return -1;
8513 }
8514
8515 return result;
8516#undef T
8e79c3df
CM
8517}
8518
ee065d83
PB
8519/* Merge EABI object attributes from IBFD into OBFD. Raise an error if there
8520 are conflicting attributes. */
906e58ca 8521
ee065d83
PB
8522static bfd_boolean
8523elf32_arm_merge_eabi_attributes (bfd *ibfd, bfd *obfd)
8524{
104d59d1
JM
8525 obj_attribute *in_attr;
8526 obj_attribute *out_attr;
8527 obj_attribute_list *in_list;
8e79c3df 8528 obj_attribute_list *out_list;
91e22acd 8529 obj_attribute_list **out_listp;
ee065d83
PB
8530 /* Some tags have 0 = don't care, 1 = strong requirement,
8531 2 = weak requirement. */
91e22acd 8532 static const int order_021[3] = {0, 2, 1};
b1cc4aeb
PB
8533 /* For use with Tag_VFP_arch. */
8534 static const int order_01243[5] = {0, 1, 2, 4, 3};
ee065d83 8535 int i;
91e22acd 8536 bfd_boolean result = TRUE;
ee065d83 8537
104d59d1 8538 if (!elf_known_obj_attributes_proc (obfd)[0].i)
ee065d83
PB
8539 {
8540 /* This is the first object. Copy the attributes. */
104d59d1 8541 _bfd_elf_copy_obj_attributes (ibfd, obfd);
004ae526
PB
8542
8543 /* Use the Tag_null value to indicate the attributes have been
8544 initialized. */
104d59d1 8545 elf_known_obj_attributes_proc (obfd)[0].i = 1;
004ae526 8546
ee065d83
PB
8547 return TRUE;
8548 }
8549
104d59d1
JM
8550 in_attr = elf_known_obj_attributes_proc (ibfd);
8551 out_attr = elf_known_obj_attributes_proc (obfd);
ee065d83
PB
8552 /* This needs to happen before Tag_ABI_FP_number_model is merged. */
8553 if (in_attr[Tag_ABI_VFP_args].i != out_attr[Tag_ABI_VFP_args].i)
8554 {
8e79c3df 8555 /* Ignore mismatches if the object doesn't use floating point. */
ee065d83
PB
8556 if (out_attr[Tag_ABI_FP_number_model].i == 0)
8557 out_attr[Tag_ABI_VFP_args].i = in_attr[Tag_ABI_VFP_args].i;
8558 else if (in_attr[Tag_ABI_FP_number_model].i != 0)
8559 {
8560 _bfd_error_handler
8561 (_("ERROR: %B uses VFP register arguments, %B does not"),
8562 ibfd, obfd);
91e22acd 8563 result = FALSE;
ee065d83
PB
8564 }
8565 }
8566
104d59d1 8567 for (i = 4; i < NUM_KNOWN_OBJ_ATTRIBUTES; i++)
ee065d83
PB
8568 {
8569 /* Merge this attribute with existing attributes. */
8570 switch (i)
8571 {
8572 case Tag_CPU_raw_name:
8573 case Tag_CPU_name:
91e22acd 8574 /* These are merged after Tag_CPU_arch. */
ee065d83
PB
8575 break;
8576
8577 case Tag_ABI_optimization_goals:
8578 case Tag_ABI_FP_optimization_goals:
8579 /* Use the first value seen. */
8580 break;
8581
8582 case Tag_CPU_arch:
91e22acd
AS
8583 {
8584 int secondary_compat = -1, secondary_compat_out = -1;
8585 unsigned int saved_out_attr = out_attr[i].i;
8586 static const char *name_table[] = {
8587 /* These aren't real CPU names, but we can't guess
8588 that from the architecture version alone. */
8589 "Pre v4",
8590 "ARM v4",
8591 "ARM v4T",
8592 "ARM v5T",
8593 "ARM v5TE",
8594 "ARM v5TEJ",
8595 "ARM v6",
8596 "ARM v6KZ",
8597 "ARM v6T2",
8598 "ARM v6K",
8599 "ARM v7",
8600 "ARM v6-M",
8601 "ARM v6S-M"
8602 };
8603
8604 /* Merge Tag_CPU_arch and Tag_also_compatible_with. */
8605 secondary_compat = get_secondary_compatible_arch (ibfd);
8606 secondary_compat_out = get_secondary_compatible_arch (obfd);
8607 out_attr[i].i = tag_cpu_arch_combine (ibfd, out_attr[i].i,
8608 &secondary_compat_out,
8609 in_attr[i].i,
8610 secondary_compat);
8611 set_secondary_compatible_arch (obfd, secondary_compat_out);
8612
8613 /* Merge Tag_CPU_name and Tag_CPU_raw_name. */
8614 if (out_attr[i].i == saved_out_attr)
8615 ; /* Leave the names alone. */
8616 else if (out_attr[i].i == in_attr[i].i)
8617 {
8618 /* The output architecture has been changed to match the
8619 input architecture. Use the input names. */
8620 out_attr[Tag_CPU_name].s = in_attr[Tag_CPU_name].s
8621 ? _bfd_elf_attr_strdup (obfd, in_attr[Tag_CPU_name].s)
8622 : NULL;
8623 out_attr[Tag_CPU_raw_name].s = in_attr[Tag_CPU_raw_name].s
8624 ? _bfd_elf_attr_strdup (obfd, in_attr[Tag_CPU_raw_name].s)
8625 : NULL;
8626 }
8627 else
8628 {
8629 out_attr[Tag_CPU_name].s = NULL;
8630 out_attr[Tag_CPU_raw_name].s = NULL;
8631 }
8632
8633 /* If we still don't have a value for Tag_CPU_name,
8634 make one up now. Tag_CPU_raw_name remains blank. */
8635 if (out_attr[Tag_CPU_name].s == NULL
8636 && out_attr[i].i < ARRAY_SIZE (name_table))
8637 out_attr[Tag_CPU_name].s =
8638 _bfd_elf_attr_strdup (obfd, name_table[out_attr[i].i]);
8639 }
8640 break;
8641
ee065d83
PB
8642 case Tag_ARM_ISA_use:
8643 case Tag_THUMB_ISA_use:
ee065d83 8644 case Tag_WMMX_arch:
91e22acd
AS
8645 case Tag_Advanced_SIMD_arch:
8646 /* ??? Do Advanced_SIMD (NEON) and WMMX conflict? */
ee065d83 8647 case Tag_ABI_FP_rounding:
ee065d83
PB
8648 case Tag_ABI_FP_exceptions:
8649 case Tag_ABI_FP_user_exceptions:
8650 case Tag_ABI_FP_number_model:
91e22acd
AS
8651 case Tag_VFP_HP_extension:
8652 case Tag_CPU_unaligned_access:
8653 case Tag_T2EE_use:
8654 case Tag_Virtualization_use:
8655 case Tag_MPextension_use:
ee065d83
PB
8656 /* Use the largest value specified. */
8657 if (in_attr[i].i > out_attr[i].i)
8658 out_attr[i].i = in_attr[i].i;
8659 break;
8660
91e22acd
AS
8661 case Tag_ABI_align8_preserved:
8662 case Tag_ABI_PCS_RO_data:
8663 /* Use the smallest value specified. */
8664 if (in_attr[i].i < out_attr[i].i)
8665 out_attr[i].i = in_attr[i].i;
8666 break;
8667
8668 case Tag_ABI_align8_needed:
8669 if ((in_attr[i].i > 0 || out_attr[i].i > 0)
8670 && (in_attr[Tag_ABI_align8_preserved].i == 0
8671 || out_attr[Tag_ABI_align8_preserved].i == 0))
ee065d83 8672 {
91e22acd
AS
8673 /* This error message should be enabled once all non-conformant
8674 binaries in the toolchain have had the attributes set
8675 properly.
ee065d83 8676 _bfd_error_handler
91e22acd
AS
8677 (_("ERROR: %B: 8-byte data alignment conflicts with %B"),
8678 obfd, ibfd);
8679 result = FALSE; */
ee065d83 8680 }
91e22acd
AS
8681 /* Fall through. */
8682 case Tag_ABI_FP_denormal:
8683 case Tag_ABI_PCS_GOT_use:
8684 /* Use the "greatest" from the sequence 0, 2, 1, or the largest
8685 value if greater than 2 (for future-proofing). */
8686 if ((in_attr[i].i > 2 && in_attr[i].i > out_attr[i].i)
8687 || (in_attr[i].i <= 2 && out_attr[i].i <= 2
8688 && order_021[in_attr[i].i] > order_021[out_attr[i].i]))
ee065d83
PB
8689 out_attr[i].i = in_attr[i].i;
8690 break;
91e22acd
AS
8691
8692
8693 case Tag_CPU_arch_profile:
8694 if (out_attr[i].i != in_attr[i].i)
8695 {
8696 /* 0 will merge with anything.
8697 'A' and 'S' merge to 'A'.
8698 'R' and 'S' merge to 'R'.
8699 'M' and 'A|R|S' is an error. */
8700 if (out_attr[i].i == 0
8701 || (out_attr[i].i == 'S'
8702 && (in_attr[i].i == 'A' || in_attr[i].i == 'R')))
8703 out_attr[i].i = in_attr[i].i;
8704 else if (in_attr[i].i == 0
8705 || (in_attr[i].i == 'S'
8706 && (out_attr[i].i == 'A' || out_attr[i].i == 'R')))
8707 ; /* Do nothing. */
8708 else
8709 {
8710 _bfd_error_handler
8711 (_("ERROR: %B: Conflicting architecture profiles %c/%c"),
8712 ibfd,
8713 in_attr[i].i ? in_attr[i].i : '0',
8714 out_attr[i].i ? out_attr[i].i : '0');
8715 result = FALSE;
8716 }
8717 }
8718 break;
b1cc4aeb 8719 case Tag_VFP_arch:
91e22acd
AS
8720 /* Use the "greatest" from the sequence 0, 1, 2, 4, 3, or the
8721 largest value if greater than 4 (for future-proofing). */
8722 if ((in_attr[i].i > 4 && in_attr[i].i > out_attr[i].i)
8723 || (in_attr[i].i <= 4 && out_attr[i].i <= 4
8724 && order_01243[in_attr[i].i] > order_01243[out_attr[i].i]))
b1cc4aeb
PB
8725 out_attr[i].i = in_attr[i].i;
8726 break;
ee065d83
PB
8727 case Tag_PCS_config:
8728 if (out_attr[i].i == 0)
8729 out_attr[i].i = in_attr[i].i;
8730 else if (in_attr[i].i != 0 && out_attr[i].i != 0)
8731 {
8732 /* It's sometimes ok to mix different configs, so this is only
8733 a warning. */
8734 _bfd_error_handler
8735 (_("Warning: %B: Conflicting platform configuration"), ibfd);
8736 }
8737 break;
8738 case Tag_ABI_PCS_R9_use:
004ae526
PB
8739 if (in_attr[i].i != out_attr[i].i
8740 && out_attr[i].i != AEABI_R9_unused
ee065d83
PB
8741 && in_attr[i].i != AEABI_R9_unused)
8742 {
8743 _bfd_error_handler
8744 (_("ERROR: %B: Conflicting use of R9"), ibfd);
91e22acd 8745 result = FALSE;
ee065d83
PB
8746 }
8747 if (out_attr[i].i == AEABI_R9_unused)
8748 out_attr[i].i = in_attr[i].i;
8749 break;
8750 case Tag_ABI_PCS_RW_data:
8751 if (in_attr[i].i == AEABI_PCS_RW_data_SBrel
8752 && out_attr[Tag_ABI_PCS_R9_use].i != AEABI_R9_SB
8753 && out_attr[Tag_ABI_PCS_R9_use].i != AEABI_R9_unused)
8754 {
8755 _bfd_error_handler
8756 (_("ERROR: %B: SB relative addressing conflicts with use of R9"),
8757 ibfd);
91e22acd 8758 result = FALSE;
ee065d83
PB
8759 }
8760 /* Use the smallest value specified. */
8761 if (in_attr[i].i < out_attr[i].i)
8762 out_attr[i].i = in_attr[i].i;
8763 break;
ee065d83 8764 case Tag_ABI_PCS_wchar_t:
a9dc9481
JM
8765 if (out_attr[i].i && in_attr[i].i && out_attr[i].i != in_attr[i].i
8766 && !elf_arm_tdata (obfd)->no_wchar_size_warning)
ee065d83
PB
8767 {
8768 _bfd_error_handler
a9dc9481
JM
8769 (_("warning: %B uses %u-byte wchar_t yet the output is to use %u-byte wchar_t; use of wchar_t values across objects may fail"),
8770 ibfd, in_attr[i].i, out_attr[i].i);
ee065d83 8771 }
a9dc9481 8772 else if (in_attr[i].i && !out_attr[i].i)
ee065d83
PB
8773 out_attr[i].i = in_attr[i].i;
8774 break;
ee065d83
PB
8775 case Tag_ABI_enum_size:
8776 if (in_attr[i].i != AEABI_enum_unused)
8777 {
8778 if (out_attr[i].i == AEABI_enum_unused
8779 || out_attr[i].i == AEABI_enum_forced_wide)
8780 {
8781 /* The existing object is compatible with anything.
8782 Use whatever requirements the new object has. */
8783 out_attr[i].i = in_attr[i].i;
8784 }
8785 else if (in_attr[i].i != AEABI_enum_forced_wide
bf21ed78 8786 && out_attr[i].i != in_attr[i].i
0ffa91dd 8787 && !elf_arm_tdata (obfd)->no_enum_size_warning)
ee065d83 8788 {
91e22acd 8789 static const char *aeabi_enum_names[] =
bf21ed78 8790 { "", "variable-size", "32-bit", "" };
91e22acd
AS
8791 const char *in_name =
8792 in_attr[i].i < ARRAY_SIZE(aeabi_enum_names)
8793 ? aeabi_enum_names[in_attr[i].i]
8794 : "<unknown>";
8795 const char *out_name =
8796 out_attr[i].i < ARRAY_SIZE(aeabi_enum_names)
8797 ? aeabi_enum_names[out_attr[i].i]
8798 : "<unknown>";
ee065d83 8799 _bfd_error_handler
bf21ed78 8800 (_("warning: %B uses %s enums yet the output is to use %s enums; use of enum values across objects may fail"),
91e22acd 8801 ibfd, in_name, out_name);
ee065d83
PB
8802 }
8803 }
8804 break;
8805 case Tag_ABI_VFP_args:
8806 /* Aready done. */
8807 break;
8808 case Tag_ABI_WMMX_args:
8809 if (in_attr[i].i != out_attr[i].i)
8810 {
8811 _bfd_error_handler
8812 (_("ERROR: %B uses iWMMXt register arguments, %B does not"),
8813 ibfd, obfd);
91e22acd 8814 result = FALSE;
ee065d83
PB
8815 }
8816 break;
7b86a9fa
AS
8817 case Tag_compatibility:
8818 /* Merged in target-independent code. */
8819 break;
91e22acd
AS
8820 case Tag_ABI_HardFP_use:
8821 /* 1 (SP) and 2 (DP) conflict, so combine to 3 (SP & DP). */
8822 if ((in_attr[i].i == 1 && out_attr[i].i == 2)
8823 || (in_attr[i].i == 2 && out_attr[i].i == 1))
8824 out_attr[i].i = 3;
8825 else if (in_attr[i].i > out_attr[i].i)
8826 out_attr[i].i = in_attr[i].i;
8827 break;
8828 case Tag_ABI_FP_16bit_format:
8829 if (in_attr[i].i != 0 && out_attr[i].i != 0)
8830 {
8831 if (in_attr[i].i != out_attr[i].i)
8832 {
8833 _bfd_error_handler
8834 (_("ERROR: fp16 format mismatch between %B and %B"),
8835 ibfd, obfd);
8836 result = FALSE;
8837 }
8838 }
8839 if (in_attr[i].i != 0)
8840 out_attr[i].i = in_attr[i].i;
8841 break;
7b86a9fa 8842
91e22acd 8843 case Tag_nodefaults:
2d0bb761
AS
8844 /* This tag is set if it exists, but the value is unused (and is
8845 typically zero). We don't actually need to do anything here -
8846 the merge happens automatically when the type flags are merged
8847 below. */
91e22acd
AS
8848 break;
8849 case Tag_also_compatible_with:
8850 /* Already done in Tag_CPU_arch. */
8851 break;
8852 case Tag_conformance:
8853 /* Keep the attribute if it matches. Throw it away otherwise.
8854 No attribute means no claim to conform. */
8855 if (!in_attr[i].s || !out_attr[i].s
8856 || strcmp (in_attr[i].s, out_attr[i].s) != 0)
8857 out_attr[i].s = NULL;
8858 break;
3cfad14c 8859
91e22acd 8860 default:
3cfad14c 8861 {
91e22acd
AS
8862 bfd *err_bfd = NULL;
8863
8864 /* The "known_obj_attributes" table does contain some undefined
8865 attributes. Ensure that there are unused. */
8866 if (out_attr[i].i != 0 || out_attr[i].s != NULL)
8867 err_bfd = obfd;
8868 else if (in_attr[i].i != 0 || in_attr[i].s != NULL)
8869 err_bfd = ibfd;
8870
8871 if (err_bfd != NULL)
8872 {
8873 /* Attribute numbers >=64 (mod 128) can be safely ignored. */
8874 if ((i & 127) < 64)
8875 {
8876 _bfd_error_handler
8877 (_("%B: Unknown mandatory EABI object attribute %d"),
8878 err_bfd, i);
8879 bfd_set_error (bfd_error_bad_value);
8880 result = FALSE;
8881 }
8882 else
8883 {
8884 _bfd_error_handler
8885 (_("Warning: %B: Unknown EABI object attribute %d"),
8886 err_bfd, i);
8887 }
8888 }
8889
8890 /* Only pass on attributes that match in both inputs. */
8891 if (in_attr[i].i != out_attr[i].i
8892 || in_attr[i].s != out_attr[i].s
8893 || (in_attr[i].s != NULL && out_attr[i].s != NULL
8894 && strcmp (in_attr[i].s, out_attr[i].s) != 0))
8895 {
8896 out_attr[i].i = 0;
8897 out_attr[i].s = NULL;
8898 }
3cfad14c 8899 }
91e22acd
AS
8900 }
8901
8902 /* If out_attr was copied from in_attr then it won't have a type yet. */
8903 if (in_attr[i].type && !out_attr[i].type)
8904 out_attr[i].type = in_attr[i].type;
ee065d83
PB
8905 }
8906
104d59d1
JM
8907 /* Merge Tag_compatibility attributes and any common GNU ones. */
8908 _bfd_elf_merge_object_attributes (ibfd, obfd);
ee065d83 8909
104d59d1
JM
8910 /* Check for any attributes not known on ARM. */
8911 in_list = elf_other_obj_attributes_proc (ibfd);
91e22acd
AS
8912 out_listp = &elf_other_obj_attributes_proc (obfd);
8913 out_list = *out_listp;
8e79c3df 8914
91e22acd 8915 for (; in_list || out_list; )
ee065d83 8916 {
91e22acd
AS
8917 bfd *err_bfd = NULL;
8918 int err_tag = 0;
8e79c3df
CM
8919
8920 /* The tags for each list are in numerical order. */
8921 /* If the tags are equal, then merge. */
91e22acd 8922 if (out_list && (!in_list || in_list->tag > out_list->tag))
8e79c3df 8923 {
91e22acd
AS
8924 /* This attribute only exists in obfd. We can't merge, and we don't
8925 know what the tag means, so delete it. */
8926 err_bfd = obfd;
8927 err_tag = out_list->tag;
8928 *out_listp = out_list->next;
8929 out_list = *out_listp;
8e79c3df 8930 }
91e22acd 8931 else if (in_list && (!out_list || in_list->tag < out_list->tag))
8e79c3df 8932 {
91e22acd
AS
8933 /* This attribute only exists in ibfd. We can't merge, and we don't
8934 know what the tag means, so ignore it. */
8935 err_bfd = ibfd;
8936 err_tag = in_list->tag;
8e79c3df 8937 in_list = in_list->next;
eb111b1f 8938 }
91e22acd
AS
8939 else /* The tags are equal. */
8940 {
8941 /* As present, all attributes in the list are unknown, and
8942 therefore can't be merged meaningfully. */
8943 err_bfd = obfd;
8944 err_tag = out_list->tag;
8945
8946 /* Only pass on attributes that match in both inputs. */
8947 if (in_list->attr.i != out_list->attr.i
8948 || in_list->attr.s != out_list->attr.s
8949 || (in_list->attr.s && out_list->attr.s
8950 && strcmp (in_list->attr.s, out_list->attr.s) != 0))
8951 {
8952 /* No match. Delete the attribute. */
8953 *out_listp = out_list->next;
8954 out_list = *out_listp;
8955 }
8956 else
8957 {
8958 /* Matched. Keep the attribute and move to the next. */
8959 out_list = out_list->next;
8960 in_list = in_list->next;
8961 }
8962 }
8963
8964 if (err_bfd)
8965 {
8966 /* Attribute numbers >=64 (mod 128) can be safely ignored. */
8967 if ((err_tag & 127) < 64)
8968 {
8969 _bfd_error_handler
8970 (_("%B: Unknown mandatory EABI object attribute %d"),
8971 err_bfd, err_tag);
8972 bfd_set_error (bfd_error_bad_value);
8973 result = FALSE;
8974 }
8975 else
8976 {
8977 _bfd_error_handler
8978 (_("Warning: %B: Unknown EABI object attribute %d"),
8979 err_bfd, err_tag);
8980 }
8981 }
ee065d83 8982 }
91e22acd 8983 return result;
252b5132
RH
8984}
8985
3a4a14e9
PB
8986
8987/* Return TRUE if the two EABI versions are incompatible. */
8988
8989static bfd_boolean
8990elf32_arm_versions_compatible (unsigned iver, unsigned over)
8991{
8992 /* v4 and v5 are the same spec before and after it was released,
8993 so allow mixing them. */
8994 if ((iver == EF_ARM_EABI_VER4 && over == EF_ARM_EABI_VER5)
8995 || (iver == EF_ARM_EABI_VER5 && over == EF_ARM_EABI_VER4))
8996 return TRUE;
8997
8998 return (iver == over);
8999}
9000
252b5132
RH
9001/* Merge backend specific data from an object file to the output
9002 object file when linking. */
9b485d32 9003
b34976b6 9004static bfd_boolean
57e8b36a 9005elf32_arm_merge_private_bfd_data (bfd * ibfd, bfd * obfd)
252b5132
RH
9006{
9007 flagword out_flags;
9008 flagword in_flags;
b34976b6 9009 bfd_boolean flags_compatible = TRUE;
cf919dfd 9010 asection *sec;
252b5132 9011
9b485d32 9012 /* Check if we have the same endianess. */
82e51918 9013 if (! _bfd_generic_verify_endian_match (ibfd, obfd))
b34976b6 9014 return FALSE;
1fe494a5 9015
0ffa91dd 9016 if (! is_arm_elf (ibfd) || ! is_arm_elf (obfd))
b34976b6 9017 return TRUE;
252b5132 9018
ee065d83
PB
9019 if (!elf32_arm_merge_eabi_attributes (ibfd, obfd))
9020 return FALSE;
9021
252b5132
RH
9022 /* The input BFD must have had its flags initialised. */
9023 /* The following seems bogus to me -- The flags are initialized in
9024 the assembler but I don't think an elf_flags_init field is
9b485d32 9025 written into the object. */
252b5132
RH
9026 /* BFD_ASSERT (elf_flags_init (ibfd)); */
9027
9028 in_flags = elf_elfheader (ibfd)->e_flags;
9029 out_flags = elf_elfheader (obfd)->e_flags;
9030
23684067
PB
9031 /* In theory there is no reason why we couldn't handle this. However
9032 in practice it isn't even close to working and there is no real
9033 reason to want it. */
9034 if (EF_ARM_EABI_VERSION (in_flags) >= EF_ARM_EABI_VER4
c13bb2ea 9035 && !(ibfd->flags & DYNAMIC)
23684067
PB
9036 && (in_flags & EF_ARM_BE8))
9037 {
8029a119 9038 _bfd_error_handler (_("ERROR: %B is already in final BE8 format"),
23684067
PB
9039 ibfd);
9040 return FALSE;
9041 }
9042
252b5132
RH
9043 if (!elf_flags_init (obfd))
9044 {
fe077fa6
NC
9045 /* If the input is the default architecture and had the default
9046 flags then do not bother setting the flags for the output
9047 architecture, instead allow future merges to do this. If no
9048 future merges ever set these flags then they will retain their
9049 uninitialised values, which surprise surprise, correspond
252b5132 9050 to the default values. */
fe077fa6
NC
9051 if (bfd_get_arch_info (ibfd)->the_default
9052 && elf_elfheader (ibfd)->e_flags == 0)
b34976b6 9053 return TRUE;
252b5132 9054
b34976b6 9055 elf_flags_init (obfd) = TRUE;
252b5132
RH
9056 elf_elfheader (obfd)->e_flags = in_flags;
9057
9058 if (bfd_get_arch (obfd) == bfd_get_arch (ibfd)
9059 && bfd_get_arch_info (obfd)->the_default)
9060 return bfd_set_arch_mach (obfd, bfd_get_arch (ibfd), bfd_get_mach (ibfd));
9061
b34976b6 9062 return TRUE;
252b5132
RH
9063 }
9064
5a6c6817
NC
9065 /* Determine what should happen if the input ARM architecture
9066 does not match the output ARM architecture. */
9067 if (! bfd_arm_merge_machines (ibfd, obfd))
9068 return FALSE;
e16bb312 9069
1006ba19 9070 /* Identical flags must be compatible. */
252b5132 9071 if (in_flags == out_flags)
b34976b6 9072 return TRUE;
252b5132 9073
35a0f415
DJ
9074 /* Check to see if the input BFD actually contains any sections. If
9075 not, its flags may not have been initialised either, but it
8e3de13a 9076 cannot actually cause any incompatiblity. Do not short-circuit
35a0f415 9077 dynamic objects; their section list may be emptied by
d1f161ea 9078 elf_link_add_object_symbols.
35a0f415 9079
d1f161ea
NC
9080 Also check to see if there are no code sections in the input.
9081 In this case there is no need to check for code specific flags.
9082 XXX - do we need to worry about floating-point format compatability
9083 in data sections ? */
35a0f415 9084 if (!(ibfd->flags & DYNAMIC))
cf919dfd 9085 {
35a0f415 9086 bfd_boolean null_input_bfd = TRUE;
d1f161ea 9087 bfd_boolean only_data_sections = TRUE;
35a0f415
DJ
9088
9089 for (sec = ibfd->sections; sec != NULL; sec = sec->next)
cf919dfd 9090 {
35a0f415
DJ
9091 /* Ignore synthetic glue sections. */
9092 if (strcmp (sec->name, ".glue_7")
9093 && strcmp (sec->name, ".glue_7t"))
9094 {
d1f161ea
NC
9095 if ((bfd_get_section_flags (ibfd, sec)
9096 & (SEC_LOAD | SEC_CODE | SEC_HAS_CONTENTS))
9097 == (SEC_LOAD | SEC_CODE | SEC_HAS_CONTENTS))
9098 only_data_sections = FALSE;
9099
35a0f415
DJ
9100 null_input_bfd = FALSE;
9101 break;
9102 }
cf919dfd 9103 }
d1f161ea
NC
9104
9105 if (null_input_bfd || only_data_sections)
35a0f415 9106 return TRUE;
cf919dfd 9107 }
cf919dfd 9108
252b5132 9109 /* Complain about various flag mismatches. */
3a4a14e9
PB
9110 if (!elf32_arm_versions_compatible (EF_ARM_EABI_VERSION (in_flags),
9111 EF_ARM_EABI_VERSION (out_flags)))
fc830a83 9112 {
d003868e 9113 _bfd_error_handler
3656d5e3 9114 (_("ERROR: Source object %B has EABI version %d, but target %B has EABI version %d"),
d003868e
AM
9115 ibfd, obfd,
9116 (in_flags & EF_ARM_EABIMASK) >> 24,
9117 (out_flags & EF_ARM_EABIMASK) >> 24);
b34976b6 9118 return FALSE;
fc830a83 9119 }
252b5132 9120
1006ba19 9121 /* Not sure what needs to be checked for EABI versions >= 1. */
00a97672
RS
9122 /* VxWorks libraries do not use these flags. */
9123 if (get_elf_backend_data (obfd) != &elf32_arm_vxworks_bed
9124 && get_elf_backend_data (ibfd) != &elf32_arm_vxworks_bed
9125 && EF_ARM_EABI_VERSION (in_flags) == EF_ARM_EABI_UNKNOWN)
1006ba19 9126 {
fd2ec330 9127 if ((in_flags & EF_ARM_APCS_26) != (out_flags & EF_ARM_APCS_26))
1006ba19 9128 {
d003868e
AM
9129 _bfd_error_handler
9130 (_("ERROR: %B is compiled for APCS-%d, whereas target %B uses APCS-%d"),
9131 ibfd, obfd,
9132 in_flags & EF_ARM_APCS_26 ? 26 : 32,
9133 out_flags & EF_ARM_APCS_26 ? 26 : 32);
b34976b6 9134 flags_compatible = FALSE;
1006ba19 9135 }
252b5132 9136
fd2ec330 9137 if ((in_flags & EF_ARM_APCS_FLOAT) != (out_flags & EF_ARM_APCS_FLOAT))
1006ba19 9138 {
5eefb65f 9139 if (in_flags & EF_ARM_APCS_FLOAT)
d003868e
AM
9140 _bfd_error_handler
9141 (_("ERROR: %B passes floats in float registers, whereas %B passes them in integer registers"),
9142 ibfd, obfd);
5eefb65f 9143 else
d003868e
AM
9144 _bfd_error_handler
9145 (_("ERROR: %B passes floats in integer registers, whereas %B passes them in float registers"),
9146 ibfd, obfd);
63b0f745 9147
b34976b6 9148 flags_compatible = FALSE;
1006ba19 9149 }
252b5132 9150
96a846ea 9151 if ((in_flags & EF_ARM_VFP_FLOAT) != (out_flags & EF_ARM_VFP_FLOAT))
1006ba19 9152 {
96a846ea 9153 if (in_flags & EF_ARM_VFP_FLOAT)
d003868e
AM
9154 _bfd_error_handler
9155 (_("ERROR: %B uses VFP instructions, whereas %B does not"),
9156 ibfd, obfd);
5eefb65f 9157 else
d003868e
AM
9158 _bfd_error_handler
9159 (_("ERROR: %B uses FPA instructions, whereas %B does not"),
9160 ibfd, obfd);
fde78edd
NC
9161
9162 flags_compatible = FALSE;
9163 }
9164
9165 if ((in_flags & EF_ARM_MAVERICK_FLOAT) != (out_flags & EF_ARM_MAVERICK_FLOAT))
9166 {
9167 if (in_flags & EF_ARM_MAVERICK_FLOAT)
d003868e
AM
9168 _bfd_error_handler
9169 (_("ERROR: %B uses Maverick instructions, whereas %B does not"),
9170 ibfd, obfd);
fde78edd 9171 else
d003868e
AM
9172 _bfd_error_handler
9173 (_("ERROR: %B does not use Maverick instructions, whereas %B does"),
9174 ibfd, obfd);
63b0f745 9175
b34976b6 9176 flags_compatible = FALSE;
1006ba19 9177 }
96a846ea
RE
9178
9179#ifdef EF_ARM_SOFT_FLOAT
9180 if ((in_flags & EF_ARM_SOFT_FLOAT) != (out_flags & EF_ARM_SOFT_FLOAT))
9181 {
9182 /* We can allow interworking between code that is VFP format
9183 layout, and uses either soft float or integer regs for
9184 passing floating point arguments and results. We already
9185 know that the APCS_FLOAT flags match; similarly for VFP
9186 flags. */
9187 if ((in_flags & EF_ARM_APCS_FLOAT) != 0
9188 || (in_flags & EF_ARM_VFP_FLOAT) == 0)
9189 {
9190 if (in_flags & EF_ARM_SOFT_FLOAT)
d003868e
AM
9191 _bfd_error_handler
9192 (_("ERROR: %B uses software FP, whereas %B uses hardware FP"),
9193 ibfd, obfd);
96a846ea 9194 else
d003868e
AM
9195 _bfd_error_handler
9196 (_("ERROR: %B uses hardware FP, whereas %B uses software FP"),
9197 ibfd, obfd);
96a846ea 9198
b34976b6 9199 flags_compatible = FALSE;
96a846ea
RE
9200 }
9201 }
ee43f35e 9202#endif
252b5132 9203
1006ba19 9204 /* Interworking mismatch is only a warning. */
fd2ec330 9205 if ((in_flags & EF_ARM_INTERWORK) != (out_flags & EF_ARM_INTERWORK))
8f615d07 9206 {
e3c8793a
NC
9207 if (in_flags & EF_ARM_INTERWORK)
9208 {
d003868e
AM
9209 _bfd_error_handler
9210 (_("Warning: %B supports interworking, whereas %B does not"),
9211 ibfd, obfd);
e3c8793a
NC
9212 }
9213 else
9214 {
d003868e
AM
9215 _bfd_error_handler
9216 (_("Warning: %B does not support interworking, whereas %B does"),
9217 ibfd, obfd);
e3c8793a 9218 }
8f615d07 9219 }
252b5132 9220 }
63b0f745 9221
1006ba19 9222 return flags_compatible;
252b5132
RH
9223}
9224
9b485d32
NC
9225/* Display the flags field. */
9226
b34976b6 9227static bfd_boolean
57e8b36a 9228elf32_arm_print_private_bfd_data (bfd *abfd, void * ptr)
252b5132 9229{
fc830a83
NC
9230 FILE * file = (FILE *) ptr;
9231 unsigned long flags;
252b5132
RH
9232
9233 BFD_ASSERT (abfd != NULL && ptr != NULL);
9234
9235 /* Print normal ELF private data. */
9236 _bfd_elf_print_private_bfd_data (abfd, ptr);
9237
fc830a83 9238 flags = elf_elfheader (abfd)->e_flags;
9b485d32
NC
9239 /* Ignore init flag - it may not be set, despite the flags field
9240 containing valid data. */
252b5132
RH
9241
9242 /* xgettext:c-format */
9b485d32 9243 fprintf (file, _("private flags = %lx:"), elf_elfheader (abfd)->e_flags);
252b5132 9244
fc830a83
NC
9245 switch (EF_ARM_EABI_VERSION (flags))
9246 {
9247 case EF_ARM_EABI_UNKNOWN:
4cc11e76 9248 /* The following flag bits are GNU extensions and not part of the
fc830a83
NC
9249 official ARM ELF extended ABI. Hence they are only decoded if
9250 the EABI version is not set. */
fd2ec330 9251 if (flags & EF_ARM_INTERWORK)
9b485d32 9252 fprintf (file, _(" [interworking enabled]"));
9a5aca8c 9253
fd2ec330 9254 if (flags & EF_ARM_APCS_26)
6c571f00 9255 fprintf (file, " [APCS-26]");
fc830a83 9256 else
6c571f00 9257 fprintf (file, " [APCS-32]");
9a5aca8c 9258
96a846ea
RE
9259 if (flags & EF_ARM_VFP_FLOAT)
9260 fprintf (file, _(" [VFP float format]"));
fde78edd
NC
9261 else if (flags & EF_ARM_MAVERICK_FLOAT)
9262 fprintf (file, _(" [Maverick float format]"));
96a846ea
RE
9263 else
9264 fprintf (file, _(" [FPA float format]"));
9265
fd2ec330 9266 if (flags & EF_ARM_APCS_FLOAT)
9b485d32 9267 fprintf (file, _(" [floats passed in float registers]"));
9a5aca8c 9268
fd2ec330 9269 if (flags & EF_ARM_PIC)
9b485d32 9270 fprintf (file, _(" [position independent]"));
fc830a83 9271
fd2ec330 9272 if (flags & EF_ARM_NEW_ABI)
9b485d32 9273 fprintf (file, _(" [new ABI]"));
9a5aca8c 9274
fd2ec330 9275 if (flags & EF_ARM_OLD_ABI)
9b485d32 9276 fprintf (file, _(" [old ABI]"));
9a5aca8c 9277
fd2ec330 9278 if (flags & EF_ARM_SOFT_FLOAT)
9b485d32 9279 fprintf (file, _(" [software FP]"));
9a5aca8c 9280
96a846ea
RE
9281 flags &= ~(EF_ARM_INTERWORK | EF_ARM_APCS_26 | EF_ARM_APCS_FLOAT
9282 | EF_ARM_PIC | EF_ARM_NEW_ABI | EF_ARM_OLD_ABI
fde78edd
NC
9283 | EF_ARM_SOFT_FLOAT | EF_ARM_VFP_FLOAT
9284 | EF_ARM_MAVERICK_FLOAT);
fc830a83 9285 break;
9a5aca8c 9286
fc830a83 9287 case EF_ARM_EABI_VER1:
9b485d32 9288 fprintf (file, _(" [Version1 EABI]"));
9a5aca8c 9289
fc830a83 9290 if (flags & EF_ARM_SYMSARESORTED)
9b485d32 9291 fprintf (file, _(" [sorted symbol table]"));
fc830a83 9292 else
9b485d32 9293 fprintf (file, _(" [unsorted symbol table]"));
9a5aca8c 9294
fc830a83
NC
9295 flags &= ~ EF_ARM_SYMSARESORTED;
9296 break;
9a5aca8c 9297
fd2ec330
PB
9298 case EF_ARM_EABI_VER2:
9299 fprintf (file, _(" [Version2 EABI]"));
9300
9301 if (flags & EF_ARM_SYMSARESORTED)
9302 fprintf (file, _(" [sorted symbol table]"));
9303 else
9304 fprintf (file, _(" [unsorted symbol table]"));
9305
9306 if (flags & EF_ARM_DYNSYMSUSESEGIDX)
9307 fprintf (file, _(" [dynamic symbols use segment index]"));
9308
9309 if (flags & EF_ARM_MAPSYMSFIRST)
9310 fprintf (file, _(" [mapping symbols precede others]"));
9311
99e4ae17 9312 flags &= ~(EF_ARM_SYMSARESORTED | EF_ARM_DYNSYMSUSESEGIDX
fd2ec330
PB
9313 | EF_ARM_MAPSYMSFIRST);
9314 break;
9315
d507cf36
PB
9316 case EF_ARM_EABI_VER3:
9317 fprintf (file, _(" [Version3 EABI]"));
8cb51566
PB
9318 break;
9319
9320 case EF_ARM_EABI_VER4:
9321 fprintf (file, _(" [Version4 EABI]"));
3a4a14e9 9322 goto eabi;
d507cf36 9323
3a4a14e9
PB
9324 case EF_ARM_EABI_VER5:
9325 fprintf (file, _(" [Version5 EABI]"));
9326 eabi:
d507cf36
PB
9327 if (flags & EF_ARM_BE8)
9328 fprintf (file, _(" [BE8]"));
9329
9330 if (flags & EF_ARM_LE8)
9331 fprintf (file, _(" [LE8]"));
9332
9333 flags &= ~(EF_ARM_LE8 | EF_ARM_BE8);
9334 break;
9335
fc830a83 9336 default:
9b485d32 9337 fprintf (file, _(" <EABI version unrecognised>"));
fc830a83
NC
9338 break;
9339 }
252b5132 9340
fc830a83 9341 flags &= ~ EF_ARM_EABIMASK;
252b5132 9342
fc830a83 9343 if (flags & EF_ARM_RELEXEC)
9b485d32 9344 fprintf (file, _(" [relocatable executable]"));
252b5132 9345
fc830a83 9346 if (flags & EF_ARM_HASENTRY)
9b485d32 9347 fprintf (file, _(" [has entry point]"));
252b5132 9348
fc830a83
NC
9349 flags &= ~ (EF_ARM_RELEXEC | EF_ARM_HASENTRY);
9350
9351 if (flags)
9b485d32 9352 fprintf (file, _("<Unrecognised flag bits set>"));
9a5aca8c 9353
252b5132
RH
9354 fputc ('\n', file);
9355
b34976b6 9356 return TRUE;
252b5132
RH
9357}
9358
9359static int
57e8b36a 9360elf32_arm_get_symbol_type (Elf_Internal_Sym * elf_sym, int type)
252b5132 9361{
2f0ca46a
NC
9362 switch (ELF_ST_TYPE (elf_sym->st_info))
9363 {
9364 case STT_ARM_TFUNC:
9365 return ELF_ST_TYPE (elf_sym->st_info);
ce855c42 9366
2f0ca46a
NC
9367 case STT_ARM_16BIT:
9368 /* If the symbol is not an object, return the STT_ARM_16BIT flag.
9369 This allows us to distinguish between data used by Thumb instructions
9370 and non-data (which is probably code) inside Thumb regions of an
9371 executable. */
1a0eb693 9372 if (type != STT_OBJECT && type != STT_TLS)
2f0ca46a
NC
9373 return ELF_ST_TYPE (elf_sym->st_info);
9374 break;
9a5aca8c 9375
ce855c42
NC
9376 default:
9377 break;
2f0ca46a
NC
9378 }
9379
9380 return type;
252b5132 9381}
f21f3fe0 9382
252b5132 9383static asection *
07adf181
AM
9384elf32_arm_gc_mark_hook (asection *sec,
9385 struct bfd_link_info *info,
9386 Elf_Internal_Rela *rel,
9387 struct elf_link_hash_entry *h,
9388 Elf_Internal_Sym *sym)
252b5132
RH
9389{
9390 if (h != NULL)
07adf181 9391 switch (ELF32_R_TYPE (rel->r_info))
252b5132
RH
9392 {
9393 case R_ARM_GNU_VTINHERIT:
9394 case R_ARM_GNU_VTENTRY:
07adf181
AM
9395 return NULL;
9396 }
9ad5cbcf 9397
07adf181 9398 return _bfd_elf_gc_mark_hook (sec, info, rel, h, sym);
252b5132
RH
9399}
9400
780a67af
NC
9401/* Update the got entry reference counts for the section being removed. */
9402
b34976b6 9403static bfd_boolean
ba93b8ac
DJ
9404elf32_arm_gc_sweep_hook (bfd * abfd,
9405 struct bfd_link_info * info,
9406 asection * sec,
9407 const Elf_Internal_Rela * relocs)
252b5132 9408{
5e681ec4
PB
9409 Elf_Internal_Shdr *symtab_hdr;
9410 struct elf_link_hash_entry **sym_hashes;
9411 bfd_signed_vma *local_got_refcounts;
9412 const Elf_Internal_Rela *rel, *relend;
eb043451
PB
9413 struct elf32_arm_link_hash_table * globals;
9414
7dda2462
TG
9415 if (info->relocatable)
9416 return TRUE;
9417
eb043451 9418 globals = elf32_arm_hash_table (info);
5e681ec4
PB
9419
9420 elf_section_data (sec)->local_dynrel = NULL;
9421
0ffa91dd 9422 symtab_hdr = & elf_symtab_hdr (abfd);
5e681ec4
PB
9423 sym_hashes = elf_sym_hashes (abfd);
9424 local_got_refcounts = elf_local_got_refcounts (abfd);
9425
906e58ca 9426 check_use_blx (globals);
bd97cb95 9427
5e681ec4
PB
9428 relend = relocs + sec->reloc_count;
9429 for (rel = relocs; rel < relend; rel++)
eb043451 9430 {
3eb128b2
AM
9431 unsigned long r_symndx;
9432 struct elf_link_hash_entry *h = NULL;
eb043451 9433 int r_type;
5e681ec4 9434
3eb128b2
AM
9435 r_symndx = ELF32_R_SYM (rel->r_info);
9436 if (r_symndx >= symtab_hdr->sh_info)
9437 {
9438 h = sym_hashes[r_symndx - symtab_hdr->sh_info];
9439 while (h->root.type == bfd_link_hash_indirect
9440 || h->root.type == bfd_link_hash_warning)
9441 h = (struct elf_link_hash_entry *) h->root.u.i.link;
9442 }
9443
eb043451 9444 r_type = ELF32_R_TYPE (rel->r_info);
eb043451 9445 r_type = arm_real_reloc_type (globals, r_type);
eb043451
PB
9446 switch (r_type)
9447 {
9448 case R_ARM_GOT32:
eb043451 9449 case R_ARM_GOT_PREL:
ba93b8ac
DJ
9450 case R_ARM_TLS_GD32:
9451 case R_ARM_TLS_IE32:
3eb128b2 9452 if (h != NULL)
eb043451 9453 {
eb043451
PB
9454 if (h->got.refcount > 0)
9455 h->got.refcount -= 1;
9456 }
9457 else if (local_got_refcounts != NULL)
9458 {
9459 if (local_got_refcounts[r_symndx] > 0)
9460 local_got_refcounts[r_symndx] -= 1;
9461 }
9462 break;
9463
ba93b8ac
DJ
9464 case R_ARM_TLS_LDM32:
9465 elf32_arm_hash_table (info)->tls_ldm_got.refcount -= 1;
9466 break;
9467
eb043451 9468 case R_ARM_ABS32:
bb224fc3 9469 case R_ARM_ABS32_NOI:
eb043451 9470 case R_ARM_REL32:
bb224fc3 9471 case R_ARM_REL32_NOI:
eb043451
PB
9472 case R_ARM_PC24:
9473 case R_ARM_PLT32:
5b5bb741
PB
9474 case R_ARM_CALL:
9475 case R_ARM_JUMP24:
eb043451 9476 case R_ARM_PREL31:
c19d1205 9477 case R_ARM_THM_CALL:
bd97cb95
DJ
9478 case R_ARM_THM_JUMP24:
9479 case R_ARM_THM_JUMP19:
b6895b4f
PB
9480 case R_ARM_MOVW_ABS_NC:
9481 case R_ARM_MOVT_ABS:
9482 case R_ARM_MOVW_PREL_NC:
9483 case R_ARM_MOVT_PREL:
9484 case R_ARM_THM_MOVW_ABS_NC:
9485 case R_ARM_THM_MOVT_ABS:
9486 case R_ARM_THM_MOVW_PREL_NC:
9487 case R_ARM_THM_MOVT_PREL:
b7693d02
DJ
9488 /* Should the interworking branches be here also? */
9489
3eb128b2 9490 if (h != NULL)
eb043451
PB
9491 {
9492 struct elf32_arm_link_hash_entry *eh;
9493 struct elf32_arm_relocs_copied **pp;
9494 struct elf32_arm_relocs_copied *p;
5e681ec4 9495
b7693d02 9496 eh = (struct elf32_arm_link_hash_entry *) h;
5e681ec4 9497
eb043451 9498 if (h->plt.refcount > 0)
b7693d02
DJ
9499 {
9500 h->plt.refcount -= 1;
bd97cb95
DJ
9501 if (r_type == R_ARM_THM_CALL)
9502 eh->plt_maybe_thumb_refcount--;
9503
9504 if (r_type == R_ARM_THM_JUMP24
9505 || r_type == R_ARM_THM_JUMP19)
b7693d02
DJ
9506 eh->plt_thumb_refcount--;
9507 }
5e681ec4 9508
eb043451 9509 if (r_type == R_ARM_ABS32
bb224fc3
MS
9510 || r_type == R_ARM_REL32
9511 || r_type == R_ARM_ABS32_NOI
9512 || r_type == R_ARM_REL32_NOI)
eb043451 9513 {
eb043451
PB
9514 for (pp = &eh->relocs_copied; (p = *pp) != NULL;
9515 pp = &p->next)
9516 if (p->section == sec)
9517 {
9518 p->count -= 1;
bb224fc3
MS
9519 if (ELF32_R_TYPE (rel->r_info) == R_ARM_REL32
9520 || ELF32_R_TYPE (rel->r_info) == R_ARM_REL32_NOI)
ba93b8ac 9521 p->pc_count -= 1;
eb043451
PB
9522 if (p->count == 0)
9523 *pp = p->next;
9524 break;
9525 }
9526 }
9527 }
9528 break;
5e681ec4 9529
eb043451
PB
9530 default:
9531 break;
9532 }
9533 }
5e681ec4 9534
b34976b6 9535 return TRUE;
252b5132
RH
9536}
9537
780a67af
NC
9538/* Look through the relocs for a section during the first phase. */
9539
b34976b6 9540static bfd_boolean
57e8b36a
NC
9541elf32_arm_check_relocs (bfd *abfd, struct bfd_link_info *info,
9542 asection *sec, const Elf_Internal_Rela *relocs)
252b5132 9543{
b34976b6
AM
9544 Elf_Internal_Shdr *symtab_hdr;
9545 struct elf_link_hash_entry **sym_hashes;
b34976b6
AM
9546 const Elf_Internal_Rela *rel;
9547 const Elf_Internal_Rela *rel_end;
9548 bfd *dynobj;
5e681ec4 9549 asection *sreloc;
b34976b6 9550 bfd_vma *local_got_offsets;
5e681ec4 9551 struct elf32_arm_link_hash_table *htab;
39623e12 9552 bfd_boolean needs_plt;
9a5aca8c 9553
1049f94e 9554 if (info->relocatable)
b34976b6 9555 return TRUE;
9a5aca8c 9556
0ffa91dd
NC
9557 BFD_ASSERT (is_arm_elf (abfd));
9558
5e681ec4
PB
9559 htab = elf32_arm_hash_table (info);
9560 sreloc = NULL;
9a5aca8c 9561
67687978
PB
9562 /* Create dynamic sections for relocatable executables so that we can
9563 copy relocations. */
9564 if (htab->root.is_relocatable_executable
9565 && ! htab->root.dynamic_sections_created)
9566 {
9567 if (! _bfd_elf_link_create_dynamic_sections (abfd, info))
9568 return FALSE;
9569 }
9570
252b5132
RH
9571 dynobj = elf_hash_table (info)->dynobj;
9572 local_got_offsets = elf_local_got_offsets (abfd);
f21f3fe0 9573
0ffa91dd 9574 symtab_hdr = & elf_symtab_hdr (abfd);
252b5132 9575 sym_hashes = elf_sym_hashes (abfd);
9b485d32 9576
252b5132
RH
9577 rel_end = relocs + sec->reloc_count;
9578 for (rel = relocs; rel < rel_end; rel++)
9579 {
9580 struct elf_link_hash_entry *h;
b7693d02 9581 struct elf32_arm_link_hash_entry *eh;
252b5132 9582 unsigned long r_symndx;
eb043451 9583 int r_type;
9a5aca8c 9584
252b5132 9585 r_symndx = ELF32_R_SYM (rel->r_info);
eb043451 9586 r_type = ELF32_R_TYPE (rel->r_info);
eb043451 9587 r_type = arm_real_reloc_type (htab, r_type);
ba93b8ac
DJ
9588
9589 if (r_symndx >= NUM_SHDR_ENTRIES (symtab_hdr))
9590 {
9591 (*_bfd_error_handler) (_("%B: bad symbol index: %d"), abfd,
9592 r_symndx);
9593 return FALSE;
9594 }
9595
252b5132
RH
9596 if (r_symndx < symtab_hdr->sh_info)
9597 h = NULL;
9598 else
973a3492
L
9599 {
9600 h = sym_hashes[r_symndx - symtab_hdr->sh_info];
9601 while (h->root.type == bfd_link_hash_indirect
9602 || h->root.type == bfd_link_hash_warning)
9603 h = (struct elf_link_hash_entry *) h->root.u.i.link;
9604 }
9a5aca8c 9605
b7693d02
DJ
9606 eh = (struct elf32_arm_link_hash_entry *) h;
9607
eb043451 9608 switch (r_type)
252b5132 9609 {
5e681ec4 9610 case R_ARM_GOT32:
eb043451 9611 case R_ARM_GOT_PREL:
ba93b8ac
DJ
9612 case R_ARM_TLS_GD32:
9613 case R_ARM_TLS_IE32:
5e681ec4 9614 /* This symbol requires a global offset table entry. */
ba93b8ac
DJ
9615 {
9616 int tls_type, old_tls_type;
5e681ec4 9617
ba93b8ac
DJ
9618 switch (r_type)
9619 {
9620 case R_ARM_TLS_GD32: tls_type = GOT_TLS_GD; break;
9621 case R_ARM_TLS_IE32: tls_type = GOT_TLS_IE; break;
9622 default: tls_type = GOT_NORMAL; break;
9623 }
252b5132 9624
ba93b8ac
DJ
9625 if (h != NULL)
9626 {
9627 h->got.refcount++;
9628 old_tls_type = elf32_arm_hash_entry (h)->tls_type;
9629 }
9630 else
9631 {
9632 bfd_signed_vma *local_got_refcounts;
9633
9634 /* This is a global offset table entry for a local symbol. */
9635 local_got_refcounts = elf_local_got_refcounts (abfd);
9636 if (local_got_refcounts == NULL)
9637 {
9638 bfd_size_type size;
906e58ca 9639
ba93b8ac 9640 size = symtab_hdr->sh_info;
906e58ca 9641 size *= (sizeof (bfd_signed_vma) + sizeof (char));
ba93b8ac
DJ
9642 local_got_refcounts = bfd_zalloc (abfd, size);
9643 if (local_got_refcounts == NULL)
9644 return FALSE;
9645 elf_local_got_refcounts (abfd) = local_got_refcounts;
9646 elf32_arm_local_got_tls_type (abfd)
9647 = (char *) (local_got_refcounts + symtab_hdr->sh_info);
9648 }
9649 local_got_refcounts[r_symndx] += 1;
9650 old_tls_type = elf32_arm_local_got_tls_type (abfd) [r_symndx];
9651 }
9652
9653 /* We will already have issued an error message if there is a
9654 TLS / non-TLS mismatch, based on the symbol type. We don't
9655 support any linker relaxations. So just combine any TLS
9656 types needed. */
9657 if (old_tls_type != GOT_UNKNOWN && old_tls_type != GOT_NORMAL
9658 && tls_type != GOT_NORMAL)
9659 tls_type |= old_tls_type;
9660
9661 if (old_tls_type != tls_type)
9662 {
9663 if (h != NULL)
9664 elf32_arm_hash_entry (h)->tls_type = tls_type;
9665 else
9666 elf32_arm_local_got_tls_type (abfd) [r_symndx] = tls_type;
9667 }
9668 }
8029a119 9669 /* Fall through. */
ba93b8ac
DJ
9670
9671 case R_ARM_TLS_LDM32:
9672 if (r_type == R_ARM_TLS_LDM32)
9673 htab->tls_ldm_got.refcount++;
8029a119 9674 /* Fall through. */
252b5132 9675
c19d1205 9676 case R_ARM_GOTOFF32:
5e681ec4
PB
9677 case R_ARM_GOTPC:
9678 if (htab->sgot == NULL)
9679 {
9680 if (htab->root.dynobj == NULL)
9681 htab->root.dynobj = abfd;
9682 if (!create_got_section (htab->root.dynobj, info))
9683 return FALSE;
9684 }
252b5132
RH
9685 break;
9686
00a97672
RS
9687 case R_ARM_ABS12:
9688 /* VxWorks uses dynamic R_ARM_ABS12 relocations for
9689 ldr __GOTT_INDEX__ offsets. */
9690 if (!htab->vxworks_p)
9691 break;
8029a119 9692 /* Fall through. */
00a97672 9693
252b5132 9694 case R_ARM_PC24:
7359ea65 9695 case R_ARM_PLT32:
5b5bb741
PB
9696 case R_ARM_CALL:
9697 case R_ARM_JUMP24:
eb043451 9698 case R_ARM_PREL31:
c19d1205 9699 case R_ARM_THM_CALL:
bd97cb95
DJ
9700 case R_ARM_THM_JUMP24:
9701 case R_ARM_THM_JUMP19:
39623e12
PB
9702 needs_plt = 1;
9703 goto normal_reloc;
9704
9705 case R_ARM_ABS32:
9706 case R_ARM_ABS32_NOI:
9707 case R_ARM_REL32:
9708 case R_ARM_REL32_NOI:
b6895b4f
PB
9709 case R_ARM_MOVW_ABS_NC:
9710 case R_ARM_MOVT_ABS:
9711 case R_ARM_MOVW_PREL_NC:
9712 case R_ARM_MOVT_PREL:
9713 case R_ARM_THM_MOVW_ABS_NC:
9714 case R_ARM_THM_MOVT_ABS:
9715 case R_ARM_THM_MOVW_PREL_NC:
9716 case R_ARM_THM_MOVT_PREL:
39623e12
PB
9717 needs_plt = 0;
9718 normal_reloc:
9719
b7693d02 9720 /* Should the interworking branches be listed here? */
7359ea65 9721 if (h != NULL)
5e681ec4
PB
9722 {
9723 /* If this reloc is in a read-only section, we might
9724 need a copy reloc. We can't check reliably at this
9725 stage whether the section is read-only, as input
9726 sections have not yet been mapped to output sections.
9727 Tentatively set the flag for now, and correct in
9728 adjust_dynamic_symbol. */
7359ea65 9729 if (!info->shared)
f5385ebf 9730 h->non_got_ref = 1;
7359ea65 9731
5e681ec4 9732 /* We may need a .plt entry if the function this reloc
c84cd8ee
DJ
9733 refers to is in a different object. We can't tell for
9734 sure yet, because something later might force the
9735 symbol local. */
39623e12 9736 if (needs_plt)
f5385ebf 9737 h->needs_plt = 1;
4f199be3
DJ
9738
9739 /* If we create a PLT entry, this relocation will reference
9740 it, even if it's an ABS32 relocation. */
9741 h->plt.refcount += 1;
b7693d02 9742
bd97cb95
DJ
9743 /* It's too early to use htab->use_blx here, so we have to
9744 record possible blx references separately from
9745 relocs that definitely need a thumb stub. */
9746
c19d1205 9747 if (r_type == R_ARM_THM_CALL)
bd97cb95
DJ
9748 eh->plt_maybe_thumb_refcount += 1;
9749
9750 if (r_type == R_ARM_THM_JUMP24
9751 || r_type == R_ARM_THM_JUMP19)
b7693d02 9752 eh->plt_thumb_refcount += 1;
5e681ec4
PB
9753 }
9754
67687978
PB
9755 /* If we are creating a shared library or relocatable executable,
9756 and this is a reloc against a global symbol, or a non PC
9757 relative reloc against a local symbol, then we need to copy
9758 the reloc into the shared library. However, if we are linking
9759 with -Bsymbolic, we do not need to copy a reloc against a
252b5132
RH
9760 global symbol which is defined in an object we are
9761 including in the link (i.e., DEF_REGULAR is set). At
9762 this point we have not seen all the input files, so it is
9763 possible that DEF_REGULAR is not set now but will be set
9764 later (it is never cleared). We account for that
9765 possibility below by storing information in the
5e681ec4 9766 relocs_copied field of the hash table entry. */
67687978 9767 if ((info->shared || htab->root.is_relocatable_executable)
5e681ec4 9768 && (sec->flags & SEC_ALLOC) != 0
bb224fc3 9769 && ((r_type == R_ARM_ABS32 || r_type == R_ARM_ABS32_NOI)
71a976dd
DJ
9770 || (h != NULL && ! h->needs_plt
9771 && (! info->symbolic || ! h->def_regular))))
252b5132 9772 {
5e681ec4
PB
9773 struct elf32_arm_relocs_copied *p, **head;
9774
252b5132
RH
9775 /* When creating a shared object, we must copy these
9776 reloc types into the output file. We create a reloc
9777 section in dynobj and make room for this reloc. */
83bac4b0 9778 if (sreloc == NULL)
252b5132 9779 {
83bac4b0
NC
9780 sreloc = _bfd_elf_make_dynamic_reloc_section
9781 (sec, dynobj, 2, abfd, ! htab->use_rel);
252b5132 9782
83bac4b0 9783 if (sreloc == NULL)
b34976b6 9784 return FALSE;
252b5132 9785
83bac4b0
NC
9786 /* BPABI objects never have dynamic relocations mapped. */
9787 if (! htab->symbian_p)
252b5132 9788 {
83bac4b0 9789 flagword flags;
5e681ec4 9790
83bac4b0 9791 flags = bfd_get_section_flags (dynobj, sreloc);
528aeb62 9792 flags |= (SEC_LOAD | SEC_ALLOC);
83bac4b0
NC
9793 bfd_set_section_flags (dynobj, sreloc, flags);
9794 }
252b5132
RH
9795 }
9796
5e681ec4
PB
9797 /* If this is a global symbol, we count the number of
9798 relocations we need for this symbol. */
9799 if (h != NULL)
252b5132 9800 {
5e681ec4
PB
9801 head = &((struct elf32_arm_link_hash_entry *) h)->relocs_copied;
9802 }
9803 else
9804 {
9805 /* Track dynamic relocs needed for local syms too.
9806 We really need local syms available to do this
9807 easily. Oh well. */
57e8b36a 9808
5e681ec4 9809 asection *s;
6edfbbad
DJ
9810 void *vpp;
9811
5e681ec4
PB
9812 s = bfd_section_from_r_symndx (abfd, &htab->sym_sec,
9813 sec, r_symndx);
9814 if (s == NULL)
9815 return FALSE;
57e8b36a 9816
6edfbbad
DJ
9817 vpp = &elf_section_data (s)->local_dynrel;
9818 head = (struct elf32_arm_relocs_copied **) vpp;
5e681ec4 9819 }
57e8b36a 9820
5e681ec4
PB
9821 p = *head;
9822 if (p == NULL || p->section != sec)
9823 {
9824 bfd_size_type amt = sizeof *p;
57e8b36a 9825
5e681ec4 9826 p = bfd_alloc (htab->root.dynobj, amt);
252b5132 9827 if (p == NULL)
5e681ec4
PB
9828 return FALSE;
9829 p->next = *head;
9830 *head = p;
9831 p->section = sec;
9832 p->count = 0;
ba93b8ac 9833 p->pc_count = 0;
252b5132 9834 }
57e8b36a 9835
bb224fc3 9836 if (r_type == R_ARM_REL32 || r_type == R_ARM_REL32_NOI)
ba93b8ac 9837 p->pc_count += 1;
71a976dd 9838 p->count += 1;
252b5132
RH
9839 }
9840 break;
9841
9842 /* This relocation describes the C++ object vtable hierarchy.
9843 Reconstruct it for later use during GC. */
9844 case R_ARM_GNU_VTINHERIT:
c152c796 9845 if (!bfd_elf_gc_record_vtinherit (abfd, sec, h, rel->r_offset))
b34976b6 9846 return FALSE;
252b5132 9847 break;
9a5aca8c 9848
252b5132
RH
9849 /* This relocation describes which C++ vtable entries are actually
9850 used. Record for later use during GC. */
9851 case R_ARM_GNU_VTENTRY:
d17e0c6e
JB
9852 BFD_ASSERT (h != NULL);
9853 if (h != NULL
9854 && !bfd_elf_gc_record_vtentry (abfd, sec, h, rel->r_offset))
b34976b6 9855 return FALSE;
252b5132
RH
9856 break;
9857 }
9858 }
f21f3fe0 9859
b34976b6 9860 return TRUE;
252b5132
RH
9861}
9862
6a5bb875
PB
9863/* Unwinding tables are not referenced directly. This pass marks them as
9864 required if the corresponding code section is marked. */
9865
9866static bfd_boolean
906e58ca
NC
9867elf32_arm_gc_mark_extra_sections (struct bfd_link_info *info,
9868 elf_gc_mark_hook_fn gc_mark_hook)
6a5bb875
PB
9869{
9870 bfd *sub;
9871 Elf_Internal_Shdr **elf_shdrp;
9872 bfd_boolean again;
9873
9874 /* Marking EH data may cause additional code sections to be marked,
9875 requiring multiple passes. */
9876 again = TRUE;
9877 while (again)
9878 {
9879 again = FALSE;
9880 for (sub = info->input_bfds; sub != NULL; sub = sub->link_next)
9881 {
9882 asection *o;
9883
0ffa91dd 9884 if (! is_arm_elf (sub))
6a5bb875
PB
9885 continue;
9886
9887 elf_shdrp = elf_elfsections (sub);
9888 for (o = sub->sections; o != NULL; o = o->next)
9889 {
9890 Elf_Internal_Shdr *hdr;
0ffa91dd 9891
6a5bb875 9892 hdr = &elf_section_data (o)->this_hdr;
4fbb74a6
AM
9893 if (hdr->sh_type == SHT_ARM_EXIDX
9894 && hdr->sh_link
9895 && hdr->sh_link < elf_numsections (sub)
6a5bb875
PB
9896 && !o->gc_mark
9897 && elf_shdrp[hdr->sh_link]->bfd_section->gc_mark)
9898 {
9899 again = TRUE;
9900 if (!_bfd_elf_gc_mark (info, o, gc_mark_hook))
9901 return FALSE;
9902 }
9903 }
9904 }
9905 }
9906
9907 return TRUE;
9908}
9909
3c9458e9
NC
9910/* Treat mapping symbols as special target symbols. */
9911
9912static bfd_boolean
9913elf32_arm_is_target_special_symbol (bfd * abfd ATTRIBUTE_UNUSED, asymbol * sym)
9914{
b0796911
PB
9915 return bfd_is_arm_special_symbol_name (sym->name,
9916 BFD_ARM_SPECIAL_SYM_TYPE_ANY);
3c9458e9
NC
9917}
9918
0367ecfb
NC
9919/* This is a copy of elf_find_function() from elf.c except that
9920 ARM mapping symbols are ignored when looking for function names
9921 and STT_ARM_TFUNC is considered to a function type. */
252b5132 9922
0367ecfb
NC
9923static bfd_boolean
9924arm_elf_find_function (bfd * abfd ATTRIBUTE_UNUSED,
9925 asection * section,
9926 asymbol ** symbols,
9927 bfd_vma offset,
9928 const char ** filename_ptr,
9929 const char ** functionname_ptr)
9930{
9931 const char * filename = NULL;
9932 asymbol * func = NULL;
9933 bfd_vma low_func = 0;
9934 asymbol ** p;
252b5132
RH
9935
9936 for (p = symbols; *p != NULL; p++)
9937 {
9938 elf_symbol_type *q;
9939
9940 q = (elf_symbol_type *) *p;
9941
252b5132
RH
9942 switch (ELF_ST_TYPE (q->internal_elf_sym.st_info))
9943 {
9944 default:
9945 break;
9946 case STT_FILE:
9947 filename = bfd_asymbol_name (&q->symbol);
9948 break;
252b5132
RH
9949 case STT_FUNC:
9950 case STT_ARM_TFUNC:
9d2da7ca 9951 case STT_NOTYPE:
b0796911 9952 /* Skip mapping symbols. */
0367ecfb 9953 if ((q->symbol.flags & BSF_LOCAL)
b0796911
PB
9954 && bfd_is_arm_special_symbol_name (q->symbol.name,
9955 BFD_ARM_SPECIAL_SYM_TYPE_ANY))
0367ecfb
NC
9956 continue;
9957 /* Fall through. */
6b40fcba 9958 if (bfd_get_section (&q->symbol) == section
252b5132
RH
9959 && q->symbol.value >= low_func
9960 && q->symbol.value <= offset)
9961 {
9962 func = (asymbol *) q;
9963 low_func = q->symbol.value;
9964 }
9965 break;
9966 }
9967 }
9968
9969 if (func == NULL)
b34976b6 9970 return FALSE;
252b5132 9971
0367ecfb
NC
9972 if (filename_ptr)
9973 *filename_ptr = filename;
9974 if (functionname_ptr)
9975 *functionname_ptr = bfd_asymbol_name (func);
9976
9977 return TRUE;
906e58ca 9978}
0367ecfb
NC
9979
9980
9981/* Find the nearest line to a particular section and offset, for error
9982 reporting. This code is a duplicate of the code in elf.c, except
9983 that it uses arm_elf_find_function. */
9984
9985static bfd_boolean
9986elf32_arm_find_nearest_line (bfd * abfd,
9987 asection * section,
9988 asymbol ** symbols,
9989 bfd_vma offset,
9990 const char ** filename_ptr,
9991 const char ** functionname_ptr,
9992 unsigned int * line_ptr)
9993{
9994 bfd_boolean found = FALSE;
9995
9996 /* We skip _bfd_dwarf1_find_nearest_line since no known ARM toolchain uses it. */
9997
9998 if (_bfd_dwarf2_find_nearest_line (abfd, section, symbols, offset,
9999 filename_ptr, functionname_ptr,
10000 line_ptr, 0,
10001 & elf_tdata (abfd)->dwarf2_find_line_info))
10002 {
10003 if (!*functionname_ptr)
10004 arm_elf_find_function (abfd, section, symbols, offset,
10005 *filename_ptr ? NULL : filename_ptr,
10006 functionname_ptr);
f21f3fe0 10007
0367ecfb
NC
10008 return TRUE;
10009 }
10010
10011 if (! _bfd_stab_section_find_nearest_line (abfd, symbols, section, offset,
10012 & found, filename_ptr,
10013 functionname_ptr, line_ptr,
10014 & elf_tdata (abfd)->line_info))
10015 return FALSE;
10016
10017 if (found && (*functionname_ptr || *line_ptr))
10018 return TRUE;
10019
10020 if (symbols == NULL)
10021 return FALSE;
10022
10023 if (! arm_elf_find_function (abfd, section, symbols, offset,
10024 filename_ptr, functionname_ptr))
10025 return FALSE;
10026
10027 *line_ptr = 0;
b34976b6 10028 return TRUE;
252b5132
RH
10029}
10030
4ab527b0
FF
10031static bfd_boolean
10032elf32_arm_find_inliner_info (bfd * abfd,
10033 const char ** filename_ptr,
10034 const char ** functionname_ptr,
10035 unsigned int * line_ptr)
10036{
10037 bfd_boolean found;
10038 found = _bfd_dwarf2_find_inliner_info (abfd, filename_ptr,
10039 functionname_ptr, line_ptr,
10040 & elf_tdata (abfd)->dwarf2_find_line_info);
10041 return found;
10042}
10043
252b5132
RH
10044/* Adjust a symbol defined by a dynamic object and referenced by a
10045 regular object. The current definition is in some section of the
10046 dynamic object, but we're not including those sections. We have to
10047 change the definition to something the rest of the link can
10048 understand. */
10049
b34976b6 10050static bfd_boolean
57e8b36a
NC
10051elf32_arm_adjust_dynamic_symbol (struct bfd_link_info * info,
10052 struct elf_link_hash_entry * h)
252b5132
RH
10053{
10054 bfd * dynobj;
10055 asection * s;
b7693d02 10056 struct elf32_arm_link_hash_entry * eh;
67687978 10057 struct elf32_arm_link_hash_table *globals;
252b5132 10058
67687978 10059 globals = elf32_arm_hash_table (info);
252b5132
RH
10060 dynobj = elf_hash_table (info)->dynobj;
10061
10062 /* Make sure we know what is going on here. */
10063 BFD_ASSERT (dynobj != NULL
f5385ebf 10064 && (h->needs_plt
f6e332e6 10065 || h->u.weakdef != NULL
f5385ebf
AM
10066 || (h->def_dynamic
10067 && h->ref_regular
10068 && !h->def_regular)));
252b5132 10069
b7693d02
DJ
10070 eh = (struct elf32_arm_link_hash_entry *) h;
10071
252b5132
RH
10072 /* If this is a function, put it in the procedure linkage table. We
10073 will fill in the contents of the procedure linkage table later,
10074 when we know the address of the .got section. */
0f88be7a 10075 if (h->type == STT_FUNC || h->type == STT_ARM_TFUNC
f5385ebf 10076 || h->needs_plt)
252b5132 10077 {
5e681ec4
PB
10078 if (h->plt.refcount <= 0
10079 || SYMBOL_CALLS_LOCAL (info, h)
10080 || (ELF_ST_VISIBILITY (h->other) != STV_DEFAULT
10081 && h->root.type == bfd_link_hash_undefweak))
252b5132
RH
10082 {
10083 /* This case can occur if we saw a PLT32 reloc in an input
5e681ec4
PB
10084 file, but the symbol was never referred to by a dynamic
10085 object, or if all references were garbage collected. In
10086 such a case, we don't actually need to build a procedure
10087 linkage table, and we can just do a PC24 reloc instead. */
10088 h->plt.offset = (bfd_vma) -1;
b7693d02 10089 eh->plt_thumb_refcount = 0;
bd97cb95 10090 eh->plt_maybe_thumb_refcount = 0;
f5385ebf 10091 h->needs_plt = 0;
252b5132
RH
10092 }
10093
b34976b6 10094 return TRUE;
252b5132 10095 }
5e681ec4 10096 else
b7693d02
DJ
10097 {
10098 /* It's possible that we incorrectly decided a .plt reloc was
10099 needed for an R_ARM_PC24 or similar reloc to a non-function sym
10100 in check_relocs. We can't decide accurately between function
10101 and non-function syms in check-relocs; Objects loaded later in
10102 the link may change h->type. So fix it now. */
10103 h->plt.offset = (bfd_vma) -1;
10104 eh->plt_thumb_refcount = 0;
bd97cb95 10105 eh->plt_maybe_thumb_refcount = 0;
b7693d02 10106 }
252b5132
RH
10107
10108 /* If this is a weak symbol, and there is a real definition, the
10109 processor independent code will have arranged for us to see the
10110 real definition first, and we can just use the same value. */
f6e332e6 10111 if (h->u.weakdef != NULL)
252b5132 10112 {
f6e332e6
AM
10113 BFD_ASSERT (h->u.weakdef->root.type == bfd_link_hash_defined
10114 || h->u.weakdef->root.type == bfd_link_hash_defweak);
10115 h->root.u.def.section = h->u.weakdef->root.u.def.section;
10116 h->root.u.def.value = h->u.weakdef->root.u.def.value;
b34976b6 10117 return TRUE;
252b5132
RH
10118 }
10119
ba93b8ac
DJ
10120 /* If there are no non-GOT references, we do not need a copy
10121 relocation. */
10122 if (!h->non_got_ref)
10123 return TRUE;
10124
252b5132
RH
10125 /* This is a reference to a symbol defined by a dynamic object which
10126 is not a function. */
10127
10128 /* If we are creating a shared library, we must presume that the
10129 only references to the symbol are via the global offset table.
10130 For such cases we need not do anything here; the relocations will
67687978
PB
10131 be handled correctly by relocate_section. Relocatable executables
10132 can reference data in shared objects directly, so we don't need to
10133 do anything here. */
10134 if (info->shared || globals->root.is_relocatable_executable)
b34976b6 10135 return TRUE;
252b5132 10136
909272ee
AM
10137 if (h->size == 0)
10138 {
10139 (*_bfd_error_handler) (_("dynamic variable `%s' is zero size"),
10140 h->root.root.string);
10141 return TRUE;
10142 }
10143
252b5132
RH
10144 /* We must allocate the symbol in our .dynbss section, which will
10145 become part of the .bss section of the executable. There will be
10146 an entry for this symbol in the .dynsym section. The dynamic
10147 object will contain position independent code, so all references
10148 from the dynamic object to this symbol will go through the global
10149 offset table. The dynamic linker will use the .dynsym entry to
10150 determine the address it must put in the global offset table, so
10151 both the dynamic object and the regular object will refer to the
10152 same memory location for the variable. */
252b5132
RH
10153 s = bfd_get_section_by_name (dynobj, ".dynbss");
10154 BFD_ASSERT (s != NULL);
10155
10156 /* We must generate a R_ARM_COPY reloc to tell the dynamic linker to
10157 copy the initial value out of the dynamic object and into the
10158 runtime process image. We need to remember the offset into the
00a97672 10159 .rel(a).bss section we are going to use. */
252b5132
RH
10160 if ((h->root.u.def.section->flags & SEC_ALLOC) != 0)
10161 {
10162 asection *srel;
10163
00a97672 10164 srel = bfd_get_section_by_name (dynobj, RELOC_SECTION (globals, ".bss"));
252b5132 10165 BFD_ASSERT (srel != NULL);
00a97672 10166 srel->size += RELOC_SIZE (globals);
f5385ebf 10167 h->needs_copy = 1;
252b5132
RH
10168 }
10169
027297b7 10170 return _bfd_elf_adjust_dynamic_copy (h, s);
252b5132
RH
10171}
10172
5e681ec4
PB
10173/* Allocate space in .plt, .got and associated reloc sections for
10174 dynamic relocs. */
10175
10176static bfd_boolean
57e8b36a 10177allocate_dynrelocs (struct elf_link_hash_entry *h, void * inf)
5e681ec4
PB
10178{
10179 struct bfd_link_info *info;
10180 struct elf32_arm_link_hash_table *htab;
10181 struct elf32_arm_link_hash_entry *eh;
10182 struct elf32_arm_relocs_copied *p;
bd97cb95 10183 bfd_signed_vma thumb_refs;
5e681ec4 10184
b7693d02
DJ
10185 eh = (struct elf32_arm_link_hash_entry *) h;
10186
5e681ec4
PB
10187 if (h->root.type == bfd_link_hash_indirect)
10188 return TRUE;
10189
10190 if (h->root.type == bfd_link_hash_warning)
10191 /* When warning symbols are created, they **replace** the "real"
10192 entry in the hash table, thus we never get to see the real
10193 symbol in a hash traversal. So look at it now. */
10194 h = (struct elf_link_hash_entry *) h->root.u.i.link;
10195
10196 info = (struct bfd_link_info *) inf;
10197 htab = elf32_arm_hash_table (info);
10198
10199 if (htab->root.dynamic_sections_created
10200 && h->plt.refcount > 0)
10201 {
10202 /* Make sure this symbol is output as a dynamic symbol.
10203 Undefined weak syms won't yet be marked as dynamic. */
10204 if (h->dynindx == -1
f5385ebf 10205 && !h->forced_local)
5e681ec4 10206 {
c152c796 10207 if (! bfd_elf_link_record_dynamic_symbol (info, h))
5e681ec4
PB
10208 return FALSE;
10209 }
10210
10211 if (info->shared
7359ea65 10212 || WILL_CALL_FINISH_DYNAMIC_SYMBOL (1, 0, h))
5e681ec4
PB
10213 {
10214 asection *s = htab->splt;
10215
10216 /* If this is the first .plt entry, make room for the special
10217 first entry. */
eea6121a 10218 if (s->size == 0)
e5a52504 10219 s->size += htab->plt_header_size;
5e681ec4 10220
eea6121a 10221 h->plt.offset = s->size;
5e681ec4 10222
b7693d02
DJ
10223 /* If we will insert a Thumb trampoline before this PLT, leave room
10224 for it. */
bd97cb95
DJ
10225 thumb_refs = eh->plt_thumb_refcount;
10226 if (!htab->use_blx)
10227 thumb_refs += eh->plt_maybe_thumb_refcount;
10228
10229 if (thumb_refs > 0)
b7693d02
DJ
10230 {
10231 h->plt.offset += PLT_THUMB_STUB_SIZE;
10232 s->size += PLT_THUMB_STUB_SIZE;
10233 }
10234
5e681ec4
PB
10235 /* If this symbol is not defined in a regular file, and we are
10236 not generating a shared library, then set the symbol to this
10237 location in the .plt. This is required to make function
10238 pointers compare as equal between the normal executable and
10239 the shared library. */
10240 if (! info->shared
f5385ebf 10241 && !h->def_regular)
5e681ec4
PB
10242 {
10243 h->root.u.def.section = s;
10244 h->root.u.def.value = h->plt.offset;
b7693d02
DJ
10245
10246 /* Make sure the function is not marked as Thumb, in case
10247 it is the target of an ABS32 relocation, which will
10248 point to the PLT entry. */
10249 if (ELF_ST_TYPE (h->type) == STT_ARM_TFUNC)
10250 h->type = ELF_ST_INFO (ELF_ST_BIND (h->type), STT_FUNC);
5e681ec4
PB
10251 }
10252
10253 /* Make room for this entry. */
e5a52504 10254 s->size += htab->plt_entry_size;
5e681ec4 10255
e5a52504 10256 if (!htab->symbian_p)
b7693d02
DJ
10257 {
10258 /* We also need to make an entry in the .got.plt section, which
10259 will be placed in the .got section by the linker script. */
10260 eh->plt_got_offset = htab->sgotplt->size;
10261 htab->sgotplt->size += 4;
10262 }
5e681ec4 10263
00a97672
RS
10264 /* We also need to make an entry in the .rel(a).plt section. */
10265 htab->srelplt->size += RELOC_SIZE (htab);
10266
10267 /* VxWorks executables have a second set of relocations for
10268 each PLT entry. They go in a separate relocation section,
10269 which is processed by the kernel loader. */
10270 if (htab->vxworks_p && !info->shared)
10271 {
10272 /* There is a relocation for the initial PLT entry:
10273 an R_ARM_32 relocation for _GLOBAL_OFFSET_TABLE_. */
10274 if (h->plt.offset == htab->plt_header_size)
10275 htab->srelplt2->size += RELOC_SIZE (htab);
10276
10277 /* There are two extra relocations for each subsequent
10278 PLT entry: an R_ARM_32 relocation for the GOT entry,
10279 and an R_ARM_32 relocation for the PLT entry. */
10280 htab->srelplt2->size += RELOC_SIZE (htab) * 2;
10281 }
5e681ec4
PB
10282 }
10283 else
10284 {
10285 h->plt.offset = (bfd_vma) -1;
f5385ebf 10286 h->needs_plt = 0;
5e681ec4
PB
10287 }
10288 }
10289 else
10290 {
10291 h->plt.offset = (bfd_vma) -1;
f5385ebf 10292 h->needs_plt = 0;
5e681ec4
PB
10293 }
10294
10295 if (h->got.refcount > 0)
10296 {
10297 asection *s;
10298 bfd_boolean dyn;
ba93b8ac
DJ
10299 int tls_type = elf32_arm_hash_entry (h)->tls_type;
10300 int indx;
5e681ec4
PB
10301
10302 /* Make sure this symbol is output as a dynamic symbol.
10303 Undefined weak syms won't yet be marked as dynamic. */
10304 if (h->dynindx == -1
f5385ebf 10305 && !h->forced_local)
5e681ec4 10306 {
c152c796 10307 if (! bfd_elf_link_record_dynamic_symbol (info, h))
5e681ec4
PB
10308 return FALSE;
10309 }
10310
e5a52504
MM
10311 if (!htab->symbian_p)
10312 {
10313 s = htab->sgot;
10314 h->got.offset = s->size;
ba93b8ac
DJ
10315
10316 if (tls_type == GOT_UNKNOWN)
10317 abort ();
10318
10319 if (tls_type == GOT_NORMAL)
10320 /* Non-TLS symbols need one GOT slot. */
10321 s->size += 4;
10322 else
10323 {
10324 if (tls_type & GOT_TLS_GD)
10325 /* R_ARM_TLS_GD32 needs 2 consecutive GOT slots. */
10326 s->size += 8;
10327 if (tls_type & GOT_TLS_IE)
10328 /* R_ARM_TLS_IE32 needs one GOT slot. */
10329 s->size += 4;
10330 }
10331
e5a52504 10332 dyn = htab->root.dynamic_sections_created;
ba93b8ac
DJ
10333
10334 indx = 0;
10335 if (WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn, info->shared, h)
10336 && (!info->shared
10337 || !SYMBOL_REFERENCES_LOCAL (info, h)))
10338 indx = h->dynindx;
10339
10340 if (tls_type != GOT_NORMAL
10341 && (info->shared || indx != 0)
10342 && (ELF_ST_VISIBILITY (h->other) == STV_DEFAULT
10343 || h->root.type != bfd_link_hash_undefweak))
10344 {
10345 if (tls_type & GOT_TLS_IE)
00a97672 10346 htab->srelgot->size += RELOC_SIZE (htab);
ba93b8ac
DJ
10347
10348 if (tls_type & GOT_TLS_GD)
00a97672 10349 htab->srelgot->size += RELOC_SIZE (htab);
ba93b8ac
DJ
10350
10351 if ((tls_type & GOT_TLS_GD) && indx != 0)
00a97672 10352 htab->srelgot->size += RELOC_SIZE (htab);
ba93b8ac
DJ
10353 }
10354 else if ((ELF_ST_VISIBILITY (h->other) == STV_DEFAULT
10355 || h->root.type != bfd_link_hash_undefweak)
10356 && (info->shared
10357 || WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn, 0, h)))
00a97672 10358 htab->srelgot->size += RELOC_SIZE (htab);
e5a52504 10359 }
5e681ec4
PB
10360 }
10361 else
10362 h->got.offset = (bfd_vma) -1;
10363
a4fd1a8e
PB
10364 /* Allocate stubs for exported Thumb functions on v4t. */
10365 if (!htab->use_blx && h->dynindx != -1
0eaedd0e 10366 && h->def_regular
a4fd1a8e
PB
10367 && ELF_ST_TYPE (h->type) == STT_ARM_TFUNC
10368 && ELF_ST_VISIBILITY (h->other) == STV_DEFAULT)
10369 {
10370 struct elf_link_hash_entry * th;
10371 struct bfd_link_hash_entry * bh;
10372 struct elf_link_hash_entry * myh;
10373 char name[1024];
10374 asection *s;
10375 bh = NULL;
10376 /* Create a new symbol to regist the real location of the function. */
10377 s = h->root.u.def.section;
906e58ca 10378 sprintf (name, "__real_%s", h->root.root.string);
a4fd1a8e
PB
10379 _bfd_generic_link_add_one_symbol (info, s->owner,
10380 name, BSF_GLOBAL, s,
10381 h->root.u.def.value,
10382 NULL, TRUE, FALSE, &bh);
10383
10384 myh = (struct elf_link_hash_entry *) bh;
10385 myh->type = ELF_ST_INFO (STB_LOCAL, STT_ARM_TFUNC);
10386 myh->forced_local = 1;
10387 eh->export_glue = myh;
10388 th = record_arm_to_thumb_glue (info, h);
10389 /* Point the symbol at the stub. */
10390 h->type = ELF_ST_INFO (ELF_ST_BIND (h->type), STT_FUNC);
10391 h->root.u.def.section = th->root.u.def.section;
10392 h->root.u.def.value = th->root.u.def.value & ~1;
10393 }
10394
5e681ec4
PB
10395 if (eh->relocs_copied == NULL)
10396 return TRUE;
10397
10398 /* In the shared -Bsymbolic case, discard space allocated for
10399 dynamic pc-relative relocs against symbols which turn out to be
10400 defined in regular objects. For the normal shared case, discard
10401 space for pc-relative relocs that have become local due to symbol
10402 visibility changes. */
10403
67687978 10404 if (info->shared || htab->root.is_relocatable_executable)
5e681ec4 10405 {
7bdca076 10406 /* The only relocs that use pc_count are R_ARM_REL32 and
bb224fc3
MS
10407 R_ARM_REL32_NOI, which will appear on something like
10408 ".long foo - .". We want calls to protected symbols to resolve
10409 directly to the function rather than going via the plt. If people
10410 want function pointer comparisons to work as expected then they
10411 should avoid writing assembly like ".long foo - .". */
ba93b8ac
DJ
10412 if (SYMBOL_CALLS_LOCAL (info, h))
10413 {
10414 struct elf32_arm_relocs_copied **pp;
10415
10416 for (pp = &eh->relocs_copied; (p = *pp) != NULL; )
10417 {
10418 p->count -= p->pc_count;
10419 p->pc_count = 0;
10420 if (p->count == 0)
10421 *pp = p->next;
10422 else
10423 pp = &p->next;
10424 }
10425 }
10426
3348747a
NS
10427 if (elf32_arm_hash_table (info)->vxworks_p)
10428 {
10429 struct elf32_arm_relocs_copied **pp;
10430
10431 for (pp = &eh->relocs_copied; (p = *pp) != NULL; )
10432 {
10433 if (strcmp (p->section->output_section->name, ".tls_vars") == 0)
10434 *pp = p->next;
10435 else
10436 pp = &p->next;
10437 }
10438 }
10439
ba93b8ac 10440 /* Also discard relocs on undefined weak syms with non-default
7359ea65 10441 visibility. */
22d606e9 10442 if (eh->relocs_copied != NULL
5e681ec4 10443 && h->root.type == bfd_link_hash_undefweak)
22d606e9
AM
10444 {
10445 if (ELF_ST_VISIBILITY (h->other) != STV_DEFAULT)
10446 eh->relocs_copied = NULL;
10447
10448 /* Make sure undefined weak symbols are output as a dynamic
10449 symbol in PIEs. */
10450 else if (h->dynindx == -1
10451 && !h->forced_local)
10452 {
10453 if (! bfd_elf_link_record_dynamic_symbol (info, h))
10454 return FALSE;
10455 }
10456 }
10457
67687978
PB
10458 else if (htab->root.is_relocatable_executable && h->dynindx == -1
10459 && h->root.type == bfd_link_hash_new)
10460 {
10461 /* Output absolute symbols so that we can create relocations
10462 against them. For normal symbols we output a relocation
10463 against the section that contains them. */
10464 if (! bfd_elf_link_record_dynamic_symbol (info, h))
10465 return FALSE;
10466 }
10467
5e681ec4
PB
10468 }
10469 else
10470 {
10471 /* For the non-shared case, discard space for relocs against
10472 symbols which turn out to need copy relocs or are not
10473 dynamic. */
10474
f5385ebf
AM
10475 if (!h->non_got_ref
10476 && ((h->def_dynamic
10477 && !h->def_regular)
5e681ec4
PB
10478 || (htab->root.dynamic_sections_created
10479 && (h->root.type == bfd_link_hash_undefweak
10480 || h->root.type == bfd_link_hash_undefined))))
10481 {
10482 /* Make sure this symbol is output as a dynamic symbol.
10483 Undefined weak syms won't yet be marked as dynamic. */
10484 if (h->dynindx == -1
f5385ebf 10485 && !h->forced_local)
5e681ec4 10486 {
c152c796 10487 if (! bfd_elf_link_record_dynamic_symbol (info, h))
5e681ec4
PB
10488 return FALSE;
10489 }
10490
10491 /* If that succeeded, we know we'll be keeping all the
10492 relocs. */
10493 if (h->dynindx != -1)
10494 goto keep;
10495 }
10496
10497 eh->relocs_copied = NULL;
10498
10499 keep: ;
10500 }
10501
10502 /* Finally, allocate space. */
10503 for (p = eh->relocs_copied; p != NULL; p = p->next)
10504 {
10505 asection *sreloc = elf_section_data (p->section)->sreloc;
00a97672 10506 sreloc->size += p->count * RELOC_SIZE (htab);
5e681ec4
PB
10507 }
10508
10509 return TRUE;
10510}
10511
08d1f311
DJ
10512/* Find any dynamic relocs that apply to read-only sections. */
10513
10514static bfd_boolean
8029a119 10515elf32_arm_readonly_dynrelocs (struct elf_link_hash_entry * h, void * inf)
08d1f311 10516{
8029a119
NC
10517 struct elf32_arm_link_hash_entry * eh;
10518 struct elf32_arm_relocs_copied * p;
08d1f311
DJ
10519
10520 if (h->root.type == bfd_link_hash_warning)
10521 h = (struct elf_link_hash_entry *) h->root.u.i.link;
10522
10523 eh = (struct elf32_arm_link_hash_entry *) h;
10524 for (p = eh->relocs_copied; p != NULL; p = p->next)
10525 {
10526 asection *s = p->section;
10527
10528 if (s != NULL && (s->flags & SEC_READONLY) != 0)
10529 {
10530 struct bfd_link_info *info = (struct bfd_link_info *) inf;
10531
10532 info->flags |= DF_TEXTREL;
10533
10534 /* Not an error, just cut short the traversal. */
10535 return FALSE;
10536 }
10537 }
10538 return TRUE;
10539}
10540
d504ffc8
DJ
10541void
10542bfd_elf32_arm_set_byteswap_code (struct bfd_link_info *info,
10543 int byteswap_code)
10544{
10545 struct elf32_arm_link_hash_table *globals;
10546
10547 globals = elf32_arm_hash_table (info);
10548 globals->byteswap_code = byteswap_code;
10549}
10550
252b5132
RH
10551/* Set the sizes of the dynamic sections. */
10552
b34976b6 10553static bfd_boolean
57e8b36a
NC
10554elf32_arm_size_dynamic_sections (bfd * output_bfd ATTRIBUTE_UNUSED,
10555 struct bfd_link_info * info)
252b5132
RH
10556{
10557 bfd * dynobj;
10558 asection * s;
b34976b6
AM
10559 bfd_boolean plt;
10560 bfd_boolean relocs;
5e681ec4
PB
10561 bfd *ibfd;
10562 struct elf32_arm_link_hash_table *htab;
252b5132 10563
5e681ec4 10564 htab = elf32_arm_hash_table (info);
252b5132
RH
10565 dynobj = elf_hash_table (info)->dynobj;
10566 BFD_ASSERT (dynobj != NULL);
39b41c9c 10567 check_use_blx (htab);
252b5132
RH
10568
10569 if (elf_hash_table (info)->dynamic_sections_created)
10570 {
10571 /* Set the contents of the .interp section to the interpreter. */
893c4fe2 10572 if (info->executable)
252b5132
RH
10573 {
10574 s = bfd_get_section_by_name (dynobj, ".interp");
10575 BFD_ASSERT (s != NULL);
eea6121a 10576 s->size = sizeof ELF_DYNAMIC_INTERPRETER;
252b5132
RH
10577 s->contents = (unsigned char *) ELF_DYNAMIC_INTERPRETER;
10578 }
10579 }
5e681ec4
PB
10580
10581 /* Set up .got offsets for local syms, and space for local dynamic
10582 relocs. */
10583 for (ibfd = info->input_bfds; ibfd != NULL; ibfd = ibfd->link_next)
252b5132 10584 {
5e681ec4
PB
10585 bfd_signed_vma *local_got;
10586 bfd_signed_vma *end_local_got;
10587 char *local_tls_type;
10588 bfd_size_type locsymcount;
10589 Elf_Internal_Shdr *symtab_hdr;
10590 asection *srel;
3348747a 10591 bfd_boolean is_vxworks = elf32_arm_hash_table (info)->vxworks_p;
5e681ec4 10592
0ffa91dd 10593 if (! is_arm_elf (ibfd))
5e681ec4
PB
10594 continue;
10595
10596 for (s = ibfd->sections; s != NULL; s = s->next)
10597 {
10598 struct elf32_arm_relocs_copied *p;
10599
6edfbbad 10600 for (p = elf_section_data (s)->local_dynrel; p != NULL; p = p->next)
5e681ec4
PB
10601 {
10602 if (!bfd_is_abs_section (p->section)
10603 && bfd_is_abs_section (p->section->output_section))
10604 {
10605 /* Input section has been discarded, either because
10606 it is a copy of a linkonce section or due to
10607 linker script /DISCARD/, so we'll be discarding
10608 the relocs too. */
10609 }
3348747a
NS
10610 else if (is_vxworks
10611 && strcmp (p->section->output_section->name,
10612 ".tls_vars") == 0)
10613 {
10614 /* Relocations in vxworks .tls_vars sections are
10615 handled specially by the loader. */
10616 }
5e681ec4
PB
10617 else if (p->count != 0)
10618 {
10619 srel = elf_section_data (p->section)->sreloc;
00a97672 10620 srel->size += p->count * RELOC_SIZE (htab);
5e681ec4
PB
10621 if ((p->section->output_section->flags & SEC_READONLY) != 0)
10622 info->flags |= DF_TEXTREL;
10623 }
10624 }
10625 }
10626
10627 local_got = elf_local_got_refcounts (ibfd);
10628 if (!local_got)
10629 continue;
10630
0ffa91dd 10631 symtab_hdr = & elf_symtab_hdr (ibfd);
5e681ec4
PB
10632 locsymcount = symtab_hdr->sh_info;
10633 end_local_got = local_got + locsymcount;
ba93b8ac 10634 local_tls_type = elf32_arm_local_got_tls_type (ibfd);
5e681ec4
PB
10635 s = htab->sgot;
10636 srel = htab->srelgot;
10637 for (; local_got < end_local_got; ++local_got, ++local_tls_type)
10638 {
10639 if (*local_got > 0)
10640 {
eea6121a 10641 *local_got = s->size;
ba93b8ac
DJ
10642 if (*local_tls_type & GOT_TLS_GD)
10643 /* TLS_GD relocs need an 8-byte structure in the GOT. */
10644 s->size += 8;
10645 if (*local_tls_type & GOT_TLS_IE)
10646 s->size += 4;
10647 if (*local_tls_type == GOT_NORMAL)
10648 s->size += 4;
10649
10650 if (info->shared || *local_tls_type == GOT_TLS_GD)
00a97672 10651 srel->size += RELOC_SIZE (htab);
5e681ec4
PB
10652 }
10653 else
10654 *local_got = (bfd_vma) -1;
10655 }
252b5132
RH
10656 }
10657
ba93b8ac
DJ
10658 if (htab->tls_ldm_got.refcount > 0)
10659 {
10660 /* Allocate two GOT entries and one dynamic relocation (if necessary)
10661 for R_ARM_TLS_LDM32 relocations. */
10662 htab->tls_ldm_got.offset = htab->sgot->size;
10663 htab->sgot->size += 8;
10664 if (info->shared)
00a97672 10665 htab->srelgot->size += RELOC_SIZE (htab);
ba93b8ac
DJ
10666 }
10667 else
10668 htab->tls_ldm_got.offset = -1;
10669
5e681ec4
PB
10670 /* Allocate global sym .plt and .got entries, and space for global
10671 sym dynamic relocs. */
57e8b36a 10672 elf_link_hash_traverse (& htab->root, allocate_dynrelocs, info);
252b5132 10673
d504ffc8
DJ
10674 /* Here we rummage through the found bfds to collect glue information. */
10675 for (ibfd = info->input_bfds; ibfd != NULL; ibfd = ibfd->link_next)
c7b8f16e 10676 {
0ffa91dd 10677 if (! is_arm_elf (ibfd))
e44a2c9c
AM
10678 continue;
10679
c7b8f16e
JB
10680 /* Initialise mapping tables for code/data. */
10681 bfd_elf32_arm_init_maps (ibfd);
906e58ca 10682
c7b8f16e
JB
10683 if (!bfd_elf32_arm_process_before_allocation (ibfd, info)
10684 || !bfd_elf32_arm_vfp11_erratum_scan (ibfd, info))
10685 /* xgettext:c-format */
10686 _bfd_error_handler (_("Errors encountered processing file %s"),
10687 ibfd->filename);
10688 }
d504ffc8 10689
252b5132
RH
10690 /* The check_relocs and adjust_dynamic_symbol entry points have
10691 determined the sizes of the various dynamic sections. Allocate
10692 memory for them. */
b34976b6
AM
10693 plt = FALSE;
10694 relocs = FALSE;
252b5132
RH
10695 for (s = dynobj->sections; s != NULL; s = s->next)
10696 {
10697 const char * name;
252b5132
RH
10698
10699 if ((s->flags & SEC_LINKER_CREATED) == 0)
10700 continue;
10701
10702 /* It's OK to base decisions on the section name, because none
10703 of the dynobj section names depend upon the input files. */
10704 name = bfd_get_section_name (dynobj, s);
10705
24a1ba0f 10706 if (strcmp (name, ".plt") == 0)
252b5132 10707 {
c456f082
AM
10708 /* Remember whether there is a PLT. */
10709 plt = s->size != 0;
252b5132 10710 }
0112cd26 10711 else if (CONST_STRNEQ (name, ".rel"))
252b5132 10712 {
c456f082 10713 if (s->size != 0)
252b5132 10714 {
252b5132 10715 /* Remember whether there are any reloc sections other
00a97672
RS
10716 than .rel(a).plt and .rela.plt.unloaded. */
10717 if (s != htab->srelplt && s != htab->srelplt2)
b34976b6 10718 relocs = TRUE;
252b5132
RH
10719
10720 /* We use the reloc_count field as a counter if we need
10721 to copy relocs into the output file. */
10722 s->reloc_count = 0;
10723 }
10724 }
0112cd26 10725 else if (! CONST_STRNEQ (name, ".got")
c456f082 10726 && strcmp (name, ".dynbss") != 0)
252b5132
RH
10727 {
10728 /* It's not one of our sections, so don't allocate space. */
10729 continue;
10730 }
10731
c456f082 10732 if (s->size == 0)
252b5132 10733 {
c456f082 10734 /* If we don't need this section, strip it from the
00a97672
RS
10735 output file. This is mostly to handle .rel(a).bss and
10736 .rel(a).plt. We must create both sections in
c456f082
AM
10737 create_dynamic_sections, because they must be created
10738 before the linker maps input sections to output
10739 sections. The linker does that before
10740 adjust_dynamic_symbol is called, and it is that
10741 function which decides whether anything needs to go
10742 into these sections. */
8423293d 10743 s->flags |= SEC_EXCLUDE;
252b5132
RH
10744 continue;
10745 }
10746
c456f082
AM
10747 if ((s->flags & SEC_HAS_CONTENTS) == 0)
10748 continue;
10749
252b5132 10750 /* Allocate memory for the section contents. */
906e58ca 10751 s->contents = bfd_zalloc (dynobj, s->size);
c456f082 10752 if (s->contents == NULL)
b34976b6 10753 return FALSE;
252b5132
RH
10754 }
10755
10756 if (elf_hash_table (info)->dynamic_sections_created)
10757 {
10758 /* Add some entries to the .dynamic section. We fill in the
10759 values later, in elf32_arm_finish_dynamic_sections, but we
10760 must add the entries now so that we get the correct size for
10761 the .dynamic section. The DT_DEBUG entry is filled in by the
10762 dynamic linker and used by the debugger. */
dc810e39 10763#define add_dynamic_entry(TAG, VAL) \
5a580b3a 10764 _bfd_elf_add_dynamic_entry (info, TAG, VAL)
dc810e39 10765
8532796c 10766 if (info->executable)
252b5132 10767 {
dc810e39 10768 if (!add_dynamic_entry (DT_DEBUG, 0))
b34976b6 10769 return FALSE;
252b5132
RH
10770 }
10771
10772 if (plt)
10773 {
dc810e39
AM
10774 if ( !add_dynamic_entry (DT_PLTGOT, 0)
10775 || !add_dynamic_entry (DT_PLTRELSZ, 0)
00a97672
RS
10776 || !add_dynamic_entry (DT_PLTREL,
10777 htab->use_rel ? DT_REL : DT_RELA)
dc810e39 10778 || !add_dynamic_entry (DT_JMPREL, 0))
b34976b6 10779 return FALSE;
252b5132
RH
10780 }
10781
10782 if (relocs)
10783 {
00a97672
RS
10784 if (htab->use_rel)
10785 {
10786 if (!add_dynamic_entry (DT_REL, 0)
10787 || !add_dynamic_entry (DT_RELSZ, 0)
10788 || !add_dynamic_entry (DT_RELENT, RELOC_SIZE (htab)))
10789 return FALSE;
10790 }
10791 else
10792 {
10793 if (!add_dynamic_entry (DT_RELA, 0)
10794 || !add_dynamic_entry (DT_RELASZ, 0)
10795 || !add_dynamic_entry (DT_RELAENT, RELOC_SIZE (htab)))
10796 return FALSE;
10797 }
252b5132
RH
10798 }
10799
08d1f311
DJ
10800 /* If any dynamic relocs apply to a read-only section,
10801 then we need a DT_TEXTREL entry. */
10802 if ((info->flags & DF_TEXTREL) == 0)
8029a119
NC
10803 elf_link_hash_traverse (& htab->root, elf32_arm_readonly_dynrelocs,
10804 info);
08d1f311 10805
99e4ae17 10806 if ((info->flags & DF_TEXTREL) != 0)
252b5132 10807 {
dc810e39 10808 if (!add_dynamic_entry (DT_TEXTREL, 0))
b34976b6 10809 return FALSE;
252b5132 10810 }
7a2b07ff
NS
10811 if (htab->vxworks_p
10812 && !elf_vxworks_add_dynamic_entries (output_bfd, info))
10813 return FALSE;
252b5132 10814 }
8532796c 10815#undef add_dynamic_entry
252b5132 10816
b34976b6 10817 return TRUE;
252b5132
RH
10818}
10819
252b5132
RH
10820/* Finish up dynamic symbol handling. We set the contents of various
10821 dynamic sections here. */
10822
b34976b6 10823static bfd_boolean
906e58ca
NC
10824elf32_arm_finish_dynamic_symbol (bfd * output_bfd,
10825 struct bfd_link_info * info,
10826 struct elf_link_hash_entry * h,
10827 Elf_Internal_Sym * sym)
252b5132
RH
10828{
10829 bfd * dynobj;
e5a52504 10830 struct elf32_arm_link_hash_table *htab;
b7693d02 10831 struct elf32_arm_link_hash_entry *eh;
252b5132
RH
10832
10833 dynobj = elf_hash_table (info)->dynobj;
e5a52504 10834 htab = elf32_arm_hash_table (info);
b7693d02 10835 eh = (struct elf32_arm_link_hash_entry *) h;
252b5132
RH
10836
10837 if (h->plt.offset != (bfd_vma) -1)
10838 {
10839 asection * splt;
252b5132 10840 asection * srel;
e5a52504 10841 bfd_byte *loc;
24a1ba0f 10842 bfd_vma plt_index;
947216bf 10843 Elf_Internal_Rela rel;
252b5132
RH
10844
10845 /* This symbol has an entry in the procedure linkage table. Set
10846 it up. */
10847
10848 BFD_ASSERT (h->dynindx != -1);
10849
10850 splt = bfd_get_section_by_name (dynobj, ".plt");
00a97672 10851 srel = bfd_get_section_by_name (dynobj, RELOC_SECTION (htab, ".plt"));
e5a52504 10852 BFD_ASSERT (splt != NULL && srel != NULL);
252b5132 10853
e5a52504
MM
10854 /* Fill in the entry in the procedure linkage table. */
10855 if (htab->symbian_p)
10856 {
906e58ca 10857 put_arm_insn (htab, output_bfd,
52ab56c2
PB
10858 elf32_arm_symbian_plt_entry[0],
10859 splt->contents + h->plt.offset);
906e58ca 10860 bfd_put_32 (output_bfd,
52ab56c2
PB
10861 elf32_arm_symbian_plt_entry[1],
10862 splt->contents + h->plt.offset + 4);
906e58ca 10863
e5a52504 10864 /* Fill in the entry in the .rel.plt section. */
2a1b9a48
MM
10865 rel.r_offset = (splt->output_section->vma
10866 + splt->output_offset
52ab56c2 10867 + h->plt.offset + 4);
e5a52504 10868 rel.r_info = ELF32_R_INFO (h->dynindx, R_ARM_GLOB_DAT);
b7693d02
DJ
10869
10870 /* Get the index in the procedure linkage table which
10871 corresponds to this symbol. This is the index of this symbol
10872 in all the symbols for which we are making plt entries. The
10873 first entry in the procedure linkage table is reserved. */
906e58ca 10874 plt_index = ((h->plt.offset - htab->plt_header_size)
b7693d02 10875 / htab->plt_entry_size);
e5a52504
MM
10876 }
10877 else
10878 {
00a97672 10879 bfd_vma got_offset, got_address, plt_address;
e5a52504
MM
10880 bfd_vma got_displacement;
10881 asection * sgot;
52ab56c2 10882 bfd_byte * ptr;
906e58ca 10883
e5a52504
MM
10884 sgot = bfd_get_section_by_name (dynobj, ".got.plt");
10885 BFD_ASSERT (sgot != NULL);
10886
b7693d02
DJ
10887 /* Get the offset into the .got.plt table of the entry that
10888 corresponds to this function. */
10889 got_offset = eh->plt_got_offset;
10890
10891 /* Get the index in the procedure linkage table which
10892 corresponds to this symbol. This is the index of this symbol
10893 in all the symbols for which we are making plt entries. The
10894 first three entries in .got.plt are reserved; after that
10895 symbols appear in the same order as in .plt. */
10896 plt_index = (got_offset - 12) / 4;
e5a52504 10897
00a97672
RS
10898 /* Calculate the address of the GOT entry. */
10899 got_address = (sgot->output_section->vma
10900 + sgot->output_offset
10901 + got_offset);
5e681ec4 10902
00a97672
RS
10903 /* ...and the address of the PLT entry. */
10904 plt_address = (splt->output_section->vma
10905 + splt->output_offset
10906 + h->plt.offset);
5e681ec4 10907
52ab56c2 10908 ptr = htab->splt->contents + h->plt.offset;
00a97672
RS
10909 if (htab->vxworks_p && info->shared)
10910 {
10911 unsigned int i;
10912 bfd_vma val;
10913
52ab56c2 10914 for (i = 0; i != htab->plt_entry_size / 4; i++, ptr += 4)
00a97672
RS
10915 {
10916 val = elf32_arm_vxworks_shared_plt_entry[i];
10917 if (i == 2)
10918 val |= got_address - sgot->output_section->vma;
10919 if (i == 5)
10920 val |= plt_index * RELOC_SIZE (htab);
52ab56c2
PB
10921 if (i == 2 || i == 5)
10922 bfd_put_32 (output_bfd, val, ptr);
10923 else
10924 put_arm_insn (htab, output_bfd, val, ptr);
00a97672
RS
10925 }
10926 }
10927 else if (htab->vxworks_p)
b7693d02 10928 {
00a97672
RS
10929 unsigned int i;
10930 bfd_vma val;
10931
d3753b85 10932 for (i = 0; i != htab->plt_entry_size / 4; i++, ptr += 4)
00a97672
RS
10933 {
10934 val = elf32_arm_vxworks_exec_plt_entry[i];
10935 if (i == 2)
10936 val |= got_address;
10937 if (i == 4)
10938 val |= 0xffffff & -((h->plt.offset + i * 4 + 8) >> 2);
10939 if (i == 5)
10940 val |= plt_index * RELOC_SIZE (htab);
52ab56c2
PB
10941 if (i == 2 || i == 5)
10942 bfd_put_32 (output_bfd, val, ptr);
10943 else
10944 put_arm_insn (htab, output_bfd, val, ptr);
00a97672
RS
10945 }
10946
10947 loc = (htab->srelplt2->contents
10948 + (plt_index * 2 + 1) * RELOC_SIZE (htab));
10949
10950 /* Create the .rela.plt.unloaded R_ARM_ABS32 relocation
10951 referencing the GOT for this PLT entry. */
10952 rel.r_offset = plt_address + 8;
10953 rel.r_info = ELF32_R_INFO (htab->root.hgot->indx, R_ARM_ABS32);
10954 rel.r_addend = got_offset;
10955 SWAP_RELOC_OUT (htab) (output_bfd, &rel, loc);
10956 loc += RELOC_SIZE (htab);
10957
10958 /* Create the R_ARM_ABS32 relocation referencing the
10959 beginning of the PLT for this GOT entry. */
10960 rel.r_offset = got_address;
10961 rel.r_info = ELF32_R_INFO (htab->root.hplt->indx, R_ARM_ABS32);
10962 rel.r_addend = 0;
10963 SWAP_RELOC_OUT (htab) (output_bfd, &rel, loc);
b7693d02 10964 }
00a97672
RS
10965 else
10966 {
bd97cb95 10967 bfd_signed_vma thumb_refs;
00a97672
RS
10968 /* Calculate the displacement between the PLT slot and the
10969 entry in the GOT. The eight-byte offset accounts for the
10970 value produced by adding to pc in the first instruction
10971 of the PLT stub. */
10972 got_displacement = got_address - (plt_address + 8);
b7693d02 10973
00a97672
RS
10974 BFD_ASSERT ((got_displacement & 0xf0000000) == 0);
10975
bd97cb95
DJ
10976 thumb_refs = eh->plt_thumb_refcount;
10977 if (!htab->use_blx)
10978 thumb_refs += eh->plt_maybe_thumb_refcount;
10979
10980 if (thumb_refs > 0)
00a97672 10981 {
52ab56c2
PB
10982 put_thumb_insn (htab, output_bfd,
10983 elf32_arm_plt_thumb_stub[0], ptr - 4);
10984 put_thumb_insn (htab, output_bfd,
10985 elf32_arm_plt_thumb_stub[1], ptr - 2);
00a97672
RS
10986 }
10987
52ab56c2
PB
10988 put_arm_insn (htab, output_bfd,
10989 elf32_arm_plt_entry[0]
10990 | ((got_displacement & 0x0ff00000) >> 20),
10991 ptr + 0);
10992 put_arm_insn (htab, output_bfd,
10993 elf32_arm_plt_entry[1]
10994 | ((got_displacement & 0x000ff000) >> 12),
10995 ptr+ 4);
10996 put_arm_insn (htab, output_bfd,
10997 elf32_arm_plt_entry[2]
10998 | (got_displacement & 0x00000fff),
10999 ptr + 8);
5e681ec4 11000#ifdef FOUR_WORD_PLT
52ab56c2 11001 bfd_put_32 (output_bfd, elf32_arm_plt_entry[3], ptr + 12);
5e681ec4 11002#endif
00a97672 11003 }
252b5132 11004
e5a52504
MM
11005 /* Fill in the entry in the global offset table. */
11006 bfd_put_32 (output_bfd,
11007 (splt->output_section->vma
11008 + splt->output_offset),
11009 sgot->contents + got_offset);
906e58ca 11010
00a97672
RS
11011 /* Fill in the entry in the .rel(a).plt section. */
11012 rel.r_addend = 0;
11013 rel.r_offset = got_address;
e5a52504
MM
11014 rel.r_info = ELF32_R_INFO (h->dynindx, R_ARM_JUMP_SLOT);
11015 }
57e8b36a 11016
00a97672
RS
11017 loc = srel->contents + plt_index * RELOC_SIZE (htab);
11018 SWAP_RELOC_OUT (htab) (output_bfd, &rel, loc);
252b5132 11019
f5385ebf 11020 if (!h->def_regular)
252b5132
RH
11021 {
11022 /* Mark the symbol as undefined, rather than as defined in
11023 the .plt section. Leave the value alone. */
11024 sym->st_shndx = SHN_UNDEF;
d982ba73
PB
11025 /* If the symbol is weak, we do need to clear the value.
11026 Otherwise, the PLT entry would provide a definition for
11027 the symbol even if the symbol wasn't defined anywhere,
11028 and so the symbol would never be NULL. */
f5385ebf 11029 if (!h->ref_regular_nonweak)
d982ba73 11030 sym->st_value = 0;
252b5132
RH
11031 }
11032 }
11033
ba93b8ac
DJ
11034 if (h->got.offset != (bfd_vma) -1
11035 && (elf32_arm_hash_entry (h)->tls_type & GOT_TLS_GD) == 0
11036 && (elf32_arm_hash_entry (h)->tls_type & GOT_TLS_IE) == 0)
252b5132
RH
11037 {
11038 asection * sgot;
11039 asection * srel;
947216bf
AM
11040 Elf_Internal_Rela rel;
11041 bfd_byte *loc;
00a97672 11042 bfd_vma offset;
252b5132
RH
11043
11044 /* This symbol has an entry in the global offset table. Set it
11045 up. */
252b5132 11046 sgot = bfd_get_section_by_name (dynobj, ".got");
00a97672 11047 srel = bfd_get_section_by_name (dynobj, RELOC_SECTION (htab, ".got"));
252b5132
RH
11048 BFD_ASSERT (sgot != NULL && srel != NULL);
11049
00a97672
RS
11050 offset = (h->got.offset & ~(bfd_vma) 1);
11051 rel.r_addend = 0;
252b5132
RH
11052 rel.r_offset = (sgot->output_section->vma
11053 + sgot->output_offset
00a97672 11054 + offset);
252b5132 11055
5e681ec4
PB
11056 /* If this is a static link, or it is a -Bsymbolic link and the
11057 symbol is defined locally or was forced to be local because
11058 of a version file, we just want to emit a RELATIVE reloc.
11059 The entry in the global offset table will already have been
11060 initialized in the relocate_section function. */
252b5132 11061 if (info->shared
5e681ec4
PB
11062 && SYMBOL_REFERENCES_LOCAL (info, h))
11063 {
906e58ca 11064 BFD_ASSERT ((h->got.offset & 1) != 0);
5e681ec4 11065 rel.r_info = ELF32_R_INFO (0, R_ARM_RELATIVE);
00a97672
RS
11066 if (!htab->use_rel)
11067 {
11068 rel.r_addend = bfd_get_32 (output_bfd, sgot->contents + offset);
11069 bfd_put_32 (output_bfd, (bfd_vma) 0, sgot->contents + offset);
11070 }
5e681ec4 11071 }
252b5132
RH
11072 else
11073 {
906e58ca 11074 BFD_ASSERT ((h->got.offset & 1) == 0);
00a97672 11075 bfd_put_32 (output_bfd, (bfd_vma) 0, sgot->contents + offset);
252b5132
RH
11076 rel.r_info = ELF32_R_INFO (h->dynindx, R_ARM_GLOB_DAT);
11077 }
11078
00a97672
RS
11079 loc = srel->contents + srel->reloc_count++ * RELOC_SIZE (htab);
11080 SWAP_RELOC_OUT (htab) (output_bfd, &rel, loc);
252b5132
RH
11081 }
11082
f5385ebf 11083 if (h->needs_copy)
252b5132
RH
11084 {
11085 asection * s;
947216bf
AM
11086 Elf_Internal_Rela rel;
11087 bfd_byte *loc;
252b5132
RH
11088
11089 /* This symbol needs a copy reloc. Set it up. */
252b5132
RH
11090 BFD_ASSERT (h->dynindx != -1
11091 && (h->root.type == bfd_link_hash_defined
11092 || h->root.type == bfd_link_hash_defweak));
11093
11094 s = bfd_get_section_by_name (h->root.u.def.section->owner,
00a97672 11095 RELOC_SECTION (htab, ".bss"));
252b5132
RH
11096 BFD_ASSERT (s != NULL);
11097
00a97672 11098 rel.r_addend = 0;
252b5132
RH
11099 rel.r_offset = (h->root.u.def.value
11100 + h->root.u.def.section->output_section->vma
11101 + h->root.u.def.section->output_offset);
11102 rel.r_info = ELF32_R_INFO (h->dynindx, R_ARM_COPY);
00a97672
RS
11103 loc = s->contents + s->reloc_count++ * RELOC_SIZE (htab);
11104 SWAP_RELOC_OUT (htab) (output_bfd, &rel, loc);
252b5132
RH
11105 }
11106
00a97672
RS
11107 /* Mark _DYNAMIC and _GLOBAL_OFFSET_TABLE_ as absolute. On VxWorks,
11108 the _GLOBAL_OFFSET_TABLE_ symbol is not absolute: it is relative
11109 to the ".got" section. */
252b5132 11110 if (strcmp (h->root.root.string, "_DYNAMIC") == 0
00a97672 11111 || (!htab->vxworks_p && h == htab->root.hgot))
252b5132
RH
11112 sym->st_shndx = SHN_ABS;
11113
b34976b6 11114 return TRUE;
252b5132
RH
11115}
11116
11117/* Finish up the dynamic sections. */
11118
b34976b6 11119static bfd_boolean
57e8b36a 11120elf32_arm_finish_dynamic_sections (bfd * output_bfd, struct bfd_link_info * info)
252b5132
RH
11121{
11122 bfd * dynobj;
11123 asection * sgot;
11124 asection * sdyn;
11125
11126 dynobj = elf_hash_table (info)->dynobj;
11127
11128 sgot = bfd_get_section_by_name (dynobj, ".got.plt");
229fcec5 11129 BFD_ASSERT (elf32_arm_hash_table (info)->symbian_p || sgot != NULL);
252b5132
RH
11130 sdyn = bfd_get_section_by_name (dynobj, ".dynamic");
11131
11132 if (elf_hash_table (info)->dynamic_sections_created)
11133 {
11134 asection *splt;
11135 Elf32_External_Dyn *dyncon, *dynconend;
229fcec5 11136 struct elf32_arm_link_hash_table *htab;
252b5132 11137
229fcec5 11138 htab = elf32_arm_hash_table (info);
252b5132 11139 splt = bfd_get_section_by_name (dynobj, ".plt");
24a1ba0f 11140 BFD_ASSERT (splt != NULL && sdyn != NULL);
252b5132
RH
11141
11142 dyncon = (Elf32_External_Dyn *) sdyn->contents;
eea6121a 11143 dynconend = (Elf32_External_Dyn *) (sdyn->contents + sdyn->size);
9b485d32 11144
252b5132
RH
11145 for (; dyncon < dynconend; dyncon++)
11146 {
11147 Elf_Internal_Dyn dyn;
11148 const char * name;
11149 asection * s;
11150
11151 bfd_elf32_swap_dyn_in (dynobj, dyncon, &dyn);
11152
11153 switch (dyn.d_tag)
11154 {
229fcec5
MM
11155 unsigned int type;
11156
252b5132 11157 default:
7a2b07ff
NS
11158 if (htab->vxworks_p
11159 && elf_vxworks_finish_dynamic_entry (output_bfd, &dyn))
11160 bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon);
252b5132
RH
11161 break;
11162
229fcec5
MM
11163 case DT_HASH:
11164 name = ".hash";
11165 goto get_vma_if_bpabi;
11166 case DT_STRTAB:
11167 name = ".dynstr";
11168 goto get_vma_if_bpabi;
11169 case DT_SYMTAB:
11170 name = ".dynsym";
11171 goto get_vma_if_bpabi;
c0042f5d
MM
11172 case DT_VERSYM:
11173 name = ".gnu.version";
11174 goto get_vma_if_bpabi;
11175 case DT_VERDEF:
11176 name = ".gnu.version_d";
11177 goto get_vma_if_bpabi;
11178 case DT_VERNEED:
11179 name = ".gnu.version_r";
11180 goto get_vma_if_bpabi;
11181
252b5132
RH
11182 case DT_PLTGOT:
11183 name = ".got";
11184 goto get_vma;
11185 case DT_JMPREL:
00a97672 11186 name = RELOC_SECTION (htab, ".plt");
252b5132
RH
11187 get_vma:
11188 s = bfd_get_section_by_name (output_bfd, name);
11189 BFD_ASSERT (s != NULL);
229fcec5
MM
11190 if (!htab->symbian_p)
11191 dyn.d_un.d_ptr = s->vma;
11192 else
11193 /* In the BPABI, tags in the PT_DYNAMIC section point
11194 at the file offset, not the memory address, for the
11195 convenience of the post linker. */
11196 dyn.d_un.d_ptr = s->filepos;
252b5132
RH
11197 bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon);
11198 break;
11199
229fcec5
MM
11200 get_vma_if_bpabi:
11201 if (htab->symbian_p)
11202 goto get_vma;
11203 break;
11204
252b5132 11205 case DT_PLTRELSZ:
00a97672
RS
11206 s = bfd_get_section_by_name (output_bfd,
11207 RELOC_SECTION (htab, ".plt"));
252b5132 11208 BFD_ASSERT (s != NULL);
eea6121a 11209 dyn.d_un.d_val = s->size;
252b5132
RH
11210 bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon);
11211 break;
906e58ca 11212
252b5132 11213 case DT_RELSZ:
00a97672 11214 case DT_RELASZ:
229fcec5
MM
11215 if (!htab->symbian_p)
11216 {
11217 /* My reading of the SVR4 ABI indicates that the
11218 procedure linkage table relocs (DT_JMPREL) should be
11219 included in the overall relocs (DT_REL). This is
11220 what Solaris does. However, UnixWare can not handle
11221 that case. Therefore, we override the DT_RELSZ entry
11222 here to make it not include the JMPREL relocs. Since
00a97672 11223 the linker script arranges for .rel(a).plt to follow all
229fcec5
MM
11224 other relocation sections, we don't have to worry
11225 about changing the DT_REL entry. */
00a97672
RS
11226 s = bfd_get_section_by_name (output_bfd,
11227 RELOC_SECTION (htab, ".plt"));
229fcec5
MM
11228 if (s != NULL)
11229 dyn.d_un.d_val -= s->size;
11230 bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon);
11231 break;
11232 }
8029a119 11233 /* Fall through. */
229fcec5
MM
11234
11235 case DT_REL:
11236 case DT_RELA:
229fcec5
MM
11237 /* In the BPABI, the DT_REL tag must point at the file
11238 offset, not the VMA, of the first relocation
11239 section. So, we use code similar to that in
11240 elflink.c, but do not check for SHF_ALLOC on the
11241 relcoation section, since relocations sections are
11242 never allocated under the BPABI. The comments above
11243 about Unixware notwithstanding, we include all of the
11244 relocations here. */
11245 if (htab->symbian_p)
11246 {
11247 unsigned int i;
11248 type = ((dyn.d_tag == DT_REL || dyn.d_tag == DT_RELSZ)
11249 ? SHT_REL : SHT_RELA);
11250 dyn.d_un.d_val = 0;
11251 for (i = 1; i < elf_numsections (output_bfd); i++)
11252 {
906e58ca 11253 Elf_Internal_Shdr *hdr
229fcec5
MM
11254 = elf_elfsections (output_bfd)[i];
11255 if (hdr->sh_type == type)
11256 {
906e58ca 11257 if (dyn.d_tag == DT_RELSZ
229fcec5
MM
11258 || dyn.d_tag == DT_RELASZ)
11259 dyn.d_un.d_val += hdr->sh_size;
de52dba4
AM
11260 else if ((ufile_ptr) hdr->sh_offset
11261 <= dyn.d_un.d_val - 1)
229fcec5
MM
11262 dyn.d_un.d_val = hdr->sh_offset;
11263 }
11264 }
11265 bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon);
11266 }
252b5132 11267 break;
88f7bcd5
NC
11268
11269 /* Set the bottom bit of DT_INIT/FINI if the
11270 corresponding function is Thumb. */
11271 case DT_INIT:
11272 name = info->init_function;
11273 goto get_sym;
11274 case DT_FINI:
11275 name = info->fini_function;
11276 get_sym:
11277 /* If it wasn't set by elf_bfd_final_link
4cc11e76 11278 then there is nothing to adjust. */
88f7bcd5
NC
11279 if (dyn.d_un.d_val != 0)
11280 {
11281 struct elf_link_hash_entry * eh;
11282
11283 eh = elf_link_hash_lookup (elf_hash_table (info), name,
b34976b6 11284 FALSE, FALSE, TRUE);
906e58ca 11285 if (eh != NULL
88f7bcd5
NC
11286 && ELF_ST_TYPE (eh->type) == STT_ARM_TFUNC)
11287 {
11288 dyn.d_un.d_val |= 1;
b34976b6 11289 bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon);
88f7bcd5
NC
11290 }
11291 }
11292 break;
252b5132
RH
11293 }
11294 }
11295
24a1ba0f 11296 /* Fill in the first entry in the procedure linkage table. */
e5a52504 11297 if (splt->size > 0 && elf32_arm_hash_table (info)->plt_header_size)
f7a74f8c 11298 {
00a97672
RS
11299 const bfd_vma *plt0_entry;
11300 bfd_vma got_address, plt_address, got_displacement;
11301
11302 /* Calculate the addresses of the GOT and PLT. */
11303 got_address = sgot->output_section->vma + sgot->output_offset;
11304 plt_address = splt->output_section->vma + splt->output_offset;
11305
11306 if (htab->vxworks_p)
11307 {
11308 /* The VxWorks GOT is relocated by the dynamic linker.
11309 Therefore, we must emit relocations rather than simply
11310 computing the values now. */
11311 Elf_Internal_Rela rel;
11312
11313 plt0_entry = elf32_arm_vxworks_exec_plt0_entry;
52ab56c2
PB
11314 put_arm_insn (htab, output_bfd, plt0_entry[0],
11315 splt->contents + 0);
11316 put_arm_insn (htab, output_bfd, plt0_entry[1],
11317 splt->contents + 4);
11318 put_arm_insn (htab, output_bfd, plt0_entry[2],
11319 splt->contents + 8);
00a97672
RS
11320 bfd_put_32 (output_bfd, got_address, splt->contents + 12);
11321
8029a119 11322 /* Generate a relocation for _GLOBAL_OFFSET_TABLE_. */
00a97672
RS
11323 rel.r_offset = plt_address + 12;
11324 rel.r_info = ELF32_R_INFO (htab->root.hgot->indx, R_ARM_ABS32);
11325 rel.r_addend = 0;
11326 SWAP_RELOC_OUT (htab) (output_bfd, &rel,
11327 htab->srelplt2->contents);
11328 }
11329 else
11330 {
11331 got_displacement = got_address - (plt_address + 16);
11332
11333 plt0_entry = elf32_arm_plt0_entry;
52ab56c2
PB
11334 put_arm_insn (htab, output_bfd, plt0_entry[0],
11335 splt->contents + 0);
11336 put_arm_insn (htab, output_bfd, plt0_entry[1],
11337 splt->contents + 4);
11338 put_arm_insn (htab, output_bfd, plt0_entry[2],
11339 splt->contents + 8);
11340 put_arm_insn (htab, output_bfd, plt0_entry[3],
11341 splt->contents + 12);
5e681ec4 11342
5e681ec4 11343#ifdef FOUR_WORD_PLT
00a97672
RS
11344 /* The displacement value goes in the otherwise-unused
11345 last word of the second entry. */
11346 bfd_put_32 (output_bfd, got_displacement, splt->contents + 28);
5e681ec4 11347#else
00a97672 11348 bfd_put_32 (output_bfd, got_displacement, splt->contents + 16);
5e681ec4 11349#endif
00a97672 11350 }
f7a74f8c 11351 }
252b5132
RH
11352
11353 /* UnixWare sets the entsize of .plt to 4, although that doesn't
11354 really seem like the right value. */
74541ad4
AM
11355 if (splt->output_section->owner == output_bfd)
11356 elf_section_data (splt->output_section)->this_hdr.sh_entsize = 4;
00a97672
RS
11357
11358 if (htab->vxworks_p && !info->shared && htab->splt->size > 0)
11359 {
11360 /* Correct the .rel(a).plt.unloaded relocations. They will have
11361 incorrect symbol indexes. */
11362 int num_plts;
eed62c48 11363 unsigned char *p;
00a97672
RS
11364
11365 num_plts = ((htab->splt->size - htab->plt_header_size)
11366 / htab->plt_entry_size);
11367 p = htab->srelplt2->contents + RELOC_SIZE (htab);
11368
11369 for (; num_plts; num_plts--)
11370 {
11371 Elf_Internal_Rela rel;
11372
11373 SWAP_RELOC_IN (htab) (output_bfd, p, &rel);
11374 rel.r_info = ELF32_R_INFO (htab->root.hgot->indx, R_ARM_ABS32);
11375 SWAP_RELOC_OUT (htab) (output_bfd, &rel, p);
11376 p += RELOC_SIZE (htab);
11377
11378 SWAP_RELOC_IN (htab) (output_bfd, p, &rel);
11379 rel.r_info = ELF32_R_INFO (htab->root.hplt->indx, R_ARM_ABS32);
11380 SWAP_RELOC_OUT (htab) (output_bfd, &rel, p);
11381 p += RELOC_SIZE (htab);
11382 }
11383 }
252b5132
RH
11384 }
11385
11386 /* Fill in the first three entries in the global offset table. */
229fcec5 11387 if (sgot)
252b5132 11388 {
229fcec5
MM
11389 if (sgot->size > 0)
11390 {
11391 if (sdyn == NULL)
11392 bfd_put_32 (output_bfd, (bfd_vma) 0, sgot->contents);
11393 else
11394 bfd_put_32 (output_bfd,
11395 sdyn->output_section->vma + sdyn->output_offset,
11396 sgot->contents);
11397 bfd_put_32 (output_bfd, (bfd_vma) 0, sgot->contents + 4);
11398 bfd_put_32 (output_bfd, (bfd_vma) 0, sgot->contents + 8);
11399 }
252b5132 11400
229fcec5
MM
11401 elf_section_data (sgot->output_section)->this_hdr.sh_entsize = 4;
11402 }
252b5132 11403
b34976b6 11404 return TRUE;
252b5132
RH
11405}
11406
ba96a88f 11407static void
57e8b36a 11408elf32_arm_post_process_headers (bfd * abfd, struct bfd_link_info * link_info ATTRIBUTE_UNUSED)
ba96a88f 11409{
9b485d32 11410 Elf_Internal_Ehdr * i_ehdrp; /* ELF file header, internal form. */
e489d0ae 11411 struct elf32_arm_link_hash_table *globals;
ba96a88f
NC
11412
11413 i_ehdrp = elf_elfheader (abfd);
11414
94a3258f
PB
11415 if (EF_ARM_EABI_VERSION (i_ehdrp->e_flags) == EF_ARM_EABI_UNKNOWN)
11416 i_ehdrp->e_ident[EI_OSABI] = ELFOSABI_ARM;
11417 else
11418 i_ehdrp->e_ident[EI_OSABI] = 0;
ba96a88f 11419 i_ehdrp->e_ident[EI_ABIVERSION] = ARM_ELF_ABI_VERSION;
e489d0ae 11420
93204d3a
PB
11421 if (link_info)
11422 {
11423 globals = elf32_arm_hash_table (link_info);
11424 if (globals->byteswap_code)
11425 i_ehdrp->e_flags |= EF_ARM_BE8;
11426 }
ba96a88f
NC
11427}
11428
99e4ae17 11429static enum elf_reloc_type_class
57e8b36a 11430elf32_arm_reloc_type_class (const Elf_Internal_Rela *rela)
99e4ae17 11431{
f51e552e 11432 switch ((int) ELF32_R_TYPE (rela->r_info))
99e4ae17
AJ
11433 {
11434 case R_ARM_RELATIVE:
11435 return reloc_class_relative;
11436 case R_ARM_JUMP_SLOT:
11437 return reloc_class_plt;
11438 case R_ARM_COPY:
11439 return reloc_class_copy;
11440 default:
11441 return reloc_class_normal;
11442 }
11443}
11444
e16bb312
NC
11445/* Set the right machine number for an Arm ELF file. */
11446
11447static bfd_boolean
57e8b36a 11448elf32_arm_section_flags (flagword *flags, const Elf_Internal_Shdr *hdr)
e16bb312
NC
11449{
11450 if (hdr->sh_type == SHT_NOTE)
11451 *flags |= SEC_LINK_ONCE | SEC_LINK_DUPLICATES_SAME_CONTENTS;
11452
11453 return TRUE;
11454}
11455
e489d0ae 11456static void
57e8b36a 11457elf32_arm_final_write_processing (bfd *abfd, bfd_boolean linker ATTRIBUTE_UNUSED)
e16bb312 11458{
5a6c6817 11459 bfd_arm_update_notes (abfd, ARM_NOTE_SECTION);
e16bb312
NC
11460}
11461
40a18ebd
NC
11462/* Return TRUE if this is an unwinding table entry. */
11463
11464static bfd_boolean
11465is_arm_elf_unwind_section_name (bfd * abfd ATTRIBUTE_UNUSED, const char * name)
11466{
0112cd26
NC
11467 return (CONST_STRNEQ (name, ELF_STRING_ARM_unwind)
11468 || CONST_STRNEQ (name, ELF_STRING_ARM_unwind_once));
40a18ebd
NC
11469}
11470
11471
11472/* Set the type and flags for an ARM section. We do this by
11473 the section name, which is a hack, but ought to work. */
11474
11475static bfd_boolean
11476elf32_arm_fake_sections (bfd * abfd, Elf_Internal_Shdr * hdr, asection * sec)
11477{
11478 const char * name;
11479
11480 name = bfd_get_section_name (abfd, sec);
11481
11482 if (is_arm_elf_unwind_section_name (abfd, name))
11483 {
11484 hdr->sh_type = SHT_ARM_EXIDX;
11485 hdr->sh_flags |= SHF_LINK_ORDER;
11486 }
11487 return TRUE;
11488}
11489
6dc132d9
L
11490/* Handle an ARM specific section when reading an object file. This is
11491 called when bfd_section_from_shdr finds a section with an unknown
11492 type. */
40a18ebd
NC
11493
11494static bfd_boolean
11495elf32_arm_section_from_shdr (bfd *abfd,
11496 Elf_Internal_Shdr * hdr,
6dc132d9
L
11497 const char *name,
11498 int shindex)
40a18ebd
NC
11499{
11500 /* There ought to be a place to keep ELF backend specific flags, but
11501 at the moment there isn't one. We just keep track of the
11502 sections by their name, instead. Fortunately, the ABI gives
11503 names for all the ARM specific sections, so we will probably get
11504 away with this. */
11505 switch (hdr->sh_type)
11506 {
11507 case SHT_ARM_EXIDX:
0951f019
RE
11508 case SHT_ARM_PREEMPTMAP:
11509 case SHT_ARM_ATTRIBUTES:
40a18ebd
NC
11510 break;
11511
11512 default:
11513 return FALSE;
11514 }
11515
6dc132d9 11516 if (! _bfd_elf_make_section_from_shdr (abfd, hdr, name, shindex))
40a18ebd
NC
11517 return FALSE;
11518
11519 return TRUE;
11520}
e489d0ae 11521
8e3de13a
NC
11522/* A structure used to record a list of sections, independently
11523 of the next and prev fields in the asection structure. */
11524typedef struct section_list
11525{
11526 asection * sec;
11527 struct section_list * next;
11528 struct section_list * prev;
11529}
11530section_list;
11531
11532/* Unfortunately we need to keep a list of sections for which
11533 an _arm_elf_section_data structure has been allocated. This
11534 is because it is possible for functions like elf32_arm_write_section
11535 to be called on a section which has had an elf_data_structure
11536 allocated for it (and so the used_by_bfd field is valid) but
11537 for which the ARM extended version of this structure - the
11538 _arm_elf_section_data structure - has not been allocated. */
11539static section_list * sections_with_arm_elf_section_data = NULL;
11540
11541static void
957c6e41 11542record_section_with_arm_elf_section_data (asection * sec)
8e3de13a
NC
11543{
11544 struct section_list * entry;
11545
957c6e41 11546 entry = bfd_malloc (sizeof (* entry));
8e3de13a
NC
11547 if (entry == NULL)
11548 return;
11549 entry->sec = sec;
11550 entry->next = sections_with_arm_elf_section_data;
11551 entry->prev = NULL;
11552 if (entry->next != NULL)
11553 entry->next->prev = entry;
11554 sections_with_arm_elf_section_data = entry;
11555}
11556
44444f50
NC
11557static struct section_list *
11558find_arm_elf_section_entry (asection * sec)
8e3de13a
NC
11559{
11560 struct section_list * entry;
bd4aae00 11561 static struct section_list * last_entry = NULL;
8e3de13a 11562
bd4aae00
NC
11563 /* This is a short cut for the typical case where the sections are added
11564 to the sections_with_arm_elf_section_data list in forward order and
11565 then looked up here in backwards order. This makes a real difference
11566 to the ld-srec/sec64k.exp linker test. */
44444f50 11567 entry = sections_with_arm_elf_section_data;
bd4aae00
NC
11568 if (last_entry != NULL)
11569 {
11570 if (last_entry->sec == sec)
44444f50
NC
11571 entry = last_entry;
11572 else if (last_entry->next != NULL
11573 && last_entry->next->sec == sec)
11574 entry = last_entry->next;
bd4aae00 11575 }
44444f50
NC
11576
11577 for (; entry; entry = entry->next)
8e3de13a 11578 if (entry->sec == sec)
44444f50 11579 break;
bd4aae00 11580
44444f50
NC
11581 if (entry)
11582 /* Record the entry prior to this one - it is the entry we are most
11583 likely to want to locate next time. Also this way if we have been
11584 called from unrecord_section_with_arm_elf_section_data() we will not
11585 be caching a pointer that is about to be freed. */
11586 last_entry = entry->prev;
11587
11588 return entry;
11589}
11590
11591static _arm_elf_section_data *
11592get_arm_elf_section_data (asection * sec)
11593{
11594 struct section_list * entry;
11595
11596 entry = find_arm_elf_section_entry (sec);
11597
11598 if (entry)
11599 return elf32_arm_section_data (entry->sec);
11600 else
11601 return NULL;
8e3de13a
NC
11602}
11603
11604static void
11605unrecord_section_with_arm_elf_section_data (asection * sec)
11606{
11607 struct section_list * entry;
11608
44444f50
NC
11609 entry = find_arm_elf_section_entry (sec);
11610
11611 if (entry)
11612 {
11613 if (entry->prev != NULL)
11614 entry->prev->next = entry->next;
11615 if (entry->next != NULL)
11616 entry->next->prev = entry->prev;
11617 if (entry == sections_with_arm_elf_section_data)
11618 sections_with_arm_elf_section_data = entry->next;
11619 free (entry);
11620 }
8e3de13a
NC
11621}
11622
e489d0ae 11623
4e617b1e
PB
11624typedef struct
11625{
11626 void *finfo;
11627 struct bfd_link_info *info;
91a5743d
PB
11628 asection *sec;
11629 int sec_shndx;
4e617b1e
PB
11630 bfd_boolean (*func) (void *, const char *, Elf_Internal_Sym *,
11631 asection *, struct elf_link_hash_entry *);
11632} output_arch_syminfo;
11633
11634enum map_symbol_type
11635{
11636 ARM_MAP_ARM,
11637 ARM_MAP_THUMB,
11638 ARM_MAP_DATA
11639};
11640
11641
7413f23f 11642/* Output a single mapping symbol. */
4e617b1e
PB
11643
11644static bfd_boolean
7413f23f
DJ
11645elf32_arm_output_map_sym (output_arch_syminfo *osi,
11646 enum map_symbol_type type,
11647 bfd_vma offset)
4e617b1e
PB
11648{
11649 static const char *names[3] = {"$a", "$t", "$d"};
11650 struct elf32_arm_link_hash_table *htab;
11651 Elf_Internal_Sym sym;
11652
11653 htab = elf32_arm_hash_table (osi->info);
91a5743d
PB
11654 sym.st_value = osi->sec->output_section->vma
11655 + osi->sec->output_offset
11656 + offset;
4e617b1e
PB
11657 sym.st_size = 0;
11658 sym.st_other = 0;
11659 sym.st_info = ELF_ST_INFO (STB_LOCAL, STT_NOTYPE);
91a5743d
PB
11660 sym.st_shndx = osi->sec_shndx;
11661 if (!osi->func (osi->finfo, names[type], &sym, osi->sec, NULL))
4e617b1e
PB
11662 return FALSE;
11663 return TRUE;
11664}
11665
11666
11667/* Output mapping symbols for PLT entries associated with H. */
11668
11669static bfd_boolean
11670elf32_arm_output_plt_map (struct elf_link_hash_entry *h, void *inf)
11671{
11672 output_arch_syminfo *osi = (output_arch_syminfo *) inf;
11673 struct elf32_arm_link_hash_table *htab;
11674 struct elf32_arm_link_hash_entry *eh;
11675 bfd_vma addr;
11676
11677 htab = elf32_arm_hash_table (osi->info);
11678
11679 if (h->root.type == bfd_link_hash_indirect)
11680 return TRUE;
11681
11682 if (h->root.type == bfd_link_hash_warning)
11683 /* When warning symbols are created, they **replace** the "real"
11684 entry in the hash table, thus we never get to see the real
11685 symbol in a hash traversal. So look at it now. */
11686 h = (struct elf_link_hash_entry *) h->root.u.i.link;
11687
11688 if (h->plt.offset == (bfd_vma) -1)
11689 return TRUE;
11690
11691 eh = (struct elf32_arm_link_hash_entry *) h;
11692 addr = h->plt.offset;
11693 if (htab->symbian_p)
11694 {
7413f23f 11695 if (!elf32_arm_output_map_sym (osi, ARM_MAP_ARM, addr))
4e617b1e 11696 return FALSE;
7413f23f 11697 if (!elf32_arm_output_map_sym (osi, ARM_MAP_DATA, addr + 4))
4e617b1e
PB
11698 return FALSE;
11699 }
11700 else if (htab->vxworks_p)
11701 {
7413f23f 11702 if (!elf32_arm_output_map_sym (osi, ARM_MAP_ARM, addr))
4e617b1e 11703 return FALSE;
7413f23f 11704 if (!elf32_arm_output_map_sym (osi, ARM_MAP_DATA, addr + 8))
4e617b1e 11705 return FALSE;
7413f23f 11706 if (!elf32_arm_output_map_sym (osi, ARM_MAP_ARM, addr + 12))
4e617b1e 11707 return FALSE;
7413f23f 11708 if (!elf32_arm_output_map_sym (osi, ARM_MAP_DATA, addr + 20))
4e617b1e
PB
11709 return FALSE;
11710 }
11711 else
11712 {
bd97cb95
DJ
11713 bfd_signed_vma thumb_refs;
11714
11715 thumb_refs = eh->plt_thumb_refcount;
11716 if (!htab->use_blx)
11717 thumb_refs += eh->plt_maybe_thumb_refcount;
4e617b1e 11718
bd97cb95 11719 if (thumb_refs > 0)
4e617b1e 11720 {
7413f23f 11721 if (!elf32_arm_output_map_sym (osi, ARM_MAP_THUMB, addr - 4))
4e617b1e
PB
11722 return FALSE;
11723 }
11724#ifdef FOUR_WORD_PLT
7413f23f 11725 if (!elf32_arm_output_map_sym (osi, ARM_MAP_ARM, addr))
4e617b1e 11726 return FALSE;
7413f23f 11727 if (!elf32_arm_output_map_sym (osi, ARM_MAP_DATA, addr + 12))
4e617b1e
PB
11728 return FALSE;
11729#else
906e58ca 11730 /* A three-word PLT with no Thumb thunk contains only Arm code,
4e617b1e
PB
11731 so only need to output a mapping symbol for the first PLT entry and
11732 entries with thumb thunks. */
bd97cb95 11733 if (thumb_refs > 0 || addr == 20)
4e617b1e 11734 {
7413f23f 11735 if (!elf32_arm_output_map_sym (osi, ARM_MAP_ARM, addr))
4e617b1e
PB
11736 return FALSE;
11737 }
11738#endif
11739 }
11740
11741 return TRUE;
11742}
11743
7413f23f
DJ
11744/* Output a single local symbol for a generated stub. */
11745
11746static bfd_boolean
11747elf32_arm_output_stub_sym (output_arch_syminfo *osi, const char *name,
11748 bfd_vma offset, bfd_vma size)
11749{
11750 struct elf32_arm_link_hash_table *htab;
11751 Elf_Internal_Sym sym;
11752
11753 htab = elf32_arm_hash_table (osi->info);
11754 sym.st_value = osi->sec->output_section->vma
11755 + osi->sec->output_offset
11756 + offset;
11757 sym.st_size = size;
11758 sym.st_other = 0;
11759 sym.st_info = ELF_ST_INFO (STB_LOCAL, STT_FUNC);
11760 sym.st_shndx = osi->sec_shndx;
11761 if (!osi->func (osi->finfo, name, &sym, osi->sec, NULL))
11762 return FALSE;
11763 return TRUE;
11764}
4e617b1e 11765
da5938a2 11766static bfd_boolean
8029a119
NC
11767arm_map_one_stub (struct bfd_hash_entry * gen_entry,
11768 void * in_arg)
da5938a2
NC
11769{
11770 struct elf32_arm_stub_hash_entry *stub_entry;
11771 struct bfd_link_info *info;
11772 struct elf32_arm_link_hash_table *htab;
11773 asection *stub_sec;
11774 bfd_vma addr;
7413f23f 11775 char *stub_name;
9a008db3 11776 output_arch_syminfo *osi;
461a49ca
DJ
11777 const insn_sequence *template;
11778 enum stub_insn_type prev_type;
11779 int size;
11780 int i;
11781 enum map_symbol_type sym_type;
da5938a2
NC
11782
11783 /* Massage our args to the form they really have. */
11784 stub_entry = (struct elf32_arm_stub_hash_entry *) gen_entry;
9a008db3 11785 osi = (output_arch_syminfo *) in_arg;
da5938a2 11786
da5938a2
NC
11787 info = osi->info;
11788
11789 htab = elf32_arm_hash_table (info);
11790 stub_sec = stub_entry->stub_sec;
11791
11792 /* Ensure this stub is attached to the current section being
7413f23f 11793 processed. */
da5938a2
NC
11794 if (stub_sec != osi->sec)
11795 return TRUE;
11796
7413f23f
DJ
11797 addr = (bfd_vma) stub_entry->stub_offset;
11798 stub_name = stub_entry->output_name;
da5938a2 11799
461a49ca 11800 template = stub_entry->stub_template;
4e31c731 11801 switch (template[0].type)
7413f23f 11802 {
461a49ca
DJ
11803 case ARM_TYPE:
11804 if (!elf32_arm_output_stub_sym (osi, stub_name, addr, stub_entry->stub_size))
da5938a2
NC
11805 return FALSE;
11806 break;
461a49ca
DJ
11807 case THUMB16_TYPE:
11808 if (!elf32_arm_output_stub_sym (osi, stub_name, addr | 1,
11809 stub_entry->stub_size))
da5938a2
NC
11810 return FALSE;
11811 break;
11812 default:
11813 BFD_FAIL ();
4e31c731 11814 return FALSE;
7413f23f 11815 }
da5938a2 11816
461a49ca
DJ
11817 prev_type = DATA_TYPE;
11818 size = 0;
11819 for (i = 0; i < stub_entry->stub_template_size; i++)
11820 {
4e31c731 11821 switch (template[i].type)
461a49ca
DJ
11822 {
11823 case ARM_TYPE:
11824 sym_type = ARM_MAP_ARM;
11825 break;
11826
11827 case THUMB16_TYPE:
11828 sym_type = ARM_MAP_THUMB;
11829 break;
11830
11831 case DATA_TYPE:
11832 sym_type = ARM_MAP_DATA;
11833 break;
11834
11835 default:
11836 BFD_FAIL ();
4e31c731 11837 return FALSE;
461a49ca
DJ
11838 }
11839
11840 if (template[i].type != prev_type)
11841 {
11842 prev_type = template[i].type;
11843 if (!elf32_arm_output_map_sym (osi, sym_type, addr + size))
11844 return FALSE;
11845 }
11846
4e31c731 11847 switch (template[i].type)
461a49ca
DJ
11848 {
11849 case ARM_TYPE:
11850 size += 4;
11851 break;
11852
11853 case THUMB16_TYPE:
11854 size += 2;
11855 break;
11856
11857 case DATA_TYPE:
11858 size += 4;
11859 break;
11860
11861 default:
11862 BFD_FAIL ();
4e31c731 11863 return FALSE;
461a49ca
DJ
11864 }
11865 }
11866
da5938a2
NC
11867 return TRUE;
11868}
11869
91a5743d 11870/* Output mapping symbols for linker generated sections. */
4e617b1e
PB
11871
11872static bfd_boolean
11873elf32_arm_output_arch_local_syms (bfd *output_bfd,
906e58ca
NC
11874 struct bfd_link_info *info,
11875 void *finfo,
11876 bfd_boolean (*func) (void *, const char *,
11877 Elf_Internal_Sym *,
11878 asection *,
11879 struct elf_link_hash_entry *))
4e617b1e
PB
11880{
11881 output_arch_syminfo osi;
11882 struct elf32_arm_link_hash_table *htab;
91a5743d
PB
11883 bfd_vma offset;
11884 bfd_size_type size;
4e617b1e
PB
11885
11886 htab = elf32_arm_hash_table (info);
906e58ca 11887 check_use_blx (htab);
91a5743d 11888
4e617b1e
PB
11889 osi.finfo = finfo;
11890 osi.info = info;
11891 osi.func = func;
906e58ca 11892
91a5743d
PB
11893 /* ARM->Thumb glue. */
11894 if (htab->arm_glue_size > 0)
11895 {
11896 osi.sec = bfd_get_section_by_name (htab->bfd_of_glue_owner,
11897 ARM2THUMB_GLUE_SECTION_NAME);
11898
11899 osi.sec_shndx = _bfd_elf_section_from_bfd_section
11900 (output_bfd, osi.sec->output_section);
11901 if (info->shared || htab->root.is_relocatable_executable
11902 || htab->pic_veneer)
11903 size = ARM2THUMB_PIC_GLUE_SIZE;
11904 else if (htab->use_blx)
11905 size = ARM2THUMB_V5_STATIC_GLUE_SIZE;
11906 else
11907 size = ARM2THUMB_STATIC_GLUE_SIZE;
4e617b1e 11908
91a5743d
PB
11909 for (offset = 0; offset < htab->arm_glue_size; offset += size)
11910 {
7413f23f
DJ
11911 elf32_arm_output_map_sym (&osi, ARM_MAP_ARM, offset);
11912 elf32_arm_output_map_sym (&osi, ARM_MAP_DATA, offset + size - 4);
91a5743d
PB
11913 }
11914 }
11915
11916 /* Thumb->ARM glue. */
11917 if (htab->thumb_glue_size > 0)
11918 {
11919 osi.sec = bfd_get_section_by_name (htab->bfd_of_glue_owner,
11920 THUMB2ARM_GLUE_SECTION_NAME);
11921
11922 osi.sec_shndx = _bfd_elf_section_from_bfd_section
11923 (output_bfd, osi.sec->output_section);
11924 size = THUMB2ARM_GLUE_SIZE;
11925
11926 for (offset = 0; offset < htab->thumb_glue_size; offset += size)
11927 {
7413f23f
DJ
11928 elf32_arm_output_map_sym (&osi, ARM_MAP_THUMB, offset);
11929 elf32_arm_output_map_sym (&osi, ARM_MAP_ARM, offset + 4);
91a5743d
PB
11930 }
11931 }
11932
845b51d6
PB
11933 /* ARMv4 BX veneers. */
11934 if (htab->bx_glue_size > 0)
11935 {
11936 osi.sec = bfd_get_section_by_name (htab->bfd_of_glue_owner,
11937 ARM_BX_GLUE_SECTION_NAME);
11938
11939 osi.sec_shndx = _bfd_elf_section_from_bfd_section
11940 (output_bfd, osi.sec->output_section);
11941
7413f23f 11942 elf32_arm_output_map_sym (&osi, ARM_MAP_ARM, 0);
845b51d6
PB
11943 }
11944
8029a119
NC
11945 /* Long calls stubs. */
11946 if (htab->stub_bfd && htab->stub_bfd->sections)
11947 {
da5938a2 11948 asection* stub_sec;
8029a119 11949
da5938a2
NC
11950 for (stub_sec = htab->stub_bfd->sections;
11951 stub_sec != NULL;
8029a119
NC
11952 stub_sec = stub_sec->next)
11953 {
11954 /* Ignore non-stub sections. */
11955 if (!strstr (stub_sec->name, STUB_SUFFIX))
11956 continue;
da5938a2 11957
8029a119 11958 osi.sec = stub_sec;
da5938a2 11959
8029a119
NC
11960 osi.sec_shndx = _bfd_elf_section_from_bfd_section
11961 (output_bfd, osi.sec->output_section);
da5938a2 11962
8029a119
NC
11963 bfd_hash_traverse (&htab->stub_hash_table, arm_map_one_stub, &osi);
11964 }
11965 }
da5938a2 11966
91a5743d
PB
11967 /* Finally, output mapping symbols for the PLT. */
11968 if (!htab->splt || htab->splt->size == 0)
11969 return TRUE;
11970
11971 osi.sec_shndx = _bfd_elf_section_from_bfd_section (output_bfd,
8029a119 11972 htab->splt->output_section);
91a5743d 11973 osi.sec = htab->splt;
4e617b1e
PB
11974 /* Output mapping symbols for the plt header. SymbianOS does not have a
11975 plt header. */
11976 if (htab->vxworks_p)
11977 {
11978 /* VxWorks shared libraries have no PLT header. */
11979 if (!info->shared)
11980 {
7413f23f 11981 if (!elf32_arm_output_map_sym (&osi, ARM_MAP_ARM, 0))
4e617b1e 11982 return FALSE;
7413f23f 11983 if (!elf32_arm_output_map_sym (&osi, ARM_MAP_DATA, 12))
4e617b1e
PB
11984 return FALSE;
11985 }
11986 }
11987 else if (!htab->symbian_p)
11988 {
7413f23f 11989 if (!elf32_arm_output_map_sym (&osi, ARM_MAP_ARM, 0))
4e617b1e
PB
11990 return FALSE;
11991#ifndef FOUR_WORD_PLT
7413f23f 11992 if (!elf32_arm_output_map_sym (&osi, ARM_MAP_DATA, 16))
4e617b1e
PB
11993 return FALSE;
11994#endif
11995 }
11996
11997 elf_link_hash_traverse (&htab->root, elf32_arm_output_plt_map, (void *) &osi);
11998 return TRUE;
11999}
12000
e489d0ae
PB
12001/* Allocate target specific section data. */
12002
12003static bfd_boolean
12004elf32_arm_new_section_hook (bfd *abfd, asection *sec)
12005{
f592407e
AM
12006 if (!sec->used_by_bfd)
12007 {
12008 _arm_elf_section_data *sdata;
12009 bfd_size_type amt = sizeof (*sdata);
e489d0ae 12010
f592407e
AM
12011 sdata = bfd_zalloc (abfd, amt);
12012 if (sdata == NULL)
12013 return FALSE;
12014 sec->used_by_bfd = sdata;
12015 }
e489d0ae 12016
957c6e41 12017 record_section_with_arm_elf_section_data (sec);
8e3de13a 12018
e489d0ae
PB
12019 return _bfd_elf_new_section_hook (abfd, sec);
12020}
12021
12022
12023/* Used to order a list of mapping symbols by address. */
12024
12025static int
12026elf32_arm_compare_mapping (const void * a, const void * b)
12027{
7f6a71ff
JM
12028 const elf32_arm_section_map *amap = (const elf32_arm_section_map *) a;
12029 const elf32_arm_section_map *bmap = (const elf32_arm_section_map *) b;
12030
12031 if (amap->vma > bmap->vma)
12032 return 1;
12033 else if (amap->vma < bmap->vma)
12034 return -1;
12035 else if (amap->type > bmap->type)
12036 /* Ensure results do not depend on the host qsort for objects with
12037 multiple mapping symbols at the same address by sorting on type
12038 after vma. */
12039 return 1;
12040 else if (amap->type < bmap->type)
12041 return -1;
12042 else
12043 return 0;
e489d0ae
PB
12044}
12045
12046
12047/* Do code byteswapping. Return FALSE afterwards so that the section is
12048 written out as normal. */
12049
12050static bfd_boolean
c7b8f16e 12051elf32_arm_write_section (bfd *output_bfd,
8029a119
NC
12052 struct bfd_link_info *link_info,
12053 asection *sec,
e489d0ae
PB
12054 bfd_byte *contents)
12055{
c7b8f16e 12056 int mapcount, errcount;
8e3de13a 12057 _arm_elf_section_data *arm_data;
c7b8f16e 12058 struct elf32_arm_link_hash_table *globals = elf32_arm_hash_table (link_info);
e489d0ae 12059 elf32_arm_section_map *map;
c7b8f16e 12060 elf32_vfp11_erratum_list *errnode;
e489d0ae
PB
12061 bfd_vma ptr;
12062 bfd_vma end;
c7b8f16e 12063 bfd_vma offset = sec->output_section->vma + sec->output_offset;
e489d0ae
PB
12064 bfd_byte tmp;
12065 int i;
57e8b36a 12066
8e3de13a
NC
12067 /* If this section has not been allocated an _arm_elf_section_data
12068 structure then we cannot record anything. */
12069 arm_data = get_arm_elf_section_data (sec);
12070 if (arm_data == NULL)
12071 return FALSE;
12072
12073 mapcount = arm_data->mapcount;
12074 map = arm_data->map;
c7b8f16e
JB
12075 errcount = arm_data->erratumcount;
12076
12077 if (errcount != 0)
12078 {
12079 unsigned int endianflip = bfd_big_endian (output_bfd) ? 3 : 0;
12080
12081 for (errnode = arm_data->erratumlist; errnode != 0;
12082 errnode = errnode->next)
12083 {
12084 bfd_vma index = errnode->vma - offset;
12085
12086 switch (errnode->type)
12087 {
12088 case VFP11_ERRATUM_BRANCH_TO_ARM_VENEER:
12089 {
12090 bfd_vma branch_to_veneer;
12091 /* Original condition code of instruction, plus bit mask for
12092 ARM B instruction. */
12093 unsigned int insn = (errnode->u.b.vfp_insn & 0xf0000000)
12094 | 0x0a000000;
12095
12096 /* The instruction is before the label. */
12097 index -= 4;
12098
12099 /* Above offset included in -4 below. */
12100 branch_to_veneer = errnode->u.b.veneer->vma
12101 - errnode->vma - 4;
12102
12103 if ((signed) branch_to_veneer < -(1 << 25)
12104 || (signed) branch_to_veneer >= (1 << 25))
12105 (*_bfd_error_handler) (_("%B: error: VFP11 veneer out of "
12106 "range"), output_bfd);
12107
12108 insn |= (branch_to_veneer >> 2) & 0xffffff;
12109 contents[endianflip ^ index] = insn & 0xff;
12110 contents[endianflip ^ (index + 1)] = (insn >> 8) & 0xff;
12111 contents[endianflip ^ (index + 2)] = (insn >> 16) & 0xff;
12112 contents[endianflip ^ (index + 3)] = (insn >> 24) & 0xff;
12113 }
12114 break;
12115
12116 case VFP11_ERRATUM_ARM_VENEER:
12117 {
12118 bfd_vma branch_from_veneer;
12119 unsigned int insn;
12120
12121 /* Take size of veneer into account. */
12122 branch_from_veneer = errnode->u.v.branch->vma
12123 - errnode->vma - 12;
12124
12125 if ((signed) branch_from_veneer < -(1 << 25)
12126 || (signed) branch_from_veneer >= (1 << 25))
12127 (*_bfd_error_handler) (_("%B: error: VFP11 veneer out of "
12128 "range"), output_bfd);
12129
12130 /* Original instruction. */
12131 insn = errnode->u.v.branch->u.b.vfp_insn;
12132 contents[endianflip ^ index] = insn & 0xff;
12133 contents[endianflip ^ (index + 1)] = (insn >> 8) & 0xff;
12134 contents[endianflip ^ (index + 2)] = (insn >> 16) & 0xff;
12135 contents[endianflip ^ (index + 3)] = (insn >> 24) & 0xff;
12136
12137 /* Branch back to insn after original insn. */
12138 insn = 0xea000000 | ((branch_from_veneer >> 2) & 0xffffff);
12139 contents[endianflip ^ (index + 4)] = insn & 0xff;
12140 contents[endianflip ^ (index + 5)] = (insn >> 8) & 0xff;
12141 contents[endianflip ^ (index + 6)] = (insn >> 16) & 0xff;
12142 contents[endianflip ^ (index + 7)] = (insn >> 24) & 0xff;
12143 }
12144 break;
12145
12146 default:
12147 abort ();
12148 }
12149 }
12150 }
e489d0ae
PB
12151
12152 if (mapcount == 0)
12153 return FALSE;
12154
c7b8f16e 12155 if (globals->byteswap_code)
e489d0ae 12156 {
c7b8f16e 12157 qsort (map, mapcount, sizeof (* map), elf32_arm_compare_mapping);
57e8b36a 12158
c7b8f16e
JB
12159 ptr = map[0].vma;
12160 for (i = 0; i < mapcount; i++)
12161 {
12162 if (i == mapcount - 1)
12163 end = sec->size;
12164 else
12165 end = map[i + 1].vma;
e489d0ae 12166
c7b8f16e 12167 switch (map[i].type)
e489d0ae 12168 {
c7b8f16e
JB
12169 case 'a':
12170 /* Byte swap code words. */
12171 while (ptr + 3 < end)
12172 {
12173 tmp = contents[ptr];
12174 contents[ptr] = contents[ptr + 3];
12175 contents[ptr + 3] = tmp;
12176 tmp = contents[ptr + 1];
12177 contents[ptr + 1] = contents[ptr + 2];
12178 contents[ptr + 2] = tmp;
12179 ptr += 4;
12180 }
12181 break;
e489d0ae 12182
c7b8f16e
JB
12183 case 't':
12184 /* Byte swap code halfwords. */
12185 while (ptr + 1 < end)
12186 {
12187 tmp = contents[ptr];
12188 contents[ptr] = contents[ptr + 1];
12189 contents[ptr + 1] = tmp;
12190 ptr += 2;
12191 }
12192 break;
12193
12194 case 'd':
12195 /* Leave data alone. */
12196 break;
12197 }
12198 ptr = end;
12199 }
e489d0ae 12200 }
8e3de13a 12201
93204d3a 12202 free (map);
8e3de13a 12203 arm_data->mapcount = 0;
c7b8f16e 12204 arm_data->mapsize = 0;
8e3de13a
NC
12205 arm_data->map = NULL;
12206 unrecord_section_with_arm_elf_section_data (sec);
12207
e489d0ae
PB
12208 return FALSE;
12209}
12210
957c6e41
NC
12211static void
12212unrecord_section_via_map_over_sections (bfd * abfd ATTRIBUTE_UNUSED,
12213 asection * sec,
12214 void * ignore ATTRIBUTE_UNUSED)
12215{
12216 unrecord_section_with_arm_elf_section_data (sec);
12217}
12218
12219static bfd_boolean
12220elf32_arm_close_and_cleanup (bfd * abfd)
12221{
b25e3d87
L
12222 if (abfd->sections)
12223 bfd_map_over_sections (abfd,
12224 unrecord_section_via_map_over_sections,
12225 NULL);
957c6e41
NC
12226
12227 return _bfd_elf_close_and_cleanup (abfd);
12228}
12229
b25e3d87
L
12230static bfd_boolean
12231elf32_arm_bfd_free_cached_info (bfd * abfd)
12232{
12233 if (abfd->sections)
12234 bfd_map_over_sections (abfd,
12235 unrecord_section_via_map_over_sections,
12236 NULL);
12237
12238 return _bfd_free_cached_info (abfd);
12239}
12240
b7693d02
DJ
12241/* Display STT_ARM_TFUNC symbols as functions. */
12242
12243static void
12244elf32_arm_symbol_processing (bfd *abfd ATTRIBUTE_UNUSED,
12245 asymbol *asym)
12246{
12247 elf_symbol_type *elfsym = (elf_symbol_type *) asym;
12248
12249 if (ELF_ST_TYPE (elfsym->internal_elf_sym.st_info) == STT_ARM_TFUNC)
12250 elfsym->symbol.flags |= BSF_FUNCTION;
12251}
12252
0beaef2b
PB
12253
12254/* Mangle thumb function symbols as we read them in. */
12255
8384fb8f 12256static bfd_boolean
0beaef2b
PB
12257elf32_arm_swap_symbol_in (bfd * abfd,
12258 const void *psrc,
12259 const void *pshn,
12260 Elf_Internal_Sym *dst)
12261{
8384fb8f
AM
12262 if (!bfd_elf32_swap_symbol_in (abfd, psrc, pshn, dst))
12263 return FALSE;
0beaef2b
PB
12264
12265 /* New EABI objects mark thumb function symbols by setting the low bit of
12266 the address. Turn these into STT_ARM_TFUNC. */
0f88be7a 12267 if ((ELF_ST_TYPE (dst->st_info) == STT_FUNC)
0beaef2b
PB
12268 && (dst->st_value & 1))
12269 {
12270 dst->st_info = ELF_ST_INFO (ELF_ST_BIND (dst->st_info), STT_ARM_TFUNC);
12271 dst->st_value &= ~(bfd_vma) 1;
12272 }
8384fb8f 12273 return TRUE;
0beaef2b
PB
12274}
12275
12276
12277/* Mangle thumb function symbols as we write them out. */
12278
12279static void
12280elf32_arm_swap_symbol_out (bfd *abfd,
12281 const Elf_Internal_Sym *src,
12282 void *cdst,
12283 void *shndx)
12284{
12285 Elf_Internal_Sym newsym;
12286
12287 /* We convert STT_ARM_TFUNC symbols into STT_FUNC with the low bit
12288 of the address set, as per the new EABI. We do this unconditionally
12289 because objcopy does not set the elf header flags until after
12290 it writes out the symbol table. */
12291 if (ELF_ST_TYPE (src->st_info) == STT_ARM_TFUNC)
12292 {
12293 newsym = *src;
12294 newsym.st_info = ELF_ST_INFO (ELF_ST_BIND (src->st_info), STT_FUNC);
0fa3dcad
PB
12295 if (newsym.st_shndx != SHN_UNDEF)
12296 {
12297 /* Do this only for defined symbols. At link type, the static
12298 linker will simulate the work of dynamic linker of resolving
12299 symbols and will carry over the thumbness of found symbols to
12300 the output symbol table. It's not clear how it happens, but
b0fead2b 12301 the thumbness of undefined symbols can well be different at
0fa3dcad
PB
12302 runtime, and writing '1' for them will be confusing for users
12303 and possibly for dynamic linker itself.
12304 */
12305 newsym.st_value |= 1;
12306 }
906e58ca 12307
0beaef2b
PB
12308 src = &newsym;
12309 }
12310 bfd_elf32_swap_symbol_out (abfd, src, cdst, shndx);
12311}
12312
b294bdf8
MM
12313/* Add the PT_ARM_EXIDX program header. */
12314
12315static bfd_boolean
906e58ca 12316elf32_arm_modify_segment_map (bfd *abfd,
b294bdf8
MM
12317 struct bfd_link_info *info ATTRIBUTE_UNUSED)
12318{
12319 struct elf_segment_map *m;
12320 asection *sec;
12321
12322 sec = bfd_get_section_by_name (abfd, ".ARM.exidx");
12323 if (sec != NULL && (sec->flags & SEC_LOAD) != 0)
12324 {
12325 /* If there is already a PT_ARM_EXIDX header, then we do not
12326 want to add another one. This situation arises when running
12327 "strip"; the input binary already has the header. */
12328 m = elf_tdata (abfd)->segment_map;
12329 while (m && m->p_type != PT_ARM_EXIDX)
12330 m = m->next;
12331 if (!m)
12332 {
12333 m = bfd_zalloc (abfd, sizeof (struct elf_segment_map));
12334 if (m == NULL)
12335 return FALSE;
12336 m->p_type = PT_ARM_EXIDX;
12337 m->count = 1;
12338 m->sections[0] = sec;
12339
12340 m->next = elf_tdata (abfd)->segment_map;
12341 elf_tdata (abfd)->segment_map = m;
12342 }
12343 }
12344
12345 return TRUE;
12346}
12347
12348/* We may add a PT_ARM_EXIDX program header. */
12349
12350static int
a6b96beb
AM
12351elf32_arm_additional_program_headers (bfd *abfd,
12352 struct bfd_link_info *info ATTRIBUTE_UNUSED)
b294bdf8
MM
12353{
12354 asection *sec;
12355
12356 sec = bfd_get_section_by_name (abfd, ".ARM.exidx");
12357 if (sec != NULL && (sec->flags & SEC_LOAD) != 0)
12358 return 1;
12359 else
12360 return 0;
12361}
12362
fcb93ecf 12363/* We have two function types: STT_FUNC and STT_ARM_TFUNC. */
906e58ca 12364
fcb93ecf
PB
12365static bfd_boolean
12366elf32_arm_is_function_type (unsigned int type)
12367{
0f88be7a 12368 return (type == STT_FUNC) || (type == STT_ARM_TFUNC);
fcb93ecf
PB
12369}
12370
0beaef2b 12371/* We use this to override swap_symbol_in and swap_symbol_out. */
906e58ca
NC
12372const struct elf_size_info elf32_arm_size_info =
12373{
0beaef2b
PB
12374 sizeof (Elf32_External_Ehdr),
12375 sizeof (Elf32_External_Phdr),
12376 sizeof (Elf32_External_Shdr),
12377 sizeof (Elf32_External_Rel),
12378 sizeof (Elf32_External_Rela),
12379 sizeof (Elf32_External_Sym),
12380 sizeof (Elf32_External_Dyn),
12381 sizeof (Elf_External_Note),
12382 4,
12383 1,
12384 32, 2,
12385 ELFCLASS32, EV_CURRENT,
12386 bfd_elf32_write_out_phdrs,
12387 bfd_elf32_write_shdrs_and_ehdr,
1489a3a0 12388 bfd_elf32_checksum_contents,
0beaef2b
PB
12389 bfd_elf32_write_relocs,
12390 elf32_arm_swap_symbol_in,
12391 elf32_arm_swap_symbol_out,
12392 bfd_elf32_slurp_reloc_table,
12393 bfd_elf32_slurp_symbol_table,
12394 bfd_elf32_swap_dyn_in,
12395 bfd_elf32_swap_dyn_out,
12396 bfd_elf32_swap_reloc_in,
12397 bfd_elf32_swap_reloc_out,
12398 bfd_elf32_swap_reloca_in,
12399 bfd_elf32_swap_reloca_out
12400};
12401
252b5132
RH
12402#define ELF_ARCH bfd_arch_arm
12403#define ELF_MACHINE_CODE EM_ARM
d0facd1b
NC
12404#ifdef __QNXTARGET__
12405#define ELF_MAXPAGESIZE 0x1000
12406#else
f21f3fe0 12407#define ELF_MAXPAGESIZE 0x8000
d0facd1b 12408#endif
b1342370 12409#define ELF_MINPAGESIZE 0x1000
24718e3b 12410#define ELF_COMMONPAGESIZE 0x1000
252b5132 12411
ba93b8ac
DJ
12412#define bfd_elf32_mkobject elf32_arm_mkobject
12413
99e4ae17
AJ
12414#define bfd_elf32_bfd_copy_private_bfd_data elf32_arm_copy_private_bfd_data
12415#define bfd_elf32_bfd_merge_private_bfd_data elf32_arm_merge_private_bfd_data
252b5132
RH
12416#define bfd_elf32_bfd_set_private_flags elf32_arm_set_private_flags
12417#define bfd_elf32_bfd_print_private_bfd_data elf32_arm_print_private_bfd_data
12418#define bfd_elf32_bfd_link_hash_table_create elf32_arm_link_hash_table_create
906e58ca 12419#define bfd_elf32_bfd_link_hash_table_free elf32_arm_hash_table_free
dc810e39 12420#define bfd_elf32_bfd_reloc_type_lookup elf32_arm_reloc_type_lookup
157090f7 12421#define bfd_elf32_bfd_reloc_name_lookup elf32_arm_reloc_name_lookup
252b5132 12422#define bfd_elf32_find_nearest_line elf32_arm_find_nearest_line
4ab527b0 12423#define bfd_elf32_find_inliner_info elf32_arm_find_inliner_info
e489d0ae 12424#define bfd_elf32_new_section_hook elf32_arm_new_section_hook
3c9458e9 12425#define bfd_elf32_bfd_is_target_special_symbol elf32_arm_is_target_special_symbol
957c6e41 12426#define bfd_elf32_close_and_cleanup elf32_arm_close_and_cleanup
b25e3d87 12427#define bfd_elf32_bfd_free_cached_info elf32_arm_bfd_free_cached_info
252b5132
RH
12428
12429#define elf_backend_get_symbol_type elf32_arm_get_symbol_type
12430#define elf_backend_gc_mark_hook elf32_arm_gc_mark_hook
6a5bb875 12431#define elf_backend_gc_mark_extra_sections elf32_arm_gc_mark_extra_sections
252b5132
RH
12432#define elf_backend_gc_sweep_hook elf32_arm_gc_sweep_hook
12433#define elf_backend_check_relocs elf32_arm_check_relocs
dc810e39 12434#define elf_backend_relocate_section elf32_arm_relocate_section
e489d0ae 12435#define elf_backend_write_section elf32_arm_write_section
252b5132 12436#define elf_backend_adjust_dynamic_symbol elf32_arm_adjust_dynamic_symbol
5e681ec4 12437#define elf_backend_create_dynamic_sections elf32_arm_create_dynamic_sections
252b5132
RH
12438#define elf_backend_finish_dynamic_symbol elf32_arm_finish_dynamic_symbol
12439#define elf_backend_finish_dynamic_sections elf32_arm_finish_dynamic_sections
12440#define elf_backend_size_dynamic_sections elf32_arm_size_dynamic_sections
74541ad4 12441#define elf_backend_init_index_section _bfd_elf_init_2_index_sections
ba96a88f 12442#define elf_backend_post_process_headers elf32_arm_post_process_headers
99e4ae17 12443#define elf_backend_reloc_type_class elf32_arm_reloc_type_class
c178919b 12444#define elf_backend_object_p elf32_arm_object_p
e16bb312 12445#define elf_backend_section_flags elf32_arm_section_flags
40a18ebd
NC
12446#define elf_backend_fake_sections elf32_arm_fake_sections
12447#define elf_backend_section_from_shdr elf32_arm_section_from_shdr
e16bb312 12448#define elf_backend_final_write_processing elf32_arm_final_write_processing
5e681ec4 12449#define elf_backend_copy_indirect_symbol elf32_arm_copy_indirect_symbol
b7693d02 12450#define elf_backend_symbol_processing elf32_arm_symbol_processing
0beaef2b 12451#define elf_backend_size_info elf32_arm_size_info
b294bdf8 12452#define elf_backend_modify_segment_map elf32_arm_modify_segment_map
906e58ca
NC
12453#define elf_backend_additional_program_headers elf32_arm_additional_program_headers
12454#define elf_backend_output_arch_local_syms elf32_arm_output_arch_local_syms
12455#define elf_backend_begin_write_processing elf32_arm_begin_write_processing
12456#define elf_backend_is_function_type elf32_arm_is_function_type
12457
12458#define elf_backend_can_refcount 1
12459#define elf_backend_can_gc_sections 1
12460#define elf_backend_plt_readonly 1
12461#define elf_backend_want_got_plt 1
12462#define elf_backend_want_plt_sym 0
12463#define elf_backend_may_use_rel_p 1
12464#define elf_backend_may_use_rela_p 0
4e7fd91e 12465#define elf_backend_default_use_rela_p 0
252b5132 12466
04f7c78d 12467#define elf_backend_got_header_size 12
04f7c78d 12468
906e58ca
NC
12469#undef elf_backend_obj_attrs_vendor
12470#define elf_backend_obj_attrs_vendor "aeabi"
12471#undef elf_backend_obj_attrs_section
12472#define elf_backend_obj_attrs_section ".ARM.attributes"
12473#undef elf_backend_obj_attrs_arg_type
12474#define elf_backend_obj_attrs_arg_type elf32_arm_obj_attrs_arg_type
12475#undef elf_backend_obj_attrs_section_type
104d59d1 12476#define elf_backend_obj_attrs_section_type SHT_ARM_ATTRIBUTES
5aa6ff7c 12477#define elf_backend_obj_attrs_order elf32_arm_obj_attrs_order
104d59d1 12478
252b5132 12479#include "elf32-target.h"
7f266840 12480
906e58ca 12481/* VxWorks Targets. */
4e7fd91e 12482
906e58ca 12483#undef TARGET_LITTLE_SYM
4e7fd91e 12484#define TARGET_LITTLE_SYM bfd_elf32_littlearm_vxworks_vec
906e58ca 12485#undef TARGET_LITTLE_NAME
4e7fd91e 12486#define TARGET_LITTLE_NAME "elf32-littlearm-vxworks"
906e58ca 12487#undef TARGET_BIG_SYM
4e7fd91e 12488#define TARGET_BIG_SYM bfd_elf32_bigarm_vxworks_vec
906e58ca 12489#undef TARGET_BIG_NAME
4e7fd91e
PB
12490#define TARGET_BIG_NAME "elf32-bigarm-vxworks"
12491
12492/* Like elf32_arm_link_hash_table_create -- but overrides
12493 appropriately for VxWorks. */
906e58ca 12494
4e7fd91e
PB
12495static struct bfd_link_hash_table *
12496elf32_arm_vxworks_link_hash_table_create (bfd *abfd)
12497{
12498 struct bfd_link_hash_table *ret;
12499
12500 ret = elf32_arm_link_hash_table_create (abfd);
12501 if (ret)
12502 {
12503 struct elf32_arm_link_hash_table *htab
00a97672 12504 = (struct elf32_arm_link_hash_table *) ret;
4e7fd91e 12505 htab->use_rel = 0;
00a97672 12506 htab->vxworks_p = 1;
4e7fd91e
PB
12507 }
12508 return ret;
906e58ca 12509}
4e7fd91e 12510
00a97672
RS
12511static void
12512elf32_arm_vxworks_final_write_processing (bfd *abfd, bfd_boolean linker)
12513{
12514 elf32_arm_final_write_processing (abfd, linker);
12515 elf_vxworks_final_write_processing (abfd, linker);
12516}
12517
906e58ca 12518#undef elf32_bed
4e7fd91e
PB
12519#define elf32_bed elf32_arm_vxworks_bed
12520
906e58ca
NC
12521#undef bfd_elf32_bfd_link_hash_table_create
12522#define bfd_elf32_bfd_link_hash_table_create elf32_arm_vxworks_link_hash_table_create
12523#undef elf_backend_add_symbol_hook
12524#define elf_backend_add_symbol_hook elf_vxworks_add_symbol_hook
12525#undef elf_backend_final_write_processing
12526#define elf_backend_final_write_processing elf32_arm_vxworks_final_write_processing
12527#undef elf_backend_emit_relocs
12528#define elf_backend_emit_relocs elf_vxworks_emit_relocs
4e7fd91e 12529
906e58ca 12530#undef elf_backend_may_use_rel_p
00a97672 12531#define elf_backend_may_use_rel_p 0
906e58ca 12532#undef elf_backend_may_use_rela_p
00a97672 12533#define elf_backend_may_use_rela_p 1
906e58ca 12534#undef elf_backend_default_use_rela_p
00a97672 12535#define elf_backend_default_use_rela_p 1
906e58ca 12536#undef elf_backend_want_plt_sym
00a97672 12537#define elf_backend_want_plt_sym 1
906e58ca 12538#undef ELF_MAXPAGESIZE
00a97672 12539#define ELF_MAXPAGESIZE 0x1000
4e7fd91e
PB
12540
12541#include "elf32-target.h"
12542
12543
906e58ca 12544/* Symbian OS Targets. */
7f266840 12545
906e58ca 12546#undef TARGET_LITTLE_SYM
7f266840 12547#define TARGET_LITTLE_SYM bfd_elf32_littlearm_symbian_vec
906e58ca 12548#undef TARGET_LITTLE_NAME
7f266840 12549#define TARGET_LITTLE_NAME "elf32-littlearm-symbian"
906e58ca 12550#undef TARGET_BIG_SYM
7f266840 12551#define TARGET_BIG_SYM bfd_elf32_bigarm_symbian_vec
906e58ca 12552#undef TARGET_BIG_NAME
7f266840
DJ
12553#define TARGET_BIG_NAME "elf32-bigarm-symbian"
12554
12555/* Like elf32_arm_link_hash_table_create -- but overrides
12556 appropriately for Symbian OS. */
906e58ca 12557
7f266840
DJ
12558static struct bfd_link_hash_table *
12559elf32_arm_symbian_link_hash_table_create (bfd *abfd)
12560{
12561 struct bfd_link_hash_table *ret;
12562
12563 ret = elf32_arm_link_hash_table_create (abfd);
12564 if (ret)
12565 {
12566 struct elf32_arm_link_hash_table *htab
12567 = (struct elf32_arm_link_hash_table *)ret;
12568 /* There is no PLT header for Symbian OS. */
12569 htab->plt_header_size = 0;
95720a86
DJ
12570 /* The PLT entries are each one instruction and one word. */
12571 htab->plt_entry_size = 4 * ARRAY_SIZE (elf32_arm_symbian_plt_entry);
7f266840 12572 htab->symbian_p = 1;
33bfe774
JB
12573 /* Symbian uses armv5t or above, so use_blx is always true. */
12574 htab->use_blx = 1;
67687978 12575 htab->root.is_relocatable_executable = 1;
7f266840
DJ
12576 }
12577 return ret;
906e58ca 12578}
7f266840 12579
b35d266b 12580static const struct bfd_elf_special_section
551b43fd 12581elf32_arm_symbian_special_sections[] =
7f266840 12582{
5cd3778d
MM
12583 /* In a BPABI executable, the dynamic linking sections do not go in
12584 the loadable read-only segment. The post-linker may wish to
12585 refer to these sections, but they are not part of the final
12586 program image. */
0112cd26
NC
12587 { STRING_COMMA_LEN (".dynamic"), 0, SHT_DYNAMIC, 0 },
12588 { STRING_COMMA_LEN (".dynstr"), 0, SHT_STRTAB, 0 },
12589 { STRING_COMMA_LEN (".dynsym"), 0, SHT_DYNSYM, 0 },
12590 { STRING_COMMA_LEN (".got"), 0, SHT_PROGBITS, 0 },
12591 { STRING_COMMA_LEN (".hash"), 0, SHT_HASH, 0 },
5cd3778d
MM
12592 /* These sections do not need to be writable as the SymbianOS
12593 postlinker will arrange things so that no dynamic relocation is
12594 required. */
0112cd26
NC
12595 { STRING_COMMA_LEN (".init_array"), 0, SHT_INIT_ARRAY, SHF_ALLOC },
12596 { STRING_COMMA_LEN (".fini_array"), 0, SHT_FINI_ARRAY, SHF_ALLOC },
12597 { STRING_COMMA_LEN (".preinit_array"), 0, SHT_PREINIT_ARRAY, SHF_ALLOC },
12598 { NULL, 0, 0, 0, 0 }
7f266840
DJ
12599};
12600
c3c76620 12601static void
906e58ca 12602elf32_arm_symbian_begin_write_processing (bfd *abfd,
a4fd1a8e 12603 struct bfd_link_info *link_info)
c3c76620
MM
12604{
12605 /* BPABI objects are never loaded directly by an OS kernel; they are
12606 processed by a postlinker first, into an OS-specific format. If
12607 the D_PAGED bit is set on the file, BFD will align segments on
12608 page boundaries, so that an OS can directly map the file. With
12609 BPABI objects, that just results in wasted space. In addition,
12610 because we clear the D_PAGED bit, map_sections_to_segments will
12611 recognize that the program headers should not be mapped into any
12612 loadable segment. */
12613 abfd->flags &= ~D_PAGED;
906e58ca 12614 elf32_arm_begin_write_processing (abfd, link_info);
c3c76620 12615}
7f266840
DJ
12616
12617static bfd_boolean
906e58ca 12618elf32_arm_symbian_modify_segment_map (bfd *abfd,
b294bdf8 12619 struct bfd_link_info *info)
7f266840
DJ
12620{
12621 struct elf_segment_map *m;
12622 asection *dynsec;
12623
7f266840
DJ
12624 /* BPABI shared libraries and executables should have a PT_DYNAMIC
12625 segment. However, because the .dynamic section is not marked
12626 with SEC_LOAD, the generic ELF code will not create such a
12627 segment. */
12628 dynsec = bfd_get_section_by_name (abfd, ".dynamic");
12629 if (dynsec)
12630 {
8ded5a0f
AM
12631 for (m = elf_tdata (abfd)->segment_map; m != NULL; m = m->next)
12632 if (m->p_type == PT_DYNAMIC)
12633 break;
12634
12635 if (m == NULL)
12636 {
12637 m = _bfd_elf_make_dynamic_segment (abfd, dynsec);
12638 m->next = elf_tdata (abfd)->segment_map;
12639 elf_tdata (abfd)->segment_map = m;
12640 }
7f266840
DJ
12641 }
12642
b294bdf8
MM
12643 /* Also call the generic arm routine. */
12644 return elf32_arm_modify_segment_map (abfd, info);
7f266840
DJ
12645}
12646
95720a86
DJ
12647/* Return address for Ith PLT stub in section PLT, for relocation REL
12648 or (bfd_vma) -1 if it should not be included. */
12649
12650static bfd_vma
12651elf32_arm_symbian_plt_sym_val (bfd_vma i, const asection *plt,
12652 const arelent *rel ATTRIBUTE_UNUSED)
12653{
12654 return plt->vma + 4 * ARRAY_SIZE (elf32_arm_symbian_plt_entry) * i;
12655}
12656
12657
8029a119 12658#undef elf32_bed
7f266840
DJ
12659#define elf32_bed elf32_arm_symbian_bed
12660
12661/* The dynamic sections are not allocated on SymbianOS; the postlinker
12662 will process them and then discard them. */
906e58ca 12663#undef ELF_DYNAMIC_SEC_FLAGS
7f266840
DJ
12664#define ELF_DYNAMIC_SEC_FLAGS \
12665 (SEC_HAS_CONTENTS | SEC_IN_MEMORY | SEC_LINKER_CREATED)
12666
00a97672 12667#undef elf_backend_add_symbol_hook
00a97672 12668#undef elf_backend_emit_relocs
c3c76620 12669
906e58ca
NC
12670#undef bfd_elf32_bfd_link_hash_table_create
12671#define bfd_elf32_bfd_link_hash_table_create elf32_arm_symbian_link_hash_table_create
12672#undef elf_backend_special_sections
12673#define elf_backend_special_sections elf32_arm_symbian_special_sections
12674#undef elf_backend_begin_write_processing
12675#define elf_backend_begin_write_processing elf32_arm_symbian_begin_write_processing
12676#undef elf_backend_final_write_processing
12677#define elf_backend_final_write_processing elf32_arm_final_write_processing
12678
12679#undef elf_backend_modify_segment_map
7f266840
DJ
12680#define elf_backend_modify_segment_map elf32_arm_symbian_modify_segment_map
12681
12682/* There is no .got section for BPABI objects, and hence no header. */
906e58ca 12683#undef elf_backend_got_header_size
7f266840
DJ
12684#define elf_backend_got_header_size 0
12685
12686/* Similarly, there is no .got.plt section. */
906e58ca 12687#undef elf_backend_want_got_plt
7f266840
DJ
12688#define elf_backend_want_got_plt 0
12689
906e58ca 12690#undef elf_backend_plt_sym_val
95720a86
DJ
12691#define elf_backend_plt_sym_val elf32_arm_symbian_plt_sym_val
12692
906e58ca 12693#undef elf_backend_may_use_rel_p
00a97672 12694#define elf_backend_may_use_rel_p 1
906e58ca 12695#undef elf_backend_may_use_rela_p
00a97672 12696#define elf_backend_may_use_rela_p 0
906e58ca 12697#undef elf_backend_default_use_rela_p
00a97672 12698#define elf_backend_default_use_rela_p 0
906e58ca 12699#undef elf_backend_want_plt_sym
00a97672 12700#define elf_backend_want_plt_sym 0
906e58ca 12701#undef ELF_MAXPAGESIZE
00a97672 12702#define ELF_MAXPAGESIZE 0x8000
4e7fd91e 12703
7f266840 12704#include "elf32-target.h"
This page took 1.294724 seconds and 4 git commands to generate.