aboutsummaryrefslogtreecommitdiff
path: root/ld/ldelfgen.c
diff options
context:
space:
mode:
authorH.J. Lu <hjl.tools@gmail.com>2020-04-21 05:23:51 -0700
committerH.J. Lu <hjl.tools@gmail.com>2020-04-21 05:24:03 -0700
commit6f6fd151cbf226bbaa66e44977f57b7c6dc33d89 (patch)
tree0ef4a78de35fde84a58c5964f7822a19a95c620c /ld/ldelfgen.c
parent1f7f2abbc31ee9e6d4faca58bef14d8ee8cb1bd2 (diff)
downloadgdb-6f6fd151cbf226bbaa66e44977f57b7c6dc33d89.zip
gdb-6f6fd151cbf226bbaa66e44977f57b7c6dc33d89.tar.gz
gdb-6f6fd151cbf226bbaa66e44977f57b7c6dc33d89.tar.bz2
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.
Diffstat (limited to 'ld/ldelfgen.c')
-rw-r--r--ld/ldelfgen.c13
1 files changed, 13 insertions, 0 deletions
diff --git a/ld/ldelfgen.c b/ld/ldelfgen.c
index 21739b1..c0568f1 100644
--- a/ld/ldelfgen.c
+++ b/ld/ldelfgen.c
@@ -73,6 +73,19 @@ ldelf_map_segments (bfd_boolean need_layout)
if (tries == 0)
einfo (_("%F%P: looping in map_segments"));
+
+ if (link_info.output_bfd->xvec->flavour == bfd_target_elf_flavour
+ && lang_phdr_list == NULL)
+ {
+ /* If we don't have user supplied phdrs, strip zero-sized dynamic
+ sections and regenerate program headers. */
+ const struct elf_backend_data *bed
+ = get_elf_backend_data (link_info.output_bfd);
+ if (bed->elf_backend_strip_zero_sized_dynamic_sections
+ && !bed->elf_backend_strip_zero_sized_dynamic_sections
+ (&link_info))
+ einfo (_("%F%P: failed to strip zero-sized dynamic sections"));
+ }
}
/* We want to emit CTF early if and only if we are not targetting ELF with this