1 /* BFD back-end for ARM COFF files.
2 Copyright 1990, 1991, 1992, 1993, 1994, 1995 Free Software Foundation, Inc.
3 Written by Cygnus Support.
5 This file is part of BFD, the Binary File Descriptor library.
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.
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.
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
19 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
28 #include "coff/internal.h"
36 static bfd_reloc_status_type
37 aoutarm_fix_pcrel_26_done PARAMS ((bfd *, arelent *, asymbol *, PTR,
38 asection *, bfd *, char **));
40 static bfd_reloc_status_type
41 aoutarm_fix_pcrel_26 PARAMS ((bfd *, arelent *, asymbol *, PTR,
42 asection *, bfd *, char **));
45 static bfd_reloc_status_type coff_arm_reloc
46 PARAMS ((bfd *, arelent *, asymbol *, PTR, asection *, bfd *, char **));
49 /* Used by the assembler. */
50 static bfd_reloc_status_type
51 coff_arm_reloc (abfd, reloc_entry, symbol, data, input_section, output_bfd,
57 asection *input_section;
62 if (output_bfd == (bfd *) NULL)
63 return bfd_reloc_continue;
65 diff = reloc_entry->addend;
68 x = ((x & ~howto->dst_mask) | (((x & howto->src_mask) + diff) & howto->dst_mask))
72 reloc_howto_type *howto = reloc_entry->howto;
73 unsigned char *addr = (unsigned char *) data + reloc_entry->address;
79 char x = bfd_get_8 (abfd, addr);
81 bfd_put_8 (abfd, x, addr);
87 short x = bfd_get_16 (abfd, addr);
89 bfd_put_16 (abfd, x, addr);
95 long x = bfd_get_32 (abfd, addr);
97 bfd_put_32 (abfd, x, addr);
106 /* Now let bfd_perform_relocation finish everything up. */
107 return bfd_reloc_continue;
111 #define PCRELOFFSET true
114 static reloc_howto_type aoutarm_std_reloc_howto[] =
116 /* type rs size bsz pcrel bitpos ovrf sf name part_inpl readmask setmask pcdone */
123 complain_overflow_bitfield, /* ovf */
124 coff_arm_reloc, /* sf */
127 0x000000ff, /*read mask */
128 0x000000ff, /* setmask */
129 PCRELOFFSET /* pcdone */),
136 complain_overflow_bitfield,
149 complain_overflow_bitfield,
162 complain_overflow_signed,
163 aoutarm_fix_pcrel_26 ,
175 complain_overflow_signed,
188 complain_overflow_signed,
201 complain_overflow_signed,
214 complain_overflow_signed,
215 aoutarm_fix_pcrel_26_done,
228 complain_overflow_bitfield,
241 complain_overflow_bitfield,
254 complain_overflow_bitfield,
263 /* Return true if this relocation should
264 appear in the output .reloc section. */
266 static boolean in_reloc_p (abfd, howto)
268 reloc_howto_type *howto;
270 return !howto->pc_relative && howto->type != 11;
275 #define RTYPE2HOWTO(cache_ptr, dst) \
276 (cache_ptr)->howto = aoutarm_std_reloc_howto + (dst)->r_type;
278 #define coff_rtype_to_howto coff_arm_rtype_to_howto
280 static reloc_howto_type *
281 coff_arm_rtype_to_howto (abfd, sec, rel, h, sym, addendp)
284 struct internal_reloc *rel;
285 struct coff_link_hash_entry *h;
286 struct internal_syment *sym;
289 reloc_howto_type *howto;
291 howto = aoutarm_std_reloc_howto + rel->r_type;
293 if (rel->r_type == 11)
295 *addendp -= pe_data(sec->output_section->owner)->pe_opthdr.ImageBase;
300 /* Used by the assembler. */
302 static bfd_reloc_status_type
303 aoutarm_fix_pcrel_26_done (abfd, reloc_entry, symbol, data, input_section,
304 output_bfd, error_message)
306 arelent *reloc_entry;
309 asection *input_section;
311 char **error_message;
313 /* This is dead simple at present. */
317 /* Used by the assembler. */
319 static bfd_reloc_status_type
320 aoutarm_fix_pcrel_26 (abfd, reloc_entry, symbol, data, input_section,
321 output_bfd, error_message)
323 arelent *reloc_entry;
326 asection *input_section;
328 char **error_message;
331 bfd_size_type addr = reloc_entry->address;
332 long target = bfd_get_32 (abfd, (bfd_byte *) data + addr);
333 bfd_reloc_status_type flag = bfd_reloc_ok;
335 /* If this is an undefined symbol, return error */
336 if (symbol->section == &bfd_und_section
337 && (symbol->flags & BSF_WEAK) == 0)
338 return output_bfd ? bfd_reloc_continue : bfd_reloc_undefined;
340 /* If the sections are different, and we are doing a partial relocation,
341 just ignore it for now. */
342 if (symbol->section->name != input_section->name
343 && output_bfd != (bfd *)NULL)
344 return bfd_reloc_continue;
346 relocation = (target & 0x00ffffff) << 2;
347 relocation = (relocation ^ 0x02000000) - 0x02000000; /* Sign extend */
348 relocation += symbol->value;
349 relocation += symbol->section->output_section->vma;
350 relocation += symbol->section->output_offset;
351 relocation += reloc_entry->addend;
352 relocation -= input_section->output_section->vma;
353 relocation -= input_section->output_offset;
356 return bfd_reloc_overflow;
358 /* Check for overflow */
359 if (relocation & 0x02000000)
361 if ((relocation & ~0x03ffffff) != ~0x03ffffff)
362 flag = bfd_reloc_overflow;
364 else if (relocation & ~0x03ffffff)
365 flag = bfd_reloc_overflow;
367 target &= ~0x00ffffff;
368 target |= (relocation >> 2) & 0x00ffffff;
369 bfd_put_32 (abfd, target, (bfd_byte *) data + addr);
371 /* Now the ARM magic... Change the reloc type so that it is marked as done.
372 Strictly this is only necessary if we are doing a partial relocation. */
373 reloc_entry->howto = &aoutarm_std_reloc_howto[7];
379 static CONST struct reloc_howto_struct *
380 arm_reloc_type_lookup(abfd,code)
382 bfd_reloc_code_real_type code;
384 #define ASTD(i,j) case i: return &aoutarm_std_reloc_howto[j]
385 if (code == BFD_RELOC_CTOR)
386 switch (bfd_get_arch_info (abfd)->bits_per_address)
391 default: return (CONST struct reloc_howto_struct *) 0;
396 ASTD (BFD_RELOC_16, 1);
397 ASTD (BFD_RELOC_32, 2);
398 ASTD (BFD_RELOC_ARM_PCREL_BRANCH, 3);
399 ASTD (BFD_RELOC_8_PCREL, 4);
400 ASTD (BFD_RELOC_16_PCREL, 5);
401 ASTD (BFD_RELOC_32_PCREL, 6);
402 ASTD (BFD_RELOC_RVA, 11);
403 default: return (CONST struct reloc_howto_struct *) 0;
408 #define coff_bfd_reloc_type_lookup arm_reloc_type_lookup
410 #define COFF_DEFAULT_SECTION_ALIGNMENT_POWER (2)
411 #define COFF_PAGE_SIZE 0x1000
412 /* Turn a howto into a reloc nunmber */
414 #define SELECT_RELOC(x,howto) { x.r_type = howto->type; }
415 #define BADMAG(x) ARMBADMAG(x)
416 #define ARM 1 /* Customize coffcode.h */
419 /* We use the special COFF backend linker. */
420 #define coff_relocate_section _bfd_coff_generic_relocate_section
423 #include "coffcode.h"
426 #ifdef TARGET_LITTLE_SYM
432 #ifdef TARGET_LITTLE_NAME
437 bfd_target_coff_flavour,
438 false, /* data byte order is little */
439 false, /* header byte order is little */
441 (HAS_RELOC | EXEC_P | /* object flags */
442 HAS_LINENO | HAS_DEBUG |
443 HAS_SYMS | HAS_LOCALS | WP_TEXT | D_PAGED),
445 (SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_RELOC), /* section flags */
446 #ifdef TARGET_UNDERSCORE
447 TARGET_UNDERSCORE, /* leading underscore */
449 0, /* leading underscore */
451 '/', /* ar_pad_char */
452 15, /* ar_max_namelen */
454 bfd_getl64, bfd_getl_signed_64, bfd_putl64,
455 bfd_getl32, bfd_getl_signed_32, bfd_putl32,
456 bfd_getl16, bfd_getl_signed_16, bfd_putl16, /* data */
457 bfd_getl64, bfd_getl_signed_64, bfd_putl64,
458 bfd_getl32, bfd_getl_signed_32, bfd_putl32,
459 bfd_getl16, bfd_getl_signed_16, bfd_putl16, /* hdrs */
461 /* Note that we allow an object file to be treated as a core file as well. */
462 {_bfd_dummy_target, coff_object_p, /* bfd_check_format */
463 bfd_generic_archive_p, coff_object_p},
464 {bfd_false, coff_mkobject, _bfd_generic_mkarchive, /* bfd_set_format */
466 {bfd_false, coff_write_object_contents, /* bfd_write_contents */
467 _bfd_write_archive_contents, bfd_false},
469 BFD_JUMP_TABLE_GENERIC (coff),
470 BFD_JUMP_TABLE_COPY (coff),
471 BFD_JUMP_TABLE_CORE (_bfd_nocore),
472 BFD_JUMP_TABLE_ARCHIVE (_bfd_archive_coff),
473 BFD_JUMP_TABLE_SYMBOLS (coff),
474 BFD_JUMP_TABLE_RELOCS (coff),
475 BFD_JUMP_TABLE_WRITE (coff),
476 BFD_JUMP_TABLE_LINK (coff),
477 BFD_JUMP_TABLE_DYNAMIC (_bfd_nodynamic),
483 #ifdef TARGET_BIG_SYM
489 #ifdef TARGET_BIG_NAME
494 bfd_target_coff_flavour,
495 true, /* data byte order is big */
496 true, /* header byte order is big */
498 (HAS_RELOC | EXEC_P | /* object flags */
499 HAS_LINENO | HAS_DEBUG |
500 HAS_SYMS | HAS_LOCALS | WP_TEXT | D_PAGED),
502 (SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_RELOC), /* section flags */
503 #ifdef TARGET_UNDERSCORE
504 TARGET_UNDERSCORE, /* leading underscore */
506 0, /* leading underscore */
508 '/', /* ar_pad_char */
509 15, /* ar_max_namelen */
511 bfd_getb64, bfd_getb_signed_64, bfd_putb64,
512 bfd_getb32, bfd_getb_signed_32, bfd_putb32,
513 bfd_getb16, bfd_getb_signed_16, bfd_putb16, /* data */
514 bfd_getb64, bfd_getb_signed_64, bfd_putb64,
515 bfd_getb32, bfd_getb_signed_32, bfd_putb32,
516 bfd_getb16, bfd_getb_signed_16, bfd_putb16, /* hdrs */
518 /* Note that we allow an object file to be treated as a core file as well. */
519 {_bfd_dummy_target, coff_object_p, /* bfd_check_format */
520 bfd_generic_archive_p, coff_object_p},
521 {bfd_false, coff_mkobject, _bfd_generic_mkarchive, /* bfd_set_format */
523 {bfd_false, coff_write_object_contents, /* bfd_write_contents */
524 _bfd_write_archive_contents, bfd_false},
526 BFD_JUMP_TABLE_GENERIC (coff),
527 BFD_JUMP_TABLE_COPY (coff),
528 BFD_JUMP_TABLE_CORE (_bfd_nocore),
529 BFD_JUMP_TABLE_ARCHIVE (_bfd_archive_coff),
530 BFD_JUMP_TABLE_SYMBOLS (coff),
531 BFD_JUMP_TABLE_RELOCS (coff),
532 BFD_JUMP_TABLE_WRITE (coff),
533 BFD_JUMP_TABLE_LINK (coff),
534 BFD_JUMP_TABLE_DYNAMIC (_bfd_nodynamic),