aboutsummaryrefslogtreecommitdiff
path: root/bfd/elf32-ppc.c
diff options
context:
space:
mode:
authorAlan Modra <amodra@gmail.com>2017-01-24 08:43:01 +1030
committerAlan Modra <amodra@gmail.com>2017-01-24 12:15:54 +1030
commitf0158f44168c29338e0b4424c69589f79bf58b19 (patch)
tree6dc86299e189f17a526e41b275c1be42d303a391 /bfd/elf32-ppc.c
parent741bcbe94d7811caa1efa500dacd047c428cce61 (diff)
downloadgdb-f0158f44168c29338e0b4424c69589f79bf58b19.zip
gdb-f0158f44168c29338e0b4424c69589f79bf58b19.tar.gz
gdb-f0158f44168c29338e0b4424c69589f79bf58b19.tar.bz2
PowerPC dynamic relocations
This patch fixes a number of issues with powerpc dynamic relocations. 1) Both ppc and ppc64 were emitting more dynamic symbols and relocations than necessary, due to not supporting static linker resolution of tls_index entries for __tls_get_addr_opt. This meant that any @got@tlsgd or @got@tlsld reloc needed to make their symbols dynamic and generate dptmod and dtprel relocs for the dynamic linker. That would have been passable, but what happened was that practically all @got relocations resulted in their symbols being made dynamic and dynamic relocations emitted against the GOT entries. (Mostly visible on ppc32 executables since ppc64 gcc really only uses @got style relocs for TLS.) 2) The PowerOpen syntax was not supported with __tls_get_addr_opt. DTPMOD/DTPREL relocs on tls_index TOC entries did not use the trick of forcing dynamic symbols and relocations so those entries always resulted in the full __tls_get_addr processing. gcc doesn't use the PowerOpen syntax for TLS, and normally such code would be optimized to TLS IE or LE so the impact of missing this support was minimal. 3) In an executable, relocations against GNU indirect functions always used the value of their PLT stub. While this is correct, it is better in some cases to use a dynamic relocation. An extra dynamic relocation can mean that calls via function pointers need not bounce through the PLT stub at runtime. The patch also tidies the PLT handling code in ppc32 allocate_dynrelocs. Allocating PLT entries after other dynamic relocs allows the PLT loop to omit special handling for undefined weak symbols, and that in turn allows the loop to be simplified. bfd/ * elf32-ppc.c (ppc_elf_adjust_dynamic_symbol): Merge two cases where dynamic relocs are preferable. Allow ifunc too. (ensure_undefweak_dynamic): New function. (allocate_dynrelocs): Use it here. Move plt handling last and don't make symbols dynamic, simplifying loop. Only make undef weak symbols with GOT entries dynamic. Correct condition for GOT relocs. Handle dynamic relocs on ifuncs. Correct comments. Remove goto. (ppc_elf_relocate_section): Correct test for using dynamic symbol on GOT relocs. Rearrange test for emitting GOT relocs to suit. Set up explicit tls_index entries and implicit GOT tls_index entries resolvable at link time for __tls_get_addr_opt. Simplify test to clear mem for prelink. * elf64-ppc.c (allocate_got): Correct condition for GOT relocs. (ensure_undefweak_dynamic): New function. (allocate_dynrelocs): Use it here. Only make undef weak symbols with GOT entries dynamic. Remove unnecessary test of WILL_CALL_FINISH_DYNAMIC_SYMBOL in PLT handling. (ppc64_elf_relocate_section): Correct test for using dynamic symbol on GOT relocs. Rearrange test for emitting GOT relocs to suit. Set up explicit tls_index entries and implicit GOT tls_index entries resolvable at link time for __tls_get_addr_opt. Simplify expression to clear mem for prelink. ld/ * testsuite/ld-powerpc/tlsexe.r: Update for fewer dynamic relocs and symbols. * testsuite/ld-powerpc/tlsexe.d: Likewise. * testsuite/ld-powerpc/tlsexe.g: Likewise.
Diffstat (limited to 'bfd/elf32-ppc.c')
-rw-r--r--bfd/elf32-ppc.c502
1 files changed, 254 insertions, 248 deletions
diff --git a/bfd/elf32-ppc.c b/bfd/elf32-ppc.c
index 989f785..7d69ea0 100644
--- a/bfd/elf32-ppc.c
+++ b/bfd/elf32-ppc.c
@@ -5684,33 +5684,24 @@ ppc_elf_adjust_dynamic_symbol (struct bfd_link_info *info,
/* Taking a function's address in a read/write section
doesn't require us to define the function symbol in the
executable on a plt call stub. A dynamic reloc can
- be used instead. */
- if (h->pointer_equality_needed
- && h->type != STT_GNU_IFUNC
+ be used instead, giving better runtime performance.
+ (Calls via that function pointer don't need to bounce
+ through the plt call stub.) Similarly, use a dynamic
+ reloc for a weak reference when possible, allowing the
+ resolution of the symbol to be set at load time rather
+ than link time. */
+ if ((h->pointer_equality_needed
+ || (!h->ref_regular_nonweak && h->non_got_ref))
&& !htab->is_vxworks
&& !ppc_elf_hash_entry (h)->has_sda_refs
&& !readonly_dynrelocs (h))
{
h->pointer_equality_needed = 0;
+ /* After adjust_dynamic_symbol, non_got_ref set in the
+ non-pic case means that dyn_relocs for this symbol
+ should be discarded. */
h->non_got_ref = 0;
}
-
- /* After adjust_dynamic_symbol, non_got_ref set in the
- non-shared case means that we have allocated space in
- .dynbss for the symbol and thus dyn_relocs for this
- symbol should be discarded.
- If we get here we know we are making a PLT entry for this
- symbol, and in an executable we'd normally resolve
- relocations against this symbol to the PLT entry. Allow
- dynamic relocs if the reference is weak, and the dynamic
- relocs will not cause text relocation. */
- else if (!h->ref_regular_nonweak
- && h->non_got_ref
- && h->type != STT_GNU_IFUNC
- && !htab->is_vxworks
- && !ppc_elf_hash_entry (h)->has_sda_refs
- && !readonly_dynrelocs (h))
- h->non_got_ref = 0;
}
h->protected_def = 0;
return TRUE;
@@ -5925,6 +5916,23 @@ allocate_got (struct ppc_elf_link_hash_table *htab, unsigned int need)
return where;
}
+/* If H is undefined weak, make it dynamic if that makes sense. */
+
+static bfd_boolean
+ensure_undefweak_dynamic (struct bfd_link_info *info,
+ struct elf_link_hash_entry *h)
+{
+ struct elf_link_hash_table *htab = elf_hash_table (info);
+
+ if (htab->dynamic_sections_created
+ && h->root.type == bfd_link_hash_undefweak
+ && h->dynindx == -1
+ && !h->forced_local
+ && ELF_ST_VISIBILITY (h->other) == STV_DEFAULT)
+ return bfd_elf_link_record_dynamic_symbol (info, h);
+ return TRUE;
+}
+
/* Allocate space in associated reloc sections for dynamic relocs. */
static bfd_boolean
@@ -5934,175 +5942,12 @@ allocate_dynrelocs (struct elf_link_hash_entry *h, void *inf)
struct ppc_elf_link_hash_entry *eh;
struct ppc_elf_link_hash_table *htab;
struct elf_dyn_relocs *p;
+ bfd_boolean dyn;
if (h->root.type == bfd_link_hash_indirect)
return TRUE;
htab = ppc_elf_hash_table (info);
- if (htab->elf.dynamic_sections_created
- || h->type == STT_GNU_IFUNC)
- {
- struct plt_entry *ent;
- bfd_boolean doneone = FALSE;
- bfd_vma plt_offset = 0, glink_offset = 0;
- bfd_boolean dyn;
-
- for (ent = h->plt.plist; ent != NULL; ent = ent->next)
- if (ent->plt.refcount > 0)
- {
- /* Make sure this symbol is output as a dynamic symbol. */
- if (h->dynindx == -1
- && !h->forced_local
- && !h->def_regular
- && htab->elf.dynamic_sections_created)
- {
- if (! bfd_elf_link_record_dynamic_symbol (info, h))
- return FALSE;
- }
-
- dyn = htab->elf.dynamic_sections_created;
- if (bfd_link_pic (info)
- || h->type == STT_GNU_IFUNC
- || WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn, 0, h))
- {
- asection *s = htab->elf.splt;
- if (!dyn || h->dynindx == -1)
- s = htab->elf.iplt;
-
- if (htab->plt_type == PLT_NEW || !dyn || h->dynindx == -1)
- {
- if (!doneone)
- {
- plt_offset = s->size;
- s->size += 4;
- }
- ent->plt.offset = plt_offset;
-
- s = htab->glink;
- if (!doneone || bfd_link_pic (info))
- {
- glink_offset = s->size;
- s->size += GLINK_ENTRY_SIZE;
- if (h == htab->tls_get_addr
- && !htab->params->no_tls_get_addr_opt)
- s->size += TLS_GET_ADDR_GLINK_SIZE - GLINK_ENTRY_SIZE;
- }
- if (!doneone
- && !bfd_link_pic (info)
- && h->def_dynamic
- && !h->def_regular)
- {
- h->root.u.def.section = s;
- h->root.u.def.value = glink_offset;
- }
- ent->glink_offset = glink_offset;
-
- if (htab->params->emit_stub_syms
- && !add_stub_sym (ent, h, info))
- return FALSE;
- }
- else
- {
- if (!doneone)
- {
- /* If this is the first .plt entry, make room
- for the special first entry. */
- if (s->size == 0)
- s->size += htab->plt_initial_entry_size;
-
- /* The PowerPC PLT is actually composed of two
- parts, the first part is 2 words (for a load
- and a jump), and then there is a remaining
- word available at the end. */
- plt_offset = (htab->plt_initial_entry_size
- + (htab->plt_slot_size
- * ((s->size
- - htab->plt_initial_entry_size)
- / htab->plt_entry_size)));
-
- /* If this symbol is not defined in a regular
- file, and we are not generating a shared
- library, then set the symbol to this location
- in the .plt. This is to avoid text
- relocations, and is required to make
- function pointers compare as equal between
- the normal executable and the shared library. */
- if (! bfd_link_pic (info)
- && h->def_dynamic
- && !h->def_regular)
- {
- h->root.u.def.section = s;
- h->root.u.def.value = plt_offset;
- }
-
- /* Make room for this entry. */
- s->size += htab->plt_entry_size;
- /* After the 8192nd entry, room for two entries
- is allocated. */
- if (htab->plt_type == PLT_OLD
- && (s->size - htab->plt_initial_entry_size)
- / htab->plt_entry_size
- > PLT_NUM_SINGLE_ENTRIES)
- s->size += htab->plt_entry_size;
- }
- ent->plt.offset = plt_offset;
- }
-
- /* We also need to make an entry in the .rela.plt section. */
- if (!doneone)
- {
- if (!htab->elf.dynamic_sections_created
- || h->dynindx == -1)
- htab->elf.irelplt->size += sizeof (Elf32_External_Rela);
- else
- {
- htab->elf.srelplt->size += sizeof (Elf32_External_Rela);
-
- if (htab->plt_type == PLT_VXWORKS)
- {
- /* Allocate space for the unloaded relocations. */
- if (!bfd_link_pic (info)
- && htab->elf.dynamic_sections_created)
- {
- if (ent->plt.offset
- == (bfd_vma) htab->plt_initial_entry_size)
- {
- htab->srelplt2->size
- += (sizeof (Elf32_External_Rela)
- * VXWORKS_PLTRESOLVE_RELOCS);
- }
-
- htab->srelplt2->size
- += (sizeof (Elf32_External_Rela)
- * VXWORKS_PLT_NON_JMP_SLOT_RELOCS);
- }
-
- /* Every PLT entry has an associated GOT entry in
- .got.plt. */
- htab->elf.sgotplt->size += 4;
- }
- }
- doneone = TRUE;
- }
- }
- else
- ent->plt.offset = (bfd_vma) -1;
- }
- else
- ent->plt.offset = (bfd_vma) -1;
-
- if (!doneone)
- {
- h->plt.plist = NULL;
- h->needs_plt = 0;
- }
- }
- else
- {
- h->plt.plist = NULL;
- h->needs_plt = 0;
- }
-
eh = (struct ppc_elf_link_hash_entry *) h;
if (eh->elf.got.refcount > 0
|| (ELIMINATE_COPY_RELOCS
@@ -6112,18 +5957,12 @@ allocate_dynrelocs (struct elf_link_hash_entry *h, void *inf)
&& eh->has_addr16_lo
&& htab->params->pic_fixup > 0))
{
- bfd_boolean dyn;
unsigned int need;
- /* Make sure this symbol is output as a dynamic symbol. */
- if (eh->elf.dynindx == -1
- && !eh->elf.forced_local
- && eh->elf.type != STT_GNU_IFUNC
- && htab->elf.dynamic_sections_created)
- {
- if (!bfd_elf_link_record_dynamic_symbol (info, &eh->elf))
- return FALSE;
- }
+ /* Make sure this symbol is output as a dynamic symbol.
+ Undefined weak syms won't yet be marked as dynamic. */
+ if (!ensure_undefweak_dynamic (info, &eh->elf))
+ return FALSE;
need = 0;
if ((eh->tls_mask & TLS_TLS) != 0)
@@ -6152,9 +5991,10 @@ allocate_dynrelocs (struct elf_link_hash_entry *h, void *inf)
else
{
eh->elf.got.offset = allocate_got (htab, need);
- dyn = htab->elf.dynamic_sections_created;
if ((bfd_link_pic (info)
- || WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn, 0, &eh->elf))
+ || (htab->elf.dynamic_sections_created
+ && eh->elf.dynindx != -1
+ && !SYMBOL_REFERENCES_LOCAL (info, &eh->elf)))
&& (ELF_ST_VISIBILITY (eh->elf.other) == STV_DEFAULT
|| eh->elf.root.type != bfd_link_hash_undefweak))
{
@@ -6174,17 +6014,19 @@ allocate_dynrelocs (struct elf_link_hash_entry *h, void *inf)
else
eh->elf.got.offset = (bfd_vma) -1;
- if (eh->dyn_relocs == NULL
- || !htab->elf.dynamic_sections_created)
- return TRUE;
+ if (!htab->elf.dynamic_sections_created
+ && h->type != STT_GNU_IFUNC)
+ eh->dyn_relocs = NULL;
+
+ if (eh->dyn_relocs == NULL)
+ ;
/* In the shared -Bsymbolic case, discard space allocated for
dynamic pc-relative relocs against symbols which turn out to be
defined in regular objects. For the normal shared case, discard
space for relocs that have become local due to symbol visibility
changes. */
-
- if (bfd_link_pic (info))
+ else if (bfd_link_pic (info))
{
/* Relocs that use pc_count are those that appear on a call insn,
or certain REL relocs (see must_be_dyn_reloc) that can be
@@ -6237,21 +6079,15 @@ allocate_dynrelocs (struct elf_link_hash_entry *h, void *inf)
/* Make sure undefined weak symbols are output as a dynamic
symbol in PIEs. */
- else if (h->dynindx == -1
- && !h->forced_local
- && !h->def_regular)
- {
- if (! bfd_elf_link_record_dynamic_symbol (info, h))
- return FALSE;
- }
+ else if (!ensure_undefweak_dynamic (info, h))
+ return FALSE;
}
}
else if (ELIMINATE_COPY_RELOCS)
{
- /* For the non-shared case, discard space for relocs against
+ /* For the non-pic case, discard space for relocs against
symbols which turn out to need copy relocs or are not
dynamic. */
-
if (!h->non_got_ref
&& !h->def_regular
&& !(h->protected_def
@@ -6261,25 +6097,17 @@ allocate_dynrelocs (struct elf_link_hash_entry *h, void *inf)
{
/* Make sure this symbol is output as a dynamic symbol.
Undefined weak syms won't yet be marked as dynamic. */
- if (h->dynindx == -1
- && !h->forced_local)
- {
- if (! bfd_elf_link_record_dynamic_symbol (info, h))
- return FALSE;
- }
+ if (!ensure_undefweak_dynamic (info, h))
+ return FALSE;
- /* If that succeeded, we know we'll be keeping all the
- relocs. */
- if (h->dynindx != -1)
- goto keep;
+ if (h->dynindx == -1)
+ eh->dyn_relocs = NULL;
}
-
- eh->dyn_relocs = NULL;
-
- keep: ;
+ else
+ eh->dyn_relocs = NULL;
}
- /* Finally, allocate space. */
+ /* Allocate space. */
for (p = eh->dyn_relocs; p != NULL; p = p->next)
{
asection *sreloc = elf_section_data (p->sec)->sreloc;
@@ -6288,6 +6116,152 @@ allocate_dynrelocs (struct elf_link_hash_entry *h, void *inf)
sreloc->size += p->count * sizeof (Elf32_External_Rela);
}
+ /* Handle PLT relocs. Done last, after dynindx has settled. */
+ dyn = htab->elf.dynamic_sections_created && h->dynindx != -1;
+ if (dyn || h->type == STT_GNU_IFUNC)
+ {
+ struct plt_entry *ent;
+ bfd_boolean doneone = FALSE;
+ bfd_vma plt_offset = 0, glink_offset = 0;
+
+ for (ent = h->plt.plist; ent != NULL; ent = ent->next)
+ if (ent->plt.refcount > 0)
+ {
+ asection *s = htab->elf.splt;
+
+ if (!dyn)
+ s = htab->elf.iplt;
+
+ if (htab->plt_type == PLT_NEW || !dyn)
+ {
+ if (!doneone)
+ {
+ plt_offset = s->size;
+ s->size += 4;
+ }
+ ent->plt.offset = plt_offset;
+
+ s = htab->glink;
+ if (!doneone || bfd_link_pic (info))
+ {
+ glink_offset = s->size;
+ s->size += GLINK_ENTRY_SIZE;
+ if (h == htab->tls_get_addr
+ && !htab->params->no_tls_get_addr_opt)
+ s->size += TLS_GET_ADDR_GLINK_SIZE - GLINK_ENTRY_SIZE;
+ }
+ if (!doneone
+ && !bfd_link_pic (info)
+ && h->def_dynamic
+ && !h->def_regular)
+ {
+ h->root.u.def.section = s;
+ h->root.u.def.value = glink_offset;
+ }
+ ent->glink_offset = glink_offset;
+
+ if (htab->params->emit_stub_syms
+ && !add_stub_sym (ent, h, info))
+ return FALSE;
+ }
+ else
+ {
+ if (!doneone)
+ {
+ /* If this is the first .plt entry, make room
+ for the special first entry. */
+ if (s->size == 0)
+ s->size += htab->plt_initial_entry_size;
+
+ /* The PowerPC PLT is actually composed of two
+ parts, the first part is 2 words (for a load
+ and a jump), and then there is a remaining
+ word available at the end. */
+ plt_offset = (htab->plt_initial_entry_size
+ + (htab->plt_slot_size
+ * ((s->size
+ - htab->plt_initial_entry_size)
+ / htab->plt_entry_size)));
+
+ /* If this symbol is not defined in a regular
+ file, and we are not generating a shared
+ library, then set the symbol to this location
+ in the .plt. This is to avoid text
+ relocations, and is required to make
+ function pointers compare as equal between
+ the normal executable and the shared library. */
+ if (! bfd_link_pic (info)
+ && h->def_dynamic
+ && !h->def_regular)
+ {
+ h->root.u.def.section = s;
+ h->root.u.def.value = plt_offset;
+ }
+
+ /* Make room for this entry. */
+ s->size += htab->plt_entry_size;
+ /* After the 8192nd entry, room for two entries
+ is allocated. */
+ if (htab->plt_type == PLT_OLD
+ && (s->size - htab->plt_initial_entry_size)
+ / htab->plt_entry_size
+ > PLT_NUM_SINGLE_ENTRIES)
+ s->size += htab->plt_entry_size;
+ }
+ ent->plt.offset = plt_offset;
+ }
+
+ /* We also need to make an entry in the .rela.plt section. */
+ if (!doneone)
+ {
+ if (!dyn)
+ htab->elf.irelplt->size += sizeof (Elf32_External_Rela);
+ else
+ {
+ htab->elf.srelplt->size += sizeof (Elf32_External_Rela);
+
+ if (htab->plt_type == PLT_VXWORKS)
+ {
+ /* Allocate space for the unloaded relocations. */
+ if (!bfd_link_pic (info)
+ && htab->elf.dynamic_sections_created)
+ {
+ if (ent->plt.offset
+ == (bfd_vma) htab->plt_initial_entry_size)
+ {
+ htab->srelplt2->size
+ += (sizeof (Elf32_External_Rela)
+ * VXWORKS_PLTRESOLVE_RELOCS);
+ }
+
+ htab->srelplt2->size
+ += (sizeof (Elf32_External_Rela)
+ * VXWORKS_PLT_NON_JMP_SLOT_RELOCS);
+ }
+
+ /* Every PLT entry has an associated GOT entry in
+ .got.plt. */
+ htab->elf.sgotplt->size += 4;
+ }
+ }
+ doneone = TRUE;
+ }
+ }
+ else
+ ent->plt.offset = (bfd_vma) -1;
+
+ if (!doneone)
+ {
+ h->plt.plist = NULL;
+ h->needs_plt = 0;
+ }
+ }
+ else
+ {
+ h->plt.plist = NULL;
+ h->needs_plt = 0;
+ }
+
return TRUE;
}
@@ -8502,11 +8476,11 @@ ppc_elf_relocate_section (bfd *output_bfd,
offp = &htab->tlsld_got.offset;
else if (h != NULL)
{
- bfd_boolean dyn;
- dyn = htab->elf.dynamic_sections_created;
- if (! WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn, bfd_link_pic (info), h)
- || (bfd_link_pic (info)
- && SYMBOL_REFERENCES_LOCAL (info, h)))
+ if (!htab->elf.dynamic_sections_created
+ || h->dynindx == -1
+ || SYMBOL_REFERENCES_LOCAL (info, h)
+ || (ELF_ST_VISIBILITY (h->other) != STV_DEFAULT
+ && h->root.type == bfd_link_hash_undefweak))
/* This is actually a static link, or it is a
-Bsymbolic link and the symbol is defined
locally, or the symbol was forced to be local
@@ -8514,7 +8488,6 @@ ppc_elf_relocate_section (bfd *output_bfd,
;
else
{
- BFD_ASSERT (h->dynindx != -1);
indx = h->dynindx;
unresolved_reloc = FALSE;
}
@@ -8573,11 +8546,12 @@ ppc_elf_relocate_section (bfd *output_bfd,
}
/* Generate relocs for the dynamic linker. */
- if ((bfd_link_pic (info) || indx != 0)
- && (offp == &htab->tlsld_got.offset
- || h == NULL
- || ELF_ST_VISIBILITY (h->other) == STV_DEFAULT
- || h->root.type != bfd_link_hash_undefweak))
+ if (indx != 0
+ || (bfd_link_pic (info)
+ && (h == NULL
+ || ELF_ST_VISIBILITY (h->other) == STV_DEFAULT
+ || h->root.type != bfd_link_hash_undefweak
+ || offp == &htab->tlsld_got.offset)))
{
asection *rsec = htab->elf.srelgot;
bfd_byte * loc;
@@ -8635,25 +8609,31 @@ ppc_elf_relocate_section (bfd *output_bfd,
else
{
bfd_vma value = relocation;
+ int tlsopt = (htab->plt_type == PLT_NEW
+ && !htab->params->no_tls_get_addr_opt
+ && htab->tls_get_addr != NULL
+ && htab->tls_get_addr->plt.plist != NULL);
- if (tls_ty == (TLS_TLS | TLS_LD))
- value = 1;
- else if (tls_ty != 0)
+ if (tls_ty != 0)
{
if (htab->elf.tls_sec == NULL)
value = 0;
else
{
- value -= htab->elf.tls_sec->vma + DTP_OFFSET;
- if (tls_ty == (TLS_TLS | TLS_TPREL))
+ if (tls_ty & TLS_LD)
+ value = 0;
+ else
+ value -= htab->elf.tls_sec->vma + DTP_OFFSET;
+ if ((tls_ty & TLS_TPREL)
+ || (tlsopt && !(tls_ty & TLS_DTPREL)))
value += DTP_OFFSET - TP_OFFSET;
}
- if (tls_ty == (TLS_TLS | TLS_GD))
+ if (tls_ty & (TLS_LD | TLS_GD))
{
bfd_put_32 (input_bfd, value,
htab->elf.sgot->contents + off + 4);
- value = 1;
+ value = !tlsopt;
}
}
bfd_put_32 (input_bfd, value,
@@ -8987,17 +8967,43 @@ ppc_elf_relocate_section (bfd *output_bfd,
if (skip == -1)
goto copy_reloc;
- /* This reloc will be computed at runtime. We clear the memory
- so that it contains predictable value. */
- if (! skip
- && ((input_section->flags & SEC_ALLOC) != 0
- || ELF32_R_TYPE (outrel.r_info) != R_PPC_RELATIVE))
+ /* This reloc will be computed at runtime. Clear the memory
+ so that it contains a predictable value for prelink. */
+ if (!skip)
{
relocation = howto->pc_relative ? outrel.r_offset : 0;
addend = 0;
break;
}
}
+ else if (r_type == R_PPC_DTPMOD32
+ && htab->plt_type == PLT_NEW
+ && !htab->params->no_tls_get_addr_opt
+ && htab->tls_get_addr != NULL
+ && htab->tls_get_addr->plt.plist != NULL)
+ {
+ /* Set up for __tls_get_addr_opt stub when this entry
+ does not have dynamic relocs. */
+ relocation = 0;
+ /* Set up the next word for local dynamic. If it turns
+ out to be global dynamic, the reloc will overwrite
+ this value. */
+ if (rel->r_offset + 8 <= input_section->size)
+ bfd_put_32 (input_bfd, DTP_OFFSET - TP_OFFSET,
+ contents + rel->r_offset + 4);
+ }
+ else if (r_type == R_PPC_DTPREL32
+ && htab->plt_type == PLT_NEW
+ && !htab->params->no_tls_get_addr_opt
+ && htab->tls_get_addr != NULL
+ && htab->tls_get_addr->plt.plist != NULL
+ && rel > relocs
+ && rel[-1].r_info == ELF32_R_INFO (r_symndx, R_PPC_DTPMOD32)
+ && rel[-1].r_offset + 4 == rel->r_offset)
+ {
+ /* __tls_get_addr_opt stub value. */
+ addend += DTP_OFFSET - TP_OFFSET;
+ }
break;
case R_PPC_RELAX_PLT: