[testsuite] Disable Ctrl-V use for mingw hosts.
[deliverable/binutils-gdb.git] / bfd / libpei.h
CommitLineData
277d1b5e 1/* Support for the generic parts of PE/PEI; common header information.
4b95cf5c 2 Copyright (C) 1995-2014 Free Software Foundation, Inc.
277d1b5e
ILT
3 Written by Cygnus Solutions.
4
ff0c9faf 5 This file is part of BFD, the Binary File Descriptor library.
277d1b5e 6
ff0c9faf
NC
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
cd123cb7 9 the Free Software Foundation; either version 3 of the License, or
ff0c9faf 10 (at your option) any later version.
277d1b5e 11
ff0c9faf
NC
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.
68ffbac6 16
ff0c9faf
NC
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
cd123cb7
NC
19 Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
20 MA 02110-1301, USA. */
21
277d1b5e 22
ff0c9faf 23/* Most of this hacked by Steve Chamberlain,
277d1b5e
ILT
24 sac@cygnus.com
25
ff0c9faf
NC
26 PE/PEI rearrangement (and code added): Donn Terry
27 Softway Systems, Inc. */
277d1b5e
ILT
28
29/* Hey look, some documentation [and in a place you expect to find it]!
30
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.
34
35 Another reference:
36 "Peering Inside the PE: A Tour of the Win32 Portable Executable
37 File Format", MSJ 1994, Volume 9.
38
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
45 document it here!)
46
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.
52
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
ff0c9faf 55 wasting too much time. */
277d1b5e
ILT
56
57#ifndef GET_FCN_LNNOPTR
58#define GET_FCN_LNNOPTR(abfd, ext) \
dc810e39 59 H_GET_32 (abfd, ext->x_sym.x_fcnary.x_fcn.x_lnnoptr)
277d1b5e
ILT
60#endif
61
62#ifndef GET_FCN_ENDNDX
dc810e39
AM
63#define GET_FCN_ENDNDX(abfd, ext) \
64 H_GET_32 (abfd, ext->x_sym.x_fcnary.x_fcn.x_endndx)
277d1b5e
ILT
65#endif
66
67#ifndef PUT_FCN_LNNOPTR
dc810e39
AM
68#define PUT_FCN_LNNOPTR(abfd, in, ext) \
69 H_PUT_32(abfd, in, ext->x_sym.x_fcnary.x_fcn.x_lnnoptr)
277d1b5e
ILT
70#endif
71#ifndef PUT_FCN_ENDNDX
dc810e39
AM
72#define PUT_FCN_ENDNDX(abfd, in, ext) \
73 H_PUT_32(abfd, in, ext->x_sym.x_fcnary.x_fcn.x_endndx)
277d1b5e
ILT
74#endif
75#ifndef GET_LNSZ_LNNO
dc810e39
AM
76#define GET_LNSZ_LNNO(abfd, ext) \
77 H_GET_16 (abfd, ext->x_sym.x_misc.x_lnsz.x_lnno)
277d1b5e
ILT
78#endif
79#ifndef GET_LNSZ_SIZE
dc810e39
AM
80#define GET_LNSZ_SIZE(abfd, ext) \
81 H_GET_16 (abfd, ext->x_sym.x_misc.x_lnsz.x_size)
277d1b5e
ILT
82#endif
83#ifndef PUT_LNSZ_LNNO
dc810e39
AM
84#define PUT_LNSZ_LNNO(abfd, in, ext) \
85 H_PUT_16(abfd, in, ext->x_sym.x_misc.x_lnsz.x_lnno)
277d1b5e
ILT
86#endif
87#ifndef PUT_LNSZ_SIZE
dc810e39
AM
88#define PUT_LNSZ_SIZE(abfd, in, ext) \
89 H_PUT_16(abfd, in, ext->x_sym.x_misc.x_lnsz.x_size)
277d1b5e
ILT
90#endif
91#ifndef GET_SCN_SCNLEN
dc810e39
AM
92#define GET_SCN_SCNLEN(abfd, ext) \
93 H_GET_32 (abfd, ext->x_scn.x_scnlen)
277d1b5e
ILT
94#endif
95#ifndef GET_SCN_NRELOC
dc810e39
AM
96#define GET_SCN_NRELOC(abfd, ext) \
97 H_GET_16 (abfd, ext->x_scn.x_nreloc)
277d1b5e
ILT
98#endif
99#ifndef GET_SCN_NLINNO
dc810e39
AM
100#define GET_SCN_NLINNO(abfd, ext) \
101 H_GET_16 (abfd, ext->x_scn.x_nlinno)
277d1b5e
ILT
102#endif
103#ifndef PUT_SCN_SCNLEN
dc810e39
AM
104#define PUT_SCN_SCNLEN(abfd, in, ext) \
105 H_PUT_32(abfd, in, ext->x_scn.x_scnlen)
277d1b5e
ILT
106#endif
107#ifndef PUT_SCN_NRELOC
dc810e39
AM
108#define PUT_SCN_NRELOC(abfd, in, ext) \
109 H_PUT_16(abfd, in, ext->x_scn.x_nreloc)
277d1b5e
ILT
110#endif
111#ifndef PUT_SCN_NLINNO
dc810e39
AM
112#define PUT_SCN_NLINNO(abfd, in, ext) \
113 H_PUT_16(abfd,in, ext->x_scn.x_nlinno)
277d1b5e
ILT
114#endif
115#ifndef GET_LINENO_LNNO
dc810e39
AM
116#define GET_LINENO_LNNO(abfd, ext) \
117 H_GET_16 (abfd, ext->l_lnno);
277d1b5e
ILT
118#endif
119#ifndef PUT_LINENO_LNNO
dc810e39
AM
120#define PUT_LINENO_LNNO(abfd, val, ext) \
121 H_PUT_16(abfd,val, ext->l_lnno);
277d1b5e
ILT
122#endif
123
124/* The f_symptr field in the filehdr is sometimes 64 bits. */
125#ifndef GET_FILEHDR_SYMPTR
dc810e39 126#define GET_FILEHDR_SYMPTR H_GET_32
277d1b5e
ILT
127#endif
128#ifndef PUT_FILEHDR_SYMPTR
dc810e39 129#define PUT_FILEHDR_SYMPTR H_PUT_32
277d1b5e
ILT
130#endif
131
132/* Some fields in the aouthdr are sometimes 64 bits. */
133#ifndef GET_AOUTHDR_TSIZE
dc810e39 134#define GET_AOUTHDR_TSIZE H_GET_32
277d1b5e
ILT
135#endif
136#ifndef PUT_AOUTHDR_TSIZE
dc810e39 137#define PUT_AOUTHDR_TSIZE H_PUT_32
277d1b5e
ILT
138#endif
139#ifndef GET_AOUTHDR_DSIZE
dc810e39 140#define GET_AOUTHDR_DSIZE H_GET_32
277d1b5e
ILT
141#endif
142#ifndef PUT_AOUTHDR_DSIZE
dc810e39 143#define PUT_AOUTHDR_DSIZE H_PUT_32
277d1b5e
ILT
144#endif
145#ifndef GET_AOUTHDR_BSIZE
dc810e39 146#define GET_AOUTHDR_BSIZE H_GET_32
277d1b5e
ILT
147#endif
148#ifndef PUT_AOUTHDR_BSIZE
dc810e39 149#define PUT_AOUTHDR_BSIZE H_PUT_32
277d1b5e
ILT
150#endif
151#ifndef GET_AOUTHDR_ENTRY
dc810e39 152#define GET_AOUTHDR_ENTRY H_GET_32
277d1b5e
ILT
153#endif
154#ifndef PUT_AOUTHDR_ENTRY
dc810e39 155#define PUT_AOUTHDR_ENTRY H_PUT_32
277d1b5e
ILT
156#endif
157#ifndef GET_AOUTHDR_TEXT_START
dc810e39 158#define GET_AOUTHDR_TEXT_START H_GET_32
277d1b5e
ILT
159#endif
160#ifndef PUT_AOUTHDR_TEXT_START
dc810e39 161#define PUT_AOUTHDR_TEXT_START H_PUT_32
277d1b5e
ILT
162#endif
163#ifndef GET_AOUTHDR_DATA_START
dc810e39 164#define GET_AOUTHDR_DATA_START H_GET_32
277d1b5e
ILT
165#endif
166#ifndef PUT_AOUTHDR_DATA_START
dc810e39 167#define PUT_AOUTHDR_DATA_START H_PUT_32
277d1b5e
ILT
168#endif
169
170/* Some fields in the scnhdr are sometimes 64 bits. */
171#ifndef GET_SCNHDR_PADDR
dc810e39 172#define GET_SCNHDR_PADDR H_GET_32
277d1b5e
ILT
173#endif
174#ifndef PUT_SCNHDR_PADDR
dc810e39 175#define PUT_SCNHDR_PADDR H_PUT_32
277d1b5e
ILT
176#endif
177#ifndef GET_SCNHDR_VADDR
dc810e39 178#define GET_SCNHDR_VADDR H_GET_32
277d1b5e
ILT
179#endif
180#ifndef PUT_SCNHDR_VADDR
dc810e39 181#define PUT_SCNHDR_VADDR H_PUT_32
277d1b5e
ILT
182#endif
183#ifndef GET_SCNHDR_SIZE
dc810e39 184#define GET_SCNHDR_SIZE H_GET_32
277d1b5e
ILT
185#endif
186#ifndef PUT_SCNHDR_SIZE
dc810e39 187#define PUT_SCNHDR_SIZE H_PUT_32
277d1b5e
ILT
188#endif
189#ifndef GET_SCNHDR_SCNPTR
dc810e39 190#define GET_SCNHDR_SCNPTR H_GET_32
277d1b5e
ILT
191#endif
192#ifndef PUT_SCNHDR_SCNPTR
dc810e39 193#define PUT_SCNHDR_SCNPTR H_PUT_32
277d1b5e
ILT
194#endif
195#ifndef GET_SCNHDR_RELPTR
dc810e39 196#define GET_SCNHDR_RELPTR H_GET_32
277d1b5e
ILT
197#endif
198#ifndef PUT_SCNHDR_RELPTR
dc810e39 199#define PUT_SCNHDR_RELPTR H_PUT_32
277d1b5e
ILT
200#endif
201#ifndef GET_SCNHDR_LNNOPTR
dc810e39 202#define GET_SCNHDR_LNNOPTR H_GET_32
277d1b5e
ILT
203#endif
204#ifndef PUT_SCNHDR_LNNOPTR
dc810e39 205#define PUT_SCNHDR_LNNOPTR H_PUT_32
277d1b5e
ILT
206#endif
207
99ad8390
NC
208#ifdef COFF_WITH_pex64
209
210#define GET_OPTHDR_IMAGE_BASE H_GET_64
211#define PUT_OPTHDR_IMAGE_BASE H_PUT_64
212#define GET_OPTHDR_SIZE_OF_STACK_RESERVE H_GET_64
213#define PUT_OPTHDR_SIZE_OF_STACK_RESERVE H_PUT_64
214#define GET_OPTHDR_SIZE_OF_STACK_COMMIT H_GET_64
215#define PUT_OPTHDR_SIZE_OF_STACK_COMMIT H_PUT_64
216#define GET_OPTHDR_SIZE_OF_HEAP_RESERVE H_GET_64
217#define PUT_OPTHDR_SIZE_OF_HEAP_RESERVE H_PUT_64
218#define GET_OPTHDR_SIZE_OF_HEAP_COMMIT H_GET_64
219#define PUT_OPTHDR_SIZE_OF_HEAP_COMMIT H_PUT_64
220#define GET_PDATA_ENTRY bfd_get_32
221
222#define _bfd_XX_bfd_copy_private_bfd_data_common _bfd_pex64_bfd_copy_private_bfd_data_common
223#define _bfd_XX_bfd_copy_private_section_data _bfd_pex64_bfd_copy_private_section_data
224#define _bfd_XX_get_symbol_info _bfd_pex64_get_symbol_info
225#define _bfd_XX_only_swap_filehdr_out _bfd_pex64_only_swap_filehdr_out
226#define _bfd_XX_print_private_bfd_data_common _bfd_pex64_print_private_bfd_data_common
227#define _bfd_XXi_final_link_postscript _bfd_pex64i_final_link_postscript
99ad8390
NC
228#define _bfd_XXi_only_swap_filehdr_out _bfd_pex64i_only_swap_filehdr_out
229#define _bfd_XXi_swap_aouthdr_in _bfd_pex64i_swap_aouthdr_in
230#define _bfd_XXi_swap_aouthdr_out _bfd_pex64i_swap_aouthdr_out
231#define _bfd_XXi_swap_aux_in _bfd_pex64i_swap_aux_in
232#define _bfd_XXi_swap_aux_out _bfd_pex64i_swap_aux_out
233#define _bfd_XXi_swap_lineno_in _bfd_pex64i_swap_lineno_in
234#define _bfd_XXi_swap_lineno_out _bfd_pex64i_swap_lineno_out
235#define _bfd_XXi_swap_scnhdr_out _bfd_pex64i_swap_scnhdr_out
236#define _bfd_XXi_swap_sym_in _bfd_pex64i_swap_sym_in
237#define _bfd_XXi_swap_sym_out _bfd_pex64i_swap_sym_out
238
239#elif defined COFF_WITH_pep
fac41780 240
dc810e39
AM
241#define GET_OPTHDR_IMAGE_BASE H_GET_64
242#define PUT_OPTHDR_IMAGE_BASE H_PUT_64
243#define GET_OPTHDR_SIZE_OF_STACK_RESERVE H_GET_64
244#define PUT_OPTHDR_SIZE_OF_STACK_RESERVE H_PUT_64
245#define GET_OPTHDR_SIZE_OF_STACK_COMMIT H_GET_64
246#define PUT_OPTHDR_SIZE_OF_STACK_COMMIT H_PUT_64
247#define GET_OPTHDR_SIZE_OF_HEAP_RESERVE H_GET_64
248#define PUT_OPTHDR_SIZE_OF_HEAP_RESERVE H_PUT_64
249#define GET_OPTHDR_SIZE_OF_HEAP_COMMIT H_GET_64
250#define PUT_OPTHDR_SIZE_OF_HEAP_COMMIT H_PUT_64
fac41780
JW
251#define GET_PDATA_ENTRY bfd_get_64
252
cbff5e0d
DD
253#define _bfd_XX_bfd_copy_private_bfd_data_common _bfd_pep_bfd_copy_private_bfd_data_common
254#define _bfd_XX_bfd_copy_private_section_data _bfd_pep_bfd_copy_private_section_data
255#define _bfd_XX_get_symbol_info _bfd_pep_get_symbol_info
256#define _bfd_XX_only_swap_filehdr_out _bfd_pep_only_swap_filehdr_out
257#define _bfd_XX_print_private_bfd_data_common _bfd_pep_print_private_bfd_data_common
258#define _bfd_XXi_final_link_postscript _bfd_pepi_final_link_postscript
cbff5e0d
DD
259#define _bfd_XXi_only_swap_filehdr_out _bfd_pepi_only_swap_filehdr_out
260#define _bfd_XXi_swap_aouthdr_in _bfd_pepi_swap_aouthdr_in
261#define _bfd_XXi_swap_aouthdr_out _bfd_pepi_swap_aouthdr_out
262#define _bfd_XXi_swap_aux_in _bfd_pepi_swap_aux_in
263#define _bfd_XXi_swap_aux_out _bfd_pepi_swap_aux_out
264#define _bfd_XXi_swap_lineno_in _bfd_pepi_swap_lineno_in
265#define _bfd_XXi_swap_lineno_out _bfd_pepi_swap_lineno_out
266#define _bfd_XXi_swap_scnhdr_out _bfd_pepi_swap_scnhdr_out
267#define _bfd_XXi_swap_sym_in _bfd_pepi_swap_sym_in
268#define _bfd_XXi_swap_sym_out _bfd_pepi_swap_sym_out
269
270#else /* !COFF_WITH_pep */
fac41780 271
dc810e39
AM
272#define GET_OPTHDR_IMAGE_BASE H_GET_32
273#define PUT_OPTHDR_IMAGE_BASE H_PUT_32
274#define GET_OPTHDR_SIZE_OF_STACK_RESERVE H_GET_32
275#define PUT_OPTHDR_SIZE_OF_STACK_RESERVE H_PUT_32
276#define GET_OPTHDR_SIZE_OF_STACK_COMMIT H_GET_32
277#define PUT_OPTHDR_SIZE_OF_STACK_COMMIT H_PUT_32
278#define GET_OPTHDR_SIZE_OF_HEAP_RESERVE H_GET_32
279#define PUT_OPTHDR_SIZE_OF_HEAP_RESERVE H_PUT_32
280#define GET_OPTHDR_SIZE_OF_HEAP_COMMIT H_GET_32
281#define PUT_OPTHDR_SIZE_OF_HEAP_COMMIT H_PUT_32
fac41780
JW
282#define GET_PDATA_ENTRY bfd_get_32
283
cbff5e0d
DD
284#define _bfd_XX_bfd_copy_private_bfd_data_common _bfd_pe_bfd_copy_private_bfd_data_common
285#define _bfd_XX_bfd_copy_private_section_data _bfd_pe_bfd_copy_private_section_data
286#define _bfd_XX_get_symbol_info _bfd_pe_get_symbol_info
287#define _bfd_XX_only_swap_filehdr_out _bfd_pe_only_swap_filehdr_out
288#define _bfd_XX_print_private_bfd_data_common _bfd_pe_print_private_bfd_data_common
289#define _bfd_XXi_final_link_postscript _bfd_pei_final_link_postscript
cbff5e0d
DD
290#define _bfd_XXi_only_swap_filehdr_out _bfd_pei_only_swap_filehdr_out
291#define _bfd_XXi_swap_aouthdr_in _bfd_pei_swap_aouthdr_in
292#define _bfd_XXi_swap_aouthdr_out _bfd_pei_swap_aouthdr_out
293#define _bfd_XXi_swap_aux_in _bfd_pei_swap_aux_in
294#define _bfd_XXi_swap_aux_out _bfd_pei_swap_aux_out
295#define _bfd_XXi_swap_lineno_in _bfd_pei_swap_lineno_in
296#define _bfd_XXi_swap_lineno_out _bfd_pei_swap_lineno_out
297#define _bfd_XXi_swap_scnhdr_out _bfd_pei_swap_scnhdr_out
298#define _bfd_XXi_swap_sym_in _bfd_pei_swap_sym_in
299#define _bfd_XXi_swap_sym_out _bfd_pei_swap_sym_out
300
301#endif /* !COFF_WITH_pep */
fac41780 302
277d1b5e
ILT
303/* These functions are architecture dependent, and are in peicode.h:
304 coff_swap_reloc_in
305 int coff_swap_reloc_out
306 coff_swap_filehdr_in
307 coff_swap_scnhdr_in
308 pe_mkobject
309 pe_mkobject_hook */
310
311/* The functions described below are common across all PE/PEI
312 implementations architecture types, and actually appear in
313 peigen.c. */
314
7920ce38
NC
315#define coff_swap_sym_in _bfd_XXi_swap_sym_in
316#define coff_swap_sym_out _bfd_XXi_swap_sym_out
317#define coff_swap_aux_in _bfd_XXi_swap_aux_in
318#define coff_swap_aux_out _bfd_XXi_swap_aux_out
319#define coff_swap_lineno_in _bfd_XXi_swap_lineno_in
320#define coff_swap_lineno_out _bfd_XXi_swap_lineno_out
321#define coff_swap_aouthdr_in _bfd_XXi_swap_aouthdr_in
cbff5e0d 322#define coff_swap_aouthdr_out _bfd_XXi_swap_aouthdr_out
7920ce38 323#define coff_swap_scnhdr_out _bfd_XXi_swap_scnhdr_out
2fbadf2c 324
17505c5c 325#ifndef coff_final_link_postscript
cbff5e0d 326#define coff_final_link_postscript _bfd_XXi_final_link_postscript
17505c5c 327#endif
7920ce38
NC
328
329void _bfd_XXi_swap_sym_in (bfd *, void *, void *);
330unsigned _bfd_XXi_swap_sym_out (bfd *, void *, void *);
331void _bfd_XXi_swap_aux_in (bfd *, void *, int, int, int, int, void *);
332unsigned _bfd_XXi_swap_aux_out (bfd *, void *, int, int, int, int, void *);
333void _bfd_XXi_swap_lineno_in (bfd *, void *, void *);
334unsigned _bfd_XXi_swap_lineno_out (bfd *, void *, void *);
335void _bfd_XXi_swap_aouthdr_in (bfd *, void *, void *);
336unsigned _bfd_XXi_swap_aouthdr_out (bfd *, void *, void *);
337unsigned _bfd_XXi_swap_scnhdr_out (bfd *, void *, void *);
338bfd_boolean _bfd_XX_print_private_bfd_data_common (bfd *, void *);
339bfd_boolean _bfd_XX_bfd_copy_private_bfd_data_common (bfd *, bfd *);
340void _bfd_XX_get_symbol_info (bfd *, asymbol *, symbol_info *);
341bfd_boolean _bfd_XXi_final_link_postscript (bfd *, struct coff_final_link_info *);
342
277d1b5e
ILT
343/* The following are needed only for ONE of pe or pei, but don't
344 otherwise vary; peicode.h fixes up ifdefs but we provide the
345 prototype. */
346
7920ce38
NC
347unsigned _bfd_XX_only_swap_filehdr_out (bfd *, void *, void *);
348unsigned _bfd_XXi_only_swap_filehdr_out (bfd *, void *, void *);
349bfd_boolean _bfd_XX_bfd_copy_private_section_data (bfd *, asection *, bfd *, asection *);
ff0c9faf 350
799c00e0
NC
351bfd_boolean _bfd_pe_print_ce_compressed_pdata (bfd *, void *);
352bfd_boolean _bfd_pe64_print_ce_compressed_pdata (bfd *, void *);
353bfd_boolean _bfd_pex64_print_ce_compressed_pdata (bfd *, void *);
354bfd_boolean _bfd_pep_print_ce_compressed_pdata (bfd *, void *);
355
This page took 0.761122 seconds and 4 git commands to generate.