/* X86-64 specific support for 64-bit ELF
- Copyright 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007
+ Copyright 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008
Free Software Foundation, Inc.
Contributed by Jan Hubicka <jh@suse.cz>.
#define elf64_x86_64_local_tlsdesc_gotent(abfd) \
(elf64_x86_64_tdata (abfd)->local_tlsdesc_gotent)
+#define is_x86_64_elf(bfd) \
+ (bfd_get_flavour (bfd) == bfd_target_elf_flavour \
+ && elf_tdata (bfd) != NULL \
+ && elf_object_id (bfd) == X86_64_ELF_TDATA)
+
+static bfd_boolean
+elf64_x86_64_mkobject (bfd *abfd)
+{
+ return bfd_elf_allocate_object (abfd, sizeof (struct elf64_x86_64_obj_tdata),
+ X86_64_ELF_TDATA);
+}
+
/* x86-64 ELF linker hash table. */
struct elf64_x86_64_link_hash_table
_bfd_elf_link_hash_copy_indirect (info, dir, ind);
}
-static bfd_boolean
-elf64_x86_64_mkobject (bfd *abfd)
-{
- if (abfd->tdata.any == NULL)
- {
- bfd_size_type amt = sizeof (struct elf64_x86_64_obj_tdata);
- abfd->tdata.any = bfd_zalloc (abfd, amt);
- if (abfd->tdata.any == NULL)
- return FALSE;
- }
- return bfd_elf_mkobject (abfd);
-}
-
static bfd_boolean
elf64_x86_64_elf_object_p (bfd *abfd)
{
if (info->relocatable)
return TRUE;
+ BFD_ASSERT (is_x86_64_elf (abfd));
+
htab = elf64_x86_64_hash_table (info);
- symtab_hdr = &elf_tdata (abfd)->symtab_hdr;
+ symtab_hdr = &elf_symtab_hdr (abfd);
sym_hashes = elf_sym_hashes (abfd);
sreloc = NULL;
else
{
(*_bfd_error_handler)
- (_("%B: %s' accessed both as normal and thread local symbol"),
+ (_("%B: '%s' accessed both as normal and thread local symbol"),
abfd, h ? h->root.root.string : "<local>");
return FALSE;
}
/* This relocation describes which C++ vtable entries are actually
used. Record for later use during GC. */
case R_X86_64_GNU_VTENTRY:
- if (!bfd_elf_gc_record_vtentry (abfd, sec, h, rel->r_addend))
+ BFD_ASSERT (h != NULL);
+ if (h != NULL
+ && !bfd_elf_gc_record_vtentry (abfd, sec, h, rel->r_addend))
return FALSE;
break;
bfd_signed_vma *local_got_refcounts;
const Elf_Internal_Rela *rel, *relend;
+ if (info->relocatable)
+ return TRUE;
+
elf_section_data (sec)->local_dynrel = NULL;
- symtab_hdr = &elf_tdata (abfd)->symtab_hdr;
+ symtab_hdr = &elf_symtab_hdr (abfd);
sym_hashes = elf_sym_hashes (abfd);
local_got_refcounts = elf_local_got_refcounts (abfd);
Elf_Internal_Shdr *symtab_hdr;
asection *srel;
- if (bfd_get_flavour (ibfd) != bfd_target_elf_flavour)
+ if (! is_x86_64_elf (ibfd))
continue;
for (s = ibfd->sections; s != NULL; s = s->next)
if (!local_got)
continue;
- symtab_hdr = &elf_tdata (ibfd)->symtab_hdr;
+ symtab_hdr = &elf_symtab_hdr (ibfd);
locsymcount = symtab_hdr->sh_info;
end_local_got = local_got + locsymcount;
local_tls_type = elf64_x86_64_local_got_tls_type (ibfd);
Elf_Internal_Rela *rel;
Elf_Internal_Rela *relend;
+ BFD_ASSERT (is_x86_64_elf (input_bfd));
+
htab = elf64_x86_64_hash_table (info);
- symtab_hdr = &elf_tdata (input_bfd)->symtab_hdr;
+ symtab_hdr = &elf_symtab_hdr (input_bfd);
sym_hashes = elf_sym_hashes (input_bfd);
local_got_offsets = elf_local_got_offsets (input_bfd);
local_tlsdesc_gotents = elf64_x86_64_local_tlsdesc_gotent (input_bfd);
case R_X86_64_PC16:
case R_X86_64_PC32:
if (info->shared
- && !SYMBOL_REFERENCES_LOCAL (info, h)
&& (input_section->flags & SEC_ALLOC) != 0
&& (input_section->flags & SEC_READONLY) != 0
- && (!h->def_regular
- || r_type != R_X86_64_PC32
- || h->type != STT_FUNC
- || ELF_ST_VISIBILITY (h->other) != STV_PROTECTED
- || !is_32bit_relative_branch (contents,
- rel->r_offset)))
+ && h != NULL)
{
- if (h->def_regular
- && r_type == R_X86_64_PC32
- && h->type == STT_FUNC
- && ELF_ST_VISIBILITY (h->other) == STV_PROTECTED)
- (*_bfd_error_handler)
- (_("%B: relocation R_X86_64_PC32 against protected function `%s' can not be used when making a shared object"),
- input_bfd, h->root.root.string);
+ bfd_boolean fail = FALSE;
+ bfd_boolean branch
+ = (r_type == R_X86_64_PC32
+ && is_32bit_relative_branch (contents, rel->r_offset));
+
+ if (SYMBOL_REFERENCES_LOCAL (info, h))
+ {
+ /* Symbol is referenced locally. Make sure it is
+ defined locally or for a branch. */
+ fail = !h->def_regular && !branch;
+ }
else
- (*_bfd_error_handler)
- (_("%B: relocation %s against `%s' can not be used when making a shared object; recompile with -fPIC"),
- input_bfd, x86_64_elf_howto_table[r_type].name,
- h->root.root.string);
- bfd_set_error (bfd_error_bad_value);
- return FALSE;
+ {
+ /* Symbol isn't referenced locally. We only allow
+ branch to symbol with non-default visibility. */
+ fail = (!branch
+ || ELF_ST_VISIBILITY (h->other) == STV_DEFAULT);
+ }
+
+ if (fail)
+ {
+ const char *fmt;
+ const char *v;
+ const char *pic = "";
+
+ switch (ELF_ST_VISIBILITY (h->other))
+ {
+ case STV_HIDDEN:
+ v = _("hidden symbol");
+ break;
+ case STV_INTERNAL:
+ v = _("internal symbol");
+ break;
+ case STV_PROTECTED:
+ v = _("protected symbol");
+ break;
+ default:
+ v = _("symbol");
+ pic = _("; recompile with -fPIC");
+ break;
+ }
+
+ if (h->def_regular)
+ fmt = _("%B: relocation %s against %s `%s' can not be used when making a shared object%s");
+ else
+ fmt = _("%B: relocation %s against undefined %s `%s' can not be used when making a shared object%s");
+
+ (*_bfd_error_handler) (fmt, input_bfd,
+ x86_64_elf_howto_table[r_type].name,
+ v, h->root.root.string, pic);
+ bfd_set_error (bfd_error_bad_value);
+ return FALSE;
+ }
}
/* Fall through. */
if (info->shared
&& SYMBOL_REFERENCES_LOCAL (info, h))
{
+ if (!h->def_regular)
+ return FALSE;
BFD_ASSERT((h->got.offset & 1) != 0);
rela.r_info = ELF64_R_INFO (0, R_X86_64_RELATIVE);
rela.r_addend = (h->root.u.def.value
elf64_x86_64_reloc_name_lookup
#define elf_backend_adjust_dynamic_symbol elf64_x86_64_adjust_dynamic_symbol
+#define elf_backend_relocs_compatible _bfd_elf_relocs_compatible
#define elf_backend_check_relocs elf64_x86_64_check_relocs
#define elf_backend_copy_indirect_symbol elf64_x86_64_copy_indirect_symbol
#define elf_backend_create_dynamic_sections elf64_x86_64_create_dynamic_sections