1 /* BFD back-end for HP/Intel IA-64 COFF files.
2 Copyright (C) 1999-2019 Free Software Foundation, Inc.
3 Contributed by David Mosberger <davidm@hpl.hp.com>
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 3 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., 51 Franklin Street - Fifth Floor, Boston,
20 MA 02110-1301, USA. */
25 #include "coff/ia64.h"
26 #include "coff/internal.h"
30 #define COFF_DEFAULT_SECTION_ALIGNMENT_POWER (2)
32 /* Windows ia64 uses 8K page size. */
33 #define COFF_PAGE_SIZE 0x2000
35 static reloc_howto_type howto_table[] =
40 #define BADMAG(x) IA64BADMAG(x)
41 #define IA64 1 /* Customize coffcode.h */
45 # define AOUTSZ PEPAOUTSZ
46 # define PEAOUTHDR PEPAOUTHDR
49 #define RTYPE2HOWTO(cache_ptr, dst) \
50 (cache_ptr)->howto = howto_table;
53 /* Return TRUE if this relocation should
54 appear in the output .reloc section. */
57 in_reloc_p (bfd * abfd ATTRIBUTE_UNUSED,
58 reloc_howto_type *howto ATTRIBUTE_UNUSED)
60 return FALSE; /* We don't do relocs for now... */
64 #ifndef bfd_pe_print_pdata
65 #define bfd_pe_print_pdata NULL
70 static const bfd_target *
71 ia64coff_object_p (bfd *abfd)
73 #ifdef COFF_IMAGE_WITH_PE
75 struct external_DOS_hdr dos_hdr;
76 struct external_PEI_IMAGE_hdr image_hdr;
79 if (bfd_seek (abfd, (file_ptr) 0, SEEK_SET) != 0
80 || (bfd_bread (&dos_hdr, (bfd_size_type) sizeof (dos_hdr), abfd)
83 if (bfd_get_error () != bfd_error_system_call)
84 bfd_set_error (bfd_error_wrong_format);
88 /* There are really two magic numbers involved; the magic number
89 that says this is a NT executable (PEI) and the magic number
90 that determines the architecture. The former is IMAGE_DOS_SIGNATURE,
91 stored in the e_magic field. The latter is stored in the
92 f_magic field. If the NT magic number isn't valid, the
93 architecture magic number could be mimicked by some other
94 field (specifically, the number of relocs in section 3). Since
95 this routine can only be called correctly for a PEI file, check
96 the e_magic number here, and, if it doesn't match, clobber the
97 f_magic number so that we don't get a false match. */
98 if (H_GET_16 (abfd, dos_hdr.e_magic) != IMAGE_DOS_SIGNATURE)
100 bfd_set_error (bfd_error_wrong_format);
104 offset = H_GET_32 (abfd, dos_hdr.e_lfanew);
105 if (bfd_seek (abfd, offset, SEEK_SET) != 0
106 || (bfd_bread (&image_hdr, (bfd_size_type) sizeof (image_hdr), abfd)
107 != sizeof (image_hdr)))
109 if (bfd_get_error () != bfd_error_system_call)
110 bfd_set_error (bfd_error_wrong_format);
114 if (H_GET_32 (abfd, image_hdr.nt_signature)
117 bfd_set_error (bfd_error_wrong_format);
121 /* Here is the hack. coff_object_p wants to read filhsz bytes to
122 pick up the COFF header for PE, see "struct external_PEI_filehdr"
123 in include/coff/pe.h. We adjust so that that will work. */
124 if (bfd_seek (abfd, offset - sizeof (dos_hdr), SEEK_SET) != 0)
126 if (bfd_get_error () != bfd_error_system_call)
127 bfd_set_error (bfd_error_wrong_format);
133 return coff_object_p (abfd);
146 "coff-ia64", /* name */
148 bfd_target_coff_flavour,
149 BFD_ENDIAN_LITTLE, /* data byte order is little */
150 BFD_ENDIAN_LITTLE, /* header byte order is little */
152 (HAS_RELOC | EXEC_P /* object flags */
153 | HAS_LINENO | HAS_DEBUG
154 | HAS_SYMS | HAS_LOCALS | WP_TEXT | D_PAGED),
157 (SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_RELOC /* section flags */
158 | SEC_CODE | SEC_DATA),
160 (SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_RELOC /* section flags */
161 | SEC_CODE | SEC_DATA
162 | SEC_LINK_ONCE | SEC_LINK_DUPLICATES),
165 #ifdef TARGET_UNDERSCORE
166 TARGET_UNDERSCORE, /* leading underscore */
168 0, /* leading underscore */
170 '/', /* ar_pad_char */
171 15, /* ar_max_namelen */
172 0, /* match priority. */
174 bfd_getl64, bfd_getl_signed_64, bfd_putl64,
175 bfd_getl32, bfd_getl_signed_32, bfd_putl32,
176 bfd_getl16, bfd_getl_signed_16, bfd_putl16, /* data */
177 bfd_getl64, bfd_getl_signed_64, bfd_putl64,
178 bfd_getl32, bfd_getl_signed_32, bfd_putl32,
179 bfd_getl16, bfd_getl_signed_16, bfd_putl16, /* hdrs */
181 /* Note that we allow an object file to be treated as a core file as well. */
182 { /* bfd_check_format */
185 bfd_generic_archive_p,
188 { /* bfd_set_format */
189 _bfd_bool_bfd_false_error,
191 _bfd_generic_mkarchive,
192 _bfd_bool_bfd_false_error
194 { /* bfd_write_contents */
195 _bfd_bool_bfd_false_error,
196 coff_write_object_contents,
197 _bfd_write_archive_contents,
198 _bfd_bool_bfd_false_error
201 BFD_JUMP_TABLE_GENERIC (coff),
202 BFD_JUMP_TABLE_COPY (coff),
203 BFD_JUMP_TABLE_CORE (_bfd_nocore),
204 BFD_JUMP_TABLE_ARCHIVE (_bfd_archive_coff),
205 BFD_JUMP_TABLE_SYMBOLS (coff),
206 BFD_JUMP_TABLE_RELOCS (coff),
207 BFD_JUMP_TABLE_WRITE (coff),
208 BFD_JUMP_TABLE_LINK (coff),
209 BFD_JUMP_TABLE_DYNAMIC (_bfd_nodynamic),