Back to index

cell-binutils  2.17cvs20070401
coff-ia64.c
Go to the documentation of this file.
00001 /* BFD back-end for HP/Intel IA-64 COFF files.
00002    Copyright 1999, 2000, 2001, 2002 Free Software Foundation, Inc.
00003    Contributed by David Mosberger <davidm@hpl.hp.com>
00004 
00005 This file is part of BFD, the Binary File Descriptor library.
00006 
00007 This program is free software; you can redistribute it and/or modify
00008 it under the terms of the GNU General Public License as published by
00009 the Free Software Foundation; either version 2 of the License, or
00010 (at your option) any later version.
00011 
00012 This program is distributed in the hope that it will be useful,
00013 but WITHOUT ANY WARRANTY; without even the implied warranty of
00014 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015 GNU General Public License for more details.
00016 
00017 You should have received a copy of the GNU General Public License
00018 along with this program; if not, write to the Free Software
00019 Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.  */
00020 
00021 #include "bfd.h"
00022 #include "sysdep.h"
00023 #include "libbfd.h"
00024 #include "coff/ia64.h"
00025 #include "coff/internal.h"
00026 #include "coff/pe.h"
00027 #include "libcoff.h"
00028 
00029 #define COFF_DEFAULT_SECTION_ALIGNMENT_POWER (2)
00030 /* The page size is a guess based on ELF.  */
00031 
00032 #define COFF_PAGE_SIZE 0x1000
00033 
00034 static reloc_howto_type howto_table[] =
00035 {
00036   EMPTY_HOWTO (0),
00037 };
00038 
00039 #define BADMAG(x) IA64BADMAG(x)
00040 #define IA64 1                     /* Customize coffcode.h */
00041 
00042 #ifdef COFF_WITH_pep
00043 # undef AOUTSZ
00044 # define AOUTSZ             PEPAOUTSZ
00045 # define PEAOUTHDR   PEPAOUTHDR
00046 #endif
00047 
00048 #define RTYPE2HOWTO(cache_ptr, dst) \
00049            (cache_ptr)->howto = howto_table + (dst)->r_type;
00050 
00051 #ifdef COFF_WITH_PE
00052 /* Return TRUE if this relocation should
00053    appear in the output .reloc section.  */
00054 
00055 static bfd_boolean in_reloc_p PARAMS ((bfd *, reloc_howto_type *));
00056 
00057 static bfd_boolean
00058 in_reloc_p(abfd, howto)
00059      bfd * abfd ATTRIBUTE_UNUSED;
00060      reloc_howto_type *howto ATTRIBUTE_UNUSED;
00061 {
00062   return FALSE;                    /* We don't do relocs for now...  */
00063 }
00064 #endif
00065 
00066 #include "coffcode.h"
00067 
00068 static const bfd_target *ia64coff_object_p PARAMS ((bfd *));
00069 
00070 static const bfd_target *
00071 ia64coff_object_p (abfd)
00072      bfd *abfd;
00073 {
00074 #ifdef COFF_IMAGE_WITH_PE
00075   {
00076     struct external_PEI_DOS_hdr dos_hdr;
00077     struct external_PEI_IMAGE_hdr image_hdr;
00078     file_ptr offset;
00079 
00080     if (bfd_seek (abfd, (file_ptr) 0, SEEK_SET) != 0
00081        || (bfd_bread (&dos_hdr, (bfd_size_type) sizeof (dos_hdr), abfd)
00082            != sizeof (dos_hdr)))
00083       {
00084        if (bfd_get_error () != bfd_error_system_call)
00085          bfd_set_error (bfd_error_wrong_format);
00086        return NULL;
00087       }
00088 
00089     /* There are really two magic numbers involved; the magic number
00090        that says this is a NT executable (PEI) and the magic number
00091        that determines the architecture.  The former is DOSMAGIC,
00092        stored in the e_magic field.  The latter is stored in the
00093        f_magic field.  If the NT magic number isn't valid, the
00094        architecture magic number could be mimicked by some other
00095        field (specifically, the number of relocs in section 3).  Since
00096        this routine can only be called correctly for a PEI file, check
00097        the e_magic number here, and, if it doesn't match, clobber the
00098        f_magic number so that we don't get a false match.  */
00099     if (H_GET_16 (abfd, dos_hdr.e_magic) != DOSMAGIC)
00100       {
00101        bfd_set_error (bfd_error_wrong_format);
00102        return NULL;
00103       }
00104 
00105     offset = H_GET_32 (abfd, dos_hdr.e_lfanew);
00106     if (bfd_seek (abfd, offset, SEEK_SET) != 0
00107        || (bfd_bread (&image_hdr, (bfd_size_type) sizeof (image_hdr), abfd)
00108            != sizeof (image_hdr)))
00109       {
00110        if (bfd_get_error () != bfd_error_system_call)
00111          bfd_set_error (bfd_error_wrong_format);
00112        return NULL;
00113       }
00114 
00115     if (H_GET_32 (abfd, image_hdr.nt_signature)
00116        != 0x4550)
00117       {
00118        bfd_set_error (bfd_error_wrong_format);
00119        return NULL;
00120       }
00121 
00122     /* Here is the hack.  coff_object_p wants to read filhsz bytes to
00123        pick up the COFF header for PE, see "struct external_PEI_filehdr"
00124        in include/coff/pe.h.  We adjust so that that will work. */
00125     if (bfd_seek (abfd, offset - sizeof (dos_hdr), SEEK_SET) != 0)
00126       {
00127        if (bfd_get_error () != bfd_error_system_call)
00128          bfd_set_error (bfd_error_wrong_format);
00129        return NULL;
00130       }
00131   }
00132 #endif
00133 
00134   return coff_object_p (abfd);
00135 }
00136 
00137 const bfd_target
00138 #ifdef TARGET_SYM
00139   TARGET_SYM =
00140 #else
00141   ia64coff_vec =
00142 #endif
00143 {
00144 #ifdef TARGET_NAME
00145   TARGET_NAME,
00146 #else
00147   "coff-ia64",                     /* name */
00148 #endif
00149   bfd_target_coff_flavour,
00150   BFD_ENDIAN_LITTLE,        /* data byte order is little */
00151   BFD_ENDIAN_LITTLE,        /* header byte order is little */
00152 
00153   (HAS_RELOC | EXEC_P |            /* object flags */
00154    HAS_LINENO | HAS_DEBUG |
00155    HAS_SYMS | HAS_LOCALS | WP_TEXT | D_PAGED),
00156 
00157 #ifndef COFF_WITH_PE
00158   (SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_RELOC /* section flags */
00159    | SEC_CODE | SEC_DATA),
00160 #else
00161   (SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_RELOC /* section flags */
00162    | SEC_CODE | SEC_DATA
00163    | SEC_LINK_ONCE | SEC_LINK_DUPLICATES),
00164 #endif
00165 
00166 #ifdef TARGET_UNDERSCORE
00167   TARGET_UNDERSCORE,        /* leading underscore */
00168 #else
00169   0,                        /* leading underscore */
00170 #endif
00171   '/',                      /* ar_pad_char */
00172   15,                       /* ar_max_namelen */
00173 
00174   bfd_getl64, bfd_getl_signed_64, bfd_putl64,
00175      bfd_getl32, bfd_getl_signed_32, bfd_putl32,
00176      bfd_getl16, bfd_getl_signed_16, bfd_putl16, /* data */
00177   bfd_getl64, bfd_getl_signed_64, bfd_putl64,
00178      bfd_getl32, bfd_getl_signed_32, bfd_putl32,
00179      bfd_getl16, bfd_getl_signed_16, bfd_putl16, /* hdrs */
00180 
00181 /* Note that we allow an object file to be treated as a core file as well.  */
00182     {_bfd_dummy_target, ia64coff_object_p, /* bfd_check_format */
00183        bfd_generic_archive_p, ia64coff_object_p},
00184     {bfd_false, coff_mkobject, _bfd_generic_mkarchive, /* bfd_set_format */
00185        bfd_false},
00186     {bfd_false, coff_write_object_contents, /* bfd_write_contents */
00187        _bfd_write_archive_contents, bfd_false},
00188 
00189      BFD_JUMP_TABLE_GENERIC (coff),
00190      BFD_JUMP_TABLE_COPY (coff),
00191      BFD_JUMP_TABLE_CORE (_bfd_nocore),
00192      BFD_JUMP_TABLE_ARCHIVE (_bfd_archive_coff),
00193      BFD_JUMP_TABLE_SYMBOLS (coff),
00194      BFD_JUMP_TABLE_RELOCS (coff),
00195      BFD_JUMP_TABLE_WRITE (coff),
00196      BFD_JUMP_TABLE_LINK (coff),
00197      BFD_JUMP_TABLE_DYNAMIC (_bfd_nodynamic),
00198 
00199   NULL,
00200 
00201   COFF_SWAP_TABLE
00202 };