From: Mark Wielaard Date: Mon, 4 Apr 2011 10:42:21 +0000 (+0200) Subject: dwarflint: linkage_name attributes checking. X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=d2c0eb5359352b687a737bb19ca6dbce7fe5aa31;p=thirdparty%2Felfutils.git dwarflint: linkage_name attributes checking. Dwarf4 introduces DW_AT_linkage_name, which is like DW_AT_MIPS_linkage_name already used by gcc for earlier versions. Mark DW_TAG_common_block, DW_TAG_constant, DW_TAG_entry_point, DW_TAG_subprogram and DW_TAG_variable as optionally having at_linkage_name (either the old or new variant) in expected-at.cc. Add new check_linkage_external_die.cc to find DIEs with linkage_name set, but not marked DW_AT_external. --- diff --git a/dwarflint/Makefile.am b/dwarflint/Makefile.am index b4164ddf0..d7def5dbf 100644 --- a/dwarflint/Makefile.am +++ b/dwarflint/Makefile.am @@ -85,6 +85,7 @@ dwarflint_SOURCES = \ check_nodebug.cc \ check_range_out_of_scope.cc \ check_self_referential_die.cc \ + check_linkage_external_die.cc \ locstats.cc \ lowlevel_checks.cc lowlevel_checks.hh \ \ diff --git a/dwarflint/check_linkage_external_die.cc b/dwarflint/check_linkage_external_die.cc new file mode 100644 index 000000000..e18d0e973 --- /dev/null +++ b/dwarflint/check_linkage_external_die.cc @@ -0,0 +1,79 @@ +/* Check that every die that has a linkage_name is also external. + 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 + . */ + +#ifdef HAVE_CONFIG_H +# include +#endif + +#include "highlevel_check.hh" +#include "../src/dwarfstrings.h" +#include "all-dies-it.hh" +#include "pri.hh" +#include "messages.hh" +#include + +using elfutils::dwarf; + +namespace +{ + class check_linkage_external_die + : public highlevel_check + { + public: + static checkdescriptor const *descriptor () + { + static checkdescriptor cd + (checkdescriptor::create ("check_linkage_external_die") + .inherit > () + .description ( +"Check that each DIE that has a linkage_name also has an external attribute.\n" + )); + return &cd; + } + + explicit check_linkage_external_die (checkstack &stack, dwarflint &lint) + : highlevel_check (stack, lint) + { + for (all_dies_iterator it = all_dies_iterator (dw); + it != all_dies_iterator (); ++it) + { + dwarf::debug_info_entry const &die = *it; + dwarf::debug_info_entry::attributes_type attrs = die.attributes (); + if ((attrs.find (DW_AT_linkage_name) != attrs.end () + || attrs.find (DW_AT_MIPS_linkage_name) != attrs.end ()) + && attrs.find (DW_AT_external) == attrs.end ()) + { + wr_message (to_where (die), + mc_impact_3 | mc_acc_suboptimal | mc_die_other) + << elfutils::dwarf::tags::name (die.tag ()) + << " has linkage_name attribute, but no external attribute." + << std::endl; + } + } + } + }; + + reg reg; +} diff --git a/dwarflint/expected-at.cc b/dwarflint/expected-at.cc index 7a433c722..72a2104b2 100644 --- a/dwarflint/expected-at.cc +++ b/dwarflint/expected-at.cc @@ -1,5 +1,5 @@ /* Pedantic checking of DWARF files. - Copyright (C) 2009 Red Hat, Inc. + Copyright (C) 2009, 2011 Red Hat, Inc. This file is part of Red Hat elfutils. Written by Petr Machata , 2009. @@ -35,6 +35,10 @@ expected_at_map::expected_at_map () at_set_decl.insert (DW_AT_decl_file); at_set_decl.insert (DW_AT_decl_line); + std::set at_linkage_name; + at_linkage_name.insert (DW_AT_MIPS_linkage_name); + at_linkage_name.insert (DW_AT_linkage_name); + m_map [DW_TAG_access_declaration] .optional (at_set_decl) .optional (DW_AT_accessibility) @@ -120,6 +124,7 @@ expected_at_map::expected_at_map () .optional (DW_AT_segment) .optional (DW_AT_sibling) .optional (DW_AT_visibility) + .optional (at_linkage_name) ; m_map [DW_TAG_common_inclusion] @@ -175,6 +180,7 @@ expected_at_map::expected_at_map () .optional (DW_AT_start_scope) .optional (DW_AT_type) .optional (DW_AT_visibility) + .optional (at_linkage_name) ; m_map [DW_TAG_dwarf_procedure] @@ -195,6 +201,7 @@ expected_at_map::expected_at_map () .optional (DW_AT_GNU_all_tail_call_sites) .optional (DW_AT_GNU_all_call_sites) .optional (DW_AT_GNU_all_source_call_sites) + .optional (at_linkage_name) ; m_map [DW_TAG_enumeration_type] @@ -341,6 +348,9 @@ expected_at_map::expected_at_map () .optional (DW_AT_sibling) ; + // At one time gcc did emit at_linkage_name for members, but that + // has been corrected: + // http://gcc.gnu.org/ml/gcc-patches/2010-06/msg01713.html m_map [DW_TAG_member] .optional (at_set_decl) .optional (DW_AT_accessibility) @@ -355,10 +365,6 @@ expected_at_map::expected_at_map () .optional (DW_AT_sibling) .optional (DW_AT_type) .optional (DW_AT_visibility) - .optional (DW_AT_MIPS_linkage_name) // xxx - .optional (DW_AT_external) // xxx - .optional (DW_AT_const_value) // xxx - .optional (DW_AT_artificial) // xxx ; m_map [DW_TAG_module] @@ -572,7 +578,7 @@ expected_at_map::expected_at_map () .optional (DW_AT_visibility) .optional (DW_AT_virtuality) .optional (DW_AT_vtable_elem_location) - .optional (DW_AT_MIPS_linkage_name) // XXX added to reflect reality + .optional (at_linkage_name) .optional (DW_AT_containing_type) // XXX added to reflect reality .optional (DW_AT_GNU_all_tail_call_sites) .optional (DW_AT_GNU_all_call_sites) @@ -717,7 +723,7 @@ expected_at_map::expected_at_map () .optional (DW_AT_start_scope) .optional (DW_AT_type) .optional (DW_AT_visibility) - .optional (DW_AT_MIPS_linkage_name) // XXX added to reflect reality + .optional (at_linkage_name) .optional (DW_AT_artificial) // XXX added to reflect reality ;