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