From 6f6fd151cbf226bbaa66e44977f57b7c6dc33d89 Mon Sep 17 00:00:00 2001 From: "H.J. Lu" Date: Tue, 21 Apr 2020 05:23:51 -0700 Subject: elf: Strip zero-sized dynamic sections ELF size_dynamic_sections is called by the ELF backend linker after all the linker input files have been seen but before the section sizes have been set. After the sections sizes have been set, target-specific, global optimizations may make some dynamic sections zero-sized if they are no longer needed. Add ELF strip_zero_sized_dynamic_sections so that ELF backend linker can strip zero-sized dynamic sections after the sections sizes have been set. bfd/ PR ld/25849 * elf-bfd.h (elf_backend_data): Add elf_backend_strip_zero_sized_dynamic_sections. (_bfd_elf_strip_zero_sized_dynamic_sections): New prototype. * elf64-alpha.c (elf_backend_strip_zero_sized_dynamic_sections): New macro. * elflink.c (_bfd_elf_strip_zero_sized_dynamic_sections): New function. * elfxx-target.h (elf_backend_strip_zero_sized_dynamic_sections): New macro. (elfNN_bed): Add elf_backend_strip_zero_sized_dynamic_sections. ld/ PR ld/25849 * ldelfgen.c (ldelf_map_segments): Call elf_backend_strip_zero_sized_dynamic_sections. * testsuite/ld-alpha/tlsbinr.rd: Updated. --- bfd/elf-bfd.h | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'bfd/elf-bfd.h') diff --git a/bfd/elf-bfd.h b/bfd/elf-bfd.h index b08502c..3ae9842 100644 --- a/bfd/elf-bfd.h +++ b/bfd/elf-bfd.h @@ -1083,6 +1083,12 @@ struct elf_backend_data bfd_boolean (*elf_backend_size_dynamic_sections) (bfd *output_bfd, struct bfd_link_info *info); + /* The STRIP_ZERO_SIZED_DYNAMIC_SECTIONS function is called by the + ELF backend linker to strip zero-sized dynamic sections after + the section sizes have been set. */ + bfd_boolean (*elf_backend_strip_zero_sized_dynamic_sections) + (struct bfd_link_info *info); + /* Set TEXT_INDEX_SECTION and DATA_INDEX_SECTION, the output sections we keep to use as a base for relocs and symbols. */ void (*elf_backend_init_index_section) @@ -2520,6 +2526,8 @@ extern bfd_boolean bfd_elf_link_add_symbols (bfd *, struct bfd_link_info *); extern bfd_boolean _bfd_elf_add_dynamic_entry (struct bfd_link_info *, bfd_vma, bfd_vma); +extern bfd_boolean _bfd_elf_strip_zero_sized_dynamic_sections + (struct bfd_link_info *); extern int bfd_elf_add_dt_needed_tag (bfd *, struct bfd_link_info *); extern bfd_boolean _bfd_elf_link_check_relocs -- cgit v1.1