]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blob - bfd/libpei.h
Update copyright notices
[thirdparty/binutils-gdb.git] / bfd / libpei.h
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.
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) \
61 bfd_h_get_32(abfd, (bfd_byte *) ext->x_sym.x_fcnary.x_fcn.x_lnnoptr)
62 #endif
63
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)
67 #endif
68
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)
71 #endif
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)
74 #endif
75 #ifndef GET_LNSZ_LNNO
76 #define GET_LNSZ_LNNO(abfd, ext) bfd_h_get_16(abfd, (bfd_byte *) ext->x_sym.x_misc.x_lnsz.x_lnno)
77 #endif
78 #ifndef GET_LNSZ_SIZE
79 #define GET_LNSZ_SIZE(abfd, ext) bfd_h_get_16(abfd, (bfd_byte *) ext->x_sym.x_misc.x_lnsz.x_size)
80 #endif
81 #ifndef PUT_LNSZ_LNNO
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)
83 #endif
84 #ifndef PUT_LNSZ_SIZE
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)
86 #endif
87 #ifndef GET_SCN_SCNLEN
88 #define GET_SCN_SCNLEN(abfd, ext) bfd_h_get_32(abfd, (bfd_byte *) ext->x_scn.x_scnlen)
89 #endif
90 #ifndef GET_SCN_NRELOC
91 #define GET_SCN_NRELOC(abfd, ext) bfd_h_get_16(abfd, (bfd_byte *)ext->x_scn.x_nreloc)
92 #endif
93 #ifndef GET_SCN_NLINNO
94 #define GET_SCN_NLINNO(abfd, ext) bfd_h_get_16(abfd, (bfd_byte *)ext->x_scn.x_nlinno)
95 #endif
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)
98 #endif
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)
101 #endif
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)
104 #endif
105 #ifndef GET_LINENO_LNNO
106 #define GET_LINENO_LNNO(abfd, ext) bfd_h_get_16(abfd, (bfd_byte *) (ext->l_lnno));
107 #endif
108 #ifndef PUT_LINENO_LNNO
109 #define PUT_LINENO_LNNO(abfd,val, ext) bfd_h_put_16(abfd,val, (bfd_byte *) (ext->l_lnno));
110 #endif
111
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
115 #endif
116 #ifndef PUT_FILEHDR_SYMPTR
117 #define PUT_FILEHDR_SYMPTR bfd_h_put_32
118 #endif
119
120 /* Some fields in the aouthdr are sometimes 64 bits. */
121 #ifndef GET_AOUTHDR_TSIZE
122 #define GET_AOUTHDR_TSIZE bfd_h_get_32
123 #endif
124 #ifndef PUT_AOUTHDR_TSIZE
125 #define PUT_AOUTHDR_TSIZE bfd_h_put_32
126 #endif
127 #ifndef GET_AOUTHDR_DSIZE
128 #define GET_AOUTHDR_DSIZE bfd_h_get_32
129 #endif
130 #ifndef PUT_AOUTHDR_DSIZE
131 #define PUT_AOUTHDR_DSIZE bfd_h_put_32
132 #endif
133 #ifndef GET_AOUTHDR_BSIZE
134 #define GET_AOUTHDR_BSIZE bfd_h_get_32
135 #endif
136 #ifndef PUT_AOUTHDR_BSIZE
137 #define PUT_AOUTHDR_BSIZE bfd_h_put_32
138 #endif
139 #ifndef GET_AOUTHDR_ENTRY
140 #define GET_AOUTHDR_ENTRY bfd_h_get_32
141 #endif
142 #ifndef PUT_AOUTHDR_ENTRY
143 #define PUT_AOUTHDR_ENTRY bfd_h_put_32
144 #endif
145 #ifndef GET_AOUTHDR_TEXT_START
146 #define GET_AOUTHDR_TEXT_START bfd_h_get_32
147 #endif
148 #ifndef PUT_AOUTHDR_TEXT_START
149 #define PUT_AOUTHDR_TEXT_START bfd_h_put_32
150 #endif
151 #ifndef GET_AOUTHDR_DATA_START
152 #define GET_AOUTHDR_DATA_START bfd_h_get_32
153 #endif
154 #ifndef PUT_AOUTHDR_DATA_START
155 #define PUT_AOUTHDR_DATA_START bfd_h_put_32
156 #endif
157
158 /* Some fields in the scnhdr are sometimes 64 bits. */
159 #ifndef GET_SCNHDR_PADDR
160 #define GET_SCNHDR_PADDR bfd_h_get_32
161 #endif
162 #ifndef PUT_SCNHDR_PADDR
163 #define PUT_SCNHDR_PADDR bfd_h_put_32
164 #endif
165 #ifndef GET_SCNHDR_VADDR
166 #define GET_SCNHDR_VADDR bfd_h_get_32
167 #endif
168 #ifndef PUT_SCNHDR_VADDR
169 #define PUT_SCNHDR_VADDR bfd_h_put_32
170 #endif
171 #ifndef GET_SCNHDR_SIZE
172 #define GET_SCNHDR_SIZE bfd_h_get_32
173 #endif
174 #ifndef PUT_SCNHDR_SIZE
175 #define PUT_SCNHDR_SIZE bfd_h_put_32
176 #endif
177 #ifndef GET_SCNHDR_SCNPTR
178 #define GET_SCNHDR_SCNPTR bfd_h_get_32
179 #endif
180 #ifndef PUT_SCNHDR_SCNPTR
181 #define PUT_SCNHDR_SCNPTR bfd_h_put_32
182 #endif
183 #ifndef GET_SCNHDR_RELPTR
184 #define GET_SCNHDR_RELPTR bfd_h_get_32
185 #endif
186 #ifndef PUT_SCNHDR_RELPTR
187 #define PUT_SCNHDR_RELPTR bfd_h_put_32
188 #endif
189 #ifndef GET_SCNHDR_LNNOPTR
190 #define GET_SCNHDR_LNNOPTR bfd_h_get_32
191 #endif
192 #ifndef PUT_SCNHDR_LNNOPTR
193 #define PUT_SCNHDR_LNNOPTR bfd_h_put_32
194 #endif
195
196 #ifdef COFF_WITH_pep
197
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
209
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
227
228 #else /* !COFF_WITH_pep */
229
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
241
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
259
260 #endif /* !COFF_WITH_pep */
261
262 /* These functions are architecture dependent, and are in peicode.h:
263 coff_swap_reloc_in
264 int coff_swap_reloc_out
265 coff_swap_filehdr_in
266 coff_swap_scnhdr_in
267 pe_mkobject
268 pe_mkobject_hook */
269
270 /* The functions described below are common across all PE/PEI
271 implementations architecture types, and actually appear in
272 peigen.c. */
273
274 void _bfd_XXi_swap_sym_in PARAMS ((bfd*, PTR, PTR));
275 #define coff_swap_sym_in _bfd_XXi_swap_sym_in
276
277 unsigned int _bfd_XXi_swap_sym_out PARAMS ((bfd*, PTR, PTR));
278 #define coff_swap_sym_out _bfd_XXi_swap_sym_out
279
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
282
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
286
287 void _bfd_XXi_swap_lineno_in PARAMS ((bfd*, PTR, PTR));
288 #define coff_swap_lineno_in _bfd_XXi_swap_lineno_in
289
290 unsigned int _bfd_XXi_swap_lineno_out PARAMS ((bfd*, PTR, PTR));
291 #define coff_swap_lineno_out _bfd_XXi_swap_lineno_out
292
293 void _bfd_XXi_swap_aouthdr_in PARAMS ((bfd*, PTR, PTR));
294 #define coff_swap_aouthdr_in _bfd_XXi_swap_aouthdr_in
295
296 unsigned int _bfd_XXi_swap_aouthdr_out PARAMS ((bfd *, PTR, PTR));
297 #define coff_swap_aouthdr_out _bfd_XXi_swap_aouthdr_out
298
299 unsigned int _bfd_XXi_swap_scnhdr_out PARAMS ((bfd *, PTR, PTR));
300 #define coff_swap_scnhdr_out _bfd_XXi_swap_scnhdr_out
301
302 boolean _bfd_XX_print_private_bfd_data_common PARAMS ((bfd *, PTR));
303
304 boolean _bfd_XX_bfd_copy_private_bfd_data_common PARAMS ((bfd *, bfd *));
305
306 void _bfd_XX_get_symbol_info PARAMS ((bfd *, asymbol *, symbol_info *));
307
308 boolean _bfd_XXi_final_link_postscript
309 PARAMS ((bfd *, struct coff_final_link_info *));
310
311 #ifndef coff_final_link_postscript
312 #define coff_final_link_postscript _bfd_XXi_final_link_postscript
313 #endif
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
316 prototype. */
317
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 *));