Add SHF_COMPRESSED section decompression to gold

This patch adds SHF_COMPRESSED section decompression to gold.

	PR gold/18321
	* compressed_output.h (decompress_input_section): Add arguments
	for ELF class, big endian and sh_flags.
	* compressed_output.cc (decompress_input_section): Likewise.
	Support the SHF_COMPRESSED section.
	* dynobj.h (Dynobj): Add elfsize and is_big_endian member
	functions.
	* plugin.h (Pluginobj): Likewise.
	* layout.cc (Layout::get_output_section_flags): Also clear the
	SHF_COMPRESSED bit.
	* object.h (Compressed_section_info): Add flag to store sh_flags.
	(Object): Add pure virtual elfsize and is_big_endian member
	functions.
	* object.cc (need_decompressed_section): Don't skip the ".zdebug"
	prefix here.
	(build_compressed_section_map): Check SHF_COMPRESSED for
	uncompressed size.  Store sh_flags in Compressed_section_info.
	Pass size, big_endian and sh_flags to decompress_input_section.
	Skip the ".debug"/".zdebug" prefix when passing section name to
	need_decompressed_section.
	(Sized_relobj_file<size, big_endian>::do_find_special_section):
	Don't check ".zdebug_*" sections.
	(Object::decompressed_section_contents): Pass ELF class, big
	endian and sh_flags to decompress_input_section.
	* reloc.cc (Sized_relobj_file<size, big_endian>::write_sections):
	Likewise.
	* testsuite/Makefile.am (check_DATA): Add
	debug_msg_cdebug_gabi.err and gdb_index_test_2_gabi.stdout.
	(MOSTLYCLEANFILES): Add debug_msg_cdebug_gabi.err and
	gdb_index_test_2_gabi.stdout.
	(debug_msg_cdebug_gabi.o): New.
	(odr_violation1_cdebug_gabi.o): Likewise.
	(odr_violation2_cdebug_gabi.o): Likewise.
	(debug_msg_cdebug_gabi.err): Likewise.
	(check_SCRIPTS): Add gdb_index_test_2_gabi.sh.
	(gdb_index_test_cdebug_gabi.o): Likewise.
	(gdb_index_test_2_gabi): Likewise.
	(gdb_index_test_2_gabi.stdout): Likewise.
	* testsuite/gdb_index_test_2_gabi.sh: New file.
	* testsuite/Makefile.in: Regenerated.
This commit is contained in:
H.J. Lu
2015-07-12 10:50:25 -07:00
parent 8d6dbeb44c
commit 480586639d
12 changed files with 237 additions and 19 deletions

View File

@@ -143,8 +143,55 @@ bool
decompress_input_section(const unsigned char* compressed_data,
unsigned long compressed_size,
unsigned char* uncompressed_data,
unsigned long uncompressed_size)
unsigned long uncompressed_size,
int size,
bool big_endian,
elfcpp::Elf_Xword sh_flags)
{
if ((sh_flags & elfcpp::SHF_COMPRESSED) != 0)
{
unsigned int compression_header_size;
if (size == 32)
{
compression_header_size = elfcpp::Elf_sizes<32>::chdr_size;
if (big_endian)
{
elfcpp::Chdr<32, true> chdr(compressed_data);
if (chdr.get_ch_type() != elfcpp::ELFCOMPRESS_ZLIB)
return false;
}
else
{
elfcpp::Chdr<32, false> chdr(compressed_data);
if (chdr.get_ch_type() != elfcpp::ELFCOMPRESS_ZLIB)
return false;
}
}
else if (size == 64)
{
compression_header_size = elfcpp::Elf_sizes<64>::chdr_size;
if (big_endian)
{
elfcpp::Chdr<64, true> chdr(compressed_data);
if (chdr.get_ch_type() != elfcpp::ELFCOMPRESS_ZLIB)
return false;
}
else
{
elfcpp::Chdr<64, false> chdr(compressed_data);
if (chdr.get_ch_type() != elfcpp::ELFCOMPRESS_ZLIB)
return false;
}
}
else
gold_unreachable();
return zlib_decompress(compressed_data + compression_header_size,
compressed_size - compression_header_size,
uncompressed_data,
uncompressed_size);
}
const unsigned int zlib_header_size = 12;
/* Verify the compression header. Currently, we support only zlib