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