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

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [gnu-old/] [gdb-7.1/] [bfd/] [sunos.c] - Diff between revs 834 and 842

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

Rev 834 Rev 842
/* BFD backend for SunOS binaries.
/* BFD backend for SunOS binaries.
   Copyright 1990, 1991, 1992, 1994, 1995, 1996, 1997, 1998, 1999, 2000,
   Copyright 1990, 1991, 1992, 1994, 1995, 1996, 1997, 1998, 1999, 2000,
   2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008
   2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008
   Free Software Foundation, Inc.
   Free Software Foundation, Inc.
   Written by Cygnus Support.
   Written by Cygnus Support.
 
 
   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.  */
 
 
#define TARGETNAME "a.out-sunos-big"
#define TARGETNAME "a.out-sunos-big"
 
 
/* Do not "beautify" the CONCAT* macro args.  Traditional C will not
/* Do not "beautify" the CONCAT* macro args.  Traditional C will not
   remove whitespace added here, and thus will fail to concatenate
   remove whitespace added here, and thus will fail to concatenate
   the tokens.  */
   the tokens.  */
#define MY(OP) CONCAT2 (sunos_big_,OP)
#define MY(OP) CONCAT2 (sunos_big_,OP)
 
 
#include "bfd.h"
#include "bfd.h"
#include "bfdlink.h"
#include "bfdlink.h"
#include "libaout.h"
#include "libaout.h"
 
 
/* ??? Where should this go?  */
/* ??? Where should this go?  */
#define MACHTYPE_OK(mtype) \
#define MACHTYPE_OK(mtype) \
  (((mtype) == M_SPARC && bfd_lookup_arch (bfd_arch_sparc, 0) != NULL) \
  (((mtype) == M_SPARC && bfd_lookup_arch (bfd_arch_sparc, 0) != NULL) \
   || ((mtype) == M_SPARCLET \
   || ((mtype) == M_SPARCLET \
       && bfd_lookup_arch (bfd_arch_sparc, bfd_mach_sparc_sparclet) != NULL) \
       && bfd_lookup_arch (bfd_arch_sparc, bfd_mach_sparc_sparclet) != NULL) \
   || ((mtype) == M_SPARCLITE_LE \
   || ((mtype) == M_SPARCLITE_LE \
       && bfd_lookup_arch (bfd_arch_sparc, bfd_mach_sparc_sparclet) != NULL) \
       && bfd_lookup_arch (bfd_arch_sparc, bfd_mach_sparc_sparclet) != NULL) \
   || (((mtype) == M_UNKNOWN || (mtype) == M_68010 || (mtype) == M_68020) \
   || (((mtype) == M_UNKNOWN || (mtype) == M_68010 || (mtype) == M_68020) \
       && bfd_lookup_arch (bfd_arch_m68k, 0) != NULL))
       && bfd_lookup_arch (bfd_arch_m68k, 0) != NULL))
 
 
#define MY_get_dynamic_symtab_upper_bound  sunos_get_dynamic_symtab_upper_bound
#define MY_get_dynamic_symtab_upper_bound  sunos_get_dynamic_symtab_upper_bound
#define MY_canonicalize_dynamic_symtab     sunos_canonicalize_dynamic_symtab
#define MY_canonicalize_dynamic_symtab     sunos_canonicalize_dynamic_symtab
#define MY_get_synthetic_symtab            _bfd_nodynamic_get_synthetic_symtab
#define MY_get_synthetic_symtab            _bfd_nodynamic_get_synthetic_symtab
#define MY_get_dynamic_reloc_upper_bound   sunos_get_dynamic_reloc_upper_bound
#define MY_get_dynamic_reloc_upper_bound   sunos_get_dynamic_reloc_upper_bound
#define MY_canonicalize_dynamic_reloc      sunos_canonicalize_dynamic_reloc
#define MY_canonicalize_dynamic_reloc      sunos_canonicalize_dynamic_reloc
#define MY_bfd_link_hash_table_create      sunos_link_hash_table_create
#define MY_bfd_link_hash_table_create      sunos_link_hash_table_create
#define MY_add_dynamic_symbols             sunos_add_dynamic_symbols
#define MY_add_dynamic_symbols             sunos_add_dynamic_symbols
#define MY_add_one_symbol                  sunos_add_one_symbol
#define MY_add_one_symbol                  sunos_add_one_symbol
#define MY_link_dynamic_object             sunos_link_dynamic_object
#define MY_link_dynamic_object             sunos_link_dynamic_object
#define MY_write_dynamic_symbol            sunos_write_dynamic_symbol
#define MY_write_dynamic_symbol            sunos_write_dynamic_symbol
#define MY_check_dynamic_reloc             sunos_check_dynamic_reloc
#define MY_check_dynamic_reloc             sunos_check_dynamic_reloc
#define MY_finish_dynamic_link             sunos_finish_dynamic_link
#define MY_finish_dynamic_link             sunos_finish_dynamic_link
 
 
static bfd_boolean sunos_add_dynamic_symbols            (bfd *, struct bfd_link_info *, struct external_nlist **, bfd_size_type *, char **);
static bfd_boolean sunos_add_dynamic_symbols            (bfd *, struct bfd_link_info *, struct external_nlist **, bfd_size_type *, char **);
static bfd_boolean sunos_add_one_symbol                 (struct bfd_link_info *, bfd *, const char *, flagword, asection *, bfd_vma, const char *, bfd_boolean, bfd_boolean, struct bfd_link_hash_entry **);
static bfd_boolean sunos_add_one_symbol                 (struct bfd_link_info *, bfd *, const char *, flagword, asection *, bfd_vma, const char *, bfd_boolean, bfd_boolean, struct bfd_link_hash_entry **);
static bfd_boolean sunos_link_dynamic_object            (struct bfd_link_info *, bfd *);
static bfd_boolean sunos_link_dynamic_object            (struct bfd_link_info *, bfd *);
static bfd_boolean sunos_write_dynamic_symbol           (bfd *, struct bfd_link_info *, struct aout_link_hash_entry *);
static bfd_boolean sunos_write_dynamic_symbol           (bfd *, struct bfd_link_info *, struct aout_link_hash_entry *);
static bfd_boolean sunos_check_dynamic_reloc            (struct bfd_link_info *, bfd *, asection *, struct aout_link_hash_entry *, void *, bfd_byte *, bfd_boolean *, bfd_vma *);
static bfd_boolean sunos_check_dynamic_reloc            (struct bfd_link_info *, bfd *, asection *, struct aout_link_hash_entry *, void *, bfd_byte *, bfd_boolean *, bfd_vma *);
static bfd_boolean sunos_finish_dynamic_link            (bfd *, struct bfd_link_info *);
static bfd_boolean sunos_finish_dynamic_link            (bfd *, struct bfd_link_info *);
static struct bfd_link_hash_table *sunos_link_hash_table_create  (bfd *);
static struct bfd_link_hash_table *sunos_link_hash_table_create  (bfd *);
static long        sunos_get_dynamic_symtab_upper_bound (bfd *);
static long        sunos_get_dynamic_symtab_upper_bound (bfd *);
static long        sunos_canonicalize_dynamic_symtab    (bfd *, asymbol **);
static long        sunos_canonicalize_dynamic_symtab    (bfd *, asymbol **);
static long        sunos_get_dynamic_reloc_upper_bound  (bfd *);
static long        sunos_get_dynamic_reloc_upper_bound  (bfd *);
static long        sunos_canonicalize_dynamic_reloc     (bfd *, arelent **, asymbol **);
static long        sunos_canonicalize_dynamic_reloc     (bfd *, arelent **, asymbol **);
 
 
/* Include the usual a.out support.  */
/* Include the usual a.out support.  */
#include "aoutf1.h"
#include "aoutf1.h"
 
 
/* The SunOS 4.1.4 /usr/include/locale.h defines valid as a macro.  */
/* The SunOS 4.1.4 /usr/include/locale.h defines valid as a macro.  */
#undef valid
#undef valid
 
 
/* SunOS shared library support.  We store a pointer to this structure
/* SunOS shared library support.  We store a pointer to this structure
   in obj_aout_dynamic_info (abfd).  */
   in obj_aout_dynamic_info (abfd).  */
 
 
struct sunos_dynamic_info
struct sunos_dynamic_info
{
{
  /* Whether we found any dynamic information.  */
  /* Whether we found any dynamic information.  */
  bfd_boolean valid;
  bfd_boolean valid;
  /* Dynamic information.  */
  /* Dynamic information.  */
  struct internal_sun4_dynamic_link dyninfo;
  struct internal_sun4_dynamic_link dyninfo;
  /* Number of dynamic symbols.  */
  /* Number of dynamic symbols.  */
  unsigned long dynsym_count;
  unsigned long dynsym_count;
  /* Read in nlists for dynamic symbols.  */
  /* Read in nlists for dynamic symbols.  */
  struct external_nlist *dynsym;
  struct external_nlist *dynsym;
  /* asymbol structures for dynamic symbols.  */
  /* asymbol structures for dynamic symbols.  */
  aout_symbol_type *canonical_dynsym;
  aout_symbol_type *canonical_dynsym;
  /* Read in dynamic string table.  */
  /* Read in dynamic string table.  */
  char *dynstr;
  char *dynstr;
  /* Number of dynamic relocs.  */
  /* Number of dynamic relocs.  */
  unsigned long dynrel_count;
  unsigned long dynrel_count;
  /* Read in dynamic relocs.  This may be reloc_std_external or
  /* Read in dynamic relocs.  This may be reloc_std_external or
     reloc_ext_external.  */
     reloc_ext_external.  */
  void * dynrel;
  void * dynrel;
  /* arelent structures for dynamic relocs.  */
  /* arelent structures for dynamic relocs.  */
  arelent *canonical_dynrel;
  arelent *canonical_dynrel;
};
};
 
 
/* The hash table of dynamic symbols is composed of two word entries.
/* The hash table of dynamic symbols is composed of two word entries.
   See include/aout/sun4.h for details.  */
   See include/aout/sun4.h for details.  */
 
 
#define HASH_ENTRY_SIZE (2 * BYTES_IN_WORD)
#define HASH_ENTRY_SIZE (2 * BYTES_IN_WORD)
 
 
/* Read in the basic dynamic information.  This locates the __DYNAMIC
/* Read in the basic dynamic information.  This locates the __DYNAMIC
   structure and uses it to find the dynamic_link structure.  It
   structure and uses it to find the dynamic_link structure.  It
   creates and saves a sunos_dynamic_info structure.  If it can't find
   creates and saves a sunos_dynamic_info structure.  If it can't find
   __DYNAMIC, it sets the valid field of the sunos_dynamic_info
   __DYNAMIC, it sets the valid field of the sunos_dynamic_info
   structure to FALSE to avoid doing this work again.  */
   structure to FALSE to avoid doing this work again.  */
 
 
static bfd_boolean
static bfd_boolean
sunos_read_dynamic_info (bfd *abfd)
sunos_read_dynamic_info (bfd *abfd)
{
{
  struct sunos_dynamic_info *info;
  struct sunos_dynamic_info *info;
  asection *dynsec;
  asection *dynsec;
  bfd_vma dynoff;
  bfd_vma dynoff;
  struct external_sun4_dynamic dyninfo;
  struct external_sun4_dynamic dyninfo;
  unsigned long dynver;
  unsigned long dynver;
  struct external_sun4_dynamic_link linkinfo;
  struct external_sun4_dynamic_link linkinfo;
  bfd_size_type amt;
  bfd_size_type amt;
 
 
  if (obj_aout_dynamic_info (abfd) != NULL)
  if (obj_aout_dynamic_info (abfd) != NULL)
    return TRUE;
    return TRUE;
 
 
  if ((abfd->flags & DYNAMIC) == 0)
  if ((abfd->flags & DYNAMIC) == 0)
    {
    {
      bfd_set_error (bfd_error_invalid_operation);
      bfd_set_error (bfd_error_invalid_operation);
      return FALSE;
      return FALSE;
    }
    }
 
 
  amt = sizeof (struct sunos_dynamic_info);
  amt = sizeof (struct sunos_dynamic_info);
  info = bfd_zalloc (abfd, amt);
  info = bfd_zalloc (abfd, amt);
  if (!info)
  if (!info)
    return FALSE;
    return FALSE;
  info->valid = FALSE;
  info->valid = FALSE;
  info->dynsym = NULL;
  info->dynsym = NULL;
  info->dynstr = NULL;
  info->dynstr = NULL;
  info->canonical_dynsym = NULL;
  info->canonical_dynsym = NULL;
  info->dynrel = NULL;
  info->dynrel = NULL;
  info->canonical_dynrel = NULL;
  info->canonical_dynrel = NULL;
  obj_aout_dynamic_info (abfd) = (void *) info;
  obj_aout_dynamic_info (abfd) = (void *) info;
 
 
  /* This code used to look for the __DYNAMIC symbol to locate the dynamic
  /* This code used to look for the __DYNAMIC symbol to locate the dynamic
     linking information.
     linking information.
     However this inhibits recovering the dynamic symbols from a
     However this inhibits recovering the dynamic symbols from a
     stripped object file, so blindly assume that the dynamic linking
     stripped object file, so blindly assume that the dynamic linking
     information is located at the start of the data section.
     information is located at the start of the data section.
     We could verify this assumption later by looking through the dynamic
     We could verify this assumption later by looking through the dynamic
     symbols for the __DYNAMIC symbol.  */
     symbols for the __DYNAMIC symbol.  */
  if ((abfd->flags & DYNAMIC) == 0)
  if ((abfd->flags & DYNAMIC) == 0)
    return TRUE;
    return TRUE;
  if (! bfd_get_section_contents (abfd, obj_datasec (abfd), (void *) &dyninfo,
  if (! bfd_get_section_contents (abfd, obj_datasec (abfd), (void *) &dyninfo,
                                  (file_ptr) 0,
                                  (file_ptr) 0,
                                  (bfd_size_type) sizeof dyninfo))
                                  (bfd_size_type) sizeof dyninfo))
    return TRUE;
    return TRUE;
 
 
  dynver = GET_WORD (abfd, dyninfo.ld_version);
  dynver = GET_WORD (abfd, dyninfo.ld_version);
  if (dynver != 2 && dynver != 3)
  if (dynver != 2 && dynver != 3)
    return TRUE;
    return TRUE;
 
 
  dynoff = GET_WORD (abfd, dyninfo.ld);
  dynoff = GET_WORD (abfd, dyninfo.ld);
 
 
  /* dynoff is a virtual address.  It is probably always in the .data
  /* dynoff is a virtual address.  It is probably always in the .data
     section, but this code should work even if it moves.  */
     section, but this code should work even if it moves.  */
  if (dynoff < bfd_get_section_vma (abfd, obj_datasec (abfd)))
  if (dynoff < bfd_get_section_vma (abfd, obj_datasec (abfd)))
    dynsec = obj_textsec (abfd);
    dynsec = obj_textsec (abfd);
  else
  else
    dynsec = obj_datasec (abfd);
    dynsec = obj_datasec (abfd);
  dynoff -= bfd_get_section_vma (abfd, dynsec);
  dynoff -= bfd_get_section_vma (abfd, dynsec);
  if (dynoff > dynsec->size)
  if (dynoff > dynsec->size)
    return TRUE;
    return TRUE;
 
 
  /* This executable appears to be dynamically linked in a way that we
  /* This executable appears to be dynamically linked in a way that we
     can understand.  */
     can understand.  */
  if (! bfd_get_section_contents (abfd, dynsec, (void *) &linkinfo,
  if (! bfd_get_section_contents (abfd, dynsec, (void *) &linkinfo,
                                  (file_ptr) dynoff,
                                  (file_ptr) dynoff,
                                  (bfd_size_type) sizeof linkinfo))
                                  (bfd_size_type) sizeof linkinfo))
    return TRUE;
    return TRUE;
 
 
  /* Swap in the dynamic link information.  */
  /* Swap in the dynamic link information.  */
  info->dyninfo.ld_loaded = GET_WORD (abfd, linkinfo.ld_loaded);
  info->dyninfo.ld_loaded = GET_WORD (abfd, linkinfo.ld_loaded);
  info->dyninfo.ld_need = GET_WORD (abfd, linkinfo.ld_need);
  info->dyninfo.ld_need = GET_WORD (abfd, linkinfo.ld_need);
  info->dyninfo.ld_rules = GET_WORD (abfd, linkinfo.ld_rules);
  info->dyninfo.ld_rules = GET_WORD (abfd, linkinfo.ld_rules);
  info->dyninfo.ld_got = GET_WORD (abfd, linkinfo.ld_got);
  info->dyninfo.ld_got = GET_WORD (abfd, linkinfo.ld_got);
  info->dyninfo.ld_plt = GET_WORD (abfd, linkinfo.ld_plt);
  info->dyninfo.ld_plt = GET_WORD (abfd, linkinfo.ld_plt);
  info->dyninfo.ld_rel = GET_WORD (abfd, linkinfo.ld_rel);
  info->dyninfo.ld_rel = GET_WORD (abfd, linkinfo.ld_rel);
  info->dyninfo.ld_hash = GET_WORD (abfd, linkinfo.ld_hash);
  info->dyninfo.ld_hash = GET_WORD (abfd, linkinfo.ld_hash);
  info->dyninfo.ld_stab = GET_WORD (abfd, linkinfo.ld_stab);
  info->dyninfo.ld_stab = GET_WORD (abfd, linkinfo.ld_stab);
  info->dyninfo.ld_stab_hash = GET_WORD (abfd, linkinfo.ld_stab_hash);
  info->dyninfo.ld_stab_hash = GET_WORD (abfd, linkinfo.ld_stab_hash);
  info->dyninfo.ld_buckets = GET_WORD (abfd, linkinfo.ld_buckets);
  info->dyninfo.ld_buckets = GET_WORD (abfd, linkinfo.ld_buckets);
  info->dyninfo.ld_symbols = GET_WORD (abfd, linkinfo.ld_symbols);
  info->dyninfo.ld_symbols = GET_WORD (abfd, linkinfo.ld_symbols);
  info->dyninfo.ld_symb_size = GET_WORD (abfd, linkinfo.ld_symb_size);
  info->dyninfo.ld_symb_size = GET_WORD (abfd, linkinfo.ld_symb_size);
  info->dyninfo.ld_text = GET_WORD (abfd, linkinfo.ld_text);
  info->dyninfo.ld_text = GET_WORD (abfd, linkinfo.ld_text);
  info->dyninfo.ld_plt_sz = GET_WORD (abfd, linkinfo.ld_plt_sz);
  info->dyninfo.ld_plt_sz = GET_WORD (abfd, linkinfo.ld_plt_sz);
 
 
  /* Reportedly the addresses need to be offset by the size of the
  /* Reportedly the addresses need to be offset by the size of the
     exec header in an NMAGIC file.  */
     exec header in an NMAGIC file.  */
  if (adata (abfd).magic == n_magic)
  if (adata (abfd).magic == n_magic)
    {
    {
      unsigned long exec_bytes_size = adata (abfd).exec_bytes_size;
      unsigned long exec_bytes_size = adata (abfd).exec_bytes_size;
 
 
      info->dyninfo.ld_need += exec_bytes_size;
      info->dyninfo.ld_need += exec_bytes_size;
      info->dyninfo.ld_rules += exec_bytes_size;
      info->dyninfo.ld_rules += exec_bytes_size;
      info->dyninfo.ld_rel += exec_bytes_size;
      info->dyninfo.ld_rel += exec_bytes_size;
      info->dyninfo.ld_hash += exec_bytes_size;
      info->dyninfo.ld_hash += exec_bytes_size;
      info->dyninfo.ld_stab += exec_bytes_size;
      info->dyninfo.ld_stab += exec_bytes_size;
      info->dyninfo.ld_symbols += exec_bytes_size;
      info->dyninfo.ld_symbols += exec_bytes_size;
    }
    }
 
 
  /* The only way to get the size of the symbol information appears to
  /* The only way to get the size of the symbol information appears to
     be to determine the distance between it and the string table.  */
     be to determine the distance between it and the string table.  */
  info->dynsym_count = ((info->dyninfo.ld_symbols - info->dyninfo.ld_stab)
  info->dynsym_count = ((info->dyninfo.ld_symbols - info->dyninfo.ld_stab)
                        / EXTERNAL_NLIST_SIZE);
                        / EXTERNAL_NLIST_SIZE);
  BFD_ASSERT (info->dynsym_count * EXTERNAL_NLIST_SIZE
  BFD_ASSERT (info->dynsym_count * EXTERNAL_NLIST_SIZE
              == (unsigned long) (info->dyninfo.ld_symbols
              == (unsigned long) (info->dyninfo.ld_symbols
                                  - info->dyninfo.ld_stab));
                                  - info->dyninfo.ld_stab));
 
 
  /* Similarly, the relocs end at the hash table.  */
  /* Similarly, the relocs end at the hash table.  */
  info->dynrel_count = ((info->dyninfo.ld_hash - info->dyninfo.ld_rel)
  info->dynrel_count = ((info->dyninfo.ld_hash - info->dyninfo.ld_rel)
                        / obj_reloc_entry_size (abfd));
                        / obj_reloc_entry_size (abfd));
  BFD_ASSERT (info->dynrel_count * obj_reloc_entry_size (abfd)
  BFD_ASSERT (info->dynrel_count * obj_reloc_entry_size (abfd)
              == (unsigned long) (info->dyninfo.ld_hash
              == (unsigned long) (info->dyninfo.ld_hash
                                  - info->dyninfo.ld_rel));
                                  - info->dyninfo.ld_rel));
 
 
  info->valid = TRUE;
  info->valid = TRUE;
 
 
  return TRUE;
  return TRUE;
}
}
 
 
/* Return the amount of memory required for the dynamic symbols.  */
/* Return the amount of memory required for the dynamic symbols.  */
 
 
static long
static long
sunos_get_dynamic_symtab_upper_bound (bfd *abfd)
sunos_get_dynamic_symtab_upper_bound (bfd *abfd)
{
{
  struct sunos_dynamic_info *info;
  struct sunos_dynamic_info *info;
 
 
  if (! sunos_read_dynamic_info (abfd))
  if (! sunos_read_dynamic_info (abfd))
    return -1;
    return -1;
 
 
  info = (struct sunos_dynamic_info *) obj_aout_dynamic_info (abfd);
  info = (struct sunos_dynamic_info *) obj_aout_dynamic_info (abfd);
  if (! info->valid)
  if (! info->valid)
    {
    {
      bfd_set_error (bfd_error_no_symbols);
      bfd_set_error (bfd_error_no_symbols);
      return -1;
      return -1;
    }
    }
 
 
  return (info->dynsym_count + 1) * sizeof (asymbol *);
  return (info->dynsym_count + 1) * sizeof (asymbol *);
}
}
 
 
/* Read the external dynamic symbols.  */
/* Read the external dynamic symbols.  */
 
 
static bfd_boolean
static bfd_boolean
sunos_slurp_dynamic_symtab (bfd *abfd)
sunos_slurp_dynamic_symtab (bfd *abfd)
{
{
  struct sunos_dynamic_info *info;
  struct sunos_dynamic_info *info;
  bfd_size_type amt;
  bfd_size_type amt;
 
 
  /* Get the general dynamic information.  */
  /* Get the general dynamic information.  */
  if (obj_aout_dynamic_info (abfd) == NULL)
  if (obj_aout_dynamic_info (abfd) == NULL)
    {
    {
      if (! sunos_read_dynamic_info (abfd))
      if (! sunos_read_dynamic_info (abfd))
          return FALSE;
          return FALSE;
    }
    }
 
 
  info = (struct sunos_dynamic_info *) obj_aout_dynamic_info (abfd);
  info = (struct sunos_dynamic_info *) obj_aout_dynamic_info (abfd);
  if (! info->valid)
  if (! info->valid)
    {
    {
      bfd_set_error (bfd_error_no_symbols);
      bfd_set_error (bfd_error_no_symbols);
      return FALSE;
      return FALSE;
    }
    }
 
 
  /* Get the dynamic nlist structures.  */
  /* Get the dynamic nlist structures.  */
  if (info->dynsym == NULL)
  if (info->dynsym == NULL)
    {
    {
      amt = (bfd_size_type) info->dynsym_count * EXTERNAL_NLIST_SIZE;
      amt = (bfd_size_type) info->dynsym_count * EXTERNAL_NLIST_SIZE;
      info->dynsym = bfd_alloc (abfd, amt);
      info->dynsym = bfd_alloc (abfd, amt);
      if (info->dynsym == NULL && info->dynsym_count != 0)
      if (info->dynsym == NULL && info->dynsym_count != 0)
        return FALSE;
        return FALSE;
      if (bfd_seek (abfd, (file_ptr) info->dyninfo.ld_stab, SEEK_SET) != 0
      if (bfd_seek (abfd, (file_ptr) info->dyninfo.ld_stab, SEEK_SET) != 0
          || bfd_bread ((void *) info->dynsym, amt, abfd) != amt)
          || bfd_bread ((void *) info->dynsym, amt, abfd) != amt)
        {
        {
          if (info->dynsym != NULL)
          if (info->dynsym != NULL)
            {
            {
              bfd_release (abfd, info->dynsym);
              bfd_release (abfd, info->dynsym);
              info->dynsym = NULL;
              info->dynsym = NULL;
            }
            }
          return FALSE;
          return FALSE;
        }
        }
    }
    }
 
 
  /* Get the dynamic strings.  */
  /* Get the dynamic strings.  */
  if (info->dynstr == NULL)
  if (info->dynstr == NULL)
    {
    {
      amt = info->dyninfo.ld_symb_size;
      amt = info->dyninfo.ld_symb_size;
      info->dynstr = bfd_alloc (abfd, amt);
      info->dynstr = bfd_alloc (abfd, amt);
      if (info->dynstr == NULL && info->dyninfo.ld_symb_size != 0)
      if (info->dynstr == NULL && info->dyninfo.ld_symb_size != 0)
        return FALSE;
        return FALSE;
      if (bfd_seek (abfd, (file_ptr) info->dyninfo.ld_symbols, SEEK_SET) != 0
      if (bfd_seek (abfd, (file_ptr) info->dyninfo.ld_symbols, SEEK_SET) != 0
          || bfd_bread ((void *) info->dynstr, amt, abfd) != amt)
          || bfd_bread ((void *) info->dynstr, amt, abfd) != amt)
        {
        {
          if (info->dynstr != NULL)
          if (info->dynstr != NULL)
            {
            {
              bfd_release (abfd, info->dynstr);
              bfd_release (abfd, info->dynstr);
              info->dynstr = NULL;
              info->dynstr = NULL;
            }
            }
          return FALSE;
          return FALSE;
        }
        }
    }
    }
 
 
  return TRUE;
  return TRUE;
}
}
 
 
/* Read in the dynamic symbols.  */
/* Read in the dynamic symbols.  */
 
 
static long
static long
sunos_canonicalize_dynamic_symtab (bfd *abfd, asymbol **storage)
sunos_canonicalize_dynamic_symtab (bfd *abfd, asymbol **storage)
{
{
  struct sunos_dynamic_info *info;
  struct sunos_dynamic_info *info;
  unsigned long i;
  unsigned long i;
 
 
  if (! sunos_slurp_dynamic_symtab (abfd))
  if (! sunos_slurp_dynamic_symtab (abfd))
    return -1;
    return -1;
 
 
  info = (struct sunos_dynamic_info *) obj_aout_dynamic_info (abfd);
  info = (struct sunos_dynamic_info *) obj_aout_dynamic_info (abfd);
 
 
#ifdef CHECK_DYNAMIC_HASH
#ifdef CHECK_DYNAMIC_HASH
  /* Check my understanding of the dynamic hash table by making sure
  /* Check my understanding of the dynamic hash table by making sure
     that each symbol can be located in the hash table.  */
     that each symbol can be located in the hash table.  */
  {
  {
    bfd_size_type table_size;
    bfd_size_type table_size;
    bfd_byte *table;
    bfd_byte *table;
    bfd_size_type i;
    bfd_size_type i;
 
 
    if (info->dyninfo.ld_buckets > info->dynsym_count)
    if (info->dyninfo.ld_buckets > info->dynsym_count)
      abort ();
      abort ();
    table_size = info->dyninfo.ld_stab - info->dyninfo.ld_hash;
    table_size = info->dyninfo.ld_stab - info->dyninfo.ld_hash;
    table = bfd_malloc (table_size);
    table = bfd_malloc (table_size);
    if (table == NULL && table_size != 0)
    if (table == NULL && table_size != 0)
      abort ();
      abort ();
    if (bfd_seek (abfd, (file_ptr) info->dyninfo.ld_hash, SEEK_SET) != 0
    if (bfd_seek (abfd, (file_ptr) info->dyninfo.ld_hash, SEEK_SET) != 0
        || bfd_bread ((void *) table, table_size, abfd) != table_size)
        || bfd_bread ((void *) table, table_size, abfd) != table_size)
      abort ();
      abort ();
    for (i = 0; i < info->dynsym_count; i++)
    for (i = 0; i < info->dynsym_count; i++)
      {
      {
        unsigned char *name;
        unsigned char *name;
        unsigned long hash;
        unsigned long hash;
 
 
        name = ((unsigned char *) info->dynstr
        name = ((unsigned char *) info->dynstr
                + GET_WORD (abfd, info->dynsym[i].e_strx));
                + GET_WORD (abfd, info->dynsym[i].e_strx));
        hash = 0;
        hash = 0;
        while (*name != '\0')
        while (*name != '\0')
          hash = (hash << 1) + *name++;
          hash = (hash << 1) + *name++;
        hash &= 0x7fffffff;
        hash &= 0x7fffffff;
        hash %= info->dyninfo.ld_buckets;
        hash %= info->dyninfo.ld_buckets;
        while (GET_WORD (abfd, table + hash * HASH_ENTRY_SIZE) != i)
        while (GET_WORD (abfd, table + hash * HASH_ENTRY_SIZE) != i)
          {
          {
            hash = GET_WORD (abfd,
            hash = GET_WORD (abfd,
                             table + hash * HASH_ENTRY_SIZE + BYTES_IN_WORD);
                             table + hash * HASH_ENTRY_SIZE + BYTES_IN_WORD);
            if (hash == 0 || hash >= table_size / HASH_ENTRY_SIZE)
            if (hash == 0 || hash >= table_size / HASH_ENTRY_SIZE)
              abort ();
              abort ();
          }
          }
      }
      }
    free (table);
    free (table);
  }
  }
#endif /* CHECK_DYNAMIC_HASH */
#endif /* CHECK_DYNAMIC_HASH */
 
 
  /* Get the asymbol structures corresponding to the dynamic nlist
  /* Get the asymbol structures corresponding to the dynamic nlist
     structures.  */
     structures.  */
  if (info->canonical_dynsym == NULL)
  if (info->canonical_dynsym == NULL)
    {
    {
      bfd_size_type size;
      bfd_size_type size;
      bfd_size_type strsize = info->dyninfo.ld_symb_size;
      bfd_size_type strsize = info->dyninfo.ld_symb_size;
 
 
      size = (bfd_size_type) info->dynsym_count * sizeof (aout_symbol_type);
      size = (bfd_size_type) info->dynsym_count * sizeof (aout_symbol_type);
      info->canonical_dynsym = bfd_alloc (abfd, size);
      info->canonical_dynsym = bfd_alloc (abfd, size);
      if (info->canonical_dynsym == NULL && info->dynsym_count != 0)
      if (info->canonical_dynsym == NULL && info->dynsym_count != 0)
        return -1;
        return -1;
 
 
      if (! aout_32_translate_symbol_table (abfd, info->canonical_dynsym,
      if (! aout_32_translate_symbol_table (abfd, info->canonical_dynsym,
                                            info->dynsym,
                                            info->dynsym,
                                            (bfd_size_type) info->dynsym_count,
                                            (bfd_size_type) info->dynsym_count,
                                            info->dynstr, strsize, TRUE))
                                            info->dynstr, strsize, TRUE))
        {
        {
          if (info->canonical_dynsym != NULL)
          if (info->canonical_dynsym != NULL)
            {
            {
              bfd_release (abfd, info->canonical_dynsym);
              bfd_release (abfd, info->canonical_dynsym);
              info->canonical_dynsym = NULL;
              info->canonical_dynsym = NULL;
            }
            }
          return -1;
          return -1;
        }
        }
    }
    }
 
 
  /* Return pointers to the dynamic asymbol structures.  */
  /* Return pointers to the dynamic asymbol structures.  */
  for (i = 0; i < info->dynsym_count; i++)
  for (i = 0; i < info->dynsym_count; i++)
    *storage++ = (asymbol *) (info->canonical_dynsym + i);
    *storage++ = (asymbol *) (info->canonical_dynsym + i);
  *storage = NULL;
  *storage = NULL;
 
 
  return info->dynsym_count;
  return info->dynsym_count;
}
}
 
 
/* Return the amount of memory required for the dynamic relocs.  */
/* Return the amount of memory required for the dynamic relocs.  */
 
 
static long
static long
sunos_get_dynamic_reloc_upper_bound (bfd *abfd)
sunos_get_dynamic_reloc_upper_bound (bfd *abfd)
{
{
  struct sunos_dynamic_info *info;
  struct sunos_dynamic_info *info;
 
 
  if (! sunos_read_dynamic_info (abfd))
  if (! sunos_read_dynamic_info (abfd))
    return -1;
    return -1;
 
 
  info = (struct sunos_dynamic_info *) obj_aout_dynamic_info (abfd);
  info = (struct sunos_dynamic_info *) obj_aout_dynamic_info (abfd);
  if (! info->valid)
  if (! info->valid)
    {
    {
      bfd_set_error (bfd_error_no_symbols);
      bfd_set_error (bfd_error_no_symbols);
      return -1;
      return -1;
    }
    }
 
 
  return (info->dynrel_count + 1) * sizeof (arelent *);
  return (info->dynrel_count + 1) * sizeof (arelent *);
}
}
 
 
/* Read in the dynamic relocs.  */
/* Read in the dynamic relocs.  */
 
 
static long
static long
sunos_canonicalize_dynamic_reloc (bfd *abfd, arelent **storage, asymbol **syms)
sunos_canonicalize_dynamic_reloc (bfd *abfd, arelent **storage, asymbol **syms)
{
{
  struct sunos_dynamic_info *info;
  struct sunos_dynamic_info *info;
  unsigned long i;
  unsigned long i;
  bfd_size_type size;
  bfd_size_type size;
 
 
  /* Get the general dynamic information.  */
  /* Get the general dynamic information.  */
  if (obj_aout_dynamic_info (abfd) == NULL)
  if (obj_aout_dynamic_info (abfd) == NULL)
    {
    {
      if (! sunos_read_dynamic_info (abfd))
      if (! sunos_read_dynamic_info (abfd))
        return -1;
        return -1;
    }
    }
 
 
  info = (struct sunos_dynamic_info *) obj_aout_dynamic_info (abfd);
  info = (struct sunos_dynamic_info *) obj_aout_dynamic_info (abfd);
  if (! info->valid)
  if (! info->valid)
    {
    {
      bfd_set_error (bfd_error_no_symbols);
      bfd_set_error (bfd_error_no_symbols);
      return -1;
      return -1;
    }
    }
 
 
  /* Get the dynamic reloc information.  */
  /* Get the dynamic reloc information.  */
  if (info->dynrel == NULL)
  if (info->dynrel == NULL)
    {
    {
      size = (bfd_size_type) info->dynrel_count * obj_reloc_entry_size (abfd);
      size = (bfd_size_type) info->dynrel_count * obj_reloc_entry_size (abfd);
      info->dynrel = bfd_alloc (abfd, size);
      info->dynrel = bfd_alloc (abfd, size);
      if (info->dynrel == NULL && size != 0)
      if (info->dynrel == NULL && size != 0)
        return -1;
        return -1;
      if (bfd_seek (abfd, (file_ptr) info->dyninfo.ld_rel, SEEK_SET) != 0
      if (bfd_seek (abfd, (file_ptr) info->dyninfo.ld_rel, SEEK_SET) != 0
          || bfd_bread ((void *) info->dynrel, size, abfd) != size)
          || bfd_bread ((void *) info->dynrel, size, abfd) != size)
        {
        {
          if (info->dynrel != NULL)
          if (info->dynrel != NULL)
            {
            {
              bfd_release (abfd, info->dynrel);
              bfd_release (abfd, info->dynrel);
              info->dynrel = NULL;
              info->dynrel = NULL;
            }
            }
          return -1;
          return -1;
        }
        }
    }
    }
 
 
  /* Get the arelent structures corresponding to the dynamic reloc
  /* Get the arelent structures corresponding to the dynamic reloc
     information.  */
     information.  */
  if (info->canonical_dynrel == NULL)
  if (info->canonical_dynrel == NULL)
    {
    {
      arelent *to;
      arelent *to;
 
 
      size = (bfd_size_type) info->dynrel_count * sizeof (arelent);
      size = (bfd_size_type) info->dynrel_count * sizeof (arelent);
      info->canonical_dynrel = bfd_alloc (abfd, size);
      info->canonical_dynrel = bfd_alloc (abfd, size);
      if (info->canonical_dynrel == NULL && info->dynrel_count != 0)
      if (info->canonical_dynrel == NULL && info->dynrel_count != 0)
        return -1;
        return -1;
 
 
      to = info->canonical_dynrel;
      to = info->canonical_dynrel;
 
 
      if (obj_reloc_entry_size (abfd) == RELOC_EXT_SIZE)
      if (obj_reloc_entry_size (abfd) == RELOC_EXT_SIZE)
        {
        {
          struct reloc_ext_external *p;
          struct reloc_ext_external *p;
          struct reloc_ext_external *pend;
          struct reloc_ext_external *pend;
 
 
          p = (struct reloc_ext_external *) info->dynrel;
          p = (struct reloc_ext_external *) info->dynrel;
          pend = p + info->dynrel_count;
          pend = p + info->dynrel_count;
          for (; p < pend; p++, to++)
          for (; p < pend; p++, to++)
            NAME (aout, swap_ext_reloc_in) (abfd, p, to, syms,
            NAME (aout, swap_ext_reloc_in) (abfd, p, to, syms,
                                            (bfd_size_type) info->dynsym_count);
                                            (bfd_size_type) info->dynsym_count);
        }
        }
      else
      else
        {
        {
          struct reloc_std_external *p;
          struct reloc_std_external *p;
          struct reloc_std_external *pend;
          struct reloc_std_external *pend;
 
 
          p = (struct reloc_std_external *) info->dynrel;
          p = (struct reloc_std_external *) info->dynrel;
          pend = p + info->dynrel_count;
          pend = p + info->dynrel_count;
          for (; p < pend; p++, to++)
          for (; p < pend; p++, to++)
            NAME (aout, swap_std_reloc_in) (abfd, p, to, syms,
            NAME (aout, swap_std_reloc_in) (abfd, p, to, syms,
                                            (bfd_size_type) info->dynsym_count);
                                            (bfd_size_type) info->dynsym_count);
        }
        }
    }
    }
 
 
  /* Return pointers to the dynamic arelent structures.  */
  /* Return pointers to the dynamic arelent structures.  */
  for (i = 0; i < info->dynrel_count; i++)
  for (i = 0; i < info->dynrel_count; i++)
    *storage++ = info->canonical_dynrel + i;
    *storage++ = info->canonical_dynrel + i;
  *storage = NULL;
  *storage = NULL;
 
 
  return info->dynrel_count;
  return info->dynrel_count;
}
}


/* Code to handle linking of SunOS shared libraries.  */
/* Code to handle linking of SunOS shared libraries.  */
 
 
/* A SPARC procedure linkage table entry is 12 bytes.  The first entry
/* A SPARC procedure linkage table entry is 12 bytes.  The first entry
   in the table is a jump which is filled in by the runtime linker.
   in the table is a jump which is filled in by the runtime linker.
   The remaining entries are branches back to the first entry,
   The remaining entries are branches back to the first entry,
   followed by an index into the relocation table encoded to look like
   followed by an index into the relocation table encoded to look like
   a sethi of %g0.  */
   a sethi of %g0.  */
 
 
#define SPARC_PLT_ENTRY_SIZE (12)
#define SPARC_PLT_ENTRY_SIZE (12)
 
 
static const bfd_byte sparc_plt_first_entry[SPARC_PLT_ENTRY_SIZE] =
static const bfd_byte sparc_plt_first_entry[SPARC_PLT_ENTRY_SIZE] =
{
{
  /* sethi %hi(0),%g1; address filled in by runtime linker.  */
  /* sethi %hi(0),%g1; address filled in by runtime linker.  */
  0x3, 0, 0, 0,
  0x3, 0, 0, 0,
  /* jmp %g1; offset filled in by runtime linker.  */
  /* jmp %g1; offset filled in by runtime linker.  */
  0x81, 0xc0, 0x60, 0,
  0x81, 0xc0, 0x60, 0,
  /* nop */
  /* nop */
  0x1, 0, 0, 0
  0x1, 0, 0, 0
};
};
 
 
/* save %sp, -96, %sp */
/* save %sp, -96, %sp */
#define SPARC_PLT_ENTRY_WORD0 ((bfd_vma) 0x9de3bfa0)
#define SPARC_PLT_ENTRY_WORD0 ((bfd_vma) 0x9de3bfa0)
/* call; address filled in later.  */
/* call; address filled in later.  */
#define SPARC_PLT_ENTRY_WORD1 ((bfd_vma) 0x40000000)
#define SPARC_PLT_ENTRY_WORD1 ((bfd_vma) 0x40000000)
/* sethi; reloc index filled in later.  */
/* sethi; reloc index filled in later.  */
#define SPARC_PLT_ENTRY_WORD2 ((bfd_vma) 0x01000000)
#define SPARC_PLT_ENTRY_WORD2 ((bfd_vma) 0x01000000)
 
 
/* This sequence is used when for the jump table entry to a defined
/* This sequence is used when for the jump table entry to a defined
   symbol in a complete executable.  It is used when linking PIC
   symbol in a complete executable.  It is used when linking PIC
   compiled code which is not being put into a shared library.  */
   compiled code which is not being put into a shared library.  */
/* sethi <address to be filled in later>, %g1 */
/* sethi <address to be filled in later>, %g1 */
#define SPARC_PLT_PIC_WORD0 ((bfd_vma) 0x03000000)
#define SPARC_PLT_PIC_WORD0 ((bfd_vma) 0x03000000)
/* jmp %g1 + <address to be filled in later> */
/* jmp %g1 + <address to be filled in later> */
#define SPARC_PLT_PIC_WORD1 ((bfd_vma) 0x81c06000)
#define SPARC_PLT_PIC_WORD1 ((bfd_vma) 0x81c06000)
/* nop */
/* nop */
#define SPARC_PLT_PIC_WORD2 ((bfd_vma) 0x01000000)
#define SPARC_PLT_PIC_WORD2 ((bfd_vma) 0x01000000)
 
 
/* An m68k procedure linkage table entry is 8 bytes.  The first entry
/* An m68k procedure linkage table entry is 8 bytes.  The first entry
   in the table is a jump which is filled in the by the runtime
   in the table is a jump which is filled in the by the runtime
   linker.  The remaining entries are branches back to the first
   linker.  The remaining entries are branches back to the first
   entry, followed by a two byte index into the relocation table.  */
   entry, followed by a two byte index into the relocation table.  */
 
 
#define M68K_PLT_ENTRY_SIZE (8)
#define M68K_PLT_ENTRY_SIZE (8)
 
 
static const bfd_byte m68k_plt_first_entry[M68K_PLT_ENTRY_SIZE] =
static const bfd_byte m68k_plt_first_entry[M68K_PLT_ENTRY_SIZE] =
{
{
  /* jmps @# */
  /* jmps @# */
  0x4e, 0xf9,
  0x4e, 0xf9,
  /* Filled in by runtime linker with a magic address.  */
  /* Filled in by runtime linker with a magic address.  */
  0, 0, 0, 0,
  0, 0, 0, 0,
  /* Not used?  */
  /* Not used?  */
  0, 0
  0, 0
};
};
 
 
/* bsrl */
/* bsrl */
#define M68K_PLT_ENTRY_WORD0 ((bfd_vma) 0x61ff)
#define M68K_PLT_ENTRY_WORD0 ((bfd_vma) 0x61ff)
/* Remaining words filled in later.  */
/* Remaining words filled in later.  */
 
 
/* An entry in the SunOS linker hash table.  */
/* An entry in the SunOS linker hash table.  */
 
 
struct sunos_link_hash_entry
struct sunos_link_hash_entry
{
{
  struct aout_link_hash_entry root;
  struct aout_link_hash_entry root;
 
 
  /* If this is a dynamic symbol, this is its index into the dynamic
  /* If this is a dynamic symbol, this is its index into the dynamic
     symbol table.  This is initialized to -1.  As the linker looks at
     symbol table.  This is initialized to -1.  As the linker looks at
     the input files, it changes this to -2 if it will be added to the
     the input files, it changes this to -2 if it will be added to the
     dynamic symbol table.  After all the input files have been seen,
     dynamic symbol table.  After all the input files have been seen,
     the linker will know whether to build a dynamic symbol table; if
     the linker will know whether to build a dynamic symbol table; if
     it does build one, this becomes the index into the table.  */
     it does build one, this becomes the index into the table.  */
  long dynindx;
  long dynindx;
 
 
  /* If this is a dynamic symbol, this is the index of the name in the
  /* If this is a dynamic symbol, this is the index of the name in the
     dynamic symbol string table.  */
     dynamic symbol string table.  */
  long dynstr_index;
  long dynstr_index;
 
 
  /* The offset into the global offset table used for this symbol.  If
  /* The offset into the global offset table used for this symbol.  If
     the symbol does not require a GOT entry, this is 0.  */
     the symbol does not require a GOT entry, this is 0.  */
  bfd_vma got_offset;
  bfd_vma got_offset;
 
 
  /* The offset into the procedure linkage table used for this symbol.
  /* The offset into the procedure linkage table used for this symbol.
     If the symbol does not require a PLT entry, this is 0.  */
     If the symbol does not require a PLT entry, this is 0.  */
  bfd_vma plt_offset;
  bfd_vma plt_offset;
 
 
  /* Some linker flags.  */
  /* Some linker flags.  */
  unsigned char flags;
  unsigned char flags;
  /* Symbol is referenced by a regular object.  */
  /* Symbol is referenced by a regular object.  */
#define SUNOS_REF_REGULAR 01
#define SUNOS_REF_REGULAR 01
  /* Symbol is defined by a regular object.  */
  /* Symbol is defined by a regular object.  */
#define SUNOS_DEF_REGULAR 02
#define SUNOS_DEF_REGULAR 02
  /* Symbol is referenced by a dynamic object.  */
  /* Symbol is referenced by a dynamic object.  */
#define SUNOS_REF_DYNAMIC 04
#define SUNOS_REF_DYNAMIC 04
  /* Symbol is defined by a dynamic object.  */
  /* Symbol is defined by a dynamic object.  */
#define SUNOS_DEF_DYNAMIC 010
#define SUNOS_DEF_DYNAMIC 010
  /* Symbol is a constructor symbol in a regular object.  */
  /* Symbol is a constructor symbol in a regular object.  */
#define SUNOS_CONSTRUCTOR 020
#define SUNOS_CONSTRUCTOR 020
};
};
 
 
/* The SunOS linker hash table.  */
/* The SunOS linker hash table.  */
 
 
struct sunos_link_hash_table
struct sunos_link_hash_table
{
{
  struct aout_link_hash_table root;
  struct aout_link_hash_table root;
 
 
  /* The object which holds the dynamic sections.  */
  /* The object which holds the dynamic sections.  */
  bfd *dynobj;
  bfd *dynobj;
 
 
  /* Whether we have created the dynamic sections.  */
  /* Whether we have created the dynamic sections.  */
  bfd_boolean dynamic_sections_created;
  bfd_boolean dynamic_sections_created;
 
 
  /* Whether we need the dynamic sections.  */
  /* Whether we need the dynamic sections.  */
  bfd_boolean dynamic_sections_needed;
  bfd_boolean dynamic_sections_needed;
 
 
  /* Whether we need the .got table.  */
  /* Whether we need the .got table.  */
  bfd_boolean got_needed;
  bfd_boolean got_needed;
 
 
  /* The number of dynamic symbols.  */
  /* The number of dynamic symbols.  */
  size_t dynsymcount;
  size_t dynsymcount;
 
 
  /* The number of buckets in the hash table.  */
  /* The number of buckets in the hash table.  */
  size_t bucketcount;
  size_t bucketcount;
 
 
  /* The list of dynamic objects needed by dynamic objects included in
  /* The list of dynamic objects needed by dynamic objects included in
     the link.  */
     the link.  */
  struct bfd_link_needed_list *needed;
  struct bfd_link_needed_list *needed;
 
 
  /* The offset of __GLOBAL_OFFSET_TABLE_ into the .got section.  */
  /* The offset of __GLOBAL_OFFSET_TABLE_ into the .got section.  */
  bfd_vma got_base;
  bfd_vma got_base;
};
};
 
 
/* Routine to create an entry in an SunOS link hash table.  */
/* Routine to create an entry in an SunOS link hash table.  */
 
 
static struct bfd_hash_entry *
static struct bfd_hash_entry *
sunos_link_hash_newfunc (struct bfd_hash_entry *entry,
sunos_link_hash_newfunc (struct bfd_hash_entry *entry,
                         struct bfd_hash_table *table,
                         struct bfd_hash_table *table,
                         const char *string)
                         const char *string)
{
{
  struct sunos_link_hash_entry *ret = (struct sunos_link_hash_entry *) entry;
  struct sunos_link_hash_entry *ret = (struct sunos_link_hash_entry *) entry;
 
 
  /* Allocate the structure if it has not already been allocated by a
  /* Allocate the structure if it has not already been allocated by a
     subclass.  */
     subclass.  */
  if (ret ==  NULL)
  if (ret ==  NULL)
    ret = bfd_hash_allocate (table, sizeof (* ret));
    ret = bfd_hash_allocate (table, sizeof (* ret));
  if (ret == NULL)
  if (ret == NULL)
    return NULL;
    return NULL;
 
 
  /* Call the allocation method of the superclass.  */
  /* Call the allocation method of the superclass.  */
  ret = ((struct sunos_link_hash_entry *)
  ret = ((struct sunos_link_hash_entry *)
         NAME (aout, link_hash_newfunc) ((struct bfd_hash_entry *) ret,
         NAME (aout, link_hash_newfunc) ((struct bfd_hash_entry *) ret,
                                         table, string));
                                         table, string));
  if (ret != NULL)
  if (ret != NULL)
    {
    {
      /* Set local fields.  */
      /* Set local fields.  */
      ret->dynindx = -1;
      ret->dynindx = -1;
      ret->dynstr_index = -1;
      ret->dynstr_index = -1;
      ret->got_offset = 0;
      ret->got_offset = 0;
      ret->plt_offset = 0;
      ret->plt_offset = 0;
      ret->flags = 0;
      ret->flags = 0;
    }
    }
 
 
  return (struct bfd_hash_entry *) ret;
  return (struct bfd_hash_entry *) ret;
}
}
 
 
/* Create a SunOS link hash table.  */
/* Create a SunOS link hash table.  */
 
 
static struct bfd_link_hash_table *
static struct bfd_link_hash_table *
sunos_link_hash_table_create (bfd *abfd)
sunos_link_hash_table_create (bfd *abfd)
{
{
  struct sunos_link_hash_table *ret;
  struct sunos_link_hash_table *ret;
  bfd_size_type amt = sizeof (struct sunos_link_hash_table);
  bfd_size_type amt = sizeof (struct sunos_link_hash_table);
 
 
  ret = bfd_malloc (amt);
  ret = bfd_malloc (amt);
  if (ret ==  NULL)
  if (ret ==  NULL)
    return NULL;
    return NULL;
  if (!NAME (aout, link_hash_table_init) (&ret->root, abfd,
  if (!NAME (aout, link_hash_table_init) (&ret->root, abfd,
                                          sunos_link_hash_newfunc,
                                          sunos_link_hash_newfunc,
                                          sizeof (struct sunos_link_hash_entry)))
                                          sizeof (struct sunos_link_hash_entry)))
    {
    {
      free (ret);
      free (ret);
      return NULL;
      return NULL;
    }
    }
 
 
  ret->dynobj = NULL;
  ret->dynobj = NULL;
  ret->dynamic_sections_created = FALSE;
  ret->dynamic_sections_created = FALSE;
  ret->dynamic_sections_needed = FALSE;
  ret->dynamic_sections_needed = FALSE;
  ret->got_needed = FALSE;
  ret->got_needed = FALSE;
  ret->dynsymcount = 0;
  ret->dynsymcount = 0;
  ret->bucketcount = 0;
  ret->bucketcount = 0;
  ret->needed = NULL;
  ret->needed = NULL;
  ret->got_base = 0;
  ret->got_base = 0;
 
 
  return &ret->root.root;
  return &ret->root.root;
}
}
 
 
/* Look up an entry in an SunOS link hash table.  */
/* Look up an entry in an SunOS link hash table.  */
 
 
#define sunos_link_hash_lookup(table, string, create, copy, follow) \
#define sunos_link_hash_lookup(table, string, create, copy, follow) \
  ((struct sunos_link_hash_entry *) \
  ((struct sunos_link_hash_entry *) \
   aout_link_hash_lookup (&(table)->root, (string), (create), (copy),\
   aout_link_hash_lookup (&(table)->root, (string), (create), (copy),\
                          (follow)))
                          (follow)))
 
 
/* Traverse a SunOS link hash table.  */
/* Traverse a SunOS link hash table.  */
 
 
#define sunos_link_hash_traverse(table, func, info)                     \
#define sunos_link_hash_traverse(table, func, info)                     \
  (aout_link_hash_traverse                                              \
  (aout_link_hash_traverse                                              \
   (&(table)->root,                                                     \
   (&(table)->root,                                                     \
    (bfd_boolean (*) (struct aout_link_hash_entry *, void *)) (func),   \
    (bfd_boolean (*) (struct aout_link_hash_entry *, void *)) (func),   \
    (info)))
    (info)))
 
 
/* Get the SunOS link hash table from the info structure.  This is
/* Get the SunOS link hash table from the info structure.  This is
   just a cast.  */
   just a cast.  */
 
 
#define sunos_hash_table(p) ((struct sunos_link_hash_table *) ((p)->hash))
#define sunos_hash_table(p) ((struct sunos_link_hash_table *) ((p)->hash))
 
 
/* Create the dynamic sections needed if we are linking against a
/* Create the dynamic sections needed if we are linking against a
   dynamic object, or if we are linking PIC compiled code.  ABFD is a
   dynamic object, or if we are linking PIC compiled code.  ABFD is a
   bfd we can attach the dynamic sections to.  The linker script will
   bfd we can attach the dynamic sections to.  The linker script will
   look for these special sections names and put them in the right
   look for these special sections names and put them in the right
   place in the output file.  See include/aout/sun4.h for more details
   place in the output file.  See include/aout/sun4.h for more details
   of the dynamic linking information.  */
   of the dynamic linking information.  */
 
 
static bfd_boolean
static bfd_boolean
sunos_create_dynamic_sections (bfd *abfd,
sunos_create_dynamic_sections (bfd *abfd,
                               struct bfd_link_info *info,
                               struct bfd_link_info *info,
                               bfd_boolean needed)
                               bfd_boolean needed)
{
{
  asection *s;
  asection *s;
 
 
  if (! sunos_hash_table (info)->dynamic_sections_created)
  if (! sunos_hash_table (info)->dynamic_sections_created)
    {
    {
      flagword flags;
      flagword flags;
 
 
      sunos_hash_table (info)->dynobj = abfd;
      sunos_hash_table (info)->dynobj = abfd;
 
 
      flags = (SEC_ALLOC | SEC_LOAD | SEC_HAS_CONTENTS | SEC_IN_MEMORY
      flags = (SEC_ALLOC | SEC_LOAD | SEC_HAS_CONTENTS | SEC_IN_MEMORY
               | SEC_LINKER_CREATED);
               | SEC_LINKER_CREATED);
 
 
      /* The .dynamic section holds the basic dynamic information: the
      /* The .dynamic section holds the basic dynamic information: the
         sun4_dynamic structure, the dynamic debugger information, and
         sun4_dynamic structure, the dynamic debugger information, and
         the sun4_dynamic_link structure.  */
         the sun4_dynamic_link structure.  */
      s = bfd_make_section_with_flags (abfd, ".dynamic", flags);
      s = bfd_make_section_with_flags (abfd, ".dynamic", flags);
      if (s == NULL
      if (s == NULL
          || ! bfd_set_section_alignment (abfd, s, 2))
          || ! bfd_set_section_alignment (abfd, s, 2))
        return FALSE;
        return FALSE;
 
 
      /* The .got section holds the global offset table.  The address
      /* The .got section holds the global offset table.  The address
         is put in the ld_got field.  */
         is put in the ld_got field.  */
      s = bfd_make_section_with_flags (abfd, ".got", flags);
      s = bfd_make_section_with_flags (abfd, ".got", flags);
      if (s == NULL
      if (s == NULL
          || ! bfd_set_section_alignment (abfd, s, 2))
          || ! bfd_set_section_alignment (abfd, s, 2))
        return FALSE;
        return FALSE;
 
 
      /* The .plt section holds the procedure linkage table.  The
      /* The .plt section holds the procedure linkage table.  The
         address is put in the ld_plt field.  */
         address is put in the ld_plt field.  */
      s = bfd_make_section_with_flags (abfd, ".plt", flags | SEC_CODE);
      s = bfd_make_section_with_flags (abfd, ".plt", flags | SEC_CODE);
      if (s == NULL
      if (s == NULL
          || ! bfd_set_section_alignment (abfd, s, 2))
          || ! bfd_set_section_alignment (abfd, s, 2))
        return FALSE;
        return FALSE;
 
 
      /* The .dynrel section holds the dynamic relocs.  The address is
      /* The .dynrel section holds the dynamic relocs.  The address is
         put in the ld_rel field.  */
         put in the ld_rel field.  */
      s = bfd_make_section_with_flags (abfd, ".dynrel", flags | SEC_READONLY);
      s = bfd_make_section_with_flags (abfd, ".dynrel", flags | SEC_READONLY);
      if (s == NULL
      if (s == NULL
          || ! bfd_set_section_alignment (abfd, s, 2))
          || ! bfd_set_section_alignment (abfd, s, 2))
        return FALSE;
        return FALSE;
 
 
      /* The .hash section holds the dynamic hash table.  The address
      /* The .hash section holds the dynamic hash table.  The address
         is put in the ld_hash field.  */
         is put in the ld_hash field.  */
      s = bfd_make_section_with_flags (abfd, ".hash", flags | SEC_READONLY);
      s = bfd_make_section_with_flags (abfd, ".hash", flags | SEC_READONLY);
      if (s == NULL
      if (s == NULL
          || ! bfd_set_section_alignment (abfd, s, 2))
          || ! bfd_set_section_alignment (abfd, s, 2))
        return FALSE;
        return FALSE;
 
 
      /* The .dynsym section holds the dynamic symbols.  The address
      /* The .dynsym section holds the dynamic symbols.  The address
         is put in the ld_stab field.  */
         is put in the ld_stab field.  */
      s = bfd_make_section_with_flags (abfd, ".dynsym", flags | SEC_READONLY);
      s = bfd_make_section_with_flags (abfd, ".dynsym", flags | SEC_READONLY);
      if (s == NULL
      if (s == NULL
          || ! bfd_set_section_alignment (abfd, s, 2))
          || ! bfd_set_section_alignment (abfd, s, 2))
        return FALSE;
        return FALSE;
 
 
      /* The .dynstr section holds the dynamic symbol string table.
      /* The .dynstr section holds the dynamic symbol string table.
         The address is put in the ld_symbols field.  */
         The address is put in the ld_symbols field.  */
      s = bfd_make_section_with_flags (abfd, ".dynstr", flags | SEC_READONLY);
      s = bfd_make_section_with_flags (abfd, ".dynstr", flags | SEC_READONLY);
      if (s == NULL
      if (s == NULL
          || ! bfd_set_section_alignment (abfd, s, 2))
          || ! bfd_set_section_alignment (abfd, s, 2))
        return FALSE;
        return FALSE;
 
 
      sunos_hash_table (info)->dynamic_sections_created = TRUE;
      sunos_hash_table (info)->dynamic_sections_created = TRUE;
    }
    }
 
 
  if ((needed && ! sunos_hash_table (info)->dynamic_sections_needed)
  if ((needed && ! sunos_hash_table (info)->dynamic_sections_needed)
      || info->shared)
      || info->shared)
    {
    {
      bfd *dynobj;
      bfd *dynobj;
 
 
      dynobj = sunos_hash_table (info)->dynobj;
      dynobj = sunos_hash_table (info)->dynobj;
 
 
      s = bfd_get_section_by_name (dynobj, ".got");
      s = bfd_get_section_by_name (dynobj, ".got");
      if (s->size == 0)
      if (s->size == 0)
        s->size = BYTES_IN_WORD;
        s->size = BYTES_IN_WORD;
 
 
      sunos_hash_table (info)->dynamic_sections_needed = TRUE;
      sunos_hash_table (info)->dynamic_sections_needed = TRUE;
      sunos_hash_table (info)->got_needed = TRUE;
      sunos_hash_table (info)->got_needed = TRUE;
    }
    }
 
 
  return TRUE;
  return TRUE;
}
}
 
 
/* Add dynamic symbols during a link.  This is called by the a.out
/* Add dynamic symbols during a link.  This is called by the a.out
   backend linker for each object it encounters.  */
   backend linker for each object it encounters.  */
 
 
static bfd_boolean
static bfd_boolean
sunos_add_dynamic_symbols (bfd *abfd,
sunos_add_dynamic_symbols (bfd *abfd,
                           struct bfd_link_info *info,
                           struct bfd_link_info *info,
                           struct external_nlist **symsp,
                           struct external_nlist **symsp,
                           bfd_size_type *sym_countp,
                           bfd_size_type *sym_countp,
                           char **stringsp)
                           char **stringsp)
{
{
  bfd *dynobj;
  bfd *dynobj;
  struct sunos_dynamic_info *dinfo;
  struct sunos_dynamic_info *dinfo;
  unsigned long need;
  unsigned long need;
 
 
  /* Make sure we have all the required sections.  */
  /* Make sure we have all the required sections.  */
  if (info->output_bfd->xvec == abfd->xvec)
  if (info->output_bfd->xvec == abfd->xvec)
    {
    {
      if (! sunos_create_dynamic_sections (abfd, info,
      if (! sunos_create_dynamic_sections (abfd, info,
                                           ((abfd->flags & DYNAMIC) != 0
                                           ((abfd->flags & DYNAMIC) != 0
                                            && !info->relocatable)))
                                            && !info->relocatable)))
        return FALSE;
        return FALSE;
    }
    }
 
 
  /* There is nothing else to do for a normal object.  */
  /* There is nothing else to do for a normal object.  */
  if ((abfd->flags & DYNAMIC) == 0)
  if ((abfd->flags & DYNAMIC) == 0)
    return TRUE;
    return TRUE;
 
 
  dynobj = sunos_hash_table (info)->dynobj;
  dynobj = sunos_hash_table (info)->dynobj;
 
 
  /* We do not want to include the sections in a dynamic object in the
  /* We do not want to include the sections in a dynamic object in the
     output file.  We hack by simply clobbering the list of sections
     output file.  We hack by simply clobbering the list of sections
     in the BFD.  This could be handled more cleanly by, say, a new
     in the BFD.  This could be handled more cleanly by, say, a new
     section flag; the existing SEC_NEVER_LOAD flag is not the one we
     section flag; the existing SEC_NEVER_LOAD flag is not the one we
     want, because that one still implies that the section takes up
     want, because that one still implies that the section takes up
     space in the output file.  If this is the first object we have
     space in the output file.  If this is the first object we have
     seen, we must preserve the dynamic sections we just created.  */
     seen, we must preserve the dynamic sections we just created.  */
  if (abfd != dynobj)
  if (abfd != dynobj)
    abfd->sections = NULL;
    abfd->sections = NULL;
  else
  else
    {
    {
      asection *s;
      asection *s;
 
 
      for (s = abfd->sections; s != NULL; s = s->next)
      for (s = abfd->sections; s != NULL; s = s->next)
        {
        {
          if ((s->flags & SEC_LINKER_CREATED) == 0)
          if ((s->flags & SEC_LINKER_CREATED) == 0)
            bfd_section_list_remove (abfd, s);
            bfd_section_list_remove (abfd, s);
        }
        }
    }
    }
 
 
  /* The native linker seems to just ignore dynamic objects when -r is
  /* The native linker seems to just ignore dynamic objects when -r is
     used.  */
     used.  */
  if (info->relocatable)
  if (info->relocatable)
    return TRUE;
    return TRUE;
 
 
  /* There's no hope of using a dynamic object which does not exactly
  /* There's no hope of using a dynamic object which does not exactly
     match the format of the output file.  */
     match the format of the output file.  */
  if (info->output_bfd->xvec != abfd->xvec)
  if (info->output_bfd->xvec != abfd->xvec)
    {
    {
      bfd_set_error (bfd_error_invalid_operation);
      bfd_set_error (bfd_error_invalid_operation);
      return FALSE;
      return FALSE;
    }
    }
 
 
  /* Make sure we have a .need and a .rules sections.  These are only
  /* Make sure we have a .need and a .rules sections.  These are only
     needed if there really is a dynamic object in the link, so they
     needed if there really is a dynamic object in the link, so they
     are not added by sunos_create_dynamic_sections.  */
     are not added by sunos_create_dynamic_sections.  */
  if (bfd_get_section_by_name (dynobj, ".need") == NULL)
  if (bfd_get_section_by_name (dynobj, ".need") == NULL)
    {
    {
      /* The .need section holds the list of names of shared objets
      /* The .need section holds the list of names of shared objets
         which must be included at runtime.  The address of this
         which must be included at runtime.  The address of this
         section is put in the ld_need field.  */
         section is put in the ld_need field.  */
      flagword flags = (SEC_ALLOC | SEC_LOAD | SEC_HAS_CONTENTS
      flagword flags = (SEC_ALLOC | SEC_LOAD | SEC_HAS_CONTENTS
                        | SEC_IN_MEMORY | SEC_READONLY);
                        | SEC_IN_MEMORY | SEC_READONLY);
      asection *s = bfd_make_section_with_flags (dynobj, ".need", flags);
      asection *s = bfd_make_section_with_flags (dynobj, ".need", flags);
      if (s == NULL
      if (s == NULL
          || ! bfd_set_section_alignment (dynobj, s, 2))
          || ! bfd_set_section_alignment (dynobj, s, 2))
        return FALSE;
        return FALSE;
    }
    }
 
 
  if (bfd_get_section_by_name (dynobj, ".rules") == NULL)
  if (bfd_get_section_by_name (dynobj, ".rules") == NULL)
    {
    {
      /* The .rules section holds the path to search for shared
      /* The .rules section holds the path to search for shared
         objects.  The address of this section is put in the ld_rules
         objects.  The address of this section is put in the ld_rules
         field.  */
         field.  */
      flagword flags = (SEC_ALLOC | SEC_LOAD | SEC_HAS_CONTENTS
      flagword flags = (SEC_ALLOC | SEC_LOAD | SEC_HAS_CONTENTS
                        | SEC_IN_MEMORY | SEC_READONLY);
                        | SEC_IN_MEMORY | SEC_READONLY);
      asection *s = bfd_make_section_with_flags (dynobj, ".rules", flags);
      asection *s = bfd_make_section_with_flags (dynobj, ".rules", flags);
      if (s == NULL
      if (s == NULL
          || ! bfd_set_section_alignment (dynobj, s, 2))
          || ! bfd_set_section_alignment (dynobj, s, 2))
        return FALSE;
        return FALSE;
    }
    }
 
 
  /* Pick up the dynamic symbols and return them to the caller.  */
  /* Pick up the dynamic symbols and return them to the caller.  */
  if (! sunos_slurp_dynamic_symtab (abfd))
  if (! sunos_slurp_dynamic_symtab (abfd))
    return FALSE;
    return FALSE;
 
 
  dinfo = (struct sunos_dynamic_info *) obj_aout_dynamic_info (abfd);
  dinfo = (struct sunos_dynamic_info *) obj_aout_dynamic_info (abfd);
  *symsp = dinfo->dynsym;
  *symsp = dinfo->dynsym;
  *sym_countp = dinfo->dynsym_count;
  *sym_countp = dinfo->dynsym_count;
  *stringsp = dinfo->dynstr;
  *stringsp = dinfo->dynstr;
 
 
  /* Record information about any other objects needed by this one.  */
  /* Record information about any other objects needed by this one.  */
  need = dinfo->dyninfo.ld_need;
  need = dinfo->dyninfo.ld_need;
  while (need != 0)
  while (need != 0)
    {
    {
      bfd_byte buf[16];
      bfd_byte buf[16];
      unsigned long name, flags;
      unsigned long name, flags;
      unsigned short major_vno, minor_vno;
      unsigned short major_vno, minor_vno;
      struct bfd_link_needed_list *needed, **pp;
      struct bfd_link_needed_list *needed, **pp;
      char *namebuf, *p;
      char *namebuf, *p;
      bfd_size_type alc;
      bfd_size_type alc;
      bfd_byte b;
      bfd_byte b;
      char *namecopy;
      char *namecopy;
 
 
      if (bfd_seek (abfd, (file_ptr) need, SEEK_SET) != 0
      if (bfd_seek (abfd, (file_ptr) need, SEEK_SET) != 0
          || bfd_bread (buf, (bfd_size_type) 16, abfd) != 16)
          || bfd_bread (buf, (bfd_size_type) 16, abfd) != 16)
        return FALSE;
        return FALSE;
 
 
      /* For the format of an ld_need entry, see aout/sun4.h.  We
      /* For the format of an ld_need entry, see aout/sun4.h.  We
         should probably define structs for this manipulation.  */
         should probably define structs for this manipulation.  */
      name = bfd_get_32 (abfd, buf);
      name = bfd_get_32 (abfd, buf);
      flags = bfd_get_32 (abfd, buf + 4);
      flags = bfd_get_32 (abfd, buf + 4);
      major_vno = (unsigned short) bfd_get_16 (abfd, buf + 8);
      major_vno = (unsigned short) bfd_get_16 (abfd, buf + 8);
      minor_vno = (unsigned short) bfd_get_16 (abfd, buf + 10);
      minor_vno = (unsigned short) bfd_get_16 (abfd, buf + 10);
      need = bfd_get_32 (abfd, buf + 12);
      need = bfd_get_32 (abfd, buf + 12);
 
 
      alc = sizeof (struct bfd_link_needed_list);
      alc = sizeof (struct bfd_link_needed_list);
      needed = bfd_alloc (abfd, alc);
      needed = bfd_alloc (abfd, alc);
      if (needed == NULL)
      if (needed == NULL)
        return FALSE;
        return FALSE;
      needed->by = abfd;
      needed->by = abfd;
 
 
      /* We return the name as [-l]name[.maj][.min].  */
      /* We return the name as [-l]name[.maj][.min].  */
      alc = 30;
      alc = 30;
      namebuf = bfd_malloc (alc + 1);
      namebuf = bfd_malloc (alc + 1);
      if (namebuf == NULL)
      if (namebuf == NULL)
        return FALSE;
        return FALSE;
      p = namebuf;
      p = namebuf;
 
 
      if ((flags & 0x80000000) != 0)
      if ((flags & 0x80000000) != 0)
        {
        {
          *p++ = '-';
          *p++ = '-';
          *p++ = 'l';
          *p++ = 'l';
        }
        }
      if (bfd_seek (abfd, (file_ptr) name, SEEK_SET) != 0)
      if (bfd_seek (abfd, (file_ptr) name, SEEK_SET) != 0)
        {
        {
          free (namebuf);
          free (namebuf);
          return FALSE;
          return FALSE;
        }
        }
 
 
      do
      do
        {
        {
          if (bfd_bread (&b, (bfd_size_type) 1, abfd) != 1)
          if (bfd_bread (&b, (bfd_size_type) 1, abfd) != 1)
            {
            {
              free (namebuf);
              free (namebuf);
              return FALSE;
              return FALSE;
            }
            }
 
 
          if ((bfd_size_type) (p - namebuf) >= alc)
          if ((bfd_size_type) (p - namebuf) >= alc)
            {
            {
              char *n;
              char *n;
 
 
              alc *= 2;
              alc *= 2;
              n = bfd_realloc (namebuf, alc + 1);
              n = bfd_realloc (namebuf, alc + 1);
              if (n == NULL)
              if (n == NULL)
                {
                {
                  free (namebuf);
                  free (namebuf);
                  return FALSE;
                  return FALSE;
                }
                }
              p = n + (p - namebuf);
              p = n + (p - namebuf);
              namebuf = n;
              namebuf = n;
            }
            }
 
 
          *p++ = b;
          *p++ = b;
        }
        }
      while (b != '\0');
      while (b != '\0');
 
 
      if (major_vno == 0)
      if (major_vno == 0)
        *p = '\0';
        *p = '\0';
      else
      else
        {
        {
          char majbuf[30];
          char majbuf[30];
          char minbuf[30];
          char minbuf[30];
 
 
          sprintf (majbuf, ".%d", major_vno);
          sprintf (majbuf, ".%d", major_vno);
          if (minor_vno == 0)
          if (minor_vno == 0)
            minbuf[0] = '\0';
            minbuf[0] = '\0';
          else
          else
            sprintf (minbuf, ".%d", minor_vno);
            sprintf (minbuf, ".%d", minor_vno);
 
 
          if ((p - namebuf) + strlen (majbuf) + strlen (minbuf) >= alc)
          if ((p - namebuf) + strlen (majbuf) + strlen (minbuf) >= alc)
            {
            {
              char *n;
              char *n;
 
 
              alc = (p - namebuf) + strlen (majbuf) + strlen (minbuf);
              alc = (p - namebuf) + strlen (majbuf) + strlen (minbuf);
              n = bfd_realloc (namebuf, alc + 1);
              n = bfd_realloc (namebuf, alc + 1);
              if (n == NULL)
              if (n == NULL)
                {
                {
                  free (namebuf);
                  free (namebuf);
                  return FALSE;
                  return FALSE;
                }
                }
              p = n + (p - namebuf);
              p = n + (p - namebuf);
              namebuf = n;
              namebuf = n;
            }
            }
 
 
          strcpy (p, majbuf);
          strcpy (p, majbuf);
          strcat (p, minbuf);
          strcat (p, minbuf);
        }
        }
 
 
      namecopy = bfd_alloc (abfd, (bfd_size_type) strlen (namebuf) + 1);
      namecopy = bfd_alloc (abfd, (bfd_size_type) strlen (namebuf) + 1);
      if (namecopy == NULL)
      if (namecopy == NULL)
        {
        {
          free (namebuf);
          free (namebuf);
          return FALSE;
          return FALSE;
        }
        }
      strcpy (namecopy, namebuf);
      strcpy (namecopy, namebuf);
      free (namebuf);
      free (namebuf);
      needed->name = namecopy;
      needed->name = namecopy;
 
 
      needed->next = NULL;
      needed->next = NULL;
 
 
      for (pp = &sunos_hash_table (info)->needed;
      for (pp = &sunos_hash_table (info)->needed;
           *pp != NULL;
           *pp != NULL;
           pp = &(*pp)->next)
           pp = &(*pp)->next)
        ;
        ;
      *pp = needed;
      *pp = needed;
    }
    }
 
 
  return TRUE;
  return TRUE;
}
}
 
 
/* Function to add a single symbol to the linker hash table.  This is
/* Function to add a single symbol to the linker hash table.  This is
   a wrapper around _bfd_generic_link_add_one_symbol which handles the
   a wrapper around _bfd_generic_link_add_one_symbol which handles the
   tweaking needed for dynamic linking support.  */
   tweaking needed for dynamic linking support.  */
 
 
static bfd_boolean
static bfd_boolean
sunos_add_one_symbol (struct bfd_link_info *info,
sunos_add_one_symbol (struct bfd_link_info *info,
                      bfd *abfd,
                      bfd *abfd,
                      const char *name,
                      const char *name,
                      flagword flags,
                      flagword flags,
                      asection *section,
                      asection *section,
                      bfd_vma value,
                      bfd_vma value,
                      const char *string,
                      const char *string,
                      bfd_boolean copy,
                      bfd_boolean copy,
                      bfd_boolean collect,
                      bfd_boolean collect,
                      struct bfd_link_hash_entry **hashp)
                      struct bfd_link_hash_entry **hashp)
{
{
  struct sunos_link_hash_entry *h;
  struct sunos_link_hash_entry *h;
  int new_flag;
  int new_flag;
 
 
  if ((flags & (BSF_INDIRECT | BSF_WARNING | BSF_CONSTRUCTOR)) != 0
  if ((flags & (BSF_INDIRECT | BSF_WARNING | BSF_CONSTRUCTOR)) != 0
      || ! bfd_is_und_section (section))
      || ! bfd_is_und_section (section))
    h = sunos_link_hash_lookup (sunos_hash_table (info), name, TRUE, copy,
    h = sunos_link_hash_lookup (sunos_hash_table (info), name, TRUE, copy,
                                FALSE);
                                FALSE);
  else
  else
    h = ((struct sunos_link_hash_entry *)
    h = ((struct sunos_link_hash_entry *)
         bfd_wrapped_link_hash_lookup (abfd, info, name, TRUE, copy, FALSE));
         bfd_wrapped_link_hash_lookup (abfd, info, name, TRUE, copy, FALSE));
  if (h == NULL)
  if (h == NULL)
    return FALSE;
    return FALSE;
 
 
  if (hashp != NULL)
  if (hashp != NULL)
    *hashp = (struct bfd_link_hash_entry *) h;
    *hashp = (struct bfd_link_hash_entry *) h;
 
 
  /* Treat a common symbol in a dynamic object as defined in the .bss
  /* Treat a common symbol in a dynamic object as defined in the .bss
     section of the dynamic object.  We don't want to allocate space
     section of the dynamic object.  We don't want to allocate space
     for it in our process image.  */
     for it in our process image.  */
  if ((abfd->flags & DYNAMIC) != 0
  if ((abfd->flags & DYNAMIC) != 0
      && bfd_is_com_section (section))
      && bfd_is_com_section (section))
    section = obj_bsssec (abfd);
    section = obj_bsssec (abfd);
 
 
  if (! bfd_is_und_section (section)
  if (! bfd_is_und_section (section)
      && h->root.root.type != bfd_link_hash_new
      && h->root.root.type != bfd_link_hash_new
      && h->root.root.type != bfd_link_hash_undefined
      && h->root.root.type != bfd_link_hash_undefined
      && h->root.root.type != bfd_link_hash_defweak)
      && h->root.root.type != bfd_link_hash_defweak)
    {
    {
      /* We are defining the symbol, and it is already defined.  This
      /* We are defining the symbol, and it is already defined.  This
         is a potential multiple definition error.  */
         is a potential multiple definition error.  */
      if ((abfd->flags & DYNAMIC) != 0)
      if ((abfd->flags & DYNAMIC) != 0)
        {
        {
          /* The definition we are adding is from a dynamic object.
          /* The definition we are adding is from a dynamic object.
             We do not want this new definition to override the
             We do not want this new definition to override the
             existing definition, so we pretend it is just a
             existing definition, so we pretend it is just a
             reference.  */
             reference.  */
          section = bfd_und_section_ptr;
          section = bfd_und_section_ptr;
        }
        }
      else if (h->root.root.type == bfd_link_hash_defined
      else if (h->root.root.type == bfd_link_hash_defined
               && h->root.root.u.def.section->owner != NULL
               && h->root.root.u.def.section->owner != NULL
               && (h->root.root.u.def.section->owner->flags & DYNAMIC) != 0)
               && (h->root.root.u.def.section->owner->flags & DYNAMIC) != 0)
        {
        {
          /* The existing definition is from a dynamic object.  We
          /* The existing definition is from a dynamic object.  We
             want to override it with the definition we just found.
             want to override it with the definition we just found.
             Clobber the existing definition.  */
             Clobber the existing definition.  */
          h->root.root.type = bfd_link_hash_undefined;
          h->root.root.type = bfd_link_hash_undefined;
          h->root.root.u.undef.abfd = h->root.root.u.def.section->owner;
          h->root.root.u.undef.abfd = h->root.root.u.def.section->owner;
        }
        }
      else if (h->root.root.type == bfd_link_hash_common
      else if (h->root.root.type == bfd_link_hash_common
               && (h->root.root.u.c.p->section->owner->flags & DYNAMIC) != 0)
               && (h->root.root.u.c.p->section->owner->flags & DYNAMIC) != 0)
        {
        {
          /* The existing definition is from a dynamic object.  We
          /* The existing definition is from a dynamic object.  We
             want to override it with the definition we just found.
             want to override it with the definition we just found.
             Clobber the existing definition.  We can't set it to new,
             Clobber the existing definition.  We can't set it to new,
             because it is on the undefined list.  */
             because it is on the undefined list.  */
          h->root.root.type = bfd_link_hash_undefined;
          h->root.root.type = bfd_link_hash_undefined;
          h->root.root.u.undef.abfd = h->root.root.u.c.p->section->owner;
          h->root.root.u.undef.abfd = h->root.root.u.c.p->section->owner;
        }
        }
    }
    }
 
 
  if ((abfd->flags & DYNAMIC) != 0
  if ((abfd->flags & DYNAMIC) != 0
      && abfd->xvec == info->output_bfd->xvec
      && abfd->xvec == info->output_bfd->xvec
      && (h->flags & SUNOS_CONSTRUCTOR) != 0)
      && (h->flags & SUNOS_CONSTRUCTOR) != 0)
    /* The existing symbol is a constructor symbol, and this symbol
    /* The existing symbol is a constructor symbol, and this symbol
       is from a dynamic object.  A constructor symbol is actually a
       is from a dynamic object.  A constructor symbol is actually a
       definition, although the type will be bfd_link_hash_undefined
       definition, although the type will be bfd_link_hash_undefined
       at this point.  We want to ignore the definition from the
       at this point.  We want to ignore the definition from the
       dynamic object.  */
       dynamic object.  */
    section = bfd_und_section_ptr;
    section = bfd_und_section_ptr;
  else if ((flags & BSF_CONSTRUCTOR) != 0
  else if ((flags & BSF_CONSTRUCTOR) != 0
           && (abfd->flags & DYNAMIC) == 0
           && (abfd->flags & DYNAMIC) == 0
           && h->root.root.type == bfd_link_hash_defined
           && h->root.root.type == bfd_link_hash_defined
           && h->root.root.u.def.section->owner != NULL
           && h->root.root.u.def.section->owner != NULL
           && (h->root.root.u.def.section->owner->flags & DYNAMIC) != 0)
           && (h->root.root.u.def.section->owner->flags & DYNAMIC) != 0)
    /* The existing symbol is defined by a dynamic object, and this
    /* The existing symbol is defined by a dynamic object, and this
       is a constructor symbol.  As above, we want to force the use
       is a constructor symbol.  As above, we want to force the use
       of the constructor symbol from the regular object.  */
       of the constructor symbol from the regular object.  */
    h->root.root.type = bfd_link_hash_new;
    h->root.root.type = bfd_link_hash_new;
 
 
  /* Do the usual procedure for adding a symbol.  */
  /* Do the usual procedure for adding a symbol.  */
  if (! _bfd_generic_link_add_one_symbol (info, abfd, name, flags, section,
  if (! _bfd_generic_link_add_one_symbol (info, abfd, name, flags, section,
                                          value, string, copy, collect,
                                          value, string, copy, collect,
                                          hashp))
                                          hashp))
    return FALSE;
    return FALSE;
 
 
  if (abfd->xvec == info->output_bfd->xvec)
  if (abfd->xvec == info->output_bfd->xvec)
    {
    {
      /* Set a flag in the hash table entry indicating the type of
      /* Set a flag in the hash table entry indicating the type of
         reference or definition we just found.  Keep a count of the
         reference or definition we just found.  Keep a count of the
         number of dynamic symbols we find.  A dynamic symbol is one
         number of dynamic symbols we find.  A dynamic symbol is one
         which is referenced or defined by both a regular object and a
         which is referenced or defined by both a regular object and a
         shared object.  */
         shared object.  */
      if ((abfd->flags & DYNAMIC) == 0)
      if ((abfd->flags & DYNAMIC) == 0)
        {
        {
          if (bfd_is_und_section (section))
          if (bfd_is_und_section (section))
            new_flag = SUNOS_REF_REGULAR;
            new_flag = SUNOS_REF_REGULAR;
          else
          else
            new_flag = SUNOS_DEF_REGULAR;
            new_flag = SUNOS_DEF_REGULAR;
        }
        }
      else
      else
        {
        {
          if (bfd_is_und_section (section))
          if (bfd_is_und_section (section))
            new_flag = SUNOS_REF_DYNAMIC;
            new_flag = SUNOS_REF_DYNAMIC;
          else
          else
            new_flag = SUNOS_DEF_DYNAMIC;
            new_flag = SUNOS_DEF_DYNAMIC;
        }
        }
      h->flags |= new_flag;
      h->flags |= new_flag;
 
 
      if (h->dynindx == -1
      if (h->dynindx == -1
          && (h->flags & (SUNOS_DEF_REGULAR | SUNOS_REF_REGULAR)) != 0)
          && (h->flags & (SUNOS_DEF_REGULAR | SUNOS_REF_REGULAR)) != 0)
        {
        {
          ++sunos_hash_table (info)->dynsymcount;
          ++sunos_hash_table (info)->dynsymcount;
          h->dynindx = -2;
          h->dynindx = -2;
        }
        }
 
 
      if ((flags & BSF_CONSTRUCTOR) != 0
      if ((flags & BSF_CONSTRUCTOR) != 0
          && (abfd->flags & DYNAMIC) == 0)
          && (abfd->flags & DYNAMIC) == 0)
        h->flags |= SUNOS_CONSTRUCTOR;
        h->flags |= SUNOS_CONSTRUCTOR;
    }
    }
 
 
  return TRUE;
  return TRUE;
}
}
 
 
extern const bfd_target MY (vec);
extern const bfd_target MY (vec);
 
 
/* Return the list of objects needed by BFD.  */
/* Return the list of objects needed by BFD.  */
 
 
struct bfd_link_needed_list *
struct bfd_link_needed_list *
bfd_sunos_get_needed_list (bfd *abfd ATTRIBUTE_UNUSED,
bfd_sunos_get_needed_list (bfd *abfd ATTRIBUTE_UNUSED,
                           struct bfd_link_info *info)
                           struct bfd_link_info *info)
{
{
  if (info->output_bfd->xvec != &MY (vec))
  if (info->output_bfd->xvec != &MY (vec))
    return NULL;
    return NULL;
  return sunos_hash_table (info)->needed;
  return sunos_hash_table (info)->needed;
}
}
 
 
/* Record an assignment made to a symbol by a linker script.  We need
/* Record an assignment made to a symbol by a linker script.  We need
   this in case some dynamic object refers to this symbol.  */
   this in case some dynamic object refers to this symbol.  */
 
 
bfd_boolean
bfd_boolean
bfd_sunos_record_link_assignment (bfd *output_bfd,
bfd_sunos_record_link_assignment (bfd *output_bfd,
                                  struct bfd_link_info *info,
                                  struct bfd_link_info *info,
                                  const char *name)
                                  const char *name)
{
{
  struct sunos_link_hash_entry *h;
  struct sunos_link_hash_entry *h;
 
 
  if (output_bfd->xvec != &MY(vec))
  if (output_bfd->xvec != &MY(vec))
    return TRUE;
    return TRUE;
 
 
  /* This is called after we have examined all the input objects.  If
  /* This is called after we have examined all the input objects.  If
     the symbol does not exist, it merely means that no object refers
     the symbol does not exist, it merely means that no object refers
     to it, and we can just ignore it at this point.  */
     to it, and we can just ignore it at this point.  */
  h = sunos_link_hash_lookup (sunos_hash_table (info), name,
  h = sunos_link_hash_lookup (sunos_hash_table (info), name,
                              FALSE, FALSE, FALSE);
                              FALSE, FALSE, FALSE);
  if (h == NULL)
  if (h == NULL)
    return TRUE;
    return TRUE;
 
 
  /* In a shared library, the __DYNAMIC symbol does not appear in the
  /* In a shared library, the __DYNAMIC symbol does not appear in the
     dynamic symbol table.  */
     dynamic symbol table.  */
  if (! info->shared || strcmp (name, "__DYNAMIC") != 0)
  if (! info->shared || strcmp (name, "__DYNAMIC") != 0)
    {
    {
      h->flags |= SUNOS_DEF_REGULAR;
      h->flags |= SUNOS_DEF_REGULAR;
 
 
      if (h->dynindx == -1)
      if (h->dynindx == -1)
        {
        {
          ++sunos_hash_table (info)->dynsymcount;
          ++sunos_hash_table (info)->dynsymcount;
          h->dynindx = -2;
          h->dynindx = -2;
        }
        }
    }
    }
 
 
  return TRUE;
  return TRUE;
}
}
 
 
/* Scan the relocs for an input section using standard relocs.  We
/* Scan the relocs for an input section using standard relocs.  We
   need to figure out what to do for each reloc against a dynamic
   need to figure out what to do for each reloc against a dynamic
   symbol.  If the symbol is in the .text section, an entry is made in
   symbol.  If the symbol is in the .text section, an entry is made in
   the procedure linkage table.  Note that this will do the wrong
   the procedure linkage table.  Note that this will do the wrong
   thing if the symbol is actually data; I don't think the Sun 3
   thing if the symbol is actually data; I don't think the Sun 3
   native linker handles this case correctly either.  If the symbol is
   native linker handles this case correctly either.  If the symbol is
   not in the .text section, we must preserve the reloc as a dynamic
   not in the .text section, we must preserve the reloc as a dynamic
   reloc.  FIXME: We should also handle the PIC relocs here by
   reloc.  FIXME: We should also handle the PIC relocs here by
   building global offset table entries.  */
   building global offset table entries.  */
 
 
static bfd_boolean
static bfd_boolean
sunos_scan_std_relocs (struct bfd_link_info *info,
sunos_scan_std_relocs (struct bfd_link_info *info,
                       bfd *abfd,
                       bfd *abfd,
                       asection *sec ATTRIBUTE_UNUSED,
                       asection *sec ATTRIBUTE_UNUSED,
                       const struct reloc_std_external *relocs,
                       const struct reloc_std_external *relocs,
                       bfd_size_type rel_size)
                       bfd_size_type rel_size)
{
{
  bfd *dynobj;
  bfd *dynobj;
  asection *splt = NULL;
  asection *splt = NULL;
  asection *srel = NULL;
  asection *srel = NULL;
  struct sunos_link_hash_entry **sym_hashes;
  struct sunos_link_hash_entry **sym_hashes;
  const struct reloc_std_external *rel, *relend;
  const struct reloc_std_external *rel, *relend;
 
 
  /* We only know how to handle m68k plt entries.  */
  /* We only know how to handle m68k plt entries.  */
  if (bfd_get_arch (abfd) != bfd_arch_m68k)
  if (bfd_get_arch (abfd) != bfd_arch_m68k)
    {
    {
      bfd_set_error (bfd_error_invalid_target);
      bfd_set_error (bfd_error_invalid_target);
      return FALSE;
      return FALSE;
    }
    }
 
 
  dynobj = NULL;
  dynobj = NULL;
 
 
  sym_hashes = (struct sunos_link_hash_entry **) obj_aout_sym_hashes (abfd);
  sym_hashes = (struct sunos_link_hash_entry **) obj_aout_sym_hashes (abfd);
 
 
  relend = relocs + rel_size / RELOC_STD_SIZE;
  relend = relocs + rel_size / RELOC_STD_SIZE;
  for (rel = relocs; rel < relend; rel++)
  for (rel = relocs; rel < relend; rel++)
    {
    {
      int r_index;
      int r_index;
      struct sunos_link_hash_entry *h;
      struct sunos_link_hash_entry *h;
 
 
      /* We only want relocs against external symbols.  */
      /* We only want relocs against external symbols.  */
      if (bfd_header_big_endian (abfd))
      if (bfd_header_big_endian (abfd))
        {
        {
          if ((rel->r_type[0] & RELOC_STD_BITS_EXTERN_BIG) == 0)
          if ((rel->r_type[0] & RELOC_STD_BITS_EXTERN_BIG) == 0)
            continue;
            continue;
        }
        }
      else
      else
        {
        {
          if ((rel->r_type[0] & RELOC_STD_BITS_EXTERN_LITTLE) == 0)
          if ((rel->r_type[0] & RELOC_STD_BITS_EXTERN_LITTLE) == 0)
            continue;
            continue;
        }
        }
 
 
      /* Get the symbol index.  */
      /* Get the symbol index.  */
      if (bfd_header_big_endian (abfd))
      if (bfd_header_big_endian (abfd))
        r_index = ((rel->r_index[0] << 16)
        r_index = ((rel->r_index[0] << 16)
                   | (rel->r_index[1] << 8)
                   | (rel->r_index[1] << 8)
                   | rel->r_index[2]);
                   | rel->r_index[2]);
      else
      else
        r_index = ((rel->r_index[2] << 16)
        r_index = ((rel->r_index[2] << 16)
                   | (rel->r_index[1] << 8)
                   | (rel->r_index[1] << 8)
                   | rel->r_index[0]);
                   | rel->r_index[0]);
 
 
      /* Get the hash table entry.  */
      /* Get the hash table entry.  */
      h = sym_hashes[r_index];
      h = sym_hashes[r_index];
      if (h == NULL)
      if (h == NULL)
        /* This should not normally happen, but it will in any case
        /* This should not normally happen, but it will in any case
           be caught in the relocation phase.  */
           be caught in the relocation phase.  */
        continue;
        continue;
 
 
      /* At this point common symbols have already been allocated, so
      /* At this point common symbols have already been allocated, so
         we don't have to worry about them.  We need to consider that
         we don't have to worry about them.  We need to consider that
         we may have already seen this symbol and marked it undefined;
         we may have already seen this symbol and marked it undefined;
         if the symbol is really undefined, then SUNOS_DEF_DYNAMIC
         if the symbol is really undefined, then SUNOS_DEF_DYNAMIC
         will be zero.  */
         will be zero.  */
      if (h->root.root.type != bfd_link_hash_defined
      if (h->root.root.type != bfd_link_hash_defined
          && h->root.root.type != bfd_link_hash_defweak
          && h->root.root.type != bfd_link_hash_defweak
          && h->root.root.type != bfd_link_hash_undefined)
          && h->root.root.type != bfd_link_hash_undefined)
        continue;
        continue;
 
 
      if ((h->flags & SUNOS_DEF_DYNAMIC) == 0
      if ((h->flags & SUNOS_DEF_DYNAMIC) == 0
          || (h->flags & SUNOS_DEF_REGULAR) != 0)
          || (h->flags & SUNOS_DEF_REGULAR) != 0)
        continue;
        continue;
 
 
      if (dynobj == NULL)
      if (dynobj == NULL)
        {
        {
          asection *sgot;
          asection *sgot;
 
 
          if (! sunos_create_dynamic_sections (abfd, info, FALSE))
          if (! sunos_create_dynamic_sections (abfd, info, FALSE))
            return FALSE;
            return FALSE;
          dynobj = sunos_hash_table (info)->dynobj;
          dynobj = sunos_hash_table (info)->dynobj;
          splt = bfd_get_section_by_name (dynobj, ".plt");
          splt = bfd_get_section_by_name (dynobj, ".plt");
          srel = bfd_get_section_by_name (dynobj, ".dynrel");
          srel = bfd_get_section_by_name (dynobj, ".dynrel");
          BFD_ASSERT (splt != NULL && srel != NULL);
          BFD_ASSERT (splt != NULL && srel != NULL);
 
 
          sgot = bfd_get_section_by_name (dynobj, ".got");
          sgot = bfd_get_section_by_name (dynobj, ".got");
          BFD_ASSERT (sgot != NULL);
          BFD_ASSERT (sgot != NULL);
          if (sgot->size == 0)
          if (sgot->size == 0)
            sgot->size = BYTES_IN_WORD;
            sgot->size = BYTES_IN_WORD;
          sunos_hash_table (info)->got_needed = TRUE;
          sunos_hash_table (info)->got_needed = TRUE;
        }
        }
 
 
      BFD_ASSERT ((h->flags & SUNOS_REF_REGULAR) != 0);
      BFD_ASSERT ((h->flags & SUNOS_REF_REGULAR) != 0);
      BFD_ASSERT (h->plt_offset != 0
      BFD_ASSERT (h->plt_offset != 0
                  || ((h->root.root.type == bfd_link_hash_defined
                  || ((h->root.root.type == bfd_link_hash_defined
                       || h->root.root.type == bfd_link_hash_defweak)
                       || h->root.root.type == bfd_link_hash_defweak)
                      ? (h->root.root.u.def.section->owner->flags
                      ? (h->root.root.u.def.section->owner->flags
                         & DYNAMIC) != 0
                         & DYNAMIC) != 0
                      : (h->root.root.u.undef.abfd->flags & DYNAMIC) != 0));
                      : (h->root.root.u.undef.abfd->flags & DYNAMIC) != 0));
 
 
      /* This reloc is against a symbol defined only by a dynamic
      /* This reloc is against a symbol defined only by a dynamic
         object.  */
         object.  */
      if (h->root.root.type == bfd_link_hash_undefined)
      if (h->root.root.type == bfd_link_hash_undefined)
        /* Presumably this symbol was marked as being undefined by
        /* Presumably this symbol was marked as being undefined by
           an earlier reloc.  */
           an earlier reloc.  */
        srel->size += RELOC_STD_SIZE;
        srel->size += RELOC_STD_SIZE;
      else if ((h->root.root.u.def.section->flags & SEC_CODE) == 0)
      else if ((h->root.root.u.def.section->flags & SEC_CODE) == 0)
        {
        {
          bfd *sub;
          bfd *sub;
 
 
          /* This reloc is not in the .text section.  It must be
          /* This reloc is not in the .text section.  It must be
             copied into the dynamic relocs.  We mark the symbol as
             copied into the dynamic relocs.  We mark the symbol as
             being undefined.  */
             being undefined.  */
          srel->size += RELOC_STD_SIZE;
          srel->size += RELOC_STD_SIZE;
          sub = h->root.root.u.def.section->owner;
          sub = h->root.root.u.def.section->owner;
          h->root.root.type = bfd_link_hash_undefined;
          h->root.root.type = bfd_link_hash_undefined;
          h->root.root.u.undef.abfd = sub;
          h->root.root.u.undef.abfd = sub;
        }
        }
      else
      else
        {
        {
          /* This symbol is in the .text section.  We must give it an
          /* This symbol is in the .text section.  We must give it an
             entry in the procedure linkage table, if we have not
             entry in the procedure linkage table, if we have not
             already done so.  We change the definition of the symbol
             already done so.  We change the definition of the symbol
             to the .plt section; this will cause relocs against it to
             to the .plt section; this will cause relocs against it to
             be handled correctly.  */
             be handled correctly.  */
          if (h->plt_offset == 0)
          if (h->plt_offset == 0)
            {
            {
              if (splt->size == 0)
              if (splt->size == 0)
                splt->size = M68K_PLT_ENTRY_SIZE;
                splt->size = M68K_PLT_ENTRY_SIZE;
              h->plt_offset = splt->size;
              h->plt_offset = splt->size;
 
 
              if ((h->flags & SUNOS_DEF_REGULAR) == 0)
              if ((h->flags & SUNOS_DEF_REGULAR) == 0)
                {
                {
                  h->root.root.u.def.section = splt;
                  h->root.root.u.def.section = splt;
                  h->root.root.u.def.value = splt->size;
                  h->root.root.u.def.value = splt->size;
                }
                }
 
 
              splt->size += M68K_PLT_ENTRY_SIZE;
              splt->size += M68K_PLT_ENTRY_SIZE;
 
 
              /* We may also need a dynamic reloc entry.  */
              /* We may also need a dynamic reloc entry.  */
              if ((h->flags & SUNOS_DEF_REGULAR) == 0)
              if ((h->flags & SUNOS_DEF_REGULAR) == 0)
                srel->size += RELOC_STD_SIZE;
                srel->size += RELOC_STD_SIZE;
            }
            }
        }
        }
    }
    }
 
 
  return TRUE;
  return TRUE;
}
}
 
 
/* Scan the relocs for an input section using extended relocs.  We
/* Scan the relocs for an input section using extended relocs.  We
   need to figure out what to do for each reloc against a dynamic
   need to figure out what to do for each reloc against a dynamic
   symbol.  If the reloc is a WDISP30, and the symbol is in the .text
   symbol.  If the reloc is a WDISP30, and the symbol is in the .text
   section, an entry is made in the procedure linkage table.
   section, an entry is made in the procedure linkage table.
   Otherwise, we must preserve the reloc as a dynamic reloc.  */
   Otherwise, we must preserve the reloc as a dynamic reloc.  */
 
 
static bfd_boolean
static bfd_boolean
sunos_scan_ext_relocs (struct bfd_link_info *info,
sunos_scan_ext_relocs (struct bfd_link_info *info,
                       bfd *abfd,
                       bfd *abfd,
                       asection *sec ATTRIBUTE_UNUSED,
                       asection *sec ATTRIBUTE_UNUSED,
                       const struct reloc_ext_external *relocs,
                       const struct reloc_ext_external *relocs,
                       bfd_size_type rel_size)
                       bfd_size_type rel_size)
{
{
  bfd *dynobj;
  bfd *dynobj;
  struct sunos_link_hash_entry **sym_hashes;
  struct sunos_link_hash_entry **sym_hashes;
  const struct reloc_ext_external *rel, *relend;
  const struct reloc_ext_external *rel, *relend;
  asection *splt = NULL;
  asection *splt = NULL;
  asection *sgot = NULL;
  asection *sgot = NULL;
  asection *srel = NULL;
  asection *srel = NULL;
  bfd_size_type amt;
  bfd_size_type amt;
 
 
  /* We only know how to handle SPARC plt entries.  */
  /* We only know how to handle SPARC plt entries.  */
  if (bfd_get_arch (abfd) != bfd_arch_sparc)
  if (bfd_get_arch (abfd) != bfd_arch_sparc)
    {
    {
      bfd_set_error (bfd_error_invalid_target);
      bfd_set_error (bfd_error_invalid_target);
      return FALSE;
      return FALSE;
    }
    }
 
 
  dynobj = NULL;
  dynobj = NULL;
 
 
  sym_hashes = (struct sunos_link_hash_entry **) obj_aout_sym_hashes (abfd);
  sym_hashes = (struct sunos_link_hash_entry **) obj_aout_sym_hashes (abfd);
 
 
  relend = relocs + rel_size / RELOC_EXT_SIZE;
  relend = relocs + rel_size / RELOC_EXT_SIZE;
  for (rel = relocs; rel < relend; rel++)
  for (rel = relocs; rel < relend; rel++)
    {
    {
      unsigned int r_index;
      unsigned int r_index;
      int r_extern;
      int r_extern;
      int r_type;
      int r_type;
      struct sunos_link_hash_entry *h = NULL;
      struct sunos_link_hash_entry *h = NULL;
 
 
      /* Swap in the reloc information.  */
      /* Swap in the reloc information.  */
      if (bfd_header_big_endian (abfd))
      if (bfd_header_big_endian (abfd))
        {
        {
          r_index = ((rel->r_index[0] << 16)
          r_index = ((rel->r_index[0] << 16)
                     | (rel->r_index[1] << 8)
                     | (rel->r_index[1] << 8)
                     | rel->r_index[2]);
                     | rel->r_index[2]);
          r_extern = (0 != (rel->r_type[0] & RELOC_EXT_BITS_EXTERN_BIG));
          r_extern = (0 != (rel->r_type[0] & RELOC_EXT_BITS_EXTERN_BIG));
          r_type = ((rel->r_type[0] & RELOC_EXT_BITS_TYPE_BIG)
          r_type = ((rel->r_type[0] & RELOC_EXT_BITS_TYPE_BIG)
                    >> RELOC_EXT_BITS_TYPE_SH_BIG);
                    >> RELOC_EXT_BITS_TYPE_SH_BIG);
        }
        }
      else
      else
        {
        {
          r_index = ((rel->r_index[2] << 16)
          r_index = ((rel->r_index[2] << 16)
                     | (rel->r_index[1] << 8)
                     | (rel->r_index[1] << 8)
                     | rel->r_index[0]);
                     | rel->r_index[0]);
          r_extern = (0 != (rel->r_type[0] & RELOC_EXT_BITS_EXTERN_LITTLE));
          r_extern = (0 != (rel->r_type[0] & RELOC_EXT_BITS_EXTERN_LITTLE));
          r_type = ((rel->r_type[0] & RELOC_EXT_BITS_TYPE_LITTLE)
          r_type = ((rel->r_type[0] & RELOC_EXT_BITS_TYPE_LITTLE)
                    >> RELOC_EXT_BITS_TYPE_SH_LITTLE);
                    >> RELOC_EXT_BITS_TYPE_SH_LITTLE);
        }
        }
 
 
      if (r_extern)
      if (r_extern)
        {
        {
          h = sym_hashes[r_index];
          h = sym_hashes[r_index];
          if (h == NULL)
          if (h == NULL)
            {
            {
              /* This should not normally happen, but it will in any
              /* This should not normally happen, but it will in any
                 case be caught in the relocation phase.  */
                 case be caught in the relocation phase.  */
              continue;
              continue;
            }
            }
        }
        }
 
 
      /* If this is a base relative reloc, we need to make an entry in
      /* If this is a base relative reloc, we need to make an entry in
         the .got section.  */
         the .got section.  */
      if (r_type == RELOC_BASE10
      if (r_type == RELOC_BASE10
          || r_type == RELOC_BASE13
          || r_type == RELOC_BASE13
          || r_type == RELOC_BASE22)
          || r_type == RELOC_BASE22)
        {
        {
          if (dynobj == NULL)
          if (dynobj == NULL)
            {
            {
              if (! sunos_create_dynamic_sections (abfd, info, FALSE))
              if (! sunos_create_dynamic_sections (abfd, info, FALSE))
                return FALSE;
                return FALSE;
              dynobj = sunos_hash_table (info)->dynobj;
              dynobj = sunos_hash_table (info)->dynobj;
              splt = bfd_get_section_by_name (dynobj, ".plt");
              splt = bfd_get_section_by_name (dynobj, ".plt");
              sgot = bfd_get_section_by_name (dynobj, ".got");
              sgot = bfd_get_section_by_name (dynobj, ".got");
              srel = bfd_get_section_by_name (dynobj, ".dynrel");
              srel = bfd_get_section_by_name (dynobj, ".dynrel");
              BFD_ASSERT (splt != NULL && sgot != NULL && srel != NULL);
              BFD_ASSERT (splt != NULL && sgot != NULL && srel != NULL);
 
 
              /* Make sure we have an initial entry in the .got table.  */
              /* Make sure we have an initial entry in the .got table.  */
              if (sgot->size == 0)
              if (sgot->size == 0)
                sgot->size = BYTES_IN_WORD;
                sgot->size = BYTES_IN_WORD;
              sunos_hash_table (info)->got_needed = TRUE;
              sunos_hash_table (info)->got_needed = TRUE;
            }
            }
 
 
          if (r_extern)
          if (r_extern)
            {
            {
              if (h->got_offset != 0)
              if (h->got_offset != 0)
                continue;
                continue;
 
 
              h->got_offset = sgot->size;
              h->got_offset = sgot->size;
            }
            }
          else
          else
            {
            {
              if (r_index >= bfd_get_symcount (abfd))
              if (r_index >= bfd_get_symcount (abfd))
                /* This is abnormal, but should be caught in the
                /* This is abnormal, but should be caught in the
                   relocation phase.  */
                   relocation phase.  */
                continue;
                continue;
 
 
              if (adata (abfd).local_got_offsets == NULL)
              if (adata (abfd).local_got_offsets == NULL)
                {
                {
                  amt = bfd_get_symcount (abfd);
                  amt = bfd_get_symcount (abfd);
                  amt *= sizeof (bfd_vma);
                  amt *= sizeof (bfd_vma);
                  adata (abfd).local_got_offsets = bfd_zalloc (abfd, amt);
                  adata (abfd).local_got_offsets = bfd_zalloc (abfd, amt);
                  if (adata (abfd).local_got_offsets == NULL)
                  if (adata (abfd).local_got_offsets == NULL)
                    return FALSE;
                    return FALSE;
                }
                }
 
 
              if (adata (abfd).local_got_offsets[r_index] != 0)
              if (adata (abfd).local_got_offsets[r_index] != 0)
                continue;
                continue;
 
 
              adata (abfd).local_got_offsets[r_index] = sgot->size;
              adata (abfd).local_got_offsets[r_index] = sgot->size;
            }
            }
 
 
          sgot->size += BYTES_IN_WORD;
          sgot->size += BYTES_IN_WORD;
 
 
          /* If we are making a shared library, or if the symbol is
          /* If we are making a shared library, or if the symbol is
             defined by a dynamic object, we will need a dynamic reloc
             defined by a dynamic object, we will need a dynamic reloc
             entry.  */
             entry.  */
          if (info->shared
          if (info->shared
              || (h != NULL
              || (h != NULL
                  && (h->flags & SUNOS_DEF_DYNAMIC) != 0
                  && (h->flags & SUNOS_DEF_DYNAMIC) != 0
                  && (h->flags & SUNOS_DEF_REGULAR) == 0))
                  && (h->flags & SUNOS_DEF_REGULAR) == 0))
            srel->size += RELOC_EXT_SIZE;
            srel->size += RELOC_EXT_SIZE;
 
 
          continue;
          continue;
        }
        }
 
 
      /* Otherwise, we are only interested in relocs against symbols
      /* Otherwise, we are only interested in relocs against symbols
         defined in dynamic objects but not in regular objects.  We
         defined in dynamic objects but not in regular objects.  We
         only need to consider relocs against external symbols.  */
         only need to consider relocs against external symbols.  */
      if (! r_extern)
      if (! r_extern)
        {
        {
          /* But, if we are creating a shared library, we need to
          /* But, if we are creating a shared library, we need to
             generate an absolute reloc.  */
             generate an absolute reloc.  */
          if (info->shared)
          if (info->shared)
            {
            {
              if (dynobj == NULL)
              if (dynobj == NULL)
                {
                {
                  if (! sunos_create_dynamic_sections (abfd, info, TRUE))
                  if (! sunos_create_dynamic_sections (abfd, info, TRUE))
                    return FALSE;
                    return FALSE;
                  dynobj = sunos_hash_table (info)->dynobj;
                  dynobj = sunos_hash_table (info)->dynobj;
                  splt = bfd_get_section_by_name (dynobj, ".plt");
                  splt = bfd_get_section_by_name (dynobj, ".plt");
                  sgot = bfd_get_section_by_name (dynobj, ".got");
                  sgot = bfd_get_section_by_name (dynobj, ".got");
                  srel = bfd_get_section_by_name (dynobj, ".dynrel");
                  srel = bfd_get_section_by_name (dynobj, ".dynrel");
                  BFD_ASSERT (splt != NULL && sgot != NULL && srel != NULL);
                  BFD_ASSERT (splt != NULL && sgot != NULL && srel != NULL);
                }
                }
 
 
              srel->size += RELOC_EXT_SIZE;
              srel->size += RELOC_EXT_SIZE;
            }
            }
 
 
          continue;
          continue;
        }
        }
 
 
      /* At this point common symbols have already been allocated, so
      /* At this point common symbols have already been allocated, so
         we don't have to worry about them.  We need to consider that
         we don't have to worry about them.  We need to consider that
         we may have already seen this symbol and marked it undefined;
         we may have already seen this symbol and marked it undefined;
         if the symbol is really undefined, then SUNOS_DEF_DYNAMIC
         if the symbol is really undefined, then SUNOS_DEF_DYNAMIC
         will be zero.  */
         will be zero.  */
      if (h->root.root.type != bfd_link_hash_defined
      if (h->root.root.type != bfd_link_hash_defined
          && h->root.root.type != bfd_link_hash_defweak
          && h->root.root.type != bfd_link_hash_defweak
          && h->root.root.type != bfd_link_hash_undefined)
          && h->root.root.type != bfd_link_hash_undefined)
        continue;
        continue;
 
 
      if (r_type != RELOC_JMP_TBL
      if (r_type != RELOC_JMP_TBL
          && ! info->shared
          && ! info->shared
          && ((h->flags & SUNOS_DEF_DYNAMIC) == 0
          && ((h->flags & SUNOS_DEF_DYNAMIC) == 0
              || (h->flags & SUNOS_DEF_REGULAR) != 0))
              || (h->flags & SUNOS_DEF_REGULAR) != 0))
        continue;
        continue;
 
 
      if (r_type == RELOC_JMP_TBL
      if (r_type == RELOC_JMP_TBL
          && ! info->shared
          && ! info->shared
          && (h->flags & SUNOS_DEF_DYNAMIC) == 0
          && (h->flags & SUNOS_DEF_DYNAMIC) == 0
          && (h->flags & SUNOS_DEF_REGULAR) == 0)
          && (h->flags & SUNOS_DEF_REGULAR) == 0)
        {
        {
          /* This symbol is apparently undefined.  Don't do anything
          /* This symbol is apparently undefined.  Don't do anything
             here; just let the relocation routine report an undefined
             here; just let the relocation routine report an undefined
             symbol.  */
             symbol.  */
          continue;
          continue;
        }
        }
 
 
      if (strcmp (h->root.root.root.string, "__GLOBAL_OFFSET_TABLE_") == 0)
      if (strcmp (h->root.root.root.string, "__GLOBAL_OFFSET_TABLE_") == 0)
        continue;
        continue;
 
 
      if (dynobj == NULL)
      if (dynobj == NULL)
        {
        {
          if (! sunos_create_dynamic_sections (abfd, info, FALSE))
          if (! sunos_create_dynamic_sections (abfd, info, FALSE))
            return FALSE;
            return FALSE;
          dynobj = sunos_hash_table (info)->dynobj;
          dynobj = sunos_hash_table (info)->dynobj;
          splt = bfd_get_section_by_name (dynobj, ".plt");
          splt = bfd_get_section_by_name (dynobj, ".plt");
          sgot = bfd_get_section_by_name (dynobj, ".got");
          sgot = bfd_get_section_by_name (dynobj, ".got");
          srel = bfd_get_section_by_name (dynobj, ".dynrel");
          srel = bfd_get_section_by_name (dynobj, ".dynrel");
          BFD_ASSERT (splt != NULL && sgot != NULL && srel != NULL);
          BFD_ASSERT (splt != NULL && sgot != NULL && srel != NULL);
 
 
          /* Make sure we have an initial entry in the .got table.  */
          /* Make sure we have an initial entry in the .got table.  */
          if (sgot->size == 0)
          if (sgot->size == 0)
            sgot->size = BYTES_IN_WORD;
            sgot->size = BYTES_IN_WORD;
          sunos_hash_table (info)->got_needed = TRUE;
          sunos_hash_table (info)->got_needed = TRUE;
        }
        }
 
 
      BFD_ASSERT (r_type == RELOC_JMP_TBL
      BFD_ASSERT (r_type == RELOC_JMP_TBL
                  || info->shared
                  || info->shared
                  || (h->flags & SUNOS_REF_REGULAR) != 0);
                  || (h->flags & SUNOS_REF_REGULAR) != 0);
      BFD_ASSERT (r_type == RELOC_JMP_TBL
      BFD_ASSERT (r_type == RELOC_JMP_TBL
                  || info->shared
                  || info->shared
                  || h->plt_offset != 0
                  || h->plt_offset != 0
                  || ((h->root.root.type == bfd_link_hash_defined
                  || ((h->root.root.type == bfd_link_hash_defined
                       || h->root.root.type == bfd_link_hash_defweak)
                       || h->root.root.type == bfd_link_hash_defweak)
                      ? (h->root.root.u.def.section->owner->flags
                      ? (h->root.root.u.def.section->owner->flags
                         & DYNAMIC) != 0
                         & DYNAMIC) != 0
                      : (h->root.root.u.undef.abfd->flags & DYNAMIC) != 0));
                      : (h->root.root.u.undef.abfd->flags & DYNAMIC) != 0));
 
 
      /* This reloc is against a symbol defined only by a dynamic
      /* This reloc is against a symbol defined only by a dynamic
         object, or it is a jump table reloc from PIC compiled code.  */
         object, or it is a jump table reloc from PIC compiled code.  */
 
 
      if (r_type != RELOC_JMP_TBL
      if (r_type != RELOC_JMP_TBL
          && h->root.root.type == bfd_link_hash_undefined)
          && h->root.root.type == bfd_link_hash_undefined)
        /* Presumably this symbol was marked as being undefined by
        /* Presumably this symbol was marked as being undefined by
           an earlier reloc.  */
           an earlier reloc.  */
        srel->size += RELOC_EXT_SIZE;
        srel->size += RELOC_EXT_SIZE;
 
 
      else if (r_type != RELOC_JMP_TBL
      else if (r_type != RELOC_JMP_TBL
               && (h->root.root.u.def.section->flags & SEC_CODE) == 0)
               && (h->root.root.u.def.section->flags & SEC_CODE) == 0)
        {
        {
          bfd *sub;
          bfd *sub;
 
 
          /* This reloc is not in the .text section.  It must be
          /* This reloc is not in the .text section.  It must be
             copied into the dynamic relocs.  We mark the symbol as
             copied into the dynamic relocs.  We mark the symbol as
             being undefined.  */
             being undefined.  */
          srel->size += RELOC_EXT_SIZE;
          srel->size += RELOC_EXT_SIZE;
          if ((h->flags & SUNOS_DEF_REGULAR) == 0)
          if ((h->flags & SUNOS_DEF_REGULAR) == 0)
            {
            {
              sub = h->root.root.u.def.section->owner;
              sub = h->root.root.u.def.section->owner;
              h->root.root.type = bfd_link_hash_undefined;
              h->root.root.type = bfd_link_hash_undefined;
              h->root.root.u.undef.abfd = sub;
              h->root.root.u.undef.abfd = sub;
            }
            }
        }
        }
      else
      else
        {
        {
          /* This symbol is in the .text section.  We must give it an
          /* This symbol is in the .text section.  We must give it an
             entry in the procedure linkage table, if we have not
             entry in the procedure linkage table, if we have not
             already done so.  We change the definition of the symbol
             already done so.  We change the definition of the symbol
             to the .plt section; this will cause relocs against it to
             to the .plt section; this will cause relocs against it to
             be handled correctly.  */
             be handled correctly.  */
          if (h->plt_offset == 0)
          if (h->plt_offset == 0)
            {
            {
              if (splt->size == 0)
              if (splt->size == 0)
                splt->size = SPARC_PLT_ENTRY_SIZE;
                splt->size = SPARC_PLT_ENTRY_SIZE;
              h->plt_offset = splt->size;
              h->plt_offset = splt->size;
 
 
              if ((h->flags & SUNOS_DEF_REGULAR) == 0)
              if ((h->flags & SUNOS_DEF_REGULAR) == 0)
                {
                {
                  if (h->root.root.type == bfd_link_hash_undefined)
                  if (h->root.root.type == bfd_link_hash_undefined)
                    h->root.root.type = bfd_link_hash_defined;
                    h->root.root.type = bfd_link_hash_defined;
                  h->root.root.u.def.section = splt;
                  h->root.root.u.def.section = splt;
                  h->root.root.u.def.value = splt->size;
                  h->root.root.u.def.value = splt->size;
                }
                }
 
 
              splt->size += SPARC_PLT_ENTRY_SIZE;
              splt->size += SPARC_PLT_ENTRY_SIZE;
 
 
              /* We will also need a dynamic reloc entry, unless this
              /* We will also need a dynamic reloc entry, unless this
                 is a JMP_TBL reloc produced by linking PIC compiled
                 is a JMP_TBL reloc produced by linking PIC compiled
                 code, and we are not making a shared library.  */
                 code, and we are not making a shared library.  */
              if (info->shared || (h->flags & SUNOS_DEF_REGULAR) == 0)
              if (info->shared || (h->flags & SUNOS_DEF_REGULAR) == 0)
                srel->size += RELOC_EXT_SIZE;
                srel->size += RELOC_EXT_SIZE;
            }
            }
 
 
          /* If we are creating a shared library, we need to copy over
          /* If we are creating a shared library, we need to copy over
             any reloc other than a jump table reloc.  */
             any reloc other than a jump table reloc.  */
          if (info->shared && r_type != RELOC_JMP_TBL)
          if (info->shared && r_type != RELOC_JMP_TBL)
            srel->size += RELOC_EXT_SIZE;
            srel->size += RELOC_EXT_SIZE;
        }
        }
    }
    }
 
 
  return TRUE;
  return TRUE;
}
}
 
 
/* Scan the relocs for an input section.  */
/* Scan the relocs for an input section.  */
 
 
static bfd_boolean
static bfd_boolean
sunos_scan_relocs (struct bfd_link_info *info,
sunos_scan_relocs (struct bfd_link_info *info,
                   bfd *abfd,
                   bfd *abfd,
                   asection *sec,
                   asection *sec,
                   bfd_size_type rel_size)
                   bfd_size_type rel_size)
{
{
  void * relocs;
  void * relocs;
  void * free_relocs = NULL;
  void * free_relocs = NULL;
 
 
  if (rel_size == 0)
  if (rel_size == 0)
    return TRUE;
    return TRUE;
 
 
  if (! info->keep_memory)
  if (! info->keep_memory)
    relocs = free_relocs = bfd_malloc (rel_size);
    relocs = free_relocs = bfd_malloc (rel_size);
  else
  else
    {
    {
      struct aout_section_data_struct *n;
      struct aout_section_data_struct *n;
      bfd_size_type amt = sizeof (struct aout_section_data_struct);
      bfd_size_type amt = sizeof (struct aout_section_data_struct);
 
 
      n = bfd_alloc (abfd, amt);
      n = bfd_alloc (abfd, amt);
      if (n == NULL)
      if (n == NULL)
        relocs = NULL;
        relocs = NULL;
      else
      else
        {
        {
          set_aout_section_data (sec, n);
          set_aout_section_data (sec, n);
          relocs = bfd_malloc (rel_size);
          relocs = bfd_malloc (rel_size);
          aout_section_data (sec)->relocs = relocs;
          aout_section_data (sec)->relocs = relocs;
        }
        }
    }
    }
  if (relocs == NULL)
  if (relocs == NULL)
    return FALSE;
    return FALSE;
 
 
  if (bfd_seek (abfd, sec->rel_filepos, SEEK_SET) != 0
  if (bfd_seek (abfd, sec->rel_filepos, SEEK_SET) != 0
      || bfd_bread (relocs, rel_size, abfd) != rel_size)
      || bfd_bread (relocs, rel_size, abfd) != rel_size)
    goto error_return;
    goto error_return;
 
 
  if (obj_reloc_entry_size (abfd) == RELOC_STD_SIZE)
  if (obj_reloc_entry_size (abfd) == RELOC_STD_SIZE)
    {
    {
      if (! sunos_scan_std_relocs (info, abfd, sec,
      if (! sunos_scan_std_relocs (info, abfd, sec,
                                   (struct reloc_std_external *) relocs,
                                   (struct reloc_std_external *) relocs,
                                   rel_size))
                                   rel_size))
        goto error_return;
        goto error_return;
    }
    }
  else
  else
    {
    {
      if (! sunos_scan_ext_relocs (info, abfd, sec,
      if (! sunos_scan_ext_relocs (info, abfd, sec,
                                   (struct reloc_ext_external *) relocs,
                                   (struct reloc_ext_external *) relocs,
                                   rel_size))
                                   rel_size))
        goto error_return;
        goto error_return;
    }
    }
 
 
  if (free_relocs != NULL)
  if (free_relocs != NULL)
    free (free_relocs);
    free (free_relocs);
 
 
  return TRUE;
  return TRUE;
 
 
 error_return:
 error_return:
  if (free_relocs != NULL)
  if (free_relocs != NULL)
    free (free_relocs);
    free (free_relocs);
  return FALSE;
  return FALSE;
}
}
 
 
/* Build the hash table of dynamic symbols, and to mark as written all
/* Build the hash table of dynamic symbols, and to mark as written all
   symbols from dynamic objects which we do not plan to write out.  */
   symbols from dynamic objects which we do not plan to write out.  */
 
 
static bfd_boolean
static bfd_boolean
sunos_scan_dynamic_symbol (struct sunos_link_hash_entry *h, void * data)
sunos_scan_dynamic_symbol (struct sunos_link_hash_entry *h, void * data)
{
{
  struct bfd_link_info *info = (struct bfd_link_info *) data;
  struct bfd_link_info *info = (struct bfd_link_info *) data;
 
 
  if (h->root.root.type == bfd_link_hash_warning)
  if (h->root.root.type == bfd_link_hash_warning)
    h = (struct sunos_link_hash_entry *) h->root.root.u.i.link;
    h = (struct sunos_link_hash_entry *) h->root.root.u.i.link;
 
 
  /* Set the written flag for symbols we do not want to write out as
  /* Set the written flag for symbols we do not want to write out as
     part of the regular symbol table.  This is all symbols which are
     part of the regular symbol table.  This is all symbols which are
     not defined in a regular object file.  For some reason symbols
     not defined in a regular object file.  For some reason symbols
     which are referenced by a regular object and defined by a dynamic
     which are referenced by a regular object and defined by a dynamic
     object do not seem to show up in the regular symbol table.  It is
     object do not seem to show up in the regular symbol table.  It is
     possible for a symbol to have only SUNOS_REF_REGULAR set here, it
     possible for a symbol to have only SUNOS_REF_REGULAR set here, it
     is an undefined symbol which was turned into a common symbol
     is an undefined symbol which was turned into a common symbol
     because it was found in an archive object which was not included
     because it was found in an archive object which was not included
     in the link.  */
     in the link.  */
  if ((h->flags & SUNOS_DEF_REGULAR) == 0
  if ((h->flags & SUNOS_DEF_REGULAR) == 0
      && (h->flags & SUNOS_DEF_DYNAMIC) != 0
      && (h->flags & SUNOS_DEF_DYNAMIC) != 0
      && strcmp (h->root.root.root.string, "__DYNAMIC") != 0)
      && strcmp (h->root.root.root.string, "__DYNAMIC") != 0)
    h->root.written = TRUE;
    h->root.written = TRUE;
 
 
  /* If this symbol is defined by a dynamic object and referenced by a
  /* If this symbol is defined by a dynamic object and referenced by a
     regular object, see whether we gave it a reasonable value while
     regular object, see whether we gave it a reasonable value while
     scanning the relocs.  */
     scanning the relocs.  */
  if ((h->flags & SUNOS_DEF_REGULAR) == 0
  if ((h->flags & SUNOS_DEF_REGULAR) == 0
      && (h->flags & SUNOS_DEF_DYNAMIC) != 0
      && (h->flags & SUNOS_DEF_DYNAMIC) != 0
      && (h->flags & SUNOS_REF_REGULAR) != 0)
      && (h->flags & SUNOS_REF_REGULAR) != 0)
    {
    {
      if ((h->root.root.type == bfd_link_hash_defined
      if ((h->root.root.type == bfd_link_hash_defined
           || h->root.root.type == bfd_link_hash_defweak)
           || h->root.root.type == bfd_link_hash_defweak)
          && ((h->root.root.u.def.section->owner->flags & DYNAMIC) != 0)
          && ((h->root.root.u.def.section->owner->flags & DYNAMIC) != 0)
          && h->root.root.u.def.section->output_section == NULL)
          && h->root.root.u.def.section->output_section == NULL)
        {
        {
          bfd *sub;
          bfd *sub;
 
 
          /* This symbol is currently defined in a dynamic section
          /* This symbol is currently defined in a dynamic section
             which is not being put into the output file.  This
             which is not being put into the output file.  This
             implies that there is no reloc against the symbol.  I'm
             implies that there is no reloc against the symbol.  I'm
             not sure why this case would ever occur.  In any case, we
             not sure why this case would ever occur.  In any case, we
             change the symbol to be undefined.  */
             change the symbol to be undefined.  */
          sub = h->root.root.u.def.section->owner;
          sub = h->root.root.u.def.section->owner;
          h->root.root.type = bfd_link_hash_undefined;
          h->root.root.type = bfd_link_hash_undefined;
          h->root.root.u.undef.abfd = sub;
          h->root.root.u.undef.abfd = sub;
        }
        }
    }
    }
 
 
  /* If this symbol is defined or referenced by a regular file, add it
  /* If this symbol is defined or referenced by a regular file, add it
     to the dynamic symbols.  */
     to the dynamic symbols.  */
  if ((h->flags & (SUNOS_DEF_REGULAR | SUNOS_REF_REGULAR)) != 0)
  if ((h->flags & (SUNOS_DEF_REGULAR | SUNOS_REF_REGULAR)) != 0)
    {
    {
      asection *s;
      asection *s;
      size_t len;
      size_t len;
      bfd_byte *contents;
      bfd_byte *contents;
      unsigned char *name;
      unsigned char *name;
      unsigned long hash;
      unsigned long hash;
      bfd *dynobj;
      bfd *dynobj;
 
 
      BFD_ASSERT (h->dynindx == -2);
      BFD_ASSERT (h->dynindx == -2);
 
 
      dynobj = sunos_hash_table (info)->dynobj;
      dynobj = sunos_hash_table (info)->dynobj;
 
 
      h->dynindx = sunos_hash_table (info)->dynsymcount;
      h->dynindx = sunos_hash_table (info)->dynsymcount;
      ++sunos_hash_table (info)->dynsymcount;
      ++sunos_hash_table (info)->dynsymcount;
 
 
      len = strlen (h->root.root.root.string);
      len = strlen (h->root.root.root.string);
 
 
      /* We don't bother to construct a BFD hash table for the strings
      /* We don't bother to construct a BFD hash table for the strings
         which are the names of the dynamic symbols.  Using a hash
         which are the names of the dynamic symbols.  Using a hash
         table for the regular symbols is beneficial, because the
         table for the regular symbols is beneficial, because the
         regular symbols includes the debugging symbols, which have
         regular symbols includes the debugging symbols, which have
         long names and are often duplicated in several object files.
         long names and are often duplicated in several object files.
         There are no debugging symbols in the dynamic symbols.  */
         There are no debugging symbols in the dynamic symbols.  */
      s = bfd_get_section_by_name (dynobj, ".dynstr");
      s = bfd_get_section_by_name (dynobj, ".dynstr");
      BFD_ASSERT (s != NULL);
      BFD_ASSERT (s != NULL);
      contents = bfd_realloc (s->contents, s->size + len + 1);
      contents = bfd_realloc (s->contents, s->size + len + 1);
      if (contents == NULL)
      if (contents == NULL)
        return FALSE;
        return FALSE;
      s->contents = contents;
      s->contents = contents;
 
 
      h->dynstr_index = s->size;
      h->dynstr_index = s->size;
      strcpy ((char *) contents + s->size, h->root.root.root.string);
      strcpy ((char *) contents + s->size, h->root.root.root.string);
      s->size += len + 1;
      s->size += len + 1;
 
 
      /* Add it to the dynamic hash table.  */
      /* Add it to the dynamic hash table.  */
      name = (unsigned char *) h->root.root.root.string;
      name = (unsigned char *) h->root.root.root.string;
      hash = 0;
      hash = 0;
      while (*name != '\0')
      while (*name != '\0')
        hash = (hash << 1) + *name++;
        hash = (hash << 1) + *name++;
      hash &= 0x7fffffff;
      hash &= 0x7fffffff;
      hash %= sunos_hash_table (info)->bucketcount;
      hash %= sunos_hash_table (info)->bucketcount;
 
 
      s = bfd_get_section_by_name (dynobj, ".hash");
      s = bfd_get_section_by_name (dynobj, ".hash");
      BFD_ASSERT (s != NULL);
      BFD_ASSERT (s != NULL);
 
 
      if (GET_SWORD (dynobj, s->contents + hash * HASH_ENTRY_SIZE) == -1)
      if (GET_SWORD (dynobj, s->contents + hash * HASH_ENTRY_SIZE) == -1)
        PUT_WORD (dynobj, h->dynindx, s->contents + hash * HASH_ENTRY_SIZE);
        PUT_WORD (dynobj, h->dynindx, s->contents + hash * HASH_ENTRY_SIZE);
      else
      else
        {
        {
          bfd_vma next;
          bfd_vma next;
 
 
          next = GET_WORD (dynobj,
          next = GET_WORD (dynobj,
                           (s->contents
                           (s->contents
                            + hash * HASH_ENTRY_SIZE
                            + hash * HASH_ENTRY_SIZE
                            + BYTES_IN_WORD));
                            + BYTES_IN_WORD));
          PUT_WORD (dynobj, s->size / HASH_ENTRY_SIZE,
          PUT_WORD (dynobj, s->size / HASH_ENTRY_SIZE,
                    s->contents + hash * HASH_ENTRY_SIZE + BYTES_IN_WORD);
                    s->contents + hash * HASH_ENTRY_SIZE + BYTES_IN_WORD);
          PUT_WORD (dynobj, h->dynindx, s->contents + s->size);
          PUT_WORD (dynobj, h->dynindx, s->contents + s->size);
          PUT_WORD (dynobj, next, s->contents + s->size + BYTES_IN_WORD);
          PUT_WORD (dynobj, next, s->contents + s->size + BYTES_IN_WORD);
          s->size += HASH_ENTRY_SIZE;
          s->size += HASH_ENTRY_SIZE;
        }
        }
    }
    }
 
 
  return TRUE;
  return TRUE;
}
}
 
 
/* Set up the sizes and contents of the dynamic sections created in
/* Set up the sizes and contents of the dynamic sections created in
   sunos_add_dynamic_symbols.  This is called by the SunOS linker
   sunos_add_dynamic_symbols.  This is called by the SunOS linker
   emulation before_allocation routine.  We must set the sizes of the
   emulation before_allocation routine.  We must set the sizes of the
   sections before the linker sets the addresses of the various
   sections before the linker sets the addresses of the various
   sections.  This unfortunately requires reading all the relocs so
   sections.  This unfortunately requires reading all the relocs so
   that we can work out which ones need to become dynamic relocs.  If
   that we can work out which ones need to become dynamic relocs.  If
   info->keep_memory is TRUE, we keep the relocs in memory; otherwise,
   info->keep_memory is TRUE, we keep the relocs in memory; otherwise,
   we discard them, and will read them again later.  */
   we discard them, and will read them again later.  */
 
 
bfd_boolean
bfd_boolean
bfd_sunos_size_dynamic_sections (bfd *output_bfd,
bfd_sunos_size_dynamic_sections (bfd *output_bfd,
                                 struct bfd_link_info *info,
                                 struct bfd_link_info *info,
                                 asection **sdynptr,
                                 asection **sdynptr,
                                 asection **sneedptr,
                                 asection **sneedptr,
                                 asection **srulesptr)
                                 asection **srulesptr)
{
{
  bfd *dynobj;
  bfd *dynobj;
  bfd_size_type dynsymcount;
  bfd_size_type dynsymcount;
  struct sunos_link_hash_entry *h;
  struct sunos_link_hash_entry *h;
  asection *s;
  asection *s;
  size_t bucketcount;
  size_t bucketcount;
  bfd_size_type hashalloc;
  bfd_size_type hashalloc;
  size_t i;
  size_t i;
  bfd *sub;
  bfd *sub;
 
 
  *sdynptr = NULL;
  *sdynptr = NULL;
  *sneedptr = NULL;
  *sneedptr = NULL;
  *srulesptr = NULL;
  *srulesptr = NULL;
 
 
  if (info->relocatable)
  if (info->relocatable)
    return TRUE;
    return TRUE;
 
 
  if (output_bfd->xvec != &MY(vec))
  if (output_bfd->xvec != &MY(vec))
    return TRUE;
    return TRUE;
 
 
  /* Look through all the input BFD's and read their relocs.  It would
  /* Look through all the input BFD's and read their relocs.  It would
     be better if we didn't have to do this, but there is no other way
     be better if we didn't have to do this, but there is no other way
     to determine the number of dynamic relocs we need, and, more
     to determine the number of dynamic relocs we need, and, more
     importantly, there is no other way to know which symbols should
     importantly, there is no other way to know which symbols should
     get an entry in the procedure linkage table.  */
     get an entry in the procedure linkage table.  */
  for (sub = info->input_bfds; sub != NULL; sub = sub->link_next)
  for (sub = info->input_bfds; sub != NULL; sub = sub->link_next)
    {
    {
      if ((sub->flags & DYNAMIC) == 0
      if ((sub->flags & DYNAMIC) == 0
          && sub->xvec == output_bfd->xvec)
          && sub->xvec == output_bfd->xvec)
        {
        {
          if (! sunos_scan_relocs (info, sub, obj_textsec (sub),
          if (! sunos_scan_relocs (info, sub, obj_textsec (sub),
                                   exec_hdr (sub)->a_trsize)
                                   exec_hdr (sub)->a_trsize)
              || ! sunos_scan_relocs (info, sub, obj_datasec (sub),
              || ! sunos_scan_relocs (info, sub, obj_datasec (sub),
                                      exec_hdr (sub)->a_drsize))
                                      exec_hdr (sub)->a_drsize))
            return FALSE;
            return FALSE;
        }
        }
    }
    }
 
 
  dynobj = sunos_hash_table (info)->dynobj;
  dynobj = sunos_hash_table (info)->dynobj;
  dynsymcount = sunos_hash_table (info)->dynsymcount;
  dynsymcount = sunos_hash_table (info)->dynsymcount;
 
 
  /* If there were no dynamic objects in the link, and we don't need
  /* If there were no dynamic objects in the link, and we don't need
     to build a global offset table, there is nothing to do here.  */
     to build a global offset table, there is nothing to do here.  */
  if (! sunos_hash_table (info)->dynamic_sections_needed
  if (! sunos_hash_table (info)->dynamic_sections_needed
      && ! sunos_hash_table (info)->got_needed)
      && ! sunos_hash_table (info)->got_needed)
    return TRUE;
    return TRUE;
 
 
  /* If __GLOBAL_OFFSET_TABLE_ was mentioned, define it.  */
  /* If __GLOBAL_OFFSET_TABLE_ was mentioned, define it.  */
  h = sunos_link_hash_lookup (sunos_hash_table (info),
  h = sunos_link_hash_lookup (sunos_hash_table (info),
                              "__GLOBAL_OFFSET_TABLE_", FALSE, FALSE, FALSE);
                              "__GLOBAL_OFFSET_TABLE_", FALSE, FALSE, FALSE);
  if (h != NULL && (h->flags & SUNOS_REF_REGULAR) != 0)
  if (h != NULL && (h->flags & SUNOS_REF_REGULAR) != 0)
    {
    {
      h->flags |= SUNOS_DEF_REGULAR;
      h->flags |= SUNOS_DEF_REGULAR;
      if (h->dynindx == -1)
      if (h->dynindx == -1)
        {
        {
          ++sunos_hash_table (info)->dynsymcount;
          ++sunos_hash_table (info)->dynsymcount;
          h->dynindx = -2;
          h->dynindx = -2;
        }
        }
      h->root.root.type = bfd_link_hash_defined;
      h->root.root.type = bfd_link_hash_defined;
      h->root.root.u.def.section = bfd_get_section_by_name (dynobj, ".got");
      h->root.root.u.def.section = bfd_get_section_by_name (dynobj, ".got");
 
 
      /* If the .got section is more than 0x1000 bytes, we set
      /* If the .got section is more than 0x1000 bytes, we set
         __GLOBAL_OFFSET_TABLE_ to be 0x1000 bytes into the section,
         __GLOBAL_OFFSET_TABLE_ to be 0x1000 bytes into the section,
         so that 13 bit relocations have a greater chance of working.  */
         so that 13 bit relocations have a greater chance of working.  */
      s = bfd_get_section_by_name (dynobj, ".got");
      s = bfd_get_section_by_name (dynobj, ".got");
      BFD_ASSERT (s != NULL);
      BFD_ASSERT (s != NULL);
      if (s->size >= 0x1000)
      if (s->size >= 0x1000)
        h->root.root.u.def.value = 0x1000;
        h->root.root.u.def.value = 0x1000;
      else
      else
        h->root.root.u.def.value = 0;
        h->root.root.u.def.value = 0;
 
 
      sunos_hash_table (info)->got_base = h->root.root.u.def.value;
      sunos_hash_table (info)->got_base = h->root.root.u.def.value;
    }
    }
 
 
  /* If there are any shared objects in the link, then we need to set
  /* If there are any shared objects in the link, then we need to set
     up the dynamic linking information.  */
     up the dynamic linking information.  */
  if (sunos_hash_table (info)->dynamic_sections_needed)
  if (sunos_hash_table (info)->dynamic_sections_needed)
    {
    {
      *sdynptr = bfd_get_section_by_name (dynobj, ".dynamic");
      *sdynptr = bfd_get_section_by_name (dynobj, ".dynamic");
 
 
      /* The .dynamic section is always the same size.  */
      /* The .dynamic section is always the same size.  */
      s = *sdynptr;
      s = *sdynptr;
      BFD_ASSERT (s != NULL);
      BFD_ASSERT (s != NULL);
      s->size = (sizeof (struct external_sun4_dynamic)
      s->size = (sizeof (struct external_sun4_dynamic)
                      + EXTERNAL_SUN4_DYNAMIC_DEBUGGER_SIZE
                      + EXTERNAL_SUN4_DYNAMIC_DEBUGGER_SIZE
                      + sizeof (struct external_sun4_dynamic_link));
                      + sizeof (struct external_sun4_dynamic_link));
 
 
      /* Set the size of the .dynsym and .hash sections.  We counted
      /* Set the size of the .dynsym and .hash sections.  We counted
         the number of dynamic symbols as we read the input files.  We
         the number of dynamic symbols as we read the input files.  We
         will build the dynamic symbol table (.dynsym) and the hash
         will build the dynamic symbol table (.dynsym) and the hash
         table (.hash) when we build the final symbol table, because
         table (.hash) when we build the final symbol table, because
         until then we do not know the correct value to give the
         until then we do not know the correct value to give the
         symbols.  We build the dynamic symbol string table (.dynstr)
         symbols.  We build the dynamic symbol string table (.dynstr)
         in a traversal of the symbol table using
         in a traversal of the symbol table using
         sunos_scan_dynamic_symbol.  */
         sunos_scan_dynamic_symbol.  */
      s = bfd_get_section_by_name (dynobj, ".dynsym");
      s = bfd_get_section_by_name (dynobj, ".dynsym");
      BFD_ASSERT (s != NULL);
      BFD_ASSERT (s != NULL);
      s->size = dynsymcount * sizeof (struct external_nlist);
      s->size = dynsymcount * sizeof (struct external_nlist);
      s->contents = bfd_alloc (output_bfd, s->size);
      s->contents = bfd_alloc (output_bfd, s->size);
      if (s->contents == NULL && s->size != 0)
      if (s->contents == NULL && s->size != 0)
        return FALSE;
        return FALSE;
 
 
      /* The number of buckets is just the number of symbols divided
      /* The number of buckets is just the number of symbols divided
         by four.  To compute the final size of the hash table, we
         by four.  To compute the final size of the hash table, we
         must actually compute the hash table.  Normally we need
         must actually compute the hash table.  Normally we need
         exactly as many entries in the hash table as there are
         exactly as many entries in the hash table as there are
         dynamic symbols, but if some of the buckets are not used we
         dynamic symbols, but if some of the buckets are not used we
         will need additional entries.  In the worst case, every
         will need additional entries.  In the worst case, every
         symbol will hash to the same bucket, and we will need
         symbol will hash to the same bucket, and we will need
         BUCKETCOUNT - 1 extra entries.  */
         BUCKETCOUNT - 1 extra entries.  */
      if (dynsymcount >= 4)
      if (dynsymcount >= 4)
        bucketcount = dynsymcount / 4;
        bucketcount = dynsymcount / 4;
      else if (dynsymcount > 0)
      else if (dynsymcount > 0)
        bucketcount = dynsymcount;
        bucketcount = dynsymcount;
      else
      else
        bucketcount = 1;
        bucketcount = 1;
      s = bfd_get_section_by_name (dynobj, ".hash");
      s = bfd_get_section_by_name (dynobj, ".hash");
      BFD_ASSERT (s != NULL);
      BFD_ASSERT (s != NULL);
      hashalloc = (dynsymcount + bucketcount - 1) * HASH_ENTRY_SIZE;
      hashalloc = (dynsymcount + bucketcount - 1) * HASH_ENTRY_SIZE;
      s->contents = bfd_zalloc (dynobj, hashalloc);
      s->contents = bfd_zalloc (dynobj, hashalloc);
      if (s->contents == NULL && dynsymcount > 0)
      if (s->contents == NULL && dynsymcount > 0)
        return FALSE;
        return FALSE;
      for (i = 0; i < bucketcount; i++)
      for (i = 0; i < bucketcount; i++)
        PUT_WORD (output_bfd, (bfd_vma) -1, s->contents + i * HASH_ENTRY_SIZE);
        PUT_WORD (output_bfd, (bfd_vma) -1, s->contents + i * HASH_ENTRY_SIZE);
      s->size = bucketcount * HASH_ENTRY_SIZE;
      s->size = bucketcount * HASH_ENTRY_SIZE;
 
 
      sunos_hash_table (info)->bucketcount = bucketcount;
      sunos_hash_table (info)->bucketcount = bucketcount;
 
 
      /* Scan all the symbols, place them in the dynamic symbol table,
      /* Scan all the symbols, place them in the dynamic symbol table,
         and build the dynamic hash table.  We reuse dynsymcount as a
         and build the dynamic hash table.  We reuse dynsymcount as a
         counter for the number of symbols we have added so far.  */
         counter for the number of symbols we have added so far.  */
      sunos_hash_table (info)->dynsymcount = 0;
      sunos_hash_table (info)->dynsymcount = 0;
      sunos_link_hash_traverse (sunos_hash_table (info),
      sunos_link_hash_traverse (sunos_hash_table (info),
                                sunos_scan_dynamic_symbol,
                                sunos_scan_dynamic_symbol,
                                (void *) info);
                                (void *) info);
      BFD_ASSERT (sunos_hash_table (info)->dynsymcount == dynsymcount);
      BFD_ASSERT (sunos_hash_table (info)->dynsymcount == dynsymcount);
 
 
      /* The SunOS native linker seems to align the total size of the
      /* The SunOS native linker seems to align the total size of the
         symbol strings to a multiple of 8.  I don't know if this is
         symbol strings to a multiple of 8.  I don't know if this is
         important, but it can't hurt much.  */
         important, but it can't hurt much.  */
      s = bfd_get_section_by_name (dynobj, ".dynstr");
      s = bfd_get_section_by_name (dynobj, ".dynstr");
      BFD_ASSERT (s != NULL);
      BFD_ASSERT (s != NULL);
      if ((s->size & 7) != 0)
      if ((s->size & 7) != 0)
        {
        {
          bfd_size_type add;
          bfd_size_type add;
          bfd_byte *contents;
          bfd_byte *contents;
 
 
          add = 8 - (s->size & 7);
          add = 8 - (s->size & 7);
          contents = bfd_realloc (s->contents, s->size + add);
          contents = bfd_realloc (s->contents, s->size + add);
          if (contents == NULL)
          if (contents == NULL)
            return FALSE;
            return FALSE;
          memset (contents + s->size, 0, (size_t) add);
          memset (contents + s->size, 0, (size_t) add);
          s->contents = contents;
          s->contents = contents;
          s->size += add;
          s->size += add;
        }
        }
    }
    }
 
 
  /* Now that we have worked out the sizes of the procedure linkage
  /* Now that we have worked out the sizes of the procedure linkage
     table and the dynamic relocs, allocate storage for them.  */
     table and the dynamic relocs, allocate storage for them.  */
  s = bfd_get_section_by_name (dynobj, ".plt");
  s = bfd_get_section_by_name (dynobj, ".plt");
  BFD_ASSERT (s != NULL);
  BFD_ASSERT (s != NULL);
  if (s->size != 0)
  if (s->size != 0)
    {
    {
      s->contents = bfd_alloc (dynobj, s->size);
      s->contents = bfd_alloc (dynobj, s->size);
      if (s->contents == NULL)
      if (s->contents == NULL)
        return FALSE;
        return FALSE;
 
 
      /* Fill in the first entry in the table.  */
      /* Fill in the first entry in the table.  */
      switch (bfd_get_arch (dynobj))
      switch (bfd_get_arch (dynobj))
        {
        {
        case bfd_arch_sparc:
        case bfd_arch_sparc:
          memcpy (s->contents, sparc_plt_first_entry, SPARC_PLT_ENTRY_SIZE);
          memcpy (s->contents, sparc_plt_first_entry, SPARC_PLT_ENTRY_SIZE);
          break;
          break;
 
 
        case bfd_arch_m68k:
        case bfd_arch_m68k:
          memcpy (s->contents, m68k_plt_first_entry, M68K_PLT_ENTRY_SIZE);
          memcpy (s->contents, m68k_plt_first_entry, M68K_PLT_ENTRY_SIZE);
          break;
          break;
 
 
        default:
        default:
          abort ();
          abort ();
        }
        }
    }
    }
 
 
  s = bfd_get_section_by_name (dynobj, ".dynrel");
  s = bfd_get_section_by_name (dynobj, ".dynrel");
  if (s->size != 0)
  if (s->size != 0)
    {
    {
      s->contents = bfd_alloc (dynobj, s->size);
      s->contents = bfd_alloc (dynobj, s->size);
      if (s->contents == NULL)
      if (s->contents == NULL)
        return FALSE;
        return FALSE;
    }
    }
  /* We use the reloc_count field to keep track of how many of the
  /* We use the reloc_count field to keep track of how many of the
     relocs we have output so far.  */
     relocs we have output so far.  */
  s->reloc_count = 0;
  s->reloc_count = 0;
 
 
  /* Make space for the global offset table.  */
  /* Make space for the global offset table.  */
  s = bfd_get_section_by_name (dynobj, ".got");
  s = bfd_get_section_by_name (dynobj, ".got");
  s->contents = bfd_alloc (dynobj, s->size);
  s->contents = bfd_alloc (dynobj, s->size);
  if (s->contents == NULL)
  if (s->contents == NULL)
    return FALSE;
    return FALSE;
 
 
  *sneedptr = bfd_get_section_by_name (dynobj, ".need");
  *sneedptr = bfd_get_section_by_name (dynobj, ".need");
  *srulesptr = bfd_get_section_by_name (dynobj, ".rules");
  *srulesptr = bfd_get_section_by_name (dynobj, ".rules");
 
 
  return TRUE;
  return TRUE;
}
}
 
 
/* Link a dynamic object.  We actually don't have anything to do at
/* Link a dynamic object.  We actually don't have anything to do at
   this point.  This entry point exists to prevent the regular linker
   this point.  This entry point exists to prevent the regular linker
   code from doing anything with the object.  */
   code from doing anything with the object.  */
 
 
static bfd_boolean
static bfd_boolean
sunos_link_dynamic_object (struct bfd_link_info *info ATTRIBUTE_UNUSED,
sunos_link_dynamic_object (struct bfd_link_info *info ATTRIBUTE_UNUSED,
                           bfd *abfd ATTRIBUTE_UNUSED)
                           bfd *abfd ATTRIBUTE_UNUSED)
{
{
  return TRUE;
  return TRUE;
}
}
 
 
/* Write out a dynamic symbol.  This is called by the final traversal
/* Write out a dynamic symbol.  This is called by the final traversal
   over the symbol table.  */
   over the symbol table.  */
 
 
static bfd_boolean
static bfd_boolean
sunos_write_dynamic_symbol (bfd *output_bfd,
sunos_write_dynamic_symbol (bfd *output_bfd,
                            struct bfd_link_info *info,
                            struct bfd_link_info *info,
                            struct aout_link_hash_entry *harg)
                            struct aout_link_hash_entry *harg)
{
{
  struct sunos_link_hash_entry *h = (struct sunos_link_hash_entry *) harg;
  struct sunos_link_hash_entry *h = (struct sunos_link_hash_entry *) harg;
  int type;
  int type;
  bfd_vma val;
  bfd_vma val;
  asection *s;
  asection *s;
  struct external_nlist *outsym;
  struct external_nlist *outsym;
 
 
  /* If this symbol is in the procedure linkage table, fill in the
  /* If this symbol is in the procedure linkage table, fill in the
     table entry.  */
     table entry.  */
  if (h->plt_offset != 0)
  if (h->plt_offset != 0)
    {
    {
      bfd *dynobj;
      bfd *dynobj;
      asection *splt;
      asection *splt;
      bfd_byte *p;
      bfd_byte *p;
      bfd_vma r_address;
      bfd_vma r_address;
 
 
      dynobj = sunos_hash_table (info)->dynobj;
      dynobj = sunos_hash_table (info)->dynobj;
      splt = bfd_get_section_by_name (dynobj, ".plt");
      splt = bfd_get_section_by_name (dynobj, ".plt");
      p = splt->contents + h->plt_offset;
      p = splt->contents + h->plt_offset;
 
 
      s = bfd_get_section_by_name (dynobj, ".dynrel");
      s = bfd_get_section_by_name (dynobj, ".dynrel");
 
 
      r_address = (splt->output_section->vma
      r_address = (splt->output_section->vma
                   + splt->output_offset
                   + splt->output_offset
                   + h->plt_offset);
                   + h->plt_offset);
 
 
      switch (bfd_get_arch (output_bfd))
      switch (bfd_get_arch (output_bfd))
        {
        {
        case bfd_arch_sparc:
        case bfd_arch_sparc:
          if (info->shared || (h->flags & SUNOS_DEF_REGULAR) == 0)
          if (info->shared || (h->flags & SUNOS_DEF_REGULAR) == 0)
            {
            {
              bfd_put_32 (output_bfd, SPARC_PLT_ENTRY_WORD0, p);
              bfd_put_32 (output_bfd, SPARC_PLT_ENTRY_WORD0, p);
              bfd_put_32 (output_bfd,
              bfd_put_32 (output_bfd,
                          (SPARC_PLT_ENTRY_WORD1
                          (SPARC_PLT_ENTRY_WORD1
                           + (((- (h->plt_offset + 4) >> 2)
                           + (((- (h->plt_offset + 4) >> 2)
                               & 0x3fffffff))),
                               & 0x3fffffff))),
                          p + 4);
                          p + 4);
              bfd_put_32 (output_bfd, SPARC_PLT_ENTRY_WORD2 + s->reloc_count,
              bfd_put_32 (output_bfd, SPARC_PLT_ENTRY_WORD2 + s->reloc_count,
                          p + 8);
                          p + 8);
            }
            }
          else
          else
            {
            {
              val = (h->root.root.u.def.section->output_section->vma
              val = (h->root.root.u.def.section->output_section->vma
                     + h->root.root.u.def.section->output_offset
                     + h->root.root.u.def.section->output_offset
                     + h->root.root.u.def.value);
                     + h->root.root.u.def.value);
              bfd_put_32 (output_bfd,
              bfd_put_32 (output_bfd,
                          SPARC_PLT_PIC_WORD0 + ((val >> 10) & 0x3fffff),
                          SPARC_PLT_PIC_WORD0 + ((val >> 10) & 0x3fffff),
                          p);
                          p);
              bfd_put_32 (output_bfd,
              bfd_put_32 (output_bfd,
                          SPARC_PLT_PIC_WORD1 + (val & 0x3ff),
                          SPARC_PLT_PIC_WORD1 + (val & 0x3ff),
                          p + 4);
                          p + 4);
              bfd_put_32 (output_bfd, SPARC_PLT_PIC_WORD2, p + 8);
              bfd_put_32 (output_bfd, SPARC_PLT_PIC_WORD2, p + 8);
            }
            }
          break;
          break;
 
 
        case bfd_arch_m68k:
        case bfd_arch_m68k:
          if (! info->shared && (h->flags & SUNOS_DEF_REGULAR) != 0)
          if (! info->shared && (h->flags & SUNOS_DEF_REGULAR) != 0)
            abort ();
            abort ();
          bfd_put_16 (output_bfd, M68K_PLT_ENTRY_WORD0, p);
          bfd_put_16 (output_bfd, M68K_PLT_ENTRY_WORD0, p);
          bfd_put_32 (output_bfd, (- (h->plt_offset + 2)), p + 2);
          bfd_put_32 (output_bfd, (- (h->plt_offset + 2)), p + 2);
          bfd_put_16 (output_bfd, (bfd_vma) s->reloc_count, p + 6);
          bfd_put_16 (output_bfd, (bfd_vma) s->reloc_count, p + 6);
          r_address += 2;
          r_address += 2;
          break;
          break;
 
 
        default:
        default:
          abort ();
          abort ();
        }
        }
 
 
      /* We also need to add a jump table reloc, unless this is the
      /* We also need to add a jump table reloc, unless this is the
         result of a JMP_TBL reloc from PIC compiled code.  */
         result of a JMP_TBL reloc from PIC compiled code.  */
      if (info->shared || (h->flags & SUNOS_DEF_REGULAR) == 0)
      if (info->shared || (h->flags & SUNOS_DEF_REGULAR) == 0)
        {
        {
          BFD_ASSERT (h->dynindx >= 0);
          BFD_ASSERT (h->dynindx >= 0);
          BFD_ASSERT (s->reloc_count * obj_reloc_entry_size (dynobj)
          BFD_ASSERT (s->reloc_count * obj_reloc_entry_size (dynobj)
                      < s->size);
                      < s->size);
          p = s->contents + s->reloc_count * obj_reloc_entry_size (output_bfd);
          p = s->contents + s->reloc_count * obj_reloc_entry_size (output_bfd);
          if (obj_reloc_entry_size (output_bfd) == RELOC_STD_SIZE)
          if (obj_reloc_entry_size (output_bfd) == RELOC_STD_SIZE)
            {
            {
              struct reloc_std_external *srel;
              struct reloc_std_external *srel;
 
 
              srel = (struct reloc_std_external *) p;
              srel = (struct reloc_std_external *) p;
              PUT_WORD (output_bfd, r_address, srel->r_address);
              PUT_WORD (output_bfd, r_address, srel->r_address);
              if (bfd_header_big_endian (output_bfd))
              if (bfd_header_big_endian (output_bfd))
                {
                {
                  srel->r_index[0] = (bfd_byte) (h->dynindx >> 16);
                  srel->r_index[0] = (bfd_byte) (h->dynindx >> 16);
                  srel->r_index[1] = (bfd_byte) (h->dynindx >> 8);
                  srel->r_index[1] = (bfd_byte) (h->dynindx >> 8);
                  srel->r_index[2] = (bfd_byte) (h->dynindx);
                  srel->r_index[2] = (bfd_byte) (h->dynindx);
                  srel->r_type[0] = (RELOC_STD_BITS_EXTERN_BIG
                  srel->r_type[0] = (RELOC_STD_BITS_EXTERN_BIG
                                     | RELOC_STD_BITS_JMPTABLE_BIG);
                                     | RELOC_STD_BITS_JMPTABLE_BIG);
                }
                }
              else
              else
                {
                {
                  srel->r_index[2] = (bfd_byte) (h->dynindx >> 16);
                  srel->r_index[2] = (bfd_byte) (h->dynindx >> 16);
                  srel->r_index[1] = (bfd_byte) (h->dynindx >> 8);
                  srel->r_index[1] = (bfd_byte) (h->dynindx >> 8);
                  srel->r_index[0] = (bfd_byte)h->dynindx;
                  srel->r_index[0] = (bfd_byte)h->dynindx;
                  srel->r_type[0] = (RELOC_STD_BITS_EXTERN_LITTLE
                  srel->r_type[0] = (RELOC_STD_BITS_EXTERN_LITTLE
                                     | RELOC_STD_BITS_JMPTABLE_LITTLE);
                                     | RELOC_STD_BITS_JMPTABLE_LITTLE);
                }
                }
            }
            }
          else
          else
            {
            {
              struct reloc_ext_external *erel;
              struct reloc_ext_external *erel;
 
 
              erel = (struct reloc_ext_external *) p;
              erel = (struct reloc_ext_external *) p;
              PUT_WORD (output_bfd, r_address, erel->r_address);
              PUT_WORD (output_bfd, r_address, erel->r_address);
              if (bfd_header_big_endian (output_bfd))
              if (bfd_header_big_endian (output_bfd))
                {
                {
                  erel->r_index[0] = (bfd_byte) (h->dynindx >> 16);
                  erel->r_index[0] = (bfd_byte) (h->dynindx >> 16);
                  erel->r_index[1] = (bfd_byte) (h->dynindx >> 8);
                  erel->r_index[1] = (bfd_byte) (h->dynindx >> 8);
                  erel->r_index[2] = (bfd_byte)h->dynindx;
                  erel->r_index[2] = (bfd_byte)h->dynindx;
                  erel->r_type[0] =
                  erel->r_type[0] =
                    (RELOC_EXT_BITS_EXTERN_BIG
                    (RELOC_EXT_BITS_EXTERN_BIG
                     | (RELOC_JMP_SLOT << RELOC_EXT_BITS_TYPE_SH_BIG));
                     | (RELOC_JMP_SLOT << RELOC_EXT_BITS_TYPE_SH_BIG));
                }
                }
              else
              else
                {
                {
                  erel->r_index[2] = (bfd_byte) (h->dynindx >> 16);
                  erel->r_index[2] = (bfd_byte) (h->dynindx >> 16);
                  erel->r_index[1] = (bfd_byte) (h->dynindx >> 8);
                  erel->r_index[1] = (bfd_byte) (h->dynindx >> 8);
                  erel->r_index[0] = (bfd_byte)h->dynindx;
                  erel->r_index[0] = (bfd_byte)h->dynindx;
                  erel->r_type[0] =
                  erel->r_type[0] =
                    (RELOC_EXT_BITS_EXTERN_LITTLE
                    (RELOC_EXT_BITS_EXTERN_LITTLE
                     | (RELOC_JMP_SLOT << RELOC_EXT_BITS_TYPE_SH_LITTLE));
                     | (RELOC_JMP_SLOT << RELOC_EXT_BITS_TYPE_SH_LITTLE));
                }
                }
              PUT_WORD (output_bfd, (bfd_vma) 0, erel->r_addend);
              PUT_WORD (output_bfd, (bfd_vma) 0, erel->r_addend);
            }
            }
 
 
          ++s->reloc_count;
          ++s->reloc_count;
        }
        }
    }
    }
 
 
  /* If this is not a dynamic symbol, we don't have to do anything
  /* If this is not a dynamic symbol, we don't have to do anything
     else.  We only check this after handling the PLT entry, because
     else.  We only check this after handling the PLT entry, because
     we can have a PLT entry for a nondynamic symbol when linking PIC
     we can have a PLT entry for a nondynamic symbol when linking PIC
     compiled code from a regular object.  */
     compiled code from a regular object.  */
  if (h->dynindx < 0)
  if (h->dynindx < 0)
    return TRUE;
    return TRUE;
 
 
  switch (h->root.root.type)
  switch (h->root.root.type)
    {
    {
    default:
    default:
    case bfd_link_hash_new:
    case bfd_link_hash_new:
      abort ();
      abort ();
      /* Avoid variable not initialized warnings.  */
      /* Avoid variable not initialized warnings.  */
      return TRUE;
      return TRUE;
    case bfd_link_hash_undefined:
    case bfd_link_hash_undefined:
      type = N_UNDF | N_EXT;
      type = N_UNDF | N_EXT;
      val = 0;
      val = 0;
      break;
      break;
    case bfd_link_hash_defined:
    case bfd_link_hash_defined:
    case bfd_link_hash_defweak:
    case bfd_link_hash_defweak:
      {
      {
        asection *sec;
        asection *sec;
        asection *output_section;
        asection *output_section;
 
 
        sec = h->root.root.u.def.section;
        sec = h->root.root.u.def.section;
        output_section = sec->output_section;
        output_section = sec->output_section;
        BFD_ASSERT (bfd_is_abs_section (output_section)
        BFD_ASSERT (bfd_is_abs_section (output_section)
                    || output_section->owner == output_bfd);
                    || output_section->owner == output_bfd);
        if (h->plt_offset != 0
        if (h->plt_offset != 0
            && (h->flags & SUNOS_DEF_REGULAR) == 0)
            && (h->flags & SUNOS_DEF_REGULAR) == 0)
          {
          {
            type = N_UNDF | N_EXT;
            type = N_UNDF | N_EXT;
            val = 0;
            val = 0;
          }
          }
        else
        else
          {
          {
            if (output_section == obj_textsec (output_bfd))
            if (output_section == obj_textsec (output_bfd))
              type = (h->root.root.type == bfd_link_hash_defined
              type = (h->root.root.type == bfd_link_hash_defined
                      ? N_TEXT
                      ? N_TEXT
                      : N_WEAKT);
                      : N_WEAKT);
            else if (output_section == obj_datasec (output_bfd))
            else if (output_section == obj_datasec (output_bfd))
              type = (h->root.root.type == bfd_link_hash_defined
              type = (h->root.root.type == bfd_link_hash_defined
                      ? N_DATA
                      ? N_DATA
                      : N_WEAKD);
                      : N_WEAKD);
            else if (output_section == obj_bsssec (output_bfd))
            else if (output_section == obj_bsssec (output_bfd))
              type = (h->root.root.type == bfd_link_hash_defined
              type = (h->root.root.type == bfd_link_hash_defined
                      ? N_BSS
                      ? N_BSS
                      : N_WEAKB);
                      : N_WEAKB);
            else
            else
              type = (h->root.root.type == bfd_link_hash_defined
              type = (h->root.root.type == bfd_link_hash_defined
                      ? N_ABS
                      ? N_ABS
                      : N_WEAKA);
                      : N_WEAKA);
            type |= N_EXT;
            type |= N_EXT;
            val = (h->root.root.u.def.value
            val = (h->root.root.u.def.value
                   + output_section->vma
                   + output_section->vma
                   + sec->output_offset);
                   + sec->output_offset);
          }
          }
      }
      }
      break;
      break;
    case bfd_link_hash_common:
    case bfd_link_hash_common:
      type = N_UNDF | N_EXT;
      type = N_UNDF | N_EXT;
      val = h->root.root.u.c.size;
      val = h->root.root.u.c.size;
      break;
      break;
    case bfd_link_hash_undefweak:
    case bfd_link_hash_undefweak:
      type = N_WEAKU;
      type = N_WEAKU;
      val = 0;
      val = 0;
      break;
      break;
    case bfd_link_hash_indirect:
    case bfd_link_hash_indirect:
    case bfd_link_hash_warning:
    case bfd_link_hash_warning:
      /* FIXME: Ignore these for now.  The circumstances under which
      /* FIXME: Ignore these for now.  The circumstances under which
         they should be written out are not clear to me.  */
         they should be written out are not clear to me.  */
      return TRUE;
      return TRUE;
    }
    }
 
 
  s = bfd_get_section_by_name (sunos_hash_table (info)->dynobj, ".dynsym");
  s = bfd_get_section_by_name (sunos_hash_table (info)->dynobj, ".dynsym");
  BFD_ASSERT (s != NULL);
  BFD_ASSERT (s != NULL);
  outsym = ((struct external_nlist *)
  outsym = ((struct external_nlist *)
            (s->contents + h->dynindx * EXTERNAL_NLIST_SIZE));
            (s->contents + h->dynindx * EXTERNAL_NLIST_SIZE));
 
 
  H_PUT_8 (output_bfd, type, outsym->e_type);
  H_PUT_8 (output_bfd, type, outsym->e_type);
  H_PUT_8 (output_bfd, 0, outsym->e_other);
  H_PUT_8 (output_bfd, 0, outsym->e_other);
 
 
  /* FIXME: The native linker doesn't use 0 for desc.  It seems to use
  /* FIXME: The native linker doesn't use 0 for desc.  It seems to use
     one less than the desc value in the shared library, although that
     one less than the desc value in the shared library, although that
     seems unlikely.  */
     seems unlikely.  */
  H_PUT_16 (output_bfd, 0, outsym->e_desc);
  H_PUT_16 (output_bfd, 0, outsym->e_desc);
 
 
  PUT_WORD (output_bfd, h->dynstr_index, outsym->e_strx);
  PUT_WORD (output_bfd, h->dynstr_index, outsym->e_strx);
  PUT_WORD (output_bfd, val, outsym->e_value);
  PUT_WORD (output_bfd, val, outsym->e_value);
 
 
  return TRUE;
  return TRUE;
}
}
 
 
/* This is called for each reloc against an external symbol.  If this
/* This is called for each reloc against an external symbol.  If this
   is a reloc which are are going to copy as a dynamic reloc, then
   is a reloc which are are going to copy as a dynamic reloc, then
   copy it over, and tell the caller to not bother processing this
   copy it over, and tell the caller to not bother processing this
   reloc.  */
   reloc.  */
 
 
static bfd_boolean
static bfd_boolean
sunos_check_dynamic_reloc (struct bfd_link_info *info,
sunos_check_dynamic_reloc (struct bfd_link_info *info,
                           bfd *input_bfd,
                           bfd *input_bfd,
                           asection *input_section,
                           asection *input_section,
                           struct aout_link_hash_entry *harg,
                           struct aout_link_hash_entry *harg,
                           void * reloc,
                           void * reloc,
                           bfd_byte *contents ATTRIBUTE_UNUSED,
                           bfd_byte *contents ATTRIBUTE_UNUSED,
                           bfd_boolean *skip,
                           bfd_boolean *skip,
                           bfd_vma *relocationp)
                           bfd_vma *relocationp)
{
{
  struct sunos_link_hash_entry *h = (struct sunos_link_hash_entry *) harg;
  struct sunos_link_hash_entry *h = (struct sunos_link_hash_entry *) harg;
  bfd *dynobj;
  bfd *dynobj;
  bfd_boolean baserel;
  bfd_boolean baserel;
  bfd_boolean jmptbl;
  bfd_boolean jmptbl;
  bfd_boolean pcrel;
  bfd_boolean pcrel;
  asection *s;
  asection *s;
  bfd_byte *p;
  bfd_byte *p;
  long indx;
  long indx;
 
 
  *skip = FALSE;
  *skip = FALSE;
 
 
  dynobj = sunos_hash_table (info)->dynobj;
  dynobj = sunos_hash_table (info)->dynobj;
 
 
  if (h != NULL
  if (h != NULL
      && h->plt_offset != 0
      && h->plt_offset != 0
      && (info->shared
      && (info->shared
          || (h->flags & SUNOS_DEF_REGULAR) == 0))
          || (h->flags & SUNOS_DEF_REGULAR) == 0))
    {
    {
      asection *splt;
      asection *splt;
 
 
      /* Redirect the relocation to the PLT entry.  */
      /* Redirect the relocation to the PLT entry.  */
      splt = bfd_get_section_by_name (dynobj, ".plt");
      splt = bfd_get_section_by_name (dynobj, ".plt");
      *relocationp = (splt->output_section->vma
      *relocationp = (splt->output_section->vma
                      + splt->output_offset
                      + splt->output_offset
                      + h->plt_offset);
                      + h->plt_offset);
    }
    }
 
 
  if (obj_reloc_entry_size (input_bfd) == RELOC_STD_SIZE)
  if (obj_reloc_entry_size (input_bfd) == RELOC_STD_SIZE)
    {
    {
      struct reloc_std_external *srel;
      struct reloc_std_external *srel;
 
 
      srel = (struct reloc_std_external *) reloc;
      srel = (struct reloc_std_external *) reloc;
      if (bfd_header_big_endian (input_bfd))
      if (bfd_header_big_endian (input_bfd))
        {
        {
          baserel = (0 != (srel->r_type[0] & RELOC_STD_BITS_BASEREL_BIG));
          baserel = (0 != (srel->r_type[0] & RELOC_STD_BITS_BASEREL_BIG));
          jmptbl = (0 != (srel->r_type[0] & RELOC_STD_BITS_JMPTABLE_BIG));
          jmptbl = (0 != (srel->r_type[0] & RELOC_STD_BITS_JMPTABLE_BIG));
          pcrel = (0 != (srel->r_type[0] & RELOC_STD_BITS_PCREL_BIG));
          pcrel = (0 != (srel->r_type[0] & RELOC_STD_BITS_PCREL_BIG));
        }
        }
      else
      else
        {
        {
          baserel = (0 != (srel->r_type[0] & RELOC_STD_BITS_BASEREL_LITTLE));
          baserel = (0 != (srel->r_type[0] & RELOC_STD_BITS_BASEREL_LITTLE));
          jmptbl = (0 != (srel->r_type[0] & RELOC_STD_BITS_JMPTABLE_LITTLE));
          jmptbl = (0 != (srel->r_type[0] & RELOC_STD_BITS_JMPTABLE_LITTLE));
          pcrel = (0 != (srel->r_type[0] & RELOC_STD_BITS_PCREL_LITTLE));
          pcrel = (0 != (srel->r_type[0] & RELOC_STD_BITS_PCREL_LITTLE));
        }
        }
    }
    }
  else
  else
    {
    {
      struct reloc_ext_external *erel;
      struct reloc_ext_external *erel;
      int r_type;
      int r_type;
 
 
      erel = (struct reloc_ext_external *) reloc;
      erel = (struct reloc_ext_external *) reloc;
      if (bfd_header_big_endian (input_bfd))
      if (bfd_header_big_endian (input_bfd))
        r_type = ((erel->r_type[0] & RELOC_EXT_BITS_TYPE_BIG)
        r_type = ((erel->r_type[0] & RELOC_EXT_BITS_TYPE_BIG)
                  >> RELOC_EXT_BITS_TYPE_SH_BIG);
                  >> RELOC_EXT_BITS_TYPE_SH_BIG);
      else
      else
        r_type = ((erel->r_type[0] & RELOC_EXT_BITS_TYPE_LITTLE)
        r_type = ((erel->r_type[0] & RELOC_EXT_BITS_TYPE_LITTLE)
                  >> RELOC_EXT_BITS_TYPE_SH_LITTLE);
                  >> RELOC_EXT_BITS_TYPE_SH_LITTLE);
      baserel = (r_type == RELOC_BASE10
      baserel = (r_type == RELOC_BASE10
                 || r_type == RELOC_BASE13
                 || r_type == RELOC_BASE13
                 || r_type == RELOC_BASE22);
                 || r_type == RELOC_BASE22);
      jmptbl = r_type == RELOC_JMP_TBL;
      jmptbl = r_type == RELOC_JMP_TBL;
      pcrel = (r_type == RELOC_DISP8
      pcrel = (r_type == RELOC_DISP8
               || r_type == RELOC_DISP16
               || r_type == RELOC_DISP16
               || r_type == RELOC_DISP32
               || r_type == RELOC_DISP32
               || r_type == RELOC_WDISP30
               || r_type == RELOC_WDISP30
               || r_type == RELOC_WDISP22);
               || r_type == RELOC_WDISP22);
      /* We don't consider the PC10 and PC22 types to be PC relative,
      /* We don't consider the PC10 and PC22 types to be PC relative,
         because they are pcrel_offset.  */
         because they are pcrel_offset.  */
    }
    }
 
 
  if (baserel)
  if (baserel)
    {
    {
      bfd_vma *got_offsetp;
      bfd_vma *got_offsetp;
      asection *sgot;
      asection *sgot;
 
 
      if (h != NULL)
      if (h != NULL)
        got_offsetp = &h->got_offset;
        got_offsetp = &h->got_offset;
      else if (adata (input_bfd).local_got_offsets == NULL)
      else if (adata (input_bfd).local_got_offsets == NULL)
        got_offsetp = NULL;
        got_offsetp = NULL;
      else
      else
        {
        {
          struct reloc_std_external *srel;
          struct reloc_std_external *srel;
          int r_index;
          int r_index;
 
 
          srel = (struct reloc_std_external *) reloc;
          srel = (struct reloc_std_external *) reloc;
          if (obj_reloc_entry_size (input_bfd) == RELOC_STD_SIZE)
          if (obj_reloc_entry_size (input_bfd) == RELOC_STD_SIZE)
            {
            {
              if (bfd_header_big_endian (input_bfd))
              if (bfd_header_big_endian (input_bfd))
                r_index = ((srel->r_index[0] << 16)
                r_index = ((srel->r_index[0] << 16)
                           | (srel->r_index[1] << 8)
                           | (srel->r_index[1] << 8)
                           | srel->r_index[2]);
                           | srel->r_index[2]);
              else
              else
                r_index = ((srel->r_index[2] << 16)
                r_index = ((srel->r_index[2] << 16)
                           | (srel->r_index[1] << 8)
                           | (srel->r_index[1] << 8)
                           | srel->r_index[0]);
                           | srel->r_index[0]);
            }
            }
          else
          else
            {
            {
              struct reloc_ext_external *erel;
              struct reloc_ext_external *erel;
 
 
              erel = (struct reloc_ext_external *) reloc;
              erel = (struct reloc_ext_external *) reloc;
              if (bfd_header_big_endian (input_bfd))
              if (bfd_header_big_endian (input_bfd))
                r_index = ((erel->r_index[0] << 16)
                r_index = ((erel->r_index[0] << 16)
                           | (erel->r_index[1] << 8)
                           | (erel->r_index[1] << 8)
                           | erel->r_index[2]);
                           | erel->r_index[2]);
              else
              else
                r_index = ((erel->r_index[2] << 16)
                r_index = ((erel->r_index[2] << 16)
                           | (erel->r_index[1] << 8)
                           | (erel->r_index[1] << 8)
                           | erel->r_index[0]);
                           | erel->r_index[0]);
            }
            }
 
 
          got_offsetp = adata (input_bfd).local_got_offsets + r_index;
          got_offsetp = adata (input_bfd).local_got_offsets + r_index;
        }
        }
 
 
      BFD_ASSERT (got_offsetp != NULL && *got_offsetp != 0);
      BFD_ASSERT (got_offsetp != NULL && *got_offsetp != 0);
 
 
      sgot = bfd_get_section_by_name (dynobj, ".got");
      sgot = bfd_get_section_by_name (dynobj, ".got");
 
 
      /* We set the least significant bit to indicate whether we have
      /* We set the least significant bit to indicate whether we have
         already initialized the GOT entry.  */
         already initialized the GOT entry.  */
      if ((*got_offsetp & 1) == 0)
      if ((*got_offsetp & 1) == 0)
        {
        {
          if (h == NULL
          if (h == NULL
              || (! info->shared
              || (! info->shared
                  && ((h->flags & SUNOS_DEF_DYNAMIC) == 0
                  && ((h->flags & SUNOS_DEF_DYNAMIC) == 0
                      || (h->flags & SUNOS_DEF_REGULAR) != 0)))
                      || (h->flags & SUNOS_DEF_REGULAR) != 0)))
            PUT_WORD (dynobj, *relocationp, sgot->contents + *got_offsetp);
            PUT_WORD (dynobj, *relocationp, sgot->contents + *got_offsetp);
          else
          else
            PUT_WORD (dynobj, 0, sgot->contents + *got_offsetp);
            PUT_WORD (dynobj, 0, sgot->contents + *got_offsetp);
 
 
          if (info->shared
          if (info->shared
              || (h != NULL
              || (h != NULL
                  && (h->flags & SUNOS_DEF_DYNAMIC) != 0
                  && (h->flags & SUNOS_DEF_DYNAMIC) != 0
                  && (h->flags & SUNOS_DEF_REGULAR) == 0))
                  && (h->flags & SUNOS_DEF_REGULAR) == 0))
            {
            {
              /* We need to create a GLOB_DAT or 32 reloc to tell the
              /* We need to create a GLOB_DAT or 32 reloc to tell the
                 dynamic linker to fill in this entry in the table.  */
                 dynamic linker to fill in this entry in the table.  */
 
 
              s = bfd_get_section_by_name (dynobj, ".dynrel");
              s = bfd_get_section_by_name (dynobj, ".dynrel");
              BFD_ASSERT (s != NULL);
              BFD_ASSERT (s != NULL);
              BFD_ASSERT (s->reloc_count * obj_reloc_entry_size (dynobj)
              BFD_ASSERT (s->reloc_count * obj_reloc_entry_size (dynobj)
                          < s->size);
                          < s->size);
 
 
              p = (s->contents
              p = (s->contents
                   + s->reloc_count * obj_reloc_entry_size (dynobj));
                   + s->reloc_count * obj_reloc_entry_size (dynobj));
 
 
              if (h != NULL)
              if (h != NULL)
                indx = h->dynindx;
                indx = h->dynindx;
              else
              else
                indx = 0;
                indx = 0;
 
 
              if (obj_reloc_entry_size (dynobj) == RELOC_STD_SIZE)
              if (obj_reloc_entry_size (dynobj) == RELOC_STD_SIZE)
                {
                {
                  struct reloc_std_external *srel;
                  struct reloc_std_external *srel;
 
 
                  srel = (struct reloc_std_external *) p;
                  srel = (struct reloc_std_external *) p;
                  PUT_WORD (dynobj,
                  PUT_WORD (dynobj,
                            (*got_offsetp
                            (*got_offsetp
                             + sgot->output_section->vma
                             + sgot->output_section->vma
                             + sgot->output_offset),
                             + sgot->output_offset),
                            srel->r_address);
                            srel->r_address);
                  if (bfd_header_big_endian (dynobj))
                  if (bfd_header_big_endian (dynobj))
                    {
                    {
                      srel->r_index[0] = (bfd_byte) (indx >> 16);
                      srel->r_index[0] = (bfd_byte) (indx >> 16);
                      srel->r_index[1] = (bfd_byte) (indx >> 8);
                      srel->r_index[1] = (bfd_byte) (indx >> 8);
                      srel->r_index[2] = (bfd_byte)indx;
                      srel->r_index[2] = (bfd_byte)indx;
                      if (h == NULL)
                      if (h == NULL)
                        srel->r_type[0] = 2 << RELOC_STD_BITS_LENGTH_SH_BIG;
                        srel->r_type[0] = 2 << RELOC_STD_BITS_LENGTH_SH_BIG;
                      else
                      else
                        srel->r_type[0] =
                        srel->r_type[0] =
                          (RELOC_STD_BITS_EXTERN_BIG
                          (RELOC_STD_BITS_EXTERN_BIG
                           | RELOC_STD_BITS_BASEREL_BIG
                           | RELOC_STD_BITS_BASEREL_BIG
                           | RELOC_STD_BITS_RELATIVE_BIG
                           | RELOC_STD_BITS_RELATIVE_BIG
                           | (2 << RELOC_STD_BITS_LENGTH_SH_BIG));
                           | (2 << RELOC_STD_BITS_LENGTH_SH_BIG));
                    }
                    }
                  else
                  else
                    {
                    {
                      srel->r_index[2] = (bfd_byte) (indx >> 16);
                      srel->r_index[2] = (bfd_byte) (indx >> 16);
                      srel->r_index[1] = (bfd_byte) (indx >> 8);
                      srel->r_index[1] = (bfd_byte) (indx >> 8);
                      srel->r_index[0] = (bfd_byte)indx;
                      srel->r_index[0] = (bfd_byte)indx;
                      if (h == NULL)
                      if (h == NULL)
                        srel->r_type[0] = 2 << RELOC_STD_BITS_LENGTH_SH_LITTLE;
                        srel->r_type[0] = 2 << RELOC_STD_BITS_LENGTH_SH_LITTLE;
                      else
                      else
                        srel->r_type[0] =
                        srel->r_type[0] =
                          (RELOC_STD_BITS_EXTERN_LITTLE
                          (RELOC_STD_BITS_EXTERN_LITTLE
                           | RELOC_STD_BITS_BASEREL_LITTLE
                           | RELOC_STD_BITS_BASEREL_LITTLE
                           | RELOC_STD_BITS_RELATIVE_LITTLE
                           | RELOC_STD_BITS_RELATIVE_LITTLE
                           | (2 << RELOC_STD_BITS_LENGTH_SH_LITTLE));
                           | (2 << RELOC_STD_BITS_LENGTH_SH_LITTLE));
                    }
                    }
                }
                }
              else
              else
                {
                {
                  struct reloc_ext_external *erel;
                  struct reloc_ext_external *erel;
 
 
                  erel = (struct reloc_ext_external *) p;
                  erel = (struct reloc_ext_external *) p;
                  PUT_WORD (dynobj,
                  PUT_WORD (dynobj,
                            (*got_offsetp
                            (*got_offsetp
                             + sgot->output_section->vma
                             + sgot->output_section->vma
                             + sgot->output_offset),
                             + sgot->output_offset),
                            erel->r_address);
                            erel->r_address);
                  if (bfd_header_big_endian (dynobj))
                  if (bfd_header_big_endian (dynobj))
                    {
                    {
                      erel->r_index[0] = (bfd_byte) (indx >> 16);
                      erel->r_index[0] = (bfd_byte) (indx >> 16);
                      erel->r_index[1] = (bfd_byte) (indx >> 8);
                      erel->r_index[1] = (bfd_byte) (indx >> 8);
                      erel->r_index[2] = (bfd_byte)indx;
                      erel->r_index[2] = (bfd_byte)indx;
                      if (h == NULL)
                      if (h == NULL)
                        erel->r_type[0] =
                        erel->r_type[0] =
                          RELOC_32 << RELOC_EXT_BITS_TYPE_SH_BIG;
                          RELOC_32 << RELOC_EXT_BITS_TYPE_SH_BIG;
                      else
                      else
                        erel->r_type[0] =
                        erel->r_type[0] =
                          (RELOC_EXT_BITS_EXTERN_BIG
                          (RELOC_EXT_BITS_EXTERN_BIG
                           | (RELOC_GLOB_DAT << RELOC_EXT_BITS_TYPE_SH_BIG));
                           | (RELOC_GLOB_DAT << RELOC_EXT_BITS_TYPE_SH_BIG));
                    }
                    }
                  else
                  else
                    {
                    {
                      erel->r_index[2] = (bfd_byte) (indx >> 16);
                      erel->r_index[2] = (bfd_byte) (indx >> 16);
                      erel->r_index[1] = (bfd_byte) (indx >> 8);
                      erel->r_index[1] = (bfd_byte) (indx >> 8);
                      erel->r_index[0] = (bfd_byte)indx;
                      erel->r_index[0] = (bfd_byte)indx;
                      if (h == NULL)
                      if (h == NULL)
                        erel->r_type[0] =
                        erel->r_type[0] =
                          RELOC_32 << RELOC_EXT_BITS_TYPE_SH_LITTLE;
                          RELOC_32 << RELOC_EXT_BITS_TYPE_SH_LITTLE;
                      else
                      else
                        erel->r_type[0] =
                        erel->r_type[0] =
                          (RELOC_EXT_BITS_EXTERN_LITTLE
                          (RELOC_EXT_BITS_EXTERN_LITTLE
                           | (RELOC_GLOB_DAT
                           | (RELOC_GLOB_DAT
                              << RELOC_EXT_BITS_TYPE_SH_LITTLE));
                              << RELOC_EXT_BITS_TYPE_SH_LITTLE));
                    }
                    }
                  PUT_WORD (dynobj, 0, erel->r_addend);
                  PUT_WORD (dynobj, 0, erel->r_addend);
                }
                }
 
 
              ++s->reloc_count;
              ++s->reloc_count;
            }
            }
 
 
          *got_offsetp |= 1;
          *got_offsetp |= 1;
        }
        }
 
 
      *relocationp = (sgot->vma
      *relocationp = (sgot->vma
                      + (*got_offsetp &~ (bfd_vma) 1)
                      + (*got_offsetp &~ (bfd_vma) 1)
                      - sunos_hash_table (info)->got_base);
                      - sunos_hash_table (info)->got_base);
 
 
      /* There is nothing else to do for a base relative reloc.  */
      /* There is nothing else to do for a base relative reloc.  */
      return TRUE;
      return TRUE;
    }
    }
 
 
  if (! sunos_hash_table (info)->dynamic_sections_needed)
  if (! sunos_hash_table (info)->dynamic_sections_needed)
    return TRUE;
    return TRUE;
  if (! info->shared)
  if (! info->shared)
    {
    {
      if (h == NULL
      if (h == NULL
          || h->dynindx == -1
          || h->dynindx == -1
          || h->root.root.type != bfd_link_hash_undefined
          || h->root.root.type != bfd_link_hash_undefined
          || (h->flags & SUNOS_DEF_REGULAR) != 0
          || (h->flags & SUNOS_DEF_REGULAR) != 0
          || (h->flags & SUNOS_DEF_DYNAMIC) == 0
          || (h->flags & SUNOS_DEF_DYNAMIC) == 0
          || (h->root.root.u.undef.abfd->flags & DYNAMIC) == 0)
          || (h->root.root.u.undef.abfd->flags & DYNAMIC) == 0)
        return TRUE;
        return TRUE;
    }
    }
  else
  else
    {
    {
      if (h != NULL
      if (h != NULL
          && (h->dynindx == -1
          && (h->dynindx == -1
              || jmptbl
              || jmptbl
              || strcmp (h->root.root.root.string,
              || strcmp (h->root.root.root.string,
                         "__GLOBAL_OFFSET_TABLE_") == 0))
                         "__GLOBAL_OFFSET_TABLE_") == 0))
        return TRUE;
        return TRUE;
    }
    }
 
 
  /* It looks like this is a reloc we are supposed to copy.  */
  /* It looks like this is a reloc we are supposed to copy.  */
 
 
  s = bfd_get_section_by_name (dynobj, ".dynrel");
  s = bfd_get_section_by_name (dynobj, ".dynrel");
  BFD_ASSERT (s != NULL);
  BFD_ASSERT (s != NULL);
  BFD_ASSERT (s->reloc_count * obj_reloc_entry_size (dynobj) < s->size);
  BFD_ASSERT (s->reloc_count * obj_reloc_entry_size (dynobj) < s->size);
 
 
  p = s->contents + s->reloc_count * obj_reloc_entry_size (dynobj);
  p = s->contents + s->reloc_count * obj_reloc_entry_size (dynobj);
 
 
  /* Copy the reloc over.  */
  /* Copy the reloc over.  */
  memcpy (p, reloc, obj_reloc_entry_size (dynobj));
  memcpy (p, reloc, obj_reloc_entry_size (dynobj));
 
 
  if (h != NULL)
  if (h != NULL)
    indx = h->dynindx;
    indx = h->dynindx;
  else
  else
    indx = 0;
    indx = 0;
 
 
  /* Adjust the address and symbol index.  */
  /* Adjust the address and symbol index.  */
  if (obj_reloc_entry_size (dynobj) == RELOC_STD_SIZE)
  if (obj_reloc_entry_size (dynobj) == RELOC_STD_SIZE)
    {
    {
      struct reloc_std_external *srel;
      struct reloc_std_external *srel;
 
 
      srel = (struct reloc_std_external *) p;
      srel = (struct reloc_std_external *) p;
      PUT_WORD (dynobj,
      PUT_WORD (dynobj,
                (GET_WORD (dynobj, srel->r_address)
                (GET_WORD (dynobj, srel->r_address)
                 + input_section->output_section->vma
                 + input_section->output_section->vma
                 + input_section->output_offset),
                 + input_section->output_offset),
                srel->r_address);
                srel->r_address);
      if (bfd_header_big_endian (dynobj))
      if (bfd_header_big_endian (dynobj))
        {
        {
          srel->r_index[0] = (bfd_byte) (indx >> 16);
          srel->r_index[0] = (bfd_byte) (indx >> 16);
          srel->r_index[1] = (bfd_byte) (indx >> 8);
          srel->r_index[1] = (bfd_byte) (indx >> 8);
          srel->r_index[2] = (bfd_byte)indx;
          srel->r_index[2] = (bfd_byte)indx;
        }
        }
      else
      else
        {
        {
          srel->r_index[2] = (bfd_byte) (indx >> 16);
          srel->r_index[2] = (bfd_byte) (indx >> 16);
          srel->r_index[1] = (bfd_byte) (indx >> 8);
          srel->r_index[1] = (bfd_byte) (indx >> 8);
          srel->r_index[0] = (bfd_byte)indx;
          srel->r_index[0] = (bfd_byte)indx;
        }
        }
      /* FIXME: We may have to change the addend for a PC relative
      /* FIXME: We may have to change the addend for a PC relative
         reloc.  */
         reloc.  */
    }
    }
  else
  else
    {
    {
      struct reloc_ext_external *erel;
      struct reloc_ext_external *erel;
 
 
      erel = (struct reloc_ext_external *) p;
      erel = (struct reloc_ext_external *) p;
      PUT_WORD (dynobj,
      PUT_WORD (dynobj,
                (GET_WORD (dynobj, erel->r_address)
                (GET_WORD (dynobj, erel->r_address)
                 + input_section->output_section->vma
                 + input_section->output_section->vma
                 + input_section->output_offset),
                 + input_section->output_offset),
                erel->r_address);
                erel->r_address);
      if (bfd_header_big_endian (dynobj))
      if (bfd_header_big_endian (dynobj))
        {
        {
          erel->r_index[0] = (bfd_byte) (indx >> 16);
          erel->r_index[0] = (bfd_byte) (indx >> 16);
          erel->r_index[1] = (bfd_byte) (indx >> 8);
          erel->r_index[1] = (bfd_byte) (indx >> 8);
          erel->r_index[2] = (bfd_byte)indx;
          erel->r_index[2] = (bfd_byte)indx;
        }
        }
      else
      else
        {
        {
          erel->r_index[2] = (bfd_byte) (indx >> 16);
          erel->r_index[2] = (bfd_byte) (indx >> 16);
          erel->r_index[1] = (bfd_byte) (indx >> 8);
          erel->r_index[1] = (bfd_byte) (indx >> 8);
          erel->r_index[0] = (bfd_byte)indx;
          erel->r_index[0] = (bfd_byte)indx;
        }
        }
      if (pcrel && h != NULL)
      if (pcrel && h != NULL)
        {
        {
          /* Adjust the addend for the change in address.  */
          /* Adjust the addend for the change in address.  */
          PUT_WORD (dynobj,
          PUT_WORD (dynobj,
                    (GET_WORD (dynobj, erel->r_addend)
                    (GET_WORD (dynobj, erel->r_addend)
                     - (input_section->output_section->vma
                     - (input_section->output_section->vma
                        + input_section->output_offset
                        + input_section->output_offset
                        - input_section->vma)),
                        - input_section->vma)),
                    erel->r_addend);
                    erel->r_addend);
        }
        }
    }
    }
 
 
  ++s->reloc_count;
  ++s->reloc_count;
 
 
  if (h != NULL)
  if (h != NULL)
    *skip = TRUE;
    *skip = TRUE;
 
 
  return TRUE;
  return TRUE;
}
}
 
 
/* Finish up the dynamic linking information.  */
/* Finish up the dynamic linking information.  */
 
 
static bfd_boolean
static bfd_boolean
sunos_finish_dynamic_link (bfd *abfd, struct bfd_link_info *info)
sunos_finish_dynamic_link (bfd *abfd, struct bfd_link_info *info)
{
{
  bfd *dynobj;
  bfd *dynobj;
  asection *o;
  asection *o;
  asection *s;
  asection *s;
  asection *sdyn;
  asection *sdyn;
 
 
  if (! sunos_hash_table (info)->dynamic_sections_needed
  if (! sunos_hash_table (info)->dynamic_sections_needed
      && ! sunos_hash_table (info)->got_needed)
      && ! sunos_hash_table (info)->got_needed)
    return TRUE;
    return TRUE;
 
 
  dynobj = sunos_hash_table (info)->dynobj;
  dynobj = sunos_hash_table (info)->dynobj;
 
 
  sdyn = bfd_get_section_by_name (dynobj, ".dynamic");
  sdyn = bfd_get_section_by_name (dynobj, ".dynamic");
  BFD_ASSERT (sdyn != NULL);
  BFD_ASSERT (sdyn != NULL);
 
 
  /* Finish up the .need section.  The linker emulation code filled it
  /* Finish up the .need section.  The linker emulation code filled it
     in, but with offsets from the start of the section instead of
     in, but with offsets from the start of the section instead of
     real addresses.  Now that we know the section location, we can
     real addresses.  Now that we know the section location, we can
     fill in the final values.  */
     fill in the final values.  */
  s = bfd_get_section_by_name (dynobj, ".need");
  s = bfd_get_section_by_name (dynobj, ".need");
  if (s != NULL && s->size != 0)
  if (s != NULL && s->size != 0)
    {
    {
      file_ptr filepos;
      file_ptr filepos;
      bfd_byte *p;
      bfd_byte *p;
 
 
      filepos = s->output_section->filepos + s->output_offset;
      filepos = s->output_section->filepos + s->output_offset;
      p = s->contents;
      p = s->contents;
      while (1)
      while (1)
        {
        {
          bfd_vma val;
          bfd_vma val;
 
 
          PUT_WORD (dynobj, GET_WORD (dynobj, p) + filepos, p);
          PUT_WORD (dynobj, GET_WORD (dynobj, p) + filepos, p);
          val = GET_WORD (dynobj, p + 12);
          val = GET_WORD (dynobj, p + 12);
          if (val == 0)
          if (val == 0)
            break;
            break;
          PUT_WORD (dynobj, val + filepos, p + 12);
          PUT_WORD (dynobj, val + filepos, p + 12);
          p += 16;
          p += 16;
        }
        }
    }
    }
 
 
  /* The first entry in the .got section is the address of the
  /* The first entry in the .got section is the address of the
     dynamic information, unless this is a shared library.  */
     dynamic information, unless this is a shared library.  */
  s = bfd_get_section_by_name (dynobj, ".got");
  s = bfd_get_section_by_name (dynobj, ".got");
  BFD_ASSERT (s != NULL);
  BFD_ASSERT (s != NULL);
  if (info->shared || sdyn->size == 0)
  if (info->shared || sdyn->size == 0)
    PUT_WORD (dynobj, 0, s->contents);
    PUT_WORD (dynobj, 0, s->contents);
  else
  else
    PUT_WORD (dynobj, sdyn->output_section->vma + sdyn->output_offset,
    PUT_WORD (dynobj, sdyn->output_section->vma + sdyn->output_offset,
              s->contents);
              s->contents);
 
 
  for (o = dynobj->sections; o != NULL; o = o->next)
  for (o = dynobj->sections; o != NULL; o = o->next)
    {
    {
      if ((o->flags & SEC_HAS_CONTENTS) != 0
      if ((o->flags & SEC_HAS_CONTENTS) != 0
          && o->contents != NULL)
          && o->contents != NULL)
        {
        {
          BFD_ASSERT (o->output_section != NULL
          BFD_ASSERT (o->output_section != NULL
                      && o->output_section->owner == abfd);
                      && o->output_section->owner == abfd);
          if (! bfd_set_section_contents (abfd, o->output_section,
          if (! bfd_set_section_contents (abfd, o->output_section,
                                          o->contents,
                                          o->contents,
                                          (file_ptr) o->output_offset,
                                          (file_ptr) o->output_offset,
                                          o->size))
                                          o->size))
            return FALSE;
            return FALSE;
        }
        }
    }
    }
 
 
  if (sdyn->size > 0)
  if (sdyn->size > 0)
    {
    {
      struct external_sun4_dynamic esd;
      struct external_sun4_dynamic esd;
      struct external_sun4_dynamic_link esdl;
      struct external_sun4_dynamic_link esdl;
      file_ptr pos;
      file_ptr pos;
 
 
      /* Finish up the dynamic link information.  */
      /* Finish up the dynamic link information.  */
      PUT_WORD (dynobj, (bfd_vma) 3, esd.ld_version);
      PUT_WORD (dynobj, (bfd_vma) 3, esd.ld_version);
      PUT_WORD (dynobj,
      PUT_WORD (dynobj,
                sdyn->output_section->vma + sdyn->output_offset + sizeof esd,
                sdyn->output_section->vma + sdyn->output_offset + sizeof esd,
                esd.ldd);
                esd.ldd);
      PUT_WORD (dynobj,
      PUT_WORD (dynobj,
                (sdyn->output_section->vma
                (sdyn->output_section->vma
                 + sdyn->output_offset
                 + sdyn->output_offset
                 + sizeof esd
                 + sizeof esd
                 + EXTERNAL_SUN4_DYNAMIC_DEBUGGER_SIZE),
                 + EXTERNAL_SUN4_DYNAMIC_DEBUGGER_SIZE),
                esd.ld);
                esd.ld);
 
 
      if (! bfd_set_section_contents (abfd, sdyn->output_section, &esd,
      if (! bfd_set_section_contents (abfd, sdyn->output_section, &esd,
                                      (file_ptr) sdyn->output_offset,
                                      (file_ptr) sdyn->output_offset,
                                      (bfd_size_type) sizeof esd))
                                      (bfd_size_type) sizeof esd))
        return FALSE;
        return FALSE;
 
 
      PUT_WORD (dynobj, (bfd_vma) 0, esdl.ld_loaded);
      PUT_WORD (dynobj, (bfd_vma) 0, esdl.ld_loaded);
 
 
      s = bfd_get_section_by_name (dynobj, ".need");
      s = bfd_get_section_by_name (dynobj, ".need");
      if (s == NULL || s->size == 0)
      if (s == NULL || s->size == 0)
        PUT_WORD (dynobj, (bfd_vma) 0, esdl.ld_need);
        PUT_WORD (dynobj, (bfd_vma) 0, esdl.ld_need);
      else
      else
        PUT_WORD (dynobj, s->output_section->filepos + s->output_offset,
        PUT_WORD (dynobj, s->output_section->filepos + s->output_offset,
                  esdl.ld_need);
                  esdl.ld_need);
 
 
      s = bfd_get_section_by_name (dynobj, ".rules");
      s = bfd_get_section_by_name (dynobj, ".rules");
      if (s == NULL || s->size == 0)
      if (s == NULL || s->size == 0)
        PUT_WORD (dynobj, (bfd_vma) 0, esdl.ld_rules);
        PUT_WORD (dynobj, (bfd_vma) 0, esdl.ld_rules);
      else
      else
        PUT_WORD (dynobj, s->output_section->filepos + s->output_offset,
        PUT_WORD (dynobj, s->output_section->filepos + s->output_offset,
                  esdl.ld_rules);
                  esdl.ld_rules);
 
 
      s = bfd_get_section_by_name (dynobj, ".got");
      s = bfd_get_section_by_name (dynobj, ".got");
      BFD_ASSERT (s != NULL);
      BFD_ASSERT (s != NULL);
      PUT_WORD (dynobj, s->output_section->vma + s->output_offset,
      PUT_WORD (dynobj, s->output_section->vma + s->output_offset,
                esdl.ld_got);
                esdl.ld_got);
 
 
      s = bfd_get_section_by_name (dynobj, ".plt");
      s = bfd_get_section_by_name (dynobj, ".plt");
      BFD_ASSERT (s != NULL);
      BFD_ASSERT (s != NULL);
      PUT_WORD (dynobj, s->output_section->vma + s->output_offset,
      PUT_WORD (dynobj, s->output_section->vma + s->output_offset,
                esdl.ld_plt);
                esdl.ld_plt);
      PUT_WORD (dynobj, s->size, esdl.ld_plt_sz);
      PUT_WORD (dynobj, s->size, esdl.ld_plt_sz);
 
 
      s = bfd_get_section_by_name (dynobj, ".dynrel");
      s = bfd_get_section_by_name (dynobj, ".dynrel");
      BFD_ASSERT (s != NULL);
      BFD_ASSERT (s != NULL);
      BFD_ASSERT (s->reloc_count * obj_reloc_entry_size (dynobj)
      BFD_ASSERT (s->reloc_count * obj_reloc_entry_size (dynobj)
                  == s->size);
                  == s->size);
      PUT_WORD (dynobj, s->output_section->filepos + s->output_offset,
      PUT_WORD (dynobj, s->output_section->filepos + s->output_offset,
                esdl.ld_rel);
                esdl.ld_rel);
 
 
      s = bfd_get_section_by_name (dynobj, ".hash");
      s = bfd_get_section_by_name (dynobj, ".hash");
      BFD_ASSERT (s != NULL);
      BFD_ASSERT (s != NULL);
      PUT_WORD (dynobj, s->output_section->filepos + s->output_offset,
      PUT_WORD (dynobj, s->output_section->filepos + s->output_offset,
                esdl.ld_hash);
                esdl.ld_hash);
 
 
      s = bfd_get_section_by_name (dynobj, ".dynsym");
      s = bfd_get_section_by_name (dynobj, ".dynsym");
      BFD_ASSERT (s != NULL);
      BFD_ASSERT (s != NULL);
      PUT_WORD (dynobj, s->output_section->filepos + s->output_offset,
      PUT_WORD (dynobj, s->output_section->filepos + s->output_offset,
                esdl.ld_stab);
                esdl.ld_stab);
 
 
      PUT_WORD (dynobj, (bfd_vma) 0, esdl.ld_stab_hash);
      PUT_WORD (dynobj, (bfd_vma) 0, esdl.ld_stab_hash);
 
 
      PUT_WORD (dynobj, (bfd_vma) sunos_hash_table (info)->bucketcount,
      PUT_WORD (dynobj, (bfd_vma) sunos_hash_table (info)->bucketcount,
                esdl.ld_buckets);
                esdl.ld_buckets);
 
 
      s = bfd_get_section_by_name (dynobj, ".dynstr");
      s = bfd_get_section_by_name (dynobj, ".dynstr");
      BFD_ASSERT (s != NULL);
      BFD_ASSERT (s != NULL);
      PUT_WORD (dynobj, s->output_section->filepos + s->output_offset,
      PUT_WORD (dynobj, s->output_section->filepos + s->output_offset,
                esdl.ld_symbols);
                esdl.ld_symbols);
      PUT_WORD (dynobj, s->size, esdl.ld_symb_size);
      PUT_WORD (dynobj, s->size, esdl.ld_symb_size);
 
 
      /* The size of the text area is the size of the .text section
      /* The size of the text area is the size of the .text section
         rounded up to a page boundary.  FIXME: Should the page size be
         rounded up to a page boundary.  FIXME: Should the page size be
         conditional on something?  */
         conditional on something?  */
      PUT_WORD (dynobj,
      PUT_WORD (dynobj,
                BFD_ALIGN (obj_textsec (abfd)->size, 0x2000),
                BFD_ALIGN (obj_textsec (abfd)->size, 0x2000),
                esdl.ld_text);
                esdl.ld_text);
 
 
      pos = sdyn->output_offset;
      pos = sdyn->output_offset;
      pos += sizeof esd + EXTERNAL_SUN4_DYNAMIC_DEBUGGER_SIZE;
      pos += sizeof esd + EXTERNAL_SUN4_DYNAMIC_DEBUGGER_SIZE;
      if (! bfd_set_section_contents (abfd, sdyn->output_section, &esdl,
      if (! bfd_set_section_contents (abfd, sdyn->output_section, &esdl,
                                      pos, (bfd_size_type) sizeof esdl))
                                      pos, (bfd_size_type) sizeof esdl))
        return FALSE;
        return FALSE;
 
 
      abfd->flags |= DYNAMIC;
      abfd->flags |= DYNAMIC;
    }
    }
 
 
  return TRUE;
  return TRUE;
}
}
 
 

powered by: WebSVN 2.1.0

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