]>
Commit | Line | Data |
---|---|---|
277d1b5e | 1 | /* Support for the generic parts of PE/PEI; common header information. |
cbff5e0d | 2 | Copyright 1995, 1996, 1997, 1998, 1999, 2001 Free Software Foundation, Inc. |
277d1b5e ILT |
3 | Written by Cygnus Solutions. |
4 | ||
5 | This file is part of BFD, the Binary File Descriptor library. | |
6 | ||
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 2 of the License, or | |
10 | (at your option) any later version. | |
11 | ||
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. | |
16 | ||
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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ | |
20 | ||
21 | /* | |
22 | Most of this hacked by Steve Chamberlain, | |
23 | [email protected] | |
24 | ||
25 | PE/PEI rearrangement (and code added): Donn Terry | |
26 | Softway Systems, Inc. | |
27 | */ | |
28 | ||
29 | /* Hey look, some documentation [and in a place you expect to find it]! | |
30 | ||
31 | The main reference for the pei format is "Microsoft Portable Executable | |
32 | and Common Object File Format Specification 4.1". Get it if you need to | |
33 | do some serious hacking on this code. | |
34 | ||
35 | Another reference: | |
36 | "Peering Inside the PE: A Tour of the Win32 Portable Executable | |
37 | File Format", MSJ 1994, Volume 9. | |
38 | ||
39 | The *sole* difference between the pe format and the pei format is that the | |
40 | latter has an MSDOS 2.0 .exe header on the front that prints the message | |
41 | "This app must be run under Windows." (or some such). | |
42 | (FIXME: Whether that statement is *really* true or not is unknown. | |
43 | Are there more subtle differences between pe and pei formats? | |
44 | For now assume there aren't. If you find one, then for God sakes | |
45 | document it here!) | |
46 | ||
47 | The Microsoft docs use the word "image" instead of "executable" because | |
48 | the former can also refer to a DLL (shared library). Confusion can arise | |
49 | because the `i' in `pei' also refers to "image". The `pe' format can | |
50 | also create images (i.e. executables), it's just that to run on a win32 | |
51 | system you need to use the pei format. | |
52 | ||
53 | FIXME: Please add more docs here so the next poor fool that has to hack | |
54 | on this code has a chance of getting something accomplished without | |
55 | wasting too much time. | |
56 | */ | |
57 | ||
58 | #ifndef GET_FCN_LNNOPTR | |
59 | #define GET_FCN_LNNOPTR(abfd, ext) \ | |
60 | bfd_h_get_32(abfd, (bfd_byte *) ext->x_sym.x_fcnary.x_fcn.x_lnnoptr) | |
61 | #endif | |
62 | ||
63 | #ifndef GET_FCN_ENDNDX | |
64 | #define GET_FCN_ENDNDX(abfd, ext) \ | |
65 | bfd_h_get_32(abfd, (bfd_byte *) ext->x_sym.x_fcnary.x_fcn.x_endndx) | |
66 | #endif | |
67 | ||
68 | #ifndef PUT_FCN_LNNOPTR | |
69 | #define PUT_FCN_LNNOPTR(abfd, in, ext) bfd_h_put_32(abfd, in, (bfd_byte *) ext->x_sym.x_fcnary.x_fcn.x_lnnoptr) | |
70 | #endif | |
71 | #ifndef PUT_FCN_ENDNDX | |
72 | #define PUT_FCN_ENDNDX(abfd, in, ext) bfd_h_put_32(abfd, in, (bfd_byte *) ext->x_sym.x_fcnary.x_fcn.x_endndx) | |
73 | #endif | |
74 | #ifndef GET_LNSZ_LNNO | |
75 | #define GET_LNSZ_LNNO(abfd, ext) bfd_h_get_16(abfd, (bfd_byte *) ext->x_sym.x_misc.x_lnsz.x_lnno) | |
76 | #endif | |
77 | #ifndef GET_LNSZ_SIZE | |
78 | #define GET_LNSZ_SIZE(abfd, ext) bfd_h_get_16(abfd, (bfd_byte *) ext->x_sym.x_misc.x_lnsz.x_size) | |
79 | #endif | |
80 | #ifndef PUT_LNSZ_LNNO | |
81 | #define PUT_LNSZ_LNNO(abfd, in, ext) bfd_h_put_16(abfd, in, (bfd_byte *)ext->x_sym.x_misc.x_lnsz.x_lnno) | |
82 | #endif | |
83 | #ifndef PUT_LNSZ_SIZE | |
84 | #define PUT_LNSZ_SIZE(abfd, in, ext) bfd_h_put_16(abfd, in, (bfd_byte*) ext->x_sym.x_misc.x_lnsz.x_size) | |
85 | #endif | |
86 | #ifndef GET_SCN_SCNLEN | |
87 | #define GET_SCN_SCNLEN(abfd, ext) bfd_h_get_32(abfd, (bfd_byte *) ext->x_scn.x_scnlen) | |
88 | #endif | |
89 | #ifndef GET_SCN_NRELOC | |
90 | #define GET_SCN_NRELOC(abfd, ext) bfd_h_get_16(abfd, (bfd_byte *)ext->x_scn.x_nreloc) | |
91 | #endif | |
92 | #ifndef GET_SCN_NLINNO | |
93 | #define GET_SCN_NLINNO(abfd, ext) bfd_h_get_16(abfd, (bfd_byte *)ext->x_scn.x_nlinno) | |
94 | #endif | |
95 | #ifndef PUT_SCN_SCNLEN | |
96 | #define PUT_SCN_SCNLEN(abfd,in, ext) bfd_h_put_32(abfd, in, (bfd_byte *) ext->x_scn.x_scnlen) | |
97 | #endif | |
98 | #ifndef PUT_SCN_NRELOC | |
99 | #define PUT_SCN_NRELOC(abfd,in, ext) bfd_h_put_16(abfd, in, (bfd_byte *)ext->x_scn.x_nreloc) | |
100 | #endif | |
101 | #ifndef PUT_SCN_NLINNO | |
102 | #define PUT_SCN_NLINNO(abfd,in, ext) bfd_h_put_16(abfd,in, (bfd_byte *) ext->x_scn.x_nlinno) | |
103 | #endif | |
104 | #ifndef GET_LINENO_LNNO | |
105 | #define GET_LINENO_LNNO(abfd, ext) bfd_h_get_16(abfd, (bfd_byte *) (ext->l_lnno)); | |
106 | #endif | |
107 | #ifndef PUT_LINENO_LNNO | |
108 | #define PUT_LINENO_LNNO(abfd,val, ext) bfd_h_put_16(abfd,val, (bfd_byte *) (ext->l_lnno)); | |
109 | #endif | |
110 | ||
111 | /* The f_symptr field in the filehdr is sometimes 64 bits. */ | |
112 | #ifndef GET_FILEHDR_SYMPTR | |
113 | #define GET_FILEHDR_SYMPTR bfd_h_get_32 | |
114 | #endif | |
115 | #ifndef PUT_FILEHDR_SYMPTR | |
116 | #define PUT_FILEHDR_SYMPTR bfd_h_put_32 | |
117 | #endif | |
118 | ||
119 | /* Some fields in the aouthdr are sometimes 64 bits. */ | |
120 | #ifndef GET_AOUTHDR_TSIZE | |
121 | #define GET_AOUTHDR_TSIZE bfd_h_get_32 | |
122 | #endif | |
123 | #ifndef PUT_AOUTHDR_TSIZE | |
124 | #define PUT_AOUTHDR_TSIZE bfd_h_put_32 | |
125 | #endif | |
126 | #ifndef GET_AOUTHDR_DSIZE | |
127 | #define GET_AOUTHDR_DSIZE bfd_h_get_32 | |
128 | #endif | |
129 | #ifndef PUT_AOUTHDR_DSIZE | |
130 | #define PUT_AOUTHDR_DSIZE bfd_h_put_32 | |
131 | #endif | |
132 | #ifndef GET_AOUTHDR_BSIZE | |
133 | #define GET_AOUTHDR_BSIZE bfd_h_get_32 | |
134 | #endif | |
135 | #ifndef PUT_AOUTHDR_BSIZE | |
136 | #define PUT_AOUTHDR_BSIZE bfd_h_put_32 | |
137 | #endif | |
138 | #ifndef GET_AOUTHDR_ENTRY | |
139 | #define GET_AOUTHDR_ENTRY bfd_h_get_32 | |
140 | #endif | |
141 | #ifndef PUT_AOUTHDR_ENTRY | |
142 | #define PUT_AOUTHDR_ENTRY bfd_h_put_32 | |
143 | #endif | |
144 | #ifndef GET_AOUTHDR_TEXT_START | |
145 | #define GET_AOUTHDR_TEXT_START bfd_h_get_32 | |
146 | #endif | |
147 | #ifndef PUT_AOUTHDR_TEXT_START | |
148 | #define PUT_AOUTHDR_TEXT_START bfd_h_put_32 | |
149 | #endif | |
150 | #ifndef GET_AOUTHDR_DATA_START | |
151 | #define GET_AOUTHDR_DATA_START bfd_h_get_32 | |
152 | #endif | |
153 | #ifndef PUT_AOUTHDR_DATA_START | |
154 | #define PUT_AOUTHDR_DATA_START bfd_h_put_32 | |
155 | #endif | |
156 | ||
157 | /* Some fields in the scnhdr are sometimes 64 bits. */ | |
158 | #ifndef GET_SCNHDR_PADDR | |
159 | #define GET_SCNHDR_PADDR bfd_h_get_32 | |
160 | #endif | |
161 | #ifndef PUT_SCNHDR_PADDR | |
162 | #define PUT_SCNHDR_PADDR bfd_h_put_32 | |
163 | #endif | |
164 | #ifndef GET_SCNHDR_VADDR | |
165 | #define GET_SCNHDR_VADDR bfd_h_get_32 | |
166 | #endif | |
167 | #ifndef PUT_SCNHDR_VADDR | |
168 | #define PUT_SCNHDR_VADDR bfd_h_put_32 | |
169 | #endif | |
170 | #ifndef GET_SCNHDR_SIZE | |
171 | #define GET_SCNHDR_SIZE bfd_h_get_32 | |
172 | #endif | |
173 | #ifndef PUT_SCNHDR_SIZE | |
174 | #define PUT_SCNHDR_SIZE bfd_h_put_32 | |
175 | #endif | |
176 | #ifndef GET_SCNHDR_SCNPTR | |
177 | #define GET_SCNHDR_SCNPTR bfd_h_get_32 | |
178 | #endif | |
179 | #ifndef PUT_SCNHDR_SCNPTR | |
180 | #define PUT_SCNHDR_SCNPTR bfd_h_put_32 | |
181 | #endif | |
182 | #ifndef GET_SCNHDR_RELPTR | |
183 | #define GET_SCNHDR_RELPTR bfd_h_get_32 | |
184 | #endif | |
185 | #ifndef PUT_SCNHDR_RELPTR | |
186 | #define PUT_SCNHDR_RELPTR bfd_h_put_32 | |
187 | #endif | |
188 | #ifndef GET_SCNHDR_LNNOPTR | |
189 | #define GET_SCNHDR_LNNOPTR bfd_h_get_32 | |
190 | #endif | |
191 | #ifndef PUT_SCNHDR_LNNOPTR | |
192 | #define PUT_SCNHDR_LNNOPTR bfd_h_put_32 | |
193 | #endif | |
194 | ||
cbff5e0d | 195 | #ifdef COFF_WITH_pep |
fac41780 JW |
196 | |
197 | #define GET_OPTHDR_IMAGE_BASE bfd_h_get_64 | |
198 | #define PUT_OPTHDR_IMAGE_BASE bfd_h_put_64 | |
199 | #define GET_OPTHDR_SIZE_OF_STACK_RESERVE bfd_h_get_64 | |
200 | #define PUT_OPTHDR_SIZE_OF_STACK_RESERVE bfd_h_put_64 | |
201 | #define GET_OPTHDR_SIZE_OF_STACK_COMMIT bfd_h_get_64 | |
202 | #define PUT_OPTHDR_SIZE_OF_STACK_COMMIT bfd_h_put_64 | |
203 | #define GET_OPTHDR_SIZE_OF_HEAP_RESERVE bfd_h_get_64 | |
204 | #define PUT_OPTHDR_SIZE_OF_HEAP_RESERVE bfd_h_put_64 | |
205 | #define GET_OPTHDR_SIZE_OF_HEAP_COMMIT bfd_h_get_64 | |
206 | #define PUT_OPTHDR_SIZE_OF_HEAP_COMMIT bfd_h_put_64 | |
207 | #define GET_PDATA_ENTRY bfd_get_64 | |
208 | ||
cbff5e0d DD |
209 | #define _bfd_XX_bfd_copy_private_bfd_data_common _bfd_pep_bfd_copy_private_bfd_data_common |
210 | #define _bfd_XX_bfd_copy_private_section_data _bfd_pep_bfd_copy_private_section_data | |
211 | #define _bfd_XX_get_symbol_info _bfd_pep_get_symbol_info | |
212 | #define _bfd_XX_only_swap_filehdr_out _bfd_pep_only_swap_filehdr_out | |
213 | #define _bfd_XX_print_private_bfd_data_common _bfd_pep_print_private_bfd_data_common | |
214 | #define _bfd_XXi_final_link_postscript _bfd_pepi_final_link_postscript | |
215 | #define _bfd_XXi_final_link_postscript _bfd_pepi_final_link_postscript | |
216 | #define _bfd_XXi_only_swap_filehdr_out _bfd_pepi_only_swap_filehdr_out | |
217 | #define _bfd_XXi_swap_aouthdr_in _bfd_pepi_swap_aouthdr_in | |
218 | #define _bfd_XXi_swap_aouthdr_out _bfd_pepi_swap_aouthdr_out | |
219 | #define _bfd_XXi_swap_aux_in _bfd_pepi_swap_aux_in | |
220 | #define _bfd_XXi_swap_aux_out _bfd_pepi_swap_aux_out | |
221 | #define _bfd_XXi_swap_lineno_in _bfd_pepi_swap_lineno_in | |
222 | #define _bfd_XXi_swap_lineno_out _bfd_pepi_swap_lineno_out | |
223 | #define _bfd_XXi_swap_scnhdr_out _bfd_pepi_swap_scnhdr_out | |
224 | #define _bfd_XXi_swap_sym_in _bfd_pepi_swap_sym_in | |
225 | #define _bfd_XXi_swap_sym_out _bfd_pepi_swap_sym_out | |
226 | ||
227 | #else /* !COFF_WITH_pep */ | |
fac41780 JW |
228 | |
229 | #define GET_OPTHDR_IMAGE_BASE bfd_h_get_32 | |
230 | #define PUT_OPTHDR_IMAGE_BASE bfd_h_put_32 | |
231 | #define GET_OPTHDR_SIZE_OF_STACK_RESERVE bfd_h_get_32 | |
232 | #define PUT_OPTHDR_SIZE_OF_STACK_RESERVE bfd_h_put_32 | |
233 | #define GET_OPTHDR_SIZE_OF_STACK_COMMIT bfd_h_get_32 | |
234 | #define PUT_OPTHDR_SIZE_OF_STACK_COMMIT bfd_h_put_32 | |
235 | #define GET_OPTHDR_SIZE_OF_HEAP_RESERVE bfd_h_get_32 | |
236 | #define PUT_OPTHDR_SIZE_OF_HEAP_RESERVE bfd_h_put_32 | |
237 | #define GET_OPTHDR_SIZE_OF_HEAP_COMMIT bfd_h_get_32 | |
238 | #define PUT_OPTHDR_SIZE_OF_HEAP_COMMIT bfd_h_put_32 | |
239 | #define GET_PDATA_ENTRY bfd_get_32 | |
240 | ||
cbff5e0d DD |
241 | #define _bfd_XX_bfd_copy_private_bfd_data_common _bfd_pe_bfd_copy_private_bfd_data_common |
242 | #define _bfd_XX_bfd_copy_private_section_data _bfd_pe_bfd_copy_private_section_data | |
243 | #define _bfd_XX_get_symbol_info _bfd_pe_get_symbol_info | |
244 | #define _bfd_XX_only_swap_filehdr_out _bfd_pe_only_swap_filehdr_out | |
245 | #define _bfd_XX_print_private_bfd_data_common _bfd_pe_print_private_bfd_data_common | |
246 | #define _bfd_XXi_final_link_postscript _bfd_pei_final_link_postscript | |
247 | #define _bfd_XXi_final_link_postscript _bfd_pei_final_link_postscript | |
248 | #define _bfd_XXi_only_swap_filehdr_out _bfd_pei_only_swap_filehdr_out | |
249 | #define _bfd_XXi_swap_aouthdr_in _bfd_pei_swap_aouthdr_in | |
250 | #define _bfd_XXi_swap_aouthdr_out _bfd_pei_swap_aouthdr_out | |
251 | #define _bfd_XXi_swap_aux_in _bfd_pei_swap_aux_in | |
252 | #define _bfd_XXi_swap_aux_out _bfd_pei_swap_aux_out | |
253 | #define _bfd_XXi_swap_lineno_in _bfd_pei_swap_lineno_in | |
254 | #define _bfd_XXi_swap_lineno_out _bfd_pei_swap_lineno_out | |
255 | #define _bfd_XXi_swap_scnhdr_out _bfd_pei_swap_scnhdr_out | |
256 | #define _bfd_XXi_swap_sym_in _bfd_pei_swap_sym_in | |
257 | #define _bfd_XXi_swap_sym_out _bfd_pei_swap_sym_out | |
258 | ||
259 | #endif /* !COFF_WITH_pep */ | |
fac41780 | 260 | |
277d1b5e ILT |
261 | /* These functions are architecture dependent, and are in peicode.h: |
262 | coff_swap_reloc_in | |
263 | int coff_swap_reloc_out | |
264 | coff_swap_filehdr_in | |
265 | coff_swap_scnhdr_in | |
266 | pe_mkobject | |
267 | pe_mkobject_hook */ | |
268 | ||
269 | /* The functions described below are common across all PE/PEI | |
270 | implementations architecture types, and actually appear in | |
271 | peigen.c. */ | |
272 | ||
cbff5e0d DD |
273 | void _bfd_XXi_swap_sym_in PARAMS ((bfd*, PTR, PTR)); |
274 | #define coff_swap_sym_in _bfd_XXi_swap_sym_in | |
277d1b5e | 275 | |
cbff5e0d DD |
276 | unsigned int _bfd_XXi_swap_sym_out PARAMS ((bfd*, PTR, PTR)); |
277 | #define coff_swap_sym_out _bfd_XXi_swap_sym_out | |
277d1b5e | 278 | |
cbff5e0d DD |
279 | void _bfd_XXi_swap_aux_in PARAMS ((bfd *, PTR, int, int, int, int, PTR)); |
280 | #define coff_swap_aux_in _bfd_XXi_swap_aux_in | |
277d1b5e | 281 | |
cbff5e0d | 282 | unsigned int _bfd_XXi_swap_aux_out \ |
277d1b5e | 283 | PARAMS ((bfd *, PTR, int, int, int, int, PTR)); |
cbff5e0d | 284 | #define coff_swap_aux_out _bfd_XXi_swap_aux_out |
277d1b5e | 285 | |
cbff5e0d DD |
286 | void _bfd_XXi_swap_lineno_in PARAMS ((bfd*, PTR, PTR)); |
287 | #define coff_swap_lineno_in _bfd_XXi_swap_lineno_in | |
277d1b5e | 288 | |
cbff5e0d DD |
289 | unsigned int _bfd_XXi_swap_lineno_out PARAMS ((bfd*, PTR, PTR)); |
290 | #define coff_swap_lineno_out _bfd_XXi_swap_lineno_out | |
277d1b5e | 291 | |
cbff5e0d DD |
292 | void _bfd_XXi_swap_aouthdr_in PARAMS ((bfd*, PTR, PTR)); |
293 | #define coff_swap_aouthdr_in _bfd_XXi_swap_aouthdr_in | |
277d1b5e | 294 | |
cbff5e0d DD |
295 | unsigned int _bfd_XXi_swap_aouthdr_out PARAMS ((bfd *, PTR, PTR)); |
296 | #define coff_swap_aouthdr_out _bfd_XXi_swap_aouthdr_out | |
277d1b5e | 297 | |
cbff5e0d DD |
298 | unsigned int _bfd_XXi_swap_scnhdr_out PARAMS ((bfd *, PTR, PTR)); |
299 | #define coff_swap_scnhdr_out _bfd_XXi_swap_scnhdr_out | |
277d1b5e | 300 | |
cbff5e0d | 301 | boolean _bfd_XX_print_private_bfd_data_common PARAMS ((bfd *, PTR)); |
277d1b5e | 302 | |
cbff5e0d | 303 | boolean _bfd_XX_bfd_copy_private_bfd_data_common PARAMS ((bfd *, bfd *)); |
7d2b58d6 | 304 | |
cbff5e0d | 305 | void _bfd_XX_get_symbol_info PARAMS ((bfd *, asymbol *, symbol_info *)); |
277d1b5e | 306 | |
cbff5e0d | 307 | boolean _bfd_XXi_final_link_postscript |
2fbadf2c | 308 | PARAMS ((bfd *, struct coff_final_link_info *)); |
2fbadf2c | 309 | |
17505c5c | 310 | #ifndef coff_final_link_postscript |
cbff5e0d | 311 | #define coff_final_link_postscript _bfd_XXi_final_link_postscript |
17505c5c | 312 | #endif |
277d1b5e ILT |
313 | /* The following are needed only for ONE of pe or pei, but don't |
314 | otherwise vary; peicode.h fixes up ifdefs but we provide the | |
315 | prototype. */ | |
316 | ||
cbff5e0d DD |
317 | unsigned int _bfd_XX_only_swap_filehdr_out PARAMS ((bfd*, PTR, PTR)); |
318 | unsigned int _bfd_XXi_only_swap_filehdr_out PARAMS ((bfd*, PTR, PTR)); | |
319 | boolean _bfd_XX_bfd_copy_private_section_data | |
277d1b5e | 320 | PARAMS ((bfd *, asection *, bfd *, asection *)); |