Home | History | Annotate | Line # | Download | only in bfd
elf32-hppa.c revision 1.1
      1  1.1  skrll /* BFD back-end for HP PA-RISC ELF files.
      2  1.1  skrll    Copyright 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1999, 2000, 2001,
      3  1.1  skrll    2002, 2003, 2004, 2005, 2006, 2007, 2008
      4  1.1  skrll    Free Software Foundation, Inc.
      5  1.1  skrll 
      6  1.1  skrll    Original code by
      7  1.1  skrll 	Center for Software Science
      8  1.1  skrll 	Department of Computer Science
      9  1.1  skrll 	University of Utah
     10  1.1  skrll    Largely rewritten by Alan Modra <alan (at) linuxcare.com.au>
     11  1.1  skrll    Naming cleanup by Carlos O'Donell <carlos (at) systemhalted.org>
     12  1.1  skrll    TLS support written by Randolph Chung <tausq (at) debian.org>
     13  1.1  skrll 
     14  1.1  skrll    This file is part of BFD, the Binary File Descriptor library.
     15  1.1  skrll 
     16  1.1  skrll    This program is free software; you can redistribute it and/or modify
     17  1.1  skrll    it under the terms of the GNU General Public License as published by
     18  1.1  skrll    the Free Software Foundation; either version 3 of the License, or
     19  1.1  skrll    (at your option) any later version.
     20  1.1  skrll 
     21  1.1  skrll    This program is distributed in the hope that it will be useful,
     22  1.1  skrll    but WITHOUT ANY WARRANTY; without even the implied warranty of
     23  1.1  skrll    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     24  1.1  skrll    GNU General Public License for more details.
     25  1.1  skrll 
     26  1.1  skrll    You should have received a copy of the GNU General Public License
     27  1.1  skrll    along with this program; if not, write to the Free Software
     28  1.1  skrll    Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
     29  1.1  skrll    MA 02110-1301, USA.  */
     30  1.1  skrll 
     31  1.1  skrll #include "sysdep.h"
     32  1.1  skrll #include "bfd.h"
     33  1.1  skrll #include "libbfd.h"
     34  1.1  skrll #include "elf-bfd.h"
     35  1.1  skrll #include "elf/hppa.h"
     36  1.1  skrll #include "libhppa.h"
     37  1.1  skrll #include "elf32-hppa.h"
     38  1.1  skrll #define ARCH_SIZE		32
     39  1.1  skrll #include "elf32-hppa.h"
     40  1.1  skrll #include "elf-hppa.h"
     41  1.1  skrll 
     42  1.1  skrll /* In order to gain some understanding of code in this file without
     43  1.1  skrll    knowing all the intricate details of the linker, note the
     44  1.1  skrll    following:
     45  1.1  skrll 
     46  1.1  skrll    Functions named elf32_hppa_* are called by external routines, other
     47  1.1  skrll    functions are only called locally.  elf32_hppa_* functions appear
     48  1.1  skrll    in this file more or less in the order in which they are called
     49  1.1  skrll    from external routines.  eg. elf32_hppa_check_relocs is called
     50  1.1  skrll    early in the link process, elf32_hppa_finish_dynamic_sections is
     51  1.1  skrll    one of the last functions.  */
     52  1.1  skrll 
     53  1.1  skrll /* We use two hash tables to hold information for linking PA ELF objects.
     54  1.1  skrll 
     55  1.1  skrll    The first is the elf32_hppa_link_hash_table which is derived
     56  1.1  skrll    from the standard ELF linker hash table.  We use this as a place to
     57  1.1  skrll    attach other hash tables and static information.
     58  1.1  skrll 
     59  1.1  skrll    The second is the stub hash table which is derived from the
     60  1.1  skrll    base BFD hash table.  The stub hash table holds the information
     61  1.1  skrll    necessary to build the linker stubs during a link.
     62  1.1  skrll 
     63  1.1  skrll    There are a number of different stubs generated by the linker.
     64  1.1  skrll 
     65  1.1  skrll    Long branch stub:
     66  1.1  skrll    :		ldil LR'X,%r1
     67  1.1  skrll    :		be,n RR'X(%sr4,%r1)
     68  1.1  skrll 
     69  1.1  skrll    PIC long branch stub:
     70  1.1  skrll    :		b,l .+8,%r1
     71  1.1  skrll    :		addil LR'X - ($PIC_pcrel$0 - 4),%r1
     72  1.1  skrll    :		be,n RR'X - ($PIC_pcrel$0 - 8)(%sr4,%r1)
     73  1.1  skrll 
     74  1.1  skrll    Import stub to call shared library routine from normal object file
     75  1.1  skrll    (single sub-space version)
     76  1.1  skrll    :		addil LR'lt_ptr+ltoff,%dp	; get procedure entry point
     77  1.1  skrll    :		ldw RR'lt_ptr+ltoff(%r1),%r21
     78  1.1  skrll    :		bv %r0(%r21)
     79  1.1  skrll    :		ldw RR'lt_ptr+ltoff+4(%r1),%r19	; get new dlt value.
     80  1.1  skrll 
     81  1.1  skrll    Import stub to call shared library routine from shared library
     82  1.1  skrll    (single sub-space version)
     83  1.1  skrll    :		addil LR'ltoff,%r19		; get procedure entry point
     84  1.1  skrll    :		ldw RR'ltoff(%r1),%r21
     85  1.1  skrll    :		bv %r0(%r21)
     86  1.1  skrll    :		ldw RR'ltoff+4(%r1),%r19	; get new dlt value.
     87  1.1  skrll 
     88  1.1  skrll    Import stub to call shared library routine from normal object file
     89  1.1  skrll    (multiple sub-space support)
     90  1.1  skrll    :		addil LR'lt_ptr+ltoff,%dp	; get procedure entry point
     91  1.1  skrll    :		ldw RR'lt_ptr+ltoff(%r1),%r21
     92  1.1  skrll    :		ldw RR'lt_ptr+ltoff+4(%r1),%r19	; get new dlt value.
     93  1.1  skrll    :		ldsid (%r21),%r1
     94  1.1  skrll    :		mtsp %r1,%sr0
     95  1.1  skrll    :		be 0(%sr0,%r21)			; branch to target
     96  1.1  skrll    :		stw %rp,-24(%sp)		; save rp
     97  1.1  skrll 
     98  1.1  skrll    Import stub to call shared library routine from shared library
     99  1.1  skrll    (multiple sub-space support)
    100  1.1  skrll    :		addil LR'ltoff,%r19		; get procedure entry point
    101  1.1  skrll    :		ldw RR'ltoff(%r1),%r21
    102  1.1  skrll    :		ldw RR'ltoff+4(%r1),%r19	; get new dlt value.
    103  1.1  skrll    :		ldsid (%r21),%r1
    104  1.1  skrll    :		mtsp %r1,%sr0
    105  1.1  skrll    :		be 0(%sr0,%r21)			; branch to target
    106  1.1  skrll    :		stw %rp,-24(%sp)		; save rp
    107  1.1  skrll 
    108  1.1  skrll    Export stub to return from shared lib routine (multiple sub-space support)
    109  1.1  skrll    One of these is created for each exported procedure in a shared
    110  1.1  skrll    library (and stored in the shared lib).  Shared lib routines are
    111  1.1  skrll    called via the first instruction in the export stub so that we can
    112  1.1  skrll    do an inter-space return.  Not required for single sub-space.
    113  1.1  skrll    :		bl,n X,%rp			; trap the return
    114  1.1  skrll    :		nop
    115  1.1  skrll    :		ldw -24(%sp),%rp		; restore the original rp
    116  1.1  skrll    :		ldsid (%rp),%r1
    117  1.1  skrll    :		mtsp %r1,%sr0
    118  1.1  skrll    :		be,n 0(%sr0,%rp)		; inter-space return.  */
    119  1.1  skrll 
    120  1.1  skrll 
    121  1.1  skrll /* Variable names follow a coding style.
    122  1.1  skrll    Please follow this (Apps Hungarian) style:
    123  1.1  skrll 
    124  1.1  skrll    Structure/Variable         		Prefix
    125  1.1  skrll    elf_link_hash_table			"etab"
    126  1.1  skrll    elf_link_hash_entry			"eh"
    127  1.1  skrll 
    128  1.1  skrll    elf32_hppa_link_hash_table		"htab"
    129  1.1  skrll    elf32_hppa_link_hash_entry		"hh"
    130  1.1  skrll 
    131  1.1  skrll    bfd_hash_table			"btab"
    132  1.1  skrll    bfd_hash_entry			"bh"
    133  1.1  skrll 
    134  1.1  skrll    bfd_hash_table containing stubs	"bstab"
    135  1.1  skrll    elf32_hppa_stub_hash_entry		"hsh"
    136  1.1  skrll 
    137  1.1  skrll    elf32_hppa_dyn_reloc_entry		"hdh"
    138  1.1  skrll 
    139  1.1  skrll    Always remember to use GNU Coding Style. */
    140  1.1  skrll 
    141  1.1  skrll #define PLT_ENTRY_SIZE 8
    142  1.1  skrll #define GOT_ENTRY_SIZE 4
    143  1.1  skrll #define ELF_DYNAMIC_INTERPRETER "/lib/ld.so.1"
    144  1.1  skrll 
    145  1.1  skrll static const bfd_byte plt_stub[] =
    146  1.1  skrll {
    147  1.1  skrll   0x0e, 0x80, 0x10, 0x96,  /* 1: ldw	0(%r20),%r22		*/
    148  1.1  skrll   0xea, 0xc0, 0xc0, 0x00,  /*    bv	%r0(%r22)		*/
    149  1.1  skrll   0x0e, 0x88, 0x10, 0x95,  /*    ldw	4(%r20),%r21		*/
    150  1.1  skrll #define PLT_STUB_ENTRY (3*4)
    151  1.1  skrll   0xea, 0x9f, 0x1f, 0xdd,  /*    b,l	1b,%r20			*/
    152  1.1  skrll   0xd6, 0x80, 0x1c, 0x1e,  /*    depi	0,31,2,%r20		*/
    153  1.1  skrll   0x00, 0xc0, 0xff, 0xee,  /* 9: .word	fixup_func		*/
    154  1.1  skrll   0xde, 0xad, 0xbe, 0xef   /*    .word	fixup_ltp		*/
    155  1.1  skrll };
    156  1.1  skrll 
    157  1.1  skrll /* Section name for stubs is the associated section name plus this
    158  1.1  skrll    string.  */
    159  1.1  skrll #define STUB_SUFFIX ".stub"
    160  1.1  skrll 
    161  1.1  skrll /* We don't need to copy certain PC- or GP-relative dynamic relocs
    162  1.1  skrll    into a shared object's dynamic section.  All the relocs of the
    163  1.1  skrll    limited class we are interested in, are absolute.  */
    164  1.1  skrll #ifndef RELATIVE_DYNRELOCS
    165  1.1  skrll #define RELATIVE_DYNRELOCS 0
    166  1.1  skrll #define IS_ABSOLUTE_RELOC(r_type) 1
    167  1.1  skrll #endif
    168  1.1  skrll 
    169  1.1  skrll /* If ELIMINATE_COPY_RELOCS is non-zero, the linker will try to avoid
    170  1.1  skrll    copying dynamic variables from a shared lib into an app's dynbss
    171  1.1  skrll    section, and instead use a dynamic relocation to point into the
    172  1.1  skrll    shared lib.  */
    173  1.1  skrll #define ELIMINATE_COPY_RELOCS 1
    174  1.1  skrll 
    175  1.1  skrll enum elf32_hppa_stub_type
    176  1.1  skrll {
    177  1.1  skrll   hppa_stub_long_branch,
    178  1.1  skrll   hppa_stub_long_branch_shared,
    179  1.1  skrll   hppa_stub_import,
    180  1.1  skrll   hppa_stub_import_shared,
    181  1.1  skrll   hppa_stub_export,
    182  1.1  skrll   hppa_stub_none
    183  1.1  skrll };
    184  1.1  skrll 
    185  1.1  skrll struct elf32_hppa_stub_hash_entry
    186  1.1  skrll {
    187  1.1  skrll   /* Base hash table entry structure.  */
    188  1.1  skrll   struct bfd_hash_entry bh_root;
    189  1.1  skrll 
    190  1.1  skrll   /* The stub section.  */
    191  1.1  skrll   asection *stub_sec;
    192  1.1  skrll 
    193  1.1  skrll   /* Offset within stub_sec of the beginning of this stub.  */
    194  1.1  skrll   bfd_vma stub_offset;
    195  1.1  skrll 
    196  1.1  skrll   /* Given the symbol's value and its section we can determine its final
    197  1.1  skrll      value when building the stubs (so the stub knows where to jump.  */
    198  1.1  skrll   bfd_vma target_value;
    199  1.1  skrll   asection *target_section;
    200  1.1  skrll 
    201  1.1  skrll   enum elf32_hppa_stub_type stub_type;
    202  1.1  skrll 
    203  1.1  skrll   /* The symbol table entry, if any, that this was derived from.  */
    204  1.1  skrll   struct elf32_hppa_link_hash_entry *hh;
    205  1.1  skrll 
    206  1.1  skrll   /* Where this stub is being called from, or, in the case of combined
    207  1.1  skrll      stub sections, the first input section in the group.  */
    208  1.1  skrll   asection *id_sec;
    209  1.1  skrll };
    210  1.1  skrll 
    211  1.1  skrll struct elf32_hppa_link_hash_entry
    212  1.1  skrll {
    213  1.1  skrll   struct elf_link_hash_entry eh;
    214  1.1  skrll 
    215  1.1  skrll   /* A pointer to the most recently used stub hash entry against this
    216  1.1  skrll      symbol.  */
    217  1.1  skrll   struct elf32_hppa_stub_hash_entry *hsh_cache;
    218  1.1  skrll 
    219  1.1  skrll   /* Used to count relocations for delayed sizing of relocation
    220  1.1  skrll      sections.  */
    221  1.1  skrll   struct elf32_hppa_dyn_reloc_entry
    222  1.1  skrll   {
    223  1.1  skrll     /* Next relocation in the chain.  */
    224  1.1  skrll     struct elf32_hppa_dyn_reloc_entry *hdh_next;
    225  1.1  skrll 
    226  1.1  skrll     /* The input section of the reloc.  */
    227  1.1  skrll     asection *sec;
    228  1.1  skrll 
    229  1.1  skrll     /* Number of relocs copied in this section.  */
    230  1.1  skrll     bfd_size_type count;
    231  1.1  skrll 
    232  1.1  skrll #if RELATIVE_DYNRELOCS
    233  1.1  skrll   /* Number of relative relocs copied for the input section.  */
    234  1.1  skrll     bfd_size_type relative_count;
    235  1.1  skrll #endif
    236  1.1  skrll   } *dyn_relocs;
    237  1.1  skrll 
    238  1.1  skrll   enum
    239  1.1  skrll   {
    240  1.1  skrll     GOT_UNKNOWN = 0, GOT_NORMAL = 1, GOT_TLS_GD = 2, GOT_TLS_LDM = 4, GOT_TLS_IE = 8
    241  1.1  skrll   } tls_type;
    242  1.1  skrll 
    243  1.1  skrll   /* Set if this symbol is used by a plabel reloc.  */
    244  1.1  skrll   unsigned int plabel:1;
    245  1.1  skrll };
    246  1.1  skrll 
    247  1.1  skrll struct elf32_hppa_link_hash_table
    248  1.1  skrll {
    249  1.1  skrll   /* The main hash table.  */
    250  1.1  skrll   struct elf_link_hash_table etab;
    251  1.1  skrll 
    252  1.1  skrll   /* The stub hash table.  */
    253  1.1  skrll   struct bfd_hash_table bstab;
    254  1.1  skrll 
    255  1.1  skrll   /* Linker stub bfd.  */
    256  1.1  skrll   bfd *stub_bfd;
    257  1.1  skrll 
    258  1.1  skrll   /* Linker call-backs.  */
    259  1.1  skrll   asection * (*add_stub_section) (const char *, asection *);
    260  1.1  skrll   void (*layout_sections_again) (void);
    261  1.1  skrll 
    262  1.1  skrll   /* Array to keep track of which stub sections have been created, and
    263  1.1  skrll      information on stub grouping.  */
    264  1.1  skrll   struct map_stub
    265  1.1  skrll   {
    266  1.1  skrll     /* This is the section to which stubs in the group will be
    267  1.1  skrll        attached.  */
    268  1.1  skrll     asection *link_sec;
    269  1.1  skrll     /* The stub section.  */
    270  1.1  skrll     asection *stub_sec;
    271  1.1  skrll   } *stub_group;
    272  1.1  skrll 
    273  1.1  skrll   /* Assorted information used by elf32_hppa_size_stubs.  */
    274  1.1  skrll   unsigned int bfd_count;
    275  1.1  skrll   int top_index;
    276  1.1  skrll   asection **input_list;
    277  1.1  skrll   Elf_Internal_Sym **all_local_syms;
    278  1.1  skrll 
    279  1.1  skrll   /* Short-cuts to get to dynamic linker sections.  */
    280  1.1  skrll   asection *sgot;
    281  1.1  skrll   asection *srelgot;
    282  1.1  skrll   asection *splt;
    283  1.1  skrll   asection *srelplt;
    284  1.1  skrll   asection *sdynbss;
    285  1.1  skrll   asection *srelbss;
    286  1.1  skrll 
    287  1.1  skrll   /* Used during a final link to store the base of the text and data
    288  1.1  skrll      segments so that we can perform SEGREL relocations.  */
    289  1.1  skrll   bfd_vma text_segment_base;
    290  1.1  skrll   bfd_vma data_segment_base;
    291  1.1  skrll 
    292  1.1  skrll   /* Whether we support multiple sub-spaces for shared libs.  */
    293  1.1  skrll   unsigned int multi_subspace:1;
    294  1.1  skrll 
    295  1.1  skrll   /* Flags set when various size branches are detected.  Used to
    296  1.1  skrll      select suitable defaults for the stub group size.  */
    297  1.1  skrll   unsigned int has_12bit_branch:1;
    298  1.1  skrll   unsigned int has_17bit_branch:1;
    299  1.1  skrll   unsigned int has_22bit_branch:1;
    300  1.1  skrll 
    301  1.1  skrll   /* Set if we need a .plt stub to support lazy dynamic linking.  */
    302  1.1  skrll   unsigned int need_plt_stub:1;
    303  1.1  skrll 
    304  1.1  skrll   /* Small local sym to section mapping cache.  */
    305  1.1  skrll   struct sym_sec_cache sym_sec;
    306  1.1  skrll 
    307  1.1  skrll   /* Data for LDM relocations.  */
    308  1.1  skrll   union
    309  1.1  skrll   {
    310  1.1  skrll     bfd_signed_vma refcount;
    311  1.1  skrll     bfd_vma offset;
    312  1.1  skrll   } tls_ldm_got;
    313  1.1  skrll };
    314  1.1  skrll 
    315  1.1  skrll /* Various hash macros and functions.  */
    316  1.1  skrll #define hppa_link_hash_table(p) \
    317  1.1  skrll   ((struct elf32_hppa_link_hash_table *) ((p)->hash))
    318  1.1  skrll 
    319  1.1  skrll #define hppa_elf_hash_entry(ent) \
    320  1.1  skrll   ((struct elf32_hppa_link_hash_entry *)(ent))
    321  1.1  skrll 
    322  1.1  skrll #define hppa_stub_hash_entry(ent) \
    323  1.1  skrll   ((struct elf32_hppa_stub_hash_entry *)(ent))
    324  1.1  skrll 
    325  1.1  skrll #define hppa_stub_hash_lookup(table, string, create, copy) \
    326  1.1  skrll   ((struct elf32_hppa_stub_hash_entry *) \
    327  1.1  skrll    bfd_hash_lookup ((table), (string), (create), (copy)))
    328  1.1  skrll 
    329  1.1  skrll #define hppa_elf_local_got_tls_type(abfd) \
    330  1.1  skrll   ((char *)(elf_local_got_offsets (abfd) + (elf_tdata (abfd)->symtab_hdr.sh_info * 2)))
    331  1.1  skrll 
    332  1.1  skrll #define hh_name(hh) \
    333  1.1  skrll   (hh ? hh->eh.root.root.string : "<undef>")
    334  1.1  skrll 
    335  1.1  skrll #define eh_name(eh) \
    336  1.1  skrll   (eh ? eh->root.root.string : "<undef>")
    337  1.1  skrll 
    338  1.1  skrll /* Override the generic function because we want to mark our BFDs.  */
    339  1.1  skrll 
    340  1.1  skrll static bfd_boolean
    341  1.1  skrll elf32_hppa_mkobject (bfd *abfd)
    342  1.1  skrll {
    343  1.1  skrll   return bfd_elf_allocate_object (abfd, sizeof (struct elf_obj_tdata),
    344  1.1  skrll 				  HPPA_ELF_TDATA);
    345  1.1  skrll }
    346  1.1  skrll 
    347  1.1  skrll /* Assorted hash table functions.  */
    348  1.1  skrll 
    349  1.1  skrll /* Initialize an entry in the stub hash table.  */
    350  1.1  skrll 
    351  1.1  skrll static struct bfd_hash_entry *
    352  1.1  skrll stub_hash_newfunc (struct bfd_hash_entry *entry,
    353  1.1  skrll 		   struct bfd_hash_table *table,
    354  1.1  skrll 		   const char *string)
    355  1.1  skrll {
    356  1.1  skrll   /* Allocate the structure if it has not already been allocated by a
    357  1.1  skrll      subclass.  */
    358  1.1  skrll   if (entry == NULL)
    359  1.1  skrll     {
    360  1.1  skrll       entry = bfd_hash_allocate (table,
    361  1.1  skrll 				 sizeof (struct elf32_hppa_stub_hash_entry));
    362  1.1  skrll       if (entry == NULL)
    363  1.1  skrll 	return entry;
    364  1.1  skrll     }
    365  1.1  skrll 
    366  1.1  skrll   /* Call the allocation method of the superclass.  */
    367  1.1  skrll   entry = bfd_hash_newfunc (entry, table, string);
    368  1.1  skrll   if (entry != NULL)
    369  1.1  skrll     {
    370  1.1  skrll       struct elf32_hppa_stub_hash_entry *hsh;
    371  1.1  skrll 
    372  1.1  skrll       /* Initialize the local fields.  */
    373  1.1  skrll       hsh = hppa_stub_hash_entry (entry);
    374  1.1  skrll       hsh->stub_sec = NULL;
    375  1.1  skrll       hsh->stub_offset = 0;
    376  1.1  skrll       hsh->target_value = 0;
    377  1.1  skrll       hsh->target_section = NULL;
    378  1.1  skrll       hsh->stub_type = hppa_stub_long_branch;
    379  1.1  skrll       hsh->hh = NULL;
    380  1.1  skrll       hsh->id_sec = NULL;
    381  1.1  skrll     }
    382  1.1  skrll 
    383  1.1  skrll   return entry;
    384  1.1  skrll }
    385  1.1  skrll 
    386  1.1  skrll /* Initialize an entry in the link hash table.  */
    387  1.1  skrll 
    388  1.1  skrll static struct bfd_hash_entry *
    389  1.1  skrll hppa_link_hash_newfunc (struct bfd_hash_entry *entry,
    390  1.1  skrll 			struct bfd_hash_table *table,
    391  1.1  skrll 			const char *string)
    392  1.1  skrll {
    393  1.1  skrll   /* Allocate the structure if it has not already been allocated by a
    394  1.1  skrll      subclass.  */
    395  1.1  skrll   if (entry == NULL)
    396  1.1  skrll     {
    397  1.1  skrll       entry = bfd_hash_allocate (table,
    398  1.1  skrll 				 sizeof (struct elf32_hppa_link_hash_entry));
    399  1.1  skrll       if (entry == NULL)
    400  1.1  skrll 	return entry;
    401  1.1  skrll     }
    402  1.1  skrll 
    403  1.1  skrll   /* Call the allocation method of the superclass.  */
    404  1.1  skrll   entry = _bfd_elf_link_hash_newfunc (entry, table, string);
    405  1.1  skrll   if (entry != NULL)
    406  1.1  skrll     {
    407  1.1  skrll       struct elf32_hppa_link_hash_entry *hh;
    408  1.1  skrll 
    409  1.1  skrll       /* Initialize the local fields.  */
    410  1.1  skrll       hh = hppa_elf_hash_entry (entry);
    411  1.1  skrll       hh->hsh_cache = NULL;
    412  1.1  skrll       hh->dyn_relocs = NULL;
    413  1.1  skrll       hh->plabel = 0;
    414  1.1  skrll       hh->tls_type = GOT_UNKNOWN;
    415  1.1  skrll     }
    416  1.1  skrll 
    417  1.1  skrll   return entry;
    418  1.1  skrll }
    419  1.1  skrll 
    420  1.1  skrll /* Create the derived linker hash table.  The PA ELF port uses the derived
    421  1.1  skrll    hash table to keep information specific to the PA ELF linker (without
    422  1.1  skrll    using static variables).  */
    423  1.1  skrll 
    424  1.1  skrll static struct bfd_link_hash_table *
    425  1.1  skrll elf32_hppa_link_hash_table_create (bfd *abfd)
    426  1.1  skrll {
    427  1.1  skrll   struct elf32_hppa_link_hash_table *htab;
    428  1.1  skrll   bfd_size_type amt = sizeof (*htab);
    429  1.1  skrll 
    430  1.1  skrll   htab = bfd_malloc (amt);
    431  1.1  skrll   if (htab == NULL)
    432  1.1  skrll     return NULL;
    433  1.1  skrll 
    434  1.1  skrll   if (!_bfd_elf_link_hash_table_init (&htab->etab, abfd, hppa_link_hash_newfunc,
    435  1.1  skrll 				      sizeof (struct elf32_hppa_link_hash_entry)))
    436  1.1  skrll     {
    437  1.1  skrll       free (htab);
    438  1.1  skrll       return NULL;
    439  1.1  skrll     }
    440  1.1  skrll 
    441  1.1  skrll   /* Init the stub hash table too.  */
    442  1.1  skrll   if (!bfd_hash_table_init (&htab->bstab, stub_hash_newfunc,
    443  1.1  skrll 			    sizeof (struct elf32_hppa_stub_hash_entry)))
    444  1.1  skrll     return NULL;
    445  1.1  skrll 
    446  1.1  skrll   htab->stub_bfd = NULL;
    447  1.1  skrll   htab->add_stub_section = NULL;
    448  1.1  skrll   htab->layout_sections_again = NULL;
    449  1.1  skrll   htab->stub_group = NULL;
    450  1.1  skrll   htab->sgot = NULL;
    451  1.1  skrll   htab->srelgot = NULL;
    452  1.1  skrll   htab->splt = NULL;
    453  1.1  skrll   htab->srelplt = NULL;
    454  1.1  skrll   htab->sdynbss = NULL;
    455  1.1  skrll   htab->srelbss = NULL;
    456  1.1  skrll   htab->text_segment_base = (bfd_vma) -1;
    457  1.1  skrll   htab->data_segment_base = (bfd_vma) -1;
    458  1.1  skrll   htab->multi_subspace = 0;
    459  1.1  skrll   htab->has_12bit_branch = 0;
    460  1.1  skrll   htab->has_17bit_branch = 0;
    461  1.1  skrll   htab->has_22bit_branch = 0;
    462  1.1  skrll   htab->need_plt_stub = 0;
    463  1.1  skrll   htab->sym_sec.abfd = NULL;
    464  1.1  skrll   htab->tls_ldm_got.refcount = 0;
    465  1.1  skrll 
    466  1.1  skrll   return &htab->etab.root;
    467  1.1  skrll }
    468  1.1  skrll 
    469  1.1  skrll /* Free the derived linker hash table.  */
    470  1.1  skrll 
    471  1.1  skrll static void
    472  1.1  skrll elf32_hppa_link_hash_table_free (struct bfd_link_hash_table *btab)
    473  1.1  skrll {
    474  1.1  skrll   struct elf32_hppa_link_hash_table *htab
    475  1.1  skrll     = (struct elf32_hppa_link_hash_table *) btab;
    476  1.1  skrll 
    477  1.1  skrll   bfd_hash_table_free (&htab->bstab);
    478  1.1  skrll   _bfd_generic_link_hash_table_free (btab);
    479  1.1  skrll }
    480  1.1  skrll 
    481  1.1  skrll /* Build a name for an entry in the stub hash table.  */
    482  1.1  skrll 
    483  1.1  skrll static char *
    484  1.1  skrll hppa_stub_name (const asection *input_section,
    485  1.1  skrll 		const asection *sym_sec,
    486  1.1  skrll 		const struct elf32_hppa_link_hash_entry *hh,
    487  1.1  skrll 		const Elf_Internal_Rela *rela)
    488  1.1  skrll {
    489  1.1  skrll   char *stub_name;
    490  1.1  skrll   bfd_size_type len;
    491  1.1  skrll 
    492  1.1  skrll   if (hh)
    493  1.1  skrll     {
    494  1.1  skrll       len = 8 + 1 + strlen (hh_name (hh)) + 1 + 8 + 1;
    495  1.1  skrll       stub_name = bfd_malloc (len);
    496  1.1  skrll       if (stub_name != NULL)
    497  1.1  skrll 	sprintf (stub_name, "%08x_%s+%x",
    498  1.1  skrll 		 input_section->id & 0xffffffff,
    499  1.1  skrll 		 hh_name (hh),
    500  1.1  skrll 		 (int) rela->r_addend & 0xffffffff);
    501  1.1  skrll     }
    502  1.1  skrll   else
    503  1.1  skrll     {
    504  1.1  skrll       len = 8 + 1 + 8 + 1 + 8 + 1 + 8 + 1;
    505  1.1  skrll       stub_name = bfd_malloc (len);
    506  1.1  skrll       if (stub_name != NULL)
    507  1.1  skrll 	sprintf (stub_name, "%08x_%x:%x+%x",
    508  1.1  skrll 		 input_section->id & 0xffffffff,
    509  1.1  skrll 		 sym_sec->id & 0xffffffff,
    510  1.1  skrll 		 (int) ELF32_R_SYM (rela->r_info) & 0xffffffff,
    511  1.1  skrll 		 (int) rela->r_addend & 0xffffffff);
    512  1.1  skrll     }
    513  1.1  skrll   return stub_name;
    514  1.1  skrll }
    515  1.1  skrll 
    516  1.1  skrll /* Look up an entry in the stub hash.  Stub entries are cached because
    517  1.1  skrll    creating the stub name takes a bit of time.  */
    518  1.1  skrll 
    519  1.1  skrll static struct elf32_hppa_stub_hash_entry *
    520  1.1  skrll hppa_get_stub_entry (const asection *input_section,
    521  1.1  skrll 		     const asection *sym_sec,
    522  1.1  skrll 		     struct elf32_hppa_link_hash_entry *hh,
    523  1.1  skrll 		     const Elf_Internal_Rela *rela,
    524  1.1  skrll 		     struct elf32_hppa_link_hash_table *htab)
    525  1.1  skrll {
    526  1.1  skrll   struct elf32_hppa_stub_hash_entry *hsh_entry;
    527  1.1  skrll   const asection *id_sec;
    528  1.1  skrll 
    529  1.1  skrll   /* If this input section is part of a group of sections sharing one
    530  1.1  skrll      stub section, then use the id of the first section in the group.
    531  1.1  skrll      Stub names need to include a section id, as there may well be
    532  1.1  skrll      more than one stub used to reach say, printf, and we need to
    533  1.1  skrll      distinguish between them.  */
    534  1.1  skrll   id_sec = htab->stub_group[input_section->id].link_sec;
    535  1.1  skrll 
    536  1.1  skrll   if (hh != NULL && hh->hsh_cache != NULL
    537  1.1  skrll       && hh->hsh_cache->hh == hh
    538  1.1  skrll       && hh->hsh_cache->id_sec == id_sec)
    539  1.1  skrll     {
    540  1.1  skrll       hsh_entry = hh->hsh_cache;
    541  1.1  skrll     }
    542  1.1  skrll   else
    543  1.1  skrll     {
    544  1.1  skrll       char *stub_name;
    545  1.1  skrll 
    546  1.1  skrll       stub_name = hppa_stub_name (id_sec, sym_sec, hh, rela);
    547  1.1  skrll       if (stub_name == NULL)
    548  1.1  skrll 	return NULL;
    549  1.1  skrll 
    550  1.1  skrll       hsh_entry = hppa_stub_hash_lookup (&htab->bstab,
    551  1.1  skrll 					  stub_name, FALSE, FALSE);
    552  1.1  skrll       if (hh != NULL)
    553  1.1  skrll 	hh->hsh_cache = hsh_entry;
    554  1.1  skrll 
    555  1.1  skrll       free (stub_name);
    556  1.1  skrll     }
    557  1.1  skrll 
    558  1.1  skrll   return hsh_entry;
    559  1.1  skrll }
    560  1.1  skrll 
    561  1.1  skrll /* Add a new stub entry to the stub hash.  Not all fields of the new
    562  1.1  skrll    stub entry are initialised.  */
    563  1.1  skrll 
    564  1.1  skrll static struct elf32_hppa_stub_hash_entry *
    565  1.1  skrll hppa_add_stub (const char *stub_name,
    566  1.1  skrll 	       asection *section,
    567  1.1  skrll 	       struct elf32_hppa_link_hash_table *htab)
    568  1.1  skrll {
    569  1.1  skrll   asection *link_sec;
    570  1.1  skrll   asection *stub_sec;
    571  1.1  skrll   struct elf32_hppa_stub_hash_entry *hsh;
    572  1.1  skrll 
    573  1.1  skrll   link_sec = htab->stub_group[section->id].link_sec;
    574  1.1  skrll   stub_sec = htab->stub_group[section->id].stub_sec;
    575  1.1  skrll   if (stub_sec == NULL)
    576  1.1  skrll     {
    577  1.1  skrll       stub_sec = htab->stub_group[link_sec->id].stub_sec;
    578  1.1  skrll       if (stub_sec == NULL)
    579  1.1  skrll 	{
    580  1.1  skrll 	  size_t namelen;
    581  1.1  skrll 	  bfd_size_type len;
    582  1.1  skrll 	  char *s_name;
    583  1.1  skrll 
    584  1.1  skrll 	  namelen = strlen (link_sec->name);
    585  1.1  skrll 	  len = namelen + sizeof (STUB_SUFFIX);
    586  1.1  skrll 	  s_name = bfd_alloc (htab->stub_bfd, len);
    587  1.1  skrll 	  if (s_name == NULL)
    588  1.1  skrll 	    return NULL;
    589  1.1  skrll 
    590  1.1  skrll 	  memcpy (s_name, link_sec->name, namelen);
    591  1.1  skrll 	  memcpy (s_name + namelen, STUB_SUFFIX, sizeof (STUB_SUFFIX));
    592  1.1  skrll 	  stub_sec = (*htab->add_stub_section) (s_name, link_sec);
    593  1.1  skrll 	  if (stub_sec == NULL)
    594  1.1  skrll 	    return NULL;
    595  1.1  skrll 	  htab->stub_group[link_sec->id].stub_sec = stub_sec;
    596  1.1  skrll 	}
    597  1.1  skrll       htab->stub_group[section->id].stub_sec = stub_sec;
    598  1.1  skrll     }
    599  1.1  skrll 
    600  1.1  skrll   /* Enter this entry into the linker stub hash table.  */
    601  1.1  skrll   hsh = hppa_stub_hash_lookup (&htab->bstab, stub_name,
    602  1.1  skrll 				      TRUE, FALSE);
    603  1.1  skrll   if (hsh == NULL)
    604  1.1  skrll     {
    605  1.1  skrll       (*_bfd_error_handler) (_("%B: cannot create stub entry %s"),
    606  1.1  skrll 			     section->owner,
    607  1.1  skrll 			     stub_name);
    608  1.1  skrll       return NULL;
    609  1.1  skrll     }
    610  1.1  skrll 
    611  1.1  skrll   hsh->stub_sec = stub_sec;
    612  1.1  skrll   hsh->stub_offset = 0;
    613  1.1  skrll   hsh->id_sec = link_sec;
    614  1.1  skrll   return hsh;
    615  1.1  skrll }
    616  1.1  skrll 
    617  1.1  skrll /* Determine the type of stub needed, if any, for a call.  */
    618  1.1  skrll 
    619  1.1  skrll static enum elf32_hppa_stub_type
    620  1.1  skrll hppa_type_of_stub (asection *input_sec,
    621  1.1  skrll 		   const Elf_Internal_Rela *rela,
    622  1.1  skrll 		   struct elf32_hppa_link_hash_entry *hh,
    623  1.1  skrll 		   bfd_vma destination,
    624  1.1  skrll 		   struct bfd_link_info *info)
    625  1.1  skrll {
    626  1.1  skrll   bfd_vma location;
    627  1.1  skrll   bfd_vma branch_offset;
    628  1.1  skrll   bfd_vma max_branch_offset;
    629  1.1  skrll   unsigned int r_type;
    630  1.1  skrll 
    631  1.1  skrll   if (hh != NULL
    632  1.1  skrll       && hh->eh.plt.offset != (bfd_vma) -1
    633  1.1  skrll       && hh->eh.dynindx != -1
    634  1.1  skrll       && !hh->plabel
    635  1.1  skrll       && (info->shared
    636  1.1  skrll 	  || !hh->eh.def_regular
    637  1.1  skrll 	  || hh->eh.root.type == bfd_link_hash_defweak))
    638  1.1  skrll     {
    639  1.1  skrll       /* We need an import stub.  Decide between hppa_stub_import
    640  1.1  skrll 	 and hppa_stub_import_shared later.  */
    641  1.1  skrll       return hppa_stub_import;
    642  1.1  skrll     }
    643  1.1  skrll 
    644  1.1  skrll   /* Determine where the call point is.  */
    645  1.1  skrll   location = (input_sec->output_offset
    646  1.1  skrll 	      + input_sec->output_section->vma
    647  1.1  skrll 	      + rela->r_offset);
    648  1.1  skrll 
    649  1.1  skrll   branch_offset = destination - location - 8;
    650  1.1  skrll   r_type = ELF32_R_TYPE (rela->r_info);
    651  1.1  skrll 
    652  1.1  skrll   /* Determine if a long branch stub is needed.  parisc branch offsets
    653  1.1  skrll      are relative to the second instruction past the branch, ie. +8
    654  1.1  skrll      bytes on from the branch instruction location.  The offset is
    655  1.1  skrll      signed and counts in units of 4 bytes.  */
    656  1.1  skrll   if (r_type == (unsigned int) R_PARISC_PCREL17F)
    657  1.1  skrll     max_branch_offset = (1 << (17 - 1)) << 2;
    658  1.1  skrll 
    659  1.1  skrll   else if (r_type == (unsigned int) R_PARISC_PCREL12F)
    660  1.1  skrll     max_branch_offset = (1 << (12 - 1)) << 2;
    661  1.1  skrll 
    662  1.1  skrll   else /* R_PARISC_PCREL22F.  */
    663  1.1  skrll     max_branch_offset = (1 << (22 - 1)) << 2;
    664  1.1  skrll 
    665  1.1  skrll   if (branch_offset + max_branch_offset >= 2*max_branch_offset)
    666  1.1  skrll     return hppa_stub_long_branch;
    667  1.1  skrll 
    668  1.1  skrll   return hppa_stub_none;
    669  1.1  skrll }
    670  1.1  skrll 
    671  1.1  skrll /* Build one linker stub as defined by the stub hash table entry GEN_ENTRY.
    672  1.1  skrll    IN_ARG contains the link info pointer.  */
    673  1.1  skrll 
    674  1.1  skrll #define LDIL_R1		0x20200000	/* ldil  LR'XXX,%r1		*/
    675  1.1  skrll #define BE_SR4_R1	0xe0202002	/* be,n  RR'XXX(%sr4,%r1)	*/
    676  1.1  skrll 
    677  1.1  skrll #define BL_R1		0xe8200000	/* b,l   .+8,%r1		*/
    678  1.1  skrll #define ADDIL_R1	0x28200000	/* addil LR'XXX,%r1,%r1		*/
    679  1.1  skrll #define DEPI_R1		0xd4201c1e	/* depi  0,31,2,%r1		*/
    680  1.1  skrll 
    681  1.1  skrll #define ADDIL_DP	0x2b600000	/* addil LR'XXX,%dp,%r1		*/
    682  1.1  skrll #define LDW_R1_R21	0x48350000	/* ldw   RR'XXX(%sr0,%r1),%r21	*/
    683  1.1  skrll #define BV_R0_R21	0xeaa0c000	/* bv    %r0(%r21)		*/
    684  1.1  skrll #define LDW_R1_R19	0x48330000	/* ldw   RR'XXX(%sr0,%r1),%r19	*/
    685  1.1  skrll 
    686  1.1  skrll #define ADDIL_R19	0x2a600000	/* addil LR'XXX,%r19,%r1	*/
    687  1.1  skrll #define LDW_R1_DP	0x483b0000	/* ldw   RR'XXX(%sr0,%r1),%dp	*/
    688  1.1  skrll 
    689  1.1  skrll #define LDSID_R21_R1	0x02a010a1	/* ldsid (%sr0,%r21),%r1	*/
    690  1.1  skrll #define MTSP_R1		0x00011820	/* mtsp  %r1,%sr0		*/
    691  1.1  skrll #define BE_SR0_R21	0xe2a00000	/* be    0(%sr0,%r21)		*/
    692  1.1  skrll #define STW_RP		0x6bc23fd1	/* stw   %rp,-24(%sr0,%sp)	*/
    693  1.1  skrll 
    694  1.1  skrll #define BL22_RP		0xe800a002	/* b,l,n XXX,%rp		*/
    695  1.1  skrll #define BL_RP		0xe8400002	/* b,l,n XXX,%rp		*/
    696  1.1  skrll #define NOP		0x08000240	/* nop				*/
    697  1.1  skrll #define LDW_RP		0x4bc23fd1	/* ldw   -24(%sr0,%sp),%rp	*/
    698  1.1  skrll #define LDSID_RP_R1	0x004010a1	/* ldsid (%sr0,%rp),%r1		*/
    699  1.1  skrll #define BE_SR0_RP	0xe0400002	/* be,n  0(%sr0,%rp)		*/
    700  1.1  skrll 
    701  1.1  skrll #ifndef R19_STUBS
    702  1.1  skrll #define R19_STUBS 1
    703  1.1  skrll #endif
    704  1.1  skrll 
    705  1.1  skrll #if R19_STUBS
    706  1.1  skrll #define LDW_R1_DLT	LDW_R1_R19
    707  1.1  skrll #else
    708  1.1  skrll #define LDW_R1_DLT	LDW_R1_DP
    709  1.1  skrll #endif
    710  1.1  skrll 
    711  1.1  skrll static bfd_boolean
    712  1.1  skrll hppa_build_one_stub (struct bfd_hash_entry *bh, void *in_arg)
    713  1.1  skrll {
    714  1.1  skrll   struct elf32_hppa_stub_hash_entry *hsh;
    715  1.1  skrll   struct bfd_link_info *info;
    716  1.1  skrll   struct elf32_hppa_link_hash_table *htab;
    717  1.1  skrll   asection *stub_sec;
    718  1.1  skrll   bfd *stub_bfd;
    719  1.1  skrll   bfd_byte *loc;
    720  1.1  skrll   bfd_vma sym_value;
    721  1.1  skrll   bfd_vma insn;
    722  1.1  skrll   bfd_vma off;
    723  1.1  skrll   int val;
    724  1.1  skrll   int size;
    725  1.1  skrll 
    726  1.1  skrll   /* Massage our args to the form they really have.  */
    727  1.1  skrll   hsh = hppa_stub_hash_entry (bh);
    728  1.1  skrll   info = (struct bfd_link_info *)in_arg;
    729  1.1  skrll 
    730  1.1  skrll   htab = hppa_link_hash_table (info);
    731  1.1  skrll   stub_sec = hsh->stub_sec;
    732  1.1  skrll 
    733  1.1  skrll   /* Make a note of the offset within the stubs for this entry.  */
    734  1.1  skrll   hsh->stub_offset = stub_sec->size;
    735  1.1  skrll   loc = stub_sec->contents + hsh->stub_offset;
    736  1.1  skrll 
    737  1.1  skrll   stub_bfd = stub_sec->owner;
    738  1.1  skrll 
    739  1.1  skrll   switch (hsh->stub_type)
    740  1.1  skrll     {
    741  1.1  skrll     case hppa_stub_long_branch:
    742  1.1  skrll       /* Create the long branch.  A long branch is formed with "ldil"
    743  1.1  skrll 	 loading the upper bits of the target address into a register,
    744  1.1  skrll 	 then branching with "be" which adds in the lower bits.
    745  1.1  skrll 	 The "be" has its delay slot nullified.  */
    746  1.1  skrll       sym_value = (hsh->target_value
    747  1.1  skrll 		   + hsh->target_section->output_offset
    748  1.1  skrll 		   + hsh->target_section->output_section->vma);
    749  1.1  skrll 
    750  1.1  skrll       val = hppa_field_adjust (sym_value, 0, e_lrsel);
    751  1.1  skrll       insn = hppa_rebuild_insn ((int) LDIL_R1, val, 21);
    752  1.1  skrll       bfd_put_32 (stub_bfd, insn, loc);
    753  1.1  skrll 
    754  1.1  skrll       val = hppa_field_adjust (sym_value, 0, e_rrsel) >> 2;
    755  1.1  skrll       insn = hppa_rebuild_insn ((int) BE_SR4_R1, val, 17);
    756  1.1  skrll       bfd_put_32 (stub_bfd, insn, loc + 4);
    757  1.1  skrll 
    758  1.1  skrll       size = 8;
    759  1.1  skrll       break;
    760  1.1  skrll 
    761  1.1  skrll     case hppa_stub_long_branch_shared:
    762  1.1  skrll       /* Branches are relative.  This is where we are going to.  */
    763  1.1  skrll       sym_value = (hsh->target_value
    764  1.1  skrll 		   + hsh->target_section->output_offset
    765  1.1  skrll 		   + hsh->target_section->output_section->vma);
    766  1.1  skrll 
    767  1.1  skrll       /* And this is where we are coming from, more or less.  */
    768  1.1  skrll       sym_value -= (hsh->stub_offset
    769  1.1  skrll 		    + stub_sec->output_offset
    770  1.1  skrll 		    + stub_sec->output_section->vma);
    771  1.1  skrll 
    772  1.1  skrll       bfd_put_32 (stub_bfd, (bfd_vma) BL_R1, loc);
    773  1.1  skrll       val = hppa_field_adjust (sym_value, (bfd_signed_vma) -8, e_lrsel);
    774  1.1  skrll       insn = hppa_rebuild_insn ((int) ADDIL_R1, val, 21);
    775  1.1  skrll       bfd_put_32 (stub_bfd, insn, loc + 4);
    776  1.1  skrll 
    777  1.1  skrll       val = hppa_field_adjust (sym_value, (bfd_signed_vma) -8, e_rrsel) >> 2;
    778  1.1  skrll       insn = hppa_rebuild_insn ((int) BE_SR4_R1, val, 17);
    779  1.1  skrll       bfd_put_32 (stub_bfd, insn, loc + 8);
    780  1.1  skrll       size = 12;
    781  1.1  skrll       break;
    782  1.1  skrll 
    783  1.1  skrll     case hppa_stub_import:
    784  1.1  skrll     case hppa_stub_import_shared:
    785  1.1  skrll       off = hsh->hh->eh.plt.offset;
    786  1.1  skrll       if (off >= (bfd_vma) -2)
    787  1.1  skrll 	abort ();
    788  1.1  skrll 
    789  1.1  skrll       off &= ~ (bfd_vma) 1;
    790  1.1  skrll       sym_value = (off
    791  1.1  skrll 		   + htab->splt->output_offset
    792  1.1  skrll 		   + htab->splt->output_section->vma
    793  1.1  skrll 		   - elf_gp (htab->splt->output_section->owner));
    794  1.1  skrll 
    795  1.1  skrll       insn = ADDIL_DP;
    796  1.1  skrll #if R19_STUBS
    797  1.1  skrll       if (hsh->stub_type == hppa_stub_import_shared)
    798  1.1  skrll 	insn = ADDIL_R19;
    799  1.1  skrll #endif
    800  1.1  skrll       val = hppa_field_adjust (sym_value, 0, e_lrsel),
    801  1.1  skrll       insn = hppa_rebuild_insn ((int) insn, val, 21);
    802  1.1  skrll       bfd_put_32 (stub_bfd, insn, loc);
    803  1.1  skrll 
    804  1.1  skrll       /* It is critical to use lrsel/rrsel here because we are using
    805  1.1  skrll 	 two different offsets (+0 and +4) from sym_value.  If we use
    806  1.1  skrll 	 lsel/rsel then with unfortunate sym_values we will round
    807  1.1  skrll 	 sym_value+4 up to the next 2k block leading to a mis-match
    808  1.1  skrll 	 between the lsel and rsel value.  */
    809  1.1  skrll       val = hppa_field_adjust (sym_value, 0, e_rrsel);
    810  1.1  skrll       insn = hppa_rebuild_insn ((int) LDW_R1_R21, val, 14);
    811  1.1  skrll       bfd_put_32 (stub_bfd, insn, loc + 4);
    812  1.1  skrll 
    813  1.1  skrll       if (htab->multi_subspace)
    814  1.1  skrll 	{
    815  1.1  skrll 	  val = hppa_field_adjust (sym_value, (bfd_signed_vma) 4, e_rrsel);
    816  1.1  skrll 	  insn = hppa_rebuild_insn ((int) LDW_R1_DLT, val, 14);
    817  1.1  skrll 	  bfd_put_32 (stub_bfd, insn, loc + 8);
    818  1.1  skrll 
    819  1.1  skrll 	  bfd_put_32 (stub_bfd, (bfd_vma) LDSID_R21_R1, loc + 12);
    820  1.1  skrll 	  bfd_put_32 (stub_bfd, (bfd_vma) MTSP_R1,      loc + 16);
    821  1.1  skrll 	  bfd_put_32 (stub_bfd, (bfd_vma) BE_SR0_R21,   loc + 20);
    822  1.1  skrll 	  bfd_put_32 (stub_bfd, (bfd_vma) STW_RP,       loc + 24);
    823  1.1  skrll 
    824  1.1  skrll 	  size = 28;
    825  1.1  skrll 	}
    826  1.1  skrll       else
    827  1.1  skrll 	{
    828  1.1  skrll 	  bfd_put_32 (stub_bfd, (bfd_vma) BV_R0_R21, loc + 8);
    829  1.1  skrll 	  val = hppa_field_adjust (sym_value, (bfd_signed_vma) 4, e_rrsel);
    830  1.1  skrll 	  insn = hppa_rebuild_insn ((int) LDW_R1_DLT, val, 14);
    831  1.1  skrll 	  bfd_put_32 (stub_bfd, insn, loc + 12);
    832  1.1  skrll 
    833  1.1  skrll 	  size = 16;
    834  1.1  skrll 	}
    835  1.1  skrll 
    836  1.1  skrll       break;
    837  1.1  skrll 
    838  1.1  skrll     case hppa_stub_export:
    839  1.1  skrll       /* Branches are relative.  This is where we are going to.  */
    840  1.1  skrll       sym_value = (hsh->target_value
    841  1.1  skrll 		   + hsh->target_section->output_offset
    842  1.1  skrll 		   + hsh->target_section->output_section->vma);
    843  1.1  skrll 
    844  1.1  skrll       /* And this is where we are coming from.  */
    845  1.1  skrll       sym_value -= (hsh->stub_offset
    846  1.1  skrll 		    + stub_sec->output_offset
    847  1.1  skrll 		    + stub_sec->output_section->vma);
    848  1.1  skrll 
    849  1.1  skrll       if (sym_value - 8 + (1 << (17 + 1)) >= (1 << (17 + 2))
    850  1.1  skrll 	  && (!htab->has_22bit_branch
    851  1.1  skrll 	      || sym_value - 8 + (1 << (22 + 1)) >= (1 << (22 + 2))))
    852  1.1  skrll 	{
    853  1.1  skrll 	  (*_bfd_error_handler)
    854  1.1  skrll 	    (_("%B(%A+0x%lx): cannot reach %s, recompile with -ffunction-sections"),
    855  1.1  skrll 	     hsh->target_section->owner,
    856  1.1  skrll 	     stub_sec,
    857  1.1  skrll 	     (long) hsh->stub_offset,
    858  1.1  skrll 	     hsh->bh_root.string);
    859  1.1  skrll 	  bfd_set_error (bfd_error_bad_value);
    860  1.1  skrll 	  return FALSE;
    861  1.1  skrll 	}
    862  1.1  skrll 
    863  1.1  skrll       val = hppa_field_adjust (sym_value, (bfd_signed_vma) -8, e_fsel) >> 2;
    864  1.1  skrll       if (!htab->has_22bit_branch)
    865  1.1  skrll 	insn = hppa_rebuild_insn ((int) BL_RP, val, 17);
    866  1.1  skrll       else
    867  1.1  skrll 	insn = hppa_rebuild_insn ((int) BL22_RP, val, 22);
    868  1.1  skrll       bfd_put_32 (stub_bfd, insn, loc);
    869  1.1  skrll 
    870  1.1  skrll       bfd_put_32 (stub_bfd, (bfd_vma) NOP,         loc + 4);
    871  1.1  skrll       bfd_put_32 (stub_bfd, (bfd_vma) LDW_RP,      loc + 8);
    872  1.1  skrll       bfd_put_32 (stub_bfd, (bfd_vma) LDSID_RP_R1, loc + 12);
    873  1.1  skrll       bfd_put_32 (stub_bfd, (bfd_vma) MTSP_R1,     loc + 16);
    874  1.1  skrll       bfd_put_32 (stub_bfd, (bfd_vma) BE_SR0_RP,   loc + 20);
    875  1.1  skrll 
    876  1.1  skrll       /* Point the function symbol at the stub.  */
    877  1.1  skrll       hsh->hh->eh.root.u.def.section = stub_sec;
    878  1.1  skrll       hsh->hh->eh.root.u.def.value = stub_sec->size;
    879  1.1  skrll 
    880  1.1  skrll       size = 24;
    881  1.1  skrll       break;
    882  1.1  skrll 
    883  1.1  skrll     default:
    884  1.1  skrll       BFD_FAIL ();
    885  1.1  skrll       return FALSE;
    886  1.1  skrll     }
    887  1.1  skrll 
    888  1.1  skrll   stub_sec->size += size;
    889  1.1  skrll   return TRUE;
    890  1.1  skrll }
    891  1.1  skrll 
    892  1.1  skrll #undef LDIL_R1
    893  1.1  skrll #undef BE_SR4_R1
    894  1.1  skrll #undef BL_R1
    895  1.1  skrll #undef ADDIL_R1
    896  1.1  skrll #undef DEPI_R1
    897  1.1  skrll #undef LDW_R1_R21
    898  1.1  skrll #undef LDW_R1_DLT
    899  1.1  skrll #undef LDW_R1_R19
    900  1.1  skrll #undef ADDIL_R19
    901  1.1  skrll #undef LDW_R1_DP
    902  1.1  skrll #undef LDSID_R21_R1
    903  1.1  skrll #undef MTSP_R1
    904  1.1  skrll #undef BE_SR0_R21
    905  1.1  skrll #undef STW_RP
    906  1.1  skrll #undef BV_R0_R21
    907  1.1  skrll #undef BL_RP
    908  1.1  skrll #undef NOP
    909  1.1  skrll #undef LDW_RP
    910  1.1  skrll #undef LDSID_RP_R1
    911  1.1  skrll #undef BE_SR0_RP
    912  1.1  skrll 
    913  1.1  skrll /* As above, but don't actually build the stub.  Just bump offset so
    914  1.1  skrll    we know stub section sizes.  */
    915  1.1  skrll 
    916  1.1  skrll static bfd_boolean
    917  1.1  skrll hppa_size_one_stub (struct bfd_hash_entry *bh, void *in_arg)
    918  1.1  skrll {
    919  1.1  skrll   struct elf32_hppa_stub_hash_entry *hsh;
    920  1.1  skrll   struct elf32_hppa_link_hash_table *htab;
    921  1.1  skrll   int size;
    922  1.1  skrll 
    923  1.1  skrll   /* Massage our args to the form they really have.  */
    924  1.1  skrll   hsh = hppa_stub_hash_entry (bh);
    925  1.1  skrll   htab = in_arg;
    926  1.1  skrll 
    927  1.1  skrll   if (hsh->stub_type == hppa_stub_long_branch)
    928  1.1  skrll     size = 8;
    929  1.1  skrll   else if (hsh->stub_type == hppa_stub_long_branch_shared)
    930  1.1  skrll     size = 12;
    931  1.1  skrll   else if (hsh->stub_type == hppa_stub_export)
    932  1.1  skrll     size = 24;
    933  1.1  skrll   else /* hppa_stub_import or hppa_stub_import_shared.  */
    934  1.1  skrll     {
    935  1.1  skrll       if (htab->multi_subspace)
    936  1.1  skrll 	size = 28;
    937  1.1  skrll       else
    938  1.1  skrll 	size = 16;
    939  1.1  skrll     }
    940  1.1  skrll 
    941  1.1  skrll   hsh->stub_sec->size += size;
    942  1.1  skrll   return TRUE;
    943  1.1  skrll }
    944  1.1  skrll 
    945  1.1  skrll /* Return nonzero if ABFD represents an HPPA ELF32 file.
    946  1.1  skrll    Additionally we set the default architecture and machine.  */
    947  1.1  skrll 
    948  1.1  skrll static bfd_boolean
    949  1.1  skrll elf32_hppa_object_p (bfd *abfd)
    950  1.1  skrll {
    951  1.1  skrll   Elf_Internal_Ehdr * i_ehdrp;
    952  1.1  skrll   unsigned int flags;
    953  1.1  skrll 
    954  1.1  skrll   i_ehdrp = elf_elfheader (abfd);
    955  1.1  skrll   if (strcmp (bfd_get_target (abfd), "elf32-hppa-linux") == 0)
    956  1.1  skrll     {
    957  1.1  skrll       /* GCC on hppa-linux produces binaries with OSABI=Linux,
    958  1.1  skrll 	 but the kernel produces corefiles with OSABI=SysV.  */
    959  1.1  skrll       if (i_ehdrp->e_ident[EI_OSABI] != ELFOSABI_LINUX &&
    960  1.1  skrll 	  i_ehdrp->e_ident[EI_OSABI] != ELFOSABI_NONE) /* aka SYSV */
    961  1.1  skrll 	return FALSE;
    962  1.1  skrll     }
    963  1.1  skrll   else if (strcmp (bfd_get_target (abfd), "elf32-hppa-netbsd") == 0)
    964  1.1  skrll     {
    965  1.1  skrll       /* GCC on hppa-netbsd produces binaries with OSABI=NetBSD,
    966  1.1  skrll 	 but the kernel produces corefiles with OSABI=SysV.  */
    967  1.1  skrll       if (i_ehdrp->e_ident[EI_OSABI] != ELFOSABI_NETBSD &&
    968  1.1  skrll 	  i_ehdrp->e_ident[EI_OSABI] != ELFOSABI_NONE) /* aka SYSV */
    969  1.1  skrll 	return FALSE;
    970  1.1  skrll     }
    971  1.1  skrll   else
    972  1.1  skrll     {
    973  1.1  skrll       if (i_ehdrp->e_ident[EI_OSABI] != ELFOSABI_HPUX)
    974  1.1  skrll 	return FALSE;
    975  1.1  skrll     }
    976  1.1  skrll 
    977  1.1  skrll   flags = i_ehdrp->e_flags;
    978  1.1  skrll   switch (flags & (EF_PARISC_ARCH | EF_PARISC_WIDE))
    979  1.1  skrll     {
    980  1.1  skrll     case EFA_PARISC_1_0:
    981  1.1  skrll       return bfd_default_set_arch_mach (abfd, bfd_arch_hppa, 10);
    982  1.1  skrll     case EFA_PARISC_1_1:
    983  1.1  skrll       return bfd_default_set_arch_mach (abfd, bfd_arch_hppa, 11);
    984  1.1  skrll     case EFA_PARISC_2_0:
    985  1.1  skrll       return bfd_default_set_arch_mach (abfd, bfd_arch_hppa, 20);
    986  1.1  skrll     case EFA_PARISC_2_0 | EF_PARISC_WIDE:
    987  1.1  skrll       return bfd_default_set_arch_mach (abfd, bfd_arch_hppa, 25);
    988  1.1  skrll     }
    989  1.1  skrll   return TRUE;
    990  1.1  skrll }
    991  1.1  skrll 
    992  1.1  skrll /* Create the .plt and .got sections, and set up our hash table
    993  1.1  skrll    short-cuts to various dynamic sections.  */
    994  1.1  skrll 
    995  1.1  skrll static bfd_boolean
    996  1.1  skrll elf32_hppa_create_dynamic_sections (bfd *abfd, struct bfd_link_info *info)
    997  1.1  skrll {
    998  1.1  skrll   struct elf32_hppa_link_hash_table *htab;
    999  1.1  skrll   struct elf_link_hash_entry *eh;
   1000  1.1  skrll 
   1001  1.1  skrll   /* Don't try to create the .plt and .got twice.  */
   1002  1.1  skrll   htab = hppa_link_hash_table (info);
   1003  1.1  skrll   if (htab->splt != NULL)
   1004  1.1  skrll     return TRUE;
   1005  1.1  skrll 
   1006  1.1  skrll   /* Call the generic code to do most of the work.  */
   1007  1.1  skrll   if (! _bfd_elf_create_dynamic_sections (abfd, info))
   1008  1.1  skrll     return FALSE;
   1009  1.1  skrll 
   1010  1.1  skrll   htab->splt = bfd_get_section_by_name (abfd, ".plt");
   1011  1.1  skrll   htab->srelplt = bfd_get_section_by_name (abfd, ".rela.plt");
   1012  1.1  skrll 
   1013  1.1  skrll   htab->sgot = bfd_get_section_by_name (abfd, ".got");
   1014  1.1  skrll   htab->srelgot = bfd_make_section_with_flags (abfd, ".rela.got",
   1015  1.1  skrll 					       (SEC_ALLOC
   1016  1.1  skrll 						| SEC_LOAD
   1017  1.1  skrll 						| SEC_HAS_CONTENTS
   1018  1.1  skrll 						| SEC_IN_MEMORY
   1019  1.1  skrll 						| SEC_LINKER_CREATED
   1020  1.1  skrll 						| SEC_READONLY));
   1021  1.1  skrll   if (htab->srelgot == NULL
   1022  1.1  skrll       || ! bfd_set_section_alignment (abfd, htab->srelgot, 2))
   1023  1.1  skrll     return FALSE;
   1024  1.1  skrll 
   1025  1.1  skrll   htab->sdynbss = bfd_get_section_by_name (abfd, ".dynbss");
   1026  1.1  skrll   htab->srelbss = bfd_get_section_by_name (abfd, ".rela.bss");
   1027  1.1  skrll 
   1028  1.1  skrll   /* hppa-linux needs _GLOBAL_OFFSET_TABLE_ to be visible from the main
   1029  1.1  skrll      application, because __canonicalize_funcptr_for_compare needs it.  */
   1030  1.1  skrll   eh = elf_hash_table (info)->hgot;
   1031  1.1  skrll   eh->forced_local = 0;
   1032  1.1  skrll   eh->other = STV_DEFAULT;
   1033  1.1  skrll   return bfd_elf_link_record_dynamic_symbol (info, eh);
   1034  1.1  skrll }
   1035  1.1  skrll 
   1036  1.1  skrll /* Copy the extra info we tack onto an elf_link_hash_entry.  */
   1037  1.1  skrll 
   1038  1.1  skrll static void
   1039  1.1  skrll elf32_hppa_copy_indirect_symbol (struct bfd_link_info *info,
   1040  1.1  skrll 				 struct elf_link_hash_entry *eh_dir,
   1041  1.1  skrll 				 struct elf_link_hash_entry *eh_ind)
   1042  1.1  skrll {
   1043  1.1  skrll   struct elf32_hppa_link_hash_entry *hh_dir, *hh_ind;
   1044  1.1  skrll 
   1045  1.1  skrll   hh_dir = hppa_elf_hash_entry (eh_dir);
   1046  1.1  skrll   hh_ind = hppa_elf_hash_entry (eh_ind);
   1047  1.1  skrll 
   1048  1.1  skrll   if (hh_ind->dyn_relocs != NULL)
   1049  1.1  skrll     {
   1050  1.1  skrll       if (hh_dir->dyn_relocs != NULL)
   1051  1.1  skrll 	{
   1052  1.1  skrll 	  struct elf32_hppa_dyn_reloc_entry **hdh_pp;
   1053  1.1  skrll 	  struct elf32_hppa_dyn_reloc_entry *hdh_p;
   1054  1.1  skrll 
   1055  1.1  skrll 	  /* Add reloc counts against the indirect sym to the direct sym
   1056  1.1  skrll 	     list.  Merge any entries against the same section.  */
   1057  1.1  skrll 	  for (hdh_pp = &hh_ind->dyn_relocs; (hdh_p = *hdh_pp) != NULL; )
   1058  1.1  skrll 	    {
   1059  1.1  skrll 	      struct elf32_hppa_dyn_reloc_entry *hdh_q;
   1060  1.1  skrll 
   1061  1.1  skrll 	      for (hdh_q = hh_dir->dyn_relocs;
   1062  1.1  skrll 		   hdh_q != NULL;
   1063  1.1  skrll 		   hdh_q = hdh_q->hdh_next)
   1064  1.1  skrll 		if (hdh_q->sec == hdh_p->sec)
   1065  1.1  skrll 		  {
   1066  1.1  skrll #if RELATIVE_DYNRELOCS
   1067  1.1  skrll 		    hdh_q->relative_count += hdh_p->relative_count;
   1068  1.1  skrll #endif
   1069  1.1  skrll 		    hdh_q->count += hdh_p->count;
   1070  1.1  skrll 		    *hdh_pp = hdh_p->hdh_next;
   1071  1.1  skrll 		    break;
   1072  1.1  skrll 		  }
   1073  1.1  skrll 	      if (hdh_q == NULL)
   1074  1.1  skrll 		hdh_pp = &hdh_p->hdh_next;
   1075  1.1  skrll 	    }
   1076  1.1  skrll 	  *hdh_pp = hh_dir->dyn_relocs;
   1077  1.1  skrll 	}
   1078  1.1  skrll 
   1079  1.1  skrll       hh_dir->dyn_relocs = hh_ind->dyn_relocs;
   1080  1.1  skrll       hh_ind->dyn_relocs = NULL;
   1081  1.1  skrll     }
   1082  1.1  skrll 
   1083  1.1  skrll   if (ELIMINATE_COPY_RELOCS
   1084  1.1  skrll       && eh_ind->root.type != bfd_link_hash_indirect
   1085  1.1  skrll       && eh_dir->dynamic_adjusted)
   1086  1.1  skrll     {
   1087  1.1  skrll       /* If called to transfer flags for a weakdef during processing
   1088  1.1  skrll 	 of elf_adjust_dynamic_symbol, don't copy non_got_ref.
   1089  1.1  skrll 	 We clear it ourselves for ELIMINATE_COPY_RELOCS.  */
   1090  1.1  skrll       eh_dir->ref_dynamic |= eh_ind->ref_dynamic;
   1091  1.1  skrll       eh_dir->ref_regular |= eh_ind->ref_regular;
   1092  1.1  skrll       eh_dir->ref_regular_nonweak |= eh_ind->ref_regular_nonweak;
   1093  1.1  skrll       eh_dir->needs_plt |= eh_ind->needs_plt;
   1094  1.1  skrll     }
   1095  1.1  skrll   else
   1096  1.1  skrll     {
   1097  1.1  skrll       if (eh_ind->root.type == bfd_link_hash_indirect
   1098  1.1  skrll           && eh_dir->got.refcount <= 0)
   1099  1.1  skrll         {
   1100  1.1  skrll           hh_dir->tls_type = hh_ind->tls_type;
   1101  1.1  skrll           hh_ind->tls_type = GOT_UNKNOWN;
   1102  1.1  skrll         }
   1103  1.1  skrll 
   1104  1.1  skrll       _bfd_elf_link_hash_copy_indirect (info, eh_dir, eh_ind);
   1105  1.1  skrll     }
   1106  1.1  skrll }
   1107  1.1  skrll 
   1108  1.1  skrll static int
   1109  1.1  skrll elf32_hppa_optimized_tls_reloc (struct bfd_link_info *info ATTRIBUTE_UNUSED,
   1110  1.1  skrll 				int r_type, int is_local ATTRIBUTE_UNUSED)
   1111  1.1  skrll {
   1112  1.1  skrll   /* For now we don't support linker optimizations.  */
   1113  1.1  skrll   return r_type;
   1114  1.1  skrll }
   1115  1.1  skrll 
   1116  1.1  skrll /* Look through the relocs for a section during the first phase, and
   1117  1.1  skrll    calculate needed space in the global offset table, procedure linkage
   1118  1.1  skrll    table, and dynamic reloc sections.  At this point we haven't
   1119  1.1  skrll    necessarily read all the input files.  */
   1120  1.1  skrll 
   1121  1.1  skrll static bfd_boolean
   1122  1.1  skrll elf32_hppa_check_relocs (bfd *abfd,
   1123  1.1  skrll 			 struct bfd_link_info *info,
   1124  1.1  skrll 			 asection *sec,
   1125  1.1  skrll 			 const Elf_Internal_Rela *relocs)
   1126  1.1  skrll {
   1127  1.1  skrll   Elf_Internal_Shdr *symtab_hdr;
   1128  1.1  skrll   struct elf_link_hash_entry **eh_syms;
   1129  1.1  skrll   const Elf_Internal_Rela *rela;
   1130  1.1  skrll   const Elf_Internal_Rela *rela_end;
   1131  1.1  skrll   struct elf32_hppa_link_hash_table *htab;
   1132  1.1  skrll   asection *sreloc;
   1133  1.1  skrll   asection *stubreloc;
   1134  1.1  skrll   int tls_type = GOT_UNKNOWN, old_tls_type = GOT_UNKNOWN;
   1135  1.1  skrll 
   1136  1.1  skrll   if (info->relocatable)
   1137  1.1  skrll     return TRUE;
   1138  1.1  skrll 
   1139  1.1  skrll   htab = hppa_link_hash_table (info);
   1140  1.1  skrll   symtab_hdr = &elf_tdata (abfd)->symtab_hdr;
   1141  1.1  skrll   eh_syms = elf_sym_hashes (abfd);
   1142  1.1  skrll   sreloc = NULL;
   1143  1.1  skrll   stubreloc = NULL;
   1144  1.1  skrll 
   1145  1.1  skrll   rela_end = relocs + sec->reloc_count;
   1146  1.1  skrll   for (rela = relocs; rela < rela_end; rela++)
   1147  1.1  skrll     {
   1148  1.1  skrll       enum {
   1149  1.1  skrll 	NEED_GOT = 1,
   1150  1.1  skrll 	NEED_PLT = 2,
   1151  1.1  skrll 	NEED_DYNREL = 4,
   1152  1.1  skrll 	PLT_PLABEL = 8
   1153  1.1  skrll       };
   1154  1.1  skrll 
   1155  1.1  skrll       unsigned int r_symndx, r_type;
   1156  1.1  skrll       struct elf32_hppa_link_hash_entry *hh;
   1157  1.1  skrll       int need_entry = 0;
   1158  1.1  skrll 
   1159  1.1  skrll       r_symndx = ELF32_R_SYM (rela->r_info);
   1160  1.1  skrll 
   1161  1.1  skrll       if (r_symndx < symtab_hdr->sh_info)
   1162  1.1  skrll 	hh = NULL;
   1163  1.1  skrll       else
   1164  1.1  skrll 	{
   1165  1.1  skrll 	  hh =  hppa_elf_hash_entry (eh_syms[r_symndx - symtab_hdr->sh_info]);
   1166  1.1  skrll 	  while (hh->eh.root.type == bfd_link_hash_indirect
   1167  1.1  skrll 		 || hh->eh.root.type == bfd_link_hash_warning)
   1168  1.1  skrll 	    hh = hppa_elf_hash_entry (hh->eh.root.u.i.link);
   1169  1.1  skrll 	}
   1170  1.1  skrll 
   1171  1.1  skrll       r_type = ELF32_R_TYPE (rela->r_info);
   1172  1.1  skrll       r_type = elf32_hppa_optimized_tls_reloc (info, r_type, hh == NULL);
   1173  1.1  skrll 
   1174  1.1  skrll       switch (r_type)
   1175  1.1  skrll 	{
   1176  1.1  skrll 	case R_PARISC_DLTIND14F:
   1177  1.1  skrll 	case R_PARISC_DLTIND14R:
   1178  1.1  skrll 	case R_PARISC_DLTIND21L:
   1179  1.1  skrll 	  /* This symbol requires a global offset table entry.  */
   1180  1.1  skrll 	  need_entry = NEED_GOT;
   1181  1.1  skrll 	  break;
   1182  1.1  skrll 
   1183  1.1  skrll 	case R_PARISC_PLABEL14R: /* "Official" procedure labels.  */
   1184  1.1  skrll 	case R_PARISC_PLABEL21L:
   1185  1.1  skrll 	case R_PARISC_PLABEL32:
   1186  1.1  skrll 	  /* If the addend is non-zero, we break badly.  */
   1187  1.1  skrll 	  if (rela->r_addend != 0)
   1188  1.1  skrll 	    abort ();
   1189  1.1  skrll 
   1190  1.1  skrll 	  /* If we are creating a shared library, then we need to
   1191  1.1  skrll 	     create a PLT entry for all PLABELs, because PLABELs with
   1192  1.1  skrll 	     local symbols may be passed via a pointer to another
   1193  1.1  skrll 	     object.  Additionally, output a dynamic relocation
   1194  1.1  skrll 	     pointing to the PLT entry.
   1195  1.1  skrll 
   1196  1.1  skrll 	     For executables, the original 32-bit ABI allowed two
   1197  1.1  skrll 	     different styles of PLABELs (function pointers):  For
   1198  1.1  skrll 	     global functions, the PLABEL word points into the .plt
   1199  1.1  skrll 	     two bytes past a (function address, gp) pair, and for
   1200  1.1  skrll 	     local functions the PLABEL points directly at the
   1201  1.1  skrll 	     function.  The magic +2 for the first type allows us to
   1202  1.1  skrll 	     differentiate between the two.  As you can imagine, this
   1203  1.1  skrll 	     is a real pain when it comes to generating code to call
   1204  1.1  skrll 	     functions indirectly or to compare function pointers.
   1205  1.1  skrll 	     We avoid the mess by always pointing a PLABEL into the
   1206  1.1  skrll 	     .plt, even for local functions.  */
   1207  1.1  skrll 	  need_entry = PLT_PLABEL | NEED_PLT | NEED_DYNREL;
   1208  1.1  skrll 	  break;
   1209  1.1  skrll 
   1210  1.1  skrll 	case R_PARISC_PCREL12F:
   1211  1.1  skrll 	  htab->has_12bit_branch = 1;
   1212  1.1  skrll 	  goto branch_common;
   1213  1.1  skrll 
   1214  1.1  skrll 	case R_PARISC_PCREL17C:
   1215  1.1  skrll 	case R_PARISC_PCREL17F:
   1216  1.1  skrll 	  htab->has_17bit_branch = 1;
   1217  1.1  skrll 	  goto branch_common;
   1218  1.1  skrll 
   1219  1.1  skrll 	case R_PARISC_PCREL22F:
   1220  1.1  skrll 	  htab->has_22bit_branch = 1;
   1221  1.1  skrll 	branch_common:
   1222  1.1  skrll 	  /* Function calls might need to go through the .plt, and
   1223  1.1  skrll 	     might require long branch stubs.  */
   1224  1.1  skrll 	  if (hh == NULL)
   1225  1.1  skrll 	    {
   1226  1.1  skrll 	      /* We know local syms won't need a .plt entry, and if
   1227  1.1  skrll 		 they need a long branch stub we can't guarantee that
   1228  1.1  skrll 		 we can reach the stub.  So just flag an error later
   1229  1.1  skrll 		 if we're doing a shared link and find we need a long
   1230  1.1  skrll 		 branch stub.  */
   1231  1.1  skrll 	      continue;
   1232  1.1  skrll 	    }
   1233  1.1  skrll 	  else
   1234  1.1  skrll 	    {
   1235  1.1  skrll 	      /* Global symbols will need a .plt entry if they remain
   1236  1.1  skrll 		 global, and in most cases won't need a long branch
   1237  1.1  skrll 		 stub.  Unfortunately, we have to cater for the case
   1238  1.1  skrll 		 where a symbol is forced local by versioning, or due
   1239  1.1  skrll 		 to symbolic linking, and we lose the .plt entry.  */
   1240  1.1  skrll 	      need_entry = NEED_PLT;
   1241  1.1  skrll 	      if (hh->eh.type == STT_PARISC_MILLI)
   1242  1.1  skrll 		need_entry = 0;
   1243  1.1  skrll 	    }
   1244  1.1  skrll 	  break;
   1245  1.1  skrll 
   1246  1.1  skrll 	case R_PARISC_SEGBASE:  /* Used to set segment base.  */
   1247  1.1  skrll 	case R_PARISC_SEGREL32: /* Relative reloc, used for unwind.  */
   1248  1.1  skrll 	case R_PARISC_PCREL14F: /* PC relative load/store.  */
   1249  1.1  skrll 	case R_PARISC_PCREL14R:
   1250  1.1  skrll 	case R_PARISC_PCREL17R: /* External branches.  */
   1251  1.1  skrll 	case R_PARISC_PCREL21L: /* As above, and for load/store too.  */
   1252  1.1  skrll 	case R_PARISC_PCREL32:
   1253  1.1  skrll 	  /* We don't need to propagate the relocation if linking a
   1254  1.1  skrll 	     shared object since these are section relative.  */
   1255  1.1  skrll 	  continue;
   1256  1.1  skrll 
   1257  1.1  skrll 	case R_PARISC_DPREL14F: /* Used for gp rel data load/store.  */
   1258  1.1  skrll 	case R_PARISC_DPREL14R:
   1259  1.1  skrll 	case R_PARISC_DPREL21L:
   1260  1.1  skrll 	  if (info->shared)
   1261  1.1  skrll 	    {
   1262  1.1  skrll 	      (*_bfd_error_handler)
   1263  1.1  skrll 		(_("%B: relocation %s can not be used when making a shared object; recompile with -fPIC"),
   1264  1.1  skrll 		 abfd,
   1265  1.1  skrll 		 elf_hppa_howto_table[r_type].name);
   1266  1.1  skrll 	      bfd_set_error (bfd_error_bad_value);
   1267  1.1  skrll 	      return FALSE;
   1268  1.1  skrll 	    }
   1269  1.1  skrll 	  /* Fall through.  */
   1270  1.1  skrll 
   1271  1.1  skrll 	case R_PARISC_DIR17F: /* Used for external branches.  */
   1272  1.1  skrll 	case R_PARISC_DIR17R:
   1273  1.1  skrll 	case R_PARISC_DIR14F: /* Used for load/store from absolute locn.  */
   1274  1.1  skrll 	case R_PARISC_DIR14R:
   1275  1.1  skrll 	case R_PARISC_DIR21L: /* As above, and for ext branches too.  */
   1276  1.1  skrll 	case R_PARISC_DIR32: /* .word relocs.  */
   1277  1.1  skrll 	  /* We may want to output a dynamic relocation later.  */
   1278  1.1  skrll 	  need_entry = NEED_DYNREL;
   1279  1.1  skrll 	  break;
   1280  1.1  skrll 
   1281  1.1  skrll 	  /* This relocation describes the C++ object vtable hierarchy.
   1282  1.1  skrll 	     Reconstruct it for later use during GC.  */
   1283  1.1  skrll 	case R_PARISC_GNU_VTINHERIT:
   1284  1.1  skrll 	  if (!bfd_elf_gc_record_vtinherit (abfd, sec, &hh->eh, rela->r_offset))
   1285  1.1  skrll 	    return FALSE;
   1286  1.1  skrll 	  continue;
   1287  1.1  skrll 
   1288  1.1  skrll 	  /* This relocation describes which C++ vtable entries are actually
   1289  1.1  skrll 	     used.  Record for later use during GC.  */
   1290  1.1  skrll 	case R_PARISC_GNU_VTENTRY:
   1291  1.1  skrll 	  BFD_ASSERT (hh != NULL);
   1292  1.1  skrll 	  if (hh != NULL
   1293  1.1  skrll 	      && !bfd_elf_gc_record_vtentry (abfd, sec, &hh->eh, rela->r_addend))
   1294  1.1  skrll 	    return FALSE;
   1295  1.1  skrll 	  continue;
   1296  1.1  skrll 
   1297  1.1  skrll 	case R_PARISC_TLS_GD21L:
   1298  1.1  skrll 	case R_PARISC_TLS_GD14R:
   1299  1.1  skrll 	case R_PARISC_TLS_LDM21L:
   1300  1.1  skrll 	case R_PARISC_TLS_LDM14R:
   1301  1.1  skrll 	  need_entry = NEED_GOT;
   1302  1.1  skrll 	  break;
   1303  1.1  skrll 
   1304  1.1  skrll 	case R_PARISC_TLS_IE21L:
   1305  1.1  skrll 	case R_PARISC_TLS_IE14R:
   1306  1.1  skrll 	  if (info->shared)
   1307  1.1  skrll             info->flags |= DF_STATIC_TLS;
   1308  1.1  skrll 	  need_entry = NEED_GOT;
   1309  1.1  skrll 	  break;
   1310  1.1  skrll 
   1311  1.1  skrll 	default:
   1312  1.1  skrll 	  continue;
   1313  1.1  skrll 	}
   1314  1.1  skrll 
   1315  1.1  skrll       /* Now carry out our orders.  */
   1316  1.1  skrll       if (need_entry & NEED_GOT)
   1317  1.1  skrll 	{
   1318  1.1  skrll 	  switch (r_type)
   1319  1.1  skrll 	    {
   1320  1.1  skrll 	    default:
   1321  1.1  skrll 	      tls_type = GOT_NORMAL;
   1322  1.1  skrll 	      break;
   1323  1.1  skrll 	    case R_PARISC_TLS_GD21L:
   1324  1.1  skrll 	    case R_PARISC_TLS_GD14R:
   1325  1.1  skrll 	      tls_type |= GOT_TLS_GD;
   1326  1.1  skrll 	      break;
   1327  1.1  skrll 	    case R_PARISC_TLS_LDM21L:
   1328  1.1  skrll 	    case R_PARISC_TLS_LDM14R:
   1329  1.1  skrll 	      tls_type |= GOT_TLS_LDM;
   1330  1.1  skrll 	      break;
   1331  1.1  skrll 	    case R_PARISC_TLS_IE21L:
   1332  1.1  skrll 	    case R_PARISC_TLS_IE14R:
   1333  1.1  skrll 	      tls_type |= GOT_TLS_IE;
   1334  1.1  skrll 	      break;
   1335  1.1  skrll 	    }
   1336  1.1  skrll 
   1337  1.1  skrll 	  /* Allocate space for a GOT entry, as well as a dynamic
   1338  1.1  skrll 	     relocation for this entry.  */
   1339  1.1  skrll 	  if (htab->sgot == NULL)
   1340  1.1  skrll 	    {
   1341  1.1  skrll 	      if (htab->etab.dynobj == NULL)
   1342  1.1  skrll 		htab->etab.dynobj = abfd;
   1343  1.1  skrll 	      if (!elf32_hppa_create_dynamic_sections (htab->etab.dynobj, info))
   1344  1.1  skrll 		return FALSE;
   1345  1.1  skrll 	    }
   1346  1.1  skrll 
   1347  1.1  skrll 	  if (r_type == R_PARISC_TLS_LDM21L
   1348  1.1  skrll 	      || r_type == R_PARISC_TLS_LDM14R)
   1349  1.1  skrll 	    hppa_link_hash_table (info)->tls_ldm_got.refcount += 1;
   1350  1.1  skrll 	  else
   1351  1.1  skrll 	    {
   1352  1.1  skrll 	      if (hh != NULL)
   1353  1.1  skrll 	        {
   1354  1.1  skrll 	          hh->eh.got.refcount += 1;
   1355  1.1  skrll 	          old_tls_type = hh->tls_type;
   1356  1.1  skrll 	        }
   1357  1.1  skrll 	      else
   1358  1.1  skrll 	        {
   1359  1.1  skrll 	          bfd_signed_vma *local_got_refcounts;
   1360  1.1  skrll 
   1361  1.1  skrll 	          /* This is a global offset table entry for a local symbol.  */
   1362  1.1  skrll 	          local_got_refcounts = elf_local_got_refcounts (abfd);
   1363  1.1  skrll 	          if (local_got_refcounts == NULL)
   1364  1.1  skrll 		    {
   1365  1.1  skrll 		      bfd_size_type size;
   1366  1.1  skrll 
   1367  1.1  skrll 		      /* Allocate space for local got offsets and local
   1368  1.1  skrll 		         plt offsets.  Done this way to save polluting
   1369  1.1  skrll 		         elf_obj_tdata with another target specific
   1370  1.1  skrll 		         pointer.  */
   1371  1.1  skrll 		      size = symtab_hdr->sh_info;
   1372  1.1  skrll 		      size *= 2 * sizeof (bfd_signed_vma);
   1373  1.1  skrll 		      /* Add in space to store the local GOT TLS types.  */
   1374  1.1  skrll 		      size += symtab_hdr->sh_info;
   1375  1.1  skrll 		      local_got_refcounts = bfd_zalloc (abfd, size);
   1376  1.1  skrll 		      if (local_got_refcounts == NULL)
   1377  1.1  skrll 		        return FALSE;
   1378  1.1  skrll 		      elf_local_got_refcounts (abfd) = local_got_refcounts;
   1379  1.1  skrll 		      memset (hppa_elf_local_got_tls_type (abfd),
   1380  1.1  skrll 		    	  GOT_UNKNOWN, symtab_hdr->sh_info);
   1381  1.1  skrll 		    }
   1382  1.1  skrll 	          local_got_refcounts[r_symndx] += 1;
   1383  1.1  skrll 
   1384  1.1  skrll 	          old_tls_type = hppa_elf_local_got_tls_type (abfd) [r_symndx];
   1385  1.1  skrll 	        }
   1386  1.1  skrll 
   1387  1.1  skrll 	      tls_type |= old_tls_type;
   1388  1.1  skrll 
   1389  1.1  skrll 	      if (old_tls_type != tls_type)
   1390  1.1  skrll 	        {
   1391  1.1  skrll 	          if (hh != NULL)
   1392  1.1  skrll 		    hh->tls_type = tls_type;
   1393  1.1  skrll 	          else
   1394  1.1  skrll 		    hppa_elf_local_got_tls_type (abfd) [r_symndx] = tls_type;
   1395  1.1  skrll 	        }
   1396  1.1  skrll 
   1397  1.1  skrll 	    }
   1398  1.1  skrll 	}
   1399  1.1  skrll 
   1400  1.1  skrll       if (need_entry & NEED_PLT)
   1401  1.1  skrll 	{
   1402  1.1  skrll 	  /* If we are creating a shared library, and this is a reloc
   1403  1.1  skrll 	     against a weak symbol or a global symbol in a dynamic
   1404  1.1  skrll 	     object, then we will be creating an import stub and a
   1405  1.1  skrll 	     .plt entry for the symbol.  Similarly, on a normal link
   1406  1.1  skrll 	     to symbols defined in a dynamic object we'll need the
   1407  1.1  skrll 	     import stub and a .plt entry.  We don't know yet whether
   1408  1.1  skrll 	     the symbol is defined or not, so make an entry anyway and
   1409  1.1  skrll 	     clean up later in adjust_dynamic_symbol.  */
   1410  1.1  skrll 	  if ((sec->flags & SEC_ALLOC) != 0)
   1411  1.1  skrll 	    {
   1412  1.1  skrll 	      if (hh != NULL)
   1413  1.1  skrll 		{
   1414  1.1  skrll 		  hh->eh.needs_plt = 1;
   1415  1.1  skrll 		  hh->eh.plt.refcount += 1;
   1416  1.1  skrll 
   1417  1.1  skrll 		  /* If this .plt entry is for a plabel, mark it so
   1418  1.1  skrll 		     that adjust_dynamic_symbol will keep the entry
   1419  1.1  skrll 		     even if it appears to be local.  */
   1420  1.1  skrll 		  if (need_entry & PLT_PLABEL)
   1421  1.1  skrll 		    hh->plabel = 1;
   1422  1.1  skrll 		}
   1423  1.1  skrll 	      else if (need_entry & PLT_PLABEL)
   1424  1.1  skrll 		{
   1425  1.1  skrll 		  bfd_signed_vma *local_got_refcounts;
   1426  1.1  skrll 		  bfd_signed_vma *local_plt_refcounts;
   1427  1.1  skrll 
   1428  1.1  skrll 		  local_got_refcounts = elf_local_got_refcounts (abfd);
   1429  1.1  skrll 		  if (local_got_refcounts == NULL)
   1430  1.1  skrll 		    {
   1431  1.1  skrll 		      bfd_size_type size;
   1432  1.1  skrll 
   1433  1.1  skrll 		      /* Allocate space for local got offsets and local
   1434  1.1  skrll 			 plt offsets.  */
   1435  1.1  skrll 		      size = symtab_hdr->sh_info;
   1436  1.1  skrll 		      size *= 2 * sizeof (bfd_signed_vma);
   1437  1.1  skrll 		      /* Add in space to store the local GOT TLS types.  */
   1438  1.1  skrll 		      size += symtab_hdr->sh_info;
   1439  1.1  skrll 		      local_got_refcounts = bfd_zalloc (abfd, size);
   1440  1.1  skrll 		      if (local_got_refcounts == NULL)
   1441  1.1  skrll 			return FALSE;
   1442  1.1  skrll 		      elf_local_got_refcounts (abfd) = local_got_refcounts;
   1443  1.1  skrll 		    }
   1444  1.1  skrll 		  local_plt_refcounts = (local_got_refcounts
   1445  1.1  skrll 					 + symtab_hdr->sh_info);
   1446  1.1  skrll 		  local_plt_refcounts[r_symndx] += 1;
   1447  1.1  skrll 		}
   1448  1.1  skrll 	    }
   1449  1.1  skrll 	}
   1450  1.1  skrll 
   1451  1.1  skrll       if (need_entry & NEED_DYNREL)
   1452  1.1  skrll 	{
   1453  1.1  skrll 	  /* Flag this symbol as having a non-got, non-plt reference
   1454  1.1  skrll 	     so that we generate copy relocs if it turns out to be
   1455  1.1  skrll 	     dynamic.  */
   1456  1.1  skrll 	  if (hh != NULL && !info->shared)
   1457  1.1  skrll 	    hh->eh.non_got_ref = 1;
   1458  1.1  skrll 
   1459  1.1  skrll 	  /* If we are creating a shared library then we need to copy
   1460  1.1  skrll 	     the reloc into the shared library.  However, if we are
   1461  1.1  skrll 	     linking with -Bsymbolic, we need only copy absolute
   1462  1.1  skrll 	     relocs or relocs against symbols that are not defined in
   1463  1.1  skrll 	     an object we are including in the link.  PC- or DP- or
   1464  1.1  skrll 	     DLT-relative relocs against any local sym or global sym
   1465  1.1  skrll 	     with DEF_REGULAR set, can be discarded.  At this point we
   1466  1.1  skrll 	     have not seen all the input files, so it is possible that
   1467  1.1  skrll 	     DEF_REGULAR is not set now but will be set later (it is
   1468  1.1  skrll 	     never cleared).  We account for that possibility below by
   1469  1.1  skrll 	     storing information in the dyn_relocs field of the
   1470  1.1  skrll 	     hash table entry.
   1471  1.1  skrll 
   1472  1.1  skrll 	     A similar situation to the -Bsymbolic case occurs when
   1473  1.1  skrll 	     creating shared libraries and symbol visibility changes
   1474  1.1  skrll 	     render the symbol local.
   1475  1.1  skrll 
   1476  1.1  skrll 	     As it turns out, all the relocs we will be creating here
   1477  1.1  skrll 	     are absolute, so we cannot remove them on -Bsymbolic
   1478  1.1  skrll 	     links or visibility changes anyway.  A STUB_REL reloc
   1479  1.1  skrll 	     is absolute too, as in that case it is the reloc in the
   1480  1.1  skrll 	     stub we will be creating, rather than copying the PCREL
   1481  1.1  skrll 	     reloc in the branch.
   1482  1.1  skrll 
   1483  1.1  skrll 	     If on the other hand, we are creating an executable, we
   1484  1.1  skrll 	     may need to keep relocations for symbols satisfied by a
   1485  1.1  skrll 	     dynamic library if we manage to avoid copy relocs for the
   1486  1.1  skrll 	     symbol.  */
   1487  1.1  skrll 	  if ((info->shared
   1488  1.1  skrll 	       && (sec->flags & SEC_ALLOC) != 0
   1489  1.1  skrll 	       && (IS_ABSOLUTE_RELOC (r_type)
   1490  1.1  skrll 		   || (hh != NULL
   1491  1.1  skrll 		       && (!info->symbolic
   1492  1.1  skrll 			   || hh->eh.root.type == bfd_link_hash_defweak
   1493  1.1  skrll 			   || !hh->eh.def_regular))))
   1494  1.1  skrll 	      || (ELIMINATE_COPY_RELOCS
   1495  1.1  skrll 		  && !info->shared
   1496  1.1  skrll 		  && (sec->flags & SEC_ALLOC) != 0
   1497  1.1  skrll 		  && hh != NULL
   1498  1.1  skrll 		  && (hh->eh.root.type == bfd_link_hash_defweak
   1499  1.1  skrll 		      || !hh->eh.def_regular)))
   1500  1.1  skrll 	    {
   1501  1.1  skrll 	      struct elf32_hppa_dyn_reloc_entry *hdh_p;
   1502  1.1  skrll 	      struct elf32_hppa_dyn_reloc_entry **hdh_head;
   1503  1.1  skrll 
   1504  1.1  skrll 	      /* Create a reloc section in dynobj and make room for
   1505  1.1  skrll 		 this reloc.  */
   1506  1.1  skrll 	      if (sreloc == NULL)
   1507  1.1  skrll 		{
   1508  1.1  skrll 		  char *name;
   1509  1.1  skrll 		  bfd *dynobj;
   1510  1.1  skrll 
   1511  1.1  skrll 		  name = (bfd_elf_string_from_elf_section
   1512  1.1  skrll 			  (abfd,
   1513  1.1  skrll 			   elf_elfheader (abfd)->e_shstrndx,
   1514  1.1  skrll 			   elf_section_data (sec)->rel_hdr.sh_name));
   1515  1.1  skrll 		  if (name == NULL)
   1516  1.1  skrll 		    {
   1517  1.1  skrll 		      (*_bfd_error_handler)
   1518  1.1  skrll 			(_("Could not find relocation section for %s"),
   1519  1.1  skrll 			 sec->name);
   1520  1.1  skrll 		      bfd_set_error (bfd_error_bad_value);
   1521  1.1  skrll 		      return FALSE;
   1522  1.1  skrll 		    }
   1523  1.1  skrll 
   1524  1.1  skrll 		  if (htab->etab.dynobj == NULL)
   1525  1.1  skrll 		    htab->etab.dynobj = abfd;
   1526  1.1  skrll 
   1527  1.1  skrll 		  dynobj = htab->etab.dynobj;
   1528  1.1  skrll 		  sreloc = bfd_get_section_by_name (dynobj, name);
   1529  1.1  skrll 		  if (sreloc == NULL)
   1530  1.1  skrll 		    {
   1531  1.1  skrll 		      flagword flags;
   1532  1.1  skrll 
   1533  1.1  skrll 		      flags = (SEC_HAS_CONTENTS | SEC_READONLY
   1534  1.1  skrll 			       | SEC_IN_MEMORY | SEC_LINKER_CREATED);
   1535  1.1  skrll 		      if ((sec->flags & SEC_ALLOC) != 0)
   1536  1.1  skrll 			flags |= SEC_ALLOC | SEC_LOAD;
   1537  1.1  skrll 		      sreloc = bfd_make_section_with_flags (dynobj,
   1538  1.1  skrll 							    name,
   1539  1.1  skrll 							    flags);
   1540  1.1  skrll 		      if (sreloc == NULL
   1541  1.1  skrll 			  || !bfd_set_section_alignment (dynobj, sreloc, 2))
   1542  1.1  skrll 			return FALSE;
   1543  1.1  skrll 		    }
   1544  1.1  skrll 
   1545  1.1  skrll 		  elf_section_data (sec)->sreloc = sreloc;
   1546  1.1  skrll 		}
   1547  1.1  skrll 
   1548  1.1  skrll 	      /* If this is a global symbol, we count the number of
   1549  1.1  skrll 		 relocations we need for this symbol.  */
   1550  1.1  skrll 	      if (hh != NULL)
   1551  1.1  skrll 		{
   1552  1.1  skrll 		  hdh_head = &hh->dyn_relocs;
   1553  1.1  skrll 		}
   1554  1.1  skrll 	      else
   1555  1.1  skrll 		{
   1556  1.1  skrll 		  /* Track dynamic relocs needed for local syms too.
   1557  1.1  skrll 		     We really need local syms available to do this
   1558  1.1  skrll 		     easily.  Oh well.  */
   1559  1.1  skrll 
   1560  1.1  skrll 		  asection *sr;
   1561  1.1  skrll 		  void *vpp;
   1562  1.1  skrll 
   1563  1.1  skrll 		  sr = bfd_section_from_r_symndx (abfd, &htab->sym_sec,
   1564  1.1  skrll 						       sec, r_symndx);
   1565  1.1  skrll 		  if (sr == NULL)
   1566  1.1  skrll 		    return FALSE;
   1567  1.1  skrll 
   1568  1.1  skrll 		  vpp = &elf_section_data (sr)->local_dynrel;
   1569  1.1  skrll 		  hdh_head = (struct elf32_hppa_dyn_reloc_entry **) vpp;
   1570  1.1  skrll 		}
   1571  1.1  skrll 
   1572  1.1  skrll 	      hdh_p = *hdh_head;
   1573  1.1  skrll 	      if (hdh_p == NULL || hdh_p->sec != sec)
   1574  1.1  skrll 		{
   1575  1.1  skrll 		  hdh_p = bfd_alloc (htab->etab.dynobj, sizeof *hdh_p);
   1576  1.1  skrll 		  if (hdh_p == NULL)
   1577  1.1  skrll 		    return FALSE;
   1578  1.1  skrll 		  hdh_p->hdh_next = *hdh_head;
   1579  1.1  skrll 		  *hdh_head = hdh_p;
   1580  1.1  skrll 		  hdh_p->sec = sec;
   1581  1.1  skrll 		  hdh_p->count = 0;
   1582  1.1  skrll #if RELATIVE_DYNRELOCS
   1583  1.1  skrll 		  hdh_p->relative_count = 0;
   1584  1.1  skrll #endif
   1585  1.1  skrll 		}
   1586  1.1  skrll 
   1587  1.1  skrll 	      hdh_p->count += 1;
   1588  1.1  skrll #if RELATIVE_DYNRELOCS
   1589  1.1  skrll 	      if (!IS_ABSOLUTE_RELOC (rtype))
   1590  1.1  skrll 		hdh_p->relative_count += 1;
   1591  1.1  skrll #endif
   1592  1.1  skrll 	    }
   1593  1.1  skrll 	}
   1594  1.1  skrll     }
   1595  1.1  skrll 
   1596  1.1  skrll   return TRUE;
   1597  1.1  skrll }
   1598  1.1  skrll 
   1599  1.1  skrll /* Return the section that should be marked against garbage collection
   1600  1.1  skrll    for a given relocation.  */
   1601  1.1  skrll 
   1602  1.1  skrll static asection *
   1603  1.1  skrll elf32_hppa_gc_mark_hook (asection *sec,
   1604  1.1  skrll 			 struct bfd_link_info *info,
   1605  1.1  skrll 			 Elf_Internal_Rela *rela,
   1606  1.1  skrll 			 struct elf_link_hash_entry *hh,
   1607  1.1  skrll 			 Elf_Internal_Sym *sym)
   1608  1.1  skrll {
   1609  1.1  skrll   if (hh != NULL)
   1610  1.1  skrll     switch ((unsigned int) ELF32_R_TYPE (rela->r_info))
   1611  1.1  skrll       {
   1612  1.1  skrll       case R_PARISC_GNU_VTINHERIT:
   1613  1.1  skrll       case R_PARISC_GNU_VTENTRY:
   1614  1.1  skrll 	return NULL;
   1615  1.1  skrll       }
   1616  1.1  skrll 
   1617  1.1  skrll   return _bfd_elf_gc_mark_hook (sec, info, rela, hh, sym);
   1618  1.1  skrll }
   1619  1.1  skrll 
   1620  1.1  skrll /* Update the got and plt entry reference counts for the section being
   1621  1.1  skrll    removed.  */
   1622  1.1  skrll 
   1623  1.1  skrll static bfd_boolean
   1624  1.1  skrll elf32_hppa_gc_sweep_hook (bfd *abfd,
   1625  1.1  skrll 			  struct bfd_link_info *info ATTRIBUTE_UNUSED,
   1626  1.1  skrll 			  asection *sec,
   1627  1.1  skrll 			  const Elf_Internal_Rela *relocs)
   1628  1.1  skrll {
   1629  1.1  skrll   Elf_Internal_Shdr *symtab_hdr;
   1630  1.1  skrll   struct elf_link_hash_entry **eh_syms;
   1631  1.1  skrll   bfd_signed_vma *local_got_refcounts;
   1632  1.1  skrll   bfd_signed_vma *local_plt_refcounts;
   1633  1.1  skrll   const Elf_Internal_Rela *rela, *relend;
   1634  1.1  skrll 
   1635  1.1  skrll   if (info->relocatable)
   1636  1.1  skrll     return TRUE;
   1637  1.1  skrll 
   1638  1.1  skrll   elf_section_data (sec)->local_dynrel = NULL;
   1639  1.1  skrll 
   1640  1.1  skrll   symtab_hdr = &elf_tdata (abfd)->symtab_hdr;
   1641  1.1  skrll   eh_syms = elf_sym_hashes (abfd);
   1642  1.1  skrll   local_got_refcounts = elf_local_got_refcounts (abfd);
   1643  1.1  skrll   local_plt_refcounts = local_got_refcounts;
   1644  1.1  skrll   if (local_plt_refcounts != NULL)
   1645  1.1  skrll     local_plt_refcounts += symtab_hdr->sh_info;
   1646  1.1  skrll 
   1647  1.1  skrll   relend = relocs + sec->reloc_count;
   1648  1.1  skrll   for (rela = relocs; rela < relend; rela++)
   1649  1.1  skrll     {
   1650  1.1  skrll       unsigned long r_symndx;
   1651  1.1  skrll       unsigned int r_type;
   1652  1.1  skrll       struct elf_link_hash_entry *eh = NULL;
   1653  1.1  skrll 
   1654  1.1  skrll       r_symndx = ELF32_R_SYM (rela->r_info);
   1655  1.1  skrll       if (r_symndx >= symtab_hdr->sh_info)
   1656  1.1  skrll 	{
   1657  1.1  skrll 	  struct elf32_hppa_link_hash_entry *hh;
   1658  1.1  skrll 	  struct elf32_hppa_dyn_reloc_entry **hdh_pp;
   1659  1.1  skrll 	  struct elf32_hppa_dyn_reloc_entry *hdh_p;
   1660  1.1  skrll 
   1661  1.1  skrll 	  eh = eh_syms[r_symndx - symtab_hdr->sh_info];
   1662  1.1  skrll 	  while (eh->root.type == bfd_link_hash_indirect
   1663  1.1  skrll 		 || eh->root.type == bfd_link_hash_warning)
   1664  1.1  skrll 	    eh = (struct elf_link_hash_entry *) eh->root.u.i.link;
   1665  1.1  skrll 	  hh = hppa_elf_hash_entry (eh);
   1666  1.1  skrll 
   1667  1.1  skrll 	  for (hdh_pp = &hh->dyn_relocs; (hdh_p = *hdh_pp) != NULL; hdh_pp = &hdh_p->hdh_next)
   1668  1.1  skrll 	    if (hdh_p->sec == sec)
   1669  1.1  skrll 	      {
   1670  1.1  skrll 		/* Everything must go for SEC.  */
   1671  1.1  skrll 		*hdh_pp = hdh_p->hdh_next;
   1672  1.1  skrll 		break;
   1673  1.1  skrll 	      }
   1674  1.1  skrll 	}
   1675  1.1  skrll 
   1676  1.1  skrll       r_type = ELF32_R_TYPE (rela->r_info);
   1677  1.1  skrll       r_type = elf32_hppa_optimized_tls_reloc (info, r_type, eh != NULL);
   1678  1.1  skrll 
   1679  1.1  skrll       switch (r_type)
   1680  1.1  skrll 	{
   1681  1.1  skrll 	case R_PARISC_DLTIND14F:
   1682  1.1  skrll 	case R_PARISC_DLTIND14R:
   1683  1.1  skrll 	case R_PARISC_DLTIND21L:
   1684  1.1  skrll 	case R_PARISC_TLS_GD21L:
   1685  1.1  skrll 	case R_PARISC_TLS_GD14R:
   1686  1.1  skrll 	case R_PARISC_TLS_IE21L:
   1687  1.1  skrll 	case R_PARISC_TLS_IE14R:
   1688  1.1  skrll 	  if (eh != NULL)
   1689  1.1  skrll 	    {
   1690  1.1  skrll 	      if (eh->got.refcount > 0)
   1691  1.1  skrll 		eh->got.refcount -= 1;
   1692  1.1  skrll 	    }
   1693  1.1  skrll 	  else if (local_got_refcounts != NULL)
   1694  1.1  skrll 	    {
   1695  1.1  skrll 	      if (local_got_refcounts[r_symndx] > 0)
   1696  1.1  skrll 		local_got_refcounts[r_symndx] -= 1;
   1697  1.1  skrll 	    }
   1698  1.1  skrll 	  break;
   1699  1.1  skrll 
   1700  1.1  skrll 	case R_PARISC_TLS_LDM21L:
   1701  1.1  skrll 	case R_PARISC_TLS_LDM14R:
   1702  1.1  skrll 	  hppa_link_hash_table (info)->tls_ldm_got.refcount -= 1;
   1703  1.1  skrll 	  break;
   1704  1.1  skrll 
   1705  1.1  skrll 	case R_PARISC_PCREL12F:
   1706  1.1  skrll 	case R_PARISC_PCREL17C:
   1707  1.1  skrll 	case R_PARISC_PCREL17F:
   1708  1.1  skrll 	case R_PARISC_PCREL22F:
   1709  1.1  skrll 	  if (eh != NULL)
   1710  1.1  skrll 	    {
   1711  1.1  skrll 	      if (eh->plt.refcount > 0)
   1712  1.1  skrll 		eh->plt.refcount -= 1;
   1713  1.1  skrll 	    }
   1714  1.1  skrll 	  break;
   1715  1.1  skrll 
   1716  1.1  skrll 	case R_PARISC_PLABEL14R:
   1717  1.1  skrll 	case R_PARISC_PLABEL21L:
   1718  1.1  skrll 	case R_PARISC_PLABEL32:
   1719  1.1  skrll 	  if (eh != NULL)
   1720  1.1  skrll 	    {
   1721  1.1  skrll 	      if (eh->plt.refcount > 0)
   1722  1.1  skrll 		eh->plt.refcount -= 1;
   1723  1.1  skrll 	    }
   1724  1.1  skrll 	  else if (local_plt_refcounts != NULL)
   1725  1.1  skrll 	    {
   1726  1.1  skrll 	      if (local_plt_refcounts[r_symndx] > 0)
   1727  1.1  skrll 		local_plt_refcounts[r_symndx] -= 1;
   1728  1.1  skrll 	    }
   1729  1.1  skrll 	  break;
   1730  1.1  skrll 
   1731  1.1  skrll 	default:
   1732  1.1  skrll 	  break;
   1733  1.1  skrll 	}
   1734  1.1  skrll     }
   1735  1.1  skrll 
   1736  1.1  skrll   return TRUE;
   1737  1.1  skrll }
   1738  1.1  skrll 
   1739  1.1  skrll /* Support for core dump NOTE sections.  */
   1740  1.1  skrll 
   1741  1.1  skrll static bfd_boolean
   1742  1.1  skrll elf32_hppa_grok_prstatus (bfd *abfd, Elf_Internal_Note *note)
   1743  1.1  skrll {
   1744  1.1  skrll   int offset;
   1745  1.1  skrll   size_t size;
   1746  1.1  skrll 
   1747  1.1  skrll   switch (note->descsz)
   1748  1.1  skrll     {
   1749  1.1  skrll       default:
   1750  1.1  skrll 	return FALSE;
   1751  1.1  skrll 
   1752  1.1  skrll       case 396:		/* Linux/hppa */
   1753  1.1  skrll 	/* pr_cursig */
   1754  1.1  skrll 	elf_tdata (abfd)->core_signal = bfd_get_16 (abfd, note->descdata + 12);
   1755  1.1  skrll 
   1756  1.1  skrll 	/* pr_pid */
   1757  1.1  skrll 	elf_tdata (abfd)->core_pid = bfd_get_32 (abfd, note->descdata + 24);
   1758  1.1  skrll 
   1759  1.1  skrll 	/* pr_reg */
   1760  1.1  skrll 	offset = 72;
   1761  1.1  skrll 	size = 320;
   1762  1.1  skrll 
   1763  1.1  skrll 	break;
   1764  1.1  skrll     }
   1765  1.1  skrll 
   1766  1.1  skrll   /* Make a ".reg/999" section.  */
   1767  1.1  skrll   return _bfd_elfcore_make_pseudosection (abfd, ".reg",
   1768  1.1  skrll 					  size, note->descpos + offset);
   1769  1.1  skrll }
   1770  1.1  skrll 
   1771  1.1  skrll static bfd_boolean
   1772  1.1  skrll elf32_hppa_grok_psinfo (bfd *abfd, Elf_Internal_Note *note)
   1773  1.1  skrll {
   1774  1.1  skrll   switch (note->descsz)
   1775  1.1  skrll     {
   1776  1.1  skrll       default:
   1777  1.1  skrll 	return FALSE;
   1778  1.1  skrll 
   1779  1.1  skrll       case 124:		/* Linux/hppa elf_prpsinfo.  */
   1780  1.1  skrll 	elf_tdata (abfd)->core_program
   1781  1.1  skrll 	  = _bfd_elfcore_strndup (abfd, note->descdata + 28, 16);
   1782  1.1  skrll 	elf_tdata (abfd)->core_command
   1783  1.1  skrll 	  = _bfd_elfcore_strndup (abfd, note->descdata + 44, 80);
   1784  1.1  skrll     }
   1785  1.1  skrll 
   1786  1.1  skrll   /* Note that for some reason, a spurious space is tacked
   1787  1.1  skrll      onto the end of the args in some (at least one anyway)
   1788  1.1  skrll      implementations, so strip it off if it exists.  */
   1789  1.1  skrll   {
   1790  1.1  skrll     char *command = elf_tdata (abfd)->core_command;
   1791  1.1  skrll     int n = strlen (command);
   1792  1.1  skrll 
   1793  1.1  skrll     if (0 < n && command[n - 1] == ' ')
   1794  1.1  skrll       command[n - 1] = '\0';
   1795  1.1  skrll   }
   1796  1.1  skrll 
   1797  1.1  skrll   return TRUE;
   1798  1.1  skrll }
   1799  1.1  skrll 
   1800  1.1  skrll /* Our own version of hide_symbol, so that we can keep plt entries for
   1801  1.1  skrll    plabels.  */
   1802  1.1  skrll 
   1803  1.1  skrll static void
   1804  1.1  skrll elf32_hppa_hide_symbol (struct bfd_link_info *info,
   1805  1.1  skrll 			struct elf_link_hash_entry *eh,
   1806  1.1  skrll 			bfd_boolean force_local)
   1807  1.1  skrll {
   1808  1.1  skrll   if (force_local)
   1809  1.1  skrll     {
   1810  1.1  skrll       eh->forced_local = 1;
   1811  1.1  skrll       if (eh->dynindx != -1)
   1812  1.1  skrll 	{
   1813  1.1  skrll 	  eh->dynindx = -1;
   1814  1.1  skrll 	  _bfd_elf_strtab_delref (elf_hash_table (info)->dynstr,
   1815  1.1  skrll 				  eh->dynstr_index);
   1816  1.1  skrll 	}
   1817  1.1  skrll     }
   1818  1.1  skrll 
   1819  1.1  skrll   if (! hppa_elf_hash_entry (eh)->plabel)
   1820  1.1  skrll     {
   1821  1.1  skrll       eh->needs_plt = 0;
   1822  1.1  skrll       eh->plt = elf_hash_table (info)->init_plt_refcount;
   1823  1.1  skrll     }
   1824  1.1  skrll }
   1825  1.1  skrll 
   1826  1.1  skrll /* Adjust a symbol defined by a dynamic object and referenced by a
   1827  1.1  skrll    regular object.  The current definition is in some section of the
   1828  1.1  skrll    dynamic object, but we're not including those sections.  We have to
   1829  1.1  skrll    change the definition to something the rest of the link can
   1830  1.1  skrll    understand.  */
   1831  1.1  skrll 
   1832  1.1  skrll static bfd_boolean
   1833  1.1  skrll elf32_hppa_adjust_dynamic_symbol (struct bfd_link_info *info,
   1834  1.1  skrll 				  struct elf_link_hash_entry *eh)
   1835  1.1  skrll {
   1836  1.1  skrll   struct elf32_hppa_link_hash_table *htab;
   1837  1.1  skrll   asection *sec;
   1838  1.1  skrll 
   1839  1.1  skrll   /* If this is a function, put it in the procedure linkage table.  We
   1840  1.1  skrll      will fill in the contents of the procedure linkage table later.  */
   1841  1.1  skrll   if (eh->type == STT_FUNC
   1842  1.1  skrll       || eh->needs_plt)
   1843  1.1  skrll     {
   1844  1.1  skrll       if (eh->plt.refcount <= 0
   1845  1.1  skrll 	  || (eh->def_regular
   1846  1.1  skrll 	      && eh->root.type != bfd_link_hash_defweak
   1847  1.1  skrll 	      && ! hppa_elf_hash_entry (eh)->plabel
   1848  1.1  skrll 	      && (!info->shared || info->symbolic)))
   1849  1.1  skrll 	{
   1850  1.1  skrll 	  /* The .plt entry is not needed when:
   1851  1.1  skrll 	     a) Garbage collection has removed all references to the
   1852  1.1  skrll 	     symbol, or
   1853  1.1  skrll 	     b) We know for certain the symbol is defined in this
   1854  1.1  skrll 	     object, and it's not a weak definition, nor is the symbol
   1855  1.1  skrll 	     used by a plabel relocation.  Either this object is the
   1856  1.1  skrll 	     application or we are doing a shared symbolic link.  */
   1857  1.1  skrll 
   1858  1.1  skrll 	  eh->plt.offset = (bfd_vma) -1;
   1859  1.1  skrll 	  eh->needs_plt = 0;
   1860  1.1  skrll 	}
   1861  1.1  skrll 
   1862  1.1  skrll       return TRUE;
   1863  1.1  skrll     }
   1864  1.1  skrll   else
   1865  1.1  skrll     eh->plt.offset = (bfd_vma) -1;
   1866  1.1  skrll 
   1867  1.1  skrll   /* If this is a weak symbol, and there is a real definition, the
   1868  1.1  skrll      processor independent code will have arranged for us to see the
   1869  1.1  skrll      real definition first, and we can just use the same value.  */
   1870  1.1  skrll   if (eh->u.weakdef != NULL)
   1871  1.1  skrll     {
   1872  1.1  skrll       if (eh->u.weakdef->root.type != bfd_link_hash_defined
   1873  1.1  skrll 	  && eh->u.weakdef->root.type != bfd_link_hash_defweak)
   1874  1.1  skrll 	abort ();
   1875  1.1  skrll       eh->root.u.def.section = eh->u.weakdef->root.u.def.section;
   1876  1.1  skrll       eh->root.u.def.value = eh->u.weakdef->root.u.def.value;
   1877  1.1  skrll       if (ELIMINATE_COPY_RELOCS)
   1878  1.1  skrll 	eh->non_got_ref = eh->u.weakdef->non_got_ref;
   1879  1.1  skrll       return TRUE;
   1880  1.1  skrll     }
   1881  1.1  skrll 
   1882  1.1  skrll   /* This is a reference to a symbol defined by a dynamic object which
   1883  1.1  skrll      is not a function.  */
   1884  1.1  skrll 
   1885  1.1  skrll   /* If we are creating a shared library, we must presume that the
   1886  1.1  skrll      only references to the symbol are via the global offset table.
   1887  1.1  skrll      For such cases we need not do anything here; the relocations will
   1888  1.1  skrll      be handled correctly by relocate_section.  */
   1889  1.1  skrll   if (info->shared)
   1890  1.1  skrll     return TRUE;
   1891  1.1  skrll 
   1892  1.1  skrll   /* If there are no references to this symbol that do not use the
   1893  1.1  skrll      GOT, we don't need to generate a copy reloc.  */
   1894  1.1  skrll   if (!eh->non_got_ref)
   1895  1.1  skrll     return TRUE;
   1896  1.1  skrll 
   1897  1.1  skrll   if (ELIMINATE_COPY_RELOCS)
   1898  1.1  skrll     {
   1899  1.1  skrll       struct elf32_hppa_link_hash_entry *hh;
   1900  1.1  skrll       struct elf32_hppa_dyn_reloc_entry *hdh_p;
   1901  1.1  skrll 
   1902  1.1  skrll       hh = hppa_elf_hash_entry (eh);
   1903  1.1  skrll       for (hdh_p = hh->dyn_relocs; hdh_p != NULL; hdh_p = hdh_p->hdh_next)
   1904  1.1  skrll 	{
   1905  1.1  skrll 	  sec = hdh_p->sec->output_section;
   1906  1.1  skrll 	  if (sec != NULL && (sec->flags & SEC_READONLY) != 0)
   1907  1.1  skrll 	    break;
   1908  1.1  skrll 	}
   1909  1.1  skrll 
   1910  1.1  skrll       /* If we didn't find any dynamic relocs in read-only sections, then
   1911  1.1  skrll 	 we'll be keeping the dynamic relocs and avoiding the copy reloc.  */
   1912  1.1  skrll       if (hdh_p == NULL)
   1913  1.1  skrll 	{
   1914  1.1  skrll 	  eh->non_got_ref = 0;
   1915  1.1  skrll 	  return TRUE;
   1916  1.1  skrll 	}
   1917  1.1  skrll     }
   1918  1.1  skrll 
   1919  1.1  skrll   if (eh->size == 0)
   1920  1.1  skrll     {
   1921  1.1  skrll       (*_bfd_error_handler) (_("dynamic variable `%s' is zero size"),
   1922  1.1  skrll 			     eh->root.root.string);
   1923  1.1  skrll       return TRUE;
   1924  1.1  skrll     }
   1925  1.1  skrll 
   1926  1.1  skrll   /* We must allocate the symbol in our .dynbss section, which will
   1927  1.1  skrll      become part of the .bss section of the executable.  There will be
   1928  1.1  skrll      an entry for this symbol in the .dynsym section.  The dynamic
   1929  1.1  skrll      object will contain position independent code, so all references
   1930  1.1  skrll      from the dynamic object to this symbol will go through the global
   1931  1.1  skrll      offset table.  The dynamic linker will use the .dynsym entry to
   1932  1.1  skrll      determine the address it must put in the global offset table, so
   1933  1.1  skrll      both the dynamic object and the regular object will refer to the
   1934  1.1  skrll      same memory location for the variable.  */
   1935  1.1  skrll 
   1936  1.1  skrll   htab = hppa_link_hash_table (info);
   1937  1.1  skrll 
   1938  1.1  skrll   /* We must generate a COPY reloc to tell the dynamic linker to
   1939  1.1  skrll      copy the initial value out of the dynamic object and into the
   1940  1.1  skrll      runtime process image.  */
   1941  1.1  skrll   if ((eh->root.u.def.section->flags & SEC_ALLOC) != 0)
   1942  1.1  skrll     {
   1943  1.1  skrll       htab->srelbss->size += sizeof (Elf32_External_Rela);
   1944  1.1  skrll       eh->needs_copy = 1;
   1945  1.1  skrll     }
   1946  1.1  skrll 
   1947  1.1  skrll   sec = htab->sdynbss;
   1948  1.1  skrll 
   1949  1.1  skrll   return _bfd_elf_adjust_dynamic_copy (eh, sec);
   1950  1.1  skrll }
   1951  1.1  skrll 
   1952  1.1  skrll /* Allocate space in the .plt for entries that won't have relocations.
   1953  1.1  skrll    ie. plabel entries.  */
   1954  1.1  skrll 
   1955  1.1  skrll static bfd_boolean
   1956  1.1  skrll allocate_plt_static (struct elf_link_hash_entry *eh, void *inf)
   1957  1.1  skrll {
   1958  1.1  skrll   struct bfd_link_info *info;
   1959  1.1  skrll   struct elf32_hppa_link_hash_table *htab;
   1960  1.1  skrll   struct elf32_hppa_link_hash_entry *hh;
   1961  1.1  skrll   asection *sec;
   1962  1.1  skrll 
   1963  1.1  skrll   if (eh->root.type == bfd_link_hash_indirect)
   1964  1.1  skrll     return TRUE;
   1965  1.1  skrll 
   1966  1.1  skrll   if (eh->root.type == bfd_link_hash_warning)
   1967  1.1  skrll     eh = (struct elf_link_hash_entry *) eh->root.u.i.link;
   1968  1.1  skrll 
   1969  1.1  skrll   info = (struct bfd_link_info *) inf;
   1970  1.1  skrll   hh = hppa_elf_hash_entry (eh);
   1971  1.1  skrll   htab = hppa_link_hash_table (info);
   1972  1.1  skrll   if (htab->etab.dynamic_sections_created
   1973  1.1  skrll       && eh->plt.refcount > 0)
   1974  1.1  skrll     {
   1975  1.1  skrll       /* Make sure this symbol is output as a dynamic symbol.
   1976  1.1  skrll 	 Undefined weak syms won't yet be marked as dynamic.  */
   1977  1.1  skrll       if (eh->dynindx == -1
   1978  1.1  skrll 	  && !eh->forced_local
   1979  1.1  skrll 	  && eh->type != STT_PARISC_MILLI)
   1980  1.1  skrll 	{
   1981  1.1  skrll 	  if (! bfd_elf_link_record_dynamic_symbol (info, eh))
   1982  1.1  skrll 	    return FALSE;
   1983  1.1  skrll 	}
   1984  1.1  skrll 
   1985  1.1  skrll       if (WILL_CALL_FINISH_DYNAMIC_SYMBOL (1, info->shared, eh))
   1986  1.1  skrll 	{
   1987  1.1  skrll 	  /* Allocate these later.  From this point on, h->plabel
   1988  1.1  skrll 	     means that the plt entry is only used by a plabel.
   1989  1.1  skrll 	     We'll be using a normal plt entry for this symbol, so
   1990  1.1  skrll 	     clear the plabel indicator.  */
   1991  1.1  skrll 
   1992  1.1  skrll 	  hh->plabel = 0;
   1993  1.1  skrll 	}
   1994  1.1  skrll       else if (hh->plabel)
   1995  1.1  skrll 	{
   1996  1.1  skrll 	  /* Make an entry in the .plt section for plabel references
   1997  1.1  skrll 	     that won't have a .plt entry for other reasons.  */
   1998  1.1  skrll 	  sec = htab->splt;
   1999  1.1  skrll 	  eh->plt.offset = sec->size;
   2000  1.1  skrll 	  sec->size += PLT_ENTRY_SIZE;
   2001  1.1  skrll 	}
   2002  1.1  skrll       else
   2003  1.1  skrll 	{
   2004  1.1  skrll 	  /* No .plt entry needed.  */
   2005  1.1  skrll 	  eh->plt.offset = (bfd_vma) -1;
   2006  1.1  skrll 	  eh->needs_plt = 0;
   2007  1.1  skrll 	}
   2008  1.1  skrll     }
   2009  1.1  skrll   else
   2010  1.1  skrll     {
   2011  1.1  skrll       eh->plt.offset = (bfd_vma) -1;
   2012  1.1  skrll       eh->needs_plt = 0;
   2013  1.1  skrll     }
   2014  1.1  skrll 
   2015  1.1  skrll   return TRUE;
   2016  1.1  skrll }
   2017  1.1  skrll 
   2018  1.1  skrll /* Allocate space in .plt, .got and associated reloc sections for
   2019  1.1  skrll    global syms.  */
   2020  1.1  skrll 
   2021  1.1  skrll static bfd_boolean
   2022  1.1  skrll allocate_dynrelocs (struct elf_link_hash_entry *eh, void *inf)
   2023  1.1  skrll {
   2024  1.1  skrll   struct bfd_link_info *info;
   2025  1.1  skrll   struct elf32_hppa_link_hash_table *htab;
   2026  1.1  skrll   asection *sec;
   2027  1.1  skrll   struct elf32_hppa_link_hash_entry *hh;
   2028  1.1  skrll   struct elf32_hppa_dyn_reloc_entry *hdh_p;
   2029  1.1  skrll 
   2030  1.1  skrll   if (eh->root.type == bfd_link_hash_indirect)
   2031  1.1  skrll     return TRUE;
   2032  1.1  skrll 
   2033  1.1  skrll   if (eh->root.type == bfd_link_hash_warning)
   2034  1.1  skrll     eh = (struct elf_link_hash_entry *) eh->root.u.i.link;
   2035  1.1  skrll 
   2036  1.1  skrll   info = inf;
   2037  1.1  skrll   htab = hppa_link_hash_table (info);
   2038  1.1  skrll   hh = hppa_elf_hash_entry (eh);
   2039  1.1  skrll 
   2040  1.1  skrll   if (htab->etab.dynamic_sections_created
   2041  1.1  skrll       && eh->plt.offset != (bfd_vma) -1
   2042  1.1  skrll       && !hh->plabel
   2043  1.1  skrll       && eh->plt.refcount > 0)
   2044  1.1  skrll     {
   2045  1.1  skrll       /* Make an entry in the .plt section.  */
   2046  1.1  skrll       sec = htab->splt;
   2047  1.1  skrll       eh->plt.offset = sec->size;
   2048  1.1  skrll       sec->size += PLT_ENTRY_SIZE;
   2049  1.1  skrll 
   2050  1.1  skrll       /* We also need to make an entry in the .rela.plt section.  */
   2051  1.1  skrll       htab->srelplt->size += sizeof (Elf32_External_Rela);
   2052  1.1  skrll       htab->need_plt_stub = 1;
   2053  1.1  skrll     }
   2054  1.1  skrll 
   2055  1.1  skrll   if (eh->got.refcount > 0)
   2056  1.1  skrll     {
   2057  1.1  skrll       /* Make sure this symbol is output as a dynamic symbol.
   2058  1.1  skrll 	 Undefined weak syms won't yet be marked as dynamic.  */
   2059  1.1  skrll       if (eh->dynindx == -1
   2060  1.1  skrll 	  && !eh->forced_local
   2061  1.1  skrll 	  && eh->type != STT_PARISC_MILLI)
   2062  1.1  skrll 	{
   2063  1.1  skrll 	  if (! bfd_elf_link_record_dynamic_symbol (info, eh))
   2064  1.1  skrll 	    return FALSE;
   2065  1.1  skrll 	}
   2066  1.1  skrll 
   2067  1.1  skrll       sec = htab->sgot;
   2068  1.1  skrll       eh->got.offset = sec->size;
   2069  1.1  skrll       sec->size += GOT_ENTRY_SIZE;
   2070  1.1  skrll       /* R_PARISC_TLS_GD* needs two GOT entries */
   2071  1.1  skrll       if ((hh->tls_type & (GOT_TLS_GD | GOT_TLS_IE)) == (GOT_TLS_GD | GOT_TLS_IE))
   2072  1.1  skrll       	sec->size += GOT_ENTRY_SIZE * 2;
   2073  1.1  skrll       else if ((hh->tls_type & GOT_TLS_GD) == GOT_TLS_GD)
   2074  1.1  skrll       	sec->size += GOT_ENTRY_SIZE;
   2075  1.1  skrll       if (htab->etab.dynamic_sections_created
   2076  1.1  skrll 	  && (info->shared
   2077  1.1  skrll 	      || (eh->dynindx != -1
   2078  1.1  skrll 		  && !eh->forced_local)))
   2079  1.1  skrll 	{
   2080  1.1  skrll 	  htab->srelgot->size += sizeof (Elf32_External_Rela);
   2081  1.1  skrll 	  if ((hh->tls_type & (GOT_TLS_GD | GOT_TLS_IE)) == (GOT_TLS_GD | GOT_TLS_IE))
   2082  1.1  skrll 	    htab->srelgot->size += 2 * sizeof (Elf32_External_Rela);
   2083  1.1  skrll 	  else if ((hh->tls_type & GOT_TLS_GD) == GOT_TLS_GD)
   2084  1.1  skrll 	    htab->srelgot->size += sizeof (Elf32_External_Rela);
   2085  1.1  skrll 	}
   2086  1.1  skrll     }
   2087  1.1  skrll   else
   2088  1.1  skrll     eh->got.offset = (bfd_vma) -1;
   2089  1.1  skrll 
   2090  1.1  skrll   if (hh->dyn_relocs == NULL)
   2091  1.1  skrll     return TRUE;
   2092  1.1  skrll 
   2093  1.1  skrll   /* If this is a -Bsymbolic shared link, then we need to discard all
   2094  1.1  skrll      space allocated for dynamic pc-relative relocs against symbols
   2095  1.1  skrll      defined in a regular object.  For the normal shared case, discard
   2096  1.1  skrll      space for relocs that have become local due to symbol visibility
   2097  1.1  skrll      changes.  */
   2098  1.1  skrll   if (info->shared)
   2099  1.1  skrll     {
   2100  1.1  skrll #if RELATIVE_DYNRELOCS
   2101  1.1  skrll       if (SYMBOL_CALLS_LOCAL (info, eh))
   2102  1.1  skrll 	{
   2103  1.1  skrll 	  struct elf32_hppa_dyn_reloc_entry **hdh_pp;
   2104  1.1  skrll 
   2105  1.1  skrll 	  for (hdh_pp = &hh->dyn_relocs; (hdh_p = *hdh_pp) != NULL; )
   2106  1.1  skrll 	    {
   2107  1.1  skrll 	      hdh_p->count -= hdh_p->relative_count;
   2108  1.1  skrll 	      hdh_p->relative_count = 0;
   2109  1.1  skrll 	      if (hdh_p->count == 0)
   2110  1.1  skrll 		*hdh_pp = hdh_p->hdh_next;
   2111  1.1  skrll 	      else
   2112  1.1  skrll 		hdh_pp = &hdh_p->hdh_next;
   2113  1.1  skrll 	    }
   2114  1.1  skrll 	}
   2115  1.1  skrll #endif
   2116  1.1  skrll 
   2117  1.1  skrll       /* Also discard relocs on undefined weak syms with non-default
   2118  1.1  skrll 	 visibility.  */
   2119  1.1  skrll       if (hh->dyn_relocs != NULL
   2120  1.1  skrll 	  && eh->root.type == bfd_link_hash_undefweak)
   2121  1.1  skrll 	{
   2122  1.1  skrll 	  if (ELF_ST_VISIBILITY (eh->other) != STV_DEFAULT)
   2123  1.1  skrll 	    hh->dyn_relocs = NULL;
   2124  1.1  skrll 
   2125  1.1  skrll 	  /* Make sure undefined weak symbols are output as a dynamic
   2126  1.1  skrll 	     symbol in PIEs.  */
   2127  1.1  skrll 	  else if (eh->dynindx == -1
   2128  1.1  skrll 		   && !eh->forced_local)
   2129  1.1  skrll 	    {
   2130  1.1  skrll 	      if (! bfd_elf_link_record_dynamic_symbol (info, eh))
   2131  1.1  skrll 		return FALSE;
   2132  1.1  skrll 	    }
   2133  1.1  skrll 	}
   2134  1.1  skrll     }
   2135  1.1  skrll   else
   2136  1.1  skrll     {
   2137  1.1  skrll       /* For the non-shared case, discard space for relocs against
   2138  1.1  skrll 	 symbols which turn out to need copy relocs or are not
   2139  1.1  skrll 	 dynamic.  */
   2140  1.1  skrll 
   2141  1.1  skrll       if (!eh->non_got_ref
   2142  1.1  skrll 	  && ((ELIMINATE_COPY_RELOCS
   2143  1.1  skrll 	       && eh->def_dynamic
   2144  1.1  skrll 	       && !eh->def_regular)
   2145  1.1  skrll 	       || (htab->etab.dynamic_sections_created
   2146  1.1  skrll 		   && (eh->root.type == bfd_link_hash_undefweak
   2147  1.1  skrll 		       || eh->root.type == bfd_link_hash_undefined))))
   2148  1.1  skrll 	{
   2149  1.1  skrll 	  /* Make sure this symbol is output as a dynamic symbol.
   2150  1.1  skrll 	     Undefined weak syms won't yet be marked as dynamic.  */
   2151  1.1  skrll 	  if (eh->dynindx == -1
   2152  1.1  skrll 	      && !eh->forced_local
   2153  1.1  skrll 	      && eh->type != STT_PARISC_MILLI)
   2154  1.1  skrll 	    {
   2155  1.1  skrll 	      if (! bfd_elf_link_record_dynamic_symbol (info, eh))
   2156  1.1  skrll 		return FALSE;
   2157  1.1  skrll 	    }
   2158  1.1  skrll 
   2159  1.1  skrll 	  /* If that succeeded, we know we'll be keeping all the
   2160  1.1  skrll 	     relocs.  */
   2161  1.1  skrll 	  if (eh->dynindx != -1)
   2162  1.1  skrll 	    goto keep;
   2163  1.1  skrll 	}
   2164  1.1  skrll 
   2165  1.1  skrll       hh->dyn_relocs = NULL;
   2166  1.1  skrll       return TRUE;
   2167  1.1  skrll 
   2168  1.1  skrll     keep: ;
   2169  1.1  skrll     }
   2170  1.1  skrll 
   2171  1.1  skrll   /* Finally, allocate space.  */
   2172  1.1  skrll   for (hdh_p = hh->dyn_relocs; hdh_p != NULL; hdh_p = hdh_p->hdh_next)
   2173  1.1  skrll     {
   2174  1.1  skrll       asection *sreloc = elf_section_data (hdh_p->sec)->sreloc;
   2175  1.1  skrll       sreloc->size += hdh_p->count * sizeof (Elf32_External_Rela);
   2176  1.1  skrll     }
   2177  1.1  skrll 
   2178  1.1  skrll   return TRUE;
   2179  1.1  skrll }
   2180  1.1  skrll 
   2181  1.1  skrll /* This function is called via elf_link_hash_traverse to force
   2182  1.1  skrll    millicode symbols local so they do not end up as globals in the
   2183  1.1  skrll    dynamic symbol table.  We ought to be able to do this in
   2184  1.1  skrll    adjust_dynamic_symbol, but our adjust_dynamic_symbol is not called
   2185  1.1  skrll    for all dynamic symbols.  Arguably, this is a bug in
   2186  1.1  skrll    elf_adjust_dynamic_symbol.  */
   2187  1.1  skrll 
   2188  1.1  skrll static bfd_boolean
   2189  1.1  skrll clobber_millicode_symbols (struct elf_link_hash_entry *eh,
   2190  1.1  skrll 			   struct bfd_link_info *info)
   2191  1.1  skrll {
   2192  1.1  skrll   if (eh->root.type == bfd_link_hash_warning)
   2193  1.1  skrll     eh = (struct elf_link_hash_entry *) eh->root.u.i.link;
   2194  1.1  skrll 
   2195  1.1  skrll   if (eh->type == STT_PARISC_MILLI
   2196  1.1  skrll       && !eh->forced_local)
   2197  1.1  skrll     {
   2198  1.1  skrll       elf32_hppa_hide_symbol (info, eh, TRUE);
   2199  1.1  skrll     }
   2200  1.1  skrll   return TRUE;
   2201  1.1  skrll }
   2202  1.1  skrll 
   2203  1.1  skrll /* Find any dynamic relocs that apply to read-only sections.  */
   2204  1.1  skrll 
   2205  1.1  skrll static bfd_boolean
   2206  1.1  skrll readonly_dynrelocs (struct elf_link_hash_entry *eh, void *inf)
   2207  1.1  skrll {
   2208  1.1  skrll   struct elf32_hppa_link_hash_entry *hh;
   2209  1.1  skrll   struct elf32_hppa_dyn_reloc_entry *hdh_p;
   2210  1.1  skrll 
   2211  1.1  skrll   if (eh->root.type == bfd_link_hash_warning)
   2212  1.1  skrll     eh = (struct elf_link_hash_entry *) eh->root.u.i.link;
   2213  1.1  skrll 
   2214  1.1  skrll   hh = hppa_elf_hash_entry (eh);
   2215  1.1  skrll   for (hdh_p = hh->dyn_relocs; hdh_p != NULL; hdh_p = hdh_p->hdh_next)
   2216  1.1  skrll     {
   2217  1.1  skrll       asection *sec = hdh_p->sec->output_section;
   2218  1.1  skrll 
   2219  1.1  skrll       if (sec != NULL && (sec->flags & SEC_READONLY) != 0)
   2220  1.1  skrll 	{
   2221  1.1  skrll 	  struct bfd_link_info *info = inf;
   2222  1.1  skrll 
   2223  1.1  skrll 	  info->flags |= DF_TEXTREL;
   2224  1.1  skrll 
   2225  1.1  skrll 	  /* Not an error, just cut short the traversal.  */
   2226  1.1  skrll 	  return FALSE;
   2227  1.1  skrll 	}
   2228  1.1  skrll     }
   2229  1.1  skrll   return TRUE;
   2230  1.1  skrll }
   2231  1.1  skrll 
   2232  1.1  skrll /* Set the sizes of the dynamic sections.  */
   2233  1.1  skrll 
   2234  1.1  skrll static bfd_boolean
   2235  1.1  skrll elf32_hppa_size_dynamic_sections (bfd *output_bfd ATTRIBUTE_UNUSED,
   2236  1.1  skrll 				  struct bfd_link_info *info)
   2237  1.1  skrll {
   2238  1.1  skrll   struct elf32_hppa_link_hash_table *htab;
   2239  1.1  skrll   bfd *dynobj;
   2240  1.1  skrll   bfd *ibfd;
   2241  1.1  skrll   asection *sec;
   2242  1.1  skrll   bfd_boolean relocs;
   2243  1.1  skrll 
   2244  1.1  skrll   htab = hppa_link_hash_table (info);
   2245  1.1  skrll   dynobj = htab->etab.dynobj;
   2246  1.1  skrll   if (dynobj == NULL)
   2247  1.1  skrll     abort ();
   2248  1.1  skrll 
   2249  1.1  skrll   if (htab->etab.dynamic_sections_created)
   2250  1.1  skrll     {
   2251  1.1  skrll       /* Set the contents of the .interp section to the interpreter.  */
   2252  1.1  skrll       if (info->executable)
   2253  1.1  skrll 	{
   2254  1.1  skrll 	  sec = bfd_get_section_by_name (dynobj, ".interp");
   2255  1.1  skrll 	  if (sec == NULL)
   2256  1.1  skrll 	    abort ();
   2257  1.1  skrll 	  sec->size = sizeof ELF_DYNAMIC_INTERPRETER;
   2258  1.1  skrll 	  sec->contents = (unsigned char *) ELF_DYNAMIC_INTERPRETER;
   2259  1.1  skrll 	}
   2260  1.1  skrll 
   2261  1.1  skrll       /* Force millicode symbols local.  */
   2262  1.1  skrll       elf_link_hash_traverse (&htab->etab,
   2263  1.1  skrll 			      clobber_millicode_symbols,
   2264  1.1  skrll 			      info);
   2265  1.1  skrll     }
   2266  1.1  skrll 
   2267  1.1  skrll   /* Set up .got and .plt offsets for local syms, and space for local
   2268  1.1  skrll      dynamic relocs.  */
   2269  1.1  skrll   for (ibfd = info->input_bfds; ibfd != NULL; ibfd = ibfd->link_next)
   2270  1.1  skrll     {
   2271  1.1  skrll       bfd_signed_vma *local_got;
   2272  1.1  skrll       bfd_signed_vma *end_local_got;
   2273  1.1  skrll       bfd_signed_vma *local_plt;
   2274  1.1  skrll       bfd_signed_vma *end_local_plt;
   2275  1.1  skrll       bfd_size_type locsymcount;
   2276  1.1  skrll       Elf_Internal_Shdr *symtab_hdr;
   2277  1.1  skrll       asection *srel;
   2278  1.1  skrll       char *local_tls_type;
   2279  1.1  skrll 
   2280  1.1  skrll       if (bfd_get_flavour (ibfd) != bfd_target_elf_flavour)
   2281  1.1  skrll 	continue;
   2282  1.1  skrll 
   2283  1.1  skrll       for (sec = ibfd->sections; sec != NULL; sec = sec->next)
   2284  1.1  skrll 	{
   2285  1.1  skrll 	  struct elf32_hppa_dyn_reloc_entry *hdh_p;
   2286  1.1  skrll 
   2287  1.1  skrll 	  for (hdh_p = ((struct elf32_hppa_dyn_reloc_entry *)
   2288  1.1  skrll 		    elf_section_data (sec)->local_dynrel);
   2289  1.1  skrll 	       hdh_p != NULL;
   2290  1.1  skrll 	       hdh_p = hdh_p->hdh_next)
   2291  1.1  skrll 	    {
   2292  1.1  skrll 	      if (!bfd_is_abs_section (hdh_p->sec)
   2293  1.1  skrll 		  && bfd_is_abs_section (hdh_p->sec->output_section))
   2294  1.1  skrll 		{
   2295  1.1  skrll 		  /* Input section has been discarded, either because
   2296  1.1  skrll 		     it is a copy of a linkonce section or due to
   2297  1.1  skrll 		     linker script /DISCARD/, so we'll be discarding
   2298  1.1  skrll 		     the relocs too.  */
   2299  1.1  skrll 		}
   2300  1.1  skrll 	      else if (hdh_p->count != 0)
   2301  1.1  skrll 		{
   2302  1.1  skrll 		  srel = elf_section_data (hdh_p->sec)->sreloc;
   2303  1.1  skrll 		  srel->size += hdh_p->count * sizeof (Elf32_External_Rela);
   2304  1.1  skrll 		  if ((hdh_p->sec->output_section->flags & SEC_READONLY) != 0)
   2305  1.1  skrll 		    info->flags |= DF_TEXTREL;
   2306  1.1  skrll 		}
   2307  1.1  skrll 	    }
   2308  1.1  skrll 	}
   2309  1.1  skrll 
   2310  1.1  skrll       local_got = elf_local_got_refcounts (ibfd);
   2311  1.1  skrll       if (!local_got)
   2312  1.1  skrll 	continue;
   2313  1.1  skrll 
   2314  1.1  skrll       symtab_hdr = &elf_tdata (ibfd)->symtab_hdr;
   2315  1.1  skrll       locsymcount = symtab_hdr->sh_info;
   2316  1.1  skrll       end_local_got = local_got + locsymcount;
   2317  1.1  skrll       local_tls_type = hppa_elf_local_got_tls_type (ibfd);
   2318  1.1  skrll       sec = htab->sgot;
   2319  1.1  skrll       srel = htab->srelgot;
   2320  1.1  skrll       for (; local_got < end_local_got; ++local_got)
   2321  1.1  skrll 	{
   2322  1.1  skrll 	  if (*local_got > 0)
   2323  1.1  skrll 	    {
   2324  1.1  skrll 	      *local_got = sec->size;
   2325  1.1  skrll 	      sec->size += GOT_ENTRY_SIZE;
   2326  1.1  skrll 	      if ((*local_tls_type & (GOT_TLS_GD | GOT_TLS_IE)) == (GOT_TLS_GD | GOT_TLS_IE))
   2327  1.1  skrll 		sec->size += 2 * GOT_ENTRY_SIZE;
   2328  1.1  skrll 	      else if ((*local_tls_type & GOT_TLS_GD) == GOT_TLS_GD)
   2329  1.1  skrll 		sec->size += GOT_ENTRY_SIZE;
   2330  1.1  skrll 	      if (info->shared)
   2331  1.1  skrll 	        {
   2332  1.1  skrll 		  srel->size += sizeof (Elf32_External_Rela);
   2333  1.1  skrll 		  if ((*local_tls_type & (GOT_TLS_GD | GOT_TLS_IE)) == (GOT_TLS_GD | GOT_TLS_IE))
   2334  1.1  skrll 		    srel->size += 2 * sizeof (Elf32_External_Rela);
   2335  1.1  skrll 		  else if ((*local_tls_type & GOT_TLS_GD) == GOT_TLS_GD)
   2336  1.1  skrll 		    srel->size += sizeof (Elf32_External_Rela);
   2337  1.1  skrll 	        }
   2338  1.1  skrll 	    }
   2339  1.1  skrll 	  else
   2340  1.1  skrll 	    *local_got = (bfd_vma) -1;
   2341  1.1  skrll 
   2342  1.1  skrll 	  ++local_tls_type;
   2343  1.1  skrll 	}
   2344  1.1  skrll 
   2345  1.1  skrll       local_plt = end_local_got;
   2346  1.1  skrll       end_local_plt = local_plt + locsymcount;
   2347  1.1  skrll       if (! htab->etab.dynamic_sections_created)
   2348  1.1  skrll 	{
   2349  1.1  skrll 	  /* Won't be used, but be safe.  */
   2350  1.1  skrll 	  for (; local_plt < end_local_plt; ++local_plt)
   2351  1.1  skrll 	    *local_plt = (bfd_vma) -1;
   2352  1.1  skrll 	}
   2353  1.1  skrll       else
   2354  1.1  skrll 	{
   2355  1.1  skrll 	  sec = htab->splt;
   2356  1.1  skrll 	  srel = htab->srelplt;
   2357  1.1  skrll 	  for (; local_plt < end_local_plt; ++local_plt)
   2358  1.1  skrll 	    {
   2359  1.1  skrll 	      if (*local_plt > 0)
   2360  1.1  skrll 		{
   2361  1.1  skrll 		  *local_plt = sec->size;
   2362  1.1  skrll 		  sec->size += PLT_ENTRY_SIZE;
   2363  1.1  skrll 		  if (info->shared)
   2364  1.1  skrll 		    srel->size += sizeof (Elf32_External_Rela);
   2365  1.1  skrll 		}
   2366  1.1  skrll 	      else
   2367  1.1  skrll 		*local_plt = (bfd_vma) -1;
   2368  1.1  skrll 	    }
   2369  1.1  skrll 	}
   2370  1.1  skrll     }
   2371  1.1  skrll 
   2372  1.1  skrll   if (htab->tls_ldm_got.refcount > 0)
   2373  1.1  skrll     {
   2374  1.1  skrll       /* Allocate 2 got entries and 1 dynamic reloc for
   2375  1.1  skrll          R_PARISC_TLS_DTPMOD32 relocs.  */
   2376  1.1  skrll       htab->tls_ldm_got.offset = htab->sgot->size;
   2377  1.1  skrll       htab->sgot->size += (GOT_ENTRY_SIZE * 2);
   2378  1.1  skrll       htab->srelgot->size += sizeof (Elf32_External_Rela);
   2379  1.1  skrll     }
   2380  1.1  skrll   else
   2381  1.1  skrll     htab->tls_ldm_got.offset = -1;
   2382  1.1  skrll 
   2383  1.1  skrll   /* Do all the .plt entries without relocs first.  The dynamic linker
   2384  1.1  skrll      uses the last .plt reloc to find the end of the .plt (and hence
   2385  1.1  skrll      the start of the .got) for lazy linking.  */
   2386  1.1  skrll   elf_link_hash_traverse (&htab->etab, allocate_plt_static, info);
   2387  1.1  skrll 
   2388  1.1  skrll   /* Allocate global sym .plt and .got entries, and space for global
   2389  1.1  skrll      sym dynamic relocs.  */
   2390  1.1  skrll   elf_link_hash_traverse (&htab->etab, allocate_dynrelocs, info);
   2391  1.1  skrll 
   2392  1.1  skrll   /* The check_relocs and adjust_dynamic_symbol entry points have
   2393  1.1  skrll      determined the sizes of the various dynamic sections.  Allocate
   2394  1.1  skrll      memory for them.  */
   2395  1.1  skrll   relocs = FALSE;
   2396  1.1  skrll   for (sec = dynobj->sections; sec != NULL; sec = sec->next)
   2397  1.1  skrll     {
   2398  1.1  skrll       if ((sec->flags & SEC_LINKER_CREATED) == 0)
   2399  1.1  skrll 	continue;
   2400  1.1  skrll 
   2401  1.1  skrll       if (sec == htab->splt)
   2402  1.1  skrll 	{
   2403  1.1  skrll 	  if (htab->need_plt_stub)
   2404  1.1  skrll 	    {
   2405  1.1  skrll 	      /* Make space for the plt stub at the end of the .plt
   2406  1.1  skrll 		 section.  We want this stub right at the end, up
   2407  1.1  skrll 		 against the .got section.  */
   2408  1.1  skrll 	      int gotalign = bfd_section_alignment (dynobj, htab->sgot);
   2409  1.1  skrll 	      int pltalign = bfd_section_alignment (dynobj, sec);
   2410  1.1  skrll 	      bfd_size_type mask;
   2411  1.1  skrll 
   2412  1.1  skrll 	      if (gotalign > pltalign)
   2413  1.1  skrll 		bfd_set_section_alignment (dynobj, sec, gotalign);
   2414  1.1  skrll 	      mask = ((bfd_size_type) 1 << gotalign) - 1;
   2415  1.1  skrll 	      sec->size = (sec->size + sizeof (plt_stub) + mask) & ~mask;
   2416  1.1  skrll 	    }
   2417  1.1  skrll 	}
   2418  1.1  skrll       else if (sec == htab->sgot
   2419  1.1  skrll 	       || sec == htab->sdynbss)
   2420  1.1  skrll 	;
   2421  1.1  skrll       else if (CONST_STRNEQ (bfd_get_section_name (dynobj, sec), ".rela"))
   2422  1.1  skrll 	{
   2423  1.1  skrll 	  if (sec->size != 0)
   2424  1.1  skrll 	    {
   2425  1.1  skrll 	      /* Remember whether there are any reloc sections other
   2426  1.1  skrll 		 than .rela.plt.  */
   2427  1.1  skrll 	      if (sec != htab->srelplt)
   2428  1.1  skrll 		relocs = TRUE;
   2429  1.1  skrll 
   2430  1.1  skrll 	      /* We use the reloc_count field as a counter if we need
   2431  1.1  skrll 		 to copy relocs into the output file.  */
   2432  1.1  skrll 	      sec->reloc_count = 0;
   2433  1.1  skrll 	    }
   2434  1.1  skrll 	}
   2435  1.1  skrll       else
   2436  1.1  skrll 	{
   2437  1.1  skrll 	  /* It's not one of our sections, so don't allocate space.  */
   2438  1.1  skrll 	  continue;
   2439  1.1  skrll 	}
   2440  1.1  skrll 
   2441  1.1  skrll       if (sec->size == 0)
   2442  1.1  skrll 	{
   2443  1.1  skrll 	  /* If we don't need this section, strip it from the
   2444  1.1  skrll 	     output file.  This is mostly to handle .rela.bss and
   2445  1.1  skrll 	     .rela.plt.  We must create both sections in
   2446  1.1  skrll 	     create_dynamic_sections, because they must be created
   2447  1.1  skrll 	     before the linker maps input sections to output
   2448  1.1  skrll 	     sections.  The linker does that before
   2449  1.1  skrll 	     adjust_dynamic_symbol is called, and it is that
   2450  1.1  skrll 	     function which decides whether anything needs to go
   2451  1.1  skrll 	     into these sections.  */
   2452  1.1  skrll 	  sec->flags |= SEC_EXCLUDE;
   2453  1.1  skrll 	  continue;
   2454  1.1  skrll 	}
   2455  1.1  skrll 
   2456  1.1  skrll       if ((sec->flags & SEC_HAS_CONTENTS) == 0)
   2457  1.1  skrll 	continue;
   2458  1.1  skrll 
   2459  1.1  skrll       /* Allocate memory for the section contents.  Zero it, because
   2460  1.1  skrll 	 we may not fill in all the reloc sections.  */
   2461  1.1  skrll       sec->contents = bfd_zalloc (dynobj, sec->size);
   2462  1.1  skrll       if (sec->contents == NULL)
   2463  1.1  skrll 	return FALSE;
   2464  1.1  skrll     }
   2465  1.1  skrll 
   2466  1.1  skrll   if (htab->etab.dynamic_sections_created)
   2467  1.1  skrll     {
   2468  1.1  skrll       /* Like IA-64 and HPPA64, always create a DT_PLTGOT.  It
   2469  1.1  skrll 	 actually has nothing to do with the PLT, it is how we
   2470  1.1  skrll 	 communicate the LTP value of a load module to the dynamic
   2471  1.1  skrll 	 linker.  */
   2472  1.1  skrll #define add_dynamic_entry(TAG, VAL) \
   2473  1.1  skrll   _bfd_elf_add_dynamic_entry (info, TAG, VAL)
   2474  1.1  skrll 
   2475  1.1  skrll       if (!add_dynamic_entry (DT_PLTGOT, 0))
   2476  1.1  skrll 	return FALSE;
   2477  1.1  skrll 
   2478  1.1  skrll       /* Add some entries to the .dynamic section.  We fill in the
   2479  1.1  skrll 	 values later, in elf32_hppa_finish_dynamic_sections, but we
   2480  1.1  skrll 	 must add the entries now so that we get the correct size for
   2481  1.1  skrll 	 the .dynamic section.  The DT_DEBUG entry is filled in by the
   2482  1.1  skrll 	 dynamic linker and used by the debugger.  */
   2483  1.1  skrll       if (info->executable)
   2484  1.1  skrll 	{
   2485  1.1  skrll 	  if (!add_dynamic_entry (DT_DEBUG, 0))
   2486  1.1  skrll 	    return FALSE;
   2487  1.1  skrll 	}
   2488  1.1  skrll 
   2489  1.1  skrll       if (htab->srelplt->size != 0)
   2490  1.1  skrll 	{
   2491  1.1  skrll 	  if (!add_dynamic_entry (DT_PLTRELSZ, 0)
   2492  1.1  skrll 	      || !add_dynamic_entry (DT_PLTREL, DT_RELA)
   2493  1.1  skrll 	      || !add_dynamic_entry (DT_JMPREL, 0))
   2494  1.1  skrll 	    return FALSE;
   2495  1.1  skrll 	}
   2496  1.1  skrll 
   2497  1.1  skrll       if (relocs)
   2498  1.1  skrll 	{
   2499  1.1  skrll 	  if (!add_dynamic_entry (DT_RELA, 0)
   2500  1.1  skrll 	      || !add_dynamic_entry (DT_RELASZ, 0)
   2501  1.1  skrll 	      || !add_dynamic_entry (DT_RELAENT, sizeof (Elf32_External_Rela)))
   2502  1.1  skrll 	    return FALSE;
   2503  1.1  skrll 
   2504  1.1  skrll 	  /* If any dynamic relocs apply to a read-only section,
   2505  1.1  skrll 	     then we need a DT_TEXTREL entry.  */
   2506  1.1  skrll 	  if ((info->flags & DF_TEXTREL) == 0)
   2507  1.1  skrll 	    elf_link_hash_traverse (&htab->etab, readonly_dynrelocs, info);
   2508  1.1  skrll 
   2509  1.1  skrll 	  if ((info->flags & DF_TEXTREL) != 0)
   2510  1.1  skrll 	    {
   2511  1.1  skrll 	      if (!add_dynamic_entry (DT_TEXTREL, 0))
   2512  1.1  skrll 		return FALSE;
   2513  1.1  skrll 	    }
   2514  1.1  skrll 	}
   2515  1.1  skrll     }
   2516  1.1  skrll #undef add_dynamic_entry
   2517  1.1  skrll 
   2518  1.1  skrll   return TRUE;
   2519  1.1  skrll }
   2520  1.1  skrll 
   2521  1.1  skrll /* External entry points for sizing and building linker stubs.  */
   2522  1.1  skrll 
   2523  1.1  skrll /* Set up various things so that we can make a list of input sections
   2524  1.1  skrll    for each output section included in the link.  Returns -1 on error,
   2525  1.1  skrll    0 when no stubs will be needed, and 1 on success.  */
   2526  1.1  skrll 
   2527  1.1  skrll int
   2528  1.1  skrll elf32_hppa_setup_section_lists (bfd *output_bfd, struct bfd_link_info *info)
   2529  1.1  skrll {
   2530  1.1  skrll   bfd *input_bfd;
   2531  1.1  skrll   unsigned int bfd_count;
   2532  1.1  skrll   int top_id, top_index;
   2533  1.1  skrll   asection *section;
   2534  1.1  skrll   asection **input_list, **list;
   2535  1.1  skrll   bfd_size_type amt;
   2536  1.1  skrll   struct elf32_hppa_link_hash_table *htab = hppa_link_hash_table (info);
   2537  1.1  skrll 
   2538  1.1  skrll   /* Count the number of input BFDs and find the top input section id.  */
   2539  1.1  skrll   for (input_bfd = info->input_bfds, bfd_count = 0, top_id = 0;
   2540  1.1  skrll        input_bfd != NULL;
   2541  1.1  skrll        input_bfd = input_bfd->link_next)
   2542  1.1  skrll     {
   2543  1.1  skrll       bfd_count += 1;
   2544  1.1  skrll       for (section = input_bfd->sections;
   2545  1.1  skrll 	   section != NULL;
   2546  1.1  skrll 	   section = section->next)
   2547  1.1  skrll 	{
   2548  1.1  skrll 	  if (top_id < section->id)
   2549  1.1  skrll 	    top_id = section->id;
   2550  1.1  skrll 	}
   2551  1.1  skrll     }
   2552  1.1  skrll   htab->bfd_count = bfd_count;
   2553  1.1  skrll 
   2554  1.1  skrll   amt = sizeof (struct map_stub) * (top_id + 1);
   2555  1.1  skrll   htab->stub_group = bfd_zmalloc (amt);
   2556  1.1  skrll   if (htab->stub_group == NULL)
   2557  1.1  skrll     return -1;
   2558  1.1  skrll 
   2559  1.1  skrll   /* We can't use output_bfd->section_count here to find the top output
   2560  1.1  skrll      section index as some sections may have been removed, and
   2561  1.1  skrll      strip_excluded_output_sections doesn't renumber the indices.  */
   2562  1.1  skrll   for (section = output_bfd->sections, top_index = 0;
   2563  1.1  skrll        section != NULL;
   2564  1.1  skrll        section = section->next)
   2565  1.1  skrll     {
   2566  1.1  skrll       if (top_index < section->index)
   2567  1.1  skrll 	top_index = section->index;
   2568  1.1  skrll     }
   2569  1.1  skrll 
   2570  1.1  skrll   htab->top_index = top_index;
   2571  1.1  skrll   amt = sizeof (asection *) * (top_index + 1);
   2572  1.1  skrll   input_list = bfd_malloc (amt);
   2573  1.1  skrll   htab->input_list = input_list;
   2574  1.1  skrll   if (input_list == NULL)
   2575  1.1  skrll     return -1;
   2576  1.1  skrll 
   2577  1.1  skrll   /* For sections we aren't interested in, mark their entries with a
   2578  1.1  skrll      value we can check later.  */
   2579  1.1  skrll   list = input_list + top_index;
   2580  1.1  skrll   do
   2581  1.1  skrll     *list = bfd_abs_section_ptr;
   2582  1.1  skrll   while (list-- != input_list);
   2583  1.1  skrll 
   2584  1.1  skrll   for (section = output_bfd->sections;
   2585  1.1  skrll        section != NULL;
   2586  1.1  skrll        section = section->next)
   2587  1.1  skrll     {
   2588  1.1  skrll       if ((section->flags & SEC_CODE) != 0)
   2589  1.1  skrll 	input_list[section->index] = NULL;
   2590  1.1  skrll     }
   2591  1.1  skrll 
   2592  1.1  skrll   return 1;
   2593  1.1  skrll }
   2594  1.1  skrll 
   2595  1.1  skrll /* The linker repeatedly calls this function for each input section,
   2596  1.1  skrll    in the order that input sections are linked into output sections.
   2597  1.1  skrll    Build lists of input sections to determine groupings between which
   2598  1.1  skrll    we may insert linker stubs.  */
   2599  1.1  skrll 
   2600  1.1  skrll void
   2601  1.1  skrll elf32_hppa_next_input_section (struct bfd_link_info *info, asection *isec)
   2602  1.1  skrll {
   2603  1.1  skrll   struct elf32_hppa_link_hash_table *htab = hppa_link_hash_table (info);
   2604  1.1  skrll 
   2605  1.1  skrll   if (isec->output_section->index <= htab->top_index)
   2606  1.1  skrll     {
   2607  1.1  skrll       asection **list = htab->input_list + isec->output_section->index;
   2608  1.1  skrll       if (*list != bfd_abs_section_ptr)
   2609  1.1  skrll 	{
   2610  1.1  skrll 	  /* Steal the link_sec pointer for our list.  */
   2611  1.1  skrll #define PREV_SEC(sec) (htab->stub_group[(sec)->id].link_sec)
   2612  1.1  skrll 	  /* This happens to make the list in reverse order,
   2613  1.1  skrll 	     which is what we want.  */
   2614  1.1  skrll 	  PREV_SEC (isec) = *list;
   2615  1.1  skrll 	  *list = isec;
   2616  1.1  skrll 	}
   2617  1.1  skrll     }
   2618  1.1  skrll }
   2619  1.1  skrll 
   2620  1.1  skrll /* See whether we can group stub sections together.  Grouping stub
   2621  1.1  skrll    sections may result in fewer stubs.  More importantly, we need to
   2622  1.1  skrll    put all .init* and .fini* stubs at the beginning of the .init or
   2623  1.1  skrll    .fini output sections respectively, because glibc splits the
   2624  1.1  skrll    _init and _fini functions into multiple parts.  Putting a stub in
   2625  1.1  skrll    the middle of a function is not a good idea.  */
   2626  1.1  skrll 
   2627  1.1  skrll static void
   2628  1.1  skrll group_sections (struct elf32_hppa_link_hash_table *htab,
   2629  1.1  skrll 		bfd_size_type stub_group_size,
   2630  1.1  skrll 		bfd_boolean stubs_always_before_branch)
   2631  1.1  skrll {
   2632  1.1  skrll   asection **list = htab->input_list + htab->top_index;
   2633  1.1  skrll   do
   2634  1.1  skrll     {
   2635  1.1  skrll       asection *tail = *list;
   2636  1.1  skrll       if (tail == bfd_abs_section_ptr)
   2637  1.1  skrll 	continue;
   2638  1.1  skrll       while (tail != NULL)
   2639  1.1  skrll 	{
   2640  1.1  skrll 	  asection *curr;
   2641  1.1  skrll 	  asection *prev;
   2642  1.1  skrll 	  bfd_size_type total;
   2643  1.1  skrll 	  bfd_boolean big_sec;
   2644  1.1  skrll 
   2645  1.1  skrll 	  curr = tail;
   2646  1.1  skrll 	  total = tail->size;
   2647  1.1  skrll 	  big_sec = total >= stub_group_size;
   2648  1.1  skrll 
   2649  1.1  skrll 	  while ((prev = PREV_SEC (curr)) != NULL
   2650  1.1  skrll 		 && ((total += curr->output_offset - prev->output_offset)
   2651  1.1  skrll 		     < stub_group_size))
   2652  1.1  skrll 	    curr = prev;
   2653  1.1  skrll 
   2654  1.1  skrll 	  /* OK, the size from the start of CURR to the end is less
   2655  1.1  skrll 	     than 240000 bytes and thus can be handled by one stub
   2656  1.1  skrll 	     section.  (or the tail section is itself larger than
   2657  1.1  skrll 	     240000 bytes, in which case we may be toast.)
   2658  1.1  skrll 	     We should really be keeping track of the total size of
   2659  1.1  skrll 	     stubs added here, as stubs contribute to the final output
   2660  1.1  skrll 	     section size.  That's a little tricky, and this way will
   2661  1.1  skrll 	     only break if stubs added total more than 22144 bytes, or
   2662  1.1  skrll 	     2768 long branch stubs.  It seems unlikely for more than
   2663  1.1  skrll 	     2768 different functions to be called, especially from
   2664  1.1  skrll 	     code only 240000 bytes long.  This limit used to be
   2665  1.1  skrll 	     250000, but c++ code tends to generate lots of little
   2666  1.1  skrll 	     functions, and sometimes violated the assumption.  */
   2667  1.1  skrll 	  do
   2668  1.1  skrll 	    {
   2669  1.1  skrll 	      prev = PREV_SEC (tail);
   2670  1.1  skrll 	      /* Set up this stub group.  */
   2671  1.1  skrll 	      htab->stub_group[tail->id].link_sec = curr;
   2672  1.1  skrll 	    }
   2673  1.1  skrll 	  while (tail != curr && (tail = prev) != NULL);
   2674  1.1  skrll 
   2675  1.1  skrll 	  /* But wait, there's more!  Input sections up to 240000
   2676  1.1  skrll 	     bytes before the stub section can be handled by it too.
   2677  1.1  skrll 	     Don't do this if we have a really large section after the
   2678  1.1  skrll 	     stubs, as adding more stubs increases the chance that
   2679  1.1  skrll 	     branches may not reach into the stub section.  */
   2680  1.1  skrll 	  if (!stubs_always_before_branch && !big_sec)
   2681  1.1  skrll 	    {
   2682  1.1  skrll 	      total = 0;
   2683  1.1  skrll 	      while (prev != NULL
   2684  1.1  skrll 		     && ((total += tail->output_offset - prev->output_offset)
   2685  1.1  skrll 			 < stub_group_size))
   2686  1.1  skrll 		{
   2687  1.1  skrll 		  tail = prev;
   2688  1.1  skrll 		  prev = PREV_SEC (tail);
   2689  1.1  skrll 		  htab->stub_group[tail->id].link_sec = curr;
   2690  1.1  skrll 		}
   2691  1.1  skrll 	    }
   2692  1.1  skrll 	  tail = prev;
   2693  1.1  skrll 	}
   2694  1.1  skrll     }
   2695  1.1  skrll   while (list-- != htab->input_list);
   2696  1.1  skrll   free (htab->input_list);
   2697  1.1  skrll #undef PREV_SEC
   2698  1.1  skrll }
   2699  1.1  skrll 
   2700  1.1  skrll /* Read in all local syms for all input bfds, and create hash entries
   2701  1.1  skrll    for export stubs if we are building a multi-subspace shared lib.
   2702  1.1  skrll    Returns -1 on error, 1 if export stubs created, 0 otherwise.  */
   2703  1.1  skrll 
   2704  1.1  skrll static int
   2705  1.1  skrll get_local_syms (bfd *output_bfd, bfd *input_bfd, struct bfd_link_info *info)
   2706  1.1  skrll {
   2707  1.1  skrll   unsigned int bfd_indx;
   2708  1.1  skrll   Elf_Internal_Sym *local_syms, **all_local_syms;
   2709  1.1  skrll   int stub_changed = 0;
   2710  1.1  skrll   struct elf32_hppa_link_hash_table *htab = hppa_link_hash_table (info);
   2711  1.1  skrll 
   2712  1.1  skrll   /* We want to read in symbol extension records only once.  To do this
   2713  1.1  skrll      we need to read in the local symbols in parallel and save them for
   2714  1.1  skrll      later use; so hold pointers to the local symbols in an array.  */
   2715  1.1  skrll   bfd_size_type amt = sizeof (Elf_Internal_Sym *) * htab->bfd_count;
   2716  1.1  skrll   all_local_syms = bfd_zmalloc (amt);
   2717  1.1  skrll   htab->all_local_syms = all_local_syms;
   2718  1.1  skrll   if (all_local_syms == NULL)
   2719  1.1  skrll     return -1;
   2720  1.1  skrll 
   2721  1.1  skrll   /* Walk over all the input BFDs, swapping in local symbols.
   2722  1.1  skrll      If we are creating a shared library, create hash entries for the
   2723  1.1  skrll      export stubs.  */
   2724  1.1  skrll   for (bfd_indx = 0;
   2725  1.1  skrll        input_bfd != NULL;
   2726  1.1  skrll        input_bfd = input_bfd->link_next, bfd_indx++)
   2727  1.1  skrll     {
   2728  1.1  skrll       Elf_Internal_Shdr *symtab_hdr;
   2729  1.1  skrll 
   2730  1.1  skrll       /* We'll need the symbol table in a second.  */
   2731  1.1  skrll       symtab_hdr = &elf_tdata (input_bfd)->symtab_hdr;
   2732  1.1  skrll       if (symtab_hdr->sh_info == 0)
   2733  1.1  skrll 	continue;
   2734  1.1  skrll 
   2735  1.1  skrll       /* We need an array of the local symbols attached to the input bfd.  */
   2736  1.1  skrll       local_syms = (Elf_Internal_Sym *) symtab_hdr->contents;
   2737  1.1  skrll       if (local_syms == NULL)
   2738  1.1  skrll 	{
   2739  1.1  skrll 	  local_syms = bfd_elf_get_elf_syms (input_bfd, symtab_hdr,
   2740  1.1  skrll 					     symtab_hdr->sh_info, 0,
   2741  1.1  skrll 					     NULL, NULL, NULL);
   2742  1.1  skrll 	  /* Cache them for elf_link_input_bfd.  */
   2743  1.1  skrll 	  symtab_hdr->contents = (unsigned char *) local_syms;
   2744  1.1  skrll 	}
   2745  1.1  skrll       if (local_syms == NULL)
   2746  1.1  skrll 	return -1;
   2747  1.1  skrll 
   2748  1.1  skrll       all_local_syms[bfd_indx] = local_syms;
   2749  1.1  skrll 
   2750  1.1  skrll       if (info->shared && htab->multi_subspace)
   2751  1.1  skrll 	{
   2752  1.1  skrll 	  struct elf_link_hash_entry **eh_syms;
   2753  1.1  skrll 	  struct elf_link_hash_entry **eh_symend;
   2754  1.1  skrll 	  unsigned int symcount;
   2755  1.1  skrll 
   2756  1.1  skrll 	  symcount = (symtab_hdr->sh_size / sizeof (Elf32_External_Sym)
   2757  1.1  skrll 		      - symtab_hdr->sh_info);
   2758  1.1  skrll 	  eh_syms = (struct elf_link_hash_entry **) elf_sym_hashes (input_bfd);
   2759  1.1  skrll 	  eh_symend = (struct elf_link_hash_entry **) (eh_syms + symcount);
   2760  1.1  skrll 
   2761  1.1  skrll 	  /* Look through the global syms for functions;  We need to
   2762  1.1  skrll 	     build export stubs for all globally visible functions.  */
   2763  1.1  skrll 	  for (; eh_syms < eh_symend; eh_syms++)
   2764  1.1  skrll 	    {
   2765  1.1  skrll 	      struct elf32_hppa_link_hash_entry *hh;
   2766  1.1  skrll 
   2767  1.1  skrll 	      hh = hppa_elf_hash_entry (*eh_syms);
   2768  1.1  skrll 
   2769  1.1  skrll 	      while (hh->eh.root.type == bfd_link_hash_indirect
   2770  1.1  skrll 		     || hh->eh.root.type == bfd_link_hash_warning)
   2771  1.1  skrll 		   hh = hppa_elf_hash_entry (hh->eh.root.u.i.link);
   2772  1.1  skrll 
   2773  1.1  skrll 	      /* At this point in the link, undefined syms have been
   2774  1.1  skrll 		 resolved, so we need to check that the symbol was
   2775  1.1  skrll 		 defined in this BFD.  */
   2776  1.1  skrll 	      if ((hh->eh.root.type == bfd_link_hash_defined
   2777  1.1  skrll 		   || hh->eh.root.type == bfd_link_hash_defweak)
   2778  1.1  skrll 		  && hh->eh.type == STT_FUNC
   2779  1.1  skrll 		  && hh->eh.root.u.def.section->output_section != NULL
   2780  1.1  skrll 		  && (hh->eh.root.u.def.section->output_section->owner
   2781  1.1  skrll 		      == output_bfd)
   2782  1.1  skrll 		  && hh->eh.root.u.def.section->owner == input_bfd
   2783  1.1  skrll 		  && hh->eh.def_regular
   2784  1.1  skrll 		  && !hh->eh.forced_local
   2785  1.1  skrll 		  && ELF_ST_VISIBILITY (hh->eh.other) == STV_DEFAULT)
   2786  1.1  skrll 		{
   2787  1.1  skrll 		  asection *sec;
   2788  1.1  skrll 		  const char *stub_name;
   2789  1.1  skrll 		  struct elf32_hppa_stub_hash_entry *hsh;
   2790  1.1  skrll 
   2791  1.1  skrll 		  sec = hh->eh.root.u.def.section;
   2792  1.1  skrll 		  stub_name = hh_name (hh);
   2793  1.1  skrll 		  hsh = hppa_stub_hash_lookup (&htab->bstab,
   2794  1.1  skrll 						      stub_name,
   2795  1.1  skrll 						      FALSE, FALSE);
   2796  1.1  skrll 		  if (hsh == NULL)
   2797  1.1  skrll 		    {
   2798  1.1  skrll 		      hsh = hppa_add_stub (stub_name, sec, htab);
   2799  1.1  skrll 		      if (!hsh)
   2800  1.1  skrll 			return -1;
   2801  1.1  skrll 
   2802  1.1  skrll 		      hsh->target_value = hh->eh.root.u.def.value;
   2803  1.1  skrll 		      hsh->target_section = hh->eh.root.u.def.section;
   2804  1.1  skrll 		      hsh->stub_type = hppa_stub_export;
   2805  1.1  skrll 		      hsh->hh = hh;
   2806  1.1  skrll 		      stub_changed = 1;
   2807  1.1  skrll 		    }
   2808  1.1  skrll 		  else
   2809  1.1  skrll 		    {
   2810  1.1  skrll 		      (*_bfd_error_handler) (_("%B: duplicate export stub %s"),
   2811  1.1  skrll 					     input_bfd,
   2812  1.1  skrll 					     stub_name);
   2813  1.1  skrll 		    }
   2814  1.1  skrll 		}
   2815  1.1  skrll 	    }
   2816  1.1  skrll 	}
   2817  1.1  skrll     }
   2818  1.1  skrll 
   2819  1.1  skrll   return stub_changed;
   2820  1.1  skrll }
   2821  1.1  skrll 
   2822  1.1  skrll /* Determine and set the size of the stub section for a final link.
   2823  1.1  skrll 
   2824  1.1  skrll    The basic idea here is to examine all the relocations looking for
   2825  1.1  skrll    PC-relative calls to a target that is unreachable with a "bl"
   2826  1.1  skrll    instruction.  */
   2827  1.1  skrll 
   2828  1.1  skrll bfd_boolean
   2829  1.1  skrll elf32_hppa_size_stubs
   2830  1.1  skrll   (bfd *output_bfd, bfd *stub_bfd, struct bfd_link_info *info,
   2831  1.1  skrll    bfd_boolean multi_subspace, bfd_signed_vma group_size,
   2832  1.1  skrll    asection * (*add_stub_section) (const char *, asection *),
   2833  1.1  skrll    void (*layout_sections_again) (void))
   2834  1.1  skrll {
   2835  1.1  skrll   bfd_size_type stub_group_size;
   2836  1.1  skrll   bfd_boolean stubs_always_before_branch;
   2837  1.1  skrll   bfd_boolean stub_changed;
   2838  1.1  skrll   struct elf32_hppa_link_hash_table *htab = hppa_link_hash_table (info);
   2839  1.1  skrll 
   2840  1.1  skrll   /* Stash our params away.  */
   2841  1.1  skrll   htab->stub_bfd = stub_bfd;
   2842  1.1  skrll   htab->multi_subspace = multi_subspace;
   2843  1.1  skrll   htab->add_stub_section = add_stub_section;
   2844  1.1  skrll   htab->layout_sections_again = layout_sections_again;
   2845  1.1  skrll   stubs_always_before_branch = group_size < 0;
   2846  1.1  skrll   if (group_size < 0)
   2847  1.1  skrll     stub_group_size = -group_size;
   2848  1.1  skrll   else
   2849  1.1  skrll     stub_group_size = group_size;
   2850  1.1  skrll   if (stub_group_size == 1)
   2851  1.1  skrll     {
   2852  1.1  skrll       /* Default values.  */
   2853  1.1  skrll       if (stubs_always_before_branch)
   2854  1.1  skrll 	{
   2855  1.1  skrll 	  stub_group_size = 7680000;
   2856  1.1  skrll 	  if (htab->has_17bit_branch || htab->multi_subspace)
   2857  1.1  skrll 	    stub_group_size = 240000;
   2858  1.1  skrll 	  if (htab->has_12bit_branch)
   2859  1.1  skrll 	    stub_group_size = 7500;
   2860  1.1  skrll 	}
   2861  1.1  skrll       else
   2862  1.1  skrll 	{
   2863  1.1  skrll 	  stub_group_size = 6971392;
   2864  1.1  skrll 	  if (htab->has_17bit_branch || htab->multi_subspace)
   2865  1.1  skrll 	    stub_group_size = 217856;
   2866  1.1  skrll 	  if (htab->has_12bit_branch)
   2867  1.1  skrll 	    stub_group_size = 6808;
   2868  1.1  skrll 	}
   2869  1.1  skrll     }
   2870  1.1  skrll 
   2871  1.1  skrll   group_sections (htab, stub_group_size, stubs_always_before_branch);
   2872  1.1  skrll 
   2873  1.1  skrll   switch (get_local_syms (output_bfd, info->input_bfds, info))
   2874  1.1  skrll     {
   2875  1.1  skrll     default:
   2876  1.1  skrll       if (htab->all_local_syms)
   2877  1.1  skrll 	goto error_ret_free_local;
   2878  1.1  skrll       return FALSE;
   2879  1.1  skrll 
   2880  1.1  skrll     case 0:
   2881  1.1  skrll       stub_changed = FALSE;
   2882  1.1  skrll       break;
   2883  1.1  skrll 
   2884  1.1  skrll     case 1:
   2885  1.1  skrll       stub_changed = TRUE;
   2886  1.1  skrll       break;
   2887  1.1  skrll     }
   2888  1.1  skrll 
   2889  1.1  skrll   while (1)
   2890  1.1  skrll     {
   2891  1.1  skrll       bfd *input_bfd;
   2892  1.1  skrll       unsigned int bfd_indx;
   2893  1.1  skrll       asection *stub_sec;
   2894  1.1  skrll 
   2895  1.1  skrll       for (input_bfd = info->input_bfds, bfd_indx = 0;
   2896  1.1  skrll 	   input_bfd != NULL;
   2897  1.1  skrll 	   input_bfd = input_bfd->link_next, bfd_indx++)
   2898  1.1  skrll 	{
   2899  1.1  skrll 	  Elf_Internal_Shdr *symtab_hdr;
   2900  1.1  skrll 	  asection *section;
   2901  1.1  skrll 	  Elf_Internal_Sym *local_syms;
   2902  1.1  skrll 
   2903  1.1  skrll 	  /* We'll need the symbol table in a second.  */
   2904  1.1  skrll 	  symtab_hdr = &elf_tdata (input_bfd)->symtab_hdr;
   2905  1.1  skrll 	  if (symtab_hdr->sh_info == 0)
   2906  1.1  skrll 	    continue;
   2907  1.1  skrll 
   2908  1.1  skrll 	  local_syms = htab->all_local_syms[bfd_indx];
   2909  1.1  skrll 
   2910  1.1  skrll 	  /* Walk over each section attached to the input bfd.  */
   2911  1.1  skrll 	  for (section = input_bfd->sections;
   2912  1.1  skrll 	       section != NULL;
   2913  1.1  skrll 	       section = section->next)
   2914  1.1  skrll 	    {
   2915  1.1  skrll 	      Elf_Internal_Rela *internal_relocs, *irelaend, *irela;
   2916  1.1  skrll 
   2917  1.1  skrll 	      /* If there aren't any relocs, then there's nothing more
   2918  1.1  skrll 		 to do.  */
   2919  1.1  skrll 	      if ((section->flags & SEC_RELOC) == 0
   2920  1.1  skrll 		  || section->reloc_count == 0)
   2921  1.1  skrll 		continue;
   2922  1.1  skrll 
   2923  1.1  skrll 	      /* If this section is a link-once section that will be
   2924  1.1  skrll 		 discarded, then don't create any stubs.  */
   2925  1.1  skrll 	      if (section->output_section == NULL
   2926  1.1  skrll 		  || section->output_section->owner != output_bfd)
   2927  1.1  skrll 		continue;
   2928  1.1  skrll 
   2929  1.1  skrll 	      /* Get the relocs.  */
   2930  1.1  skrll 	      internal_relocs
   2931  1.1  skrll 		= _bfd_elf_link_read_relocs (input_bfd, section, NULL, NULL,
   2932  1.1  skrll 					     info->keep_memory);
   2933  1.1  skrll 	      if (internal_relocs == NULL)
   2934  1.1  skrll 		goto error_ret_free_local;
   2935  1.1  skrll 
   2936  1.1  skrll 	      /* Now examine each relocation.  */
   2937  1.1  skrll 	      irela = internal_relocs;
   2938  1.1  skrll 	      irelaend = irela + section->reloc_count;
   2939  1.1  skrll 	      for (; irela < irelaend; irela++)
   2940  1.1  skrll 		{
   2941  1.1  skrll 		  unsigned int r_type, r_indx;
   2942  1.1  skrll 		  enum elf32_hppa_stub_type stub_type;
   2943  1.1  skrll 		  struct elf32_hppa_stub_hash_entry *hsh;
   2944  1.1  skrll 		  asection *sym_sec;
   2945  1.1  skrll 		  bfd_vma sym_value;
   2946  1.1  skrll 		  bfd_vma destination;
   2947  1.1  skrll 		  struct elf32_hppa_link_hash_entry *hh;
   2948  1.1  skrll 		  char *stub_name;
   2949  1.1  skrll 		  const asection *id_sec;
   2950  1.1  skrll 
   2951  1.1  skrll 		  r_type = ELF32_R_TYPE (irela->r_info);
   2952  1.1  skrll 		  r_indx = ELF32_R_SYM (irela->r_info);
   2953  1.1  skrll 
   2954  1.1  skrll 		  if (r_type >= (unsigned int) R_PARISC_UNIMPLEMENTED)
   2955  1.1  skrll 		    {
   2956  1.1  skrll 		      bfd_set_error (bfd_error_bad_value);
   2957  1.1  skrll 		    error_ret_free_internal:
   2958  1.1  skrll 		      if (elf_section_data (section)->relocs == NULL)
   2959  1.1  skrll 			free (internal_relocs);
   2960  1.1  skrll 		      goto error_ret_free_local;
   2961  1.1  skrll 		    }
   2962  1.1  skrll 
   2963  1.1  skrll 		  /* Only look for stubs on call instructions.  */
   2964  1.1  skrll 		  if (r_type != (unsigned int) R_PARISC_PCREL12F
   2965  1.1  skrll 		      && r_type != (unsigned int) R_PARISC_PCREL17F
   2966  1.1  skrll 		      && r_type != (unsigned int) R_PARISC_PCREL22F)
   2967  1.1  skrll 		    continue;
   2968  1.1  skrll 
   2969  1.1  skrll 		  /* Now determine the call target, its name, value,
   2970  1.1  skrll 		     section.  */
   2971  1.1  skrll 		  sym_sec = NULL;
   2972  1.1  skrll 		  sym_value = 0;
   2973  1.1  skrll 		  destination = 0;
   2974  1.1  skrll 		  hh = NULL;
   2975  1.1  skrll 		  if (r_indx < symtab_hdr->sh_info)
   2976  1.1  skrll 		    {
   2977  1.1  skrll 		      /* It's a local symbol.  */
   2978  1.1  skrll 		      Elf_Internal_Sym *sym;
   2979  1.1  skrll 		      Elf_Internal_Shdr *hdr;
   2980  1.1  skrll 		      unsigned int shndx;
   2981  1.1  skrll 
   2982  1.1  skrll 		      sym = local_syms + r_indx;
   2983  1.1  skrll 		      if (ELF_ST_TYPE (sym->st_info) != STT_SECTION)
   2984  1.1  skrll 			sym_value = sym->st_value;
   2985  1.1  skrll 		      shndx = sym->st_shndx;
   2986  1.1  skrll 		      if (shndx < elf_numsections (input_bfd))
   2987  1.1  skrll 			{
   2988  1.1  skrll 			  hdr = elf_elfsections (input_bfd)[shndx];
   2989  1.1  skrll 			  sym_sec = hdr->bfd_section;
   2990  1.1  skrll 			  destination = (sym_value + irela->r_addend
   2991  1.1  skrll 					 + sym_sec->output_offset
   2992  1.1  skrll 					 + sym_sec->output_section->vma);
   2993  1.1  skrll 			}
   2994  1.1  skrll 		    }
   2995  1.1  skrll 		  else
   2996  1.1  skrll 		    {
   2997  1.1  skrll 		      /* It's an external symbol.  */
   2998  1.1  skrll 		      int e_indx;
   2999  1.1  skrll 
   3000  1.1  skrll 		      e_indx = r_indx - symtab_hdr->sh_info;
   3001  1.1  skrll 		      hh = hppa_elf_hash_entry (elf_sym_hashes (input_bfd)[e_indx]);
   3002  1.1  skrll 
   3003  1.1  skrll 		      while (hh->eh.root.type == bfd_link_hash_indirect
   3004  1.1  skrll 			     || hh->eh.root.type == bfd_link_hash_warning)
   3005  1.1  skrll 			hh = hppa_elf_hash_entry (hh->eh.root.u.i.link);
   3006  1.1  skrll 
   3007  1.1  skrll 		      if (hh->eh.root.type == bfd_link_hash_defined
   3008  1.1  skrll 			  || hh->eh.root.type == bfd_link_hash_defweak)
   3009  1.1  skrll 			{
   3010  1.1  skrll 			  sym_sec = hh->eh.root.u.def.section;
   3011  1.1  skrll 			  sym_value = hh->eh.root.u.def.value;
   3012  1.1  skrll 			  if (sym_sec->output_section != NULL)
   3013  1.1  skrll 			    destination = (sym_value + irela->r_addend
   3014  1.1  skrll 					   + sym_sec->output_offset
   3015  1.1  skrll 					   + sym_sec->output_section->vma);
   3016  1.1  skrll 			}
   3017  1.1  skrll 		      else if (hh->eh.root.type == bfd_link_hash_undefweak)
   3018  1.1  skrll 			{
   3019  1.1  skrll 			  if (! info->shared)
   3020  1.1  skrll 			    continue;
   3021  1.1  skrll 			}
   3022  1.1  skrll 		      else if (hh->eh.root.type == bfd_link_hash_undefined)
   3023  1.1  skrll 			{
   3024  1.1  skrll 			  if (! (info->unresolved_syms_in_objects == RM_IGNORE
   3025  1.1  skrll 				 && (ELF_ST_VISIBILITY (hh->eh.other)
   3026  1.1  skrll 				     == STV_DEFAULT)
   3027  1.1  skrll 				 && hh->eh.type != STT_PARISC_MILLI))
   3028  1.1  skrll 			    continue;
   3029  1.1  skrll 			}
   3030  1.1  skrll 		      else
   3031  1.1  skrll 			{
   3032  1.1  skrll 			  bfd_set_error (bfd_error_bad_value);
   3033  1.1  skrll 			  goto error_ret_free_internal;
   3034  1.1  skrll 			}
   3035  1.1  skrll 		    }
   3036  1.1  skrll 
   3037  1.1  skrll 		  /* Determine what (if any) linker stub is needed.  */
   3038  1.1  skrll 		  stub_type = hppa_type_of_stub (section, irela, hh,
   3039  1.1  skrll 						 destination, info);
   3040  1.1  skrll 		  if (stub_type == hppa_stub_none)
   3041  1.1  skrll 		    continue;
   3042  1.1  skrll 
   3043  1.1  skrll 		  /* Support for grouping stub sections.  */
   3044  1.1  skrll 		  id_sec = htab->stub_group[section->id].link_sec;
   3045  1.1  skrll 
   3046  1.1  skrll 		  /* Get the name of this stub.  */
   3047  1.1  skrll 		  stub_name = hppa_stub_name (id_sec, sym_sec, hh, irela);
   3048  1.1  skrll 		  if (!stub_name)
   3049  1.1  skrll 		    goto error_ret_free_internal;
   3050  1.1  skrll 
   3051  1.1  skrll 		  hsh = hppa_stub_hash_lookup (&htab->bstab,
   3052  1.1  skrll 						      stub_name,
   3053  1.1  skrll 						      FALSE, FALSE);
   3054  1.1  skrll 		  if (hsh != NULL)
   3055  1.1  skrll 		    {
   3056  1.1  skrll 		      /* The proper stub has already been created.  */
   3057  1.1  skrll 		      free (stub_name);
   3058  1.1  skrll 		      continue;
   3059  1.1  skrll 		    }
   3060  1.1  skrll 
   3061  1.1  skrll 		  hsh = hppa_add_stub (stub_name, section, htab);
   3062  1.1  skrll 		  if (hsh == NULL)
   3063  1.1  skrll 		    {
   3064  1.1  skrll 		      free (stub_name);
   3065  1.1  skrll 		      goto error_ret_free_internal;
   3066  1.1  skrll 		    }
   3067  1.1  skrll 
   3068  1.1  skrll 		  hsh->target_value = sym_value;
   3069  1.1  skrll 		  hsh->target_section = sym_sec;
   3070  1.1  skrll 		  hsh->stub_type = stub_type;
   3071  1.1  skrll 		  if (info->shared)
   3072  1.1  skrll 		    {
   3073  1.1  skrll 		      if (stub_type == hppa_stub_import)
   3074  1.1  skrll 			hsh->stub_type = hppa_stub_import_shared;
   3075  1.1  skrll 		      else if (stub_type == hppa_stub_long_branch)
   3076  1.1  skrll 			hsh->stub_type = hppa_stub_long_branch_shared;
   3077  1.1  skrll 		    }
   3078  1.1  skrll 		  hsh->hh = hh;
   3079  1.1  skrll 		  stub_changed = TRUE;
   3080  1.1  skrll 		}
   3081  1.1  skrll 
   3082  1.1  skrll 	      /* We're done with the internal relocs, free them.  */
   3083  1.1  skrll 	      if (elf_section_data (section)->relocs == NULL)
   3084  1.1  skrll 		free (internal_relocs);
   3085  1.1  skrll 	    }
   3086  1.1  skrll 	}
   3087  1.1  skrll 
   3088  1.1  skrll       if (!stub_changed)
   3089  1.1  skrll 	break;
   3090  1.1  skrll 
   3091  1.1  skrll       /* OK, we've added some stubs.  Find out the new size of the
   3092  1.1  skrll 	 stub sections.  */
   3093  1.1  skrll       for (stub_sec = htab->stub_bfd->sections;
   3094  1.1  skrll 	   stub_sec != NULL;
   3095  1.1  skrll 	   stub_sec = stub_sec->next)
   3096  1.1  skrll 	stub_sec->size = 0;
   3097  1.1  skrll 
   3098  1.1  skrll       bfd_hash_traverse (&htab->bstab, hppa_size_one_stub, htab);
   3099  1.1  skrll 
   3100  1.1  skrll       /* Ask the linker to do its stuff.  */
   3101  1.1  skrll       (*htab->layout_sections_again) ();
   3102  1.1  skrll       stub_changed = FALSE;
   3103  1.1  skrll     }
   3104  1.1  skrll 
   3105  1.1  skrll   free (htab->all_local_syms);
   3106  1.1  skrll   return TRUE;
   3107  1.1  skrll 
   3108  1.1  skrll  error_ret_free_local:
   3109  1.1  skrll   free (htab->all_local_syms);
   3110  1.1  skrll   return FALSE;
   3111  1.1  skrll }
   3112  1.1  skrll 
   3113  1.1  skrll /* For a final link, this function is called after we have sized the
   3114  1.1  skrll    stubs to provide a value for __gp.  */
   3115  1.1  skrll 
   3116  1.1  skrll bfd_boolean
   3117  1.1  skrll elf32_hppa_set_gp (bfd *abfd, struct bfd_link_info *info)
   3118  1.1  skrll {
   3119  1.1  skrll   struct bfd_link_hash_entry *h;
   3120  1.1  skrll   asection *sec = NULL;
   3121  1.1  skrll   bfd_vma gp_val = 0;
   3122  1.1  skrll   struct elf32_hppa_link_hash_table *htab;
   3123  1.1  skrll 
   3124  1.1  skrll   htab = hppa_link_hash_table (info);
   3125  1.1  skrll   h = bfd_link_hash_lookup (&htab->etab.root, "$global$", FALSE, FALSE, FALSE);
   3126  1.1  skrll 
   3127  1.1  skrll   if (h != NULL
   3128  1.1  skrll       && (h->type == bfd_link_hash_defined
   3129  1.1  skrll 	  || h->type == bfd_link_hash_defweak))
   3130  1.1  skrll     {
   3131  1.1  skrll       gp_val = h->u.def.value;
   3132  1.1  skrll       sec = h->u.def.section;
   3133  1.1  skrll     }
   3134  1.1  skrll   else
   3135  1.1  skrll     {
   3136  1.1  skrll       asection *splt = bfd_get_section_by_name (abfd, ".plt");
   3137  1.1  skrll       asection *sgot = bfd_get_section_by_name (abfd, ".got");
   3138  1.1  skrll 
   3139  1.1  skrll       /* Choose to point our LTP at, in this order, one of .plt, .got,
   3140  1.1  skrll 	 or .data, if these sections exist.  In the case of choosing
   3141  1.1  skrll 	 .plt try to make the LTP ideal for addressing anywhere in the
   3142  1.1  skrll 	 .plt or .got with a 14 bit signed offset.  Typically, the end
   3143  1.1  skrll 	 of the .plt is the start of the .got, so choose .plt + 0x2000
   3144  1.1  skrll 	 if either the .plt or .got is larger than 0x2000.  If both
   3145  1.1  skrll 	 the .plt and .got are smaller than 0x2000, choose the end of
   3146  1.1  skrll 	 the .plt section.  */
   3147  1.1  skrll       sec = strcmp (bfd_get_target (abfd), "elf32-hppa-netbsd") == 0
   3148  1.1  skrll 	  ? NULL : splt;
   3149  1.1  skrll       if (sec != NULL)
   3150  1.1  skrll 	{
   3151  1.1  skrll 	  gp_val = sec->size;
   3152  1.1  skrll 	  if (gp_val > 0x2000 || (sgot && sgot->size > 0x2000))
   3153  1.1  skrll 	    {
   3154  1.1  skrll 	      gp_val = 0x2000;
   3155  1.1  skrll 	    }
   3156  1.1  skrll 	}
   3157  1.1  skrll       else
   3158  1.1  skrll 	{
   3159  1.1  skrll 	  sec = sgot;
   3160  1.1  skrll 	  if (sec != NULL)
   3161  1.1  skrll 	    {
   3162  1.1  skrll 	      if (strcmp (bfd_get_target (abfd), "elf32-hppa-netbsd") != 0)
   3163  1.1  skrll 		{
   3164  1.1  skrll 	          /* We know we don't have a .plt.  If .got is large,
   3165  1.1  skrll 		     offset our LTP.  */
   3166  1.1  skrll 	          if (sec->size > 0x2000)
   3167  1.1  skrll 		    gp_val = 0x2000;
   3168  1.1  skrll 		}
   3169  1.1  skrll 	    }
   3170  1.1  skrll 	  else
   3171  1.1  skrll 	    {
   3172  1.1  skrll 	      /* No .plt or .got.  Who cares what the LTP is?  */
   3173  1.1  skrll 	      sec = bfd_get_section_by_name (abfd, ".data");
   3174  1.1  skrll 	    }
   3175  1.1  skrll 	}
   3176  1.1  skrll 
   3177  1.1  skrll       if (h != NULL)
   3178  1.1  skrll 	{
   3179  1.1  skrll 	  h->type = bfd_link_hash_defined;
   3180  1.1  skrll 	  h->u.def.value = gp_val;
   3181  1.1  skrll 	  if (sec != NULL)
   3182  1.1  skrll 	    h->u.def.section = sec;
   3183  1.1  skrll 	  else
   3184  1.1  skrll 	    h->u.def.section = bfd_abs_section_ptr;
   3185  1.1  skrll 	}
   3186  1.1  skrll     }
   3187  1.1  skrll 
   3188  1.1  skrll   if (sec != NULL && sec->output_section != NULL)
   3189  1.1  skrll     gp_val += sec->output_section->vma + sec->output_offset;
   3190  1.1  skrll 
   3191  1.1  skrll   elf_gp (abfd) = gp_val;
   3192  1.1  skrll   return TRUE;
   3193  1.1  skrll }
   3194  1.1  skrll 
   3195  1.1  skrll /* Build all the stubs associated with the current output file.  The
   3196  1.1  skrll    stubs are kept in a hash table attached to the main linker hash
   3197  1.1  skrll    table.  We also set up the .plt entries for statically linked PIC
   3198  1.1  skrll    functions here.  This function is called via hppaelf_finish in the
   3199  1.1  skrll    linker.  */
   3200  1.1  skrll 
   3201  1.1  skrll bfd_boolean
   3202  1.1  skrll elf32_hppa_build_stubs (struct bfd_link_info *info)
   3203  1.1  skrll {
   3204  1.1  skrll   asection *stub_sec;
   3205  1.1  skrll   struct bfd_hash_table *table;
   3206  1.1  skrll   struct elf32_hppa_link_hash_table *htab;
   3207  1.1  skrll 
   3208  1.1  skrll   htab = hppa_link_hash_table (info);
   3209  1.1  skrll 
   3210  1.1  skrll   for (stub_sec = htab->stub_bfd->sections;
   3211  1.1  skrll        stub_sec != NULL;
   3212  1.1  skrll        stub_sec = stub_sec->next)
   3213  1.1  skrll     {
   3214  1.1  skrll       bfd_size_type size;
   3215  1.1  skrll 
   3216  1.1  skrll       /* Allocate memory to hold the linker stubs.  */
   3217  1.1  skrll       size = stub_sec->size;
   3218  1.1  skrll       stub_sec->contents = bfd_zalloc (htab->stub_bfd, size);
   3219  1.1  skrll       if (stub_sec->contents == NULL && size != 0)
   3220  1.1  skrll 	return FALSE;
   3221  1.1  skrll       stub_sec->size = 0;
   3222  1.1  skrll     }
   3223  1.1  skrll 
   3224  1.1  skrll   /* Build the stubs as directed by the stub hash table.  */
   3225  1.1  skrll   table = &htab->bstab;
   3226  1.1  skrll   bfd_hash_traverse (table, hppa_build_one_stub, info);
   3227  1.1  skrll 
   3228  1.1  skrll   return TRUE;
   3229  1.1  skrll }
   3230  1.1  skrll 
   3231  1.1  skrll /* Return the base vma address which should be subtracted from the real
   3232  1.1  skrll    address when resolving a dtpoff relocation.
   3233  1.1  skrll    This is PT_TLS segment p_vaddr.  */
   3234  1.1  skrll 
   3235  1.1  skrll static bfd_vma
   3236  1.1  skrll dtpoff_base (struct bfd_link_info *info)
   3237  1.1  skrll {
   3238  1.1  skrll   /* If tls_sec is NULL, we should have signalled an error already.  */
   3239  1.1  skrll   if (elf_hash_table (info)->tls_sec == NULL)
   3240  1.1  skrll     return 0;
   3241  1.1  skrll   return elf_hash_table (info)->tls_sec->vma;
   3242  1.1  skrll }
   3243  1.1  skrll 
   3244  1.1  skrll /* Return the relocation value for R_PARISC_TLS_TPOFF*..  */
   3245  1.1  skrll 
   3246  1.1  skrll static bfd_vma
   3247  1.1  skrll tpoff (struct bfd_link_info *info, bfd_vma address)
   3248  1.1  skrll {
   3249  1.1  skrll   struct elf_link_hash_table *htab = elf_hash_table (info);
   3250  1.1  skrll 
   3251  1.1  skrll   /* If tls_sec is NULL, we should have signalled an error already.  */
   3252  1.1  skrll   if (htab->tls_sec == NULL)
   3253  1.1  skrll     return 0;
   3254  1.1  skrll   /* hppa TLS ABI is variant I and static TLS block start just after
   3255  1.1  skrll      tcbhead structure which has 2 pointer fields.  */
   3256  1.1  skrll   return (address - htab->tls_sec->vma
   3257  1.1  skrll 	  + align_power ((bfd_vma) 8, htab->tls_sec->alignment_power));
   3258  1.1  skrll }
   3259  1.1  skrll 
   3260  1.1  skrll /* Perform a final link.  */
   3261  1.1  skrll 
   3262  1.1  skrll static bfd_boolean
   3263  1.1  skrll elf32_hppa_final_link (bfd *abfd, struct bfd_link_info *info)
   3264  1.1  skrll {
   3265  1.1  skrll   /* Invoke the regular ELF linker to do all the work.  */
   3266  1.1  skrll   if (!bfd_elf_final_link (abfd, info))
   3267  1.1  skrll     return FALSE;
   3268  1.1  skrll 
   3269  1.1  skrll   /* If we're producing a final executable, sort the contents of the
   3270  1.1  skrll      unwind section.  */
   3271  1.1  skrll   return elf_hppa_sort_unwind (abfd);
   3272  1.1  skrll }
   3273  1.1  skrll 
   3274  1.1  skrll /* Record the lowest address for the data and text segments.  */
   3275  1.1  skrll 
   3276  1.1  skrll static void
   3277  1.1  skrll hppa_record_segment_addr (bfd *abfd, asection *section, void *data)
   3278  1.1  skrll {
   3279  1.1  skrll   struct elf32_hppa_link_hash_table *htab;
   3280  1.1  skrll 
   3281  1.1  skrll   htab = (struct elf32_hppa_link_hash_table*) data;
   3282  1.1  skrll 
   3283  1.1  skrll   if ((section->flags & (SEC_ALLOC | SEC_LOAD)) == (SEC_ALLOC | SEC_LOAD))
   3284  1.1  skrll     {
   3285  1.1  skrll       bfd_vma value;
   3286  1.1  skrll       Elf_Internal_Phdr *p;
   3287  1.1  skrll 
   3288  1.1  skrll       p = _bfd_elf_find_segment_containing_section (abfd, section->output_section);
   3289  1.1  skrll       BFD_ASSERT (p != NULL);
   3290  1.1  skrll       value = p->p_vaddr;
   3291  1.1  skrll 
   3292  1.1  skrll       if ((section->flags & SEC_READONLY) != 0)
   3293  1.1  skrll 	{
   3294  1.1  skrll 	  if (value < htab->text_segment_base)
   3295  1.1  skrll 	    htab->text_segment_base = value;
   3296  1.1  skrll 	}
   3297  1.1  skrll       else
   3298  1.1  skrll 	{
   3299  1.1  skrll 	  if (value < htab->data_segment_base)
   3300  1.1  skrll 	    htab->data_segment_base = value;
   3301  1.1  skrll 	}
   3302  1.1  skrll     }
   3303  1.1  skrll }
   3304  1.1  skrll 
   3305  1.1  skrll /* Perform a relocation as part of a final link.  */
   3306  1.1  skrll 
   3307  1.1  skrll static bfd_reloc_status_type
   3308  1.1  skrll final_link_relocate (asection *input_section,
   3309  1.1  skrll 		     bfd_byte *contents,
   3310  1.1  skrll 		     const Elf_Internal_Rela *rela,
   3311  1.1  skrll 		     bfd_vma value,
   3312  1.1  skrll 		     struct elf32_hppa_link_hash_table *htab,
   3313  1.1  skrll 		     asection *sym_sec,
   3314  1.1  skrll 		     struct elf32_hppa_link_hash_entry *hh,
   3315  1.1  skrll 		     struct bfd_link_info *info)
   3316  1.1  skrll {
   3317  1.1  skrll   int insn;
   3318  1.1  skrll   unsigned int r_type = ELF32_R_TYPE (rela->r_info);
   3319  1.1  skrll   unsigned int orig_r_type = r_type;
   3320  1.1  skrll   reloc_howto_type *howto = elf_hppa_howto_table + r_type;
   3321  1.1  skrll   int r_format = howto->bitsize;
   3322  1.1  skrll   enum hppa_reloc_field_selector_type_alt r_field;
   3323  1.1  skrll   bfd *input_bfd = input_section->owner;
   3324  1.1  skrll   bfd_vma offset = rela->r_offset;
   3325  1.1  skrll   bfd_vma max_branch_offset = 0;
   3326  1.1  skrll   bfd_byte *hit_data = contents + offset;
   3327  1.1  skrll   bfd_signed_vma addend = rela->r_addend;
   3328  1.1  skrll   bfd_vma location;
   3329  1.1  skrll   struct elf32_hppa_stub_hash_entry *hsh = NULL;
   3330  1.1  skrll   int val;
   3331  1.1  skrll 
   3332  1.1  skrll   if (r_type == R_PARISC_NONE)
   3333  1.1  skrll     return bfd_reloc_ok;
   3334  1.1  skrll 
   3335  1.1  skrll   insn = bfd_get_32 (input_bfd, hit_data);
   3336  1.1  skrll 
   3337  1.1  skrll   /* Find out where we are and where we're going.  */
   3338  1.1  skrll   location = (offset +
   3339  1.1  skrll 	      input_section->output_offset +
   3340  1.1  skrll 	      input_section->output_section->vma);
   3341  1.1  skrll 
   3342  1.1  skrll   /* If we are not building a shared library, convert DLTIND relocs to
   3343  1.1  skrll      DPREL relocs.  */
   3344  1.1  skrll   if (!info->shared)
   3345  1.1  skrll     {
   3346  1.1  skrll       switch (r_type)
   3347  1.1  skrll 	{
   3348  1.1  skrll 	  case R_PARISC_DLTIND21L:
   3349  1.1  skrll 	    r_type = R_PARISC_DPREL21L;
   3350  1.1  skrll 	    break;
   3351  1.1  skrll 
   3352  1.1  skrll 	  case R_PARISC_DLTIND14R:
   3353  1.1  skrll 	    r_type = R_PARISC_DPREL14R;
   3354  1.1  skrll 	    break;
   3355  1.1  skrll 
   3356  1.1  skrll 	  case R_PARISC_DLTIND14F:
   3357  1.1  skrll 	    r_type = R_PARISC_DPREL14F;
   3358  1.1  skrll 	    break;
   3359  1.1  skrll 	}
   3360  1.1  skrll     }
   3361  1.1  skrll 
   3362  1.1  skrll   switch (r_type)
   3363  1.1  skrll     {
   3364  1.1  skrll     case R_PARISC_PCREL12F:
   3365  1.1  skrll     case R_PARISC_PCREL17F:
   3366  1.1  skrll     case R_PARISC_PCREL22F:
   3367  1.1  skrll       /* If this call should go via the plt, find the import stub in
   3368  1.1  skrll 	 the stub hash.  */
   3369  1.1  skrll       if (sym_sec == NULL
   3370  1.1  skrll 	  || sym_sec->output_section == NULL
   3371  1.1  skrll 	  || (hh != NULL
   3372  1.1  skrll 	      && hh->eh.plt.offset != (bfd_vma) -1
   3373  1.1  skrll 	      && hh->eh.dynindx != -1
   3374  1.1  skrll 	      && !hh->plabel
   3375  1.1  skrll 	      && (info->shared
   3376  1.1  skrll 		  || !hh->eh.def_regular
   3377  1.1  skrll 		  || hh->eh.root.type == bfd_link_hash_defweak)))
   3378  1.1  skrll 	{
   3379  1.1  skrll 	  hsh = hppa_get_stub_entry (input_section, sym_sec,
   3380  1.1  skrll 					    hh, rela, htab);
   3381  1.1  skrll 	  if (hsh != NULL)
   3382  1.1  skrll 	    {
   3383  1.1  skrll 	      value = (hsh->stub_offset
   3384  1.1  skrll 		       + hsh->stub_sec->output_offset
   3385  1.1  skrll 		       + hsh->stub_sec->output_section->vma);
   3386  1.1  skrll 	      addend = 0;
   3387  1.1  skrll 	    }
   3388  1.1  skrll 	  else if (sym_sec == NULL && hh != NULL
   3389  1.1  skrll 		   && hh->eh.root.type == bfd_link_hash_undefweak)
   3390  1.1  skrll 	    {
   3391  1.1  skrll 	      /* It's OK if undefined weak.  Calls to undefined weak
   3392  1.1  skrll 		 symbols behave as if the "called" function
   3393  1.1  skrll 		 immediately returns.  We can thus call to a weak
   3394  1.1  skrll 		 function without first checking whether the function
   3395  1.1  skrll 		 is defined.  */
   3396  1.1  skrll 	      value = location;
   3397  1.1  skrll 	      addend = 8;
   3398  1.1  skrll 	    }
   3399  1.1  skrll 	  else
   3400  1.1  skrll 	    return bfd_reloc_undefined;
   3401  1.1  skrll 	}
   3402  1.1  skrll       /* Fall thru.  */
   3403  1.1  skrll 
   3404  1.1  skrll     case R_PARISC_PCREL21L:
   3405  1.1  skrll     case R_PARISC_PCREL17C:
   3406  1.1  skrll     case R_PARISC_PCREL17R:
   3407  1.1  skrll     case R_PARISC_PCREL14R:
   3408  1.1  skrll     case R_PARISC_PCREL14F:
   3409  1.1  skrll     case R_PARISC_PCREL32:
   3410  1.1  skrll       /* Make it a pc relative offset.  */
   3411  1.1  skrll       value -= location;
   3412  1.1  skrll       addend -= 8;
   3413  1.1  skrll       break;
   3414  1.1  skrll 
   3415  1.1  skrll     case R_PARISC_DPREL21L:
   3416  1.1  skrll     case R_PARISC_DPREL14R:
   3417  1.1  skrll     case R_PARISC_DPREL14F:
   3418  1.1  skrll       /* Convert instructions that use the linkage table pointer (r19) to
   3419  1.1  skrll 	 instructions that use the global data pointer (dp).  This is the
   3420  1.1  skrll 	 most efficient way of using PIC code in an incomplete executable,
   3421  1.1  skrll 	 but the user must follow the standard runtime conventions for
   3422  1.1  skrll 	 accessing data for this to work.  */
   3423  1.1  skrll       if (orig_r_type == R_PARISC_DLTIND21L)
   3424  1.1  skrll 	{
   3425  1.1  skrll 	  /* Convert addil instructions if the original reloc was a
   3426  1.1  skrll 	     DLTIND21L.  GCC sometimes uses a register other than r19 for
   3427  1.1  skrll 	     the operation, so we must convert any addil instruction
   3428  1.1  skrll 	     that uses this relocation.  */
   3429  1.1  skrll 	  if ((insn & 0xfc000000) == ((int) OP_ADDIL << 26))
   3430  1.1  skrll 	    insn = ADDIL_DP;
   3431  1.1  skrll 	  else
   3432  1.1  skrll 	    /* We must have a ldil instruction.  It's too hard to find
   3433  1.1  skrll 	       and convert the associated add instruction, so issue an
   3434  1.1  skrll 	       error.  */
   3435  1.1  skrll 	    (*_bfd_error_handler)
   3436  1.1  skrll 	      (_("%B(%A+0x%lx): %s fixup for insn 0x%x is not supported in a non-shared link"),
   3437  1.1  skrll 	       input_bfd,
   3438  1.1  skrll 	       input_section,
   3439  1.1  skrll 	       offset,
   3440  1.1  skrll 	       howto->name,
   3441  1.1  skrll 	       insn);
   3442  1.1  skrll 	}
   3443  1.1  skrll       else if (orig_r_type == R_PARISC_DLTIND14F)
   3444  1.1  skrll 	{
   3445  1.1  skrll 	  /* This must be a format 1 load/store.  Change the base
   3446  1.1  skrll 	     register to dp.  */
   3447  1.1  skrll 	  insn = (insn & 0xfc1ffff) | (27 << 21);
   3448  1.1  skrll 	}
   3449  1.1  skrll 
   3450  1.1  skrll     /* For all the DP relative relocations, we need to examine the symbol's
   3451  1.1  skrll        section.  If it has no section or if it's a code section, then
   3452  1.1  skrll        "data pointer relative" makes no sense.  In that case we don't
   3453  1.1  skrll        adjust the "value", and for 21 bit addil instructions, we change the
   3454  1.1  skrll        source addend register from %dp to %r0.  This situation commonly
   3455  1.1  skrll        arises for undefined weak symbols and when a variable's "constness"
   3456  1.1  skrll        is declared differently from the way the variable is defined.  For
   3457  1.1  skrll        instance: "extern int foo" with foo defined as "const int foo".  */
   3458  1.1  skrll       if (sym_sec == NULL || (sym_sec->flags & SEC_CODE) != 0)
   3459  1.1  skrll 	{
   3460  1.1  skrll 	  if ((insn & ((0x3f << 26) | (0x1f << 21)))
   3461  1.1  skrll 	      == (((int) OP_ADDIL << 26) | (27 << 21)))
   3462  1.1  skrll 	    {
   3463  1.1  skrll 	      insn &= ~ (0x1f << 21);
   3464  1.1  skrll 	    }
   3465  1.1  skrll 	  /* Now try to make things easy for the dynamic linker.  */
   3466  1.1  skrll 
   3467  1.1  skrll 	  break;
   3468  1.1  skrll 	}
   3469  1.1  skrll       /* Fall thru.  */
   3470  1.1  skrll 
   3471  1.1  skrll     case R_PARISC_DLTIND21L:
   3472  1.1  skrll     case R_PARISC_DLTIND14R:
   3473  1.1  skrll     case R_PARISC_DLTIND14F:
   3474  1.1  skrll     case R_PARISC_TLS_GD21L:
   3475  1.1  skrll     case R_PARISC_TLS_GD14R:
   3476  1.1  skrll     case R_PARISC_TLS_LDM21L:
   3477  1.1  skrll     case R_PARISC_TLS_LDM14R:
   3478  1.1  skrll     case R_PARISC_TLS_IE21L:
   3479  1.1  skrll     case R_PARISC_TLS_IE14R:
   3480  1.1  skrll       value -= elf_gp (input_section->output_section->owner);
   3481  1.1  skrll       break;
   3482  1.1  skrll 
   3483  1.1  skrll     case R_PARISC_SEGREL32:
   3484  1.1  skrll       if ((sym_sec->flags & SEC_CODE) != 0)
   3485  1.1  skrll 	value -= htab->text_segment_base;
   3486  1.1  skrll       else
   3487  1.1  skrll 	value -= htab->data_segment_base;
   3488  1.1  skrll       break;
   3489  1.1  skrll 
   3490  1.1  skrll     default:
   3491  1.1  skrll       break;
   3492  1.1  skrll     }
   3493  1.1  skrll 
   3494  1.1  skrll   switch (r_type)
   3495  1.1  skrll     {
   3496  1.1  skrll     case R_PARISC_DIR32:
   3497  1.1  skrll     case R_PARISC_DIR14F:
   3498  1.1  skrll     case R_PARISC_DIR17F:
   3499  1.1  skrll     case R_PARISC_PCREL17C:
   3500  1.1  skrll     case R_PARISC_PCREL14F:
   3501  1.1  skrll     case R_PARISC_PCREL32:
   3502  1.1  skrll     case R_PARISC_DPREL14F:
   3503  1.1  skrll     case R_PARISC_PLABEL32:
   3504  1.1  skrll     case R_PARISC_DLTIND14F:
   3505  1.1  skrll     case R_PARISC_SEGBASE:
   3506  1.1  skrll     case R_PARISC_SEGREL32:
   3507  1.1  skrll     case R_PARISC_TLS_DTPMOD32:
   3508  1.1  skrll     case R_PARISC_TLS_DTPOFF32:
   3509  1.1  skrll     case R_PARISC_TLS_TPREL32:
   3510  1.1  skrll       r_field = e_fsel;
   3511  1.1  skrll       break;
   3512  1.1  skrll 
   3513  1.1  skrll     case R_PARISC_DLTIND21L:
   3514  1.1  skrll     case R_PARISC_PCREL21L:
   3515  1.1  skrll     case R_PARISC_PLABEL21L:
   3516  1.1  skrll       r_field = e_lsel;
   3517  1.1  skrll       break;
   3518  1.1  skrll 
   3519  1.1  skrll     case R_PARISC_DIR21L:
   3520  1.1  skrll     case R_PARISC_DPREL21L:
   3521  1.1  skrll     case R_PARISC_TLS_GD21L:
   3522  1.1  skrll     case R_PARISC_TLS_LDM21L:
   3523  1.1  skrll     case R_PARISC_TLS_LDO21L:
   3524  1.1  skrll     case R_PARISC_TLS_IE21L:
   3525  1.1  skrll     case R_PARISC_TLS_LE21L:
   3526  1.1  skrll       r_field = e_lrsel;
   3527  1.1  skrll       break;
   3528  1.1  skrll 
   3529  1.1  skrll     case R_PARISC_PCREL17R:
   3530  1.1  skrll     case R_PARISC_PCREL14R:
   3531  1.1  skrll     case R_PARISC_PLABEL14R:
   3532  1.1  skrll     case R_PARISC_DLTIND14R:
   3533  1.1  skrll       r_field = e_rsel;
   3534  1.1  skrll       break;
   3535  1.1  skrll 
   3536  1.1  skrll     case R_PARISC_DIR17R:
   3537  1.1  skrll     case R_PARISC_DIR14R:
   3538  1.1  skrll     case R_PARISC_DPREL14R:
   3539  1.1  skrll     case R_PARISC_TLS_GD14R:
   3540  1.1  skrll     case R_PARISC_TLS_LDM14R:
   3541  1.1  skrll     case R_PARISC_TLS_LDO14R:
   3542  1.1  skrll     case R_PARISC_TLS_IE14R:
   3543  1.1  skrll     case R_PARISC_TLS_LE14R:
   3544  1.1  skrll       r_field = e_rrsel;
   3545  1.1  skrll       break;
   3546  1.1  skrll 
   3547  1.1  skrll     case R_PARISC_PCREL12F:
   3548  1.1  skrll     case R_PARISC_PCREL17F:
   3549  1.1  skrll     case R_PARISC_PCREL22F:
   3550  1.1  skrll       r_field = e_fsel;
   3551  1.1  skrll 
   3552  1.1  skrll       if (r_type == (unsigned int) R_PARISC_PCREL17F)
   3553  1.1  skrll 	{
   3554  1.1  skrll 	  max_branch_offset = (1 << (17-1)) << 2;
   3555  1.1  skrll 	}
   3556  1.1  skrll       else if (r_type == (unsigned int) R_PARISC_PCREL12F)
   3557  1.1  skrll 	{
   3558  1.1  skrll 	  max_branch_offset = (1 << (12-1)) << 2;
   3559  1.1  skrll 	}
   3560  1.1  skrll       else
   3561  1.1  skrll 	{
   3562  1.1  skrll 	  max_branch_offset = (1 << (22-1)) << 2;
   3563  1.1  skrll 	}
   3564  1.1  skrll 
   3565  1.1  skrll       /* sym_sec is NULL on undefined weak syms or when shared on
   3566  1.1  skrll 	 undefined syms.  We've already checked for a stub for the
   3567  1.1  skrll 	 shared undefined case.  */
   3568  1.1  skrll       if (sym_sec == NULL)
   3569  1.1  skrll 	break;
   3570  1.1  skrll 
   3571  1.1  skrll       /* If the branch is out of reach, then redirect the
   3572  1.1  skrll 	 call to the local stub for this function.  */
   3573  1.1  skrll       if (value + addend + max_branch_offset >= 2*max_branch_offset)
   3574  1.1  skrll 	{
   3575  1.1  skrll 	  hsh = hppa_get_stub_entry (input_section, sym_sec,
   3576  1.1  skrll 					    hh, rela, htab);
   3577  1.1  skrll 	  if (hsh == NULL)
   3578  1.1  skrll 	    return bfd_reloc_undefined;
   3579  1.1  skrll 
   3580  1.1  skrll 	  /* Munge up the value and addend so that we call the stub
   3581  1.1  skrll 	     rather than the procedure directly.  */
   3582  1.1  skrll 	  value = (hsh->stub_offset
   3583  1.1  skrll 		   + hsh->stub_sec->output_offset
   3584  1.1  skrll 		   + hsh->stub_sec->output_section->vma
   3585  1.1  skrll 		   - location);
   3586  1.1  skrll 	  addend = -8;
   3587  1.1  skrll 	}
   3588  1.1  skrll       break;
   3589  1.1  skrll 
   3590  1.1  skrll     /* Something we don't know how to handle.  */
   3591  1.1  skrll     default:
   3592  1.1  skrll       return bfd_reloc_notsupported;
   3593  1.1  skrll     }
   3594  1.1  skrll 
   3595  1.1  skrll   /* Make sure we can reach the stub.  */
   3596  1.1  skrll   if (max_branch_offset != 0
   3597  1.1  skrll       && value + addend + max_branch_offset >= 2*max_branch_offset)
   3598  1.1  skrll     {
   3599  1.1  skrll       (*_bfd_error_handler)
   3600  1.1  skrll 	(_("%B(%A+0x%lx): cannot reach %s, recompile with -ffunction-sections"),
   3601  1.1  skrll 	 input_bfd,
   3602  1.1  skrll 	 input_section,
   3603  1.1  skrll 	 offset,
   3604  1.1  skrll 	 hsh->bh_root.string);
   3605  1.1  skrll       bfd_set_error (bfd_error_bad_value);
   3606  1.1  skrll       return bfd_reloc_notsupported;
   3607  1.1  skrll     }
   3608  1.1  skrll 
   3609  1.1  skrll   val = hppa_field_adjust (value, addend, r_field);
   3610  1.1  skrll 
   3611  1.1  skrll   switch (r_type)
   3612  1.1  skrll     {
   3613  1.1  skrll     case R_PARISC_PCREL12F:
   3614  1.1  skrll     case R_PARISC_PCREL17C:
   3615  1.1  skrll     case R_PARISC_PCREL17F:
   3616  1.1  skrll     case R_PARISC_PCREL17R:
   3617  1.1  skrll     case R_PARISC_PCREL22F:
   3618  1.1  skrll     case R_PARISC_DIR17F:
   3619  1.1  skrll     case R_PARISC_DIR17R:
   3620  1.1  skrll       /* This is a branch.  Divide the offset by four.
   3621  1.1  skrll 	 Note that we need to decide whether it's a branch or
   3622  1.1  skrll 	 otherwise by inspecting the reloc.  Inspecting insn won't
   3623  1.1  skrll 	 work as insn might be from a .word directive.  */
   3624  1.1  skrll       val >>= 2;
   3625  1.1  skrll       break;
   3626  1.1  skrll 
   3627  1.1  skrll     default:
   3628  1.1  skrll       break;
   3629  1.1  skrll     }
   3630  1.1  skrll 
   3631  1.1  skrll   insn = hppa_rebuild_insn (insn, val, r_format);
   3632  1.1  skrll 
   3633  1.1  skrll   /* Update the instruction word.  */
   3634  1.1  skrll   bfd_put_32 (input_bfd, (bfd_vma) insn, hit_data);
   3635  1.1  skrll   return bfd_reloc_ok;
   3636  1.1  skrll }
   3637  1.1  skrll 
   3638  1.1  skrll /* Relocate an HPPA ELF section.  */
   3639  1.1  skrll 
   3640  1.1  skrll static bfd_boolean
   3641  1.1  skrll elf32_hppa_relocate_section (bfd *output_bfd,
   3642  1.1  skrll 			     struct bfd_link_info *info,
   3643  1.1  skrll 			     bfd *input_bfd,
   3644  1.1  skrll 			     asection *input_section,
   3645  1.1  skrll 			     bfd_byte *contents,
   3646  1.1  skrll 			     Elf_Internal_Rela *relocs,
   3647  1.1  skrll 			     Elf_Internal_Sym *local_syms,
   3648  1.1  skrll 			     asection **local_sections)
   3649  1.1  skrll {
   3650  1.1  skrll   bfd_vma *local_got_offsets;
   3651  1.1  skrll   struct elf32_hppa_link_hash_table *htab;
   3652  1.1  skrll   Elf_Internal_Shdr *symtab_hdr;
   3653  1.1  skrll   Elf_Internal_Rela *rela;
   3654  1.1  skrll   Elf_Internal_Rela *relend;
   3655  1.1  skrll 
   3656  1.1  skrll   symtab_hdr = &elf_tdata (input_bfd)->symtab_hdr;
   3657  1.1  skrll 
   3658  1.1  skrll   htab = hppa_link_hash_table (info);
   3659  1.1  skrll   local_got_offsets = elf_local_got_offsets (input_bfd);
   3660  1.1  skrll 
   3661  1.1  skrll   rela = relocs;
   3662  1.1  skrll   relend = relocs + input_section->reloc_count;
   3663  1.1  skrll   for (; rela < relend; rela++)
   3664  1.1  skrll     {
   3665  1.1  skrll       unsigned int r_type;
   3666  1.1  skrll       reloc_howto_type *howto;
   3667  1.1  skrll       unsigned int r_symndx;
   3668  1.1  skrll       struct elf32_hppa_link_hash_entry *hh;
   3669  1.1  skrll       Elf_Internal_Sym *sym;
   3670  1.1  skrll       asection *sym_sec;
   3671  1.1  skrll       bfd_vma relocation;
   3672  1.1  skrll       bfd_reloc_status_type rstatus;
   3673  1.1  skrll       const char *sym_name;
   3674  1.1  skrll       bfd_boolean plabel;
   3675  1.1  skrll       bfd_boolean warned_undef;
   3676  1.1  skrll 
   3677  1.1  skrll       r_type = ELF32_R_TYPE (rela->r_info);
   3678  1.1  skrll       if (r_type >= (unsigned int) R_PARISC_UNIMPLEMENTED)
   3679  1.1  skrll 	{
   3680  1.1  skrll 	  bfd_set_error (bfd_error_bad_value);
   3681  1.1  skrll 	  return FALSE;
   3682  1.1  skrll 	}
   3683  1.1  skrll       if (r_type == (unsigned int) R_PARISC_GNU_VTENTRY
   3684  1.1  skrll 	  || r_type == (unsigned int) R_PARISC_GNU_VTINHERIT)
   3685  1.1  skrll 	continue;
   3686  1.1  skrll 
   3687  1.1  skrll       r_symndx = ELF32_R_SYM (rela->r_info);
   3688  1.1  skrll       hh = NULL;
   3689  1.1  skrll       sym = NULL;
   3690  1.1  skrll       sym_sec = NULL;
   3691  1.1  skrll       warned_undef = FALSE;
   3692  1.1  skrll       if (r_symndx < symtab_hdr->sh_info)
   3693  1.1  skrll 	{
   3694  1.1  skrll 	  /* This is a local symbol, h defaults to NULL.  */
   3695  1.1  skrll 	  sym = local_syms + r_symndx;
   3696  1.1  skrll 	  sym_sec = local_sections[r_symndx];
   3697  1.1  skrll 	  relocation = _bfd_elf_rela_local_sym (output_bfd, sym, &sym_sec, rela);
   3698  1.1  skrll 	}
   3699  1.1  skrll       else
   3700  1.1  skrll 	{
   3701  1.1  skrll 	  struct elf_link_hash_entry *eh;
   3702  1.1  skrll 	  bfd_boolean unresolved_reloc;
   3703  1.1  skrll 	  struct elf_link_hash_entry **sym_hashes = elf_sym_hashes (input_bfd);
   3704  1.1  skrll 
   3705  1.1  skrll 	  RELOC_FOR_GLOBAL_SYMBOL (info, input_bfd, input_section, rela,
   3706  1.1  skrll 				   r_symndx, symtab_hdr, sym_hashes,
   3707  1.1  skrll 				   eh, sym_sec, relocation,
   3708  1.1  skrll 				   unresolved_reloc, warned_undef);
   3709  1.1  skrll 
   3710  1.1  skrll 	  if (!info->relocatable
   3711  1.1  skrll 	      && relocation == 0
   3712  1.1  skrll 	      && eh->root.type != bfd_link_hash_defined
   3713  1.1  skrll 	      && eh->root.type != bfd_link_hash_defweak
   3714  1.1  skrll 	      && eh->root.type != bfd_link_hash_undefweak)
   3715  1.1  skrll 	    {
   3716  1.1  skrll 	      if (info->unresolved_syms_in_objects == RM_IGNORE
   3717  1.1  skrll 		  && ELF_ST_VISIBILITY (eh->other) == STV_DEFAULT
   3718  1.1  skrll 		  && eh->type == STT_PARISC_MILLI)
   3719  1.1  skrll 		{
   3720  1.1  skrll 		  if (! info->callbacks->undefined_symbol
   3721  1.1  skrll 		      (info, eh_name (eh), input_bfd,
   3722  1.1  skrll 		       input_section, rela->r_offset, FALSE))
   3723  1.1  skrll 		    return FALSE;
   3724  1.1  skrll 		  warned_undef = TRUE;
   3725  1.1  skrll 		}
   3726  1.1  skrll 	    }
   3727  1.1  skrll 	  hh = hppa_elf_hash_entry (eh);
   3728  1.1  skrll 	}
   3729  1.1  skrll 
   3730  1.1  skrll       if (sym_sec != NULL && elf_discarded_section (sym_sec))
   3731  1.1  skrll 	{
   3732  1.1  skrll 	  /* For relocs against symbols from removed linkonce
   3733  1.1  skrll 	     sections, or sections discarded by a linker script,
   3734  1.1  skrll 	     we just want the section contents zeroed.  Avoid any
   3735  1.1  skrll 	     special processing.  */
   3736  1.1  skrll 	  _bfd_clear_contents (elf_hppa_howto_table + r_type, input_bfd,
   3737  1.1  skrll 			       contents + rela->r_offset);
   3738  1.1  skrll 	  rela->r_info = 0;
   3739  1.1  skrll 	  rela->r_addend = 0;
   3740  1.1  skrll 	  continue;
   3741  1.1  skrll 	}
   3742  1.1  skrll 
   3743  1.1  skrll       if (info->relocatable)
   3744  1.1  skrll 	continue;
   3745  1.1  skrll 
   3746  1.1  skrll       /* Do any required modifications to the relocation value, and
   3747  1.1  skrll 	 determine what types of dynamic info we need to output, if
   3748  1.1  skrll 	 any.  */
   3749  1.1  skrll       plabel = 0;
   3750  1.1  skrll       switch (r_type)
   3751  1.1  skrll 	{
   3752  1.1  skrll 	case R_PARISC_DLTIND14F:
   3753  1.1  skrll 	case R_PARISC_DLTIND14R:
   3754  1.1  skrll 	case R_PARISC_DLTIND21L:
   3755  1.1  skrll 	  {
   3756  1.1  skrll 	    bfd_vma off;
   3757  1.1  skrll 	    bfd_boolean do_got = 0;
   3758  1.1  skrll 
   3759  1.1  skrll 	    /* Relocation is to the entry for this symbol in the
   3760  1.1  skrll 	       global offset table.  */
   3761  1.1  skrll 	    if (hh != NULL)
   3762  1.1  skrll 	      {
   3763  1.1  skrll 		bfd_boolean dyn;
   3764  1.1  skrll 
   3765  1.1  skrll 		off = hh->eh.got.offset;
   3766  1.1  skrll 		dyn = htab->etab.dynamic_sections_created;
   3767  1.1  skrll 		if (! WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn, info->shared,
   3768  1.1  skrll 						       &hh->eh))
   3769  1.1  skrll 		  {
   3770  1.1  skrll 		    /* If we aren't going to call finish_dynamic_symbol,
   3771  1.1  skrll 		       then we need to handle initialisation of the .got
   3772  1.1  skrll 		       entry and create needed relocs here.  Since the
   3773  1.1  skrll 		       offset must always be a multiple of 4, we use the
   3774  1.1  skrll 		       least significant bit to record whether we have
   3775  1.1  skrll 		       initialised it already.  */
   3776  1.1  skrll 		    if ((off & 1) != 0)
   3777  1.1  skrll 		      off &= ~1;
   3778  1.1  skrll 		    else
   3779  1.1  skrll 		      {
   3780  1.1  skrll 			hh->eh.got.offset |= 1;
   3781  1.1  skrll 			do_got = 1;
   3782  1.1  skrll 		      }
   3783  1.1  skrll 		  }
   3784  1.1  skrll 	      }
   3785  1.1  skrll 	    else
   3786  1.1  skrll 	      {
   3787  1.1  skrll 		/* Local symbol case.  */
   3788  1.1  skrll 		if (local_got_offsets == NULL)
   3789  1.1  skrll 		  abort ();
   3790  1.1  skrll 
   3791  1.1  skrll 		off = local_got_offsets[r_symndx];
   3792  1.1  skrll 
   3793  1.1  skrll 		/* The offset must always be a multiple of 4.  We use
   3794  1.1  skrll 		   the least significant bit to record whether we have
   3795  1.1  skrll 		   already generated the necessary reloc.  */
   3796  1.1  skrll 		if ((off & 1) != 0)
   3797  1.1  skrll 		  off &= ~1;
   3798  1.1  skrll 		else
   3799  1.1  skrll 		  {
   3800  1.1  skrll 		    local_got_offsets[r_symndx] |= 1;
   3801  1.1  skrll 		    do_got = 1;
   3802  1.1  skrll 		  }
   3803  1.1  skrll 	      }
   3804  1.1  skrll 
   3805  1.1  skrll 	    if (do_got)
   3806  1.1  skrll 	      {
   3807  1.1  skrll 		if (info->shared)
   3808  1.1  skrll 		  {
   3809  1.1  skrll 		    /* Output a dynamic relocation for this GOT entry.
   3810  1.1  skrll 		       In this case it is relative to the base of the
   3811  1.1  skrll 		       object because the symbol index is zero.  */
   3812  1.1  skrll 		    Elf_Internal_Rela outrel;
   3813  1.1  skrll 		    bfd_byte *loc;
   3814  1.1  skrll 		    asection *sec = htab->srelgot;
   3815  1.1  skrll 
   3816  1.1  skrll 		    outrel.r_offset = (off
   3817  1.1  skrll 				       + htab->sgot->output_offset
   3818  1.1  skrll 				       + htab->sgot->output_section->vma);
   3819  1.1  skrll 		    outrel.r_info = ELF32_R_INFO (0, R_PARISC_DIR32);
   3820  1.1  skrll 		    outrel.r_addend = relocation;
   3821  1.1  skrll 		    loc = sec->contents;
   3822  1.1  skrll 		    loc += sec->reloc_count++ * sizeof (Elf32_External_Rela);
   3823  1.1  skrll 		    bfd_elf32_swap_reloca_out (output_bfd, &outrel, loc);
   3824  1.1  skrll 		  }
   3825  1.1  skrll 		else
   3826  1.1  skrll 		  bfd_put_32 (output_bfd, relocation,
   3827  1.1  skrll 			      htab->sgot->contents + off);
   3828  1.1  skrll 	      }
   3829  1.1  skrll 
   3830  1.1  skrll 	    if (off >= (bfd_vma) -2)
   3831  1.1  skrll 	      abort ();
   3832  1.1  skrll 
   3833  1.1  skrll 	    /* Add the base of the GOT to the relocation value.  */
   3834  1.1  skrll 	    relocation = (off
   3835  1.1  skrll 			  + htab->sgot->output_offset
   3836  1.1  skrll 			  + htab->sgot->output_section->vma);
   3837  1.1  skrll 	  }
   3838  1.1  skrll 	  break;
   3839  1.1  skrll 
   3840  1.1  skrll 	case R_PARISC_SEGREL32:
   3841  1.1  skrll 	  /* If this is the first SEGREL relocation, then initialize
   3842  1.1  skrll 	     the segment base values.  */
   3843  1.1  skrll 	  if (htab->text_segment_base == (bfd_vma) -1)
   3844  1.1  skrll 	    bfd_map_over_sections (output_bfd, hppa_record_segment_addr, htab);
   3845  1.1  skrll 	  break;
   3846  1.1  skrll 
   3847  1.1  skrll 	case R_PARISC_PLABEL14R:
   3848  1.1  skrll 	case R_PARISC_PLABEL21L:
   3849  1.1  skrll 	case R_PARISC_PLABEL32:
   3850  1.1  skrll 	  if (htab->etab.dynamic_sections_created)
   3851  1.1  skrll 	    {
   3852  1.1  skrll 	      bfd_vma off;
   3853  1.1  skrll 	      bfd_boolean do_plt = 0;
   3854  1.1  skrll 	      /* If we have a global symbol with a PLT slot, then
   3855  1.1  skrll 		 redirect this relocation to it.  */
   3856  1.1  skrll 	      if (hh != NULL)
   3857  1.1  skrll 		{
   3858  1.1  skrll 		  off = hh->eh.plt.offset;
   3859  1.1  skrll 		  if (! WILL_CALL_FINISH_DYNAMIC_SYMBOL (1, info->shared,
   3860  1.1  skrll 							 &hh->eh))
   3861  1.1  skrll 		    {
   3862  1.1  skrll 		      /* In a non-shared link, adjust_dynamic_symbols
   3863  1.1  skrll 			 isn't called for symbols forced local.  We
   3864  1.1  skrll 			 need to write out the plt entry here.  */
   3865  1.1  skrll 		      if ((off & 1) != 0)
   3866  1.1  skrll 			off &= ~1;
   3867  1.1  skrll 		      else
   3868  1.1  skrll 			{
   3869  1.1  skrll 			  hh->eh.plt.offset |= 1;
   3870  1.1  skrll 			  do_plt = 1;
   3871  1.1  skrll 			}
   3872  1.1  skrll 		    }
   3873  1.1  skrll 		}
   3874  1.1  skrll 	      else
   3875  1.1  skrll 		{
   3876  1.1  skrll 		  bfd_vma *local_plt_offsets;
   3877  1.1  skrll 
   3878  1.1  skrll 		  if (local_got_offsets == NULL)
   3879  1.1  skrll 		    abort ();
   3880  1.1  skrll 
   3881  1.1  skrll 		  local_plt_offsets = local_got_offsets + symtab_hdr->sh_info;
   3882  1.1  skrll 		  off = local_plt_offsets[r_symndx];
   3883  1.1  skrll 
   3884  1.1  skrll 		  /* As for the local .got entry case, we use the last
   3885  1.1  skrll 		     bit to record whether we've already initialised
   3886  1.1  skrll 		     this local .plt entry.  */
   3887  1.1  skrll 		  if ((off & 1) != 0)
   3888  1.1  skrll 		    off &= ~1;
   3889  1.1  skrll 		  else
   3890  1.1  skrll 		    {
   3891  1.1  skrll 		      local_plt_offsets[r_symndx] |= 1;
   3892  1.1  skrll 		      do_plt = 1;
   3893  1.1  skrll 		    }
   3894  1.1  skrll 		}
   3895  1.1  skrll 
   3896  1.1  skrll 	      if (do_plt)
   3897  1.1  skrll 		{
   3898  1.1  skrll 		  if (info->shared)
   3899  1.1  skrll 		    {
   3900  1.1  skrll 		      /* Output a dynamic IPLT relocation for this
   3901  1.1  skrll 			 PLT entry.  */
   3902  1.1  skrll 		      Elf_Internal_Rela outrel;
   3903  1.1  skrll 		      bfd_byte *loc;
   3904  1.1  skrll 		      asection *s = htab->srelplt;
   3905  1.1  skrll 
   3906  1.1  skrll 		      outrel.r_offset = (off
   3907  1.1  skrll 					 + htab->splt->output_offset
   3908  1.1  skrll 					 + htab->splt->output_section->vma);
   3909  1.1  skrll 		      outrel.r_info = ELF32_R_INFO (0, R_PARISC_IPLT);
   3910  1.1  skrll 		      outrel.r_addend = relocation;
   3911  1.1  skrll 		      loc = s->contents;
   3912  1.1  skrll 		      loc += s->reloc_count++ * sizeof (Elf32_External_Rela);
   3913  1.1  skrll 		      bfd_elf32_swap_reloca_out (output_bfd, &outrel, loc);
   3914  1.1  skrll 		    }
   3915  1.1  skrll 		  else
   3916  1.1  skrll 		    {
   3917  1.1  skrll 		      bfd_put_32 (output_bfd,
   3918  1.1  skrll 				  relocation,
   3919  1.1  skrll 				  htab->splt->contents + off);
   3920  1.1  skrll 		      bfd_put_32 (output_bfd,
   3921  1.1  skrll 				  elf_gp (htab->splt->output_section->owner),
   3922  1.1  skrll 				  htab->splt->contents + off + 4);
   3923  1.1  skrll 		    }
   3924  1.1  skrll 		}
   3925  1.1  skrll 
   3926  1.1  skrll 	      if (off >= (bfd_vma) -2)
   3927  1.1  skrll 		abort ();
   3928  1.1  skrll 
   3929  1.1  skrll 	      /* PLABELs contain function pointers.  Relocation is to
   3930  1.1  skrll 		 the entry for the function in the .plt.  The magic +2
   3931  1.1  skrll 		 offset signals to $$dyncall that the function pointer
   3932  1.1  skrll 		 is in the .plt and thus has a gp pointer too.
   3933  1.1  skrll 		 Exception:  Undefined PLABELs should have a value of
   3934  1.1  skrll 		 zero.  */
   3935  1.1  skrll 	      if (hh == NULL
   3936  1.1  skrll 		  || (hh->eh.root.type != bfd_link_hash_undefweak
   3937  1.1  skrll 		      && hh->eh.root.type != bfd_link_hash_undefined))
   3938  1.1  skrll 		{
   3939  1.1  skrll 		  relocation = (off
   3940  1.1  skrll 				+ htab->splt->output_offset
   3941  1.1  skrll 				+ htab->splt->output_section->vma
   3942  1.1  skrll 				+ 2);
   3943  1.1  skrll 		}
   3944  1.1  skrll 	      plabel = 1;
   3945  1.1  skrll 	    }
   3946  1.1  skrll 	  /* Fall through and possibly emit a dynamic relocation.  */
   3947  1.1  skrll 
   3948  1.1  skrll 	case R_PARISC_DIR17F:
   3949  1.1  skrll 	case R_PARISC_DIR17R:
   3950  1.1  skrll 	case R_PARISC_DIR14F:
   3951  1.1  skrll 	case R_PARISC_DIR14R:
   3952  1.1  skrll 	case R_PARISC_DIR21L:
   3953  1.1  skrll 	case R_PARISC_DPREL14F:
   3954  1.1  skrll 	case R_PARISC_DPREL14R:
   3955  1.1  skrll 	case R_PARISC_DPREL21L:
   3956  1.1  skrll 	case R_PARISC_DIR32:
   3957  1.1  skrll 	  if ((input_section->flags & SEC_ALLOC) == 0)
   3958  1.1  skrll 	    break;
   3959  1.1  skrll 
   3960  1.1  skrll 	  /* The reloc types handled here and this conditional
   3961  1.1  skrll 	     expression must match the code in ..check_relocs and
   3962  1.1  skrll 	     allocate_dynrelocs.  ie. We need exactly the same condition
   3963  1.1  skrll 	     as in ..check_relocs, with some extra conditions (dynindx
   3964  1.1  skrll 	     test in this case) to cater for relocs removed by
   3965  1.1  skrll 	     allocate_dynrelocs.  If you squint, the non-shared test
   3966  1.1  skrll 	     here does indeed match the one in ..check_relocs, the
   3967  1.1  skrll 	     difference being that here we test DEF_DYNAMIC as well as
   3968  1.1  skrll 	     !DEF_REGULAR.  All common syms end up with !DEF_REGULAR,
   3969  1.1  skrll 	     which is why we can't use just that test here.
   3970  1.1  skrll 	     Conversely, DEF_DYNAMIC can't be used in check_relocs as
   3971  1.1  skrll 	     there all files have not been loaded.  */
   3972  1.1  skrll 	  if ((info->shared
   3973  1.1  skrll 	       && (hh == NULL
   3974  1.1  skrll 		   || ELF_ST_VISIBILITY (hh->eh.other) == STV_DEFAULT
   3975  1.1  skrll 		   || hh->eh.root.type != bfd_link_hash_undefweak)
   3976  1.1  skrll 	       && (IS_ABSOLUTE_RELOC (r_type)
   3977  1.1  skrll 		   || !SYMBOL_CALLS_LOCAL (info, &hh->eh)))
   3978  1.1  skrll 	      || (!info->shared
   3979  1.1  skrll 		  && hh != NULL
   3980  1.1  skrll 		  && hh->eh.dynindx != -1
   3981  1.1  skrll 		  && !hh->eh.non_got_ref
   3982  1.1  skrll 		  && ((ELIMINATE_COPY_RELOCS
   3983  1.1  skrll 		       && hh->eh.def_dynamic
   3984  1.1  skrll 		       && !hh->eh.def_regular)
   3985  1.1  skrll 		      || hh->eh.root.type == bfd_link_hash_undefweak
   3986  1.1  skrll 		      || hh->eh.root.type == bfd_link_hash_undefined)))
   3987  1.1  skrll 	    {
   3988  1.1  skrll 	      Elf_Internal_Rela outrel;
   3989  1.1  skrll 	      bfd_boolean skip;
   3990  1.1  skrll 	      asection *sreloc;
   3991  1.1  skrll 	      bfd_byte *loc;
   3992  1.1  skrll 
   3993  1.1  skrll 	      /* When generating a shared object, these relocations
   3994  1.1  skrll 		 are copied into the output file to be resolved at run
   3995  1.1  skrll 		 time.  */
   3996  1.1  skrll 
   3997  1.1  skrll 	      outrel.r_addend = rela->r_addend;
   3998  1.1  skrll 	      outrel.r_offset =
   3999  1.1  skrll 		_bfd_elf_section_offset (output_bfd, info, input_section,
   4000  1.1  skrll 					 rela->r_offset);
   4001  1.1  skrll 	      skip = (outrel.r_offset == (bfd_vma) -1
   4002  1.1  skrll 		      || outrel.r_offset == (bfd_vma) -2);
   4003  1.1  skrll 	      outrel.r_offset += (input_section->output_offset
   4004  1.1  skrll 				  + input_section->output_section->vma);
   4005  1.1  skrll 
   4006  1.1  skrll 	      if (skip)
   4007  1.1  skrll 		{
   4008  1.1  skrll 		  memset (&outrel, 0, sizeof (outrel));
   4009  1.1  skrll 		}
   4010  1.1  skrll 	      else if (hh != NULL
   4011  1.1  skrll 		       && hh->eh.dynindx != -1
   4012  1.1  skrll 		       && (plabel
   4013  1.1  skrll 			   || !IS_ABSOLUTE_RELOC (r_type)
   4014  1.1  skrll 			   || !info->shared
   4015  1.1  skrll 			   || !info->symbolic
   4016  1.1  skrll 			   || !hh->eh.def_regular))
   4017  1.1  skrll 		{
   4018  1.1  skrll 		  outrel.r_info = ELF32_R_INFO (hh->eh.dynindx, r_type);
   4019  1.1  skrll 		}
   4020  1.1  skrll 	      else /* It's a local symbol, or one marked to become local.  */
   4021  1.1  skrll 		{
   4022  1.1  skrll 		  int indx = 0;
   4023  1.1  skrll 
   4024  1.1  skrll 		  /* Add the absolute offset of the symbol.  */
   4025  1.1  skrll 		  outrel.r_addend += relocation;
   4026  1.1  skrll 
   4027  1.1  skrll 		  /* Global plabels need to be processed by the
   4028  1.1  skrll 		     dynamic linker so that functions have at most one
   4029  1.1  skrll 		     fptr.  For this reason, we need to differentiate
   4030  1.1  skrll 		     between global and local plabels, which we do by
   4031  1.1  skrll 		     providing the function symbol for a global plabel
   4032  1.1  skrll 		     reloc, and no symbol for local plabels.  */
   4033  1.1  skrll 		  if (! plabel
   4034  1.1  skrll 		      && sym_sec != NULL
   4035  1.1  skrll 		      && sym_sec->output_section != NULL
   4036  1.1  skrll 		      && ! bfd_is_abs_section (sym_sec))
   4037  1.1  skrll 		    {
   4038  1.1  skrll 		      asection *osec;
   4039  1.1  skrll 
   4040  1.1  skrll 		      osec = sym_sec->output_section;
   4041  1.1  skrll 		      indx = elf_section_data (osec)->dynindx;
   4042  1.1  skrll 		      if (indx == 0)
   4043  1.1  skrll 			{
   4044  1.1  skrll 			  osec = htab->etab.text_index_section;
   4045  1.1  skrll 			  indx = elf_section_data (osec)->dynindx;
   4046  1.1  skrll 			}
   4047  1.1  skrll 		      BFD_ASSERT (indx != 0);
   4048  1.1  skrll 
   4049  1.1  skrll 		      /* We are turning this relocation into one
   4050  1.1  skrll 			 against a section symbol, so subtract out the
   4051  1.1  skrll 			 output section's address but not the offset
   4052  1.1  skrll 			 of the input section in the output section.  */
   4053  1.1  skrll 		      outrel.r_addend -= osec->vma;
   4054  1.1  skrll 		    }
   4055  1.1  skrll 
   4056  1.1  skrll 		  outrel.r_info = ELF32_R_INFO (indx, r_type);
   4057  1.1  skrll 		}
   4058  1.1  skrll 	      sreloc = elf_section_data (input_section)->sreloc;
   4059  1.1  skrll 	      if (sreloc == NULL)
   4060  1.1  skrll 		abort ();
   4061  1.1  skrll 
   4062  1.1  skrll 	      loc = sreloc->contents;
   4063  1.1  skrll 	      loc += sreloc->reloc_count++ * sizeof (Elf32_External_Rela);
   4064  1.1  skrll 	      bfd_elf32_swap_reloca_out (output_bfd, &outrel, loc);
   4065  1.1  skrll 	    }
   4066  1.1  skrll 	  break;
   4067  1.1  skrll 
   4068  1.1  skrll 	case R_PARISC_TLS_LDM21L:
   4069  1.1  skrll 	case R_PARISC_TLS_LDM14R:
   4070  1.1  skrll 	  {
   4071  1.1  skrll 	    bfd_vma off;
   4072  1.1  skrll 
   4073  1.1  skrll 	    off = htab->tls_ldm_got.offset;
   4074  1.1  skrll 	    if (off & 1)
   4075  1.1  skrll 	      off &= ~1;
   4076  1.1  skrll 	    else
   4077  1.1  skrll 	      {
   4078  1.1  skrll 		Elf_Internal_Rela outrel;
   4079  1.1  skrll 		bfd_byte *loc;
   4080  1.1  skrll 
   4081  1.1  skrll 		outrel.r_offset = (off
   4082  1.1  skrll 				   + htab->sgot->output_section->vma
   4083  1.1  skrll 				   + htab->sgot->output_offset);
   4084  1.1  skrll 		outrel.r_addend = 0;
   4085  1.1  skrll 		outrel.r_info = ELF32_R_INFO (0, R_PARISC_TLS_DTPMOD32);
   4086  1.1  skrll 		loc = htab->srelgot->contents;
   4087  1.1  skrll 		loc += htab->srelgot->reloc_count++ * sizeof (Elf32_External_Rela);
   4088  1.1  skrll 
   4089  1.1  skrll 		bfd_elf32_swap_reloca_out (output_bfd, &outrel, loc);
   4090  1.1  skrll 		htab->tls_ldm_got.offset |= 1;
   4091  1.1  skrll 	      }
   4092  1.1  skrll 
   4093  1.1  skrll 	    /* Add the base of the GOT to the relocation value.  */
   4094  1.1  skrll 	    relocation = (off
   4095  1.1  skrll 			  + htab->sgot->output_offset
   4096  1.1  skrll 			  + htab->sgot->output_section->vma);
   4097  1.1  skrll 
   4098  1.1  skrll 	    break;
   4099  1.1  skrll 	  }
   4100  1.1  skrll 
   4101  1.1  skrll 	case R_PARISC_TLS_LDO21L:
   4102  1.1  skrll 	case R_PARISC_TLS_LDO14R:
   4103  1.1  skrll 	  relocation -= dtpoff_base (info);
   4104  1.1  skrll 	  break;
   4105  1.1  skrll 
   4106  1.1  skrll 	case R_PARISC_TLS_GD21L:
   4107  1.1  skrll 	case R_PARISC_TLS_GD14R:
   4108  1.1  skrll 	case R_PARISC_TLS_IE21L:
   4109  1.1  skrll 	case R_PARISC_TLS_IE14R:
   4110  1.1  skrll 	  {
   4111  1.1  skrll 	    bfd_vma off;
   4112  1.1  skrll 	    int indx;
   4113  1.1  skrll 	    char tls_type;
   4114  1.1  skrll 
   4115  1.1  skrll 	    indx = 0;
   4116  1.1  skrll 	    if (hh != NULL)
   4117  1.1  skrll 	      {
   4118  1.1  skrll 	        bfd_boolean dyn;
   4119  1.1  skrll 	        dyn = htab->etab.dynamic_sections_created;
   4120  1.1  skrll 
   4121  1.1  skrll 		if (WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn, info->shared, &hh->eh)
   4122  1.1  skrll 		    && (!info->shared
   4123  1.1  skrll 			|| !SYMBOL_REFERENCES_LOCAL (info, &hh->eh)))
   4124  1.1  skrll 		  {
   4125  1.1  skrll 		    indx = hh->eh.dynindx;
   4126  1.1  skrll 		  }
   4127  1.1  skrll 		off = hh->eh.got.offset;
   4128  1.1  skrll 		tls_type = hh->tls_type;
   4129  1.1  skrll 	      }
   4130  1.1  skrll 	    else
   4131  1.1  skrll 	      {
   4132  1.1  skrll 		off = local_got_offsets[r_symndx];
   4133  1.1  skrll 		tls_type = hppa_elf_local_got_tls_type (input_bfd)[r_symndx];
   4134  1.1  skrll 	      }
   4135  1.1  skrll 
   4136  1.1  skrll 	    if (tls_type == GOT_UNKNOWN)
   4137  1.1  skrll 	      abort ();
   4138  1.1  skrll 
   4139  1.1  skrll 	    if ((off & 1) != 0)
   4140  1.1  skrll 	      off &= ~1;
   4141  1.1  skrll 	    else
   4142  1.1  skrll 	      {
   4143  1.1  skrll 		bfd_boolean need_relocs = FALSE;
   4144  1.1  skrll 		Elf_Internal_Rela outrel;
   4145  1.1  skrll 		bfd_byte *loc = NULL;
   4146  1.1  skrll 		int cur_off = off;
   4147  1.1  skrll 
   4148  1.1  skrll 	        /* The GOT entries have not been initialized yet.  Do it
   4149  1.1  skrll 	           now, and emit any relocations.  If both an IE GOT and a
   4150  1.1  skrll 	           GD GOT are necessary, we emit the GD first.  */
   4151  1.1  skrll 
   4152  1.1  skrll 		if ((info->shared || indx != 0)
   4153  1.1  skrll 		    && (hh == NULL
   4154  1.1  skrll 			|| ELF_ST_VISIBILITY (hh->eh.other) == STV_DEFAULT
   4155  1.1  skrll 			|| hh->eh.root.type != bfd_link_hash_undefweak))
   4156  1.1  skrll 		  {
   4157  1.1  skrll 		    need_relocs = TRUE;
   4158  1.1  skrll 		    loc = htab->srelgot->contents;
   4159  1.1  skrll 		    /* FIXME (CAO): Should this be reloc_count++ ? */
   4160  1.1  skrll 		    loc += htab->srelgot->reloc_count * sizeof (Elf32_External_Rela);
   4161  1.1  skrll 		  }
   4162  1.1  skrll 
   4163  1.1  skrll 		if (tls_type & GOT_TLS_GD)
   4164  1.1  skrll 		  {
   4165  1.1  skrll 		    if (need_relocs)
   4166  1.1  skrll 		      {
   4167  1.1  skrll 			outrel.r_offset = (cur_off
   4168  1.1  skrll 					   + htab->sgot->output_section->vma
   4169  1.1  skrll 					   + htab->sgot->output_offset);
   4170  1.1  skrll 			outrel.r_info = ELF32_R_INFO (indx,R_PARISC_TLS_DTPMOD32);
   4171  1.1  skrll 			outrel.r_addend = 0;
   4172  1.1  skrll 			bfd_put_32 (output_bfd, 0, htab->sgot->contents + cur_off);
   4173  1.1  skrll 			bfd_elf32_swap_reloca_out (output_bfd, &outrel, loc);
   4174  1.1  skrll 			htab->srelgot->reloc_count++;
   4175  1.1  skrll 			loc += sizeof (Elf32_External_Rela);
   4176  1.1  skrll 
   4177  1.1  skrll 			if (indx == 0)
   4178  1.1  skrll 			  bfd_put_32 (output_bfd, relocation - dtpoff_base (info),
   4179  1.1  skrll 				      htab->sgot->contents + cur_off + 4);
   4180  1.1  skrll 			else
   4181  1.1  skrll 			  {
   4182  1.1  skrll 			    bfd_put_32 (output_bfd, 0,
   4183  1.1  skrll 					htab->sgot->contents + cur_off + 4);
   4184  1.1  skrll 			    outrel.r_info = ELF32_R_INFO (indx, R_PARISC_TLS_DTPOFF32);
   4185  1.1  skrll 			    outrel.r_offset += 4;
   4186  1.1  skrll 			    bfd_elf32_swap_reloca_out (output_bfd, &outrel,loc);
   4187  1.1  skrll 			    htab->srelgot->reloc_count++;
   4188  1.1  skrll 			    loc += sizeof (Elf32_External_Rela);
   4189  1.1  skrll 			  }
   4190  1.1  skrll 		      }
   4191  1.1  skrll 		    else
   4192  1.1  skrll 		      {
   4193  1.1  skrll 		        /* If we are not emitting relocations for a
   4194  1.1  skrll 		           general dynamic reference, then we must be in a
   4195  1.1  skrll 		           static link or an executable link with the
   4196  1.1  skrll 		           symbol binding locally.  Mark it as belonging
   4197  1.1  skrll 		           to module 1, the executable.  */
   4198  1.1  skrll 		        bfd_put_32 (output_bfd, 1,
   4199  1.1  skrll 				    htab->sgot->contents + cur_off);
   4200  1.1  skrll 		        bfd_put_32 (output_bfd, relocation - dtpoff_base (info),
   4201  1.1  skrll 				    htab->sgot->contents + cur_off + 4);
   4202  1.1  skrll 		      }
   4203  1.1  skrll 
   4204  1.1  skrll 
   4205  1.1  skrll 		    cur_off += 8;
   4206  1.1  skrll 		  }
   4207  1.1  skrll 
   4208  1.1  skrll 		if (tls_type & GOT_TLS_IE)
   4209  1.1  skrll 		  {
   4210  1.1  skrll 		    if (need_relocs)
   4211  1.1  skrll 		      {
   4212  1.1  skrll 			outrel.r_offset = (cur_off
   4213  1.1  skrll 					   + htab->sgot->output_section->vma
   4214  1.1  skrll 					   + htab->sgot->output_offset);
   4215  1.1  skrll 			outrel.r_info = ELF32_R_INFO (indx, R_PARISC_TLS_TPREL32);
   4216  1.1  skrll 
   4217  1.1  skrll 			if (indx == 0)
   4218  1.1  skrll 			  outrel.r_addend = relocation - dtpoff_base (info);
   4219  1.1  skrll 			else
   4220  1.1  skrll 			  outrel.r_addend = 0;
   4221  1.1  skrll 
   4222  1.1  skrll 			bfd_elf32_swap_reloca_out (output_bfd, &outrel, loc);
   4223  1.1  skrll 			htab->srelgot->reloc_count++;
   4224  1.1  skrll 			loc += sizeof (Elf32_External_Rela);
   4225  1.1  skrll 		      }
   4226  1.1  skrll 		    else
   4227  1.1  skrll 		      bfd_put_32 (output_bfd, tpoff (info, relocation),
   4228  1.1  skrll 				  htab->sgot->contents + cur_off);
   4229  1.1  skrll 
   4230  1.1  skrll 		    cur_off += 4;
   4231  1.1  skrll 		  }
   4232  1.1  skrll 
   4233  1.1  skrll 		if (hh != NULL)
   4234  1.1  skrll 		  hh->eh.got.offset |= 1;
   4235  1.1  skrll 		else
   4236  1.1  skrll 		  local_got_offsets[r_symndx] |= 1;
   4237  1.1  skrll 	      }
   4238  1.1  skrll 
   4239  1.1  skrll 	    if ((tls_type & GOT_TLS_GD)
   4240  1.1  skrll 	  	&& r_type != R_PARISC_TLS_GD21L
   4241  1.1  skrll 	  	&& r_type != R_PARISC_TLS_GD14R)
   4242  1.1  skrll 	      off += 2 * GOT_ENTRY_SIZE;
   4243  1.1  skrll 
   4244  1.1  skrll 	    /* Add the base of the GOT to the relocation value.  */
   4245  1.1  skrll 	    relocation = (off
   4246  1.1  skrll 			  + htab->sgot->output_offset
   4247  1.1  skrll 			  + htab->sgot->output_section->vma);
   4248  1.1  skrll 
   4249  1.1  skrll 	    break;
   4250  1.1  skrll 	  }
   4251  1.1  skrll 
   4252  1.1  skrll 	case R_PARISC_TLS_LE21L:
   4253  1.1  skrll 	case R_PARISC_TLS_LE14R:
   4254  1.1  skrll 	  {
   4255  1.1  skrll 	    relocation = tpoff (info, relocation);
   4256  1.1  skrll 	    break;
   4257  1.1  skrll 	  }
   4258  1.1  skrll 	  break;
   4259  1.1  skrll 
   4260  1.1  skrll 	default:
   4261  1.1  skrll 	  break;
   4262  1.1  skrll 	}
   4263  1.1  skrll 
   4264  1.1  skrll       rstatus = final_link_relocate (input_section, contents, rela, relocation,
   4265  1.1  skrll 			       htab, sym_sec, hh, info);
   4266  1.1  skrll 
   4267  1.1  skrll       if (rstatus == bfd_reloc_ok)
   4268  1.1  skrll 	continue;
   4269  1.1  skrll 
   4270  1.1  skrll       if (hh != NULL)
   4271  1.1  skrll 	sym_name = hh_name (hh);
   4272  1.1  skrll       else
   4273  1.1  skrll 	{
   4274  1.1  skrll 	  sym_name = bfd_elf_string_from_elf_section (input_bfd,
   4275  1.1  skrll 						      symtab_hdr->sh_link,
   4276  1.1  skrll 						      sym->st_name);
   4277  1.1  skrll 	  if (sym_name == NULL)
   4278  1.1  skrll 	    return FALSE;
   4279  1.1  skrll 	  if (*sym_name == '\0')
   4280  1.1  skrll 	    sym_name = bfd_section_name (input_bfd, sym_sec);
   4281  1.1  skrll 	}
   4282  1.1  skrll 
   4283  1.1  skrll       howto = elf_hppa_howto_table + r_type;
   4284  1.1  skrll 
   4285  1.1  skrll       if (rstatus == bfd_reloc_undefined || rstatus == bfd_reloc_notsupported)
   4286  1.1  skrll 	{
   4287  1.1  skrll 	  if (rstatus == bfd_reloc_notsupported || !warned_undef)
   4288  1.1  skrll 	    {
   4289  1.1  skrll 	      (*_bfd_error_handler)
   4290  1.1  skrll 		(_("%B(%A+0x%lx): cannot handle %s for %s"),
   4291  1.1  skrll 		 input_bfd,
   4292  1.1  skrll 		 input_section,
   4293  1.1  skrll 		 (long) rela->r_offset,
   4294  1.1  skrll 		 howto->name,
   4295  1.1  skrll 		 sym_name);
   4296  1.1  skrll 	      bfd_set_error (bfd_error_bad_value);
   4297  1.1  skrll 	      return FALSE;
   4298  1.1  skrll 	    }
   4299  1.1  skrll 	}
   4300  1.1  skrll       else
   4301  1.1  skrll 	{
   4302  1.1  skrll 	  if (!((*info->callbacks->reloc_overflow)
   4303  1.1  skrll 		(info, (hh ? &hh->eh.root : NULL), sym_name, howto->name,
   4304  1.1  skrll 		 (bfd_vma) 0, input_bfd, input_section, rela->r_offset)))
   4305  1.1  skrll 	    return FALSE;
   4306  1.1  skrll 	}
   4307  1.1  skrll     }
   4308  1.1  skrll 
   4309  1.1  skrll   return TRUE;
   4310  1.1  skrll }
   4311  1.1  skrll 
   4312  1.1  skrll /* Finish up dynamic symbol handling.  We set the contents of various
   4313  1.1  skrll    dynamic sections here.  */
   4314  1.1  skrll 
   4315  1.1  skrll static bfd_boolean
   4316  1.1  skrll elf32_hppa_finish_dynamic_symbol (bfd *output_bfd,
   4317  1.1  skrll 				  struct bfd_link_info *info,
   4318  1.1  skrll 				  struct elf_link_hash_entry *eh,
   4319  1.1  skrll 				  Elf_Internal_Sym *sym)
   4320  1.1  skrll {
   4321  1.1  skrll   struct elf32_hppa_link_hash_table *htab;
   4322  1.1  skrll   Elf_Internal_Rela rela;
   4323  1.1  skrll   bfd_byte *loc;
   4324  1.1  skrll 
   4325  1.1  skrll   htab = hppa_link_hash_table (info);
   4326  1.1  skrll 
   4327  1.1  skrll   if (eh->plt.offset != (bfd_vma) -1)
   4328  1.1  skrll     {
   4329  1.1  skrll       bfd_vma value;
   4330  1.1  skrll 
   4331  1.1  skrll       if (eh->plt.offset & 1)
   4332  1.1  skrll 	abort ();
   4333  1.1  skrll 
   4334  1.1  skrll       /* This symbol has an entry in the procedure linkage table.  Set
   4335  1.1  skrll 	 it up.
   4336  1.1  skrll 
   4337  1.1  skrll 	 The format of a plt entry is
   4338  1.1  skrll 	 <funcaddr>
   4339  1.1  skrll 	 <__gp>
   4340  1.1  skrll       */
   4341  1.1  skrll       value = 0;
   4342  1.1  skrll       if (eh->root.type == bfd_link_hash_defined
   4343  1.1  skrll 	  || eh->root.type == bfd_link_hash_defweak)
   4344  1.1  skrll 	{
   4345  1.1  skrll 	  value = eh->root.u.def.value;
   4346  1.1  skrll 	  if (eh->root.u.def.section->output_section != NULL)
   4347  1.1  skrll 	    value += (eh->root.u.def.section->output_offset
   4348  1.1  skrll 		      + eh->root.u.def.section->output_section->vma);
   4349  1.1  skrll 	}
   4350  1.1  skrll 
   4351  1.1  skrll       /* Create a dynamic IPLT relocation for this entry.  */
   4352  1.1  skrll       rela.r_offset = (eh->plt.offset
   4353  1.1  skrll 		      + htab->splt->output_offset
   4354  1.1  skrll 		      + htab->splt->output_section->vma);
   4355  1.1  skrll       if (eh->dynindx != -1)
   4356  1.1  skrll 	{
   4357  1.1  skrll 	  rela.r_info = ELF32_R_INFO (eh->dynindx, R_PARISC_IPLT);
   4358  1.1  skrll 	  rela.r_addend = 0;
   4359  1.1  skrll 	}
   4360  1.1  skrll       else
   4361  1.1  skrll 	{
   4362  1.1  skrll 	  /* This symbol has been marked to become local, and is
   4363  1.1  skrll 	     used by a plabel so must be kept in the .plt.  */
   4364  1.1  skrll 	  rela.r_info = ELF32_R_INFO (0, R_PARISC_IPLT);
   4365  1.1  skrll 	  rela.r_addend = value;
   4366  1.1  skrll 	}
   4367  1.1  skrll 
   4368  1.1  skrll       loc = htab->srelplt->contents;
   4369  1.1  skrll       loc += htab->srelplt->reloc_count++ * sizeof (Elf32_External_Rela);
   4370  1.1  skrll       bfd_elf32_swap_reloca_out (htab->splt->output_section->owner, &rela, loc);
   4371  1.1  skrll 
   4372  1.1  skrll       if (!eh->def_regular)
   4373  1.1  skrll 	{
   4374  1.1  skrll 	  /* Mark the symbol as undefined, rather than as defined in
   4375  1.1  skrll 	     the .plt section.  Leave the value alone.  */
   4376  1.1  skrll 	  sym->st_shndx = SHN_UNDEF;
   4377  1.1  skrll 	}
   4378  1.1  skrll     }
   4379  1.1  skrll 
   4380  1.1  skrll   if (eh->got.offset != (bfd_vma) -1
   4381  1.1  skrll       && (hppa_elf_hash_entry (eh)->tls_type & GOT_TLS_GD) == 0
   4382  1.1  skrll       && (hppa_elf_hash_entry (eh)->tls_type & GOT_TLS_IE) == 0)
   4383  1.1  skrll     {
   4384  1.1  skrll       /* This symbol has an entry in the global offset table.  Set it
   4385  1.1  skrll 	 up.  */
   4386  1.1  skrll 
   4387  1.1  skrll       rela.r_offset = ((eh->got.offset &~ (bfd_vma) 1)
   4388  1.1  skrll 		      + htab->sgot->output_offset
   4389  1.1  skrll 		      + htab->sgot->output_section->vma);
   4390  1.1  skrll 
   4391  1.1  skrll       /* If this is a -Bsymbolic link and the symbol is defined
   4392  1.1  skrll 	 locally or was forced to be local because of a version file,
   4393  1.1  skrll 	 we just want to emit a RELATIVE reloc.  The entry in the
   4394  1.1  skrll 	 global offset table will already have been initialized in the
   4395  1.1  skrll 	 relocate_section function.  */
   4396  1.1  skrll       if (info->shared
   4397  1.1  skrll 	  && (info->symbolic || eh->dynindx == -1)
   4398  1.1  skrll 	  && eh->def_regular)
   4399  1.1  skrll 	{
   4400  1.1  skrll 	  rela.r_info = ELF32_R_INFO (0, R_PARISC_DIR32);
   4401  1.1  skrll 	  rela.r_addend = (eh->root.u.def.value
   4402  1.1  skrll 			  + eh->root.u.def.section->output_offset
   4403  1.1  skrll 			  + eh->root.u.def.section->output_section->vma);
   4404  1.1  skrll 	}
   4405  1.1  skrll       else
   4406  1.1  skrll 	{
   4407  1.1  skrll 	  if ((eh->got.offset & 1) != 0)
   4408  1.1  skrll 	    abort ();
   4409  1.1  skrll 
   4410  1.1  skrll 	  bfd_put_32 (output_bfd, 0, htab->sgot->contents + (eh->got.offset & ~1));
   4411  1.1  skrll 	  rela.r_info = ELF32_R_INFO (eh->dynindx, R_PARISC_DIR32);
   4412  1.1  skrll 	  rela.r_addend = 0;
   4413  1.1  skrll 	}
   4414  1.1  skrll 
   4415  1.1  skrll       loc = htab->srelgot->contents;
   4416  1.1  skrll       loc += htab->srelgot->reloc_count++ * sizeof (Elf32_External_Rela);
   4417  1.1  skrll       bfd_elf32_swap_reloca_out (output_bfd, &rela, loc);
   4418  1.1  skrll     }
   4419  1.1  skrll 
   4420  1.1  skrll   if (eh->needs_copy)
   4421  1.1  skrll     {
   4422  1.1  skrll       asection *sec;
   4423  1.1  skrll 
   4424  1.1  skrll       /* This symbol needs a copy reloc.  Set it up.  */
   4425  1.1  skrll 
   4426  1.1  skrll       if (! (eh->dynindx != -1
   4427  1.1  skrll 	     && (eh->root.type == bfd_link_hash_defined
   4428  1.1  skrll 		 || eh->root.type == bfd_link_hash_defweak)))
   4429  1.1  skrll 	abort ();
   4430  1.1  skrll 
   4431  1.1  skrll       sec = htab->srelbss;
   4432  1.1  skrll 
   4433  1.1  skrll       rela.r_offset = (eh->root.u.def.value
   4434  1.1  skrll 		      + eh->root.u.def.section->output_offset
   4435  1.1  skrll 		      + eh->root.u.def.section->output_section->vma);
   4436  1.1  skrll       rela.r_addend = 0;
   4437  1.1  skrll       rela.r_info = ELF32_R_INFO (eh->dynindx, R_PARISC_COPY);
   4438  1.1  skrll       loc = sec->contents + sec->reloc_count++ * sizeof (Elf32_External_Rela);
   4439  1.1  skrll       bfd_elf32_swap_reloca_out (output_bfd, &rela, loc);
   4440  1.1  skrll     }
   4441  1.1  skrll 
   4442  1.1  skrll   /* Mark _DYNAMIC and _GLOBAL_OFFSET_TABLE_ as absolute.  */
   4443  1.1  skrll   if (eh_name (eh)[0] == '_'
   4444  1.1  skrll       && (strcmp (eh_name (eh), "_DYNAMIC") == 0
   4445  1.1  skrll 	  || eh == htab->etab.hgot))
   4446  1.1  skrll     {
   4447  1.1  skrll       sym->st_shndx = SHN_ABS;
   4448  1.1  skrll     }
   4449  1.1  skrll 
   4450  1.1  skrll   return TRUE;
   4451  1.1  skrll }
   4452  1.1  skrll 
   4453  1.1  skrll /* Used to decide how to sort relocs in an optimal manner for the
   4454  1.1  skrll    dynamic linker, before writing them out.  */
   4455  1.1  skrll 
   4456  1.1  skrll static enum elf_reloc_type_class
   4457  1.1  skrll elf32_hppa_reloc_type_class (const Elf_Internal_Rela *rela)
   4458  1.1  skrll {
   4459  1.1  skrll   /* Handle TLS relocs first; we don't want them to be marked
   4460  1.1  skrll      relative by the "if (ELF32_R_SYM (rela->r_info) == 0)"
   4461  1.1  skrll      check below.  */
   4462  1.1  skrll   switch ((int) ELF32_R_TYPE (rela->r_info))
   4463  1.1  skrll     {
   4464  1.1  skrll       case R_PARISC_TLS_DTPMOD32:
   4465  1.1  skrll       case R_PARISC_TLS_DTPOFF32:
   4466  1.1  skrll       case R_PARISC_TLS_TPREL32:
   4467  1.1  skrll         return reloc_class_normal;
   4468  1.1  skrll     }
   4469  1.1  skrll 
   4470  1.1  skrll   if (ELF32_R_SYM (rela->r_info) == 0)
   4471  1.1  skrll     return reloc_class_relative;
   4472  1.1  skrll 
   4473  1.1  skrll   switch ((int) ELF32_R_TYPE (rela->r_info))
   4474  1.1  skrll     {
   4475  1.1  skrll     case R_PARISC_IPLT:
   4476  1.1  skrll       return reloc_class_plt;
   4477  1.1  skrll     case R_PARISC_COPY:
   4478  1.1  skrll       return reloc_class_copy;
   4479  1.1  skrll     default:
   4480  1.1  skrll       return reloc_class_normal;
   4481  1.1  skrll     }
   4482  1.1  skrll }
   4483  1.1  skrll 
   4484  1.1  skrll /* Finish up the dynamic sections.  */
   4485  1.1  skrll 
   4486  1.1  skrll static bfd_boolean
   4487  1.1  skrll elf32_hppa_finish_dynamic_sections (bfd *output_bfd,
   4488  1.1  skrll 				    struct bfd_link_info *info)
   4489  1.1  skrll {
   4490  1.1  skrll   bfd *dynobj;
   4491  1.1  skrll   struct elf32_hppa_link_hash_table *htab;
   4492  1.1  skrll   asection *sdyn;
   4493  1.1  skrll 
   4494  1.1  skrll   htab = hppa_link_hash_table (info);
   4495  1.1  skrll   dynobj = htab->etab.dynobj;
   4496  1.1  skrll 
   4497  1.1  skrll   sdyn = bfd_get_section_by_name (dynobj, ".dynamic");
   4498  1.1  skrll 
   4499  1.1  skrll   if (htab->etab.dynamic_sections_created)
   4500  1.1  skrll     {
   4501  1.1  skrll       Elf32_External_Dyn *dyncon, *dynconend;
   4502  1.1  skrll 
   4503  1.1  skrll       if (sdyn == NULL)
   4504  1.1  skrll 	abort ();
   4505  1.1  skrll 
   4506  1.1  skrll       dyncon = (Elf32_External_Dyn *) sdyn->contents;
   4507  1.1  skrll       dynconend = (Elf32_External_Dyn *) (sdyn->contents + sdyn->size);
   4508  1.1  skrll       for (; dyncon < dynconend; dyncon++)
   4509  1.1  skrll 	{
   4510  1.1  skrll 	  Elf_Internal_Dyn dyn;
   4511  1.1  skrll 	  asection *s;
   4512  1.1  skrll 
   4513  1.1  skrll 	  bfd_elf32_swap_dyn_in (dynobj, dyncon, &dyn);
   4514  1.1  skrll 
   4515  1.1  skrll 	  switch (dyn.d_tag)
   4516  1.1  skrll 	    {
   4517  1.1  skrll 	    default:
   4518  1.1  skrll 	      continue;
   4519  1.1  skrll 
   4520  1.1  skrll 	    case DT_PLTGOT:
   4521  1.1  skrll 	      /* Use PLTGOT to set the GOT register.  */
   4522  1.1  skrll 	      dyn.d_un.d_ptr = elf_gp (output_bfd);
   4523  1.1  skrll 	      break;
   4524  1.1  skrll 
   4525  1.1  skrll 	    case DT_JMPREL:
   4526  1.1  skrll 	      s = htab->srelplt;
   4527  1.1  skrll 	      dyn.d_un.d_ptr = s->output_section->vma + s->output_offset;
   4528  1.1  skrll 	      break;
   4529  1.1  skrll 
   4530  1.1  skrll 	    case DT_PLTRELSZ:
   4531  1.1  skrll 	      s = htab->srelplt;
   4532  1.1  skrll 	      dyn.d_un.d_val = s->size;
   4533  1.1  skrll 	      break;
   4534  1.1  skrll 
   4535  1.1  skrll 	    case DT_RELASZ:
   4536  1.1  skrll 	      /* Don't count procedure linkage table relocs in the
   4537  1.1  skrll 		 overall reloc count.  */
   4538  1.1  skrll 	      s = htab->srelplt;
   4539  1.1  skrll 	      if (s == NULL)
   4540  1.1  skrll 		continue;
   4541  1.1  skrll 	      dyn.d_un.d_val -= s->size;
   4542  1.1  skrll 	      break;
   4543  1.1  skrll 
   4544  1.1  skrll 	    case DT_RELA:
   4545  1.1  skrll 	      /* We may not be using the standard ELF linker script.
   4546  1.1  skrll 		 If .rela.plt is the first .rela section, we adjust
   4547  1.1  skrll 		 DT_RELA to not include it.  */
   4548  1.1  skrll 	      s = htab->srelplt;
   4549  1.1  skrll 	      if (s == NULL)
   4550  1.1  skrll 		continue;
   4551  1.1  skrll 	      if (dyn.d_un.d_ptr != s->output_section->vma + s->output_offset)
   4552  1.1  skrll 		continue;
   4553  1.1  skrll 	      dyn.d_un.d_ptr += s->size;
   4554  1.1  skrll 	      break;
   4555  1.1  skrll 	    }
   4556  1.1  skrll 
   4557  1.1  skrll 	  bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon);
   4558  1.1  skrll 	}
   4559  1.1  skrll     }
   4560  1.1  skrll 
   4561  1.1  skrll   if (htab->sgot != NULL && htab->sgot->size != 0)
   4562  1.1  skrll     {
   4563  1.1  skrll       /* Fill in the first entry in the global offset table.
   4564  1.1  skrll 	 We use it to point to our dynamic section, if we have one.  */
   4565  1.1  skrll       bfd_put_32 (output_bfd,
   4566  1.1  skrll 		  sdyn ? sdyn->output_section->vma + sdyn->output_offset : 0,
   4567  1.1  skrll 		  htab->sgot->contents);
   4568  1.1  skrll 
   4569  1.1  skrll       /* The second entry is reserved for use by the dynamic linker.  */
   4570  1.1  skrll       memset (htab->sgot->contents + GOT_ENTRY_SIZE, 0, GOT_ENTRY_SIZE);
   4571  1.1  skrll 
   4572  1.1  skrll       /* Set .got entry size.  */
   4573  1.1  skrll       elf_section_data (htab->sgot->output_section)
   4574  1.1  skrll 	->this_hdr.sh_entsize = GOT_ENTRY_SIZE;
   4575  1.1  skrll     }
   4576  1.1  skrll 
   4577  1.1  skrll   if (htab->splt != NULL && htab->splt->size != 0)
   4578  1.1  skrll     {
   4579  1.1  skrll       /* Set plt entry size.  */
   4580  1.1  skrll       elf_section_data (htab->splt->output_section)
   4581  1.1  skrll 	->this_hdr.sh_entsize = PLT_ENTRY_SIZE;
   4582  1.1  skrll 
   4583  1.1  skrll       if (htab->need_plt_stub)
   4584  1.1  skrll 	{
   4585  1.1  skrll 	  /* Set up the .plt stub.  */
   4586  1.1  skrll 	  memcpy (htab->splt->contents
   4587  1.1  skrll 		  + htab->splt->size - sizeof (plt_stub),
   4588  1.1  skrll 		  plt_stub, sizeof (plt_stub));
   4589  1.1  skrll 
   4590  1.1  skrll 	  if ((htab->splt->output_offset
   4591  1.1  skrll 	       + htab->splt->output_section->vma
   4592  1.1  skrll 	       + htab->splt->size)
   4593  1.1  skrll 	      != (htab->sgot->output_offset
   4594  1.1  skrll 		  + htab->sgot->output_section->vma))
   4595  1.1  skrll 	    {
   4596  1.1  skrll 	      (*_bfd_error_handler)
   4597  1.1  skrll 		(_(".got section not immediately after .plt section"));
   4598  1.1  skrll 	      return FALSE;
   4599  1.1  skrll 	    }
   4600  1.1  skrll 	}
   4601  1.1  skrll     }
   4602  1.1  skrll 
   4603  1.1  skrll   return TRUE;
   4604  1.1  skrll }
   4605  1.1  skrll 
   4606  1.1  skrll /* Called when writing out an object file to decide the type of a
   4607  1.1  skrll    symbol.  */
   4608  1.1  skrll static int
   4609  1.1  skrll elf32_hppa_elf_get_symbol_type (Elf_Internal_Sym *elf_sym, int type)
   4610  1.1  skrll {
   4611  1.1  skrll   if (ELF_ST_TYPE (elf_sym->st_info) == STT_PARISC_MILLI)
   4612  1.1  skrll     return STT_PARISC_MILLI;
   4613  1.1  skrll   else
   4614  1.1  skrll     return type;
   4615  1.1  skrll }
   4616  1.1  skrll 
   4617  1.1  skrll /* Misc BFD support code.  */
   4618  1.1  skrll #define bfd_elf32_bfd_is_local_label_name    elf_hppa_is_local_label_name
   4619  1.1  skrll #define bfd_elf32_bfd_reloc_type_lookup	     elf_hppa_reloc_type_lookup
   4620  1.1  skrll #define bfd_elf32_bfd_reloc_name_lookup      elf_hppa_reloc_name_lookup
   4621  1.1  skrll #define elf_info_to_howto		     elf_hppa_info_to_howto
   4622  1.1  skrll #define elf_info_to_howto_rel		     elf_hppa_info_to_howto_rel
   4623  1.1  skrll 
   4624  1.1  skrll /* Stuff for the BFD linker.  */
   4625  1.1  skrll #define bfd_elf32_mkobject		     elf32_hppa_mkobject
   4626  1.1  skrll #define bfd_elf32_bfd_final_link	     elf32_hppa_final_link
   4627  1.1  skrll #define bfd_elf32_bfd_link_hash_table_create elf32_hppa_link_hash_table_create
   4628  1.1  skrll #define bfd_elf32_bfd_link_hash_table_free   elf32_hppa_link_hash_table_free
   4629  1.1  skrll #define elf_backend_adjust_dynamic_symbol    elf32_hppa_adjust_dynamic_symbol
   4630  1.1  skrll #define elf_backend_copy_indirect_symbol     elf32_hppa_copy_indirect_symbol
   4631  1.1  skrll #define elf_backend_check_relocs	     elf32_hppa_check_relocs
   4632  1.1  skrll #define elf_backend_create_dynamic_sections  elf32_hppa_create_dynamic_sections
   4633  1.1  skrll #define elf_backend_fake_sections	     elf_hppa_fake_sections
   4634  1.1  skrll #define elf_backend_relocate_section	     elf32_hppa_relocate_section
   4635  1.1  skrll #define elf_backend_hide_symbol		     elf32_hppa_hide_symbol
   4636  1.1  skrll #define elf_backend_finish_dynamic_symbol    elf32_hppa_finish_dynamic_symbol
   4637  1.1  skrll #define elf_backend_finish_dynamic_sections  elf32_hppa_finish_dynamic_sections
   4638  1.1  skrll #define elf_backend_size_dynamic_sections    elf32_hppa_size_dynamic_sections
   4639  1.1  skrll #define elf_backend_init_index_section	     _bfd_elf_init_1_index_section
   4640  1.1  skrll #define elf_backend_gc_mark_hook	     elf32_hppa_gc_mark_hook
   4641  1.1  skrll #define elf_backend_gc_sweep_hook	     elf32_hppa_gc_sweep_hook
   4642  1.1  skrll #define elf_backend_grok_prstatus	     elf32_hppa_grok_prstatus
   4643  1.1  skrll #define elf_backend_grok_psinfo		     elf32_hppa_grok_psinfo
   4644  1.1  skrll #define elf_backend_object_p		     elf32_hppa_object_p
   4645  1.1  skrll #define elf_backend_final_write_processing   elf_hppa_final_write_processing
   4646  1.1  skrll #define elf_backend_post_process_headers     _bfd_elf_set_osabi
   4647  1.1  skrll #define elf_backend_get_symbol_type	     elf32_hppa_elf_get_symbol_type
   4648  1.1  skrll #define elf_backend_reloc_type_class	     elf32_hppa_reloc_type_class
   4649  1.1  skrll #define elf_backend_action_discarded	     elf_hppa_action_discarded
   4650  1.1  skrll 
   4651  1.1  skrll #define elf_backend_can_gc_sections	     1
   4652  1.1  skrll #define elf_backend_can_refcount	     1
   4653  1.1  skrll #define elf_backend_plt_alignment	     2
   4654  1.1  skrll #define elf_backend_want_got_plt	     0
   4655  1.1  skrll #define elf_backend_plt_readonly	     0
   4656  1.1  skrll #define elf_backend_want_plt_sym	     0
   4657  1.1  skrll #define elf_backend_got_header_size	     8
   4658  1.1  skrll #define elf_backend_rela_normal		     1
   4659  1.1  skrll 
   4660  1.1  skrll #define TARGET_BIG_SYM		bfd_elf32_hppa_vec
   4661  1.1  skrll #define TARGET_BIG_NAME		"elf32-hppa"
   4662  1.1  skrll #define ELF_ARCH		bfd_arch_hppa
   4663  1.1  skrll #define ELF_MACHINE_CODE	EM_PARISC
   4664  1.1  skrll #define ELF_MAXPAGESIZE		0x1000
   4665  1.1  skrll #define ELF_OSABI		ELFOSABI_HPUX
   4666  1.1  skrll #define elf32_bed		elf32_hppa_hpux_bed
   4667  1.1  skrll 
   4668  1.1  skrll #include "elf32-target.h"
   4669  1.1  skrll 
   4670  1.1  skrll #undef TARGET_BIG_SYM
   4671  1.1  skrll #define TARGET_BIG_SYM		bfd_elf32_hppa_linux_vec
   4672  1.1  skrll #undef TARGET_BIG_NAME
   4673  1.1  skrll #define TARGET_BIG_NAME		"elf32-hppa-linux"
   4674  1.1  skrll #undef ELF_OSABI
   4675  1.1  skrll #define ELF_OSABI		ELFOSABI_LINUX
   4676  1.1  skrll #undef elf32_bed
   4677  1.1  skrll #define elf32_bed		elf32_hppa_linux_bed
   4678  1.1  skrll 
   4679  1.1  skrll #include "elf32-target.h"
   4680  1.1  skrll 
   4681  1.1  skrll #undef TARGET_BIG_SYM
   4682  1.1  skrll #define TARGET_BIG_SYM		bfd_elf32_hppa_nbsd_vec
   4683  1.1  skrll #undef TARGET_BIG_NAME
   4684  1.1  skrll #define TARGET_BIG_NAME		"elf32-hppa-netbsd"
   4685  1.1  skrll #undef ELF_OSABI
   4686  1.1  skrll #define ELF_OSABI		ELFOSABI_NETBSD
   4687  1.1  skrll #undef elf32_bed
   4688  1.1  skrll #define elf32_bed		elf32_hppa_netbsd_bed
   4689  1.1  skrll 
   4690  1.1  skrll #include "elf32-target.h"
   4691