bfd/
[binutils-gdb.git] / bfd / libpei.h
index 5b9cc045cc979d455ce2d393eef2ec34bbd90702..72fa7b5f7287d53cfa5b545cd929156d4ce5a49a 100644 (file)
@@ -1,31 +1,29 @@
 /* Support for the generic parts of PE/PEI; common header information.
-   Copyright 1995, 1996, 1997, 1998, 1999, 2000, 2001
+   Copyright 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003
    Free Software Foundation, Inc.
    Written by Cygnus Solutions.
 
-This file is part of BFD, the Binary File Descriptor library.
+   This file is part of BFD, the Binary File Descriptor library.
 
-This program is free software; you can redistribute it and/or modify
-it under the terms of the GNU General Public License as published by
-the Free Software Foundation; either version 2 of the License, or
-(at your option) any later version.
+   This program is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 2 of the License, or
+   (at your option) any later version.
 
-This program is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-GNU General Public License for more details.
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+   
+   You should have received a copy of the GNU General Public License
+   along with this program; if not, write to the Free Software
+   Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.  */
 
-You should have received a copy of the GNU General Public License
-along with this program; if not, write to the Free Software
-Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.  */
-
-/*
-Most of this hacked by  Steve Chamberlain,
+/* Most of this hacked by  Steve Chamberlain,
                        sac@cygnus.com
 
-PE/PEI rearrangement (and code added): Donn Terry
-                                      Softway Systems, Inc.
-*/
+   PE/PEI rearrangement (and code added): Donn Terry
+                                      Softway Systems, Inc.  */
 
 /* Hey look, some documentation [and in a place you expect to find it]!
 
@@ -53,158 +51,171 @@ PE/PEI rearrangement (and code added): Donn Terry
 
    FIXME: Please add more docs here so the next poor fool that has to hack
    on this code has a chance of getting something accomplished without
-   wasting too much time.
-*/
+   wasting too much time.  */
 
 #ifndef GET_FCN_LNNOPTR
 #define GET_FCN_LNNOPTR(abfd, ext) \
-     bfd_h_get_32(abfd, (bfd_byte *) ext->x_sym.x_fcnary.x_fcn.x_lnnoptr)
+  H_GET_32 (abfd, ext->x_sym.x_fcnary.x_fcn.x_lnnoptr)
 #endif
 
 #ifndef GET_FCN_ENDNDX
-#define GET_FCN_ENDNDX(abfd, ext)  \
-       bfd_h_get_32(abfd, (bfd_byte *) ext->x_sym.x_fcnary.x_fcn.x_endndx)
+#define GET_FCN_ENDNDX(abfd, ext) \
+  H_GET_32 (abfd, ext->x_sym.x_fcnary.x_fcn.x_endndx)
 #endif
 
 #ifndef PUT_FCN_LNNOPTR
-#define PUT_FCN_LNNOPTR(abfd, in, ext)  bfd_h_put_32(abfd,  in, (bfd_byte *) ext->x_sym.x_fcnary.x_fcn.x_lnnoptr)
+#define PUT_FCN_LNNOPTR(abfd, in, ext) \
+  H_PUT_32(abfd, in, ext->x_sym.x_fcnary.x_fcn.x_lnnoptr)
 #endif
 #ifndef PUT_FCN_ENDNDX
-#define PUT_FCN_ENDNDX(abfd, in, ext) bfd_h_put_32(abfd, in, (bfd_byte *) ext->x_sym.x_fcnary.x_fcn.x_endndx)
+#define PUT_FCN_ENDNDX(abfd, in, ext) \
+  H_PUT_32(abfd, in, ext->x_sym.x_fcnary.x_fcn.x_endndx)
 #endif
 #ifndef GET_LNSZ_LNNO
-#define GET_LNSZ_LNNO(abfd, ext) bfd_h_get_16(abfd, (bfd_byte *) ext->x_sym.x_misc.x_lnsz.x_lnno)
+#define GET_LNSZ_LNNO(abfd, ext) \
+  H_GET_16 (abfd, ext->x_sym.x_misc.x_lnsz.x_lnno)
 #endif
 #ifndef GET_LNSZ_SIZE
-#define GET_LNSZ_SIZE(abfd, ext) bfd_h_get_16(abfd, (bfd_byte *) ext->x_sym.x_misc.x_lnsz.x_size)
+#define GET_LNSZ_SIZE(abfd, ext) \
+  H_GET_16 (abfd, ext->x_sym.x_misc.x_lnsz.x_size)
 #endif
 #ifndef PUT_LNSZ_LNNO
-#define PUT_LNSZ_LNNO(abfd, in, ext) bfd_h_put_16(abfd, in, (bfd_byte *)ext->x_sym.x_misc.x_lnsz.x_lnno)
+#define PUT_LNSZ_LNNO(abfd, in, ext) \
+  H_PUT_16(abfd, in, ext->x_sym.x_misc.x_lnsz.x_lnno)
 #endif
 #ifndef PUT_LNSZ_SIZE
-#define PUT_LNSZ_SIZE(abfd, in, ext) bfd_h_put_16(abfd, in, (bfd_byte*) ext->x_sym.x_misc.x_lnsz.x_size)
+#define PUT_LNSZ_SIZE(abfd, in, ext) \
+  H_PUT_16(abfd, in, ext->x_sym.x_misc.x_lnsz.x_size)
 #endif
 #ifndef GET_SCN_SCNLEN
-#define GET_SCN_SCNLEN(abfd,  ext) bfd_h_get_32(abfd, (bfd_byte *) ext->x_scn.x_scnlen)
+#define GET_SCN_SCNLEN(abfd, ext) \
+  H_GET_32 (abfd, ext->x_scn.x_scnlen)
 #endif
 #ifndef GET_SCN_NRELOC
-#define GET_SCN_NRELOC(abfd,  ext) bfd_h_get_16(abfd, (bfd_byte *)ext->x_scn.x_nreloc)
+#define GET_SCN_NRELOC(abfd, ext) \
+  H_GET_16 (abfd, ext->x_scn.x_nreloc)
 #endif
 #ifndef GET_SCN_NLINNO
-#define GET_SCN_NLINNO(abfd, ext)  bfd_h_get_16(abfd, (bfd_byte *)ext->x_scn.x_nlinno)
+#define GET_SCN_NLINNO(abfd, ext) \
+  H_GET_16 (abfd, ext->x_scn.x_nlinno)
 #endif
 #ifndef PUT_SCN_SCNLEN
-#define PUT_SCN_SCNLEN(abfd,in, ext) bfd_h_put_32(abfd, in, (bfd_byte *) ext->x_scn.x_scnlen)
+#define PUT_SCN_SCNLEN(abfd, in, ext) \
+  H_PUT_32(abfd, in, ext->x_scn.x_scnlen)
 #endif
 #ifndef PUT_SCN_NRELOC
-#define PUT_SCN_NRELOC(abfd,in, ext) bfd_h_put_16(abfd, in, (bfd_byte *)ext->x_scn.x_nreloc)
+#define PUT_SCN_NRELOC(abfd, in, ext) \
+  H_PUT_16(abfd, in, ext->x_scn.x_nreloc)
 #endif
 #ifndef PUT_SCN_NLINNO
-#define PUT_SCN_NLINNO(abfd,in, ext)  bfd_h_put_16(abfd,in, (bfd_byte  *) ext->x_scn.x_nlinno)
+#define PUT_SCN_NLINNO(abfd, in, ext) \
+  H_PUT_16(abfd,in, ext->x_scn.x_nlinno)
 #endif
 #ifndef GET_LINENO_LNNO
-#define GET_LINENO_LNNO(abfd, ext) bfd_h_get_16(abfd, (bfd_byte *) (ext->l_lnno));
+#define GET_LINENO_LNNO(abfd, ext) \
+  H_GET_16 (abfd, ext->l_lnno);
 #endif
 #ifndef PUT_LINENO_LNNO
-#define PUT_LINENO_LNNO(abfd,val, ext) bfd_h_put_16(abfd,val,  (bfd_byte *) (ext->l_lnno));
+#define PUT_LINENO_LNNO(abfd, val, ext) \
+  H_PUT_16(abfd,val, ext->l_lnno);
 #endif
 
 /* The f_symptr field in the filehdr is sometimes 64 bits.  */
 #ifndef GET_FILEHDR_SYMPTR
-#define GET_FILEHDR_SYMPTR bfd_h_get_32
+#define GET_FILEHDR_SYMPTR H_GET_32
 #endif
 #ifndef PUT_FILEHDR_SYMPTR
-#define PUT_FILEHDR_SYMPTR bfd_h_put_32
+#define PUT_FILEHDR_SYMPTR H_PUT_32
 #endif
 
 /* Some fields in the aouthdr are sometimes 64 bits.  */
 #ifndef GET_AOUTHDR_TSIZE
-#define GET_AOUTHDR_TSIZE bfd_h_get_32
+#define GET_AOUTHDR_TSIZE H_GET_32
 #endif
 #ifndef PUT_AOUTHDR_TSIZE
-#define PUT_AOUTHDR_TSIZE bfd_h_put_32
+#define PUT_AOUTHDR_TSIZE H_PUT_32
 #endif
 #ifndef GET_AOUTHDR_DSIZE
-#define GET_AOUTHDR_DSIZE bfd_h_get_32
+#define GET_AOUTHDR_DSIZE H_GET_32
 #endif
 #ifndef PUT_AOUTHDR_DSIZE
-#define PUT_AOUTHDR_DSIZE bfd_h_put_32
+#define PUT_AOUTHDR_DSIZE H_PUT_32
 #endif
 #ifndef GET_AOUTHDR_BSIZE
-#define GET_AOUTHDR_BSIZE bfd_h_get_32
+#define GET_AOUTHDR_BSIZE H_GET_32
 #endif
 #ifndef PUT_AOUTHDR_BSIZE
-#define PUT_AOUTHDR_BSIZE bfd_h_put_32
+#define PUT_AOUTHDR_BSIZE H_PUT_32
 #endif
 #ifndef GET_AOUTHDR_ENTRY
-#define GET_AOUTHDR_ENTRY bfd_h_get_32
+#define GET_AOUTHDR_ENTRY H_GET_32
 #endif
 #ifndef PUT_AOUTHDR_ENTRY
-#define PUT_AOUTHDR_ENTRY bfd_h_put_32
+#define PUT_AOUTHDR_ENTRY H_PUT_32
 #endif
 #ifndef GET_AOUTHDR_TEXT_START
-#define GET_AOUTHDR_TEXT_START bfd_h_get_32
+#define GET_AOUTHDR_TEXT_START H_GET_32
 #endif
 #ifndef PUT_AOUTHDR_TEXT_START
-#define PUT_AOUTHDR_TEXT_START bfd_h_put_32
+#define PUT_AOUTHDR_TEXT_START H_PUT_32
 #endif
 #ifndef GET_AOUTHDR_DATA_START
-#define GET_AOUTHDR_DATA_START bfd_h_get_32
+#define GET_AOUTHDR_DATA_START H_GET_32
 #endif
 #ifndef PUT_AOUTHDR_DATA_START
-#define PUT_AOUTHDR_DATA_START bfd_h_put_32
+#define PUT_AOUTHDR_DATA_START H_PUT_32
 #endif
 
 /* Some fields in the scnhdr are sometimes 64 bits.  */
 #ifndef GET_SCNHDR_PADDR
-#define GET_SCNHDR_PADDR bfd_h_get_32
+#define GET_SCNHDR_PADDR H_GET_32
 #endif
 #ifndef PUT_SCNHDR_PADDR
-#define PUT_SCNHDR_PADDR bfd_h_put_32
+#define PUT_SCNHDR_PADDR H_PUT_32
 #endif
 #ifndef GET_SCNHDR_VADDR
-#define GET_SCNHDR_VADDR bfd_h_get_32
+#define GET_SCNHDR_VADDR H_GET_32
 #endif
 #ifndef PUT_SCNHDR_VADDR
-#define PUT_SCNHDR_VADDR bfd_h_put_32
+#define PUT_SCNHDR_VADDR H_PUT_32
 #endif
 #ifndef GET_SCNHDR_SIZE
-#define GET_SCNHDR_SIZE bfd_h_get_32
+#define GET_SCNHDR_SIZE H_GET_32
 #endif
 #ifndef PUT_SCNHDR_SIZE
-#define PUT_SCNHDR_SIZE bfd_h_put_32
+#define PUT_SCNHDR_SIZE H_PUT_32
 #endif
 #ifndef GET_SCNHDR_SCNPTR
-#define GET_SCNHDR_SCNPTR bfd_h_get_32
+#define GET_SCNHDR_SCNPTR H_GET_32
 #endif
 #ifndef PUT_SCNHDR_SCNPTR
-#define PUT_SCNHDR_SCNPTR bfd_h_put_32
+#define PUT_SCNHDR_SCNPTR H_PUT_32
 #endif
 #ifndef GET_SCNHDR_RELPTR
-#define GET_SCNHDR_RELPTR bfd_h_get_32
+#define GET_SCNHDR_RELPTR H_GET_32
 #endif
 #ifndef PUT_SCNHDR_RELPTR
-#define PUT_SCNHDR_RELPTR bfd_h_put_32
+#define PUT_SCNHDR_RELPTR H_PUT_32
 #endif
 #ifndef GET_SCNHDR_LNNOPTR
-#define GET_SCNHDR_LNNOPTR bfd_h_get_32
+#define GET_SCNHDR_LNNOPTR H_GET_32
 #endif
 #ifndef PUT_SCNHDR_LNNOPTR
-#define PUT_SCNHDR_LNNOPTR bfd_h_put_32
+#define PUT_SCNHDR_LNNOPTR H_PUT_32
 #endif
 
 #ifdef COFF_WITH_pep
 
-#define GET_OPTHDR_IMAGE_BASE bfd_h_get_64
-#define PUT_OPTHDR_IMAGE_BASE bfd_h_put_64
-#define GET_OPTHDR_SIZE_OF_STACK_RESERVE bfd_h_get_64
-#define PUT_OPTHDR_SIZE_OF_STACK_RESERVE bfd_h_put_64
-#define GET_OPTHDR_SIZE_OF_STACK_COMMIT bfd_h_get_64
-#define PUT_OPTHDR_SIZE_OF_STACK_COMMIT bfd_h_put_64
-#define GET_OPTHDR_SIZE_OF_HEAP_RESERVE bfd_h_get_64
-#define PUT_OPTHDR_SIZE_OF_HEAP_RESERVE bfd_h_put_64
-#define GET_OPTHDR_SIZE_OF_HEAP_COMMIT bfd_h_get_64
-#define PUT_OPTHDR_SIZE_OF_HEAP_COMMIT bfd_h_put_64
+#define GET_OPTHDR_IMAGE_BASE H_GET_64
+#define PUT_OPTHDR_IMAGE_BASE H_PUT_64
+#define GET_OPTHDR_SIZE_OF_STACK_RESERVE H_GET_64
+#define PUT_OPTHDR_SIZE_OF_STACK_RESERVE H_PUT_64
+#define GET_OPTHDR_SIZE_OF_STACK_COMMIT H_GET_64
+#define PUT_OPTHDR_SIZE_OF_STACK_COMMIT H_PUT_64
+#define GET_OPTHDR_SIZE_OF_HEAP_RESERVE H_GET_64
+#define PUT_OPTHDR_SIZE_OF_HEAP_RESERVE H_PUT_64
+#define GET_OPTHDR_SIZE_OF_HEAP_COMMIT H_GET_64
+#define PUT_OPTHDR_SIZE_OF_HEAP_COMMIT H_PUT_64
 #define GET_PDATA_ENTRY bfd_get_64
 
 #define _bfd_XX_bfd_copy_private_bfd_data_common       _bfd_pep_bfd_copy_private_bfd_data_common
@@ -227,16 +238,16 @@ PE/PEI rearrangement (and code added): Donn Terry
 
 #else /* !COFF_WITH_pep */
 
-#define GET_OPTHDR_IMAGE_BASE bfd_h_get_32
-#define PUT_OPTHDR_IMAGE_BASE bfd_h_put_32
-#define GET_OPTHDR_SIZE_OF_STACK_RESERVE bfd_h_get_32
-#define PUT_OPTHDR_SIZE_OF_STACK_RESERVE bfd_h_put_32
-#define GET_OPTHDR_SIZE_OF_STACK_COMMIT bfd_h_get_32
-#define PUT_OPTHDR_SIZE_OF_STACK_COMMIT bfd_h_put_32
-#define GET_OPTHDR_SIZE_OF_HEAP_RESERVE bfd_h_get_32
-#define PUT_OPTHDR_SIZE_OF_HEAP_RESERVE bfd_h_put_32
-#define GET_OPTHDR_SIZE_OF_HEAP_COMMIT bfd_h_get_32
-#define PUT_OPTHDR_SIZE_OF_HEAP_COMMIT bfd_h_put_32
+#define GET_OPTHDR_IMAGE_BASE H_GET_32
+#define PUT_OPTHDR_IMAGE_BASE H_PUT_32
+#define GET_OPTHDR_SIZE_OF_STACK_RESERVE H_GET_32
+#define PUT_OPTHDR_SIZE_OF_STACK_RESERVE H_PUT_32
+#define GET_OPTHDR_SIZE_OF_STACK_COMMIT H_GET_32
+#define PUT_OPTHDR_SIZE_OF_STACK_COMMIT H_PUT_32
+#define GET_OPTHDR_SIZE_OF_HEAP_RESERVE H_GET_32
+#define PUT_OPTHDR_SIZE_OF_HEAP_RESERVE H_PUT_32
+#define GET_OPTHDR_SIZE_OF_HEAP_COMMIT H_GET_32
+#define PUT_OPTHDR_SIZE_OF_HEAP_COMMIT H_PUT_32
 #define GET_PDATA_ENTRY bfd_get_32
 
 #define _bfd_XX_bfd_copy_private_bfd_data_common       _bfd_pe_bfd_copy_private_bfd_data_common
@@ -299,13 +310,13 @@ unsigned int _bfd_XXi_swap_aouthdr_out PARAMS ((bfd *, PTR, PTR));
 unsigned int _bfd_XXi_swap_scnhdr_out PARAMS ((bfd *, PTR, PTR));
 #define coff_swap_scnhdr_out _bfd_XXi_swap_scnhdr_out
 
-boolean _bfd_XX_print_private_bfd_data_common PARAMS ((bfd *, PTR));
+bfd_boolean _bfd_XX_print_private_bfd_data_common PARAMS ((bfd *, PTR));
 
-boolean _bfd_XX_bfd_copy_private_bfd_data_common PARAMS ((bfd *, bfd *));
+bfd_boolean _bfd_XX_bfd_copy_private_bfd_data_common PARAMS ((bfd *, bfd *));
 
 void _bfd_XX_get_symbol_info PARAMS ((bfd *, asymbol *, symbol_info *));
 
-boolean _bfd_XXi_final_link_postscript
+bfd_boolean _bfd_XXi_final_link_postscript
   PARAMS ((bfd *, struct coff_final_link_info *));
 
 #ifndef coff_final_link_postscript
@@ -317,5 +328,8 @@ boolean _bfd_XXi_final_link_postscript
 
 unsigned int _bfd_XX_only_swap_filehdr_out PARAMS ((bfd*, PTR, PTR));
 unsigned int _bfd_XXi_only_swap_filehdr_out PARAMS ((bfd*, PTR, PTR));
-boolean _bfd_XX_bfd_copy_private_section_data
+bfd_boolean _bfd_XX_bfd_copy_private_section_data
   PARAMS ((bfd *, asection *, bfd *, asection *));
+
+/* Macro: Returns true if the bfd is a PE executable as opposed to a PE object file.  */
+#define bfd_pe_executable_p(abfd)  (strncmp ((abfd)->xvec->name, "pei-", 4) == 0)