elf64-ppc.c (272888) | elf64-ppc.c (275718) |
---|---|
1/* PowerPC64-specific support for 64-bit ELF. 2 Copyright 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007 3 Free Software Foundation, Inc. 4 Written by Linus Nordberg, Swox AB <info@swox.com>, 5 based on elf32-ppc.c by Ian Lance Taylor. 6 Largely rewritten by Alan Modra <amodra@bigpond.net.au> 7 8 This file is part of BFD, the Binary File Descriptor library. --- 116 unchanged lines hidden (view full) --- 125#define TOC_BASE_OFF 0x8000 126 127/* Offset of tp and dtp pointers from start of TLS block. */ 128#define TP_OFFSET 0x7000 129#define DTP_OFFSET 0x8000 130 131/* .plt call stub instructions. The normal stub is like this, but 132 sometimes the .plt entry crosses a 64k boundary and we need to | 1/* PowerPC64-specific support for 64-bit ELF. 2 Copyright 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007 3 Free Software Foundation, Inc. 4 Written by Linus Nordberg, Swox AB <info@swox.com>, 5 based on elf32-ppc.c by Ian Lance Taylor. 6 Largely rewritten by Alan Modra <amodra@bigpond.net.au> 7 8 This file is part of BFD, the Binary File Descriptor library. --- 116 unchanged lines hidden (view full) --- 125#define TOC_BASE_OFF 0x8000 126 127/* Offset of tp and dtp pointers from start of TLS block. */ 128#define TP_OFFSET 0x7000 129#define DTP_OFFSET 0x8000 130 131/* .plt call stub instructions. The normal stub is like this, but 132 sometimes the .plt entry crosses a 64k boundary and we need to |
133 insert an addis to adjust r12. */ | 133 insert an addi to adjust r12. */ |
134#define PLT_CALL_STUB_SIZE (7*4) 135#define ADDIS_R12_R2 0x3d820000 /* addis %r12,%r2,xxx@ha */ 136#define STD_R2_40R1 0xf8410028 /* std %r2,40(%r1) */ 137#define LD_R11_0R12 0xe96c0000 /* ld %r11,xxx+0@l(%r12) */ | 134#define PLT_CALL_STUB_SIZE (7*4) 135#define ADDIS_R12_R2 0x3d820000 /* addis %r12,%r2,xxx@ha */ 136#define STD_R2_40R1 0xf8410028 /* std %r2,40(%r1) */ 137#define LD_R11_0R12 0xe96c0000 /* ld %r11,xxx+0@l(%r12) */ |
138#define LD_R2_0R12 0xe84c0000 /* ld %r2,xxx+8@l(%r12) */ | |
139#define MTCTR_R11 0x7d6903a6 /* mtctr %r11 */ | 138#define MTCTR_R11 0x7d6903a6 /* mtctr %r11 */ |
139#define LD_R2_0R12 0xe84c0000 /* ld %r2,xxx+8@l(%r12) */ |
|
140 /* ld %r11,xxx+16@l(%r12) */ 141#define BCTR 0x4e800420 /* bctr */ 142 143 144#define ADDIS_R12_R12 0x3d8c0000 /* addis %r12,%r12,off@ha */ | 140 /* ld %r11,xxx+16@l(%r12) */ 141#define BCTR 0x4e800420 /* bctr */ 142 143 144#define ADDIS_R12_R12 0x3d8c0000 /* addis %r12,%r12,off@ha */ |
145#define ADDI_R12_R12 0x398c0000 /* addi %r12,%r12,off@l */ |
|
145#define ADDIS_R2_R2 0x3c420000 /* addis %r2,%r2,off@ha */ 146#define ADDI_R2_R2 0x38420000 /* addi %r2,%r2,off@l */ 147 | 146#define ADDIS_R2_R2 0x3c420000 /* addis %r2,%r2,off@ha */ 147#define ADDI_R2_R2 0x38420000 /* addi %r2,%r2,off@l */ 148 |
149#define LD_R11_0R2 0xe9620000 /* ld %r11,xxx+0(%r2) */ 150#define LD_R2_0R2 0xe8420000 /* ld %r2,xxx+0(%r2) */ 151 |
|
148#define LD_R2_40R1 0xe8410028 /* ld %r2,40(%r1) */ 149 150/* glink call stub instructions. We enter with the index in R0. */ 151#define GLINK_CALL_STUB_SIZE (16*4) 152 /* 0: */ 153 /* .quad plt0-1f */ 154 /* __glink: */ 155#define MFLR_R12 0x7d8802a6 /* mflr %12 */ --- 1068 unchanged lines hidden (view full) --- 1224 complain_overflow_dont, /* complain_on_overflow */ 1225 ppc64_elf_unhandled_reloc, /* special_function */ 1226 "R_PPC64_PLTGOT16_LO_DS",/* name */ 1227 FALSE, /* partial_inplace */ 1228 0, /* src_mask */ 1229 0xfffc, /* dst_mask */ 1230 FALSE), /* pcrel_offset */ 1231 | 152#define LD_R2_40R1 0xe8410028 /* ld %r2,40(%r1) */ 153 154/* glink call stub instructions. We enter with the index in R0. */ 155#define GLINK_CALL_STUB_SIZE (16*4) 156 /* 0: */ 157 /* .quad plt0-1f */ 158 /* __glink: */ 159#define MFLR_R12 0x7d8802a6 /* mflr %12 */ --- 1068 unchanged lines hidden (view full) --- 1228 complain_overflow_dont, /* complain_on_overflow */ 1229 ppc64_elf_unhandled_reloc, /* special_function */ 1230 "R_PPC64_PLTGOT16_LO_DS",/* name */ 1231 FALSE, /* partial_inplace */ 1232 0, /* src_mask */ 1233 0xfffc, /* dst_mask */ 1234 FALSE), /* pcrel_offset */ 1235 |
1232 /* Marker reloc for TLS. */ | 1236 /* Marker relocs for TLS. */ |
1233 HOWTO (R_PPC64_TLS, 1234 0, /* rightshift */ 1235 2, /* size (0 = byte, 1 = short, 2 = long) */ 1236 32, /* bitsize */ 1237 FALSE, /* pc_relative */ 1238 0, /* bitpos */ 1239 complain_overflow_dont, /* complain_on_overflow */ 1240 bfd_elf_generic_reloc, /* special_function */ 1241 "R_PPC64_TLS", /* name */ 1242 FALSE, /* partial_inplace */ 1243 0, /* src_mask */ 1244 0, /* dst_mask */ 1245 FALSE), /* pcrel_offset */ 1246 | 1237 HOWTO (R_PPC64_TLS, 1238 0, /* rightshift */ 1239 2, /* size (0 = byte, 1 = short, 2 = long) */ 1240 32, /* bitsize */ 1241 FALSE, /* pc_relative */ 1242 0, /* bitpos */ 1243 complain_overflow_dont, /* complain_on_overflow */ 1244 bfd_elf_generic_reloc, /* special_function */ 1245 "R_PPC64_TLS", /* name */ 1246 FALSE, /* partial_inplace */ 1247 0, /* src_mask */ 1248 0, /* dst_mask */ 1249 FALSE), /* pcrel_offset */ 1250 |
1251 HOWTO (R_PPC64_TLSGD, 1252 0, /* rightshift */ 1253 2, /* size (0 = byte, 1 = short, 2 = long) */ 1254 32, /* bitsize */ 1255 FALSE, /* pc_relative */ 1256 0, /* bitpos */ 1257 complain_overflow_dont, /* complain_on_overflow */ 1258 bfd_elf_generic_reloc, /* special_function */ 1259 "R_PPC64_TLSGD", /* name */ 1260 FALSE, /* partial_inplace */ 1261 0, /* src_mask */ 1262 0, /* dst_mask */ 1263 FALSE), /* pcrel_offset */ 1264 1265 HOWTO (R_PPC64_TLSLD, 1266 0, /* rightshift */ 1267 2, /* size (0 = byte, 1 = short, 2 = long) */ 1268 32, /* bitsize */ 1269 FALSE, /* pc_relative */ 1270 0, /* bitpos */ 1271 complain_overflow_dont, /* complain_on_overflow */ 1272 bfd_elf_generic_reloc, /* special_function */ 1273 "R_PPC64_TLSLD", /* name */ 1274 FALSE, /* partial_inplace */ 1275 0, /* src_mask */ 1276 0, /* dst_mask */ 1277 FALSE), /* pcrel_offset */ 1278 |
|
1247 /* Computes the load module index of the load module that contains the 1248 definition of its TLS sym. */ 1249 HOWTO (R_PPC64_DTPMOD64, 1250 0, /* rightshift */ 1251 4, /* size (0 = byte, 1 = short, 2 = long) */ 1252 64, /* bitsize */ 1253 FALSE, /* pc_relative */ 1254 0, /* bitpos */ --- 765 unchanged lines hidden (view full) --- 2020 case BFD_RELOC_PPC64_TOC16_LO_DS: r = R_PPC64_TOC16_LO_DS; 2021 break; 2022 case BFD_RELOC_PPC64_PLTGOT16_DS: r = R_PPC64_PLTGOT16_DS; 2023 break; 2024 case BFD_RELOC_PPC64_PLTGOT16_LO_DS: r = R_PPC64_PLTGOT16_LO_DS; 2025 break; 2026 case BFD_RELOC_PPC_TLS: r = R_PPC64_TLS; 2027 break; | 1279 /* Computes the load module index of the load module that contains the 1280 definition of its TLS sym. */ 1281 HOWTO (R_PPC64_DTPMOD64, 1282 0, /* rightshift */ 1283 4, /* size (0 = byte, 1 = short, 2 = long) */ 1284 64, /* bitsize */ 1285 FALSE, /* pc_relative */ 1286 0, /* bitpos */ --- 765 unchanged lines hidden (view full) --- 2052 case BFD_RELOC_PPC64_TOC16_LO_DS: r = R_PPC64_TOC16_LO_DS; 2053 break; 2054 case BFD_RELOC_PPC64_PLTGOT16_DS: r = R_PPC64_PLTGOT16_DS; 2055 break; 2056 case BFD_RELOC_PPC64_PLTGOT16_LO_DS: r = R_PPC64_PLTGOT16_LO_DS; 2057 break; 2058 case BFD_RELOC_PPC_TLS: r = R_PPC64_TLS; 2059 break; |
2060 case BFD_RELOC_PPC_TLSGD: r = R_PPC64_TLSGD; 2061 break; 2062 case BFD_RELOC_PPC_TLSLD: r = R_PPC64_TLSLD; 2063 break; |
|
2028 case BFD_RELOC_PPC_DTPMOD: r = R_PPC64_DTPMOD64; 2029 break; 2030 case BFD_RELOC_PPC_TPREL16: r = R_PPC64_TPREL16; 2031 break; 2032 case BFD_RELOC_PPC_TPREL16_LO: r = R_PPC64_TPREL16_LO; 2033 break; 2034 case BFD_RELOC_PPC_TPREL16_HI: r = R_PPC64_TPREL16_HI; 2035 break; --- 570 unchanged lines hidden (view full) --- 2606 /* An array with one entry for each opd function descriptor. */ 2607 union 2608 { 2609 /* Points to the function code section for local opd entries. */ 2610 asection **opd_func_sec; 2611 /* After editing .opd, adjust references to opd local syms. */ 2612 long *opd_adjust; 2613 | 2064 case BFD_RELOC_PPC_DTPMOD: r = R_PPC64_DTPMOD64; 2065 break; 2066 case BFD_RELOC_PPC_TPREL16: r = R_PPC64_TPREL16; 2067 break; 2068 case BFD_RELOC_PPC_TPREL16_LO: r = R_PPC64_TPREL16_LO; 2069 break; 2070 case BFD_RELOC_PPC_TPREL16_HI: r = R_PPC64_TPREL16_HI; 2071 break; --- 570 unchanged lines hidden (view full) --- 2642 /* An array with one entry for each opd function descriptor. */ 2643 union 2644 { 2645 /* Points to the function code section for local opd entries. */ 2646 asection **opd_func_sec; 2647 /* After editing .opd, adjust references to opd local syms. */ 2648 long *opd_adjust; 2649 |
2614 /* An array for toc sections, indexed by offset/8. 2615 Specifies the relocation symbol index used at a given toc offset. */ 2616 unsigned *t_symndx; | 2650 /* An array for toc sections, indexed by offset/8. */ 2651 struct _toc_sec_data 2652 { 2653 /* Specifies the relocation symbol index used at a given toc offset. */ 2654 unsigned *symndx; 2655 2656 /* And the relocation addend. */ 2657 bfd_vma *add; 2658 } toc; |
2617 } u; 2618 2619 enum _ppc64_sec_type sec_type:2; 2620 2621 /* Flag set when small branches are detected. Used to 2622 select suitable defaults for the stub group size. */ 2623 unsigned int has_14bit_branch:1; 2624}; --- 526 unchanged lines hidden (view full) --- 3151 struct got_entry *next; 3152 3153 /* The symbol addend that we'll be placing in the GOT. */ 3154 bfd_vma addend; 3155 3156 /* Unlike other ELF targets, we use separate GOT entries for the same 3157 symbol referenced from different input files. This is to support 3158 automatic multiple TOC/GOT sections, where the TOC base can vary | 2659 } u; 2660 2661 enum _ppc64_sec_type sec_type:2; 2662 2663 /* Flag set when small branches are detected. Used to 2664 select suitable defaults for the stub group size. */ 2665 unsigned int has_14bit_branch:1; 2666}; --- 526 unchanged lines hidden (view full) --- 3193 struct got_entry *next; 3194 3195 /* The symbol addend that we'll be placing in the GOT. */ 3196 bfd_vma addend; 3197 3198 /* Unlike other ELF targets, we use separate GOT entries for the same 3199 symbol referenced from different input files. This is to support 3200 automatic multiple TOC/GOT sections, where the TOC base can vary |
3159 from one input file to another. | 3201 from one input file to another. FIXME: After group_sections we 3202 ought to merge entries within the group. |
3160 3161 Point to the BFD owning this GOT entry. */ 3162 bfd *owner; 3163 3164 /* Zero for non-tls entries, or TLS_TLS and one of TLS_GD, TLS_LD, 3165 TLS_TPREL or TLS_DTPREL for tls entries. */ 3166 char tls_type; 3167 --- 14 unchanged lines hidden (view full) --- 3182 3183 union 3184 { 3185 bfd_signed_vma refcount; 3186 bfd_vma offset; 3187 } plt; 3188}; 3189 | 3203 3204 Point to the BFD owning this GOT entry. */ 3205 bfd *owner; 3206 3207 /* Zero for non-tls entries, or TLS_TLS and one of TLS_GD, TLS_LD, 3208 TLS_TPREL or TLS_DTPREL for tls entries. */ 3209 char tls_type; 3210 --- 14 unchanged lines hidden (view full) --- 3225 3226 union 3227 { 3228 bfd_signed_vma refcount; 3229 bfd_vma offset; 3230 } plt; 3231}; 3232 |
3190/* Of those relocs that might be copied as dynamic relocs, this macro | 3233/* Of those relocs that might be copied as dynamic relocs, this function |
3191 selects those that must be copied when linking a shared library, 3192 even when the symbol is local. */ 3193 | 3234 selects those that must be copied when linking a shared library, 3235 even when the symbol is local. */ 3236 |
3194#define MUST_BE_DYN_RELOC(RTYPE) \ 3195 ((RTYPE) != R_PPC64_REL32 \ 3196 && (RTYPE) != R_PPC64_REL64 \ 3197 && (RTYPE) != R_PPC64_REL30) | 3237static int 3238must_be_dyn_reloc (struct bfd_link_info *info, 3239 enum elf_ppc64_reloc_type r_type) 3240{ 3241 switch (r_type) 3242 { 3243 default: 3244 return 1; |
3198 | 3245 |
3246 case R_PPC64_REL32: 3247 case R_PPC64_REL64: 3248 case R_PPC64_REL30: 3249 return 0; 3250 3251 case R_PPC64_TPREL16: 3252 case R_PPC64_TPREL16_LO: 3253 case R_PPC64_TPREL16_HI: 3254 case R_PPC64_TPREL16_HA: 3255 case R_PPC64_TPREL16_DS: 3256 case R_PPC64_TPREL16_LO_DS: 3257 case R_PPC64_TPREL16_HIGHER: 3258 case R_PPC64_TPREL16_HIGHERA: 3259 case R_PPC64_TPREL16_HIGHEST: 3260 case R_PPC64_TPREL16_HIGHESTA: 3261 case R_PPC64_TPREL64: 3262 return !info->executable; 3263 } 3264} 3265 |
|
3199/* If ELIMINATE_COPY_RELOCS is non-zero, the linker will try to avoid 3200 copying dynamic variables from a shared lib into an app's dynbss 3201 section, and instead use a dynamic relocation to point into the 3202 shared lib. With code that gcc generates, it's vital that this be 3203 enabled; In the PowerPC64 ABI, the address of a function is actually 3204 the address of a function descriptor, which resides in the .opd 3205 section. gcc uses the descriptor directly rather than going via the 3206 GOT as some other ABI's do, which means that initialized function --- 22 unchanged lines hidden (view full) --- 3229 . addis %r12,%r2,xxx@toc@ha 3230 . ld %r11,xxx@toc@l(%r12) 3231 . mtctr %r11 3232 . bctr 3233 3234 ppc_stub_plt_call: 3235 Used to call a function in a shared library. If it so happens that 3236 the plt entry referenced crosses a 64k boundary, then an extra | 3266/* If ELIMINATE_COPY_RELOCS is non-zero, the linker will try to avoid 3267 copying dynamic variables from a shared lib into an app's dynbss 3268 section, and instead use a dynamic relocation to point into the 3269 shared lib. With code that gcc generates, it's vital that this be 3270 enabled; In the PowerPC64 ABI, the address of a function is actually 3271 the address of a function descriptor, which resides in the .opd 3272 section. gcc uses the descriptor directly rather than going via the 3273 GOT as some other ABI's do, which means that initialized function --- 22 unchanged lines hidden (view full) --- 3296 . addis %r12,%r2,xxx@toc@ha 3297 . ld %r11,xxx@toc@l(%r12) 3298 . mtctr %r11 3299 . bctr 3300 3301 ppc_stub_plt_call: 3302 Used to call a function in a shared library. If it so happens that 3303 the plt entry referenced crosses a 64k boundary, then an extra |
3237 "addis %r12,%r12,1" will be inserted before the load at xxx+8 or 3238 xxx+16 as appropriate. | 3304 "addi %r12,%r12,xxx@toc@l" will be inserted before the "mtctr". |
3239 . addis %r12,%r2,xxx@toc@ha 3240 . std %r2,40(%r1) 3241 . ld %r11,xxx+0@toc@l(%r12) | 3305 . addis %r12,%r2,xxx@toc@ha 3306 . std %r2,40(%r1) 3307 . ld %r11,xxx+0@toc@l(%r12) |
3242 . ld %r2,xxx+8@toc@l(%r12) | |
3243 . mtctr %r11 | 3308 . mtctr %r11 |
3309 . ld %r2,xxx+8@toc@l(%r12) |
|
3244 . ld %r11,xxx+16@toc@l(%r12) 3245 . bctr 3246 3247 ppc_stub_long_branch and ppc_stub_plt_branch may also have additional 3248 code to adjust the value and save r2 to support multiple toc sections. 3249 A ppc_stub_long_branch with an r2 offset looks like: 3250 . std %r2,40(%r1) 3251 . addis %r2,%r2,off@ha 3252 . addi %r2,%r2,off@l 3253 . b dest 3254 3255 A ppc_stub_plt_branch with an r2 offset looks like: 3256 . std %r2,40(%r1) 3257 . addis %r12,%r2,xxx@toc@ha 3258 . ld %r11,xxx@toc@l(%r12) 3259 . addis %r2,%r2,off@ha 3260 . addi %r2,%r2,off@l 3261 . mtctr %r11 3262 . bctr | 3310 . ld %r11,xxx+16@toc@l(%r12) 3311 . bctr 3312 3313 ppc_stub_long_branch and ppc_stub_plt_branch may also have additional 3314 code to adjust the value and save r2 to support multiple toc sections. 3315 A ppc_stub_long_branch with an r2 offset looks like: 3316 . std %r2,40(%r1) 3317 . addis %r2,%r2,off@ha 3318 . addi %r2,%r2,off@l 3319 . b dest 3320 3321 A ppc_stub_plt_branch with an r2 offset looks like: 3322 . std %r2,40(%r1) 3323 . addis %r12,%r2,xxx@toc@ha 3324 . ld %r11,xxx@toc@l(%r12) 3325 . addis %r2,%r2,off@ha 3326 . addi %r2,%r2,off@l 3327 . mtctr %r11 3328 . bctr |
3329 3330 In cases where the "addis" instruction would add zero, the "addis" is 3331 omitted and following instructions modified slightly in some cases. |
|
3263*/ 3264 3265enum ppc_stub_type { 3266 ppc_stub_none, 3267 ppc_stub_long_branch, 3268 ppc_stub_long_branch_r2off, 3269 ppc_stub_plt_branch, 3270 ppc_stub_plt_branch_r2off, --- 1117 unchanged lines hidden (view full) --- 4388{ 4389 struct ppc_link_hash_table *htab; 4390 Elf_Internal_Shdr *symtab_hdr; 4391 struct elf_link_hash_entry **sym_hashes, **sym_hashes_end; 4392 const Elf_Internal_Rela *rel; 4393 const Elf_Internal_Rela *rel_end; 4394 asection *sreloc; 4395 asection **opd_sym_map; | 3332*/ 3333 3334enum ppc_stub_type { 3335 ppc_stub_none, 3336 ppc_stub_long_branch, 3337 ppc_stub_long_branch_r2off, 3338 ppc_stub_plt_branch, 3339 ppc_stub_plt_branch_r2off, --- 1117 unchanged lines hidden (view full) --- 4457{ 4458 struct ppc_link_hash_table *htab; 4459 Elf_Internal_Shdr *symtab_hdr; 4460 struct elf_link_hash_entry **sym_hashes, **sym_hashes_end; 4461 const Elf_Internal_Rela *rel; 4462 const Elf_Internal_Rela *rel_end; 4463 asection *sreloc; 4464 asection **opd_sym_map; |
4465 struct elf_link_hash_entry *tga, *dottga; |
|
4396 4397 if (info->relocatable) 4398 return TRUE; 4399 4400 /* Don't do anything special with non-loaded, non-alloced sections. 4401 In particular, any relocs in such sections should not affect GOT 4402 and PLT reference counting (ie. we don't allow them to create GOT 4403 or PLT entries), there's no possibility or desire to optimize TLS 4404 relocs, and there's not much point in propagating relocs to shared 4405 libs that the dynamic linker won't relocate. */ 4406 if ((sec->flags & SEC_ALLOC) == 0) 4407 return TRUE; 4408 4409 htab = ppc_hash_table (info); | 4466 4467 if (info->relocatable) 4468 return TRUE; 4469 4470 /* Don't do anything special with non-loaded, non-alloced sections. 4471 In particular, any relocs in such sections should not affect GOT 4472 and PLT reference counting (ie. we don't allow them to create GOT 4473 or PLT entries), there's no possibility or desire to optimize TLS 4474 relocs, and there's not much point in propagating relocs to shared 4475 libs that the dynamic linker won't relocate. */ 4476 if ((sec->flags & SEC_ALLOC) == 0) 4477 return TRUE; 4478 4479 htab = ppc_hash_table (info); |
4480 tga = elf_link_hash_lookup (&htab->elf, "__tls_get_addr", 4481 FALSE, FALSE, TRUE); 4482 dottga = elf_link_hash_lookup (&htab->elf, ".__tls_get_addr", 4483 FALSE, FALSE, TRUE); |
|
4410 symtab_hdr = &elf_tdata (abfd)->symtab_hdr; 4411 4412 sym_hashes = elf_sym_hashes (abfd); 4413 sym_hashes_end = (sym_hashes 4414 + symtab_hdr->sh_size / sizeof (Elf64_External_Sym) 4415 - symtab_hdr->sh_info); 4416 4417 sreloc = NULL; --- 29 unchanged lines hidden (view full) --- 4447 return FALSE; 4448 4449 rel_end = relocs + sec->reloc_count; 4450 for (rel = relocs; rel < rel_end; rel++) 4451 { 4452 unsigned long r_symndx; 4453 struct elf_link_hash_entry *h; 4454 enum elf_ppc64_reloc_type r_type; | 4484 symtab_hdr = &elf_tdata (abfd)->symtab_hdr; 4485 4486 sym_hashes = elf_sym_hashes (abfd); 4487 sym_hashes_end = (sym_hashes 4488 + symtab_hdr->sh_size / sizeof (Elf64_External_Sym) 4489 - symtab_hdr->sh_info); 4490 4491 sreloc = NULL; --- 29 unchanged lines hidden (view full) --- 4521 return FALSE; 4522 4523 rel_end = relocs + sec->reloc_count; 4524 for (rel = relocs; rel < rel_end; rel++) 4525 { 4526 unsigned long r_symndx; 4527 struct elf_link_hash_entry *h; 4528 enum elf_ppc64_reloc_type r_type; |
4455 int tls_type = 0; | 4529 int tls_type; |
4456 struct _ppc64_elf_section_data *ppc64_sec; 4457 4458 r_symndx = ELF64_R_SYM (rel->r_info); 4459 if (r_symndx < symtab_hdr->sh_info) 4460 h = NULL; 4461 else 4462 { 4463 h = sym_hashes[r_symndx - symtab_hdr->sh_info]; 4464 while (h->root.type == bfd_link_hash_indirect 4465 || h->root.type == bfd_link_hash_warning) 4466 h = (struct elf_link_hash_entry *) h->root.u.i.link; 4467 } 4468 | 4530 struct _ppc64_elf_section_data *ppc64_sec; 4531 4532 r_symndx = ELF64_R_SYM (rel->r_info); 4533 if (r_symndx < symtab_hdr->sh_info) 4534 h = NULL; 4535 else 4536 { 4537 h = sym_hashes[r_symndx - symtab_hdr->sh_info]; 4538 while (h->root.type == bfd_link_hash_indirect 4539 || h->root.type == bfd_link_hash_warning) 4540 h = (struct elf_link_hash_entry *) h->root.u.i.link; 4541 } 4542 |
4543 tls_type = 0; |
|
4469 r_type = ELF64_R_TYPE (rel->r_info); | 4544 r_type = ELF64_R_TYPE (rel->r_info); |
4545 if (h != NULL && (h == tga || h == dottga)) 4546 switch (r_type) 4547 { 4548 default: 4549 break; 4550 4551 case R_PPC64_REL24: 4552 case R_PPC64_REL14: 4553 case R_PPC64_REL14_BRTAKEN: 4554 case R_PPC64_REL14_BRNTAKEN: 4555 case R_PPC64_ADDR24: 4556 case R_PPC64_ADDR14: 4557 case R_PPC64_ADDR14_BRTAKEN: 4558 case R_PPC64_ADDR14_BRNTAKEN: 4559 if (rel != relocs 4560 && (ELF64_R_TYPE (rel[-1].r_info) == R_PPC64_TLSGD 4561 || ELF64_R_TYPE (rel[-1].r_info) == R_PPC64_TLSLD)) 4562 /* We have a new-style __tls_get_addr call with a marker 4563 reloc. */ 4564 ; 4565 else 4566 /* Mark this section as having an old-style call. */ 4567 sec->has_tls_get_addr_call = 1; 4568 break; 4569 } 4570 |
|
4470 switch (r_type) 4471 { | 4571 switch (r_type) 4572 { |
4573 case R_PPC64_TLSGD: 4574 case R_PPC64_TLSLD: 4575 /* These special tls relocs tie a call to __tls_get_addr with 4576 its parameter symbol. */ 4577 break; 4578 |
|
4472 case R_PPC64_GOT_TLSLD16: 4473 case R_PPC64_GOT_TLSLD16_LO: 4474 case R_PPC64_GOT_TLSLD16_HI: 4475 case R_PPC64_GOT_TLSLD16_HA: | 4579 case R_PPC64_GOT_TLSLD16: 4580 case R_PPC64_GOT_TLSLD16_LO: 4581 case R_PPC64_GOT_TLSLD16_HI: 4582 case R_PPC64_GOT_TLSLD16_HA: |
4476 ppc64_tlsld_got (abfd)->refcount += 1; | |
4477 tls_type = TLS_TLS | TLS_LD; 4478 goto dogottls; 4479 4480 case R_PPC64_GOT_TLSGD16: 4481 case R_PPC64_GOT_TLSGD16_LO: 4482 case R_PPC64_GOT_TLSGD16_HI: 4483 case R_PPC64_GOT_TLSGD16_HA: 4484 tls_type = TLS_TLS | TLS_GD; 4485 goto dogottls; 4486 4487 case R_PPC64_GOT_TPREL16_DS: 4488 case R_PPC64_GOT_TPREL16_LO_DS: 4489 case R_PPC64_GOT_TPREL16_HI: 4490 case R_PPC64_GOT_TPREL16_HA: | 4583 tls_type = TLS_TLS | TLS_LD; 4584 goto dogottls; 4585 4586 case R_PPC64_GOT_TLSGD16: 4587 case R_PPC64_GOT_TLSGD16_LO: 4588 case R_PPC64_GOT_TLSGD16_HI: 4589 case R_PPC64_GOT_TLSGD16_HA: 4590 tls_type = TLS_TLS | TLS_GD; 4591 goto dogottls; 4592 4593 case R_PPC64_GOT_TPREL16_DS: 4594 case R_PPC64_GOT_TPREL16_LO_DS: 4595 case R_PPC64_GOT_TPREL16_HI: 4596 case R_PPC64_GOT_TPREL16_HA: |
4491 if (info->shared) | 4597 if (!info->executable) |
4492 info->flags |= DF_STATIC_TLS; 4493 tls_type = TLS_TLS | TLS_TPREL; 4494 goto dogottls; 4495 4496 case R_PPC64_GOT_DTPREL16_DS: 4497 case R_PPC64_GOT_DTPREL16_LO_DS: 4498 case R_PPC64_GOT_DTPREL16_HI: 4499 case R_PPC64_GOT_DTPREL16_HA: --- 142 unchanged lines hidden (view full) --- 4642 case R_PPC64_REL24: 4643 if (h != NULL) 4644 { 4645 /* We may need a .plt entry if the function this reloc 4646 refers to is in a shared lib. */ 4647 if (!update_plt_info (abfd, (struct ppc_link_hash_entry *) h, 4648 rel->r_addend)) 4649 return FALSE; | 4598 info->flags |= DF_STATIC_TLS; 4599 tls_type = TLS_TLS | TLS_TPREL; 4600 goto dogottls; 4601 4602 case R_PPC64_GOT_DTPREL16_DS: 4603 case R_PPC64_GOT_DTPREL16_LO_DS: 4604 case R_PPC64_GOT_DTPREL16_HI: 4605 case R_PPC64_GOT_DTPREL16_HA: --- 142 unchanged lines hidden (view full) --- 4748 case R_PPC64_REL24: 4749 if (h != NULL) 4750 { 4751 /* We may need a .plt entry if the function this reloc 4752 refers to is in a shared lib. */ 4753 if (!update_plt_info (abfd, (struct ppc_link_hash_entry *) h, 4754 rel->r_addend)) 4755 return FALSE; |
4650 if (h == &htab->tls_get_addr->elf 4651 || h == &htab->tls_get_addr_fd->elf) | 4756 if (h == tga || h == dottga) |
4652 sec->has_tls_reloc = 1; | 4757 sec->has_tls_reloc = 1; |
4653 else if (htab->tls_get_addr == NULL 4654 && CONST_STRNEQ (h->root.root.string, ".__tls_get_addr") 4655 && (h->root.root.string[15] == 0 4656 || h->root.root.string[15] == '@')) 4657 { 4658 htab->tls_get_addr = (struct ppc_link_hash_entry *) h; 4659 sec->has_tls_reloc = 1; 4660 } 4661 else if (htab->tls_get_addr_fd == NULL 4662 && CONST_STRNEQ (h->root.root.string, "__tls_get_addr") 4663 && (h->root.root.string[14] == 0 4664 || h->root.root.string[14] == '@')) 4665 { 4666 htab->tls_get_addr_fd = (struct ppc_link_hash_entry *) h; 4667 sec->has_tls_reloc = 1; 4668 } | |
4669 } 4670 break; 4671 4672 case R_PPC64_TPREL64: 4673 tls_type = TLS_EXPLICIT | TLS_TLS | TLS_TPREL; | 4758 } 4759 break; 4760 4761 case R_PPC64_TPREL64: 4762 tls_type = TLS_EXPLICIT | TLS_TLS | TLS_TPREL; |
4674 if (info->shared) | 4763 if (!info->executable) |
4675 info->flags |= DF_STATIC_TLS; 4676 goto dotlstoc; 4677 4678 case R_PPC64_DTPMOD64: 4679 if (rel + 1 < rel_end 4680 && rel[1].r_info == ELF64_R_INFO (r_symndx, R_PPC64_DTPREL64) 4681 && rel[1].r_offset == rel->r_offset + 8) 4682 tls_type = TLS_EXPLICIT | TLS_TLS | TLS_GD; --- 21 unchanged lines hidden (view full) --- 4704 else 4705 if (!update_local_sym_info (abfd, symtab_hdr, r_symndx, 4706 rel->r_addend, tls_type)) 4707 return FALSE; 4708 4709 ppc64_sec = ppc64_elf_section_data (sec); 4710 if (ppc64_sec->sec_type != sec_toc) 4711 { | 4764 info->flags |= DF_STATIC_TLS; 4765 goto dotlstoc; 4766 4767 case R_PPC64_DTPMOD64: 4768 if (rel + 1 < rel_end 4769 && rel[1].r_info == ELF64_R_INFO (r_symndx, R_PPC64_DTPREL64) 4770 && rel[1].r_offset == rel->r_offset + 8) 4771 tls_type = TLS_EXPLICIT | TLS_TLS | TLS_GD; --- 21 unchanged lines hidden (view full) --- 4793 else 4794 if (!update_local_sym_info (abfd, symtab_hdr, r_symndx, 4795 rel->r_addend, tls_type)) 4796 return FALSE; 4797 4798 ppc64_sec = ppc64_elf_section_data (sec); 4799 if (ppc64_sec->sec_type != sec_toc) 4800 { |
4801 bfd_size_type amt; 4802 |
|
4712 /* One extra to simplify get_tls_mask. */ | 4803 /* One extra to simplify get_tls_mask. */ |
4713 bfd_size_type amt = sec->size * sizeof (unsigned) / 8 + 1; 4714 ppc64_sec->u.t_symndx = bfd_zalloc (abfd, amt); 4715 if (ppc64_sec->u.t_symndx == NULL) | 4804 amt = sec->size * sizeof (unsigned) / 8 + sizeof (unsigned); 4805 ppc64_sec->u.toc.symndx = bfd_zalloc (abfd, amt); 4806 if (ppc64_sec->u.toc.symndx == NULL) |
4716 return FALSE; | 4807 return FALSE; |
4808 amt = sec->size * sizeof (bfd_vma) / 8; 4809 ppc64_sec->u.toc.add = bfd_zalloc (abfd, amt); 4810 if (ppc64_sec->u.toc.add == NULL) 4811 return FALSE; |
|
4717 BFD_ASSERT (ppc64_sec->sec_type == sec_normal); 4718 ppc64_sec->sec_type = sec_toc; 4719 } 4720 BFD_ASSERT (rel->r_offset % 8 == 0); | 4812 BFD_ASSERT (ppc64_sec->sec_type == sec_normal); 4813 ppc64_sec->sec_type = sec_toc; 4814 } 4815 BFD_ASSERT (rel->r_offset % 8 == 0); |
4721 ppc64_sec->u.t_symndx[rel->r_offset / 8] = r_symndx; | 4816 ppc64_sec->u.toc.symndx[rel->r_offset / 8] = r_symndx; 4817 ppc64_sec->u.toc.add[rel->r_offset / 8] = rel->r_addend; |
4722 4723 /* Mark the second slot of a GD or LD entry. 4724 -1 to indicate GD and -2 to indicate LD. */ 4725 if (tls_type == (TLS_EXPLICIT | TLS_TLS | TLS_GD)) | 4818 4819 /* Mark the second slot of a GD or LD entry. 4820 -1 to indicate GD and -2 to indicate LD. */ 4821 if (tls_type == (TLS_EXPLICIT | TLS_TLS | TLS_GD)) |
4726 ppc64_sec->u.t_symndx[rel->r_offset / 8 + 1] = -1; | 4822 ppc64_sec->u.toc.symndx[rel->r_offset / 8 + 1] = -1; |
4727 else if (tls_type == (TLS_EXPLICIT | TLS_TLS | TLS_LD)) | 4823 else if (tls_type == (TLS_EXPLICIT | TLS_TLS | TLS_LD)) |
4728 ppc64_sec->u.t_symndx[rel->r_offset / 8 + 1] = -2; | 4824 ppc64_sec->u.toc.symndx[rel->r_offset / 8 + 1] = -2; |
4729 goto dodyn; 4730 4731 case R_PPC64_TPREL16: 4732 case R_PPC64_TPREL16_LO: 4733 case R_PPC64_TPREL16_HI: 4734 case R_PPC64_TPREL16_HA: 4735 case R_PPC64_TPREL16_DS: 4736 case R_PPC64_TPREL16_LO_DS: 4737 case R_PPC64_TPREL16_HIGHER: 4738 case R_PPC64_TPREL16_HIGHERA: 4739 case R_PPC64_TPREL16_HIGHEST: 4740 case R_PPC64_TPREL16_HIGHESTA: 4741 if (info->shared) 4742 { | 4825 goto dodyn; 4826 4827 case R_PPC64_TPREL16: 4828 case R_PPC64_TPREL16_LO: 4829 case R_PPC64_TPREL16_HI: 4830 case R_PPC64_TPREL16_HA: 4831 case R_PPC64_TPREL16_DS: 4832 case R_PPC64_TPREL16_LO_DS: 4833 case R_PPC64_TPREL16_HIGHER: 4834 case R_PPC64_TPREL16_HIGHERA: 4835 case R_PPC64_TPREL16_HIGHEST: 4836 case R_PPC64_TPREL16_HIGHESTA: 4837 if (info->shared) 4838 { |
4743 info->flags |= DF_STATIC_TLS; | 4839 if (!info->executable) 4840 info->flags |= DF_STATIC_TLS; |
4744 goto dodyn; 4745 } 4746 break; 4747 4748 case R_PPC64_ADDR64: 4749 if (opd_sym_map != NULL 4750 && rel + 1 < rel_end 4751 && ELF64_R_TYPE ((rel + 1)->r_info) == R_PPC64_TOC) --- 69 unchanged lines hidden (view full) --- 4821 symbol local. 4822 4823 If on the other hand, we are creating an executable, we 4824 may need to keep relocations for symbols satisfied by a 4825 dynamic library if we manage to avoid copy relocs for the 4826 symbol. */ 4827 dodyn: 4828 if ((info->shared | 4841 goto dodyn; 4842 } 4843 break; 4844 4845 case R_PPC64_ADDR64: 4846 if (opd_sym_map != NULL 4847 && rel + 1 < rel_end 4848 && ELF64_R_TYPE ((rel + 1)->r_info) == R_PPC64_TOC) --- 69 unchanged lines hidden (view full) --- 4918 symbol local. 4919 4920 If on the other hand, we are creating an executable, we 4921 may need to keep relocations for symbols satisfied by a 4922 dynamic library if we manage to avoid copy relocs for the 4923 symbol. */ 4924 dodyn: 4925 if ((info->shared |
4829 && (MUST_BE_DYN_RELOC (r_type) | 4926 && (must_be_dyn_reloc (info, r_type) |
4830 || (h != NULL 4831 && (! info->symbolic 4832 || h->root.type == bfd_link_hash_defweak 4833 || !h->def_regular)))) 4834 || (ELIMINATE_COPY_RELOCS 4835 && !info->shared 4836 && h != NULL 4837 && (h->root.type == bfd_link_hash_defweak --- 79 unchanged lines hidden (view full) --- 4917 p->next = *head; 4918 *head = p; 4919 p->sec = sec; 4920 p->count = 0; 4921 p->pc_count = 0; 4922 } 4923 4924 p->count += 1; | 4927 || (h != NULL 4928 && (! info->symbolic 4929 || h->root.type == bfd_link_hash_defweak 4930 || !h->def_regular)))) 4931 || (ELIMINATE_COPY_RELOCS 4932 && !info->shared 4933 && h != NULL 4934 && (h->root.type == bfd_link_hash_defweak --- 79 unchanged lines hidden (view full) --- 5014 p->next = *head; 5015 *head = p; 5016 p->sec = sec; 5017 p->count = 0; 5018 p->pc_count = 0; 5019 } 5020 5021 p->count += 1; |
4925 if (!MUST_BE_DYN_RELOC (r_type)) | 5022 if (!must_be_dyn_reloc (info, r_type)) |
4926 p->pc_count += 1; 4927 } 4928 break; 4929 4930 default: 4931 break; 4932 } 4933 } --- 358 unchanged lines hidden (view full) --- 5292 } 5293 5294 switch (r_type) 5295 { 5296 case R_PPC64_GOT_TLSLD16: 5297 case R_PPC64_GOT_TLSLD16_LO: 5298 case R_PPC64_GOT_TLSLD16_HI: 5299 case R_PPC64_GOT_TLSLD16_HA: | 5023 p->pc_count += 1; 5024 } 5025 break; 5026 5027 default: 5028 break; 5029 } 5030 } --- 358 unchanged lines hidden (view full) --- 5389 } 5390 5391 switch (r_type) 5392 { 5393 case R_PPC64_GOT_TLSLD16: 5394 case R_PPC64_GOT_TLSLD16_LO: 5395 case R_PPC64_GOT_TLSLD16_HI: 5396 case R_PPC64_GOT_TLSLD16_HA: |
5300 ppc64_tlsld_got (abfd)->refcount -= 1; | |
5301 tls_type = TLS_TLS | TLS_LD; 5302 goto dogot; 5303 5304 case R_PPC64_GOT_TLSGD16: 5305 case R_PPC64_GOT_TLSGD16_LO: 5306 case R_PPC64_GOT_TLSGD16_HI: 5307 case R_PPC64_GOT_TLSGD16_HA: 5308 tls_type = TLS_TLS | TLS_GD; --- 328 unchanged lines hidden (view full) --- 5637 && get_opd_info (fh->oh->elf.root.u.def.section) != NULL 5638 && opd_entry_value (fh->oh->elf.root.u.def.section, 5639 fh->oh->elf.root.u.def.value, 5640 &fh->elf.root.u.def.section, 5641 &fh->elf.root.u.def.value) != (bfd_vma) -1) 5642 { 5643 fh->elf.root.type = fh->oh->elf.root.type; 5644 fh->elf.forced_local = 1; | 5397 tls_type = TLS_TLS | TLS_LD; 5398 goto dogot; 5399 5400 case R_PPC64_GOT_TLSGD16: 5401 case R_PPC64_GOT_TLSGD16_LO: 5402 case R_PPC64_GOT_TLSGD16_HI: 5403 case R_PPC64_GOT_TLSGD16_HA: 5404 tls_type = TLS_TLS | TLS_GD; --- 328 unchanged lines hidden (view full) --- 5733 && get_opd_info (fh->oh->elf.root.u.def.section) != NULL 5734 && opd_entry_value (fh->oh->elf.root.u.def.section, 5735 fh->oh->elf.root.u.def.value, 5736 &fh->elf.root.u.def.section, 5737 &fh->elf.root.u.def.value) != (bfd_vma) -1) 5738 { 5739 fh->elf.root.type = fh->oh->elf.root.type; 5740 fh->elf.forced_local = 1; |
5741 fh->elf.def_regular = fh->oh->elf.def_regular; 5742 fh->elf.def_dynamic = fh->oh->elf.def_dynamic; |
|
5645 } 5646 5647 /* If this is a function code symbol, transfer dynamic linking 5648 information to the function descriptor symbol. */ 5649 if (!fh->is_func) 5650 return TRUE; 5651 5652 for (ent = fh->elf.plt.plist; ent != NULL; ent = ent->next) --- 427 unchanged lines hidden (view full) --- 6080 return TRUE; 6081} 6082 6083/* Returns TLS_MASKP for the given REL symbol. Function return is 0 on 6084 error, 2 on a toc GD type suitable for optimization, 3 on a toc LD 6085 type suitable for optimization, and 1 otherwise. */ 6086 6087static int | 5743 } 5744 5745 /* If this is a function code symbol, transfer dynamic linking 5746 information to the function descriptor symbol. */ 5747 if (!fh->is_func) 5748 return TRUE; 5749 5750 for (ent = fh->elf.plt.plist; ent != NULL; ent = ent->next) --- 427 unchanged lines hidden (view full) --- 6178 return TRUE; 6179} 6180 6181/* Returns TLS_MASKP for the given REL symbol. Function return is 0 on 6182 error, 2 on a toc GD type suitable for optimization, 3 on a toc LD 6183 type suitable for optimization, and 1 otherwise. */ 6184 6185static int |
6088get_tls_mask (char **tls_maskp, unsigned long *toc_symndx, | 6186get_tls_mask (char **tls_maskp, 6187 unsigned long *toc_symndx, 6188 bfd_vma *toc_addend, |
6089 Elf_Internal_Sym **locsymsp, | 6189 Elf_Internal_Sym **locsymsp, |
6090 const Elf_Internal_Rela *rel, bfd *ibfd) | 6190 const Elf_Internal_Rela *rel, 6191 bfd *ibfd) |
6091{ 6092 unsigned long r_symndx; 6093 int next_r; 6094 struct elf_link_hash_entry *h; 6095 Elf_Internal_Sym *sym; 6096 asection *sec; 6097 bfd_vma off; 6098 --- 11 unchanged lines hidden (view full) --- 6110 { 6111 BFD_ASSERT (h->root.type == bfd_link_hash_defined); 6112 off = h->root.u.def.value; 6113 } 6114 else 6115 off = sym->st_value; 6116 off += rel->r_addend; 6117 BFD_ASSERT (off % 8 == 0); | 6192{ 6193 unsigned long r_symndx; 6194 int next_r; 6195 struct elf_link_hash_entry *h; 6196 Elf_Internal_Sym *sym; 6197 asection *sec; 6198 bfd_vma off; 6199 --- 11 unchanged lines hidden (view full) --- 6211 { 6212 BFD_ASSERT (h->root.type == bfd_link_hash_defined); 6213 off = h->root.u.def.value; 6214 } 6215 else 6216 off = sym->st_value; 6217 off += rel->r_addend; 6218 BFD_ASSERT (off % 8 == 0); |
6118 r_symndx = ppc64_elf_section_data (sec)->u.t_symndx[off / 8]; 6119 next_r = ppc64_elf_section_data (sec)->u.t_symndx[off / 8 + 1]; 6120 if (!get_sym_h (&h, &sym, &sec, tls_maskp, locsymsp, r_symndx, ibfd)) 6121 return 0; | 6219 r_symndx = ppc64_elf_section_data (sec)->u.toc.symndx[off / 8]; 6220 next_r = ppc64_elf_section_data (sec)->u.toc.symndx[off / 8 + 1]; |
6122 if (toc_symndx != NULL) 6123 *toc_symndx = r_symndx; | 6221 if (toc_symndx != NULL) 6222 *toc_symndx = r_symndx; |
6223 if (toc_addend != NULL) 6224 *toc_addend = ppc64_elf_section_data (sec)->u.toc.add[off / 8]; 6225 if (!get_sym_h (&h, &sym, &sec, tls_maskp, locsymsp, r_symndx, ibfd)) 6226 return 0; |
|
6124 if ((h == NULL 6125 || ((h->root.type == bfd_link_hash_defined 6126 || h->root.type == bfd_link_hash_defweak) 6127 && !h->def_dynamic)) 6128 && (next_r == -1 || next_r == -2)) 6129 return 1 - next_r; 6130 return 1; 6131} --- 123 unchanged lines hidden (view full) --- 6255 bfd *ibfd = sec->owner; 6256 6257 r_symndx = ELF64_R_SYM (r_info); 6258 if (!get_sym_h (&h, &sym, &sym_sec, NULL, local_syms, r_symndx, ibfd)) 6259 return FALSE; 6260 } 6261 6262 if ((info->shared | 6227 if ((h == NULL 6228 || ((h->root.type == bfd_link_hash_defined 6229 || h->root.type == bfd_link_hash_defweak) 6230 && !h->def_dynamic)) 6231 && (next_r == -1 || next_r == -2)) 6232 return 1 - next_r; 6233 return 1; 6234} --- 123 unchanged lines hidden (view full) --- 6358 bfd *ibfd = sec->owner; 6359 6360 r_symndx = ELF64_R_SYM (r_info); 6361 if (!get_sym_h (&h, &sym, &sym_sec, NULL, local_syms, r_symndx, ibfd)) 6362 return FALSE; 6363 } 6364 6365 if ((info->shared |
6263 && (MUST_BE_DYN_RELOC (r_type) | 6366 && (must_be_dyn_reloc (info, r_type) |
6264 || (h != NULL 6265 && (!info->symbolic 6266 || h->root.type == bfd_link_hash_defweak 6267 || !h->def_regular)))) 6268 || (ELIMINATE_COPY_RELOCS 6269 && !info->shared 6270 && h != NULL 6271 && (h->root.type == bfd_link_hash_defweak --- 23 unchanged lines hidden (view full) --- 6295 if (*pp == NULL) 6296 return TRUE; 6297 } 6298 6299 while ((p = *pp) != NULL) 6300 { 6301 if (p->sec == sec) 6302 { | 6367 || (h != NULL 6368 && (!info->symbolic 6369 || h->root.type == bfd_link_hash_defweak 6370 || !h->def_regular)))) 6371 || (ELIMINATE_COPY_RELOCS 6372 && !info->shared 6373 && h != NULL 6374 && (h->root.type == bfd_link_hash_defweak --- 23 unchanged lines hidden (view full) --- 6398 if (*pp == NULL) 6399 return TRUE; 6400 } 6401 6402 while ((p = *pp) != NULL) 6403 { 6404 if (p->sec == sec) 6405 { |
6303 if (!MUST_BE_DYN_RELOC (r_type)) | 6406 if (!must_be_dyn_reloc (info, r_type)) |
6304 p->pc_count -= 1; 6305 p->count -= 1; 6306 if (p->count == 0) 6307 *pp = p->next; 6308 return TRUE; 6309 } 6310 pp = &p->next; 6311 } --- 420 unchanged lines hidden (view full) --- 6732/* Set htab->tls_get_addr and call the generic ELF tls_setup function. */ 6733 6734asection * 6735ppc64_elf_tls_setup (bfd *obfd, struct bfd_link_info *info) 6736{ 6737 struct ppc_link_hash_table *htab; 6738 6739 htab = ppc_hash_table (info); | 6407 p->pc_count -= 1; 6408 p->count -= 1; 6409 if (p->count == 0) 6410 *pp = p->next; 6411 return TRUE; 6412 } 6413 pp = &p->next; 6414 } --- 420 unchanged lines hidden (view full) --- 6835/* Set htab->tls_get_addr and call the generic ELF tls_setup function. */ 6836 6837asection * 6838ppc64_elf_tls_setup (bfd *obfd, struct bfd_link_info *info) 6839{ 6840 struct ppc_link_hash_table *htab; 6841 6842 htab = ppc_hash_table (info); |
6740 if (htab->tls_get_addr != NULL) 6741 { 6742 struct ppc_link_hash_entry *h = htab->tls_get_addr; | 6843 htab->tls_get_addr = ((struct ppc_link_hash_entry *) 6844 elf_link_hash_lookup (&htab->elf, ".__tls_get_addr", 6845 FALSE, FALSE, TRUE)); 6846 htab->tls_get_addr_fd = ((struct ppc_link_hash_entry *) 6847 elf_link_hash_lookup (&htab->elf, "__tls_get_addr", 6848 FALSE, FALSE, TRUE)); 6849 return _bfd_elf_tls_setup (obfd, info); 6850} |
6743 | 6851 |
6744 while (h->elf.root.type == bfd_link_hash_indirect 6745 || h->elf.root.type == bfd_link_hash_warning) 6746 h = (struct ppc_link_hash_entry *) h->elf.root.u.i.link; | 6852/* Return TRUE iff REL is a branch reloc with a global symbol matching 6853 HASH1 or HASH2. */ |
6747 | 6854 |
6748 htab->tls_get_addr = h; | 6855static bfd_boolean 6856branch_reloc_hash_match (const bfd *ibfd, 6857 const Elf_Internal_Rela *rel, 6858 const struct ppc_link_hash_entry *hash1, 6859 const struct ppc_link_hash_entry *hash2) 6860{ 6861 Elf_Internal_Shdr *symtab_hdr = &elf_tdata (ibfd)->symtab_hdr; 6862 enum elf_ppc64_reloc_type r_type = ELF64_R_TYPE (rel->r_info); 6863 unsigned int r_symndx = ELF64_R_SYM (rel->r_info); |
6749 | 6864 |
6750 if (htab->tls_get_addr_fd == NULL 6751 && h->oh != NULL 6752 && h->oh->is_func_descriptor 6753 && (h->oh->elf.root.type == bfd_link_hash_defined 6754 || h->oh->elf.root.type == bfd_link_hash_defweak)) 6755 htab->tls_get_addr_fd = h->oh; 6756 } 6757 6758 if (htab->tls_get_addr_fd != NULL) | 6865 if (r_symndx >= symtab_hdr->sh_info 6866 && (r_type == R_PPC64_REL24 6867 || r_type == R_PPC64_REL14 6868 || r_type == R_PPC64_REL14_BRTAKEN 6869 || r_type == R_PPC64_REL14_BRNTAKEN 6870 || r_type == R_PPC64_ADDR24 6871 || r_type == R_PPC64_ADDR14 6872 || r_type == R_PPC64_ADDR14_BRTAKEN 6873 || r_type == R_PPC64_ADDR14_BRNTAKEN)) |
6759 { | 6874 { |
6760 struct ppc_link_hash_entry *h = htab->tls_get_addr_fd; | 6875 struct elf_link_hash_entry **sym_hashes = elf_sym_hashes (ibfd); 6876 struct elf_link_hash_entry *h; |
6761 | 6877 |
6762 while (h->elf.root.type == bfd_link_hash_indirect 6763 || h->elf.root.type == bfd_link_hash_warning) 6764 h = (struct ppc_link_hash_entry *) h->elf.root.u.i.link; 6765 6766 htab->tls_get_addr_fd = h; | 6878 h = sym_hashes[r_symndx - symtab_hdr->sh_info]; 6879 while (h->root.type == bfd_link_hash_indirect 6880 || h->root.type == bfd_link_hash_warning) 6881 h = (struct elf_link_hash_entry *) h->root.u.i.link; 6882 if (h == &hash1->elf || h == &hash2->elf) 6883 return TRUE; |
6767 } | 6884 } |
6768 6769 return _bfd_elf_tls_setup (obfd, info); | 6885 return FALSE; |
6770} 6771 6772/* Run through all the TLS relocs looking for optimization 6773 opportunities. The linker has been hacked (see ppc64elf.em) to do 6774 a preliminary section layout so that we know the TLS segment 6775 offsets. We can't optimize earlier because some optimizations need 6776 to know the tp offset, and we need to optimize before allocating 6777 dynamic relocations. */ 6778 6779bfd_boolean 6780ppc64_elf_tls_optimize (bfd *obfd ATTRIBUTE_UNUSED, struct bfd_link_info *info) 6781{ 6782 bfd *ibfd; 6783 asection *sec; 6784 struct ppc_link_hash_table *htab; | 6886} 6887 6888/* Run through all the TLS relocs looking for optimization 6889 opportunities. The linker has been hacked (see ppc64elf.em) to do 6890 a preliminary section layout so that we know the TLS segment 6891 offsets. We can't optimize earlier because some optimizations need 6892 to know the tp offset, and we need to optimize before allocating 6893 dynamic relocations. */ 6894 6895bfd_boolean 6896ppc64_elf_tls_optimize (bfd *obfd ATTRIBUTE_UNUSED, struct bfd_link_info *info) 6897{ 6898 bfd *ibfd; 6899 asection *sec; 6900 struct ppc_link_hash_table *htab; |
6901 int pass; |
|
6785 | 6902 |
6786 if (info->relocatable || info->shared) | 6903 if (info->relocatable || !info->executable) |
6787 return TRUE; 6788 6789 htab = ppc_hash_table (info); 6790 for (ibfd = info->input_bfds; ibfd != NULL; ibfd = ibfd->link_next) 6791 { 6792 Elf_Internal_Sym *locsyms = NULL; 6793 asection *toc = bfd_get_section_by_name (ibfd, ".toc"); 6794 unsigned char *toc_ref = NULL; 6795 | 6904 return TRUE; 6905 6906 htab = ppc_hash_table (info); 6907 for (ibfd = info->input_bfds; ibfd != NULL; ibfd = ibfd->link_next) 6908 { 6909 Elf_Internal_Sym *locsyms = NULL; 6910 asection *toc = bfd_get_section_by_name (ibfd, ".toc"); 6911 unsigned char *toc_ref = NULL; 6912 |
6796 /* Look at all the sections for this file, with TOC last. */ 6797 for (sec = (ibfd->sections == toc && toc && toc->next ? toc->next 6798 : ibfd->sections); 6799 sec != NULL; 6800 sec = (sec == toc ? NULL 6801 : sec->next == NULL ? toc 6802 : sec->next == toc && toc->next ? toc->next 6803 : sec->next)) 6804 if (sec->has_tls_reloc && !bfd_is_abs_section (sec->output_section)) 6805 { 6806 Elf_Internal_Rela *relstart, *rel, *relend; 6807 int expecting_tls_get_addr; 6808 long toc_ref_index = 0; | 6913 /* Look at all the sections for this file. Make two passes over 6914 the relocs. On the first pass, mark toc entries involved 6915 with tls relocs, and check that tls relocs involved in 6916 setting up a tls_get_addr call are indeed followed by such a 6917 call. If they are not, exclude them from the optimizations 6918 done on the second pass. */ 6919 for (pass = 0; pass < 2; ++pass) 6920 for (sec = ibfd->sections; sec != NULL; sec = sec->next) 6921 if (sec->has_tls_reloc && !bfd_is_abs_section (sec->output_section)) 6922 { 6923 Elf_Internal_Rela *relstart, *rel, *relend; |
6809 | 6924 |
6810 /* Read the relocations. */ 6811 relstart = _bfd_elf_link_read_relocs (ibfd, sec, NULL, NULL, 6812 info->keep_memory); 6813 if (relstart == NULL) 6814 return FALSE; | 6925 /* Read the relocations. */ 6926 relstart = _bfd_elf_link_read_relocs (ibfd, sec, NULL, NULL, 6927 info->keep_memory); 6928 if (relstart == NULL) 6929 return FALSE; |
6815 | 6930 |
6816 expecting_tls_get_addr = 0; 6817 relend = relstart + sec->reloc_count; 6818 for (rel = relstart; rel < relend; rel++) 6819 { 6820 enum elf_ppc64_reloc_type r_type; 6821 unsigned long r_symndx; 6822 struct elf_link_hash_entry *h; 6823 Elf_Internal_Sym *sym; 6824 asection *sym_sec; 6825 char *tls_mask; 6826 char tls_set, tls_clear, tls_type = 0; 6827 bfd_vma value; 6828 bfd_boolean ok_tprel, is_local; | 6931 relend = relstart + sec->reloc_count; 6932 for (rel = relstart; rel < relend; rel++) 6933 { 6934 enum elf_ppc64_reloc_type r_type; 6935 unsigned long r_symndx; 6936 struct elf_link_hash_entry *h; 6937 Elf_Internal_Sym *sym; 6938 asection *sym_sec; 6939 char *tls_mask; 6940 char tls_set, tls_clear, tls_type = 0; 6941 bfd_vma value; 6942 bfd_boolean ok_tprel, is_local; 6943 long toc_ref_index = 0; 6944 int expecting_tls_get_addr = 0; |
6829 | 6945 |
6830 r_symndx = ELF64_R_SYM (rel->r_info); 6831 if (!get_sym_h (&h, &sym, &sym_sec, &tls_mask, &locsyms, 6832 r_symndx, ibfd)) 6833 { 6834 err_free_rel: 6835 if (elf_section_data (sec)->relocs != relstart) 6836 free (relstart); 6837 if (toc_ref != NULL) 6838 free (toc_ref); 6839 if (locsyms != NULL 6840 && (elf_tdata (ibfd)->symtab_hdr.contents 6841 != (unsigned char *) locsyms)) 6842 free (locsyms); 6843 return FALSE; 6844 } | 6946 r_symndx = ELF64_R_SYM (rel->r_info); 6947 if (!get_sym_h (&h, &sym, &sym_sec, &tls_mask, &locsyms, 6948 r_symndx, ibfd)) 6949 { 6950 err_free_rel: 6951 if (elf_section_data (sec)->relocs != relstart) 6952 free (relstart); 6953 if (toc_ref != NULL) 6954 free (toc_ref); 6955 if (locsyms != NULL 6956 && (elf_tdata (ibfd)->symtab_hdr.contents 6957 != (unsigned char *) locsyms)) 6958 free (locsyms); 6959 return FALSE; 6960 } |
6845 | 6961 |
6846 if (h != NULL) 6847 { 6848 if (h->root.type != bfd_link_hash_defined 6849 && h->root.type != bfd_link_hash_defweak) 6850 continue; 6851 value = h->root.u.def.value; 6852 } 6853 else 6854 /* Symbols referenced by TLS relocs must be of type 6855 STT_TLS. So no need for .opd local sym adjust. */ 6856 value = sym->st_value; | 6962 if (h != NULL) 6963 { 6964 if (h->root.type != bfd_link_hash_defined 6965 && h->root.type != bfd_link_hash_defweak) 6966 continue; 6967 value = h->root.u.def.value; 6968 } 6969 else 6970 /* Symbols referenced by TLS relocs must be of type 6971 STT_TLS. So no need for .opd local sym adjust. */ 6972 value = sym->st_value; |
6857 | 6973 |
6858 ok_tprel = FALSE; 6859 is_local = FALSE; 6860 if (h == NULL 6861 || !h->def_dynamic) 6862 { 6863 is_local = TRUE; 6864 value += sym_sec->output_offset; 6865 value += sym_sec->output_section->vma; 6866 value -= htab->elf.tls_sec->vma; 6867 ok_tprel = (value + TP_OFFSET + ((bfd_vma) 1 << 31) 6868 < (bfd_vma) 1 << 32); 6869 } | 6974 ok_tprel = FALSE; 6975 is_local = FALSE; 6976 if (h == NULL 6977 || !h->def_dynamic) 6978 { 6979 is_local = TRUE; 6980 value += sym_sec->output_offset; 6981 value += sym_sec->output_section->vma; 6982 value -= htab->elf.tls_sec->vma; 6983 ok_tprel = (value + TP_OFFSET + ((bfd_vma) 1 << 31) 6984 < (bfd_vma) 1 << 32); 6985 } |
6870 | 6986 |
6871 r_type = ELF64_R_TYPE (rel->r_info); 6872 switch (r_type) 6873 { 6874 case R_PPC64_GOT_TLSLD16: 6875 case R_PPC64_GOT_TLSLD16_LO: 6876 case R_PPC64_GOT_TLSLD16_HI: 6877 case R_PPC64_GOT_TLSLD16_HA: 6878 /* These relocs should never be against a symbol 6879 defined in a shared lib. Leave them alone if 6880 that turns out to be the case. */ 6881 ppc64_tlsld_got (ibfd)->refcount -= 1; 6882 if (!is_local) 6883 continue; | 6987 r_type = ELF64_R_TYPE (rel->r_info); 6988 switch (r_type) 6989 { 6990 case R_PPC64_GOT_TLSLD16: 6991 case R_PPC64_GOT_TLSLD16_LO: 6992 expecting_tls_get_addr = 1; 6993 /* Fall thru */ |
6884 | 6994 |
6885 /* LD -> LE */ 6886 tls_set = 0; 6887 tls_clear = TLS_LD; 6888 tls_type = TLS_TLS | TLS_LD; 6889 expecting_tls_get_addr = 1; 6890 break; | 6995 case R_PPC64_GOT_TLSLD16_HI: 6996 case R_PPC64_GOT_TLSLD16_HA: 6997 /* These relocs should never be against a symbol 6998 defined in a shared lib. Leave them alone if 6999 that turns out to be the case. */ 7000 if (!is_local) 7001 continue; |
6891 | 7002 |
6892 case R_PPC64_GOT_TLSGD16: 6893 case R_PPC64_GOT_TLSGD16_LO: 6894 case R_PPC64_GOT_TLSGD16_HI: 6895 case R_PPC64_GOT_TLSGD16_HA: 6896 if (ok_tprel) 6897 /* GD -> LE */ | 7003 /* LD -> LE */ |
6898 tls_set = 0; | 7004 tls_set = 0; |
6899 else 6900 /* GD -> IE */ 6901 tls_set = TLS_TLS | TLS_TPRELGD; 6902 tls_clear = TLS_GD; 6903 tls_type = TLS_TLS | TLS_GD; 6904 expecting_tls_get_addr = 1; 6905 break; | 7005 tls_clear = TLS_LD; 7006 tls_type = TLS_TLS | TLS_LD; 7007 break; |
6906 | 7008 |
6907 case R_PPC64_GOT_TPREL16_DS: 6908 case R_PPC64_GOT_TPREL16_LO_DS: 6909 case R_PPC64_GOT_TPREL16_HI: 6910 case R_PPC64_GOT_TPREL16_HA: 6911 expecting_tls_get_addr = 0; 6912 if (ok_tprel) 6913 { 6914 /* IE -> LE */ | 7009 case R_PPC64_GOT_TLSGD16: 7010 case R_PPC64_GOT_TLSGD16_LO: 7011 expecting_tls_get_addr = 1; 7012 /* Fall thru */ 7013 7014 case R_PPC64_GOT_TLSGD16_HI: 7015 case R_PPC64_GOT_TLSGD16_HA: 7016 if (ok_tprel) 7017 /* GD -> LE */ |
6915 tls_set = 0; | 7018 tls_set = 0; |
6916 tls_clear = TLS_TPREL; 6917 tls_type = TLS_TLS | TLS_TPREL; 6918 break; 6919 } 6920 else | 7019 else 7020 /* GD -> IE */ 7021 tls_set = TLS_TLS | TLS_TPRELGD; 7022 tls_clear = TLS_GD; 7023 tls_type = TLS_TLS | TLS_GD; 7024 break; 7025 7026 case R_PPC64_GOT_TPREL16_DS: 7027 case R_PPC64_GOT_TPREL16_LO_DS: 7028 case R_PPC64_GOT_TPREL16_HI: 7029 case R_PPC64_GOT_TPREL16_HA: 7030 if (ok_tprel) 7031 { 7032 /* IE -> LE */ 7033 tls_set = 0; 7034 tls_clear = TLS_TPREL; 7035 tls_type = TLS_TLS | TLS_TPREL; 7036 break; 7037 } |
6921 continue; 6922 | 7038 continue; 7039 |
6923 case R_PPC64_REL14: 6924 case R_PPC64_REL14_BRTAKEN: 6925 case R_PPC64_REL14_BRNTAKEN: 6926 case R_PPC64_REL24: 6927 if (h != NULL 6928 && (h == &htab->tls_get_addr->elf 6929 || h == &htab->tls_get_addr_fd->elf)) 6930 { 6931 if (!expecting_tls_get_addr 6932 && rel != relstart 6933 && ((ELF64_R_TYPE (rel[-1].r_info) 6934 == R_PPC64_TOC16) 6935 || (ELF64_R_TYPE (rel[-1].r_info) 6936 == R_PPC64_TOC16_LO))) 6937 { 6938 /* Check for toc tls entries. */ 6939 char *toc_tls; 6940 int retval; | 7040 case R_PPC64_TOC16: 7041 case R_PPC64_TOC16_LO: 7042 case R_PPC64_TLS: 7043 case R_PPC64_TLSGD: 7044 case R_PPC64_TLSLD: 7045 if (sym_sec == NULL || sym_sec != toc) 7046 continue; |
6941 | 7047 |
6942 retval = get_tls_mask (&toc_tls, NULL, &locsyms, 6943 rel - 1, ibfd); 6944 if (retval == 0) 6945 goto err_free_rel; 6946 if (retval > 1 && toc_tls != NULL) 6947 { 6948 expecting_tls_get_addr = 1; 6949 if (toc_ref != NULL) 6950 toc_ref[toc_ref_index] = 1; 6951 } 6952 } | 7048 /* Mark this toc entry as referenced by a TLS 7049 code sequence. We can do that now in the 7050 case of R_PPC64_TLS, and after checking for 7051 tls_get_addr for the TOC16 relocs. */ 7052 if (toc_ref == NULL) 7053 { 7054 toc_ref = bfd_zmalloc (toc->size / 8); 7055 if (toc_ref == NULL) 7056 goto err_free_rel; 7057 } 7058 if (h != NULL) 7059 value = h->root.u.def.value; 7060 else 7061 value = sym->st_value; 7062 value += rel->r_addend; 7063 BFD_ASSERT (value < toc->size && value % 8 == 0); 7064 toc_ref_index = value / 8; 7065 if (r_type == R_PPC64_TLS 7066 || r_type == R_PPC64_TLSGD 7067 || r_type == R_PPC64_TLSLD) 7068 { 7069 toc_ref[toc_ref_index] = 1; 7070 continue; 7071 } |
6953 | 7072 |
6954 if (expecting_tls_get_addr) 6955 { 6956 struct plt_entry *ent; 6957 for (ent = h->plt.plist; ent; ent = ent->next) 6958 if (ent->addend == 0) 6959 { 6960 if (ent->plt.refcount > 0) 6961 ent->plt.refcount -= 1; 6962 break; 6963 } 6964 } 6965 } 6966 expecting_tls_get_addr = 0; 6967 continue; | 7073 if (pass != 0 && toc_ref[toc_ref_index] == 0) 7074 continue; |
6968 | 7075 |
6969 case R_PPC64_TOC16: 6970 case R_PPC64_TOC16_LO: 6971 case R_PPC64_TLS: 6972 expecting_tls_get_addr = 0; 6973 if (sym_sec == toc && toc != NULL) 6974 { 6975 /* Mark this toc entry as referenced by a TLS 6976 code sequence. We can do that now in the 6977 case of R_PPC64_TLS, and after checking for 6978 tls_get_addr for the TOC16 relocs. */ 6979 if (toc_ref == NULL) 6980 { 6981 toc_ref = bfd_zmalloc (toc->size / 8); 6982 if (toc_ref == NULL) 6983 goto err_free_rel; 6984 } 6985 if (h != NULL) 6986 value = h->root.u.def.value; 6987 else 6988 value = sym->st_value; 6989 value += rel->r_addend; 6990 BFD_ASSERT (value < toc->size && value % 8 == 0); 6991 toc_ref_index = value / 8; 6992 if (r_type == R_PPC64_TLS) 6993 toc_ref[toc_ref_index] = 1; 6994 } 6995 continue; | 7076 tls_set = 0; 7077 tls_clear = 0; 7078 expecting_tls_get_addr = 2; 7079 break; |
6996 | 7080 |
6997 case R_PPC64_TPREL64: 6998 expecting_tls_get_addr = 0; 6999 if (sec != toc 7000 || toc_ref == NULL 7001 || !toc_ref[rel->r_offset / 8]) | 7081 case R_PPC64_TPREL64: 7082 if (pass == 0 7083 || sec != toc 7084 || toc_ref == NULL 7085 || !toc_ref[rel->r_offset / 8]) 7086 continue; 7087 if (ok_tprel) 7088 { 7089 /* IE -> LE */ 7090 tls_set = TLS_EXPLICIT; 7091 tls_clear = TLS_TPREL; 7092 break; 7093 } |
7002 continue; | 7094 continue; |
7003 if (ok_tprel) 7004 { 7005 /* IE -> LE */ 7006 tls_set = TLS_EXPLICIT; 7007 tls_clear = TLS_TPREL; 7008 break; 7009 } 7010 else 7011 continue; | |
7012 | 7095 |
7013 case R_PPC64_DTPMOD64: 7014 expecting_tls_get_addr = 0; 7015 if (sec != toc 7016 || toc_ref == NULL 7017 || !toc_ref[rel->r_offset / 8]) | 7096 case R_PPC64_DTPMOD64: 7097 if (pass == 0 7098 || sec != toc 7099 || toc_ref == NULL 7100 || !toc_ref[rel->r_offset / 8]) 7101 continue; 7102 if (rel + 1 < relend 7103 && (rel[1].r_info 7104 == ELF64_R_INFO (r_symndx, R_PPC64_DTPREL64)) 7105 && rel[1].r_offset == rel->r_offset + 8) 7106 { 7107 if (ok_tprel) 7108 /* GD -> LE */ 7109 tls_set = TLS_EXPLICIT | TLS_GD; 7110 else 7111 /* GD -> IE */ 7112 tls_set = TLS_EXPLICIT | TLS_GD | TLS_TPRELGD; 7113 tls_clear = TLS_GD; 7114 } 7115 else 7116 { 7117 if (!is_local) 7118 continue; 7119 7120 /* LD -> LE */ 7121 tls_set = TLS_EXPLICIT; 7122 tls_clear = TLS_LD; 7123 } 7124 break; 7125 7126 default: |
7018 continue; | 7127 continue; |
7019 if (rel + 1 < relend 7020 && (rel[1].r_info 7021 == ELF64_R_INFO (r_symndx, R_PPC64_DTPREL64)) 7022 && rel[1].r_offset == rel->r_offset + 8) 7023 { 7024 if (ok_tprel) 7025 /* GD -> LE */ 7026 tls_set = TLS_EXPLICIT | TLS_GD; 7027 else 7028 /* GD -> IE */ 7029 tls_set = TLS_EXPLICIT | TLS_GD | TLS_TPRELGD; 7030 tls_clear = TLS_GD; 7031 } 7032 else 7033 { 7034 if (!is_local) | 7128 } 7129 7130 if (pass == 0) 7131 { 7132 if (!expecting_tls_get_addr 7133 || !sec->has_tls_get_addr_call) 7134 continue; 7135 7136 if (rel + 1 < relend 7137 && branch_reloc_hash_match (ibfd, rel + 1, 7138 htab->tls_get_addr, 7139 htab->tls_get_addr_fd)) 7140 { 7141 if (expecting_tls_get_addr == 2) 7142 { 7143 /* Check for toc tls entries. */ 7144 char *toc_tls; 7145 int retval; 7146 7147 retval = get_tls_mask (&toc_tls, NULL, NULL, 7148 &locsyms, 7149 rel, ibfd); 7150 if (retval == 0) 7151 goto err_free_rel; 7152 if (retval > 1 && toc_tls != NULL) 7153 toc_ref[toc_ref_index] = 1; 7154 } |
7035 continue; | 7155 continue; |
7156 } |
|
7036 | 7157 |
7037 /* LD -> LE */ 7038 tls_set = TLS_EXPLICIT; 7039 tls_clear = TLS_LD; 7040 } 7041 break; | 7158 if (expecting_tls_get_addr != 1) 7159 continue; |
7042 | 7160 |
7043 default: 7044 expecting_tls_get_addr = 0; | 7161 /* Uh oh, we didn't find the expected call. We 7162 could just mark this symbol to exclude it 7163 from tls optimization but it's safer to skip 7164 the entire section. */ 7165 sec->has_tls_reloc = 0; 7166 break; 7167 } 7168 7169 if (expecting_tls_get_addr) 7170 { 7171 struct plt_entry *ent; 7172 for (ent = htab->tls_get_addr->elf.plt.plist; 7173 ent != NULL; 7174 ent = ent->next) 7175 if (ent->addend == 0) 7176 { 7177 if (ent->plt.refcount > 0) 7178 { 7179 ent->plt.refcount -= 1; 7180 expecting_tls_get_addr = 0; 7181 } 7182 break; 7183 } 7184 } 7185 7186 if (expecting_tls_get_addr) 7187 { 7188 struct plt_entry *ent; 7189 for (ent = htab->tls_get_addr_fd->elf.plt.plist; 7190 ent != NULL; 7191 ent = ent->next) 7192 if (ent->addend == 0) 7193 { 7194 if (ent->plt.refcount > 0) 7195 ent->plt.refcount -= 1; 7196 break; 7197 } 7198 } 7199 7200 if (tls_clear == 0) |
7045 continue; | 7201 continue; |
7046 } | |
7047 | 7202 |
7048 if ((tls_set & TLS_EXPLICIT) == 0) 7049 { 7050 struct got_entry *ent; | 7203 if ((tls_set & TLS_EXPLICIT) == 0) 7204 { 7205 struct got_entry *ent; |
7051 | 7206 |
7052 /* Adjust got entry for this reloc. */ 7053 if (h != NULL) 7054 ent = h->got.glist; 7055 else 7056 ent = elf_local_got_ents (ibfd)[r_symndx]; | 7207 /* Adjust got entry for this reloc. */ 7208 if (h != NULL) 7209 ent = h->got.glist; 7210 else 7211 ent = elf_local_got_ents (ibfd)[r_symndx]; |
7057 | 7212 |
7058 for (; ent != NULL; ent = ent->next) 7059 if (ent->addend == rel->r_addend 7060 && ent->owner == ibfd 7061 && ent->tls_type == tls_type) 7062 break; 7063 if (ent == NULL) 7064 abort (); | 7213 for (; ent != NULL; ent = ent->next) 7214 if (ent->addend == rel->r_addend 7215 && ent->owner == ibfd 7216 && ent->tls_type == tls_type) 7217 break; 7218 if (ent == NULL) 7219 abort (); |
7065 | 7220 |
7066 if (tls_set == 0) 7067 { 7068 /* We managed to get rid of a got entry. */ 7069 if (ent->got.refcount > 0) 7070 ent->got.refcount -= 1; 7071 } 7072 } 7073 else 7074 { 7075 /* If we got rid of a DTPMOD/DTPREL reloc pair then 7076 we'll lose one or two dyn relocs. */ 7077 if (!dec_dynrel_count (rel->r_info, sec, info, 7078 NULL, h, sym_sec)) 7079 return FALSE; | 7221 if (tls_set == 0) 7222 { 7223 /* We managed to get rid of a got entry. */ 7224 if (ent->got.refcount > 0) 7225 ent->got.refcount -= 1; 7226 } 7227 } 7228 else 7229 { 7230 /* If we got rid of a DTPMOD/DTPREL reloc pair then 7231 we'll lose one or two dyn relocs. */ 7232 if (!dec_dynrel_count (rel->r_info, sec, info, 7233 NULL, h, sym_sec)) 7234 return FALSE; |
7080 | 7235 |
7081 if (tls_set == (TLS_EXPLICIT | TLS_GD)) 7082 { 7083 if (!dec_dynrel_count ((rel + 1)->r_info, sec, info, 7084 NULL, h, sym_sec)) 7085 return FALSE; 7086 } 7087 } | 7236 if (tls_set == (TLS_EXPLICIT | TLS_GD)) 7237 { 7238 if (!dec_dynrel_count ((rel + 1)->r_info, sec, info, 7239 NULL, h, sym_sec)) 7240 return FALSE; 7241 } 7242 } |
7088 | 7243 |
7089 *tls_mask |= tls_set; 7090 *tls_mask &= ~tls_clear; 7091 } | 7244 *tls_mask |= tls_set; 7245 *tls_mask &= ~tls_clear; 7246 } |
7092 | 7247 |
7093 if (elf_section_data (sec)->relocs != relstart) 7094 free (relstart); 7095 } | 7248 if (elf_section_data (sec)->relocs != relstart) 7249 free (relstart); 7250 } |
7096 | 7251 |
7097 if (toc_ref != NULL) 7098 free (toc_ref); | 7252 if (toc_ref != NULL) 7253 free (toc_ref); |
7099 | 7254 |
7100 if (locsyms != NULL 7101 && (elf_tdata (ibfd)->symtab_hdr.contents 7102 != (unsigned char *) locsyms)) 7103 { 7104 if (!info->keep_memory) 7105 free (locsyms); 7106 else 7107 elf_tdata (ibfd)->symtab_hdr.contents = (unsigned char *) locsyms; 7108 } 7109 } | 7255 if (locsyms != NULL 7256 && (elf_tdata (ibfd)->symtab_hdr.contents 7257 != (unsigned char *) locsyms)) 7258 { 7259 if (!info->keep_memory) 7260 free (locsyms); 7261 else 7262 elf_tdata (ibfd)->symtab_hdr.contents = (unsigned char *) locsyms; 7263 } 7264 } |
7110 return TRUE; 7111} 7112 7113/* Called via elf_link_hash_traverse from ppc64_elf_edit_toc to adjust 7114 the values of any global symbols in a toc section that has been 7115 edited. Globals in toc sections should be a rarity, so this function 7116 sets a flag if any are found in toc sections other than the one just 7117 edited, so that futher hash table traversals can be avoided. */ --- 557 unchanged lines hidden (view full) --- 7675 { 7676 if (! bfd_elf_link_record_dynamic_symbol (info, h)) 7677 return FALSE; 7678 } 7679 7680 if ((gent->tls_type & TLS_LD) != 0 7681 && !h->def_dynamic) 7682 { | 7265 return TRUE; 7266} 7267 7268/* Called via elf_link_hash_traverse from ppc64_elf_edit_toc to adjust 7269 the values of any global symbols in a toc section that has been 7270 edited. Globals in toc sections should be a rarity, so this function 7271 sets a flag if any are found in toc sections other than the one just 7272 edited, so that futher hash table traversals can be avoided. */ --- 557 unchanged lines hidden (view full) --- 7830 { 7831 if (! bfd_elf_link_record_dynamic_symbol (info, h)) 7832 return FALSE; 7833 } 7834 7835 if ((gent->tls_type & TLS_LD) != 0 7836 && !h->def_dynamic) 7837 { |
7683 gent->got.offset = ppc64_tlsld_got (gent->owner)->offset; | 7838 ppc64_tlsld_got (gent->owner)->refcount += 1; 7839 gent->got.offset = (bfd_vma) -1; |
7684 continue; 7685 } 7686 7687 s = ppc64_elf_tdata (gent->owner)->got; 7688 gent->got.offset = s->size; 7689 s->size 7690 += (gent->tls_type & eh->tls_mask & (TLS_GD | TLS_LD)) ? 16 : 8; 7691 dyn = htab->elf.dynamic_sections_created; --- 16 unchanged lines hidden (view full) --- 7708 dynamic pc-relative relocs against symbols which turn out to be 7709 defined in regular objects. For the normal shared case, discard 7710 space for relocs that have become local due to symbol visibility 7711 changes. */ 7712 7713 if (info->shared) 7714 { 7715 /* Relocs that use pc_count are those that appear on a call insn, | 7840 continue; 7841 } 7842 7843 s = ppc64_elf_tdata (gent->owner)->got; 7844 gent->got.offset = s->size; 7845 s->size 7846 += (gent->tls_type & eh->tls_mask & (TLS_GD | TLS_LD)) ? 16 : 8; 7847 dyn = htab->elf.dynamic_sections_created; --- 16 unchanged lines hidden (view full) --- 7864 dynamic pc-relative relocs against symbols which turn out to be 7865 defined in regular objects. For the normal shared case, discard 7866 space for relocs that have become local due to symbol visibility 7867 changes. */ 7868 7869 if (info->shared) 7870 { 7871 /* Relocs that use pc_count are those that appear on a call insn, |
7716 or certain REL relocs (see MUST_BE_DYN_RELOC) that can be | 7872 or certain REL relocs (see must_be_dyn_reloc) that can be |
7717 generated via assembly. We want calls to protected symbols to 7718 resolve directly to the function rather than going via the plt. 7719 If people want function pointer comparisons to work as expected 7720 then they should avoid writing weird assembly. */ 7721 if (SYMBOL_CALLS_LOCAL (info, h)) 7722 { 7723 struct ppc_dyn_relocs **pp; 7724 --- 134 unchanged lines hidden (view full) --- 7859 char *lgot_masks; 7860 bfd_size_type locsymcount; 7861 Elf_Internal_Shdr *symtab_hdr; 7862 asection *srel; 7863 7864 if (!is_ppc64_elf_target (ibfd->xvec)) 7865 continue; 7866 | 7873 generated via assembly. We want calls to protected symbols to 7874 resolve directly to the function rather than going via the plt. 7875 If people want function pointer comparisons to work as expected 7876 then they should avoid writing weird assembly. */ 7877 if (SYMBOL_CALLS_LOCAL (info, h)) 7878 { 7879 struct ppc_dyn_relocs **pp; 7880 --- 134 unchanged lines hidden (view full) --- 8015 char *lgot_masks; 8016 bfd_size_type locsymcount; 8017 Elf_Internal_Shdr *symtab_hdr; 8018 asection *srel; 8019 8020 if (!is_ppc64_elf_target (ibfd->xvec)) 8021 continue; 8022 |
7867 if (ppc64_tlsld_got (ibfd)->refcount > 0) 7868 { 7869 s = ppc64_elf_tdata (ibfd)->got; 7870 ppc64_tlsld_got (ibfd)->offset = s->size; 7871 s->size += 16; 7872 if (info->shared) 7873 { 7874 srel = ppc64_elf_tdata (ibfd)->relgot; 7875 srel->size += sizeof (Elf64_External_Rela); 7876 } 7877 } 7878 else 7879 ppc64_tlsld_got (ibfd)->offset = (bfd_vma) -1; 7880 | |
7881 for (s = ibfd->sections; s != NULL; s = s->next) 7882 { 7883 struct ppc_dyn_relocs *p; 7884 7885 for (p = elf_section_data (s)->local_dynrel; p != NULL; p = p->next) 7886 { 7887 if (!bfd_is_abs_section (p->sec) 7888 && bfd_is_abs_section (p->sec->output_section)) --- 27 unchanged lines hidden (view full) --- 7916 { 7917 struct got_entry *ent; 7918 7919 for (ent = *lgot_ents; ent != NULL; ent = ent->next) 7920 if (ent->got.refcount > 0) 7921 { 7922 if ((ent->tls_type & *lgot_masks & TLS_LD) != 0) 7923 { | 8023 for (s = ibfd->sections; s != NULL; s = s->next) 8024 { 8025 struct ppc_dyn_relocs *p; 8026 8027 for (p = elf_section_data (s)->local_dynrel; p != NULL; p = p->next) 8028 { 8029 if (!bfd_is_abs_section (p->sec) 8030 && bfd_is_abs_section (p->sec->output_section)) --- 27 unchanged lines hidden (view full) --- 8058 { 8059 struct got_entry *ent; 8060 8061 for (ent = *lgot_ents; ent != NULL; ent = ent->next) 8062 if (ent->got.refcount > 0) 8063 { 8064 if ((ent->tls_type & *lgot_masks & TLS_LD) != 0) 8065 { |
7924 if (ppc64_tlsld_got (ibfd)->offset == (bfd_vma) -1) 7925 { 7926 ppc64_tlsld_got (ibfd)->offset = s->size; 7927 s->size += 16; 7928 if (info->shared) 7929 srel->size += sizeof (Elf64_External_Rela); 7930 } 7931 ent->got.offset = ppc64_tlsld_got (ibfd)->offset; | 8066 ppc64_tlsld_got (ibfd)->refcount += 1; 8067 ent->got.offset = (bfd_vma) -1; |
7932 } 7933 else 7934 { 7935 ent->got.offset = s->size; 7936 if ((ent->tls_type & *lgot_masks & TLS_GD) != 0) 7937 { 7938 s->size += 16; 7939 if (info->shared) --- 11 unchanged lines hidden (view full) --- 7951 ent->got.offset = (bfd_vma) -1; 7952 } 7953 } 7954 7955 /* Allocate global sym .plt and .got entries, and space for global 7956 sym dynamic relocs. */ 7957 elf_link_hash_traverse (&htab->elf, allocate_dynrelocs, info); 7958 | 8068 } 8069 else 8070 { 8071 ent->got.offset = s->size; 8072 if ((ent->tls_type & *lgot_masks & TLS_GD) != 0) 8073 { 8074 s->size += 16; 8075 if (info->shared) --- 11 unchanged lines hidden (view full) --- 8087 ent->got.offset = (bfd_vma) -1; 8088 } 8089 } 8090 8091 /* Allocate global sym .plt and .got entries, and space for global 8092 sym dynamic relocs. */ 8093 elf_link_hash_traverse (&htab->elf, allocate_dynrelocs, info); 8094 |
8095 for (ibfd = info->input_bfds; ibfd != NULL; ibfd = ibfd->link_next) 8096 { 8097 if (!is_ppc64_elf_target (ibfd->xvec)) 8098 continue; 8099 8100 if (ppc64_tlsld_got (ibfd)->refcount > 0) 8101 { 8102 s = ppc64_elf_tdata (ibfd)->got; 8103 ppc64_tlsld_got (ibfd)->offset = s->size; 8104 s->size += 16; 8105 if (info->shared) 8106 { 8107 asection *srel = ppc64_elf_tdata (ibfd)->relgot; 8108 srel->size += sizeof (Elf64_External_Rela); 8109 } 8110 } 8111 else 8112 ppc64_tlsld_got (ibfd)->offset = (bfd_vma) -1; 8113 } 8114 |
|
7959 /* We now have determined the sizes of the various dynamic sections. 7960 Allocate memory for them. */ 7961 relocs = FALSE; 7962 for (s = dynobj->sections; s != NULL; s = s->next) 7963 { 7964 if ((s->flags & SEC_LINKER_CREATED) == 0) 7965 continue; 7966 --- 218 unchanged lines hidden (view full) --- 8185 8186static inline bfd_byte * 8187build_plt_stub (bfd *obfd, bfd_byte *p, int offset) 8188{ 8189#define PPC_LO(v) ((v) & 0xffff) 8190#define PPC_HI(v) (((v) >> 16) & 0xffff) 8191#define PPC_HA(v) PPC_HI ((v) + 0x8000) 8192 | 8115 /* We now have determined the sizes of the various dynamic sections. 8116 Allocate memory for them. */ 8117 relocs = FALSE; 8118 for (s = dynobj->sections; s != NULL; s = s->next) 8119 { 8120 if ((s->flags & SEC_LINKER_CREATED) == 0) 8121 continue; 8122 --- 218 unchanged lines hidden (view full) --- 8341 8342static inline bfd_byte * 8343build_plt_stub (bfd *obfd, bfd_byte *p, int offset) 8344{ 8345#define PPC_LO(v) ((v) & 0xffff) 8346#define PPC_HI(v) (((v) >> 16) & 0xffff) 8347#define PPC_HA(v) PPC_HI ((v) + 0x8000) 8348 |
8193 bfd_put_32 (obfd, ADDIS_R12_R2 | PPC_HA (offset), p), p += 4; 8194 bfd_put_32 (obfd, STD_R2_40R1, p), p += 4; 8195 bfd_put_32 (obfd, LD_R11_0R12 | PPC_LO (offset), p), p += 4; 8196 if (PPC_HA (offset + 8) != PPC_HA (offset)) 8197 bfd_put_32 (obfd, ADDIS_R12_R12 | 1, p), p += 4; 8198 offset += 8; 8199 bfd_put_32 (obfd, LD_R2_0R12 | PPC_LO (offset), p), p += 4; 8200 if (PPC_HA (offset + 8) != PPC_HA (offset)) 8201 bfd_put_32 (obfd, ADDIS_R12_R12 | 1, p), p += 4; 8202 offset += 8; 8203 bfd_put_32 (obfd, MTCTR_R11, p), p += 4; 8204 bfd_put_32 (obfd, LD_R11_0R12 | PPC_LO (offset), p), p += 4; 8205 bfd_put_32 (obfd, BCTR, p), p += 4; | 8349 if (PPC_HA (offset) != 0) 8350 { 8351 bfd_put_32 (obfd, ADDIS_R12_R2 | PPC_HA (offset), p), p += 4; 8352 bfd_put_32 (obfd, STD_R2_40R1, p), p += 4; 8353 bfd_put_32 (obfd, LD_R11_0R12 | PPC_LO (offset), p), p += 4; 8354 if (PPC_HA (offset + 16) != PPC_HA (offset)) 8355 { 8356 bfd_put_32 (obfd, ADDI_R12_R12 | PPC_LO (offset), p), p += 4; 8357 offset = 0; 8358 } 8359 bfd_put_32 (obfd, MTCTR_R11, p), p += 4; 8360 bfd_put_32 (obfd, LD_R2_0R12 | PPC_LO (offset + 8), p), p += 4; 8361 bfd_put_32 (obfd, LD_R11_0R12 | PPC_LO (offset + 16), p), p += 4; 8362 bfd_put_32 (obfd, BCTR, p), p += 4; 8363 } 8364 else 8365 { 8366 bfd_put_32 (obfd, STD_R2_40R1, p), p += 4; 8367 bfd_put_32 (obfd, LD_R11_0R2 | PPC_LO (offset), p), p += 4; 8368 if (PPC_HA (offset + 16) != PPC_HA (offset)) 8369 { 8370 bfd_put_32 (obfd, ADDI_R2_R2 | PPC_LO (offset), p), p += 4; 8371 offset = 0; 8372 } 8373 bfd_put_32 (obfd, MTCTR_R11, p), p += 4; 8374 bfd_put_32 (obfd, LD_R11_0R2 | PPC_LO (offset + 16), p), p += 4; 8375 bfd_put_32 (obfd, LD_R2_0R2 | PPC_LO (offset + 8), p), p += 4; 8376 bfd_put_32 (obfd, BCTR, p), p += 4; 8377 } |
8206 return p; 8207} 8208 8209static bfd_boolean 8210ppc_build_one_stub (struct bfd_hash_entry *gen_entry, void *in_arg) 8211{ 8212 struct ppc_stub_hash_entry *stub_entry; 8213 struct ppc_branch_hash_entry *br_entry; --- 26 unchanged lines hidden (view full) --- 8240 + stub_entry->target_section->output_offset 8241 + stub_entry->target_section->output_section->vma); 8242 8243 /* And this is where we are coming from. */ 8244 off -= (stub_entry->stub_offset 8245 + stub_entry->stub_sec->output_offset 8246 + stub_entry->stub_sec->output_section->vma); 8247 | 8378 return p; 8379} 8380 8381static bfd_boolean 8382ppc_build_one_stub (struct bfd_hash_entry *gen_entry, void *in_arg) 8383{ 8384 struct ppc_stub_hash_entry *stub_entry; 8385 struct ppc_branch_hash_entry *br_entry; --- 26 unchanged lines hidden (view full) --- 8412 + stub_entry->target_section->output_offset 8413 + stub_entry->target_section->output_section->vma); 8414 8415 /* And this is where we are coming from. */ 8416 off -= (stub_entry->stub_offset 8417 + stub_entry->stub_sec->output_offset 8418 + stub_entry->stub_sec->output_section->vma); 8419 |
8248 if (stub_entry->stub_type != ppc_stub_long_branch_r2off) 8249 size = 4; 8250 else | 8420 size = 4; 8421 if (stub_entry->stub_type == ppc_stub_long_branch_r2off) |
8251 { 8252 bfd_vma r2off; 8253 8254 r2off = (htab->stub_group[stub_entry->target_section->id].toc_off 8255 - htab->stub_group[stub_entry->id_sec->id].toc_off); 8256 bfd_put_32 (htab->stub_bfd, STD_R2_40R1, loc); 8257 loc += 4; | 8422 { 8423 bfd_vma r2off; 8424 8425 r2off = (htab->stub_group[stub_entry->target_section->id].toc_off 8426 - htab->stub_group[stub_entry->id_sec->id].toc_off); 8427 bfd_put_32 (htab->stub_bfd, STD_R2_40R1, loc); 8428 loc += 4; |
8258 bfd_put_32 (htab->stub_bfd, ADDIS_R2_R2 | PPC_HA (r2off), loc); 8259 loc += 4; | 8429 size = 12; 8430 if (PPC_HA (r2off) != 0) 8431 { 8432 size = 16; 8433 bfd_put_32 (htab->stub_bfd, ADDIS_R2_R2 | PPC_HA (r2off), loc); 8434 loc += 4; 8435 } |
8260 bfd_put_32 (htab->stub_bfd, ADDI_R2_R2 | PPC_LO (r2off), loc); 8261 loc += 4; | 8436 bfd_put_32 (htab->stub_bfd, ADDI_R2_R2 | PPC_LO (r2off), loc); 8437 loc += 4; |
8262 off -= 12; 8263 size = 16; | 8438 off -= size - 4; |
8264 } 8265 bfd_put_32 (htab->stub_bfd, B_DOT | (off & 0x3fffffc), loc); 8266 8267 if (off + (1 << 25) >= (bfd_vma) (1 << 26)) 8268 { 8269 (*_bfd_error_handler) (_("long branch stub `%s' offset overflow"), 8270 stub_entry->root.string); 8271 htab->stub_error = TRUE; --- 140 unchanged lines hidden (view full) --- 8412 bfd_set_error (bfd_error_bad_value); 8413 htab->stub_error = TRUE; 8414 return FALSE; 8415 } 8416 8417 indx = off; 8418 if (stub_entry->stub_type != ppc_stub_plt_branch_r2off) 8419 { | 8439 } 8440 bfd_put_32 (htab->stub_bfd, B_DOT | (off & 0x3fffffc), loc); 8441 8442 if (off + (1 << 25) >= (bfd_vma) (1 << 26)) 8443 { 8444 (*_bfd_error_handler) (_("long branch stub `%s' offset overflow"), 8445 stub_entry->root.string); 8446 htab->stub_error = TRUE; --- 140 unchanged lines hidden (view full) --- 8587 bfd_set_error (bfd_error_bad_value); 8588 htab->stub_error = TRUE; 8589 return FALSE; 8590 } 8591 8592 indx = off; 8593 if (stub_entry->stub_type != ppc_stub_plt_branch_r2off) 8594 { |
8420 bfd_put_32 (htab->stub_bfd, ADDIS_R12_R2 | PPC_HA (indx), loc); 8421 loc += 4; 8422 bfd_put_32 (htab->stub_bfd, LD_R11_0R12 | PPC_LO (indx), loc); 8423 size = 16; | 8595 if (PPC_HA (indx) != 0) 8596 { 8597 size = 16; 8598 bfd_put_32 (htab->stub_bfd, ADDIS_R12_R2 | PPC_HA (indx), loc); 8599 loc += 4; 8600 bfd_put_32 (htab->stub_bfd, LD_R11_0R12 | PPC_LO (indx), loc); 8601 } 8602 else 8603 { 8604 size = 12; 8605 bfd_put_32 (htab->stub_bfd, LD_R11_0R2 | PPC_LO (indx), loc); 8606 } |
8424 } 8425 else 8426 { 8427 bfd_vma r2off; 8428 8429 r2off = (htab->stub_group[stub_entry->target_section->id].toc_off 8430 - htab->stub_group[stub_entry->id_sec->id].toc_off); 8431 bfd_put_32 (htab->stub_bfd, STD_R2_40R1, loc); 8432 loc += 4; | 8607 } 8608 else 8609 { 8610 bfd_vma r2off; 8611 8612 r2off = (htab->stub_group[stub_entry->target_section->id].toc_off 8613 - htab->stub_group[stub_entry->id_sec->id].toc_off); 8614 bfd_put_32 (htab->stub_bfd, STD_R2_40R1, loc); 8615 loc += 4; |
8433 bfd_put_32 (htab->stub_bfd, ADDIS_R12_R2 | PPC_HA (indx), loc); 8434 loc += 4; 8435 bfd_put_32 (htab->stub_bfd, LD_R11_0R12 | PPC_LO (indx), loc); 8436 loc += 4; 8437 bfd_put_32 (htab->stub_bfd, ADDIS_R2_R2 | PPC_HA (r2off), loc); 8438 loc += 4; | 8616 size = 20; 8617 if (PPC_HA (indx) != 0) 8618 { 8619 size += 4; 8620 bfd_put_32 (htab->stub_bfd, ADDIS_R12_R2 | PPC_HA (indx), loc); 8621 loc += 4; 8622 bfd_put_32 (htab->stub_bfd, LD_R11_0R12 | PPC_LO (indx), loc); 8623 loc += 4; 8624 } 8625 else 8626 { 8627 bfd_put_32 (htab->stub_bfd, LD_R11_0R2 | PPC_LO (indx), loc); 8628 loc += 4; 8629 } 8630 8631 if (PPC_HA (r2off) != 0) 8632 { 8633 size += 4; 8634 bfd_put_32 (htab->stub_bfd, ADDIS_R2_R2 | PPC_HA (r2off), loc); 8635 loc += 4; 8636 } |
8439 bfd_put_32 (htab->stub_bfd, ADDI_R2_R2 | PPC_LO (r2off), loc); | 8637 bfd_put_32 (htab->stub_bfd, ADDI_R2_R2 | PPC_LO (r2off), loc); |
8440 size = 28; | |
8441 } 8442 loc += 4; 8443 bfd_put_32 (htab->stub_bfd, MTCTR_R11, loc); 8444 loc += 4; 8445 bfd_put_32 (htab->stub_bfd, BCTR, loc); 8446 break; 8447 8448 case ppc_stub_plt_call: --- 122 unchanged lines hidden (view full) --- 8571 if (off >= (bfd_vma) -2) 8572 abort (); 8573 off += (htab->plt->output_offset 8574 + htab->plt->output_section->vma 8575 - elf_gp (htab->plt->output_section->owner) 8576 - htab->stub_group[stub_entry->id_sec->id].toc_off); 8577 8578 size = PLT_CALL_STUB_SIZE; | 8638 } 8639 loc += 4; 8640 bfd_put_32 (htab->stub_bfd, MTCTR_R11, loc); 8641 loc += 4; 8642 bfd_put_32 (htab->stub_bfd, BCTR, loc); 8643 break; 8644 8645 case ppc_stub_plt_call: --- 122 unchanged lines hidden (view full) --- 8768 if (off >= (bfd_vma) -2) 8769 abort (); 8770 off += (htab->plt->output_offset 8771 + htab->plt->output_section->vma 8772 - elf_gp (htab->plt->output_section->owner) 8773 - htab->stub_group[stub_entry->id_sec->id].toc_off); 8774 8775 size = PLT_CALL_STUB_SIZE; |
8776 if (PPC_HA (off) == 0) 8777 size -= 4; |
|
8579 if (PPC_HA (off + 16) != PPC_HA (off)) 8580 size += 4; 8581 } 8582 else 8583 { 8584 /* ppc_stub_long_branch or ppc_stub_plt_branch, or their r2off 8585 variants. */ | 8778 if (PPC_HA (off + 16) != PPC_HA (off)) 8779 size += 4; 8780 } 8781 else 8782 { 8783 /* ppc_stub_long_branch or ppc_stub_plt_branch, or their r2off 8784 variants. */ |
8785 bfd_vma r2off = 0; 8786 |
|
8586 off = (stub_entry->target_value 8587 + stub_entry->target_section->output_offset 8588 + stub_entry->target_section->output_section->vma); 8589 off -= (stub_entry->stub_sec->size 8590 + stub_entry->stub_sec->output_offset 8591 + stub_entry->stub_sec->output_section->vma); 8592 8593 /* Reset the stub type from the plt variant in case we now 8594 can reach with a shorter stub. */ 8595 if (stub_entry->stub_type >= ppc_stub_plt_branch) 8596 stub_entry->stub_type += ppc_stub_long_branch - ppc_stub_plt_branch; 8597 8598 size = 4; 8599 if (stub_entry->stub_type == ppc_stub_long_branch_r2off) 8600 { | 8787 off = (stub_entry->target_value 8788 + stub_entry->target_section->output_offset 8789 + stub_entry->target_section->output_section->vma); 8790 off -= (stub_entry->stub_sec->size 8791 + stub_entry->stub_sec->output_offset 8792 + stub_entry->stub_sec->output_section->vma); 8793 8794 /* Reset the stub type from the plt variant in case we now 8795 can reach with a shorter stub. */ 8796 if (stub_entry->stub_type >= ppc_stub_plt_branch) 8797 stub_entry->stub_type += ppc_stub_long_branch - ppc_stub_plt_branch; 8798 8799 size = 4; 8800 if (stub_entry->stub_type == ppc_stub_long_branch_r2off) 8801 { |
8601 off -= 12; 8602 size = 16; | 8802 r2off = (htab->stub_group[stub_entry->target_section->id].toc_off 8803 - htab->stub_group[stub_entry->id_sec->id].toc_off); 8804 size = 12; 8805 if (PPC_HA (r2off) != 0) 8806 size = 16; 8807 off -= size - 4; |
8603 } 8604 8605 /* If the branch offset if too big, use a ppc_stub_plt_branch. */ 8606 if (off + (1 << 25) >= (bfd_vma) (1 << 26)) 8607 { 8608 struct ppc_branch_hash_entry *br_entry; | 8808 } 8809 8810 /* If the branch offset if too big, use a ppc_stub_plt_branch. */ 8811 if (off + (1 << 25) >= (bfd_vma) (1 << 26)) 8812 { 8813 struct ppc_branch_hash_entry *br_entry; |
8814 unsigned int indx; |
|
8609 8610 br_entry = ppc_branch_hash_lookup (&htab->branch_hash_table, 8611 stub_entry->root.string + 9, 8612 TRUE, FALSE); 8613 if (br_entry == NULL) 8614 { 8615 (*_bfd_error_handler) (_("can't build branch stub `%s'"), 8616 stub_entry->root.string); --- 12 unchanged lines hidden (view full) --- 8629 else if (info->emitrelocations) 8630 { 8631 htab->brlt->reloc_count += 1; 8632 htab->brlt->flags |= SEC_RELOC; 8633 } 8634 } 8635 8636 stub_entry->stub_type += ppc_stub_plt_branch - ppc_stub_long_branch; | 8815 8816 br_entry = ppc_branch_hash_lookup (&htab->branch_hash_table, 8817 stub_entry->root.string + 9, 8818 TRUE, FALSE); 8819 if (br_entry == NULL) 8820 { 8821 (*_bfd_error_handler) (_("can't build branch stub `%s'"), 8822 stub_entry->root.string); --- 12 unchanged lines hidden (view full) --- 8835 else if (info->emitrelocations) 8836 { 8837 htab->brlt->reloc_count += 1; 8838 htab->brlt->flags |= SEC_RELOC; 8839 } 8840 } 8841 8842 stub_entry->stub_type += ppc_stub_plt_branch - ppc_stub_long_branch; |
8637 size = 16; 8638 if (stub_entry->stub_type != ppc_stub_plt_branch) 8639 size = 28; | 8843 off = (br_entry->offset 8844 + htab->brlt->output_offset 8845 + htab->brlt->output_section->vma 8846 - elf_gp (htab->brlt->output_section->owner) 8847 - htab->stub_group[stub_entry->id_sec->id].toc_off); 8848 8849 indx = off; 8850 if (stub_entry->stub_type != ppc_stub_plt_branch_r2off) 8851 { 8852 size = 12; 8853 if (PPC_HA (indx) != 0) 8854 size = 16; 8855 } 8856 else 8857 { 8858 size = 20; 8859 if (PPC_HA (indx) != 0) 8860 size += 4; 8861 8862 if (PPC_HA (r2off) != 0) 8863 size += 4; 8864 } |
8640 } 8641 else if (info->emitrelocations) 8642 { 8643 stub_entry->stub_sec->reloc_count += 1; 8644 stub_entry->stub_sec->flags |= SEC_RELOC; 8645 } 8646 } 8647 --- 150 unchanged lines hidden (view full) --- 8798 local_syms = NULL; 8799 ret = 0; 8800 htab = ppc_hash_table (info); 8801 for (rel = relstart; rel < relstart + isec->reloc_count; ++rel) 8802 { 8803 enum elf_ppc64_reloc_type r_type; 8804 unsigned long r_symndx; 8805 struct elf_link_hash_entry *h; | 8865 } 8866 else if (info->emitrelocations) 8867 { 8868 stub_entry->stub_sec->reloc_count += 1; 8869 stub_entry->stub_sec->flags |= SEC_RELOC; 8870 } 8871 } 8872 --- 150 unchanged lines hidden (view full) --- 9023 local_syms = NULL; 9024 ret = 0; 9025 htab = ppc_hash_table (info); 9026 for (rel = relstart; rel < relstart + isec->reloc_count; ++rel) 9027 { 9028 enum elf_ppc64_reloc_type r_type; 9029 unsigned long r_symndx; 9030 struct elf_link_hash_entry *h; |
9031 struct ppc_link_hash_entry *eh; |
|
8806 Elf_Internal_Sym *sym; 8807 asection *sym_sec; 8808 long *opd_adjust; 8809 bfd_vma sym_value; 8810 bfd_vma dest; 8811 8812 r_type = ELF64_R_TYPE (rel->r_info); 8813 if (r_type != R_PPC64_REL24 --- 6 unchanged lines hidden (view full) --- 8820 if (!get_sym_h (&h, &sym, &sym_sec, NULL, &local_syms, r_symndx, 8821 isec->owner)) 8822 { 8823 ret = -1; 8824 break; 8825 } 8826 8827 /* Calls to dynamic lib functions go through a plt call stub | 9032 Elf_Internal_Sym *sym; 9033 asection *sym_sec; 9034 long *opd_adjust; 9035 bfd_vma sym_value; 9036 bfd_vma dest; 9037 9038 r_type = ELF64_R_TYPE (rel->r_info); 9039 if (r_type != R_PPC64_REL24 --- 6 unchanged lines hidden (view full) --- 9046 if (!get_sym_h (&h, &sym, &sym_sec, NULL, &local_syms, r_symndx, 9047 isec->owner)) 9048 { 9049 ret = -1; 9050 break; 9051 } 9052 9053 /* Calls to dynamic lib functions go through a plt call stub |
8828 that uses r2. Branches to undefined symbols might be a call 8829 using old-style dot symbols that can be satisfied by a plt 8830 call into a new-style dynamic library. */ 8831 if (sym_sec == NULL) | 9054 that uses r2. */ 9055 eh = (struct ppc_link_hash_entry *) h; 9056 if (eh != NULL 9057 && (eh->elf.plt.plist != NULL 9058 || (eh->oh != NULL 9059 && eh->oh->elf.plt.plist != NULL))) |
8832 { | 9060 { |
8833 struct ppc_link_hash_entry *eh = (struct ppc_link_hash_entry *) h; 8834 if (eh != NULL 8835 && eh->oh != NULL 8836 && eh->oh->elf.plt.plist != NULL) 8837 { 8838 ret = 1; 8839 break; 8840 } 8841 8842 /* Ignore other undefined symbols. */ 8843 continue; | 9061 ret = 1; 9062 break; |
8844 } 8845 | 9063 } 9064 |
9065 if (sym_sec == NULL) 9066 /* Ignore other undefined symbols. */ 9067 continue; 9068 |
|
8846 /* Assume branches to other sections not included in the link need 8847 stubs too, to cover -R and absolute syms. */ 8848 if (sym_sec->output_section == NULL) 8849 { 8850 ret = 1; 8851 break; 8852 } 8853 --- 501 unchanged lines hidden (view full) --- 9355 && (hash == htab->tls_get_addr 9356 || hash == htab->tls_get_addr_fd) 9357 && section->has_tls_reloc 9358 && irela != internal_relocs) 9359 { 9360 /* Get tls info. */ 9361 char *tls_mask; 9362 | 9069 /* Assume branches to other sections not included in the link need 9070 stubs too, to cover -R and absolute syms. */ 9071 if (sym_sec->output_section == NULL) 9072 { 9073 ret = 1; 9074 break; 9075 } 9076 --- 501 unchanged lines hidden (view full) --- 9578 && (hash == htab->tls_get_addr 9579 || hash == htab->tls_get_addr_fd) 9580 && section->has_tls_reloc 9581 && irela != internal_relocs) 9582 { 9583 /* Get tls info. */ 9584 char *tls_mask; 9585 |
9363 if (!get_tls_mask (&tls_mask, NULL, &local_syms, | 9586 if (!get_tls_mask (&tls_mask, NULL, NULL, &local_syms, |
9364 irela - 1, input_bfd)) 9365 goto error_ret_free_internal; 9366 if (*tls_mask != 0) 9367 continue; 9368 } 9369 9370 /* Support for grouping stub sections. */ 9371 id_sec = htab->stub_group[section->id].link_sec; --- 461 unchanged lines hidden (view full) --- 9833 bfd_reloc_status_type r; 9834 Elf_Internal_Sym *sym; 9835 asection *sec; 9836 struct elf_link_hash_entry *h_elf; 9837 struct ppc_link_hash_entry *h; 9838 struct ppc_link_hash_entry *fdh; 9839 const char *sym_name; 9840 unsigned long r_symndx, toc_symndx; | 9587 irela - 1, input_bfd)) 9588 goto error_ret_free_internal; 9589 if (*tls_mask != 0) 9590 continue; 9591 } 9592 9593 /* Support for grouping stub sections. */ 9594 id_sec = htab->stub_group[section->id].link_sec; --- 461 unchanged lines hidden (view full) --- 10056 bfd_reloc_status_type r; 10057 Elf_Internal_Sym *sym; 10058 asection *sec; 10059 struct elf_link_hash_entry *h_elf; 10060 struct ppc_link_hash_entry *h; 10061 struct ppc_link_hash_entry *fdh; 10062 const char *sym_name; 10063 unsigned long r_symndx, toc_symndx; |
10064 bfd_vma toc_addend; |
|
9841 char tls_mask, tls_gd, tls_type; 9842 char sym_type; 9843 bfd_vma relocation; 9844 bfd_boolean unresolved_reloc; 9845 bfd_boolean warned; 9846 unsigned long insn, mask; 9847 struct ppc_stub_hash_entry *stub_entry; 9848 bfd_vma max_br_offset; --- 77 unchanged lines hidden (view full) --- 9926 9927 /* TLS optimizations. Replace instruction sequences and relocs 9928 based on information we collected in tls_optimize. We edit 9929 RELOCS so that --emit-relocs will output something sensible 9930 for the final instruction stream. */ 9931 tls_mask = 0; 9932 tls_gd = 0; 9933 toc_symndx = 0; | 10065 char tls_mask, tls_gd, tls_type; 10066 char sym_type; 10067 bfd_vma relocation; 10068 bfd_boolean unresolved_reloc; 10069 bfd_boolean warned; 10070 unsigned long insn, mask; 10071 struct ppc_stub_hash_entry *stub_entry; 10072 bfd_vma max_br_offset; --- 77 unchanged lines hidden (view full) --- 10150 10151 /* TLS optimizations. Replace instruction sequences and relocs 10152 based on information we collected in tls_optimize. We edit 10153 RELOCS so that --emit-relocs will output something sensible 10154 for the final instruction stream. */ 10155 tls_mask = 0; 10156 tls_gd = 0; 10157 toc_symndx = 0; |
9934 if (IS_PPC64_TLS_RELOC (r_type)) | 10158 if (h != NULL) 10159 tls_mask = h->tls_mask; 10160 else if (local_got_ents != NULL) |
9935 { | 10161 { |
9936 if (h != NULL) 9937 tls_mask = h->tls_mask; 9938 else if (local_got_ents != NULL) 9939 { 9940 char *lgot_masks; 9941 lgot_masks = (char *) (local_got_ents + symtab_hdr->sh_info); 9942 tls_mask = lgot_masks[r_symndx]; 9943 } 9944 if (tls_mask == 0 && r_type == R_PPC64_TLS) 9945 { 9946 /* Check for toc tls entries. */ 9947 char *toc_tls; | 10162 char *lgot_masks; 10163 lgot_masks = (char *) (local_got_ents + symtab_hdr->sh_info); 10164 tls_mask = lgot_masks[r_symndx]; 10165 } 10166 if (tls_mask == 0 10167 && (r_type == R_PPC64_TLS 10168 || r_type == R_PPC64_TLSGD 10169 || r_type == R_PPC64_TLSLD)) 10170 { 10171 /* Check for toc tls entries. */ 10172 char *toc_tls; |
9948 | 10173 |
9949 if (!get_tls_mask (&toc_tls, &toc_symndx, &local_syms, 9950 rel, input_bfd)) 9951 return FALSE; | 10174 if (!get_tls_mask (&toc_tls, &toc_symndx, &toc_addend, 10175 &local_syms, rel, input_bfd)) 10176 return FALSE; |
9952 | 10177 |
9953 if (toc_tls) 9954 tls_mask = *toc_tls; 9955 } | 10178 if (toc_tls) 10179 tls_mask = *toc_tls; |
9956 } 9957 9958 /* Check that tls relocs are used with tls syms, and non-tls 9959 relocs are used with non-tls syms. */ 9960 if (r_symndx != 0 9961 && r_type != R_PPC64_NONE 9962 && (h == NULL 9963 || h->elf.root.type == bfd_link_hash_defined 9964 || h->elf.root.type == bfd_link_hash_defweak) | 10180 } 10181 10182 /* Check that tls relocs are used with tls syms, and non-tls 10183 relocs are used with non-tls syms. */ 10184 if (r_symndx != 0 10185 && r_type != R_PPC64_NONE 10186 && (h == NULL 10187 || h->elf.root.type == bfd_link_hash_defined 10188 || h->elf.root.type == bfd_link_hash_defweak) |
9965 && IS_PPC64_TLS_RELOC (r_type) != (sym_type == STT_TLS)) | 10189 && (IS_PPC64_TLS_RELOC (r_type) 10190 != (sym_type == STT_TLS 10191 || (sym_type == STT_SECTION 10192 && (sec->flags & SEC_THREAD_LOCAL) != 0)))) |
9966 { | 10193 { |
9967 if (r_type == R_PPC64_TLS && tls_mask != 0) | 10194 if (tls_mask != 0 10195 && (r_type == R_PPC64_TLS 10196 || r_type == R_PPC64_TLSGD 10197 || r_type == R_PPC64_TLSLD)) |
9968 /* R_PPC64_TLS is OK against a symbol in the TOC. */ 9969 ; 9970 else 9971 (*_bfd_error_handler) | 10198 /* R_PPC64_TLS is OK against a symbol in the TOC. */ 10199 ; 10200 else 10201 (*_bfd_error_handler) |
9972 (sym_type == STT_TLS | 10202 (!IS_PPC64_TLS_RELOC (r_type) |
9973 ? _("%B(%A+0x%lx): %s used with TLS symbol %s") 9974 : _("%B(%A+0x%lx): %s used with non-TLS symbol %s"), 9975 input_bfd, 9976 input_section, 9977 (long) rel->r_offset, 9978 ppc64_elf_howto_table[r_type]->name, 9979 sym_name); 9980 } --- 20 unchanged lines hidden (view full) --- 10001 case R_PPC64_TOC16_LO: 10002 case R_PPC64_TOC16_DS: 10003 case R_PPC64_TOC16_LO_DS: 10004 { 10005 /* Check for toc tls entries. */ 10006 char *toc_tls; 10007 int retval; 10008 | 10203 ? _("%B(%A+0x%lx): %s used with TLS symbol %s") 10204 : _("%B(%A+0x%lx): %s used with non-TLS symbol %s"), 10205 input_bfd, 10206 input_section, 10207 (long) rel->r_offset, 10208 ppc64_elf_howto_table[r_type]->name, 10209 sym_name); 10210 } --- 20 unchanged lines hidden (view full) --- 10231 case R_PPC64_TOC16_LO: 10232 case R_PPC64_TOC16_DS: 10233 case R_PPC64_TOC16_LO_DS: 10234 { 10235 /* Check for toc tls entries. */ 10236 char *toc_tls; 10237 int retval; 10238 |
10009 retval = get_tls_mask (&toc_tls, &toc_symndx, &local_syms, 10010 rel, input_bfd); | 10239 retval = get_tls_mask (&toc_tls, &toc_symndx, &toc_addend, 10240 &local_syms, rel, input_bfd); |
10011 if (retval == 0) 10012 return FALSE; 10013 10014 if (toc_tls) 10015 { 10016 tls_mask = *toc_tls; 10017 if (r_type == R_PPC64_TOC16_DS 10018 || r_type == R_PPC64_TOC16_LO_DS) --- 5 unchanged lines hidden (view full) --- 10024 else 10025 { 10026 /* If we found a GD reloc pair, then we might be 10027 doing a GD->IE transition. */ 10028 if (retval == 2) 10029 { 10030 tls_gd = TLS_TPRELGD; 10031 if (tls_mask != 0 && (tls_mask & TLS_GD) == 0) | 10241 if (retval == 0) 10242 return FALSE; 10243 10244 if (toc_tls) 10245 { 10246 tls_mask = *toc_tls; 10247 if (r_type == R_PPC64_TOC16_DS 10248 || r_type == R_PPC64_TOC16_LO_DS) --- 5 unchanged lines hidden (view full) --- 10254 else 10255 { 10256 /* If we found a GD reloc pair, then we might be 10257 doing a GD->IE transition. */ 10258 if (retval == 2) 10259 { 10260 tls_gd = TLS_TPRELGD; 10261 if (tls_mask != 0 && (tls_mask & TLS_GD) == 0) |
10032 goto tls_get_addr_check; | 10262 goto tls_ldgd_opt; |
10033 } 10034 else if (retval == 3) 10035 { 10036 if (tls_mask != 0 && (tls_mask & TLS_LD) == 0) | 10263 } 10264 else if (retval == 3) 10265 { 10266 if (tls_mask != 0 && (tls_mask & TLS_LD) == 0) |
10037 goto tls_get_addr_check; | 10267 goto tls_ldgd_opt; |
10038 } 10039 } 10040 } 10041 } 10042 break; 10043 10044 case R_PPC64_GOT_TPREL16_DS: 10045 case R_PPC64_GOT_TPREL16_LO_DS: --- 57 unchanged lines hidden (view full) --- 10103 bfd_put_32 (output_bfd, insn, contents + rel->r_offset); 10104 /* Was PPC64_TLS which sits on insn boundary, now 10105 PPC64_TPREL16_LO which is at low-order half-word. */ 10106 rel->r_offset += d_offset; 10107 r_type = R_PPC64_TPREL16_LO; 10108 if (toc_symndx != 0) 10109 { 10110 rel->r_info = ELF64_R_INFO (toc_symndx, r_type); | 10268 } 10269 } 10270 } 10271 } 10272 break; 10273 10274 case R_PPC64_GOT_TPREL16_DS: 10275 case R_PPC64_GOT_TPREL16_LO_DS: --- 57 unchanged lines hidden (view full) --- 10333 bfd_put_32 (output_bfd, insn, contents + rel->r_offset); 10334 /* Was PPC64_TLS which sits on insn boundary, now 10335 PPC64_TPREL16_LO which is at low-order half-word. */ 10336 rel->r_offset += d_offset; 10337 r_type = R_PPC64_TPREL16_LO; 10338 if (toc_symndx != 0) 10339 { 10340 rel->r_info = ELF64_R_INFO (toc_symndx, r_type); |
10341 rel->r_addend = toc_addend; 10342 rel->r_addend = toc_addend; |
|
10111 /* We changed the symbol. Start over in order to 10112 get h, sym, sec etc. right. */ 10113 rel--; 10114 continue; 10115 } 10116 else 10117 rel->r_info = ELF64_R_INFO (r_symndx, r_type); 10118 } --- 23 unchanged lines hidden (view full) --- 10142 rel->r_info = ELF64_R_INFO (r_symndx, r_type); 10143 } 10144 break; 10145 10146 case R_PPC64_GOT_TLSGD16: 10147 case R_PPC64_GOT_TLSGD16_LO: 10148 tls_gd = TLS_TPRELGD; 10149 if (tls_mask != 0 && (tls_mask & TLS_GD) == 0) | 10343 /* We changed the symbol. Start over in order to 10344 get h, sym, sec etc. right. */ 10345 rel--; 10346 continue; 10347 } 10348 else 10349 rel->r_info = ELF64_R_INFO (r_symndx, r_type); 10350 } --- 23 unchanged lines hidden (view full) --- 10374 rel->r_info = ELF64_R_INFO (r_symndx, r_type); 10375 } 10376 break; 10377 10378 case R_PPC64_GOT_TLSGD16: 10379 case R_PPC64_GOT_TLSGD16_LO: 10380 tls_gd = TLS_TPRELGD; 10381 if (tls_mask != 0 && (tls_mask & TLS_GD) == 0) |
10150 goto tls_get_addr_check; | 10382 goto tls_ldgd_opt; |
10151 break; 10152 10153 case R_PPC64_GOT_TLSLD16: 10154 case R_PPC64_GOT_TLSLD16_LO: 10155 if (tls_mask != 0 && (tls_mask & TLS_LD) == 0) 10156 { | 10383 break; 10384 10385 case R_PPC64_GOT_TLSLD16: 10386 case R_PPC64_GOT_TLSLD16_LO: 10387 if (tls_mask != 0 && (tls_mask & TLS_LD) == 0) 10388 { |
10157 tls_get_addr_check: 10158 if (rel + 1 < relend) 10159 { 10160 enum elf_ppc64_reloc_type r_type2; 10161 unsigned long r_symndx2; 10162 struct elf_link_hash_entry *h2; 10163 bfd_vma insn1, insn2, insn3; 10164 bfd_vma offset; | 10389 unsigned int insn1, insn2, insn3; 10390 bfd_vma offset; |
10165 | 10391 |
10166 /* The next instruction should be a call to 10167 __tls_get_addr. Peek at the reloc to be sure. */ 10168 r_type2 = ELF64_R_TYPE (rel[1].r_info); 10169 r_symndx2 = ELF64_R_SYM (rel[1].r_info); 10170 if (r_symndx2 < symtab_hdr->sh_info 10171 || (r_type2 != R_PPC64_REL14 10172 && r_type2 != R_PPC64_REL14_BRTAKEN 10173 && r_type2 != R_PPC64_REL14_BRNTAKEN 10174 && r_type2 != R_PPC64_REL24)) 10175 break; 10176 10177 h2 = sym_hashes[r_symndx2 - symtab_hdr->sh_info]; 10178 while (h2->root.type == bfd_link_hash_indirect 10179 || h2->root.type == bfd_link_hash_warning) 10180 h2 = (struct elf_link_hash_entry *) h2->root.u.i.link; 10181 if (h2 == NULL || (h2 != &htab->tls_get_addr->elf 10182 && h2 != &htab->tls_get_addr_fd->elf)) 10183 break; 10184 10185 /* OK, it checks out. Replace the call. */ 10186 offset = rel[1].r_offset; | 10392 tls_ldgd_opt: 10393 offset = (bfd_vma) -1; 10394 /* If not using the newer R_PPC64_TLSGD/LD to mark 10395 __tls_get_addr calls, we must trust that the call 10396 stays with its arg setup insns, ie. that the next 10397 reloc is the __tls_get_addr call associated with 10398 the current reloc. Edit both insns. */ 10399 if (input_section->has_tls_get_addr_call 10400 && rel + 1 < relend 10401 && branch_reloc_hash_match (input_bfd, rel + 1, 10402 htab->tls_get_addr, 10403 htab->tls_get_addr_fd)) 10404 offset = rel[1].r_offset; 10405 if ((tls_mask & tls_gd) != 0) 10406 { 10407 /* IE */ |
10187 insn1 = bfd_get_32 (output_bfd, 10188 contents + rel->r_offset - d_offset); | 10408 insn1 = bfd_get_32 (output_bfd, 10409 contents + rel->r_offset - d_offset); |
10189 insn3 = bfd_get_32 (output_bfd, 10190 contents + offset + 4); 10191 if ((tls_mask & tls_gd) != 0) | 10410 insn1 &= (1 << 26) - (1 << 2); 10411 insn1 |= 58 << 26; /* ld */ 10412 insn2 = 0x7c636a14; /* add 3,3,13 */ 10413 if (offset != (bfd_vma) -1) 10414 rel[1].r_info = ELF64_R_INFO (ELF64_R_SYM (rel[1].r_info), 10415 R_PPC64_NONE); 10416 if ((tls_mask & TLS_EXPLICIT) == 0) 10417 r_type = (((r_type - (R_PPC64_GOT_TLSGD16 & 3)) & 3) 10418 + R_PPC64_GOT_TPREL16_DS); 10419 else 10420 r_type += R_PPC64_TOC16_DS - R_PPC64_TOC16; 10421 rel->r_info = ELF64_R_INFO (r_symndx, r_type); 10422 } 10423 else 10424 { 10425 /* LE */ 10426 insn1 = 0x3c6d0000; /* addis 3,13,0 */ 10427 insn2 = 0x38630000; /* addi 3,3,0 */ 10428 if (tls_gd == 0) |
10192 { | 10429 { |
10193 /* IE */ 10194 insn1 &= (1 << 26) - (1 << 2); 10195 insn1 |= 58 << 26; /* ld */ 10196 insn2 = 0x7c636a14; /* add 3,3,13 */ 10197 rel[1].r_info = ELF64_R_INFO (r_symndx2, R_PPC64_NONE); 10198 if ((tls_mask & TLS_EXPLICIT) == 0) 10199 r_type = (((r_type - (R_PPC64_GOT_TLSGD16 & 3)) & 3) 10200 + R_PPC64_GOT_TPREL16_DS); 10201 else 10202 r_type += R_PPC64_TOC16_DS - R_PPC64_TOC16; 10203 rel->r_info = ELF64_R_INFO (r_symndx, r_type); | 10430 /* Was an LD reloc. */ 10431 if (toc_symndx) 10432 sec = local_sections[toc_symndx]; 10433 for (r_symndx = 0; 10434 r_symndx < symtab_hdr->sh_info; 10435 r_symndx++) 10436 if (local_sections[r_symndx] == sec) 10437 break; 10438 if (r_symndx >= symtab_hdr->sh_info) 10439 r_symndx = 0; 10440 rel->r_addend = htab->elf.tls_sec->vma + DTP_OFFSET; 10441 if (r_symndx != 0) 10442 rel->r_addend -= (local_syms[r_symndx].st_value 10443 + sec->output_offset 10444 + sec->output_section->vma); |
10204 } | 10445 } |
10205 else | 10446 else if (toc_symndx != 0) |
10206 { | 10447 { |
10207 /* LE */ 10208 insn1 = 0x3c6d0000; /* addis 3,13,0 */ 10209 insn2 = 0x38630000; /* addi 3,3,0 */ 10210 if (tls_gd == 0) 10211 { 10212 /* Was an LD reloc. */ 10213 r_symndx = 0; 10214 rel->r_addend = htab->elf.tls_sec->vma + DTP_OFFSET; 10215 rel[1].r_addend = htab->elf.tls_sec->vma + DTP_OFFSET; 10216 } 10217 else if (toc_symndx != 0) 10218 r_symndx = toc_symndx; 10219 r_type = R_PPC64_TPREL16_HA; 10220 rel->r_info = ELF64_R_INFO (r_symndx, r_type); | 10448 r_symndx = toc_symndx; 10449 rel->r_addend = toc_addend; 10450 } 10451 r_type = R_PPC64_TPREL16_HA; 10452 rel->r_info = ELF64_R_INFO (r_symndx, r_type); 10453 if (offset != (bfd_vma) -1) 10454 { |
10221 rel[1].r_info = ELF64_R_INFO (r_symndx, 10222 R_PPC64_TPREL16_LO); | 10455 rel[1].r_info = ELF64_R_INFO (r_symndx, 10456 R_PPC64_TPREL16_LO); |
10223 rel[1].r_offset += d_offset; | 10457 rel[1].r_offset = offset + d_offset; 10458 rel[1].r_addend = rel->r_addend; |
10224 } | 10459 } |
10460 } 10461 bfd_put_32 (output_bfd, insn1, 10462 contents + rel->r_offset - d_offset); 10463 if (offset != (bfd_vma) -1) 10464 { 10465 insn3 = bfd_get_32 (output_bfd, 10466 contents + offset + 4); |
|
10225 if (insn3 == NOP 10226 || insn3 == CROR_151515 || insn3 == CROR_313131) 10227 { | 10467 if (insn3 == NOP 10468 || insn3 == CROR_151515 || insn3 == CROR_313131) 10469 { |
10228 insn3 = insn2; 10229 insn2 = NOP; | |
10230 rel[1].r_offset += 4; | 10470 rel[1].r_offset += 4; |
10471 bfd_put_32 (output_bfd, insn2, contents + offset + 4); 10472 insn2 = NOP; |
|
10231 } | 10473 } |
10232 bfd_put_32 (output_bfd, insn1, contents + rel->r_offset - d_offset); | |
10233 bfd_put_32 (output_bfd, insn2, contents + offset); | 10474 bfd_put_32 (output_bfd, insn2, contents + offset); |
10234 bfd_put_32 (output_bfd, insn3, contents + offset + 4); 10235 if (tls_gd == 0 || toc_symndx != 0) | 10475 } 10476 if ((tls_mask & tls_gd) == 0 10477 && (tls_gd == 0 || toc_symndx != 0)) 10478 { 10479 /* We changed the symbol. Start over in order 10480 to get h, sym, sec etc. right. */ 10481 rel--; 10482 continue; 10483 } 10484 } 10485 break; 10486 10487 case R_PPC64_TLSGD: 10488 if (tls_mask != 0 && (tls_mask & TLS_GD) == 0) 10489 { 10490 unsigned int insn2, insn3; 10491 bfd_vma offset = rel->r_offset; 10492 10493 if ((tls_mask & TLS_TPRELGD) != 0) 10494 { 10495 /* IE */ 10496 r_type = R_PPC64_NONE; 10497 insn2 = 0x7c636a14; /* add 3,3,13 */ 10498 } 10499 else 10500 { 10501 /* LE */ 10502 if (toc_symndx != 0) |
10236 { | 10503 { |
10237 /* We changed the symbol. Start over in order 10238 to get h, sym, sec etc. right. */ 10239 rel--; 10240 continue; | 10504 r_symndx = toc_symndx; 10505 rel->r_addend = toc_addend; |
10241 } | 10506 } |
10507 r_type = R_PPC64_TPREL16_LO; 10508 rel->r_offset = offset + d_offset; 10509 insn2 = 0x38630000; /* addi 3,3,0 */ |
|
10242 } | 10510 } |
10511 rel->r_info = ELF64_R_INFO (r_symndx, r_type); 10512 /* Zap the reloc on the _tls_get_addr call too. */ 10513 BFD_ASSERT (offset == rel[1].r_offset); 10514 rel[1].r_info = ELF64_R_INFO (ELF64_R_SYM (rel[1].r_info), 10515 R_PPC64_NONE); 10516 insn3 = bfd_get_32 (output_bfd, 10517 contents + offset + 4); 10518 if (insn3 == NOP 10519 || insn3 == CROR_151515 || insn3 == CROR_313131) 10520 { 10521 rel->r_offset += 4; 10522 bfd_put_32 (output_bfd, insn2, contents + offset + 4); 10523 insn2 = NOP; 10524 } 10525 bfd_put_32 (output_bfd, insn2, contents + offset); 10526 if ((tls_mask & TLS_TPRELGD) == 0 && toc_symndx != 0) 10527 { 10528 rel--; 10529 continue; 10530 } |
|
10243 } 10244 break; 10245 | 10531 } 10532 break; 10533 |
10534 case R_PPC64_TLSLD: 10535 if (tls_mask != 0 && (tls_mask & TLS_LD) == 0) 10536 { 10537 unsigned int insn2, insn3; 10538 bfd_vma offset = rel->r_offset; 10539 10540 if (toc_symndx) 10541 sec = local_sections[toc_symndx]; 10542 for (r_symndx = 0; 10543 r_symndx < symtab_hdr->sh_info; 10544 r_symndx++) 10545 if (local_sections[r_symndx] == sec) 10546 break; 10547 if (r_symndx >= symtab_hdr->sh_info) 10548 r_symndx = 0; 10549 rel->r_addend = htab->elf.tls_sec->vma + DTP_OFFSET; 10550 if (r_symndx != 0) 10551 rel->r_addend -= (local_syms[r_symndx].st_value 10552 + sec->output_offset 10553 + sec->output_section->vma); 10554 10555 r_type = R_PPC64_TPREL16_LO; 10556 rel->r_info = ELF64_R_INFO (r_symndx, r_type); 10557 rel->r_offset = offset + d_offset; 10558 /* Zap the reloc on the _tls_get_addr call too. */ 10559 BFD_ASSERT (offset == rel[1].r_offset); 10560 rel[1].r_info = ELF64_R_INFO (ELF64_R_SYM (rel[1].r_info), 10561 R_PPC64_NONE); 10562 insn2 = 0x38630000; /* addi 3,3,0 */ 10563 insn3 = bfd_get_32 (output_bfd, 10564 contents + offset + 4); 10565 if (insn3 == NOP 10566 || insn3 == CROR_151515 || insn3 == CROR_313131) 10567 { 10568 rel->r_offset += 4; 10569 bfd_put_32 (output_bfd, insn2, contents + offset + 4); 10570 insn2 = NOP; 10571 } 10572 bfd_put_32 (output_bfd, insn2, contents + offset); 10573 rel--; 10574 continue; 10575 } 10576 break; 10577 |
|
10246 case R_PPC64_DTPMOD64: 10247 if (rel + 1 < relend 10248 && rel[1].r_info == ELF64_R_INFO (r_symndx, R_PPC64_DTPREL64) 10249 && rel[1].r_offset == rel->r_offset + 8) 10250 { 10251 if ((tls_mask & TLS_GD) == 0) 10252 { 10253 rel[1].r_info = ELF64_R_INFO (r_symndx, R_PPC64_NONE); --- 237 unchanged lines hidden (view full) --- 10491 input_bfd, (int) r_type, sym_name); 10492 10493 bfd_set_error (bfd_error_bad_value); 10494 ret = FALSE; 10495 continue; 10496 10497 case R_PPC64_NONE: 10498 case R_PPC64_TLS: | 10578 case R_PPC64_DTPMOD64: 10579 if (rel + 1 < relend 10580 && rel[1].r_info == ELF64_R_INFO (r_symndx, R_PPC64_DTPREL64) 10581 && rel[1].r_offset == rel->r_offset + 8) 10582 { 10583 if ((tls_mask & TLS_GD) == 0) 10584 { 10585 rel[1].r_info = ELF64_R_INFO (r_symndx, R_PPC64_NONE); --- 237 unchanged lines hidden (view full) --- 10823 input_bfd, (int) r_type, sym_name); 10824 10825 bfd_set_error (bfd_error_bad_value); 10826 ret = FALSE; 10827 continue; 10828 10829 case R_PPC64_NONE: 10830 case R_PPC64_TLS: |
10831 case R_PPC64_TLSGD: 10832 case R_PPC64_TLSLD: |
|
10499 case R_PPC64_GNU_VTINHERIT: 10500 case R_PPC64_GNU_VTENTRY: 10501 continue; 10502 10503 /* GOT16 relocations. Like an ADDR16 using the symbol's 10504 address in the GOT as relocation value instead of the 10505 symbol's value itself. Also, create a GOT entry for the 10506 symbol and put the symbol value there. */ --- 98 unchanged lines hidden (view full) --- 10605 { 10606 /* Generate relocs for the dynamic linker, except in 10607 the case of TLSLD where we'll use one entry per 10608 module. */ 10609 asection *relgot = ppc64_elf_tdata (input_bfd)->relgot; 10610 10611 *offp = off | 1; 10612 if ((info->shared || indx != 0) | 10833 case R_PPC64_GNU_VTINHERIT: 10834 case R_PPC64_GNU_VTENTRY: 10835 continue; 10836 10837 /* GOT16 relocations. Like an ADDR16 using the symbol's 10838 address in the GOT as relocation value instead of the 10839 symbol's value itself. Also, create a GOT entry for the 10840 symbol and put the symbol value there. */ --- 98 unchanged lines hidden (view full) --- 10939 { 10940 /* Generate relocs for the dynamic linker, except in 10941 the case of TLSLD where we'll use one entry per 10942 module. */ 10943 asection *relgot = ppc64_elf_tdata (input_bfd)->relgot; 10944 10945 *offp = off | 1; 10946 if ((info->shared || indx != 0) |
10613 && (h == NULL | 10947 && (offp == &ppc64_tlsld_got (input_bfd)->offset 10948 || h == NULL |
10614 || ELF_ST_VISIBILITY (h->elf.other) == STV_DEFAULT 10615 || h->elf.root.type != bfd_link_hash_undefweak)) 10616 { 10617 outrel.r_offset = (got->output_section->vma 10618 + got->output_offset 10619 + off); 10620 outrel.r_addend = addend; 10621 if (tls_type & (TLS_LD | TLS_GD)) --- 227 unchanged lines hidden (view full) --- 10849 10850 if (NO_OPD_RELOCS && is_opd) 10851 break; 10852 10853 if ((info->shared 10854 && (h == NULL 10855 || ELF_ST_VISIBILITY (h->elf.other) == STV_DEFAULT 10856 || h->elf.root.type != bfd_link_hash_undefweak) | 10949 || ELF_ST_VISIBILITY (h->elf.other) == STV_DEFAULT 10950 || h->elf.root.type != bfd_link_hash_undefweak)) 10951 { 10952 outrel.r_offset = (got->output_section->vma 10953 + got->output_offset 10954 + off); 10955 outrel.r_addend = addend; 10956 if (tls_type & (TLS_LD | TLS_GD)) --- 227 unchanged lines hidden (view full) --- 11184 11185 if (NO_OPD_RELOCS && is_opd) 11186 break; 11187 11188 if ((info->shared 11189 && (h == NULL 11190 || ELF_ST_VISIBILITY (h->elf.other) == STV_DEFAULT 11191 || h->elf.root.type != bfd_link_hash_undefweak) |
10857 && (MUST_BE_DYN_RELOC (r_type) | 11192 && (must_be_dyn_reloc (info, r_type) |
10858 || !SYMBOL_CALLS_LOCAL (info, &h->elf))) 10859 || (ELIMINATE_COPY_RELOCS 10860 && !info->shared 10861 && h != NULL 10862 && h->elf.dynindx != -1 10863 && !h->elf.non_got_ref 10864 && h->elf.def_dynamic 10865 && !h->elf.def_regular)) --- 68 unchanged lines hidden (view full) --- 10934 for relocs. This make all RELATIVE relocs have 10935 *r_offset equal to r_addend. */ 10936 relocate = TRUE; 10937 } 10938 else 10939 { 10940 long indx = 0; 10941 | 11193 || !SYMBOL_CALLS_LOCAL (info, &h->elf))) 11194 || (ELIMINATE_COPY_RELOCS 11195 && !info->shared 11196 && h != NULL 11197 && h->elf.dynindx != -1 11198 && !h->elf.non_got_ref 11199 && h->elf.def_dynamic 11200 && !h->elf.def_regular)) --- 68 unchanged lines hidden (view full) --- 11269 for relocs. This make all RELATIVE relocs have 11270 *r_offset equal to r_addend. */ 11271 relocate = TRUE; 11272 } 11273 else 11274 { 11275 long indx = 0; 11276 |
10942 if (bfd_is_abs_section (sec)) | 11277 if (r_symndx == 0 || bfd_is_abs_section (sec)) |
10943 ; 10944 else if (sec == NULL || sec->owner == NULL) 10945 { 10946 bfd_set_error (bfd_error_bad_value); 10947 return FALSE; 10948 } 10949 else 10950 { --- 550 unchanged lines hidden --- | 11278 ; 11279 else if (sec == NULL || sec->owner == NULL) 11280 { 11281 bfd_set_error (bfd_error_bad_value); 11282 return FALSE; 11283 } 11284 else 11285 { --- 550 unchanged lines hidden --- |