1 /* 32-bit ELF support for ARM new abi option.
2 Copyright 1999 Free Software Foundation, Inc.
4 This file is part of BFD, the Binary File Descriptor library.
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
27 #define NUM_ELEM(a) (sizeof (a) / (sizeof (a)[0]))
32 #define TARGET_LITTLE_SYM bfd_elf32_littlearm_vec
33 #define TARGET_LITTLE_NAME "elf32-littlearm"
34 #define TARGET_BIG_SYM bfd_elf32_bigarm_vec
35 #define TARGET_BIG_NAME "elf32-bigarm"
37 #define elf_info_to_howto 0
38 #define elf_info_to_howto_rel elf32_arm_info_to_howto
40 #define ARM_ELF_ABI_VERSION 0
41 #define ARM_ELF_OS_ABI_VERSION ELFOSABI_ARM
43 static reloc_howto_type
* elf32_arm_reloc_type_lookup
44 PARAMS ((bfd
* abfd
, bfd_reloc_code_real_type code
));
46 /* Note: code such as elf32_arm_reloc_type_lookup expect to use e.g.
47 R_ARM_PC24 as an index into this, and find the R_ARM_PC24 HOWTO
50 static reloc_howto_type elf32_arm_howto_table
[] =
53 HOWTO (R_ARM_NONE
, /* type */
55 0, /* size (0 = byte, 1 = short, 2 = long) */
57 false, /* pc_relative */
59 complain_overflow_dont
,/* complain_on_overflow */
60 bfd_elf_generic_reloc
, /* special_function */
61 "R_ARM_NONE", /* name */
62 false, /* partial_inplace */
65 false), /* pcrel_offset */
67 HOWTO (R_ARM_PC24
, /* type */
69 2, /* size (0 = byte, 1 = short, 2 = long) */
71 true, /* pc_relative */
73 complain_overflow_signed
,/* complain_on_overflow */
74 bfd_elf_generic_reloc
, /* special_function */
75 "R_ARM_PC24", /* name */
76 false, /* partial_inplace */
77 0x00ffffff, /* src_mask */
78 0x00ffffff, /* dst_mask */
79 true), /* pcrel_offset */
82 HOWTO (R_ARM_ABS32
, /* type */
84 2, /* size (0 = byte, 1 = short, 2 = long) */
86 false, /* pc_relative */
88 complain_overflow_bitfield
,/* complain_on_overflow */
89 bfd_elf_generic_reloc
, /* special_function */
90 "R_ARM_ABS32", /* name */
91 false, /* partial_inplace */
92 0xffffffff, /* src_mask */
93 0xffffffff, /* dst_mask */
94 false), /* pcrel_offset */
96 /* standard 32bit pc-relative reloc */
97 HOWTO (R_ARM_REL32
, /* type */
99 2, /* size (0 = byte, 1 = short, 2 = long) */
101 true, /* pc_relative */
103 complain_overflow_bitfield
,/* complain_on_overflow */
104 bfd_elf_generic_reloc
, /* special_function */
105 "R_ARM_REL32", /* name */
106 false, /* partial_inplace */
107 0xffffffff, /* src_mask */
108 0xffffffff, /* dst_mask */
109 true), /* pcrel_offset */
112 HOWTO (R_ARM_PC13
, /* type */
114 0, /* size (0 = byte, 1 = short, 2 = long) */
116 false, /* pc_relative */
118 complain_overflow_bitfield
,/* complain_on_overflow */
119 bfd_elf_generic_reloc
, /* special_function */
120 "R_ARM_PC13", /* name */
121 false, /* partial_inplace */
122 0x000000ff, /* src_mask */
123 0x000000ff, /* dst_mask */
124 false), /* pcrel_offset */
126 /* 16 bit absolute */
127 HOWTO (R_ARM_ABS16
, /* type */
129 1, /* size (0 = byte, 1 = short, 2 = long) */
131 false, /* pc_relative */
133 complain_overflow_bitfield
,/* complain_on_overflow */
134 bfd_elf_generic_reloc
, /* special_function */
135 "R_ARM_ABS16", /* name */
136 false, /* partial_inplace */
139 false), /* pcrel_offset */
141 /* 12 bit absolute */
142 HOWTO (R_ARM_ABS12
, /* type */
144 2, /* size (0 = byte, 1 = short, 2 = long) */
146 false, /* pc_relative */
148 complain_overflow_bitfield
,/* complain_on_overflow */
149 bfd_elf_generic_reloc
, /* special_function */
150 "R_ARM_ABS12", /* name */
151 false, /* partial_inplace */
152 0x000008ff, /* src_mask */
153 0x000008ff, /* dst_mask */
154 false), /* pcrel_offset */
156 HOWTO (R_ARM_THM_ABS5
, /* type */
158 1, /* size (0 = byte, 1 = short, 2 = long) */
160 false, /* pc_relative */
162 complain_overflow_bitfield
,/* complain_on_overflow */
163 bfd_elf_generic_reloc
, /* special_function */
164 "R_ARM_THM_ABS5", /* name */
165 false, /* partial_inplace */
166 0x000007e0, /* src_mask */
167 0x000007e0, /* dst_mask */
168 false), /* pcrel_offset */
171 HOWTO (R_ARM_ABS8
, /* type */
173 0, /* size (0 = byte, 1 = short, 2 = long) */
175 false, /* pc_relative */
177 complain_overflow_bitfield
,/* complain_on_overflow */
178 bfd_elf_generic_reloc
, /* special_function */
179 "R_ARM_ABS8", /* name */
180 false, /* partial_inplace */
181 0x000000ff, /* src_mask */
182 0x000000ff, /* dst_mask */
183 false), /* pcrel_offset */
185 HOWTO (R_ARM_SBREL32
, /* type */
187 0, /* size (0 = byte, 1 = short, 2 = long) */
189 false, /* pc_relative */
191 complain_overflow_dont
,/* complain_on_overflow */
192 bfd_elf_generic_reloc
, /* special_function */
193 "R_ARM_SBREL32", /* name */
194 false, /* partial_inplace */
197 false), /* pcrel_offset */
199 HOWTO (R_ARM_THM_PC22
, /* type */
201 2, /* size (0 = byte, 1 = short, 2 = long) */
203 true, /* pc_relative */
205 complain_overflow_signed
,/* complain_on_overflow */
206 bfd_elf_generic_reloc
, /* special_function */
207 "R_ARM_THM_PC22", /* name */
208 false, /* partial_inplace */
209 0x07ff07ff, /* src_mask */
210 0x07ff07ff, /* dst_mask */
211 true), /* pcrel_offset */
213 HOWTO (R_ARM_THM_PC8
, /* type */
215 1, /* size (0 = byte, 1 = short, 2 = long) */
217 true, /* pc_relative */
219 complain_overflow_signed
,/* complain_on_overflow */
220 bfd_elf_generic_reloc
, /* special_function */
221 "R_ARM_THM_PC8", /* name */
222 false, /* partial_inplace */
223 0x000000ff, /* src_mask */
224 0x000000ff, /* dst_mask */
225 true), /* pcrel_offset */
227 HOWTO (R_ARM_AMP_VCALL9
, /* type */
229 1, /* size (0 = byte, 1 = short, 2 = long) */
231 true, /* pc_relative */
233 complain_overflow_signed
,/* complain_on_overflow */
234 bfd_elf_generic_reloc
, /* special_function */
235 "R_ARM_AMP_VCALL9", /* name */
236 false, /* partial_inplace */
237 0x000000ff, /* src_mask */
238 0x000000ff, /* dst_mask */
239 true), /* pcrel_offset */
241 HOWTO (R_ARM_SWI24
, /* type */
243 0, /* size (0 = byte, 1 = short, 2 = long) */
245 false, /* pc_relative */
247 complain_overflow_signed
,/* complain_on_overflow */
248 bfd_elf_generic_reloc
, /* special_function */
249 "R_ARM_SWI24", /* name */
250 false, /* partial_inplace */
251 0x00000000, /* src_mask */
252 0x00000000, /* dst_mask */
253 false), /* pcrel_offset */
255 HOWTO (R_ARM_THM_SWI8
, /* type */
257 0, /* size (0 = byte, 1 = short, 2 = long) */
259 false, /* pc_relative */
261 complain_overflow_signed
,/* complain_on_overflow */
262 bfd_elf_generic_reloc
, /* special_function */
263 "R_ARM_SWI8", /* name */
264 false, /* partial_inplace */
265 0x00000000, /* src_mask */
266 0x00000000, /* dst_mask */
267 false), /* pcrel_offset */
269 /* BLX instruction for the ARM. */
270 HOWTO (R_ARM_XPC25
, /* type */
272 2, /* size (0 = byte, 1 = short, 2 = long) */
274 true, /* pc_relative */
276 complain_overflow_signed
,/* complain_on_overflow */
277 bfd_elf_generic_reloc
, /* special_function */
278 "R_ARM_XPC25", /* name */
279 false, /* partial_inplace */
280 0x00ffffff, /* src_mask */
281 0x00ffffff, /* dst_mask */
282 true), /* pcrel_offset */
284 /* BLX instruction for the Thumb. */
285 HOWTO (R_ARM_THM_XPC22
, /* type */
287 2, /* size (0 = byte, 1 = short, 2 = long) */
289 true, /* pc_relative */
291 complain_overflow_signed
,/* complain_on_overflow */
292 bfd_elf_generic_reloc
, /* special_function */
293 "R_ARM_THM_XPC22", /* name */
294 false, /* partial_inplace */
295 0x07ff07ff, /* src_mask */
296 0x07ff07ff, /* dst_mask */
297 true), /* pcrel_offset */
299 /* These next three relocs are not defined, but we need to fill the space. */
301 HOWTO (R_ARM_NONE
, /* type */
303 0, /* size (0 = byte, 1 = short, 2 = long) */
305 false, /* pc_relative */
307 complain_overflow_dont
,/* complain_on_overflow */
308 bfd_elf_generic_reloc
, /* special_function */
309 "R_ARM_unknown_17", /* name */
310 false, /* partial_inplace */
313 false), /* pcrel_offset */
315 HOWTO (R_ARM_NONE
, /* type */
317 0, /* size (0 = byte, 1 = short, 2 = long) */
319 false, /* pc_relative */
321 complain_overflow_dont
,/* complain_on_overflow */
322 bfd_elf_generic_reloc
, /* special_function */
323 "R_ARM_unknown_18", /* name */
324 false, /* partial_inplace */
327 false), /* pcrel_offset */
329 HOWTO (R_ARM_NONE
, /* type */
331 0, /* size (0 = byte, 1 = short, 2 = long) */
333 false, /* pc_relative */
335 complain_overflow_dont
,/* complain_on_overflow */
336 bfd_elf_generic_reloc
, /* special_function */
337 "R_ARM_unknown_19", /* name */
338 false, /* partial_inplace */
341 false), /* pcrel_offset */
343 /* Relocs used in ARM Linux */
345 HOWTO (R_ARM_COPY
, /* type */
347 2, /* size (0 = byte, 1 = short, 2 = long) */
349 false, /* pc_relative */
351 complain_overflow_bitfield
,/* complain_on_overflow */
352 bfd_elf_generic_reloc
, /* special_function */
353 "R_ARM_COPY", /* name */
354 true, /* partial_inplace */
355 0xffffffff, /* src_mask */
356 0xffffffff, /* dst_mask */
357 false), /* pcrel_offset */
359 HOWTO (R_ARM_GLOB_DAT
, /* type */
361 2, /* size (0 = byte, 1 = short, 2 = long) */
363 false, /* pc_relative */
365 complain_overflow_bitfield
,/* complain_on_overflow */
366 bfd_elf_generic_reloc
, /* special_function */
367 "R_ARM_GLOB_DAT", /* name */
368 true, /* partial_inplace */
369 0xffffffff, /* src_mask */
370 0xffffffff, /* dst_mask */
371 false), /* pcrel_offset */
373 HOWTO (R_ARM_JUMP_SLOT
, /* type */
375 2, /* size (0 = byte, 1 = short, 2 = long) */
377 false, /* pc_relative */
379 complain_overflow_bitfield
,/* complain_on_overflow */
380 bfd_elf_generic_reloc
, /* special_function */
381 "R_ARM_JUMP_SLOT", /* name */
382 true, /* partial_inplace */
383 0xffffffff, /* src_mask */
384 0xffffffff, /* dst_mask */
385 false), /* pcrel_offset */
387 HOWTO (R_ARM_RELATIVE
, /* type */
389 2, /* size (0 = byte, 1 = short, 2 = long) */
391 false, /* pc_relative */
393 complain_overflow_bitfield
,/* complain_on_overflow */
394 bfd_elf_generic_reloc
, /* special_function */
395 "R_ARM_RELATIVE", /* name */
396 true, /* partial_inplace */
397 0xffffffff, /* src_mask */
398 0xffffffff, /* dst_mask */
399 false), /* pcrel_offset */
401 HOWTO (R_ARM_GOTOFF
, /* type */
403 2, /* size (0 = byte, 1 = short, 2 = long) */
405 false, /* pc_relative */
407 complain_overflow_bitfield
,/* complain_on_overflow */
408 bfd_elf_generic_reloc
, /* special_function */
409 "R_ARM_GOTOFF", /* name */
410 true, /* partial_inplace */
411 0xffffffff, /* src_mask */
412 0xffffffff, /* dst_mask */
413 false), /* pcrel_offset */
415 HOWTO (R_ARM_GOTPC
, /* type */
417 2, /* size (0 = byte, 1 = short, 2 = long) */
419 true, /* pc_relative */
421 complain_overflow_bitfield
,/* complain_on_overflow */
422 bfd_elf_generic_reloc
, /* special_function */
423 "R_ARM_GOTPC", /* name */
424 true, /* partial_inplace */
425 0xffffffff, /* src_mask */
426 0xffffffff, /* dst_mask */
427 true), /* pcrel_offset */
429 HOWTO (R_ARM_GOT32
, /* type */
431 2, /* size (0 = byte, 1 = short, 2 = long) */
433 false, /* pc_relative */
435 complain_overflow_bitfield
,/* complain_on_overflow */
436 bfd_elf_generic_reloc
, /* special_function */
437 "R_ARM_GOT32", /* name */
438 true, /* partial_inplace */
439 0xffffffff, /* src_mask */
440 0xffffffff, /* dst_mask */
441 false), /* pcrel_offset */
443 HOWTO (R_ARM_PLT32
, /* type */
445 2, /* size (0 = byte, 1 = short, 2 = long) */
447 true, /* pc_relative */
449 complain_overflow_bitfield
,/* complain_on_overflow */
450 bfd_elf_generic_reloc
, /* special_function */
451 "R_ARM_PLT32", /* name */
452 true, /* partial_inplace */
453 0x00ffffff, /* src_mask */
454 0x00ffffff, /* dst_mask */
455 true), /* pcrel_offset */
457 /* End of relocs used in ARM Linux */
459 HOWTO (R_ARM_RREL32
, /* type */
461 0, /* size (0 = byte, 1 = short, 2 = long) */
463 false, /* pc_relative */
465 complain_overflow_dont
,/* complain_on_overflow */
466 bfd_elf_generic_reloc
, /* special_function */
467 "R_ARM_RREL32", /* name */
468 false, /* partial_inplace */
471 false), /* pcrel_offset */
473 HOWTO (R_ARM_RABS32
, /* type */
475 0, /* size (0 = byte, 1 = short, 2 = long) */
477 false, /* pc_relative */
479 complain_overflow_dont
,/* complain_on_overflow */
480 bfd_elf_generic_reloc
, /* special_function */
481 "R_ARM_RABS32", /* name */
482 false, /* partial_inplace */
485 false), /* pcrel_offset */
487 HOWTO (R_ARM_RPC24
, /* type */
489 0, /* size (0 = byte, 1 = short, 2 = long) */
491 false, /* pc_relative */
493 complain_overflow_dont
,/* complain_on_overflow */
494 bfd_elf_generic_reloc
, /* special_function */
495 "R_ARM_RPC24", /* name */
496 false, /* partial_inplace */
499 false), /* pcrel_offset */
501 HOWTO (R_ARM_RBASE
, /* type */
503 0, /* size (0 = byte, 1 = short, 2 = long) */
505 false, /* pc_relative */
507 complain_overflow_dont
,/* complain_on_overflow */
508 bfd_elf_generic_reloc
, /* special_function */
509 "R_ARM_RBASE", /* name */
510 false, /* partial_inplace */
513 false), /* pcrel_offset */
517 /* GNU extension to record C++ vtable hierarchy */
518 static reloc_howto_type elf32_arm_vtinherit_howto
=
519 HOWTO (R_ARM_GNU_VTINHERIT
, /* type */
521 2, /* size (0 = byte, 1 = short, 2 = long) */
523 false, /* pc_relative */
525 complain_overflow_dont
, /* complain_on_overflow */
526 NULL
, /* special_function */
527 "R_ARM_GNU_VTINHERIT", /* name */
528 false, /* partial_inplace */
531 false); /* pcrel_offset */
533 /* GNU extension to record C++ vtable member usage */
534 static reloc_howto_type elf32_arm_vtentry_howto
=
535 HOWTO (R_ARM_GNU_VTENTRY
, /* type */
537 2, /* size (0 = byte, 1 = short, 2 = long) */
539 false, /* pc_relative */
541 complain_overflow_dont
, /* complain_on_overflow */
542 _bfd_elf_rel_vtable_reloc_fn
, /* special_function */
543 "R_ARM_GNU_VTENTRY", /* name */
544 false, /* partial_inplace */
547 false); /* pcrel_offset */
549 /* 12 bit pc relative */
550 static reloc_howto_type elf32_arm_thm_pc11_howto
=
551 HOWTO (R_ARM_THM_PC11
, /* type */
553 1, /* size (0 = byte, 1 = short, 2 = long) */
555 true, /* pc_relative */
557 complain_overflow_signed
, /* complain_on_overflow */
558 bfd_elf_generic_reloc
, /* special_function */
559 "R_ARM_THM_PC11", /* name */
560 false, /* partial_inplace */
561 0x000007ff, /* src_mask */
562 0x000007ff, /* dst_mask */
563 true); /* pcrel_offset */
565 /* 12 bit pc relative */
566 static reloc_howto_type elf32_arm_thm_pc9_howto
=
567 HOWTO (R_ARM_THM_PC9
, /* type */
569 1, /* size (0 = byte, 1 = short, 2 = long) */
571 true, /* pc_relative */
573 complain_overflow_signed
, /* complain_on_overflow */
574 bfd_elf_generic_reloc
, /* special_function */
575 "R_ARM_THM_PC9", /* name */
576 false, /* partial_inplace */
577 0x000000ff, /* src_mask */
578 0x000000ff, /* dst_mask */
579 true); /* pcrel_offset */
583 elf32_arm_info_to_howto (abfd
, bfd_reloc
, elf_reloc
)
584 bfd
* abfd ATTRIBUTE_UNUSED
;
586 Elf32_Internal_Rel
* elf_reloc
;
590 r_type
= ELF32_R_TYPE (elf_reloc
->r_info
);
594 case R_ARM_GNU_VTINHERIT
:
595 bfd_reloc
->howto
= & elf32_arm_vtinherit_howto
;
598 case R_ARM_GNU_VTENTRY
:
599 bfd_reloc
->howto
= & elf32_arm_vtentry_howto
;
603 bfd_reloc
->howto
= & elf32_arm_thm_pc11_howto
;
607 bfd_reloc
->howto
= & elf32_arm_thm_pc9_howto
;
611 if (r_type
>= NUM_ELEM (elf32_arm_howto_table
))
612 bfd_reloc
->howto
= NULL
;
614 bfd_reloc
->howto
= & elf32_arm_howto_table
[r_type
];
619 struct elf32_arm_reloc_map
621 bfd_reloc_code_real_type bfd_reloc_val
;
622 unsigned char elf_reloc_val
;
625 static const struct elf32_arm_reloc_map elf32_arm_reloc_map
[] =
627 {BFD_RELOC_NONE
, R_ARM_NONE
},
628 {BFD_RELOC_ARM_PCREL_BRANCH
, R_ARM_PC24
},
629 {BFD_RELOC_ARM_PCREL_BLX
, R_ARM_XPC25
},
630 {BFD_RELOC_THUMB_PCREL_BLX
, R_ARM_THM_XPC22
},
631 {BFD_RELOC_32
, R_ARM_ABS32
},
632 {BFD_RELOC_32_PCREL
, R_ARM_REL32
},
633 {BFD_RELOC_8
, R_ARM_ABS8
},
634 {BFD_RELOC_16
, R_ARM_ABS16
},
635 {BFD_RELOC_ARM_OFFSET_IMM
, R_ARM_ABS12
},
636 {BFD_RELOC_ARM_THUMB_OFFSET
, R_ARM_THM_ABS5
},
637 {BFD_RELOC_THUMB_PCREL_BRANCH23
, R_ARM_THM_PC22
},
638 {BFD_RELOC_ARM_COPY
, R_ARM_COPY
},
639 {BFD_RELOC_ARM_GLOB_DAT
, R_ARM_GLOB_DAT
},
640 {BFD_RELOC_ARM_JUMP_SLOT
, R_ARM_JUMP_SLOT
},
641 {BFD_RELOC_ARM_RELATIVE
, R_ARM_RELATIVE
},
642 {BFD_RELOC_ARM_GOTOFF
, R_ARM_GOTOFF
},
643 {BFD_RELOC_ARM_GOTPC
, R_ARM_GOTPC
},
644 {BFD_RELOC_ARM_GOT32
, R_ARM_GOT32
},
645 {BFD_RELOC_ARM_PLT32
, R_ARM_PLT32
}
648 static reloc_howto_type
*
649 elf32_arm_reloc_type_lookup (abfd
, code
)
650 bfd
*abfd ATTRIBUTE_UNUSED
;
651 bfd_reloc_code_real_type code
;
657 case BFD_RELOC_VTABLE_INHERIT
:
658 return & elf32_arm_vtinherit_howto
;
660 case BFD_RELOC_VTABLE_ENTRY
:
661 return & elf32_arm_vtentry_howto
;
663 case BFD_RELOC_THUMB_PCREL_BRANCH12
:
664 return & elf32_arm_thm_pc11_howto
;
666 case BFD_RELOC_THUMB_PCREL_BRANCH9
:
667 return & elf32_arm_thm_pc9_howto
;
670 for (i
= 0; i
< NUM_ELEM (elf32_arm_reloc_map
); i
++)
671 if (elf32_arm_reloc_map
[i
].bfd_reloc_val
== code
)
672 return & elf32_arm_howto_table
[elf32_arm_reloc_map
[i
].elf_reloc_val
];
678 #include "elf32-arm.h"