| 1 | /* IBM S/390-specific support for 64-bit ELF
|
|---|
| 2 | Copyright 2000, 2001, 2002, 2003 Free Software Foundation, Inc.
|
|---|
| 3 | Contributed Martin Schwidefsky (schwidefsky@de.ibm.com).
|
|---|
| 4 |
|
|---|
| 5 | This file is part of BFD, the Binary File Descriptor library.
|
|---|
| 6 |
|
|---|
| 7 | This program is free software; you can redistribute it and/or modify
|
|---|
| 8 | it under the terms of the GNU General Public License as published by
|
|---|
| 9 | the Free Software Foundation; either version 2 of the License, or
|
|---|
| 10 | (at your option) any later version.
|
|---|
| 11 |
|
|---|
| 12 | This program is distributed in the hope that it will be useful,
|
|---|
| 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|---|
| 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|---|
| 15 | GNU General Public License for more details.
|
|---|
| 16 |
|
|---|
| 17 | You should have received a copy of the GNU General Public License
|
|---|
| 18 | along with this program; if not, write to the Free Software
|
|---|
| 19 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
|
|---|
| 20 | 02111-1307, USA. */
|
|---|
| 21 |
|
|---|
| 22 | #include "bfd.h"
|
|---|
| 23 | #include "sysdep.h"
|
|---|
| 24 | #include "bfdlink.h"
|
|---|
| 25 | #include "libbfd.h"
|
|---|
| 26 | #include "elf-bfd.h"
|
|---|
| 27 |
|
|---|
| 28 | static reloc_howto_type *elf_s390_reloc_type_lookup
|
|---|
| 29 | PARAMS ((bfd *, bfd_reloc_code_real_type));
|
|---|
| 30 | static void elf_s390_info_to_howto
|
|---|
| 31 | PARAMS ((bfd *, arelent *, Elf_Internal_Rela *));
|
|---|
| 32 | static bfd_boolean elf_s390_is_local_label_name
|
|---|
| 33 | PARAMS ((bfd *, const char *));
|
|---|
| 34 | static struct bfd_hash_entry *link_hash_newfunc
|
|---|
| 35 | PARAMS ((struct bfd_hash_entry *, struct bfd_hash_table *, const char *));
|
|---|
| 36 | static struct bfd_link_hash_table *elf_s390_link_hash_table_create
|
|---|
| 37 | PARAMS ((bfd *));
|
|---|
| 38 | static bfd_boolean create_got_section
|
|---|
| 39 | PARAMS((bfd *, struct bfd_link_info *));
|
|---|
| 40 | static bfd_boolean elf_s390_create_dynamic_sections
|
|---|
| 41 | PARAMS((bfd *, struct bfd_link_info *));
|
|---|
| 42 | static void elf_s390_copy_indirect_symbol
|
|---|
| 43 | PARAMS ((struct elf_backend_data *, struct elf_link_hash_entry *,
|
|---|
| 44 | struct elf_link_hash_entry *));
|
|---|
| 45 | static bfd_boolean elf_s390_check_relocs
|
|---|
| 46 | PARAMS ((bfd *, struct bfd_link_info *, asection *,
|
|---|
| 47 | const Elf_Internal_Rela *));
|
|---|
| 48 | static asection *elf_s390_gc_mark_hook
|
|---|
| 49 | PARAMS ((asection *, struct bfd_link_info *, Elf_Internal_Rela *,
|
|---|
| 50 | struct elf_link_hash_entry *, Elf_Internal_Sym *));
|
|---|
| 51 | static bfd_boolean elf_s390_gc_sweep_hook
|
|---|
| 52 | PARAMS ((bfd *, struct bfd_link_info *, asection *,
|
|---|
| 53 | const Elf_Internal_Rela *));
|
|---|
| 54 | struct elf_s390_link_hash_entry;
|
|---|
| 55 | static void elf_s390_adjust_gotplt
|
|---|
| 56 | PARAMS ((struct elf_s390_link_hash_entry *));
|
|---|
| 57 | static bfd_boolean elf_s390_adjust_dynamic_symbol
|
|---|
| 58 | PARAMS ((struct bfd_link_info *, struct elf_link_hash_entry *));
|
|---|
| 59 | static bfd_boolean allocate_dynrelocs
|
|---|
| 60 | PARAMS ((struct elf_link_hash_entry *, PTR));
|
|---|
| 61 | static bfd_boolean readonly_dynrelocs
|
|---|
| 62 | PARAMS ((struct elf_link_hash_entry *, PTR));
|
|---|
| 63 | static bfd_boolean elf_s390_size_dynamic_sections
|
|---|
| 64 | PARAMS ((bfd *, struct bfd_link_info *));
|
|---|
| 65 | static bfd_boolean elf_s390_relocate_section
|
|---|
| 66 | PARAMS ((bfd *, struct bfd_link_info *, bfd *, asection *, bfd_byte *,
|
|---|
| 67 | Elf_Internal_Rela *, Elf_Internal_Sym *, asection **));
|
|---|
| 68 | static bfd_boolean elf_s390_finish_dynamic_symbol
|
|---|
| 69 | PARAMS ((bfd *, struct bfd_link_info *, struct elf_link_hash_entry *,
|
|---|
| 70 | Elf_Internal_Sym *));
|
|---|
| 71 | static enum elf_reloc_type_class elf_s390_reloc_type_class
|
|---|
| 72 | PARAMS ((const Elf_Internal_Rela *));
|
|---|
| 73 | static bfd_boolean elf_s390_finish_dynamic_sections
|
|---|
| 74 | PARAMS ((bfd *, struct bfd_link_info *));
|
|---|
| 75 | static bfd_boolean elf_s390_mkobject
|
|---|
| 76 | PARAMS ((bfd *));
|
|---|
| 77 | static bfd_boolean elf_s390_object_p
|
|---|
| 78 | PARAMS ((bfd *));
|
|---|
| 79 | static int elf_s390_tls_transition
|
|---|
| 80 | PARAMS ((struct bfd_link_info *, int, int));
|
|---|
| 81 | static bfd_reloc_status_type s390_tls_reloc
|
|---|
| 82 | PARAMS ((bfd *, arelent *, asymbol *, PTR, asection *, bfd *, char **));
|
|---|
| 83 | static bfd_vma dtpoff_base
|
|---|
| 84 | PARAMS ((struct bfd_link_info *));
|
|---|
| 85 | static bfd_vma tpoff
|
|---|
| 86 | PARAMS ((struct bfd_link_info *, bfd_vma));
|
|---|
| 87 | static void invalid_tls_insn
|
|---|
| 88 | PARAMS ((bfd *, asection *, Elf_Internal_Rela *));
|
|---|
| 89 |
|
|---|
| 90 | #include "elf/s390.h"
|
|---|
| 91 |
|
|---|
| 92 | /* In case we're on a 32-bit machine, construct a 64-bit "-1" value
|
|---|
| 93 | from smaller values. Start with zero, widen, *then* decrement. */
|
|---|
| 94 | #define MINUS_ONE (((bfd_vma)0) - 1)
|
|---|
| 95 |
|
|---|
| 96 | /* The relocation "howto" table. */
|
|---|
| 97 | static reloc_howto_type elf_howto_table[] =
|
|---|
| 98 | {
|
|---|
| 99 | HOWTO (R_390_NONE, /* type */
|
|---|
| 100 | 0, /* rightshift */
|
|---|
| 101 | 0, /* size (0 = byte, 1 = short, 2 = long) */
|
|---|
| 102 | 0, /* bitsize */
|
|---|
| 103 | FALSE, /* pc_relative */
|
|---|
| 104 | 0, /* bitpos */
|
|---|
| 105 | complain_overflow_dont, /* complain_on_overflow */
|
|---|
| 106 | bfd_elf_generic_reloc, /* special_function */
|
|---|
| 107 | "R_390_NONE", /* name */
|
|---|
| 108 | FALSE, /* partial_inplace */
|
|---|
| 109 | 0, /* src_mask */
|
|---|
| 110 | 0, /* dst_mask */
|
|---|
| 111 | FALSE), /* pcrel_offset */
|
|---|
| 112 |
|
|---|
| 113 | HOWTO(R_390_8, 0, 0, 8, FALSE, 0, complain_overflow_bitfield,
|
|---|
| 114 | bfd_elf_generic_reloc, "R_390_8", FALSE, 0,0x000000ff, FALSE),
|
|---|
| 115 | HOWTO(R_390_12, 0, 1, 12, FALSE, 0, complain_overflow_dont,
|
|---|
| 116 | bfd_elf_generic_reloc, "R_390_12", FALSE, 0,0x00000fff, FALSE),
|
|---|
| 117 | HOWTO(R_390_16, 0, 1, 16, FALSE, 0, complain_overflow_bitfield,
|
|---|
| 118 | bfd_elf_generic_reloc, "R_390_16", FALSE, 0,0x0000ffff, FALSE),
|
|---|
| 119 | HOWTO(R_390_32, 0, 2, 32, FALSE, 0, complain_overflow_bitfield,
|
|---|
| 120 | bfd_elf_generic_reloc, "R_390_32", FALSE, 0,0xffffffff, FALSE),
|
|---|
| 121 | HOWTO(R_390_PC32, 0, 2, 32, TRUE, 0, complain_overflow_bitfield,
|
|---|
| 122 | bfd_elf_generic_reloc, "R_390_PC32", FALSE, 0,0xffffffff, TRUE),
|
|---|
| 123 | HOWTO(R_390_GOT12, 0, 1, 12, FALSE, 0, complain_overflow_dont,
|
|---|
| 124 | bfd_elf_generic_reloc, "R_390_GOT12", FALSE, 0,0x00000fff, FALSE),
|
|---|
| 125 | HOWTO(R_390_GOT32, 0, 2, 32, FALSE, 0, complain_overflow_bitfield,
|
|---|
| 126 | bfd_elf_generic_reloc, "R_390_GOT32", FALSE, 0,0xffffffff, FALSE),
|
|---|
| 127 | HOWTO(R_390_PLT32, 0, 2, 32, TRUE, 0, complain_overflow_bitfield,
|
|---|
| 128 | bfd_elf_generic_reloc, "R_390_PLT32", FALSE, 0,0xffffffff, TRUE),
|
|---|
| 129 | HOWTO(R_390_COPY, 0, 4, 64, FALSE, 0, complain_overflow_bitfield,
|
|---|
| 130 | bfd_elf_generic_reloc, "R_390_COPY", FALSE, 0,MINUS_ONE, FALSE),
|
|---|
| 131 | HOWTO(R_390_GLOB_DAT, 0, 4, 64, FALSE, 0, complain_overflow_bitfield,
|
|---|
| 132 | bfd_elf_generic_reloc, "R_390_GLOB_DAT", FALSE, 0,MINUS_ONE, FALSE),
|
|---|
| 133 | HOWTO(R_390_JMP_SLOT, 0, 4, 64, FALSE, 0, complain_overflow_bitfield,
|
|---|
| 134 | bfd_elf_generic_reloc, "R_390_JMP_SLOT", FALSE, 0,MINUS_ONE, FALSE),
|
|---|
| 135 | HOWTO(R_390_RELATIVE, 0, 4, 64, TRUE, 0, complain_overflow_bitfield,
|
|---|
| 136 | bfd_elf_generic_reloc, "R_390_RELATIVE", FALSE, 0,MINUS_ONE, FALSE),
|
|---|
| 137 | HOWTO(R_390_GOTOFF32, 0, 2, 32, FALSE, 0, complain_overflow_bitfield,
|
|---|
| 138 | bfd_elf_generic_reloc, "R_390_GOTOFF32", FALSE, 0,MINUS_ONE, FALSE),
|
|---|
| 139 | HOWTO(R_390_GOTPC, 0, 4, 64, TRUE, 0, complain_overflow_bitfield,
|
|---|
| 140 | bfd_elf_generic_reloc, "R_390_GOTPC", FALSE, 0,MINUS_ONE, TRUE),
|
|---|
| 141 | HOWTO(R_390_GOT16, 0, 1, 16, FALSE, 0, complain_overflow_bitfield,
|
|---|
| 142 | bfd_elf_generic_reloc, "R_390_GOT16", FALSE, 0,0x0000ffff, FALSE),
|
|---|
| 143 | HOWTO(R_390_PC16, 0, 1, 16, TRUE, 0, complain_overflow_bitfield,
|
|---|
| 144 | bfd_elf_generic_reloc, "R_390_PC16", FALSE, 0,0x0000ffff, TRUE),
|
|---|
| 145 | HOWTO(R_390_PC16DBL, 1, 1, 16, TRUE, 0, complain_overflow_bitfield,
|
|---|
| 146 | bfd_elf_generic_reloc, "R_390_PC16DBL", FALSE, 0,0x0000ffff, TRUE),
|
|---|
| 147 | HOWTO(R_390_PLT16DBL, 1, 1, 16, TRUE, 0, complain_overflow_bitfield,
|
|---|
| 148 | bfd_elf_generic_reloc, "R_390_PLT16DBL", FALSE, 0,0x0000ffff, TRUE),
|
|---|
| 149 | HOWTO(R_390_PC32DBL, 1, 2, 32, TRUE, 0, complain_overflow_bitfield,
|
|---|
| 150 | bfd_elf_generic_reloc, "R_390_PC32DBL", FALSE, 0,0xffffffff, TRUE),
|
|---|
| 151 | HOWTO(R_390_PLT32DBL, 1, 2, 32, TRUE, 0, complain_overflow_bitfield,
|
|---|
| 152 | bfd_elf_generic_reloc, "R_390_PLT32DBL", FALSE, 0,0xffffffff, TRUE),
|
|---|
| 153 | HOWTO(R_390_GOTPCDBL, 1, 2, 32, TRUE, 0, complain_overflow_bitfield,
|
|---|
| 154 | bfd_elf_generic_reloc, "R_390_GOTPCDBL", FALSE, 0,MINUS_ONE, TRUE),
|
|---|
| 155 | HOWTO(R_390_64, 0, 4, 64, FALSE, 0, complain_overflow_bitfield,
|
|---|
| 156 | bfd_elf_generic_reloc, "R_390_64", FALSE, 0,MINUS_ONE, FALSE),
|
|---|
| 157 | HOWTO(R_390_PC64, 0, 4, 64, TRUE, 0, complain_overflow_bitfield,
|
|---|
| 158 | bfd_elf_generic_reloc, "R_390_PC64", FALSE, 0,MINUS_ONE, TRUE),
|
|---|
| 159 | HOWTO(R_390_GOT64, 0, 4, 64, FALSE, 0, complain_overflow_bitfield,
|
|---|
| 160 | bfd_elf_generic_reloc, "R_390_GOT64", FALSE, 0,MINUS_ONE, FALSE),
|
|---|
| 161 | HOWTO(R_390_PLT64, 0, 4, 64, TRUE, 0, complain_overflow_bitfield,
|
|---|
| 162 | bfd_elf_generic_reloc, "R_390_PLT64", FALSE, 0,MINUS_ONE, TRUE),
|
|---|
| 163 | HOWTO(R_390_GOTENT, 1, 2, 32, TRUE, 0, complain_overflow_bitfield,
|
|---|
| 164 | bfd_elf_generic_reloc, "R_390_GOTENT", FALSE, 0,MINUS_ONE, TRUE),
|
|---|
| 165 | HOWTO(R_390_GOTOFF16, 0, 1, 16, FALSE, 0, complain_overflow_bitfield,
|
|---|
| 166 | bfd_elf_generic_reloc, "R_390_GOTOFF16", FALSE, 0,0x0000ffff, FALSE),
|
|---|
| 167 | HOWTO(R_390_GOTOFF64, 0, 4, 64, FALSE, 0, complain_overflow_bitfield,
|
|---|
| 168 | bfd_elf_generic_reloc, "R_390_GOTOFF64", FALSE, 0,MINUS_ONE, FALSE),
|
|---|
| 169 | HOWTO(R_390_GOTPLT12, 0, 1, 12, FALSE, 0, complain_overflow_dont,
|
|---|
| 170 | bfd_elf_generic_reloc, "R_390_GOTPLT12", FALSE, 0,0x00000fff, FALSE),
|
|---|
| 171 | HOWTO(R_390_GOTPLT16, 0, 1, 16, FALSE, 0, complain_overflow_bitfield,
|
|---|
| 172 | bfd_elf_generic_reloc, "R_390_GOTPLT16", FALSE, 0,0x0000ffff, FALSE),
|
|---|
| 173 | HOWTO(R_390_GOTPLT32, 0, 2, 32, FALSE, 0, complain_overflow_bitfield,
|
|---|
| 174 | bfd_elf_generic_reloc, "R_390_GOTPLT32", FALSE, 0,0xffffffff, FALSE),
|
|---|
| 175 | HOWTO(R_390_GOTPLT64, 0, 4, 64, FALSE, 0, complain_overflow_bitfield,
|
|---|
| 176 | bfd_elf_generic_reloc, "R_390_GOTPLT64", FALSE, 0,MINUS_ONE, FALSE),
|
|---|
| 177 | HOWTO(R_390_GOTPLTENT, 1, 2, 32, TRUE, 0, complain_overflow_bitfield,
|
|---|
| 178 | bfd_elf_generic_reloc, "R_390_GOTPLTENT",FALSE, 0,MINUS_ONE, TRUE),
|
|---|
| 179 | HOWTO(R_390_PLTOFF16, 0, 1, 16, FALSE, 0, complain_overflow_bitfield,
|
|---|
| 180 | bfd_elf_generic_reloc, "R_390_PLTOFF16", FALSE, 0,0x0000ffff, FALSE),
|
|---|
| 181 | HOWTO(R_390_PLTOFF32, 0, 2, 32, FALSE, 0, complain_overflow_bitfield,
|
|---|
| 182 | bfd_elf_generic_reloc, "R_390_PLTOFF32", FALSE, 0,0xffffffff, FALSE),
|
|---|
| 183 | HOWTO(R_390_PLTOFF64, 0, 4, 64, FALSE, 0, complain_overflow_bitfield,
|
|---|
| 184 | bfd_elf_generic_reloc, "R_390_PLTOFF64", FALSE, 0,MINUS_ONE, FALSE),
|
|---|
| 185 | HOWTO(R_390_TLS_LOAD, 0, 0, 0, FALSE, 0, complain_overflow_dont,
|
|---|
| 186 | s390_tls_reloc, "R_390_TLS_LOAD", FALSE, 0, 0, FALSE),
|
|---|
| 187 | HOWTO(R_390_TLS_GDCALL, 0, 0, 0, FALSE, 0, complain_overflow_dont,
|
|---|
| 188 | s390_tls_reloc, "R_390_TLS_GDCALL", FALSE, 0, 0, FALSE),
|
|---|
| 189 | HOWTO(R_390_TLS_LDCALL, 0, 0, 0, FALSE, 0, complain_overflow_dont,
|
|---|
| 190 | s390_tls_reloc, "R_390_TLS_LDCALL", FALSE, 0, 0, FALSE),
|
|---|
| 191 | EMPTY_HOWTO (R_390_TLS_GD32), /* Empty entry for R_390_TLS_GD32. */
|
|---|
| 192 | HOWTO(R_390_TLS_GD64, 0, 4, 64, FALSE, 0, complain_overflow_bitfield,
|
|---|
| 193 | bfd_elf_generic_reloc, "R_390_TLS_GD64", FALSE, 0, MINUS_ONE, FALSE),
|
|---|
| 194 | HOWTO(R_390_TLS_GOTIE12, 0, 1, 12, FALSE, 0, complain_overflow_dont,
|
|---|
| 195 | bfd_elf_generic_reloc, "R_390_TLS_GOTIE12", FALSE, 0, 0x00000fff, FALSE),
|
|---|
| 196 | EMPTY_HOWTO (R_390_TLS_GOTIE32), /* Empty entry for R_390_TLS_GOTIE32. */
|
|---|
| 197 | HOWTO(R_390_TLS_GOTIE64, 0, 4, 64, FALSE, 0, complain_overflow_bitfield,
|
|---|
| 198 | bfd_elf_generic_reloc, "R_390_TLS_GOTIE64", FALSE, 0, MINUS_ONE, FALSE),
|
|---|
| 199 | EMPTY_HOWTO (R_390_TLS_LDM32), /* Empty entry for R_390_TLS_LDM32. */
|
|---|
| 200 | HOWTO(R_390_TLS_LDM64, 0, 4, 64, FALSE, 0, complain_overflow_bitfield,
|
|---|
| 201 | bfd_elf_generic_reloc, "R_390_TLS_LDM64", FALSE, 0, MINUS_ONE, FALSE),
|
|---|
| 202 | EMPTY_HOWTO (R_390_TLS_IE32), /* Empty entry for R_390_TLS_IE32. */
|
|---|
| 203 | HOWTO(R_390_TLS_IE64, 0, 4, 64, FALSE, 0, complain_overflow_bitfield,
|
|---|
| 204 | bfd_elf_generic_reloc, "R_390_TLS_IE64", FALSE, 0, MINUS_ONE, FALSE),
|
|---|
| 205 | HOWTO(R_390_TLS_IEENT, 1, 2, 32, TRUE, 0, complain_overflow_bitfield,
|
|---|
| 206 | bfd_elf_generic_reloc, "R_390_TLS_IEENT", FALSE, 0, MINUS_ONE, TRUE),
|
|---|
| 207 | EMPTY_HOWTO (R_390_TLS_LE32), /* Empty entry for R_390_TLS_LE32. */
|
|---|
| 208 | HOWTO(R_390_TLS_LE64, 0, 2, 32, FALSE, 0, complain_overflow_bitfield,
|
|---|
| 209 | bfd_elf_generic_reloc, "R_390_TLS_LE64", FALSE, 0, MINUS_ONE, FALSE),
|
|---|
| 210 | EMPTY_HOWTO (R_390_TLS_LDO32), /* Empty entry for R_390_TLS_LDO32. */
|
|---|
| 211 | HOWTO(R_390_TLS_LDO64, 0, 4, 64, FALSE, 0, complain_overflow_bitfield,
|
|---|
| 212 | bfd_elf_generic_reloc, "R_390_TLS_LDO64", FALSE, 0, MINUS_ONE, FALSE),
|
|---|
| 213 | HOWTO(R_390_TLS_DTPMOD, 0, 4, 64, FALSE, 0, complain_overflow_bitfield,
|
|---|
| 214 | bfd_elf_generic_reloc, "R_390_TLS_DTPMOD", FALSE, 0, MINUS_ONE, FALSE),
|
|---|
| 215 | HOWTO(R_390_TLS_DTPOFF, 0, 4, 64, FALSE, 0, complain_overflow_bitfield,
|
|---|
| 216 | bfd_elf_generic_reloc, "R_390_TLS_DTPOFF", FALSE, 0, MINUS_ONE, FALSE),
|
|---|
| 217 | HOWTO(R_390_TLS_TPOFF, 0, 4, 64, FALSE, 0, complain_overflow_bitfield,
|
|---|
| 218 | bfd_elf_generic_reloc, "R_390_TLS_TPOFF", FALSE, 0, MINUS_ONE, FALSE),
|
|---|
| 219 | };
|
|---|
| 220 |
|
|---|
| 221 | /* GNU extension to record C++ vtable hierarchy. */
|
|---|
| 222 | static reloc_howto_type elf64_s390_vtinherit_howto =
|
|---|
| 223 | HOWTO (R_390_GNU_VTINHERIT, 0,4,0,FALSE,0,complain_overflow_dont, NULL, "R_390_GNU_VTINHERIT", FALSE,0, 0, FALSE);
|
|---|
| 224 | static reloc_howto_type elf64_s390_vtentry_howto =
|
|---|
| 225 | HOWTO (R_390_GNU_VTENTRY, 0,4,0,FALSE,0,complain_overflow_dont, _bfd_elf_rel_vtable_reloc_fn,"R_390_GNU_VTENTRY", FALSE,0,0, FALSE);
|
|---|
| 226 |
|
|---|
| 227 | static reloc_howto_type *
|
|---|
| 228 | elf_s390_reloc_type_lookup (abfd, code)
|
|---|
| 229 | bfd *abfd ATTRIBUTE_UNUSED;
|
|---|
| 230 | bfd_reloc_code_real_type code;
|
|---|
| 231 | {
|
|---|
| 232 | switch (code)
|
|---|
| 233 | {
|
|---|
| 234 | case BFD_RELOC_NONE:
|
|---|
| 235 | return &elf_howto_table[(int) R_390_NONE];
|
|---|
| 236 | case BFD_RELOC_8:
|
|---|
| 237 | return &elf_howto_table[(int) R_390_8];
|
|---|
| 238 | case BFD_RELOC_390_12:
|
|---|
| 239 | return &elf_howto_table[(int) R_390_12];
|
|---|
| 240 | case BFD_RELOC_16:
|
|---|
| 241 | return &elf_howto_table[(int) R_390_16];
|
|---|
| 242 | case BFD_RELOC_32:
|
|---|
| 243 | return &elf_howto_table[(int) R_390_32];
|
|---|
| 244 | case BFD_RELOC_CTOR:
|
|---|
| 245 | return &elf_howto_table[(int) R_390_32];
|
|---|
| 246 | case BFD_RELOC_32_PCREL:
|
|---|
| 247 | return &elf_howto_table[(int) R_390_PC32];
|
|---|
| 248 | case BFD_RELOC_390_GOT12:
|
|---|
| 249 | return &elf_howto_table[(int) R_390_GOT12];
|
|---|
| 250 | case BFD_RELOC_32_GOT_PCREL:
|
|---|
| 251 | return &elf_howto_table[(int) R_390_GOT32];
|
|---|
| 252 | case BFD_RELOC_390_PLT32:
|
|---|
| 253 | return &elf_howto_table[(int) R_390_PLT32];
|
|---|
| 254 | case BFD_RELOC_390_COPY:
|
|---|
| 255 | return &elf_howto_table[(int) R_390_COPY];
|
|---|
| 256 | case BFD_RELOC_390_GLOB_DAT:
|
|---|
| 257 | return &elf_howto_table[(int) R_390_GLOB_DAT];
|
|---|
| 258 | case BFD_RELOC_390_JMP_SLOT:
|
|---|
| 259 | return &elf_howto_table[(int) R_390_JMP_SLOT];
|
|---|
| 260 | case BFD_RELOC_390_RELATIVE:
|
|---|
| 261 | return &elf_howto_table[(int) R_390_RELATIVE];
|
|---|
| 262 | case BFD_RELOC_32_GOTOFF:
|
|---|
| 263 | return &elf_howto_table[(int) R_390_GOTOFF32];
|
|---|
| 264 | case BFD_RELOC_390_GOTPC:
|
|---|
| 265 | return &elf_howto_table[(int) R_390_GOTPC];
|
|---|
| 266 | case BFD_RELOC_390_GOT16:
|
|---|
| 267 | return &elf_howto_table[(int) R_390_GOT16];
|
|---|
| 268 | case BFD_RELOC_16_PCREL:
|
|---|
| 269 | return &elf_howto_table[(int) R_390_PC16];
|
|---|
| 270 | case BFD_RELOC_390_PC16DBL:
|
|---|
| 271 | return &elf_howto_table[(int) R_390_PC16DBL];
|
|---|
| 272 | case BFD_RELOC_390_PLT16DBL:
|
|---|
| 273 | return &elf_howto_table[(int) R_390_PLT16DBL];
|
|---|
| 274 | case BFD_RELOC_390_PC32DBL:
|
|---|
| 275 | return &elf_howto_table[(int) R_390_PC32DBL];
|
|---|
| 276 | case BFD_RELOC_390_PLT32DBL:
|
|---|
| 277 | return &elf_howto_table[(int) R_390_PLT32DBL];
|
|---|
| 278 | case BFD_RELOC_390_GOTPCDBL:
|
|---|
| 279 | return &elf_howto_table[(int) R_390_GOTPCDBL];
|
|---|
| 280 | case BFD_RELOC_64:
|
|---|
| 281 | return &elf_howto_table[(int) R_390_64];
|
|---|
| 282 | case BFD_RELOC_64_PCREL:
|
|---|
| 283 | return &elf_howto_table[(int) R_390_PC64];
|
|---|
| 284 | case BFD_RELOC_390_GOT64:
|
|---|
| 285 | return &elf_howto_table[(int) R_390_GOT64];
|
|---|
| 286 | case BFD_RELOC_390_PLT64:
|
|---|
| 287 | return &elf_howto_table[(int) R_390_PLT64];
|
|---|
| 288 | case BFD_RELOC_390_GOTENT:
|
|---|
| 289 | return &elf_howto_table[(int) R_390_GOTENT];
|
|---|
| 290 | case BFD_RELOC_16_GOTOFF:
|
|---|
| 291 | return &elf_howto_table[(int) R_390_GOTOFF16];
|
|---|
| 292 | case BFD_RELOC_390_GOTOFF64:
|
|---|
| 293 | return &elf_howto_table[(int) R_390_GOTOFF64];
|
|---|
| 294 | case BFD_RELOC_390_GOTPLT12:
|
|---|
| 295 | return &elf_howto_table[(int) R_390_GOTPLT12];
|
|---|
| 296 | case BFD_RELOC_390_GOTPLT16:
|
|---|
| 297 | return &elf_howto_table[(int) R_390_GOTPLT16];
|
|---|
| 298 | case BFD_RELOC_390_GOTPLT32:
|
|---|
| 299 | return &elf_howto_table[(int) R_390_GOTPLT32];
|
|---|
| 300 | case BFD_RELOC_390_GOTPLT64:
|
|---|
| 301 | return &elf_howto_table[(int) R_390_GOTPLT64];
|
|---|
| 302 | case BFD_RELOC_390_GOTPLTENT:
|
|---|
| 303 | return &elf_howto_table[(int) R_390_GOTPLTENT];
|
|---|
| 304 | case BFD_RELOC_390_PLTOFF16:
|
|---|
| 305 | return &elf_howto_table[(int) R_390_PLTOFF16];
|
|---|
| 306 | case BFD_RELOC_390_PLTOFF32:
|
|---|
| 307 | return &elf_howto_table[(int) R_390_PLTOFF32];
|
|---|
| 308 | case BFD_RELOC_390_PLTOFF64:
|
|---|
| 309 | return &elf_howto_table[(int) R_390_PLTOFF64];
|
|---|
| 310 | case BFD_RELOC_390_TLS_LOAD:
|
|---|
| 311 | return &elf_howto_table[(int) R_390_TLS_LOAD];
|
|---|
| 312 | case BFD_RELOC_390_TLS_GDCALL:
|
|---|
| 313 | return &elf_howto_table[(int) R_390_TLS_GDCALL];
|
|---|
| 314 | case BFD_RELOC_390_TLS_LDCALL:
|
|---|
| 315 | return &elf_howto_table[(int) R_390_TLS_LDCALL];
|
|---|
| 316 | case BFD_RELOC_390_TLS_GD64:
|
|---|
| 317 | return &elf_howto_table[(int) R_390_TLS_GD64];
|
|---|
| 318 | case BFD_RELOC_390_TLS_GOTIE12:
|
|---|
| 319 | return &elf_howto_table[(int) R_390_TLS_GOTIE12];
|
|---|
| 320 | case BFD_RELOC_390_TLS_GOTIE64:
|
|---|
| 321 | return &elf_howto_table[(int) R_390_TLS_GOTIE64];
|
|---|
| 322 | case BFD_RELOC_390_TLS_LDM64:
|
|---|
| 323 | return &elf_howto_table[(int) R_390_TLS_LDM64];
|
|---|
| 324 | case BFD_RELOC_390_TLS_IE64:
|
|---|
| 325 | return &elf_howto_table[(int) R_390_TLS_IE64];
|
|---|
| 326 | case BFD_RELOC_390_TLS_IEENT:
|
|---|
| 327 | return &elf_howto_table[(int) R_390_TLS_IEENT];
|
|---|
| 328 | case BFD_RELOC_390_TLS_LE64:
|
|---|
| 329 | return &elf_howto_table[(int) R_390_TLS_LE64];
|
|---|
| 330 | case BFD_RELOC_390_TLS_LDO64:
|
|---|
| 331 | return &elf_howto_table[(int) R_390_TLS_LDO64];
|
|---|
| 332 | case BFD_RELOC_390_TLS_DTPMOD:
|
|---|
| 333 | return &elf_howto_table[(int) R_390_TLS_DTPMOD];
|
|---|
| 334 | case BFD_RELOC_390_TLS_DTPOFF:
|
|---|
| 335 | return &elf_howto_table[(int) R_390_TLS_DTPOFF];
|
|---|
| 336 | case BFD_RELOC_390_TLS_TPOFF:
|
|---|
| 337 | return &elf_howto_table[(int) R_390_TLS_TPOFF];
|
|---|
| 338 | case BFD_RELOC_VTABLE_INHERIT:
|
|---|
| 339 | return &elf64_s390_vtinherit_howto;
|
|---|
| 340 | case BFD_RELOC_VTABLE_ENTRY:
|
|---|
| 341 | return &elf64_s390_vtentry_howto;
|
|---|
| 342 | default:
|
|---|
| 343 | break;
|
|---|
| 344 | }
|
|---|
| 345 | return 0;
|
|---|
| 346 | }
|
|---|
| 347 |
|
|---|
| 348 | /* We need to use ELF64_R_TYPE so we have our own copy of this function,
|
|---|
| 349 | and elf64-s390.c has its own copy. */
|
|---|
| 350 |
|
|---|
| 351 | static void
|
|---|
| 352 | elf_s390_info_to_howto (abfd, cache_ptr, dst)
|
|---|
| 353 | bfd *abfd ATTRIBUTE_UNUSED;
|
|---|
| 354 | arelent *cache_ptr;
|
|---|
| 355 | Elf_Internal_Rela *dst;
|
|---|
| 356 | {
|
|---|
| 357 | switch (ELF64_R_TYPE(dst->r_info))
|
|---|
| 358 | {
|
|---|
| 359 | case R_390_GNU_VTINHERIT:
|
|---|
| 360 | cache_ptr->howto = &elf64_s390_vtinherit_howto;
|
|---|
| 361 | break;
|
|---|
| 362 |
|
|---|
| 363 | case R_390_GNU_VTENTRY:
|
|---|
| 364 | cache_ptr->howto = &elf64_s390_vtentry_howto;
|
|---|
| 365 | break;
|
|---|
| 366 |
|
|---|
| 367 | default:
|
|---|
| 368 | BFD_ASSERT (ELF64_R_TYPE(dst->r_info) < (unsigned int) R_390_max);
|
|---|
| 369 | cache_ptr->howto = &elf_howto_table[ELF64_R_TYPE(dst->r_info)];
|
|---|
| 370 | }
|
|---|
| 371 | }
|
|---|
| 372 |
|
|---|
| 373 | /* A relocation function which doesn't do anything. */
|
|---|
| 374 | static bfd_reloc_status_type
|
|---|
| 375 | s390_tls_reloc (abfd, reloc_entry, symbol, data, input_section,
|
|---|
| 376 | output_bfd, error_message)
|
|---|
| 377 | bfd *abfd ATTRIBUTE_UNUSED;
|
|---|
| 378 | arelent *reloc_entry;
|
|---|
| 379 | asymbol *symbol ATTRIBUTE_UNUSED;
|
|---|
| 380 | PTR data ATTRIBUTE_UNUSED;
|
|---|
| 381 | asection *input_section;
|
|---|
| 382 | bfd *output_bfd;
|
|---|
| 383 | char **error_message ATTRIBUTE_UNUSED;
|
|---|
| 384 | {
|
|---|
| 385 | if (output_bfd)
|
|---|
| 386 | reloc_entry->address += input_section->output_offset;
|
|---|
| 387 | return bfd_reloc_ok;
|
|---|
| 388 | }
|
|---|
| 389 |
|
|---|
| 390 | static bfd_boolean
|
|---|
| 391 | elf_s390_is_local_label_name (abfd, name)
|
|---|
| 392 | bfd *abfd;
|
|---|
| 393 | const char *name;
|
|---|
| 394 | {
|
|---|
| 395 | if (name[0] == '.' && (name[1] == 'X' || name[1] == 'L'))
|
|---|
| 396 | return TRUE;
|
|---|
| 397 |
|
|---|
| 398 | return _bfd_elf_is_local_label_name (abfd, name);
|
|---|
| 399 | }
|
|---|
| 400 |
|
|---|
| 401 | /* Functions for the 390 ELF linker. */
|
|---|
| 402 |
|
|---|
| 403 | /* The name of the dynamic interpreter. This is put in the .interp
|
|---|
| 404 | section. */
|
|---|
| 405 |
|
|---|
| 406 | #define ELF_DYNAMIC_INTERPRETER "/usr/lib/ld.so.1"
|
|---|
| 407 |
|
|---|
| 408 | /* If ELIMINATE_COPY_RELOCS is non-zero, the linker will try to avoid
|
|---|
| 409 | copying dynamic variables from a shared lib into an app's dynbss
|
|---|
| 410 | section, and instead use a dynamic relocation to point into the
|
|---|
| 411 | shared lib. */
|
|---|
| 412 | #define ELIMINATE_COPY_RELOCS 1
|
|---|
| 413 |
|
|---|
| 414 | /* The size in bytes of the first entry in the procedure linkage table. */
|
|---|
| 415 | #define PLT_FIRST_ENTRY_SIZE 32
|
|---|
| 416 | /* The size in bytes of an entry in the procedure linkage table. */
|
|---|
| 417 | #define PLT_ENTRY_SIZE 32
|
|---|
| 418 |
|
|---|
| 419 | #define GOT_ENTRY_SIZE 8
|
|---|
| 420 |
|
|---|
| 421 | /* The first three entries in a procedure linkage table are reserved,
|
|---|
| 422 | and the initial contents are unimportant (we zero them out).
|
|---|
| 423 | Subsequent entries look like this. See the SVR4 ABI 386
|
|---|
| 424 | supplement to see how this works. */
|
|---|
| 425 |
|
|---|
| 426 | /* For the s390, simple addr offset can only be 0 - 4096.
|
|---|
| 427 | To use the full 16777216 TB address space, several instructions
|
|---|
| 428 | are needed to load an address in a register and execute
|
|---|
| 429 | a branch( or just saving the address)
|
|---|
| 430 |
|
|---|
| 431 | Furthermore, only r 0 and 1 are free to use!!! */
|
|---|
| 432 |
|
|---|
| 433 | /* The first 3 words in the GOT are then reserved.
|
|---|
| 434 | Word 0 is the address of the dynamic table.
|
|---|
| 435 | Word 1 is a pointer to a structure describing the object
|
|---|
| 436 | Word 2 is used to point to the loader entry address.
|
|---|
| 437 |
|
|---|
| 438 | The code for PLT entries looks like this:
|
|---|
| 439 |
|
|---|
| 440 | The GOT holds the address in the PLT to be executed.
|
|---|
| 441 | The loader then gets:
|
|---|
| 442 | 24(15) = Pointer to the structure describing the object.
|
|---|
| 443 | 28(15) = Offset in symbol table
|
|---|
| 444 | The loader must then find the module where the function is
|
|---|
| 445 | and insert the address in the GOT.
|
|---|
| 446 |
|
|---|
| 447 | PLT1: LARL 1,<fn>@GOTENT # 6 bytes Load address of GOT entry in r1
|
|---|
| 448 | LG 1,0(1) # 6 bytes Load address from GOT in r1
|
|---|
| 449 | BCR 15,1 # 2 bytes Jump to address
|
|---|
| 450 | RET1: BASR 1,0 # 2 bytes Return from GOT 1st time
|
|---|
| 451 | LGF 1,12(1) # 6 bytes Load offset in symbl table in r1
|
|---|
| 452 | BRCL 15,-x # 6 bytes Jump to start of PLT
|
|---|
| 453 | .long ? # 4 bytes offset into symbol table
|
|---|
| 454 |
|
|---|
| 455 | Total = 32 bytes per PLT entry
|
|---|
| 456 | Fixup at offset 2: relative address to GOT entry
|
|---|
| 457 | Fixup at offset 22: relative branch to PLT0
|
|---|
| 458 | Fixup at offset 28: 32 bit offset into symbol table
|
|---|
| 459 |
|
|---|
| 460 | A 32 bit offset into the symbol table is enough. It allows for symbol
|
|---|
| 461 | tables up to a size of 2 gigabyte. A single dynamic object (the main
|
|---|
| 462 | program, any shared library) is limited to 4GB in size and I want to see
|
|---|
| 463 | the program that manages to have a symbol table of more than 2 GB with a
|
|---|
| 464 | total size of at max 4 GB. */
|
|---|
| 465 |
|
|---|
| 466 | #define PLT_ENTRY_WORD0 (bfd_vma) 0xc0100000
|
|---|
| 467 | #define PLT_ENTRY_WORD1 (bfd_vma) 0x0000e310
|
|---|
| 468 | #define PLT_ENTRY_WORD2 (bfd_vma) 0x10000004
|
|---|
| 469 | #define PLT_ENTRY_WORD3 (bfd_vma) 0x07f10d10
|
|---|
| 470 | #define PLT_ENTRY_WORD4 (bfd_vma) 0xe310100c
|
|---|
| 471 | #define PLT_ENTRY_WORD5 (bfd_vma) 0x0014c0f4
|
|---|
| 472 | #define PLT_ENTRY_WORD6 (bfd_vma) 0x00000000
|
|---|
| 473 | #define PLT_ENTRY_WORD7 (bfd_vma) 0x00000000
|
|---|
| 474 |
|
|---|
| 475 | /* The first PLT entry pushes the offset into the symbol table
|
|---|
| 476 | from R1 onto the stack at 8(15) and the loader object info
|
|---|
| 477 | at 12(15), loads the loader address in R1 and jumps to it. */
|
|---|
| 478 |
|
|---|
| 479 | /* The first entry in the PLT:
|
|---|
| 480 |
|
|---|
| 481 | PLT0:
|
|---|
| 482 | STG 1,56(15) # r1 contains the offset into the symbol table
|
|---|
| 483 | LARL 1,_GLOBAL_OFFSET_TABLE # load address of global offset table
|
|---|
| 484 | MVC 48(8,15),8(1) # move loader ino (object struct address) to stack
|
|---|
| 485 | LG 1,16(1) # get entry address of loader
|
|---|
| 486 | BCR 15,1 # jump to loader
|
|---|
| 487 |
|
|---|
| 488 | Fixup at offset 8: relative address to start of GOT. */
|
|---|
| 489 |
|
|---|
| 490 | #define PLT_FIRST_ENTRY_WORD0 (bfd_vma) 0xe310f038
|
|---|
| 491 | #define PLT_FIRST_ENTRY_WORD1 (bfd_vma) 0x0024c010
|
|---|
| 492 | #define PLT_FIRST_ENTRY_WORD2 (bfd_vma) 0x00000000
|
|---|
| 493 | #define PLT_FIRST_ENTRY_WORD3 (bfd_vma) 0xd207f030
|
|---|
| 494 | #define PLT_FIRST_ENTRY_WORD4 (bfd_vma) 0x1008e310
|
|---|
| 495 | #define PLT_FIRST_ENTRY_WORD5 (bfd_vma) 0x10100004
|
|---|
| 496 | #define PLT_FIRST_ENTRY_WORD6 (bfd_vma) 0x07f10700
|
|---|
| 497 | #define PLT_FIRST_ENTRY_WORD7 (bfd_vma) 0x07000700
|
|---|
| 498 |
|
|---|
| 499 | /* The s390 linker needs to keep track of the number of relocs that it
|
|---|
| 500 | decides to copy as dynamic relocs in check_relocs for each symbol.
|
|---|
| 501 | This is so that it can later discard them if they are found to be
|
|---|
| 502 | unnecessary. We store the information in a field extending the
|
|---|
| 503 | regular ELF linker hash table. */
|
|---|
| 504 |
|
|---|
| 505 | struct elf_s390_dyn_relocs
|
|---|
| 506 | {
|
|---|
| 507 | struct elf_s390_dyn_relocs *next;
|
|---|
| 508 |
|
|---|
| 509 | /* The input section of the reloc. */
|
|---|
| 510 | asection *sec;
|
|---|
| 511 |
|
|---|
| 512 | /* Total number of relocs copied for the input section. */
|
|---|
| 513 | bfd_size_type count;
|
|---|
| 514 |
|
|---|
| 515 | /* Number of pc-relative relocs copied for the input section. */
|
|---|
| 516 | bfd_size_type pc_count;
|
|---|
| 517 | };
|
|---|
| 518 |
|
|---|
| 519 | /* s390 ELF linker hash entry. */
|
|---|
| 520 |
|
|---|
| 521 | struct elf_s390_link_hash_entry
|
|---|
| 522 | {
|
|---|
| 523 | struct elf_link_hash_entry elf;
|
|---|
| 524 |
|
|---|
| 525 | /* Track dynamic relocs copied for this symbol. */
|
|---|
| 526 | struct elf_s390_dyn_relocs *dyn_relocs;
|
|---|
| 527 |
|
|---|
| 528 | /* Number of GOTPLT references for a function. */
|
|---|
| 529 | bfd_signed_vma gotplt_refcount;
|
|---|
| 530 |
|
|---|
| 531 | #define GOT_UNKNOWN 0
|
|---|
| 532 | #define GOT_NORMAL 1
|
|---|
| 533 | #define GOT_TLS_GD 2
|
|---|
| 534 | #define GOT_TLS_IE 3
|
|---|
| 535 | #define GOT_TLS_IE_NLT 3
|
|---|
| 536 | unsigned char tls_type;
|
|---|
| 537 | };
|
|---|
| 538 |
|
|---|
| 539 | #define elf_s390_hash_entry(ent) \
|
|---|
| 540 | ((struct elf_s390_link_hash_entry *)(ent))
|
|---|
| 541 |
|
|---|
| 542 | struct elf_s390_obj_tdata
|
|---|
| 543 | {
|
|---|
| 544 | struct elf_obj_tdata root;
|
|---|
| 545 |
|
|---|
| 546 | /* tls_type for each local got entry. */
|
|---|
| 547 | char *local_got_tls_type;
|
|---|
| 548 | };
|
|---|
| 549 |
|
|---|
| 550 | #define elf_s390_tdata(abfd) \
|
|---|
| 551 | ((struct elf_s390_obj_tdata *) (abfd)->tdata.any)
|
|---|
| 552 |
|
|---|
| 553 | #define elf_s390_local_got_tls_type(abfd) \
|
|---|
| 554 | (elf_s390_tdata (abfd)->local_got_tls_type)
|
|---|
| 555 |
|
|---|
| 556 | static bfd_boolean
|
|---|
| 557 | elf_s390_mkobject (abfd)
|
|---|
| 558 | bfd *abfd;
|
|---|
| 559 | {
|
|---|
| 560 | bfd_size_type amt = sizeof (struct elf_s390_obj_tdata);
|
|---|
| 561 | abfd->tdata.any = bfd_zalloc (abfd, amt);
|
|---|
| 562 | if (abfd->tdata.any == NULL)
|
|---|
| 563 | return FALSE;
|
|---|
| 564 | return TRUE;
|
|---|
| 565 | }
|
|---|
| 566 |
|
|---|
| 567 | static bfd_boolean
|
|---|
| 568 | elf_s390_object_p (abfd)
|
|---|
| 569 | bfd *abfd;
|
|---|
| 570 | {
|
|---|
| 571 | /* Allocate our special target data. */
|
|---|
| 572 | struct elf_s390_obj_tdata *new_tdata;
|
|---|
| 573 | bfd_size_type amt = sizeof (struct elf_s390_obj_tdata);
|
|---|
| 574 | new_tdata = bfd_zalloc (abfd, amt);
|
|---|
| 575 | if (new_tdata == NULL)
|
|---|
| 576 | return FALSE;
|
|---|
| 577 | new_tdata->root = *abfd->tdata.elf_obj_data;
|
|---|
| 578 | abfd->tdata.any = new_tdata;
|
|---|
| 579 | /* Set the right machine number for an s390 elf32 file. */
|
|---|
| 580 | return bfd_default_set_arch_mach (abfd, bfd_arch_s390, bfd_mach_s390_64);
|
|---|
| 581 | }
|
|---|
| 582 |
|
|---|
| 583 | /* s390 ELF linker hash table. */
|
|---|
| 584 |
|
|---|
| 585 | struct elf_s390_link_hash_table
|
|---|
| 586 | {
|
|---|
| 587 | struct elf_link_hash_table elf;
|
|---|
| 588 |
|
|---|
| 589 | /* Short-cuts to get to dynamic linker sections. */
|
|---|
| 590 | asection *sgot;
|
|---|
| 591 | asection *sgotplt;
|
|---|
| 592 | asection *srelgot;
|
|---|
| 593 | asection *splt;
|
|---|
| 594 | asection *srelplt;
|
|---|
| 595 | asection *sdynbss;
|
|---|
| 596 | asection *srelbss;
|
|---|
| 597 |
|
|---|
| 598 | union {
|
|---|
| 599 | bfd_signed_vma refcount;
|
|---|
| 600 | bfd_vma offset;
|
|---|
| 601 | } tls_ldm_got;
|
|---|
| 602 |
|
|---|
| 603 | /* Small local sym to section mapping cache. */
|
|---|
| 604 | struct sym_sec_cache sym_sec;
|
|---|
| 605 | };
|
|---|
| 606 |
|
|---|
| 607 | /* Get the s390 ELF linker hash table from a link_info structure. */
|
|---|
| 608 |
|
|---|
| 609 | #define elf_s390_hash_table(p) \
|
|---|
| 610 | ((struct elf_s390_link_hash_table *) ((p)->hash))
|
|---|
| 611 |
|
|---|
| 612 | /* Create an entry in an s390 ELF linker hash table. */
|
|---|
| 613 |
|
|---|
| 614 | static struct bfd_hash_entry *
|
|---|
| 615 | link_hash_newfunc (entry, table, string)
|
|---|
| 616 | struct bfd_hash_entry *entry;
|
|---|
| 617 | struct bfd_hash_table *table;
|
|---|
| 618 | const char *string;
|
|---|
| 619 | {
|
|---|
| 620 | /* Allocate the structure if it has not already been allocated by a
|
|---|
| 621 | subclass. */
|
|---|
| 622 | if (entry == NULL)
|
|---|
| 623 | {
|
|---|
| 624 | entry = bfd_hash_allocate (table,
|
|---|
| 625 | sizeof (struct elf_s390_link_hash_entry));
|
|---|
| 626 | if (entry == NULL)
|
|---|
| 627 | return entry;
|
|---|
| 628 | }
|
|---|
| 629 |
|
|---|
| 630 | /* Call the allocation method of the superclass. */
|
|---|
| 631 | entry = _bfd_elf_link_hash_newfunc (entry, table, string);
|
|---|
| 632 | if (entry != NULL)
|
|---|
| 633 | {
|
|---|
| 634 | struct elf_s390_link_hash_entry *eh;
|
|---|
| 635 |
|
|---|
| 636 | eh = (struct elf_s390_link_hash_entry *) entry;
|
|---|
| 637 | eh->dyn_relocs = NULL;
|
|---|
| 638 | eh->gotplt_refcount = 0;
|
|---|
| 639 | eh->tls_type = GOT_UNKNOWN;
|
|---|
| 640 | }
|
|---|
| 641 |
|
|---|
| 642 | return entry;
|
|---|
| 643 | }
|
|---|
| 644 |
|
|---|
| 645 | /* Create an s390 ELF linker hash table. */
|
|---|
| 646 |
|
|---|
| 647 | static struct bfd_link_hash_table *
|
|---|
| 648 | elf_s390_link_hash_table_create (abfd)
|
|---|
| 649 | bfd *abfd;
|
|---|
| 650 | {
|
|---|
| 651 | struct elf_s390_link_hash_table *ret;
|
|---|
| 652 | bfd_size_type amt = sizeof (struct elf_s390_link_hash_table);
|
|---|
| 653 |
|
|---|
| 654 | ret = (struct elf_s390_link_hash_table *) bfd_malloc (amt);
|
|---|
| 655 | if (ret == NULL)
|
|---|
| 656 | return NULL;
|
|---|
| 657 |
|
|---|
| 658 | if (! _bfd_elf_link_hash_table_init (&ret->elf, abfd, link_hash_newfunc))
|
|---|
| 659 | {
|
|---|
| 660 | free (ret);
|
|---|
| 661 | return NULL;
|
|---|
| 662 | }
|
|---|
| 663 |
|
|---|
| 664 | ret->sgot = NULL;
|
|---|
| 665 | ret->sgotplt = NULL;
|
|---|
| 666 | ret->srelgot = NULL;
|
|---|
| 667 | ret->splt = NULL;
|
|---|
| 668 | ret->srelplt = NULL;
|
|---|
| 669 | ret->sdynbss = NULL;
|
|---|
| 670 | ret->srelbss = NULL;
|
|---|
| 671 | ret->tls_ldm_got.refcount = 0;
|
|---|
| 672 | ret->sym_sec.abfd = NULL;
|
|---|
| 673 |
|
|---|
| 674 | return &ret->elf.root;
|
|---|
| 675 | }
|
|---|
| 676 |
|
|---|
| 677 | /* Create .got, .gotplt, and .rela.got sections in DYNOBJ, and set up
|
|---|
| 678 | shortcuts to them in our hash table. */
|
|---|
| 679 |
|
|---|
| 680 | static bfd_boolean
|
|---|
| 681 | create_got_section (dynobj, info)
|
|---|
| 682 | bfd *dynobj;
|
|---|
| 683 | struct bfd_link_info *info;
|
|---|
| 684 | {
|
|---|
| 685 | struct elf_s390_link_hash_table *htab;
|
|---|
| 686 |
|
|---|
| 687 | if (! _bfd_elf_create_got_section (dynobj, info))
|
|---|
| 688 | return FALSE;
|
|---|
| 689 |
|
|---|
| 690 | htab = elf_s390_hash_table (info);
|
|---|
| 691 | htab->sgot = bfd_get_section_by_name (dynobj, ".got");
|
|---|
| 692 | htab->sgotplt = bfd_get_section_by_name (dynobj, ".got.plt");
|
|---|
| 693 | if (!htab->sgot || !htab->sgotplt)
|
|---|
| 694 | abort ();
|
|---|
| 695 |
|
|---|
| 696 | htab->srelgot = bfd_make_section (dynobj, ".rela.got");
|
|---|
| 697 | if (htab->srelgot == NULL
|
|---|
| 698 | || ! bfd_set_section_flags (dynobj, htab->srelgot,
|
|---|
| 699 | (SEC_ALLOC | SEC_LOAD | SEC_HAS_CONTENTS
|
|---|
| 700 | | SEC_IN_MEMORY | SEC_LINKER_CREATED
|
|---|
| 701 | | SEC_READONLY))
|
|---|
| 702 | || ! bfd_set_section_alignment (dynobj, htab->srelgot, 3))
|
|---|
| 703 | return FALSE;
|
|---|
| 704 | return TRUE;
|
|---|
| 705 | }
|
|---|
| 706 |
|
|---|
| 707 | /* Create .plt, .rela.plt, .got, .got.plt, .rela.got, .dynbss, and
|
|---|
| 708 | .rela.bss sections in DYNOBJ, and set up shortcuts to them in our
|
|---|
| 709 | hash table. */
|
|---|
| 710 |
|
|---|
| 711 | static bfd_boolean
|
|---|
| 712 | elf_s390_create_dynamic_sections (dynobj, info)
|
|---|
| 713 | bfd *dynobj;
|
|---|
| 714 | struct bfd_link_info *info;
|
|---|
| 715 | {
|
|---|
| 716 | struct elf_s390_link_hash_table *htab;
|
|---|
| 717 |
|
|---|
| 718 | htab = elf_s390_hash_table (info);
|
|---|
| 719 | if (!htab->sgot && !create_got_section (dynobj, info))
|
|---|
| 720 | return FALSE;
|
|---|
| 721 |
|
|---|
| 722 | if (!_bfd_elf_create_dynamic_sections (dynobj, info))
|
|---|
| 723 | return FALSE;
|
|---|
| 724 |
|
|---|
| 725 | htab->splt = bfd_get_section_by_name (dynobj, ".plt");
|
|---|
| 726 | htab->srelplt = bfd_get_section_by_name (dynobj, ".rela.plt");
|
|---|
| 727 | htab->sdynbss = bfd_get_section_by_name (dynobj, ".dynbss");
|
|---|
| 728 | if (!info->shared)
|
|---|
| 729 | htab->srelbss = bfd_get_section_by_name (dynobj, ".rela.bss");
|
|---|
| 730 |
|
|---|
| 731 | if (!htab->splt || !htab->srelplt || !htab->sdynbss
|
|---|
| 732 | || (!info->shared && !htab->srelbss))
|
|---|
| 733 | abort ();
|
|---|
| 734 |
|
|---|
| 735 | return TRUE;
|
|---|
| 736 | }
|
|---|
| 737 |
|
|---|
| 738 | /* Copy the extra info we tack onto an elf_link_hash_entry. */
|
|---|
| 739 |
|
|---|
| 740 | static void
|
|---|
| 741 | elf_s390_copy_indirect_symbol (bed, dir, ind)
|
|---|
| 742 | struct elf_backend_data *bed;
|
|---|
| 743 | struct elf_link_hash_entry *dir, *ind;
|
|---|
| 744 | {
|
|---|
| 745 | struct elf_s390_link_hash_entry *edir, *eind;
|
|---|
| 746 |
|
|---|
| 747 | edir = (struct elf_s390_link_hash_entry *) dir;
|
|---|
| 748 | eind = (struct elf_s390_link_hash_entry *) ind;
|
|---|
| 749 |
|
|---|
| 750 | if (eind->dyn_relocs != NULL)
|
|---|
| 751 | {
|
|---|
| 752 | if (edir->dyn_relocs != NULL)
|
|---|
| 753 | {
|
|---|
| 754 | struct elf_s390_dyn_relocs **pp;
|
|---|
| 755 | struct elf_s390_dyn_relocs *p;
|
|---|
| 756 |
|
|---|
| 757 | if (ind->root.type == bfd_link_hash_indirect)
|
|---|
| 758 | abort ();
|
|---|
| 759 |
|
|---|
| 760 | /* Add reloc counts against the weak sym to the strong sym
|
|---|
| 761 | list. Merge any entries against the same section. */
|
|---|
| 762 | for (pp = &eind->dyn_relocs; (p = *pp) != NULL; )
|
|---|
| 763 | {
|
|---|
| 764 | struct elf_s390_dyn_relocs *q;
|
|---|
| 765 |
|
|---|
| 766 | for (q = edir->dyn_relocs; q != NULL; q = q->next)
|
|---|
| 767 | if (q->sec == p->sec)
|
|---|
| 768 | {
|
|---|
| 769 | q->pc_count += p->pc_count;
|
|---|
| 770 | q->count += p->count;
|
|---|
| 771 | *pp = p->next;
|
|---|
| 772 | break;
|
|---|
| 773 | }
|
|---|
| 774 | if (q == NULL)
|
|---|
| 775 | pp = &p->next;
|
|---|
| 776 | }
|
|---|
| 777 | *pp = edir->dyn_relocs;
|
|---|
| 778 | }
|
|---|
| 779 |
|
|---|
| 780 | edir->dyn_relocs = eind->dyn_relocs;
|
|---|
| 781 | eind->dyn_relocs = NULL;
|
|---|
| 782 | }
|
|---|
| 783 |
|
|---|
| 784 | if (ind->root.type == bfd_link_hash_indirect
|
|---|
| 785 | && dir->got.refcount <= 0)
|
|---|
| 786 | {
|
|---|
| 787 | edir->tls_type = eind->tls_type;
|
|---|
| 788 | eind->tls_type = GOT_UNKNOWN;
|
|---|
| 789 | }
|
|---|
| 790 |
|
|---|
| 791 | if (ELIMINATE_COPY_RELOCS
|
|---|
| 792 | && ind->root.type != bfd_link_hash_indirect
|
|---|
| 793 | && (dir->elf_link_hash_flags & ELF_LINK_HASH_DYNAMIC_ADJUSTED) != 0)
|
|---|
| 794 | /* If called to transfer flags for a weakdef during processing
|
|---|
| 795 | of elf_adjust_dynamic_symbol, don't copy ELF_LINK_NON_GOT_REF.
|
|---|
| 796 | We clear it ourselves for ELIMINATE_COPY_RELOCS. */
|
|---|
| 797 | dir->elf_link_hash_flags |=
|
|---|
| 798 | (ind->elf_link_hash_flags & (ELF_LINK_HASH_REF_DYNAMIC
|
|---|
| 799 | | ELF_LINK_HASH_REF_REGULAR
|
|---|
| 800 | | ELF_LINK_HASH_REF_REGULAR_NONWEAK));
|
|---|
| 801 | else
|
|---|
| 802 | _bfd_elf_link_hash_copy_indirect (bed, dir, ind);
|
|---|
| 803 | }
|
|---|
| 804 |
|
|---|
| 805 | static int
|
|---|
| 806 | elf_s390_tls_transition (info, r_type, is_local)
|
|---|
| 807 | struct bfd_link_info *info;
|
|---|
| 808 | int r_type;
|
|---|
| 809 | int is_local;
|
|---|
| 810 | {
|
|---|
| 811 | if (info->shared)
|
|---|
| 812 | return r_type;
|
|---|
| 813 |
|
|---|
| 814 | switch (r_type)
|
|---|
| 815 | {
|
|---|
| 816 | case R_390_TLS_GD64:
|
|---|
| 817 | case R_390_TLS_IE64:
|
|---|
| 818 | if (is_local)
|
|---|
| 819 | return R_390_TLS_LE64;
|
|---|
| 820 | return R_390_TLS_IE64;
|
|---|
| 821 | case R_390_TLS_GOTIE64:
|
|---|
| 822 | if (is_local)
|
|---|
| 823 | return R_390_TLS_LE64;
|
|---|
| 824 | return R_390_TLS_GOTIE64;
|
|---|
| 825 | case R_390_TLS_LDM64:
|
|---|
| 826 | return R_390_TLS_LE64;
|
|---|
| 827 | }
|
|---|
| 828 |
|
|---|
| 829 | return r_type;
|
|---|
| 830 | }
|
|---|
| 831 |
|
|---|
| 832 | /* Look through the relocs for a section during the first phase, and
|
|---|
| 833 | allocate space in the global offset table or procedure linkage
|
|---|
| 834 | table. */
|
|---|
| 835 |
|
|---|
| 836 | static bfd_boolean
|
|---|
| 837 | elf_s390_check_relocs (abfd, info, sec, relocs)
|
|---|
| 838 | bfd *abfd;
|
|---|
| 839 | struct bfd_link_info *info;
|
|---|
| 840 | asection *sec;
|
|---|
| 841 | const Elf_Internal_Rela *relocs;
|
|---|
| 842 | {
|
|---|
| 843 | struct elf_s390_link_hash_table *htab;
|
|---|
| 844 | Elf_Internal_Shdr *symtab_hdr;
|
|---|
| 845 | struct elf_link_hash_entry **sym_hashes;
|
|---|
| 846 | const Elf_Internal_Rela *rel;
|
|---|
| 847 | const Elf_Internal_Rela *rel_end;
|
|---|
| 848 | asection *sreloc;
|
|---|
| 849 | bfd_signed_vma *local_got_refcounts;
|
|---|
| 850 | int tls_type, old_tls_type;
|
|---|
| 851 |
|
|---|
| 852 | if (info->relocateable)
|
|---|
| 853 | return TRUE;
|
|---|
| 854 |
|
|---|
| 855 | htab = elf_s390_hash_table (info);
|
|---|
| 856 | symtab_hdr = &elf_tdata (abfd)->symtab_hdr;
|
|---|
| 857 | sym_hashes = elf_sym_hashes (abfd);
|
|---|
| 858 | local_got_refcounts = elf_local_got_refcounts (abfd);
|
|---|
| 859 |
|
|---|
| 860 | sreloc = NULL;
|
|---|
| 861 |
|
|---|
| 862 | rel_end = relocs + sec->reloc_count;
|
|---|
| 863 | for (rel = relocs; rel < rel_end; rel++)
|
|---|
| 864 | {
|
|---|
| 865 | unsigned int r_type;
|
|---|
| 866 | unsigned long r_symndx;
|
|---|
| 867 | struct elf_link_hash_entry *h;
|
|---|
| 868 |
|
|---|
| 869 | r_symndx = ELF64_R_SYM (rel->r_info);
|
|---|
| 870 |
|
|---|
| 871 | if (r_symndx >= NUM_SHDR_ENTRIES (symtab_hdr))
|
|---|
| 872 | {
|
|---|
| 873 | (*_bfd_error_handler) (_("%s: bad symbol index: %d"),
|
|---|
| 874 | bfd_archive_filename (abfd),
|
|---|
| 875 | r_symndx);
|
|---|
| 876 | return FALSE;
|
|---|
| 877 | }
|
|---|
| 878 |
|
|---|
| 879 | if (r_symndx < symtab_hdr->sh_info)
|
|---|
| 880 | h = NULL;
|
|---|
| 881 | else
|
|---|
| 882 | h = sym_hashes[r_symndx - symtab_hdr->sh_info];
|
|---|
| 883 |
|
|---|
| 884 | /* Create got section and local_got_refcounts array if they
|
|---|
| 885 | are needed. */
|
|---|
| 886 | r_type = elf_s390_tls_transition (info,
|
|---|
| 887 | ELF64_R_TYPE (rel->r_info),
|
|---|
| 888 | h == NULL);
|
|---|
| 889 | switch (r_type)
|
|---|
| 890 | {
|
|---|
| 891 | case R_390_GOT12:
|
|---|
| 892 | case R_390_GOT16:
|
|---|
| 893 | case R_390_GOT32:
|
|---|
| 894 | case R_390_GOT64:
|
|---|
| 895 | case R_390_GOTENT:
|
|---|
| 896 | case R_390_GOTPLT12:
|
|---|
| 897 | case R_390_GOTPLT16:
|
|---|
| 898 | case R_390_GOTPLT32:
|
|---|
| 899 | case R_390_GOTPLT64:
|
|---|
| 900 | case R_390_GOTPLTENT:
|
|---|
| 901 | case R_390_TLS_GD64:
|
|---|
| 902 | case R_390_TLS_GOTIE12:
|
|---|
| 903 | case R_390_TLS_GOTIE64:
|
|---|
| 904 | case R_390_TLS_IEENT:
|
|---|
| 905 | case R_390_TLS_IE64:
|
|---|
| 906 | case R_390_TLS_LDM64:
|
|---|
| 907 | if (h == NULL
|
|---|
| 908 | && local_got_refcounts == NULL)
|
|---|
| 909 | {
|
|---|
| 910 | bfd_size_type size;
|
|---|
| 911 |
|
|---|
| 912 | size = symtab_hdr->sh_info;
|
|---|
| 913 | size *= (sizeof (bfd_signed_vma) + sizeof(char));
|
|---|
| 914 | local_got_refcounts = ((bfd_signed_vma *)
|
|---|
| 915 | bfd_zalloc (abfd, size));
|
|---|
| 916 | if (local_got_refcounts == NULL)
|
|---|
| 917 | return FALSE;
|
|---|
| 918 | elf_local_got_refcounts (abfd) = local_got_refcounts;
|
|---|
| 919 | elf_s390_local_got_tls_type (abfd)
|
|---|
| 920 | = (char *) (local_got_refcounts + symtab_hdr->sh_info);
|
|---|
| 921 | }
|
|---|
| 922 | /* Fall through. */
|
|---|
| 923 | case R_390_GOTOFF16:
|
|---|
| 924 | case R_390_GOTOFF32:
|
|---|
| 925 | case R_390_GOTOFF64:
|
|---|
| 926 | case R_390_GOTPC:
|
|---|
| 927 | case R_390_GOTPCDBL:
|
|---|
| 928 | if (htab->sgot == NULL)
|
|---|
| 929 | {
|
|---|
| 930 | if (htab->elf.dynobj == NULL)
|
|---|
| 931 | htab->elf.dynobj = abfd;
|
|---|
| 932 | if (!create_got_section (htab->elf.dynobj, info))
|
|---|
| 933 | return FALSE;
|
|---|
| 934 | }
|
|---|
| 935 | }
|
|---|
| 936 |
|
|---|
| 937 | switch (r_type)
|
|---|
| 938 | {
|
|---|
| 939 | case R_390_GOTOFF16:
|
|---|
| 940 | case R_390_GOTOFF32:
|
|---|
| 941 | case R_390_GOTOFF64:
|
|---|
| 942 | case R_390_GOTPC:
|
|---|
| 943 | case R_390_GOTPCDBL:
|
|---|
| 944 | /* Got is created, nothing to be done. */
|
|---|
| 945 | break;
|
|---|
| 946 |
|
|---|
| 947 | case R_390_PLT16DBL:
|
|---|
| 948 | case R_390_PLT32:
|
|---|
| 949 | case R_390_PLT32DBL:
|
|---|
| 950 | case R_390_PLT64:
|
|---|
| 951 | case R_390_PLTOFF16:
|
|---|
| 952 | case R_390_PLTOFF32:
|
|---|
| 953 | case R_390_PLTOFF64:
|
|---|
| 954 | /* This symbol requires a procedure linkage table entry. We
|
|---|
| 955 | actually build the entry in adjust_dynamic_symbol,
|
|---|
| 956 | because this might be a case of linking PIC code which is
|
|---|
| 957 | never referenced by a dynamic object, in which case we
|
|---|
| 958 | don't need to generate a procedure linkage table entry
|
|---|
| 959 | after all. */
|
|---|
| 960 |
|
|---|
| 961 | /* If this is a local symbol, we resolve it directly without
|
|---|
| 962 | creating a procedure linkage table entry. */
|
|---|
| 963 | if (h != NULL)
|
|---|
| 964 | {
|
|---|
| 965 | h->elf_link_hash_flags |= ELF_LINK_HASH_NEEDS_PLT;
|
|---|
| 966 | h->plt.refcount += 1;
|
|---|
| 967 | }
|
|---|
| 968 | break;
|
|---|
| 969 |
|
|---|
| 970 | case R_390_GOTPLT12:
|
|---|
| 971 | case R_390_GOTPLT16:
|
|---|
| 972 | case R_390_GOTPLT32:
|
|---|
| 973 | case R_390_GOTPLT64:
|
|---|
| 974 | case R_390_GOTPLTENT:
|
|---|
| 975 | /* This symbol requires either a procedure linkage table entry
|
|---|
| 976 | or an entry in the local got. We actually build the entry
|
|---|
| 977 | in adjust_dynamic_symbol because whether this is really a
|
|---|
| 978 | global reference can change and with it the fact if we have
|
|---|
| 979 | to create a plt entry or a local got entry. To be able to
|
|---|
| 980 | make a once global symbol a local one we have to keep track
|
|---|
| 981 | of the number of gotplt references that exist for this
|
|---|
| 982 | symbol. */
|
|---|
| 983 | if (h != NULL)
|
|---|
| 984 | {
|
|---|
| 985 | ((struct elf_s390_link_hash_entry *) h)->gotplt_refcount++;
|
|---|
| 986 | h->elf_link_hash_flags |= ELF_LINK_HASH_NEEDS_PLT;
|
|---|
| 987 | h->plt.refcount += 1;
|
|---|
| 988 | }
|
|---|
| 989 | else
|
|---|
| 990 | local_got_refcounts[r_symndx] += 1;
|
|---|
| 991 | break;
|
|---|
| 992 |
|
|---|
| 993 | case R_390_TLS_LDM64:
|
|---|
| 994 | htab->tls_ldm_got.refcount += 1;
|
|---|
| 995 | break;
|
|---|
| 996 |
|
|---|
| 997 | case R_390_TLS_IE64:
|
|---|
| 998 | case R_390_TLS_GOTIE12:
|
|---|
| 999 | case R_390_TLS_GOTIE64:
|
|---|
| 1000 | case R_390_TLS_IEENT:
|
|---|
| 1001 | if (info->shared)
|
|---|
| 1002 | info->flags |= DF_STATIC_TLS;
|
|---|
| 1003 | /* Fall through */
|
|---|
| 1004 |
|
|---|
| 1005 | case R_390_GOT12:
|
|---|
| 1006 | case R_390_GOT16:
|
|---|
| 1007 | case R_390_GOT32:
|
|---|
| 1008 | case R_390_GOT64:
|
|---|
| 1009 | case R_390_GOTENT:
|
|---|
| 1010 | case R_390_TLS_GD64:
|
|---|
| 1011 | /* This symbol requires a global offset table entry. */
|
|---|
| 1012 | switch (r_type)
|
|---|
| 1013 | {
|
|---|
| 1014 | default:
|
|---|
| 1015 | case R_390_GOT12:
|
|---|
| 1016 | case R_390_GOT16:
|
|---|
| 1017 | case R_390_GOT32:
|
|---|
| 1018 | case R_390_GOTENT:
|
|---|
| 1019 | tls_type = GOT_NORMAL;
|
|---|
| 1020 | break;
|
|---|
| 1021 | case R_390_TLS_GD64:
|
|---|
| 1022 | tls_type = GOT_TLS_GD;
|
|---|
| 1023 | break;
|
|---|
| 1024 | case R_390_TLS_IE64:
|
|---|
| 1025 | case R_390_TLS_GOTIE64:
|
|---|
| 1026 | tls_type = GOT_TLS_IE;
|
|---|
| 1027 | break;
|
|---|
| 1028 | case R_390_TLS_GOTIE12:
|
|---|
| 1029 | case R_390_TLS_IEENT:
|
|---|
| 1030 | tls_type = GOT_TLS_IE_NLT;
|
|---|
| 1031 | break;
|
|---|
| 1032 | }
|
|---|
| 1033 |
|
|---|
| 1034 | if (h != NULL)
|
|---|
| 1035 | {
|
|---|
| 1036 | h->got.refcount += 1;
|
|---|
| 1037 | old_tls_type = elf_s390_hash_entry(h)->tls_type;
|
|---|
| 1038 | }
|
|---|
| 1039 | else
|
|---|
| 1040 | {
|
|---|
| 1041 | local_got_refcounts[r_symndx] += 1;
|
|---|
| 1042 | old_tls_type = elf_s390_local_got_tls_type (abfd) [r_symndx];
|
|---|
| 1043 | }
|
|---|
| 1044 | /* If a TLS symbol is accessed using IE at least once,
|
|---|
| 1045 | there is no point to use dynamic model for it. */
|
|---|
| 1046 | if (old_tls_type != tls_type && old_tls_type != GOT_UNKNOWN)
|
|---|
| 1047 | {
|
|---|
| 1048 | if (old_tls_type == GOT_NORMAL || tls_type == GOT_NORMAL)
|
|---|
| 1049 | {
|
|---|
| 1050 | (*_bfd_error_handler)
|
|---|
| 1051 | (_("%s: `%s' accessed both as normal and thread local symbol"),
|
|---|
| 1052 | bfd_archive_filename (abfd), h->root.root.string);
|
|---|
| 1053 | return FALSE;
|
|---|
| 1054 | }
|
|---|
| 1055 | if (old_tls_type > tls_type)
|
|---|
| 1056 | tls_type = old_tls_type;
|
|---|
| 1057 | }
|
|---|
| 1058 |
|
|---|
| 1059 | if (old_tls_type != tls_type)
|
|---|
| 1060 | {
|
|---|
| 1061 | if (h != NULL)
|
|---|
| 1062 | elf_s390_hash_entry (h)->tls_type = tls_type;
|
|---|
| 1063 | else
|
|---|
| 1064 | elf_s390_local_got_tls_type (abfd) [r_symndx] = tls_type;
|
|---|
| 1065 | }
|
|---|
| 1066 |
|
|---|
| 1067 | if (r_type != R_390_TLS_IE64)
|
|---|
| 1068 | break;
|
|---|
| 1069 | /* Fall through */
|
|---|
| 1070 |
|
|---|
| 1071 | case R_390_TLS_LE64:
|
|---|
| 1072 | if (!info->shared)
|
|---|
| 1073 | break;
|
|---|
| 1074 | info->flags |= DF_STATIC_TLS;
|
|---|
| 1075 | /* Fall through */
|
|---|
| 1076 |
|
|---|
| 1077 | case R_390_8:
|
|---|
| 1078 | case R_390_16:
|
|---|
| 1079 | case R_390_32:
|
|---|
| 1080 | case R_390_64:
|
|---|
| 1081 | case R_390_PC16:
|
|---|
| 1082 | case R_390_PC16DBL:
|
|---|
| 1083 | case R_390_PC32:
|
|---|
| 1084 | case R_390_PC32DBL:
|
|---|
| 1085 | case R_390_PC64:
|
|---|
| 1086 | if (h != NULL && !info->shared)
|
|---|
| 1087 | {
|
|---|
| 1088 | /* If this reloc is in a read-only section, we might
|
|---|
| 1089 | need a copy reloc. We can't check reliably at this
|
|---|
| 1090 | stage whether the section is read-only, as input
|
|---|
| 1091 | sections have not yet been mapped to output sections.
|
|---|
| 1092 | Tentatively set the flag for now, and correct in
|
|---|
| 1093 | adjust_dynamic_symbol. */
|
|---|
| 1094 | h->elf_link_hash_flags |= ELF_LINK_NON_GOT_REF;
|
|---|
| 1095 |
|
|---|
| 1096 | /* We may need a .plt entry if the function this reloc
|
|---|
| 1097 | refers to is in a shared lib. */
|
|---|
| 1098 | h->plt.refcount += 1;
|
|---|
| 1099 | }
|
|---|
| 1100 |
|
|---|
| 1101 | /* If we are creating a shared library, and this is a reloc
|
|---|
| 1102 | against a global symbol, or a non PC relative reloc
|
|---|
| 1103 | against a local symbol, then we need to copy the reloc
|
|---|
| 1104 | into the shared library. However, if we are linking with
|
|---|
| 1105 | -Bsymbolic, we do not need to copy a reloc against a
|
|---|
| 1106 | global symbol which is defined in an object we are
|
|---|
| 1107 | including in the link (i.e., DEF_REGULAR is set). At
|
|---|
| 1108 | this point we have not seen all the input files, so it is
|
|---|
| 1109 | possible that DEF_REGULAR is not set now but will be set
|
|---|
| 1110 | later (it is never cleared). In case of a weak definition,
|
|---|
| 1111 | DEF_REGULAR may be cleared later by a strong definition in
|
|---|
| 1112 | a shared library. We account for that possibility below by
|
|---|
| 1113 | storing information in the relocs_copied field of the hash
|
|---|
| 1114 | table entry. A similar situation occurs when creating
|
|---|
| 1115 | shared libraries and symbol visibility changes render the
|
|---|
| 1116 | symbol local.
|
|---|
| 1117 |
|
|---|
| 1118 | If on the other hand, we are creating an executable, we
|
|---|
| 1119 | may need to keep relocations for symbols satisfied by a
|
|---|
| 1120 | dynamic library if we manage to avoid copy relocs for the
|
|---|
| 1121 | symbol. */
|
|---|
| 1122 | if ((info->shared
|
|---|
| 1123 | && (sec->flags & SEC_ALLOC) != 0
|
|---|
| 1124 | && ((ELF64_R_TYPE (rel->r_info) != R_390_PC16
|
|---|
| 1125 | && ELF64_R_TYPE (rel->r_info) != R_390_PC16DBL
|
|---|
| 1126 | && ELF64_R_TYPE (rel->r_info) != R_390_PC32
|
|---|
| 1127 | && ELF64_R_TYPE (rel->r_info) != R_390_PC32DBL
|
|---|
| 1128 | && ELF64_R_TYPE (rel->r_info) != R_390_PC64)
|
|---|
| 1129 | || (h != NULL
|
|---|
| 1130 | && (! info->symbolic
|
|---|
| 1131 | || h->root.type == bfd_link_hash_defweak
|
|---|
| 1132 | || (h->elf_link_hash_flags
|
|---|
| 1133 | & ELF_LINK_HASH_DEF_REGULAR) == 0))))
|
|---|
| 1134 | || (ELIMINATE_COPY_RELOCS
|
|---|
| 1135 | && !info->shared
|
|---|
| 1136 | && (sec->flags & SEC_ALLOC) != 0
|
|---|
| 1137 | && h != NULL
|
|---|
| 1138 | && (h->root.type == bfd_link_hash_defweak
|
|---|
| 1139 | || (h->elf_link_hash_flags
|
|---|
| 1140 | & ELF_LINK_HASH_DEF_REGULAR) == 0)))
|
|---|
| 1141 | {
|
|---|
| 1142 | struct elf_s390_dyn_relocs *p;
|
|---|
| 1143 | struct elf_s390_dyn_relocs **head;
|
|---|
| 1144 |
|
|---|
| 1145 | /* We must copy these reloc types into the output file.
|
|---|
| 1146 | Create a reloc section in dynobj and make room for
|
|---|
| 1147 | this reloc. */
|
|---|
| 1148 | if (sreloc == NULL)
|
|---|
| 1149 | {
|
|---|
| 1150 | const char *name;
|
|---|
| 1151 | bfd *dynobj;
|
|---|
| 1152 |
|
|---|
| 1153 | name = (bfd_elf_string_from_elf_section
|
|---|
| 1154 | (abfd,
|
|---|
| 1155 | elf_elfheader (abfd)->e_shstrndx,
|
|---|
| 1156 | elf_section_data (sec)->rel_hdr.sh_name));
|
|---|
| 1157 | if (name == NULL)
|
|---|
| 1158 | return FALSE;
|
|---|
| 1159 |
|
|---|
| 1160 | if (strncmp (name, ".rela", 5) != 0
|
|---|
| 1161 | || strcmp (bfd_get_section_name (abfd, sec),
|
|---|
| 1162 | name + 5) != 0)
|
|---|
| 1163 | {
|
|---|
| 1164 | (*_bfd_error_handler)
|
|---|
| 1165 | (_("%s: bad relocation section name `%s\'"),
|
|---|
| 1166 | bfd_archive_filename (abfd), name);
|
|---|
| 1167 | }
|
|---|
| 1168 |
|
|---|
| 1169 | if (htab->elf.dynobj == NULL)
|
|---|
| 1170 | htab->elf.dynobj = abfd;
|
|---|
| 1171 |
|
|---|
| 1172 | dynobj = htab->elf.dynobj;
|
|---|
| 1173 | sreloc = bfd_get_section_by_name (dynobj, name);
|
|---|
| 1174 | if (sreloc == NULL)
|
|---|
| 1175 | {
|
|---|
| 1176 | flagword flags;
|
|---|
| 1177 |
|
|---|
| 1178 | sreloc = bfd_make_section (dynobj, name);
|
|---|
| 1179 | flags = (SEC_HAS_CONTENTS | SEC_READONLY
|
|---|
| 1180 | | SEC_IN_MEMORY | SEC_LINKER_CREATED);
|
|---|
| 1181 | if ((sec->flags & SEC_ALLOC) != 0)
|
|---|
| 1182 | flags |= SEC_ALLOC | SEC_LOAD;
|
|---|
| 1183 | if (sreloc == NULL
|
|---|
| 1184 | || ! bfd_set_section_flags (dynobj, sreloc, flags)
|
|---|
| 1185 | || ! bfd_set_section_alignment (dynobj, sreloc, 3))
|
|---|
| 1186 | return FALSE;
|
|---|
| 1187 | }
|
|---|
| 1188 | elf_section_data (sec)->sreloc = sreloc;
|
|---|
| 1189 | }
|
|---|
| 1190 |
|
|---|
| 1191 | /* If this is a global symbol, we count the number of
|
|---|
| 1192 | relocations we need for this symbol. */
|
|---|
| 1193 | if (h != NULL)
|
|---|
| 1194 | {
|
|---|
| 1195 | head = &((struct elf_s390_link_hash_entry *) h)->dyn_relocs;
|
|---|
| 1196 | }
|
|---|
| 1197 | else
|
|---|
| 1198 | {
|
|---|
| 1199 | /* Track dynamic relocs needed for local syms too.
|
|---|
| 1200 | We really need local syms available to do this
|
|---|
| 1201 | easily. Oh well. */
|
|---|
| 1202 |
|
|---|
| 1203 | asection *s;
|
|---|
| 1204 | s = bfd_section_from_r_symndx (abfd, &htab->sym_sec,
|
|---|
| 1205 | sec, r_symndx);
|
|---|
| 1206 | if (s == NULL)
|
|---|
| 1207 | return FALSE;
|
|---|
| 1208 |
|
|---|
| 1209 | head = ((struct elf_s390_dyn_relocs **)
|
|---|
| 1210 | &elf_section_data (s)->local_dynrel);
|
|---|
| 1211 | }
|
|---|
| 1212 |
|
|---|
| 1213 | p = *head;
|
|---|
| 1214 | if (p == NULL || p->sec != sec)
|
|---|
| 1215 | {
|
|---|
| 1216 | bfd_size_type amt = sizeof *p;
|
|---|
| 1217 | p = ((struct elf_s390_dyn_relocs *)
|
|---|
| 1218 | bfd_alloc (htab->elf.dynobj, amt));
|
|---|
| 1219 | if (p == NULL)
|
|---|
| 1220 | return FALSE;
|
|---|
| 1221 | p->next = *head;
|
|---|
| 1222 | *head = p;
|
|---|
| 1223 | p->sec = sec;
|
|---|
| 1224 | p->count = 0;
|
|---|
| 1225 | p->pc_count = 0;
|
|---|
| 1226 | }
|
|---|
| 1227 |
|
|---|
| 1228 | p->count += 1;
|
|---|
| 1229 | if (ELF64_R_TYPE (rel->r_info) == R_390_PC16
|
|---|
| 1230 | || ELF64_R_TYPE (rel->r_info) == R_390_PC16DBL
|
|---|
| 1231 | || ELF64_R_TYPE (rel->r_info) == R_390_PC32
|
|---|
| 1232 | || ELF64_R_TYPE (rel->r_info) == R_390_PC32DBL
|
|---|
| 1233 | || ELF64_R_TYPE (rel->r_info) == R_390_PC64)
|
|---|
| 1234 | p->pc_count += 1;
|
|---|
| 1235 | }
|
|---|
| 1236 | break;
|
|---|
| 1237 |
|
|---|
| 1238 | /* This relocation describes the C++ object vtable hierarchy.
|
|---|
| 1239 | Reconstruct it for later use during GC. */
|
|---|
| 1240 | case R_390_GNU_VTINHERIT:
|
|---|
| 1241 | if (!_bfd_elf64_gc_record_vtinherit (abfd, sec, h, rel->r_offset))
|
|---|
| 1242 | return FALSE;
|
|---|
| 1243 | break;
|
|---|
| 1244 |
|
|---|
| 1245 | /* This relocation describes which C++ vtable entries are actually
|
|---|
| 1246 | used. Record for later use during GC. */
|
|---|
| 1247 | case R_390_GNU_VTENTRY:
|
|---|
| 1248 | if (!_bfd_elf64_gc_record_vtentry (abfd, sec, h, rel->r_addend))
|
|---|
| 1249 | return FALSE;
|
|---|
| 1250 | break;
|
|---|
| 1251 |
|
|---|
| 1252 | default:
|
|---|
| 1253 | break;
|
|---|
| 1254 | }
|
|---|
| 1255 | }
|
|---|
| 1256 |
|
|---|
| 1257 | return TRUE;
|
|---|
| 1258 | }
|
|---|
| 1259 |
|
|---|
| 1260 | /* Return the section that should be marked against GC for a given
|
|---|
| 1261 | relocation. */
|
|---|
| 1262 |
|
|---|
| 1263 | static asection *
|
|---|
| 1264 | elf_s390_gc_mark_hook (sec, info, rel, h, sym)
|
|---|
| 1265 | asection *sec;
|
|---|
| 1266 | struct bfd_link_info *info ATTRIBUTE_UNUSED;
|
|---|
| 1267 | Elf_Internal_Rela *rel;
|
|---|
| 1268 | struct elf_link_hash_entry *h;
|
|---|
| 1269 | Elf_Internal_Sym *sym;
|
|---|
| 1270 | {
|
|---|
| 1271 | if (h != NULL)
|
|---|
| 1272 | {
|
|---|
| 1273 | switch (ELF64_R_TYPE (rel->r_info))
|
|---|
| 1274 | {
|
|---|
| 1275 | case R_390_GNU_VTINHERIT:
|
|---|
| 1276 | case R_390_GNU_VTENTRY:
|
|---|
| 1277 | break;
|
|---|
| 1278 |
|
|---|
| 1279 | default:
|
|---|
| 1280 | switch (h->root.type)
|
|---|
| 1281 | {
|
|---|
| 1282 | case bfd_link_hash_defined:
|
|---|
| 1283 | case bfd_link_hash_defweak:
|
|---|
| 1284 | return h->root.u.def.section;
|
|---|
| 1285 |
|
|---|
| 1286 | case bfd_link_hash_common:
|
|---|
| 1287 | return h->root.u.c.p->section;
|
|---|
| 1288 |
|
|---|
| 1289 | default:
|
|---|
| 1290 | break;
|
|---|
| 1291 | }
|
|---|
| 1292 | }
|
|---|
| 1293 | }
|
|---|
| 1294 | else
|
|---|
| 1295 | return bfd_section_from_elf_index (sec->owner, sym->st_shndx);
|
|---|
| 1296 |
|
|---|
| 1297 | return NULL;
|
|---|
| 1298 | }
|
|---|
| 1299 |
|
|---|
| 1300 | /* Update the got entry reference counts for the section being removed. */
|
|---|
| 1301 |
|
|---|
| 1302 | static bfd_boolean
|
|---|
| 1303 | elf_s390_gc_sweep_hook (abfd, info, sec, relocs)
|
|---|
| 1304 | bfd *abfd;
|
|---|
| 1305 | struct bfd_link_info *info;
|
|---|
| 1306 | asection *sec;
|
|---|
| 1307 | const Elf_Internal_Rela *relocs;
|
|---|
| 1308 | {
|
|---|
| 1309 | Elf_Internal_Shdr *symtab_hdr;
|
|---|
| 1310 | struct elf_link_hash_entry **sym_hashes;
|
|---|
| 1311 | bfd_signed_vma *local_got_refcounts;
|
|---|
| 1312 | const Elf_Internal_Rela *rel, *relend;
|
|---|
| 1313 |
|
|---|
| 1314 | elf_section_data (sec)->local_dynrel = NULL;
|
|---|
| 1315 |
|
|---|
| 1316 | symtab_hdr = &elf_tdata (abfd)->symtab_hdr;
|
|---|
| 1317 | sym_hashes = elf_sym_hashes (abfd);
|
|---|
| 1318 | local_got_refcounts = elf_local_got_refcounts (abfd);
|
|---|
| 1319 |
|
|---|
| 1320 | relend = relocs + sec->reloc_count;
|
|---|
| 1321 | for (rel = relocs; rel < relend; rel++)
|
|---|
| 1322 | {
|
|---|
| 1323 | unsigned long r_symndx;
|
|---|
| 1324 | unsigned int r_type;
|
|---|
| 1325 | struct elf_link_hash_entry *h = NULL;
|
|---|
| 1326 |
|
|---|
| 1327 | r_symndx = ELF64_R_SYM (rel->r_info);
|
|---|
| 1328 | if (r_symndx >= symtab_hdr->sh_info)
|
|---|
| 1329 | {
|
|---|
| 1330 | struct elf_s390_link_hash_entry *eh;
|
|---|
| 1331 | struct elf_s390_dyn_relocs **pp;
|
|---|
| 1332 | struct elf_s390_dyn_relocs *p;
|
|---|
| 1333 |
|
|---|
| 1334 | h = sym_hashes[r_symndx - symtab_hdr->sh_info];
|
|---|
| 1335 | eh = (struct elf_s390_link_hash_entry *) h;
|
|---|
| 1336 |
|
|---|
| 1337 | for (pp = &eh->dyn_relocs; (p = *pp) != NULL; pp = &p->next)
|
|---|
| 1338 | if (p->sec == sec)
|
|---|
| 1339 | {
|
|---|
| 1340 | /* Everything must go for SEC. */
|
|---|
| 1341 | *pp = p->next;
|
|---|
| 1342 | break;
|
|---|
| 1343 | }
|
|---|
| 1344 | }
|
|---|
| 1345 |
|
|---|
| 1346 | r_type = ELF64_R_TYPE (rel->r_info);
|
|---|
| 1347 | r_type = elf_s390_tls_transition (info, r_type, h != NULL);
|
|---|
| 1348 | switch (r_type)
|
|---|
| 1349 | {
|
|---|
| 1350 | case R_390_TLS_LDM64:
|
|---|
| 1351 | if (elf_s390_hash_table (info)->tls_ldm_got.refcount > 0)
|
|---|
| 1352 | elf_s390_hash_table (info)->tls_ldm_got.refcount -= 1;
|
|---|
| 1353 | break;
|
|---|
| 1354 |
|
|---|
| 1355 | case R_390_TLS_GD64:
|
|---|
| 1356 | case R_390_TLS_IE64:
|
|---|
| 1357 | case R_390_TLS_GOTIE12:
|
|---|
| 1358 | case R_390_TLS_GOTIE64:
|
|---|
| 1359 | case R_390_TLS_IEENT:
|
|---|
| 1360 | case R_390_GOT12:
|
|---|
| 1361 | case R_390_GOT16:
|
|---|
| 1362 | case R_390_GOT32:
|
|---|
| 1363 | case R_390_GOT64:
|
|---|
| 1364 | case R_390_GOTOFF16:
|
|---|
| 1365 | case R_390_GOTOFF32:
|
|---|
| 1366 | case R_390_GOTOFF64:
|
|---|
| 1367 | case R_390_GOTPC:
|
|---|
| 1368 | case R_390_GOTPCDBL:
|
|---|
| 1369 | case R_390_GOTENT:
|
|---|
| 1370 | if (h != NULL)
|
|---|
| 1371 | {
|
|---|
| 1372 | if (h->got.refcount > 0)
|
|---|
| 1373 | h->got.refcount -= 1;
|
|---|
| 1374 | }
|
|---|
| 1375 | else if (local_got_refcounts != NULL)
|
|---|
| 1376 | {
|
|---|
| 1377 | if (local_got_refcounts[r_symndx] > 0)
|
|---|
| 1378 | local_got_refcounts[r_symndx] -= 1;
|
|---|
| 1379 | }
|
|---|
| 1380 | break;
|
|---|
| 1381 |
|
|---|
| 1382 | case R_390_8:
|
|---|
| 1383 | case R_390_12:
|
|---|
| 1384 | case R_390_16:
|
|---|
| 1385 | case R_390_32:
|
|---|
| 1386 | case R_390_64:
|
|---|
| 1387 | case R_390_PC16:
|
|---|
| 1388 | case R_390_PC16DBL:
|
|---|
| 1389 | case R_390_PC32:
|
|---|
| 1390 | case R_390_PC32DBL:
|
|---|
| 1391 | case R_390_PC64:
|
|---|
| 1392 | if (info->shared)
|
|---|
| 1393 | break;
|
|---|
| 1394 | /* Fall through */
|
|---|
| 1395 |
|
|---|
| 1396 | case R_390_PLT16DBL:
|
|---|
| 1397 | case R_390_PLT32:
|
|---|
| 1398 | case R_390_PLT32DBL:
|
|---|
| 1399 | case R_390_PLT64:
|
|---|
| 1400 | case R_390_PLTOFF16:
|
|---|
| 1401 | case R_390_PLTOFF32:
|
|---|
| 1402 | case R_390_PLTOFF64:
|
|---|
| 1403 | if (h != NULL)
|
|---|
| 1404 | {
|
|---|
| 1405 | if (h->plt.refcount > 0)
|
|---|
| 1406 | h->plt.refcount -= 1;
|
|---|
| 1407 | }
|
|---|
| 1408 | break;
|
|---|
| 1409 |
|
|---|
| 1410 | case R_390_GOTPLT12:
|
|---|
| 1411 | case R_390_GOTPLT16:
|
|---|
| 1412 | case R_390_GOTPLT32:
|
|---|
| 1413 | case R_390_GOTPLT64:
|
|---|
| 1414 | case R_390_GOTPLTENT:
|
|---|
| 1415 | if (h != NULL)
|
|---|
| 1416 | {
|
|---|
| 1417 | if (h->plt.refcount > 0)
|
|---|
| 1418 | {
|
|---|
| 1419 | ((struct elf_s390_link_hash_entry *) h)->gotplt_refcount--;
|
|---|
| 1420 | h->plt.refcount -= 1;
|
|---|
| 1421 | }
|
|---|
| 1422 | }
|
|---|
| 1423 | else if (local_got_refcounts != NULL)
|
|---|
| 1424 | {
|
|---|
| 1425 | if (local_got_refcounts[r_symndx] > 0)
|
|---|
| 1426 | local_got_refcounts[r_symndx] -= 1;
|
|---|
| 1427 | }
|
|---|
| 1428 | break;
|
|---|
| 1429 |
|
|---|
| 1430 | default:
|
|---|
| 1431 | break;
|
|---|
| 1432 | }
|
|---|
| 1433 | }
|
|---|
| 1434 |
|
|---|
| 1435 | return TRUE;
|
|---|
| 1436 | }
|
|---|
| 1437 |
|
|---|
| 1438 | /* Make sure we emit a GOT entry if the symbol was supposed to have a PLT
|
|---|
| 1439 | entry but we found we will not create any. Called when we find we will
|
|---|
| 1440 | not have any PLT for this symbol, by for example
|
|---|
| 1441 | elf_s390_adjust_dynamic_symbol when we're doing a proper dynamic link,
|
|---|
| 1442 | or elf_s390_size_dynamic_sections if no dynamic sections will be
|
|---|
| 1443 | created (we're only linking static objects). */
|
|---|
| 1444 |
|
|---|
| 1445 | static void
|
|---|
| 1446 | elf_s390_adjust_gotplt (h)
|
|---|
| 1447 | struct elf_s390_link_hash_entry *h;
|
|---|
| 1448 | {
|
|---|
| 1449 | if (h->elf.root.type == bfd_link_hash_warning)
|
|---|
| 1450 | h = (struct elf_s390_link_hash_entry *) h->elf.root.u.i.link;
|
|---|
| 1451 |
|
|---|
| 1452 | if (h->gotplt_refcount <= 0)
|
|---|
| 1453 | return;
|
|---|
| 1454 |
|
|---|
| 1455 | /* We simply add the number of gotplt references to the number
|
|---|
| 1456 | * of got references for this symbol. */
|
|---|
| 1457 | h->elf.got.refcount += h->gotplt_refcount;
|
|---|
| 1458 | h->gotplt_refcount = -1;
|
|---|
| 1459 | }
|
|---|
| 1460 |
|
|---|
| 1461 | /* Adjust a symbol defined by a dynamic object and referenced by a
|
|---|
| 1462 | regular object. The current definition is in some section of the
|
|---|
| 1463 | dynamic object, but we're not including those sections. We have to
|
|---|
| 1464 | change the definition to something the rest of the link can
|
|---|
| 1465 | understand. */
|
|---|
| 1466 |
|
|---|
| 1467 | static bfd_boolean
|
|---|
| 1468 | elf_s390_adjust_dynamic_symbol (info, h)
|
|---|
| 1469 | struct bfd_link_info *info;
|
|---|
| 1470 | struct elf_link_hash_entry *h;
|
|---|
| 1471 | {
|
|---|
| 1472 | struct elf_s390_link_hash_table *htab;
|
|---|
| 1473 | asection *s;
|
|---|
| 1474 | unsigned int power_of_two;
|
|---|
| 1475 |
|
|---|
| 1476 | /* If this is a function, put it in the procedure linkage table. We
|
|---|
| 1477 | will fill in the contents of the procedure linkage table later
|
|---|
| 1478 | (although we could actually do it here). */
|
|---|
| 1479 | if (h->type == STT_FUNC
|
|---|
| 1480 | || (h->elf_link_hash_flags & ELF_LINK_HASH_NEEDS_PLT) != 0)
|
|---|
| 1481 | {
|
|---|
| 1482 | if (h->plt.refcount <= 0
|
|---|
| 1483 | || (! info->shared
|
|---|
| 1484 | && (h->elf_link_hash_flags & ELF_LINK_HASH_DEF_DYNAMIC) == 0
|
|---|
| 1485 | && (h->elf_link_hash_flags & ELF_LINK_HASH_REF_DYNAMIC) == 0
|
|---|
| 1486 | && h->root.type != bfd_link_hash_undefweak
|
|---|
| 1487 | && h->root.type != bfd_link_hash_undefined))
|
|---|
| 1488 | {
|
|---|
| 1489 | /* This case can occur if we saw a PLT32 reloc in an input
|
|---|
| 1490 | file, but the symbol was never referred to by a dynamic
|
|---|
| 1491 | object, or if all references were garbage collected. In
|
|---|
| 1492 | such a case, we don't actually need to build a procedure
|
|---|
| 1493 | linkage table, and we can just do a PC32 reloc instead. */
|
|---|
| 1494 | h->plt.offset = (bfd_vma) -1;
|
|---|
| 1495 | h->elf_link_hash_flags &= ~ELF_LINK_HASH_NEEDS_PLT;
|
|---|
| 1496 | elf_s390_adjust_gotplt((struct elf_s390_link_hash_entry *) h);
|
|---|
| 1497 | }
|
|---|
| 1498 |
|
|---|
| 1499 | return TRUE;
|
|---|
| 1500 | }
|
|---|
| 1501 | else
|
|---|
| 1502 | /* It's possible that we incorrectly decided a .plt reloc was
|
|---|
| 1503 | needed for an R_390_PC32 reloc to a non-function sym in
|
|---|
| 1504 | check_relocs. We can't decide accurately between function and
|
|---|
| 1505 | non-function syms in check-relocs; Objects loaded later in
|
|---|
| 1506 | the link may change h->type. So fix it now. */
|
|---|
| 1507 | h->plt.offset = (bfd_vma) -1;
|
|---|
| 1508 |
|
|---|
| 1509 | /* If this is a weak symbol, and there is a real definition, the
|
|---|
| 1510 | processor independent code will have arranged for us to see the
|
|---|
| 1511 | real definition first, and we can just use the same value. */
|
|---|
| 1512 | if (h->weakdef != NULL)
|
|---|
| 1513 | {
|
|---|
| 1514 | BFD_ASSERT (h->weakdef->root.type == bfd_link_hash_defined
|
|---|
| 1515 | || h->weakdef->root.type == bfd_link_hash_defweak);
|
|---|
| 1516 | h->root.u.def.section = h->weakdef->root.u.def.section;
|
|---|
| 1517 | h->root.u.def.value = h->weakdef->root.u.def.value;
|
|---|
| 1518 | if (ELIMINATE_COPY_RELOCS || info->nocopyreloc)
|
|---|
| 1519 | h->elf_link_hash_flags
|
|---|
| 1520 | = ((h->elf_link_hash_flags & ~ELF_LINK_NON_GOT_REF)
|
|---|
| 1521 | | (h->weakdef->elf_link_hash_flags & ELF_LINK_NON_GOT_REF));
|
|---|
| 1522 | return TRUE;
|
|---|
| 1523 | }
|
|---|
| 1524 |
|
|---|
| 1525 | /* This is a reference to a symbol defined by a dynamic object which
|
|---|
| 1526 | is not a function. */
|
|---|
| 1527 |
|
|---|
| 1528 | /* If we are creating a shared library, we must presume that the
|
|---|
| 1529 | only references to the symbol are via the global offset table.
|
|---|
| 1530 | For such cases we need not do anything here; the relocations will
|
|---|
| 1531 | be handled correctly by relocate_section. */
|
|---|
| 1532 | if (info->shared)
|
|---|
| 1533 | return TRUE;
|
|---|
| 1534 |
|
|---|
| 1535 | /* If there are no references to this symbol that do not use the
|
|---|
| 1536 | GOT, we don't need to generate a copy reloc. */
|
|---|
| 1537 | if ((h->elf_link_hash_flags & ELF_LINK_NON_GOT_REF) == 0)
|
|---|
| 1538 | return TRUE;
|
|---|
| 1539 |
|
|---|
| 1540 | /* If -z nocopyreloc was given, we won't generate them either. */
|
|---|
| 1541 | if (info->nocopyreloc)
|
|---|
| 1542 | {
|
|---|
| 1543 | h->elf_link_hash_flags &= ~ELF_LINK_NON_GOT_REF;
|
|---|
| 1544 | return TRUE;
|
|---|
| 1545 | }
|
|---|
| 1546 |
|
|---|
| 1547 | if (ELIMINATE_COPY_RELOCS)
|
|---|
| 1548 | {
|
|---|
| 1549 | struct elf_s390_link_hash_entry * eh;
|
|---|
| 1550 | struct elf_s390_dyn_relocs *p;
|
|---|
| 1551 |
|
|---|
| 1552 | eh = (struct elf_s390_link_hash_entry *) h;
|
|---|
| 1553 | for (p = eh->dyn_relocs; p != NULL; p = p->next)
|
|---|
| 1554 | {
|
|---|
| 1555 | s = p->sec->output_section;
|
|---|
| 1556 | if (s != NULL && (s->flags & SEC_READONLY) != 0)
|
|---|
| 1557 | break;
|
|---|
| 1558 | }
|
|---|
| 1559 |
|
|---|
| 1560 | /* If we didn't find any dynamic relocs in read-only sections, then
|
|---|
| 1561 | we'll be keeping the dynamic relocs and avoiding the copy reloc. */
|
|---|
| 1562 | if (p == NULL)
|
|---|
| 1563 | {
|
|---|
| 1564 | h->elf_link_hash_flags &= ~ELF_LINK_NON_GOT_REF;
|
|---|
| 1565 | return TRUE;
|
|---|
| 1566 | }
|
|---|
| 1567 | }
|
|---|
| 1568 |
|
|---|
| 1569 | /* We must allocate the symbol in our .dynbss section, which will
|
|---|
| 1570 | become part of the .bss section of the executable. There will be
|
|---|
| 1571 | an entry for this symbol in the .dynsym section. The dynamic
|
|---|
| 1572 | object will contain position independent code, so all references
|
|---|
| 1573 | from the dynamic object to this symbol will go through the global
|
|---|
| 1574 | offset table. The dynamic linker will use the .dynsym entry to
|
|---|
| 1575 | determine the address it must put in the global offset table, so
|
|---|
| 1576 | both the dynamic object and the regular object will refer to the
|
|---|
| 1577 | same memory location for the variable. */
|
|---|
| 1578 |
|
|---|
| 1579 | htab = elf_s390_hash_table (info);
|
|---|
| 1580 |
|
|---|
| 1581 | /* We must generate a R_390_COPY reloc to tell the dynamic linker to
|
|---|
| 1582 | copy the initial value out of the dynamic object and into the
|
|---|
| 1583 | runtime process image. */
|
|---|
| 1584 | if ((h->root.u.def.section->flags & SEC_ALLOC) != 0)
|
|---|
| 1585 | {
|
|---|
| 1586 | htab->srelbss->_raw_size += sizeof (Elf64_External_Rela);
|
|---|
| 1587 | h->elf_link_hash_flags |= ELF_LINK_HASH_NEEDS_COPY;
|
|---|
| 1588 | }
|
|---|
| 1589 |
|
|---|
| 1590 | /* We need to figure out the alignment required for this symbol. I
|
|---|
| 1591 | have no idea how ELF linkers handle this. */
|
|---|
| 1592 | power_of_two = bfd_log2 (h->size);
|
|---|
| 1593 | if (power_of_two > 3)
|
|---|
| 1594 | power_of_two = 3;
|
|---|
| 1595 |
|
|---|
| 1596 | /* Apply the required alignment. */
|
|---|
| 1597 | s = htab->sdynbss;
|
|---|
| 1598 | s->_raw_size = BFD_ALIGN (s->_raw_size, (bfd_size_type) (1 << power_of_two));
|
|---|
| 1599 | if (power_of_two > bfd_get_section_alignment (htab->elf.dynobj, s))
|
|---|
| 1600 | {
|
|---|
| 1601 | if (! bfd_set_section_alignment (htab->elf.dynobj, s, power_of_two))
|
|---|
| 1602 | return FALSE;
|
|---|
| 1603 | }
|
|---|
| 1604 |
|
|---|
| 1605 | /* Define the symbol as being at this point in the section. */
|
|---|
| 1606 | h->root.u.def.section = s;
|
|---|
| 1607 | h->root.u.def.value = s->_raw_size;
|
|---|
| 1608 |
|
|---|
| 1609 | /* Increment the section size to make room for the symbol. */
|
|---|
| 1610 | s->_raw_size += h->size;
|
|---|
| 1611 |
|
|---|
| 1612 | return TRUE;
|
|---|
| 1613 | }
|
|---|
| 1614 |
|
|---|
| 1615 | /* This is the condition under which elf_s390_finish_dynamic_symbol
|
|---|
| 1616 | will be called from elflink.h. If elflink.h doesn't call our
|
|---|
| 1617 | finish_dynamic_symbol routine, we'll need to do something about
|
|---|
| 1618 | initializing any .plt and .got entries in elf_s390_relocate_section. */
|
|---|
| 1619 | #define WILL_CALL_FINISH_DYNAMIC_SYMBOL(DYN, INFO, H) \
|
|---|
| 1620 | ((DYN) \
|
|---|
| 1621 | && ((INFO)->shared \
|
|---|
| 1622 | || ((H)->elf_link_hash_flags & ELF_LINK_FORCED_LOCAL) == 0) \
|
|---|
| 1623 | && ((H)->dynindx != -1 \
|
|---|
| 1624 | || ((H)->elf_link_hash_flags & ELF_LINK_FORCED_LOCAL) != 0))
|
|---|
| 1625 |
|
|---|
| 1626 | /* Allocate space in .plt, .got and associated reloc sections for
|
|---|
| 1627 | dynamic relocs. */
|
|---|
| 1628 |
|
|---|
| 1629 | static bfd_boolean
|
|---|
| 1630 | allocate_dynrelocs (h, inf)
|
|---|
| 1631 | struct elf_link_hash_entry *h;
|
|---|
| 1632 | PTR inf;
|
|---|
| 1633 | {
|
|---|
| 1634 | struct bfd_link_info *info;
|
|---|
| 1635 | struct elf_s390_link_hash_table *htab;
|
|---|
| 1636 | struct elf_s390_link_hash_entry *eh;
|
|---|
| 1637 | struct elf_s390_dyn_relocs *p;
|
|---|
| 1638 |
|
|---|
| 1639 | if (h->root.type == bfd_link_hash_indirect)
|
|---|
| 1640 | return TRUE;
|
|---|
| 1641 |
|
|---|
| 1642 | if (h->root.type == bfd_link_hash_warning)
|
|---|
| 1643 | /* When warning symbols are created, they **replace** the "real"
|
|---|
| 1644 | entry in the hash table, thus we never get to see the real
|
|---|
| 1645 | symbol in a hash traversal. So look at it now. */
|
|---|
| 1646 | h = (struct elf_link_hash_entry *) h->root.u.i.link;
|
|---|
| 1647 |
|
|---|
| 1648 | info = (struct bfd_link_info *) inf;
|
|---|
| 1649 | htab = elf_s390_hash_table (info);
|
|---|
| 1650 |
|
|---|
| 1651 | if (htab->elf.dynamic_sections_created
|
|---|
| 1652 | && h->plt.refcount > 0)
|
|---|
| 1653 | {
|
|---|
| 1654 | /* Make sure this symbol is output as a dynamic symbol.
|
|---|
| 1655 | Undefined weak syms won't yet be marked as dynamic. */
|
|---|
| 1656 | if (h->dynindx == -1
|
|---|
| 1657 | && (h->elf_link_hash_flags & ELF_LINK_FORCED_LOCAL) == 0)
|
|---|
| 1658 | {
|
|---|
| 1659 | if (! bfd_elf64_link_record_dynamic_symbol (info, h))
|
|---|
| 1660 | return FALSE;
|
|---|
| 1661 | }
|
|---|
| 1662 |
|
|---|
| 1663 | if (WILL_CALL_FINISH_DYNAMIC_SYMBOL (1, info, h))
|
|---|
| 1664 | {
|
|---|
| 1665 | asection *s = htab->splt;
|
|---|
| 1666 |
|
|---|
| 1667 | /* If this is the first .plt entry, make room for the special
|
|---|
| 1668 | first entry. */
|
|---|
| 1669 | if (s->_raw_size == 0)
|
|---|
| 1670 | s->_raw_size += PLT_FIRST_ENTRY_SIZE;
|
|---|
| 1671 |
|
|---|
| 1672 | h->plt.offset = s->_raw_size;
|
|---|
| 1673 |
|
|---|
| 1674 | /* If this symbol is not defined in a regular file, and we are
|
|---|
| 1675 | not generating a shared library, then set the symbol to this
|
|---|
| 1676 | location in the .plt. This is required to make function
|
|---|
| 1677 | pointers compare as equal between the normal executable and
|
|---|
| 1678 | the shared library. */
|
|---|
| 1679 | if (! info->shared
|
|---|
| 1680 | && (h->elf_link_hash_flags & ELF_LINK_HASH_DEF_REGULAR) == 0)
|
|---|
| 1681 | {
|
|---|
| 1682 | h->root.u.def.section = s;
|
|---|
| 1683 | h->root.u.def.value = h->plt.offset;
|
|---|
| 1684 | }
|
|---|
| 1685 |
|
|---|
| 1686 | /* Make room for this entry. */
|
|---|
| 1687 | s->_raw_size += PLT_ENTRY_SIZE;
|
|---|
| 1688 |
|
|---|
| 1689 | /* We also need to make an entry in the .got.plt section, which
|
|---|
| 1690 | will be placed in the .got section by the linker script. */
|
|---|
| 1691 | htab->sgotplt->_raw_size += GOT_ENTRY_SIZE;
|
|---|
| 1692 |
|
|---|
| 1693 | /* We also need to make an entry in the .rela.plt section. */
|
|---|
| 1694 | htab->srelplt->_raw_size += sizeof (Elf64_External_Rela);
|
|---|
| 1695 | }
|
|---|
| 1696 | else
|
|---|
| 1697 | {
|
|---|
| 1698 | h->plt.offset = (bfd_vma) -1;
|
|---|
| 1699 | h->elf_link_hash_flags &= ~ELF_LINK_HASH_NEEDS_PLT;
|
|---|
| 1700 | elf_s390_adjust_gotplt((struct elf_s390_link_hash_entry *) h);
|
|---|
| 1701 | }
|
|---|
| 1702 | }
|
|---|
| 1703 | else
|
|---|
| 1704 | {
|
|---|
| 1705 | h->plt.offset = (bfd_vma) -1;
|
|---|
| 1706 | h->elf_link_hash_flags &= ~ELF_LINK_HASH_NEEDS_PLT;
|
|---|
| 1707 | elf_s390_adjust_gotplt((struct elf_s390_link_hash_entry *) h);
|
|---|
| 1708 | }
|
|---|
| 1709 |
|
|---|
| 1710 | /* If R_390_TLS_{IE64,GOTIE64,GOTIE12,IEENT} symbol is now local to
|
|---|
| 1711 | the binary, we can optimize a bit. IE64 and GOTIE64 get converted
|
|---|
| 1712 | to R_390_TLS_LE64 requiring no TLS entry. For GOTIE12 and IEENT
|
|---|
| 1713 | we can save the dynamic TLS relocation. */
|
|---|
| 1714 | if (h->got.refcount > 0
|
|---|
| 1715 | && !info->shared
|
|---|
| 1716 | && h->dynindx == -1
|
|---|
| 1717 | && elf_s390_hash_entry(h)->tls_type >= GOT_TLS_IE)
|
|---|
| 1718 | {
|
|---|
| 1719 | if (elf_s390_hash_entry(h)->tls_type == GOT_TLS_IE_NLT)
|
|---|
| 1720 | /* For the GOTIE access without a literal pool entry the offset has
|
|---|
| 1721 | to be stored somewhere. The immediate value in the instruction
|
|---|
| 1722 | is not bit enough so the value is stored in the got. */
|
|---|
| 1723 | {
|
|---|
| 1724 | h->got.offset = htab->sgot->_raw_size;
|
|---|
| 1725 | htab->sgot->_raw_size += GOT_ENTRY_SIZE;
|
|---|
| 1726 | }
|
|---|
| 1727 | else
|
|---|
| 1728 | h->got.offset = (bfd_vma) -1;
|
|---|
| 1729 | }
|
|---|
| 1730 | else if (h->got.refcount > 0)
|
|---|
| 1731 | {
|
|---|
| 1732 | asection *s;
|
|---|
| 1733 | bfd_boolean dyn;
|
|---|
| 1734 | int tls_type = elf_s390_hash_entry(h)->tls_type;
|
|---|
| 1735 |
|
|---|
| 1736 | /* Make sure this symbol is output as a dynamic symbol.
|
|---|
| 1737 | Undefined weak syms won't yet be marked as dynamic. */
|
|---|
| 1738 | if (h->dynindx == -1
|
|---|
| 1739 | && (h->elf_link_hash_flags & ELF_LINK_FORCED_LOCAL) == 0)
|
|---|
| 1740 | {
|
|---|
| 1741 | if (! bfd_elf64_link_record_dynamic_symbol (info, h))
|
|---|
| 1742 | return FALSE;
|
|---|
| 1743 | }
|
|---|
| 1744 |
|
|---|
| 1745 | s = htab->sgot;
|
|---|
| 1746 | h->got.offset = s->_raw_size;
|
|---|
| 1747 | s->_raw_size += GOT_ENTRY_SIZE;
|
|---|
| 1748 | /* R_390_TLS_GD64 needs 2 consecutive GOT slots. */
|
|---|
| 1749 | if (tls_type == GOT_TLS_GD)
|
|---|
| 1750 | s->_raw_size += GOT_ENTRY_SIZE;
|
|---|
| 1751 | dyn = htab->elf.dynamic_sections_created;
|
|---|
| 1752 | /* R_390_TLS_IE64 needs one dynamic relocation,
|
|---|
| 1753 | R_390_TLS_GD64 needs one if local symbol and two if global. */
|
|---|
| 1754 | if ((tls_type == GOT_TLS_GD && h->dynindx == -1)
|
|---|
| 1755 | || tls_type >= GOT_TLS_IE)
|
|---|
| 1756 | htab->srelgot->_raw_size += sizeof (Elf64_External_Rela);
|
|---|
| 1757 | else if (tls_type == GOT_TLS_GD)
|
|---|
| 1758 | htab->srelgot->_raw_size += 2 * sizeof (Elf64_External_Rela);
|
|---|
| 1759 | else if (WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn, info, h))
|
|---|
| 1760 | htab->srelgot->_raw_size += sizeof (Elf64_External_Rela);
|
|---|
| 1761 | }
|
|---|
| 1762 | else
|
|---|
| 1763 | h->got.offset = (bfd_vma) -1;
|
|---|
| 1764 |
|
|---|
| 1765 | eh = (struct elf_s390_link_hash_entry *) h;
|
|---|
| 1766 | if (eh->dyn_relocs == NULL)
|
|---|
| 1767 | return TRUE;
|
|---|
| 1768 |
|
|---|
| 1769 | /* In the shared -Bsymbolic case, discard space allocated for
|
|---|
| 1770 | dynamic pc-relative relocs against symbols which turn out to be
|
|---|
| 1771 | defined in regular objects. For the normal shared case, discard
|
|---|
| 1772 | space for pc-relative relocs that have become local due to symbol
|
|---|
| 1773 | visibility changes. */
|
|---|
| 1774 |
|
|---|
| 1775 | if (info->shared)
|
|---|
| 1776 | {
|
|---|
| 1777 | if ((h->elf_link_hash_flags & ELF_LINK_HASH_DEF_REGULAR) != 0
|
|---|
| 1778 | && ((h->elf_link_hash_flags & ELF_LINK_FORCED_LOCAL) != 0
|
|---|
| 1779 | || info->symbolic))
|
|---|
| 1780 | {
|
|---|
| 1781 | struct elf_s390_dyn_relocs **pp;
|
|---|
| 1782 |
|
|---|
| 1783 | for (pp = &eh->dyn_relocs; (p = *pp) != NULL; )
|
|---|
| 1784 | {
|
|---|
| 1785 | p->count -= p->pc_count;
|
|---|
| 1786 | p->pc_count = 0;
|
|---|
| 1787 | if (p->count == 0)
|
|---|
| 1788 | *pp = p->next;
|
|---|
| 1789 | else
|
|---|
| 1790 | pp = &p->next;
|
|---|
| 1791 | }
|
|---|
| 1792 | }
|
|---|
| 1793 | }
|
|---|
| 1794 | else if (ELIMINATE_COPY_RELOCS)
|
|---|
| 1795 | {
|
|---|
| 1796 | /* For the non-shared case, discard space for relocs against
|
|---|
| 1797 | symbols which turn out to need copy relocs or are not
|
|---|
| 1798 | dynamic. */
|
|---|
| 1799 |
|
|---|
| 1800 | if ((h->elf_link_hash_flags & ELF_LINK_NON_GOT_REF) == 0
|
|---|
| 1801 | && (((h->elf_link_hash_flags & ELF_LINK_HASH_DEF_DYNAMIC) != 0
|
|---|
| 1802 | && (h->elf_link_hash_flags & ELF_LINK_HASH_DEF_REGULAR) == 0)
|
|---|
| 1803 | || (htab->elf.dynamic_sections_created
|
|---|
| 1804 | && (h->root.type == bfd_link_hash_undefweak
|
|---|
| 1805 | || h->root.type == bfd_link_hash_undefined))))
|
|---|
| 1806 | {
|
|---|
| 1807 | /* Make sure this symbol is output as a dynamic symbol.
|
|---|
| 1808 | Undefined weak syms won't yet be marked as dynamic. */
|
|---|
| 1809 | if (h->dynindx == -1
|
|---|
| 1810 | && (h->elf_link_hash_flags & ELF_LINK_FORCED_LOCAL) == 0)
|
|---|
| 1811 | {
|
|---|
| 1812 | if (! bfd_elf64_link_record_dynamic_symbol (info, h))
|
|---|
| 1813 | return FALSE;
|
|---|
| 1814 | }
|
|---|
| 1815 |
|
|---|
| 1816 | /* If that succeeded, we know we'll be keeping all the
|
|---|
| 1817 | relocs. */
|
|---|
| 1818 | if (h->dynindx != -1)
|
|---|
| 1819 | goto keep;
|
|---|
| 1820 | }
|
|---|
| 1821 |
|
|---|
| 1822 | eh->dyn_relocs = NULL;
|
|---|
| 1823 |
|
|---|
| 1824 | keep: ;
|
|---|
| 1825 | }
|
|---|
| 1826 |
|
|---|
| 1827 | /* Finally, allocate space. */
|
|---|
| 1828 | for (p = eh->dyn_relocs; p != NULL; p = p->next)
|
|---|
| 1829 | {
|
|---|
| 1830 | asection *sreloc = elf_section_data (p->sec)->sreloc;
|
|---|
| 1831 | sreloc->_raw_size += p->count * sizeof (Elf64_External_Rela);
|
|---|
| 1832 | }
|
|---|
| 1833 |
|
|---|
| 1834 | return TRUE;
|
|---|
| 1835 | }
|
|---|
| 1836 |
|
|---|
| 1837 | /* Find any dynamic relocs that apply to read-only sections. */
|
|---|
| 1838 |
|
|---|
| 1839 | static bfd_boolean
|
|---|
| 1840 | readonly_dynrelocs (h, inf)
|
|---|
| 1841 | struct elf_link_hash_entry *h;
|
|---|
| 1842 | PTR inf;
|
|---|
| 1843 | {
|
|---|
| 1844 | struct elf_s390_link_hash_entry *eh;
|
|---|
| 1845 | struct elf_s390_dyn_relocs *p;
|
|---|
| 1846 |
|
|---|
| 1847 | if (h->root.type == bfd_link_hash_warning)
|
|---|
| 1848 | h = (struct elf_link_hash_entry *) h->root.u.i.link;
|
|---|
| 1849 |
|
|---|
| 1850 | eh = (struct elf_s390_link_hash_entry *) h;
|
|---|
| 1851 | for (p = eh->dyn_relocs; p != NULL; p = p->next)
|
|---|
| 1852 | {
|
|---|
| 1853 | asection *s = p->sec->output_section;
|
|---|
| 1854 |
|
|---|
| 1855 | if (s != NULL && (s->flags & SEC_READONLY) != 0)
|
|---|
| 1856 | {
|
|---|
| 1857 | struct bfd_link_info *info = (struct bfd_link_info *) inf;
|
|---|
| 1858 |
|
|---|
| 1859 | info->flags |= DF_TEXTREL;
|
|---|
| 1860 |
|
|---|
| 1861 | /* Not an error, just cut short the traversal. */
|
|---|
| 1862 | return FALSE;
|
|---|
| 1863 | }
|
|---|
| 1864 | }
|
|---|
| 1865 | return TRUE;
|
|---|
| 1866 | }
|
|---|
| 1867 |
|
|---|
| 1868 | /* Set the sizes of the dynamic sections. */
|
|---|
| 1869 |
|
|---|
| 1870 | static bfd_boolean
|
|---|
| 1871 | elf_s390_size_dynamic_sections (output_bfd, info)
|
|---|
| 1872 | bfd *output_bfd ATTRIBUTE_UNUSED;
|
|---|
| 1873 | struct bfd_link_info *info;
|
|---|
| 1874 | {
|
|---|
| 1875 | struct elf_s390_link_hash_table *htab;
|
|---|
| 1876 | bfd *dynobj;
|
|---|
| 1877 | asection *s;
|
|---|
| 1878 | bfd_boolean relocs;
|
|---|
| 1879 | bfd *ibfd;
|
|---|
| 1880 |
|
|---|
| 1881 | htab = elf_s390_hash_table (info);
|
|---|
| 1882 | dynobj = htab->elf.dynobj;
|
|---|
| 1883 | if (dynobj == NULL)
|
|---|
| 1884 | abort ();
|
|---|
| 1885 |
|
|---|
| 1886 | if (htab->elf.dynamic_sections_created)
|
|---|
| 1887 | {
|
|---|
| 1888 | /* Set the contents of the .interp section to the interpreter. */
|
|---|
| 1889 | if (! info->shared)
|
|---|
| 1890 | {
|
|---|
| 1891 | s = bfd_get_section_by_name (dynobj, ".interp");
|
|---|
| 1892 | if (s == NULL)
|
|---|
| 1893 | abort ();
|
|---|
| 1894 | s->_raw_size = sizeof ELF_DYNAMIC_INTERPRETER;
|
|---|
| 1895 | s->contents = (unsigned char *) ELF_DYNAMIC_INTERPRETER;
|
|---|
| 1896 | }
|
|---|
| 1897 | }
|
|---|
| 1898 |
|
|---|
| 1899 | /* Set up .got offsets for local syms, and space for local dynamic
|
|---|
| 1900 | relocs. */
|
|---|
| 1901 | for (ibfd = info->input_bfds; ibfd != NULL; ibfd = ibfd->link_next)
|
|---|
| 1902 | {
|
|---|
| 1903 | bfd_signed_vma *local_got;
|
|---|
| 1904 | bfd_signed_vma *end_local_got;
|
|---|
| 1905 | char *local_tls_type;
|
|---|
| 1906 | bfd_size_type locsymcount;
|
|---|
| 1907 | Elf_Internal_Shdr *symtab_hdr;
|
|---|
| 1908 | asection *srela;
|
|---|
| 1909 |
|
|---|
| 1910 | if (bfd_get_flavour (ibfd) != bfd_target_elf_flavour)
|
|---|
| 1911 | continue;
|
|---|
| 1912 |
|
|---|
| 1913 | for (s = ibfd->sections; s != NULL; s = s->next)
|
|---|
| 1914 | {
|
|---|
| 1915 | struct elf_s390_dyn_relocs *p;
|
|---|
| 1916 |
|
|---|
| 1917 | for (p = *((struct elf_s390_dyn_relocs **)
|
|---|
| 1918 | &elf_section_data (s)->local_dynrel);
|
|---|
| 1919 | p != NULL;
|
|---|
| 1920 | p = p->next)
|
|---|
| 1921 | {
|
|---|
| 1922 | if (!bfd_is_abs_section (p->sec)
|
|---|
| 1923 | && bfd_is_abs_section (p->sec->output_section))
|
|---|
| 1924 | {
|
|---|
| 1925 | /* Input section has been discarded, either because
|
|---|
| 1926 | it is a copy of a linkonce section or due to
|
|---|
| 1927 | linker script /DISCARD/, so we'll be discarding
|
|---|
| 1928 | the relocs too. */
|
|---|
| 1929 | }
|
|---|
| 1930 | else if (p->count != 0)
|
|---|
| 1931 | {
|
|---|
| 1932 | srela = elf_section_data (p->sec)->sreloc;
|
|---|
| 1933 | srela->_raw_size += p->count * sizeof (Elf64_External_Rela);
|
|---|
| 1934 | if ((p->sec->output_section->flags & SEC_READONLY) != 0)
|
|---|
| 1935 | info->flags |= DF_TEXTREL;
|
|---|
| 1936 | }
|
|---|
| 1937 | }
|
|---|
| 1938 | }
|
|---|
| 1939 |
|
|---|
| 1940 | local_got = elf_local_got_refcounts (ibfd);
|
|---|
| 1941 | if (!local_got)
|
|---|
| 1942 | continue;
|
|---|
| 1943 |
|
|---|
| 1944 | symtab_hdr = &elf_tdata (ibfd)->symtab_hdr;
|
|---|
| 1945 | locsymcount = symtab_hdr->sh_info;
|
|---|
| 1946 | end_local_got = local_got + locsymcount;
|
|---|
| 1947 | local_tls_type = elf_s390_local_got_tls_type (ibfd);
|
|---|
| 1948 | s = htab->sgot;
|
|---|
| 1949 | srela = htab->srelgot;
|
|---|
| 1950 | for (; local_got < end_local_got; ++local_got, ++local_tls_type)
|
|---|
| 1951 | {
|
|---|
| 1952 | if (*local_got > 0)
|
|---|
| 1953 | {
|
|---|
| 1954 | *local_got = s->_raw_size;
|
|---|
| 1955 | s->_raw_size += GOT_ENTRY_SIZE;
|
|---|
| 1956 | if (*local_tls_type == GOT_TLS_GD)
|
|---|
| 1957 | s->_raw_size += GOT_ENTRY_SIZE;
|
|---|
| 1958 | if (info->shared)
|
|---|
| 1959 | srela->_raw_size += sizeof (Elf64_External_Rela);
|
|---|
| 1960 | }
|
|---|
| 1961 | else
|
|---|
| 1962 | *local_got = (bfd_vma) -1;
|
|---|
| 1963 | }
|
|---|
| 1964 | }
|
|---|
| 1965 |
|
|---|
| 1966 | if (htab->tls_ldm_got.refcount > 0)
|
|---|
| 1967 | {
|
|---|
| 1968 | /* Allocate 2 got entries and 1 dynamic reloc for R_390_TLS_LDM64
|
|---|
| 1969 | relocs. */
|
|---|
| 1970 | htab->tls_ldm_got.offset = htab->sgot->_raw_size;
|
|---|
| 1971 | htab->sgot->_raw_size += 2 * GOT_ENTRY_SIZE;
|
|---|
| 1972 | htab->srelgot->_raw_size += sizeof (Elf64_External_Rela);
|
|---|
| 1973 | }
|
|---|
| 1974 | else
|
|---|
| 1975 | htab->tls_ldm_got.offset = -1;
|
|---|
| 1976 |
|
|---|
| 1977 | /* Allocate global sym .plt and .got entries, and space for global
|
|---|
| 1978 | sym dynamic relocs. */
|
|---|
| 1979 | elf_link_hash_traverse (&htab->elf, allocate_dynrelocs, (PTR) info);
|
|---|
| 1980 |
|
|---|
| 1981 | /* We now have determined the sizes of the various dynamic sections.
|
|---|
| 1982 | Allocate memory for them. */
|
|---|
| 1983 | relocs = FALSE;
|
|---|
| 1984 | for (s = dynobj->sections; s != NULL; s = s->next)
|
|---|
| 1985 | {
|
|---|
| 1986 | if ((s->flags & SEC_LINKER_CREATED) == 0)
|
|---|
| 1987 | continue;
|
|---|
| 1988 |
|
|---|
| 1989 | if (s == htab->splt
|
|---|
| 1990 | || s == htab->sgot
|
|---|
| 1991 | || s == htab->sgotplt)
|
|---|
| 1992 | {
|
|---|
| 1993 | /* Strip this section if we don't need it; see the
|
|---|
| 1994 | comment below. */
|
|---|
| 1995 | }
|
|---|
| 1996 | else if (strncmp (bfd_get_section_name (dynobj, s), ".rela", 5) == 0)
|
|---|
| 1997 | {
|
|---|
| 1998 | if (s->_raw_size != 0 && s != htab->srelplt)
|
|---|
| 1999 | relocs = TRUE;
|
|---|
| 2000 |
|
|---|
| 2001 | /* We use the reloc_count field as a counter if we need
|
|---|
| 2002 | to copy relocs into the output file. */
|
|---|
| 2003 | s->reloc_count = 0;
|
|---|
| 2004 | }
|
|---|
| 2005 | else
|
|---|
| 2006 | {
|
|---|
| 2007 | /* It's not one of our sections, so don't allocate space. */
|
|---|
| 2008 | continue;
|
|---|
| 2009 | }
|
|---|
| 2010 |
|
|---|
| 2011 | if (s->_raw_size == 0)
|
|---|
| 2012 | {
|
|---|
| 2013 | /* If we don't need this section, strip it from the
|
|---|
| 2014 | output file. This is to handle .rela.bss and
|
|---|
| 2015 | .rela.plt. We must create it in
|
|---|
| 2016 | create_dynamic_sections, because it must be created
|
|---|
| 2017 | before the linker maps input sections to output
|
|---|
| 2018 | sections. The linker does that before
|
|---|
| 2019 | adjust_dynamic_symbol is called, and it is that
|
|---|
| 2020 | function which decides whether anything needs to go
|
|---|
| 2021 | into these sections. */
|
|---|
| 2022 |
|
|---|
| 2023 | _bfd_strip_section_from_output (info, s);
|
|---|
| 2024 | continue;
|
|---|
| 2025 | }
|
|---|
| 2026 |
|
|---|
| 2027 | /* Allocate memory for the section contents. We use bfd_zalloc
|
|---|
| 2028 | here in case unused entries are not reclaimed before the
|
|---|
| 2029 | section's contents are written out. This should not happen,
|
|---|
| 2030 | but this way if it does, we get a R_390_NONE reloc instead
|
|---|
| 2031 | of garbage. */
|
|---|
| 2032 | s->contents = (bfd_byte *) bfd_zalloc (dynobj, s->_raw_size);
|
|---|
| 2033 | if (s->contents == NULL)
|
|---|
| 2034 | return FALSE;
|
|---|
| 2035 | }
|
|---|
| 2036 |
|
|---|
| 2037 | if (htab->elf.dynamic_sections_created)
|
|---|
| 2038 | {
|
|---|
| 2039 | /* Add some entries to the .dynamic section. We fill in the
|
|---|
| 2040 | values later, in elf_s390_finish_dynamic_sections, but we
|
|---|
| 2041 | must add the entries now so that we get the correct size for
|
|---|
| 2042 | the .dynamic section. The DT_DEBUG entry is filled in by the
|
|---|
| 2043 | dynamic linker and used by the debugger. */
|
|---|
| 2044 | #define add_dynamic_entry(TAG, VAL) \
|
|---|
| 2045 | bfd_elf64_add_dynamic_entry (info, (bfd_vma) (TAG), (bfd_vma) (VAL))
|
|---|
| 2046 |
|
|---|
| 2047 | if (! info->shared)
|
|---|
| 2048 | {
|
|---|
| 2049 | if (!add_dynamic_entry (DT_DEBUG, 0))
|
|---|
| 2050 | return FALSE;
|
|---|
| 2051 | }
|
|---|
| 2052 |
|
|---|
| 2053 | if (htab->splt->_raw_size != 0)
|
|---|
| 2054 | {
|
|---|
| 2055 | if (!add_dynamic_entry (DT_PLTGOT, 0)
|
|---|
| 2056 | || !add_dynamic_entry (DT_PLTRELSZ, 0)
|
|---|
| 2057 | || !add_dynamic_entry (DT_PLTREL, DT_RELA)
|
|---|
| 2058 | || !add_dynamic_entry (DT_JMPREL, 0))
|
|---|
| 2059 | return FALSE;
|
|---|
| 2060 | }
|
|---|
| 2061 |
|
|---|
| 2062 | if (relocs)
|
|---|
| 2063 | {
|
|---|
| 2064 | if (!add_dynamic_entry (DT_RELA, 0)
|
|---|
| 2065 | || !add_dynamic_entry (DT_RELASZ, 0)
|
|---|
| 2066 | || !add_dynamic_entry (DT_RELAENT, sizeof (Elf64_External_Rela)))
|
|---|
| 2067 | return FALSE;
|
|---|
| 2068 |
|
|---|
| 2069 | /* If any dynamic relocs apply to a read-only section,
|
|---|
| 2070 | then we need a DT_TEXTREL entry. */
|
|---|
| 2071 | if ((info->flags & DF_TEXTREL) == 0)
|
|---|
| 2072 | elf_link_hash_traverse (&htab->elf, readonly_dynrelocs,
|
|---|
| 2073 | (PTR) info);
|
|---|
| 2074 |
|
|---|
| 2075 | if ((info->flags & DF_TEXTREL) != 0)
|
|---|
| 2076 | {
|
|---|
| 2077 | if (!add_dynamic_entry (DT_TEXTREL, 0))
|
|---|
| 2078 | return FALSE;
|
|---|
| 2079 | }
|
|---|
| 2080 | }
|
|---|
| 2081 | }
|
|---|
| 2082 | #undef add_dynamic_entry
|
|---|
| 2083 |
|
|---|
| 2084 | return TRUE;
|
|---|
| 2085 | }
|
|---|
| 2086 |
|
|---|
| 2087 | /* Return the base VMA address which should be subtracted from real addresses
|
|---|
| 2088 | when resolving @dtpoff relocation.
|
|---|
| 2089 | This is PT_TLS segment p_vaddr. */
|
|---|
| 2090 |
|
|---|
| 2091 | static bfd_vma
|
|---|
| 2092 | dtpoff_base (info)
|
|---|
| 2093 | struct bfd_link_info *info;
|
|---|
| 2094 | {
|
|---|
| 2095 | /* If tls_segment is NULL, we should have signalled an error already. */
|
|---|
| 2096 | if (elf_hash_table (info)->tls_segment == NULL)
|
|---|
| 2097 | return 0;
|
|---|
| 2098 | return elf_hash_table (info)->tls_segment->start;
|
|---|
| 2099 | }
|
|---|
| 2100 |
|
|---|
| 2101 | /* Return the relocation value for @tpoff relocation
|
|---|
| 2102 | if STT_TLS virtual address is ADDRESS. */
|
|---|
| 2103 |
|
|---|
| 2104 | static bfd_vma
|
|---|
| 2105 | tpoff (info, address)
|
|---|
| 2106 | struct bfd_link_info *info;
|
|---|
| 2107 | bfd_vma address;
|
|---|
| 2108 | {
|
|---|
| 2109 | struct elf_link_tls_segment *tls_segment
|
|---|
| 2110 | = elf_hash_table (info)->tls_segment;
|
|---|
| 2111 |
|
|---|
| 2112 | /* If tls_segment is NULL, we should have signalled an error already. */
|
|---|
| 2113 | if (tls_segment == NULL)
|
|---|
| 2114 | return 0;
|
|---|
| 2115 | return (align_power (tls_segment->size, tls_segment->align)
|
|---|
| 2116 | + tls_segment->start - address);
|
|---|
| 2117 | }
|
|---|
| 2118 |
|
|---|
| 2119 | /* Complain if TLS instruction relocation is against an invalid
|
|---|
| 2120 | instruction. */
|
|---|
| 2121 |
|
|---|
| 2122 | static void
|
|---|
| 2123 | invalid_tls_insn (input_bfd, input_section, rel)
|
|---|
| 2124 | bfd *input_bfd;
|
|---|
| 2125 | asection *input_section;
|
|---|
| 2126 | Elf_Internal_Rela *rel;
|
|---|
| 2127 | {
|
|---|
| 2128 | reloc_howto_type *howto;
|
|---|
| 2129 |
|
|---|
| 2130 | howto = elf_howto_table + ELF64_R_TYPE (rel->r_info);
|
|---|
| 2131 | (*_bfd_error_handler)
|
|---|
| 2132 | (_("%s(%s+0x%lx): invalid instruction for TLS relocation %s"),
|
|---|
| 2133 | bfd_archive_filename (input_bfd),
|
|---|
| 2134 | bfd_get_section_name (input_bfd, input_section),
|
|---|
| 2135 | (long) rel->r_offset,
|
|---|
| 2136 | howto->name);
|
|---|
| 2137 | }
|
|---|
| 2138 |
|
|---|
| 2139 | /* Relocate a 390 ELF section. */
|
|---|
| 2140 |
|
|---|
| 2141 | static bfd_boolean
|
|---|
| 2142 | elf_s390_relocate_section (output_bfd, info, input_bfd, input_section,
|
|---|
| 2143 | contents, relocs, local_syms, local_sections)
|
|---|
| 2144 | bfd *output_bfd;
|
|---|
| 2145 | struct bfd_link_info *info;
|
|---|
| 2146 | bfd *input_bfd;
|
|---|
| 2147 | asection *input_section;
|
|---|
| 2148 | bfd_byte *contents;
|
|---|
| 2149 | Elf_Internal_Rela *relocs;
|
|---|
| 2150 | Elf_Internal_Sym *local_syms;
|
|---|
| 2151 | asection **local_sections;
|
|---|
| 2152 | {
|
|---|
| 2153 | struct elf_s390_link_hash_table *htab;
|
|---|
| 2154 | Elf_Internal_Shdr *symtab_hdr;
|
|---|
| 2155 | struct elf_link_hash_entry **sym_hashes;
|
|---|
| 2156 | bfd_vma *local_got_offsets;
|
|---|
| 2157 | Elf_Internal_Rela *rel;
|
|---|
| 2158 | Elf_Internal_Rela *relend;
|
|---|
| 2159 |
|
|---|
| 2160 | if (info->relocateable)
|
|---|
| 2161 | return TRUE;
|
|---|
| 2162 |
|
|---|
| 2163 | htab = elf_s390_hash_table (info);
|
|---|
| 2164 | symtab_hdr = &elf_tdata (input_bfd)->symtab_hdr;
|
|---|
| 2165 | sym_hashes = elf_sym_hashes (input_bfd);
|
|---|
| 2166 | local_got_offsets = elf_local_got_offsets (input_bfd);
|
|---|
| 2167 |
|
|---|
| 2168 | rel = relocs;
|
|---|
| 2169 | relend = relocs + input_section->reloc_count;
|
|---|
| 2170 | for (; rel < relend; rel++)
|
|---|
| 2171 | {
|
|---|
| 2172 | unsigned int r_type;
|
|---|
| 2173 | reloc_howto_type *howto;
|
|---|
| 2174 | unsigned long r_symndx;
|
|---|
| 2175 | struct elf_link_hash_entry *h;
|
|---|
| 2176 | Elf_Internal_Sym *sym;
|
|---|
| 2177 | asection *sec;
|
|---|
| 2178 | bfd_vma off;
|
|---|
| 2179 | bfd_vma relocation;
|
|---|
| 2180 | bfd_boolean unresolved_reloc;
|
|---|
| 2181 | bfd_reloc_status_type r;
|
|---|
| 2182 | int tls_type;
|
|---|
| 2183 |
|
|---|
| 2184 | r_type = ELF64_R_TYPE (rel->r_info);
|
|---|
| 2185 | if (r_type == (int) R_390_GNU_VTINHERIT
|
|---|
| 2186 | || r_type == (int) R_390_GNU_VTENTRY)
|
|---|
| 2187 | continue;
|
|---|
| 2188 | if (r_type >= (int) R_390_max)
|
|---|
| 2189 | {
|
|---|
| 2190 | bfd_set_error (bfd_error_bad_value);
|
|---|
| 2191 | return FALSE;
|
|---|
| 2192 | }
|
|---|
| 2193 |
|
|---|
| 2194 | howto = elf_howto_table + r_type;
|
|---|
| 2195 | r_symndx = ELF64_R_SYM (rel->r_info);
|
|---|
| 2196 |
|
|---|
| 2197 | /* This is a final link. */
|
|---|
| 2198 | h = NULL;
|
|---|
| 2199 | sym = NULL;
|
|---|
| 2200 | sec = NULL;
|
|---|
| 2201 | unresolved_reloc = FALSE;
|
|---|
| 2202 | if (r_symndx < symtab_hdr->sh_info)
|
|---|
| 2203 | {
|
|---|
| 2204 | sym = local_syms + r_symndx;
|
|---|
| 2205 | sec = local_sections[r_symndx];
|
|---|
| 2206 | relocation = _bfd_elf_rela_local_sym (output_bfd, sym, sec, rel);
|
|---|
| 2207 | }
|
|---|
| 2208 | else
|
|---|
| 2209 | {
|
|---|
| 2210 | h = sym_hashes[r_symndx - symtab_hdr->sh_info];
|
|---|
| 2211 | while (h->root.type == bfd_link_hash_indirect
|
|---|
| 2212 | || h->root.type == bfd_link_hash_warning)
|
|---|
| 2213 | h = (struct elf_link_hash_entry *) h->root.u.i.link;
|
|---|
| 2214 |
|
|---|
| 2215 | if (h->root.type == bfd_link_hash_defined
|
|---|
| 2216 | || h->root.type == bfd_link_hash_defweak)
|
|---|
| 2217 | {
|
|---|
| 2218 | sec = h->root.u.def.section;
|
|---|
| 2219 | if (sec->output_section == NULL)
|
|---|
| 2220 | {
|
|---|
| 2221 | /* Set a flag that will be cleared later if we find a
|
|---|
| 2222 | relocation value for this symbol. output_section
|
|---|
| 2223 | is typically NULL for symbols satisfied by a shared
|
|---|
| 2224 | library. */
|
|---|
| 2225 | unresolved_reloc = TRUE;
|
|---|
| 2226 | relocation = 0;
|
|---|
| 2227 | }
|
|---|
| 2228 | else
|
|---|
| 2229 | relocation = (h->root.u.def.value
|
|---|
| 2230 | + sec->output_section->vma
|
|---|
| 2231 | + sec->output_offset);
|
|---|
| 2232 | }
|
|---|
| 2233 | else if (h->root.type == bfd_link_hash_undefweak)
|
|---|
| 2234 | relocation = 0;
|
|---|
| 2235 | else if (info->shared
|
|---|
| 2236 | && !info->no_undefined
|
|---|
| 2237 | && ELF_ST_VISIBILITY (h->other) == STV_DEFAULT)
|
|---|
| 2238 | relocation = 0;
|
|---|
| 2239 | else
|
|---|
| 2240 | {
|
|---|
| 2241 | if (! ((*info->callbacks->undefined_symbol)
|
|---|
| 2242 | (info, h->root.root.string, input_bfd,
|
|---|
| 2243 | input_section, rel->r_offset,
|
|---|
| 2244 | (!info->shared || info->no_undefined
|
|---|
| 2245 | || ELF_ST_VISIBILITY (h->other)))))
|
|---|
| 2246 | return FALSE;
|
|---|
| 2247 | relocation = 0;
|
|---|
| 2248 | }
|
|---|
| 2249 | }
|
|---|
| 2250 |
|
|---|
| 2251 | switch (r_type)
|
|---|
| 2252 | {
|
|---|
| 2253 | case R_390_GOTPLT12:
|
|---|
| 2254 | case R_390_GOTPLT16:
|
|---|
| 2255 | case R_390_GOTPLT32:
|
|---|
| 2256 | case R_390_GOTPLT64:
|
|---|
| 2257 | case R_390_GOTPLTENT:
|
|---|
| 2258 | /* There are three cases for a GOTPLT relocation. 1) The
|
|---|
| 2259 | relocation is against the jump slot entry of a plt that
|
|---|
| 2260 | will get emitted to the output file. 2) The relocation
|
|---|
| 2261 | is against the jump slot of a plt entry that has been
|
|---|
| 2262 | removed. elf_s390_adjust_gotplt has created a GOT entry
|
|---|
| 2263 | as replacement. 3) The relocation is against a local symbol.
|
|---|
| 2264 | Cases 2) and 3) are the same as the GOT relocation code
|
|---|
| 2265 | so we just have to test for case 1 and fall through for
|
|---|
| 2266 | the other two. */
|
|---|
| 2267 | if (h != NULL && h->plt.offset != (bfd_vma) -1)
|
|---|
| 2268 | {
|
|---|
| 2269 | bfd_vma plt_index;
|
|---|
| 2270 |
|
|---|
| 2271 | /* Calc. index no.
|
|---|
| 2272 | Current offset - size first entry / entry size. */
|
|---|
| 2273 | plt_index = (h->plt.offset - PLT_FIRST_ENTRY_SIZE) /
|
|---|
| 2274 | PLT_ENTRY_SIZE;
|
|---|
| 2275 |
|
|---|
| 2276 | /* Offset in GOT is PLT index plus GOT headers(3) times 4,
|
|---|
| 2277 | addr & GOT addr. */
|
|---|
| 2278 | relocation = (plt_index + 3) * GOT_ENTRY_SIZE;
|
|---|
| 2279 | unresolved_reloc = FALSE;
|
|---|
| 2280 |
|
|---|
| 2281 | if (r_type == R_390_GOTPLTENT)
|
|---|
| 2282 | relocation += htab->sgot->output_section->vma;
|
|---|
| 2283 | break;
|
|---|
| 2284 | }
|
|---|
| 2285 | /* Fall through. */
|
|---|
| 2286 |
|
|---|
| 2287 | case R_390_GOT12:
|
|---|
| 2288 | case R_390_GOT16:
|
|---|
| 2289 | case R_390_GOT32:
|
|---|
| 2290 | case R_390_GOT64:
|
|---|
| 2291 | case R_390_GOTENT:
|
|---|
| 2292 | /* Relocation is to the entry for this symbol in the global
|
|---|
| 2293 | offset table. */
|
|---|
| 2294 | if (htab->sgot == NULL)
|
|---|
| 2295 | abort ();
|
|---|
| 2296 |
|
|---|
| 2297 | if (h != NULL)
|
|---|
| 2298 | {
|
|---|
| 2299 | bfd_boolean dyn;
|
|---|
| 2300 |
|
|---|
| 2301 | off = h->got.offset;
|
|---|
| 2302 | dyn = htab->elf.dynamic_sections_created;
|
|---|
| 2303 | if (! WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn, info, h)
|
|---|
| 2304 | || (info->shared
|
|---|
| 2305 | && (info->symbolic
|
|---|
| 2306 | || h->dynindx == -1
|
|---|
| 2307 | || (h->elf_link_hash_flags & ELF_LINK_FORCED_LOCAL))
|
|---|
| 2308 | && (h->elf_link_hash_flags & ELF_LINK_HASH_DEF_REGULAR)))
|
|---|
| 2309 | {
|
|---|
| 2310 | /* This is actually a static link, or it is a
|
|---|
| 2311 | -Bsymbolic link and the symbol is defined
|
|---|
| 2312 | locally, or the symbol was forced to be local
|
|---|
| 2313 | because of a version file. We must initialize
|
|---|
| 2314 | this entry in the global offset table. Since the
|
|---|
| 2315 | offset must always be a multiple of 2, we use the
|
|---|
| 2316 | least significant bit to record whether we have
|
|---|
| 2317 | initialized it already.
|
|---|
| 2318 |
|
|---|
| 2319 | When doing a dynamic link, we create a .rel.got
|
|---|
| 2320 | relocation entry to initialize the value. This
|
|---|
| 2321 | is done in the finish_dynamic_symbol routine. */
|
|---|
| 2322 | if ((off & 1) != 0)
|
|---|
| 2323 | off &= ~1;
|
|---|
| 2324 | else
|
|---|
| 2325 | {
|
|---|
| 2326 | bfd_put_64 (output_bfd, relocation,
|
|---|
| 2327 | htab->sgot->contents + off);
|
|---|
| 2328 | h->got.offset |= 1;
|
|---|
| 2329 | }
|
|---|
| 2330 | }
|
|---|
| 2331 | else
|
|---|
| 2332 | unresolved_reloc = FALSE;
|
|---|
| 2333 | }
|
|---|
| 2334 | else
|
|---|
| 2335 | {
|
|---|
| 2336 | if (local_got_offsets == NULL)
|
|---|
| 2337 | abort ();
|
|---|
| 2338 |
|
|---|
| 2339 | off = local_got_offsets[r_symndx];
|
|---|
| 2340 |
|
|---|
| 2341 | /* The offset must always be a multiple of 8. We use
|
|---|
| 2342 | the least significant bit to record whether we have
|
|---|
| 2343 | already generated the necessary reloc. */
|
|---|
| 2344 | if ((off & 1) != 0)
|
|---|
| 2345 | off &= ~1;
|
|---|
| 2346 | else
|
|---|
| 2347 | {
|
|---|
| 2348 | bfd_put_64 (output_bfd, relocation,
|
|---|
| 2349 | htab->sgot->contents + off);
|
|---|
| 2350 |
|
|---|
| 2351 | if (info->shared)
|
|---|
| 2352 | {
|
|---|
| 2353 | asection *s;
|
|---|
| 2354 | Elf_Internal_Rela outrel;
|
|---|
| 2355 | bfd_byte *loc;
|
|---|
| 2356 |
|
|---|
| 2357 | s = htab->srelgot;
|
|---|
| 2358 | if (s == NULL)
|
|---|
| 2359 | abort ();
|
|---|
| 2360 |
|
|---|
| 2361 | outrel.r_offset = (htab->sgot->output_section->vma
|
|---|
| 2362 | + htab->sgot->output_offset
|
|---|
| 2363 | + off);
|
|---|
| 2364 | outrel.r_info = ELF64_R_INFO (0, R_390_RELATIVE);
|
|---|
| 2365 | outrel.r_addend = relocation;
|
|---|
| 2366 | loc = s->contents;
|
|---|
| 2367 | loc += s->reloc_count++ * sizeof (Elf64_External_Rela);
|
|---|
| 2368 | bfd_elf64_swap_reloca_out (output_bfd, &outrel, loc);
|
|---|
| 2369 | }
|
|---|
| 2370 |
|
|---|
| 2371 | local_got_offsets[r_symndx] |= 1;
|
|---|
| 2372 | }
|
|---|
| 2373 | }
|
|---|
| 2374 |
|
|---|
| 2375 | if (off >= (bfd_vma) -2)
|
|---|
| 2376 | abort ();
|
|---|
| 2377 |
|
|---|
| 2378 | relocation = htab->sgot->output_offset + off;
|
|---|
| 2379 |
|
|---|
| 2380 | /* For @GOTENT the relocation is against the offset between
|
|---|
| 2381 | the instruction and the symbols entry in the GOT and not
|
|---|
| 2382 | between the start of the GOT and the symbols entry. We
|
|---|
| 2383 | add the vma of the GOT to get the correct value. */
|
|---|
| 2384 | if ( r_type == R_390_GOTENT
|
|---|
| 2385 | || r_type == R_390_GOTPLTENT)
|
|---|
| 2386 | relocation += htab->sgot->output_section->vma;
|
|---|
| 2387 |
|
|---|
| 2388 | break;
|
|---|
| 2389 |
|
|---|
| 2390 | case R_390_GOTOFF16:
|
|---|
| 2391 | case R_390_GOTOFF32:
|
|---|
| 2392 | case R_390_GOTOFF64:
|
|---|
| 2393 | /* Relocation is relative to the start of the global offset
|
|---|
| 2394 | table. */
|
|---|
| 2395 |
|
|---|
| 2396 | /* Note that sgot->output_offset is not involved in this
|
|---|
| 2397 | calculation. We always want the start of .got. If we
|
|---|
| 2398 | defined _GLOBAL_OFFSET_TABLE in a different way, as is
|
|---|
| 2399 | permitted by the ABI, we might have to change this
|
|---|
| 2400 | calculation. */
|
|---|
| 2401 | relocation -= htab->sgot->output_section->vma;
|
|---|
| 2402 | break;
|
|---|
| 2403 |
|
|---|
| 2404 | case R_390_GOTPC:
|
|---|
| 2405 | case R_390_GOTPCDBL:
|
|---|
| 2406 | /* Use global offset table as symbol value. */
|
|---|
| 2407 | relocation = htab->sgot->output_section->vma;
|
|---|
| 2408 | unresolved_reloc = FALSE;
|
|---|
| 2409 | break;
|
|---|
| 2410 |
|
|---|
| 2411 | case R_390_PLT16DBL:
|
|---|
| 2412 | case R_390_PLT32:
|
|---|
| 2413 | case R_390_PLT32DBL:
|
|---|
| 2414 | case R_390_PLT64:
|
|---|
| 2415 | /* Relocation is to the entry for this symbol in the
|
|---|
| 2416 | procedure linkage table. */
|
|---|
| 2417 |
|
|---|
| 2418 | /* Resolve a PLT32 reloc against a local symbol directly,
|
|---|
| 2419 | without using the procedure linkage table. */
|
|---|
| 2420 | if (h == NULL)
|
|---|
| 2421 | break;
|
|---|
| 2422 |
|
|---|
| 2423 | if (h->plt.offset == (bfd_vma) -1
|
|---|
| 2424 | || htab->splt == NULL)
|
|---|
| 2425 | {
|
|---|
| 2426 | /* We didn't make a PLT entry for this symbol. This
|
|---|
| 2427 | happens when statically linking PIC code, or when
|
|---|
| 2428 | using -Bsymbolic. */
|
|---|
| 2429 | break;
|
|---|
| 2430 | }
|
|---|
| 2431 |
|
|---|
| 2432 | relocation = (htab->splt->output_section->vma
|
|---|
| 2433 | + htab->splt->output_offset
|
|---|
| 2434 | + h->plt.offset);
|
|---|
| 2435 | unresolved_reloc = FALSE;
|
|---|
| 2436 | break;
|
|---|
| 2437 |
|
|---|
| 2438 | case R_390_PLTOFF16:
|
|---|
| 2439 | case R_390_PLTOFF32:
|
|---|
| 2440 | case R_390_PLTOFF64:
|
|---|
| 2441 | /* Relocation is to the entry for this symbol in the
|
|---|
| 2442 | procedure linkage table relative to the start of the GOT. */
|
|---|
| 2443 |
|
|---|
| 2444 | /* For local symbols or if we didn't make a PLT entry for
|
|---|
| 2445 | this symbol resolve the symbol directly. */
|
|---|
| 2446 | if ( h == NULL
|
|---|
| 2447 | || h->plt.offset == (bfd_vma) -1
|
|---|
| 2448 | || htab->splt == NULL)
|
|---|
| 2449 | {
|
|---|
| 2450 | relocation -= htab->sgot->output_section->vma;
|
|---|
| 2451 | break;
|
|---|
| 2452 | }
|
|---|
| 2453 |
|
|---|
| 2454 | relocation = (htab->splt->output_section->vma
|
|---|
| 2455 | + htab->splt->output_offset
|
|---|
| 2456 | + h->plt.offset
|
|---|
| 2457 | - htab->sgot->output_section->vma);
|
|---|
| 2458 | unresolved_reloc = FALSE;
|
|---|
| 2459 | break;
|
|---|
| 2460 |
|
|---|
| 2461 | case R_390_8:
|
|---|
| 2462 | case R_390_16:
|
|---|
| 2463 | case R_390_32:
|
|---|
| 2464 | case R_390_64:
|
|---|
| 2465 | case R_390_PC16:
|
|---|
| 2466 | case R_390_PC16DBL:
|
|---|
| 2467 | case R_390_PC32:
|
|---|
| 2468 | case R_390_PC32DBL:
|
|---|
| 2469 | case R_390_PC64:
|
|---|
| 2470 | /* r_symndx will be zero only for relocs against symbols
|
|---|
| 2471 | from removed linkonce sections, or sections discarded by
|
|---|
| 2472 | a linker script. */
|
|---|
| 2473 | if (r_symndx == 0
|
|---|
| 2474 | || (input_section->flags & SEC_ALLOC) == 0)
|
|---|
| 2475 | break;
|
|---|
| 2476 |
|
|---|
| 2477 | if ((info->shared
|
|---|
| 2478 | && ((r_type != R_390_PC16
|
|---|
| 2479 | && r_type != R_390_PC16DBL
|
|---|
| 2480 | && r_type != R_390_PC32
|
|---|
| 2481 | && r_type != R_390_PC32DBL
|
|---|
| 2482 | && r_type != R_390_PC64)
|
|---|
| 2483 | || (h != NULL
|
|---|
| 2484 | && h->dynindx != -1
|
|---|
| 2485 | && (! info->symbolic
|
|---|
| 2486 | || (h->elf_link_hash_flags
|
|---|
| 2487 | & ELF_LINK_HASH_DEF_REGULAR) == 0))))
|
|---|
| 2488 | || (ELIMINATE_COPY_RELOCS
|
|---|
| 2489 | && !info->shared
|
|---|
| 2490 | && h != NULL
|
|---|
| 2491 | && h->dynindx != -1
|
|---|
| 2492 | && (h->elf_link_hash_flags & ELF_LINK_NON_GOT_REF) == 0
|
|---|
| 2493 | && (((h->elf_link_hash_flags
|
|---|
| 2494 | & ELF_LINK_HASH_DEF_DYNAMIC) != 0
|
|---|
| 2495 | && (h->elf_link_hash_flags
|
|---|
| 2496 | & ELF_LINK_HASH_DEF_REGULAR) == 0)
|
|---|
| 2497 | || h->root.type == bfd_link_hash_undefweak
|
|---|
| 2498 | || h->root.type == bfd_link_hash_undefined)))
|
|---|
| 2499 | {
|
|---|
| 2500 | Elf_Internal_Rela outrel;
|
|---|
| 2501 | bfd_boolean skip, relocate;
|
|---|
| 2502 | asection *sreloc;
|
|---|
| 2503 | bfd_byte *loc;
|
|---|
| 2504 |
|
|---|
| 2505 | /* When generating a shared object, these relocations
|
|---|
| 2506 | are copied into the output file to be resolved at run
|
|---|
| 2507 | time. */
|
|---|
| 2508 | skip = FALSE;
|
|---|
| 2509 | relocate = FALSE;
|
|---|
| 2510 |
|
|---|
| 2511 | outrel.r_offset =
|
|---|
| 2512 | _bfd_elf_section_offset (output_bfd, info, input_section,
|
|---|
| 2513 | rel->r_offset);
|
|---|
| 2514 | if (outrel.r_offset == (bfd_vma) -1)
|
|---|
| 2515 | skip = TRUE;
|
|---|
| 2516 | else if (outrel.r_offset == (bfd_vma) -2)
|
|---|
| 2517 | skip = TRUE, relocate = TRUE;
|
|---|
| 2518 |
|
|---|
| 2519 | outrel.r_offset += (input_section->output_section->vma
|
|---|
| 2520 | + input_section->output_offset);
|
|---|
| 2521 |
|
|---|
| 2522 | if (skip)
|
|---|
| 2523 | memset (&outrel, 0, sizeof outrel);
|
|---|
| 2524 | else if (h != NULL
|
|---|
| 2525 | && h->dynindx != -1
|
|---|
| 2526 | && (r_type == R_390_PC16
|
|---|
| 2527 | || r_type == R_390_PC16DBL
|
|---|
| 2528 | || r_type == R_390_PC32
|
|---|
| 2529 | || r_type == R_390_PC32DBL
|
|---|
| 2530 | || r_type == R_390_PC64
|
|---|
| 2531 | || !info->shared
|
|---|
| 2532 | || !info->symbolic
|
|---|
| 2533 | || (h->elf_link_hash_flags
|
|---|
| 2534 | & ELF_LINK_HASH_DEF_REGULAR) == 0))
|
|---|
| 2535 | {
|
|---|
| 2536 | outrel.r_info = ELF64_R_INFO (h->dynindx, r_type);
|
|---|
| 2537 | outrel.r_addend = rel->r_addend;
|
|---|
| 2538 | }
|
|---|
| 2539 | else
|
|---|
| 2540 | {
|
|---|
| 2541 | /* This symbol is local, or marked to become local. */
|
|---|
| 2542 | relocate = TRUE;
|
|---|
| 2543 | outrel.r_info = ELF64_R_INFO (0, R_390_RELATIVE);
|
|---|
| 2544 | outrel.r_addend = relocation + rel->r_addend;
|
|---|
| 2545 | }
|
|---|
| 2546 |
|
|---|
| 2547 | sreloc = elf_section_data (input_section)->sreloc;
|
|---|
| 2548 | if (sreloc == NULL)
|
|---|
| 2549 | abort ();
|
|---|
| 2550 |
|
|---|
| 2551 | loc = sreloc->contents;
|
|---|
| 2552 | loc += sreloc->reloc_count++ * sizeof (Elf64_External_Rela);
|
|---|
| 2553 | bfd_elf64_swap_reloca_out (output_bfd, &outrel, loc);
|
|---|
| 2554 |
|
|---|
| 2555 | /* If this reloc is against an external symbol, we do
|
|---|
| 2556 | not want to fiddle with the addend. Otherwise, we
|
|---|
| 2557 | need to include the symbol value so that it becomes
|
|---|
| 2558 | an addend for the dynamic reloc. */
|
|---|
| 2559 | if (! relocate)
|
|---|
| 2560 | continue;
|
|---|
| 2561 | }
|
|---|
| 2562 |
|
|---|
| 2563 | break;
|
|---|
| 2564 |
|
|---|
| 2565 | /* Relocations for tls literal pool entries. */
|
|---|
| 2566 | case R_390_TLS_IE64:
|
|---|
| 2567 | if (info->shared)
|
|---|
| 2568 | {
|
|---|
| 2569 | Elf_Internal_Rela outrel;
|
|---|
| 2570 | asection *sreloc;
|
|---|
| 2571 | bfd_byte *loc;
|
|---|
| 2572 |
|
|---|
| 2573 | outrel.r_offset = rel->r_offset
|
|---|
| 2574 | + input_section->output_section->vma
|
|---|
| 2575 | + input_section->output_offset;
|
|---|
| 2576 | outrel.r_info = ELF64_R_INFO (0, R_390_RELATIVE);
|
|---|
| 2577 | sreloc = elf_section_data (input_section)->sreloc;
|
|---|
| 2578 | if (sreloc == NULL)
|
|---|
| 2579 | abort ();
|
|---|
| 2580 | loc = sreloc->contents;
|
|---|
| 2581 | loc += sreloc->reloc_count++ * sizeof (Elf64_External_Rela);
|
|---|
| 2582 | bfd_elf64_swap_reloc_out (output_bfd, &outrel, loc);
|
|---|
| 2583 | }
|
|---|
| 2584 | /* Fall through. */
|
|---|
| 2585 |
|
|---|
| 2586 | case R_390_TLS_GD64:
|
|---|
| 2587 | case R_390_TLS_GOTIE64:
|
|---|
| 2588 | r_type = elf_s390_tls_transition (info, r_type, h == NULL);
|
|---|
| 2589 | tls_type = GOT_UNKNOWN;
|
|---|
| 2590 | if (h == NULL && local_got_offsets)
|
|---|
| 2591 | tls_type = elf_s390_local_got_tls_type (input_bfd) [r_symndx];
|
|---|
| 2592 | else if (h != NULL)
|
|---|
| 2593 | {
|
|---|
| 2594 | tls_type = elf_s390_hash_entry(h)->tls_type;
|
|---|
| 2595 | if (!info->shared && h->dynindx == -1 && tls_type >= GOT_TLS_IE)
|
|---|
| 2596 | r_type = R_390_TLS_LE64;
|
|---|
| 2597 | }
|
|---|
| 2598 | if (r_type == R_390_TLS_GD64 && tls_type >= GOT_TLS_IE)
|
|---|
| 2599 | r_type = R_390_TLS_IE64;
|
|---|
| 2600 |
|
|---|
| 2601 | if (r_type == R_390_TLS_LE64)
|
|---|
| 2602 | {
|
|---|
| 2603 | /* This relocation gets optimized away by the local exec
|
|---|
| 2604 | access optimization. */
|
|---|
| 2605 | BFD_ASSERT (! unresolved_reloc);
|
|---|
| 2606 | bfd_put_64 (output_bfd, -tpoff (info, relocation),
|
|---|
| 2607 | contents + rel->r_offset);
|
|---|
| 2608 | continue;
|
|---|
| 2609 | }
|
|---|
| 2610 |
|
|---|
| 2611 | if (htab->sgot == NULL)
|
|---|
| 2612 | abort ();
|
|---|
| 2613 |
|
|---|
| 2614 | if (h != NULL)
|
|---|
| 2615 | off = h->got.offset;
|
|---|
| 2616 | else
|
|---|
| 2617 | {
|
|---|
| 2618 | if (local_got_offsets == NULL)
|
|---|
| 2619 | abort ();
|
|---|
| 2620 |
|
|---|
| 2621 | off = local_got_offsets[r_symndx];
|
|---|
| 2622 | }
|
|---|
| 2623 |
|
|---|
| 2624 | emit_tls_relocs:
|
|---|
| 2625 |
|
|---|
| 2626 | if ((off & 1) != 0)
|
|---|
| 2627 | off &= ~1;
|
|---|
| 2628 | else
|
|---|
| 2629 | {
|
|---|
| 2630 | Elf_Internal_Rela outrel;
|
|---|
| 2631 | bfd_byte *loc;
|
|---|
| 2632 | int dr_type, indx;
|
|---|
| 2633 |
|
|---|
| 2634 | if (htab->srelgot == NULL)
|
|---|
| 2635 | abort ();
|
|---|
| 2636 |
|
|---|
| 2637 | outrel.r_offset = (htab->sgot->output_section->vma
|
|---|
| 2638 | + htab->sgot->output_offset + off);
|
|---|
| 2639 |
|
|---|
| 2640 | indx = h && h->dynindx != -1 ? h->dynindx : 0;
|
|---|
| 2641 | if (r_type == R_390_TLS_GD64)
|
|---|
| 2642 | dr_type = R_390_TLS_DTPMOD;
|
|---|
| 2643 | else
|
|---|
| 2644 | dr_type = R_390_TLS_TPOFF;
|
|---|
| 2645 | if (dr_type == R_390_TLS_TPOFF && indx == 0)
|
|---|
| 2646 | outrel.r_addend = relocation - dtpoff_base (info);
|
|---|
| 2647 | else
|
|---|
| 2648 | outrel.r_addend = 0;
|
|---|
| 2649 | outrel.r_info = ELF64_R_INFO (indx, dr_type);
|
|---|
| 2650 | loc = htab->srelgot->contents;
|
|---|
| 2651 | loc += htab->srelgot->reloc_count++
|
|---|
| 2652 | * sizeof (Elf64_External_Rela);
|
|---|
| 2653 | bfd_elf64_swap_reloca_out (output_bfd, &outrel, loc);
|
|---|
| 2654 |
|
|---|
| 2655 | if (r_type == R_390_TLS_GD64)
|
|---|
| 2656 | {
|
|---|
| 2657 | if (indx == 0)
|
|---|
| 2658 | {
|
|---|
| 2659 | BFD_ASSERT (! unresolved_reloc);
|
|---|
| 2660 | bfd_put_64 (output_bfd,
|
|---|
| 2661 | relocation - dtpoff_base (info),
|
|---|
| 2662 | htab->sgot->contents + off + GOT_ENTRY_SIZE);
|
|---|
| 2663 | }
|
|---|
| 2664 | else
|
|---|
| 2665 | {
|
|---|
| 2666 | outrel.r_info = ELF64_R_INFO (indx, R_390_TLS_DTPOFF);
|
|---|
| 2667 | outrel.r_offset += GOT_ENTRY_SIZE;
|
|---|
| 2668 | outrel.r_addend = 0;
|
|---|
| 2669 | htab->srelgot->reloc_count++;
|
|---|
| 2670 | loc += sizeof (Elf64_External_Rela);
|
|---|
| 2671 | bfd_elf64_swap_reloca_out (output_bfd, &outrel, loc);
|
|---|
| 2672 | }
|
|---|
| 2673 | }
|
|---|
| 2674 |
|
|---|
| 2675 | if (h != NULL)
|
|---|
| 2676 | h->got.offset |= 1;
|
|---|
| 2677 | else
|
|---|
| 2678 | local_got_offsets[r_symndx] |= 1;
|
|---|
| 2679 | }
|
|---|
| 2680 |
|
|---|
| 2681 | if (off >= (bfd_vma) -2)
|
|---|
| 2682 | abort ();
|
|---|
| 2683 | if (r_type == ELF64_R_TYPE (rel->r_info))
|
|---|
| 2684 | {
|
|---|
| 2685 | relocation = htab->sgot->output_offset + off;
|
|---|
| 2686 | if (r_type == R_390_TLS_IE64 || r_type == R_390_TLS_IEENT)
|
|---|
| 2687 | relocation += htab->sgot->output_section->vma;
|
|---|
| 2688 | unresolved_reloc = FALSE;
|
|---|
| 2689 | }
|
|---|
| 2690 | else
|
|---|
| 2691 | {
|
|---|
| 2692 | bfd_put_64 (output_bfd, htab->sgot->output_offset + off,
|
|---|
| 2693 | contents + rel->r_offset);
|
|---|
| 2694 | continue;
|
|---|
| 2695 | }
|
|---|
| 2696 | break;
|
|---|
| 2697 |
|
|---|
| 2698 | case R_390_TLS_GOTIE12:
|
|---|
| 2699 | case R_390_TLS_IEENT:
|
|---|
| 2700 | if (h == NULL)
|
|---|
| 2701 | {
|
|---|
| 2702 | if (local_got_offsets == NULL)
|
|---|
| 2703 | abort();
|
|---|
| 2704 | off = local_got_offsets[r_symndx];
|
|---|
| 2705 | if (info->shared)
|
|---|
| 2706 | goto emit_tls_relocs;
|
|---|
| 2707 | }
|
|---|
| 2708 | else
|
|---|
| 2709 | {
|
|---|
| 2710 | off = h->got.offset;
|
|---|
| 2711 | tls_type = elf_s390_hash_entry(h)->tls_type;
|
|---|
| 2712 | if (info->shared || h->dynindx != -1 || tls_type < GOT_TLS_IE)
|
|---|
| 2713 | goto emit_tls_relocs;
|
|---|
| 2714 | }
|
|---|
| 2715 |
|
|---|
| 2716 | if (htab->sgot == NULL)
|
|---|
| 2717 | abort ();
|
|---|
| 2718 |
|
|---|
| 2719 | BFD_ASSERT (! unresolved_reloc);
|
|---|
| 2720 | bfd_put_64 (output_bfd, -tpoff (info, relocation),
|
|---|
| 2721 | htab->sgot->contents + off);
|
|---|
| 2722 | relocation = htab->sgot->output_offset + off;
|
|---|
| 2723 | if (r_type == R_390_TLS_IEENT)
|
|---|
| 2724 | relocation += htab->sgot->output_section->vma;
|
|---|
| 2725 | unresolved_reloc = FALSE;
|
|---|
| 2726 | break;
|
|---|
| 2727 |
|
|---|
| 2728 | case R_390_TLS_LDM64:
|
|---|
| 2729 | if (! info->shared)
|
|---|
| 2730 | /* The literal pool entry this relocation refers to gets ignored
|
|---|
| 2731 | by the optimized code of the local exec model. Do nothing
|
|---|
| 2732 | and the value will turn out zero. */
|
|---|
| 2733 | continue;
|
|---|
| 2734 |
|
|---|
| 2735 | if (htab->sgot == NULL)
|
|---|
| 2736 | abort ();
|
|---|
| 2737 |
|
|---|
| 2738 | off = htab->tls_ldm_got.offset;
|
|---|
| 2739 | if (off & 1)
|
|---|
| 2740 | off &= ~1;
|
|---|
| 2741 | else
|
|---|
| 2742 | {
|
|---|
| 2743 | Elf_Internal_Rela outrel;
|
|---|
| 2744 | bfd_byte *loc;
|
|---|
| 2745 |
|
|---|
| 2746 | if (htab->srelgot == NULL)
|
|---|
| 2747 | abort ();
|
|---|
| 2748 |
|
|---|
| 2749 | outrel.r_offset = (htab->sgot->output_section->vma
|
|---|
| 2750 | + htab->sgot->output_offset + off);
|
|---|
| 2751 |
|
|---|
| 2752 | bfd_put_64 (output_bfd, 0,
|
|---|
| 2753 | htab->sgot->contents + off + GOT_ENTRY_SIZE);
|
|---|
| 2754 | outrel.r_info = ELF64_R_INFO (0, R_390_TLS_DTPMOD);
|
|---|
| 2755 | outrel.r_addend = 0;
|
|---|
| 2756 | loc = htab->srelgot->contents;
|
|---|
| 2757 | loc += htab->srelgot->reloc_count++
|
|---|
| 2758 | * sizeof (Elf64_External_Rela);
|
|---|
| 2759 | bfd_elf64_swap_reloca_out (output_bfd, &outrel, loc);
|
|---|
| 2760 | htab->tls_ldm_got.offset |= 1;
|
|---|
| 2761 | }
|
|---|
| 2762 | relocation = htab->sgot->output_offset + off;
|
|---|
| 2763 | unresolved_reloc = FALSE;
|
|---|
| 2764 | break;
|
|---|
| 2765 |
|
|---|
| 2766 | case R_390_TLS_LE64:
|
|---|
| 2767 | if (info->shared)
|
|---|
| 2768 | {
|
|---|
| 2769 | /* Linking a shared library with non-fpic code requires
|
|---|
| 2770 | a R_390_TLS_TPOFF relocation. */
|
|---|
| 2771 | Elf_Internal_Rela outrel;
|
|---|
| 2772 | asection *sreloc;
|
|---|
| 2773 | bfd_byte *loc;
|
|---|
| 2774 | int indx;
|
|---|
| 2775 |
|
|---|
| 2776 | outrel.r_offset = rel->r_offset
|
|---|
| 2777 | + input_section->output_section->vma
|
|---|
| 2778 | + input_section->output_offset;
|
|---|
| 2779 | if (h != NULL && h->dynindx != -1)
|
|---|
| 2780 | indx = h->dynindx;
|
|---|
| 2781 | else
|
|---|
| 2782 | indx = 0;
|
|---|
| 2783 | outrel.r_info = ELF64_R_INFO (indx, R_390_TLS_TPOFF);
|
|---|
| 2784 | if (indx == 0)
|
|---|
| 2785 | outrel.r_addend = relocation - dtpoff_base (info);
|
|---|
| 2786 | else
|
|---|
| 2787 | outrel.r_addend = 0;
|
|---|
| 2788 | sreloc = elf_section_data (input_section)->sreloc;
|
|---|
| 2789 | if (sreloc == NULL)
|
|---|
| 2790 | abort ();
|
|---|
| 2791 | loc = sreloc->contents;
|
|---|
| 2792 | loc += sreloc->reloc_count++ * sizeof (Elf64_External_Rela);
|
|---|
| 2793 | bfd_elf64_swap_reloca_out (output_bfd, &outrel, loc);
|
|---|
| 2794 | }
|
|---|
| 2795 | else
|
|---|
| 2796 | {
|
|---|
| 2797 | BFD_ASSERT (! unresolved_reloc);
|
|---|
| 2798 | bfd_put_64 (output_bfd, -tpoff (info, relocation),
|
|---|
| 2799 | contents + rel->r_offset);
|
|---|
| 2800 | }
|
|---|
| 2801 | continue;
|
|---|
| 2802 |
|
|---|
| 2803 | case R_390_TLS_LDO64:
|
|---|
| 2804 | if (info->shared || (input_section->flags & SEC_CODE) == 0)
|
|---|
| 2805 | relocation -= dtpoff_base (info);
|
|---|
| 2806 | else
|
|---|
| 2807 | /* When converting LDO to LE, we must negate. */
|
|---|
| 2808 | relocation = -tpoff (info, relocation);
|
|---|
| 2809 | break;
|
|---|
| 2810 |
|
|---|
| 2811 | /* Relocations for tls instructions. */
|
|---|
| 2812 | case R_390_TLS_LOAD:
|
|---|
| 2813 | case R_390_TLS_GDCALL:
|
|---|
| 2814 | case R_390_TLS_LDCALL:
|
|---|
| 2815 | tls_type = GOT_UNKNOWN;
|
|---|
| 2816 | if (h == NULL && local_got_offsets)
|
|---|
| 2817 | tls_type = elf_s390_local_got_tls_type (input_bfd) [r_symndx];
|
|---|
| 2818 | else if (h != NULL)
|
|---|
| 2819 | tls_type = elf_s390_hash_entry(h)->tls_type;
|
|---|
| 2820 |
|
|---|
| 2821 | if (tls_type == GOT_TLS_GD)
|
|---|
| 2822 | continue;
|
|---|
| 2823 |
|
|---|
| 2824 | if (r_type == R_390_TLS_LOAD)
|
|---|
| 2825 | {
|
|---|
| 2826 | if (!info->shared && (h == NULL || h->dynindx == -1))
|
|---|
| 2827 | {
|
|---|
| 2828 | /* IE->LE transition. Four valid cases:
|
|---|
| 2829 | lg %rx,(0,%ry) -> sllg %rx,%ry,0
|
|---|
| 2830 | lg %rx,(%ry,0) -> sllg %rx,%ry,0
|
|---|
| 2831 | lg %rx,(%ry,%r12) -> sllg %rx,%ry,0
|
|---|
| 2832 | lg %rx,(%r12,%ry) -> sllg %rx,%ry,0 */
|
|---|
| 2833 | unsigned int insn0, insn1, ry;
|
|---|
| 2834 |
|
|---|
| 2835 | insn0 = bfd_get_32 (input_bfd, contents + rel->r_offset);
|
|---|
| 2836 | insn1 = bfd_get_16 (input_bfd, contents + rel->r_offset + 4);
|
|---|
| 2837 | if (insn1 != 0x0004)
|
|---|
| 2838 | invalid_tls_insn (input_bfd, input_section, rel);
|
|---|
| 2839 | ry = 0;
|
|---|
| 2840 | if ((insn0 & 0xff00f000) == 0xe3000000)
|
|---|
| 2841 | /* lg %rx,0(%ry,0) -> sllg %rx,%ry,0 */
|
|---|
| 2842 | ry = (insn0 & 0x000f0000);
|
|---|
| 2843 | else if ((insn0 & 0xff0f0000) == 0xe3000000)
|
|---|
| 2844 | /* lg %rx,0(0,%ry) -> sllg %rx,%ry,0 */
|
|---|
| 2845 | ry = (insn0 & 0x0000f000) << 4;
|
|---|
| 2846 | else if ((insn0 & 0xff00f000) == 0xe300c000)
|
|---|
| 2847 | /* lg %rx,0(%ry,%r12) -> sllg %rx,%ry,0 */
|
|---|
| 2848 | ry = (insn0 & 0x000f0000);
|
|---|
| 2849 | else if ((insn0 & 0xff0f0000) == 0xe30c0000)
|
|---|
| 2850 | /* lg %rx,0(%r12,%ry) -> sllg %rx,%ry,0 */
|
|---|
| 2851 | ry = (insn0 & 0x0000f000) << 4;
|
|---|
| 2852 | else
|
|---|
| 2853 | invalid_tls_insn (input_bfd, input_section, rel);
|
|---|
| 2854 | insn0 = 0xeb000000 | (insn0 & 0x00f00000) | ry;
|
|---|
| 2855 | insn1 = 0x000d;
|
|---|
| 2856 | bfd_put_32 (output_bfd, insn0, contents + rel->r_offset);
|
|---|
| 2857 | bfd_put_16 (output_bfd, insn1, contents + rel->r_offset + 4);
|
|---|
| 2858 | }
|
|---|
| 2859 | }
|
|---|
| 2860 | else if (r_type == R_390_TLS_GDCALL)
|
|---|
| 2861 | {
|
|---|
| 2862 | unsigned int insn0, insn1;
|
|---|
| 2863 |
|
|---|
| 2864 | insn0 = bfd_get_32 (input_bfd, contents + rel->r_offset);
|
|---|
| 2865 | insn1 = bfd_get_16 (input_bfd, contents + rel->r_offset + 4);
|
|---|
| 2866 | if ((insn0 & 0xffff0000) != 0xc0e50000)
|
|---|
| 2867 | invalid_tls_insn (input_bfd, input_section, rel);
|
|---|
| 2868 | if (!info->shared && (h == NULL || h->dynindx == -1))
|
|---|
| 2869 | {
|
|---|
| 2870 | /* GD->LE transition.
|
|---|
| 2871 | brasl %r14,__tls_get_addr@plt -> brcl 0,. */
|
|---|
| 2872 | insn0 = 0xc0040000;
|
|---|
| 2873 | insn1 = 0x0000;
|
|---|
| 2874 | }
|
|---|
| 2875 | else
|
|---|
| 2876 | {
|
|---|
| 2877 | /* GD->IE transition.
|
|---|
| 2878 | brasl %r14,__tls_get_addr@plt -> lg %r2,0(%r2,%r12) */
|
|---|
| 2879 | insn0 = 0xe322c000;
|
|---|
| 2880 | insn1 = 0x0004;
|
|---|
| 2881 | }
|
|---|
| 2882 | bfd_put_32 (output_bfd, insn0, contents + rel->r_offset);
|
|---|
| 2883 | bfd_put_16 (output_bfd, insn1, contents + rel->r_offset + 4);
|
|---|
| 2884 | }
|
|---|
| 2885 | else if (r_type == R_390_TLS_LDCALL)
|
|---|
| 2886 | {
|
|---|
| 2887 | if (!info->shared)
|
|---|
| 2888 | {
|
|---|
| 2889 | unsigned int insn0, insn1;
|
|---|
| 2890 |
|
|---|
| 2891 | insn0 = bfd_get_32 (input_bfd, contents + rel->r_offset);
|
|---|
| 2892 | insn1 = bfd_get_16 (input_bfd, contents + rel->r_offset + 4);
|
|---|
| 2893 | if ((insn0 & 0xffff0000) != 0xc0e50000)
|
|---|
| 2894 | invalid_tls_insn (input_bfd, input_section, rel);
|
|---|
| 2895 | /* LD->LE transition.
|
|---|
| 2896 | brasl %r14,__tls_get_addr@plt -> brcl 0,. */
|
|---|
| 2897 | insn0 = 0xc0040000;
|
|---|
| 2898 | insn1 = 0x0000;
|
|---|
| 2899 | bfd_put_32 (output_bfd, insn0, contents + rel->r_offset);
|
|---|
| 2900 | bfd_put_16 (output_bfd, insn1, contents + rel->r_offset + 4);
|
|---|
| 2901 | }
|
|---|
| 2902 | }
|
|---|
| 2903 | continue;
|
|---|
| 2904 |
|
|---|
| 2905 | default:
|
|---|
| 2906 | break;
|
|---|
| 2907 | }
|
|---|
| 2908 |
|
|---|
| 2909 | /* Dynamic relocs are not propagated for SEC_DEBUGGING sections
|
|---|
| 2910 | because such sections are not SEC_ALLOC and thus ld.so will
|
|---|
| 2911 | not process them. */
|
|---|
| 2912 | if (unresolved_reloc
|
|---|
| 2913 | && !((input_section->flags & SEC_DEBUGGING) != 0
|
|---|
| 2914 | && (h->elf_link_hash_flags & ELF_LINK_HASH_DEF_DYNAMIC) != 0))
|
|---|
| 2915 | (*_bfd_error_handler)
|
|---|
| 2916 | (_("%s(%s+0x%lx): unresolvable relocation against symbol `%s'"),
|
|---|
| 2917 | bfd_archive_filename (input_bfd),
|
|---|
| 2918 | bfd_get_section_name (input_bfd, input_section),
|
|---|
| 2919 | (long) rel->r_offset,
|
|---|
| 2920 | h->root.root.string);
|
|---|
| 2921 |
|
|---|
| 2922 | r = _bfd_final_link_relocate (howto, input_bfd, input_section,
|
|---|
| 2923 | contents, rel->r_offset,
|
|---|
| 2924 | relocation, rel->r_addend);
|
|---|
| 2925 |
|
|---|
| 2926 | if (r != bfd_reloc_ok)
|
|---|
| 2927 | {
|
|---|
| 2928 | const char *name;
|
|---|
| 2929 |
|
|---|
| 2930 | if (h != NULL)
|
|---|
| 2931 | name = h->root.root.string;
|
|---|
| 2932 | else
|
|---|
| 2933 | {
|
|---|
| 2934 | name = bfd_elf_string_from_elf_section (input_bfd,
|
|---|
| 2935 | symtab_hdr->sh_link,
|
|---|
| 2936 | sym->st_name);
|
|---|
| 2937 | if (name == NULL)
|
|---|
| 2938 | return FALSE;
|
|---|
| 2939 | if (*name == '\0')
|
|---|
| 2940 | name = bfd_section_name (input_bfd, sec);
|
|---|
| 2941 | }
|
|---|
| 2942 |
|
|---|
| 2943 | if (r == bfd_reloc_overflow)
|
|---|
| 2944 | {
|
|---|
| 2945 |
|
|---|
| 2946 | if (! ((*info->callbacks->reloc_overflow)
|
|---|
| 2947 | (info, name, howto->name, (bfd_vma) 0,
|
|---|
| 2948 | input_bfd, input_section, rel->r_offset)))
|
|---|
| 2949 | return FALSE;
|
|---|
| 2950 | }
|
|---|
| 2951 | else
|
|---|
| 2952 | {
|
|---|
| 2953 | (*_bfd_error_handler)
|
|---|
| 2954 | (_("%s(%s+0x%lx): reloc against `%s': error %d"),
|
|---|
| 2955 | bfd_archive_filename (input_bfd),
|
|---|
| 2956 | bfd_get_section_name (input_bfd, input_section),
|
|---|
| 2957 | (long) rel->r_offset, name, (int) r);
|
|---|
| 2958 | return FALSE;
|
|---|
| 2959 | }
|
|---|
| 2960 | }
|
|---|
| 2961 | }
|
|---|
| 2962 |
|
|---|
| 2963 | return TRUE;
|
|---|
| 2964 | }
|
|---|
| 2965 |
|
|---|
| 2966 | /* Finish up dynamic symbol handling. We set the contents of various
|
|---|
| 2967 | dynamic sections here. */
|
|---|
| 2968 |
|
|---|
| 2969 | static bfd_boolean
|
|---|
| 2970 | elf_s390_finish_dynamic_symbol (output_bfd, info, h, sym)
|
|---|
| 2971 | bfd *output_bfd;
|
|---|
| 2972 | struct bfd_link_info *info;
|
|---|
| 2973 | struct elf_link_hash_entry *h;
|
|---|
| 2974 | Elf_Internal_Sym *sym;
|
|---|
| 2975 | {
|
|---|
| 2976 | struct elf_s390_link_hash_table *htab;
|
|---|
| 2977 |
|
|---|
| 2978 | htab = elf_s390_hash_table (info);
|
|---|
| 2979 |
|
|---|
| 2980 | if (h->plt.offset != (bfd_vma) -1)
|
|---|
| 2981 | {
|
|---|
| 2982 | bfd_vma plt_index;
|
|---|
| 2983 | bfd_vma got_offset;
|
|---|
| 2984 | Elf_Internal_Rela rela;
|
|---|
| 2985 | bfd_byte *loc;
|
|---|
| 2986 |
|
|---|
| 2987 | /* This symbol has an entry in the procedure linkage table. Set
|
|---|
| 2988 | it up. */
|
|---|
| 2989 |
|
|---|
| 2990 | if (h->dynindx == -1
|
|---|
| 2991 | || htab->splt == NULL
|
|---|
| 2992 | || htab->sgotplt == NULL
|
|---|
| 2993 | || htab->srelplt == NULL)
|
|---|
| 2994 | abort ();
|
|---|
| 2995 |
|
|---|
| 2996 | /* Calc. index no.
|
|---|
| 2997 | Current offset - size first entry / entry size. */
|
|---|
| 2998 | plt_index = (h->plt.offset - PLT_FIRST_ENTRY_SIZE) / PLT_ENTRY_SIZE;
|
|---|
| 2999 |
|
|---|
| 3000 | /* Offset in GOT is PLT index plus GOT headers(3) times 8,
|
|---|
| 3001 | addr & GOT addr. */
|
|---|
| 3002 | got_offset = (plt_index + 3) * GOT_ENTRY_SIZE;
|
|---|
| 3003 |
|
|---|
| 3004 | /* Fill in the blueprint of a PLT. */
|
|---|
| 3005 | bfd_put_32 (output_bfd, (bfd_vma) PLT_ENTRY_WORD0,
|
|---|
| 3006 | htab->splt->contents + h->plt.offset);
|
|---|
| 3007 | bfd_put_32 (output_bfd, (bfd_vma) PLT_ENTRY_WORD1,
|
|---|
| 3008 | htab->splt->contents + h->plt.offset + 4);
|
|---|
| 3009 | bfd_put_32 (output_bfd, (bfd_vma) PLT_ENTRY_WORD2,
|
|---|
| 3010 | htab->splt->contents + h->plt.offset + 8);
|
|---|
| 3011 | bfd_put_32 (output_bfd, (bfd_vma) PLT_ENTRY_WORD3,
|
|---|
| 3012 | htab->splt->contents + h->plt.offset + 12);
|
|---|
| 3013 | bfd_put_32 (output_bfd, (bfd_vma) PLT_ENTRY_WORD4,
|
|---|
| 3014 | htab->splt->contents + h->plt.offset + 16);
|
|---|
| 3015 | bfd_put_32 (output_bfd, (bfd_vma) PLT_ENTRY_WORD5,
|
|---|
| 3016 | htab->splt->contents + h->plt.offset + 20);
|
|---|
| 3017 | bfd_put_32 (output_bfd, (bfd_vma) PLT_ENTRY_WORD6,
|
|---|
| 3018 | htab->splt->contents + h->plt.offset + 24);
|
|---|
| 3019 | bfd_put_32 (output_bfd, (bfd_vma) PLT_ENTRY_WORD7,
|
|---|
| 3020 | htab->splt->contents + h->plt.offset + 28);
|
|---|
| 3021 | /* Fixup the relative address to the GOT entry */
|
|---|
| 3022 | bfd_put_32 (output_bfd,
|
|---|
| 3023 | (htab->sgotplt->output_section->vma +
|
|---|
| 3024 | htab->sgotplt->output_offset + got_offset
|
|---|
| 3025 | - (htab->splt->output_section->vma + h->plt.offset))/2,
|
|---|
| 3026 | htab->splt->contents + h->plt.offset + 2);
|
|---|
| 3027 | /* Fixup the relative branch to PLT 0 */
|
|---|
| 3028 | bfd_put_32 (output_bfd, - (PLT_FIRST_ENTRY_SIZE +
|
|---|
| 3029 | (PLT_ENTRY_SIZE * plt_index) + 22)/2,
|
|---|
| 3030 | htab->splt->contents + h->plt.offset + 24);
|
|---|
| 3031 | /* Fixup offset into symbol table */
|
|---|
| 3032 | bfd_put_32 (output_bfd, plt_index * sizeof (Elf64_External_Rela),
|
|---|
| 3033 | htab->splt->contents + h->plt.offset + 28);
|
|---|
| 3034 |
|
|---|
| 3035 | /* Fill in the entry in the global offset table.
|
|---|
| 3036 | Points to instruction after GOT offset. */
|
|---|
| 3037 | bfd_put_64 (output_bfd,
|
|---|
| 3038 | (htab->splt->output_section->vma
|
|---|
| 3039 | + htab->splt->output_offset
|
|---|
| 3040 | + h->plt.offset
|
|---|
| 3041 | + 14),
|
|---|
| 3042 | htab->sgotplt->contents + got_offset);
|
|---|
| 3043 |
|
|---|
| 3044 | /* Fill in the entry in the .rela.plt section. */
|
|---|
| 3045 | rela.r_offset = (htab->sgotplt->output_section->vma
|
|---|
| 3046 | + htab->sgotplt->output_offset
|
|---|
| 3047 | + got_offset);
|
|---|
| 3048 | rela.r_info = ELF64_R_INFO (h->dynindx, R_390_JMP_SLOT);
|
|---|
| 3049 | rela.r_addend = 0;
|
|---|
| 3050 | loc = htab->srelplt->contents + plt_index * sizeof (Elf64_External_Rela);
|
|---|
| 3051 | bfd_elf64_swap_reloca_out (output_bfd, &rela, loc);
|
|---|
| 3052 |
|
|---|
| 3053 | if ((h->elf_link_hash_flags & ELF_LINK_HASH_DEF_REGULAR) == 0)
|
|---|
| 3054 | {
|
|---|
| 3055 | /* Mark the symbol as undefined, rather than as defined in
|
|---|
| 3056 | the .plt section. Leave the value alone. This is a clue
|
|---|
| 3057 | for the dynamic linker, to make function pointer
|
|---|
| 3058 | comparisons work between an application and shared
|
|---|
| 3059 | library. */
|
|---|
| 3060 | sym->st_shndx = SHN_UNDEF;
|
|---|
| 3061 | }
|
|---|
| 3062 | }
|
|---|
| 3063 |
|
|---|
| 3064 | if (h->got.offset != (bfd_vma) -1
|
|---|
| 3065 | && elf_s390_hash_entry(h)->tls_type != GOT_TLS_GD
|
|---|
| 3066 | && elf_s390_hash_entry(h)->tls_type != GOT_TLS_IE
|
|---|
| 3067 | && elf_s390_hash_entry(h)->tls_type != GOT_TLS_IE_NLT)
|
|---|
| 3068 | {
|
|---|
| 3069 | Elf_Internal_Rela rela;
|
|---|
| 3070 | bfd_byte *loc;
|
|---|
| 3071 |
|
|---|
| 3072 | /* This symbol has an entry in the global offset table. Set it
|
|---|
| 3073 | up. */
|
|---|
| 3074 | if (htab->sgot == NULL || htab->srelgot == NULL)
|
|---|
| 3075 | abort ();
|
|---|
| 3076 |
|
|---|
| 3077 | rela.r_offset = (htab->sgot->output_section->vma
|
|---|
| 3078 | + htab->sgot->output_offset
|
|---|
| 3079 | + (h->got.offset &~ (bfd_vma) 1));
|
|---|
| 3080 |
|
|---|
| 3081 | /* If this is a static link, or it is a -Bsymbolic link and the
|
|---|
| 3082 | symbol is defined locally or was forced to be local because
|
|---|
| 3083 | of a version file, we just want to emit a RELATIVE reloc.
|
|---|
| 3084 | The entry in the global offset table will already have been
|
|---|
| 3085 | initialized in the relocate_section function. */
|
|---|
| 3086 | if (info->shared
|
|---|
| 3087 | && (info->symbolic
|
|---|
| 3088 | || h->dynindx == -1
|
|---|
| 3089 | || (h->elf_link_hash_flags & ELF_LINK_FORCED_LOCAL))
|
|---|
| 3090 | && (h->elf_link_hash_flags & ELF_LINK_HASH_DEF_REGULAR))
|
|---|
| 3091 | {
|
|---|
| 3092 | BFD_ASSERT((h->got.offset & 1) != 0);
|
|---|
| 3093 | rela.r_info = ELF64_R_INFO (0, R_390_RELATIVE);
|
|---|
| 3094 | rela.r_addend = (h->root.u.def.value
|
|---|
| 3095 | + h->root.u.def.section->output_section->vma
|
|---|
| 3096 | + h->root.u.def.section->output_offset);
|
|---|
| 3097 | }
|
|---|
| 3098 | else
|
|---|
| 3099 | {
|
|---|
| 3100 | BFD_ASSERT((h->got.offset & 1) == 0);
|
|---|
| 3101 | bfd_put_64 (output_bfd, (bfd_vma) 0, htab->sgot->contents + h->got.offset);
|
|---|
| 3102 | rela.r_info = ELF64_R_INFO (h->dynindx, R_390_GLOB_DAT);
|
|---|
| 3103 | rela.r_addend = 0;
|
|---|
| 3104 | }
|
|---|
| 3105 |
|
|---|
| 3106 | loc = htab->srelgot->contents;
|
|---|
| 3107 | loc += htab->srelgot->reloc_count++ * sizeof (Elf64_External_Rela);
|
|---|
| 3108 | bfd_elf64_swap_reloca_out (output_bfd, &rela, loc);
|
|---|
| 3109 | }
|
|---|
| 3110 |
|
|---|
| 3111 | if ((h->elf_link_hash_flags & ELF_LINK_HASH_NEEDS_COPY) != 0)
|
|---|
| 3112 | {
|
|---|
| 3113 | Elf_Internal_Rela rela;
|
|---|
| 3114 | bfd_byte *loc;
|
|---|
| 3115 |
|
|---|
| 3116 | /* This symbols needs a copy reloc. Set it up. */
|
|---|
| 3117 |
|
|---|
| 3118 | if (h->dynindx == -1
|
|---|
| 3119 | || (h->root.type != bfd_link_hash_defined
|
|---|
| 3120 | && h->root.type != bfd_link_hash_defweak)
|
|---|
| 3121 | || htab->srelbss == NULL)
|
|---|
| 3122 | abort ();
|
|---|
| 3123 |
|
|---|
| 3124 | rela.r_offset = (h->root.u.def.value
|
|---|
| 3125 | + h->root.u.def.section->output_section->vma
|
|---|
| 3126 | + h->root.u.def.section->output_offset);
|
|---|
| 3127 | rela.r_info = ELF64_R_INFO (h->dynindx, R_390_COPY);
|
|---|
| 3128 | rela.r_addend = 0;
|
|---|
| 3129 | loc = htab->srelbss->contents;
|
|---|
| 3130 | loc += htab->srelbss->reloc_count++ * sizeof (Elf64_External_Rela);
|
|---|
| 3131 | bfd_elf64_swap_reloca_out (output_bfd, &rela, loc);
|
|---|
| 3132 | }
|
|---|
| 3133 |
|
|---|
| 3134 | /* Mark some specially defined symbols as absolute. */
|
|---|
| 3135 | if (strcmp (h->root.root.string, "_DYNAMIC") == 0
|
|---|
| 3136 | || strcmp (h->root.root.string, "_GLOBAL_OFFSET_TABLE_") == 0
|
|---|
| 3137 | || strcmp (h->root.root.string, "_PROCEDURE_LINKAGE_TABLE_") == 0)
|
|---|
| 3138 | sym->st_shndx = SHN_ABS;
|
|---|
| 3139 |
|
|---|
| 3140 | return TRUE;
|
|---|
| 3141 | }
|
|---|
| 3142 |
|
|---|
| 3143 | /* Used to decide how to sort relocs in an optimal manner for the
|
|---|
| 3144 | dynamic linker, before writing them out. */
|
|---|
| 3145 |
|
|---|
| 3146 | static enum elf_reloc_type_class
|
|---|
| 3147 | elf_s390_reloc_type_class (rela)
|
|---|
| 3148 | const Elf_Internal_Rela *rela;
|
|---|
| 3149 | {
|
|---|
| 3150 | switch ((int) ELF64_R_TYPE (rela->r_info))
|
|---|
| 3151 | {
|
|---|
| 3152 | case R_390_RELATIVE:
|
|---|
| 3153 | return reloc_class_relative;
|
|---|
| 3154 | case R_390_JMP_SLOT:
|
|---|
| 3155 | return reloc_class_plt;
|
|---|
| 3156 | case R_390_COPY:
|
|---|
| 3157 | return reloc_class_copy;
|
|---|
| 3158 | default:
|
|---|
| 3159 | return reloc_class_normal;
|
|---|
| 3160 | }
|
|---|
| 3161 | }
|
|---|
| 3162 |
|
|---|
| 3163 | /* Finish up the dynamic sections. */
|
|---|
| 3164 |
|
|---|
| 3165 | static bfd_boolean
|
|---|
| 3166 | elf_s390_finish_dynamic_sections (output_bfd, info)
|
|---|
| 3167 | bfd *output_bfd;
|
|---|
| 3168 | struct bfd_link_info *info;
|
|---|
| 3169 | {
|
|---|
| 3170 | struct elf_s390_link_hash_table *htab;
|
|---|
| 3171 | bfd *dynobj;
|
|---|
| 3172 | asection *sdyn;
|
|---|
| 3173 |
|
|---|
| 3174 | htab = elf_s390_hash_table (info);
|
|---|
| 3175 | dynobj = htab->elf.dynobj;
|
|---|
| 3176 | sdyn = bfd_get_section_by_name (dynobj, ".dynamic");
|
|---|
| 3177 |
|
|---|
| 3178 | if (htab->elf.dynamic_sections_created)
|
|---|
| 3179 | {
|
|---|
| 3180 | Elf64_External_Dyn *dyncon, *dynconend;
|
|---|
| 3181 |
|
|---|
| 3182 | if (sdyn == NULL || htab->sgot == NULL)
|
|---|
| 3183 | abort ();
|
|---|
| 3184 |
|
|---|
| 3185 | dyncon = (Elf64_External_Dyn *) sdyn->contents;
|
|---|
| 3186 | dynconend = (Elf64_External_Dyn *) (sdyn->contents + sdyn->_raw_size);
|
|---|
| 3187 | for (; dyncon < dynconend; dyncon++)
|
|---|
| 3188 | {
|
|---|
| 3189 | Elf_Internal_Dyn dyn;
|
|---|
| 3190 | asection *s;
|
|---|
| 3191 |
|
|---|
| 3192 | bfd_elf64_swap_dyn_in (dynobj, dyncon, &dyn);
|
|---|
| 3193 |
|
|---|
| 3194 | switch (dyn.d_tag)
|
|---|
| 3195 | {
|
|---|
| 3196 | default:
|
|---|
| 3197 | continue;
|
|---|
| 3198 |
|
|---|
| 3199 | case DT_PLTGOT:
|
|---|
| 3200 | dyn.d_un.d_ptr = htab->sgot->output_section->vma;
|
|---|
| 3201 | break;
|
|---|
| 3202 |
|
|---|
| 3203 | case DT_JMPREL:
|
|---|
| 3204 | dyn.d_un.d_ptr = htab->srelplt->output_section->vma;
|
|---|
| 3205 | break;
|
|---|
| 3206 |
|
|---|
| 3207 | case DT_PLTRELSZ:
|
|---|
| 3208 | s = htab->srelplt->output_section;
|
|---|
| 3209 | if (s->_cooked_size != 0)
|
|---|
| 3210 | dyn.d_un.d_val = s->_cooked_size;
|
|---|
| 3211 | else
|
|---|
| 3212 | dyn.d_un.d_val = s->_raw_size;
|
|---|
| 3213 | break;
|
|---|
| 3214 |
|
|---|
| 3215 | case DT_RELASZ:
|
|---|
| 3216 | /* The procedure linkage table relocs (DT_JMPREL) should
|
|---|
| 3217 | not be included in the overall relocs (DT_RELA).
|
|---|
| 3218 | Therefore, we override the DT_RELASZ entry here to
|
|---|
| 3219 | make it not include the JMPREL relocs. Since the
|
|---|
| 3220 | linker script arranges for .rela.plt to follow all
|
|---|
| 3221 | other relocation sections, we don't have to worry
|
|---|
| 3222 | about changing the DT_RELA entry. */
|
|---|
| 3223 | s = htab->srelplt->output_section;
|
|---|
| 3224 | if (s->_cooked_size != 0)
|
|---|
| 3225 | dyn.d_un.d_val -= s->_cooked_size;
|
|---|
| 3226 | else
|
|---|
| 3227 | dyn.d_un.d_val -= s->_raw_size;
|
|---|
| 3228 | break;
|
|---|
| 3229 | }
|
|---|
| 3230 |
|
|---|
| 3231 | bfd_elf64_swap_dyn_out (output_bfd, &dyn, dyncon);
|
|---|
| 3232 | }
|
|---|
| 3233 |
|
|---|
| 3234 | /* Fill in the special first entry in the procedure linkage table. */
|
|---|
| 3235 | if (htab->splt && htab->splt->_raw_size > 0)
|
|---|
| 3236 | {
|
|---|
| 3237 | /* fill in blueprint for plt 0 entry */
|
|---|
| 3238 | bfd_put_32 (output_bfd, (bfd_vma) PLT_FIRST_ENTRY_WORD0,
|
|---|
| 3239 | htab->splt->contents );
|
|---|
| 3240 | bfd_put_32 (output_bfd, (bfd_vma) PLT_FIRST_ENTRY_WORD1,
|
|---|
| 3241 | htab->splt->contents +4 );
|
|---|
| 3242 | bfd_put_32 (output_bfd, (bfd_vma) PLT_FIRST_ENTRY_WORD3,
|
|---|
| 3243 | htab->splt->contents +12 );
|
|---|
| 3244 | bfd_put_32 (output_bfd, (bfd_vma) PLT_FIRST_ENTRY_WORD4,
|
|---|
| 3245 | htab->splt->contents +16 );
|
|---|
| 3246 | bfd_put_32 (output_bfd, (bfd_vma) PLT_FIRST_ENTRY_WORD5,
|
|---|
| 3247 | htab->splt->contents +20 );
|
|---|
| 3248 | bfd_put_32 (output_bfd, (bfd_vma) PLT_FIRST_ENTRY_WORD6,
|
|---|
| 3249 | htab->splt->contents + 24);
|
|---|
| 3250 | bfd_put_32 (output_bfd, (bfd_vma) PLT_FIRST_ENTRY_WORD7,
|
|---|
| 3251 | htab->splt->contents + 28 );
|
|---|
| 3252 | /* Fixup relative address to start of GOT */
|
|---|
| 3253 | bfd_put_32 (output_bfd,
|
|---|
| 3254 | (htab->sgotplt->output_section->vma +
|
|---|
| 3255 | htab->sgotplt->output_offset
|
|---|
| 3256 | - htab->splt->output_section->vma - 6)/2,
|
|---|
| 3257 | htab->splt->contents + 8);
|
|---|
| 3258 | }
|
|---|
| 3259 | elf_section_data (htab->splt->output_section)
|
|---|
| 3260 | ->this_hdr.sh_entsize = PLT_ENTRY_SIZE;
|
|---|
| 3261 | }
|
|---|
| 3262 |
|
|---|
| 3263 | if (htab->sgotplt)
|
|---|
| 3264 | {
|
|---|
| 3265 | /* Fill in the first three entries in the global offset table. */
|
|---|
| 3266 | if (htab->sgotplt->_raw_size > 0)
|
|---|
| 3267 | {
|
|---|
| 3268 | bfd_put_64 (output_bfd,
|
|---|
| 3269 | (sdyn == NULL ? (bfd_vma) 0
|
|---|
| 3270 | : sdyn->output_section->vma + sdyn->output_offset),
|
|---|
| 3271 | htab->sgotplt->contents);
|
|---|
| 3272 | /* One entry for shared object struct ptr. */
|
|---|
| 3273 | bfd_put_64 (output_bfd, (bfd_vma) 0, htab->sgotplt->contents + 8);
|
|---|
| 3274 | /* One entry for _dl_runtime_resolve. */
|
|---|
| 3275 | bfd_put_64 (output_bfd, (bfd_vma) 0, htab->sgotplt->contents + 12);
|
|---|
| 3276 | }
|
|---|
| 3277 |
|
|---|
| 3278 | elf_section_data (htab->sgot->output_section)
|
|---|
| 3279 | ->this_hdr.sh_entsize = 8;
|
|---|
| 3280 | }
|
|---|
| 3281 | return TRUE;
|
|---|
| 3282 | }
|
|---|
| 3283 |
|
|---|
| 3284 | /* Why was the hash table entry size definition changed from
|
|---|
| 3285 | ARCH_SIZE/8 to 4? This breaks the 64 bit dynamic linker and
|
|---|
| 3286 | this is the only reason for the s390_elf64_size_info structure. */
|
|---|
| 3287 |
|
|---|
| 3288 | const struct elf_size_info s390_elf64_size_info =
|
|---|
| 3289 | {
|
|---|
| 3290 | sizeof (Elf64_External_Ehdr),
|
|---|
| 3291 | sizeof (Elf64_External_Phdr),
|
|---|
| 3292 | sizeof (Elf64_External_Shdr),
|
|---|
| 3293 | sizeof (Elf64_External_Rel),
|
|---|
| 3294 | sizeof (Elf64_External_Rela),
|
|---|
| 3295 | sizeof (Elf64_External_Sym),
|
|---|
| 3296 | sizeof (Elf64_External_Dyn),
|
|---|
| 3297 | sizeof (Elf_External_Note),
|
|---|
| 3298 | 8, /* hash-table entry size. */
|
|---|
| 3299 | 1, /* internal relocations per external relocations. */
|
|---|
| 3300 | 64, /* arch_size. */
|
|---|
| 3301 | 8, /* file_align. */
|
|---|
| 3302 | ELFCLASS64, EV_CURRENT,
|
|---|
| 3303 | bfd_elf64_write_out_phdrs,
|
|---|
| 3304 | bfd_elf64_write_shdrs_and_ehdr,
|
|---|
| 3305 | bfd_elf64_write_relocs,
|
|---|
| 3306 | bfd_elf64_swap_symbol_in,
|
|---|
| 3307 | bfd_elf64_swap_symbol_out,
|
|---|
| 3308 | bfd_elf64_slurp_reloc_table,
|
|---|
| 3309 | bfd_elf64_slurp_symbol_table,
|
|---|
| 3310 | bfd_elf64_swap_dyn_in,
|
|---|
| 3311 | bfd_elf64_swap_dyn_out,
|
|---|
| 3312 | bfd_elf64_swap_reloc_in,
|
|---|
| 3313 | bfd_elf64_swap_reloc_out,
|
|---|
| 3314 | bfd_elf64_swap_reloca_in,
|
|---|
| 3315 | bfd_elf64_swap_reloca_out
|
|---|
| 3316 | };
|
|---|
| 3317 |
|
|---|
| 3318 | #define TARGET_BIG_SYM bfd_elf64_s390_vec
|
|---|
| 3319 | #define TARGET_BIG_NAME "elf64-s390"
|
|---|
| 3320 | #define ELF_ARCH bfd_arch_s390
|
|---|
| 3321 | #define ELF_MACHINE_CODE EM_S390
|
|---|
| 3322 | #define ELF_MACHINE_ALT1 EM_S390_OLD
|
|---|
| 3323 | #define ELF_MAXPAGESIZE 0x1000
|
|---|
| 3324 |
|
|---|
| 3325 | #define elf_backend_size_info s390_elf64_size_info
|
|---|
| 3326 |
|
|---|
| 3327 | #define elf_backend_can_gc_sections 1
|
|---|
| 3328 | #define elf_backend_can_refcount 1
|
|---|
| 3329 | #define elf_backend_want_got_plt 1
|
|---|
| 3330 | #define elf_backend_plt_readonly 1
|
|---|
| 3331 | #define elf_backend_want_plt_sym 0
|
|---|
| 3332 | #define elf_backend_got_header_size 24
|
|---|
| 3333 | #define elf_backend_plt_header_size PLT_ENTRY_SIZE
|
|---|
| 3334 | #define elf_backend_rela_normal 1
|
|---|
| 3335 |
|
|---|
| 3336 | #define elf_info_to_howto elf_s390_info_to_howto
|
|---|
| 3337 |
|
|---|
| 3338 | #define bfd_elf64_bfd_is_local_label_name elf_s390_is_local_label_name
|
|---|
| 3339 | #define bfd_elf64_bfd_link_hash_table_create elf_s390_link_hash_table_create
|
|---|
| 3340 | #define bfd_elf64_bfd_reloc_type_lookup elf_s390_reloc_type_lookup
|
|---|
| 3341 |
|
|---|
| 3342 | #define elf_backend_adjust_dynamic_symbol elf_s390_adjust_dynamic_symbol
|
|---|
| 3343 | #define elf_backend_check_relocs elf_s390_check_relocs
|
|---|
| 3344 | #define elf_backend_copy_indirect_symbol elf_s390_copy_indirect_symbol
|
|---|
| 3345 | #define elf_backend_create_dynamic_sections elf_s390_create_dynamic_sections
|
|---|
| 3346 | #define elf_backend_finish_dynamic_sections elf_s390_finish_dynamic_sections
|
|---|
| 3347 | #define elf_backend_finish_dynamic_symbol elf_s390_finish_dynamic_symbol
|
|---|
| 3348 | #define elf_backend_gc_mark_hook elf_s390_gc_mark_hook
|
|---|
| 3349 | #define elf_backend_gc_sweep_hook elf_s390_gc_sweep_hook
|
|---|
| 3350 | #define elf_backend_reloc_type_class elf_s390_reloc_type_class
|
|---|
| 3351 | #define elf_backend_relocate_section elf_s390_relocate_section
|
|---|
| 3352 | #define elf_backend_size_dynamic_sections elf_s390_size_dynamic_sections
|
|---|
| 3353 | #define elf_backend_reloc_type_class elf_s390_reloc_type_class
|
|---|
| 3354 |
|
|---|
| 3355 | #define bfd_elf64_mkobject elf_s390_mkobject
|
|---|
| 3356 | #define elf_backend_object_p elf_s390_object_p
|
|---|
| 3357 |
|
|---|
| 3358 | #include "elf64-target.h"
|
|---|