+2019-10-04 Alan Modra <amodra@gmail.com>
+
+ * elf64-ppc.c (ppc64_elf_check_relocs): Move initialisation of vars.
+ (ppc64_elf_tls_optimize): Correct is_local condition.
+ (allocate_got): Don't reserve dynamic relocations for any of the
+ tls got relocs in PIEs when the symbol is local.
+ (allocate_dynrelocs): Correct validity test for local sym using
+ tlsld_got slot.
+ (ppc64_elf_size_dynamic_sections): Don't reserve dynamic relocations
+ for any of the tls got relocs in PIEs.
+ (ppc64_elf_layout_multitoc): Likewise.
+ (ppc64_elf_relocate_section): Correct validity test for local sym
+ using tlsld_got slot. Don't emit dynamic relocations for any of
+ the tls got relocs in PIEs when the symbol is local.
+ * elf32-ppc.c (ppc_elf_tls_optimize): Correct is_local condition.
+ (got_relocs_needed): Delete.
+ (allocate_dynrelocs): Correct validity test for local sym using
+ tlsld_got slot. Don't reserve dynamic relocations for any of the
+ tls got relocs in PIEs when the symbol is local.
+ (ppc_elf_size_dynamic_sections): Don't reserve dynamic relocations
+ for any of the tls got relocs in PIEs.
+ (ppc_elf_relocate_section): Correct validity test for local sym
+ using tlsld_got slot. Don't emit dynamic relocations for any of
+ the tls got relocs in PIEs when the symbol is local.
+
2019-10-04 Szabolcs Nagy <szabolcs.nagy@arm.com>
PR ld/22263
h = (struct elf_link_hash_entry *) h->root.u.i.link;
}
- is_local = FALSE;
- if (h == NULL
- || !h->def_dynamic)
- is_local = TRUE;
-
+ is_local = SYMBOL_REFERENCES_LOCAL (info, h);
r_type = ELF32_R_TYPE (rel->r_info);
/* If this section has old-style __tls_get_addr calls
without marker relocs, then check that each
return need;
}
-/* Calculate size of relocs needed for symbol given its TLS_MASK and
- NEEDed GOT entries. KNOWN says a TPREL offset can be calculated at
- link time. */
-
-static inline unsigned int
-got_relocs_needed (int tls_mask, unsigned int need, bfd_boolean known)
-{
- /* All the entries we allocated need relocs.
- Except IE in executable with a local symbol. We could also omit
- the DTPREL reloc on the second word of a GD entry under the same
- condition as that for IE, but ld.so needs to differentiate
- LD and GD entries. */
- if (known && (tls_mask & TLS_TLS) != 0
- && (tls_mask & (TLS_TPREL | TLS_GDIE)) != 0)
- need -= 4;
- return need * sizeof (Elf32_External_Rela) / 4;
-}
-
/* If H is undefined, make it dynamic if that makes sense. */
static bfd_boolean
need = 0;
if ((eh->tls_mask & (TLS_TLS | TLS_LD)) == (TLS_TLS | TLS_LD))
{
- if (!eh->elf.def_dynamic)
+ if (SYMBOL_REFERENCES_LOCAL (info, &eh->elf))
/* We'll just use htab->tlsld_got.offset. This should
always be the case. It's a little odd if we have
a local dynamic reloc against a non-local symbol. */
else
{
eh->elf.got.offset = allocate_got (htab, need);
- if ((bfd_link_pic (info)
+ if (((bfd_link_pic (info)
+ && !((eh->tls_mask & TLS_TLS) != 0
+ && bfd_link_executable (info)
+ && SYMBOL_REFERENCES_LOCAL (info, &eh->elf)))
|| (htab->elf.dynamic_sections_created
&& eh->elf.dynindx != -1
&& !SYMBOL_REFERENCES_LOCAL (info, &eh->elf)))
&& !UNDEFWEAK_NO_DYNAMIC_RELOC (info, &eh->elf))
{
asection *rsec;
- bfd_boolean tprel_known = (bfd_link_executable (info)
- && SYMBOL_REFERENCES_LOCAL (info,
- &eh->elf));
- need = got_relocs_needed (eh->tls_mask, need, tprel_known);
- if ((eh->tls_mask & (TLS_TLS | TLS_LD)) == (TLS_TLS | TLS_LD)
- && eh->elf.def_dynamic)
+ need *= sizeof (Elf32_External_Rela) / 4;
+ if ((eh->tls_mask & (TLS_TLS | TLS_LD)) == (TLS_TLS | TLS_LD))
need -= sizeof (Elf32_External_Rela);
rsec = htab->elf.srelgot;
if (eh->elf.type == STT_GNU_IFUNC)
else
{
*local_got = allocate_got (htab, need);
- if (bfd_link_pic (info))
+ if (bfd_link_pic (info)
+ && !((*lgot_masks & TLS_TLS) != 0
+ && bfd_link_executable (info)))
{
asection *srel;
- bfd_boolean tprel_known = bfd_link_executable (info);
- need = got_relocs_needed (*lgot_masks, need, tprel_known);
+ need *= sizeof (Elf32_External_Rela) / 4;
srel = htab->elf.srelgot;
if ((*lgot_masks & (TLS_TLS | PLT_IFUNC)) == PLT_IFUNC)
srel = htab->elf.irelplt;
if (htab->tlsld_got.refcount > 0)
{
htab->tlsld_got.offset = allocate_got (htab, 8);
- if (bfd_link_pic (info))
+ if (bfd_link_dll (info))
htab->elf.srelgot->size += sizeof (Elf32_External_Rela);
}
else
indx = 0;
if (tls_type == (TLS_TLS | TLS_LD)
- && (h == NULL
- || !h->def_dynamic))
+ && SYMBOL_REFERENCES_LOCAL (info, h))
offp = &htab->tlsld_got.offset;
else if (h != NULL)
{
if (offp == &htab->tlsld_got.offset)
tls_m = TLS_LD;
- else if (h == NULL
- || !h->def_dynamic)
+ else if ((tls_m & TLS_LD) != 0
+ && SYMBOL_REFERENCES_LOCAL (info, h))
tls_m &= ~TLS_LD;
/* We might have multiple got entries for this sym.
if (indx != 0
|| (bfd_link_pic (info)
&& (h == NULL
- || !UNDEFWEAK_NO_DYNAMIC_RELOC (info, h)
- || offp == &htab->tlsld_got.offset)
- && !(tls_ty == (TLS_TLS | TLS_TPREL)
+ || !UNDEFWEAK_NO_DYNAMIC_RELOC (info, h))
+ && !(tls_ty != 0
&& bfd_link_executable (info)
&& SYMBOL_REFERENCES_LOCAL (info, h))))
{
if (tls_type != (TLS_TLS | TLS_LD))
{
if ((tls_mask & TLS_LD) != 0
- && !(h == NULL
- || !h->def_dynamic))
+ && !SYMBOL_REFERENCES_LOCAL (info, h))
off += 8;
if (tls_type != (TLS_TLS | TLS_GD))
{
sec->has_toc_reloc = 1;
}
- tls_type = 0;
- ifunc = NULL;
r_type = ELF64_R_TYPE (rel->r_info);
switch (r_type)
{
break;
}
+ ifunc = NULL;
if (h != NULL)
{
if (h->type == STT_GNU_IFUNC)
}
}
+ tls_type = 0;
switch (r_type)
{
case R_PPC64_TLSGD:
value = sym->st_value;
ok_tprel = FALSE;
- is_local = FALSE;
- if (h == NULL
- || !h->def_dynamic)
+ is_local = SYMBOL_REFERENCES_LOCAL (info, h);
+ if (is_local)
{
- is_local = TRUE;
if (h != NULL
&& h->root.type == bfd_link_hash_undefweak)
ok_tprel = TRUE;
htab->got_reli_size += rentsize;
}
else if (((bfd_link_pic (info)
- && !((gent->tls_type & TLS_TPREL) != 0
+ && !(gent->tls_type != 0
&& bfd_link_executable (info)
&& SYMBOL_REFERENCES_LOCAL (info, h)))
|| (htab->elf.dynamic_sections_created
if (gent->got.refcount > 0)
{
if ((gent->tls_type & TLS_LD) != 0
- && !h->def_dynamic)
+ && SYMBOL_REFERENCES_LOCAL (info, h))
{
ppc64_tlsld_got (gent->owner)->got.refcount += 1;
*pgent = gent->next;
htab->elf.irelplt->size += rel_size;
htab->got_reli_size += rel_size;
}
- else if (bfd_link_pic (info)
- && !((ent->tls_type & TLS_TPREL) != 0
- && bfd_link_executable (info)))
+ else if (bfd_link_dll (info))
{
asection *srel = ppc64_elf_tdata (ibfd)->relgot;
srel->size += rel_size;
ent->got.offset = s->size;
ent->owner = ibfd;
s->size += 16;
- if (bfd_link_pic (info))
+ if (bfd_link_dll (info))
{
asection *srel = ppc64_elf_tdata (ibfd)->relgot;
srel->size += sizeof (Elf64_External_Rela);
htab->got_reli_size += rel_size;
}
else if (bfd_link_pic (info)
- && !((ent->tls_type & TLS_TPREL) != 0
+ && !(ent->tls_type != 0
&& bfd_link_executable (info)))
{
asection *srel = ppc64_elf_tdata (ibfd)->relgot;
asection *s = ppc64_elf_tdata (ibfd)->got;
ent->got.offset = s->size;
s->size += 16;
- if (bfd_link_pic (info))
+ if (bfd_link_dll (info))
{
asection *srel = ppc64_elf_tdata (ibfd)->relgot;
srel->size += sizeof (Elf64_External_Rela);
struct got_entry *ent;
if (tls_type == (TLS_TLS | TLS_LD)
- && (h == NULL
- || !h->elf.def_dynamic))
+ && SYMBOL_REFERENCES_LOCAL (info, &h->elf))
ent = ppc64_tlsld_got (input_bfd);
else
{
else if (indx != 0
|| (bfd_link_pic (info)
&& (h == NULL
- || !UNDEFWEAK_NO_DYNAMIC_RELOC (info, &h->elf)
- || (tls_type == (TLS_TLS | TLS_LD)
- && !h->elf.def_dynamic))
- && !(tls_type == (TLS_TLS | TLS_TPREL)
+ || !UNDEFWEAK_NO_DYNAMIC_RELOC (info, &h->elf))
+ && !(tls_type != 0
&& bfd_link_executable (info)
&& SYMBOL_REFERENCES_LOCAL (info, &h->elf))))
relgot = ppc64_elf_tdata (ent->owner)->relgot;
+2019-10-04 Alan Modra <amodra@gmail.com>
+
+ * testsuite/ld-powerpc/tlsso.d: Adjust to suit tlsld_got usage change.
+ * testsuite/ld-powerpc/tlsso.g: Likewise.
+ * testsuite/ld-powerpc/tlsso.r: Likewise.
+ * testsuite/ld-powerpc/tlsso32.d: Likewise.
+ * testsuite/ld-powerpc/tlsso32.g: Likewise.
+ * testsuite/ld-powerpc/tlsso32.r: Likewise.
+
2019-10-04 Szabolcs Nagy <szabolcs.nagy@arm.com>
PR ld/25062
.* <.*plt_call\.__tls_get_addr(|_opt)>:
.* (f8 41 00 28|28 00 41 f8) std r2,40\(r1\)
-.* (e9 82 80 78|78 80 82 e9) ld r12,-32648\(r2\)
+.* (e9 82 80 98|98 80 82 e9) ld r12,-32616\(r2\)
.* (7d 89 03 a6|a6 03 89 7d) mtctr r12
-.* (e8 42 80 80|80 80 42 e8) ld r2,-32640\(r2\)
+.* (e8 42 80 a0|a0 80 42 e8) ld r2,-32608\(r2\)
.* (28 22 00 00|00 00 22 28) cmpldi r2,0
.* (4c e2 04 20|20 04 e2 4c) bnectr\+ *
.* (48 00 00 ..|.. 00 00 48) b .* <__tls_get_addr@plt>
.* (38 62 80 20|20 80 62 38) addi r3,r2,-32736
.* (4b ff ff ..|.. ff ff 4b) bl .*plt_call.__tls_get_addr.*
.* (e8 41 00 28|28 00 41 e8) ld r2,40\(r1\)
-.* (38 62 80 50|50 80 62 38) addi r3,r2,-32688
+.* (38 62 80 40|40 80 62 38) addi r3,r2,-32704
.* (4b ff ff ..|.. ff ff 4b) bl .*plt_call.__tls_get_addr.*
.* (e8 41 00 28|28 00 41 e8) ld r2,40\(r1\)
-.* (38 62 80 38|38 80 62 38) addi r3,r2,-32712
+.* (38 62 80 58|58 80 62 38) addi r3,r2,-32680
.* (4b ff ff ..|.. ff ff 4b) bl .*plt_call.__tls_get_addr.*
.* (e8 41 00 28|28 00 41 e8) ld r2,40\(r1\)
-.* (38 62 80 50|50 80 62 38) addi r3,r2,-32688
+.* (38 62 80 30|30 80 62 38) addi r3,r2,-32720
.* (4b ff ff ..|.. ff ff 4b) bl .*plt_call.__tls_get_addr.*
.* (e8 41 00 28|28 00 41 e8) ld r2,40\(r1\)
.* (39 23 80 40|40 80 23 39) addi r9,r3,-32704
.* (3d 23 00 00|00 00 23 3d) addis r9,r3,0
.* (81 49 80 48|48 80 49 81) lwz r10,-32696\(r9\)
-.* (e9 22 80 30|30 80 22 e9) ld r9,-32720\(r2\)
+.* (e9 22 80 50|50 80 22 e9) ld r9,-32688\(r2\)
.* (7d 49 18 2a|2a 18 49 7d) ldx r10,r9,r3
-.* (e9 22 80 48|48 80 22 e9) ld r9,-32696\(r2\)
+.* (e9 22 80 68|68 80 22 e9) ld r9,-32664\(r2\)
.* (7d 49 6a 2e|2e 6a 49 7d) lhzx r10,r9,r13
.* (89 4d 00 00|00 00 4d 89) lbz r10,0\(r13\)
.* (3d 2d 00 00|00 00 2d 3d) addis r9,r13,0
.* (38 62 80 08|08 80 62 38) addi r3,r2,-32760
.* (4b ff ff ..|.. ff ff 4b) bl .*plt_call.__tls_get_addr.*
.* (e8 41 00 28|28 00 41 e8) ld r2,40\(r1\)
-.* (38 62 80 50|50 80 62 38) addi r3,r2,-32688
+.* (38 62 80 70|70 80 62 38) addi r3,r2,-32656
.* (4b ff ff ..|.. ff ff 4b) bl .*plt_call.__tls_get_addr.*
.* (e8 41 00 28|28 00 41 e8) ld r2,40\(r1\)
.* (f9 43 80 08|08 80 43 f9) std r10,-32760\(r3\)
.* (91 49 80 10|10 80 49 91) stw r10,-32752\(r9\)
.* (e9 22 80 18|18 80 22 e9) ld r9,-32744\(r2\)
.* (7d 49 19 2a|2a 19 49 7d) stdx r10,r9,r3
-.* (e9 22 80 48|48 80 22 e9) ld r9,-32696\(r2\)
+.* (e9 22 80 68|68 80 22 e9) ld r9,-32664\(r2\)
.* (7d 49 6b 2e|2e 6b 49 7d) sthx r10,r9,r13
.* (e9 4d 00 02|02 00 4d e9) lwa r10,0\(r13\)
.* (3d 2d 00 00|00 00 2d 3d) addis r9,r13,0
.* 00000000 00000000 00000000 00000000 .*
.* 00000000 00000000 00000000 00000000 .*
.* 00000000 00000000 00000000 00000000 .*
+.* 00000000 00000000 00000000 00000000 .*
+.* 00000000 00000000 00000000 00000000 .*
+02 +\.dynamic *
+03 +\.tdata \.tbss *
-Relocation section '\.rela\.dyn' at offset .* contains 18 entries:
+Relocation section '\.rela\.dyn' at offset .* contains 20 entries:
+Offset +Info +Type +Symbol's Value +Symbol's Name \+ Addend
-[0-9a-f ]+R_PPC64_RELATIVE +4fc
+[0-9a-f ]+R_PPC64_RELATIVE +51c
[0-9a-f ]+R_PPC64_RELATIVE +18800
[0-9a-f ]+R_PPC64_TPREL16 +0+60 le0 \+ 0
[0-9a-f ]+R_PPC64_TPREL16_HA +0+68 le1 \+ 0
[0-9a-f ]+R_PPC64_DTPMOD64 +0
[0-9a-f ]+R_PPC64_DTPMOD64 +0+ gd \+ 0
[0-9a-f ]+R_PPC64_DTPREL64 +0+ gd \+ 0
+[0-9a-f ]+R_PPC64_DTPMOD64 +0+40 ld0 \+ 0
+[0-9a-f ]+R_PPC64_DTPMOD64 +0+ ld \+ 0
[0-9a-f ]+R_PPC64_DTPREL64 +0+50 ld2 \+ 0
[0-9a-f ]+R_PPC64_DTPMOD64 +0+38 gd0 \+ 0
[0-9a-f ]+R_PPC64_DTPREL64 +0+38 gd0 \+ 0
.*: (7f c8 02 a6|a6 02 c8 7f) mflr r30
.*: (3f de 00 02|02 00 de 3f) addis r30,r30,2
.*: (3b de 80 e8|e8 80 de 3b) addi r30,r30,-32536
-.*: (38 7f ff e4|e4 ff 7f 38) addi r3,r31,-28
+.*: (38 7f ff d4|d4 ff 7f 38) addi r3,r31,-44
.*: (48 00 00 01|01 00 00 48) bl .*
-.*: (38 7f ff f8|f8 ff 7f 38) addi r3,r31,-8
+.*: (38 7f ff e4|e4 ff 7f 38) addi r3,r31,-28
.*: (48 00 00 01|01 00 00 48) bl .*
.*: (38 7f ff ec|ec ff 7f 38) addi r3,r31,-20
.*: (48 00 00 5d|5d 00 00 48) bl .*<0+8000\.got2\.plt_pic32\.__tls_get_addr>
-.*: (38 7f ff f8|f8 ff 7f 38) addi r3,r31,-8
+.*: (38 7f ff dc|dc ff 7f 38) addi r3,r31,-36
.*: (48 00 00 55|55 00 00 48) bl .*<0+8000\.got2\.plt_pic32\.__tls_get_addr>
.*: (39 23 80 20|20 80 23 39) addi r9,r3,-32736
.*: (3d 23 00 00|00 00 23 3d) addis r9,r3,0
.*: (89 42 00 00|00 00 42 89) lbz r10,0\(r2\)
.*: (3d 22 00 00|00 00 22 3d) addis r9,r2,0
.*: (99 49 00 00|00 00 49 99) stb r10,0\(r9\)
-.*: (38 7e ff dc|dc ff 7e 38) addi r3,r30,-36
+.*: (38 7e ff cc|cc ff 7e 38) addi r3,r30,-52
.*: (48 00 00 01|01 00 00 48) bl .*
.*: (38 7e ff f8|f8 ff 7e 38) addi r3,r30,-8
.*: (48 00 00 01|01 00 00 48) bl .*
.*: (a9 49 00 00|00 00 49 a9) lha r10,0\(r9\)
.* <00008000.got2.plt_pic32.__tls_get_addr>:
-.*: (81 7e 80 d8|d8 80 7e 81) lwz r11,-32552\(r30\)
+.*: (81 7e 80 e8|e8 80 7e 81) lwz r11,-32536\(r30\)
.*: (7d 69 03 a6|a6 03 69 7d) mtctr r11
.*: (4e 80 04 20|20 04 80 4e) bctr
.*: (60 00 00 00|00 00 00 60) nop
.*: (7c 08 03 a6|a6 03 08 7c) mtlr r0
.*: (7d 6c 58 50|50 58 6c 7d) subf r11,r12,r11
.*: (3d 8c 00 01|01 00 8c 3d) addis r12,r12,1
-.*: (80 0c 01 20|20 01 0c 80) lwz r0,288\(r12\)
-.*: (81 8c 01 24|24 01 8c 81) lwz r12,292\(r12\)
+.*: (80 0c 01 30|30 01 0c 80) lwz r0,304\(r12\)
+.*: (81 8c 01 34|34 01 8c 81) lwz r12,308\(r12\)
.*: (7c 09 03 a6|a6 03 09 7c) mtctr r0
.*: (7c 0b 5a 14|14 5a 0b 7c) add r0,r11,r11
.*: (7d 60 5a 14|14 5a 60 7d) add r11,r0,r11
Contents of section \.got:
.* 00000000 00000000 00000000 00000000 .*
.* 00000000 00000000 00000000 00000000 .*
-.* 00000000 (000103dc|dc030100) 00000000 00000000 .*
+.* 00000000 00000000 00000000 00000000 .*
+.* 00000000 (000103fc|fc030100) 00000000 00000000 .*
+\[[ 0-9]+\] \.tdata +PROGBITS .* 0+1c 0+ WAT +0 +0 +4
+\[[ 0-9]+\] \.tbss +NOBITS .* 0+1c 0+ WAT +0 +0 +4
+\[[ 0-9]+\] \.dynamic +DYNAMIC .* 08 +WA +3 +0 +4
- +\[[ 0-9]+\] \.got +PROGBITS .* 0+30 04 +WA +0 +0 +4
+ +\[[ 0-9]+\] \.got +PROGBITS .* 0+40 04 +WA +0 +0 +4
+\[[ 0-9]+\] \.plt +PROGBITS .* 0+4 00 +WA +0 +0 +4
+\[[ 0-9]+\] \.symtab +.*
+\[[ 0-9]+\] \.strtab +.*
+02 +\.dynamic
+03 +\.tdata \.tbss
-Relocation section '\.rela\.dyn' at offset 0x[0-9a-f]+ contains 18 entries:
+Relocation section '\.rela\.dyn' at offset 0x[0-9a-f]+ contains 20 entries:
Offset +Info +Type +Sym\. Value +Symbol's Name \+ Addend
[0-9a-f ]+R_PPC_REL24 +0+ +__tls_get_addr \+ 0
[0-9a-f ]+R_PPC_REL24 +0+ +__tls_get_addr \+ 0
[0-9a-f ]+R_PPC_DTPMOD32 +0
[0-9a-f ]+R_PPC_DTPMOD32 +0+ +gd \+ 0
[0-9a-f ]+R_PPC_DTPREL32 +0+ +gd \+ 0
+[0-9a-f ]+R_PPC_DTPMOD32 +0+20 +ld0 \+ 0
+[0-9a-f ]+R_PPC_DTPMOD32 +0+ +ld \+ 0
[0-9a-f ]+R_PPC_DTPMOD32 +0+1c +gd0 \+ 0
[0-9a-f ]+R_PPC_DTPREL32 +0+1c +gd0 \+ 0
[0-9a-f ]+R_PPC_TPREL32 +0+2c +ie0 \+ 0