Back to index

cell-binutils  2.17cvs20070401
elf64-s390.c
Go to the documentation of this file.
00001 /* IBM S/390-specific support for 64-bit ELF
00002    Copyright 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007
00003    Free Software Foundation, Inc.
00004    Contributed Martin Schwidefsky (schwidefsky@de.ibm.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
00021    02110-1301, USA.  */
00022 
00023 #include "bfd.h"
00024 #include "sysdep.h"
00025 #include "bfdlink.h"
00026 #include "libbfd.h"
00027 #include "elf-bfd.h"
00028 
00029 static reloc_howto_type *elf_s390_reloc_type_lookup
00030   PARAMS ((bfd *, bfd_reloc_code_real_type));
00031 static void elf_s390_info_to_howto
00032   PARAMS ((bfd *, arelent *, Elf_Internal_Rela *));
00033 static bfd_boolean elf_s390_is_local_label_name
00034   PARAMS ((bfd *, const char *));
00035 static struct bfd_hash_entry *link_hash_newfunc
00036   PARAMS ((struct bfd_hash_entry *, struct bfd_hash_table *, const char *));
00037 static struct bfd_link_hash_table *elf_s390_link_hash_table_create
00038   PARAMS ((bfd *));
00039 static bfd_boolean create_got_section
00040   PARAMS((bfd *, struct bfd_link_info *));
00041 static bfd_boolean elf_s390_create_dynamic_sections
00042   PARAMS((bfd *, struct bfd_link_info *));
00043 static void elf_s390_copy_indirect_symbol
00044   PARAMS ((struct bfd_link_info *, struct elf_link_hash_entry *,
00045           struct elf_link_hash_entry *));
00046 static bfd_boolean elf_s390_check_relocs
00047   PARAMS ((bfd *, struct bfd_link_info *, asection *,
00048           const Elf_Internal_Rela *));
00049 struct elf_s390_link_hash_entry;
00050 static void elf_s390_adjust_gotplt
00051   PARAMS ((struct elf_s390_link_hash_entry *));
00052 static bfd_boolean elf_s390_adjust_dynamic_symbol
00053   PARAMS ((struct bfd_link_info *, struct elf_link_hash_entry *));
00054 static bfd_boolean allocate_dynrelocs
00055   PARAMS ((struct elf_link_hash_entry *, PTR));
00056 static bfd_boolean readonly_dynrelocs
00057   PARAMS ((struct elf_link_hash_entry *, PTR));
00058 static bfd_boolean elf_s390_size_dynamic_sections
00059   PARAMS ((bfd *, struct bfd_link_info *));
00060 static bfd_boolean elf_s390_relocate_section
00061   PARAMS ((bfd *, struct bfd_link_info *, bfd *, asection *, bfd_byte *,
00062           Elf_Internal_Rela *, Elf_Internal_Sym *, asection **));
00063 static bfd_boolean elf_s390_finish_dynamic_symbol
00064   PARAMS ((bfd *, struct bfd_link_info *, struct elf_link_hash_entry *,
00065           Elf_Internal_Sym *));
00066 static enum elf_reloc_type_class elf_s390_reloc_type_class
00067   PARAMS ((const Elf_Internal_Rela *));
00068 static bfd_boolean elf_s390_finish_dynamic_sections
00069   PARAMS ((bfd *, struct bfd_link_info *));
00070 static bfd_boolean elf_s390_object_p
00071   PARAMS ((bfd *));
00072 static int elf_s390_tls_transition
00073   PARAMS ((struct bfd_link_info *, int, int));
00074 static bfd_reloc_status_type s390_tls_reloc
00075   PARAMS ((bfd *, arelent *, asymbol *, PTR, asection *, bfd *, char **));
00076 static bfd_vma dtpoff_base
00077   PARAMS ((struct bfd_link_info *));
00078 static bfd_vma tpoff
00079   PARAMS ((struct bfd_link_info *, bfd_vma));
00080 static void invalid_tls_insn
00081   PARAMS ((bfd *, asection *, Elf_Internal_Rela *));
00082 static bfd_reloc_status_type s390_elf_ldisp_reloc
00083   PARAMS ((bfd *, arelent *, asymbol *, PTR, asection *, bfd *, char **));
00084 
00085 #include "elf/s390.h"
00086 
00087 /* In case we're on a 32-bit machine, construct a 64-bit "-1" value
00088    from smaller values.  Start with zero, widen, *then* decrement.  */
00089 #define MINUS_ONE      (((bfd_vma)0) - 1)
00090 
00091 /* The relocation "howto" table.  */
00092 static reloc_howto_type elf_howto_table[] =
00093 {
00094   HOWTO (R_390_NONE,        /* type */
00095         0,                  /* rightshift */
00096         0,                  /* size (0 = byte, 1 = short, 2 = long) */
00097         0,                  /* bitsize */
00098         FALSE,                     /* pc_relative */
00099         0,                  /* bitpos */
00100         complain_overflow_dont, /* complain_on_overflow */
00101         bfd_elf_generic_reloc, /* special_function */
00102         "R_390_NONE",              /* name */
00103         FALSE,                     /* partial_inplace */
00104         0,                  /* src_mask */
00105         0,                  /* dst_mask */
00106         FALSE),             /* pcrel_offset */
00107 
00108   HOWTO(R_390_8,         0, 0,  8, FALSE, 0, complain_overflow_bitfield,
00109        bfd_elf_generic_reloc, "R_390_8",        FALSE, 0,0x000000ff, FALSE),
00110   HOWTO(R_390_12,        0, 1, 12, FALSE, 0, complain_overflow_dont,
00111        bfd_elf_generic_reloc, "R_390_12",       FALSE, 0,0x00000fff, FALSE),
00112   HOWTO(R_390_16,        0, 1, 16, FALSE, 0, complain_overflow_bitfield,
00113        bfd_elf_generic_reloc, "R_390_16",       FALSE, 0,0x0000ffff, FALSE),
00114   HOWTO(R_390_32,        0, 2, 32, FALSE, 0, complain_overflow_bitfield,
00115        bfd_elf_generic_reloc, "R_390_32",       FALSE, 0,0xffffffff, FALSE),
00116   HOWTO(R_390_PC32,   0, 2, 32,  TRUE, 0, complain_overflow_bitfield,
00117        bfd_elf_generic_reloc, "R_390_PC32",     FALSE, 0,0xffffffff, TRUE),
00118   HOWTO(R_390_GOT12,  0, 1, 12, FALSE, 0, complain_overflow_bitfield,
00119        bfd_elf_generic_reloc, "R_390_GOT12",    FALSE, 0,0x00000fff, FALSE),
00120   HOWTO(R_390_GOT32,  0, 2, 32, FALSE, 0, complain_overflow_bitfield,
00121        bfd_elf_generic_reloc, "R_390_GOT32",    FALSE, 0,0xffffffff, FALSE),
00122   HOWTO(R_390_PLT32,  0, 2, 32,  TRUE, 0, complain_overflow_bitfield,
00123        bfd_elf_generic_reloc, "R_390_PLT32",    FALSE, 0,0xffffffff, TRUE),
00124   HOWTO(R_390_COPY,      0, 4, 64, FALSE, 0, complain_overflow_bitfield,
00125        bfd_elf_generic_reloc, "R_390_COPY",     FALSE, 0,MINUS_ONE,  FALSE),
00126   HOWTO(R_390_GLOB_DAT,  0, 4, 64, FALSE, 0, complain_overflow_bitfield,
00127        bfd_elf_generic_reloc, "R_390_GLOB_DAT", FALSE, 0,MINUS_ONE,  FALSE),
00128   HOWTO(R_390_JMP_SLOT,  0, 4, 64, FALSE, 0, complain_overflow_bitfield,
00129        bfd_elf_generic_reloc, "R_390_JMP_SLOT", FALSE, 0,MINUS_ONE,  FALSE),
00130   HOWTO(R_390_RELATIVE,  0, 4, 64,  TRUE, 0, complain_overflow_bitfield,
00131        bfd_elf_generic_reloc, "R_390_RELATIVE", FALSE, 0,MINUS_ONE,  FALSE),
00132   HOWTO(R_390_GOTOFF32,  0, 2, 32, FALSE, 0, complain_overflow_bitfield,
00133        bfd_elf_generic_reloc, "R_390_GOTOFF32", FALSE, 0,MINUS_ONE,  FALSE),
00134   HOWTO(R_390_GOTPC,     0, 4, 64,  TRUE, 0, complain_overflow_bitfield,
00135        bfd_elf_generic_reloc, "R_390_GOTPC",    FALSE, 0,MINUS_ONE,  TRUE),
00136   HOWTO(R_390_GOT16,     0, 1, 16, FALSE, 0, complain_overflow_bitfield,
00137        bfd_elf_generic_reloc, "R_390_GOT16",    FALSE, 0,0x0000ffff, FALSE),
00138   HOWTO(R_390_PC16,      0, 1, 16,  TRUE, 0, complain_overflow_bitfield,
00139        bfd_elf_generic_reloc, "R_390_PC16",     FALSE, 0,0x0000ffff, TRUE),
00140   HOWTO(R_390_PC16DBL,   1, 1, 16,  TRUE, 0, complain_overflow_bitfield,
00141        bfd_elf_generic_reloc, "R_390_PC16DBL",  FALSE, 0,0x0000ffff, TRUE),
00142   HOWTO(R_390_PLT16DBL,  1, 1, 16,  TRUE, 0, complain_overflow_bitfield,
00143        bfd_elf_generic_reloc, "R_390_PLT16DBL", FALSE, 0,0x0000ffff, TRUE),
00144   HOWTO(R_390_PC32DBL,       1, 2, 32,  TRUE, 0, complain_overflow_bitfield,
00145        bfd_elf_generic_reloc, "R_390_PC32DBL",  FALSE, 0,0xffffffff, TRUE),
00146   HOWTO(R_390_PLT32DBL,      1, 2, 32,  TRUE, 0, complain_overflow_bitfield,
00147        bfd_elf_generic_reloc, "R_390_PLT32DBL", FALSE, 0,0xffffffff, TRUE),
00148   HOWTO(R_390_GOTPCDBL,  1, 2, 32,  TRUE, 0, complain_overflow_bitfield,
00149        bfd_elf_generic_reloc, "R_390_GOTPCDBL", FALSE, 0,MINUS_ONE,  TRUE),
00150   HOWTO(R_390_64,        0, 4, 64, FALSE, 0, complain_overflow_bitfield,
00151        bfd_elf_generic_reloc, "R_390_64",       FALSE, 0,MINUS_ONE,  FALSE),
00152   HOWTO(R_390_PC64,   0, 4, 64,  TRUE, 0, complain_overflow_bitfield,
00153        bfd_elf_generic_reloc, "R_390_PC64",     FALSE, 0,MINUS_ONE,  TRUE),
00154   HOWTO(R_390_GOT64,  0, 4, 64, FALSE, 0, complain_overflow_bitfield,
00155        bfd_elf_generic_reloc, "R_390_GOT64",    FALSE, 0,MINUS_ONE,  FALSE),
00156   HOWTO(R_390_PLT64,  0, 4, 64,  TRUE, 0, complain_overflow_bitfield,
00157        bfd_elf_generic_reloc, "R_390_PLT64",    FALSE, 0,MINUS_ONE,  TRUE),
00158   HOWTO(R_390_GOTENT,        1, 2, 32,  TRUE, 0, complain_overflow_bitfield,
00159        bfd_elf_generic_reloc, "R_390_GOTENT",   FALSE, 0,MINUS_ONE,  TRUE),
00160   HOWTO(R_390_GOTOFF16,  0, 1, 16, FALSE, 0, complain_overflow_bitfield,
00161        bfd_elf_generic_reloc, "R_390_GOTOFF16", FALSE, 0,0x0000ffff, FALSE),
00162   HOWTO(R_390_GOTOFF64,  0, 4, 64, FALSE, 0, complain_overflow_bitfield,
00163        bfd_elf_generic_reloc, "R_390_GOTOFF64", FALSE, 0,MINUS_ONE,  FALSE),
00164   HOWTO(R_390_GOTPLT12,      0, 1, 12, FALSE, 0, complain_overflow_dont,
00165        bfd_elf_generic_reloc, "R_390_GOTPLT12", FALSE, 0,0x00000fff, FALSE),
00166   HOWTO(R_390_GOTPLT16,  0, 1, 16, FALSE, 0, complain_overflow_bitfield,
00167        bfd_elf_generic_reloc, "R_390_GOTPLT16", FALSE, 0,0x0000ffff, FALSE),
00168   HOWTO(R_390_GOTPLT32,      0, 2, 32, FALSE, 0, complain_overflow_bitfield,
00169        bfd_elf_generic_reloc, "R_390_GOTPLT32", FALSE, 0,0xffffffff, FALSE),
00170   HOWTO(R_390_GOTPLT64,      0, 4, 64, FALSE, 0, complain_overflow_bitfield,
00171        bfd_elf_generic_reloc, "R_390_GOTPLT64", FALSE, 0,MINUS_ONE,  FALSE),
00172   HOWTO(R_390_GOTPLTENT, 1, 2, 32,  TRUE, 0, complain_overflow_bitfield,
00173        bfd_elf_generic_reloc, "R_390_GOTPLTENT",FALSE, 0,MINUS_ONE,  TRUE),
00174   HOWTO(R_390_PLTOFF16,  0, 1, 16, FALSE, 0, complain_overflow_bitfield,
00175        bfd_elf_generic_reloc, "R_390_PLTOFF16", FALSE, 0,0x0000ffff, FALSE),
00176   HOWTO(R_390_PLTOFF32,  0, 2, 32, FALSE, 0, complain_overflow_bitfield,
00177        bfd_elf_generic_reloc, "R_390_PLTOFF32", FALSE, 0,0xffffffff, FALSE),
00178   HOWTO(R_390_PLTOFF64,  0, 4, 64, FALSE, 0, complain_overflow_bitfield,
00179        bfd_elf_generic_reloc, "R_390_PLTOFF64", FALSE, 0,MINUS_ONE,  FALSE),
00180   HOWTO(R_390_TLS_LOAD, 0, 0, 0, FALSE, 0, complain_overflow_dont,
00181        s390_tls_reloc, "R_390_TLS_LOAD", FALSE, 0, 0, FALSE),
00182   HOWTO(R_390_TLS_GDCALL, 0, 0, 0, FALSE, 0, complain_overflow_dont,
00183        s390_tls_reloc, "R_390_TLS_GDCALL", FALSE, 0, 0, FALSE),
00184   HOWTO(R_390_TLS_LDCALL, 0, 0, 0, FALSE, 0, complain_overflow_dont,
00185        s390_tls_reloc, "R_390_TLS_LDCALL", FALSE, 0, 0, FALSE),
00186   EMPTY_HOWTO (R_390_TLS_GD32),    /* Empty entry for R_390_TLS_GD32.  */
00187   HOWTO(R_390_TLS_GD64,  0, 4, 64, FALSE, 0, complain_overflow_bitfield,
00188        bfd_elf_generic_reloc, "R_390_TLS_GD64", FALSE, 0, MINUS_ONE, FALSE),
00189   HOWTO(R_390_TLS_GOTIE12, 0, 1, 12, FALSE, 0, complain_overflow_dont,
00190        bfd_elf_generic_reloc, "R_390_TLS_GOTIE12", FALSE, 0, 0x00000fff, FALSE),
00191   EMPTY_HOWTO (R_390_TLS_GOTIE32), /* Empty entry for R_390_TLS_GOTIE32.  */
00192   HOWTO(R_390_TLS_GOTIE64, 0, 4, 64, FALSE, 0, complain_overflow_bitfield,
00193        bfd_elf_generic_reloc, "R_390_TLS_GOTIE64", FALSE, 0, MINUS_ONE, FALSE),
00194   EMPTY_HOWTO (R_390_TLS_LDM32),   /* Empty entry for R_390_TLS_LDM32.  */
00195   HOWTO(R_390_TLS_LDM64, 0, 4, 64, FALSE, 0, complain_overflow_bitfield,
00196        bfd_elf_generic_reloc, "R_390_TLS_LDM64", FALSE, 0, MINUS_ONE, FALSE),
00197   EMPTY_HOWTO (R_390_TLS_IE32),    /* Empty entry for R_390_TLS_IE32.  */
00198   HOWTO(R_390_TLS_IE64,  0, 4, 64, FALSE, 0, complain_overflow_bitfield,
00199        bfd_elf_generic_reloc, "R_390_TLS_IE64", FALSE, 0, MINUS_ONE, FALSE),
00200   HOWTO(R_390_TLS_IEENT, 1, 2, 32, TRUE, 0, complain_overflow_bitfield,
00201        bfd_elf_generic_reloc, "R_390_TLS_IEENT", FALSE, 0, MINUS_ONE, TRUE),
00202   EMPTY_HOWTO (R_390_TLS_LE32),    /* Empty entry for R_390_TLS_LE32.  */
00203   HOWTO(R_390_TLS_LE64,  0, 2, 32, FALSE, 0, complain_overflow_bitfield,
00204        bfd_elf_generic_reloc, "R_390_TLS_LE64", FALSE, 0, MINUS_ONE, FALSE),
00205   EMPTY_HOWTO (R_390_TLS_LDO32),   /* Empty entry for R_390_TLS_LDO32.  */
00206   HOWTO(R_390_TLS_LDO64, 0, 4, 64, FALSE, 0, complain_overflow_bitfield,
00207        bfd_elf_generic_reloc, "R_390_TLS_LDO64", FALSE, 0, MINUS_ONE, FALSE),
00208   HOWTO(R_390_TLS_DTPMOD, 0, 4, 64, FALSE, 0, complain_overflow_bitfield,
00209        bfd_elf_generic_reloc, "R_390_TLS_DTPMOD", FALSE, 0, MINUS_ONE, FALSE),
00210   HOWTO(R_390_TLS_DTPOFF, 0, 4, 64, FALSE, 0, complain_overflow_bitfield,
00211        bfd_elf_generic_reloc, "R_390_TLS_DTPOFF", FALSE, 0, MINUS_ONE, FALSE),
00212   HOWTO(R_390_TLS_TPOFF, 0, 4, 64, FALSE, 0, complain_overflow_bitfield,
00213        bfd_elf_generic_reloc, "R_390_TLS_TPOFF", FALSE, 0, MINUS_ONE, FALSE),
00214   HOWTO(R_390_20,        0, 2, 20, FALSE, 8, complain_overflow_dont,
00215        s390_elf_ldisp_reloc, "R_390_20",      FALSE, 0,0x0fffff00, FALSE),
00216   HOWTO(R_390_GOT20,  0, 2, 20, FALSE, 8, complain_overflow_dont,
00217        s390_elf_ldisp_reloc, "R_390_GOT20",   FALSE, 0,0x0fffff00, FALSE),
00218   HOWTO(R_390_GOTPLT20,  0, 2, 20, FALSE, 8, complain_overflow_dont,
00219        s390_elf_ldisp_reloc, "R_390_GOTPLT20", FALSE, 0,0x0fffff00, FALSE),
00220   HOWTO(R_390_TLS_GOTIE20, 0, 2, 20, FALSE, 8, complain_overflow_dont,
00221        s390_elf_ldisp_reloc, "R_390_TLS_GOTIE20", FALSE, 0,0x0fffff00, FALSE),
00222 };
00223 
00224 /* GNU extension to record C++ vtable hierarchy.  */
00225 static reloc_howto_type elf64_s390_vtinherit_howto =
00226   HOWTO (R_390_GNU_VTINHERIT, 0,4,0,FALSE,0,complain_overflow_dont, NULL, "R_390_GNU_VTINHERIT", FALSE,0, 0, FALSE);
00227 static reloc_howto_type elf64_s390_vtentry_howto =
00228   HOWTO (R_390_GNU_VTENTRY, 0,4,0,FALSE,0,complain_overflow_dont, _bfd_elf_rel_vtable_reloc_fn,"R_390_GNU_VTENTRY", FALSE,0,0, FALSE);
00229 
00230 static reloc_howto_type *
00231 elf_s390_reloc_type_lookup (abfd, code)
00232      bfd *abfd ATTRIBUTE_UNUSED;
00233      bfd_reloc_code_real_type code;
00234 {
00235   switch (code)
00236     {
00237     case BFD_RELOC_NONE:
00238       return &elf_howto_table[(int) R_390_NONE];
00239     case BFD_RELOC_8:
00240       return &elf_howto_table[(int) R_390_8];
00241     case BFD_RELOC_390_12:
00242       return &elf_howto_table[(int) R_390_12];
00243     case BFD_RELOC_16:
00244       return &elf_howto_table[(int) R_390_16];
00245     case BFD_RELOC_32:
00246       return &elf_howto_table[(int) R_390_32];
00247     case BFD_RELOC_CTOR:
00248       return &elf_howto_table[(int) R_390_32];
00249     case BFD_RELOC_32_PCREL:
00250       return &elf_howto_table[(int) R_390_PC32];
00251     case BFD_RELOC_390_GOT12:
00252       return &elf_howto_table[(int) R_390_GOT12];
00253     case BFD_RELOC_32_GOT_PCREL:
00254       return &elf_howto_table[(int) R_390_GOT32];
00255     case BFD_RELOC_390_PLT32:
00256       return &elf_howto_table[(int) R_390_PLT32];
00257     case BFD_RELOC_390_COPY:
00258       return &elf_howto_table[(int) R_390_COPY];
00259     case BFD_RELOC_390_GLOB_DAT:
00260       return &elf_howto_table[(int) R_390_GLOB_DAT];
00261     case BFD_RELOC_390_JMP_SLOT:
00262       return &elf_howto_table[(int) R_390_JMP_SLOT];
00263     case BFD_RELOC_390_RELATIVE:
00264       return &elf_howto_table[(int) R_390_RELATIVE];
00265     case BFD_RELOC_32_GOTOFF:
00266       return &elf_howto_table[(int) R_390_GOTOFF32];
00267     case BFD_RELOC_390_GOTPC:
00268       return &elf_howto_table[(int) R_390_GOTPC];
00269     case BFD_RELOC_390_GOT16:
00270       return &elf_howto_table[(int) R_390_GOT16];
00271     case BFD_RELOC_16_PCREL:
00272       return &elf_howto_table[(int) R_390_PC16];
00273     case BFD_RELOC_390_PC16DBL:
00274       return &elf_howto_table[(int) R_390_PC16DBL];
00275     case BFD_RELOC_390_PLT16DBL:
00276       return &elf_howto_table[(int) R_390_PLT16DBL];
00277     case BFD_RELOC_390_PC32DBL:
00278       return &elf_howto_table[(int) R_390_PC32DBL];
00279     case BFD_RELOC_390_PLT32DBL:
00280       return &elf_howto_table[(int) R_390_PLT32DBL];
00281     case BFD_RELOC_390_GOTPCDBL:
00282       return &elf_howto_table[(int) R_390_GOTPCDBL];
00283     case BFD_RELOC_64:
00284       return &elf_howto_table[(int) R_390_64];
00285     case BFD_RELOC_64_PCREL:
00286       return &elf_howto_table[(int) R_390_PC64];
00287     case BFD_RELOC_390_GOT64:
00288       return &elf_howto_table[(int) R_390_GOT64];
00289     case BFD_RELOC_390_PLT64:
00290       return &elf_howto_table[(int) R_390_PLT64];
00291     case BFD_RELOC_390_GOTENT:
00292       return &elf_howto_table[(int) R_390_GOTENT];
00293     case BFD_RELOC_16_GOTOFF:
00294       return &elf_howto_table[(int) R_390_GOTOFF16];
00295     case BFD_RELOC_390_GOTOFF64:
00296       return &elf_howto_table[(int) R_390_GOTOFF64];
00297     case BFD_RELOC_390_GOTPLT12:
00298       return &elf_howto_table[(int) R_390_GOTPLT12];
00299     case BFD_RELOC_390_GOTPLT16:
00300       return &elf_howto_table[(int) R_390_GOTPLT16];
00301     case BFD_RELOC_390_GOTPLT32:
00302       return &elf_howto_table[(int) R_390_GOTPLT32];
00303     case BFD_RELOC_390_GOTPLT64:
00304       return &elf_howto_table[(int) R_390_GOTPLT64];
00305     case BFD_RELOC_390_GOTPLTENT:
00306       return &elf_howto_table[(int) R_390_GOTPLTENT];
00307     case BFD_RELOC_390_PLTOFF16:
00308       return &elf_howto_table[(int) R_390_PLTOFF16];
00309     case BFD_RELOC_390_PLTOFF32:
00310       return &elf_howto_table[(int) R_390_PLTOFF32];
00311     case BFD_RELOC_390_PLTOFF64:
00312       return &elf_howto_table[(int) R_390_PLTOFF64];
00313     case BFD_RELOC_390_TLS_LOAD:
00314       return &elf_howto_table[(int) R_390_TLS_LOAD];
00315     case BFD_RELOC_390_TLS_GDCALL:
00316       return &elf_howto_table[(int) R_390_TLS_GDCALL];
00317     case BFD_RELOC_390_TLS_LDCALL:
00318       return &elf_howto_table[(int) R_390_TLS_LDCALL];
00319     case BFD_RELOC_390_TLS_GD64:
00320       return &elf_howto_table[(int) R_390_TLS_GD64];
00321     case BFD_RELOC_390_TLS_GOTIE12:
00322       return &elf_howto_table[(int) R_390_TLS_GOTIE12];
00323     case BFD_RELOC_390_TLS_GOTIE64:
00324       return &elf_howto_table[(int) R_390_TLS_GOTIE64];
00325     case BFD_RELOC_390_TLS_LDM64:
00326       return &elf_howto_table[(int) R_390_TLS_LDM64];
00327     case BFD_RELOC_390_TLS_IE64:
00328       return &elf_howto_table[(int) R_390_TLS_IE64];
00329     case BFD_RELOC_390_TLS_IEENT:
00330       return &elf_howto_table[(int) R_390_TLS_IEENT];
00331     case BFD_RELOC_390_TLS_LE64:
00332       return &elf_howto_table[(int) R_390_TLS_LE64];
00333     case BFD_RELOC_390_TLS_LDO64:
00334       return &elf_howto_table[(int) R_390_TLS_LDO64];
00335     case BFD_RELOC_390_TLS_DTPMOD:
00336       return &elf_howto_table[(int) R_390_TLS_DTPMOD];
00337     case BFD_RELOC_390_TLS_DTPOFF:
00338       return &elf_howto_table[(int) R_390_TLS_DTPOFF];
00339     case BFD_RELOC_390_TLS_TPOFF:
00340       return &elf_howto_table[(int) R_390_TLS_TPOFF];
00341     case BFD_RELOC_390_20:
00342       return &elf_howto_table[(int) R_390_20];
00343     case BFD_RELOC_390_GOT20:
00344       return &elf_howto_table[(int) R_390_GOT20];
00345     case BFD_RELOC_390_GOTPLT20:
00346       return &elf_howto_table[(int) R_390_GOTPLT20];
00347     case BFD_RELOC_390_TLS_GOTIE20:
00348       return &elf_howto_table[(int) R_390_TLS_GOTIE20];
00349     case BFD_RELOC_VTABLE_INHERIT:
00350       return &elf64_s390_vtinherit_howto;
00351     case BFD_RELOC_VTABLE_ENTRY:
00352       return &elf64_s390_vtentry_howto;
00353     default:
00354       break;
00355     }
00356   return 0;
00357 }
00358 
00359 static reloc_howto_type *
00360 elf_s390_reloc_name_lookup (bfd *abfd ATTRIBUTE_UNUSED,
00361                          const char *r_name)
00362 {
00363   unsigned int i;
00364 
00365   for (i = 0;
00366        i < sizeof (elf_howto_table) / sizeof (elf_howto_table[0]);
00367        i++)
00368     if (elf_howto_table[i].name != NULL
00369        && strcasecmp (elf_howto_table[i].name, r_name) == 0)
00370       return &elf_howto_table[i];
00371 
00372     if (strcasecmp (elf64_s390_vtinherit_howto.name, r_name) == 0)
00373       return &elf64_s390_vtinherit_howto;
00374     if (strcasecmp (elf64_s390_vtentry_howto.name, r_name) == 0)
00375       return &elf64_s390_vtentry_howto;
00376 
00377   return NULL;
00378 }
00379 
00380 /* We need to use ELF64_R_TYPE so we have our own copy of this function,
00381    and elf64-s390.c has its own copy.  */
00382 
00383 static void
00384 elf_s390_info_to_howto (abfd, cache_ptr, dst)
00385      bfd *abfd ATTRIBUTE_UNUSED;
00386      arelent *cache_ptr;
00387      Elf_Internal_Rela *dst;
00388 {
00389   unsigned int r_type = ELF64_R_TYPE(dst->r_info);
00390   switch (r_type)
00391     {
00392     case R_390_GNU_VTINHERIT:
00393       cache_ptr->howto = &elf64_s390_vtinherit_howto;
00394       break;
00395 
00396     case R_390_GNU_VTENTRY:
00397       cache_ptr->howto = &elf64_s390_vtentry_howto;
00398       break;
00399 
00400     default:
00401       if (r_type >= sizeof (elf_howto_table) / sizeof (elf_howto_table[0]))
00402        {
00403          (*_bfd_error_handler) (_("%B: invalid relocation type %d"),
00404                              abfd, (int) r_type);
00405          r_type = R_390_NONE;
00406        }
00407       cache_ptr->howto = &elf_howto_table[r_type];
00408     }
00409 }
00410 
00411 /* A relocation function which doesn't do anything.  */
00412 static bfd_reloc_status_type
00413 s390_tls_reloc (abfd, reloc_entry, symbol, data, input_section,
00414               output_bfd, error_message)
00415      bfd *abfd ATTRIBUTE_UNUSED;
00416      arelent *reloc_entry;
00417      asymbol *symbol ATTRIBUTE_UNUSED;
00418      PTR data ATTRIBUTE_UNUSED;
00419      asection *input_section;
00420      bfd *output_bfd;
00421      char **error_message ATTRIBUTE_UNUSED;
00422 {
00423   if (output_bfd)
00424     reloc_entry->address += input_section->output_offset;
00425   return bfd_reloc_ok;
00426 }
00427 
00428 /* Handle the large displacement relocs.  */
00429 static bfd_reloc_status_type
00430 s390_elf_ldisp_reloc (abfd, reloc_entry, symbol, data, input_section,
00431                       output_bfd, error_message)
00432      bfd *abfd;
00433      arelent *reloc_entry;
00434      asymbol *symbol;
00435      PTR data;
00436      asection *input_section;
00437      bfd *output_bfd;
00438      char **error_message ATTRIBUTE_UNUSED;
00439 {
00440   reloc_howto_type *howto = reloc_entry->howto;
00441   bfd_vma relocation;
00442   bfd_vma insn;
00443 
00444   if (output_bfd != (bfd *) NULL
00445       && (symbol->flags & BSF_SECTION_SYM) == 0
00446       && (! howto->partial_inplace
00447          || reloc_entry->addend == 0))
00448     {
00449       reloc_entry->address += input_section->output_offset;
00450       return bfd_reloc_ok;
00451     }
00452   if (output_bfd != NULL)
00453     return bfd_reloc_continue;
00454 
00455   if (reloc_entry->address > bfd_get_section_limit (abfd, input_section))
00456     return bfd_reloc_outofrange;
00457 
00458   relocation = (symbol->value
00459               + symbol->section->output_section->vma
00460               + symbol->section->output_offset);
00461   relocation += reloc_entry->addend;
00462   if (howto->pc_relative)
00463     {
00464       relocation -= (input_section->output_section->vma
00465                    + input_section->output_offset);
00466       relocation -= reloc_entry->address;
00467     }
00468 
00469   insn = bfd_get_32 (abfd, (bfd_byte *) data + reloc_entry->address); 
00470   insn |= (relocation & 0xfff) << 16 | (relocation & 0xff000) >> 4;
00471   bfd_put_32 (abfd, insn, (bfd_byte *) data + reloc_entry->address);
00472 
00473   if ((bfd_signed_vma) relocation < - 0x80000
00474       || (bfd_signed_vma) relocation > 0x7ffff)
00475     return bfd_reloc_overflow;
00476   else
00477     return bfd_reloc_ok;
00478 }
00479 
00480 static bfd_boolean
00481 elf_s390_is_local_label_name (abfd, name)
00482      bfd *abfd;
00483      const char *name;
00484 {
00485   if (name[0] == '.' && (name[1] == 'X' || name[1] == 'L'))
00486     return TRUE;
00487 
00488   return _bfd_elf_is_local_label_name (abfd, name);
00489 }
00490 
00491 /* Functions for the 390 ELF linker.  */
00492 
00493 /* The name of the dynamic interpreter.  This is put in the .interp
00494    section.  */
00495 
00496 #define ELF_DYNAMIC_INTERPRETER "/usr/lib/ld.so.1"
00497 
00498 /* If ELIMINATE_COPY_RELOCS is non-zero, the linker will try to avoid
00499    copying dynamic variables from a shared lib into an app's dynbss
00500    section, and instead use a dynamic relocation to point into the
00501    shared lib.  */
00502 #define ELIMINATE_COPY_RELOCS 1
00503 
00504 /* The size in bytes of the first entry in the procedure linkage table.  */
00505 #define PLT_FIRST_ENTRY_SIZE 32
00506 /* The size in bytes of an entry in the procedure linkage table.  */
00507 #define PLT_ENTRY_SIZE 32
00508 
00509 #define GOT_ENTRY_SIZE 8
00510 
00511 /* The first three entries in a procedure linkage table are reserved,
00512    and the initial contents are unimportant (we zero them out).
00513    Subsequent entries look like this.  See the SVR4 ABI 386
00514    supplement to see how this works.  */
00515 
00516 /* For the s390, simple addr offset can only be 0 - 4096.
00517    To use the full 16777216 TB address space, several instructions
00518    are needed to load an address in a register and execute
00519    a branch( or just saving the address)
00520 
00521    Furthermore, only r 0 and 1 are free to use!!!  */
00522 
00523 /* The first 3 words in the GOT are then reserved.
00524    Word 0 is the address of the dynamic table.
00525    Word 1 is a pointer to a structure describing the object
00526    Word 2 is used to point to the loader entry address.
00527 
00528    The code for PLT entries looks like this:
00529 
00530    The GOT holds the address in the PLT to be executed.
00531    The loader then gets:
00532    24(15) =  Pointer to the structure describing the object.
00533    28(15) =  Offset in symbol table
00534    The loader  must  then find the module where the function is
00535    and insert the address in the GOT.
00536 
00537    PLT1: LARL 1,<fn>@GOTENT # 6 bytes  Load address of GOT entry in r1
00538          LG   1,0(1)      # 6 bytes  Load address from GOT in r1
00539          BCR  15,1        # 2 bytes  Jump to address
00540    RET1: BASR 1,0         # 2 bytes  Return from GOT 1st time
00541          LGF  1,12(1)     # 6 bytes  Load offset in symbl table in r1
00542          BRCL 15,-x       # 6 bytes  Jump to start of PLT
00543          .long ?          # 4 bytes  offset into symbol table
00544 
00545    Total = 32 bytes per PLT entry
00546    Fixup at offset 2: relative address to GOT entry
00547    Fixup at offset 22: relative branch to PLT0
00548    Fixup at offset 28: 32 bit offset into symbol table
00549 
00550    A 32 bit offset into the symbol table is enough. It allows for symbol
00551    tables up to a size of 2 gigabyte. A single dynamic object (the main
00552    program, any shared library) is limited to 4GB in size and I want to see
00553    the program that manages to have a symbol table of more than 2 GB with a
00554    total size of at max 4 GB.  */
00555 
00556 #define PLT_ENTRY_WORD0     (bfd_vma) 0xc0100000
00557 #define PLT_ENTRY_WORD1     (bfd_vma) 0x0000e310
00558 #define PLT_ENTRY_WORD2     (bfd_vma) 0x10000004
00559 #define PLT_ENTRY_WORD3     (bfd_vma) 0x07f10d10
00560 #define PLT_ENTRY_WORD4     (bfd_vma) 0xe310100c
00561 #define PLT_ENTRY_WORD5     (bfd_vma) 0x0014c0f4
00562 #define PLT_ENTRY_WORD6     (bfd_vma) 0x00000000
00563 #define PLT_ENTRY_WORD7     (bfd_vma) 0x00000000
00564 
00565 /* The first PLT entry pushes the offset into the symbol table
00566    from R1 onto the stack at 8(15) and the loader object info
00567    at 12(15), loads the loader address in R1 and jumps to it.  */
00568 
00569 /* The first entry in the PLT:
00570 
00571   PLT0:
00572      STG  1,56(15)  # r1 contains the offset into the symbol table
00573      LARL 1,_GLOBAL_OFFSET_TABLE # load address of global offset table
00574      MVC  48(8,15),8(1) # move loader ino (object struct address) to stack
00575      LG   1,16(1)   # get entry address of loader
00576      BCR  15,1      # jump to loader
00577 
00578      Fixup at offset 8: relative address to start of GOT.  */
00579 
00580 #define PLT_FIRST_ENTRY_WORD0     (bfd_vma) 0xe310f038
00581 #define PLT_FIRST_ENTRY_WORD1     (bfd_vma) 0x0024c010
00582 #define PLT_FIRST_ENTRY_WORD2     (bfd_vma) 0x00000000
00583 #define PLT_FIRST_ENTRY_WORD3     (bfd_vma) 0xd207f030
00584 #define PLT_FIRST_ENTRY_WORD4     (bfd_vma) 0x1008e310
00585 #define PLT_FIRST_ENTRY_WORD5     (bfd_vma) 0x10100004
00586 #define PLT_FIRST_ENTRY_WORD6     (bfd_vma) 0x07f10700
00587 #define PLT_FIRST_ENTRY_WORD7     (bfd_vma) 0x07000700
00588 
00589 /* The s390 linker needs to keep track of the number of relocs that it
00590    decides to copy as dynamic relocs in check_relocs for each symbol.
00591    This is so that it can later discard them if they are found to be
00592    unnecessary.  We store the information in a field extending the
00593    regular ELF linker hash table.  */
00594 
00595 struct elf_s390_dyn_relocs
00596 {
00597   struct elf_s390_dyn_relocs *next;
00598 
00599   /* The input section of the reloc.  */
00600   asection *sec;
00601 
00602   /* Total number of relocs copied for the input section.  */
00603   bfd_size_type count;
00604 
00605   /* Number of pc-relative relocs copied for the input section.  */
00606   bfd_size_type pc_count;
00607 };
00608 
00609 /* s390 ELF linker hash entry.  */
00610 
00611 struct elf_s390_link_hash_entry
00612 {
00613   struct elf_link_hash_entry elf;
00614 
00615   /* Track dynamic relocs copied for this symbol.  */
00616   struct elf_s390_dyn_relocs *dyn_relocs;
00617 
00618   /* Number of GOTPLT references for a function.  */
00619   bfd_signed_vma gotplt_refcount;
00620 
00621 #define GOT_UNKNOWN  0
00622 #define GOT_NORMAL   1
00623 #define GOT_TLS_GD   2
00624 #define GOT_TLS_IE   3
00625 #define GOT_TLS_IE_NLT      3
00626   unsigned char tls_type;
00627 };
00628 
00629 #define elf_s390_hash_entry(ent) \
00630   ((struct elf_s390_link_hash_entry *)(ent))
00631 
00632 struct elf_s390_obj_tdata
00633 {
00634   struct elf_obj_tdata root;
00635 
00636   /* tls_type for each local got entry.  */
00637   char *local_got_tls_type;
00638 };
00639 
00640 #define elf_s390_tdata(abfd) \
00641   ((struct elf_s390_obj_tdata *) (abfd)->tdata.any)
00642 
00643 #define elf_s390_local_got_tls_type(abfd) \
00644   (elf_s390_tdata (abfd)->local_got_tls_type)
00645 
00646 static bfd_boolean
00647 elf_s390_mkobject (bfd *abfd)
00648 {
00649   if (abfd->tdata.any == NULL)
00650     {
00651       bfd_size_type amt = sizeof (struct elf_s390_obj_tdata);
00652       abfd->tdata.any = bfd_zalloc (abfd, amt);
00653       if (abfd->tdata.any == NULL)
00654        return FALSE;
00655     }
00656   return bfd_elf_mkobject (abfd);
00657 }
00658 
00659 static bfd_boolean
00660 elf_s390_object_p (abfd)
00661      bfd *abfd;
00662 {
00663   /* Set the right machine number for an s390 elf32 file.  */
00664   return bfd_default_set_arch_mach (abfd, bfd_arch_s390, bfd_mach_s390_64);
00665 }
00666 
00667 /* s390 ELF linker hash table.  */
00668 
00669 struct elf_s390_link_hash_table
00670 {
00671   struct elf_link_hash_table elf;
00672 
00673   /* Short-cuts to get to dynamic linker sections.  */
00674   asection *sgot;
00675   asection *sgotplt;
00676   asection *srelgot;
00677   asection *splt;
00678   asection *srelplt;
00679   asection *sdynbss;
00680   asection *srelbss;
00681 
00682   union {
00683     bfd_signed_vma refcount;
00684     bfd_vma offset;
00685   } tls_ldm_got;
00686 
00687   /* Small local sym to section mapping cache.  */
00688   struct sym_sec_cache sym_sec;
00689 };
00690 
00691 /* Get the s390 ELF linker hash table from a link_info structure.  */
00692 
00693 #define elf_s390_hash_table(p) \
00694   ((struct elf_s390_link_hash_table *) ((p)->hash))
00695 
00696 /* Create an entry in an s390 ELF linker hash table.  */
00697 
00698 static struct bfd_hash_entry *
00699 link_hash_newfunc (entry, table, string)
00700      struct bfd_hash_entry *entry;
00701      struct bfd_hash_table *table;
00702      const char *string;
00703 {
00704   /* Allocate the structure if it has not already been allocated by a
00705      subclass.  */
00706   if (entry == NULL)
00707     {
00708       entry = bfd_hash_allocate (table,
00709                              sizeof (struct elf_s390_link_hash_entry));
00710       if (entry == NULL)
00711        return entry;
00712     }
00713 
00714   /* Call the allocation method of the superclass.  */
00715   entry = _bfd_elf_link_hash_newfunc (entry, table, string);
00716   if (entry != NULL)
00717     {
00718       struct elf_s390_link_hash_entry *eh;
00719 
00720       eh = (struct elf_s390_link_hash_entry *) entry;
00721       eh->dyn_relocs = NULL;
00722       eh->gotplt_refcount = 0;
00723       eh->tls_type = GOT_UNKNOWN;
00724     }
00725 
00726   return entry;
00727 }
00728 
00729 /* Create an s390 ELF linker hash table.  */
00730 
00731 static struct bfd_link_hash_table *
00732 elf_s390_link_hash_table_create (abfd)
00733      bfd *abfd;
00734 {
00735   struct elf_s390_link_hash_table *ret;
00736   bfd_size_type amt = sizeof (struct elf_s390_link_hash_table);
00737 
00738   ret = (struct elf_s390_link_hash_table *) bfd_malloc (amt);
00739   if (ret == NULL)
00740     return NULL;
00741 
00742   if (!_bfd_elf_link_hash_table_init (&ret->elf, abfd, link_hash_newfunc,
00743                                   sizeof (struct elf_s390_link_hash_entry)))
00744     {
00745       free (ret);
00746       return NULL;
00747     }
00748 
00749   ret->sgot = NULL;
00750   ret->sgotplt = NULL;
00751   ret->srelgot = NULL;
00752   ret->splt = NULL;
00753   ret->srelplt = NULL;
00754   ret->sdynbss = NULL;
00755   ret->srelbss = NULL;
00756   ret->tls_ldm_got.refcount = 0;
00757   ret->sym_sec.abfd = NULL;
00758 
00759   return &ret->elf.root;
00760 }
00761 
00762 /* Create .got, .gotplt, and .rela.got sections in DYNOBJ, and set up
00763    shortcuts to them in our hash table.  */
00764 
00765 static bfd_boolean
00766 create_got_section (dynobj, info)
00767      bfd *dynobj;
00768      struct bfd_link_info *info;
00769 {
00770   struct elf_s390_link_hash_table *htab;
00771 
00772   if (! _bfd_elf_create_got_section (dynobj, info))
00773     return FALSE;
00774 
00775   htab = elf_s390_hash_table (info);
00776   htab->sgot = bfd_get_section_by_name (dynobj, ".got");
00777   htab->sgotplt = bfd_get_section_by_name (dynobj, ".got.plt");
00778   if (!htab->sgot || !htab->sgotplt)
00779     abort ();
00780 
00781   htab->srelgot = bfd_make_section_with_flags (dynobj, ".rela.got",
00782                                           (SEC_ALLOC | SEC_LOAD
00783                                           | SEC_HAS_CONTENTS
00784                                           | SEC_IN_MEMORY
00785                                           | SEC_LINKER_CREATED
00786                                           | SEC_READONLY));
00787   if (htab->srelgot == NULL
00788       || ! bfd_set_section_alignment (dynobj, htab->srelgot, 3))
00789     return FALSE;
00790   return TRUE;
00791 }
00792 
00793 /* Create .plt, .rela.plt, .got, .got.plt, .rela.got, .dynbss, and
00794    .rela.bss sections in DYNOBJ, and set up shortcuts to them in our
00795    hash table.  */
00796 
00797 static bfd_boolean
00798 elf_s390_create_dynamic_sections (dynobj, info)
00799      bfd *dynobj;
00800      struct bfd_link_info *info;
00801 {
00802   struct elf_s390_link_hash_table *htab;
00803 
00804   htab = elf_s390_hash_table (info);
00805   if (!htab->sgot && !create_got_section (dynobj, info))
00806     return FALSE;
00807 
00808   if (!_bfd_elf_create_dynamic_sections (dynobj, info))
00809     return FALSE;
00810 
00811   htab->splt = bfd_get_section_by_name (dynobj, ".plt");
00812   htab->srelplt = bfd_get_section_by_name (dynobj, ".rela.plt");
00813   htab->sdynbss = bfd_get_section_by_name (dynobj, ".dynbss");
00814   if (!info->shared)
00815     htab->srelbss = bfd_get_section_by_name (dynobj, ".rela.bss");
00816 
00817   if (!htab->splt || !htab->srelplt || !htab->sdynbss
00818       || (!info->shared && !htab->srelbss))
00819     abort ();
00820 
00821   return TRUE;
00822 }
00823 
00824 /* Copy the extra info we tack onto an elf_link_hash_entry.  */
00825 
00826 static void
00827 elf_s390_copy_indirect_symbol (info, dir, ind)
00828      struct bfd_link_info *info;
00829      struct elf_link_hash_entry *dir, *ind;
00830 {
00831   struct elf_s390_link_hash_entry *edir, *eind;
00832 
00833   edir = (struct elf_s390_link_hash_entry *) dir;
00834   eind = (struct elf_s390_link_hash_entry *) ind;
00835 
00836   if (eind->dyn_relocs != NULL)
00837     {
00838       if (edir->dyn_relocs != NULL)
00839        {
00840          struct elf_s390_dyn_relocs **pp;
00841          struct elf_s390_dyn_relocs *p;
00842 
00843          /* Add reloc counts against the indirect sym to the direct sym
00844             list.  Merge any entries against the same section.  */
00845          for (pp = &eind->dyn_relocs; (p = *pp) != NULL; )
00846            {
00847              struct elf_s390_dyn_relocs *q;
00848 
00849              for (q = edir->dyn_relocs; q != NULL; q = q->next)
00850               if (q->sec == p->sec)
00851                 {
00852                   q->pc_count += p->pc_count;
00853                   q->count += p->count;
00854                   *pp = p->next;
00855                   break;
00856                 }
00857              if (q == NULL)
00858               pp = &p->next;
00859            }
00860          *pp = edir->dyn_relocs;
00861        }
00862 
00863       edir->dyn_relocs = eind->dyn_relocs;
00864       eind->dyn_relocs = NULL;
00865     }
00866 
00867   if (ind->root.type == bfd_link_hash_indirect
00868       && dir->got.refcount <= 0)
00869     {
00870       edir->tls_type = eind->tls_type;
00871       eind->tls_type = GOT_UNKNOWN;
00872     }
00873 
00874   if (ELIMINATE_COPY_RELOCS
00875       && ind->root.type != bfd_link_hash_indirect
00876       && dir->dynamic_adjusted)
00877     {
00878       /* If called to transfer flags for a weakdef during processing
00879         of elf_adjust_dynamic_symbol, don't copy non_got_ref.
00880         We clear it ourselves for ELIMINATE_COPY_RELOCS.  */
00881       dir->ref_dynamic |= ind->ref_dynamic;
00882       dir->ref_regular |= ind->ref_regular;
00883       dir->ref_regular_nonweak |= ind->ref_regular_nonweak;
00884       dir->needs_plt |= ind->needs_plt;
00885     }
00886   else
00887     _bfd_elf_link_hash_copy_indirect (info, dir, ind);
00888 }
00889 
00890 static int
00891 elf_s390_tls_transition (info, r_type, is_local)
00892      struct bfd_link_info *info;
00893      int r_type;
00894      int is_local;
00895 {
00896   if (info->shared)
00897     return r_type;
00898 
00899   switch (r_type)
00900     {
00901     case R_390_TLS_GD64:
00902     case R_390_TLS_IE64:
00903       if (is_local)
00904        return R_390_TLS_LE64;
00905       return R_390_TLS_IE64;
00906     case R_390_TLS_GOTIE64:
00907       if (is_local)
00908        return R_390_TLS_LE64;
00909       return R_390_TLS_GOTIE64;
00910     case R_390_TLS_LDM64:
00911       return R_390_TLS_LE64;
00912     }
00913 
00914   return r_type;
00915 }
00916 
00917 /* Look through the relocs for a section during the first phase, and
00918    allocate space in the global offset table or procedure linkage
00919    table.  */
00920 
00921 static bfd_boolean
00922 elf_s390_check_relocs (abfd, info, sec, relocs)
00923      bfd *abfd;
00924      struct bfd_link_info *info;
00925      asection *sec;
00926      const Elf_Internal_Rela *relocs;
00927 {
00928   struct elf_s390_link_hash_table *htab;
00929   Elf_Internal_Shdr *symtab_hdr;
00930   struct elf_link_hash_entry **sym_hashes;
00931   const Elf_Internal_Rela *rel;
00932   const Elf_Internal_Rela *rel_end;
00933   asection *sreloc;
00934   bfd_signed_vma *local_got_refcounts;
00935   int tls_type, old_tls_type;
00936 
00937   if (info->relocatable)
00938     return TRUE;
00939 
00940   htab = elf_s390_hash_table (info);
00941   symtab_hdr = &elf_tdata (abfd)->symtab_hdr;
00942   sym_hashes = elf_sym_hashes (abfd);
00943   local_got_refcounts = elf_local_got_refcounts (abfd);
00944 
00945   sreloc = NULL;
00946 
00947   rel_end = relocs + sec->reloc_count;
00948   for (rel = relocs; rel < rel_end; rel++)
00949     {
00950       unsigned int r_type;
00951       unsigned long r_symndx;
00952       struct elf_link_hash_entry *h;
00953 
00954       r_symndx = ELF64_R_SYM (rel->r_info);
00955 
00956       if (r_symndx >= NUM_SHDR_ENTRIES (symtab_hdr))
00957        {
00958          (*_bfd_error_handler) (_("%B: bad symbol index: %d"),
00959                              abfd,
00960                              r_symndx);
00961          return FALSE;
00962        }
00963 
00964       if (r_symndx < symtab_hdr->sh_info)
00965        h = NULL;
00966       else
00967        {
00968          h = sym_hashes[r_symndx - symtab_hdr->sh_info];
00969          while (h->root.type == bfd_link_hash_indirect
00970                || h->root.type == bfd_link_hash_warning)
00971            h = (struct elf_link_hash_entry *) h->root.u.i.link;
00972        }
00973 
00974       /* Create got section and local_got_refcounts array if they
00975         are needed.  */
00976       r_type = elf_s390_tls_transition (info,
00977                                    ELF64_R_TYPE (rel->r_info),
00978                                    h == NULL);
00979       switch (r_type)
00980        {
00981        case R_390_GOT12:
00982        case R_390_GOT16:
00983        case R_390_GOT20:
00984        case R_390_GOT32:
00985        case R_390_GOT64:
00986        case R_390_GOTENT:
00987        case R_390_GOTPLT12:
00988        case R_390_GOTPLT16:
00989        case R_390_GOTPLT20:
00990        case R_390_GOTPLT32:
00991        case R_390_GOTPLT64:
00992        case R_390_GOTPLTENT:
00993        case R_390_TLS_GD64:
00994        case R_390_TLS_GOTIE12:
00995        case R_390_TLS_GOTIE20:
00996        case R_390_TLS_GOTIE64:
00997        case R_390_TLS_IEENT:
00998        case R_390_TLS_IE64:
00999        case R_390_TLS_LDM64:
01000          if (h == NULL
01001              && local_got_refcounts == NULL)
01002            {
01003              bfd_size_type size;
01004 
01005              size = symtab_hdr->sh_info;
01006              size *= (sizeof (bfd_signed_vma) + sizeof(char));
01007              local_got_refcounts = ((bfd_signed_vma *)
01008                                  bfd_zalloc (abfd, size));
01009              if (local_got_refcounts == NULL)
01010               return FALSE;
01011              elf_local_got_refcounts (abfd) = local_got_refcounts;
01012              elf_s390_local_got_tls_type (abfd)
01013               = (char *) (local_got_refcounts + symtab_hdr->sh_info);
01014            }
01015          /* Fall through.  */
01016        case R_390_GOTOFF16:
01017        case R_390_GOTOFF32:
01018        case R_390_GOTOFF64:
01019        case R_390_GOTPC:
01020        case R_390_GOTPCDBL:
01021          if (htab->sgot == NULL)
01022            {
01023              if (htab->elf.dynobj == NULL)
01024               htab->elf.dynobj = abfd;
01025              if (!create_got_section (htab->elf.dynobj, info))
01026               return FALSE;
01027            }
01028        }
01029 
01030       switch (r_type)
01031        {
01032        case R_390_GOTOFF16:
01033        case R_390_GOTOFF32:
01034        case R_390_GOTOFF64:
01035        case R_390_GOTPC:
01036        case R_390_GOTPCDBL:
01037          /* Got is created, nothing to be done.  */
01038          break;
01039 
01040        case R_390_PLT16DBL:
01041        case R_390_PLT32:
01042        case R_390_PLT32DBL:
01043        case R_390_PLT64:
01044        case R_390_PLTOFF16:
01045        case R_390_PLTOFF32:
01046        case R_390_PLTOFF64:
01047          /* This symbol requires a procedure linkage table entry.  We
01048             actually build the entry in adjust_dynamic_symbol,
01049             because this might be a case of linking PIC code which is
01050             never referenced by a dynamic object, in which case we
01051             don't need to generate a procedure linkage table entry
01052             after all.  */
01053 
01054          /* If this is a local symbol, we resolve it directly without
01055             creating a procedure linkage table entry.  */
01056          if (h != NULL)
01057            {
01058              h->needs_plt = 1;
01059              h->plt.refcount += 1;
01060            }
01061          break;
01062 
01063        case R_390_GOTPLT12:
01064        case R_390_GOTPLT16:
01065        case R_390_GOTPLT20:
01066        case R_390_GOTPLT32:
01067        case R_390_GOTPLT64:
01068        case R_390_GOTPLTENT:
01069          /* This symbol requires either a procedure linkage table entry
01070             or an entry in the local got. We actually build the entry
01071             in adjust_dynamic_symbol because whether this is really a
01072             global reference can change and with it the fact if we have
01073             to create a plt entry or a local got entry. To be able to
01074             make a once global symbol a local one we have to keep track
01075             of the number of gotplt references that exist for this
01076             symbol.  */
01077          if (h != NULL)
01078            {
01079              ((struct elf_s390_link_hash_entry *) h)->gotplt_refcount++;
01080              h->needs_plt = 1;
01081              h->plt.refcount += 1;
01082            }
01083          else
01084            local_got_refcounts[r_symndx] += 1;
01085          break;
01086 
01087        case R_390_TLS_LDM64:
01088          htab->tls_ldm_got.refcount += 1;
01089          break;
01090 
01091        case R_390_TLS_IE64:
01092        case R_390_TLS_GOTIE12:
01093        case R_390_TLS_GOTIE20:
01094        case R_390_TLS_GOTIE64:
01095        case R_390_TLS_IEENT:
01096          if (info->shared)
01097            info->flags |= DF_STATIC_TLS;
01098          /* Fall through */
01099 
01100        case R_390_GOT12:
01101        case R_390_GOT16:
01102        case R_390_GOT20:
01103        case R_390_GOT32:
01104        case R_390_GOT64:
01105        case R_390_GOTENT:
01106        case R_390_TLS_GD64:
01107          /* This symbol requires a global offset table entry.  */
01108          switch (r_type)
01109            {
01110            default:
01111            case R_390_GOT12:
01112            case R_390_GOT16:
01113            case R_390_GOT20:
01114            case R_390_GOT32:
01115            case R_390_GOTENT:
01116              tls_type = GOT_NORMAL;
01117              break;
01118            case R_390_TLS_GD64:
01119              tls_type = GOT_TLS_GD;
01120              break;
01121            case R_390_TLS_IE64:
01122            case R_390_TLS_GOTIE64:
01123              tls_type = GOT_TLS_IE;
01124              break;
01125            case R_390_TLS_GOTIE12:
01126            case R_390_TLS_GOTIE20:
01127            case R_390_TLS_IEENT:
01128              tls_type = GOT_TLS_IE_NLT;
01129              break;
01130            }
01131 
01132          if (h != NULL)
01133            {
01134              h->got.refcount += 1;
01135              old_tls_type = elf_s390_hash_entry(h)->tls_type;
01136            }
01137          else
01138            {
01139              local_got_refcounts[r_symndx] += 1;
01140              old_tls_type = elf_s390_local_got_tls_type (abfd) [r_symndx];
01141            }
01142          /* If a TLS symbol is accessed using IE at least once,
01143             there is no point to use dynamic model for it.  */
01144          if (old_tls_type != tls_type && old_tls_type != GOT_UNKNOWN)
01145            {
01146              if (old_tls_type == GOT_NORMAL || tls_type == GOT_NORMAL)
01147               {
01148                 (*_bfd_error_handler)
01149                   (_("%B: `%s' accessed both as normal and thread local symbol"),
01150                    abfd, h->root.root.string);
01151                 return FALSE;
01152               }
01153              if (old_tls_type > tls_type)
01154               tls_type = old_tls_type;
01155            }
01156 
01157          if (old_tls_type != tls_type)
01158            {
01159              if (h != NULL)
01160               elf_s390_hash_entry (h)->tls_type = tls_type;
01161              else
01162               elf_s390_local_got_tls_type (abfd) [r_symndx] = tls_type;
01163            }
01164 
01165          if (r_type != R_390_TLS_IE64)
01166            break;
01167          /* Fall through */
01168 
01169        case R_390_TLS_LE64:
01170          if (!info->shared)
01171            break;
01172          info->flags |= DF_STATIC_TLS;
01173          /* Fall through */
01174 
01175        case R_390_8:
01176        case R_390_16:
01177        case R_390_32:
01178        case R_390_64:
01179        case R_390_PC16:
01180        case R_390_PC16DBL:
01181        case R_390_PC32:
01182        case R_390_PC32DBL:
01183        case R_390_PC64:
01184          if (h != NULL && !info->shared)
01185            {
01186              /* If this reloc is in a read-only section, we might
01187                need a copy reloc.  We can't check reliably at this
01188                stage whether the section is read-only, as input
01189                sections have not yet been mapped to output sections.
01190                Tentatively set the flag for now, and correct in
01191                adjust_dynamic_symbol.  */
01192              h->non_got_ref = 1;
01193 
01194              /* We may need a .plt entry if the function this reloc
01195                refers to is in a shared lib.  */
01196              h->plt.refcount += 1;
01197            }
01198 
01199          /* If we are creating a shared library, and this is a reloc
01200             against a global symbol, or a non PC relative reloc
01201             against a local symbol, then we need to copy the reloc
01202             into the shared library.  However, if we are linking with
01203             -Bsymbolic, we do not need to copy a reloc against a
01204             global symbol which is defined in an object we are
01205             including in the link (i.e., DEF_REGULAR is set).  At
01206             this point we have not seen all the input files, so it is
01207             possible that DEF_REGULAR is not set now but will be set
01208             later (it is never cleared).  In case of a weak definition,
01209             DEF_REGULAR may be cleared later by a strong definition in
01210             a shared library. We account for that possibility below by
01211             storing information in the relocs_copied field of the hash
01212             table entry.  A similar situation occurs when creating
01213             shared libraries and symbol visibility changes render the
01214             symbol local.
01215 
01216             If on the other hand, we are creating an executable, we
01217             may need to keep relocations for symbols satisfied by a
01218             dynamic library if we manage to avoid copy relocs for the
01219             symbol.  */
01220          if ((info->shared
01221               && (sec->flags & SEC_ALLOC) != 0
01222               && ((ELF64_R_TYPE (rel->r_info) != R_390_PC16
01223                   && ELF64_R_TYPE (rel->r_info) != R_390_PC16DBL
01224                   && ELF64_R_TYPE (rel->r_info) != R_390_PC32
01225                   && ELF64_R_TYPE (rel->r_info) != R_390_PC32DBL
01226                   && ELF64_R_TYPE (rel->r_info) != R_390_PC64)
01227                  || (h != NULL
01228                      && (! info->symbolic
01229                         || h->root.type == bfd_link_hash_defweak
01230                         || !h->def_regular))))
01231              || (ELIMINATE_COPY_RELOCS
01232                 && !info->shared
01233                 && (sec->flags & SEC_ALLOC) != 0
01234                 && h != NULL
01235                 && (h->root.type == bfd_link_hash_defweak
01236                     || !h->def_regular)))
01237            {
01238              struct elf_s390_dyn_relocs *p;
01239              struct elf_s390_dyn_relocs **head;
01240 
01241              /* We must copy these reloc types into the output file.
01242                Create a reloc section in dynobj and make room for
01243                this reloc.  */
01244              if (sreloc == NULL)
01245               {
01246                 const char *name;
01247                 bfd *dynobj;
01248 
01249                 name = (bfd_elf_string_from_elf_section
01250                        (abfd,
01251                         elf_elfheader (abfd)->e_shstrndx,
01252                         elf_section_data (sec)->rel_hdr.sh_name));
01253                 if (name == NULL)
01254                   return FALSE;
01255 
01256                 if (! CONST_STRNEQ (name, ".rela")
01257                     || strcmp (bfd_get_section_name (abfd, sec),
01258                              name + 5) != 0)
01259                   {
01260                     (*_bfd_error_handler)
01261                      (_("%B: bad relocation section name `%s\'"),
01262                       abfd, name);
01263                   }
01264 
01265                 if (htab->elf.dynobj == NULL)
01266                   htab->elf.dynobj = abfd;
01267 
01268                 dynobj = htab->elf.dynobj;
01269                 sreloc = bfd_get_section_by_name (dynobj, name);
01270                 if (sreloc == NULL)
01271                   {
01272                     flagword flags;
01273 
01274                     flags = (SEC_HAS_CONTENTS | SEC_READONLY
01275                             | SEC_IN_MEMORY | SEC_LINKER_CREATED);
01276                     if ((sec->flags & SEC_ALLOC) != 0)
01277                      flags |= SEC_ALLOC | SEC_LOAD;
01278                     sreloc = bfd_make_section_with_flags (dynobj,
01279                                                      name,
01280                                                      flags);
01281                     if (sreloc == NULL
01282                        || ! bfd_set_section_alignment (dynobj, sreloc, 3))
01283                      return FALSE;
01284                   }
01285                 elf_section_data (sec)->sreloc = sreloc;
01286               }
01287 
01288              /* If this is a global symbol, we count the number of
01289                relocations we need for this symbol.  */
01290              if (h != NULL)
01291               {
01292                 head = &((struct elf_s390_link_hash_entry *) h)->dyn_relocs;
01293               }
01294              else
01295               {
01296                 /* Track dynamic relocs needed for local syms too.
01297                    We really need local syms available to do this
01298                    easily.  Oh well.  */
01299 
01300                 asection *s;
01301                 void *vpp;
01302 
01303                 s = bfd_section_from_r_symndx (abfd, &htab->sym_sec,
01304                                            sec, r_symndx);
01305                 if (s == NULL)
01306                   return FALSE;
01307 
01308                 vpp = &elf_section_data (s)->local_dynrel;
01309                 head = (struct elf_s390_dyn_relocs **) vpp;
01310               }
01311 
01312              p = *head;
01313              if (p == NULL || p->sec != sec)
01314               {
01315                 bfd_size_type amt = sizeof *p;
01316                 p = ((struct elf_s390_dyn_relocs *)
01317                      bfd_alloc (htab->elf.dynobj, amt));
01318                 if (p == NULL)
01319                   return FALSE;
01320                 p->next = *head;
01321                 *head = p;
01322                 p->sec = sec;
01323                 p->count = 0;
01324                 p->pc_count = 0;
01325               }
01326 
01327              p->count += 1;
01328              if (ELF64_R_TYPE (rel->r_info) == R_390_PC16
01329                 || ELF64_R_TYPE (rel->r_info) == R_390_PC16DBL
01330                 || ELF64_R_TYPE (rel->r_info) == R_390_PC32
01331                 || ELF64_R_TYPE (rel->r_info) == R_390_PC32DBL
01332                 || ELF64_R_TYPE (rel->r_info) == R_390_PC64)
01333               p->pc_count += 1;
01334            }
01335          break;
01336 
01337          /* This relocation describes the C++ object vtable hierarchy.
01338             Reconstruct it for later use during GC.  */
01339        case R_390_GNU_VTINHERIT:
01340          if (!bfd_elf_gc_record_vtinherit (abfd, sec, h, rel->r_offset))
01341            return FALSE;
01342          break;
01343 
01344          /* This relocation describes which C++ vtable entries are actually
01345             used.  Record for later use during GC.  */
01346        case R_390_GNU_VTENTRY:
01347          if (!bfd_elf_gc_record_vtentry (abfd, sec, h, rel->r_addend))
01348            return FALSE;
01349          break;
01350 
01351        default:
01352          break;
01353        }
01354     }
01355 
01356   return TRUE;
01357 }
01358 
01359 /* Return the section that should be marked against GC for a given
01360    relocation.  */
01361 
01362 static asection *
01363 elf_s390_gc_mark_hook (asection *sec,
01364                      struct bfd_link_info *info,
01365                      Elf_Internal_Rela *rel,
01366                      struct elf_link_hash_entry *h,
01367                      Elf_Internal_Sym *sym)
01368 {
01369   if (h != NULL)
01370     switch (ELF64_R_TYPE (rel->r_info))
01371       {
01372       case R_390_GNU_VTINHERIT:
01373       case R_390_GNU_VTENTRY:
01374        return NULL;
01375       }
01376 
01377   return _bfd_elf_gc_mark_hook (sec, info, rel, h, sym);
01378 }
01379 
01380 /* Update the got entry reference counts for the section being removed.  */
01381 
01382 static bfd_boolean
01383 elf_s390_gc_sweep_hook (bfd *abfd,
01384                      struct bfd_link_info *info,
01385                      asection *sec,
01386                      const Elf_Internal_Rela *relocs)
01387 {
01388   Elf_Internal_Shdr *symtab_hdr;
01389   struct elf_link_hash_entry **sym_hashes;
01390   bfd_signed_vma *local_got_refcounts;
01391   const Elf_Internal_Rela *rel, *relend;
01392 
01393   elf_section_data (sec)->local_dynrel = NULL;
01394 
01395   symtab_hdr = &elf_tdata (abfd)->symtab_hdr;
01396   sym_hashes = elf_sym_hashes (abfd);
01397   local_got_refcounts = elf_local_got_refcounts (abfd);
01398 
01399   relend = relocs + sec->reloc_count;
01400   for (rel = relocs; rel < relend; rel++)
01401     {
01402       unsigned long r_symndx;
01403       unsigned int r_type;
01404       struct elf_link_hash_entry *h = NULL;
01405 
01406       r_symndx = ELF64_R_SYM (rel->r_info);
01407       if (r_symndx >= symtab_hdr->sh_info)
01408        {
01409          struct elf_s390_link_hash_entry *eh;
01410          struct elf_s390_dyn_relocs **pp;
01411          struct elf_s390_dyn_relocs *p;
01412 
01413          h = sym_hashes[r_symndx - symtab_hdr->sh_info];
01414          while (h->root.type == bfd_link_hash_indirect
01415                || h->root.type == bfd_link_hash_warning)
01416            h = (struct elf_link_hash_entry *) h->root.u.i.link;
01417          eh = (struct elf_s390_link_hash_entry *) h;
01418 
01419          for (pp = &eh->dyn_relocs; (p = *pp) != NULL; pp = &p->next)
01420            if (p->sec == sec)
01421              {
01422               /* Everything must go for SEC.  */
01423               *pp = p->next;
01424               break;
01425              }
01426        }
01427 
01428       r_type = ELF64_R_TYPE (rel->r_info);
01429       r_type = elf_s390_tls_transition (info, r_type, h != NULL);
01430       switch (r_type)
01431        {
01432        case R_390_TLS_LDM64:
01433          if (elf_s390_hash_table (info)->tls_ldm_got.refcount > 0)
01434            elf_s390_hash_table (info)->tls_ldm_got.refcount -= 1;
01435          break;
01436 
01437        case R_390_TLS_GD64:
01438        case R_390_TLS_IE64:
01439        case R_390_TLS_GOTIE12:
01440        case R_390_TLS_GOTIE20:
01441        case R_390_TLS_GOTIE64:
01442        case R_390_TLS_IEENT:
01443        case R_390_GOT12:
01444        case R_390_GOT16:
01445        case R_390_GOT20:
01446        case R_390_GOT32:
01447        case R_390_GOT64:
01448        case R_390_GOTOFF16:
01449        case R_390_GOTOFF32:
01450        case R_390_GOTOFF64:
01451        case R_390_GOTPC:
01452        case R_390_GOTPCDBL:
01453        case R_390_GOTENT:
01454          if (h != NULL)
01455            {
01456              if (h->got.refcount > 0)
01457               h->got.refcount -= 1;
01458            }
01459          else if (local_got_refcounts != NULL)
01460            {
01461              if (local_got_refcounts[r_symndx] > 0)
01462               local_got_refcounts[r_symndx] -= 1;
01463            }
01464          break;
01465 
01466        case R_390_8:
01467        case R_390_12:
01468        case R_390_16:
01469        case R_390_20:
01470        case R_390_32:
01471        case R_390_64:
01472        case R_390_PC16:
01473        case R_390_PC16DBL:
01474        case R_390_PC32:
01475        case R_390_PC32DBL:
01476        case R_390_PC64:
01477          if (info->shared)
01478            break;
01479          /* Fall through */
01480 
01481        case R_390_PLT16DBL:
01482        case R_390_PLT32:
01483        case R_390_PLT32DBL:
01484        case R_390_PLT64:
01485        case R_390_PLTOFF16:
01486        case R_390_PLTOFF32:
01487        case R_390_PLTOFF64:
01488          if (h != NULL)
01489            {
01490              if (h->plt.refcount > 0)
01491               h->plt.refcount -= 1;
01492            }
01493          break;
01494 
01495        case R_390_GOTPLT12:
01496        case R_390_GOTPLT16:
01497        case R_390_GOTPLT20:
01498        case R_390_GOTPLT32:
01499        case R_390_GOTPLT64:
01500        case R_390_GOTPLTENT:
01501          if (h != NULL)
01502            {
01503              if (h->plt.refcount > 0)
01504               {
01505                 ((struct elf_s390_link_hash_entry *) h)->gotplt_refcount--;
01506                 h->plt.refcount -= 1;
01507               }
01508            }
01509          else if (local_got_refcounts != NULL)
01510            {
01511              if (local_got_refcounts[r_symndx] > 0)
01512               local_got_refcounts[r_symndx] -= 1;
01513            }
01514          break;
01515 
01516        default:
01517          break;
01518        }
01519     }
01520 
01521   return TRUE;
01522 }
01523 
01524 /* Make sure we emit a GOT entry if the symbol was supposed to have a PLT
01525    entry but we found we will not create any.  Called when we find we will
01526    not have any PLT for this symbol, by for example
01527    elf_s390_adjust_dynamic_symbol when we're doing a proper dynamic link,
01528    or elf_s390_size_dynamic_sections if no dynamic sections will be
01529    created (we're only linking static objects).  */
01530 
01531 static void
01532 elf_s390_adjust_gotplt (h)
01533      struct elf_s390_link_hash_entry *h;
01534 {
01535   if (h->elf.root.type == bfd_link_hash_warning)
01536     h = (struct elf_s390_link_hash_entry *) h->elf.root.u.i.link;
01537 
01538   if (h->gotplt_refcount <= 0)
01539     return;
01540 
01541   /* We simply add the number of gotplt references to the number
01542    * of got references for this symbol.  */
01543   h->elf.got.refcount += h->gotplt_refcount;
01544   h->gotplt_refcount = -1;
01545 }
01546 
01547 /* Adjust a symbol defined by a dynamic object and referenced by a
01548    regular object.  The current definition is in some section of the
01549    dynamic object, but we're not including those sections.  We have to
01550    change the definition to something the rest of the link can
01551    understand.  */
01552 
01553 static bfd_boolean
01554 elf_s390_adjust_dynamic_symbol (info, h)
01555      struct bfd_link_info *info;
01556      struct elf_link_hash_entry *h;
01557 {
01558   struct elf_s390_link_hash_table *htab;
01559   asection *s;
01560   unsigned int power_of_two;
01561 
01562   /* If this is a function, put it in the procedure linkage table.  We
01563      will fill in the contents of the procedure linkage table later
01564      (although we could actually do it here).  */
01565   if (h->type == STT_FUNC
01566       || h->needs_plt)
01567     {
01568       if (h->plt.refcount <= 0
01569          || (! info->shared
01570              && !h->def_dynamic
01571              && !h->ref_dynamic
01572              && h->root.type != bfd_link_hash_undefweak
01573              && h->root.type != bfd_link_hash_undefined))
01574        {
01575          /* This case can occur if we saw a PLT32 reloc in an input
01576             file, but the symbol was never referred to by a dynamic
01577             object, or if all references were garbage collected.  In
01578             such a case, we don't actually need to build a procedure
01579             linkage table, and we can just do a PC32 reloc instead.  */
01580          h->plt.offset = (bfd_vma) -1;
01581          h->needs_plt = 0;
01582          elf_s390_adjust_gotplt((struct elf_s390_link_hash_entry *) h);
01583        }
01584 
01585       return TRUE;
01586     }
01587   else
01588     /* It's possible that we incorrectly decided a .plt reloc was
01589        needed for an R_390_PC32 reloc to a non-function sym in
01590        check_relocs.  We can't decide accurately between function and
01591        non-function syms in check-relocs;  Objects loaded later in
01592        the link may change h->type.  So fix it now.  */
01593     h->plt.offset = (bfd_vma) -1;
01594 
01595   /* If this is a weak symbol, and there is a real definition, the
01596      processor independent code will have arranged for us to see the
01597      real definition first, and we can just use the same value.  */
01598   if (h->u.weakdef != NULL)
01599     {
01600       BFD_ASSERT (h->u.weakdef->root.type == bfd_link_hash_defined
01601                 || h->u.weakdef->root.type == bfd_link_hash_defweak);
01602       h->root.u.def.section = h->u.weakdef->root.u.def.section;
01603       h->root.u.def.value = h->u.weakdef->root.u.def.value;
01604       if (ELIMINATE_COPY_RELOCS || info->nocopyreloc)
01605        h->non_got_ref = h->u.weakdef->non_got_ref;
01606       return TRUE;
01607     }
01608 
01609   /* This is a reference to a symbol defined by a dynamic object which
01610      is not a function.  */
01611 
01612   /* If we are creating a shared library, we must presume that the
01613      only references to the symbol are via the global offset table.
01614      For such cases we need not do anything here; the relocations will
01615      be handled correctly by relocate_section.  */
01616   if (info->shared)
01617     return TRUE;
01618 
01619   /* If there are no references to this symbol that do not use the
01620      GOT, we don't need to generate a copy reloc.  */
01621   if (!h->non_got_ref)
01622     return TRUE;
01623 
01624   /* If -z nocopyreloc was given, we won't generate them either.  */
01625   if (info->nocopyreloc)
01626     {
01627       h->non_got_ref = 0;
01628       return TRUE;
01629     }
01630 
01631   if (ELIMINATE_COPY_RELOCS)
01632     {
01633       struct elf_s390_link_hash_entry * eh;
01634       struct elf_s390_dyn_relocs *p;
01635 
01636       eh = (struct elf_s390_link_hash_entry *) h;
01637       for (p = eh->dyn_relocs; p != NULL; p = p->next)
01638        {
01639          s = p->sec->output_section;
01640          if (s != NULL && (s->flags & SEC_READONLY) != 0)
01641            break;
01642        }
01643 
01644       /* If we didn't find any dynamic relocs in read-only sections, then
01645         we'll be keeping the dynamic relocs and avoiding the copy reloc.  */
01646       if (p == NULL)
01647        {
01648          h->non_got_ref = 0;
01649          return TRUE;
01650        }
01651     }
01652 
01653   if (h->size == 0)
01654     {
01655       (*_bfd_error_handler) (_("dynamic variable `%s' is zero size"),
01656                           h->root.root.string);
01657       return TRUE;
01658     }
01659 
01660   /* We must allocate the symbol in our .dynbss section, which will
01661      become part of the .bss section of the executable.  There will be
01662      an entry for this symbol in the .dynsym section.  The dynamic
01663      object will contain position independent code, so all references
01664      from the dynamic object to this symbol will go through the global
01665      offset table.  The dynamic linker will use the .dynsym entry to
01666      determine the address it must put in the global offset table, so
01667      both the dynamic object and the regular object will refer to the
01668      same memory location for the variable.  */
01669 
01670   htab = elf_s390_hash_table (info);
01671 
01672   /* We must generate a R_390_COPY reloc to tell the dynamic linker to
01673      copy the initial value out of the dynamic object and into the
01674      runtime process image.  */
01675   if ((h->root.u.def.section->flags & SEC_ALLOC) != 0)
01676     {
01677       htab->srelbss->size += sizeof (Elf64_External_Rela);
01678       h->needs_copy = 1;
01679     }
01680 
01681   /* We need to figure out the alignment required for this symbol.  I
01682      have no idea how ELF linkers handle this.  */
01683   power_of_two = bfd_log2 (h->size);
01684   if (power_of_two > 3)
01685     power_of_two = 3;
01686 
01687   /* Apply the required alignment.  */
01688   s = htab->sdynbss;
01689   s->size = BFD_ALIGN (s->size, (bfd_size_type) (1 << power_of_two));
01690   if (power_of_two > bfd_get_section_alignment (htab->elf.dynobj, s))
01691     {
01692       if (! bfd_set_section_alignment (htab->elf.dynobj, s, power_of_two))
01693        return FALSE;
01694     }
01695 
01696   /* Define the symbol as being at this point in the section.  */
01697   h->root.u.def.section = s;
01698   h->root.u.def.value = s->size;
01699 
01700   /* Increment the section size to make room for the symbol.  */
01701   s->size += h->size;
01702 
01703   return TRUE;
01704 }
01705 
01706 /* Allocate space in .plt, .got and associated reloc sections for
01707    dynamic relocs.  */
01708 
01709 static bfd_boolean
01710 allocate_dynrelocs (h, inf)
01711      struct elf_link_hash_entry *h;
01712      PTR inf;
01713 {
01714   struct bfd_link_info *info;
01715   struct elf_s390_link_hash_table *htab;
01716   struct elf_s390_link_hash_entry *eh;
01717   struct elf_s390_dyn_relocs *p;
01718 
01719   if (h->root.type == bfd_link_hash_indirect)
01720     return TRUE;
01721 
01722   if (h->root.type == bfd_link_hash_warning)
01723     /* When warning symbols are created, they **replace** the "real"
01724        entry in the hash table, thus we never get to see the real
01725        symbol in a hash traversal.  So look at it now.  */
01726     h = (struct elf_link_hash_entry *) h->root.u.i.link;
01727 
01728   info = (struct bfd_link_info *) inf;
01729   htab = elf_s390_hash_table (info);
01730 
01731   if (htab->elf.dynamic_sections_created
01732       && h->plt.refcount > 0
01733       && (ELF_ST_VISIBILITY (h->other) == STV_DEFAULT
01734          || h->root.type != bfd_link_hash_undefweak))
01735     {
01736       /* Make sure this symbol is output as a dynamic symbol.
01737         Undefined weak syms won't yet be marked as dynamic.  */
01738       if (h->dynindx == -1
01739          && !h->forced_local)
01740        {
01741          if (! bfd_elf_link_record_dynamic_symbol (info, h))
01742            return FALSE;
01743        }
01744 
01745       if (info->shared
01746          || WILL_CALL_FINISH_DYNAMIC_SYMBOL (1, 0, h))
01747        {
01748          asection *s = htab->splt;
01749 
01750          /* If this is the first .plt entry, make room for the special
01751             first entry.  */
01752          if (s->size == 0)
01753            s->size += PLT_FIRST_ENTRY_SIZE;
01754 
01755          h->plt.offset = s->size;
01756 
01757          /* If this symbol is not defined in a regular file, and we are
01758             not generating a shared library, then set the symbol to this
01759             location in the .plt.  This is required to make function
01760             pointers compare as equal between the normal executable and
01761             the shared library.  */
01762          if (! info->shared
01763              && !h->def_regular)
01764            {
01765              h->root.u.def.section = s;
01766              h->root.u.def.value = h->plt.offset;
01767            }
01768 
01769          /* Make room for this entry.  */
01770          s->size += PLT_ENTRY_SIZE;
01771 
01772          /* We also need to make an entry in the .got.plt section, which
01773             will be placed in the .got section by the linker script.  */
01774          htab->sgotplt->size += GOT_ENTRY_SIZE;
01775 
01776          /* We also need to make an entry in the .rela.plt section.  */
01777          htab->srelplt->size += sizeof (Elf64_External_Rela);
01778        }
01779       else
01780        {
01781          h->plt.offset = (bfd_vma) -1;
01782          h->needs_plt = 0;
01783          elf_s390_adjust_gotplt((struct elf_s390_link_hash_entry *) h);
01784        }
01785     }
01786   else
01787     {
01788       h->plt.offset = (bfd_vma) -1;
01789       h->needs_plt = 0;
01790       elf_s390_adjust_gotplt((struct elf_s390_link_hash_entry *) h);
01791     }
01792 
01793   /* If R_390_TLS_{IE64,GOTIE64,GOTIE12,IEENT} symbol is now local to
01794      the binary, we can optimize a bit. IE64 and GOTIE64 get converted
01795      to R_390_TLS_LE64 requiring no TLS entry. For GOTIE12 and IEENT
01796      we can save the dynamic TLS relocation.  */
01797   if (h->got.refcount > 0
01798       && !info->shared
01799       && h->dynindx == -1
01800       && elf_s390_hash_entry(h)->tls_type >= GOT_TLS_IE)
01801     {
01802       if (elf_s390_hash_entry(h)->tls_type == GOT_TLS_IE_NLT)
01803        /* For the GOTIE access without a literal pool entry the offset has
01804           to be stored somewhere. The immediate value in the instruction
01805           is not bit enough so the value is stored in the got.  */
01806        {
01807          h->got.offset = htab->sgot->size;
01808          htab->sgot->size += GOT_ENTRY_SIZE;
01809        }
01810       else
01811        h->got.offset = (bfd_vma) -1;
01812     }
01813   else if (h->got.refcount > 0)
01814     {
01815       asection *s;
01816       bfd_boolean dyn;
01817       int tls_type = elf_s390_hash_entry(h)->tls_type;
01818 
01819       /* Make sure this symbol is output as a dynamic symbol.
01820         Undefined weak syms won't yet be marked as dynamic.  */
01821       if (h->dynindx == -1
01822          && !h->forced_local)
01823        {
01824          if (! bfd_elf_link_record_dynamic_symbol (info, h))
01825            return FALSE;
01826        }
01827 
01828       s = htab->sgot;
01829       h->got.offset = s->size;
01830       s->size += GOT_ENTRY_SIZE;
01831       /* R_390_TLS_GD64 needs 2 consecutive GOT slots.  */
01832       if (tls_type == GOT_TLS_GD)
01833        s->size += GOT_ENTRY_SIZE;
01834       dyn = htab->elf.dynamic_sections_created;
01835       /* R_390_TLS_IE64 needs one dynamic relocation,
01836         R_390_TLS_GD64 needs one if local symbol and two if global.  */
01837       if ((tls_type == GOT_TLS_GD && h->dynindx == -1)
01838          || tls_type >= GOT_TLS_IE)
01839        htab->srelgot->size += sizeof (Elf64_External_Rela);
01840       else if (tls_type == GOT_TLS_GD)
01841        htab->srelgot->size += 2 * sizeof (Elf64_External_Rela);
01842       else if ((ELF_ST_VISIBILITY (h->other) == STV_DEFAULT
01843               || h->root.type != bfd_link_hash_undefweak)
01844               && (info->shared
01845                  || WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn, 0, h)))
01846        htab->srelgot->size += sizeof (Elf64_External_Rela);
01847     }
01848   else
01849     h->got.offset = (bfd_vma) -1;
01850 
01851   eh = (struct elf_s390_link_hash_entry *) h;
01852   if (eh->dyn_relocs == NULL)
01853     return TRUE;
01854 
01855   /* In the shared -Bsymbolic case, discard space allocated for
01856      dynamic pc-relative relocs against symbols which turn out to be
01857      defined in regular objects.  For the normal shared case, discard
01858      space for pc-relative relocs that have become local due to symbol
01859      visibility changes.  */
01860 
01861   if (info->shared)
01862     {
01863       if (SYMBOL_REFERENCES_LOCAL (info, h))
01864        {
01865          struct elf_s390_dyn_relocs **pp;
01866 
01867          for (pp = &eh->dyn_relocs; (p = *pp) != NULL; )
01868            {
01869              p->count -= p->pc_count;
01870              p->pc_count = 0;
01871              if (p->count == 0)
01872               *pp = p->next;
01873              else
01874               pp = &p->next;
01875            }
01876        }
01877 
01878       /* Also discard relocs on undefined weak syms with non-default
01879         visibility.  */
01880       if (eh->dyn_relocs != NULL
01881          && h->root.type == bfd_link_hash_undefweak)
01882        {
01883          if (ELF_ST_VISIBILITY (h->other) != STV_DEFAULT)
01884            eh->dyn_relocs = NULL;
01885 
01886          /* Make sure undefined weak symbols are output as a dynamic
01887             symbol in PIEs.  */
01888          else if (h->dynindx == -1
01889                  && !h->forced_local)
01890            {
01891              if (! bfd_elf_link_record_dynamic_symbol (info, h))
01892               return FALSE;
01893            }
01894        }
01895     }
01896   else if (ELIMINATE_COPY_RELOCS)
01897     {
01898       /* For the non-shared case, discard space for relocs against
01899         symbols which turn out to need copy relocs or are not
01900         dynamic.  */
01901 
01902       if (!h->non_got_ref
01903          && ((h->def_dynamic
01904               && !h->def_regular)
01905              || (htab->elf.dynamic_sections_created
01906                 && (h->root.type == bfd_link_hash_undefweak
01907                     || h->root.type == bfd_link_hash_undefined))))
01908        {
01909          /* Make sure this symbol is output as a dynamic symbol.
01910             Undefined weak syms won't yet be marked as dynamic.  */
01911          if (h->dynindx == -1
01912              && !h->forced_local)
01913            {
01914              if (! bfd_elf_link_record_dynamic_symbol (info, h))
01915               return FALSE;
01916            }
01917 
01918          /* If that succeeded, we know we'll be keeping all the
01919             relocs.  */
01920          if (h->dynindx != -1)
01921            goto keep;
01922        }
01923 
01924       eh->dyn_relocs = NULL;
01925 
01926     keep: ;
01927     }
01928 
01929   /* Finally, allocate space.  */
01930   for (p = eh->dyn_relocs; p != NULL; p = p->next)
01931     {
01932       asection *sreloc = elf_section_data (p->sec)->sreloc;
01933       sreloc->size += p->count * sizeof (Elf64_External_Rela);
01934     }
01935 
01936   return TRUE;
01937 }
01938 
01939 /* Find any dynamic relocs that apply to read-only sections.  */
01940 
01941 static bfd_boolean
01942 readonly_dynrelocs (h, inf)
01943      struct elf_link_hash_entry *h;
01944      PTR inf;
01945 {
01946   struct elf_s390_link_hash_entry *eh;
01947   struct elf_s390_dyn_relocs *p;
01948 
01949   if (h->root.type == bfd_link_hash_warning)
01950     h = (struct elf_link_hash_entry *) h->root.u.i.link;
01951 
01952   eh = (struct elf_s390_link_hash_entry *) h;
01953   for (p = eh->dyn_relocs; p != NULL; p = p->next)
01954     {
01955       asection *s = p->sec->output_section;
01956 
01957       if (s != NULL && (s->flags & SEC_READONLY) != 0)
01958        {
01959          struct bfd_link_info *info = (struct bfd_link_info *) inf;
01960 
01961          info->flags |= DF_TEXTREL;
01962 
01963          /* Not an error, just cut short the traversal.  */
01964          return FALSE;
01965        }
01966     }
01967   return TRUE;
01968 }
01969 
01970 /* Set the sizes of the dynamic sections.  */
01971 
01972 static bfd_boolean
01973 elf_s390_size_dynamic_sections (output_bfd, info)
01974      bfd *output_bfd ATTRIBUTE_UNUSED;
01975      struct bfd_link_info *info;
01976 {
01977   struct elf_s390_link_hash_table *htab;
01978   bfd *dynobj;
01979   asection *s;
01980   bfd_boolean relocs;
01981   bfd *ibfd;
01982 
01983   htab = elf_s390_hash_table (info);
01984   dynobj = htab->elf.dynobj;
01985   if (dynobj == NULL)
01986     abort ();
01987 
01988   if (htab->elf.dynamic_sections_created)
01989     {
01990       /* Set the contents of the .interp section to the interpreter.  */
01991       if (info->executable)
01992        {
01993          s = bfd_get_section_by_name (dynobj, ".interp");
01994          if (s == NULL)
01995            abort ();
01996          s->size = sizeof ELF_DYNAMIC_INTERPRETER;
01997          s->contents = (unsigned char *) ELF_DYNAMIC_INTERPRETER;
01998        }
01999     }
02000 
02001   /* Set up .got offsets for local syms, and space for local dynamic
02002      relocs.  */
02003   for (ibfd = info->input_bfds; ibfd != NULL; ibfd = ibfd->link_next)
02004     {
02005       bfd_signed_vma *local_got;
02006       bfd_signed_vma *end_local_got;
02007       char *local_tls_type;
02008       bfd_size_type locsymcount;
02009       Elf_Internal_Shdr *symtab_hdr;
02010       asection *srela;
02011 
02012       if (bfd_get_flavour (ibfd) != bfd_target_elf_flavour)
02013        continue;
02014 
02015       for (s = ibfd->sections; s != NULL; s = s->next)
02016        {
02017          struct elf_s390_dyn_relocs *p;
02018 
02019          for (p = elf_section_data (s)->local_dynrel; p != NULL; p = p->next)
02020            {
02021              if (!bfd_is_abs_section (p->sec)
02022                 && bfd_is_abs_section (p->sec->output_section))
02023               {
02024                 /* Input section has been discarded, either because
02025                    it is a copy of a linkonce section or due to
02026                    linker script /DISCARD/, so we'll be discarding
02027                    the relocs too.  */
02028               }
02029              else if (p->count != 0)
02030               {
02031                 srela = elf_section_data (p->sec)->sreloc;
02032                 srela->size += p->count * sizeof (Elf64_External_Rela);
02033                 if ((p->sec->output_section->flags & SEC_READONLY) != 0)
02034                   info->flags |= DF_TEXTREL;
02035               }
02036            }
02037        }
02038 
02039       local_got = elf_local_got_refcounts (ibfd);
02040       if (!local_got)
02041        continue;
02042 
02043       symtab_hdr = &elf_tdata (ibfd)->symtab_hdr;
02044       locsymcount = symtab_hdr->sh_info;
02045       end_local_got = local_got + locsymcount;
02046       local_tls_type = elf_s390_local_got_tls_type (ibfd);
02047       s = htab->sgot;
02048       srela = htab->srelgot;
02049       for (; local_got < end_local_got; ++local_got, ++local_tls_type)
02050        {
02051          if (*local_got > 0)
02052            {
02053              *local_got = s->size;
02054              s->size += GOT_ENTRY_SIZE;
02055              if (*local_tls_type == GOT_TLS_GD)
02056               s->size += GOT_ENTRY_SIZE;
02057              if (info->shared)
02058               srela->size += sizeof (Elf64_External_Rela);
02059            }
02060          else
02061            *local_got = (bfd_vma) -1;
02062        }
02063     }
02064 
02065   if (htab->tls_ldm_got.refcount > 0)
02066     {
02067       /* Allocate 2 got entries and 1 dynamic reloc for R_390_TLS_LDM64
02068         relocs.  */
02069       htab->tls_ldm_got.offset = htab->sgot->size;
02070       htab->sgot->size += 2 * GOT_ENTRY_SIZE;
02071       htab->srelgot->size += sizeof (Elf64_External_Rela);
02072     }
02073   else
02074     htab->tls_ldm_got.offset = -1;
02075 
02076   /* Allocate global sym .plt and .got entries, and space for global
02077      sym dynamic relocs.  */
02078   elf_link_hash_traverse (&htab->elf, allocate_dynrelocs, (PTR) info);
02079 
02080   /* We now have determined the sizes of the various dynamic sections.
02081      Allocate memory for them.  */
02082   relocs = FALSE;
02083   for (s = dynobj->sections; s != NULL; s = s->next)
02084     {
02085       if ((s->flags & SEC_LINKER_CREATED) == 0)
02086        continue;
02087 
02088       if (s == htab->splt
02089          || s == htab->sgot
02090          || s == htab->sgotplt
02091          || s == htab->sdynbss)
02092        {
02093          /* Strip this section if we don't need it; see the
02094             comment below.  */
02095        }
02096       else if (CONST_STRNEQ (bfd_get_section_name (dynobj, s), ".rela"))
02097        {
02098          if (s->size != 0 && s != htab->srelplt)
02099            relocs = TRUE;
02100 
02101          /* We use the reloc_count field as a counter if we need
02102             to copy relocs into the output file.  */
02103          s->reloc_count = 0;
02104        }
02105       else
02106        {
02107          /* It's not one of our sections, so don't allocate space.  */
02108          continue;
02109        }
02110 
02111       if (s->size == 0)
02112        {
02113          /* If we don't need this section, strip it from the
02114             output file.  This is to handle .rela.bss and
02115             .rela.plt.  We must create it in
02116             create_dynamic_sections, because it must be created
02117             before the linker maps input sections to output
02118             sections.  The linker does that before
02119             adjust_dynamic_symbol is called, and it is that
02120             function which decides whether anything needs to go
02121             into these sections.  */
02122 
02123          s->flags |= SEC_EXCLUDE;
02124          continue;
02125        }
02126 
02127       if ((s->flags & SEC_HAS_CONTENTS) == 0)
02128        continue;
02129 
02130       /* Allocate memory for the section contents.  We use bfd_zalloc
02131         here in case unused entries are not reclaimed before the
02132         section's contents are written out.  This should not happen,
02133         but this way if it does, we get a R_390_NONE reloc instead
02134         of garbage.  */
02135       s->contents = (bfd_byte *) bfd_zalloc (dynobj, s->size);
02136       if (s->contents == NULL)
02137        return FALSE;
02138     }
02139 
02140   if (htab->elf.dynamic_sections_created)
02141     {
02142       /* Add some entries to the .dynamic section.  We fill in the
02143         values later, in elf_s390_finish_dynamic_sections, but we
02144         must add the entries now so that we get the correct size for
02145         the .dynamic section.  The DT_DEBUG entry is filled in by the
02146         dynamic linker and used by the debugger.  */
02147 #define add_dynamic_entry(TAG, VAL) \
02148   _bfd_elf_add_dynamic_entry (info, TAG, VAL)
02149 
02150       if (info->executable)
02151        {
02152          if (!add_dynamic_entry (DT_DEBUG, 0))
02153            return FALSE;
02154        }
02155 
02156       if (htab->splt->size != 0)
02157        {
02158          if (!add_dynamic_entry (DT_PLTGOT, 0)
02159              || !add_dynamic_entry (DT_PLTRELSZ, 0)
02160              || !add_dynamic_entry (DT_PLTREL, DT_RELA)
02161              || !add_dynamic_entry (DT_JMPREL, 0))
02162            return FALSE;
02163        }
02164 
02165       if (relocs)
02166        {
02167          if (!add_dynamic_entry (DT_RELA, 0)
02168              || !add_dynamic_entry (DT_RELASZ, 0)
02169              || !add_dynamic_entry (DT_RELAENT, sizeof (Elf64_External_Rela)))
02170            return FALSE;
02171 
02172          /* If any dynamic relocs apply to a read-only section,
02173             then we need a DT_TEXTREL entry.  */
02174          if ((info->flags & DF_TEXTREL) == 0)
02175            elf_link_hash_traverse (&htab->elf, readonly_dynrelocs,
02176                                 (PTR) info);
02177 
02178          if ((info->flags & DF_TEXTREL) != 0)
02179            {
02180              if (!add_dynamic_entry (DT_TEXTREL, 0))
02181               return FALSE;
02182            }
02183        }
02184     }
02185 #undef add_dynamic_entry
02186 
02187   return TRUE;
02188 }
02189 
02190 /* Return the base VMA address which should be subtracted from real addresses
02191    when resolving @dtpoff relocation.
02192    This is PT_TLS segment p_vaddr.  */
02193 
02194 static bfd_vma
02195 dtpoff_base (info)
02196      struct bfd_link_info *info;
02197 {
02198   /* If tls_sec is NULL, we should have signalled an error already.  */
02199   if (elf_hash_table (info)->tls_sec == NULL)
02200     return 0;
02201   return elf_hash_table (info)->tls_sec->vma;
02202 }
02203 
02204 /* Return the relocation value for @tpoff relocation
02205    if STT_TLS virtual address is ADDRESS.  */
02206 
02207 static bfd_vma
02208 tpoff (info, address)
02209      struct bfd_link_info *info;
02210      bfd_vma address;
02211 {
02212   struct elf_link_hash_table *htab = elf_hash_table (info);
02213 
02214   /* If tls_sec is NULL, we should have signalled an error already.  */
02215   if (htab->tls_sec == NULL)
02216     return 0;
02217   return htab->tls_size + htab->tls_sec->vma - address;
02218 }
02219 
02220 /* Complain if TLS instruction relocation is against an invalid
02221    instruction.  */
02222 
02223 static void
02224 invalid_tls_insn (input_bfd, input_section, rel)
02225      bfd *input_bfd;
02226      asection *input_section;
02227      Elf_Internal_Rela *rel;
02228 {
02229   reloc_howto_type *howto;
02230 
02231   howto = elf_howto_table + ELF64_R_TYPE (rel->r_info);
02232   (*_bfd_error_handler)
02233     (_("%B(%A+0x%lx): invalid instruction for TLS relocation %s"),
02234      input_bfd,
02235      input_section,
02236      (long) rel->r_offset,
02237      howto->name);
02238   bfd_set_error (bfd_error_bad_value);
02239 }
02240 
02241 /* Relocate a 390 ELF section.  */
02242 
02243 static bfd_boolean
02244 elf_s390_relocate_section (output_bfd, info, input_bfd, input_section,
02245                            contents, relocs, local_syms, local_sections)
02246      bfd *output_bfd;
02247      struct bfd_link_info *info;
02248      bfd *input_bfd;
02249      asection *input_section;
02250      bfd_byte *contents;
02251      Elf_Internal_Rela *relocs;
02252      Elf_Internal_Sym *local_syms;
02253      asection **local_sections;
02254 {
02255   struct elf_s390_link_hash_table *htab;
02256   Elf_Internal_Shdr *symtab_hdr;
02257   struct elf_link_hash_entry **sym_hashes;
02258   bfd_vma *local_got_offsets;
02259   Elf_Internal_Rela *rel;
02260   Elf_Internal_Rela *relend;
02261 
02262   htab = elf_s390_hash_table (info);
02263   symtab_hdr = &elf_tdata (input_bfd)->symtab_hdr;
02264   sym_hashes = elf_sym_hashes (input_bfd);
02265   local_got_offsets = elf_local_got_offsets (input_bfd);
02266 
02267   rel = relocs;
02268   relend = relocs + input_section->reloc_count;
02269   for (; rel < relend; rel++)
02270     {
02271       unsigned int r_type;
02272       reloc_howto_type *howto;
02273       unsigned long r_symndx;
02274       struct elf_link_hash_entry *h;
02275       Elf_Internal_Sym *sym;
02276       asection *sec;
02277       bfd_vma off;
02278       bfd_vma relocation;
02279       bfd_boolean unresolved_reloc;
02280       bfd_reloc_status_type r;
02281       int tls_type;
02282 
02283       r_type = ELF64_R_TYPE (rel->r_info);
02284       if (r_type == (int) R_390_GNU_VTINHERIT
02285          || r_type == (int) R_390_GNU_VTENTRY)
02286        continue;
02287       if (r_type >= (int) R_390_max)
02288        {
02289          bfd_set_error (bfd_error_bad_value);
02290          return FALSE;
02291        }
02292 
02293       howto = elf_howto_table + r_type;
02294       r_symndx = ELF64_R_SYM (rel->r_info);
02295 
02296       h = NULL;
02297       sym = NULL;
02298       sec = NULL;
02299       unresolved_reloc = FALSE;
02300       if (r_symndx < symtab_hdr->sh_info)
02301        {
02302          sym = local_syms + r_symndx;
02303          sec = local_sections[r_symndx];
02304          relocation = _bfd_elf_rela_local_sym (output_bfd, sym, &sec, rel);
02305        }
02306       else
02307        {
02308          bfd_boolean warned ATTRIBUTE_UNUSED;
02309 
02310          RELOC_FOR_GLOBAL_SYMBOL (info, input_bfd, input_section, rel,
02311                                r_symndx, symtab_hdr, sym_hashes,
02312                                h, sec, relocation,
02313                                unresolved_reloc, warned);
02314        }
02315 
02316       if (sec != NULL && elf_discarded_section (sec))
02317        {
02318          /* For relocs against symbols from removed linkonce sections,
02319             or sections discarded by a linker script, we just want the
02320             section contents zeroed.  Avoid any special processing.  */
02321          _bfd_clear_contents (howto, input_bfd, contents + rel->r_offset);
02322          rel->r_info = 0;
02323          rel->r_addend = 0;
02324          continue;
02325        }
02326 
02327       if (info->relocatable)
02328        continue;
02329 
02330       switch (r_type)
02331        {
02332        case R_390_GOTPLT12:
02333        case R_390_GOTPLT16:
02334        case R_390_GOTPLT20:
02335        case R_390_GOTPLT32:
02336        case R_390_GOTPLT64:
02337        case R_390_GOTPLTENT:
02338          /* There are three cases for a GOTPLT relocation. 1) The
02339             relocation is against the jump slot entry of a plt that
02340             will get emitted to the output file. 2) The relocation
02341             is against the jump slot of a plt entry that has been
02342             removed. elf_s390_adjust_gotplt has created a GOT entry
02343             as replacement. 3) The relocation is against a local symbol.
02344             Cases 2) and 3) are the same as the GOT relocation code
02345             so we just have to test for case 1 and fall through for
02346             the other two.  */
02347          if (h != NULL && h->plt.offset != (bfd_vma) -1)
02348            {
02349              bfd_vma plt_index;
02350 
02351              /* Calc. index no.
02352                Current offset - size first entry / entry size.  */
02353              plt_index = (h->plt.offset - PLT_FIRST_ENTRY_SIZE) /
02354               PLT_ENTRY_SIZE;
02355 
02356              /* Offset in GOT is PLT index plus GOT headers(3) times 4,
02357                addr & GOT addr.  */
02358              relocation = (plt_index + 3) * GOT_ENTRY_SIZE;
02359              unresolved_reloc = FALSE;
02360 
02361              if (r_type == R_390_GOTPLTENT)
02362               relocation += htab->sgot->output_section->vma;
02363              break;
02364            }
02365          /* Fall through.  */
02366 
02367        case R_390_GOT12:
02368        case R_390_GOT16:
02369        case R_390_GOT20:
02370        case R_390_GOT32:
02371        case R_390_GOT64:
02372        case R_390_GOTENT:
02373          /* Relocation is to the entry for this symbol in the global
02374             offset table.  */
02375          if (htab->sgot == NULL)
02376            abort ();
02377 
02378          if (h != NULL)
02379            {
02380              bfd_boolean dyn;
02381 
02382              off = h->got.offset;
02383              dyn = htab->elf.dynamic_sections_created;
02384              if (! WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn, info->shared, h)
02385                 || (info->shared
02386                     && (info->symbolic
02387                        || h->dynindx == -1
02388                        || h->forced_local)
02389                     && h->def_regular)
02390                 || (ELF_ST_VISIBILITY (h->other)
02391                     && h->root.type == bfd_link_hash_undefweak))
02392               {
02393                 /* This is actually a static link, or it is a
02394                    -Bsymbolic link and the symbol is defined
02395                    locally, or the symbol was forced to be local
02396                    because of a version file.  We must initialize
02397                    this entry in the global offset table.  Since the
02398                    offset must always be a multiple of 2, we use the
02399                    least significant bit to record whether we have
02400                    initialized it already.
02401 
02402                    When doing a dynamic link, we create a .rel.got
02403                    relocation entry to initialize the value.  This
02404                    is done in the finish_dynamic_symbol routine.  */
02405                 if ((off & 1) != 0)
02406                   off &= ~1;
02407                 else
02408                   {
02409                     bfd_put_64 (output_bfd, relocation,
02410                               htab->sgot->contents + off);
02411                     h->got.offset |= 1;
02412                   }
02413               }
02414              else
02415               unresolved_reloc = FALSE;
02416            }
02417          else
02418            {
02419              if (local_got_offsets == NULL)
02420               abort ();
02421 
02422              off = local_got_offsets[r_symndx];
02423 
02424              /* The offset must always be a multiple of 8.  We use
02425                the least significant bit to record whether we have
02426                already generated the necessary reloc.  */
02427              if ((off & 1) != 0)
02428               off &= ~1;
02429              else
02430               {
02431                 bfd_put_64 (output_bfd, relocation,
02432                            htab->sgot->contents + off);
02433 
02434                 if (info->shared)
02435                   {
02436                     asection *s;
02437                     Elf_Internal_Rela outrel;
02438                     bfd_byte *loc;
02439 
02440                     s = htab->srelgot;
02441                     if (s == NULL)
02442                      abort ();
02443 
02444                     outrel.r_offset = (htab->sgot->output_section->vma
02445                                     + htab->sgot->output_offset
02446                                     + off);
02447                     outrel.r_info = ELF64_R_INFO (0, R_390_RELATIVE);
02448                     outrel.r_addend = relocation;
02449                     loc = s->contents;
02450                     loc += s->reloc_count++ * sizeof (Elf64_External_Rela);
02451                     bfd_elf64_swap_reloca_out (output_bfd, &outrel, loc);
02452                   }
02453 
02454                 local_got_offsets[r_symndx] |= 1;
02455               }
02456            }
02457 
02458          if (off >= (bfd_vma) -2)
02459            abort ();
02460 
02461          relocation = htab->sgot->output_offset + off;
02462 
02463          /* For @GOTENT the relocation is against the offset between
02464             the instruction and the symbols entry in the GOT and not
02465             between the start of the GOT and the symbols entry. We
02466             add the vma of the GOT to get the correct value.  */
02467          if (   r_type == R_390_GOTENT
02468              || r_type == R_390_GOTPLTENT)
02469            relocation += htab->sgot->output_section->vma;
02470 
02471          break;
02472 
02473        case R_390_GOTOFF16:
02474        case R_390_GOTOFF32:
02475        case R_390_GOTOFF64:
02476          /* Relocation is relative to the start of the global offset
02477             table.  */
02478 
02479          /* Note that sgot->output_offset is not involved in this
02480             calculation.  We always want the start of .got.  If we
02481             defined _GLOBAL_OFFSET_TABLE in a different way, as is
02482             permitted by the ABI, we might have to change this
02483             calculation.  */
02484          relocation -= htab->sgot->output_section->vma;
02485          break;
02486 
02487        case R_390_GOTPC:
02488        case R_390_GOTPCDBL:
02489          /* Use global offset table as symbol value.  */
02490          relocation = htab->sgot->output_section->vma;
02491          unresolved_reloc = FALSE;
02492          break;
02493 
02494        case R_390_PLT16DBL:
02495        case R_390_PLT32:
02496        case R_390_PLT32DBL:
02497        case R_390_PLT64:
02498          /* Relocation is to the entry for this symbol in the
02499             procedure linkage table.  */
02500 
02501          /* Resolve a PLT32 reloc against a local symbol directly,
02502             without using the procedure linkage table.  */
02503          if (h == NULL)
02504            break;
02505 
02506          if (h->plt.offset == (bfd_vma) -1
02507              || htab->splt == NULL)
02508            {
02509              /* We didn't make a PLT entry for this symbol.  This
02510                happens when statically linking PIC code, or when
02511                using -Bsymbolic.  */
02512              break;
02513            }
02514 
02515          relocation = (htab->splt->output_section->vma
02516                      + htab->splt->output_offset
02517                      + h->plt.offset);
02518          unresolved_reloc = FALSE;
02519          break;
02520 
02521        case R_390_PLTOFF16:
02522        case R_390_PLTOFF32:
02523        case R_390_PLTOFF64:
02524          /* Relocation is to the entry for this symbol in the
02525             procedure linkage table relative to the start of the GOT.  */
02526 
02527          /* For local symbols or if we didn't make a PLT entry for
02528             this symbol resolve the symbol directly.  */
02529          if (   h == NULL
02530              || h->plt.offset == (bfd_vma) -1
02531              || htab->splt == NULL)
02532            {
02533              relocation -= htab->sgot->output_section->vma;
02534              break;
02535            }
02536 
02537          relocation = (htab->splt->output_section->vma
02538                      + htab->splt->output_offset
02539                      + h->plt.offset
02540                      - htab->sgot->output_section->vma);
02541          unresolved_reloc = FALSE;
02542          break;
02543 
02544        case R_390_8:
02545        case R_390_16:
02546        case R_390_32:
02547        case R_390_64:
02548        case R_390_PC16:
02549        case R_390_PC16DBL:
02550        case R_390_PC32:
02551        case R_390_PC32DBL:
02552        case R_390_PC64:
02553          if ((input_section->flags & SEC_ALLOC) == 0)
02554            break;
02555 
02556          if ((info->shared
02557               && (h == NULL
02558                  || ELF_ST_VISIBILITY (h->other) == STV_DEFAULT
02559                  || h->root.type != bfd_link_hash_undefweak)
02560               && ((r_type != R_390_PC16
02561                   && r_type != R_390_PC16DBL
02562                   && r_type != R_390_PC32
02563                   && r_type != R_390_PC32DBL
02564                   && r_type != R_390_PC64)
02565                  || (h != NULL
02566                      && !SYMBOL_REFERENCES_LOCAL (info, h))))
02567              || (ELIMINATE_COPY_RELOCS
02568                 && !info->shared
02569                 && h != NULL
02570                 && h->dynindx != -1
02571                 && !h->non_got_ref
02572                 && ((h->def_dynamic
02573                      && !h->def_regular)
02574                     || h->root.type == bfd_link_hash_undefweak
02575                     || h->root.type == bfd_link_hash_undefined)))
02576            {
02577              Elf_Internal_Rela outrel;
02578              bfd_boolean skip, relocate;
02579              asection *sreloc;
02580              bfd_byte *loc;
02581 
02582              /* When generating a shared object, these relocations
02583                are copied into the output file to be resolved at run
02584                time.  */
02585              skip = FALSE;
02586              relocate = FALSE;
02587 
02588              outrel.r_offset =
02589               _bfd_elf_section_offset (output_bfd, info, input_section,
02590                                     rel->r_offset);
02591              if (outrel.r_offset == (bfd_vma) -1)
02592               skip = TRUE;
02593              else if (outrel.r_offset == (bfd_vma) -2)
02594               skip = TRUE, relocate = TRUE;
02595 
02596              outrel.r_offset += (input_section->output_section->vma
02597                               + input_section->output_offset);
02598 
02599              if (skip)
02600               memset (&outrel, 0, sizeof outrel);
02601              else if (h != NULL
02602                      && h->dynindx != -1
02603                      && (r_type == R_390_PC16
02604                         || r_type == R_390_PC16DBL
02605                         || r_type == R_390_PC32
02606                         || r_type == R_390_PC32DBL
02607                         || r_type == R_390_PC64
02608                         || !info->shared
02609                         || !info->symbolic
02610                         || !h->def_regular))
02611               {
02612                 outrel.r_info = ELF64_R_INFO (h->dynindx, r_type);
02613                 outrel.r_addend = rel->r_addend;
02614               }
02615              else
02616               {
02617                 /* This symbol is local, or marked to become local.  */
02618                 outrel.r_addend = relocation + rel->r_addend;
02619                 if (r_type == R_390_64)
02620                   {
02621                     relocate = TRUE;
02622                     outrel.r_info = ELF64_R_INFO (0, R_390_RELATIVE);
02623                   }
02624                 else
02625                   {
02626                     long sindx;
02627 
02628                     if (bfd_is_abs_section (sec))
02629                      sindx = 0;
02630                     else if (sec == NULL || sec->owner == NULL)
02631                      {
02632                        bfd_set_error(bfd_error_bad_value);
02633                        return FALSE;
02634                      }
02635                     else
02636                      {
02637                        asection *osec;
02638 
02639                        osec = sec->output_section;
02640                        sindx = elf_section_data (osec)->dynindx;
02641 
02642                        if (sindx == 0)
02643                          {
02644                            osec = htab->elf.text_index_section;
02645                            sindx = elf_section_data (osec)->dynindx;
02646                          }
02647                        BFD_ASSERT (sindx != 0);
02648 
02649                        /* We are turning this relocation into one
02650                           against a section symbol, so subtract out
02651                           the output section's address but not the
02652                           offset of the input section in the output
02653                           section.  */
02654                        outrel.r_addend -= osec->vma;
02655                      }
02656                     outrel.r_info = ELF64_R_INFO (sindx, r_type);
02657                   }
02658               }
02659 
02660              sreloc = elf_section_data (input_section)->sreloc;
02661              if (sreloc == NULL)
02662               abort ();
02663 
02664              loc = sreloc->contents;
02665              loc += sreloc->reloc_count++ * sizeof (Elf64_External_Rela);
02666              bfd_elf64_swap_reloca_out (output_bfd, &outrel, loc);
02667 
02668              /* If this reloc is against an external symbol, we do
02669                not want to fiddle with the addend.  Otherwise, we
02670                need to include the symbol value so that it becomes
02671                an addend for the dynamic reloc.  */
02672              if (! relocate)
02673               continue;
02674            }
02675 
02676          break;
02677 
02678          /* Relocations for tls literal pool entries.  */
02679        case R_390_TLS_IE64:
02680          if (info->shared)
02681            {
02682              Elf_Internal_Rela outrel;
02683              asection *sreloc;
02684              bfd_byte *loc;
02685 
02686              outrel.r_offset = rel->r_offset
02687                             + input_section->output_section->vma
02688                             + input_section->output_offset;
02689              outrel.r_info = ELF64_R_INFO (0, R_390_RELATIVE);
02690              sreloc = elf_section_data (input_section)->sreloc;
02691              if (sreloc == NULL)
02692               abort ();
02693              loc = sreloc->contents;
02694              loc += sreloc->reloc_count++ * sizeof (Elf64_External_Rela);
02695              bfd_elf64_swap_reloc_out (output_bfd, &outrel, loc);
02696            }
02697          /* Fall through.  */
02698 
02699        case R_390_TLS_GD64:
02700        case R_390_TLS_GOTIE64:
02701          r_type = elf_s390_tls_transition (info, r_type, h == NULL);
02702          tls_type = GOT_UNKNOWN;
02703          if (h == NULL && local_got_offsets)
02704            tls_type = elf_s390_local_got_tls_type (input_bfd) [r_symndx];
02705          else if (h != NULL)
02706            {
02707              tls_type = elf_s390_hash_entry(h)->tls_type;
02708              if (!info->shared && h->dynindx == -1 && tls_type >= GOT_TLS_IE)
02709               r_type = R_390_TLS_LE64;
02710            }
02711          if (r_type == R_390_TLS_GD64 && tls_type >= GOT_TLS_IE)
02712            r_type = R_390_TLS_IE64;
02713 
02714          if (r_type == R_390_TLS_LE64)
02715            {
02716              /* This relocation gets optimized away by the local exec
02717                access optimization.  */
02718              BFD_ASSERT (! unresolved_reloc);
02719              bfd_put_64 (output_bfd, -tpoff (info, relocation),
02720                        contents + rel->r_offset);
02721              continue;
02722            }
02723 
02724          if (htab->sgot == NULL)
02725            abort ();
02726 
02727          if (h != NULL)
02728            off = h->got.offset;
02729          else
02730            {
02731              if (local_got_offsets == NULL)
02732               abort ();
02733 
02734              off = local_got_offsets[r_symndx];
02735            }
02736 
02737        emit_tls_relocs:
02738 
02739          if ((off & 1) != 0)
02740            off &= ~1;
02741          else
02742            {
02743              Elf_Internal_Rela outrel;
02744              bfd_byte *loc;
02745              int dr_type, indx;
02746 
02747              if (htab->srelgot == NULL)
02748               abort ();
02749 
02750              outrel.r_offset = (htab->sgot->output_section->vma
02751                              + htab->sgot->output_offset + off);
02752 
02753              indx = h && h->dynindx != -1 ? h->dynindx : 0;
02754              if (r_type == R_390_TLS_GD64)
02755               dr_type = R_390_TLS_DTPMOD;
02756              else
02757               dr_type = R_390_TLS_TPOFF;
02758              if (dr_type == R_390_TLS_TPOFF && indx == 0)
02759               outrel.r_addend = relocation - dtpoff_base (info);
02760              else
02761               outrel.r_addend = 0;
02762              outrel.r_info = ELF64_R_INFO (indx, dr_type);
02763              loc = htab->srelgot->contents;
02764              loc += htab->srelgot->reloc_count++
02765               * sizeof (Elf64_External_Rela);
02766              bfd_elf64_swap_reloca_out (output_bfd, &outrel, loc);
02767 
02768              if (r_type == R_390_TLS_GD64)
02769               {
02770                 if (indx == 0)
02771                   {
02772                     BFD_ASSERT (! unresolved_reloc);
02773                     bfd_put_64 (output_bfd,
02774                               relocation - dtpoff_base (info),
02775                               htab->sgot->contents + off + GOT_ENTRY_SIZE);
02776                   }
02777                 else
02778                   {
02779                     outrel.r_info = ELF64_R_INFO (indx, R_390_TLS_DTPOFF);
02780                     outrel.r_offset += GOT_ENTRY_SIZE;
02781                     outrel.r_addend = 0;
02782                     htab->srelgot->reloc_count++;
02783                     loc += sizeof (Elf64_External_Rela);
02784                     bfd_elf64_swap_reloca_out (output_bfd, &outrel, loc);
02785                   }
02786               }
02787 
02788              if (h != NULL)
02789               h->got.offset |= 1;
02790              else
02791               local_got_offsets[r_symndx] |= 1;
02792            }
02793 
02794          if (off >= (bfd_vma) -2)
02795            abort ();
02796          if (r_type == ELF64_R_TYPE (rel->r_info))
02797            {
02798              relocation = htab->sgot->output_offset + off;
02799              if (r_type == R_390_TLS_IE64 || r_type == R_390_TLS_IEENT)
02800               relocation += htab->sgot->output_section->vma;
02801              unresolved_reloc = FALSE;
02802            }
02803          else
02804            {
02805              bfd_put_64 (output_bfd, htab->sgot->output_offset + off,
02806                        contents + rel->r_offset);
02807              continue;
02808            }
02809          break;
02810 
02811        case R_390_TLS_GOTIE12:
02812        case R_390_TLS_GOTIE20:
02813        case R_390_TLS_IEENT:
02814          if (h == NULL)
02815            {
02816              if (local_got_offsets == NULL)
02817               abort();
02818              off = local_got_offsets[r_symndx];
02819              if (info->shared)
02820               goto emit_tls_relocs;
02821            }
02822          else
02823            {
02824              off = h->got.offset;
02825              tls_type = elf_s390_hash_entry(h)->tls_type;
02826              if (info->shared || h->dynindx != -1 || tls_type < GOT_TLS_IE)
02827               goto emit_tls_relocs;
02828            }
02829 
02830          if (htab->sgot == NULL)
02831            abort ();
02832 
02833          BFD_ASSERT (! unresolved_reloc);
02834          bfd_put_64 (output_bfd, -tpoff (info, relocation),
02835                     htab->sgot->contents + off);
02836          relocation = htab->sgot->output_offset + off;
02837          if (r_type == R_390_TLS_IEENT)
02838            relocation += htab->sgot->output_section->vma;
02839          unresolved_reloc = FALSE;
02840          break;
02841 
02842        case R_390_TLS_LDM64:
02843          if (! info->shared)
02844            /* The literal pool entry this relocation refers to gets ignored
02845               by the optimized code of the local exec model. Do nothing
02846               and the value will turn out zero.  */
02847            continue;
02848 
02849          if (htab->sgot == NULL)
02850            abort ();
02851 
02852          off = htab->tls_ldm_got.offset;
02853          if (off & 1)
02854            off &= ~1;
02855          else
02856            {
02857              Elf_Internal_Rela outrel;
02858              bfd_byte *loc;
02859 
02860              if (htab->srelgot == NULL)
02861               abort ();
02862 
02863              outrel.r_offset = (htab->sgot->output_section->vma
02864                              + htab->sgot->output_offset + off);
02865 
02866              bfd_put_64 (output_bfd, 0,
02867                        htab->sgot->contents + off + GOT_ENTRY_SIZE);
02868              outrel.r_info = ELF64_R_INFO (0, R_390_TLS_DTPMOD);
02869              outrel.r_addend = 0;
02870              loc = htab->srelgot->contents;
02871              loc += htab->srelgot->reloc_count++
02872               * sizeof (Elf64_External_Rela);
02873              bfd_elf64_swap_reloca_out (output_bfd, &outrel, loc);
02874              htab->tls_ldm_got.offset |= 1;
02875            }
02876          relocation = htab->sgot->output_offset + off;
02877          unresolved_reloc = FALSE;
02878          break;
02879 
02880        case R_390_TLS_LE64:
02881          if (info->shared)
02882            {
02883              /* Linking a shared library with non-fpic code requires
02884                a R_390_TLS_TPOFF relocation.  */
02885              Elf_Internal_Rela outrel;
02886              asection *sreloc;
02887              bfd_byte *loc;
02888              int indx;
02889 
02890              outrel.r_offset = rel->r_offset
02891                             + input_section->output_section->vma
02892                             + input_section->output_offset;
02893              if (h != NULL && h->dynindx != -1)
02894               indx = h->dynindx;
02895              else
02896               indx = 0;
02897              outrel.r_info = ELF64_R_INFO (indx, R_390_TLS_TPOFF);
02898              if (indx == 0)
02899               outrel.r_addend = relocation - dtpoff_base (info);
02900              else
02901               outrel.r_addend = 0;
02902              sreloc = elf_section_data (input_section)->sreloc;
02903              if (sreloc == NULL)
02904               abort ();
02905              loc = sreloc->contents;
02906              loc += sreloc->reloc_count++ * sizeof (Elf64_External_Rela);
02907              bfd_elf64_swap_reloca_out (output_bfd, &outrel, loc);
02908            }
02909          else
02910            {
02911              BFD_ASSERT (! unresolved_reloc);
02912              bfd_put_64 (output_bfd, -tpoff (info, relocation),
02913                        contents + rel->r_offset);
02914            }
02915          continue;
02916 
02917        case R_390_TLS_LDO64:
02918          if (info->shared)
02919            relocation -= dtpoff_base (info);
02920          else
02921            /* When converting LDO to LE, we must negate.  */
02922            relocation = -tpoff (info, relocation);
02923          break;
02924 
02925          /* Relocations for tls instructions.  */
02926        case R_390_TLS_LOAD:
02927        case R_390_TLS_GDCALL:
02928        case R_390_TLS_LDCALL:
02929          tls_type = GOT_UNKNOWN;
02930          if (h == NULL && local_got_offsets)
02931            tls_type = elf_s390_local_got_tls_type (input_bfd) [r_symndx];
02932          else if (h != NULL)
02933            tls_type = elf_s390_hash_entry(h)->tls_type;
02934 
02935          if (tls_type == GOT_TLS_GD)
02936            continue;
02937 
02938          if (r_type == R_390_TLS_LOAD)
02939            {
02940              if (!info->shared && (h == NULL || h->dynindx == -1))
02941               {
02942                 /* IE->LE transition. Four valid cases:
02943                    lg %rx,(0,%ry)    -> sllg %rx,%ry,0
02944                    lg %rx,(%ry,0)    -> sllg %rx,%ry,0
02945                    lg %rx,(%ry,%r12) -> sllg %rx,%ry,0
02946                    lg %rx,(%r12,%ry) -> sllg %rx,%ry,0  */
02947                 unsigned int insn0, insn1, ry;
02948 
02949                 insn0 = bfd_get_32 (input_bfd, contents + rel->r_offset);
02950                 insn1 = bfd_get_16 (input_bfd, contents + rel->r_offset + 4);
02951                 if (insn1 != 0x0004)
02952                   invalid_tls_insn (input_bfd, input_section, rel);
02953                 ry = 0;
02954                 if ((insn0 & 0xff00f000) == 0xe3000000)
02955                   /* lg %rx,0(%ry,0) -> sllg %rx,%ry,0  */
02956                   ry = (insn0 & 0x000f0000);
02957                 else if ((insn0 & 0xff0f0000) == 0xe3000000)
02958                   /* lg %rx,0(0,%ry) -> sllg %rx,%ry,0  */
02959                   ry = (insn0 & 0x0000f000) << 4;
02960                 else if ((insn0 & 0xff00f000) == 0xe300c000)
02961                   /* lg %rx,0(%ry,%r12) -> sllg %rx,%ry,0  */
02962                   ry = (insn0 & 0x000f0000);
02963                 else if ((insn0 & 0xff0f0000) == 0xe30c0000)
02964                   /* lg %rx,0(%r12,%ry) -> sllg %rx,%ry,0  */
02965                   ry = (insn0 & 0x0000f000) << 4;
02966                 else
02967                   invalid_tls_insn (input_bfd, input_section, rel);
02968                 insn0 = 0xeb000000 | (insn0 & 0x00f00000) | ry;
02969                 insn1 = 0x000d;
02970                 bfd_put_32 (output_bfd, insn0, contents + rel->r_offset);
02971                 bfd_put_16 (output_bfd, insn1, contents + rel->r_offset + 4);
02972               }
02973            }
02974          else if (r_type == R_390_TLS_GDCALL)
02975            {
02976              unsigned int insn0, insn1;
02977 
02978              insn0 = bfd_get_32 (input_bfd, contents + rel->r_offset);
02979              insn1 = bfd_get_16 (input_bfd, contents + rel->r_offset + 4);
02980              if ((insn0 & 0xffff0000) != 0xc0e50000)
02981               invalid_tls_insn (input_bfd, input_section, rel);
02982              if (!info->shared && (h == NULL || h->dynindx == -1))
02983               {
02984                 /* GD->LE transition.
02985                    brasl %r14,__tls_get_addr@plt -> brcl 0,. */
02986                 insn0 = 0xc0040000;
02987                 insn1 = 0x0000;
02988               }
02989              else
02990               {
02991                 /* GD->IE transition.
02992                    brasl %r14,__tls_get_addr@plt -> lg %r2,0(%r2,%r12)  */
02993                 insn0 = 0xe322c000;
02994                 insn1 = 0x0004;
02995               }
02996              bfd_put_32 (output_bfd, insn0, contents + rel->r_offset);
02997              bfd_put_16 (output_bfd, insn1, contents + rel->r_offset + 4);
02998            }
02999          else if (r_type == R_390_TLS_LDCALL)
03000            {
03001              if (!info->shared)
03002               {
03003                 unsigned int insn0, insn1;
03004 
03005                 insn0 = bfd_get_32 (input_bfd, contents + rel->r_offset);
03006                 insn1 = bfd_get_16 (input_bfd, contents + rel->r_offset + 4);
03007                 if ((insn0 & 0xffff0000) != 0xc0e50000)
03008                   invalid_tls_insn (input_bfd, input_section, rel);
03009                 /* LD->LE transition.
03010                    brasl %r14,__tls_get_addr@plt -> brcl 0,. */
03011                 insn0 = 0xc0040000;
03012                 insn1 = 0x0000;
03013                 bfd_put_32 (output_bfd, insn0, contents + rel->r_offset);
03014                 bfd_put_16 (output_bfd, insn1, contents + rel->r_offset + 4);
03015               }
03016            }
03017          continue;
03018 
03019        default:
03020          break;
03021        }
03022 
03023       /* Dynamic relocs are not propagated for SEC_DEBUGGING sections
03024         because such sections are not SEC_ALLOC and thus ld.so will
03025         not process them.  */
03026       if (unresolved_reloc
03027          && !((input_section->flags & SEC_DEBUGGING) != 0
03028               && h->def_dynamic))
03029        (*_bfd_error_handler)
03030          (_("%B(%A+0x%lx): unresolvable %s relocation against symbol `%s'"),
03031           input_bfd,
03032           input_section,
03033           (long) rel->r_offset,
03034           howto->name,
03035           h->root.root.string);
03036 
03037       if (r_type == R_390_20
03038          || r_type == R_390_GOT20
03039          || r_type == R_390_GOTPLT20
03040          || r_type == R_390_TLS_GOTIE20)
03041        {
03042          relocation += rel->r_addend;
03043          relocation = (relocation&0xfff) << 8 | (relocation&0xff000) >> 12;
03044          r = _bfd_final_link_relocate (howto, input_bfd, input_section,
03045                                    contents, rel->r_offset,
03046                                    relocation, 0);
03047        }
03048       else
03049        r = _bfd_final_link_relocate (howto, input_bfd, input_section,
03050                                   contents, rel->r_offset,
03051                                   relocation, rel->r_addend);
03052 
03053       if (r != bfd_reloc_ok)
03054        {
03055          const char *name;
03056 
03057          if (h != NULL)
03058            name = h->root.root.string;
03059          else
03060            {
03061              name = bfd_elf_string_from_elf_section (input_bfd,
03062                                                 symtab_hdr->sh_link,
03063                                                 sym->st_name);
03064              if (name == NULL)
03065               return FALSE;
03066              if (*name == '\0')
03067               name = bfd_section_name (input_bfd, sec);
03068            }
03069 
03070          if (r == bfd_reloc_overflow)
03071            {
03072 
03073              if (! ((*info->callbacks->reloc_overflow)
03074                    (info, (h ? &h->root : NULL), name, howto->name,
03075                     (bfd_vma) 0, input_bfd, input_section,
03076                     rel->r_offset)))
03077               return FALSE;
03078            }
03079          else
03080            {
03081              (*_bfd_error_handler)
03082               (_("%B(%A+0x%lx): reloc against `%s': error %d"),
03083                input_bfd, input_section,
03084                (long) rel->r_offset, name, (int) r);
03085              return FALSE;
03086            }
03087        }
03088     }
03089 
03090   return TRUE;
03091 }
03092 
03093 /* Finish up dynamic symbol handling.  We set the contents of various
03094    dynamic sections here.  */
03095 
03096 static bfd_boolean
03097 elf_s390_finish_dynamic_symbol (output_bfd, info, h, sym)
03098      bfd *output_bfd;
03099      struct bfd_link_info *info;
03100      struct elf_link_hash_entry *h;
03101      Elf_Internal_Sym *sym;
03102 {
03103   struct elf_s390_link_hash_table *htab;
03104 
03105   htab = elf_s390_hash_table (info);
03106 
03107   if (h->plt.offset != (bfd_vma) -1)
03108     {
03109       bfd_vma plt_index;
03110       bfd_vma got_offset;
03111       Elf_Internal_Rela rela;
03112       bfd_byte *loc;
03113 
03114       /* This symbol has an entry in the procedure linkage table.  Set
03115         it up.  */
03116 
03117       if (h->dynindx == -1
03118          || htab->splt == NULL
03119          || htab->sgotplt == NULL
03120          || htab->srelplt == NULL)
03121        abort ();
03122 
03123       /* Calc. index no.
03124         Current offset - size first entry / entry size.  */
03125       plt_index = (h->plt.offset - PLT_FIRST_ENTRY_SIZE) / PLT_ENTRY_SIZE;
03126 
03127       /* Offset in GOT is PLT index plus GOT headers(3) times 8,
03128         addr & GOT addr.  */
03129       got_offset = (plt_index + 3) * GOT_ENTRY_SIZE;
03130 
03131       /* Fill in the blueprint of a PLT.  */
03132       bfd_put_32 (output_bfd, (bfd_vma) PLT_ENTRY_WORD0,
03133                 htab->splt->contents + h->plt.offset);
03134       bfd_put_32 (output_bfd, (bfd_vma) PLT_ENTRY_WORD1,
03135                 htab->splt->contents + h->plt.offset + 4);
03136       bfd_put_32 (output_bfd, (bfd_vma) PLT_ENTRY_WORD2,
03137                 htab->splt->contents + h->plt.offset + 8);
03138       bfd_put_32 (output_bfd, (bfd_vma) PLT_ENTRY_WORD3,
03139                 htab->splt->contents + h->plt.offset + 12);
03140       bfd_put_32 (output_bfd, (bfd_vma) PLT_ENTRY_WORD4,
03141                 htab->splt->contents + h->plt.offset + 16);
03142       bfd_put_32 (output_bfd, (bfd_vma) PLT_ENTRY_WORD5,
03143                 htab->splt->contents + h->plt.offset + 20);
03144       bfd_put_32 (output_bfd, (bfd_vma) PLT_ENTRY_WORD6,
03145                 htab->splt->contents + h->plt.offset + 24);
03146       bfd_put_32 (output_bfd, (bfd_vma) PLT_ENTRY_WORD7,
03147                 htab->splt->contents + h->plt.offset + 28);
03148       /* Fixup the relative address to the GOT entry */
03149       bfd_put_32 (output_bfd,
03150                 (htab->sgotplt->output_section->vma +
03151                  htab->sgotplt->output_offset + got_offset
03152                  - (htab->splt->output_section->vma + h->plt.offset))/2,
03153                 htab->splt->contents + h->plt.offset + 2);
03154       /* Fixup the relative branch to PLT 0 */
03155       bfd_put_32 (output_bfd, - (PLT_FIRST_ENTRY_SIZE +
03156                              (PLT_ENTRY_SIZE * plt_index) + 22)/2,
03157                 htab->splt->contents + h->plt.offset + 24);
03158       /* Fixup offset into symbol table */
03159       bfd_put_32 (output_bfd, plt_index * sizeof (Elf64_External_Rela),
03160                 htab->splt->contents + h->plt.offset + 28);
03161 
03162       /* Fill in the entry in the global offset table.
03163         Points to instruction after GOT offset.  */
03164       bfd_put_64 (output_bfd,
03165                 (htab->splt->output_section->vma
03166                  + htab->splt->output_offset
03167                  + h->plt.offset
03168                  + 14),
03169                 htab->sgotplt->contents + got_offset);
03170 
03171       /* Fill in the entry in the .rela.plt section.  */
03172       rela.r_offset = (htab->sgotplt->output_section->vma
03173                      + htab->sgotplt->output_offset
03174                      + got_offset);
03175       rela.r_info = ELF64_R_INFO (h->dynindx, R_390_JMP_SLOT);
03176       rela.r_addend = 0;
03177       loc = htab->srelplt->contents + plt_index * sizeof (Elf64_External_Rela);
03178       bfd_elf64_swap_reloca_out (output_bfd, &rela, loc);
03179 
03180       if (!h->def_regular)
03181        {
03182          /* Mark the symbol as undefined, rather than as defined in
03183             the .plt section.  Leave the value alone.  This is a clue
03184             for the dynamic linker, to make function pointer
03185             comparisons work between an application and shared
03186             library.  */
03187          sym->st_shndx = SHN_UNDEF;
03188        }
03189     }
03190 
03191   if (h->got.offset != (bfd_vma) -1
03192       && elf_s390_hash_entry(h)->tls_type != GOT_TLS_GD
03193       && elf_s390_hash_entry(h)->tls_type != GOT_TLS_IE
03194       && elf_s390_hash_entry(h)->tls_type != GOT_TLS_IE_NLT)
03195     {
03196       Elf_Internal_Rela rela;
03197       bfd_byte *loc;
03198 
03199       /* This symbol has an entry in the global offset table.  Set it
03200         up.  */
03201       if (htab->sgot == NULL || htab->srelgot == NULL)
03202        abort ();
03203 
03204       rela.r_offset = (htab->sgot->output_section->vma
03205                      + htab->sgot->output_offset
03206                      + (h->got.offset &~ (bfd_vma) 1));
03207 
03208       /* If this is a static link, or it is a -Bsymbolic link and the
03209         symbol is defined locally or was forced to be local because
03210         of a version file, we just want to emit a RELATIVE reloc.
03211         The entry in the global offset table will already have been
03212         initialized in the relocate_section function.  */
03213       if (info->shared
03214          && (info->symbolic
03215              || h->dynindx == -1
03216              || h->forced_local)
03217          && h->def_regular)
03218        {
03219          BFD_ASSERT((h->got.offset & 1) != 0);
03220          rela.r_info = ELF64_R_INFO (0, R_390_RELATIVE);
03221          rela.r_addend = (h->root.u.def.value
03222                         + h->root.u.def.section->output_section->vma
03223                         + h->root.u.def.section->output_offset);
03224        }
03225       else
03226        {
03227          BFD_ASSERT((h->got.offset & 1) == 0);
03228          bfd_put_64 (output_bfd, (bfd_vma) 0, htab->sgot->contents + h->got.offset);
03229          rela.r_info = ELF64_R_INFO (h->dynindx, R_390_GLOB_DAT);
03230          rela.r_addend = 0;
03231        }
03232 
03233       loc = htab->srelgot->contents;
03234       loc += htab->srelgot->reloc_count++ * sizeof (Elf64_External_Rela);
03235       bfd_elf64_swap_reloca_out (output_bfd, &rela, loc);
03236     }
03237 
03238   if (h->needs_copy)
03239     {
03240       Elf_Internal_Rela rela;
03241       bfd_byte *loc;
03242 
03243       /* This symbols needs a copy reloc.  Set it up.  */
03244 
03245       if (h->dynindx == -1
03246          || (h->root.type != bfd_link_hash_defined
03247              && h->root.type != bfd_link_hash_defweak)
03248          || htab->srelbss == NULL)
03249        abort ();
03250 
03251       rela.r_offset = (h->root.u.def.value
03252                      + h->root.u.def.section->output_section->vma
03253                      + h->root.u.def.section->output_offset);
03254       rela.r_info = ELF64_R_INFO (h->dynindx, R_390_COPY);
03255       rela.r_addend = 0;
03256       loc = htab->srelbss->contents;
03257       loc += htab->srelbss->reloc_count++ * sizeof (Elf64_External_Rela);
03258       bfd_elf64_swap_reloca_out (output_bfd, &rela, loc);
03259     }
03260 
03261   /* Mark some specially defined symbols as absolute.  */
03262   if (strcmp (h->root.root.string, "_DYNAMIC") == 0
03263       || h == htab->elf.hgot
03264       || h == htab->elf.hplt)
03265     sym->st_shndx = SHN_ABS;
03266 
03267   return TRUE;
03268 }
03269 
03270 /* Used to decide how to sort relocs in an optimal manner for the
03271    dynamic linker, before writing them out.  */
03272 
03273 static enum elf_reloc_type_class
03274 elf_s390_reloc_type_class (rela)
03275      const Elf_Internal_Rela *rela;
03276 {
03277   switch ((int) ELF64_R_TYPE (rela->r_info))
03278     {
03279     case R_390_RELATIVE:
03280       return reloc_class_relative;
03281     case R_390_JMP_SLOT:
03282       return reloc_class_plt;
03283     case R_390_COPY:
03284       return reloc_class_copy;
03285     default:
03286       return reloc_class_normal;
03287     }
03288 }
03289 
03290 /* Finish up the dynamic sections.  */
03291 
03292 static bfd_boolean
03293 elf_s390_finish_dynamic_sections (output_bfd, info)
03294      bfd *output_bfd;
03295      struct bfd_link_info *info;
03296 {
03297   struct elf_s390_link_hash_table *htab;
03298   bfd *dynobj;
03299   asection *sdyn;
03300 
03301   htab = elf_s390_hash_table (info);
03302   dynobj = htab->elf.dynobj;
03303   sdyn = bfd_get_section_by_name (dynobj, ".dynamic");
03304 
03305   if (htab->elf.dynamic_sections_created)
03306     {
03307       Elf64_External_Dyn *dyncon, *dynconend;
03308 
03309       if (sdyn == NULL || htab->sgot == NULL)
03310        abort ();
03311 
03312       dyncon = (Elf64_External_Dyn *) sdyn->contents;
03313       dynconend = (Elf64_External_Dyn *) (sdyn->contents + sdyn->size);
03314       for (; dyncon < dynconend; dyncon++)
03315        {
03316          Elf_Internal_Dyn dyn;
03317          asection *s;
03318 
03319          bfd_elf64_swap_dyn_in (dynobj, dyncon, &dyn);
03320 
03321          switch (dyn.d_tag)
03322            {
03323            default:
03324              continue;
03325 
03326            case DT_PLTGOT:
03327              dyn.d_un.d_ptr = htab->sgot->output_section->vma;
03328              break;
03329 
03330            case DT_JMPREL:
03331              dyn.d_un.d_ptr = htab->srelplt->output_section->vma;
03332              break;
03333 
03334            case DT_PLTRELSZ:
03335              s = htab->srelplt->output_section;
03336              dyn.d_un.d_val = s->size;
03337              break;
03338 
03339            case DT_RELASZ:
03340              /* The procedure linkage table relocs (DT_JMPREL) should
03341                not be included in the overall relocs (DT_RELA).
03342                Therefore, we override the DT_RELASZ entry here to
03343                make it not include the JMPREL relocs.  Since the
03344                linker script arranges for .rela.plt to follow all
03345                other relocation sections, we don't have to worry
03346                about changing the DT_RELA entry.  */
03347              s = htab->srelplt->output_section;
03348              dyn.d_un.d_val -= s->size;
03349              break;
03350            }
03351 
03352          bfd_elf64_swap_dyn_out (output_bfd, &dyn, dyncon);
03353        }
03354 
03355       /* Fill in the special first entry in the procedure linkage table.  */
03356       if (htab->splt && htab->splt->size > 0)
03357        {
03358          /* fill in blueprint for plt 0 entry */
03359          bfd_put_32 (output_bfd, (bfd_vma) PLT_FIRST_ENTRY_WORD0,
03360                     htab->splt->contents );
03361          bfd_put_32 (output_bfd, (bfd_vma) PLT_FIRST_ENTRY_WORD1,
03362                     htab->splt->contents +4 );
03363          bfd_put_32 (output_bfd, (bfd_vma) PLT_FIRST_ENTRY_WORD3,
03364                     htab->splt->contents +12 );
03365          bfd_put_32 (output_bfd, (bfd_vma) PLT_FIRST_ENTRY_WORD4,
03366                     htab->splt->contents +16 );
03367          bfd_put_32 (output_bfd, (bfd_vma) PLT_FIRST_ENTRY_WORD5,
03368                     htab->splt->contents +20 );
03369          bfd_put_32 (output_bfd, (bfd_vma) PLT_FIRST_ENTRY_WORD6,
03370                     htab->splt->contents + 24);
03371          bfd_put_32 (output_bfd, (bfd_vma) PLT_FIRST_ENTRY_WORD7,
03372                     htab->splt->contents + 28 );
03373          /* Fixup relative address to start of GOT */
03374          bfd_put_32 (output_bfd,
03375                     (htab->sgotplt->output_section->vma +
03376                      htab->sgotplt->output_offset
03377                      - htab->splt->output_section->vma - 6)/2,
03378                     htab->splt->contents + 8);
03379        }
03380       elf_section_data (htab->splt->output_section)
03381        ->this_hdr.sh_entsize = PLT_ENTRY_SIZE;
03382     }
03383 
03384   if (htab->sgotplt)
03385     {
03386       /* Fill in the first three entries in the global offset table.  */
03387       if (htab->sgotplt->size > 0)
03388        {
03389          bfd_put_64 (output_bfd,
03390                     (sdyn == NULL ? (bfd_vma) 0
03391                      : sdyn->output_section->vma + sdyn->output_offset),
03392                     htab->sgotplt->contents);
03393          /* One entry for shared object struct ptr.  */
03394          bfd_put_64 (output_bfd, (bfd_vma) 0, htab->sgotplt->contents + 8);
03395          /* One entry for _dl_runtime_resolve.  */
03396          bfd_put_64 (output_bfd, (bfd_vma) 0, htab->sgotplt->contents + 12);
03397        }
03398 
03399       elf_section_data (htab->sgot->output_section)
03400        ->this_hdr.sh_entsize = 8;
03401     }
03402   return TRUE;
03403 }
03404 
03405 /* Return address for Ith PLT stub in section PLT, for relocation REL
03406    or (bfd_vma) -1 if it should not be included.  */
03407 
03408 static bfd_vma
03409 elf_s390_plt_sym_val (bfd_vma i, const asection *plt,
03410                     const arelent *rel ATTRIBUTE_UNUSED)
03411 {
03412   return plt->vma + PLT_FIRST_ENTRY_SIZE + i * PLT_ENTRY_SIZE;
03413 }
03414 
03415 
03416 /* Why was the hash table entry size definition changed from
03417    ARCH_SIZE/8 to 4? This breaks the 64 bit dynamic linker and
03418    this is the only reason for the s390_elf64_size_info structure.  */
03419 
03420 const struct elf_size_info s390_elf64_size_info =
03421 {
03422   sizeof (Elf64_External_Ehdr),
03423   sizeof (Elf64_External_Phdr),
03424   sizeof (Elf64_External_Shdr),
03425   sizeof (Elf64_External_Rel),
03426   sizeof (Elf64_External_Rela),
03427   sizeof (Elf64_External_Sym),
03428   sizeof (Elf64_External_Dyn),
03429   sizeof (Elf_External_Note),
03430   8,          /* hash-table entry size.  */
03431   1,          /* internal relocations per external relocations.  */
03432   64,         /* arch_size.  */
03433   3,          /* log_file_align.  */
03434   ELFCLASS64, EV_CURRENT,
03435   bfd_elf64_write_out_phdrs,
03436   bfd_elf64_write_shdrs_and_ehdr,
03437   bfd_elf64_write_relocs,
03438   bfd_elf64_swap_symbol_in,
03439   bfd_elf64_swap_symbol_out,
03440   bfd_elf64_slurp_reloc_table,
03441   bfd_elf64_slurp_symbol_table,
03442   bfd_elf64_swap_dyn_in,
03443   bfd_elf64_swap_dyn_out,
03444   bfd_elf64_swap_reloc_in,
03445   bfd_elf64_swap_reloc_out,
03446   bfd_elf64_swap_reloca_in,
03447   bfd_elf64_swap_reloca_out
03448 };
03449 
03450 #define TARGET_BIG_SYM      bfd_elf64_s390_vec
03451 #define TARGET_BIG_NAME     "elf64-s390"
03452 #define ELF_ARCH     bfd_arch_s390
03453 #define ELF_MACHINE_CODE EM_S390
03454 #define ELF_MACHINE_ALT1 EM_S390_OLD
03455 #define ELF_MAXPAGESIZE 0x1000
03456 
03457 #define elf_backend_size_info             s390_elf64_size_info
03458 
03459 #define elf_backend_can_gc_sections       1
03460 #define elf_backend_can_refcount   1
03461 #define elf_backend_want_got_plt   1
03462 #define elf_backend_plt_readonly   1
03463 #define elf_backend_want_plt_sym   0
03464 #define elf_backend_got_header_size       24
03465 #define elf_backend_rela_normal           1
03466 
03467 #define elf_info_to_howto          elf_s390_info_to_howto
03468 
03469 #define bfd_elf64_bfd_is_local_label_name     elf_s390_is_local_label_name
03470 #define bfd_elf64_bfd_link_hash_table_create  elf_s390_link_hash_table_create
03471 #define bfd_elf64_bfd_reloc_type_lookup         elf_s390_reloc_type_lookup
03472 #define bfd_elf64_bfd_reloc_name_lookup elf_s390_reloc_name_lookup
03473 
03474 #define elf_backend_adjust_dynamic_symbol     elf_s390_adjust_dynamic_symbol
03475 #define elf_backend_check_relocs         elf_s390_check_relocs
03476 #define elf_backend_copy_indirect_symbol      elf_s390_copy_indirect_symbol
03477 #define elf_backend_create_dynamic_sections   elf_s390_create_dynamic_sections
03478 #define elf_backend_finish_dynamic_sections   elf_s390_finish_dynamic_sections
03479 #define elf_backend_finish_dynamic_symbol     elf_s390_finish_dynamic_symbol
03480 #define elf_backend_gc_mark_hook         elf_s390_gc_mark_hook
03481 #define elf_backend_gc_sweep_hook        elf_s390_gc_sweep_hook
03482 #define elf_backend_reloc_type_class            elf_s390_reloc_type_class
03483 #define elf_backend_relocate_section            elf_s390_relocate_section
03484 #define elf_backend_size_dynamic_sections     elf_s390_size_dynamic_sections
03485 #define elf_backend_init_index_section          _bfd_elf_init_1_index_section
03486 #define elf_backend_reloc_type_class            elf_s390_reloc_type_class
03487 #define elf_backend_plt_sym_val                 elf_s390_plt_sym_val
03488 
03489 #define bfd_elf64_mkobject         elf_s390_mkobject
03490 #define elf_backend_object_p              elf_s390_object_p
03491 
03492 #include "elf64-target.h"