From: Petr Machata Date: Wed, 23 Mar 2011 17:44:30 +0000 (+0100) Subject: dwarflint: Tolerate attributes from all DWARF versions, be less strict X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=3e010bdf21ebb6b8c88cbfe88986bbe20fdee4df;p=thirdparty%2Felfutils.git dwarflint: Tolerate attributes from all DWARF versions, be less strict --- 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 000000000..2a5690b3c Binary files /dev/null and b/dwarflint/tests/DW_AT-later-version.bz2 differ diff --git a/dwarflint/tests/run-DW_AT-later-version.sh b/dwarflint/tests/run-DW_AT-later-version.sh new file mode 100755 index 000000000..b2f026580 --- /dev/null +++ b/dwarflint/tests/run-DW_AT-later-version.sh @@ -0,0 +1,35 @@ +#! /bin/sh +# Copyright (C) 2011 Red Hat, Inc. +# This file is part of Red Hat elfutils. +# +# Red Hat elfutils 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; version 2 of the License. +# +# Red Hat 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 Red Hat elfutils; if not, write to the Free Software Foundation, +# Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301 USA. +# +# Red Hat elfutils is an included package of the Open Invention Network. +# An included package of the Open Invention Network is a package for which +# Open Invention Network licensees cross-license their patents. No patent +# license is granted, either expressly or impliedly, by designation as an +# included package. Should you wish to participate in the Open Invention +# Network licensing program, please visit www.openinventionnetwork.com +# . + +. $srcdir/../tests/test-subr.sh + +srcdir=$srcdir/tests + +testfiles DW_AT-later-version + +testrun_compare ./dwarflint --nognu DW_AT-later-version <