Changeset 609 for branches/GNU/src/binutils/bfd/elf64-x86-64.c
- Timestamp:
- Aug 16, 2003, 6:59:22 PM (22 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/GNU/src/binutils/bfd/elf64-x86-64.c
-
Property cvs2svn:cvs-rev
changed from
1.1
to1.1.1.2
r608 r609 1 1 /* X86-64 specific support for 64-bit ELF 2 Copyright 2000, 2001 Free Software Foundation, Inc.2 Copyright 2000, 2001, 2002, 2003 Free Software Foundation, Inc. 3 3 Contributed by Jan Hubicka <jh@suse.cz>. 4 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 modify8 it under the terms of the GNU General Public License as published by9 the Free Software Foundation; either version 2 of the License, or10 (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 of14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the15 GNU General Public License for more details.16 17 You should have received a copy of the GNU General Public License18 along with this program; if not, write to the Free Software19 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */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 02111-1307, USA. */ 20 20 21 21 #include "bfd.h" 22 22 #include "sysdep.h" 23 #include "bfdlink.h" 23 24 #include "libbfd.h" 24 25 #include "elf-bfd.h" 25 26 26 27 #include "elf/x86-64.h" 27 28 /* We use only the RELA entries. */29 #define USE_RELA30 28 31 29 /* In case we're on a 32-bit machine, construct a 64-bit "-1" value. */ … … 37 35 static reloc_howto_type x86_64_elf_howto_table[] = 38 36 { 39 HOWTO(R_X86_64_NONE, 0, 0, 0, false, 0, complain_overflow_dont, 40 bfd_elf_generic_reloc, "R_X86_64_NONE", false, 0x00000000, 0x00000000, 41 false), 42 HOWTO(R_X86_64_64, 0, 4, 64, false, 0, complain_overflow_bitfield, 43 bfd_elf_generic_reloc, "R_X86_64_64", false, MINUS_ONE, MINUS_ONE, 44 false), 45 HOWTO(R_X86_64_PC32, 0, 4, 32, true, 0, complain_overflow_signed, 46 bfd_elf_generic_reloc, "R_X86_64_PC32", false, 0xffffffff, 0xffffffff, 47 true), 48 HOWTO(R_X86_64_GOT32, 0, 4, 32, false, 0, complain_overflow_signed, 49 bfd_elf_generic_reloc, "R_X86_64_GOT32", false, 0xffffffff, 0xffffffff, 50 false), 51 HOWTO(R_X86_64_PLT32, 0, 4, 32, true, 0, complain_overflow_signed, 52 bfd_elf_generic_reloc, "R_X86_64_PLT32", false, 0xffffffff, 0xffffffff, 53 true), 54 HOWTO(R_X86_64_COPY, 0, 4, 32, false, 0, complain_overflow_bitfield, 55 bfd_elf_generic_reloc, "R_X86_64_COPY", false, 0xffffffff, 0xffffffff, 56 false), 57 HOWTO(R_X86_64_GLOB_DAT, 0, 4, 64, false, 0, complain_overflow_bitfield, 58 bfd_elf_generic_reloc, "R_X86_64_GLOB_DAT", false, MINUS_ONE, 59 MINUS_ONE, false), 60 HOWTO(R_X86_64_JUMP_SLOT, 0, 4, 64, false, 0, complain_overflow_bitfield, 61 bfd_elf_generic_reloc, "R_X86_64_JUMP_SLOT", false, MINUS_ONE, 62 MINUS_ONE, false), 63 HOWTO(R_X86_64_RELATIVE, 0, 4, 64, false, 0, complain_overflow_bitfield, 64 bfd_elf_generic_reloc, "R_X86_64_RELATIVE", false, MINUS_ONE, 65 MINUS_ONE, false), 66 HOWTO(R_X86_64_GOTPCREL, 0, 4, 32, true,0 , complain_overflow_signed, 67 bfd_elf_generic_reloc, "R_X86_64_GOTPCREL", false, 0xffffffff, 68 0xffffffff, true), 69 HOWTO(R_X86_64_32, 0, 4, 32, false, 0, complain_overflow_unsigned, 70 bfd_elf_generic_reloc, "R_X86_64_32", false, 0xffffffff, 0xffffffff, 71 false), 72 HOWTO(R_X86_64_32S, 0, 4, 32, false, 0, complain_overflow_signed, 73 bfd_elf_generic_reloc, "R_X86_64_32S", false, 0xffffffff, 0xffffffff, 74 false), 75 HOWTO(R_X86_64_16, 0, 1, 16, false, 0, complain_overflow_bitfield, 76 bfd_elf_generic_reloc, "R_X86_64_16", false, 0xffff, 0xffff, false), 77 HOWTO(R_X86_64_PC16,0, 1, 16, true, 0, complain_overflow_bitfield, 78 bfd_elf_generic_reloc, "R_X86_64_PC16", false, 0xffff, 0xffff, true), 79 HOWTO(R_X86_64_8, 0, 0, 8, false, 0, complain_overflow_signed, 80 bfd_elf_generic_reloc, "R_X86_64_8", false, 0xff, 0xff, false), 81 HOWTO(R_X86_64_PC8, 0, 0, 8, true, 0, complain_overflow_signed, 82 bfd_elf_generic_reloc, "R_X86_64_PC8", false, 0xff, 0xff, true) 37 HOWTO(R_X86_64_NONE, 0, 0, 0, FALSE, 0, complain_overflow_dont, 38 bfd_elf_generic_reloc, "R_X86_64_NONE", FALSE, 0x00000000, 0x00000000, 39 FALSE), 40 HOWTO(R_X86_64_64, 0, 4, 64, FALSE, 0, complain_overflow_bitfield, 41 bfd_elf_generic_reloc, "R_X86_64_64", FALSE, MINUS_ONE, MINUS_ONE, 42 FALSE), 43 HOWTO(R_X86_64_PC32, 0, 2, 32, TRUE, 0, complain_overflow_signed, 44 bfd_elf_generic_reloc, "R_X86_64_PC32", FALSE, 0xffffffff, 0xffffffff, 45 TRUE), 46 HOWTO(R_X86_64_GOT32, 0, 2, 32, FALSE, 0, complain_overflow_signed, 47 bfd_elf_generic_reloc, "R_X86_64_GOT32", FALSE, 0xffffffff, 0xffffffff, 48 FALSE), 49 HOWTO(R_X86_64_PLT32, 0, 2, 32, TRUE, 0, complain_overflow_signed, 50 bfd_elf_generic_reloc, "R_X86_64_PLT32", FALSE, 0xffffffff, 0xffffffff, 51 TRUE), 52 HOWTO(R_X86_64_COPY, 0, 2, 32, FALSE, 0, complain_overflow_bitfield, 53 bfd_elf_generic_reloc, "R_X86_64_COPY", FALSE, 0xffffffff, 0xffffffff, 54 FALSE), 55 HOWTO(R_X86_64_GLOB_DAT, 0, 4, 64, FALSE, 0, complain_overflow_bitfield, 56 bfd_elf_generic_reloc, "R_X86_64_GLOB_DAT", FALSE, MINUS_ONE, 57 MINUS_ONE, FALSE), 58 HOWTO(R_X86_64_JUMP_SLOT, 0, 4, 64, FALSE, 0, complain_overflow_bitfield, 59 bfd_elf_generic_reloc, "R_X86_64_JUMP_SLOT", FALSE, MINUS_ONE, 60 MINUS_ONE, FALSE), 61 HOWTO(R_X86_64_RELATIVE, 0, 4, 64, FALSE, 0, complain_overflow_bitfield, 62 bfd_elf_generic_reloc, "R_X86_64_RELATIVE", FALSE, MINUS_ONE, 63 MINUS_ONE, FALSE), 64 HOWTO(R_X86_64_GOTPCREL, 0, 2, 32, TRUE, 0, complain_overflow_signed, 65 bfd_elf_generic_reloc, "R_X86_64_GOTPCREL", FALSE, 0xffffffff, 66 0xffffffff, TRUE), 67 HOWTO(R_X86_64_32, 0, 2, 32, FALSE, 0, complain_overflow_unsigned, 68 bfd_elf_generic_reloc, "R_X86_64_32", FALSE, 0xffffffff, 0xffffffff, 69 FALSE), 70 HOWTO(R_X86_64_32S, 0, 2, 32, FALSE, 0, complain_overflow_signed, 71 bfd_elf_generic_reloc, "R_X86_64_32S", FALSE, 0xffffffff, 0xffffffff, 72 FALSE), 73 HOWTO(R_X86_64_16, 0, 1, 16, FALSE, 0, complain_overflow_bitfield, 74 bfd_elf_generic_reloc, "R_X86_64_16", FALSE, 0xffff, 0xffff, FALSE), 75 HOWTO(R_X86_64_PC16,0, 1, 16, TRUE, 0, complain_overflow_bitfield, 76 bfd_elf_generic_reloc, "R_X86_64_PC16", FALSE, 0xffff, 0xffff, TRUE), 77 HOWTO(R_X86_64_8, 0, 0, 8, FALSE, 0, complain_overflow_signed, 78 bfd_elf_generic_reloc, "R_X86_64_8", FALSE, 0xff, 0xff, FALSE), 79 HOWTO(R_X86_64_PC8, 0, 0, 8, TRUE, 0, complain_overflow_signed, 80 bfd_elf_generic_reloc, "R_X86_64_PC8", FALSE, 0xff, 0xff, TRUE), 81 HOWTO(R_X86_64_DTPMOD64, 0, 4, 64, FALSE, 0, complain_overflow_bitfield, 82 bfd_elf_generic_reloc, "R_X86_64_DTPMOD64", FALSE, MINUS_ONE, 83 MINUS_ONE, FALSE), 84 HOWTO(R_X86_64_DTPOFF64, 0, 4, 64, FALSE, 0, complain_overflow_bitfield, 85 bfd_elf_generic_reloc, "R_X86_64_DTPOFF64", FALSE, MINUS_ONE, 86 MINUS_ONE, FALSE), 87 HOWTO(R_X86_64_TPOFF64, 0, 4, 64, FALSE, 0, complain_overflow_bitfield, 88 bfd_elf_generic_reloc, "R_X86_64_TPOFF64", FALSE, MINUS_ONE, 89 MINUS_ONE, FALSE), 90 HOWTO(R_X86_64_TLSGD, 0, 2, 32, TRUE, 0, complain_overflow_signed, 91 bfd_elf_generic_reloc, "R_X86_64_TLSGD", FALSE, 0xffffffff, 92 0xffffffff, TRUE), 93 HOWTO(R_X86_64_TLSLD, 0, 2, 32, TRUE, 0, complain_overflow_signed, 94 bfd_elf_generic_reloc, "R_X86_64_TLSLD", FALSE, 0xffffffff, 95 0xffffffff, TRUE), 96 HOWTO(R_X86_64_DTPOFF32, 0, 2, 32, FALSE, 0, complain_overflow_bitfield, 97 bfd_elf_generic_reloc, "R_X86_64_DTPOFF32", FALSE, 0xffffffff, 98 0xffffffff, FALSE), 99 HOWTO(R_X86_64_GOTTPOFF, 0, 2, 32, TRUE, 0, complain_overflow_signed, 100 bfd_elf_generic_reloc, "R_X86_64_GOTTPOFF", FALSE, 0xffffffff, 101 0xffffffff, TRUE), 102 HOWTO(R_X86_64_TPOFF32, 0, 2, 32, FALSE, 0, complain_overflow_signed, 103 bfd_elf_generic_reloc, "R_X86_64_TPOFF32", FALSE, 0xffffffff, 104 0xffffffff, FALSE), 105 106 /* GNU extension to record C++ vtable hierarchy. */ 107 HOWTO (R_X86_64_GNU_VTINHERIT, 0, 4, 0, FALSE, 0, complain_overflow_dont, 108 NULL, "R_X86_64_GNU_VTINHERIT", FALSE, 0, 0, FALSE), 109 110 /* GNU extension to record C++ vtable member usage. */ 111 HOWTO (R_X86_64_GNU_VTENTRY, 0, 4, 0, FALSE, 0, complain_overflow_dont, 112 _bfd_elf_rel_vtable_reloc_fn, "R_X86_64_GNU_VTENTRY", FALSE, 0, 0, 113 FALSE) 83 114 }; 84 115 … … 90 121 }; 91 122 92 static CONSTstruct elf_reloc_map x86_64_reloc_map[] =123 static const struct elf_reloc_map x86_64_reloc_map[] = 93 124 { 94 125 { BFD_RELOC_NONE, R_X86_64_NONE, }, … … 108 139 { BFD_RELOC_8, R_X86_64_8, }, 109 140 { BFD_RELOC_8_PCREL, R_X86_64_PC8, }, 141 { BFD_RELOC_X86_64_DTPMOD64, R_X86_64_DTPMOD64, }, 142 { BFD_RELOC_X86_64_DTPOFF64, R_X86_64_DTPOFF64, }, 143 { BFD_RELOC_X86_64_TPOFF64, R_X86_64_TPOFF64, }, 144 { BFD_RELOC_X86_64_TLSGD, R_X86_64_TLSGD, }, 145 { BFD_RELOC_X86_64_TLSLD, R_X86_64_TLSLD, }, 146 { BFD_RELOC_X86_64_DTPOFF32, R_X86_64_DTPOFF32, }, 147 { BFD_RELOC_X86_64_GOTTPOFF, R_X86_64_GOTTPOFF, }, 148 { BFD_RELOC_X86_64_TPOFF32, R_X86_64_TPOFF32, }, 149 { BFD_RELOC_VTABLE_INHERIT, R_X86_64_GNU_VTINHERIT, }, 150 { BFD_RELOC_VTABLE_ENTRY, R_X86_64_GNU_VTENTRY, }, 110 151 }; 111 152 … … 113 154 PARAMS ((bfd *, bfd_reloc_code_real_type)); 114 155 static void elf64_x86_64_info_to_howto 115 PARAMS ((bfd *, arelent *, Elf64_Internal_Rela *)); 156 PARAMS ((bfd *, arelent *, Elf_Internal_Rela *)); 157 static bfd_boolean elf64_x86_64_grok_prstatus 158 PARAMS ((bfd *, Elf_Internal_Note *)); 159 static bfd_boolean elf64_x86_64_grok_psinfo 160 PARAMS ((bfd *, Elf_Internal_Note *)); 116 161 static struct bfd_link_hash_table *elf64_x86_64_link_hash_table_create 117 162 PARAMS ((bfd *)); 118 119 static struct bfd_hash_entry *elf64_x86_64_link_hash_newfunc 163 static int elf64_x86_64_tls_transition 164 PARAMS ((struct bfd_link_info *, int, int)); 165 static bfd_boolean elf64_x86_64_mkobject 166 PARAMS((bfd *)); 167 static bfd_boolean elf64_x86_64_elf_object_p PARAMS ((bfd *abfd)); 168 static bfd_boolean create_got_section 169 PARAMS((bfd *, struct bfd_link_info *)); 170 static bfd_boolean elf64_x86_64_create_dynamic_sections 171 PARAMS((bfd *, struct bfd_link_info *)); 172 static void elf64_x86_64_copy_indirect_symbol 173 PARAMS ((struct elf_backend_data *, struct elf_link_hash_entry *, 174 struct elf_link_hash_entry *)); 175 static bfd_boolean elf64_x86_64_check_relocs 176 PARAMS ((bfd *, struct bfd_link_info *, asection *sec, 177 const Elf_Internal_Rela *)); 178 static asection *elf64_x86_64_gc_mark_hook 179 PARAMS ((asection *, struct bfd_link_info *, Elf_Internal_Rela *, 180 struct elf_link_hash_entry *, Elf_Internal_Sym *)); 181 182 static bfd_boolean elf64_x86_64_gc_sweep_hook 183 PARAMS ((bfd *, struct bfd_link_info *, asection *, 184 const Elf_Internal_Rela *)); 185 186 static struct bfd_hash_entry *link_hash_newfunc 120 187 PARAMS ((struct bfd_hash_entry *, struct bfd_hash_table *, const char *)); 121 static b oolean elf64_x86_64_adjust_dynamic_symbol188 static bfd_boolean elf64_x86_64_adjust_dynamic_symbol 122 189 PARAMS ((struct bfd_link_info *, struct elf_link_hash_entry *)); 123 190 124 static boolean elf64_x86_64_size_dynamic_sections 191 static bfd_boolean allocate_dynrelocs 192 PARAMS ((struct elf_link_hash_entry *, PTR)); 193 static bfd_boolean readonly_dynrelocs 194 PARAMS ((struct elf_link_hash_entry *, PTR)); 195 static bfd_boolean elf64_x86_64_size_dynamic_sections 125 196 PARAMS ((bfd *, struct bfd_link_info *)); 126 static boolean elf64_x86_64_relocate_section 197 static bfd_vma dtpoff_base 198 PARAMS ((struct bfd_link_info *)); 199 static bfd_vma tpoff 200 PARAMS ((struct bfd_link_info *, bfd_vma)); 201 static bfd_boolean elf64_x86_64_relocate_section 127 202 PARAMS ((bfd *, struct bfd_link_info *, bfd *, asection *, bfd_byte *, 128 203 Elf_Internal_Rela *, Elf_Internal_Sym *, asection **)); 129 static b oolean elf64_x86_64_finish_dynamic_symbol204 static bfd_boolean elf64_x86_64_finish_dynamic_symbol 130 205 PARAMS ((bfd *, struct bfd_link_info *, struct elf_link_hash_entry *, 131 206 Elf_Internal_Sym *sym)); 132 static b oolean elf64_x86_64_finish_dynamic_sections207 static bfd_boolean elf64_x86_64_finish_dynamic_sections 133 208 PARAMS ((bfd *, struct bfd_link_info *)); 209 static enum elf_reloc_type_class elf64_x86_64_reloc_type_class 210 PARAMS ((const Elf_Internal_Rela *)); 134 211 135 212 /* Given a BFD reloc type, return a HOWTO structure. */ … … 144 221 { 145 222 if (x86_64_reloc_map[i].bfd_reloc_val == code) 146 return &x86_64_elf_howto_table[(int) 147 x86_64_reloc_map[i].elf_reloc_val]; 223 return &x86_64_elf_howto_table[i]; 148 224 } 149 225 return 0; … … 156 232 bfd *abfd ATTRIBUTE_UNUSED; 157 233 arelent *cache_ptr; 158 Elf 64_Internal_Rela *dst;159 { 160 unsigned r_type ;234 Elf_Internal_Rela *dst; 235 { 236 unsigned r_type, i; 161 237 162 238 r_type = ELF64_R_TYPE (dst->r_info); 163 BFD_ASSERT (r_type < (unsigned int) R_X86_64_max); 164 cache_ptr->howto = &x86_64_elf_howto_table[r_type]; 239 if (r_type < (unsigned int) R_X86_64_GNU_VTINHERIT) 240 { 241 BFD_ASSERT (r_type <= (unsigned int) R_X86_64_TPOFF32); 242 i = r_type; 243 } 244 else 245 { 246 BFD_ASSERT (r_type < (unsigned int) R_X86_64_max); 247 i = r_type - ((unsigned int) R_X86_64_GNU_VTINHERIT - R_X86_64_TPOFF32 - 1); 248 } 249 cache_ptr->howto = &x86_64_elf_howto_table[i]; 165 250 BFD_ASSERT (r_type == cache_ptr->howto->type); 166 251 } 167 252 168 253 254 /* Support for core dump NOTE sections. */ 255 static bfd_boolean 256 elf64_x86_64_grok_prstatus (abfd, note) 257 bfd *abfd; 258 Elf_Internal_Note *note; 259 { 260 int offset; 261 size_t raw_size; 262 263 switch (note->descsz) 264 { 265 default: 266 return FALSE; 267 268 case 336: /* sizeof(istruct elf_prstatus) on Linux/x86_64 */ 269 /* pr_cursig */ 270 elf_tdata (abfd)->core_signal 271 = bfd_get_16 (abfd, note->descdata + 12); 272 273 /* pr_pid */ 274 elf_tdata (abfd)->core_pid 275 = bfd_get_32 (abfd, note->descdata + 32); 276 277 /* pr_reg */ 278 offset = 112; 279 raw_size = 216; 280 281 break; 282 } 283 284 /* Make a ".reg/999" section. */ 285 return _bfd_elfcore_make_pseudosection (abfd, ".reg", 286 raw_size, note->descpos + offset); 287 } 288 289 static bfd_boolean 290 elf64_x86_64_grok_psinfo (abfd, note) 291 bfd *abfd; 292 Elf_Internal_Note *note; 293 { 294 switch (note->descsz) 295 { 296 default: 297 return FALSE; 298 299 case 136: /* sizeof(struct elf_prpsinfo) on Linux/x86_64 */ 300 elf_tdata (abfd)->core_program 301 = _bfd_elfcore_strndup (abfd, note->descdata + 40, 16); 302 elf_tdata (abfd)->core_command 303 = _bfd_elfcore_strndup (abfd, note->descdata + 56, 80); 304 } 305 306 /* Note that for some reason, a spurious space is tacked 307 onto the end of the args in some (at least one anyway) 308 implementations, so strip it off if it exists. */ 309 310 { 311 char *command = elf_tdata (abfd)->core_command; 312 int n = strlen (command); 313 314 if (0 < n && command[n - 1] == ' ') 315 command[n - 1] = '\0'; 316 } 317 318 return TRUE; 319 } 320 321 169 322 /* Functions for the x86-64 ELF linker. */ 170 323 … … 173 326 174 327 #define ELF_DYNAMIC_INTERPRETER "/lib/ld64.so.1" 328 329 /* If ELIMINATE_COPY_RELOCS is non-zero, the linker will try to avoid 330 copying dynamic variables from a shared lib into an app's dynbss 331 section, and instead use a dynamic relocation to point into the 332 shared lib. */ 333 #define ELIMINATE_COPY_RELOCS 1 175 334 176 335 /* The size in bytes of an entry in the global offset table. */ … … 205 364 206 365 /* The x86-64 linker needs to keep track of the number of relocs that 207 it decides to copy in check_relocs for each symbol. This is so 208 that it can discard PC relative relocs if it doesn't need them when 209 linking with -Bsymbolic. We store the information in a field 210 extending the regular ELF linker hash table. */ 211 212 /* This structure keeps track of the number of PC relative relocs we 213 have copied for a given symbol. */ 214 215 struct elf64_x86_64_pcrel_relocs_copied 366 it decides to copy as dynamic relocs in check_relocs for each symbol. 367 This is so that it can later discard them if they are found to be 368 unnecessary. We store the information in a field extending the 369 regular ELF linker hash table. */ 370 371 struct elf64_x86_64_dyn_relocs 216 372 { 217 373 /* Next section. */ 218 struct elf64_x86_64_pcrel_relocs_copied *next; 219 /* A section in dynobj. */ 220 asection *section; 221 /* Number of relocs copied in this section. */ 374 struct elf64_x86_64_dyn_relocs *next; 375 376 /* The input section of the reloc. */ 377 asection *sec; 378 379 /* Total number of relocs copied for the input section. */ 222 380 bfd_size_type count; 381 382 /* Number of pc-relative relocs copied for the input section. */ 383 bfd_size_type pc_count; 223 384 }; 224 385 … … 227 388 struct elf64_x86_64_link_hash_entry 228 389 { 229 struct elf_link_hash_entry root; 230 231 /* Number of PC relative relocs copied for this symbol. */ 232 struct elf64_x86_64_pcrel_relocs_copied *pcrel_relocs_copied; 390 struct elf_link_hash_entry elf; 391 392 /* Track dynamic relocs copied for this symbol. */ 393 struct elf64_x86_64_dyn_relocs *dyn_relocs; 394 395 #define GOT_UNKNOWN 0 396 #define GOT_NORMAL 1 397 #define GOT_TLS_GD 2 398 #define GOT_TLS_IE 3 399 unsigned char tls_type; 233 400 }; 234 401 235 /* x86-64 ELF linker hash table. */ 402 #define elf64_x86_64_hash_entry(ent) \ 403 ((struct elf64_x86_64_link_hash_entry *)(ent)) 404 405 struct elf64_x86_64_obj_tdata 406 { 407 struct elf_obj_tdata root; 408 409 /* tls_type for each local got entry. */ 410 char *local_got_tls_type; 411 }; 412 413 #define elf64_x86_64_tdata(abfd) \ 414 ((struct elf64_x86_64_obj_tdata *) (abfd)->tdata.any) 415 416 #define elf64_x86_64_local_got_tls_type(abfd) \ 417 (elf64_x86_64_tdata (abfd)->local_got_tls_type) 418 419 420 /* x86-64 ELF linker hash table. */ 236 421 237 422 struct elf64_x86_64_link_hash_table 238 423 { 239 struct elf_link_hash_table root; 424 struct elf_link_hash_table elf; 425 426 /* Short-cuts to get to dynamic linker sections. */ 427 asection *sgot; 428 asection *sgotplt; 429 asection *srelgot; 430 asection *splt; 431 asection *srelplt; 432 asection *sdynbss; 433 asection *srelbss; 434 435 union { 436 bfd_signed_vma refcount; 437 bfd_vma offset; 438 } tls_ld_got; 439 440 /* Small local sym to section mapping cache. */ 441 struct sym_sec_cache sym_sec; 240 442 }; 241 242 /* Declare this now that the above structures are defined. */243 244 static boolean elf64_x86_64_discard_copies245 PARAMS ((struct elf64_x86_64_link_hash_entry *, PTR));246 247 /* Traverse an x86-64 ELF linker hash table. */248 249 #define elf64_x86_64_link_hash_traverse(table, func, info) \250 (elf_link_hash_traverse \251 (&(table)->root, \252 (boolean (*) PARAMS ((struct elf_link_hash_entry *, PTR))) (func), \253 (info)))254 443 255 444 /* Get the x86-64 ELF linker hash table from a link_info structure. */ … … 261 450 262 451 static struct bfd_hash_entry * 263 elf64_x86_64_link_hash_newfunc (entry, table, string)452 link_hash_newfunc (entry, table, string) 264 453 struct bfd_hash_entry *entry; 265 454 struct bfd_hash_table *table; 266 455 const char *string; 267 456 { 268 struct elf64_x86_64_link_hash_entry *ret =269 (struct elf64_x86_64_link_hash_entry *) entry;270 271 457 /* Allocate the structure if it has not already been allocated by a 272 subclass. */ 273 if (ret == (struct elf64_x86_64_link_hash_entry *) NULL) 274 ret = ((struct elf64_x86_64_link_hash_entry *) 275 bfd_hash_allocate (table, 276 sizeof (struct elf64_x86_64_link_hash_entry))); 277 if (ret == (struct elf64_x86_64_link_hash_entry *) NULL) 278 return (struct bfd_hash_entry *) ret; 458 subclass. */ 459 if (entry == NULL) 460 { 461 entry = bfd_hash_allocate (table, 462 sizeof (struct elf64_x86_64_link_hash_entry)); 463 if (entry == NULL) 464 return entry; 465 } 279 466 280 467 /* Call the allocation method of the superclass. */ 281 ret = ((struct elf64_x86_64_link_hash_entry *) 282 _bfd_elf_link_hash_newfunc ((struct bfd_hash_entry *) ret, 283 table, string)); 284 if (ret != (struct elf64_x86_64_link_hash_entry *) NULL) 285 { 286 ret->pcrel_relocs_copied = NULL; 287 } 288 289 return (struct bfd_hash_entry *) ret; 468 entry = _bfd_elf_link_hash_newfunc (entry, table, string); 469 if (entry != NULL) 470 { 471 struct elf64_x86_64_link_hash_entry *eh; 472 473 eh = (struct elf64_x86_64_link_hash_entry *) entry; 474 eh->dyn_relocs = NULL; 475 eh->tls_type = GOT_UNKNOWN; 476 } 477 478 return entry; 290 479 } 291 480 … … 297 486 { 298 487 struct elf64_x86_64_link_hash_table *ret; 299 300 ret = ((struct elf64_x86_64_link_hash_table *) 301 bfd_alloc (abfd, sizeof (struct elf64_x86_64_link_hash_table)));302 if (ret == (struct elf64_x86_64_link_hash_table *)NULL)488 bfd_size_type amt = sizeof (struct elf64_x86_64_link_hash_table); 489 490 ret = (struct elf64_x86_64_link_hash_table *) bfd_malloc (amt); 491 if (ret == NULL) 303 492 return NULL; 304 493 305 if (! _bfd_elf_link_hash_table_init (&ret->root, abfd, 306 elf64_x86_64_link_hash_newfunc)) 307 { 308 bfd_release (abfd, ret); 494 if (! _bfd_elf_link_hash_table_init (&ret->elf, abfd, link_hash_newfunc)) 495 { 496 free (ret); 309 497 return NULL; 310 498 } 311 499 312 return &ret->root.root; 500 ret->sgot = NULL; 501 ret->sgotplt = NULL; 502 ret->srelgot = NULL; 503 ret->splt = NULL; 504 ret->srelplt = NULL; 505 ret->sdynbss = NULL; 506 ret->srelbss = NULL; 507 ret->sym_sec.abfd = NULL; 508 ret->tls_ld_got.refcount = 0; 509 510 return &ret->elf.root; 313 511 } 314 512 315 boolean 513 /* Create .got, .gotplt, and .rela.got sections in DYNOBJ, and set up 514 shortcuts to them in our hash table. */ 515 516 static bfd_boolean 517 create_got_section (dynobj, info) 518 bfd *dynobj; 519 struct bfd_link_info *info; 520 { 521 struct elf64_x86_64_link_hash_table *htab; 522 523 if (! _bfd_elf_create_got_section (dynobj, info)) 524 return FALSE; 525 526 htab = elf64_x86_64_hash_table (info); 527 htab->sgot = bfd_get_section_by_name (dynobj, ".got"); 528 htab->sgotplt = bfd_get_section_by_name (dynobj, ".got.plt"); 529 if (!htab->sgot || !htab->sgotplt) 530 abort (); 531 532 htab->srelgot = bfd_make_section (dynobj, ".rela.got"); 533 if (htab->srelgot == NULL 534 || ! bfd_set_section_flags (dynobj, htab->srelgot, 535 (SEC_ALLOC | SEC_LOAD | SEC_HAS_CONTENTS 536 | SEC_IN_MEMORY | SEC_LINKER_CREATED 537 | SEC_READONLY)) 538 || ! bfd_set_section_alignment (dynobj, htab->srelgot, 3)) 539 return FALSE; 540 return TRUE; 541 } 542 543 /* Create .plt, .rela.plt, .got, .got.plt, .rela.got, .dynbss, and 544 .rela.bss sections in DYNOBJ, and set up shortcuts to them in our 545 hash table. */ 546 547 static bfd_boolean 548 elf64_x86_64_create_dynamic_sections (dynobj, info) 549 bfd *dynobj; 550 struct bfd_link_info *info; 551 { 552 struct elf64_x86_64_link_hash_table *htab; 553 554 htab = elf64_x86_64_hash_table (info); 555 if (!htab->sgot && !create_got_section (dynobj, info)) 556 return FALSE; 557 558 if (!_bfd_elf_create_dynamic_sections (dynobj, info)) 559 return FALSE; 560 561 htab->splt = bfd_get_section_by_name (dynobj, ".plt"); 562 htab->srelplt = bfd_get_section_by_name (dynobj, ".rela.plt"); 563 htab->sdynbss = bfd_get_section_by_name (dynobj, ".dynbss"); 564 if (!info->shared) 565 htab->srelbss = bfd_get_section_by_name (dynobj, ".rela.bss"); 566 567 if (!htab->splt || !htab->srelplt || !htab->sdynbss 568 || (!info->shared && !htab->srelbss)) 569 abort (); 570 571 return TRUE; 572 } 573 574 /* Copy the extra info we tack onto an elf_link_hash_entry. */ 575 576 static void 577 elf64_x86_64_copy_indirect_symbol (bed, dir, ind) 578 struct elf_backend_data *bed; 579 struct elf_link_hash_entry *dir, *ind; 580 { 581 struct elf64_x86_64_link_hash_entry *edir, *eind; 582 583 edir = (struct elf64_x86_64_link_hash_entry *) dir; 584 eind = (struct elf64_x86_64_link_hash_entry *) ind; 585 586 if (eind->dyn_relocs != NULL) 587 { 588 if (edir->dyn_relocs != NULL) 589 { 590 struct elf64_x86_64_dyn_relocs **pp; 591 struct elf64_x86_64_dyn_relocs *p; 592 593 if (ind->root.type == bfd_link_hash_indirect) 594 abort (); 595 596 /* Add reloc counts against the weak sym to the strong sym 597 list. Merge any entries against the same section. */ 598 for (pp = &eind->dyn_relocs; (p = *pp) != NULL; ) 599 { 600 struct elf64_x86_64_dyn_relocs *q; 601 602 for (q = edir->dyn_relocs; q != NULL; q = q->next) 603 if (q->sec == p->sec) 604 { 605 q->pc_count += p->pc_count; 606 q->count += p->count; 607 *pp = p->next; 608 break; 609 } 610 if (q == NULL) 611 pp = &p->next; 612 } 613 *pp = edir->dyn_relocs; 614 } 615 616 edir->dyn_relocs = eind->dyn_relocs; 617 eind->dyn_relocs = NULL; 618 } 619 620 if (ind->root.type == bfd_link_hash_indirect 621 && dir->got.refcount <= 0) 622 { 623 edir->tls_type = eind->tls_type; 624 eind->tls_type = GOT_UNKNOWN; 625 } 626 627 if (ELIMINATE_COPY_RELOCS 628 && ind->root.type != bfd_link_hash_indirect 629 && (dir->elf_link_hash_flags & ELF_LINK_HASH_DYNAMIC_ADJUSTED) != 0) 630 /* If called to transfer flags for a weakdef during processing 631 of elf_adjust_dynamic_symbol, don't copy ELF_LINK_NON_GOT_REF. 632 We clear it ourselves for ELIMINATE_COPY_RELOCS. */ 633 dir->elf_link_hash_flags |= 634 (ind->elf_link_hash_flags & (ELF_LINK_HASH_REF_DYNAMIC 635 | ELF_LINK_HASH_REF_REGULAR 636 | ELF_LINK_HASH_REF_REGULAR_NONWEAK)); 637 else 638 _bfd_elf_link_hash_copy_indirect (bed, dir, ind); 639 } 640 641 static bfd_boolean 642 elf64_x86_64_mkobject (abfd) 643 bfd *abfd; 644 { 645 bfd_size_type amt = sizeof (struct elf64_x86_64_obj_tdata); 646 abfd->tdata.any = bfd_zalloc (abfd, amt); 647 if (abfd->tdata.any == NULL) 648 return FALSE; 649 return TRUE; 650 } 651 652 static bfd_boolean 316 653 elf64_x86_64_elf_object_p (abfd) 317 bfd *abfd; 318 { 654 bfd *abfd; 655 { 656 /* Allocate our special target data. */ 657 struct elf64_x86_64_obj_tdata *new_tdata; 658 bfd_size_type amt = sizeof (struct elf64_x86_64_obj_tdata); 659 new_tdata = bfd_zalloc (abfd, amt); 660 if (new_tdata == NULL) 661 return FALSE; 662 new_tdata->root = *abfd->tdata.elf_obj_data; 663 abfd->tdata.any = new_tdata; 319 664 /* Set the right machine number for an x86-64 elf64 file. */ 320 665 bfd_default_set_arch_mach (abfd, bfd_arch_i386, bfd_mach_x86_64); 321 return true;666 return TRUE; 322 667 } 323 668 669 static int 670 elf64_x86_64_tls_transition (info, r_type, is_local) 671 struct bfd_link_info *info; 672 int r_type; 673 int is_local; 674 { 675 if (info->shared) 676 return r_type; 677 678 switch (r_type) 679 { 680 case R_X86_64_TLSGD: 681 case R_X86_64_GOTTPOFF: 682 if (is_local) 683 return R_X86_64_TPOFF32; 684 return R_X86_64_GOTTPOFF; 685 case R_X86_64_TLSLD: 686 return R_X86_64_TPOFF32; 687 } 688 689 return r_type; 690 } 691 324 692 /* Look through the relocs for a section during the first phase, and 325 allocate space in the global offset table or procedure linkage326 table. */327 328 static b oolean693 calculate needed space in the global offset table, procedure 694 linkage table, and dynamic reloc sections. */ 695 696 static bfd_boolean 329 697 elf64_x86_64_check_relocs (abfd, info, sec, relocs) 330 698 bfd *abfd; … … 333 701 const Elf_Internal_Rela *relocs; 334 702 { 335 bfd *dynobj;703 struct elf64_x86_64_link_hash_table *htab; 336 704 Elf_Internal_Shdr *symtab_hdr; 337 705 struct elf_link_hash_entry **sym_hashes; 338 bfd_signed_vma *local_got_refcounts;339 706 const Elf_Internal_Rela *rel; 340 707 const Elf_Internal_Rela *rel_end; 341 asection *sgot;342 asection *srelgot;343 708 asection *sreloc; 344 709 345 710 if (info->relocateable) 346 return true;347 348 dynobj = elf_hash_table (info)->dynobj;711 return TRUE; 712 713 htab = elf64_x86_64_hash_table (info); 349 714 symtab_hdr = &elf_tdata (abfd)->symtab_hdr; 350 715 sym_hashes = elf_sym_hashes (abfd); 351 local_got_refcounts = elf_local_got_refcounts (abfd); 352 353 sgot = srelgot = sreloc = NULL; 716 717 sreloc = NULL; 718 354 719 rel_end = relocs + sec->reloc_count; 355 720 for (rel = relocs; rel < rel_end; rel++) 356 721 { 722 unsigned int r_type; 357 723 unsigned long r_symndx; 358 724 struct elf_link_hash_entry *h; 359 725 360 726 r_symndx = ELF64_R_SYM (rel->r_info); 727 r_type = ELF64_R_TYPE (rel->r_info); 728 729 if (r_symndx >= NUM_SHDR_ENTRIES (symtab_hdr)) 730 { 731 (*_bfd_error_handler) (_("%s: bad symbol index: %d"), 732 bfd_archive_filename (abfd), 733 r_symndx); 734 return FALSE; 735 } 736 361 737 if (r_symndx < symtab_hdr->sh_info) 362 738 h = NULL; … … 364 740 h = sym_hashes[r_symndx - symtab_hdr->sh_info]; 365 741 366 /* Some relocs require a global offset table. */ 367 if (dynobj == NULL) 368 { 369 switch (ELF64_R_TYPE (rel->r_info)) 370 { 371 case R_X86_64_GOT32: 372 case R_X86_64_GOTPCREL: 373 elf_hash_table (info)->dynobj = dynobj = abfd; 374 if (! _bfd_elf_create_got_section (dynobj, info)) 375 return false; 376 break; 377 } 378 } 379 380 switch (ELF64_R_TYPE (rel->r_info)) 381 { 742 r_type = elf64_x86_64_tls_transition (info, r_type, h == NULL); 743 switch (r_type) 744 { 745 case R_X86_64_TLSLD: 746 htab->tls_ld_got.refcount += 1; 747 goto create_got; 748 749 case R_X86_64_TPOFF32: 750 if (info->shared) 751 { 752 (*_bfd_error_handler) 753 (_("%s: relocation %s can not be used when making a shared object; recompile with -fPIC"), 754 bfd_archive_filename (abfd), 755 x86_64_elf_howto_table[r_type].name); 756 bfd_set_error (bfd_error_bad_value); 757 return FALSE; 758 } 759 break; 760 761 case R_X86_64_GOTTPOFF: 762 if (info->shared) 763 info->flags |= DF_STATIC_TLS; 764 /* Fall through */ 765 766 case R_X86_64_GOT32: 382 767 case R_X86_64_GOTPCREL: 383 case R_X86_64_ GOT32:768 case R_X86_64_TLSGD: 384 769 /* This symbol requires a global offset table entry. */ 385 386 if (sgot == NULL) 387 { 388 sgot = bfd_get_section_by_name (dynobj, ".got"); 389 BFD_ASSERT (sgot != NULL); 390 } 391 392 if (srelgot == NULL && (h != NULL || info->shared)) 393 { 394 srelgot = bfd_get_section_by_name (dynobj, ".rela.got"); 395 if (srelgot == NULL) 396 { 397 srelgot = bfd_make_section (dynobj, ".rela.got"); 398 if (srelgot == NULL 399 || ! bfd_set_section_flags (dynobj, srelgot, 400 (SEC_ALLOC 401 | SEC_LOAD 402 | SEC_HAS_CONTENTS 403 | SEC_IN_MEMORY 404 | SEC_LINKER_CREATED 405 | SEC_READONLY)) 406 || ! bfd_set_section_alignment (dynobj, srelgot, 3)) 407 return false; 408 } 409 } 410 411 if (h != NULL) 412 { 413 if (h->got.refcount == -1) 414 { 415 h->got.refcount = 1; 416 417 /* Make sure this symbol is output as a dynamic symbol. */ 418 if (h->dynindx == -1) 419 { 420 if (! bfd_elf64_link_record_dynamic_symbol (info, h)) 421 return false; 422 } 423 424 sgot->_raw_size += GOT_ENTRY_SIZE; 425 srelgot->_raw_size += sizeof (Elf64_External_Rela); 426 } 427 else 770 { 771 int tls_type, old_tls_type; 772 773 switch (r_type) 774 { 775 default: tls_type = GOT_NORMAL; break; 776 case R_X86_64_TLSGD: tls_type = GOT_TLS_GD; break; 777 case R_X86_64_GOTTPOFF: tls_type = GOT_TLS_IE; break; 778 } 779 780 if (h != NULL) 781 { 428 782 h->got.refcount += 1; 429 } 430 else 431 { 432 /* This is a global offset table entry for a local symbol. */ 433 if (local_got_refcounts == NULL) 434 { 435 size_t size; 436 437 size = symtab_hdr->sh_info * sizeof (bfd_signed_vma); 438 local_got_refcounts = ((bfd_signed_vma *) 439 bfd_alloc (abfd, size)); 440 if (local_got_refcounts == NULL) 441 return false; 442 elf_local_got_refcounts (abfd) = local_got_refcounts; 443 memset (local_got_refcounts, -1, size); 444 } 445 if (local_got_refcounts[r_symndx] == -1) 446 { 447 local_got_refcounts[r_symndx] = 1; 448 449 sgot->_raw_size += GOT_ENTRY_SIZE; 450 if (info->shared) 451 { 452 /* If we are generating a shared object, we need to 453 output a R_X86_64_RELATIVE reloc so that the dynamic 454 linker can adjust this GOT entry. */ 455 srelgot->_raw_size += sizeof (Elf64_External_Rela); 456 } 457 } 458 else 783 old_tls_type = elf64_x86_64_hash_entry (h)->tls_type; 784 } 785 else 786 { 787 bfd_signed_vma *local_got_refcounts; 788 789 /* This is a global offset table entry for a local symbol. */ 790 local_got_refcounts = elf_local_got_refcounts (abfd); 791 if (local_got_refcounts == NULL) 792 { 793 bfd_size_type size; 794 795 size = symtab_hdr->sh_info; 796 size *= sizeof (bfd_signed_vma) + sizeof (char); 797 local_got_refcounts = ((bfd_signed_vma *) 798 bfd_zalloc (abfd, size)); 799 if (local_got_refcounts == NULL) 800 return FALSE; 801 elf_local_got_refcounts (abfd) = local_got_refcounts; 802 elf64_x86_64_local_got_tls_type (abfd) 803 = (char *) (local_got_refcounts + symtab_hdr->sh_info); 804 } 459 805 local_got_refcounts[r_symndx] += 1; 806 old_tls_type 807 = elf64_x86_64_local_got_tls_type (abfd) [r_symndx]; 808 } 809 810 /* If a TLS symbol is accessed using IE at least once, 811 there is no point to use dynamic model for it. */ 812 if (old_tls_type != tls_type && old_tls_type != GOT_UNKNOWN 813 && (old_tls_type != GOT_TLS_GD || tls_type != GOT_TLS_IE)) 814 { 815 if (old_tls_type == GOT_TLS_IE && tls_type == GOT_TLS_GD) 816 tls_type = old_tls_type; 817 else 818 { 819 (*_bfd_error_handler) 820 (_("%s: %s' accessed both as normal and thread local symbol"), 821 bfd_archive_filename (abfd), 822 h ? h->root.root.string : "<local>"); 823 return FALSE; 824 } 825 } 826 827 if (old_tls_type != tls_type) 828 { 829 if (h != NULL) 830 elf64_x86_64_hash_entry (h)->tls_type = tls_type; 831 else 832 elf64_x86_64_local_got_tls_type (abfd) [r_symndx] = tls_type; 833 } 834 } 835 /* Fall through */ 836 837 //case R_X86_64_GOTPCREL: 838 create_got: 839 if (htab->sgot == NULL) 840 { 841 if (htab->elf.dynobj == NULL) 842 htab->elf.dynobj = abfd; 843 if (!create_got_section (htab->elf.dynobj, info)) 844 return FALSE; 460 845 } 461 846 break; … … 475 860 476 861 h->elf_link_hash_flags |= ELF_LINK_HASH_NEEDS_PLT; 477 if (h->plt.refcount == -1) 478 h->plt.refcount = 1; 479 else 480 h->plt.refcount += 1; 862 h->plt.refcount += 1; 481 863 break; 482 864 … … 484 866 case R_X86_64_16: 485 867 case R_X86_64_32: 868 case R_X86_64_32S: 869 /* Let's help debug shared library creation. These relocs 870 cannot be used in shared libs. Don't error out for 871 sections we don't care about, such as debug sections or 872 non-constant sections. */ 873 if (info->shared 874 && (sec->flags & SEC_ALLOC) != 0 875 && (sec->flags & SEC_READONLY) != 0) 876 { 877 (*_bfd_error_handler) 878 (_("%s: relocation %s can not be used when making a shared object; recompile with -fPIC"), 879 bfd_archive_filename (abfd), 880 x86_64_elf_howto_table[r_type].name); 881 bfd_set_error (bfd_error_bad_value); 882 return FALSE; 883 } 884 /* Fall through. */ 885 886 case R_X86_64_PC8: 887 case R_X86_64_PC16: 888 case R_X86_64_PC32: 486 889 case R_X86_64_64: 487 case R_X86_64_32S: 488 case R_X86_64_PC32: 489 if (h != NULL) 490 h->elf_link_hash_flags |= ELF_LINK_NON_GOT_REF; 890 if (h != NULL && !info->shared) 891 { 892 /* If this reloc is in a read-only section, we might 893 need a copy reloc. We can't check reliably at this 894 stage whether the section is read-only, as input 895 sections have not yet been mapped to output sections. 896 Tentatively set the flag for now, and correct in 897 adjust_dynamic_symbol. */ 898 h->elf_link_hash_flags |= ELF_LINK_NON_GOT_REF; 899 900 /* We may need a .plt entry if the function this reloc 901 refers to is in a shared lib. */ 902 h->plt.refcount += 1; 903 } 491 904 492 905 /* If we are creating a shared library, and this is a reloc … … 499 912 this point we have not seen all the input files, so it is 500 913 possible that DEF_REGULAR is not set now but will be set 501 later (it is never cleared). We account for that 502 possibility below by storing information in the 503 pcrel_relocs_copied field of the hash table entry. 504 A similar situation occurs when creating shared libraries 505 and symbol visibility changes render the symbol local. */ 506 if (info->shared 507 && (sec->flags & SEC_ALLOC) != 0 508 && (((ELF64_R_TYPE (rel->r_info) != R_X86_64_PC8) 509 && (ELF64_R_TYPE (rel->r_info) != R_X86_64_PC16) 510 && (ELF64_R_TYPE (rel->r_info) != R_X86_64_PC32)) 511 || (h != NULL 512 && (! info->symbolic 513 || (h->elf_link_hash_flags 514 & ELF_LINK_HASH_DEF_REGULAR) == 0)))) 515 { 516 /* When creating a shared object, we must copy these 517 reloc types into the output file. We create a reloc 518 section in dynobj and make room for this reloc. */ 914 later (it is never cleared). In case of a weak definition, 915 DEF_REGULAR may be cleared later by a strong definition in 916 a shared library. We account for that possibility below by 917 storing information in the relocs_copied field of the hash 918 table entry. A similar situation occurs when creating 919 shared libraries and symbol visibility changes render the 920 symbol local. 921 922 If on the other hand, we are creating an executable, we 923 may need to keep relocations for symbols satisfied by a 924 dynamic library if we manage to avoid copy relocs for the 925 symbol. */ 926 if ((info->shared 927 && (sec->flags & SEC_ALLOC) != 0 928 && (((r_type != R_X86_64_PC8) 929 && (r_type != R_X86_64_PC16) 930 && (r_type != R_X86_64_PC32)) 931 || (h != NULL 932 && (! info->symbolic 933 || h->root.type == bfd_link_hash_defweak 934 || (h->elf_link_hash_flags 935 & ELF_LINK_HASH_DEF_REGULAR) == 0)))) 936 || (ELIMINATE_COPY_RELOCS 937 && !info->shared 938 && (sec->flags & SEC_ALLOC) != 0 939 && h != NULL 940 && (h->root.type == bfd_link_hash_defweak 941 || (h->elf_link_hash_flags 942 & ELF_LINK_HASH_DEF_REGULAR) == 0))) 943 { 944 struct elf64_x86_64_dyn_relocs *p; 945 struct elf64_x86_64_dyn_relocs **head; 946 947 /* We must copy these reloc types into the output file. 948 Create a reloc section in dynobj and make room for 949 this reloc. */ 519 950 if (sreloc == NULL) 520 951 { 521 952 const char *name; 953 bfd *dynobj; 522 954 523 955 name = (bfd_elf_string_from_elf_section … … 526 958 elf_section_data (sec)->rel_hdr.sh_name)); 527 959 if (name == NULL) 528 return false; 529 530 BFD_ASSERT (strncmp (name, ".rela", 5) == 0 531 && strcmp (bfd_get_section_name (abfd, sec), 532 name + 5) == 0); 960 return FALSE; 961 962 if (strncmp (name, ".rela", 5) != 0 963 || strcmp (bfd_get_section_name (abfd, sec), 964 name + 5) != 0) 965 { 966 (*_bfd_error_handler) 967 (_("%s: bad relocation section name `%s\'"), 968 bfd_archive_filename (abfd), name); 969 } 970 971 if (htab->elf.dynobj == NULL) 972 htab->elf.dynobj = abfd; 973 974 dynobj = htab->elf.dynobj; 533 975 534 976 sreloc = bfd_get_section_by_name (dynobj, name); … … 545 987 || ! bfd_set_section_flags (dynobj, sreloc, flags) 546 988 || ! bfd_set_section_alignment (dynobj, sreloc, 3)) 547 return false;989 return FALSE; 548 990 } 991 elf_section_data (sec)->sreloc = sreloc; 549 992 } 550 993 551 sreloc->_raw_size += sizeof (Elf64_External_Rela); 552 553 /* If this is a global symbol, we count the number of PC 554 relative relocations we have entered for this symbol, 555 so that we can discard them later as necessary. Note 556 that this function is only called if we are using an 557 elf64_x86_64 linker hash table, which means that h is 558 really a pointer to an elf64_x86_64_link_hash_entry. */ 559 if (h != NULL 560 && ((ELF64_R_TYPE (rel->r_info) == R_X86_64_PC8) 561 || (ELF64_R_TYPE (rel->r_info) == R_X86_64_PC16) 562 || (ELF64_R_TYPE (rel->r_info) == R_X86_64_PC32))) 994 /* If this is a global symbol, we count the number of 995 relocations we need for this symbol. */ 996 if (h != NULL) 563 997 { 564 struct elf64_x86_64_link_hash_entry *eh; 565 struct elf64_x86_64_pcrel_relocs_copied *p; 566 567 eh = (struct elf64_x86_64_link_hash_entry *) h; 568 569 for (p = eh->pcrel_relocs_copied; p != NULL; p = p->next) 570 if (p->section == sreloc) 571 break; 572 998 head = &((struct elf64_x86_64_link_hash_entry *) h)->dyn_relocs; 999 } 1000 else 1001 { 1002 /* Track dynamic relocs needed for local syms too. 1003 We really need local syms available to do this 1004 easily. Oh well. */ 1005 1006 asection *s; 1007 s = bfd_section_from_r_symndx (abfd, &htab->sym_sec, 1008 sec, r_symndx); 1009 if (s == NULL) 1010 return FALSE; 1011 1012 head = ((struct elf64_x86_64_dyn_relocs **) 1013 &elf_section_data (s)->local_dynrel); 1014 } 1015 1016 p = *head; 1017 if (p == NULL || p->sec != sec) 1018 { 1019 bfd_size_type amt = sizeof *p; 1020 p = ((struct elf64_x86_64_dyn_relocs *) 1021 bfd_alloc (htab->elf.dynobj, amt)); 573 1022 if (p == NULL) 574 { 575 p = ((struct elf64_x86_64_pcrel_relocs_copied *) 576 bfd_alloc (dynobj, sizeof *p)); 577 if (p == NULL) 578 return false; 579 p->next = eh->pcrel_relocs_copied; 580 eh->pcrel_relocs_copied = p; 581 p->section = sreloc; 582 p->count = 0; 583 } 584 585 ++p->count; 1023 return FALSE; 1024 p->next = *head; 1025 *head = p; 1026 p->sec = sec; 1027 p->count = 0; 1028 p->pc_count = 0; 586 1029 } 1030 1031 p->count += 1; 1032 if (r_type == R_X86_64_PC8 1033 || r_type == R_X86_64_PC16 1034 || r_type == R_X86_64_PC32) 1035 p->pc_count += 1; 587 1036 } 588 1037 break; 589 } 590 } 591 592 return true; 1038 1039 /* This relocation describes the C++ object vtable hierarchy. 1040 Reconstruct it for later use during GC. */ 1041 case R_X86_64_GNU_VTINHERIT: 1042 if (!_bfd_elf64_gc_record_vtinherit (abfd, sec, h, rel->r_offset)) 1043 return FALSE; 1044 break; 1045 1046 /* This relocation describes which C++ vtable entries are actually 1047 used. Record for later use during GC. */ 1048 case R_X86_64_GNU_VTENTRY: 1049 if (!_bfd_elf64_gc_record_vtentry (abfd, sec, h, rel->r_addend)) 1050 return FALSE; 1051 break; 1052 1053 default: 1054 break; 1055 } 1056 } 1057 1058 return TRUE; 593 1059 } 594 1060 … … 597 1063 598 1064 static asection * 599 elf64_x86_64_gc_mark_hook ( abfd, info, rel, h, sym)600 bfd *abfd;1065 elf64_x86_64_gc_mark_hook (sec, info, rel, h, sym) 1066 asection *sec; 601 1067 struct bfd_link_info *info ATTRIBUTE_UNUSED; 602 Elf_Internal_Rela *rel ATTRIBUTE_UNUSED;1068 Elf_Internal_Rela *rel; 603 1069 struct elf_link_hash_entry *h; 604 1070 Elf_Internal_Sym *sym; … … 606 1072 if (h != NULL) 607 1073 { 608 switch (h->root.type) 609 { 610 case bfd_link_hash_defined: 611 case bfd_link_hash_defweak: 612 return h->root.u.def.section; 613 614 case bfd_link_hash_common: 615 return h->root.u.c.p->section; 1074 switch (ELF64_R_TYPE (rel->r_info)) 1075 { 1076 case R_X86_64_GNU_VTINHERIT: 1077 case R_X86_64_GNU_VTENTRY: 1078 break; 616 1079 617 1080 default: 618 break; 1081 switch (h->root.type) 1082 { 1083 case bfd_link_hash_defined: 1084 case bfd_link_hash_defweak: 1085 return h->root.u.def.section; 1086 1087 case bfd_link_hash_common: 1088 return h->root.u.c.p->section; 1089 1090 default: 1091 break; 1092 } 619 1093 } 620 1094 } 621 1095 else 622 { 623 if (!(elf_bad_symtab (abfd) 624 && ELF_ST_BIND (sym->st_info) != STB_LOCAL) 625 && ! ((sym->st_shndx <= 0 || sym->st_shndx >= SHN_LORESERVE) 626 && sym->st_shndx != SHN_COMMON)) 627 { 628 return bfd_section_from_elf_index (abfd, sym->st_shndx); 629 } 630 } 1096 return bfd_section_from_elf_index (sec->owner, sym->st_shndx); 631 1097 632 1098 return NULL; … … 635 1101 /* Update the got entry reference counts for the section being removed. */ 636 1102 637 static b oolean1103 static bfd_boolean 638 1104 elf64_x86_64_gc_sweep_hook (abfd, info, sec, relocs) 639 1105 bfd *abfd; 640 struct bfd_link_info *info ATTRIBUTE_UNUSED;1106 struct bfd_link_info *info; 641 1107 asection *sec; 642 1108 const Elf_Internal_Rela *relocs; … … 646 1112 bfd_signed_vma *local_got_refcounts; 647 1113 const Elf_Internal_Rela *rel, *relend; 648 unsigned long r_symndx; 649 struct elf_link_hash_entry *h; 650 bfd *dynobj; 651 asection *sgot; 652 asection *srelgot; 1114 1115 elf_section_data (sec)->local_dynrel = NULL; 653 1116 654 1117 symtab_hdr = &elf_tdata (abfd)->symtab_hdr; … … 656 1119 local_got_refcounts = elf_local_got_refcounts (abfd); 657 1120 658 dynobj = elf_hash_table (info)->dynobj;659 if (dynobj == NULL)660 return true;661 662 sgot = bfd_get_section_by_name (dynobj, ".got");663 srelgot = bfd_get_section_by_name (dynobj, ".rela.got");664 665 1121 relend = relocs + sec->reloc_count; 666 1122 for (rel = relocs; rel < relend; rel++) 667 switch (ELF64_R_TYPE (rel->r_info)) 668 { 669 case R_X86_64_GOT32: 670 case R_X86_64_GOTPCREL: 671 r_symndx = ELF64_R_SYM (rel->r_info); 672 if (r_symndx >= symtab_hdr->sh_info) 673 { 674 h = sym_hashes[r_symndx - symtab_hdr->sh_info]; 675 if (h->got.refcount > 0) 1123 { 1124 unsigned long r_symndx; 1125 unsigned int r_type; 1126 struct elf_link_hash_entry *h = NULL; 1127 1128 r_symndx = ELF64_R_SYM (rel->r_info); 1129 if (r_symndx >= symtab_hdr->sh_info) 1130 { 1131 struct elf64_x86_64_link_hash_entry *eh; 1132 struct elf64_x86_64_dyn_relocs **pp; 1133 struct elf64_x86_64_dyn_relocs *p; 1134 1135 h = sym_hashes[r_symndx - symtab_hdr->sh_info]; 1136 eh = (struct elf64_x86_64_link_hash_entry *) h; 1137 1138 for (pp = &eh->dyn_relocs; (p = *pp) != NULL; pp = &p->next) 1139 if (p->sec == sec) 676 1140 { 1141 /* Everything must go for SEC. */ 1142 *pp = p->next; 1143 break; 1144 } 1145 } 1146 1147 r_type = ELF64_R_TYPE (rel->r_info); 1148 r_type = elf64_x86_64_tls_transition (info, r_type, h != NULL); 1149 switch (r_type) 1150 { 1151 case R_X86_64_TLSLD: 1152 if (elf64_x86_64_hash_table (info)->tls_ld_got.refcount > 0) 1153 elf64_x86_64_hash_table (info)->tls_ld_got.refcount -= 1; 1154 break; 1155 1156 case R_X86_64_TLSGD: 1157 case R_X86_64_GOTTPOFF: 1158 case R_X86_64_GOT32: 1159 case R_X86_64_GOTPCREL: 1160 if (h != NULL) 1161 { 1162 if (h->got.refcount > 0) 677 1163 h->got.refcount -= 1; 678 if (h->got.refcount == 0) 679 { 680 sgot->_raw_size -= GOT_ENTRY_SIZE; 681 srelgot->_raw_size -= sizeof (Elf64_External_Rela); 682 } 683 } 684 } 685 else if (local_got_refcounts != NULL) 686 { 687 if (local_got_refcounts[r_symndx] > 0) 688 { 1164 } 1165 else if (local_got_refcounts != NULL) 1166 { 1167 if (local_got_refcounts[r_symndx] > 0) 689 1168 local_got_refcounts[r_symndx] -= 1; 690 if (local_got_refcounts[r_symndx] == 0) 691 { 692 sgot->_raw_size -= GOT_ENTRY_SIZE; 693 if (info->shared) 694 srelgot->_raw_size -= sizeof (Elf64_External_Rela); 695 } 696 } 697 } 698 break; 699 700 case R_X86_64_PLT32: 701 r_symndx = ELF64_R_SYM (rel->r_info); 702 if (r_symndx >= symtab_hdr->sh_info) 703 { 704 h = sym_hashes[r_symndx - symtab_hdr->sh_info]; 705 if (h->plt.refcount > 0) 706 h->plt.refcount -= 1; 707 } 708 break; 709 710 default: 711 break; 712 } 713 714 return true; 1169 } 1170 break; 1171 1172 case R_X86_64_8: 1173 case R_X86_64_16: 1174 case R_X86_64_32: 1175 case R_X86_64_64: 1176 case R_X86_64_32S: 1177 case R_X86_64_PC8: 1178 case R_X86_64_PC16: 1179 case R_X86_64_PC32: 1180 if (info->shared) 1181 break; 1182 /* Fall thru */ 1183 1184 case R_X86_64_PLT32: 1185 if (h != NULL) 1186 { 1187 if (h->plt.refcount > 0) 1188 h->plt.refcount -= 1; 1189 } 1190 break; 1191 1192 default: 1193 break; 1194 } 1195 } 1196 1197 return TRUE; 715 1198 } 716 1199 … … 721 1204 understand. */ 722 1205 723 static b oolean1206 static bfd_boolean 724 1207 elf64_x86_64_adjust_dynamic_symbol (info, h) 725 1208 struct bfd_link_info *info; 726 1209 struct elf_link_hash_entry *h; 727 1210 { 728 bfd *dynobj;1211 struct elf64_x86_64_link_hash_table *htab; 729 1212 asection *s; 730 1213 unsigned int power_of_two; 731 732 dynobj = elf_hash_table (info)->dynobj;733 734 /* Make sure we know what is going on here. */735 BFD_ASSERT (dynobj != NULL736 && ((h->elf_link_hash_flags & ELF_LINK_HASH_NEEDS_PLT)737 || h->weakdef != NULL738 || ((h->elf_link_hash_flags739 & ELF_LINK_HASH_DEF_DYNAMIC) != 0740 && (h->elf_link_hash_flags741 & ELF_LINK_HASH_REF_REGULAR) != 0742 && (h->elf_link_hash_flags743 & ELF_LINK_HASH_DEF_REGULAR) == 0)));744 1214 745 1215 /* If this is a function, put it in the procedure linkage table. We … … 749 1219 || (h->elf_link_hash_flags & ELF_LINK_HASH_NEEDS_PLT) != 0) 750 1220 { 751 if ((! info->shared 752 && (h->elf_link_hash_flags & ELF_LINK_HASH_DEF_DYNAMIC) == 0 753 && (h->elf_link_hash_flags & ELF_LINK_HASH_REF_DYNAMIC) == 0) 754 || (info->shared && h->plt.refcount <= 0)) 1221 if (h->plt.refcount <= 0 1222 || (! info->shared 1223 && (h->elf_link_hash_flags & ELF_LINK_HASH_DEF_DYNAMIC) == 0 1224 && (h->elf_link_hash_flags & ELF_LINK_HASH_REF_DYNAMIC) == 0 1225 && h->root.type != bfd_link_hash_undefweak 1226 && h->root.type != bfd_link_hash_undefined)) 755 1227 { 756 1228 /* This case can occur if we saw a PLT32 reloc in an input … … 761 1233 h->plt.offset = (bfd_vma) -1; 762 1234 h->elf_link_hash_flags &= ~ELF_LINK_HASH_NEEDS_PLT; 763 return true; 764 } 765 766 /* Make sure this symbol is output as a dynamic symbol. */ 767 if (h->dynindx == -1) 768 { 769 if (! bfd_elf64_link_record_dynamic_symbol (info, h)) 770 return false; 771 } 772 773 s = bfd_get_section_by_name (dynobj, ".plt"); 774 BFD_ASSERT (s != NULL); 775 776 /* If this is the first .plt entry, make room for the special 777 first entry. */ 778 if (s->_raw_size == 0) 779 s->_raw_size = PLT_ENTRY_SIZE; 780 781 /* If this symbol is not defined in a regular file, and we are 782 not generating a shared library, then set the symbol to this 783 location in the .plt. This is required to make function 784 pointers compare as equal between the normal executable and 785 the shared library. */ 786 if (! info->shared 787 && (h->elf_link_hash_flags & ELF_LINK_HASH_DEF_REGULAR) == 0) 788 { 789 h->root.u.def.section = s; 790 h->root.u.def.value = s->_raw_size; 791 } 792 793 h->plt.offset = s->_raw_size; 794 795 /* Make room for this entry. */ 796 s->_raw_size += PLT_ENTRY_SIZE; 797 798 /* We also need to make an entry in the .got.plt section, which 799 will be placed in the .got section by the linker script. */ 800 s = bfd_get_section_by_name (dynobj, ".got.plt"); 801 BFD_ASSERT (s != NULL); 802 s->_raw_size += GOT_ENTRY_SIZE; 803 804 /* We also need to make an entry in the .rela.plt section. */ 805 s = bfd_get_section_by_name (dynobj, ".rela.plt"); 806 BFD_ASSERT (s != NULL); 807 s->_raw_size += sizeof (Elf64_External_Rela); 808 809 return true; 810 } 1235 } 1236 1237 return TRUE; 1238 } 1239 else 1240 /* It's possible that we incorrectly decided a .plt reloc was 1241 needed for an R_X86_64_PC32 reloc to a non-function sym in 1242 check_relocs. We can't decide accurately between function and 1243 non-function syms in check-relocs; Objects loaded later in 1244 the link may change h->type. So fix it now. */ 1245 h->plt.offset = (bfd_vma) -1; 811 1246 812 1247 /* If this is a weak symbol, and there is a real definition, the … … 819 1254 h->root.u.def.section = h->weakdef->root.u.def.section; 820 1255 h->root.u.def.value = h->weakdef->root.u.def.value; 821 return true; 1256 if (ELIMINATE_COPY_RELOCS || info->nocopyreloc) 1257 h->elf_link_hash_flags 1258 = ((h->elf_link_hash_flags & ~ELF_LINK_NON_GOT_REF) 1259 | (h->weakdef->elf_link_hash_flags & ELF_LINK_NON_GOT_REF)); 1260 return TRUE; 822 1261 } 823 1262 … … 830 1269 be handled correctly by relocate_section. */ 831 1270 if (info->shared) 832 return true;1271 return TRUE; 833 1272 834 1273 /* If there are no references to this symbol that do not use the 835 1274 GOT, we don't need to generate a copy reloc. */ 836 1275 if ((h->elf_link_hash_flags & ELF_LINK_NON_GOT_REF) == 0) 837 return true; 1276 return TRUE; 1277 1278 /* If -z nocopyreloc was given, we won't generate them either. */ 1279 if (info->nocopyreloc) 1280 { 1281 h->elf_link_hash_flags &= ~ELF_LINK_NON_GOT_REF; 1282 return TRUE; 1283 } 1284 1285 if (ELIMINATE_COPY_RELOCS) 1286 { 1287 struct elf64_x86_64_link_hash_entry * eh; 1288 struct elf64_x86_64_dyn_relocs *p; 1289 1290 eh = (struct elf64_x86_64_link_hash_entry *) h; 1291 for (p = eh->dyn_relocs; p != NULL; p = p->next) 1292 { 1293 s = p->sec->output_section; 1294 if (s != NULL && (s->flags & SEC_READONLY) != 0) 1295 break; 1296 } 1297 1298 /* If we didn't find any dynamic relocs in read-only sections, then 1299 we'll be keeping the dynamic relocs and avoiding the copy reloc. */ 1300 if (p == NULL) 1301 { 1302 h->elf_link_hash_flags &= ~ELF_LINK_NON_GOT_REF; 1303 return TRUE; 1304 } 1305 } 838 1306 839 1307 /* We must allocate the symbol in our .dynbss section, which will … … 847 1315 same memory location for the variable. */ 848 1316 849 s = bfd_get_section_by_name (dynobj, ".dynbss"); 850 BFD_ASSERT (s != NULL); 1317 htab = elf64_x86_64_hash_table (info); 851 1318 852 1319 /* We must generate a R_X86_64_COPY reloc to tell the dynamic linker 853 1320 to copy the initial value out of the dynamic object and into the 854 runtime process image. We need to remember the offset into the 855 .rela.bss section we are going to use. */ 1321 runtime process image. */ 856 1322 if ((h->root.u.def.section->flags & SEC_ALLOC) != 0) 857 1323 { 858 asection *srel; 859 860 srel = bfd_get_section_by_name (dynobj, ".rela.bss"); 861 BFD_ASSERT (srel != NULL); 862 srel->_raw_size += sizeof (Elf64_External_Rela); 1324 htab->srelbss->_raw_size += sizeof (Elf64_External_Rela); 863 1325 h->elf_link_hash_flags |= ELF_LINK_HASH_NEEDS_COPY; 864 1326 } … … 874 1336 875 1337 /* Apply the required alignment. */ 1338 s = htab->sdynbss; 876 1339 s->_raw_size = BFD_ALIGN (s->_raw_size, (bfd_size_type) (1 << power_of_two)); 877 if (power_of_two > bfd_get_section_alignment ( dynobj, s))878 { 879 if (! bfd_set_section_alignment ( dynobj, s, power_of_two))880 return false;1340 if (power_of_two > bfd_get_section_alignment (htab->elf.dynobj, s)) 1341 { 1342 if (! bfd_set_section_alignment (htab->elf.dynobj, s, power_of_two)) 1343 return FALSE; 881 1344 } 882 1345 … … 888 1351 s->_raw_size += h->size; 889 1352 890 return true;1353 return TRUE; 891 1354 } 892 1355 1356 /* This is the condition under which elf64_x86_64_finish_dynamic_symbol 1357 will be called from elflink.h. If elflink.h doesn't call our 1358 finish_dynamic_symbol routine, we'll need to do something about 1359 initializing any .plt and .got entries in elf64_x86_64_relocate_section. */ 1360 #define WILL_CALL_FINISH_DYNAMIC_SYMBOL(DYN, INFO, H) \ 1361 ((DYN) \ 1362 && ((INFO)->shared \ 1363 || ((H)->elf_link_hash_flags & ELF_LINK_FORCED_LOCAL) == 0) \ 1364 && ((H)->dynindx != -1 \ 1365 || ((H)->elf_link_hash_flags & ELF_LINK_FORCED_LOCAL) != 0)) 1366 1367 /* Allocate space in .plt, .got and associated reloc sections for 1368 dynamic relocs. */ 1369 1370 static bfd_boolean 1371 allocate_dynrelocs (h, inf) 1372 struct elf_link_hash_entry *h; 1373 PTR inf; 1374 { 1375 struct bfd_link_info *info; 1376 struct elf64_x86_64_link_hash_table *htab; 1377 struct elf64_x86_64_link_hash_entry *eh; 1378 struct elf64_x86_64_dyn_relocs *p; 1379 1380 if (h->root.type == bfd_link_hash_indirect) 1381 return TRUE; 1382 1383 if (h->root.type == bfd_link_hash_warning) 1384 h = (struct elf_link_hash_entry *) h->root.u.i.link; 1385 1386 info = (struct bfd_link_info *) inf; 1387 htab = elf64_x86_64_hash_table (info); 1388 1389 if (htab->elf.dynamic_sections_created 1390 && h->plt.refcount > 0) 1391 { 1392 /* Make sure this symbol is output as a dynamic symbol. 1393 Undefined weak syms won't yet be marked as dynamic. */ 1394 if (h->dynindx == -1 1395 && (h->elf_link_hash_flags & ELF_LINK_FORCED_LOCAL) == 0) 1396 { 1397 if (! bfd_elf64_link_record_dynamic_symbol (info, h)) 1398 return FALSE; 1399 } 1400 1401 if (WILL_CALL_FINISH_DYNAMIC_SYMBOL (1, info, h)) 1402 { 1403 asection *s = htab->splt; 1404 1405 /* If this is the first .plt entry, make room for the special 1406 first entry. */ 1407 if (s->_raw_size == 0) 1408 s->_raw_size += PLT_ENTRY_SIZE; 1409 1410 h->plt.offset = s->_raw_size; 1411 1412 /* If this symbol is not defined in a regular file, and we are 1413 not generating a shared library, then set the symbol to this 1414 location in the .plt. This is required to make function 1415 pointers compare as equal between the normal executable and 1416 the shared library. */ 1417 if (! info->shared 1418 && (h->elf_link_hash_flags & ELF_LINK_HASH_DEF_REGULAR) == 0) 1419 { 1420 h->root.u.def.section = s; 1421 h->root.u.def.value = h->plt.offset; 1422 } 1423 1424 /* Make room for this entry. */ 1425 s->_raw_size += PLT_ENTRY_SIZE; 1426 1427 /* We also need to make an entry in the .got.plt section, which 1428 will be placed in the .got section by the linker script. */ 1429 htab->sgotplt->_raw_size += GOT_ENTRY_SIZE; 1430 1431 /* We also need to make an entry in the .rela.plt section. */ 1432 htab->srelplt->_raw_size += sizeof (Elf64_External_Rela); 1433 } 1434 else 1435 { 1436 h->plt.offset = (bfd_vma) -1; 1437 h->elf_link_hash_flags &= ~ELF_LINK_HASH_NEEDS_PLT; 1438 } 1439 } 1440 else 1441 { 1442 h->plt.offset = (bfd_vma) -1; 1443 h->elf_link_hash_flags &= ~ELF_LINK_HASH_NEEDS_PLT; 1444 } 1445 1446 /* If R_X86_64_GOTTPOFF symbol is now local to the binary, 1447 make it a R_X86_64_TPOFF32 requiring no GOT entry. */ 1448 if (h->got.refcount > 0 1449 && !info->shared 1450 && h->dynindx == -1 1451 && elf64_x86_64_hash_entry (h)->tls_type == GOT_TLS_IE) 1452 h->got.offset = (bfd_vma) -1; 1453 else if (h->got.refcount > 0) 1454 { 1455 asection *s; 1456 bfd_boolean dyn; 1457 int tls_type = elf64_x86_64_hash_entry (h)->tls_type; 1458 1459 /* Make sure this symbol is output as a dynamic symbol. 1460 Undefined weak syms won't yet be marked as dynamic. */ 1461 if (h->dynindx == -1 1462 && (h->elf_link_hash_flags & ELF_LINK_FORCED_LOCAL) == 0) 1463 { 1464 if (! bfd_elf64_link_record_dynamic_symbol (info, h)) 1465 return FALSE; 1466 } 1467 1468 s = htab->sgot; 1469 h->got.offset = s->_raw_size; 1470 s->_raw_size += GOT_ENTRY_SIZE; 1471 /* R_X86_64_TLSGD needs 2 consecutive GOT slots. */ 1472 if (tls_type == GOT_TLS_GD) 1473 s->_raw_size += GOT_ENTRY_SIZE; 1474 dyn = htab->elf.dynamic_sections_created; 1475 /* R_X86_64_TLSGD needs one dynamic relocation if local symbol 1476 and two if global. 1477 R_X86_64_GOTTPOFF needs one dynamic relocation. */ 1478 if ((tls_type == GOT_TLS_GD && h->dynindx == -1) 1479 || tls_type == GOT_TLS_IE) 1480 htab->srelgot->_raw_size += sizeof (Elf64_External_Rela); 1481 else if (tls_type == GOT_TLS_GD) 1482 htab->srelgot->_raw_size += 2 * sizeof (Elf64_External_Rela); 1483 else if (WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn, info, h)) 1484 htab->srelgot->_raw_size += sizeof (Elf64_External_Rela); 1485 } 1486 else 1487 h->got.offset = (bfd_vma) -1; 1488 1489 eh = (struct elf64_x86_64_link_hash_entry *) h; 1490 if (eh->dyn_relocs == NULL) 1491 return TRUE; 1492 1493 /* In the shared -Bsymbolic case, discard space allocated for 1494 dynamic pc-relative relocs against symbols which turn out to be 1495 defined in regular objects. For the normal shared case, discard 1496 space for pc-relative relocs that have become local due to symbol 1497 visibility changes. */ 1498 1499 if (info->shared) 1500 { 1501 if ((h->elf_link_hash_flags & ELF_LINK_HASH_DEF_REGULAR) != 0 1502 && ((h->elf_link_hash_flags & ELF_LINK_FORCED_LOCAL) != 0 1503 || info->symbolic)) 1504 { 1505 struct elf64_x86_64_dyn_relocs **pp; 1506 1507 for (pp = &eh->dyn_relocs; (p = *pp) != NULL; ) 1508 { 1509 p->count -= p->pc_count; 1510 p->pc_count = 0; 1511 if (p->count == 0) 1512 *pp = p->next; 1513 else 1514 pp = &p->next; 1515 } 1516 } 1517 } 1518 else if (ELIMINATE_COPY_RELOCS) 1519 { 1520 /* For the non-shared case, discard space for relocs against 1521 symbols which turn out to need copy relocs or are not 1522 dynamic. */ 1523 1524 if ((h->elf_link_hash_flags & ELF_LINK_NON_GOT_REF) == 0 1525 && (((h->elf_link_hash_flags & ELF_LINK_HASH_DEF_DYNAMIC) != 0 1526 && (h->elf_link_hash_flags & ELF_LINK_HASH_DEF_REGULAR) == 0) 1527 || (htab->elf.dynamic_sections_created 1528 && (h->root.type == bfd_link_hash_undefweak 1529 || h->root.type == bfd_link_hash_undefined)))) 1530 { 1531 /* Make sure this symbol is output as a dynamic symbol. 1532 Undefined weak syms won't yet be marked as dynamic. */ 1533 if (h->dynindx == -1 1534 && (h->elf_link_hash_flags & ELF_LINK_FORCED_LOCAL) == 0) 1535 { 1536 if (! bfd_elf64_link_record_dynamic_symbol (info, h)) 1537 return FALSE; 1538 } 1539 1540 /* If that succeeded, we know we'll be keeping all the 1541 relocs. */ 1542 if (h->dynindx != -1) 1543 goto keep; 1544 } 1545 1546 eh->dyn_relocs = NULL; 1547 1548 keep: ; 1549 } 1550 1551 /* Finally, allocate space. */ 1552 for (p = eh->dyn_relocs; p != NULL; p = p->next) 1553 { 1554 asection *sreloc = elf_section_data (p->sec)->sreloc; 1555 sreloc->_raw_size += p->count * sizeof (Elf64_External_Rela); 1556 } 1557 1558 return TRUE; 1559 } 1560 1561 /* Find any dynamic relocs that apply to read-only sections. */ 1562 1563 static bfd_boolean 1564 readonly_dynrelocs (h, inf) 1565 struct elf_link_hash_entry *h; 1566 PTR inf; 1567 { 1568 struct elf64_x86_64_link_hash_entry *eh; 1569 struct elf64_x86_64_dyn_relocs *p; 1570 1571 if (h->root.type == bfd_link_hash_warning) 1572 h = (struct elf_link_hash_entry *) h->root.u.i.link; 1573 1574 eh = (struct elf64_x86_64_link_hash_entry *) h; 1575 for (p = eh->dyn_relocs; p != NULL; p = p->next) 1576 { 1577 asection *s = p->sec->output_section; 1578 1579 if (s != NULL && (s->flags & SEC_READONLY) != 0) 1580 { 1581 struct bfd_link_info *info = (struct bfd_link_info *) inf; 1582 1583 info->flags |= DF_TEXTREL; 1584 1585 /* Not an error, just cut short the traversal. */ 1586 return FALSE; 1587 } 1588 } 1589 return TRUE; 1590 } 1591 893 1592 /* Set the sizes of the dynamic sections. */ 894 1593 895 static b oolean1594 static bfd_boolean 896 1595 elf64_x86_64_size_dynamic_sections (output_bfd, info) 897 bfd *output_bfd ;1596 bfd *output_bfd ATTRIBUTE_UNUSED; 898 1597 struct bfd_link_info *info; 899 1598 { 1599 struct elf64_x86_64_link_hash_table *htab; 900 1600 bfd *dynobj; 901 1601 asection *s; 902 boolean plt; 903 boolean relocs; 904 boolean reltext; 905 906 dynobj = elf_hash_table (info)->dynobj; 907 BFD_ASSERT (dynobj != NULL); 908 909 if (elf_hash_table (info)->dynamic_sections_created) 1602 bfd_boolean relocs; 1603 bfd *ibfd; 1604 1605 htab = elf64_x86_64_hash_table (info); 1606 dynobj = htab->elf.dynobj; 1607 if (dynobj == NULL) 1608 abort (); 1609 1610 if (htab->elf.dynamic_sections_created) 910 1611 { 911 1612 /* Set the contents of the .interp section to the interpreter. */ … … 913 1614 { 914 1615 s = bfd_get_section_by_name (dynobj, ".interp"); 915 BFD_ASSERT (s != NULL); 1616 if (s == NULL) 1617 abort (); 916 1618 s->_raw_size = sizeof ELF_DYNAMIC_INTERPRETER; 917 1619 s->contents = (unsigned char *) ELF_DYNAMIC_INTERPRETER; 918 1620 } 919 1621 } 1622 1623 /* Set up .got offsets for local syms, and space for local dynamic 1624 relocs. */ 1625 for (ibfd = info->input_bfds; ibfd != NULL; ibfd = ibfd->link_next) 1626 { 1627 bfd_signed_vma *local_got; 1628 bfd_signed_vma *end_local_got; 1629 char *local_tls_type; 1630 bfd_size_type locsymcount; 1631 Elf_Internal_Shdr *symtab_hdr; 1632 asection *srel; 1633 1634 if (bfd_get_flavour (ibfd) != bfd_target_elf_flavour) 1635 continue; 1636 1637 for (s = ibfd->sections; s != NULL; s = s->next) 1638 { 1639 struct elf64_x86_64_dyn_relocs *p; 1640 1641 for (p = *((struct elf64_x86_64_dyn_relocs **) 1642 &elf_section_data (s)->local_dynrel); 1643 p != NULL; 1644 p = p->next) 1645 { 1646 if (!bfd_is_abs_section (p->sec) 1647 && bfd_is_abs_section (p->sec->output_section)) 1648 { 1649 /* Input section has been discarded, either because 1650 it is a copy of a linkonce section or due to 1651 linker script /DISCARD/, so we'll be discarding 1652 the relocs too. */ 1653 } 1654 else if (p->count != 0) 1655 { 1656 srel = elf_section_data (p->sec)->sreloc; 1657 srel->_raw_size += p->count * sizeof (Elf64_External_Rela); 1658 if ((p->sec->output_section->flags & SEC_READONLY) != 0) 1659 info->flags |= DF_TEXTREL; 1660 1661 } 1662 } 1663 } 1664 1665 local_got = elf_local_got_refcounts (ibfd); 1666 if (!local_got) 1667 continue; 1668 1669 symtab_hdr = &elf_tdata (ibfd)->symtab_hdr; 1670 locsymcount = symtab_hdr->sh_info; 1671 end_local_got = local_got + locsymcount; 1672 local_tls_type = elf64_x86_64_local_got_tls_type (ibfd); 1673 s = htab->sgot; 1674 srel = htab->srelgot; 1675 for (; local_got < end_local_got; ++local_got, ++local_tls_type) 1676 { 1677 if (*local_got > 0) 1678 { 1679 *local_got = s->_raw_size; 1680 s->_raw_size += GOT_ENTRY_SIZE; 1681 if (*local_tls_type == GOT_TLS_GD) 1682 s->_raw_size += GOT_ENTRY_SIZE; 1683 if (info->shared 1684 || *local_tls_type == GOT_TLS_GD 1685 || *local_tls_type == GOT_TLS_IE) 1686 srel->_raw_size += sizeof (Elf64_External_Rela); 1687 } 1688 else 1689 *local_got = (bfd_vma) -1; 1690 } 1691 } 1692 1693 if (htab->tls_ld_got.refcount > 0) 1694 { 1695 /* Allocate 2 got entries and 1 dynamic reloc for R_X86_64_TLSLD 1696 relocs. */ 1697 htab->tls_ld_got.offset = htab->sgot->_raw_size; 1698 htab->sgot->_raw_size += 2 * GOT_ENTRY_SIZE; 1699 htab->srelgot->_raw_size += sizeof (Elf64_External_Rela); 1700 } 920 1701 else 921 { 922 /* We may have created entries in the .rela.got section. 923 However, if we are not creating the dynamic sections, we will 924 not actually use these entries. Reset the size of .rela.got, 925 which will cause it to get stripped from the output file 926 below. */ 927 s = bfd_get_section_by_name (dynobj, ".rela.got"); 928 if (s != NULL) 929 s->_raw_size = 0; 930 } 931 932 /* If this is a -Bsymbolic shared link, then we need to discard all 933 PC relative relocs against symbols defined in a regular object. 934 We allocated space for them in the check_relocs routine, but we 935 will not fill them in in the relocate_section routine. */ 936 if (info->shared) 937 elf64_x86_64_link_hash_traverse (elf64_x86_64_hash_table (info), 938 elf64_x86_64_discard_copies, 939 (PTR) info); 940 941 /* The check_relocs and adjust_dynamic_symbol entry points have 942 determined the sizes of the various dynamic sections. Allocate 943 memory for them. */ 944 plt = relocs = reltext = false; 1702 htab->tls_ld_got.offset = -1; 1703 1704 /* Allocate global sym .plt and .got entries, and space for global 1705 sym dynamic relocs. */ 1706 elf_link_hash_traverse (&htab->elf, allocate_dynrelocs, (PTR) info); 1707 1708 /* We now have determined the sizes of the various dynamic sections. 1709 Allocate memory for them. */ 1710 relocs = FALSE; 945 1711 for (s = dynobj->sections; s != NULL; s = s->next) 946 1712 { 947 const char *name;948 boolean strip;949 950 1713 if ((s->flags & SEC_LINKER_CREATED) == 0) 951 1714 continue; 952 1715 953 /* It's OK to base decisions on the section name, because none 954 of the dynobj section names depend upon the input files. */ 955 name = bfd_get_section_name (dynobj, s); 956 957 strip = false; 958 if (strcmp (name, ".plt") == 0) 959 { 960 if (s->_raw_size == 0) 961 { 962 /* Strip this section if we don't need it; see the 963 comment below. */ 964 strip = true; 965 } 966 else 967 { 968 /* Remember whether there is a PLT. */ 969 plt = true; 970 } 971 } 972 else if (strncmp (name, ".rela", 5) == 0) 973 { 974 if (s->_raw_size == 0) 975 { 976 /* If we don't need this section, strip it from the 977 output file. This is mostly to handle .rela.bss and 978 .rela.plt. We must create both sections in 979 create_dynamic_sections, because they must be created 980 before the linker maps input sections to output 981 sections. The linker does that before 982 adjust_dynamic_symbol is called, and it is that 983 function which decides whether anything needs to go 984 into these sections. */ 985 strip = true; 986 } 987 else 988 { 989 asection *target; 990 991 /* Remember whether there are any reloc sections other 992 than .rela.plt. */ 993 if (strcmp (name, ".rela.plt") != 0) 994 { 995 const char *outname; 996 997 relocs = true; 998 999 /* If this relocation section applies to a read only 1000 section, then we probably need a DT_TEXTREL 1001 entry. The entries in the .rela.plt section 1002 really apply to the .got section, which we 1003 created ourselves and so know is not readonly. */ 1004 outname = bfd_get_section_name (output_bfd, 1005 s->output_section); 1006 target = bfd_get_section_by_name (output_bfd, outname + 5); 1007 if (target != NULL 1008 && (target->flags & SEC_READONLY) != 0 1009 && (target->flags & SEC_ALLOC) != 0) 1010 reltext = true; 1011 } 1012 1013 /* We use the reloc_count field as a counter if we need 1014 to copy relocs into the output file. */ 1015 s->reloc_count = 0; 1016 } 1017 } 1018 else if (strncmp (name, ".got", 4) != 0) 1716 if (s == htab->splt 1717 || s == htab->sgot 1718 || s == htab->sgotplt) 1719 { 1720 /* Strip this section if we don't need it; see the 1721 comment below. */ 1722 } 1723 else if (strncmp (bfd_get_section_name (dynobj, s), ".rela", 5) == 0) 1724 { 1725 if (s->_raw_size != 0 && s != htab->srelplt) 1726 relocs = TRUE; 1727 1728 /* We use the reloc_count field as a counter if we need 1729 to copy relocs into the output file. */ 1730 s->reloc_count = 0; 1731 } 1732 else 1019 1733 { 1020 1734 /* It's not one of our sections, so don't allocate space. */ … … 1022 1736 } 1023 1737 1024 if (strip) 1025 { 1738 if (s->_raw_size == 0) 1739 { 1740 /* If we don't need this section, strip it from the 1741 output file. This is mostly to handle .rela.bss and 1742 .rela.plt. We must create both sections in 1743 create_dynamic_sections, because they must be created 1744 before the linker maps input sections to output 1745 sections. The linker does that before 1746 adjust_dynamic_symbol is called, and it is that 1747 function which decides whether anything needs to go 1748 into these sections. */ 1749 1026 1750 _bfd_strip_section_from_output (info, s); 1027 1751 continue; … … 1034 1758 of garbage. */ 1035 1759 s->contents = (bfd_byte *) bfd_zalloc (dynobj, s->_raw_size); 1036 if (s->contents == NULL && s->_raw_size != 0)1037 return false;1038 } 1039 1040 if ( elf_hash_table (info)->dynamic_sections_created)1760 if (s->contents == NULL) 1761 return FALSE; 1762 } 1763 1764 if (htab->elf.dynamic_sections_created) 1041 1765 { 1042 1766 /* Add some entries to the .dynamic section. We fill in the … … 1045 1769 the .dynamic section. The DT_DEBUG entry is filled in by the 1046 1770 dynamic linker and used by the debugger. */ 1771 #define add_dynamic_entry(TAG, VAL) \ 1772 bfd_elf64_add_dynamic_entry (info, (bfd_vma) (TAG), (bfd_vma) (VAL)) 1773 1047 1774 if (! info->shared) 1048 1775 { 1049 if (! bfd_elf64_add_dynamic_entry (info,DT_DEBUG, 0))1050 return false;1051 } 1052 1053 if ( plt)1054 { 1055 if (! bfd_elf64_add_dynamic_entry (info,DT_PLTGOT, 0)1056 || ! bfd_elf64_add_dynamic_entry (info,DT_PLTRELSZ, 0)1057 || ! bfd_elf64_add_dynamic_entry (info,DT_PLTREL, DT_RELA)1058 || ! bfd_elf64_add_dynamic_entry (info,DT_JMPREL, 0))1059 return false;1776 if (!add_dynamic_entry (DT_DEBUG, 0)) 1777 return FALSE; 1778 } 1779 1780 if (htab->splt->_raw_size != 0) 1781 { 1782 if (!add_dynamic_entry (DT_PLTGOT, 0) 1783 || !add_dynamic_entry (DT_PLTRELSZ, 0) 1784 || !add_dynamic_entry (DT_PLTREL, DT_RELA) 1785 || !add_dynamic_entry (DT_JMPREL, 0)) 1786 return FALSE; 1060 1787 } 1061 1788 1062 1789 if (relocs) 1063 1790 { 1064 if (! bfd_elf64_add_dynamic_entry (info, DT_RELA, 0) 1065 || ! bfd_elf64_add_dynamic_entry (info, DT_RELASZ, 0) 1066 || ! bfd_elf64_add_dynamic_entry (info, DT_RELAENT, 1067 sizeof (Elf64_External_Rela))) 1068 return false; 1069 } 1070 1071 if (reltext) 1072 { 1073 if (! bfd_elf64_add_dynamic_entry (info, DT_TEXTREL, 0)) 1074 return false; 1075 info->flags |= DF_TEXTREL; 1076 } 1077 } 1078 1079 return true; 1791 if (!add_dynamic_entry (DT_RELA, 0) 1792 || !add_dynamic_entry (DT_RELASZ, 0) 1793 || !add_dynamic_entry (DT_RELAENT, sizeof (Elf64_External_Rela))) 1794 return FALSE; 1795 1796 /* If any dynamic relocs apply to a read-only section, 1797 then we need a DT_TEXTREL entry. */ 1798 if ((info->flags & DF_TEXTREL) == 0) 1799 elf_link_hash_traverse (&htab->elf, readonly_dynrelocs, 1800 (PTR) info); 1801 1802 if ((info->flags & DF_TEXTREL) != 0) 1803 { 1804 if (!add_dynamic_entry (DT_TEXTREL, 0)) 1805 return FALSE; 1806 } 1807 } 1808 } 1809 #undef add_dynamic_entry 1810 1811 return TRUE; 1080 1812 } 1081 1813 1082 /* This function is called via elf64_x86_64_link_hash_traverse if we are 1083 creating a shared object. In the -Bsymbolic case, it discards the 1084 space allocated to copy PC relative relocs against symbols which 1085 are defined in regular objects. For the normal non-symbolic case, 1086 we also discard space for relocs that have become local due to 1087 symbol visibility changes. We allocated space for them in the 1088 check_relocs routine, but we won't fill them in in the 1089 relocate_section routine. */ 1090 1091 static boolean 1092 elf64_x86_64_discard_copies (h, inf) 1093 struct elf64_x86_64_link_hash_entry *h; 1094 PTR inf; 1095 { 1096 struct elf64_x86_64_pcrel_relocs_copied *s; 1097 struct bfd_link_info *info = (struct bfd_link_info *) inf; 1098 1099 /* If a symbol has been forced local or we have found a regular 1100 definition for the symbolic link case, then we won't be needing 1101 any relocs. */ 1102 if ((h->root.elf_link_hash_flags & ELF_LINK_HASH_DEF_REGULAR) != 0 1103 && ((h->root.elf_link_hash_flags & ELF_LINK_FORCED_LOCAL) != 0 1104 || info->symbolic)) 1105 { 1106 for (s = h->pcrel_relocs_copied; s != NULL; s = s->next) 1107 s->section->_raw_size -= s->count * sizeof (Elf64_External_Rela); 1108 } 1109 1110 return true; 1814 /* Return the base VMA address which should be subtracted from real addresses 1815 when resolving @dtpoff relocation. 1816 This is PT_TLS segment p_vaddr. */ 1817 1818 static bfd_vma 1819 dtpoff_base (info) 1820 struct bfd_link_info *info; 1821 { 1822 /* If tls_segment is NULL, we should have signalled an error already. */ 1823 if (elf_hash_table (info)->tls_segment == NULL) 1824 return 0; 1825 return elf_hash_table (info)->tls_segment->start; 1111 1826 } 1112 1827 1828 /* Return the relocation value for @tpoff relocation 1829 if STT_TLS virtual address is ADDRESS. */ 1830 1831 static bfd_vma 1832 tpoff (info, address) 1833 struct bfd_link_info *info; 1834 bfd_vma address; 1835 { 1836 struct elf_link_tls_segment *tls_segment 1837 = elf_hash_table (info)->tls_segment; 1838 1839 /* If tls_segment is NULL, we should have signalled an error already. */ 1840 if (tls_segment == NULL) 1841 return 0; 1842 return address - align_power (tls_segment->size, tls_segment->align) 1843 - tls_segment->start; 1844 } 1845 1113 1846 /* Relocate an x86_64 ELF section. */ 1114 1847 1115 static b oolean1848 static bfd_boolean 1116 1849 elf64_x86_64_relocate_section (output_bfd, info, input_bfd, input_section, 1117 1850 contents, relocs, local_syms, local_sections) … … 1125 1858 asection **local_sections; 1126 1859 { 1127 bfd *dynobj;1860 struct elf64_x86_64_link_hash_table *htab; 1128 1861 Elf_Internal_Shdr *symtab_hdr; 1129 1862 struct elf_link_hash_entry **sym_hashes; 1130 1863 bfd_vma *local_got_offsets; 1131 asection *sgot; 1132 asection *splt; 1133 asection *sreloc; 1134 Elf_Internal_Rela *rela; 1864 Elf_Internal_Rela *rel; 1135 1865 Elf_Internal_Rela *relend; 1136 1866 1137 dynobj = elf_hash_table (info)->dynobj; 1867 if (info->relocateable) 1868 return TRUE; 1869 1870 htab = elf64_x86_64_hash_table (info); 1138 1871 symtab_hdr = &elf_tdata (input_bfd)->symtab_hdr; 1139 1872 sym_hashes = elf_sym_hashes (input_bfd); 1140 1873 local_got_offsets = elf_local_got_offsets (input_bfd); 1141 1874 1142 sreloc = splt = sgot = NULL; 1143 if (dynobj != NULL) 1144 { 1145 splt = bfd_get_section_by_name (dynobj, ".plt"); 1146 sgot = bfd_get_section_by_name (dynobj, ".got"); 1147 } 1148 1149 rela = relocs; 1875 rel = relocs; 1150 1876 relend = relocs + input_section->reloc_count; 1151 for (; rel a < relend; rela++)1152 { 1153 int r_type;1877 for (; rel < relend; rel++) 1878 { 1879 unsigned int r_type; 1154 1880 reloc_howto_type *howto; 1155 1881 unsigned long r_symndx; … … 1157 1883 Elf_Internal_Sym *sym; 1158 1884 asection *sec; 1885 bfd_vma off; 1159 1886 bfd_vma relocation; 1887 bfd_boolean unresolved_reloc; 1160 1888 bfd_reloc_status_type r; 1161 unsigned int indx; 1162 1163 r_type = ELF64_R_TYPE (rela->r_info); 1164 1165 if ((indx = (unsigned) r_type) >= R_X86_64_max) 1889 int tls_type; 1890 1891 r_type = ELF64_R_TYPE (rel->r_info); 1892 if (r_type == (int) R_X86_64_GNU_VTINHERIT 1893 || r_type == (int) R_X86_64_GNU_VTENTRY) 1894 continue; 1895 1896 if (r_type >= R_X86_64_max) 1166 1897 { 1167 1898 bfd_set_error (bfd_error_bad_value); 1168 return false; 1169 } 1170 howto = x86_64_elf_howto_table + indx; 1171 1172 r_symndx = ELF64_R_SYM (rela->r_info); 1173 1174 if (info->relocateable) 1175 { 1176 /* This is a relocateable link. We don't have to change 1177 anything, unless the reloc is against a section symbol, 1178 in which case we have to adjust according to where the 1179 section symbol winds up in the output section. */ 1180 if (r_symndx < symtab_hdr->sh_info) 1181 { 1182 sym = local_syms + r_symndx; 1183 if (ELF_ST_TYPE (sym->st_info) == STT_SECTION) 1184 { 1185 sec = local_sections[r_symndx]; 1186 rela->r_addend += sec->output_offset + sym->st_value; 1187 } 1188 } 1189 1190 continue; 1191 } 1192 1193 /* This is a final link. */ 1899 return FALSE; 1900 } 1901 1902 howto = x86_64_elf_howto_table + r_type; 1903 r_symndx = ELF64_R_SYM (rel->r_info); 1194 1904 h = NULL; 1195 1905 sym = NULL; 1196 1906 sec = NULL; 1907 unresolved_reloc = FALSE; 1197 1908 if (r_symndx < symtab_hdr->sh_info) 1198 1909 { 1199 1910 sym = local_syms + r_symndx; 1200 1911 sec = local_sections[r_symndx]; 1201 relocation = (sec->output_section->vma 1202 + sec->output_offset 1203 + sym->st_value); 1912 1913 relocation = _bfd_elf_rela_local_sym (output_bfd, sym, sec, rel); 1204 1914 } 1205 1915 else … … 1209 1919 || h->root.type == bfd_link_hash_warning) 1210 1920 h = (struct elf_link_hash_entry *) h->root.u.i.link; 1921 1211 1922 if (h->root.type == bfd_link_hash_defined 1212 1923 || h->root.type == bfd_link_hash_defweak) 1213 1924 { 1214 1925 sec = h->root.u.def.section; 1215 if ((r_type == R_X86_64_PLT32 1216 && splt != NULL 1217 && h->plt.offset != (bfd_vma) -1) 1218 || ((r_type == R_X86_64_GOT32 || r_type == R_X86_64_GOTPCREL) 1219 && elf_hash_table (info)->dynamic_sections_created 1220 && (!info->shared 1221 || (! info->symbolic && h->dynindx != -1) 1222 || (h->elf_link_hash_flags 1223 & ELF_LINK_HASH_DEF_REGULAR) == 0)) 1224 || (info->shared 1225 && ((! info->symbolic && h->dynindx != -1) 1226 || (h->elf_link_hash_flags 1227 & ELF_LINK_HASH_DEF_REGULAR) == 0) 1228 && (r_type == R_X86_64_8 1229 || r_type == R_X86_64_16 1230 || r_type == R_X86_64_32 1231 || r_type == R_X86_64_64 1232 || r_type == R_X86_64_PC8 1233 || r_type == R_X86_64_PC16 1234 || r_type == R_X86_64_PC32) 1235 && ((input_section->flags & SEC_ALLOC) != 0 1236 /* DWARF will emit R_X86_64_32 relocations in its 1237 sections against symbols defined externally 1238 in shared libraries. We can't do anything 1239 with them here. */ 1240 || ((input_section->flags & SEC_DEBUGGING) != 0 1241 && (h->elf_link_hash_flags 1242 & ELF_LINK_HASH_DEF_DYNAMIC) != 0)))) 1926 if (sec->output_section == NULL) 1243 1927 { 1244 /* In these cases, we don't need the relocation 1245 value. We check specially because in some 1246 obscure cases sec->output_section will be NULL. */ 1247 relocation = 0; 1248 } 1249 else if (sec->output_section == NULL) 1250 { 1251 (*_bfd_error_handler) 1252 (_("%s: warning: unresolvable relocation against symbol `%s' from %s section"), 1253 bfd_get_filename (input_bfd), h->root.root.string, 1254 bfd_get_section_name (input_bfd, input_section)); 1928 /* Set a flag that will be cleared later if we find a 1929 relocation value for this symbol. output_section 1930 is typically NULL for symbols satisfied by a shared 1931 library. */ 1932 unresolved_reloc = TRUE; 1255 1933 relocation = 0; 1256 1934 } … … 1262 1940 else if (h->root.type == bfd_link_hash_undefweak) 1263 1941 relocation = 0; 1264 else if (info->shared && !info->symbolic && !info->no_undefined 1942 else if (info->shared 1943 && !info->no_undefined 1265 1944 && ELF_ST_VISIBILITY (h->other) == STV_DEFAULT) 1266 1945 relocation = 0; … … 1269 1948 if (! ((*info->callbacks->undefined_symbol) 1270 1949 (info, h->root.root.string, input_bfd, 1271 input_section, rel a->r_offset,1950 input_section, rel->r_offset, 1272 1951 (!info->shared || info->no_undefined 1273 1952 || ELF_ST_VISIBILITY (h->other))))) 1274 return false;1953 return FALSE; 1275 1954 relocation = 0; 1276 1955 } 1277 1956 } 1278 1279 1957 /* When generating a shared object, the relocations handled here are 1280 1958 copied into the output file to be resolved at run time. */ … … 1286 1964 case R_X86_64_GOTPCREL: 1287 1965 /* Use global offset table as symbol value. */ 1288 BFD_ASSERT (sgot != NULL); 1966 if (htab->sgot == NULL) 1967 abort (); 1289 1968 1290 1969 if (h != NULL) 1291 1970 { 1292 bfd_vma off = h->got.offset; 1293 BFD_ASSERT (off != (bfd_vma) -1); 1294 1295 if (! elf_hash_table (info)->dynamic_sections_created 1971 bfd_boolean dyn; 1972 1973 off = h->got.offset; 1974 dyn = htab->elf.dynamic_sections_created; 1975 1976 if (! WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn, info, h) 1296 1977 || (info->shared 1297 && (info->symbolic || h->dynindx == -1) 1978 && (info->symbolic 1979 || h->dynindx == -1 1980 || (h->elf_link_hash_flags & ELF_LINK_FORCED_LOCAL)) 1298 1981 && (h->elf_link_hash_flags & ELF_LINK_HASH_DEF_REGULAR))) 1299 1982 { … … 1314 1997 { 1315 1998 bfd_put_64 (output_bfd, relocation, 1316 sgot->contents + off);1999 htab->sgot->contents + off); 1317 2000 h->got.offset |= 1; 1318 2001 } 1319 2002 } 1320 if (r_type == R_X86_64_GOTPCREL)1321 relocation = sgot->output_section->vma + sgot->output_offset + off;1322 2003 else 1323 relocation = sgot->output_offset + off;2004 unresolved_reloc = FALSE; 1324 2005 } 1325 2006 else 1326 2007 { 1327 bfd_vma off; 1328 1329 BFD_ASSERT (local_got_offsets != NULL 1330 && local_got_offsets[r_symndx] != (bfd_vma) -1); 2008 if (local_got_offsets == NULL) 2009 abort (); 1331 2010 1332 2011 off = local_got_offsets[r_symndx]; … … 1339 2018 else 1340 2019 { 1341 bfd_put_64 (output_bfd, relocation, sgot->contents + off); 2020 bfd_put_64 (output_bfd, relocation, 2021 htab->sgot->contents + off); 1342 2022 1343 2023 if (info->shared) 1344 2024 { 1345 asection *s relgot;2025 asection *s; 1346 2026 Elf_Internal_Rela outrel; 2027 bfd_byte *loc; 1347 2028 1348 2029 /* We need to generate a R_X86_64_RELATIVE reloc 1349 2030 for the dynamic linker. */ 1350 srelgot = bfd_get_section_by_name (dynobj, ".rela.got"); 1351 BFD_ASSERT (srelgot != NULL); 1352 1353 outrel.r_offset = (sgot->output_section->vma 1354 + sgot->output_offset 2031 s = htab->srelgot; 2032 if (s == NULL) 2033 abort (); 2034 2035 outrel.r_offset = (htab->sgot->output_section->vma 2036 + htab->sgot->output_offset 1355 2037 + off); 1356 2038 outrel.r_info = ELF64_R_INFO (0, R_X86_64_RELATIVE); 1357 2039 outrel.r_addend = relocation; 1358 bfd_elf64_swap_reloca_out (output_bfd, &outrel, 1359 (((Elf64_External_Rela *) 1360 srelgot->contents) 1361 + srelgot->reloc_count)); 1362 ++srelgot->reloc_count; 2040 loc = s->contents; 2041 loc += s->reloc_count++ * sizeof (Elf64_External_Rela); 2042 bfd_elf64_swap_reloca_out (output_bfd, &outrel, loc); 1363 2043 } 1364 2044 1365 2045 local_got_offsets[r_symndx] |= 1; 1366 2046 } 1367 1368 if (r_type == R_X86_64_GOTPCREL) 1369 relocation = sgot->output_section->vma + sgot->output_offset + off; 1370 else 1371 relocation = sgot->output_offset + off; 1372 } 2047 } 2048 2049 if (off >= (bfd_vma) -2) 2050 abort (); 2051 2052 relocation = htab->sgot->output_offset + off; 2053 if (r_type == R_X86_64_GOTPCREL) 2054 relocation += htab->sgot->output_section->vma; 1373 2055 1374 2056 break; … … 1383 2065 break; 1384 2066 1385 if (h->plt.offset == (bfd_vma) -1 || splt == NULL) 2067 if (h->plt.offset == (bfd_vma) -1 2068 || htab->splt == NULL) 1386 2069 { 1387 2070 /* We didn't make a PLT entry for this symbol. This … … 1391 2074 } 1392 2075 1393 relocation = ( splt->output_section->vma1394 + splt->output_offset2076 relocation = (htab->splt->output_section->vma 2077 + htab->splt->output_offset 1395 2078 + h->plt.offset); 2079 unresolved_reloc = FALSE; 1396 2080 break; 1397 2081 … … 1399 2083 case R_X86_64_PC16: 1400 2084 case R_X86_64_PC32: 1401 if (h == NULL)1402 break;1403 /* Fall through. */1404 2085 case R_X86_64_8: 1405 2086 case R_X86_64_16: … … 1408 2089 /* FIXME: The ABI says the linker should make sure the value is 1409 2090 the same when it's zeroextended to 64 bit. */ 1410 if (info->shared 1411 && (input_section->flags & SEC_ALLOC) != 0 1412 && ((r_type != R_X86_64_PC8 1413 && r_type != R_X86_64_PC16 1414 && r_type != R_X86_64_PC32) 1415 || (! info->symbolic 1416 || (h->elf_link_hash_flags 1417 & ELF_LINK_HASH_DEF_REGULAR) == 0))) 1418 2091 2092 /* r_symndx will be zero only for relocs against symbols 2093 from removed linkonce sections, or sections discarded by 2094 a linker script. */ 2095 if (r_symndx == 0 2096 || (input_section->flags & SEC_ALLOC) == 0) 2097 break; 2098 2099 if ((info->shared 2100 && ((r_type != R_X86_64_PC8 2101 && r_type != R_X86_64_PC16 2102 && r_type != R_X86_64_PC32) 2103 || (h != NULL 2104 && h->dynindx != -1 2105 && (! info->symbolic 2106 || (h->elf_link_hash_flags 2107 & ELF_LINK_HASH_DEF_REGULAR) == 0)))) 2108 || (ELIMINATE_COPY_RELOCS 2109 && !info->shared 2110 && h != NULL 2111 && h->dynindx != -1 2112 && (h->elf_link_hash_flags & ELF_LINK_NON_GOT_REF) == 0 2113 && (((h->elf_link_hash_flags 2114 & ELF_LINK_HASH_DEF_DYNAMIC) != 0 2115 && (h->elf_link_hash_flags 2116 & ELF_LINK_HASH_DEF_REGULAR) == 0) 2117 || h->root.type == bfd_link_hash_undefweak 2118 || h->root.type == bfd_link_hash_undefined))) 1419 2119 { 1420 2120 Elf_Internal_Rela outrel; 1421 boolean skip, relocate; 2121 bfd_byte *loc; 2122 bfd_boolean skip, relocate; 2123 asection *sreloc; 1422 2124 1423 2125 /* When generating a shared object, these relocations 1424 2126 are copied into the output file to be resolved at run 1425 2127 time. */ 1426 1427 if (sreloc == NULL) 1428 { 1429 const char *name; 1430 1431 name = (bfd_elf_string_from_elf_section 1432 (input_bfd, 1433 elf_elfheader (input_bfd)->e_shstrndx, 1434 elf_section_data (input_section)->rel_hdr.sh_name)); 1435 if (name == NULL) 1436 return false; 1437 1438 BFD_ASSERT (strncmp (name, ".rela", 5) == 0 1439 && strcmp (bfd_get_section_name (input_bfd, 1440 input_section), 1441 name + 5) == 0); 1442 1443 sreloc = bfd_get_section_by_name (dynobj, name); 1444 BFD_ASSERT (sreloc != NULL); 1445 } 1446 1447 skip = false; 1448 1449 if (elf_section_data (input_section)->stab_info == NULL) 1450 outrel.r_offset = rela->r_offset; 1451 else 1452 { 1453 bfd_vma off; 1454 1455 off = (_bfd_stab_section_offset 1456 (output_bfd, &elf_hash_table (info)->stab_info, 1457 input_section, 1458 &elf_section_data (input_section)->stab_info, 1459 rela->r_offset)); 1460 if (off == (bfd_vma) -1) 1461 skip = true; 1462 outrel.r_offset = off; 1463 } 2128 skip = FALSE; 2129 relocate = FALSE; 2130 2131 outrel.r_offset = 2132 _bfd_elf_section_offset (output_bfd, info, input_section, 2133 rel->r_offset); 2134 if (outrel.r_offset == (bfd_vma) -1) 2135 skip = TRUE; 2136 else if (outrel.r_offset == (bfd_vma) -2) 2137 skip = TRUE, relocate = TRUE; 1464 2138 1465 2139 outrel.r_offset += (input_section->output_section->vma … … 1467 2141 1468 2142 if (skip) 1469 { 1470 memset (&outrel, 0, sizeof outrel); 1471 relocate = false; 1472 } 2143 memset (&outrel, 0, sizeof outrel); 2144 1473 2145 /* h->dynindx may be -1 if this symbol was marked to 1474 2146 become local. */ 1475 2147 else if (h != NULL 1476 && ((! info->symbolic && h->dynindx != -1) 2148 && h->dynindx != -1 2149 && (r_type == R_X86_64_PC8 2150 || r_type == R_X86_64_PC16 2151 || r_type == R_X86_64_PC32 2152 || !info->shared 2153 || !info->symbolic 1477 2154 || (h->elf_link_hash_flags 1478 2155 & ELF_LINK_HASH_DEF_REGULAR) == 0)) 1479 2156 { 1480 BFD_ASSERT (h->dynindx != -1);1481 relocate = false;1482 2157 outrel.r_info = ELF64_R_INFO (h->dynindx, r_type); 1483 outrel.r_addend = rel ocation + rela->r_addend;2158 outrel.r_addend = rel->r_addend; 1484 2159 } 1485 2160 else 1486 2161 { 2162 /* This symbol is local, or marked to become local. */ 1487 2163 if (r_type == R_X86_64_64) 1488 2164 { 1489 relocate = true;2165 relocate = TRUE; 1490 2166 outrel.r_info = ELF64_R_INFO (0, R_X86_64_RELATIVE); 1491 outrel.r_addend = relocation + rel a->r_addend;2167 outrel.r_addend = relocation + rel->r_addend; 1492 2168 } 1493 2169 else 1494 2170 { 1495 long indx;2171 long sindx; 1496 2172 1497 2173 if (h == NULL) … … 1505 2181 } 1506 2182 if (sec != NULL && bfd_is_abs_section (sec)) 1507 indx = 0;2183 sindx = 0; 1508 2184 else if (sec == NULL || sec->owner == NULL) 1509 2185 { 1510 2186 bfd_set_error (bfd_error_bad_value); 1511 return false;2187 return FALSE; 1512 2188 } 1513 2189 else … … 1516 2192 1517 2193 osec = sec->output_section; 1518 indx = elf_section_data (osec)->dynindx;1519 BFD_ASSERT ( indx > 0);2194 sindx = elf_section_data (osec)->dynindx; 2195 BFD_ASSERT (sindx > 0); 1520 2196 } 1521 2197 1522 relocate = false; 1523 outrel.r_info = ELF64_R_INFO (indx, r_type); 1524 outrel.r_addend = relocation + rela->r_addend; 1525 } 1526 2198 outrel.r_info = ELF64_R_INFO (sindx, r_type); 2199 outrel.r_addend = relocation + rel->r_addend; 2200 } 1527 2201 } 1528 2202 1529 bfd_elf64_swap_reloca_out (output_bfd, &outrel, 1530 (((Elf64_External_Rela *) 1531 sreloc->contents) 1532 + sreloc->reloc_count)); 1533 ++sreloc->reloc_count; 2203 sreloc = elf_section_data (input_section)->sreloc; 2204 if (sreloc == NULL) 2205 abort (); 2206 2207 loc = sreloc->contents; 2208 loc += sreloc->reloc_count++ * sizeof (Elf64_External_Rela); 2209 bfd_elf64_swap_reloca_out (output_bfd, &outrel, loc); 1534 2210 1535 2211 /* If this reloc is against an external symbol, we do … … 1543 2219 break; 1544 2220 2221 case R_X86_64_TLSGD: 2222 case R_X86_64_GOTTPOFF: 2223 r_type = elf64_x86_64_tls_transition (info, r_type, h == NULL); 2224 tls_type = GOT_UNKNOWN; 2225 if (h == NULL && local_got_offsets) 2226 tls_type = elf64_x86_64_local_got_tls_type (input_bfd) [r_symndx]; 2227 else if (h != NULL) 2228 { 2229 tls_type = elf64_x86_64_hash_entry (h)->tls_type; 2230 if (!info->shared && h->dynindx == -1 && tls_type == GOT_TLS_IE) 2231 r_type = R_X86_64_TPOFF32; 2232 } 2233 if (r_type == R_X86_64_TLSGD) 2234 { 2235 if (tls_type == GOT_TLS_IE) 2236 r_type = R_X86_64_GOTTPOFF; 2237 } 2238 2239 if (r_type == R_X86_64_TPOFF32) 2240 { 2241 BFD_ASSERT (! unresolved_reloc); 2242 if (ELF64_R_TYPE (rel->r_info) == R_X86_64_TLSGD) 2243 { 2244 unsigned int i; 2245 static unsigned char tlsgd[8] 2246 = { 0x66, 0x48, 0x8d, 0x3d, 0x66, 0x66, 0x48, 0xe8 }; 2247 2248 /* GD->LE transition. 2249 .byte 0x66; leaq foo@tlsgd(%rip), %rdi 2250 .word 0x6666; rex64; call __tls_get_addr@plt 2251 Change it into: 2252 movq %fs:0, %rax 2253 leaq foo@tpoff(%rax), %rax */ 2254 BFD_ASSERT (rel->r_offset >= 4); 2255 for (i = 0; i < 4; i++) 2256 BFD_ASSERT (bfd_get_8 (input_bfd, 2257 contents + rel->r_offset - 4 + i) 2258 == tlsgd[i]); 2259 BFD_ASSERT (rel->r_offset + 12 <= input_section->_raw_size); 2260 for (i = 0; i < 4; i++) 2261 BFD_ASSERT (bfd_get_8 (input_bfd, 2262 contents + rel->r_offset + 4 + i) 2263 == tlsgd[i+4]); 2264 BFD_ASSERT (rel + 1 < relend); 2265 BFD_ASSERT (ELF64_R_TYPE (rel[1].r_info) == R_X86_64_PLT32); 2266 memcpy (contents + rel->r_offset - 4, 2267 "\x64\x48\x8b\x04\x25\0\0\0\0\x48\x8d\x80\0\0\0", 2268 16); 2269 bfd_put_32 (output_bfd, tpoff (info, relocation), 2270 contents + rel->r_offset + 8); 2271 /* Skip R_X86_64_PLT32. */ 2272 rel++; 2273 continue; 2274 } 2275 else 2276 { 2277 unsigned int val, type, reg; 2278 2279 /* IE->LE transition: 2280 Originally it can be one of: 2281 movq foo@gottpoff(%rip), %reg 2282 addq foo@gottpoff(%rip), %reg 2283 We change it into: 2284 movq $foo, %reg 2285 leaq foo(%reg), %reg 2286 addq $foo, %reg. */ 2287 BFD_ASSERT (rel->r_offset >= 3); 2288 val = bfd_get_8 (input_bfd, contents + rel->r_offset - 3); 2289 BFD_ASSERT (val == 0x48 || val == 0x4c); 2290 type = bfd_get_8 (input_bfd, contents + rel->r_offset - 2); 2291 BFD_ASSERT (type == 0x8b || type == 0x03); 2292 reg = bfd_get_8 (input_bfd, contents + rel->r_offset - 1); 2293 BFD_ASSERT ((reg & 0xc7) == 5); 2294 reg >>= 3; 2295 BFD_ASSERT (rel->r_offset + 4 <= input_section->_raw_size); 2296 if (type == 0x8b) 2297 { 2298 /* movq */ 2299 if (val == 0x4c) 2300 bfd_put_8 (output_bfd, 0x49, 2301 contents + rel->r_offset - 3); 2302 bfd_put_8 (output_bfd, 0xc7, 2303 contents + rel->r_offset - 2); 2304 bfd_put_8 (output_bfd, 0xc0 | reg, 2305 contents + rel->r_offset - 1); 2306 } 2307 else if (reg == 4) 2308 { 2309 /* addq -> addq - addressing with %rsp/%r12 is 2310 special */ 2311 if (val == 0x4c) 2312 bfd_put_8 (output_bfd, 0x49, 2313 contents + rel->r_offset - 3); 2314 bfd_put_8 (output_bfd, 0x81, 2315 contents + rel->r_offset - 2); 2316 bfd_put_8 (output_bfd, 0xc0 | reg, 2317 contents + rel->r_offset - 1); 2318 } 2319 else 2320 { 2321 /* addq -> leaq */ 2322 if (val == 0x4c) 2323 bfd_put_8 (output_bfd, 0x4d, 2324 contents + rel->r_offset - 3); 2325 bfd_put_8 (output_bfd, 0x8d, 2326 contents + rel->r_offset - 2); 2327 bfd_put_8 (output_bfd, 0x80 | reg | (reg << 3), 2328 contents + rel->r_offset - 1); 2329 } 2330 bfd_put_32 (output_bfd, tpoff (info, relocation), 2331 contents + rel->r_offset); 2332 continue; 2333 } 2334 } 2335 2336 if (htab->sgot == NULL) 2337 abort (); 2338 2339 if (h != NULL) 2340 off = h->got.offset; 2341 else 2342 { 2343 if (local_got_offsets == NULL) 2344 abort (); 2345 2346 off = local_got_offsets[r_symndx]; 2347 } 2348 2349 if ((off & 1) != 0) 2350 off &= ~1; 2351 else 2352 { 2353 Elf_Internal_Rela outrel; 2354 bfd_byte *loc; 2355 int dr_type, indx; 2356 2357 if (htab->srelgot == NULL) 2358 abort (); 2359 2360 outrel.r_offset = (htab->sgot->output_section->vma 2361 + htab->sgot->output_offset + off); 2362 2363 indx = h && h->dynindx != -1 ? h->dynindx : 0; 2364 if (r_type == R_X86_64_TLSGD) 2365 dr_type = R_X86_64_DTPMOD64; 2366 else 2367 dr_type = R_X86_64_TPOFF64; 2368 2369 bfd_put_64 (output_bfd, 0, htab->sgot->contents + off); 2370 outrel.r_addend = 0; 2371 if (dr_type == R_X86_64_TPOFF64 && indx == 0) 2372 outrel.r_addend = relocation - dtpoff_base (info); 2373 outrel.r_info = ELF64_R_INFO (indx, dr_type); 2374 2375 loc = htab->srelgot->contents; 2376 loc += htab->srelgot->reloc_count++ * sizeof (Elf64_External_Rela); 2377 bfd_elf64_swap_reloca_out (output_bfd, &outrel, loc); 2378 2379 if (r_type == R_X86_64_TLSGD) 2380 { 2381 if (indx == 0) 2382 { 2383 BFD_ASSERT (! unresolved_reloc); 2384 bfd_put_64 (output_bfd, 2385 relocation - dtpoff_base (info), 2386 htab->sgot->contents + off + GOT_ENTRY_SIZE); 2387 } 2388 else 2389 { 2390 bfd_put_64 (output_bfd, 0, 2391 htab->sgot->contents + off + GOT_ENTRY_SIZE); 2392 outrel.r_info = ELF64_R_INFO (indx, 2393 R_X86_64_DTPOFF64); 2394 outrel.r_offset += GOT_ENTRY_SIZE; 2395 htab->srelgot->reloc_count++; 2396 loc += sizeof (Elf64_External_Rela); 2397 bfd_elf64_swap_reloca_out (output_bfd, &outrel, loc); 2398 } 2399 } 2400 2401 if (h != NULL) 2402 h->got.offset |= 1; 2403 else 2404 local_got_offsets[r_symndx] |= 1; 2405 } 2406 2407 if (off >= (bfd_vma) -2) 2408 abort (); 2409 if (r_type == ELF64_R_TYPE (rel->r_info)) 2410 { 2411 relocation = htab->sgot->output_section->vma 2412 + htab->sgot->output_offset + off; 2413 unresolved_reloc = FALSE; 2414 } 2415 else 2416 { 2417 unsigned int i; 2418 static unsigned char tlsgd[8] 2419 = { 0x66, 0x48, 0x8d, 0x3d, 0x66, 0x66, 0x48, 0xe8 }; 2420 2421 /* GD->IE transition. 2422 .byte 0x66; leaq foo@tlsgd(%rip), %rdi 2423 .word 0x6666; rex64; call __tls_get_addr@plt 2424 Change it into: 2425 movq %fs:0, %rax 2426 addq foo@gottpoff(%rip), %rax */ 2427 BFD_ASSERT (rel->r_offset >= 4); 2428 for (i = 0; i < 4; i++) 2429 BFD_ASSERT (bfd_get_8 (input_bfd, 2430 contents + rel->r_offset - 4 + i) 2431 == tlsgd[i]); 2432 BFD_ASSERT (rel->r_offset + 12 <= input_section->_raw_size); 2433 for (i = 0; i < 4; i++) 2434 BFD_ASSERT (bfd_get_8 (input_bfd, 2435 contents + rel->r_offset + 4 + i) 2436 == tlsgd[i+4]); 2437 BFD_ASSERT (rel + 1 < relend); 2438 BFD_ASSERT (ELF64_R_TYPE (rel[1].r_info) == R_X86_64_PLT32); 2439 memcpy (contents + rel->r_offset - 4, 2440 "\x64\x48\x8b\x04\x25\0\0\0\0\x48\x03\x05\0\0\0", 2441 16); 2442 2443 relocation = (htab->sgot->output_section->vma 2444 + htab->sgot->output_offset + off 2445 - rel->r_offset 2446 - input_section->output_section->vma 2447 - input_section->output_offset 2448 - 12); 2449 bfd_put_32 (output_bfd, relocation, 2450 contents + rel->r_offset + 8); 2451 /* Skip R_X86_64_PLT32. */ 2452 rel++; 2453 continue; 2454 } 2455 break; 2456 2457 case R_X86_64_TLSLD: 2458 if (! info->shared) 2459 { 2460 /* LD->LE transition: 2461 Ensure it is: 2462 leaq foo@tlsld(%rip), %rdi; call __tls_get_addr@plt. 2463 We change it into: 2464 .word 0x6666; .byte 0x66; movl %fs:0, %rax. */ 2465 BFD_ASSERT (rel->r_offset >= 3); 2466 BFD_ASSERT (bfd_get_8 (input_bfd, contents + rel->r_offset - 3) 2467 == 0x48); 2468 BFD_ASSERT (bfd_get_8 (input_bfd, contents + rel->r_offset - 2) 2469 == 0x8d); 2470 BFD_ASSERT (bfd_get_8 (input_bfd, contents + rel->r_offset - 1) 2471 == 0x3d); 2472 BFD_ASSERT (rel->r_offset + 9 <= input_section->_raw_size); 2473 BFD_ASSERT (bfd_get_8 (input_bfd, contents + rel->r_offset + 4) 2474 == 0xe8); 2475 BFD_ASSERT (rel + 1 < relend); 2476 BFD_ASSERT (ELF64_R_TYPE (rel[1].r_info) == R_X86_64_PLT32); 2477 memcpy (contents + rel->r_offset - 3, 2478 "\x66\x66\x66\x64\x48\x8b\x04\x25\0\0\0", 12); 2479 /* Skip R_X86_64_PLT32. */ 2480 rel++; 2481 continue; 2482 } 2483 2484 if (htab->sgot == NULL) 2485 abort (); 2486 2487 off = htab->tls_ld_got.offset; 2488 if (off & 1) 2489 off &= ~1; 2490 else 2491 { 2492 Elf_Internal_Rela outrel; 2493 bfd_byte *loc; 2494 2495 if (htab->srelgot == NULL) 2496 abort (); 2497 2498 outrel.r_offset = (htab->sgot->output_section->vma 2499 + htab->sgot->output_offset + off); 2500 2501 bfd_put_64 (output_bfd, 0, 2502 htab->sgot->contents + off); 2503 bfd_put_64 (output_bfd, 0, 2504 htab->sgot->contents + off + GOT_ENTRY_SIZE); 2505 outrel.r_info = ELF64_R_INFO (0, R_X86_64_DTPMOD64); 2506 outrel.r_addend = 0; 2507 loc = htab->srelgot->contents; 2508 loc += htab->srelgot->reloc_count++ * sizeof (Elf64_External_Rela); 2509 bfd_elf64_swap_reloca_out (output_bfd, &outrel, loc); 2510 htab->tls_ld_got.offset |= 1; 2511 } 2512 relocation = htab->sgot->output_section->vma 2513 + htab->sgot->output_offset + off; 2514 unresolved_reloc = FALSE; 2515 break; 2516 2517 case R_X86_64_DTPOFF32: 2518 if (info->shared || (input_section->flags & SEC_CODE) == 0) 2519 relocation -= dtpoff_base (info); 2520 else 2521 relocation = tpoff (info, relocation); 2522 break; 2523 2524 case R_X86_64_TPOFF32: 2525 BFD_ASSERT (! info->shared); 2526 relocation = tpoff (info, relocation); 2527 break; 2528 1545 2529 default: 1546 2530 break; 1547 2531 } 1548 2532 2533 /* Dynamic relocs are not propagated for SEC_DEBUGGING sections 2534 because such sections are not SEC_ALLOC and thus ld.so will 2535 not process them. */ 2536 if (unresolved_reloc 2537 && !((input_section->flags & SEC_DEBUGGING) != 0 2538 && (h->elf_link_hash_flags & ELF_LINK_HASH_DEF_DYNAMIC) != 0)) 2539 (*_bfd_error_handler) 2540 (_("%s(%s+0x%lx): unresolvable relocation against symbol `%s'"), 2541 bfd_archive_filename (input_bfd), 2542 bfd_get_section_name (input_bfd, input_section), 2543 (long) rel->r_offset, 2544 h->root.root.string); 2545 1549 2546 r = _bfd_final_link_relocate (howto, input_bfd, input_section, 1550 contents, rel a->r_offset,1551 relocation, rel a->r_addend);2547 contents, rel->r_offset, 2548 relocation, rel->r_addend); 1552 2549 1553 2550 if (r != bfd_reloc_ok) 1554 2551 { 1555 switch (r) 1556 { 1557 default: 1558 case bfd_reloc_outofrange: 1559 abort (); 1560 case bfd_reloc_overflow: 1561 { 1562 const char *name; 1563 1564 if (h != NULL) 1565 name = h->root.root.string; 1566 else 1567 { 1568 name = bfd_elf_string_from_elf_section (input_bfd, 1569 symtab_hdr->sh_link, 1570 sym->st_name); 1571 if (name == NULL) 1572 return false; 1573 if (*name == '\0') 1574 name = bfd_section_name (input_bfd, sec); 1575 } 1576 if (! ((*info->callbacks->reloc_overflow) 1577 (info, name, howto->name, (bfd_vma) 0, 1578 input_bfd, input_section, rela->r_offset))) 1579 return false; 1580 } 1581 break; 1582 } 1583 } 1584 } 1585 1586 return true; 2552 const char *name; 2553 2554 if (h != NULL) 2555 name = h->root.root.string; 2556 else 2557 { 2558 name = bfd_elf_string_from_elf_section (input_bfd, 2559 symtab_hdr->sh_link, 2560 sym->st_name); 2561 if (name == NULL) 2562 return FALSE; 2563 if (*name == '\0') 2564 name = bfd_section_name (input_bfd, sec); 2565 } 2566 2567 if (r == bfd_reloc_overflow) 2568 { 2569 2570 if (! ((*info->callbacks->reloc_overflow) 2571 (info, name, howto->name, (bfd_vma) 0, 2572 input_bfd, input_section, rel->r_offset))) 2573 return FALSE; 2574 } 2575 else 2576 { 2577 (*_bfd_error_handler) 2578 (_("%s(%s+0x%lx): reloc against `%s': error %d"), 2579 bfd_archive_filename (input_bfd), 2580 bfd_get_section_name (input_bfd, input_section), 2581 (long) rel->r_offset, name, (int) r); 2582 return FALSE; 2583 } 2584 } 2585 } 2586 2587 return TRUE; 1587 2588 } 1588 2589 … … 1590 2591 dynamic sections here. */ 1591 2592 1592 static b oolean2593 static bfd_boolean 1593 2594 elf64_x86_64_finish_dynamic_symbol (output_bfd, info, h, sym) 1594 2595 bfd *output_bfd; … … 1597 2598 Elf_Internal_Sym *sym; 1598 2599 { 1599 bfd *dynobj;1600 1601 dynobj = elf_hash_table (info)->dynobj;2600 struct elf64_x86_64_link_hash_table *htab; 2601 2602 htab = elf64_x86_64_hash_table (info); 1602 2603 1603 2604 if (h->plt.offset != (bfd_vma) -1) 1604 2605 { 1605 asection *splt;1606 asection *sgot;1607 asection *srela;1608 2606 bfd_vma plt_index; 1609 2607 bfd_vma got_offset; 1610 2608 Elf_Internal_Rela rela; 2609 bfd_byte *loc; 1611 2610 1612 2611 /* This symbol has an entry in the procedure linkage table. Set 1613 2612 it up. */ 1614 1615 BFD_ASSERT (h->dynindx != -1); 1616 1617 splt = bfd_get_section_by_name (dynobj, ".plt"); 1618 sgot = bfd_get_section_by_name (dynobj, ".got.plt"); 1619 srela = bfd_get_section_by_name (dynobj, ".rela.plt"); 1620 BFD_ASSERT (splt != NULL && sgot != NULL && srela != NULL); 2613 if (h->dynindx == -1 2614 || htab->splt == NULL 2615 || htab->sgotplt == NULL 2616 || htab->srelplt == NULL) 2617 abort (); 1621 2618 1622 2619 /* Get the index in the procedure linkage table which … … 1632 2629 1633 2630 /* Fill in the entry in the procedure linkage table. */ 1634 memcpy ( splt->contents + h->plt.offset, elf64_x86_64_plt_entry,2631 memcpy (htab->splt->contents + h->plt.offset, elf64_x86_64_plt_entry, 1635 2632 PLT_ENTRY_SIZE); 1636 2633 … … 1641 2638 instruction uses 6 bytes, subtract this value. */ 1642 2639 bfd_put_32 (output_bfd, 1643 ( sgot->output_section->vma1644 + sgot->output_offset2640 (htab->sgotplt->output_section->vma 2641 + htab->sgotplt->output_offset 1645 2642 + got_offset 1646 - splt->output_section->vma1647 - splt->output_offset2643 - htab->splt->output_section->vma 2644 - htab->splt->output_offset 1648 2645 - h->plt.offset 1649 2646 - 6), 1650 splt->contents + h->plt.offset + 2);2647 htab->splt->contents + h->plt.offset + 2); 1651 2648 /* Put relocation index. */ 1652 2649 bfd_put_32 (output_bfd, plt_index, 1653 splt->contents + h->plt.offset + 7);2650 htab->splt->contents + h->plt.offset + 7); 1654 2651 /* Put offset for jmp .PLT0. */ 1655 2652 bfd_put_32 (output_bfd, - (h->plt.offset + PLT_ENTRY_SIZE), 1656 splt->contents + h->plt.offset + 12);2653 htab->splt->contents + h->plt.offset + 12); 1657 2654 1658 2655 /* Fill in the entry in the global offset table, initially this 1659 2656 points to the pushq instruction in the PLT which is at offset 6. */ 1660 bfd_put_64 (output_bfd, (splt->output_section->vma + splt->output_offset 2657 bfd_put_64 (output_bfd, (htab->splt->output_section->vma 2658 + htab->splt->output_offset 1661 2659 + h->plt.offset + 6), 1662 sgot->contents + got_offset);2660 htab->sgotplt->contents + got_offset); 1663 2661 1664 2662 /* Fill in the entry in the .rela.plt section. */ 1665 rela.r_offset = ( sgot->output_section->vma1666 + sgot->output_offset2663 rela.r_offset = (htab->sgotplt->output_section->vma 2664 + htab->sgotplt->output_offset 1667 2665 + got_offset); 1668 2666 rela.r_info = ELF64_R_INFO (h->dynindx, R_X86_64_JUMP_SLOT); 1669 2667 rela.r_addend = 0; 1670 bfd_elf64_swap_reloca_out (output_bfd, &rela, 1671 ((Elf64_External_Rela *) srela->contents 1672 + plt_index)); 2668 loc = htab->srelplt->contents + plt_index * sizeof (Elf64_External_Rela); 2669 bfd_elf64_swap_reloca_out (output_bfd, &rela, loc); 1673 2670 1674 2671 if ((h->elf_link_hash_flags & ELF_LINK_HASH_DEF_REGULAR) == 0) 1675 2672 { 1676 2673 /* Mark the symbol as undefined, rather than as defined in 1677 the .plt section. Leave the value alone. */ 2674 the .plt section. Leave the value alone. This is a clue 2675 for the dynamic linker, to make function pointer 2676 comparisons work between an application and shared 2677 library. */ 1678 2678 sym->st_shndx = SHN_UNDEF; 1679 /* If the symbol is weak, we do need to clear the value. 1680 Otherwise, the PLT entry would provide a definition for 1681 the symbol even if the symbol wasn't defined anywhere, 1682 and so the symbol would never be NULL. */ 1683 if ((h->elf_link_hash_flags & ELF_LINK_HASH_REF_REGULAR_NONWEAK) 1684 == 0) 1685 sym->st_value = 0; 1686 } 1687 } 1688 1689 if (h->got.offset != (bfd_vma) -1) 1690 { 1691 asection *sgot; 1692 asection *srela; 2679 } 2680 } 2681 2682 if (h->got.offset != (bfd_vma) -1 2683 && elf64_x86_64_hash_entry (h)->tls_type != GOT_TLS_GD 2684 && elf64_x86_64_hash_entry (h)->tls_type != GOT_TLS_IE) 2685 { 1693 2686 Elf_Internal_Rela rela; 2687 bfd_byte *loc; 1694 2688 1695 2689 /* This symbol has an entry in the global offset table. Set it 1696 up. */ 1697 1698 sgot = bfd_get_section_by_name (dynobj, ".got"); 1699 srela = bfd_get_section_by_name (dynobj, ".rela.got"); 1700 BFD_ASSERT (sgot != NULL && srela != NULL); 1701 1702 rela.r_offset = (sgot->output_section->vma 1703 + sgot->output_offset 1704 + (h->got.offset &~ 1)); 2690 up. */ 2691 if (htab->sgot == NULL || htab->srelgot == NULL) 2692 abort (); 2693 2694 rela.r_offset = (htab->sgot->output_section->vma 2695 + htab->sgot->output_offset 2696 + (h->got.offset &~ (bfd_vma) 1)); 1705 2697 1706 2698 /* If this is a static link, or it is a -Bsymbolic link and the … … 1709 2701 The entry in the global offset table will already have been 1710 2702 initialized in the relocate_section function. */ 1711 if (! elf_hash_table (info)->dynamic_sections_created 1712 || (info->shared 1713 && (info->symbolic || h->dynindx == -1) 1714 && (h->elf_link_hash_flags & ELF_LINK_HASH_DEF_REGULAR))) 2703 if (info->shared 2704 && (info->symbolic 2705 || h->dynindx == -1 2706 || (h->elf_link_hash_flags & ELF_LINK_FORCED_LOCAL)) 2707 && (h->elf_link_hash_flags & ELF_LINK_HASH_DEF_REGULAR)) 1715 2708 { 1716 2709 BFD_ASSERT((h->got.offset & 1) != 0); … … 1723 2716 { 1724 2717 BFD_ASSERT((h->got.offset & 1) == 0); 1725 bfd_put_64 (output_bfd, (bfd_vma) 0, sgot->contents + h->got.offset); 2718 bfd_put_64 (output_bfd, (bfd_vma) 0, 2719 htab->sgot->contents + h->got.offset); 1726 2720 rela.r_info = ELF64_R_INFO (h->dynindx, R_X86_64_GLOB_DAT); 1727 2721 rela.r_addend = 0; 1728 2722 } 1729 2723 1730 bfd_elf64_swap_reloca_out (output_bfd, &rela, 1731 ((Elf64_External_Rela *) srela->contents 1732 + srela->reloc_count)); 1733 ++srela->reloc_count; 2724 loc = htab->srelgot->contents; 2725 loc += htab->srelgot->reloc_count++ * sizeof (Elf64_External_Rela); 2726 bfd_elf64_swap_reloca_out (output_bfd, &rela, loc); 1734 2727 } 1735 2728 1736 2729 if ((h->elf_link_hash_flags & ELF_LINK_HASH_NEEDS_COPY) != 0) 1737 2730 { 1738 asection *s;1739 2731 Elf_Internal_Rela rela; 2732 bfd_byte *loc; 1740 2733 1741 2734 /* This symbol needs a copy reloc. Set it up. */ 1742 2735 1743 BFD_ASSERT (h->dynindx != -1 1744 && (h->root.type == bfd_link_hash_defined 1745 || h->root.type == bfd_link_hash_defweak)); 1746 1747 s = bfd_get_section_by_name (h->root.u.def.section->owner, 1748 ".rela.bss"); 1749 BFD_ASSERT (s != NULL); 2736 if (h->dynindx == -1 2737 || (h->root.type != bfd_link_hash_defined 2738 && h->root.type != bfd_link_hash_defweak) 2739 || htab->srelbss == NULL) 2740 abort (); 1750 2741 1751 2742 rela.r_offset = (h->root.u.def.value … … 1754 2745 rela.r_info = ELF64_R_INFO (h->dynindx, R_X86_64_COPY); 1755 2746 rela.r_addend = 0; 1756 bfd_elf64_swap_reloca_out (output_bfd, &rela, 1757 ((Elf64_External_Rela *) s->contents 1758 + s->reloc_count)); 1759 ++s->reloc_count; 2747 loc = htab->srelbss->contents; 2748 loc += htab->srelbss->reloc_count++ * sizeof (Elf64_External_Rela); 2749 bfd_elf64_swap_reloca_out (output_bfd, &rela, loc); 1760 2750 } 1761 2751 … … 1765 2755 sym->st_shndx = SHN_ABS; 1766 2756 1767 return true;2757 return TRUE; 1768 2758 } 1769 2759 2760 /* Used to decide how to sort relocs in an optimal manner for the 2761 dynamic linker, before writing them out. */ 2762 2763 static enum elf_reloc_type_class 2764 elf64_x86_64_reloc_type_class (rela) 2765 const Elf_Internal_Rela *rela; 2766 { 2767 switch ((int) ELF64_R_TYPE (rela->r_info)) 2768 { 2769 case R_X86_64_RELATIVE: 2770 return reloc_class_relative; 2771 case R_X86_64_JUMP_SLOT: 2772 return reloc_class_plt; 2773 case R_X86_64_COPY: 2774 return reloc_class_copy; 2775 default: 2776 return reloc_class_normal; 2777 } 2778 } 2779 1770 2780 /* Finish up the dynamic sections. */ 1771 2781 1772 static b oolean2782 static bfd_boolean 1773 2783 elf64_x86_64_finish_dynamic_sections (output_bfd, info) 1774 2784 bfd *output_bfd; 1775 2785 struct bfd_link_info *info; 1776 2786 { 2787 struct elf64_x86_64_link_hash_table *htab; 1777 2788 bfd *dynobj; 1778 2789 asection *sdyn; 1779 asection *sgot; 1780 1781 dynobj = elf_hash_table (info)->dynobj; 1782 1783 sgot = bfd_get_section_by_name (dynobj, ".got.plt"); 1784 BFD_ASSERT (sgot != NULL); 2790 2791 htab = elf64_x86_64_hash_table (info); 2792 dynobj = htab->elf.dynobj; 1785 2793 sdyn = bfd_get_section_by_name (dynobj, ".dynamic"); 1786 2794 1787 if (elf_hash_table (info)->dynamic_sections_created) 1788 { 1789 asection *splt; 2795 if (htab->elf.dynamic_sections_created) 2796 { 1790 2797 Elf64_External_Dyn *dyncon, *dynconend; 1791 2798 1792 BFD_ASSERT (sdyn != NULL); 2799 if (sdyn == NULL || htab->sgot == NULL) 2800 abort (); 1793 2801 1794 2802 dyncon = (Elf64_External_Dyn *) sdyn->contents; … … 1797 2805 { 1798 2806 Elf_Internal_Dyn dyn; 1799 const char *name;1800 2807 asection *s; 1801 2808 … … 1808 2815 1809 2816 case DT_PLTGOT: 1810 name = ".got";1811 goto get_vma;2817 dyn.d_un.d_ptr = htab->sgot->output_section->vma; 2818 break; 1812 2819 1813 2820 case DT_JMPREL: 1814 name = ".rela.plt"; 1815 1816 get_vma: 1817 s = bfd_get_section_by_name (output_bfd, name); 1818 BFD_ASSERT (s != NULL); 1819 dyn.d_un.d_ptr = s->vma; 2821 dyn.d_un.d_ptr = htab->srelplt->output_section->vma; 1820 2822 break; 1821 2823 2824 case DT_PLTRELSZ: 2825 s = htab->srelplt->output_section; 2826 if (s->_cooked_size != 0) 2827 dyn.d_un.d_val = s->_cooked_size; 2828 else 2829 dyn.d_un.d_val = s->_raw_size; 2830 break; 2831 1822 2832 case DT_RELASZ: 1823 /* FIXME: This comment and code is from elf64-alpha.c: */1824 /* My interpretation of the TIS v1.1 ELF document indicates1825 that RELASZ should not include JMPREL. This is not what1826 the rest of the BFD does. It is, however, whatthe1827 glibc ld.so wants. Do this fixup here until we found1828 o ut who is right. */1829 s = bfd_get_section_by_name (output_bfd, ".rela.plt");1830 if ( s)2833 /* The procedure linkage table relocs (DT_JMPREL) should 2834 not be included in the overall relocs (DT_RELA). 2835 Therefore, we override the DT_RELASZ entry here to 2836 make it not include the JMPREL relocs. Since the 2837 linker script arranges for .rela.plt to follow all 2838 other relocation sections, we don't have to worry 2839 about changing the DT_RELA entry. */ 2840 if (htab->srelplt != NULL) 1831 2841 { 1832 /* Subtract JMPREL size from RELASZ. */ 1833 dyn.d_un.d_val -= 1834 (s->_cooked_size ? s->_cooked_size : s->_raw_size); 2842 s = htab->srelplt->output_section; 2843 if (s->_cooked_size != 0) 2844 dyn.d_un.d_val -= s->_cooked_size; 2845 else 2846 dyn.d_un.d_val -= s->_raw_size; 1835 2847 } 1836 2848 break; 1837 1838 case DT_PLTRELSZ: 1839 s = bfd_get_section_by_name (output_bfd, ".rela.plt"); 1840 BFD_ASSERT (s != NULL); 1841 dyn.d_un.d_val = 1842 (s->_cooked_size != 0 ? s->_cooked_size : s->_raw_size); 1843 break; 1844 } 2849 } 2850 1845 2851 bfd_elf64_swap_dyn_out (output_bfd, &dyn, dyncon); 1846 2852 } 1847 2853 1848 /* Initialize the contents of the .plt section. */ 1849 splt = bfd_get_section_by_name (dynobj, ".plt"); 1850 BFD_ASSERT (splt != NULL); 1851 if (splt->_raw_size > 0) 2854 /* Fill in the special first entry in the procedure linkage table. */ 2855 if (htab->splt && htab->splt->_raw_size > 0) 1852 2856 { 1853 2857 /* Fill in the first entry in the procedure linkage table. */ 1854 memcpy (splt->contents, elf64_x86_64_plt0_entry, PLT_ENTRY_SIZE); 2858 memcpy (htab->splt->contents, elf64_x86_64_plt0_entry, 2859 PLT_ENTRY_SIZE); 1855 2860 /* Add offset for pushq GOT+8(%rip), since the instruction 1856 2861 uses 6 bytes subtract this value. */ 1857 2862 bfd_put_32 (output_bfd, 1858 ( sgot->output_section->vma1859 + sgot->output_offset2863 (htab->sgotplt->output_section->vma 2864 + htab->sgotplt->output_offset 1860 2865 + 8 1861 - splt->output_section->vma1862 - splt->output_offset2866 - htab->splt->output_section->vma 2867 - htab->splt->output_offset 1863 2868 - 6), 1864 splt->contents + 2);2869 htab->splt->contents + 2); 1865 2870 /* Add offset for jmp *GOT+16(%rip). The 12 is the offset to 1866 2871 the end of the instruction. */ 1867 2872 bfd_put_32 (output_bfd, 1868 ( sgot->output_section->vma1869 + sgot->output_offset2873 (htab->sgotplt->output_section->vma 2874 + htab->sgotplt->output_offset 1870 2875 + 16 1871 - splt->output_section->vma1872 - splt->output_offset2876 - htab->splt->output_section->vma 2877 - htab->splt->output_offset 1873 2878 - 12), 1874 splt->contents + 8); 1875 1876 } 1877 1878 elf_section_data (splt->output_section)->this_hdr.sh_entsize = 1879 PLT_ENTRY_SIZE; 1880 } 1881 1882 /* Set the first entry in the global offset table to the address of 1883 the dynamic section. */ 1884 if (sgot->_raw_size > 0) 1885 { 1886 if (sdyn == NULL) 1887 bfd_put_64 (output_bfd, (bfd_vma) 0, sgot->contents); 1888 else 1889 bfd_put_64 (output_bfd, 1890 sdyn->output_section->vma + sdyn->output_offset, 1891 sgot->contents); 1892 /* Write GOT[1] and GOT[2], needed for the dynamic linker. */ 1893 bfd_put_64 (output_bfd, (bfd_vma) 0, sgot->contents + GOT_ENTRY_SIZE); 1894 bfd_put_64 (output_bfd, (bfd_vma) 0, sgot->contents + GOT_ENTRY_SIZE*2); 1895 } 1896 1897 elf_section_data (sgot->output_section)->this_hdr.sh_entsize = 1898 GOT_ENTRY_SIZE; 1899 1900 return true; 2879 htab->splt->contents + 8); 2880 2881 elf_section_data (htab->splt->output_section)->this_hdr.sh_entsize = 2882 PLT_ENTRY_SIZE; 2883 } 2884 } 2885 2886 if (htab->sgotplt) 2887 { 2888 /* Fill in the first three entries in the global offset table. */ 2889 if (htab->sgotplt->_raw_size > 0) 2890 { 2891 /* Set the first entry in the global offset table to the address of 2892 the dynamic section. */ 2893 if (sdyn == NULL) 2894 bfd_put_64 (output_bfd, (bfd_vma) 0, htab->sgotplt->contents); 2895 else 2896 bfd_put_64 (output_bfd, 2897 sdyn->output_section->vma + sdyn->output_offset, 2898 htab->sgotplt->contents); 2899 /* Write GOT[1] and GOT[2], needed for the dynamic linker. */ 2900 bfd_put_64 (output_bfd, (bfd_vma) 0, htab->sgotplt->contents + GOT_ENTRY_SIZE); 2901 bfd_put_64 (output_bfd, (bfd_vma) 0, htab->sgotplt->contents + GOT_ENTRY_SIZE*2); 2902 } 2903 2904 elf_section_data (htab->sgotplt->output_section)->this_hdr.sh_entsize = 2905 GOT_ENTRY_SIZE; 2906 } 2907 2908 return TRUE; 1901 2909 } 1902 2910 … … 1909 2917 1910 2918 #define elf_backend_can_gc_sections 1 2919 #define elf_backend_can_refcount 1 1911 2920 #define elf_backend_want_got_plt 1 1912 2921 #define elf_backend_plt_readonly 1 … … 1914 2923 #define elf_backend_got_header_size (GOT_ENTRY_SIZE*3) 1915 2924 #define elf_backend_plt_header_size PLT_ENTRY_SIZE 2925 #define elf_backend_rela_normal 1 1916 2926 1917 2927 #define elf_info_to_howto elf64_x86_64_info_to_howto 1918 2928 1919 #define bfd_elf64_bfd_final_link _bfd_elf64_gc_common_final_link1920 2929 #define bfd_elf64_bfd_link_hash_table_create \ 1921 2930 elf64_x86_64_link_hash_table_create … … 1924 2933 #define elf_backend_adjust_dynamic_symbol elf64_x86_64_adjust_dynamic_symbol 1925 2934 #define elf_backend_check_relocs elf64_x86_64_check_relocs 1926 #define elf_backend_c reate_dynamic_sections _bfd_elf_create_dynamic_sections1927 #define elf_backend_ finish_dynamic_sections \1928 2935 #define elf_backend_copy_indirect_symbol elf64_x86_64_copy_indirect_symbol 2936 #define elf_backend_create_dynamic_sections elf64_x86_64_create_dynamic_sections 2937 #define elf_backend_finish_dynamic_sections elf64_x86_64_finish_dynamic_sections 1929 2938 #define elf_backend_finish_dynamic_symbol elf64_x86_64_finish_dynamic_symbol 1930 2939 #define elf_backend_gc_mark_hook elf64_x86_64_gc_mark_hook 1931 2940 #define elf_backend_gc_sweep_hook elf64_x86_64_gc_sweep_hook 2941 #define elf_backend_grok_prstatus elf64_x86_64_grok_prstatus 2942 #define elf_backend_grok_psinfo elf64_x86_64_grok_psinfo 2943 #define elf_backend_reloc_type_class elf64_x86_64_reloc_type_class 1932 2944 #define elf_backend_relocate_section elf64_x86_64_relocate_section 1933 2945 #define elf_backend_size_dynamic_sections elf64_x86_64_size_dynamic_sections 1934 2946 #define elf_backend_object_p elf64_x86_64_elf_object_p 2947 #define bfd_elf64_mkobject elf64_x86_64_mkobject 1935 2948 1936 2949 #include "elf64-target.h" -
Property cvs2svn:cvs-rev
changed from
Note:
See TracChangeset
for help on using the changeset viewer.