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