/* Lattice Mico32-specific support for 32-bit ELF
- Copyright (C) 2008-2018 Free Software Foundation, Inc.
+ Copyright (C) 2008-2021 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
/* Get the lm32 ELF linker hash table from a link_info structure. */
#define lm32_elf_hash_table(p) \
- (elf_hash_table_id ((struct elf_link_hash_table *) ((p)->hash)) \
- == LM32_ELF_DATA ? ((struct elf_lm32_link_hash_table *) ((p)->hash)) : NULL)
+ ((is_elf_hash_table ((p)->hash) \
+ && elf_hash_table_id (elf_hash_table (p)) == LM32_ELF_DATA) \
+ ? (struct elf_lm32_link_hash_table *) (p)->hash : NULL)
#define lm32fdpic_got_section(info) \
(lm32_elf_hash_table (info)->root.sgot)
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);
/* Create .rofixup sections in DYNOBJ, and set up
shortcuts to them in our hash table. */
-static bfd_boolean
+static bool
create_rofixup_section (bfd *dynobj, struct bfd_link_info *info)
{
struct elf_lm32_link_hash_table *htab;
htab = lm32_elf_hash_table (info);
if (htab == NULL)
- return FALSE;
+ return false;
/* Fixup section for R_LM32_32 relocs. */
lm32fdpic_fixup32_section (info)
| SEC_LINKER_CREATED
| SEC_READONLY));
if (lm32fdpic_fixup32_section (info) == NULL
- || ! bfd_set_section_alignment (dynobj,
- lm32fdpic_fixup32_section (info), 2))
- return FALSE;
+ || !bfd_set_section_alignment (lm32fdpic_fixup32_section (info), 2))
+ return false;
- return TRUE;
+ return true;
}
static reloc_howto_type lm32_elf_howto_table [] =
0, /* rightshift */
3, /* size (0 = byte, 1 = short, 2 = long) */
0, /* bitsize */
- FALSE, /* pc_relative */
+ false, /* pc_relative */
0, /* bitpos */
complain_overflow_dont, /* complain_on_overflow */
bfd_elf_generic_reloc, /* special_function */
"R_LM32_NONE", /* name */
- FALSE, /* partial_inplace */
+ false, /* partial_inplace */
0, /* src_mask */
0, /* dst_mask */
- FALSE), /* pcrel_offset */
+ false), /* pcrel_offset */
/* An 8 bit absolute relocation. */
HOWTO (R_LM32_8, /* type */
0, /* rightshift */
0, /* size (0 = byte, 1 = short, 2 = long) */
8, /* bitsize */
- FALSE, /* pc_relative */
+ false, /* pc_relative */
0, /* bitpos */
complain_overflow_bitfield,/* complain_on_overflow */
bfd_elf_generic_reloc, /* special_function */
"R_LM32_8", /* name */
- FALSE, /* partial_inplace */
+ false, /* partial_inplace */
0, /* src_mask */
0xff, /* dst_mask */
- FALSE), /* pcrel_offset */
+ false), /* pcrel_offset */
/* A 16 bit absolute relocation. */
HOWTO (R_LM32_16, /* type */
0, /* rightshift */
1, /* size (0 = byte, 1 = short, 2 = long) */
16, /* bitsize */
- FALSE, /* pc_relative */
+ false, /* pc_relative */
0, /* bitpos */
complain_overflow_bitfield,/* complain_on_overflow */
bfd_elf_generic_reloc, /* special_function */
"R_LM32_16", /* name */
- FALSE, /* partial_inplace */
+ false, /* partial_inplace */
0, /* src_mask */
0xffff, /* dst_mask */
- FALSE), /* pcrel_offset */
+ false), /* pcrel_offset */
/* A 32 bit absolute relocation. */
HOWTO (R_LM32_32, /* type */
0, /* rightshift */
2, /* size (0 = byte, 1 = short, 2 = long) */
32, /* bitsize */
- FALSE, /* pc_relative */
+ false, /* pc_relative */
0, /* bitpos */
complain_overflow_bitfield,/* complain_on_overflow */
bfd_elf_generic_reloc, /* special_function */
"R_LM32_32", /* name */
- FALSE, /* partial_inplace */
+ false, /* partial_inplace */
0, /* src_mask */
0xffffffff, /* dst_mask */
- FALSE), /* pcrel_offset */
+ false), /* pcrel_offset */
HOWTO (R_LM32_HI16, /* type */
16, /* rightshift */
2, /* size (0 = byte, 1 = short, 2 = long) */
16, /* bitsize */
- FALSE, /* pc_relative */
+ false, /* pc_relative */
0, /* bitpos */
complain_overflow_bitfield,/* complain_on_overflow */
bfd_elf_generic_reloc, /* special_function */
"R_LM32_HI16", /* name */
- FALSE, /* partial_inplace */
+ false, /* partial_inplace */
0, /* src_mask */
0xffff, /* dst_mask */
- FALSE), /* pcrel_offset */
+ false), /* pcrel_offset */
HOWTO (R_LM32_LO16, /* type */
0, /* rightshift */
2, /* size (0 = byte, 1 = short, 2 = long) */
16, /* bitsize */
- FALSE, /* pc_relative */
+ false, /* pc_relative */
0, /* bitpos */
complain_overflow_dont, /* complain_on_overflow */
bfd_elf_generic_reloc, /* special_function */
"R_LM32_LO16", /* name */
- FALSE, /* partial_inplace */
+ false, /* partial_inplace */
0, /* src_mask */
0xffff, /* dst_mask */
- FALSE), /* pcrel_offset */
+ false), /* pcrel_offset */
HOWTO (R_LM32_GPREL16, /* type */
0, /* rightshift */
2, /* size (0 = byte, 1 = short, 2 = long) */
16, /* bitsize */
- FALSE, /* pc_relative */
+ false, /* pc_relative */
0, /* bitpos */
complain_overflow_dont, /* complain_on_overflow */
lm32_elf_gprel_reloc, /* special_function */
"R_LM32_GPREL16", /* name */
- FALSE, /* partial_inplace */
+ false, /* partial_inplace */
0, /* src_mask */
0xffff, /* dst_mask */
- FALSE), /* pcrel_offset */
+ false), /* pcrel_offset */
HOWTO (R_LM32_CALL, /* type */
2, /* rightshift */
2, /* size (0 = byte, 1 = short, 2 = long) */
26, /* bitsize */
- TRUE, /* pc_relative */
+ true, /* pc_relative */
0, /* bitpos */
complain_overflow_signed, /* complain_on_overflow */
bfd_elf_generic_reloc, /* special_function */
"R_LM32_CALL", /* name */
- FALSE, /* partial_inplace */
+ false, /* partial_inplace */
0, /* src_mask */
0x3ffffff, /* dst_mask */
- TRUE), /* pcrel_offset */
+ true), /* pcrel_offset */
HOWTO (R_LM32_BRANCH, /* type */
2, /* rightshift */
2, /* size (0 = byte, 1 = short, 2 = long) */
16, /* bitsize */
- TRUE, /* pc_relative */
+ true, /* pc_relative */
0, /* bitpos */
complain_overflow_signed, /* complain_on_overflow */
bfd_elf_generic_reloc, /* special_function */
"R_LM32_BRANCH", /* name */
- FALSE, /* partial_inplace */
+ false, /* partial_inplace */
0, /* src_mask */
0xffff, /* dst_mask */
- TRUE), /* pcrel_offset */
+ true), /* pcrel_offset */
/* GNU extension to record C++ vtable hierarchy. */
HOWTO (R_LM32_GNU_VTINHERIT, /* type */
0, /* rightshift */
2, /* size (0 = byte, 1 = short, 2 = long) */
0, /* bitsize */
- FALSE, /* pc_relative */
+ false, /* pc_relative */
0, /* bitpos */
complain_overflow_dont, /* complain_on_overflow */
NULL, /* special_function */
"R_LM32_GNU_VTINHERIT", /* name */
- FALSE, /* partial_inplace */
+ false, /* partial_inplace */
0, /* src_mask */
0, /* dst_mask */
- FALSE), /* pcrel_offset */
+ false), /* pcrel_offset */
/* GNU extension to record C++ vtable member usage. */
HOWTO (R_LM32_GNU_VTENTRY, /* type */
0, /* rightshift */
2, /* size (0 = byte, 1 = short, 2 = long) */
0, /* bitsize */
- FALSE, /* pc_relative */
+ false, /* pc_relative */
0, /* bitpos */
complain_overflow_dont, /* complain_on_overflow */
_bfd_elf_rel_vtable_reloc_fn,/* special_function */
"R_LM32_GNU_VTENTRY", /* name */
- FALSE, /* partial_inplace */
+ false, /* partial_inplace */
0, /* src_mask */
0, /* dst_mask */
- FALSE), /* pcrel_offset */
+ false), /* pcrel_offset */
HOWTO (R_LM32_16_GOT, /* type */
0, /* rightshift */
2, /* size (0 = byte, 1 = short, 2 = long) */
16, /* bitsize */
- FALSE, /* pc_relative */
+ false, /* pc_relative */
0, /* bitpos */
complain_overflow_signed, /* complain_on_overflow */
bfd_elf_generic_reloc, /* special_function */
"R_LM32_16_GOT", /* name */
- FALSE, /* partial_inplace */
+ false, /* partial_inplace */
0, /* src_mask */
0xffff, /* dst_mask */
- FALSE), /* pcrel_offset */
+ false), /* pcrel_offset */
HOWTO (R_LM32_GOTOFF_HI16, /* type */
16, /* rightshift */
2, /* size (0 = byte, 1 = short, 2 = long) */
16, /* bitsize */
- FALSE, /* pc_relative */
+ false, /* pc_relative */
0, /* bitpos */
complain_overflow_dont, /* complain_on_overflow */
bfd_elf_generic_reloc, /* special_function */
"R_LM32_GOTOFF_HI16", /* name */
- FALSE, /* partial_inplace */
+ false, /* partial_inplace */
0xffff, /* src_mask */
0xffff, /* dst_mask */
- FALSE), /* pcrel_offset */
+ false), /* pcrel_offset */
HOWTO (R_LM32_GOTOFF_LO16, /* type */
0, /* rightshift */
2, /* size (0 = byte, 1 = short, 2 = long) */
16, /* bitsize */
- FALSE, /* pc_relative */
+ false, /* pc_relative */
0, /* bitpos */
complain_overflow_dont, /* complain_on_overflow */
bfd_elf_generic_reloc, /* special_function */
"R_LM32_GOTOFF_LO16", /* name */
- FALSE, /* partial_inplace */
+ false, /* partial_inplace */
0xffff, /* src_mask */
0xffff, /* dst_mask */
- FALSE), /* pcrel_offset */
+ false), /* pcrel_offset */
HOWTO (R_LM32_COPY, /* type */
0, /* rightshift */
2, /* size (0 = byte, 1 = short, 2 = long) */
32, /* bitsize */
- FALSE, /* pc_relative */
+ false, /* pc_relative */
0, /* bitpos */
complain_overflow_bitfield, /* complain_on_overflow */
bfd_elf_generic_reloc, /* special_function */
"R_LM32_COPY", /* name */
- FALSE, /* partial_inplace */
+ false, /* partial_inplace */
0xffffffff, /* src_mask */
0xffffffff, /* dst_mask */
- FALSE), /* pcrel_offset */
+ false), /* pcrel_offset */
HOWTO (R_LM32_GLOB_DAT, /* type */
0, /* rightshift */
2, /* size (0 = byte, 1 = short, 2 = long) */
32, /* bitsize */
- FALSE, /* pc_relative */
+ false, /* pc_relative */
0, /* bitpos */
complain_overflow_bitfield, /* complain_on_overflow */
bfd_elf_generic_reloc, /* special_function */
"R_LM32_GLOB_DAT", /* name */
- FALSE, /* partial_inplace */
+ false, /* partial_inplace */
0xffffffff, /* src_mask */
0xffffffff, /* dst_mask */
- FALSE), /* pcrel_offset */
+ false), /* pcrel_offset */
HOWTO (R_LM32_JMP_SLOT, /* type */
0, /* rightshift */
2, /* size (0 = byte, 1 = short, 2 = long) */
32, /* bitsize */
- FALSE, /* pc_relative */
+ false, /* pc_relative */
0, /* bitpos */
complain_overflow_bitfield, /* complain_on_overflow */
bfd_elf_generic_reloc, /* special_function */
"R_LM32_JMP_SLOT", /* name */
- FALSE, /* partial_inplace */
+ false, /* partial_inplace */
0xffffffff, /* src_mask */
0xffffffff, /* dst_mask */
- FALSE), /* pcrel_offset */
+ false), /* pcrel_offset */
HOWTO (R_LM32_RELATIVE, /* type */
0, /* rightshift */
2, /* size (0 = byte, 1 = short, 2 = long) */
32, /* bitsize */
- FALSE, /* pc_relative */
+ false, /* pc_relative */
0, /* bitpos */
complain_overflow_bitfield, /* complain_on_overflow */
bfd_elf_generic_reloc, /* special_function */
"R_LM32_RELATIVE", /* name */
- FALSE, /* partial_inplace */
+ false, /* partial_inplace */
0xffffffff, /* src_mask */
0xffffffff, /* dst_mask */
- FALSE), /* pcrel_offset */
+ false), /* pcrel_offset */
};
/* Set the howto pointer for an Lattice Mico32 ELF reloc. */
-static void
-lm32_info_to_howto_rela (bfd *abfd ATTRIBUTE_UNUSED,
+static bool
+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 (_("%pB: 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. */
-static bfd_boolean
+static bool
lm32_elf_object_p (bfd *abfd)
{
return bfd_default_set_arch_mach (abfd, bfd_arch_lm32, bfd_mach_lm32);
/* 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 bool
+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
dangerous relocation. */
-static bfd_boolean
+static bool
lm32_elf_assign_gp (bfd *output_bfd, bfd_vma *pgp)
{
unsigned int count;
/* If we've already figured out what GP will be, just return it. */
*pgp = _bfd_get_gp_value (output_bfd);
if (*pgp)
- return TRUE;
+ return true;
count = bfd_get_symcount (output_bfd);
sym = bfd_get_outsymbols (output_bfd);
/* Only get the error once. */
*pgp = 4;
_bfd_set_gp_value (output_bfd, *pgp);
- return FALSE;
+ return false;
}
- return TRUE;
+ return true;
}
/* We have to figure out the gp value, so that we can adjust the
external symbol if we are producing relocatable output. */
static bfd_reloc_status_type
-lm32_elf_final_gp (bfd *output_bfd, asymbol *symbol, bfd_boolean relocatable,
+lm32_elf_final_gp (bfd *output_bfd, asymbol *symbol, bool relocatable,
char **error_message, bfd_vma *pgp)
{
if (bfd_is_und_section (symbol->section) && !relocatable)
+ symbol->section->output_section->vma + symbol->section->output_offset;
if ((r =
- lm32_elf_final_gp (abfd, symbol, FALSE, msg, &gp)) == bfd_reloc_ok)
+ lm32_elf_final_gp (abfd, symbol, false, msg, &gp)) == bfd_reloc_ok)
{
relocation = relocation + reloc_entry->addend - gp;
reloc_entry->addend = 0;
/* Determine if an output section is read-only. */
-inline static bfd_boolean
+inline static bool
_lm32fdpic_osec_readonly_p (bfd *output_bfd, asection *osec)
{
unsigned seg = _lm32fdpic_osec_to_segment (output_bfd, osec);
/* Relocate a section */
-static bfd_boolean
+static int
lm32_elf_relocate_section (bfd *output_bfd,
struct bfd_link_info *info,
bfd *input_bfd,
asection *sgot;
if (htab == NULL)
- return FALSE;
+ return false;
local_got_offsets = elf_local_got_offsets (input_bfd);
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
{
/* It's a global symbol. */
- bfd_boolean unresolved_reloc;
- bfd_boolean warned, ignored;
+ bool unresolved_reloc;
+ bool warned, ignored;
RELOC_FOR_GLOBAL_SYMBOL (info, input_bfd, input_section, rel,
r_symndx, symtab_hdr, sym_hashes,
BFD_ASSERT (sgot != NULL);
if (h != NULL)
{
- bfd_boolean dyn;
+ bool dyn;
bfd_vma off;
off = h->got.offset;
/* 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))
{
(info,
_("cannot emit dynamic relocations in read-only section"),
name, input_bfd, input_section, rel->r_offset);
- return FALSE;
+ return false;
}
/* Create entry in .rofixup section. */
_lm32fdpic_add_rofixup (output_bfd,
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)
case bfd_reloc_undefined:
(*info->callbacks->undefined_symbol)
- (info, name, input_bfd, input_section, rel->r_offset, TRUE);
+ (info, name, input_bfd, input_section, rel->r_offset, true);
break;
case bfd_reloc_outofrange:
}
}
- return TRUE;
+ return true;
}
static asection *
/* Look through the relocs for a section during the first phase. */
-static bfd_boolean
+static bool
lm32_elf_check_relocs (bfd *abfd,
struct bfd_link_info *info,
asection *sec,
bfd *dynobj;
if (bfd_link_relocatable (info))
- return TRUE;
-
- /* Don't do anything special with non-loaded, non-alloced sections.
- In particular, any relocs in such sections should not affect GOT
- and PLT reference counting (ie. we don't allow them to create GOT
- or PLT entries), there's no possibility or desire to optimize TLS
- relocs, and there's not much point in propagating relocs to shared
- libs that the dynamic linker won't relocate. */
- if ((sec->flags & SEC_ALLOC) == 0)
- return TRUE;
+ return true;
symtab_hdr = &elf_tdata (abfd)->symtab_hdr;
sym_hashes = elf_sym_hashes (abfd);
htab = lm32_elf_hash_table (info);
if (htab == NULL)
- return FALSE;
+ return false;
dynobj = htab->root.dynobj;
if (dynobj == NULL)
htab->root.dynobj = dynobj = abfd;
if (!_bfd_elf_create_got_section (dynobj, info))
- return FALSE;
+ return false;
break;
}
}
if (dynobj == NULL)
htab->root.dynobj = dynobj = abfd;
if (!_bfd_elf_create_got_section (dynobj, info))
- return FALSE;
+ return false;
/* Create .rofixup section */
if (htab->sfixup32 == NULL)
{
if (! create_rofixup_section (dynobj, info))
- return FALSE;
+ return false;
}
break;
case R_LM32_16_GOT:
if (dynobj == NULL)
htab->root.dynobj = dynobj = abfd;
if (! create_rofixup_section (dynobj, info))
- return FALSE;
+ return false;
}
break;
}
size *= sizeof (bfd_signed_vma);
local_got_refcounts = bfd_zalloc (abfd, size);
if (local_got_refcounts == NULL)
- return FALSE;
+ return false;
elf_local_got_refcounts (abfd) = local_got_refcounts;
}
local_got_refcounts[r_symndx] += 1;
Reconstruct it for later use during GC. */
case R_LM32_GNU_VTINHERIT:
if (!bfd_elf_gc_record_vtinherit (abfd, sec, h, rel->r_offset))
- return FALSE;
+ return false;
break;
/* This relocation describes which C++ vtable entries are actually
used. Record for later use during GC. */
case R_LM32_GNU_VTENTRY:
if (!bfd_elf_gc_record_vtentry (abfd, sec, h, rel->r_addend))
- return FALSE;
+ return false;
break;
}
}
- return TRUE;
+ return true;
}
/* Finish up the dynamic sections. */
-static bfd_boolean
+static bool
lm32_elf_finish_dynamic_sections (bfd *output_bfd,
struct bfd_link_info *info)
{
htab = lm32_elf_hash_table (info);
if (htab == NULL)
- return FALSE;
+ return false;
dynobj = htab->root.dynobj;
!= (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;
+ return false;
}
hend = bfd_link_hash_lookup (info->hash, "__ROFIXUP_END__",
- FALSE, FALSE, TRUE);
+ 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);
- return FALSE;
+ ("LINKER BUG: .rofixup section hend->u.def.value != value: %"
+ PRId64 " != %" PRId64,
+ (int64_t) hend->u.def.value, (int64_t) value);
+ return false;
}
}
}
- return TRUE;
+ return true;
}
/* Finish up dynamic symbol handling. We set the contents of various
dynamic sections here. */
-static bfd_boolean
+static bool
lm32_elf_finish_dynamic_symbol (bfd *output_bfd,
struct bfd_link_info *info,
struct elf_link_hash_entry *h,
htab = lm32_elf_hash_table (info);
if (htab == NULL)
- return FALSE;
+ return false;
if (h->plt.offset != (bfd_vma) -1)
{
if (h == htab->root.hdynamic || h == htab->root.hgot)
sym->st_shndx = SHN_ABS;
- return TRUE;
+ return true;
}
static enum elf_reloc_type_class
}
}
-/* 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
change the definition to something the rest of the link can
understand. */
-static bfd_boolean
+static bool
lm32_elf_adjust_dynamic_symbol (struct bfd_link_info *info,
struct elf_link_hash_entry *h)
{
h->needs_plt = 0;
}
- return TRUE;
+ return true;
}
else
h->plt.offset = (bfd_vma) -1;
BFD_ASSERT (def->root.type == bfd_link_hash_defined);
h->root.u.def.section = def->root.u.def.section;
h->root.u.def.value = def->root.u.def.value;
- return TRUE;
+ return true;
}
/* This is a reference to a symbol defined by a dynamic object which
For such cases we need not do anything here; the relocations will
be handled correctly by relocate_section. */
if (bfd_link_pic (info))
- return TRUE;
+ return true;
/* If there are no references to this symbol that do not use the
GOT, we don't need to generate a copy reloc. */
if (!h->non_got_ref)
- return TRUE;
+ return true;
/* If -z nocopyreloc was given, we won't generate them either. */
if (0 && info->nocopyreloc)
{
h->non_got_ref = 0;
- return TRUE;
+ return true;
}
/* 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;
+ return true;
}
/* We must allocate the symbol in our .dynbss section, which will
htab = lm32_elf_hash_table (info);
if (htab == NULL)
- return FALSE;
+ return false;
s = htab->sdynbss;
BFD_ASSERT (s != NULL);
/* Allocate space in .plt, .got and associated reloc sections for
dynamic relocs. */
-static bfd_boolean
+static bool
allocate_dynrelocs (struct elf_link_hash_entry *h, void * inf)
{
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)
- return TRUE;
+ return true;
info = (struct bfd_link_info *) inf;
htab = lm32_elf_hash_table (info);
if (htab == NULL)
- return FALSE;
-
- eh = (struct elf_lm32_link_hash_entry *) h;
+ return false;
if (htab->root.dynamic_sections_created
&& h->plt.refcount > 0)
&& !h->forced_local)
{
if (! bfd_elf_link_record_dynamic_symbol (info, h))
- return FALSE;
+ return false;
}
if (WILL_CALL_FINISH_DYNAMIC_SYMBOL (1, bfd_link_pic (info), h))
if (h->got.refcount > 0)
{
asection *s;
- bfd_boolean dyn;
+ bool dyn;
/* Make sure this symbol is output as a dynamic symbol.
Undefined weak syms won't yet be marked as dynamic. */
&& !h->forced_local)
{
if (! bfd_elf_link_record_dynamic_symbol (info, h))
- return FALSE;
+ return false;
}
s = htab->root.sgot;
else
h->got.offset = (bfd_vma) -1;
- if (eh->dyn_relocs == NULL)
- return TRUE;
+ if (h->dyn_relocs == NULL)
+ return true;
/* In the shared -Bsymbolic case, discard space allocated for
dynamic pc-relative relocs against symbols which turn out to be
{
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. */
&& !h->forced_local)
{
if (! bfd_elf_link_record_dynamic_symbol (info, h))
- return FALSE;
+ return false;
}
}
}
&& !h->forced_local)
{
if (! bfd_elf_link_record_dynamic_symbol (info, h))
- return FALSE;
+ return false;
}
/* If that succeeded, we know we'll be keeping all the
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
- (_("%pB: dynamic relocation against `%T' in read-only section `%pA'\n"),
- sec->owner, h->root.root.string, sec);
-
- /* Not an error, just cut short the traversal. */
- return FALSE;
- }
- return TRUE;
+ return true;
}
/* Set the sizes of the dynamic sections. */
-static bfd_boolean
+static bool
lm32_elf_size_dynamic_sections (bfd *output_bfd,
struct bfd_link_info *info)
{
struct elf_lm32_link_hash_table *htab;
bfd *dynobj;
asection *s;
- bfd_boolean relocs;
+ bool relocs;
bfd *ibfd;
htab = lm32_elf_hash_table (info);
if (htab == NULL)
- return FALSE;
+ return false;
dynobj = htab->root.dynobj;
BFD_ASSERT (dynobj != NULL);
/* We now have determined the sizes of the various dynamic sections.
Allocate memory for them. */
- relocs = FALSE;
+ relocs = false;
for (s = dynobj->sections; s != NULL; s = s->next)
{
if ((s->flags & SEC_LINKER_CREATED) == 0)
/* 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 (startswith (bfd_section_name (s), ".rela"))
{
if (s->size != 0 && s != htab->root.srelplt)
- relocs = TRUE;
+ relocs = true;
/* We use the reloc_count field as a counter if we need
to copy relocs into the output file. */
of garbage. */
s->contents = bfd_zalloc (dynobj, s->size);
if (s->contents == NULL)
- return FALSE;
+ return false;
}
- if (htab->root.dynamic_sections_created)
- {
- /* Add some entries to the .dynamic section. We fill in the
- values later, in lm32_elf_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_executable (info))
- {
- if (! add_dynamic_entry (DT_DEBUG, 0))
- return FALSE;
- }
-
- if (htab->root.splt->size != 0)
- {
- 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 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);
-
- if ((info->flags & DF_TEXTREL) != 0)
- {
- if (! add_dynamic_entry (DT_TEXTREL, 0))
- return FALSE;
- }
- }
- }
-#undef add_dynamic_entry
+ if (!_bfd_elf_add_dynamic_tags (output_bfd, info, relocs))
+ return false;
/* Allocate .rofixup section. */
if (IS_FDPIC (output_bfd))
Elf_Internal_Rela *internal_relocs, *end;
internal_relocs = elf_section_data (s)->relocs;
if (internal_relocs == NULL)
- internal_relocs = (_bfd_elf_link_read_relocs (ibfd, s, NULL, NULL, FALSE));
+ internal_relocs = (_bfd_elf_link_read_relocs (ibfd, s, NULL, NULL, false));
if (internal_relocs != NULL)
{
end = internal_relocs + s->reloc_count;
/* 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)
/* Create a new entry. */
new_entry = malloc (sizeof (struct weak_symbol_list));
if (!new_entry)
- return FALSE;
+ return false;
new_entry->name = h->root.root.string;
new_entry->next = NULL;
/* Add to list */
}
}
else
- return FALSE;
+ return false;
}
}
}
lm32fdpic_fixup32_section (info)->contents =
bfd_zalloc (dynobj, lm32fdpic_fixup32_section (info)->size);
if (lm32fdpic_fixup32_section (info)->contents == NULL)
- return FALSE;
+ return false;
}
}
- return TRUE;
+ return true;
}
/* Create dynamic sections when linking against a dynamic object. */
-static bfd_boolean
+static bool
lm32_elf_create_dynamic_sections (bfd *abfd, struct bfd_link_info *info)
{
struct elf_lm32_link_hash_table *htab;
htab = lm32_elf_hash_table (info);
if (htab == NULL)
- return FALSE;
+ return false;
/* Make sure we have a GOT - For the case where we have a dynamic object
but none of the relocs in check_relocs */
if (!_bfd_elf_create_got_section (abfd, info))
- return FALSE;
+ return false;
if (IS_FDPIC (abfd) && (htab->sfixup32 == NULL))
{
if (! create_rofixup_section (abfd, info))
- return FALSE;
+ return false;
}
/* We need to create .plt, .rel[a].plt, .got, .got.plt, .dynbss, and
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))
- return FALSE;
+ || !bfd_set_section_alignment (s, bed->plt_alignment))
+ return false;
if (bed->want_plt_sym)
{
if (! (_bfd_generic_link_add_one_symbol
(info, abfd, "_PROCEDURE_LINKAGE_TABLE_", BSF_GLOBAL, s,
- (bfd_vma) 0, NULL, FALSE,
+ (bfd_vma) 0, NULL, false,
get_elf_backend_data (abfd)->collect, &bh)))
- return FALSE;
+ return false;
h = (struct elf_link_hash_entry *) bh;
h->def_regular = 1;
h->type = STT_OBJECT;
if (bfd_link_pic (info)
&& ! bfd_elf_link_record_dynamic_symbol (info, h))
- return FALSE;
+ return false;
}
s = bfd_make_section_anyway_with_flags (abfd,
flags | SEC_READONLY);
htab->root.srelplt = s;
if (s == NULL
- || ! bfd_set_section_alignment (abfd, s, ptralign))
- return FALSE;
+ || !bfd_set_section_alignment (s, ptralign))
+ return false;
if (htab->root.sgot == NULL
&& !_bfd_elf_create_got_section (abfd, info))
- return FALSE;
+ return false;
if (bed->want_dynbss)
{
SEC_ALLOC | SEC_LINKER_CREATED);
htab->sdynbss = s;
if (s == NULL)
- return FALSE;
+ return false;
/* The .rel[a].bss section holds copy relocs. This section is not
normally needed. We need to create it here, though, so that the
linker will map it to an output section. We can't just create it
flags | SEC_READONLY);
htab->srelbss = s;
if (s == NULL
- || ! bfd_set_section_alignment (abfd, s, ptralign))
- return FALSE;
+ || !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);
+ return true;
}
-static bfd_boolean
+static bool
lm32_elf_always_size_sections (bfd *output_bfd, struct bfd_link_info *info)
{
if (!bfd_link_relocatable (info))
{
if (!bfd_elf_stack_segment_size (output_bfd, info,
"__stacksize", DEFAULT_STACK_SIZE))
- return FALSE;
+ return false;
asection *sec = bfd_get_section_by_name (output_bfd, ".stack");
if (sec)
sec->size = info->stacksize >= 0 ? info->stacksize : 0;
}
- return TRUE;
+ return true;
}
-static bfd_boolean
+static bool
lm32_elf_fdpic_copy_private_bfd_data (bfd *ibfd, bfd *obfd)
{
unsigned i;
if (bfd_get_flavour (ibfd) != bfd_target_elf_flavour
|| bfd_get_flavour (obfd) != bfd_target_elf_flavour)
- return TRUE;
+ return true;
if (! _bfd_elf_copy_private_bfd_data (ibfd, obfd))
- return FALSE;
+ return false;
if (! elf_tdata (ibfd) || ! elf_tdata (ibfd)->phdr
|| ! elf_tdata (obfd) || ! elf_tdata (obfd)->phdr)
- return TRUE;
+ return true;
/* Copy the stack size. */
for (i = 0; i < elf_elfheader (ibfd)->e_phnum; i++)
->s->sizeof_ehdr, SEEK_SET) != 0
|| get_elf_backend_data (obfd)->s->write_out_phdrs (obfd, elf_tdata (obfd)->phdr,
elf_elfheader (obfd)->e_phnum) != 0)
- return FALSE;
+ return false;
break;
}
break;
}
- return TRUE;
+ return true;
}
#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_elf_omit_section_dynsym_all
#define elf_backend_create_dynamic_sections lm32_elf_create_dynamic_sections