diff options
| author | Ulf Hermann <[email protected]> | 2017-04-19 18:59:27 +0200 |
|---|---|---|
| committer | Ulf Hermann <[email protected]> | 2017-04-19 18:59:54 +0200 |
| commit | 3fd4025d5c6d6ba6fcafa502da2c097ad504b2e3 (patch) | |
| tree | 36a37eb968218e0cbcbd80b7430e63f53b893112 | |
| parent | 6b471502bc27da64c59191c7e59f83dd7f55aee3 (diff) | |
| parent | 45ca3b9dfdc730cc6e6420a59ad9cb2613473aa0 (diff) | |
Merge branch 'upstream' into HEAD
Change-Id: Ifefd8ffeadb4e7d6df59cdc606323999eedc9adb
| -rw-r--r-- | libdw/ChangeLog | 5 | ||||
| -rw-r--r-- | libdw/dwarf_peel_type.c | 2 | ||||
| -rw-r--r-- | src/ChangeLog | 4 | ||||
| -rw-r--r-- | src/elflint.c | 7 | ||||
| -rw-r--r-- | tests/ChangeLog | 15 | ||||
| -rw-r--r-- | tests/Makefile.am | 9 | ||||
| -rw-r--r-- | tests/peel_type.c | 119 | ||||
| -rwxr-xr-x | tests/run-elflint-self.sh | 3 | ||||
| -rwxr-xr-x | tests/run-elflint-test.sh | 10 | ||||
| -rwxr-xr-x | tests/run-peel-type.sh | 62 | ||||
| -rw-r--r-- | tests/test-subr.sh | 20 |
11 files changed, 249 insertions, 7 deletions
diff --git a/libdw/ChangeLog b/libdw/ChangeLog index 978b9913..3f63a174 100644 --- a/libdw/ChangeLog +++ b/libdw/ChangeLog @@ -1,3 +1,8 @@ +2017-03-30 Mark Wielaard <[email protected]> + + * dwarf_peel_type.c (dwarf_peel_type): Call dwarf_attr_integrate on + result. + 2016-10-22 Mark Wielaard <[email protected]> * dwarf.h: Correct spelling of DW_LANG_PLI. Add compatibility define. diff --git a/libdw/dwarf_peel_type.c b/libdw/dwarf_peel_type.c index 5dca8f88..97356944 100644 --- a/libdw/dwarf_peel_type.c +++ b/libdw/dwarf_peel_type.c @@ -53,7 +53,7 @@ dwarf_peel_type (Dwarf_Die *die, Dwarf_Die *result) || tag == DW_TAG_atomic_type) { Dwarf_Attribute attr_mem; - Dwarf_Attribute *attr = INTUSE (dwarf_attr_integrate) (die, DW_AT_type, + Dwarf_Attribute *attr = INTUSE (dwarf_attr_integrate) (result, DW_AT_type, &attr_mem); if (attr == NULL) return 1; diff --git a/src/ChangeLog b/src/ChangeLog index e022503b..a1bec198 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,7 @@ +2017-04-05 Mark Wielaard <[email protected]> + + * elflint.c (check_elf_header): Decompress all sections. + 2017-03-28 Mark Wielaard <[email protected]> * elflint (check_group): Don't check if there is no flag word. diff --git a/src/elflint.c b/src/elflint.c index e0c65b6a..51e53c23 100644 --- a/src/elflint.c +++ b/src/elflint.c @@ -456,7 +456,9 @@ invalid number of section header table entries\n")); ERROR (gettext ("invalid section header index\n")); } - /* Check the shdrs actually exist. */ + /* Check the shdrs actually exist. And uncompress them before + further checking. Indexes between sections reference the + uncompressed data. */ unsigned int scnt; Elf_Scn *scn = NULL; for (scnt = 1; scnt < shnum; ++scnt) @@ -464,6 +466,9 @@ invalid number of section header table entries\n")); scn = elf_nextscn (ebl->elf, scn); if (scn == NULL) break; + /* If the section wasn't compressed this does nothing, but + returns an error. We don't care. */ + elf_compress (scn, 0, 0); } if (scnt < shnum) ERROR (gettext ("Can only check %u headers, shnum was %u\n"), scnt, shnum); diff --git a/tests/ChangeLog b/tests/ChangeLog index 0df0bae4..5f7bcddb 100644 --- a/tests/ChangeLog +++ b/tests/ChangeLog @@ -1,3 +1,18 @@ +2017-04-05 Mark Wielaard <[email protected]> + + * test-subr.sh (testrun_on_self_compressed): New function. + * run-elflint-self.sh: Call testrun_on_self_compressed. + * run-elflint-test.sh: Add testfile42z and testfile-s390x-hash-bothz. + +2017-03-30 Mark Wielaard <[email protected]> + + * peel_type.c: New file. + * run-peel-type.sh: New test. + * Makefile.am (check_PROGRAMS): Add peel_type.c. + (TESTS): Add run-peel-type.sh. + (EXTRA_DIST): Likewise. + (peel_type_LDADD): New variable. + 2017-03-27 Mark Wielaard <[email protected]> * fillfile.c: New file. diff --git a/tests/Makefile.am b/tests/Makefile.am index f287d92b..f6d8b0d8 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -50,7 +50,8 @@ check_PROGRAMS = arextract arsymtest newfile saridx scnnames sectiondump \ test-elf_cntl_gelf_getshdr dwflsyms dwfllines \ dwfl-report-elf-align varlocs backtrace backtrace-child \ backtrace-data backtrace-dwarf debuglink debugaltlink \ - buildid deleted deleted-lib.so aggregate_size vdsosyms \ + buildid deleted deleted-lib.so aggregate_size peel_type \ + vdsosyms \ getsrc_die strptr newdata elfstrtab dwfl-proc-attach \ elfshphehdr elfstrmerge dwelfgnucompressed elfgetchdr \ elfgetzdata elfputzdata zstrptr emptyfile vendorelf \ @@ -121,7 +122,8 @@ TESTS = run-arextract.sh run-arsymtest.sh newfile test-nlist \ run-backtrace-demangle.sh run-stack-d-test.sh run-stack-i-test.sh \ run-stack-demangled-test.sh run-readelf-zx.sh run-readelf-zp.sh \ run-readelf-dwz-multi.sh run-allfcts-multi.sh run-deleted.sh \ - run-linkmap-cut.sh run-aggregate-size.sh vdsosyms run-readelf-A.sh \ + run-linkmap-cut.sh run-aggregate-size.sh run-peel-type.sh \ + vdsosyms run-readelf-A.sh \ run-getsrc-die.sh run-strptr.sh newdata elfstrtab dwfl-proc-attach \ elfshphehdr run-lfs-symbols.sh run-dwelfgnucompressed.sh \ run-elfgetchdr.sh \ @@ -316,7 +318,7 @@ EXTRA_DIST = run-arextract.sh run-arsymtest.sh \ run-deleted.sh run-linkmap-cut.sh linkmap-cut-lib.so.bz2 \ linkmap-cut.bz2 linkmap-cut.core.bz2 \ run-aggregate-size.sh testfile-sizes1.o.bz2 testfile-sizes2.o.bz2 \ - testfile-sizes3.o.bz2 \ + testfile-sizes3.o.bz2 run-peel-type.sh \ run-readelf-A.sh testfileppc32attrs.o.bz2 \ testfilesparc64attrs.o.bz2 testfileppc64attrs.o.bz2 \ testfile-debug-types.bz2 \ @@ -474,6 +476,7 @@ deleted_LDADD = ./deleted-lib.so deleted_lib_so_LDFLAGS = -shared -rdynamic deleted_lib_so_CFLAGS = -fPIC -fasynchronous-unwind-tables aggregate_size_LDADD = $(libdw) $(libelf) $(argp_LDADD) +peel_type_LDADD = $(libdw) $(libelf) $(argp_LDADD) vdsosyms_LDADD = $(libdw) $(libelf) getsrc_die_LDADD = $(libdw) $(libelf) strptr_LDADD = $(libelf) diff --git a/tests/peel_type.c b/tests/peel_type.c new file mode 100644 index 00000000..bccce32e --- /dev/null +++ b/tests/peel_type.c @@ -0,0 +1,119 @@ +/* Test program for dwarf_peel_type. Peels type of top-level vars. + Copyright (C) 2017 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/>. */ + +#ifdef HAVE_CONFIG_H +# include <config.h> +#endif + +#include <assert.h> +#include <argp.h> +#include <inttypes.h> +#include <fcntl.h> +#include ELFUTILS_HEADER(dw) +#include ELFUTILS_HEADER(dwfl) +#include <stdio.h> +#include <unistd.h> +#include <dwarf.h> + +#include "../libdw/known-dwarf.h" + +static const char * +dwarf_tag_string (unsigned int tag) +{ + switch (tag) + { +#define DWARF_ONE_KNOWN_DW_TAG(NAME, CODE) case CODE: return #NAME; + DWARF_ALL_KNOWN_DW_TAG +#undef DWARF_ONE_KNOWN_DW_TAG + default: + return NULL; + } +} + +void +print_var_raw_type (Dwarf_Die *var) +{ + Dwarf_Attribute attr_mem; + Dwarf_Die type_mem; + Dwarf_Die *type; + const char *name = dwarf_diename (var); + + type = dwarf_formref_die (dwarf_attr (var, DW_AT_type, &attr_mem), + &type_mem); + if (type != NULL) + { + /* Test twice, once with a separate result DIE. Then with the + DIE itself. The resulting tag should be the same. */ + Dwarf_Die result_mem; + Dwarf_Die *result = &result_mem; + int res = dwarf_peel_type (type, result); + if (res < 0) + printf ("%s error peeling type: %s\n", name, dwarf_errmsg (-1)); + else if (res > 0) + printf ("%s missing DW_TAG_TYPE, could peel further: %s\n", + name, dwarf_tag_string (dwarf_tag (result))); + else + { + int tag = dwarf_tag (result); + printf ("%s raw type %s\n", name, dwarf_tag_string (tag)); + res = dwarf_peel_type (type, type); + if (res < 0) + printf ("%s cannot peel type itself: %s\n", name, + dwarf_errmsg (-1)); + else if (res > 0) + printf ("%s missing DW_TAG_TYPE, could peel type further: %s\n", + name, dwarf_tag_string (dwarf_tag (type))); + else if (dwarf_tag (type) != tag) + printf ("%s doesn't resolve the same: %s != %s\n", name, + dwarf_tag_string (tag), + dwarf_tag_string (dwarf_tag (type))); + } + } + else + printf ("%s has no type.\n", name); +} + +int +main (int argc, char *argv[]) +{ + + int remaining; + Dwfl *dwfl; + (void) argp_parse (dwfl_standard_argp (), argc, argv, 0, &remaining, + &dwfl); + assert (dwfl != NULL); + + Dwarf_Die *cu = NULL; + Dwarf_Addr dwbias; + while ((cu = dwfl_nextcu (dwfl, cu, &dwbias)) != NULL) + { + Dwarf_Die die_mem; + Dwarf_Die *die = &die_mem; + dwarf_child (cu, &die_mem); + + while (1) + { + if (dwarf_tag (die) == DW_TAG_variable) + print_var_raw_type (die); + + if (dwarf_siblingof (die, &die_mem) != 0) + break; + } + } + + dwfl_end (dwfl); +} diff --git a/tests/run-elflint-self.sh b/tests/run-elflint-self.sh index 013109db..58fa7d0f 100755 --- a/tests/run-elflint-self.sh +++ b/tests/run-elflint-self.sh @@ -1,5 +1,5 @@ #! /bin/sh -# Copyright (C) 2005, 2007 Red Hat, Inc. +# Copyright (C) 2005, 2007, 2017 Red Hat, Inc. # This file is part of elfutils. # Written by Ulrich Drepper <[email protected]>, 2005. # @@ -19,3 +19,4 @@ . $srcdir/test-subr.sh testrun_on_self ${abs_top_builddir}/src/elflint --quiet --gnu-ld +testrun_on_self_compressed ${abs_top_builddir}/src/elflint --quiet --gnu-ld diff --git a/tests/run-elflint-test.sh b/tests/run-elflint-test.sh index f3bd9012..caf172a6 100755 --- a/tests/run-elflint-test.sh +++ b/tests/run-elflint-test.sh @@ -33,6 +33,11 @@ testrun ${abs_top_builddir}/src/elflint -q testfile33 testfiles testfile42 testrun ${abs_top_builddir}/src/elflint -q --gnu-ld testfile42 +# Contains debuginfo, compress it, recheck +tempfiles testfile42z +testrun ${abs_top_builddir}/src/elfcompress -f -q -o testfile42z testfile42 +testrun ${abs_top_builddir}/src/elflint -q --gnu-ld testfile42z + testfiles testfile46 testrun ${abs_top_builddir}/src/elflint -q testfile46 @@ -47,4 +52,9 @@ testrun ${abs_top_builddir}/src/elflint -q --gnu-ld testlib_dynseg.so testfiles testfile-s390x-hash-both testrun ${abs_top_builddir}/src/elflint -q --gnu-ld testfile-s390x-hash-both +# Compress the symtab/strtab just because and recheck +tempfiles testfile-s390x-hash-bothz +testrun ${abs_top_builddir}/src/elfcompress -f -q --name='.s??tab' -o testfile-s390x-hash-bothz testfile-s390x-hash-both +testrun ${abs_top_builddir}/src/elflint -q --gnu-ld testfile-s390x-hash-bothz + exit 0 diff --git a/tests/run-peel-type.sh b/tests/run-peel-type.sh new file mode 100755 index 00000000..7fd96e84 --- /dev/null +++ b/tests/run-peel-type.sh @@ -0,0 +1,62 @@ +#! /bin/sh +# Copyright (C) 2017 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-aggregate-size.sh for how to generate testfiles. + +testfiles testfile-sizes1.o testfile-sizes2.o testfile-sizes3.o + +testrun_compare ${abs_builddir}/peel_type -e testfile-sizes1.o <<\EOF +c raw type base_type +i raw type base_type +l raw type base_type +v raw type pointer_type +s raw type structure_type +ca raw type array_type +ia raw type array_type +va raw type array_type +sa raw type array_type +EOF + +testrun_compare ${abs_builddir}/peel_type -e testfile-sizes2.o <<\EOF +c raw type base_type +i raw type base_type +l raw type base_type +v raw type pointer_type +s raw type structure_type +ca raw type array_type +ia raw type array_type +va raw type array_type +sa raw type array_type +EOF + +testrun_compare ${abs_builddir}/peel_type -e testfile-sizes3.o <<\EOF +c raw type base_type +i raw type base_type +l raw type base_type +v raw type pointer_type +s raw type structure_type +ca raw type array_type +ia raw type array_type +va raw type array_type +sa raw type array_type +f raw type base_type +b raw type base_type +EOF + +exit 0 diff --git a/tests/test-subr.sh b/tests/test-subr.sh index f397aed1..a765db63 100644 --- a/tests/test-subr.sh +++ b/tests/test-subr.sh @@ -1,5 +1,5 @@ #! /bin/sh -# Copyright (C) 2005-2015 Red Hat, Inc. +# Copyright (C) 2005-2015, 2017 Red Hat, Inc. # This file is part of elfutils. # # This file is free software; you can redistribute it and/or modify @@ -139,6 +139,24 @@ testrun_on_self() if test $exit_status != 0; then exit $exit_status; fi } +# Compress the files first. Compress both debug sections and symtab. +testrun_on_self_compressed() +{ + exit_status=0 + + for file in $self_test_files; do + tempfiles ${file}z + testrun ${abs_top_builddir}/src/elfcompress -f -q -o ${file}z ${file} + testrun ${abs_top_builddir}/src/elfcompress -f -q --name='.s??tab' ${file}z + + testrun $* ${file}z \ + || { echo "*** failure in $* ${file}z"; exit_status=1; } + done + + # Only exit if something failed + if test $exit_status != 0; then exit $exit_status; fi +} + # Same as above, but redirects stdout to /dev/null testrun_on_self_quiet() { |
