/* Lattice Mico32-specific support for 32-bit ELF
- Copyright (C) 2008-2018 Free Software Foundation, Inc.
+ Copyright (C) 2008-2020 Free Software Foundation, Inc.
Contributed by Jon Beniston <jon@beniston.com>
This file is part of BFD, the Binary File Descriptor library.
static bfd_reloc_status_type lm32_elf_gprel_reloc
(bfd *, arelent *, asymbol *, void *, asection *, bfd *, char **);
-/* lm32 ELF linker hash entry. */
-
-struct elf_lm32_link_hash_entry
-{
- struct elf_link_hash_entry root;
-
- /* Track dynamic relocs copied for this symbol. */
- struct elf_dyn_relocs *dyn_relocs;
-};
-
/* lm32 ELF linker hash table. */
struct elf_lm32_link_hash_table
struct weak_symbol_list *next;
};
-/* Create an entry in an lm32 ELF linker hash table. */
-
-static struct bfd_hash_entry *
-lm32_elf_link_hash_newfunc (struct bfd_hash_entry *entry,
- struct bfd_hash_table *table,
- const char *string)
-{
- struct elf_lm32_link_hash_entry *ret =
- (struct elf_lm32_link_hash_entry *) entry;
-
- /* Allocate the structure if it has not already been allocated by a
- subclass. */
- if (ret == NULL)
- ret = bfd_hash_allocate (table,
- sizeof (struct elf_lm32_link_hash_entry));
- if (ret == NULL)
- return NULL;
-
- /* Call the allocation method of the superclass. */
- ret = ((struct elf_lm32_link_hash_entry *)
- _bfd_elf_link_hash_newfunc ((struct bfd_hash_entry *) ret,
- table, string));
- if (ret != NULL)
- {
- struct elf_lm32_link_hash_entry *eh;
-
- eh = (struct elf_lm32_link_hash_entry *) ret;
- eh->dyn_relocs = NULL;
- }
-
- return (struct bfd_hash_entry *) ret;
-}
-
/* Create an lm32 ELF linker hash table. */
static struct bfd_link_hash_table *
lm32_elf_link_hash_table_create (bfd *abfd)
{
struct elf_lm32_link_hash_table *ret;
- bfd_size_type amt = sizeof (struct elf_lm32_link_hash_table);
+ size_t amt = sizeof (struct elf_lm32_link_hash_table);
ret = bfd_zmalloc (amt);
if (ret == NULL)
return NULL;
if (!_bfd_elf_link_hash_table_init (&ret->root, abfd,
- lm32_elf_link_hash_newfunc,
- sizeof (struct elf_lm32_link_hash_entry),
+ _bfd_elf_link_hash_newfunc,
+ sizeof (struct elf_link_hash_entry),
LM32_ELF_DATA))
{
free (ret);
| SEC_LINKER_CREATED
| SEC_READONLY));
if (lm32fdpic_fixup32_section (info) == NULL
- || ! bfd_set_section_alignment (dynobj,
- lm32fdpic_fixup32_section (info), 2))
+ || !bfd_set_section_alignment (lm32fdpic_fixup32_section (info), 2))
return FALSE;
return TRUE;
/* Set the howto pointer for an Lattice Mico32 ELF reloc. */
-static void
-lm32_info_to_howto_rela (bfd *abfd ATTRIBUTE_UNUSED,
+static bfd_boolean
+lm32_info_to_howto_rela (bfd *abfd,
arelent *cache_ptr,
Elf_Internal_Rela *dst)
{
if (r_type >= (unsigned int) R_LM32_max)
{
/* xgettext:c-format */
- _bfd_error_handler (_("%B: invalid LM32 reloc number: %d"), abfd, r_type);
- r_type = 0;
+ _bfd_error_handler (_("%pB: unsupported relocation type %#x"),
+ abfd, r_type);
+ bfd_set_error (bfd_error_bad_value);
+ return FALSE;
}
cache_ptr->howto = &lm32_elf_howto_table[r_type];
+ return TRUE;
}
/* Set the right machine number for an Lattice Mico32 ELF file. */
/* Set machine type flags just before file is written out. */
-static void
-lm32_elf_final_write_processing (bfd *abfd, bfd_boolean linker ATTRIBUTE_UNUSED)
+static bfd_boolean
+lm32_elf_final_write_processing (bfd *abfd)
{
elf_elfheader (abfd)->e_machine = EM_LATTICEMICO32;
elf_elfheader (abfd)->e_flags &=~ EF_LM32_MACH;
default:
abort ();
}
+ return _bfd_elf_final_write_processing (abfd);
}
/* Set the GP value for OUTPUT_BFD. Returns FALSE if this is a
relocation = _bfd_elf_rela_local_sym (output_bfd, sym, &sec, rel);
name = bfd_elf_string_from_elf_section
(input_bfd, symtab_hdr->sh_link, sym->st_name);
- name = (name == NULL) ? bfd_section_name (input_bfd, sec) : name;
+ name = name == NULL ? bfd_section_name (sec) : name;
}
else
{
/* Addend should be zero. */
if (rel->r_addend != 0)
- _bfd_error_handler (_("internal error: addend should be zero for R_LM32_16_GOT"));
+ _bfd_error_handler
+ (_("internal error: addend should be zero for %s"),
+ "R_LM32_16_GOT");
r = _bfd_final_link_relocate (howto,
input_bfd,
if ((!h) || (h && h->root.type != bfd_link_hash_undefweak))
{
/* Only create .rofixup entries for relocs in loadable sections. */
- if ((bfd_get_section_flags (output_bfd, input_section->output_section)
+ if ((bfd_section_flags (input_section->output_section)
& (SEC_ALLOC | SEC_LOAD)) == (SEC_ALLOC | SEC_LOAD))
{
const char *msg = NULL;
arelent bfd_reloc;
- lm32_info_to_howto_rela (input_bfd, &bfd_reloc, rel);
+ if (! lm32_info_to_howto_rela (input_bfd, &bfd_reloc, rel))
+ continue;
howto = bfd_reloc.howto;
if (h != NULL)
name = (bfd_elf_string_from_elf_section
(input_bfd, symtab_hdr->sh_link, sym->st_name));
if (name == NULL || *name == '\0')
- name = bfd_section_name (input_bfd, sec);
+ name = bfd_section_name (sec);
}
switch (r)
!= (lm32fdpic_fixup32_section (info)->reloc_count * 4))
{
_bfd_error_handler
- ("LINKER BUG: .rofixup section size mismatch: size/4 %Ld != relocs %d",
- lm32fdpic_fixup32_section (info)->size/4,
+ ("LINKER BUG: .rofixup section size mismatch: size/4 %" PRId64
+ " != relocs %d",
+ (int64_t) (lm32fdpic_fixup32_section (info)->size / 4),
lm32fdpic_fixup32_section (info)->reloc_count);
return FALSE;
}
FALSE, FALSE, TRUE);
if (hend
&& (hend->type == bfd_link_hash_defined
- || hend->type == bfd_link_hash_defweak))
+ || hend->type == bfd_link_hash_defweak)
+ && hend->u.def.section->output_section != NULL)
{
bfd_vma value =
lm32fdpic_fixup32_section (info)->output_section->vma
if (hend->u.def.value != value)
{
_bfd_error_handler
- ("LINKER BUG: .rofixup section hend->u.def.value != value: %Ld != %Ld", hend->u.def.value, value);
+ ("LINKER BUG: .rofixup section hend->u.def.value != value: %"
+ PRId64 " != %" PRId64,
+ (int64_t) hend->u.def.value, (int64_t) value);
return FALSE;
}
}
}
}
-/* Find dynamic relocs for H that apply to read-only sections. */
-
-static asection *
-readonly_dynrelocs (struct elf_link_hash_entry *h)
-{
- struct elf_dyn_relocs *p;
- struct elf_lm32_link_hash_entry *eh = (struct elf_lm32_link_hash_entry *) h;
-
- for (p = eh->dyn_relocs; p != NULL; p = p->next)
- {
- asection *s = p->sec->output_section;
-
- if (s != NULL && (s->flags & SEC_READONLY) != 0)
- return p->sec;
- }
- return NULL;
-}
-
/* Adjust a symbol defined by a dynamic object and referenced by a
regular object. The current definition is in some section of the
dynamic object, but we're not including those sections. We have to
/* If we don't find any dynamic relocs in read-only sections, then
we'll be keeping the dynamic relocs and avoiding the copy reloc. */
- if (0 && !readonly_dynrelocs (h))
+ if (0 && !_bfd_elf_readonly_dynrelocs (h))
{
h->non_got_ref = 0;
return TRUE;
{
struct bfd_link_info *info;
struct elf_lm32_link_hash_table *htab;
- struct elf_lm32_link_hash_entry *eh;
struct elf_dyn_relocs *p;
if (h->root.type == bfd_link_hash_indirect)
if (htab == NULL)
return FALSE;
- eh = (struct elf_lm32_link_hash_entry *) h;
-
if (htab->root.dynamic_sections_created
&& h->plt.refcount > 0)
{
else
h->got.offset = (bfd_vma) -1;
- if (eh->dyn_relocs == NULL)
+ if (h->dyn_relocs == NULL)
return TRUE;
/* In the shared -Bsymbolic case, discard space allocated for
{
struct elf_dyn_relocs **pp;
- for (pp = &eh->dyn_relocs; (p = *pp) != NULL;)
+ for (pp = &h->dyn_relocs; (p = *pp) != NULL;)
{
p->count -= p->pc_count;
p->pc_count = 0;
/* Also discard relocs on undefined weak syms with non-default
visibility. */
- if (eh->dyn_relocs != NULL
+ if (h->dyn_relocs != NULL
&& h->root.type == bfd_link_hash_undefweak)
{
if (ELF_ST_VISIBILITY (h->other) != STV_DEFAULT)
- eh->dyn_relocs = NULL;
+ h->dyn_relocs = NULL;
/* Make sure undefined weak symbols are output as a dynamic
symbol in PIEs. */
goto keep;
}
- eh->dyn_relocs = NULL;
+ h->dyn_relocs = NULL;
keep: ;
}
/* Finally, allocate space. */
- for (p = eh->dyn_relocs; p != NULL; p = p->next)
+ for (p = h->dyn_relocs; p != NULL; p = p->next)
{
asection *sreloc = elf_section_data (p->sec)->sreloc;
sreloc->size += p->count * sizeof (Elf32_External_Rela);
return TRUE;
}
-/* Set DF_TEXTREL if we find any dynamic relocs that apply to
- read-only sections. */
-
-static bfd_boolean
-maybe_set_textrel (struct elf_link_hash_entry *h, void *info_p)
-{
- asection *sec;
-
- if (h->root.type == bfd_link_hash_indirect)
- return TRUE;
-
- sec = readonly_dynrelocs (h);
- if (sec != NULL)
- {
- struct bfd_link_info *info = (struct bfd_link_info *) info_p;
-
- info->flags |= DF_TEXTREL;
- info->callbacks->minfo
- (_("%B: dynamic relocation against `%T' in read-only section `%A'\n"),
- sec->owner, h->root.root.string, sec);
-
- /* Not an error, just cut short the traversal. */
- return FALSE;
- }
- return TRUE;
-}
-
/* Set the sizes of the dynamic sections. */
static bfd_boolean
/* Strip this section if we don't need it; see the
comment below. */
}
- else if (CONST_STRNEQ (bfd_get_section_name (dynobj, s), ".rela"))
+ else if (CONST_STRNEQ (bfd_section_name (s), ".rela"))
{
if (s->size != 0 && s != htab->root.srelplt)
relocs = TRUE;
/* If any dynamic relocs apply to a read-only section,
then we need a DT_TEXTREL entry. */
if ((info->flags & DF_TEXTREL) == 0)
- elf_link_hash_traverse (&htab->root, maybe_set_textrel, info);
+ elf_link_hash_traverse (&htab->root,
+ _bfd_elf_maybe_set_textrel, info);
if ((info->flags & DF_TEXTREL) != 0)
{
/* Don't generate entries for weak symbols. */
if (!h || (h && h->root.type != bfd_link_hash_undefweak))
{
- if (!discarded_section (s) && !((bfd_get_section_flags (ibfd, s) & SEC_ALLOC) == 0))
+ if (!discarded_section (s) && !((bfd_section_flags (s) & SEC_ALLOC) == 0))
{
switch (ELF32_R_TYPE (internal_relocs->r_info))
{
if (!strcmp (current->name, h->root.root.string))
break;
}
- if (!current && !discarded_section (s) && (bfd_get_section_flags (ibfd, s) & SEC_ALLOC))
+ if (!current && !discarded_section (s) && (bfd_section_flags (s) & SEC_ALLOC))
{
/* Will this have an entry in the GOT. */
if (ELF32_R_TYPE (internal_relocs->r_info) == R_LM32_16_GOT)
s = bfd_make_section_anyway_with_flags (abfd, ".plt", pltflags);
htab->root.splt = s;
if (s == NULL
- || ! bfd_set_section_alignment (abfd, s, bed->plt_alignment))
+ || !bfd_set_section_alignment (s, bed->plt_alignment))
return FALSE;
if (bed->want_plt_sym)
flags | SEC_READONLY);
htab->root.srelplt = s;
if (s == NULL
- || ! bfd_set_section_alignment (abfd, s, ptralign))
+ || !bfd_set_section_alignment (s, ptralign))
return FALSE;
if (htab->root.sgot == NULL
flags | SEC_READONLY);
htab->srelbss = s;
if (s == NULL
- || ! bfd_set_section_alignment (abfd, s, ptralign))
+ || !bfd_set_section_alignment (s, ptralign))
return FALSE;
}
}
return TRUE;
}
-/* Copy the extra info we tack onto an elf_link_hash_entry. */
-
-static void
-lm32_elf_copy_indirect_symbol (struct bfd_link_info *info,
- struct elf_link_hash_entry *dir,
- struct elf_link_hash_entry *ind)
-{
- struct elf_lm32_link_hash_entry * edir;
- struct elf_lm32_link_hash_entry * eind;
-
- edir = (struct elf_lm32_link_hash_entry *) dir;
- eind = (struct elf_lm32_link_hash_entry *) ind;
-
- if (eind->dyn_relocs != NULL)
- {
- if (edir->dyn_relocs != NULL)
- {
- struct elf_dyn_relocs **pp;
- struct elf_dyn_relocs *p;
-
- /* Add reloc counts against the indirect sym to the direct sym
- list. Merge any entries against the same section. */
- for (pp = &eind->dyn_relocs; (p = *pp) != NULL;)
- {
- struct elf_dyn_relocs *q;
-
- for (q = edir->dyn_relocs; q != NULL; q = q->next)
- if (q->sec == p->sec)
- {
- q->pc_count += p->pc_count;
- q->count += p->count;
- *pp = p->next;
- break;
- }
- if (q == NULL)
- pp = &p->next;
- }
- *pp = edir->dyn_relocs;
- }
-
- edir->dyn_relocs = eind->dyn_relocs;
- eind->dyn_relocs = NULL;
- }
-
- _bfd_elf_link_hash_copy_indirect (info, dir, ind);
-}
-
static bfd_boolean
lm32_elf_always_size_sections (bfd *output_bfd, struct bfd_link_info *info)
{
#define bfd_elf32_bfd_reloc_type_lookup lm32_reloc_type_lookup
#define bfd_elf32_bfd_reloc_name_lookup lm32_reloc_name_lookup
#define elf_info_to_howto lm32_info_to_howto_rela
-#define elf_info_to_howto_rel 0
+#define elf_info_to_howto_rel NULL
#define elf_backend_rela_normal 1
#define elf_backend_object_p lm32_elf_object_p
#define elf_backend_final_write_processing lm32_elf_final_write_processing
#define bfd_elf32_bfd_link_hash_table_create lm32_elf_link_hash_table_create
#define elf_backend_check_relocs lm32_elf_check_relocs
#define elf_backend_reloc_type_class lm32_elf_reloc_type_class
-#define elf_backend_copy_indirect_symbol lm32_elf_copy_indirect_symbol
#define elf_backend_size_dynamic_sections lm32_elf_size_dynamic_sections
-#define elf_backend_omit_section_dynsym ((bfd_boolean (*) (bfd *, struct bfd_link_info *, asection *)) bfd_true_any)
+#define elf_backend_omit_section_dynsym _bfd_elf_omit_section_dynsym_all
#define elf_backend_create_dynamic_sections lm32_elf_create_dynamic_sections
#define elf_backend_finish_dynamic_sections lm32_elf_finish_dynamic_sections
#define elf_backend_adjust_dynamic_symbol lm32_elf_adjust_dynamic_symbol