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