libabigail/include/abg-tools-utils.h
Dodji Seketeli 90b4e7676c PR23641 - Type definition DIE matched by a supprspec but not its decl
Suppose we have two versions of a library which are almost identical.
Suppose the difference between the two binaries is a slight difference of
ordering in how the linker put together what the DWARF describes.

Then, while processing the debug info of the first library, libabigail
first comes across the forward declaration of a type T.  Suppose that
declaration is not matched by any private type suppression
specification.  Libabigail is going to keep the declaration of T and
build an internal representation (IR) for it.  It's also going to
build an IR for types and decls using T like "T*" or "T* var".

Now suppose that while processing the debug info of the second
library, libabigail first comes across the *definition* of T --
because in this second library, that definition comes first.  Suppose
that the definition is matched by a private type suppression
specification, unlike the declaration in the first library.  In this
case, T is going to be dropped, and no IR is going to be built for it.
If other types or decl like 'T*' or 'T *var" refer to this
*definition* of T, they will be dropped too.

We'll end up with those two libraries that are identical (modulo the
order in which libabigail sees type declarations and their
definitions) and are considered different when a suppression
specification makes us drop T: the second library appears to
libabigail as if T was removed from it.

This is the problem addressed by this patch.

When the definition of a type T is suppressed because it's considered
private then we look if there was a forward declaration for it
elsewhere, that is not matched by the private type suppression
specification.  If we encountered such a type declaration then it
means that declaration is in effect an "opaque" version of T.  So
rather than just dropping T altogether, we keep (and build an IR) for
its opaque version only.  And we drop the definition of T.

This seems to fix the issue.

I can't seem to reproduce the slight re-ordering of DIEs descriptions that
uncover the issue so I'll rely on integration tests to catch future
regressions on this issue, rather than on unit tests.  Sigh.

	* include/abg-tools-utils.h (PRIVATE_TYPES_SUPPR_SPEC_NAME):
	Remove this extern constant definition.
	* src/abg-dwarf-reader.cc (type_is_suppressed): Add an overload
	that takes an additional type_is_private output parameter.
	(get_opaque_version_of_type): New static function.
	(build_ir_node_from_die): For class types, get the opaque version
	for suppressed private types rather than dropping them altogether.
	* src/abg-reader.cc (type_is_suppressed): Adjust.
	* src/abg-suppression-priv.h (type_is_suppressed): Add an overload
	that takes a type_is_private output parameter.
	* include/abg-suppression.h (get_private_types_suppr_spec_label)
	(is_private_type_suppr_spec): Declare new functions.
	* src/abg-suppression.cc
	(get_private_types_suppr_spec_label, is_private_type_suppr_spec):
	Define new functions.
	(suppression_matches_type_name_or_location): Use the new
	get_private_types_suppr_spec_label rather than a global extern
	variable.
	* src/abg-tools-utils.cc (handle_fts_entry): Adjust to use the new
	get_private_types_suppr_spec_label.
	(gen_suppr_spec_from_headers): Handle the case or an empty headers
	root dir.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2018-09-21 17:56:48 +02:00

291 lines
7.8 KiB
C++

// -*- Mode: C++ -*-
//
// Copyright (C) 2013-2018 Red Hat, Inc.
//
// This file is part of the GNU Application Binary Interface Generic
// Analysis and Instrumentation Library (libabigail). This library is
// free software; you can redistribute it and/or modify it under the
// terms of the GNU Lesser General Public License as published by the
// Free Software Foundation; either version 3, or (at your option) any
// later version.
// This library 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 Lesser Public License for more details.
// You should have received a copy of the GNU Lesser General Public
// License along with this program; see the file COPYING-LGPLV3. If
// not, see <http://www.gnu.org/licenses/>.
///@file
#include <tr1/memory>
#include <string>
#include <set>
#include <ostream>
#include <istream>
#include <iostream>
#include <abg-suppression.h>
namespace abigail
{
namespace tools_utils
{
using std::ostream;
using std::istream;
using std::ifstream;
using std::string;
using std::set;
using std::tr1::shared_ptr;
const char* get_system_libdir();
bool file_exists(const string&);
bool is_regular_file(const string&);
bool is_dir(const string&);
bool dir_exists(const string&);
bool dir_is_empty(const string &);
bool maybe_get_symlink_target_file_path(const string& file_path,
string& target_path);
bool base_name(string const& path,
string& file_name);
bool dir_name(string const &path,
string& path_dir_name,
bool keep_separator_at_end=false);
void real_path(const string&path, string& realpath);
bool ensure_dir_path_created(const string&);
bool ensure_parent_dir_created(const string&);
ostream& emit_prefix(const string& prog_name, ostream& out);
bool check_file(const string& path, ostream& out, const string& prog_name = "");
bool check_dir(const string& path, ostream& out, const string& prog_name="");
bool string_ends_with(const string&, const string&);
bool string_begins_with(const string&, const string&);
bool string_is_ascii(const string&);
bool string_is_ascii_identifier(const string&);
bool split_string(const string&, const string&, vector<string>&);
bool string_suffix(const string&, const string&, string&);
bool sorted_strings_common_prefix(vector<string>&, string&);
string get_library_version_string();
bool execute_command_and_get_output(const string&, vector<string>&);
bool get_dsos_provided_by_rpm(const string& rpm_path,
set<string>& provided_dsos);
string trim_white_space(const string&);
suppr::type_suppression_sptr
gen_suppr_spec_from_headers(const string& hdrs_root_dir);
bool
gen_suppr_spec_from_kernel_abi_whitelist(const string& abi_whitelist_path,
suppr::suppressions_type& s);
bool
get_vmlinux_path_from_kernel_dist(const string& from,
string& vmlinux_path);
bool
get_binary_paths_from_kernel_dist(const string& dist_root,
const string& debug_info_root_path,
string& vmlinux_path,
vector<string>& module_paths);
bool
get_binary_paths_from_kernel_dist(const string& dist_root,
string& vmlinux_path,
vector<string>& module_paths);
string
get_default_system_suppression_file_path();
string
get_default_user_suppression_file_path();
void
load_default_system_suppressions(suppr::suppressions_type&);
void
load_default_user_suppressions(suppr::suppressions_type&);
class temp_file;
/// Convenience typedef for a shared_ptr to @ref temp_file.
typedef shared_ptr<temp_file> temp_file_sptr;
/// A temporary file.
///
/// This is a helper file around the mkstemp API.
///
/// Once the temporary file is created, users can interact with it
/// using an iostream. They can also get the path to the newly
/// created temporary file.
///
/// When the instance of @ref temp_file is destroyed, the underlying
/// resources are de-allocated, the underlying temporary file is
/// closed and removed.
class temp_file
{
struct priv;
typedef shared_ptr<priv> priv_sptr;
priv_sptr priv_;
temp_file();
public:
bool
is_good() const;
const char*
get_path() const;
std::iostream&
get_stream();
static temp_file_sptr
create();
}; // end class temp_file
size_t
get_random_number();
string
get_random_number_as_string();
/// The different types of files understood the bi* suite of tools.
enum file_type
{
/// A file type we don't know about.
FILE_TYPE_UNKNOWN,
/// The native xml file format representing a translation unit.
FILE_TYPE_NATIVE_BI,
/// An elf file. Read this kind of file should yield an
/// abigail::corpus type.
FILE_TYPE_ELF,
/// An archive (AR) file.
FILE_TYPE_AR,
// A native abixml file format representing a corpus of one or
// several translation units.
FILE_TYPE_XML_CORPUS,
// A native abixml file format representing a corpus group of one or
// several corpora.
FILE_TYPE_XML_CORPUS_GROUP,
// A zip file, possibly containing a corpus of one of several
// translation units.
FILE_TYPE_ZIP_CORPUS,
/// An RPM (.rpm) binary file
FILE_TYPE_RPM,
/// An SRPM (.src.rpm) file
FILE_TYPE_SRPM,
/// A DEB (.deb) binary file
FILE_TYPE_DEB,
/// A plain directory
FILE_TYPE_DIR,
/// A tar archive. The archive can be compressed with the popular
/// compression schemes recognized by GNU tar.
FILE_TYPE_TAR
};
/// Exit status for abidiff and abicompat tools.
///
/// It's actually a bit mask. The value of each enumerator is a power
/// of two.
enum abidiff_status
{
/// This is for when the compared ABIs are equal.
///
/// Its numerical value is 0.
ABIDIFF_OK = 0,
/// This bit is set if there an application error.
///
/// Its numerical value is 1.
ABIDIFF_ERROR = 1,
/// This bit is set if the tool is invoked in an non appropriate
/// manner.
///
/// Its numerical value is 2.
ABIDIFF_USAGE_ERROR = 1 << 1,
/// This bit is set if the ABIs being compared are different.
///
/// Its numerical value is 4.
ABIDIFF_ABI_CHANGE = 1 << 2,
/// This bit is set if the ABIs being compared are different *and*
/// are incompatible.
///
/// Its numerical value is 8.
ABIDIFF_ABI_INCOMPATIBLE_CHANGE = 1 << 3
};
abidiff_status
operator|(abidiff_status, abidiff_status);
abidiff_status
operator&(abidiff_status, abidiff_status);
abidiff_status&
operator|=(abidiff_status&l, abidiff_status r);
bool
abidiff_status_has_error(abidiff_status s);
bool
abidiff_status_has_abi_change(abidiff_status s);
bool
abidiff_status_has_incompatible_abi_change(abidiff_status s);
ostream&
operator<<(ostream& output, file_type r);
file_type guess_file_type(istream& in);
file_type guess_file_type(const string& file_path);
bool
get_rpm_name(const string& str, string& name);
bool
get_rpm_arch(const string& str, string& arch);
bool
get_deb_name(const string& str, string& name);
bool
file_is_kernel_package(const string& file_path,
file_type file_type);
bool
file_is_kernel_debuginfo_package(const string& file_path,
file_type file_type);
std::tr1::shared_ptr<char>
make_path_absolute(const char*p);
corpus_group_sptr
build_corpus_group_from_kernel_dist_under(const string& root,
const string debug_info_root,
const string& vmlinux_path,
vector<string>& suppr_paths,
vector<string>& kabi_wl_paths,
suppr::suppressions_type& supprs,
bool verbose,
environment_sptr& env);
}// end namespace tools_utils
/// A macro that expands to aborting the program when executed.
///
/// Before aborting, the macro emits informatin about the source
/// location where it was expanded.
#define ABG_ASSERT_NOT_REACHED \
do { \
std::cerr << "in " << __FUNCTION__ \
<< " at: " << __FILE__ << ":" << __LINE__ \
<< ": execution should not have reached this point!\n"; \
abort(); \
} while (false)
}//end namespace abigail