home *** CD-ROM | disk | FTP | other *** search
/ Geek Gadgets 1 / ADE-1.bin / ade-dist / binutils-2.7-src.tgz / tar.out / fsf / binutils / bfd / sunos.c < prev    next >
C/C++ Source or Header  |  1996-09-28  |  85KB  |  2,773 lines

  1. /* BFD backend for SunOS binaries.
  2.    Copyright (C) 1990, 91, 92, 93, 94, 95, 1996 Free Software Foundation, Inc.
  3.    Written by Cygnus Support.
  4.  
  5. This file is part of BFD, the Binary File Descriptor library.
  6.  
  7. This program is free software; you can redistribute it and/or modify
  8. it under the terms of the GNU General Public License as published by
  9. the Free Software Foundation; either version 2 of the License, or
  10. (at your option) any later version.
  11.  
  12. This program is distributed in the hope that it will be useful,
  13. but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  15. GNU General Public License for more details.
  16.  
  17. You should have received a copy of the GNU General Public License
  18. along with this program; if not, write to the Free Software
  19. Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.  */
  20.  
  21. #define TARGETNAME "a.out-sunos-big"
  22. #define MY(OP) CAT(sunos_big_,OP)
  23.  
  24. #include "bfd.h"
  25. #include "bfdlink.h"
  26. #include "libaout.h"
  27.  
  28. /* Static routines defined in this file.  */
  29.  
  30. static boolean sunos_read_dynamic_info PARAMS ((bfd *));
  31. static long sunos_get_dynamic_symtab_upper_bound PARAMS ((bfd *));
  32. static boolean sunos_slurp_dynamic_symtab PARAMS ((bfd *));
  33. static long sunos_canonicalize_dynamic_symtab PARAMS ((bfd *, asymbol **));
  34. static long sunos_get_dynamic_reloc_upper_bound PARAMS ((bfd *));
  35. static long sunos_canonicalize_dynamic_reloc
  36.   PARAMS ((bfd *, arelent **, asymbol **));
  37. static struct bfd_hash_entry *sunos_link_hash_newfunc
  38.   PARAMS ((struct bfd_hash_entry *, struct bfd_hash_table *, const char *));
  39. static struct bfd_link_hash_table *sunos_link_hash_table_create
  40.   PARAMS ((bfd *));
  41. static boolean sunos_create_dynamic_sections
  42.   PARAMS ((bfd *, struct bfd_link_info *, boolean));
  43. static boolean sunos_add_dynamic_symbols
  44.   PARAMS ((bfd *, struct bfd_link_info *, struct external_nlist **,
  45.        bfd_size_type *, char **));
  46. static boolean sunos_add_one_symbol
  47.   PARAMS ((struct bfd_link_info *, bfd *, const char *, flagword, asection *,
  48.        bfd_vma, const char *, boolean, boolean,
  49.        struct bfd_link_hash_entry **));
  50. static boolean sunos_scan_relocs
  51.   PARAMS ((struct bfd_link_info *, bfd *, asection *, bfd_size_type));
  52. static boolean sunos_scan_std_relocs
  53.   PARAMS ((struct bfd_link_info *, bfd *, asection *,
  54.        const struct reloc_std_external *, bfd_size_type));
  55. static boolean sunos_scan_ext_relocs
  56.   PARAMS ((struct bfd_link_info *, bfd *, asection *,
  57.        const struct reloc_ext_external *, bfd_size_type));
  58. static boolean sunos_link_dynamic_object
  59.   PARAMS ((struct bfd_link_info *, bfd *));
  60. static boolean sunos_write_dynamic_symbol
  61.   PARAMS ((bfd *, struct bfd_link_info *, struct aout_link_hash_entry *));
  62. static boolean sunos_check_dynamic_reloc
  63.   PARAMS ((struct bfd_link_info *, bfd *, asection *,
  64.        struct aout_link_hash_entry *, PTR, bfd_byte *, boolean *,
  65.        bfd_vma *));
  66. static boolean sunos_finish_dynamic_link
  67.   PARAMS ((bfd *, struct bfd_link_info *));
  68.  
  69. #define MY_get_dynamic_symtab_upper_bound sunos_get_dynamic_symtab_upper_bound
  70. #define MY_canonicalize_dynamic_symtab sunos_canonicalize_dynamic_symtab
  71. #define MY_get_dynamic_reloc_upper_bound sunos_get_dynamic_reloc_upper_bound
  72. #define MY_canonicalize_dynamic_reloc sunos_canonicalize_dynamic_reloc
  73. #define MY_bfd_link_hash_table_create sunos_link_hash_table_create
  74. #define MY_add_dynamic_symbols sunos_add_dynamic_symbols
  75. #define MY_add_one_symbol sunos_add_one_symbol
  76. #define MY_link_dynamic_object sunos_link_dynamic_object
  77. #define MY_write_dynamic_symbol sunos_write_dynamic_symbol
  78. #define MY_check_dynamic_reloc sunos_check_dynamic_reloc
  79. #define MY_finish_dynamic_link sunos_finish_dynamic_link
  80.  
  81. /* ??? Where should this go?  */
  82. #define MACHTYPE_OK(mtype) \
  83.   (((mtype) == M_SPARC && bfd_lookup_arch (bfd_arch_sparc, 0) != NULL) \
  84.    || ((mtype) == M_SPARCLET \
  85.        && bfd_lookup_arch (bfd_arch_sparc, bfd_mach_sparc_sparclet) != NULL) \
  86.    || (((mtype) == M_UNKNOWN || (mtype) == M_68010 || (mtype) == M_68020) \
  87.        && bfd_lookup_arch (bfd_arch_m68k, 0) != NULL))
  88.  
  89. /* Include the usual a.out support.  */
  90. #include "aoutf1.h"
  91.  
  92. /* SunOS shared library support.  We store a pointer to this structure
  93.    in obj_aout_dynamic_info (abfd).  */
  94.  
  95. struct sunos_dynamic_info
  96. {
  97.   /* Whether we found any dynamic information.  */
  98.   boolean valid;
  99.   /* Dynamic information.  */
  100.   struct internal_sun4_dynamic_link dyninfo;
  101.   /* Number of dynamic symbols.  */
  102.   unsigned long dynsym_count;
  103.   /* Read in nlists for dynamic symbols.  */
  104.   struct external_nlist *dynsym;
  105.   /* asymbol structures for dynamic symbols.  */
  106.   aout_symbol_type *canonical_dynsym;
  107.   /* Read in dynamic string table.  */
  108.   char *dynstr;
  109.   /* Number of dynamic relocs.  */
  110.   unsigned long dynrel_count;
  111.   /* Read in dynamic relocs.  This may be reloc_std_external or
  112.      reloc_ext_external.  */
  113.   PTR dynrel;
  114.   /* arelent structures for dynamic relocs.  */
  115.   arelent *canonical_dynrel;
  116. };
  117.  
  118. /* The hash table of dynamic symbols is composed of two word entries.
  119.    See include/aout/sun4.h for details.  */
  120.  
  121. #define HASH_ENTRY_SIZE (2 * BYTES_IN_WORD)
  122.  
  123. /* Read in the basic dynamic information.  This locates the __DYNAMIC
  124.    structure and uses it to find the dynamic_link structure.  It
  125.    creates and saves a sunos_dynamic_info structure.  If it can't find
  126.    __DYNAMIC, it sets the valid field of the sunos_dynamic_info
  127.    structure to false to avoid doing this work again.  */
  128.  
  129. static boolean
  130. sunos_read_dynamic_info (abfd)
  131.      bfd *abfd;
  132. {
  133.   struct sunos_dynamic_info *info;
  134.   asection *dynsec;
  135.   bfd_vma dynoff;
  136.   struct external_sun4_dynamic dyninfo;
  137.   unsigned long dynver;
  138.   struct external_sun4_dynamic_link linkinfo;
  139.  
  140.   if (obj_aout_dynamic_info (abfd) != (PTR) NULL)
  141.     return true;
  142.  
  143.   if ((abfd->flags & DYNAMIC) == 0)
  144.     {
  145.       bfd_set_error (bfd_error_invalid_operation);
  146.       return false;
  147.     }
  148.  
  149.   info = ((struct sunos_dynamic_info *)
  150.       bfd_zalloc (abfd, sizeof (struct sunos_dynamic_info)));
  151.   if (!info)
  152.     return false;
  153.   info->valid = false;
  154.   info->dynsym = NULL;
  155.   info->dynstr = NULL;
  156.   info->canonical_dynsym = NULL;
  157.   info->dynrel = NULL;
  158.   info->canonical_dynrel = NULL;
  159.   obj_aout_dynamic_info (abfd) = (PTR) info;
  160.  
  161.   /* This code used to look for the __DYNAMIC symbol to locate the dynamic
  162.      linking information.
  163.      However this inhibits recovering the dynamic symbols from a
  164.      stripped object file, so blindly assume that the dynamic linking
  165.      information is located at the start of the data section.
  166.      We could verify this assumption later by looking through the dynamic
  167.      symbols for the __DYNAMIC symbol.  */
  168.   if ((abfd->flags & DYNAMIC) == 0)
  169.     return true;
  170.   if (! bfd_get_section_contents (abfd, obj_datasec (abfd), (PTR) &dyninfo,
  171.                   (file_ptr) 0, sizeof dyninfo))
  172.     return true;
  173.  
  174.   dynver = GET_WORD (abfd, dyninfo.ld_version);
  175.   if (dynver != 2 && dynver != 3)
  176.     return true;
  177.  
  178.   dynoff = GET_WORD (abfd, dyninfo.ld);
  179.  
  180.   /* dynoff is a virtual address.  It is probably always in the .data
  181.      section, but this code should work even if it moves.  */
  182.   if (dynoff < bfd_get_section_vma (abfd, obj_datasec (abfd)))
  183.     dynsec = obj_textsec (abfd);
  184.   else
  185.     dynsec = obj_datasec (abfd);
  186.   dynoff -= bfd_get_section_vma (abfd, dynsec);
  187.   if (dynoff > bfd_section_size (abfd, dynsec))
  188.     return true;
  189.  
  190.   /* This executable appears to be dynamically linked in a way that we
  191.      can understand.  */
  192.   if (! bfd_get_section_contents (abfd, dynsec, (PTR) &linkinfo, dynoff,
  193.                   (bfd_size_type) sizeof linkinfo))
  194.     return true;
  195.  
  196.   /* Swap in the dynamic link information.  */
  197.   info->dyninfo.ld_loaded = GET_WORD (abfd, linkinfo.ld_loaded);
  198.   info->dyninfo.ld_need = GET_WORD (abfd, linkinfo.ld_need);
  199.   info->dyninfo.ld_rules = GET_WORD (abfd, linkinfo.ld_rules);
  200.   info->dyninfo.ld_got = GET_WORD (abfd, linkinfo.ld_got);
  201.   info->dyninfo.ld_plt = GET_WORD (abfd, linkinfo.ld_plt);
  202.   info->dyninfo.ld_rel = GET_WORD (abfd, linkinfo.ld_rel);
  203.   info->dyninfo.ld_hash = GET_WORD (abfd, linkinfo.ld_hash);
  204.   info->dyninfo.ld_stab = GET_WORD (abfd, linkinfo.ld_stab);
  205.   info->dyninfo.ld_stab_hash = GET_WORD (abfd, linkinfo.ld_stab_hash);
  206.   info->dyninfo.ld_buckets = GET_WORD (abfd, linkinfo.ld_buckets);
  207.   info->dyninfo.ld_symbols = GET_WORD (abfd, linkinfo.ld_symbols);
  208.   info->dyninfo.ld_symb_size = GET_WORD (abfd, linkinfo.ld_symb_size);
  209.   info->dyninfo.ld_text = GET_WORD (abfd, linkinfo.ld_text);
  210.   info->dyninfo.ld_plt_sz = GET_WORD (abfd, linkinfo.ld_plt_sz);
  211.  
  212.   /* Reportedly the addresses need to be offset by the size of the
  213.      exec header in an NMAGIC file.  */
  214.   if (adata (abfd).magic == n_magic)
  215.     {
  216.       unsigned long exec_bytes_size = adata (abfd).exec_bytes_size;
  217.  
  218.       info->dyninfo.ld_need += exec_bytes_size;
  219.       info->dyninfo.ld_rules += exec_bytes_size;
  220.       info->dyninfo.ld_rel += exec_bytes_size;
  221.       info->dyninfo.ld_hash += exec_bytes_size;
  222.       info->dyninfo.ld_stab += exec_bytes_size;
  223.       info->dyninfo.ld_symbols += exec_bytes_size;
  224.     }
  225.  
  226.   /* The only way to get the size of the symbol information appears to
  227.      be to determine the distance between it and the string table.  */
  228.   info->dynsym_count = ((info->dyninfo.ld_symbols - info->dyninfo.ld_stab)
  229.             / EXTERNAL_NLIST_SIZE);
  230.   BFD_ASSERT (info->dynsym_count * EXTERNAL_NLIST_SIZE
  231.           == (unsigned long) (info->dyninfo.ld_symbols
  232.                   - info->dyninfo.ld_stab));
  233.  
  234.   /* Similarly, the relocs end at the hash table.  */
  235.   info->dynrel_count = ((info->dyninfo.ld_hash - info->dyninfo.ld_rel)
  236.             / obj_reloc_entry_size (abfd));
  237.   BFD_ASSERT (info->dynrel_count * obj_reloc_entry_size (abfd)
  238.           == (unsigned long) (info->dyninfo.ld_hash
  239.                   - info->dyninfo.ld_rel));
  240.  
  241.   info->valid = true;
  242.  
  243.   return true;
  244. }
  245.  
  246. /* Return the amount of memory required for the dynamic symbols.  */
  247.  
  248. static long
  249. sunos_get_dynamic_symtab_upper_bound (abfd)
  250.      bfd *abfd;
  251. {
  252.   struct sunos_dynamic_info *info;
  253.  
  254.   if (! sunos_read_dynamic_info (abfd))
  255.     return -1;
  256.  
  257.   info = (struct sunos_dynamic_info *) obj_aout_dynamic_info (abfd);
  258.   if (! info->valid)
  259.     {
  260.       bfd_set_error (bfd_error_no_symbols);
  261.       return -1;
  262.     }
  263.  
  264.   return (info->dynsym_count + 1) * sizeof (asymbol *);
  265. }
  266.  
  267. /* Read the external dynamic symbols.  */
  268.  
  269. static boolean
  270. sunos_slurp_dynamic_symtab (abfd)
  271.      bfd *abfd;
  272. {
  273.   struct sunos_dynamic_info *info;
  274.  
  275.   /* Get the general dynamic information.  */
  276.   if (obj_aout_dynamic_info (abfd) == NULL)
  277.     {
  278.       if (! sunos_read_dynamic_info (abfd))
  279.       return false;
  280.     }
  281.  
  282.   info = (struct sunos_dynamic_info *) obj_aout_dynamic_info (abfd);
  283.   if (! info->valid)
  284.     {
  285.       bfd_set_error (bfd_error_no_symbols);
  286.       return false;
  287.     }
  288.  
  289.   /* Get the dynamic nlist structures.  */
  290.   if (info->dynsym == (struct external_nlist *) NULL)
  291.     {
  292.       info->dynsym = ((struct external_nlist *)
  293.               bfd_alloc (abfd,
  294.                  (info->dynsym_count
  295.                   * EXTERNAL_NLIST_SIZE)));
  296.       if (info->dynsym == NULL && info->dynsym_count != 0)
  297.     return false;
  298.       if (bfd_seek (abfd, info->dyninfo.ld_stab, SEEK_SET) != 0
  299.       || (bfd_read ((PTR) info->dynsym, info->dynsym_count,
  300.             EXTERNAL_NLIST_SIZE, abfd)
  301.           != info->dynsym_count * EXTERNAL_NLIST_SIZE))
  302.     {
  303.       if (info->dynsym != NULL)
  304.         {
  305.           bfd_release (abfd, info->dynsym);
  306.           info->dynsym = NULL;
  307.         }
  308.       return false;
  309.     }
  310.     }
  311.  
  312.   /* Get the dynamic strings.  */
  313.   if (info->dynstr == (char *) NULL)
  314.     {
  315.       info->dynstr = (char *) bfd_alloc (abfd, info->dyninfo.ld_symb_size);
  316.       if (info->dynstr == NULL && info->dyninfo.ld_symb_size != 0)
  317.     return false;
  318.       if (bfd_seek (abfd, info->dyninfo.ld_symbols, SEEK_SET) != 0
  319.       || (bfd_read ((PTR) info->dynstr, 1, info->dyninfo.ld_symb_size,
  320.             abfd)
  321.           != info->dyninfo.ld_symb_size))
  322.     {
  323.       if (info->dynstr != NULL)
  324.         {
  325.           bfd_release (abfd, info->dynstr);
  326.           info->dynstr = NULL;
  327.         }
  328.       return false;
  329.     }
  330.     }
  331.  
  332.   return true;
  333. }
  334.  
  335. /* Read in the dynamic symbols.  */
  336.  
  337. static long
  338. sunos_canonicalize_dynamic_symtab (abfd, storage)
  339.      bfd *abfd;
  340.      asymbol **storage;
  341. {
  342.   struct sunos_dynamic_info *info;
  343.   unsigned long i;
  344.  
  345.   if (! sunos_slurp_dynamic_symtab (abfd))
  346.     return -1;
  347.  
  348.   info = (struct sunos_dynamic_info *) obj_aout_dynamic_info (abfd);
  349.  
  350. #ifdef CHECK_DYNAMIC_HASH
  351.   /* Check my understanding of the dynamic hash table by making sure
  352.      that each symbol can be located in the hash table.  */
  353.   {
  354.     bfd_size_type table_size;
  355.     bfd_byte *table;
  356.     bfd_size_type i;
  357.  
  358.     if (info->dyninfo.ld_buckets > info->dynsym_count)
  359.       abort ();
  360.     table_size = info->dyninfo.ld_stab - info->dyninfo.ld_hash;
  361.     table = (bfd_byte *) bfd_malloc (table_size);
  362.     if (table == NULL && table_size != 0)
  363.       abort ();
  364.     if (bfd_seek (abfd, info->dyninfo.ld_hash, SEEK_SET) != 0
  365.     || bfd_read ((PTR) table, 1, table_size, abfd) != table_size)
  366.       abort ();
  367.     for (i = 0; i < info->dynsym_count; i++)
  368.       {
  369.     unsigned char *name;
  370.     unsigned long hash;
  371.  
  372.     name = ((unsigned char *) info->dynstr
  373.         + GET_WORD (abfd, info->dynsym[i].e_strx));
  374.     hash = 0;
  375.     while (*name != '\0')
  376.       hash = (hash << 1) + *name++;
  377.     hash &= 0x7fffffff;
  378.     hash %= info->dyninfo.ld_buckets;
  379.     while (GET_WORD (abfd, table + hash * HASH_ENTRY_SIZE) != i)
  380.       {
  381.         hash = GET_WORD (abfd,
  382.                  table + hash * HASH_ENTRY_SIZE + BYTES_IN_WORD);
  383.         if (hash == 0 || hash >= table_size / HASH_ENTRY_SIZE)
  384.           abort ();
  385.       }
  386.       }
  387.     free (table);
  388.   }
  389. #endif /* CHECK_DYNAMIC_HASH */
  390.  
  391.   /* Get the asymbol structures corresponding to the dynamic nlist
  392.      structures.  */
  393.   if (info->canonical_dynsym == (aout_symbol_type *) NULL)
  394.     {
  395.       info->canonical_dynsym = ((aout_symbol_type *)
  396.                 bfd_alloc (abfd,
  397.                        (info->dynsym_count
  398.                         * sizeof (aout_symbol_type))));
  399.       if (info->canonical_dynsym == NULL && info->dynsym_count != 0)
  400.     return -1;
  401.  
  402.       if (! aout_32_translate_symbol_table (abfd, info->canonical_dynsym,
  403.                         info->dynsym, info->dynsym_count,
  404.                         info->dynstr,
  405.                         info->dyninfo.ld_symb_size,
  406.                         true))
  407.     {
  408.       if (info->canonical_dynsym != NULL)
  409.         {
  410.           bfd_release (abfd, info->canonical_dynsym);
  411.           info->canonical_dynsym = NULL;
  412.         }
  413.       return -1;
  414.     }
  415.     }
  416.  
  417.   /* Return pointers to the dynamic asymbol structures.  */
  418.   for (i = 0; i < info->dynsym_count; i++)
  419.     *storage++ = (asymbol *) (info->canonical_dynsym + i);
  420.   *storage = NULL;
  421.  
  422.   return info->dynsym_count;
  423. }
  424.  
  425. /* Return the amount of memory required for the dynamic relocs.  */
  426.  
  427. static long
  428. sunos_get_dynamic_reloc_upper_bound (abfd)
  429.      bfd *abfd;
  430. {
  431.   struct sunos_dynamic_info *info;
  432.  
  433.   if (! sunos_read_dynamic_info (abfd))
  434.     return -1;
  435.  
  436.   info = (struct sunos_dynamic_info *) obj_aout_dynamic_info (abfd);
  437.   if (! info->valid)
  438.     {
  439.       bfd_set_error (bfd_error_no_symbols);
  440.       return -1;
  441.     }
  442.  
  443.   return (info->dynrel_count + 1) * sizeof (arelent *);
  444. }
  445.  
  446. /* Read in the dynamic relocs.  */
  447.  
  448. static long
  449. sunos_canonicalize_dynamic_reloc (abfd, storage, syms)
  450.      bfd *abfd;
  451.      arelent **storage;
  452.      asymbol **syms;
  453. {
  454.   struct sunos_dynamic_info *info;
  455.   unsigned long i;
  456.  
  457.   /* Get the general dynamic information.  */
  458.   if (obj_aout_dynamic_info (abfd) == (PTR) NULL)
  459.     {
  460.       if (! sunos_read_dynamic_info (abfd))
  461.     return -1;
  462.     }
  463.  
  464.   info = (struct sunos_dynamic_info *) obj_aout_dynamic_info (abfd);
  465.   if (! info->valid)
  466.     {
  467.       bfd_set_error (bfd_error_no_symbols);
  468.       return -1;
  469.     }
  470.  
  471.   /* Get the dynamic reloc information.  */
  472.   if (info->dynrel == NULL)
  473.     {
  474.       info->dynrel = (PTR) bfd_alloc (abfd,
  475.                       (info->dynrel_count
  476.                        * obj_reloc_entry_size (abfd)));
  477.       if (info->dynrel == NULL && info->dynrel_count != 0)
  478.     return -1;
  479.       if (bfd_seek (abfd, info->dyninfo.ld_rel, SEEK_SET) != 0
  480.       || (bfd_read ((PTR) info->dynrel, info->dynrel_count,
  481.             obj_reloc_entry_size (abfd), abfd)
  482.           != info->dynrel_count * obj_reloc_entry_size (abfd)))
  483.     {
  484.       if (info->dynrel != NULL)
  485.         {
  486.           bfd_release (abfd, info->dynrel);
  487.           info->dynrel = NULL;
  488.         }
  489.       return -1;
  490.     }
  491.     }
  492.  
  493.   /* Get the arelent structures corresponding to the dynamic reloc
  494.      information.  */
  495.   if (info->canonical_dynrel == (arelent *) NULL)
  496.     {
  497.       arelent *to;
  498.  
  499.       info->canonical_dynrel = ((arelent *)
  500.                 bfd_alloc (abfd,
  501.                        (info->dynrel_count
  502.                         * sizeof (arelent))));
  503.       if (info->canonical_dynrel == NULL && info->dynrel_count != 0)
  504.     return -1;
  505.       
  506.       to = info->canonical_dynrel;
  507.  
  508.       if (obj_reloc_entry_size (abfd) == RELOC_EXT_SIZE)
  509.     {
  510.       register struct reloc_ext_external *p;
  511.       struct reloc_ext_external *pend;
  512.  
  513.       p = (struct reloc_ext_external *) info->dynrel;
  514.       pend = p + info->dynrel_count;
  515.       for (; p < pend; p++, to++)
  516.         NAME(aout,swap_ext_reloc_in) (abfd, p, to, syms,
  517.                       info->dynsym_count);
  518.     }
  519.       else
  520.     {
  521.       register struct reloc_std_external *p;
  522.       struct reloc_std_external *pend;
  523.  
  524.       p = (struct reloc_std_external *) info->dynrel;
  525.       pend = p + info->dynrel_count;
  526.       for (; p < pend; p++, to++)
  527.         NAME(aout,swap_std_reloc_in) (abfd, p, to, syms,
  528.                       info->dynsym_count);
  529.     }
  530.     }
  531.  
  532.   /* Return pointers to the dynamic arelent structures.  */
  533.   for (i = 0; i < info->dynrel_count; i++)
  534.     *storage++ = info->canonical_dynrel + i;
  535.   *storage = NULL;
  536.  
  537.   return info->dynrel_count;
  538. }
  539.  
  540. /* Code to handle linking of SunOS shared libraries.  */
  541.  
  542. /* A SPARC procedure linkage table entry is 12 bytes.  The first entry
  543.    in the table is a jump which is filled in by the runtime linker.
  544.    The remaining entries are branches back to the first entry,
  545.    followed by an index into the relocation table encoded to look like
  546.    a sethi of %g0.  */
  547.  
  548. #define SPARC_PLT_ENTRY_SIZE (12)
  549.  
  550. static const bfd_byte sparc_plt_first_entry[SPARC_PLT_ENTRY_SIZE] =
  551. {
  552.   /* sethi %hi(0),%g1; address filled in by runtime linker.  */
  553.   0x3, 0, 0, 0,
  554.   /* jmp %g1; offset filled in by runtime linker.  */
  555.   0x81, 0xc0, 0x60, 0,
  556.   /* nop */
  557.   0x1, 0, 0, 0
  558. };
  559.  
  560. /* save %sp, -96, %sp */
  561. #define SPARC_PLT_ENTRY_WORD0 0x9de3bfa0
  562. /* call; address filled in later.  */
  563. #define SPARC_PLT_ENTRY_WORD1 0x40000000
  564. /* sethi; reloc index filled in later.  */
  565. #define SPARC_PLT_ENTRY_WORD2 0x01000000
  566.  
  567. /* This sequence is used when for the jump table entry to a defined
  568.    symbol in a complete executable.  It is used when linking PIC
  569.    compiled code which is not being put into a shared library.  */
  570. /* sethi <address to be filled in later>, %g1 */
  571. #define SPARC_PLT_PIC_WORD0 0x03000000
  572. /* jmp %g1 + <address to be filled in later> */
  573. #define SPARC_PLT_PIC_WORD1 0x81c06000
  574. /* nop */
  575. #define SPARC_PLT_PIC_WORD2 0x01000000
  576.  
  577. /* An m68k procedure linkage table entry is 8 bytes.  The first entry
  578.    in the table is a jump which is filled in the by the runtime
  579.    linker.  The remaining entries are branches back to the first
  580.    entry, followed by a two byte index into the relocation table.  */
  581.  
  582. #define M68K_PLT_ENTRY_SIZE (8)
  583.  
  584. static const bfd_byte m68k_plt_first_entry[M68K_PLT_ENTRY_SIZE] =
  585. {
  586.   /* jmps @# */
  587.   0x4e, 0xf9,
  588.   /* Filled in by runtime linker with a magic address.  */
  589.   0, 0, 0, 0,
  590.   /* Not used?  */
  591.   0, 0
  592. };
  593.  
  594. /* bsrl */
  595. #define M68K_PLT_ENTRY_WORD0 (0x61ff)
  596. /* Remaining words filled in later.  */
  597.  
  598. /* An entry in the SunOS linker hash table.  */
  599.  
  600. struct sunos_link_hash_entry
  601. {
  602.   struct aout_link_hash_entry root;
  603.  
  604.   /* If this is a dynamic symbol, this is its index into the dynamic
  605.      symbol table.  This is initialized to -1.  As the linker looks at
  606.      the input files, it changes this to -2 if it will be added to the
  607.      dynamic symbol table.  After all the input files have been seen,
  608.      the linker will know whether to build a dynamic symbol table; if
  609.      it does build one, this becomes the index into the table.  */
  610.   long dynindx;
  611.  
  612.   /* If this is a dynamic symbol, this is the index of the name in the
  613.      dynamic symbol string table.  */
  614.   long dynstr_index;
  615.  
  616.   /* The offset into the global offset table used for this symbol.  If
  617.      the symbol does not require a GOT entry, this is 0.  */
  618.   bfd_vma got_offset;
  619.  
  620.   /* The offset into the procedure linkage table used for this symbol.
  621.      If the symbol does not require a PLT entry, this is 0.  */
  622.   bfd_vma plt_offset;
  623.  
  624.   /* Some linker flags.  */
  625.   unsigned char flags;
  626.   /* Symbol is referenced by a regular object.  */
  627. #define SUNOS_REF_REGULAR 01
  628.   /* Symbol is defined by a regular object.  */
  629. #define SUNOS_DEF_REGULAR 02
  630.   /* Symbol is referenced by a dynamic object.  */
  631. #define SUNOS_REF_DYNAMIC 04
  632.   /* Symbol is defined by a dynamic object.  */
  633. #define SUNOS_DEF_DYNAMIC 010
  634.   /* Symbol is a constructor symbol in a regular object.  */
  635. #define SUNOS_CONSTRUCTOR 020
  636. };
  637.  
  638. /* The SunOS linker hash table.  */
  639.  
  640. struct sunos_link_hash_table
  641. {
  642.   struct aout_link_hash_table root;
  643.  
  644.   /* The object which holds the dynamic sections.  */
  645.   bfd *dynobj;
  646.  
  647.   /* Whether we have created the dynamic sections.  */
  648.   boolean dynamic_sections_created;
  649.  
  650.   /* Whether we need the dynamic sections.  */
  651.   boolean dynamic_sections_needed;
  652.  
  653.   /* The number of dynamic symbols.  */
  654.   size_t dynsymcount;
  655.  
  656.   /* The number of buckets in the hash table.  */
  657.   size_t bucketcount;
  658.  
  659.   /* The list of dynamic objects needed by dynamic objects included in
  660.      the link.  */
  661.   struct bfd_link_needed_list *needed;
  662. };
  663.  
  664. /* Routine to create an entry in an SunOS link hash table.  */
  665.  
  666. static struct bfd_hash_entry *
  667. sunos_link_hash_newfunc (entry, table, string)
  668.      struct bfd_hash_entry *entry;
  669.      struct bfd_hash_table *table;
  670.      const char *string;
  671. {
  672.   struct sunos_link_hash_entry *ret = (struct sunos_link_hash_entry *) entry;
  673.  
  674.   /* Allocate the structure if it has not already been allocated by a
  675.      subclass.  */
  676.   if (ret == (struct sunos_link_hash_entry *) NULL)
  677.     ret = ((struct sunos_link_hash_entry *)
  678.        bfd_hash_allocate (table, sizeof (struct sunos_link_hash_entry)));
  679.   if (ret == (struct sunos_link_hash_entry *) NULL)
  680.     return (struct bfd_hash_entry *) ret;
  681.  
  682.   /* Call the allocation method of the superclass.  */
  683.   ret = ((struct sunos_link_hash_entry *)
  684.      NAME(aout,link_hash_newfunc) ((struct bfd_hash_entry *) ret,
  685.                        table, string));
  686.   if (ret != NULL)
  687.     {
  688.       /* Set local fields.  */
  689.       ret->dynindx = -1;
  690.       ret->dynstr_index = -1;
  691.       ret->got_offset = 0;
  692.       ret->plt_offset = 0;
  693.       ret->flags = 0;
  694.     }
  695.  
  696.   return (struct bfd_hash_entry *) ret;
  697. }
  698.  
  699. /* Create a SunOS link hash table.  */
  700.  
  701. static struct bfd_link_hash_table *
  702. sunos_link_hash_table_create (abfd)
  703.      bfd *abfd;
  704. {
  705.   struct sunos_link_hash_table *ret;
  706.  
  707.   ret = ((struct sunos_link_hash_table *)
  708.      bfd_alloc (abfd, sizeof (struct sunos_link_hash_table)));
  709.   if (ret == (struct sunos_link_hash_table *) NULL)
  710.     return (struct bfd_link_hash_table *) NULL;
  711.   if (! NAME(aout,link_hash_table_init) (&ret->root, abfd,
  712.                      sunos_link_hash_newfunc))
  713.     {
  714.       bfd_release (abfd, ret);
  715.       return (struct bfd_link_hash_table *) NULL;
  716.     }
  717.  
  718.   ret->dynobj = NULL;
  719.   ret->dynamic_sections_created = false;
  720.   ret->dynamic_sections_needed = false;
  721.   ret->dynsymcount = 0;
  722.   ret->bucketcount = 0;
  723.   ret->needed = NULL;
  724.  
  725.   return &ret->root.root;
  726. }
  727.  
  728. /* Look up an entry in an SunOS link hash table.  */
  729.  
  730. #define sunos_link_hash_lookup(table, string, create, copy, follow) \
  731.   ((struct sunos_link_hash_entry *) \
  732.    aout_link_hash_lookup (&(table)->root, (string), (create), (copy),\
  733.               (follow)))
  734.  
  735. /* Traverse a SunOS link hash table.  */
  736.  
  737. #define sunos_link_hash_traverse(table, func, info)            \
  738.   (aout_link_hash_traverse                        \
  739.    (&(table)->root,                            \
  740.     (boolean (*) PARAMS ((struct aout_link_hash_entry *, PTR))) (func),    \
  741.     (info)))
  742.  
  743. /* Get the SunOS link hash table from the info structure.  This is
  744.    just a cast.  */
  745.  
  746. #define sunos_hash_table(p) ((struct sunos_link_hash_table *) ((p)->hash))
  747.  
  748. static boolean sunos_scan_dynamic_symbol
  749.   PARAMS ((struct sunos_link_hash_entry *, PTR));
  750.  
  751. /* Create the dynamic sections needed if we are linking against a
  752.    dynamic object, or if we are linking PIC compiled code.  ABFD is a
  753.    bfd we can attach the dynamic sections to.  The linker script will
  754.    look for these special sections names and put them in the right
  755.    place in the output file.  See include/aout/sun4.h for more details
  756.    of the dynamic linking information.  */
  757.  
  758. static boolean
  759. sunos_create_dynamic_sections (abfd, info, needed)
  760.      bfd *abfd;
  761.      struct bfd_link_info *info;
  762.      boolean needed;
  763. {
  764.   asection *s;
  765.  
  766.   if (! sunos_hash_table (info)->dynamic_sections_created)
  767.     {
  768.       flagword flags;
  769.  
  770.       sunos_hash_table (info)->dynobj = abfd;
  771.  
  772.       flags = SEC_ALLOC | SEC_LOAD | SEC_HAS_CONTENTS | SEC_IN_MEMORY;
  773.  
  774.       /* The .dynamic section holds the basic dynamic information: the
  775.      sun4_dynamic structure, the dynamic debugger information, and
  776.      the sun4_dynamic_link structure.  */
  777.       s = bfd_make_section (abfd, ".dynamic");
  778.       if (s == NULL
  779.       || ! bfd_set_section_flags (abfd, s, flags)
  780.       || ! bfd_set_section_alignment (abfd, s, 2))
  781.     return false;
  782.  
  783.       /* The .got section holds the global offset table.  The address
  784.      is put in the ld_got field.  */
  785.       s = bfd_make_section (abfd, ".got");
  786.       if (s == NULL
  787.       || ! bfd_set_section_flags (abfd, s, flags)
  788.       || ! bfd_set_section_alignment (abfd, s, 2))
  789.     return false;
  790.  
  791.       /* The .plt section holds the procedure linkage table.  The
  792.      address is put in the ld_plt field.  */
  793.       s = bfd_make_section (abfd, ".plt");
  794.       if (s == NULL
  795.       || ! bfd_set_section_flags (abfd, s, flags | SEC_CODE)
  796.       || ! bfd_set_section_alignment (abfd, s, 2))
  797.     return false;
  798.  
  799.       /* The .dynrel section holds the dynamic relocs.  The address is
  800.      put in the ld_rel field.  */
  801.       s = bfd_make_section (abfd, ".dynrel");
  802.       if (s == NULL
  803.       || ! bfd_set_section_flags (abfd, s, flags | SEC_READONLY)
  804.       || ! bfd_set_section_alignment (abfd, s, 2))
  805.     return false;
  806.  
  807.       /* The .hash section holds the dynamic hash table.  The address
  808.      is put in the ld_hash field.  */
  809.       s = bfd_make_section (abfd, ".hash");
  810.       if (s == NULL
  811.       || ! bfd_set_section_flags (abfd, s, flags | SEC_READONLY)
  812.       || ! bfd_set_section_alignment (abfd, s, 2))
  813.     return false;
  814.  
  815.       /* The .dynsym section holds the dynamic symbols.  The address
  816.      is put in the ld_stab field.  */
  817.       s = bfd_make_section (abfd, ".dynsym");
  818.       if (s == NULL
  819.       || ! bfd_set_section_flags (abfd, s, flags | SEC_READONLY)
  820.       || ! bfd_set_section_alignment (abfd, s, 2))
  821.     return false;
  822.  
  823.       /* The .dynstr section holds the dynamic symbol string table.
  824.      The address is put in the ld_symbols field.  */
  825.       s = bfd_make_section (abfd, ".dynstr");
  826.       if (s == NULL
  827.       || ! bfd_set_section_flags (abfd, s, flags | SEC_READONLY)
  828.       || ! bfd_set_section_alignment (abfd, s, 2))
  829.     return false;
  830.  
  831.       sunos_hash_table (info)->dynamic_sections_created = true;
  832.     }
  833.  
  834.   if (needed && ! sunos_hash_table (info)->dynamic_sections_needed)
  835.     {
  836.       bfd *dynobj;
  837.  
  838.       dynobj = sunos_hash_table (info)->dynobj;
  839.  
  840.       s = bfd_get_section_by_name (dynobj, ".got");
  841.       s->_raw_size = BYTES_IN_WORD;
  842.  
  843.       sunos_hash_table (info)->dynamic_sections_needed = true;
  844.     }
  845.  
  846.   return true;
  847. }
  848.  
  849. /* Add dynamic symbols during a link.  This is called by the a.out
  850.    backend linker for each object it encounters.  */
  851.  
  852. static boolean
  853. sunos_add_dynamic_symbols (abfd, info, symsp, sym_countp, stringsp)
  854.      bfd *abfd;
  855.      struct bfd_link_info *info;
  856.      struct external_nlist **symsp;
  857.      bfd_size_type *sym_countp;
  858.      char **stringsp;
  859. {
  860.   asection *s;
  861.   bfd *dynobj;
  862.   struct sunos_dynamic_info *dinfo;
  863.   unsigned long need;
  864.  
  865.   /* Make sure we have all the required sections.  */
  866.   if (! sunos_create_dynamic_sections (abfd, info,
  867.                        (((abfd->flags & DYNAMIC) != 0
  868.                      && ! info->relocateable)
  869.                     ? true
  870.                     : false)))
  871.     return false;
  872.  
  873.   /* There is nothing else to do for a normal object.  */
  874.   if ((abfd->flags & DYNAMIC) == 0)
  875.     return true;
  876.  
  877.   /* We do not want to include the sections in a dynamic object in the
  878.      output file.  We hack by simply clobbering the list of sections
  879.      in the BFD.  This could be handled more cleanly by, say, a new
  880.      section flag; the existing SEC_NEVER_LOAD flag is not the one we
  881.      want, because that one still implies that the section takes up
  882.      space in the output file.  */
  883.   abfd->sections = NULL;
  884.  
  885.   /* The native linker seems to just ignore dynamic objects when -r is
  886.      used.  */
  887.   if (info->relocateable)
  888.     return true;
  889.  
  890.   /* There's no hope of using a dynamic object which does not exactly
  891.      match the format of the output file.  */
  892.   if (info->hash->creator != abfd->xvec)
  893.     {
  894.       bfd_set_error (bfd_error_invalid_operation);
  895.       return false;
  896.     }
  897.  
  898.   /* Make sure we have a .need and a .rules sections.  These are only
  899.      needed if there really is a dynamic object in the link, so they
  900.      are not added by sunos_create_dynamic_sections.  */
  901.   dynobj = sunos_hash_table (info)->dynobj;
  902.   if (bfd_get_section_by_name (dynobj, ".need") == NULL)
  903.     {
  904.       /* The .need section holds the list of names of shared objets
  905.      which must be included at runtime.  The address of this
  906.      section is put in the ld_need field.  */
  907.       s = bfd_make_section (dynobj, ".need");
  908.       if (s == NULL
  909.       || ! bfd_set_section_flags (dynobj, s,
  910.                       (SEC_ALLOC
  911.                        | SEC_LOAD
  912.                        | SEC_HAS_CONTENTS
  913.                        | SEC_IN_MEMORY
  914.                        | SEC_READONLY))
  915.       || ! bfd_set_section_alignment (dynobj, s, 2))
  916.     return false;
  917.     }
  918.  
  919.   if (bfd_get_section_by_name (dynobj, ".rules") == NULL)
  920.     {
  921.       /* The .rules section holds the path to search for shared
  922.      objects.  The address of this section is put in the ld_rules
  923.      field.  */
  924.       s = bfd_make_section (dynobj, ".rules");
  925.       if (s == NULL
  926.       || ! bfd_set_section_flags (dynobj, s,
  927.                       (SEC_ALLOC
  928.                        | SEC_LOAD
  929.                        | SEC_HAS_CONTENTS
  930.                        | SEC_IN_MEMORY
  931.                        | SEC_READONLY))
  932.       || ! bfd_set_section_alignment (dynobj, s, 2))
  933.     return false;
  934.     }
  935.  
  936.   /* Pick up the dynamic symbols and return them to the caller.  */
  937.   if (! sunos_slurp_dynamic_symtab (abfd))
  938.     return false;
  939.  
  940.   dinfo = (struct sunos_dynamic_info *) obj_aout_dynamic_info (abfd);
  941.   *symsp = dinfo->dynsym;
  942.   *sym_countp = dinfo->dynsym_count;
  943.   *stringsp = dinfo->dynstr;
  944.  
  945.   /* Record information about any other objects needed by this one.  */
  946.   need = dinfo->dyninfo.ld_need;
  947.   while (need != 0)
  948.     {
  949.       bfd_byte buf[16];
  950.       unsigned long name, flags;
  951.       unsigned short major_vno, minor_vno;
  952.       struct bfd_link_needed_list *needed, **pp;
  953.       bfd_byte b;
  954.  
  955.       if (bfd_seek (abfd, need, SEEK_SET) != 0
  956.       || bfd_read (buf, 1, 16, abfd) != 16)
  957.     return false;
  958.  
  959.       /* For the format of an ld_need entry, see aout/sun4.h.  We
  960.          should probably define structs for this manipulation.  */
  961.  
  962.       name = bfd_get_32 (abfd, buf);
  963.       flags = bfd_get_32 (abfd, buf + 4);
  964.       major_vno = bfd_get_16 (abfd, buf + 8);
  965.       minor_vno = bfd_get_16 (abfd, buf + 10);
  966.       need = bfd_get_32 (abfd, buf + 12);
  967.  
  968.       needed = ((struct bfd_link_needed_list *)
  969.         bfd_alloc (abfd, sizeof (struct bfd_link_needed_list)));
  970.       if (needed == NULL)
  971.     return false;
  972.       needed->by = abfd;
  973.  
  974.       /* We return the name as [-l]name[.maj][.min].  */
  975.  
  976.       if ((flags & 0x80000000) != 0)
  977.     bfd_alloc_grow (abfd, "-l", 2);
  978.       if (bfd_seek (abfd, name, SEEK_SET) != 0)
  979.     return false;
  980.       do
  981.     {
  982.       if (bfd_read (&b, 1, 1, abfd) != 1)
  983.         return false;
  984.       bfd_alloc_grow (abfd, &b, 1);
  985.     }
  986.       while (b != '\0');
  987.       if (major_vno != 0)
  988.     {
  989.       char verbuf[30];
  990.  
  991.       sprintf (verbuf, ".%d", major_vno);
  992.       bfd_alloc_grow (abfd, verbuf, strlen (verbuf));
  993.       if (minor_vno != 0)
  994.         {
  995.           sprintf (verbuf, ".%d", minor_vno);
  996.           bfd_alloc_grow (abfd, verbuf, strlen (verbuf));
  997.         }
  998.     }
  999.       needed->name = bfd_alloc_finish (abfd);
  1000.       if (needed->name == NULL)
  1001.     return false;
  1002.  
  1003.       needed->next = NULL;
  1004.  
  1005.       for (pp = &sunos_hash_table (info)->needed;
  1006.        *pp != NULL;
  1007.        pp = &(*pp)->next)
  1008.     ;
  1009.       *pp = needed;
  1010.     }
  1011.  
  1012.   return true;
  1013. }
  1014.  
  1015. /* Function to add a single symbol to the linker hash table.  This is
  1016.    a wrapper around _bfd_generic_link_add_one_symbol which handles the
  1017.    tweaking needed for dynamic linking support.  */
  1018.  
  1019. static boolean
  1020. sunos_add_one_symbol (info, abfd, name, flags, section, value, string,
  1021.               copy, collect, hashp)
  1022.      struct bfd_link_info *info;
  1023.      bfd *abfd;
  1024.      const char *name;
  1025.      flagword flags;
  1026.      asection *section;
  1027.      bfd_vma value;
  1028.      const char *string;
  1029.      boolean copy;
  1030.      boolean collect;
  1031.      struct bfd_link_hash_entry **hashp;
  1032. {
  1033.   struct sunos_link_hash_entry *h;
  1034.   int new_flag;
  1035.  
  1036.   if ((flags & (BSF_INDIRECT | BSF_WARNING | BSF_CONSTRUCTOR)) != 0
  1037.       || ! bfd_is_und_section (section))
  1038.     h = sunos_link_hash_lookup (sunos_hash_table (info), name, true, copy,
  1039.                 false);
  1040.   else
  1041.     h = ((struct sunos_link_hash_entry *)
  1042.      bfd_wrapped_link_hash_lookup (abfd, info, name, true, copy, false));
  1043.   if (h == NULL)
  1044.     return false;
  1045.  
  1046.   if (hashp != NULL)
  1047.     *hashp = (struct bfd_link_hash_entry *) h;
  1048.  
  1049.   /* Treat a common symbol in a dynamic object as defined in the .bss
  1050.      section of the dynamic object.  We don't want to allocate space
  1051.      for it in our process image.  */
  1052.   if ((abfd->flags & DYNAMIC) != 0
  1053.       && bfd_is_com_section (section))
  1054.     section = obj_bsssec (abfd);
  1055.  
  1056.   if (! bfd_is_und_section (section)
  1057.       && h->root.root.type != bfd_link_hash_new
  1058.       && h->root.root.type != bfd_link_hash_undefined
  1059.       && h->root.root.type != bfd_link_hash_defweak)
  1060.     {
  1061.       /* We are defining the symbol, and it is already defined.  This
  1062.      is a potential multiple definition error.  */
  1063.       if ((abfd->flags & DYNAMIC) != 0)
  1064.     {
  1065.       /* The definition we are adding is from a dynamic object.
  1066.          We do not want this new definition to override the
  1067.          existing definition, so we pretend it is just a
  1068.          reference.  */
  1069.       section = bfd_und_section_ptr;
  1070.     }
  1071.       else if (h->root.root.type == bfd_link_hash_defined
  1072.            && h->root.root.u.def.section->owner != NULL
  1073.            && (h->root.root.u.def.section->owner->flags & DYNAMIC) != 0)
  1074.     {
  1075.       /* The existing definition is from a dynamic object.  We
  1076.          want to override it with the definition we just found.
  1077.          Clobber the existing definition.  */
  1078.       h->root.root.type = bfd_link_hash_new;
  1079.     }
  1080.       else if (h->root.root.type == bfd_link_hash_common
  1081.            && (h->root.root.u.c.p->section->owner->flags & DYNAMIC) != 0)
  1082.     {
  1083.       /* The existing definition is from a dynamic object.  We
  1084.          want to override it with the definition we just found.
  1085.          Clobber the existing definition.  We can't set it to new,
  1086.          because it is on the undefined list.  */
  1087.       h->root.root.type = bfd_link_hash_undefined;
  1088.       h->root.root.u.undef.abfd = h->root.root.u.c.p->section->owner;
  1089.     }
  1090.     }
  1091.  
  1092.   if ((abfd->flags & DYNAMIC) != 0
  1093.       && abfd->xvec == info->hash->creator
  1094.       && (h->flags & SUNOS_CONSTRUCTOR) != 0)
  1095.     {
  1096.       /* The existing symbol is a constructor symbol, and this symbol
  1097.          is from a dynamic object.  A constructor symbol is actually a
  1098.          definition, although the type will be bfd_link_hash_undefined
  1099.          at this point.  We want to ignore the definition from the
  1100.          dynamic object.  */
  1101.       section = bfd_und_section_ptr;
  1102.     }
  1103.   else if ((flags & BSF_CONSTRUCTOR) != 0
  1104.        && (abfd->flags & DYNAMIC) == 0
  1105.        && h->root.root.type == bfd_link_hash_defined
  1106.        && h->root.root.u.def.section->owner != NULL
  1107.        && (h->root.root.u.def.section->owner->flags & DYNAMIC) != 0)
  1108.     {
  1109.       /* The existing symbol is defined by a dynamic object, and this
  1110.          is a constructor symbol.  As above, we want to force the use
  1111.          of the constructor symbol from the regular object.  */
  1112.       h->root.root.type = bfd_link_hash_new;
  1113.     }
  1114.  
  1115.   /* Do the usual procedure for adding a symbol.  */
  1116.   if (! _bfd_generic_link_add_one_symbol (info, abfd, name, flags, section,
  1117.                       value, string, copy, collect,
  1118.                       hashp))
  1119.     return false;
  1120.  
  1121.   if (abfd->xvec == info->hash->creator)
  1122.     {
  1123.       /* Set a flag in the hash table entry indicating the type of
  1124.      reference or definition we just found.  Keep a count of the
  1125.      number of dynamic symbols we find.  A dynamic symbol is one
  1126.      which is referenced or defined by both a regular object and a
  1127.      shared object.  */
  1128.       if ((abfd->flags & DYNAMIC) == 0)
  1129.     {
  1130.       if (bfd_is_und_section (section))
  1131.         new_flag = SUNOS_REF_REGULAR;
  1132.       else
  1133.         new_flag = SUNOS_DEF_REGULAR;
  1134.     }
  1135.       else
  1136.     {
  1137.       if (bfd_is_und_section (section))
  1138.         new_flag = SUNOS_REF_DYNAMIC;
  1139.       else
  1140.         new_flag = SUNOS_DEF_DYNAMIC;
  1141.     }
  1142.       h->flags |= new_flag;
  1143.  
  1144.       if (h->dynindx == -1
  1145.       && (h->flags & (SUNOS_DEF_REGULAR | SUNOS_REF_REGULAR)) != 0)
  1146.     {
  1147.       ++sunos_hash_table (info)->dynsymcount;
  1148.       h->dynindx = -2;
  1149.     }
  1150.  
  1151.       if ((flags & BSF_CONSTRUCTOR) != 0
  1152.       && (abfd->flags & DYNAMIC) == 0)
  1153.     h->flags |= SUNOS_CONSTRUCTOR;
  1154.     }
  1155.  
  1156.   return true;
  1157. }
  1158.  
  1159. /* Return the list of objects needed by BFD.  */
  1160.  
  1161. /*ARGSUSED*/
  1162. struct bfd_link_needed_list *
  1163. bfd_sunos_get_needed_list (abfd, info)
  1164.      bfd *abfd;
  1165.      struct bfd_link_info *info;
  1166. {
  1167.   if (info->hash->creator != &MY(vec))
  1168.     return NULL;
  1169.   return sunos_hash_table (info)->needed;
  1170. }
  1171.  
  1172. /* Record an assignment made to a symbol by a linker script.  We need
  1173.    this in case some dynamic object refers to this symbol.  */
  1174.  
  1175. boolean
  1176. bfd_sunos_record_link_assignment (output_bfd, info, name)
  1177.      bfd *output_bfd;
  1178.      struct bfd_link_info *info;
  1179.      const char *name;
  1180. {
  1181.   struct sunos_link_hash_entry *h;
  1182.  
  1183.   if (output_bfd->xvec != &MY(vec))
  1184.     return true;
  1185.  
  1186.   /* This is called after we have examined all the input objects.  If
  1187.      the symbol does not exist, it merely means that no object refers
  1188.      to it, and we can just ignore it at this point.  */
  1189.   h = sunos_link_hash_lookup (sunos_hash_table (info), name,
  1190.                   false, false, false);
  1191.   if (h == NULL)
  1192.     return true;
  1193.  
  1194.   /* In a shared library, the __DYNAMIC symbol does not appear in the
  1195.      dynamic symbol table.  */
  1196.   if (! info->shared || strcmp (name, "__DYNAMIC") != 0)
  1197.     {
  1198.       h->flags |= SUNOS_DEF_REGULAR;
  1199.  
  1200.       if (h->dynindx == -1)
  1201.     {
  1202.       ++sunos_hash_table (info)->dynsymcount;
  1203.       h->dynindx = -2;
  1204.     }
  1205.     }
  1206.  
  1207.   return true;
  1208. }
  1209.  
  1210. /* Set up the sizes and contents of the dynamic sections created in
  1211.    sunos_add_dynamic_symbols.  This is called by the SunOS linker
  1212.    emulation before_allocation routine.  We must set the sizes of the
  1213.    sections before the linker sets the addresses of the various
  1214.    sections.  This unfortunately requires reading all the relocs so
  1215.    that we can work out which ones need to become dynamic relocs.  If
  1216.    info->keep_memory is true, we keep the relocs in memory; otherwise,
  1217.    we discard them, and will read them again later.  */
  1218.  
  1219. boolean
  1220. bfd_sunos_size_dynamic_sections (output_bfd, info, sdynptr, sneedptr,
  1221.                  srulesptr)
  1222.      bfd *output_bfd;
  1223.      struct bfd_link_info *info;
  1224.      asection **sdynptr;
  1225.      asection **sneedptr;
  1226.      asection **srulesptr;
  1227. {
  1228.   bfd *dynobj;
  1229.   size_t dynsymcount;
  1230.   struct sunos_link_hash_entry *h;
  1231.   asection *s;
  1232.   size_t bucketcount;
  1233.   size_t hashalloc;
  1234.   size_t i;
  1235.   bfd *sub;
  1236.  
  1237.   *sdynptr = NULL;
  1238.   *sneedptr = NULL;
  1239.   *srulesptr = NULL;
  1240.  
  1241.   if (output_bfd->xvec != &MY(vec))
  1242.     return true;
  1243.  
  1244.   /* Look through all the input BFD's and read their relocs.  It would
  1245.      be better if we didn't have to do this, but there is no other way
  1246.      to determine the number of dynamic relocs we need, and, more
  1247.      importantly, there is no other way to know which symbols should
  1248.      get an entry in the procedure linkage table.  */
  1249.   for (sub = info->input_bfds; sub != NULL; sub = sub->link_next)
  1250.     {
  1251.       if ((sub->flags & DYNAMIC) == 0
  1252.       && sub->xvec == output_bfd->xvec)
  1253.     {
  1254.       if (! sunos_scan_relocs (info, sub, obj_textsec (sub),
  1255.                    exec_hdr (sub)->a_trsize)
  1256.           || ! sunos_scan_relocs (info, sub, obj_datasec (sub),
  1257.                       exec_hdr (sub)->a_drsize))
  1258.         return false;
  1259.     }
  1260.     }
  1261.  
  1262.   dynobj = sunos_hash_table (info)->dynobj;
  1263.   dynsymcount = sunos_hash_table (info)->dynsymcount;
  1264.  
  1265.   /* If there were no dynamic objects in the link, and we don't need
  1266.      to build a global offset table, there is nothing to do here.  */
  1267.   if (! sunos_hash_table (info)->dynamic_sections_needed)
  1268.     return true;
  1269.  
  1270.   /* If __GLOBAL_OFFSET_TABLE_ was mentioned, define it.  */
  1271.   h = sunos_link_hash_lookup (sunos_hash_table (info),
  1272.                   "__GLOBAL_OFFSET_TABLE_", false, false, false);
  1273.   if (h != NULL && (h->flags & SUNOS_REF_REGULAR) != 0)
  1274.     {
  1275.       h->flags |= SUNOS_DEF_REGULAR;
  1276.       if (h->dynindx == -1)
  1277.     {
  1278.       ++sunos_hash_table (info)->dynsymcount;
  1279.       h->dynindx = -2;
  1280.     }
  1281.       h->root.root.type = bfd_link_hash_defined;
  1282.       h->root.root.u.def.section = bfd_get_section_by_name (dynobj, ".got");
  1283.       h->root.root.u.def.value = 0;
  1284.     }
  1285.  
  1286.   /* The .dynamic section is always the same size.  */
  1287.   s = bfd_get_section_by_name (dynobj, ".dynamic");
  1288.   BFD_ASSERT (s != NULL);
  1289.   s->_raw_size = (sizeof (struct external_sun4_dynamic)
  1290.           + EXTERNAL_SUN4_DYNAMIC_DEBUGGER_SIZE
  1291.           + sizeof (struct external_sun4_dynamic_link));
  1292.  
  1293.   /* Set the size of the .dynsym and .hash sections.  We counted the
  1294.      number of dynamic symbols as we read the input files.  We will
  1295.      build the dynamic symbol table (.dynsym) and the hash table
  1296.      (.hash) when we build the final symbol table, because until then
  1297.      we do not know the correct value to give the symbols.  We build
  1298.      the dynamic symbol string table (.dynstr) in a traversal of the
  1299.      symbol table using sunos_scan_dynamic_symbol.  */
  1300.   s = bfd_get_section_by_name (dynobj, ".dynsym");
  1301.   BFD_ASSERT (s != NULL);
  1302.   s->_raw_size = dynsymcount * sizeof (struct external_nlist);
  1303.   s->contents = (bfd_byte *) bfd_alloc (output_bfd, s->_raw_size);
  1304.   if (s->contents == NULL && s->_raw_size != 0)
  1305.     return false;
  1306.       
  1307.   /* The number of buckets is just the number of symbols divided by
  1308.      four.  To compute the final size of the hash table, we must
  1309.      actually compute the hash table.  Normally we need exactly as
  1310.      many entries in the hash table as there are dynamic symbols, but
  1311.      if some of the buckets are not used we will need additional
  1312.      entries.  In the worst case, every symbol will hash to the same
  1313.      bucket, and we will need BUCKETCOUNT - 1 extra entries.  */
  1314.   if (dynsymcount >= 4)
  1315.     bucketcount = dynsymcount / 4;
  1316.   else if (dynsymcount > 0)
  1317.     bucketcount = dynsymcount;
  1318.   else
  1319.     bucketcount = 1;
  1320.   s = bfd_get_section_by_name (dynobj, ".hash");
  1321.   BFD_ASSERT (s != NULL);
  1322.   hashalloc = (dynsymcount + bucketcount - 1) * HASH_ENTRY_SIZE;
  1323.   s->contents = (bfd_byte *) bfd_alloc (dynobj, hashalloc);
  1324.   if (s->contents == NULL && dynsymcount > 0)
  1325.     return false;
  1326.   memset (s->contents, 0, hashalloc);
  1327.   for (i = 0; i < bucketcount; i++)
  1328.     PUT_WORD (output_bfd, (bfd_vma) -1, s->contents + i * HASH_ENTRY_SIZE);
  1329.   s->_raw_size = bucketcount * HASH_ENTRY_SIZE;
  1330.  
  1331.   sunos_hash_table (info)->bucketcount = bucketcount;
  1332.  
  1333.   /* Scan all the symbols, place them in the dynamic symbol table, and
  1334.      build the dynamic hash table.  We reuse dynsymcount as a counter
  1335.      for the number of symbols we have added so far.  */
  1336.   sunos_hash_table (info)->dynsymcount = 0;
  1337.   sunos_link_hash_traverse (sunos_hash_table (info),
  1338.                 sunos_scan_dynamic_symbol,
  1339.                 (PTR) info);
  1340.   BFD_ASSERT (sunos_hash_table (info)->dynsymcount == dynsymcount);
  1341.  
  1342.   /* The SunOS native linker seems to align the total size of the
  1343.      symbol strings to a multiple of 8.  I don't know if this is
  1344.      important, but it can't hurt much.  */
  1345.   s = bfd_get_section_by_name (dynobj, ".dynstr");
  1346.   BFD_ASSERT (s != NULL);
  1347.   if ((s->_raw_size & 7) != 0)
  1348.     {
  1349.       bfd_size_type add;
  1350.       bfd_byte *contents;
  1351.  
  1352.       add = 8 - (s->_raw_size & 7);
  1353.       contents = (bfd_byte *) bfd_realloc (s->contents,
  1354.                        (size_t) (s->_raw_size + add));
  1355.       if (contents == NULL)
  1356.     return false;
  1357.       memset (contents + s->_raw_size, 0, (size_t) add);
  1358.       s->contents = contents;
  1359.       s->_raw_size += add;
  1360.     }
  1361.  
  1362.   /* Now that we have worked out the sizes of the procedure linkage
  1363.      table and the dynamic relocs, allocate storage for them.  */
  1364.   s = bfd_get_section_by_name (dynobj, ".plt");
  1365.   BFD_ASSERT (s != NULL);
  1366.   if (s->_raw_size != 0)
  1367.     {
  1368.       s->contents = (bfd_byte *) bfd_alloc (dynobj, s->_raw_size);
  1369.       if (s->contents == NULL)
  1370.     return false;
  1371.  
  1372.       /* Fill in the first entry in the table.  */
  1373.       switch (bfd_get_arch (dynobj))
  1374.     {
  1375.     case bfd_arch_sparc:
  1376.       memcpy (s->contents, sparc_plt_first_entry, SPARC_PLT_ENTRY_SIZE);
  1377.       break;
  1378.  
  1379.     case bfd_arch_m68k:
  1380.       memcpy (s->contents, m68k_plt_first_entry, M68K_PLT_ENTRY_SIZE);
  1381.       break;
  1382.  
  1383.     default:
  1384.       abort ();
  1385.     }
  1386.     }
  1387.  
  1388.   s = bfd_get_section_by_name (dynobj, ".dynrel");
  1389.   if (s->_raw_size != 0)
  1390.     {
  1391.       s->contents = (bfd_byte *) bfd_alloc (dynobj, s->_raw_size);
  1392.       if (s->contents == NULL)
  1393.     return false;
  1394.     }
  1395.   /* We use the reloc_count field to keep track of how many of the
  1396.      relocs we have output so far.  */
  1397.   s->reloc_count = 0;
  1398.  
  1399.   /* Make space for the global offset table.  */
  1400.   s = bfd_get_section_by_name (dynobj, ".got");
  1401.   s->contents = (bfd_byte *) bfd_alloc (dynobj, s->_raw_size);
  1402.   if (s->contents == NULL)
  1403.     return false;
  1404.  
  1405.   *sdynptr = bfd_get_section_by_name (dynobj, ".dynamic");
  1406.   *sneedptr = bfd_get_section_by_name (dynobj, ".need");
  1407.   *srulesptr = bfd_get_section_by_name (dynobj, ".rules");
  1408.  
  1409.   return true;
  1410. }
  1411.  
  1412. /* Scan the relocs for an input section.  */
  1413.  
  1414. static boolean
  1415. sunos_scan_relocs (info, abfd, sec, rel_size)
  1416.      struct bfd_link_info *info;
  1417.      bfd *abfd;
  1418.      asection *sec;
  1419.      bfd_size_type rel_size;
  1420. {
  1421.   PTR relocs;
  1422.   PTR free_relocs = NULL;
  1423.  
  1424.   if (rel_size == 0)
  1425.     return true;
  1426.  
  1427.   if (! info->keep_memory)
  1428.     relocs = free_relocs = bfd_malloc ((size_t) rel_size);
  1429.   else
  1430.     {
  1431.       struct aout_section_data_struct *n;
  1432.  
  1433.       n = ((struct aout_section_data_struct *)
  1434.        bfd_alloc (abfd, sizeof (struct aout_section_data_struct)));
  1435.       if (n == NULL)
  1436.     relocs = NULL;
  1437.       else
  1438.     {
  1439.       set_aout_section_data (sec, n);
  1440.       relocs = bfd_malloc ((size_t) rel_size);
  1441.       aout_section_data (sec)->relocs = relocs;
  1442.     }
  1443.     }
  1444.   if (relocs == NULL)
  1445.     return false;
  1446.  
  1447.   if (bfd_seek (abfd, sec->rel_filepos, SEEK_SET) != 0
  1448.       || bfd_read (relocs, 1, rel_size, abfd) != rel_size)
  1449.     goto error_return;
  1450.  
  1451.   if (obj_reloc_entry_size (abfd) == RELOC_STD_SIZE)
  1452.     {
  1453.       if (! sunos_scan_std_relocs (info, abfd, sec,
  1454.                    (struct reloc_std_external *) relocs,
  1455.                    rel_size))
  1456.     goto error_return;
  1457.     }
  1458.   else
  1459.     {
  1460.       if (! sunos_scan_ext_relocs (info, abfd, sec,
  1461.                    (struct reloc_ext_external *) relocs,
  1462.                    rel_size))
  1463.     goto error_return;
  1464.     }
  1465.  
  1466.   if (free_relocs != NULL)
  1467.     free (free_relocs);
  1468.  
  1469.   return true;
  1470.  
  1471.  error_return:
  1472.   if (free_relocs != NULL)
  1473.     free (free_relocs);
  1474.   return false;
  1475. }
  1476.  
  1477. /* Scan the relocs for an input section using standard relocs.  We
  1478.    need to figure out what to do for each reloc against a dynamic
  1479.    symbol.  If the symbol is in the .text section, an entry is made in
  1480.    the procedure linkage table.  Note that this will do the wrong
  1481.    thing if the symbol is actually data; I don't think the Sun 3
  1482.    native linker handles this case correctly either.  If the symbol is
  1483.    not in the .text section, we must preserve the reloc as a dynamic
  1484.    reloc.  FIXME: We should also handle the PIC relocs here by
  1485.    building global offset table entries.  */
  1486.  
  1487. static boolean
  1488. sunos_scan_std_relocs (info, abfd, sec, relocs, rel_size)
  1489.      struct bfd_link_info *info;
  1490.      bfd *abfd;
  1491.      asection *sec;
  1492.      const struct reloc_std_external *relocs;
  1493.      bfd_size_type rel_size;
  1494. {
  1495.   bfd *dynobj;
  1496.   asection *splt = NULL;
  1497.   asection *srel = NULL;
  1498.   struct sunos_link_hash_entry **sym_hashes;
  1499.   const struct reloc_std_external *rel, *relend;
  1500.  
  1501.   /* We only know how to handle m68k plt entries.  */
  1502.   if (bfd_get_arch (abfd) != bfd_arch_m68k)
  1503.     {
  1504.       bfd_set_error (bfd_error_invalid_target);
  1505.       return false;
  1506.     }
  1507.  
  1508.   dynobj = NULL;
  1509.  
  1510.   sym_hashes = (struct sunos_link_hash_entry **) obj_aout_sym_hashes (abfd);
  1511.  
  1512.   relend = relocs + rel_size / RELOC_STD_SIZE;
  1513.   for (rel = relocs; rel < relend; rel++)
  1514.     {
  1515.       int r_index;
  1516.       struct sunos_link_hash_entry *h;
  1517.  
  1518.       /* We only want relocs against external symbols.  */
  1519.       if (bfd_header_big_endian (abfd))
  1520.     {
  1521.       if ((rel->r_type[0] & RELOC_STD_BITS_EXTERN_BIG) == 0)
  1522.         continue;
  1523.     }
  1524.       else
  1525.     {
  1526.       if ((rel->r_type[0] & RELOC_STD_BITS_EXTERN_LITTLE) == 0)
  1527.         continue;
  1528.     }
  1529.  
  1530.       /* Get the symbol index.  */
  1531.       if (bfd_header_big_endian (abfd))
  1532.     r_index = ((rel->r_index[0] << 16)
  1533.            | (rel->r_index[1] << 8)
  1534.            | rel->r_index[2]);
  1535.       else
  1536.     r_index = ((rel->r_index[2] << 16)
  1537.            | (rel->r_index[1] << 8)
  1538.            | rel->r_index[0]);
  1539.  
  1540.       /* Get the hash table entry.  */
  1541.       h = sym_hashes[r_index];
  1542.       if (h == NULL)
  1543.     {
  1544.       /* This should not normally happen, but it will in any case
  1545.          be caught in the relocation phase.  */
  1546.       continue;
  1547.     }
  1548.  
  1549.       /* At this point common symbols have already been allocated, so
  1550.      we don't have to worry about them.  We need to consider that
  1551.      we may have already seen this symbol and marked it undefined;
  1552.      if the symbol is really undefined, then SUNOS_DEF_DYNAMIC
  1553.      will be zero.  */
  1554.       if (h->root.root.type != bfd_link_hash_defined
  1555.       && h->root.root.type != bfd_link_hash_defweak
  1556.       && h->root.root.type != bfd_link_hash_undefined)
  1557.     continue;
  1558.  
  1559.       if ((h->flags & SUNOS_DEF_DYNAMIC) == 0
  1560.       || (h->flags & SUNOS_DEF_REGULAR) != 0)
  1561.     continue;
  1562.  
  1563.       if (dynobj == NULL)
  1564.     {
  1565.       if (! sunos_create_dynamic_sections (abfd, info, true))
  1566.         return false;
  1567.       dynobj = sunos_hash_table (info)->dynobj;
  1568.       splt = bfd_get_section_by_name (dynobj, ".plt");
  1569.       srel = bfd_get_section_by_name (dynobj, ".dynrel");
  1570.       BFD_ASSERT (splt != NULL && srel != NULL);
  1571.     }
  1572.  
  1573.       BFD_ASSERT ((h->flags & SUNOS_REF_REGULAR) != 0);
  1574.       BFD_ASSERT (h->plt_offset != 0
  1575.           || ((h->root.root.type == bfd_link_hash_defined
  1576.                || h->root.root.type == bfd_link_hash_defweak)
  1577.               ? (h->root.root.u.def.section->owner->flags
  1578.              & DYNAMIC) != 0
  1579.               : (h->root.root.u.undef.abfd->flags & DYNAMIC) != 0));
  1580.  
  1581.       /* This reloc is against a symbol defined only by a dynamic
  1582.      object.  */
  1583.  
  1584.       if (h->root.root.type == bfd_link_hash_undefined)
  1585.     {
  1586.       /* Presumably this symbol was marked as being undefined by
  1587.          an earlier reloc.  */
  1588.       srel->_raw_size += RELOC_STD_SIZE;
  1589.     }
  1590.       else if ((h->root.root.u.def.section->flags & SEC_CODE) == 0)
  1591.     {
  1592.       bfd *sub;
  1593.  
  1594.       /* This reloc is not in the .text section.  It must be
  1595.          copied into the dynamic relocs.  We mark the symbol as
  1596.          being undefined.  */
  1597.       srel->_raw_size += RELOC_STD_SIZE;
  1598.       sub = h->root.root.u.def.section->owner;
  1599.       h->root.root.type = bfd_link_hash_undefined;
  1600.       h->root.root.u.undef.abfd = sub;
  1601.     }
  1602.       else
  1603.     {
  1604.       /* This symbol is in the .text section.  We must give it an
  1605.          entry in the procedure linkage table, if we have not
  1606.          already done so.  We change the definition of the symbol
  1607.          to the .plt section; this will cause relocs against it to
  1608.          be handled correctly.  */
  1609.       if (h->plt_offset == 0)
  1610.         {
  1611.           if (splt->_raw_size == 0)
  1612.         splt->_raw_size = M68K_PLT_ENTRY_SIZE;
  1613.           h->plt_offset = splt->_raw_size;
  1614.  
  1615.           if ((h->flags & SUNOS_DEF_REGULAR) == 0)
  1616.         {
  1617.           h->root.root.u.def.section = splt;
  1618.           h->root.root.u.def.value = splt->_raw_size;
  1619.         }
  1620.  
  1621.           splt->_raw_size += M68K_PLT_ENTRY_SIZE;
  1622.  
  1623.           /* We may also need a dynamic reloc entry.  */
  1624.           if ((h->flags & SUNOS_DEF_REGULAR) == 0)
  1625.         srel->_raw_size += RELOC_STD_SIZE;
  1626.         }
  1627.     }
  1628.     }
  1629.  
  1630.   return true;
  1631. }
  1632.  
  1633. /* Scan the relocs for an input section using extended relocs.  We
  1634.    need to figure out what to do for each reloc against a dynamic
  1635.    symbol.  If the reloc is a WDISP30, and the symbol is in the .text
  1636.    section, an entry is made in the procedure linkage table.
  1637.    Otherwise, we must preserve the reloc as a dynamic reloc.  */
  1638.  
  1639. static boolean
  1640. sunos_scan_ext_relocs (info, abfd, sec, relocs, rel_size)
  1641.      struct bfd_link_info *info;
  1642.      bfd *abfd;
  1643.      asection *sec;
  1644.      const struct reloc_ext_external *relocs;
  1645.      bfd_size_type rel_size;
  1646. {
  1647.   bfd *dynobj;
  1648.   struct sunos_link_hash_entry **sym_hashes;
  1649.   const struct reloc_ext_external *rel, *relend;
  1650.   asection *splt = NULL;
  1651.   asection *sgot = NULL;
  1652.   asection *srel = NULL;
  1653.  
  1654.   /* We only know how to handle SPARC plt entries.  */
  1655.   if (bfd_get_arch (abfd) != bfd_arch_sparc)
  1656.     {
  1657.       bfd_set_error (bfd_error_invalid_target);
  1658.       return false;
  1659.     }
  1660.  
  1661.   dynobj = NULL;
  1662.  
  1663.   sym_hashes = (struct sunos_link_hash_entry **) obj_aout_sym_hashes (abfd);
  1664.  
  1665.   relend = relocs + rel_size / RELOC_EXT_SIZE;
  1666.   for (rel = relocs; rel < relend; rel++)
  1667.     {
  1668.       unsigned int r_index;
  1669.       int r_extern;
  1670.       int r_type;
  1671.       struct sunos_link_hash_entry *h = NULL;
  1672.  
  1673.       /* Swap in the reloc information.  */
  1674.       if (bfd_header_big_endian (abfd))
  1675.     {
  1676.       r_index = ((rel->r_index[0] << 16)
  1677.              | (rel->r_index[1] << 8)
  1678.              | rel->r_index[2]);
  1679.       r_extern = (0 != (rel->r_type[0] & RELOC_EXT_BITS_EXTERN_BIG));
  1680.       r_type = ((rel->r_type[0] & RELOC_EXT_BITS_TYPE_BIG)
  1681.             >> RELOC_EXT_BITS_TYPE_SH_BIG);
  1682.     }
  1683.       else
  1684.     {
  1685.       r_index = ((rel->r_index[2] << 16)
  1686.              | (rel->r_index[1] << 8)
  1687.              | rel->r_index[0]);
  1688.       r_extern = (0 != (rel->r_type[0] & RELOC_EXT_BITS_EXTERN_LITTLE));
  1689.       r_type = ((rel->r_type[0] & RELOC_EXT_BITS_TYPE_LITTLE)
  1690.             >> RELOC_EXT_BITS_TYPE_SH_LITTLE);
  1691.     }
  1692.  
  1693.       if (r_extern)
  1694.     {
  1695.       h = sym_hashes[r_index];
  1696.       if (h == NULL)
  1697.         {
  1698.           /* This should not normally happen, but it will in any
  1699.          case be caught in the relocation phase.  */
  1700.           continue;
  1701.         }
  1702.     }
  1703.  
  1704.       /* If this is a base relative reloc, we need to make an entry in
  1705.          the .got section.  */
  1706.       if (r_type == RELOC_BASE10
  1707.       || r_type == RELOC_BASE13
  1708.       || r_type == RELOC_BASE22)
  1709.     {
  1710.       if (dynobj == NULL)
  1711.         {
  1712.           if (! sunos_create_dynamic_sections (abfd, info, true))
  1713.         return false;
  1714.           dynobj = sunos_hash_table (info)->dynobj;
  1715.           splt = bfd_get_section_by_name (dynobj, ".plt");
  1716.           sgot = bfd_get_section_by_name (dynobj, ".got");
  1717.           srel = bfd_get_section_by_name (dynobj, ".dynrel");
  1718.           BFD_ASSERT (splt != NULL && sgot != NULL && srel != NULL);
  1719.         }
  1720.  
  1721.       if (r_extern)
  1722.         {
  1723.           if (h->got_offset != 0)
  1724.         continue;
  1725.  
  1726.           h->got_offset = sgot->_raw_size;
  1727.         }
  1728.       else
  1729.         {
  1730.           if (r_index >= bfd_get_symcount (abfd))
  1731.         {
  1732.           /* This is abnormal, but should be caught in the
  1733.              relocation phase.  */
  1734.           continue;
  1735.         }
  1736.  
  1737.           if (adata (abfd).local_got_offsets == NULL)
  1738.         {
  1739.           adata (abfd).local_got_offsets =
  1740.             (bfd_vma *) bfd_zalloc (abfd,
  1741.                         (bfd_get_symcount (abfd)
  1742.                          * sizeof (bfd_vma)));
  1743.           if (adata (abfd).local_got_offsets == NULL)
  1744.             return false;
  1745.         }
  1746.  
  1747.           if (adata (abfd).local_got_offsets[r_index] != 0)
  1748.         continue;
  1749.  
  1750.           adata (abfd).local_got_offsets[r_index] = sgot->_raw_size;
  1751.         }
  1752.  
  1753.       sgot->_raw_size += BYTES_IN_WORD;
  1754.  
  1755.       /* If we are making a shared library, or if the symbol is
  1756.          defined by a dynamic object, we will need a dynamic reloc
  1757.          entry.  */
  1758.       if (info->shared
  1759.           || (h != NULL
  1760.           && (h->flags & SUNOS_DEF_DYNAMIC) != 0
  1761.           && (h->flags & SUNOS_DEF_REGULAR) == 0))
  1762.         srel->_raw_size += RELOC_EXT_SIZE;
  1763.  
  1764.       continue;
  1765.     }
  1766.  
  1767.       /* Otherwise, we are only interested in relocs against symbols
  1768.          defined in dynamic objects but not in regular objects.  We
  1769.          only need to consider relocs against external symbols.  */
  1770.       if (! r_extern)
  1771.     {
  1772.       /* But, if we are creating a shared library, we need to
  1773.              generate an absolute reloc.  */
  1774.       if (info->shared)
  1775.         {
  1776.           if (dynobj == NULL)
  1777.         {
  1778.           if (! sunos_create_dynamic_sections (abfd, info, true))
  1779.             return false;
  1780.           dynobj = sunos_hash_table (info)->dynobj;
  1781.           splt = bfd_get_section_by_name (dynobj, ".plt");
  1782.           sgot = bfd_get_section_by_name (dynobj, ".got");
  1783.           srel = bfd_get_section_by_name (dynobj, ".dynrel");
  1784.           BFD_ASSERT (splt != NULL && sgot != NULL && srel != NULL);
  1785.         }
  1786.  
  1787.           srel->_raw_size += RELOC_EXT_SIZE;
  1788.         }
  1789.  
  1790.       continue;
  1791.     }
  1792.  
  1793.       /* At this point common symbols have already been allocated, so
  1794.      we don't have to worry about them.  We need to consider that
  1795.      we may have already seen this symbol and marked it undefined;
  1796.      if the symbol is really undefined, then SUNOS_DEF_DYNAMIC
  1797.      will be zero.  */
  1798.       if (h->root.root.type != bfd_link_hash_defined
  1799.       && h->root.root.type != bfd_link_hash_defweak
  1800.       && h->root.root.type != bfd_link_hash_undefined)
  1801.     continue;
  1802.  
  1803.       if (r_type != RELOC_JMP_TBL
  1804.       && ! info->shared
  1805.       && ((h->flags & SUNOS_DEF_DYNAMIC) == 0
  1806.           || (h->flags & SUNOS_DEF_REGULAR) != 0))
  1807.     continue;
  1808.  
  1809.       if (r_type == RELOC_JMP_TBL
  1810.       && ! info->shared
  1811.       && (h->flags & SUNOS_DEF_DYNAMIC) == 0
  1812.       && (h->flags & SUNOS_DEF_REGULAR) == 0)
  1813.     {
  1814.       /* This symbol is apparently undefined.  Don't do anything
  1815.              here; just let the relocation routine report an undefined
  1816.              symbol.  */
  1817.       continue;
  1818.     }
  1819.  
  1820.       if (strcmp (h->root.root.root.string, "__GLOBAL_OFFSET_TABLE_") == 0)
  1821.     continue;
  1822.  
  1823.       if (dynobj == NULL)
  1824.     {
  1825.       if (! sunos_create_dynamic_sections (abfd, info, true))
  1826.         return false;
  1827.       dynobj = sunos_hash_table (info)->dynobj;
  1828.       splt = bfd_get_section_by_name (dynobj, ".plt");
  1829.       sgot = bfd_get_section_by_name (dynobj, ".got");
  1830.       srel = bfd_get_section_by_name (dynobj, ".dynrel");
  1831.       BFD_ASSERT (splt != NULL && sgot != NULL && srel != NULL);
  1832.     }
  1833.  
  1834.       BFD_ASSERT (r_type == RELOC_JMP_TBL
  1835.           || info->shared
  1836.           || (h->flags & SUNOS_REF_REGULAR) != 0);
  1837.       BFD_ASSERT (r_type == RELOC_JMP_TBL
  1838.           || info->shared
  1839.           || h->plt_offset != 0
  1840.           || ((h->root.root.type == bfd_link_hash_defined
  1841.                || h->root.root.type == bfd_link_hash_defweak)
  1842.               ? (h->root.root.u.def.section->owner->flags
  1843.              & DYNAMIC) != 0
  1844.               : (h->root.root.u.undef.abfd->flags & DYNAMIC) != 0));
  1845.  
  1846.       /* This reloc is against a symbol defined only by a dynamic
  1847.      object, or it is a jump table reloc from PIC compiled code.  */
  1848.  
  1849.       if (r_type != RELOC_JMP_TBL
  1850.       && h->root.root.type == bfd_link_hash_undefined)
  1851.     {
  1852.       /* Presumably this symbol was marked as being undefined by
  1853.          an earlier reloc.  */
  1854.       srel->_raw_size += RELOC_EXT_SIZE;
  1855.     }
  1856.       else if (r_type != RELOC_JMP_TBL
  1857.            && (h->root.root.u.def.section->flags & SEC_CODE) == 0)
  1858.     {
  1859.       bfd *sub;
  1860.  
  1861.       /* This reloc is not in the .text section.  It must be
  1862.          copied into the dynamic relocs.  We mark the symbol as
  1863.          being undefined.  */
  1864.       srel->_raw_size += RELOC_EXT_SIZE;
  1865.       if ((h->flags & SUNOS_DEF_REGULAR) == 0)
  1866.         {
  1867.           sub = h->root.root.u.def.section->owner;
  1868.           h->root.root.type = bfd_link_hash_undefined;
  1869.           h->root.root.u.undef.abfd = sub;
  1870.         }
  1871.     }
  1872.       else
  1873.     {
  1874.       /* This symbol is in the .text section.  We must give it an
  1875.          entry in the procedure linkage table, if we have not
  1876.          already done so.  We change the definition of the symbol
  1877.          to the .plt section; this will cause relocs against it to
  1878.          be handled correctly.  */
  1879.       if (h->plt_offset == 0)
  1880.         {
  1881.           if (splt->_raw_size == 0)
  1882.         splt->_raw_size = SPARC_PLT_ENTRY_SIZE;
  1883.           h->plt_offset = splt->_raw_size;
  1884.  
  1885.           if ((h->flags & SUNOS_DEF_REGULAR) == 0)
  1886.         {
  1887.           if (h->root.root.type == bfd_link_hash_undefined)
  1888.             h->root.root.type = bfd_link_hash_defined;
  1889.           h->root.root.u.def.section = splt;
  1890.           h->root.root.u.def.value = splt->_raw_size;
  1891.         }
  1892.  
  1893.           splt->_raw_size += SPARC_PLT_ENTRY_SIZE;
  1894.  
  1895.           /* We will also need a dynamic reloc entry, unless this
  1896.                  is a JMP_TBL reloc produced by linking PIC compiled
  1897.                  code, and we are not making a shared library.  */
  1898.           if (info->shared || (h->flags & SUNOS_DEF_REGULAR) == 0)
  1899.         srel->_raw_size += RELOC_EXT_SIZE;
  1900.         }
  1901.  
  1902.       /* If we are creating a shared library, we need to copy over
  1903.              any reloc other than a jump table reloc.  */
  1904.       if (info->shared && r_type != RELOC_JMP_TBL)
  1905.         srel->_raw_size += RELOC_EXT_SIZE;
  1906.     }
  1907.     }
  1908.  
  1909.   return true;
  1910. }
  1911.  
  1912. /* Build the hash table of dynamic symbols, and to mark as written all
  1913.    symbols from dynamic objects which we do not plan to write out.  */
  1914.  
  1915. static boolean
  1916. sunos_scan_dynamic_symbol (h, data)
  1917.      struct sunos_link_hash_entry *h;
  1918.      PTR data;
  1919. {
  1920.   struct bfd_link_info *info = (struct bfd_link_info *) data;
  1921.  
  1922.   /* Set the written flag for symbols we do not want to write out as
  1923.      part of the regular symbol table.  This is all symbols which are
  1924.      not defined in a regular object file.  For some reason symbols
  1925.      which are referenced by a regular object and defined by a dynamic
  1926.      object do not seem to show up in the regular symbol table.  It is
  1927.      possible for a symbol to have only SUNOS_REF_REGULAR set here, it
  1928.      is an undefined symbol which was turned into a common symbol
  1929.      because it was found in an archive object which was not included
  1930.      in the link.  */
  1931.   if ((h->flags & SUNOS_DEF_REGULAR) == 0
  1932.       && (h->flags & SUNOS_DEF_DYNAMIC) != 0
  1933.       && strcmp (h->root.root.root.string, "__DYNAMIC") != 0)
  1934.     h->root.written = true;
  1935.  
  1936.   /* If this symbol is defined by a dynamic object and referenced by a
  1937.      regular object, see whether we gave it a reasonable value while
  1938.      scanning the relocs.  */
  1939.  
  1940.   if ((h->flags & SUNOS_DEF_REGULAR) == 0
  1941.       && (h->flags & SUNOS_DEF_DYNAMIC) != 0
  1942.       && (h->flags & SUNOS_REF_REGULAR) != 0)
  1943.     {
  1944.       if ((h->root.root.type == bfd_link_hash_defined
  1945.        || h->root.root.type == bfd_link_hash_defweak)
  1946.       && ((h->root.root.u.def.section->owner->flags & DYNAMIC) != 0)
  1947.       && h->root.root.u.def.section->output_section == NULL)
  1948.     {
  1949.       bfd *sub;
  1950.  
  1951.       /* This symbol is currently defined in a dynamic section
  1952.          which is not being put into the output file.  This
  1953.          implies that there is no reloc against the symbol.  I'm
  1954.          not sure why this case would ever occur.  In any case, we
  1955.          change the symbol to be undefined.  */
  1956.       sub = h->root.root.u.def.section->owner;
  1957.       h->root.root.type = bfd_link_hash_undefined;
  1958.       h->root.root.u.undef.abfd = sub;
  1959.     }
  1960.     }
  1961.  
  1962.   /* If this symbol is defined or referenced by a regular file, add it
  1963.      to the dynamic symbols.  */
  1964.   if ((h->flags & (SUNOS_DEF_REGULAR | SUNOS_REF_REGULAR)) != 0)
  1965.     {
  1966.       asection *s;
  1967.       size_t len;
  1968.       bfd_byte *contents;
  1969.       unsigned char *name;
  1970.       unsigned long hash;
  1971.       bfd *dynobj;
  1972.  
  1973.       BFD_ASSERT (h->dynindx == -2);
  1974.  
  1975.       dynobj = sunos_hash_table (info)->dynobj;
  1976.  
  1977.       h->dynindx = sunos_hash_table (info)->dynsymcount;
  1978.       ++sunos_hash_table (info)->dynsymcount;
  1979.  
  1980.       len = strlen (h->root.root.root.string);
  1981.  
  1982.       /* We don't bother to construct a BFD hash table for the strings
  1983.      which are the names of the dynamic symbols.  Using a hash
  1984.      table for the regular symbols is beneficial, because the
  1985.      regular symbols includes the debugging symbols, which have
  1986.      long names and are often duplicated in several object files.
  1987.      There are no debugging symbols in the dynamic symbols.  */
  1988.       s = bfd_get_section_by_name (dynobj, ".dynstr");
  1989.       BFD_ASSERT (s != NULL);
  1990.       contents = (bfd_byte *) bfd_realloc (s->contents,
  1991.                        s->_raw_size + len + 1);
  1992.       if (contents == NULL)
  1993.     return false;
  1994.       s->contents = contents;
  1995.  
  1996.       h->dynstr_index = s->_raw_size;
  1997.       strcpy (contents + s->_raw_size, h->root.root.root.string);
  1998.       s->_raw_size += len + 1;
  1999.  
  2000.       /* Add it to the dynamic hash table.  */
  2001.       name = (unsigned char *) h->root.root.root.string;
  2002.       hash = 0;
  2003.       while (*name != '\0')
  2004.     hash = (hash << 1) + *name++;
  2005.       hash &= 0x7fffffff;
  2006.       hash %= sunos_hash_table (info)->bucketcount;
  2007.  
  2008.       s = bfd_get_section_by_name (dynobj, ".hash");
  2009.       BFD_ASSERT (s != NULL);
  2010.  
  2011.       if (GET_SWORD (dynobj, s->contents + hash * HASH_ENTRY_SIZE) == -1)
  2012.     PUT_WORD (dynobj, h->dynindx, s->contents + hash * HASH_ENTRY_SIZE);
  2013.       else
  2014.     {
  2015.       bfd_vma next;
  2016.  
  2017.       next = GET_WORD (dynobj,
  2018.                (s->contents
  2019.                 + hash * HASH_ENTRY_SIZE
  2020.                 + BYTES_IN_WORD));
  2021.       PUT_WORD (dynobj, s->_raw_size / HASH_ENTRY_SIZE,
  2022.             s->contents + hash * HASH_ENTRY_SIZE + BYTES_IN_WORD);
  2023.       PUT_WORD (dynobj, h->dynindx, s->contents + s->_raw_size);
  2024.       PUT_WORD (dynobj, next, s->contents + s->_raw_size + BYTES_IN_WORD);
  2025.       s->_raw_size += HASH_ENTRY_SIZE;
  2026.     }
  2027.     }
  2028.  
  2029.   return true;
  2030. }
  2031.  
  2032. /* Link a dynamic object.  We actually don't have anything to do at
  2033.    this point.  This entry point exists to prevent the regular linker
  2034.    code from doing anything with the object.  */
  2035.  
  2036. /*ARGSUSED*/
  2037. static boolean
  2038. sunos_link_dynamic_object (info, abfd)
  2039.      struct bfd_link_info *info;
  2040.      bfd *abfd;
  2041. {
  2042.   return true;
  2043. }
  2044.  
  2045. /* Write out a dynamic symbol.  This is called by the final traversal
  2046.    over the symbol table.  */
  2047.  
  2048. static boolean
  2049. sunos_write_dynamic_symbol (output_bfd, info, harg)
  2050.      bfd *output_bfd;
  2051.      struct bfd_link_info *info;
  2052.      struct aout_link_hash_entry *harg;
  2053. {
  2054.   struct sunos_link_hash_entry *h = (struct sunos_link_hash_entry *) harg;
  2055.   int type;
  2056.   bfd_vma val;
  2057.   asection *s;
  2058.   struct external_nlist *outsym;
  2059.  
  2060.   if (h->dynindx < 0)
  2061.     return true;
  2062.  
  2063.   switch (h->root.root.type)
  2064.     {
  2065.     default:
  2066.     case bfd_link_hash_new:
  2067.       abort ();
  2068.       /* Avoid variable not initialized warnings.  */
  2069.       return true;
  2070.     case bfd_link_hash_undefined:
  2071.       type = N_UNDF | N_EXT;
  2072.       val = 0;
  2073.       break;
  2074.     case bfd_link_hash_defined:
  2075.     case bfd_link_hash_defweak:
  2076.       {
  2077.     asection *sec;
  2078.     asection *output_section;
  2079.  
  2080.     sec = h->root.root.u.def.section;
  2081.     output_section = sec->output_section;
  2082.     BFD_ASSERT (bfd_is_abs_section (output_section)
  2083.             || output_section->owner == output_bfd);
  2084.     if (h->plt_offset != 0
  2085.         && (h->flags & SUNOS_DEF_REGULAR) == 0)
  2086.       {
  2087.         type = N_UNDF | N_EXT;
  2088.         val = 0;
  2089.       }
  2090.     else
  2091.       {
  2092.         if (output_section == obj_textsec (output_bfd))
  2093.           type = (h->root.root.type == bfd_link_hash_defined
  2094.               ? N_TEXT
  2095.               : N_WEAKT);
  2096.         else if (output_section == obj_datasec (output_bfd))
  2097.           type = (h->root.root.type == bfd_link_hash_defined
  2098.               ? N_DATA
  2099.               : N_WEAKD);
  2100.         else if (output_section == obj_bsssec (output_bfd))
  2101.           type = (h->root.root.type == bfd_link_hash_defined
  2102.               ? N_BSS
  2103.               : N_WEAKB);
  2104.         else
  2105.           type = (h->root.root.type == bfd_link_hash_defined
  2106.               ? N_ABS
  2107.               : N_WEAKA);
  2108.         type |= N_EXT;
  2109.         val = (h->root.root.u.def.value
  2110.            + output_section->vma
  2111.            + sec->output_offset);
  2112.       }
  2113.       }
  2114.       break;
  2115.     case bfd_link_hash_common:
  2116.       type = N_UNDF | N_EXT;
  2117.       val = h->root.root.u.c.size;
  2118.       break;
  2119.     case bfd_link_hash_undefweak:
  2120.       type = N_WEAKU;
  2121.       val = 0;
  2122.       break;
  2123.     case bfd_link_hash_indirect:
  2124.     case bfd_link_hash_warning:
  2125.       /* FIXME: Ignore these for now.  The circumstances under which
  2126.      they should be written out are not clear to me.  */
  2127.       return true;
  2128.     }
  2129.  
  2130.   s = bfd_get_section_by_name (sunos_hash_table (info)->dynobj, ".dynsym");
  2131.   BFD_ASSERT (s != NULL);
  2132.   outsym = ((struct external_nlist *)
  2133.         (s->contents + h->dynindx * EXTERNAL_NLIST_SIZE));
  2134.  
  2135.   bfd_h_put_8 (output_bfd, type, outsym->e_type);
  2136.   bfd_h_put_8 (output_bfd, 0, outsym->e_other);
  2137.  
  2138.   /* FIXME: The native linker doesn't use 0 for desc.  It seems to use
  2139.      one less than the desc value in the shared library, although that
  2140.      seems unlikely.  */
  2141.   bfd_h_put_16 (output_bfd, 0, outsym->e_desc);
  2142.  
  2143.   PUT_WORD (output_bfd, h->dynstr_index, outsym->e_strx);
  2144.   PUT_WORD (output_bfd, val, outsym->e_value);
  2145.  
  2146.   /* If this symbol is in the procedure linkage table, fill in the
  2147.      table entry.  */
  2148.   if (h->plt_offset != 0)
  2149.     {
  2150.       bfd *dynobj;
  2151.       asection *splt;
  2152.       bfd_byte *p;
  2153.       asection *s;
  2154.       bfd_vma r_address;
  2155.  
  2156.       dynobj = sunos_hash_table (info)->dynobj;
  2157.       splt = bfd_get_section_by_name (dynobj, ".plt");
  2158.       p = splt->contents + h->plt_offset;
  2159.  
  2160.       s = bfd_get_section_by_name (dynobj, ".dynrel");
  2161.  
  2162.       r_address = (splt->output_section->vma
  2163.            + splt->output_offset
  2164.            + h->plt_offset);
  2165.  
  2166.       switch (bfd_get_arch (output_bfd))
  2167.     {
  2168.     case bfd_arch_sparc:
  2169.       if (info->shared || (h->flags & SUNOS_DEF_REGULAR) == 0)
  2170.         {
  2171.           bfd_put_32 (output_bfd, SPARC_PLT_ENTRY_WORD0, p);
  2172.           bfd_put_32 (output_bfd,
  2173.               (SPARC_PLT_ENTRY_WORD1
  2174.                + (((- (h->plt_offset + 4) >> 2)
  2175.                    & 0x3fffffff))),
  2176.               p + 4);
  2177.           bfd_put_32 (output_bfd, SPARC_PLT_ENTRY_WORD2 + s->reloc_count,
  2178.               p + 8);
  2179.         }
  2180.       else
  2181.         {
  2182.           bfd_vma val;
  2183.  
  2184.           val = (h->root.root.u.def.section->output_section->vma
  2185.              + h->root.root.u.def.section->output_offset
  2186.              + h->root.root.u.def.value);
  2187.           bfd_put_32 (output_bfd,
  2188.               SPARC_PLT_PIC_WORD0 + ((val >> 10) & 0x3fffff),
  2189.               p);
  2190.           bfd_put_32 (output_bfd,
  2191.               SPARC_PLT_PIC_WORD1 + (val & 0x3ff),
  2192.               p + 4);
  2193.           bfd_put_32 (output_bfd, SPARC_PLT_PIC_WORD2, p + 8);
  2194.         }
  2195.       break;
  2196.  
  2197.     case bfd_arch_m68k:
  2198.       if (! info->shared && (h->flags & SUNOS_DEF_REGULAR) != 0)
  2199.         abort ();
  2200.       bfd_put_16 (output_bfd, M68K_PLT_ENTRY_WORD0, p);
  2201.       bfd_put_32 (output_bfd, (- (h->plt_offset + 2)), p + 2);
  2202.       bfd_put_16 (output_bfd, s->reloc_count, p + 6);
  2203.       r_address += 2;
  2204.       break;
  2205.  
  2206.     default:
  2207.       abort ();
  2208.     }
  2209.  
  2210.       /* We also need to add a jump table reloc, unless this is the
  2211.          result of a JMP_TBL reloc from PIC compiled code.  */
  2212.       if (info->shared || (h->flags & SUNOS_DEF_REGULAR) == 0)
  2213.     {
  2214.       BFD_ASSERT (s->reloc_count * obj_reloc_entry_size (dynobj)
  2215.               < s->_raw_size);
  2216.       p = s->contents + s->reloc_count * obj_reloc_entry_size (output_bfd);
  2217.       if (obj_reloc_entry_size (output_bfd) == RELOC_STD_SIZE)
  2218.         {
  2219.           struct reloc_std_external *srel;
  2220.  
  2221.           srel = (struct reloc_std_external *) p;
  2222.           PUT_WORD (output_bfd, r_address, srel->r_address);
  2223.           if (bfd_header_big_endian (output_bfd))
  2224.         {
  2225.           srel->r_index[0] = h->dynindx >> 16;
  2226.           srel->r_index[1] = h->dynindx >> 8;
  2227.           srel->r_index[2] = h->dynindx;
  2228.           srel->r_type[0] = (RELOC_STD_BITS_EXTERN_BIG
  2229.                      | RELOC_STD_BITS_JMPTABLE_BIG);
  2230.         }
  2231.           else
  2232.         {
  2233.           srel->r_index[2] = h->dynindx >> 16;
  2234.           srel->r_index[1] = h->dynindx >> 8;
  2235.           srel->r_index[0] = h->dynindx;
  2236.           srel->r_type[0] = (RELOC_STD_BITS_EXTERN_LITTLE
  2237.                      | RELOC_STD_BITS_JMPTABLE_LITTLE);
  2238.         }
  2239.         }
  2240.       else
  2241.         {
  2242.           struct reloc_ext_external *erel;
  2243.  
  2244.           erel = (struct reloc_ext_external *) p;
  2245.           PUT_WORD (output_bfd, r_address, erel->r_address);
  2246.           if (bfd_header_big_endian (output_bfd))
  2247.         {
  2248.           erel->r_index[0] = h->dynindx >> 16;
  2249.           erel->r_index[1] = h->dynindx >> 8;
  2250.           erel->r_index[2] = h->dynindx;
  2251.           erel->r_type[0] =
  2252.             (RELOC_EXT_BITS_EXTERN_BIG
  2253.              | (RELOC_JMP_SLOT << RELOC_EXT_BITS_TYPE_SH_BIG));
  2254.         }
  2255.           else
  2256.         {
  2257.           erel->r_index[2] = h->dynindx >> 16;
  2258.           erel->r_index[1] = h->dynindx >> 8;
  2259.           erel->r_index[0] = h->dynindx;
  2260.           erel->r_type[0] =
  2261.             (RELOC_EXT_BITS_EXTERN_LITTLE
  2262.              | (RELOC_JMP_SLOT << RELOC_EXT_BITS_TYPE_SH_LITTLE));
  2263.         }
  2264.           PUT_WORD (output_bfd, (bfd_vma) 0, erel->r_addend);
  2265.         }
  2266.  
  2267.       ++s->reloc_count;
  2268.     }
  2269.     }
  2270.  
  2271.   return true;
  2272. }
  2273.  
  2274. /* This is called for each reloc against an external symbol.  If this
  2275.    is a reloc which are are going to copy as a dynamic reloc, then
  2276.    copy it over, and tell the caller to not bother processing this
  2277.    reloc.  */
  2278.  
  2279. /*ARGSUSED*/
  2280. static boolean
  2281. sunos_check_dynamic_reloc (info, input_bfd, input_section, harg, reloc,
  2282.                contents, skip, relocationp)
  2283.      struct bfd_link_info *info;
  2284.      bfd *input_bfd;
  2285.      asection *input_section;
  2286.      struct aout_link_hash_entry *harg;
  2287.      PTR reloc;
  2288.      bfd_byte *contents;
  2289.      boolean *skip;
  2290.      bfd_vma *relocationp;
  2291. {
  2292.   struct sunos_link_hash_entry *h = (struct sunos_link_hash_entry *) harg;
  2293.   bfd *dynobj;
  2294.   boolean baserel;
  2295.   boolean jmptbl;
  2296.   asection *s;
  2297.   bfd_byte *p;
  2298.   long indx;
  2299.  
  2300.   *skip = false;
  2301.  
  2302.   dynobj = sunos_hash_table (info)->dynobj;
  2303.  
  2304.   if (h != NULL && h->plt_offset != 0)
  2305.     {
  2306.       asection *splt;
  2307.  
  2308.       /* Redirect the relocation to the PLT entry.  */
  2309.       splt = bfd_get_section_by_name (dynobj, ".plt");
  2310.       *relocationp = (splt->output_section->vma
  2311.               + splt->output_offset
  2312.               + h->plt_offset);
  2313.     }
  2314.  
  2315.   if (obj_reloc_entry_size (input_bfd) == RELOC_STD_SIZE)
  2316.     {
  2317.       struct reloc_std_external *srel;
  2318.  
  2319.       srel = (struct reloc_std_external *) reloc;
  2320.       if (bfd_header_big_endian (input_bfd))
  2321.     {
  2322.       baserel = (0 != (srel->r_type[0] & RELOC_STD_BITS_BASEREL_BIG));
  2323.       jmptbl = (0 != (srel->r_type[0] & RELOC_STD_BITS_JMPTABLE_BIG));
  2324.     }
  2325.       else
  2326.     {
  2327.       baserel = (0 != (srel->r_type[0] & RELOC_STD_BITS_BASEREL_LITTLE));
  2328.       jmptbl = (0 != (srel->r_type[0] & RELOC_STD_BITS_JMPTABLE_LITTLE));
  2329.     }
  2330.     }
  2331.   else
  2332.     {
  2333.       struct reloc_ext_external *erel;
  2334.       int r_type;
  2335.  
  2336.       erel = (struct reloc_ext_external *) reloc;
  2337.       if (bfd_header_big_endian (input_bfd))
  2338.     r_type = ((erel->r_type[0] & RELOC_EXT_BITS_TYPE_BIG)
  2339.           >> RELOC_EXT_BITS_TYPE_SH_BIG);
  2340.       else
  2341.     r_type = ((erel->r_type[0] & RELOC_EXT_BITS_TYPE_LITTLE)
  2342.           >> RELOC_EXT_BITS_TYPE_SH_LITTLE);
  2343.       baserel = (r_type == RELOC_BASE10
  2344.          || r_type == RELOC_BASE13
  2345.          || r_type == RELOC_BASE22);
  2346.       jmptbl = r_type == RELOC_JMP_TBL;
  2347.     }
  2348.  
  2349.   if (baserel)
  2350.     {
  2351.       bfd_vma *got_offsetp;
  2352.       asection *sgot;
  2353.  
  2354.       if (h != NULL)
  2355.     got_offsetp = &h->got_offset;
  2356.       else if (adata (input_bfd).local_got_offsets == NULL)
  2357.     got_offsetp = NULL;
  2358.       else
  2359.     {
  2360.       struct reloc_std_external *srel;
  2361.       int r_index;
  2362.  
  2363.       srel = (struct reloc_std_external *) reloc;
  2364.       if (obj_reloc_entry_size (input_bfd) == RELOC_STD_SIZE)
  2365.         {
  2366.           if (bfd_header_big_endian (input_bfd))
  2367.         r_index = ((srel->r_index[0] << 16)
  2368.                | (srel->r_index[1] << 8)
  2369.                | srel->r_index[2]);
  2370.           else
  2371.         r_index = ((srel->r_index[2] << 16)
  2372.                | (srel->r_index[1] << 8)
  2373.                | srel->r_index[0]);
  2374.         }
  2375.       else
  2376.         {
  2377.           struct reloc_ext_external *erel;
  2378.  
  2379.           erel = (struct reloc_ext_external *) reloc;
  2380.           if (bfd_header_big_endian (input_bfd))
  2381.         r_index = ((erel->r_index[0] << 16)
  2382.                | (erel->r_index[1] << 8)
  2383.                | erel->r_index[2]);
  2384.           else
  2385.         r_index = ((erel->r_index[2] << 16)
  2386.                | (erel->r_index[1] << 8)
  2387.                | erel->r_index[0]);
  2388.         }
  2389.  
  2390.       got_offsetp = adata (input_bfd).local_got_offsets + r_index;
  2391.     }
  2392.  
  2393.       BFD_ASSERT (got_offsetp != NULL && *got_offsetp != 0);
  2394.  
  2395.       sgot = bfd_get_section_by_name (dynobj, ".got");
  2396.  
  2397.       /* We set the least significant bit to indicate whether we have
  2398.      already initialized the GOT entry.  */
  2399.       if ((*got_offsetp & 1) == 0)
  2400.     {
  2401.       if (h == NULL
  2402.           || (! info->shared
  2403.           && ((h->flags & SUNOS_DEF_DYNAMIC) == 0
  2404.               || (h->flags & SUNOS_DEF_REGULAR) != 0)))
  2405.         PUT_WORD (dynobj, *relocationp, sgot->contents + *got_offsetp);
  2406.       else
  2407.         PUT_WORD (dynobj, 0, sgot->contents + *got_offsetp);
  2408.  
  2409.       if (info->shared
  2410.           || (h != NULL
  2411.           && (h->flags & SUNOS_DEF_DYNAMIC) != 0
  2412.           && (h->flags & SUNOS_DEF_REGULAR) == 0))
  2413.         {
  2414.           /* We need to create a GLOB_DAT or 32 reloc to tell the
  2415.                  dynamic linker to fill in this entry in the table.  */
  2416.  
  2417.           s = bfd_get_section_by_name (dynobj, ".dynrel");
  2418.           BFD_ASSERT (s != NULL);
  2419.           BFD_ASSERT (s->reloc_count * obj_reloc_entry_size (dynobj)
  2420.               < s->_raw_size);
  2421.  
  2422.           p = (s->contents
  2423.            + s->reloc_count * obj_reloc_entry_size (dynobj));
  2424.  
  2425.           if (h != NULL)
  2426.         indx = h->dynindx;
  2427.           else
  2428.         indx = 0;
  2429.  
  2430.           if (obj_reloc_entry_size (dynobj) == RELOC_STD_SIZE)
  2431.         {
  2432.           struct reloc_std_external *srel;
  2433.  
  2434.           srel = (struct reloc_std_external *) p;
  2435.           PUT_WORD (dynobj,
  2436.                 (*got_offsetp
  2437.                  + sgot->output_section->vma
  2438.                  + sgot->output_offset),
  2439.                 srel->r_address);
  2440.           if (bfd_header_big_endian (dynobj))
  2441.             {
  2442.               srel->r_index[0] = indx >> 16;
  2443.               srel->r_index[1] = indx >> 8;
  2444.               srel->r_index[2] = indx;
  2445.               if (h == NULL)
  2446.             srel->r_type[0] = 2 << RELOC_STD_BITS_LENGTH_SH_BIG;
  2447.               else
  2448.             srel->r_type[0] =
  2449.               (RELOC_STD_BITS_EXTERN_BIG
  2450.                | RELOC_STD_BITS_BASEREL_BIG
  2451.                | RELOC_STD_BITS_RELATIVE_BIG
  2452.                | (2 << RELOC_STD_BITS_LENGTH_SH_BIG));
  2453.             }
  2454.           else
  2455.             {
  2456.               srel->r_index[2] = indx >> 16;
  2457.               srel->r_index[1] = indx >> 8;
  2458.               srel->r_index[0] = indx;
  2459.               if (h == NULL)
  2460.             srel->r_type[0] = 2 << RELOC_STD_BITS_LENGTH_SH_LITTLE;
  2461.               else
  2462.             srel->r_type[0] =
  2463.               (RELOC_STD_BITS_EXTERN_LITTLE
  2464.                | RELOC_STD_BITS_BASEREL_LITTLE
  2465.                | RELOC_STD_BITS_RELATIVE_LITTLE
  2466.                | (2 << RELOC_STD_BITS_LENGTH_SH_LITTLE));
  2467.             }
  2468.         }
  2469.           else
  2470.         {
  2471.           struct reloc_ext_external *erel;
  2472.  
  2473.           erel = (struct reloc_ext_external *) p;
  2474.           PUT_WORD (dynobj,
  2475.                 (*got_offsetp
  2476.                  + sgot->output_section->vma
  2477.                  + sgot->output_offset),
  2478.                 erel->r_address);
  2479.           if (bfd_header_big_endian (dynobj))
  2480.             {
  2481.               erel->r_index[0] = indx >> 16;
  2482.               erel->r_index[1] = indx >> 8;
  2483.               erel->r_index[2] = indx;
  2484.               if (h == NULL)
  2485.             erel->r_type[0] =
  2486.               RELOC_32 << RELOC_EXT_BITS_TYPE_SH_BIG;
  2487.               else
  2488.             erel->r_type[0] =
  2489.               (RELOC_EXT_BITS_EXTERN_BIG
  2490.                | (RELOC_GLOB_DAT << RELOC_EXT_BITS_TYPE_SH_BIG));
  2491.             }
  2492.           else
  2493.             {
  2494.               erel->r_index[2] = indx >> 16;
  2495.               erel->r_index[1] = indx >> 8;
  2496.               erel->r_index[0] = indx;
  2497.               if (h == NULL)
  2498.             erel->r_type[0] =
  2499.               RELOC_32 << RELOC_EXT_BITS_TYPE_SH_LITTLE;
  2500.               else
  2501.             erel->r_type[0] =
  2502.               (RELOC_EXT_BITS_EXTERN_LITTLE
  2503.                | (RELOC_GLOB_DAT
  2504.                   << RELOC_EXT_BITS_TYPE_SH_LITTLE));
  2505.             }
  2506.           PUT_WORD (dynobj, 0, erel->r_addend);
  2507.         }
  2508.  
  2509.           ++s->reloc_count;
  2510.         }
  2511.  
  2512.       *got_offsetp |= 1;
  2513.     }
  2514.  
  2515.       *relocationp = sgot->vma + (*got_offsetp &~ 1);
  2516.  
  2517.       /* There is nothing else to do for a base relative reloc.  */
  2518.       return true;
  2519.     }
  2520.  
  2521.   if (! sunos_hash_table (info)->dynamic_sections_needed)
  2522.     return true;
  2523.   if (! info->shared)
  2524.     {
  2525.       if (h == NULL
  2526.       || h->dynindx == -1
  2527.       || h->root.root.type != bfd_link_hash_undefined
  2528.       || (h->flags & SUNOS_DEF_REGULAR) != 0
  2529.       || (h->flags & SUNOS_DEF_DYNAMIC) == 0
  2530.       || (h->root.root.u.undef.abfd->flags & DYNAMIC) == 0)
  2531.     return true;
  2532.     }
  2533.   else
  2534.     {
  2535.       if (h != NULL
  2536.       && (h->dynindx == -1
  2537.           || jmptbl
  2538.           || strcmp (h->root.root.root.string,
  2539.              "__GLOBAL_OFFSET_TABLE_") == 0))
  2540.     return true;
  2541.     }
  2542.  
  2543.   /* It looks like this is a reloc we are supposed to copy.  */
  2544.  
  2545.   s = bfd_get_section_by_name (dynobj, ".dynrel");
  2546.   BFD_ASSERT (s != NULL);
  2547.   BFD_ASSERT (s->reloc_count * obj_reloc_entry_size (dynobj) < s->_raw_size);
  2548.  
  2549.   p = s->contents + s->reloc_count * obj_reloc_entry_size (dynobj);
  2550.  
  2551.   /* Copy the reloc over.  */
  2552.   memcpy (p, reloc, obj_reloc_entry_size (dynobj));
  2553.  
  2554.   if (h != NULL)
  2555.     indx = h->dynindx;
  2556.   else
  2557.     indx = 0;
  2558.  
  2559.   /* Adjust the address and symbol index.  */
  2560.   if (obj_reloc_entry_size (dynobj) == RELOC_STD_SIZE)
  2561.     {
  2562.       struct reloc_std_external *srel;
  2563.  
  2564.       srel = (struct reloc_std_external *) p;
  2565.       PUT_WORD (dynobj,
  2566.         (GET_WORD (dynobj, srel->r_address)
  2567.          + input_section->output_section->vma
  2568.          + input_section->output_offset),
  2569.         srel->r_address);
  2570.       if (bfd_header_big_endian (dynobj))
  2571.     {
  2572.       srel->r_index[0] = indx >> 16;
  2573.       srel->r_index[1] = indx >> 8;
  2574.       srel->r_index[2] = indx;
  2575.     }
  2576.       else
  2577.     {
  2578.       srel->r_index[2] = indx >> 16;
  2579.       srel->r_index[1] = indx >> 8;
  2580.       srel->r_index[0] = indx;
  2581.     }
  2582.     }
  2583.   else
  2584.     {
  2585.       struct reloc_ext_external *erel;
  2586.  
  2587.       erel = (struct reloc_ext_external *) p;
  2588.       PUT_WORD (dynobj,
  2589.         (GET_WORD (dynobj, erel->r_address)
  2590.          + input_section->output_section->vma
  2591.          + input_section->output_offset),
  2592.         erel->r_address);
  2593.       if (bfd_header_big_endian (dynobj))
  2594.     {
  2595.       erel->r_index[0] = indx >> 16;
  2596.       erel->r_index[1] = indx >> 8;
  2597.       erel->r_index[2] = indx;
  2598.     }
  2599.       else
  2600.     {
  2601.       erel->r_index[2] = indx >> 16;
  2602.       erel->r_index[1] = indx >> 8;
  2603.       erel->r_index[0] = indx;
  2604.     }
  2605.     }
  2606.  
  2607.   ++s->reloc_count;
  2608.  
  2609.   if (h != NULL)
  2610.     *skip = true;
  2611.  
  2612.   return true;
  2613. }
  2614.  
  2615. /* Finish up the dynamic linking information.  */
  2616.  
  2617. static boolean
  2618. sunos_finish_dynamic_link (abfd, info)
  2619.      bfd *abfd;
  2620.      struct bfd_link_info *info;
  2621. {
  2622.   bfd *dynobj;
  2623.   asection *o;
  2624.   asection *s;
  2625.   asection *sdyn;
  2626.   struct external_sun4_dynamic esd;
  2627.   struct external_sun4_dynamic_link esdl;
  2628.  
  2629.   if (! sunos_hash_table (info)->dynamic_sections_needed)
  2630.     return true;
  2631.  
  2632.   dynobj = sunos_hash_table (info)->dynobj;
  2633.  
  2634.   sdyn = bfd_get_section_by_name (dynobj, ".dynamic");
  2635.   BFD_ASSERT (sdyn != NULL);
  2636.  
  2637.   /* Finish up the .need section.  The linker emulation code filled it
  2638.      in, but with offsets from the start of the section instead of
  2639.      real addresses.  Now that we know the section location, we can
  2640.      fill in the final values.  */
  2641.   s = bfd_get_section_by_name (dynobj, ".need");
  2642.   if (s != NULL && s->_raw_size != 0)
  2643.     {
  2644.       file_ptr filepos;
  2645.       bfd_byte *p;
  2646.  
  2647.       filepos = s->output_section->filepos + s->output_offset;
  2648.       p = s->contents;
  2649.       while (1)
  2650.     {
  2651.       bfd_vma val;
  2652.  
  2653.       PUT_WORD (dynobj, GET_WORD (dynobj, p) + filepos, p);
  2654.       val = GET_WORD (dynobj, p + 12);
  2655.       if (val == 0)
  2656.         break;
  2657.       PUT_WORD (dynobj, val + filepos, p + 12);
  2658.       p += 16;
  2659.     }
  2660.     }
  2661.  
  2662.   /* The first entry in the .got section is the address of the
  2663.      dynamic information, unless this is a shared library.  */
  2664.   s = bfd_get_section_by_name (dynobj, ".got");
  2665.   BFD_ASSERT (s != NULL);
  2666.   if (info->shared)
  2667.     PUT_WORD (dynobj, 0, s->contents);
  2668.   else
  2669.     PUT_WORD (dynobj, sdyn->output_section->vma + sdyn->output_offset,
  2670.           s->contents);
  2671.  
  2672.   for (o = dynobj->sections; o != NULL; o = o->next)
  2673.     {
  2674.       if ((o->flags & SEC_HAS_CONTENTS) != 0
  2675.       && o->contents != NULL)
  2676.     {
  2677.       BFD_ASSERT (o->output_section != NULL
  2678.               && o->output_section->owner == abfd);
  2679.       if (! bfd_set_section_contents (abfd, o->output_section,
  2680.                       o->contents, o->output_offset,
  2681.                       o->_raw_size))
  2682.         return false;
  2683.     }
  2684.     }
  2685.  
  2686.   /* Finish up the dynamic link information.  */
  2687.   PUT_WORD (dynobj, (bfd_vma) 3, esd.ld_version);
  2688.   PUT_WORD (dynobj,
  2689.         sdyn->output_section->vma + sdyn->output_offset + sizeof esd,
  2690.         esd.ldd);
  2691.   PUT_WORD (dynobj,
  2692.         (sdyn->output_section->vma
  2693.          + sdyn->output_offset
  2694.          + sizeof esd
  2695.          + EXTERNAL_SUN4_DYNAMIC_DEBUGGER_SIZE),
  2696.         esd.ld);
  2697.  
  2698.   if (! bfd_set_section_contents (abfd, sdyn->output_section, &esd,
  2699.                   sdyn->output_offset, sizeof esd))
  2700.     return false;
  2701.  
  2702.  
  2703.   PUT_WORD (dynobj, (bfd_vma) 0, esdl.ld_loaded);
  2704.  
  2705.   s = bfd_get_section_by_name (dynobj, ".need");
  2706.   if (s == NULL || s->_raw_size == 0)
  2707.     PUT_WORD (dynobj, (bfd_vma) 0, esdl.ld_need);
  2708.   else
  2709.     PUT_WORD (dynobj, s->output_section->filepos + s->output_offset,
  2710.           esdl.ld_need);
  2711.  
  2712.   s = bfd_get_section_by_name (dynobj, ".rules");
  2713.   if (s == NULL || s->_raw_size == 0)
  2714.     PUT_WORD (dynobj, (bfd_vma) 0, esdl.ld_rules);
  2715.   else
  2716.     PUT_WORD (dynobj, s->output_section->filepos + s->output_offset,
  2717.           esdl.ld_rules);
  2718.  
  2719.   s = bfd_get_section_by_name (dynobj, ".got");
  2720.   BFD_ASSERT (s != NULL);
  2721.   PUT_WORD (dynobj, s->output_section->vma + s->output_offset, esdl.ld_got);
  2722.  
  2723.   s = bfd_get_section_by_name (dynobj, ".plt");
  2724.   BFD_ASSERT (s != NULL);
  2725.   PUT_WORD (dynobj, s->output_section->vma + s->output_offset, esdl.ld_plt);
  2726.   PUT_WORD (dynobj, s->_raw_size, esdl.ld_plt_sz);
  2727.  
  2728.   s = bfd_get_section_by_name (dynobj, ".dynrel");
  2729.   BFD_ASSERT (s != NULL);
  2730.   BFD_ASSERT (s->reloc_count * obj_reloc_entry_size (dynobj) == s->_raw_size);
  2731.   PUT_WORD (dynobj, s->output_section->filepos + s->output_offset,
  2732.         esdl.ld_rel);
  2733.  
  2734.   s = bfd_get_section_by_name (dynobj, ".hash");
  2735.   BFD_ASSERT (s != NULL);
  2736.   PUT_WORD (dynobj, s->output_section->filepos + s->output_offset,
  2737.         esdl.ld_hash);
  2738.  
  2739.   s = bfd_get_section_by_name (dynobj, ".dynsym");
  2740.   BFD_ASSERT (s != NULL);
  2741.   PUT_WORD (dynobj, s->output_section->filepos + s->output_offset,
  2742.         esdl.ld_stab);
  2743.  
  2744.   PUT_WORD (dynobj, (bfd_vma) 0, esdl.ld_stab_hash);
  2745.  
  2746.   PUT_WORD (dynobj, (bfd_vma) sunos_hash_table (info)->bucketcount,
  2747.         esdl.ld_buckets);
  2748.  
  2749.   s = bfd_get_section_by_name (dynobj, ".dynstr");
  2750.   BFD_ASSERT (s != NULL);
  2751.   PUT_WORD (dynobj, s->output_section->filepos + s->output_offset,
  2752.         esdl.ld_symbols);
  2753.   PUT_WORD (dynobj, s->_raw_size, esdl.ld_symb_size);
  2754.  
  2755.   /* The size of the text area is the size of the .text section
  2756.      rounded up to a page boundary.  FIXME: Should the page size be
  2757.      conditional on something?  */
  2758.   PUT_WORD (dynobj,
  2759.         BFD_ALIGN (obj_textsec (abfd)->_raw_size, 0x2000),
  2760.         esdl.ld_text);
  2761.   
  2762.   if (! bfd_set_section_contents (abfd, sdyn->output_section, &esdl,
  2763.                   (sdyn->output_offset
  2764.                    + sizeof esd
  2765.                    + EXTERNAL_SUN4_DYNAMIC_DEBUGGER_SIZE),
  2766.                   sizeof esdl))
  2767.     return false;
  2768.  
  2769.   abfd->flags |= DYNAMIC;
  2770.  
  2771.   return true;
  2772. }
  2773.