Home | History | Annotate | Line # | Download | only in bfd
elf32-vax.c revision 1.1.1.9
      1      1.1  christos /* VAX series support for 32-bit ELF
      2  1.1.1.9  christos    Copyright (C) 1993-2020 Free Software Foundation, Inc.
      3      1.1  christos    Contributed by Matt Thomas <matt (at) 3am-software.com>.
      4      1.1  christos 
      5      1.1  christos    This file is part of BFD, the Binary File Descriptor library.
      6      1.1  christos 
      7      1.1  christos    This program is free software; you can redistribute it and/or modify
      8      1.1  christos    it under the terms of the GNU General Public License as published by
      9      1.1  christos    the Free Software Foundation; either version 3 of the License, or
     10      1.1  christos    (at your option) any later version.
     11      1.1  christos 
     12      1.1  christos    This program is distributed in the hope that it will be useful,
     13      1.1  christos    but WITHOUT ANY WARRANTY; without even the implied warranty of
     14      1.1  christos    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     15      1.1  christos    GNU General Public License for more details.
     16      1.1  christos 
     17      1.1  christos    You should have received a copy of the GNU General Public License
     18      1.1  christos    along with this program; if not, write to the Free Software
     19      1.1  christos    Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
     20      1.1  christos    MA 02110-1301, USA.  */
     21      1.1  christos 
     22      1.1  christos #include "sysdep.h"
     23      1.1  christos #include "bfd.h"
     24      1.1  christos #include "bfdlink.h"
     25      1.1  christos #include "libbfd.h"
     26      1.1  christos #include "elf-bfd.h"
     27      1.1  christos #include "elf/vax.h"
     28      1.1  christos 
     29      1.1  christos static reloc_howto_type *reloc_type_lookup (bfd *, bfd_reloc_code_real_type);
     30  1.1.1.8  christos static bfd_boolean rtype_to_howto (bfd *, arelent *, Elf_Internal_Rela *);
     31      1.1  christos static struct bfd_hash_entry *elf_vax_link_hash_newfunc (struct bfd_hash_entry *,
     32      1.1  christos 							 struct bfd_hash_table *,
     33      1.1  christos 							 const char *);
     34      1.1  christos static struct bfd_link_hash_table *elf_vax_link_hash_table_create (bfd *);
     35      1.1  christos static bfd_boolean elf_vax_check_relocs (bfd *, struct bfd_link_info *,
     36      1.1  christos 					 asection *, const Elf_Internal_Rela *);
     37      1.1  christos static bfd_boolean elf_vax_adjust_dynamic_symbol (struct bfd_link_info *,
     38      1.1  christos 						  struct elf_link_hash_entry *);
     39      1.1  christos static bfd_boolean elf_vax_size_dynamic_sections (bfd *, struct bfd_link_info *);
     40      1.1  christos static bfd_boolean elf_vax_relocate_section (bfd *, struct bfd_link_info *,
     41      1.1  christos 					     bfd *, asection *, bfd_byte *,
     42      1.1  christos 					     Elf_Internal_Rela *,
     43      1.1  christos 					     Elf_Internal_Sym *, asection **);
     44      1.1  christos static bfd_boolean elf_vax_finish_dynamic_symbol (bfd *, struct bfd_link_info *,
     45      1.1  christos 						  struct elf_link_hash_entry *,
     46      1.1  christos 						  Elf_Internal_Sym *);
     47      1.1  christos static bfd_boolean elf_vax_finish_dynamic_sections (bfd *,
     48      1.1  christos 						    struct bfd_link_info *);
     49      1.1  christos static bfd_vma elf_vax_plt_sym_val (bfd_vma, const asection *,
     50      1.1  christos 				    const arelent *);
     51      1.1  christos 
     52      1.1  christos static bfd_boolean elf32_vax_set_private_flags (bfd *, flagword);
     53  1.1.1.2  christos static bfd_boolean elf32_vax_print_private_bfd_data (bfd *, void *);
     54      1.1  christos 
     55      1.1  christos static reloc_howto_type howto_table[] = {
     56      1.1  christos   HOWTO (R_VAX_NONE,		/* type */
     57      1.1  christos 	 0,			/* rightshift */
     58  1.1.1.5  christos 	 3,			/* size (0 = byte, 1 = short, 2 = long) */
     59      1.1  christos 	 0,			/* bitsize */
     60      1.1  christos 	 FALSE,			/* pc_relative */
     61      1.1  christos 	 0,			/* bitpos */
     62      1.1  christos 	 complain_overflow_dont, /* complain_on_overflow */
     63      1.1  christos 	 bfd_elf_generic_reloc,	/* special_function */
     64      1.1  christos 	 "R_VAX_NONE",		/* name */
     65      1.1  christos 	 FALSE,			/* partial_inplace */
     66      1.1  christos 	 0,			/* src_mask */
     67      1.1  christos 	 0x00000000,		/* dst_mask */
     68      1.1  christos 	 FALSE),		/* pcrel_offset */
     69      1.1  christos 
     70      1.1  christos   HOWTO (R_VAX_32,		/* type */
     71      1.1  christos 	 0,			/* rightshift */
     72      1.1  christos 	 2,			/* size (0 = byte, 1 = short, 2 = long) */
     73      1.1  christos 	 32,			/* bitsize */
     74      1.1  christos 	 FALSE,			/* pc_relative */
     75      1.1  christos 	 0,			/* bitpos */
     76      1.1  christos 	 complain_overflow_bitfield, /* complain_on_overflow */
     77      1.1  christos 	 bfd_elf_generic_reloc,	/* special_function */
     78      1.1  christos 	 "R_VAX_32",		/* name */
     79      1.1  christos 	 FALSE,			/* partial_inplace */
     80      1.1  christos 	 0,			/* src_mask */
     81      1.1  christos 	 0xffffffff,		/* dst_mask */
     82      1.1  christos 	 FALSE),		/* pcrel_offset */
     83      1.1  christos 
     84      1.1  christos   HOWTO (R_VAX_16,		/* type */
     85      1.1  christos 	 0,			/* rightshift */
     86      1.1  christos 	 1,			/* size (0 = byte, 1 = short, 2 = long) */
     87      1.1  christos 	 16,			/* bitsize */
     88      1.1  christos 	 FALSE,			/* pc_relative */
     89      1.1  christos 	 0,			/* bitpos */
     90      1.1  christos 	 complain_overflow_bitfield, /* complain_on_overflow */
     91      1.1  christos 	 bfd_elf_generic_reloc,	/* special_function */
     92      1.1  christos 	 "R_VAX_16",		/* name */
     93      1.1  christos 	 FALSE,			/* partial_inplace */
     94      1.1  christos 	 0,			/* src_mask */
     95      1.1  christos 	 0x0000ffff,		/* dst_mask */
     96      1.1  christos 	 FALSE),		/* pcrel_offset */
     97      1.1  christos 
     98      1.1  christos   HOWTO (R_VAX_8,		/* type */
     99      1.1  christos 	 0,			/* rightshift */
    100      1.1  christos 	 0,			/* size (0 = byte, 1 = short, 2 = long) */
    101      1.1  christos 	 8,			/* bitsize */
    102      1.1  christos 	 FALSE,			/* pc_relative */
    103      1.1  christos 	 0,			/* bitpos */
    104      1.1  christos 	 complain_overflow_bitfield, /* complain_on_overflow */
    105      1.1  christos 	 bfd_elf_generic_reloc,	/* special_function */
    106      1.1  christos 	 "R_VAX_8",		/* name */
    107      1.1  christos 	 FALSE,			/* partial_inplace */
    108      1.1  christos 	 0,			/* src_mask */
    109      1.1  christos 	 0x000000ff,		/* dst_mask */
    110      1.1  christos 	 FALSE),		/* pcrel_offset */
    111      1.1  christos 
    112      1.1  christos   HOWTO (R_VAX_PC32,		/* type */
    113      1.1  christos 	 0,			/* rightshift */
    114      1.1  christos 	 2,			/* size (0 = byte, 1 = short, 2 = long) */
    115      1.1  christos 	 32,			/* bitsize */
    116      1.1  christos 	 TRUE,			/* pc_relative */
    117      1.1  christos 	 0,			/* bitpos */
    118      1.1  christos 	 complain_overflow_bitfield, /* complain_on_overflow */
    119      1.1  christos 	 bfd_elf_generic_reloc,	/* special_function */
    120      1.1  christos 	 "R_VAX_PC32",		/* name */
    121      1.1  christos 	 FALSE,			/* partial_inplace */
    122      1.1  christos 	 0,			/* src_mask */
    123      1.1  christos 	 0xffffffff,		/* dst_mask */
    124      1.1  christos 	 TRUE),			/* pcrel_offset */
    125      1.1  christos 
    126      1.1  christos   HOWTO (R_VAX_PC16,		/* type */
    127      1.1  christos 	 0,			/* rightshift */
    128      1.1  christos 	 1,			/* size (0 = byte, 1 = short, 2 = long) */
    129      1.1  christos 	 16,			/* bitsize */
    130      1.1  christos 	 TRUE,			/* pc_relative */
    131      1.1  christos 	 0,			/* bitpos */
    132      1.1  christos 	 complain_overflow_signed, /* complain_on_overflow */
    133      1.1  christos 	 bfd_elf_generic_reloc,	/* special_function */
    134      1.1  christos 	 "R_VAX_PC16",		/* name */
    135      1.1  christos 	 FALSE,			/* partial_inplace */
    136      1.1  christos 	 0,			/* src_mask */
    137      1.1  christos 	 0x0000ffff,		/* dst_mask */
    138      1.1  christos 	 TRUE),			/* pcrel_offset */
    139      1.1  christos 
    140      1.1  christos   HOWTO (R_VAX_PC8,		/* type */
    141      1.1  christos 	 0,			/* rightshift */
    142      1.1  christos 	 0,			/* size (0 = byte, 1 = short, 2 = long) */
    143      1.1  christos 	 8,			/* bitsize */
    144      1.1  christos 	 TRUE,			/* pc_relative */
    145      1.1  christos 	 0,			/* bitpos */
    146      1.1  christos 	 complain_overflow_signed, /* complain_on_overflow */
    147      1.1  christos 	 bfd_elf_generic_reloc,	/* special_function */
    148      1.1  christos 	 "R_VAX_PC8",		/* name */
    149      1.1  christos 	 FALSE,			/* partial_inplace */
    150      1.1  christos 	 0,			/* src_mask */
    151      1.1  christos 	 0x000000ff,		/* dst_mask */
    152      1.1  christos 	 TRUE),			/* pcrel_offset */
    153      1.1  christos 
    154      1.1  christos   HOWTO (R_VAX_GOT32,		/* type */
    155      1.1  christos 	 0,			/* rightshift */
    156      1.1  christos 	 2,			/* size (0 = byte, 1 = short, 2 = long) */
    157      1.1  christos 	 32,			/* bitsize */
    158      1.1  christos 	 TRUE,			/* pc_relative */
    159      1.1  christos 	 0,			/* bitpos */
    160      1.1  christos 	 complain_overflow_bitfield, /* complain_on_overflow */
    161      1.1  christos 	 bfd_elf_generic_reloc,	/* special_function */
    162      1.1  christos 	 "R_VAX_GOT32",		/* name */
    163      1.1  christos 	 FALSE,			/* partial_inplace */
    164      1.1  christos 	 0,			/* src_mask */
    165      1.1  christos 	 0xffffffff,		/* dst_mask */
    166      1.1  christos 	 TRUE),			/* pcrel_offset */
    167      1.1  christos 
    168      1.1  christos   EMPTY_HOWTO (-1),
    169      1.1  christos   EMPTY_HOWTO (-1),
    170      1.1  christos   EMPTY_HOWTO (-1),
    171      1.1  christos   EMPTY_HOWTO (-1),
    172      1.1  christos   EMPTY_HOWTO (-1),
    173      1.1  christos 
    174      1.1  christos   HOWTO (R_VAX_PLT32,		/* type */
    175      1.1  christos 	 0,			/* rightshift */
    176      1.1  christos 	 2,			/* size (0 = byte, 1 = short, 2 = long) */
    177      1.1  christos 	 32,			/* bitsize */
    178      1.1  christos 	 TRUE,			/* pc_relative */
    179      1.1  christos 	 0,			/* bitpos */
    180      1.1  christos 	 complain_overflow_bitfield, /* complain_on_overflow */
    181      1.1  christos 	 bfd_elf_generic_reloc,	/* special_function */
    182      1.1  christos 	 "R_VAX_PLT32",		/* name */
    183      1.1  christos 	 FALSE,			/* partial_inplace */
    184      1.1  christos 	 0,			/* src_mask */
    185      1.1  christos 	 0xffffffff,		/* dst_mask */
    186      1.1  christos 	 TRUE),			/* pcrel_offset */
    187      1.1  christos 
    188      1.1  christos   EMPTY_HOWTO (-1),
    189      1.1  christos   EMPTY_HOWTO (-1),
    190      1.1  christos   EMPTY_HOWTO (-1),
    191      1.1  christos   EMPTY_HOWTO (-1),
    192      1.1  christos   EMPTY_HOWTO (-1),
    193      1.1  christos 
    194      1.1  christos   HOWTO (R_VAX_COPY,		/* type */
    195      1.1  christos 	 0,			/* rightshift */
    196      1.1  christos 	 0,			/* size (0 = byte, 1 = short, 2 = long) */
    197      1.1  christos 	 0,			/* bitsize */
    198      1.1  christos 	 FALSE,			/* pc_relative */
    199      1.1  christos 	 0,			/* bitpos */
    200      1.1  christos 	 complain_overflow_dont, /* complain_on_overflow */
    201      1.1  christos 	 bfd_elf_generic_reloc,	/* special_function */
    202      1.1  christos 	 "R_VAX_COPY",		/* name */
    203      1.1  christos 	 FALSE,			/* partial_inplace */
    204      1.1  christos 	 0,			/* src_mask */
    205      1.1  christos 	 0xffffffff,		/* dst_mask */
    206      1.1  christos 	 FALSE),		/* pcrel_offset */
    207      1.1  christos 
    208      1.1  christos   HOWTO (R_VAX_GLOB_DAT,	/* type */
    209      1.1  christos 	 0,			/* rightshift */
    210      1.1  christos 	 2,			/* size (0 = byte, 1 = short, 2 = long) */
    211      1.1  christos 	 32,			/* bitsize */
    212      1.1  christos 	 FALSE,			/* pc_relative */
    213      1.1  christos 	 0,			/* bitpos */
    214      1.1  christos 	 complain_overflow_dont, /* complain_on_overflow */
    215      1.1  christos 	 bfd_elf_generic_reloc,	/* special_function */
    216      1.1  christos 	 "R_VAX_GLOB_DAT",	/* name */
    217      1.1  christos 	 FALSE,			/* partial_inplace */
    218      1.1  christos 	 0,			/* src_mask */
    219      1.1  christos 	 0xffffffff,		/* dst_mask */
    220      1.1  christos 	 FALSE),		/* pcrel_offset */
    221      1.1  christos 
    222      1.1  christos   HOWTO (R_VAX_JMP_SLOT,	/* type */
    223      1.1  christos 	 0,			/* rightshift */
    224      1.1  christos 	 2,			/* size (0 = byte, 1 = short, 2 = long) */
    225      1.1  christos 	 32,			/* bitsize */
    226      1.1  christos 	 FALSE,			/* pc_relative */
    227      1.1  christos 	 0,			/* bitpos */
    228      1.1  christos 	 complain_overflow_dont, /* complain_on_overflow */
    229      1.1  christos 	 bfd_elf_generic_reloc,	/* special_function */
    230      1.1  christos 	 "R_VAX_JMP_SLOT",	/* name */
    231      1.1  christos 	 FALSE,			/* partial_inplace */
    232      1.1  christos 	 0,			/* src_mask */
    233      1.1  christos 	 0xffffffff,		/* dst_mask */
    234      1.1  christos 	 FALSE),		/* pcrel_offset */
    235      1.1  christos 
    236      1.1  christos   HOWTO (R_VAX_RELATIVE,	/* type */
    237      1.1  christos 	 0,			/* rightshift */
    238      1.1  christos 	 2,			/* size (0 = byte, 1 = short, 2 = long) */
    239      1.1  christos 	 32,			/* bitsize */
    240      1.1  christos 	 FALSE,			/* pc_relative */
    241      1.1  christos 	 0,			/* bitpos */
    242      1.1  christos 	 complain_overflow_dont, /* complain_on_overflow */
    243      1.1  christos 	 bfd_elf_generic_reloc,	/* special_function */
    244      1.1  christos 	 "R_VAX_RELATIVE",	/* name */
    245      1.1  christos 	 FALSE,			/* partial_inplace */
    246      1.1  christos 	 0,			/* src_mask */
    247      1.1  christos 	 0xffffffff,		/* dst_mask */
    248      1.1  christos 	 FALSE),		/* pcrel_offset */
    249      1.1  christos 
    250      1.1  christos   /* GNU extension to record C++ vtable hierarchy */
    251      1.1  christos   HOWTO (R_VAX_GNU_VTINHERIT,	/* type */
    252      1.1  christos 	 0,			/* rightshift */
    253      1.1  christos 	 2,			/* size (0 = byte, 1 = short, 2 = long) */
    254      1.1  christos 	 0,			/* bitsize */
    255      1.1  christos 	 FALSE,			/* pc_relative */
    256      1.1  christos 	 0,			/* bitpos */
    257      1.1  christos 	 complain_overflow_dont, /* complain_on_overflow */
    258      1.1  christos 	 NULL,			/* special_function */
    259      1.1  christos 	 "R_VAX_GNU_VTINHERIT",	/* name */
    260      1.1  christos 	 FALSE,			/* partial_inplace */
    261      1.1  christos 	 0,			/* src_mask */
    262      1.1  christos 	 0,			/* dst_mask */
    263      1.1  christos 	 FALSE),		/* pcrel_offset */
    264      1.1  christos 
    265      1.1  christos   /* GNU extension to record C++ vtable member usage */
    266      1.1  christos   HOWTO (R_VAX_GNU_VTENTRY,	/* type */
    267      1.1  christos 	 0,			/* rightshift */
    268      1.1  christos 	 2,			/* size (0 = byte, 1 = short, 2 = long) */
    269      1.1  christos 	 0,			/* bitsize */
    270      1.1  christos 	 FALSE,			/* pc_relative */
    271      1.1  christos 	 0,			/* bitpos */
    272      1.1  christos 	 complain_overflow_dont, /* complain_on_overflow */
    273      1.1  christos 	 _bfd_elf_rel_vtable_reloc_fn, /* special_function */
    274      1.1  christos 	 "R_VAX_GNU_VTENTRY",	/* name */
    275      1.1  christos 	 FALSE,			/* partial_inplace */
    276      1.1  christos 	 0,			/* src_mask */
    277      1.1  christos 	 0,			/* dst_mask */
    278      1.1  christos 	 FALSE),		/* pcrel_offset */
    279      1.1  christos };
    280      1.1  christos 
    281  1.1.1.8  christos static bfd_boolean
    282  1.1.1.5  christos rtype_to_howto (bfd *abfd, arelent *cache_ptr, Elf_Internal_Rela *dst)
    283      1.1  christos {
    284  1.1.1.5  christos   unsigned int r_type;
    285  1.1.1.5  christos 
    286  1.1.1.5  christos   r_type = ELF32_R_TYPE (dst->r_info);
    287  1.1.1.5  christos   if (r_type >= R_VAX_max)
    288  1.1.1.5  christos     {
    289  1.1.1.7  christos       /* xgettext:c-format */
    290  1.1.1.8  christos       _bfd_error_handler (_("%pB: unsupported relocation type %#x"),
    291  1.1.1.7  christos 			  abfd, r_type);
    292  1.1.1.5  christos       bfd_set_error (bfd_error_bad_value);
    293  1.1.1.8  christos       return FALSE;
    294  1.1.1.5  christos     }
    295  1.1.1.5  christos   cache_ptr->howto = &howto_table[r_type];
    296  1.1.1.8  christos   return TRUE;
    297      1.1  christos }
    298      1.1  christos 
    299      1.1  christos #define elf_info_to_howto rtype_to_howto
    300      1.1  christos 
    301      1.1  christos static const struct
    302      1.1  christos {
    303      1.1  christos   bfd_reloc_code_real_type bfd_val;
    304      1.1  christos   int elf_val;
    305      1.1  christos } reloc_map[] = {
    306      1.1  christos   { BFD_RELOC_NONE, R_VAX_NONE },
    307      1.1  christos   { BFD_RELOC_32, R_VAX_32 },
    308      1.1  christos   { BFD_RELOC_16, R_VAX_16 },
    309      1.1  christos   { BFD_RELOC_8, R_VAX_8 },
    310      1.1  christos   { BFD_RELOC_32_PCREL, R_VAX_PC32 },
    311      1.1  christos   { BFD_RELOC_16_PCREL, R_VAX_PC16 },
    312      1.1  christos   { BFD_RELOC_8_PCREL, R_VAX_PC8 },
    313      1.1  christos   { BFD_RELOC_32_GOT_PCREL, R_VAX_GOT32 },
    314      1.1  christos   { BFD_RELOC_32_PLT_PCREL, R_VAX_PLT32 },
    315      1.1  christos   { BFD_RELOC_NONE, R_VAX_COPY },
    316      1.1  christos   { BFD_RELOC_VAX_GLOB_DAT, R_VAX_GLOB_DAT },
    317      1.1  christos   { BFD_RELOC_VAX_JMP_SLOT, R_VAX_JMP_SLOT },
    318      1.1  christos   { BFD_RELOC_VAX_RELATIVE, R_VAX_RELATIVE },
    319      1.1  christos   { BFD_RELOC_CTOR, R_VAX_32 },
    320      1.1  christos   { BFD_RELOC_VTABLE_INHERIT, R_VAX_GNU_VTINHERIT },
    321      1.1  christos   { BFD_RELOC_VTABLE_ENTRY, R_VAX_GNU_VTENTRY },
    322      1.1  christos };
    323      1.1  christos 
    324      1.1  christos static reloc_howto_type *
    325      1.1  christos reloc_type_lookup (bfd *abfd ATTRIBUTE_UNUSED, bfd_reloc_code_real_type code)
    326      1.1  christos {
    327      1.1  christos   unsigned int i;
    328      1.1  christos   for (i = 0; i < sizeof (reloc_map) / sizeof (reloc_map[0]); i++)
    329      1.1  christos     {
    330      1.1  christos       if (reloc_map[i].bfd_val == code)
    331      1.1  christos 	return &howto_table[reloc_map[i].elf_val];
    332      1.1  christos     }
    333      1.1  christos   return 0;
    334      1.1  christos }
    335      1.1  christos 
    336      1.1  christos static reloc_howto_type *
    337      1.1  christos reloc_name_lookup (bfd *abfd ATTRIBUTE_UNUSED,
    338      1.1  christos 		   const char *r_name)
    339      1.1  christos {
    340      1.1  christos   unsigned int i;
    341      1.1  christos 
    342      1.1  christos   for (i = 0; i < sizeof (howto_table) / sizeof (howto_table[0]); i++)
    343      1.1  christos     if (howto_table[i].name != NULL
    344      1.1  christos 	&& strcasecmp (howto_table[i].name, r_name) == 0)
    345      1.1  christos       return &howto_table[i];
    346      1.1  christos 
    347      1.1  christos   return NULL;
    348      1.1  christos }
    349      1.1  christos 
    350      1.1  christos #define bfd_elf32_bfd_reloc_type_lookup reloc_type_lookup
    351      1.1  christos #define bfd_elf32_bfd_reloc_name_lookup reloc_name_lookup
    352      1.1  christos #define ELF_ARCH bfd_arch_vax
    353      1.1  christos /* end code generated by elf.el */
    354      1.1  christos 
    355      1.1  christos /* Functions for the VAX ELF linker.  */
    357      1.1  christos 
    358      1.1  christos /* The name of the dynamic interpreter.  This is put in the .interp
    359      1.1  christos    section.  */
    360      1.1  christos 
    361      1.1  christos #define ELF_DYNAMIC_INTERPRETER "/usr/libexec/ld.elf_so"
    362      1.1  christos 
    363      1.1  christos /* The size in bytes of an entry in the procedure linkage table.  */
    364      1.1  christos 
    365      1.1  christos #define PLT_ENTRY_SIZE 12
    366      1.1  christos 
    367      1.1  christos /* The first entry in a procedure linkage table looks like this.  See
    368      1.1  christos    the SVR4 ABI VAX supplement to see how this works.  */
    369      1.1  christos 
    370      1.1  christos static const bfd_byte elf_vax_plt0_entry[PLT_ENTRY_SIZE] =
    371      1.1  christos {
    372      1.1  christos   0xdd, 0xef,		/* pushl l^ */
    373      1.1  christos   0, 0, 0, 0,		/* offset to .plt.got + 4 */
    374      1.1  christos   0x17, 0xff,		/* jmp @L^(pc) */
    375      1.1  christos   0, 0, 0, 0,		/* offset to .plt.got + 8 */
    376      1.1  christos };
    377      1.1  christos 
    378      1.1  christos /* Subsequent entries in a procedure linkage table look like this.  */
    379      1.1  christos 
    380      1.1  christos static const bfd_byte elf_vax_plt_entry[PLT_ENTRY_SIZE] =
    381      1.1  christos {
    382      1.1  christos   0xfc, 0x0f,		/* .word ^M<r11:r2> */
    383      1.1  christos   0x16, 0xef,		/* jsb L^(pc) */
    384      1.1  christos   0, 0, 0, 0,		/* replaced with offset to start of .plt  */
    385      1.1  christos   0, 0, 0, 0,		/* index into .rela.plt */
    386      1.1  christos };
    387      1.1  christos 
    388      1.1  christos /* The VAX linker needs to keep track of the number of relocs that it
    389      1.1  christos    decides to copy in check_relocs for each symbol.  This is so that it
    390      1.1  christos    can discard PC relative relocs if it doesn't need them when linking
    391      1.1  christos    with -Bsymbolic.  We store the information in a field extending the
    392      1.1  christos    regular ELF linker hash table.  */
    393      1.1  christos 
    394      1.1  christos /* This structure keeps track of the number of PC relative relocs we have
    395      1.1  christos    copied for a given symbol.  */
    396      1.1  christos 
    397      1.1  christos struct elf_vax_pcrel_relocs_copied
    398      1.1  christos {
    399      1.1  christos   /* Next section.  */
    400      1.1  christos   struct elf_vax_pcrel_relocs_copied *next;
    401      1.1  christos   /* A section in dynobj.  */
    402      1.1  christos   asection *section;
    403      1.1  christos   /* Number of relocs copied in this section.  */
    404      1.1  christos   bfd_size_type count;
    405      1.1  christos };
    406      1.1  christos 
    407      1.1  christos /* VAX ELF linker hash entry.  */
    408      1.1  christos 
    409      1.1  christos struct elf_vax_link_hash_entry
    410      1.1  christos {
    411      1.1  christos   struct elf_link_hash_entry root;
    412      1.1  christos 
    413      1.1  christos   /* Number of PC relative relocs copied for this symbol.  */
    414      1.1  christos   struct elf_vax_pcrel_relocs_copied *pcrel_relocs_copied;
    415      1.1  christos 
    416      1.1  christos   bfd_vma got_addend;
    417      1.1  christos };
    418      1.1  christos 
    419      1.1  christos /* Declare this now that the above structures are defined.  */
    420      1.1  christos 
    421      1.1  christos static bfd_boolean elf_vax_discard_copies (struct elf_vax_link_hash_entry *,
    422      1.1  christos 					   void *);
    423      1.1  christos 
    424      1.1  christos /* Declare this now that the above structures are defined.  */
    425      1.1  christos 
    426      1.1  christos static bfd_boolean elf_vax_instantiate_got_entries (struct elf_link_hash_entry *,
    427      1.1  christos 						    void *);
    428      1.1  christos 
    429      1.1  christos /* Traverse an VAX ELF linker hash table.  */
    430      1.1  christos 
    431      1.1  christos #define elf_vax_link_hash_traverse(table, func, info)			\
    432      1.1  christos   (elf_link_hash_traverse						\
    433  1.1.1.2  christos    ((table),								\
    434      1.1  christos     (bfd_boolean (*) (struct elf_link_hash_entry *, void *)) (func),	\
    435      1.1  christos     (info)))
    436      1.1  christos 
    437      1.1  christos /* Create an entry in an VAX ELF linker hash table.  */
    438      1.1  christos 
    439      1.1  christos static struct bfd_hash_entry *
    440      1.1  christos elf_vax_link_hash_newfunc (struct bfd_hash_entry *entry,
    441      1.1  christos 			   struct bfd_hash_table *table,
    442      1.1  christos 			   const char *string)
    443      1.1  christos {
    444      1.1  christos   struct elf_vax_link_hash_entry *ret =
    445      1.1  christos     (struct elf_vax_link_hash_entry *) entry;
    446      1.1  christos 
    447      1.1  christos   /* Allocate the structure if it has not already been allocated by a
    448      1.1  christos      subclass.  */
    449      1.1  christos   if (ret == NULL)
    450      1.1  christos     ret = ((struct elf_vax_link_hash_entry *)
    451      1.1  christos 	   bfd_hash_allocate (table,
    452      1.1  christos 			      sizeof (struct elf_vax_link_hash_entry)));
    453      1.1  christos   if (ret == NULL)
    454      1.1  christos     return (struct bfd_hash_entry *) ret;
    455      1.1  christos 
    456      1.1  christos   /* Call the allocation method of the superclass.  */
    457      1.1  christos   ret = ((struct elf_vax_link_hash_entry *)
    458      1.1  christos 	 _bfd_elf_link_hash_newfunc ((struct bfd_hash_entry *) ret,
    459      1.1  christos 				     table, string));
    460      1.1  christos   if (ret != NULL)
    461      1.1  christos     {
    462      1.1  christos       ret->pcrel_relocs_copied = NULL;
    463      1.1  christos     }
    464      1.1  christos 
    465      1.1  christos   return (struct bfd_hash_entry *) ret;
    466      1.1  christos }
    467      1.1  christos 
    468      1.1  christos /* Create an VAX ELF linker hash table.  */
    469      1.1  christos 
    470      1.1  christos static struct bfd_link_hash_table *
    471      1.1  christos elf_vax_link_hash_table_create (bfd *abfd)
    472      1.1  christos {
    473  1.1.1.9  christos   struct elf_link_hash_table *ret;
    474      1.1  christos   size_t amt = sizeof (struct elf_link_hash_table);
    475  1.1.1.2  christos 
    476      1.1  christos   ret = bfd_zmalloc (amt);
    477      1.1  christos   if (ret == NULL)
    478      1.1  christos     return NULL;
    479      1.1  christos 
    480      1.1  christos   if (!_bfd_elf_link_hash_table_init (ret, abfd,
    481      1.1  christos 				      elf_vax_link_hash_newfunc,
    482      1.1  christos 				      sizeof (struct elf_vax_link_hash_entry),
    483      1.1  christos 				      GENERIC_ELF_DATA))
    484      1.1  christos     {
    485      1.1  christos       free (ret);
    486      1.1  christos       return NULL;
    487      1.1  christos     }
    488      1.1  christos 
    489      1.1  christos   return &ret->root;
    490      1.1  christos }
    491      1.1  christos 
    492      1.1  christos /* Keep vax-specific flags in the ELF header */
    493      1.1  christos static bfd_boolean
    494      1.1  christos elf32_vax_set_private_flags (bfd *abfd, flagword flags)
    495      1.1  christos {
    496      1.1  christos   elf_elfheader (abfd)->e_flags = flags;
    497      1.1  christos   elf_flags_init (abfd) = TRUE;
    498      1.1  christos   return TRUE;
    499      1.1  christos }
    500      1.1  christos 
    501      1.1  christos /* Merge backend specific data from an object file to the output
    502      1.1  christos    object file when linking.  */
    503  1.1.1.7  christos static bfd_boolean
    504      1.1  christos elf32_vax_merge_private_bfd_data (bfd *ibfd, struct bfd_link_info *info)
    505  1.1.1.7  christos {
    506      1.1  christos   bfd *obfd = info->output_bfd;
    507      1.1  christos   flagword in_flags;
    508      1.1  christos 
    509      1.1  christos   if (   bfd_get_flavour (ibfd) != bfd_target_elf_flavour
    510      1.1  christos       || bfd_get_flavour (obfd) != bfd_target_elf_flavour)
    511      1.1  christos     return TRUE;
    512      1.1  christos 
    513      1.1  christos   in_flags  = elf_elfheader (ibfd)->e_flags;
    514      1.1  christos 
    515      1.1  christos   if (!elf_flags_init (obfd))
    516      1.1  christos     {
    517      1.1  christos       elf_flags_init (obfd) = TRUE;
    518      1.1  christos       elf_elfheader (obfd)->e_flags = in_flags;
    519      1.1  christos     }
    520      1.1  christos 
    521      1.1  christos   return TRUE;
    522      1.1  christos }
    523      1.1  christos 
    524      1.1  christos /* Display the flags field */
    525  1.1.1.2  christos static bfd_boolean
    526      1.1  christos elf32_vax_print_private_bfd_data (bfd *abfd, void * ptr)
    527      1.1  christos {
    528      1.1  christos   FILE *file = (FILE *) ptr;
    529      1.1  christos 
    530      1.1  christos   BFD_ASSERT (abfd != NULL && ptr != NULL);
    531      1.1  christos 
    532      1.1  christos   /* Print normal ELF private data.  */
    533      1.1  christos   _bfd_elf_print_private_bfd_data (abfd, ptr);
    534      1.1  christos 
    535      1.1  christos   /* Ignore init flag - it may not be set, despite the flags field containing valid data.  */
    536      1.1  christos 
    537      1.1  christos   /* xgettext:c-format */
    538      1.1  christos   fprintf (file, _("private flags = %lx:"), elf_elfheader (abfd)->e_flags);
    539      1.1  christos 
    540      1.1  christos   if (elf_elfheader (abfd)->e_flags & EF_VAX_NONPIC)
    541      1.1  christos     fprintf (file, _(" [nonpic]"));
    542      1.1  christos 
    543      1.1  christos   if (elf_elfheader (abfd)->e_flags & EF_VAX_DFLOAT)
    544      1.1  christos     fprintf (file, _(" [d-float]"));
    545      1.1  christos 
    546      1.1  christos   if (elf_elfheader (abfd)->e_flags & EF_VAX_GFLOAT)
    547      1.1  christos     fprintf (file, _(" [g-float]"));
    548      1.1  christos 
    549      1.1  christos   fputc ('\n', file);
    550      1.1  christos 
    551      1.1  christos   return TRUE;
    552      1.1  christos }
    553      1.1  christos /* Look through the relocs for a section during the first phase, and
    554      1.1  christos    allocate space in the global offset table or procedure linkage
    555      1.1  christos    table.  */
    556      1.1  christos 
    557      1.1  christos static bfd_boolean
    558      1.1  christos elf_vax_check_relocs (bfd *abfd, struct bfd_link_info *info, asection *sec,
    559      1.1  christos 		      const Elf_Internal_Rela *relocs)
    560      1.1  christos {
    561      1.1  christos   bfd *dynobj;
    562      1.1  christos   Elf_Internal_Shdr *symtab_hdr;
    563      1.1  christos   struct elf_link_hash_entry **sym_hashes;
    564      1.1  christos   const Elf_Internal_Rela *rel;
    565      1.1  christos   const Elf_Internal_Rela *rel_end;
    566      1.1  christos   asection *sreloc;
    567  1.1.1.6  christos 
    568      1.1  christos   if (bfd_link_relocatable (info))
    569      1.1  christos     return TRUE;
    570      1.1  christos 
    571      1.1  christos   dynobj = elf_hash_table (info)->dynobj;
    572      1.1  christos   symtab_hdr = &elf_tdata (abfd)->symtab_hdr;
    573      1.1  christos   sym_hashes = elf_sym_hashes (abfd);
    574      1.1  christos 
    575      1.1  christos   sreloc = NULL;
    576      1.1  christos 
    577      1.1  christos   rel_end = relocs + sec->reloc_count;
    578      1.1  christos   for (rel = relocs; rel < rel_end; rel++)
    579      1.1  christos     {
    580      1.1  christos       unsigned long r_symndx;
    581      1.1  christos       struct elf_link_hash_entry *h;
    582      1.1  christos 
    583      1.1  christos       r_symndx = ELF32_R_SYM (rel->r_info);
    584      1.1  christos 
    585      1.1  christos       if (r_symndx < symtab_hdr->sh_info)
    586      1.1  christos 	h = NULL;
    587      1.1  christos       else
    588      1.1  christos 	{
    589      1.1  christos 	  h = sym_hashes[r_symndx - symtab_hdr->sh_info];
    590      1.1  christos 	  while (h->root.type == bfd_link_hash_indirect
    591      1.1  christos 		 || h->root.type == bfd_link_hash_warning)
    592      1.1  christos 	    h = (struct elf_link_hash_entry *) h->root.u.i.link;
    593      1.1  christos 	}
    594      1.1  christos 
    595      1.1  christos       switch (ELF32_R_TYPE (rel->r_info))
    596      1.1  christos 	{
    597      1.1  christos 	case R_VAX_GOT32:
    598      1.1  christos 	  BFD_ASSERT (h != NULL);
    599      1.1  christos 
    600      1.1  christos 	  /* If this is a local symbol, we resolve it directly without
    601  1.1.1.3  christos 	     creating a global offset table entry.  */
    602  1.1.1.3  christos 	  if (h->forced_local
    603  1.1.1.3  christos 	      || h == elf_hash_table (info)->hgot
    604      1.1  christos 	      || h == elf_hash_table (info)->hplt)
    605      1.1  christos 	    break;
    606      1.1  christos 
    607      1.1  christos 	  /* This symbol requires a global offset table entry.  */
    608      1.1  christos 
    609      1.1  christos 	  if (dynobj == NULL)
    610      1.1  christos 	    {
    611      1.1  christos 	      /* Create the .got section.  */
    612      1.1  christos 	      elf_hash_table (info)->dynobj = dynobj = abfd;
    613      1.1  christos 	      if (!_bfd_elf_create_got_section (dynobj, info))
    614      1.1  christos 		return FALSE;
    615      1.1  christos 	    }
    616      1.1  christos 
    617      1.1  christos 	  if (h != NULL)
    618      1.1  christos 	    {
    619      1.1  christos 	      struct elf_vax_link_hash_entry *eh;
    620      1.1  christos 
    621      1.1  christos 	      eh = (struct elf_vax_link_hash_entry *) h;
    622      1.1  christos 	      if (h->got.refcount == -1)
    623      1.1  christos 		{
    624      1.1  christos 		  h->got.refcount = 1;
    625      1.1  christos 		  eh->got_addend = rel->r_addend;
    626      1.1  christos 		}
    627      1.1  christos 	      else
    628      1.1  christos 		{
    629      1.1  christos 		  h->got.refcount++;
    630  1.1.1.7  christos 		  if (eh->got_addend != (bfd_vma) rel->r_addend)
    631  1.1.1.7  christos 		    _bfd_error_handler
    632  1.1.1.8  christos 		      /* xgettext:c-format */
    633  1.1.1.8  christos 		      (_("%pB: warning: GOT addend of %" PRId64 " to `%s' does"
    634  1.1.1.8  christos 			 " not match previous GOT addend of %" PRId64),
    635  1.1.1.8  christos 			 abfd, (int64_t) rel->r_addend, h->root.root.string,
    636      1.1  christos 			 (int64_t) eh->got_addend);
    637      1.1  christos 
    638      1.1  christos 		}
    639      1.1  christos 	    }
    640      1.1  christos 	  break;
    641      1.1  christos 
    642      1.1  christos 	case R_VAX_PLT32:
    643      1.1  christos 	  /* This symbol requires a procedure linkage table entry.  We
    644  1.1.1.8  christos 	     actually build the entry in adjust_dynamic_symbol,
    645  1.1.1.8  christos 	     because this might be a case of linking PIC code which is
    646  1.1.1.8  christos 	     never referenced by a dynamic object, in which case we
    647  1.1.1.8  christos 	     don't need to generate a procedure linkage table entry
    648  1.1.1.3  christos 	     after all.  */
    649      1.1  christos 	  BFD_ASSERT (h != NULL);
    650      1.1  christos 
    651      1.1  christos 	  /* If this is a local symbol, we resolve it directly without
    652  1.1.1.3  christos 	     creating a procedure linkage table entry.  */
    653      1.1  christos 	  if (h->forced_local)
    654      1.1  christos 	    break;
    655      1.1  christos 
    656      1.1  christos 	  h->needs_plt = 1;
    657      1.1  christos 	  if (h->plt.refcount == -1)
    658      1.1  christos 	    h->plt.refcount = 1;
    659      1.1  christos 	  else
    660      1.1  christos 	    h->plt.refcount++;
    661      1.1  christos 	  break;
    662      1.1  christos 
    663      1.1  christos 	case R_VAX_PC8:
    664      1.1  christos 	case R_VAX_PC16:
    665      1.1  christos 	case R_VAX_PC32:
    666      1.1  christos 	  /* If we are creating a shared library and this is not a local
    667      1.1  christos 	     symbol, we need to copy the reloc into the shared library.
    668      1.1  christos 	     However when linking with -Bsymbolic and this is a global
    669      1.1  christos 	     symbol which is defined in an object we are including in the
    670      1.1  christos 	     link (i.e., DEF_REGULAR is set), then we can resolve the
    671      1.1  christos 	     reloc directly.  At this point we have not seen all the input
    672      1.1  christos 	     files, so it is possible that DEF_REGULAR is not set now but
    673      1.1  christos 	     will be set later (it is never cleared).  We account for that
    674      1.1  christos 	     possibility below by storing information in the
    675  1.1.1.6  christos 	     pcrel_relocs_copied field of the hash table entry.  */
    676      1.1  christos 	  if (!(bfd_link_pic (info)
    677      1.1  christos 		&& (sec->flags & SEC_ALLOC) != 0
    678      1.1  christos 		&& h != NULL
    679      1.1  christos 		&& (!info->symbolic
    680      1.1  christos 		    || !h->def_regular)))
    681      1.1  christos 	    {
    682      1.1  christos 	      if (h != NULL
    683      1.1  christos 		  && ELF_ST_VISIBILITY (h->other) == STV_DEFAULT
    684      1.1  christos 		  && !h->forced_local)
    685      1.1  christos 		{
    686      1.1  christos 		  /* Make sure a plt entry is created for this symbol if
    687      1.1  christos 		     it turns out to be a function defined by a dynamic
    688      1.1  christos 		     object.  */
    689      1.1  christos 		  if (h->plt.refcount == -1)
    690      1.1  christos 		    h->plt.refcount = 1;
    691      1.1  christos 		  else
    692      1.1  christos 		    h->plt.refcount++;
    693      1.1  christos 		}
    694      1.1  christos 	      break;
    695      1.1  christos 	    }
    696      1.1  christos 	  /* If this is a local symbol, we can resolve it directly.  */
    697      1.1  christos 	  if (h != NULL
    698      1.1  christos 	      && (ELF_ST_VISIBILITY (h->other) != STV_DEFAULT
    699      1.1  christos 		  || h->forced_local))
    700      1.1  christos 	    break;
    701      1.1  christos 
    702      1.1  christos 	  /* Fall through.  */
    703      1.1  christos 	case R_VAX_8:
    704      1.1  christos 	case R_VAX_16:
    705      1.1  christos 	case R_VAX_32:
    706      1.1  christos 	  if (h != NULL && ELF_ST_VISIBILITY (h->other) == STV_DEFAULT)
    707      1.1  christos 	    {
    708      1.1  christos 	      /* Make sure a plt entry is created for this symbol if it
    709      1.1  christos 		 turns out to be a function defined by a dynamic object.  */
    710      1.1  christos 	      if (h->plt.refcount == -1)
    711      1.1  christos 		h->plt.refcount = 1;
    712      1.1  christos 	      else
    713      1.1  christos 		h->plt.refcount++;
    714      1.1  christos 	    }
    715  1.1.1.9  christos 
    716  1.1.1.9  christos 	  /* Non-GOT reference may need a copy reloc in executable or
    717  1.1.1.9  christos 	     a dynamic reloc in shared library.  */
    718  1.1.1.9  christos 	  if (h != NULL)
    719  1.1.1.9  christos 	    h->non_got_ref = 1;
    720      1.1  christos 
    721      1.1  christos 	  /* If we are creating a shared library, we need to copy the
    722  1.1.1.6  christos 	     reloc into the shared library.  */
    723      1.1  christos 	  if (bfd_link_pic (info)
    724      1.1  christos 	      && (sec->flags & SEC_ALLOC) != 0)
    725      1.1  christos 	    {
    726      1.1  christos 	      /* When creating a shared object, we must copy these
    727      1.1  christos 		 reloc types into the output file.  We create a reloc
    728      1.1  christos 		 section in dynobj and make room for this reloc.  */
    729      1.1  christos 	      if (sreloc == NULL)
    730      1.1  christos 		{
    731      1.1  christos 		  sreloc = _bfd_elf_make_dynamic_reloc_section
    732      1.1  christos 		    (sec, dynobj, 2, abfd, /*rela?*/ TRUE);
    733      1.1  christos 
    734      1.1  christos 		  if (sreloc == NULL)
    735      1.1  christos 		    return FALSE;
    736      1.1  christos 
    737      1.1  christos 		  if (sec->flags & SEC_READONLY)
    738      1.1  christos 		    info->flags |= DF_TEXTREL;
    739      1.1  christos 		}
    740      1.1  christos 
    741      1.1  christos 	      sreloc->size += sizeof (Elf32_External_Rela);
    742      1.1  christos 
    743      1.1  christos 	      /* If we are linking with -Bsymbolic, we count the number of
    744      1.1  christos 		 PC relative relocations we have entered for this symbol,
    745      1.1  christos 		 so that we can discard them again if the symbol is later
    746      1.1  christos 		 defined by a regular object.  Note that this function is
    747      1.1  christos 		 only called if we are using a vaxelf linker hash table,
    748      1.1  christos 		 which means that h is really a pointer to an
    749      1.1  christos 		 elf_vax_link_hash_entry.  */
    750      1.1  christos 	      if ((ELF32_R_TYPE (rel->r_info) == R_VAX_PC8
    751      1.1  christos 		   || ELF32_R_TYPE (rel->r_info) == R_VAX_PC16
    752      1.1  christos 		   || ELF32_R_TYPE (rel->r_info) == R_VAX_PC32)
    753      1.1  christos 		  && info->symbolic)
    754      1.1  christos 		{
    755      1.1  christos 		  struct elf_vax_link_hash_entry *eh;
    756      1.1  christos 		  struct elf_vax_pcrel_relocs_copied *p;
    757      1.1  christos 
    758      1.1  christos 		  eh = (struct elf_vax_link_hash_entry *) h;
    759      1.1  christos 
    760      1.1  christos 		  for (p = eh->pcrel_relocs_copied; p != NULL; p = p->next)
    761      1.1  christos 		    if (p->section == sreloc)
    762      1.1  christos 		      break;
    763      1.1  christos 
    764      1.1  christos 		  if (p == NULL)
    765      1.1  christos 		    {
    766      1.1  christos 		      p = ((struct elf_vax_pcrel_relocs_copied *)
    767      1.1  christos 			   bfd_alloc (dynobj, (bfd_size_type) sizeof *p));
    768      1.1  christos 		      if (p == NULL)
    769      1.1  christos 			return FALSE;
    770      1.1  christos 		      p->next = eh->pcrel_relocs_copied;
    771      1.1  christos 		      eh->pcrel_relocs_copied = p;
    772      1.1  christos 		      p->section = sreloc;
    773      1.1  christos 		      p->count = 0;
    774      1.1  christos 		    }
    775      1.1  christos 
    776      1.1  christos 		  ++p->count;
    777      1.1  christos 		}
    778      1.1  christos 	    }
    779      1.1  christos 
    780      1.1  christos 	  break;
    781      1.1  christos 
    782      1.1  christos 	  /* This relocation describes the C++ object vtable hierarchy.
    783      1.1  christos 	     Reconstruct it for later use during GC.  */
    784      1.1  christos 	case R_VAX_GNU_VTINHERIT:
    785      1.1  christos 	  if (!bfd_elf_gc_record_vtinherit (abfd, sec, h, rel->r_offset))
    786      1.1  christos 	    return FALSE;
    787      1.1  christos 	  break;
    788      1.1  christos 
    789      1.1  christos 	  /* This relocation describes which C++ vtable entries are actually
    790      1.1  christos 	     used.  Record for later use during GC.  */
    791  1.1.1.9  christos 	case R_VAX_GNU_VTENTRY:
    792      1.1  christos 	  if (!bfd_elf_gc_record_vtentry (abfd, sec, h, rel->r_addend))
    793      1.1  christos 	    return FALSE;
    794      1.1  christos 	  break;
    795      1.1  christos 
    796      1.1  christos 	default:
    797      1.1  christos 	  break;
    798      1.1  christos 	}
    799      1.1  christos     }
    800      1.1  christos 
    801      1.1  christos   return TRUE;
    802      1.1  christos }
    803      1.1  christos 
    804      1.1  christos /* Return the section that should be marked against GC for a given
    805      1.1  christos    relocation.  */
    806      1.1  christos 
    807      1.1  christos static asection *
    808      1.1  christos elf_vax_gc_mark_hook (asection *sec,
    809      1.1  christos 		      struct bfd_link_info *info,
    810      1.1  christos 		      Elf_Internal_Rela *rel,
    811      1.1  christos 		      struct elf_link_hash_entry *h,
    812      1.1  christos 		      Elf_Internal_Sym *sym)
    813      1.1  christos {
    814      1.1  christos   if (h != NULL)
    815      1.1  christos     switch (ELF32_R_TYPE (rel->r_info))
    816      1.1  christos       {
    817      1.1  christos       case R_VAX_GNU_VTINHERIT:
    818      1.1  christos       case R_VAX_GNU_VTENTRY:
    819      1.1  christos 	return NULL;
    820      1.1  christos       }
    821      1.1  christos 
    822      1.1  christos   return _bfd_elf_gc_mark_hook (sec, info, rel, h, sym);
    823      1.1  christos }
    824      1.1  christos 
    825      1.1  christos /* Adjust a symbol defined by a dynamic object and referenced by a
    826      1.1  christos    regular object.  The current definition is in some section of the
    827      1.1  christos    dynamic object, but we're not including those sections.  We have to
    828      1.1  christos    change the definition to something the rest of the link can
    829      1.1  christos    understand.  */
    830      1.1  christos 
    831  1.1.1.3  christos static bfd_boolean
    832  1.1.1.3  christos elf_vax_adjust_dynamic_symbol (struct bfd_link_info *info,
    833      1.1  christos 			       struct elf_link_hash_entry *h)
    834      1.1  christos {
    835      1.1  christos   bfd *dynobj;
    836      1.1  christos   asection *s;
    837      1.1  christos 
    838      1.1  christos   dynobj = elf_hash_table (info)->dynobj;
    839      1.1  christos 
    840      1.1  christos   /* Make sure we know what is going on here.  */
    841      1.1  christos   BFD_ASSERT (dynobj != NULL
    842  1.1.1.8  christos 	      && (h->needs_plt
    843      1.1  christos 		  || h->is_weakalias
    844      1.1  christos 		  || (h->def_dynamic
    845      1.1  christos 		      && h->ref_regular
    846      1.1  christos 		      && !h->def_regular)));
    847      1.1  christos 
    848      1.1  christos   /* If this is a function, put it in the procedure linkage table.  We
    849      1.1  christos      will fill in the contents of the procedure linkage table later,
    850      1.1  christos      when we know the address of the .got section.  */
    851      1.1  christos   if (h->type == STT_FUNC
    852      1.1  christos       || h->needs_plt)
    853  1.1.1.2  christos     {
    854  1.1.1.2  christos       if (h->plt.refcount <= 0
    855  1.1.1.2  christos 	  || SYMBOL_CALLS_LOCAL (info, h)
    856  1.1.1.2  christos 	  || (ELF_ST_VISIBILITY (h->other) != STV_DEFAULT
    857      1.1  christos 	      && h->root.type == bfd_link_hash_undefweak))
    858      1.1  christos 	{
    859      1.1  christos 	  /* This case can occur if we saw a PLTxx reloc in an input
    860  1.1.1.2  christos 	     file, but the symbol was never referred to by a dynamic
    861  1.1.1.2  christos 	     object, or if all references were garbage collected.  In
    862  1.1.1.2  christos 	     such a case, we don't actually need to build a procedure
    863      1.1  christos 	     linkage table, and we can just do a PCxx reloc instead.  */
    864      1.1  christos 	  h->plt.offset = (bfd_vma) -1;
    865      1.1  christos 	  h->needs_plt = 0;
    866      1.1  christos 	  return TRUE;
    867      1.1  christos 	}
    868  1.1.1.7  christos 
    869      1.1  christos       s = elf_hash_table (info)->splt;
    870      1.1  christos       BFD_ASSERT (s != NULL);
    871      1.1  christos 
    872      1.1  christos       /* If this is the first .plt entry, make room for the special
    873      1.1  christos 	 first entry.  */
    874      1.1  christos       if (s->size == 0)
    875      1.1  christos 	{
    876      1.1  christos 	  s->size += PLT_ENTRY_SIZE;
    877      1.1  christos 	}
    878      1.1  christos 
    879      1.1  christos       /* If this symbol is not defined in a regular file, and we are
    880      1.1  christos 	 not generating a shared library, then set the symbol to this
    881      1.1  christos 	 location in the .plt.  This is required to make function
    882      1.1  christos 	 pointers compare as equal between the normal executable and
    883  1.1.1.6  christos 	 the shared library.  */
    884      1.1  christos       if (!bfd_link_pic (info)
    885      1.1  christos 	  && !h->def_regular)
    886      1.1  christos 	{
    887      1.1  christos 	  h->root.u.def.section = s;
    888      1.1  christos 	  h->root.u.def.value = s->size;
    889      1.1  christos 	}
    890      1.1  christos 
    891      1.1  christos       h->plt.offset = s->size;
    892      1.1  christos 
    893      1.1  christos       /* Make room for this entry.  */
    894      1.1  christos       s->size += PLT_ENTRY_SIZE;
    895      1.1  christos 
    896      1.1  christos       /* We also need to make an entry in the .got.plt section, which
    897      1.1  christos 	 will be placed in the .got section by the linker script.  */
    898  1.1.1.7  christos 
    899      1.1  christos       s = elf_hash_table (info)->sgotplt;
    900      1.1  christos       BFD_ASSERT (s != NULL);
    901      1.1  christos       s->size += 4;
    902      1.1  christos 
    903      1.1  christos       /* We also need to make an entry in the .rela.plt section.  */
    904  1.1.1.7  christos 
    905      1.1  christos       s = elf_hash_table (info)->srelplt;
    906      1.1  christos       BFD_ASSERT (s != NULL);
    907      1.1  christos       s->size += sizeof (Elf32_External_Rela);
    908      1.1  christos 
    909      1.1  christos       return TRUE;
    910      1.1  christos     }
    911      1.1  christos 
    912      1.1  christos   /* Reinitialize the plt offset now that it is not used as a reference
    913      1.1  christos      count any more.  */
    914      1.1  christos   h->plt.offset = (bfd_vma) -1;
    915      1.1  christos 
    916      1.1  christos   /* If this is a weak symbol, and there is a real definition, the
    917      1.1  christos      processor independent code will have arranged for us to see the
    918  1.1.1.8  christos      real definition first, and we can just use the same value.  */
    919      1.1  christos   if (h->is_weakalias)
    920  1.1.1.8  christos     {
    921  1.1.1.8  christos       struct elf_link_hash_entry *def = weakdef (h);
    922  1.1.1.8  christos       BFD_ASSERT (def->root.type == bfd_link_hash_defined);
    923  1.1.1.8  christos       h->root.u.def.section = def->root.u.def.section;
    924      1.1  christos       h->root.u.def.value = def->root.u.def.value;
    925      1.1  christos       return TRUE;
    926      1.1  christos     }
    927      1.1  christos 
    928      1.1  christos   /* This is a reference to a symbol defined by a dynamic object which
    929      1.1  christos      is not a function.  */
    930      1.1  christos 
    931      1.1  christos   /* If we are creating a shared library, we must presume that the
    932      1.1  christos      only references to the symbol are via the global offset table.
    933      1.1  christos      For such cases we need not do anything here; the relocations will
    934  1.1.1.6  christos      be handled correctly by relocate_section.  */
    935      1.1  christos   if (bfd_link_pic (info))
    936      1.1  christos     return TRUE;
    937  1.1.1.9  christos 
    938  1.1.1.9  christos   /* If there are no references to this symbol that do not use the
    939  1.1.1.9  christos      GOT relocation, we don't need to generate a copy reloc.  */
    940  1.1.1.9  christos   if (!h->non_got_ref)
    941  1.1.1.9  christos     return TRUE;
    942      1.1  christos 
    943      1.1  christos   /* We must allocate the symbol in our .dynbss section, which will
    944      1.1  christos      become part of the .bss section of the executable.  There will be
    945      1.1  christos      an entry for this symbol in the .dynsym section.  The dynamic
    946      1.1  christos      object will contain position independent code, so all references
    947      1.1  christos      from the dynamic object to this symbol will go through the global
    948      1.1  christos      offset table.  The dynamic linker will use the .dynsym entry to
    949      1.1  christos      determine the address it must put in the global offset table, so
    950      1.1  christos      both the dynamic object and the regular object will refer to the
    951      1.1  christos      same memory location for the variable.  */
    952  1.1.1.2  christos 
    953      1.1  christos   s = bfd_get_linker_section (dynobj, ".dynbss");
    954      1.1  christos   BFD_ASSERT (s != NULL);
    955      1.1  christos 
    956      1.1  christos   /* We must generate a R_VAX_COPY reloc to tell the dynamic linker to
    957      1.1  christos      copy the initial value out of the dynamic object and into the
    958      1.1  christos      runtime process image.  We need to remember the offset into the
    959  1.1.1.2  christos      .rela.bss section we are going to use.  */
    960      1.1  christos   if ((h->root.u.def.section->flags & SEC_ALLOC) != 0 && h->size != 0)
    961      1.1  christos     {
    962      1.1  christos       asection *srel;
    963  1.1.1.2  christos 
    964      1.1  christos       srel = bfd_get_linker_section (dynobj, ".rela.bss");
    965      1.1  christos       BFD_ASSERT (srel != NULL);
    966      1.1  christos       srel->size += sizeof (Elf32_External_Rela);
    967      1.1  christos       h->needs_copy = 1;
    968      1.1  christos     }
    969  1.1.1.4  christos 
    970      1.1  christos   return _bfd_elf_adjust_dynamic_copy (info, h, s);
    971      1.1  christos }
    972  1.1.1.3  christos 
    973  1.1.1.3  christos /* This function is called via elf_link_hash_traverse.  It resets GOT
    974  1.1.1.3  christos    and PLT (.GOT) reference counts back to -1 so normal PC32 relocation
    975  1.1.1.3  christos    will be done.  */
    976  1.1.1.3  christos 
    977  1.1.1.3  christos static bfd_boolean
    978  1.1.1.3  christos elf_vax_discard_got_entries (struct elf_link_hash_entry *h,
    979  1.1.1.3  christos 			     void *infoptr ATTRIBUTE_UNUSED)
    980  1.1.1.3  christos {
    981  1.1.1.3  christos   h->got.refcount = -1;
    982  1.1.1.3  christos   h->plt.refcount = -1;
    983  1.1.1.3  christos 
    984  1.1.1.3  christos   return TRUE;
    985  1.1.1.3  christos }
    986  1.1.1.3  christos 
    987  1.1.1.3  christos /* Discard unused dynamic data if this is a static link.  */
    988  1.1.1.3  christos 
    989  1.1.1.3  christos static bfd_boolean
    990  1.1.1.3  christos elf_vax_always_size_sections (bfd *output_bfd ATTRIBUTE_UNUSED,
    991  1.1.1.3  christos 			      struct bfd_link_info *info)
    992  1.1.1.3  christos {
    993  1.1.1.3  christos   bfd *dynobj;
    994  1.1.1.3  christos   asection *s;
    995  1.1.1.3  christos 
    996  1.1.1.3  christos   dynobj = elf_hash_table (info)->dynobj;
    997  1.1.1.3  christos 
    998  1.1.1.3  christos   if (dynobj && !elf_hash_table (info)->dynamic_sections_created)
    999  1.1.1.3  christos     {
   1000  1.1.1.3  christos       /* We may have created entries in the .rela.got and .got sections.
   1001  1.1.1.3  christos 	 However, if we are not creating the dynamic sections, we will
   1002  1.1.1.3  christos 	 not actually use these entries.  Reset the size of .rela.got
   1003  1.1.1.3  christos 	 and .got, which will cause them to get stripped from the output
   1004  1.1.1.7  christos 	 file below.  */
   1005  1.1.1.3  christos       s = elf_hash_table (info)->srelgot;
   1006  1.1.1.3  christos       if (s != NULL)
   1007  1.1.1.7  christos 	s->size = 0;
   1008  1.1.1.3  christos       s = elf_hash_table (info)->sgotplt;
   1009  1.1.1.3  christos       if (s != NULL)
   1010  1.1.1.7  christos 	s->size = 0;
   1011  1.1.1.3  christos       s = elf_hash_table (info)->sgot;
   1012  1.1.1.3  christos       if (s != NULL)
   1013  1.1.1.3  christos 	s->size = 0;
   1014  1.1.1.3  christos     }
   1015  1.1.1.3  christos 
   1016  1.1.1.3  christos   /* If this is a static link, we need to discard all the got entries we've
   1017  1.1.1.3  christos      recorded.  */
   1018  1.1.1.3  christos   if (!dynobj || !elf_hash_table (info)->dynamic_sections_created)
   1019  1.1.1.3  christos     elf_link_hash_traverse (elf_hash_table (info),
   1020  1.1.1.3  christos 			    elf_vax_discard_got_entries,
   1021  1.1.1.3  christos 			    info);
   1022  1.1.1.3  christos 
   1023  1.1.1.3  christos   return TRUE;
   1024  1.1.1.3  christos }
   1025      1.1  christos 
   1026      1.1  christos /* Set the sizes of the dynamic sections.  */
   1027      1.1  christos 
   1028      1.1  christos static bfd_boolean
   1029      1.1  christos elf_vax_size_dynamic_sections (bfd *output_bfd, struct bfd_link_info *info)
   1030      1.1  christos {
   1031      1.1  christos   bfd *dynobj;
   1032      1.1  christos   asection *s;
   1033      1.1  christos   bfd_boolean relocs;
   1034      1.1  christos 
   1035      1.1  christos   dynobj = elf_hash_table (info)->dynobj;
   1036      1.1  christos   BFD_ASSERT (dynobj != NULL);
   1037      1.1  christos 
   1038      1.1  christos   if (elf_hash_table (info)->dynamic_sections_created)
   1039      1.1  christos     {
   1040  1.1.1.6  christos       /* Set the contents of the .interp section to the interpreter.  */
   1041      1.1  christos       if (bfd_link_executable (info) && !info->nointerp)
   1042  1.1.1.2  christos 	{
   1043      1.1  christos 	  s = bfd_get_linker_section (dynobj, ".interp");
   1044      1.1  christos 	  BFD_ASSERT (s != NULL);
   1045      1.1  christos 	  s->size = sizeof ELF_DYNAMIC_INTERPRETER;
   1046      1.1  christos 	  s->contents = (unsigned char *) ELF_DYNAMIC_INTERPRETER;
   1047      1.1  christos 	}
   1048      1.1  christos     }
   1049      1.1  christos 
   1050      1.1  christos   /* If this is a -Bsymbolic shared link, then we need to discard all PC
   1051      1.1  christos      relative relocs against symbols defined in a regular object.  We
   1052      1.1  christos      allocated space for them in the check_relocs routine, but we will not
   1053  1.1.1.6  christos      fill them in in the relocate_section routine.  */
   1054      1.1  christos   if (bfd_link_pic (info) && info->symbolic)
   1055      1.1  christos     elf_vax_link_hash_traverse (elf_hash_table (info),
   1056      1.1  christos 				elf_vax_discard_copies,
   1057      1.1  christos 				NULL);
   1058  1.1.1.3  christos 
   1059  1.1.1.3  christos   /* If this is a -Bsymbolic shared link, we need to discard all the got
   1060  1.1.1.3  christos      entries we've recorded.  Otherwise, we need to instantiate (allocate
   1061      1.1  christos      space for them).  */
   1062      1.1  christos   elf_link_hash_traverse (elf_hash_table (info),
   1063  1.1.1.2  christos 			  elf_vax_instantiate_got_entries,
   1064      1.1  christos 			  info);
   1065      1.1  christos 
   1066      1.1  christos   /* The check_relocs and adjust_dynamic_symbol entry points have
   1067      1.1  christos      determined the sizes of the various dynamic sections.  Allocate
   1068      1.1  christos      memory for them.  */
   1069      1.1  christos   relocs = FALSE;
   1070      1.1  christos   for (s = dynobj->sections; s != NULL; s = s->next)
   1071      1.1  christos     {
   1072      1.1  christos       const char *name;
   1073      1.1  christos 
   1074      1.1  christos       if ((s->flags & SEC_LINKER_CREATED) == 0)
   1075      1.1  christos 	continue;
   1076      1.1  christos 
   1077      1.1  christos       /* It's OK to base decisions on the section name, because none
   1078  1.1.1.9  christos 	 of the dynobj section names depend upon the input files.  */
   1079      1.1  christos       name = bfd_section_name (s);
   1080      1.1  christos 
   1081      1.1  christos       if (strcmp (name, ".plt") == 0)
   1082      1.1  christos 	{
   1083  1.1.1.9  christos 	  /* Remember whether there is a PLT.  */
   1084      1.1  christos 	  ;
   1085      1.1  christos 	}
   1086      1.1  christos       else if (CONST_STRNEQ (name, ".rela"))
   1087      1.1  christos 	{
   1088      1.1  christos 	  if (s->size != 0)
   1089      1.1  christos 	    {
   1090  1.1.1.9  christos 	      if (strcmp (name, ".rela.plt") != 0)
   1091      1.1  christos 		relocs = TRUE;
   1092      1.1  christos 
   1093      1.1  christos 	      /* We use the reloc_count field as a counter if we need
   1094      1.1  christos 		 to copy relocs into the output file.  */
   1095      1.1  christos 	      s->reloc_count = 0;
   1096      1.1  christos 	    }
   1097      1.1  christos 	}
   1098      1.1  christos       else if (! CONST_STRNEQ (name, ".got")
   1099      1.1  christos 	       && strcmp (name, ".dynbss") != 0)
   1100      1.1  christos 	{
   1101      1.1  christos 	  /* It's not one of our sections, so don't allocate space.  */
   1102      1.1  christos 	  continue;
   1103      1.1  christos 	}
   1104      1.1  christos 
   1105      1.1  christos       if (s->size == 0)
   1106      1.1  christos 	{
   1107      1.1  christos 	  /* If we don't need this section, strip it from the
   1108      1.1  christos 	     output file.  This is mostly to handle .rela.bss and
   1109      1.1  christos 	     .rela.plt.  We must create both sections in
   1110      1.1  christos 	     create_dynamic_sections, because they must be created
   1111      1.1  christos 	     before the linker maps input sections to output
   1112      1.1  christos 	     sections.  The linker does that before
   1113      1.1  christos 	     adjust_dynamic_symbol is called, and it is that
   1114      1.1  christos 	     function which decides whether anything needs to go
   1115      1.1  christos 	     into these sections.  */
   1116      1.1  christos 	  s->flags |= SEC_EXCLUDE;
   1117      1.1  christos 	  continue;
   1118      1.1  christos 	}
   1119      1.1  christos 
   1120      1.1  christos       if ((s->flags & SEC_HAS_CONTENTS) == 0)
   1121      1.1  christos 	continue;
   1122      1.1  christos 
   1123  1.1.1.4  christos       /* Allocate memory for the section contents.  */
   1124      1.1  christos       s->contents = (bfd_byte *) bfd_zalloc (dynobj, s->size);
   1125      1.1  christos       if (s->contents == NULL)
   1126      1.1  christos 	return FALSE;
   1127      1.1  christos     }
   1128  1.1.1.9  christos 
   1129      1.1  christos   return _bfd_elf_add_dynamic_tags (output_bfd, info, relocs);
   1130      1.1  christos }
   1131      1.1  christos 
   1132      1.1  christos /* This function is called via elf_vax_link_hash_traverse if we are
   1133      1.1  christos    creating a shared object with -Bsymbolic.  It discards the space
   1134      1.1  christos    allocated to copy PC relative relocs against symbols which are defined
   1135      1.1  christos    in regular objects.  We allocated space for them in the check_relocs
   1136      1.1  christos    routine, but we won't fill them in in the relocate_section routine.  */
   1137      1.1  christos 
   1138      1.1  christos static bfd_boolean
   1139  1.1.1.2  christos elf_vax_discard_copies (struct elf_vax_link_hash_entry *h,
   1140      1.1  christos 			void * ignore ATTRIBUTE_UNUSED)
   1141      1.1  christos {
   1142      1.1  christos   struct elf_vax_pcrel_relocs_copied *s;
   1143      1.1  christos 
   1144      1.1  christos   /* We only discard relocs for symbols defined in a regular object.  */
   1145      1.1  christos   if (!h->root.def_regular)
   1146      1.1  christos     return TRUE;
   1147      1.1  christos 
   1148      1.1  christos   for (s = h->pcrel_relocs_copied; s != NULL; s = s->next)
   1149      1.1  christos     s->section->size -= s->count * sizeof (Elf32_External_Rela);
   1150      1.1  christos 
   1151      1.1  christos   return TRUE;
   1152      1.1  christos }
   1153  1.1.1.3  christos 
   1154  1.1.1.3  christos /* This function is called via elf_link_hash_traverse.  It looks for
   1155  1.1.1.3  christos    entries that have GOT or PLT (.GOT) references.  If creating a shared
   1156  1.1.1.3  christos    object with -Bsymbolic, or the symbol has been forced local, then it
   1157  1.1.1.3  christos    resets the reference count back to -1 so normal PC32 relocation will
   1158  1.1.1.3  christos    be done.  Otherwise space in the .got and .rela.got will be reserved
   1159      1.1  christos    for the symbol.  */
   1160      1.1  christos 
   1161  1.1.1.2  christos static bfd_boolean
   1162      1.1  christos elf_vax_instantiate_got_entries (struct elf_link_hash_entry *h, void * infoptr)
   1163      1.1  christos {
   1164      1.1  christos   struct bfd_link_info *info = (struct bfd_link_info *) infoptr;
   1165      1.1  christos   bfd *dynobj;
   1166      1.1  christos   asection *sgot;
   1167      1.1  christos   asection *srelgot;
   1168      1.1  christos 
   1169      1.1  christos   /* We don't care about non-GOT (and non-PLT) entries.  */
   1170      1.1  christos   if (h->got.refcount <= 0 && h->plt.refcount <= 0)
   1171      1.1  christos     return TRUE;
   1172      1.1  christos 
   1173  1.1.1.3  christos   dynobj = elf_hash_table (info)->dynobj;
   1174      1.1  christos   BFD_ASSERT (dynobj != NULL);
   1175  1.1.1.7  christos 
   1176  1.1.1.7  christos   sgot = elf_hash_table (info)->sgot;
   1177      1.1  christos   srelgot = elf_hash_table (info)->srelgot;
   1178  1.1.1.3  christos 
   1179      1.1  christos   if (SYMBOL_REFERENCES_LOCAL (info, h))
   1180  1.1.1.3  christos     {
   1181  1.1.1.3  christos       h->got.refcount = -1;
   1182      1.1  christos       h->plt.refcount = -1;
   1183      1.1  christos     }
   1184      1.1  christos   else if (h->got.refcount > 0)
   1185      1.1  christos     {
   1186      1.1  christos       /* Make sure this symbol is output as a dynamic symbol.  */
   1187      1.1  christos       if (h->dynindx == -1)
   1188      1.1  christos 	{
   1189      1.1  christos 	  if (!bfd_elf_link_record_dynamic_symbol (info, h))
   1190      1.1  christos 	    return FALSE;
   1191      1.1  christos 	}
   1192      1.1  christos 
   1193  1.1.1.3  christos       /* Allocate space in the .got and .rela.got sections.  */
   1194  1.1.1.3  christos       sgot->size += 4;
   1195      1.1  christos       srelgot->size += sizeof (Elf32_External_Rela);
   1196      1.1  christos     }
   1197      1.1  christos 
   1198      1.1  christos   return TRUE;
   1199      1.1  christos }
   1200      1.1  christos 
   1201      1.1  christos /* Relocate an VAX ELF section.  */
   1202      1.1  christos 
   1203      1.1  christos static bfd_boolean
   1204      1.1  christos elf_vax_relocate_section (bfd *output_bfd,
   1205      1.1  christos 			  struct bfd_link_info *info,
   1206      1.1  christos 			  bfd *input_bfd,
   1207      1.1  christos 			  asection *input_section,
   1208      1.1  christos 			  bfd_byte *contents,
   1209      1.1  christos 			  Elf_Internal_Rela *relocs,
   1210      1.1  christos 			  Elf_Internal_Sym *local_syms,
   1211      1.1  christos 			  asection **local_sections)
   1212      1.1  christos {
   1213      1.1  christos   Elf_Internal_Shdr *symtab_hdr;
   1214      1.1  christos   struct elf_link_hash_entry **sym_hashes;
   1215      1.1  christos   bfd_vma plt_index;
   1216      1.1  christos   bfd_vma got_offset;
   1217      1.1  christos   asection *sgot;
   1218      1.1  christos   asection *splt;
   1219      1.1  christos   asection *sgotplt;
   1220      1.1  christos   asection *sreloc;
   1221      1.1  christos   Elf_Internal_Rela *rel;
   1222      1.1  christos   Elf_Internal_Rela *relend;
   1223      1.1  christos 
   1224      1.1  christos   symtab_hdr = &elf_tdata (input_bfd)->symtab_hdr;
   1225      1.1  christos   sym_hashes = elf_sym_hashes (input_bfd);
   1226      1.1  christos 
   1227      1.1  christos   sgot = NULL;
   1228      1.1  christos   splt = NULL;
   1229      1.1  christos   sgotplt = NULL;
   1230      1.1  christos   sreloc = NULL;
   1231      1.1  christos 
   1232      1.1  christos   rel = relocs;
   1233      1.1  christos   relend = relocs + input_section->reloc_count;
   1234      1.1  christos   for (; rel < relend; rel++)
   1235      1.1  christos     {
   1236      1.1  christos       int r_type;
   1237      1.1  christos       reloc_howto_type *howto;
   1238      1.1  christos       unsigned long r_symndx;
   1239      1.1  christos       struct elf_link_hash_entry *h;
   1240      1.1  christos       Elf_Internal_Sym *sym;
   1241      1.1  christos       asection *sec;
   1242      1.1  christos       bfd_vma relocation;
   1243      1.1  christos       bfd_reloc_status_type r;
   1244      1.1  christos 
   1245      1.1  christos       r_type = ELF32_R_TYPE (rel->r_info);
   1246      1.1  christos       if (r_type < 0 || r_type >= (int) R_VAX_max)
   1247      1.1  christos 	{
   1248      1.1  christos 	  bfd_set_error (bfd_error_bad_value);
   1249      1.1  christos 	  return FALSE;
   1250      1.1  christos 	}
   1251      1.1  christos       howto = howto_table + r_type;
   1252      1.1  christos 
   1253      1.1  christos       r_symndx = ELF32_R_SYM (rel->r_info);
   1254      1.1  christos       h = NULL;
   1255      1.1  christos       sym = NULL;
   1256      1.1  christos       sec = NULL;
   1257      1.1  christos       if (r_symndx < symtab_hdr->sh_info)
   1258      1.1  christos 	{
   1259      1.1  christos 	  sym = local_syms + r_symndx;
   1260      1.1  christos 	  sec = local_sections[r_symndx];
   1261      1.1  christos 	  relocation = _bfd_elf_rela_local_sym (output_bfd, sym, &sec, rel);
   1262      1.1  christos 	}
   1263      1.1  christos       else
   1264      1.1  christos 	{
   1265  1.1.1.3  christos 	  bfd_boolean unresolved_reloc;
   1266      1.1  christos 	  bfd_boolean warned, ignored;
   1267      1.1  christos 
   1268      1.1  christos 	  RELOC_FOR_GLOBAL_SYMBOL (info, input_bfd, input_section, rel,
   1269      1.1  christos 				   r_symndx, symtab_hdr, sym_hashes,
   1270  1.1.1.3  christos 				   h, sec, relocation,
   1271      1.1  christos 				   unresolved_reloc, warned, ignored);
   1272      1.1  christos 
   1273      1.1  christos 	  if ((h->root.type == bfd_link_hash_defined
   1274      1.1  christos 	      || h->root.type == bfd_link_hash_defweak)
   1275      1.1  christos 	      && ((r_type == R_VAX_PLT32
   1276      1.1  christos 		   && h->plt.offset != (bfd_vma) -1
   1277      1.1  christos 		   && !h->forced_local
   1278      1.1  christos 		   && elf_hash_table (info)->dynamic_sections_created)
   1279      1.1  christos 		  || (r_type == R_VAX_GOT32
   1280      1.1  christos 		      && h->got.offset != (bfd_vma) -1
   1281      1.1  christos 		      && !h->forced_local
   1282  1.1.1.6  christos 		      && elf_hash_table (info)->dynamic_sections_created
   1283      1.1  christos 		      && (! bfd_link_pic (info)
   1284      1.1  christos 			  || (! info->symbolic && h->dynindx != -1)
   1285  1.1.1.6  christos 			  || !h->def_regular))
   1286      1.1  christos 		  || (bfd_link_pic (info)
   1287      1.1  christos 		      && ((! info->symbolic && h->dynindx != -1)
   1288      1.1  christos 			  || !h->def_regular)
   1289      1.1  christos 		      && ((input_section->flags & SEC_ALLOC) != 0
   1290      1.1  christos 			  /* DWARF will emit R_VAX_32 relocations in its
   1291      1.1  christos 			     sections against symbols defined externally
   1292      1.1  christos 			     in shared libraries.  We can't do anything
   1293      1.1  christos 			     with them here.  */
   1294      1.1  christos 
   1295      1.1  christos 			  || ((input_section->flags & SEC_DEBUGGING) != 0
   1296      1.1  christos 			      && h->def_dynamic))
   1297      1.1  christos 		      && (r_type == R_VAX_8
   1298      1.1  christos 			  || r_type == R_VAX_16
   1299      1.1  christos 			  || r_type == R_VAX_32))))
   1300      1.1  christos 	    /* In these cases, we don't need the relocation
   1301      1.1  christos 	       value.  We check specially because in some
   1302      1.1  christos 	       obscure cases sec->output_section will be NULL.  */
   1303      1.1  christos 	    relocation = 0;
   1304      1.1  christos 	}
   1305  1.1.1.2  christos 
   1306      1.1  christos       if (sec != NULL && discarded_section (sec))
   1307  1.1.1.2  christos 	RELOC_AGAINST_DISCARDED_SECTION (info, input_bfd, input_section,
   1308      1.1  christos 					 rel, 1, relend, howto, 0, contents);
   1309  1.1.1.6  christos 
   1310      1.1  christos       if (bfd_link_relocatable (info))
   1311      1.1  christos 	continue;
   1312      1.1  christos 
   1313      1.1  christos       switch (r_type)
   1314      1.1  christos 	{
   1315      1.1  christos 	case R_VAX_GOT32:
   1316      1.1  christos 	  /* Relocation is to the address of the entry for this symbol
   1317  1.1.1.3  christos 	     in the global offset table.  */
   1318  1.1.1.3  christos 
   1319  1.1.1.3  christos 	  /* Resolve a GOTxx reloc against a local symbol directly,
   1320      1.1  christos 	     without using the global offset table.  */
   1321  1.1.1.3  christos 	  if (h == NULL
   1322      1.1  christos 	      || h->got.offset == (bfd_vma) -1)
   1323      1.1  christos 	    break;
   1324      1.1  christos 
   1325      1.1  christos 	  {
   1326      1.1  christos 	    bfd_vma off;
   1327  1.1.1.7  christos 
   1328  1.1.1.7  christos 	    sgot = elf_hash_table (info)->sgot;
   1329      1.1  christos 	    BFD_ASSERT (sgot != NULL);
   1330      1.1  christos 
   1331      1.1  christos 	    off = h->got.offset;
   1332      1.1  christos 	    BFD_ASSERT (off < sgot->size);
   1333  1.1.1.3  christos 
   1334      1.1  christos 	    bfd_put_32 (output_bfd, rel->r_addend, sgot->contents + off);
   1335      1.1  christos 
   1336      1.1  christos 	    relocation = sgot->output_offset + off;
   1337      1.1  christos 	    /* The GOT relocation uses the addend.  */
   1338      1.1  christos 	    rel->r_addend = 0;
   1339      1.1  christos 
   1340      1.1  christos 	    /* Change the reference to be indirect.  */
   1341      1.1  christos 	    contents[rel->r_offset - 1] |= 0x10;
   1342      1.1  christos 	    relocation += sgot->output_section->vma;
   1343      1.1  christos 	  }
   1344      1.1  christos 	  break;
   1345      1.1  christos 
   1346      1.1  christos 	case R_VAX_PC32:
   1347      1.1  christos 	  /* If we are creating an executable and the function this
   1348      1.1  christos 	     reloc refers to is in a shared lib, then we made a PLT
   1349      1.1  christos 	     entry for this symbol and need to handle the reloc like
   1350  1.1.1.6  christos 	     a PLT reloc.  */
   1351      1.1  christos 	  if (bfd_link_pic (info))
   1352      1.1  christos 	     goto r_vax_pc32_shared;
   1353      1.1  christos 	  /* Fall through.  */
   1354      1.1  christos 	case R_VAX_PLT32:
   1355      1.1  christos 	  /* Relocation is to the entry for this symbol in the
   1356      1.1  christos 	     procedure linkage table.  */
   1357      1.1  christos 
   1358      1.1  christos 	  /* Resolve a PLTxx reloc against a local symbol directly,
   1359      1.1  christos 	     without using the procedure linkage table.  */
   1360  1.1.1.3  christos 	  if (h == NULL
   1361      1.1  christos 	      || h->plt.offset == (bfd_vma) -1)
   1362      1.1  christos 	    break;
   1363  1.1.1.7  christos 
   1364  1.1.1.7  christos 	  splt = elf_hash_table (info)->splt;
   1365      1.1  christos 	  BFD_ASSERT (splt != NULL);
   1366  1.1.1.7  christos 
   1367  1.1.1.7  christos 	  sgotplt = elf_hash_table (info)->sgotplt;
   1368      1.1  christos 	  BFD_ASSERT (sgotplt != NULL);
   1369      1.1  christos 
   1370      1.1  christos 	  plt_index = h->plt.offset / PLT_ENTRY_SIZE - 1;
   1371      1.1  christos 
   1372      1.1  christos 	  /* Get the offset into the .got table of the entry that
   1373      1.1  christos 	     corresponds to this function.  Each .got entry is 4 bytes.
   1374      1.1  christos 	     The first two are reserved.  */
   1375      1.1  christos 	  got_offset = (plt_index + 3) * 4;
   1376      1.1  christos 
   1377      1.1  christos 	  /* We want the relocation to point into the .got.plt instead
   1378      1.1  christos 	     of the plt itself.  */
   1379      1.1  christos 	  relocation = (sgotplt->output_section->vma
   1380      1.1  christos 			+ sgotplt->output_offset
   1381      1.1  christos 			+ got_offset);
   1382      1.1  christos 	  contents[rel->r_offset-1] |= 0x10; /* make indirect */
   1383      1.1  christos 	  if (rel->r_addend == 2)
   1384      1.1  christos 	    {
   1385      1.1  christos 	      h->plt.offset |= 1;
   1386      1.1  christos 	    }
   1387  1.1.1.7  christos 	  else if (rel->r_addend != 0)
   1388  1.1.1.7  christos 	    _bfd_error_handler
   1389  1.1.1.8  christos 	      /* xgettext:c-format */
   1390  1.1.1.8  christos 	      (_("%pB: warning: PLT addend of %" PRId64 " to `%s'"
   1391  1.1.1.8  christos 		 " from %pA section ignored"),
   1392  1.1.1.8  christos 	       input_bfd, (int64_t) rel->r_addend, h->root.root.string,
   1393      1.1  christos 	       input_section);
   1394      1.1  christos 	  rel->r_addend = 0;
   1395      1.1  christos 
   1396      1.1  christos 	  break;
   1397      1.1  christos 
   1398      1.1  christos 	case R_VAX_PC8:
   1399      1.1  christos 	case R_VAX_PC16:
   1400      1.1  christos 	r_vax_pc32_shared:
   1401      1.1  christos 	  if (h == NULL
   1402      1.1  christos 	      || ELF_ST_VISIBILITY (h->other) != STV_DEFAULT
   1403      1.1  christos 	      || h->forced_local)
   1404      1.1  christos 	    break;
   1405      1.1  christos 	  /* Fall through.  */
   1406      1.1  christos 	case R_VAX_8:
   1407      1.1  christos 	case R_VAX_16:
   1408  1.1.1.6  christos 	case R_VAX_32:
   1409      1.1  christos 	  if (bfd_link_pic (info)
   1410      1.1  christos 	      && r_symndx != STN_UNDEF
   1411      1.1  christos 	      && (input_section->flags & SEC_ALLOC) != 0
   1412      1.1  christos 	      && ((r_type != R_VAX_PC8
   1413      1.1  christos 		   && r_type != R_VAX_PC16
   1414      1.1  christos 		   && r_type != R_VAX_PC32)
   1415      1.1  christos 		  || ((input_section->flags & SEC_CODE)
   1416      1.1  christos 		      && (!info->symbolic
   1417      1.1  christos 			  || (!h->def_regular && h->type != STT_SECTION)))))
   1418      1.1  christos 	    {
   1419      1.1  christos 	      Elf_Internal_Rela outrel;
   1420      1.1  christos 	      bfd_byte *loc;
   1421      1.1  christos 	      bfd_boolean skip, relocate;
   1422      1.1  christos 
   1423      1.1  christos 	      /* When generating a shared object, these relocations
   1424      1.1  christos 		 are copied into the output file to be resolved at run
   1425      1.1  christos 		 time.  */
   1426      1.1  christos 	      if (sreloc == NULL)
   1427      1.1  christos 		{
   1428      1.1  christos 		  sreloc = _bfd_elf_get_dynamic_reloc_section
   1429      1.1  christos 		    (input_bfd, input_section, /*rela?*/ TRUE);
   1430      1.1  christos 		  if (sreloc == NULL)
   1431      1.1  christos 		    return FALSE;
   1432      1.1  christos 		}
   1433      1.1  christos 
   1434      1.1  christos 	      skip = FALSE;
   1435      1.1  christos 	      relocate = FALSE;
   1436      1.1  christos 
   1437      1.1  christos 	      outrel.r_offset =
   1438      1.1  christos 		_bfd_elf_section_offset (output_bfd, info, input_section,
   1439      1.1  christos 					 rel->r_offset);
   1440      1.1  christos 	      if (outrel.r_offset == (bfd_vma) -1)
   1441      1.1  christos 		skip = TRUE;
   1442      1.1  christos 	      if (outrel.r_offset == (bfd_vma) -2)
   1443      1.1  christos 		skip = TRUE, relocate = TRUE;
   1444      1.1  christos 	      outrel.r_offset += (input_section->output_section->vma
   1445      1.1  christos 				  + input_section->output_offset);
   1446      1.1  christos 
   1447      1.1  christos 	      if (skip)
   1448      1.1  christos 		  memset (&outrel, 0, sizeof outrel);
   1449  1.1.1.8  christos 	      /* h->dynindx may be -1 if the symbol was marked to
   1450      1.1  christos 		 become local.  */
   1451      1.1  christos 	      else if (h != NULL
   1452      1.1  christos 		       && ((! info->symbolic && h->dynindx != -1)
   1453      1.1  christos 			   || !h->def_regular))
   1454      1.1  christos 		{
   1455      1.1  christos 		  BFD_ASSERT (h->dynindx != -1);
   1456      1.1  christos 		  outrel.r_info = ELF32_R_INFO (h->dynindx, r_type);
   1457      1.1  christos 		  outrel.r_addend = relocation + rel->r_addend;
   1458      1.1  christos 		}
   1459      1.1  christos 	      else
   1460      1.1  christos 		{
   1461      1.1  christos 		  if (r_type == R_VAX_32)
   1462      1.1  christos 		    {
   1463      1.1  christos 		      relocate = TRUE;
   1464      1.1  christos 		      outrel.r_info = ELF32_R_INFO (0, R_VAX_RELATIVE);
   1465      1.1  christos 		      BFD_ASSERT (bfd_get_signed_32 (input_bfd,
   1466      1.1  christos 						     &contents[rel->r_offset]) == 0);
   1467      1.1  christos 		      outrel.r_addend = relocation + rel->r_addend;
   1468      1.1  christos 		    }
   1469      1.1  christos 		  else
   1470      1.1  christos 		    {
   1471      1.1  christos 		      long indx;
   1472      1.1  christos 
   1473      1.1  christos 		      if (bfd_is_abs_section (sec))
   1474      1.1  christos 			indx = 0;
   1475      1.1  christos 		      else if (sec == NULL || sec->owner == NULL)
   1476      1.1  christos 			{
   1477      1.1  christos 			  bfd_set_error (bfd_error_bad_value);
   1478      1.1  christos 			  return FALSE;
   1479      1.1  christos 			}
   1480      1.1  christos 		      else
   1481      1.1  christos 			{
   1482      1.1  christos 			  asection *osec;
   1483      1.1  christos 
   1484      1.1  christos 			  /* We are turning this relocation into one
   1485      1.1  christos 			     against a section symbol.  It would be
   1486      1.1  christos 			     proper to subtract the symbol's value,
   1487      1.1  christos 			     osec->vma, from the emitted reloc addend,
   1488      1.1  christos 			     but ld.so expects buggy relocs.  */
   1489      1.1  christos 			  osec = sec->output_section;
   1490      1.1  christos 			  indx = elf_section_data (osec)->dynindx;
   1491      1.1  christos 			  if (indx == 0)
   1492      1.1  christos 			    {
   1493      1.1  christos 			      struct elf_link_hash_table *htab;
   1494      1.1  christos 			      htab = elf_hash_table (info);
   1495      1.1  christos 			      osec = htab->text_index_section;
   1496      1.1  christos 			      indx = elf_section_data (osec)->dynindx;
   1497      1.1  christos 			    }
   1498      1.1  christos 			  BFD_ASSERT (indx != 0);
   1499      1.1  christos 			}
   1500      1.1  christos 
   1501      1.1  christos 		      outrel.r_info = ELF32_R_INFO (indx, r_type);
   1502      1.1  christos 		      outrel.r_addend = relocation + rel->r_addend;
   1503      1.1  christos 		    }
   1504      1.1  christos 		}
   1505  1.1.1.2  christos 
   1506  1.1.1.2  christos 	      if ((input_section->flags & SEC_CODE) != 0
   1507  1.1.1.2  christos 		  || (ELF32_R_TYPE (outrel.r_info) != R_VAX_32
   1508  1.1.1.2  christos 		      && ELF32_R_TYPE (outrel.r_info) != R_VAX_RELATIVE
   1509  1.1.1.2  christos 		      && ELF32_R_TYPE (outrel.r_info) != R_VAX_COPY
   1510  1.1.1.2  christos 		      && ELF32_R_TYPE (outrel.r_info) != R_VAX_JMP_SLOT
   1511      1.1  christos 		      && ELF32_R_TYPE (outrel.r_info) != R_VAX_GLOB_DAT))
   1512      1.1  christos 		{
   1513  1.1.1.7  christos 		  if (h != NULL)
   1514  1.1.1.7  christos 		    _bfd_error_handler
   1515  1.1.1.8  christos 		      /* xgettext:c-format */
   1516  1.1.1.8  christos 		      (_("%pB: warning: %s relocation against symbol `%s'"
   1517  1.1.1.7  christos 			 " from %pA section"),
   1518  1.1.1.7  christos 		      input_bfd, howto->name, h->root.root.string,
   1519      1.1  christos 		      input_section);
   1520  1.1.1.7  christos 		  else
   1521  1.1.1.7  christos 		    _bfd_error_handler
   1522  1.1.1.8  christos 		      /* xgettext:c-format */
   1523  1.1.1.8  christos 		      (_("%pB: warning: %s relocation to %#" PRIx64
   1524  1.1.1.8  christos 			 " from %pA section"),
   1525  1.1.1.7  christos 		      input_bfd, howto->name, (uint64_t) outrel.r_addend,
   1526      1.1  christos 		      input_section);
   1527      1.1  christos 		}
   1528      1.1  christos 	      loc = sreloc->contents;
   1529      1.1  christos 	      loc += sreloc->reloc_count++ * sizeof (Elf32_External_Rela);
   1530      1.1  christos 	      bfd_elf32_swap_reloca_out (output_bfd, &outrel, loc);
   1531      1.1  christos 
   1532  1.1.1.8  christos 	      /* This reloc will be computed at runtime, so there's no
   1533  1.1.1.8  christos 		 need to do anything now, except for R_VAX_32
   1534  1.1.1.8  christos 		 relocations that have been turned into
   1535      1.1  christos 		 R_VAX_RELATIVE.  */
   1536      1.1  christos 	      if (!relocate)
   1537      1.1  christos 		continue;
   1538      1.1  christos 	    }
   1539      1.1  christos 
   1540      1.1  christos 	  break;
   1541      1.1  christos 
   1542      1.1  christos 	case R_VAX_GNU_VTINHERIT:
   1543      1.1  christos 	case R_VAX_GNU_VTENTRY:
   1544      1.1  christos 	  /* These are no-ops in the end.  */
   1545      1.1  christos 	  continue;
   1546      1.1  christos 
   1547      1.1  christos 	default:
   1548      1.1  christos 	  break;
   1549      1.1  christos 	}
   1550      1.1  christos 
   1551  1.1.1.8  christos       /* VAX PCREL relocations are from the end of relocation, not the start.
   1552  1.1.1.8  christos 	 So subtract the difference from the relocation amount since we can't
   1553      1.1  christos 	 add it to the offset.  */
   1554      1.1  christos       if (howto->pc_relative && howto->pcrel_offset)
   1555      1.1  christos 	relocation -= bfd_get_reloc_size(howto);
   1556      1.1  christos 
   1557      1.1  christos       r = _bfd_final_link_relocate (howto, input_bfd, input_section,
   1558      1.1  christos 				    contents, rel->r_offset,
   1559      1.1  christos 				    relocation, rel->r_addend);
   1560      1.1  christos 
   1561      1.1  christos       if (r != bfd_reloc_ok)
   1562      1.1  christos 	{
   1563      1.1  christos 	  switch (r)
   1564      1.1  christos 	    {
   1565      1.1  christos 	    default:
   1566      1.1  christos 	    case bfd_reloc_outofrange:
   1567      1.1  christos 	      abort ();
   1568      1.1  christos 	    case bfd_reloc_overflow:
   1569      1.1  christos 	      {
   1570      1.1  christos 		const char *name;
   1571      1.1  christos 
   1572      1.1  christos 		if (h != NULL)
   1573      1.1  christos 		  name = NULL;
   1574      1.1  christos 		else
   1575      1.1  christos 		  {
   1576      1.1  christos 		    name = bfd_elf_string_from_elf_section (input_bfd,
   1577      1.1  christos 							    symtab_hdr->sh_link,
   1578      1.1  christos 							    sym->st_name);
   1579      1.1  christos 		    if (name == NULL)
   1580      1.1  christos 		      return FALSE;
   1581  1.1.1.9  christos 		    if (*name == '\0')
   1582      1.1  christos 		      name = bfd_section_name (sec);
   1583  1.1.1.6  christos 		  }
   1584  1.1.1.6  christos 		info->callbacks->reloc_overflow
   1585  1.1.1.6  christos 		  (info, (h ? &h->root : NULL), name, howto->name,
   1586      1.1  christos 		   (bfd_vma) 0, input_bfd, input_section, rel->r_offset);
   1587      1.1  christos 	      }
   1588      1.1  christos 	      break;
   1589      1.1  christos 	    }
   1590      1.1  christos 	}
   1591      1.1  christos     }
   1592      1.1  christos 
   1593      1.1  christos   return TRUE;
   1594      1.1  christos }
   1595      1.1  christos 
   1596      1.1  christos /* Finish up dynamic symbol handling.  We set the contents of various
   1597      1.1  christos    dynamic sections here.  */
   1598      1.1  christos 
   1599      1.1  christos static bfd_boolean
   1600      1.1  christos elf_vax_finish_dynamic_symbol (bfd *output_bfd, struct bfd_link_info *info,
   1601      1.1  christos 			       struct elf_link_hash_entry *h,
   1602      1.1  christos 			       Elf_Internal_Sym *sym)
   1603      1.1  christos {
   1604      1.1  christos   bfd *dynobj;
   1605      1.1  christos 
   1606      1.1  christos   dynobj = elf_hash_table (info)->dynobj;
   1607      1.1  christos 
   1608      1.1  christos   if (h->plt.offset != (bfd_vma) -1)
   1609      1.1  christos     {
   1610      1.1  christos       asection *splt;
   1611      1.1  christos       asection *sgot;
   1612      1.1  christos       asection *srela;
   1613      1.1  christos       bfd_vma plt_index;
   1614      1.1  christos       bfd_vma got_offset;
   1615      1.1  christos       bfd_vma addend;
   1616      1.1  christos       Elf_Internal_Rela rela;
   1617      1.1  christos       bfd_byte *loc;
   1618      1.1  christos 
   1619      1.1  christos       /* This symbol has an entry in the procedure linkage table.  Set
   1620      1.1  christos 	 it up.  */
   1621      1.1  christos       BFD_ASSERT (h->dynindx != -1);
   1622  1.1.1.7  christos 
   1623  1.1.1.7  christos       splt = elf_hash_table (info)->splt;
   1624  1.1.1.7  christos       sgot = elf_hash_table (info)->sgotplt;
   1625      1.1  christos       srela = elf_hash_table (info)->srelplt;
   1626      1.1  christos       BFD_ASSERT (splt != NULL && sgot != NULL && srela != NULL);
   1627      1.1  christos 
   1628      1.1  christos       addend = 2 * (h->plt.offset & 1);
   1629      1.1  christos       h->plt.offset &= ~1;
   1630      1.1  christos 
   1631      1.1  christos       /* Get the index in the procedure linkage table which
   1632      1.1  christos 	 corresponds to this symbol.  This is the index of this symbol
   1633      1.1  christos 	 in all the symbols for which we are making plt entries.  The
   1634      1.1  christos 	 first entry in the procedure linkage table is reserved.  */
   1635      1.1  christos       plt_index = h->plt.offset / PLT_ENTRY_SIZE - 1;
   1636      1.1  christos 
   1637      1.1  christos       /* Get the offset into the .got table of the entry that
   1638      1.1  christos 	 corresponds to this function.  Each .got entry is 4 bytes.
   1639      1.1  christos 	 The first two are reserved.  */
   1640      1.1  christos       got_offset = (plt_index + 3) * 4;
   1641      1.1  christos 
   1642      1.1  christos       /* Fill in the entry in the procedure linkage table.  */
   1643  1.1.1.8  christos       memcpy (splt->contents + h->plt.offset, elf_vax_plt_entry,
   1644      1.1  christos 		  PLT_ENTRY_SIZE);
   1645      1.1  christos 
   1646      1.1  christos       /* The offset is relative to the first extension word.  */
   1647      1.1  christos       bfd_put_32 (output_bfd,
   1648      1.1  christos 		  -(h->plt.offset + 8),
   1649      1.1  christos 		  splt->contents + h->plt.offset + 4);
   1650      1.1  christos 
   1651      1.1  christos       bfd_put_32 (output_bfd, plt_index * sizeof (Elf32_External_Rela),
   1652      1.1  christos 		  splt->contents + h->plt.offset + 8);
   1653      1.1  christos 
   1654      1.1  christos       /* Fill in the entry in the global offset table.  */
   1655      1.1  christos       bfd_put_32 (output_bfd,
   1656      1.1  christos 		  (splt->output_section->vma
   1657      1.1  christos 		   + splt->output_offset
   1658      1.1  christos 		   + h->plt.offset) + addend,
   1659      1.1  christos 		  sgot->contents + got_offset);
   1660      1.1  christos 
   1661      1.1  christos       /* Fill in the entry in the .rela.plt section.  */
   1662      1.1  christos       rela.r_offset = (sgot->output_section->vma
   1663      1.1  christos 		       + sgot->output_offset
   1664      1.1  christos 		       + got_offset);
   1665      1.1  christos       rela.r_info = ELF32_R_INFO (h->dynindx, R_VAX_JMP_SLOT);
   1666      1.1  christos       rela.r_addend = addend;
   1667      1.1  christos       loc = srela->contents + plt_index * sizeof (Elf32_External_Rela);
   1668      1.1  christos       bfd_elf32_swap_reloca_out (output_bfd, &rela, loc);
   1669      1.1  christos 
   1670      1.1  christos       if (!h->def_regular)
   1671      1.1  christos 	{
   1672      1.1  christos 	  /* Mark the symbol as undefined, rather than as defined in
   1673      1.1  christos 	     the .plt section.  Leave the value alone.  */
   1674      1.1  christos 	  sym->st_shndx = SHN_UNDEF;
   1675      1.1  christos 	}
   1676      1.1  christos     }
   1677      1.1  christos 
   1678      1.1  christos   if (h->got.offset != (bfd_vma) -1)
   1679      1.1  christos     {
   1680      1.1  christos       asection *sgot;
   1681      1.1  christos       asection *srela;
   1682      1.1  christos       Elf_Internal_Rela rela;
   1683      1.1  christos       bfd_byte *loc;
   1684      1.1  christos 
   1685      1.1  christos       /* This symbol has an entry in the global offset table.  Set it
   1686  1.1.1.7  christos 	 up.  */
   1687  1.1.1.7  christos       sgot = elf_hash_table (info)->sgot;
   1688      1.1  christos       srela = elf_hash_table (info)->srelgot;
   1689      1.1  christos       BFD_ASSERT (sgot != NULL && srela != NULL);
   1690      1.1  christos 
   1691      1.1  christos       rela.r_offset = (sgot->output_section->vma
   1692  1.1.1.3  christos 		       + sgot->output_offset
   1693  1.1.1.3  christos 		       + h->got.offset);
   1694      1.1  christos       rela.r_info = ELF32_R_INFO (h->dynindx, R_VAX_GLOB_DAT);
   1695  1.1.1.3  christos       rela.r_addend = bfd_get_signed_32 (output_bfd,
   1696      1.1  christos 					 sgot->contents + h->got.offset);
   1697      1.1  christos 
   1698      1.1  christos       loc = srela->contents;
   1699      1.1  christos       loc += srela->reloc_count++ * sizeof (Elf32_External_Rela);
   1700      1.1  christos       bfd_elf32_swap_reloca_out (output_bfd, &rela, loc);
   1701      1.1  christos     }
   1702      1.1  christos 
   1703      1.1  christos   if (h->needs_copy)
   1704      1.1  christos     {
   1705      1.1  christos       asection *s;
   1706      1.1  christos       Elf_Internal_Rela rela;
   1707      1.1  christos       bfd_byte *loc;
   1708      1.1  christos 
   1709      1.1  christos       /* This symbol needs a copy reloc.  Set it up.  */
   1710      1.1  christos       BFD_ASSERT (h->dynindx != -1
   1711      1.1  christos 		  && (h->root.type == bfd_link_hash_defined
   1712      1.1  christos 		      || h->root.type == bfd_link_hash_defweak));
   1713  1.1.1.2  christos 
   1714      1.1  christos       s = bfd_get_linker_section (dynobj, ".rela.bss");
   1715      1.1  christos       BFD_ASSERT (s != NULL);
   1716      1.1  christos 
   1717      1.1  christos       rela.r_offset = (h->root.u.def.value
   1718      1.1  christos 		       + h->root.u.def.section->output_section->vma
   1719      1.1  christos 		       + h->root.u.def.section->output_offset);
   1720      1.1  christos       rela.r_info = ELF32_R_INFO (h->dynindx, R_VAX_COPY);
   1721      1.1  christos       rela.r_addend = 0;
   1722      1.1  christos       loc = s->contents + s->reloc_count++ * sizeof (Elf32_External_Rela);
   1723      1.1  christos       bfd_elf32_swap_reloca_out (output_bfd, &rela, loc);
   1724      1.1  christos     }
   1725      1.1  christos 
   1726  1.1.1.2  christos   /* Mark _DYNAMIC and _GLOBAL_OFFSET_TABLE_ as absolute.  */
   1727      1.1  christos   if (h == elf_hash_table (info)->hdynamic
   1728      1.1  christos       || h == elf_hash_table (info)->hgot)
   1729      1.1  christos     sym->st_shndx = SHN_ABS;
   1730      1.1  christos 
   1731      1.1  christos   return TRUE;
   1732      1.1  christos }
   1733      1.1  christos 
   1734      1.1  christos /* Finish up the dynamic sections.  */
   1735      1.1  christos 
   1736      1.1  christos static bfd_boolean
   1737      1.1  christos elf_vax_finish_dynamic_sections (bfd *output_bfd, struct bfd_link_info *info)
   1738      1.1  christos {
   1739      1.1  christos   bfd *dynobj;
   1740      1.1  christos   asection *sgot;
   1741      1.1  christos   asection *sdyn;
   1742      1.1  christos 
   1743      1.1  christos   dynobj = elf_hash_table (info)->dynobj;
   1744  1.1.1.7  christos 
   1745      1.1  christos   sgot = elf_hash_table (info)->sgotplt;
   1746  1.1.1.2  christos   BFD_ASSERT (sgot != NULL);
   1747      1.1  christos   sdyn = bfd_get_linker_section (dynobj, ".dynamic");
   1748      1.1  christos 
   1749      1.1  christos   if (elf_hash_table (info)->dynamic_sections_created)
   1750      1.1  christos     {
   1751      1.1  christos       asection *splt;
   1752      1.1  christos       Elf32_External_Dyn *dyncon, *dynconend;
   1753  1.1.1.7  christos 
   1754      1.1  christos       splt = elf_hash_table (info)->splt;
   1755      1.1  christos       BFD_ASSERT (splt != NULL && sdyn != NULL);
   1756      1.1  christos 
   1757      1.1  christos       dyncon = (Elf32_External_Dyn *) sdyn->contents;
   1758      1.1  christos       dynconend = (Elf32_External_Dyn *) (sdyn->contents + sdyn->size);
   1759      1.1  christos       for (; dyncon < dynconend; dyncon++)
   1760      1.1  christos 	{
   1761      1.1  christos 	  Elf_Internal_Dyn dyn;
   1762      1.1  christos 	  asection *s;
   1763      1.1  christos 
   1764      1.1  christos 	  bfd_elf32_swap_dyn_in (dynobj, dyncon, &dyn);
   1765      1.1  christos 
   1766      1.1  christos 	  switch (dyn.d_tag)
   1767      1.1  christos 	    {
   1768      1.1  christos 	    default:
   1769      1.1  christos 	      break;
   1770      1.1  christos 
   1771  1.1.1.7  christos 	    case DT_PLTGOT:
   1772      1.1  christos 	      s = elf_hash_table (info)->sgotplt;
   1773      1.1  christos 	      goto get_vma;
   1774  1.1.1.7  christos 	    case DT_JMPREL:
   1775      1.1  christos 	      s = elf_hash_table (info)->srelplt;
   1776  1.1.1.6  christos 	    get_vma:
   1777      1.1  christos 	      dyn.d_un.d_ptr = s->output_section->vma + s->output_offset;
   1778      1.1  christos 	      bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon);
   1779      1.1  christos 	      break;
   1780      1.1  christos 
   1781  1.1.1.7  christos 	    case DT_PLTRELSZ:
   1782      1.1  christos 	      s = elf_hash_table (info)->srelplt;
   1783      1.1  christos 	      dyn.d_un.d_val = s->size;
   1784      1.1  christos 	      bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon);
   1785      1.1  christos 	      break;
   1786      1.1  christos 	    }
   1787      1.1  christos 	}
   1788      1.1  christos 
   1789      1.1  christos       /* Fill in the first entry in the procedure linkage table.  */
   1790      1.1  christos       if (splt->size > 0)
   1791      1.1  christos 	{
   1792      1.1  christos 	  memcpy (splt->contents, elf_vax_plt0_entry, PLT_ENTRY_SIZE);
   1793  1.1.1.8  christos 	  bfd_put_32 (output_bfd,
   1794  1.1.1.8  christos 			  (sgot->output_section->vma
   1795  1.1.1.8  christos 			   + sgot->output_offset + 4
   1796  1.1.1.8  christos 			   - (splt->output_section->vma + 6)),
   1797      1.1  christos 			  splt->contents + 2);
   1798  1.1.1.8  christos 	  bfd_put_32 (output_bfd,
   1799  1.1.1.8  christos 			  (sgot->output_section->vma
   1800  1.1.1.8  christos 			   + sgot->output_offset + 8
   1801  1.1.1.8  christos 			   - (splt->output_section->vma + 12)),
   1802  1.1.1.8  christos 			  splt->contents + 8);
   1803  1.1.1.8  christos 	  elf_section_data (splt->output_section)->this_hdr.sh_entsize
   1804      1.1  christos 	   = PLT_ENTRY_SIZE;
   1805      1.1  christos 	}
   1806      1.1  christos     }
   1807      1.1  christos 
   1808      1.1  christos   /* Fill in the first three entries in the global offset table.  */
   1809      1.1  christos   if (sgot->size > 0)
   1810      1.1  christos     {
   1811      1.1  christos       if (sdyn == NULL)
   1812      1.1  christos 	bfd_put_32 (output_bfd, (bfd_vma) 0, sgot->contents);
   1813      1.1  christos       else
   1814      1.1  christos 	bfd_put_32 (output_bfd,
   1815      1.1  christos 		    sdyn->output_section->vma + sdyn->output_offset,
   1816      1.1  christos 		    sgot->contents);
   1817      1.1  christos       bfd_put_32 (output_bfd, (bfd_vma) 0, sgot->contents + 4);
   1818      1.1  christos       bfd_put_32 (output_bfd, (bfd_vma) 0, sgot->contents + 8);
   1819      1.1  christos     }
   1820  1.1.1.3  christos 
   1821  1.1.1.3  christos   if (elf_section_data (sgot->output_section) != NULL)
   1822      1.1  christos     elf_section_data (sgot->output_section)->this_hdr.sh_entsize = 4;
   1823      1.1  christos 
   1824      1.1  christos   return TRUE;
   1825      1.1  christos }
   1826      1.1  christos 
   1827  1.1.1.3  christos static enum elf_reloc_type_class
   1828  1.1.1.3  christos elf_vax_reloc_type_class (const struct bfd_link_info *info ATTRIBUTE_UNUSED,
   1829  1.1.1.3  christos 			  const asection *rel_sec ATTRIBUTE_UNUSED,
   1830      1.1  christos 			  const Elf_Internal_Rela *rela)
   1831      1.1  christos {
   1832      1.1  christos   switch ((int) ELF32_R_TYPE (rela->r_info))
   1833      1.1  christos     {
   1834      1.1  christos     case R_VAX_RELATIVE:
   1835      1.1  christos       return reloc_class_relative;
   1836      1.1  christos     case R_VAX_JMP_SLOT:
   1837      1.1  christos       return reloc_class_plt;
   1838      1.1  christos     case R_VAX_COPY:
   1839      1.1  christos       return reloc_class_copy;
   1840      1.1  christos     default:
   1841      1.1  christos       return reloc_class_normal;
   1842      1.1  christos     }
   1843      1.1  christos }
   1844      1.1  christos 
   1845      1.1  christos static bfd_vma
   1846      1.1  christos elf_vax_plt_sym_val (bfd_vma i, const asection *plt,
   1847      1.1  christos 		     const arelent *rel ATTRIBUTE_UNUSED)
   1848      1.1  christos {
   1849      1.1  christos   return plt->vma + (i + 1) * PLT_ENTRY_SIZE;
   1850      1.1  christos }
   1851  1.1.1.4  christos 
   1852      1.1  christos #define TARGET_LITTLE_SYM		vax_elf32_vec
   1853      1.1  christos #define TARGET_LITTLE_NAME		"elf32-vax"
   1854      1.1  christos #define ELF_MACHINE_CODE		EM_VAX
   1855      1.1  christos #define ELF_MAXPAGESIZE			0x1000
   1856      1.1  christos 
   1857      1.1  christos #define elf_backend_create_dynamic_sections \
   1858      1.1  christos 					_bfd_elf_create_dynamic_sections
   1859      1.1  christos #define bfd_elf32_bfd_link_hash_table_create \
   1860      1.1  christos 					elf_vax_link_hash_table_create
   1861      1.1  christos #define bfd_elf32_bfd_final_link	bfd_elf_gc_common_final_link
   1862      1.1  christos 
   1863      1.1  christos #define elf_backend_check_relocs	elf_vax_check_relocs
   1864      1.1  christos #define elf_backend_adjust_dynamic_symbol \
   1865  1.1.1.3  christos 					elf_vax_adjust_dynamic_symbol
   1866  1.1.1.3  christos #define elf_backend_always_size_sections \
   1867      1.1  christos 					elf_vax_always_size_sections
   1868      1.1  christos #define elf_backend_size_dynamic_sections \
   1869      1.1  christos 					elf_vax_size_dynamic_sections
   1870      1.1  christos #define elf_backend_init_index_section	_bfd_elf_init_1_index_section
   1871      1.1  christos #define elf_backend_relocate_section	elf_vax_relocate_section
   1872      1.1  christos #define elf_backend_finish_dynamic_symbol \
   1873      1.1  christos 					elf_vax_finish_dynamic_symbol
   1874      1.1  christos #define elf_backend_finish_dynamic_sections \
   1875      1.1  christos 					elf_vax_finish_dynamic_sections
   1876      1.1  christos #define elf_backend_reloc_type_class	elf_vax_reloc_type_class
   1877      1.1  christos #define elf_backend_gc_mark_hook	elf_vax_gc_mark_hook
   1878      1.1  christos #define elf_backend_plt_sym_val		elf_vax_plt_sym_val
   1879  1.1.1.8  christos #define bfd_elf32_bfd_merge_private_bfd_data \
   1880      1.1  christos 					elf32_vax_merge_private_bfd_data
   1881  1.1.1.8  christos #define bfd_elf32_bfd_set_private_flags \
   1882      1.1  christos 					elf32_vax_set_private_flags
   1883  1.1.1.8  christos #define bfd_elf32_bfd_print_private_bfd_data \
   1884      1.1  christos 					elf32_vax_print_private_bfd_data
   1885      1.1  christos 
   1886      1.1  christos #define elf_backend_can_gc_sections	1
   1887      1.1  christos #define elf_backend_want_got_plt	1
   1888      1.1  christos #define elf_backend_plt_readonly	1
   1889      1.1  christos #define elf_backend_want_plt_sym	0
   1890      1.1  christos #define elf_backend_got_header_size	16
   1891  1.1.1.7  christos #define elf_backend_rela_normal		1
   1892      1.1  christos #define elf_backend_dtrel_excludes_plt	1
   1893      1.1  christos 
   1894                    #include "elf32-target.h"
   1895