1 /* BFD back-end for Intel 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
,
264 #define RTYPE2HOWTO(cache_ptr, dst) \
265 (cache_ptr)->howto = aoutarm_std_reloc_howto + (dst)->r_type;
267 #define coff_rtype_to_howto coff_arm_rtype_to_howto
269 static reloc_howto_type
*
270 coff_arm_rtype_to_howto (abfd
, sec
, rel
, h
, sym
, addendp
)
273 struct internal_reloc
*rel
;
274 struct coff_link_hash_entry
*h
;
275 struct internal_syment
*sym
;
278 reloc_howto_type
*howto
;
280 howto
= aoutarm_std_reloc_howto
+ rel
->r_type
;
282 if (rel
->r_type
== 11)
284 *addendp
-= pe_data(sec
->output_section
->owner
)->pe_opthdr
.ImageBase
;
289 /* Used by the assembler. */
291 static bfd_reloc_status_type
292 aoutarm_fix_pcrel_26_done (abfd
, reloc_entry
, symbol
, data
, input_section
,
293 output_bfd
, error_message
)
295 arelent
*reloc_entry
;
298 asection
*input_section
;
300 char **error_message
;
302 /* This is dead simple at present. */
306 /* Used by the assembler. */
308 static bfd_reloc_status_type
309 aoutarm_fix_pcrel_26 (abfd
, reloc_entry
, symbol
, data
, input_section
,
310 output_bfd
, error_message
)
312 arelent
*reloc_entry
;
315 asection
*input_section
;
317 char **error_message
;
320 bfd_size_type addr
= reloc_entry
->address
;
321 long target
= bfd_get_32 (abfd
, (bfd_byte
*) data
+ addr
);
322 bfd_reloc_status_type flag
= bfd_reloc_ok
;
324 /* If this is an undefined symbol, return error */
325 if (symbol
->section
== &bfd_und_section
326 && (symbol
->flags
& BSF_WEAK
) == 0)
327 return output_bfd
? bfd_reloc_continue
: bfd_reloc_undefined
;
329 /* If the sections are different, and we are doing a partial relocation,
330 just ignore it for now. */
331 if (symbol
->section
->name
!= input_section
->name
332 && output_bfd
!= (bfd
*)NULL
)
333 return bfd_reloc_continue
;
335 relocation
= (target
& 0x00ffffff) << 2;
336 relocation
= (relocation
^ 0x02000000) - 0x02000000; /* Sign extend */
337 relocation
+= symbol
->value
;
338 relocation
+= symbol
->section
->output_section
->vma
;
339 relocation
+= symbol
->section
->output_offset
;
340 relocation
+= reloc_entry
->addend
;
341 relocation
-= input_section
->output_section
->vma
;
342 relocation
-= input_section
->output_offset
;
345 return bfd_reloc_overflow
;
347 /* Check for overflow */
348 if (relocation
& 0x02000000)
350 if ((relocation
& ~0x03ffffff) != ~0x03ffffff)
351 flag
= bfd_reloc_overflow
;
353 else if (relocation
& ~0x03ffffff)
354 flag
= bfd_reloc_overflow
;
356 target
&= ~0x00ffffff;
357 target
|= (relocation
>> 2) & 0x00ffffff;
358 bfd_put_32 (abfd
, target
, (bfd_byte
*) data
+ addr
);
360 /* Now the ARM magic... Change the reloc type so that it is marked as done.
361 Strictly this is only necessary if we are doing a partial relocation. */
362 reloc_entry
->howto
= &aoutarm_std_reloc_howto
[7];
368 static CONST
struct reloc_howto_struct
*
369 arm_reloc_type_lookup(abfd
,code
)
371 bfd_reloc_code_real_type code
;
373 #define ASTD(i,j) case i: return &aoutarm_std_reloc_howto[j]
374 if (code
== BFD_RELOC_CTOR
)
375 switch (bfd_get_arch_info (abfd
)->bits_per_address
)
380 default: return (CONST
struct reloc_howto_struct
*) 0;
385 ASTD (BFD_RELOC_16
, 1);
386 ASTD (BFD_RELOC_32
, 2);
387 ASTD (BFD_RELOC_ARM_PCREL_BRANCH
, 3);
388 ASTD (BFD_RELOC_8_PCREL
, 4);
389 ASTD (BFD_RELOC_16_PCREL
, 5);
390 ASTD (BFD_RELOC_32_PCREL
, 6);
391 ASTD (BFD_RELOC_RVA
, 11);
392 default: return (CONST
struct reloc_howto_struct
*) 0;
397 #define coff_bfd_reloc_type_lookup arm_reloc_type_lookup
399 #define COFF_DEFAULT_SECTION_ALIGNMENT_POWER (2)
400 #define COFF_PAGE_SIZE 0x1000
401 /* Turn a howto into a reloc nunmber */
403 #define SELECT_RELOC(x,howto) { x.r_type = howto->type; }
404 #define BADMAG(x) ARMBADMAG(x)
405 #define ARM 1 /* Customize coffcode.h */
408 /* We use the special COFF backend linker. */
409 #define coff_relocate_section _bfd_coff_generic_relocate_section
412 #include "coffcode.h"
414 #ifdef TARGET_LITTLE_SYM
415 const bfd_target TARGET_LITTLE_SYM
=
417 TARGET_LITTLE_NAME
, /* name or coff-arm-little */
418 bfd_target_coff_flavour
,
419 false, /* data byte order is little */
420 false, /* header byte order is little */
422 (HAS_RELOC
| EXEC_P
| /* object flags */
423 HAS_LINENO
| HAS_DEBUG
|
424 HAS_SYMS
| HAS_LOCALS
| WP_TEXT
| D_PAGED
),
426 (SEC_HAS_CONTENTS
| SEC_ALLOC
| SEC_LOAD
| SEC_RELOC
), /* section flags */
427 #ifdef TARGET_UNDERSCORE
428 TARGET_UNDERSCORE
, /* leading underscore */
430 0, /* leading underscore */
432 '/', /* ar_pad_char */
433 15, /* ar_max_namelen */
435 bfd_getl64
, bfd_getl_signed_64
, bfd_putl64
,
436 bfd_getl32
, bfd_getl_signed_32
, bfd_putl32
,
437 bfd_getl16
, bfd_getl_signed_16
, bfd_putl16
, /* data */
438 bfd_getl64
, bfd_getl_signed_64
, bfd_putl64
,
439 bfd_getl32
, bfd_getl_signed_32
, bfd_putl32
,
440 bfd_getl16
, bfd_getl_signed_16
, bfd_putl16
, /* hdrs */
442 /* Note that we allow an object file to be treated as a core file as well. */
443 {_bfd_dummy_target
, coff_object_p
, /* bfd_check_format */
444 bfd_generic_archive_p
, coff_object_p
},
445 {bfd_false
, coff_mkobject
, _bfd_generic_mkarchive
, /* bfd_set_format */
447 {bfd_false
, coff_write_object_contents
, /* bfd_write_contents */
448 _bfd_write_archive_contents
, bfd_false
},
450 BFD_JUMP_TABLE_GENERIC (coff
),
451 BFD_JUMP_TABLE_COPY (coff
),
452 BFD_JUMP_TABLE_CORE (_bfd_nocore
),
453 BFD_JUMP_TABLE_ARCHIVE (_bfd_archive_coff
),
454 BFD_JUMP_TABLE_SYMBOLS (coff
),
455 BFD_JUMP_TABLE_RELOCS (coff
),
456 BFD_JUMP_TABLE_WRITE (coff
),
457 BFD_JUMP_TABLE_LINK (coff
),
458 BFD_JUMP_TABLE_DYNAMIC (_bfd_nodynamic
),
464 #ifdef TARGET_BIG_SYM
465 const bfd_target TARGET_BIG_SYM
=
467 TARGET_BIG_NAME
, /* name or coff-arm-big */
468 bfd_target_coff_flavour
,
469 true, /* data byte order is big */
470 true, /* header byte order is big */
472 (HAS_RELOC
| EXEC_P
| /* object flags */
473 HAS_LINENO
| HAS_DEBUG
|
474 HAS_SYMS
| HAS_LOCALS
| WP_TEXT
| D_PAGED
),
476 (SEC_HAS_CONTENTS
| SEC_ALLOC
| SEC_LOAD
| SEC_RELOC
), /* section flags */
477 #ifdef TARGET_UNDERSCORE
478 TARGET_UNDERSCORE
, /* leading underscore */
480 0, /* leading underscore */
482 '/', /* ar_pad_char */
483 15, /* ar_max_namelen */
485 bfd_getb64
, bfd_getb_signed_64
, bfd_putb64
,
486 bfd_getb32
, bfd_getb_signed_32
, bfd_putb32
,
487 bfd_getb16
, bfd_getb_signed_16
, bfd_putb16
, /* data */
488 bfd_getb64
, bfd_getb_signed_64
, bfd_putb64
,
489 bfd_getb32
, bfd_getb_signed_32
, bfd_putb32
,
490 bfd_getb16
, bfd_getb_signed_16
, bfd_putb16
, /* hdrs */
492 /* Note that we allow an object file to be treated as a core file as well. */
493 {_bfd_dummy_target
, coff_object_p
, /* bfd_check_format */
494 bfd_generic_archive_p
, coff_object_p
},
495 {bfd_false
, coff_mkobject
, _bfd_generic_mkarchive
, /* bfd_set_format */
497 {bfd_false
, coff_write_object_contents
, /* bfd_write_contents */
498 _bfd_write_archive_contents
, bfd_false
},
500 BFD_JUMP_TABLE_GENERIC (coff
),
501 BFD_JUMP_TABLE_COPY (coff
),
502 BFD_JUMP_TABLE_CORE (_bfd_nocore
),
503 BFD_JUMP_TABLE_ARCHIVE (_bfd_archive_coff
),
504 BFD_JUMP_TABLE_SYMBOLS (coff
),
505 BFD_JUMP_TABLE_RELOCS (coff
),
506 BFD_JUMP_TABLE_WRITE (coff
),
507 BFD_JUMP_TABLE_LINK (coff
),
508 BFD_JUMP_TABLE_DYNAMIC (_bfd_nodynamic
),