/* ELF STT_GNU_IFUNC support.
- Copyright (C) 2009-2014 Free Software Foundation, Inc.
+ Copyright (C) 2009-2016 Free Software Foundation, Inc.
This file is part of BFD, the Binary File Descriptor library.
if (bed->plt_readonly)
pltflags |= SEC_READONLY;
- if (info->shared)
+ if (bfd_link_pic (info))
{
/* We need to create .rel[a].ifunc for shared objects. */
const char *rel_sec = (bed->rela_plts_and_copies_p
_bfd_elf_allocate_ifunc_dyn_relocs (struct bfd_link_info *info,
struct elf_link_hash_entry *h,
struct elf_dyn_relocs **head,
+ bfd_boolean *readonly_dynrelocs_against_ifunc_p,
unsigned int plt_entry_size,
unsigned int plt_header_size,
unsigned int got_entry_size)
unsigned int sizeof_reloc;
const struct elf_backend_data *bed;
struct elf_link_hash_table *htab;
+ bfd_boolean readonly_dynrelocs_against_ifunc;
/* When a shared library references a STT_GNU_IFUNC symbol defined
in executable, the address of the resolved function may be used.
But in non-shared executable, the address of its .plt slot may
be used. Pointer equality may not work correctly. PIE should
be used if pointer equality is required here. */
- if (!info->shared
+ if (!bfd_link_pic (info)
&& (h->dynindx != -1
|| info->export_dynamic)
&& h->pointer_equality_needed)
/* When building shared library, we need to handle the case where it is
marked with regular reference, but not non-GOT reference since the
non-GOT reference bit may not be set here. */
- if (info->shared && !h->non_got_ref && h->ref_regular)
+ if (bfd_link_pic (info) && !h->non_got_ref && h->ref_regular)
for (p = *head; p != NULL; p = p->next)
if (p->count)
{
/* We need dynamic relocation for STT_GNU_IFUNC symbol only when
there is a non-GOT reference in a shared object. */
- if (!info->shared
+ if (!bfd_link_pic (info)
|| !h->non_got_ref)
*head = NULL;
+ readonly_dynrelocs_against_ifunc = FALSE;
+
/* Finally, allocate space. */
p = *head;
if (p != NULL)
bfd_size_type count = 0;
do
{
+ if (!readonly_dynrelocs_against_ifunc)
+ {
+ asection *s = p->sec->output_section;
+ if (s != NULL && (s->flags & SEC_READONLY) != 0)
+ readonly_dynrelocs_against_ifunc = TRUE;
+ }
count += p->count;
p = p->next;
}
htab->irelifunc->size += count * sizeof_reloc;
}
+ if (readonly_dynrelocs_against_ifunc_p)
+ *readonly_dynrelocs_against_ifunc_p = readonly_dynrelocs_against_ifunc;
+
/* For STT_GNU_IFUNC symbol, .got.plt has the real function address
and .got has the PLT entry adddress. We will load the GOT entry
with the PLT entry in finish_dynamic_symbol if it is used. For
objects at run-time.
We only need to relocate .got entry in shared object. */
if (h->got.refcount <= 0
- || (info->shared
+ || (bfd_link_pic (info)
&& (h->dynindx == -1
|| h->forced_local))
- || (!info->shared
+ || (!bfd_link_pic (info)
&& !h->pointer_equality_needed)
- || (info->executable && info->shared)
+ || bfd_link_pie (info)
|| htab->sgot == NULL)
{
/* Use .got.plt. */
{
h->got.offset = htab->sgot->size;
htab->sgot->size += got_entry_size;
- if (info->shared)
+ if (bfd_link_pic (info))
htab->srelgot->size += sizeof_reloc;
}