Commit Graph

218 Commits

Author SHA1 Message Date
Dodji Seketeli
9b4d20db90 Bug 18342 - Segmentation fault while comparing functions with variadic parameters
In the IR built from DWARF, a variadic variadic parameter has an empty
type.  Later during type comparison, comparing an empty (NULL) type
with other types proves to be troublesome.

This patch handles the issue by creating a new kind of
abigail::type_decl type specifically for variadic parameters.  This is
like what is done for void types.

After that it appears that the categorizing sub-system flags a change
of variadic type to non-variadic type as redundant if that change
appears several times on different functions.  We don't want that
because it can hide important changes we want to see.  The patch fixes
that too.

	* include/abg-fwd.h (is_array_type): New overload for a naked
	pointer.
	* include/abg-ir.h (type_decl::get_variadic_parameter_type_decl): Declare new
	static function.
	* src/abg-ir.cc (is_array_type): Define new function overload for
	naked pointers
	(type_decl::get_variadic_parameter_type_decl): Define new static
	function.
	* src/abg-dwarf-reader.cc (build_function_decl): The type of
	variadic parameter is now a special type_decl.
	* include/abg-comparison.h (is_diff_of_variadic_parameter_type)
	(is_diff_of_variadic_parameter): New function declarations.
	* src/abg-comparison.cc (is_diff_of_variadic_parameter_type)
	(is_diff_of_variadic_parameter): Define new functions.
	(compute_diff): Refuse to return a NULL
	diff for types.  Assert that the parameters are non-NULL.
	(report_size_and_alignment_changes): We are comparing arrays only
	if the two parameters are arrays.
	(fn_parm_diff::fn_parm_diff): Refuse that type diff for this diff
	node is non empty.
	(fn_parm_diff::report): Strengthen an assert.  Cleanup a comment.
	(redundancy_marking_visitor::visit_begin): Do not mark function
	type and variadic parms diff nodes as redundant for local changes.
	* tests/data/test-diff-dwarf/libtest26-added-parms-before-variadic-v{0,1}.so:
	New test input binaries.
	* tests/data/test-diff-dwarf/test26-added-parms-before-variadic-report.txt:
	New test output reference.
	* tests/data/test-diff-dwarf/test26-added-parms-before-variadic-v{0,1}.c:
	Source code of the new test input binaries above.
	* tests/data/Makefile.am: Add the new test stuff to source
	distribution.
	* tests/test-diff-dwarf.cc (in_out_specs): Add the new test inputs
	above to the set of input to run this test harness over.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2015-05-05 10:45:06 +02:00
Dodji Seketeli
18bbfb5ec3 Fix archive writing support
The runtestwritereadarchive test is failing on Rawhide (Fedora 23) for
me now.  It appears it was because the content to write to the zip
archive is in a buffer which is stored in a vector of buffers.

When the vector grows, the buffers are potentially copied over, and
the old buffers are destroyed, making the address of the old buffers
being stalled.  But then those old address are used by the code that
write stuff in the zip archive.  Ooops.

This patch essentially replaces the vector of buffer with a list, so
that growing the list doesn't invalidate the buffers.  The patch also
does away with using deprecated APIs of libzip.

	* configure.ac: Require libzip 0.10.1 at least.
	* src/abg-writer.cc (archive_write_ctxt::serialized_tus): Make
	this be a list<string>, rather than a vector<string>.
	(create_archive_write_context): Truncate the archive if it exists
	already.
	(write_translation_unit_to_archive): Do not use the deprecated
	zip_add() function anymore.  Rather, use zip_file_add().
	* tests/test-write-read-archive.cc (main): Double check if the
	translation unit we read is empty or not.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2015-04-24 19:59:19 +02:00
Dodji Seketeli
6baecca506 18252 - Added parameters are not properly sorted
In the changed functions/variables section of the abidiff report, when
function parameters were added or removed, they were not properly
sorted.  This patch fixes that.

	* src/abg-comparison.cc (sort_string_parm_map): Define new static
	function.
	(struct parm_comp): Define new type.
	(function_type_diff::priv::{sorted_deleted_parms_,
	sorted_added_parms_}): New data members that hold sorted
	deleted/added parameters.
	(function_type_diff::ensure_lookup_tables_populated): Initialize
	the two new data members above.
	(function_type_diff::report): For the report of parameters that
	got added/removed, use the sorted set of added/removed parameters
	above.
	* tests/data/test-diff-dwarf/test24-added-fn-parms-report-0.txt:
	New test input.
	* tests/data/test-diff-dwarf/libtest24-added-fn-parms-v{0,1}.so:
	Likewise.
	* tests/data/test-diff-dwarf/test25-removed-fn-parms-report-0.txt:
	Likewise.
	* tests/data/test-diff-dwarf/libtest25-removed-fn-parms-v{0,1}.so:
	Likewise.
	* tests/data/test-diff-dwarf/test24-added-fn-parms-v{0,1}.c:
	Likewise.
	* tests/data/test-diff-dwarf/test25-removed-fn-parms-v{0,1}.c:
	Likewise.
	* tests/data/Makefile.am: Add the new test material above to the
	source distribution.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2015-04-15 15:21:56 +02:00
Dodji Seketeli
21adfb066f Misc reporting fixes/improvements
This patch contains various reporting improvement about how variables
and data member changes are represented, as well as how type changes
are represented.  The number changes itself is not that big, but the
number of adjustments to regression test is.

	* src/abg-comparison.cc (distinct_diff::report): Remove spurious
	vertical space before reporting size and alignment changes here.
	(represent): In the variables/data member overload, report type
	changes first.  Then the other changes.
	(report_size_and_alignment_changes): Make this report array size
	changes too.  Also, make some small adjustments about how type
	size/alignment changes are introduced.
	(array_diff::report): Now that report_size_and_alignment_changes()
	supports size change reporting, just use that function rather than
	doing it here.
	(corpus_diff::report): Consistently add a space between each
	changed function report.  Prefix changed variables with a [C],
	just like for functions.
	* tests/data/test-abicompat/test0-fn-changed-report-0.txt: Adjust.
	* tests/data/test-abicompat/test5-fn-changed-report-0.txt: Likewise.
	* tests/data/test-abicompat/test6-var-changed-report-0.txt: Likewise.
	* tests/data/test-abidiff/test-qual-type0-report.txt: Likewise.
	* tests/data/test-abidiff/test-struct0-report.txt: Likewise.
	* tests/data/test-abidiff/test-struct1-report.txt: Likewise.
	* tests/data/test-abidiff/test-var0-report.txt: Likewise.
	* tests/data/test-diff-dwarf/test-23-diff-arch-report-0.txt: Likewise.
	* tests/data/test-diff-dwarf/test0-report.txt: Likewise.
	* tests/data/test-diff-dwarf/test1-report.txt: Likewise.
	* tests/data/test-diff-dwarf/test10-report.txt: Likewise.
	* tests/data/test-diff-dwarf/test11-report.txt: Likewise.
	* tests/data/test-diff-dwarf/test13-report.txt: Likewise.
	* tests/data/test-diff-dwarf/test15-enum-report.txt: Likewise.
	* tests/data/test-diff-dwarf/test2-report.txt: Likewise.
	* tests/data/test-diff-dwarf/test20-add-fn-parm-report-0.txt: Likewise.
	* tests/data/test-diff-dwarf/test21-redundant-fn-report-0.txt: Likewise.
	* tests/data/test-diff-dwarf/test22-changed-parm-c-report-0.txt: Likewise.
	* tests/data/test-diff-dwarf/test3-report.txt: Likewise.
	* tests/data/test-diff-dwarf/test6-report.txt: Likewise.
	* tests/data/test-diff-dwarf/test7-report.txt: Likewise.
	* tests/data/test-diff-dwarf/test8-report.txt: Likewise.
	* tests/data/test-diff-dwarf/test9-report.txt: Likewise.
	* tests/data/test-diff-filter/test0-report.txt: Likewise.
	* tests/data/test-diff-filter/test01-report.txt: Likewise.
	* tests/data/test-diff-filter/test1-report.txt: Likewise.
	* tests/data/test-diff-filter/test10-report.txt: Likewise.
	* tests/data/test-diff-filter/test11-report.txt: Likewise.
	* tests/data/test-diff-filter/test13-report.txt: Likewise.
	* tests/data/test-diff-filter/test14-0-report.txt: Likewise.
	* tests/data/test-diff-filter/test14-1-report.txt: Likewise.
	* tests/data/test-diff-filter/test15-0-report.txt: Likewise.
	* tests/data/test-diff-filter/test15-1-report.txt: Likewise.
	* tests/data/test-diff-filter/test16-report-2.txt: Likewise.
	* tests/data/test-diff-filter/test16-report.txt: Likewise.
	* tests/data/test-diff-filter/test17-0-report.txt: Likewise.
	* tests/data/test-diff-filter/test17-1-report.txt: Likewise.
	* tests/data/test-diff-filter/test18-report.txt: Likewise.
	* tests/data/test-diff-filter/test19-enum-report-1.txt: Likewise.
	* tests/data/test-diff-filter/test2-report.txt: Likewise.
	* tests/data/test-diff-filter/test20-inline-report-1.txt: Likewise.
	* tests/data/test-diff-filter/test21-compatible-vars-report-0.txt: Likewise.
	* tests/data/test-diff-filter/test22-compatible-fns-report-0.txt: Likewise.
	* tests/data/test-diff-filter/test23-redundant-fn-parm-change-report-0.txt: Likewise.
	* tests/data/test-diff-filter/test24-compatible-vars-report-1.txt: Likewise.
	* tests/data/test-diff-filter/test25-cyclic-type-report-0.txt: Likewise.
	* tests/data/test-diff-filter/test25-cyclic-type-report-1.txt: Likewise.
	* tests/data/test-diff-filter/test26-qualified-redundant-node-report-0.txt: Likewise.
	* tests/data/test-diff-filter/test26-qualified-redundant-node-report-1.txt: Likewise.
	* tests/data/test-diff-filter/test27-redundant-and-filtered-children-nodes-report-0.txt: Likewise.
	* tests/data/test-diff-filter/test27-redundant-and-filtered-children-nodes-report-1.txt: Likewise.
	* tests/data/test-diff-filter/test27-redundant-and-filtered-children-nodes-report-2.txt: Likewise.
	* tests/data/test-diff-filter/test28-redundant-and-filtered-children-nodes-report-0.txt: Likewise.
	* tests/data/test-diff-filter/test28-redundant-and-filtered-children-nodes-report-1.txt: Likewise.
	* tests/data/test-diff-filter/test3-report.txt: Likewise.
	* tests/data/test-diff-filter/test6-report.txt: Likewise.
	* tests/data/test-diff-filter/test9-report.txt: Likewise.
	* tests/data/test-diff-suppr/test0-type-suppr-report-0.txt: Likewise.
	* tests/data/test-diff-suppr/test0-type-suppr-report-3.txt: Likewise.
	* tests/data/test-diff-suppr/test1-typedef-suppr-report-0.txt: Likewise.
	* tests/data/test-diff-suppr/test1-typedef-suppr-report-2.txt: Likewise.
	* tests/data/test-diff-suppr/test10-changed-parm-c-report-0.txt: Likewise.
	* tests/data/test-diff-suppr/test2-struct-suppr-report-0.txt: Likewise.
	* tests/data/test-diff-suppr/test3-struct-suppr-report-0.txt: Likewise.
	* tests/data/test-diff-suppr/test3-struct-suppr-report-1.txt: Likewise.
	* tests/data/test-diff-suppr/test3-struct-suppr-report-2.txt: Likewise.
	* tests/data/test-diff-suppr/test4-local-suppr-report-0.txt: Likewise.
	* tests/data/test-diff-suppr/test4-local-suppr-report-1.txt: Likewise.
	* tests/data/test-diff-suppr/test5-fn-suppr-report-0.txt: Likewise.
	* tests/data/test-diff-suppr/test5-fn-suppr-report-1.txt: Likewise.
	* tests/data/test-diff-suppr/test5-fn-suppr-report-2.txt: Likewise.
	* tests/data/test-diff-suppr/test5-fn-suppr-report-3.txt: Likewise.
	* tests/data/test-diff-suppr/test5-fn-suppr-report-4.txt: Likewise.
	* tests/data/test-diff-suppr/test5-fn-suppr-report-5.txt: Likewise.
	* tests/data/test-diff-suppr/test6-fn-suppr-report-0.txt: Likewise.
	* tests/data/test-diff-suppr/test6-fn-suppr-report-1.txt: Likewise.
	* tests/data/test-diff-suppr/test6-fn-suppr-report-2.txt: Likewise.
	* tests/data/test-diff-suppr/test6-fn-suppr-report-3.txt: Likewise.
	* tests/data/test-diff-suppr/test7-var-suppr-report-0.txt: Likewise.
	* tests/data/test-diff-suppr/test7-var-suppr-report-1.txt: Likewise.
	* tests/data/test-diff-suppr/test7-var-suppr-report-2.txt: Likewise.
	* tests/data/test-diff-suppr/test7-var-suppr-report-3.txt: Likewise.
	* tests/data/test-diff-suppr/test7-var-suppr-report-4.txt: Likewise.
	* tests/data/test-diff-suppr/test7-var-suppr-report-7.txt: Likewise.
	* tests/data/test-diff-suppr/test7-var-suppr-report-8.txt: Likewise.
	* tests/data/test-diff-suppr/test8-redundant-fn-report-0.txt: Likewise.
	* tests/data/test-diff-suppr/test8-redundant-fn-report-1.txt: Likewise.
	* tests/data/test-diff-suppr/test9-changed-parm-c-report-0.txt: Likewise.
	* tests/data/test-diff-suppr/test9-changed-parm-c-report-1.txt: Likewise.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2015-04-14 06:16:00 +02:00
Dodji Seketeli
fc55e7f343 Make abidiff and abicompat return meaningful exit codes
As per https://sourceware.org/bugzilla/show_bug.cgi?id=18146, abidiff
the exit code of abidiff and abicompat is now a bit field that can be
inspected to know if the ABI change reported is incompatible for sure,
or if it needs user review of the output to decide.

This patch also updates the documentation.

	* doc/manuals/abicompat.rst: Update documentation for abicompat
	exit codes.
	* doc/manuals/abidiff.rst: Likewise for abidiff exit codes.
	* include/abg-tools-utils.h (enum abidiff_status): Declare new
	enum.
	(operator{|,&,|=}): Declare new operators for the new enum
	abidiff_status.
	(abidiff_status_has_error, abidiff_status_has_abi_change)
	(abidiff_status_has_incompatible_abi_change): Declare new
	functions.
	* src/abg-tools-utils.cc (operator{|,&,|=}): Define these new
	operators.
	(abidiff_status_has_error, abidiff_status_has_abi_change)
	(abidiff_status_has_incompatible_abi_change): Define new
	functions.
	* tests/test-diff-filter.cc (main): Adjust for the new exit code
	of abidiff.
	* tests/test-diff-suppr.cc (main): Likewise.
	* tests/test-abicompat.cc (main): Likewise.
	* tools/abicompat.cc (enum abicompat_status): Remove.
	(operator{|,&,|=}): Remove these operators for enum
	abicompat_status.
	(perform_compat_check_in_normal_mode)
	(perform_compat_check_in_weak_mode): Return abidiff_status instead
	of abicompat_status.  Adjust therefore.
	(main): Adjust to return abidiff_status now, instead of a just
	zero for all non-error cases.
	* tools/abidiff.cc (main): Likewise.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2015-04-10 16:26:36 +02:00
Dodji Seketeli
a102a2f032 Add support for abicompat weak mode
This patch implements the weak mode of abicompat.  In this mode, just
the application and the new version of the library are provided.  The
types of functions and variables of the library that are consumed by
the application are compared to the types of the functions and
variables expected by the application.  The goal is to check if the
types of the declarations consumed by the application and provided by
the library are compatible with what the application expects.

The abicompat first gets the set of symbols undefined in the
application and exported by the library.  It then builds the set of
declarations exported by the library that have those symbols.  We call
these the set of declarations of the library that are consumed by the
application.

Note that the debug information for the application does not contain
the declarations of the functions/variables whose symbols are
undefined.  So we can not just read them to compare them to
declarations exported by the library.

But the *types* of the variables and the *sub-types* of the functions
whose symbols are undefined in the application are present in the
debug information of the application.

So in the weak mode, abicompat compare the *types* of the declarations
consumed by the application as expected by the application (described
by the debug information of the application) with the types of the
declarations exported by the library.

To do this a number of changes were necessary.

The patch builds a representation of all the types found in the
application's debug info.  Before that, only the types that are
reachable from exported declarations were represented.

The abidw tool got a new --load-all-types to test this new ability of
loading all types.

The patch also adds support for looking a type, not by name, but by
its internal representation.

In the comparison engine, function_type_diff is introduced to
represent changes between two function types.  For this, a new class
type_or_decl_base has been introduced in the IR.  It's now the base
class for both decl_base and type_base.  And abigail::comparison::diff
now takes two pointers of type_or_decl, not decl_base anymore.  So
function_type_diff can take two function_type now; not that a
function_type has no declaration so it doesn't inherit decl_base.  A
bunch of changes got made just to adjust to this modification.

A number of fixes were made too, to make this work, like adding
missing comparison operators, removing asserts that too strong, etc..

The patch also adjust the test suite as well as the documentation.

	* include/abg-fwd.h (class type_or_decl_base): Forward declare
	this.
	(is_decl, is_type, is_function_type, get_name, get_type_name)
	(get_function_type_name, get_pretty_representation)
	(lookup_function_type_in_corpus, lookup_type_in_translation_unit)
	(lookup_function_type_in_translation_unit)
	(synthesize_function_type_from_translation_unit)
	(hash_type_or_decl): New function declarations.
	* src/abg-corpus.cc (lookup_type_in_corpus)
	(lookup_function_type_in_corpus): Define new functions.
	* include/abg-ir.h
	(translation_unit::lookup_function_type_in_translation_unit):
	Declare new friend function.
	(class type_or_decl_base): Declare this.
	(operator==(const type_or_decl_base&, const type_or_decl_base&)):
	Declare new operator.
	(operator==(const type_or_decl_base_sptr&, const
	type_or_decl_base_sptr&)): Likewise.
	(class {decl_base, type_base}): Make these class inherit
	type_or_decl_base.
	(decl_base::get_member_scopes): New const overload.
	(bool operator==(const function_decl::parameter_sptr&,
	                 const function_decl::parameter_sptr&)): New operator.
	(function_type::get_parameters): Remove the non-const overload.
	(function_type::get_pretty_representation): Declare new member
	function.
	(method_type::get_pretty_representation): Likewise.
	* src/abg-ir.cc (bool operator==(const type_or_decl_base&, const
	type_or_decl_base&)): Define new equality operator.
	(bool operator==(const type_or_decl_base_sptr&, const
	type_or_decl_base_sptr&)): Likewise.
	(strip_typedef): Do not expect canonicalized types anymore.  Now
	the system accepts (and expects) canonicalized types in certain
	cases.  For instance, non-complete types and aggregated types that
	contain non-complete sub-types.
	(get_name, get_function_type_name, get_type_name)
	(get_pretty_representation, is_decl, is_type, is_function_type)
	(lookup_function_type_in_translation_unit)
	(synthesize_function_type_from_translation_unit)
	(lookup_type_in_scope, lookup_type_in_translation_unit): Define
	new functions or new overloads.
	(bool operator==(const function_decl::parameter_sptr&,
	                 const function_decl::parameter_sptr& r)): Define
	new operator.
	(function_type::get_parameters): Remove non-const overload.
	(function_type::get_pretty_representation): Define new function.
	(function_type::traverse): Adjust.
	(method_type::get_pretty_representation): Likewise.
	(function_decl::get_pretty_representation): Avoid emitting the
	type of cdtors.
	(hash_type_or_decl): Define new function.
	* include/abg-dwarf-reader.h (create_read_context)
	(read_corpus_from_elf): Take a new 'read_all_types' flag.
	* src/abg-dwarf-reader.cc (read_context::load_all_types_): New
	flag.
	(read_context::read_context): Initialize it.
	(read_context::canonical_types_scheduled): If some types still
	have non-canonicalized sub-types, then do not canonicalize them.
	(read_context::load_all_types): New member functions.
	(build_function_decl): Do not represent void return type like
	empty type anymore, rather, represent it like a void type node.
	(build_ir_node_from_die): When asked, load all types
	including those that are not reachable from an exported
	declaration.
	(create_read_context, read_corpus_from_elf): Take a new
	'load_all_types' flag and honour it.
	* src/abg-reader.cc (read_context::type_is_from_translation_unit):
	Support looking up function types in the current translation unit,
	now that we now how to lookup function types.
	* include/abg-comparison.h (diff_context::{has_diff_for, add_diff,
	set_canonical_diff_for, set_or_get_canonical_diff_for,
	get_canonical_diff_for}): Make these take instances of
	type_or_decl_base_sptr, instead of decl_base_sptr.
	(diff::diff): Likewise.
	(diff::{first_subject, second_subject}): Make these return
	type_or_decl_base_sptr instead of decl_base_sptr.
	(type_diff_base::type_diff_base): Make these take instances of
	type_or_decl_base_sptr instead of decl_base_sptr.
	(distinct_diff::distinct_diff): Likewise.
	(distinct_diff::{first, second}): Make these return
	type_or_decl_base_sptr instead of decl_base_sptr.
	(distinct_diff::entities_are_of_distinct_kinds): Make these take
	instances of type_or_decl_base_sptr instead of decl_base_sptr.
	(class function_type_diff): Create this new type.  It's a
	factorization of the function_decl_diff type.
	* src/abg-comparison.cc ():
	* src/abg-comp-filter.cc ({harmless, harmful}_filter::visit):
	Adjust as diff::{first,second}_subject() now returns a
	type_or_decl_base_sptr, no more a decl_base_sptr.
	(decls_type, decls_diff_map_type): Remove these typedefs and replace it with ...
	(types_or_decls_type, types_or_decls_diff_map_type): ... these.
	(struct {decls_hash, decls_equals): Remove these type sand replace them with ...
	(struct {types_or_decls_hash, types_or_decls_equals}): ... these.
	({type_suppression, variable_suppression}::suppresses_diff):
	Adjust.
	(diff_context::priv::decls_diff_map): Replace this with ...
	(diff_context::priv::types_or_decls_diff_map): ... this.
	(diff_context::{has_diff_for, add_diff, get_canonical_diff_for,
	set_canonical_diff_for, set_or_get_canonical_diff_for}): Take
	type_or_decl_base_sptr instead of decl_base_sptr.
	(diff::priv::{first, second}_subject): Make the type of these be
	type_or_decl_base_sptr, no more decl_base_sptr.
	(diff::priv::priv): Adjust for the subjects of the diff being of
	type type_or_decl_sptr now, no more decl_base_sptr.
	(diff_less_than_functor::operator()(const diff_sptr, const
	diff_sptr) const): Adjust.
	(diff::diff): djust for the subjects of the diff being of type
	type_or_decl_sptr now, no more decl_base_sptr.
	(diff::{first,second}_subject): Make the type of these be
	type_or_decl_base_sptr, no more decl_base_sptr.
	(report_size_and_alignment_changes): Likewise.
	(type_diff_base::type_diff_base): Make the type of this be
	type_or_decl_base_sptr instead of type_base_sptr.
	(distinct_diff::distinct_diff): Make this take instances of
	type_or_decl_base_sptr instead of decl_base_sptr.
	(distinct_diff::{first, second, entities_are_of_distinct_kinds}):
	Likewise.
	(distinct_diff::has_changes): Simplify logic.
	(distinct_diff::report): Adjust.
	(compute_diff_for_types): Add an additional case to support the
	new function_type.
	(report_size_and_alignment_changes): Make this take instances of
	type_or_decl_base_sptr instead of decl_base_sptr.
	(class_diff::priv::member_type_has_changed): Return an instance of
	type_or_decl_base_sptr rather than a decl_base_sptr.
	(class_diff::report): Adjust.
	(diff_comp::operator()(const diff&, diff&) const): Adjust.
	(enum function_decl_diff::priv::Flags): Remove.
	(function_decl_diff::priv::{first_fn_flags_, second_fn_flags_,
	fn_flags_changes_}): Remove.
	(function_decl_diff::priv::{fn_is_declared_inline_to_flag,
	fn_binding_to_flag}): Remove.
	(function_decl_diff::{deleted_parameter_at,
	inserted_parameter_at}): Remove.
	(function_decl_diff::ensure_lookup_tables_populated): Empty this.
	(function_decl_diff::chain_into_hierarchy): Adjust.
	(function_decl_diff::function_decl_diff): This now only takes the
	subjects.  It's body is now empty.
	(function_decl_diff::{return_type_diff, subtype_changed_parms,
	removed_parms, added_parms, type_diff}): Remove these member
	functions.
	(function_decl_diff::type_diff): Define new member function.
	(function_decl_diff::report): Simplify logic by using the
	reporting of the child type diff node.
	(compute_diff): Likewise, in the overload for function_decl_sptr
	simplify logic by using the child type diff object.
	(function_type_diff::priv): Define new type.
	(function_type_diff::{function_type_diff,
	ensure_lookup_tables_populated, deleted_parameter_at,
	inserted_parameter_at, finish_diff_type, first_function_type,
	second_function_type, return_type_diff, subtype_changed_parms,
	removed_parms, added_parms, get_pretty_representation,
	has_changes, has_local_changes, report, chain_into_hierarchy}):
	Define new functions.
	(compute_diff): Define new overload for function_type_sptr.
	* tools/abicompat.cc (options::weak_mode): New data member.
	(options::options): Initialize it.
	(enum abicompat_status): New enum
	(abicompat_status operator|(abicompat_status, abicompat_status))
	(abicompat_status& operator|=(abicompat_status &, abicompat_status))
	(abicompat_status operator&(abicompat_status, abicompat_status)):
	New operators to manipulate the abicompat_status enum.
	(display_usage): Add help string for the new --weak-mode option.
	(parse_command_line): Add the new --weak-mode command line
	argument.  If the tool is called with just the application and one
	library then assume that we are in the weak mode.
	(perform_compat_check_in_normal_mode): Define new function, factorized
	from what was in the main function.
	(perform_compat_check_in_weak_mode): Define new function.
	(struct {fn,var}_change): Define new types.
	(main): Use perform_compat_check_in_weak_mode() and
	perform_compat_check_in_normal_mode().
	* tools/abidiff.cc (main): Adjust.
	* tools/abidw.cc: (options::load_all_types): Add new data member.
	(options::options): Initialize it.
	(display_usage): New help string for --load-all-types.
	(parse_command_line): Support the new --load-all-types option.
	(main): Adjust and honour the --load-all-types option.
	* tools/abilint.cc (main): Adjust.
	* doc/manuals/abicompat.rst: Update documentation for the new weak
	mode.  Also provide stuff that was missing from the examples
	provided.
	* doc/manuals/abidw.rst: Update documentation for the new
	--load-all-types option.
	* tests/print-diff-tree.cc (main): Adjust.
	* tests/test-diff-dwarf.cc (main): Likewise.
	* tests/test-read-dwarf.cc (main): Likewise.
	* tests/data/test-abicompat/test0-fn-changed-app: Recompile this.
	* tests/data/test-abicompat/libtest5-fn-changed-libapp-v{0,1}.so:
	New new test input binaries
	* tests/data/test-abicompat/test5-fn-changed-app: Likewise.
	* tests/data/test-abicompat/test6-var-changed-app: Likewise.
	* tests/data/test-abicompat/libtest6-var-changed-libapp-v{0,1}.so:
	Likewise.
	* tests/data/test-abicompat/test5-fn-changed-report-0.txt:
	Reference output for one test above.
	* tests/data/test-abicompat/test6-var-changed-report-0.txt:
	Likewise.
	* tests/data/test-abicompat/test5-fn-changed-app.cc: Source file
	for a binary above.
	* tests/data/test-abicompat/test5-fn-changed-libapp-v{0,1}.{h,cc}:
	Likewise.
	* tests/data/test-abicompat/test6-var-changed-libapp-v{0,1}.{cc,h}:
	Likewise.
	* tests/data/test-abicompat/test6-var-changed-app.cc: Likewise.
	* tests/data/Makefile.am: Add the test related files above to the
	source distribution.
	* tests/test-abicompat.cc (in_out_spec): Add the new test input
	above to the list of inputs to feed to this test harness.
	(main): Support taking just the app and one library.
	* tests/data/test-read-dwarf/test{0, 1, 2.so, 3.so, 5.o,
	8-qualified-this-pointer.so,}.abi: Adjust for void type being
	really emitted now, as opposed to just being an empty type.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2015-04-03 22:45:41 +02:00
Dodji
2486b210ff PR libabigail/18180
commit eea9ce11eabfda96b2192341b50e9dcc27653369
Author: Dodji Seketeli <dodji@redhat.com>
Date:   Mon Mar 30 22:02:52 2015 +0200

    18180 - runtestreadwrite fails on i386

    The issue here is that unresolved decl-only classes and resolved
    decl-only classes have the same hash value (zero), and that changes
    the type-id of the resolved decl-only class.

    This patch ensures that the hash value of a decl-only class is zero
    only for non-resolved classes.  The patch also fixes an error in an
    input XML file.

    	* src/abg-hash.cc (class_decl:#️⃣:operator()(const class_decl&)
    	const): Return zero only for class declarations that are not
    	resolved.
    	* tests/data/test-read-write/test20.xml: Fix the output to make a
    	class definition to reference its declaration, when there was a
    	forward declaration for it.

    Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2015-03-31 08:06:17 +02:00
Dodji Seketeli
b9fa3b7fd1 18166 - Abidiff fails with internal on Libtirpc ABI in XML format
It turns out the support for reading the native libabigail XML format
is falling short since the work on (late) type canonicalizing.

The type ID -> XML node map is wrongly considered as being per corpus
data while it should be per translation unit data; type IDs are unique
only for a given translation unit.

The code to walk a XML sub-tree to perform the ID -> node mapping is
wrongly walking all the XML node *after* the sub-tree node too; that
is, it walks the entire corpus file starting from the XML sub-tree
node it's given.  It should only walk the sub-tree it's given.

These two issues normally solve the crash reported here.  But then
there are other related issues too.

The native XML format reader doesn't populate the set of exported
declarations for the current corpus it's building.

This patch addresses all these issues and makes tests/test-abidiff.cc
supports corpus files for a new regression test.

	* src/abg-reader.cc (read_context::m_exported_decls_builder_): New
	data member.
	(read_context::read_context): Initialize it.
	(read_context::{type_is_from_translation_unit,
	get_exported_decls_builder, set_exported_decls_builder,
	maybe_add_fn_to_exported_decls, maybe_add_fn_to_exported_decls,
	type_id_new_in_translation_unit}): New member functions.
	(read_context::clear_per_translation_unit_data): Clear id->xml
	node map here ...
	(read_context::clear_per_corpus_data): ... not here.
	(read_context::walk_xml_node_to_map_type_ids): Only walk the
	sub-tree we are asked to walk.
	(read_translation_unit_from_input): Cleanup.
	(read_corpus_from_input): Wire populating of exported declarations
	of the current corpus.
	(build_function_decl, build_var_decl): Populate exported
	declarations of the current corpus here.
	(build_type_decl, build_qualified_type_decl)
	(build_pointer_type_def, build_reference_type_def)
	(build_array_type_def, build_enum_type_decl, build_type_decl)
	(build_template_tparameter): Adjust assert on ID to make sure
	it's the first type it's being defined in the current translation
	unit.
	* tests/data/test-abidiff/test-corpus0-report0.txt: New test
	reference output.
	* tests/data/test-abidiff/test-corpus0-v{0,1}.so.abi: New test
	input.
	* tests/test-abidiff.cc (specs): Add the test inputs above to the
	list of inputs over which to run the test harness.
	(main): Support reading corpora too, as this test harness was
	reading just translation units before.
	(tests/data/Makefile.am): Add test material above to source
	distribution.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2015-03-30 09:50:44 +02:00
Dodji Seketeli
b041bc9cf0 Fix redundancy propagation on node with filtered local changes
Until now, if a diff node N has a local change, even if all of its
children nodes are redundant, N is not considered as being redundant.
This is an issue if the local changes of N are filtered out; in that
case, N should be considered redundant.

This patch fixes that.  It introduces a second category bitmap on the
diff node that stores the categorization of the diff node that does
*NOT* take in account the categories inherited from its children
nodes.  That way, it's possible to know if the *local changes* of a
given node have been filtered out.

	* include/abg-comparison.h (diff::{get_local_category,
	add_to_local_category, add_to_local_and_inherited_categories,
	remove_from_local_category, set_local_category,
	is_filtered_out_wrt_non_inherited_categories,
	has_local_changes_to_be_reported}): Declare new member functions.
	* src/abg-comp-filter.cc ({harmless, harmful}_filter::{visit,
	visit_end}): Update local category too.
	* src/abg-comparison.cc (diff::priv::local_category_): Add new
	data member.
	(diff::priv::priv): Initialize it.
	(diff::priv::is_filtered_out): Add new member function.  This is
	factorized out of diff::is_filtered_out().
	(diff::is_filtered_out): Re-write in terms of
	diff::priv::is_filtered_out().
	(diff::{get_local_category, add_to_local_category,
	add_to_local_and_inherited_categories, remove_from_local_category,
	set_local_category, is_filtered_out_wrt_non_inherited_categories,
	has_local_changes_to_be_reported}): Define new member functions.
	(suppression_categorization_visitor::visit_begin): Update local
	categories too.
	(redundancy_marking_visitor::visit_end): If all of the children
	nodes of the a diff node N are redundant and if N has filtered-out
	local changes, then N is redundant too.
	* tests/data/test-diff-filter/libtest28-redundant-and-filtered-children-nodes-v{1,2}.so:
	New binary test inputs.
	* tests/data/test-diff-filter/test28-redundant-and-filtered-children-nodes-v{0,1}.cc:
	Source code for the binary test inputs above.
	* tests/data/test-diff-filter/test28-redundant-and-filtered-children-nodes-report-{0,1}.txt:
	New test output references.
	* tests/test-diff-filter.cc (in_out_specs): Add the test inputs
	above to the set of inputs this test harness has to run over.
	* tests/data/Makefile.am: Add the test materials above to the
	source distribution.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2015-03-18 18:41:52 +01:00
Dodji Seketeli
635e5fa6b2 Delay non-complete class type resolution up to end of corpus reading
From the DWARF emitted by GCC 4.4.7 for libstdc++ we encountered an
interesting construct.

A non-complete version of std::runtime_error is declared in
libstdc++-v3/src/functexcept.cc and is represented in DWARF as:

     [ 37344]      class_type
		    name                 (strp) "runtime_error"
		    declaration          (flag)

Then a bit later, that *non-complete* class is used as a base class
for a class, *without* being fully defined!  This shouldn't happen
but, well, it does:

     [ 3b3a1]    class_type
		  specification        (ref4) [ 3733e]
		  byte_size            (data1) 16
		  decl_file            (data1) 5
		  decl_line (data1) 141
		  containing_type      (ref4) [ 3734a]
		  sibling              (ref4) [3b405]
     [ 3b3b1]      inheritance
		   type                 (ref4) [ 37344] <---- here.

The thing is that, later, in another translation unit
(libstdc++-v3/src/stdexcept.cc), that same class is defined fully:

     [ 7e9f9]      class_type
		   name                 (strp) "runtime_error"
		   declaration          (flag)
[...]

     [ 80c95]    class_type
		 specification        (ref4) [ 7e9f9]
		 byte_size            (data1) 16
		 decl_file            (data1) 4
		 decl_line            (data1) 108
		 containing_type      (ref4) [ 7e9ff]
		 sibling              (ref4) [ 80d2b]
		 [...] <---------- and the definition goes here.

But then you see that the DIE offset of the "version" of the
runtime_error class that is "defined" libstdc++-v3/src/stdexcept.cc in
is different from the version that is only declared in
libstdc++-v3/src/functexcept.cc.  But virtue of the "One Definition
Rule", we can assume that they designate the same type.  But still,
runtime_error should have been defined in
libstdc++-v3/src/stdexcept.cc.  Anyhow, libabigail needs to be able to
handle this.  That is, it needs to wait until the entire ABI corpus is
loaded from DWARF, then lookup the definition of all the non-complete
types we have encountered.

And then only after that non-complete type resolution has taken place,
we can proceed with type canonicalizing, rather than doing it after
the loading of each translation unit like what we were doing
previously.

This is what this patch does.

	* include/abg-fwd.h (lookup_type_in_corpus): Declare new function.
	* src/abg-corpus.cc (lookup_type_in_corpus): Define new function
	here.
	* include/abg-ir.h (function_types_type): Declare new typedef.
	(translation_unit::get_canonical_function_type): Remove member function.
	(translation_unit::bind_function_type_life_time): Declare new
	member function.
	(classes_type): New typedef.
	* src/abg-ir.cc
	(translation_unit::priv::canonical_function_types_): Remove data
	member.
	(translation_unit::priv::function_types): New data member.
	(translation_unit::get_canonical_function_type): Remove this
	function definition.
	(translation_unit::bind_function_type_life_time): New function
	definition.
	(lookup_node_in_scope): Ensure that the type returned is
	complete.
	* src/abg-dwarf-reader.cc (string_classes_map): New typedef.
	(read_context::decl_only_classes_map_): New data member.
	(read_context::declaration_only_classes): New accessor.
	(read_context::{maybe_schedule_declaration_only_class_for_resolution,
	is_decl_only_class_scheduled_for_resolution,
	resolve_declaration_only_classes, current_elf_file_is_executable,
	current_elf_file_is_dso}): Define new member functions.
	(read_context::clear_per_translation_unit_data): Do not clear the
	data structures that associate DIEs to decls/types or that contain
	the types to canonicalize here.  Rather, clear them ...
	(read_context::clear_per_corpus_data): ... here instead.
	(read_context::build_translation_unit_and_add_to_ir): Do not
	perform late type canonicalizing here.  Rather, do it ...
	(read_debug_info_into_corpus): ... here instead.  And before that,
	call read_context::clear_per_corpus_data() and the new
	read_context::resolve_declaration_only_classes() here.
	(build_class_type_and_add_to_ir): Schedule the non-complete types
	for resolution to complete types.  Assert that base classes that
	are non-complete are scheduled to be completed.
	(build_function_decl): Do not try to canonicalize function types
	this early, systematically.  Now, all the non-complete types needs
	to be completed before starting canonicalizing.  So let function
	types go through the normal processes of deciding when to
	canonicalize them.  But then, bind the life time of the function
	type to the life time of the current translation unit.
	(maybe_canonicalize_type): If a class type is non-complete,
	schedule it for late canonicalizing.
	* src/abg-hash.cc (class_decl:#️⃣:operator()(const class_decl&)
	const): During hashing, a base class should be complete.
	* src/abg-reader.cc
	(read_context::clear_per_translation_unit_data): Do not clear
	id/xml node, and type maps here.  Rather, clear it ...
	(read_context::clear_per_corpus_data): ... here instead.
	(read_translation_unit_from_input): Do not perform late
	canonicalizing here.  Rather, do it ...
	(read_corpus_from_input): ... here.  Also, call the new
	read_context::clear_per_corpus_data() here.
	(build_function_decl): Do not canonicalize function types here so
	early.  Rather, bind the life time of the function type to the
	life time of the translation unit.
	* src/abg-writer.cc (write_translation_unit): Do not clear the
	type/ID map here.
	* tests/data/test-read-dwarf/test2.so.abi: Adjust test input.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2015-03-17 10:54:12 +01:00
Dodji Seketeli
5244794279 Fix redundancy categorization propagation
Propagating redundancy categorization is broken for cases where there
is a diff node that has children nodes carrying changes that are all
filtered out.  In that case, if among those children changes there is
a redundant change, normally the parent diff node we are look at
should be marked redundant too.  The bug is that it's not marked as
redundant at the moment.  This patch fixes that.

	* src/abg-comparison.cc (redundancy_marking_visitor::visit_end):
	Consider the cases of changes that are a filtered out.
	* tests/data/test-diff-filter/libtest27-redundant-and-filtered-children-nodes-v{0,1}.so:
	New test binaries to use as test input.
	* tests/data/test-diff-filter/test27-redundant-and-filtered-children-nodes-report-{0,1,2}.txt:
	New test result baselines.
	* tests/data/test-diff-filter/test27-redundant-and-filtered-children-nodes-v{0,1}.cc:
	Source code for the test input binaries above.
	* tests/test-diff-filter.cc (in_out_spec): Add the binaries to the
	test inputs used for this test harness.
	* tests/data/Makefile.am: Add the new test material above to the
	distribution.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2015-03-13 16:38:34 +01:00
Dodji Seketeli
dbe88f1103 Fix the new regression test for type canonicalizing
* tests/runtestcanonicalizetypes.sh.in (binaries): Refer to
	abg-tools-utils, not abg-tools-utils.o; the extension is computed
	automatically, depending on the underlying platform.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2015-02-19 11:44:19 +01:00
Dodji Seketeli
8b28d171c3 Canonicalize types either early or late after TU reading
While trying to diff two identical files (abidiff foo.so foo.so) it
appeared that canonicalizing types during e.g, the DWARF reading
process was leading to subtle errors because it's extremely hard to
know when a type is complete.  That is, during the building of a class
type C, a pointer to C can be built before C is complete.  Worse, even
after reading the DIE (from DWARF) of class C, there can be DIE seen
later in the translation unit that modifies type C.  In these late
cases, one needs to wait -- not only until C is fully built, but also
sometimes, after the translation unit is fully built -- to
canonicalize C and then the pointer to C.  This kind of things.

So now there are two possible points in time when canonicalization of
a type can happen.  It can happen early, when the type is built.  This
is the case for basic types and composite types for which all
sub-types are canonicalized already.  It can happen late, right after
we've finished reading the debug info for the current translation
unit.

So this patch fixes the IR traversal and uses that to walk the
translation unit (or even types) after it's built.  It does away with
the first attempt to perform early canonicalizing only.

The patch also handles type canonicalizing while reading xml-abi
format.

	* include/abg-fwd.h (is_class_type)
	(type_has_non_canonicalized_subtype): Declare new functions.
	(is_member_type): Remove the overload that takes a decl_base_sptr.
	It's superfluous.  We just need the one that takes a
	type_base_sptr.
	* include/abg-ir.h (translation_unit::{is_constructed,
	set_is_constructed}): Add new methods.
	(class_decl::has_virtual_member_functions): Likewise.
	(class decl_base): Makes it virtually inherit ir_traversable_base.
	(class type_base): Make this virtually inherit traversable_base
	too.
	(type_base::canonicalize): Renamed enable_canonical_equality
	into this.
	(type_base::traverse): Declare new virtual method.
	(canonicalize): Renamed enable_canonical_equality into this.
	(scope_type_decl::traverse): Declare new virtual method.
	(namespace_decl::get_pretty_representation): Declare new virtual
	method.
	(function_type::traverse): Likewise.
	(class_decl::base_spec::traverse): Likewise.
	(ir_node_visitor::visit): Remove the overloads and replace each of
	them with a pair of ...
	(ir_node_visitor::{visit_begin, visit_end}): ... of these.
	* include/abg-traverse.h (traversable_base::visiting): New
	method.
	(traversable_base::visiting_): New data member.
	(traversable_base::traversable_base): New constructor.
	* src/abg-ir.cc ({scope_decl, type_decl, namespace_decl,
	qualified_type_def, pointer_type_def, reference_type_def,
	array_type_def, enum_type_decl, typedef_decl, var_decl,
	function_decl, function_decl::parameter, class_decl,
	class_decl::member_function_template,
	class_decl::member_class_template, function_tdecl,
	class_tdecl}::traverse): Fix this to properly set the
	traversable_base::visiting_ flag and to reflect the new signatures
	of the ir_node_visitor methods.
	({type_base, scope_type_decl, function_type,
	class_decl::base_spec}::traverse): New method.
	(type_base::get_canonical_type_for): Handle the case of the type
	already having a canonical type.  Properly hash the type using the
	dynamic type hasher.  Look through declaration-only classes to
	consider the definition of the class instead.  Fix logic to have a
	single pointer of return, to ease debugging.
	(canonicalize): Renamed enable_canonical_equality into this.
	(namespace_decl::get_pretty_representation): Define new method.
	(ir_node_visitor::visit): Replace each of these overloads with a
	pair of visit_begin/visit_end ones.
	(translation_unit::priv::is_constructed_): New data member.
	(translation_unit::priv::priv): Initialize it.
	(translation_unit::{is_constructed, set_is_constructed}): Define
	new methods.
	(is_member_type(const decl_base_sptr)): Remove.
	(is_class_type(decl_base *d)): Define new function.
	(class_decl::has_virtual_member_functions): Define new method.
	(equals(const class_decl&, const class_decl&, change_kind*)): If
	the containing translation unit is not constructed yet, do not
	take virtual member functions in account when comparing the
	classes.  This is because when reading from DWARF, there can be
	DIEs that change the number of virtual member functions after the
	DIE of the class.  So one needs to start taking virtual members
	into account only after the translation unit has been constructed.
	(class non_canonicalized_subtype_detector): Define new type.
	(type_has_non_canonicalized_subtype): Define new function.
	* src/abg-corpus.cc (symtab_build_visitor_type::visit): Renamed
	this into symtab_build_visitor_type::visit_end.
	* src/abg-dwarf-reader.cc (die_type_map_type): New typedef.
	(die_class_map_type): This is now a typedef on a map of
	Dwarf_Off/class_decl_sptr.
	(read_context::{die_type_map_, alternate_die_type_map_,
	types_to_canonicalize_, alt_types_to_canonicalize_}): New data
	members.
	(read_context::{associate_die_to_decl,
	associate_die_to_decl_primary}): Make these methods public.
	(read_context::{associate_die_to_type,
	lookup_type_from_die_offset, is_wip_class_die_offset,
	types_to_canonicalize, schedule_type_for_canonicalization}):
	Define new methods.
	(build_type_decl, build_enum_type)
	(build_class_type_and_add_to_ir, build_qualified_type)
	(build_pointer_type_def, build_reference_type, build_array_type)
	(build_typedef_type, build_function_decl): Do not canonicalize
	types here.
	(maybe_canonicalize_type): Define new function.
	(build_ir_node_from_die): Take a new flag that says if the ir node
	is a member type/function or not. Early-canonicalize base types.
	Canonicalize composite types that have only canonicalized
	sub-types.  Schedule the other types for late canonicalizing.  For
	class types, early canonicalize those that are non-member types,
	that are fully constructed and that have only canonicalized
	sub-types.  Adjust to the new signature of build_ir_node_from_die.
	(get_scope_for_die, build_namespace_decl_and_add_to_ir)
	(build_qualified_type, build_pointer_type_def)
	(build_reference_type, build_array_type, build_typedef_type)
	(build_var_decl, build_function_decl): Adjust for the new
	signature of build_ir_node_from_die.
	(build_translation_unit_and_add_to_ir): Likewise.  Perform the
	late canonicalizing of the types that have been scheduled for
	that.
	(build_class_type_and_add_to_ir): Return a class_decl_sptr, not a
	decl_base_sptr.  Adjust for the new signature of
	build_ir_node_from_die.  Early canonicalize member types that are
	created and added to a given class, or schedule them for late
	canonicalizing.
	* src/abg-reader.cc (class read_context::{m_wip_classes_map,
	m_types_to_canonicalize}): New data members.
	(read_context::{clear_types_to_canonicalize,
	clear_wip_classes_map, mark_class_as_wip, unmark_class_as_wip,
	is_wip_class, maybe_canonicalize_type,
	schedule_type_for_late_canonicalizing,
	perform_late_type_canonicalizing}): Add new method definitions.
	(read_context::clear_per_translation_unit_data): Call
	read_context::clear_types_to_canonicalize().
	(read_translation_unit_from_input): Call
	read_context::perform_late_type_canonicalizing() at the end of the
	function.
	(build_function_decl): Fix the function type canonicalizing (per
	translation) that was already in place.  Do the canonicalizing of
	these only when the type is fully built.  Oops.  This was really
	brokend.  Also, when the function type is constructed, consider it
	for type canonicalizing.
	(build_type_decl): Early canonicalize basic types.
	(build_qualified_type_decl, build_pointer_type_def)
	(build_pointer_type_def, build_reference_type_def)
	(build_array_type_def, build_enum_type_decl, build_typedef_decl):
	Handle the canonicalizing for these composite types: either early
	or late.
	(build_class_decl): Likewise.  Also, mark this class a 'being
	built' until it's fully built.  This helps the canonicalizing code
	to know that it should leave a class alone until it's fully built.
	* tests/test-ir-walker.cc (struct name_printing_visitor): Adjust
	to the visitor methods naming change.
	* configure.ac: Generate the tests/runtestcanonicalizetypes.sh
	testing script from tests/runtestcanonicalizetypes.sh.in.
	* tests/runtestcanonicalizetypes.sh.in: Add the template for the
	new runtestcanonicalizetypes.sh script that test for type
	canonicalizing.
	* tests/Makefile.am: Add the new runtestcanonicalizetypes.sh
	regression testing script to the build system.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2015-02-18 21:32:37 +01:00
Dodji Seketeli
3b3dbf6643 Rename diff::length() into diff::has_changes()
Since it turned out that the length of the changes carried by a diff
node has never been used in the algorithms of the comparison engine,
the diff::length() feels wrong.  What we want is rather a name like
diff::has_changes() so this is what this patch does.

	* include/abg-comparison.h (*::has_changes): Rename the ::length()
	method of all the diff types that inherit the diff class into
	this, in the class declarations.
	* src/abg-comparison.cc (*::has_changes): Do the same as in the
	declarations, in the definitions.
	(diff::to_be_reported, distinct_diff::has_local_changes)
	(distinct_diff::report, distinct_diff::, array_diff::has_changes)
	(reference_diff::has_changes, qualified_type_diff::has_changes)
	(enum_diff::has_changes, translation_unit_diff::has_changes)
	(suppression_categorization_visitor::visit_end)
	(redundancy_marking_visitor::visit_begin): Adjust.
	* tests/test-diff-dwarf.cc (main): Adjust.
	* tools/abidiff.cc (main): Likewise.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2015-02-05 12:44:59 +01:00
Dodji Seketeli
a00ed6bf41 Hand-code the string representation of GElf_Ehdr::e_machine
I was using elfutils/libebl.h to get a string representation of the
marchine architecture of the elf file.  It appears elfutils/libebl.h
is an internal header not meant to be used by client code of
elfutils.  So this patch hand-codes the string representation of the
value of the GElf_Ehdr data member and does away with the need of the
elfutils/libebl.h header as with libebl.

	* configure.ac: Do not check for elfutils/libebl.h and libebl.a
	anymore.
	* src/abg-dwarf-reader.cc: Do not include elfutils/libebl.h
	anymore.
	(e_machine_to_string): Define new static
	function.
	(read_context::::load_elf_architecture): Use the new
	e_machine_to_string() function rather than ebl_backend_name() and
	ebl_openbackend().
	* tests/data/test-diff-dwarf/test-23-diff-arch-report-0.txt: Adjust.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2015-01-26 22:17:39 +01:00
Dodji Seketeli
29bc673dc0 Fix chaining of descendant node of qualified type diff node
While looking at the abidiff report emitted for two versions of the
TBB library, I noticed that some diff nodes were not marked as
redundant as they should be.  As a result, they were being reported as
having "been reported earlier", which seems to be an acceptable cruft
to me especially now that the comparison IR can do proper redundancy
detection and marking.

I tracked that down and it's because the child node of a
qualified_type_diff is just the underlying type diff node, whereas
during reporting, we report about the leaf underlying type diff node,
which can be different from the just the underlying type diff node
because the later is always non-qualified.

The fix is to make the child node of qualified_type_diff be the leaf
underlying type diff node, so that diff tree walking (for the purpose
of redundancy detection) and reporting are all looking at the same
tree.

	* include/abg-comparison.h
	(qualified_type_diff::leaf_underlying_type_diff): Declare new
	accessor.
	* src/abg-comparison.cc (get_leaf_type): Forward declare this
	static function.
	(qualified_type_diff::priv::leaf_underlying_type_diff): Define new
	data member.
	(qualified_type_diff::leaf_underlying_type_diff): Define this new
	accessor.
	(qualified_type_diff::chain_into_hierarchy): Call
	leaf_underlying_type_diff() here rather than
	underlying_type_diff().
	(qualified_type_diff::report): Use leaf_underlying_type_diff()
	rather than re-computing the diff between the two leaf underlying
	type diff nodes.
	* libtest26-qualified-redundant-node-v{0,1}.so: New binary test
	input files.
	* tests/data/test-diff-filter/test26-qualified-redundant-node-v{0,1}.cc:
	Source code for the binary test inputs above.
	* tests/test-diff-filter.cc (int_out_spec): Add the new test input
	to the vector of test input data over which to run this test
	harness.
	* tests/data/test-diff-filter/test26-qualified-redundant-node-report-{0,1.txt:
	New test input file.
	* tests/data/Makefile.am: Add the new test input data to the
	source distribution.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2015-01-26 12:12:57 +01:00
Dodji Seketeli
ddfb37ab17 Recognize cyclic diff tree nodes as being redundant
Okay I need to introduce some vocabulary here.  Suppose we have the
version 1 of a library named library-v1.so which source code is:

    struct S
    {
     int m0;
     struct S* m2;
    };

    int
    foo(struct S* ptr)
    {
      return ptr;
    }

And now suppose we have a version 2 of that library named
library-v2.so which source code is modified so that a new data member
is inserted into struct S:

    struct S
    {
     int m0;
     char m1; /* <--- a new data member is inserted here.  */
     struct S* m2;
    };

    int
    foo(struct S* ptr)
    {
      return ptr;
    }

struct S is said to be a cyclic type because it contains a (data)
member which type refers to struct S itself, namely, the type of the
data member S::m2 is struct S*, which refers to struct S.

So, by analogy, the diff node tree that represents the changes of
struct S is also said to be cyclic, for similar reasons: the diff
node of the change of S::m2 refers to the diff node of the change of
the type of S::m2, namely the diff node of struct S*, which refers to
the diff node for the change of struct S itself.

Now let's talk about redundancy.  When walking the diff node tree of
struct S in a depth-first manner, at some point, we look at the diff
node for the data member S::m2, and we end up looking at the diff node
of its type which is the diff node for struct S*; we keep walking and
eventually we look the diff node of the change of the underlying type
of struct S, which is the diff node of struct S, and hah! that is a
redundant node because it's the first node that we visited when
visiting the diff node of ...  struct S!  So the diff tree node for
the change of struct S is not only a cyclic node, it's a redundant
diff node as well, and its second occurrence is located at the point
of appearance of data member S::m2.  Hence the wording "cyclic
redundant diff tree node".  There! We have our vocabulary all set now.

This patch enhances the code of the comparison engine so that a cyclic
diff tree node is marked as redundant from the point of its second
occurrence, onward.

First the patch separates the notion of visiting a diff node from the
notion of traversing it.  Now traversing a diff node means visiting it
and visiting its children nodes.  So one can visit a node without
traversing it, but one can not traverse a node without visiting it.

So, when walking diff node trees, we need to avoid ending up in
infinite loop in presence of cyclic nodes.  This is why re-traversing
a node that is already being traversed is forbidden by this patch, but
visiting a node that is being visited is allowed.  Before this patch,
the notions of visiting and traversing were conflated in one and were
not very clear; and one couldn't visit a node that was currently being
visited.  As a result, in presence of a cyclic node, its redundant
nature wasn't being recognized, and so the diff tree node was not
being flagged as being redundant.  Diff reports were then cluttered by
redundant references to changes involving cyclic types.

	* include/abg-comparison.h (enum visiting_kind): Rename
	enumerator DO_NOT_MARK_VISITED_NODES_AS_TRAVERSED into
	DO_NOT_MARK_VISITED_NODES_AS_VISITED.
	(diff_context::diff_has_been_visited): Rename
	diff_context::diff_has_been_traversed into this.
	(diff_context::mark_diff_as_visited): Rename
	diff_context::mark_diff_as_traversed into this.
	(diff_context::forget_visited_diffs): Rename
	diff_context::forget_traversed_diffs into this.
	(diff_context::forbid_visiting_a_node_twice): Rename
	diff_context::forbid_traversing_a_node_twice into this.
	(diff_context::visiting_a_node_twice_is_forbidden): Rename
	diff_context::traversing_a_node_twice_is_forbidden into this.
	(diff::is_traversing): Move this from protected to public.
	* src/abg-comparison.cc (diff_context::priv::visited_diff_nodes_):
	Rename diff_context::priv::traversed_diff_nodes_ into this.
	(diff_context::priv::forbid_visiting_a_node_twice_): Rename
	diff_context::priv::forbid_traversing_a_node_twice_ into this.
	(diff_context::priv::priv): Adjust.
	(diff_context::diff_has_been_visited): Rename
	diff_context::diff_has_been_traversed into this.  Adjust.
	(diff_context::mark_diff_as_visited): Rename
	diff_context::mark_diff_as_traversed into this.  Adjust.
	(diff_context::forget_visited_diffs): Rename
	diff_context::forget_traversed_diffs into this.  Adjust.
	(diff_context::forbid_visiting_a_node_twice): Rename
	diff_context::forbid_traversing_a_node_twice into this.
	(diff_context::visiting_a_node_twice_is_forbidden): Rename
	diff_context::traversing_a_node_twice_is_forbidden into this.
	(diff_context::maybe_apply_filters): Adjust.
	(diff::end_traversing): Remove the 'mark_as_traversed' parameter
	of this.  Remove the visited-marking code.
	(diff::traverse): This is the crux of the changes of this patch.
	Avoid traversing a node that is being traversed, but one can visit
	a node being visited.  Also, traversing a node means visiting it
	and visiting its children nodes.
	(diff::is_filtered_out):  Simplify logic for filtering redundant
	code.  Basically all nodes that are redundant are filtered.  All
	the complicated logic that was due when diff nodes were shared is
	not relevant anymore.
	(corpus_diff::priv::categorize_redundant_changed_sub_nodes)
	(propagate_categories, apply_suppressions)
	(diff_node_printer::diff_node_printer, print_diff_tree)
	(categorize_redundant_changed_sub_nodes)
	(clear_redundancy_categorization)
	(clear_redundancy_categorization): Adjust.
	(redundancy_marking_visitor::visit_begin): Adjust.  Also, if the
	current diff node is already being traversed (that's a clyclic
	node) then mark it as redundant.
	* src/abg-comp-filter.cc (apply_filter): Adjust.
	* tests/data/test-diff-filter/test16-report-2.txt: New test input data.
	* tests/data/test-diff-filter/libtest25-cyclic-type-v{0,1}.so: New
	test input binaries.
	* tests/data/test-diff-filter/test25-cyclic-type-v{0,1}.cc: Source
	code for the test input binaries.
	* tests/data/test-diff-filter/test25-cyclic-type-report-0.txt: New
	test input data.
	* tests/data/test-diff-filter/test25-cyclic-type-report-1.txt:
	Likewise.
	* tests/test-diff-filter.cc (in_out_specs): Add the new test
	inputs above to the list of test input data over which to run this
	test harness.
	* tests/data/Makefile.am: Add the new test files above to source
	distribution.
	* tests/data/test-diff-filter/test16-report.txt: Adjust.
	* tests/data/test-diff-filter/test17-0-report.txt: Likewise.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2015-01-24 22:48:40 +01:00
Dodji Seketeli
af0923b1b0 Fix the output of the array diff report
While working on something else, I realized the report of the array
diff change wasn't referring to the pretty representation of the array
when talking about the changes of array element type; rather it was
just referring to the array name.  I think referring to the pretty
representation of the array is more helpful.  This patch does just
that.

	* src/abg-comparison.cc (array_diff::report): Refer to the pretty
	representation of the array when talking about changes of the
	array element type.
	* src/abg-ir.cc (equals): In the overload for array_type, use the
	equality operator that knows how to handle null pointers to
	element type.  This avoids crashes when the pointer to element
	type is null.
	* tests/data/test-diff-dwarf/test10-report.txt: Adjust.
	* tests/data/test-diff-filter/test24-compatible-vars-report-1.txt:
	Likewise.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2015-01-19 15:00:44 +01:00
Dodji Seketeli
b25f1bd7e7 Adjust archive-related code for the recent addition of tools_utils::*
What was in the abigail::tools namespace got recently moved in the
abigail::tools_unit namespace.  I forgot to adjust the client code
related to the archive support because that code is now compiled by
default on my main hacking box.  This patch fixes that.

	* tests/Makefile.am: tools/libtoolsutils.la is no more.
	* tests/test-write-read-archive.cc (main): Adjust.
	* tools/abiar.cc (extract_tus_from_archive): Likewise.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2015-01-13 11:02:10 +01:00
Dodji Seketeli
19013fd110 Sort functions & variables diff nodes in the diff tree
Since the work on un-sharing diff tree nodes, it looks like some
reports of regression tests on i686 order functions and variables in
different orders, leading to test failures on 32 bits platforms
because they are different fromthe 64 bits platforms that we use as a
reference.  This patch sorts (lexicographically) the children diff
nodes of a given diff node in general, and also sorts the set of diff
nodes for functions and variables that have sub-type changes, in a
given corpus_diff.  That way, the result of the diff report should be
sorted the same way, whatever the platform.

	* include/abg-comparison.h (function_decl_diff_sptrs_type)
	(var_diff_sptrs_type): New typedefs.
	(corpus_diff::{changed_functions, changed_variables}): Declare new
	methods.
	* src/abg-comparison.cc (sort_string_function_decl_diff_sptr_map)
	(sort_string_var_diff_sptr_map): Forward declare these static
	functions there were already defined later.
	(struct diff_less_than_functor): Define new comparison functor.
	(diff::append_child_node): Sort the children diff nodes of a given
	diff node.
	(corpus_diff::priv::changed_fns_map_): Renamed the data member
	corpus_diff::priv::changed_fns_ into this.
	(corpus_diff::priv::changed_fns_): New data member that is a
	sorted vector of changed functions.
	(corpus_diff::priv::{lookup_tables_empty, clear_lookup_tables}):
	Adjust changed_fns_ -> changed_fns_map_ and changed_vars_ ->
	changed_vars_map_.
	(corpus_diff::priv::ensure_lookup_tables_populated): Likewise.
	Sort the changed functions and changed variables.
	(corpus_diff::priv::apply_filters_and_compute_diff_stats): Adjust
	changed_fns_ -> changed_fns_map_ and changed_vars_ ->
	changed_vars_map_.  Also, walk the changed functions and variables
	diff nodes in their sorted order.
	(corpus_diff::priv::{categorize_redundant_changed_sub_nodes,
	clear_redundancy_categorization, maybe_dump_diff_tree}): Walk the
	changed functions and variables diff nodes in their sorted order.
	* include/abg-ir.h
	(function_decl::get_pretty_representation_of_declarator):
	Declarenew method.
	* src/abg-ir.cc
	(function_decl::get_pretty_representation_of_declarator): Define
	new function.  Its content got split out of ...
	(function_decl::get_pretty_representation): ... this one.
	* src/abg-comparison.cc (corpus_diff::chain_into_hierarchy):
	Consider the sorted the children nodes of a diff tree node.
	(corpus_diff::append_child_node): Keep the children nodes of a
	diff tree node sorted.
	(corpus_diff::{changed_functions, changed_variables, length,
	report}): Adjust.
	(corpus_diff::{changed_functions_sorted,
	changed_variables_sorted}): Define new functions.
	(function_comp::operator()): First compare the qualified function
	names along with the parameter declarations, then the rest.
	(sort_string_function_decl_diff_sptr_map)
	(sort_string_var_diff_sptr_map): Adjust.
	* tests/data/test-abicompat/test0-fn-changed-report-0.txt: Adjust.
	* tests/data/test-diff-suppr/test5-fn-suppr-report-0.txt: Adjust.
	* tests/data/test-diff-suppr/test8-redundant-fn-report-0.txt:
	Adjust.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2015-01-09 14:45:11 +01:00
Dodji Seketeli
7c2a0940e2 Update copyright year for tests/test-abicompat.cc
* tests/test-abicompat.cc: Update copyright year.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2015-01-09 14:09:16 +01:00
Dodji Seketeli
322b0e7769 Expose a new libabigail::tools_utils namespace
The utilities present in this namespace were previously living in
tools/abg-tools-utils.h and tools/abg-tools-utils.cc.  They were not
exported and were meant to be useful to the tools writting in the
tools/ directory.  I realized that these utilities might be useful to
clients of the libabigail library in general so I am making them
available generally.  Note that the initial name of the namespace was
libabigail::tools; so renaming it to libabigail::tools_utils required
that I adjust some client code.  I have also cleaned up the code,
interfaces and their apidoc a little bit.

	* include/abg-tools-utils.h: Moved tools/abg-tools-utils.h in
	here.  Renamed the namespace tools into tools_utils.  Inject
	std::ostream, std::istream, std::ifstream, and std::string types
	into the tools_utils namespace.  Adjust the function declarations
	accordingly.  Remove the useless dirname() function declaration.
	* include/Makefile.am: Add abg-tools-utils.h to the list of
	exported headers.
	* src/abg-tools-utils.cc: Moved tools/abg-tools-utils.cc in here.
	Renamed the namespace tools into tools_utils.
	(get_stat): Add apidoc.
	(is_dir): Cleanup apidoc.
	(dir_name); Cleanup parameter name.
	(guess_file_type): Cleanup parameter type.
	* src/Makefile.am: Add abg-tools-utils.cc to the list of exported
	headers.
	* tools/Makefile.am: Do not build the temporary library
	libtoolsutils.la anymore as abg-tools-utils.{h,cc} have moved out
	of this directory.
	* tools/abicompat.cc (parse_command_line, main): Adjust for tools
	-> tools_utils namespace change.
	* tools/abidiff.cc (parse_command_line, main): Likewise.
	* tools/abidw.cc (parse_command_line, main): Likewise.
	* tools/abilint.cc (parse_command_line, main): Likewise.
	* tests/test-abicompat.cc (main): Adjust for tools -> tools_utils
	namespace change.
	* tests/test-abidiff.cc (main): Likewise.
	* tests/test-alt-dwarf-file.cc (main): Likewise.
	* tests/test-core-diff.cc (main): Likewise.
	* tests/test-diff-dwarf.cc (main): Likewise.
	* tests/test-diff-filter.cc (main): Likewise.
	* tests/test-diff-suppr.cc (main): Likewise.
	* tests/test-lookup-syms.cc (main): Likewise.
	* tests/test-read-dwarf.cc (main): Likewise.
	* tests/test-read-write.cc (main): Likewise.
	* tests/Makefile.am: Do not reference the libtoolsutils.la private
	library anymore.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2015-01-08 12:28:14 +01:00
Dodji Seketeli
76837d1cbf Update copyright years
* include/abg-comp-filter.h: Update copyright years.
	* include/abg-comparison.h: Likewise.
	* include/abg-config.h: Likewise.
	* include/abg-corpus.h: Likewise.
	* include/abg-diff-utils.h: Likewise.
	* include/abg-dwarf-reader.h: Likewise.
	* include/abg-fwd.h: Likewise.
	* include/abg-hash.h: Likewise.
	* include/abg-ini.h: Likewise.
	* include/abg-ir.h: Likewise.
	* include/abg-libxml-utils.h: Likewise.
	* include/abg-libzip-utils.h: Likewise.
	* include/abg-reader.h: Likewise.
	* include/abg-sptr-utils.h: Likewise.
	* include/abg-traverse.h: Likewise.
	* include/abg-viz-common.h: Likewise.
	* include/abg-viz-dot.h: Likewise.
	* include/abg-viz-svg.h: Likewise.
	* include/abg-writer.h: Likewise.
	* src/abg-comp-filter.cc: Likewise.
	* src/abg-comparison.cc: Likewise.
	* src/abg-config.cc: Likewise.
	* src/abg-corpus.cc: Likewise.
	* src/abg-diff-utils.cc: Likewise.
	* src/abg-dwarf-reader.cc: Likewise.
	* src/abg-hash.cc: Likewise.
	* src/abg-ini.cc: Likewise.
	* src/abg-ir.cc: Likewise.
	* src/abg-libxml-utils.cc: Likewise.
	* src/abg-libzip-utils.cc: Likewise.
	* src/abg-reader.cc: Likewise.
	* src/abg-traverse.cc: Likewise.
	* src/abg-viz-common.cc: Likewise.
	* src/abg-viz-dot.cc: Likewise.
	* src/abg-viz-svg.cc: Likewise.
	* src/abg-writer.cc: Likewise.
	* tests/print-diff-tree.cc: Likewise.
	* tests/test-abidiff.cc: Likewise.
	* tests/test-alt-dwarf-file.cc: Likewise.
	* tests/test-core-diff.cc: Likewise.
	* tests/test-diff-dwarf.cc: Likewise.
	* tests/test-diff-filter.cc: Likewise.
	* tests/test-diff-suppr.cc: Likewise.
	* tests/test-diff2.cc: Likewise.
	* tests/test-ir-walker.cc: Likewise.
	* tests/test-lookup-syms.cc: Likewise.
	* tests/test-read-dwarf.cc: Likewise.
	* tests/test-read-write.cc: Likewise.
	* tests/test-utils.cc: Likewise.
	* tests/test-utils.h: Likewise.
	* tests/test-write-read-archive.cc: Likewise.
	* tools/abg-tools-utils.cc: Likewise.
	* tools/abg-tools-utils.h: Likewise.
	* tools/abiar.cc: Likewise.
	* tools/abidiff.cc: Likewise.
	* tools/abidw.cc: Likewise.
	* tools/abilint.cc: Likewise.
	* tools/abisym.cc: Likewise.
	* tools/binilint.cc: Likewise.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2015-01-07 17:52:10 +01:00
Dodji Seketeli
929db0a880 Detect and report changes in ELF architecture
Libabigail does not take in account the architecture of the ELF file
it reads.  This patch changes that to represent the ELF architecture
as a string, detect when that architecture changes accross two corpora
being compared and emit a report about that change.

	* configure.ac: Detect the presence of libebl.a and add it to the
	list of library we depend on to build libabigail.  Report when
	libelf.so is not found.
	* include/abg-comparison.h:
	(diff_context::show_architecture_change): Declare new accessors.
	(corpus_diff::architecture_changed): Declare new method.
	* include/abg-corpus.h (corpus::{get,set}_architecture_name):
	Declare new accessors.
	* src/abg-comparison.cc
	(diff_context::priv::show_architecture_change_): New data member.
	(diff_context::priv::priv): Initialize it.
	(diff_context::show_architecture_change): Define new accessors.
	(function_decl_diff::report): Report when the size/alignment of
	the function address changes.
	(corpus_diff::priv::architectures_equal_): New data member.
	(corpus_diff::priv::priv): Initialize it.
	(corpus_diff::priv::emit_diff_stats): Take in account changes of
	architecture.
	(corpus_diff::architecture_changed): Define new method.
	(corpus_diff::length): Take in account changes of architecture.
	(corpus_diff::report): Report about changes of architecture.
	(compute_diff): In the overload for corpus_diff_sptr, detect
	changes fo architecture.
	* src/abg-corpus.cc (corpus_priv::architecture_name): Define new
	data member.
	(corpus::{get,set}_architecture_name): Define new method.
	* src/abg-dwarf-reader.cc: Include elfutils/libebl.h to use
	ebl_openbackend() and ebl_backend_name()
	(read_context::elf_architecture_): Define new data member.
	(read_context::elf_architecture): Define new accessor.
	(read_context::{load_elf_architecture, load_remaining_elf_data}):
	Define new methods.
	(read_corpus_from_elf): Use ctxt.load_remaining_elf_data() in lieu
	of ctxt.load_dt_soname_and_needed.  Stick the architecture into
	the corpus.
	* src/abg-reader.cc (read_corpus_from_input): Read the
	'architecture' XML property.
	* src/abg-writer.cc (write_corpus_to_native_xml): Write the
	'architecture' XML property.
	* tests/data/test-diff-dwarf/libtest-23-diff-arch-v0-32.so: New
	test input file.
	* tests/data/test-diff-dwarf/libtest-23-diff-arch-v0-64.so:
	Likewise.
	* tests/data/test-diff-dwarf/test-23-diff-arch-report-0.txt:
	Likewise.
	* tests/data/test-diff-dwarf/test-23-diff-arch-v0.cc: Source code
	for the binary test input files above.
	* tests/data/Makefile.am: Add the new test input files to the
	source distribution.
	* tests/test-diff-dwarf.cc (in_out_specs): Add the new test input
	data to the set of input data to run this test harness over.
	* tests/test-read-dwarf.cc (main): Do not take the architecture in
	account during comparisons.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2015-01-07 17:52:10 +01:00
Dodji Seketeli
1e82b98af2 Do not mark sibling structurally identical nodes as redundant
Consider the C code below:

    int
    foo(int a, int b)
    {
    }

that is changed as:

    float
    foo(float a, float b)
    {
    }

In this case, we want the 'abidiff' tool to report the three
occurrences of the 'int' -> 'float' change (in the return type and in
the two parameter changes of the function foo).

In the current code, the comparison engine only reports the first
occurrence of the change and consider the two other occurrences as
being redundant.  So, by default, it only reports the first occurrence
of the change.

This patch modifies the comparison engine to make it *NOT* mark the
two later occurrences of change as redundant because the three
occurrences of changes happen at the same logical level: they are all
children of the function diff node in the diff tree.

	* include/abg-comparison.h (diff::parent_node): Declare new
	accessor.
	* src/abg-comparison.cc (diff::priv::parent_): New data member.
	(diff::priv::priv): Initialize it.
	(diff::parent_node): Define new accessor.
	(diff::append_child_node): Set the diff::priv::parent_ data member
	of the added child node.
	(redundancy_marking_visitor::visit_begin): If two (logical)
	sibbling nodes are structurally equivalent, do not mark them as
	being redundant.
	* tests/data/test-diff-suppr/libtest10-changed-parm-c-v0.so: New
	test input binary.
	* tests/data/test-diff-suppr/libtest10-changed-parm-c-v1.so:
	Likewise.
	* tests/data/test-diff-suppr/test10-changed-parm-c-report-0.txt:
	New test input data.
	* tests/data/test-diff-suppr/test10-changed-parm-c-v0.c: Source
	code for the binary input above.
	* tests/data/test-diff-suppr/test10-changed-parm-c-v1.c: Likewise.
	* tests/data/Makefile.am: Add the new test files to source
	distribution.
	* tests/test-diff-suppr.cc (in_out_specs): Add the new test input
	to the vector of test inputs to run this harness over.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2014-12-26 18:45:06 +01:00
Dodji Seketeli
817aa5555e Un-share diff nodes in the comparison IR
Until now, the diff nodes of the comparison IR were shared.  That is,
two diffs about the same subjects were represented by the same diff
node that would appear twice in the tree.

This was preventing us from spotting e.g, the first occurrence of a
diff node that would later (in the tree) turn to be redundant because
all redundant diff nodes are represented by the same diff node
pointer.

This patch now makes each diff node be different, as far of pointer
comparison is concerned.  But it introduces the concept of canonical
diff node to ease the comparison between two diff nodes.  Two diff
nodes that are equal have the same canonical diff node.

With this facility, it's now possible to tell the difference between
diff nodes that are (structurally) equal.  It's not possible to say
things like "this is the first or second occurrence of the redundant
diff node foo'.

	* include/abg-ir.h: Prefix the doc string with "///", rather than
	writing it inside a /**/ comment.
	* include/abg-comparison.h (function_decl_diff)
	(function_decl_diff_sptr, fn_parm_diff, fn_parm_diff_sptr)
	(var_diff_sptr, base_diff, class_diff, class_diff_sptr): Move
	these class & typedef decls to the top of the file.
	(string_changed_base_map, string_changed_parm_map)
	(unsigned_changed_parm_map, changed_function_ptr)
	(string_changed_function_ptr_map): Remove these typedefs.
	(string_base_diff_sptr_map, string_fn_parm_diff_sptr_map)
	(unsigned_fn_parm_diff_sptr_map, string_var_diff_sptr_map)
	(unsigned_var_diff_sptr_map, string_function_decl_diff_sptr_map)
	(string_var_diff_ptr_map): New typedefs.
	(diff_context::{has_diff_for,add_diff}): Make these member
	functions private.
	(diff_context::{set_canonical_diff_for,
	set_or_get_canonical_diff_for}): Declare new private member
	functions.
	(diff_context::{get_canonical_diff_for,
	initialize_canonical_diff}): New public member functions.
	(diff_context::maybe_apply_filters): Set the default value of the
	'traverse_nodes_once' parameter to false.
	(compute_diff): Make the overload for class_decl_sptr friend of
	the diff_context class.
	(class diff): Make the diff_context class a friend of this one.
	(diff::set_canonical_diff): Declare new private member function.
	(diff::get_canonical_diff): Declare new public member function.
	(diff::children_nodes): Make this return a vector<diff_sptr>, rather
	than a vector<diff*>.
	(diff::append_child_node): Make this take a diff_sptr rather than
	a diff*.
	(class fn_parm_diff): Declare new type.
	(compute_diff): Declare new overload for the new
	function_decl::parameter_sptr.
	(function_decl_diff::subtype_changed_parms): Return a
	string_fn_parm_diff_sptr_map rather than a string_changed_parm.
	(function_decl_diff::children_nodes): Return a vector<diff_sptr>.
	(function_decl_diff::append_child_node): Take a diff_sptr.
	(function_decl_diff::changed_functions): Return a
	string_function_decl_diff_sptr_map.
	(function_decl_diff::changed_variables): Return a
	string_var_diff_sptr.
	(class function_decl::parameter): Make this a pimpled class.
	Also, make it inherit decl_base.
	(equals): New overload for function_decl::parameter.
	(struct function_decl::parameter::hash): Declare this.
	(ir_node_visitor::visit): Declare new overload for
	function_decl::parameter.
	* src/abg-comparison.cc: Add doc-string about the internal
	representation of the comparison engine and also about the concept
	of canonical diff of the comparison engine.
	(RETURN_IF_BEING_REPORTED_OR_WAS_REPORTED_EARLIER)
	(RETURN_IF_BEING_REPORTED_OR_WAS_REPORTED_EARLIER2)
	(RETURN_IF_BEING_REPORTED_OR_WAS_REPORTED_EARLIER3): Consider the
	canonical diff when trying to know if the current node was
	reported earlier.
	(diff_context::priv::canonical_diffs): New data member.
	(diff_context::{get_canonical_diff_for, set_canonical_diff_for,
	set_or_get_canonical_diff_for, initialize_canonical_diff}): Define
	new member functions.
	(diff_context::{diff_has_been_traversed, mark_diff_as_traversed):
	Consider canonical diff for these tests and actions.
	(diff::priv::children_): Change the type of this to
	vector<diff_sptr>.
	(diff::canonical_diff_): New data member.
	(diff::diff): Initialize the diff::canonical_diff_ data member.
	(diff::begin_traversing): Mark the canonical diff node too.
	(diff::is_traversing): Consider the canonical diff node in this
	test.
	(diff::end_traversing): Make the canonical diff node too.  Also
	mark the current node as having been traversed.
	(diff::children_nodes): Return a vector<diff_sptr> type.
	(diff::{get_canonical_diff, set_canonical_diff}): Define new
	member functions.
	(diff::append_child_node): Take a diff_sptr type parameter.
	(diff::{reported_once, currently_reporting}): Flag the canonical
	diff node too.  And consider the canonical diff node when checking
	the flag.
	(diff::traverse): No need to mark the node as being traversed
	because the diff::end_traversing() function does it now.  Adjust
	the code because diff::children_nodes() now returns
	vector<diff_sptr>.
	({distinct_diff, var_diff, pointer_diff, array_diff,
	reference_diff, qualified_type_diff, enum_diff, class_diff,
	base_diff, scope_diff, function_decl_diff, typedef_diff,
	corpus_diff}::chain_into_hierarchy): Adjust to the new type that
	diff::append_child_node() takes.  Also, take into account that the
	diff nodes are now un-shared.
	(compute_diff_for_distinct_kinds, compute_diff_for_types)
	(compute_diff): Do not share diff nodes anymore.  Initialize the
	canonical diff node for the new created node.
	(represent): Take a var_diff_sptr rather than two var_decl_sptr.
	Adjust.  Also take in account the fact that diff nodes are not
	shared anymore, and that they do have canonical diffs.
	(var_diff::type_diff): Make the computation of the type_diff of
	the var_diff be lazy.  This avoids infinite (recursive) creation
	of diff nodes when a class diff node has a sub-type of data member
	that is a class diff node too.
	(var_diff::report): Detect redundant reporting of this kind of
	diff node.
	(class_diff::priv::changed_bases_): Change the type of this to
	string_base_diff_sptr_map.
	(class_diff::priv::subtype_changed_dm_): Change the type of this
	to string_var_diff_sptr_map.
	(class_diff::priv::changed_dm_): Change the type of this to
	unsigned_var_diff_sptr_map.
	(class_diff::priv::{count_filtered_subtype_changed_dm,
	count_filtered_bases}): Do not take a diff_context_sptr anymore.
	(class_diff::ensure_lookup_tables_populated): changed_bases_
	subtype_changed_dm_ and changed_dm_ are now *NOT* shared diff
	nodes anymore.
	(class_diff::priv::base_has_changed): Adjust.
	(class_diff::priv::subtype_changed_dm): Adjust.
	(class_diff::priv::count_filtered_bases): Adjust as changed_bases_
	is now a map of un-shared diff nodes.
	(class_diff::priv::count_filtered_subtype_changed_dm): Adjust as
	subtype_changed_dm_ is now a map of un-shared diff nodes.
	(class_diff::priv::{count_filtered_changed_mem_fns,
	count_filtered_inserted_mem_fns, count_filtered_deleted_mem_fns,
	}): Adjust for change of the default parameter value of
	diff_context::maybe_apply_filters().
	(class_diff::~class_diff): New destructor.
	(class_diff::changed_bases): Return a string_base_diff_sptr_map&
	type.
	(class_diff::{inserted_data_members, deleted_data_members,
	changed_member_fns}): Add doc strings.
	(struct changed_data_member_comp): Remove.
	(struct var_diff_comp): New comparison functor.
	(sort_changed_data_members): Remove.
	(sort_var_diffs): Define new sorting function.
	(class_diff::report): Adjust.
	(fn_parm_diff::*): Define member types and functions of the new
	fn_parm_diff type.
	(function_decl_diff::priv::{subtype_changed_parms_,
	changed_parms_by_id_}): Make these take a map of fn_parm_diff_sptr
	nodes.
	(function_decl_diff::ensure_lookup_tables_populated): Adjust to
	the fact that priv_->subtype_changed_parms_ and
	priv_->priv_->changed_parms_by_id_ now are maps of un-shared
	fn_parm_diff_sptr nodes.
	(function_decl_diff::subtype_changed_parms): Adjust.
	(struct changed_parm_comp): Remove.
	(struct fn_parm_diff_comp): New comparison functor.
	(sort_changed_parm_map): Remove.
	(sort_string_fn_parm_diff_sptr_map): New sorting function.
	(function_decl_diff::report): Adjust.
	(corpus_diff::priv::children_): Change the type of this to
	vector<diff_sptr>.
	(corpus_diff::priv::changed_fns_): Changed the type of this to
	string_function_decl_diff_sptr_map.
	(corpus_diff::priv::changed_vars_): Changed the type of this to
	string_var_diff_sptr_map.
	(corpus_diff::priv::ensure_lookup_tables_populated): Adjust.
	(corpus_diff::priv::apply_filters_and_compute_diff_stats}):
	Adjust.  Do not need to clear redundancy categorization anymore
	because the diff nodes are not shared anymore.
	(corpus_diff::priv::categorize_redundant_changed_sub_nodes):
	Adjust.
	(corpus_diff::priv::clear_redundancy_categorization): Adjust.
	(corpus_diff::changed_variables): Adjust.
	(struct changed_function_ptr_comp): Remove.
	(struct function_decl_diff_comp): New comparison functor.
	(sort_string_changed_function_ptr_map): Remove.
	(sort_string_function_decl_diff_sptr_map): Define new sorting
	function.
	(struct changed_vars_comp): Remove.
	(struct var_diff_sptr_comp): New comparison functor.
	(sort_changed_vars): Remove.
	(sort_string_var_diff_sptr_map): Define new sorting function.
	(corpus_diff::report): Adjust.
	(corpus_diff::traverse): Adjust.
	({category_propagation_visitor,
	suppression_categorization_visitor}::visit_end): Adjust.
	(clear_redundancy_categorization): Adjust.
	* src/abg-hash.cc (function_decl::parameter:#️⃣:operator):
	Adjust.
	* src/abg-ir.cc (struct function_decl::parameter::priv): Define
	here as part of pimpl-ifying the function_decl::parameter type.
	(function_decl::parameter::*): Define here the member functions as
	part of pimpl-ifying the function_decl::parameter type.
	(equals): Define the overload for function_decl::parameter here
	too.
	(ir_node_visitor::visit(function_decl::parameter*)): Define this.
	* tests/data/test-abicompat/test0-fn-changed-report-0.txt: Adjust.
	* tests/data/test-diff-suppr/test5-fn-suppr-report-0.txt: Adjust.
	* tests/data/test-diff-dwarf/libtest21-redundant-fn-v0.so: New
	test input data.
	* tests/data/test-diff-dwarf/libtest21-redundant-fn-v1.so:
	Likewise.
	* tests/data/test-diff-dwarf/test21-redundant-fn-v0.cc: Source
	code for test input binary above.
	* tests/data/test-diff-dwarf/test21-redundant-fn-v1.cc: Likewise.
	* tests/data/test-diff-dwarf/test21-redundant-fn-report-0.txt: New
	test input data.
	* tests/data/test-diff-dwarf/libtest22-changed-parm-c-v0.so: New
	test input data.
	* tests/data/test-diff-dwarf/libtest22-changed-parm-c-v1.so:
	Likewise.
	* tests/data/test-diff-dwarf/test22-changed-parm-c-v0.c: Source
	code for test input binary above.
	* tests/data/test-diff-dwarf/test22-changed-parm-c-v1.c: Likewise.
	* tests/test-diff-dwarf.cc (in_out_spec): Add the new test input
	data to the vector the test inputs to run this harness over.
	* tests/data/test-diff-suppr/test8-redundant-fn-report-0.txt: New
	test input data.
	* tests/data/test-diff-suppr/test8-redundant-fn-report-1.txt:
	Likewise.
	* tests/data/test-diff-suppr/libtest8-redundant-fn-v0.so: New test
	input binary.
	* tests/data/test-diff-suppr/libtest8-redundant-fn-v1.so: Likewise.
	* tests/data/test-diff-suppr/test8-redundant-fn-v0.cc: Source code
	code for binary test input above.
	* tests/data/test-diff-suppr/test8-redundant-fn-v1.cc: Likewise.
	* tests/data/test-diff-suppr/test9-changed-parm-c-report-0.txt:
	New test input data.
	* tests/data/test-diff-suppr/test9-changed-parm-c-report-1.txt:
	Likewise.
	* tests/data/test-diff-suppr/libtest9-changed-parm-c-v0.so: New
	test input binary.
	* tests/data/test-diff-suppr/libtest9-changed-parm-c-v1.so: New
	test input binary.
	* tests/data/test-diff-suppr/test9-changed-parm-c-v0.c: Source
	code for binary test input above.
	* tests/data/test-diff-suppr/test9-changed-parm-c-v1.c: Likewise.
	* tests/test-diff-suppr.cc (in_out_specs): Add the new test input
	data to the vector the test inputs to run this harness over.
	* tests/data/Makefile.am: Add the new files to the source
	distribution.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2014-12-26 18:45:06 +01:00
Dodji Seketeli
8879d00538 Extend detection of compatible types to arrays
* include/abg-fwd.h (is_array_type): Renamed is_array_type_def()
	into this for consistency.
	* src/abg-comparison.cc (type_suppression::suppresses_diff):
	Adjust.
	* src/abg-dwarf-reader.cc (build_array_type): Remove useless code
	that was trying to read a DW_AT_byte_size attribute from the DIE
	of the array, but then wasn't doing anything with the value.  But
	then if the attribute was not present, the array type wouldn't be
	built.
	* src/abg-ir.cc (strip_typedef): Strip typedefs from sub-types of
	array types too.
	(is_array_type): Rename is_array_def() to this, for consistency.
	(var_decl::get_pretty_representation): Adjust.
	* tests/data/test-diff-filter/libtest24-compatible-vars-v0.so: New
	test input data.
	* tests/data/test-diff-filter/libtest24-compatible-vars-v1.so: Likewise.
	* tests/data/test-diff-filter/test24-compatible-vars-report-0.txt:
	Likewise.
	* tests/data/test-diff-filter/test24-compatible-vars-v0.c: Source
	code for the first binary above.
	* tests/data/test-diff-filter/test24-compatible-vars-v1.c: Source
	code for the second binary above.
	* tests/data/Makefile.am: Add the new test input data to source
	distribution.
	* tests/test-diff-filter.cc (in_out_specs): Add the new test input
	data to the list of input to run this test harness over.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2014-12-12 14:44:24 +01:00
Dodji Seketeli
8f994b5e29 Temporarily disable redundant diff report elimination
So, this is all about problem report
https://sourceware.org/bugzilla/show_bug.cgi?id=17693.

When redundant diff node reporting is enabled and when a diff node
appears twice in a diff tree, we detect that and the second occurrence
of the diff node is flagged as being redundant.  Later at diff tree
node reporting time, the redundant diff node is not reported.

The problem is that diff nodes are canonicalized.  That is, when the
same change is present twice in a diff, the same diff node is going to
be present twice.  So flagging the second occurrence as being
redundant amounts as flagging the first occurrence as being redundant
too!  So at reporting time, the diff tree visitor that walks the diff
tree nodes will avoid reporting the two occurrences of diff tree nodes
altogether.  This is what happens in the example of the bug above.  I
am reproducing the example here for convenience:

So suppose we have a first version of a library named lib-v0.so which
is made of this C code:

    int add(int a, int b)
    {
    }

Then suppose that code was changed in a subsequent version of the
library named lib-v1.so, leading to the following code:

    int add(float a, float b)
    {
    }

So, the diff tree node for the 'add' function is going to have several
child diff tree nodes, among which, one that carries the change for
the first parameter (int a becoming float a) and the one carrying the
change for the second parameter (int b becoming float b).

The diff tree node for the second parameter is going to be same diff
tree node as the one for the first parameter because what counts is
the change in the *type* of the parameter.  Thus, the diff tree node
for the second parameter is going to be marked as being redundant; and
so is the first parameter.

So abidiff lib-v0.so lib-v1.so yields:

    Functions changes summary: 0 Removed, 0 Changed (1 filtered out), 0 Added
    function
    Variables changes summary: 0 Removed, 0 Changed, 0 Added variable

You can see that even the function 'add' is not mentioned in the
report.  This is because it has also been considered as being
redundant because of a phenomenon named 'propagation'.  The
redundant-ness of the children nodes of the diff tree node of the
'add' function is propagated to the diff tree node of the add function
itself because that add function diff tree node has no child but
redundant diff children nodes.  This categorization behaviour is
correct.

What is not correct is that only the second child node of the add
function diff tree node should have been marked redundant.

I am going to tackle this issue a bit later.  For now, I am
temporarily disabling redundancy categorization for diff tree nodes by
default.  Hence this patch.

With this patch, abidiff lib-v0.so lib-v1.so yields:

    Functions changes summary: 0 Removed, 1 Changed, 0 Added function
    Variables changes summary: 0 Removed, 0 Changed, 0 Added variable

    1 function with some indirect sub-type change:

      [C]'function int add(int, int)' has some indirect sub-type changes:
	parameter 0 of type 'int' changed:
	  name changed from 'int' to 'float'
	parameter 1 of type 'int' changed:
	  name changed from 'int' to 'float'

Note how the change on the second parameter appears equal to the
change on the first.

	* src/abg-comparison.cc
	(diff_context::priv::priv): Show redundant changes by default.
	(categorize_redundancy): Do not categorize redundancy if the
	diff_context says that we shouldn't.
	* tools/abicompat.cc (options::show_redundant): New data member.
	(options::options): Initialize to true.
	(display_usage): Add new help string for new --no-redundant and
	--redundant options.
	(parse_command_line): Parse new --no-redundant and --redundant
	command line options.
	(main): Initialize the diff context with respect to the
	options::show_redundant property.
	* tools/abidiff.cc (options::options): Initialize the
	show_redundant_changes data member to true.
	(display_usage): Show new help string for the new --no-redundant
	command line option.
	(parse_command_line): Parse the new --no-redundant command line
	option.
	* tests/data/test-diff-filter/libtest23-redundant-fn-parm-change-v0.so:
	New test data input.
	* tests/data/test-diff-filter/libtest23-redundant-fn-parm-change-v1.so:
	Likewise.
	* tests/data/test-diff-filter/test23-redundant-fn-parm-change-report-0.txt:
	Likewise.
	* tests/data/test-diff-filter/test23-redundant-fn-parm-change-v0.c:
	Source code for the first binary above.
	* tests/data/test-diff-filter/test23-redundant-fn-parm-change-v1.c:
	Source code for the second binary above.
	* tests/data/Makefile.am: Add the new test data input to source
	distribution.
	* tests/test-abicompat.cc (in_out_specs): Add --no-redundant to
	abicompat when we don't want it to show redundant diff reports.
	* test-diff-filter.cc (in_out_specs): Likewise for abidiff.
	* test-diff-suppr.cc (in_out_specs): Likewise.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2014-12-10 19:19:57 +01:00
Jan Engelhardt
112432bbd2 Fix conditional build wrt zip archives and cx11
Revert 1b4e3844e9. Automake does support
nested conditionals just fine.  One just has to use the += operator.

This also fixes the problem:

	./configure: line 15878: ENABLE_ZIP_ARCHIVE_AND_CXX11:
	command not found

caused by bad syntax:

	ENABLE_ZIP_ARCHIVE_AND_CXX11 = yes

(Variable assignments must not use spaces around '=').

	* configure.ac: remove (broken) assignment to the
	ENABLE_ZIP_ARCHIVE_AND_CXX11 variable
	* Makefile.am: replace variable assignments to
	ZIP_ARCHIVE_TESTS_FIRST_PART, ZIP_ARCHIVE_TESTS_SECOND_PART
	by ZIP_ARCHIVE_TESTS using the "+=" automake operator.
	Likewise for CXX11_TESTS.

Signed-off-by: Jan Engelhardt <jengelh@inai.de>
Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2014-12-10 14:35:55 +01:00
Dodji Seketeli
1b75fd3eac Make determining of compatible types complete
Until now, two types that are different were considered compatible if
one type is a typedef of the other.  This is useful because two
different types, if compatible, are not ABI-incompatible.  This patch
extends the concept of compatible types to types which might have
sub-types that are typedefs of each others, including function types.

Note implementing this required that I fixed various other things left
and right.  Like style fixes, crash avoiding fixes, etc.

	* include/abg-fwd.h (is_reference_type, is_function_type)
	(is_method_type): Declare new predicates.
	* include/abg-ir.h (class qualified_type_def): Pimpl this class.
	(qualified_type_def::qualified_type_def): Use the convenience
	type_base_sptr typedef.
	(qualified_type_def::{get_cv_quals, set_cv_quals}): Use the
	qualified_type_def::CV type rather than char.
	(qualified_type_def::get_underlying_type): Use the convenience
	type_base_sptr typedef.
	(pointer_type_def::pointer_type_def): Likewise.
	(function_decl::parameter::parameter): Add a new constructor.
	* src/abg-ir.cc (is_reference_type, is_function_type)
	(is_method_type): Define new predicates.
	(class qualified_type_def::priv): Define this new private type,
	for the purpose of Pimpl-ifying the qualified_type_def class.
	(qualified_type_def::{qualified_type_def, build_name,
	get_cv_quals_string_prefix, get_underlying_type}): Adjust for the
	purpose of Pimpl-ifying the qualified_type_def class.
	(equals): In the qualified_type_def, reference_type_def overloads,
	trust the fact that we have operator== overload for the
	type_base_sptr.  This avoids crashes for when the (possible)
	underlying type is null.
	(pointer_type_def::operator==): Likewise.
	(strip_typedef): Make this recursively strip
	typedefs from sub-types.
	(types_are_compatible): Handle null types.
	(qualified_type_def::{get_cv_quals, set_cv_quals}): Handle
	qualified_type_def::CV rather than char.
	(pointer_type_def::pointer_type_def): Use the convenience
	type_base_sptr typedef.
	* include/abg-comparison.h (distinct_diff::compatible_child_diff):
	Declare new member function.
	* src/abg-comparison.cc (distinct_diff::compatible_child_diff):
	Define new member function.
	(distinct_diff::chain_into_hierarchy):
	Chain the compatible child diff node that might be present.
	(distinct_diff::report): Now when a distinct diff carries a
	compatible change, mention it in the report.
	* src/abg-comp-filter.cc (is_compatible_change): A compatible
	change can now involve types that are not typedefs.  Only their
	sub-types need to be involved with typedef-ness.
	* tests/data/test-diff-dwarf/test{2,4,5}-report.txt: Adjust.
	* tests/data/test-diff-filter/libtest21-compatible-vars-v0.so: New
	test data input.
	* tests/data/test-diff-filter/libtest21-compatible-vars-v1.so: Likewise.
	* tests/data/test-diff-filter/test21-compatible-vars-report-0.txt Likewise.
	* tests/data/test-diff-filter/test21-compatible-vars-report-1.txt Likewise.
	* tests/data/test-diff-filter/test21-compatible-vars-v0.cc: Source
	code for the first data input binary above.
	* tests/data/test-diff-filter/test21-compatible-vars-v1.cc: Source
	code for the second data input binary above.
	* tests/data/test-diff-filter/libtest22-compatible-fns-v0.so: New
	test data input.
	* tests/data/test-diff-filter/libtest22-compatible-fns-v1.so Likewise.
	* tests/data/test-diff-filter/test22-compatible-fns-report-0.txt:
	New test data input.
	* tests/data/test-diff-filter/test22-compatible-fns-report-1.txt: Likewise.
	* tests/data/test-diff-filter/test22-compatible-fns-v0.c: Source
	code for the first test data input binary above.
	* tests/data/test-diff-filter/test22-compatible-fns-v1.c: Source
	code for the second test data input binary above.
	* tests/data/Makefile.am: Add the new test input data to source
	distribution.
	* tests/test-diff-filter.cc (in_out_specs): Add the new test data
	input above to the list of test data this harness has to be run
	over.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2014-12-10 08:02:32 +01:00
Dodji Seketeli
eecf5f87df Fix classification of parameter addition in C
The comparison engine classifies an addition or removal of parameter
from a C function as harmless.  This is a mistake that impacts abidiff
and abicompat.  Fixed thus.

	* src/abg-comp-filter.cc (function_name_changed_but_not_symbol):
	Compare the fully qualified name of the functions; not their
	pretty representation.
	* tests/data/test-diff-dwarf/libtest20-add-fn-parm-v0.so: New test
	data intput.
	* tests/data/test-diff-dwarf/libtest20-add-fn-parm-v1.so:
	Likewise.
	* tests/data/test-diff-dwarf/test20-add-fn-parm-report-0.txt:
	Likewise.
	* tests/data/test-diff-dwarf/test20-add-fn-parm-v0.c: Source code
	for the first shared library above.
	* tests/data/test-diff-dwarf/test20-add-fn-parm-v1.c: Source code
	for the second shared library above.
	* tests/test-diff-dwarf.cc (in_out_specs): Add the test input data
	above to the list of test input the harness must run over.
	* Makefile.am: Add the new files above to source distribution.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2014-12-09 13:10:58 +01:00
Dodji Seketeli
775cfcde0c Wire the soname check into abicompat
Now that the comparison engine knows how to take SONAMEs into account
during ABI abi comparison, it's feasible to make abicompat leverage
that capability.  This patch does just that.

	* include/abg-comparison.h (corpus_diff::soname_changed): Declare
	new member function.
	* src/abg-comparison.cc (corpus_diff::soname_changed): Define new
	member function.
	(corpus_diff::length): Use the new corpus_diff::soname_changed()
	method.
	* tests/data/test-abicompat/libtest4-soname-changed-v0.so: New
	test input data.
	* tests/data/test-abicompat/libtest4-soname-changed-v1.so:
	Likewise.
	* tests/data/test-abicompat/test4-soname-changed-app: Likewise.
	* tests/data/test-abicompat/test4-soname-changed-report-0.txt:
	Likewise.
	* tests/data/test-abicompat/test4-soname-changed-app.cc: Source
	code for one of the binaries above.
	* tests/data/test-abicompat/test4-soname-changed-v0.cc: Likewise.
	* tests/data/test-abicompat/test4-soname-changed-v1.cc: Likewise.
	* tests/test-abicompat.cc (in_out_specs): Add the new test input
	data to the list of input data to run this harness over.
	(main): Take the soname change in account to determine if the
	change is ABI incompatible.
	* tests/data/Makefile.am: Add the new test input data above to source
	distribution.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2014-12-08 13:47:00 +01:00
Dodji Seketeli
ae98acdb90 Fixup messed up old runtestdiffdwarf input tests
While working on supporting the comparison of sonames I realized that
the runtestdiffdwarf test harness was missing some input data.  This
patch addresses that.

	* tests/data/test-diff-dwarf/test17-non-refed-syms-report-0.txt:
	Add this missing reference test output.
	* tests/data/Makefile.am: Add the new reference test output to
	source distribution.
	* tests/data/test-diff-dwarf/test18-alias-sym-report-0.txt: Fix
	this output to avoid emitting symbol alias information in it.
	* tests/test-diff-dwarf.cc (in_out_specs): Add two missing test
	input data to the list of input data this harness is supposed to
	run over.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2014-12-07 23:42:26 +01:00
Dodji Seketeli
721728e7de Support reading and comparing soname from ELF files
Libabigail's DWARF reader doesn't read the DT_SONAME tag from the
.dynamic section.  The abigail::corpus type doesn't have a property
for that tag either.  And the comparison engine doesn't take that tag
in when comparing corpora.

This patch modifies the DWARF reader to read the DT_SONAME and
DT_NEEDED tags from the .dynamic section.  The value of DT_SONAME tag
is then saved in the new corpus property accessed by the new
abigail::corpus::get_soname() accessor.  The comparison engine has
also been modified to compare the sonames of two corpora being
compared.  Note that the value of the DT_NEEDED elf tag is saved in a
new corpus property that is accessed via the new
abigail::corpus::get_needed() getter.  This property is not used yet.

This patch also adds a unit test for this new feature.

	* include/abg-corpus.h (corpus::{get_needed, set_needed,
	get_soname, set_soname}): Declare new accessors.
	* src/abg-corpus.cc (corpus::priv::{needed, soname}): New data
	members.
	(corpus::{get_needed, set_needed, get_soname, set_soname}): Define
	new accessors.
	(corpus::is_empty): Take dt_needed and dt_soname in account in
	computing empty-ness.
	* src/abg-dwarf-reader.cc (read_context::{dt_needed_,
	dt_soname_}): New data members.
	(read_context::{dt_needed, dt_soname}): New accessors.
	(read_context::load_dt_soname_and_needed): New member function.
	(read_corpus_from_elf): Call the new
	read_context::load_dt_soname_and_needed() to read the dt_soname
	and dt_needed tags.  Set them to the corpus.
	* include/abg-comparison.h (diff_context::show_soname_change):
	Declare new accessors.
	* src/abg-comparison.cc (diff_context::priv::show_soname_change_):
	New data member.
	(diff_context::priv::priv): Initialize the new data member
	diff_context::priv::show_soname_change_.
	(diff_context::show_soname_change): Define new accessors.
	(corpus_diff::priv::sonames_equal_): New data member.
	(corpus_diff::priv::priv): Initialize the new data member
	corpus_diff::priv::sonames_equal_.
	(corpus_diff::length): Take the new priv_->sonames_equals_ data
	member in account.
	(corpus_diff::{report, priv::emit_diff_stats}): If the sonames
	changed and we are allowed to report it, then report it.
	(compute_diff): In the variant for corpus_diff, do not forget to
	compare the sonames.
	* src/abg-reader.cc (build_needed, read_elf_needed_from_input):
	Define new static functions.
	(read_corpus_from_input): Read the 'soname' attribute from the
	'abi-corpus' xml element node.
	* src/abg-writer.cc (write_elf_needed): Define new static
	function.
	(write_corpus_to_native_xml): Write a new 'elf-needed' xml element
	node that contains one xml 'dependency' element node per
	dependency to emit.  This uses the new write_elf_needed() function
	above.
	* tests/data/test-diff-dwarf/libtest19-soname-v0.so: New test
	input data.
	* tests/data/test-diff-dwarf/libtest19-soname-v1.so: Likewise.
	* tests/data/test-diff-dwarf/test19-soname-report-0.txt: Likewise.
	* tests/data/test-diff-dwarf/test19-soname-v0.c: Source code of
	the first binary above.
	* tests/data/test-diff-dwarf/test19-soname-v1.c: Source code of
	the second binary above.
	* tests/test-diff-dwarf.cc (in_out_specs): Add the test input
	above to the list of test input to run this harness on.
	* tests/data/Makefile.am: Add the new test input data above.
	* tests/data/test-read-dwarf/test{0,1}.abi: Adjust.
	* tests/data/test-read-dwarf/test{2,3,4,6,}.so.abi: Adjust.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2014-12-07 23:42:26 +01:00
Dodji Seketeli
c0a31b48c7 Fix a crash while writing symbol information
While working on something else, I noticed that the abilint tool would
crash when trying to write information relative to some symbol
information.  It turned out that invoking corpus::get_fun_symbol_map()
or corpus::get_var_symbol_map() on a corpus that has an empty function
(or variable) symbol map yields a crash.  This patch fixes that.

To test the fix I had to extend the test-read-write.cc test harness to
teach it to load corpus files too; up to now it was only loading
simple translation unit files (named Binary Instrumentation files).  I
then created a native xml corpus file using the abidw tool on a simple
shared library I created.  That corpus file does have an empty
variable symbol section which triggers the crash on a non-fixed tree.

	* src/abg-corpus.cc (corpus::{get_fun_symbol_map_sptr,
	get_var_symbol_map_sptr}): Make sure the symbol map is always
	constructed, even if it's empty.
	* tests/data/test-read-write/test26.xml: New test input data.
	* tests/test-read-write.cc (in_out_spec): Add this new test input
	data to the list of input data to run the harness on.
	(main): Support reading and writing corpus files alongside
	translation unit files that we were handling already.
	* tests/data/Makefile.am: Add the new test input data to source
	distribution.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2014-12-07 17:25:26 +01:00
Dodji Seketeli
ef7e71febf Initial implementation of the abicompat tool
Given an application A that links to a shared library L of version V
denoted L(V) and a subsequent version of that library denoted L(V+P),
the 'abicompat' tool tells the user if L(V+P) is still ABI compatible
with L(V+P).  And if it is not, abicompat gives a reports that shows
the differences between L(V) and L(V+P) that makes L(V+P)
ABI-incompatible with A.

The source code of this tool is in the tools/abicompat.cc source
file.  To support this new tool, this commit changes the comparison
engine to optionally avoid showing added symbols that were not
referenced by any debug info.  It changes the ABI corpus type to allow
the specification of a list of variables and functions symbols to keep
(and drop all other functions and variables which have other symbols
on the floor even before starting to compare the two libraries).

This is how the abicompat tool itself works.  It basically compares
L(V) and L(V+P) but it only looks at their exported functions and
variables which symbols are undefined in application A.  If the list
of exported and defined variables and functions of L(V) whose symbols
are undefined in A equals that of L(V+P) (including the sub-types of
these variables and functions) A is still compatible with L(V+P).
Otherwise, they might not be compatible depending on the kind of
differences that are found.

	* include/abg-comparison.h
	(diff_context::show_added_symbols_unreferenced_by_debug_info):
	Declare new accessors.
	(corpus_diff::{deleted_variables,
	deleted_unrefed_function_symbols,
	deleted_unrefed_variable_symbols,
	apply_filters_and_suppressions_before_reporting}): Declare new
	methods.
	(corpus_diff::diff_stats): Declare this new type.  Actually this
	was previously corpus_diff::priv::diff_stats, which was a hidden
	internal type..  We are moving it here, in the external API so
	that client code can have more information about changes
	statistics.  Change all the previously publicly accessible data
	members into accessor functions.
	* src/abg-comparison.cc (class corpus_diff::diff_stats::priv): New
	type.
	(diff_context::priv::show_added_syms_unreferenced_by_di_): New
	data member.
	(diff_context::priv::priv): Adjust.
	(diff_context::show_added_symbols_unreferenced_by_debug_info):
	Define this new method.
	(corpus_diff::priv::emit_diff_stats):  Do not show the diff stat
	if the only changes is added function or variables symbols and if
	we were instructed to not show added symbols.
	(corpus_diff::priv::{diff_stats_, filters_and_suppr_applied_}):
	New data members.
	(corpus_diff::priv::priv): Initialize the
	filters_and_suppr_applied_ data member.
	(corpus_diff::priv::diff_stats): Move this type to
	corpus_diff::diff_stats.
	(corpus_diff::priv::{apply_filters_and_compute_diff_stats,
	emit_diff_stats}): Adjust.
	(corpus_diff::apply_filters_and_suppressions_before_reporting):
	Define new member function.
	(corpus_diff::report): Use the new
	apply_filters_and_suppressions_before_reporting() function, rather
	than applying the filters and suppressions by ourselves.  Also
	adjust to the use the accessors of the new corpus_diff::diff_stats
	type.
	(corpus_diff::{deleted_variables,
	deleted_unrefed_function_symbols,
	deleted_unrefed_variable_symbols}): Define new accessors.
	(corpus_diff::diff_stats::{diff_stats, num_func_removed,
	num_func_added, num_func_changed, num_func_filtered_out,
	net_num_func_changed, num_vars_removed, num_vars_added,
	num_vars_changed, num_vars_filtered_out, net_num_vars_changed,
	num_func_sym_removed, num_func_syms_added, num_var_syms_removed,
	num_var_syms_added}): Define new member functions.
	* include/abg-corpus.h (corpus::{get_sym_ids_of_fns_to_keep,
	get_sym_ids_of_vars_to_keep}): Declare new methods.
	* src/abg-corpus.cc (corpus::priv::{sym_id_fns_to_keep,
	sym_id_vars_to_keep}): Added data members.
	(symtab_build_visitor_type::{unrefed_fun_symbols,
	unrefed_var_symbols, sym_id_fns_to_keep, sym_id_vars_to_keep}):
	Added new data members.
	(symtab_build_visitor_type::symtab_build_visitor_type): Take two
	additional parameters for the function and variable symbol ids to
	keep.
	(symtab_build_visitor_type::add_fn_to_wip_fns): Take the function
	symbols to keep in account when building the exported symbol
	table.
	(symtab_build_visitor_type::add_var_to_wip_vars): Likewise, take
	the variable symbols to keep in account when building the exported
	symbol table.
	(corpus::priv::build_public_decl_table): Adjust the initialization
	of the visitor that walks the ABI artifacts to build the exported
	symbol table to know take a list of function/variable symbols to
	keep.
	(corpus::priv::build_unreferenced_symbols_tables): Ensure that the
	public table of functions/variables is built before doing the work
	of this function.  Also, if a list of variable/function symbols to
	keep is given, drop all symbols that are not in that list on the
	floor.
	(corpus::{get_sym_ids_of_fns_to_keep,
	get_sym_ids_of_vars_to_keep}): Define new accessors.
	* tools/abicompat.cc: New abicompat tool.
	* doc/manuals/abicompat.rst: New documentation source for
	abicompat.
	* doc/manuals/libabigail-tools.rst: Add an entry for the abicompat
	doc.
	* tests/test-abicompat.cc: New test harness for the 'abicompat'
	tool.
	* tests/Makefile.am: Build the runtestabicompat test harness and
	add it to the list of tests harnesses that are run by make check.
	* tests/data/test-abicompat/libtest0-fn-changed-libapp-v0.so: New
	test input.
	* tests/data/test-abicompat/libtest0-fn-changed-libapp-v1.so: Likewise.
	* tests/data/test-abicompat/test0-fn-changed-app: Likewise.
	* tests/data/test-abicompat/test0-fn-changed-0.suppr: Likewise
	* tests/data/test-abicompat/test0-fn-changed-report-0.txt: Likewise.
	* tests/data/test-abicompat/test0-fn-changed-report-1.txt: Likewise.
	* tests/data/test-abicompat/test0-fn-changed-app.cc: Likewise.
	* tests/data/test-abicompat/test0-fn-changed-libapp.h: Likewise.
	* tests/data/test-abicompat/test0-fn-changed-libapp-v0.cc: Likewise.
	* tests/data/test-abicompat/test0-fn-changed-libapp-v1.cc: Likewise.
	* tests/data/test-abicompat/libtest1-fn-removed-v0.so: Likewise.
	* tests/data/test-abicompat/libtest1-fn-removed-v1.so: Likewise.
	* tests/data/test-abicompat/test1-fn-removed-app: Likewise.
	* tests/data/test-abicompat/test1-fn-removed-app.cc: Likewise.
	* tests/data/test-abicompat/test1-fn-removed-report-0.txt: Likewise.
	* tests/data/test-abicompat/test1-fn-removed-v0.cc: Likewise.
	* tests/data/test-abicompat/test1-fn-removed-v1.cc: Likewise.
	* tests/data/test-abicompat/libtest2-var-removed-v0.so: Likewise.
	* tests/data/test-abicompat/libtest2-var-removed-v1.so: Likewise.
	* tests/data/test-abicompat/test2-var-removed-app: Likewise.
	* tests/data/test-abicompat/test2-var-removed-app.cc: Likewise.
	* tests/data/test-abicompat/test2-var-removed-report-0.txt: Likewise.
	* tests/data/test-abicompat/test2-var-removed-v0.cc: Likewise.
	* tests/data/test-abicompat/test2-var-removed-v1.cc: Likewise.
	* tests/data/test-abicompat/libtest3-fn-removed-v0.so: Likewise.
	* tests/data/test-abicompat/libtest3-fn-removed-v1.so: Likewise.
	* tests/data/test-abicompat/test3-fn-removed-app: Likewise.
	* tests/data/test-abicompat/test3-fn-removed-app.cc: Likewise.
	* tests/data/test-abicompat/test3-fn-removed-report-0.txt: Likewise.
	* tests/data/test-abicompat/test3-fn-removed-v0.cc: Likewise.
	* tests/data/test-abicompat/test3-fn-removed-v1.cc: Likewise.
	* tests/data/test-abicompat/test3-fn-removed-version-script-0 Likewise.:
	* tests/data/test-abicompat/test3-fn-removed-version-script-1: Likewise.
	* tests/data/Makefile.am: Add the new test inputs above to the
	source distribution.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2014-12-05 15:43:31 +01:00
Dodji Seketeli
5c19aa1061 Make tests/data directory have its own Makefile
On RHEL 6, make distcheck was trying to compile the C++ files that are
in tests/data.  Having a dedicated tests/data Makefile.am which only
put the data files into an EXTRA_DIST variable fixes that.

	* configure.ac(AC_CONFIG_FILE): Generate a new tests/data/Makefile
	file.
	* tests/Makefile.am: Link the data/ sub-directory from here.  Move
	the EXTRA_DIST definition to ...
	* tests/data/Makefile.am: ... this new file here.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2014-11-20 11:26:30 +01:00
Dodji Seketeli
d259f37ca3 Hmh, finally EXTRA_DIST was just fine
* tests/Makefile.am: Put EXTRA_DIST back.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2014-11-20 10:53:58 +01:00
Dodji Seketeli
a6422da0a2 Make sure we don't try to build test data
* tests/Makefile.am: Replace EXTRA_DIST with noinst_DATA.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2014-11-19 21:20:27 +01:00
Dodji Seketeli
d09799377a Add loads of forgotten test data files to source distribution
* tests/Makefile.am: Add lots of test data file that were
	forgotten and then revealed by running make distcheck.  Also fix
	some wrong paths to test data files.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2014-11-19 17:31:34 +01:00
Dodji Seketeli
1e55a1245e Make the alt dwarf debug file *not* be a symlink
* tests/data/test-alt-dwarf-file/test0-debug-dir/.build-id/16/7088580c513b439c9ed95fe6a8b29496495f26.debug:
	Make this be a real file, no more a symlink to
	../../../test0-common-dwz.debug.
	* tests/data/test-alt-dwarf-file/test0-report.txt: Now that the
	file above is no more a symlink the message emitted by the test
	changes.  It now says that the file found is the base name of the
	real file.  So change the reference report accordingly.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2014-11-19 16:50:48 +01:00
Dodji Seketeli
1b4e3844e9 Nested automake conditionals don't work
* configure.ac (ENABLE_ZIP_ARCHIVE_AND_CXX11): Define this
	automake condition variable that is true if both the zip archive
	and c++11 features are enabled.  This is important to know if the
	test runtestdot is going to be compiled.  That test needs both
	c++11 and the zip archive features.
	* tests/Makefile.am: Do not nest automake conditional statements.
	It does not work.  Rather, use the new
	ENABLE_ZIP_ARCHIVE_AND_CXX11 condition variable.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2014-11-19 10:23:41 +01:00
Dodji Seketeli
c134ed84c7 If c++11 is disable do not execute the runtestdot test
* tests/Makefile.am: runtestdot should not be executed if c++11 is
	disabled.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2014-11-19 09:17:13 +01:00
Dodji Seketeli
3be48230b7 Sort reported changed declarations & types in a given scope
* src/abg-comparison.cc (struct changed_type_or_decl_comp, struct
	changed_vars_comp): New comparison functors.
	(sort_changed_type_or_decl, sort_changed_vars): New static
	functions.
	(scope_diff::report): Use the above to sort changed declarations,
	and types in a given scope.
	(corpus_diff::report): Likewise for the changed variables.
	* tests/data/test-abidiff/test-struct1-report.txt: Adjust.
	* tests/data/test-diff-suppr/test7-var-suppr-report-0.txt:
	Likewise.
	* tests/data/test-diff-suppr/test7-var-suppr-report-8.txt:
	Likewise.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2014-11-08 11:32:58 +01:00
Dodji Seketeli
0dd5f64279 Sort elf symbols before serializing them
* include/abg-corpus.h (corpus::{get_sorted_fun_symbols,
	get_sorted_var_symbols}): Declare new member functions.
	* src/abg-corpus.cc (corpus_priv::{sorted_var_symbols,
	sorted_fun_symbols}): New data members.
	(struct elf_symbol_comp_functor): Define new comparison functor.
	(corpus::{get_sorted_fun_symbols, get_sorted_var_symbols}): Define
	new member functions.
	* src/abg-writer.cc (write_elf_symbols_table): Take a sorted
	vector of symbols in parameters, rather than an unsorted map.
	(write_corpus_to_native_xml): Write a sorted vector of symbols,
	rather than an unsorted map of symbols.
	* tests/data/test-read-dwarf/test0.abi: Adjust.
	* tests/data/test-read-dwarf/test1.abi: Likewise.
	* tests/data/test-read-dwarf/test2.so.abi: Likewise.
	* tests/data/test-read-dwarf/test3.so.abi: Likewise.
	* tests/data/test-read-dwarf/test6.so.abi: Likewise.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2014-11-08 11:22:43 +01:00
Dodji Seketeli
d3b188f859 Fix template parameter hashing: make it know about enclosing template
* include/abg-ir.h (template_parameter_sptr, template_decl_sptr)
	(template_decl_wptr): Declare new typedefs.
	(class template_decl): Make this virtually inherit decl_base and
	pimpl-ify it.
	(class template_parameter): Pimpl-ify this.  Make the constructor
	take the enclosing template parameter.
	(struct template_decl::hash): Declare this here, rather than in
	src/abg-hash.cc
	(class type_tparameter, non_type_tparameter, template_tparameter)
	(class type_composition, function_tdecl, class_tdecl): Pimpl-ify
	this.
	* src/abg-hash.cc (template_parameter:#️⃣:operator()): Hash the
	enclosing template parameter.  Avoid infinite recursion due to the
	loop hash parameter -> hash template -> hash parameter.
	(template_decl:#️⃣:operator()) Define this here, now that it's
	declared in abg-ir.h.  Also, avoid infinite recursion here; this
	is complementary to what is done in the hashing for
	template_parameter.
	({type_tparameter, template_tparameter, }:#️⃣:operator()):
	Cache the calculated hash just as what is done for other types
	hashed.
	(template_decl::priv): Define this new type.
	(template_decl::{add_template_parameter, get_template_parameters,
	~template_decl}): Define these here to pimpl-ify template_decl.
	(template_parameter::priv): Define this new type.
	(template_parameter::template_parameter): Define this here to
	pimpl-ify template_parameter.  Note also that this now takes the
	enclosing template decl.
	(template_parameter::{get_index, get_enclosing_template_decl,
	get_hashing_has_started, set_hashing_has_started, operator::==}):
	Define these here to pimpl-ify template_parameter.
	(type_tparameter::priv): Define this new type.
	(type_tparameter::type_tparameter): Define this here to pimpl-ify
	type_tparameter.   Also, not that this constructor now takes the
	enclosing template decl.
	(class non_type_tparameter::priv): Define new type.
	(non_type_tparameter::{non_type_tparameter, get_type}): Define
	these here to pimpl-ify non_type_tparameter.  The constructor now
	takes the enclosing template.
	(template_tparameter::priv): Define new type.
	(template_tparameter::template_tparameter): Define this here to
	pimpl-ify template_tparameter.  This constructor now takes the
	enclosing template.
	(class type_composition::priv): New type.
	(type_composition::{type_composition, get_composed_type,
	set_composed_type}): Define these here to pimpl-ify
	type_composition.  The constructor now takes the enclosing
	template decl.
	(class function_tdecl::priv): Define new type.
	(function_tdecl::{function_tdecl, set_pattern, get_pattern,
	get_binding}): Define this here to pimpl-ify function_tdecl.
	(class class_tdecl::priv): Define this new type.
	(class_tdecl::class_tdecl): Define this here to pimpl-ify
	class_tdecl.
	(class_tdecl::set_pattern): Adjust to pimpl-ify.
	(class_tdecl::get_pattern): Define new pimpl-ified getter.
	* src/abg-reader.cc (build_function_tdecl, build_class_tdecl):
	Cleanup.  Pass the enclosing template to the template parameters
	that are built.
	(build_type_tparameter, build_type_composition)
	(build_non_type_tparameter, build_template_tparameter)
	(build_template_parameter): Take the enclosing template
	declaration and pass it to the template parameter being created.
	* tests/data/test-read-write/test12.xml: Fix and Adjust.
	* tests/data/test-read-write/test13.xml: Likewise.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2014-11-07 12:16:34 +01:00
Dodji Seketeli
a206dd881d Pass -std=gnu++11 to the compiler when --enable-cxx11 for tests
* tests/Makefile.am: Pass -std=gnu++11 to the compiler when
	--enable-cxx11 has been used.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2014-11-05 10:53:00 +01:00
Dodji Seketeli
1082520383 Make the use of a C++-11 compiler optional
* configure.ac: Define a new --enable-cxx11 switch to control the
	use of the C++-11 compiler.  Define a WITH_CXX11 C macro and an
	automake ENABLE_CXX11 variable.
	* config.h.in: Initialize the new WITH_CXX11 C macro.
	* src/Makefile.am: Include the files coded in C++-11 only if the
	ENABLE_CXX11 automake variable is defined.
	* tests/Makefile.am: Likewise, build the runtestsvg test program
	only if C++-11 usage is enabled.
	* include/abg-diff-utils.h (class d_path_vec): Remove useless
	usage of the 'typename' keyword.
	* include/abg-fwd.h (is_enum_type): Renamed is_enum into this,
	because of a name clash with a tr1 function when not using C++-11.
	(is_pointer_type): Likewise, renamed is_pointer into this because
	of a name clash with a tr1 function when not using C++-11.
	* src/abg-comp-filter.cc (has_harmless_name_change): Adjust for
	the is_enum -> is_enum_type change.
	* src/abg-comparison.cc (type_suppression::suppresses_diff):
	Likewise.
	(class function_suppression::priv): Add a missing "class" keyword
	in friend declaration.
	(diff_context::diff_has_been_traversed)
	(diff_context::mark_diff_as_traversed): Do not use the C++-11
	specific type uintptr_t.
	* src/abg-dwarf-reader.cc (create_default_dwfl): Do not use
	designated initializers.  Sigh.  This is handy though.
	(expr_result::abs): Cast the argument of std::abs to avoid
	ambiguous call.
	(finish_member_function_reading): Adjust for the is_pointer ->
	is_pointer_type renaming.
	* src/abg-hash.cc (scope_decl:#️⃣:operator)
	(class_decl::base_spec:#️⃣:operator)
	(type_composition:#️⃣:operator): Use std::tr1::hash string,
	rather than the C++-11 specific std::hash function.
	* src/abg-ini.cc (read_sections, write_sections): Make
	std::ifstream constructor take a const char* rather than a string.
	* src/abg-ir.cc (is_enum_type, is_pointer_type): Renamed is_enum
	into is_enum_type and is_pointer into is_pointer_type.
	* src/abg-writer.cc (write_translation_unit): Remove useless
	typename keyword.  Make ofstream take a const char* rather than a
	string.
	(write_namespace_decl): Remove useless typename keyword.
	(write_corpus_to_native_xml_file): Make ofstream take a const
	char* rather than a string.
	* tests/test-abidiff.cc (main): Make ofstream take a const char*
	rather than a string.
	* tests/test-diff-dwarf.cc (main): Likewise.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2014-11-05 10:45:07 +01:00
Dodji Seketeli
2e896ce107 Initial support for variable suppressions
* include/abg-comparison.h (variable_suppression_sptr)
	(variable_suppressions_type): New convenience typedefs.
	(class variable_suppression): Declare new type.
	* src/abg-comparison.cc (is_var_diff): New predicate.
	(read_variable_suppression): Define new static function.
	(class variable_suppression::priv): Define type for the private
	data of the variable_suppression type.
	(variable_suppression::{variable_suppression,
	~variable_suppression, get_name, set_name, get_name_regex_str,
	set_name_regex_str, get_symbol_name, set_symbol_name,
	get_symbol_name_regex_str, set_symbol_name_regex_str,
	get_symbol_version, set_symbol_version,
	get_symbol_version_regex_str, set_symbol_version_regex_str,
	get_type_name, set_type_name, get_type_name_regex_str,
	set_type_name_regex_str, suppresses_diff}): Define new member
	functions for the variable_suppression type.
	* tests/data/test-diff-suppr/libtest7-var-suppr-v0.so: Add new
	test input.
	* tests/data/test-diff-suppr/libtest7-var-suppr-v1.so: Likewise.
	* tests/data/test-diff-suppr/test7-var-suppr-1.suppr: Likewise.
	* tests/data/test-diff-suppr/test7-var-suppr-2.suppr: Likewise.
	* tests/data/test-diff-suppr/test7-var-suppr-3.suppr: Likewise.
	* tests/data/test-diff-suppr/test7-var-suppr-4.suppr: Likewise.
	* tests/data/test-diff-suppr/test7-var-suppr-5.suppr: Likewise.
	* tests/data/test-diff-suppr/test7-var-suppr-6.suppr: Likewise.
	* tests/data/test-diff-suppr/test7-var-suppr-7.suppr: Likewise.
	* tests/data/test-diff-suppr/test7-var-suppr-8.suppr: Likewise.
	* tests/data/test-diff-suppr/test7-var-suppr-report-0.txt: Likewise.
	* tests/data/test-diff-suppr/test7-var-suppr-report-1.txt: Likewise.
	* tests/data/test-diff-suppr/test7-var-suppr-report-2.txt: Likewise.
	* tests/data/test-diff-suppr/test7-var-suppr-report-3.txt: Likewise.
	* tests/data/test-diff-suppr/test7-var-suppr-report-4.txt: Likewise.
	* tests/data/test-diff-suppr/test7-var-suppr-report-5.txt: Likewise.
	* tests/data/test-diff-suppr/test7-var-suppr-report-6.txt: Likewise.
	* tests/data/test-diff-suppr/test7-var-suppr-report-7.txt: Likewise.
	* tests/data/test-diff-suppr/test7-var-suppr-report-8.txt:
	Likewise.
	* tests/data/test-diff-suppr/test7-var-suppr-version-script: Likewise.
	* tests/data/test-diff-suppr/test7-var-suppr-v0.cc: Source code
	for the librairie above.
	* tests/data/test-diff-suppr/test7-var-suppr-v1.cc: Source code
	for the librairie above.
	* tests/Makefile.am: Add the new test input data to the source
	distribution.
	* tests/test-diff-suppr.cc: Update to make this harness to run
	over the new test input above.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2014-11-01 12:22:08 +01:00
Dodji Seketeli
6ebf695323 Spit and polish variables presentation in diff report
* src/abg-comparison.cc (corpus_diff::report): Show the full
	representation of the variable, rather than just its name.  Also,
	show the new representation of the variable only if it has
	changed.
	* tests/data/test-diff-dwarf/test9-report.txt: Adjust test.
	* tests/data/test-diff-filter/test15-0-report.txt: Likewise.
	* tests/data/test-diff-filter/test15-1-report.txt: Likewise.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2014-11-01 12:15:14 +01:00