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