1 /* Support for the generic parts of PE/PEI; common header information.
2 Copyright 1995, 1996, 1997, 1998, 1999, 2001 Free Software Foundation, Inc.
3 Written by Cygnus Solutions.
5 This file is part of BFD, the Binary File Descriptor library.
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.
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.
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. */
22 Most of this hacked by Steve Chamberlain,
25 PE/PEI rearrangement (and code added): Donn Terry
29 /* Hey look, some documentation [and in a place you expect to find it]!
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.
36 "Peering Inside the PE: A Tour of the Win32 Portable Executable
37 File Format", MSJ 1994, Volume 9.
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
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.
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.
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)
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)
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)
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)
75 #define GET_LNSZ_LNNO(abfd, ext) bfd_h_get_16(abfd, (bfd_byte *) ext->x_sym.x_misc.x_lnsz.x_lnno)
78 #define GET_LNSZ_SIZE(abfd, ext) bfd_h_get_16(abfd, (bfd_byte *) ext->x_sym.x_misc.x_lnsz.x_size)
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)
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)
86 #ifndef GET_SCN_SCNLEN
87 #define GET_SCN_SCNLEN(abfd, ext) bfd_h_get_32(abfd, (bfd_byte *) ext->x_scn.x_scnlen)
89 #ifndef GET_SCN_NRELOC
90 #define GET_SCN_NRELOC(abfd, ext) bfd_h_get_16(abfd, (bfd_byte *)ext->x_scn.x_nreloc)
92 #ifndef GET_SCN_NLINNO
93 #define GET_SCN_NLINNO(abfd, ext) bfd_h_get_16(abfd, (bfd_byte *)ext->x_scn.x_nlinno)
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)
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)
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)
104 #ifndef GET_LINENO_LNNO
105 #define GET_LINENO_LNNO(abfd, ext) bfd_h_get_16(abfd, (bfd_byte *) (ext->l_lnno));
107 #ifndef PUT_LINENO_LNNO
108 #define PUT_LINENO_LNNO(abfd,val, ext) bfd_h_put_16(abfd,val, (bfd_byte *) (ext->l_lnno));
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
115 #ifndef PUT_FILEHDR_SYMPTR
116 #define PUT_FILEHDR_SYMPTR bfd_h_put_32
119 /* Some fields in the aouthdr are sometimes 64 bits. */
120 #ifndef GET_AOUTHDR_TSIZE
121 #define GET_AOUTHDR_TSIZE bfd_h_get_32
123 #ifndef PUT_AOUTHDR_TSIZE
124 #define PUT_AOUTHDR_TSIZE bfd_h_put_32
126 #ifndef GET_AOUTHDR_DSIZE
127 #define GET_AOUTHDR_DSIZE bfd_h_get_32
129 #ifndef PUT_AOUTHDR_DSIZE
130 #define PUT_AOUTHDR_DSIZE bfd_h_put_32
132 #ifndef GET_AOUTHDR_BSIZE
133 #define GET_AOUTHDR_BSIZE bfd_h_get_32
135 #ifndef PUT_AOUTHDR_BSIZE
136 #define PUT_AOUTHDR_BSIZE bfd_h_put_32
138 #ifndef GET_AOUTHDR_ENTRY
139 #define GET_AOUTHDR_ENTRY bfd_h_get_32
141 #ifndef PUT_AOUTHDR_ENTRY
142 #define PUT_AOUTHDR_ENTRY bfd_h_put_32
144 #ifndef GET_AOUTHDR_TEXT_START
145 #define GET_AOUTHDR_TEXT_START bfd_h_get_32
147 #ifndef PUT_AOUTHDR_TEXT_START
148 #define PUT_AOUTHDR_TEXT_START bfd_h_put_32
150 #ifndef GET_AOUTHDR_DATA_START
151 #define GET_AOUTHDR_DATA_START bfd_h_get_32
153 #ifndef PUT_AOUTHDR_DATA_START
154 #define PUT_AOUTHDR_DATA_START bfd_h_put_32
157 /* Some fields in the scnhdr are sometimes 64 bits. */
158 #ifndef GET_SCNHDR_PADDR
159 #define GET_SCNHDR_PADDR bfd_h_get_32
161 #ifndef PUT_SCNHDR_PADDR
162 #define PUT_SCNHDR_PADDR bfd_h_put_32
164 #ifndef GET_SCNHDR_VADDR
165 #define GET_SCNHDR_VADDR bfd_h_get_32
167 #ifndef PUT_SCNHDR_VADDR
168 #define PUT_SCNHDR_VADDR bfd_h_put_32
170 #ifndef GET_SCNHDR_SIZE
171 #define GET_SCNHDR_SIZE bfd_h_get_32
173 #ifndef PUT_SCNHDR_SIZE
174 #define PUT_SCNHDR_SIZE bfd_h_put_32
176 #ifndef GET_SCNHDR_SCNPTR
177 #define GET_SCNHDR_SCNPTR bfd_h_get_32
179 #ifndef PUT_SCNHDR_SCNPTR
180 #define PUT_SCNHDR_SCNPTR bfd_h_put_32
182 #ifndef GET_SCNHDR_RELPTR
183 #define GET_SCNHDR_RELPTR bfd_h_get_32
185 #ifndef PUT_SCNHDR_RELPTR
186 #define PUT_SCNHDR_RELPTR bfd_h_put_32
188 #ifndef GET_SCNHDR_LNNOPTR
189 #define GET_SCNHDR_LNNOPTR bfd_h_get_32
191 #ifndef PUT_SCNHDR_LNNOPTR
192 #define PUT_SCNHDR_LNNOPTR bfd_h_put_32
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
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
227 #else /* !COFF_WITH_pep */
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
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
259 #endif /* !COFF_WITH_pep */
261 /* These functions are architecture dependent, and are in peicode.h:
263 int coff_swap_reloc_out
269 /* The functions described below are common across all PE/PEI
270 implementations architecture types, and actually appear in
273 void _bfd_XXi_swap_sym_in PARAMS ((bfd*, PTR, PTR));
274 #define coff_swap_sym_in _bfd_XXi_swap_sym_in
276 unsigned int _bfd_XXi_swap_sym_out PARAMS ((bfd*, PTR, PTR));
277 #define coff_swap_sym_out _bfd_XXi_swap_sym_out
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
282 unsigned int _bfd_XXi_swap_aux_out \
283 PARAMS ((bfd *, PTR, int, int, int, int, PTR));
284 #define coff_swap_aux_out _bfd_XXi_swap_aux_out
286 void _bfd_XXi_swap_lineno_in PARAMS ((bfd*, PTR, PTR));
287 #define coff_swap_lineno_in _bfd_XXi_swap_lineno_in
289 unsigned int _bfd_XXi_swap_lineno_out PARAMS ((bfd*, PTR, PTR));
290 #define coff_swap_lineno_out _bfd_XXi_swap_lineno_out
292 void _bfd_XXi_swap_aouthdr_in PARAMS ((bfd*, PTR, PTR));
293 #define coff_swap_aouthdr_in _bfd_XXi_swap_aouthdr_in
295 unsigned int _bfd_XXi_swap_aouthdr_out PARAMS ((bfd *, PTR, PTR));
296 #define coff_swap_aouthdr_out _bfd_XXi_swap_aouthdr_out
298 unsigned int _bfd_XXi_swap_scnhdr_out PARAMS ((bfd *, PTR, PTR));
299 #define coff_swap_scnhdr_out _bfd_XXi_swap_scnhdr_out
301 boolean _bfd_XX_print_private_bfd_data_common PARAMS ((bfd *, PTR));
303 boolean _bfd_XX_bfd_copy_private_bfd_data_common PARAMS ((bfd *, bfd *));
305 void _bfd_XX_get_symbol_info PARAMS ((bfd *, asymbol *, symbol_info *));
307 boolean _bfd_XXi_final_link_postscript
308 PARAMS ((bfd *, struct coff_final_link_info *));
310 #ifndef coff_final_link_postscript
311 #define coff_final_link_postscript _bfd_XXi_final_link_postscript
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
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
320 PARAMS ((bfd *, asection *, bfd *, asection *));