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