aboutsummaryrefslogtreecommitdiff
path: root/binutils/readelf.c
diff options
context:
space:
mode:
authorH.J. Lu <hjl.tools@gmail.com>2015-05-14 15:58:51 -0700
committerH.J. Lu <hjl.tools@gmail.com>2015-05-14 16:02:08 -0700
commitdab394de9e41de54df5e2310e081e1c550326f5b (patch)
treefbdbe4f564baa35e7fb4bea28416a531fcb9d916 /binutils/readelf.c
parent61a7418ccb7c2de12d4c4df79e193f32db938a11 (diff)
downloadgdb-dab394de9e41de54df5e2310e081e1c550326f5b.zip
gdb-dab394de9e41de54df5e2310e081e1c550326f5b.tar.gz
gdb-dab394de9e41de54df5e2310e081e1c550326f5b.tar.bz2
Don't add the zlib header to SHF_COMPRESSED section
In a SHF_COMPRESSED compressed section, the raw compressed data should begin immediately after the compression header. This patch removes the extra zlib header from the SHF_COMPRESSED section. bfd/ * bfd.c (bfd_update_compression_header): Also write the zlib header if the SHF_COMPRESSED bit cleared.. (bfd_check_compression_header): Return the uncompressed size. * compress.c (decompress_contents): Don't skip the zlib header. (bfd_compress_section_contents): Properly handle ELFCOMPRESS_ZLIB, which doesn't have the zlib header. (bfd_init_section_decompress_status): Likewise. (bfd_get_full_section_contents): Updated. (bfd_is_section_compressed): Likewise. (bfd_is_section_compressed_with_header): Return the uncompressed size. * elf.c (_bfd_elf_make_section_from_shdr): Updated. * bfd-in2.h: Regenerated. binutils/ * readelf.c (uncompress_section_contents): Add a parameter for uncompressed size. Don't check the zlib header. (load_specific_debug_section): Updated. binutils/testsuite/ * binutils-all/compress.exp: Replace "$OBJDUMP -s -j .debug_info" with "$OBJDUMP -W". * binutils-all/libdw2-compressedgabi.out: Updated. gas/ 2015-05-14 H.J. Lu <hongjiu.lu@intel.com> * write.c (compress_debug): Don't write the zlib header, which is handled by bfd_update_compression_header.
Diffstat (limited to 'binutils/readelf.c')
-rw-r--r--binutils/readelf.c46
1 files changed, 25 insertions, 21 deletions
diff --git a/binutils/readelf.c b/binutils/readelf.c
index c2531ed..e7090ff 100644
--- a/binutils/readelf.c
+++ b/binutils/readelf.c
@@ -12074,30 +12074,14 @@ dump_section_as_bytes (Elf_Internal_Shdr * section,
static int
uncompress_section_contents (unsigned char **buffer,
+ dwarf_size_type uncompressed_size,
dwarf_size_type *size)
{
dwarf_size_type compressed_size = *size;
unsigned char * compressed_buffer = *buffer;
- dwarf_size_type uncompressed_size;
unsigned char * uncompressed_buffer;
z_stream strm;
int rc;
- dwarf_size_type header_size = 12;
-
- /* Read the zlib header. In this case, it should be "ZLIB" followed
- by the uncompressed section size, 8 bytes in big-endian order. */
- if (compressed_size < header_size
- || ! streq ((char *) compressed_buffer, "ZLIB"))
- return 0;
-
- uncompressed_size = compressed_buffer[4]; uncompressed_size <<= 8;
- uncompressed_size += compressed_buffer[5]; uncompressed_size <<= 8;
- uncompressed_size += compressed_buffer[6]; uncompressed_size <<= 8;
- uncompressed_size += compressed_buffer[7]; uncompressed_size <<= 8;
- uncompressed_size += compressed_buffer[8]; uncompressed_size <<= 8;
- uncompressed_size += compressed_buffer[9]; uncompressed_size <<= 8;
- uncompressed_size += compressed_buffer[10]; uncompressed_size <<= 8;
- uncompressed_size += compressed_buffer[11];
/* It is possible the section consists of several compressed
buffers concatenated together, so we uncompress in a loop. */
@@ -12107,8 +12091,8 @@ uncompress_section_contents (unsigned char **buffer,
we first zero the entire z_stream structure and then set the fields
that we need. */
memset (& strm, 0, sizeof strm);
- strm.avail_in = compressed_size - header_size;
- strm.next_in = (Bytef *) compressed_buffer + header_size;
+ strm.avail_in = compressed_size;
+ strm.next_in = (Bytef *) compressed_buffer;
strm.avail_out = uncompressed_size;
uncompressed_buffer = (unsigned char *) xmalloc (uncompressed_size);
@@ -12163,6 +12147,7 @@ load_specific_debug_section (enum dwarf_section_display_enum debug,
{
unsigned char *start = section->start;
dwarf_size_type size = sec->sh_size;
+ dwarf_size_type uncompressed_size = 0;
if ((sec->sh_flags & SHF_COMPRESSED) != 0)
{
@@ -12172,11 +12157,30 @@ load_specific_debug_section (enum dwarf_section_display_enum debug,
if (chdr.ch_type != ELFCOMPRESS_ZLIB
|| chdr.ch_addralign != sec->sh_addralign)
return 0;
+ uncompressed_size = chdr.ch_size;
start += compression_header_size;
size -= compression_header_size;
}
-
- if (uncompress_section_contents (&start, &size))
+ else if (size > 12 && streq ((char *) start, "ZLIB"))
+ {
+ /* Read the zlib header. In this case, it should be "ZLIB"
+ followed by the uncompressed section size, 8 bytes in
+ big-endian order. */
+ uncompressed_size = start[4]; uncompressed_size <<= 8;
+ uncompressed_size += start[5]; uncompressed_size <<= 8;
+ uncompressed_size += start[6]; uncompressed_size <<= 8;
+ uncompressed_size += start[7]; uncompressed_size <<= 8;
+ uncompressed_size += start[8]; uncompressed_size <<= 8;
+ uncompressed_size += start[9]; uncompressed_size <<= 8;
+ uncompressed_size += start[10]; uncompressed_size <<= 8;
+ uncompressed_size += start[11];
+ start += 12;
+ size -= 12;
+ }
+
+ if (uncompressed_size
+ && uncompress_section_contents (&start, uncompressed_size,
+ &size))
{
/* Free the compressed buffer, update the section buffer
and the section size if uncompress is successful. */