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