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