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