/* 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;
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
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
&& 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)
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))
{
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
/* 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
{
/* 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;
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;
}
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
;
else
{
- BFD_ASSERT (h->dynindx != -1);
indx = h->dynindx;
unresolved_reloc = FALSE;
}
}
/* 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;
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,
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:
struct got_entry *gent)
{
struct ppc_link_hash_table *htab = ppc_hash_table (info);
- bfd_boolean dyn;
struct ppc_link_hash_entry *eh = (struct ppc_link_hash_entry *) h;
int entsize = (gent->tls_type & eh->tls_mask & (TLS_GD | TLS_LD)
? 16 : 8);
gent->got.offset = got->size;
got->size += entsize;
- dyn = htab->elf.dynamic_sections_created;
if (h->type == STT_GNU_IFUNC)
{
htab->elf.irelplt->size += rentsize;
htab->got_reli_size += rentsize;
}
else if ((bfd_link_pic (info)
- || WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn, 0, h))
+ || (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))
{
}
}
+/* 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 .plt, .got and associated reloc sections for
dynamic relocs. */
if (!gent->is_indirect)
{
/* Make sure this symbol is output as a dynamic symbol.
- Undefined weak syms won't yet be marked as dynamic,
- nor will all TLS symbols. */
- if (h->dynindx == -1
- && !h->forced_local
- && h->type != STT_GNU_IFUNC
- && htab->elf.dynamic_sections_created)
- {
- if (! bfd_elf_link_record_dynamic_symbol (info, h))
- return FALSE;
- }
+ Undefined weak syms won't yet be marked as dynamic. */
+ if (!ensure_undefweak_dynamic (info, h))
+ return FALSE;
if (!is_ppc64_elf (gent->owner))
abort ();
/* Make sure this symbol is output as a dynamic symbol.
Undefined weak syms won't yet be marked as dynamic. */
- else if (h->dynindx == -1
- && !h->forced_local)
- {
- if (! bfd_elf_link_record_dynamic_symbol (info, h))
- return FALSE;
- }
+ else if (!ensure_undefweak_dynamic (info, h))
+ return FALSE;
}
}
else if (h->type == STT_GNU_IFUNC)
/* 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)
+ {
+ /* 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, h))
+ return FALSE;
- /* First make sure this symbol is output as a dynamic symbol.
- Undefined weak syms won't yet be marked as dynamic. */
- if (h->root.type == bfd_link_hash_undefweak
- && !h->non_got_ref
- && !h->def_regular
- && h->dynindx == -1
- && !h->forced_local
- && !bfd_elf_link_record_dynamic_symbol (info, h))
- return FALSE;
-
- if (h->non_got_ref
- || h->def_regular
- || h->dynindx == -1)
+ if (h->dynindx == -1)
+ eh->dyn_relocs = NULL;
+ }
+ else
eh->dyn_relocs = NULL;
}
}
if ((htab->elf.dynamic_sections_created
- && h->dynindx != -1
- && WILL_CALL_FINISH_DYNAMIC_SYMBOL (1, bfd_link_pic (info), h))
+ && h->dynindx != -1)
|| h->type == STT_GNU_IFUNC)
{
struct plt_entry *pent;
ent = ppc64_tlsld_got (input_bfd);
else
{
-
if (h != NULL)
{
- bfd_boolean dyn = htab->elf.dynamic_sections_created;
- if (!WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn, bfd_link_pic (info),
- &h->elf)
- || (bfd_link_pic (info)
- && SYMBOL_REFERENCES_LOCAL (info, &h->elf)))
+ if (!htab->elf.dynamic_sections_created
+ || h->elf.dynindx == -1
+ || SYMBOL_REFERENCES_LOCAL (info, &h->elf)
+ || (ELF_ST_VISIBILITY (h->elf.other) != STV_DEFAULT
+ && h->elf.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
;
else
{
- BFD_ASSERT (h->elf.dynindx != -1);
indx = h->elf.dynindx;
unresolved_reloc = FALSE;
}
: ELF_ST_TYPE (sym->st_info) == STT_GNU_IFUNC);
if (ifunc)
relgot = htab->elf.irelplt;
- else if ((bfd_link_pic (info) || indx != 0)
- && (h == NULL
- || (tls_type == (TLS_TLS | TLS_LD)
- && !h->elf.def_dynamic)
- || ELF_ST_VISIBILITY (h->elf.other) == STV_DEFAULT
- || h->elf.root.type != bfd_link_hash_undefweak))
+ else if (indx != 0
+ || (bfd_link_pic (info)
+ && (h == NULL
+ || (ELF_ST_VISIBILITY (h->elf.other)
+ == STV_DEFAULT)
+ || h->elf.root.type != bfd_link_hash_undefweak
+ || (tls_type == (TLS_TLS | TLS_LD)
+ && !h->elf.def_dynamic))))
relgot = ppc64_elf_tdata (ent->owner)->relgot;
if (relgot != NULL)
{
emitting a reloc. */
else
{
+ int tlsopt
+ = (htab->params->tls_get_addr_opt
+ && htab->tls_get_addr_fd != NULL
+ && htab->tls_get_addr_fd->elf.plt.plist != NULL);
+
relocation += addend;
- if (tls_type == (TLS_TLS | TLS_LD))
- relocation = 1;
- else if (tls_type != 0)
+ if (tls_type != 0)
{
if (htab->elf.tls_sec == NULL)
relocation = 0;
else
{
- relocation -= htab->elf.tls_sec->vma + DTP_OFFSET;
- if (tls_type == (TLS_TLS | TLS_TPREL))
+ if (tls_type & TLS_LD)
+ relocation = 0;
+ else
+ relocation -= htab->elf.tls_sec->vma + DTP_OFFSET;
+ if ((tls_type & TLS_TPREL)
+ || (tlsopt && !(tls_type & TLS_DTPREL)))
relocation += DTP_OFFSET - TP_OFFSET;
}
- if (tls_type == (TLS_TLS | TLS_GD))
+ if (tls_type & (TLS_GD | TLS_LD))
{
bfd_put_64 (output_bfd, relocation,
got->contents + off + 8);
- relocation = 1;
+ relocation = !tlsopt;
}
}
-
bfd_put_64 (output_bfd, relocation,
got->contents + off);
}
addend = outrel.r_addend;
/* Adjust pc_relative relocs to have zero in *r_offset. */
else if (ppc64_elf_howto_table[r_type]->pc_relative)
- addend = (input_section->output_section->vma
- + input_section->output_offset
- + rel->r_offset);
+ addend = outrel.r_offset;
}
}
+ else if (r_type == R_PPC64_DTPMOD64
+ && htab->params->tls_get_addr_opt
+ && htab->tls_get_addr_fd != NULL
+ && htab->tls_get_addr_fd->elf.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 + 16 <= input_section->size)
+ bfd_put_64 (input_bfd, DTP_OFFSET - TP_OFFSET,
+ contents + rel->r_offset + 8);
+ }
+ else if (r_type == R_PPC64_DTPREL64
+ && htab->params->tls_get_addr_opt
+ && htab->tls_get_addr_fd != NULL
+ && htab->tls_get_addr_fd->elf.plt.plist != NULL
+ && rel > relocs
+ && rel[-1].r_info == ELF64_R_INFO (r_symndx, R_PPC64_DTPMOD64)
+ && rel[-1].r_offset + 8 == rel->r_offset)
+ {
+ /* __tls_get_addr_opt stub value. */
+ addend += DTP_OFFSET - TP_OFFSET;
+ }
break;
case R_PPC64_COPY: