summaryrefslogtreecommitdiff
path: root/bfd/compress.c
diff options
context:
space:
mode:
authorH.J. Lu <hjl.tools@gmail.com>2015-04-23 16:37:44 -0700
committerH.J. Lu <hjl.tools@gmail.com>2015-04-23 16:37:56 -0700
commit3e19fb8f990e4ce8a08f9cf2817cd9e9398648d5 (patch)
tree9e22ba6ecd1bc3533550524049c4fbde9ae57331 /bfd/compress.c
parentece794d9c43addc2a347c01f5cd753b9171d028a (diff)
downloadbinutils-gdb-3e19fb8f990e4ce8a08f9cf2817cd9e9398648d5.tar.gz
Delay setting up compressed debug section names
When we set up st_name for output section name in elf_fake_sections, we don't know if the compressed DWARF debug section will be smaller. We may end up with compressed DWARF debug sections which are bigger than the uncompressed ones. This patch delays setting up st_name for output DWARF debug section to _bfd_elf_assign_file_positions_for_non_load which will compress the output debug section. We also postpone placement of shstrtab section after DWARF debug sections have been compressed. The net effect is .shstrtab section is now placed after .symtab and .strtab sections. bfd/ PR ld/18277 * compress.c (bfd_compress_section_contents): Remove the write_compress argument. (bfd_init_section_compress_status): Updated. (bfd_compress_section): Likewise. * elf.c (_bfd_elf_set_reloc_sh_name): New. (_bfd_elf_init_reloc_shdr): Add delay_st_name_p. Set sh_name to (unsigned int) -1 if delay_st_name_p is TRUE. Use _bfd_elf_set_reloc_sh_name. (elf_fake_sections): Don't rename DWARF debug section for linker output if it will be compressed. Instead, set delay_st_name_p to TRUE and pass it to _bfd_elf_init_reloc_shdr. (assign_section_numbers): Call _bfd_elf_strtab_addref only if sh_name != (unsigned int) -1. Don't finalize nor assign shstrtab section here. Delay setting output section names to _bfd_elf_write_object_contents. (_bfd_elf_compute_section_file_positions): Update comments on sh_offset for shstrtab section. (assign_file_positions_for_non_load_sections): Set sh_offset to -1 for shstrtab section. (assign_file_positions_except_relocs): Likewise. (_bfd_elf_assign_file_positions_for_non_load): Set up sh_name when compressing DWARF debug sections. Place shstrtab section after DWARF debug sections have been compressed. (_bfd_elf_write_object_contents): Setting sh_name for output sections. ld/testsuite/ PR ld/18277 * ld-elf/compressed1d.d: New. * ld-elf/compressed1e.d: Likewise.
Diffstat (limited to 'bfd/compress.c')
-rw-r--r--bfd/compress.c15
1 files changed, 5 insertions, 10 deletions
diff --git a/bfd/compress.c b/bfd/compress.c
index dfde50e81c6..d0f745fe6e1 100644
--- a/bfd/compress.c
+++ b/bfd/compress.c
@@ -72,8 +72,7 @@ decompress_contents (bfd_byte *compressed_buffer,
static bfd_size_type
bfd_compress_section_contents (bfd *abfd, sec_ptr sec,
bfd_byte *uncompressed_buffer,
- bfd_size_type uncompressed_size,
- bfd_boolean write_compress)
+ bfd_size_type uncompressed_size)
{
uLong compressed_size;
bfd_byte *buffer;
@@ -177,11 +176,8 @@ bfd_compress_section_contents (bfd *abfd, sec_ptr sec,
compressed_size += header_size;
/* PR binutils/18087: If compression didn't make the section smaller,
- just keep it uncompressed. We always generate .zdebug_* section
- when linking since section names have been finalized and they
- can't be changed easily. */
- if ((write_compress && compression_header_size == 0)
- || compressed_size < uncompressed_size)
+ just keep it uncompressed. */
+ if (compressed_size < uncompressed_size)
{
bfd_update_compression_header (abfd, buffer, sec);
@@ -547,8 +543,7 @@ bfd_init_section_compress_status (bfd *abfd, sec_ptr sec)
{
uncompressed_size = bfd_compress_section_contents (abfd, sec,
uncompressed_buffer,
- uncompressed_size,
- FALSE);
+ uncompressed_size);
ret = uncompressed_size != 0;
}
@@ -590,5 +585,5 @@ bfd_compress_section (bfd *abfd, sec_ptr sec, bfd_byte *uncompressed_buffer)
/* Compress it. */
return bfd_compress_section_contents (abfd, sec, uncompressed_buffer,
- uncompressed_size, TRUE) != 0;
+ uncompressed_size) != 0;
}