-z, --decompress Show compression information for compressed sections (when used with -S).
Signed-off-by: Mark Wielaard <m...@redhat.com> --- src/ChangeLog | 8 ++++ src/readelf.c | 48 +++++++++++++++++++++ tests/ChangeLog | 6 +++ tests/Makefile.am | 3 +- tests/run-readelf-z.sh | 110 +++++++++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 174 insertions(+), 1 deletion(-) create mode 100755 tests/run-readelf-z.sh diff --git a/src/ChangeLog b/src/ChangeLog index f9e3b4a..eff42df 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,5 +1,13 @@ 2015-10-16 Mark Wielaard <m...@redhat.com> + * readelf.c (argp_option): Describe --decompress,-z. + (print_decompress): New bool. + (parse_opt): Handle -z. + (elf_ch_type_name): New function. + (print_shdr): Print section compress information. + +2015-10-16 Mark Wielaard <m...@redhat.com> + * elflint.c (check_symtab): Don't check TLS symbol value against TLS phdr offset in debuginfo files. (check_sections): Don't try to match section offsets to phdrs offsets diff --git a/src/readelf.c b/src/readelf.c index 5f6e4ed..6441c56 100644 --- a/src/readelf.c +++ b/src/readelf.c @@ -112,6 +112,8 @@ static const struct argp_option options[] = N_("Display just offsets instead of resolving values to addresses in DWARF data"), 0 }, { "wide", 'W', NULL, 0, N_("Ignored for compatibility (lines always wide)"), 0 }, + { "decompress", 'z', NULL, 0, + N_("Show compression information for compressed sections (when used with -S)."), 0 }, { NULL, 0, NULL, 0, NULL, 0 } }; @@ -190,6 +192,9 @@ static bool decodedaranges = false; /* True if we should print the .debug_aranges section using libdw. */ static bool decodedline = false; +/* True if we want to show more information about compressed sections. */ +static bool print_decompress = false; + /* Select printing of debugging sections. */ static enum section_e { @@ -479,6 +484,9 @@ parse_opt (int key, char *arg, break; case 'W': /* Ignored. */ break; + case 'z': + print_decompress = true; + break; case ELF_INPUT_SECTION: if (arg == NULL) elf_input_section = ".gnu_debugdata"; @@ -1065,6 +1073,17 @@ get_visibility_type (int value) } } +static const char * +elf_ch_type_name (unsigned int code) +{ + if (code == 0) + return "NONE"; + + if (code == ELFCOMPRESS_ZLIB) + return "ZLIB"; + + return "UNKNOWN"; +} /* Print the section headers. */ static void @@ -1091,6 +1110,14 @@ There are %d section headers, starting at offset %#" PRIx64 ":\n\ else puts (gettext ("[Nr] Name Type Addr Off Size ES Flags Lk Inf Al")); + if (print_decompress) + { + if (ehdr->e_ident[EI_CLASS] == ELFCLASS32) + puts (gettext (" [Compression Size Al]")); + else + puts (gettext (" [Compression Size Al]")); + } + for (cnt = 0; cnt < shnum; ++cnt) { Elf_Scn *scn = elf_getscn (ebl->elf, cnt); @@ -1128,6 +1155,8 @@ There are %d section headers, starting at offset %#" PRIx64 ":\n\ *cp++ = 'G'; if (shdr->sh_flags & SHF_TLS) *cp++ = 'T'; + if (shdr->sh_flags & SHF_COMPRESSED) + *cp++ = 'C'; if (shdr->sh_flags & SHF_ORDERED) *cp++ = 'O'; if (shdr->sh_flags & SHF_EXCLUDE) @@ -1147,6 +1176,25 @@ There are %d section headers, starting at offset %#" PRIx64 ":\n\ ehdr->e_ident[EI_CLASS] == ELFCLASS32 ? 6 : 8, shdr->sh_size, shdr->sh_entsize, flagbuf, shdr->sh_link, shdr->sh_info, shdr->sh_addralign); + + if (print_decompress) + { + GElf_Chdr chdr; + int type; + if (gelf_getchdr (scn, &chdr, &type) != NULL) + printf (" [%s %s (%" PRId32 ") %0*" PRIx64 + " %2" PRId64 "]\n", + type == ELF_ZSCN_T_GNU ? "GNU" : "ELF", + elf_ch_type_name (chdr.ch_type), + chdr.ch_type, + ehdr->e_ident[EI_CLASS] == ELFCLASS32 ? 6 : 8, + chdr.ch_size, chdr.ch_addralign); + else if (type != ELF_ZSCN_T_NONE) + error (0, 0, + gettext ("bad compression header for section %zd: %s"), + elf_ndxscn (scn), elf_errmsg (-1)); + + } } fputc_unlocked ('\n', stdout); diff --git a/tests/ChangeLog b/tests/ChangeLog index 16f8144..cbe7084 100644 --- a/tests/ChangeLog +++ b/tests/ChangeLog @@ -1,5 +1,11 @@ 2015-10-14 Mark Wielaard <m...@redhat.com> + * run-readelf-z.sh: New test. + * Makefile.am (TESTS): Add run-readelf-z.sh. + (EXTRA_DIST): Likewise. + +2015-06-24 Mark Wielaard <m...@redhat.com> + * msg_tst.c: Add ELF_E_NOT_COMPRESSED. * run-elfgetchdr.sh: New test. * testfile-zgnu32.bz2: New testfile. diff --git a/tests/Makefile.am b/tests/Makefile.am index d252f1c..a81817f 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -90,7 +90,7 @@ TESTS = run-arextract.sh run-arsymtest.sh newfile test-nlist \ run-readelf-test1.sh run-readelf-test2.sh run-readelf-test3.sh \ run-readelf-test4.sh run-readelf-twofiles.sh \ run-readelf-macro.sh run-readelf-loc.sh \ - run-readelf-aranges.sh run-readelf-line.sh \ + run-readelf-aranges.sh run-readelf-line.sh run-readelf-z.sh \ run-native-test.sh run-bug1-test.sh \ run-debuglink.sh run-debugaltlink.sh run-buildid.sh \ dwfl-bug-addr-overflow run-addrname-test.sh \ @@ -208,6 +208,7 @@ EXTRA_DIST = run-arextract.sh run-arsymtest.sh \ run-readelf-macro.sh testfilemacro.bz2 \ run-readelf-loc.sh testfileloc.bz2 \ run-readelf-aranges.sh run-readelf-line.sh testfilefoobarbaz.bz2 \ + run-readelf-z.sh \ run-readelf-dwz-multi.sh libtestfile_multi_shared.so.bz2 \ testfile_multi.dwz.bz2 testfile_multi_main.bz2 \ testfile-dwzstr.bz2 testfile-dwzstr.multi.bz2 \ diff --git a/tests/run-readelf-z.sh b/tests/run-readelf-z.sh new file mode 100755 index 0000000..065b481 --- /dev/null +++ b/tests/run-readelf-z.sh @@ -0,0 +1,110 @@ +#! /bin/sh +# Copyright (C) 2015 Red Hat, Inc. +# This file is part of elfutils. +# +# This file is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# elfutils is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see <http://www.gnu.org/licenses/>. + +. $srcdir/test-subr.sh + +# See run-elfgetchdr.sh for testfiles. + +testfiles testfile-zgnu64 +testrun_compare ${abs_top_builddir}/src/readelf -z -S testfile-zgnu64 <<\EOF +There are 9 section headers, starting at offset 0x3e0: + +Section Headers: +[Nr] Name Type Addr Off Size ES Flags Lk Inf Al + [Compression Size Al] +[ 0] NULL 0000000000000000 00000000 00000000 0 0 0 0 +[ 1] .text PROGBITS 0000000000400078 00000078 0000002a 0 AX 0 0 1 +[ 2] .zdebug_aranges PROGBITS 0000000000000000 00000260 00000032 0 0 0 16 + [GNU ZLIB (1) 00000060 16] +[ 3] .zdebug_info PROGBITS 0000000000000000 00000292 0000006f 0 0 0 1 + [GNU ZLIB (1) 000000aa 1] +[ 4] .debug_abbrev PROGBITS 0000000000000000 00000301 00000028 0 0 0 1 +[ 5] .zdebug_line PROGBITS 0000000000000000 00000329 0000005b 0 0 0 1 + [GNU ZLIB (1) 0000008d 1] +[ 6] .shstrtab STRTAB 0000000000000000 00000384 00000059 0 0 0 1 +[ 7] .symtab SYMTAB 0000000000000000 000000a8 00000168 24 8 8 8 +[ 8] .strtab STRTAB 0000000000000000 00000210 0000004b 0 0 0 1 + +EOF + +testfiles testfile-zgabi64 +testrun_compare ${abs_top_builddir}/src/readelf -z -S testfile-zgabi64 <<\EOF +There are 9 section headers, starting at offset 0x400: + +Section Headers: +[Nr] Name Type Addr Off Size ES Flags Lk Inf Al + [Compression Size Al] +[ 0] NULL 0000000000000000 00000000 00000000 0 0 0 0 +[ 1] .text PROGBITS 0000000000400078 00000078 0000002a 0 AX 0 0 1 +[ 2] .debug_aranges PROGBITS 0000000000000000 00000260 0000003e 0 C 0 0 16 + [ELF ZLIB (1) 00000060 16] +[ 3] .debug_info PROGBITS 0000000000000000 0000029e 0000007b 0 C 0 0 1 + [ELF ZLIB (1) 000000aa 1] +[ 4] .debug_abbrev PROGBITS 0000000000000000 00000319 00000028 0 0 0 1 +[ 5] .debug_line PROGBITS 0000000000000000 00000341 00000067 0 C 0 0 1 + [ELF ZLIB (1) 0000008d 1] +[ 6] .shstrtab STRTAB 0000000000000000 000003a8 00000056 0 0 0 1 +[ 7] .symtab SYMTAB 0000000000000000 000000a8 00000168 24 8 8 8 +[ 8] .strtab STRTAB 0000000000000000 00000210 0000004b 0 0 0 1 + +EOF + +testfiles testfile-zgnu32 +testrun_compare ${abs_top_builddir}/src/readelf -z -S testfile-zgnu32 <<\EOF +There are 9 section headers, starting at offset 0x33c: + +Section Headers: +[Nr] Name Type Addr Off Size ES Flags Lk Inf Al + [Compression Size Al] +[ 0] NULL 00000000 000000 000000 0 0 0 0 +[ 1] .text PROGBITS 08048054 000054 00002a 0 AX 0 0 1 +[ 2] .zdebug_aranges PROGBITS 00000000 0001c0 000031 0 0 0 8 + [GNU ZLIB (1) 000040 8] +[ 3] .zdebug_info PROGBITS 00000000 0001f1 00006f 0 0 0 1 + [GNU ZLIB (1) 00009a 1] +[ 4] .debug_abbrev PROGBITS 00000000 000260 000028 0 0 0 1 +[ 5] .zdebug_line PROGBITS 00000000 000288 00005a 0 0 0 1 + [GNU ZLIB (1) 000085 1] +[ 6] .shstrtab STRTAB 00000000 0002e2 000059 0 0 0 1 +[ 7] .symtab SYMTAB 00000000 000080 0000f0 16 8 8 4 +[ 8] .strtab STRTAB 00000000 000170 00004b 0 0 0 1 + +EOF + +testfiles testfile-zgabi32 +testrun_compare ${abs_top_builddir}/src/readelf -z -S testfile-zgabi32 <<\EOF +There are 9 section headers, starting at offset 0x338: + +Section Headers: +[Nr] Name Type Addr Off Size ES Flags Lk Inf Al + [Compression Size Al] +[ 0] NULL 00000000 000000 000000 0 0 0 0 +[ 1] .text PROGBITS 08048054 000054 00002a 0 AX 0 0 1 +[ 2] .debug_aranges PROGBITS 00000000 0001c0 000031 0 C 0 0 8 + [ELF ZLIB (1) 000040 8] +[ 3] .debug_info PROGBITS 00000000 0001f1 00006f 0 C 0 0 1 + [ELF ZLIB (1) 00009a 1] +[ 4] .debug_abbrev PROGBITS 00000000 000260 000028 0 0 0 1 +[ 5] .debug_line PROGBITS 00000000 000288 00005a 0 C 0 0 1 + [ELF ZLIB (1) 000085 1] +[ 6] .shstrtab STRTAB 00000000 0002e2 000056 0 0 0 1 +[ 7] .symtab SYMTAB 00000000 000080 0000f0 16 8 8 4 +[ 8] .strtab STRTAB 00000000 000170 00004b 0 0 0 1 + +EOF + +exit 0 -- 1.8.3.1