From 3e010bdf21ebb6b8c88cbfe88986bbe20fdee4df Mon Sep 17 00:00:00 2001 From: Petr Machata Date: Wed, 23 Mar 2011 18:44:30 +0100 Subject: [PATCH] dwarflint: Tolerate attributes from all DWARF versions, be less strict --- dwarflint/Makefile.am | 6 ++-- dwarflint/check_debug_abbrev.cc | 31 +++++++++++++----- dwarflint/dwarf_version.cc | 12 +++---- dwarflint/dwarf_version.hh | 3 ++ dwarflint/tests/DW_AT-later-version.bz2 | Bin 0 -> 591 bytes dwarflint/tests/run-DW_AT-later-version.sh | 35 +++++++++++++++++++++ dwarflint/tests/run-bad.sh | 2 +- dwarflint/tests/run-libdl-2.12.so.debug.sh | 10 +++--- 8 files changed, 77 insertions(+), 22 deletions(-) create mode 100644 dwarflint/tests/DW_AT-later-version.bz2 create mode 100755 dwarflint/tests/run-DW_AT-later-version.sh diff --git a/dwarflint/Makefile.am b/dwarflint/Makefile.am index 4317edc32..2247d0e94 100644 --- a/dwarflint/Makefile.am +++ b/dwarflint/Makefile.am @@ -106,7 +106,8 @@ EXTRA_TESTS = tests/run-debug_abbrev-duplicate-attribute.sh \ tests/run-bad.sh \ tests/run-check_self_referential_die.sh \ tests/run-DW_AT_high_pc-relative.sh \ - tests/run-DW_AT_high_pc-below.sh + tests/run-DW_AT_high_pc-below.sh \ + tests/run-DW_AT-later-version.sh TESTS = $(EXTRA_TESTS) \ tests/test-coverage \ @@ -138,7 +139,8 @@ EXTRA_DIST = $(EXTRA_TESTS) \ tests/garbage-12.bz2 \ tests/check_self_referential_die.bz2 \ tests/DW_AT_high_pc-relative.bz2 \ - tests/DW_AT_high_pc-below.bz2 + tests/DW_AT_high_pc-below.bz2 \ + tests/DW_AT-later-version.bz2 installed_TESTS_ENVIRONMENT = libdir=$(DESTDIR)$(libdir) \ bindir=$(DESTDIR)$(bindir) \ diff --git a/dwarflint/check_debug_abbrev.cc b/dwarflint/check_debug_abbrev.cc index 39b5f316d..c8038c6d3 100644 --- a/dwarflint/check_debug_abbrev.cc +++ b/dwarflint/check_debug_abbrev.cc @@ -156,6 +156,7 @@ namespace // Tolerate failure here. dwarf_version const *ver = NULL; + static dwarf_version const *latest_ver = dwarf_version::get_latest (); where.addr1 = 0; bool failed = false; @@ -285,7 +286,7 @@ namespace << "couldn't load CU headers for processing .debug_abbrev; " "assuming latest DWARF flavor." << std::endl; - ver = dwarf_version::get_latest (); + ver = latest_ver; } assert (ver != NULL); @@ -397,11 +398,24 @@ namespace attribute const *attribute = ver->get_attribute (attrib_name); if (attribute == NULL) { - wr_error (where) - << "invalid or unknown name " << pri::hex (attrib_name) - << '.' << std::endl; - // libdw should handle unknown attribute, as long as - // the form is kosher, so don't fail the check. + // GCC commonly emits DWARF 2 with trivial extensions + // (such as attribute names) from newer versions. In + // GNU mode, don't even mind this. In non-gnu, emit + // warning. We explicitly don't do this for forms, + // where the consumer wouldn't know how to read or + // skip the datum. + attribute = latest_ver->get_attribute (attrib_name); + if (attribute == NULL) + // libdw should handle unknown attribute, as long as + // the form is kosher, so don't fail the check. + wr_message (where, mc_abbrevs | mc_impact_1) + << "invalid or unknown name " << pri::hex (attrib_name) + << '.' << std::endl; + else if (opt_nognu) + wr_message (where, mc_abbrevs | mc_impact_1) + << "attribute " << *attribute + << " from later DWARF version." + << std::endl; } form const *form = check_debug_abbrev::check_form @@ -410,7 +424,7 @@ namespace // Error message has been emitted in check_form. failed = true; - if (form == NULL || attribute == NULL) + if (form == NULL) continue; std::pair::iterator, bool> inserted @@ -418,7 +432,8 @@ namespace if (!inserted.second) { wr_error (where) - << "duplicate attribute " << *attribute + << "duplicate attribute " + << elfutils::dwarf::attributes::name (attrib_name) << " (first was at " << pri::hex (inserted.first->second) << ")." << std::endl; // I think we may allow such files for high-level diff --git a/dwarflint/dwarf_version.cc b/dwarflint/dwarf_version.cc index fc4595a65..a74e1699b 100644 --- a/dwarflint/dwarf_version.cc +++ b/dwarflint/dwarf_version.cc @@ -45,6 +45,9 @@ #include "dwarf_mips.hh" #include "check_debug_info.hh" +global_opt + opt_nognu ("Don't use GNU extension.", "nognu"); + dw_class_set::dw_class_set (dw_class a, dw_class b, dw_class c, dw_class d, dw_class e) { @@ -118,7 +121,7 @@ form::width (cu_head const *cu_head) const std::ostream & operator << (std::ostream &os, form const &obj) { - return os << elfutils::dwarf::forms::name (obj.name ()); + return os << elfutils::dwarf::forms::identifier (obj.name ()); } namespace @@ -139,7 +142,7 @@ attribute::attribute (int a_name, dw_class_set const &a_classes) std::ostream & operator << (std::ostream &os, attribute const &obj) { - return os << elfutils::dwarf::attributes::name (obj.name ()); + return os << elfutils::dwarf::attributes::identifier (obj.name ()); } @@ -230,9 +233,6 @@ dwarf_version::extend (dwarf_version const *source, return new dwarf_version_union (source, extension); } -global_opt - nognu ("Don't use GNU extension.", "nognu"); - namespace { dwarf_version const *get_ext () @@ -244,7 +244,7 @@ namespace // need the version to know how to read these attributes in the // first place. - if (nognu) + if (opt_nognu) return dwarf_mips_ext (); else return dwarf_version::extend (dwarf_mips_ext (), dwarf_gnu_ext ()); diff --git a/dwarflint/dwarf_version.hh b/dwarflint/dwarf_version.hh index 43df29e96..f130b8d25 100644 --- a/dwarflint/dwarf_version.hh +++ b/dwarflint/dwarf_version.hh @@ -31,6 +31,9 @@ #include #include "check_debug_info.ii" #include "dwarf_version.ii" +#include "option.hh" + +extern global_opt opt_nognu; enum dw_class { diff --git a/dwarflint/tests/DW_AT-later-version.bz2 b/dwarflint/tests/DW_AT-later-version.bz2 new file mode 100644 index 0000000000000000000000000000000000000000..2a5690b3c6363c39fa3ebe4544fbfcc0d8d76970 GIT binary patch literal 591 zc-jF^0gwss})G}xQGf)5k0ku6QjRvNsO${1m>_7#84QLa zK*^&_T}Eze?5QdsWFo7m^;fJ@hH7vN>cQr=2uPqdL)tp7o)iXf{>Jg@c z@4DzI#*8GCrCD^IXd&tubCtI3clFZV7+Z3+WL8c5x(O5Mi`~dna?+fwdLA1{Mh07A zMPtQj5YW2~2&thU{l6Oq!rxv1xrPrD6&M#7Ll(wvf)WDx^72Fg?wLWF0m@I91W%wLJRCMm}4-`eg~0USAGxvA6%qdcWauafIbK$ zl#xlpq4n(x!mN7YPk{QExKM;tGQ+2C1_VX|K%np#7#OpHO3#tBZ-X(;k9cM)@owQFOqLw3KrIbj%V0 zmMSsN$^c3;oZ>fUU;. + +. $srcdir/../tests/test-subr.sh + +srcdir=$srcdir/tests + +testfiles DW_AT-later-version + +testrun_compare ./dwarflint --nognu DW_AT-later-version <