diff options
author | Jon Turney <jon.turney@dronecode.org.uk> | 2015-03-18 15:47:13 +0000 |
---|---|---|
committer | Nick Clifton <nickc@redhat.com> | 2015-03-18 15:47:13 +0000 |
commit | 273a49858fa9c8d73de87167618ef99d70f9731a (patch) | |
tree | f003dbb576f1e259d8a68250ba039550f6608fee /bfd | |
parent | 670f82d437c21ec9c8f59a365336163e0381149d (diff) | |
download | fsf-binutils-gdb-273a49858fa9c8d73de87167618ef99d70f9731a.zip fsf-binutils-gdb-273a49858fa9c8d73de87167618ef99d70f9731a.tar.gz fsf-binutils-gdb-273a49858fa9c8d73de87167618ef99d70f9731a.tar.bz2 |
Fix debug section compression so that it is only performed if it would make the section smaller.
PR binutils/18087
gas * doc/as.texinfo: Note that when gas compresses debug sections the
compression is only performed if it makes the section smaller.
* write.c (compress_debug): Do not compress a debug section if
doing so would make it larger.
tests * gas/i386/dw2-compress-1.d: Do not expect the .debug_abbrev or
.debug_info sections to be compressed.
binu * doc/binutils.texi: Note that when objcopy compresses debug
sections the compression is only performed if it makes the section
smaller.
bfd * coffgen.c (make_a_section_from_file): Only prepend a z to a
debug section's name if the section was actually compressed.
* elf.c (_bfd_elf_make_section_from_shdr): Likewise.
* compress.c (bfd_init_section_compress_status): Do not compress
the section if doing so would make it bigger. In such cases leave
the section alone and return COMPRESS_SECTION_NONE.
Diffstat (limited to 'bfd')
-rw-r--r-- | bfd/ChangeLog | 11 | ||||
-rw-r--r-- | bfd/coffgen.c | 21 | ||||
-rw-r--r-- | bfd/compress.c | 13 | ||||
-rw-r--r-- | bfd/elf.c | 24 |
4 files changed, 50 insertions, 19 deletions
diff --git a/bfd/ChangeLog b/bfd/ChangeLog index 9173e17..c5f109e 100644 --- a/bfd/ChangeLog +++ b/bfd/ChangeLog @@ -1,3 +1,14 @@ +2015-03-18 Jon Turney <jon.turney@dronecode.org.uk> + Nick Clifton <nickc@redhat.com> + + PR binutils/18087 + * coffgen.c (make_a_section_from_file): Only prepend a z to a + debug section's name if the section was actually compressed. + * elf.c (_bfd_elf_make_section_from_shdr): Likewise. + * compress.c (bfd_init_section_compress_status): Do not compress + the section if doing so would make it bigger. In such cases leave + the section alone and return COMPRESS_SECTION_NONE. + 2015-03-17 Alan Modra <amodra@gmail.com> * elf64-ppc.c (ppc64_elf_get_synthetic_symtab): Return count of 0 diff --git a/bfd/coffgen.c b/bfd/coffgen.c index 5c664a4..b1ab56e 100644 --- a/bfd/coffgen.c +++ b/bfd/coffgen.c @@ -178,18 +178,21 @@ make_a_section_from_file (bfd *abfd, abfd, name); return FALSE; } - if (name[1] != 'z') + if (return_section->compress_status == COMPRESS_SECTION_DONE) { - unsigned int len = strlen (name); + if (name[1] != 'z') + { + unsigned int len = strlen (name); - new_name = bfd_alloc (abfd, len + 2); - if (new_name == NULL) - return FALSE; - new_name[0] = '.'; - new_name[1] = 'z'; - memcpy (new_name + 2, name + 1, len); + new_name = bfd_alloc (abfd, len + 2); + if (new_name == NULL) + return FALSE; + new_name[0] = '.'; + new_name[1] = 'z'; + memcpy (new_name + 2, name + 1, len); + } } - break; + break; case decompress: if (!bfd_init_section_decompress_status (abfd, return_section)) { diff --git a/bfd/compress.c b/bfd/compress.c index 0087a66..ad1fbee 100644 --- a/bfd/compress.c +++ b/bfd/compress.c @@ -441,7 +441,18 @@ bfd_init_section_compress_status (bfd *abfd ATTRIBUTE_UNUSED, uncompressed_buffer, uncompressed_size); - free (uncompressed_buffer); + /* PR binutils/18087: If compression didn't make + the section smaller, just keep it uncompressed. */ + if (ret && uncompressed_size < sec->size) + { + free (sec->contents); + sec->contents = uncompressed_buffer; + sec->size = uncompressed_size; + sec->compress_status = COMPRESS_SECTION_NONE; + } + else + free (uncompressed_buffer); + return ret; #endif } @@ -1069,16 +1069,22 @@ _bfd_elf_make_section_from_shdr (bfd *abfd, abfd, name); return FALSE; } - if (name[1] != 'z') + /* PR binutils/18087: Compression does not always make a section + smaller. So only rename the section when compression has + actually taken place. */ + if (newsect->compress_status == COMPRESS_SECTION_DONE) { - unsigned int len = strlen (name); - - new_name = bfd_alloc (abfd, len + 2); - if (new_name == NULL) - return FALSE; - new_name[0] = '.'; - new_name[1] = 'z'; - memcpy (new_name + 2, name + 1, len); + if (name[1] != 'z') + { + unsigned int len = strlen (name); + + new_name = bfd_alloc (abfd, len + 2); + if (new_name == NULL) + return FALSE; + new_name[0] = '.'; + new_name[1] = 'z'; + memcpy (new_name + 2, name + 1, len); + } } break; case decompress: |