#define elf_backend_maybe_function_sym ppc64_elf_maybe_function_sym
#define elf_backend_always_size_sections ppc64_elf_func_desc_adjust
#define elf_backend_size_dynamic_sections ppc64_elf_size_dynamic_sections
+#define elf_backend_hash_symbol ppc64_elf_hash_symbol
#define elf_backend_init_index_section _bfd_elf_init_2_index_sections
#define elf_backend_action_discarded ppc64_elf_action_discarded
#define elf_backend_relocate_section ppc64_elf_relocate_section
#define elf_backend_finish_dynamic_sections ppc64_elf_finish_dynamic_sections
#define elf_backend_link_output_symbol_hook ppc64_elf_output_symbol_hook
#define elf_backend_special_sections ppc64_elf_special_sections
-#define elf_backend_post_process_headers _bfd_elf_set_osabi
#define elf_backend_merge_symbol_attribute ppc64_elf_merge_symbol_attribute
/* The name of the dynamic interpreter. This is put in the .interp
#define LD_R2_0R1 0xe8410000 /* ld %r2,0(%r1) */
+#define ADDIS_R12_R12 0x3d8c0000 /* addis %r12,%r12,xxx@ha */
+#define LD_R12_0R12 0xe98c0000 /* ld %r12,xxx@l(%r12) */
+
/* glink call stub instructions. We enter with the index in R0. */
#define GLINK_CALL_STUB_SIZE (16*4)
/* 0: */
/* List of input sections for each output section. */
asection **input_list;
- /* Short-cuts to get to dynamic linker sections. */
- asection *got;
- asection *plt;
- asection *relplt;
- asection *iplt;
- asection *reliplt;
+ /* Shortcuts to get to dynamic linker sections. */
asection *dynbss;
asection *relbss;
asection *glink;
}
flags = SEC_ALLOC | SEC_LINKER_CREATED;
- htab->iplt = bfd_make_section_anyway_with_flags (dynobj, ".iplt", flags);
- if (htab->iplt == NULL
- || ! bfd_set_section_alignment (dynobj, htab->iplt, 3))
+ htab->elf.iplt = bfd_make_section_anyway_with_flags (dynobj, ".iplt", flags);
+ if (htab->elf.iplt == NULL
+ || ! bfd_set_section_alignment (dynobj, htab->elf.iplt, 3))
return FALSE;
flags = (SEC_ALLOC | SEC_LOAD | SEC_READONLY
| SEC_HAS_CONTENTS | SEC_IN_MEMORY | SEC_LINKER_CREATED);
- htab->reliplt = bfd_make_section_anyway_with_flags (dynobj,
- ".rela.iplt",
- flags);
- if (htab->reliplt == NULL
- || ! bfd_set_section_alignment (dynobj, htab->reliplt, 3))
+ htab->elf.irelplt
+ = bfd_make_section_anyway_with_flags (dynobj, ".rela.iplt", flags);
+ if (htab->elf.irelplt == NULL
+ || ! bfd_set_section_alignment (dynobj, htab->elf.irelplt, 3))
return FALSE;
/* Create branch lookup table for plt_branch stubs. */
if (htab == NULL)
return FALSE;
- if (!htab->got)
- {
- if (! _bfd_elf_create_got_section (htab->elf.dynobj, info))
- return FALSE;
-
- htab->got = bfd_get_linker_section (htab->elf.dynobj, ".got");
- if (!htab->got)
- abort ();
- }
+ if (!htab->elf.sgot
+ && !_bfd_elf_create_got_section (htab->elf.dynobj, info))
+ return FALSE;
flags = (SEC_ALLOC | SEC_LOAD | SEC_HAS_CONTENTS | SEC_IN_MEMORY
| SEC_LINKER_CREATED);
if (htab == NULL)
return FALSE;
- if (!htab->got)
- htab->got = bfd_get_linker_section (dynobj, ".got");
- htab->plt = bfd_get_linker_section (dynobj, ".plt");
- htab->relplt = bfd_get_linker_section (dynobj, ".rela.plt");
htab->dynbss = bfd_get_linker_section (dynobj, ".dynbss");
if (!info->shared)
htab->relbss = bfd_get_linker_section (dynobj, ".rela.bss");
- if (!htab->got || !htab->plt || !htab->relplt || !htab->dynbss
+ if (!htab->elf.sgot || !htab->elf.splt || !htab->elf.srelplt || !htab->dynbss
|| (!info->shared && !htab->relbss))
abort ();
edir->elf.ref_regular |= eind->elf.ref_regular;
edir->elf.ref_regular_nonweak |= eind->elf.ref_regular_nonweak;
edir->elf.needs_plt |= eind->elf.needs_plt;
+ edir->elf.pointer_equality_needed |= eind->elf.pointer_equality_needed;
/* Copy over any dynamic relocs we may have on the indirect sym. */
if (eind->dyn_relocs != NULL)
&& (sec->owner->flags & (EXEC_P | DYNAMIC)) != 0
&& is_ppc64_elf (sec->owner))
{
- asection *got = bfd_get_section_by_name (sec->owner, ".got");
- if (got != NULL
- && got->size >= elf_backend_got_header_size
- && bfd_get_section_by_name (sec->owner, ".opd") != NULL)
+ if (abiversion (sec->owner) >= 2
+ || bfd_get_section_by_name (sec->owner, ".opd") != NULL)
sec->has_toc_reloc = 1;
}
_bfd_elf_link_just_syms (sec, info);
if (!update_local_sym_info (abfd, symtab_hdr, r_symndx,
rel->r_addend, tls_type))
return FALSE;
+
+ /* We may also need a plt entry if the symbol turns out to be
+ an ifunc. */
+ if (h != NULL && !info->shared && abiversion (abfd) == 2)
+ {
+ if (!update_plt_info (abfd, &h->plt.plist, rel->r_addend))
+ return FALSE;
+ }
break;
case R_PPC64_PLT16_HA:
}
/* Fall through. */
- case R_PPC64_REL30:
- case R_PPC64_REL32:
- case R_PPC64_REL64:
- case R_PPC64_ADDR14:
- case R_PPC64_ADDR14_BRNTAKEN:
- case R_PPC64_ADDR14_BRTAKEN:
case R_PPC64_ADDR16:
case R_PPC64_ADDR16_DS:
case R_PPC64_ADDR16_HA:
case R_PPC64_ADDR16_HIGHESTA:
case R_PPC64_ADDR16_LO:
case R_PPC64_ADDR16_LO_DS:
+ if (h != NULL && !info->shared && abiversion (abfd) == 2
+ && rel->r_addend == 0)
+ {
+ /* We may need a .plt entry if this reloc refers to a
+ function in a shared lib. */
+ if (!update_plt_info (abfd, &h->plt.plist, rel->r_addend))
+ return FALSE;
+ h->pointer_equality_needed = 1;
+ }
+ /* Fall through. */
+
+ case R_PPC64_REL30:
+ case R_PPC64_REL32:
+ case R_PPC64_REL64:
+ case R_PPC64_ADDR14:
+ case R_PPC64_ADDR14_BRNTAKEN:
+ case R_PPC64_ADDR14_BRTAKEN:
case R_PPC64_ADDR24:
case R_PPC64_ADDR32:
case R_PPC64_UADDR16:
if (!info->relocatable
&& htab->elf.hgot != NULL)
- _bfd_elf_link_hash_hide_symbol (info, htab->elf.hgot, TRUE);
+ {
+ _bfd_elf_link_hash_hide_symbol (info, htab->elf.hgot, TRUE);
+ /* Make .TOC. defined so as to prevent it being made dynamic.
+ The wrong value here is fixed later in ppc64_elf_set_toc. */
+ htab->elf.hgot->type = STT_OBJECT;
+ htab->elf.hgot->root.type = bfd_link_hash_defined;
+ htab->elf.hgot->root.u.def.value = 0;
+ htab->elf.hgot->root.u.def.section = bfd_abs_section_ptr;
+ htab->elf.hgot->def_regular = 1;
+ htab->elf.hgot->other = ((htab->elf.hgot->other & ~ELF_ST_VISIBILITY (-1))
+ | STV_HIDDEN);
+ }
if (htab->sfpr == NULL)
/* We don't have any relocs. */
return TRUE;
}
+/* Return true if we have dynamic relocs that apply to read-only sections. */
+
+static bfd_boolean
+readonly_dynrelocs (struct elf_link_hash_entry *h)
+{
+ struct ppc_link_hash_entry *eh;
+ struct elf_dyn_relocs *p;
+
+ eh = (struct ppc_link_hash_entry *) h;
+ for (p = eh->dyn_relocs; p != NULL; p = p->next)
+ {
+ asection *s = p->sec->output_section;
+
+ if (s != NULL && (s->flags & SEC_READONLY) != 0)
+ return TRUE;
+ }
+ return FALSE;
+}
+
/* Adjust a symbol defined by a dynamic object and referenced by a
regular object. The current definition is in some section of the
dynamic object, but we're not including those sections. We have to
h->plt.plist = NULL;
h->needs_plt = 0;
}
+ else if (abiversion (info->output_bfd) == 2)
+ {
+ /* 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. */
+ if (!h->ref_regular_nonweak
+ && h->non_got_ref
+ && h->type != STT_GNU_IFUNC
+ && !readonly_dynrelocs (h))
+ h->non_got_ref = 0;
+
+ /* If making a plt entry, then we don't need copy relocs. */
+ return TRUE;
+ }
}
else
h->plt.plist = NULL;
if (!h->def_dynamic || !h->ref_regular || h->def_regular)
return TRUE;
- if (ELIMINATE_COPY_RELOCS)
+ /* If we didn't find any dynamic relocs in read-only sections, then
+ we'll be keeping the dynamic relocs and avoiding the copy reloc. */
+ if (ELIMINATE_COPY_RELOCS && !readonly_dynrelocs (h))
{
- struct ppc_link_hash_entry * eh;
- struct elf_dyn_relocs *p;
-
- eh = (struct ppc_link_hash_entry *) h;
- for (p = eh->dyn_relocs; p != NULL; p = p->next)
- {
- s = p->sec->output_section;
- if (s != NULL && (s->flags & SEC_READONLY) != 0)
- break;
- }
-
- /* If we didn't find any dynamic relocs in read-only sections, then
- we'll be keeping the dynamic relocs and avoiding the copy reloc. */
- if (p == NULL)
- {
- h->non_got_ref = 0;
- return TRUE;
- }
+ h->non_got_ref = 0;
+ return TRUE;
}
if (h->plt.plist != NULL)
|| discarded_section (sym_sec))
continue;
- if (!SYMBOL_CALLS_LOCAL (info, h))
+ if (!SYMBOL_REFERENCES_LOCAL (info, h))
continue;
if (h != NULL)
dyn = htab->elf.dynamic_sections_created;
if (h->type == STT_GNU_IFUNC)
{
- htab->reliplt->size += rentsize;
+ htab->elf.irelplt->size += rentsize;
htab->got_reli_size += rentsize;
}
else if ((info->shared
if (!htab->elf.dynamic_sections_created
|| h->dynindx == -1)
{
- s = htab->iplt;
+ s = htab->elf.iplt;
pent->plt.offset = s->size;
s->size += PLT_ENTRY_SIZE (htab);
- s = htab->reliplt;
+ s = htab->elf.irelplt;
}
else
{
/* If this is the first .plt entry, make room for the special
first entry. */
- s = htab->plt;
+ s = htab->elf.splt;
if (s->size == 0)
s->size += PLT_INITIAL_ENTRY_SIZE (htab);
s->size += 4;
/* We also need to make an entry in the .rela.plt section. */
- s = htab->relplt;
+ s = htab->elf.srelplt;
}
s->size += sizeof (Elf64_External_Rela);
doneone = TRUE;
{
asection *sreloc = elf_section_data (p->sec)->sreloc;
if (eh->elf.type == STT_GNU_IFUNC)
- sreloc = htab->reliplt;
+ sreloc = htab->elf.irelplt;
sreloc->size += p->count * sizeof (Elf64_External_Rela);
}
return TRUE;
}
-/* Find any dynamic relocs that apply to read-only sections. */
+/* Called via elf_link_hash_traverse from ppc64_elf_size_dynamic_sections
+ to set up space for global entry stubs. These are put in glink,
+ after the branch table. */
static bfd_boolean
-readonly_dynrelocs (struct elf_link_hash_entry *h, void *inf)
+size_global_entry_stubs (struct elf_link_hash_entry *h, void *inf)
{
- struct ppc_link_hash_entry *eh;
- struct elf_dyn_relocs *p;
+ struct bfd_link_info *info;
+ struct ppc_link_hash_table *htab;
+ struct plt_entry *pent;
+ asection *s;
- eh = (struct ppc_link_hash_entry *) h;
- for (p = eh->dyn_relocs; p != NULL; p = p->next)
- {
- asection *s = p->sec->output_section;
+ if (h->root.type == bfd_link_hash_indirect)
+ return TRUE;
- if (s != NULL && (s->flags & SEC_READONLY) != 0)
- {
- struct bfd_link_info *info = inf;
+ if (!h->pointer_equality_needed)
+ return TRUE;
- info->flags |= DF_TEXTREL;
+ if (h->def_regular)
+ return TRUE;
- /* Not an error, just cut short the traversal. */
- return FALSE;
- }
+ info = inf;
+ htab = ppc_hash_table (info);
+ if (htab == NULL)
+ return FALSE;
+
+ s = htab->glink;
+ for (pent = h->plt.plist; pent != NULL; pent = pent->next)
+ if (pent->plt.offset != (bfd_vma) -1
+ && pent->addend == 0)
+ {
+ /* For ELFv2, if this symbol is not defined in a regular file
+ and we are not generating a shared library or pie, then we
+ need to define the symbol in the executable on a call stub.
+ This is to avoid text relocations. */
+ s->size = (s->size + 15) & -16;
+ h->root.u.def.section = s;
+ h->root.u.def.value = s->size;
+ s->size += 16;
+ break;
+ }
+ return TRUE;
+}
+
+/* Set DF_TEXTREL if we find any dynamic relocs that apply to
+ read-only sections. */
+
+static bfd_boolean
+maybe_set_textrel (struct elf_link_hash_entry *h, void *info)
+{
+ if (h->root.type == bfd_link_hash_indirect)
+ return TRUE;
+
+ if (readonly_dynrelocs (h))
+ {
+ ((struct bfd_link_info *) info)->flags |= DF_TEXTREL;
+
+ /* Not an error, just cut short the traversal. */
+ return FALSE;
}
return TRUE;
}
{
asection *srel = elf_section_data (p->sec)->sreloc;
if (p->ifunc)
- srel = htab->reliplt;
+ srel = htab->elf.irelplt;
srel->size += p->count * sizeof (Elf64_External_Rela);
if ((p->sec->output_section->flags & SEC_READONLY) != 0)
info->flags |= DF_TEXTREL;
s->size += ent_size;
if ((*lgot_masks & PLT_IFUNC) != 0)
{
- htab->reliplt->size += rel_size;
+ htab->elf.irelplt->size += rel_size;
htab->got_reli_size += rel_size;
}
else if (info->shared)
for (ent = *local_plt; ent != NULL; ent = ent->next)
if (ent->plt.refcount > 0)
{
- s = htab->iplt;
+ s = htab->elf.iplt;
ent->plt.offset = s->size;
s->size += PLT_ENTRY_SIZE (htab);
- htab->reliplt->size += sizeof (Elf64_External_Rela);
+ htab->elf.irelplt->size += sizeof (Elf64_External_Rela);
}
else
ent->plt.offset = (bfd_vma) -1;
/* Allocate global sym .plt and .got entries, and space for global
sym dynamic relocs. */
elf_link_hash_traverse (&htab->elf, allocate_dynrelocs, info);
+ /* Stash the end of glink branch table. */
+ if (htab->glink != NULL)
+ htab->glink->rawsize = htab->glink->size;
+
+ if (!htab->opd_abi && !info->shared)
+ elf_link_hash_traverse (&htab->elf, size_global_entry_stubs, info);
first_tlsld = NULL;
for (ibfd = info->input_bfds; ibfd != NULL; ibfd = ibfd->link_next)
if (s == htab->brlt || s == htab->relbrlt)
/* These haven't been allocated yet; don't strip. */
continue;
- else if (s == htab->got
- || s == htab->plt
- || s == htab->iplt
+ else if (s == htab->elf.sgot
+ || s == htab->elf.splt
+ || s == htab->elf.iplt
|| s == htab->glink
|| s == htab->dynbss)
{
{
if (s->size != 0)
{
- if (s != htab->relplt)
+ if (s != htab->elf.srelplt)
relocs = TRUE;
/* We use the reloc_count field as a counter if we need
continue;
s = ppc64_elf_tdata (ibfd)->got;
- if (s != NULL && s != htab->got)
+ if (s != NULL && s != htab->elf.sgot)
{
if (s->size == 0)
s->flags |= SEC_EXCLUDE;
return FALSE;
}
- if (htab->plt != NULL && htab->plt->size != 0)
+ if (htab->elf.splt != NULL && htab->elf.splt->size != 0)
{
if (!add_dynamic_entry (DT_PLTGOT, 0)
|| !add_dynamic_entry (DT_PLTRELSZ, 0)
/* If any dynamic relocs apply to a read-only section,
then we need a DT_TEXTREL entry. */
if ((info->flags & DF_TEXTREL) == 0)
- elf_link_hash_traverse (&htab->elf, readonly_dynrelocs, info);
+ elf_link_hash_traverse (&htab->elf, maybe_set_textrel, info);
if ((info->flags & DF_TEXTREL) != 0)
{
return TRUE;
}
+/* Return TRUE if symbol should be hashed in the `.gnu.hash' section. */
+
+static bfd_boolean
+ppc64_elf_hash_symbol (struct elf_link_hash_entry *h)
+{
+ if (h->plt.plist != NULL
+ && !h->def_regular
+ && !h->pointer_equality_needed)
+ return FALSE;
+
+ return _bfd_elf_hash_symbol (h);
+}
+
/* Determine the type of stub needed, if any, for a call. */
static inline enum ppc_stub_type
r[0].r_offset = loc - stub_entry->stub_sec->contents;
if (bfd_big_endian (info->output_bfd))
r[0].r_offset += 2;
- if (stub_entry->stub_type == ppc_stub_plt_branch_r2off
- && htab->opd_abi)
+ if (stub_entry->stub_type == ppc_stub_plt_branch_r2off)
r[0].r_offset += 4;
r[0].r_info = ELF64_R_INFO (0, R_PPC64_TOC16_DS);
r[0].r_addend = dest;
}
}
- if (stub_entry->stub_type != ppc_stub_plt_branch_r2off
- || !htab->opd_abi)
+ if (stub_entry->stub_type != ppc_stub_plt_branch_r2off)
{
if (PPC_HA (off) != 0)
{
{
bfd_vma r2off = get_r2off (info, stub_entry);
- if (r2off == 0)
+ if (r2off == 0 && htab->opd_abi)
{
htab->stub_error = TRUE;
return FALSE;
bfd_put_32 (htab->stub_bfd, STD_R2_0R1 + STK_TOC (htab), loc);
loc += 4;
- size = 20;
+ size = 16;
if (PPC_HA (off) != 0)
{
size += 4;
bfd_put_32 (htab->stub_bfd, ADDIS_R11_R2 | PPC_HA (off), loc);
loc += 4;
bfd_put_32 (htab->stub_bfd, LD_R12_0R11 | PPC_LO (off), loc);
- loc += 4;
}
else
- {
- bfd_put_32 (htab->stub_bfd, LD_R12_0R2 | PPC_LO (off), loc);
- loc += 4;
- }
+ bfd_put_32 (htab->stub_bfd, LD_R12_0R2 | PPC_LO (off), loc);
if (PPC_HA (r2off) != 0)
{
size += 4;
+ loc += 4;
bfd_put_32 (htab->stub_bfd, ADDIS_R2_R2 | PPC_HA (r2off), loc);
+ }
+ if (PPC_LO (r2off) != 0)
+ {
+ size += 4;
loc += 4;
+ bfd_put_32 (htab->stub_bfd, ADDI_R2_R2 | PPC_LO (r2off), loc);
}
- bfd_put_32 (htab->stub_bfd, ADDI_R2_R2 | PPC_LO (r2off), loc);
}
loc += 4;
bfd_put_32 (htab->stub_bfd, MTCTR_R12, loc);
if (dest >= (bfd_vma) -2)
abort ();
- plt = htab->plt;
+ plt = htab->elf.splt;
if (!htab->elf.dynamic_sections_created
|| stub_entry->h == NULL
|| stub_entry->h->elf.dynindx == -1)
- plt = htab->iplt;
+ plt = htab->elf.iplt;
dest += plt->output_offset + plt->output_section->vma;
+ stub_entry->target_section->output_offset
+ stub_entry->target_section->output_section->vma);
- rl = (htab->reliplt->contents
- + (htab->reliplt->reloc_count++
+ rl = (htab->elf.irelplt->contents
+ + (htab->elf.irelplt->reloc_count++
* sizeof (Elf64_External_Rela)));
bfd_elf64_swap_reloca_out (info->output_bfd, &rela, rl);
stub_entry->plt_ent->plt.offset |= 1;
off = stub_entry->plt_ent->plt.offset & ~(bfd_vma) 1;
if (off >= (bfd_vma) -2)
abort ();
- plt = htab->plt;
+ plt = htab->elf.splt;
if (!htab->elf.dynamic_sections_created
|| stub_entry->h == NULL
|| stub_entry->h->elf.dynindx == -1)
- plt = htab->iplt;
+ plt = htab->elf.iplt;
off += (plt->output_offset
+ plt->output_section->vma
- elf_gp (plt->output_section->owner)
stub_entry->stub_sec->flags |= SEC_RELOC;
}
- if (stub_entry->stub_type != ppc_stub_plt_branch_r2off
- || !htab->opd_abi)
+ if (stub_entry->stub_type != ppc_stub_plt_branch_r2off)
{
size = 12;
if (PPC_HA (off) != 0)
}
else
{
- size = 20;
+ size = 16;
if (PPC_HA (off) != 0)
size += 4;
if (PPC_HA (r2off) != 0)
size += 4;
+ if (PPC_LO (r2off) != 0)
+ size += 4;
}
}
else if (info->emitrelocations)
}
/* Zap sizes of got sections. */
- htab->reliplt->rawsize = htab->reliplt->size;
- htab->reliplt->size -= htab->got_reli_size;
+ htab->elf.irelplt->rawsize = htab->elf.irelplt->size;
+ htab->elf.irelplt->size -= htab->got_reli_size;
htab->got_reli_size = 0;
for (ibfd = info->input_bfds; ibfd != NULL; ibfd = ibfd->link_next)
s->size += ent_size;
if ((*lgot_masks & PLT_IFUNC) != 0)
{
- htab->reliplt->size += rel_size;
+ htab->elf.irelplt->size += rel_size;
htab->got_reli_size += rel_size;
}
else if (info->shared)
}
}
- done_something = htab->reliplt->rawsize != htab->reliplt->size;
+ done_something = htab->elf.irelplt->rawsize != htab->elf.irelplt->size;
if (!done_something)
for (ibfd = info->input_bfds; ibfd != NULL; ibfd = ibfd->link_next)
{
if (htab != NULL
&& htab->elf.hgot != NULL)
{
- htab->elf.hgot->type = STT_OBJECT;
- htab->elf.hgot->root.type = bfd_link_hash_defined;
htab->elf.hgot->root.u.def.value = TOC_BASE_OFF;
htab->elf.hgot->root.u.def.section = s;
}
return TOCstart;
}
+/* Called via elf_link_hash_traverse from ppc64_elf_build_stubs to
+ write out any global entry stubs. */
+
+static bfd_boolean
+build_global_entry_stubs (struct elf_link_hash_entry *h, void *inf)
+{
+ struct bfd_link_info *info;
+ struct ppc_link_hash_table *htab;
+ struct plt_entry *pent;
+ asection *s;
+
+ if (h->root.type == bfd_link_hash_indirect)
+ return TRUE;
+
+ if (!h->pointer_equality_needed)
+ return TRUE;
+
+ if (h->def_regular)
+ return TRUE;
+
+ info = inf;
+ htab = ppc_hash_table (info);
+ if (htab == NULL)
+ return FALSE;
+
+ s = htab->glink;
+ for (pent = h->plt.plist; pent != NULL; pent = pent->next)
+ if (pent->plt.offset != (bfd_vma) -1
+ && pent->addend == 0)
+ {
+ bfd_byte *p;
+ asection *plt;
+ bfd_vma off;
+
+ p = s->contents + h->root.u.def.value;
+ plt = htab->elf.splt;
+ if (!htab->elf.dynamic_sections_created
+ || h->dynindx == -1)
+ plt = htab->elf.iplt;
+ off = pent->plt.offset + plt->output_offset + plt->output_section->vma;
+ off -= h->root.u.def.value + s->output_offset + s->output_section->vma;
+
+ if (off + 0x80008000 > 0xffffffff || (off & 3) != 0)
+ {
+ info->callbacks->einfo
+ (_("%P: linkage table error against `%T'\n"),
+ h->root.root.string);
+ bfd_set_error (bfd_error_bad_value);
+ htab->stub_error = TRUE;
+ }
+
+ if (PPC_HA (off) != 0)
+ {
+ bfd_put_32 (s->owner, ADDIS_R12_R12 | PPC_HA (off), p);
+ p += 4;
+ }
+ bfd_put_32 (s->owner, LD_R12_0R12 | PPC_LO (off), p);
+ p += 4;
+ bfd_put_32 (s->owner, MTCTR_R12, p);
+ p += 4;
+ bfd_put_32 (s->owner, BCTR, p);
+ break;
+ }
+ return TRUE;
+}
+
/* Build all the stubs associated with the current output file.
The stubs are kept in a hash table attached to the main linker
hash table. This function is called via gldelf64ppc_finish. */
h->non_elf = 0;
}
}
- plt0 = htab->plt->output_section->vma + htab->plt->output_offset - 16;
+ plt0 = (htab->elf.splt->output_section->vma
+ + htab->elf.splt->output_offset
+ - 16);
if (info->emitrelocations)
{
Elf_Internal_Rela *r = get_relocs (htab->glink, 1);
/* Build the .glink lazy link call stubs. */
indx = 0;
- while (p < htab->glink->contents + htab->glink->size)
+ while (p < htab->glink->contents + htab->glink->rawsize)
{
if (htab->opd_abi)
{
indx++;
p += 4;
}
- htab->glink->rawsize = p - htab->glink->contents;
+
+ /* Build .glink global entry stubs. */
+ if (htab->glink->size > htab->glink->rawsize)
+ elf_link_hash_traverse (&htab->elf, build_global_entry_stubs, info);
}
if (htab->brlt->size != 0)
bfd_put_32 (htab->elf.dynobj, val, p);
p += 4;
/* .glink size. */
- bfd_put_32 (htab->elf.dynobj, htab->glink->rawsize - 8, p);
+ bfd_put_32 (htab->elf.dynobj, htab->glink->size - 8, p);
p += 4;
/* Augmentation. */
p += 1;
}
if (stub_sec != NULL
- || htab->glink->rawsize != htab->glink->size
|| (htab->glink_eh_frame != NULL
&& htab->glink_eh_frame->rawsize != htab->glink_eh_frame->size))
{
}
else
{
+ bfd_boolean ignored;
+
RELOC_FOR_GLOBAL_SYMBOL (info, input_bfd, input_section, rel,
r_symndx, symtab_hdr, sym_hashes,
h_elf, sec, relocation,
- unresolved_reloc, warned);
+ unresolved_reloc, warned, ignored);
sym_name = h_elf->root.root.string;
sym_type = h_elf->type;
if (sec != NULL
rel->r_info = ELF64_R_INFO (r_symndx, r_type);
}
break;
+
+ case R_PPC64_REL16_HA:
+ /* If we are generating a non-PIC executable, edit
+ . 0: addis 2,12,.TOC.-0b@ha
+ . addi 2,2,.TOC.-0b@l
+ used by ELFv2 global entry points to set up r2, to
+ . lis 2,.TOC.@ha
+ . addi 2,2,.TOC.@l
+ if .TOC. is in range. */
+ if (!info->shared
+ && h != NULL && &h->elf == htab->elf.hgot
+ && rel + 1 < relend
+ && rel[1].r_info == ELF64_R_INFO (r_symndx, R_PPC64_REL16_LO)
+ && rel[1].r_offset == rel->r_offset + 4
+ && rel[1].r_addend == rel->r_addend + 4
+ && relocation + 0x80008000 <= 0xffffffff)
+ {
+ unsigned int insn1, insn2;
+ bfd_vma offset = rel->r_offset - d_offset;
+ insn1 = bfd_get_32 (output_bfd, contents + offset);
+ insn2 = bfd_get_32 (output_bfd, contents + offset + 4);
+ if ((insn1 & 0xffff0000) == 0x3c4c0000 /* addis 2,12 */
+ && (insn2 & 0xffff0000) == 0x38420000 /* addi 2,2 */)
+ {
+ r_type = R_PPC64_ADDR16_HA;
+ rel->r_info = ELF64_R_INFO (r_symndx, r_type);
+ rel->r_addend -= d_offset;
+ rel[1].r_info = ELF64_R_INFO (r_symndx, R_PPC64_ADDR16_LO);
+ rel[1].r_addend -= d_offset + 4;
+ bfd_put_32 (output_bfd, 0x3c400000, contents + offset);
+ }
+ }
+ break;
}
/* Handle other relocations that tweak non-addend part of insn. */
{
info->callbacks->einfo
(_("%P: %H: call to `%T' lacks nop, can't restore toc; "
- "recompile with -fPIC"),
+ "recompile with -fPIC\n"),
input_bfd, input_section, rel->r_offset, sym_name);
bfd_set_error (bfd_error_bad_value);
if (!WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn, info->shared,
&h->elf)
|| (info->shared
- && SYMBOL_CALLS_LOCAL (info, &h->elf)))
+ && SYMBOL_REFERENCES_LOCAL (info, &h->elf)))
/* 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
? h->elf.type == STT_GNU_IFUNC
: ELF_ST_TYPE (sym->st_info) == STT_GNU_IFUNC);
if (ifunc)
- relgot = htab->reliplt;
+ relgot = htab->elf.irelplt;
else if ((info->shared || indx != 0)
&& (h == NULL
|| (tls_type == (TLS_TLS | TLS_LD)
symbol. This happens when statically linking PIC code,
or when using -Bsymbolic. Go find a match if there is a
PLT entry. */
- if (htab->plt != NULL)
+ if (htab->elf.splt != NULL)
{
struct plt_entry *ent;
for (ent = h->elf.plt.plist; ent != NULL; ent = ent->next)
- if (ent->addend == orig_rel.r_addend
- && ent->plt.offset != (bfd_vma) -1)
+ if (ent->plt.offset != (bfd_vma) -1
+ && ent->addend == orig_rel.r_addend)
{
- relocation = (htab->plt->output_section->vma
- + htab->plt->output_offset
+ relocation = (htab->elf.splt->output_section->vma
+ + htab->elf.splt->output_offset
+ ent->plt.offset);
unresolved_reloc = FALSE;
+ break;
}
}
break;
if (skip)
memset (&outrel, 0, sizeof outrel);
- else if (!SYMBOL_CALLS_LOCAL (info, &h->elf)
+ else if (!SYMBOL_REFERENCES_LOCAL (info, &h->elf)
&& !is_opd
&& r_type != R_PPC64_TOC)
{
if (h != NULL
? h->elf.type == STT_GNU_IFUNC
: ELF_ST_TYPE (sym->st_info) == STT_GNU_IFUNC)
- sreloc = htab->reliplt;
+ sreloc = htab->elf.irelplt;
if (sreloc == NULL)
abort ();
&& h->def_regular
&& (h->root.type == bfd_link_hash_defined
|| h->root.type == bfd_link_hash_defweak));
- rela.r_offset = (htab->iplt->output_section->vma
- + htab->iplt->output_offset
+ rela.r_offset = (htab->elf.iplt->output_section->vma
+ + htab->elf.iplt->output_offset
+ ent->plt.offset);
if (htab->opd_abi)
rela.r_info = ELF64_R_INFO (0, R_PPC64_JMP_IREL);
+ h->root.u.def.section->output_offset
+ h->root.u.def.section->output_section->vma
+ ent->addend);
- loc = (htab->reliplt->contents
- + (htab->reliplt->reloc_count++
+ loc = (htab->elf.irelplt->contents
+ + (htab->elf.irelplt->reloc_count++
* sizeof (Elf64_External_Rela)));
}
else
{
- rela.r_offset = (htab->plt->output_section->vma
- + htab->plt->output_offset
+ rela.r_offset = (htab->elf.splt->output_section->vma
+ + htab->elf.splt->output_offset
+ ent->plt.offset);
rela.r_info = ELF64_R_INFO (h->dynindx, R_PPC64_JMP_SLOT);
rela.r_addend = ent->addend;
- loc = (htab->relplt->contents
+ loc = (htab->elf.srelplt->contents
+ ((ent->plt.offset - PLT_INITIAL_ENTRY_SIZE (htab))
/ PLT_ENTRY_SIZE (htab) * sizeof (Elf64_External_Rela)));
}
bfd_elf64_swap_reloca_out (output_bfd, &rela, loc);
+
+ if (!htab->opd_abi)
+ {
+ if (!h->def_regular)
+ {
+ /* Mark the symbol as undefined, rather than as
+ defined in glink. Leave the value if there were
+ any relocations where pointer equality matters
+ (this is a clue for the dynamic linker, to make
+ function pointer comparisons work between an
+ application and shared library), otherwise set it
+ to zero. */
+ sym->st_shndx = SHN_UNDEF;
+ if (!h->pointer_equality_needed)
+ sym->st_value = 0;
+ else if (!h->ref_regular_nonweak)
+ {
+ /* This breaks function pointer comparisons, but
+ that is better than breaking tests for a NULL
+ function pointer. */
+ sym->st_value = 0;
+ }
+ }
+ }
}
if (h->needs_copy)
enum elf_ppc64_reloc_type r_type;
struct ppc_link_hash_table *htab = ppc_hash_table (info);
- if (rel_sec == htab->reliplt)
+ if (rel_sec == htab->elf.irelplt)
return reloc_class_ifunc;
r_type = ELF64_R_TYPE (rela->r_info);
{
Elf64_External_Dyn *dyncon, *dynconend;
- if (sdyn == NULL || htab->got == NULL)
+ if (sdyn == NULL || htab->elf.sgot == NULL)
abort ();
dyncon = (Elf64_External_Dyn *) sdyn->contents;
break;
case DT_PLTGOT:
- s = htab->plt;
+ s = htab->elf.splt;
dyn.d_un.d_ptr = s->output_section->vma + s->output_offset;
break;
case DT_JMPREL:
- s = htab->relplt;
+ s = htab->elf.srelplt;
dyn.d_un.d_ptr = s->output_section->vma + s->output_offset;
break;
case DT_PLTRELSZ:
- dyn.d_un.d_val = htab->relplt->size;
+ dyn.d_un.d_val = htab->elf.srelplt->size;
break;
case DT_RELASZ:
/* Don't count procedure linkage table relocs in the
overall reloc count. */
- s = htab->relplt;
+ s = htab->elf.srelplt;
if (s == NULL)
continue;
dyn.d_un.d_val -= s->size;
/* We may not be using the standard ELF linker script.
If .rela.plt is the first .rela section, we adjust
DT_RELA to not include it. */
- s = htab->relplt;
+ s = htab->elf.srelplt;
if (s == NULL)
continue;
if (dyn.d_un.d_ptr != s->output_section->vma + s->output_offset)
}
}
- if (htab->got != NULL && htab->got->size != 0)
+ if (htab->elf.sgot != NULL && htab->elf.sgot->size != 0)
{
/* Fill in the first entry in the global offset table.
We use it to hold the link-time TOCbase. */
bfd_put_64 (output_bfd,
elf_gp (output_bfd) + TOC_BASE_OFF,
- htab->got->contents);
+ htab->elf.sgot->contents);
/* Set .got entry size. */
- elf_section_data (htab->got->output_section)->this_hdr.sh_entsize = 8;
+ elf_section_data (htab->elf.sgot->output_section)->this_hdr.sh_entsize = 8;
}
- if (htab->plt != NULL && htab->plt->size != 0)
+ if (htab->elf.splt != NULL && htab->elf.splt->size != 0)
{
/* Set .plt entry size. */
- elf_section_data (htab->plt->output_section)->this_hdr.sh_entsize
+ elf_section_data (htab->elf.splt->output_section)->this_hdr.sh_entsize
= PLT_ENTRY_SIZE (htab);
}