/* PowerPC64-specific support for 64-bit ELF.
- Copyright 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008,
- 2009, 2010, 2011, 2012 Free Software Foundation, Inc.
+ Copyright (C) 1999-2014 Free Software Foundation, Inc.
Written by Linus Nordberg, Swox AB <info@swox.com>,
based on elf32-ppc.c by Ian Lance Taylor.
Largely rewritten by Alan Modra.
static bfd_vma opd_entry_value
(asection *, bfd_vma, asection **, bfd_vma *, bfd_boolean);
-#define TARGET_LITTLE_SYM bfd_elf64_powerpcle_vec
+#define TARGET_LITTLE_SYM powerpc_elf64_le_vec
#define TARGET_LITTLE_NAME "elf64-powerpcle"
-#define TARGET_BIG_SYM bfd_elf64_powerpc_vec
+#define TARGET_BIG_SYM powerpc_elf64_vec
#define TARGET_BIG_NAME "elf64-powerpc"
#define ELF_ARCH bfd_arch_powerpc
#define ELF_TARGET_ID PPC64_ELF_DATA
#define bfd_elf64_bfd_print_private_bfd_data ppc64_elf_print_private_bfd_data
#define bfd_elf64_new_section_hook ppc64_elf_new_section_hook
#define bfd_elf64_bfd_link_hash_table_create ppc64_elf_link_hash_table_create
-#define bfd_elf64_bfd_link_hash_table_free ppc64_elf_link_hash_table_free
#define bfd_elf64_get_synthetic_symtab ppc64_elf_get_synthetic_symtab
#define bfd_elf64_bfd_link_just_syms ppc64_elf_link_just_syms
#define elf_backend_create_dynamic_sections ppc64_elf_create_dynamic_sections
#define elf_backend_copy_indirect_symbol ppc64_elf_copy_indirect_symbol
#define elf_backend_add_symbol_hook ppc64_elf_add_symbol_hook
-#define elf_backend_check_directives ppc64_elf_process_dot_syms
+#define elf_backend_check_directives ppc64_elf_before_check_relocs
#define elf_backend_notice_as_needed ppc64_elf_notice_as_needed
#define elf_backend_archive_symbol_lookup ppc64_elf_archive_symbol_lookup
#define elf_backend_check_relocs ppc64_elf_check_relocs
#define elf_backend_finish_dynamic_sections ppc64_elf_finish_dynamic_sections
#define elf_backend_link_output_symbol_hook ppc64_elf_output_symbol_hook
#define elf_backend_special_sections ppc64_elf_special_sections
-#define elf_backend_post_process_headers _bfd_elf_set_osabi
#define elf_backend_merge_symbol_attribute ppc64_elf_merge_symbol_attribute
/* The name of the dynamic interpreter. This is put in the .interp
/* Offsets to some stack save slots. */
#define STK_LR 16
#define STK_TOC(htab) (htab->opd_abi ? 40 : 24)
-/* This one is dodgy. ABIv2 does not have a linker word, so use the
+/* This one is dodgy. ELFv2 does not have a linker word, so use the
CR save slot. Used only by optimised __tls_get_addr call stub,
relying on __tls_get_addr_opt not saving CR.. */
#define STK_LINKER(htab) (htab->opd_abi ? 32 : 8)
#define LD_R2_0R1 0xe8410000 /* ld %r2,0(%r1) */
+#define ADDIS_R12_R2 0x3d820000 /* addis %r12,%r2,xxx@ha */
#define ADDIS_R12_R12 0x3d8c0000 /* addis %r12,%r12,xxx@ha */
#define LD_R12_0R12 0xe98c0000 /* ld %r12,xxx@l(%r12) */
#ifndef NO_OPD_RELOCS
#define NO_OPD_RELOCS 0
#endif
+
+static inline int
+abiversion (bfd *abfd)
+{
+ return elf_elfheader (abfd)->e_flags & EF_PPC64_ABI;
+}
+
+static inline void
+set_abiversion (bfd *abfd, int ver)
+{
+ elf_elfheader (abfd)->e_flags &= ~EF_PPC64_ABI;
+ elf_elfheader (abfd)->e_flags |= ver & EF_PPC64_ABI;
+}
\f
#define ONES(n) (((bfd_vma) 1 << ((n) - 1) << 1) - 1)
16, /* bitsize */
FALSE, /* pc_relative */
0, /* bitpos */
- complain_overflow_bitfield, /* complain_on_overflow */
+ complain_overflow_signed, /* complain_on_overflow */
ppc64_elf_branch_reloc, /* special_function */
"R_PPC64_ADDR14", /* name */
FALSE, /* partial_inplace */
16, /* bitsize */
FALSE, /* pc_relative */
0, /* bitpos */
- complain_overflow_bitfield, /* complain_on_overflow */
+ complain_overflow_signed, /* complain_on_overflow */
ppc64_elf_brtaken_reloc, /* special_function */
"R_PPC64_ADDR14_BRTAKEN",/* name */
FALSE, /* partial_inplace */
16, /* bitsize */
FALSE, /* pc_relative */
0, /* bitpos */
- complain_overflow_bitfield, /* complain_on_overflow */
+ complain_overflow_signed, /* complain_on_overflow */
ppc64_elf_brtaken_reloc, /* special_function */
"R_PPC64_ADDR14_BRNTAKEN",/* name */
FALSE, /* partial_inplace */
32, /* bitsize */
TRUE, /* pc_relative */
0, /* bitpos */
- /* FIXME: Verify. Was complain_overflow_bitfield. */
complain_overflow_signed, /* complain_on_overflow */
bfd_elf_generic_reloc, /* special_function */
"R_PPC64_REL32", /* name */
16, /* bitsize */
FALSE, /* pc_relative */
0, /* bitpos */
- complain_overflow_bitfield, /* complain_on_overflow */
+ complain_overflow_signed, /* complain_on_overflow */
ppc64_elf_sectoff_reloc, /* special_function */
"R_PPC64_SECTOFF", /* name */
FALSE, /* partial_inplace */
64, /* bitsize */
FALSE, /* pc_relative */
0, /* bitpos */
- complain_overflow_bitfield, /* complain_on_overflow */
+ complain_overflow_dont, /* complain_on_overflow */
ppc64_elf_toc64_reloc, /* special_function */
"R_PPC64_TOC", /* name */
FALSE, /* partial_inplace */
16, /* bitsize */
FALSE, /* pc_relative */
0, /* bitpos */
- complain_overflow_bitfield, /* complain_on_overflow */
+ complain_overflow_signed, /* complain_on_overflow */
bfd_elf_generic_reloc, /* special_function */
"R_PPC64_ADDR16_DS", /* name */
FALSE, /* partial_inplace */
16, /* bitsize */
FALSE, /* pc_relative */
0, /* bitpos */
- complain_overflow_bitfield, /* complain_on_overflow */
+ complain_overflow_signed, /* complain_on_overflow */
ppc64_elf_sectoff_reloc, /* special_function */
"R_PPC64_SECTOFF_DS", /* name */
FALSE, /* partial_inplace */
16, /* bitsize */
TRUE, /* pc_relative */
0, /* bitpos */
- complain_overflow_bitfield, /* complain_on_overflow */
+ complain_overflow_signed, /* complain_on_overflow */
bfd_elf_generic_reloc, /* special_function */
"R_PPC64_REL16", /* name */
FALSE, /* partial_inplace */
0xffff, /* dst_mask */
FALSE), /* pcrel_offset */
+ /* Like ADDR64, but use local entry point of function. */
+ HOWTO (R_PPC64_ADDR64_LOCAL, /* type */
+ 0, /* rightshift */
+ 4, /* size (0=byte, 1=short, 2=long, 4=64 bits) */
+ 64, /* bitsize */
+ FALSE, /* pc_relative */
+ 0, /* bitpos */
+ complain_overflow_dont, /* complain_on_overflow */
+ bfd_elf_generic_reloc, /* special_function */
+ "R_PPC64_ADDR64_LOCAL", /* name */
+ FALSE, /* partial_inplace */
+ 0, /* src_mask */
+ ONES (64), /* dst_mask */
+ FALSE), /* pcrel_offset */
+
/* GNU extension to record C++ vtable hierarchy. */
HOWTO (R_PPC64_GNU_VTINHERIT, /* type */
0, /* rightshift */
break;
case BFD_RELOC_HI16_S_PCREL: r = R_PPC64_REL16_HA;
break;
+ case BFD_RELOC_PPC64_ADDR64_LOCAL: r = R_PPC64_ADDR64_LOCAL;
+ break;
case BFD_RELOC_VTABLE_INHERIT: r = R_PPC64_GNU_VTINHERIT;
break;
case BFD_RELOC_VTABLE_ENTRY: r = R_PPC64_GNU_VTENTRY;
+ symbol->section->output_section->vma
+ symbol->section->output_offset);
}
+ else
+ {
+ elf_symbol_type *elfsym = (elf_symbol_type *) symbol;
+
+ if (symbol->section->owner != abfd
+ && abiversion (symbol->section->owner) >= 2)
+ {
+ unsigned int i;
+
+ for (i = 0; i < symbol->section->owner->symcount; ++i)
+ {
+ asymbol *symdef = symbol->section->owner->outsymbols[i];
+
+ if (strcmp (symdef->name, symbol->name) == 0)
+ {
+ elfsym = (elf_symbol_type *) symdef;
+ break;
+ }
+ }
+ }
+ reloc_entry->addend
+ += PPC64_LOCAL_ENTRY_OFFSET (elfsym->internal_elf_sym.st_other);
+ }
return bfd_reloc_continue;
}
return &ppc64_elf_section_data (sec)->u.opd;
return NULL;
}
-
-static inline int
-abiversion (bfd *abfd)
-{
- return elf_elfheader (abfd)->e_flags & EF_PPC64_ABI;
-}
-
-static inline void
-set_abiversion (bfd *abfd, int ver)
-{
- elf_elfheader (abfd)->e_flags &= ~EF_PPC64_ABI;
- elf_elfheader (abfd)->e_flags |= ver & EF_PPC64_ABI;
-}
\f
/* Parameters for the qsort hook. */
static bfd_boolean synthetic_relocatable;
ppc_stub_plt_branch,
ppc_stub_plt_branch_r2off,
ppc_stub_plt_call,
- ppc_stub_plt_call_r2save
+ ppc_stub_plt_call_r2save,
+ ppc_stub_global_entry
};
struct ppc_stub_hash_entry {
/* Hash table for function prologue tocsave. */
htab_t tocsave_htab;
- /* Linker stub bfd. */
- bfd *stub_bfd;
-
- /* Linker call-backs. */
- asection * (*add_stub_section) (const char *, asection *);
- void (*layout_sections_again) (void);
+ /* Various options and other info passed from the linker. */
+ struct ppc64_elf_params *params;
/* Array to keep track of which stub sections have been created, and
information on stub grouping. */
bfd_size_type got_reli_size;
/* Statistics. */
- unsigned long stub_count[ppc_stub_plt_call_r2save];
+ unsigned long stub_count[ppc_stub_global_entry];
/* Number of stubs against global syms. */
unsigned long stub_globals;
- /* Alignment of PLT call stubs. */
- unsigned int plt_stub_align:4;
-
/* Set if we're linking code with function descriptors. */
unsigned int opd_abi:1;
- /* Set if PLT call stubs should load r11. */
- unsigned int plt_static_chain:1;
-
- /* Set if PLT call stubs need a read-read barrier. */
- unsigned int plt_thread_safe:1;
-
- /* Set if we should emit symbols for stubs. */
- unsigned int emit_stub_syms:1;
-
- /* Set if __tls_get_addr optimization should not be done. */
- unsigned int no_tls_get_addr_opt:1;
-
/* Support for multiple toc sections. */
unsigned int do_multi_toc:1;
unsigned int multi_toc_needed:1;
/* Set on error. */
unsigned int stub_error:1;
- /* Temp used by ppc64_elf_process_dot_syms. */
+ /* Temp used by ppc64_elf_before_check_relocs. */
unsigned int twiddled_syms:1;
/* Incremented every time we size stubs. */
return e1->sec == e2->sec && e1->offset == e2->offset;
}
+/* Destroy a ppc64 ELF linker hash table. */
+
+static void
+ppc64_elf_link_hash_table_free (bfd *obfd)
+{
+ struct ppc_link_hash_table *htab;
+
+ htab = (struct ppc_link_hash_table *) obfd->link.hash;
+ if (htab->tocsave_htab)
+ htab_delete (htab->tocsave_htab);
+ bfd_hash_table_free (&htab->branch_hash_table);
+ bfd_hash_table_free (&htab->stub_hash_table);
+ _bfd_elf_link_hash_table_free (obfd);
+}
+
/* Create a ppc64 ELF linker hash table. */
static struct bfd_link_hash_table *
/* Init the stub hash table too. */
if (!bfd_hash_table_init (&htab->stub_hash_table, stub_hash_newfunc,
sizeof (struct ppc_stub_hash_entry)))
- return NULL;
+ {
+ _bfd_elf_link_hash_table_free (abfd);
+ return NULL;
+ }
/* And the branch hash table. */
if (!bfd_hash_table_init (&htab->branch_hash_table, branch_hash_newfunc,
sizeof (struct ppc_branch_hash_entry)))
- return NULL;
+ {
+ bfd_hash_table_free (&htab->stub_hash_table);
+ _bfd_elf_link_hash_table_free (abfd);
+ return NULL;
+ }
htab->tocsave_htab = htab_try_create (1024,
tocsave_htab_hash,
tocsave_htab_eq,
NULL);
if (htab->tocsave_htab == NULL)
- return NULL;
+ {
+ ppc64_elf_link_hash_table_free (abfd);
+ return NULL;
+ }
+ htab->elf.root.hash_table_free = ppc64_elf_link_hash_table_free;
/* Initializing two fields of the union is just cosmetic. We really
only care about glist, but when compiled on a 32-bit host the
return &htab->elf.root;
}
-/* Free the derived linker hash table. */
-
-static void
-ppc64_elf_link_hash_table_free (struct bfd_link_hash_table *hash)
-{
- struct ppc_link_hash_table *htab = (struct ppc_link_hash_table *) hash;
-
- bfd_hash_table_free (&htab->stub_hash_table);
- bfd_hash_table_free (&htab->branch_hash_table);
- if (htab->tocsave_htab)
- htab_delete (htab->tocsave_htab);
- _bfd_elf_link_hash_table_free (hash);
-}
-
/* Create sections for linker generated code. */
static bfd_boolean
/* Satisfy the ELF linker by filling in some fields in our fake bfd. */
bfd_boolean
-ppc64_elf_init_stub_bfd (bfd *abfd, struct bfd_link_info *info)
+ppc64_elf_init_stub_bfd (struct bfd_link_info *info,
+ struct ppc64_elf_params *params)
{
struct ppc_link_hash_table *htab;
- elf_elfheader (abfd)->e_ident[EI_CLASS] = ELFCLASS64;
+ elf_elfheader (params->stub_bfd)->e_ident[EI_CLASS] = ELFCLASS64;
/* Always hook our dynamic sections into the first bfd, which is the
linker created stub bfd. This ensures that the GOT header is at
htab = ppc_hash_table (info);
if (htab == NULL)
return FALSE;
- htab->stub_bfd = abfd;
- htab->elf.dynobj = abfd;
+ htab->elf.dynobj = params->stub_bfd;
+ htab->params = params;
if (info->relocatable)
return TRUE;
namelen = strlen (link_sec->name);
len = namelen + sizeof (STUB_SUFFIX);
- s_name = bfd_alloc (htab->stub_bfd, len);
+ s_name = bfd_alloc (htab->params->stub_bfd, len);
if (s_name == NULL)
return NULL;
memcpy (s_name, link_sec->name, namelen);
memcpy (s_name + namelen, STUB_SUFFIX, sizeof (STUB_SUFFIX));
- stub_sec = (*htab->add_stub_section) (s_name, link_sec);
+ stub_sec = (*htab->params->add_stub_section) (s_name, link_sec);
if (stub_sec == NULL)
return NULL;
htab->stub_group[link_sec->id].stub_sec = stub_sec;
const char **name,
flagword *flags ATTRIBUTE_UNUSED,
asection **sec,
- bfd_vma *value ATTRIBUTE_UNUSED)
+ bfd_vma *value)
{
- if ((ibfd->flags & DYNAMIC) == 0
- && ELF_ST_BIND (isym->st_info) == STB_GNU_UNIQUE)
+ if ((ELF_ST_TYPE (isym->st_info) == STT_GNU_IFUNC
+ || ELF_ST_BIND (isym->st_info) == STB_GNU_UNIQUE)
+ && (ibfd->flags & DYNAMIC) == 0
+ && bfd_get_flavour (info->output_bfd) == bfd_target_elf_flavour)
elf_tdata (info->output_bfd)->has_gnu_symbols = TRUE;
- if (ELF_ST_TYPE (isym->st_info) == STT_GNU_IFUNC)
+ if (*sec != NULL
+ && strcmp ((*sec)->name, ".opd") == 0)
{
- if ((ibfd->flags & DYNAMIC) == 0)
- elf_tdata (info->output_bfd)->has_gnu_symbols = TRUE;
+ asection *code_sec;
+
+ if (!(ELF_ST_TYPE (isym->st_info) == STT_GNU_IFUNC
+ || ELF_ST_TYPE (isym->st_info) == STT_FUNC))
+ isym->st_info = ELF_ST_INFO (ELF_ST_BIND (isym->st_info), STT_FUNC);
+
+ /* If the symbol is a function defined in .opd, and the function
+ code is in a discarded group, let it appear to be undefined. */
+ if (!info->relocatable
+ && (*sec)->reloc_count != 0
+ && opd_entry_value (*sec, *value, &code_sec, NULL,
+ FALSE) != (bfd_vma) -1
+ && discarded_section (code_sec))
+ {
+ *sec = bfd_und_section_ptr;
+ isym->st_shndx = SHN_UNDEF;
+ }
}
- else if (ELF_ST_TYPE (isym->st_info) == STT_FUNC)
- ;
- else if (*sec != NULL
- && strcmp ((*sec)->name, ".opd") == 0)
- isym->st_info = ELF_ST_INFO (ELF_ST_BIND (isym->st_info), STT_FUNC);
if ((STO_PPC64_LOCAL_MASK & isym->st_other) != 0)
{
return TRUE;
}
-/* Process list of dot-symbols we made in link_hash_newfunc. */
+/* Set up opd section info and abiversion for IBFD, and process list
+ of dot-symbols we made in link_hash_newfunc. */
static bfd_boolean
-ppc64_elf_process_dot_syms (bfd *ibfd, struct bfd_link_info *info)
+ppc64_elf_before_check_relocs (bfd *ibfd, struct bfd_link_info *info)
{
struct ppc_link_hash_table *htab;
struct ppc_link_hash_entry **p, *eh;
+ asection *opd = bfd_get_section_by_name (ibfd, ".opd");
+
+ if (opd != NULL && opd->size != 0)
+ {
+ if (abiversion (ibfd) == 0)
+ set_abiversion (ibfd, 1);
+ else if (abiversion (ibfd) == 2)
+ {
+ info->callbacks->einfo (_("%P: %B .opd not allowed in ABI"
+ " version %d\n"),
+ ibfd, abiversion (ibfd));
+ bfd_set_error (bfd_error_bad_value);
+ return FALSE;
+ }
+
+ if ((ibfd->flags & DYNAMIC) == 0
+ && (opd->flags & SEC_RELOC) != 0
+ && opd->reloc_count != 0
+ && !bfd_is_abs_section (opd->output_section))
+ {
+ /* Garbage collection needs some extra help with .opd sections.
+ We don't want to necessarily keep everything referenced by
+ relocs in .opd, as that would keep all functions. Instead,
+ if we reference an .opd symbol (a function descriptor), we
+ want to keep the function code symbol's section. This is
+ easy for global symbols, but for local syms we need to keep
+ information about the associated function section. */
+ bfd_size_type amt;
+ asection **opd_sym_map;
+
+ amt = opd->size * sizeof (*opd_sym_map) / 8;
+ opd_sym_map = bfd_zalloc (ibfd, amt);
+ if (opd_sym_map == NULL)
+ return FALSE;
+ ppc64_elf_section_data (opd)->u.opd.func_sec = opd_sym_map;
+ BFD_ASSERT (ppc64_elf_section_data (opd)->sec_type == sec_normal);
+ ppc64_elf_section_data (opd)->sec_type = sec_opd;
+ }
+ }
if (!is_ppc64_elf (info->output_bfd))
return TRUE;
if (htab == NULL)
return FALSE;
- if (is_ppc64_elf (ibfd))
+ /* For input files without an explicit abiversion in e_flags
+ we should have flagged any with symbol st_other bits set
+ as ELFv1 and above flagged those with .opd as ELFv2.
+ Set the output abiversion if not yet set, and for any input
+ still ambiguous, take its abiversion from the output.
+ Differences in ABI are reported later. */
+ if (abiversion (info->output_bfd) == 0)
+ set_abiversion (info->output_bfd, abiversion (ibfd));
+ else if (abiversion (ibfd) == 0)
+ set_abiversion (ibfd, abiversion (info->output_bfd));
+
+ p = &htab->dot_syms;
+ while ((eh = *p) != NULL)
{
- p = &htab->dot_syms;
- while ((eh = *p) != NULL)
- {
- *p = NULL;
- if (&eh->elf == htab->elf.hgot)
- ;
- else if (htab->elf.hgot == NULL
- && strcmp (eh->elf.root.root.string, ".TOC.") == 0)
- htab->elf.hgot = &eh->elf;
- else if (!add_symbol_adjust (eh, info))
- return FALSE;
- p = &eh->u.next_dot_sym;
- }
+ *p = NULL;
+ if (&eh->elf == htab->elf.hgot)
+ ;
+ else if (htab->elf.hgot == NULL
+ && strcmp (eh->elf.root.root.string, ".TOC.") == 0)
+ htab->elf.hgot = &eh->elf;
+ else if (!add_symbol_adjust (eh, info))
+ return FALSE;
+ p = &eh->u.next_dot_sym;
}
/* Clear the list for non-ppc64 input files. */
&& (sec->owner->flags & (EXEC_P | DYNAMIC)) != 0
&& is_ppc64_elf (sec->owner))
{
- asection *got = bfd_get_section_by_name (sec->owner, ".got");
- if (got != NULL
- && got->size >= elf_backend_got_header_size
- && bfd_get_section_by_name (sec->owner, ".opd") != NULL)
+ if (abiversion (sec->owner) >= 2
+ || bfd_get_section_by_name (sec->owner, ".opd") != NULL)
sec->has_toc_reloc = 1;
}
_bfd_elf_link_just_syms (sec, info);
sym_hashes = elf_sym_hashes (abfd);
sreloc = NULL;
opd_sym_map = NULL;
- if (strcmp (sec->name, ".opd") == 0)
- {
- /* Garbage collection needs some extra help with .opd sections.
- We don't want to necessarily keep everything referenced by
- relocs in .opd, as that would keep all functions. Instead,
- if we reference an .opd symbol (a function descriptor), we
- want to keep the function code symbol's section. This is
- easy for global symbols, but for local syms we need to keep
- information about the associated function section. */
- bfd_size_type amt;
-
- if (abiversion (abfd) == 0)
- set_abiversion (abfd, 1);
- else if (abiversion (abfd) == 2)
- {
- info->callbacks->einfo (_("%P: .opd not allowed in ABI version %d\n"),
- abiversion (abfd));
- bfd_set_error (bfd_error_bad_value);
- return FALSE;
- }
- amt = sec->size * sizeof (*opd_sym_map) / 8;
- opd_sym_map = bfd_zalloc (abfd, amt);
- if (opd_sym_map == NULL)
- return FALSE;
- ppc64_elf_section_data (sec)->u.opd.func_sec = opd_sym_map;
- BFD_ASSERT (ppc64_elf_section_data (sec)->sec_type == sec_normal);
- ppc64_elf_section_data (sec)->sec_type = sec_opd;
- }
+ if (ppc64_elf_section_data (sec) != NULL
+ && ppc64_elf_section_data (sec)->sec_type == sec_opd)
+ opd_sym_map = ppc64_elf_section_data (sec)->u.opd.func_sec;
rel_end = relocs + sec->reloc_count;
for (rel = relocs; rel < rel_end; rel++)
case R_PPC64_GOT_TPREL16_LO_DS:
case R_PPC64_GOT_TPREL16_HI:
case R_PPC64_GOT_TPREL16_HA:
- if (!info->executable)
+ if (info->shared)
info->flags |= DF_STATIC_TLS;
tls_type = TLS_TLS | TLS_TPREL;
goto dogottls;
/* We may also need a plt entry if the symbol turns out to be
an ifunc. */
- if (h != NULL && !info->shared && abiversion (abfd) == 2)
+ if (h != NULL && !info->shared && abiversion (abfd) != 1)
{
if (!update_plt_info (abfd, &h->plt.plist, rel->r_addend))
return FALSE;
case R_PPC64_REL16_HA:
break;
+ /* Not supported as a dynamic relocation. */
+ case R_PPC64_ADDR64_LOCAL:
+ if (info->shared)
+ {
+ if (!ppc64_elf_howto_table[R_PPC64_ADDR32])
+ ppc_howto_init ();
+ info->callbacks->einfo (_("%P: %H: %s reloc unsupported "
+ "in shared libraries and PIEs.\n"),
+ abfd, sec, rel->r_offset,
+ ppc64_elf_howto_table[r_type]->name);
+ bfd_set_error (bfd_error_bad_value);
+ return FALSE;
+ }
+ break;
+
case R_PPC64_TOC16:
case R_PPC64_TOC16_DS:
htab->do_multi_toc = 1;
case R_PPC64_TPREL64:
tls_type = TLS_EXPLICIT | TLS_TLS | TLS_TPREL;
- if (!info->executable)
+ if (info->shared)
info->flags |= DF_STATIC_TLS;
goto dotlstoc;
case R_PPC64_TPREL16_HIGHESTA:
if (info->shared)
{
- if (!info->executable)
- info->flags |= DF_STATIC_TLS;
+ info->flags |= DF_STATIC_TLS;
goto dodyn;
}
break;
case R_PPC64_ADDR16_HIGHESTA:
case R_PPC64_ADDR16_LO:
case R_PPC64_ADDR16_LO_DS:
- if (h != NULL && !info->shared && abiversion (abfd) == 2
+ if (h != NULL && !info->shared && abiversion (abfd) != 1
&& rel->r_addend == 0)
{
/* We may need a .plt entry if this reloc refers to a
iflags = elf_elfheader (ibfd)->e_flags;
oflags = elf_elfheader (obfd)->e_flags;
- if (!elf_flags_init (obfd) || oflags == 0)
- {
- elf_flags_init (obfd) = TRUE;
- elf_elfheader (obfd)->e_flags = iflags;
- }
- else if (iflags == oflags || iflags == 0)
- ;
- else if (iflags & ~EF_PPC64_ABI)
+ if (iflags & ~EF_PPC64_ABI)
{
(*_bfd_error_handler)
(_("%B uses unknown e_flags 0x%lx"), ibfd, iflags);
bfd_set_error (bfd_error_bad_value);
return FALSE;
}
- else
+ else if (iflags != oflags && iflags != 0)
{
(*_bfd_error_handler)
(_("%B: ABI version %ld is not compatible with ABI version %ld output"),
}
/* OFFSET in OPD_SEC specifies a function descriptor. Return the address
- of the code entry point, and its section. */
+ of the code entry point, and its section, which must be in the same
+ object as OPD_SEC. Returns (bfd_vma) -1 on error. */
static bfd_vma
opd_entry_value (asection *opd_sec,
&& ELF64_R_TYPE ((look + 1)->r_info) == R_PPC64_TOC)
{
unsigned long symndx = ELF64_R_SYM (look->r_info);
- asection *sec;
+ asection *sec = NULL;
- if (symndx < symtab_hdr->sh_info
- || elf_sym_hashes (opd_bfd) == NULL)
- {
- Elf_Internal_Sym *sym;
-
- sym = (Elf_Internal_Sym *) symtab_hdr->contents;
- if (sym == NULL)
- {
- size_t symcnt = symtab_hdr->sh_info;
- if (elf_sym_hashes (opd_bfd) == NULL)
- symcnt = symtab_hdr->sh_size / symtab_hdr->sh_entsize;
- sym = bfd_elf_get_elf_syms (opd_bfd, symtab_hdr, symcnt,
- 0, NULL, NULL, NULL);
- if (sym == NULL)
- break;
- symtab_hdr->contents = (bfd_byte *) sym;
- }
-
- sym += symndx;
- val = sym->st_value;
- sec = bfd_section_from_elf_index (opd_bfd, sym->st_shndx);
- BFD_ASSERT ((sec->flags & SEC_MERGE) == 0);
- }
- else
+ if (symndx >= symtab_hdr->sh_info
+ && elf_sym_hashes (opd_bfd) != NULL)
{
struct elf_link_hash_entry **sym_hashes;
struct elf_link_hash_entry *rh;
|| rh->root.type == bfd_link_hash_defweak);
val = rh->root.u.def.value;
sec = rh->root.u.def.section;
+ if (sec->owner != opd_bfd)
+ {
+ sec = NULL;
+ val = (bfd_vma) -1;
+ }
+ }
+ }
+
+ if (sec == NULL)
+ {
+ Elf_Internal_Sym *sym;
+
+ if (symndx < symtab_hdr->sh_info)
+ {
+ sym = (Elf_Internal_Sym *) symtab_hdr->contents;
+ if (sym == NULL)
+ {
+ size_t symcnt = symtab_hdr->sh_info;
+ sym = bfd_elf_get_elf_syms (opd_bfd, symtab_hdr,
+ symcnt, 0,
+ NULL, NULL, NULL);
+ if (sym == NULL)
+ break;
+ symtab_hdr->contents = (bfd_byte *) sym;
+ }
+ sym += symndx;
}
else
{
- /* Handle the odd case where we can be called
- during bfd_elf_link_add_symbols before the
- symbol hashes have been fully populated. */
- Elf_Internal_Sym *sym;
-
- sym = bfd_elf_get_elf_syms (opd_bfd, symtab_hdr, 1,
- symndx, NULL, NULL, NULL);
+ sym = bfd_elf_get_elf_syms (opd_bfd, symtab_hdr,
+ 1, symndx,
+ NULL, NULL, NULL);
if (sym == NULL)
break;
-
- val = sym->st_value;
- sec = bfd_section_from_elf_index (opd_bfd, sym->st_shndx);
- free (sym);
}
+ sec = bfd_section_from_elf_index (opd_bfd, sym->st_shndx);
+ if (sec == NULL)
+ break;
+ BFD_ASSERT ((sec->flags & SEC_MERGE) == 0);
+ val = sym->st_value;
}
+
val += look->r_addend;
if (code_off != NULL)
*code_off = val;
else
*code_sec = sec;
}
- if (sec != NULL && sec->output_section != NULL)
+ if (sec->output_section != NULL)
val += sec->output_section->vma + sec->output_offset;
}
break;
struct bfd_link_info *info = (struct bfd_link_info *) inf;
struct ppc_link_hash_entry *eh = (struct ppc_link_hash_entry *) h;
struct ppc_link_hash_entry *fdh;
+ struct bfd_elf_dynamic_list *d = info->dynamic_list;
/* Dynamic linking info is on the func descriptor sym. */
fdh = defined_func_desc (eh);
if ((eh->elf.root.type == bfd_link_hash_defined
|| eh->elf.root.type == bfd_link_hash_defweak)
&& (eh->elf.ref_dynamic
- || (!info->executable
- && eh->elf.def_regular
+ || (eh->elf.def_regular
&& ELF_ST_VISIBILITY (eh->elf.other) != STV_INTERNAL
&& ELF_ST_VISIBILITY (eh->elf.other) != STV_HIDDEN
+ && (!info->executable
+ || info->export_dynamic
+ || (eh->elf.dynamic
+ && d != NULL
+ && (*d->match) (&d->head, NULL, eh->elf.root.root.string)))
&& (strchr (eh->elf.root.root.string, ELF_VER_CHR) != NULL
|| !bfd_hide_sym_by_version (info->version_info,
eh->elf.root.root.string)))))
if (!info->relocatable
&& htab->elf.hgot != NULL)
- _bfd_elf_link_hash_hide_symbol (info, htab->elf.hgot, TRUE);
+ {
+ _bfd_elf_link_hash_hide_symbol (info, htab->elf.hgot, TRUE);
+ /* Make .TOC. defined so as to prevent it being made dynamic.
+ The wrong value here is fixed later in ppc64_elf_set_toc. */
+ htab->elf.hgot->type = STT_OBJECT;
+ htab->elf.hgot->root.type = bfd_link_hash_defined;
+ htab->elf.hgot->root.u.def.value = 0;
+ htab->elf.hgot->root.u.def.section = bfd_abs_section_ptr;
+ htab->elf.hgot->def_regular = 1;
+ htab->elf.hgot->other = ((htab->elf.hgot->other & ~ELF_ST_VISIBILITY (-1))
+ | STV_HIDDEN);
+ }
if (htab->sfpr == NULL)
/* We don't have any relocs. */
/* Provide any missing _save* and _rest* functions. */
htab->sfpr->size = 0;
- if (!info->relocatable)
+ if (htab->params->save_restore_funcs)
for (i = 0; i < sizeof (funcs) / sizeof (funcs[0]); i++)
if (!sfpr_define (info, &funcs[i]))
return FALSE;
{
h->plt.plist = NULL;
h->needs_plt = 0;
+ h->pointer_equality_needed = 0;
}
else if (abiversion (info->output_bfd) == 2)
{
+ /* Taking a function's address in a read/write section
+ doesn't require us to define the function symbol in the
+ executable on a global entry stub. A dynamic reloc can
+ be used instead. */
+ if (h->pointer_equality_needed
+ && h->type != STT_GNU_IFUNC
+ && !readonly_dynrelocs (h))
+ {
+ h->pointer_equality_needed = 0;
+ h->non_got_ref = 0;
+ }
+
/* After adjust_dynamic_symbol, non_got_ref set in the
non-shared case means that we have allocated space in
.dynbss for the symbol and thus dyn_relocs for this
relocations against this symbol to the PLT entry. Allow
dynamic relocs if the reference is weak, and the dynamic
relocs will not cause text relocation. */
- if (!h->ref_regular_nonweak
- && h->non_got_ref
- && h->type != STT_GNU_IFUNC
- && !readonly_dynrelocs (h))
+ else if (!h->ref_regular_nonweak
+ && h->non_got_ref
+ && h->type != STT_GNU_IFUNC
+ && !readonly_dynrelocs (h))
h->non_got_ref = 0;
/* If making a plt entry, then we don't need copy relocs. */
applications. */
bfd_boolean
-ppc64_elf_edit_opd (struct bfd_link_info *info, bfd_boolean non_overlapping)
+ppc64_elf_edit_opd (struct bfd_link_info *info)
{
bfd *ibfd;
bfd_boolean some_edited = FALSE;
asection *need_pad = NULL;
+ struct ppc_link_hash_table *htab;
+
+ htab = ppc_hash_table (info);
+ if (htab == NULL)
+ return FALSE;
- for (ibfd = info->input_bfds; ibfd != NULL; ibfd = ibfd->link_next)
+ for (ibfd = info->input_bfds; ibfd != NULL; ibfd = ibfd->link.next)
{
asection *sec;
Elf_Internal_Rela *relstart, *rel, *relend;
goto broken_opd;
}
- add_aux_fields = non_overlapping && cnt_16b > 0;
+ add_aux_fields = htab->params->non_overlapping_opd && cnt_16b > 0;
if (need_edit || add_aux_fields)
{
if (h != NULL
&& h->root.root.string[0] == '.')
{
- struct ppc_link_hash_table *htab;
-
- htab = ppc_hash_table (info);
- if (htab != NULL)
- fdh = lookup_fdh ((struct ppc_link_hash_entry *) h,
- htab);
+ fdh = lookup_fdh ((struct ppc_link_hash_entry *) h, htab);
if (fdh != NULL
&& fdh->elf.root.type != bfd_link_hash_defined
&& fdh->elf.root.type != bfd_link_hash_defweak)
/* Set htab->tls_get_addr and call the generic ELF tls_setup function. */
asection *
-ppc64_elf_tls_setup (struct bfd_link_info *info,
- int no_tls_get_addr_opt,
- int *no_multi_toc)
+ppc64_elf_tls_setup (struct bfd_link_info *info)
{
struct ppc_link_hash_table *htab;
if (abiversion (info->output_bfd) == 1)
htab->opd_abi = 1;
- if (*no_multi_toc)
+ if (htab->params->no_multi_toc)
htab->do_multi_toc = 0;
else if (!htab->do_multi_toc)
- *no_multi_toc = 1;
+ htab->params->no_multi_toc = 1;
htab->tls_get_addr = ((struct ppc_link_hash_entry *)
elf_link_hash_lookup (&htab->elf, ".__tls_get_addr",
htab->tls_get_addr_fd = ((struct ppc_link_hash_entry *)
elf_link_hash_lookup (&htab->elf, "__tls_get_addr",
FALSE, FALSE, TRUE));
- if (!no_tls_get_addr_opt)
+ if (!htab->params->no_tls_get_addr_opt)
{
struct elf_link_hash_entry *opt, *opt_fd, *tga, *tga_fd;
}
}
else
- no_tls_get_addr_opt = TRUE;
+ htab->params->no_tls_get_addr_opt = TRUE;
}
- htab->no_tls_get_addr_opt = no_tls_get_addr_opt;
return _bfd_elf_tls_setup (info->output_bfd, info);
}
and plt refcounts. */
toc_ref = NULL;
for (pass = 0; pass < 2; ++pass)
- for (ibfd = info->input_bfds; ibfd != NULL; ibfd = ibfd->link_next)
+ for (ibfd = info->input_bfds; ibfd != NULL; ibfd = ibfd->link.next)
{
Elf_Internal_Sym *locsyms = NULL;
asection *toc = bfd_get_section_by_name (ibfd, ".toc");
relstart = _bfd_elf_link_read_relocs (ibfd, sec, NULL, NULL,
info->keep_memory);
if (relstart == NULL)
- return FALSE;
+ {
+ free (toc_ref);
+ return FALSE;
+ }
relend = relstart + sec->reloc_count;
for (rel = relstart; rel < relend; rel++)
else
value = sym->st_value;
value += rel->r_addend;
- BFD_ASSERT (value < toc->size && value % 8 == 0);
+ if (value % 8 != 0)
+ continue;
+ BFD_ASSERT (value < toc->size
+ && toc->output_offset % 8 == 0);
toc_ref_index = (value + toc->output_offset) / 8;
if (r_type == R_PPC64_TLS
|| r_type == R_PPC64_TLSGD
htab->do_toc_opt = 1;
toc_inf.global_toc_syms = TRUE;
- for (ibfd = info->input_bfds; ibfd != NULL; ibfd = ibfd->link_next)
+ for (ibfd = info->input_bfds; ibfd != NULL; ibfd = ibfd->link.next)
{
asection *toc, *sec;
Elf_Internal_Shdr *symtab_hdr;
|| discarded_section (sym_sec))
continue;
- if (!SYMBOL_CALLS_LOCAL (info, h))
+ if (!SYMBOL_REFERENCES_LOCAL (info, h))
continue;
if (h != NULL)
relstart = _bfd_elf_link_read_relocs (ibfd, sec, NULL, NULL,
info->keep_memory);
if (relstart == NULL)
- goto error_ret;
+ {
+ free (used);
+ goto error_ret;
+ }
/* Mark toc entries referenced as used. */
do
if (eh->dyn_relocs == NULL
|| (!htab->elf.dynamic_sections_created
- && (h->type != STT_GNU_IFUNC
- || !htab->opd_abi)))
+ && h->type != STT_GNU_IFUNC))
return TRUE;
/* In the shared -Bsymbolic case, discard space allocated for
if (pent->plt.offset != (bfd_vma) -1
&& pent->addend == 0)
{
+ /* For ELFv2, if this symbol is not defined in a regular file
+ and we are not generating a shared library or pie, then we
+ need to define the symbol in the executable on a call stub.
+ This is to avoid text relocations. */
s->size = (s->size + 15) & -16;
+ h->root.u.def.section = s;
+ h->root.u.def.value = s->size;
s->size += 16;
break;
}
/* Set up .got offsets for local syms, and space for local dynamic
relocs. */
- for (ibfd = info->input_bfds; ibfd != NULL; ibfd = ibfd->link_next)
+ for (ibfd = info->input_bfds; ibfd != NULL; ibfd = ibfd->link.next)
{
struct got_entry **lgot_ents;
struct got_entry **end_lgot_ents;
elf_link_hash_traverse (&htab->elf, size_global_entry_stubs, info);
first_tlsld = NULL;
- for (ibfd = info->input_bfds; ibfd != NULL; ibfd = ibfd->link_next)
+ for (ibfd = info->input_bfds; ibfd != NULL; ibfd = ibfd->link.next)
{
struct got_entry *ent;
return FALSE;
}
- for (ibfd = info->input_bfds; ibfd != NULL; ibfd = ibfd->link_next)
+ for (ibfd = info->input_bfds; ibfd != NULL; ibfd = ibfd->link.next)
{
if (!is_ppc64_elf (ibfd))
continue;
return FALSE;
}
- tls_opt = (!htab->no_tls_get_addr_opt
+ tls_opt = (!htab->params->no_tls_get_addr_opt
&& htab->tls_get_addr_fd != NULL
&& htab->tls_get_addr_fd->elf.plt.plist != NULL);
if (tls_opt || !htab->opd_abi)
if (htab->opd_abi)
{
size += 4;
- if (htab->plt_static_chain)
+ if (htab->params->plt_static_chain)
size += 4;
- if (htab->plt_thread_safe)
+ if (htab->params->plt_thread_safe)
size += 8;
- if (PPC_HA (off + 8 + 8 * htab->plt_static_chain) != PPC_HA (off))
+ if (PPC_HA (off + 8 + 8 * htab->params->plt_static_chain) != PPC_HA (off))
size += 4;
}
if (stub_entry->h != NULL
&& (stub_entry->h == htab->tls_get_addr_fd
|| stub_entry->h == htab->tls_get_addr)
- && !htab->no_tls_get_addr_opt)
+ && !htab->params->no_tls_get_addr_opt)
size += 13 * 4;
return size;
}
struct ppc_stub_hash_entry *stub_entry,
bfd_vma plt_off)
{
- int stub_align = 1 << htab->plt_stub_align;
+ int stub_align = 1 << htab->params->plt_stub_align;
unsigned stub_size = plt_stub_size (htab, stub_entry, plt_off);
bfd_vma stub_off = stub_entry->stub_sec->size;
if (((stub_off + stub_size - 1) & -stub_align) - (stub_off & -stub_align)
- > (stub_size & -stub_align))
+ > ((stub_size - 1) & -stub_align))
return stub_align - (stub_off & (stub_align - 1));
return 0;
}
struct ppc_stub_hash_entry *stub_entry,
bfd_byte *p, bfd_vma offset, Elf_Internal_Rela *r)
{
- bfd *obfd = htab->stub_bfd;
+ bfd *obfd = htab->params->stub_bfd;
bfd_boolean plt_load_toc = htab->opd_abi;
- bfd_boolean plt_static_chain = htab->plt_static_chain;
- bfd_boolean plt_thread_safe = htab->plt_thread_safe;
+ bfd_boolean plt_static_chain = htab->params->plt_static_chain;
+ bfd_boolean plt_thread_safe = htab->params->plt_thread_safe;
bfd_boolean use_fake_dep = plt_thread_safe;
bfd_vma cmp_branch_off = 0;
&& !(stub_entry->h != NULL
&& (stub_entry->h == htab->tls_get_addr_fd
|| stub_entry->h == htab->tls_get_addr)
- && !htab->no_tls_get_addr_opt))
+ && !htab->params->no_tls_get_addr_opt))
{
bfd_vma pltoff = stub_entry->plt_ent->plt.offset & ~1;
bfd_vma pltindex = ((pltoff - PLT_INITIAL_ENTRY_SIZE (htab))
if (ALWAYS_EMIT_R2SAVE
|| stub_entry->stub_type == ppc_stub_plt_call_r2save)
bfd_put_32 (obfd, STD_R2_0R1 + STK_TOC (htab), p), p += 4;
- bfd_put_32 (obfd, ADDIS_R11_R2 | PPC_HA (offset), p), p += 4;
- bfd_put_32 (obfd, LD_R12_0R11 | PPC_LO (offset), p), p += 4;
+ if (plt_load_toc)
+ {
+ bfd_put_32 (obfd, ADDIS_R11_R2 | PPC_HA (offset), p), p += 4;
+ bfd_put_32 (obfd, LD_R12_0R11 | PPC_LO (offset), p), p += 4;
+ }
+ else
+ {
+ bfd_put_32 (obfd, ADDIS_R12_R2 | PPC_HA (offset), p), p += 4;
+ bfd_put_32 (obfd, LD_R12_0R12 | PPC_LO (offset), p), p += 4;
+ }
if (plt_load_toc
&& PPC_HA (offset + 8 + 8 * plt_static_chain) != PPC_HA (offset))
{
struct ppc_stub_hash_entry *stub_entry,
bfd_byte *p, bfd_vma offset, Elf_Internal_Rela *r)
{
- bfd *obfd = htab->stub_bfd;
+ bfd *obfd = htab->params->stub_bfd;
bfd_put_32 (obfd, LD_R11_0R3 + 0, p), p += 4;
bfd_put_32 (obfd, LD_R12_0R3 + 8, p), p += 4;
htab->stub_error = TRUE;
return FALSE;
}
- bfd_put_32 (htab->stub_bfd, STD_R2_0R1 + STK_TOC (htab), loc);
+ bfd_put_32 (htab->params->stub_bfd, STD_R2_0R1 + STK_TOC (htab), loc);
loc += 4;
size = 12;
if (PPC_HA (r2off) != 0)
{
size = 16;
- bfd_put_32 (htab->stub_bfd, ADDIS_R2_R2 | PPC_HA (r2off), loc);
+ bfd_put_32 (htab->params->stub_bfd,
+ ADDIS_R2_R2 | PPC_HA (r2off), loc);
loc += 4;
}
- bfd_put_32 (htab->stub_bfd, ADDI_R2_R2 | PPC_LO (r2off), loc);
+ bfd_put_32 (htab->params->stub_bfd, ADDI_R2_R2 | PPC_LO (r2off), loc);
loc += 4;
off -= size - 4;
}
- bfd_put_32 (htab->stub_bfd, B_DOT | (off & 0x3fffffc), loc);
+ bfd_put_32 (htab->params->stub_bfd, B_DOT | (off & 0x3fffffc), loc);
if (off + (1 << 25) >= (bfd_vma) (1 << 26))
{
unsigned long symndx;
struct ppc_link_hash_entry *h;
- hashes = elf_sym_hashes (htab->stub_bfd);
+ hashes = elf_sym_hashes (htab->params->stub_bfd);
if (hashes == NULL)
{
bfd_size_type hsize;
hsize = (htab->stub_globals + 1) * sizeof (*hashes);
- hashes = bfd_zalloc (htab->stub_bfd, hsize);
+ hashes = bfd_zalloc (htab->params->stub_bfd, hsize);
if (hashes == NULL)
return FALSE;
- elf_sym_hashes (htab->stub_bfd) = hashes;
+ elf_sym_hashes (htab->params->stub_bfd) = hashes;
htab->stub_globals = 1;
}
symndx = htab->stub_globals++;
r[0].r_offset = loc - stub_entry->stub_sec->contents;
if (bfd_big_endian (info->output_bfd))
r[0].r_offset += 2;
- if (stub_entry->stub_type == ppc_stub_plt_branch_r2off
- && htab->opd_abi)
+ if (stub_entry->stub_type == ppc_stub_plt_branch_r2off)
r[0].r_offset += 4;
r[0].r_info = ELF64_R_INFO (0, R_PPC64_TOC16_DS);
r[0].r_addend = dest;
}
}
- if (stub_entry->stub_type != ppc_stub_plt_branch_r2off
- || !htab->opd_abi)
+ if (stub_entry->stub_type != ppc_stub_plt_branch_r2off)
{
if (PPC_HA (off) != 0)
{
size = 16;
- bfd_put_32 (htab->stub_bfd, ADDIS_R11_R2 | PPC_HA (off), loc);
+ bfd_put_32 (htab->params->stub_bfd,
+ ADDIS_R12_R2 | PPC_HA (off), loc);
loc += 4;
- bfd_put_32 (htab->stub_bfd, LD_R12_0R11 | PPC_LO (off), loc);
+ bfd_put_32 (htab->params->stub_bfd,
+ LD_R12_0R12 | PPC_LO (off), loc);
}
else
{
size = 12;
- bfd_put_32 (htab->stub_bfd, LD_R12_0R2 | PPC_LO (off), loc);
+ bfd_put_32 (htab->params->stub_bfd,
+ LD_R12_0R2 | PPC_LO (off), loc);
}
}
else
{
bfd_vma r2off = get_r2off (info, stub_entry);
- if (r2off == 0)
+ if (r2off == 0 && htab->opd_abi)
{
htab->stub_error = TRUE;
return FALSE;
}
- bfd_put_32 (htab->stub_bfd, STD_R2_0R1 + STK_TOC (htab), loc);
+ bfd_put_32 (htab->params->stub_bfd, STD_R2_0R1 + STK_TOC (htab), loc);
loc += 4;
- size = 20;
+ size = 16;
if (PPC_HA (off) != 0)
{
size += 4;
- bfd_put_32 (htab->stub_bfd, ADDIS_R11_R2 | PPC_HA (off), loc);
- loc += 4;
- bfd_put_32 (htab->stub_bfd, LD_R12_0R11 | PPC_LO (off), loc);
+ bfd_put_32 (htab->params->stub_bfd,
+ ADDIS_R12_R2 | PPC_HA (off), loc);
loc += 4;
+ bfd_put_32 (htab->params->stub_bfd,
+ LD_R12_0R12 | PPC_LO (off), loc);
}
else
+ bfd_put_32 (htab->params->stub_bfd, LD_R12_0R2 | PPC_LO (off), loc);
+
+ if (PPC_HA (r2off) != 0)
{
- bfd_put_32 (htab->stub_bfd, LD_R12_0R2 | PPC_LO (off), loc);
+ size += 4;
loc += 4;
+ bfd_put_32 (htab->params->stub_bfd,
+ ADDIS_R2_R2 | PPC_HA (r2off), loc);
}
-
- if (PPC_HA (r2off) != 0)
+ if (PPC_LO (r2off) != 0)
{
size += 4;
- bfd_put_32 (htab->stub_bfd, ADDIS_R2_R2 | PPC_HA (r2off), loc);
loc += 4;
+ bfd_put_32 (htab->params->stub_bfd,
+ ADDI_R2_R2 | PPC_LO (r2off), loc);
}
- bfd_put_32 (htab->stub_bfd, ADDI_R2_R2 | PPC_LO (r2off), loc);
}
loc += 4;
- bfd_put_32 (htab->stub_bfd, MTCTR_R12, loc);
+ bfd_put_32 (htab->params->stub_bfd, MTCTR_R12, loc);
loc += 4;
- bfd_put_32 (htab->stub_bfd, BCTR, loc);
+ bfd_put_32 (htab->params->stub_bfd, BCTR, loc);
break;
case ppc_stub_plt_call:
return FALSE;
}
- if (htab->plt_stub_align != 0)
+ if (htab->params->plt_stub_align != 0)
{
unsigned pad = plt_stub_pad (htab, stub_entry, off);
if (info->emitrelocations)
{
r = get_relocs (stub_entry->stub_sec,
- (2
- + (PPC_HA (off) != 0)
- + (htab->plt_static_chain
- && PPC_HA (off + 16) == PPC_HA (off))));
+ ((PPC_HA (off) != 0)
+ + (htab->opd_abi
+ ? 2 + (htab->params->plt_static_chain
+ && PPC_HA (off + 16) == PPC_HA (off))
+ : 1)));
if (r == NULL)
return FALSE;
r[0].r_offset = loc - stub_entry->stub_sec->contents;
if (stub_entry->h != NULL
&& (stub_entry->h == htab->tls_get_addr_fd
|| stub_entry->h == htab->tls_get_addr)
- && !htab->no_tls_get_addr_opt)
+ && !htab->params->no_tls_get_addr_opt)
p = build_tls_get_addr_stub (htab, stub_entry, loc, off, r);
else
p = build_plt_stub (htab, stub_entry, loc, off, r);
stub_entry->stub_sec->size += size;
- if (htab->emit_stub_syms)
+ if (htab->params->emit_stub_syms)
{
struct elf_link_hash_entry *h;
size_t len1, len2;
- htab->stub_group[stub_entry->id_sec->id].toc_off);
size = plt_stub_size (htab, stub_entry, off);
- if (htab->plt_stub_align)
+ if (htab->params->plt_stub_align)
size += plt_stub_pad (htab, stub_entry, off);
if (info->emitrelocations)
{
stub_entry->stub_sec->reloc_count
+= ((PPC_HA (off) != 0)
+ (htab->opd_abi
- ? 2 + (htab->plt_static_chain
+ ? 2 + (htab->params->plt_static_chain
&& PPC_HA (off + 16) == PPC_HA (off))
: 1));
stub_entry->stub_sec->flags |= SEC_RELOC;
stub_entry->stub_sec->flags |= SEC_RELOC;
}
- if (stub_entry->stub_type != ppc_stub_plt_branch_r2off
- || !htab->opd_abi)
+ if (stub_entry->stub_type != ppc_stub_plt_branch_r2off)
{
size = 12;
if (PPC_HA (off) != 0)
}
else
{
- size = 20;
+ size = 16;
if (PPC_HA (off) != 0)
size += 4;
if (PPC_HA (r2off) != 0)
size += 4;
+ if (PPC_LO (r2off) != 0)
+ size += 4;
}
}
else if (info->emitrelocations)
0 when no stubs will be needed, and 1 on success. */
int
-ppc64_elf_setup_section_lists
- (struct bfd_link_info *info,
- asection *(*add_stub_section) (const char *, asection *),
- void (*layout_sections_again) (void))
+ppc64_elf_setup_section_lists (struct bfd_link_info *info)
{
bfd *input_bfd;
int top_id, top_index, id;
if (htab == NULL)
return -1;
- /* Stash our params away. */
- htab->add_stub_section = add_stub_section;
- htab->layout_sections_again = layout_sections_again;
/* Find the top input section id. */
for (input_bfd = info->input_bfds, top_id = 3;
input_bfd != NULL;
- input_bfd = input_bfd->link_next)
+ input_bfd = input_bfd->link.next)
{
for (section = input_bfd->sections;
section != NULL;
elf_link_hash_traverse (&htab->elf, merge_global_got, info);
/* And tlsld_got. */
- for (ibfd = info->input_bfds; ibfd != NULL; ibfd = ibfd->link_next)
+ for (ibfd = info->input_bfds; ibfd != NULL; ibfd = ibfd->link.next)
{
struct got_entry *ent, *ent2;
if (!ent->is_indirect
&& ent->got.offset != (bfd_vma) -1)
{
- for (ibfd2 = ibfd->link_next; ibfd2 != NULL; ibfd2 = ibfd2->link_next)
+ for (ibfd2 = ibfd->link.next; ibfd2 != NULL; ibfd2 = ibfd2->link.next)
{
if (!is_ppc64_elf (ibfd2))
continue;
htab->elf.irelplt->size -= htab->got_reli_size;
htab->got_reli_size = 0;
- for (ibfd = info->input_bfds; ibfd != NULL; ibfd = ibfd->link_next)
+ for (ibfd = info->input_bfds; ibfd != NULL; ibfd = ibfd->link.next)
{
asection *got, *relgot;
/* Now reallocate the got, local syms first. We don't need to
allocate section contents again since we never increase size. */
- for (ibfd = info->input_bfds; ibfd != NULL; ibfd = ibfd->link_next)
+ for (ibfd = info->input_bfds; ibfd != NULL; ibfd = ibfd->link.next)
{
struct got_entry **lgot_ents;
struct got_entry **end_lgot_ents;
elf_link_hash_traverse (&htab->elf, reallocate_got, info);
- for (ibfd = info->input_bfds; ibfd != NULL; ibfd = ibfd->link_next)
+ for (ibfd = info->input_bfds; ibfd != NULL; ibfd = ibfd->link.next)
{
struct got_entry *ent;
done_something = htab->elf.irelplt->rawsize != htab->elf.irelplt->size;
if (!done_something)
- for (ibfd = info->input_bfds; ibfd != NULL; ibfd = ibfd->link_next)
+ for (ibfd = info->input_bfds; ibfd != NULL; ibfd = ibfd->link.next)
{
asection *got;
}
if (done_something)
- (*htab->layout_sections_again) ();
+ (*htab->params->layout_sections_again) ();
/* Set up for second pass over toc sections to recalculate elf_gp
on input sections. */
bfd_boolean suppress_size_errors;
suppress_size_errors = FALSE;
- stub14_group_size = stub_group_size;
+ stub14_group_size = stub_group_size >> 10;
if (stub_group_size == 1)
{
/* Default values. */
65, /* RA reg. */
1, /* Augmentation size. */
DW_EH_PE_pcrel | DW_EH_PE_sdata4, /* FDE encoding. */
- DW_CFA_def_cfa, 1, 0 /* def_cfa: r1 offset 0. */
+ DW_CFA_def_cfa, 1, 0, /* def_cfa: r1 offset 0. */
+ 0, 0, 0, 0
};
/* Stripping output sections is normally done before dynamic section
instruction. */
bfd_boolean
-ppc64_elf_size_stubs (struct bfd_link_info *info, bfd_signed_vma group_size,
- bfd_boolean plt_static_chain, int plt_thread_safe,
- int plt_stub_align)
+ppc64_elf_size_stubs (struct bfd_link_info *info)
{
bfd_size_type stub_group_size;
bfd_boolean stubs_always_before_branch;
if (htab == NULL)
return FALSE;
- htab->plt_static_chain = plt_static_chain;
- htab->plt_stub_align = plt_stub_align;
- if (plt_thread_safe == -1 && !info->executable)
- plt_thread_safe = 1;
+ if (htab->params->plt_thread_safe == -1 && !info->executable)
+ htab->params->plt_thread_safe = 1;
if (!htab->opd_abi)
- plt_thread_safe = 0;
- else if (plt_thread_safe == -1)
+ htab->params->plt_thread_safe = 0;
+ else if (htab->params->plt_thread_safe == -1)
{
static const char *const thread_starter[] =
{
/* libanl */
"getaddrinfo_a",
/* libgomp */
+ "GOMP_parallel",
"GOMP_parallel_start",
+ "GOMP_parallel_loop_static",
"GOMP_parallel_loop_static_start",
+ "GOMP_parallel_loop_dynamic",
"GOMP_parallel_loop_dynamic_start",
+ "GOMP_parallel_loop_guided",
"GOMP_parallel_loop_guided_start",
+ "GOMP_parallel_loop_runtime",
"GOMP_parallel_loop_runtime_start",
+ "GOMP_parallel_sections",
"GOMP_parallel_sections_start",
+ /* libgo */
+ "__go_go",
};
unsigned i;
struct elf_link_hash_entry *h;
h = elf_link_hash_lookup (&htab->elf, thread_starter[i],
FALSE, FALSE, TRUE);
- plt_thread_safe = h != NULL && h->ref_regular;
- if (plt_thread_safe)
+ htab->params->plt_thread_safe = h != NULL && h->ref_regular;
+ if (htab->params->plt_thread_safe)
break;
}
}
- htab->plt_thread_safe = plt_thread_safe;
- stubs_always_before_branch = group_size < 0;
- if (group_size < 0)
- stub_group_size = -group_size;
+ stubs_always_before_branch = htab->params->group_size < 0;
+ if (htab->params->group_size < 0)
+ stub_group_size = -htab->params->group_size;
else
- stub_group_size = group_size;
+ stub_group_size = htab->params->group_size;
group_sections (htab, stub_group_size, stubs_always_before_branch);
for (input_bfd = info->input_bfds, bfd_indx = 0;
input_bfd != NULL;
- input_bfd = input_bfd->link_next, bfd_indx++)
+ input_bfd = input_bfd->link.next, bfd_indx++)
{
Elf_Internal_Shdr *symtab_hdr;
asection *section;
/* We may have added some stubs. Find out the new size of the
stub sections. */
- for (stub_sec = htab->stub_bfd->sections;
+ for (stub_sec = htab->params->stub_bfd->sections;
stub_sec != NULL;
stub_sec = stub_sec->next)
if ((stub_sec->flags & SEC_LINKER_CREATED) == 0)
{
size_t size = 0, align;
- for (stub_sec = htab->stub_bfd->sections;
+ for (stub_sec = htab->params->stub_bfd->sections;
stub_sec != NULL;
stub_sec = stub_sec->next)
if ((stub_sec->flags & SEC_LINKER_CREATED) == 0)
- size += 20;
+ size += 24;
if (htab->glink != NULL && htab->glink->size != 0)
size += 24;
if (size != 0)
htab->glink_eh_frame->size = size;
}
- if (htab->plt_stub_align != 0)
- for (stub_sec = htab->stub_bfd->sections;
+ if (htab->params->plt_stub_align != 0)
+ for (stub_sec = htab->params->stub_bfd->sections;
stub_sec != NULL;
stub_sec = stub_sec->next)
if ((stub_sec->flags & SEC_LINKER_CREATED) == 0)
- stub_sec->size = ((stub_sec->size + (1 << htab->plt_stub_align) - 1)
- & (-1 << htab->plt_stub_align));
+ stub_sec->size = ((stub_sec->size
+ + (1 << htab->params->plt_stub_align) - 1)
+ & (-1 << htab->params->plt_stub_align));
- for (stub_sec = htab->stub_bfd->sections;
+ for (stub_sec = htab->params->stub_bfd->sections;
stub_sec != NULL;
stub_sec = stub_sec->next)
if ((stub_sec->flags & SEC_LINKER_CREATED) == 0
break;
/* Ask the linker to do its stuff. */
- (*htab->layout_sections_again) ();
+ (*htab->params->layout_sections_again) ();
}
- maybe_strip_output (info, htab->brlt);
- if (htab->glink_eh_frame != NULL)
- maybe_strip_output (info, htab->glink_eh_frame);
-
- return TRUE;
-}
-
-/* Called after we have determined section placement. If sections
- move, we'll be called again. Provide a value for TOCstart. */
+ if (htab->glink_eh_frame != NULL
+ && htab->glink_eh_frame->size != 0)
+ {
+ bfd_vma val;
+ bfd_byte *p, *last_fde;
+ size_t last_fde_len, size, align, pad;
+ asection *stub_sec;
+
+ p = bfd_zalloc (htab->glink_eh_frame->owner, htab->glink_eh_frame->size);
+ if (p == NULL)
+ return FALSE;
+ htab->glink_eh_frame->contents = p;
+ last_fde = p;
+
+ memcpy (p, glink_eh_frame_cie, sizeof (glink_eh_frame_cie));
+ /* CIE length (rewrite in case little-endian). */
+ last_fde_len = sizeof (glink_eh_frame_cie) - 4;
+ bfd_put_32 (htab->elf.dynobj, last_fde_len, p);
+ p += sizeof (glink_eh_frame_cie);
+
+ for (stub_sec = htab->params->stub_bfd->sections;
+ stub_sec != NULL;
+ stub_sec = stub_sec->next)
+ if ((stub_sec->flags & SEC_LINKER_CREATED) == 0)
+ {
+ last_fde = p;
+ last_fde_len = 20;
+ /* FDE length. */
+ bfd_put_32 (htab->elf.dynobj, 20, p);
+ p += 4;
+ /* CIE pointer. */
+ val = p - htab->glink_eh_frame->contents;
+ bfd_put_32 (htab->elf.dynobj, val, p);
+ p += 4;
+ /* Offset to stub section, written later. */
+ p += 4;
+ /* stub section size. */
+ bfd_put_32 (htab->elf.dynobj, stub_sec->size, p);
+ p += 4;
+ /* Augmentation. */
+ p += 1;
+ /* Pad. */
+ p += 7;
+ }
+ if (htab->glink != NULL && htab->glink->size != 0)
+ {
+ last_fde = p;
+ last_fde_len = 20;
+ /* FDE length. */
+ bfd_put_32 (htab->elf.dynobj, 20, 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, written later. */
+ p += 4;
+ /* .glink size. */
+ bfd_put_32 (htab->elf.dynobj, htab->glink->size - 8, p);
+ p += 4;
+ /* Augmentation. */
+ p += 1;
+
+ *p++ = DW_CFA_advance_loc + 1;
+ *p++ = DW_CFA_register;
+ *p++ = 65;
+ *p++ = 12;
+ *p++ = DW_CFA_advance_loc + 4;
+ *p++ = DW_CFA_restore_extended;
+ *p++ = 65;
+ }
+ /* Subsume any padding into the last FDE if user .eh_frame
+ sections are aligned more than glink_eh_frame. Otherwise any
+ zero padding will be seen as a terminator. */
+ size = p - htab->glink_eh_frame->contents;
+ align = 1;
+ align <<= htab->glink_eh_frame->output_section->alignment_power;
+ align -= 1;
+ pad = ((size + align) & ~align) - size;
+ htab->glink_eh_frame->size = size + pad;
+ bfd_put_32 (htab->elf.dynobj, last_fde_len + pad, last_fde);
+ }
+
+ maybe_strip_output (info, htab->brlt);
+ if (htab->glink_eh_frame != NULL)
+ maybe_strip_output (info, htab->glink_eh_frame);
+
+ return TRUE;
+}
+
+/* Called after we have determined section placement. If sections
+ move, we'll be called again. Provide a value for TOCstart. */
bfd_vma
ppc64_elf_set_toc (struct bfd_link_info *info, bfd *obfd)
_bfd_set_gp_value (obfd, TOCstart);
- if (info != NULL && s != NULL && is_ppc64_elf (obfd))
+ if (info != NULL && s != NULL)
{
struct ppc_link_hash_table *htab = ppc_hash_table (info);
- if (htab != NULL
- && htab->elf.hgot != NULL)
+ if (htab != NULL)
{
- htab->elf.hgot->type = STT_OBJECT;
- htab->elf.hgot->root.type = bfd_link_hash_defined;
- htab->elf.hgot->root.u.def.value = TOC_BASE_OFF;
- htab->elf.hgot->root.u.def.section = s;
+ if (htab->elf.hgot != NULL)
+ {
+ htab->elf.hgot->root.u.def.value = TOC_BASE_OFF;
+ htab->elf.hgot->root.u.def.section = s;
+ }
+ }
+ else
+ {
+ struct bfd_link_hash_entry *bh = NULL;
+ _bfd_generic_link_add_one_symbol (info, obfd, ".TOC.", BSF_GLOBAL,
+ s, TOC_BASE_OFF, NULL, FALSE,
+ FALSE, &bh);
}
}
return TOCstart;
asection *plt;
bfd_vma off;
- /* For ELFv2, if this symbol is not defined in a regular file
- and we are not generating a shared library or pie, then we
- need to define the symbol in the executable on a call stub.
- This is to avoid text relocations. */
- h->root.u.def.section = s;
- h->root.u.def.value = s->size;
- s->size += 16;
p = s->contents + h->root.u.def.value;
plt = htab->elf.splt;
if (!htab->elf.dynamic_sections_created
htab->stub_error = TRUE;
}
+ htab->stub_count[ppc_stub_global_entry - 1] += 1;
+ if (htab->params->emit_stub_syms)
+ {
+ size_t len = strlen (h->root.root.string);
+ char *name = bfd_malloc (sizeof "12345678.global_entry." + len);
+
+ if (name == NULL)
+ return FALSE;
+
+ sprintf (name, "%08x.global_entry.%s", s->id, h->root.root.string);
+ h = elf_link_hash_lookup (&htab->elf, name, TRUE, FALSE, FALSE);
+ if (h == NULL)
+ return FALSE;
+ if (h->root.type == bfd_link_hash_new)
+ {
+ h->root.type = bfd_link_hash_defined;
+ h->root.u.def.section = s;
+ h->root.u.def.value = p - s->contents;
+ h->ref_regular = 1;
+ h->def_regular = 1;
+ h->ref_regular_nonweak = 1;
+ h->forced_local = 1;
+ h->non_elf = 0;
+ }
+ }
+
if (PPC_HA (off) != 0)
{
bfd_put_32 (s->owner, ADDIS_R12_R12 | PPC_HA (off), p);
hash table. This function is called via gldelf64ppc_finish. */
bfd_boolean
-ppc64_elf_build_stubs (bfd_boolean emit_stub_syms,
- struct bfd_link_info *info,
+ppc64_elf_build_stubs (struct bfd_link_info *info,
char **stats)
{
struct ppc_link_hash_table *htab = ppc_hash_table (info);
if (htab == NULL)
return FALSE;
- htab->emit_stub_syms = emit_stub_syms;
-
/* Allocate memory to hold the linker stubs. */
- for (stub_sec = htab->stub_bfd->sections;
+ for (stub_sec = htab->params->stub_bfd->sections;
stub_sec != NULL;
stub_sec = stub_sec->next)
if ((stub_sec->flags & SEC_LINKER_CREATED) == 0
&& stub_sec->size != 0)
{
- stub_sec->contents = bfd_zalloc (htab->stub_bfd, stub_sec->size);
+ stub_sec->contents = bfd_zalloc (htab->params->stub_bfd, stub_sec->size);
if (stub_sec->contents == NULL)
return FALSE;
/* We want to check that built size is the same as calculated
bfd_vma plt0;
/* Build the .glink plt call stub. */
- if (htab->emit_stub_syms)
+ if (htab->params->emit_stub_syms)
{
struct elf_link_hash_entry *h;
h = elf_link_hash_lookup (&htab->elf, "__glink_PLTresolve",
/* Build .glink global entry stubs. */
if (htab->glink->size > htab->glink->rawsize)
- {
- htab->glink->size = (htab->glink->rawsize + 15) & -16;
- elf_link_hash_traverse (&htab->elf, build_global_entry_stubs, info);
- }
+ elf_link_hash_traverse (&htab->elf, build_global_entry_stubs, info);
}
- if (htab->brlt->size != 0)
+ if (htab->brlt != NULL && htab->brlt->size != 0)
{
htab->brlt->contents = bfd_zalloc (htab->brlt->owner,
htab->brlt->size);
return FALSE;
}
- if (htab->glink_eh_frame != NULL
- && htab->glink_eh_frame->size != 0)
- {
- bfd_vma val;
- bfd_byte *last_fde;
- size_t last_fde_len, size, align, pad;
-
- p = bfd_zalloc (htab->glink_eh_frame->owner, htab->glink_eh_frame->size);
- if (p == NULL)
- return FALSE;
- htab->glink_eh_frame->contents = p;
- last_fde = p;
-
- htab->glink_eh_frame->rawsize = htab->glink_eh_frame->size;
-
- memcpy (p, glink_eh_frame_cie, sizeof (glink_eh_frame_cie));
- /* CIE length (rewrite in case little-endian). */
- last_fde_len = sizeof (glink_eh_frame_cie) - 4;
- bfd_put_32 (htab->elf.dynobj, last_fde_len, p);
- p += sizeof (glink_eh_frame_cie);
-
- for (stub_sec = htab->stub_bfd->sections;
- stub_sec != NULL;
- stub_sec = stub_sec->next)
- if ((stub_sec->flags & SEC_LINKER_CREATED) == 0)
- {
- last_fde = p;
- last_fde_len = 16;
- /* FDE length. */
- bfd_put_32 (htab->elf.dynobj, 16, p);
- p += 4;
- /* CIE pointer. */
- val = p - htab->glink_eh_frame->contents;
- bfd_put_32 (htab->elf.dynobj, val, p);
- p += 4;
- /* Offset to stub section. */
- val = (stub_sec->output_section->vma
- + stub_sec->output_offset);
- val -= (htab->glink_eh_frame->output_section->vma
- + htab->glink_eh_frame->output_offset);
- val -= p - htab->glink_eh_frame->contents;
- if (val + 0x80000000 > 0xffffffff)
- {
- info->callbacks->einfo
- (_("%P: %s offset too large for .eh_frame sdata4 encoding"),
- stub_sec->name);
- return FALSE;
- }
- bfd_put_32 (htab->elf.dynobj, val, p);
- p += 4;
- /* stub section size. */
- bfd_put_32 (htab->elf.dynobj, stub_sec->rawsize, p);
- p += 4;
- /* Augmentation. */
- p += 1;
- /* Pad. */
- p += 3;
- }
- if (htab->glink != NULL && htab->glink->size != 0)
- {
- last_fde = p;
- last_fde_len = 20;
- /* FDE length. */
- bfd_put_32 (htab->elf.dynobj, 20, 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->output_offset
- + 8);
- val -= (htab->glink_eh_frame->output_section->vma
- + htab->glink_eh_frame->output_offset);
- val -= p - htab->glink_eh_frame->contents;
- if (val + 0x80000000 > 0xffffffff)
- {
- info->callbacks->einfo
- (_("%P: %s offset too large for .eh_frame sdata4 encoding"),
- htab->glink->name);
- return FALSE;
- }
- bfd_put_32 (htab->elf.dynobj, val, p);
- p += 4;
- /* .glink size. */
- bfd_put_32 (htab->elf.dynobj, htab->glink->size - 8, p);
- p += 4;
- /* Augmentation. */
- p += 1;
-
- *p++ = DW_CFA_advance_loc + 1;
- *p++ = DW_CFA_register;
- *p++ = 65;
- *p++ = 12;
- *p++ = DW_CFA_advance_loc + 4;
- *p++ = DW_CFA_restore_extended;
- *p++ = 65;
- }
- /* Subsume any padding into the last FDE if user .eh_frame
- sections are aligned more than glink_eh_frame. Otherwise any
- zero padding will be seen as a terminator. */
- size = p - htab->glink_eh_frame->contents;
- align = 1;
- align <<= htab->glink_eh_frame->output_section->alignment_power;
- align -= 1;
- pad = ((size + align) & ~align) - size;
- htab->glink_eh_frame->size = size + pad;
- bfd_put_32 (htab->elf.dynobj, last_fde_len + pad, last_fde);
- }
-
/* Build the stubs as directed by the stub hash table. */
bfd_hash_traverse (&htab->stub_hash_table, ppc_build_one_stub, info);
if (htab->relbrlt != NULL)
htab->relbrlt->reloc_count = 0;
- if (htab->plt_stub_align != 0)
- for (stub_sec = htab->stub_bfd->sections;
+ if (htab->params->plt_stub_align != 0)
+ for (stub_sec = htab->params->stub_bfd->sections;
stub_sec != NULL;
stub_sec = stub_sec->next)
if ((stub_sec->flags & SEC_LINKER_CREATED) == 0)
- stub_sec->size = ((stub_sec->size + (1 << htab->plt_stub_align) - 1)
- & (-1 << htab->plt_stub_align));
+ stub_sec->size = ((stub_sec->size
+ + (1 << htab->params->plt_stub_align) - 1)
+ & (-1 << htab->params->plt_stub_align));
- for (stub_sec = htab->stub_bfd->sections;
+ for (stub_sec = htab->params->stub_bfd->sections;
stub_sec != NULL;
stub_sec = stub_sec->next)
if ((stub_sec->flags & SEC_LINKER_CREATED) == 0)
break;
}
+ /* Note that the glink_eh_frame check here is not only testing that
+ the generated size matched the calculated size but also that
+ bfd_elf_discard_info didn't make any changes to the section. */
if (stub_sec != NULL
|| (htab->glink_eh_frame != NULL
&& htab->glink_eh_frame->rawsize != htab->glink_eh_frame->size))
" long branch %lu\n"
" long toc adj %lu\n"
" plt call %lu\n"
- " plt call toc %lu"),
+ " plt call toc %lu\n"
+ " global entry %lu"),
stub_sec_count,
stub_sec_count == 1 ? "" : "s",
htab->stub_count[ppc_stub_long_branch - 1],
htab->stub_count[ppc_stub_plt_branch - 1],
htab->stub_count[ppc_stub_plt_branch_r2off - 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_r2save - 1],
+ htab->stub_count[ppc_stub_global_entry - 1]);
}
return TRUE;
}
return FALSE;
/* Don't relocate stub sections. */
- if (input_section->owner == htab->stub_bfd)
+ if (input_section->owner == htab->params->stub_bfd)
return TRUE;
BFD_ASSERT (is_ppc64_elf (input_bfd));
bfd_vma max_br_offset;
bfd_vma from;
const Elf_Internal_Rela orig_rel = *rel;
+ reloc_howto_type *howto;
+ struct reloc_howto_struct alt_howto;
r_type = ELF64_R_TYPE (rel->r_info);
r_symndx = ELF64_R_SYM (rel->r_info);
}
else
{
+ bfd_boolean ignored;
+
RELOC_FOR_GLOBAL_SYMBOL (info, input_bfd, input_section, rel,
r_symndx, symtab_hdr, sym_hashes,
h_elf, sec, relocation,
- unresolved_reloc, warned);
+ unresolved_reloc, warned, ignored);
sym_name = h_elf->root.root.string;
sym_type = h_elf->type;
if (sec != NULL
. addi 2,2,.TOC.@l
if .TOC. is in range. */
if (!info->shared
+ && !info->traditional_format
&& h != NULL && &h->elf == htab->elf.hgot
&& rel + 1 < relend
&& rel[1].r_info == ELF64_R_INFO (r_symndx, R_PPC64_REL16_LO)
if (h != NULL
&& (h == htab->tls_get_addr_fd
|| h == htab->tls_get_addr)
- && !htab->no_tls_get_addr_opt)
+ && !htab->params->no_tls_get_addr_opt)
{
/* Special stub used, leave nop alone. */
}
if (!can_plt_call)
{
- info->callbacks->einfo
- (_("%P: %H: call to `%T' lacks nop, can't restore toc; "
- "recompile with -fPIC"),
- input_bfd, input_section, rel->r_offset, sym_name);
+ if (stub_entry->stub_type == ppc_stub_plt_call
+ || stub_entry->stub_type == ppc_stub_plt_call_r2save)
+ info->callbacks->einfo
+ (_("%P: %H: call to `%T' lacks nop, can't restore toc; "
+ "recompile with -fPIC\n"),
+ input_bfd, input_section, rel->r_offset, sym_name);
+ else
+ info->callbacks->einfo
+ (_("%P: %H: call to `%T' lacks nop, can't restore toc; "
+ "(-mcmodel=small toc adjust stub)\n"),
+ input_bfd, input_section, rel->r_offset, sym_name);
bfd_set_error (bfd_error_bad_value);
ret = FALSE;
if (!WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn, info->shared,
&h->elf)
|| (info->shared
- && SYMBOL_CALLS_LOCAL (info, &h->elf)))
+ && SYMBOL_REFERENCES_LOCAL (info, &h->elf)))
/* This is actually a static link, or it is a
-Bsymbolic link and the symbol is defined
locally, or the symbol was forced to be local
addend -= htab->elf.tls_sec->vma + DTP_OFFSET;
break;
+ case R_PPC64_ADDR64_LOCAL:
+ addend += PPC64_LOCAL_ENTRY_OFFSET (h != NULL
+ ? h->elf.other
+ : sym->st_other);
+ break;
+
case R_PPC64_DTPMOD64:
relocation = 1;
addend = 0;
if (skip)
memset (&outrel, 0, sizeof outrel);
- else if (!SYMBOL_CALLS_LOCAL (info, &h->elf)
+ else if (!SYMBOL_REFERENCES_LOCAL (info, &h->elf)
&& !is_opd
&& r_type != R_PPC64_TOC)
{
}
/* Do any further special processing. */
+ howto = ppc64_elf_howto_table[(int) r_type];
switch (r_type)
{
default:
info->callbacks->einfo
(_("%P: %H: error: %s not a multiple of %u\n"),
input_bfd, input_section, rel->r_offset,
- ppc64_elf_howto_table[r_type]->name,
+ howto->name,
mask + 1);
bfd_set_error (bfd_error_bad_value);
ret = FALSE;
info->callbacks->einfo
(_("%P: %H: unresolvable %s against `%T'\n"),
input_bfd, input_section, rel->r_offset,
- ppc64_elf_howto_table[(int) r_type]->name,
+ howto->name,
h->elf.root.root.string);
ret = FALSE;
}
- r = _bfd_final_link_relocate (ppc64_elf_howto_table[(int) r_type],
- input_bfd,
- input_section,
- contents,
- rel->r_offset,
- relocation,
- addend);
+ /* 16-bit fields in insns mostly have signed values, but a
+ few insns have 16-bit unsigned values. Really, we should
+ have different reloc types. */
+ if (howto->complain_on_overflow != complain_overflow_dont
+ && howto->dst_mask == 0xffff
+ && (input_section->flags & SEC_CODE) != 0)
+ {
+ enum complain_overflow complain = complain_overflow_signed;
+
+ insn = bfd_get_32 (input_bfd, contents + (rel->r_offset & ~3));
+ if ((insn & (0x3f << 26)) == 10u << 26 /* cmpli */)
+ complain = complain_overflow_bitfield;
+ else if (howto->rightshift == 0
+ ? ((insn & (0x3f << 26)) == 28u << 26 /* andi */
+ || (insn & (0x3f << 26)) == 24u << 26 /* ori */
+ || (insn & (0x3f << 26)) == 26u << 26 /* xori */)
+ : ((insn & (0x3f << 26)) == 29u << 26 /* andis */
+ || (insn & (0x3f << 26)) == 25u << 26 /* oris */
+ || (insn & (0x3f << 26)) == 27u << 26 /* xoris */))
+ complain = complain_overflow_unsigned;
+ if (howto->complain_on_overflow != complain)
+ {
+ alt_howto = *howto;
+ alt_howto.complain_on_overflow = complain;
+ howto = &alt_howto;
+ }
+ }
+
+ r = _bfd_final_link_relocate (howto, input_bfd, input_section, contents,
+ rel->r_offset, relocation, addend);
if (r != bfd_reloc_ok)
{
char *more_info = NULL;
- const char *reloc_name = ppc64_elf_howto_table[r_type]->name;
+ const char *reloc_name = howto->name;
if (reloc_dest != DEST_NORMAL)
{
continue;
if (h != NULL
&& h->elf.root.type == bfd_link_hash_undefweak
- && ppc64_elf_howto_table[r_type]->pc_relative)
+ && howto->pc_relative)
{
/* Assume this is a call protected by other code that
detects the symbol is undefined. If this is the case,
NULL))
return FALSE;
-
if (htab->glink_eh_frame != NULL
- && htab->glink_eh_frame->sec_info_type == SEC_INFO_TYPE_EH_FRAME
- && !_bfd_elf_write_section_eh_frame (output_bfd, info,
- htab->glink_eh_frame,
- htab->glink_eh_frame->contents))
- return FALSE;
+ && htab->glink_eh_frame->size != 0)
+ {
+ bfd_vma val;
+ bfd_byte *p;
+ asection *stub_sec;
+
+ p = htab->glink_eh_frame->contents + sizeof (glink_eh_frame_cie);
+ for (stub_sec = htab->params->stub_bfd->sections;
+ stub_sec != NULL;
+ stub_sec = stub_sec->next)
+ if ((stub_sec->flags & SEC_LINKER_CREATED) == 0)
+ {
+ /* FDE length. */
+ p += 4;
+ /* CIE pointer. */
+ p += 4;
+ /* Offset to stub section. */
+ val = (stub_sec->output_section->vma
+ + stub_sec->output_offset);
+ val -= (htab->glink_eh_frame->output_section->vma
+ + htab->glink_eh_frame->output_offset
+ + (p - htab->glink_eh_frame->contents));
+ if (val + 0x80000000 > 0xffffffff)
+ {
+ info->callbacks->einfo
+ (_("%P: %s offset too large for .eh_frame sdata4 encoding"),
+ stub_sec->name);
+ return FALSE;
+ }
+ bfd_put_32 (dynobj, val, p);
+ p += 4;
+ /* stub section size. */
+ p += 4;
+ /* Augmentation. */
+ p += 1;
+ /* Pad. */
+ p += 7;
+ }
+ if (htab->glink != NULL && htab->glink->size != 0)
+ {
+ /* FDE length. */
+ p += 4;
+ /* CIE pointer. */
+ p += 4;
+ /* Offset to .glink. */
+ val = (htab->glink->output_section->vma
+ + htab->glink->output_offset
+ + 8);
+ val -= (htab->glink_eh_frame->output_section->vma
+ + htab->glink_eh_frame->output_offset
+ + (p - htab->glink_eh_frame->contents));
+ if (val + 0x80000000 > 0xffffffff)
+ {
+ info->callbacks->einfo
+ (_("%P: %s offset too large for .eh_frame sdata4 encoding"),
+ htab->glink->name);
+ return FALSE;
+ }
+ bfd_put_32 (dynobj, val, p);
+ p += 4;
+ /* .glink size. */
+ p += 4;
+ /* Augmentation. */
+ p += 1;
+ /* Ops. */
+ p += 7;
+ }
+
+ if (htab->glink_eh_frame->sec_info_type == SEC_INFO_TYPE_EH_FRAME
+ && !_bfd_elf_write_section_eh_frame (output_bfd, info,
+ htab->glink_eh_frame,
+ htab->glink_eh_frame->contents))
+ return FALSE;
+ }
/* We need to handle writing out multiple GOT sections ourselves,
since we didn't add them to DYNOBJ. We know dynobj is the first
bfd. */
- while ((dynobj = dynobj->link_next) != NULL)
+ while ((dynobj = dynobj->link.next) != NULL)
{
asection *s;
#undef TARGET_LITTLE_NAME
#undef TARGET_BIG_SYM
-#define TARGET_BIG_SYM bfd_elf64_powerpc_freebsd_vec
+#define TARGET_BIG_SYM powerpc_elf64_fbsd_vec
#undef TARGET_BIG_NAME
#define TARGET_BIG_NAME "elf64-powerpc-freebsd"