diff options
author | Cary Coutant <ccoutant@google.com> | 2010-07-12 17:59:58 +0000 |
---|---|---|
committer | Cary Coutant <ccoutant@google.com> | 2010-07-12 17:59:58 +0000 |
commit | a2e4736229d6ce6f804ed26ea8d763c538de9d2c (patch) | |
tree | 25de3c95f1bf545500aa9adf3278422f477ace18 /gold/compressed_output.cc | |
parent | add265ae415ecd40208537d1f84155f868668ef5 (diff) | |
download | gdb-a2e4736229d6ce6f804ed26ea8d763c538de9d2c.zip gdb-a2e4736229d6ce6f804ed26ea8d763c538de9d2c.tar.gz gdb-a2e4736229d6ce6f804ed26ea8d763c538de9d2c.tar.bz2 |
* compressed_output.cc (zlib_decompress): New function.
(get_uncompressed_size): New function.
(decompress_input_section): New function.
* compressed_output.h (get_uncompressed_size): New function.
(decompress_input_section): New function.
* dwarf_reader.cc (Sized_dwarf_line_info::Sized_dwarf_line_info)
Handle compressed debug sections.
* layout.cc (is_compressed_debug_section): New function.
(Layout::output_section_name): Map compressed section names to
canonical names.
* layout.h (is_compressed_debug_section): New function.
(is_debug_info_section): Recognize compressed debug sections.
* merge.cc: Include compressed_output.h.
(Output_merge_data::do_add_input_section): Handle compressed
debug sections.
(Output_merge_string::do_add_input_section): Handle compressed
debug sections.
* object.cc: Include compressed_output.h.
(Sized_relobj::Sized_relobj): Initialize new data members.
(build_compressed_section_map): New function.
(Sized_relobj::do_read_symbols): Handle compressed debug sections.
* object.h (Object::section_is_compressed): New method.
(Object::do_section_is_compressed): New method.
(Sized_relobj::Compressed_section_map): New type.
(Sized_relobj::do_section_is_compressed): New method.
(Sized_relobj::compressed_sections_): New data member.
* output.cc (Output_section::add_input_section): Handle compressed
debug sections.
* reloc.cc: Include compressed_output.h.
(Sized_relobj::write_sections): Handle compressed debug sections.
Diffstat (limited to 'gold/compressed_output.cc')
-rw-r--r-- | gold/compressed_output.cc | 105 |
1 files changed, 101 insertions, 4 deletions
diff --git a/gold/compressed_output.cc b/gold/compressed_output.cc index a0f8ed1..16d9129 100644 --- a/gold/compressed_output.cc +++ b/gold/compressed_output.cc @@ -1,6 +1,6 @@ -// compressed_output.cc -- manage compressed output sections for gold +// compressed_output.cc -- manage compressed debug sections for gold -// Copyright 2007, 2008 Free Software Foundation, Inc. +// Copyright 2007, 2008, 2010 Free Software Foundation, Inc. // Written by Ian Lance Taylor <iant@google.com>. // This file is part of gold. @@ -33,6 +33,8 @@ namespace gold { +#ifdef HAVE_ZLIB_H + // Compress UNCOMPRESSED_DATA of size UNCOMPRESSED_SIZE. Returns true // if it successfully compressed, false if it failed for any reason // (including not having zlib support in the library). If it returns @@ -42,8 +44,6 @@ namespace gold // "ZLIB", and 8 bytes indicating the uncompressed size, in big-endian // order. -#ifdef HAVE_ZLIB_H - static bool zlib_compress(const unsigned char* uncompressed_data, unsigned long uncompressed_size, @@ -81,6 +81,49 @@ zlib_compress(const unsigned char* uncompressed_data, } } +// Decompress COMPRESSED_DATA of size COMPRESSED_SIZE, into a buffer +// UNCOMPRESSED_DATA of size UNCOMPRESSED_SIZE. Returns TRUE if it +// decompressed successfully, false if it failed. The buffer, of +// appropriate size, is provided by the caller, and is typically part +// of the memory-mapped output file. + +static bool +zlib_decompress(const unsigned char* compressed_data, + unsigned long compressed_size, + unsigned char* uncompressed_data, + unsigned long uncompressed_size) +{ + z_stream strm; + int rc; + + /* It is possible the section consists of several compressed + buffers concatenated together, so we uncompress in a loop. */ + strm.zalloc = NULL; + strm.zfree = NULL; + strm.opaque = NULL; + strm.avail_in = compressed_size; + strm.next_in = const_cast<Bytef*>(compressed_data); + strm.avail_out = uncompressed_size; + + rc = inflateInit(&strm); + while (strm.avail_in > 0) + { + if (rc != Z_OK) + return false; + strm.next_out = ((Bytef*) uncompressed_data + + (uncompressed_size - strm.avail_out)); + rc = inflate(&strm, Z_FINISH); + if (rc != Z_STREAM_END) + return false; + rc = inflateReset(&strm); + } + rc = inflateEnd(&strm); + if (rc != Z_OK || strm.avail_out != 0) + return false; + + return true; +} + #else // !defined(HAVE_ZLIB_H) static bool @@ -90,8 +133,62 @@ zlib_compress(const unsigned char*, unsigned long, return false; } +static bool +zlib_decompress(const unsigned char*, unsigned long, + unsigned char**, unsigned long*) +{ + return false; +} + #endif // !defined(HAVE_ZLIB_H) +// Read the compression header of a compressed debug section and return +// the uncompressed size. + +uint64_t +get_uncompressed_size(const unsigned char* compressed_data, + section_size_type compressed_size) +{ + const unsigned int zlib_header_size = 12; + + /* Verify the compression header. Currently, we support only zlib + compression, so it should be "ZLIB" followed by the uncompressed + section size, 8 bytes in big-endian order. */ + if (compressed_size >= zlib_header_size + && strncmp(reinterpret_cast<const char*>(compressed_data), + "ZLIB", 4) == 0) + return elfcpp::Swap_unaligned<64, true>::readval(compressed_data + 4); + return -1ULL; +} + +// Decompress a compressed debug section directly into the output file. + +bool +decompress_input_section(const unsigned char* compressed_data, + unsigned long compressed_size, + unsigned char* uncompressed_data, + unsigned long uncompressed_size) +{ + const unsigned int zlib_header_size = 12; + + /* Verify the compression header. Currently, we support only zlib + compression, so it should be "ZLIB" followed by the uncompressed + section size, 8 bytes in big-endian order. */ + if (compressed_size >= zlib_header_size + && strncmp(reinterpret_cast<const char*>(compressed_data), + "ZLIB", 4) == 0) + { + unsigned long uncompressed_size_check = + elfcpp::Swap_unaligned<64, true>::readval(compressed_data + 4); + gold_assert(uncompressed_size_check == uncompressed_size); + return zlib_decompress(compressed_data + zlib_header_size, + compressed_size - zlib_header_size, + uncompressed_data, + uncompressed_size); + } + return false; +} + // Class Output_compressed_section. // Set the final data size of a compressed section. This is where |