elf: Strip zero-sized dynamic sections
authorH.J. Lu <hjl.tools@gmail.com>
Tue, 21 Apr 2020 12:23:51 +0000 (05:23 -0700)
committerH.J. Lu <hjl.tools@gmail.com>
Tue, 21 Apr 2020 12:24:03 +0000 (05:24 -0700)
commit6f6fd151cbf226bbaa66e44977f57b7c6dc33d89
tree0ef4a78de35fde84a58c5964f7822a19a95c620c
parent1f7f2abbc31ee9e6d4faca58bef14d8ee8cb1bd2
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/ChangeLog
bfd/elf-bfd.h
bfd/elf64-alpha.c
bfd/elflink.c
bfd/elfxx-target.h
ld/ChangeLog
ld/ldelfgen.c
ld/testsuite/ld-alpha/tlsbinr.rd