1 /* Support for the generic parts of PE/PEI; common header information.
2 Copyright 1995, 1996, 1997, 1998, 1999, 2000, 2001
3 Free Software Foundation, Inc.
4 Written by Cygnus Solutions.
6 This file is part of BFD, the Binary File Descriptor library.
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.
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.
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. */
23 Most of this hacked by Steve Chamberlain,
26 PE/PEI rearrangement (and code added): Donn Terry
30 /* Hey look, some documentation [and in a place you expect to find it]!
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.
37 "Peering Inside the PE: A Tour of the Win32 Portable Executable
38 File Format", MSJ 1994, Volume 9.
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
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.
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.
59 #ifndef GET_FCN_LNNOPTR
60 #define GET_FCN_LNNOPTR(abfd, ext) \
61 bfd_h_get_32(abfd, (bfd_byte *) ext->x_sym.x_fcnary.x_fcn.x_lnnoptr)
64 #ifndef GET_FCN_ENDNDX
65 #define GET_FCN_ENDNDX(abfd, ext) \
66 bfd_h_get_32(abfd, (bfd_byte *) ext->x_sym.x_fcnary.x_fcn.x_endndx)
69 #ifndef PUT_FCN_LNNOPTR
70 #define PUT_FCN_LNNOPTR(abfd, in, ext) bfd_h_put_32(abfd, in, (bfd_byte *) ext->x_sym.x_fcnary.x_fcn.x_lnnoptr)
72 #ifndef PUT_FCN_ENDNDX
73 #define PUT_FCN_ENDNDX(abfd, in, ext) bfd_h_put_32(abfd, in, (bfd_byte *) ext->x_sym.x_fcnary.x_fcn.x_endndx)
76 #define GET_LNSZ_LNNO(abfd, ext) bfd_h_get_16(abfd, (bfd_byte *) ext->x_sym.x_misc.x_lnsz.x_lnno)
79 #define GET_LNSZ_SIZE(abfd, ext) bfd_h_get_16(abfd, (bfd_byte *) ext->x_sym.x_misc.x_lnsz.x_size)
82 #define PUT_LNSZ_LNNO(abfd, in, ext) bfd_h_put_16(abfd, in, (bfd_byte *)ext->x_sym.x_misc.x_lnsz.x_lnno)
85 #define PUT_LNSZ_SIZE(abfd, in, ext) bfd_h_put_16(abfd, in, (bfd_byte*) ext->x_sym.x_misc.x_lnsz.x_size)
87 #ifndef GET_SCN_SCNLEN
88 #define GET_SCN_SCNLEN(abfd, ext) bfd_h_get_32(abfd, (bfd_byte *) ext->x_scn.x_scnlen)
90 #ifndef GET_SCN_NRELOC
91 #define GET_SCN_NRELOC(abfd, ext) bfd_h_get_16(abfd, (bfd_byte *)ext->x_scn.x_nreloc)
93 #ifndef GET_SCN_NLINNO
94 #define GET_SCN_NLINNO(abfd, ext) bfd_h_get_16(abfd, (bfd_byte *)ext->x_scn.x_nlinno)
96 #ifndef PUT_SCN_SCNLEN
97 #define PUT_SCN_SCNLEN(abfd,in, ext) bfd_h_put_32(abfd, in, (bfd_byte *) ext->x_scn.x_scnlen)
99 #ifndef PUT_SCN_NRELOC
100 #define PUT_SCN_NRELOC(abfd,in, ext) bfd_h_put_16(abfd, in, (bfd_byte *)ext->x_scn.x_nreloc)
102 #ifndef PUT_SCN_NLINNO
103 #define PUT_SCN_NLINNO(abfd,in, ext) bfd_h_put_16(abfd,in, (bfd_byte *) ext->x_scn.x_nlinno)
105 #ifndef GET_LINENO_LNNO
106 #define GET_LINENO_LNNO(abfd, ext) bfd_h_get_16(abfd, (bfd_byte *) (ext->l_lnno));
108 #ifndef PUT_LINENO_LNNO
109 #define PUT_LINENO_LNNO(abfd,val, ext) bfd_h_put_16(abfd,val, (bfd_byte *) (ext->l_lnno));
112 /* The f_symptr field in the filehdr is sometimes 64 bits. */
113 #ifndef GET_FILEHDR_SYMPTR
114 #define GET_FILEHDR_SYMPTR bfd_h_get_32
116 #ifndef PUT_FILEHDR_SYMPTR
117 #define PUT_FILEHDR_SYMPTR bfd_h_put_32
120 /* Some fields in the aouthdr are sometimes 64 bits. */
121 #ifndef GET_AOUTHDR_TSIZE
122 #define GET_AOUTHDR_TSIZE bfd_h_get_32
124 #ifndef PUT_AOUTHDR_TSIZE
125 #define PUT_AOUTHDR_TSIZE bfd_h_put_32
127 #ifndef GET_AOUTHDR_DSIZE
128 #define GET_AOUTHDR_DSIZE bfd_h_get_32
130 #ifndef PUT_AOUTHDR_DSIZE
131 #define PUT_AOUTHDR_DSIZE bfd_h_put_32
133 #ifndef GET_AOUTHDR_BSIZE
134 #define GET_AOUTHDR_BSIZE bfd_h_get_32
136 #ifndef PUT_AOUTHDR_BSIZE
137 #define PUT_AOUTHDR_BSIZE bfd_h_put_32
139 #ifndef GET_AOUTHDR_ENTRY
140 #define GET_AOUTHDR_ENTRY bfd_h_get_32
142 #ifndef PUT_AOUTHDR_ENTRY
143 #define PUT_AOUTHDR_ENTRY bfd_h_put_32
145 #ifndef GET_AOUTHDR_TEXT_START
146 #define GET_AOUTHDR_TEXT_START bfd_h_get_32
148 #ifndef PUT_AOUTHDR_TEXT_START
149 #define PUT_AOUTHDR_TEXT_START bfd_h_put_32
151 #ifndef GET_AOUTHDR_DATA_START
152 #define GET_AOUTHDR_DATA_START bfd_h_get_32
154 #ifndef PUT_AOUTHDR_DATA_START
155 #define PUT_AOUTHDR_DATA_START bfd_h_put_32
158 /* Some fields in the scnhdr are sometimes 64 bits. */
159 #ifndef GET_SCNHDR_PADDR
160 #define GET_SCNHDR_PADDR bfd_h_get_32
162 #ifndef PUT_SCNHDR_PADDR
163 #define PUT_SCNHDR_PADDR bfd_h_put_32
165 #ifndef GET_SCNHDR_VADDR
166 #define GET_SCNHDR_VADDR bfd_h_get_32
168 #ifndef PUT_SCNHDR_VADDR
169 #define PUT_SCNHDR_VADDR bfd_h_put_32
171 #ifndef GET_SCNHDR_SIZE
172 #define GET_SCNHDR_SIZE bfd_h_get_32
174 #ifndef PUT_SCNHDR_SIZE
175 #define PUT_SCNHDR_SIZE bfd_h_put_32
177 #ifndef GET_SCNHDR_SCNPTR
178 #define GET_SCNHDR_SCNPTR bfd_h_get_32
180 #ifndef PUT_SCNHDR_SCNPTR
181 #define PUT_SCNHDR_SCNPTR bfd_h_put_32
183 #ifndef GET_SCNHDR_RELPTR
184 #define GET_SCNHDR_RELPTR bfd_h_get_32
186 #ifndef PUT_SCNHDR_RELPTR
187 #define PUT_SCNHDR_RELPTR bfd_h_put_32
189 #ifndef GET_SCNHDR_LNNOPTR
190 #define GET_SCNHDR_LNNOPTR bfd_h_get_32
192 #ifndef PUT_SCNHDR_LNNOPTR
193 #define PUT_SCNHDR_LNNOPTR bfd_h_put_32
198 #define GET_OPTHDR_IMAGE_BASE bfd_h_get_64
199 #define PUT_OPTHDR_IMAGE_BASE bfd_h_put_64
200 #define GET_OPTHDR_SIZE_OF_STACK_RESERVE bfd_h_get_64
201 #define PUT_OPTHDR_SIZE_OF_STACK_RESERVE bfd_h_put_64
202 #define GET_OPTHDR_SIZE_OF_STACK_COMMIT bfd_h_get_64
203 #define PUT_OPTHDR_SIZE_OF_STACK_COMMIT bfd_h_put_64
204 #define GET_OPTHDR_SIZE_OF_HEAP_RESERVE bfd_h_get_64
205 #define PUT_OPTHDR_SIZE_OF_HEAP_RESERVE bfd_h_put_64
206 #define GET_OPTHDR_SIZE_OF_HEAP_COMMIT bfd_h_get_64
207 #define PUT_OPTHDR_SIZE_OF_HEAP_COMMIT bfd_h_put_64
208 #define GET_PDATA_ENTRY bfd_get_64
210 #define _bfd_XX_bfd_copy_private_bfd_data_common _bfd_pep_bfd_copy_private_bfd_data_common
211 #define _bfd_XX_bfd_copy_private_section_data _bfd_pep_bfd_copy_private_section_data
212 #define _bfd_XX_get_symbol_info _bfd_pep_get_symbol_info
213 #define _bfd_XX_only_swap_filehdr_out _bfd_pep_only_swap_filehdr_out
214 #define _bfd_XX_print_private_bfd_data_common _bfd_pep_print_private_bfd_data_common
215 #define _bfd_XXi_final_link_postscript _bfd_pepi_final_link_postscript
216 #define _bfd_XXi_final_link_postscript _bfd_pepi_final_link_postscript
217 #define _bfd_XXi_only_swap_filehdr_out _bfd_pepi_only_swap_filehdr_out
218 #define _bfd_XXi_swap_aouthdr_in _bfd_pepi_swap_aouthdr_in
219 #define _bfd_XXi_swap_aouthdr_out _bfd_pepi_swap_aouthdr_out
220 #define _bfd_XXi_swap_aux_in _bfd_pepi_swap_aux_in
221 #define _bfd_XXi_swap_aux_out _bfd_pepi_swap_aux_out
222 #define _bfd_XXi_swap_lineno_in _bfd_pepi_swap_lineno_in
223 #define _bfd_XXi_swap_lineno_out _bfd_pepi_swap_lineno_out
224 #define _bfd_XXi_swap_scnhdr_out _bfd_pepi_swap_scnhdr_out
225 #define _bfd_XXi_swap_sym_in _bfd_pepi_swap_sym_in
226 #define _bfd_XXi_swap_sym_out _bfd_pepi_swap_sym_out
228 #else /* !COFF_WITH_pep */
230 #define GET_OPTHDR_IMAGE_BASE bfd_h_get_32
231 #define PUT_OPTHDR_IMAGE_BASE bfd_h_put_32
232 #define GET_OPTHDR_SIZE_OF_STACK_RESERVE bfd_h_get_32
233 #define PUT_OPTHDR_SIZE_OF_STACK_RESERVE bfd_h_put_32
234 #define GET_OPTHDR_SIZE_OF_STACK_COMMIT bfd_h_get_32
235 #define PUT_OPTHDR_SIZE_OF_STACK_COMMIT bfd_h_put_32
236 #define GET_OPTHDR_SIZE_OF_HEAP_RESERVE bfd_h_get_32
237 #define PUT_OPTHDR_SIZE_OF_HEAP_RESERVE bfd_h_put_32
238 #define GET_OPTHDR_SIZE_OF_HEAP_COMMIT bfd_h_get_32
239 #define PUT_OPTHDR_SIZE_OF_HEAP_COMMIT bfd_h_put_32
240 #define GET_PDATA_ENTRY bfd_get_32
242 #define _bfd_XX_bfd_copy_private_bfd_data_common _bfd_pe_bfd_copy_private_bfd_data_common
243 #define _bfd_XX_bfd_copy_private_section_data _bfd_pe_bfd_copy_private_section_data
244 #define _bfd_XX_get_symbol_info _bfd_pe_get_symbol_info
245 #define _bfd_XX_only_swap_filehdr_out _bfd_pe_only_swap_filehdr_out
246 #define _bfd_XX_print_private_bfd_data_common _bfd_pe_print_private_bfd_data_common
247 #define _bfd_XXi_final_link_postscript _bfd_pei_final_link_postscript
248 #define _bfd_XXi_final_link_postscript _bfd_pei_final_link_postscript
249 #define _bfd_XXi_only_swap_filehdr_out _bfd_pei_only_swap_filehdr_out
250 #define _bfd_XXi_swap_aouthdr_in _bfd_pei_swap_aouthdr_in
251 #define _bfd_XXi_swap_aouthdr_out _bfd_pei_swap_aouthdr_out
252 #define _bfd_XXi_swap_aux_in _bfd_pei_swap_aux_in
253 #define _bfd_XXi_swap_aux_out _bfd_pei_swap_aux_out
254 #define _bfd_XXi_swap_lineno_in _bfd_pei_swap_lineno_in
255 #define _bfd_XXi_swap_lineno_out _bfd_pei_swap_lineno_out
256 #define _bfd_XXi_swap_scnhdr_out _bfd_pei_swap_scnhdr_out
257 #define _bfd_XXi_swap_sym_in _bfd_pei_swap_sym_in
258 #define _bfd_XXi_swap_sym_out _bfd_pei_swap_sym_out
260 #endif /* !COFF_WITH_pep */
262 /* These functions are architecture dependent, and are in peicode.h:
264 int coff_swap_reloc_out
270 /* The functions described below are common across all PE/PEI
271 implementations architecture types, and actually appear in
274 void _bfd_XXi_swap_sym_in
PARAMS ((bfd
*, PTR
, PTR
));
275 #define coff_swap_sym_in _bfd_XXi_swap_sym_in
277 unsigned int _bfd_XXi_swap_sym_out
PARAMS ((bfd
*, PTR
, PTR
));
278 #define coff_swap_sym_out _bfd_XXi_swap_sym_out
280 void _bfd_XXi_swap_aux_in
PARAMS ((bfd
*, PTR
, int, int, int, int, PTR
));
281 #define coff_swap_aux_in _bfd_XXi_swap_aux_in
283 unsigned int _bfd_XXi_swap_aux_out \
284 PARAMS ((bfd
*, PTR
, int, int, int, int, PTR
));
285 #define coff_swap_aux_out _bfd_XXi_swap_aux_out
287 void _bfd_XXi_swap_lineno_in
PARAMS ((bfd
*, PTR
, PTR
));
288 #define coff_swap_lineno_in _bfd_XXi_swap_lineno_in
290 unsigned int _bfd_XXi_swap_lineno_out
PARAMS ((bfd
*, PTR
, PTR
));
291 #define coff_swap_lineno_out _bfd_XXi_swap_lineno_out
293 void _bfd_XXi_swap_aouthdr_in
PARAMS ((bfd
*, PTR
, PTR
));
294 #define coff_swap_aouthdr_in _bfd_XXi_swap_aouthdr_in
296 unsigned int _bfd_XXi_swap_aouthdr_out
PARAMS ((bfd
*, PTR
, PTR
));
297 #define coff_swap_aouthdr_out _bfd_XXi_swap_aouthdr_out
299 unsigned int _bfd_XXi_swap_scnhdr_out
PARAMS ((bfd
*, PTR
, PTR
));
300 #define coff_swap_scnhdr_out _bfd_XXi_swap_scnhdr_out
302 boolean _bfd_XX_print_private_bfd_data_common
PARAMS ((bfd
*, PTR
));
304 boolean _bfd_XX_bfd_copy_private_bfd_data_common
PARAMS ((bfd
*, bfd
*));
306 void _bfd_XX_get_symbol_info
PARAMS ((bfd
*, asymbol
*, symbol_info
*));
308 boolean _bfd_XXi_final_link_postscript
309 PARAMS ((bfd
*, struct coff_final_link_info
*));
311 #ifndef coff_final_link_postscript
312 #define coff_final_link_postscript _bfd_XXi_final_link_postscript
314 /* The following are needed only for ONE of pe or pei, but don't
315 otherwise vary; peicode.h fixes up ifdefs but we provide the
318 unsigned int _bfd_XX_only_swap_filehdr_out
PARAMS ((bfd
*, PTR
, PTR
));
319 unsigned int _bfd_XXi_only_swap_filehdr_out
PARAMS ((bfd
*, PTR
, PTR
));
320 boolean _bfd_XX_bfd_copy_private_section_data
321 PARAMS ((bfd
*, asection
*, bfd
*, asection
*));