Back to index

cell-binutils  2.17cvs20070401
elf32-vax.c
Go to the documentation of this file.
00001 /* VAX series support for 32-bit ELF
00002    Copyright 1993, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003,
00003    2004, 2005, 2006, 2007 Free Software Foundation, Inc.
00004    Contributed by Matt Thomas <matt@3am-software.com>.
00005 
00006    This file is part of BFD, the Binary File Descriptor library.
00007 
00008    This program is free software; you can redistribute it and/or modify
00009    it under the terms of the GNU General Public License as published by
00010    the Free Software Foundation; either version 2 of the License, or
00011    (at your option) any later version.
00012 
00013    This program is distributed in the hope that it will be useful,
00014    but WITHOUT ANY WARRANTY; without even the implied warranty of
00015    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00016    GNU General Public License for more details.
00017 
00018    You should have received a copy of the GNU General Public License
00019    along with this program; if not, write to the Free Software
00020    Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.  */
00021 
00022 #include "bfd.h"
00023 #include "sysdep.h"
00024 #include "bfdlink.h"
00025 #include "libbfd.h"
00026 #include "elf-bfd.h"
00027 #include "elf/vax.h"
00028 
00029 static reloc_howto_type *reloc_type_lookup (bfd *, bfd_reloc_code_real_type);
00030 static void rtype_to_howto (bfd *, arelent *, Elf_Internal_Rela *);
00031 static struct bfd_hash_entry *elf_vax_link_hash_newfunc (struct bfd_hash_entry *,
00032                                                   struct bfd_hash_table *,
00033                                                   const char *);
00034 static struct bfd_link_hash_table *elf_vax_link_hash_table_create (bfd *);
00035 static bfd_boolean elf_vax_check_relocs (bfd *, struct bfd_link_info *,
00036                                     asection *, const Elf_Internal_Rela *);
00037 static bfd_boolean elf_vax_adjust_dynamic_symbol (struct bfd_link_info *,
00038                                             struct elf_link_hash_entry *);
00039 static bfd_boolean elf_vax_size_dynamic_sections (bfd *, struct bfd_link_info *);
00040 static bfd_boolean elf_vax_relocate_section (bfd *, struct bfd_link_info *,
00041                                         bfd *, asection *, bfd_byte *,
00042                                         Elf_Internal_Rela *,
00043                                         Elf_Internal_Sym *, asection **);
00044 static bfd_boolean elf_vax_finish_dynamic_symbol (bfd *, struct bfd_link_info *,
00045                                             struct elf_link_hash_entry *,
00046                                             Elf_Internal_Sym *);
00047 static bfd_boolean elf_vax_finish_dynamic_sections (bfd *,
00048                                               struct bfd_link_info *);
00049 
00050 static bfd_boolean elf32_vax_set_private_flags (bfd *, flagword);
00051 static bfd_boolean elf32_vax_merge_private_bfd_data (bfd *, bfd *);
00052 static bfd_boolean elf32_vax_print_private_bfd_data (bfd *, PTR);
00053 
00054 static reloc_howto_type howto_table[] = {
00055   HOWTO (R_VAX_NONE,        /* type */
00056         0,                  /* rightshift */
00057         0,                  /* size (0 = byte, 1 = short, 2 = long) */
00058         0,                  /* bitsize */
00059         FALSE,                     /* pc_relative */
00060         0,                  /* bitpos */
00061         complain_overflow_dont, /* complain_on_overflow */
00062         bfd_elf_generic_reloc,     /* special_function */
00063         "R_VAX_NONE",              /* name */
00064         FALSE,                     /* partial_inplace */
00065         0,                  /* src_mask */
00066         0x00000000,         /* dst_mask */
00067         FALSE),             /* pcrel_offset */
00068 
00069   HOWTO (R_VAX_32,          /* type */
00070         0,                  /* rightshift */
00071         2,                  /* size (0 = byte, 1 = short, 2 = long) */
00072         32,                 /* bitsize */
00073         FALSE,                     /* pc_relative */
00074         0,                  /* bitpos */
00075         complain_overflow_bitfield, /* complain_on_overflow */
00076         bfd_elf_generic_reloc,     /* special_function */
00077         "R_VAX_32",         /* name */
00078         FALSE,                     /* partial_inplace */
00079         0,                  /* src_mask */
00080         0xffffffff,         /* dst_mask */
00081         FALSE),             /* pcrel_offset */
00082 
00083   HOWTO (R_VAX_16,          /* type */
00084         0,                  /* rightshift */
00085         1,                  /* size (0 = byte, 1 = short, 2 = long) */
00086         16,                 /* bitsize */
00087         FALSE,                     /* pc_relative */
00088         0,                  /* bitpos */
00089         complain_overflow_bitfield, /* complain_on_overflow */
00090         bfd_elf_generic_reloc,     /* special_function */
00091         "R_VAX_16",         /* name */
00092         FALSE,                     /* partial_inplace */
00093         0,                  /* src_mask */
00094         0x0000ffff,         /* dst_mask */
00095         FALSE),             /* pcrel_offset */
00096 
00097   HOWTO (R_VAX_8,           /* type */
00098         0,                  /* rightshift */
00099         0,                  /* size (0 = byte, 1 = short, 2 = long) */
00100         8,                  /* bitsize */
00101         FALSE,                     /* pc_relative */
00102         0,                  /* bitpos */
00103         complain_overflow_bitfield, /* complain_on_overflow */
00104         bfd_elf_generic_reloc,     /* special_function */
00105         "R_VAX_8",          /* name */
00106         FALSE,                     /* partial_inplace */
00107         0,                  /* src_mask */
00108         0x000000ff,         /* dst_mask */
00109         FALSE),             /* pcrel_offset */
00110 
00111   HOWTO (R_VAX_PC32,        /* type */
00112         0,                  /* rightshift */
00113         2,                  /* size (0 = byte, 1 = short, 2 = long) */
00114         32,                 /* bitsize */
00115         TRUE,               /* pc_relative */
00116         0,                  /* bitpos */
00117         complain_overflow_bitfield, /* complain_on_overflow */
00118         bfd_elf_generic_reloc,     /* special_function */
00119         "R_VAX_PC32",              /* name */
00120         FALSE,                     /* partial_inplace */
00121         0,                  /* src_mask */
00122         0xffffffff,         /* dst_mask */
00123         TRUE),                     /* pcrel_offset */
00124 
00125   HOWTO (R_VAX_PC16,        /* type */
00126         0,                  /* rightshift */
00127         1,                  /* size (0 = byte, 1 = short, 2 = long) */
00128         16,                 /* bitsize */
00129         TRUE,               /* pc_relative */
00130         0,                  /* bitpos */
00131         complain_overflow_signed, /* complain_on_overflow */
00132         bfd_elf_generic_reloc,     /* special_function */
00133         "R_VAX_PC16",              /* name */
00134         FALSE,                     /* partial_inplace */
00135         0,                  /* src_mask */
00136         0x0000ffff,         /* dst_mask */
00137         TRUE),                     /* pcrel_offset */
00138 
00139   HOWTO (R_VAX_PC8,         /* type */
00140         0,                  /* rightshift */
00141         0,                  /* size (0 = byte, 1 = short, 2 = long) */
00142         8,                  /* bitsize */
00143         TRUE,               /* pc_relative */
00144         0,                  /* bitpos */
00145         complain_overflow_signed, /* complain_on_overflow */
00146         bfd_elf_generic_reloc,     /* special_function */
00147         "R_VAX_PC8",        /* name */
00148         FALSE,                     /* partial_inplace */
00149         0,                  /* src_mask */
00150         0x000000ff,         /* dst_mask */
00151         TRUE),                     /* pcrel_offset */
00152 
00153   HOWTO (R_VAX_GOT32,              /* type */
00154         0,                  /* rightshift */
00155         2,                  /* size (0 = byte, 1 = short, 2 = long) */
00156         32,                 /* bitsize */
00157         TRUE,               /* pc_relative */
00158         0,                  /* bitpos */
00159         complain_overflow_bitfield, /* complain_on_overflow */
00160         bfd_elf_generic_reloc,     /* special_function */
00161         "R_VAX_GOT32",             /* name */
00162         FALSE,                     /* partial_inplace */
00163         0,                  /* src_mask */
00164         0xffffffff,         /* dst_mask */
00165         TRUE),                     /* pcrel_offset */
00166 
00167   EMPTY_HOWTO (-1),
00168   EMPTY_HOWTO (-1),
00169   EMPTY_HOWTO (-1),
00170   EMPTY_HOWTO (-1),
00171   EMPTY_HOWTO (-1),
00172 
00173   HOWTO (R_VAX_PLT32,              /* type */
00174         0,                  /* rightshift */
00175         2,                  /* size (0 = byte, 1 = short, 2 = long) */
00176         32,                 /* bitsize */
00177         TRUE,               /* pc_relative */
00178         0,                  /* bitpos */
00179         complain_overflow_bitfield, /* complain_on_overflow */
00180         bfd_elf_generic_reloc,     /* special_function */
00181         "R_VAX_PLT32",             /* name */
00182         FALSE,                     /* partial_inplace */
00183         0,                  /* src_mask */
00184         0xffffffff,         /* dst_mask */
00185         TRUE),                     /* pcrel_offset */
00186 
00187   EMPTY_HOWTO (-1),
00188   EMPTY_HOWTO (-1),
00189   EMPTY_HOWTO (-1),
00190   EMPTY_HOWTO (-1),
00191   EMPTY_HOWTO (-1),
00192 
00193   HOWTO (R_VAX_COPY,        /* type */
00194         0,                  /* rightshift */
00195         0,                  /* size (0 = byte, 1 = short, 2 = long) */
00196         0,                  /* bitsize */
00197         FALSE,                     /* pc_relative */
00198         0,                  /* bitpos */
00199         complain_overflow_dont, /* complain_on_overflow */
00200         bfd_elf_generic_reloc,     /* special_function */
00201         "R_VAX_COPY",              /* name */
00202         FALSE,                     /* partial_inplace */
00203         0,                  /* src_mask */
00204         0xffffffff,         /* dst_mask */
00205         FALSE),             /* pcrel_offset */
00206 
00207   HOWTO (R_VAX_GLOB_DAT,    /* type */
00208         0,                  /* rightshift */
00209         2,                  /* size (0 = byte, 1 = short, 2 = long) */
00210         32,                 /* bitsize */
00211         FALSE,                     /* pc_relative */
00212         0,                  /* bitpos */
00213         complain_overflow_dont, /* complain_on_overflow */
00214         bfd_elf_generic_reloc,     /* special_function */
00215         "R_VAX_GLOB_DAT",   /* name */
00216         FALSE,                     /* partial_inplace */
00217         0,                  /* src_mask */
00218         0xffffffff,         /* dst_mask */
00219         FALSE),             /* pcrel_offset */
00220 
00221   HOWTO (R_VAX_JMP_SLOT,    /* type */
00222         0,                  /* rightshift */
00223         2,                  /* size (0 = byte, 1 = short, 2 = long) */
00224         32,                 /* bitsize */
00225         FALSE,                     /* pc_relative */
00226         0,                  /* bitpos */
00227         complain_overflow_dont, /* complain_on_overflow */
00228         bfd_elf_generic_reloc,     /* special_function */
00229         "R_VAX_JMP_SLOT",   /* name */
00230         FALSE,                     /* partial_inplace */
00231         0,                  /* src_mask */
00232         0xffffffff,         /* dst_mask */
00233         FALSE),             /* pcrel_offset */
00234 
00235   HOWTO (R_VAX_RELATIVE,    /* type */
00236         0,                  /* rightshift */
00237         2,                  /* size (0 = byte, 1 = short, 2 = long) */
00238         32,                 /* bitsize */
00239         FALSE,                     /* pc_relative */
00240         0,                  /* bitpos */
00241         complain_overflow_dont, /* complain_on_overflow */
00242         bfd_elf_generic_reloc,     /* special_function */
00243         "R_VAX_RELATIVE",   /* name */
00244         FALSE,                     /* partial_inplace */
00245         0,                  /* src_mask */
00246         0xffffffff,         /* dst_mask */
00247         FALSE),             /* pcrel_offset */
00248 
00249   /* GNU extension to record C++ vtable hierarchy */
00250   HOWTO (R_VAX_GNU_VTINHERIT,      /* type */
00251         0,                  /* rightshift */
00252         2,                  /* size (0 = byte, 1 = short, 2 = long) */
00253         0,                  /* bitsize */
00254         FALSE,                     /* pc_relative */
00255         0,                  /* bitpos */
00256         complain_overflow_dont, /* complain_on_overflow */
00257         NULL,               /* special_function */
00258         "R_VAX_GNU_VTINHERIT",     /* name */
00259         FALSE,                     /* partial_inplace */
00260         0,                  /* src_mask */
00261         0,                  /* dst_mask */
00262         FALSE),             /* pcrel_offset */
00263 
00264   /* GNU extension to record C++ vtable member usage */
00265   HOWTO (R_VAX_GNU_VTENTRY, /* type */
00266         0,                  /* rightshift */
00267         2,                  /* size (0 = byte, 1 = short, 2 = long) */
00268         0,                  /* bitsize */
00269         FALSE,                     /* pc_relative */
00270         0,                  /* bitpos */
00271         complain_overflow_dont, /* complain_on_overflow */
00272         _bfd_elf_rel_vtable_reloc_fn, /* special_function */
00273         "R_VAX_GNU_VTENTRY",       /* name */
00274         FALSE,                     /* partial_inplace */
00275         0,                  /* src_mask */
00276         0,                  /* dst_mask */
00277         FALSE),             /* pcrel_offset */
00278 };
00279 
00280 static void
00281 rtype_to_howto (bfd *abfd ATTRIBUTE_UNUSED, arelent *cache_ptr,
00282               Elf_Internal_Rela *dst)
00283 {
00284   BFD_ASSERT (ELF32_R_TYPE(dst->r_info) < (unsigned int) R_VAX_max);
00285   cache_ptr->howto = &howto_table[ELF32_R_TYPE(dst->r_info)];
00286 }
00287 
00288 #define elf_info_to_howto rtype_to_howto
00289 
00290 static const struct
00291 {
00292   bfd_reloc_code_real_type bfd_val;
00293   int elf_val;
00294 } reloc_map[] = {
00295   { BFD_RELOC_NONE, R_VAX_NONE },
00296   { BFD_RELOC_32, R_VAX_32 },
00297   { BFD_RELOC_16, R_VAX_16 },
00298   { BFD_RELOC_8, R_VAX_8 },
00299   { BFD_RELOC_32_PCREL, R_VAX_PC32 },
00300   { BFD_RELOC_16_PCREL, R_VAX_PC16 },
00301   { BFD_RELOC_8_PCREL, R_VAX_PC8 },
00302   { BFD_RELOC_32_GOT_PCREL, R_VAX_GOT32 },
00303   { BFD_RELOC_32_PLT_PCREL, R_VAX_PLT32 },
00304   { BFD_RELOC_NONE, R_VAX_COPY },
00305   { BFD_RELOC_VAX_GLOB_DAT, R_VAX_GLOB_DAT },
00306   { BFD_RELOC_VAX_JMP_SLOT, R_VAX_JMP_SLOT },
00307   { BFD_RELOC_VAX_RELATIVE, R_VAX_RELATIVE },
00308   { BFD_RELOC_CTOR, R_VAX_32 },
00309   { BFD_RELOC_VTABLE_INHERIT, R_VAX_GNU_VTINHERIT },
00310   { BFD_RELOC_VTABLE_ENTRY, R_VAX_GNU_VTENTRY },
00311 };
00312 
00313 static reloc_howto_type *
00314 reloc_type_lookup (bfd *abfd ATTRIBUTE_UNUSED, bfd_reloc_code_real_type code)
00315 {
00316   unsigned int i;
00317   for (i = 0; i < sizeof (reloc_map) / sizeof (reloc_map[0]); i++)
00318     {
00319       if (reloc_map[i].bfd_val == code)
00320        return &howto_table[reloc_map[i].elf_val];
00321     }
00322   return 0;
00323 }
00324 
00325 static reloc_howto_type *
00326 reloc_name_lookup (bfd *abfd ATTRIBUTE_UNUSED,
00327                  const char *r_name)
00328 {
00329   unsigned int i;
00330 
00331   for (i = 0; i < sizeof (howto_table) / sizeof (howto_table[0]); i++)
00332     if (howto_table[i].name != NULL
00333        && strcasecmp (howto_table[i].name, r_name) == 0)
00334       return &howto_table[i];
00335 
00336   return NULL;
00337 }
00338 
00339 #define bfd_elf32_bfd_reloc_type_lookup reloc_type_lookup
00340 #define bfd_elf32_bfd_reloc_name_lookup reloc_name_lookup
00341 #define ELF_ARCH bfd_arch_vax
00342 /* end code generated by elf.el */
00343 
00344 /* Functions for the VAX ELF linker.  */
00345 
00346 /* The name of the dynamic interpreter.  This is put in the .interp
00347    section.  */
00348 
00349 #define ELF_DYNAMIC_INTERPRETER "/usr/libexec/ld.elf_so"
00350 
00351 /* The size in bytes of an entry in the procedure linkage table.  */
00352 
00353 #define PLT_ENTRY_SIZE 12
00354 
00355 /* The first entry in a procedure linkage table looks like this.  See
00356    the SVR4 ABI VAX supplement to see how this works.  */
00357 
00358 static const bfd_byte elf_vax_plt0_entry[PLT_ENTRY_SIZE] =
00359 {
00360   0xdd, 0xef,        /* pushl l^ */
00361   0, 0, 0, 0,        /* offset to .plt.got + 4 */
00362   0x17, 0xff,        /* jmp @L^(pc) */
00363   0, 0, 0, 0,        /* offset to .plt.got + 8 */
00364 };
00365 
00366 /* Subsequent entries in a procedure linkage table look like this.  */
00367 
00368 static const bfd_byte elf_vax_plt_entry[PLT_ENTRY_SIZE] =
00369 {
00370   0x40, 0x00,        /* .word ^M<r6> */
00371   0x16,       0xef,         /* jsb L^(pc) */
00372   0, 0, 0, 0,        /* replaced with offset to start of .plt  */
00373   0, 0, 0, 0,        /* index into .rela.plt */
00374 };
00375 
00376 /* The VAX linker needs to keep track of the number of relocs that it
00377    decides to copy in check_relocs for each symbol.  This is so that it
00378    can discard PC relative relocs if it doesn't need them when linking
00379    with -Bsymbolic.  We store the information in a field extending the
00380    regular ELF linker hash table.  */
00381 
00382 /* This structure keeps track of the number of PC relative relocs we have
00383    copied for a given symbol.  */
00384 
00385 struct elf_vax_pcrel_relocs_copied
00386 {
00387   /* Next section.  */
00388   struct elf_vax_pcrel_relocs_copied *next;
00389   /* A section in dynobj.  */
00390   asection *section;
00391   /* Number of relocs copied in this section.  */
00392   bfd_size_type count;
00393 };
00394 
00395 /* VAX ELF linker hash entry.  */
00396 
00397 struct elf_vax_link_hash_entry
00398 {
00399   struct elf_link_hash_entry root;
00400 
00401   /* Number of PC relative relocs copied for this symbol.  */
00402   struct elf_vax_pcrel_relocs_copied *pcrel_relocs_copied;
00403 
00404   bfd_vma got_addend;
00405 };
00406 
00407 /* VAX ELF linker hash table.  */
00408 
00409 struct elf_vax_link_hash_table
00410 {
00411   struct elf_link_hash_table root;
00412 };
00413 
00414 /* Declare this now that the above structures are defined.  */
00415 
00416 static bfd_boolean elf_vax_discard_copies (struct elf_vax_link_hash_entry *,
00417                                       PTR);
00418 
00419 /* Declare this now that the above structures are defined.  */
00420 
00421 static bfd_boolean elf_vax_instantiate_got_entries (struct elf_link_hash_entry *,
00422                                               PTR);
00423 
00424 /* Traverse an VAX ELF linker hash table.  */
00425 
00426 #define elf_vax_link_hash_traverse(table, func, info)                 \
00427   (elf_link_hash_traverse                                      \
00428    (&(table)->root,                                            \
00429     (bfd_boolean (*) (struct elf_link_hash_entry *, PTR)) (func),     \
00430     (info)))
00431 
00432 /* Get the VAX ELF linker hash table from a link_info structure.  */
00433 
00434 #define elf_vax_hash_table(p) ((struct elf_vax_link_hash_table *) (p)->hash)
00435 
00436 /* Create an entry in an VAX ELF linker hash table.  */
00437 
00438 static struct bfd_hash_entry *
00439 elf_vax_link_hash_newfunc (struct bfd_hash_entry *entry,
00440                         struct bfd_hash_table *table,
00441                         const char *string)
00442 {
00443   struct elf_vax_link_hash_entry *ret =
00444     (struct elf_vax_link_hash_entry *) entry;
00445 
00446   /* Allocate the structure if it has not already been allocated by a
00447      subclass.  */
00448   if (ret == NULL)
00449     ret = ((struct elf_vax_link_hash_entry *)
00450           bfd_hash_allocate (table,
00451                            sizeof (struct elf_vax_link_hash_entry)));
00452   if (ret == NULL)
00453     return (struct bfd_hash_entry *) ret;
00454 
00455   /* Call the allocation method of the superclass.  */
00456   ret = ((struct elf_vax_link_hash_entry *)
00457         _bfd_elf_link_hash_newfunc ((struct bfd_hash_entry *) ret,
00458                                  table, string));
00459   if (ret != NULL)
00460     {
00461       ret->pcrel_relocs_copied = NULL;
00462     }
00463 
00464   return (struct bfd_hash_entry *) ret;
00465 }
00466 
00467 /* Create an VAX ELF linker hash table.  */
00468 
00469 static struct bfd_link_hash_table *
00470 elf_vax_link_hash_table_create (bfd *abfd)
00471 {
00472   struct elf_vax_link_hash_table *ret;
00473   bfd_size_type amt = sizeof (struct elf_vax_link_hash_table);
00474 
00475   ret = bfd_malloc (amt);
00476   if (ret == NULL)
00477     return NULL;
00478 
00479   if (!_bfd_elf_link_hash_table_init (&ret->root, abfd,
00480                                   elf_vax_link_hash_newfunc,
00481                                   sizeof (struct elf_vax_link_hash_entry)))
00482     {
00483       free (ret);
00484       return NULL;
00485     }
00486 
00487   return &ret->root.root;
00488 }
00489 
00490 /* Keep vax-specific flags in the ELF header */
00491 static bfd_boolean
00492 elf32_vax_set_private_flags (bfd *abfd, flagword flags)
00493 {
00494   elf_elfheader (abfd)->e_flags = flags;
00495   elf_flags_init (abfd) = TRUE;
00496   return TRUE;
00497 }
00498 
00499 /* Merge backend specific data from an object file to the output
00500    object file when linking.  */
00501 static bfd_boolean
00502 elf32_vax_merge_private_bfd_data (bfd *ibfd, bfd *obfd)
00503 {
00504   flagword out_flags;
00505   flagword in_flags;
00506 
00507   if (   bfd_get_flavour (ibfd) != bfd_target_elf_flavour
00508       || bfd_get_flavour (obfd) != bfd_target_elf_flavour)
00509     return TRUE;
00510 
00511   in_flags  = elf_elfheader (ibfd)->e_flags;
00512   out_flags = elf_elfheader (obfd)->e_flags;
00513 
00514   if (!elf_flags_init (obfd))
00515     {
00516       elf_flags_init (obfd) = TRUE;
00517       elf_elfheader (obfd)->e_flags = in_flags;
00518     }
00519 
00520   return TRUE;
00521 }
00522 
00523 /* Display the flags field */
00524 static bfd_boolean
00525 elf32_vax_print_private_bfd_data (bfd *abfd, PTR ptr)
00526 {
00527   FILE *file = (FILE *) ptr;
00528 
00529   BFD_ASSERT (abfd != NULL && ptr != NULL);
00530 
00531   /* Print normal ELF private data.  */
00532   _bfd_elf_print_private_bfd_data (abfd, ptr);
00533 
00534   /* Ignore init flag - it may not be set, despite the flags field containing valid data.  */
00535 
00536   /* xgettext:c-format */
00537   fprintf (file, _("private flags = %lx:"), elf_elfheader (abfd)->e_flags);
00538 
00539   if (elf_elfheader (abfd)->e_flags & EF_VAX_NONPIC)
00540     fprintf (file, _(" [nonpic]"));
00541 
00542   if (elf_elfheader (abfd)->e_flags & EF_VAX_DFLOAT)
00543     fprintf (file, _(" [d-float]"));
00544 
00545   if (elf_elfheader (abfd)->e_flags & EF_VAX_GFLOAT)
00546     fprintf (file, _(" [g-float]"));
00547 
00548   fputc ('\n', file);
00549 
00550   return TRUE;
00551 }
00552 /* Look through the relocs for a section during the first phase, and
00553    allocate space in the global offset table or procedure linkage
00554    table.  */
00555 
00556 static bfd_boolean
00557 elf_vax_check_relocs (bfd *abfd, struct bfd_link_info *info, asection *sec,
00558                     const Elf_Internal_Rela *relocs)
00559 {
00560   bfd *dynobj;
00561   Elf_Internal_Shdr *symtab_hdr;
00562   struct elf_link_hash_entry **sym_hashes;
00563   const Elf_Internal_Rela *rel;
00564   const Elf_Internal_Rela *rel_end;
00565   asection *sgot;
00566   asection *srelgot;
00567   asection *sreloc;
00568 
00569   if (info->relocatable)
00570     return TRUE;
00571 
00572   dynobj = elf_hash_table (info)->dynobj;
00573   symtab_hdr = &elf_tdata (abfd)->symtab_hdr;
00574   sym_hashes = elf_sym_hashes (abfd);
00575 
00576   sgot = NULL;
00577   srelgot = NULL;
00578   sreloc = NULL;
00579 
00580   rel_end = relocs + sec->reloc_count;
00581   for (rel = relocs; rel < rel_end; rel++)
00582     {
00583       unsigned long r_symndx;
00584       struct elf_link_hash_entry *h;
00585 
00586       r_symndx = ELF32_R_SYM (rel->r_info);
00587 
00588       if (r_symndx < symtab_hdr->sh_info)
00589        h = NULL;
00590       else
00591        {
00592          h = sym_hashes[r_symndx - symtab_hdr->sh_info];
00593          while (h->root.type == bfd_link_hash_indirect
00594                || h->root.type == bfd_link_hash_warning)
00595            h = (struct elf_link_hash_entry *) h->root.u.i.link;
00596        }
00597 
00598       switch (ELF32_R_TYPE (rel->r_info))
00599        {
00600        case R_VAX_GOT32:
00601          if (h != NULL
00602              && strcmp (h->root.root.string, "_GLOBAL_OFFSET_TABLE_") == 0)
00603            break;
00604 
00605          /* This symbol requires a global offset table entry.  */
00606 
00607          if (dynobj == NULL)
00608            {
00609              /* Create the .got section.  */
00610              elf_hash_table (info)->dynobj = dynobj = abfd;
00611              if (!_bfd_elf_create_got_section (dynobj, info))
00612               return FALSE;
00613            }
00614 
00615          if (sgot == NULL)
00616            {
00617              sgot = bfd_get_section_by_name (dynobj, ".got");
00618              BFD_ASSERT (sgot != NULL);
00619            }
00620 
00621          if (srelgot == NULL
00622              && (h != NULL || info->shared))
00623            {
00624              srelgot = bfd_get_section_by_name (dynobj, ".rela.got");
00625              if (srelgot == NULL)
00626               {
00627                 srelgot = bfd_make_section_with_flags (dynobj,
00628                                                   ".rela.got",
00629                                                   (SEC_ALLOC
00630                                                    | SEC_LOAD
00631                                                    | SEC_HAS_CONTENTS
00632                                                    | SEC_IN_MEMORY
00633                                                    | SEC_LINKER_CREATED
00634                                                    | SEC_READONLY));
00635                 if (srelgot == NULL
00636                     || !bfd_set_section_alignment (dynobj, srelgot, 2))
00637                   return FALSE;
00638               }
00639            }
00640 
00641          if (h != NULL)
00642            {
00643              struct elf_vax_link_hash_entry *eh;
00644 
00645              eh = (struct elf_vax_link_hash_entry *) h;
00646              if (h->got.refcount == -1)
00647               {
00648                 h->got.refcount = 1;
00649                 eh->got_addend = rel->r_addend;
00650               }
00651              else
00652               {
00653                 h->got.refcount++;
00654                 if (eh->got_addend != (bfd_vma) rel->r_addend)
00655                   (*_bfd_error_handler)
00656                     (_("%s: warning: GOT addend of %ld to `%s' does not match previous GOT addend of %ld"),
00657                            bfd_get_filename (abfd), rel->r_addend,
00658                            h->root.root.string,
00659                            eh->got_addend);
00660 
00661               }
00662            }
00663          break;
00664 
00665        case R_VAX_PLT32:
00666          /* This symbol requires a procedure linkage table entry.  We
00667             actually build the entry in adjust_dynamic_symbol,
00668              because this might be a case of linking PIC code which is
00669              never referenced by a dynamic object, in which case we
00670              don't need to generate a procedure linkage table entry
00671              after all.  */
00672 
00673          /* If this is a local symbol, we resolve it directly without
00674             creating a procedure linkage table entry.  */
00675          if (h == NULL)
00676            continue;
00677 
00678          h->needs_plt = 1;
00679          if (h->plt.refcount == -1)
00680            h->plt.refcount = 1;
00681          else
00682            h->plt.refcount++;
00683          break;
00684 
00685        case R_VAX_PC8:
00686        case R_VAX_PC16:
00687        case R_VAX_PC32:
00688          /* If we are creating a shared library and this is not a local
00689             symbol, we need to copy the reloc into the shared library.
00690             However when linking with -Bsymbolic and this is a global
00691             symbol which is defined in an object we are including in the
00692             link (i.e., DEF_REGULAR is set), then we can resolve the
00693             reloc directly.  At this point we have not seen all the input
00694             files, so it is possible that DEF_REGULAR is not set now but
00695             will be set later (it is never cleared).  We account for that
00696             possibility below by storing information in the
00697             pcrel_relocs_copied field of the hash table entry.  */
00698          if (!(info->shared
00699               && (sec->flags & SEC_ALLOC) != 0
00700               && h != NULL
00701               && (!info->symbolic
00702                   || !h->def_regular)))
00703            {
00704              if (h != NULL)
00705               {
00706                 /* Make sure a plt entry is created for this symbol if
00707                    it turns out to be a function defined by a dynamic
00708                    object.  */
00709                 if (h->plt.refcount == -1)
00710                   h->plt.refcount = 1;
00711                 else
00712                   h->plt.refcount++;
00713               }
00714              break;
00715            }
00716          /* Fall through.  */
00717        case R_VAX_8:
00718        case R_VAX_16:
00719        case R_VAX_32:
00720          if (h != NULL)
00721            {
00722              /* Make sure a plt entry is created for this symbol if it
00723                turns out to be a function defined by a dynamic object.  */
00724              if (h->plt.refcount == -1)
00725               h->plt.refcount = 1;
00726              else
00727               h->plt.refcount++;
00728            }
00729 
00730          /* If we are creating a shared library, we need to copy the
00731             reloc into the shared library.  */
00732          if (info->shared
00733              && (sec->flags & SEC_ALLOC) != 0)
00734            {
00735              /* When creating a shared object, we must copy these
00736                reloc types into the output file.  We create a reloc
00737                section in dynobj and make room for this reloc.  */
00738              if (sreloc == NULL)
00739               {
00740                 const char *name;
00741 
00742                 name = (bfd_elf_string_from_elf_section
00743                        (abfd,
00744                         elf_elfheader (abfd)->e_shstrndx,
00745                         elf_section_data (sec)->rel_hdr.sh_name));
00746                 if (name == NULL)
00747                   return FALSE;
00748 
00749                 BFD_ASSERT (CONST_STRNEQ (name, ".rela")
00750                            && strcmp (bfd_get_section_name (abfd, sec),
00751                                     name + 5) == 0);
00752 
00753                 sreloc = bfd_get_section_by_name (dynobj, name);
00754                 if (sreloc == NULL)
00755                   {
00756                     sreloc = bfd_make_section_with_flags (dynobj,
00757                                                      name,
00758                                                      (SEC_ALLOC
00759                                                       | SEC_LOAD
00760                                                       | SEC_HAS_CONTENTS
00761                                                       | SEC_IN_MEMORY
00762                                                       | SEC_LINKER_CREATED
00763                                                       | SEC_READONLY));
00764                     if (sreloc == NULL
00765                        || !bfd_set_section_alignment (dynobj, sreloc, 2))
00766                      return FALSE;
00767                   }
00768                 if (sec->flags & SEC_READONLY)
00769                   info->flags |= DF_TEXTREL;
00770               }
00771 
00772              sreloc->size += sizeof (Elf32_External_Rela);
00773 
00774              /* If we are linking with -Bsymbolic, we count the number of
00775                PC relative relocations we have entered for this symbol,
00776                so that we can discard them again if the symbol is later
00777                defined by a regular object.  Note that this function is
00778                only called if we are using a vaxelf linker hash table,
00779                which means that h is really a pointer to an
00780                elf_vax_link_hash_entry.  */
00781              if ((ELF32_R_TYPE (rel->r_info) == R_VAX_PC8
00782                  || ELF32_R_TYPE (rel->r_info) == R_VAX_PC16
00783                  || ELF32_R_TYPE (rel->r_info) == R_VAX_PC32)
00784                 && info->symbolic)
00785               {
00786                 struct elf_vax_link_hash_entry *eh;
00787                 struct elf_vax_pcrel_relocs_copied *p;
00788 
00789                 eh = (struct elf_vax_link_hash_entry *) h;
00790 
00791                 for (p = eh->pcrel_relocs_copied; p != NULL; p = p->next)
00792                   if (p->section == sreloc)
00793                     break;
00794 
00795                 if (p == NULL)
00796                   {
00797                     p = ((struct elf_vax_pcrel_relocs_copied *)
00798                         bfd_alloc (dynobj, (bfd_size_type) sizeof *p));
00799                     if (p == NULL)
00800                      return FALSE;
00801                     p->next = eh->pcrel_relocs_copied;
00802                     eh->pcrel_relocs_copied = p;
00803                     p->section = sreloc;
00804                     p->count = 0;
00805                   }
00806 
00807                 ++p->count;
00808               }
00809            }
00810 
00811          break;
00812 
00813          /* This relocation describes the C++ object vtable hierarchy.
00814             Reconstruct it for later use during GC.  */
00815        case R_VAX_GNU_VTINHERIT:
00816          if (!bfd_elf_gc_record_vtinherit (abfd, sec, h, rel->r_offset))
00817            return FALSE;
00818          break;
00819 
00820          /* This relocation describes which C++ vtable entries are actually
00821             used.  Record for later use during GC.  */
00822        case R_VAX_GNU_VTENTRY:
00823          if (!bfd_elf_gc_record_vtentry (abfd, sec, h, rel->r_addend))
00824            return FALSE;
00825          break;
00826 
00827        default:
00828          break;
00829        }
00830     }
00831 
00832   return TRUE;
00833 }
00834 
00835 /* Return the section that should be marked against GC for a given
00836    relocation.  */
00837 
00838 static asection *
00839 elf_vax_gc_mark_hook (asection *sec,
00840                     struct bfd_link_info *info,
00841                     Elf_Internal_Rela *rel,
00842                     struct elf_link_hash_entry *h,
00843                     Elf_Internal_Sym *sym)
00844 {
00845   if (h != NULL)
00846     switch (ELF32_R_TYPE (rel->r_info))
00847       {
00848       case R_VAX_GNU_VTINHERIT:
00849       case R_VAX_GNU_VTENTRY:
00850        return NULL;
00851       }
00852 
00853   return _bfd_elf_gc_mark_hook (sec, info, rel, h, sym);
00854 }
00855 
00856 /* Update the got entry reference counts for the section being removed.  */
00857 
00858 static bfd_boolean
00859 elf_vax_gc_sweep_hook (bfd *abfd, struct bfd_link_info *info, asection *sec,
00860                      const Elf_Internal_Rela *relocs)
00861 {
00862   Elf_Internal_Shdr *symtab_hdr;
00863   struct elf_link_hash_entry **sym_hashes;
00864   const Elf_Internal_Rela *rel, *relend;
00865   bfd *dynobj;
00866 
00867   dynobj = elf_hash_table (info)->dynobj;
00868   if (dynobj == NULL)
00869     return TRUE;
00870 
00871   symtab_hdr = &elf_tdata (abfd)->symtab_hdr;
00872   sym_hashes = elf_sym_hashes (abfd);
00873 
00874   relend = relocs + sec->reloc_count;
00875   for (rel = relocs; rel < relend; rel++)
00876     {
00877       unsigned long r_symndx;
00878       struct elf_link_hash_entry *h = NULL;
00879 
00880       r_symndx = ELF32_R_SYM (rel->r_info);
00881       if (r_symndx >= symtab_hdr->sh_info)
00882        {
00883          h = sym_hashes[r_symndx - symtab_hdr->sh_info];
00884          while (h->root.type == bfd_link_hash_indirect
00885                || h->root.type == bfd_link_hash_warning)
00886            h = (struct elf_link_hash_entry *) h->root.u.i.link;
00887        }
00888 
00889       switch (ELF32_R_TYPE (rel->r_info))
00890        {
00891        case R_VAX_GOT32:
00892          if (h != NULL && h->got.refcount > 0)
00893            --h->got.refcount;
00894          break;
00895 
00896        case R_VAX_PLT32:
00897        case R_VAX_PC8:
00898        case R_VAX_PC16:
00899        case R_VAX_PC32:
00900        case R_VAX_8:
00901        case R_VAX_16:
00902        case R_VAX_32:
00903          if (h != NULL && h->plt.refcount > 0)
00904            --h->plt.refcount;
00905          break;
00906 
00907        default:
00908          break;
00909        }
00910     }
00911 
00912   return TRUE;
00913 }
00914 
00915 /* Adjust a symbol defined by a dynamic object and referenced by a
00916    regular object.  The current definition is in some section of the
00917    dynamic object, but we're not including those sections.  We have to
00918    change the definition to something the rest of the link can
00919    understand.  */
00920 
00921 static bfd_boolean
00922 elf_vax_adjust_dynamic_symbol (info, h)
00923      struct bfd_link_info *info;
00924      struct elf_link_hash_entry *h;
00925 {
00926   bfd *dynobj;
00927   asection *s;
00928   unsigned int power_of_two;
00929 
00930   dynobj = elf_hash_table (info)->dynobj;
00931 
00932   /* Make sure we know what is going on here.  */
00933   BFD_ASSERT (dynobj != NULL
00934              && (h->needs_plt
00935                 || h->u.weakdef != NULL
00936                 || (h->def_dynamic
00937                     && h->ref_regular
00938                     && !h->def_regular)));
00939 
00940   /* If this is a function, put it in the procedure linkage table.  We
00941      will fill in the contents of the procedure linkage table later,
00942      when we know the address of the .got section.  */
00943   if (h->type == STT_FUNC
00944       || h->needs_plt)
00945     {
00946       if (! info->shared
00947          && !h->def_dynamic
00948          && !h->ref_dynamic
00949          /* We must always create the plt entry if it was referenced
00950             by a PLTxxO relocation.  In this case we already recorded
00951             it as a dynamic symbol.  */
00952          && h->dynindx == -1)
00953        {
00954          /* This case can occur if we saw a PLTxx reloc in an input
00955             file, but the symbol was never referred to by a dynamic
00956             object.  In such a case, we don't actually need to build
00957             a procedure linkage table, and we can just do a PCxx
00958             reloc instead.  */
00959          BFD_ASSERT (h->needs_plt);
00960          h->plt.offset = (bfd_vma) -1;
00961          return TRUE;
00962        }
00963 
00964       /* GC may have rendered this entry unused.  */
00965       if (h->plt.refcount <= 0)
00966        {
00967          h->needs_plt = 0;
00968          h->plt.offset = (bfd_vma) -1;
00969          return TRUE;
00970        }
00971 
00972       /* Make sure this symbol is output as a dynamic symbol.  */
00973       if (h->dynindx == -1)
00974        {
00975          if (! bfd_elf_link_record_dynamic_symbol (info, h))
00976            return FALSE;
00977        }
00978 
00979       s = bfd_get_section_by_name (dynobj, ".plt");
00980       BFD_ASSERT (s != NULL);
00981 
00982       /* If this is the first .plt entry, make room for the special
00983         first entry.  */
00984       if (s->size == 0)
00985        {
00986          s->size += PLT_ENTRY_SIZE;
00987        }
00988 
00989       /* If this symbol is not defined in a regular file, and we are
00990         not generating a shared library, then set the symbol to this
00991         location in the .plt.  This is required to make function
00992         pointers compare as equal between the normal executable and
00993         the shared library.  */
00994       if (!info->shared
00995          && !h->def_regular)
00996        {
00997          h->root.u.def.section = s;
00998          h->root.u.def.value = s->size;
00999        }
01000 
01001       h->plt.offset = s->size;
01002 
01003       /* Make room for this entry.  */
01004       s->size += PLT_ENTRY_SIZE;
01005 
01006       /* We also need to make an entry in the .got.plt section, which
01007         will be placed in the .got section by the linker script.  */
01008 
01009       s = bfd_get_section_by_name (dynobj, ".got.plt");
01010       BFD_ASSERT (s != NULL);
01011       s->size += 4;
01012 
01013       /* We also need to make an entry in the .rela.plt section.  */
01014 
01015       s = bfd_get_section_by_name (dynobj, ".rela.plt");
01016       BFD_ASSERT (s != NULL);
01017       s->size += sizeof (Elf32_External_Rela);
01018 
01019       return TRUE;
01020     }
01021 
01022   /* Reinitialize the plt offset now that it is not used as a reference
01023      count any more.  */
01024   h->plt.offset = (bfd_vma) -1;
01025 
01026   /* If this is a weak symbol, and there is a real definition, the
01027      processor independent code will have arranged for us to see the
01028      real definition first, and we can just use the same value.  */
01029   if (h->u.weakdef != NULL)
01030     {
01031       BFD_ASSERT (h->u.weakdef->root.type == bfd_link_hash_defined
01032                 || h->u.weakdef->root.type == bfd_link_hash_defweak);
01033       h->root.u.def.section = h->u.weakdef->root.u.def.section;
01034       h->root.u.def.value = h->u.weakdef->root.u.def.value;
01035       return TRUE;
01036     }
01037 
01038   /* This is a reference to a symbol defined by a dynamic object which
01039      is not a function.  */
01040 
01041   /* If we are creating a shared library, we must presume that the
01042      only references to the symbol are via the global offset table.
01043      For such cases we need not do anything here; the relocations will
01044      be handled correctly by relocate_section.  */
01045   if (info->shared)
01046     return TRUE;
01047 
01048   if (h->size == 0)
01049     {
01050       (*_bfd_error_handler) (_("dynamic variable `%s' is zero size"),
01051                           h->root.root.string);
01052       return TRUE;
01053     }
01054 
01055   /* We must allocate the symbol in our .dynbss section, which will
01056      become part of the .bss section of the executable.  There will be
01057      an entry for this symbol in the .dynsym section.  The dynamic
01058      object will contain position independent code, so all references
01059      from the dynamic object to this symbol will go through the global
01060      offset table.  The dynamic linker will use the .dynsym entry to
01061      determine the address it must put in the global offset table, so
01062      both the dynamic object and the regular object will refer to the
01063      same memory location for the variable.  */
01064 
01065   s = bfd_get_section_by_name (dynobj, ".dynbss");
01066   BFD_ASSERT (s != NULL);
01067 
01068   /* We must generate a R_VAX_COPY reloc to tell the dynamic linker to
01069      copy the initial value out of the dynamic object and into the
01070      runtime process image.  We need to remember the offset into the
01071      .rela.bss section we are going to use.  */
01072   if ((h->root.u.def.section->flags & SEC_ALLOC) != 0)
01073     {
01074       asection *srel;
01075 
01076       srel = bfd_get_section_by_name (dynobj, ".rela.bss");
01077       BFD_ASSERT (srel != NULL);
01078       srel->size += sizeof (Elf32_External_Rela);
01079       h->needs_copy = 1;
01080     }
01081 
01082   /* We need to figure out the alignment required for this symbol.  I
01083      have no idea how ELF linkers handle this.  */
01084   power_of_two = bfd_log2 (h->size);
01085   if (power_of_two > 3)
01086     power_of_two = 3;
01087 
01088   /* Apply the required alignment.  */
01089   s->size = BFD_ALIGN (s->size, (bfd_size_type) (1 << power_of_two));
01090   if (power_of_two > bfd_get_section_alignment (dynobj, s))
01091     {
01092       if (!bfd_set_section_alignment (dynobj, s, power_of_two))
01093        return FALSE;
01094     }
01095 
01096   /* Define the symbol as being at this point in the section.  */
01097   h->root.u.def.section = s;
01098   h->root.u.def.value = s->size;
01099 
01100   /* Increment the section size to make room for the symbol.  */
01101   s->size += h->size;
01102 
01103   return TRUE;
01104 }
01105 
01106 /* Set the sizes of the dynamic sections.  */
01107 
01108 static bfd_boolean
01109 elf_vax_size_dynamic_sections (bfd *output_bfd, struct bfd_link_info *info)
01110 {
01111   bfd *dynobj;
01112   asection *s;
01113   bfd_boolean plt;
01114   bfd_boolean relocs;
01115   bfd_boolean reltext;
01116 
01117   dynobj = elf_hash_table (info)->dynobj;
01118   BFD_ASSERT (dynobj != NULL);
01119 
01120   if (elf_hash_table (info)->dynamic_sections_created)
01121     {
01122       /* Set the contents of the .interp section to the interpreter.  */
01123       if (info->executable)
01124        {
01125          s = bfd_get_section_by_name (dynobj, ".interp");
01126          BFD_ASSERT (s != NULL);
01127          s->size = sizeof ELF_DYNAMIC_INTERPRETER;
01128          s->contents = (unsigned char *) ELF_DYNAMIC_INTERPRETER;
01129        }
01130     }
01131   else
01132     {
01133       /* We may have created entries in the .rela.got and .got sections.
01134         However, if we are not creating the dynamic sections, we will
01135         not actually use these entries.  Reset the size of .rela.got
01136         and .got, which will cause it to get stripped from the output
01137         file below.  */
01138       s = bfd_get_section_by_name (dynobj, ".rela.got");
01139       if (s != NULL)
01140        s->size = 0;
01141       s = bfd_get_section_by_name (dynobj, ".got.plt");
01142       if (s != NULL)
01143        s->size = 0;
01144       s = bfd_get_section_by_name (dynobj, ".got");
01145       if (s != NULL)
01146        s->size = 0;
01147     }
01148 
01149   /* If this is a -Bsymbolic shared link, then we need to discard all PC
01150      relative relocs against symbols defined in a regular object.  We
01151      allocated space for them in the check_relocs routine, but we will not
01152      fill them in in the relocate_section routine.  */
01153   if (info->shared && info->symbolic)
01154     elf_vax_link_hash_traverse (elf_vax_hash_table (info),
01155                             elf_vax_discard_copies,
01156                             NULL);
01157 
01158   /* If this is a -Bsymbolic shared link or a static link, we need to
01159      discard all the got entries we've recorded.  Otherwise, we need to
01160      instantiate (allocate space for them).  */
01161   elf_link_hash_traverse (elf_hash_table (info),
01162                        elf_vax_instantiate_got_entries,
01163                        (PTR) info);
01164 
01165   /* The check_relocs and adjust_dynamic_symbol entry points have
01166      determined the sizes of the various dynamic sections.  Allocate
01167      memory for them.  */
01168   plt = FALSE;
01169   relocs = FALSE;
01170   reltext = FALSE;
01171   for (s = dynobj->sections; s != NULL; s = s->next)
01172     {
01173       const char *name;
01174 
01175       if ((s->flags & SEC_LINKER_CREATED) == 0)
01176        continue;
01177 
01178       /* It's OK to base decisions on the section name, because none
01179         of the dynobj section names depend upon the input files.  */
01180       name = bfd_get_section_name (dynobj, s);
01181 
01182       if (strcmp (name, ".plt") == 0)
01183        {
01184          /* Remember whether there is a PLT.  */
01185          plt = s->size != 0;
01186        }
01187       else if (CONST_STRNEQ (name, ".rela"))
01188        {
01189          if (s->size != 0)
01190            {
01191              asection *target;
01192 
01193              /* Remember whether there are any reloc sections other
01194                  than .rela.plt.  */
01195              if (strcmp (name, ".rela.plt") != 0)
01196               {
01197                 const char *outname;
01198 
01199                 relocs = TRUE;
01200 
01201                 /* If this relocation section applies to a read only
01202                    section, then we probably need a DT_TEXTREL
01203                    entry.  .rela.plt is actually associated with
01204                    .got.plt, which is never readonly.  */
01205                 outname = bfd_get_section_name (output_bfd,
01206                                             s->output_section);
01207                 target = bfd_get_section_by_name (output_bfd, outname + 5);
01208                 if (target != NULL
01209                     && (target->flags & SEC_READONLY) != 0
01210                     && (target->flags & SEC_ALLOC) != 0)
01211                   reltext = TRUE;
01212               }
01213 
01214              /* We use the reloc_count field as a counter if we need
01215                to copy relocs into the output file.  */
01216              s->reloc_count = 0;
01217            }
01218        }
01219       else if (! CONST_STRNEQ (name, ".got")
01220               && strcmp (name, ".dynbss") != 0)
01221        {
01222          /* It's not one of our sections, so don't allocate space.  */
01223          continue;
01224        }
01225 
01226       if (s->size == 0)
01227        {
01228          /* If we don't need this section, strip it from the
01229             output file.  This is mostly to handle .rela.bss and
01230             .rela.plt.  We must create both sections in
01231             create_dynamic_sections, because they must be created
01232             before the linker maps input sections to output
01233             sections.  The linker does that before
01234             adjust_dynamic_symbol is called, and it is that
01235             function which decides whether anything needs to go
01236             into these sections.  */
01237          s->flags |= SEC_EXCLUDE;
01238          continue;
01239        }
01240 
01241       if ((s->flags & SEC_HAS_CONTENTS) == 0)
01242        continue;
01243 
01244       /* Allocate memory for the section contents.  */
01245       s->contents = (bfd_byte *) bfd_alloc (dynobj, s->size);
01246       if (s->contents == NULL)
01247        return FALSE;
01248     }
01249 
01250   if (elf_hash_table (info)->dynamic_sections_created)
01251     {
01252       /* Add some entries to the .dynamic section.  We fill in the
01253         values later, in elf_vax_finish_dynamic_sections, but we
01254         must add the entries now so that we get the correct size for
01255         the .dynamic section.  The DT_DEBUG entry is filled in by the
01256         dynamic linker and used by the debugger.  */
01257 #define add_dynamic_entry(TAG, VAL) \
01258   _bfd_elf_add_dynamic_entry (info, TAG, VAL)
01259 
01260       if (!info->shared)
01261        {
01262          if (!add_dynamic_entry (DT_DEBUG, 0))
01263            return FALSE;
01264        }
01265 
01266       if (plt)
01267        {
01268          if (!add_dynamic_entry (DT_PLTGOT, 0)
01269              || !add_dynamic_entry (DT_PLTRELSZ, 0)
01270              || !add_dynamic_entry (DT_PLTREL, DT_RELA)
01271              || !add_dynamic_entry (DT_JMPREL, 0))
01272            return FALSE;
01273        }
01274 
01275       if (relocs)
01276        {
01277          if (!add_dynamic_entry (DT_RELA, 0)
01278              || !add_dynamic_entry (DT_RELASZ, 0)
01279              || !add_dynamic_entry (DT_RELAENT, sizeof (Elf32_External_Rela)))
01280            return FALSE;
01281        }
01282 
01283       if (reltext || (info->flags & DF_TEXTREL) != 0)
01284        {
01285          if (!add_dynamic_entry (DT_TEXTREL, 0))
01286            return FALSE;
01287        }
01288     }
01289 #undef add_dynamic_entry
01290 
01291   return TRUE;
01292 }
01293 
01294 /* This function is called via elf_vax_link_hash_traverse if we are
01295    creating a shared object with -Bsymbolic.  It discards the space
01296    allocated to copy PC relative relocs against symbols which are defined
01297    in regular objects.  We allocated space for them in the check_relocs
01298    routine, but we won't fill them in in the relocate_section routine.  */
01299 
01300 static bfd_boolean
01301 elf_vax_discard_copies (struct elf_vax_link_hash_entry *h,
01302                      PTR ignore ATTRIBUTE_UNUSED)
01303 {
01304   struct elf_vax_pcrel_relocs_copied *s;
01305 
01306   if (h->root.root.type == bfd_link_hash_warning)
01307     h = (struct elf_vax_link_hash_entry *) h->root.root.u.i.link;
01308 
01309   /* We only discard relocs for symbols defined in a regular object.  */
01310   if (!h->root.def_regular)
01311     return TRUE;
01312 
01313   for (s = h->pcrel_relocs_copied; s != NULL; s = s->next)
01314     s->section->size -= s->count * sizeof (Elf32_External_Rela);
01315 
01316   return TRUE;
01317 }
01318 
01319 /* This function is called via elf_link_hash_traverse.  It looks for entries
01320    that have GOT or PLT (.GOT) references.  If creating a static object or a
01321    shared object with -Bsymbolic, it resets the reference count back to 0
01322    and sets the offset to -1 so normal PC32 relocation will be done.  If
01323    creating a shared object or executable, space in the .got and .rela.got
01324    will be reserved for the symbol.  */
01325 
01326 static bfd_boolean
01327 elf_vax_instantiate_got_entries (struct elf_link_hash_entry *h, PTR infoptr)
01328 {
01329   struct bfd_link_info *info = (struct bfd_link_info *) infoptr;
01330   bfd *dynobj;
01331   asection *sgot;
01332   asection *srelgot;
01333 
01334   /* We don't care about non-GOT (and non-PLT) entries.  */
01335   if (h->got.refcount <= 0 && h->plt.refcount <= 0)
01336     return TRUE;
01337 
01338   dynobj = elf_hash_table (info)->dynobj;
01339   if (dynobj == NULL)
01340     return TRUE;
01341 
01342   sgot = bfd_get_section_by_name (dynobj, ".got");
01343   srelgot = bfd_get_section_by_name (dynobj, ".rela.got");
01344 
01345   if (!elf_hash_table (info)->dynamic_sections_created
01346       || (info->shared && info->symbolic))
01347     {
01348       h->got.refcount = 0;
01349       h->got.offset = (bfd_vma) -1;
01350       h->plt.refcount = 0;
01351       h->plt.offset = (bfd_vma) -1;
01352     }
01353   else if (h->got.refcount > 0)
01354     {
01355       /* Make sure this symbol is output as a dynamic symbol.  */
01356       if (h->dynindx == -1)
01357        {
01358          if (!bfd_elf_link_record_dynamic_symbol (info, h))
01359            return FALSE;
01360        }
01361 
01362       /* Allocate space in the .got and .rela.got sections.  */
01363       sgot->size += 4;
01364       srelgot->size += sizeof (Elf32_External_Rela);
01365     }
01366 
01367   return TRUE;
01368 }
01369 
01370 /* Relocate an VAX ELF section.  */
01371 
01372 static bfd_boolean
01373 elf_vax_relocate_section (bfd *output_bfd,
01374                        struct bfd_link_info *info,
01375                        bfd *input_bfd,
01376                        asection *input_section,
01377                        bfd_byte *contents,
01378                        Elf_Internal_Rela *relocs,
01379                        Elf_Internal_Sym *local_syms,
01380                        asection **local_sections)
01381 {
01382   bfd *dynobj;
01383   Elf_Internal_Shdr *symtab_hdr;
01384   struct elf_link_hash_entry **sym_hashes;
01385   bfd_vma *local_got_offsets;
01386   bfd_vma plt_index;
01387   bfd_vma got_offset;
01388   asection *sgot;
01389   asection *splt;
01390   asection *sgotplt;
01391   asection *sreloc;
01392   Elf_Internal_Rela *rel;
01393   Elf_Internal_Rela *relend;
01394 
01395   dynobj = elf_hash_table (info)->dynobj;
01396   symtab_hdr = &elf_tdata (input_bfd)->symtab_hdr;
01397   sym_hashes = elf_sym_hashes (input_bfd);
01398   local_got_offsets = elf_local_got_offsets (input_bfd);
01399 
01400   sgot = NULL;
01401   splt = NULL;
01402   sgotplt = NULL;
01403   sreloc = NULL;
01404 
01405   rel = relocs;
01406   relend = relocs + input_section->reloc_count;
01407   for (; rel < relend; rel++)
01408     {
01409       int r_type;
01410       reloc_howto_type *howto;
01411       unsigned long r_symndx;
01412       struct elf_link_hash_entry *h;
01413       Elf_Internal_Sym *sym;
01414       asection *sec;
01415       bfd_vma relocation;
01416       bfd_reloc_status_type r;
01417 
01418       r_type = ELF32_R_TYPE (rel->r_info);
01419       if (r_type < 0 || r_type >= (int) R_VAX_max)
01420        {
01421          bfd_set_error (bfd_error_bad_value);
01422          return FALSE;
01423        }
01424       howto = howto_table + r_type;
01425 
01426       r_symndx = ELF32_R_SYM (rel->r_info);
01427       h = NULL;
01428       sym = NULL;
01429       sec = NULL;
01430       if (r_symndx < symtab_hdr->sh_info)
01431        {
01432          sym = local_syms + r_symndx;
01433          sec = local_sections[r_symndx];
01434          relocation = _bfd_elf_rela_local_sym (output_bfd, sym, &sec, rel);
01435        }
01436       else
01437        {
01438          bfd_boolean unresolved_reloc;
01439          bfd_boolean warned;
01440 
01441          RELOC_FOR_GLOBAL_SYMBOL (info, input_bfd, input_section, rel,
01442                                r_symndx, symtab_hdr, sym_hashes,
01443                                h, sec, relocation,
01444                                unresolved_reloc, warned);
01445 
01446          if ((h->root.type == bfd_link_hash_defined
01447              || h->root.type == bfd_link_hash_defweak)
01448              && ((r_type == R_VAX_PLT32
01449                  && h->plt.offset != (bfd_vma) -1
01450                  && elf_hash_table (info)->dynamic_sections_created)
01451                 || (r_type == R_VAX_GOT32
01452                     && strcmp (h->root.root.string,
01453                              "_GLOBAL_OFFSET_TABLE_") != 0
01454                     && elf_hash_table (info)->dynamic_sections_created
01455                     && (! info->shared
01456                        || (! info->symbolic && h->dynindx != -1)
01457                        || !h->def_regular))
01458                 || (info->shared
01459                     && ((! info->symbolic && h->dynindx != -1)
01460                        || !h->def_regular)
01461                     && ((input_section->flags & SEC_ALLOC) != 0
01462                        /* DWARF will emit R_VAX_32 relocations in its
01463                           sections against symbols defined externally
01464                           in shared libraries.  We can't do anything
01465                           with them here.  */
01466 
01467                        || ((input_section->flags & SEC_DEBUGGING) != 0
01468                            && h->def_dynamic))
01469                     && (r_type == R_VAX_8
01470                        || r_type == R_VAX_16
01471                        || r_type == R_VAX_32
01472                        || r_type == R_VAX_PC8
01473                        || r_type == R_VAX_PC16
01474                        || r_type == R_VAX_PC32))))
01475            /* In these cases, we don't need the relocation
01476               value.  We check specially because in some
01477               obscure cases sec->output_section will be NULL.  */
01478            relocation = 0;
01479        }
01480 
01481       if (sec != NULL && elf_discarded_section (sec))
01482        {
01483          /* For relocs against symbols from removed linkonce sections,
01484             or sections discarded by a linker script, we just want the
01485             section contents zeroed.  Avoid any special processing.  */
01486          _bfd_clear_contents (howto, input_bfd, contents + rel->r_offset);
01487          rel->r_info = 0;
01488          rel->r_addend = 0;
01489          continue;
01490        }
01491 
01492       if (info->relocatable)
01493        continue;
01494 
01495       switch (r_type)
01496        {
01497        case R_VAX_GOT32:
01498          /* Relocation is to the address of the entry for this symbol
01499             in the global offset table.  */
01500          if (h == NULL || h->got.offset == (bfd_vma) -1)
01501            break;
01502 
01503          /* Relocation is the offset of the entry for this symbol in
01504             the global offset table.  */
01505 
01506          {
01507            bfd_vma off;
01508 
01509            if (sgot == NULL)
01510              {
01511               sgot = bfd_get_section_by_name (dynobj, ".got");
01512               BFD_ASSERT (sgot != NULL);
01513              }
01514 
01515            BFD_ASSERT (h != NULL);
01516            off = h->got.offset;
01517            BFD_ASSERT (off != (bfd_vma) -1);
01518            BFD_ASSERT (off < sgot->size);
01519 
01520            if (info->shared
01521               && h->dynindx == -1
01522               && h->def_regular)
01523              {
01524               /* The symbol was forced to be local
01525                  because of a version file..  We must initialize
01526                  this entry in the global offset table.  Since
01527                  the offset must always be a multiple of 4, we
01528                  use the least significant bit to record whether
01529                  we have initialized it already.
01530 
01531                  When doing a dynamic link, we create a .rela.got
01532                  relocation entry to initialize the value.  This
01533                  is done in the finish_dynamic_symbol routine.  */
01534               if ((off & 1) != 0)
01535                 off &= ~1;
01536               else
01537                 {
01538                   bfd_put_32 (output_bfd, relocation + rel->r_addend,
01539                             sgot->contents + off);
01540                   h->got.offset |= 1;
01541                 }
01542              } else {
01543               bfd_put_32 (output_bfd, rel->r_addend, sgot->contents + off);
01544              }
01545 
01546            relocation = sgot->output_offset + off;
01547            /* The GOT relocation uses the addend.  */
01548            rel->r_addend = 0;
01549 
01550            /* Change the reference to be indirect.  */
01551            contents[rel->r_offset - 1] |= 0x10;
01552            relocation += sgot->output_section->vma;
01553          }
01554          break;
01555 
01556        case R_VAX_PLT32:
01557          /* Relocation is to the entry for this symbol in the
01558             procedure linkage table.  */
01559 
01560          /* Resolve a PLTxx reloc against a local symbol directly,
01561             without using the procedure linkage table.  */
01562          if (h == NULL)
01563            break;
01564 
01565          if (h->plt.offset == (bfd_vma) -1
01566              || !elf_hash_table (info)->dynamic_sections_created)
01567            {
01568              /* We didn't make a PLT entry for this symbol.  This
01569                happens when statically linking PIC code, or when
01570                using -Bsymbolic.  */
01571              break;
01572            }
01573 
01574          if (splt == NULL)
01575            {
01576              splt = bfd_get_section_by_name (dynobj, ".plt");
01577              BFD_ASSERT (splt != NULL);
01578            }
01579 
01580          if (sgotplt == NULL)
01581            {
01582              sgotplt = bfd_get_section_by_name (dynobj, ".got.plt");
01583              BFD_ASSERT (splt != NULL);
01584            }
01585 
01586          plt_index = h->plt.offset / PLT_ENTRY_SIZE - 1;
01587 
01588          /* Get the offset into the .got table of the entry that
01589             corresponds to this function.  Each .got entry is 4 bytes.
01590             The first two are reserved.  */
01591          got_offset = (plt_index + 3) * 4;
01592 
01593          /* We want the relocate to point into the .got.plt instead
01594             of the plt itself.  */
01595          relocation = (sgotplt->output_section->vma
01596                      + sgotplt->output_offset
01597                      + got_offset);
01598          contents[rel->r_offset-1] |= 0x10; /* make indirect */
01599          if (rel->r_addend == 2)
01600            {
01601              h->plt.offset |= 1;
01602            }
01603          else if (rel->r_addend != 0)
01604            (*_bfd_error_handler)
01605              (_("%s: warning: PLT addend of %d to `%s' from %s section ignored"),
01606                     bfd_get_filename (input_bfd), rel->r_addend,
01607                     h->root.root.string,
01608                     bfd_get_section_name (input_bfd, input_section));
01609          rel->r_addend = 0;
01610 
01611          break;
01612 
01613        case R_VAX_PC8:
01614        case R_VAX_PC16:
01615        case R_VAX_PC32:
01616          if (h == NULL)
01617            break;
01618          /* Fall through.  */
01619        case R_VAX_8:
01620        case R_VAX_16:
01621        case R_VAX_32:
01622          if (info->shared
01623              && r_symndx != 0
01624              && (input_section->flags & SEC_ALLOC) != 0
01625              && ((r_type != R_VAX_PC8
01626                  && r_type != R_VAX_PC16
01627                  && r_type != R_VAX_PC32)
01628                 || (!info->symbolic
01629                     || !h->def_regular)))
01630            {
01631              Elf_Internal_Rela outrel;
01632              bfd_byte *loc;
01633              bfd_boolean skip, relocate;
01634 
01635              /* When generating a shared object, these relocations
01636                are copied into the output file to be resolved at run
01637                time.  */
01638              if (sreloc == NULL)
01639               {
01640                 const char *name;
01641 
01642                 name = (bfd_elf_string_from_elf_section
01643                        (input_bfd,
01644                         elf_elfheader (input_bfd)->e_shstrndx,
01645                         elf_section_data (input_section)->rel_hdr.sh_name));
01646                 if (name == NULL)
01647                   return FALSE;
01648 
01649                 BFD_ASSERT (CONST_STRNEQ (name, ".rela")
01650                            && strcmp (bfd_get_section_name (input_bfd,
01651                                                         input_section),
01652                                     name + 5) == 0);
01653 
01654                 sreloc = bfd_get_section_by_name (dynobj, name);
01655                 BFD_ASSERT (sreloc != NULL);
01656               }
01657 
01658              skip = FALSE;
01659              relocate = FALSE;
01660 
01661              outrel.r_offset =
01662               _bfd_elf_section_offset (output_bfd, info, input_section,
01663                                     rel->r_offset);
01664              if (outrel.r_offset == (bfd_vma) -1)
01665               skip = TRUE;
01666              if (outrel.r_offset == (bfd_vma) -2)
01667               skip = TRUE, relocate = TRUE;
01668              outrel.r_offset += (input_section->output_section->vma
01669                               + input_section->output_offset);
01670 
01671              if (skip)
01672                 memset (&outrel, 0, sizeof outrel);
01673              /* h->dynindx may be -1 if the symbol was marked to
01674                  become local.  */
01675              else if (h != NULL
01676                      && ((! info->symbolic && h->dynindx != -1)
01677                         || !h->def_regular))
01678               {
01679                 BFD_ASSERT (h->dynindx != -1);
01680                 outrel.r_info = ELF32_R_INFO (h->dynindx, r_type);
01681                 outrel.r_addend = relocation + rel->r_addend;
01682               }
01683              else
01684               {
01685                 if (r_type == R_VAX_32)
01686                   {
01687                     relocate = TRUE;
01688                     outrel.r_info = ELF32_R_INFO (0, R_VAX_RELATIVE);
01689                     BFD_ASSERT (bfd_get_signed_32 (input_bfd,
01690                                                &contents[rel->r_offset]) == 0);
01691                     outrel.r_addend = relocation + rel->r_addend;
01692                   }
01693                 else
01694                   {
01695                     long indx;
01696 
01697                     if (bfd_is_abs_section (sec))
01698                      indx = 0;
01699                     else if (sec == NULL || sec->owner == NULL)
01700                      {
01701                        bfd_set_error (bfd_error_bad_value);
01702                        return FALSE;
01703                      }
01704                     else
01705                      {
01706                        asection *osec;
01707 
01708                        /* We are turning this relocation into one
01709                           against a section symbol.  It would be
01710                           proper to subtract the symbol's value,
01711                           osec->vma, from the emitted reloc addend,
01712                           but ld.so expects buggy relocs.  */
01713                        osec = sec->output_section;
01714                        indx = elf_section_data (osec)->dynindx;
01715                        if (indx == 0)
01716                          {
01717                            struct elf_link_hash_table *htab;
01718                            htab = elf_hash_table (info);
01719                            osec = htab->text_index_section;
01720                            indx = elf_section_data (osec)->dynindx;
01721                          }
01722                        BFD_ASSERT (indx != 0);
01723                      }
01724 
01725                     outrel.r_info = ELF32_R_INFO (indx, r_type);
01726                     outrel.r_addend = relocation + rel->r_addend;
01727                   }
01728               }
01729 
01730              if (!strcmp (bfd_get_section_name (input_bfd, input_section),
01731                         ".text") != 0 ||
01732                 (info->shared
01733                  && ELF32_R_TYPE(outrel.r_info) != R_VAX_32
01734                  && ELF32_R_TYPE(outrel.r_info) != R_VAX_RELATIVE
01735                  && ELF32_R_TYPE(outrel.r_info) != R_VAX_COPY
01736                  && ELF32_R_TYPE(outrel.r_info) != R_VAX_JMP_SLOT
01737                  && ELF32_R_TYPE(outrel.r_info) != R_VAX_GLOB_DAT))
01738               {
01739                 if (h != NULL)
01740                   (*_bfd_error_handler)
01741                     (_("%s: warning: %s relocation against symbol `%s' from %s section"),
01742                     bfd_get_filename (input_bfd), howto->name,
01743                     h->root.root.string,
01744                     bfd_get_section_name (input_bfd, input_section));
01745                 else
01746                   (*_bfd_error_handler)
01747                     (_("%s: warning: %s relocation to 0x%x from %s section"),
01748                     bfd_get_filename (input_bfd), howto->name,
01749                     outrel.r_addend,
01750                     bfd_get_section_name (input_bfd, input_section));
01751               }
01752              loc = sreloc->contents;
01753              loc += sreloc->reloc_count++ * sizeof (Elf32_External_Rela);
01754              bfd_elf32_swap_reloca_out (output_bfd, &outrel, loc);
01755 
01756              /* This reloc will be computed at runtime, so there's no
01757                  need to do anything now, except for R_VAX_32
01758                  relocations that have been turned into
01759                  R_VAX_RELATIVE.  */
01760              if (!relocate)
01761               continue;
01762            }
01763 
01764          break;
01765 
01766        case R_VAX_GNU_VTINHERIT:
01767        case R_VAX_GNU_VTENTRY:
01768          /* These are no-ops in the end.  */
01769          continue;
01770 
01771        default:
01772          break;
01773        }
01774 
01775       /* VAX PCREL relocations are from the end of relocation, not the start.
01776          So subtract the difference from the relocation amount since we can't
01777          add it to the offset.  */
01778       if (howto->pc_relative && howto->pcrel_offset)
01779        relocation -= bfd_get_reloc_size(howto);
01780 
01781       r = _bfd_final_link_relocate (howto, input_bfd, input_section,
01782                                 contents, rel->r_offset,
01783                                 relocation, rel->r_addend);
01784 
01785       if (r != bfd_reloc_ok)
01786        {
01787          switch (r)
01788            {
01789            default:
01790            case bfd_reloc_outofrange:
01791              abort ();
01792            case bfd_reloc_overflow:
01793              {
01794               const char *name;
01795 
01796               if (h != NULL)
01797                 name = NULL;
01798               else
01799                 {
01800                   name = bfd_elf_string_from_elf_section (input_bfd,
01801                                                      symtab_hdr->sh_link,
01802                                                      sym->st_name);
01803                   if (name == NULL)
01804                     return FALSE;
01805                   if (*name == '\0')
01806                     name = bfd_section_name (input_bfd, sec);
01807                 }
01808               if (!(info->callbacks->reloc_overflow
01809                     (info, (h ? &h->root : NULL), name, howto->name,
01810                      (bfd_vma) 0, input_bfd, input_section,
01811                      rel->r_offset)))
01812                 return FALSE;
01813              }
01814              break;
01815            }
01816        }
01817     }
01818 
01819   return TRUE;
01820 }
01821 
01822 /* Finish up dynamic symbol handling.  We set the contents of various
01823    dynamic sections here.  */
01824 
01825 static bfd_boolean
01826 elf_vax_finish_dynamic_symbol (bfd *output_bfd, struct bfd_link_info *info,
01827                             struct elf_link_hash_entry *h,
01828                             Elf_Internal_Sym *sym)
01829 {
01830   bfd *dynobj;
01831 
01832   dynobj = elf_hash_table (info)->dynobj;
01833 
01834   if (h->plt.offset != (bfd_vma) -1)
01835     {
01836       asection *splt;
01837       asection *sgot;
01838       asection *srela;
01839       bfd_vma plt_index;
01840       bfd_vma got_offset;
01841       bfd_vma addend;
01842       Elf_Internal_Rela rela;
01843       bfd_byte *loc;
01844 
01845       /* This symbol has an entry in the procedure linkage table.  Set
01846         it up.  */
01847       BFD_ASSERT (h->dynindx != -1);
01848 
01849       splt = bfd_get_section_by_name (dynobj, ".plt");
01850       sgot = bfd_get_section_by_name (dynobj, ".got.plt");
01851       srela = bfd_get_section_by_name (dynobj, ".rela.plt");
01852       BFD_ASSERT (splt != NULL && sgot != NULL && srela != NULL);
01853 
01854       addend = 2 * (h->plt.offset & 1);
01855       h->plt.offset &= ~1;
01856 
01857       /* Get the index in the procedure linkage table which
01858         corresponds to this symbol.  This is the index of this symbol
01859         in all the symbols for which we are making plt entries.  The
01860         first entry in the procedure linkage table is reserved.  */
01861       plt_index = h->plt.offset / PLT_ENTRY_SIZE - 1;
01862 
01863       /* Get the offset into the .got table of the entry that
01864         corresponds to this function.  Each .got entry is 4 bytes.
01865         The first two are reserved.  */
01866       got_offset = (plt_index + 3) * 4;
01867 
01868       /* Fill in the entry in the procedure linkage table.  */
01869       memcpy (splt->contents + h->plt.offset, elf_vax_plt_entry,
01870                  PLT_ENTRY_SIZE);
01871 
01872       /* The offset is relative to the first extension word.  */
01873       bfd_put_32 (output_bfd,
01874                 -(h->plt.offset + 8),
01875                 splt->contents + h->plt.offset + 4);
01876 
01877       bfd_put_32 (output_bfd, plt_index * sizeof (Elf32_External_Rela),
01878                 splt->contents + h->plt.offset + 8);
01879 
01880       /* Fill in the entry in the global offset table.  */
01881       bfd_put_32 (output_bfd,
01882                 (splt->output_section->vma
01883                  + splt->output_offset
01884                  + h->plt.offset) + addend,
01885                 sgot->contents + got_offset);
01886 
01887       /* Fill in the entry in the .rela.plt section.  */
01888       rela.r_offset = (sgot->output_section->vma
01889                      + sgot->output_offset
01890                      + got_offset);
01891       rela.r_info = ELF32_R_INFO (h->dynindx, R_VAX_JMP_SLOT);
01892       rela.r_addend = addend;
01893       loc = srela->contents + plt_index * sizeof (Elf32_External_Rela);
01894       bfd_elf32_swap_reloca_out (output_bfd, &rela, loc);
01895 
01896       if (!h->def_regular)
01897        {
01898          /* Mark the symbol as undefined, rather than as defined in
01899             the .plt section.  Leave the value alone.  */
01900          sym->st_shndx = SHN_UNDEF;
01901        }
01902     }
01903 
01904   if (h->got.offset != (bfd_vma) -1)
01905     {
01906       asection *sgot;
01907       asection *srela;
01908       Elf_Internal_Rela rela;
01909       bfd_byte *loc;
01910 
01911       /* This symbol has an entry in the global offset table.  Set it
01912         up.  */
01913       sgot = bfd_get_section_by_name (dynobj, ".got");
01914       srela = bfd_get_section_by_name (dynobj, ".rela.got");
01915       BFD_ASSERT (sgot != NULL && srela != NULL);
01916 
01917       rela.r_offset = (sgot->output_section->vma
01918                      + sgot->output_offset
01919                      + (h->got.offset &~ 1));
01920 
01921       /* If the symbol was forced to be local because of a version file
01922         locally we just want to emit a RELATIVE reloc.  The entry in
01923         the global offset table will already have been initialized in
01924         the relocate_section function.  */
01925       if (info->shared
01926          && h->dynindx == -1
01927          && h->def_regular)
01928        {
01929          rela.r_info = ELF32_R_INFO (0, R_VAX_RELATIVE);
01930        }
01931       else
01932        {
01933          rela.r_info = ELF32_R_INFO (h->dynindx, R_VAX_GLOB_DAT);
01934        }
01935       rela.r_addend = bfd_get_signed_32 (output_bfd,
01936                                     (sgot->contents
01937                                      + (h->got.offset & ~1)));
01938 
01939       loc = srela->contents;
01940       loc += srela->reloc_count++ * sizeof (Elf32_External_Rela);
01941       bfd_elf32_swap_reloca_out (output_bfd, &rela, loc);
01942     }
01943 
01944   if (h->needs_copy)
01945     {
01946       asection *s;
01947       Elf_Internal_Rela rela;
01948       bfd_byte *loc;
01949 
01950       /* This symbol needs a copy reloc.  Set it up.  */
01951       BFD_ASSERT (h->dynindx != -1
01952                 && (h->root.type == bfd_link_hash_defined
01953                     || h->root.type == bfd_link_hash_defweak));
01954 
01955       s = bfd_get_section_by_name (h->root.u.def.section->owner,
01956                                ".rela.bss");
01957       BFD_ASSERT (s != NULL);
01958 
01959       rela.r_offset = (h->root.u.def.value
01960                      + h->root.u.def.section->output_section->vma
01961                      + h->root.u.def.section->output_offset);
01962       rela.r_info = ELF32_R_INFO (h->dynindx, R_VAX_COPY);
01963       rela.r_addend = 0;
01964       loc = s->contents + s->reloc_count++ * sizeof (Elf32_External_Rela);
01965       bfd_elf32_swap_reloca_out (output_bfd, &rela, loc);
01966     }
01967 
01968   /* Mark _DYNAMIC and _GLOBAL_OFFSET_TABLE_ as absolute.  */
01969   if (strcmp (h->root.root.string, "_DYNAMIC") == 0
01970       || h == elf_hash_table (info)->hgot)
01971     sym->st_shndx = SHN_ABS;
01972 
01973   return TRUE;
01974 }
01975 
01976 /* Finish up the dynamic sections.  */
01977 
01978 static bfd_boolean
01979 elf_vax_finish_dynamic_sections (bfd *output_bfd, struct bfd_link_info *info)
01980 {
01981   bfd *dynobj;
01982   asection *sgot;
01983   asection *sdyn;
01984 
01985   dynobj = elf_hash_table (info)->dynobj;
01986 
01987   sgot = bfd_get_section_by_name (dynobj, ".got.plt");
01988   BFD_ASSERT (sgot != NULL);
01989   sdyn = bfd_get_section_by_name (dynobj, ".dynamic");
01990 
01991   if (elf_hash_table (info)->dynamic_sections_created)
01992     {
01993       asection *splt;
01994       Elf32_External_Dyn *dyncon, *dynconend;
01995 
01996       splt = bfd_get_section_by_name (dynobj, ".plt");
01997       BFD_ASSERT (splt != NULL && sdyn != NULL);
01998 
01999       dyncon = (Elf32_External_Dyn *) sdyn->contents;
02000       dynconend = (Elf32_External_Dyn *) (sdyn->contents + sdyn->size);
02001       for (; dyncon < dynconend; dyncon++)
02002        {
02003          Elf_Internal_Dyn dyn;
02004          const char *name;
02005          asection *s;
02006 
02007          bfd_elf32_swap_dyn_in (dynobj, dyncon, &dyn);
02008 
02009          switch (dyn.d_tag)
02010            {
02011            default:
02012              break;
02013 
02014            case DT_PLTGOT:
02015              name = ".got";
02016              goto get_vma;
02017            case DT_JMPREL:
02018              name = ".rela.plt";
02019            get_vma:
02020              s = bfd_get_section_by_name (output_bfd, name);
02021              BFD_ASSERT (s != NULL);
02022              dyn.d_un.d_ptr = s->vma;
02023              bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon);
02024              break;
02025 
02026            case DT_PLTRELSZ:
02027              s = bfd_get_section_by_name (output_bfd, ".rela.plt");
02028              BFD_ASSERT (s != NULL);
02029              dyn.d_un.d_val = s->size;
02030              bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon);
02031              break;
02032 
02033            case DT_RELASZ:
02034              /* The procedure linkage table relocs (DT_JMPREL) should
02035                not be included in the overall relocs (DT_RELA).
02036                Therefore, we override the DT_RELASZ entry here to
02037                make it not include the JMPREL relocs.  Since the
02038                linker script arranges for .rela.plt to follow all
02039                other relocation sections, we don't have to worry
02040                about changing the DT_RELA entry.  */
02041              s = bfd_get_section_by_name (output_bfd, ".rela.plt");
02042              if (s != NULL)
02043               dyn.d_un.d_val -= s->size;
02044              bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon);
02045              break;
02046            }
02047        }
02048 
02049       /* Fill in the first entry in the procedure linkage table.  */
02050       if (splt->size > 0)
02051        {
02052          memcpy (splt->contents, elf_vax_plt0_entry, PLT_ENTRY_SIZE);
02053          bfd_put_32 (output_bfd,
02054                         (sgot->output_section->vma
02055                          + sgot->output_offset + 4
02056                          - (splt->output_section->vma + 6)),
02057                         splt->contents + 2);
02058          bfd_put_32 (output_bfd,
02059                         (sgot->output_section->vma
02060                          + sgot->output_offset + 8
02061                          - (splt->output_section->vma + 12)),
02062                         splt->contents + 8);
02063           elf_section_data (splt->output_section)->this_hdr.sh_entsize
02064            = PLT_ENTRY_SIZE;
02065        }
02066     }
02067 
02068   /* Fill in the first three entries in the global offset table.  */
02069   if (sgot->size > 0)
02070     {
02071       if (sdyn == NULL)
02072        bfd_put_32 (output_bfd, (bfd_vma) 0, sgot->contents);
02073       else
02074        bfd_put_32 (output_bfd,
02075                   sdyn->output_section->vma + sdyn->output_offset,
02076                   sgot->contents);
02077       bfd_put_32 (output_bfd, (bfd_vma) 0, sgot->contents + 4);
02078       bfd_put_32 (output_bfd, (bfd_vma) 0, sgot->contents + 8);
02079     }
02080 
02081   elf_section_data (sgot->output_section)->this_hdr.sh_entsize = 4;
02082 
02083   return TRUE;
02084 }
02085 
02086 #define TARGET_LITTLE_SYM          bfd_elf32_vax_vec
02087 #define TARGET_LITTLE_NAME         "elf32-vax"
02088 #define ELF_MACHINE_CODE           EM_VAX
02089 #define ELF_MAXPAGESIZE                   0x1000
02090 
02091 #define elf_backend_create_dynamic_sections \
02092                                    _bfd_elf_create_dynamic_sections
02093 #define bfd_elf32_bfd_link_hash_table_create \
02094                                    elf_vax_link_hash_table_create
02095 #define bfd_elf32_bfd_final_link   bfd_elf_gc_common_final_link
02096 
02097 #define elf_backend_check_relocs   elf_vax_check_relocs
02098 #define elf_backend_adjust_dynamic_symbol \
02099                                    elf_vax_adjust_dynamic_symbol
02100 #define elf_backend_size_dynamic_sections \
02101                                    elf_vax_size_dynamic_sections
02102 #define elf_backend_init_index_section    _bfd_elf_init_1_index_section
02103 #define elf_backend_relocate_section      elf_vax_relocate_section
02104 #define elf_backend_finish_dynamic_symbol \
02105                                    elf_vax_finish_dynamic_symbol
02106 #define elf_backend_finish_dynamic_sections \
02107                                    elf_vax_finish_dynamic_sections
02108 #define elf_backend_gc_mark_hook   elf_vax_gc_mark_hook
02109 #define elf_backend_gc_sweep_hook  elf_vax_gc_sweep_hook
02110 #define bfd_elf32_bfd_merge_private_bfd_data \
02111                                         elf32_vax_merge_private_bfd_data
02112 #define bfd_elf32_bfd_set_private_flags \
02113                                         elf32_vax_set_private_flags
02114 #define bfd_elf32_bfd_print_private_bfd_data \
02115                                         elf32_vax_print_private_bfd_data
02116 
02117 #define elf_backend_can_gc_sections       1
02118 #define elf_backend_want_got_plt   1
02119 #define elf_backend_plt_readonly   1
02120 #define elf_backend_want_plt_sym   0
02121 #define elf_backend_got_header_size       16
02122 #define elf_backend_rela_normal           1
02123 
02124 #include "elf32-target.h"