OpenCores
URL https://opencores.org/ocsvn/open8_urisc/open8_urisc/trunk

Subversion Repositories open8_urisc

[/] [open8_urisc/] [trunk/] [gnu/] [binutils/] [bfd/] [elfcode.h] - Diff between revs 14 and 148

Go to most recent revision | Only display areas with differences | Details | Blame | View Log

Rev 14 Rev 148
/* ELF executable support for BFD.
/* ELF executable support for BFD.
   Copyright 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000,
   Copyright 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000,
   2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011
   2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011
   Free Software Foundation, Inc.
   Free Software Foundation, Inc.
 
 
   Written by Fred Fish @ Cygnus Support, from information published
   Written by Fred Fish @ Cygnus Support, from information published
   in "UNIX System V Release 4, Programmers Guide: ANSI C and
   in "UNIX System V Release 4, Programmers Guide: ANSI C and
   Programming Support Tools".  Sufficient support for gdb.
   Programming Support Tools".  Sufficient support for gdb.
 
 
   Rewritten by Mark Eichin @ Cygnus Support, from information
   Rewritten by Mark Eichin @ Cygnus Support, from information
   published in "System V Application Binary Interface", chapters 4
   published in "System V Application Binary Interface", chapters 4
   and 5, as well as the various "Processor Supplement" documents
   and 5, as well as the various "Processor Supplement" documents
   derived from it. Added support for assembler and other object file
   derived from it. Added support for assembler and other object file
   utilities.  Further work done by Ken Raeburn (Cygnus Support), Michael
   utilities.  Further work done by Ken Raeburn (Cygnus Support), Michael
   Meissner (Open Software Foundation), and Peter Hoogenboom (University
   Meissner (Open Software Foundation), and Peter Hoogenboom (University
   of Utah) to finish and extend this.
   of Utah) to finish and extend this.
 
 
   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
   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
   it under the terms of the GNU General Public License as published by
   the Free Software Foundation; either version 3 of the License, or
   the Free Software Foundation; either version 3 of the License, or
   (at your option) any later version.
   (at your option) any later version.
 
 
   This program is distributed in the hope that it will be useful,
   This program is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   GNU General Public License for more details.
   GNU General Public License for more details.
 
 
   You should have received a copy of the GNU General Public License
   You should have received a copy of the GNU General Public License
   along with this program; if not, write to the Free Software
   along with this program; if not, write to the Free Software
   Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
   Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
   MA 02110-1301, USA.  */
   MA 02110-1301, USA.  */
 
 
 
 
/* Problems and other issues to resolve.
/* Problems and other issues to resolve.
 
 
   (1)  BFD expects there to be some fixed number of "sections" in
   (1)  BFD expects there to be some fixed number of "sections" in
        the object file.  I.E. there is a "section_count" variable in the
        the object file.  I.E. there is a "section_count" variable in the
        bfd structure which contains the number of sections.  However, ELF
        bfd structure which contains the number of sections.  However, ELF
        supports multiple "views" of a file.  In particular, with current
        supports multiple "views" of a file.  In particular, with current
        implementations, executable files typically have two tables, a
        implementations, executable files typically have two tables, a
        program header table and a section header table, both of which
        program header table and a section header table, both of which
        partition the executable.
        partition the executable.
 
 
        In ELF-speak, the "linking view" of the file uses the section header
        In ELF-speak, the "linking view" of the file uses the section header
        table to access "sections" within the file, and the "execution view"
        table to access "sections" within the file, and the "execution view"
        uses the program header table to access "segments" within the file.
        uses the program header table to access "segments" within the file.
        "Segments" typically may contain all the data from one or more
        "Segments" typically may contain all the data from one or more
        "sections".
        "sections".
 
 
        Note that the section header table is optional in ELF executables,
        Note that the section header table is optional in ELF executables,
        but it is this information that is most useful to gdb.  If the
        but it is this information that is most useful to gdb.  If the
        section header table is missing, then gdb should probably try
        section header table is missing, then gdb should probably try
        to make do with the program header table.  (FIXME)
        to make do with the program header table.  (FIXME)
 
 
   (2)  The code in this file is compiled twice, once in 32-bit mode and
   (2)  The code in this file is compiled twice, once in 32-bit mode and
        once in 64-bit mode.  More of it should be made size-independent
        once in 64-bit mode.  More of it should be made size-independent
        and moved into elf.c.
        and moved into elf.c.
 
 
   (3)  ELF section symbols are handled rather sloppily now.  This should
   (3)  ELF section symbols are handled rather sloppily now.  This should
        be cleaned up, and ELF section symbols reconciled with BFD section
        be cleaned up, and ELF section symbols reconciled with BFD section
        symbols.
        symbols.
 
 
   (4)  We need a published spec for 64-bit ELF.  We've got some stuff here
   (4)  We need a published spec for 64-bit ELF.  We've got some stuff here
        that we're using for SPARC V9 64-bit chips, but don't assume that
        that we're using for SPARC V9 64-bit chips, but don't assume that
        it's cast in stone.
        it's cast in stone.
 */
 */
 
 
#include "sysdep.h"
#include "sysdep.h"
#include "bfd.h"
#include "bfd.h"
#include "libiberty.h"
#include "libiberty.h"
#include "bfdlink.h"
#include "bfdlink.h"
#include "libbfd.h"
#include "libbfd.h"
#include "elf-bfd.h"
#include "elf-bfd.h"
 
 
/* Renaming structures, typedefs, macros and functions to be size-specific.  */
/* Renaming structures, typedefs, macros and functions to be size-specific.  */
#define Elf_External_Ehdr       NAME(Elf,External_Ehdr)
#define Elf_External_Ehdr       NAME(Elf,External_Ehdr)
#define Elf_External_Sym        NAME(Elf,External_Sym)
#define Elf_External_Sym        NAME(Elf,External_Sym)
#define Elf_External_Shdr       NAME(Elf,External_Shdr)
#define Elf_External_Shdr       NAME(Elf,External_Shdr)
#define Elf_External_Phdr       NAME(Elf,External_Phdr)
#define Elf_External_Phdr       NAME(Elf,External_Phdr)
#define Elf_External_Rel        NAME(Elf,External_Rel)
#define Elf_External_Rel        NAME(Elf,External_Rel)
#define Elf_External_Rela       NAME(Elf,External_Rela)
#define Elf_External_Rela       NAME(Elf,External_Rela)
#define Elf_External_Dyn        NAME(Elf,External_Dyn)
#define Elf_External_Dyn        NAME(Elf,External_Dyn)
 
 
#define elf_core_file_failing_command   NAME(bfd_elf,core_file_failing_command)
#define elf_core_file_failing_command   NAME(bfd_elf,core_file_failing_command)
#define elf_core_file_failing_signal    NAME(bfd_elf,core_file_failing_signal)
#define elf_core_file_failing_signal    NAME(bfd_elf,core_file_failing_signal)
#define elf_core_file_matches_executable_p \
#define elf_core_file_matches_executable_p \
  NAME(bfd_elf,core_file_matches_executable_p)
  NAME(bfd_elf,core_file_matches_executable_p)
#define elf_core_file_pid               NAME(bfd_elf,core_file_pid)
#define elf_core_file_pid               NAME(bfd_elf,core_file_pid)
#define elf_object_p                    NAME(bfd_elf,object_p)
#define elf_object_p                    NAME(bfd_elf,object_p)
#define elf_core_file_p                 NAME(bfd_elf,core_file_p)
#define elf_core_file_p                 NAME(bfd_elf,core_file_p)
#define elf_get_symtab_upper_bound      NAME(bfd_elf,get_symtab_upper_bound)
#define elf_get_symtab_upper_bound      NAME(bfd_elf,get_symtab_upper_bound)
#define elf_get_dynamic_symtab_upper_bound \
#define elf_get_dynamic_symtab_upper_bound \
  NAME(bfd_elf,get_dynamic_symtab_upper_bound)
  NAME(bfd_elf,get_dynamic_symtab_upper_bound)
#define elf_swap_reloc_in               NAME(bfd_elf,swap_reloc_in)
#define elf_swap_reloc_in               NAME(bfd_elf,swap_reloc_in)
#define elf_swap_reloca_in              NAME(bfd_elf,swap_reloca_in)
#define elf_swap_reloca_in              NAME(bfd_elf,swap_reloca_in)
#define elf_swap_reloc_out              NAME(bfd_elf,swap_reloc_out)
#define elf_swap_reloc_out              NAME(bfd_elf,swap_reloc_out)
#define elf_swap_reloca_out             NAME(bfd_elf,swap_reloca_out)
#define elf_swap_reloca_out             NAME(bfd_elf,swap_reloca_out)
#define elf_swap_symbol_in              NAME(bfd_elf,swap_symbol_in)
#define elf_swap_symbol_in              NAME(bfd_elf,swap_symbol_in)
#define elf_swap_symbol_out             NAME(bfd_elf,swap_symbol_out)
#define elf_swap_symbol_out             NAME(bfd_elf,swap_symbol_out)
#define elf_swap_phdr_in                NAME(bfd_elf,swap_phdr_in)
#define elf_swap_phdr_in                NAME(bfd_elf,swap_phdr_in)
#define elf_swap_phdr_out               NAME(bfd_elf,swap_phdr_out)
#define elf_swap_phdr_out               NAME(bfd_elf,swap_phdr_out)
#define elf_swap_dyn_in                 NAME(bfd_elf,swap_dyn_in)
#define elf_swap_dyn_in                 NAME(bfd_elf,swap_dyn_in)
#define elf_swap_dyn_out                NAME(bfd_elf,swap_dyn_out)
#define elf_swap_dyn_out                NAME(bfd_elf,swap_dyn_out)
#define elf_get_reloc_upper_bound       NAME(bfd_elf,get_reloc_upper_bound)
#define elf_get_reloc_upper_bound       NAME(bfd_elf,get_reloc_upper_bound)
#define elf_canonicalize_reloc          NAME(bfd_elf,canonicalize_reloc)
#define elf_canonicalize_reloc          NAME(bfd_elf,canonicalize_reloc)
#define elf_slurp_symbol_table          NAME(bfd_elf,slurp_symbol_table)
#define elf_slurp_symbol_table          NAME(bfd_elf,slurp_symbol_table)
#define elf_canonicalize_symtab         NAME(bfd_elf,canonicalize_symtab)
#define elf_canonicalize_symtab         NAME(bfd_elf,canonicalize_symtab)
#define elf_canonicalize_dynamic_symtab \
#define elf_canonicalize_dynamic_symtab \
  NAME(bfd_elf,canonicalize_dynamic_symtab)
  NAME(bfd_elf,canonicalize_dynamic_symtab)
#define elf_get_synthetic_symtab \
#define elf_get_synthetic_symtab \
  NAME(bfd_elf,get_synthetic_symtab)
  NAME(bfd_elf,get_synthetic_symtab)
#define elf_make_empty_symbol           NAME(bfd_elf,make_empty_symbol)
#define elf_make_empty_symbol           NAME(bfd_elf,make_empty_symbol)
#define elf_get_symbol_info             NAME(bfd_elf,get_symbol_info)
#define elf_get_symbol_info             NAME(bfd_elf,get_symbol_info)
#define elf_get_lineno                  NAME(bfd_elf,get_lineno)
#define elf_get_lineno                  NAME(bfd_elf,get_lineno)
#define elf_set_arch_mach               NAME(bfd_elf,set_arch_mach)
#define elf_set_arch_mach               NAME(bfd_elf,set_arch_mach)
#define elf_find_nearest_line           NAME(bfd_elf,find_nearest_line)
#define elf_find_nearest_line           NAME(bfd_elf,find_nearest_line)
#define elf_sizeof_headers              NAME(bfd_elf,sizeof_headers)
#define elf_sizeof_headers              NAME(bfd_elf,sizeof_headers)
#define elf_set_section_contents        NAME(bfd_elf,set_section_contents)
#define elf_set_section_contents        NAME(bfd_elf,set_section_contents)
#define elf_no_info_to_howto            NAME(bfd_elf,no_info_to_howto)
#define elf_no_info_to_howto            NAME(bfd_elf,no_info_to_howto)
#define elf_no_info_to_howto_rel        NAME(bfd_elf,no_info_to_howto_rel)
#define elf_no_info_to_howto_rel        NAME(bfd_elf,no_info_to_howto_rel)
#define elf_find_section                NAME(bfd_elf,find_section)
#define elf_find_section                NAME(bfd_elf,find_section)
#define elf_write_shdrs_and_ehdr        NAME(bfd_elf,write_shdrs_and_ehdr)
#define elf_write_shdrs_and_ehdr        NAME(bfd_elf,write_shdrs_and_ehdr)
#define elf_write_out_phdrs             NAME(bfd_elf,write_out_phdrs)
#define elf_write_out_phdrs             NAME(bfd_elf,write_out_phdrs)
#define elf_checksum_contents           NAME(bfd_elf,checksum_contents)
#define elf_checksum_contents           NAME(bfd_elf,checksum_contents)
#define elf_write_relocs                NAME(bfd_elf,write_relocs)
#define elf_write_relocs                NAME(bfd_elf,write_relocs)
#define elf_slurp_reloc_table           NAME(bfd_elf,slurp_reloc_table)
#define elf_slurp_reloc_table           NAME(bfd_elf,slurp_reloc_table)
 
 
#if ARCH_SIZE == 64
#if ARCH_SIZE == 64
#define ELF_R_INFO(X,Y) ELF64_R_INFO(X,Y)
#define ELF_R_INFO(X,Y) ELF64_R_INFO(X,Y)
#define ELF_R_SYM(X)    ELF64_R_SYM(X)
#define ELF_R_SYM(X)    ELF64_R_SYM(X)
#define ELF_R_TYPE(X)   ELF64_R_TYPE(X)
#define ELF_R_TYPE(X)   ELF64_R_TYPE(X)
#define ELFCLASS        ELFCLASS64
#define ELFCLASS        ELFCLASS64
#define FILE_ALIGN      8
#define FILE_ALIGN      8
#define LOG_FILE_ALIGN  3
#define LOG_FILE_ALIGN  3
#endif
#endif
#if ARCH_SIZE == 32
#if ARCH_SIZE == 32
#define ELF_R_INFO(X,Y) ELF32_R_INFO(X,Y)
#define ELF_R_INFO(X,Y) ELF32_R_INFO(X,Y)
#define ELF_R_SYM(X)    ELF32_R_SYM(X)
#define ELF_R_SYM(X)    ELF32_R_SYM(X)
#define ELF_R_TYPE(X)   ELF32_R_TYPE(X)
#define ELF_R_TYPE(X)   ELF32_R_TYPE(X)
#define ELFCLASS        ELFCLASS32
#define ELFCLASS        ELFCLASS32
#define FILE_ALIGN      4
#define FILE_ALIGN      4
#define LOG_FILE_ALIGN  2
#define LOG_FILE_ALIGN  2
#endif
#endif
 
 
#if DEBUG & 2
#if DEBUG & 2
static void elf_debug_section (int, Elf_Internal_Shdr *);
static void elf_debug_section (int, Elf_Internal_Shdr *);
#endif
#endif
#if DEBUG & 1
#if DEBUG & 1
static void elf_debug_file (Elf_Internal_Ehdr *);
static void elf_debug_file (Elf_Internal_Ehdr *);
#endif
#endif


/* Structure swapping routines */
/* Structure swapping routines */
 
 
/* Should perhaps use put_offset, put_word, etc.  For now, the two versions
/* Should perhaps use put_offset, put_word, etc.  For now, the two versions
   can be handled by explicitly specifying 32 bits or "the long type".  */
   can be handled by explicitly specifying 32 bits or "the long type".  */
#if ARCH_SIZE == 64
#if ARCH_SIZE == 64
#define H_PUT_WORD              H_PUT_64
#define H_PUT_WORD              H_PUT_64
#define H_PUT_SIGNED_WORD       H_PUT_S64
#define H_PUT_SIGNED_WORD       H_PUT_S64
#define H_GET_WORD              H_GET_64
#define H_GET_WORD              H_GET_64
#define H_GET_SIGNED_WORD       H_GET_S64
#define H_GET_SIGNED_WORD       H_GET_S64
#endif
#endif
#if ARCH_SIZE == 32
#if ARCH_SIZE == 32
#define H_PUT_WORD              H_PUT_32
#define H_PUT_WORD              H_PUT_32
#define H_PUT_SIGNED_WORD       H_PUT_S32
#define H_PUT_SIGNED_WORD       H_PUT_S32
#define H_GET_WORD              H_GET_32
#define H_GET_WORD              H_GET_32
#define H_GET_SIGNED_WORD       H_GET_S32
#define H_GET_SIGNED_WORD       H_GET_S32
#endif
#endif
 
 
/* Translate an ELF symbol in external format into an ELF symbol in internal
/* Translate an ELF symbol in external format into an ELF symbol in internal
   format.  */
   format.  */
 
 
bfd_boolean
bfd_boolean
elf_swap_symbol_in (bfd *abfd,
elf_swap_symbol_in (bfd *abfd,
                    const void *psrc,
                    const void *psrc,
                    const void *pshn,
                    const void *pshn,
                    Elf_Internal_Sym *dst)
                    Elf_Internal_Sym *dst)
{
{
  const Elf_External_Sym *src = (const Elf_External_Sym *) psrc;
  const Elf_External_Sym *src = (const Elf_External_Sym *) psrc;
  const Elf_External_Sym_Shndx *shndx = (const Elf_External_Sym_Shndx *) pshn;
  const Elf_External_Sym_Shndx *shndx = (const Elf_External_Sym_Shndx *) pshn;
  int signed_vma = get_elf_backend_data (abfd)->sign_extend_vma;
  int signed_vma = get_elf_backend_data (abfd)->sign_extend_vma;
 
 
  dst->st_name = H_GET_32 (abfd, src->st_name);
  dst->st_name = H_GET_32 (abfd, src->st_name);
  if (signed_vma)
  if (signed_vma)
    dst->st_value = H_GET_SIGNED_WORD (abfd, src->st_value);
    dst->st_value = H_GET_SIGNED_WORD (abfd, src->st_value);
  else
  else
    dst->st_value = H_GET_WORD (abfd, src->st_value);
    dst->st_value = H_GET_WORD (abfd, src->st_value);
  dst->st_size = H_GET_WORD (abfd, src->st_size);
  dst->st_size = H_GET_WORD (abfd, src->st_size);
  dst->st_info = H_GET_8 (abfd, src->st_info);
  dst->st_info = H_GET_8 (abfd, src->st_info);
  dst->st_other = H_GET_8 (abfd, src->st_other);
  dst->st_other = H_GET_8 (abfd, src->st_other);
  dst->st_shndx = H_GET_16 (abfd, src->st_shndx);
  dst->st_shndx = H_GET_16 (abfd, src->st_shndx);
  if (dst->st_shndx == (SHN_XINDEX & 0xffff))
  if (dst->st_shndx == (SHN_XINDEX & 0xffff))
    {
    {
      if (shndx == NULL)
      if (shndx == NULL)
        return FALSE;
        return FALSE;
      dst->st_shndx = H_GET_32 (abfd, shndx->est_shndx);
      dst->st_shndx = H_GET_32 (abfd, shndx->est_shndx);
    }
    }
  else if (dst->st_shndx >= (SHN_LORESERVE & 0xffff))
  else if (dst->st_shndx >= (SHN_LORESERVE & 0xffff))
    dst->st_shndx += SHN_LORESERVE - (SHN_LORESERVE & 0xffff);
    dst->st_shndx += SHN_LORESERVE - (SHN_LORESERVE & 0xffff);
  dst->st_target_internal = 0;
  dst->st_target_internal = 0;
  return TRUE;
  return TRUE;
}
}
 
 
/* Translate an ELF symbol in internal format into an ELF symbol in external
/* Translate an ELF symbol in internal format into an ELF symbol in external
   format.  */
   format.  */
 
 
void
void
elf_swap_symbol_out (bfd *abfd,
elf_swap_symbol_out (bfd *abfd,
                     const Elf_Internal_Sym *src,
                     const Elf_Internal_Sym *src,
                     void *cdst,
                     void *cdst,
                     void *shndx)
                     void *shndx)
{
{
  unsigned int tmp;
  unsigned int tmp;
  Elf_External_Sym *dst = (Elf_External_Sym *) cdst;
  Elf_External_Sym *dst = (Elf_External_Sym *) cdst;
  H_PUT_32 (abfd, src->st_name, dst->st_name);
  H_PUT_32 (abfd, src->st_name, dst->st_name);
  H_PUT_WORD (abfd, src->st_value, dst->st_value);
  H_PUT_WORD (abfd, src->st_value, dst->st_value);
  H_PUT_WORD (abfd, src->st_size, dst->st_size);
  H_PUT_WORD (abfd, src->st_size, dst->st_size);
  H_PUT_8 (abfd, src->st_info, dst->st_info);
  H_PUT_8 (abfd, src->st_info, dst->st_info);
  H_PUT_8 (abfd, src->st_other, dst->st_other);
  H_PUT_8 (abfd, src->st_other, dst->st_other);
  tmp = src->st_shndx;
  tmp = src->st_shndx;
  if (tmp >= (SHN_LORESERVE & 0xffff) && tmp < SHN_LORESERVE)
  if (tmp >= (SHN_LORESERVE & 0xffff) && tmp < SHN_LORESERVE)
    {
    {
      if (shndx == NULL)
      if (shndx == NULL)
        abort ();
        abort ();
      H_PUT_32 (abfd, tmp, shndx);
      H_PUT_32 (abfd, tmp, shndx);
      tmp = SHN_XINDEX & 0xffff;
      tmp = SHN_XINDEX & 0xffff;
    }
    }
  H_PUT_16 (abfd, tmp, dst->st_shndx);
  H_PUT_16 (abfd, tmp, dst->st_shndx);
}
}
 
 
/* Translate an ELF file header in external format into an ELF file header in
/* Translate an ELF file header in external format into an ELF file header in
   internal format.  */
   internal format.  */
 
 
static void
static void
elf_swap_ehdr_in (bfd *abfd,
elf_swap_ehdr_in (bfd *abfd,
                  const Elf_External_Ehdr *src,
                  const Elf_External_Ehdr *src,
                  Elf_Internal_Ehdr *dst)
                  Elf_Internal_Ehdr *dst)
{
{
  int signed_vma = get_elf_backend_data (abfd)->sign_extend_vma;
  int signed_vma = get_elf_backend_data (abfd)->sign_extend_vma;
  memcpy (dst->e_ident, src->e_ident, EI_NIDENT);
  memcpy (dst->e_ident, src->e_ident, EI_NIDENT);
  dst->e_type = H_GET_16 (abfd, src->e_type);
  dst->e_type = H_GET_16 (abfd, src->e_type);
  dst->e_machine = H_GET_16 (abfd, src->e_machine);
  dst->e_machine = H_GET_16 (abfd, src->e_machine);
  dst->e_version = H_GET_32 (abfd, src->e_version);
  dst->e_version = H_GET_32 (abfd, src->e_version);
  if (signed_vma)
  if (signed_vma)
    dst->e_entry = H_GET_SIGNED_WORD (abfd, src->e_entry);
    dst->e_entry = H_GET_SIGNED_WORD (abfd, src->e_entry);
  else
  else
    dst->e_entry = H_GET_WORD (abfd, src->e_entry);
    dst->e_entry = H_GET_WORD (abfd, src->e_entry);
  dst->e_phoff = H_GET_WORD (abfd, src->e_phoff);
  dst->e_phoff = H_GET_WORD (abfd, src->e_phoff);
  dst->e_shoff = H_GET_WORD (abfd, src->e_shoff);
  dst->e_shoff = H_GET_WORD (abfd, src->e_shoff);
  dst->e_flags = H_GET_32 (abfd, src->e_flags);
  dst->e_flags = H_GET_32 (abfd, src->e_flags);
  dst->e_ehsize = H_GET_16 (abfd, src->e_ehsize);
  dst->e_ehsize = H_GET_16 (abfd, src->e_ehsize);
  dst->e_phentsize = H_GET_16 (abfd, src->e_phentsize);
  dst->e_phentsize = H_GET_16 (abfd, src->e_phentsize);
  dst->e_phnum = H_GET_16 (abfd, src->e_phnum);
  dst->e_phnum = H_GET_16 (abfd, src->e_phnum);
  dst->e_shentsize = H_GET_16 (abfd, src->e_shentsize);
  dst->e_shentsize = H_GET_16 (abfd, src->e_shentsize);
  dst->e_shnum = H_GET_16 (abfd, src->e_shnum);
  dst->e_shnum = H_GET_16 (abfd, src->e_shnum);
  dst->e_shstrndx = H_GET_16 (abfd, src->e_shstrndx);
  dst->e_shstrndx = H_GET_16 (abfd, src->e_shstrndx);
}
}
 
 
/* Translate an ELF file header in internal format into an ELF file header in
/* Translate an ELF file header in internal format into an ELF file header in
   external format.  */
   external format.  */
 
 
static void
static void
elf_swap_ehdr_out (bfd *abfd,
elf_swap_ehdr_out (bfd *abfd,
                   const Elf_Internal_Ehdr *src,
                   const Elf_Internal_Ehdr *src,
                   Elf_External_Ehdr *dst)
                   Elf_External_Ehdr *dst)
{
{
  unsigned int tmp;
  unsigned int tmp;
  int signed_vma = get_elf_backend_data (abfd)->sign_extend_vma;
  int signed_vma = get_elf_backend_data (abfd)->sign_extend_vma;
  memcpy (dst->e_ident, src->e_ident, EI_NIDENT);
  memcpy (dst->e_ident, src->e_ident, EI_NIDENT);
  /* note that all elements of dst are *arrays of unsigned char* already...  */
  /* note that all elements of dst are *arrays of unsigned char* already...  */
  H_PUT_16 (abfd, src->e_type, dst->e_type);
  H_PUT_16 (abfd, src->e_type, dst->e_type);
  H_PUT_16 (abfd, src->e_machine, dst->e_machine);
  H_PUT_16 (abfd, src->e_machine, dst->e_machine);
  H_PUT_32 (abfd, src->e_version, dst->e_version);
  H_PUT_32 (abfd, src->e_version, dst->e_version);
  if (signed_vma)
  if (signed_vma)
    H_PUT_SIGNED_WORD (abfd, src->e_entry, dst->e_entry);
    H_PUT_SIGNED_WORD (abfd, src->e_entry, dst->e_entry);
  else
  else
    H_PUT_WORD (abfd, src->e_entry, dst->e_entry);
    H_PUT_WORD (abfd, src->e_entry, dst->e_entry);
  H_PUT_WORD (abfd, src->e_phoff, dst->e_phoff);
  H_PUT_WORD (abfd, src->e_phoff, dst->e_phoff);
  H_PUT_WORD (abfd, src->e_shoff, dst->e_shoff);
  H_PUT_WORD (abfd, src->e_shoff, dst->e_shoff);
  H_PUT_32 (abfd, src->e_flags, dst->e_flags);
  H_PUT_32 (abfd, src->e_flags, dst->e_flags);
  H_PUT_16 (abfd, src->e_ehsize, dst->e_ehsize);
  H_PUT_16 (abfd, src->e_ehsize, dst->e_ehsize);
  H_PUT_16 (abfd, src->e_phentsize, dst->e_phentsize);
  H_PUT_16 (abfd, src->e_phentsize, dst->e_phentsize);
  tmp = src->e_phnum;
  tmp = src->e_phnum;
  if (tmp > PN_XNUM)
  if (tmp > PN_XNUM)
    tmp = PN_XNUM;
    tmp = PN_XNUM;
  H_PUT_16 (abfd, tmp, dst->e_phnum);
  H_PUT_16 (abfd, tmp, dst->e_phnum);
  H_PUT_16 (abfd, src->e_shentsize, dst->e_shentsize);
  H_PUT_16 (abfd, src->e_shentsize, dst->e_shentsize);
  tmp = src->e_shnum;
  tmp = src->e_shnum;
  if (tmp >= (SHN_LORESERVE & 0xffff))
  if (tmp >= (SHN_LORESERVE & 0xffff))
    tmp = SHN_UNDEF;
    tmp = SHN_UNDEF;
  H_PUT_16 (abfd, tmp, dst->e_shnum);
  H_PUT_16 (abfd, tmp, dst->e_shnum);
  tmp = src->e_shstrndx;
  tmp = src->e_shstrndx;
  if (tmp >= (SHN_LORESERVE & 0xffff))
  if (tmp >= (SHN_LORESERVE & 0xffff))
    tmp = SHN_XINDEX & 0xffff;
    tmp = SHN_XINDEX & 0xffff;
  H_PUT_16 (abfd, tmp, dst->e_shstrndx);
  H_PUT_16 (abfd, tmp, dst->e_shstrndx);
}
}
 
 
/* Translate an ELF section header table entry in external format into an
/* Translate an ELF section header table entry in external format into an
   ELF section header table entry in internal format.  */
   ELF section header table entry in internal format.  */
 
 
static void
static void
elf_swap_shdr_in (bfd *abfd,
elf_swap_shdr_in (bfd *abfd,
                  const Elf_External_Shdr *src,
                  const Elf_External_Shdr *src,
                  Elf_Internal_Shdr *dst)
                  Elf_Internal_Shdr *dst)
{
{
  int signed_vma = get_elf_backend_data (abfd)->sign_extend_vma;
  int signed_vma = get_elf_backend_data (abfd)->sign_extend_vma;
 
 
  dst->sh_name = H_GET_32 (abfd, src->sh_name);
  dst->sh_name = H_GET_32 (abfd, src->sh_name);
  dst->sh_type = H_GET_32 (abfd, src->sh_type);
  dst->sh_type = H_GET_32 (abfd, src->sh_type);
  dst->sh_flags = H_GET_WORD (abfd, src->sh_flags);
  dst->sh_flags = H_GET_WORD (abfd, src->sh_flags);
  if (signed_vma)
  if (signed_vma)
    dst->sh_addr = H_GET_SIGNED_WORD (abfd, src->sh_addr);
    dst->sh_addr = H_GET_SIGNED_WORD (abfd, src->sh_addr);
  else
  else
    dst->sh_addr = H_GET_WORD (abfd, src->sh_addr);
    dst->sh_addr = H_GET_WORD (abfd, src->sh_addr);
  dst->sh_offset = H_GET_WORD (abfd, src->sh_offset);
  dst->sh_offset = H_GET_WORD (abfd, src->sh_offset);
  dst->sh_size = H_GET_WORD (abfd, src->sh_size);
  dst->sh_size = H_GET_WORD (abfd, src->sh_size);
  dst->sh_link = H_GET_32 (abfd, src->sh_link);
  dst->sh_link = H_GET_32 (abfd, src->sh_link);
  dst->sh_info = H_GET_32 (abfd, src->sh_info);
  dst->sh_info = H_GET_32 (abfd, src->sh_info);
  dst->sh_addralign = H_GET_WORD (abfd, src->sh_addralign);
  dst->sh_addralign = H_GET_WORD (abfd, src->sh_addralign);
  dst->sh_entsize = H_GET_WORD (abfd, src->sh_entsize);
  dst->sh_entsize = H_GET_WORD (abfd, src->sh_entsize);
  dst->bfd_section = NULL;
  dst->bfd_section = NULL;
  dst->contents = NULL;
  dst->contents = NULL;
}
}
 
 
/* Translate an ELF section header table entry in internal format into an
/* Translate an ELF section header table entry in internal format into an
   ELF section header table entry in external format.  */
   ELF section header table entry in external format.  */
 
 
static void
static void
elf_swap_shdr_out (bfd *abfd,
elf_swap_shdr_out (bfd *abfd,
                   const Elf_Internal_Shdr *src,
                   const Elf_Internal_Shdr *src,
                   Elf_External_Shdr *dst)
                   Elf_External_Shdr *dst)
{
{
  /* note that all elements of dst are *arrays of unsigned char* already...  */
  /* note that all elements of dst are *arrays of unsigned char* already...  */
  H_PUT_32 (abfd, src->sh_name, dst->sh_name);
  H_PUT_32 (abfd, src->sh_name, dst->sh_name);
  H_PUT_32 (abfd, src->sh_type, dst->sh_type);
  H_PUT_32 (abfd, src->sh_type, dst->sh_type);
  H_PUT_WORD (abfd, src->sh_flags, dst->sh_flags);
  H_PUT_WORD (abfd, src->sh_flags, dst->sh_flags);
  H_PUT_WORD (abfd, src->sh_addr, dst->sh_addr);
  H_PUT_WORD (abfd, src->sh_addr, dst->sh_addr);
  H_PUT_WORD (abfd, src->sh_offset, dst->sh_offset);
  H_PUT_WORD (abfd, src->sh_offset, dst->sh_offset);
  H_PUT_WORD (abfd, src->sh_size, dst->sh_size);
  H_PUT_WORD (abfd, src->sh_size, dst->sh_size);
  H_PUT_32 (abfd, src->sh_link, dst->sh_link);
  H_PUT_32 (abfd, src->sh_link, dst->sh_link);
  H_PUT_32 (abfd, src->sh_info, dst->sh_info);
  H_PUT_32 (abfd, src->sh_info, dst->sh_info);
  H_PUT_WORD (abfd, src->sh_addralign, dst->sh_addralign);
  H_PUT_WORD (abfd, src->sh_addralign, dst->sh_addralign);
  H_PUT_WORD (abfd, src->sh_entsize, dst->sh_entsize);
  H_PUT_WORD (abfd, src->sh_entsize, dst->sh_entsize);
}
}
 
 
/* Translate an ELF program header table entry in external format into an
/* Translate an ELF program header table entry in external format into an
   ELF program header table entry in internal format.  */
   ELF program header table entry in internal format.  */
 
 
void
void
elf_swap_phdr_in (bfd *abfd,
elf_swap_phdr_in (bfd *abfd,
                  const Elf_External_Phdr *src,
                  const Elf_External_Phdr *src,
                  Elf_Internal_Phdr *dst)
                  Elf_Internal_Phdr *dst)
{
{
  int signed_vma = get_elf_backend_data (abfd)->sign_extend_vma;
  int signed_vma = get_elf_backend_data (abfd)->sign_extend_vma;
 
 
  dst->p_type = H_GET_32 (abfd, src->p_type);
  dst->p_type = H_GET_32 (abfd, src->p_type);
  dst->p_flags = H_GET_32 (abfd, src->p_flags);
  dst->p_flags = H_GET_32 (abfd, src->p_flags);
  dst->p_offset = H_GET_WORD (abfd, src->p_offset);
  dst->p_offset = H_GET_WORD (abfd, src->p_offset);
  if (signed_vma)
  if (signed_vma)
    {
    {
      dst->p_vaddr = H_GET_SIGNED_WORD (abfd, src->p_vaddr);
      dst->p_vaddr = H_GET_SIGNED_WORD (abfd, src->p_vaddr);
      dst->p_paddr = H_GET_SIGNED_WORD (abfd, src->p_paddr);
      dst->p_paddr = H_GET_SIGNED_WORD (abfd, src->p_paddr);
    }
    }
  else
  else
    {
    {
      dst->p_vaddr = H_GET_WORD (abfd, src->p_vaddr);
      dst->p_vaddr = H_GET_WORD (abfd, src->p_vaddr);
      dst->p_paddr = H_GET_WORD (abfd, src->p_paddr);
      dst->p_paddr = H_GET_WORD (abfd, src->p_paddr);
    }
    }
  dst->p_filesz = H_GET_WORD (abfd, src->p_filesz);
  dst->p_filesz = H_GET_WORD (abfd, src->p_filesz);
  dst->p_memsz = H_GET_WORD (abfd, src->p_memsz);
  dst->p_memsz = H_GET_WORD (abfd, src->p_memsz);
  dst->p_align = H_GET_WORD (abfd, src->p_align);
  dst->p_align = H_GET_WORD (abfd, src->p_align);
}
}
 
 
void
void
elf_swap_phdr_out (bfd *abfd,
elf_swap_phdr_out (bfd *abfd,
                   const Elf_Internal_Phdr *src,
                   const Elf_Internal_Phdr *src,
                   Elf_External_Phdr *dst)
                   Elf_External_Phdr *dst)
{
{
  const struct elf_backend_data *bed;
  const struct elf_backend_data *bed;
  bfd_vma p_paddr;
  bfd_vma p_paddr;
 
 
  bed = get_elf_backend_data (abfd);
  bed = get_elf_backend_data (abfd);
  p_paddr = bed->want_p_paddr_set_to_zero ? 0 : src->p_paddr;
  p_paddr = bed->want_p_paddr_set_to_zero ? 0 : src->p_paddr;
 
 
  /* note that all elements of dst are *arrays of unsigned char* already...  */
  /* note that all elements of dst are *arrays of unsigned char* already...  */
  H_PUT_32 (abfd, src->p_type, dst->p_type);
  H_PUT_32 (abfd, src->p_type, dst->p_type);
  H_PUT_WORD (abfd, src->p_offset, dst->p_offset);
  H_PUT_WORD (abfd, src->p_offset, dst->p_offset);
  H_PUT_WORD (abfd, src->p_vaddr, dst->p_vaddr);
  H_PUT_WORD (abfd, src->p_vaddr, dst->p_vaddr);
  H_PUT_WORD (abfd, p_paddr, dst->p_paddr);
  H_PUT_WORD (abfd, p_paddr, dst->p_paddr);
  H_PUT_WORD (abfd, src->p_filesz, dst->p_filesz);
  H_PUT_WORD (abfd, src->p_filesz, dst->p_filesz);
  H_PUT_WORD (abfd, src->p_memsz, dst->p_memsz);
  H_PUT_WORD (abfd, src->p_memsz, dst->p_memsz);
  H_PUT_32 (abfd, src->p_flags, dst->p_flags);
  H_PUT_32 (abfd, src->p_flags, dst->p_flags);
  H_PUT_WORD (abfd, src->p_align, dst->p_align);
  H_PUT_WORD (abfd, src->p_align, dst->p_align);
}
}
 
 
/* Translate an ELF reloc from external format to internal format.  */
/* Translate an ELF reloc from external format to internal format.  */
void
void
elf_swap_reloc_in (bfd *abfd,
elf_swap_reloc_in (bfd *abfd,
                   const bfd_byte *s,
                   const bfd_byte *s,
                   Elf_Internal_Rela *dst)
                   Elf_Internal_Rela *dst)
{
{
  const Elf_External_Rel *src = (const Elf_External_Rel *) s;
  const Elf_External_Rel *src = (const Elf_External_Rel *) s;
  dst->r_offset = H_GET_WORD (abfd, src->r_offset);
  dst->r_offset = H_GET_WORD (abfd, src->r_offset);
  dst->r_info = H_GET_WORD (abfd, src->r_info);
  dst->r_info = H_GET_WORD (abfd, src->r_info);
  dst->r_addend = 0;
  dst->r_addend = 0;
}
}
 
 
void
void
elf_swap_reloca_in (bfd *abfd,
elf_swap_reloca_in (bfd *abfd,
                    const bfd_byte *s,
                    const bfd_byte *s,
                    Elf_Internal_Rela *dst)
                    Elf_Internal_Rela *dst)
{
{
  const Elf_External_Rela *src = (const Elf_External_Rela *) s;
  const Elf_External_Rela *src = (const Elf_External_Rela *) s;
  dst->r_offset = H_GET_WORD (abfd, src->r_offset);
  dst->r_offset = H_GET_WORD (abfd, src->r_offset);
  dst->r_info = H_GET_WORD (abfd, src->r_info);
  dst->r_info = H_GET_WORD (abfd, src->r_info);
  dst->r_addend = H_GET_SIGNED_WORD (abfd, src->r_addend);
  dst->r_addend = H_GET_SIGNED_WORD (abfd, src->r_addend);
}
}
 
 
/* Translate an ELF reloc from internal format to external format.  */
/* Translate an ELF reloc from internal format to external format.  */
void
void
elf_swap_reloc_out (bfd *abfd,
elf_swap_reloc_out (bfd *abfd,
                    const Elf_Internal_Rela *src,
                    const Elf_Internal_Rela *src,
                    bfd_byte *d)
                    bfd_byte *d)
{
{
  Elf_External_Rel *dst = (Elf_External_Rel *) d;
  Elf_External_Rel *dst = (Elf_External_Rel *) d;
  H_PUT_WORD (abfd, src->r_offset, dst->r_offset);
  H_PUT_WORD (abfd, src->r_offset, dst->r_offset);
  H_PUT_WORD (abfd, src->r_info, dst->r_info);
  H_PUT_WORD (abfd, src->r_info, dst->r_info);
}
}
 
 
void
void
elf_swap_reloca_out (bfd *abfd,
elf_swap_reloca_out (bfd *abfd,
                     const Elf_Internal_Rela *src,
                     const Elf_Internal_Rela *src,
                     bfd_byte *d)
                     bfd_byte *d)
{
{
  Elf_External_Rela *dst = (Elf_External_Rela *) d;
  Elf_External_Rela *dst = (Elf_External_Rela *) d;
  H_PUT_WORD (abfd, src->r_offset, dst->r_offset);
  H_PUT_WORD (abfd, src->r_offset, dst->r_offset);
  H_PUT_WORD (abfd, src->r_info, dst->r_info);
  H_PUT_WORD (abfd, src->r_info, dst->r_info);
  H_PUT_SIGNED_WORD (abfd, src->r_addend, dst->r_addend);
  H_PUT_SIGNED_WORD (abfd, src->r_addend, dst->r_addend);
}
}
 
 
void
void
elf_swap_dyn_in (bfd *abfd,
elf_swap_dyn_in (bfd *abfd,
                 const void *p,
                 const void *p,
                 Elf_Internal_Dyn *dst)
                 Elf_Internal_Dyn *dst)
{
{
  const Elf_External_Dyn *src = (const Elf_External_Dyn *) p;
  const Elf_External_Dyn *src = (const Elf_External_Dyn *) p;
 
 
  dst->d_tag = H_GET_WORD (abfd, src->d_tag);
  dst->d_tag = H_GET_WORD (abfd, src->d_tag);
  dst->d_un.d_val = H_GET_WORD (abfd, src->d_un.d_val);
  dst->d_un.d_val = H_GET_WORD (abfd, src->d_un.d_val);
}
}
 
 
void
void
elf_swap_dyn_out (bfd *abfd,
elf_swap_dyn_out (bfd *abfd,
                  const Elf_Internal_Dyn *src,
                  const Elf_Internal_Dyn *src,
                  void *p)
                  void *p)
{
{
  Elf_External_Dyn *dst = (Elf_External_Dyn *) p;
  Elf_External_Dyn *dst = (Elf_External_Dyn *) p;
 
 
  H_PUT_WORD (abfd, src->d_tag, dst->d_tag);
  H_PUT_WORD (abfd, src->d_tag, dst->d_tag);
  H_PUT_WORD (abfd, src->d_un.d_val, dst->d_un.d_val);
  H_PUT_WORD (abfd, src->d_un.d_val, dst->d_un.d_val);
}
}


/* ELF .o/exec file reading */
/* ELF .o/exec file reading */
 
 
/* Begin processing a given object.
/* Begin processing a given object.
 
 
   First we validate the file by reading in the ELF header and checking
   First we validate the file by reading in the ELF header and checking
   the magic number.  */
   the magic number.  */
 
 
static inline bfd_boolean
static inline bfd_boolean
elf_file_p (Elf_External_Ehdr *x_ehdrp)
elf_file_p (Elf_External_Ehdr *x_ehdrp)
{
{
  return ((x_ehdrp->e_ident[EI_MAG0] == ELFMAG0)
  return ((x_ehdrp->e_ident[EI_MAG0] == ELFMAG0)
          && (x_ehdrp->e_ident[EI_MAG1] == ELFMAG1)
          && (x_ehdrp->e_ident[EI_MAG1] == ELFMAG1)
          && (x_ehdrp->e_ident[EI_MAG2] == ELFMAG2)
          && (x_ehdrp->e_ident[EI_MAG2] == ELFMAG2)
          && (x_ehdrp->e_ident[EI_MAG3] == ELFMAG3));
          && (x_ehdrp->e_ident[EI_MAG3] == ELFMAG3));
}
}
 
 
/* Check to see if the file associated with ABFD matches the target vector
/* Check to see if the file associated with ABFD matches the target vector
   that ABFD points to.
   that ABFD points to.
 
 
   Note that we may be called several times with the same ABFD, but different
   Note that we may be called several times with the same ABFD, but different
   target vectors, most of which will not match.  We have to avoid leaving
   target vectors, most of which will not match.  We have to avoid leaving
   any side effects in ABFD, or any data it points to (like tdata), if the
   any side effects in ABFD, or any data it points to (like tdata), if the
   file does not match the target vector.  */
   file does not match the target vector.  */
 
 
const bfd_target *
const bfd_target *
elf_object_p (bfd *abfd)
elf_object_p (bfd *abfd)
{
{
  Elf_External_Ehdr x_ehdr;     /* Elf file header, external form */
  Elf_External_Ehdr x_ehdr;     /* Elf file header, external form */
  Elf_Internal_Ehdr *i_ehdrp;   /* Elf file header, internal form */
  Elf_Internal_Ehdr *i_ehdrp;   /* Elf file header, internal form */
  Elf_External_Shdr x_shdr;     /* Section header table entry, external form */
  Elf_External_Shdr x_shdr;     /* Section header table entry, external form */
  Elf_Internal_Shdr i_shdr;
  Elf_Internal_Shdr i_shdr;
  Elf_Internal_Shdr *i_shdrp;   /* Section header table, internal form */
  Elf_Internal_Shdr *i_shdrp;   /* Section header table, internal form */
  unsigned int shindex;
  unsigned int shindex;
  const struct elf_backend_data *ebd;
  const struct elf_backend_data *ebd;
  struct bfd_preserve preserve;
  struct bfd_preserve preserve;
  asection *s;
  asection *s;
  bfd_size_type amt;
  bfd_size_type amt;
  const bfd_target *target;
  const bfd_target *target;
  const bfd_target * const *target_ptr;
 
 
 
  preserve.marker = NULL;
  preserve.marker = NULL;
 
 
  /* Read in the ELF header in external format.  */
  /* Read in the ELF header in external format.  */
 
 
  if (bfd_bread (&x_ehdr, sizeof (x_ehdr), abfd) != sizeof (x_ehdr))
  if (bfd_bread (&x_ehdr, sizeof (x_ehdr), abfd) != sizeof (x_ehdr))
    {
    {
      if (bfd_get_error () != bfd_error_system_call)
      if (bfd_get_error () != bfd_error_system_call)
        goto got_wrong_format_error;
        goto got_wrong_format_error;
      else
      else
        goto got_no_match;
        goto got_no_match;
    }
    }
 
 
  /* Now check to see if we have a valid ELF file, and one that BFD can
  /* Now check to see if we have a valid ELF file, and one that BFD can
     make use of.  The magic number must match, the address size ('class')
     make use of.  The magic number must match, the address size ('class')
     and byte-swapping must match our XVEC entry, and it must have a
     and byte-swapping must match our XVEC entry, and it must have a
     section header table (FIXME: See comments re sections at top of this
     section header table (FIXME: See comments re sections at top of this
     file).  */
     file).  */
 
 
  if (! elf_file_p (&x_ehdr)
  if (! elf_file_p (&x_ehdr)
      || x_ehdr.e_ident[EI_VERSION] != EV_CURRENT
      || x_ehdr.e_ident[EI_VERSION] != EV_CURRENT
      || x_ehdr.e_ident[EI_CLASS] != ELFCLASS)
      || x_ehdr.e_ident[EI_CLASS] != ELFCLASS)
    goto got_wrong_format_error;
    goto got_wrong_format_error;
 
 
  /* Check that file's byte order matches xvec's */
  /* Check that file's byte order matches xvec's */
  switch (x_ehdr.e_ident[EI_DATA])
  switch (x_ehdr.e_ident[EI_DATA])
    {
    {
    case ELFDATA2MSB:           /* Big-endian */
    case ELFDATA2MSB:           /* Big-endian */
      if (! bfd_header_big_endian (abfd))
      if (! bfd_header_big_endian (abfd))
        goto got_wrong_format_error;
        goto got_wrong_format_error;
      break;
      break;
    case ELFDATA2LSB:           /* Little-endian */
    case ELFDATA2LSB:           /* Little-endian */
      if (! bfd_header_little_endian (abfd))
      if (! bfd_header_little_endian (abfd))
        goto got_wrong_format_error;
        goto got_wrong_format_error;
      break;
      break;
    case ELFDATANONE:           /* No data encoding specified */
    case ELFDATANONE:           /* No data encoding specified */
    default:                    /* Unknown data encoding specified */
    default:                    /* Unknown data encoding specified */
      goto got_wrong_format_error;
      goto got_wrong_format_error;
    }
    }
 
 
  if (!bfd_preserve_save (abfd, &preserve))
  if (!bfd_preserve_save (abfd, &preserve))
    goto got_no_match;
    goto got_no_match;
 
 
  target = abfd->xvec;
  target = abfd->xvec;
 
 
  /* Allocate an instance of the elf_obj_tdata structure and hook it up to
  /* Allocate an instance of the elf_obj_tdata structure and hook it up to
     the tdata pointer in the bfd.  */
     the tdata pointer in the bfd.  */
 
 
  if (! (*target->_bfd_set_format[bfd_object]) (abfd))
  if (! (*target->_bfd_set_format[bfd_object]) (abfd))
    goto got_no_match;
    goto got_no_match;
  preserve.marker = elf_tdata (abfd);
  preserve.marker = elf_tdata (abfd);
 
 
  /* Now that we know the byte order, swap in the rest of the header */
  /* Now that we know the byte order, swap in the rest of the header */
  i_ehdrp = elf_elfheader (abfd);
  i_ehdrp = elf_elfheader (abfd);
  elf_swap_ehdr_in (abfd, &x_ehdr, i_ehdrp);
  elf_swap_ehdr_in (abfd, &x_ehdr, i_ehdrp);
#if DEBUG & 1
#if DEBUG & 1
  elf_debug_file (i_ehdrp);
  elf_debug_file (i_ehdrp);
#endif
#endif
 
 
  /* Reject ET_CORE (header indicates core file, not object file) */
  /* Reject ET_CORE (header indicates core file, not object file) */
  if (i_ehdrp->e_type == ET_CORE)
  if (i_ehdrp->e_type == ET_CORE)
    goto got_wrong_format_error;
    goto got_wrong_format_error;
 
 
  /* If this is a relocatable file and there is no section header
  /* If this is a relocatable file and there is no section header
     table, then we're hosed.  */
     table, then we're hosed.  */
  if (i_ehdrp->e_shoff == 0 && i_ehdrp->e_type == ET_REL)
  if (i_ehdrp->e_shoff == 0 && i_ehdrp->e_type == ET_REL)
    goto got_wrong_format_error;
    goto got_wrong_format_error;
 
 
  /* As a simple sanity check, verify that what BFD thinks is the
  /* As a simple sanity check, verify that what BFD thinks is the
     size of each section header table entry actually matches the size
     size of each section header table entry actually matches the size
     recorded in the file, but only if there are any sections.  */
     recorded in the file, but only if there are any sections.  */
  if (i_ehdrp->e_shentsize != sizeof (x_shdr) && i_ehdrp->e_shnum != 0)
  if (i_ehdrp->e_shentsize != sizeof (x_shdr) && i_ehdrp->e_shnum != 0)
    goto got_wrong_format_error;
    goto got_wrong_format_error;
 
 
  /* Further sanity check.  */
  /* Further sanity check.  */
  if (i_ehdrp->e_shoff == 0 && i_ehdrp->e_shnum != 0)
  if (i_ehdrp->e_shoff == 0 && i_ehdrp->e_shnum != 0)
    goto got_wrong_format_error;
    goto got_wrong_format_error;
 
 
  ebd = get_elf_backend_data (abfd);
  ebd = get_elf_backend_data (abfd);
  if (ebd->s->arch_size != ARCH_SIZE)
  if (ebd->s->arch_size != ARCH_SIZE)
    goto got_wrong_format_error;
    goto got_wrong_format_error;
 
 
  /* Check that the ELF e_machine field matches what this particular
  /* Check that the ELF e_machine field matches what this particular
     BFD format expects.  */
     BFD format expects.  */
  if (ebd->elf_machine_code != i_ehdrp->e_machine
  if (ebd->elf_machine_code != i_ehdrp->e_machine
      && (ebd->elf_machine_alt1 == 0
      && (ebd->elf_machine_alt1 == 0
          || i_ehdrp->e_machine != ebd->elf_machine_alt1)
          || i_ehdrp->e_machine != ebd->elf_machine_alt1)
      && (ebd->elf_machine_alt2 == 0
      && (ebd->elf_machine_alt2 == 0
          || i_ehdrp->e_machine != ebd->elf_machine_alt2))
          || i_ehdrp->e_machine != ebd->elf_machine_alt2)
    {
      && ebd->elf_machine_code != EM_NONE)
      if (ebd->elf_machine_code != EM_NONE)
 
        goto got_wrong_format_error;
 
 
 
      /* This is the generic ELF target.  Let it match any ELF target
 
         for which we do not have a specific backend.  */
 
      for (target_ptr = bfd_target_vector; *target_ptr != NULL; target_ptr++)
 
        {
 
          const struct elf_backend_data *back;
 
 
 
          if ((*target_ptr)->flavour != bfd_target_elf_flavour)
 
            continue;
 
          back = xvec_get_elf_backend_data (*target_ptr);
 
          if (back->s->arch_size != ARCH_SIZE)
 
            continue;
 
          if (back->elf_machine_code == i_ehdrp->e_machine
 
              || (back->elf_machine_alt1 != 0
 
                  && back->elf_machine_alt1 == i_ehdrp->e_machine)
 
              || (back->elf_machine_alt2 != 0
 
                  && back->elf_machine_alt2 == i_ehdrp->e_machine))
 
            {
 
              /* target_ptr is an ELF backend which matches this
 
                 object file, so reject the generic ELF target.  */
 
              goto got_wrong_format_error;
              goto got_wrong_format_error;
            }
 
        }
 
    }
 
 
 
  if (i_ehdrp->e_type == ET_EXEC)
  if (i_ehdrp->e_type == ET_EXEC)
    abfd->flags |= EXEC_P;
    abfd->flags |= EXEC_P;
  else if (i_ehdrp->e_type == ET_DYN)
  else if (i_ehdrp->e_type == ET_DYN)
    abfd->flags |= DYNAMIC;
    abfd->flags |= DYNAMIC;
 
 
  if (i_ehdrp->e_phnum > 0)
  if (i_ehdrp->e_phnum > 0)
    abfd->flags |= D_PAGED;
    abfd->flags |= D_PAGED;
 
 
  if (! bfd_default_set_arch_mach (abfd, ebd->arch, 0))
  if (! bfd_default_set_arch_mach (abfd, ebd->arch, 0))
    {
    {
      /* It's OK if this fails for the generic target.  */
      /* It's OK if this fails for the generic target.  */
      if (ebd->elf_machine_code != EM_NONE)
      if (ebd->elf_machine_code != EM_NONE)
        goto got_no_match;
        goto got_no_match;
    }
    }
 
 
  if (ebd->elf_machine_code != EM_NONE
  if (ebd->elf_machine_code != EM_NONE
      && i_ehdrp->e_ident[EI_OSABI] != ebd->elf_osabi)
      && i_ehdrp->e_ident[EI_OSABI] != ebd->elf_osabi
    {
      && ebd->elf_osabi != ELFOSABI_NONE)
      if (ebd->elf_osabi != ELFOSABI_NONE)
 
        goto got_wrong_format_error;
        goto got_wrong_format_error;
 
 
      /* This is an ELFOSABI_NONE ELF target.  Let it match any ELF
 
         target of the compatible machine for which we do not have a
 
         backend with matching ELFOSABI.  */
 
      for (target_ptr = bfd_target_vector;
 
           *target_ptr != NULL;
 
           target_ptr++)
 
        {
 
          const struct elf_backend_data *back;
 
 
 
          /* Skip this target and targets with incompatible byte
 
             order.  */
 
          if (*target_ptr == target
 
              || (*target_ptr)->flavour != bfd_target_elf_flavour
 
              || (*target_ptr)->byteorder != target->byteorder
 
              || ((*target_ptr)->header_byteorder
 
                  != target->header_byteorder))
 
            continue;
 
 
 
          back = xvec_get_elf_backend_data (*target_ptr);
 
          if (back->elf_osabi == i_ehdrp->e_ident[EI_OSABI]
 
              && (back->elf_machine_code == i_ehdrp->e_machine
 
                  || (back->elf_machine_alt1 != 0
 
                      && back->elf_machine_alt1 == i_ehdrp->e_machine)
 
                  || (back->elf_machine_alt2 != 0
 
                      && back->elf_machine_alt2 == i_ehdrp->e_machine)))
 
            {
 
              /* target_ptr is an ELF backend which matches this
 
                 object file, so reject the ELFOSABI_NONE ELF target.  */
 
              goto got_wrong_format_error;
 
            }
 
        }
 
    }
 
 
 
  if (i_ehdrp->e_shoff != 0)
  if (i_ehdrp->e_shoff != 0)
    {
    {
      bfd_signed_vma where = i_ehdrp->e_shoff;
      bfd_signed_vma where = i_ehdrp->e_shoff;
 
 
      if (where != (file_ptr) where)
      if (where != (file_ptr) where)
        goto got_wrong_format_error;
        goto got_wrong_format_error;
 
 
      /* Seek to the section header table in the file.  */
      /* Seek to the section header table in the file.  */
      if (bfd_seek (abfd, (file_ptr) where, SEEK_SET) != 0)
      if (bfd_seek (abfd, (file_ptr) where, SEEK_SET) != 0)
        goto got_no_match;
        goto got_no_match;
 
 
      /* Read the first section header at index 0, and convert to internal
      /* Read the first section header at index 0, and convert to internal
         form.  */
         form.  */
      if (bfd_bread (&x_shdr, sizeof x_shdr, abfd) != sizeof (x_shdr))
      if (bfd_bread (&x_shdr, sizeof x_shdr, abfd) != sizeof (x_shdr))
        goto got_no_match;
        goto got_no_match;
      elf_swap_shdr_in (abfd, &x_shdr, &i_shdr);
      elf_swap_shdr_in (abfd, &x_shdr, &i_shdr);
 
 
      /* If the section count is zero, the actual count is in the first
      /* If the section count is zero, the actual count is in the first
         section header.  */
         section header.  */
      if (i_ehdrp->e_shnum == SHN_UNDEF)
      if (i_ehdrp->e_shnum == SHN_UNDEF)
        {
        {
          i_ehdrp->e_shnum = i_shdr.sh_size;
          i_ehdrp->e_shnum = i_shdr.sh_size;
          if (i_ehdrp->e_shnum != i_shdr.sh_size
          if (i_ehdrp->e_shnum != i_shdr.sh_size
              || i_ehdrp->e_shnum == 0)
              || i_ehdrp->e_shnum == 0)
            goto got_wrong_format_error;
            goto got_wrong_format_error;
        }
        }
 
 
      /* And similarly for the string table index.  */
      /* And similarly for the string table index.  */
      if (i_ehdrp->e_shstrndx == (SHN_XINDEX & 0xffff))
      if (i_ehdrp->e_shstrndx == (SHN_XINDEX & 0xffff))
        {
        {
          i_ehdrp->e_shstrndx = i_shdr.sh_link;
          i_ehdrp->e_shstrndx = i_shdr.sh_link;
          if (i_ehdrp->e_shstrndx != i_shdr.sh_link)
          if (i_ehdrp->e_shstrndx != i_shdr.sh_link)
            goto got_wrong_format_error;
            goto got_wrong_format_error;
        }
        }
 
 
      /* And program headers.  */
      /* And program headers.  */
      if (i_ehdrp->e_phnum == PN_XNUM && i_shdr.sh_info != 0)
      if (i_ehdrp->e_phnum == PN_XNUM && i_shdr.sh_info != 0)
        {
        {
          i_ehdrp->e_phnum = i_shdr.sh_info;
          i_ehdrp->e_phnum = i_shdr.sh_info;
          if (i_ehdrp->e_phnum != i_shdr.sh_info)
          if (i_ehdrp->e_phnum != i_shdr.sh_info)
            goto got_wrong_format_error;
            goto got_wrong_format_error;
        }
        }
 
 
      /* Sanity check that we can read all of the section headers.
      /* Sanity check that we can read all of the section headers.
         It ought to be good enough to just read the last one.  */
         It ought to be good enough to just read the last one.  */
      if (i_ehdrp->e_shnum != 1)
      if (i_ehdrp->e_shnum != 1)
        {
        {
          /* Check that we don't have a totally silly number of sections.  */
          /* Check that we don't have a totally silly number of sections.  */
          if (i_ehdrp->e_shnum > (unsigned int) -1 / sizeof (x_shdr)
          if (i_ehdrp->e_shnum > (unsigned int) -1 / sizeof (x_shdr)
              || i_ehdrp->e_shnum > (unsigned int) -1 / sizeof (i_shdr))
              || i_ehdrp->e_shnum > (unsigned int) -1 / sizeof (i_shdr))
            goto got_wrong_format_error;
            goto got_wrong_format_error;
 
 
          where += (i_ehdrp->e_shnum - 1) * sizeof (x_shdr);
          where += (i_ehdrp->e_shnum - 1) * sizeof (x_shdr);
          if (where != (file_ptr) where)
          if (where != (file_ptr) where)
            goto got_wrong_format_error;
            goto got_wrong_format_error;
          if ((bfd_size_type) where <= i_ehdrp->e_shoff)
          if ((bfd_size_type) where <= i_ehdrp->e_shoff)
            goto got_wrong_format_error;
            goto got_wrong_format_error;
 
 
          if (bfd_seek (abfd, (file_ptr) where, SEEK_SET) != 0)
          if (bfd_seek (abfd, (file_ptr) where, SEEK_SET) != 0)
            goto got_no_match;
            goto got_no_match;
          if (bfd_bread (&x_shdr, sizeof x_shdr, abfd) != sizeof (x_shdr))
          if (bfd_bread (&x_shdr, sizeof x_shdr, abfd) != sizeof (x_shdr))
            goto got_no_match;
            goto got_no_match;
 
 
          /* Back to where we were.  */
          /* Back to where we were.  */
          where = i_ehdrp->e_shoff + sizeof (x_shdr);
          where = i_ehdrp->e_shoff + sizeof (x_shdr);
          if (bfd_seek (abfd, (file_ptr) where, SEEK_SET) != 0)
          if (bfd_seek (abfd, (file_ptr) where, SEEK_SET) != 0)
            goto got_no_match;
            goto got_no_match;
        }
        }
    }
    }
 
 
  /* Allocate space for a copy of the section header table in
  /* Allocate space for a copy of the section header table in
     internal form.  */
     internal form.  */
  if (i_ehdrp->e_shnum != 0)
  if (i_ehdrp->e_shnum != 0)
    {
    {
      Elf_Internal_Shdr *shdrp;
      Elf_Internal_Shdr *shdrp;
      unsigned int num_sec;
      unsigned int num_sec;
 
 
      amt = sizeof (*i_shdrp) * i_ehdrp->e_shnum;
      amt = sizeof (*i_shdrp) * i_ehdrp->e_shnum;
      i_shdrp = (Elf_Internal_Shdr *) bfd_alloc (abfd, amt);
      i_shdrp = (Elf_Internal_Shdr *) bfd_alloc (abfd, amt);
      if (!i_shdrp)
      if (!i_shdrp)
        goto got_no_match;
        goto got_no_match;
      num_sec = i_ehdrp->e_shnum;
      num_sec = i_ehdrp->e_shnum;
      elf_numsections (abfd) = num_sec;
      elf_numsections (abfd) = num_sec;
      amt = sizeof (i_shdrp) * num_sec;
      amt = sizeof (i_shdrp) * num_sec;
      elf_elfsections (abfd) = (Elf_Internal_Shdr **) bfd_alloc (abfd, amt);
      elf_elfsections (abfd) = (Elf_Internal_Shdr **) bfd_alloc (abfd, amt);
      if (!elf_elfsections (abfd))
      if (!elf_elfsections (abfd))
        goto got_no_match;
        goto got_no_match;
 
 
      memcpy (i_shdrp, &i_shdr, sizeof (*i_shdrp));
      memcpy (i_shdrp, &i_shdr, sizeof (*i_shdrp));
      for (shdrp = i_shdrp, shindex = 0; shindex < num_sec; shindex++)
      for (shdrp = i_shdrp, shindex = 0; shindex < num_sec; shindex++)
        elf_elfsections (abfd)[shindex] = shdrp++;
        elf_elfsections (abfd)[shindex] = shdrp++;
 
 
      /* Read in the rest of the section header table and convert it
      /* Read in the rest of the section header table and convert it
         to internal form.  */
         to internal form.  */
      for (shindex = 1; shindex < i_ehdrp->e_shnum; shindex++)
      for (shindex = 1; shindex < i_ehdrp->e_shnum; shindex++)
        {
        {
          if (bfd_bread (&x_shdr, sizeof x_shdr, abfd) != sizeof (x_shdr))
          if (bfd_bread (&x_shdr, sizeof x_shdr, abfd) != sizeof (x_shdr))
            goto got_no_match;
            goto got_no_match;
          elf_swap_shdr_in (abfd, &x_shdr, i_shdrp + shindex);
          elf_swap_shdr_in (abfd, &x_shdr, i_shdrp + shindex);
 
 
          /* Sanity check sh_link and sh_info.  */
          /* Sanity check sh_link and sh_info.  */
          if (i_shdrp[shindex].sh_link >= num_sec)
          if (i_shdrp[shindex].sh_link >= num_sec)
            {
            {
              /* PR 10478: Accept Solaris binaries with a sh_link
              /* PR 10478: Accept Solaris binaries with a sh_link
                 field set to SHN_BEFORE or SHN_AFTER.  */
                 field set to SHN_BEFORE or SHN_AFTER.  */
              switch (ebd->elf_machine_code)
              switch (ebd->elf_machine_code)
                {
                {
                case EM_386:
                case EM_386:
                case EM_486:
                case EM_486:
                case EM_X86_64:
                case EM_X86_64:
                case EM_OLD_SPARCV9:
                case EM_OLD_SPARCV9:
                case EM_SPARC32PLUS:
                case EM_SPARC32PLUS:
                case EM_SPARCV9:
                case EM_SPARCV9:
                case EM_SPARC:
                case EM_SPARC:
                  if (i_shdrp[shindex].sh_link == (SHN_LORESERVE & 0xffff) /* SHN_BEFORE */
                  if (i_shdrp[shindex].sh_link == (SHN_LORESERVE & 0xffff) /* SHN_BEFORE */
                      || i_shdrp[shindex].sh_link == ((SHN_LORESERVE + 1) & 0xffff) /* SHN_AFTER */)
                      || i_shdrp[shindex].sh_link == ((SHN_LORESERVE + 1) & 0xffff) /* SHN_AFTER */)
                    break;
                    break;
                  /* Otherwise fall through.  */
                  /* Otherwise fall through.  */
                default:
                default:
                  goto got_wrong_format_error;
                  goto got_wrong_format_error;
                }
                }
            }
            }
 
 
          if (((i_shdrp[shindex].sh_flags & SHF_INFO_LINK)
          if (((i_shdrp[shindex].sh_flags & SHF_INFO_LINK)
               || i_shdrp[shindex].sh_type == SHT_RELA
               || i_shdrp[shindex].sh_type == SHT_RELA
               || i_shdrp[shindex].sh_type == SHT_REL)
               || i_shdrp[shindex].sh_type == SHT_REL)
              && i_shdrp[shindex].sh_info >= num_sec)
              && i_shdrp[shindex].sh_info >= num_sec)
            goto got_wrong_format_error;
            goto got_wrong_format_error;
 
 
          /* If the section is loaded, but not page aligned, clear
          /* If the section is loaded, but not page aligned, clear
             D_PAGED.  */
             D_PAGED.  */
          if (i_shdrp[shindex].sh_size != 0
          if (i_shdrp[shindex].sh_size != 0
              && (i_shdrp[shindex].sh_flags & SHF_ALLOC) != 0
              && (i_shdrp[shindex].sh_flags & SHF_ALLOC) != 0
              && i_shdrp[shindex].sh_type != SHT_NOBITS
              && i_shdrp[shindex].sh_type != SHT_NOBITS
              && (((i_shdrp[shindex].sh_addr - i_shdrp[shindex].sh_offset)
              && (((i_shdrp[shindex].sh_addr - i_shdrp[shindex].sh_offset)
                   % ebd->minpagesize)
                   % ebd->minpagesize)
                  != 0))
                  != 0))
            abfd->flags &= ~D_PAGED;
            abfd->flags &= ~D_PAGED;
        }
        }
    }
    }
 
 
  /* A further sanity check.  */
  /* A further sanity check.  */
  if (i_ehdrp->e_shnum != 0)
  if (i_ehdrp->e_shnum != 0)
    {
    {
      if (i_ehdrp->e_shstrndx >= elf_numsections (abfd))
      if (i_ehdrp->e_shstrndx >= elf_numsections (abfd))
        {
        {
          /* PR 2257:
          /* PR 2257:
             We used to just goto got_wrong_format_error here
             We used to just goto got_wrong_format_error here
             but there are binaries in existance for which this test
             but there are binaries in existance for which this test
             will prevent the binutils from working with them at all.
             will prevent the binutils from working with them at all.
             So we are kind, and reset the string index value to 0
             So we are kind, and reset the string index value to 0
             so that at least some processing can be done.  */
             so that at least some processing can be done.  */
          i_ehdrp->e_shstrndx = SHN_UNDEF;
          i_ehdrp->e_shstrndx = SHN_UNDEF;
          _bfd_error_handler (_("warning: %s has a corrupt string table index - ignoring"), abfd->filename);
          _bfd_error_handler (_("warning: %s has a corrupt string table index - ignoring"), abfd->filename);
        }
        }
    }
    }
  else if (i_ehdrp->e_shstrndx != SHN_UNDEF)
  else if (i_ehdrp->e_shstrndx != SHN_UNDEF)
    goto got_wrong_format_error;
    goto got_wrong_format_error;
 
 
  /* Read in the program headers.  */
  /* Read in the program headers.  */
  if (i_ehdrp->e_phnum == 0)
  if (i_ehdrp->e_phnum == 0)
    elf_tdata (abfd)->phdr = NULL;
    elf_tdata (abfd)->phdr = NULL;
  else
  else
    {
    {
      Elf_Internal_Phdr *i_phdr;
      Elf_Internal_Phdr *i_phdr;
      unsigned int i;
      unsigned int i;
 
 
      amt = i_ehdrp->e_phnum * sizeof (Elf_Internal_Phdr);
      amt = i_ehdrp->e_phnum * sizeof (Elf_Internal_Phdr);
      elf_tdata (abfd)->phdr = (Elf_Internal_Phdr *) bfd_alloc (abfd, amt);
      elf_tdata (abfd)->phdr = (Elf_Internal_Phdr *) bfd_alloc (abfd, amt);
      if (elf_tdata (abfd)->phdr == NULL)
      if (elf_tdata (abfd)->phdr == NULL)
        goto got_no_match;
        goto got_no_match;
      if (bfd_seek (abfd, (file_ptr) i_ehdrp->e_phoff, SEEK_SET) != 0)
      if (bfd_seek (abfd, (file_ptr) i_ehdrp->e_phoff, SEEK_SET) != 0)
        goto got_no_match;
        goto got_no_match;
      i_phdr = elf_tdata (abfd)->phdr;
      i_phdr = elf_tdata (abfd)->phdr;
      for (i = 0; i < i_ehdrp->e_phnum; i++, i_phdr++)
      for (i = 0; i < i_ehdrp->e_phnum; i++, i_phdr++)
        {
        {
          Elf_External_Phdr x_phdr;
          Elf_External_Phdr x_phdr;
 
 
          if (bfd_bread (&x_phdr, sizeof x_phdr, abfd) != sizeof x_phdr)
          if (bfd_bread (&x_phdr, sizeof x_phdr, abfd) != sizeof x_phdr)
            goto got_no_match;
            goto got_no_match;
          elf_swap_phdr_in (abfd, &x_phdr, i_phdr);
          elf_swap_phdr_in (abfd, &x_phdr, i_phdr);
        }
        }
    }
    }
 
 
  if (i_ehdrp->e_shstrndx != 0 && i_ehdrp->e_shoff != 0)
  if (i_ehdrp->e_shstrndx != 0 && i_ehdrp->e_shoff != 0)
    {
    {
      unsigned int num_sec;
      unsigned int num_sec;
 
 
      /* Once all of the section headers have been read and converted, we
      /* Once all of the section headers have been read and converted, we
         can start processing them.  Note that the first section header is
         can start processing them.  Note that the first section header is
         a dummy placeholder entry, so we ignore it.  */
         a dummy placeholder entry, so we ignore it.  */
      num_sec = elf_numsections (abfd);
      num_sec = elf_numsections (abfd);
      for (shindex = 1; shindex < num_sec; shindex++)
      for (shindex = 1; shindex < num_sec; shindex++)
        if (!bfd_section_from_shdr (abfd, shindex))
        if (!bfd_section_from_shdr (abfd, shindex))
          goto got_no_match;
          goto got_no_match;
 
 
      /* Set up ELF sections for SHF_GROUP and SHF_LINK_ORDER.  */
      /* Set up ELF sections for SHF_GROUP and SHF_LINK_ORDER.  */
      if (! _bfd_elf_setup_sections (abfd))
      if (! _bfd_elf_setup_sections (abfd))
        goto got_wrong_format_error;
        goto got_wrong_format_error;
    }
    }
 
 
  /* Let the backend double check the format and override global
  /* Let the backend double check the format and override global
     information.  */
     information.  */
  if (ebd->elf_backend_object_p)
  if (ebd->elf_backend_object_p)
    {
    {
      if (! (*ebd->elf_backend_object_p) (abfd))
      if (! (*ebd->elf_backend_object_p) (abfd))
        goto got_wrong_format_error;
        goto got_wrong_format_error;
    }
    }
 
 
  /* Remember the entry point specified in the ELF file header.  */
  /* Remember the entry point specified in the ELF file header.  */
  bfd_set_start_address (abfd, i_ehdrp->e_entry);
  bfd_set_start_address (abfd, i_ehdrp->e_entry);
 
 
  /* If we have created any reloc sections that are associated with
  /* If we have created any reloc sections that are associated with
     debugging sections, mark the reloc sections as debugging as well.  */
     debugging sections, mark the reloc sections as debugging as well.  */
  for (s = abfd->sections; s != NULL; s = s->next)
  for (s = abfd->sections; s != NULL; s = s->next)
    {
    {
      if ((elf_section_data (s)->this_hdr.sh_type == SHT_REL
      if ((elf_section_data (s)->this_hdr.sh_type == SHT_REL
           || elf_section_data (s)->this_hdr.sh_type == SHT_RELA)
           || elf_section_data (s)->this_hdr.sh_type == SHT_RELA)
          && elf_section_data (s)->this_hdr.sh_info > 0)
          && elf_section_data (s)->this_hdr.sh_info > 0)
        {
        {
          unsigned long targ_index;
          unsigned long targ_index;
          asection *targ_sec;
          asection *targ_sec;
 
 
          targ_index = elf_section_data (s)->this_hdr.sh_info;
          targ_index = elf_section_data (s)->this_hdr.sh_info;
          targ_sec = bfd_section_from_elf_index (abfd, targ_index);
          targ_sec = bfd_section_from_elf_index (abfd, targ_index);
          if (targ_sec != NULL
          if (targ_sec != NULL
              && (targ_sec->flags & SEC_DEBUGGING) != 0)
              && (targ_sec->flags & SEC_DEBUGGING) != 0)
            s->flags |= SEC_DEBUGGING;
            s->flags |= SEC_DEBUGGING;
        }
        }
    }
    }
 
 
  bfd_preserve_finish (abfd, &preserve);
  bfd_preserve_finish (abfd, &preserve);
  return target;
  return target;
 
 
 got_wrong_format_error:
 got_wrong_format_error:
  /* There is way too much undoing of half-known state here.  The caller,
  /* There is way too much undoing of half-known state here.  The caller,
     bfd_check_format_matches, really shouldn't iterate on live bfd's to
     bfd_check_format_matches, really shouldn't iterate on live bfd's to
     check match/no-match like it does.  We have to rely on that a call to
     check match/no-match like it does.  We have to rely on that a call to
     bfd_default_set_arch_mach with the previously known mach, undoes what
     bfd_default_set_arch_mach with the previously known mach, undoes what
     was done by the first bfd_default_set_arch_mach (with mach 0) here.
     was done by the first bfd_default_set_arch_mach (with mach 0) here.
     For this to work, only elf-data and the mach may be changed by the
     For this to work, only elf-data and the mach may be changed by the
     target-specific elf_backend_object_p function.  Note that saving the
     target-specific elf_backend_object_p function.  Note that saving the
     whole bfd here and restoring it would be even worse; the first thing
     whole bfd here and restoring it would be even worse; the first thing
     you notice is that the cached bfd file position gets out of sync.  */
     you notice is that the cached bfd file position gets out of sync.  */
  bfd_set_error (bfd_error_wrong_format);
  bfd_set_error (bfd_error_wrong_format);
 
 
 got_no_match:
 got_no_match:
  if (preserve.marker != NULL)
  if (preserve.marker != NULL)
    bfd_preserve_restore (abfd, &preserve);
    bfd_preserve_restore (abfd, &preserve);
  return NULL;
  return NULL;
}
}


/* ELF .o/exec file writing */
/* ELF .o/exec file writing */
 
 
/* Write out the relocs.  */
/* Write out the relocs.  */
 
 
void
void
elf_write_relocs (bfd *abfd, asection *sec, void *data)
elf_write_relocs (bfd *abfd, asection *sec, void *data)
{
{
  bfd_boolean *failedp = (bfd_boolean *) data;
  bfd_boolean *failedp = (bfd_boolean *) data;
  Elf_Internal_Shdr *rela_hdr;
  Elf_Internal_Shdr *rela_hdr;
  bfd_vma addr_offset;
  bfd_vma addr_offset;
  void (*swap_out) (bfd *, const Elf_Internal_Rela *, bfd_byte *);
  void (*swap_out) (bfd *, const Elf_Internal_Rela *, bfd_byte *);
  size_t extsize;
  size_t extsize;
  bfd_byte *dst_rela;
  bfd_byte *dst_rela;
  unsigned int idx;
  unsigned int idx;
  asymbol *last_sym;
  asymbol *last_sym;
  int last_sym_idx;
  int last_sym_idx;
 
 
  /* If we have already failed, don't do anything.  */
  /* If we have already failed, don't do anything.  */
  if (*failedp)
  if (*failedp)
    return;
    return;
 
 
  if ((sec->flags & SEC_RELOC) == 0)
  if ((sec->flags & SEC_RELOC) == 0)
    return;
    return;
 
 
  /* The linker backend writes the relocs out itself, and sets the
  /* The linker backend writes the relocs out itself, and sets the
     reloc_count field to zero to inhibit writing them here.  Also,
     reloc_count field to zero to inhibit writing them here.  Also,
     sometimes the SEC_RELOC flag gets set even when there aren't any
     sometimes the SEC_RELOC flag gets set even when there aren't any
     relocs.  */
     relocs.  */
  if (sec->reloc_count == 0)
  if (sec->reloc_count == 0)
    return;
    return;
 
 
  /* If we have opened an existing file for update, reloc_count may be
  /* If we have opened an existing file for update, reloc_count may be
     set even though we are not linking.  In that case we have nothing
     set even though we are not linking.  In that case we have nothing
     to do.  */
     to do.  */
  if (sec->orelocation == NULL)
  if (sec->orelocation == NULL)
    return;
    return;
 
 
  rela_hdr = elf_section_data (sec)->rela.hdr;
  rela_hdr = elf_section_data (sec)->rela.hdr;
  if (rela_hdr == NULL)
  if (rela_hdr == NULL)
    rela_hdr = elf_section_data (sec)->rel.hdr;
    rela_hdr = elf_section_data (sec)->rel.hdr;
 
 
  rela_hdr->sh_size = rela_hdr->sh_entsize * sec->reloc_count;
  rela_hdr->sh_size = rela_hdr->sh_entsize * sec->reloc_count;
  rela_hdr->contents = (unsigned char *) bfd_alloc (abfd, rela_hdr->sh_size);
  rela_hdr->contents = (unsigned char *) bfd_alloc (abfd, rela_hdr->sh_size);
  if (rela_hdr->contents == NULL)
  if (rela_hdr->contents == NULL)
    {
    {
      *failedp = TRUE;
      *failedp = TRUE;
      return;
      return;
    }
    }
 
 
  /* Figure out whether the relocations are RELA or REL relocations.  */
  /* Figure out whether the relocations are RELA or REL relocations.  */
  if (rela_hdr->sh_type == SHT_RELA)
  if (rela_hdr->sh_type == SHT_RELA)
    {
    {
      swap_out = elf_swap_reloca_out;
      swap_out = elf_swap_reloca_out;
      extsize = sizeof (Elf_External_Rela);
      extsize = sizeof (Elf_External_Rela);
    }
    }
  else if (rela_hdr->sh_type == SHT_REL)
  else if (rela_hdr->sh_type == SHT_REL)
    {
    {
      swap_out = elf_swap_reloc_out;
      swap_out = elf_swap_reloc_out;
      extsize = sizeof (Elf_External_Rel);
      extsize = sizeof (Elf_External_Rel);
    }
    }
  else
  else
    /* Every relocation section should be either an SHT_RELA or an
    /* Every relocation section should be either an SHT_RELA or an
       SHT_REL section.  */
       SHT_REL section.  */
    abort ();
    abort ();
 
 
  /* The address of an ELF reloc is section relative for an object
  /* The address of an ELF reloc is section relative for an object
     file, and absolute for an executable file or shared library.
     file, and absolute for an executable file or shared library.
     The address of a BFD reloc is always section relative.  */
     The address of a BFD reloc is always section relative.  */
  addr_offset = 0;
  addr_offset = 0;
  if ((abfd->flags & (EXEC_P | DYNAMIC)) != 0)
  if ((abfd->flags & (EXEC_P | DYNAMIC)) != 0)
    addr_offset = sec->vma;
    addr_offset = sec->vma;
 
 
  /* orelocation has the data, reloc_count has the count...  */
  /* orelocation has the data, reloc_count has the count...  */
  last_sym = 0;
  last_sym = 0;
  last_sym_idx = 0;
  last_sym_idx = 0;
  dst_rela = rela_hdr->contents;
  dst_rela = rela_hdr->contents;
 
 
  for (idx = 0; idx < sec->reloc_count; idx++, dst_rela += extsize)
  for (idx = 0; idx < sec->reloc_count; idx++, dst_rela += extsize)
    {
    {
      Elf_Internal_Rela src_rela;
      Elf_Internal_Rela src_rela;
      arelent *ptr;
      arelent *ptr;
      asymbol *sym;
      asymbol *sym;
      int n;
      int n;
 
 
      ptr = sec->orelocation[idx];
      ptr = sec->orelocation[idx];
      sym = *ptr->sym_ptr_ptr;
      sym = *ptr->sym_ptr_ptr;
      if (sym == last_sym)
      if (sym == last_sym)
        n = last_sym_idx;
        n = last_sym_idx;
      else if (bfd_is_abs_section (sym->section) && sym->value == 0)
      else if (bfd_is_abs_section (sym->section) && sym->value == 0)
        n = STN_UNDEF;
        n = STN_UNDEF;
      else
      else
        {
        {
          last_sym = sym;
          last_sym = sym;
          n = _bfd_elf_symbol_from_bfd_symbol (abfd, &sym);
          n = _bfd_elf_symbol_from_bfd_symbol (abfd, &sym);
          if (n < 0)
          if (n < 0)
            {
            {
              *failedp = TRUE;
              *failedp = TRUE;
              return;
              return;
            }
            }
          last_sym_idx = n;
          last_sym_idx = n;
        }
        }
 
 
      if ((*ptr->sym_ptr_ptr)->the_bfd != NULL
      if ((*ptr->sym_ptr_ptr)->the_bfd != NULL
          && (*ptr->sym_ptr_ptr)->the_bfd->xvec != abfd->xvec
          && (*ptr->sym_ptr_ptr)->the_bfd->xvec != abfd->xvec
          && ! _bfd_elf_validate_reloc (abfd, ptr))
          && ! _bfd_elf_validate_reloc (abfd, ptr))
        {
        {
          *failedp = TRUE;
          *failedp = TRUE;
          return;
          return;
        }
        }
 
 
      src_rela.r_offset = ptr->address + addr_offset;
      src_rela.r_offset = ptr->address + addr_offset;
      src_rela.r_info = ELF_R_INFO (n, ptr->howto->type);
      src_rela.r_info = ELF_R_INFO (n, ptr->howto->type);
      src_rela.r_addend = ptr->addend;
      src_rela.r_addend = ptr->addend;
      (*swap_out) (abfd, &src_rela, dst_rela);
      (*swap_out) (abfd, &src_rela, dst_rela);
    }
    }
}
}
 
 
/* Write out the program headers.  */
/* Write out the program headers.  */
 
 
int
int
elf_write_out_phdrs (bfd *abfd,
elf_write_out_phdrs (bfd *abfd,
                     const Elf_Internal_Phdr *phdr,
                     const Elf_Internal_Phdr *phdr,
                     unsigned int count)
                     unsigned int count)
{
{
  while (count--)
  while (count--)
    {
    {
      Elf_External_Phdr extphdr;
      Elf_External_Phdr extphdr;
      elf_swap_phdr_out (abfd, phdr, &extphdr);
      elf_swap_phdr_out (abfd, phdr, &extphdr);
      if (bfd_bwrite (&extphdr, sizeof (Elf_External_Phdr), abfd)
      if (bfd_bwrite (&extphdr, sizeof (Elf_External_Phdr), abfd)
          != sizeof (Elf_External_Phdr))
          != sizeof (Elf_External_Phdr))
        return -1;
        return -1;
      phdr++;
      phdr++;
    }
    }
  return 0;
  return 0;
}
}
 
 
/* Write out the section headers and the ELF file header.  */
/* Write out the section headers and the ELF file header.  */
 
 
bfd_boolean
bfd_boolean
elf_write_shdrs_and_ehdr (bfd *abfd)
elf_write_shdrs_and_ehdr (bfd *abfd)
{
{
  Elf_External_Ehdr x_ehdr;     /* Elf file header, external form */
  Elf_External_Ehdr x_ehdr;     /* Elf file header, external form */
  Elf_Internal_Ehdr *i_ehdrp;   /* Elf file header, internal form */
  Elf_Internal_Ehdr *i_ehdrp;   /* Elf file header, internal form */
  Elf_External_Shdr *x_shdrp;   /* Section header table, external form */
  Elf_External_Shdr *x_shdrp;   /* Section header table, external form */
  Elf_Internal_Shdr **i_shdrp;  /* Section header table, internal form */
  Elf_Internal_Shdr **i_shdrp;  /* Section header table, internal form */
  unsigned int count;
  unsigned int count;
  bfd_size_type amt;
  bfd_size_type amt;
 
 
  i_ehdrp = elf_elfheader (abfd);
  i_ehdrp = elf_elfheader (abfd);
  i_shdrp = elf_elfsections (abfd);
  i_shdrp = elf_elfsections (abfd);
 
 
  /* swap the header before spitting it out...  */
  /* swap the header before spitting it out...  */
 
 
#if DEBUG & 1
#if DEBUG & 1
  elf_debug_file (i_ehdrp);
  elf_debug_file (i_ehdrp);
#endif
#endif
  elf_swap_ehdr_out (abfd, i_ehdrp, &x_ehdr);
  elf_swap_ehdr_out (abfd, i_ehdrp, &x_ehdr);
  amt = sizeof (x_ehdr);
  amt = sizeof (x_ehdr);
  if (bfd_seek (abfd, (file_ptr) 0, SEEK_SET) != 0
  if (bfd_seek (abfd, (file_ptr) 0, SEEK_SET) != 0
      || bfd_bwrite (&x_ehdr, amt, abfd) != amt)
      || bfd_bwrite (&x_ehdr, amt, abfd) != amt)
    return FALSE;
    return FALSE;
 
 
  /* Some fields in the first section header handle overflow of ehdr
  /* Some fields in the first section header handle overflow of ehdr
     fields.  */
     fields.  */
  if (i_ehdrp->e_phnum >= PN_XNUM)
  if (i_ehdrp->e_phnum >= PN_XNUM)
    i_shdrp[0]->sh_info = i_ehdrp->e_phnum;
    i_shdrp[0]->sh_info = i_ehdrp->e_phnum;
  if (i_ehdrp->e_shnum >= (SHN_LORESERVE & 0xffff))
  if (i_ehdrp->e_shnum >= (SHN_LORESERVE & 0xffff))
    i_shdrp[0]->sh_size = i_ehdrp->e_shnum;
    i_shdrp[0]->sh_size = i_ehdrp->e_shnum;
  if (i_ehdrp->e_shstrndx >= (SHN_LORESERVE & 0xffff))
  if (i_ehdrp->e_shstrndx >= (SHN_LORESERVE & 0xffff))
    i_shdrp[0]->sh_link = i_ehdrp->e_shstrndx;
    i_shdrp[0]->sh_link = i_ehdrp->e_shstrndx;
 
 
  /* at this point we've concocted all the ELF sections...  */
  /* at this point we've concocted all the ELF sections...  */
  amt = i_ehdrp->e_shnum;
  amt = i_ehdrp->e_shnum;
  amt *= sizeof (*x_shdrp);
  amt *= sizeof (*x_shdrp);
  x_shdrp = (Elf_External_Shdr *) bfd_alloc (abfd, amt);
  x_shdrp = (Elf_External_Shdr *) bfd_alloc (abfd, amt);
  if (!x_shdrp)
  if (!x_shdrp)
    return FALSE;
    return FALSE;
 
 
  for (count = 0; count < i_ehdrp->e_shnum; i_shdrp++, count++)
  for (count = 0; count < i_ehdrp->e_shnum; i_shdrp++, count++)
    {
    {
#if DEBUG & 2
#if DEBUG & 2
      elf_debug_section (count, *i_shdrp);
      elf_debug_section (count, *i_shdrp);
#endif
#endif
      elf_swap_shdr_out (abfd, *i_shdrp, x_shdrp + count);
      elf_swap_shdr_out (abfd, *i_shdrp, x_shdrp + count);
    }
    }
  if (bfd_seek (abfd, (file_ptr) i_ehdrp->e_shoff, SEEK_SET) != 0
  if (bfd_seek (abfd, (file_ptr) i_ehdrp->e_shoff, SEEK_SET) != 0
      || bfd_bwrite (x_shdrp, amt, abfd) != amt)
      || bfd_bwrite (x_shdrp, amt, abfd) != amt)
    return FALSE;
    return FALSE;
 
 
  /* need to dump the string table too...  */
  /* need to dump the string table too...  */
 
 
  return TRUE;
  return TRUE;
}
}
 
 
bfd_boolean
bfd_boolean
elf_checksum_contents (bfd *abfd,
elf_checksum_contents (bfd *abfd,
                       void (*process) (const void *, size_t, void *),
                       void (*process) (const void *, size_t, void *),
                       void *arg)
                       void *arg)
{
{
  Elf_Internal_Ehdr *i_ehdrp = elf_elfheader (abfd);
  Elf_Internal_Ehdr *i_ehdrp = elf_elfheader (abfd);
  Elf_Internal_Shdr **i_shdrp = elf_elfsections (abfd);
  Elf_Internal_Shdr **i_shdrp = elf_elfsections (abfd);
  Elf_Internal_Phdr *i_phdrp = elf_tdata (abfd)->phdr;
  Elf_Internal_Phdr *i_phdrp = elf_tdata (abfd)->phdr;
  unsigned int count, num;
  unsigned int count, num;
 
 
  {
  {
    Elf_External_Ehdr x_ehdr;
    Elf_External_Ehdr x_ehdr;
    Elf_Internal_Ehdr i_ehdr;
    Elf_Internal_Ehdr i_ehdr;
 
 
    i_ehdr = *i_ehdrp;
    i_ehdr = *i_ehdrp;
    i_ehdr.e_phoff = i_ehdr.e_shoff = 0;
    i_ehdr.e_phoff = i_ehdr.e_shoff = 0;
    elf_swap_ehdr_out (abfd, &i_ehdr, &x_ehdr);
    elf_swap_ehdr_out (abfd, &i_ehdr, &x_ehdr);
    (*process) (&x_ehdr, sizeof x_ehdr, arg);
    (*process) (&x_ehdr, sizeof x_ehdr, arg);
  }
  }
 
 
  num = i_ehdrp->e_phnum;
  num = i_ehdrp->e_phnum;
  for (count = 0; count < num; count++)
  for (count = 0; count < num; count++)
    {
    {
      Elf_External_Phdr x_phdr;
      Elf_External_Phdr x_phdr;
      elf_swap_phdr_out (abfd, &i_phdrp[count], &x_phdr);
      elf_swap_phdr_out (abfd, &i_phdrp[count], &x_phdr);
      (*process) (&x_phdr, sizeof x_phdr, arg);
      (*process) (&x_phdr, sizeof x_phdr, arg);
    }
    }
 
 
  num = elf_numsections (abfd);
  num = elf_numsections (abfd);
  for (count = 0; count < num; count++)
  for (count = 0; count < num; count++)
    {
    {
      Elf_Internal_Shdr i_shdr;
      Elf_Internal_Shdr i_shdr;
      Elf_External_Shdr x_shdr;
      Elf_External_Shdr x_shdr;
 
 
      i_shdr = *i_shdrp[count];
      i_shdr = *i_shdrp[count];
      i_shdr.sh_offset = 0;
      i_shdr.sh_offset = 0;
 
 
      elf_swap_shdr_out (abfd, &i_shdr, &x_shdr);
      elf_swap_shdr_out (abfd, &i_shdr, &x_shdr);
      (*process) (&x_shdr, sizeof x_shdr, arg);
      (*process) (&x_shdr, sizeof x_shdr, arg);
 
 
      if (i_shdr.contents)
      if (i_shdr.contents)
        (*process) (i_shdr.contents, i_shdr.sh_size, arg);
        (*process) (i_shdr.contents, i_shdr.sh_size, arg);
    }
    }
 
 
  return TRUE;
  return TRUE;
}
}
 
 
long
long
elf_slurp_symbol_table (bfd *abfd, asymbol **symptrs, bfd_boolean dynamic)
elf_slurp_symbol_table (bfd *abfd, asymbol **symptrs, bfd_boolean dynamic)
{
{
  Elf_Internal_Shdr *hdr;
  Elf_Internal_Shdr *hdr;
  Elf_Internal_Shdr *verhdr;
  Elf_Internal_Shdr *verhdr;
  unsigned long symcount;       /* Number of external ELF symbols */
  unsigned long symcount;       /* Number of external ELF symbols */
  elf_symbol_type *sym;         /* Pointer to current bfd symbol */
  elf_symbol_type *sym;         /* Pointer to current bfd symbol */
  elf_symbol_type *symbase;     /* Buffer for generated bfd symbols */
  elf_symbol_type *symbase;     /* Buffer for generated bfd symbols */
  Elf_Internal_Sym *isym;
  Elf_Internal_Sym *isym;
  Elf_Internal_Sym *isymend;
  Elf_Internal_Sym *isymend;
  Elf_Internal_Sym *isymbuf = NULL;
  Elf_Internal_Sym *isymbuf = NULL;
  Elf_External_Versym *xver;
  Elf_External_Versym *xver;
  Elf_External_Versym *xverbuf = NULL;
  Elf_External_Versym *xverbuf = NULL;
  const struct elf_backend_data *ebd;
  const struct elf_backend_data *ebd;
  bfd_size_type amt;
  bfd_size_type amt;
 
 
  /* Read each raw ELF symbol, converting from external ELF form to
  /* Read each raw ELF symbol, converting from external ELF form to
     internal ELF form, and then using the information to create a
     internal ELF form, and then using the information to create a
     canonical bfd symbol table entry.
     canonical bfd symbol table entry.
 
 
     Note that we allocate the initial bfd canonical symbol buffer
     Note that we allocate the initial bfd canonical symbol buffer
     based on a one-to-one mapping of the ELF symbols to canonical
     based on a one-to-one mapping of the ELF symbols to canonical
     symbols.  We actually use all the ELF symbols, so there will be no
     symbols.  We actually use all the ELF symbols, so there will be no
     space left over at the end.  When we have all the symbols, we
     space left over at the end.  When we have all the symbols, we
     build the caller's pointer vector.  */
     build the caller's pointer vector.  */
 
 
  if (! dynamic)
  if (! dynamic)
    {
    {
      hdr = &elf_tdata (abfd)->symtab_hdr;
      hdr = &elf_tdata (abfd)->symtab_hdr;
      verhdr = NULL;
      verhdr = NULL;
    }
    }
  else
  else
    {
    {
      hdr = &elf_tdata (abfd)->dynsymtab_hdr;
      hdr = &elf_tdata (abfd)->dynsymtab_hdr;
      if (elf_dynversym (abfd) == 0)
      if (elf_dynversym (abfd) == 0)
        verhdr = NULL;
        verhdr = NULL;
      else
      else
        verhdr = &elf_tdata (abfd)->dynversym_hdr;
        verhdr = &elf_tdata (abfd)->dynversym_hdr;
      if ((elf_tdata (abfd)->dynverdef_section != 0
      if ((elf_tdata (abfd)->dynverdef_section != 0
           && elf_tdata (abfd)->verdef == NULL)
           && elf_tdata (abfd)->verdef == NULL)
          || (elf_tdata (abfd)->dynverref_section != 0
          || (elf_tdata (abfd)->dynverref_section != 0
              && elf_tdata (abfd)->verref == NULL))
              && elf_tdata (abfd)->verref == NULL))
        {
        {
          if (!_bfd_elf_slurp_version_tables (abfd, FALSE))
          if (!_bfd_elf_slurp_version_tables (abfd, FALSE))
            return -1;
            return -1;
        }
        }
    }
    }
 
 
  ebd = get_elf_backend_data (abfd);
  ebd = get_elf_backend_data (abfd);
  symcount = hdr->sh_size / sizeof (Elf_External_Sym);
  symcount = hdr->sh_size / sizeof (Elf_External_Sym);
  if (symcount == 0)
  if (symcount == 0)
    sym = symbase = NULL;
    sym = symbase = NULL;
  else
  else
    {
    {
      isymbuf = bfd_elf_get_elf_syms (abfd, hdr, symcount, 0,
      isymbuf = bfd_elf_get_elf_syms (abfd, hdr, symcount, 0,
                                      NULL, NULL, NULL);
                                      NULL, NULL, NULL);
      if (isymbuf == NULL)
      if (isymbuf == NULL)
        return -1;
        return -1;
 
 
      amt = symcount;
      amt = symcount;
      amt *= sizeof (elf_symbol_type);
      amt *= sizeof (elf_symbol_type);
      symbase = (elf_symbol_type *) bfd_zalloc (abfd, amt);
      symbase = (elf_symbol_type *) bfd_zalloc (abfd, amt);
      if (symbase == (elf_symbol_type *) NULL)
      if (symbase == (elf_symbol_type *) NULL)
        goto error_return;
        goto error_return;
 
 
      /* Read the raw ELF version symbol information.  */
      /* Read the raw ELF version symbol information.  */
      if (verhdr != NULL
      if (verhdr != NULL
          && verhdr->sh_size / sizeof (Elf_External_Versym) != symcount)
          && verhdr->sh_size / sizeof (Elf_External_Versym) != symcount)
        {
        {
          (*_bfd_error_handler)
          (*_bfd_error_handler)
            (_("%s: version count (%ld) does not match symbol count (%ld)"),
            (_("%s: version count (%ld) does not match symbol count (%ld)"),
             abfd->filename,
             abfd->filename,
             (long) (verhdr->sh_size / sizeof (Elf_External_Versym)),
             (long) (verhdr->sh_size / sizeof (Elf_External_Versym)),
             symcount);
             symcount);
 
 
          /* Slurp in the symbols without the version information,
          /* Slurp in the symbols without the version information,
             since that is more helpful than just quitting.  */
             since that is more helpful than just quitting.  */
          verhdr = NULL;
          verhdr = NULL;
        }
        }
 
 
      if (verhdr != NULL)
      if (verhdr != NULL)
        {
        {
          if (bfd_seek (abfd, verhdr->sh_offset, SEEK_SET) != 0)
          if (bfd_seek (abfd, verhdr->sh_offset, SEEK_SET) != 0)
            goto error_return;
            goto error_return;
 
 
          xverbuf = (Elf_External_Versym *) bfd_malloc (verhdr->sh_size);
          xverbuf = (Elf_External_Versym *) bfd_malloc (verhdr->sh_size);
          if (xverbuf == NULL && verhdr->sh_size != 0)
          if (xverbuf == NULL && verhdr->sh_size != 0)
            goto error_return;
            goto error_return;
 
 
          if (bfd_bread (xverbuf, verhdr->sh_size, abfd) != verhdr->sh_size)
          if (bfd_bread (xverbuf, verhdr->sh_size, abfd) != verhdr->sh_size)
            goto error_return;
            goto error_return;
        }
        }
 
 
      /* Skip first symbol, which is a null dummy.  */
      /* Skip first symbol, which is a null dummy.  */
      xver = xverbuf;
      xver = xverbuf;
      if (xver != NULL)
      if (xver != NULL)
        ++xver;
        ++xver;
      isymend = isymbuf + symcount;
      isymend = isymbuf + symcount;
      for (isym = isymbuf + 1, sym = symbase; isym < isymend; isym++, sym++)
      for (isym = isymbuf + 1, sym = symbase; isym < isymend; isym++, sym++)
        {
        {
          memcpy (&sym->internal_elf_sym, isym, sizeof (Elf_Internal_Sym));
          memcpy (&sym->internal_elf_sym, isym, sizeof (Elf_Internal_Sym));
          sym->symbol.the_bfd = abfd;
          sym->symbol.the_bfd = abfd;
 
 
          sym->symbol.name = bfd_elf_sym_name (abfd, hdr, isym, NULL);
          sym->symbol.name = bfd_elf_sym_name (abfd, hdr, isym, NULL);
 
 
          sym->symbol.value = isym->st_value;
          sym->symbol.value = isym->st_value;
 
 
          if (isym->st_shndx == SHN_UNDEF)
          if (isym->st_shndx == SHN_UNDEF)
            {
            {
              sym->symbol.section = bfd_und_section_ptr;
              sym->symbol.section = bfd_und_section_ptr;
            }
            }
          else if (isym->st_shndx == SHN_ABS)
          else if (isym->st_shndx == SHN_ABS)
            {
            {
              sym->symbol.section = bfd_abs_section_ptr;
              sym->symbol.section = bfd_abs_section_ptr;
            }
            }
          else if (isym->st_shndx == SHN_COMMON)
          else if (isym->st_shndx == SHN_COMMON)
            {
            {
              sym->symbol.section = bfd_com_section_ptr;
              sym->symbol.section = bfd_com_section_ptr;
              if ((abfd->flags & BFD_PLUGIN) != 0)
              if ((abfd->flags & BFD_PLUGIN) != 0)
                {
                {
                  asection *xc = bfd_get_section_by_name (abfd, "COMMON");
                  asection *xc = bfd_get_section_by_name (abfd, "COMMON");
 
 
                  if (xc == NULL)
                  if (xc == NULL)
                    {
                    {
                      flagword flags = (SEC_ALLOC | SEC_IS_COMMON | SEC_KEEP
                      flagword flags = (SEC_ALLOC | SEC_IS_COMMON | SEC_KEEP
                                        | SEC_EXCLUDE);
                                        | SEC_EXCLUDE);
                      xc = bfd_make_section_with_flags (abfd, "COMMON", flags);
                      xc = bfd_make_section_with_flags (abfd, "COMMON", flags);
                      if (xc == NULL)
                      if (xc == NULL)
                        goto error_return;
                        goto error_return;
                    }
                    }
                  sym->symbol.section = xc;
                  sym->symbol.section = xc;
                }
                }
              /* Elf puts the alignment into the `value' field, and
              /* Elf puts the alignment into the `value' field, and
                 the size into the `size' field.  BFD wants to see the
                 the size into the `size' field.  BFD wants to see the
                 size in the value field, and doesn't care (at the
                 size in the value field, and doesn't care (at the
                 moment) about the alignment.  */
                 moment) about the alignment.  */
              sym->symbol.value = isym->st_size;
              sym->symbol.value = isym->st_size;
            }
            }
          else
          else
            {
            {
              sym->symbol.section
              sym->symbol.section
                = bfd_section_from_elf_index (abfd, isym->st_shndx);
                = bfd_section_from_elf_index (abfd, isym->st_shndx);
              if (sym->symbol.section == NULL)
              if (sym->symbol.section == NULL)
                {
                {
                  /* This symbol is in a section for which we did not
                  /* This symbol is in a section for which we did not
                     create a BFD section.  Just use bfd_abs_section,
                     create a BFD section.  Just use bfd_abs_section,
                     although it is wrong.  FIXME.  */
                     although it is wrong.  FIXME.  */
                  sym->symbol.section = bfd_abs_section_ptr;
                  sym->symbol.section = bfd_abs_section_ptr;
                }
                }
            }
            }
 
 
          /* If this is a relocatable file, then the symbol value is
          /* If this is a relocatable file, then the symbol value is
             already section relative.  */
             already section relative.  */
          if ((abfd->flags & (EXEC_P | DYNAMIC)) != 0)
          if ((abfd->flags & (EXEC_P | DYNAMIC)) != 0)
            sym->symbol.value -= sym->symbol.section->vma;
            sym->symbol.value -= sym->symbol.section->vma;
 
 
          switch (ELF_ST_BIND (isym->st_info))
          switch (ELF_ST_BIND (isym->st_info))
            {
            {
            case STB_LOCAL:
            case STB_LOCAL:
              sym->symbol.flags |= BSF_LOCAL;
              sym->symbol.flags |= BSF_LOCAL;
              break;
              break;
            case STB_GLOBAL:
            case STB_GLOBAL:
              if (isym->st_shndx != SHN_UNDEF && isym->st_shndx != SHN_COMMON)
              if (isym->st_shndx != SHN_UNDEF && isym->st_shndx != SHN_COMMON)
                sym->symbol.flags |= BSF_GLOBAL;
                sym->symbol.flags |= BSF_GLOBAL;
              break;
              break;
            case STB_WEAK:
            case STB_WEAK:
              sym->symbol.flags |= BSF_WEAK;
              sym->symbol.flags |= BSF_WEAK;
              break;
              break;
            case STB_GNU_UNIQUE:
            case STB_GNU_UNIQUE:
              sym->symbol.flags |= BSF_GNU_UNIQUE;
              sym->symbol.flags |= BSF_GNU_UNIQUE;
              break;
              break;
            }
            }
 
 
          switch (ELF_ST_TYPE (isym->st_info))
          switch (ELF_ST_TYPE (isym->st_info))
            {
            {
            case STT_SECTION:
            case STT_SECTION:
              sym->symbol.flags |= BSF_SECTION_SYM | BSF_DEBUGGING;
              sym->symbol.flags |= BSF_SECTION_SYM | BSF_DEBUGGING;
              break;
              break;
            case STT_FILE:
            case STT_FILE:
              sym->symbol.flags |= BSF_FILE | BSF_DEBUGGING;
              sym->symbol.flags |= BSF_FILE | BSF_DEBUGGING;
              break;
              break;
            case STT_FUNC:
            case STT_FUNC:
              sym->symbol.flags |= BSF_FUNCTION;
              sym->symbol.flags |= BSF_FUNCTION;
              break;
              break;
            case STT_COMMON:
            case STT_COMMON:
              /* FIXME: Do we have to put the size field into the value field
              /* FIXME: Do we have to put the size field into the value field
                 as we do with symbols in SHN_COMMON sections (see above) ?  */
                 as we do with symbols in SHN_COMMON sections (see above) ?  */
              /* Fall through.  */
              /* Fall through.  */
            case STT_OBJECT:
            case STT_OBJECT:
              sym->symbol.flags |= BSF_OBJECT;
              sym->symbol.flags |= BSF_OBJECT;
              break;
              break;
            case STT_TLS:
            case STT_TLS:
              sym->symbol.flags |= BSF_THREAD_LOCAL;
              sym->symbol.flags |= BSF_THREAD_LOCAL;
              break;
              break;
            case STT_RELC:
            case STT_RELC:
              sym->symbol.flags |= BSF_RELC;
              sym->symbol.flags |= BSF_RELC;
              break;
              break;
            case STT_SRELC:
            case STT_SRELC:
              sym->symbol.flags |= BSF_SRELC;
              sym->symbol.flags |= BSF_SRELC;
              break;
              break;
            case STT_GNU_IFUNC:
            case STT_GNU_IFUNC:
              sym->symbol.flags |= BSF_GNU_INDIRECT_FUNCTION;
              sym->symbol.flags |= BSF_GNU_INDIRECT_FUNCTION;
              break;
              break;
            }
            }
 
 
          if (dynamic)
          if (dynamic)
            sym->symbol.flags |= BSF_DYNAMIC;
            sym->symbol.flags |= BSF_DYNAMIC;
 
 
          if (xver != NULL)
          if (xver != NULL)
            {
            {
              Elf_Internal_Versym iversym;
              Elf_Internal_Versym iversym;
 
 
              _bfd_elf_swap_versym_in (abfd, xver, &iversym);
              _bfd_elf_swap_versym_in (abfd, xver, &iversym);
              sym->version = iversym.vs_vers;
              sym->version = iversym.vs_vers;
              xver++;
              xver++;
            }
            }
 
 
          /* Do some backend-specific processing on this symbol.  */
          /* Do some backend-specific processing on this symbol.  */
          if (ebd->elf_backend_symbol_processing)
          if (ebd->elf_backend_symbol_processing)
            (*ebd->elf_backend_symbol_processing) (abfd, &sym->symbol);
            (*ebd->elf_backend_symbol_processing) (abfd, &sym->symbol);
        }
        }
    }
    }
 
 
  /* Do some backend-specific processing on this symbol table.  */
  /* Do some backend-specific processing on this symbol table.  */
  if (ebd->elf_backend_symbol_table_processing)
  if (ebd->elf_backend_symbol_table_processing)
    (*ebd->elf_backend_symbol_table_processing) (abfd, symbase, symcount);
    (*ebd->elf_backend_symbol_table_processing) (abfd, symbase, symcount);
 
 
  /* We rely on the zalloc to clear out the final symbol entry.  */
  /* We rely on the zalloc to clear out the final symbol entry.  */
 
 
  symcount = sym - symbase;
  symcount = sym - symbase;
 
 
  /* Fill in the user's symbol pointer vector if needed.  */
  /* Fill in the user's symbol pointer vector if needed.  */
  if (symptrs)
  if (symptrs)
    {
    {
      long l = symcount;
      long l = symcount;
 
 
      sym = symbase;
      sym = symbase;
      while (l-- > 0)
      while (l-- > 0)
        {
        {
          *symptrs++ = &sym->symbol;
          *symptrs++ = &sym->symbol;
          sym++;
          sym++;
        }
        }
      *symptrs = 0;              /* Final null pointer */
      *symptrs = 0;              /* Final null pointer */
    }
    }
 
 
  if (xverbuf != NULL)
  if (xverbuf != NULL)
    free (xverbuf);
    free (xverbuf);
  if (isymbuf != NULL && hdr->contents != (unsigned char *) isymbuf)
  if (isymbuf != NULL && hdr->contents != (unsigned char *) isymbuf)
    free (isymbuf);
    free (isymbuf);
  return symcount;
  return symcount;
 
 
error_return:
error_return:
  if (xverbuf != NULL)
  if (xverbuf != NULL)
    free (xverbuf);
    free (xverbuf);
  if (isymbuf != NULL && hdr->contents != (unsigned char *) isymbuf)
  if (isymbuf != NULL && hdr->contents != (unsigned char *) isymbuf)
    free (isymbuf);
    free (isymbuf);
  return -1;
  return -1;
}
}
 
 
/* Read relocations for ASECT from REL_HDR.  There are RELOC_COUNT of
/* Read relocations for ASECT from REL_HDR.  There are RELOC_COUNT of
   them.  */
   them.  */
 
 
static bfd_boolean
static bfd_boolean
elf_slurp_reloc_table_from_section (bfd *abfd,
elf_slurp_reloc_table_from_section (bfd *abfd,
                                    asection *asect,
                                    asection *asect,
                                    Elf_Internal_Shdr *rel_hdr,
                                    Elf_Internal_Shdr *rel_hdr,
                                    bfd_size_type reloc_count,
                                    bfd_size_type reloc_count,
                                    arelent *relents,
                                    arelent *relents,
                                    asymbol **symbols,
                                    asymbol **symbols,
                                    bfd_boolean dynamic)
                                    bfd_boolean dynamic)
{
{
  const struct elf_backend_data * const ebd = get_elf_backend_data (abfd);
  const struct elf_backend_data * const ebd = get_elf_backend_data (abfd);
  void *allocated = NULL;
  void *allocated = NULL;
  bfd_byte *native_relocs;
  bfd_byte *native_relocs;
  arelent *relent;
  arelent *relent;
  unsigned int i;
  unsigned int i;
  int entsize;
  int entsize;
  unsigned int symcount;
  unsigned int symcount;
 
 
  allocated = bfd_malloc (rel_hdr->sh_size);
  allocated = bfd_malloc (rel_hdr->sh_size);
  if (allocated == NULL)
  if (allocated == NULL)
    goto error_return;
    goto error_return;
 
 
  if (bfd_seek (abfd, rel_hdr->sh_offset, SEEK_SET) != 0
  if (bfd_seek (abfd, rel_hdr->sh_offset, SEEK_SET) != 0
      || (bfd_bread (allocated, rel_hdr->sh_size, abfd)
      || (bfd_bread (allocated, rel_hdr->sh_size, abfd)
          != rel_hdr->sh_size))
          != rel_hdr->sh_size))
    goto error_return;
    goto error_return;
 
 
  native_relocs = (bfd_byte *) allocated;
  native_relocs = (bfd_byte *) allocated;
 
 
  entsize = rel_hdr->sh_entsize;
  entsize = rel_hdr->sh_entsize;
  BFD_ASSERT (entsize == sizeof (Elf_External_Rel)
  BFD_ASSERT (entsize == sizeof (Elf_External_Rel)
              || entsize == sizeof (Elf_External_Rela));
              || entsize == sizeof (Elf_External_Rela));
 
 
  if (dynamic)
  if (dynamic)
    symcount = bfd_get_dynamic_symcount (abfd);
    symcount = bfd_get_dynamic_symcount (abfd);
  else
  else
    symcount = bfd_get_symcount (abfd);
    symcount = bfd_get_symcount (abfd);
 
 
  for (i = 0, relent = relents;
  for (i = 0, relent = relents;
       i < reloc_count;
       i < reloc_count;
       i++, relent++, native_relocs += entsize)
       i++, relent++, native_relocs += entsize)
    {
    {
      Elf_Internal_Rela rela;
      Elf_Internal_Rela rela;
 
 
      if (entsize == sizeof (Elf_External_Rela))
      if (entsize == sizeof (Elf_External_Rela))
        elf_swap_reloca_in (abfd, native_relocs, &rela);
        elf_swap_reloca_in (abfd, native_relocs, &rela);
      else
      else
        elf_swap_reloc_in (abfd, native_relocs, &rela);
        elf_swap_reloc_in (abfd, native_relocs, &rela);
 
 
      /* The address of an ELF reloc is section relative for an object
      /* The address of an ELF reloc is section relative for an object
         file, and absolute for an executable file or shared library.
         file, and absolute for an executable file or shared library.
         The address of a normal BFD reloc is always section relative,
         The address of a normal BFD reloc is always section relative,
         and the address of a dynamic reloc is absolute..  */
         and the address of a dynamic reloc is absolute..  */
      if ((abfd->flags & (EXEC_P | DYNAMIC)) == 0 || dynamic)
      if ((abfd->flags & (EXEC_P | DYNAMIC)) == 0 || dynamic)
        relent->address = rela.r_offset;
        relent->address = rela.r_offset;
      else
      else
        relent->address = rela.r_offset - asect->vma;
        relent->address = rela.r_offset - asect->vma;
 
 
      if (ELF_R_SYM (rela.r_info) == STN_UNDEF)
      if (ELF_R_SYM (rela.r_info) == STN_UNDEF)
        relent->sym_ptr_ptr = bfd_abs_section_ptr->symbol_ptr_ptr;
        relent->sym_ptr_ptr = bfd_abs_section_ptr->symbol_ptr_ptr;
      else if (ELF_R_SYM (rela.r_info) > symcount)
      else if (ELF_R_SYM (rela.r_info) > symcount)
        {
        {
          (*_bfd_error_handler)
          (*_bfd_error_handler)
            (_("%s(%s): relocation %d has invalid symbol index %ld"),
            (_("%s(%s): relocation %d has invalid symbol index %ld"),
             abfd->filename, asect->name, i, ELF_R_SYM (rela.r_info));
             abfd->filename, asect->name, i, ELF_R_SYM (rela.r_info));
          relent->sym_ptr_ptr = bfd_abs_section.symbol_ptr_ptr;
          relent->sym_ptr_ptr = bfd_abs_section.symbol_ptr_ptr;
        }
        }
      else
      else
        {
        {
          asymbol **ps;
          asymbol **ps;
 
 
          ps = symbols + ELF_R_SYM (rela.r_info) - 1;
          ps = symbols + ELF_R_SYM (rela.r_info) - 1;
 
 
          relent->sym_ptr_ptr = ps;
          relent->sym_ptr_ptr = ps;
        }
        }
 
 
      relent->addend = rela.r_addend;
      relent->addend = rela.r_addend;
 
 
      if ((entsize == sizeof (Elf_External_Rela)
      if ((entsize == sizeof (Elf_External_Rela)
           && ebd->elf_info_to_howto != NULL)
           && ebd->elf_info_to_howto != NULL)
          || ebd->elf_info_to_howto_rel == NULL)
          || ebd->elf_info_to_howto_rel == NULL)
        (*ebd->elf_info_to_howto) (abfd, relent, &rela);
        (*ebd->elf_info_to_howto) (abfd, relent, &rela);
      else
      else
        (*ebd->elf_info_to_howto_rel) (abfd, relent, &rela);
        (*ebd->elf_info_to_howto_rel) (abfd, relent, &rela);
    }
    }
 
 
  if (allocated != NULL)
  if (allocated != NULL)
    free (allocated);
    free (allocated);
 
 
  return TRUE;
  return TRUE;
 
 
 error_return:
 error_return:
  if (allocated != NULL)
  if (allocated != NULL)
    free (allocated);
    free (allocated);
  return FALSE;
  return FALSE;
}
}
 
 
/* Read in and swap the external relocs.  */
/* Read in and swap the external relocs.  */
 
 
bfd_boolean
bfd_boolean
elf_slurp_reloc_table (bfd *abfd,
elf_slurp_reloc_table (bfd *abfd,
                       asection *asect,
                       asection *asect,
                       asymbol **symbols,
                       asymbol **symbols,
                       bfd_boolean dynamic)
                       bfd_boolean dynamic)
{
{
  struct bfd_elf_section_data * const d = elf_section_data (asect);
  struct bfd_elf_section_data * const d = elf_section_data (asect);
  Elf_Internal_Shdr *rel_hdr;
  Elf_Internal_Shdr *rel_hdr;
  Elf_Internal_Shdr *rel_hdr2;
  Elf_Internal_Shdr *rel_hdr2;
  bfd_size_type reloc_count;
  bfd_size_type reloc_count;
  bfd_size_type reloc_count2;
  bfd_size_type reloc_count2;
  arelent *relents;
  arelent *relents;
  bfd_size_type amt;
  bfd_size_type amt;
 
 
  if (asect->relocation != NULL)
  if (asect->relocation != NULL)
    return TRUE;
    return TRUE;
 
 
  if (! dynamic)
  if (! dynamic)
    {
    {
      if ((asect->flags & SEC_RELOC) == 0
      if ((asect->flags & SEC_RELOC) == 0
          || asect->reloc_count == 0)
          || asect->reloc_count == 0)
        return TRUE;
        return TRUE;
 
 
      rel_hdr = d->rel.hdr;
      rel_hdr = d->rel.hdr;
      reloc_count = rel_hdr ? NUM_SHDR_ENTRIES (rel_hdr) : 0;
      reloc_count = rel_hdr ? NUM_SHDR_ENTRIES (rel_hdr) : 0;
      rel_hdr2 = d->rela.hdr;
      rel_hdr2 = d->rela.hdr;
      reloc_count2 = rel_hdr2 ? NUM_SHDR_ENTRIES (rel_hdr2) : 0;
      reloc_count2 = rel_hdr2 ? NUM_SHDR_ENTRIES (rel_hdr2) : 0;
 
 
      BFD_ASSERT (asect->reloc_count == reloc_count + reloc_count2);
      BFD_ASSERT (asect->reloc_count == reloc_count + reloc_count2);
      BFD_ASSERT ((rel_hdr && asect->rel_filepos == rel_hdr->sh_offset)
      BFD_ASSERT ((rel_hdr && asect->rel_filepos == rel_hdr->sh_offset)
                  || (rel_hdr2 && asect->rel_filepos == rel_hdr2->sh_offset));
                  || (rel_hdr2 && asect->rel_filepos == rel_hdr2->sh_offset));
 
 
    }
    }
  else
  else
    {
    {
      /* Note that ASECT->RELOC_COUNT tends not to be accurate in this
      /* Note that ASECT->RELOC_COUNT tends not to be accurate in this
         case because relocations against this section may use the
         case because relocations against this section may use the
         dynamic symbol table, and in that case bfd_section_from_shdr
         dynamic symbol table, and in that case bfd_section_from_shdr
         in elf.c does not update the RELOC_COUNT.  */
         in elf.c does not update the RELOC_COUNT.  */
      if (asect->size == 0)
      if (asect->size == 0)
        return TRUE;
        return TRUE;
 
 
      rel_hdr = &d->this_hdr;
      rel_hdr = &d->this_hdr;
      reloc_count = NUM_SHDR_ENTRIES (rel_hdr);
      reloc_count = NUM_SHDR_ENTRIES (rel_hdr);
      rel_hdr2 = NULL;
      rel_hdr2 = NULL;
      reloc_count2 = 0;
      reloc_count2 = 0;
    }
    }
 
 
  amt = (reloc_count + reloc_count2) * sizeof (arelent);
  amt = (reloc_count + reloc_count2) * sizeof (arelent);
  relents = (arelent *) bfd_alloc (abfd, amt);
  relents = (arelent *) bfd_alloc (abfd, amt);
  if (relents == NULL)
  if (relents == NULL)
    return FALSE;
    return FALSE;
 
 
  if (rel_hdr
  if (rel_hdr
      && !elf_slurp_reloc_table_from_section (abfd, asect,
      && !elf_slurp_reloc_table_from_section (abfd, asect,
                                              rel_hdr, reloc_count,
                                              rel_hdr, reloc_count,
                                              relents,
                                              relents,
                                              symbols, dynamic))
                                              symbols, dynamic))
    return FALSE;
    return FALSE;
 
 
  if (rel_hdr2
  if (rel_hdr2
      && !elf_slurp_reloc_table_from_section (abfd, asect,
      && !elf_slurp_reloc_table_from_section (abfd, asect,
                                              rel_hdr2, reloc_count2,
                                              rel_hdr2, reloc_count2,
                                              relents + reloc_count,
                                              relents + reloc_count,
                                              symbols, dynamic))
                                              symbols, dynamic))
    return FALSE;
    return FALSE;
 
 
  asect->relocation = relents;
  asect->relocation = relents;
  return TRUE;
  return TRUE;
}
}
 
 
#if DEBUG & 2
#if DEBUG & 2
static void
static void
elf_debug_section (int num, Elf_Internal_Shdr *hdr)
elf_debug_section (int num, Elf_Internal_Shdr *hdr)
{
{
  fprintf (stderr, "\nSection#%d '%s' 0x%.8lx\n", num,
  fprintf (stderr, "\nSection#%d '%s' 0x%.8lx\n", num,
           hdr->bfd_section != NULL ? hdr->bfd_section->name : "",
           hdr->bfd_section != NULL ? hdr->bfd_section->name : "",
           (long) hdr);
           (long) hdr);
  fprintf (stderr,
  fprintf (stderr,
           "sh_name      = %ld\tsh_type      = %ld\tsh_flags     = %ld\n",
           "sh_name      = %ld\tsh_type      = %ld\tsh_flags     = %ld\n",
           (long) hdr->sh_name,
           (long) hdr->sh_name,
           (long) hdr->sh_type,
           (long) hdr->sh_type,
           (long) hdr->sh_flags);
           (long) hdr->sh_flags);
  fprintf (stderr,
  fprintf (stderr,
           "sh_addr      = %ld\tsh_offset    = %ld\tsh_size      = %ld\n",
           "sh_addr      = %ld\tsh_offset    = %ld\tsh_size      = %ld\n",
           (long) hdr->sh_addr,
           (long) hdr->sh_addr,
           (long) hdr->sh_offset,
           (long) hdr->sh_offset,
           (long) hdr->sh_size);
           (long) hdr->sh_size);
  fprintf (stderr,
  fprintf (stderr,
           "sh_link      = %ld\tsh_info      = %ld\tsh_addralign = %ld\n",
           "sh_link      = %ld\tsh_info      = %ld\tsh_addralign = %ld\n",
           (long) hdr->sh_link,
           (long) hdr->sh_link,
           (long) hdr->sh_info,
           (long) hdr->sh_info,
           (long) hdr->sh_addralign);
           (long) hdr->sh_addralign);
  fprintf (stderr, "sh_entsize   = %ld\n",
  fprintf (stderr, "sh_entsize   = %ld\n",
           (long) hdr->sh_entsize);
           (long) hdr->sh_entsize);
  fflush (stderr);
  fflush (stderr);
}
}
#endif
#endif
 
 
#if DEBUG & 1
#if DEBUG & 1
static void
static void
elf_debug_file (Elf_Internal_Ehdr *ehdrp)
elf_debug_file (Elf_Internal_Ehdr *ehdrp)
{
{
  fprintf (stderr, "e_entry      = 0x%.8lx\n", (long) ehdrp->e_entry);
  fprintf (stderr, "e_entry      = 0x%.8lx\n", (long) ehdrp->e_entry);
  fprintf (stderr, "e_phoff      = %ld\n", (long) ehdrp->e_phoff);
  fprintf (stderr, "e_phoff      = %ld\n", (long) ehdrp->e_phoff);
  fprintf (stderr, "e_phnum      = %ld\n", (long) ehdrp->e_phnum);
  fprintf (stderr, "e_phnum      = %ld\n", (long) ehdrp->e_phnum);
  fprintf (stderr, "e_phentsize  = %ld\n", (long) ehdrp->e_phentsize);
  fprintf (stderr, "e_phentsize  = %ld\n", (long) ehdrp->e_phentsize);
  fprintf (stderr, "e_shoff      = %ld\n", (long) ehdrp->e_shoff);
  fprintf (stderr, "e_shoff      = %ld\n", (long) ehdrp->e_shoff);
  fprintf (stderr, "e_shnum      = %ld\n", (long) ehdrp->e_shnum);
  fprintf (stderr, "e_shnum      = %ld\n", (long) ehdrp->e_shnum);
  fprintf (stderr, "e_shentsize  = %ld\n", (long) ehdrp->e_shentsize);
  fprintf (stderr, "e_shentsize  = %ld\n", (long) ehdrp->e_shentsize);
}
}
#endif
#endif


/* Create a new BFD as if by bfd_openr.  Rather than opening a file,
/* Create a new BFD as if by bfd_openr.  Rather than opening a file,
   reconstruct an ELF file by reading the segments out of remote memory
   reconstruct an ELF file by reading the segments out of remote memory
   based on the ELF file header at EHDR_VMA and the ELF program headers it
   based on the ELF file header at EHDR_VMA and the ELF program headers it
   points to.  If not null, *LOADBASEP is filled in with the difference
   points to.  If not null, *LOADBASEP is filled in with the difference
   between the VMAs from which the segments were read, and the VMAs the
   between the VMAs from which the segments were read, and the VMAs the
   file headers (and hence BFD's idea of each section's VMA) put them at.
   file headers (and hence BFD's idea of each section's VMA) put them at.
 
 
   The function TARGET_READ_MEMORY is called to copy LEN bytes from the
   The function TARGET_READ_MEMORY is called to copy LEN bytes from the
   remote memory at target address VMA into the local buffer at MYADDR; it
   remote memory at target address VMA into the local buffer at MYADDR; it
   should return zero on success or an `errno' code on failure.  TEMPL must
   should return zero on success or an `errno' code on failure.  TEMPL must
   be a BFD for a target with the word size and byte order found in the
   be a BFD for a target with the word size and byte order found in the
   remote memory.  */
   remote memory.  */
 
 
bfd *
bfd *
NAME(_bfd_elf,bfd_from_remote_memory)
NAME(_bfd_elf,bfd_from_remote_memory)
  (bfd *templ,
  (bfd *templ,
   bfd_vma ehdr_vma,
   bfd_vma ehdr_vma,
   bfd_vma *loadbasep,
   bfd_vma *loadbasep,
   int (*target_read_memory) (bfd_vma, bfd_byte *, int))
   int (*target_read_memory) (bfd_vma, bfd_byte *, int))
{
{
  Elf_External_Ehdr x_ehdr;     /* Elf file header, external form */
  Elf_External_Ehdr x_ehdr;     /* Elf file header, external form */
  Elf_Internal_Ehdr i_ehdr;     /* Elf file header, internal form */
  Elf_Internal_Ehdr i_ehdr;     /* Elf file header, internal form */
  Elf_External_Phdr *x_phdrs;
  Elf_External_Phdr *x_phdrs;
  Elf_Internal_Phdr *i_phdrs, *last_phdr;
  Elf_Internal_Phdr *i_phdrs, *last_phdr;
  bfd *nbfd;
  bfd *nbfd;
  struct bfd_in_memory *bim;
  struct bfd_in_memory *bim;
  int contents_size;
  int contents_size;
  bfd_byte *contents;
  bfd_byte *contents;
  int err;
  int err;
  unsigned int i;
  unsigned int i;
  bfd_vma loadbase;
  bfd_vma loadbase;
  bfd_boolean loadbase_set;
  bfd_boolean loadbase_set;
 
 
  /* Read in the ELF header in external format.  */
  /* Read in the ELF header in external format.  */
  err = target_read_memory (ehdr_vma, (bfd_byte *) &x_ehdr, sizeof x_ehdr);
  err = target_read_memory (ehdr_vma, (bfd_byte *) &x_ehdr, sizeof x_ehdr);
  if (err)
  if (err)
    {
    {
      bfd_set_error (bfd_error_system_call);
      bfd_set_error (bfd_error_system_call);
      errno = err;
      errno = err;
      return NULL;
      return NULL;
    }
    }
 
 
  /* Now check to see if we have a valid ELF file, and one that BFD can
  /* Now check to see if we have a valid ELF file, and one that BFD can
     make use of.  The magic number must match, the address size ('class')
     make use of.  The magic number must match, the address size ('class')
     and byte-swapping must match our XVEC entry.  */
     and byte-swapping must match our XVEC entry.  */
 
 
  if (! elf_file_p (&x_ehdr)
  if (! elf_file_p (&x_ehdr)
      || x_ehdr.e_ident[EI_VERSION] != EV_CURRENT
      || x_ehdr.e_ident[EI_VERSION] != EV_CURRENT
      || x_ehdr.e_ident[EI_CLASS] != ELFCLASS)
      || x_ehdr.e_ident[EI_CLASS] != ELFCLASS)
    {
    {
      bfd_set_error (bfd_error_wrong_format);
      bfd_set_error (bfd_error_wrong_format);
      return NULL;
      return NULL;
    }
    }
 
 
  /* Check that file's byte order matches xvec's */
  /* Check that file's byte order matches xvec's */
  switch (x_ehdr.e_ident[EI_DATA])
  switch (x_ehdr.e_ident[EI_DATA])
    {
    {
    case ELFDATA2MSB:           /* Big-endian */
    case ELFDATA2MSB:           /* Big-endian */
      if (! bfd_header_big_endian (templ))
      if (! bfd_header_big_endian (templ))
        {
        {
          bfd_set_error (bfd_error_wrong_format);
          bfd_set_error (bfd_error_wrong_format);
          return NULL;
          return NULL;
        }
        }
      break;
      break;
    case ELFDATA2LSB:           /* Little-endian */
    case ELFDATA2LSB:           /* Little-endian */
      if (! bfd_header_little_endian (templ))
      if (! bfd_header_little_endian (templ))
        {
        {
          bfd_set_error (bfd_error_wrong_format);
          bfd_set_error (bfd_error_wrong_format);
          return NULL;
          return NULL;
        }
        }
      break;
      break;
    case ELFDATANONE:           /* No data encoding specified */
    case ELFDATANONE:           /* No data encoding specified */
    default:                    /* Unknown data encoding specified */
    default:                    /* Unknown data encoding specified */
      bfd_set_error (bfd_error_wrong_format);
      bfd_set_error (bfd_error_wrong_format);
      return NULL;
      return NULL;
    }
    }
 
 
  elf_swap_ehdr_in (templ, &x_ehdr, &i_ehdr);
  elf_swap_ehdr_in (templ, &x_ehdr, &i_ehdr);
 
 
  /* The file header tells where to find the program headers.
  /* The file header tells where to find the program headers.
     These are what we use to actually choose what to read.  */
     These are what we use to actually choose what to read.  */
 
 
  if (i_ehdr.e_phentsize != sizeof (Elf_External_Phdr) || i_ehdr.e_phnum == 0)
  if (i_ehdr.e_phentsize != sizeof (Elf_External_Phdr) || i_ehdr.e_phnum == 0)
    {
    {
      bfd_set_error (bfd_error_wrong_format);
      bfd_set_error (bfd_error_wrong_format);
      return NULL;
      return NULL;
    }
    }
 
 
  x_phdrs = (Elf_External_Phdr *)
  x_phdrs = (Elf_External_Phdr *)
      bfd_malloc (i_ehdr.e_phnum * (sizeof *x_phdrs + sizeof *i_phdrs));
      bfd_malloc (i_ehdr.e_phnum * (sizeof *x_phdrs + sizeof *i_phdrs));
  if (x_phdrs == NULL)
  if (x_phdrs == NULL)
    {
    {
      bfd_set_error (bfd_error_no_memory);
      bfd_set_error (bfd_error_no_memory);
      return NULL;
      return NULL;
    }
    }
  err = target_read_memory (ehdr_vma + i_ehdr.e_phoff, (bfd_byte *) x_phdrs,
  err = target_read_memory (ehdr_vma + i_ehdr.e_phoff, (bfd_byte *) x_phdrs,
                            i_ehdr.e_phnum * sizeof x_phdrs[0]);
                            i_ehdr.e_phnum * sizeof x_phdrs[0]);
  if (err)
  if (err)
    {
    {
      free (x_phdrs);
      free (x_phdrs);
      bfd_set_error (bfd_error_system_call);
      bfd_set_error (bfd_error_system_call);
      errno = err;
      errno = err;
      return NULL;
      return NULL;
    }
    }
  i_phdrs = (Elf_Internal_Phdr *) &x_phdrs[i_ehdr.e_phnum];
  i_phdrs = (Elf_Internal_Phdr *) &x_phdrs[i_ehdr.e_phnum];
 
 
  contents_size = 0;
  contents_size = 0;
  last_phdr = NULL;
  last_phdr = NULL;
  loadbase = ehdr_vma;
  loadbase = ehdr_vma;
  loadbase_set = FALSE;
  loadbase_set = FALSE;
  for (i = 0; i < i_ehdr.e_phnum; ++i)
  for (i = 0; i < i_ehdr.e_phnum; ++i)
    {
    {
      elf_swap_phdr_in (templ, &x_phdrs[i], &i_phdrs[i]);
      elf_swap_phdr_in (templ, &x_phdrs[i], &i_phdrs[i]);
      if (i_phdrs[i].p_type == PT_LOAD)
      if (i_phdrs[i].p_type == PT_LOAD)
        {
        {
          bfd_vma segment_end;
          bfd_vma segment_end;
          segment_end = (i_phdrs[i].p_offset + i_phdrs[i].p_filesz
          segment_end = (i_phdrs[i].p_offset + i_phdrs[i].p_filesz
                         + i_phdrs[i].p_align - 1) & -i_phdrs[i].p_align;
                         + i_phdrs[i].p_align - 1) & -i_phdrs[i].p_align;
          if (segment_end > (bfd_vma) contents_size)
          if (segment_end > (bfd_vma) contents_size)
            contents_size = segment_end;
            contents_size = segment_end;
 
 
          /* LOADADDR is the `Base address' from the gELF specification:
          /* LOADADDR is the `Base address' from the gELF specification:
             `lowest p_vaddr value for a PT_LOAD segment' is P_VADDR from the
             `lowest p_vaddr value for a PT_LOAD segment' is P_VADDR from the
             first PT_LOAD as PT_LOADs are ordered by P_VADDR.  */
             first PT_LOAD as PT_LOADs are ordered by P_VADDR.  */
          if (!loadbase_set && (i_phdrs[i].p_offset & -i_phdrs[i].p_align) == 0)
          if (!loadbase_set && (i_phdrs[i].p_offset & -i_phdrs[i].p_align) == 0)
            {
            {
              loadbase = ehdr_vma - (i_phdrs[i].p_vaddr & -i_phdrs[i].p_align);
              loadbase = ehdr_vma - (i_phdrs[i].p_vaddr & -i_phdrs[i].p_align);
              loadbase_set = TRUE;
              loadbase_set = TRUE;
            }
            }
 
 
          last_phdr = &i_phdrs[i];
          last_phdr = &i_phdrs[i];
        }
        }
    }
    }
  if (last_phdr == NULL)
  if (last_phdr == NULL)
    {
    {
      /* There were no PT_LOAD segments, so we don't have anything to read.  */
      /* There were no PT_LOAD segments, so we don't have anything to read.  */
      free (x_phdrs);
      free (x_phdrs);
      bfd_set_error (bfd_error_wrong_format);
      bfd_set_error (bfd_error_wrong_format);
      return NULL;
      return NULL;
    }
    }
 
 
  /* Trim the last segment so we don't bother with zeros in the last page
  /* Trim the last segment so we don't bother with zeros in the last page
     that are off the end of the file.  However, if the extra bit in that
     that are off the end of the file.  However, if the extra bit in that
     page includes the section headers, keep them.  */
     page includes the section headers, keep them.  */
  if ((bfd_vma) contents_size > last_phdr->p_offset + last_phdr->p_filesz
  if ((bfd_vma) contents_size > last_phdr->p_offset + last_phdr->p_filesz
      && (bfd_vma) contents_size >= (i_ehdr.e_shoff
      && (bfd_vma) contents_size >= (i_ehdr.e_shoff
                                     + i_ehdr.e_shnum * i_ehdr.e_shentsize))
                                     + i_ehdr.e_shnum * i_ehdr.e_shentsize))
    {
    {
      contents_size = last_phdr->p_offset + last_phdr->p_filesz;
      contents_size = last_phdr->p_offset + last_phdr->p_filesz;
      if ((bfd_vma) contents_size < (i_ehdr.e_shoff
      if ((bfd_vma) contents_size < (i_ehdr.e_shoff
                                     + i_ehdr.e_shnum * i_ehdr.e_shentsize))
                                     + i_ehdr.e_shnum * i_ehdr.e_shentsize))
        contents_size = i_ehdr.e_shoff + i_ehdr.e_shnum * i_ehdr.e_shentsize;
        contents_size = i_ehdr.e_shoff + i_ehdr.e_shnum * i_ehdr.e_shentsize;
    }
    }
  else
  else
    contents_size = last_phdr->p_offset + last_phdr->p_filesz;
    contents_size = last_phdr->p_offset + last_phdr->p_filesz;
 
 
  /* Now we know the size of the whole image we want read in.  */
  /* Now we know the size of the whole image we want read in.  */
  contents = (bfd_byte *) bfd_zmalloc (contents_size);
  contents = (bfd_byte *) bfd_zmalloc (contents_size);
  if (contents == NULL)
  if (contents == NULL)
    {
    {
      free (x_phdrs);
      free (x_phdrs);
      bfd_set_error (bfd_error_no_memory);
      bfd_set_error (bfd_error_no_memory);
      return NULL;
      return NULL;
    }
    }
 
 
  for (i = 0; i < i_ehdr.e_phnum; ++i)
  for (i = 0; i < i_ehdr.e_phnum; ++i)
    if (i_phdrs[i].p_type == PT_LOAD)
    if (i_phdrs[i].p_type == PT_LOAD)
      {
      {
        bfd_vma start = i_phdrs[i].p_offset & -i_phdrs[i].p_align;
        bfd_vma start = i_phdrs[i].p_offset & -i_phdrs[i].p_align;
        bfd_vma end = (i_phdrs[i].p_offset + i_phdrs[i].p_filesz
        bfd_vma end = (i_phdrs[i].p_offset + i_phdrs[i].p_filesz
                       + i_phdrs[i].p_align - 1) & -i_phdrs[i].p_align;
                       + i_phdrs[i].p_align - 1) & -i_phdrs[i].p_align;
        if (end > (bfd_vma) contents_size)
        if (end > (bfd_vma) contents_size)
          end = contents_size;
          end = contents_size;
        err = target_read_memory ((loadbase + i_phdrs[i].p_vaddr)
        err = target_read_memory ((loadbase + i_phdrs[i].p_vaddr)
                                  & -i_phdrs[i].p_align,
                                  & -i_phdrs[i].p_align,
                                  contents + start, end - start);
                                  contents + start, end - start);
        if (err)
        if (err)
          {
          {
            free (x_phdrs);
            free (x_phdrs);
            free (contents);
            free (contents);
            bfd_set_error (bfd_error_system_call);
            bfd_set_error (bfd_error_system_call);
            errno = err;
            errno = err;
            return NULL;
            return NULL;
          }
          }
      }
      }
  free (x_phdrs);
  free (x_phdrs);
 
 
  /* If the segments visible in memory didn't include the section headers,
  /* If the segments visible in memory didn't include the section headers,
     then clear them from the file header.  */
     then clear them from the file header.  */
  if ((bfd_vma) contents_size < (i_ehdr.e_shoff
  if ((bfd_vma) contents_size < (i_ehdr.e_shoff
                                 + i_ehdr.e_shnum * i_ehdr.e_shentsize))
                                 + i_ehdr.e_shnum * i_ehdr.e_shentsize))
    {
    {
      memset (&x_ehdr.e_shoff, 0, sizeof x_ehdr.e_shoff);
      memset (&x_ehdr.e_shoff, 0, sizeof x_ehdr.e_shoff);
      memset (&x_ehdr.e_shnum, 0, sizeof x_ehdr.e_shnum);
      memset (&x_ehdr.e_shnum, 0, sizeof x_ehdr.e_shnum);
      memset (&x_ehdr.e_shstrndx, 0, sizeof x_ehdr.e_shstrndx);
      memset (&x_ehdr.e_shstrndx, 0, sizeof x_ehdr.e_shstrndx);
    }
    }
 
 
  /* This will normally have been in the first PT_LOAD segment.  But it
  /* This will normally have been in the first PT_LOAD segment.  But it
     conceivably could be missing, and we might have just changed it.  */
     conceivably could be missing, and we might have just changed it.  */
  memcpy (contents, &x_ehdr, sizeof x_ehdr);
  memcpy (contents, &x_ehdr, sizeof x_ehdr);
 
 
  /* Now we have a memory image of the ELF file contents.  Make a BFD.  */
  /* Now we have a memory image of the ELF file contents.  Make a BFD.  */
  bim = (struct bfd_in_memory *) bfd_malloc (sizeof (struct bfd_in_memory));
  bim = (struct bfd_in_memory *) bfd_malloc (sizeof (struct bfd_in_memory));
  if (bim == NULL)
  if (bim == NULL)
    {
    {
      free (contents);
      free (contents);
      bfd_set_error (bfd_error_no_memory);
      bfd_set_error (bfd_error_no_memory);
      return NULL;
      return NULL;
    }
    }
  nbfd = _bfd_new_bfd ();
  nbfd = _bfd_new_bfd ();
  if (nbfd == NULL)
  if (nbfd == NULL)
    {
    {
      free (bim);
      free (bim);
      free (contents);
      free (contents);
      bfd_set_error (bfd_error_no_memory);
      bfd_set_error (bfd_error_no_memory);
      return NULL;
      return NULL;
    }
    }
  nbfd->filename = "<in-memory>";
  nbfd->filename = "<in-memory>";
  nbfd->xvec = templ->xvec;
  nbfd->xvec = templ->xvec;
  bim->size = contents_size;
  bim->size = contents_size;
  bim->buffer = contents;
  bim->buffer = contents;
  nbfd->iostream = bim;
  nbfd->iostream = bim;
  nbfd->flags = BFD_IN_MEMORY;
  nbfd->flags = BFD_IN_MEMORY;
  nbfd->iovec = &_bfd_memory_iovec;
  nbfd->iovec = &_bfd_memory_iovec;
  nbfd->origin = 0;
  nbfd->origin = 0;
  nbfd->direction = read_direction;
  nbfd->direction = read_direction;
  nbfd->mtime = time (NULL);
  nbfd->mtime = time (NULL);
  nbfd->mtime_set = TRUE;
  nbfd->mtime_set = TRUE;
 
 
  if (loadbasep)
  if (loadbasep)
    *loadbasep = loadbase;
    *loadbasep = loadbase;
  return nbfd;
  return nbfd;
}
}
 
 
/* Function for ELF_R_INFO.  */
/* Function for ELF_R_INFO.  */
 
 
bfd_vma
bfd_vma
NAME(elf,r_info) (bfd_vma sym, bfd_vma type)
NAME(elf,r_info) (bfd_vma sym, bfd_vma type)
{
{
  return ELF_R_INFO (sym, type);
  return ELF_R_INFO (sym, type);
}
}
 
 
/* Function for ELF_R_SYM.  */
/* Function for ELF_R_SYM.  */
 
 
bfd_vma
bfd_vma
NAME(elf,r_sym) (bfd_vma r_info)
NAME(elf,r_sym) (bfd_vma r_info)
{
{
  return ELF_R_SYM (r_info);
  return ELF_R_SYM (r_info);
}
}


#include "elfcore.h"
#include "elfcore.h"


/* Size-dependent data and functions.  */
/* Size-dependent data and functions.  */
const struct elf_size_info NAME(_bfd_elf,size_info) = {
const struct elf_size_info NAME(_bfd_elf,size_info) = {
  sizeof (Elf_External_Ehdr),
  sizeof (Elf_External_Ehdr),
  sizeof (Elf_External_Phdr),
  sizeof (Elf_External_Phdr),
  sizeof (Elf_External_Shdr),
  sizeof (Elf_External_Shdr),
  sizeof (Elf_External_Rel),
  sizeof (Elf_External_Rel),
  sizeof (Elf_External_Rela),
  sizeof (Elf_External_Rela),
  sizeof (Elf_External_Sym),
  sizeof (Elf_External_Sym),
  sizeof (Elf_External_Dyn),
  sizeof (Elf_External_Dyn),
  sizeof (Elf_External_Note),
  sizeof (Elf_External_Note),
  4,
  4,
  1,
  1,
  ARCH_SIZE, LOG_FILE_ALIGN,
  ARCH_SIZE, LOG_FILE_ALIGN,
  ELFCLASS, EV_CURRENT,
  ELFCLASS, EV_CURRENT,
  elf_write_out_phdrs,
  elf_write_out_phdrs,
  elf_write_shdrs_and_ehdr,
  elf_write_shdrs_and_ehdr,
  elf_checksum_contents,
  elf_checksum_contents,
  elf_write_relocs,
  elf_write_relocs,
  elf_swap_symbol_in,
  elf_swap_symbol_in,
  elf_swap_symbol_out,
  elf_swap_symbol_out,
  elf_slurp_reloc_table,
  elf_slurp_reloc_table,
  elf_slurp_symbol_table,
  elf_slurp_symbol_table,
  elf_swap_dyn_in,
  elf_swap_dyn_in,
  elf_swap_dyn_out,
  elf_swap_dyn_out,
  elf_swap_reloc_in,
  elf_swap_reloc_in,
  elf_swap_reloc_out,
  elf_swap_reloc_out,
  elf_swap_reloca_in,
  elf_swap_reloca_in,
  elf_swap_reloca_out
  elf_swap_reloca_out
};
};
 
 

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.