aboutsummaryrefslogtreecommitdiff
path: root/bfd
diff options
context:
space:
mode:
authorAlan Modra <amodra@gmail.com>2019-10-04 08:48:41 +0930
committerAlan Modra <amodra@gmail.com>2019-10-04 22:53:56 +0930
commitf749f26eea052459c27e21d0d15f5fac060961dc (patch)
treea3f3e0e4355e7c712c31228440c20948c0e46e1b /bfd
parent9cb09e33e04feb12df2aaa6e81d61b82ad609ce5 (diff)
downloadgdb-f749f26eea052459c27e21d0d15f5fac060961dc.zip
gdb-f749f26eea052459c27e21d0d15f5fac060961dc.tar.gz
gdb-f749f26eea052459c27e21d0d15f5fac060961dc.tar.bz2
PowerPC PIC vs. DLL TLS issues
1) GOT entries generated for any of the GOT TLS relocations don't need dynamic relocations for locally defined symbols in PIEs. In the case of a tls_index doubleword, the dtpmod entry is known to be 1, and the dtprel entry is also known at link time and relative. Similarly, dtprel and tprel words are known at link time and relative. (GOT entries for other than TLS symbols are not relative and thus need dynamic relocations in PIEs.) 2) Local dynamic TLS code is really only meant for accesses local to the current binary. There was a cheapskate test for this before using the common tlsld_got slot, but the test wasn't exactly correct and might confuse anyone looking at the code. The proper test, SYMBOL_REFERENCES_LOCAL isn't so expensive that it should be avoided. 3) The same cheap test for local syms when optimising TLS sequences should be SYMBOL_REFERENCES_LOCAL too. bfd/ * 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. ld/ * 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.
Diffstat (limited to 'bfd')
-rw-r--r--bfd/ChangeLog25
-rw-r--r--bfd/elf32-ppc.c63
-rw-r--r--bfd/elf64-ppc.c33
3 files changed, 57 insertions, 64 deletions
diff --git a/bfd/ChangeLog b/bfd/ChangeLog
index a2e3bb0..09f34ed 100644
--- a/bfd/ChangeLog
+++ b/bfd/ChangeLog
@@ -1,3 +1,28 @@
+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
diff --git a/bfd/elf32-ppc.c b/bfd/elf32-ppc.c
index 9765a33..89d1e94 100644
--- a/bfd/elf32-ppc.c
+++ b/bfd/elf32-ppc.c
@@ -4455,11 +4455,7 @@ ppc_elf_tls_optimize (bfd *obfd ATTRIBUTE_UNUSED,
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
@@ -5049,24 +5045,6 @@ got_entries_needed (int tls_mask)
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
@@ -5119,7 +5097,7 @@ allocate_dynrelocs (struct elf_link_hash_entry *h, void *inf)
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. */
@@ -5133,20 +5111,19 @@ allocate_dynrelocs (struct elf_link_hash_entry *h, void *inf)
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)
@@ -5594,12 +5571,13 @@ ppc_elf_size_dynamic_sections (bfd *output_bfd,
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;
@@ -5676,7 +5654,7 @@ ppc_elf_size_dynamic_sections (bfd *output_bfd,
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
@@ -7749,8 +7727,7 @@ ppc_elf_relocate_section (bfd *output_bfd,
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)
{
@@ -7792,8 +7769,8 @@ ppc_elf_relocate_section (bfd *output_bfd,
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.
@@ -7827,9 +7804,8 @@ ppc_elf_relocate_section (bfd *output_bfd,
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))))
{
@@ -7939,8 +7915,7 @@ ppc_elf_relocate_section (bfd *output_bfd,
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))
{
diff --git a/bfd/elf64-ppc.c b/bfd/elf64-ppc.c
index d5a46db..30b0742 100644
--- a/bfd/elf64-ppc.c
+++ b/bfd/elf64-ppc.c
@@ -4543,8 +4543,6 @@ ppc64_elf_check_relocs (bfd *abfd, struct bfd_link_info *info,
sec->has_toc_reloc = 1;
}
- tls_type = 0;
- ifunc = NULL;
r_type = ELF64_R_TYPE (rel->r_info);
switch (r_type)
{
@@ -4597,6 +4595,7 @@ ppc64_elf_check_relocs (bfd *abfd, struct bfd_link_info *info,
break;
}
+ ifunc = NULL;
if (h != NULL)
{
if (h->type == STT_GNU_IFUNC)
@@ -4622,6 +4621,7 @@ ppc64_elf_check_relocs (bfd *abfd, struct bfd_link_info *info,
}
}
+ tls_type = 0;
switch (r_type)
{
case R_PPC64_TLSGD:
@@ -7803,11 +7803,9 @@ ppc64_elf_tls_optimize (struct bfd_link_info *info)
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;
@@ -9278,7 +9276,7 @@ allocate_got (struct elf_link_hash_entry *h,
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
@@ -9384,7 +9382,7 @@ allocate_dynrelocs (struct elf_link_hash_entry *h, void *inf)
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;
@@ -9812,9 +9810,7 @@ ppc64_elf_size_dynamic_sections (bfd *output_bfd,
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;
@@ -9890,7 +9886,7 @@ ppc64_elf_size_dynamic_sections (bfd *output_bfd,
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);
@@ -12185,7 +12181,7 @@ ppc64_elf_layout_multitoc (struct bfd_link_info *info)
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;
@@ -12211,7 +12207,7 @@ ppc64_elf_layout_multitoc (struct bfd_link_info *info)
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);
@@ -15611,8 +15607,7 @@ ppc64_elf_relocate_section (bfd *output_bfd,
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
{
@@ -15687,10 +15682,8 @@ ppc64_elf_relocate_section (bfd *output_bfd,
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;