/* 32-bit ELF support for Nios II.
- Copyright (C) 2012, 2013 Free Software Foundation, Inc.
+ Copyright (C) 2012-2015 Free Software Foundation, Inc.
Contributed by Nigel Gray (ngray@altera.com).
Contributed by Mentor Graphics, Inc.
(bfd *, arelent *, asymbol *, void *, asection *, bfd *, char **);
/* Target vector. */
-extern const bfd_target bfd_elf32_littlenios2_vec;
-extern const bfd_target bfd_elf32_bignios2_vec;
+extern const bfd_target nios2_elf32_le_vec;
+extern const bfd_target nios2_elf32_be_vec;
/* Offset of tp and dtp pointers from start of TLS block. */
#define TP_OFFSET 0x7000
/* No relocation. */
HOWTO (R_NIOS2_NONE, /* type */
0, /* rightshift */
- 0, /* size (0 = byte, 1 = short, 2 = long) */
+ 3, /* size (0 = byte, 1 = short, 2 = long) */
0, /* bitsize */
FALSE, /* pc_relative */
0, /* bitpos */
};
static const struct elf_reloc_map nios2_reloc_map[] = {
+ {BFD_RELOC_NONE, R_NIOS2_NONE},
{BFD_RELOC_NIOS2_S16, R_NIOS2_S16},
{BFD_RELOC_NIOS2_U16, R_NIOS2_U16},
{BFD_RELOC_16_PCREL, R_NIOS2_PCREL16},
/* Count the number of input BFDs and find the top input section id. */
for (input_bfd = info->input_bfds, bfd_count = 0, top_id = 0;
input_bfd != NULL;
- input_bfd = input_bfd->link_next)
+ input_bfd = input_bfd->link.next)
{
bfd_count += 1;
for (section = input_bfd->sections;
/* Walk over all the input BFDs, swapping in local symbols. */
for (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;
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;
for (stub_sec = htab->stub_bfd->sections;
stub_sec != NULL;
stub_sec = stub_sec->next)
- {
- bfd_size_type size;
-
- /* Allocate memory to hold the linker stubs. */
- size = stub_sec->size;
- stub_sec->contents = bfd_zalloc (htab->stub_bfd, size);
- if (stub_sec->contents == NULL && size != 0)
- return FALSE;
- stub_sec->size = 0;
- }
+ /* The stub_bfd may contain non-stub sections if it is also the
+ dynobj. Any such non-stub sections are created with the
+ SEC_LINKER_CREATED flag set, while stub sections do not
+ have that flag. Ignore any non-stub sections here. */
+ if ((stub_sec->flags & SEC_LINKER_CREATED) == 0)
+ {
+ bfd_size_type size;
+
+ /* Allocate memory to hold the linker stubs. */
+ size = stub_sec->size;
+ stub_sec->contents = bfd_zalloc (htab->stub_bfd, size);
+ if (stub_sec->contents == NULL && size != 0)
+ return FALSE;
+ stub_sec->size = 0;
+ }
/* Build the stubs as directed by the stub hash table. */
table = &htab->bstab;
break;
}
- /* Adjust the relocation to be relative to the GOT pointer. */
- relocation -= (sgot->output_section->vma
- + sgot->output_offset - got_base);
+ /* Note that sgot->output_offset is not involved in this
+ calculation. We always want the start of .got. */
+ relocation -= sgot->output_section->vma;
+
+ /* Now we adjust the relocation to be relative to the GOT pointer
+ (the _gp_got symbol), which possibly contains the 0x8000 bias. */
+ relocation -= got_base;
switch (howto->type)
{
/* 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)
{
bfd_signed_vma *local_got;
bfd_signed_vma *end_local_got;
return TRUE;
}
+/* Free the derived linker hash table. */
+static void
+nios2_elf32_link_hash_table_free (bfd *obfd)
+{
+ struct elf32_nios2_link_hash_table *htab
+ = (struct elf32_nios2_link_hash_table *) obfd->link.hash;
+
+ bfd_hash_table_free (&htab->bstab);
+ _bfd_elf_link_hash_table_free (obfd);
+}
+
/* Implement bfd_elf32_bfd_link_hash_table_create. */
static struct bfd_link_hash_table *
nios2_elf32_link_hash_table_create (bfd *abfd)
/* Init the stub hash table too. */
if (!bfd_hash_table_init (&ret->bstab, stub_hash_newfunc,
sizeof (struct elf32_nios2_stub_hash_entry)))
- return NULL;
+ {
+ _bfd_elf_link_hash_table_free (abfd);
+ return NULL;
+ }
+ ret->root.root.hash_table_free = nios2_elf32_link_hash_table_free;
return &ret->root.root;
}
-/* Free the derived linker hash table. */
-static void
-nios2_elf32_link_hash_table_free (struct bfd_link_hash_table *btab)
-{
- struct elf32_nios2_link_hash_table *htab
- = (struct elf32_nios2_link_hash_table *) btab;
-
- bfd_hash_table_free (&htab->bstab);
- _bfd_elf_link_hash_table_free (btab);
-}
-
/* Implement elf_backend_reloc_type_class. */
static enum elf_reloc_type_class
nios2_elf32_reloc_type_class (const struct bfd_link_info *info ATTRIBUTE_UNUSED,
static bfd_boolean
is_nios2_elf_target (const struct bfd_target *targ)
{
- return (targ == &bfd_elf32_littlenios2_vec
- || targ == &bfd_elf32_bignios2_vec);
+ return (targ == &nios2_elf32_le_vec
+ || targ == &nios2_elf32_be_vec);
}
/* Implement elf_backend_add_symbol_hook.
#define bfd_elf32_bfd_link_hash_table_create \
nios2_elf32_link_hash_table_create
-#define bfd_elf32_bfd_link_hash_table_free \
- nios2_elf32_link_hash_table_free
/* Relocation table lookup macros. */
#define elf_backend_special_sections elf32_nios2_special_sections
-#define TARGET_LITTLE_SYM bfd_elf32_littlenios2_vec
+#define TARGET_LITTLE_SYM nios2_elf32_le_vec
#define TARGET_LITTLE_NAME "elf32-littlenios2"
-#define TARGET_BIG_SYM bfd_elf32_bignios2_vec
+#define TARGET_BIG_SYM nios2_elf32_be_vec
#define TARGET_BIG_NAME "elf32-bignios2"
#define elf_backend_got_header_size 12
+#define elf_backend_default_execstack 0
#include "elf32-target.h"