Back to index

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