Commit Graph

112 Commits

Author SHA1 Message Date
Dodji Seketeli
49db3f838c Plug leak of diffs of member variables of class type
On certain work loads, cycles in the tree of diffs of member variables
can appear.  This because:

  1/ each diff tree nodes holds a reference on each of its children
  nodes
  2/ each var_diff tree node holds a reference on the diff tree node
  representing its type changes.

There can thus be reference cycles in involving diff the tree --> child
node relationship and the var_diff tree --> type diff tree
relationship.

This patch fixes the issue be make sure that a diff tree node does not
hold a reference on its children nodes.  That is, rather than having a
vector of shared pointers to its children diff nodes, it has a vector
of naked pointers to those.  The patch goes further by making sure
that a var_diff node does not hold a reference to its type diff node
either.  It holds a weak pointer to the type diff node, rather than a
shared pointer.

The patch should be followed by a patch make sure that all kinds of
diff nodes follow this pattern; that is, if a diff node needs to carry
a sub-type diff node, it should do so by either using a naked pointer
to the sub-type diff node, or a weak pointer.

For now, the patch fixes the leaks reported by running all the tests
of the suite under Valgrind.

	* include/abg-comparison.h (diff_wptr, unordered_diff_sptr_set): New typedefs.
	(struct diff_sptr_hasher): Define new type.
	(diff_context::keep_diff_alive): Declare new member function.
	(diff::children_nodes): Return a vector of diff*, rather than a
	vector of diff_sptr.
	* src/abg-comparison.cc (diff_context::priv::live_diffs_): New
	data member.
	(diff_context::keep_diff_alive): Define new data member.
	(diff::priv::children_): Make this be a vector of diff*, rather
	than a vector of diff_sptr.
	(diff_less_than_functor::operator()): Add a new overload for
	diff*.  Make the existing overload of diff_sptr use the new one.
	(diff::children_nodes): Adjust;
	(diff::append_child_node): Make sure the child node is kept
	alive.  Only add the naked pointer to the child node to the vector
	of children.
	(diff::traverse): Adjust.
	(var_diff::priv::type_diff_): Make this be a weak pointer, rather
	than a shared pointer.
	(var_diff::type_diff): The var_diff::priv::type_diff_ data member
	is now a weak pointer, so make this accessor convert it to a
	shared pointer.
	(corpus_diff::priv::children_): Turn this into a vector of diff*,
	rather than a vector of diff_sptr.
	(corpus_diff::children_nodes): Adjust.
	(corpus_diff::append_child_node): Make sure the child node is kept
	alive.  Only add the naked pointer to the child node to the vector
	of children.
	(category_propagation_visitor::visit_end): Adjust.
	(suppression_categorization_visitor::visit_end): Adjust.
	(redundancy_marking_visitor::{visit_begin, visit_end}): Adjust.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2016-05-22 23:20:13 +02:00
Dodji Seketeli
00f79732fb Plug leak of shared private data of class_diff type
Some time ago, a memory optimization was put in place to reduce the
memory usage of the IR used to represent the result of a comparison
between two corpora.

The principle of that optimization was to share the data of the
class_diff::priv member among instances of class_diff that are in the
same class of equivalence.

In practice, the class_diff::priv member of an instance that has a non
empty class of equivalence was set to the class_diff::priv of its
canonical type.

Because clas_diff::priv is a shared pointer, setting it to the
class_diff::priv of another instance was creating cycles in the graph
of class_diff, sometimes.  And those cycles lead to memory leaks as
the reference count of shared pointers to class_diff would not go down
to zero anymore.

This patch fixes the problem of those cycles by not setting the
class_diff::priv data member.  Rather, when a class_diff is part of a
non-empty class of equivalence, its class_diff::priv is left nil.  A
new class_diff::get_priv() accessor is provided; it returns the shared
class_diff::priv of the canonical type when the current
class_diff::priv is nil; otherwise it just returns the current
class_diff::priv.

	* include/abg-comparison.h (class_diff::get_priv): Declare new
	member function.
	(class_diff::get_priv): Define new member function.
	(class_diff::{chain_into_hierarchy, base_changes, deleted_bases,
	inserted_bases, changed_bases, base_changes, member_types_changes,
	member_types_changes, data_members_changes, inserted_data_members,
	deleted_data_members, member_fns_changes, changed_member_fns,
	member_fns_changes, deleted_member_fns, inserted_member_fns,
	member_fn_tmpls_changes, member_class_tmpls_changes,
	member_class_tmpls_changes, report}): Rather than accessing
	class_diff::priv directly, use the new class_diff::get_priv.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2016-05-22 23:20:13 +02:00
Dodji Seketeli
7cd624a1cd Split suppression engine off of abg-comparison.{cc,h}
Until now, the suppression engine was part of the comparison engine.
The code of both was in the abg-comparison.{cc,h} files.

For the sake of greater modularity, this patch separates the suppression
engine from the comparison engine.  The suppression engine now lives
in include/abg-suppression.h and src/abg-suppression.cc.  The patch
also updates logical consumers of the suppression engine to adapt them
to the change.

	* include/Makefile.am: Add abg-suppression.h to source
	distribution.
	* include/abg-comparison.h: Remove abg-ini.h include directive.
	(suppression_sptr, suppressions_type): Move these typedefs to
	abg-fwd.h.
	(class suppression_base, type_suppression)
	(type_suppression::insertion_range)
	(type_suppression::insertion_range::boundary)
	(type_suppression::insertion_range::integer_boundary)
	(type_suppression::insertion_range::fn_call_expr_boundary)
	(function_suppression, function_suppression::parameter_spec)
	(variable_suppression): Move these type definitions to the new
	abg-suppression.h.
	(read_suppressions, is_type_suppression, is_integer_boundary)
	(is_fn_call_expr_boundary, is_function_suppression)
	(is_variable_suppression, operator&)
	(operator|): Move these function declarations to the new
	abg-suppression.h.
	(type_suppression, type_suppression_sptr, type_suppression_type)
	(function_suppression, function_suppression_sptr)
	(function_suppressions_type, variable_suppression)
	(variable_suppression_sptr, variable_suppressions_type): Move
	these forward declaration and typedefs to the new
	abg-suppression.h.
	(diff_context::suppressions): Adjust return type to
	suppr::suppressions_type&.
	(diff_context::add_suppression): Adjust parameter type to
	suppr::suppressions_sptr.
	(diff_context::add_suppressions): Adjust parameter type
	suppr::suppressions_type&.
	(is_type_diff, is_decl_diff, is_var_diff, is_function_decl_diff)
	(is_pointer_diff, is_reference_diff, is_fn_parm_diff)
	(is_base_diff, is_child_node_of_function_parm_diff)
	(is_child_node_of_base_diff): Declare these new functions.  They
	were previously static, local to abg-comparison.cc only.  Now they
	need to be exported because they are used by the suppression
	engine's code that now lives in its one files.
	* include/abg-fwd.h (suppr::{suppression_base, suppression_sptr,
	suppressions_type}): Forward declare these here.
	* include/abg-suppression.h (class suppression_base)
	(type_suppression, type_suppression::insertion_range)
	(type_suppression::insertion_range::boundary)
	(type_suppression::insertion_range::integer_boundary)
	(type_suppression::insertion_range::fn_call_expr_boundary)
	(function_suppression, function_suppression::parameter_spec)
	(variable_suppression): Move these type definitions here, in the
	namespace suppr.
	(read_suppressions, is_type_suppression, is_integer_boundary)
	(is_fn_call_expr_boundary, is_function_suppression)
	(is_variable_suppression, operator&)
	(operator|): Move these function decalration here, in the
	namespace suppr.
	(type_suppression_sptr, type_suppressions_type)
	(function_suppression_sptr, function_suppressions_type)
	(variable_suppression_sptr, variable_suppressions_type): Move
	these typedefs here, in the namespace suppr.
	* src/Makefile.am: add src/abg-suppression.cc to source
	distribution.
	* src/abg-comparison.cc (is_type_diff, is_decl_diff, is_var_diff)
	(is_function_decl_diff, is_pointer_diff, is_reference_diff)
	(is_reference_or_pointer_diff, is_fn_parm_diff, is_base_diff)
	(is_child_node_of_function_parm_diff, is_child_node_of_base_diff):
	Export these functions.
	(*suppression*): Move all the suppression-related definitions to
	the new abg-suppression.cc.
	* src/abg-suppression.cc: New file. Contains all the *suppression*
	definitions from src/abg-comparison.cc, that are put in the suppr
	namespace.
	* tools/abicompat.cc: Adjust.
	* tools/abidiff.cc: Likewise.
	* tools/abipkgdiff.cc: Likewise.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2016-05-08 12:29:57 +02:00
Dodji Seketeli
e2f777164f Update copyright year on abg-comparison.h
* include/abg-comparison.h: Update copyright year.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2016-05-08 11:14:35 +02:00
Dodji Seketeli
b885e6283f Bug 20015 - support file_name_not_regexp and soname_not_regexp in suppr specs
The supression directives suppress_type, suppress_function and
suppress_variable support the two properties below, among others:

    file_name_regexp = <some-regexp>
    soname_regexp = <some-regexp>

When the regular expression matches either the file name or the
soname, then the suppression directive is activated.

This patch adds the support for these two additional properties for
these suppression directives:

    file_name_not_regexp = <some-regexp>
    soname_not_regexp = <some-regexp>

These activate the current suppression directive if the regular
expression does *NOT* match the file name or soname.

This is very helpful to express change report suppressions like:

    "suppress all ABI change reports for all libraries but those with
    file names (or sonames) with the pattern libfoobar.*"

	* include/abg-comparison.h
	(suppression_base::{get,set}_file_name_not_regex_str): Declare new
	member functions.
	(suppression_base::{get,set}_soname_not_regex_str): Likewise.
	(suppression_base::{names,sonames}_of_binaries_match): Likewise.
	* src/abg-comparison.cc
	(suppression_base::priv::get_file_name_regex): Fix comment.
	(suppression_base::priv::get_file_name_not_regex): New member
	function.
	(suppression_base::priv::get_soname_regex): Fix comment.
	(suppression_base::priv::get_soname_not_regex): New member
	function.
	(suppression_base::{get,set}_file_name_not_regex_str): Define new
	member functions.
	(suppression_base::{get,set}_soname_not_regex_str): Likewise.
	(suppression_base::{names,sonames}_of_binaries_match): Likewise.
	These got factorized out of type_suppression::suppresses_type,
	function_suppression::suppresses_function,
	function_suppression::suppresses_function_symbol,
	variable_suppression::suppresses_variable,
	variable_suppression::suppresses_variable_symbol.
	(type_suppression::suppresses_type): Use the new
	suppression_base::{names,sonames}_of_binaries_match.
	(read_type_suppression): Read the new file_name_not_regexp and
	soname_not_regexp properties.
	(function_suppression::{suppresses_function,
	suppresses_function_symbol}): Use the new
	suppression_base::{names,sonames}_of_binaries_match.
	(read_function_suppression): Read the new file_name_not_regexp and
	soname_not_regexp properties.
	(variable_suppression::{suppresses_variable,
	variable_suppression::suppresses_variable_symbol}): Use the new
	suppression_base::{names,sonames}_of_binaries_match.
	(read_variable_suppression): Use the new
	suppression_base::{names,sonames}_of_binaries_match.
	* doc/manuals/libabigail-concepts.rst: Document the new
	file_name_not_regexp and soname_not_regexp suppression properties.
	* tests/data/test-diff-suppr/test24-soname-report-10.txt: New test
	reference output.
	* tests/data/test-diff-suppr/test24-soname-report-11.txt: Likewise.
	* tests/data/test-diff-suppr/test24-soname-report-12.txt: Likewise.
	* tests/data/test-diff-suppr/test24-soname-report-13.txt: Likewise.
	* tests/data/test-diff-suppr/test24-soname-report-14.txt: Likewise.
	* tests/data/test-diff-suppr/test24-soname-report-15.txt: Likewise.
	* tests/data/test-diff-suppr/test24-soname-report-16.txt: Likewise.
	* tests/data/test-diff-suppr/test24-soname-report-9.txt: Likewise.
	* tests/data/test-diff-suppr/test24-soname-suppr-10.txt: New test input.
	* tests/data/test-diff-suppr/test24-soname-suppr-11.txt: Likewise.
	* tests/data/test-diff-suppr/test24-soname-suppr-12.txt: Likewise.
	* tests/data/test-diff-suppr/test24-soname-suppr-13.txt: Likewise.
	* tests/data/test-diff-suppr/test24-soname-suppr-14.txt: Likewise.
	* tests/data/test-diff-suppr/test24-soname-suppr-15.txt: Likewise.
	* tests/data/test-diff-suppr/test24-soname-suppr-16.txt: Likewise.
	* tests/data/test-diff-suppr/test24-soname-suppr-9.txt: Likewise.
	* tests/data/test-diff-suppr/test29-soname-report-2.txt: New test
	reference output.
	* tests/data/test-diff-suppr/test29-soname-report-3.txt: Likewise.
	* tests/data/test-diff-suppr/test29-soname-report-4.txt: Likewise.
	* tests/data/test-diff-suppr/test29-soname-report-5.txt: Likewise.
	* tests/data/test-diff-suppr/test29-soname-report-6.txt: Likewise.
	* tests/data/test-diff-suppr/test29-soname-report-7.txt: Likewise.
	* tests/data/test-diff-suppr/test29-soname-report-8.txt: Likewise.
	* tests/data/test-diff-suppr/test29-suppr-2.txt: New test input.
	* tests/data/test-diff-suppr/test29-suppr-3.txt: Likewise.
	* tests/data/test-diff-suppr/test29-suppr-4.txt: Likewise.
	* tests/data/test-diff-suppr/test29-suppr-5.txt: Likewise.
	* tests/data/test-diff-suppr/test29-suppr-6.txt: Likewise.
	* tests/data/test-diff-suppr/test29-suppr-7.txt: Likewise.
	* tests/data/test-diff-suppr/test29-suppr-8.txt: Likewise.
	* tests/data/Makefile.am: Add the new test material to source
	distribution.
	* tests/test-diff-suppr.cc (in_out_specs): Make this test harness
	run over the new test inputs.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2016-04-27 23:58:50 +02:00
Dodji Seketeli
4b7e295b20 Bug 19596 - Incorrect exit status for incompatible ABI change
The comparison engine doesn't take virtual offset changes into account
when deciding if a diff node carries an incompatible change.  This is
obviously an oversight.

Fixed thus.

	* include/abg-comparison.h (enum diff_category): Adjust the
	comment for enumerator VIRTUAL_MEMBER_CHANGE_CATEGORY; changes of
	this category are incompatible ABI changes.
	(corpus_diff::diff_stats::num_func_with_virtual_offset_changes):
	Declare new accessors.
	* src/abg-comparison.cc
	(corpus_diff::diff_stats::priv::num_func_with_virt_offset_changes):
	New data member.
	(corpus_diff::diff_stats::priv::priv): Initialize the new data
	member.
	(corpus_diff::diff_stats::num_func_with_virtual_offset_changes):
	Define new accessors.
	(corpus_diff::priv::apply_filters_and_compute_diff_stats): Use the
	new accessor to set the number of functions with virtual offset
	changes onto the stats data structure.
	(corpus_diff::has_incompatible_changes): Take functions with
	virtual offset changes into account.
 	* tests/test-abidiff-exit.cc: New test harness to test for exit
	codes of abidiff.
	* tests/Makefile.am: Build the new test harness runtestabidiff
	from the test-abidiff-exit.cc source file.
	* tests/data/test-abidiff-exit/test1-voffset-change-report0.txt:
	New reference test output.
	* tests/data/test-abidiff-exit/test1-voffset-change-v0.cc: New
	test input source code.
	* tests/data/test-abidiff-exit/test1-voffset-change-v0.o: New test input.
	* tests/data/test-abidiff-exit/test1-voffset-change-v1.cc: New
	test input source code.
	* tests/data/test-abidiff-exit/test1-voffset-change-v1.o: New test input.
	* tests/data/Makefile.am: tests/data/Makefile.am: Add the new test
	inputs above to the source distribution.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2016-02-10 21:31:53 +01:00
Ondrej Oprala
6a7566d513 Add the option of printing the file, line and column information about a type being reported.
* bash-completion/abicompat: Complete the new "--no-show-locs" option.
	* bash-completion/abidiff: Likewise.
	* bash-completion/abidw: Likewise.
	* bash-completion/abipkgdiff: Likewise.
	* doc/manuals/abicompat.rst: Mention the new "--no-show-locs" option.
	* doc/manuals/abidiff.rst: Likewise.
	* doc/manuals/abidw.rst: Likewise.
	* doc/manuals/abipkgdiff.rst: Likewise.
	* include/abg-comparison.h (show_locs): Add declarations.
	* src/abg-comparison.cc: (diff_context::priv): Add a new switch
	called "show_locs_" and set its default value to false.
	(report_loc_info): New function. Outputting the extra information
	is conditionalized based on the associated diff contexts settings.
	(show_locs): define a getter/setter for
	diff_context::priv::show_locs_.
	({distinct,pointer,reference,qualified_type,enum,class,scope,fn_parm,
	typedef,corpus}_diff::report): Call report_loc_info when
	appropriate.
	(maybe_report_diff_for_member): Likewise.
	(represent): Accept a const reference to a diff_context_sptr as a first
	argument and call report_loc_info on its second argument.
	* src/abg-dwarf-reader.cc:
	* tests/data/Makefile.am: Add the new test reference files.
	* tests/data/test-abicompat/test0-fn-changed-report-2.txt: New test
	reference output.
	* tests/data/test-abicompat/test5-fn-changed-report-1.txt: Likewise.
	* tests/data/test-abicompat/test6-var-changed-report-1.txt: Likewise.
	* tests/data/test-abicompat/test7-fn-changed-report-2.txt: Likewise.
	* tests/data/test-diff-filter/test30-pr18904-rvalueref-report1.txt:
	Likewise.
	* tests/data/test-diff-filter/test31-pr18535-libstdc++-report-1.txt:
	Likewise.
	* tests/data/test-diff-pkg/dirpkg-3-report-2.txt: Likewise.
	* tests/data/test-diff-suppr/test6-fn-suppr-report-0-1.txt: Likewise.
	* tests/test-abidiff.cc: Explicitly create a diff context and turn off
	location emitting.
	* tests/test-diff-dwarf.cc: Likewise.
	* tests/test-abicompat.cc: Add --no-show-locs to all existing test
	arguments. Run a few of the existing tests again, but without this
	option.
	* tests/test-diff-filter.cc: Likewise.
	* tests/test-diff-pkg.cc: Likewise.
	* tests/test-diff-suppr.cc: Likewise.
	* tools/abicompat.cc: Handle the new "--no-show-locs" option.
	* tools/abidiff.cc: Likewise.
	* tools/abidw.cc: Likewise.
	* tools/abipkgdiff.cc: Likewise.

Signed-off-by: Ondrej Oprala <ooprala@redhat.com>
2015-12-15 12:32:55 +01:00
Ondrej Oprala
9cb146a013 Bug 17340 - Support pointers and references to functions
* include/abg-comparison.h (compute_diff_for_distinct_kinds): Take the
	first two arguments of type const type_or_decl_base_sptr instead.
	* include/abg-ir.h (translation_unit::get_function_types): Declare new
	method.
	(function_types): Declare new typedef.
	* src/abg-comparison.cc (compute_diff_for_types): Take the first two
	arguments of type const type_or_decl_base_sptr instead of a const
	decl_base_sptr.
	(try_to_diff): Likewise.
	(try_to_diff<class_decl>): Likewise.
	(try_to_diff_distinct_kinds): Likewise.
	(compute_diff_for_distinct_kinds): Likewise. Also remove a variant
	accepting arguments of type const type_base_sptr.
	* src/abg-dwarf-reader.cc (build_class_type_and_add_to_ir): Skip
	building a pointer if it points to the beginning of a vptr.
	(build_pointer_type_def): Declare utype_decl of type
	type_or_decl_base_sptr and adjust assignments to it accordingly.
	(build_function_type): New function definition.
	(build_function_decl): Call build_function_type instead of building
	an ftype manually.
	(build_ir_node_from_die): Amend case DW_TAG_subroutine_type with
	appropriate calls to build a function type.
	* src/abg-ir.cc (translation_unit::get_function_types): New method
	definition.
	({pointer,reference}_type_def::pointer_type_def): Expect that
	pointed_to might not have an accompanying declaration and set a type's
	name in this case as well.
	({pointer,reference}_type_def::get_qualified_name): Generate a
	qualified name even if the pointed-to type has no declaration.
	* src/abg-reader.cc (build_function_type): New function definition.
	(handle_element_node): Return a type_or_decl_base_sptr instead and
	try calling handle_function_type in addition to others.
	(handle_function_type): New function definition that calls
	build_function_type.
	(build_type): Try calling build_function_type as well.
	* src/abg-writer.cc (fn_shared_ptr_map): Declare new typedef.
	(write_context::{clear_referenced_fntypes_map,fntype_is_referenced,
	record_fntype_as_referenced}): New member functions.
	(write_translation_unit): Call the new clear_referenced_fntypes_map.
	* tests/data/Makefile.am: Add the new test material to the build
        system.
	(write_translation_unit): Separately write function types that have
	been recorded to emit by write_{pointer,reference}_type_def.
	(write_{pointer,reference}_type_def): Record the type pointed to as
	a type to be emitted if type == function type.
	(write_function_type): Write the details of a function type in the
	abixml format and unmark the type.
	* tests/data/test-diff-dwarf/test32-fnptr-changes-report-0.txt: New
	test reference report.
	* tests/data/test-diff-dwarf/test32-fnptr-changes-v{0,1}.cc: New test
	source files.
	* tests/data/test-diff-dwarf/test32-fnptr-changes-v{0,1}.o: New binary
	test inputs.
	* tests/data/test-diff-dwarf/test33-fnref-changes-report-0.txt: New
	test reference report.
	* tests/data/test-diff-dwarf/test33-fnref-changes-v{0,1}.cc: New test
	source files.
	* tests/data/test-diff-dwarf/test33-fnref-changes-v{0,1}.o: New binary
	test inputs.
	* tests/data/test-diff-filter/test30-pr18904-rvalueref-report0.txt:
	Adjust.
	* tests/data/test-diff-filter/test31-pr18535-libstdc++-report-0.txt:
	Likewise.
	* tests/data/test-read-dwarf/test10-pr18818-gcc.so.abi: Likewise.
	* tests/data/test-read-dwarf/test11-pr18828.so.abi: Likewise.
	* tests/data/test-read-dwarf/test12-pr18844.so.abi: Likewise.
	* tests/data/test-read-dwarf/test13-pr18894.so.abi: Likewise.
	* tests/data/test-read-dwarf/test14-pr18893.so.abi: Likewise.
	* tests/data/test-read-dwarf/test15-pr18892.so.abi: Likewise.
	* tests/data/test-read-dwarf/test16-pr18904.so.abi: Likewise.
	* tests/data/test-read-dwarf/test9-pr18818-clang.so.abi: Likewise.
	* tests/data/test-read-write/test27.xml: New test source file.
	* tests/test-diff-dwarf.cc: Adjust to launch the new tests.
	* tests/test-read-write.cc: Likewise.

Signed-off-by: Ondrej Oprala <ooprala@redhat.com>
2015-09-30 21:20:42 +02:00
Dodji Seketeli
16299395d7 Support source_location_not_in and source_location_not_regexp suppressions
This patch adds support for properties source_location_not_in and
source_location_not_regexp in the [suppress_type] section of
suppression specifications.  So the suppression specification:

  [suppress_type]
    source_location_not_in = foo1.h, foo2.h bar1.h bar2.h

suppresses ABI change reports about types that are *NOT* defined in
files foo{1,2}.h and bar{1,2}.h.  The intended use of this construct is to
constrain abi change reports to types that are part of the API of a
given shared library.  The API of the library is supposed to be
defined in foo.h and bar.h only.

Similarly, the suppression specification:

  [suppress_type]
    source_location_not_regexp = (foo|bar){1,2}\\.h

suppresses ABI change reports about types that are not defined in the
same set of files foo1.h, foo2.h, bar1.h and bar2.h.

	* include/abg-ini.h (enum property_value::value_kind): Add a
	LIST_PROPERTY_VALUE kind.
	(class {list_property_value, list_property}): Declare new types.
	(is_list_property, is_list_property_value): Declare new functions.
	* src/abg-ini.cc (struct list_property_value::priv): Define new
	type.
	(list_property_value::{list_property_value, get_content,
	set_content, as_string}): Define new member functions.
	(is_list_property_value): Define new function.
	(struct list_property::priv): Define new type.
	(list_property::{list_property, get_value, set_value,
	handle_escape}): Define new member functions.
	(is_list_property): Define new function.
	(read_context::buf_): New data member.
	(read_context::{peek, get, put_back, good, eof, read_string,
	read_list_property_value}): New member functions.
	(read_context::read_next_char): Use the new read_context::{get,
	good, eof} member function, rather than using the input stream
	directly.
	(read_context::{skip_white_spaces, skip_comments,
	skip_white_spaces_or_comments, read_property_name,
	read_function_name, read_function_argument,
	read_function_call_expr, read_property_value,
	read_tuple_property_value, read_section_name, read_section}):
	Adjust to use the new member functions of read_context rather than
	using the input stream directly.
	(read_context::read_string_property_value): Likewise.  Use the new
	read_context::read_string() method.
	(read_context::{read, write}_property): Support reading list_property.
	* include/abg-comparison.h
	(type_suppression::{get_source_locations_to_keep,
	set_source_locations_to_keep,
	set_source_location_to_keep_regex_str,
	get_source_location_to_keep_regex_str}): Add new member functions.
	* src/abg-comparison.cc
	(type_suppression::priv::{source_location_to_keep_,
	source_location_to_keep_regex_str_,
	source_location_to_keep_regex_}): Add new data members.
	(type_suppression::priv::{g,s}et_source_location_to_keep_regex):
	Define new member functions.
	(type_suppression::{g,s}et_source_locations_to_keep): Define new
	member functions.
	(type_suppression::{g,s}et_source_location_to_keep_regex_str):
	Likewise.
	(type_suppression::suppresses_type): Support
	"source_location_not_regexp" and "source_location_not_in"
	properties of suppression specifications.
	(read_type_suppression): Likewise. Also adjust to the fact that
	ta tuple property value that is a list of strings is not a list
	property value.
	* doc/manuals/libabigail-concepts.rst: Add documentation for
	source_location_not_in and source_location_not_regexp.
	* tests/data/test-diff-suppr/libtest26-loc-suppr-v{0,1}.so: New
	binary test inputs.
	* tests/data/test-diff-suppr/test26-loc-suppr-{0,1,2}.suppr: New
	suppression specification test inputs.
	* tests/data/test-diff-suppr/test26-loc-suppr-report-{0,1,2,3}.txt:
	New test reference reports.
	* tests/data/test-diff-suppr/test26-loc-suppr-v{0,1}.cc: Source
	code of the test binary input above.
	* tests/data/test-diff-suppr/test26-loc-suppr.h: Likewise.
	* tests/data/Makefile.am: Add the new test material to source
	distribution.
	* tests/test-diff-suppr.cc (in_out_specs): Add the new test inputs above.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2015-09-16 20:54:40 +02:00
Dodji Seketeli
465b25e0d8 Update diff stats when added symbols are removed from change report
Until now, when added symbols were removed from the diff output, the
diff stat was not properly updated.  This patch fixes that.

	* include/abg-comparison.h (diff_context_wptr)
	(corpus_diff::diff_stats_sptr): New typedefs.
	(corpus_diff::diff_stats::diff_stats): Make this constructor take
	a diff_context_sptr.  Make the default constructor private.
	* src/abg-comparison.cc (corpus_diff::diff_stats::priv::ctxt_):
	New data member.  This is a weak pointer to a diff_context.
	(corpus_diff::diff_stats::priv::priv): Take a diff_context_sptr
	and initialize the weak pointer ctxt_ to it.
	(corpus_diff::diff_stats::priv::ctxt): New accessor to the
	diff_context hold by the diff_stats.
	(corpus_diff::diff_stats::{num_removed_func_filtered_out,
	num_added_func_filtered_out, num_removed_vars_filtered_out,
	num_added_vars_filtered_out, num_removed_func_syms_filtered_out,
	num_added_func_syms_filtered_out,
	num_removed_var_syms_filtered_out,
	num_added_var_syms_filtered_out}): If the user asked for the added
	[or removed] variables/functions/symbols to be ignored, the
	accessors for the number of filtered added/removed variables/functions/symbols
	return the total number of added/removed
	variables/functions/symbols; that is, say that *all* added/removed
	variables/functions/symbols got filtered out.
	(corpus_diff::priv::diff_stats_): Turn this data member into a
	[shared] pointer to diff_stats.
	(corpus_diff::priv::filters_and_suppr_applied_): Remove this data
	member.  Now that diff_stats_ is a pointer, we don't need this
	boolean anymore.
	(corpus_diff::apply_filters_and_suppressions_before_reporting):
	Adjust to the fact that filters_and_suppr_applied_ is gone, and
	that diff_stats_ is now a pointer.
	(corpus_diff::report): Control un-referenced added symbols
	reporting with
	diff_context::show_added_symbols_unreferenced_by_debug_info()

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2015-08-06 15:15:41 +02:00
Dodji Seketeli
a746f4afee Make applying supp specs through pointer access look through typedefs
Consider the declaration of the exported function bar() below:

    struct _OpaqueType {int member;};

    typedef struct _OpaqueType Type;

    void bar(Type*);

Once the *definition of struct _OpaqueType and bar() are compiled into
a shared library, if a layout change happens to struct _OpaqueType,
then abidiff rightfully reports that bar() is impacted by the layout
change to struct _OpaqueType.

But then, the following suppression specification won't silence the
ABI change report:

    [suppress_type]
      name = _OpaqueType
      type_kind = struct
      accessed_through = pointer

This is because strictly speaking, it's not struct _OpaqueType that is
accessed through a pointer, from function bar(); it's the type 'Type',
(which is a typedef of struct _OpaqueType) that is accessed though a
pointer.

But then, as 'Type' and 'struct _OpaqueType' are the same type (modulo
the typedef), this behaviour is not super useful.  It would be more
interesting if the suppression specification could silence the ABI
change report.

And this is what this patch does.

	* include/abg-comparison.h (type_suppression::suppresses_type):
	Declare new member function.
	(get_typedef_diff_underlying_type_diff): Declare new function.
	* include/abg-fwd.h (get_typedef_underlying_type): Likewise.
	* src/abg-comparison.cc (type_suppression::suppresses_type):
	Define new member function.
	(get_typedef_diff_underlying_type_diff): Define new function.
	(type_suppression::suppresses_diff): After looking through the
	different kind of access methods, use the new
	type_suppression::suppresses_type(), rather than doing lots of
	stuff ourselves here.  But then, if the suppression doesn't apply
	to the subjects of the diff, look through typedefs and try to
	apply the suppression again.
	* src/abg-ir.cc (get_typedef_underlying_type): Define new
	function.
	* tests/data/test-diff-suppr/libtest25-typedef-v{0,1}.so: New
	binary test input files.
	* tests/data/test-diff-suppr/test25-typedef-v{0,1}.c: Source code
	for the binary test input files above.
	* tests/data/test-diff-suppr/test25-typedef-report-{0, 1}.txt: New test
	input files.
	* tests/data/test-diff-suppr/test25-typedef-suppr-0.txt: New test
	input file.
	* tests/data/Makefile.am: Add the new test material to the source
	distribution.
	* tests/test-diff-suppr.cc (in_out_specs): Add the test inputs
	above to the set of test inputs this harness has to run over.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2015-08-01 14:34:46 +02:00
Dodji Seketeli
915bf047fb Add a new corpus_diff::has_net_changes() entry point
This entry point is to test if there are still ABI changes between two
corpora after applying suppression specifications.

	* include/abg-comparison.h (corpus_diff::has_net_changes): Declare
	new member function.
	* src/abg-comparison.cc (corpus_diff::has_net_changes): Define it.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2015-07-21 12:48:19 +02:00
Dodji Seketeli
f3ed9dfa92 Support file_name_regexp and soname_regexp in supp-specs
With this patch it's now possible to express the soname or name of the binary
file that contains the ABI artifacts the suppression specifications
should apply to.

	* include/abg-comparison.h (suppression_base::priv_): Make this
	pimpl member protected.
	(suppression_base::set_file_name_regex_str)
	(get_file_name_regex_str, get_soname_regex_str)
	(set_soname_regex_str): Declare new accessors.
	(function_suppression::{suppresses_function,
	suppresses_function_symbol}): Take a diff_context_sptr.
	(variable_suppression::{suppresses_variable,
	suppresses_variable_symbol}): Take a diff_context_sptr.
	* src/abg-comparison.cc
	(suppression_base::priv::{file_name_regex_str_, file_name_regex_,
	soname_regex_str_, soname_regex_}): Define new data members.
	(suppression_base::priv::get_file_name_regex_str)
	(get_soname_regex_str): Define new member functions.
	(suppression_base::set_file_name_regex_str)
	(get_file_name_regex_str, get_soname_regex_str)
	(set_soname_regex_str): Define new accessors.
	(type_suppression::suppresses_diff): Evaluate file_name_regexp and
	soname_regexp.
	(read_type_suppression): Fix the reading of the "label" property.
	Read the file_name_regexp and soname_regexp properties.
	(function_suppression::{suppresses_function,
	suppresses_function_symbol): Take a diff_context_sptr parameter.
	Evaluate file_name_regexp and soname_regexp properties.
	(function_suppression::suppresses_diff): Adjust for the api change
	of function_suppression::suppresses_function().
	(read_function_suppression): Read the file_name_regexp and
	soname_regexp properties.
	(variable_suppression::suppresses_variable): Take a
	diff_context_sptr parameter and evaluate file_name_regexp and
	soname_regexp properties.
	(variable_suppression::suppresses_variable_symbol): Likewise.
	(variable_suppression::suppresses_diff): Adjust for the api change
	of variable_suppression::suppresses_variable().
	(read_variable_suppression): Read the file_name_regexp and
	soname_regexp properties.
	(function_is_suppressed, variable_is_suppressed): Take a
	diff_context_sptr parameter.
	(corpus_diff::priv::apply_suppressions_to_added_removed_fns_vars):
	Adjust.
	* doc/manuals/libabigail-concepts.rst: Document file_name_regexp
	and soname_regexp in the manual.
	* tests/data/test-diff-suppr/libtest24-soname-v{0,1}.so: New test
	binary input files.
	* tests/data/test-diff-suppr/test24-soname-report-{0,4}.txt: New
	test input files.
	* tests/data/test-diff-suppr/test24-soname-suppr-{0,4}.txt:
	Likewise.
	* tests/data/test-diff-suppr/test24-soname-v{0,1}.cc: Source code
	of the binary test input files above.
	* tests/data/Makefile.am: Add the new test material above to
	source distribution.
	* tests/test-diff-suppr.cc (in_out_spec): Add the new test inputs
	to the set of tests this harness has to run over.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2015-07-19 19:48:51 +02:00
Dodji Seketeli
a2601a596a Factorize incompatible and subtype changes detection
In abg-comparison.h, there is no function to test if a given
corpus_diff carries incompatible or subtype (after having applied
suppression specifications) ABI changes.  So this patch factorizes the
code of abidiff.cc to provide these features to corpus_diff.

	* include/abg-comparison.h (corpus_diff::{has_incompatible_changes,
	has_net_subtype_changes}): Declare new member functions.
	* src/abg-comparison.cc (corpus_diff::{has_incompatible_changes,
	has_net_subtype_changes}): Define them.
	* abidiff.cc (main): Use the new member functions above.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2015-07-09 11:10:24 +02:00
Dodji Seketeli
fe9fa7a05f Support filtering out just one alias of a function
Suppose a function private_foo() has a symbol private_foo and also a
another one (an alias) named public_foo.  Then suppose we want to
filter out sub-type changes to private_foo().  But then we still want
to see changes to public_foo.

This patch does add this feature.  The [suppress_function] directive
now has a new (hidden) boolean 'allow_other_aliases' property.  When
set to 'yes' or 'true', if the function being looked at has an alias
symbol that does *NOT* match the other properties of the directive,
then the directive doesn't suppress reports for the function.  This
new  property is set to yes by default.

This means that when a function has got multiple aliases, to suppress
the function, one needs to write a regular expression that matches the
names of aliases.  Otherwise the function will not be suppressed.

	* include/abg-comparison.h (function_suppression::{get,
	set}_allow_other_aliases): Declare new member functions.
	* src/abg-comparison.cc
	(function_suppression::priv::allow_other_aliases_): New data
	member.
	(function_suppression::priv::priv): Initialize it to 'true'.
	(function_suppression::{get, set}_allow_other_aliases): Define new
	member functions.
	(read_function_suppression): Parse the new "allow_other_aliases"
	property.
	(function_suppression::suppresses_function): Update to evaluate
	the new 'allow_other_aliases' property when there is a property to
	match against some a symbol name of the function.
	(corpus_diff::report): Fix the printing of function aliases when
	printing sub-type changes to properly emit the plural of the word
	'symbol' when the function has several aliases.
	* include/abg-ir.h (elf_symbol::get_number_of_aliases): Declare
	new member function.
	* src/abg-ir.cc (elf_symbol::get_number_of_aliases): Define new
	member function.
	* doc/manuals/libabigail-concepts.rst: Update manual.
	* tests/data/test-diff-dwarf/test5-report.txt: Adjust.
	* tests/data/test-diff-suppr/libtest23-alias-filter-v0.so: New
	test input.
	* tests/data/test-diff-suppr/libtest23-alias-filter-v1.so: Likewise.
	* tests/data/test-diff-suppr/test23-alias-filter-0.suppr: Likewise.
	* tests/data/test-diff-suppr/test23-alias-filter-1.suppr: Likewise.
	* tests/data/test-diff-suppr/test23-alias-filter-2.suppr: Likewise.
	* tests/data/test-diff-suppr/test23-alias-filter-3.suppr: Likewise.
	* tests/data/test-diff-suppr/test23-alias-filter-4.suppr: Likewise.
	* tests/data/test-diff-suppr/test23-alias-filter-report-0.txt: Likewise.
	* tests/data/test-diff-suppr/test23-alias-filter-report-1.txt: Likewise.
	* tests/data/test-diff-suppr/test23-alias-filter-report-2.txt: Likewise.
	* tests/data/test-diff-suppr/test23-alias-filter-report-3.txt: Likewise.
	* tests/data/test-diff-suppr/test23-alias-filter-report-4.txt: Likewise.
	* tests/data/test-diff-suppr/test23-alias-filter-report-5.txt: Likewise.
	* tests/data/test-diff-suppr/test23-alias-filter-v0.c: Likewise.
	* tests/data/test-diff-suppr/test23-alias-filter-v1.c: Likewise.
	* tests/data/test-diff-suppr/test23-alias-filter-version-script: Likewise.
	* tests/data/Makefile.am: Add the new test stuff to source
	distribution.
	* tests/test-diff-suppr.cc (in_out_spec): Add the tests inputs
	above to the list of input to run over.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2015-07-02 17:15:35 +02:00
Dodji Seketeli
79383f937c Apply suppression specifications to added and removed functions and variables
Until now, specifications for suppressing change reports were applied
only to functions and variables that have sub-type changes.  Change
reports about function and variables that were added or removed could
not be suppressed.

This patch makes suppression specifications to apply to added and
removed functions and variables too.  They can also apply to function
and variable symbols that are not referenced by any debug info.

The patch also fixes some typo and formatting glitches and updates
some existing tests accordingly.

	* include/abg-comparison.h (is_type_suppression)
	(is_function_suppression): Declare new functions.
	({function, variable}_suppression::change_kind): Declare new enum.
	(function_suppression::{parse_change_kind, get_change_kind,
	set_change_kind, suppresses_function,
	suppresses_function_symbol}): Declare new member functions.
	(variable_suppression::{parse_change_kind, get_change_kind,
	set_change_kind, suppresses_variable, suppresses_variable,
	suppresses_variable_symbol}): Declare new member functions.
	(operator{&,|}): Declare new operators for
	function_suppression::change_kind and
	variable_suppression::change_kind enums.
	(corpus_diff::diff_stats::{num_removed_func_filtered_out,
	net_num_func_removed, num_added_func_filtered_out,
	net_num_func_added, num_removed_vars_filtered_out,
	net_num_vars_removed, num_added_vars_filtered_out,
	net_num_vars_added, num_removed_func_syms_filtered_out,
	num_added_func_syms_filtered_out, net_num_removed_func_syms,
	net_num_added_func_syms, num_added_var_syms_filtered_out,
	num_removed_vars_filtered_out, net_num_removed_var_syms,
	net_num_added_var_syms}): Declare new member functions.
	(corpus_diff::diff_stats::num_changed_vars_filtered_out): Renamed
	corpus_diff::diff_stats::num_vars_filtered_out into this.
	(corpus_diff::diff_stats::num_changed_func_filtered_out): Renamed
	corpus_diff::diff_stats::num_func_filtered_out into this.
	* src/abg-comparison.cc (is_type_suppression)
	(is_function_suppression): Define new
	function.
	(function_suppression::priv::change_kind): New data member.
	(function_suppression::priv): Initialize it.
	(function_suppression::{parse_change_kind, get_change_kind,
	set_change_kind, suppresses_function,
	suppresses_function_symbol}): Define new member functions.
	(operator{&,|}): Define new operators for the new
	function_suppression::change_kind enum.
	(function_suppression::suppresses_diff): Re-write this in terms of
	the new function_suppression::suppresses_function() function.
	(read_function_suppression): Support reading the new "change_kind"
	property.
	(variable_suppression::priv::change_kind_): New data member.
	(variable_suppression::priv::priv): Initialize it.
	(variable_suppression::{parse_change_kind, get_change_kind,
	set_change_kind, suppresses_variable,
	suppresses_variable_symbol}): Define new member functions.
	(is_variable_suppression): Define new function.
	(operator{&,|}): Define new operators for
	variable_suppression::change_kind enum.
	(variable_suppression::suppresses_diff): Re-write in terms of the
	new variable_suppression::suppresses_variable function.
	(read_variable_suppression): Support reading the new "change_kind"
	property.
	(corpus_diff::diff_stats::priv::{num_removed_func_filtered_out,
	num_added_func_filtered_out, num_removed_vars_filtered_out,
	num_added_vars_filtered_out, num_removed_func_syms_filtered_out,
	num_added_func_syms_filtered_out,
	num_removed_var_syms_filtered_out,
	num_added_var_syms_filtered_out}): New data members.
	(corpus_diff::diff_stats::priv::num_changed_func_filtered_out):
	Renamed the data member num_func_filtered_out into this.
	(corpus_diff::diff_stats::priv::num_changed_vars_filtered_out):
	Renamed data member num_vars_filtered_out into this.
	(corpus_diff::diff_stats::priv::priv): Initialize the new data
	members.
	(corpus_diff::diff_stats::{num_removed_func_filtered_out,
	num_removed_func_filtered_out, net_num_func_removed,
	net_num_func_added, num_added_func_filtered_out,
	net_num_func_added, num_removed_vars_filtered_out,
	num_removed_vars_filtered_out, net_num_vars_removed,
	num_added_vars_filtered_out, net_num_vars_added,
	num_removed_func_syms_filtered_out,
	num_added_func_syms_filtered_out, net_num_removed_func_syms,
	net_num_added_func_syms, num_added_var_syms_filtered_out,
	num_removed_vars_filtered_out, net_num_removed_var_syms,
	net_num_added_var_syms}): Define new member functions.
	(corpus_diff::diff_stats::num_changed_func_filtered_out): Renamed
	corpus_diff::diff_stats::num_func_filtered_out into this.
	(corpus_diff::diff_stats::num_changed_vars_filtered_out): Renamed
	corpus_diff::diff_stats::num_vars_filtered_out into this.
	(corpus_diff::diff_stats::{net_num_func_changed,
	net_num_vars_changed}): Adjust.
	(corpus_diff::priv::{suppressed_deleted_fns_,
	suppressed_added_fns_, suppressed_deleted_vars_,
	suppressed_added_vars_, suppressed_added_unrefed_fn_syms_,
	suppressed_deleted_unrefed_fn_syms_,
	suppressed_added_unrefed_var_syms_,
	suppressed_deleted_unrefed_fn_syms_}): New data members.
	(corpus_diff::priv::{apply_suppressions_to_added_removed_fns_vars,
	deleted_function_is_suppressed, added_function_is_suppressed,
	deleted_variable_is_suppressed, added_variable_is_suppressed,
	added_unrefed_fn_sym_is_suppressed,
	deleted_unrefed_fn_sym_is_suppressed,
	added_unrefed_var_sym_is_suppressed,
	deleted_unrefed_var_sym_is_suppressed}): Define member functions.
	(function_is_suppressed, variable_is_suppressed): Define new
	functions.
	(corpus_diff::priv::apply_filters_and_compute_diff_stats): Compute
	stats for filtered added or removed functions, variables and their
	symbols.
	(corpus_diff::priv::emit_diff_stats): Emit diff stats for filtered
	added or removed functions, variables and symbols.
	(corpus_diff::report): Support suppressed reports about added or
	removed functions, variables and symbols.  Fixed a typo that was
	in there for a while.  Note that that fix requires updating some
	regression tests, and the part of this patch that touches
	regression tests does that.
	(apply_suppressions):  In the overload for corpus_diff, apply the
	suppression to added or removed functions and variables.
	* doc/manuals/libabigail-concepts.rst: Update this manual to
	reflect the changes above.  Also, perform an extensive cleanup of
	the manual to introduce more section titles to make it easier to
	navigate the document using the table of content.
	* tests/data/test-abicompat/test2-var-removed-report-0.txt:
	Adjust.
	* tests/data/test-diff-dwarf/test0-report.txt: Likewise.
	* tests/data/test-diff-dwarf/test12-report.txt: Likewise.
	* tests/data/test-diff-dwarf/test18-alias-sym-report-0.txt:
	Likewise.
	* tests/data/test-diff-dwarf/test19-soname-report-0.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-dwarf/test16-syms-only-report.txt: Likewise.
	* tests/data/test-diff-dwarf/test17-non-refed-syms-report-0.txt:
	Likewise.
	* tests/data/test-diff-dwarf/test28-vtable-changes-report-0.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/test13-report.txt: Likewise.
	* test-diff-suppr/test15-suppr-added-fn-v0.o: Add new test
	material.
	* tests/data/test-diff-filter/test15-0-report.txt: Likewise.
	* tests/data/test-diff-filter/test2-report.txt: Likewise.
	* tests/data/test-diff-filter/test21-compatible-vars-report-0.txt:
	Likewise.
	* tests/data/test-diff-filter/test24-compatible-vars-report-1.txt:
	Likewise.
	* test-diff-suppr/test15-suppr-added-fn-v1.o: Likewise.
	* test-diff-suppr/test15-suppr-added-fn-0.suppr: Likewise.
	* test-diff-suppr/test15-suppr-added-fn-1.suppr: Likewise.
	* test-diff-suppr/test15-suppr-added-fn-2.suppr: Likewise.
	* test-diff-suppr/test15-suppr-added-fn-3.suppr: Likewise.
	* test-diff-suppr/test15-suppr-added-fn-4.suppr: Likewise.
	* test-diff-suppr/test15-suppr-added-fn-report-0.txt: Likewise.
	* test-diff-suppr/test15-suppr-added-fn-report-1.txt: Likewise.
	* test-diff-suppr/test15-suppr-added-fn-report-2.txt: Likewise.
	* test-diff-suppr/test15-suppr-added-fn-report-3.txt: Likewise.
	* test-diff-suppr/test15-suppr-added-fn-report-4.txt: Likewise.
	* test-diff-suppr/test15-suppr-added-fn-report-5.txt: Likewise.
	* test-diff-suppr/test15-suppr-added-fn-v0.cc: Likewise.
	* test-diff-suppr/test15-suppr-added-fn-v1.cc: Likewise.
	* test-diff-suppr/test16-suppr-removed-fn-v0.o: Likewise.
	* test-diff-suppr/test16-suppr-removed-fn-v1.o: Likewise.
	* test-diff-suppr/test16-suppr-removed-fn-0.suppr: Likewise.
	* test-diff-suppr/test16-suppr-removed-fn-1.suppr: Likewise.
	* test-diff-suppr/test16-suppr-removed-fn-2.suppr: Likewise.
	* test-diff-suppr/test16-suppr-removed-fn-3.suppr: Likewise.
	* test-diff-suppr/test16-suppr-removed-fn-4.suppr: Likewise.
	* test-diff-suppr/test16-suppr-removed-fn-report-0.txt: Likewise.
	* test-diff-suppr/test16-suppr-removed-fn-report-1.txt: Likewise.
	* test-diff-suppr/test16-suppr-removed-fn-report-2.txt: Likewise.
	* test-diff-suppr/test16-suppr-removed-fn-report-3.txt: Likewise.
	* test-diff-suppr/test16-suppr-removed-fn-report-4.txt: Likewise.
	* test-diff-suppr/test16-suppr-removed-fn-report-5.txt: Likewise.
	* test-diff-suppr/test16-suppr-removed-fn-v0.cc: Likewise.
	* test-diff-suppr/test16-suppr-removed-fn-v1.cc: Likewise.
	* test-diff-suppr/test17-suppr-added-var-v0.o: Likewise.
	* test-diff-suppr/test17-suppr-added-var-v1.o: Likewise.
	* test-diff-suppr/test17-suppr-added-var-0.suppr: Likewise.
	* test-diff-suppr/test17-suppr-added-var-1.suppr: Likewise.
	* test-diff-suppr/test17-suppr-added-var-2.suppr: Likewise.
	* test-diff-suppr/test17-suppr-added-var-3.suppr: Likewise.
	* test-diff-suppr/test17-suppr-added-var-4.suppr: Likewise.
	* test-diff-suppr/test17-suppr-added-var-report-0.txt: Likewise.
	* test-diff-suppr/test17-suppr-added-var-report-1.txt: Likewise.
	* test-diff-suppr/test17-suppr-added-var-report-2.txt: Likewise.
	* test-diff-suppr/test17-suppr-added-var-report-3.txt: Likewise.
	* test-diff-suppr/test17-suppr-added-var-report-4.txt: Likewise.
	* test-diff-suppr/test17-suppr-added-var-report-5.txt: Likewise.
	* test-diff-suppr/test17-suppr-added-var-v0.cc: Likewise.
	* test-diff-suppr/test17-suppr-added-var-v1.cc: Likewise.
	* test-diff-suppr/test18-suppr-removed-var-v0.o: Likewise.
	* test-diff-suppr/test18-suppr-removed-var-v1.o: Likewise.
	* test-diff-suppr/test18-suppr-removed-var-0.suppr: Likewise.
	* test-diff-suppr/test18-suppr-removed-var-1.suppr: Likewise.
	* test-diff-suppr/test18-suppr-removed-var-2.suppr: Likewise.
	* test-diff-suppr/test18-suppr-removed-var-3.suppr: Likewise.
	* test-diff-suppr/test18-suppr-removed-var-4.suppr: Likewise.
	* test-diff-suppr/test18-suppr-removed-var-report-0.txt: Likewise.
	* test-diff-suppr/test18-suppr-removed-var-report-1.txt: Likewise.
	* test-diff-suppr/test18-suppr-removed-var-report-2.txt: Likewise.
	* test-diff-suppr/test18-suppr-removed-var-report-3.txt: Likewise.
	* test-diff-suppr/test18-suppr-removed-var-report-4.txt: Likewise.
	* test-diff-suppr/test18-suppr-removed-var-report-5.txt: Likewise.
	* test-diff-suppr/test18-suppr-removed-var-v0.cc: Likewise.
	* test-diff-suppr/test18-suppr-removed-var-v1.cc: Likewise.
	* tests/data/test-diff-suppr/test19-suppr-added-fn-sym-v0.o: New
	test input.
	* tests/data/test-diff-suppr/test19-suppr-added-fn-sym-v1.o:
	Likewise.
	* tests/data/test-diff-suppr/test19-suppr-added-fn-sym-0.suppr:
	Likewise.
	* tests/data/test-diff-suppr/test19-suppr-added-fn-sym-1.suppr:
	Likewise.
	* tests/data/test-diff-suppr/test19-suppr-added-fn-sym-2.suppr:
	Likewise.
	* tests/data/test-diff-suppr/test19-suppr-added-fn-sym-3.suppr:
	Likewise.
	* tests/data/test-diff-suppr/test19-suppr-added-fn-sym-4.suppr:
	Likewise.
	* tests/data/test-diff-suppr/test19-suppr-added-fn-sym-report-0.txt:
	Likewise.
	* tests/data/test-diff-suppr/test19-suppr-added-fn-sym-report-1.txt:
	Likewise.
	* tests/data/test-diff-suppr/test19-suppr-added-fn-sym-report-2.txt:
	Likewise.
	* tests/data/test-diff-suppr/test19-suppr-added-fn-sym-report-3.txt:
	Likewise.
	* tests/data/test-diff-suppr/test19-suppr-added-fn-sym-report-4.txt:
	Likewise.
	* tests/data/test-diff-suppr/test19-suppr-added-fn-sym-report-5.txt:
	Likewise.
	* tests/data/test-diff-suppr/test19-suppr-added-fn-sym-v0.cc:
	Likewise.
	* tests/data/test-diff-suppr/test19-suppr-added-fn-sym-v1.cc:
	Likewise.
	* tests/data/test-diff-suppr/test20-suppr-removed-fn-sym-v0.o:
	Likewise.
	* tests/data/test-diff-suppr/test20-suppr-removed-fn-sym-v1.o:
	Likewise.
	* tests/data/test-diff-suppr/test20-suppr-removed-fn-sym-0.suppr:
	Likewise.
	* tests/data/test-diff-suppr/test20-suppr-removed-fn-sym-1.suppr:
	Likewise.
	* tests/data/test-diff-suppr/test20-suppr-removed-fn-sym-2.suppr:
	Likewise.
	* tests/data/test-diff-suppr/test20-suppr-removed-fn-sym-3.suppr:
	Likewise.
	* tests/data/test-diff-suppr/test20-suppr-removed-fn-sym-4.suppr:
	Likewise.
	* tests/data/test-diff-suppr/test20-suppr-removed-fn-sym-report-0.txt:
	Likewise.
	* tests/data/test-diff-suppr/test20-suppr-removed-fn-sym-report-1.txt:
	Likewise.
	* tests/data/test-diff-suppr/test20-suppr-removed-fn-sym-report-2.txt:
	Likewise.
	* tests/data/test-diff-suppr/test20-suppr-removed-fn-sym-report-3.txt:
	Likewise.
	* tests/data/test-diff-suppr/test20-suppr-removed-fn-sym-report-4.txt:
	Likewise.
	* tests/data/test-diff-suppr/test20-suppr-removed-fn-sym-report-5.txt:
	Likewise.
	* tests/data/test-diff-suppr/test20-suppr-removed-fn-sym-v0.cc:
	Likewise.
	* tests/data/test-diff-suppr/test20-suppr-removed-fn-sym-v1.cc:
	Likewise.
	* tests/data/test-diff-suppr/test21-suppr-added-var-sym-v0.o:
	Likewise.
	* tests/data/test-diff-suppr/test21-suppr-added-var-sym-v1.o:
	Likewise.
	* tests/data/test-diff-suppr/test21-suppr-added-var-sym-0.suppr:
	Likewise.
	* tests/data/test-diff-suppr/test21-suppr-added-var-sym-1.suppr:
	Likewise.
	* tests/data/test-diff-suppr/test21-suppr-added-var-sym-2.suppr:
	Likewise.
	* tests/data/test-diff-suppr/test21-suppr-added-var-sym-3.suppr:
	Likewise.
	* tests/data/test-diff-suppr/test21-suppr-added-var-sym-4.suppr:
	Likewise.
	* tests/data/test-diff-suppr/test21-suppr-added-var-sym-report-0.txt:
	Likewise.
	* tests/data/test-diff-suppr/test21-suppr-added-var-sym-report-1.txt:
	Likewise.
	* tests/data/test-diff-suppr/test21-suppr-added-var-sym-report-2.txt:
	Likewise.
	* tests/data/test-diff-suppr/test21-suppr-added-var-sym-report-3.txt:
	Likewise.
	* tests/data/test-diff-suppr/test21-suppr-added-var-sym-report-4.txt:
	Likewise.
	* tests/data/test-diff-suppr/test21-suppr-added-var-sym-report-5.txt:
	Likewise.
	* tests/data/test-diff-suppr/test21-suppr-added-var-sym-v0.cc:
	Likewise.
	* tests/data/test-diff-suppr/test21-suppr-added-var-sym-v1.cc:
	Likewise.
	* tests/data/test-diff-suppr/test22-suppr-removed-var-sym-v0.o:
	Likewise.
	* tests/data/test-diff-suppr/test22-suppr-removed-var-sym-v1.o:
	Likewise.
	* tests/data/test-diff-suppr/test22-suppr-removed-var-sym-0.suppr:
	Likewise.
	* tests/data/test-diff-suppr/test22-suppr-removed-var-sym-1.suppr:
	Likewise.
	* tests/data/test-diff-suppr/test22-suppr-removed-var-sym-2.suppr:
	Likewise.
	* tests/data/test-diff-suppr/test22-suppr-removed-var-sym-3.suppr:
	Likewise.
	* tests/data/test-diff-suppr/test22-suppr-removed-var-sym-4.suppr:
	Likewise.
	* tests/data/test-diff-suppr/test22-suppr-removed-var-sym-report-0.txt:
	Likewise.
	* tests/data/test-diff-suppr/test22-suppr-removed-var-sym-report-1.txt:
	Likewise.
	* tests/data/test-diff-suppr/test22-suppr-removed-var-sym-report-2.txt:
	Likewise.
	* tests/data/test-diff-suppr/test22-suppr-removed-var-sym-report-3.txt:
	Likewise.
	* tests/data/test-diff-suppr/test22-suppr-removed-var-sym-report-4.txt:
	Likewise.
	* tests/data/test-diff-suppr/test22-suppr-removed-var-sym-report-5.txt:
	Likewise.
	* tests/data/test-diff-suppr/test22-suppr-removed-var-sym-v0.cc:
	Likewise.
	* tests/data/test-diff-suppr/test22-suppr-removed-var-sym-v1.cc:
	Likewise.
	* tests/data/Makefile.am: Add the new test materials above to source
	distribution.
	* tests/test-diff-suppr.cc (in_out_specs): Add the new tests
	material above to the list of test inputs this harness has to run
	over.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2015-06-24 12:09:53 +02:00
Dodji Seketeli
afd0411b64 Various white space cleanups
* include/abg-comparison.h: Remove various useless vertical white
	spaces.
	* tests/test-diff-dwarf.cc (in_out_spec): Fix indentation of some
	entries.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2015-06-04 13:30:16 +02:00
Dodji Seketeli
0cd814766b Support new 'accessed_through' suppression property
It turned out it's important to be able to suppress changes about
types that are reachable from a function parameter only through e.g, a
pointer or a reference, so that only changes types that are reachable
directly from a function parameter are emitted.

This patch adds that feature.

While doing this, I noticed this: Suppose a diff node D2 is marked as
being redundant with a diff node D1 seen previously.  So only D1 is
reported; D2 is not, because it's been filtered out, because it's
redundant with D1.  But then suppose D1 is filtered out, due to a
suppression specification.  At that point, D2 should not be marked
redundant anymore, and should be reported.

Of course, the code before this patch was wrongly filtering D2 *and*
D1 out.  So this patch fixes that.

	* include/abg-comparison.h (enum type_suppression::reach_kind):
	Define new enum.
	(type_suppression::{get_consider_reach_kind,
	set_consider_reach_kind, get_reach_kind,
	mark_last_diff_visited_per_class_of_equivalence,
	clear_last_diffs_visited_per_class_of_equivalence,
	get_last_visited_diff_of_class_of_equivalence}): Declare new
	member functions.
	* src/abg-comparison.cc (diff_has_ancestor_filtered_out)
	(read_suppression_reach_kind): Define static function.
	(type_suppression::priv::{consider_reach_kind_, reach_kind_}):
	Define new data members.
	(type_suppression::priv::priv): Take a new reach_kind parameter.
	(type_suppression::type_suppression): Adjust to new prototype of
	priv constructor.
	(type_suppression::{get_consider_reach_kind,
	set_consider_reach_kind, get_reach_kind, set_reach_kind}): Define
	new member functions.
	(type_suppression::suppresses_diff): Interpret the result of
	type_suppression::get_reach_kind() to determine if the suppression
	specification suppresses a given diff node.
	(read_type_suppression): Support reading the content of the
	"accessed_through" property.
	(diff_context::priv::last_visited_diff_node_): New data member.
	(diff_context::{mark_last_diff_visited_per_class_of_equivalence,
	clear_last_diffs_visited_per_class_of_equivalence,
	get_last_visited_diff_of_class_of_equivalence}): Define new data
	members.
	(redundancy_marking_visitor::visit_begin): So if the current diff
	node has already been visited, but if the previously visited node
	has been filtered out, then do not mark this node as being
	redundant.  And mark the current diff node as being the last
	visited one in its class of equivalence.
	(categorize_redundancy): Clear the map of diff nodes visited per
	class of equivalence.
	* doc/manuals/libabigail-concepts.rst: Document the new
	'accessed_through' property.
	* tests/data/test-diff-suppr/test13-suppr-through-pointer-0.suppr:
	New test input data.
	* tests/data/test-diff-suppr/test13-suppr-through-pointer-report-{0,1}.txt:
	Likewise.
	* tests/data/test-diff-suppr/libtest13-suppr-through-pointer-v{0,1}.so:
	New test input binaries.
	* tests/data/test-diff-suppr/test13-suppr-through-pointer-v{0,1}.cc:
	Source code of the test input binaries above.
	* tests/data/test-diff-suppr/test14-suppr-non-redundant-0.suppr:
	New test input data.
	* tests/data/test-diff-suppr/test14-suppr-non-redundant-report-0.txt:
	Likewise.
	* tests/data/test-diff-suppr/test14-suppr-non-redundant-v{0,1}.o:
	New test input binaries.
	* tests/data/test-diff-suppr/test14-suppr-non-redundant-v{0,1}.cc:
	Source code of the binaries above.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2015-06-04 13:29:32 +02:00
Dodji Seketeli
85929105f5 Fix redundancy marking for change of types used directly
If a type T is used directly (i.e, not through a pointer or reference)
as a function parameter or as a base class, a change in T should never
be marked as redundant in that context.  Otherwise, the change in that
context might be filtered out, possibly hiding real ABI incompatible
changes.

This patch implements this policy.

Also, it turned out in some circumstances, we where marking the first
visited diff node of a given class of equivalence of nodes as being
redundant, while we should only mark the *subsequently* visited nodes
of that class of equivalence as visited.  The patch also fixes that.

	* include/abg-comparison.h (pointer_map): Make this be a map of
	{size_t, size_t} pairs, rather than {size_t, bool}, so that each
	pointer in the map can be associated to another one.
	(diff_context::diff_has_been_visited): Return the pointer to the
	first diff node of the equivalence class that has been visited.
	* src/abg-comparison.cc (is_pointer_diff, is_reference_diff)
	(is_reference_or_pointer_diff, is_fn_parm_diff, is_base_diff)
	(is_child_node_of_function_parm_diff, is_child_node_of_base_diff):
	Define new static functions.
	(diff_context::diff_has_been_visited): Return the pointer to the
	first diff node of the equivalence class that has been visited.
	(diff_context::mark_diff_as_visited): Save the pointer to the
	first diff node of a given class of equivalence that has been
	visited.
	(redundancy_marking_visitor::visit_begin): If a diff node is a
	child node of a function parameter diff or base diff node and if
	it's not a pointer or reference diff node, then do not mark it as
	redundant.  Also, make sure to not mark the first diff node of a
	given class of equivalence that has been visited, as redundant;
	only the other subsequent nodes should be marked redundant; we
	were hitting this case because of an optimization that makes
	equivalent class diff nodes to share their private (pimpl) data.
	* tests/data/test-diff-filter/test29-finer-redundancy-marking-v{0,1}.o:
	New test input binaries.
	* tests/data/test-diff-filter/test29-finer-redundancy-marking-v{0,1}.cc:
	Source code of the new test input binaries above.
	* tests/data/test-diff-filter/test29-finer-redundancy-marking-report-0.txt:
	New test input.
	* tests/data/Makefile.am: Add the new test material above to the
	source distribution.
	* tests/test-diff-filter.cc (in_out_specs): Make this test harness
	run over the additional test input above.
	* tests/data/test-diff-suppr/test5-fn-suppr-report-0.txt: Adjust.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2015-06-03 12:13:54 +02:00
Dodji Seketeli
d0bd599b4b Support specifying data member insertion in suppressions
This patch is for supporting this kind of things:

    [suppress_type]
      name = S
      has_data_member_inserted_between = {8, end}

or:

    [suppress_type]
      name = S
      has_data_members_inserted_between = {{8, 31}, {64, end}}

or:

    [suppress_type]
      name = S
      has_data_members_inserted_at = offset_after(member0)

How cool is that, heh?

Anyway, to do this, the patch adds support for tuple values (i.e,
lists of values) in INI files.

Then on top of that the patch adds support for the specific
has_data_member_inserted_between, has_data_members_inserted_between
and has_data_members_inserted_at properties.

	* include/abg-comparison.h (type_suppression::insertion_range):
	Declare new type.
	(type_suppression::insertion_ranges): Declare new typedef.
	(type_suppression::{s,g}et_data_member_insertion_ranges): Declare
	new member functions.
	(is_integer_boundary, is_fn_call_expr_boundary): Declare new
	functions.
	(type_suppression::insertion_range::{boundary, integer_boundary,
	fn_call_expr_boundary}): Define new types.
	* src/abg-comparison.cc:
	(struct type_suppression::insertion_range::priv): New type.
	(type_suppression::insertion_range::{insertion_range, begin,
	end}): Define new member functions.
	(type_suppression::priv::insertion_ranges_): Add data member.
	(type_suppression::{s,g}et_data_member_insertion_ranges): Define
	new member functions.
	(type_suppression::insertion_range::boundary::priv): Define new
	type.
	(type_suppression::insertion_range::boundary::{boundary,
	~boundary}): Define new member functions.
	(type_suppression::insertion_range::integer_boundary::priv):
	Define new type.
	(type_suppression::insertion_range::integer_boundary::{integer_boundary,
	as_integer, operator int, ~integer_boundary}): Define member
	functions.
	(type_suppression::insertion_range::fn_call_expr_boundary::priv):
	Define new type.
	(type_suppression::insertion_range::fn_call_expr_boundary::{fn_call_expr_boundary,
	as_function_call_expr, operator ini::function_call_expr_sptr}):
	Define new member functions.
	(type_suppression::insertion_range::{create_integer_boundary,
	type_suppression::insertion_range::create_fn_call_expr_boundary,
	type_suppression::insertion_range::eval_boundary}): Define new
	member functions.
	(is_integer_boundary, is_fn_call_expr_boundary): Define new
	functions.
	(read_type_suppression, read_function_suppression)
	(read_variable_suppression): Support the new kinds of
	property-related types. Aslo, in read_type_suppression, support
	the new properties has_data_member_inserted_at,
	has_data_member_inserted_between and
	has_data_members_inserted_between.
	(type_suppression::suppresses_diff): If we are looking at a type
	diff node that has inserted data members, evaluate the insertion
	ranges of the current type_suppression and see if they match the
	inserted data members.
	* include/abg-ini.h (property, simple_property, property_value)
	(string_property_value, tuple_property_value, function_call_expr):
	Declare new types.
	(property_sptr, property_value_sptr, string_property_value_sptr)
	(tuple_property_value_sptr): Declare new typedefs.
	(is_string_property_value, is_tuple_property_value)
	(is_simple_property, is_tuple_property, read_function_call_expr):
	Declare new functions.
	* src/abg-ini.cc (char_is_white_space, char_is_comment_start)
	(char_is_delimiter, char_is_property_value_char)
	(char_is_section_name_char, char_is_property_name_char)
	(char_is_comment_start, char_is_white_space)
	(remove_trailing_white_spaces, is_string_property_value)
	(is_tuple_property_value, is_simple_property, is_tuple_property)
	(write_property_value, char_is_function_name_char)
	(char_is_function_argument_char): Define new functions.
	(property::priv, tuple_property_value::priv)
	(simple_property::priv, tuple_property::priv): Define new types.
	(property::{property, get_name, set_name, ~property}): Define new
	member functions.
	(struct property_value::priv): Define new type.
	(property_value::{property_value, get_kind, operator const
	string&(), ~property_value}): Define new member functions.
	(struct string_property_value::priv): Define new type.
	(string_property_value::{string_property_value, set_content,
	as_string, operator string()}, ~string_property_value): Define new
	member functions.
	(tuple_property_value::{tuple_property_value, get_value_items,
	~tuple_property_value, as_string}): Likewise.
	(simple_property::{simple_property, get_value, set_value,
	~simple_property}): Likewise.
	(tuple_property::{tuple_property, set_value, get_value}):
	Likewise.
	(config::section::find_property): Adjust return type.
	(read_context::{char_is_delimiter, char_is_property_value_char,
	char_is_section_name_char, char_is_property_name_char,
	char_is_comment_start, char_is_white_space}): Remove these from
	here as they got moved them to be non-member functions above.
	(read_context::read_property_value): Return a property_value_sptr
	and do not take any parameter anymore.
	(read_context::{read_string_property_value,
	read_tuple_property_value, read_function_name,
	read_function_argument, read_function_call_expr}): Define new
	member functions.
	(read_context::read_property): Adjust return type.  Also, change to read
	the different new kinds of properties values.
	(function_call_expr::priv): Define new type.
	(function_call_expr::{function_call_expr, get_name,
	get_arguments}): New member functions.
	(read_context::read_section): Adjust.
	(write_property, write_section): Adjust.
	* tests/data/test-diff-suppr/libtest{11,12}-add-data-member-v{0,1}.so:
	New test input binaries.
	* tests/data/test-diff-suppr/test{11,12}-add-data-member-{0,1}.suppr:
	New input suppression files.
	* tests/data/test-diff-suppr/test11-add-data-member-{2,3,4}.suppr:
	Add new test input files.
	* tests/data/test-diff-suppr/test{11,12}-add-data-member-report-{0,1}.txt:
	New reference output files.
	* tests/data/test-diff-suppr/test12-add-data-member-report-2.txt:
	Likewise.
	* tests/data/test-diff-suppr/test{11,12}-add-data-member-v{0,1}.cc:
	Source code for the new binaries above.
	* tests/test-diff-suppr.cc (in_out_specs): Add new test inputs.
	* tests/data/Makefile.am: Add the new test related files above to
	source distribution.
	* doc/manuals/libabigail-concepts.rst: Document the new properties
	has_data_member_inserted_at, has_data_member_inserted_between and
	has_data_members_inserted_between.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2015-05-24 23:43:02 +02:00
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
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 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
56d958641c Bug 17649 Avoid endless looping on diff graph with cycles
Bug URL: https://sourceware.org/bugzilla/show_bug.cgi?id=17649.

abidiff stumbled accross a diff graph with cycles.  And it kept
walking that graph endlessly.  Of course.

It turned out on such graphs with cycles, the categorizing code that
uses abigail::comparison::diff::traverse() to walk the graph and
categorize the diff nodes was traversing the same class of equivalence
of certain diff nodes more than once without even noticing.

This patch changes the logic of the diff graph traversing code to make
it always call diff_node_visitor::visit_begin() on the visitor for a
diff node prior to visiting it (visiting means calling
diff_node_visitor::visit()) and diff_node_visitor::visit_end() after
visiting it.

But when the diff node has already been visited and it's reached again
by the traversing code (in case of a cycle) then the
diff_node_visitor::visit_begin() is called, but
diff_node_visitor::visit() is *NOT*.  Then
diff_node_visitor::visit_end() is called.  In other words, even when
the diff node is not visited (because it's already been visited) the
pair diff_node_visitor::{visit_begin,visit_end}() is called.

This avoids traversing the diff node (or rather the equivalence class
of the diff node) more than once even in presence of cycles, but still
gives a chance to custom visitors to detect that they are seeing a
cycle and act accordingly if need be.  This is a kind of cycle
detection feature.

Then the code of the (harmless and harmful categorization) filters has
been adapted to always rely on the cycle detection feature.  The code
of the category propagation visitor has also been adapted to propagate
the category of a given diff node to and from its canonical diff node.

	* include/abg-comp-filter.h (harm{less,ful}_filter::visit_end):
	Declare new methods.
	* include/abg-comparison.h (diff_context::maybe_apply_filters):
	Remove the traverse_nodes_once flag.
	* src/abg-comp-filter.cc (apply_filter): Force the traversing to
	operate in cycle avoidance mode.
	(harm{less,ful}_filter::visit): Update the category of the
	canonical node too.
	(harm{less,ful}_filter::visit_end): Define new method.
	* src/abg-comparison.cc (diff_context::maybe_apply_filters):
	Remove the traverse_nodes_once flag.  Adjust.  Simplify logic.
	(diff::traverse): Always call diff_node_visitor::{begin,end}.  If
	the node has already been visited previously then do not call
	diff_node_visitor::visit() and do not visit the children nodes.
	(category_propagation_visitor::visit_end):  If the node has
	already been visited, then propagate the category from the
	canonical nodes of the children nodes.
	(propagate_categories):  Force the traversing to operate in cycle
	avoidance mode.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2015-02-21 15:16:48 +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
32352341c5 Add a method to diff_context to dump a diff tree to error output
For debugging purposes it's very convenient to able to dump a diff
tree to error output.  This patch just adds that possibility.

	* include/abg-comparison.h (diff_context::error_output_stream):
	Make this function const.
	(diff_context::{do_dump_diff_tree}): Declare new methods.
	* src/abg-comparison.cc (diff_context::error_output_stream): Make
	this function const.
	(diff_context::do_dump_diff_tree): Define new methods.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2015-01-27 12:49:40 +01:00
Dodji Seketeli
2173563f3c Keep children nodes of class_diff and scope_diff sorted
I realized that some children nodes of class_diff and scope_diff node
appear in the order laid out by the hash map that contains them.  This
can be quite random depending on various factors.  More over the
reporting code walks sorts the children nodes before walking them to
emit reports, so the walking order of the reporting code is (or can
be) different from the natural walking order used, for instance, by
the categorization or redundancy detection code.  This can have weird
side effects, especially for reporting about redundancy where the
walking other matters.

This patch thus sorts the children nodes of the class_diff and
scope_diff nodes and hopefully udpates all the code that needs
updating to take that in account.

	* include/abg-comparison.h (decl_diff_base, type_diff_base):
	Forward declare these types.
	(diff_sptrs_type, decl_diff_base_sptr, decl_diff_base_sptrs_type)
	(type_diff_base_sptr, type_diff_base_sptrs_type)
	(base_diff_sptrs_type, string_type_diff_base_sptr_map)
	(string_decl_diff_base_sptr_map, string_diff_sptr_map): New
	typedefs.
	(changed_type_or_decl, changed_parm, changed_parms_type)
	(string_changed_type_or_decl_map)
	(unsigned_changed_type_or_decl_map, changed_type_or_decl_vector):
	Remove typedefs.
	(class_diff::changed_base): Make this return a
	base_diff_sptrs_type now.  No more a string_base_diff_sptr_map.
	(class_diff::changed_member_fns): Make this return a
	function_decl_diff_sptrs_type, no more a
	string_changed_member_function_sptr_map.
	(class_diff::changed_types): Make this return a diff_sptrs_type,
	not a string_changed_type_or_decl_map anymore.
	(class_diff::changed_decls): Make this return a diff_sptrs_type,
	not a string_changed_type_or_decl_map anymore.
	* src/abg-comp-filter.cc (has_virtual_mem_fn_change)
	(has_non_virtual_mem_fn_change): Adjust.
	* src/abg-comparison.cc (compute_diff): For the decl_base_sptr and
	type_base_sptr overloads, assert that the resulting diff is
	non-null.
	(class_diff::priv::{sorted_changed_base_,
	sorted_changed_member_types_, sorted_subtype_changed_dm_,
	sorted_changed_dm_, sorted_changed_member_functions_,
	sorted_changed_member_class_tmpls_}): New data members.
	(class_diff::priv::changed_member_types_): Changed the type of
	this from string_changed_type_or_decl_map to string_diff_sptr_map.
	(class_diff::priv::changed_member_functions_): Changed the type of
	this from string_changed_member_function_sptr_map to
	string_function_decl_diff_sptr_map.
	(class_diff::priv::changed_member_class_tmpls_): Changed the type
	of this from string_changed_type_or_decl_map to
	string_diff_sptr_map.
	(class_diff::ensure_lookup_tables_populated): Adjust.  Initialize
	the new sorted members class_diff::priv::{sorted_changed_bases_,
	sorted_subtype_changed_dm_, sorted_changed_dm_,
	sorted_changed_member_functions_, sorted_changed_member_types_}.
	(class_diff::priv::{member_type_has_changed,
	member_class_tmpl_has_changed, count_filtered_bases,
	count_filtered_subtype_changed_dm, count_filtered_changed_mem_fns,
	}): Adjust.
	(class_diff::chain_into_hierarchy): Adjust:  The children nodes of
	class_diff are now laid out in a sorted way.
	(class_diff::{changed_bases, changed_member_fns}): Adjust.
	(base_diff_comp, virtual_member_function_diff_comp): New types.
	(sort_string_base_diff_sptr_map)
	(sort_string_virtual_member_function_diff_sptr_map): New static
	functions.
	(data_member_diff_comp): Renamed var_diff_comp into this.
	(sort_unsigned_data_member_diff_sptr_map): Renamed sort_var_diffs
	into this and adjust.
	(class_diff::report): Do not sort the nodes we are about to emit
	here.  Just use the natural order of the nodes in their parent
	tree as they should now be sorted.
	(scope_diff::priv::{changed_types_, changed_decls_}): Change the
	type of these from string_changed_type_or_decl_map to
	string_diff_sptr_map.
	(scope_diff::priv::{sorted_changed_types_,
	sorted_changed_decls_}): New data members.
	(scope_diff::ensure_lookup_tables_populated): Adjust.  Initialize
	the new scope_diff::priv::sorted_changed_{types_, decls_}.
	(scope_diff::chain_into_hierarchy): Adjust.  The children of
	scope_diff are now sorted.
	(scope_diff::changed_{types, decls}): Return the sorted vectors of
	children nodes.
	(struct changed_type_or_decl_comp): Remove.
	(struct diff_comp): New type.
	(sort_changed_type_or_decl): Remove.
	(sort_string_diff_sptr_map): New static function.
	(scope_diff::report): Adjust.  Do not sort children nodes here
	ourselves before reporting about them.  Rather, use the natural
	topological order of the children as they are now sorted.
	(corpus_diff::priv::sorted_changed_vars_): Renamed
	corpus_diff::priv::changed_vars_ into this to make it more
	explicit that the things it holds are sorted.
	(corpus_diff::changed_variables_sorted): Adjust.
	(corpus_diff::priv::ensure_lookup_tables_populated): Likewise.
	(corpus_diff::priv::apply_filters_and_compute_diff_stats):
	Likewise.
	(corpus_diff::priv::categorize_redundant_changed_sub_nodes):
	Likewise.
	(corpus_diff::priv::clear_redundancy_categorization): Likewise.
	(corpus_diff::priv::maybe_dump_diff_tree): Likewise.
	(corpus_diff::report): Likewise.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2015-01-27 12:49:40 +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
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
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
0e1d9f9892 Add a --dump-diff-tree to abidiff for debugging purposes
I have felt the need to emit a textual representation of the diff
nodes tree maintained by the comparison engine for changed functions
and variables.  This patch adds that functionality.

	* include/abg-comparison.h (enum visiting_kind): Add new
	DO_NOT_MARK_VISITED_NODES_AS_TRAVERSED enumerator.
	(diff_context::{default_output_stream, error_output_stream,
	dump_diff_tree}): Declare new accessors.
	(diff::end_traversing): Take a new boolean flag.
	(print_diff_tree): Add new overload for diff_sptr.
	* src/abg-comparison.cc
	(diff_context::priv::{default_output_stream_,
	error_output_stream_, dump_diff_tree_}): New data members.
	(priv::priv): Initialize them.
	(diff_context::{default_output_stream_, error_output_stream_,
	dump_diff_tree, dump_diff_tree}): Define new accessors.
	(diff::end_traversing): Take a new flag that control whether or
	not to mark the current diff node as having been traversed.
	(diff::traverse): Take in account the visiting kind carried by the
	visitor to determine if the visited node should be marked as being
	traversed.
	(corpus_diff::priv::maybe_dump_diff_tree): Define new member
	function.
	(corpus_diff::report): Call it.
	(diff_node_printer::visit): Pretty print the diff node just once.
	(print_diff_tree): Define a new overload for diff_sptr.
	* tools/abidiff.cc (options::dump_diff_tree): New data member.
	(options::options): Initialize it.
	(display_usage): Add a help string for the new --dump-diff-tree
	command line switch.
	(parse_command_line): Parse the new --dump-diff-tree command line
	switch.
	(set_diff_context_from_opts): Set the diff context according to
	the --dump-diff-tree presence.
	* doc/manuals/abidiff.rst: Add a bullet point for the new
	--dump-diff-tree command line switch.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2014-12-28 11:36:52 +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
Sinny Kumari
a6897b0fea Add new methods in corpus_diff class
Functions added_unrefed_function_symbols() and
added_unrefed_variable_symbols() are required in order to access
added functions and variables obtained while calculating abi diff
between libraries with no debug information available

	* include/abg-comparison.h
	(corpus_diff::added_unrefed_function_symbols):
	Declare new member function
	(corpus_diff::added_unrefed_variable_symbols):
	Declare new member function
	* src/abg-comparison.cc
	(corpus_diff::added_unrefed_function_symbols):
	Define new member function
	(corpus_diff::added_unrefed_variable_symbols):
	Define new member function

Signed-off-by: Sinny Kumari <skumari@redhat.com>
2014-12-18 15:27:39 +01:00
Sinny Kumari
a95af1c160 Add new corpus_diff::added_variables() method
Function added_variables() is required in order to access the list of
added variables obtained while calculating abi diff between two
libraries outside libabigail

	* include/abg-comparison.h (corpus_diff::added_variables):
	Declare new member function
	* src/abg-comparison.cc (corpus_diff::added_variables):
	Define new member function

Signed-off-by: Sinny Kumari <skumari@redhat.com>
Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2014-12-15 09:23:52 +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
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
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
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
f5135b9d38 Fix an apidoc typo
* include/abg-comparison.h (class variable_suppression): Fix a
	typo in the doc string.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2014-11-01 15:16:42 +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
ba77dd98c4 Make var_diff and function_decl_diff extend decl_diff_base
* include/abg-comparison.h (class var_diff, class
	function_decl_diff): Make these types inherit the decl_diff_base
	class.  This is like the fact that all kinds of diff inherit the
	type_diff_base class.
	* src/abg-comparison.cc (var_diff::var_diff)
	(function_decl_diff::function_decl_diff): Adjust to initialize the
	sub-object of decl_diff_base;
	(is_decl_diff): New predicate to know if a diff is about decls.
	(is_function_decl): New predicate to know if a diff is about
	function decls.
	(function_suppression::suppresses_diff): Adjust to use the new
	is_function_decl.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2014-11-01 12:15:14 +01:00
Dodji Seketeli
3816b22e6f Remove useless functions from the comparison engine
* include/abg-comparison.h (read_type_suppression): Remove this
	function declaration.
	* src/abg-comparison.cc (read_type_suppressions): Remove this
	static function definition.
	(read_function_suppressions): Remove this static function
	declaration.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2014-11-01 12:15:14 +01:00
Dodji Seketeli
4200a7cbb9 Fix various apidoc typos
* include/abg-comparison.h (class function_suppression): Fix typo
	in the doc string.
	* src/abg-comparison.cc (is_type_diff, read_suppressions)
	(diff::reported_once, typedef_diff::report): Fix the doc string.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2014-11-01 12:15:14 +01:00
Dodji Seketeli
23772b3f8d Initial support for function suppressions
* include/abg-comparison.h (enum visiting_kind): Change the
	meaning of this.  It was to determine if traversal was to be done
	in a pre or post manner.  But with the recent addition of
	diff_node_visitor::visit_{begin,end}() notifiers, the pre/post
	handling is taken care of in a different way.  So now the meaning
	of this enum is changed to handle whether diff node children
	should be visited or not.  So the enumerators are now
	DEFAULT_VISITING_KIND, and SKIP_CHILDREN_VISITING_KIND.  And it's
	a bit-field.
	(operator{&,~}): Declare more bit manipulation operators for the
	enum visiting_kind.
	(function_suppression_sptr, function_suppressions_type): New
	typedefs.
	(function_suppression, function_suppression::parameter_spec):
	Declare new types.
	(read_function_suppressions): Declare new function.
	(diff_node_visitor::diff_node_visitor): Adjust for the enum
	visiting_kind change.  Value-initialize the visiting_kind_ data
	member.
	* src/abg-comparison.cc (operator{&,~}): Define these operators
	for enum visiting_kind.
	(read_type_suppressions): Forward declare this static function.
	(read_function_suppression, read_parameter_spec_from_string):
	Define new static functions.
	(read_suppressions): Update to read function suppressions too,
	using the new read_function_suppression function above.
	(class function_suppression::parameter_spec::priv): Define new
	type.
	(function_suppression::parameter_spec::*): Define the member
	functions of the new function_suppression::parameter_spec type.
	(class function_suppression::priv): Define new type.
	(function_suppression::*): Define the member functions of the new
	function_suppression type.
	(diff::traverse): There is no more {PRE,POST}_VISITING_KIND
	enumerator.  So nuke the code that was dealing with it.
	(redundancy_marking_visitor::skip_children_nodes_): New data
	member flag.
	(redundancy_marking_visitor::visit_begin): If the current diff
	node is not be reported (is filtered out), do not bother visit its
	children nodes for the purpose of marking redundant nodes.  So use
	the new skip_children_nodes_ flag above to know we are in that case.
	(redundancy_marking_visitor::visit_end): Unset the new
	skip_children_nodes_ flag above when appropriate.
	* include/abg-fwd.h (is_function_decl): Declare new function.
	* include/abg-ir.h
	(function_type::get_parm_at_index_from_first_non_implicit_parm):
	Declare new member function.
	* src/abg-ir.cc (is_function_decl): Define new function.
	(function_type::get_parm_at_index_from_first_non_implicit_parm):
	Define new member function.
	* src/abg-comp-filter.cc (apply_filter): Adjust for the enum
	visiting_kind change.  No need to set it for filters anymore
	* doc/suppr-doc.txt: Update examples of function suppression.
	* doc/manuals/libabigail-concepts.rst: Update the manual for the
	function suppression addition.
	* tests/data/test-diff-suppr/libtest5-fn-suppr-v0.so: New test input.
	* tests/data/test-diff-suppr/libtest5-fn-suppr-v1.so: New test input.
	* tests/data/test-diff-suppr/libtest6-fn-suppr-v0.so: New test input.
	* tests/data/test-diff-suppr/libtest6-fn-suppr-v1.so: New test input.
	* tests/data/test-diff-suppr/test5-fn-suppr-0.suppr: New test input.
	* tests/data/test-diff-suppr/test5-fn-suppr-1.suppr: New test input.
	* tests/data/test-diff-suppr/test5-fn-suppr-2.suppr: New test input.
	* tests/data/test-diff-suppr/test5-fn-suppr-3.suppr: New test input.
	* tests/data/test-diff-suppr/test5-fn-suppr-4.suppr: New test input.
	* tests/data/test-diff-suppr/test5-fn-suppr-report-0.txt: New test input.
	* tests/data/test-diff-suppr/test5-fn-suppr-report-1.txt: New test input.
	* tests/data/test-diff-suppr/test5-fn-suppr-report-2.txt: New test input.
	* tests/data/test-diff-suppr/test5-fn-suppr-report-3.txt: New test input.
	* tests/data/test-diff-suppr/test5-fn-suppr-report-4.txt: New test input.
	* tests/data/test-diff-suppr/test5-fn-suppr-report-5.txt: New test input.
	* tests/data/test-diff-suppr/test5-fn-suppr-v0.cc: Source code for
	new test input.
	* tests/data/test-diff-suppr/test5-fn-suppr-v1.cc: Source code for
	new test input.
	* tests/data/test-diff-suppr/test6-fn-suppr-0.suppr: New test input.
	* tests/data/test-diff-suppr/test6-fn-suppr-1.suppr: New test input.
	* tests/data/test-diff-suppr/test6-fn-suppr-2.suppr: New test input.
	* tests/data/test-diff-suppr/test6-fn-suppr-3.suppr: New test input.
	* tests/data/test-diff-suppr/test6-fn-suppr-report-0.txt: New test input.
	* tests/data/test-diff-suppr/test6-fn-suppr-report-1.txt: New test input.
	* tests/data/test-diff-suppr/test6-fn-suppr-report-2.txt: New test input.
	* tests/data/test-diff-suppr/test6-fn-suppr-report-3.txt: New test input.
	* tests/data/test-diff-suppr/test6-fn-suppr-report-4.txt: New test input.
	* tests/data/test-diff-suppr/test6-fn-suppr-v0.cc: Source code for
	new test input.
	* tests/data/test-diff-suppr/test6-fn-suppr-v1.cc: Source code for
	new test input.
	* tests/data/test-diff-suppr/test6-fn-suppr-version-script: New
	test input.
	* tests/Makefile.am: Add the new files above to source
	the distribution.
	* tests/test-diff-suppr.cc (in_out_specs): Add the test inputs
	above to the list of tests to be run by this harness.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2014-10-28 17:36:32 +01:00
Dodji Seketeli
2f52f72b5a Add missing virtual destructor in comparison engine code
* include/abg-comparison.h (type_suppression::~type_suppression):
	Declare missing virtual destructor.
	* src/abg-comparison.cc (type_suppression::~type_suppression):
	Define missing virtual destructor.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2014-10-28 12:05:24 +01:00
Dodji Seketeli
f44110b326 Support comparing symbols not referenced by debug info
* doc/manuals/abidiff.rst: Adjust intro to mention that w/o debug
	info, abidiff now works but just report about added/removed
	symbols.  Add documentation about the new
	--no-unreferenced-symbols option.
	* include/abg-comparison.h (string_elf_symbol_map): New typedef.
	(diff_context::show_symbols_unreferenced_by_debug_info): Declare
	new accessors.
	* src/abg-comparison.cc
	(diff_context::priv::show_syms_unreferenced_by_di_): New data
	member.
	(diff_context::priv::priv): Adjust.
	(diff_context::show_symbols_unreferenced_by_debug_info): Implement
	these accessors.
	(corpus_diff::priv::{unrefed_fn_syms_edit_script_,
	unrefed_var_syms_edit_script_, added_unrefed_fn_syms_,
	deleted_unrefed_fn_syms_, added_unrefed_var_syms_,
	deleted_unrefed_var_syms_}): New data members.
	(corpus_diff::priv::diff_stats::{num_func_syms_removed,
	num_func_syms_added, num_var_syms_removed, num_var_syms_added}):
	New data members.
	(corpus_diff::priv::diff_stats::diff_stats): Adjust.
	(corpus_diff::ensure_lookup_tables_populated): Populate lookup
	tables for added/removed symbols that are not referenced by any
	debug info.
	(corpus_diff::priv::apply_filters_and_compute_diff_stats): Compute
	stats for the added/removed symbols not referenced by any debug
	info.
	(corpus_diff::priv::emit_diff_stats): Emit stats about
	added/removed symbols that are not referenced by any debug info.
	(corpus_diff::length): Adjust to take in account added/removed
	symbols not referenced by any debug info.
	(show_linkage_name_and_aliases): New static function.
	(corpus_diff::report): When emitting a symbol name, emit its
	version too, and tell if it aliases other symbols.  Avoid emitted
	extra new lines.  Report added/removed symbols not referenced by
	any debug info.
	(compute_diff): In the overload for corpus_sptr, compute the diffs
	for symbols not referenced by debug info.
	* include/abg-corpus.h
	(corpus::get_unreferenced_{function,variable}_symbols): Declare
	new member functions.
	* src/abg-corpus.cc (corpus_priv::{unrefed_fun_symbols,
	unrefed_var_symbols}): New data members.
	(corpus_priv::build_unreferenced_symbols_tables): Define new
	member function.
	(struct comp_elf_symbols_functor): New functor.
	(corpus::is_empty): Adjust to take in account added/removed
	symbols not referenced by debug info.
	(corpus::{get_unreferenced_function_symbols,
	corpus::get_unreferenced_variable_symbols}): Define these
	accessors.
	* include/abg-dwarf-reader.h (enum status): Transform this into
	bitfields.  Add a STATUS_UNKNOWN value that has the value 0.
	(operator|(status, status), operator&(status, status))
	(operator|=(status&, status), operator&=(status, status)): New
	bit-wise operators to manipulate instances of the status bit-field.
	* src/abg-dwarf-reader.cc (get_version_for_symbol): Fix this to
	avoid returning garbage version sometimes.
	(read_debug_info_into_corpus): Fix this to return a non-null but
	empty corpus_sptr when there is no debug info available.
	(operator|(status, status), operator&(status, status))
	(operator|=(status&, status), operator&=(status, status)): Define
	these new bitwise operators to manipulate instances of the status
	bit-field.
	(read_corpus_from_elf): Now that the abigail::dwarf_reader::status
	is a bit-field, set it to reflect if debug info and/or symbol
	tables have been found.  Do not bail out if debug info hasn't been
	found.  Rather, keep going, and go look for symbols-only; this is
	a kind of operating in degraded mode.
	* include/abg-ir.h (elf_symbol::get_aliases_id_string): Add a flag
	that says if the current instance of elf_symbol should be included
	in the list of aliases or not.
	* src/abg-ir.cc (elf_symbol::get_aliases_id_string): Define it.
	* tests/data/test-diff-dwarf/test16-syms-only-v{0,1}.o: New test
	input.
	* tools/abidiff.cc
	(options::show_symbols_not_referenced_by_debug_info): New data
	member.
	(options:options): Adjust.
	(display_usage): Add an info string for the new
	--no-unreferenced-symbols command line option.
	(parse_command_line): Parse the new --no-unreferenced-symbols
	command line.
	(set_diff_context_from_opts): Set the diff_context according to
	the presence of --no-unreferenced-symbols.
	(main): Adjust for the fact that abigail::dwarf_reader::status is
	now a bit-field.
	* tools/abilint.cc (main): Adjust for the fact that
	abigail::dwarf_reader::status is now a bit-field..
	():
	* tests/data/test-diff-dwarf/test16-syms-only-report.txt: New test
	reference output.
	* tests/data/test-diff-dwarf/test16-syms-only-v{0,1}.cc: Source code
	for new test input.
	* tests/data/test-diff-dwarf/test17-non-refed-syms-v{0,1}.o: New
	test input.
	* tests/data/test-diff-dwarf/test17-non-refed-syms-v{0,1}.cc: New
	source code for test input.
	* tests/data/test-diff-dwarf/libtest18-alias-sym-v{0,1}.so: New
	test input.
	* tests/data/test-diff-dwarf/test18-alias-sym-report-0.txt:
	Reference output for new test input.
	* tests/data/test-diff-dwarf/test18-alias-sym-v{0,1}.cc: Source
	code for new test input.
	* tests/data/test-diff-dwarf/test18-alias-sym-version-script:
	Source code for new test input.
	* tests/Makefile.am: Add the new test materials to the source
	distribution.
	* tests/test-diff-dwarf.cc(in_out_specs): Add the new input tests
	above to the array of tests to run by this harness.
	(main): Emit empty reports for empty resulting diffs.
	* tests/data/test-diff-dwarf/test{0,8,9,12,14-inline-report,}-report.txt:
	Adjust.
	* tests/data/test-diff-filter/test{0,01,2,4,5,7,8,9,10,12,13,15-0,15-1}-report.txt:
	Likewise.
	* tests/data/test-diff-filter/test{19-enum,20-inline,}-report-0.txt:
	Likewise.
	* tests/data/test-diff-suppr/test0-type-suppr-report-{1,2}.txt:
	Likewise.
	* tests/data/test-diff-suppr/test{1,2}-typedef-suppr-report-1.txt:
	Likewise.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2014-10-22 23:04:40 +02:00
Dodji Seketeli
d4445731bb Gain ability know if a diff node has local changes
* include/abg-comparison.h (diff::has_local_changes): Add new pure
	interface.
	({decl_diff_base, type_diff_base, distinct_type_diff, var_diff,
	pointer_diff, reference_diff, array_diff, qualified_type_diff,
	enum_diff, class_diff, base_diff, scope_diff, function_decl_diff,
	type_decl_diff, typedef_diff,
	translation_unit_diff}::has_local_changes): Declare the
	implementation of the pure interface above.
	* src/abg-comparison.cc ({decl_diff_base, type_diff_base,
	distinct_type_diff, var_diff, pointer_diff, reference_diff,
	array_diff, qualified_type_diff, enum_diff, class_diff, base_diff,
	scope_diff, function_decl_diff, type_decl_diff, typedef_diff,
	translation_unit_diff}::has_local_changes): Define the
	implementation of the pure interface above.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2014-10-13 17:44:44 +02:00