Add support for ELF files which contain multiple reloc sections which all target the same section.

* elf-bfd.h (struct elf_backend_data): Add new fields:
	init_secondary_reloc_section, slurp_secondary_reloc_section,
	write_secondary_reloc_section.
	(_bfd_elf_init_secondary_reloc_section): Prototype.
	(_bfd_elf_slurp_secondary_reloc_section): Prototype.
	(_bfd_elf_write_secondary_reloc_section): Prototype.
	* elf.c ( bfd_section_from_shdr): Invoke the new
	init_secondary_reloc_section backend function, if defined, when a
	second reloc section is encountered.
	(swap_out_syms): Invoke the new symbol_section_index function, if
	defined, when computing the section index of an OS/PROC specific
	symbol.
	(_bfd_elf_init_secondary_reloc_section): New function.
	(_bfd_elf_slurp_secondary_reloc_section): New function.
	(_bfd_elf_write_secondary_reloc_section): New function.
	(_bfd_elf_copy_special_section_fields): New function.
	* elfcode.h (elf_write_relocs): Invoke the new
	write_secondary_relocs function, if defined, in order to emit
	secondary relocs.
	(elf_slurp_reloc_table): Invoke the new slurp_secondary_relocs
	function, if defined, in order to read in secondary relocs.
	* elfxx-target.h (elf_backend_copy_special_section_fields):
	Provide a non-NULL default definition.
	(elf_backend_init_secondary_reloc_section): Likewise.
	(elf_backend_slurp_secondary_reloc_section): Likewise.
	(elf_backend_write_secondary_reloc_section): Likewise.
	(struct elf_backend_data elfNN_bed): Add initialisers for the new
	fields.
        * configure.ac (score_elf32_[bl]e_vec): Add elf64.lo
        * configure: Regenerate.
This commit is contained in:
Nick Clifton
2020-03-05 15:47:15 +00:00
parent 842806cb6f
commit a8e14f4cc2
7 changed files with 465 additions and 13 deletions

View File

@ -869,6 +869,7 @@ elf_object_p (bfd *abfd)
void
elf_write_relocs (bfd *abfd, asection *sec, void *data)
{
const struct elf_backend_data * const bed = get_elf_backend_data (abfd);
bfd_boolean *failedp = (bfd_boolean *) data;
Elf_Internal_Shdr *rela_hdr;
bfd_vma addr_offset;
@ -985,6 +986,13 @@ elf_write_relocs (bfd *abfd, asection *sec, void *data)
src_rela.r_addend = ptr->addend;
(*swap_out) (abfd, &src_rela, dst_rela);
}
if (bed->write_secondary_relocs != NULL)
if (! bed->write_secondary_relocs (abfd, sec))
{
*failedp = TRUE;
return;
}
}
/* Write out the program headers. */
@ -1292,7 +1300,10 @@ elf_slurp_symbol_table (bfd *abfd, asymbol **symptrs, bfd_boolean dynamic)
{
/* This symbol is in a section for which we did not
create a BFD section. Just use bfd_abs_section,
although it is wrong. FIXME. */
although it is wrong. FIXME. Note - there is
code in elf.c:swap_out_syms that calls
symbol_section_index() in the elf backend for
cases like this. */
sym->symbol.section = bfd_abs_section_ptr;
}
}
@ -1517,6 +1528,7 @@ elf_slurp_reloc_table (bfd *abfd,
asymbol **symbols,
bfd_boolean dynamic)
{
const struct elf_backend_data * const bed = get_elf_backend_data (abfd);
struct bfd_elf_section_data * const d = elf_section_data (asect);
Elf_Internal_Shdr *rel_hdr;
Elf_Internal_Shdr *rel_hdr2;
@ -1584,6 +1596,10 @@ elf_slurp_reloc_table (bfd *abfd,
symbols, dynamic))
return FALSE;
if (bed->slurp_secondary_relocs != NULL
&& ! bed->slurp_secondary_relocs (abfd, asect, symbols))
return FALSE;
asect->relocation = relents;
return TRUE;
}