/* BFD back-end for Motorolla MCore COFF/PE
- Copyright 1999 Free Software Foundation, Inc.
+ Copyright (C) 1999 Free Software Foundation, Inc.
This file is part of BFD, the Binary File Descriptor library.
return & ret->root.root;
}
\f
+/* Add an entry to the base file. */
+static void
+mcore_emit_base_file_entry (info, output_bfd, input_section, reloc_offset)
+ struct bfd_link_info * info;
+ bfd * output_bfd;
+ asection * input_section;
+ bfd_vma reloc_offset;
+{
+ bfd_vma addr = reloc_offset
+ - input_section->vma
+ + input_section->output_offset
+ + input_section->output_section->vma;
+
+ if (coff_data (output_bfd)->pe)
+ addr -= pe_data (output_bfd)->pe_opthdr.ImageBase;
+
+ fwrite (&addr, 1, sizeof (addr), (FILE *) info->base_file);
+}
+\f
/*ARGSUSED*/
static bfd_reloc_status_type
mcore_coff_unsupported_reloc (abfd, reloc_entry, symbol, data, input_section,
if (rel->r_type == IMAGE_REL_MCORE_RVA)
* addendp -= pe_data (sec->output_section->owner)->pe_opthdr.ImageBase;
- if (howto->pc_relative)
+ else if (howto->pc_relative)
{
* addendp = sec->vma - 2; /* XXX guess - is this right ? */
sym = syms + symndx;
}
+ addend = 0;
+
/* Get the howto and initialise the addend. */
howto = bfd_coff_rtype_to_howto (input_bfd, input_section, rel, h,
sym, & addend);
case IMAGE_REL_MCORE_PCREL_32:
case IMAGE_REL_MCORE_PCREL_JSR_IMM11BY2:
case IMAGE_REL_MCORE_ADDR32:
- case IMAGE_REL_MCORE_RVA:
+ /* XXX fixme - shouldn't this be like the code for the RVA reloc ? */
rstat = _bfd_relocate_contents (howto, input_bfd, val, loc);
break;
+
+ case IMAGE_REL_MCORE_RVA:
+ rstat = _bfd_final_link_relocate
+ (howto, input_bfd,
+ input_section, contents, rel->r_vaddr - input_section->vma,
+ val, addend);
+ break;
}
+ if (info->base_file)
+ {
+ /* Emit a reloc if the backend thinks it needs it. */
+ if (sym && pe_data (output_bfd)->in_reloc_p (output_bfd, howto))
+ mcore_emit_base_file_entry (info, output_bfd, input_section, rel->r_vaddr);
+ }
+
switch (rstat)
{
default:
#include "coffcode.h"
\f
-static const bfd_target *
-pe_object_p (abfd)
- bfd * abfd;
-{
-#ifdef COFF_IMAGE_WITH_PE
- /* We need to hack badly to handle a PE image correctly. In PE
- images created by the GNU linker, the offset to the COFF header
- is always the size. However, this is not the case in images
- generated by other PE linkers. The PE format stores a four byte
- offset to the PE signature just before the COFF header at
- location 0x3c of the file. We pick up that offset, verify that
- the PE signature is there, and then set ourselves up to read in
- the COFF header. */
- {
- bfd_byte ext_offset[4];
- file_ptr offset;
- bfd_byte ext_signature[4];
- unsigned long signature;
-
- if (bfd_seek (abfd, 0x3c, SEEK_SET) != 0
- || bfd_read (ext_offset, 1, 4, abfd) != 4)
- {
- if (bfd_get_error () != bfd_error_system_call)
- bfd_set_error (bfd_error_wrong_format);
- return NULL;
- }
-
- offset = bfd_h_get_32 (abfd, ext_offset);
-
- if (bfd_seek (abfd, offset, SEEK_SET) != 0
- || bfd_read (ext_signature, 1, 4, abfd) != 4)
- {
- if (bfd_get_error () != bfd_error_system_call)
- bfd_set_error (bfd_error_wrong_format);
-
- return NULL;
- }
-
- signature = bfd_h_get_32 (abfd, ext_signature);
-
- if (signature != 0x4550)
- {
- bfd_set_error (bfd_error_wrong_format);
- return NULL;
- }
-
- /* Here is the hack. coff_object_p wants to read filhsz bytes to
- pick up the COFF header. We adjust so that that will work. 20
- is the size of the mips COFF filehdr. */
- if (bfd_seek (abfd, (bfd_tell (abfd) - bfd_coff_filhsz (abfd) + 20),
- SEEK_SET) != 0)
- {
- if (bfd_get_error () != bfd_error_system_call)
- bfd_set_error (bfd_error_wrong_format);
-
- return NULL;
- }
- }
-#endif
-
- return coff_object_p (abfd);
-}
-\f
/* Forward declaration to initialise alterbative_target field. */
extern const bfd_target TARGET_LITTLE_SYM;