1 /* BFD back-end for HP/Intel IA-64 COFF files.
2 Copyright 1999, 2000, 2001, 2002, 2005, 2007, 2008, 2009, 2011, 2012
3 Free Software Foundation, Inc.
4 Contributed by David Mosberger <davidm@hpl.hp.com>
6 This file is part of BFD, the Binary File Descriptor library.
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 3 of the License, or
11 (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
21 MA 02110-1301, USA. */
26 #include "coff/ia64.h"
27 #include "coff/internal.h"
31 #define COFF_DEFAULT_SECTION_ALIGNMENT_POWER (2)
33 /* Windows ia64 uses 8K page size. */
34 #define COFF_PAGE_SIZE 0x2000
36 static reloc_howto_type howto_table[] =
41 #define BADMAG(x) IA64BADMAG(x)
42 #define IA64 1 /* Customize coffcode.h */
46 # define AOUTSZ PEPAOUTSZ
47 # define PEAOUTHDR PEPAOUTHDR
50 #define RTYPE2HOWTO(cache_ptr, dst) \
51 (cache_ptr)->howto = howto_table + (dst)->r_type;
54 /* Return TRUE if this relocation should
55 appear in the output .reloc section. */
58 in_reloc_p (bfd * abfd ATTRIBUTE_UNUSED,
59 reloc_howto_type *howto ATTRIBUTE_UNUSED)
61 return FALSE; /* We don't do relocs for now... */
65 #ifndef bfd_pe_print_pdata
66 #define bfd_pe_print_pdata NULL
71 static const bfd_target *
72 ia64coff_object_p (bfd *abfd)
74 #ifdef COFF_IMAGE_WITH_PE
76 struct external_PEI_DOS_hdr dos_hdr;
77 struct external_PEI_IMAGE_hdr image_hdr;
80 if (bfd_seek (abfd, (file_ptr) 0, SEEK_SET) != 0
81 || (bfd_bread (&dos_hdr, (bfd_size_type) sizeof (dos_hdr), abfd)
84 if (bfd_get_error () != bfd_error_system_call)
85 bfd_set_error (bfd_error_wrong_format);
89 /* There are really two magic numbers involved; the magic number
90 that says this is a NT executable (PEI) and the magic number
91 that determines the architecture. The former is DOSMAGIC,
92 stored in the e_magic field. The latter is stored in the
93 f_magic field. If the NT magic number isn't valid, the
94 architecture magic number could be mimicked by some other
95 field (specifically, the number of relocs in section 3). Since
96 this routine can only be called correctly for a PEI file, check
97 the e_magic number here, and, if it doesn't match, clobber the
98 f_magic number so that we don't get a false match. */
99 if (H_GET_16 (abfd, dos_hdr.e_magic) != DOSMAGIC)
101 bfd_set_error (bfd_error_wrong_format);
105 offset = H_GET_32 (abfd, dos_hdr.e_lfanew);
106 if (bfd_seek (abfd, offset, SEEK_SET) != 0
107 || (bfd_bread (&image_hdr, (bfd_size_type) sizeof (image_hdr), abfd)
108 != sizeof (image_hdr)))
110 if (bfd_get_error () != bfd_error_system_call)
111 bfd_set_error (bfd_error_wrong_format);
115 if (H_GET_32 (abfd, image_hdr.nt_signature)
118 bfd_set_error (bfd_error_wrong_format);
122 /* Here is the hack. coff_object_p wants to read filhsz bytes to
123 pick up the COFF header for PE, see "struct external_PEI_filehdr"
124 in include/coff/pe.h. We adjust so that that will work. */
125 if (bfd_seek (abfd, offset - sizeof (dos_hdr), SEEK_SET) != 0)
127 if (bfd_get_error () != bfd_error_system_call)
128 bfd_set_error (bfd_error_wrong_format);
134 return coff_object_p (abfd);
147 "coff-ia64", /* name */
149 bfd_target_coff_flavour,
150 BFD_ENDIAN_LITTLE, /* data byte order is little */
151 BFD_ENDIAN_LITTLE, /* header byte order is little */
153 (HAS_RELOC | EXEC_P | /* object flags */
154 HAS_LINENO | HAS_DEBUG |
155 HAS_SYMS | HAS_LOCALS | WP_TEXT | D_PAGED),
158 (SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_RELOC /* section flags */
159 | SEC_CODE | SEC_DATA),
161 (SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_RELOC /* section flags */
162 | SEC_CODE | SEC_DATA
163 | SEC_LINK_ONCE | SEC_LINK_DUPLICATES),
166 #ifdef TARGET_UNDERSCORE
167 TARGET_UNDERSCORE, /* leading underscore */
169 0, /* leading underscore */
171 '/', /* ar_pad_char */
172 15, /* ar_max_namelen */
173 0, /* match priority. */
175 bfd_getl64, bfd_getl_signed_64, bfd_putl64,
176 bfd_getl32, bfd_getl_signed_32, bfd_putl32,
177 bfd_getl16, bfd_getl_signed_16, bfd_putl16, /* data */
178 bfd_getl64, bfd_getl_signed_64, bfd_putl64,
179 bfd_getl32, bfd_getl_signed_32, bfd_putl32,
180 bfd_getl16, bfd_getl_signed_16, bfd_putl16, /* hdrs */
182 /* Note that we allow an object file to be treated as a core file as well. */
183 {_bfd_dummy_target, ia64coff_object_p, /* bfd_check_format */
184 bfd_generic_archive_p, ia64coff_object_p},
185 {bfd_false, coff_mkobject, _bfd_generic_mkarchive, /* bfd_set_format */
187 {bfd_false, coff_write_object_contents, /* bfd_write_contents */
188 _bfd_write_archive_contents, bfd_false},
190 BFD_JUMP_TABLE_GENERIC (coff),
191 BFD_JUMP_TABLE_COPY (coff),
192 BFD_JUMP_TABLE_CORE (_bfd_nocore),
193 BFD_JUMP_TABLE_ARCHIVE (_bfd_archive_coff),
194 BFD_JUMP_TABLE_SYMBOLS (coff),
195 BFD_JUMP_TABLE_RELOCS (coff),
196 BFD_JUMP_TABLE_WRITE (coff),
197 BFD_JUMP_TABLE_LINK (coff),
198 BFD_JUMP_TABLE_DYNAMIC (_bfd_nodynamic),