#define ELF_TARGET_ID PPC64_ELF_DATA
#define ELF_MACHINE_CODE EM_PPC64
#define ELF_MAXPAGESIZE 0x10000
-#define ELF_COMMONPAGESIZE 0x10000
+#define ELF_COMMONPAGESIZE 0x1000
+#define ELF_RELROPAGESIZE ELF_MAXPAGESIZE
#define elf_info_to_howto ppc64_elf_info_to_howto
#define elf_backend_want_got_sym 0
/* The size in bytes of an entry in the procedure linkage table. */
#define PLT_ENTRY_SIZE(htab) (htab->opd_abi ? 24 : 8)
+#define LOCAL_PLT_ENTRY_SIZE(htab) (htab->opd_abi ? 16 : 8)
/* The initial size of the plt reserved for the dynamic linker. */
#define PLT_INITIAL_ENTRY_SIZE(htab) (htab->opd_abi ? 24 : 16)
#define BCTR 0x4e800420 /* bctr */
#define ADDI_R11_R11 0x396b0000 /* addi %r11,%r11,off@l */
+#define ADDI_R12_R11 0x398b0000 /* addi %r12,%r11,off@l */
+#define ADDI_R12_R12 0x398c0000 /* addi %r12,%r12,off@l */
#define ADDIS_R2_R2 0x3c420000 /* addis %r2,%r2,off@ha */
#define ADDI_R2_R2 0x38420000 /* addi %r2,%r2,off@l */
#define ADD_R2_R2_R12 0x7c426214 /* add %r2,%r2,%r12 */
#define LIS_R2 0x3c400000 /* lis %r2,xxx@ha */
+#define LIS_R12 0x3d800000 /* lis %r12,xxx@ha */
#define ADDIS_R2_R12 0x3c4c0000 /* addis %r2,%r12,xxx@ha */
#define ADDIS_R12_R2 0x3d820000 /* addis %r12,%r2,xxx@ha */
+#define ADDIS_R12_R11 0x3d8b0000 /* addis %r12,%r11,xxx@ha */
#define ADDIS_R12_R12 0x3d8c0000 /* addis %r12,%r12,xxx@ha */
+#define ORIS_R12_R12_0 0x658c0000 /* oris %r12,%r12,xxx@hi */
+#define ORI_R12_R12_0 0x618c0000 /* ori %r12,%r12,xxx@l */
#define LD_R12_0R12 0xe98c0000 /* ld %r12,xxx@l(%r12) */
+#define SLDI_R12_R12_32 0x799c07c6 /* sldi %r12,%r12,32 */
+#define LDX_R12_R11_R12 0x7d8b602a /* ldx %r12,%r11,%r12 */
+#define ADD_R12_R11_R12 0x7d8b6214 /* add %r12,%r11,%r12 */
/* __glink_PLTresolve stub instructions. We enter with the index in R0. */
#define GLINK_PLTRESOLVE_SIZE(htab) \
0x03fffffc, /* dst_mask */
TRUE), /* pcrel_offset */
+ /* A variant of R_PPC64_REL24, used when r2 is not the toc pointer. */
+ HOWTO (R_PPC64_REL24_NOTOC, /* type */
+ 0, /* rightshift */
+ 2, /* size (0 = byte, 1 = short, 2 = long) */
+ 26, /* bitsize */
+ TRUE, /* pc_relative */
+ 0, /* bitpos */
+ complain_overflow_signed, /* complain_on_overflow */
+ ppc64_elf_branch_reloc, /* special_function */
+ "R_PPC64_REL24_NOTOC", /* name */
+ FALSE, /* partial_inplace */
+ 0, /* src_mask */
+ 0x03fffffc, /* dst_mask */
+ TRUE), /* pcrel_offset */
+
/* A relative 16 bit branch; the lower two bits must be zero. */
HOWTO (R_PPC64_REL14, /* type */
0, /* rightshift */
0, /* dst_mask */
FALSE), /* pcrel_offset */
+ /* Marker reloc for optimizing r2 save in prologue rather than on
+ each plt call stub. */
HOWTO (R_PPC64_TOCSAVE,
0, /* rightshift */
2, /* size (0 = byte, 1 = short, 2 = long) */
0, /* dst_mask */
FALSE), /* pcrel_offset */
+ /* Marker relocs on inline plt call instructions. */
+ HOWTO (R_PPC64_PLTSEQ,
+ 0, /* rightshift */
+ 2, /* size (0 = byte, 1 = short, 2 = long) */
+ 32, /* bitsize */
+ FALSE, /* pc_relative */
+ 0, /* bitpos */
+ complain_overflow_dont, /* complain_on_overflow */
+ bfd_elf_generic_reloc, /* special_function */
+ "R_PPC64_PLTSEQ", /* name */
+ FALSE, /* partial_inplace */
+ 0, /* src_mask */
+ 0, /* dst_mask */
+ FALSE), /* pcrel_offset */
+
+ HOWTO (R_PPC64_PLTCALL,
+ 0, /* rightshift */
+ 2, /* size (0 = byte, 1 = short, 2 = long) */
+ 32, /* bitsize */
+ FALSE, /* pc_relative */
+ 0, /* bitpos */
+ complain_overflow_dont, /* complain_on_overflow */
+ bfd_elf_generic_reloc, /* special_function */
+ "R_PPC64_PLTCALL", /* name */
+ FALSE, /* partial_inplace */
+ 0, /* src_mask */
+ 0, /* dst_mask */
+ FALSE), /* pcrel_offset */
+
/* Computes the load module index of the load module that contains the
definition of its TLS sym. */
HOWTO (R_PPC64_DTPMOD64,
break;
case BFD_RELOC_PPC_B26: r = R_PPC64_REL24;
break;
+ case BFD_RELOC_PPC64_REL24_NOTOC: r = R_PPC64_REL24_NOTOC;
+ break;
case BFD_RELOC_PPC_B16: r = R_PPC64_REL14;
break;
case BFD_RELOC_PPC_B16_BRTAKEN: r = R_PPC64_REL14_BRTAKEN;
case NT_PRPSINFO:
{
- char data[136];
+ char data[136] ATTRIBUTE_NONSTRING;
va_list ap;
va_start (ap, note_type);
memset (data, 0, sizeof (data));
strncpy (data + 40, va_arg (ap, const char *), 16);
+#if GCC_VERSION == 8000 || GCC_VERSION == 8001
+ DIAGNOSTIC_PUSH;
+ /* GCC 8.0 and 8.1 warn about 80 equals destination size with
+ -Wstringop-truncation:
+ https://gcc.gnu.org/bugzilla/show_bug.cgi?id=85643
+ */
+ DIAGNOSTIC_IGNORE_STRINGOP_TRUNCATION;
+#endif
strncpy (data + 56, va_arg (ap, const char *), 80);
+#if GCC_VERSION == 8000 || GCC_VERSION == 8001
+ DIAGNOSTIC_POP;
+#endif
va_end (ap);
return elfcore_write_note (abfd, buf, bufsiz,
"CORE", note_type, data, sizeof (data));
/* Flag set when small branches are detected. Used to
select suitable defaults for the stub group size. */
unsigned int has_14bit_branch:1;
+
+ /* Flag set when PLTCALL relocs are detected. */
+ unsigned int has_pltcall:1;
};
#define ppc64_elf_section_data(sec) \
if (!relocatable && symcount > 1)
{
- /* Trim duplicate syms, since we may have merged the normal and
- dynamic symbols. Actually, we only care about syms that have
- different values, so trim any with the same value. */
+ /* Trim duplicate syms, since we may have merged the normal
+ and dynamic symbols. Actually, we only care about syms
+ that have different values, so trim any with the same
+ value. Don't consider ifunc and ifunc resolver symbols
+ duplicates however, because GDB wants to know whether a
+ text symbol is an ifunc resolver. */
for (i = 1, j = 1; i < symcount; ++i)
- if (syms[i - 1]->value + syms[i - 1]->section->vma
- != syms[i]->value + syms[i]->section->vma)
- syms[j++] = syms[i];
+ {
+ const asymbol *s0 = syms[i - 1];
+ const asymbol *s1 = syms[i];
+
+ if ((s0->value + s0->section->vma
+ != s1->value + s1->section->vma)
+ || ((s0->flags & BSF_GNU_INDIRECT_FUNCTION)
+ != (s1->flags & BSF_GNU_INDIRECT_FUNCTION)))
+ syms[j++] = syms[i];
+ }
symcount = j;
}
Used to call a function in a shared library. If it so happens that
the plt entry referenced crosses a 64k boundary, then an extra
"addi %r11,%r11,xxx@toc@l" will be inserted before the "mtctr".
- . std %r2,40(%r1)
+ ppc_stub_plt_call_r2save starts with "std %r2,40(%r1)".
. addis %r11,%r2,xxx@toc@ha
. ld %r12,xxx+0@toc@l(%r11)
. mtctr %r12
. mtctr %r12
. bctr
- In cases where the "addis" instruction would add zero, the "addis" is
- omitted and following instructions modified slightly in some cases.
-*/
+ All of the above stubs are shown as their ELFv1 variants. ELFv2
+ variants exist too, simpler for plt calls since a new toc pointer
+ and static chain are not loaded by the stub. In addition, ELFv2
+ has some more complex stubs to handle calls marked with NOTOC
+ relocs from functions where r2 is not a valid toc pointer. These
+ come in two flavours, the ones shown below, and _both variants that
+ start with "std %r2,24(%r1)" to save r2 in the unlikely event that
+ one call is from a function where r2 is used as the toc pointer but
+ needs a toc adjusting stub for small-model multi-toc, and another
+ call is from a function where r2 is not valid.
+ ppc_stub_long_branch_notoc:
+ . mflr %r12
+ . bcl 20,31,1f
+ . 1:
+ . mflr %r11
+ . mtlr %r12
+ . lis %r12,xxx-1b@highest
+ . ori %r12,xxx-1b@higher
+ . sldi %r12,%r12,32
+ . oris %r12,%r12,xxx-1b@hi
+ . ori %r12,%r12,xxx-1b@l
+ . add %r12,%r11,%r12
+ . b dest
+
+ ppc_stub_plt_branch_notoc:
+ . mflr %r12
+ . bcl 20,31,1f
+ . 1:
+ . mflr %r11
+ . mtlr %r12
+ . lis %r12,xxx-1b@highest
+ . ori %r12,xxx-1b@higher
+ . sldi %r12,%r12,32
+ . oris %r12,%r12,xxx-1b@hi
+ . ori %r12,%r12,xxx-1b@l
+ . add %r12,%r11,%r12
+ . mtctr %r12
+ . bctr
+
+ ppc_stub_plt_call_notoc:
+ . mflr %r12
+ . bcl 20,31,1f
+ . 1:
+ . mflr %r11
+ . mtlr %r12
+ . lis %r12,xxx-1b@highest
+ . ori %r12,xxx-1b@higher
+ . sldi %r12,%r12,32
+ . oris %r12,%r12,xxx-1b@hi
+ . ori %r12,%r12,xxx-1b@l
+ . ldx %r12,%r11,%r12
+ . mtctr %r12
+ . bctr
+
+ In cases where the high instructions would add zero, they are
+ omitted and following instructions modified in some cases.
+
+ For a given stub group (a set of sections all using the same toc
+ pointer value) there will be just one stub type used for any
+ particular function symbol. For example, if printf is called from
+ code with the tocsave optimization (ie. r2 saved in function
+ prologue) and therefore calls use a ppc_stub_plt_call linkage stub,
+ and from other code without the tocsave optimization requiring a
+ ppc_stub_plt_call_r2save linkage stub, a single stub of the latter
+ type will be created. Calls with the tocsave optimization will
+ enter this stub after the instruction saving r2. A similar
+ situation exists when calls are marked with R_PPC64_REL24_NOTOC
+ relocations. These require a ppc_stub_plt_call_notoc linkage stub
+ to call an external function like printf. If other calls to printf
+ require a ppc_stub_plt_call linkage stub then a single
+ ppc_stub_plt_call_notoc linkage stub will be used for both types of
+ call. If other calls to printf require a ppc_stub_plt_call_r2save
+ linkage stub then a single ppc_stub_plt_call_both linkage stub will
+ be created and calls not requiring r2 to be saved will enter the
+ stub after the r2 save instruction. There is an analogous
+ hierarchy of long branch and plt branch stubs for local call
+ linkage. */
enum ppc_stub_type {
ppc_stub_none,
ppc_stub_long_branch,
ppc_stub_long_branch_r2off,
+ ppc_stub_long_branch_notoc,
+ ppc_stub_long_branch_both, /* r2off and notoc variants both needed. */
ppc_stub_plt_branch,
ppc_stub_plt_branch_r2off,
+ ppc_stub_plt_branch_notoc,
+ ppc_stub_plt_branch_both,
ppc_stub_plt_call,
ppc_stub_plt_call_r2save,
+ ppc_stub_plt_call_notoc,
+ ppc_stub_plt_call_both,
ppc_stub_global_entry,
ppc_stub_save_res
};
struct ppc_link_hash_entry *h;
struct plt_entry *plt_ent;
+ /* Symbol type. */
+ unsigned char symtype;
+
/* Symbol st_other. */
unsigned char other;
};
/* The above field is also used to mark function symbols. In which
case TLS_TLS will be 0. */
#define PLT_IFUNC 2 /* STT_GNU_IFUNC. */
+#define PLT_KEEP 4 /* inline plt call requires plt entry. */
#define NON_GOT 256 /* local symbol plt, not stored. */
};
asection *glink;
asection *global_entry;
asection *sfpr;
+ asection *pltlocal;
+ asection *relpltlocal;
asection *brlt;
asection *relbrlt;
asection *glink_eh_frame;
/* Set if tls optimization is enabled. */
unsigned int do_tls_opt:1;
+ /* Set if inline plt calls should be converted to direct calls. */
+ unsigned int can_convert_all_inline_plt:1;
+
/* Set on error. */
unsigned int stub_error:1;
/* Nonzero if this section has TLS related relocations. */
#define has_tls_reloc sec_flg0
-/* Nonzero if this section has a call to __tls_get_addr. */
+/* Nonzero if this section has an old-style call to __tls_get_addr. */
#define has_tls_get_addr_call sec_flg1
/* Nonzero if this section has any toc or got relocs. */
|| ! bfd_set_section_alignment (dynobj, htab->brlt, 3))
return FALSE;
+ /* Local plt entries, put in .branch_lt but a separate section for
+ convenience. */
+ htab->pltlocal = bfd_make_section_anyway_with_flags (dynobj, ".branch_lt",
+ flags);
+ if (htab->pltlocal == NULL
+ || ! bfd_set_section_alignment (dynobj, htab->pltlocal, 3))
+ return FALSE;
+
if (!bfd_link_pic (info))
return TRUE;
flags = (SEC_ALLOC | SEC_LOAD | SEC_READONLY
| SEC_HAS_CONTENTS | SEC_IN_MEMORY | SEC_LINKER_CREATED);
- htab->relbrlt = bfd_make_section_anyway_with_flags (dynobj,
- ".rela.branch_lt",
- flags);
+ htab->relbrlt
+ = bfd_make_section_anyway_with_flags (dynobj, ".rela.branch_lt", flags);
if (htab->relbrlt == NULL
|| ! bfd_set_section_alignment (dynobj, htab->relbrlt, 3))
return FALSE;
+ htab->relpltlocal
+ = bfd_make_section_anyway_with_flags (dynobj, ".rela.branch_lt", flags);
+ if (htab->relpltlocal == NULL
+ || ! bfd_set_section_alignment (dynobj, htab->relpltlocal, 3))
+ return FALSE;
+
return TRUE;
}
asection **sec,
bfd_vma *value)
{
- if (ELF_ST_TYPE (isym->st_info) == STT_GNU_IFUNC
- && (ibfd->flags & DYNAMIC) == 0
- && bfd_get_flavour (info->output_bfd) == bfd_target_elf_flavour)
- elf_tdata (info->output_bfd)->has_gnu_symbols |= elf_gnu_symbol_ifunc;
-
if (*sec != NULL
&& strcmp ((*sec)->name, ".opd") == 0)
{
is_branch_reloc (enum elf_ppc64_reloc_type r_type)
{
return (r_type == R_PPC64_REL24
+ || r_type == R_PPC64_REL24_NOTOC
|| 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);
+ || r_type == R_PPC64_ADDR14_BRNTAKEN
+ || r_type == R_PPC64_PLTCALL);
+}
+
+/* Relocs on inline plt call sequence insns prior to the call. */
+
+static bfd_boolean
+is_plt_seq_reloc (enum elf_ppc64_reloc_type r_type)
+{
+ return (r_type == R_PPC64_PLT16_HA
+ || r_type == R_PPC64_PLT16_HI
+ || r_type == R_PPC64_PLT16_LO
+ || r_type == R_PPC64_PLT16_LO_DS
+ || r_type == R_PPC64_PLTSEQ);
}
/* Look through the relocs for a section during the first phase, and
case R_PPC64_PLT16_HA:
case R_PPC64_PLT16_HI:
case R_PPC64_PLT16_LO:
+ case R_PPC64_PLT16_LO_DS:
case R_PPC64_PLT32:
case R_PPC64_PLT64:
/* This symbol requires a procedure linkage table entry. */
if (h->root.root.string[0] == '.'
&& h->root.root.string[1] != '\0')
((struct ppc_link_hash_entry *) h)->is_func = 1;
+ ((struct ppc_link_hash_entry *) h)->tls_mask |= PLT_KEEP;
plt_list = &h->plt.plist;
}
if (plt_list == NULL)
- {
- /* It does not make sense to have a procedure linkage
- table entry for a non-ifunc local symbol. */
- info->callbacks->einfo
- /* xgettext:c-format */
- (_("%H: %s reloc against local symbol\n"),
- abfd, sec, rel->r_offset,
- ppc64_elf_howto_table[r_type]->name);
- bfd_set_error (bfd_error_bad_value);
- return FALSE;
- }
+ plt_list = update_local_sym_info (abfd, symtab_hdr, r_symndx,
+ rel->r_addend,
+ NON_GOT | PLT_KEEP);
if (!update_plt_info (abfd, plt_list, rel->r_addend))
return FALSE;
break;
if (dest != sec)
ppc64_elf_section_data (sec)->has_14bit_branch = 1;
}
+ goto rel24;
+
+ case R_PPC64_PLTCALL:
+ ppc64_elf_section_data (sec)->has_pltcall = 1;
/* Fall through. */
case R_PPC64_REL24:
+ case R_PPC64_REL24_NOTOC:
+ rel24:
plt_list = ifunc;
if (h != NULL)
{
return FALSE;
}
- _bfd_elf_ppc_merge_fp_attributes (ibfd, info);
+ if (!_bfd_elf_ppc_merge_fp_attributes (ibfd, info))
+ return FALSE;
/* Merge Tag_compatibility attributes and any common GNU ones. */
- _bfd_elf_merge_object_attributes (ibfd, info);
-
- return TRUE;
+ return _bfd_elf_merge_object_attributes (ibfd, info);
}
static bfd_boolean
if (ent->plt.refcount > 0)
break;
if (ent == NULL
- || (h->type != STT_GNU_IFUNC && local))
+ || (h->type != STT_GNU_IFUNC
+ && local
+ && (htab->can_convert_all_inline_plt
+ || (((struct ppc_link_hash_entry *) h)->tls_mask
+ & (TLS_TLS | PLT_KEEP)) != PLT_KEEP)))
{
h->plt.plist = NULL;
h->needs_plt = 0;
if (!readonly_dynrelocs (h))
{
h->pointer_equality_needed = 0;
- /* If we haven't seen a branch reloc then we don't need
- a plt entry. */
+ /* If we haven't seen a branch reloc and the symbol
+ isn't an ifunc then we don't need a plt entry. */
if (!h->needs_plt)
h->plt.plist = NULL;
}
else if (!h->needs_plt
&& !readonly_dynrelocs (h))
{
- /* If we haven't seen a branch reloc then we don't need a
- plt entry. */
+ /* If we haven't seen a branch reloc and the symbol isn't an
+ ifunc then we don't need a plt entry. */
h->plt.plist = NULL;
h->pointer_equality_needed = 0;
return TRUE;
return TRUE;
}
+/* Analyze inline PLT call relocations to see whether calls to locally
+ defined functions can be converted to direct calls. */
+
+bfd_boolean
+ppc64_elf_inline_plt (struct bfd_link_info *info)
+{
+ struct ppc_link_hash_table *htab;
+ bfd *ibfd;
+ asection *sec;
+ bfd_vma low_vma, high_vma, limit;
+
+ htab = ppc_hash_table (info);
+ if (htab == NULL)
+ return FALSE;
+
+ /* A bl insn can reach -0x2000000 to 0x1fffffc. The limit is
+ reduced somewhat to cater for possible stubs that might be added
+ between the call and its destination. */
+ if (htab->params->group_size < 0)
+ {
+ limit = -htab->params->group_size;
+ if (limit == 1)
+ limit = 0x1e00000;
+ }
+ else
+ {
+ limit = htab->params->group_size;
+ if (limit == 1)
+ limit = 0x1c00000;
+ }
+
+ low_vma = -1;
+ high_vma = 0;
+ for (sec = info->output_bfd->sections; sec != NULL; sec = sec->next)
+ if ((sec->flags & (SEC_ALLOC | SEC_CODE)) == (SEC_ALLOC | SEC_CODE))
+ {
+ if (low_vma > sec->vma)
+ low_vma = sec->vma;
+ if (high_vma < sec->vma + sec->size)
+ high_vma = sec->vma + sec->size;
+ }
+
+ /* If a "bl" can reach anywhere in local code sections, then we can
+ convert all inline PLT sequences to direct calls when the symbol
+ is local. */
+ if (high_vma - low_vma < limit)
+ {
+ htab->can_convert_all_inline_plt = 1;
+ return TRUE;
+ }
+
+ /* Otherwise, go looking through relocs for cases where a direct
+ call won't reach. Mark the symbol on any such reloc to disable
+ the optimization and keep the PLT entry as it seems likely that
+ this will be better than creating trampolines. Note that this
+ will disable the optimization for all inline PLT calls to a
+ particular symbol, not just those that won't reach. The
+ difficulty in doing a more precise optimization is that the
+ linker needs to make a decision depending on whether a
+ particular R_PPC64_PLTCALL insn can be turned into a direct
+ call, for each of the R_PPC64_PLTSEQ and R_PPC64_PLT16* insns in
+ the sequence, and there is nothing that ties those relocs
+ together except their symbol. */
+
+ for (ibfd = info->input_bfds; ibfd != NULL; ibfd = ibfd->link.next)
+ {
+ Elf_Internal_Shdr *symtab_hdr;
+ Elf_Internal_Sym *local_syms;
+
+ if (!is_ppc64_elf (ibfd))
+ continue;
+
+ local_syms = NULL;
+ symtab_hdr = &elf_symtab_hdr (ibfd);
+
+ for (sec = ibfd->sections; sec != NULL; sec = sec->next)
+ if (ppc64_elf_section_data (sec)->has_pltcall
+ && !bfd_is_abs_section (sec->output_section))
+ {
+ Elf_Internal_Rela *relstart, *rel, *relend;
+
+ /* Read the relocations. */
+ relstart = _bfd_elf_link_read_relocs (ibfd, sec, NULL, NULL,
+ info->keep_memory);
+ if (relstart == NULL)
+ return FALSE;
+
+ relend = relstart + sec->reloc_count;
+ for (rel = relstart; rel < relend; )
+ {
+ enum elf_ppc64_reloc_type r_type;
+ unsigned long r_symndx;
+ asection *sym_sec;
+ struct elf_link_hash_entry *h;
+ Elf_Internal_Sym *sym;
+ unsigned char *tls_maskp;
+
+ r_type = ELF64_R_TYPE (rel->r_info);
+ if (r_type != R_PPC64_PLTCALL)
+ continue;
+
+ r_symndx = ELF64_R_SYM (rel->r_info);
+ if (!get_sym_h (&h, &sym, &sym_sec, &tls_maskp, &local_syms,
+ r_symndx, ibfd))
+ {
+ if (elf_section_data (sec)->relocs != relstart)
+ free (relstart);
+ if (local_syms != NULL
+ && symtab_hdr->contents != (unsigned char *) local_syms)
+ free (local_syms);
+ return FALSE;
+ }
+
+ if (sym_sec != NULL && sym_sec->output_section != NULL)
+ {
+ bfd_vma from, to;
+ if (h != NULL)
+ to = h->root.u.def.value;
+ else
+ to = sym->st_value;
+ to += (rel->r_addend
+ + sym_sec->output_offset
+ + sym_sec->output_section->vma);
+ from = (rel->r_offset
+ + sec->output_offset
+ + sec->output_section->vma);
+ if (to - from + limit < 2 * limit)
+ *tls_maskp &= ~PLT_KEEP;
+ }
+ }
+ if (elf_section_data (sec)->relocs != relstart)
+ free (relstart);
+ }
+
+ if (local_syms != NULL
+ && symtab_hdr->contents != (unsigned char *) local_syms)
+ {
+ if (!info->keep_memory)
+ free (local_syms);
+ else
+ symtab_hdr->contents = (unsigned char *) local_syms;
+ }
+ }
+
+ return TRUE;
+}
+
/* Set htab->tls_get_addr and call the generic ELF tls_setup function. */
asection *
case R_PPC64_TLSGD:
case R_PPC64_TLSLD:
+ if (rel + 1 < relend
+ && is_plt_seq_reloc (ELF64_R_TYPE (rel[1].r_info)))
+ {
+ if (pass != 0
+ && ELF64_R_TYPE (rel[1].r_info) != R_PPC64_PLTSEQ)
+ {
+ r_symndx = ELF64_R_SYM (rel[1].r_info);
+ if (!get_sym_h (&h, NULL, NULL, NULL, &locsyms,
+ r_symndx, ibfd))
+ goto err_free_rel;
+ if (h != NULL)
+ {
+ struct plt_entry *ent = NULL;
+
+ for (ent = h->plt.plist;
+ ent != NULL;
+ ent = ent->next)
+ if (ent->addend == rel[1].r_addend)
+ break;
+
+ if (ent != NULL
+ && ent->plt.refcount > 0)
+ ent->plt.refcount -= 1;
+ }
+ }
+ continue;
+ }
found_tls_get_addr_arg = 1;
/* Fall through. */
!= (TLS_TLS | TLS_MARK)))
continue;
- if (expecting_tls_get_addr && htab->tls_get_addr != NULL)
+ if (expecting_tls_get_addr)
{
- struct plt_entry *ent;
- for (ent = htab->tls_get_addr->elf.plt.plist;
- ent != NULL;
- ent = ent->next)
- if (ent->addend == 0)
- {
- if (ent->plt.refcount > 0)
- {
- ent->plt.refcount -= 1;
- expecting_tls_get_addr = 0;
- }
+ struct plt_entry *ent = NULL;
+
+ if (htab->tls_get_addr != NULL)
+ for (ent = htab->tls_get_addr->elf.plt.plist;
+ ent != NULL;
+ ent = ent->next)
+ if (ent->addend == 0)
break;
- }
- }
- if (expecting_tls_get_addr && htab->tls_get_addr_fd != NULL)
- {
- struct plt_entry *ent;
- for (ent = htab->tls_get_addr_fd->elf.plt.plist;
- ent != NULL;
- ent = ent->next)
- if (ent->addend == 0)
- {
- if (ent->plt.refcount > 0)
- ent->plt.refcount -= 1;
+ if (ent == NULL && htab->tls_get_addr_fd != NULL)
+ for (ent = htab->tls_get_addr_fd->elf.plt.plist;
+ ent != NULL;
+ ent = ent->next)
+ if (ent->addend == 0)
break;
- }
+
+ if (ent != NULL
+ && ent->plt.refcount > 0)
+ ent->plt.refcount -= 1;
}
if (tls_clear == 0)
}
}
- if ((htab->elf.dynamic_sections_created
- && h->dynindx != -1)
- || h->type == STT_GNU_IFUNC)
+ /* We might need a PLT entry when the symbol
+ a) is dynamic, or
+ b) is an ifunc, or
+ c) has plt16 relocs and has been processed by adjust_dynamic_symbol, or
+ d) has plt16 relocs and we are linking statically. */
+ if ((htab->elf.dynamic_sections_created && h->dynindx != -1)
+ || h->type == STT_GNU_IFUNC
+ || (h->needs_plt && h->dynamic_adjusted)
+ || (h->needs_plt
+ && h->def_regular
+ && !htab->elf.dynamic_sections_created
+ && !htab->can_convert_all_inline_plt
+ && (((struct ppc_link_hash_entry *) h)->tls_mask
+ & (TLS_TLS | PLT_KEEP)) == PLT_KEEP))
{
struct plt_entry *pent;
bfd_boolean doneone = FALSE;
if (!htab->elf.dynamic_sections_created
|| h->dynindx == -1)
{
- s = htab->elf.iplt;
- pent->plt.offset = s->size;
- s->size += PLT_ENTRY_SIZE (htab);
- s = htab->elf.irelplt;
+ if (h->type == STT_GNU_IFUNC)
+ {
+ s = htab->elf.iplt;
+ pent->plt.offset = s->size;
+ s->size += PLT_ENTRY_SIZE (htab);
+ s = htab->elf.irelplt;
+ }
+ else
+ {
+ s = htab->pltlocal;
+ pent->plt.offset = s->size;
+ s->size += LOCAL_PLT_ENTRY_SIZE (htab);
+ s = bfd_link_pic (info) ? htab->relpltlocal : NULL;
+ }
}
else
{
/* We also need to make an entry in the .rela.plt section. */
s = htab->elf.srelplt;
}
- s->size += sizeof (Elf64_External_Rela);
+ if (s != NULL)
+ s->size += sizeof (Elf64_External_Rela);
doneone = TRUE;
}
else
*pent = ent->next;
}
- /* Allocate space for calls to local STT_GNU_IFUNC syms in .iplt. */
- for (; local_plt < end_local_plt; ++local_plt)
+ /* Allocate space for plt calls to local syms. */
+ lgot_masks = (unsigned char *) end_local_plt;
+ for (; local_plt < end_local_plt; ++local_plt, ++lgot_masks)
{
struct plt_entry *ent;
for (ent = *local_plt; ent != NULL; ent = ent->next)
if (ent->plt.refcount > 0)
{
- s = htab->elf.iplt;
- ent->plt.offset = s->size;
- s->size += PLT_ENTRY_SIZE (htab);
-
- htab->elf.irelplt->size += sizeof (Elf64_External_Rela);
+ if ((*lgot_masks & (TLS_TLS | PLT_IFUNC)) == PLT_IFUNC)
+ {
+ s = htab->elf.iplt;
+ ent->plt.offset = s->size;
+ s->size += PLT_ENTRY_SIZE (htab);
+ htab->elf.irelplt->size += sizeof (Elf64_External_Rela);
+ }
+ else if (htab->can_convert_all_inline_plt
+ || (*lgot_masks & (TLS_TLS | PLT_KEEP)) != PLT_KEEP)
+ ent->plt.offset = (bfd_vma) -1;
+ else
+ {
+ s = htab->pltlocal;
+ ent->plt.offset = s->size;
+ s->size += LOCAL_PLT_ENTRY_SIZE (htab);
+ if (bfd_link_pic (info))
+ htab->relpltlocal->size += sizeof (Elf64_External_Rela);
+ }
}
else
ent->plt.offset = (bfd_vma) -1;
else if (s == htab->elf.sgot
|| s == htab->elf.splt
|| s == htab->elf.iplt
+ || s == htab->pltlocal
|| s == htab->glink
|| s == htab->global_entry
|| s == htab->elf.sdynbss
/* Determine if a long branch stub is needed. */
max_branch_offset = 1 << 25;
- if (r_type != R_PPC64_REL24)
+ if (r_type == R_PPC64_REL14
+ || r_type == R_PPC64_REL14_BRTAKEN
+ || r_type == R_PPC64_REL14_BRNTAKEN)
max_branch_offset = 1 << 15;
if (branch_offset + max_branch_offset >= 2 * max_branch_offset - local_off)
return ppc_stub_none;
}
+/* Builds a 64-bit offset in r12 then adds it to r11 (LOAD false) or
+ loads r12 from r11+r12 (LOAD true).
+ . lis %r12,xxx-1b@highest
+ . ori %r12,xxx-1b@higher
+ . sldi %r12,%r12,32
+ . oris %r12,%r12,xxx-1b@hi
+ . ori %r12,%r12,xxx-1b@l
+ . add %r12,%r11,%r12 */
+
+static bfd_byte *
+build_offset (bfd *abfd, bfd_byte *p, bfd_vma off, bfd_boolean load)
+{
+ if (off + 0x8000 < 0x10000)
+ {
+ if (load)
+ bfd_put_32 (abfd, LD_R12_0R11 + PPC_LO (off), p);
+ else
+ bfd_put_32 (abfd, ADDI_R12_R11 + PPC_LO (off), p);
+ p += 4;
+ }
+ else if (off + 0x80008000ULL < 0x100000000ULL)
+ {
+ bfd_put_32 (abfd, ADDIS_R12_R11 + PPC_HA (off), p);
+ p += 4;
+ if (load)
+ bfd_put_32 (abfd, LD_R12_0R12 + PPC_LO (off), p);
+ else
+ bfd_put_32 (abfd, ADDI_R12_R12 + PPC_LO (off), p);
+ p += 4;
+ }
+ else
+ {
+ if (off + 0x800000000000ULL < 0x1000000000000ULL)
+ {
+ bfd_put_32 (abfd, LI_R12_0 + ((off >> 32) & 0xffff), p);
+ p += 4;
+ }
+ else
+ {
+ bfd_put_32 (abfd, LIS_R12 + ((off >> 48) & 0xffff), p);
+ p += 4;
+ if (((off >> 32) & 0xffff) != 0)
+ {
+ bfd_put_32 (abfd, ORI_R12_R12_0 + ((off >> 32) & 0xffff), p);
+ p += 4;
+ }
+ }
+ if (((off >> 32) & 0xffffffffULL) != 0)
+ {
+ bfd_put_32 (abfd, SLDI_R12_R12_32, p);
+ p += 4;
+ }
+ if (PPC_HI (off) != 0)
+ {
+ bfd_put_32 (abfd, ORIS_R12_R12_0 + PPC_HI (off), p);
+ p += 4;
+ }
+ if (PPC_LO (off) != 0)
+ {
+ bfd_put_32 (abfd, ORI_R12_R12_0 + PPC_LO (off), p);
+ p += 4;
+ }
+ if (load)
+ bfd_put_32 (abfd, LDX_R12_R11_R12, p);
+ else
+ bfd_put_32 (abfd, ADD_R12_R11_R12, p);
+ p += 4;
+ }
+ return p;
+}
+
+static unsigned int
+size_offset (bfd_vma off)
+{
+ unsigned int size;
+ if (off + 0x8000 < 0x10000)
+ size = 4;
+ else if (off + 0x80008000ULL < 0x100000000ULL)
+ size = 8;
+ else
+ {
+ if (off + 0x800000000000ULL < 0x1000000000000ULL)
+ size = 4;
+ else
+ {
+ size = 4;
+ if (((off >> 32) & 0xffff) != 0)
+ size += 4;
+ }
+ if (((off >> 32) & 0xffffffffULL) != 0)
+ size += 4;
+ if (PPC_HI (off) != 0)
+ size += 4;
+ if (PPC_LO (off) != 0)
+ size += 4;
+ size += 4;
+ }
+ return size;
+}
+
/* With power7 weakly ordered memory model, it is possible for ld.so
to update a plt entry in one thread and have another thread see a
stale zero toc entry. To avoid this we need some sort of acquire
struct ppc_stub_hash_entry *stub_entry,
bfd_vma off)
{
- unsigned size = 12;
+ unsigned size;
+
+ if (stub_entry->stub_type >= ppc_stub_plt_call_notoc)
+ {
+ size = 24 + size_offset (off);
+ if (stub_entry->stub_type > ppc_stub_plt_call_notoc)
+ size += 4;
+ return size;
+ }
+ size = 12;
if (ALWAYS_EMIT_R2SAVE
|| stub_entry->stub_type == ppc_stub_plt_call_r2save)
size += 4;
bfd_vma plt_off)
{
int stub_align;
- unsigned stub_size = plt_stub_size (htab, stub_entry, plt_off);
+ unsigned stub_size;
bfd_vma stub_off = stub_entry->group->stub_sec->size;
if (htab->params->plt_stub_align >= 0)
}
stub_align = 1 << -htab->params->plt_stub_align;
+ stub_size = plt_stub_size (htab, stub_entry, plt_off);
if (((stub_off + stub_size - 1) & -stub_align) - (stub_off & -stub_align)
> ((stub_size - 1) & -stub_align))
return stub_align - (stub_off & (stub_align - 1));
struct ppc_link_hash_table *htab;
bfd_byte *loc;
bfd_byte *p;
- bfd_vma dest, off;
+ bfd_vma targ, off;
Elf_Internal_Rela *r;
asection *plt;
if (htab == NULL)
return FALSE;
- /* Make a note of the offset within the stubs for this entry. */
- stub_entry->stub_offset = stub_entry->group->stub_sec->size;
+ BFD_ASSERT (stub_entry->stub_offset >= stub_entry->group->stub_sec->size);
loc = stub_entry->group->stub_sec->contents + stub_entry->stub_offset;
htab->stub_count[stub_entry->stub_type - 1] += 1;
case ppc_stub_long_branch:
case ppc_stub_long_branch_r2off:
/* Branches are relative. This is where we are going to. */
- dest = (stub_entry->target_value
+ targ = (stub_entry->target_value
+ stub_entry->target_section->output_offset
+ stub_entry->target_section->output_section->vma);
- dest += PPC64_LOCAL_ENTRY_OFFSET (stub_entry->other);
- off = dest;
+ targ += PPC64_LOCAL_ENTRY_OFFSET (stub_entry->other);
/* And this is where we are coming from. */
- off -= (stub_entry->stub_offset
- + stub_entry->group->stub_sec->output_offset
- + stub_entry->group->stub_sec->output_section->vma);
+ off = (stub_entry->stub_offset
+ + stub_entry->group->stub_sec->output_offset
+ + stub_entry->group->stub_sec->output_section->vma);
+ off = targ - off;
p = loc;
if (stub_entry->stub_type == ppc_stub_long_branch_r2off)
return FALSE;
r->r_offset = p - 4 - stub_entry->group->stub_sec->contents;
r->r_info = ELF64_R_INFO (0, R_PPC64_REL24);
- r->r_addend = dest;
+ r->r_addend = targ;
if (stub_entry->h != NULL)
{
struct elf_link_hash_entry **hashes;
return FALSE;
}
- dest = (stub_entry->target_value
+ targ = (stub_entry->target_value
+ stub_entry->target_section->output_offset
+ stub_entry->target_section->output_section->vma);
if (stub_entry->stub_type != ppc_stub_plt_branch_r2off)
- dest += PPC64_LOCAL_ENTRY_OFFSET (stub_entry->other);
+ targ += PPC64_LOCAL_ENTRY_OFFSET (stub_entry->other);
- bfd_put_64 (htab->brlt->owner, dest,
+ bfd_put_64 (htab->brlt->owner, targ,
htab->brlt->contents + br_entry->offset);
if (br_entry->iter == htab->stub_iteration)
+ htab->brlt->output_offset
+ htab->brlt->output_section->vma);
rela.r_info = ELF64_R_INFO (0, R_PPC64_RELATIVE);
- rela.r_addend = dest;
+ rela.r_addend = targ;
rl = htab->relbrlt->contents;
rl += (htab->relbrlt->reloc_count++
+ htab->brlt->output_offset
+ htab->brlt->output_section->vma);
r->r_info = ELF64_R_INFO (0, R_PPC64_RELATIVE);
- r->r_addend = dest;
+ r->r_addend = targ;
}
}
- dest = (br_entry->offset
+ targ = (br_entry->offset
+ htab->brlt->output_offset
+ htab->brlt->output_section->vma);
- off = (dest
- - elf_gp (info->output_bfd)
- - htab->sec_info[stub_entry->group->link_sec->id].toc_off);
+ off = (elf_gp (info->output_bfd)
+ + htab->sec_info[stub_entry->group->link_sec->id].toc_off);
+ off = targ - off;
if (off + 0x80008000 > 0xffffffff || (off & 7) != 0)
{
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;
+ r[0].r_addend = targ;
if (PPC_HA (off) != 0)
{
r[0].r_info = ELF64_R_INFO (0, R_PPC64_TOC16_HA);
p += 4;
break;
- case ppc_stub_plt_call:
- case ppc_stub_plt_call_r2save:
- if (stub_entry->h != NULL
- && stub_entry->h->is_func_descriptor
- && stub_entry->h->oh != NULL)
+ case ppc_stub_long_branch_notoc:
+ case ppc_stub_long_branch_both:
+ case ppc_stub_plt_branch_notoc:
+ case ppc_stub_plt_branch_both:
+ case ppc_stub_plt_call_notoc:
+ case ppc_stub_plt_call_both:
+ p = loc;
+ off = (8 + stub_entry->stub_offset
+ + stub_entry->group->stub_sec->output_offset
+ + stub_entry->group->stub_sec->output_section->vma);
+ if (stub_entry->stub_type == ppc_stub_long_branch_both
+ || stub_entry->stub_type == ppc_stub_plt_branch_both
+ || stub_entry->stub_type == ppc_stub_plt_call_both)
{
- struct ppc_link_hash_entry *fh = ppc_follow_link (stub_entry->h->oh);
+ off += 4;
+ bfd_put_32 (htab->params->stub_bfd, STD_R2_0R1 + STK_TOC (htab), p);
+ p += 4;
+ }
+ if (stub_entry->stub_type >= ppc_stub_plt_call_notoc)
+ {
+ targ = stub_entry->plt_ent->plt.offset & ~1;
+ if (targ >= (bfd_vma) -2)
+ abort ();
+
+ plt = htab->elf.splt;
+ if (!htab->elf.dynamic_sections_created
+ || stub_entry->h == NULL
+ || stub_entry->h->elf.dynindx == -1)
+ {
+ if (stub_entry->symtype == STT_GNU_IFUNC)
+ plt = htab->elf.iplt;
+ else
+ plt = htab->pltlocal;
+ }
+ targ += plt->output_offset + plt->output_section->vma;
+ }
+ else
+ targ = (stub_entry->target_value
+ + stub_entry->target_section->output_offset
+ + stub_entry->target_section->output_section->vma);
+ off = targ - off;
+ bfd_put_32 (htab->params->stub_bfd, MFLR_R12, p);
+ p += 4;
+ bfd_put_32 (htab->params->stub_bfd, BCL_20_31, p);
+ p += 4;
+ bfd_put_32 (htab->params->stub_bfd, MFLR_R11, p);
+ p += 4;
+ bfd_put_32 (htab->params->stub_bfd, MTLR_R12, p);
+ p += 4;
+ p = build_offset (htab->params->stub_bfd, p, off,
+ stub_entry->stub_type >= ppc_stub_plt_call_notoc);
+ if (stub_entry->stub_type == ppc_stub_long_branch_notoc)
+ {
+ off += 8;
+ bfd_put_32 (htab->params->stub_bfd,
+ B_DOT | ((off - (p - loc)) & 0x3fffffc), p);
+ }
+ else if (stub_entry->stub_type == ppc_stub_long_branch_both)
+ {
+ off += 12;
+ bfd_put_32 (htab->params->stub_bfd,
+ B_DOT | ((off - (p - loc)) & 0x3fffffc), p);
+ }
+ else
+ {
+ bfd_put_32 (htab->params->stub_bfd, MTCTR_R12, p);
+ p += 4;
+ bfd_put_32 (htab->params->stub_bfd, BCTR, p);
+ }
+ p += 4;
+ break;
+
+ case ppc_stub_plt_call:
+ case ppc_stub_plt_call_r2save:
+ 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. */
}
/* Now build the stub. */
- dest = stub_entry->plt_ent->plt.offset & ~1;
- if (dest >= (bfd_vma) -2)
+ targ = stub_entry->plt_ent->plt.offset & ~1;
+ if (targ >= (bfd_vma) -2)
abort ();
plt = htab->elf.splt;
if (!htab->elf.dynamic_sections_created
|| stub_entry->h == NULL
|| stub_entry->h->elf.dynindx == -1)
- plt = htab->elf.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;
- if (htab->opd_abi)
- rela.r_info = ELF64_R_INFO (0, R_PPC64_JMP_IREL);
+ if (stub_entry->symtype == STT_GNU_IFUNC)
+ plt = htab->elf.iplt;
else
- rela.r_info = ELF64_R_INFO (0, R_PPC64_IRELATIVE);
- rela.r_addend = (stub_entry->target_value
- + stub_entry->target_section->output_offset
- + stub_entry->target_section->output_section->vma);
-
- 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;
- htab->local_ifunc_resolver = 1;
+ plt = htab->pltlocal;
}
+ targ += plt->output_offset + plt->output_section->vma;
- off = (dest
- - elf_gp (info->output_bfd)
- - htab->sec_info[stub_entry->group->link_sec->id].toc_off);
+ off = (elf_gp (info->output_bfd)
+ + htab->sec_info[stub_entry->group->link_sec->id].toc_off);
+ off = targ - off;
if (off + 0x80008000 > 0xffffffff || (off & 7) != 0)
{
return FALSE;
}
- if (htab->params->plt_stub_align != 0)
- {
- unsigned pad = plt_stub_pad (htab, stub_entry, off);
-
- stub_entry->group->stub_sec->size += pad;
- stub_entry->stub_offset = stub_entry->group->stub_sec->size;
- loc += pad;
- }
-
r = NULL;
if (info->emitrelocations)
{
r[0].r_offset = loc - stub_entry->group->stub_sec->contents;
if (bfd_big_endian (info->output_bfd))
r[0].r_offset += 2;
- r[0].r_addend = dest;
+ r[0].r_addend = targ;
}
if (stub_entry->h != NULL
&& (stub_entry->h == htab->tls_get_addr_fd
return FALSE;
}
- stub_entry->group->stub_sec->size += p - loc;
+ stub_entry->group->stub_sec->size = stub_entry->stub_offset + (p - loc);
if (htab->params->emit_stub_syms)
{
size_t len1, len2;
char *name;
const char *const stub_str[] = { "long_branch",
- "long_branch_r2off",
+ "long_branch",
+ "long_branch",
+ "long_branch",
+ "plt_branch",
+ "plt_branch",
+ "plt_branch",
"plt_branch",
- "plt_branch_r2off",
+ "plt_call",
+ "plt_call",
"plt_call",
"plt_call" };
struct ppc_stub_hash_entry *stub_entry;
struct bfd_link_info *info;
struct ppc_link_hash_table *htab;
- bfd_vma off;
+ bfd_vma targ, off;
int size;
/* Massage our args to the form they really have. */
if (htab == NULL)
return FALSE;
+ /* Make a note of the offset within the stubs for this entry. */
+ stub_entry->stub_offset = stub_entry->group->stub_sec->size;
+
if (stub_entry->h != NULL
&& stub_entry->h->save_res
&& stub_entry->h->elf.root.type == bfd_link_hash_defined
return TRUE;
}
- if (stub_entry->stub_type == ppc_stub_plt_call
- || stub_entry->stub_type == ppc_stub_plt_call_r2save)
+ if (stub_entry->stub_type >= ppc_stub_plt_call
+ && stub_entry->stub_type <= ppc_stub_plt_call_both)
{
asection *plt;
- off = stub_entry->plt_ent->plt.offset & ~(bfd_vma) 1;
- if (off >= (bfd_vma) -2)
+ targ = stub_entry->plt_ent->plt.offset & ~(bfd_vma) 1;
+ if (targ >= (bfd_vma) -2)
abort ();
plt = htab->elf.splt;
if (!htab->elf.dynamic_sections_created
|| stub_entry->h == NULL
|| stub_entry->h->elf.dynindx == -1)
- plt = htab->elf.iplt;
- off += (plt->output_offset
- + plt->output_section->vma
- - elf_gp (info->output_bfd)
- - htab->sec_info[stub_entry->group->link_sec->id].toc_off);
+ {
+ if (stub_entry->symtype == STT_GNU_IFUNC)
+ plt = htab->elf.iplt;
+ else
+ plt = htab->pltlocal;
+ }
+ targ += plt->output_offset + plt->output_section->vma;
+ if (stub_entry->stub_type >= ppc_stub_plt_call_notoc)
+ {
+ off = (8 + stub_entry->stub_offset
+ + stub_entry->group->stub_sec->output_offset
+ + stub_entry->group->stub_sec->output_section->vma);
+ if (stub_entry->stub_type > ppc_stub_plt_call_notoc)
+ off += 4;
+ }
+ else
+ off = (elf_gp (info->output_bfd)
+ + htab->sec_info[stub_entry->group->link_sec->id].toc_off);
+
+ if (htab->params->plt_stub_align != 0)
+ {
+ unsigned pad = plt_stub_pad (htab, stub_entry, targ - off);
+
+ stub_entry->group->stub_sec->size += pad;
+ stub_entry->stub_offset = stub_entry->group->stub_sec->size;
+ if (stub_entry->stub_type >= ppc_stub_plt_call_notoc)
+ off += pad;
+ }
+
+ off = targ - off;
size = plt_stub_size (htab, stub_entry, off);
- if (stub_entry->h != NULL
- && (stub_entry->h == htab->tls_get_addr_fd
- || stub_entry->h == htab->tls_get_addr)
- && htab->params->tls_get_addr_opt
- && (ALWAYS_EMIT_R2SAVE
- || stub_entry->stub_type == ppc_stub_plt_call_r2save))
- stub_entry->group->tls_get_addr_opt_bctrl
- = stub_entry->group->stub_sec->size + size - 5 * 4;
-
- if (htab->params->plt_stub_align)
- size += plt_stub_pad (htab, stub_entry, off);
- if (info->emitrelocations)
+
+ if (stub_entry->stub_type < ppc_stub_plt_call_notoc)
{
- stub_entry->group->stub_sec->reloc_count
- += ((PPC_HA (off) != 0)
- + (htab->opd_abi
- ? 2 + (htab->params->plt_static_chain
- && PPC_HA (off + 16) == PPC_HA (off))
- : 1));
- stub_entry->group->stub_sec->flags |= SEC_RELOC;
+ if (stub_entry->h != NULL
+ && (stub_entry->h == htab->tls_get_addr_fd
+ || stub_entry->h == htab->tls_get_addr)
+ && htab->params->tls_get_addr_opt
+ && (ALWAYS_EMIT_R2SAVE
+ || stub_entry->stub_type == ppc_stub_plt_call_r2save))
+ stub_entry->group->tls_get_addr_opt_bctrl
+ = stub_entry->stub_offset + size - 5 * 4;
+
+ if (info->emitrelocations)
+ {
+ stub_entry->group->stub_sec->reloc_count
+ += ((PPC_HA (off) != 0)
+ + (htab->opd_abi
+ ? 2 + (htab->params->plt_static_chain
+ && PPC_HA (off + 16) == PPC_HA (off))
+ : 1));
+ stub_entry->group->stub_sec->flags |= SEC_RELOC;
+ }
}
}
else
bfd_vma r2off = 0;
bfd_vma local_off = 0;
- off = (stub_entry->target_value
- + stub_entry->target_section->output_offset
- + stub_entry->target_section->output_section->vma);
- off -= (stub_entry->group->stub_sec->size
- + stub_entry->group->stub_sec->output_offset
- + stub_entry->group->stub_sec->output_section->vma);
+ targ = (stub_entry->target_value
+ + stub_entry->target_section->output_offset
+ + stub_entry->target_section->output_section->vma);
+ off = (stub_entry->stub_offset
+ + stub_entry->group->stub_sec->output_offset
+ + stub_entry->group->stub_sec->output_section->vma);
/* Reset the stub type from the plt variant in case we now
can reach with a shorter stub. */
size += 4;
if (PPC_LO (r2off) != 0)
size += 4;
- off -= size - 4;
+ off += size - 4;
}
-
- local_off = PPC64_LOCAL_ENTRY_OFFSET (stub_entry->other);
-
- /* If the branch offset is too big, use a ppc_stub_plt_branch.
- Do the same for -R objects without function descriptors. */
- if (off + (1 << 25) >= (bfd_vma) (1 << 26) - local_off
- || (stub_entry->stub_type == ppc_stub_long_branch_r2off
- && r2off == 0
- && htab->sec_info[stub_entry->target_section->id].toc_off == 0))
+ else if (stub_entry->stub_type >= ppc_stub_long_branch_notoc)
{
- struct ppc_branch_hash_entry *br_entry;
+ size = 20 + size_offset (targ - (off + 8));
+ if (stub_entry->stub_type > ppc_stub_long_branch_notoc)
+ size += 4;
+ off += size - 4;
+ }
+ off = targ - off;
- br_entry = ppc_branch_hash_lookup (&htab->branch_hash_table,
- stub_entry->root.string + 9,
- TRUE, FALSE);
- if (br_entry == NULL)
+ if (stub_entry->stub_type >= ppc_stub_long_branch_notoc)
+ {
+ if (off + (1 << 25) >= (bfd_vma) (1 << 26))
{
- _bfd_error_handler (_("can't build branch stub `%s'"),
- stub_entry->root.string);
- htab->stub_error = TRUE;
- return FALSE;
+ stub_entry->stub_type += (ppc_stub_plt_branch_notoc
+ - ppc_stub_long_branch_notoc);
+ size += 4;
}
-
- if (br_entry->iter != htab->stub_iteration)
+ }
+ else
+ {
+ local_off = PPC64_LOCAL_ENTRY_OFFSET (stub_entry->other);
+
+ /* If the branch offset is too big, use a ppc_stub_plt_branch.
+ Do the same for -R objects without function descriptors. */
+ if ((stub_entry->stub_type == ppc_stub_long_branch_r2off
+ && r2off == 0
+ && htab->sec_info[stub_entry->target_section->id].toc_off == 0)
+ || off + (1 << 25) >= (bfd_vma) (1 << 26) - local_off)
{
- br_entry->iter = htab->stub_iteration;
- br_entry->offset = htab->brlt->size;
- htab->brlt->size += 8;
+ struct ppc_branch_hash_entry *br_entry;
- if (htab->relbrlt != NULL)
- htab->relbrlt->size += sizeof (Elf64_External_Rela);
- else if (info->emitrelocations)
+ br_entry = ppc_branch_hash_lookup (&htab->branch_hash_table,
+ stub_entry->root.string + 9,
+ TRUE, FALSE);
+ if (br_entry == NULL)
{
- htab->brlt->reloc_count += 1;
- htab->brlt->flags |= SEC_RELOC;
+ _bfd_error_handler (_("can't build branch stub `%s'"),
+ stub_entry->root.string);
+ htab->stub_error = TRUE;
+ return FALSE;
}
- }
- stub_entry->stub_type += ppc_stub_plt_branch - ppc_stub_long_branch;
- off = (br_entry->offset
- + htab->brlt->output_offset
- + htab->brlt->output_section->vma
- - elf_gp (info->output_bfd)
- - htab->sec_info[stub_entry->group->link_sec->id].toc_off);
+ if (br_entry->iter != htab->stub_iteration)
+ {
+ br_entry->iter = htab->stub_iteration;
+ br_entry->offset = htab->brlt->size;
+ htab->brlt->size += 8;
- if (info->emitrelocations)
- {
- stub_entry->group->stub_sec->reloc_count
- += 1 + (PPC_HA (off) != 0);
- stub_entry->group->stub_sec->flags |= SEC_RELOC;
- }
+ if (htab->relbrlt != NULL)
+ htab->relbrlt->size += sizeof (Elf64_External_Rela);
+ else if (info->emitrelocations)
+ {
+ htab->brlt->reloc_count += 1;
+ htab->brlt->flags |= SEC_RELOC;
+ }
+ }
- if (stub_entry->stub_type != ppc_stub_plt_branch_r2off)
- {
- size = 12;
- if (PPC_HA (off) != 0)
- size = 16;
+ targ = (br_entry->offset
+ + htab->brlt->output_offset
+ + htab->brlt->output_section->vma);
+ off = (elf_gp (info->output_bfd)
+ + htab->sec_info[stub_entry->group->link_sec->id].toc_off);
+ off = targ - off;
+
+ if (info->emitrelocations)
+ {
+ stub_entry->group->stub_sec->reloc_count
+ += 1 + (PPC_HA (off) != 0);
+ stub_entry->group->stub_sec->flags |= SEC_RELOC;
+ }
+
+ stub_entry->stub_type
+ += ppc_stub_plt_branch - ppc_stub_long_branch;
+ if (stub_entry->stub_type != ppc_stub_plt_branch_r2off)
+ {
+ size = 12;
+ if (PPC_HA (off) != 0)
+ size = 16;
+ }
+ else
+ {
+ size = 16;
+ if (PPC_HA (off) != 0)
+ size += 4;
+
+ if (PPC_HA (r2off) != 0)
+ size += 4;
+ if (PPC_LO (r2off) != 0)
+ size += 4;
+ }
}
- else
+ else if (info->emitrelocations)
{
- size = 16;
- if (PPC_HA (off) != 0)
- size += 4;
-
- if (PPC_HA (r2off) != 0)
- size += 4;
- if (PPC_LO (r2off) != 0)
- size += 4;
+ stub_entry->group->stub_sec->reloc_count += 1;
+ stub_entry->group->stub_sec->flags |= SEC_RELOC;
}
}
- else if (info->emitrelocations)
- {
- stub_entry->group->stub_sec->reloc_count += 1;
- stub_entry->group->stub_sec->flags |= SEC_RELOC;
- }
}
stub_entry->group->stub_sec->size += size;
if (htab == NULL)
return -1;
- htab->sec_info_arr_size = bfd_get_next_section_id ();
+ htab->sec_info_arr_size = _bfd_section_id;
amt = sizeof (*htab->sec_info) * (htab->sec_info_arr_size);
htab->sec_info = bfd_zmalloc (amt);
if (htab->sec_info == NULL)
r_type = ELF64_R_TYPE (rel->r_info);
if (r_type != R_PPC64_REL24
+ && r_type != R_PPC64_REL24_NOTOC
&& r_type != R_PPC64_REL14
&& r_type != R_PPC64_REL14_BRTAKEN
- && r_type != R_PPC64_REL14_BRNTAKEN)
+ && r_type != R_PPC64_REL14_BRNTAKEN
+ && r_type != R_PPC64_PLTCALL)
continue;
r_symndx = ELF64_R_SYM (rel->r_info);
/* Only look for stubs on branch instructions. */
if (r_type != R_PPC64_REL24
+ && r_type != R_PPC64_REL24_NOTOC
&& r_type != R_PPC64_REL14
&& r_type != R_PPC64_REL14_BRTAKEN
&& r_type != R_PPC64_REL14_BRNTAKEN)
&plt_ent, destination,
local_off);
- if (stub_type != ppc_stub_plt_call)
+ if (r_type == R_PPC64_REL24_NOTOC)
+ {
+ if (stub_type == ppc_stub_plt_call)
+ stub_type = ppc_stub_plt_call_notoc;
+ else if (stub_type == ppc_stub_long_branch
+ || (code_sec != NULL
+ && code_sec->output_section != NULL
+ && (((hash ? hash->elf.other : sym->st_other)
+ & STO_PPC64_LOCAL_MASK)
+ != 1 << STO_PPC64_LOCAL_BIT)))
+ stub_type = ppc_stub_long_branch_notoc;
+ }
+ else if (stub_type != ppc_stub_plt_call)
{
/* Check whether we need a TOC adjusting stub.
Since the linker pastes together pieces from
_init and _fini functions, it may be that a
call to what looks like a local sym is in
fact a call needing a TOC adjustment. */
- if (code_sec != NULL
- && code_sec->output_section != NULL
- && (htab->sec_info[code_sec->id].toc_off
- != htab->sec_info[section->id].toc_off)
- && (code_sec->has_toc_reloc
- || code_sec->makes_toc_func_call))
+ if ((code_sec != NULL
+ && code_sec->output_section != NULL
+ && (htab->sec_info[code_sec->id].toc_off
+ != htab->sec_info[section->id].toc_off)
+ && (code_sec->has_toc_reloc
+ || code_sec->makes_toc_func_call))
+ || (((hash ? hash->elf.other : sym->st_other)
+ & STO_PPC64_LOCAL_MASK)
+ == 1 << STO_PPC64_LOCAL_BIT))
stub_type = ppc_stub_long_branch_r2off;
}
/* __tls_get_addr calls might be eliminated. */
if (stub_type != ppc_stub_plt_call
+ && stub_type != ppc_stub_plt_call_notoc
&& hash != NULL
&& (hash == htab->tls_get_addr
|| hash == htab->tls_get_addr_fd)
stub_name, FALSE, FALSE);
if (stub_entry != NULL)
{
- /* The proper stub has already been created. */
+ enum ppc_stub_type old_type;
+ /* A stub has already been created, but it may
+ not be the required type. We shouldn't be
+ transitioning from plt_call to long_branch
+ stubs or vice versa, but we might be
+ upgrading from plt_call to plt_call_r2save or
+ from long_branch to long_branch_r2off. */
free (stub_name);
- if (stub_type == ppc_stub_plt_call_r2save)
+ old_type = stub_entry->stub_type;
+ switch (old_type)
+ {
+ default:
+ abort ();
+
+ case ppc_stub_save_res:
+ continue;
+
+ case ppc_stub_plt_call:
+ case ppc_stub_plt_call_r2save:
+ case ppc_stub_plt_call_notoc:
+ case ppc_stub_plt_call_both:
+ if (stub_type == ppc_stub_plt_call)
+ continue;
+ else if (stub_type == ppc_stub_plt_call_r2save)
+ {
+ if (old_type == ppc_stub_plt_call_notoc)
+ stub_type = ppc_stub_plt_call_both;
+ }
+ else if (stub_type == ppc_stub_plt_call_notoc)
+ {
+ if (old_type == ppc_stub_plt_call_r2save)
+ stub_type = ppc_stub_plt_call_both;
+ }
+ else
+ abort ();
+ break;
+
+ case ppc_stub_plt_branch:
+ case ppc_stub_plt_branch_r2off:
+ case ppc_stub_plt_branch_notoc:
+ case ppc_stub_plt_branch_both:
+ old_type += (ppc_stub_long_branch
+ - ppc_stub_plt_branch);
+ /* Fall through. */
+ case ppc_stub_long_branch:
+ case ppc_stub_long_branch_r2off:
+ case ppc_stub_long_branch_notoc:
+ case ppc_stub_long_branch_both:
+ if (stub_type == ppc_stub_long_branch)
+ continue;
+ else if (stub_type == ppc_stub_long_branch_r2off)
+ {
+ if (old_type == ppc_stub_long_branch_notoc)
+ stub_type = ppc_stub_long_branch_both;
+ }
+ else if (stub_type == ppc_stub_long_branch_notoc)
+ {
+ if (old_type == ppc_stub_long_branch_r2off)
+ stub_type = ppc_stub_long_branch_both;
+ }
+ else
+ abort ();
+ break;
+ }
+ if (old_type < stub_type)
stub_entry->stub_type = stub_type;
continue;
}
}
stub_entry->stub_type = stub_type;
- if (stub_type != ppc_stub_plt_call
- && stub_type != ppc_stub_plt_call_r2save)
+ if (stub_type >= ppc_stub_plt_call
+ && stub_type <= ppc_stub_plt_call_both)
{
- stub_entry->target_value = code_value;
- stub_entry->target_section = code_sec;
+ stub_entry->target_value = sym_value;
+ stub_entry->target_section = sym_sec;
}
else
{
- stub_entry->target_value = sym_value;
- stub_entry->target_section = sym_sec;
+ stub_entry->target_value = code_value;
+ stub_entry->target_section = code_sec;
}
stub_entry->h = hash;
stub_entry->plt_ent = plt_ent;
+ stub_entry->symtype
+ = hash ? hash->elf.type : ELF_ST_TYPE (sym->st_info);
stub_entry->other = hash ? hash->elf.other : sym->st_other;
if (stub_entry->h != NULL)
}
/* Called via elf_link_hash_traverse from ppc64_elf_build_stubs to
- write out any global entry stubs. */
+ write out any global entry stubs, and PLT relocations. */
static bfd_boolean
-build_global_entry_stubs (struct elf_link_hash_entry *h, void *inf)
+build_global_entry_stubs_and_plt (struct elf_link_hash_entry *h, void *inf)
{
struct bfd_link_info *info;
struct ppc_link_hash_table *htab;
- struct plt_entry *pent;
+ struct plt_entry *ent;
asection *s;
if (h->root.type == bfd_link_hash_indirect)
return TRUE;
+ info = inf;
+ htab = ppc_hash_table (info);
+ if (htab == NULL)
+ return FALSE;
+
+ for (ent = h->plt.plist; ent != NULL; ent = ent->next)
+ if (ent->plt.offset != (bfd_vma) -1)
+ {
+ /* This symbol has an entry in the procedure linkage
+ table. Set it up. */
+ Elf_Internal_Rela rela;
+ asection *plt, *relplt;
+ bfd_byte *loc;
+
+ if (!htab->elf.dynamic_sections_created
+ || h->dynindx == -1)
+ {
+ if (!(h->def_regular
+ && (h->root.type == bfd_link_hash_defined
+ || h->root.type == bfd_link_hash_defweak)))
+ continue;
+ if (h->type == STT_GNU_IFUNC)
+ {
+ plt = htab->elf.iplt;
+ relplt = htab->elf.irelplt;
+ htab->local_ifunc_resolver = 1;
+ if (htab->opd_abi)
+ rela.r_info = ELF64_R_INFO (0, R_PPC64_JMP_IREL);
+ else
+ rela.r_info = ELF64_R_INFO (0, R_PPC64_IRELATIVE);
+ }
+ else
+ {
+ plt = htab->pltlocal;
+ if (bfd_link_pic (info))
+ {
+ relplt = htab->relpltlocal;
+ if (htab->opd_abi)
+ rela.r_info = ELF64_R_INFO (0, R_PPC64_JMP_SLOT);
+ else
+ rela.r_info = ELF64_R_INFO (0, R_PPC64_RELATIVE);
+ }
+ else
+ relplt = NULL;
+ }
+ 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);
+
+ if (relplt == NULL)
+ {
+ loc = plt->contents + ent->plt.offset;
+ bfd_put_64 (info->output_bfd, rela.r_addend, loc);
+ if (htab->opd_abi)
+ {
+ bfd_vma toc = elf_gp (info->output_bfd);
+ toc += htab->sec_info[h->root.u.def.section->id].toc_off;
+ bfd_put_64 (info->output_bfd, toc, loc + 8);
+ }
+ }
+ else
+ {
+ rela.r_offset = (plt->output_section->vma
+ + plt->output_offset
+ + ent->plt.offset);
+ loc = relplt->contents + (relplt->reloc_count++
+ * sizeof (Elf64_External_Rela));
+ bfd_elf64_swap_reloca_out (info->output_bfd, &rela, loc);
+ }
+ }
+ else
+ {
+ 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->elf.srelplt->contents
+ + ((ent->plt.offset - PLT_INITIAL_ENTRY_SIZE (htab))
+ / PLT_ENTRY_SIZE (htab) * sizeof (Elf64_External_Rela)));
+ if (h->type == STT_GNU_IFUNC && is_static_defined (h))
+ htab->maybe_local_ifunc_resolver = 1;
+ bfd_elf64_swap_reloca_out (info->output_bfd, &rela, loc);
+ }
+ }
+
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->global_entry;
- for (pent = h->plt.plist; pent != NULL; pent = pent->next)
- if (pent->plt.offset != (bfd_vma) -1
- && pent->addend == 0)
+ if (s == NULL || s->size == 0)
+ return TRUE;
+
+ for (ent = h->plt.plist; ent != NULL; ent = ent->next)
+ if (ent->plt.offset != (bfd_vma) -1
+ && ent->addend == 0)
{
bfd_byte *p;
asection *plt;
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;
+ {
+ if (h->type == STT_GNU_IFUNC)
+ plt = htab->elf.iplt;
+ else
+ plt = htab->pltlocal;
+ }
+ off = ent->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)
return TRUE;
}
+/* Write PLT relocs for locals. */
+
+static bfd_boolean
+write_plt_relocs_for_local_syms (struct bfd_link_info *info)
+{
+ struct ppc_link_hash_table *htab = ppc_hash_table (info);
+ bfd *ibfd;
+
+ for (ibfd = info->input_bfds; ibfd != NULL; ibfd = ibfd->link.next)
+ {
+ struct got_entry **lgot_ents, **end_lgot_ents;
+ struct plt_entry **local_plt, **lplt, **end_local_plt;
+ Elf_Internal_Shdr *symtab_hdr;
+ bfd_size_type locsymcount;
+ Elf_Internal_Sym *local_syms = NULL;
+ struct plt_entry *ent;
+
+ if (!is_ppc64_elf (ibfd))
+ continue;
+
+ lgot_ents = elf_local_got_ents (ibfd);
+ if (!lgot_ents)
+ continue;
+
+ symtab_hdr = &elf_symtab_hdr (ibfd);
+ locsymcount = symtab_hdr->sh_info;
+ end_lgot_ents = lgot_ents + locsymcount;
+ local_plt = (struct plt_entry **) end_lgot_ents;
+ end_local_plt = local_plt + locsymcount;
+ for (lplt = local_plt; lplt < end_local_plt; ++lplt)
+ for (ent = *lplt; ent != NULL; ent = ent->next)
+ if (ent->plt.offset != (bfd_vma) -1)
+ {
+ Elf_Internal_Sym *sym;
+ asection *sym_sec;
+ asection *plt, *relplt;
+ bfd_byte *loc;
+ bfd_vma val;
+
+ if (!get_sym_h (NULL, &sym, &sym_sec, NULL, &local_syms,
+ lplt - local_plt, ibfd))
+ {
+ if (local_syms != NULL
+ && symtab_hdr->contents != (unsigned char *) local_syms)
+ free (local_syms);
+ return FALSE;
+ }
+
+ val = sym->st_value + ent->addend;
+ val += PPC64_LOCAL_ENTRY_OFFSET (sym->st_other);
+ if (sym_sec != NULL && sym_sec->output_section != NULL)
+ val += sym_sec->output_offset + sym_sec->output_section->vma;
+
+ if (ELF_ST_TYPE (sym->st_info) == STT_GNU_IFUNC)
+ {
+ htab->local_ifunc_resolver = 1;
+ plt = htab->elf.iplt;
+ relplt = htab->elf.irelplt;
+ }
+ else
+ {
+ plt = htab->pltlocal;
+ relplt = bfd_link_pic (info) ? htab->relpltlocal : NULL;
+ }
+
+ if (relplt == NULL)
+ {
+ loc = plt->contents + ent->plt.offset;
+ bfd_put_64 (info->output_bfd, val, loc);
+ if (htab->opd_abi)
+ {
+ bfd_vma toc = elf_gp (ibfd);
+ bfd_put_64 (info->output_bfd, toc, loc + 8);
+ }
+ }
+ else
+ {
+ Elf_Internal_Rela rela;
+ rela.r_offset = (ent->plt.offset
+ + plt->output_offset
+ + plt->output_section->vma);
+ if (ELF_ST_TYPE (sym->st_info) == STT_GNU_IFUNC)
+ {
+ if (htab->opd_abi)
+ rela.r_info = ELF64_R_INFO (0, R_PPC64_JMP_IREL);
+ else
+ rela.r_info = ELF64_R_INFO (0, R_PPC64_IRELATIVE);
+ }
+ else
+ {
+ if (htab->opd_abi)
+ rela.r_info = ELF64_R_INFO (0, R_PPC64_JMP_SLOT);
+ else
+ rela.r_info = ELF64_R_INFO (0, R_PPC64_RELATIVE);
+ }
+ rela.r_addend = val;
+ loc = relplt->contents + (relplt->reloc_count++
+ * sizeof (Elf64_External_Rela));
+ bfd_elf64_swap_reloca_out (info->output_bfd, &rela, loc);
+ }
+ }
+
+ if (local_syms != NULL
+ && symtab_hdr->contents != (unsigned char *) local_syms)
+ {
+ if (!info->keep_memory)
+ free (local_syms);
+ else
+ symtab_hdr->contents = (unsigned char *) local_syms;
+ }
+ }
+ 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. */
}
}
- /* Build .glink global entry stubs. */
- if (htab->global_entry != NULL && htab->global_entry->size != 0)
- elf_link_hash_traverse (&htab->elf, build_global_entry_stubs, info);
+ /* Build .glink global entry stubs, and PLT relocs for globals. */
+ elf_link_hash_traverse (&htab->elf, build_global_entry_stubs_and_plt, info);
+
+ if (!write_plt_relocs_for_local_syms (info))
+ return FALSE;
if (htab->brlt != NULL && htab->brlt->size != 0)
{
"linker stubs in %u groups\n",
stub_sec_count),
stub_sec_count);
- sprintf (*stats + len, _(" branch %lu\n"
- " toc adjust %lu\n"
- " long branch %lu\n"
- " long toc adj %lu\n"
- " plt call %lu\n"
- " plt call toc %lu\n"
- " global entry %lu"),
+ sprintf (*stats + len, _(" branch %lu\n"
+ " branch toc adj %lu\n"
+ " branch notoc %lu\n"
+ " branch both %lu\n"
+ " long branch %lu\n"
+ " long toc adj %lu\n"
+ " long notoc %lu\n"
+ " long both %lu\n"
+ " plt call %lu\n"
+ " plt call save %lu\n"
+ " plt call notoc %lu\n"
+ " plt call both %lu\n"
+ " global entry %lu"),
htab->stub_count[ppc_stub_long_branch - 1],
htab->stub_count[ppc_stub_long_branch_r2off - 1],
+ htab->stub_count[ppc_stub_long_branch_notoc - 1],
+ htab->stub_count[ppc_stub_long_branch_both - 1],
htab->stub_count[ppc_stub_plt_branch - 1],
htab->stub_count[ppc_stub_plt_branch_r2off - 1],
+ htab->stub_count[ppc_stub_plt_branch_notoc - 1],
+ htab->stub_count[ppc_stub_plt_branch_both - 1],
htab->stub_count[ppc_stub_plt_call - 1],
htab->stub_count[ppc_stub_plt_call_r2save - 1],
+ htab->stub_count[ppc_stub_plt_call_notoc - 1],
+ htab->stub_count[ppc_stub_plt_call_both - 1],
htab->stub_count[ppc_stub_global_entry - 1]);
}
return TRUE;
unsigned char tls_mask, tls_gd, tls_type;
unsigned char sym_type;
bfd_vma relocation;
- bfd_boolean unresolved_reloc;
+ bfd_boolean unresolved_reloc, save_unresolved_reloc;
bfd_boolean warned;
enum { DEST_NORMAL, DEST_OPD, DEST_STUB } reloc_dest;
unsigned int insn;
unsigned int insn2;
bfd_vma offset = rel->r_offset;
+ if (is_plt_seq_reloc (ELF64_R_TYPE (rel[1].r_info)))
+ {
+ bfd_put_32 (output_bfd, NOP, contents + offset);
+ rel[1].r_info = ELF64_R_INFO (STN_UNDEF, R_PPC64_NONE);
+ break;
+ }
+
+ if (ELF64_R_TYPE (rel[1].r_info) == R_PPC64_PLTCALL)
+ bfd_put_32 (output_bfd, NOP, contents + offset + 4);
+
if ((tls_mask & TLS_TPRELGD) != 0)
{
/* IE */
unsigned int insn2;
bfd_vma offset = rel->r_offset;
+ if (is_plt_seq_reloc (ELF64_R_TYPE (rel[1].r_info)))
+ {
+ bfd_put_32 (output_bfd, NOP, contents + offset);
+ rel[1].r_info = ELF64_R_INFO (STN_UNDEF, R_PPC64_NONE);
+ break;
+ }
+
+ if (ELF64_R_TYPE (rel[1].r_info) == R_PPC64_PLTCALL)
+ bfd_put_32 (output_bfd, NOP, contents + offset + 4);
+
if (toc_symndx)
sec = local_sections[toc_symndx];
for (r_symndx = 0;
/* Fall through. */
case R_PPC64_REL24:
+ case R_PPC64_REL24_NOTOC:
+ case R_PPC64_PLTCALL:
/* Calls to functions with a different TOC, such as calls to
shared objects, need to alter the TOC pointer. This is
done using a linkage stub. A REL24 branching to these
fdh = ppc_follow_link (h->oh);
stub_entry = ppc_get_stub_entry (input_section, sec, fdh, &orig_rel,
htab);
+ if (r_type == R_PPC64_PLTCALL
+ && stub_entry != NULL
+ && stub_entry->stub_type >= ppc_stub_plt_call
+ && stub_entry->stub_type <= ppc_stub_plt_call_both)
+ stub_entry = NULL;
+
if (stub_entry != NULL
&& (stub_entry->stub_type == ppc_stub_plt_call
|| stub_entry->stub_type == ppc_stub_plt_call_r2save
+ || stub_entry->stub_type == ppc_stub_plt_call_both
|| stub_entry->stub_type == ppc_stub_plt_branch_r2off
- || stub_entry->stub_type == ppc_stub_long_branch_r2off))
+ || stub_entry->stub_type == ppc_stub_plt_branch_both
+ || stub_entry->stub_type == ppc_stub_long_branch_r2off
+ || stub_entry->stub_type == ppc_stub_long_branch_both))
{
bfd_boolean can_plt_call = FALSE;
/* The function doesn't use or change r2. */
can_plt_call = TRUE;
}
+ else if (r_type == R_PPC64_REL24_NOTOC)
+ {
+ /* NOTOC calls don't need to restore r2. */
+ can_plt_call = TRUE;
+ }
/* All of these stubs may modify r2, so there must be a
branch and link followed by a nop. The nop is
nop = bfd_get_32 (input_bfd,
contents + rel->r_offset + 4);
- if (nop == NOP
- || nop == CROR_151515 || nop == CROR_313131)
+ if (nop == LD_R2_0R1 + STK_TOC (htab))
+ can_plt_call = TRUE;
+ else if (nop == NOP
+ || nop == CROR_151515
+ || nop == CROR_313131)
{
if (h != NULL
&& (h == htab->tls_get_addr_fd
if (!can_plt_call)
{
- if (stub_entry->stub_type == ppc_stub_plt_call
- || stub_entry->stub_type == ppc_stub_plt_call_r2save)
+ if (stub_entry->stub_type >= ppc_stub_plt_call
+ && stub_entry->stub_type <= ppc_stub_plt_call_both)
info->callbacks->einfo
/* xgettext:c-format */
(_("%H: call to `%pT' lacks nop, can't restore toc; "
}
if (can_plt_call
- && (stub_entry->stub_type == ppc_stub_plt_call
- || stub_entry->stub_type == ppc_stub_plt_call_r2save))
+ && stub_entry->stub_type >= ppc_stub_plt_call
+ && stub_entry->stub_type <= ppc_stub_plt_call_both)
unresolved_reloc = FALSE;
}
/* Don't use the stub if this branch is in range. */
stub_entry = NULL;
+ if (stub_entry != NULL
+ && (stub_entry->stub_type == ppc_stub_long_branch_notoc
+ || stub_entry->stub_type == ppc_stub_long_branch_both
+ || stub_entry->stub_type == ppc_stub_plt_branch_notoc
+ || stub_entry->stub_type == ppc_stub_plt_branch_both)
+ && (r_type != R_PPC64_REL24_NOTOC
+ || ((fdh ? fdh->elf.other : sym->st_other)
+ & STO_PPC64_LOCAL_MASK) == 1 << STO_PPC64_LOCAL_BIT)
+ && (relocation + addend - from + max_br_offset
+ < 2 * max_br_offset))
+ stub_entry = NULL;
+
+ if (stub_entry != NULL
+ && (stub_entry->stub_type == ppc_stub_long_branch_r2off
+ || stub_entry->stub_type == ppc_stub_long_branch_both
+ || stub_entry->stub_type == ppc_stub_plt_branch_r2off
+ || stub_entry->stub_type == ppc_stub_plt_branch_both)
+ && r_type == R_PPC64_REL24_NOTOC
+ && (relocation + addend - from + max_br_offset
+ < 2 * max_br_offset))
+ stub_entry = NULL;
+
if (stub_entry != NULL)
{
/* Munge up the value and addend so that we call the stub
addend = 0;
reloc_dest = DEST_STUB;
- if ((stub_entry->stub_type == ppc_stub_plt_call
- || stub_entry->stub_type == ppc_stub_plt_call_r2save)
- && (ALWAYS_EMIT_R2SAVE
- || stub_entry->stub_type == ppc_stub_plt_call_r2save)
+ if (((stub_entry->stub_type == ppc_stub_plt_call
+ && ALWAYS_EMIT_R2SAVE)
+ || stub_entry->stub_type == ppc_stub_plt_call_r2save
+ || stub_entry->stub_type == ppc_stub_plt_call_both)
&& rel + 1 < relend
&& rel[1].r_offset == rel->r_offset + 4
&& ELF64_R_TYPE (rel[1].r_info) == R_PPC64_TOCSAVE)
relocation += 4;
+ else if ((stub_entry->stub_type == ppc_stub_long_branch_both
+ || stub_entry->stub_type == ppc_stub_plt_branch_both
+ || stub_entry->stub_type == ppc_stub_plt_call_both)
+ && r_type == R_PPC64_REL24_NOTOC)
+ relocation += 4;
}
if (insn != 0)
else if (h != NULL
&& h->elf.root.type == bfd_link_hash_undefweak
&& h->elf.dynindx == -1
- && r_type == R_PPC64_REL24
+ && (r_type == R_PPC64_REL24
+ || r_type == R_PPC64_REL24_NOTOC)
&& relocation == 0
&& addend == 0)
{
/* Set `addend'. */
tls_type = 0;
+ save_unresolved_reloc = unresolved_reloc;
switch (r_type)
{
default:
case R_PPC64_PLT16_HA:
case R_PPC64_PLT16_HI:
case R_PPC64_PLT16_LO:
+ case R_PPC64_PLT16_LO_DS:
case R_PPC64_PLT32:
case R_PPC64_PLT64:
+ case R_PPC64_PLTSEQ:
+ case R_PPC64_PLTCALL:
/* Relocation is to the entry for this symbol in the
procedure linkage table. */
+ unresolved_reloc = TRUE;
{
struct plt_entry **plt_list = NULL;
if (h != NULL)
{
struct plt_entry **local_plt = (struct plt_entry **)
(local_got_ents + symtab_hdr->sh_info);
- unsigned char *local_got_tls_masks = (unsigned char *)
- (local_plt + symtab_hdr->sh_info);
- if ((local_got_tls_masks[r_symndx] & PLT_IFUNC) != 0)
- plt_list = local_plt + r_symndx;
+ plt_list = local_plt + r_symndx;
}
if (plt_list)
{
&& ent->addend == orig_rel.r_addend)
{
asection *plt;
+ bfd_vma got;
plt = htab->elf.splt;
if (!htab->elf.dynamic_sections_created
|| h == NULL
|| h->elf.dynindx == -1)
- plt = htab->elf.iplt;
+ {
+ if (h != NULL
+ ? h->elf.type == STT_GNU_IFUNC
+ : ELF_ST_TYPE (sym->st_info) == STT_GNU_IFUNC)
+ plt = htab->elf.iplt;
+ else
+ plt = htab->pltlocal;
+ }
relocation = (plt->output_section->vma
+ plt->output_offset
+ ent->plt.offset);
+ if (r_type == R_PPC64_PLT16_HA
+ || r_type ==R_PPC64_PLT16_HI
+ || r_type ==R_PPC64_PLT16_LO
+ || r_type ==R_PPC64_PLT16_LO_DS)
+ {
+ got = (elf_gp (output_bfd)
+ + htab->sec_info[input_section->id].toc_off);
+ relocation -= got;
+ }
addend = 0;
unresolved_reloc = FALSE;
break;
case R_PPC64_REL14_BRNTAKEN:
case R_PPC64_REL14_BRTAKEN:
case R_PPC64_REL24:
+ case R_PPC64_REL24_NOTOC:
break;
case R_PPC64_TPREL16:
insn. */
break;
+ case R_PPC64_PLTCALL:
+ if (unresolved_reloc)
+ {
+ /* No plt entry. Make this into a direct call. */
+ bfd_byte *p = contents + rel->r_offset;
+ insn = bfd_get_32 (input_bfd, p);
+ insn &= 1;
+ bfd_put_32 (input_bfd, B_DOT | insn, p);
+ bfd_put_32 (input_bfd, NOP, p + 4);
+ unresolved_reloc = save_unresolved_reloc;
+ r_type = R_PPC64_REL24;
+ }
+ break;
+
+ case R_PPC64_PLTSEQ:
+ if (unresolved_reloc)
+ {
+ unresolved_reloc = FALSE;
+ goto nop_it;
+ }
+ break;
+
+ case R_PPC64_PLT16_HA:
+ if (unresolved_reloc)
+ {
+ unresolved_reloc = FALSE;
+ goto nop_it;
+ }
+ /* Fall through. */
case R_PPC64_GOT_TLSLD16_HA:
case R_PPC64_GOT_TLSGD16_HA:
case R_PPC64_GOT_TPREL16_HA:
if (htab->do_toc_opt && relocation + addend + 0x8000 < 0x10000
&& !ppc64_elf_tdata (input_bfd)->unexpected_toc_insn)
{
- bfd_byte *p = contents + (rel->r_offset & ~3);
+ bfd_byte *p;
+ nop_it:
+ p = contents + (rel->r_offset & ~3);
bfd_put_32 (input_bfd, NOP, p);
goto copy_reloc;
}
break;
+ case R_PPC64_PLT16_LO:
+ case R_PPC64_PLT16_LO_DS:
+ if (unresolved_reloc)
+ {
+ unresolved_reloc = FALSE;
+ goto nop_it;
+ }
+ /* Fall through. */
case R_PPC64_GOT_TLSLD16_LO:
case R_PPC64_GOT_TLSGD16_LO:
case R_PPC64_GOT_TPREL16_LO_DS:
{
struct ppc_link_hash_table *htab;
struct plt_entry *ent;
- Elf_Internal_Rela rela;
- bfd_byte *loc;
htab = ppc_hash_table (info);
if (htab == NULL)
return FALSE;
- for (ent = h->plt.plist; ent != NULL; ent = ent->next)
- if (ent->plt.offset != (bfd_vma) -1)
- {
- /* This symbol has an entry in the procedure linkage
- table. Set it up. */
- 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->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);
- else
- rela.r_info = ELF64_R_INFO (0, R_PPC64_IRELATIVE);
- 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->elf.irelplt->contents
- + (htab->elf.irelplt->reloc_count++
- * sizeof (Elf64_External_Rela)));
- htab->local_ifunc_resolver = 1;
- }
- else
- {
- 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->elf.srelplt->contents
- + ((ent->plt.offset - PLT_INITIAL_ENTRY_SIZE (htab))
- / PLT_ENTRY_SIZE (htab) * sizeof (Elf64_External_Rela)));
- if (h->type == STT_GNU_IFUNC && is_static_defined (h))
- htab->maybe_local_ifunc_resolver = 1;
- }
- 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 (!htab->opd_abi && !h->def_regular)
+ for (ent = h->plt.plist; ent != NULL; ent = ent->next)
+ if (ent->plt.offset != (bfd_vma) -1)
+ {
+ /* 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;
+ }
+ break;
+ }
if (h->needs_copy)
{
/* This symbol needs a copy reloc. Set it up. */
+ Elf_Internal_Rela rela;
asection *srel;
+ bfd_byte *loc;
if (h->dynindx == -1
|| (h->root.type != bfd_link_hash_defined