2009 Free Software Foundation, Inc.
Written by Linus Nordberg, Swox AB <info@swox.com>,
based on elf32-ppc.c by Ian Lance Taylor.
- Largely rewritten by Alan Modra <amodra@bigpond.net.au>
+ Largely rewritten by Alan Modra.
This file is part of BFD, the Binary File Descriptor library.
#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
/* The name of the dynamic interpreter. This is put in the .interp
section. */
0xffff, /* dst_mask */
FALSE), /* pcrel_offset */
+ HOWTO (R_PPC64_JMP_IREL, /* type */
+ 0, /* rightshift */
+ 0, /* size (0=byte, 1=short, 2=long, 4=64 bits) */
+ 0, /* bitsize */
+ FALSE, /* pc_relative */
+ 0, /* bitpos */
+ complain_overflow_dont, /* complain_on_overflow */
+ ppc64_elf_unhandled_reloc, /* special_function */
+ "R_PPC64_JMP_IREL", /* name */
+ FALSE, /* partial_inplace */
+ 0, /* src_mask */
+ 0, /* dst_mask */
+ FALSE), /* pcrel_offset */
+
+ HOWTO (R_PPC64_IRELATIVE, /* type */
+ 0, /* rightshift */
+ 4, /* size (0=byte, 1=short, 2=long, 4=64 bits) */
+ 64, /* bitsize */
+ FALSE, /* pc_relative */
+ 0, /* bitpos */
+ complain_overflow_dont, /* complain_on_overflow */
+ bfd_elf_generic_reloc, /* special_function */
+ "R_PPC64_IRELATIVE", /* name */
+ FALSE, /* partial_inplace */
+ 0, /* src_mask */
+ ONES (64), /* dst_mask */
+ FALSE), /* pcrel_offset */
+
+ /* A 16 bit relative relocation. */
+ HOWTO (R_PPC64_REL16, /* type */
+ 0, /* rightshift */
+ 1, /* size (0 = byte, 1 = short, 2 = long) */
+ 16, /* bitsize */
+ TRUE, /* pc_relative */
+ 0, /* bitpos */
+ complain_overflow_bitfield, /* complain_on_overflow */
+ bfd_elf_generic_reloc, /* special_function */
+ "R_PPC64_REL16", /* name */
+ FALSE, /* partial_inplace */
+ 0, /* src_mask */
+ 0xffff, /* dst_mask */
+ TRUE), /* pcrel_offset */
+
+ /* A 16 bit relative relocation without overflow. */
+ HOWTO (R_PPC64_REL16_LO, /* type */
+ 0, /* rightshift */
+ 1, /* size (0 = byte, 1 = short, 2 = long) */
+ 16, /* bitsize */
+ TRUE, /* pc_relative */
+ 0, /* bitpos */
+ complain_overflow_dont,/* complain_on_overflow */
+ bfd_elf_generic_reloc, /* special_function */
+ "R_PPC64_REL16_LO", /* name */
+ FALSE, /* partial_inplace */
+ 0, /* src_mask */
+ 0xffff, /* dst_mask */
+ TRUE), /* pcrel_offset */
+
+ /* The high order 16 bits of a relative address. */
+ HOWTO (R_PPC64_REL16_HI, /* type */
+ 16, /* rightshift */
+ 1, /* size (0 = byte, 1 = short, 2 = long) */
+ 16, /* bitsize */
+ TRUE, /* pc_relative */
+ 0, /* bitpos */
+ complain_overflow_dont, /* complain_on_overflow */
+ bfd_elf_generic_reloc, /* special_function */
+ "R_PPC64_REL16_HI", /* name */
+ FALSE, /* partial_inplace */
+ 0, /* src_mask */
+ 0xffff, /* dst_mask */
+ TRUE), /* pcrel_offset */
+
+ /* The high order 16 bits of a relative address, plus 1 if the contents of
+ the low 16 bits, treated as a signed number, is negative. */
+ HOWTO (R_PPC64_REL16_HA, /* type */
+ 16, /* rightshift */
+ 1, /* size (0 = byte, 1 = short, 2 = long) */
+ 16, /* bitsize */
+ TRUE, /* pc_relative */
+ 0, /* bitpos */
+ complain_overflow_dont, /* complain_on_overflow */
+ ppc64_elf_ha_reloc, /* special_function */
+ "R_PPC64_REL16_HA", /* name */
+ FALSE, /* partial_inplace */
+ 0, /* src_mask */
+ 0xffff, /* dst_mask */
+ TRUE), /* pcrel_offset */
+
/* GNU extension to record C++ vtable hierarchy. */
HOWTO (R_PPC64_GNU_VTINHERIT, /* type */
0, /* rightshift */
break;
case BFD_RELOC_PPC64_DTPREL16_HIGHESTA: r = R_PPC64_DTPREL16_HIGHESTA;
break;
+ case BFD_RELOC_16_PCREL: r = R_PPC64_REL16;
+ break;
+ case BFD_RELOC_LO16_PCREL: r = R_PPC64_REL16_LO;
+ break;
+ case BFD_RELOC_HI16_PCREL: r = R_PPC64_REL16_HI;
+ break;
+ case BFD_RELOC_HI16_S_PCREL: r = R_PPC64_REL16_HA;
+ break;
case BFD_RELOC_VTABLE_INHERIT: r = R_PPC64_GNU_VTINHERIT;
break;
case BFD_RELOC_VTABLE_ENTRY: r = R_PPC64_GNU_VTENTRY;
{
bfd_vma ent;
+ /* Ignore bogus symbols. */
+ if (syms[i]->value > opd->size - 8)
+ continue;
+
ent = bfd_get_64 (abfd, contents + syms[i]->value);
if (!sym_exists_at (syms, opdsymend, symcount, -1, ent))
{
p = relplt->relocation;
for (i = 0; i < plt_count; i++, p++)
- size += strlen ((*p->sym_ptr_ptr)->name) + sizeof ("@plt");
+ {
+ size += strlen ((*p->sym_ptr_ptr)->name) + sizeof ("@plt");
+ if (p->addend != 0)
+ size += sizeof ("+0x") - 1 + 16;
+ }
}
}
{
bfd_vma ent;
+ if (syms[i]->value > opd->size - 8)
+ continue;
+
ent = bfd_get_64 (abfd, contents + syms[i]->value);
if (!sym_exists_at (syms, opdsymend, symcount, -1, ent))
{
len = strlen ((*p->sym_ptr_ptr)->name);
memcpy (names, (*p->sym_ptr_ptr)->name, len);
names += len;
+ if (p->addend != 0)
+ {
+ memcpy (names, "+0x", sizeof ("+0x") - 1);
+ names += sizeof ("+0x") - 1;
+ bfd_sprintf_vma (abfd, names, p->addend);
+ names += strlen (names);
+ }
memcpy (names, "@plt", sizeof ("@plt"));
names += sizeof ("@plt");
s++;
/* The symbol table entry, if any, that this was derived from. */
struct ppc_link_hash_entry *h;
+ struct plt_entry *plt_ent;
/* And the reloc addend that this was derived from. */
bfd_vma addend;
#define TLS_TLS 16 /* Any TLS reloc. */
#define TLS_EXPLICIT 32 /* Marks TOC section TLS relocs. */
#define TLS_TPRELGD 64 /* TPREL reloc resulting from GD->IE. */
+#define PLT_IFUNC 128 /* STT_GNU_IFUNC. */
char tls_mask;
};
asection *got;
asection *plt;
asection *relplt;
+ asection *iplt;
+ asection *reliplt;
asection *dynbss;
asection *relbss;
asection *glink;
/* Set if we should emit symbols for stubs. */
unsigned int emit_stub_syms:1;
+ /* Set if __tls_get_addr optimization should not be done. */
+ unsigned int no_tls_get_addr_opt:1;
+
/* Support for multiple toc sections. */
unsigned int no_multi_toc:1;
unsigned int multi_toc_needed:1;
/* Incremented every time we size stubs. */
unsigned int stub_iteration;
- /* Small local sym to section mapping cache. */
- struct sym_sec_cache sym_sec;
+ /* Small local sym cache. */
+ struct sym_cache sym_cache;
};
/* Rename some of the generic section flags to better document how they
|| ! bfd_set_section_alignment (dynobj, htab->glink, 3))
return FALSE;
+ 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))
+ 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))
+ return FALSE;
+
/* Create branch lookup table for plt_branch stubs. */
flags = (SEC_ALLOC | SEC_LOAD
| SEC_HAS_CONTENTS | SEC_IN_MEMORY | SEC_LINKER_CREATED);
htab->relbrlt = bfd_make_section_anyway_with_flags (dynobj,
".rela.branch_lt",
flags);
- if (!htab->relbrlt
+ if (htab->relbrlt == NULL
|| ! bfd_set_section_alignment (dynobj, htab->relbrlt, 3))
return FALSE;
return TRUE;
}
+/* Follow indirect and warning symbol links. */
+
+static inline struct bfd_link_hash_entry *
+follow_link (struct bfd_link_hash_entry *h)
+{
+ while (h->type == bfd_link_hash_indirect
+ || h->type == bfd_link_hash_warning)
+ h = h->u.i.link;
+ return h;
+}
+
+static inline struct elf_link_hash_entry *
+elf_follow_link (struct elf_link_hash_entry *h)
+{
+ return (struct elf_link_hash_entry *) follow_link (&h->root);
+}
+
+static inline struct ppc_link_hash_entry *
+ppc_follow_link (struct ppc_link_hash_entry *h)
+{
+ return (struct ppc_link_hash_entry *) follow_link (&h->elf.root);
+}
+
/* Merge PLT info on FROM with that on TO. */
static void
edir->is_func |= eind->is_func;
edir->is_func_descriptor |= eind->is_func_descriptor;
edir->tls_mask |= eind->tls_mask;
+ if (eind->oh != NULL)
+ edir->oh = ppc_follow_link (eind->oh);
/* If called to transfer flags for a weakdef during processing
of elf_adjust_dynamic_symbol, don't copy NON_GOT_REF.
hash entry FH. Link the entries via their OH fields. */
static struct ppc_link_hash_entry *
-get_fdh (struct ppc_link_hash_entry *fh, struct ppc_link_hash_table *htab)
+lookup_fdh (struct ppc_link_hash_entry *fh, struct ppc_link_hash_table *htab)
{
struct ppc_link_hash_entry *fdh = fh->oh;
fdh = (struct ppc_link_hash_entry *)
elf_link_hash_lookup (&htab->elf, fd_name, FALSE, FALSE, FALSE);
- if (fdh != NULL)
- {
- fdh->is_func_descriptor = 1;
- fdh->oh = fh;
- fh->is_func = 1;
- fh->oh = fdh;
- }
+ if (fdh == NULL)
+ return fdh;
+
+ fdh->is_func_descriptor = 1;
+ fdh->oh = fh;
+ fh->is_func = 1;
+ fh->oh = fdh;
}
- return fdh;
+ return ppc_follow_link (fdh);
}
/* Make a fake function descriptor sym for the code sym FH. */
static bfd_boolean
ppc64_elf_add_symbol_hook (bfd *ibfd ATTRIBUTE_UNUSED,
- struct bfd_link_info *info ATTRIBUTE_UNUSED,
+ struct bfd_link_info *info,
Elf_Internal_Sym *isym,
const char **name ATTRIBUTE_UNUSED,
flagword *flags ATTRIBUTE_UNUSED,
asection **sec,
bfd_vma *value ATTRIBUTE_UNUSED)
{
- if (*sec != NULL
- && strcmp (bfd_get_section_name (ibfd, *sec), ".opd") == 0)
+ if (ELF_ST_TYPE (isym->st_info) == STT_GNU_IFUNC)
+ elf_tdata (info->output_bfd)->has_ifunc_symbols = TRUE;
+ else if (ELF_ST_TYPE (isym->st_info) == STT_FUNC)
+ ;
+ else if (*sec != NULL
+ && strcmp (bfd_get_section_name (ibfd, *sec), ".opd") == 0)
isym->st_info = ELF_ST_INFO (ELF_ST_BIND (isym->st_info), STT_FUNC);
return TRUE;
abort ();
htab = ppc_hash_table (info);
- fdh = get_fdh (eh, htab);
- if (fdh == NULL
- && !info->relocatable
- && (eh->elf.root.type == bfd_link_hash_undefined
- || eh->elf.root.type == bfd_link_hash_undefweak)
- && eh->elf.ref_regular)
- {
- /* Make an undefweak function descriptor sym, which is enough to
- pull in an --as-needed shared lib, but won't cause link
- errors. Archives are handled elsewhere. */
- fdh = make_fdh (info, eh);
- if (fdh == NULL)
- return FALSE;
- else
- fdh->elf.ref_regular = 1;
+ fdh = lookup_fdh (eh, htab);
+ if (fdh == NULL)
+ {
+ if (!info->relocatable
+ && (eh->elf.root.type == bfd_link_hash_undefined
+ || eh->elf.root.type == bfd_link_hash_undefweak)
+ && eh->elf.ref_regular)
+ {
+ /* Make an undefweak function descriptor sym, which is enough to
+ pull in an --as-needed shared lib, but won't cause link
+ errors. Archives are handled elsewhere. */
+ fdh = make_fdh (info, eh);
+ if (fdh == NULL)
+ return FALSE;
+ fdh->elf.ref_regular = 1;
+ }
}
- else if (fdh != NULL)
+ else
{
unsigned entry_vis = ELF_ST_VISIBILITY (eh->elf.other) - 1;
unsigned descr_vis = ELF_ST_VISIBILITY (fdh->elf.other) - 1;
return TRUE;
}
-static bfd_boolean
+static struct plt_entry **
update_local_sym_info (bfd *abfd, Elf_Internal_Shdr *symtab_hdr,
unsigned long r_symndx, bfd_vma r_addend, int tls_type)
{
struct got_entry **local_got_ents = elf_local_got_ents (abfd);
+ struct plt_entry **local_plt;
char *local_got_tls_masks;
if (local_got_ents == NULL)
{
bfd_size_type size = symtab_hdr->sh_info;
- size *= sizeof (*local_got_ents) + sizeof (*local_got_tls_masks);
+ size *= (sizeof (*local_got_ents)
+ + sizeof (*local_plt)
+ + sizeof (*local_got_tls_masks));
local_got_ents = bfd_zalloc (abfd, size);
if (local_got_ents == NULL)
- return FALSE;
+ return NULL;
elf_local_got_ents (abfd) = local_got_ents;
}
- if ((tls_type & TLS_EXPLICIT) == 0)
+ if ((tls_type & (PLT_IFUNC | TLS_EXPLICIT)) == 0)
{
struct got_entry *ent;
ent->got.refcount += 1;
}
- local_got_tls_masks = (char *) (local_got_ents + symtab_hdr->sh_info);
+ local_plt = (struct plt_entry **) (local_got_ents + symtab_hdr->sh_info);
+ local_got_tls_masks = (char *) (local_plt + symtab_hdr->sh_info);
local_got_tls_masks[r_symndx] |= tls_type;
- return TRUE;
+
+ return local_plt + r_symndx;
}
static bfd_boolean
-update_plt_info (bfd *abfd, struct ppc_link_hash_entry *eh, bfd_vma addend)
+update_plt_info (bfd *abfd, struct plt_entry **plist, bfd_vma addend)
{
struct plt_entry *ent;
- for (ent = eh->elf.plt.plist; ent != NULL; ent = ent->next)
+ for (ent = *plist; ent != NULL; ent = ent->next)
if (ent->addend == addend)
break;
if (ent == NULL)
ent = bfd_alloc (abfd, amt);
if (ent == NULL)
return FALSE;
- ent->next = eh->elf.plt.plist;
+ ent->next = *plist;
ent->addend = addend;
ent->plt.refcount = 0;
- eh->elf.plt.plist = ent;
+ *plist = ent;
}
ent->plt.refcount += 1;
- eh->elf.needs_plt = 1;
- if (eh->elf.root.root.string[0] == '.'
- && eh->elf.root.root.string[1] != '\0')
- eh->is_func = 1;
return TRUE;
}
+static bfd_boolean
+is_branch_reloc (enum elf_ppc64_reloc_type r_type)
+{
+ return (r_type == R_PPC64_REL24
+ || r_type == R_PPC64_REL14
+ || r_type == R_PPC64_REL14_BRTAKEN
+ || r_type == R_PPC64_REL14_BRNTAKEN
+ || r_type == R_PPC64_ADDR24
+ || r_type == R_PPC64_ADDR14
+ || r_type == R_PPC64_ADDR14_BRTAKEN
+ || r_type == R_PPC64_ADDR14_BRNTAKEN);
+}
+
/* Look through the relocs for a section during the first phase, and
calculate needed space in the global offset table, procedure
linkage table, and dynamic reloc sections. */
enum elf_ppc64_reloc_type r_type;
int tls_type;
struct _ppc64_elf_section_data *ppc64_sec;
+ struct plt_entry **ifunc;
r_symndx = ELF64_R_SYM (rel->r_info);
if (r_symndx < symtab_hdr->sh_info)
else
{
h = sym_hashes[r_symndx - symtab_hdr->sh_info];
- while (h->root.type == bfd_link_hash_indirect
- || h->root.type == bfd_link_hash_warning)
- h = (struct elf_link_hash_entry *) h->root.u.i.link;
+ h = elf_follow_link (h);
}
tls_type = 0;
+ ifunc = NULL;
+ if (h != NULL)
+ {
+ if (h->type == STT_GNU_IFUNC)
+ {
+ h->needs_plt = 1;
+ ifunc = &h->plt.plist;
+ }
+ }
+ else
+ {
+ Elf_Internal_Sym *isym = bfd_sym_from_r_symndx (&htab->sym_cache,
+ abfd, r_symndx);
+ if (isym == NULL)
+ return FALSE;
+
+ if (ELF_ST_TYPE (isym->st_info) == STT_GNU_IFUNC)
+ {
+ ifunc = update_local_sym_info (abfd, symtab_hdr, r_symndx,
+ rel->r_addend, PLT_IFUNC);
+ if (ifunc == NULL)
+ return FALSE;
+ }
+ }
r_type = ELF64_R_TYPE (rel->r_info);
- if (h != NULL && (h == tga || h == dottga))
- switch (r_type)
- {
- default:
- break;
+ if (is_branch_reloc (r_type))
+ {
+ if (h != NULL && (h == tga || h == dottga))
+ {
+ if (rel != relocs
+ && (ELF64_R_TYPE (rel[-1].r_info) == R_PPC64_TLSGD
+ || ELF64_R_TYPE (rel[-1].r_info) == R_PPC64_TLSLD))
+ /* We have a new-style __tls_get_addr call with a marker
+ reloc. */
+ ;
+ else
+ /* Mark this section as having an old-style call. */
+ sec->has_tls_get_addr_call = 1;
+ }
- case R_PPC64_REL24:
- case R_PPC64_REL14:
- case R_PPC64_REL14_BRTAKEN:
- case R_PPC64_REL14_BRNTAKEN:
- case R_PPC64_ADDR24:
- case R_PPC64_ADDR14:
- case R_PPC64_ADDR14_BRTAKEN:
- case R_PPC64_ADDR14_BRNTAKEN:
- if (rel != relocs
- && (ELF64_R_TYPE (rel[-1].r_info) == R_PPC64_TLSGD
- || ELF64_R_TYPE (rel[-1].r_info) == R_PPC64_TLSLD))
- /* We have a new-style __tls_get_addr call with a marker
- reloc. */
- ;
- else
- /* Mark this section as having an old-style call. */
- sec->has_tls_get_addr_call = 1;
- break;
- }
+ /* STT_GNU_IFUNC symbols must have a PLT entry. */
+ if (ifunc != NULL
+ && !update_plt_info (abfd, ifunc, rel->r_addend))
+ return FALSE;
+ }
switch (r_type)
{
return FALSE;
}
else
- if (!update_plt_info (abfd, (struct ppc_link_hash_entry *) h,
- rel->r_addend))
- return FALSE;
+ {
+ if (!update_plt_info (abfd, &h->plt.plist, rel->r_addend))
+ return FALSE;
+ h->needs_plt = 1;
+ if (h->root.root.string[0] == '.'
+ && h->root.root.string[1] != '\0')
+ ((struct ppc_link_hash_entry *) h)->is_func = 1;
+ }
break;
/* The following relocations don't need to propagate the
break;
/* Nor do these. */
+ case R_PPC64_REL16:
+ case R_PPC64_REL16_LO:
+ case R_PPC64_REL16_HI:
+ case R_PPC64_REL16_HA:
+ break;
+
case R_PPC64_TOC16:
case R_PPC64_TOC16_LO:
case R_PPC64_TOC16_HI:
dest = h->root.u.def.section;
}
else
- dest = bfd_section_from_r_symndx (abfd, &htab->sym_sec,
- sec, r_symndx);
+ {
+ Elf_Internal_Sym *isym;
+
+ isym = bfd_sym_from_r_symndx (&htab->sym_cache,
+ abfd, r_symndx);
+ if (isym == NULL)
+ return FALSE;
+
+ dest = bfd_section_from_elf_index (abfd, isym->st_shndx);
+ }
+
if (dest != sec)
ppc64_elf_section_data (sec)->has_14bit_branch = 1;
}
/* Fall through. */
case R_PPC64_REL24:
- if (h != NULL)
+ if (h != NULL && ifunc == NULL)
{
/* We may need a .plt entry if the function this reloc
refers to is in a shared lib. */
- if (!update_plt_info (abfd, (struct ppc_link_hash_entry *) h,
- rel->r_addend))
+ if (!update_plt_info (abfd, &h->plt.plist, rel->r_addend))
return FALSE;
+ h->needs_plt = 1;
+ if (h->root.root.string[0] == '.'
+ && h->root.root.string[1] != '\0')
+ ((struct ppc_link_hash_entry *) h)->is_func = 1;
if (h == tga || h == dottga)
sec->has_tls_reloc = 1;
}
{
if (h->root.root.string[0] == '.'
&& h->root.root.string[1] != 0
- && get_fdh ((struct ppc_link_hash_entry *) h, htab))
+ && lookup_fdh ((struct ppc_link_hash_entry *) h, htab))
;
else
((struct ppc_link_hash_entry *) h)->is_func = 1;
else
{
asection *s;
+ Elf_Internal_Sym *isym;
- s = bfd_section_from_r_symndx (abfd, &htab->sym_sec, sec,
- r_symndx);
- if (s == NULL)
+ isym = bfd_sym_from_r_symndx (&htab->sym_cache,
+ abfd, r_symndx);
+ if (isym == NULL)
return FALSE;
- else if (s != sec)
+
+ s = bfd_section_from_elf_index (abfd, isym->st_shndx);
+ if (s != NULL && s != sec)
opd_sym_map[rel->r_offset / 8] = s;
}
}
&& !info->shared
&& h != NULL
&& (h->root.type == bfd_link_hash_defweak
- || !h->def_regular)))
+ || !h->def_regular))
+ || (!info->shared
+ && ifunc != NULL))
{
struct ppc_dyn_relocs *p;
struct ppc_dyn_relocs **head;
/* Track dynamic relocs needed for local syms too.
We really need local syms available to do this
easily. Oh well. */
-
asection *s;
void *vpp;
+ Elf_Internal_Sym *isym;
- s = bfd_section_from_r_symndx (abfd, &htab->sym_sec,
- sec, r_symndx);
- if (s == NULL)
+ isym = bfd_sym_from_r_symndx (&htab->sym_cache,
+ abfd, r_symndx);
+ if (isym == NULL)
return FALSE;
+ s = bfd_section_from_elf_index (abfd, isym->st_shndx);
+ if (s == NULL)
+ s = sec;
+
vpp = &elf_section_data (s)->local_dynrel;
head = (struct ppc_dyn_relocs **) vpp;
}
/* No relocs implies we are linking a --just-symbols object. */
if (opd_sec->reloc_count == 0)
{
- bfd_vma val;
-
if (!bfd_get_section_contents (opd_bfd, opd_sec, &val, offset, 8))
return (bfd_vma) -1;
sym_hashes = elf_sym_hashes (opd_bfd);
rh = sym_hashes[symndx - symtab_hdr->sh_info];
- while (rh->root.type == bfd_link_hash_indirect
- || rh->root.type == bfd_link_hash_warning)
- rh = ((struct elf_link_hash_entry *) rh->root.u.i.link);
+ rh = elf_follow_link (rh);
BFD_ASSERT (rh->root.type == bfd_link_hash_defined
|| rh->root.type == bfd_link_hash_defweak);
val = rh->root.u.def.value;
return val;
}
+/* If FDH is a function descriptor symbol, return the associated code
+ entry symbol if it is defined. Return NULL otherwise. */
+
+static struct ppc_link_hash_entry *
+defined_code_entry (struct ppc_link_hash_entry *fdh)
+{
+ if (fdh->is_func_descriptor)
+ {
+ struct ppc_link_hash_entry *fh = ppc_follow_link (fdh->oh);
+ if (fh->elf.root.type == bfd_link_hash_defined
+ || fh->elf.root.type == bfd_link_hash_defweak)
+ return fh;
+ }
+ return NULL;
+}
+
+/* If FH is a function code entry symbol, return the associated
+ function descriptor symbol if it is defined. Return NULL otherwise. */
+
+static struct ppc_link_hash_entry *
+defined_func_desc (struct ppc_link_hash_entry *fh)
+{
+ if (fh->oh != NULL
+ && fh->oh->is_func_descriptor)
+ {
+ struct ppc_link_hash_entry *fdh = ppc_follow_link (fh->oh);
+ if (fdh->elf.root.type == bfd_link_hash_defined
+ || fdh->elf.root.type == bfd_link_hash_defweak)
+ return fdh;
+ }
+ return NULL;
+}
+
/* Mark all our entry sym sections, both opd and code section. */
static void
for (sym = info->gc_sym_list; sym != NULL; sym = sym->next)
{
- struct ppc_link_hash_entry *eh;
+ struct ppc_link_hash_entry *eh, *fh;
asection *sec;
eh = (struct ppc_link_hash_entry *)
- elf_link_hash_lookup (&htab->elf, sym->name, FALSE, FALSE, FALSE);
+ elf_link_hash_lookup (&htab->elf, sym->name, FALSE, FALSE, TRUE);
if (eh == NULL)
continue;
if (eh->elf.root.type != bfd_link_hash_defined
&& eh->elf.root.type != bfd_link_hash_defweak)
continue;
- if (eh->is_func_descriptor
- && (eh->oh->elf.root.type == bfd_link_hash_defined
- || eh->oh->elf.root.type == bfd_link_hash_defweak))
+ fh = defined_code_entry (eh);
+ if (fh != NULL)
{
- sec = eh->oh->elf.root.u.def.section;
+ sec = fh->elf.root.u.def.section;
sec->flags |= SEC_KEEP;
}
else if (get_opd_info (eh->elf.root.u.def.section) != NULL
{
struct bfd_link_info *info = (struct bfd_link_info *) inf;
struct ppc_link_hash_entry *eh = (struct ppc_link_hash_entry *) h;
+ struct ppc_link_hash_entry *fdh;
if (eh->elf.root.type == bfd_link_hash_warning)
eh = (struct ppc_link_hash_entry *) eh->elf.root.u.i.link;
/* Dynamic linking info is on the func descriptor sym. */
- if (eh->oh != NULL
- && eh->oh->is_func_descriptor
- && (eh->oh->elf.root.type == bfd_link_hash_defined
- || eh->oh->elf.root.type == bfd_link_hash_defweak))
- eh = eh->oh;
+ fdh = defined_func_desc (eh);
+ if (fdh != NULL)
+ eh = fdh;
if ((eh->elf.root.type == bfd_link_hash_defined
|| eh->elf.root.type == bfd_link_hash_defweak)
&& ELF_ST_VISIBILITY (eh->elf.other) != STV_HIDDEN)))
{
asection *code_sec;
+ struct ppc_link_hash_entry *fh;
eh->elf.root.u.def.section->flags |= SEC_KEEP;
/* Function descriptor syms cause the associated
function code sym section to be marked. */
- if (eh->is_func_descriptor
- && (eh->oh->elf.root.type == bfd_link_hash_defined
- || eh->oh->elf.root.type == bfd_link_hash_defweak))
- eh->oh->elf.root.u.def.section->flags |= SEC_KEEP;
+ fh = defined_code_entry (eh);
+ if (fh != NULL)
+ {
+ code_sec = fh->elf.root.u.def.section;
+ code_sec->flags |= SEC_KEEP;
+ }
else if (get_opd_info (eh->elf.root.u.def.section) != NULL
&& opd_entry_value (eh->elf.root.u.def.section,
eh->elf.root.u.def.value,
if (h != NULL)
{
enum elf_ppc64_reloc_type r_type;
- struct ppc_link_hash_entry *eh;
+ struct ppc_link_hash_entry *eh, *fh, *fdh;
r_type = ELF64_R_TYPE (rel->r_info);
switch (r_type)
case bfd_link_hash_defined:
case bfd_link_hash_defweak:
eh = (struct ppc_link_hash_entry *) h;
- if (eh->oh != NULL
- && eh->oh->is_func_descriptor
- && (eh->oh->elf.root.type == bfd_link_hash_defined
- || eh->oh->elf.root.type == bfd_link_hash_defweak))
- eh = eh->oh;
+ fdh = defined_func_desc (eh);
+ if (fdh != NULL)
+ eh = fdh;
/* Function descriptor syms cause the associated
function code sym section to be marked. */
- if (eh->is_func_descriptor
- && (eh->oh->elf.root.type == bfd_link_hash_defined
- || eh->oh->elf.root.type == bfd_link_hash_defweak))
+ fh = defined_code_entry (eh);
+ if (fh != NULL)
{
/* They also mark their opd section. */
eh->elf.root.u.def.section->gc_mark = 1;
- rsec = eh->oh->elf.root.u.def.section;
+ rsec = fh->elf.root.u.def.section;
}
else if (get_opd_info (eh->elf.root.u.def.section) != NULL
&& opd_entry_value (eh->elf.root.u.def.section,
struct ppc_dyn_relocs *p;
h = sym_hashes[r_symndx - symtab_hdr->sh_info];
- while (h->root.type == bfd_link_hash_indirect
- || h->root.type == bfd_link_hash_warning)
- h = (struct elf_link_hash_entry *) h->root.u.i.link;
+ h = elf_follow_link (h);
eh = (struct ppc_link_hash_entry *) h;
for (pp = &eh->dyn_relocs; (p = *pp) != NULL; pp = &p->next)
}
}
+ if (is_branch_reloc (r_type))
+ {
+ struct plt_entry **ifunc = NULL;
+ if (h != NULL)
+ {
+ if (h->type == STT_GNU_IFUNC)
+ ifunc = &h->plt.plist;
+ }
+ else if (local_got_ents != NULL)
+ {
+ struct plt_entry **local_plt = (struct plt_entry **)
+ (local_got_ents + symtab_hdr->sh_info);
+ char *local_got_tls_masks = (char *)
+ (local_plt + symtab_hdr->sh_info);
+ if ((local_got_tls_masks[r_symndx] & PLT_IFUNC) != 0)
+ ifunc = local_plt + r_symndx;
+ }
+ if (ifunc != NULL)
+ {
+ struct plt_entry *ent;
+
+ for (ent = *ifunc; ent != NULL; ent = ent->next)
+ if (ent->addend == rel->r_addend)
+ break;
+ if (ent == NULL)
+ abort ();
+ if (ent->plt.refcount > 0)
+ ent->plt.refcount -= 1;
+ continue;
+ }
+ }
+
switch (r_type)
{
case R_PPC64_GOT_TLSLD16:
for (ent = h->plt.plist; ent != NULL; ent = ent->next)
if (ent->addend == rel->r_addend)
break;
- if (ent == NULL)
- abort ();
- if (ent->plt.refcount > 0)
+ if (ent != NULL && ent->plt.refcount > 0)
ent->plt.refcount -= 1;
}
break;
in dynamic objects are handled elsewhere. */
if (fh->elf.root.type == bfd_link_hash_undefweak
&& fh->was_undefined
- && (fh->oh->elf.root.type == bfd_link_hash_defined
- || fh->oh->elf.root.type == bfd_link_hash_defweak)
- && get_opd_info (fh->oh->elf.root.u.def.section) != NULL
- && opd_entry_value (fh->oh->elf.root.u.def.section,
- fh->oh->elf.root.u.def.value,
+ && (fdh = defined_func_desc (fh)) != NULL
+ && get_opd_info (fdh->elf.root.u.def.section) != NULL
+ && opd_entry_value (fdh->elf.root.u.def.section,
+ fdh->elf.root.u.def.value,
&fh->elf.root.u.def.section,
&fh->elf.root.u.def.value) != (bfd_vma) -1)
{
- fh->elf.root.type = fh->oh->elf.root.type;
+ fh->elf.root.type = fdh->elf.root.type;
fh->elf.forced_local = 1;
- fh->elf.def_regular = fh->oh->elf.def_regular;
- fh->elf.def_dynamic = fh->oh->elf.def_dynamic;
+ fh->elf.def_regular = fdh->elf.def_regular;
+ fh->elf.def_dynamic = fdh->elf.def_dynamic;
}
/* If this is a function code symbol, transfer dynamic linking
/* Find the corresponding function descriptor symbol. Create it
as undefined if necessary. */
- fdh = get_fdh (fh, htab);
- if (fdh != NULL)
- while (fdh->elf.root.type == bfd_link_hash_indirect
- || fdh->elf.root.type == bfd_link_hash_warning)
- fdh = (struct ppc_link_hash_entry *) fdh->elf.root.u.i.link;
-
+ fdh = lookup_fdh (fh, htab);
if (fdh == NULL
&& !info->executable
&& (fh->elf.root.type == bfd_link_hash_undefined
/* Deal with function syms. */
if (h->type == STT_FUNC
+ || h->type == STT_GNU_IFUNC
|| h->needs_plt)
{
/* Clear procedure linkage table information for any symbol that
if (ent->plt.refcount > 0)
break;
if (ent == NULL
- || SYMBOL_CALLS_LOCAL (info, h)
- || (ELF_ST_VISIBILITY (h->other) != STV_DEFAULT
- && h->root.type == bfd_link_hash_undefweak))
+ || (h->type != STT_GNU_IFUNC
+ && (SYMBOL_CALLS_LOCAL (info, h)
+ || (ELF_ST_VISIBILITY (h->other) != STV_DEFAULT
+ && h->root.type == bfd_link_hash_undefweak))))
{
h->plt.plist = NULL;
h->needs_plt = 0;
struct elf_link_hash_entry *h;
h = sym_hashes[r_symndx - symtab_hdr->sh_info];
- while (h->root.type == bfd_link_hash_indirect
- || h->root.type == bfd_link_hash_warning)
- h = (struct elf_link_hash_entry *) h->root.u.i.link;
+ h = elf_follow_link (h);
if (hp != NULL)
*hp = h;
lgot_ents = elf_local_got_ents (ibfd);
if (lgot_ents != NULL)
{
- char *lgot_masks = (char *) (lgot_ents + symtab_hdr->sh_info);
+ struct plt_entry **local_plt = (struct plt_entry **)
+ (lgot_ents + symtab_hdr->sh_info);
+ char *lgot_masks = (char *)
+ (local_plt + symtab_hdr->sh_info);
tls_mask = &lgot_masks[r_symndx];
}
*tls_maskp = tls_mask;
{
Elf_Internal_Rela *write_rel;
bfd_byte *rptr, *wptr;
- bfd_byte *new_contents = NULL;
+ bfd_byte *new_contents;
bfd_boolean skip;
long opd_ent_size;
bfd_size_type amt;
+ new_contents = NULL;
amt = sec->size * sizeof (long) / 8;
opd = &ppc64_elf_section_data (sec)->u.opd;
opd->adjust = bfd_zalloc (obfd, amt);
if (h != NULL
&& h->root.root.string[0] == '.')
{
- fdh = get_fdh ((struct ppc_link_hash_entry *) h,
- ppc_hash_table (info));
+ fdh = lookup_fdh ((struct ppc_link_hash_entry *) h,
+ ppc_hash_table (info));
if (fdh != NULL
&& fdh->elf.root.type != bfd_link_hash_defined
&& fdh->elf.root.type != bfd_link_hash_defweak)
/* Set htab->tls_get_addr and call the generic ELF tls_setup function. */
asection *
-ppc64_elf_tls_setup (bfd *obfd, struct bfd_link_info *info)
+ppc64_elf_tls_setup (bfd *obfd,
+ struct bfd_link_info *info,
+ int no_tls_get_addr_opt)
{
struct ppc_link_hash_table *htab;
htab->tls_get_addr = ((struct ppc_link_hash_entry *)
elf_link_hash_lookup (&htab->elf, ".__tls_get_addr",
FALSE, FALSE, TRUE));
+ /* Move dynamic linking info to the function descriptor sym. */
+ if (htab->tls_get_addr != NULL)
+ func_desc_adjust (&htab->tls_get_addr->elf, info);
htab->tls_get_addr_fd = ((struct ppc_link_hash_entry *)
elf_link_hash_lookup (&htab->elf, "__tls_get_addr",
FALSE, FALSE, TRUE));
+ if (!no_tls_get_addr_opt)
+ {
+ struct elf_link_hash_entry *opt, *opt_fd, *tga, *tga_fd;
+
+ opt = elf_link_hash_lookup (&htab->elf, ".__tls_get_addr_opt",
+ FALSE, FALSE, TRUE);
+ if (opt != NULL)
+ func_desc_adjust (opt, info);
+ opt_fd = elf_link_hash_lookup (&htab->elf, "__tls_get_addr_opt",
+ FALSE, FALSE, TRUE);
+ if (opt_fd != NULL
+ && (opt_fd->root.type == bfd_link_hash_defined
+ || opt_fd->root.type == bfd_link_hash_defweak))
+ {
+ /* If glibc supports an optimized __tls_get_addr call stub,
+ signalled by the presence of __tls_get_addr_opt, and we'll
+ be calling __tls_get_addr via a plt call stub, then
+ make __tls_get_addr point to __tls_get_addr_opt. */
+ tga_fd = &htab->tls_get_addr_fd->elf;
+ if (htab->elf.dynamic_sections_created
+ && tga_fd != NULL
+ && (tga_fd->type == STT_FUNC
+ || tga_fd->needs_plt)
+ && !(SYMBOL_CALLS_LOCAL (info, tga_fd)
+ || (ELF_ST_VISIBILITY (tga_fd->other) != STV_DEFAULT
+ && tga_fd->root.type == bfd_link_hash_undefweak)))
+ {
+ struct plt_entry *ent;
+
+ for (ent = tga_fd->plt.plist; ent != NULL; ent = ent->next)
+ if (ent->plt.refcount > 0)
+ break;
+ if (ent != NULL)
+ {
+ tga_fd->root.type = bfd_link_hash_indirect;
+ tga_fd->root.u.i.link = &opt_fd->root;
+ ppc64_elf_copy_indirect_symbol (info, opt_fd, tga_fd);
+ if (opt_fd->dynindx != -1)
+ {
+ /* Use __tls_get_addr_opt in dynamic relocations. */
+ opt_fd->dynindx = -1;
+ _bfd_elf_strtab_delref (elf_hash_table (info)->dynstr,
+ opt_fd->dynstr_index);
+ if (!bfd_elf_link_record_dynamic_symbol (info, opt_fd))
+ return FALSE;
+ }
+ htab->tls_get_addr_fd = (struct ppc_link_hash_entry *) opt_fd;
+ tga = &htab->tls_get_addr->elf;
+ if (opt != NULL && tga != NULL)
+ {
+ tga->root.type = bfd_link_hash_indirect;
+ tga->root.u.i.link = &opt->root;
+ ppc64_elf_copy_indirect_symbol (info, opt, tga);
+ _bfd_elf_link_hash_hide_symbol (info, opt,
+ tga->forced_local);
+ htab->tls_get_addr = (struct ppc_link_hash_entry *) opt;
+ }
+ htab->tls_get_addr_fd->oh = htab->tls_get_addr;
+ htab->tls_get_addr_fd->is_func_descriptor = 1;
+ if (htab->tls_get_addr != NULL)
+ {
+ htab->tls_get_addr->oh = htab->tls_get_addr_fd;
+ htab->tls_get_addr->is_func = 1;
+ }
+ }
+ }
+ }
+ else
+ no_tls_get_addr_opt = TRUE;
+ }
+ htab->no_tls_get_addr_opt = no_tls_get_addr_opt;
return _bfd_elf_tls_setup (obfd, info);
}
enum elf_ppc64_reloc_type r_type = ELF64_R_TYPE (rel->r_info);
unsigned int r_symndx = ELF64_R_SYM (rel->r_info);
- if (r_symndx >= symtab_hdr->sh_info
- && (r_type == R_PPC64_REL24
- || r_type == R_PPC64_REL14
- || r_type == R_PPC64_REL14_BRTAKEN
- || r_type == R_PPC64_REL14_BRNTAKEN
- || r_type == R_PPC64_ADDR24
- || r_type == R_PPC64_ADDR14
- || r_type == R_PPC64_ADDR14_BRTAKEN
- || r_type == R_PPC64_ADDR14_BRNTAKEN))
+ if (r_symndx >= symtab_hdr->sh_info && is_branch_reloc (r_type))
{
struct elf_link_hash_entry **sym_hashes = elf_sym_hashes (ibfd);
struct elf_link_hash_entry *h;
h = sym_hashes[r_symndx - symtab_hdr->sh_info];
- while (h->root.type == bfd_link_hash_indirect
- || h->root.type == bfd_link_hash_warning)
- h = (struct elf_link_hash_entry *) h->root.u.i.link;
+ h = elf_follow_link (h);
if (h == &hash1->elf || h == &hash2->elf)
return TRUE;
}
info = (struct bfd_link_info *) inf;
htab = ppc_hash_table (info);
- if (htab->elf.dynamic_sections_created
- && h->dynindx != -1
- && WILL_CALL_FINISH_DYNAMIC_SYMBOL (1, info->shared, h))
+ if ((htab->elf.dynamic_sections_created
+ && h->dynindx != -1
+ && WILL_CALL_FINISH_DYNAMIC_SYMBOL (1, info->shared, h))
+ || h->type == STT_GNU_IFUNC)
{
struct plt_entry *pent;
bfd_boolean doneone = FALSE;
for (pent = h->plt.plist; pent != NULL; pent = pent->next)
if (pent->plt.refcount > 0)
{
- /* If this is the first .plt entry, make room for the special
- first entry. */
- s = htab->plt;
- if (s->size == 0)
- s->size += PLT_INITIAL_ENTRY_SIZE;
-
- pent->plt.offset = s->size;
-
- /* Make room for this entry. */
- s->size += PLT_ENTRY_SIZE;
-
- /* Make room for the .glink code. */
- s = htab->glink;
- if (s->size == 0)
- s->size += GLINK_CALL_STUB_SIZE;
- /* We need bigger stubs past index 32767. */
- if (s->size >= GLINK_CALL_STUB_SIZE + 32768*2*4)
- s->size += 4;
- s->size += 2*4;
-
- /* We also need to make an entry in the .rela.plt section. */
- s = htab->relplt;
+ if (!htab->elf.dynamic_sections_created
+ || h->dynindx == -1)
+ {
+ s = htab->iplt;
+ pent->plt.offset = s->size;
+ s->size += PLT_ENTRY_SIZE;
+ s = htab->reliplt;
+ }
+ else
+ {
+ /* If this is the first .plt entry, make room for the special
+ first entry. */
+ s = htab->plt;
+ if (s->size == 0)
+ s->size += PLT_INITIAL_ENTRY_SIZE;
+
+ pent->plt.offset = s->size;
+
+ /* Make room for this entry. */
+ s->size += PLT_ENTRY_SIZE;
+
+ /* Make room for the .glink code. */
+ s = htab->glink;
+ if (s->size == 0)
+ s->size += GLINK_CALL_STUB_SIZE;
+ /* We need bigger stubs past index 32767. */
+ if (s->size >= GLINK_CALL_STUB_SIZE + 32768*2*4)
+ s->size += 4;
+ s->size += 2*4;
+
+ /* We also need to make an entry in the .rela.plt section. */
+ s = htab->relplt;
+ }
s->size += sizeof (Elf64_External_Rela);
doneone = TRUE;
}
if (gent->got.refcount > 0)
{
bfd_boolean dyn;
+ asection *rsec;
/* 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))
s->size
+= (gent->tls_type & eh->tls_mask & (TLS_GD | TLS_LD)) ? 16 : 8;
dyn = htab->elf.dynamic_sections_created;
+ rsec = NULL;
if ((info->shared
|| WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn, 0, h))
&& (ELF_ST_VISIBILITY (h->other) == STV_DEFAULT
|| h->root.type != bfd_link_hash_undefweak))
- ppc64_elf_tdata (gent->owner)->relgot->size
- += (gent->tls_type & eh->tls_mask & TLS_GD
- ? 2 * sizeof (Elf64_External_Rela)
- : sizeof (Elf64_External_Rela));
+ rsec = ppc64_elf_tdata (gent->owner)->relgot;
+ else if (h->type == STT_GNU_IFUNC)
+ rsec = htab->reliplt;
+ if (rsec != NULL)
+ rsec->size += (gent->tls_type & eh->tls_mask & TLS_GD
+ ? 2 * sizeof (Elf64_External_Rela)
+ : sizeof (Elf64_External_Rela));
}
else
gent->got.offset = (bfd_vma) -1;
if (eh->dyn_relocs == NULL
- || !htab->elf.dynamic_sections_created)
+ || (!htab->elf.dynamic_sections_created
+ && h->type != STT_GNU_IFUNC))
return TRUE;
/* In the shared -Bsymbolic case, discard space allocated for
}
}
}
+ else if (h->type == STT_GNU_IFUNC)
+ {
+ if (!h->non_got_ref)
+ eh->dyn_relocs = NULL;
+ }
else if (ELIMINATE_COPY_RELOCS)
{
/* For the non-shared case, discard space for relocs against
for (p = eh->dyn_relocs; p != NULL; p = p->next)
{
asection *sreloc = elf_section_data (p->sec)->sreloc;
+ if (!htab->elf.dynamic_sections_created)
+ sreloc = htab->reliplt;
sreloc->size += p->count * sizeof (Elf64_External_Rela);
}
{
struct got_entry **lgot_ents;
struct got_entry **end_lgot_ents;
+ struct plt_entry **local_plt;
+ struct plt_entry **end_local_plt;
char *lgot_masks;
bfd_size_type locsymcount;
Elf_Internal_Shdr *symtab_hdr;
else if (p->count != 0)
{
srel = elf_section_data (p->sec)->sreloc;
+ if (!htab->elf.dynamic_sections_created)
+ srel = htab->reliplt;
srel->size += p->count * sizeof (Elf64_External_Rela);
if ((p->sec->output_section->flags & SEC_READONLY) != 0)
info->flags |= DF_TEXTREL;
symtab_hdr = &elf_symtab_hdr (ibfd);
locsymcount = symtab_hdr->sh_info;
end_lgot_ents = lgot_ents + locsymcount;
- lgot_masks = (char *) end_lgot_ents;
+ local_plt = (struct plt_entry **) end_lgot_ents;
+ end_local_plt = local_plt + locsymcount;
+ lgot_masks = (char *) end_local_plt;
s = ppc64_elf_tdata (ibfd)->got;
srel = ppc64_elf_tdata (ibfd)->relgot;
for (; lgot_ents < end_lgot_ents; ++lgot_ents, ++lgot_masks)
}
else
{
+ unsigned int num = 1;
ent->got.offset = s->size;
if ((ent->tls_type & *lgot_masks & TLS_GD) != 0)
- {
- s->size += 16;
- if (info->shared)
- srel->size += 2 * sizeof (Elf64_External_Rela);
- }
- else
- {
- s->size += 8;
- if (info->shared)
- srel->size += sizeof (Elf64_External_Rela);
- }
+ num = 2;
+ s->size += num * 8;
+ if (info->shared)
+ srel->size += num * sizeof (Elf64_External_Rela);
+ else if ((*lgot_masks & PLT_IFUNC) != 0)
+ htab->reliplt->size += num * sizeof (Elf64_External_Rela);
}
}
else
ent->got.offset = (bfd_vma) -1;
}
+
+ /* Allocate space for calls to local STT_GNU_IFUNC syms in .iplt. */
+ for (; local_plt < end_local_plt; ++local_plt)
+ {
+ struct plt_entry *ent;
+
+ for (ent = *local_plt; ent != NULL; ent = ent->next)
+ if (ent->plt.refcount > 0)
+ {
+ s = htab->iplt;
+ ent->plt.offset = s->size;
+ s->size += PLT_ENTRY_SIZE;
+
+ htab->reliplt->size += sizeof (Elf64_External_Rela);
+ }
+ else
+ ent->plt.offset = (bfd_vma) -1;
+ }
}
/* Allocate global sym .plt and .got entries, and space for global
continue;
else if (s == htab->got
|| s == htab->plt
+ || s == htab->iplt
|| s == htab->glink
|| s == htab->dynbss)
{
return FALSE;
}
+ if (!htab->no_tls_get_addr_opt
+ && htab->tls_get_addr_fd != NULL
+ && htab->tls_get_addr_fd->elf.plt.plist != NULL
+ && !add_dynamic_entry (DT_PPC64_TLSOPT, 0))
+ return FALSE;
+
if (relocs)
{
if (!add_dynamic_entry (DT_RELA, 0)
ppc_type_of_stub (asection *input_sec,
const Elf_Internal_Rela *rel,
struct ppc_link_hash_entry **hash,
+ struct plt_entry **plt_ent,
bfd_vma destination)
{
struct ppc_link_hash_entry *h = *hash;
if (h != NULL)
{
+ struct plt_entry *ent;
struct ppc_link_hash_entry *fdh = h;
- if (fdh->oh != NULL
- && fdh->oh->is_func_descriptor)
- fdh = fdh->oh;
-
- if (fdh->elf.dynindx != -1)
- {
- struct plt_entry *ent;
+ if (h->oh != NULL
+ && h->oh->is_func_descriptor)
+ fdh = ppc_follow_link (h->oh);
- for (ent = fdh->elf.plt.plist; ent != NULL; ent = ent->next)
- if (ent->addend == rel->r_addend
- && ent->plt.offset != (bfd_vma) -1)
- {
- *hash = fdh;
- return ppc_stub_plt_call;
- }
- }
+ for (ent = fdh->elf.plt.plist; ent != NULL; ent = ent->next)
+ if (ent->addend == rel->r_addend
+ && ent->plt.offset != (bfd_vma) -1)
+ {
+ *hash = fdh;
+ *plt_ent = ent;
+ return ppc_stub_plt_call;
+ }
/* Here, we know we don't have a plt entry. If we don't have a
either a defined function descriptor or a defined entry symbol
&& h->elf.root.u.def.section->output_section != NULL))
return ppc_stub_none;
}
+ else if (elf_local_got_ents (input_sec->owner) != NULL)
+ {
+ Elf_Internal_Shdr *symtab_hdr = &elf_symtab_hdr (input_sec->owner);
+ struct plt_entry **local_plt = (struct plt_entry **)
+ elf_local_got_ents (input_sec->owner) + symtab_hdr->sh_info;
+ unsigned long r_symndx = ELF64_R_SYM (rel->r_info);
+
+ if (local_plt[r_symndx] != NULL)
+ {
+ struct plt_entry *ent;
+
+ for (ent = local_plt[r_symndx]; ent != NULL; ent = ent->next)
+ if (ent->addend == rel->r_addend
+ && ent->plt.offset != (bfd_vma) -1)
+ {
+ *plt_ent = ent;
+ return ppc_stub_plt_call;
+ }
+ }
+ }
/* Determine where the call point is. */
location = (input_sec->output_offset
return p;
}
+/* Build a special .plt call stub for __tls_get_addr. */
+
+#define LD_R11_0R3 0xe9630000
+#define LD_R12_0R3 0xe9830000
+#define MR_R0_R3 0x7c601b78
+#define CMPDI_R11_0 0x2c2b0000
+#define ADD_R3_R12_R13 0x7c6c6a14
+#define BEQLR 0x4d820020
+#define MR_R3_R0 0x7c030378
+#define MFLR_R11 0x7d6802a6
+#define STD_R11_0R1 0xf9610000
+#define BCTRL 0x4e800421
+#define LD_R11_0R1 0xe9610000
+#define LD_R2_0R1 0xe8410000
+#define MTLR_R11 0x7d6803a6
+
+static inline bfd_byte *
+build_tls_get_addr_stub (bfd *obfd, bfd_byte *p, int offset,
+ Elf_Internal_Rela *r)
+{
+ bfd_put_32 (obfd, LD_R11_0R3 + 0, p), p += 4;
+ bfd_put_32 (obfd, LD_R12_0R3 + 8, p), p += 4;
+ bfd_put_32 (obfd, MR_R0_R3, p), p += 4;
+ bfd_put_32 (obfd, CMPDI_R11_0, p), p += 4;
+ bfd_put_32 (obfd, ADD_R3_R12_R13, p), p += 4;
+ bfd_put_32 (obfd, BEQLR, p), p += 4;
+ bfd_put_32 (obfd, MR_R3_R0, p), p += 4;
+ bfd_put_32 (obfd, MFLR_R11, p), p += 4;
+ bfd_put_32 (obfd, STD_R11_0R1 + 32, p), p += 4;
+
+ if (r != NULL)
+ r[0].r_offset += 9 * 4;
+ p = build_plt_stub (obfd, p, offset, r);
+ bfd_put_32 (obfd, BCTRL, p - 4);
+
+ bfd_put_32 (obfd, LD_R11_0R1 + 32, p), p += 4;
+ bfd_put_32 (obfd, LD_R2_0R1 + 40, p), p += 4;
+ bfd_put_32 (obfd, MTLR_R11, p), p += 4;
+ bfd_put_32 (obfd, BLR, p), p += 4;
+
+ return p;
+}
+
static Elf_Internal_Rela *
get_relocs (asection *sec, int count)
{
struct ppc_link_hash_table *htab;
bfd_byte *loc;
bfd_byte *p;
- struct plt_entry *ent;
bfd_vma dest, off;
int size;
Elf_Internal_Rela *r;
+ asection *plt;
/* Massage our args to the form they really have. */
stub_entry = (struct ppc_stub_hash_entry *) gen_entry;
hashes[symndx] = &h->elf;
r->r_info = ELF64_R_INFO (symndx, R_PPC64_REL24);
if (h->oh != NULL && h->oh->is_func)
- h = h->oh;
+ h = ppc_follow_link (h->oh);
if (h->elf.root.u.def.section != stub_entry->target_section)
/* H is an opd symbol. The addend must be zero. */
r->r_addend = 0;
break;
case ppc_stub_plt_call:
- /* Do the best we can for shared libraries built without
- exporting ".foo" for each "foo". This can happen when symbol
- versioning scripts strip all bar a subset of symbols. */
- if (stub_entry->h->oh != NULL
- && stub_entry->h->oh->elf.root.type != bfd_link_hash_defined
- && stub_entry->h->oh->elf.root.type != bfd_link_hash_defweak)
- {
- /* Point the symbol at the stub. There may be multiple stubs,
- we don't really care; The main thing is to make this sym
- defined somewhere. Maybe defining the symbol in the stub
- section is a silly idea. If we didn't do this, htab->top_id
- could disappear. */
- stub_entry->h->oh->elf.root.type = bfd_link_hash_defined;
- stub_entry->h->oh->elf.root.u.def.section = stub_entry->stub_sec;
- stub_entry->h->oh->elf.root.u.def.value = stub_entry->stub_offset;
+ if (stub_entry->h != NULL
+ && stub_entry->h->is_func_descriptor
+ && stub_entry->h->oh != NULL)
+ {
+ struct ppc_link_hash_entry *fh = ppc_follow_link (stub_entry->h->oh);
+
+ /* If the old-ABI "dot-symbol" is undefined make it weak so
+ we don't get a link error from RELOC_FOR_GLOBAL_SYMBOL.
+ FIXME: We used to define the symbol on one of the call
+ stubs instead, which is why we test symbol section id
+ against htab->top_id in various places. Likely all
+ these checks could now disappear. */
+ if (fh->elf.root.type == bfd_link_hash_undefined)
+ fh->elf.root.type = bfd_link_hash_undefweak;
}
/* Now build the stub. */
- dest = (bfd_vma) -1;
- for (ent = stub_entry->h->elf.plt.plist; ent != NULL; ent = ent->next)
- if (ent->addend == stub_entry->addend)
- {
- dest = ent->plt.offset;
- break;
- }
+ dest = stub_entry->plt_ent->plt.offset & ~1;
if (dest >= (bfd_vma) -2)
abort ();
- dest &= ~ (bfd_vma) 1;
- dest += (htab->plt->output_offset
- + htab->plt->output_section->vma);
+ plt = htab->plt;
+ if (!htab->elf.dynamic_sections_created
+ || stub_entry->h == NULL
+ || stub_entry->h->elf.dynindx == -1)
+ plt = htab->iplt;
+
+ dest += plt->output_offset + plt->output_section->vma;
+
+ if (stub_entry->h == NULL
+ && (stub_entry->plt_ent->plt.offset & 1) == 0)
+ {
+ Elf_Internal_Rela rela;
+ bfd_byte *rl;
+
+ rela.r_offset = dest;
+ rela.r_info = ELF64_R_INFO (0, R_PPC64_JMP_IREL);
+ rela.r_addend = (stub_entry->target_value
+ + stub_entry->target_section->output_offset
+ + stub_entry->target_section->output_section->vma);
+
+ rl = (htab->reliplt->contents
+ + (htab->reliplt->reloc_count++
+ * sizeof (Elf64_External_Rela)));
+ bfd_elf64_swap_reloca_out (info->output_bfd, &rela, rl);
+ stub_entry->plt_ent->plt.offset |= 1;
+ }
off = (dest
- - elf_gp (htab->plt->output_section->owner)
+ - elf_gp (plt->output_section->owner)
- htab->stub_group[stub_entry->id_sec->id].toc_off);
if (off + 0x80008000 > 0xffffffff || (off & 7) != 0)
{
(*_bfd_error_handler)
(_("linkage table error against `%s'"),
- stub_entry->h->elf.root.root.string);
+ stub_entry->h != NULL
+ ? stub_entry->h->elf.root.root.string
+ : "<local sym>");
bfd_set_error (bfd_error_bad_value);
htab->stub_error = TRUE;
return FALSE;
r[0].r_offset += 2;
r[0].r_addend = dest;
}
- p = build_plt_stub (htab->stub_bfd, loc, off, r);
+ if (stub_entry->h != NULL
+ && (stub_entry->h == htab->tls_get_addr_fd
+ || stub_entry->h == htab->tls_get_addr)
+ && !htab->no_tls_get_addr_opt)
+ p = build_tls_get_addr_stub (htab->stub_bfd, loc, off, r);
+ else
+ p = build_plt_stub (htab->stub_bfd, loc, off, r);
size = p - loc;
break;
if (stub_entry->stub_type == ppc_stub_plt_call)
{
- struct plt_entry *ent;
- off = (bfd_vma) -1;
- for (ent = stub_entry->h->elf.plt.plist; ent != NULL; ent = ent->next)
- if (ent->addend == stub_entry->addend)
- {
- off = ent->plt.offset & ~(bfd_vma) 1;
- break;
- }
+ asection *plt;
+ off = stub_entry->plt_ent->plt.offset & ~(bfd_vma) 1;
if (off >= (bfd_vma) -2)
abort ();
- off += (htab->plt->output_offset
- + htab->plt->output_section->vma
- - elf_gp (htab->plt->output_section->owner)
+ plt = htab->plt;
+ if (!htab->elf.dynamic_sections_created
+ || stub_entry->h == NULL
+ || stub_entry->h->elf.dynindx == -1)
+ plt = htab->iplt;
+ off += (plt->output_offset
+ + plt->output_section->vma
+ - elf_gp (plt->output_section->owner)
- htab->stub_group[stub_entry->id_sec->id].toc_off);
size = PLT_CALL_STUB_SIZE;
size -= 4;
if (PPC_HA (off + 16) != PPC_HA (off))
size += 4;
+ if (stub_entry->h != NULL
+ && (stub_entry->h == htab->tls_get_addr_fd
+ || stub_entry->h == htab->tls_get_addr)
+ && !htab->no_tls_get_addr_opt)
+ size += 13 * 4;
if (info->emitrelocations)
{
stub_entry->stub_sec->reloc_count
if (eh != NULL
&& (eh->elf.plt.plist != NULL
|| (eh->oh != NULL
- && eh->oh->elf.plt.plist != NULL)))
+ && ppc_follow_link (eh->oh)->elf.plt.plist != NULL)))
{
ret = 1;
break;
enum ppc_stub_type stub_type;
struct ppc_stub_hash_entry *stub_entry;
asection *sym_sec, *code_sec;
- bfd_vma sym_value;
+ bfd_vma sym_value, code_value;
bfd_vma destination;
bfd_boolean ok_dest;
struct ppc_link_hash_entry *hash;
char *stub_name;
const asection *id_sec;
struct _opd_sec_data *opd;
+ struct plt_entry *plt_ent;
r_type = ELF64_R_TYPE (irela->r_info);
r_indx = ELF64_R_SYM (irela->r_info);
use the func descriptor sym instead if it is
defined. */
if (hash->elf.root.root.string[0] == '.'
- && (fdh = get_fdh (hash, htab)) != NULL)
+ && (fdh = lookup_fdh (hash, htab)) != NULL)
{
if (fdh->elf.root.type == bfd_link_hash_defined
|| fdh->elf.root.type == bfd_link_hash_defweak)
}
code_sec = sym_sec;
+ code_value = sym_value;
opd = get_opd_info (sym_sec);
if (opd != NULL)
{
long adjust = opd->adjust[sym_value / 8];
if (adjust == -1)
continue;
+ code_value += adjust;
sym_value += adjust;
}
dest = opd_entry_value (sym_sec, sym_value,
- &code_sec, &sym_value);
+ &code_sec, &code_value);
if (dest != (bfd_vma) -1)
{
destination = dest;
entry. */
hash->elf.root.type = bfd_link_hash_defweak;
hash->elf.root.u.def.section = code_sec;
- hash->elf.root.u.def.value = sym_value;
+ hash->elf.root.u.def.value = code_value;
}
}
}
/* Determine what (if any) linker stub is needed. */
+ plt_ent = NULL;
stub_type = ppc_type_of_stub (section, irela, &hash,
- destination);
+ &plt_ent, destination);
if (stub_type != ppc_stub_plt_call)
{
}
stub_entry->stub_type = stub_type;
- stub_entry->target_value = sym_value;
- stub_entry->target_section = code_sec;
+ if (stub_type != ppc_stub_plt_call)
+ {
+ stub_entry->target_value = code_value;
+ stub_entry->target_section = code_sec;
+ }
+ else
+ {
+ stub_entry->target_value = sym_value;
+ stub_entry->target_section = sym_sec;
+ }
stub_entry->h = hash;
+ stub_entry->plt_ent = plt_ent;
stub_entry->addend = irela->r_addend;
if (stub_entry->h != NULL)
/* The TOC consists of sections .got, .toc, .tocbss, .plt in that
order. The TOC starts where the first of these sections starts. */
s = bfd_get_section_by_name (obfd, ".got");
- if (s == NULL)
+ if (s == NULL || (s->flags & SEC_EXCLUDE) != 0)
s = bfd_get_section_by_name (obfd, ".toc");
- if (s == NULL)
+ if (s == NULL || (s->flags & SEC_EXCLUDE) != 0)
s = bfd_get_section_by_name (obfd, ".tocbss");
- if (s == NULL)
+ if (s == NULL || (s->flags & SEC_EXCLUDE) != 0)
s = bfd_get_section_by_name (obfd, ".plt");
- if (s == NULL)
+ if (s == NULL || (s->flags & SEC_EXCLUDE) != 0)
{
/* This may happen for
o references to TOC base (SYM@toc / TOC[tc0]) without a
/* Look for a likely section. We probably won't even be
using TOCstart. */
for (s = obfd->sections; s != NULL; s = s->next)
- if ((s->flags & (SEC_ALLOC | SEC_SMALL_DATA | SEC_READONLY))
+ if ((s->flags & (SEC_ALLOC | SEC_SMALL_DATA | SEC_READONLY
+ | SEC_EXCLUDE))
== (SEC_ALLOC | SEC_SMALL_DATA))
break;
if (s == NULL)
for (s = obfd->sections; s != NULL; s = s->next)
- if ((s->flags & (SEC_ALLOC | SEC_SMALL_DATA))
+ if ((s->flags & (SEC_ALLOC | SEC_SMALL_DATA | SEC_EXCLUDE))
== (SEC_ALLOC | SEC_SMALL_DATA))
break;
if (s == NULL)
for (s = obfd->sections; s != NULL; s = s->next)
- if ((s->flags & (SEC_ALLOC | SEC_READONLY)) == SEC_ALLOC)
+ if ((s->flags & (SEC_ALLOC | SEC_READONLY | SEC_EXCLUDE))
+ == SEC_ALLOC)
break;
if (s == NULL)
for (s = obfd->sections; s != NULL; s = s->next)
- if ((s->flags & SEC_ALLOC) == SEC_ALLOC)
+ if ((s->flags & (SEC_ALLOC | SEC_EXCLUDE)) == SEC_ALLOC)
break;
}
tls_mask = h->tls_mask;
else if (local_got_ents != NULL)
{
- char *lgot_masks;
- lgot_masks = (char *) (local_got_ents + symtab_hdr->sh_info);
+ struct plt_entry **local_plt = (struct plt_entry **)
+ (local_got_ents + symtab_hdr->sh_info);
+ char *lgot_masks = (char *)
+ (local_plt + symtab_hdr->sh_info);
tls_mask = lgot_masks[r_symndx];
}
if (tls_mask == 0
if (tls_mask != 0
&& (tls_mask & TLS_TPREL) == 0)
{
- bfd_vma rtra;
insn = bfd_get_32 (output_bfd, contents + rel->r_offset);
- if ((insn & ((0x3f << 26) | (31 << 11)))
- == ((31 << 26) | (13 << 11)))
- rtra = insn & ((1 << 26) - (1 << 16));
- else if ((insn & ((0x3f << 26) | (31 << 16)))
- == ((31 << 26) | (13 << 16)))
- rtra = (insn & (31 << 21)) | ((insn & (31 << 11)) << 5);
- else
- abort ();
- if ((insn & ((1 << 11) - (1 << 1))) == 266 << 1)
- /* add -> addi. */
- insn = 14 << 26;
- else if ((insn & (31 << 1)) == 23 << 1
- && ((insn & (31 << 6)) < 14 << 6
- || ((insn & (31 << 6)) >= 16 << 6
- && (insn & (31 << 6)) < 24 << 6)))
- /* load and store indexed -> dform. */
- insn = (32 | ((insn >> 6) & 31)) << 26;
- else if ((insn & (31 << 1)) == 21 << 1
- && (insn & (0x1a << 6)) == 0)
- /* ldx, ldux, stdx, stdux -> ld, ldu, std, stdu. */
- insn = (((58 | ((insn >> 6) & 4)) << 26)
- | ((insn >> 6) & 1));
- else if ((insn & (31 << 1)) == 21 << 1
- && (insn & ((1 << 11) - (1 << 1))) == 341 << 1)
- /* lwax -> lwa. */
- insn = (58 << 26) | 2;
- else
+ insn = _bfd_elf_ppc_at_tls_transform (insn, 13);
+ if (insn == 0)
abort ();
- insn |= rtra;
bfd_put_32 (output_bfd, insn, contents + rel->r_offset);
/* Was PPC64_TLS which sits on insn boundary, now
PPC64_TPREL16_LO which is at low-order half-word. */
insn1 |= 58 << 26; /* ld */
insn2 = 0x7c636a14; /* add 3,3,13 */
if (offset != (bfd_vma) -1)
- rel[1].r_info = ELF64_R_INFO (ELF64_R_SYM (rel[1].r_info),
- R_PPC64_NONE);
+ rel[1].r_info = ELF64_R_INFO (STN_UNDEF, R_PPC64_NONE);
if ((tls_mask & TLS_EXPLICIT) == 0)
r_type = (((r_type - (R_PPC64_GOT_TLSGD16 & 3)) & 3)
+ R_PPC64_GOT_TPREL16_DS);
rel->r_info = ELF64_R_INFO (r_symndx, r_type);
/* Zap the reloc on the _tls_get_addr call too. */
BFD_ASSERT (offset == rel[1].r_offset);
- rel[1].r_info = ELF64_R_INFO (ELF64_R_SYM (rel[1].r_info),
- R_PPC64_NONE);
+ rel[1].r_info = ELF64_R_INFO (STN_UNDEF, R_PPC64_NONE);
insn3 = bfd_get_32 (output_bfd,
contents + offset + 4);
if (insn3 == NOP
rel->r_offset = offset + d_offset;
/* Zap the reloc on the _tls_get_addr call too. */
BFD_ASSERT (offset == rel[1].r_offset);
- rel[1].r_info = ELF64_R_INFO (ELF64_R_SYM (rel[1].r_info),
- R_PPC64_NONE);
+ rel[1].r_info = ELF64_R_INFO (STN_UNDEF, R_PPC64_NONE);
insn2 = 0x38630000; /* addi 3,3,0 */
insn3 = bfd_get_32 (output_bfd,
contents + offset + 4);
base pointer. */
stub_entry = NULL;
fdh = h;
- if (((h != NULL
- && (((fdh = h->oh) != NULL
- && fdh->elf.plt.plist != NULL)
- || (fdh = h)->elf.plt.plist != NULL))
+ if (h != NULL
+ && h->oh != NULL
+ && h->oh->is_func_descriptor)
+ fdh = ppc_follow_link (h->oh);
+ if (((fdh != NULL
+ && fdh->elf.plt.plist != NULL)
|| (sec != NULL
&& sec->output_section != NULL
&& sec->id <= htab->top_id
&& (htab->stub_group[sec->id].toc_off
- != htab->stub_group[input_section->id].toc_off)))
+ != htab->stub_group[input_section->id].toc_off))
+ || (h == NULL
+ && ELF_ST_TYPE (sym->st_info) == STT_GNU_IFUNC))
&& (stub_entry = ppc_get_stub_entry (input_section, sec, fdh,
rel, htab)) != NULL
&& (stub_entry->stub_type == ppc_stub_plt_call
if (nop == NOP
|| nop == CROR_151515 || nop == CROR_313131)
{
- bfd_put_32 (input_bfd, LD_R2_40R1,
- contents + rel->r_offset + 4);
+ if (h != NULL
+ && (h == htab->tls_get_addr_fd
+ || h == htab->tls_get_addr)
+ && !htab->no_tls_get_addr_opt)
+ {
+ /* Special stub used, leave nop alone. */
+ }
+ else
+ bfd_put_32 (input_bfd, LD_R2_40R1,
+ contents + rel->r_offset + 4);
can_plt_call = TRUE;
}
}
/* Generate relocs for the dynamic linker, except in
the case of TLSLD where we'll use one entry per
module. */
- asection *relgot = ppc64_elf_tdata (input_bfd)->relgot;
+ asection *relgot;
+ bfd_boolean ifunc;
*offp = off | 1;
+ relgot = NULL;
+ ifunc = (h != NULL
+ ? h->elf.type == STT_GNU_IFUNC
+ : ELF_ST_TYPE (sym->st_info) == STT_GNU_IFUNC);
if ((info->shared || indx != 0)
&& (offp == &ppc64_tlsld_got (input_bfd)->offset
|| h == NULL
|| ELF_ST_VISIBILITY (h->elf.other) == STV_DEFAULT
|| h->elf.root.type != bfd_link_hash_undefweak))
+ relgot = ppc64_elf_tdata (input_bfd)->relgot;
+ else if (ifunc)
+ relgot = htab->reliplt;
+ if (relgot != NULL)
{
outrel.r_offset = (got->output_section->vma
+ got->output_offset
outrel.r_info = ELF64_R_INFO (indx, R_PPC64_DTPREL64);
else if (tls_type == (TLS_TLS | TLS_TPREL))
outrel.r_info = ELF64_R_INFO (indx, R_PPC64_TPREL64);
- else if (indx == 0)
+ else if (indx != 0)
+ outrel.r_info = ELF64_R_INFO (indx, R_PPC64_GLOB_DAT);
+ else
{
- outrel.r_info = ELF64_R_INFO (indx, R_PPC64_RELATIVE);
+ if (ifunc)
+ outrel.r_info = ELF64_R_INFO (0, R_PPC64_IRELATIVE);
+ else
+ outrel.r_info = ELF64_R_INFO (0, R_PPC64_RELATIVE);
/* Write the .got section contents for the sake
of prelink. */
bfd_put_64 (output_bfd, outrel.r_addend + relocation,
loc);
}
- else
- outrel.r_info = ELF64_R_INFO (indx, R_PPC64_GLOB_DAT);
if (indx == 0 && tls_type != (TLS_TLS | TLS_LD))
{
addend -= sec->output_section->vma;
break;
+ case R_PPC64_REL16:
+ case R_PPC64_REL16_LO:
+ case R_PPC64_REL16_HI:
+ case R_PPC64_REL16_HA:
+ break;
+
case R_PPC64_REL14:
case R_PPC64_REL14_BRNTAKEN:
case R_PPC64_REL14_BRTAKEN:
&& h != NULL
&& h->elf.dynindx != -1
&& !h->elf.non_got_ref
- && !h->elf.def_regular))
+ && !h->elf.def_regular)
+ || (!info->shared
+ && (h != NULL
+ ? h->elf.type == STT_GNU_IFUNC
+ : ELF_ST_TYPE (sym->st_info) == STT_GNU_IFUNC)))
{
- Elf_Internal_Rela outrel;
bfd_boolean skip, relocate;
asection *sreloc;
- bfd_byte *loc;
bfd_vma out_off;
/* When generating a dynamic object, these relocations
entry in this lib. */
unresolved_reloc = FALSE;
}
- outrel.r_info = ELF64_R_INFO (0, R_PPC64_RELATIVE);
+ if (!is_opd
+ && r_type == R_PPC64_ADDR64
+ && (h != NULL
+ ? h->elf.type == STT_GNU_IFUNC
+ : ELF_ST_TYPE (sym->st_info) == STT_GNU_IFUNC))
+ outrel.r_info = ELF64_R_INFO (0, R_PPC64_IRELATIVE);
+ else
+ {
+ outrel.r_info = ELF64_R_INFO (0, R_PPC64_RELATIVE);
- /* We need to relocate .opd contents for ld.so.
- Prelink also wants simple and consistent rules
- for relocs. This make all RELATIVE relocs have
- *r_offset equal to r_addend. */
- relocate = TRUE;
+ /* We need to relocate .opd contents for ld.so.
+ Prelink also wants simple and consistent rules
+ for relocs. This make all RELATIVE relocs have
+ *r_offset equal to r_addend. */
+ relocate = TRUE;
+ }
}
else
{
long indx = 0;
- if (r_symndx == 0 || bfd_is_abs_section (sec))
+ if (h != NULL
+ ? h->elf.type == STT_GNU_IFUNC
+ : ELF_ST_TYPE (sym->st_info) == STT_GNU_IFUNC)
+ {
+ (*_bfd_error_handler)
+ (_("%B(%A+0x%lx): relocation %s for indirect "
+ "function %s unsupported"),
+ input_bfd,
+ input_section,
+ (long) rel->r_offset,
+ ppc64_elf_howto_table[r_type]->name,
+ sym_name);
+ ret = FALSE;
+ }
+ else if (r_symndx == 0 || bfd_is_abs_section (sec))
;
else if (sec == NULL || sec->owner == NULL)
{
}
sreloc = elf_section_data (input_section)->sreloc;
+ if (!htab->elf.dynamic_sections_created)
+ sreloc = htab->reliplt;
if (sreloc == NULL)
abort ();
case R_PPC64_COPY:
case R_PPC64_GLOB_DAT:
case R_PPC64_JMP_SLOT:
+ case R_PPC64_JMP_IREL:
case R_PPC64_RELATIVE:
/* We shouldn't ever see these dynamic relocs in relocatable
files. */
break;
case R_PPC64_ADDR16_HA:
+ case R_PPC64_REL16_HA:
case R_PPC64_ADDR16_HIGHERA:
case R_PPC64_ADDR16_HIGHESTA:
case R_PPC64_TOC16_HA:
/* Adjust the value of any local symbols in opd sections. */
-static bfd_boolean
+static int
ppc64_elf_output_symbol_hook (struct bfd_link_info *info,
const char *name ATTRIBUTE_UNUSED,
Elf_Internal_Sym *elfsym,
bfd_vma value;
if (h != NULL)
- return TRUE;
+ return 1;
opd = get_opd_info (input_sec);
if (opd == NULL || opd->adjust == NULL)
- return TRUE;
+ return 1;
value = elfsym->st_value - input_sec->output_offset;
if (!info->relocatable)
adjust = opd->adjust[value / 8];
if (adjust == -1)
- elfsym->st_value = 0;
- else
- elfsym->st_value += adjust;
- return TRUE;
+ return 2;
+
+ elfsym->st_value += adjust;
+ return 1;
}
/* Finish up dynamic symbol handling. We set the contents of various
{
/* This symbol has an entry in the procedure linkage
table. Set it up. */
-
- if (htab->plt == NULL
- || htab->relplt == NULL
- || htab->glink == NULL)
- abort ();
-
- /* Create a JMP_SLOT reloc to inform the dynamic linker to
- fill in the PLT entry. */
- rela.r_offset = (htab->plt->output_section->vma
- + htab->plt->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 += ((ent->plt.offset - PLT_INITIAL_ENTRY_SIZE) / PLT_ENTRY_SIZE
- * sizeof (Elf64_External_Rela));
+ if (!htab->elf.dynamic_sections_created
+ || h->dynindx == -1)
+ {
+ BFD_ASSERT (h->type == STT_GNU_IFUNC
+ && 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
+ + ent->plt.offset);
+ rela.r_info = ELF64_R_INFO (0, R_PPC64_JMP_IREL);
+ rela.r_addend = (h->root.u.def.value
+ + 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++
+ * sizeof (Elf64_External_Rela)));
+ }
+ else
+ {
+ rela.r_offset = (htab->plt->output_section->vma
+ + htab->plt->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
+ + ((ent->plt.offset - PLT_INITIAL_ENTRY_SIZE)
+ / (PLT_ENTRY_SIZE / sizeof (Elf64_External_Rela))));
+ }
bfd_elf64_swap_reloca_out (output_bfd, &rela, loc);
}
if (h->needs_copy)
{
- Elf_Internal_Rela rela;
- bfd_byte *loc;
-
/* This symbol needs a copy reloc. Set it up. */
if (h->dynindx == -1