| 1 | /* x86 specific support for ELF |
| 2 | Copyright (C) 2017-2018 Free Software Foundation, Inc. |
| 3 | |
| 4 | This file is part of BFD, the Binary File Descriptor library. |
| 5 | |
| 6 | This program is free software; you can redistribute it and/or modify |
| 7 | it under the terms of the GNU General Public License as published by |
| 8 | the Free Software Foundation; either version 3 of the License, or |
| 9 | (at your option) any later version. |
| 10 | |
| 11 | This program is distributed in the hope that it will be useful, |
| 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 | GNU General Public License for more details. |
| 15 | |
| 16 | You should have received a copy of the GNU General Public License |
| 17 | along with this program; if not, write to the Free Software |
| 18 | Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, |
| 19 | MA 02110-1301, USA. */ |
| 20 | |
| 21 | #include "sysdep.h" |
| 22 | #include "bfd.h" |
| 23 | #include "bfdlink.h" |
| 24 | #include "libbfd.h" |
| 25 | #include "elf-bfd.h" |
| 26 | #include "bfd_stdint.h" |
| 27 | #include "hashtab.h" |
| 28 | |
| 29 | #define PLT_CIE_LENGTH 20 |
| 30 | #define PLT_FDE_LENGTH 36 |
| 31 | #define PLT_FDE_START_OFFSET 4 + PLT_CIE_LENGTH + 8 |
| 32 | #define PLT_FDE_LEN_OFFSET 4 + PLT_CIE_LENGTH + 12 |
| 33 | |
| 34 | #define ABI_64_P(abfd) \ |
| 35 | (get_elf_backend_data (abfd)->s->elfclass == ELFCLASS64) |
| 36 | |
| 37 | /* If ELIMINATE_COPY_RELOCS is non-zero, the linker will try to avoid |
| 38 | copying dynamic variables from a shared lib into an app's dynbss |
| 39 | section, and instead use a dynamic relocation to point into the |
| 40 | shared lib. */ |
| 41 | #define ELIMINATE_COPY_RELOCS 1 |
| 42 | |
| 43 | #define elf_x86_hash_table(p, id) \ |
| 44 | (is_elf_hash_table ((p)->hash) \ |
| 45 | && elf_hash_table_id ((struct elf_link_hash_table *) ((p)->hash)) == (id) \ |
| 46 | ? ((struct elf_x86_link_hash_table *) ((p)->hash)) : NULL) |
| 47 | |
| 48 | /* Will references to this symbol always be local in this object? */ |
| 49 | #define SYMBOL_REFERENCES_LOCAL_P(INFO, H) \ |
| 50 | _bfd_x86_elf_link_symbol_references_local ((INFO), (H)) |
| 51 | |
| 52 | /* TRUE if an undefined weak symbol should be resolved to 0. Local |
| 53 | undefined weak symbol is always resolved to 0. Reference to an |
| 54 | undefined weak symbol is resolved to 0 in executable if undefined |
| 55 | weak symbol should be resolved to 0 (zero_undefweak > 0). */ |
| 56 | #define UNDEFINED_WEAK_RESOLVED_TO_ZERO(INFO, EH) \ |
| 57 | ((EH)->elf.root.type == bfd_link_hash_undefweak \ |
| 58 | && (SYMBOL_REFERENCES_LOCAL_P ((INFO), &(EH)->elf) \ |
| 59 | || (bfd_link_executable (INFO) \ |
| 60 | && (EH)->zero_undefweak > 0))) |
| 61 | |
| 62 | /* Should copy relocation be generated for a symbol. Don't generate |
| 63 | copy relocation against a protected symbol defined in a shared |
| 64 | object with GNU_PROPERTY_NO_COPY_ON_PROTECTED. */ |
| 65 | #define SYMBOL_NO_COPYRELOC(INFO, EH) \ |
| 66 | ((EH)->def_protected \ |
| 67 | && ((EH)->elf.root.type == bfd_link_hash_defined \ |
| 68 | || (EH)->elf.root.type == bfd_link_hash_defweak) \ |
| 69 | && elf_has_no_copy_on_protected ((EH)->elf.root.u.def.section->owner) \ |
| 70 | && ((EH)->elf.root.u.def.section->owner->flags & DYNAMIC) != 0 \ |
| 71 | && ((EH)->elf.root.u.def.section->flags & SEC_CODE) == 0) |
| 72 | |
| 73 | /* TRUE if dynamic relocation is needed. If we are creating a shared |
| 74 | library, and this is a reloc against a global symbol, or a non PC |
| 75 | relative reloc against a local symbol, then we need to copy the reloc |
| 76 | into the shared library. However, if we are linking with -Bsymbolic, |
| 77 | we do not need to copy a reloc against a global symbol which is |
| 78 | defined in an object we are including in the link (i.e., DEF_REGULAR |
| 79 | is set). |
| 80 | |
| 81 | If PCREL_PLT is true, don't generate dynamic relocation in PIE for |
| 82 | PC-relative relocation against a dynamic function definition in data |
| 83 | section when PLT address can be used. |
| 84 | |
| 85 | If on the other hand, we are creating an executable, we may need to |
| 86 | keep relocations for symbols satisfied by a dynamic library if we |
| 87 | manage to avoid copy relocs for the symbol. |
| 88 | |
| 89 | We also need to generate dynamic pointer relocation against |
| 90 | STT_GNU_IFUNC symbol in the non-code section. */ |
| 91 | #define NEED_DYNAMIC_RELOCATION_P(INFO, PCREL_PLT, H, SEC, R_TYPE, \ |
| 92 | POINTER_TYPE) \ |
| 93 | ((bfd_link_pic (INFO) \ |
| 94 | && (! X86_PCREL_TYPE_P (R_TYPE) \ |
| 95 | || ((H) != NULL \ |
| 96 | && (! (bfd_link_pie (INFO) \ |
| 97 | || SYMBOLIC_BIND ((INFO), (H))) \ |
| 98 | || (H)->root.type == bfd_link_hash_defweak \ |
| 99 | || (!(bfd_link_pie (INFO) \ |
| 100 | && (PCREL_PLT) \ |
| 101 | && (H)->plt.refcount > 0 \ |
| 102 | && ((SEC)->flags & SEC_CODE) == 0 \ |
| 103 | && (H)->type == STT_FUNC \ |
| 104 | && (H)->def_dynamic) \ |
| 105 | && !(H)->def_regular))))) \ |
| 106 | || ((H) != NULL \ |
| 107 | && (H)->type == STT_GNU_IFUNC \ |
| 108 | && (R_TYPE) == POINTER_TYPE \ |
| 109 | && ((SEC)->flags & SEC_CODE) == 0) \ |
| 110 | || (ELIMINATE_COPY_RELOCS \ |
| 111 | && !bfd_link_pic (INFO) \ |
| 112 | && (H) != NULL \ |
| 113 | && ((H)->root.type == bfd_link_hash_defweak \ |
| 114 | || !(H)->def_regular))) |
| 115 | |
| 116 | /* TRUE if dynamic relocation should be generated. Don't copy a |
| 117 | pc-relative relocation into the output file if the symbol needs |
| 118 | copy reloc or the symbol is undefined when building executable. |
| 119 | Copy dynamic function pointer relocations. Don't generate dynamic |
| 120 | relocations against resolved undefined weak symbols in PIE, except |
| 121 | when PC32_RELOC is TRUE. Undefined weak symbol is bound locally |
| 122 | when PIC is false. */ |
| 123 | #define GENERATE_DYNAMIC_RELOCATION_P(INFO, EH, R_TYPE, \ |
| 124 | NEED_COPY_RELOC_IN_PIE, \ |
| 125 | RESOLVED_TO_ZERO, PC32_RELOC) \ |
| 126 | ((bfd_link_pic (INFO) \ |
| 127 | && !(NEED_COPY_RELOC_IN_PIE) \ |
| 128 | && ((EH) == NULL \ |
| 129 | || ((ELF_ST_VISIBILITY ((EH)->elf.other) == STV_DEFAULT \ |
| 130 | && (!(RESOLVED_TO_ZERO) || PC32_RELOC)) \ |
| 131 | || (EH)->elf.root.type != bfd_link_hash_undefweak)) \ |
| 132 | && ((!X86_PCREL_TYPE_P (R_TYPE) \ |
| 133 | && !X86_SIZE_TYPE_P (R_TYPE)) \ |
| 134 | || ! SYMBOL_CALLS_LOCAL ((INFO), &(EH)->elf))) \ |
| 135 | || (ELIMINATE_COPY_RELOCS \ |
| 136 | && !bfd_link_pic (INFO) \ |
| 137 | && (EH) != NULL \ |
| 138 | && (EH)->elf.dynindx != -1 \ |
| 139 | && (!(EH)->elf.non_got_ref \ |
| 140 | || ((EH)->elf.root.type == bfd_link_hash_undefweak \ |
| 141 | && !(RESOLVED_TO_ZERO))) \ |
| 142 | && (((EH)->elf.def_dynamic && !(EH)->elf.def_regular) \ |
| 143 | || (EH)->elf.root.type == bfd_link_hash_undefined))) |
| 144 | |
| 145 | /* TRUE if this input relocation should be copied to output. H->dynindx |
| 146 | may be -1 if this symbol was marked to become local. */ |
| 147 | #define COPY_INPUT_RELOC_P(INFO, H, R_TYPE) \ |
| 148 | ((H) != NULL \ |
| 149 | && (H)->dynindx != -1 \ |
| 150 | && (X86_PCREL_TYPE_P (R_TYPE) \ |
| 151 | || !(bfd_link_executable (INFO) || SYMBOLIC_BIND ((INFO), (H))) \ |
| 152 | || !(H)->def_regular)) |
| 153 | |
| 154 | /* TRUE if this is actually a static link, or it is a -Bsymbolic link |
| 155 | and the symbol is defined locally, or the symbol was forced to be |
| 156 | local because of a version file. */ |
| 157 | #define RESOLVED_LOCALLY_P(INFO, H, HTAB) \ |
| 158 | (!WILL_CALL_FINISH_DYNAMIC_SYMBOL ((HTAB)->elf.dynamic_sections_created, \ |
| 159 | bfd_link_pic (INFO), (H)) \ |
| 160 | || (bfd_link_pic (INFO) \ |
| 161 | && SYMBOL_REFERENCES_LOCAL_P ((INFO), (H))) \ |
| 162 | || (ELF_ST_VISIBILITY ((H)->other) \ |
| 163 | && (H)->root.type == bfd_link_hash_undefweak)) |
| 164 | |
| 165 | /* TRUE if relative relocation should be generated. GOT reference to |
| 166 | global symbol in PIC will lead to dynamic symbol. It becomes a |
| 167 | problem when "time" or "times" is defined as a variable in an |
| 168 | executable, clashing with functions of the same name in libc. If a |
| 169 | symbol isn't undefined weak symbol, don't make it dynamic in PIC and |
| 170 | generate relative relocation. */ |
| 171 | #define GENERATE_RELATIVE_RELOC_P(INFO, H) \ |
| 172 | ((H)->dynindx == -1 \ |
| 173 | && !(H)->forced_local \ |
| 174 | && (H)->root.type != bfd_link_hash_undefweak \ |
| 175 | && bfd_link_pic (INFO)) |
| 176 | |
| 177 | /* TRUE if this is a pointer reference to a local IFUNC. */ |
| 178 | #define POINTER_LOCAL_IFUNC_P(INFO, H) \ |
| 179 | ((H)->dynindx == -1 \ |
| 180 | || (H)->forced_local \ |
| 181 | || bfd_link_executable (INFO)) |
| 182 | |
| 183 | /* TRUE if this is a PLT reference to a local IFUNC. */ |
| 184 | #define PLT_LOCAL_IFUNC_P(INFO, H) \ |
| 185 | ((H)->dynindx == -1 \ |
| 186 | || ((bfd_link_executable (INFO) \ |
| 187 | || ELF_ST_VISIBILITY ((H)->other) != STV_DEFAULT) \ |
| 188 | && (H)->def_regular \ |
| 189 | && (H)->type == STT_GNU_IFUNC)) |
| 190 | |
| 191 | /* TRUE if TLS IE->LE transition is OK. */ |
| 192 | #define TLS_TRANSITION_IE_TO_LE_P(INFO, H, TLS_TYPE) \ |
| 193 | (bfd_link_executable (INFO) \ |
| 194 | && (H) != NULL \ |
| 195 | && (H)->dynindx == -1 \ |
| 196 | && (TLS_TYPE & GOT_TLS_IE)) |
| 197 | |
| 198 | /* Verify that the symbol has an entry in the procedure linkage table. */ |
| 199 | #define VERIFY_PLT_ENTRY(INFO, H, PLT, GOTPLT, RELPLT, LOCAL_UNDEFWEAK) \ |
| 200 | do \ |
| 201 | { \ |
| 202 | if (((H)->dynindx == -1 \ |
| 203 | && !LOCAL_UNDEFWEAK \ |
| 204 | && !(((H)->forced_local || bfd_link_executable (INFO)) \ |
| 205 | && (H)->def_regular \ |
| 206 | && (H)->type == STT_GNU_IFUNC)) \ |
| 207 | || (PLT) == NULL \ |
| 208 | || (GOTPLT) == NULL \ |
| 209 | || (RELPLT) == NULL) \ |
| 210 | abort (); \ |
| 211 | } \ |
| 212 | while (0); |
| 213 | |
| 214 | /* Verify that the symbol supports copy relocation. */ |
| 215 | #define VERIFY_COPY_RELOC(H, HTAB) \ |
| 216 | do \ |
| 217 | { \ |
| 218 | if ((H)->dynindx == -1 \ |
| 219 | || ((H)->root.type != bfd_link_hash_defined \ |
| 220 | && (H)->root.type != bfd_link_hash_defweak) \ |
| 221 | || (HTAB)->elf.srelbss == NULL \ |
| 222 | || (HTAB)->elf.sreldynrelro == NULL) \ |
| 223 | abort (); \ |
| 224 | } \ |
| 225 | while (0); |
| 226 | |
| 227 | /* x86 ELF linker hash entry. */ |
| 228 | |
| 229 | struct elf_x86_link_hash_entry |
| 230 | { |
| 231 | struct elf_link_hash_entry elf; |
| 232 | |
| 233 | /* Track dynamic relocs copied for this symbol. */ |
| 234 | struct elf_dyn_relocs *dyn_relocs; |
| 235 | |
| 236 | unsigned char tls_type; |
| 237 | |
| 238 | /* Bit 0: Symbol has no GOT nor PLT relocations. |
| 239 | Bit 1: Symbol has non-GOT/non-PLT relocations in text sections. |
| 240 | zero_undefweak is initialized to 1 and undefined weak symbol |
| 241 | should be resolved to 0 if zero_undefweak > 0. */ |
| 242 | unsigned int zero_undefweak : 2; |
| 243 | |
| 244 | /* Don't call finish_dynamic_symbol on this symbol. */ |
| 245 | unsigned int no_finish_dynamic_symbol : 1; |
| 246 | |
| 247 | /* TRUE if symbol is __tls_get_addr. */ |
| 248 | unsigned int tls_get_addr : 1; |
| 249 | |
| 250 | /* TRUE if symbol is defined as a protected symbol. */ |
| 251 | unsigned int def_protected : 1; |
| 252 | |
| 253 | /* 0: Symbol references are unknown. |
| 254 | 1: Symbol references aren't local. |
| 255 | 2: Symbol references are local. |
| 256 | */ |
| 257 | unsigned int local_ref : 2; |
| 258 | |
| 259 | /* TRUE if symbol is defined by linker. */ |
| 260 | unsigned int linker_def : 1; |
| 261 | |
| 262 | /* TRUE if symbol is referenced by R_386_GOTOFF relocation. This is |
| 263 | only used by i386. */ |
| 264 | unsigned int gotoff_ref : 1; |
| 265 | |
| 266 | /* TRUE if a weak symbol with a real definition needs a copy reloc. |
| 267 | When there is a weak symbol with a real definition, the processor |
| 268 | independent code will have arranged for us to see the real |
| 269 | definition first. We need to copy the needs_copy bit from the |
| 270 | real definition and check it when allowing copy reloc in PIE. This |
| 271 | is only used by x86-64. */ |
| 272 | unsigned int needs_copy : 1; |
| 273 | |
| 274 | /* Information about the GOT PLT entry. Filled when there are both |
| 275 | GOT and PLT relocations against the same function. */ |
| 276 | union gotplt_union plt_got; |
| 277 | |
| 278 | /* Information about the second PLT entry. */ |
| 279 | union gotplt_union plt_second; |
| 280 | |
| 281 | /* Offset of the GOTPLT entry reserved for the TLS descriptor, |
| 282 | starting at the end of the jump table. */ |
| 283 | bfd_vma tlsdesc_got; |
| 284 | }; |
| 285 | |
| 286 | struct elf_x86_lazy_plt_layout |
| 287 | { |
| 288 | /* The first entry in an absolute lazy procedure linkage table looks |
| 289 | like this. */ |
| 290 | const bfd_byte *plt0_entry; |
| 291 | unsigned int plt0_entry_size; /* Size of PLT0 entry. */ |
| 292 | |
| 293 | /* Later entries in an absolute lazy procedure linkage table look |
| 294 | like this. */ |
| 295 | const bfd_byte *plt_entry; |
| 296 | unsigned int plt_entry_size; /* Size of each PLT entry. */ |
| 297 | |
| 298 | /* Offsets into plt0_entry that are to be replaced with GOT[1] and |
| 299 | GOT[2]. */ |
| 300 | unsigned int plt0_got1_offset; |
| 301 | unsigned int plt0_got2_offset; |
| 302 | |
| 303 | /* Offset of the end of the PC-relative instruction containing |
| 304 | plt0_got2_offset. This is for x86-64 only. */ |
| 305 | unsigned int plt0_got2_insn_end; |
| 306 | |
| 307 | /* Offsets into plt_entry that are to be replaced with... */ |
| 308 | unsigned int plt_got_offset; /* ... address of this symbol in .got. */ |
| 309 | unsigned int plt_reloc_offset; /* ... offset into relocation table. */ |
| 310 | unsigned int plt_plt_offset; /* ... offset to start of .plt. */ |
| 311 | |
| 312 | /* Length of the PC-relative instruction containing plt_got_offset. |
| 313 | This is used for x86-64 only. */ |
| 314 | unsigned int plt_got_insn_size; |
| 315 | |
| 316 | /* Offset of the end of the PC-relative jump to plt0_entry. This is |
| 317 | used for x86-64 only. */ |
| 318 | unsigned int plt_plt_insn_end; |
| 319 | |
| 320 | /* Offset into plt_entry where the initial value of the GOT entry |
| 321 | points. */ |
| 322 | unsigned int plt_lazy_offset; |
| 323 | |
| 324 | /* The first entry in a PIC lazy procedure linkage table looks like |
| 325 | this. */ |
| 326 | const bfd_byte *pic_plt0_entry; |
| 327 | |
| 328 | /* Subsequent entries in a PIC lazy procedure linkage table look |
| 329 | like this. */ |
| 330 | const bfd_byte *pic_plt_entry; |
| 331 | |
| 332 | /* .eh_frame covering the lazy .plt section. */ |
| 333 | const bfd_byte *eh_frame_plt; |
| 334 | unsigned int eh_frame_plt_size; |
| 335 | }; |
| 336 | |
| 337 | struct elf_x86_non_lazy_plt_layout |
| 338 | { |
| 339 | /* Entries in an absolute non-lazy procedure linkage table look like |
| 340 | this. */ |
| 341 | const bfd_byte *plt_entry; |
| 342 | /* Entries in a PIC non-lazy procedure linkage table look like this. */ |
| 343 | const bfd_byte *pic_plt_entry; |
| 344 | |
| 345 | unsigned int plt_entry_size; /* Size of each PLT entry. */ |
| 346 | |
| 347 | /* Offsets into plt_entry that are to be replaced with... */ |
| 348 | unsigned int plt_got_offset; /* ... address of this symbol in .got. */ |
| 349 | |
| 350 | /* Length of the PC-relative instruction containing plt_got_offset. |
| 351 | This is used for x86-64 only. */ |
| 352 | unsigned int plt_got_insn_size; |
| 353 | |
| 354 | /* .eh_frame covering the non-lazy .plt section. */ |
| 355 | const bfd_byte *eh_frame_plt; |
| 356 | unsigned int eh_frame_plt_size; |
| 357 | }; |
| 358 | |
| 359 | struct elf_x86_plt_layout |
| 360 | { |
| 361 | /* The first entry in a lazy procedure linkage table looks like this. |
| 362 | This is only used for i386 where absolute PLT0 and PIC PLT0 are |
| 363 | different. */ |
| 364 | const bfd_byte *plt0_entry; |
| 365 | /* Entries in a procedure linkage table look like this. */ |
| 366 | const bfd_byte *plt_entry; |
| 367 | unsigned int plt_entry_size; /* Size of each PLT entry. */ |
| 368 | |
| 369 | /* 1 has PLT0. */ |
| 370 | unsigned int has_plt0; |
| 371 | |
| 372 | /* Offsets into plt_entry that are to be replaced with... */ |
| 373 | unsigned int plt_got_offset; /* ... address of this symbol in .got. */ |
| 374 | |
| 375 | /* Length of the PC-relative instruction containing plt_got_offset. |
| 376 | This is only used for x86-64. */ |
| 377 | unsigned int plt_got_insn_size; |
| 378 | |
| 379 | /* .eh_frame covering the .plt section. */ |
| 380 | const bfd_byte *eh_frame_plt; |
| 381 | unsigned int eh_frame_plt_size; |
| 382 | }; |
| 383 | |
| 384 | /* Values in tls_type of x86 ELF linker hash entry. */ |
| 385 | #define GOT_UNKNOWN 0 |
| 386 | #define GOT_NORMAL 1 |
| 387 | #define GOT_TLS_GD 2 |
| 388 | #define GOT_TLS_IE 4 |
| 389 | #define GOT_TLS_IE_POS 5 |
| 390 | #define GOT_TLS_IE_NEG 6 |
| 391 | #define GOT_TLS_IE_BOTH 7 |
| 392 | #define GOT_TLS_GDESC 8 |
| 393 | #define GOT_TLS_GD_BOTH_P(type) \ |
| 394 | ((type) == (GOT_TLS_GD | GOT_TLS_GDESC)) |
| 395 | #define GOT_TLS_GD_P(type) \ |
| 396 | ((type) == GOT_TLS_GD || GOT_TLS_GD_BOTH_P (type)) |
| 397 | #define GOT_TLS_GDESC_P(type) \ |
| 398 | ((type) == GOT_TLS_GDESC || GOT_TLS_GD_BOTH_P (type)) |
| 399 | #define GOT_TLS_GD_ANY_P(type) \ |
| 400 | (GOT_TLS_GD_P (type) || GOT_TLS_GDESC_P (type)) |
| 401 | |
| 402 | #define elf_x86_hash_entry(ent) \ |
| 403 | ((struct elf_x86_link_hash_entry *)(ent)) |
| 404 | |
| 405 | enum elf_x86_target_os |
| 406 | { |
| 407 | is_normal, |
| 408 | is_solaris, |
| 409 | is_vxworks, |
| 410 | is_nacl |
| 411 | }; |
| 412 | |
| 413 | /* x86 ELF linker hash table. */ |
| 414 | |
| 415 | struct elf_x86_link_hash_table |
| 416 | { |
| 417 | struct elf_link_hash_table elf; |
| 418 | |
| 419 | /* Short-cuts to get to dynamic linker sections. */ |
| 420 | asection *interp; |
| 421 | asection *plt_eh_frame; |
| 422 | asection *plt_second; |
| 423 | asection *plt_second_eh_frame; |
| 424 | asection *plt_got; |
| 425 | asection *plt_got_eh_frame; |
| 426 | |
| 427 | /* Parameters describing PLT generation, lazy or non-lazy. */ |
| 428 | struct elf_x86_plt_layout plt; |
| 429 | |
| 430 | /* Parameters describing lazy PLT generation. */ |
| 431 | const struct elf_x86_lazy_plt_layout *lazy_plt; |
| 432 | |
| 433 | /* Parameters describing non-lazy PLT generation. */ |
| 434 | const struct elf_x86_non_lazy_plt_layout *non_lazy_plt; |
| 435 | |
| 436 | union |
| 437 | { |
| 438 | bfd_signed_vma refcount; |
| 439 | bfd_vma offset; |
| 440 | } tls_ld_or_ldm_got; |
| 441 | |
| 442 | /* The amount of space used by the jump slots in the GOT. */ |
| 443 | bfd_vma sgotplt_jump_table_size; |
| 444 | |
| 445 | /* Small local sym cache. */ |
| 446 | struct sym_cache sym_cache; |
| 447 | |
| 448 | /* _TLS_MODULE_BASE_ symbol. */ |
| 449 | struct bfd_link_hash_entry *tls_module_base; |
| 450 | |
| 451 | /* Used by local STT_GNU_IFUNC symbols. */ |
| 452 | htab_t loc_hash_table; |
| 453 | void * loc_hash_memory; |
| 454 | |
| 455 | /* The offset into sgot of the GOT entry used by the PLT entry |
| 456 | above. */ |
| 457 | bfd_vma tlsdesc_got; |
| 458 | |
| 459 | /* The index of the next R_X86_64_JUMP_SLOT entry in .rela.plt. */ |
| 460 | bfd_vma next_jump_slot_index; |
| 461 | /* The index of the next R_X86_64_IRELATIVE entry in .rela.plt. */ |
| 462 | bfd_vma next_irelative_index; |
| 463 | |
| 464 | /* TRUE if there are dynamic relocs against IFUNC symbols that apply |
| 465 | to read-only sections. */ |
| 466 | bfd_boolean readonly_dynrelocs_against_ifunc; |
| 467 | |
| 468 | /* The (unloaded but important) .rel.plt.unloaded section on VxWorks. |
| 469 | This is used for i386 only. */ |
| 470 | asection *srelplt2; |
| 471 | |
| 472 | /* The index of the next unused R_386_TLS_DESC slot in .rel.plt. This |
| 473 | is only used for i386. */ |
| 474 | bfd_vma next_tls_desc_index; |
| 475 | |
| 476 | /* The offset into splt of the PLT entry for the TLS descriptor |
| 477 | resolver. Special values are 0, if not necessary (or not found |
| 478 | to be necessary yet), and -1 if needed but not determined |
| 479 | yet. This is only used for x86-64. */ |
| 480 | bfd_vma tlsdesc_plt; |
| 481 | |
| 482 | /* Value used to fill the unused bytes of the first PLT entry. This |
| 483 | is only used for i386. */ |
| 484 | bfd_byte plt0_pad_byte; |
| 485 | |
| 486 | /* TRUE if GOT is referenced. */ |
| 487 | unsigned int got_referenced : 1; |
| 488 | |
| 489 | /* TRUE if PLT is PC-relative. PLT in PDE and PC-relative PLT in PIE |
| 490 | can be used as function address. |
| 491 | |
| 492 | NB: i386 has non-PIC PLT and PIC PLT. Only non-PIC PLT in PDE can |
| 493 | be used as function address. PIC PLT in PIE can't be used as |
| 494 | function address. */ |
| 495 | unsigned int pcrel_plt : 1; |
| 496 | |
| 497 | bfd_vma (*r_info) (bfd_vma, bfd_vma); |
| 498 | bfd_vma (*r_sym) (bfd_vma); |
| 499 | bfd_boolean (*is_reloc_section) (const char *); |
| 500 | enum elf_target_id target_id; |
| 501 | enum elf_x86_target_os target_os; |
| 502 | unsigned int sizeof_reloc; |
| 503 | unsigned int dt_reloc; |
| 504 | unsigned int dt_reloc_sz; |
| 505 | unsigned int dt_reloc_ent; |
| 506 | unsigned int got_entry_size; |
| 507 | unsigned int pointer_r_type; |
| 508 | int dynamic_interpreter_size; |
| 509 | const char *dynamic_interpreter; |
| 510 | const char *tls_get_addr; |
| 511 | }; |
| 512 | |
| 513 | /* Architecture-specific backend data for x86. */ |
| 514 | |
| 515 | struct elf_x86_backend_data |
| 516 | { |
| 517 | /* Target system. */ |
| 518 | enum elf_x86_target_os target_os; |
| 519 | }; |
| 520 | |
| 521 | #define get_elf_x86_backend_data(abfd) \ |
| 522 | ((const struct elf_x86_backend_data *) \ |
| 523 | get_elf_backend_data (abfd)->arch_data) |
| 524 | |
| 525 | struct elf_x86_init_table |
| 526 | { |
| 527 | /* The lazy PLT layout. */ |
| 528 | const struct elf_x86_lazy_plt_layout *lazy_plt; |
| 529 | |
| 530 | /* The non-lazy PLT layout. */ |
| 531 | const struct elf_x86_non_lazy_plt_layout *non_lazy_plt; |
| 532 | |
| 533 | /* The lazy PLT layout for IBT. */ |
| 534 | const struct elf_x86_lazy_plt_layout *lazy_ibt_plt; |
| 535 | |
| 536 | /* The non-lazy PLT layout for IBT. */ |
| 537 | const struct elf_x86_non_lazy_plt_layout *non_lazy_ibt_plt; |
| 538 | |
| 539 | bfd_byte plt0_pad_byte; |
| 540 | |
| 541 | bfd_vma (*r_info) (bfd_vma, bfd_vma); |
| 542 | bfd_vma (*r_sym) (bfd_vma); |
| 543 | }; |
| 544 | |
| 545 | struct elf_x86_obj_tdata |
| 546 | { |
| 547 | struct elf_obj_tdata root; |
| 548 | |
| 549 | /* tls_type for each local got entry. */ |
| 550 | char *local_got_tls_type; |
| 551 | |
| 552 | /* GOTPLT entries for TLS descriptors. */ |
| 553 | bfd_vma *local_tlsdesc_gotent; |
| 554 | }; |
| 555 | |
| 556 | enum elf_x86_plt_type |
| 557 | { |
| 558 | plt_non_lazy = 0, |
| 559 | plt_lazy = 1 << 0, |
| 560 | plt_pic = 1 << 1, |
| 561 | plt_second = 1 << 2, |
| 562 | plt_unknown = -1 |
| 563 | }; |
| 564 | |
| 565 | struct elf_x86_plt |
| 566 | { |
| 567 | const char *name; |
| 568 | asection *sec; |
| 569 | bfd_byte *contents; |
| 570 | enum elf_x86_plt_type type; |
| 571 | unsigned int plt_got_offset; |
| 572 | unsigned int plt_entry_size; |
| 573 | unsigned int plt_got_insn_size; /* Only used for x86-64. */ |
| 574 | long count; |
| 575 | }; |
| 576 | |
| 577 | #define elf_x86_tdata(abfd) \ |
| 578 | ((struct elf_x86_obj_tdata *) (abfd)->tdata.any) |
| 579 | |
| 580 | #define elf_x86_local_got_tls_type(abfd) \ |
| 581 | (elf_x86_tdata (abfd)->local_got_tls_type) |
| 582 | |
| 583 | #define elf_x86_local_tlsdesc_gotent(abfd) \ |
| 584 | (elf_x86_tdata (abfd)->local_tlsdesc_gotent) |
| 585 | |
| 586 | #define elf_x86_compute_jump_table_size(htab) \ |
| 587 | ((htab)->elf.srelplt->reloc_count * (htab)->got_entry_size) |
| 588 | |
| 589 | #define is_x86_elf(bfd, htab) \ |
| 590 | (bfd_get_flavour (bfd) == bfd_target_elf_flavour \ |
| 591 | && elf_tdata (bfd) != NULL \ |
| 592 | && elf_object_id (bfd) == (htab)->target_id) |
| 593 | |
| 594 | extern bfd_boolean _bfd_x86_elf_mkobject |
| 595 | (bfd *); |
| 596 | |
| 597 | extern void _bfd_x86_elf_set_tls_module_base |
| 598 | (struct bfd_link_info *); |
| 599 | |
| 600 | extern bfd_vma _bfd_x86_elf_dtpoff_base |
| 601 | (struct bfd_link_info *); |
| 602 | |
| 603 | extern bfd_boolean _bfd_x86_elf_readonly_dynrelocs |
| 604 | (struct elf_link_hash_entry *, void *); |
| 605 | |
| 606 | extern struct elf_link_hash_entry * _bfd_elf_x86_get_local_sym_hash |
| 607 | (struct elf_x86_link_hash_table *, bfd *, const Elf_Internal_Rela *, |
| 608 | bfd_boolean); |
| 609 | |
| 610 | extern hashval_t _bfd_x86_elf_local_htab_hash |
| 611 | (const void *); |
| 612 | |
| 613 | extern int _bfd_x86_elf_local_htab_eq |
| 614 | (const void *, const void *); |
| 615 | |
| 616 | extern struct bfd_hash_entry * _bfd_x86_elf_link_hash_newfunc |
| 617 | (struct bfd_hash_entry *, struct bfd_hash_table *, const char *); |
| 618 | |
| 619 | extern struct bfd_link_hash_table * _bfd_x86_elf_link_hash_table_create |
| 620 | (bfd *); |
| 621 | |
| 622 | extern int _bfd_x86_elf_compare_relocs |
| 623 | (const void *, const void *); |
| 624 | |
| 625 | extern bfd_boolean _bfd_x86_elf_link_check_relocs |
| 626 | (bfd *, struct bfd_link_info *); |
| 627 | |
| 628 | extern bfd_boolean _bfd_x86_elf_size_dynamic_sections |
| 629 | (bfd *, struct bfd_link_info *); |
| 630 | |
| 631 | extern struct elf_x86_link_hash_table *_bfd_x86_elf_finish_dynamic_sections |
| 632 | (bfd *, struct bfd_link_info *); |
| 633 | |
| 634 | extern bfd_boolean _bfd_x86_elf_always_size_sections |
| 635 | (bfd *, struct bfd_link_info *); |
| 636 | |
| 637 | extern void _bfd_x86_elf_merge_symbol_attribute |
| 638 | (struct elf_link_hash_entry *, const Elf_Internal_Sym *, |
| 639 | bfd_boolean, bfd_boolean); |
| 640 | |
| 641 | extern void _bfd_x86_elf_copy_indirect_symbol |
| 642 | (struct bfd_link_info *, struct elf_link_hash_entry *, |
| 643 | struct elf_link_hash_entry *); |
| 644 | |
| 645 | extern bfd_boolean _bfd_x86_elf_fixup_symbol |
| 646 | (struct bfd_link_info *, struct elf_link_hash_entry *); |
| 647 | |
| 648 | extern bfd_boolean _bfd_x86_elf_hash_symbol |
| 649 | (struct elf_link_hash_entry *); |
| 650 | |
| 651 | extern bfd_boolean _bfd_x86_elf_adjust_dynamic_symbol |
| 652 | (struct bfd_link_info *, struct elf_link_hash_entry *); |
| 653 | |
| 654 | extern void _bfd_x86_elf_hide_symbol |
| 655 | (struct bfd_link_info *, struct elf_link_hash_entry *, bfd_boolean); |
| 656 | |
| 657 | extern bfd_boolean _bfd_x86_elf_link_symbol_references_local |
| 658 | (struct bfd_link_info *, struct elf_link_hash_entry *); |
| 659 | |
| 660 | extern asection * _bfd_x86_elf_gc_mark_hook |
| 661 | (asection *, struct bfd_link_info *, Elf_Internal_Rela *, |
| 662 | struct elf_link_hash_entry *, Elf_Internal_Sym *); |
| 663 | |
| 664 | extern long _bfd_x86_elf_get_synthetic_symtab |
| 665 | (bfd *, long, long, bfd_vma, struct elf_x86_plt [], asymbol **, |
| 666 | asymbol **); |
| 667 | |
| 668 | extern enum elf_property_kind _bfd_x86_elf_parse_gnu_properties |
| 669 | (bfd *, unsigned int, bfd_byte *, unsigned int); |
| 670 | |
| 671 | extern bfd_boolean _bfd_x86_elf_merge_gnu_properties |
| 672 | (struct bfd_link_info *, bfd *, elf_property *, elf_property *); |
| 673 | |
| 674 | extern bfd * _bfd_x86_elf_link_setup_gnu_properties |
| 675 | (struct bfd_link_info *, struct elf_x86_init_table *); |
| 676 | |
| 677 | #define bfd_elf64_mkobject \ |
| 678 | _bfd_x86_elf_mkobject |
| 679 | #define bfd_elf32_mkobject \ |
| 680 | _bfd_x86_elf_mkobject |
| 681 | #define bfd_elf64_bfd_link_hash_table_create \ |
| 682 | _bfd_x86_elf_link_hash_table_create |
| 683 | #define bfd_elf32_bfd_link_hash_table_create \ |
| 684 | _bfd_x86_elf_link_hash_table_create |
| 685 | #define bfd_elf64_bfd_link_check_relocs \ |
| 686 | _bfd_x86_elf_link_check_relocs |
| 687 | #define bfd_elf32_bfd_link_check_relocs \ |
| 688 | _bfd_x86_elf_link_check_relocs |
| 689 | |
| 690 | #define elf_backend_size_dynamic_sections \ |
| 691 | _bfd_x86_elf_size_dynamic_sections |
| 692 | #define elf_backend_always_size_sections \ |
| 693 | _bfd_x86_elf_always_size_sections |
| 694 | #define elf_backend_merge_symbol_attribute \ |
| 695 | _bfd_x86_elf_merge_symbol_attribute |
| 696 | #define elf_backend_copy_indirect_symbol \ |
| 697 | _bfd_x86_elf_copy_indirect_symbol |
| 698 | #define elf_backend_fixup_symbol \ |
| 699 | _bfd_x86_elf_fixup_symbol |
| 700 | #define elf_backend_hash_symbol \ |
| 701 | _bfd_x86_elf_hash_symbol |
| 702 | #define elf_backend_adjust_dynamic_symbol \ |
| 703 | _bfd_x86_elf_adjust_dynamic_symbol |
| 704 | #define elf_backend_gc_mark_hook \ |
| 705 | _bfd_x86_elf_gc_mark_hook |
| 706 | #define elf_backend_omit_section_dynsym \ |
| 707 | _bfd_elf_omit_section_dynsym_all |
| 708 | #define elf_backend_parse_gnu_properties \ |
| 709 | _bfd_x86_elf_parse_gnu_properties |
| 710 | #define elf_backend_merge_gnu_properties \ |
| 711 | _bfd_x86_elf_merge_gnu_properties |