/* VAX series support for 32-bit ELF
- Copyright (C) 1993-2018 Free Software Foundation, Inc.
+ Copyright (C) 1993-2020 Free Software Foundation, Inc.
Contributed by Matt Thomas <matt@3am-software.com>.
This file is part of BFD, the Binary File Descriptor library.
#include "elf/vax.h"
static reloc_howto_type *reloc_type_lookup (bfd *, bfd_reloc_code_real_type);
-static void rtype_to_howto (bfd *, arelent *, Elf_Internal_Rela *);
+static bfd_boolean rtype_to_howto (bfd *, arelent *, Elf_Internal_Rela *);
static struct bfd_hash_entry *elf_vax_link_hash_newfunc (struct bfd_hash_entry *,
struct bfd_hash_table *,
const char *);
FALSE), /* pcrel_offset */
};
-static void
+static bfd_boolean
rtype_to_howto (bfd *abfd, arelent *cache_ptr, Elf_Internal_Rela *dst)
{
unsigned int r_type;
if (r_type >= R_VAX_max)
{
/* xgettext:c-format */
- _bfd_error_handler (_("%pB: unrecognised VAX reloc number: %d"),
+ _bfd_error_handler (_("%pB: unsupported relocation type %#x"),
abfd, r_type);
bfd_set_error (bfd_error_bad_value);
- r_type = R_VAX_NONE;
+ return FALSE;
}
cache_ptr->howto = &howto_table[r_type];
+ return TRUE;
}
#define elf_info_to_howto rtype_to_howto
elf_vax_link_hash_table_create (bfd *abfd)
{
struct elf_link_hash_table *ret;
- bfd_size_type amt = sizeof (struct elf_link_hash_table);
+ size_t amt = sizeof (struct elf_link_hash_table);
ret = bfd_zmalloc (amt);
if (ret == NULL)
h->plt.refcount++;
}
+ /* Non-GOT reference may need a copy reloc in executable or
+ a dynamic reloc in shared library. */
+ if (h != NULL)
+ h->non_got_ref = 1;
+
/* If we are creating a shared library, we need to copy the
reloc into the shared library. */
if (bfd_link_pic (info)
/* This relocation describes which C++ vtable entries are actually
used. Record for later use during GC. */
case R_VAX_GNU_VTENTRY:
- BFD_ASSERT (h != NULL);
- if (h != NULL
- && !bfd_elf_gc_record_vtentry (abfd, sec, h, rel->r_addend))
+ if (!bfd_elf_gc_record_vtentry (abfd, sec, h, rel->r_addend))
return FALSE;
break;
if (bfd_link_pic (info))
return TRUE;
+ /* If there are no references to this symbol that do not use the
+ GOT relocation, we don't need to generate a copy reloc. */
+ if (!h->non_got_ref)
+ return TRUE;
+
/* We must allocate the symbol in our .dynbss section, which will
become part of the .bss section of the executable. There will be
an entry for this symbol in the .dynsym section. The dynamic
{
bfd *dynobj;
asection *s;
- bfd_boolean plt;
bfd_boolean relocs;
- bfd_boolean reltext;
dynobj = elf_hash_table (info)->dynobj;
BFD_ASSERT (dynobj != NULL);
/* The check_relocs and adjust_dynamic_symbol entry points have
determined the sizes of the various dynamic sections. Allocate
memory for them. */
- plt = FALSE;
relocs = FALSE;
- reltext = FALSE;
for (s = dynobj->sections; s != NULL; s = s->next)
{
const char *name;
/* It's OK to base decisions on the section name, because none
of the dynobj section names depend upon the input files. */
- name = bfd_get_section_name (dynobj, s);
+ name = bfd_section_name (s);
if (strcmp (name, ".plt") == 0)
{
/* Remember whether there is a PLT. */
- plt = s->size != 0;
+ ;
}
else if (CONST_STRNEQ (name, ".rela"))
{
if (s->size != 0)
{
- asection *target;
-
- /* Remember whether there are any reloc sections other
- than .rela.plt. */
if (strcmp (name, ".rela.plt") != 0)
- {
- const char *outname;
-
- relocs = TRUE;
-
- /* If this relocation section applies to a read only
- section, then we probably need a DT_TEXTREL
- entry. .rela.plt is actually associated with
- .got.plt, which is never readonly. */
- outname = bfd_get_section_name (output_bfd,
- s->output_section);
- target = bfd_get_section_by_name (output_bfd, outname + 5);
- if (target != NULL
- && (target->flags & SEC_READONLY) != 0
- && (target->flags & SEC_ALLOC) != 0)
- reltext = TRUE;
- }
+ relocs = TRUE;
/* We use the reloc_count field as a counter if we need
to copy relocs into the output file. */
return FALSE;
}
- if (elf_hash_table (info)->dynamic_sections_created)
- {
- /* Add some entries to the .dynamic section. We fill in the
- values later, in elf_vax_finish_dynamic_sections, but we
- must add the entries now so that we get the correct size for
- the .dynamic section. The DT_DEBUG entry is filled in by the
- dynamic linker and used by the debugger. */
-#define add_dynamic_entry(TAG, VAL) \
- _bfd_elf_add_dynamic_entry (info, TAG, VAL)
-
- if (!bfd_link_pic (info))
- {
- if (!add_dynamic_entry (DT_DEBUG, 0))
- return FALSE;
- }
-
- if (plt)
- {
- if (!add_dynamic_entry (DT_PLTGOT, 0)
- || !add_dynamic_entry (DT_PLTRELSZ, 0)
- || !add_dynamic_entry (DT_PLTREL, DT_RELA)
- || !add_dynamic_entry (DT_JMPREL, 0))
- return FALSE;
- }
-
- if (relocs)
- {
- if (!add_dynamic_entry (DT_RELA, 0)
- || !add_dynamic_entry (DT_RELASZ, 0)
- || !add_dynamic_entry (DT_RELAENT, sizeof (Elf32_External_Rela)))
- return FALSE;
- }
-
- if (reltext || (info->flags & DF_TEXTREL) != 0)
- {
- if (!add_dynamic_entry (DT_TEXTREL, 0))
- return FALSE;
- }
- }
-#undef add_dynamic_entry
-
- return TRUE;
+ return _bfd_elf_add_dynamic_tags (output_bfd, info, relocs);
}
/* This function is called via elf_vax_link_hash_traverse if we are
if (name == NULL)
return FALSE;
if (*name == '\0')
- name = bfd_section_name (input_bfd, sec);
+ name = bfd_section_name (sec);
}
info->callbacks->reloc_overflow
(info, (h ? &h->root : NULL), name, howto->name,