#include "elf32-ppc.h"
#include "elf-vxworks.h"
#include "dwarf2.h"
+#include "elf-linux-psinfo.h"
typedef enum split16_format_type
{
0, /* src_mask */
0xff, /* dst_mask */
TRUE), /* pcrel_offset */
-
+
/* A relative 15 bit branch. */
HOWTO (R_PPC_VLE_REL15, /* type */
1, /* rightshift */
0xfe, /* dst_mask */
TRUE), /* pcrel_offset */
- /* A relative 24 bit branch. */
+ /* A relative 24 bit branch. */
HOWTO (R_PPC_VLE_REL24, /* type */
1, /* rightshift */
2, /* size (0 = byte, 1 = short, 2 = long) */
0, /* rightshift */
2, /* size (0 = byte, 1 = short, 2 = long) */
32, /* bitsize */
- FALSE, /* pc_relative */ /* FIXME: Does this apply to split relocs? */
+ FALSE, /* pc_relative */
0, /* bitpos */
complain_overflow_bitfield, /* complain_on_overflow */
bfd_elf_generic_reloc, /* special_function */
"R_PPC_VLE_LO16A", /* name */
FALSE, /* partial_inplace */
0, /* src_mask */
- 0x1f00fff, /* dst_mask */
+ 0x1f007ff, /* dst_mask */
FALSE), /* pcrel_offset */
/* The 16 LSBS in split16d format. */
"R_PPC_VLE_HI16A", /* name */
FALSE, /* partial_inplace */
0, /* src_mask */
- 0x1f00fff, /* dst_mask */
+ 0x1f007ff, /* dst_mask */
FALSE), /* pcrel_offset */
/* Bits 16-31 split16d format. */
"R_PPC_VLE_HA16A", /* name */
FALSE, /* partial_inplace */
0, /* src_mask */
- 0x1f00fff, /* dst_mask */
+ 0x1f007ff, /* dst_mask */
FALSE), /* pcrel_offset */
/* Bits 16-31 (High Adjusted) in split16d format. */
"R_PPC_VLE_SDAREL_LO16A", /* name */
FALSE, /* partial_inplace */
0, /* src_mask */
- 0x1f00fff, /* dst_mask */
+ 0x1f007ff, /* dst_mask */
FALSE), /* pcrel_offset */
/* The 16 LSBS relative to _SDA_BASE_ in split16d format. */
"R_PPC_VLE_SDAREL_HI16A", /* name */
FALSE, /* partial_inplace */
0, /* src_mask */
- 0x1f00fff, /* dst_mask */
+ 0x1f007ff, /* dst_mask */
FALSE), /* pcrel_offset */
/* Bits 16-31 relative to _SDA_BASE_ in split16d format. */
"R_PPC_VLE_SDAREL_HA16A", /* name */
FALSE, /* partial_inplace */
0, /* src_mask */
- 0x1f00fff, /* dst_mask */
+ 0x1f007ff, /* dst_mask */
FALSE), /* pcrel_offset */
/* Bits 16-31 (HA) relative to _SDA_BASE split16d format. */
0xffff, /* dst_mask */
FALSE), /* pcrel_offset */
};
+
+/* External 32-bit PPC structure for PRPSINFO. This structure is
+ ABI-defined, thus we choose to use char arrays here in order to
+ avoid dealing with different types in different architectures.
+
+ The PPC 32-bit structure uses int for `pr_uid' and `pr_gid' while
+ most non-PPC architectures use `short int'.
+
+ This structure will ultimately be written in the corefile's note
+ section, as the PRPSINFO. */
+
+struct elf_external_ppc_linux_prpsinfo32
+ {
+ char pr_state; /* Numeric process state. */
+ char pr_sname; /* Char for pr_state. */
+ char pr_zomb; /* Zombie. */
+ char pr_nice; /* Nice val. */
+ char pr_flag[4]; /* Flags. */
+ char pr_uid[4];
+ char pr_gid[4];
+ char pr_pid[4];
+ char pr_ppid[4];
+ char pr_pgrp[4];
+ char pr_sid[4];
+ char pr_fname[16]; /* Filename of executable. */
+ char pr_psargs[80]; /* Initial part of arg list. */
+ };
+
+/* Helper macro to swap (properly handling endianess) things from the
+ `elf_internal_prpsinfo' structure to the `elf_external_ppc_prpsinfo32'
+ structure.
+
+ Note that FROM should be a pointer, and TO should be the explicit type. */
+
+#define PPC_LINUX_PRPSINFO32_SWAP_FIELDS(abfd, from, to) \
+ do \
+ { \
+ H_PUT_8 (abfd, from->pr_state, &to.pr_state); \
+ H_PUT_8 (abfd, from->pr_sname, &to.pr_sname); \
+ H_PUT_8 (abfd, from->pr_zomb, &to.pr_zomb); \
+ H_PUT_8 (abfd, from->pr_nice, &to.pr_nice); \
+ H_PUT_32 (abfd, from->pr_flag, to.pr_flag); \
+ H_PUT_32 (abfd, from->pr_uid, to.pr_uid); \
+ H_PUT_32 (abfd, from->pr_gid, to.pr_gid); \
+ H_PUT_32 (abfd, from->pr_pid, to.pr_pid); \
+ H_PUT_32 (abfd, from->pr_ppid, to.pr_ppid); \
+ H_PUT_32 (abfd, from->pr_pgrp, to.pr_pgrp); \
+ H_PUT_32 (abfd, from->pr_sid, to.pr_sid); \
+ strncpy (to.pr_fname, from->pr_fname, sizeof (to.pr_fname)); \
+ strncpy (to.pr_psargs, from->pr_psargs, sizeof (to.pr_psargs)); \
+ } while (0)
+
\f
/* Initialize the ppc_elf_howto_table, so that linear accesses can be done. */
case BFD_RELOC_NONE: r = R_PPC_NONE; break;
case BFD_RELOC_32: r = R_PPC_ADDR32; break;
case BFD_RELOC_PPC_BA26: r = R_PPC_ADDR24; break;
+ case BFD_RELOC_PPC64_ADDR16_DS:
case BFD_RELOC_16: r = R_PPC_ADDR16; break;
+ case BFD_RELOC_PPC64_ADDR16_LO_DS:
case BFD_RELOC_LO16: r = R_PPC_ADDR16_LO; break;
case BFD_RELOC_HI16: r = R_PPC_ADDR16_HI; break;
case BFD_RELOC_HI16_S: r = R_PPC_ADDR16_HA; break;
case BFD_RELOC_PPC_B16: r = R_PPC_REL14; break;
case BFD_RELOC_PPC_B16_BRTAKEN: r = R_PPC_REL14_BRTAKEN; break;
case BFD_RELOC_PPC_B16_BRNTAKEN: r = R_PPC_REL14_BRNTAKEN; break;
+ case BFD_RELOC_PPC64_GOT16_DS:
case BFD_RELOC_16_GOTOFF: r = R_PPC_GOT16; break;
+ case BFD_RELOC_PPC64_GOT16_LO_DS:
case BFD_RELOC_LO16_GOTOFF: r = R_PPC_GOT16_LO; break;
case BFD_RELOC_HI16_GOTOFF: r = R_PPC_GOT16_HI; break;
case BFD_RELOC_HI16_S_GOTOFF: r = R_PPC_GOT16_HA; break;
case BFD_RELOC_32_PCREL: r = R_PPC_REL32; break;
case BFD_RELOC_32_PLTOFF: r = R_PPC_PLT32; break;
case BFD_RELOC_32_PLT_PCREL: r = R_PPC_PLTREL32; break;
+ case BFD_RELOC_PPC64_PLT16_LO_DS:
case BFD_RELOC_LO16_PLTOFF: r = R_PPC_PLT16_LO; break;
case BFD_RELOC_HI16_PLTOFF: r = R_PPC_PLT16_HI; break;
case BFD_RELOC_HI16_S_PLTOFF: r = R_PPC_PLT16_HA; break;
case BFD_RELOC_GPREL16: r = R_PPC_SDAREL16; break;
+ case BFD_RELOC_PPC64_SECTOFF_DS:
case BFD_RELOC_16_BASEREL: r = R_PPC_SECTOFF; break;
+ case BFD_RELOC_PPC64_SECTOFF_LO_DS:
case BFD_RELOC_LO16_BASEREL: r = R_PPC_SECTOFF_LO; break;
case BFD_RELOC_HI16_BASEREL: r = R_PPC_SECTOFF_HI; break;
case BFD_RELOC_HI16_S_BASEREL: r = R_PPC_SECTOFF_HA; break;
case BFD_RELOC_CTOR: r = R_PPC_ADDR32; break;
+ case BFD_RELOC_PPC64_TOC16_DS:
case BFD_RELOC_PPC_TOC16: r = R_PPC_TOC16; break;
case BFD_RELOC_PPC_TLS: r = R_PPC_TLS; break;
case BFD_RELOC_PPC_TLSGD: r = R_PPC_TLSGD; break;
case BFD_RELOC_PPC_TLSLD: r = R_PPC_TLSLD; break;
case BFD_RELOC_PPC_DTPMOD: r = R_PPC_DTPMOD32; break;
+ case BFD_RELOC_PPC64_TPREL16_DS:
case BFD_RELOC_PPC_TPREL16: r = R_PPC_TPREL16; break;
+ case BFD_RELOC_PPC64_TPREL16_LO_DS:
case BFD_RELOC_PPC_TPREL16_LO: r = R_PPC_TPREL16_LO; break;
case BFD_RELOC_PPC_TPREL16_HI: r = R_PPC_TPREL16_HI; break;
case BFD_RELOC_PPC_TPREL16_HA: r = R_PPC_TPREL16_HA; break;
case BFD_RELOC_PPC_TPREL: r = R_PPC_TPREL32; break;
+ case BFD_RELOC_PPC64_DTPREL16_DS:
case BFD_RELOC_PPC_DTPREL16: r = R_PPC_DTPREL16; break;
+ case BFD_RELOC_PPC64_DTPREL16_LO_DS:
case BFD_RELOC_PPC_DTPREL16_LO: r = R_PPC_DTPREL16_LO; break;
case BFD_RELOC_PPC_DTPREL16_HI: r = R_PPC_DTPREL16_HI; break;
case BFD_RELOC_PPC_DTPREL16_HA: r = R_PPC_DTPREL16_HA; break;
(bfd_get_flavour (bfd) == bfd_target_elf_flavour \
&& elf_object_id (bfd) == PPC32_ELF_DATA)
-/* Rename some of the generic section flags to better document how they
- are used for ppc32. */
-
-/* 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. */
-#define has_tls_get_addr_call sec_flg1
-
-/* Nonzero if this secs_tls_get_addr_calltion has the VLE bit set. */
-#define has_vle_insns sec_flg2
-
-bfd_boolean
-is_ppc_vle (asection *sec)
-{
- return (sec->owner != NULL
- && is_ppc_elf (sec->owner)
- && sec->has_vle_insns);
-}
-
/* Override the generic function because we store some extras. */
static bfd_boolean
case 268: /* Linux/PPC. */
/* pr_cursig */
- elf_tdata (abfd)->core_signal = bfd_get_16 (abfd, note->descdata + 12);
+ elf_tdata (abfd)->core->signal = bfd_get_16 (abfd, note->descdata + 12);
/* pr_pid */
- elf_tdata (abfd)->core_lwpid = bfd_get_32 (abfd, note->descdata + 24);
+ elf_tdata (abfd)->core->lwpid = bfd_get_32 (abfd, note->descdata + 24);
/* pr_reg */
offset = 72;
return FALSE;
case 128: /* Linux/PPC elf_prpsinfo. */
- elf_tdata (abfd)->core_pid
+ elf_tdata (abfd)->core->pid
= bfd_get_32 (abfd, note->descdata + 16);
- elf_tdata (abfd)->core_program
+ elf_tdata (abfd)->core->program
= _bfd_elfcore_strndup (abfd, note->descdata + 32, 16);
- elf_tdata (abfd)->core_command
+ elf_tdata (abfd)->core->command
= _bfd_elfcore_strndup (abfd, note->descdata + 48, 80);
}
implementations, so strip it off if it exists. */
{
- char *command = elf_tdata (abfd)->core_command;
+ char *command = elf_tdata (abfd)->core->command;
int n = strlen (command);
if (0 < n && command[n - 1] == ' ')
return TRUE;
}
+char *
+elfcore_write_ppc_linux_prpsinfo32 (bfd *abfd, char *buf, int *bufsiz,
+ const struct elf_internal_linux_prpsinfo *prpsinfo)
+{
+ struct elf_external_ppc_linux_prpsinfo32 data;
+
+ memset (&data, 0, sizeof (data));
+ PPC_LINUX_PRPSINFO32_SWAP_FIELDS (abfd, prpsinfo, data);
+
+ return elfcore_write_note (abfd, buf, bufsiz,
+ "CORE", NT_PRPSINFO, &data, sizeof (data));
+}
+
static char *
ppc_elf_write_core_note (bfd *abfd, char *buf, int *bufsiz, int note_type, ...)
{
}
}
-static bfd_boolean
-ppc_elf_section_flags (flagword *flags ATTRIBUTE_UNUSED,
- const Elf_Internal_Shdr *hdr)
-{
- if (hdr->sh_flags & SHF_PPC_VLE)
- hdr->bfd_section->has_vle_insns = 1;
- return TRUE;
-}
-
static flagword
-ppc_elf_lookup_section_flags (char *flag_name)
+ppc_elf_lookup_section_flags (char *flag_name)
{
if (!strcmp (flag_name, "SHF_PPC_VLE"))
return ret;
}
-/* Modify the segment map for VLE executables. */
+/* Modify the segment map for VLE executables. */
bfd_boolean
ppc_elf_modify_segment_map (bfd *abfd,
If we find that case, we split the segment.
We maintain the original output section order. */
- for (m = elf_tdata (abfd)->segment_map; m != NULL; m = m->next)
+ for (m = elf_seg_map (abfd); m != NULL; m = m->next)
{
if (m->count == 0)
continue;
- sect0_vle = is_ppc_vle (m->sections[0]);
+ sect0_vle = (elf_section_flags (m->sections[0]) & SHF_PPC_VLE) != 0;
for (j = 1; j < m->count; ++j)
{
- if (is_ppc_vle (m->sections[j]) != sect0_vle)
+ sectj_vle = (elf_section_flags (m->sections[j]) & SHF_PPC_VLE) != 0;
+
+ if (sectj_vle != sect0_vle)
break;
}
if (j >= m->count)
continue;
- sectj_vle = is_ppc_vle (m->sections[j]);
-
/* sections 0..j-1 stay in this (current) segment,
the remainder are put in a new segment.
The scan resumes with the new segment. */
shared lib. */
#define ELIMINATE_COPY_RELOCS 1
+/* Used to track dynamic relocations for local symbols. */
+struct ppc_dyn_relocs
+{
+ struct ppc_dyn_relocs *next;
+
+ /* The input section of the reloc. */
+ asection *sec;
+
+ /* Total number of relocs copied for the input section. */
+ unsigned int count : 31;
+
+ /* Whether this entry is for STT_GNU_IFUNC symbols. */
+ unsigned int ifunc : 1;
+};
+
/* PPC ELF linker hash entry. */
struct ppc_elf_link_hash_entry
struct sym_cache sym_cache;
};
+/* Rename some of the generic section flags to better document how they
+ are used for ppc32. The flags are only valid for ppc32 elf objects. */
+
+/* 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. */
+#define has_tls_get_addr_call sec_flg1
+
/* Get the PPC ELF linker hash table from a link_info structure. */
#define ppc_elf_hash_table(p) \
return FALSE;
htab = ppc_elf_hash_table (info);
- htab->got = s = bfd_get_section_by_name (abfd, ".got");
+ htab->got = s = bfd_get_linker_section (abfd, ".got");
if (s == NULL)
abort ();
if (htab->is_vxworks)
{
- htab->sgotplt = bfd_get_section_by_name (abfd, ".got.plt");
+ htab->sgotplt = bfd_get_linker_section (abfd, ".got.plt");
if (!htab->sgotplt)
abort ();
}
return FALSE;
}
- htab->relgot = bfd_get_section_by_name (abfd, ".rela.got");
+ htab->relgot = bfd_get_linker_section (abfd, ".rela.got");
if (!htab->relgot)
abort ();
&& !ppc_elf_create_glink (abfd, info))
return FALSE;
- htab->dynbss = bfd_get_section_by_name (abfd, ".dynbss");
+ htab->dynbss = bfd_get_linker_section (abfd, ".dynbss");
s = bfd_make_section_anyway_with_flags (abfd, ".dynsbss",
SEC_ALLOC | SEC_LINKER_CREATED);
htab->dynsbss = s;
if (! info->shared)
{
- htab->relbss = bfd_get_section_by_name (abfd, ".rela.bss");
+ htab->relbss = bfd_get_linker_section (abfd, ".rela.bss");
flags = (SEC_ALLOC | SEC_LOAD | SEC_READONLY | SEC_HAS_CONTENTS
| SEC_IN_MEMORY | SEC_LINKER_CREATED);
s = bfd_make_section_anyway_with_flags (abfd, ".rela.sbss", flags);
&& !elf_vxworks_create_dynamic_sections (abfd, info, &htab->srelplt2))
return FALSE;
- htab->relplt = bfd_get_section_by_name (abfd, ".rela.plt");
- htab->plt = s = bfd_get_section_by_name (abfd, ".plt");
+ htab->relplt = bfd_get_linker_section (abfd, ".rela.plt");
+ htab->plt = s = bfd_get_linker_section (abfd, ".plt");
if (s == NULL)
abort ();
/* If we were called to copy over info for a weak sym, that's all.
You might think dyn_relocs need not be copied over; After all,
both syms will be dynamic or both non-dynamic so we're just
- moving reloc accounting around. However, ELIMINATE_COPY_RELOCS
+ moving reloc accounting around. However, ELIMINATE_COPY_RELOCS
code in ppc_elf_adjust_dynamic_symbol needs to check for
dyn_relocs in read-only sections, and it does so on what is the
DIR sym here. */
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;
+
+ /* PR15323, ref flags aren't set for references in the same
+ object. */
+ h->root.non_ir_ref = 1;
}
/* If a relocation refers to _GLOBAL_OFFSET_TABLE_, create the .got.
if (isym == NULL)
return FALSE;
- if (ELF_ST_TYPE (isym->st_info) == STT_GNU_IFUNC
- && (!info->shared
- || is_branch_reloc (r_type)))
+ if (ELF_ST_TYPE (isym->st_info) == STT_GNU_IFUNC)
{
struct plt_entry **ifunc;
- bfd_vma addend;
+ /* Set PLT_IFUNC flag for this sym, no GOT entry yet. */
ifunc = update_local_sym_info (abfd, symtab_hdr, r_symndx,
PLT_IFUNC);
if (ifunc == NULL)
/* STT_GNU_IFUNC symbols must have a PLT entry;
In a non-pie executable even when there are
no plt calls. */
- addend = 0;
- if (r_type == R_PPC_PLTREL24)
+ if (!info->shared
+ || is_branch_reloc (r_type))
{
- ppc_elf_tdata (abfd)->makes_plt_call = 1;
- if (info->shared)
- addend = rel->r_addend;
+ bfd_vma addend = 0;
+ if (r_type == R_PPC_PLTREL24)
+ {
+ ppc_elf_tdata (abfd)->makes_plt_call = 1;
+ if (info->shared)
+ addend = rel->r_addend;
+ }
+ if (!update_plt_info (abfd, ifunc, got2, addend))
+ return FALSE;
}
- if (!update_plt_info (abfd, ifunc, got2, addend))
- return FALSE;
}
}
htab->plt_type = PLT_OLD;
htab->old_bfd = abfd;
}
+ if (h != NULL && h->type == STT_GNU_IFUNC)
+ {
+ if (info->shared)
+ {
+ info->callbacks->einfo (_("%P: %H: @local call to ifunc %s\n"),
+ abfd, sec, rel->r_offset,
+ h->root.root.string);
+ bfd_set_error (bfd_error_bad_value);
+ return FALSE;
+ }
+ h->needs_plt = 1;
+ if (!update_plt_info (abfd, &h->plt.plist, NULL, 0))
+ return FALSE;
+ }
break;
/* This relocation describes the C++ object vtable hierarchy.
if ((info->shared
&& (must_be_dyn_reloc (info, r_type)
|| (h != NULL
- && (! info->symbolic
+ && (!SYMBOLIC_BIND (info, h)
|| h->root.type == bfd_link_hash_defweak
|| !h->def_regular))))
|| (ELIMINATE_COPY_RELOCS
&& (h->root.type == bfd_link_hash_defweak
|| !h->def_regular)))
{
- struct elf_dyn_relocs *p;
- struct elf_dyn_relocs **rel_head;
-
#ifdef DEBUG
fprintf (stderr,
"ppc_elf_check_relocs needs to "
relocations we need for this symbol. */
if (h != NULL)
{
+ struct elf_dyn_relocs *p;
+ struct elf_dyn_relocs **rel_head;
+
rel_head = &ppc_elf_hash_entry (h)->dyn_relocs;
+ p = *rel_head;
+ if (p == NULL || p->sec != sec)
+ {
+ p = bfd_alloc (htab->elf.dynobj, sizeof *p);
+ if (p == NULL)
+ return FALSE;
+ p->next = *rel_head;
+ *rel_head = p;
+ p->sec = sec;
+ p->count = 0;
+ p->pc_count = 0;
+ }
+ p->count += 1;
+ if (!must_be_dyn_reloc (info, r_type))
+ p->pc_count += 1;
}
else
{
/* Track dynamic relocs needed for local syms too.
We really need local syms available to do this
easily. Oh well. */
+ struct ppc_dyn_relocs *p;
+ struct ppc_dyn_relocs **rel_head;
+ bfd_boolean is_ifunc;
asection *s;
void *vpp;
Elf_Internal_Sym *isym;
s = sec;
vpp = &elf_section_data (s)->local_dynrel;
- rel_head = (struct elf_dyn_relocs **) vpp;
- }
-
- p = *rel_head;
- if (p == NULL || p->sec != sec)
- {
- p = bfd_alloc (htab->elf.dynobj, sizeof *p);
- if (p == NULL)
- return FALSE;
- p->next = *rel_head;
- *rel_head = p;
- p->sec = sec;
- p->count = 0;
- p->pc_count = 0;
+ rel_head = (struct ppc_dyn_relocs **) vpp;
+ is_ifunc = ELF_ST_TYPE (isym->st_info) == STT_GNU_IFUNC;
+ p = *rel_head;
+ if (p != NULL && p->sec == sec && p->ifunc != is_ifunc)
+ p = p->next;
+ if (p == NULL || p->sec != sec || p->ifunc != is_ifunc)
+ {
+ p = bfd_alloc (htab->elf.dynobj, sizeof *p);
+ if (p == NULL)
+ return FALSE;
+ p->next = *rel_head;
+ *rel_head = p;
+ p->sec = sec;
+ p->ifunc = is_ifunc;
+ p->count = 0;
+ }
+ p->count += 1;
}
-
- p->count += 1;
- if (!must_be_dyn_reloc (info, r_type))
- p->pc_count += 1;
}
break;
|| eh->elf.root.type != bfd_link_hash_undefweak))
{
asection *rsec = htab->relgot;
+
+ if (eh->elf.type == STT_GNU_IFUNC)
+ rsec = htab->reliplt;
/* All the entries we allocated need relocs.
Except LD only needs one. */
if ((eh->tls_mask & TLS_LD) != 0
for (p = eh->dyn_relocs; p != NULL; p = p->next)
{
asection *sreloc = elf_section_data (p->sec)->sreloc;
- if (!htab->elf.dynamic_sections_created)
+ if (eh->elf.type == STT_GNU_IFUNC)
sreloc = htab->reliplt;
sreloc->size += p->count * sizeof (Elf32_External_Rela);
}
/* Set the contents of the .interp section to the interpreter. */
if (info->executable)
{
- s = bfd_get_section_by_name (htab->elf.dynobj, ".interp");
+ s = bfd_get_linker_section (htab->elf.dynobj, ".interp");
BFD_ASSERT (s != NULL);
s->size = sizeof ELF_DYNAMIC_INTERPRETER;
s->contents = (unsigned char *) ELF_DYNAMIC_INTERPRETER;
for (s = ibfd->sections; s != NULL; s = s->next)
{
- struct elf_dyn_relocs *p;
+ struct ppc_dyn_relocs *p;
- for (p = ((struct elf_dyn_relocs *)
+ for (p = ((struct ppc_dyn_relocs *)
elf_section_data (s)->local_dynrel);
p != NULL;
p = p->next)
else if (p->count != 0)
{
asection *sreloc = elf_section_data (p->sec)->sreloc;
- if (!htab->elf.dynamic_sections_created)
+ if (p->ifunc)
sreloc = htab->reliplt;
sreloc->size += p->count * sizeof (Elf32_External_Rela);
if ((p->sec->output_section->flags
{
*local_got = allocate_got (htab, need);
if (info->shared)
- htab->relgot->size += (need
- * (sizeof (Elf32_External_Rela) / 4));
+ {
+ asection *srel = htab->relgot;
+ if ((*lgot_masks & PLT_IFUNC) != 0)
+ srel = htab->reliplt;
+ srel->size += need * (sizeof (Elf32_External_Rela) / 4);
+ }
}
}
else
if (htab->glink != NULL
&& htab->glink->size != 0
&& htab->glink_eh_frame != NULL
- && !bfd_is_abs_section (htab->glink_eh_frame->output_section))
+ && !bfd_is_abs_section (htab->glink_eh_frame->output_section)
+ && _bfd_elf_eh_frame_present (info))
{
s = htab->glink_eh_frame;
s->size = sizeof (glink_eh_frame_cie) + 20;
{
/* Strip these too. */
}
- else if (CONST_STRNEQ (bfd_get_section_name (dynobj, s), ".rela"))
+ else if (CONST_STRNEQ (bfd_get_section_name (htab->elf.dynobj, s),
+ ".rela"))
{
if (s->size != 0)
{
return FALSE;
}
- if (htab->glink != NULL && htab->glink->size != 0)
+ if (htab->plt_type == PLT_NEW
+ && htab->glink != NULL
+ && htab->glink->size != 0)
{
if (!add_dynamic_entry (DT_PPC_GOT, 0))
return FALSE;
if (!htab->no_tls_get_addr_opt
&& htab->tls_get_addr != NULL
&& htab->tls_get_addr->plt.plist != NULL
- && !add_dynamic_entry (DT_PPC_TLSOPT, 0))
+ && !add_dynamic_entry (DT_PPC_OPT, PPC_OPT_TLS))
return FALSE;
}
}
#undef add_dynamic_entry
+ if (htab->glink_eh_frame != NULL
+ && htab->glink_eh_frame->contents != NULL)
+ {
+ unsigned char *p = htab->glink_eh_frame->contents;
+ bfd_vma val;
+
+ memcpy (p, glink_eh_frame_cie, sizeof (glink_eh_frame_cie));
+ /* CIE length (rewrite in case little-endian). */
+ bfd_put_32 (htab->elf.dynobj, sizeof (glink_eh_frame_cie) - 4, p);
+ p += sizeof (glink_eh_frame_cie);
+ /* FDE length. */
+ val = htab->glink_eh_frame->size - 4 - sizeof (glink_eh_frame_cie);
+ bfd_put_32 (htab->elf.dynobj, val, p);
+ p += 4;
+ /* CIE pointer. */
+ val = p - htab->glink_eh_frame->contents;
+ bfd_put_32 (htab->elf.dynobj, val, p);
+ p += 4;
+ /* Offset to .glink. Set later. */
+ p += 4;
+ /* .glink size. */
+ bfd_put_32 (htab->elf.dynobj, htab->glink->size, p);
+ p += 4;
+ /* Augmentation. */
+ p += 1;
+
+ if (info->shared
+ && htab->elf.dynamic_sections_created)
+ {
+ bfd_vma adv = (htab->glink->size - GLINK_PLTRESOLVE + 8) >> 2;
+ if (adv < 64)
+ *p++ = DW_CFA_advance_loc + adv;
+ else if (adv < 256)
+ {
+ *p++ = DW_CFA_advance_loc1;
+ *p++ = adv;
+ }
+ else if (adv < 65536)
+ {
+ *p++ = DW_CFA_advance_loc2;
+ bfd_put_16 (htab->elf.dynobj, adv, p);
+ p += 2;
+ }
+ else
+ {
+ *p++ = DW_CFA_advance_loc4;
+ bfd_put_32 (htab->elf.dynobj, adv, p);
+ p += 4;
+ }
+ *p++ = DW_CFA_register;
+ *p++ = 65;
+ p++;
+ *p++ = DW_CFA_advance_loc + 4;
+ *p++ = DW_CFA_restore_extended;
+ *p++ = 65;
+ }
+ BFD_ASSERT ((bfd_vma) ((p + 3 - htab->glink_eh_frame->contents) & -4)
+ == htab->glink_eh_frame->size);
+ }
+
return TRUE;
}
return insn;
}
+static bfd_boolean
+is_insn_ds_form (unsigned int insn)
+{
+ return ((insn & (0x3f << 26)) == 58u << 26 /* ld,ldu,lwa */
+ || (insn & (0x3f << 26)) == 62u << 26 /* std,stdu,stq */
+ || (insn & (0x3f << 26)) == 57u << 26 /* lfdp */
+ || (insn & (0x3f << 26)) == 61u << 26 /* stfdp */);
+}
+
+static bfd_boolean
+is_insn_dq_form (unsigned int insn)
+{
+ return (insn & (0x3f << 26)) == 56u << 26; /* lq */
+}
+
/* The RELOCATE_SECTION function is called by the ELF backend linker
to handle the relocations for a section.
Elf_Internal_Rela *rel;
Elf_Internal_Rela *relend;
Elf_Internal_Rela outrel;
- asection *got2, *sreloc = NULL;
+ asection *got2;
bfd_vma *local_got_offsets;
bfd_boolean ret = TRUE;
bfd_vma d_offset = (bfd_big_endian (output_bfd) ? 2 : 0);
}
else
{
+ bfd_boolean ignored;
+
RELOC_FOR_GLOBAL_SYMBOL (info, input_bfd, input_section, rel,
r_symndx, symtab_hdr, sym_hashes,
h, sec, relocation,
- unresolved_reloc, warned);
+ unresolved_reloc, warned, ignored);
sym_name = h->root.root.string;
}
{
if (got2 != NULL
&& r_type == R_PPC_PLTREL24
- && rel->r_addend >= 32768)
+ && rel->r_addend != 0)
{
/* R_PPC_PLTREL24 is rather special. If non-zero, the
addend specifies the GOT pointer offset within .got2. */
unresolved_reloc = FALSE;
if (htab->plt_type == PLT_NEW
|| !htab->elf.dynamic_sections_created
- || h == NULL)
+ || h == NULL
+ || h->dynindx == -1)
relocation = (htab->glink->output_section->vma
+ htab->glink->output_offset
+ (ent->glink_offset & ~1));
;
else
{
+ BFD_ASSERT (h->dynindx != -1);
indx = h->dynindx;
unresolved_reloc = FALSE;
}
asection *rsec = htab->relgot;
bfd_byte * loc;
+ if (ifunc != NULL)
+ rsec = htab->reliplt;
outrel.r_offset = (htab->got->output_section->vma
+ htab->got->output_offset
+ off);
&& !h->def_regular))
{
int skip;
- bfd_byte * loc;
+ bfd_byte *loc;
+ asection *sreloc;
#ifdef DEBUG
fprintf (stderr, "ppc_elf_relocate_section needs to "
"create relocation for %s\n",
/* When generating a shared object, these relocations
are copied into the output file to be resolved at run
time. */
+ sreloc = elf_section_data (input_section)->sreloc;
+ if (ifunc)
+ sreloc = htab->reliplt;
if (sreloc == NULL)
- {
- sreloc = elf_section_data (input_section)->sreloc;
- if (!htab->elf.dynamic_sections_created)
- sreloc = htab->reliplt;
- if (sreloc == NULL)
- return FALSE;
- }
+ return FALSE;
skip = 0;
outrel.r_offset = _bfd_elf_section_offset (output_bfd, info,
|| h->root.type == bfd_link_hash_undefweak))
|| !SYMBOL_REFERENCES_LOCAL (info, h))
{
+ BFD_ASSERT (h->dynindx != -1);
unresolved_reloc = FALSE;
outrel.r_info = ELF32_R_INFO (h->dynindx, r_type);
outrel.r_addend = rel->r_addend;
unresolved_reloc = TRUE;
break;
}
- BFD_ASSERT (strcmp (bfd_get_section_name (abfd, sec), ".got") == 0
- || strcmp (bfd_get_section_name (abfd, sec), ".cgot") == 0);
+ BFD_ASSERT (strcmp (bfd_get_section_name (sec->owner, sec),
+ ".got") == 0
+ || strcmp (bfd_get_section_name (sec->owner, sec),
+ ".cgot") == 0);
addend -= sec->output_section->vma + sec->output_offset + 0x8000;
break;
case R_PPC_PLTREL24:
- if (h == NULL || ifunc != NULL)
- break;
- /* Relocation is to the entry for this symbol in the
- procedure linkage table. */
- {
- struct plt_entry *ent = find_plt_ent (&h->plt.plist, got2,
- info->shared ? addend : 0);
- addend = 0;
- if (ent == NULL
- || htab->plt == NULL)
- {
- /* We didn't make a PLT entry for this symbol. This
- happens when statically linking PIC code, or when
- using -Bsymbolic. */
- break;
- }
+ if (h != NULL && ifunc == NULL)
+ {
+ struct plt_entry *ent = find_plt_ent (&h->plt.plist, got2,
+ info->shared ? addend : 0);
+ if (ent == NULL
+ || htab->plt == NULL)
+ {
+ /* We didn't make a PLT entry for this symbol. This
+ happens when statically linking PIC code, or when
+ using -Bsymbolic. */
+ }
+ else
+ {
+ /* Relocation is to the entry for this symbol in the
+ procedure linkage table. */
+ unresolved_reloc = FALSE;
+ if (htab->plt_type == PLT_NEW)
+ relocation = (htab->glink->output_section->vma
+ + htab->glink->output_offset
+ + ent->glink_offset);
+ else
+ relocation = (htab->plt->output_section->vma
+ + htab->plt->output_offset
+ + ent->plt.offset);
+ }
+ }
- unresolved_reloc = FALSE;
- if (htab->plt_type == PLT_NEW)
- relocation = (htab->glink->output_section->vma
- + htab->glink->output_offset
- + ent->glink_offset);
- else
- relocation = (htab->plt->output_section->vma
- + htab->plt->output_offset
- + ent->plt.offset);
- }
+ /* R_PPC_PLTREL24 is rather special. If non-zero, the
+ addend specifies the GOT pointer offset within .got2.
+ Don't apply it to the relocation field. */
+ addend = 0;
break;
/* Relocate against _SDA_BASE_. */
}
addend -= SYM_VAL (sda);
- name = bfd_get_section_name (abfd, sec->output_section);
+ name = bfd_get_section_name (output_bfd, sec->output_section);
if (! ((CONST_STRNEQ (name, ".sdata")
&& (name[6] == 0 || name[6] == '.'))
|| (CONST_STRNEQ (name, ".sbss")
}
addend -= SYM_VAL (sda);
- name = bfd_get_section_name (abfd, sec->output_section);
+ name = bfd_get_section_name (output_bfd, sec->output_section);
if (! (CONST_STRNEQ (name, ".sdata2")
|| CONST_STRNEQ (name, ".sbss2")))
{
break;
}
- name = bfd_get_section_name (abfd, sec->output_section);
+ name = bfd_get_section_name (output_bfd, sec->output_section);
if (((CONST_STRNEQ (name, ".sdata")
&& (name[6] == 0 || name[6] == '.'))
|| (CONST_STRNEQ (name, ".sbss")
break;
}
- name = bfd_get_section_name (abfd, sec->output_section);
+ name = bfd_get_section_name (output_bfd, sec->output_section);
if (((CONST_STRNEQ (name, ".sdata")
&& (name[6] == 0 || name[6] == '.'))
|| (CONST_STRNEQ (name, ".sbss")
Bits 0:15 are not used. */
addend += 0x8000;
break;
+
+ case R_PPC_ADDR16:
+ case R_PPC_ADDR16_LO:
+ case R_PPC_GOT16:
+ case R_PPC_GOT16_LO:
+ case R_PPC_SDAREL16:
+ case R_PPC_SECTOFF:
+ case R_PPC_SECTOFF_LO:
+ case R_PPC_DTPREL16:
+ case R_PPC_DTPREL16_LO:
+ case R_PPC_TPREL16:
+ case R_PPC_TPREL16_LO:
+ case R_PPC_GOT_TLSGD16:
+ case R_PPC_GOT_TLSGD16_LO:
+ case R_PPC_GOT_TLSLD16:
+ case R_PPC_GOT_TLSLD16_LO:
+ case R_PPC_GOT_DTPREL16:
+ case R_PPC_GOT_DTPREL16_LO:
+ case R_PPC_GOT_TPREL16:
+ case R_PPC_GOT_TPREL16_LO:
+ {
+ /* The 32-bit ABI lacks proper relocations to deal with
+ certain 64-bit instructions. Prevent damage to bits
+ that make up part of the insn opcode. */
+ unsigned int insn, mask, lobit;
+
+ insn = bfd_get_32 (output_bfd, contents + rel->r_offset - d_offset);
+ mask = 0;
+ if (is_insn_ds_form (insn))
+ mask = 3;
+ else if (is_insn_dq_form (insn))
+ mask = 15;
+ else
+ break;
+ lobit = mask & (relocation + addend);
+ if (lobit != 0)
+ {
+ addend -= lobit;
+ info->callbacks->einfo
+ (_("%P: %H: error: %s against `%s' not a multiple of %u\n"),
+ input_bfd, input_section, rel->r_offset,
+ howto->name, sym_name, mask + 1);
+ bfd_set_error (bfd_error_bad_value);
+ ret = FALSE;
+ }
+ addend += insn & mask;
+ }
+ break;
}
#ifdef DEBUG
htab->plt->contents + ent->plt.offset + 28);
/* Fill in the GOT entry corresponding to this PLT slot with
- the address immediately after the the "bctr" instruction
+ the address immediately after the "bctr" instruction
in this PLT entry. */
bfd_put_32 (output_bfd, (htab->plt->output_section->vma
+ htab->plt->output_offset
fprintf (stderr, "\n");
#endif
- /* Mark some specially defined symbols as absolute. */
- if (strcmp (h->root.root.string, "_DYNAMIC") == 0
- || (!htab->is_vxworks
- && (h == htab->elf.hgot
- || strcmp (h->root.root.string,
- "_PROCEDURE_LINKAGE_TABLE_") == 0)))
- sym->st_shndx = SHN_ABS;
-
return TRUE;
}
\f
static enum elf_reloc_type_class
-ppc_elf_reloc_type_class (const Elf_Internal_Rela *rela)
+ppc_elf_reloc_type_class (const struct bfd_link_info *info,
+ const asection *rel_sec,
+ const Elf_Internal_Rela *rela)
{
+ struct ppc_elf_link_hash_table *htab = ppc_elf_hash_table (info);
+
+ if (rel_sec == htab->reliplt)
+ return reloc_class_ifunc;
+
switch (ELF32_R_TYPE (rela->r_info))
{
case R_PPC_RELATIVE:
return reloc_class_relative;
- case R_PPC_REL24:
- case R_PPC_ADDR24:
case R_PPC_JMP_SLOT:
return reloc_class_plt;
case R_PPC_COPY:
htab = ppc_elf_hash_table (info);
dynobj = elf_hash_table (info)->dynobj;
- sdyn = bfd_get_section_by_name (dynobj, ".dynamic");
+ sdyn = bfd_get_linker_section (dynobj, ".dynamic");
if (htab->is_vxworks)
- splt = bfd_get_section_by_name (dynobj, ".plt");
+ splt = bfd_get_linker_section (dynobj, ".plt");
else
splt = NULL;
unsigned char *p = htab->glink_eh_frame->contents;
bfd_vma val;
- memcpy (p, glink_eh_frame_cie, sizeof (glink_eh_frame_cie));
- /* CIE length (rewrite in case little-endian). */
- bfd_put_32 (htab->elf.dynobj, sizeof (glink_eh_frame_cie) - 4, p);
p += sizeof (glink_eh_frame_cie);
/* FDE length. */
- val = htab->glink_eh_frame->size - 4 - sizeof (glink_eh_frame_cie);
- bfd_put_32 (htab->elf.dynobj, val, p);
p += 4;
/* CIE pointer. */
- val = p - htab->glink_eh_frame->contents;
- bfd_put_32 (htab->elf.dynobj, val, p);
p += 4;
/* Offset to .glink. */
val = (htab->glink->output_section->vma
+ htab->glink_eh_frame->output_offset);
val -= p - htab->glink_eh_frame->contents;
bfd_put_32 (htab->elf.dynobj, val, p);
- p += 4;
- /* .glink size. */
- bfd_put_32 (htab->elf.dynobj, htab->glink->size, p);
- p += 4;
- /* Augmentation. */
- p += 1;
-
- if (info->shared
- && htab->elf.dynamic_sections_created)
- {
- bfd_vma adv = (htab->glink->size - GLINK_PLTRESOLVE + 8) >> 2;
- if (adv < 64)
- *p++ = DW_CFA_advance_loc + adv;
- else if (adv < 256)
- {
- *p++ = DW_CFA_advance_loc1;
- *p++ = adv;
- }
- else if (adv < 65536)
- {
- *p++ = DW_CFA_advance_loc2;
- bfd_put_16 (htab->elf.dynobj, adv, p);
- p += 2;
- }
- else
- {
- *p++ = DW_CFA_advance_loc4;
- bfd_put_32 (htab->elf.dynobj, adv, p);
- p += 4;
- }
- *p++ = DW_CFA_register;
- *p++ = 65;
- p++;
- *p++ = DW_CFA_advance_loc + 4;
- *p++ = DW_CFA_restore_extended;
- *p++ = 65;
- }
- BFD_ASSERT ((bfd_vma) ((p + 3 - htab->glink_eh_frame->contents) & -4)
- == htab->glink_eh_frame->size);
if (htab->glink_eh_frame->sec_info_type == SEC_INFO_TYPE_EH_FRAME
&& !_bfd_elf_write_section_eh_frame (output_bfd, info,
#define elf_backend_plt_sym_val ppc_elf_plt_sym_val
#define elf_backend_action_discarded ppc_elf_action_discarded
#define elf_backend_init_index_section _bfd_elf_init_1_index_section
-#define elf_backend_post_process_headers _bfd_elf_set_osabi
#define elf_backend_lookup_section_flags_hook ppc_elf_lookup_section_flags
-#define elf_backend_section_flags ppc_elf_section_flags
#define elf_backend_section_processing ppc_elf_section_processing
#include "elf32-target.h"