Ignore:
Timestamp:
Aug 16, 2003, 6:59:22 PM (22 years ago)
Author:
bird
Message:

binutils v2.14 - offical sources.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/GNU/src/binutils/bfd/elf32-hppa.c

    • Property cvs2svn:cvs-rev changed from 1.1 to 1.1.1.2
    r608 r609  
    11/* BFD back-end for HP PA-RISC ELF files.
    2    Copyright 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1999, 2000, 2001
    3    Free Software Foundation, Inc.
     2   Copyright 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1999, 2000, 2001,
     3   2002, 2003 Free Software Foundation, Inc.
    44
    55   Original code by
     
    99   Largely rewritten by Alan Modra <alan@linuxcare.com.au>
    1010
    11 This file is part of BFD, the Binary File Descriptor library.
    12 
    13 This program is free software; you can redistribute it and/or modify
    14 it under the terms of the GNU General Public License as published by
    15 the Free Software Foundation; either version 2 of the License, or
    16 (at your option) any later version.
    17 
    18 This program is distributed in the hope that it will be useful,
    19 but WITHOUT ANY WARRANTY; without even the implied warranty of
    20 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    21 GNU General Public License for more details.
    22 
    23 You should have received a copy of the GNU General Public License
    24 along with this program; if not, write to the Free Software
    25 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.  */
     11   This file is part of BFD, the Binary File Descriptor library.
     12
     13   This program is free software; you can redistribute it and/or modify
     14   it under the terms of the GNU General Public License as published by
     15   the Free Software Foundation; either version 2 of the License, or
     16   (at your option) any later version.
     17
     18   This program is distributed in the hope that it will be useful,
     19   but WITHOUT ANY WARRANTY; without even the implied warranty of
     20   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     21   GNU General Public License for more details.
     22
     23   You should have received a copy of the GNU General Public License
     24   along with this program; if not, write to the Free Software
     25   Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.  */
    2626
    2727#include "bfd.h"
     
    3333#include "elf32-hppa.h"
    3434#define ARCH_SIZE               32
     35#include "elf32-hppa.h"
    3536#include "elf-hppa.h"
    36 #include "elf32-hppa.h"
    3737
    3838/* In order to gain some understanding of code in this file without
     
    7272   :            addil LR'lt_ptr+ltoff,%dp       ; get procedure entry point
    7373   :            ldw RR'lt_ptr+ltoff(%r1),%r21
    74    :            bv %r0(%r21)
     74   :            bv %r0(%r21)
    7575   :            ldw RR'lt_ptr+ltoff+4(%r1),%r19 ; get new dlt value.
    7676
     
    7979   :            addil LR'ltoff,%r19             ; get procedure entry point
    8080   :            ldw RR'ltoff(%r1),%r21
    81    :            bv %r0(%r21)
     81   :            bv %r0(%r21)
    8282   :            ldw RR'ltoff+4(%r1),%r19        ; get new dlt value.
    8383
     
    112112   :            ldsid (%rp),%r1
    113113   :            mtsp %r1,%sr0
    114    :            be,n 0(%sr0,%rp)                ; inter-space return  */
     114   :            be,n 0(%sr0,%rp)                ; inter-space return.  */
    115115
    116116#define PLT_ENTRY_SIZE 8
    117 #define PLABEL_PLT_ENTRY_SIZE PLT_ENTRY_SIZE
    118117#define GOT_ENTRY_SIZE 4
    119118#define ELF_DYNAMIC_INTERPRETER "/lib/ld.so.1"
     
    135134#define STUB_SUFFIX ".stub"
    136135
    137 /* Setting the following non-zero makes all long branch stubs
    138    generated during a shared link of the PIC variety.  This saves on
    139    relocs, but costs one extra instruction per stub.  */
    140 #ifndef LONG_BRANCH_PIC_IN_SHLIB
    141 #define LONG_BRANCH_PIC_IN_SHLIB 1
    142 #endif
    143 
    144 /* Set this non-zero to use import stubs instead of long branch stubs
    145    where a .plt entry exists for the symbol.  This is a fairly useless
    146    option as import stubs are bigger than PIC long branch stubs.  */
    147 #ifndef LONG_BRANCH_VIA_PLT
    148 #define LONG_BRANCH_VIA_PLT 0
    149 #endif
    150 
    151 /* We don't need to copy any PC- or GP-relative dynamic relocs into a
    152    shared object's dynamic section.  */
    153 #ifndef RELATIVE_DYNAMIC_RELOCS
    154 #define RELATIVE_DYNAMIC_RELOCS 0
     136/* We don't need to copy certain PC- or GP-relative dynamic relocs
     137   into a shared object's dynamic section.  All the relocs of the
     138   limited class we are interested in, are absolute.  */
     139#ifndef RELATIVE_DYNRELOCS
     140#define RELATIVE_DYNRELOCS 0
     141#define IS_ABSOLUTE_RELOC(r_type) 1
    155142#endif
    156143
     
    172159  asection *stub_sec;
    173160
    174 #if ! LONG_BRANCH_PIC_IN_SHLIB
    175   /* It's associated reloc section.  */
    176   asection *reloc_sec;
    177 #endif
    178 
    179161  /* Offset within stub_sec of the beginning of this stub.  */
    180162  bfd_vma stub_offset;
     
    203185  struct elf32_hppa_stub_hash_entry *stub_cache;
    204186
    205 #if ! LONG_BRANCH_PIC_IN_SHLIB
    206   /* Used to track whether we have allocated space for a long branch
    207      stub relocation for this symbol in the given section.  */
    208   asection *stub_reloc_sec;
    209 #endif
    210 
    211 #if ! LONG_BRANCH_PIC_IN_SHLIB || RELATIVE_DYNAMIC_RELOCS
    212187  /* Used to count relocations for delayed sizing of relocation
    213188     sections.  */
     
    217192    struct elf32_hppa_dyn_reloc_entry *next;
    218193
    219     /* The section in dynobj.  */
    220     asection *section;
     194    /* The input section of the reloc.  */
     195    asection *sec;
    221196
    222197    /* Number of relocs copied in this section.  */
    223198    bfd_size_type count;
    224   } *reloc_entries;
     199
     200#if RELATIVE_DYNRELOCS
     201  /* Number of relative relocs copied for the input section.  */
     202    bfd_size_type relative_count;
    225203#endif
    226 
    227   /* Set during a static link if we detect a function is PIC.  */
    228   unsigned int maybe_pic_call:1;
     204  } *dyn_relocs;
    229205
    230206  /* Set if the only reason we need a .plt entry is for a non-PIC to
     
    234210  /* Set if this symbol is used by a plabel reloc.  */
    235211  unsigned int plabel:1;
    236 
    237   /* Set if this symbol is an init or fini function and thus should
    238      use an absolute reloc.  */
    239   unsigned int plt_abs:1;
    240212};
    241213
     
    243215
    244216  /* The main hash table.  */
    245   struct elf_link_hash_table root;
     217  struct elf_link_hash_table elf;
    246218
    247219  /* The stub hash table.  */
     
    263235    /* The stub section.  */
    264236    asection *stub_sec;
    265 #if ! LONG_BRANCH_PIC_IN_SHLIB
    266     /* The stub section's reloc section.  */
    267     asection *reloc_sec;
    268 #endif
    269237  } *stub_group;
     238
     239  /* Assorted information used by elf32_hppa_size_stubs.  */
     240  unsigned int bfd_count;
     241  int top_index;
     242  asection **input_list;
     243  Elf_Internal_Sym **all_local_syms;
    270244
    271245  /* Short-cuts to get to dynamic linker sections.  */
     
    285259  unsigned int multi_subspace:1;
    286260
    287   /* Flags set when PCREL12F and PCREL17F branches detected.  Used to
     261  /* Flags set when various size branches are detected.  Used to
    288262     select suitable defaults for the stub group size.  */
    289263  unsigned int has_12bit_branch:1;
    290264  unsigned int has_17bit_branch:1;
     265  unsigned int has_22bit_branch:1;
    291266
    292267  /* Set if we need a .plt stub to support lazy dynamic linking.  */
    293268  unsigned int need_plt_stub:1;
     269
     270  /* Small local sym to section mapping cache.  */
     271  struct sym_sec_cache sym_sec;
    294272};
    295273
     
    310288static struct bfd_link_hash_table *elf32_hppa_link_hash_table_create
    311289  PARAMS ((bfd *));
     290
     291static void elf32_hppa_link_hash_table_free
     292  PARAMS ((struct bfd_link_hash_table *));
    312293
    313294/* Stub handling functions.  */
     
    330311           struct elf32_hppa_link_hash_entry *, bfd_vma));
    331312
    332 static boolean hppa_build_one_stub
     313static bfd_boolean hppa_build_one_stub
    333314  PARAMS ((struct bfd_hash_entry *, PTR));
    334315
    335 static boolean hppa_size_one_stub
     316static bfd_boolean hppa_size_one_stub
    336317  PARAMS ((struct bfd_hash_entry *, PTR));
    337318
    338319/* BFD and elf backend functions.  */
    339 static boolean elf32_hppa_object_p PARAMS ((bfd *));
    340 
    341 static boolean elf32_hppa_add_symbol_hook
     320static bfd_boolean elf32_hppa_object_p PARAMS ((bfd *));
     321
     322static bfd_boolean elf32_hppa_add_symbol_hook
    342323  PARAMS ((bfd *, struct bfd_link_info *, const Elf_Internal_Sym *,
    343324           const char **, flagword *, asection **, bfd_vma *));
    344325
    345 static boolean elf32_hppa_create_dynamic_sections
     326static bfd_boolean elf32_hppa_create_dynamic_sections
    346327  PARAMS ((bfd *, struct bfd_link_info *));
    347328
    348 static boolean elf32_hppa_check_relocs
     329static void elf32_hppa_copy_indirect_symbol
     330  PARAMS ((struct elf_backend_data *, struct elf_link_hash_entry *,
     331           struct elf_link_hash_entry *));
     332
     333static bfd_boolean elf32_hppa_check_relocs
    349334  PARAMS ((bfd *, struct bfd_link_info *,
    350335           asection *, const Elf_Internal_Rela *));
    351336
    352337static asection *elf32_hppa_gc_mark_hook
    353   PARAMS ((bfd *, struct bfd_link_info *, Elf_Internal_Rela *,
     338  PARAMS ((asection *, struct bfd_link_info *, Elf_Internal_Rela *,
    354339           struct elf_link_hash_entry *, Elf_Internal_Sym *));
    355340
    356 static boolean elf32_hppa_gc_sweep_hook
     341static bfd_boolean elf32_hppa_gc_sweep_hook
    357342  PARAMS ((bfd *, struct bfd_link_info *,
    358343           asection *, const Elf_Internal_Rela *));
    359344
    360345static void elf32_hppa_hide_symbol
     346  PARAMS ((struct bfd_link_info *, struct elf_link_hash_entry *, bfd_boolean));
     347
     348static bfd_boolean elf32_hppa_adjust_dynamic_symbol
    361349  PARAMS ((struct bfd_link_info *, struct elf_link_hash_entry *));
    362350
    363 static boolean elf32_hppa_adjust_dynamic_symbol
    364   PARAMS ((struct bfd_link_info *, struct elf_link_hash_entry *));
    365 
    366 static boolean hppa_handle_PIC_calls
     351static bfd_boolean mark_PIC_calls
    367352  PARAMS ((struct elf_link_hash_entry *, PTR));
    368353
    369 static boolean allocate_plt_and_got
     354static bfd_boolean allocate_plt_static
    370355  PARAMS ((struct elf_link_hash_entry *, PTR));
    371356
    372 #if ((! LONG_BRANCH_PIC_IN_SHLIB && LONG_BRANCH_VIA_PLT) \
    373      || RELATIVE_DYNAMIC_RELOCS)
    374 static boolean hppa_discard_copies
     357static bfd_boolean allocate_dynrelocs
    375358  PARAMS ((struct elf_link_hash_entry *, PTR));
    376 #endif
    377 
    378 static boolean clobber_millicode_symbols
     359
     360static bfd_boolean readonly_dynrelocs
     361  PARAMS ((struct elf_link_hash_entry *, PTR));
     362
     363static bfd_boolean clobber_millicode_symbols
    379364  PARAMS ((struct elf_link_hash_entry *, struct bfd_link_info *));
    380365
    381 static boolean elf32_hppa_size_dynamic_sections
     366static bfd_boolean elf32_hppa_size_dynamic_sections
    382367  PARAMS ((bfd *, struct bfd_link_info *));
    383368
    384 static boolean elf32_hppa_final_link
     369static void group_sections
     370  PARAMS ((struct elf32_hppa_link_hash_table *, bfd_size_type, bfd_boolean));
     371
     372static int get_local_syms
     373  PARAMS ((bfd *, bfd *, struct bfd_link_info *));
     374
     375static bfd_boolean elf32_hppa_final_link
    385376  PARAMS ((bfd *, struct bfd_link_info *));
    386377
     
    393384           struct elf32_hppa_link_hash_entry *));
    394385
    395 static boolean elf32_hppa_relocate_section
     386static bfd_boolean elf32_hppa_relocate_section
    396387  PARAMS ((bfd *, struct bfd_link_info *, bfd *, asection *,
    397388           bfd_byte *, Elf_Internal_Rela *, Elf_Internal_Sym *, asection **));
    398389
    399 static int hppa_unwind_entry_compare
    400   PARAMS ((const PTR, const PTR));
    401 
    402 static boolean elf32_hppa_finish_dynamic_symbol
     390static bfd_boolean elf32_hppa_finish_dynamic_symbol
    403391  PARAMS ((bfd *, struct bfd_link_info *,
    404392           struct elf_link_hash_entry *, Elf_Internal_Sym *));
    405393
    406 static boolean elf32_hppa_finish_dynamic_sections
     394static enum elf_reloc_type_class elf32_hppa_reloc_type_class
     395  PARAMS ((const Elf_Internal_Rela *));
     396
     397static bfd_boolean elf32_hppa_finish_dynamic_sections
    407398  PARAMS ((bfd *, struct bfd_link_info *));
    408399
     
    423414     const char *string;
    424415{
    425   struct elf32_hppa_stub_hash_entry *ret;
    426 
    427   ret = (struct elf32_hppa_stub_hash_entry *) entry;
    428 
    429416  /* Allocate the structure if it has not already been allocated by a
    430417     subclass.  */
    431   if (ret == NULL)
    432     {
    433       ret = ((struct elf32_hppa_stub_hash_entry *)
    434              bfd_hash_allocate (table,
    435                                 sizeof (struct elf32_hppa_stub_hash_entry)));
    436       if (ret == NULL)
    437         return NULL;
     418  if (entry == NULL)
     419    {
     420      entry = bfd_hash_allocate (table,
     421                                 sizeof (struct elf32_hppa_stub_hash_entry));
     422      if (entry == NULL)
     423        return entry;
    438424    }
    439425
    440426  /* Call the allocation method of the superclass.  */
    441   ret = ((struct elf32_hppa_stub_hash_entry *)
    442          bfd_hash_newfunc ((struct bfd_hash_entry *) ret, table, string));
    443 
    444   if (ret)
    445     {
     427  entry = bfd_hash_newfunc (entry, table, string);
     428  if (entry != NULL)
     429    {
     430      struct elf32_hppa_stub_hash_entry *eh;
     431
    446432      /* Initialize the local fields.  */
    447       ret->stub_sec = NULL;
    448 #if ! LONG_BRANCH_PIC_IN_SHLIB
    449       ret->reloc_sec = NULL;
    450 #endif
    451       ret->stub_offset = 0;
    452       ret->target_value = 0;
    453       ret->target_section = NULL;
    454       ret->stub_type = hppa_stub_long_branch;
    455       ret->h = NULL;
    456       ret->id_sec = NULL;
    457     }
    458 
    459   return (struct bfd_hash_entry *) ret;
     433      eh = (struct elf32_hppa_stub_hash_entry *) entry;
     434      eh->stub_sec = NULL;
     435      eh->stub_offset = 0;
     436      eh->target_value = 0;
     437      eh->target_section = NULL;
     438      eh->stub_type = hppa_stub_long_branch;
     439      eh->h = NULL;
     440      eh->id_sec = NULL;
     441    }
     442
     443  return entry;
    460444}
    461445
     
    468452     const char *string;
    469453{
    470   struct elf32_hppa_link_hash_entry *ret;
    471 
    472   ret = (struct elf32_hppa_link_hash_entry *) entry;
    473 
    474454  /* Allocate the structure if it has not already been allocated by a
    475455     subclass.  */
    476   if (ret == NULL)
    477     {
    478       ret = ((struct elf32_hppa_link_hash_entry *)
    479              bfd_hash_allocate (table,
    480                                 sizeof (struct elf32_hppa_link_hash_entry)));
    481       if (ret == NULL)
    482         return NULL;
     456  if (entry == NULL)
     457    {
     458      entry = bfd_hash_allocate (table,
     459                                 sizeof (struct elf32_hppa_link_hash_entry));
     460      if (entry == NULL)
     461        return entry;
    483462    }
    484463
    485464  /* Call the allocation method of the superclass.  */
    486   ret = ((struct elf32_hppa_link_hash_entry *)
    487          _bfd_elf_link_hash_newfunc ((struct bfd_hash_entry *) ret,
    488                                      table, string));
    489 
    490   if (ret)
    491     {
     465  entry = _bfd_elf_link_hash_newfunc (entry, table, string);
     466  if (entry != NULL)
     467    {
     468      struct elf32_hppa_link_hash_entry *eh;
     469
    492470      /* Initialize the local fields.  */
    493 #if ! LONG_BRANCH_PIC_IN_SHLIB
    494       ret->stub_reloc_sec = NULL;
    495 #endif
    496       ret->stub_cache = NULL;
    497 #if ! LONG_BRANCH_PIC_IN_SHLIB || RELATIVE_DYNAMIC_RELOCS
    498       ret->reloc_entries = NULL;
    499 #endif
    500       ret->maybe_pic_call = 0;
    501       ret->pic_call = 0;
    502       ret->plabel = 0;
    503       ret->plt_abs = 0;
    504     }
    505 
    506   return (struct bfd_hash_entry *) ret;
     471      eh = (struct elf32_hppa_link_hash_entry *) entry;
     472      eh->stub_cache = NULL;
     473      eh->dyn_relocs = NULL;
     474      eh->pic_call = 0;
     475      eh->plabel = 0;
     476    }
     477
     478  return entry;
    507479}
    508480
     
    516488{
    517489  struct elf32_hppa_link_hash_table *ret;
    518 
    519   ret = ((struct elf32_hppa_link_hash_table *) bfd_alloc (abfd, sizeof (*ret)));
     490  bfd_size_type amt = sizeof (*ret);
     491
     492  ret = (struct elf32_hppa_link_hash_table *) bfd_malloc (amt);
    520493  if (ret == NULL)
    521494    return NULL;
    522495
    523   if (!_bfd_elf_link_hash_table_init (&ret->root, abfd, hppa_link_hash_newfunc))
    524     {
    525       bfd_release (abfd, ret);
     496  if (!_bfd_elf_link_hash_table_init (&ret->elf, abfd, hppa_link_hash_newfunc))
     497    {
     498      free (ret);
    526499      return NULL;
    527500    }
     
    546519  ret->has_12bit_branch = 0;
    547520  ret->has_17bit_branch = 0;
     521  ret->has_22bit_branch = 0;
    548522  ret->need_plt_stub = 0;
    549 
    550   return &ret->root.root;
     523  ret->sym_sec.abfd = NULL;
     524
     525  return &ret->elf.root;
     526}
     527
     528/* Free the derived linker hash table.  */
     529
     530static void
     531elf32_hppa_link_hash_table_free (hash)
     532     struct bfd_link_hash_table *hash;
     533{
     534  struct elf32_hppa_link_hash_table *ret
     535    = (struct elf32_hppa_link_hash_table *) hash;
     536
     537  bfd_hash_table_free (&ret->stub_hash_table);
     538  _bfd_generic_link_hash_table_free (hash);
    551539}
    552540
     
    561549{
    562550  char *stub_name;
    563   size_t len;
     551  bfd_size_type len;
    564552
    565553  if (hash)
     
    595583
    596584static struct elf32_hppa_stub_hash_entry *
    597 hppa_get_stub_entry (input_section, sym_sec, hash, rel, hplink)
     585hppa_get_stub_entry (input_section, sym_sec, hash, rel, htab)
    598586     const asection *input_section;
    599587     const asection *sym_sec;
    600588     struct elf32_hppa_link_hash_entry *hash;
    601589     const Elf_Internal_Rela *rel;
    602      struct elf32_hppa_link_hash_table *hplink;
     590     struct elf32_hppa_link_hash_table *htab;
    603591{
    604592  struct elf32_hppa_stub_hash_entry *stub_entry;
     
    610598     more than one stub used to reach say, printf, and we need to
    611599     distinguish between them.  */
    612   id_sec = hplink->stub_group[input_section->id].link_sec;
     600  id_sec = htab->stub_group[input_section->id].link_sec;
    613601
    614602  if (hash != NULL && hash->stub_cache != NULL
     
    626614        return NULL;
    627615
    628       stub_entry = hppa_stub_hash_lookup (&hplink->stub_hash_table,
    629                                           stub_name, false, false);
    630       if (stub_entry == NULL)
    631         {
    632           if (hash == NULL || hash->elf.root.type != bfd_link_hash_undefweak)
    633             (*_bfd_error_handler) (_("%s(%s+0x%lx): cannot find stub entry %s"),
    634                                    bfd_get_filename (input_section->owner),
    635                                    input_section->name,
    636                                    (long) rel->r_offset,
    637                                    stub_name);
    638         }
    639       else
    640         {
    641           if (hash != NULL)
    642             hash->stub_cache = stub_entry;
    643         }
     616      stub_entry = hppa_stub_hash_lookup (&htab->stub_hash_table,
     617                                          stub_name, FALSE, FALSE);
     618      if (hash != NULL)
     619        hash->stub_cache = stub_entry;
    644620
    645621      free (stub_name);
     
    653629
    654630static struct elf32_hppa_stub_hash_entry *
    655 hppa_add_stub (stub_name, section, hplink)
     631hppa_add_stub (stub_name, section, htab)
    656632     const char *stub_name;
    657633     asection *section;
    658      struct elf32_hppa_link_hash_table *hplink;
     634     struct elf32_hppa_link_hash_table *htab;
    659635{
    660636  asection *link_sec;
     
    662638  struct elf32_hppa_stub_hash_entry *stub_entry;
    663639
    664   link_sec = hplink->stub_group[section->id].link_sec;
    665   stub_sec = hplink->stub_group[section->id].stub_sec;
     640  link_sec = htab->stub_group[section->id].link_sec;
     641  stub_sec = htab->stub_group[section->id].stub_sec;
    666642  if (stub_sec == NULL)
    667643    {
    668       stub_sec = hplink->stub_group[link_sec->id].stub_sec;
     644      stub_sec = htab->stub_group[link_sec->id].stub_sec;
    669645      if (stub_sec == NULL)
    670646        {
    671           size_t len;
     647          size_t namelen;
     648          bfd_size_type len;
    672649          char *s_name;
    673650
    674           len = strlen (link_sec->name) + sizeof (STUB_SUFFIX);
    675           s_name = bfd_alloc (hplink->stub_bfd, len);
     651          namelen = strlen (link_sec->name);
     652          len = namelen + sizeof (STUB_SUFFIX);
     653          s_name = bfd_alloc (htab->stub_bfd, len);
    676654          if (s_name == NULL)
    677655            return NULL;
    678656
    679           strcpy (s_name, link_sec->name);
    680           strcpy (s_name + len - sizeof (STUB_SUFFIX), STUB_SUFFIX);
    681           stub_sec = (*hplink->add_stub_section) (s_name, link_sec);
     657          memcpy (s_name, link_sec->name, namelen);
     658          memcpy (s_name + namelen, STUB_SUFFIX, sizeof (STUB_SUFFIX));
     659          stub_sec = (*htab->add_stub_section) (s_name, link_sec);
    682660          if (stub_sec == NULL)
    683661            return NULL;
    684           hplink->stub_group[link_sec->id].stub_sec = stub_sec;
    685         }
    686       hplink->stub_group[section->id].stub_sec = stub_sec;
     662          htab->stub_group[link_sec->id].stub_sec = stub_sec;
     663        }
     664      htab->stub_group[section->id].stub_sec = stub_sec;
    687665    }
    688666
    689667  /* Enter this entry into the linker stub hash table.  */
    690   stub_entry = hppa_stub_hash_lookup (&hplink->stub_hash_table, stub_name,
    691                                       true, false);
     668  stub_entry = hppa_stub_hash_lookup (&htab->stub_hash_table, stub_name,
     669                                      TRUE, FALSE);
    692670  if (stub_entry == NULL)
    693671    {
    694672      (*_bfd_error_handler) (_("%s: cannot create stub entry %s"),
    695                              bfd_get_filename (section->owner),
     673                             bfd_archive_filename (section->owner),
    696674                             stub_name);
    697675      return NULL;
     
    699677
    700678  stub_entry->stub_sec = stub_sec;
    701 #if ! LONG_BRANCH_PIC_IN_SHLIB
    702   stub_entry->reloc_sec = hplink->stub_group[section->id].reloc_sec;
    703 #endif
    704679  stub_entry->stub_offset = 0;
    705680  stub_entry->id_sec = link_sec;
     
    722697
    723698  if (hash != NULL
    724       && (((hash->elf.root.type == bfd_link_hash_defined
    725             || hash->elf.root.type == bfd_link_hash_defweak)
    726            && hash->elf.root.u.def.section->output_section == NULL)
    727           || (hash->elf.root.type == bfd_link_hash_defweak
    728               && hash->elf.dynindx != -1
    729               && hash->elf.plt.offset != (bfd_vma) -1)
    730           || hash->elf.root.type == bfd_link_hash_undefweak
    731           || hash->elf.root.type == bfd_link_hash_undefined
    732           || (hash->maybe_pic_call && !(input_sec->flags & SEC_HAS_GOT_REF))))
    733     {
    734       /* If output_section is NULL, then it's a symbol defined in a
    735          shared library.  We will need an import stub.  Decide between
    736          hppa_stub_import and hppa_stub_import_shared later.  For
    737          shared links we need stubs for undefined or weak syms too;
    738          They will presumably be resolved by the dynamic linker.  */
     699      && hash->elf.plt.offset != (bfd_vma) -1
     700      && (hash->elf.dynindx != -1 || hash->pic_call)
     701      && !hash->plabel)
     702    {
     703      /* We need an import stub.  Decide between hppa_stub_import
     704         and hppa_stub_import_shared later.  */
    739705      return hppa_stub_import;
    740706    }
     
    766732
    767733  if (branch_offset + max_branch_offset >= 2*max_branch_offset)
    768     {
    769 #if LONG_BRANCH_VIA_PLT
    770       if (hash != NULL
    771           && hash->elf.dynindx != -1
    772           && hash->elf.plt.offset != (bfd_vma) -1
    773           && hash->elf.type != STT_PARISC_MILLI)
    774         {
    775           /* If we are doing a shared link and find we need a long
    776              branch stub, then go via the .plt if possible.  */
    777           return hppa_stub_import;
    778         }
    779       else
    780 #endif
    781         return hppa_stub_long_branch;
    782     }
     734    return hppa_stub_long_branch;
     735
    783736  return hppa_stub_none;
    784737}
     
    807760#define STW_RP          0x6bc23fd1      /* stw   %rp,-24(%sr0,%sp)      */
    808761
     762#define BL22_RP         0xe800a002      /* b,l,n XXX,%rp                */
    809763#define BL_RP           0xe8400002      /* b,l,n XXX,%rp                */
    810764#define NOP             0x08000240      /* nop                          */
     
    823777#endif
    824778
    825 static boolean
     779static bfd_boolean
    826780hppa_build_one_stub (gen_entry, in_arg)
    827781     struct bfd_hash_entry *gen_entry;
     
    830784  struct elf32_hppa_stub_hash_entry *stub_entry;
    831785  struct bfd_link_info *info;
    832   struct elf32_hppa_link_hash_table *hplink;
     786  struct elf32_hppa_link_hash_table *htab;
    833787  asection *stub_sec;
    834788  bfd *stub_bfd;
     
    844798  info = (struct bfd_link_info *) in_arg;
    845799
    846   hplink = hppa_link_hash_table (info);
     800  htab = hppa_link_hash_table (info);
    847801  stub_sec = stub_entry->stub_sec;
    848802
     
    872826      bfd_put_32 (stub_bfd, insn, loc + 4);
    873827
    874 #if ! LONG_BRANCH_PIC_IN_SHLIB
    875       if (info->shared)
    876         {
    877           /* Output a dynamic relocation for this stub.  We only
    878              output one PCREL21L reloc per stub, trusting that the
    879              dynamic linker will also fix the implied PCREL17R for the
    880              second instruction.  PCREL21L dynamic relocs had better
    881              never be emitted for some other purpose...  */
    882           asection *srel;
    883           Elf_Internal_Rela outrel;
    884 
    885           if (stub_entry->h == NULL)
    886             {
    887               (*_bfd_error_handler)
    888                 (_("%s(%s+0x%lx): cannot relocate %s, recompile with -ffunction-sections"),
    889                  bfd_get_filename (stub_entry->target_section->owner),
    890                  stub_sec->name,
    891                  (long) stub_entry->stub_offset,
    892                  stub_entry->root.string);
    893               bfd_set_error (bfd_error_bad_value);
    894               return false;
    895             }
    896 
    897           srel = stub_entry->reloc_sec;
    898           if (srel == NULL)
    899             {
    900               (*_bfd_error_handler)
    901                 (_("Could not find relocation section for %s"),
    902                  stub_sec->name);
    903               bfd_set_error (bfd_error_bad_value);
    904               return false;
    905             }
    906 
    907           outrel.r_offset = (stub_entry->stub_offset
    908                              + stub_sec->output_offset
    909                              + stub_sec->output_section->vma);
    910           outrel.r_info = ELF32_R_INFO (0, R_PARISC_PCREL21L);
    911           outrel.r_addend = sym_value;
    912           bfd_elf32_swap_reloca_out (stub_sec->output_section->owner,
    913                                      &outrel,
    914                                      ((Elf32_External_Rela *)
    915                                       srel->contents + srel->reloc_count));
    916           ++srel->reloc_count;
    917         }
    918 #endif
    919828      size = 8;
    920829      break;
     
    950859      off &= ~ (bfd_vma) 1;
    951860      sym_value = (off
    952                    + hplink->splt->output_offset
    953                    + hplink->splt->output_section->vma
    954                    - elf_gp (hplink->splt->output_section->owner));
     861                   + htab->splt->output_offset
     862                   + htab->splt->output_section->vma
     863                   - elf_gp (htab->splt->output_section->owner));
    955864
    956865      insn = ADDIL_DP;
     
    972881      bfd_put_32 (stub_bfd, insn, loc + 4);
    973882
    974       if (hplink->multi_subspace)
     883      if (htab->multi_subspace)
    975884        {
    976885          val = hppa_field_adjust (sym_value, (bfd_signed_vma) 4, e_rrsel);
     
    1005914          bfd_vma value;
    1006915
    1007           dynobj = hplink->root.dynobj;
     916          dynobj = htab->elf.dynobj;
    1008917          eh = (struct elf32_hppa_link_hash_entry *) stub_entry->h;
    1009918
     
    1022931             <__gp>.  */
    1023932
    1024           bfd_put_32 (hplink->splt->owner, value,
    1025                       hplink->splt->contents + off);
    1026           value = elf_gp (hplink->splt->output_section->owner);
    1027           bfd_put_32 (hplink->splt->owner, value,
    1028                       hplink->splt->contents + off + 4);
     933          bfd_put_32 (htab->splt->owner, value,
     934                      htab->splt->contents + off);
     935          value = elf_gp (htab->splt->output_section->owner);
     936          bfd_put_32 (htab->splt->owner, value,
     937                      htab->splt->contents + off + 4);
    1029938        }
    1030939      break;
     
    1041950                    + stub_sec->output_section->vma);
    1042951
    1043       if (sym_value - 8 + 0x40000 >= 0x80000)
     952      if (sym_value - 8 + (1 << (17 + 1)) >= (1 << (17 + 2))
     953          && (!htab->has_22bit_branch
     954              || sym_value - 8 + (1 << (22 + 1)) >= (1 << (22 + 2))))
    1044955        {
    1045956          (*_bfd_error_handler)
    1046957            (_("%s(%s+0x%lx): cannot reach %s, recompile with -ffunction-sections"),
    1047              bfd_get_filename (stub_entry->target_section->owner),
     958             bfd_archive_filename (stub_entry->target_section->owner),
    1048959             stub_sec->name,
    1049960             (long) stub_entry->stub_offset,
    1050961             stub_entry->root.string);
    1051962          bfd_set_error (bfd_error_bad_value);
    1052           return false;
     963          return FALSE;
    1053964        }
    1054965
    1055966      val = hppa_field_adjust (sym_value, (bfd_signed_vma) -8, e_fsel) >> 2;
    1056       insn = hppa_rebuild_insn ((int) BL_RP, val, 17);
     967      if (!htab->has_22bit_branch)
     968        insn = hppa_rebuild_insn ((int) BL_RP, val, 17);
     969      else
     970        insn = hppa_rebuild_insn ((int) BL22_RP, val, 22);
    1057971      bfd_put_32 (stub_bfd, insn, loc);
    1058972
     
    1072986    default:
    1073987      BFD_FAIL ();
    1074       return false;
     988      return FALSE;
    1075989    }
    1076990
    1077991  stub_sec->_raw_size += size;
    1078   return true;
     992  return TRUE;
    1079993}
    1080994
     
    11041018   we know stub section sizes.  */
    11051019
    1106 static boolean
     1020static bfd_boolean
    11071021hppa_size_one_stub (gen_entry, in_arg)
    11081022     struct bfd_hash_entry *gen_entry;
     
    11101024{
    11111025  struct elf32_hppa_stub_hash_entry *stub_entry;
    1112   struct elf32_hppa_link_hash_table *hplink;
     1026  struct elf32_hppa_link_hash_table *htab;
    11131027  int size;
    11141028
    11151029  /* Massage our args to the form they really have.  */
    11161030  stub_entry = (struct elf32_hppa_stub_hash_entry *) gen_entry;
    1117   hplink = (struct elf32_hppa_link_hash_table *) in_arg;
     1031  htab = (struct elf32_hppa_link_hash_table *) in_arg;
    11181032
    11191033  if (stub_entry->stub_type == hppa_stub_long_branch)
    1120     {
    1121 #if ! LONG_BRANCH_PIC_IN_SHLIB
    1122       if (stub_entry->reloc_sec != NULL)
    1123         stub_entry->reloc_sec->_raw_size += sizeof (Elf32_External_Rela);
    1124 #endif
    1125       size = 8;
    1126     }
     1034    size = 8;
    11271035  else if (stub_entry->stub_type == hppa_stub_long_branch_shared)
    11281036    size = 12;
     
    11311039  else /* hppa_stub_import or hppa_stub_import_shared.  */
    11321040    {
    1133       if (hplink->multi_subspace)
     1041      if (htab->multi_subspace)
    11341042        size = 28;
    11351043      else
     
    11381046
    11391047  stub_entry->stub_sec->_raw_size += size;
    1140   return true;
     1048  return TRUE;
    11411049}
    11421050
     
    11441052   Additionally we set the default architecture and machine.  */
    11451053
    1146 static boolean
     1054static bfd_boolean
    11471055elf32_hppa_object_p (abfd)
    11481056     bfd *abfd;
     
    11551063    {
    11561064      if (i_ehdrp->e_ident[EI_OSABI] != ELFOSABI_LINUX)
    1157         return false;
     1065        return FALSE;
    11581066    }
    11591067  else
    11601068    {
    11611069      if (i_ehdrp->e_ident[EI_OSABI] != ELFOSABI_HPUX)
    1162         return false;
     1070        return FALSE;
    11631071    }
    11641072
     
    11751083      return bfd_default_set_arch_mach (abfd, bfd_arch_hppa, 25);
    11761084    }
    1177   return true;
     1085  return TRUE;
    11781086}
    11791087
     
    11811089   value of each external symbol.  */
    11821090
    1183 static boolean
     1091static bfd_boolean
    11841092elf32_hppa_add_symbol_hook (abfd, info, sym, namep, flagsp, secp, valp)
    11851093     bfd *abfd ATTRIBUTE_UNUSED;
     
    11921100{
    11931101  *valp += (*secp)->vma;
    1194   return true;
     1102  return TRUE;
    11951103}
    11961104
     
    11981106   short-cuts to various dynamic sections.  */
    11991107
    1200 static boolean
     1108static bfd_boolean
    12011109elf32_hppa_create_dynamic_sections (abfd, info)
    12021110     bfd *abfd;
    12031111     struct bfd_link_info *info;
    12041112{
    1205   struct elf32_hppa_link_hash_table *hplink;
     1113  struct elf32_hppa_link_hash_table *htab;
    12061114
    12071115  /* Don't try to create the .plt and .got twice.  */
    1208   hplink = hppa_link_hash_table (info);
    1209   if (hplink->splt != NULL)
    1210     return true;
     1116  htab = hppa_link_hash_table (info);
     1117  if (htab->splt != NULL)
     1118    return TRUE;
    12111119
    12121120  /* Call the generic code to do most of the work.  */
    12131121  if (! _bfd_elf_create_dynamic_sections (abfd, info))
    1214     return false;
    1215 
    1216   hplink->splt = bfd_get_section_by_name (abfd, ".plt");
    1217   hplink->srelplt = bfd_get_section_by_name (abfd, ".rela.plt");
    1218 
    1219   hplink->sgot = bfd_get_section_by_name (abfd, ".got");
    1220   hplink->srelgot = bfd_make_section (abfd, ".rela.got");
    1221   if (hplink->srelgot == NULL
    1222       || ! bfd_set_section_flags (abfd, hplink->srelgot,
     1122    return FALSE;
     1123
     1124  htab->splt = bfd_get_section_by_name (abfd, ".plt");
     1125  htab->srelplt = bfd_get_section_by_name (abfd, ".rela.plt");
     1126
     1127  htab->sgot = bfd_get_section_by_name (abfd, ".got");
     1128  htab->srelgot = bfd_make_section (abfd, ".rela.got");
     1129  if (htab->srelgot == NULL
     1130      || ! bfd_set_section_flags (abfd, htab->srelgot,
    12231131                                  (SEC_ALLOC
    12241132                                   | SEC_LOAD
     
    12271135                                   | SEC_LINKER_CREATED
    12281136                                   | SEC_READONLY))
    1229       || ! bfd_set_section_alignment (abfd, hplink->srelgot, 2))
    1230     return false;
    1231 
    1232   hplink->sdynbss = bfd_get_section_by_name (abfd, ".dynbss");
    1233   hplink->srelbss = bfd_get_section_by_name (abfd, ".rela.bss");
    1234 
    1235   return true;
     1137      || ! bfd_set_section_alignment (abfd, htab->srelgot, 2))
     1138    return FALSE;
     1139
     1140  htab->sdynbss = bfd_get_section_by_name (abfd, ".dynbss");
     1141  htab->srelbss = bfd_get_section_by_name (abfd, ".rela.bss");
     1142
     1143  return TRUE;
    12361144}
    12371145
     1146/* Copy the extra info we tack onto an elf_link_hash_entry.  */
     1147
     1148static void
     1149elf32_hppa_copy_indirect_symbol (bed, dir, ind)
     1150     struct elf_backend_data *bed;
     1151     struct elf_link_hash_entry *dir, *ind;
     1152{
     1153  struct elf32_hppa_link_hash_entry *edir, *eind;
     1154
     1155  edir = (struct elf32_hppa_link_hash_entry *) dir;
     1156  eind = (struct elf32_hppa_link_hash_entry *) ind;
     1157
     1158  if (eind->dyn_relocs != NULL)
     1159    {
     1160      if (edir->dyn_relocs != NULL)
     1161        {
     1162          struct elf32_hppa_dyn_reloc_entry **pp;
     1163          struct elf32_hppa_dyn_reloc_entry *p;
     1164
     1165          if (ind->root.type == bfd_link_hash_indirect)
     1166            abort ();
     1167
     1168          /* Add reloc counts against the weak sym to the strong sym
     1169             list.  Merge any entries against the same section.  */
     1170          for (pp = &eind->dyn_relocs; (p = *pp) != NULL; )
     1171            {
     1172              struct elf32_hppa_dyn_reloc_entry *q;
     1173
     1174              for (q = edir->dyn_relocs; q != NULL; q = q->next)
     1175                if (q->sec == p->sec)
     1176                  {
     1177#if RELATIVE_DYNRELOCS
     1178                    q->relative_count += p->relative_count;
     1179#endif
     1180                    q->count += p->count;
     1181                    *pp = p->next;
     1182                    break;
     1183                  }
     1184              if (q == NULL)
     1185                pp = &p->next;
     1186            }
     1187          *pp = edir->dyn_relocs;
     1188        }
     1189
     1190      edir->dyn_relocs = eind->dyn_relocs;
     1191      eind->dyn_relocs = NULL;
     1192    }
     1193
     1194  _bfd_elf_link_hash_copy_indirect (bed, dir, ind);
     1195}
     1196
    12381197/* Look through the relocs for a section during the first phase, and
    1239    allocate space in the global offset table or procedure linkage
    1240    table.  At this point we haven't necessarily read all the input
    1241    files.  */
    1242 
    1243 static boolean
     1198   calculate needed space in the global offset table, procedure linkage
     1199   table, and dynamic reloc sections.  At this point we haven't
     1200   necessarily read all the input files.  */
     1201
     1202static bfd_boolean
    12441203elf32_hppa_check_relocs (abfd, info, sec, relocs)
    12451204     bfd *abfd;
     
    12481207     const Elf_Internal_Rela *relocs;
    12491208{
    1250   bfd *dynobj;
    12511209  Elf_Internal_Shdr *symtab_hdr;
    12521210  struct elf_link_hash_entry **sym_hashes;
    1253   bfd_signed_vma *local_got_refcounts;
    12541211  const Elf_Internal_Rela *rel;
    12551212  const Elf_Internal_Rela *rel_end;
    1256   struct elf32_hppa_link_hash_table *hplink;
     1213  struct elf32_hppa_link_hash_table *htab;
    12571214  asection *sreloc;
    12581215  asection *stubreloc;
    12591216
    12601217  if (info->relocateable)
    1261     return true;
    1262 
    1263   hplink = hppa_link_hash_table (info);
    1264   dynobj = hplink->root.dynobj;
     1218    return TRUE;
     1219
     1220  htab = hppa_link_hash_table (info);
    12651221  symtab_hdr = &elf_tdata (abfd)->symtab_hdr;
    12661222  sym_hashes = elf_sym_hashes (abfd);
    1267   local_got_refcounts = elf_local_got_refcounts (abfd);
    12681223  sreloc = NULL;
    12691224  stubreloc = NULL;
     
    12761231        NEED_PLT = 2,
    12771232        NEED_DYNREL = 4,
    1278 #if LONG_BRANCH_PIC_IN_SHLIB
    1279         NEED_STUBREL = 0,  /* We won't be needing them in this case.  */
    1280 #else
    1281         NEED_STUBREL = 8,
    1282 #endif
    1283         PLT_PLABEL = 16
     1233        PLT_PLABEL = 8
    12841234      };
    12851235
     
    13371287
    13381288        case R_PARISC_PCREL12F:
    1339           hplink->has_12bit_branch = 1;
    1340           /* Fall thru.  */
     1289          htab->has_12bit_branch = 1;
     1290          goto branch_common;
     1291
    13411292        case R_PARISC_PCREL17C:
    13421293        case R_PARISC_PCREL17F:
    1343           hplink->has_17bit_branch = 1;
    1344           /* Fall thru.  */
     1294          htab->has_17bit_branch = 1;
     1295          goto branch_common;
     1296
    13451297        case R_PARISC_PCREL22F:
     1298          htab->has_22bit_branch = 1;
     1299        branch_common:
    13461300          /* Function calls might need to go through the .plt, and
    13471301             might require long branch stubs.  */
     
    13621316                 where a symbol is forced local by versioning, or due
    13631317                 to symbolic linking, and we lose the .plt entry.  */
    1364               need_entry = NEED_PLT | NEED_STUBREL;
     1318              need_entry = NEED_PLT;
    13651319              if (h->elf.type == STT_PARISC_MILLI)
    1366                 need_entry = NEED_STUBREL;
     1320                need_entry = 0;
    13671321            }
    13681322          break;
     
    13851339              (*_bfd_error_handler)
    13861340                (_("%s: relocation %s can not be used when making a shared object; recompile with -fPIC"),
    1387                  bfd_get_filename (abfd),
     1341                 bfd_archive_filename (abfd),
    13881342                 elf_hppa_howto_table[r_type].name);
    13891343              bfd_set_error (bfd_error_bad_value);
    1390               return false;
     1344              return FALSE;
    13911345            }
    13921346          /* Fall through.  */
     
    13971351        case R_PARISC_DIR14R:
    13981352        case R_PARISC_DIR21L: /* As above, and for ext branches too.  */
    1399 #if 1
     1353#if 0
    14001354          /* Help debug shared library creation.  Any of the above
    14011355             relocs can be used in shared libs, but they may cause
     
    14051359              (*_bfd_error_handler)
    14061360                (_("%s: relocation %s should not be used when making a shared object; recompile with -fPIC"),
    1407                  bfd_get_filename (abfd),
     1361                 bfd_archive_filename (abfd),
    14081362                 elf_hppa_howto_table[r_type].name);
    14091363            }
     
    14211375          if (!_bfd_elf32_gc_record_vtinherit (abfd, sec,
    14221376                                               &h->elf, rel->r_offset))
    1423             return false;
     1377            return FALSE;
    14241378          continue;
    14251379
     
    14291383          if (!_bfd_elf32_gc_record_vtentry (abfd, sec,
    14301384                                             &h->elf, rel->r_addend))
    1431             return false;
     1385            return FALSE;
    14321386          continue;
    14331387
     
    14411395          /* Allocate space for a GOT entry, as well as a dynamic
    14421396             relocation for this entry.  */
    1443           if (dynobj == NULL)
    1444             hplink->root.dynobj = dynobj = abfd;
    1445 
    1446           if (hplink->sgot == NULL)
     1397          if (htab->sgot == NULL)
    14471398            {
    1448               if (! elf32_hppa_create_dynamic_sections (dynobj, info))
    1449                 return false;
     1399              if (htab->elf.dynobj == NULL)
     1400                htab->elf.dynobj = abfd;
     1401              if (!elf32_hppa_create_dynamic_sections (htab->elf.dynobj, info))
     1402                return FALSE;
    14501403            }
    14511404
    14521405          if (h != NULL)
    14531406            {
    1454               if (h->elf.got.refcount == -1)
    1455                 {
    1456                   h->elf.got.refcount = 1;
    1457 
    1458                   /* Make sure this symbol is output as a dynamic symbol.  */
    1459                   if (h->elf.dynindx == -1)
    1460                     {
    1461                       if (! bfd_elf32_link_record_dynamic_symbol (info,
    1462                                                                   &h->elf))
    1463                         return false;
    1464                     }
    1465                 }
    1466               else
    1467                 h->elf.got.refcount += 1;
     1407              h->elf.got.refcount += 1;
    14681408            }
    14691409          else
    14701410            {
     1411              bfd_signed_vma *local_got_refcounts;
     1412
    14711413              /* This is a global offset table entry for a local symbol.  */
     1414              local_got_refcounts = elf_local_got_refcounts (abfd);
    14721415              if (local_got_refcounts == NULL)
    14731416                {
    1474                   size_t size;
     1417                  bfd_size_type size;
    14751418
    14761419                  /* Allocate space for local got offsets and local
     
    14781421                     elf_obj_tdata with another target specific
    14791422                     pointer.  */
    1480                   size = symtab_hdr->sh_info * 2 * sizeof (bfd_signed_vma);
     1423                  size = symtab_hdr->sh_info;
     1424                  size *= 2 * sizeof (bfd_signed_vma);
    14811425                  local_got_refcounts = ((bfd_signed_vma *)
    1482                                          bfd_alloc (abfd, size));
     1426                                         bfd_zalloc (abfd, size));
    14831427                  if (local_got_refcounts == NULL)
    1484                     return false;
     1428                    return FALSE;
    14851429                  elf_local_got_refcounts (abfd) = local_got_refcounts;
    1486                   memset (local_got_refcounts, -1, size);
    14871430                }
    1488               if (local_got_refcounts[r_symndx] == -1)
    1489                 local_got_refcounts[r_symndx] = 1;
    1490               else
    1491                 local_got_refcounts[r_symndx] += 1;
     1431              local_got_refcounts[r_symndx] += 1;
    14921432            }
    14931433        }
     
    15071447              if (h != NULL)
    15081448                {
    1509                   if (h->elf.plt.refcount == -1)
    1510                     {
    1511                       h->elf.plt.refcount = 1;
    1512                       h->elf.elf_link_hash_flags |= ELF_LINK_HASH_NEEDS_PLT;
    1513                     }
    1514                   else
    1515                     h->elf.plt.refcount += 1;
     1449                  h->elf.elf_link_hash_flags |= ELF_LINK_HASH_NEEDS_PLT;
     1450                  h->elf.plt.refcount += 1;
    15161451
    15171452                  /* If this .plt entry is for a plabel, mark it so
     
    15231458              else if (need_entry & PLT_PLABEL)
    15241459                {
    1525                   int indx;
    1526 
     1460                  bfd_signed_vma *local_got_refcounts;
     1461                  bfd_signed_vma *local_plt_refcounts;
     1462
     1463                  local_got_refcounts = elf_local_got_refcounts (abfd);
    15271464                  if (local_got_refcounts == NULL)
    15281465                    {
    1529                       size_t size;
     1466                      bfd_size_type size;
    15301467
    15311468                      /* Allocate space for local got offsets and local
    15321469                         plt offsets.  */
    1533                       size = symtab_hdr->sh_info * 2 * sizeof (bfd_signed_vma);
     1470                      size = symtab_hdr->sh_info;
     1471                      size *= 2 * sizeof (bfd_signed_vma);
    15341472                      local_got_refcounts = ((bfd_signed_vma *)
    1535                                              bfd_alloc (abfd, size));
     1473                                             bfd_zalloc (abfd, size));
    15361474                      if (local_got_refcounts == NULL)
    1537                         return false;
     1475                        return FALSE;
    15381476                      elf_local_got_refcounts (abfd) = local_got_refcounts;
    1539                       memset (local_got_refcounts, -1, size);
    15401477                    }
    1541                   indx = r_symndx + symtab_hdr->sh_info;
    1542                   if (local_got_refcounts[indx] == -1)
    1543                     local_got_refcounts[indx] = 1;
    1544                   else
    1545                     local_got_refcounts[indx] += 1;
     1478                  local_plt_refcounts = (local_got_refcounts
     1479                                         + symtab_hdr->sh_info);
     1480                  local_plt_refcounts[r_symndx] += 1;
    15461481                }
    15471482            }
    15481483        }
    15491484
    1550       if (need_entry & (NEED_DYNREL | NEED_STUBREL))
     1485      if (need_entry & NEED_DYNREL)
    15511486        {
    15521487          /* Flag this symbol as having a non-got, non-plt reference
    15531488             so that we generate copy relocs if it turns out to be
    15541489             dynamic.  */
    1555           if (h != NULL)
     1490          if (h != NULL && !info->shared)
    15561491            h->elf.elf_link_hash_flags |= ELF_LINK_NON_GOT_REF;
    15571492
     
    15661501             DEF_REGULAR is not set now but will be set later (it is
    15671502             never cleared).  We account for that possibility below by
    1568              storing information in the reloc_entries field of the
     1503             storing information in the dyn_relocs field of the
    15691504             hash table entry.
    15701505
     
    15781513             is absolute too, as in that case it is the reloc in the
    15791514             stub we will be creating, rather than copying the PCREL
    1580              reloc in the branch.  */
    1581           if ((sec->flags & SEC_ALLOC) != 0
    1582               && info->shared
    1583 #if RELATIVE_DYNAMIC_RELOCS
    1584               && (!info->symbolic
    1585                   || is_absolute_reloc (r_type)
    1586                   || (h != NULL
    1587                       && ((h->elf.elf_link_hash_flags
    1588                            & ELF_LINK_HASH_DEF_REGULAR) == 0)))
    1589 #endif
    1590               )
     1515             reloc in the branch.
     1516
     1517             If on the other hand, we are creating an executable, we
     1518             may need to keep relocations for symbols satisfied by a
     1519             dynamic library if we manage to avoid copy relocs for the
     1520             symbol.  */
     1521          if ((info->shared
     1522               && (sec->flags & SEC_ALLOC) != 0
     1523               && (IS_ABSOLUTE_RELOC (r_type)
     1524                   || (h != NULL
     1525                       && (!info->symbolic
     1526                           || h->elf.root.type == bfd_link_hash_defweak
     1527                           || (h->elf.elf_link_hash_flags
     1528                               & ELF_LINK_HASH_DEF_REGULAR) == 0))))
     1529              || (!info->shared
     1530                  && (sec->flags & SEC_ALLOC) != 0
     1531                  && h != NULL
     1532                  && (h->elf.root.type == bfd_link_hash_defweak
     1533                      || (h->elf.elf_link_hash_flags
     1534                          & ELF_LINK_HASH_DEF_REGULAR) == 0)))
    15911535            {
    1592               boolean doit;
    1593               asection *srel;
    1594 
    1595               srel = sreloc;
    1596               if ((need_entry & NEED_STUBREL))
    1597                 srel = stubreloc;
     1536              struct elf32_hppa_dyn_reloc_entry *p;
     1537              struct elf32_hppa_dyn_reloc_entry **head;
    15981538
    15991539              /* Create a reloc section in dynobj and make room for
    16001540                 this reloc.  */
    1601               if (srel == NULL)
     1541              if (sreloc == NULL)
    16021542                {
    16031543                  char *name;
    1604 
    1605                   if (dynobj == NULL)
    1606                     hplink->root.dynobj = dynobj = abfd;
    1607 
    1608                   name = bfd_elf_string_from_elf_section
    1609                     (abfd,
    1610                      elf_elfheader (abfd)->e_shstrndx,
    1611                      elf_section_data (sec)->rel_hdr.sh_name);
     1544                  bfd *dynobj;
     1545
     1546                  name = (bfd_elf_string_from_elf_section
     1547                          (abfd,
     1548                           elf_elfheader (abfd)->e_shstrndx,
     1549                           elf_section_data (sec)->rel_hdr.sh_name));
    16121550                  if (name == NULL)
    16131551                    {
     
    16161554                         sec->name);
    16171555                      bfd_set_error (bfd_error_bad_value);
    1618                       return false;
     1556                      return FALSE;
    16191557                    }
    16201558
    1621                   if ((need_entry & NEED_STUBREL))
    1622                     {
    1623                       size_t len = strlen (name) + sizeof (STUB_SUFFIX);
    1624                       char *newname = bfd_malloc (len);
    1625 
    1626                       if (newname == NULL)
    1627                         return false;
    1628                       strcpy (newname, name);
    1629                       strcpy (newname + len - sizeof (STUB_SUFFIX),
    1630                               STUB_SUFFIX);
    1631                       name = newname;
    1632                     }
    1633 
    1634                   srel = bfd_get_section_by_name (dynobj, name);
    1635                   if (srel == NULL)
     1559                  if (htab->elf.dynobj == NULL)
     1560                    htab->elf.dynobj = abfd;
     1561
     1562                  dynobj = htab->elf.dynobj;
     1563                  sreloc = bfd_get_section_by_name (dynobj, name);
     1564                  if (sreloc == NULL)
    16361565                    {
    16371566                      flagword flags;
    16381567
    1639                       srel = bfd_make_section (dynobj, name);
     1568                      sreloc = bfd_make_section (dynobj, name);
    16401569                      flags = (SEC_HAS_CONTENTS | SEC_READONLY
    16411570                               | SEC_IN_MEMORY | SEC_LINKER_CREATED);
    16421571                      if ((sec->flags & SEC_ALLOC) != 0)
    16431572                        flags |= SEC_ALLOC | SEC_LOAD;
    1644                       if (srel == NULL
    1645                           || !bfd_set_section_flags (dynobj, srel, flags)
    1646                           || !bfd_set_section_alignment (dynobj, srel, 2))
    1647                         return false;
     1573                      if (sreloc == NULL
     1574                          || !bfd_set_section_flags (dynobj, sreloc, flags)
     1575                          || !bfd_set_section_alignment (dynobj, sreloc, 2))
     1576                        return FALSE;
    16481577                    }
    1649                   else if ((need_entry & NEED_STUBREL))
    1650                     free (name);
    1651 
    1652                   if ((need_entry & NEED_STUBREL))
    1653                     stubreloc = srel;
    1654                   else
    1655                     sreloc = srel;
     1578
     1579                  elf_section_data (sec)->sreloc = sreloc;
    16561580                }
    16571581
    1658 #if ! LONG_BRANCH_PIC_IN_SHLIB
    1659               /* If this is a function call, we only need one dynamic
    1660                  reloc for the stub as all calls to a particular
    1661                  function will go through the same stub.  Actually, a
    1662                  long branch stub needs two relocations, but we count
    1663                  on some intelligence on the part of the dynamic
    1664                  linker.  */
    1665               if ((need_entry & NEED_STUBREL))
     1582              /* If this is a global symbol, we count the number of
     1583                 relocations we need for this symbol.  */
     1584              if (h != NULL)
    16661585                {
    1667                   doit = h->stub_reloc_sec != stubreloc;
    1668                   h->stub_reloc_sec = stubreloc;
     1586                  head = &h->dyn_relocs;
    16691587                }
    16701588              else
    1671 #endif
    1672                 doit = 1;
    1673 
    1674               if (doit)
    16751589                {
    1676                   srel->_raw_size += sizeof (Elf32_External_Rela);
    1677 
    1678 #if ! LONG_BRANCH_PIC_IN_SHLIB || RELATIVE_DYNAMIC_RELOCS
    1679                   /* Keep track of relocations we have entered for
    1680                      this global symbol, so that we can discard them
    1681                      later if necessary.  */
    1682                   if (h != NULL
    1683                       && (0
    1684 #if RELATIVE_DYNAMIC_RELOCS
    1685                           || ! is_absolute_reloc (rtype)
    1686 #endif
    1687                           || (need_entry & NEED_STUBREL)))
    1688                     {
    1689                       struct elf32_hppa_dyn_reloc_entry *p;
    1690 
    1691                       for (p = h->reloc_entries; p != NULL; p = p->next)
    1692                         if (p->section == srel)
    1693                           break;
    1694 
    1695                       if (p == NULL)
    1696                         {
    1697                           p = ((struct elf32_hppa_dyn_reloc_entry *)
    1698                                bfd_alloc (dynobj, sizeof *p));
    1699                           if (p == NULL)
    1700                             return false;
    1701                           p->next = h->reloc_entries;
    1702                           h->reloc_entries = p;
    1703                           p->section = srel;
    1704                           p->count = 0;
    1705                         }
    1706 
    1707                       /* NEED_STUBREL and NEED_DYNREL are never both
    1708                          set.  Leave the count at zero for the
    1709                          NEED_STUBREL case as we only ever have one
    1710                          stub reloc per section per symbol, and this
    1711                          simplifies code in hppa_discard_copies.  */
    1712                       if (! (need_entry & NEED_STUBREL))
    1713                         ++p->count;
    1714                     }
     1590                  /* Track dynamic relocs needed for local syms too.
     1591                     We really need local syms available to do this
     1592                     easily.  Oh well.  */
     1593
     1594                  asection *s;
     1595                  s = bfd_section_from_r_symndx (abfd, &htab->sym_sec,
     1596                                                 sec, r_symndx);
     1597                  if (s == NULL)
     1598                    return FALSE;
     1599
     1600                  head = ((struct elf32_hppa_dyn_reloc_entry **)
     1601                          &elf_section_data (s)->local_dynrel);
     1602                }
     1603
     1604              p = *head;
     1605              if (p == NULL || p->sec != sec)
     1606                {
     1607                  p = ((struct elf32_hppa_dyn_reloc_entry *)
     1608                       bfd_alloc (htab->elf.dynobj,
     1609                                  (bfd_size_type) sizeof *p));
     1610                  if (p == NULL)
     1611                    return FALSE;
     1612                  p->next = *head;
     1613                  *head = p;
     1614                  p->sec = sec;
     1615                  p->count = 0;
     1616#if RELATIVE_DYNRELOCS
     1617                  p->relative_count = 0;
    17151618#endif
    17161619                }
     1620
     1621              p->count += 1;
     1622#if RELATIVE_DYNRELOCS
     1623              if (!IS_ABSOLUTE_RELOC (rtype))
     1624                p->relative_count += 1;
     1625#endif
    17171626            }
    17181627        }
    17191628    }
    17201629
    1721   return true;
     1630  return TRUE;
    17221631}
    17231632
     
    17261635
    17271636static asection *
    1728 elf32_hppa_gc_mark_hook (abfd, info, rel, h, sym)
    1729      bfd *abfd;
     1637elf32_hppa_gc_mark_hook (sec, info, rel, h, sym)
     1638     asection *sec;
    17301639     struct bfd_link_info *info ATTRIBUTE_UNUSED;
    17311640     Elf_Internal_Rela *rel;
     
    17571666    }
    17581667  else
    1759     {
    1760       if (!(elf_bad_symtab (abfd)
    1761             && ELF_ST_BIND (sym->st_info) != STB_LOCAL)
    1762           && ! ((sym->st_shndx <= 0 || sym->st_shndx >= SHN_LORESERVE)
    1763                 && sym->st_shndx != SHN_COMMON))
    1764         {
    1765           return bfd_section_from_elf_index (abfd, sym->st_shndx);
    1766         }
    1767     }
     1668    return bfd_section_from_elf_index (sec->owner, sym->st_shndx);
    17681669
    17691670  return NULL;
     
    17731674   removed.  */
    17741675
    1775 static boolean
     1676static bfd_boolean
    17761677elf32_hppa_gc_sweep_hook (abfd, info, sec, relocs)
    17771678     bfd *abfd;
     
    17851686  bfd_signed_vma *local_plt_refcounts;
    17861687  const Elf_Internal_Rela *rel, *relend;
    1787   unsigned long r_symndx;
    1788   struct elf_link_hash_entry *h;
    1789   struct elf32_hppa_link_hash_table *hplink;
    1790   bfd *dynobj;
     1688
     1689  elf_section_data (sec)->local_dynrel = NULL;
    17911690
    17921691  symtab_hdr = &elf_tdata (abfd)->symtab_hdr;
     
    17961695  if (local_plt_refcounts != NULL)
    17971696    local_plt_refcounts += symtab_hdr->sh_info;
    1798   hplink = hppa_link_hash_table (info);
    1799   dynobj = hplink->root.dynobj;
    1800   if (dynobj == NULL)
    1801     return true;
    18021697
    18031698  relend = relocs + sec->reloc_count;
    18041699  for (rel = relocs; rel < relend; rel++)
    1805     switch ((unsigned int) ELF32_R_TYPE (rel->r_info))
    1806       {
    1807       case R_PARISC_DLTIND14F:
    1808       case R_PARISC_DLTIND14R:
    1809       case R_PARISC_DLTIND21L:
    1810         r_symndx = ELF32_R_SYM (rel->r_info);
    1811         if (r_symndx >= symtab_hdr->sh_info)
    1812           {
    1813             h = sym_hashes[r_symndx - symtab_hdr->sh_info];
    1814             if (h->got.refcount > 0)
    1815               h->got.refcount -= 1;
    1816           }
    1817         else if (local_got_refcounts != NULL)
    1818           {
    1819             if (local_got_refcounts[r_symndx] > 0)
    1820               local_got_refcounts[r_symndx] -= 1;
    1821           }
    1822         break;
    1823 
    1824       case R_PARISC_PCREL12F:
    1825       case R_PARISC_PCREL17C:
    1826       case R_PARISC_PCREL17F:
    1827       case R_PARISC_PCREL22F:
    1828         r_symndx = ELF32_R_SYM (rel->r_info);
    1829         if (r_symndx >= symtab_hdr->sh_info)
    1830           {
    1831             h = sym_hashes[r_symndx - symtab_hdr->sh_info];
    1832             if (h->plt.refcount > 0)
    1833               h->plt.refcount -= 1;
    1834           }
    1835         break;
    1836 
    1837       case R_PARISC_PLABEL14R:
    1838       case R_PARISC_PLABEL21L:
    1839       case R_PARISC_PLABEL32:
    1840         r_symndx = ELF32_R_SYM (rel->r_info);
    1841         if (r_symndx >= symtab_hdr->sh_info)
    1842           {
    1843             h = sym_hashes[r_symndx - symtab_hdr->sh_info];
    1844             if (h->plt.refcount > 0)
    1845               h->plt.refcount -= 1;
    1846           }
    1847         else if (local_plt_refcounts != NULL)
    1848           {
    1849             if (local_plt_refcounts[r_symndx] > 0)
    1850               local_plt_refcounts[r_symndx] -= 1;
    1851           }
    1852         break;
    1853 
    1854       default:
    1855         break;
    1856       }
    1857 
    1858   return true;
     1700    {
     1701      unsigned long r_symndx;
     1702      unsigned int r_type;
     1703      struct elf_link_hash_entry *h = NULL;
     1704
     1705      r_symndx = ELF32_R_SYM (rel->r_info);
     1706      if (r_symndx >= symtab_hdr->sh_info)
     1707        {
     1708          struct elf32_hppa_link_hash_entry *eh;
     1709          struct elf32_hppa_dyn_reloc_entry **pp;
     1710          struct elf32_hppa_dyn_reloc_entry *p;
     1711
     1712          h = sym_hashes[r_symndx - symtab_hdr->sh_info];
     1713          eh = (struct elf32_hppa_link_hash_entry *) h;
     1714
     1715          for (pp = &eh->dyn_relocs; (p = *pp) != NULL; pp = &p->next)
     1716            if (p->sec == sec)
     1717              {
     1718                /* Everything must go for SEC.  */
     1719                *pp = p->next;
     1720                break;
     1721              }
     1722        }
     1723
     1724      r_type = ELF32_R_TYPE (rel->r_info);
     1725      switch (r_type)
     1726        {
     1727        case R_PARISC_DLTIND14F:
     1728        case R_PARISC_DLTIND14R:
     1729        case R_PARISC_DLTIND21L:
     1730          if (h != NULL)
     1731            {
     1732              if (h->got.refcount > 0)
     1733                h->got.refcount -= 1;
     1734            }
     1735          else if (local_got_refcounts != NULL)
     1736            {
     1737              if (local_got_refcounts[r_symndx] > 0)
     1738                local_got_refcounts[r_symndx] -= 1;
     1739            }
     1740          break;
     1741
     1742        case R_PARISC_PCREL12F:
     1743        case R_PARISC_PCREL17C:
     1744        case R_PARISC_PCREL17F:
     1745        case R_PARISC_PCREL22F:
     1746          if (h != NULL)
     1747            {
     1748              if (h->plt.refcount > 0)
     1749                h->plt.refcount -= 1;
     1750            }
     1751          break;
     1752
     1753        case R_PARISC_PLABEL14R:
     1754        case R_PARISC_PLABEL21L:
     1755        case R_PARISC_PLABEL32:
     1756          if (h != NULL)
     1757            {
     1758              if (h->plt.refcount > 0)
     1759                h->plt.refcount -= 1;
     1760            }
     1761          else if (local_plt_refcounts != NULL)
     1762            {
     1763              if (local_plt_refcounts[r_symndx] > 0)
     1764                local_plt_refcounts[r_symndx] -= 1;
     1765            }
     1766          break;
     1767
     1768        default:
     1769          break;
     1770        }
     1771    }
     1772
     1773  return TRUE;
    18591774}
    18601775
     
    18631778
    18641779static void
    1865 elf32_hppa_hide_symbol (info, h)
    1866      struct bfd_link_info *info ATTRIBUTE_UNUSED;
     1780elf32_hppa_hide_symbol (info, h, force_local)
     1781     struct bfd_link_info *info;
    18671782     struct elf_link_hash_entry *h;
     1783     bfd_boolean force_local;
    18681784{
    1869   if ((h->elf_link_hash_flags & ELF_LINK_FORCED_LOCAL) != 0)
    1870     h->dynindx = -1;
     1785  if (force_local)
     1786    {
     1787      h->elf_link_hash_flags |= ELF_LINK_FORCED_LOCAL;
     1788      if (h->dynindx != -1)
     1789        {
     1790          h->dynindx = -1;
     1791          _bfd_elf_strtab_delref (elf_hash_table (info)->dynstr,
     1792                                  h->dynstr_index);
     1793        }
     1794    }
     1795
    18711796  if (! ((struct elf32_hppa_link_hash_entry *) h)->plabel)
    18721797    {
     
    18931818   understand.  */
    18941819
    1895 static boolean
     1820static bfd_boolean
    18961821elf32_hppa_adjust_dynamic_symbol (info, h)
    18971822     struct bfd_link_info *info;
    18981823     struct elf_link_hash_entry *h;
    18991824{
    1900   bfd *dynobj;
    1901   struct elf32_hppa_link_hash_table *hplink;
     1825  struct elf32_hppa_link_hash_table *htab;
     1826  struct elf32_hppa_link_hash_entry *eh;
     1827  struct elf32_hppa_dyn_reloc_entry *p;
    19021828  asection *s;
    1903 
    1904   hplink = hppa_link_hash_table (info);
    1905   dynobj = hplink->root.dynobj;
     1829  unsigned int power_of_two;
    19061830
    19071831  /* If this is a function, put it in the procedure linkage table.  We
    1908      will fill in the contents of the procedure linkage table later,
    1909      when we know the address of the .got section.  */
     1832     will fill in the contents of the procedure linkage table later.  */
    19101833  if (h->type == STT_FUNC
    19111834      || (h->elf_link_hash_flags & ELF_LINK_HASH_NEEDS_PLT) != 0)
    19121835    {
    1913       if (!info->shared
    1914           && h->plt.refcount > 0
    1915           && (h->elf_link_hash_flags & ELF_LINK_HASH_DEF_REGULAR) != 0
    1916           && (h->root.u.def.section->flags & SEC_HAS_GOT_REF) != 0)
    1917         {
    1918           ((struct elf32_hppa_link_hash_entry *) h)->maybe_pic_call = 1;
    1919         }
    1920 
    19211836      if (h->plt.refcount <= 0
    19221837          || ((h->elf_link_hash_flags & ELF_LINK_HASH_DEF_REGULAR) != 0
     
    19351850          /* As a special sop to the hppa ABI, we keep a .plt entry
    19361851             for functions in sections containing PIC code.  */
    1937           if (((struct elf32_hppa_link_hash_entry *) h)->maybe_pic_call)
     1852          if (!info->shared
     1853              && h->plt.refcount > 0
     1854              && (h->elf_link_hash_flags & ELF_LINK_HASH_DEF_REGULAR) != 0
     1855              && (h->root.u.def.section->flags & SEC_HAS_GOT_REF) != 0)
    19381856            ((struct elf32_hppa_link_hash_entry *) h)->pic_call = 1;
    19391857          else
     
    19411859              h->plt.offset = (bfd_vma) -1;
    19421860              h->elf_link_hash_flags &= ~ELF_LINK_HASH_NEEDS_PLT;
    1943               return true;
    19441861            }
    19451862        }
    19461863
    1947       if (! ((struct elf32_hppa_link_hash_entry *) h)->pic_call)
    1948         {
    1949           /* Make sure this symbol is output as a dynamic symbol.  */
    1950           if (h->dynindx == -1
    1951               && (h->elf_link_hash_flags & ELF_LINK_FORCED_LOCAL) == 0)
    1952             {
    1953               if (! bfd_elf32_link_record_dynamic_symbol (info, h))
    1954                 return false;
    1955             }
    1956         }
    1957 
    1958       return true;
    1959     }
     1864      return TRUE;
     1865    }
     1866  else
     1867    h->plt.offset = (bfd_vma) -1;
    19601868
    19611869  /* If this is a weak symbol, and there is a real definition, the
     
    19691877      h->root.u.def.section = h->weakdef->root.u.def.section;
    19701878      h->root.u.def.value = h->weakdef->root.u.def.value;
    1971       return true;
     1879      return TRUE;
    19721880    }
    19731881
     
    19801888     be handled correctly by relocate_section.  */
    19811889  if (info->shared)
    1982     return true;
     1890    return TRUE;
    19831891
    19841892  /* If there are no references to this symbol that do not use the
    19851893     GOT, we don't need to generate a copy reloc.  */
    19861894  if ((h->elf_link_hash_flags & ELF_LINK_NON_GOT_REF) == 0)
    1987     return true;
     1895    return TRUE;
     1896
     1897  eh = (struct elf32_hppa_link_hash_entry *) h;
     1898  for (p = eh->dyn_relocs; p != NULL; p = p->next)
     1899    {
     1900      s = p->sec->output_section;
     1901      if (s != NULL && (s->flags & SEC_READONLY) != 0)
     1902        break;
     1903    }
     1904
     1905  /* If we didn't find any dynamic relocs in read-only sections, then
     1906     we'll be keeping the dynamic relocs and avoiding the copy reloc.  */
     1907  if (p == NULL)
     1908    {
     1909      h->elf_link_hash_flags &= ~ELF_LINK_NON_GOT_REF;
     1910      return TRUE;
     1911    }
    19881912
    19891913  /* We must allocate the symbol in our .dynbss section, which will
     
    19971921     same memory location for the variable.  */
    19981922
    1999   s = hplink->sdynbss;
     1923  htab = hppa_link_hash_table (info);
    20001924
    20011925  /* We must generate a COPY reloc to tell the dynamic linker to
    20021926     copy the initial value out of the dynamic object and into the
    2003      runtime process image.  We need to remember the offset into the
    2004      .rela.bss section we are going to use.  */
     1927     runtime process image.  */
    20051928  if ((h->root.u.def.section->flags & SEC_ALLOC) != 0)
    20061929    {
    2007       asection *srel;
    2008 
    2009       srel = hplink->srelbss;
    2010       srel->_raw_size += sizeof (Elf32_External_Rela);
     1930      htab->srelbss->_raw_size += sizeof (Elf32_External_Rela);
    20111931      h->elf_link_hash_flags |= ELF_LINK_HASH_NEEDS_COPY;
    20121932    }
    20131933
    2014   {
    2015     /* We need to figure out the alignment required for this symbol.  I
    2016        have no idea how other ELF linkers handle this.  */
    2017     unsigned int power_of_two;
    2018 
    2019     power_of_two = bfd_log2 (h->size);
    2020     if (power_of_two > 3)
    2021       power_of_two = 3;
    2022 
    2023     /* Apply the required alignment.  */
    2024     s->_raw_size = BFD_ALIGN (s->_raw_size,
    2025                               (bfd_size_type) (1 << power_of_two));
    2026     if (power_of_two > bfd_get_section_alignment (dynobj, s))
    2027       {
    2028         if (! bfd_set_section_alignment (dynobj, s, power_of_two))
    2029           return false;
    2030       }
    2031   }
     1934  /* We need to figure out the alignment required for this symbol.  I
     1935     have no idea how other ELF linkers handle this.  */
     1936
     1937  power_of_two = bfd_log2 (h->size);
     1938  if (power_of_two > 3)
     1939    power_of_two = 3;
     1940
     1941  /* Apply the required alignment.  */
     1942  s = htab->sdynbss;
     1943  s->_raw_size = BFD_ALIGN (s->_raw_size,
     1944                            (bfd_size_type) (1 << power_of_two));
     1945  if (power_of_two > bfd_get_section_alignment (htab->elf.dynobj, s))
     1946    {
     1947      if (! bfd_set_section_alignment (htab->elf.dynobj, s, power_of_two))
     1948        return FALSE;
     1949    }
     1950
    20321951  /* Define the symbol as being at this point in the section.  */
    20331952  h->root.u.def.section = s;
     
    20371956  s->_raw_size += h->size;
    20381957
    2039   return true;
     1958  return TRUE;
    20401959}
    20411960
     
    20441963   the first part of elf32_hppa_adjust_dynamic_symbol.  */
    20451964
    2046 static boolean
    2047 hppa_handle_PIC_calls (h, inf)
     1965static bfd_boolean
     1966mark_PIC_calls (h, inf)
    20481967     struct elf_link_hash_entry *h;
    20491968     PTR inf ATTRIBUTE_UNUSED;
    20501969{
     1970  if (h->root.type == bfd_link_hash_warning)
     1971    h = (struct elf_link_hash_entry *) h->root.u.i.link;
     1972
    20511973  if (! (h->plt.refcount > 0
    20521974         && (h->root.type == bfd_link_hash_defined
     
    20561978      h->plt.offset = (bfd_vma) -1;
    20571979      h->elf_link_hash_flags &= ~ELF_LINK_HASH_NEEDS_PLT;
    2058       return true;
     1980      return TRUE;
    20591981    }
    20601982
    20611983  h->elf_link_hash_flags |= ELF_LINK_HASH_NEEDS_PLT;
    2062   ((struct elf32_hppa_link_hash_entry *) h)->maybe_pic_call = 1;
    20631984  ((struct elf32_hppa_link_hash_entry *) h)->pic_call = 1;
    20641985
    2065   return true;
     1986  return TRUE;
    20661987}
    20671988
    2068 /* Allocate space in .plt, .got and associated reloc sections for
    2069    global syms.  */
    2070 
    2071 static boolean
    2072 allocate_plt_and_got (h, inf)
     1989/* Allocate space in the .plt for entries that won't have relocations.
     1990   ie. pic_call and plabel entries.  */
     1991
     1992static bfd_boolean
     1993allocate_plt_static (h, inf)
    20731994     struct elf_link_hash_entry *h;
    20741995     PTR inf;
    20751996{
    20761997  struct bfd_link_info *info;
    2077   struct elf32_hppa_link_hash_table *hplink;
     1998  struct elf32_hppa_link_hash_table *htab;
    20781999  asection *s;
    20792000
    2080   if (h->root.type == bfd_link_hash_indirect
    2081       || h->root.type == bfd_link_hash_warning)
    2082     return true;
     2001  if (h->root.type == bfd_link_hash_indirect)
     2002    return TRUE;
     2003
     2004  if (h->root.type == bfd_link_hash_warning)
     2005    h = (struct elf_link_hash_entry *) h->root.u.i.link;
    20832006
    20842007  info = (struct bfd_link_info *) inf;
    2085   hplink = hppa_link_hash_table (info);
    2086   if ((hplink->root.dynamic_sections_created
    2087        && h->plt.refcount > 0)
    2088       || ((struct elf32_hppa_link_hash_entry *) h)->pic_call)
    2089     {
    2090       /* Make an entry in the .plt section.  */
    2091       s = hplink->splt;
     2008  htab = hppa_link_hash_table (info);
     2009  if (((struct elf32_hppa_link_hash_entry *) h)->pic_call)
     2010    {
     2011      /* Make an entry in the .plt section for non-pic code that is
     2012         calling pic code.  */
     2013      ((struct elf32_hppa_link_hash_entry *) h)->plabel = 0;
     2014      s = htab->splt;
    20922015      h->plt.offset = s->_raw_size;
    2093       if (PLABEL_PLT_ENTRY_SIZE != PLT_ENTRY_SIZE
    2094           && ((struct elf32_hppa_link_hash_entry *) h)->plabel
    2095           && (h->elf_link_hash_flags & ELF_LINK_FORCED_LOCAL) == 0)
    2096         {
    2097           /* Add some extra space for the dynamic linker to use.  */
    2098           s->_raw_size += PLABEL_PLT_ENTRY_SIZE;
     2016      s->_raw_size += PLT_ENTRY_SIZE;
     2017    }
     2018  else if (htab->elf.dynamic_sections_created
     2019           && h->plt.refcount > 0)
     2020    {
     2021      /* Make sure this symbol is output as a dynamic symbol.
     2022         Undefined weak syms won't yet be marked as dynamic.  */
     2023      if (h->dynindx == -1
     2024          && (h->elf_link_hash_flags & ELF_LINK_FORCED_LOCAL) == 0
     2025          && h->type != STT_PARISC_MILLI)
     2026        {
     2027          if (! bfd_elf32_link_record_dynamic_symbol (info, h))
     2028            return FALSE;
     2029        }
     2030
     2031      if (WILL_CALL_FINISH_DYNAMIC_SYMBOL (1, info, h))
     2032        {
     2033          /* Allocate these later.  From this point on, h->plabel
     2034             means that the plt entry is only used by a plabel.
     2035             We'll be using a normal plt entry for this symbol, so
     2036             clear the plabel indicator.  */
     2037          ((struct elf32_hppa_link_hash_entry *) h)->plabel = 0;
     2038        }
     2039      else if (((struct elf32_hppa_link_hash_entry *) h)->plabel)
     2040        {
     2041          /* Make an entry in the .plt section for plabel references
     2042             that won't have a .plt entry for other reasons.  */
     2043          s = htab->splt;
     2044          h->plt.offset = s->_raw_size;
     2045          s->_raw_size += PLT_ENTRY_SIZE;
    20992046        }
    21002047      else
    2101         s->_raw_size += PLT_ENTRY_SIZE;
    2102 
    2103       if (! ((struct elf32_hppa_link_hash_entry *) h)->pic_call
    2104           && WILL_CALL_FINISH_DYNAMIC_SYMBOL (1, info, h))
    2105         {
    2106           /* We also need to make an entry in the .rela.plt section.  */
    2107           hplink->srelplt->_raw_size += sizeof (Elf32_External_Rela);
    2108           hplink->need_plt_stub = 1;
     2048        {
     2049          /* No .plt entry needed.  */
     2050          h->plt.offset = (bfd_vma) -1;
     2051          h->elf_link_hash_flags &= ~ELF_LINK_HASH_NEEDS_PLT;
    21092052        }
    21102053    }
     
    21152058    }
    21162059
    2117   if (h->got.refcount > 0)
    2118     {
    2119       boolean dyn;
    2120 
    2121       s = hplink->sgot;
    2122       h->got.offset = s->_raw_size;
    2123       s->_raw_size += GOT_ENTRY_SIZE;
    2124       dyn = hplink->root.dynamic_sections_created;
    2125       if (WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn, info, h))
    2126         hplink->srelgot->_raw_size += sizeof (Elf32_External_Rela);
    2127     }
    2128   else
    2129     h->got.offset = (bfd_vma) -1;
    2130 
    2131   return true;
     2060  return TRUE;
    21322061}
    21332062
    2134 #if ((! LONG_BRANCH_PIC_IN_SHLIB && LONG_BRANCH_VIA_PLT) \
    2135      || RELATIVE_DYNAMIC_RELOCS)
    2136 /* This function is called via elf_link_hash_traverse to discard space
    2137    we allocated for relocs that it turned out we didn't need.  */
    2138 
    2139 static boolean
    2140 hppa_discard_copies (h, inf)
     2063/* Allocate space in .plt, .got and associated reloc sections for
     2064   global syms.  */
     2065
     2066static bfd_boolean
     2067allocate_dynrelocs (h, inf)
    21412068     struct elf_link_hash_entry *h;
    21422069     PTR inf;
    21432070{
    2144   struct elf32_hppa_dyn_reloc_entry *s;
     2071  struct bfd_link_info *info;
     2072  struct elf32_hppa_link_hash_table *htab;
     2073  asection *s;
    21452074  struct elf32_hppa_link_hash_entry *eh;
    2146   struct bfd_link_info *info;
     2075  struct elf32_hppa_dyn_reloc_entry *p;
     2076
     2077  if (h->root.type == bfd_link_hash_indirect)
     2078    return TRUE;
     2079
     2080  if (h->root.type == bfd_link_hash_warning)
     2081    h = (struct elf_link_hash_entry *) h->root.u.i.link;
     2082
     2083  info = (struct bfd_link_info *) inf;
     2084  htab = hppa_link_hash_table (info);
     2085  if (htab->elf.dynamic_sections_created
     2086      && h->plt.offset != (bfd_vma) -1
     2087      && !((struct elf32_hppa_link_hash_entry *) h)->pic_call
     2088      && !((struct elf32_hppa_link_hash_entry *) h)->plabel)
     2089    {
     2090      /* Make an entry in the .plt section.  */
     2091      s = htab->splt;
     2092      h->plt.offset = s->_raw_size;
     2093      s->_raw_size += PLT_ENTRY_SIZE;
     2094
     2095      /* We also need to make an entry in the .rela.plt section.  */
     2096      htab->srelplt->_raw_size += sizeof (Elf32_External_Rela);
     2097      htab->need_plt_stub = 1;
     2098    }
     2099
     2100  if (h->got.refcount > 0)
     2101    {
     2102      /* Make sure this symbol is output as a dynamic symbol.
     2103         Undefined weak syms won't yet be marked as dynamic.  */
     2104      if (h->dynindx == -1
     2105          && (h->elf_link_hash_flags & ELF_LINK_FORCED_LOCAL) == 0
     2106          && h->type != STT_PARISC_MILLI)
     2107        {
     2108          if (! bfd_elf32_link_record_dynamic_symbol (info, h))
     2109            return FALSE;
     2110        }
     2111
     2112      s = htab->sgot;
     2113      h->got.offset = s->_raw_size;
     2114      s->_raw_size += GOT_ENTRY_SIZE;
     2115      if (htab->elf.dynamic_sections_created
     2116          && (info->shared
     2117              || (h->dynindx != -1
     2118                  && h->elf_link_hash_flags & ELF_LINK_FORCED_LOCAL) == 0))
     2119        {
     2120          htab->srelgot->_raw_size += sizeof (Elf32_External_Rela);
     2121        }
     2122    }
     2123  else
     2124    h->got.offset = (bfd_vma) -1;
    21472125
    21482126  eh = (struct elf32_hppa_link_hash_entry *) h;
    2149   info = (struct bfd_link_info *) inf;
    2150 
    2151 #if ! LONG_BRANCH_PIC_IN_SHLIB && LONG_BRANCH_VIA_PLT
    2152   /* Handle the stub reloc case.  If we have a plt entry for the
    2153      function, we won't be needing long branch stubs.  s->count will
    2154      only be zero for stub relocs, which provides a handy way of
    2155      flagging these relocs, and means we need do nothing special for
    2156      the forced local and symbolic link case.  */
    2157   if (eh->stub_reloc_sec != NULL
    2158       && eh->elf.plt.offset != (bfd_vma) -1)
    2159     {
    2160       for (s = eh->reloc_entries; s != NULL; s = s->next)
    2161         if (s->count == 0)
    2162           s->section->_raw_size -= sizeof (Elf32_External_Rela);
    2163     }
     2127  if (eh->dyn_relocs == NULL)
     2128    return TRUE;
     2129
     2130  /* If this is a -Bsymbolic shared link, then we need to discard all
     2131     space allocated for dynamic pc-relative relocs against symbols
     2132     defined in a regular object.  For the normal shared case, discard
     2133     space for relocs that have become local due to symbol visibility
     2134     changes.  */
     2135  if (info->shared)
     2136    {
     2137#if RELATIVE_DYNRELOCS
     2138      if ((h->elf_link_hash_flags & ELF_LINK_HASH_DEF_REGULAR) != 0
     2139          && ((h->elf_link_hash_flags & ELF_LINK_FORCED_LOCAL) != 0
     2140              || info->symbolic))
     2141        {
     2142          struct elf32_hppa_dyn_reloc_entry **pp;
     2143
     2144          for (pp = &eh->dyn_relocs; (p = *pp) != NULL; )
     2145            {
     2146              p->count -= p->relative_count;
     2147              p->relative_count = 0;
     2148              if (p->count == 0)
     2149                *pp = p->next;
     2150              else
     2151                pp = &p->next;
     2152            }
     2153        }
    21642154#endif
    2165 
    2166 #if RELATIVE_DYNAMIC_RELOCS
    2167   /* If a symbol has been forced local or we have found a regular
    2168      definition for the symbolic link case, then we won't be needing
    2169      any relocs.  */
    2170   if (eh->elf.dynindx == -1
    2171       || ((eh->elf.elf_link_hash_flags & ELF_LINK_HASH_DEF_REGULAR) != 0
    2172           && !is_absolute_reloc (r_type)
    2173           && info->symbolic))
    2174     {
    2175       for (s = eh->reloc_entries; s != NULL; s = s->next)
    2176         s->section->_raw_size -= s->count * sizeof (Elf32_External_Rela);
    2177     }
    2178 #endif
    2179 
    2180   return true;
     2155    }
     2156  else
     2157    {
     2158      /* For the non-shared case, discard space for relocs against
     2159         symbols which turn out to need copy relocs or are not
     2160         dynamic.  */
     2161      if ((h->elf_link_hash_flags & ELF_LINK_NON_GOT_REF) == 0
     2162          && (((h->elf_link_hash_flags & ELF_LINK_HASH_DEF_DYNAMIC) != 0
     2163               && (h->elf_link_hash_flags & ELF_LINK_HASH_DEF_REGULAR) == 0)
     2164              || (htab->elf.dynamic_sections_created
     2165                  && (h->root.type == bfd_link_hash_undefweak
     2166                      || h->root.type == bfd_link_hash_undefined))))
     2167        {
     2168          /* Make sure this symbol is output as a dynamic symbol.
     2169             Undefined weak syms won't yet be marked as dynamic.  */
     2170          if (h->dynindx == -1
     2171              && (h->elf_link_hash_flags & ELF_LINK_FORCED_LOCAL) == 0
     2172              && h->type != STT_PARISC_MILLI)
     2173            {
     2174              if (! bfd_elf32_link_record_dynamic_symbol (info, h))
     2175                return FALSE;
     2176            }
     2177
     2178          /* If that succeeded, we know we'll be keeping all the
     2179             relocs.  */
     2180          if (h->dynindx != -1)
     2181            goto keep;
     2182        }
     2183
     2184      eh->dyn_relocs = NULL;
     2185      return TRUE;
     2186
     2187    keep: ;
     2188    }
     2189
     2190  /* Finally, allocate space.  */
     2191  for (p = eh->dyn_relocs; p != NULL; p = p->next)
     2192    {
     2193      asection *sreloc = elf_section_data (p->sec)->sreloc;
     2194      sreloc->_raw_size += p->count * sizeof (Elf32_External_Rela);
     2195    }
     2196
     2197  return TRUE;
    21812198}
    2182 #endif
    21832199
    21842200/* This function is called via elf_link_hash_traverse to force
     
    21892205   elf_adjust_dynamic_symbol.  */
    21902206
    2191 static boolean
     2207static bfd_boolean
    21922208clobber_millicode_symbols (h, info)
    21932209     struct elf_link_hash_entry *h;
    21942210     struct bfd_link_info *info;
    21952211{
    2196   /* We only want to remove these from the dynamic symbol table.
    2197      Therefore we do not leave ELF_LINK_FORCED_LOCAL set.  */
    2198   if (h->type == STT_PARISC_MILLI)
    2199     {
    2200       unsigned short oldflags = h->elf_link_hash_flags;
    2201       h->elf_link_hash_flags |= ELF_LINK_FORCED_LOCAL;
    2202       elf32_hppa_hide_symbol (info, h);
    2203       h->elf_link_hash_flags &= ~ELF_LINK_FORCED_LOCAL;
    2204       h->elf_link_hash_flags |= oldflags & ELF_LINK_FORCED_LOCAL;
    2205     }
    2206   return true;
     2212  if (h->root.type == bfd_link_hash_warning)
     2213    h = (struct elf_link_hash_entry *) h->root.u.i.link;
     2214
     2215  if (h->type == STT_PARISC_MILLI
     2216      && (h->elf_link_hash_flags & ELF_LINK_FORCED_LOCAL) == 0)
     2217    {
     2218      elf32_hppa_hide_symbol (info, h, TRUE);
     2219    }
     2220  return TRUE;
    22072221}
    22082222
     2223/* Find any dynamic relocs that apply to read-only sections.  */
     2224
     2225static bfd_boolean
     2226readonly_dynrelocs (h, inf)
     2227     struct elf_link_hash_entry *h;
     2228     PTR inf;
     2229{
     2230  struct elf32_hppa_link_hash_entry *eh;
     2231  struct elf32_hppa_dyn_reloc_entry *p;
     2232
     2233  if (h->root.type == bfd_link_hash_warning)
     2234    h = (struct elf_link_hash_entry *) h->root.u.i.link;
     2235
     2236  eh = (struct elf32_hppa_link_hash_entry *) h;
     2237  for (p = eh->dyn_relocs; p != NULL; p = p->next)
     2238    {
     2239      asection *s = p->sec->output_section;
     2240
     2241      if (s != NULL && (s->flags & SEC_READONLY) != 0)
     2242        {
     2243          struct bfd_link_info *info = (struct bfd_link_info *) inf;
     2244
     2245          info->flags |= DF_TEXTREL;
     2246
     2247          /* Not an error, just cut short the traversal.  */
     2248          return FALSE;
     2249        }
     2250    }
     2251  return TRUE;
     2252}
     2253
    22092254/* Set the sizes of the dynamic sections.  */
    22102255
    2211 static boolean
     2256static bfd_boolean
    22122257elf32_hppa_size_dynamic_sections (output_bfd, info)
    2213      bfd *output_bfd;
     2258     bfd *output_bfd ATTRIBUTE_UNUSED;
    22142259     struct bfd_link_info *info;
    22152260{
    2216   struct elf32_hppa_link_hash_table *hplink;
     2261  struct elf32_hppa_link_hash_table *htab;
    22172262  bfd *dynobj;
     2263  bfd *ibfd;
    22182264  asection *s;
    2219   boolean relocs;
    2220   boolean reltext;
    2221 
    2222   hplink = hppa_link_hash_table (info);
    2223   dynobj = hplink->root.dynobj;
     2265  bfd_boolean relocs;
     2266
     2267  htab = hppa_link_hash_table (info);
     2268  dynobj = htab->elf.dynobj;
    22242269  if (dynobj == NULL)
    22252270    abort ();
    22262271
    2227   if (hplink->root.dynamic_sections_created)
    2228     {
    2229       bfd *i;
    2230 
     2272  if (htab->elf.dynamic_sections_created)
     2273    {
    22312274      /* Set the contents of the .interp section to the interpreter.  */
    22322275      if (! info->shared)
     
    22402283
    22412284      /* Force millicode symbols local.  */
    2242       elf_link_hash_traverse (&hplink->root,
     2285      elf_link_hash_traverse (&htab->elf,
    22432286                              clobber_millicode_symbols,
    22442287                              info);
    2245 
    2246       /* Set up .got and .plt offsets for local syms.  */
    2247       for (i = info->input_bfds; i; i = i->link_next)
    2248         {
    2249           bfd_signed_vma *local_got;
    2250           bfd_signed_vma *end_local_got;
    2251           bfd_signed_vma *local_plt;
    2252           bfd_signed_vma *end_local_plt;
    2253           bfd_size_type locsymcount;
    2254           Elf_Internal_Shdr *symtab_hdr;
    2255           asection *srel;
    2256 
    2257           if (bfd_get_flavour (i) != bfd_target_elf_flavour)
    2258             continue;
    2259 
    2260           local_got = elf_local_got_refcounts (i);
    2261           if (!local_got)
    2262             continue;
    2263 
    2264           symtab_hdr = &elf_tdata (i)->symtab_hdr;
    2265           locsymcount = symtab_hdr->sh_info;
    2266           end_local_got = local_got + locsymcount;
    2267           s = hplink->sgot;
    2268           srel = hplink->srelgot;
    2269           for (; local_got < end_local_got; ++local_got)
     2288    }
     2289  else
     2290    {
     2291      /* Run through the function symbols, looking for any that are
     2292         PIC, and mark them as needing .plt entries so that %r19 will
     2293         be set up.  */
     2294      if (! info->shared)
     2295        elf_link_hash_traverse (&htab->elf, mark_PIC_calls, (PTR) info);
     2296    }
     2297
     2298  /* Set up .got and .plt offsets for local syms, and space for local
     2299     dynamic relocs.  */
     2300  for (ibfd = info->input_bfds; ibfd != NULL; ibfd = ibfd->link_next)
     2301    {
     2302      bfd_signed_vma *local_got;
     2303      bfd_signed_vma *end_local_got;
     2304      bfd_signed_vma *local_plt;
     2305      bfd_signed_vma *end_local_plt;
     2306      bfd_size_type locsymcount;
     2307      Elf_Internal_Shdr *symtab_hdr;
     2308      asection *srel;
     2309
     2310      if (bfd_get_flavour (ibfd) != bfd_target_elf_flavour)
     2311        continue;
     2312
     2313      for (s = ibfd->sections; s != NULL; s = s->next)
     2314        {
     2315          struct elf32_hppa_dyn_reloc_entry *p;
     2316
     2317          for (p = ((struct elf32_hppa_dyn_reloc_entry *)
     2318                    elf_section_data (s)->local_dynrel);
     2319               p != NULL;
     2320               p = p->next)
    22702321            {
    2271               if (*local_got > 0)
     2322              if (!bfd_is_abs_section (p->sec)
     2323                  && bfd_is_abs_section (p->sec->output_section))
    22722324                {
    2273                   *local_got = s->_raw_size;
    2274                   s->_raw_size += GOT_ENTRY_SIZE;
    2275                   if (info->shared)
    2276                     srel->_raw_size += sizeof (Elf32_External_Rela);
     2325                  /* Input section has been discarded, either because
     2326                     it is a copy of a linkonce section or due to
     2327                     linker script /DISCARD/, so we'll be discarding
     2328                     the relocs too.  */
    22772329                }
    2278               else
    2279                 *local_got = (bfd_vma) -1;
     2330              else if (p->count != 0)
     2331                {
     2332                  srel = elf_section_data (p->sec)->sreloc;
     2333                  srel->_raw_size += p->count * sizeof (Elf32_External_Rela);
     2334                  if ((p->sec->output_section->flags & SEC_READONLY) != 0)
     2335                    info->flags |= DF_TEXTREL;
     2336                }
    22802337            }
    2281 
    2282           local_plt = end_local_got;
    2283           end_local_plt = local_plt + locsymcount;
    2284           s = hplink->splt;
    2285           srel = hplink->srelplt;
     2338        }
     2339
     2340      local_got = elf_local_got_refcounts (ibfd);
     2341      if (!local_got)
     2342        continue;
     2343
     2344      symtab_hdr = &elf_tdata (ibfd)->symtab_hdr;
     2345      locsymcount = symtab_hdr->sh_info;
     2346      end_local_got = local_got + locsymcount;
     2347      s = htab->sgot;
     2348      srel = htab->srelgot;
     2349      for (; local_got < end_local_got; ++local_got)
     2350        {
     2351          if (*local_got > 0)
     2352            {
     2353              *local_got = s->_raw_size;
     2354              s->_raw_size += GOT_ENTRY_SIZE;
     2355              if (info->shared)
     2356                srel->_raw_size += sizeof (Elf32_External_Rela);
     2357            }
     2358          else
     2359            *local_got = (bfd_vma) -1;
     2360        }
     2361
     2362      local_plt = end_local_got;
     2363      end_local_plt = local_plt + locsymcount;
     2364      if (! htab->elf.dynamic_sections_created)
     2365        {
     2366          /* Won't be used, but be safe.  */
     2367          for (; local_plt < end_local_plt; ++local_plt)
     2368            *local_plt = (bfd_vma) -1;
     2369        }
     2370      else
     2371        {
     2372          s = htab->splt;
     2373          srel = htab->srelplt;
    22862374          for (; local_plt < end_local_plt; ++local_plt)
    22872375            {
     
    22982386        }
    22992387    }
    2300   else
    2301     {
    2302       /* Run through the function symbols, looking for any that are
    2303          PIC, and allocate space for the necessary .plt entries so
    2304          that %r19 will be set up.  */
    2305       if (! info->shared)
    2306         elf_link_hash_traverse (&hplink->root,
    2307                                 hppa_handle_PIC_calls,
    2308                                 info);
    2309     }
    2310 
    2311   /* Allocate global sym .plt and .got entries.  */
    2312   elf_link_hash_traverse (&hplink->root,
    2313                           allocate_plt_and_got,
    2314                           info);
    2315 
    2316 #if ((! LONG_BRANCH_PIC_IN_SHLIB && LONG_BRANCH_VIA_PLT) \
    2317      || RELATIVE_DYNAMIC_RELOCS)
    2318   /* If this is a -Bsymbolic shared link, then we need to discard all
    2319      relocs against symbols defined in a regular object.  We also need
    2320      to lose relocs we've allocated for long branch stubs if we know
    2321      we won't be generating a stub.  */
    2322   if (info->shared)
    2323     elf_link_hash_traverse (&hplink->root,
    2324                             hppa_discard_copies,
    2325                             info);
    2326 #endif
     2388
     2389  /* Do all the .plt entries without relocs first.  The dynamic linker
     2390     uses the last .plt reloc to find the end of the .plt (and hence
     2391     the start of the .got) for lazy linking.  */
     2392  elf_link_hash_traverse (&htab->elf, allocate_plt_static, (PTR) info);
     2393
     2394  /* Allocate global sym .plt and .got entries, and space for global
     2395     sym dynamic relocs.  */
     2396  elf_link_hash_traverse (&htab->elf, allocate_dynrelocs, (PTR) info);
    23272397
    23282398  /* The check_relocs and adjust_dynamic_symbol entry points have
    23292399     determined the sizes of the various dynamic sections.  Allocate
    23302400     memory for them.  */
    2331   relocs = false;
    2332   reltext = false;
     2401  relocs = FALSE;
    23332402  for (s = dynobj->sections; s != NULL; s = s->next)
    23342403    {
    2335       const char *name;
    2336 
    23372404      if ((s->flags & SEC_LINKER_CREATED) == 0)
    23382405        continue;
    23392406
    2340       /* It's OK to base decisions on the section name, because none
    2341          of the dynobj section names depend upon the input files.  */
    2342       name = bfd_get_section_name (dynobj, s);
    2343 
    2344       if (strncmp (name, ".rela", 5) == 0)
    2345         {
    2346           if (s->_raw_size != 0)
    2347             {
    2348               asection *target;
    2349               const char *outname;
    2350 
    2351               /* Remember whether there are any reloc sections other
    2352                  than .rela.plt.  */
    2353               if (strcmp (name+5, ".plt") != 0)
    2354                 relocs = true;
    2355 
    2356               /* If this relocation section applies to a read only
    2357                  section, then we probably need a DT_TEXTREL entry.  */
    2358               outname = bfd_get_section_name (output_bfd,
    2359                                               s->output_section);
    2360               target = bfd_get_section_by_name (output_bfd, outname + 5);
    2361               if (target != NULL
    2362                   && (target->flags & SEC_READONLY) != 0
    2363                   && (target->flags & SEC_ALLOC) != 0)
    2364                 reltext = true;
    2365 
    2366               /* We use the reloc_count field as a counter if we need
    2367                  to copy relocs into the output file.  */
    2368               s->reloc_count = 0;
    2369             }
    2370         }
    2371       else if (strcmp (name, ".plt") == 0)
    2372         {
    2373           if (hplink->need_plt_stub)
     2407      if (s == htab->splt)
     2408        {
     2409          if (htab->need_plt_stub)
    23742410            {
    23752411              /* Make space for the plt stub at the end of the .plt
    23762412                 section.  We want this stub right at the end, up
    23772413                 against the .got section.  */
    2378               int gotalign = bfd_section_alignment (dynobj, hplink->sgot);
     2414              int gotalign = bfd_section_alignment (dynobj, htab->sgot);
    23792415              int pltalign = bfd_section_alignment (dynobj, s);
    23802416              bfd_size_type mask;
     
    23862422            }
    23872423        }
    2388       else if (strcmp (name, ".got") == 0)
     2424      else if (s == htab->sgot)
    23892425        ;
     2426      else if (strncmp (bfd_get_section_name (dynobj, s), ".rela", 5) == 0)
     2427        {
     2428          if (s->_raw_size != 0)
     2429            {
     2430              /* Remember whether there are any reloc sections other
     2431                 than .rela.plt.  */
     2432              if (s != htab->srelplt)
     2433                relocs = TRUE;
     2434
     2435              /* We use the reloc_count field as a counter if we need
     2436                 to copy relocs into the output file.  */
     2437              s->reloc_count = 0;
     2438            }
     2439        }
    23902440      else
    23912441        {
     
    24132463      s->contents = (bfd_byte *) bfd_zalloc (dynobj, s->_raw_size);
    24142464      if (s->contents == NULL && s->_raw_size != 0)
    2415         return false;
    2416     }
    2417 
    2418   if (hplink->root.dynamic_sections_created)
     2465        return FALSE;
     2466    }
     2467
     2468  if (htab->elf.dynamic_sections_created)
    24192469    {
    24202470      /* Like IA-64 and HPPA64, always create a DT_PLTGOT.  It
     
    24222472         communicate the LTP value of a load module to the dynamic
    24232473         linker.  */
    2424       if (! bfd_elf32_add_dynamic_entry (info, DT_PLTGOT, 0))
    2425         return false;
     2474#define add_dynamic_entry(TAG, VAL) \
     2475  bfd_elf32_add_dynamic_entry (info, (bfd_vma) (TAG), (bfd_vma) (VAL))
     2476
     2477      if (!add_dynamic_entry (DT_PLTGOT, 0))
     2478        return FALSE;
    24262479
    24272480      /* Add some entries to the .dynamic section.  We fill in the
     
    24302483         the .dynamic section.  The DT_DEBUG entry is filled in by the
    24312484         dynamic linker and used by the debugger.  */
    2432       if (! info->shared)
    2433         {
    2434           if (! bfd_elf32_add_dynamic_entry (info, DT_DEBUG, 0))
    2435             return false;
    2436         }
    2437 
    2438       if (hplink->srelplt->_raw_size != 0)
    2439         {
    2440           if (! bfd_elf32_add_dynamic_entry (info, DT_PLTRELSZ, 0)
    2441               || ! bfd_elf32_add_dynamic_entry (info, DT_PLTREL, DT_RELA)
    2442               || ! bfd_elf32_add_dynamic_entry (info, DT_JMPREL, 0))
    2443             return false;
     2485      if (!info->shared)
     2486        {
     2487          if (!add_dynamic_entry (DT_DEBUG, 0))
     2488            return FALSE;
     2489        }
     2490
     2491      if (htab->srelplt->_raw_size != 0)
     2492        {
     2493          if (!add_dynamic_entry (DT_PLTRELSZ, 0)
     2494              || !add_dynamic_entry (DT_PLTREL, DT_RELA)
     2495              || !add_dynamic_entry (DT_JMPREL, 0))
     2496            return FALSE;
    24442497        }
    24452498
    24462499      if (relocs)
    24472500        {
    2448           if (! bfd_elf32_add_dynamic_entry (info, DT_RELA, 0)
    2449               || ! bfd_elf32_add_dynamic_entry (info, DT_RELASZ, 0)
    2450               || ! bfd_elf32_add_dynamic_entry (info, DT_RELAENT,
    2451                                                 sizeof (Elf32_External_Rela)))
    2452             return false;
    2453         }
    2454 
    2455       if (reltext)
    2456         {
    2457           if (! bfd_elf32_add_dynamic_entry (info, DT_TEXTREL, 0))
    2458             return false;
    2459           info->flags |= DF_TEXTREL;
    2460         }
    2461     }
    2462 
    2463   return true;
     2501          if (!add_dynamic_entry (DT_RELA, 0)
     2502              || !add_dynamic_entry (DT_RELASZ, 0)
     2503              || !add_dynamic_entry (DT_RELAENT, sizeof (Elf32_External_Rela)))
     2504            return FALSE;
     2505
     2506          /* If any dynamic relocs apply to a read-only section,
     2507             then we need a DT_TEXTREL entry.  */
     2508          if ((info->flags & DF_TEXTREL) == 0)
     2509            elf_link_hash_traverse (&htab->elf, readonly_dynrelocs,
     2510                                    (PTR) info);
     2511
     2512          if ((info->flags & DF_TEXTREL) != 0)
     2513            {
     2514              if (!add_dynamic_entry (DT_TEXTREL, 0))
     2515                return FALSE;
     2516            }
     2517        }
     2518    }
     2519#undef add_dynamic_entry
     2520
     2521  return TRUE;
    24642522}
    24652523
    24662524/* External entry points for sizing and building linker stubs.  */
    24672525
    2468 /* Determine and set the size of the stub section for a final link.
    2469 
    2470    The basic idea here is to examine all the relocations looking for
    2471    PC-relative calls to a target that is unreachable with a "bl"
    2472    instruction.  */
    2473 
    2474 boolean
    2475 elf32_hppa_size_stubs (output_bfd, stub_bfd, info, multi_subspace, group_size,
    2476                        add_stub_section, layout_sections_again)
     2526/* Set up various things so that we can make a list of input sections
     2527   for each output section included in the link.  Returns -1 on error,
     2528   0 when no stubs will be needed, and 1 on success.  */
     2529
     2530int
     2531elf32_hppa_setup_section_lists (output_bfd, info)
    24772532     bfd *output_bfd;
    2478      bfd *stub_bfd;
    24792533     struct bfd_link_info *info;
    2480      boolean multi_subspace;
    2481      bfd_signed_vma group_size;
    2482      asection * (*add_stub_section) PARAMS ((const char *, asection *));
    2483      void (*layout_sections_again) PARAMS ((void));
    24842534{
    24852535  bfd *input_bfd;
     2536  unsigned int bfd_count;
     2537  int top_id, top_index;
    24862538  asection *section;
    24872539  asection **input_list, **list;
    2488   Elf_Internal_Sym *local_syms, **all_local_syms;
    2489   unsigned int bfd_indx, bfd_count;
    2490   int top_id, top_index;
    2491   struct elf32_hppa_link_hash_table *hplink;
    2492   bfd_size_type stub_group_size;
    2493   boolean stubs_always_before_branch;
    2494   boolean stub_changed = 0;
    2495   boolean ret = 0;
    2496 
    2497   hplink = hppa_link_hash_table (info);
    2498 
    2499   /* Stash our params away.  */
    2500   hplink->stub_bfd = stub_bfd;
    2501   hplink->multi_subspace = multi_subspace;
    2502   hplink->add_stub_section = add_stub_section;
    2503   hplink->layout_sections_again = layout_sections_again;
    2504   stubs_always_before_branch = group_size < 0;
    2505   if (group_size < 0)
    2506     stub_group_size = -group_size;
    2507   else
    2508     stub_group_size = group_size;
    2509   if (stub_group_size == 1)
    2510     {
    2511       /* Default values.  */
    2512       stub_group_size = 8000000;
    2513       if (hplink->has_17bit_branch || hplink->multi_subspace)
    2514         stub_group_size = 250000;
    2515       if (hplink->has_12bit_branch)
    2516         stub_group_size = 7812;
    2517     }
     2540  bfd_size_type amt;
     2541  struct elf32_hppa_link_hash_table *htab = hppa_link_hash_table (info);
     2542
     2543  if (htab->elf.root.creator->flavour != bfd_target_elf_flavour)
     2544    return 0;
    25182545
    25192546  /* Count the number of input BFDs and find the top input section id.  */
     
    25312558        }
    25322559    }
    2533 
    2534   hplink->stub_group
    2535     = (struct map_stub *) bfd_zmalloc (sizeof (struct map_stub) * (top_id + 1));
    2536   if (hplink->stub_group == NULL)
    2537     return false;
    2538 
    2539   /* Make a list of input sections for each output section included in
    2540      the link.
    2541 
    2542      We can't use output_bfd->section_count here to find the top output
     2560  htab->bfd_count = bfd_count;
     2561
     2562  amt = sizeof (struct map_stub) * (top_id + 1);
     2563  htab->stub_group = (struct map_stub *) bfd_zmalloc (amt);
     2564  if (htab->stub_group == NULL)
     2565    return -1;
     2566
     2567  /* We can't use output_bfd->section_count here to find the top output
    25432568     section index as some sections may have been removed, and
    25442569     _bfd_strip_section_from_output doesn't renumber the indices.  */
     
    25512576    }
    25522577
    2553   input_list
    2554     = (asection **) bfd_malloc (sizeof (asection *) * (top_index + 1));
     2578  htab->top_index = top_index;
     2579  amt = sizeof (asection *) * (top_index + 1);
     2580  input_list = (asection **) bfd_malloc (amt);
     2581  htab->input_list = input_list;
    25552582  if (input_list == NULL)
    2556     return false;
     2583    return -1;
    25572584
    25582585  /* For sections we aren't interested in, mark their entries with a
     
    25712598    }
    25722599
    2573   /* Now actually build the lists.  */
    2574   for (input_bfd = info->input_bfds;
    2575        input_bfd != NULL;
    2576        input_bfd = input_bfd->link_next)
    2577     {
    2578       for (section = input_bfd->sections;
    2579            section != NULL;
    2580            section = section->next)
    2581         {
    2582           if (section->output_section != NULL
    2583               && section->output_section->owner == output_bfd
    2584               && section->output_section->index <= top_index)
    2585             {
    2586               list = input_list + section->output_section->index;
    2587               if (*list != bfd_abs_section_ptr)
    2588                 {
    2589                   /* Steal the link_sec pointer for our list.  */
    2590 #define PREV_SEC(sec) (hplink->stub_group[(sec)->id].link_sec)
    2591                   /* This happens to make the list in reverse order,
    2592                      which is what we want.  */
    2593                   PREV_SEC (section) = *list;
    2594                   *list = section;
    2595                 }
    2596             }
    2597         }
    2598     }
    2599 
    2600   /* See whether we can group stub sections together.  Grouping stub
    2601      sections may result in fewer stubs.  More importantly, we need to
    2602      put all .init* and .fini* stubs at the beginning of the .init or
    2603      .fini output sections respectively, because glibc splits the
    2604      _init and _fini functions into multiple parts.  Putting a stub in
    2605      the middle of a function is not a good idea.  */
    2606   list = input_list + top_index;
     2600  return 1;
     2601}
     2602
     2603/* The linker repeatedly calls this function for each input section,
     2604   in the order that input sections are linked into output sections.
     2605   Build lists of input sections to determine groupings between which
     2606   we may insert linker stubs.  */
     2607
     2608void
     2609elf32_hppa_next_input_section (info, isec)
     2610     struct bfd_link_info *info;
     2611     asection *isec;
     2612{
     2613  struct elf32_hppa_link_hash_table *htab = hppa_link_hash_table (info);
     2614
     2615  if (isec->output_section->index <= htab->top_index)
     2616    {
     2617      asection **list = htab->input_list + isec->output_section->index;
     2618      if (*list != bfd_abs_section_ptr)
     2619        {
     2620          /* Steal the link_sec pointer for our list.  */
     2621#define PREV_SEC(sec) (htab->stub_group[(sec)->id].link_sec)
     2622          /* This happens to make the list in reverse order,
     2623             which is what we want.  */
     2624          PREV_SEC (isec) = *list;
     2625          *list = isec;
     2626        }
     2627    }
     2628}
     2629
     2630/* See whether we can group stub sections together.  Grouping stub
     2631   sections may result in fewer stubs.  More importantly, we need to
     2632   put all .init* and .fini* stubs at the beginning of the .init or
     2633   .fini output sections respectively, because glibc splits the
     2634   _init and _fini functions into multiple parts.  Putting a stub in
     2635   the middle of a function is not a good idea.  */
     2636
     2637static void
     2638group_sections (htab, stub_group_size, stubs_always_before_branch)
     2639     struct elf32_hppa_link_hash_table *htab;
     2640     bfd_size_type stub_group_size;
     2641     bfd_boolean stubs_always_before_branch;
     2642{
     2643  asection **list = htab->input_list + htab->top_index;
    26072644  do
    26082645    {
     
    26152652          asection *prev;
    26162653          bfd_size_type total;
     2654          bfd_boolean big_sec;
    26172655
    26182656          curr = tail;
     
    26212659          else
    26222660            total = tail->_raw_size;
     2661          big_sec = total >= stub_group_size;
     2662
    26232663          while ((prev = PREV_SEC (curr)) != NULL
    26242664                 && ((total += curr->output_offset - prev->output_offset)
     
    26272667
    26282668          /* OK, the size from the start of CURR to the end is less
    2629              than 250000 bytes and thus can be handled by one stub
     2669             than 240000 bytes and thus can be handled by one stub
    26302670             section.  (or the tail section is itself larger than
    2631              250000 bytes, in which case we may be toast.)
     2671             240000 bytes, in which case we may be toast.)
    26322672             We should really be keeping track of the total size of
    26332673             stubs added here, as stubs contribute to the final output
    26342674             section size.  That's a little tricky, and this way will
    2635              only break if stubs added total more than 12144 bytes, or
    2636              1518 long branch stubs.  It seems unlikely for more than
    2637              1518 different functions to be called, especially from
    2638              code only 250000 bytes long.  */
     2675             only break if stubs added total more than 22144 bytes, or
     2676             2768 long branch stubs.  It seems unlikely for more than
     2677             2768 different functions to be called, especially from
     2678             code only 240000 bytes long.  This limit used to be
     2679             250000, but c++ code tends to generate lots of little
     2680             functions, and sometimes violated the assumption.  */
    26392681          do
    26402682            {
    26412683              prev = PREV_SEC (tail);
    26422684              /* Set up this stub group.  */
    2643               hplink->stub_group[tail->id].link_sec = curr;
     2685              htab->stub_group[tail->id].link_sec = curr;
    26442686            }
    26452687          while (tail != curr && (tail = prev) != NULL);
    26462688
    2647           /* But wait, there's more!  Input sections up to 250000
    2648              bytes before the stub section can be handled by it too.  */
    2649           if (!stubs_always_before_branch)
     2689          /* But wait, there's more!  Input sections up to 240000
     2690             bytes before the stub section can be handled by it too.
     2691             Don't do this if we have a really large section after the
     2692             stubs, as adding more stubs increases the chance that
     2693             branches may not reach into the stub section.  */
     2694          if (!stubs_always_before_branch && !big_sec)
    26502695            {
    26512696              total = 0;
     
    26562701                  tail = prev;
    26572702                  prev = PREV_SEC (tail);
    2658                   hplink->stub_group[tail->id].link_sec = curr;
     2703                  htab->stub_group[tail->id].link_sec = curr;
    26592704                }
    26602705            }
     
    26622707        }
    26632708    }
    2664   while (list-- != input_list);
    2665   free (input_list);
     2709  while (list-- != htab->input_list);
     2710  free (htab->input_list);
    26662711#undef PREV_SEC
     2712}
     2713
     2714/* Read in all local syms for all input bfds, and create hash entries
     2715   for export stubs if we are building a multi-subspace shared lib.
     2716   Returns -1 on error, 1 if export stubs created, 0 otherwise.  */
     2717
     2718static int
     2719get_local_syms (output_bfd, input_bfd, info)
     2720     bfd *output_bfd;
     2721     bfd *input_bfd;
     2722     struct bfd_link_info *info;
     2723{
     2724  unsigned int bfd_indx;
     2725  Elf_Internal_Sym *local_syms, **all_local_syms;
     2726  int stub_changed = 0;
     2727  struct elf32_hppa_link_hash_table *htab = hppa_link_hash_table (info);
    26672728
    26682729  /* We want to read in symbol extension records only once.  To do this
    26692730     we need to read in the local symbols in parallel and save them for
    26702731     later use; so hold pointers to the local symbols in an array.  */
    2671   all_local_syms
    2672     = (Elf_Internal_Sym **) bfd_zmalloc (sizeof (Elf_Internal_Sym *)
    2673                                          * bfd_count);
     2732  bfd_size_type amt = sizeof (Elf_Internal_Sym *) * htab->bfd_count;
     2733  all_local_syms = (Elf_Internal_Sym **) bfd_zmalloc (amt);
     2734  htab->all_local_syms = all_local_syms;
    26742735  if (all_local_syms == NULL)
    2675     return false;
     2736    return -1;
    26762737
    26772738  /* Walk over all the input BFDs, swapping in local symbols.
    26782739     If we are creating a shared library, create hash entries for the
    26792740     export stubs.  */
    2680   for (input_bfd = info->input_bfds, bfd_indx = 0;
     2741  for (bfd_indx = 0;
    26812742       input_bfd != NULL;
    26822743       input_bfd = input_bfd->link_next, bfd_indx++)
    26832744    {
    26842745      Elf_Internal_Shdr *symtab_hdr;
    2685       Elf_Internal_Sym *isym;
    2686       Elf32_External_Sym *ext_syms, *esym, *end_sy;
    26872746
    26882747      /* We'll need the symbol table in a second.  */
     
    26912750        continue;
    26922751
    2693       /* We need an array of the local symbols attached to the input bfd.
    2694          Unfortunately, we're going to have to read & swap them in.  */
    2695       local_syms = (Elf_Internal_Sym *)
    2696         bfd_malloc (symtab_hdr->sh_info * sizeof (Elf_Internal_Sym));
     2752      /* We need an array of the local symbols attached to the input bfd.  */
     2753      local_syms = (Elf_Internal_Sym *) symtab_hdr->contents;
    26972754      if (local_syms == NULL)
    26982755        {
    2699           goto error_ret_free_local;
    2700         }
     2756          local_syms = bfd_elf_get_elf_syms (input_bfd, symtab_hdr,
     2757                                             symtab_hdr->sh_info, 0,
     2758                                             NULL, NULL, NULL);
     2759          /* Cache them for elf_link_input_bfd.  */
     2760          symtab_hdr->contents = (unsigned char *) local_syms;
     2761        }
     2762      if (local_syms == NULL)
     2763        return -1;
     2764
    27012765      all_local_syms[bfd_indx] = local_syms;
    2702       ext_syms = (Elf32_External_Sym *)
    2703         bfd_malloc (symtab_hdr->sh_info * sizeof (Elf32_External_Sym));
    2704       if (ext_syms == NULL)
    2705         {
    2706           goto error_ret_free_local;
    2707         }
    2708 
    2709       if (bfd_seek (input_bfd, symtab_hdr->sh_offset, SEEK_SET) != 0
    2710           || (bfd_read (ext_syms, 1,
    2711                         (symtab_hdr->sh_info * sizeof (Elf32_External_Sym)),
    2712                         input_bfd)
    2713               != (symtab_hdr->sh_info * sizeof (Elf32_External_Sym))))
    2714         {
    2715           free (ext_syms);
    2716           goto error_ret_free_local;
    2717         }
    2718 
    2719       /* Swap the local symbols in.  */
    2720       isym = local_syms;
    2721       esym = ext_syms;
    2722       for (end_sy = esym + symtab_hdr->sh_info; esym < end_sy; esym++, isym++)
    2723         bfd_elf32_swap_symbol_in (input_bfd, esym, isym);
    2724 
    2725       /* Now we can free the external symbols.  */
    2726       free (ext_syms);
    2727 
    2728 #if ! LONG_BRANCH_PIC_IN_SHLIB
    2729       /* If this is a shared link, find all the stub reloc sections.  */
    2730       if (info->shared)
    2731         for (section = input_bfd->sections;
    2732              section != NULL;
    2733              section = section->next)
    2734           {
    2735             char *name;
    2736             asection *reloc_sec;
    2737 
    2738             name = bfd_malloc (strlen (section->name)
    2739                                + sizeof STUB_SUFFIX
    2740                                + 5);
    2741             if (name == NULL)
    2742               return false;
    2743             sprintf (name, ".rela%s%s", section->name, STUB_SUFFIX);
    2744             reloc_sec = bfd_get_section_by_name (hplink->root.dynobj, name);
    2745             hplink->stub_group[section->id].reloc_sec = reloc_sec;
    2746             free (name);
    2747           }
    2748 #endif
    2749 
    2750       if (info->shared && hplink->multi_subspace)
     2766
     2767      if (info->shared && htab->multi_subspace)
    27512768        {
    27522769          struct elf_link_hash_entry **sym_hashes;
     
    27922809                  sec = hash->elf.root.u.def.section;
    27932810                  stub_name = hash->elf.root.root.string;
    2794                   stub_entry = hppa_stub_hash_lookup (&hplink->stub_hash_table,
     2811                  stub_entry = hppa_stub_hash_lookup (&htab->stub_hash_table,
    27952812                                                      stub_name,
    2796                                                       false, false);
     2813                                                      FALSE, FALSE);
    27972814                  if (stub_entry == NULL)
    27982815                    {
    2799                       stub_entry = hppa_add_stub (stub_name, sec, hplink);
     2816                      stub_entry = hppa_add_stub (stub_name, sec, htab);
    28002817                      if (!stub_entry)
    2801                         goto error_ret_free_local;
     2818                        return -1;
    28022819
    28032820                      stub_entry->target_value = hash->elf.root.u.def.value;
     
    28102827                    {
    28112828                      (*_bfd_error_handler) (_("%s: duplicate export stub %s"),
    2812                              bfd_get_filename (input_bfd),
    2813                              stub_name);
     2829                                             bfd_archive_filename (input_bfd),
     2830                                             stub_name);
    28142831                    }
    28152832                }
     
    28182835    }
    28192836
     2837  return stub_changed;
     2838}
     2839
     2840/* Determine and set the size of the stub section for a final link.
     2841
     2842   The basic idea here is to examine all the relocations looking for
     2843   PC-relative calls to a target that is unreachable with a "bl"
     2844   instruction.  */
     2845
     2846bfd_boolean
     2847elf32_hppa_size_stubs (output_bfd, stub_bfd, info, multi_subspace, group_size,
     2848                       add_stub_section, layout_sections_again)
     2849     bfd *output_bfd;
     2850     bfd *stub_bfd;
     2851     struct bfd_link_info *info;
     2852     bfd_boolean multi_subspace;
     2853     bfd_signed_vma group_size;
     2854     asection * (*add_stub_section) PARAMS ((const char *, asection *));
     2855     void (*layout_sections_again) PARAMS ((void));
     2856{
     2857  bfd_size_type stub_group_size;
     2858  bfd_boolean stubs_always_before_branch;
     2859  bfd_boolean stub_changed;
     2860  struct elf32_hppa_link_hash_table *htab = hppa_link_hash_table (info);
     2861
     2862  /* Stash our params away.  */
     2863  htab->stub_bfd = stub_bfd;
     2864  htab->multi_subspace = multi_subspace;
     2865  htab->add_stub_section = add_stub_section;
     2866  htab->layout_sections_again = layout_sections_again;
     2867  stubs_always_before_branch = group_size < 0;
     2868  if (group_size < 0)
     2869    stub_group_size = -group_size;
     2870  else
     2871    stub_group_size = group_size;
     2872  if (stub_group_size == 1)
     2873    {
     2874      /* Default values.  */
     2875      if (stubs_always_before_branch)
     2876        {
     2877          stub_group_size = 7680000;
     2878          if (htab->has_17bit_branch || htab->multi_subspace)
     2879            stub_group_size = 240000;
     2880          if (htab->has_12bit_branch)
     2881            stub_group_size = 7500;
     2882        }
     2883      else
     2884        {
     2885          stub_group_size = 6971392;
     2886          if (htab->has_17bit_branch || htab->multi_subspace)
     2887            stub_group_size = 217856;
     2888          if (htab->has_12bit_branch)
     2889            stub_group_size = 6808;
     2890        }
     2891    }
     2892
     2893  group_sections (htab, stub_group_size, stubs_always_before_branch);
     2894
     2895  switch (get_local_syms (output_bfd, info->input_bfds, info))
     2896    {
     2897    default:
     2898      if (htab->all_local_syms)
     2899        goto error_ret_free_local;
     2900      return FALSE;
     2901
     2902    case 0:
     2903      stub_changed = FALSE;
     2904      break;
     2905
     2906    case 1:
     2907      stub_changed = TRUE;
     2908      break;
     2909    }
     2910
    28202911  while (1)
    28212912    {
     2913      bfd *input_bfd;
     2914      unsigned int bfd_indx;
    28222915      asection *stub_sec;
    28232916
     
    28272920        {
    28282921          Elf_Internal_Shdr *symtab_hdr;
     2922          asection *section;
     2923          Elf_Internal_Sym *local_syms;
    28292924
    28302925          /* We'll need the symbol table in a second.  */
     
    28332928            continue;
    28342929
    2835           local_syms = all_local_syms[bfd_indx];
     2930          local_syms = htab->all_local_syms[bfd_indx];
    28362931
    28372932          /* Walk over each section attached to the input bfd.  */
     
    28402935               section = section->next)
    28412936            {
    2842               Elf_Internal_Shdr *input_rel_hdr;
    2843               Elf32_External_Rela *external_relocs, *erelaend, *erela;
    28442937              Elf_Internal_Rela *internal_relocs, *irelaend, *irela;
    28452938
     
    28562949                continue;
    28572950
    2858               /* Allocate space for the external relocations.  */
    2859               external_relocs
    2860                 = ((Elf32_External_Rela *)
    2861                    bfd_malloc (section->reloc_count
    2862                                * sizeof (Elf32_External_Rela)));
    2863               if (external_relocs == NULL)
    2864                 {
    2865                   goto error_ret_free_local;
    2866                 }
    2867 
    2868               /* Likewise for the internal relocations.  */
    2869               internal_relocs = ((Elf_Internal_Rela *)
    2870                                  bfd_malloc (section->reloc_count
    2871                                              * sizeof (Elf_Internal_Rela)));
     2951              /* Get the relocs.  */
     2952              internal_relocs
     2953                = _bfd_elf32_link_read_relocs (input_bfd, section, NULL,
     2954                                               (Elf_Internal_Rela *) NULL,
     2955                                               info->keep_memory);
    28722956              if (internal_relocs == NULL)
    2873                 {
    2874                   free (external_relocs);
    2875                   goto error_ret_free_local;
    2876                 }
    2877 
    2878               /* Read in the external relocs.  */
    2879               input_rel_hdr = &elf_section_data (section)->rel_hdr;
    2880               if (bfd_seek (input_bfd, input_rel_hdr->sh_offset, SEEK_SET) != 0
    2881                   || bfd_read (external_relocs, 1,
    2882                                input_rel_hdr->sh_size,
    2883                                input_bfd) != input_rel_hdr->sh_size)
    2884                 {
    2885                   free (external_relocs);
    2886                 error_ret_free_internal:
    2887                   free (internal_relocs);
    2888                   goto error_ret_free_local;
    2889                 }
    2890 
    2891               /* Swap in the relocs.  */
    2892               erela = external_relocs;
    2893               erelaend = erela + section->reloc_count;
    2894               irela = internal_relocs;
    2895               for (; erela < erelaend; erela++, irela++)
    2896                 bfd_elf32_swap_reloca_in (input_bfd, erela, irela);
    2897 
    2898               /* We're done with the external relocs, free them.  */
    2899               free (external_relocs);
     2957                goto error_ret_free_local;
    29002958
    29012959              /* Now examine each relocation.  */
     
    29202978                    {
    29212979                      bfd_set_error (bfd_error_bad_value);
    2922                       goto error_ret_free_internal;
     2980                    error_ret_free_internal:
     2981                      if (elf_section_data (section)->relocs == NULL)
     2982                        free (internal_relocs);
     2983                      goto error_ret_free_local;
    29232984                    }
    29242985
     
    29843045                                 && !info->no_undefined
    29853046                                 && (ELF_ST_VISIBILITY (hash->elf.other)
    2986                                      == STV_DEFAULT)))
     3047                                     == STV_DEFAULT)
     3048                                 && hash->elf.type != STT_PARISC_MILLI))
    29873049                            continue;
    29883050                        }
     
    30013063
    30023064                  /* Support for grouping stub sections.  */
    3003                   id_sec = hplink->stub_group[section->id].link_sec;
     3065                  id_sec = htab->stub_group[section->id].link_sec;
    30043066
    30053067                  /* Get the name of this stub.  */
     
    30083070                    goto error_ret_free_internal;
    30093071
    3010                   stub_entry = hppa_stub_hash_lookup (&hplink->stub_hash_table,
     3072                  stub_entry = hppa_stub_hash_lookup (&htab->stub_hash_table,
    30113073                                                      stub_name,
    3012                                                       false, false);
     3074                                                      FALSE, FALSE);
    30133075                  if (stub_entry != NULL)
    30143076                    {
     
    30183080                    }
    30193081
    3020                   stub_entry = hppa_add_stub (stub_name, section, hplink);
     3082                  stub_entry = hppa_add_stub (stub_name, section, htab);
    30213083                  if (stub_entry == NULL)
    30223084                    {
    30233085                      free (stub_name);
    3024                       goto error_ret_free_local;
     3086                      goto error_ret_free_internal;
    30253087                    }
    30263088
     
    30323094                      if (stub_type == hppa_stub_import)
    30333095                        stub_entry->stub_type = hppa_stub_import_shared;
    3034                       else if (stub_type == hppa_stub_long_branch
    3035                                && (LONG_BRANCH_PIC_IN_SHLIB || hash == NULL))
     3096                      else if (stub_type == hppa_stub_long_branch)
    30363097                        stub_entry->stub_type = hppa_stub_long_branch_shared;
    30373098                    }
    30383099                  stub_entry->h = hash;
    3039                   stub_changed = 1;
     3100                  stub_changed = TRUE;
    30403101                }
    30413102
    30423103              /* We're done with the internal relocs, free them.  */
    3043               free (internal_relocs);
     3104              if (elf_section_data (section)->relocs == NULL)
     3105                free (internal_relocs);
    30443106            }
    30453107        }
     
    30503112      /* OK, we've added some stubs.  Find out the new size of the
    30513113         stub sections.  */
    3052       for (stub_sec = hplink->stub_bfd->sections;
     3114      for (stub_sec = htab->stub_bfd->sections;
    30533115           stub_sec != NULL;
    30543116           stub_sec = stub_sec->next)
     
    30573119          stub_sec->_cooked_size = 0;
    30583120        }
    3059 #if ! LONG_BRANCH_PIC_IN_SHLIB
    3060       {
    3061         int i;
    3062 
    3063         for (i = top_id; i >= 0; --i)
    3064           {
    3065             /* This will probably hit the same section many times..  */
    3066             stub_sec = hplink->stub_group[i].reloc_sec;
    3067             if (stub_sec != NULL)
    3068               {
    3069                 stub_sec->_raw_size = 0;
    3070                 stub_sec->_cooked_size = 0;
    3071               }
    3072           }
    3073       }
    3074 #endif
    3075 
    3076       bfd_hash_traverse (&hplink->stub_hash_table,
    3077                          hppa_size_one_stub,
    3078                          hplink);
     3121
     3122      bfd_hash_traverse (&htab->stub_hash_table, hppa_size_one_stub, htab);
    30793123
    30803124      /* Ask the linker to do its stuff.  */
    3081       (*hplink->layout_sections_again) ();
    3082       stub_changed = 0;
    3083     }
    3084 
    3085   ret = 1;
     3125      (*htab->layout_sections_again) ();
     3126      stub_changed = FALSE;
     3127    }
     3128
     3129  free (htab->all_local_syms);
     3130  return TRUE;
    30863131
    30873132 error_ret_free_local:
    3088   while (bfd_count-- > 0)
    3089     if (all_local_syms[bfd_count])
    3090       free (all_local_syms[bfd_count]);
    3091   free (all_local_syms);
    3092 
    3093   return ret;
     3133  free (htab->all_local_syms);
     3134  return FALSE;
    30943135}
    30953136
     
    30973138   stubs to provide a value for __gp.  */
    30983139
    3099 boolean
     3140bfd_boolean
    31003141elf32_hppa_set_gp (abfd, info)
    31013142     bfd *abfd;
    31023143     struct bfd_link_info *info;
    31033144{
    3104   struct elf32_hppa_link_hash_table *hplink;
    3105   struct elf_link_hash_entry *h;
    3106   asection *sec;
    3107   bfd_vma gp_val;
    3108 
    3109   hplink = hppa_link_hash_table (info);
    3110   h = elf_link_hash_lookup (&hplink->root, "$global$",
    3111                             false, false, false);
     3145  struct bfd_link_hash_entry *h;
     3146  asection *sec = NULL;
     3147  bfd_vma gp_val = 0;
     3148  struct elf32_hppa_link_hash_table *htab;
     3149
     3150  htab = hppa_link_hash_table (info);
     3151  h = bfd_link_hash_lookup (&htab->elf.root, "$global$", FALSE, FALSE, FALSE);
    31123152
    31133153  if (h != NULL
    3114       && (h->root.type == bfd_link_hash_defined
    3115           || h->root.type == bfd_link_hash_defweak))
    3116     {
    3117       gp_val = h->root.u.def.value;
    3118       sec = h->root.u.def.section;
     3154      && (h->type == bfd_link_hash_defined
     3155          || h->type == bfd_link_hash_defweak))
     3156    {
     3157      gp_val = h->u.def.value;
     3158      sec = h->u.def.section;
    31193159    }
    31203160  else
    31213161    {
     3162      asection *splt;
     3163      asection *sgot;
     3164
     3165      if (htab->elf.root.creator->flavour == bfd_target_elf_flavour)
     3166        {
     3167          splt = htab->splt;
     3168          sgot = htab->sgot;
     3169        }
     3170      else
     3171        {
     3172          /* If we're not elf, look up the output sections in the
     3173             hope we may actually find them.  */
     3174          splt = bfd_get_section_by_name (abfd, ".plt");
     3175          sgot = bfd_get_section_by_name (abfd, ".got");
     3176        }
     3177
    31223178      /* Choose to point our LTP at, in this order, one of .plt, .got,
    31233179         or .data, if these sections exist.  In the case of choosing
     
    31283184         the .plt and .got are smaller than 0x2000, choose the end of
    31293185         the .plt section.  */
    3130 
    3131       sec = hplink->splt;
     3186      sec = splt;
    31323187      if (sec != NULL)
    31333188        {
    31343189          gp_val = sec->_raw_size;
    3135           if (gp_val > 0x2000
    3136               || (hplink->sgot && hplink->sgot->_raw_size > 0x2000))
     3190          if (gp_val > 0x2000 || (sgot && sgot->_raw_size > 0x2000))
    31373191            {
    31383192              gp_val = 0x2000;
     
    31413195      else
    31423196        {
    3143           gp_val = 0;
    3144           sec = hplink->sgot;
     3197          sec = sgot;
    31453198          if (sec != NULL)
    31463199            {
     
    31593212      if (h != NULL)
    31603213        {
    3161           h->root.type = bfd_link_hash_defined;
    3162           h->root.u.def.value = gp_val;
     3214          h->type = bfd_link_hash_defined;
     3215          h->u.def.value = gp_val;
    31633216          if (sec != NULL)
    3164             h->root.u.def.section = sec;
     3217            h->u.def.section = sec;
    31653218          else
    3166             h->root.u.def.section = bfd_abs_section_ptr;
     3219            h->u.def.section = bfd_abs_section_ptr;
    31673220        }
    31683221    }
     
    31723225
    31733226  elf_gp (abfd) = gp_val;
    3174   return true;
     3227  return TRUE;
    31753228}
    31763229
     
    31813234   linker.  */
    31823235
    3183 boolean
     3236bfd_boolean
    31843237elf32_hppa_build_stubs (info)
    31853238     struct bfd_link_info *info;
     
    31873240  asection *stub_sec;
    31883241  struct bfd_hash_table *table;
    3189   struct elf32_hppa_link_hash_table *hplink;
    3190 
    3191   hplink = hppa_link_hash_table (info);
    3192 
    3193   for (stub_sec = hplink->stub_bfd->sections;
     3242  struct elf32_hppa_link_hash_table *htab;
     3243
     3244  htab = hppa_link_hash_table (info);
     3245
     3246  for (stub_sec = htab->stub_bfd->sections;
    31943247       stub_sec != NULL;
    31953248       stub_sec = stub_sec->next)
    31963249    {
    3197       size_t size;
     3250      bfd_size_type size;
    31983251
    31993252      /* Allocate memory to hold the linker stubs.  */
    32003253      size = stub_sec->_raw_size;
    3201       stub_sec->contents = (unsigned char *) bfd_zalloc (hplink->stub_bfd,
    3202                                                          size);
     3254      stub_sec->contents = (unsigned char *) bfd_zalloc (htab->stub_bfd, size);
    32033255      if (stub_sec->contents == NULL && size != 0)
    3204         return false;
     3256        return FALSE;
    32053257      stub_sec->_raw_size = 0;
    32063258    }
    32073259
    32083260  /* Build the stubs as directed by the stub hash table.  */
    3209   table = &hplink->stub_hash_table;
     3261  table = &htab->stub_hash_table;
    32103262  bfd_hash_traverse (table, hppa_build_one_stub, info);
    32113263
    3212   return true;
     3264  return TRUE;
    32133265}
    32143266
    32153267/* Perform a final link.  */
    32163268
    3217 static boolean
     3269static bfd_boolean
    32183270elf32_hppa_final_link (abfd, info)
    32193271     bfd *abfd;
    32203272     struct bfd_link_info *info;
    32213273{
    3222   asection *s;
    3223 
    32243274  /* Invoke the regular ELF linker to do all the work.  */
    32253275  if (!bfd_elf32_bfd_final_link (abfd, info))
    3226     return false;
     3276    return FALSE;
    32273277
    32283278  /* If we're producing a final executable, sort the contents of the
    3229      unwind section.  Magic section names, but this is much safer than
    3230      having elf32_hppa_relocate_section remember where SEGREL32 relocs
    3231      occurred.  Consider what happens if someone inept creates a
    3232      linker script that puts unwind information in .text.  */
    3233   s = bfd_get_section_by_name (abfd, ".PARISC.unwind");
    3234   if (s != NULL)
    3235     {
    3236       bfd_size_type size;
    3237       char *contents;
    3238 
    3239       size = s->_raw_size;
    3240       contents = bfd_malloc (size);
    3241       if (contents == NULL)
    3242         return false;
    3243 
    3244       if (! bfd_get_section_contents (abfd, s, contents, (file_ptr) 0, size))
    3245         return false;
    3246 
    3247       qsort (contents, size / 16, 16, hppa_unwind_entry_compare);
    3248 
    3249       if (! bfd_set_section_contents (abfd, s, contents, (file_ptr) 0, size))
    3250         return false;
    3251     }
    3252   return true;
     3279     unwind section.  */
     3280  return elf_hppa_sort_unwind (abfd);
    32533281}
    32543282
     
    32613289     PTR data;
    32623290{
    3263   struct elf32_hppa_link_hash_table *hplink;
    3264 
    3265   hplink = (struct elf32_hppa_link_hash_table *) data;
     3291  struct elf32_hppa_link_hash_table *htab;
     3292
     3293  htab = (struct elf32_hppa_link_hash_table *) data;
    32663294
    32673295  if ((section->flags & (SEC_ALLOC | SEC_LOAD)) == (SEC_ALLOC | SEC_LOAD))
     
    32713299      if ((section->flags & SEC_READONLY) != 0)
    32723300        {
    3273           if (value < hplink->text_segment_base)
    3274             hplink->text_segment_base = value;
     3301          if (value < htab->text_segment_base)
     3302            htab->text_segment_base = value;
    32753303        }
    32763304      else
    32773305        {
    3278           if (value < hplink->data_segment_base)
    3279             hplink->data_segment_base = value;
     3306          if (value < htab->data_segment_base)
     3307            htab->data_segment_base = value;
    32803308        }
    32813309    }
     
    32853313
    32863314static bfd_reloc_status_type
    3287 final_link_relocate (input_section, contents, rel, value, hplink, sym_sec, h)
     3315final_link_relocate (input_section, contents, rel, value, htab, sym_sec, h)
    32883316     asection *input_section;
    32893317     bfd_byte *contents;
    32903318     const Elf_Internal_Rela *rel;
    32913319     bfd_vma value;
    3292      struct elf32_hppa_link_hash_table *hplink;
     3320     struct elf32_hppa_link_hash_table *htab;
    32933321     asection *sym_sec;
    32943322     struct elf32_hppa_link_hash_entry *h;
     
    33233351    case R_PARISC_PCREL17F:
    33243352    case R_PARISC_PCREL22F:
    3325       /* If this is a call to a function defined in another dynamic
    3326          library, or if it is a call to a PIC function in the same
    3327          object, or if this is a shared link and it is a call to a
    3328          weak symbol which may or may not be in the same object, then
    3329          find the import stub in the stub hash.  */
     3353      /* If this call should go via the plt, find the import stub in
     3354         the stub hash.  */
    33303355      if (sym_sec == NULL
    33313356          || sym_sec->output_section == NULL
    33323357          || (h != NULL
    3333               && ((h->maybe_pic_call
    3334                    && !(input_section->flags & SEC_HAS_GOT_REF))
    3335                   || (h->elf.root.type == bfd_link_hash_defweak
    3336                       && h->elf.dynindx != -1
    3337                       && h->elf.plt.offset != (bfd_vma) -1))))
     3358              && h->elf.plt.offset != (bfd_vma) -1
     3359              && (h->elf.dynindx != -1 || h->pic_call)
     3360              && !h->plabel))
    33383361        {
    33393362          stub_entry = hppa_get_stub_entry (input_section, sym_sec,
    3340                                             h, rel, hplink);
     3363                                            h, rel, htab);
    33413364          if (stub_entry != NULL)
    33423365            {
     
    33583381            }
    33593382          else
    3360             return bfd_reloc_notsupported;
     3383            return bfd_reloc_undefined;
    33613384        }
    33623385      /* Fall thru.  */
     
    33763399    case R_PARISC_DPREL14F:
    33773400    /* For all the DP relative relocations, we need to examine the symbol's
    3378        section.  If it's a code section, then "data pointer relative" makes
    3379        no sense.  In that case we don't adjust the "value", and for 21 bit
    3380        addil instructions, we change the source addend register from %dp to
    3381        %r0.  This situation commonly arises when a variable's "constness"
     3401       section.  If it has no section or if it's a code section, then
     3402       "data pointer relative" makes no sense.  In that case we don't
     3403       adjust the "value", and for 21 bit addil instructions, we change the
     3404       source addend register from %dp to %r0.  This situation commonly
     3405       arises for undefined weak symbols and when a variable's "constness"
    33823406       is declared differently from the way the variable is defined.  For
    33833407       instance: "extern int foo" with foo defined as "const int foo".  */
    3384       if (sym_sec == NULL)
    3385         break;
    3386       if ((sym_sec->flags & SEC_CODE) != 0)
     3408      if (sym_sec == NULL || (sym_sec->flags & SEC_CODE) != 0)
    33873409        {
    33883410          if ((insn & ((0x3f << 26) | (0x1f << 21)))
     
    33903412            {
    33913413              insn &= ~ (0x1f << 21);
    3392 #if 1 /* debug them.  */
     3414#if 0 /* debug them.  */
    33933415              (*_bfd_error_handler)
    33943416                (_("%s(%s+0x%lx): fixing %s"),
    3395                  bfd_get_filename (input_bfd),
     3417                 bfd_archive_filename (input_bfd),
    33963418                 input_section->name,
    33973419                 (long) rel->r_offset,
     
    34133435    case R_PARISC_SEGREL32:
    34143436      if ((sym_sec->flags & SEC_CODE) != 0)
    3415         value -= hplink->text_segment_base;
     3437        value -= htab->text_segment_base;
    34163438      else
    3417         value -= hplink->data_segment_base;
     3439        value -= htab->data_segment_base;
    34183440      break;
    34193441
     
    34373459      break;
    34383460
     3461    case R_PARISC_DLTIND21L:
     3462    case R_PARISC_PCREL21L:
     3463    case R_PARISC_PLABEL21L:
     3464      r_field = e_lsel;
     3465      break;
     3466
    34393467    case R_PARISC_DIR21L:
    3440     case R_PARISC_PCREL21L:
    34413468    case R_PARISC_DPREL21L:
    3442     case R_PARISC_PLABEL21L:
    3443     case R_PARISC_DLTIND21L:
    34443469      r_field = e_lrsel;
    34453470      break;
    34463471
    3447     case R_PARISC_DIR17R:
    34483472    case R_PARISC_PCREL17R:
    3449     case R_PARISC_DIR14R:
    34503473    case R_PARISC_PCREL14R:
    3451     case R_PARISC_DPREL14R:
    34523474    case R_PARISC_PLABEL14R:
    34533475    case R_PARISC_DLTIND14R:
     3476      r_field = e_rsel;
     3477      break;
     3478
     3479    case R_PARISC_DIR17R:
     3480    case R_PARISC_DIR14R:
     3481    case R_PARISC_DPREL14R:
    34543482      r_field = e_rrsel;
    34553483      break;
     
    34843512        {
    34853513          stub_entry = hppa_get_stub_entry (input_section, sym_sec,
    3486                                             h, rel, hplink);
     3514                                            h, rel, htab);
    34873515          if (stub_entry == NULL)
    3488             return bfd_reloc_notsupported;
     3516            return bfd_reloc_undefined;
    34893517
    34903518          /* Munge up the value and addend so that we call the stub
     
    35093537      (*_bfd_error_handler)
    35103538        (_("%s(%s+0x%lx): cannot reach %s, recompile with -ffunction-sections"),
    3511          bfd_get_filename (input_bfd),
     3539         bfd_archive_filename (input_bfd),
    35123540         input_section->name,
    35133541         (long) rel->r_offset,
    35143542         stub_entry->root.string);
     3543      bfd_set_error (bfd_error_bad_value);
    35153544      return bfd_reloc_notsupported;
    35163545    }
     
    35473576/* Relocate an HPPA ELF section.  */
    35483577
    3549 static boolean
     3578static bfd_boolean
    35503579elf32_hppa_relocate_section (output_bfd, info, input_bfd, input_section,
    35513580                             contents, relocs, local_syms, local_sections)
     
    35593588     asection **local_sections;
    35603589{
    3561   bfd *dynobj;
    35623590  bfd_vma *local_got_offsets;
    3563   struct elf32_hppa_link_hash_table *hplink;
     3591  struct elf32_hppa_link_hash_table *htab;
    35643592  Elf_Internal_Shdr *symtab_hdr;
    35653593  Elf_Internal_Rela *rel;
    35663594  Elf_Internal_Rela *relend;
    3567   asection *sreloc;
     3595
     3596  if (info->relocateable)
     3597    return TRUE;
    35683598
    35693599  symtab_hdr = &elf_tdata (input_bfd)->symtab_hdr;
    35703600
    3571   hplink = hppa_link_hash_table (info);
    3572   dynobj = hplink->root.dynobj;
     3601  htab = hppa_link_hash_table (info);
    35733602  local_got_offsets = elf_local_got_offsets (input_bfd);
    3574   sreloc = NULL;
    35753603
    35763604  rel = relocs;
     
    35873615      bfd_reloc_status_type r;
    35883616      const char *sym_name;
    3589       boolean plabel;
     3617      bfd_boolean plabel;
     3618      bfd_boolean warned_undef;
    35903619
    35913620      r_type = ELF32_R_TYPE (rel->r_info);
     
    35933622        {
    35943623          bfd_set_error (bfd_error_bad_value);
    3595           return false;
     3624          return FALSE;
    35963625        }
    35973626      if (r_type == (unsigned int) R_PARISC_GNU_VTENTRY
     
    35993628        continue;
    36003629
     3630      /* This is a final link.  */
    36013631      r_symndx = ELF32_R_SYM (rel->r_info);
    3602 
    3603       if (info->relocateable)
    3604         {
    3605           /* This is a relocateable link.  We don't have to change
    3606              anything, unless the reloc is against a section symbol,
    3607              in which case we have to adjust according to where the
    3608              section symbol winds up in the output section.  */
    3609           if (r_symndx < symtab_hdr->sh_info)
    3610             {
    3611               sym = local_syms + r_symndx;
    3612               if (ELF_ST_TYPE (sym->st_info) == STT_SECTION)
    3613                 {
    3614                   sym_sec = local_sections[r_symndx];
    3615                   rel->r_addend += sym_sec->output_offset;
    3616                 }
    3617             }
    3618           continue;
    3619         }
    3620 
    3621       /* This is a final link.  */
    36223632      h = NULL;
    36233633      sym = NULL;
    36243634      sym_sec = NULL;
     3635      warned_undef = FALSE;
    36253636      if (r_symndx < symtab_hdr->sh_info)
    36263637        {
     
    36283639          sym = local_syms + r_symndx;
    36293640          sym_sec = local_sections[r_symndx];
    3630           relocation = ((ELF_ST_TYPE (sym->st_info) == STT_SECTION
    3631                            ? 0 : sym->st_value)
    3632                          + sym_sec->output_offset
    3633                          + sym_sec->output_section->vma);
     3641          relocation = _bfd_elf_rela_local_sym (output_bfd, sym, sym_sec, rel);
    36343642        }
    36353643      else
     
    36593667          else if (h->elf.root.type == bfd_link_hash_undefweak)
    36603668            ;
    3661           else if (info->shared && !info->no_undefined
     3669          else if (info->shared
     3670                   && !info->no_undefined
    36623671                   && ELF_ST_VISIBILITY (h->elf.other) == STV_DEFAULT
    36633672                   && h->elf.type != STT_PARISC_MILLI)
    3664             {
    3665               if (info->symbolic)
    3666                 if (!((*info->callbacks->undefined_symbol)
    3667                       (info, h->elf.root.root.string, input_bfd,
    3668                        input_section, rel->r_offset, false)))
    3669                   return false;
    3670             }
     3673            ;
    36713674          else
    36723675            {
    36733676              if (!((*info->callbacks->undefined_symbol)
    36743677                    (info, h->elf.root.root.string, input_bfd,
    3675                      input_section, rel->r_offset, true)))
    3676                 return false;
     3678                     input_section, rel->r_offset, TRUE)))
     3679                return FALSE;
     3680              warned_undef = TRUE;
    36773681            }
    36783682        }
     
    36873691        case R_PARISC_DLTIND14R:
    36883692        case R_PARISC_DLTIND21L:
    3689           /* Relocation is to the entry for this symbol in the global
    3690              offset table.  */
    3691           if (h != NULL)
    3692             {
    3693               bfd_vma off;
    3694               boolean dyn;
    3695 
    3696               off = h->elf.got.offset;
    3697               if (off == (bfd_vma) -1)
    3698                 abort ();
    3699 
    3700               dyn = hplink->root.dynamic_sections_created;
    3701               if (! WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn, info, &h->elf))
    3702                 {
    3703                   /* This is actually a static link, or it is a
    3704                      -Bsymbolic link and the symbol is defined
    3705                      locally, or the symbol was forced to be local
    3706                      because of a version file.  We must initialize
    3707                      this entry in the global offset table.  Since the
    3708                      offset must always be a multiple of 4, we use the
    3709                      least significant bit to record whether we have
    3710                      initialized it already.
    3711 
    3712                      When doing a dynamic link, we create a .rela.got
    3713                      relocation entry to initialize the value.  This
    3714                      is done in the finish_dynamic_symbol routine.  */
    3715                   if ((off & 1) != 0)
    3716                     off &= ~1;
    3717                   else
    3718                     {
    3719                       bfd_put_32 (output_bfd, relocation,
    3720                                   hplink->sgot->contents + off);
    3721                       h->elf.got.offset |= 1;
    3722                     }
    3723                 }
    3724 
    3725               relocation = off;
    3726             }
    3727           else
    3728             {
    3729               /* Local symbol case.  */
    3730               bfd_vma off;
    3731 
    3732               if (local_got_offsets == NULL
    3733                   || (off = local_got_offsets[r_symndx]) == (bfd_vma) -1)
    3734                 abort ();
    3735 
    3736               /* The offset must always be a multiple of 4.  We use
    3737                  the least significant bit to record whether we have
    3738                  already generated the necessary reloc.  */
    3739               if ((off & 1) != 0)
    3740                 off &= ~1;
    3741               else
    3742                 {
     3693          {
     3694            bfd_vma off;
     3695            bfd_boolean do_got = 0;
     3696
     3697            /* Relocation is to the entry for this symbol in the
     3698               global offset table.  */
     3699            if (h != NULL)
     3700              {
     3701                bfd_boolean dyn;
     3702
     3703                off = h->elf.got.offset;
     3704                dyn = htab->elf.dynamic_sections_created;
     3705                if (! WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn, info, &h->elf))
     3706                  {
     3707                    /* If we aren't going to call finish_dynamic_symbol,
     3708                       then we need to handle initialisation of the .got
     3709                       entry and create needed relocs here.  Since the
     3710                       offset must always be a multiple of 4, we use the
     3711                       least significant bit to record whether we have
     3712                       initialised it already.  */
     3713                    if ((off & 1) != 0)
     3714                      off &= ~1;
     3715                    else
     3716                      {
     3717                        h->elf.got.offset |= 1;
     3718                        do_got = 1;
     3719                      }
     3720                  }
     3721              }
     3722            else
     3723              {
     3724                /* Local symbol case.  */
     3725                if (local_got_offsets == NULL)
     3726                  abort ();
     3727
     3728                off = local_got_offsets[r_symndx];
     3729
     3730                /* The offset must always be a multiple of 4.  We use
     3731                   the least significant bit to record whether we have
     3732                   already generated the necessary reloc.  */
     3733                if ((off & 1) != 0)
     3734                  off &= ~1;
     3735                else
     3736                  {
     3737                    local_got_offsets[r_symndx] |= 1;
     3738                    do_got = 1;
     3739                  }
     3740              }
     3741
     3742            if (do_got)
     3743              {
     3744                if (info->shared)
     3745                  {
     3746                    /* Output a dynamic relocation for this GOT entry.
     3747                       In this case it is relative to the base of the
     3748                       object because the symbol index is zero.  */
     3749                    Elf_Internal_Rela outrel;
     3750                    bfd_byte *loc;
     3751                    asection *s = htab->srelgot;
     3752
     3753                    outrel.r_offset = (off
     3754                                       + htab->sgot->output_offset
     3755                                       + htab->sgot->output_section->vma);
     3756                    outrel.r_info = ELF32_R_INFO (0, R_PARISC_DIR32);
     3757                    outrel.r_addend = relocation;
     3758                    loc = s->contents;
     3759                    loc += s->reloc_count++ * sizeof (Elf32_External_Rela);
     3760                    bfd_elf32_swap_reloca_out (output_bfd, &outrel, loc);
     3761                  }
     3762                else
    37433763                  bfd_put_32 (output_bfd, relocation,
    3744                               hplink->sgot->contents + off);
    3745 
    3746                   if (info->shared)
    3747                     {
    3748                       /* Output a dynamic relocation for this GOT
    3749                          entry.  In this case it is relative to the
    3750                          base of the object because the symbol index
    3751                          is zero.  */
    3752                       Elf_Internal_Rela outrel;
    3753                       asection *srelgot = hplink->srelgot;
    3754 
    3755                       outrel.r_offset = (off
    3756                                          + hplink->sgot->output_offset
    3757                                          + hplink->sgot->output_section->vma);
    3758                       outrel.r_info = ELF32_R_INFO (0, R_PARISC_DIR32);
    3759                       outrel.r_addend = relocation;
    3760                       bfd_elf32_swap_reloca_out (output_bfd, &outrel,
    3761                                                  ((Elf32_External_Rela *)
    3762                                                   srelgot->contents
    3763                                                   + srelgot->reloc_count));
    3764                       ++srelgot->reloc_count;
    3765                     }
    3766 
    3767                   local_got_offsets[r_symndx] |= 1;
    3768                 }
    3769 
    3770               relocation = off;
    3771             }
    3772 
    3773           /* Add the base of the GOT to the relocation value.  */
    3774           relocation += (hplink->sgot->output_offset
    3775                          + hplink->sgot->output_section->vma);
     3764                              htab->sgot->contents + off);
     3765              }
     3766
     3767            if (off >= (bfd_vma) -2)
     3768              abort ();
     3769
     3770            /* Add the base of the GOT to the relocation value.  */
     3771            relocation = (off
     3772                          + htab->sgot->output_offset
     3773                          + htab->sgot->output_section->vma);
     3774          }
    37763775          break;
    37773776
     
    37793778          /* If this is the first SEGREL relocation, then initialize
    37803779             the segment base values.  */
    3781           if (hplink->text_segment_base == (bfd_vma) -1)
    3782             bfd_map_over_sections (output_bfd,
    3783                                    hppa_record_segment_addr,
    3784                                    hplink);
     3780          if (htab->text_segment_base == (bfd_vma) -1)
     3781            bfd_map_over_sections (output_bfd, hppa_record_segment_addr, htab);
    37853782          break;
    37863783
     
    37883785        case R_PARISC_PLABEL21L:
    37893786        case R_PARISC_PLABEL32:
    3790           if (hplink->root.dynamic_sections_created)
     3787          if (htab->elf.dynamic_sections_created)
    37913788            {
    37923789              bfd_vma off;
     3790              bfd_boolean do_plt = 0;
    37933791
    37943792              /* If we have a global symbol with a PLT slot, then
     
    38013799                      /* In a non-shared link, adjust_dynamic_symbols
    38023800                         isn't called for symbols forced local.  We
    3803                          need to write out the plt entry here.  */ 
     3801                         need to write out the plt entry here.  */
    38043802                      if ((off & 1) != 0)
    38053803                        off &= ~1;
    38063804                      else
    38073805                        {
    3808                           bfd_put_32 (output_bfd,
    3809                                       relocation,
    3810                                       hplink->splt->contents + off);
    3811                           bfd_put_32 (output_bfd,
    3812                                       elf_gp (hplink->splt->output_section->owner),
    3813                                       hplink->splt->contents + off + 4);
    38143806                          h->elf.plt.offset |= 1;
     3807                          do_plt = 1;
    38153808                        }
    38163809                    }
     
    38183811              else
    38193812                {
    3820                   int indx;
    3821 
    3822                   indx = r_symndx + symtab_hdr->sh_info;
    3823                   off = local_got_offsets[indx];
     3813                  bfd_vma *local_plt_offsets;
     3814
     3815                  if (local_got_offsets == NULL)
     3816                    abort ();
     3817
     3818                  local_plt_offsets = local_got_offsets + symtab_hdr->sh_info;
     3819                  off = local_plt_offsets[r_symndx];
    38243820
    38253821                  /* As for the local .got entry case, we use the last
     
    38303826                  else
    38313827                    {
     3828                      local_plt_offsets[r_symndx] |= 1;
     3829                      do_plt = 1;
     3830                    }
     3831                }
     3832
     3833              if (do_plt)
     3834                {
     3835                  if (info->shared)
     3836                    {
     3837                      /* Output a dynamic IPLT relocation for this
     3838                         PLT entry.  */
     3839                      Elf_Internal_Rela outrel;
     3840                      bfd_byte *loc;
     3841                      asection *s = htab->srelplt;
     3842
     3843                      outrel.r_offset = (off
     3844                                         + htab->splt->output_offset
     3845                                         + htab->splt->output_section->vma);
     3846                      outrel.r_info = ELF32_R_INFO (0, R_PARISC_IPLT);
     3847                      outrel.r_addend = relocation;
     3848                      loc = s->contents;
     3849                      loc += s->reloc_count++ * sizeof (Elf32_External_Rela);
     3850                      bfd_elf32_swap_reloca_out (output_bfd, &outrel, loc);
     3851                    }
     3852                  else
     3853                    {
    38323854                      bfd_put_32 (output_bfd,
    38333855                                  relocation,
    3834                                   hplink->splt->contents + off);
     3856                                  htab->splt->contents + off);
    38353857                      bfd_put_32 (output_bfd,
    3836                                   elf_gp (hplink->splt->output_section->owner),
    3837                                   hplink->splt->contents + off + 4);
    3838 
    3839                       if (info->shared)
    3840                         {
    3841                           /* Output a dynamic IPLT relocation for this
    3842                              PLT entry.  */
    3843                           Elf_Internal_Rela outrel;
    3844                           asection *srelplt = hplink->srelplt;
    3845 
    3846                           outrel.r_offset = (off
    3847                                              + hplink->splt->output_offset
    3848                                              + hplink->splt->output_section->vma);
    3849                           outrel.r_info = ELF32_R_INFO (0, R_PARISC_IPLT);
    3850                           outrel.r_addend = relocation;
    3851                           bfd_elf32_swap_reloca_out (output_bfd, &outrel,
    3852                                                      ((Elf32_External_Rela *)
    3853                                                       srelplt->contents
    3854                                                       + srelplt->reloc_count));
    3855                           ++srelplt->reloc_count;
    3856                         }
    3857 
    3858                       local_got_offsets[indx] |= 1;
     3858                                  elf_gp (htab->splt->output_section->owner),
     3859                                  htab->splt->contents + off + 4);
    38593860                    }
    38603861                }
    38613862
    3862               if (off >= (bfd_vma) -2 || (off & 1) != 0)
     3863              if (off >= (bfd_vma) -2)
    38633864                abort ();
    38643865
     
    38743875                {
    38753876                  relocation = (off
    3876                                 + hplink->splt->output_offset
    3877                                 + hplink->splt->output_section->vma
     3877                                + htab->splt->output_offset
     3878                                + htab->splt->output_section->vma
    38783879                                + 2);
    38793880                }
     
    38913892        case R_PARISC_DPREL21L:
    38923893        case R_PARISC_DIR32:
     3894          /* r_symndx will be zero only for relocs against symbols
     3895             from removed linkonce sections, or sections discarded by
     3896             a linker script.  */
     3897          if (r_symndx == 0
     3898              || (input_section->flags & SEC_ALLOC) == 0)
     3899            break;
     3900
    38933901          /* The reloc types handled here and this conditional
    3894              expression must match the code in check_relocs and
    3895              hppa_discard_copies.  ie. We need exactly the same
    3896              condition as in check_relocs, with some extra conditions
    3897              (dynindx test in this case) to cater for relocs removed
    3898              by hppa_discard_copies.  */
    3899           if ((input_section->flags & SEC_ALLOC) != 0
    3900               && info->shared
    3901 #if RELATIVE_DYNAMIC_RELOCS
    3902               && (is_absolute_reloc (r_type)
    3903                   || ((!info->symbolic
    3904                        || (h != NULL
    3905                            && ((h->elf.elf_link_hash_flags
    3906                                 & ELF_LINK_HASH_DEF_REGULAR) == 0
    3907                                || h->elf.root.type == bfd_link_hash_defweak)))
    3908                       && (h == NULL || h->elf.dynindx != -1)))
    3909 #endif
    3910               )
     3902             expression must match the code in ..check_relocs and
     3903             allocate_dynrelocs.  ie. We need exactly the same condition
     3904             as in ..check_relocs, with some extra conditions (dynindx
     3905             test in this case) to cater for relocs removed by
     3906             allocate_dynrelocs.  If you squint, the non-shared test
     3907             here does indeed match the one in ..check_relocs, the
     3908             difference being that here we test DEF_DYNAMIC as well as
     3909             !DEF_REGULAR.  All common syms end up with !DEF_REGULAR,
     3910             which is why we can't use just that test here.
     3911             Conversely, DEF_DYNAMIC can't be used in check_relocs as
     3912             there all files have not been loaded.  */
     3913          if ((info->shared
     3914               && (IS_ABSOLUTE_RELOC (r_type)
     3915                   || (h != NULL
     3916                       && h->elf.dynindx != -1
     3917                       && (!info->symbolic
     3918                           || (h->elf.elf_link_hash_flags
     3919                               & ELF_LINK_HASH_DEF_REGULAR) == 0))))
     3920              || (!info->shared
     3921                  && h != NULL
     3922                  && h->elf.dynindx != -1
     3923                  && (h->elf.elf_link_hash_flags & ELF_LINK_NON_GOT_REF) == 0
     3924                  && (((h->elf.elf_link_hash_flags
     3925                        & ELF_LINK_HASH_DEF_DYNAMIC) != 0
     3926                       && (h->elf.elf_link_hash_flags
     3927                           & ELF_LINK_HASH_DEF_REGULAR) == 0)
     3928                      || h->elf.root.type == bfd_link_hash_undefweak
     3929                      || h->elf.root.type == bfd_link_hash_undefined)))
    39113930            {
    39123931              Elf_Internal_Rela outrel;
    3913               boolean skip;
     3932              bfd_boolean skip;
     3933              asection *sreloc;
     3934              bfd_byte *loc;
    39143935
    39153936              /* When generating a shared object, these relocations
     
    39173938                 time.  */
    39183939
    3919               if (sreloc == NULL)
    3920                 {
    3921                   const char *name;
    3922 
    3923                   name = (bfd_elf_string_from_elf_section
    3924                           (input_bfd,
    3925                            elf_elfheader (input_bfd)->e_shstrndx,
    3926                            elf_section_data (input_section)->rel_hdr.sh_name));
    3927                   if (name == NULL)
    3928                     return false;
    3929                   sreloc = bfd_get_section_by_name (dynobj, name);
    3930                   if (sreloc == NULL)
    3931                     abort ();
    3932                 }
    3933 
    3934               outrel.r_offset = rel->r_offset;
    39353940              outrel.r_addend = rel->r_addend;
    3936               skip = false;
    3937               if (elf_section_data (input_section)->stab_info != NULL)
    3938                 {
    3939                   bfd_vma off;
    3940 
    3941                   off = (_bfd_stab_section_offset
    3942                          (output_bfd, &hplink->root.stab_info,
    3943                           input_section,
    3944                           &elf_section_data (input_section)->stab_info,
    3945                           rel->r_offset));
    3946                   if (off == (bfd_vma) -1)
    3947                     skip = true;
    3948                   outrel.r_offset = off;
    3949                 }
    3950 
     3941              outrel.r_offset =
     3942                _bfd_elf_section_offset (output_bfd, info, input_section,
     3943                                         rel->r_offset);
     3944              skip = (outrel.r_offset == (bfd_vma) -1
     3945                      || outrel.r_offset == (bfd_vma) -2);
    39513946              outrel.r_offset += (input_section->output_offset
    39523947                                  + input_section->output_section->vma);
     
    39593954                       && h->elf.dynindx != -1
    39603955                       && (plabel
     3956                           || !IS_ABSOLUTE_RELOC (r_type)
     3957                           || !info->shared
    39613958                           || !info->symbolic
    39623959                           || (h->elf.elf_link_hash_flags
     
    39933990                  outrel.r_info = ELF32_R_INFO (indx, r_type);
    39943991                }
    3995 
    3996               bfd_elf32_swap_reloca_out (output_bfd, &outrel,
    3997                                          ((Elf32_External_Rela *)
    3998                                           sreloc->contents
    3999                                           + sreloc->reloc_count));
    4000               ++sreloc->reloc_count;
     3992#if 0
     3993              /* EH info can cause unaligned DIR32 relocs.
     3994                 Tweak the reloc type for the dynamic linker.  */
     3995              if (r_type == R_PARISC_DIR32 && (outrel.r_offset & 3) != 0)
     3996                outrel.r_info = ELF32_R_INFO (ELF32_R_SYM (outrel.r_info),
     3997                                              R_PARISC_DIR32U);
     3998#endif
     3999              sreloc = elf_section_data (input_section)->sreloc;
     4000              if (sreloc == NULL)
     4001                abort ();
     4002
     4003              loc = sreloc->contents;
     4004              loc += sreloc->reloc_count++ * sizeof (Elf32_External_Rela);
     4005              bfd_elf32_swap_reloca_out (output_bfd, &outrel, loc);
    40014006            }
    40024007          break;
     
    40074012
    40084013      r = final_link_relocate (input_section, contents, rel, relocation,
    4009                                hplink, sym_sec, h);
     4014                               htab, sym_sec, h);
    40104015
    40114016      if (r == bfd_reloc_ok)
     
    40204025                                                      sym->st_name);
    40214026          if (sym_name == NULL)
    4022             return false;
     4027            return FALSE;
    40234028          if (*sym_name == '\0')
    40244029            sym_name = bfd_section_name (input_bfd, sym_sec);
     
    40294034      if (r == bfd_reloc_undefined || r == bfd_reloc_notsupported)
    40304035        {
    4031           (*_bfd_error_handler)
    4032             (_("%s(%s+0x%lx): cannot handle %s for %s"),
    4033              bfd_get_filename (input_bfd),
    4034              input_section->name,
    4035              (long) rel->r_offset,
    4036              howto->name,
    4037              sym_name);
     4036          if (r == bfd_reloc_notsupported || !warned_undef)
     4037            {
     4038              (*_bfd_error_handler)
     4039                (_("%s(%s+0x%lx): cannot handle %s for %s"),
     4040                 bfd_archive_filename (input_bfd),
     4041                 input_section->name,
     4042                 (long) rel->r_offset,
     4043                 howto->name,
     4044                 sym_name);
     4045              bfd_set_error (bfd_error_bad_value);
     4046              return FALSE;
     4047            }
    40384048        }
    40394049      else
     
    40424052                (info, sym_name, howto->name, (bfd_vma) 0,
    40434053                 input_bfd, input_section, rel->r_offset)))
    4044             return false;
    4045         }
    4046     }
    4047 
    4048   return true;
    4049 }
    4050 
    4051 /* Comparison function for qsort to sort unwind section during a
    4052    final link.  */
    4053 
    4054 static int
    4055 hppa_unwind_entry_compare (a, b)
    4056      const PTR a;
    4057      const PTR b;
    4058 {
    4059   const bfd_byte *ap, *bp;
    4060   unsigned long av, bv;
    4061 
    4062   ap = (const bfd_byte *) a;
    4063   av = (unsigned long) ap[0] << 24;
    4064   av |= (unsigned long) ap[1] << 16;
    4065   av |= (unsigned long) ap[2] << 8;
    4066   av |= (unsigned long) ap[3];
    4067 
    4068   bp = (const bfd_byte *) b;
    4069   bv = (unsigned long) bp[0] << 24;
    4070   bv |= (unsigned long) bp[1] << 16;
    4071   bv |= (unsigned long) bp[2] << 8;
    4072   bv |= (unsigned long) bp[3];
    4073 
    4074   return av < bv ? -1 : av > bv ? 1 : 0;
     4054            return FALSE;
     4055        }
     4056    }
     4057
     4058  return TRUE;
    40754059}
    40764060
     
    40784062   dynamic sections here.  */
    40794063
    4080 static boolean
     4064static bfd_boolean
    40814065elf32_hppa_finish_dynamic_symbol (output_bfd, info, h, sym)
    40824066     bfd *output_bfd;
     
    40854069     Elf_Internal_Sym *sym;
    40864070{
    4087   struct elf32_hppa_link_hash_table *hplink;
    4088   bfd *dynobj;
    4089 
    4090   hplink = hppa_link_hash_table (info);
    4091   dynobj = hplink->root.dynobj;
     4071  struct elf32_hppa_link_hash_table *htab;
     4072
     4073  htab = hppa_link_hash_table (info);
    40924074
    40934075  if (h->plt.offset != (bfd_vma) -1)
     
    41184100        {
    41194101          Elf_Internal_Rela rel;
     4102          bfd_byte *loc;
    41204103
    41214104          /* Create a dynamic IPLT relocation for this entry.  */
    41224105          rel.r_offset = (h->plt.offset
    4123                           + hplink->splt->output_offset
    4124                           + hplink->splt->output_section->vma);
    4125           if (! ((struct elf32_hppa_link_hash_entry *) h)->plt_abs
    4126               && h->dynindx != -1)
     4106                          + htab->splt->output_offset
     4107                          + htab->splt->output_section->vma);
     4108          if (h->dynindx != -1)
    41274109            {
    4128               /* To support lazy linking, the function pointer is
    4129                  initialised to point to a special stub stored at the
    4130                  end of the .plt.  This is not done for plt entries
    4131                  with a base-relative dynamic relocation.  */
    4132               value = (hplink->splt->output_offset
    4133                        + hplink->splt->output_section->vma
    4134                        + hplink->splt->_raw_size
    4135                        - sizeof (plt_stub)
    4136                        + PLT_STUB_ENTRY);
    41374110              rel.r_info = ELF32_R_INFO (h->dynindx, R_PARISC_IPLT);
    41384111              rel.r_addend = 0;
     
    41464119            }
    41474120
    4148           bfd_elf32_swap_reloca_out (hplink->splt->output_section->owner,
    4149                                      &rel,
    4150                                      ((Elf32_External_Rela *)
    4151                                       hplink->srelplt->contents
    4152                                       + hplink->srelplt->reloc_count));
    4153           hplink->srelplt->reloc_count++;
    4154         }
    4155 
    4156       bfd_put_32 (hplink->splt->owner,
    4157                   value,
    4158                   hplink->splt->contents + h->plt.offset);
    4159       bfd_put_32 (hplink->splt->owner,
    4160                   elf_gp (hplink->splt->output_section->owner),
    4161                   hplink->splt->contents + h->plt.offset + 4);
    4162       if (PLABEL_PLT_ENTRY_SIZE != PLT_ENTRY_SIZE
    4163           && ((struct elf32_hppa_link_hash_entry *) h)->plabel
    4164           && h->dynindx != -1)
    4165         {
    4166           memset (hplink->splt->contents + h->plt.offset + 8,
    4167                   0, PLABEL_PLT_ENTRY_SIZE - PLT_ENTRY_SIZE);
     4121          loc = htab->srelplt->contents;
     4122          loc += htab->srelplt->reloc_count++ * sizeof (Elf32_External_Rela);
     4123          bfd_elf32_swap_reloca_out (htab->splt->output_section->owner,
     4124                                     &rel, loc);
     4125        }
     4126      else
     4127        {
     4128          bfd_put_32 (htab->splt->owner,
     4129                      value,
     4130                      htab->splt->contents + h->plt.offset);
     4131          bfd_put_32 (htab->splt->owner,
     4132                      elf_gp (htab->splt->output_section->owner),
     4133                      htab->splt->contents + h->plt.offset + 4);
    41684134        }
    41694135
     
    41794145    {
    41804146      Elf_Internal_Rela rel;
     4147      bfd_byte *loc;
    41814148
    41824149      /* This symbol has an entry in the global offset table.  Set it
     
    41844151
    41854152      rel.r_offset = ((h->got.offset &~ (bfd_vma) 1)
    4186                       + hplink->sgot->output_offset
    4187                       + hplink->sgot->output_section->vma);
     4153                      + htab->sgot->output_offset
     4154                      + htab->sgot->output_section->vma);
    41884155
    41894156      /* If this is a -Bsymbolic link and the symbol is defined
     
    42064173            abort ();
    42074174          bfd_put_32 (output_bfd, (bfd_vma) 0,
    4208                       hplink->sgot->contents + h->got.offset);
     4175                      htab->sgot->contents + h->got.offset);
    42094176          rel.r_info = ELF32_R_INFO (h->dynindx, R_PARISC_DIR32);
    42104177          rel.r_addend = 0;
    42114178        }
    42124179
    4213       bfd_elf32_swap_reloca_out (output_bfd, &rel,
    4214                                  ((Elf32_External_Rela *)
    4215                                   hplink->srelgot->contents
    4216                                   + hplink->srelgot->reloc_count));
    4217       ++hplink->srelgot->reloc_count;
     4180      loc = htab->srelgot->contents;
     4181      loc += htab->srelgot->reloc_count++ * sizeof (Elf32_External_Rela);
     4182      bfd_elf32_swap_reloca_out (output_bfd, &rel, loc);
    42184183    }
    42194184
     
    42224187      asection *s;
    42234188      Elf_Internal_Rela rel;
     4189      bfd_byte *loc;
    42244190
    42254191      /* This symbol needs a copy reloc.  Set it up.  */
     
    42304196        abort ();
    42314197
    4232       s = hplink->srelbss;
     4198      s = htab->srelbss;
    42334199
    42344200      rel.r_offset = (h->root.u.def.value
     
    42374203      rel.r_addend = 0;
    42384204      rel.r_info = ELF32_R_INFO (h->dynindx, R_PARISC_COPY);
    4239       bfd_elf32_swap_reloca_out (output_bfd, &rel,
    4240                                  ((Elf32_External_Rela *) s->contents
    4241                                   + s->reloc_count));
    4242       ++s->reloc_count;
     4205      loc = s->contents + s->reloc_count++ * sizeof (Elf32_External_Rela);
     4206      bfd_elf32_swap_reloca_out (output_bfd, &rel, loc);
    42434207    }
    42444208
     
    42514215    }
    42524216
    4253   return true;
     4217  return TRUE;
    42544218}
    42554219
     4220/* Used to decide how to sort relocs in an optimal manner for the
     4221   dynamic linker, before writing them out.  */
     4222
     4223static enum elf_reloc_type_class
     4224elf32_hppa_reloc_type_class (rela)
     4225     const Elf_Internal_Rela *rela;
     4226{
     4227  if (ELF32_R_SYM (rela->r_info) == 0)
     4228    return reloc_class_relative;
     4229
     4230  switch ((int) ELF32_R_TYPE (rela->r_info))
     4231    {
     4232    case R_PARISC_IPLT:
     4233      return reloc_class_plt;
     4234    case R_PARISC_COPY:
     4235      return reloc_class_copy;
     4236    default:
     4237      return reloc_class_normal;
     4238    }
     4239}
     4240
    42564241/* Finish up the dynamic sections.  */
    42574242
    4258 static boolean
     4243static bfd_boolean
    42594244elf32_hppa_finish_dynamic_sections (output_bfd, info)
    42604245     bfd *output_bfd;
     
    42624247{
    42634248  bfd *dynobj;
    4264   struct elf32_hppa_link_hash_table *hplink;
     4249  struct elf32_hppa_link_hash_table *htab;
    42654250  asection *sdyn;
    42664251
    4267   hplink = hppa_link_hash_table (info);
    4268   dynobj = hplink->root.dynobj;
     4252  htab = hppa_link_hash_table (info);
     4253  dynobj = htab->elf.dynobj;
    42694254
    42704255  sdyn = bfd_get_section_by_name (dynobj, ".dynamic");
    42714256
    4272   if (hplink->root.dynamic_sections_created)
     4257  if (htab->elf.dynamic_sections_created)
    42734258    {
    42744259      Elf32_External_Dyn *dyncon, *dynconend;
     
    42894274            {
    42904275            default:
    4291               break;
     4276              continue;
    42924277
    42934278            case DT_PLTGOT:
    42944279              /* Use PLTGOT to set the GOT register.  */
    42954280              dyn.d_un.d_ptr = elf_gp (output_bfd);
    4296               bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon);
    42974281              break;
    42984282
    42994283            case DT_JMPREL:
    4300               s = hplink->srelplt;
     4284              s = htab->srelplt;
    43014285              dyn.d_un.d_ptr = s->output_section->vma + s->output_offset;
    4302               bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon);
    43034286              break;
    43044287
    43054288            case DT_PLTRELSZ:
    4306               s = hplink->srelplt;
    4307               if (s->_cooked_size != 0)
    4308                 dyn.d_un.d_val = s->_cooked_size;
    4309               else
    4310                 dyn.d_un.d_val = s->_raw_size;
    4311               bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon);
     4289              s = htab->srelplt;
     4290              dyn.d_un.d_val = s->_raw_size;
     4291              break;
     4292
     4293            case DT_RELASZ:
     4294              /* Don't count procedure linkage table relocs in the
     4295                 overall reloc count.  */
     4296              s = htab->srelplt;
     4297              if (s == NULL)
     4298                continue;
     4299              dyn.d_un.d_val -= s->_raw_size;
     4300              break;
     4301
     4302            case DT_RELA:
     4303              /* We may not be using the standard ELF linker script.
     4304                 If .rela.plt is the first .rela section, we adjust
     4305                 DT_RELA to not include it.  */
     4306              s = htab->srelplt;
     4307              if (s == NULL)
     4308                continue;
     4309              if (dyn.d_un.d_ptr != s->output_section->vma + s->output_offset)
     4310                continue;
     4311              dyn.d_un.d_ptr += s->_raw_size;
    43124312              break;
    43134313            }
    4314         }
    4315     }
    4316 
    4317   if (hplink->sgot->_raw_size != 0)
     4314
     4315          bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon);
     4316        }
     4317    }
     4318
     4319  if (htab->sgot != NULL && htab->sgot->_raw_size != 0)
    43184320    {
    43194321      /* Fill in the first entry in the global offset table.
     
    43234325                   ? sdyn->output_section->vma + sdyn->output_offset
    43244326                   : (bfd_vma) 0),
    4325                   hplink->sgot->contents);
     4327                  htab->sgot->contents);
    43264328
    43274329      /* The second entry is reserved for use by the dynamic linker.  */
    4328       memset (hplink->sgot->contents + GOT_ENTRY_SIZE, 0, GOT_ENTRY_SIZE);
     4330      memset (htab->sgot->contents + GOT_ENTRY_SIZE, 0, GOT_ENTRY_SIZE);
    43294331
    43304332      /* Set .got entry size.  */
    4331       elf_section_data (hplink->sgot->output_section)
     4333      elf_section_data (htab->sgot->output_section)
    43324334        ->this_hdr.sh_entsize = GOT_ENTRY_SIZE;
    43334335    }
    43344336
    4335   if (hplink->splt->_raw_size != 0)
     4337  if (htab->splt != NULL && htab->splt->_raw_size != 0)
    43364338    {
    43374339      /* Set plt entry size.  */
    4338       elf_section_data (hplink->splt->output_section)
     4340      elf_section_data (htab->splt->output_section)
    43394341        ->this_hdr.sh_entsize = PLT_ENTRY_SIZE;
    43404342
    4341       if (hplink->need_plt_stub)
     4343      if (htab->need_plt_stub)
    43424344        {
    43434345          /* Set up the .plt stub.  */
    4344           memcpy (hplink->splt->contents
    4345                   + hplink->splt->_raw_size - sizeof (plt_stub),
     4346          memcpy (htab->splt->contents
     4347                  + htab->splt->_raw_size - sizeof (plt_stub),
    43464348                  plt_stub, sizeof (plt_stub));
    43474349
    4348           if ((hplink->splt->output_offset
    4349                + hplink->splt->output_section->vma
    4350                + hplink->splt->_raw_size)
    4351               != (hplink->sgot->output_offset
    4352                   + hplink->sgot->output_section->vma))
     4350          if ((htab->splt->output_offset
     4351               + htab->splt->output_section->vma
     4352               + htab->splt->_raw_size)
     4353              != (htab->sgot->output_offset
     4354                  + htab->sgot->output_section->vma))
    43534355            {
    43544356              (*_bfd_error_handler)
    43554357                (_(".got section not immediately after .plt section"));
    4356               return false;
     4358              return FALSE;
    43574359            }
    43584360        }
    43594361    }
    43604362
    4361   return true;
     4363  return TRUE;
    43624364}
    43634365
     
    44054407#define bfd_elf32_bfd_final_link             elf32_hppa_final_link
    44064408#define bfd_elf32_bfd_link_hash_table_create elf32_hppa_link_hash_table_create
     4409#define bfd_elf32_bfd_link_hash_table_free   elf32_hppa_link_hash_table_free
    44074410#define elf_backend_add_symbol_hook          elf32_hppa_add_symbol_hook
    44084411#define elf_backend_adjust_dynamic_symbol    elf32_hppa_adjust_dynamic_symbol
     4412#define elf_backend_copy_indirect_symbol     elf32_hppa_copy_indirect_symbol
    44094413#define elf_backend_check_relocs             elf32_hppa_check_relocs
    44104414#define elf_backend_create_dynamic_sections  elf32_hppa_create_dynamic_sections
     
    44214425#define elf_backend_post_process_headers     elf32_hppa_post_process_headers
    44224426#define elf_backend_get_symbol_type          elf32_hppa_elf_get_symbol_type
     4427#define elf_backend_reloc_type_class         elf32_hppa_reloc_type_class
    44234428
    44244429#define elf_backend_can_gc_sections          1
     4430#define elf_backend_can_refcount             1
    44254431#define elf_backend_plt_alignment            2
    44264432#define elf_backend_want_got_plt             0
     
    44284434#define elf_backend_want_plt_sym             0
    44294435#define elf_backend_got_header_size          8
     4436#define elf_backend_rela_normal              1
    44304437
    44314438#define TARGET_BIG_SYM          bfd_elf32_hppa_vec
Note: See TracChangeset for help on using the changeset viewer.