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