/* X86-64 specific support for ELF
- Copyright (C) 2000-2014 Free Software Foundation, Inc.
+ Copyright (C) 2000-2015 Free Software Foundation, Inc.
Contributed by Jan Hubicka <jh@suse.cz>.
This file is part of BFD, the Binary File Descriptor library.
special_function, name, partial_inplace, src_mask, dst_mask, pcrel_offset. */
static reloc_howto_type x86_64_elf_howto_table[] =
{
- HOWTO(R_X86_64_NONE, 0, 0, 0, FALSE, 0, complain_overflow_dont,
+ HOWTO(R_X86_64_NONE, 0, 3, 0, FALSE, 0, complain_overflow_dont,
bfd_elf_generic_reloc, "R_X86_64_NONE", FALSE, 0x00000000, 0x00000000,
FALSE),
HOWTO(R_X86_64_64, 0, 4, 64, FALSE, 0, complain_overflow_bitfield,
return elf_x86_64_rtype_to_howto (abfd,
x86_64_reloc_map[i].elf_reloc_val);
}
- return 0;
+ return NULL;
}
static reloc_howto_type *
(GOT_TLS_GD_P (type) || GOT_TLS_GDESC_P (type))
unsigned char tls_type;
+ /* TRUE if a weak symbol with a real definition needs a copy reloc.
+ When there is a weak symbol with a real definition, the processor
+ independent code will have arranged for us to see the real
+ definition first. We need to copy the needs_copy bit from the
+ real definition and check it when allowing copy reloc in PIE. */
+ unsigned int needs_copy : 1;
+
/* TRUE if symbol has at least one BND relocation. */
- bfd_boolean has_bnd_reloc;
+ unsigned int has_bnd_reloc : 1;
/* Information about the GOT PLT entry. Filled when there are both
GOT and PLT relocations against the same function. */
eh = (struct elf_x86_64_link_hash_entry *) entry;
eh->dyn_relocs = NULL;
eh->tls_type = GOT_UNKNOWN;
- eh->has_bnd_reloc = FALSE;
+ eh->needs_copy = 0;
+ eh->has_bnd_reloc = 0;
eh->plt_bnd.offset = (bfd_vma) -1;
eh->plt_got.offset = (bfd_vma) -1;
eh->tlsdesc_got = (bfd_vma) -1;
&& (get_elf_x86_64_backend_data (abfd)
== &elf_x86_64_arch_bed))
{
- elf_x86_64_hash_entry (h)->has_bnd_reloc = TRUE;
+ elf_x86_64_hash_entry (h)->has_bnd_reloc = 1;
/* Create the second PLT for Intel MPX support. */
if (htab->plt_bnd == NULL)
h->root.u.def.section = h->u.weakdef->root.u.def.section;
h->root.u.def.value = h->u.weakdef->root.u.def.value;
if (ELIMINATE_COPY_RELOCS || info->nocopyreloc)
- h->non_got_ref = h->u.weakdef->non_got_ref;
+ {
+ eh = (struct elf_x86_64_link_hash_entry *) h;
+ h->non_got_ref = h->u.weakdef->non_got_ref;
+ eh->needs_copy = h->u.weakdef->needs_copy;
+ }
return TRUE;
}
s = htab->sdynbss;
- return _bfd_elf_adjust_dynamic_copy (h, s);
+ return _bfd_elf_adjust_dynamic_copy (info, h, s);
}
/* Allocate space in .plt, .got and associated reloc sections for
&& ! bfd_elf_link_record_dynamic_symbol (info, h))
return FALSE;
}
- /* For PIE, discard space for relocs against symbols which
- turn out to need copy relocs. */
+ /* For PIE, discard space for pc-relative relocs against
+ symbols which turn out to need copy relocs. */
else if (info->executable
- && h->needs_copy
+ && (h->needs_copy || eh->needs_copy)
&& h->def_dynamic
&& !h->def_regular)
- eh->dyn_relocs = NULL;
+ {
+ struct elf_dyn_relocs **pp;
+
+ for (pp = &eh->dyn_relocs; (p = *pp) != NULL; )
+ {
+ if (p->pc_count != 0)
+ *pp = p->next;
+ else
+ pp = &p->next;
+ }
+ }
}
}
else if (ELIMINATE_COPY_RELOCS)
info->flags |= DF_TEXTREL;
- if (info->warn_shared_textrel && info->shared)
- info->callbacks->einfo (_("%P: %B: warning: relocation against `%s' in readonly section `%A'.\n"),
+ if ((info->warn_shared_textrel && info->shared)
+ || info->error_textrel)
+ info->callbacks->einfo (_("%P: %B: warning: relocation against `%s' in readonly section `%A'\n"),
p->sec->owner, h->root.root.string,
p->sec);
&& (info->flags & DF_TEXTREL) == 0)
{
info->flags |= DF_TEXTREL;
- if (info->warn_shared_textrel && info->shared)
- info->callbacks->einfo (_("%P: %B: warning: relocation in readonly section `%A'.\n"),
+ if ((info->warn_shared_textrel && info->shared)
+ || info->error_textrel)
+ info->callbacks->einfo (_("%P: %B: warning: relocation in readonly section `%A'\n"),
p->sec->owner, p->sec);
}
}
tlsbase = (struct elf_link_hash_entry *)bh;
tlsbase->def_regular = 1;
tlsbase->other = STV_HIDDEN;
+ tlsbase->root.linker_def = 1;
(*bed->elf_backend_hide_symbol) (info, tlsbase, TRUE);
}
}
case R_X86_64_PC16:
case R_X86_64_PC32:
case R_X86_64_PC32_BND:
+ /* Don't complain about -fPIC if the symbol is undefined when
+ building executable. */
if (info->shared
&& (input_section->flags & SEC_ALLOC) != 0
&& (input_section->flags & SEC_READONLY) != 0
- && h != NULL)
+ && h != NULL
+ && !(info->executable
+ && h->root.type == bfd_link_hash_undefined))
{
bfd_boolean fail = FALSE;
bfd_boolean branch
defined locally or for a branch. */
fail = !h->def_regular && !branch;
}
- else if (!(info->executable && h->needs_copy))
+ else if (!(info->executable
+ && (h->needs_copy || eh->needs_copy)))
{
/* Symbol doesn't need copy reloc and isn't referenced
locally. We only allow branch to symbol with
break;
/* Don't copy a pc-relative relocation into the output file
- if the symbol needs copy reloc. */
+ if the symbol needs copy reloc or the symbol is undefined
+ when building executable. */
if ((info->shared
&& !(info->executable
&& h != NULL
- && h->needs_copy
+ && (h->needs_copy
+ || eh->needs_copy
+ || h->root.type == bfd_link_hash_undefined)
&& IS_X86_64_PCREL_TYPE (r_type))
&& (h == NULL
|| ELF_ST_VISIBILITY (h->other) == STV_DEFAULT
if (plt_sym_val == NULL)
goto bad_return;
- for (i = 0; i < count; i++, p++)
+ for (i = 0; i < count; i++)
plt_sym_val[i] = -1;
plt_offset = bed->plt_entry_size;
{
long reloc_index;
+ /* Skip unknown relocation. */
+ if (p->howto == NULL)
+ continue;
+
if (p->howto->type != R_X86_64_JUMP_SLOT
&& p->howto->type != R_X86_64_IRELATIVE)
continue;