1 /* Support for the generic parts of PE/PEI; common header information.
2 Copyright 1995, 1996, 1997, 1998, 1999 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
195 #ifdef COFF_WITH_PEP64
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 #else /* !COFF_WITH_PEP64 */
211 #define GET_OPTHDR_IMAGE_BASE bfd_h_get_32
212 #define PUT_OPTHDR_IMAGE_BASE bfd_h_put_32
213 #define GET_OPTHDR_SIZE_OF_STACK_RESERVE bfd_h_get_32
214 #define PUT_OPTHDR_SIZE_OF_STACK_RESERVE bfd_h_put_32
215 #define GET_OPTHDR_SIZE_OF_STACK_COMMIT bfd_h_get_32
216 #define PUT_OPTHDR_SIZE_OF_STACK_COMMIT bfd_h_put_32
217 #define GET_OPTHDR_SIZE_OF_HEAP_RESERVE bfd_h_get_32
218 #define PUT_OPTHDR_SIZE_OF_HEAP_RESERVE bfd_h_put_32
219 #define GET_OPTHDR_SIZE_OF_HEAP_COMMIT bfd_h_get_32
220 #define PUT_OPTHDR_SIZE_OF_HEAP_COMMIT bfd_h_put_32
221 #define GET_PDATA_ENTRY bfd_get_32
223 #endif /* !COFF_WITH_PEP64 */
225 /* These functions are architecture dependent, and are in peicode.h:
227 int coff_swap_reloc_out
233 /* The functions described below are common across all PE/PEI
234 implementations architecture types, and actually appear in
237 void _bfd_pei_swap_sym_in PARAMS ((bfd*, PTR, PTR));
238 #define coff_swap_sym_in _bfd_pei_swap_sym_in
240 unsigned int _bfd_pei_swap_sym_out PARAMS ((bfd*, PTR, PTR));
241 #define coff_swap_sym_out _bfd_pei_swap_sym_out
243 void _bfd_pei_swap_aux_in PARAMS ((bfd *, PTR, int, int, int, int, PTR));
244 #define coff_swap_aux_in _bfd_pei_swap_aux_in
246 unsigned int _bfd_pei_swap_aux_out \
247 PARAMS ((bfd *, PTR, int, int, int, int, PTR));
248 #define coff_swap_aux_out _bfd_pei_swap_aux_out
250 void _bfd_pei_swap_lineno_in PARAMS ((bfd*, PTR, PTR));
251 #define coff_swap_lineno_in _bfd_pei_swap_lineno_in
253 unsigned int _bfd_pei_swap_lineno_out PARAMS ((bfd*, PTR, PTR));
254 #define coff_swap_lineno_out _bfd_pei_swap_lineno_out
256 void _bfd_pei_swap_aouthdr_in PARAMS ((bfd*, PTR, PTR));
257 #define coff_swap_aouthdr_in _bfd_pei_swap_aouthdr_in
259 unsigned int _bfd_pei_swap_aouthdr_out PARAMS ((bfd *, PTR, PTR));
260 #define coff_swap_aouthdr_out _bfd_pei_swap_aouthdr_out
262 unsigned int _bfd_pei_swap_scnhdr_out PARAMS ((bfd *, PTR, PTR));
263 #define coff_swap_scnhdr_out _bfd_pei_swap_scnhdr_out
265 boolean _bfd_pe_print_private_bfd_data_common PARAMS ((bfd *, PTR));
267 boolean _bfd_pe_bfd_copy_private_bfd_data_common PARAMS ((bfd *, bfd *));
269 void _bfd_pe_get_symbol_info PARAMS ((bfd *, asymbol *, symbol_info *));
271 boolean _bfd_pei_final_link_postscript
272 PARAMS ((bfd *, struct coff_final_link_info *));
274 #ifndef coff_final_link_postscript
275 #define coff_final_link_postscript _bfd_pei_final_link_postscript
277 /* The following are needed only for ONE of pe or pei, but don't
278 otherwise vary; peicode.h fixes up ifdefs but we provide the
281 unsigned int _bfd_pe_only_swap_filehdr_out PARAMS ((bfd*, PTR, PTR));
282 unsigned int _bfd_pei_only_swap_filehdr_out PARAMS ((bfd*, PTR, PTR));
283 boolean _bfd_pe_bfd_copy_private_section_data
284 PARAMS ((bfd *, asection *, bfd *, asection *));