summaryrefslogtreecommitdiffstats
path: root/contrib/binutils/bfd/peicode.h
diff options
context:
space:
mode:
authorobrien <obrien@FreeBSD.org>2004-06-16 05:45:41 +0000
committerobrien <obrien@FreeBSD.org>2004-06-16 05:45:41 +0000
commit2504df11e1275f63f4c53377bf91eee996360cb5 (patch)
tree04848ae93445e503c4190ca1748abe15eabc9e11 /contrib/binutils/bfd/peicode.h
parent6b4c52b743ec5e2e9f65d42b517feefad5017901 (diff)
downloadFreeBSD-src-2504df11e1275f63f4c53377bf91eee996360cb5.zip
FreeBSD-src-2504df11e1275f63f4c53377bf91eee996360cb5.tar.gz
Import of Binutils from the FSF 2.15 branch (just post-.0 release).
These bits are taken from the FSF anoncvs repo on 23-May-2004 04:41:00 UTC.
Diffstat (limited to 'contrib/binutils/bfd/peicode.h')
-rw-r--r--contrib/binutils/bfd/peicode.h156
1 files changed, 94 insertions, 62 deletions
diff --git a/contrib/binutils/bfd/peicode.h b/contrib/binutils/bfd/peicode.h
index a621acc..41445e5 100644
--- a/contrib/binutils/bfd/peicode.h
+++ b/contrib/binutils/bfd/peicode.h
@@ -1,31 +1,29 @@
/* Support for the generic parts of PE/PEI, for BFD.
- Copyright 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002
+ 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,12 +51,11 @@ 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. */
#include "libpei.h"
-static boolean (*pe_saved_coff_bfd_print_private_bfd_data)
+static bfd_boolean (*pe_saved_coff_bfd_print_private_bfd_data)
PARAMS ((bfd *, PTR)) =
#ifndef coff_bfd_print_private_bfd_data
NULL;
@@ -67,10 +64,10 @@ static boolean (*pe_saved_coff_bfd_print_private_bfd_data)
#undef coff_bfd_print_private_bfd_data
#endif
-static boolean pe_print_private_bfd_data PARAMS ((bfd *, PTR));
+static bfd_boolean pe_print_private_bfd_data PARAMS ((bfd *, PTR));
#define coff_bfd_print_private_bfd_data pe_print_private_bfd_data
-static boolean (*pe_saved_coff_bfd_copy_private_bfd_data)
+static bfd_boolean (*pe_saved_coff_bfd_copy_private_bfd_data)
PARAMS ((bfd *, bfd *)) =
#ifndef coff_bfd_copy_private_bfd_data
NULL;
@@ -79,7 +76,7 @@ static boolean (*pe_saved_coff_bfd_copy_private_bfd_data)
#undef coff_bfd_copy_private_bfd_data
#endif
-static boolean pe_bfd_copy_private_bfd_data PARAMS ((bfd *, bfd *));
+static bfd_boolean pe_bfd_copy_private_bfd_data PARAMS ((bfd *, bfd *));
#define coff_bfd_copy_private_bfd_data pe_bfd_copy_private_bfd_data
#define coff_mkobject pe_mkobject
@@ -91,7 +88,7 @@ static unsigned int coff_swap_reloc_out PARAMS ((bfd *, PTR, PTR));
#endif
static void coff_swap_filehdr_in PARAMS ((bfd *, PTR, PTR));
static void coff_swap_scnhdr_in PARAMS ((bfd *, PTR, PTR));
-static boolean pe_mkobject PARAMS ((bfd *));
+static bfd_boolean pe_mkobject PARAMS ((bfd *));
static PTR pe_mkobject_hook PARAMS ((bfd *, PTR, PTR));
#ifdef COFF_IMAGE_WITH_PE
@@ -138,8 +135,8 @@ static asection_ptr pe_ILF_make_a_section PARAMS ((pe_ILF_vars *, const
static void pe_ILF_make_a_reloc PARAMS ((pe_ILF_vars *, bfd_vma, bfd_reloc_code_real_type, asection_ptr));
static void pe_ILF_make_a_symbol PARAMS ((pe_ILF_vars *, const char *, const char *, asection_ptr, flagword));
static void pe_ILF_save_relocs PARAMS ((pe_ILF_vars *, asection_ptr));
-static void pe_ILF_make_a_symbol_reloc PARAMS ((pe_ILF_vars *, bfd_vma, bfd_reloc_code_real_type, struct symbol_cache_entry **, unsigned int));
-static boolean pe_ILF_build_a_bfd PARAMS ((bfd *, unsigned int, bfd_byte *, bfd_byte *, unsigned int, unsigned int));
+static void pe_ILF_make_a_symbol_reloc PARAMS ((pe_ILF_vars *, bfd_vma, bfd_reloc_code_real_type, struct bfd_symbol **, unsigned int));
+static bfd_boolean pe_ILF_build_a_bfd PARAMS ((bfd *, unsigned int, bfd_byte *, bfd_byte *, unsigned int, unsigned int));
static const bfd_target * pe_ILF_object_p PARAMS ((bfd *));
static const bfd_target * pe_bfd_object_p PARAMS ((bfd *));
#endif /* COFF_IMAGE_WITH_PE */
@@ -259,12 +256,17 @@ coff_swap_scnhdr_in (abfd, ext, in)
}
#ifndef COFF_NO_HACK_SCNHDR_SIZE
- /* If this section holds uninitialized data, use the virtual size
- (stored in s_paddr) instead of the physical size. */
- if ((scnhdr_int->s_flags & IMAGE_SCN_CNT_UNINITIALIZED_DATA) != 0
- && (scnhdr_int->s_paddr > 0))
+ /* If this section holds uninitialized data and is from an object file
+ or from an executable image that has not initialized the field,
+ or if the image is an executable file and the physical size is padded,
+ use the virtual size (stored in s_paddr) instead. */
+ if (scnhdr_int->s_paddr > 0
+ && (((scnhdr_int->s_flags & IMAGE_SCN_CNT_UNINITIALIZED_DATA) != 0
+ && (! bfd_pe_executable_p (abfd) || scnhdr_int->s_size == 0))
+ || (bfd_pe_executable_p (abfd) && scnhdr_int->s_size > scnhdr_int->s_paddr)))
{
scnhdr_int->s_size = scnhdr_int->s_paddr;
+
/* This code used to set scnhdr_int->s_paddr to 0. However,
coff_set_alignment_hook stores s_paddr in virt_size, which
only works if it correctly holds the virtual size of the
@@ -273,7 +275,7 @@ coff_swap_scnhdr_in (abfd, ext, in)
#endif
}
-static boolean
+static bfd_boolean
pe_mkobject (abfd)
bfd * abfd;
{
@@ -283,7 +285,7 @@ pe_mkobject (abfd)
abfd->tdata.pe_obj_data = (struct pe_tdata *) bfd_zalloc (abfd, amt);
if (abfd->tdata.pe_obj_data == 0)
- return false;
+ return FALSE;
pe = pe_data (abfd);
@@ -299,7 +301,7 @@ pe_mkobject (abfd)
pe->target_subsystem = PEI_TARGET_SUBSYSTEM;
#endif
- return true;
+ return TRUE;
}
/* Create the COFF backend specific information. */
@@ -355,7 +357,7 @@ pe_mkobject_hook (abfd, filehdr, aouthdr)
return (PTR) pe;
}
-static boolean
+static bfd_boolean
pe_print_private_bfd_data (abfd, vfile)
bfd *abfd;
PTR vfile;
@@ -363,7 +365,7 @@ pe_print_private_bfd_data (abfd, vfile)
FILE *file = (FILE *) vfile;
if (!_bfd_XX_print_private_bfd_data_common (abfd, vfile))
- return false;
+ return FALSE;
if (pe_saved_coff_bfd_print_private_bfd_data != NULL)
{
@@ -372,23 +374,23 @@ pe_print_private_bfd_data (abfd, vfile)
return pe_saved_coff_bfd_print_private_bfd_data (abfd, vfile);
}
- return true;
+ return TRUE;
}
/* Copy any private info we understand from the input bfd
to the output bfd. */
-static boolean
+static bfd_boolean
pe_bfd_copy_private_bfd_data (ibfd, obfd)
bfd *ibfd, *obfd;
{
if (!_bfd_XX_bfd_copy_private_bfd_data_common (ibfd, obfd))
- return false;
+ return FALSE;
if (pe_saved_coff_bfd_copy_private_bfd_data)
return pe_saved_coff_bfd_copy_private_bfd_data (ibfd, obfd);
- return true;
+ return TRUE;
}
#define coff_bfd_copy_private_section_data \
@@ -468,7 +470,7 @@ static void
pe_ILF_make_a_symbol_reloc (pe_ILF_vars * vars,
bfd_vma address,
bfd_reloc_code_real_type reloc,
- struct symbol_cache_entry ** sym,
+ struct bfd_symbol ** sym,
unsigned int sym_index)
{
arelent * entry;
@@ -518,7 +520,7 @@ pe_ILF_save_relocs (pe_ILF_vars * vars,
abort ();
coff_section_data (vars->abfd, sec)->relocs = vars->int_reltab;
- coff_section_data (vars->abfd, sec)->keep_relocs = true;
+ coff_section_data (vars->abfd, sec)->keep_relocs = TRUE;
sec->relocation = vars->reltab;
sec->reloc_count = vars->relcount;
@@ -610,7 +612,7 @@ pe_ILF_make_a_symbol (pe_ILF_vars * vars,
#if 0 /* See comment above. */
sym->symbol.value = 0;
sym->symbol.udata.i = 0;
- sym->done_lineno = false;
+ sym->done_lineno = FALSE;
sym->lineno = NULL;
#endif
@@ -753,7 +755,7 @@ static jump_table jtab[] =
#endif
/* Build a full BFD from the information supplied in a ILF object. */
-static boolean
+static bfd_boolean
pe_ILF_build_a_bfd (bfd * abfd,
unsigned int magic,
bfd_byte * symbol_name,
@@ -784,12 +786,12 @@ pe_ILF_build_a_bfd (bfd * abfd,
/* XXX code yet to be written. */
_bfd_error_handler (_("%s: Unhandled import type; %x"),
bfd_archive_filename (abfd), import_type);
- return false;
+ return FALSE;
default:
_bfd_error_handler (_("%s: Unrecognised import type; %x"),
bfd_archive_filename (abfd), import_type);
- return false;
+ return FALSE;
}
switch (import_name_type)
@@ -803,7 +805,7 @@ pe_ILF_build_a_bfd (bfd * abfd,
default:
_bfd_error_handler (_("%s: Unrecognised import name type; %x"),
bfd_archive_filename (abfd), import_name_type);
- return false;
+ return FALSE;
}
/* Initialise local variables.
@@ -815,7 +817,7 @@ pe_ILF_build_a_bfd (bfd * abfd,
so allocate all the space that we will need right now. */
ptr = bfd_zalloc (abfd, (bfd_size_type) ILF_DATA_SIZE);
if (ptr == NULL)
- return false;
+ return FALSE;
/* Create a bfd_in_memory structure. */
vars.bim = (struct bfd_in_memory *) ptr;
@@ -875,7 +877,7 @@ pe_ILF_build_a_bfd (bfd * abfd,
id4 = pe_ILF_make_a_section (& vars, ".idata$4", SIZEOF_IDATA4, 0);
id5 = pe_ILF_make_a_section (& vars, ".idata$5", SIZEOF_IDATA5, 0);
if (id4 == NULL || id5 == NULL)
- return false;
+ return FALSE;
/* Fill in the contents of these sections. */
if (import_name_type == IMPORT_ORDINAL)
@@ -894,16 +896,46 @@ pe_ILF_build_a_bfd (bfd * abfd,
/* Create .idata$6 - the Hint Name Table. */
id6 = pe_ILF_make_a_section (& vars, ".idata$6", SIZEOF_IDATA6, 0);
if (id6 == NULL)
- return false;
+ return FALSE;
/* If necessary, trim the import symbol name. */
symbol = symbol_name;
if (import_name_type != IMPORT_NAME)
- /* Skip any prefix in symbol_name. */
- while (*symbol == '@' || * symbol == '?' || * symbol == '_')
- ++ symbol;
-
+ {
+ bfd_boolean skipped_leading_underscore = FALSE;
+ bfd_boolean skipped_leading_at = FALSE;
+ bfd_boolean skipped_leading_question_mark = FALSE;
+ bfd_boolean check_again;
+
+ /* Skip any prefix in symbol_name. */
+ -- symbol;
+ do
+ {
+ check_again = FALSE;
+ ++ symbol;
+
+ switch (*symbol)
+ {
+ case '@':
+ if (! skipped_leading_at)
+ check_again = skipped_leading_at = TRUE;
+ break;
+ case '?':
+ if (! skipped_leading_question_mark)
+ check_again = skipped_leading_question_mark = TRUE;
+ break;
+ case '_':
+ if (! skipped_leading_underscore)
+ check_again = skipped_leading_underscore = TRUE;
+ break;
+ default:
+ break;
+ }
+ }
+ while (check_again);
+ }
+
if (import_name_type == IMPORT_NAME_UNDECORATE)
{
/* Truncate at the first '@' */
@@ -950,7 +982,7 @@ pe_ILF_build_a_bfd (bfd * abfd,
/* Create the .text section. */
text = pe_ILF_make_a_section (& vars, ".text", jtab[i].size, SEC_CODE);
if (text == NULL)
- return false;
+ return FALSE;
/* Copy in the jump code. */
memcpy (text->contents, jtab[i].data, jtab[i].size);
@@ -965,11 +997,11 @@ pe_ILF_build_a_bfd (bfd * abfd,
if (magic == MIPS_ARCH_MAGIC_WINCE)
{
pe_ILF_make_a_symbol_reloc (&vars, (bfd_vma) 0, BFD_RELOC_HI16_S,
- (struct symbol_cache_entry **) imp_sym,
+ (struct bfd_symbol **) imp_sym,
imp_index);
pe_ILF_make_a_reloc (&vars, (bfd_vma) 0, BFD_RELOC_LO16, text);
pe_ILF_make_a_symbol_reloc (&vars, (bfd_vma) 4, BFD_RELOC_LO16,
- (struct symbol_cache_entry **) imp_sym,
+ (struct bfd_symbol **) imp_sym,
imp_index);
}
else
@@ -999,10 +1031,10 @@ pe_ILF_build_a_bfd (bfd * abfd,
if ( ! bfd_set_start_address (abfd, (bfd_vma) 0)
|| ! bfd_coff_set_arch_mach_hook (abfd, & internal_f))
- return false;
+ return FALSE;
if (bfd_coff_mkobject_hook (abfd, (PTR) & internal_f, NULL) == NULL)
- return false;
+ return FALSE;
coff_data (abfd)->pe = 1;
#ifdef THUMBPEMAGIC
@@ -1053,17 +1085,17 @@ pe_ILF_build_a_bfd (bfd * abfd,
obj_raw_syment_count (abfd) = vars.sym_index;
obj_coff_external_syms (abfd) = (PTR) vars.esym_table;
- obj_coff_keep_syms (abfd) = true;
+ obj_coff_keep_syms (abfd) = TRUE;
obj_convert (abfd) = vars.sym_table;
obj_conv_table_size (abfd) = vars.sym_index;
obj_coff_strings (abfd) = vars.string_table;
- obj_coff_keep_strings (abfd) = true;
+ obj_coff_keep_strings (abfd) = TRUE;
abfd->flags |= HAS_SYMS;
- return true;
+ return TRUE;
}
/* We have detected a Image Library Format archive element.
OpenPOWER on IntegriCloud