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