diff options
author | H.J. Lu <hjl.tools@gmail.com> | 2015-07-12 10:56:41 -0700 |
---|---|---|
committer | H.J. Lu <hjl.tools@gmail.com> | 2015-07-12 10:56:58 -0700 |
commit | fb8b9dbc147d37129e5a366a395302f532f5d190 (patch) | |
tree | e19ef3d0329c2db4d6d7843c108c715b0b23f193 /gold/compressed_output.cc | |
parent | 480586639d6b814b2e87f6f106b8635cf7442b20 (diff) | |
download | gdb-fb8b9dbc147d37129e5a366a395302f532f5d190.zip gdb-fb8b9dbc147d37129e5a366a395302f532f5d190.tar.gz gdb-fb8b9dbc147d37129e5a366a395302f532f5d190.tar.bz2 |
Extend --compress-debug-sections in gold
This patch extends --compress-debug-sections= with [zlib-gnu|zlib-gabi]
in gold.
PR gold/18322
* compressed_output.cc (zlib_compress): Add argument for
compression header size. Set header size to compression header
size if it isn't 0. Don't write out the zlib header here.
(Output_compressed_section::set_final_data_size): Support
zlib-gnu and zlib-gabi compressions. Pass compression header
size to zlib_compress and write out compression header. Set
the SHF_COMPRESSED bit for zlib-gabi compression. Otherwise
clear the SHF_COMPRESSED bit
* options.h (compress_debug_sections): Add zlib-gnu and
zlib-gabi.
* output.h (Output_section::set_flags): New.
* testsuite/Makefile.am (check_PROGRAMS): Add
flagstest_compress_debug_sections_none,
flagstest_compress_debug_sections_gnu and
flagstest_compress_debug_sections_gabi.
(check_DATA): Add flagstest_compress_debug_sections_none.stdout.
flagstest_compress_debug_sections.stdout,
flagstest_compress_debug_sections.cmp,
flagstest_compress_debug_sections.check,
flagstest_compress_debug_sections_gnu.stdout,
flagstest_compress_debug_sections_gnu.cmp,
flagstest_compress_debug_sections_gnu.check,
flagstest_compress_debug_sections_gabi.stdout,
flagstest_compress_debug_sections_gabi.cmp and
flagstest_compress_debug_sections_gabi.check.
(flagstest_compress_debug_sections_none): New.
(flagstest_compress_debug_sections_none.stdout): Likewise.
(flagstest_compress_debug_sections.stdout): Likewise.
(flagstest_compress_debug_sections.check): Likewise.
(flagstest_compress_debug_sections.cmp): Likewise.
(flagstest_compress_debug_sections_gnu): Likewise.
(flagstest_compress_debug_sections_gnu.stdout): Likewise.
(flagstest_compress_debug_sections_gnu.check): Likewise.
(flagstest_compress_debug_sections_gnu.cmp): Likewise.
(flagstest_compress_debug_sections_gabi): Likewise.
(flagstest_compress_debug_sections_gabi.stdout): Likewise.
(flagstest_compress_debug_sections_gnu.check): Likewise.
(flagstest_compress_debug_sections_gnu.cmp): Likewise.
* testsuite/Makefile.in: Regenerated.
Diffstat (limited to 'gold/compressed_output.cc')
-rw-r--r-- | gold/compressed_output.cc | 89 |
1 files changed, 79 insertions, 10 deletions
diff --git a/gold/compressed_output.cc b/gold/compressed_output.cc index 02d7821..2630330 100644 --- a/gold/compressed_output.cc +++ b/gold/compressed_output.cc @@ -39,12 +39,12 @@ namespace gold // order. static bool -zlib_compress(const unsigned char* uncompressed_data, +zlib_compress(int header_size, + const unsigned char* uncompressed_data, unsigned long uncompressed_size, unsigned char** compressed_data, unsigned long* compressed_size) { - const int header_size = 12; *compressed_size = uncompressed_size + uncompressed_size / 1000 + 128; *compressed_data = new unsigned char[*compressed_size + header_size]; @@ -61,9 +61,6 @@ zlib_compress(const unsigned char* uncompressed_data, compress_level); if (rc == Z_OK) { - memcpy(*compressed_data, "ZLIB", 4); - elfcpp::Swap_unaligned<64, true>::writeval(*compressed_data + 4, - uncompressed_size); *compressed_size += header_size; return true; } @@ -233,14 +230,86 @@ Output_compressed_section::set_final_data_size() this->write_to_postprocessing_buffer(); bool success = false; + enum { none, gnu_zlib, gabi_zlib } compress; + int compression_header_size = 12; + const int size = parameters->target().get_size(); if (strcmp(this->options_->compress_debug_sections(), "zlib") == 0) - success = zlib_compress(uncompressed_data, uncompressed_size, - &this->data_, &compressed_size); + compress = gnu_zlib; + else if (strcmp(this->options_->compress_debug_sections(), "zlib-gnu") == 0) + compress = gnu_zlib; + else if (strcmp(this->options_->compress_debug_sections(), "zlib-gabi") == 0) + { + compress = gabi_zlib; + if (size == 32) + compression_header_size = elfcpp::Elf_sizes<32>::chdr_size; + else if (size == 64) + compression_header_size = elfcpp::Elf_sizes<64>::chdr_size; + else + gold_unreachable(); + } + else + compress = none; + if (compress != none) + success = zlib_compress(compression_header_size, uncompressed_data, + uncompressed_size, &this->data_, + &compressed_size); if (success) { - // This converts .debug_foo to .zdebug_foo - this->new_section_name_ = std::string(".z") + (this->name() + 1); - this->set_name(this->new_section_name_.c_str()); + elfcpp::Elf_Xword flags = this->flags(); + if (compress == gabi_zlib) + { + // Set the SHF_COMPRESSED bit. + flags |= elfcpp::SHF_COMPRESSED; + const bool is_big_endian = parameters->target().is_big_endian(); + uint64_t addralign = this->addralign(); + if (size == 32) + { + if (is_big_endian) + { + elfcpp::Chdr_write<32, true> chdr(this->data_); + chdr.put_ch_type(elfcpp::ELFCOMPRESS_ZLIB); + chdr.put_ch_size(uncompressed_size); + chdr.put_ch_addralign(addralign); + } + else + { + elfcpp::Chdr_write<32, false> chdr(this->data_); + chdr.put_ch_type(elfcpp::ELFCOMPRESS_ZLIB); + chdr.put_ch_size(uncompressed_size); + chdr.put_ch_addralign(addralign); + } + } + else if (size == 64) + { + if (is_big_endian) + { + elfcpp::Chdr_write<64, true> chdr(this->data_); + chdr.put_ch_type(elfcpp::ELFCOMPRESS_ZLIB); + chdr.put_ch_size(uncompressed_size); + chdr.put_ch_addralign(addralign); + } + else + { + elfcpp::Chdr_write<64, false> chdr(this->data_); + chdr.put_ch_type(elfcpp::ELFCOMPRESS_ZLIB); + chdr.put_ch_size(uncompressed_size); + chdr.put_ch_addralign(addralign); + } + } + else + gold_unreachable(); + } + else + { + // Write out the zlib header. + memcpy(this->data_, "ZLIB", 4); + elfcpp::Swap_unaligned<64, true>::writeval(this->data_ + 4, + uncompressed_size); + // This converts .debug_foo to .zdebug_foo + this->new_section_name_ = std::string(".z") + (this->name() + 1); + this->set_name(this->new_section_name_.c_str()); + } + this->set_flags(flags); this->set_data_size(compressed_size); } else |