Commit Graph

1435 Commits

Author SHA1 Message Date
Ondrej Oprala
aba99e5106 Bug 20970 - Add a --annotate option to abidw
This option annotates (read "pretty-prints") the types and elf symbols
in the form of XML comments in the ABIXML output emitted by the abidw
command.

Signed-off-by: Ondrej Oprala <ondrej.oprala@gmail.com>

	* doc/manuals/abidiff.rst: Document the '--no-corpus-path'
	option.
	* doc/manuals/abidw.rst: Document the '--no-corpus-path'
	and '--annotate' options.
	* include/abg-libxml-utils.h ({un,}escape_xml_comment): Add
	new function declarations.
	* include/abg-writer.h: Add new annotate functions
	(write_{translation_unit,corpus_to_{archive,native_xml_file}}):
	Add an optional "annotate" parameter defaulting to "false".
	* src/abg-libxml-utils.cc ({un,}escape_xml_comment): Add
	new function definitions.
	* src/abg-writer.cc (annotate): Define new templatized function
	and specialize it for necessary cases.
	* tests/Makefile.am: Add runtestannotate as a new test.
	* tests/data/Makefile.am: Add paths to below reference test
	outputs.
	* tests/data/test-annotate/libtest23.so.abi: New reference test
	output.
	* tests/data/test-annotate/libtest24-drop-fns-2.so.abi: Likewise.
	* tests/data/test-annotate/libtest24-drop-fns.so.abi: Likewise.
	* tests/data/test-annotate/test0.abi: Likewise.
	* tests/data/test-annotate/test1.abi: Likewise.
	* tests/data/test-annotate/test10-pr18818-gcc.so.abi: Likewise.
	* tests/data/test-annotate/test11-pr18828.so.abi: Likewise.
	* tests/data/test-annotate/test12-pr18844.so.abi: Likewise.
	* tests/data/test-annotate/test13-pr18894.so.abi: Likewise.
	* tests/data/test-annotate/test14-pr18893.so.abi: Likewise.
	* tests/data/test-annotate/test15-pr18892.so.abi: Likewise.
	* tests/data/test-annotate/test16-pr18904.so.abi: Likewise.
	* tests/data/test-annotate/test17-pr19027.so.abi: Likewise.
	* tests/data/test-annotate/test18-pr19037-libvtkRenderingLIC-6.1.so.abi: Likewise.
	* tests/data/test-annotate/test19-pr19023-libtcmalloc_and_profiler.so.abi: Likewise.
	* tests/data/test-annotate/test2.so.abi: Likewise.
	* tests/data/test-annotate/test20-pr19025-libvtkParallelCore-6.1.so.abi: Likewise.
	* tests/data/test-annotate/test21-pr19092.so.abi: Likewise.
	* tests/data/test-annotate/test22-pr19097-libstdc++.so.6.0.17.so.abi: Likewise.
	* tests/data/test-annotate/test3.so.abi: Likewise.
	* tests/data/test-annotate/test4.so.abi: Likewise.
	* tests/data/test-annotate/test5.o.abi: Likewise.
	* tests/data/test-annotate/test6.so.abi: Likewise.
	* tests/data/test-annotate/test7.so.abi: Likewise.
	* tests/data/test-annotate/test8-qualified-this-pointer.so.abi: Likewise.
	* tests/data/test-annotate/test9-pr18818-clang.so.abi: Likewise.
	* tests/test-annotate.cc: New test for ABIXML annotations.
	* tools/abidiff.cc: Add the new option '--no-corpus-path'.
	* tools/abidw.cc: Likewise. Also add the '--annotate' option.

reviews round 1

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2017-01-24 15:41:37 +01:00
Dodji Seketeli
5aa38407ce Fix test-diff-pkg after commit 2dcc606
The runtestdiffpkg test has wrong paths to the spice-server packages.

Fixed thus.

	* tests/test-diff-pkg.cc (in_out_specs): Fix paths to spice-server
	packages.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2017-01-20 15:47:16 +01:00
Dodji Seketeli
499f598907 Add --harmless option to abipkgdiff
This option that is present for the abidiff tool was missing for
abipkgdiff.

	* doc/manuals/abidiff.rst: Fix a typo.
	* doc/manuals/abipkgdiff.rst: Document the --harmless option.
	* tools/abipkgdiff.cc: Update copyright year.
	(options::show_harmless_changes): Add new data member.
	(options::options): Initialize the new data member.
	(display_usage): Add a help string for the new --harmless option.
	(parse_command_line): Parse the new --harmless option.
	(set_diff_context_from_opts): Configure the diff context
	accordingly, if the user provided the --harmless option.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2017-01-20 11:04:27 +01:00
Dodji Seketeli
2dcc6062f2 Fix suppression category propagation in diff node graph
Under certain circumstances, a diff node (which we shall name N) that
belongs to the SUPPRESSED_CATEGORY category sees its belonging to that
category been propagated to its parent diff node, effectively
suppressing that parent diff node as well.  This is how some function
diff nodes ends up being suppressed just because some of their
children diff nodes were suppressed.

This suppression category propagation is performed by a pass that
walks the diff nodes graph.  To avoid infinite cycles, the pass avoids
visiting a diff node that is equivalent to a node that has already
been visited.

As a result, diff nodes equivalent to N (the class of equivalence of
N) are not traversed by the propagation pass.  So their parent diff
nodes are not suppressed.

This leads to some functions not being suppressed as they should.
This phenomenon can be observed by comparing the two packages that are
provided in the regression test accompanying this patch using
abipkgdiff with the --redundant option.

Here is how the patch addresses the issue.

When the suppression category propagation pass considers a parent diff
node (named P) of a node N' (with N' being equivalent to N), it now
looks at the category of the *class of equivalence of N'* to determine
if that category should be propagated to P.

Previously, that pass would just look at the at the category of N'
(not the category of the class of equivalence of N') for the
propagation.  But as N' has not been visited (because N has already
been visited and nodes equivalent to N are thus not visited) the
belonging of N' to the SUPPRESSED_CATEGORY hasn't been updated.  So N'
isn't marked as being in SUPPRESSED_CATEGORY.  So the
SUPPRESSED_CATEGORY wouldn't be propagated to P as it should.

So, with this patch abipkgdiff invoked with the --redundant option now
correctly yields:

$ abipkgdiff --redundant --d1 spice-debuginfo-0.12.4-19.el7.x86_64.rpm --d2 spice-debuginfo-0.12.8-1.el7.x86_64.rpm --devel1 spice-server-devel-0.12.4-19.el7.x86_64.rpm --devel2 spice-server-devel-0.12.8-1.el7.x86_64.rpm spice-server-0.12.4-19.el7.x86_64.rpm spice-server-0.12.8-1.el7.x86_64.rpm
================ changes of 'libspice-server.so.1.8.0'===============
  Functions changes summary: 1 Removed, 2 Changed (62 filtered out), 8 Added functions
  Variables changes summary: 0 Removed, 0 Changed, 0 Added variable

[...]

  2 functions with some indirect sub-type change:

    [C]'function spice_image_compression_t spice_server_get_image_compression(SpiceServer*)' at reds.c:3618:1 has some indirect sub-type changes:
      return type changed:
        underlying type 'enum __anonymous_enum__' changed:
          type size hasn't changed
          7 enumerator deletions:
            '__anonymous_enum__::SPICE_IMAGE_COMPRESS_INVALID' value '0'
            '__anonymous_enum__::SPICE_IMAGE_COMPRESS_OFF' value '1'
            '__anonymous_enum__::SPICE_IMAGE_COMPRESS_AUTO_GLZ' value '2'
            '__anonymous_enum__::SPICE_IMAGE_COMPRESS_AUTO_LZ' value '3'
            '__anonymous_enum__::SPICE_IMAGE_COMPRESS_QUIC' value '4'
            '__anonymous_enum__::SPICE_IMAGE_COMPRESS_GLZ' value '5'
            '__anonymous_enum__::SPICE_IMAGE_COMPRESS_LZ' value '6'

          9 enumerator insertions:
            'SpiceImageCompression::SPICE_IMAGE_COMPRESSION_INVALID' value '0'
            'SpiceImageCompression::SPICE_IMAGE_COMPRESSION_OFF' value '1'
            'SpiceImageCompression::SPICE_IMAGE_COMPRESSION_AUTO_GLZ' value '2'
            'SpiceImageCompression::SPICE_IMAGE_COMPRESSION_AUTO_LZ' value '3'
            'SpiceImageCompression::SPICE_IMAGE_COMPRESSION_QUIC' value '4'
            'SpiceImageCompression::SPICE_IMAGE_COMPRESSION_GLZ' value '5'
            'SpiceImageCompression::SPICE_IMAGE_COMPRESSION_LZ' value '6'
            'SpiceImageCompression::SPICE_IMAGE_COMPRESSION_LZ4' value '7'
            'SpiceImageCompression::SPICE_IMAGE_COMPRESSION_ENUM_END' value '8'

    [C]'function int spice_server_set_image_compression(SpiceServer*, spice_image_compression_t)' at reds.c:3602:1 has some indirect sub-type changes:
      parameter 2 of type 'typedef spice_image_compression_t' changed:
        underlying type 'enum __anonymous_enum__' changed:
          type size hasn't changed
          7 enumerator deletions:
            '__anonymous_enum__::SPICE_IMAGE_COMPRESS_INVALID' value '0'
            '__anonymous_enum__::SPICE_IMAGE_COMPRESS_OFF' value '1'
            '__anonymous_enum__::SPICE_IMAGE_COMPRESS_AUTO_GLZ' value '2'
            '__anonymous_enum__::SPICE_IMAGE_COMPRESS_AUTO_LZ' value '3'
            '__anonymous_enum__::SPICE_IMAGE_COMPRESS_QUIC' value '4'
            '__anonymous_enum__::SPICE_IMAGE_COMPRESS_GLZ' value '5'
            '__anonymous_enum__::SPICE_IMAGE_COMPRESS_LZ' value '6'

          9 enumerator insertions:
            'SpiceImageCompression::SPICE_IMAGE_COMPRESSION_INVALID' value '0'
            'SpiceImageCompression::SPICE_IMAGE_COMPRESSION_OFF' value '1'
            'SpiceImageCompression::SPICE_IMAGE_COMPRESSION_AUTO_GLZ' value '2'
            'SpiceImageCompression::SPICE_IMAGE_COMPRESSION_AUTO_LZ' value '3'
            'SpiceImageCompression::SPICE_IMAGE_COMPRESSION_QUIC' value '4'
            'SpiceImageCompression::SPICE_IMAGE_COMPRESSION_GLZ' value '5'
            'SpiceImageCompression::SPICE_IMAGE_COMPRESSION_LZ' value '6'
            'SpiceImageCompression::SPICE_IMAGE_COMPRESSION_LZ4' value '7'
            'SpiceImageCompression::SPICE_IMAGE_COMPRESSION_ENUM_END' value '8'

================ end of changes of 'libspice-server.so.1.8.0'===============

$

	* include/abg-comparison.h (diff::get_class_of_equiv_category):
	Declare new member function.
	* src/abg-comparison.cc: Update copyright year.
	(diff::get_class_of_equiv_category): Define new member function.
	(suppression_categorization_visitor::visit_end): When considering
	children nodes category for propagation, consider the category of
	the class of equivalence of children nodes.
	* spice-debuginfo-0.12.4-19.el7.x86_64.rpm: New input test package.
	* spice-debuginfo-0.12.8-1.el7.x86_64.rpm: Likewise.
	* spice-server-0.12.4-19.el7.x86_64.rpm: Likewise.
	* spice-server-0.12.8-1.el7.x86_64.rpm: Likewise.
	* spice-server-devel-0.12.4-19.el7.x86_64.rpm: Likewise.
	* spice-server-devel-0.12.8-1.el7.x86_64.rpm: Likewise.
	* spice-server-0.12.4-19.el7.x86_64-0.12.8-1.el7.x86_64-report-0.txt:
	New reference test output.
	* spice-server-0.12.4-19.el7.x86_64-0.12.8-1.el7.x86_64-report-1.txt: Likewise.
	* spice-server-0.12.4-19.el7.x86_64-0.12.8-1.el7.x86_64-report-2.txt: Likewise.
	* tests/data/Makefile.am: Add the new test material above to
	source distribution.
	* tests/test-diff-pkg.cc (in_out_specs): Add the new test inputs
	to the list of packages to test.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2017-01-20 10:59:58 +01:00
Dodji Seketeli
8ae81a8e16 Bug 21058 - abipkgdiff wrongly drops non-public types
When using abipkgdiff types that are defined in files not present in
the devel packages provided by the --devel1 and --devel2 option are
dropped from the internal representation by default.

This has been designed as such, not only to avoid showing changes on
types that are not part of the public headers of a shared library, but
also to help lower the memory consumption of libabigail.

In this particular bug report, we see a library that uses types (in
its public interface) that are defined in headers of a *different*
package.  For instance, suppose a particular package foo that uses
types defined in headers of the glib package.  And some of those Glib
types can be present in its public interface.

So in this case, libabigail is dropping a type that is actually part
of the public interface of the library that is being analyzed, even if
the type was not defined in the devel package of the current package.

This patch addresses the issue by doing a number of things:

    1/ If a type is defined in a file which path starts with
    "/usr/include/", then consider it as a public type.  This is so
    that type coming from the public interface of other packages, and
    that are defined in system headers are considered as part of the
    public types of the package being analyzed.

    2/ by default, don't drop types not defined in the associated
    devel package.  This will hinder our ability to decrease the
    memory usage, but there have been a number of recent optimization
    that help in that regard independently.  So I am hoping this
    shouldn't have a big impact now.

    Incidentally, the option --dont-drop-private-types (from abidiff)
    is changed into --drop-private-types, so that interested users can
    still drop non-private types from the model, if they wish.  That
    --drop-private-types option is added to abipkgdiff too.

As the offended types are not dropped from the model anymore, the
usual filtering mechanisms of libabigail can take place.

	* doc/manuals/abidiff.rst (--dont-drop-private-types): Remove documentation.
	(--drop-private-types): Document this new option.
	* src/abg-tools-utils.cc: Update copyright notice
	(handle_fts_entry): On the generated suppression specification, do
	not set the flag to drop matched types.  Also, don't match types
	defined in files which patch start with "/usr/include/".
	* tools/abidiff.cc (options::options): Initialize the
	drop_private_types data member to false.
	(display_usage): Remove usage string for
	--dont-drop-private-types.  Add a new one for
	--drop-private-types.
	(parse_command_line): Don't part --dont-drop-private-types,
	rather, parse --drop-private-types.
	(set_suppressions): When the suppression for private types is
	generated, if --drop-private-types was provided, then instruct the
	suppression to drop matched types.
	* tools/abipkgdiff.cc (options::drop_private_types): New option.
	(options::options): Initialize the new drop_private_types data
	member to false.
	(display_usage): Add a usage string for --drop-private-types.
	(parse_command_line): Parse the new --drop-private-types option.
	(maybe_create_private_types_suppressions): Don't take just a
	package, but a package_descriptor because the latter carries the
	options.  So when the user used the --drop-private-types option,
	make the generated private types suppression to drop matched
	types.
	* tests/data/test-diff-pkg/tbb-4.1-9.20130314.fc22.x86_64--tbb-4.3-3.20141204.fc23.x86_64-report-1.txt:
	Adjust.
	* tests/test-diff-suppr.cc (in_out_specs): Likewise.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2017-01-18 10:14:02 +01:00
Dodji Seketeli
fd7e0083db Fix some include logic in abg-suppression.cc
* src/abg-suppression.cc: Update copyright notice. Fix include
	files logic.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2017-01-18 10:11:38 +01:00
Dodji Seketeli
a821154753 Support virtual member functions with vtable offset not yet set
When reading C++ class informatin DWARF, it can happen that a given
virtual member function does not yet have a vtable offset.  Right now,
that offset is set to zero.  Just like a virtual member function which
actual vtable offset is zero.  So we don't make a difference between a
virtual function with no vtable offset and a virtual function with a
vtable offset set to zero.

This can lead to confusions during class comparison.

This patch fixes that problem by setting the default vtable offset to
-1.  So whenever a vtable offset is -1 it means that the virtual
member function doesn't yet have a vtable offset.

	* include/abg-fwd.h (member_function_has_vtable_offset): Declare
	new function.
	(get_member_function_vtable_offset): Return a ssize_t, not a
	size_t.
	(set_member_function_vtable_offset): Take a ssize_t, not a size_t.
	* include/abg-ir.h (class_decl::virtual_mem_fn_map_type): Adjust
	the map typedef to make it take ssize_t as the type of the key.
	(mem_fn_context_rel::vtable_offset_in_bits_): Make this data
	member be of ssize_t type, not size_t.
	(mem_fn_context_rel::mem_fn_context_rel): Initialize the
	vtable_offset_in_bits_ data member to -1.
	* src/abg-ir.cc (member_function_has_vtable_offset): Define new
	function.
	(get_member_function_vtable_offset): Return a ssize_t, not a
	size_t.
	(set_member_function_vtable_offset): Take a ssize_t, not a size_t.
	* src/abg-dwarf-reader.cc (die_virtual_function_index): Take an
	int64_t& rather than a uint64_t&.
	(finish_member_function_reading): Don't set the vtable offset if
	it's -1.
	* src/abg-reader.cc (build_class_decl): Likewise.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2017-01-16 21:00:56 +01:00
Dodji Seketeli
c6666f5176 [comparison engine] Don't crash when the context is null
* src/abg-comparison.cc
	(RETURN_IF_BEING_REPORTED_OR_WAS_REPORTED_EARLIER): Guard against
	null context.
	(diff::is_filtered_out): Likewise.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2017-01-16 21:00:56 +01:00
Dodji Seketeli
a7b6999602 [dwarf reader] Don't abort when trying to canonicalize a non-type
maybe_canonicalize_type is too strict when given a non type.  In that
case, it should just return, not abort.

	* src/abg-dwarf-reader.cc (maybe_canonicalize_type): Don't abort
	when trying to canonicalize a decl.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2017-01-16 21:00:56 +01:00
Dodji Seketeli
970248b5ed [dwarf reader] properly separate function decls and types in lookup
We were sometimes forgetting to properly add some types to the lookup
maps as such.  Instead, the types were added as if they were decls,
leading to later type lookup to fail.

Fixed thus.

	* src/abg-dwarf-reader.cc
	(read_context::associate_die_to_artifact_by_repr_internal):
	Choose the right type of representation depending on if we are
	associating a type or a decl.
	* tests/data/test-diff-filter/test31-pr18535-libstdc++-report-0.txt: Adjust.
	* tests/data/test-diff-filter/test31-pr18535-libstdc++-report-1.txt: Adjust.
	* tests/data/test-read-dwarf/test10-pr18818-gcc.so.abi: Adjust.
	* tests/data/test-read-dwarf/test11-pr18828.so.abi: Adjust.
	* tests/data/test-read-dwarf/test12-pr18844.so.abi: Adjust.
	* tests/data/test-read-dwarf/test13-pr18894.so.abi: Adjust.
	* tests/data/test-read-dwarf/test14-pr18893.so.abi: Adjust.
	* tests/data/test-read-dwarf/test15-pr18892.so.abi: Adjust.
	* tests/data/test-read-dwarf/test16-pr18904.so.abi: Adjust.
	* tests/data/test-read-dwarf/test17-pr19027.so.abi: Adjust.
	* tests/data/test-read-dwarf/test18-pr19037-libvtkRenderingLIC-6.1.so.abi:
	Adjust.
	* tests/data/test-read-dwarf/test19-pr19023-libtcmalloc_and_profiler.so.abi:
	Adjust.
	* tests/data/test-read-dwarf/test20-pr19025-libvtkParallelCore-6.1.so.abi:
	Adjust.
	* tests/data/test-read-dwarf/test21-pr19092.so.abi: Adjust.
	* tests/data/test-read-dwarf/test22-pr19097-libstdc++.so.6.0.17.so.abi:
	Adjust.
	* tests/data/test-read-dwarf/test9-pr18818-clang.so.abi: Adjust.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2017-01-16 21:00:54 +01:00
Dodji Seketeli
45e6599334 [dwarf reader] Allow updating and de-duplicating member functions
We forget to register member functions for lookup (by DWARF DIE
representation).  So member functions are not correctly found (by
lookup) and thus are not properly de-duplicated or updated.

	* src/abg-dwarf-reader.cc (add_or_update_class_type): Register
	member functions for lookup by member function DIE representation.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2017-01-16 21:00:54 +01:00
Dodji Seketeli
2421bcc877 [dwarf reader] Do not over de-duplicate function *definitions*
When a function needs to be completed, we sometimes wrongly
try to de-duplicate rather than just complete it.

	* src/abg-dwarf-reader.cc
	(build_or_get_fn_decl_if_not_suppressed): Do try to de-duplicate a
	function if it's to be completed.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2017-01-16 21:00:54 +01:00
Dodji Seketeli
78c26e6a23 [dwarf reader] Fix pretty printing static methods from DWARF
When pretty printing static methods from DWARF, we were forgetting the
first parameter for static methods.

	* src/abg-dwarf-reader.cc
	(die_return_and_parm_names_from_fn_type_die): Take a new
	'is_static' parameter.
	(die_qualified_type_name, die_pretty_print_type): Adjust calling
	die_return_and_parm_names_from_fn_type_die.
	(die_function_signature): Likewise.  Also, do not forget to print
	the first parameter for a static method.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2017-01-16 21:00:54 +01:00
Dodji Seketeli
9136c6a639 Handle several virtual member functions having the same vtable offset
In the DWARF for C++, it can happens that a virtual constructor leads
to several (up to 3) destructor functions that all have the same
vtable offset.  That vtable offset is the same as the offset of the
virtual destructor that the user actually defined in her source code.

This patch adds a map data structure to the private data of
class_decl.  That map associates a vtable offset X to a vector of
virtual member functions that have the same vtable offset X.

That new map is populated whenever a virtual member function is added
to the class.

	* include/abg-ir.h (class_or_union::virtual_mem_fn_map_type):
	Define new typedef.
	(class_decl::get_virtual_mem_fns_map): Declare new accessor.
	* src/abg-ir.cc (class_decl::priv::virtual_mem_fns_map_): New data
	member.
	(class_decl::get_virtual_mem_fns_map): Define new accessor.
	(fixup_virtual_member_function): Populate the new virtual member
	functions map.
	(class_decl::on_canonical_type_set): Sort the virtual member
	function vectors stored in the new virtual member functions map.
	(class_decl::add_member_function): Call
	set_member_function_is_virtual *after* calling
	set_member_function_vtable_offset because the former updates the
	virtual function map, so it needs the vtable offset.
	* src/abg-dwarf-reader.cc (finish_member_function_reading):
	Likewise.
	* src/abg-reader.cc (build_class_decl): Likewise.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2017-01-16 21:00:54 +01:00
Dodji Seketeli
367da46e7a Speed up pretty representing (function) types
During structural (function) type comparison, computing the pretty
representation of the type at hand appears high on performance profiles,
especially when type canonicalization wasn't really effective.

This patch adds a type_base::get_cached_pretty_representation() and a
function_type::get_cached_name() to cache the pretty representation of
a type, as well as the function type name.  This is way, the type
representation is computed just once and stored into a cache.
subsequent invocations of the function just look into the cache
instead of computing the representation again.

Note that we do this only for non-canonicalized types because these
types can still be modified, and so caching the representation of a
type that might be changed (and thus see its representation change)
leads to issue.  So the representation of non-canonicalized types is
not cached.

	* include/abg-ir.h (type_base::get_cached_pretty_representation):
	Declare new function.
	(function_type::get_cached_name): Likewise.
	* src/abg-ir.cc (get_method_type_name): Use the new
	type_base::get_cached_pretty_representation function.
	(type_base::priv::{internal_cached_repr_, cached_repr_}): Add new
	data members.
	(function_type::priv::{internal_cached_name_, cached_name_}):
	Likewise.
	(type_base::get_cached_pretty_representation): Define new
	function.
	(function_type::get_cached_name): Likewise.
	(type_base::get_canonical_type_for): Call
	type_base::get_cached_pretty_representation here, so the internal
	representation is cached right before canonicalization.
	(function_type::{mark_as_being_compared, unmark_as_being_compared,
	comparison_started}): Uset he new type_base::get_cached_name to
	speed up function type name retrieval.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2017-01-16 21:00:54 +01:00
Dodji Seketeli
b49119584b Add missing deep comparison operators for {function, method}_decl_sptr
It turned out we were missing deep comparison operators for smart
pointers to function_decl and method_decl.  Because of coming patches
that compare virtual member functions as part of comparing classes, we
need these deep comparison operators.

	* include/abg-ir.h (operator==): Declare two new overloads for
	function_decl_sptr an method_decl_sptr.
	* src/abg-ir.cc (operator==): Define two new overloads for
	function_decl_sptr an method_decl_sptr.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2017-01-16 21:00:54 +01:00
Dodji Seketeli
0af65e6364 Fix performance regression while analyzing libjvm.so
abidiff libjvm.so libjvm.so is taking forever in the master branch
these days.  At some point it was taking ~ 15 minutes and 15GB of RAM
on a non-optimized build.

Profiling of CPU usage showed that sorting virtual member
functions of a class whenever a new virtual member function is added
was the hot spot.

This patch now sorts virtual member functions once right after the
type was canonicalized.  The patch adds a virtual function
type_base::on_canonical_type_set() that is invoked right after the
canonical type is set for a given type.  class_decl gets its own
version of that virtual function: class_decl::on_canonical_type_set.
In that function, the patch does sort the virtual member functions of
the current class_decl.

Now with this patch, abidiff is still taking around 15 minutes but it
consumes less than 12GB of ram.  This means the memory consumption was
reduced by 20%.  abipkgdiff performs on 16:30 minutes and in less than
12GB of RAM as well.  All these times are measured on a non-optimized
build.

	* include/abg-ir.h ({type_base,
	class_decl}::on_canonical_type_set): Declare new virtual member
	function.
	* src/abg-ir.cc (type_base::on_canonical_type_set): Define new
	virtual member function that does nothing.
	(class_decl::on_canonical_type_set): Define new virtual member
	function that sorts the virtual member functions of class_decl.
	(canonicalize): Invoke type_base::on_canonical_type_set when the
	canonical type is set.
	(fixup_virtual_member_function): Don't sort virtual member
	functions here.
	* src/abg-dwarf-reader.cc (finish_member_function_reading): Do not
	sort virtual member functions here.
	* tests/data/test-read-dwarf/test13-pr18894.so.abi: Adjust.
	* tests/data/test-read-dwarf/test14-pr18893.so.abi: Adjust.
	* tests/data/test-read-dwarf/test15-pr18892.so.abi: Adjust.
	* tests/data/test-read-dwarf/test21-pr19092.so.abi: Adjust.
	* tests/data/test-read-dwarf/test22-pr19097-libstdc++.so.6.0.17.so.abi: Adjust.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2017-01-16 19:25:36 +01:00
Dodji Seketeli
9dc07f5534 Update copyright notice for abg-fwd.h, abg-ir.h and test-abidiff.cc
* include/abg-fwd.h: Adjust copyright.
	* include/abg-ir.h: Likewise.
	* tests/test-abidiff.cc: Likewise.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2017-01-16 15:36:20 +01:00
Dodji Seketeli
192c8d00ff Remove unused functions from abg-ir.cc
* src/abg-ir.cc (convert_node_to_decl): Remove specializations for
	class_decl_sptr, type_base_sptr and var_decl_sptr.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2017-01-16 08:57:55 +01:00
Dodji Seketeli
08e760221b Support Linux Kernel ABI whitelist files
Enterprise Linux (at least) kernels come with ABI whitelist files that list the
names of the set of functions to be considered when looking at the ABI
exposed by the kernel to its modules.

This patch adds a new --linux-kernel-abi-whitelist option to abidiff
so that it drops changes that relate to functions that are *NOT*
defined in the whitelist.

The patch reads the whitelist file and generates one or several
instances of function_suppression that are applied when the two
binaries are loaded.

	* include/abg-suppression.h
	(function_suppression::function_suppression): Make the declaration
	of the default constructor public.
	* src/abg-suppression-priv.h (function_suppression::priv::priv):
	Declare a default constructor.
	* src/abg-suppression.cc
	(function_suppression::function_suppression): Define default
	constructor.
	* include/abg-tools-utils.h
	(gen_suppr_spec_from_kernel_abi_whitelist): Declare new function.
	* src/abg-tools-utils.cc
	(gen_suppr_spec_from_kernel_abi_whitelist): Define new function.
	* tools/abidiff.cc (options::kernel_abi_whitelist_paths):
	(display_usage): Display a help string for the new
	--linux-kernel-abi-whitelist option.
	(parse_command_line): Parse the --linux-kernel-abi-whitelist from
	the command line.
	(maybe_check_suppression_files): Check the presence of the kernel
	abi whitelist files.
	(set_suppressions): Generate suppression specifications from the
	whitelist files.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2017-01-06 12:41:57 +01:00
Dodji Seketeli
fadfa1a6f6 Support Linux Kernel binaries
This patch teaches the ELF/DWARF reader of libabigail to load special
ELF sections that are specific to Linux Kernel binaries (either
vmlinux or linux kernel modules).

The patch creates a new flag that tells the ELF reader that it needs
to consider the input binary as a Linux Kernel binary.  This is the
new 'Linux Kernel mode'.

In this linux kernel mode, the reader expects sections that are named
__ksymtab and/or __ksymtab_gpl sections.  Those sections contain
indexes (of ELF symbols described in the normal ELF symbol table) of
exported ELF symbols that are specifically marked by developers using
EXPORT_SYMBOL or EXPORT_SYMBOL_GPL macros.  These are symbols of
global variables and functions defined and meant to be used by kernel
modules.  They constitute the interface exported by the Linux Kernel
to its modules.  So the patch only exports the publicly defined and
exported ELF symbols that are also listed in __ksymtab and
__ksymtab_gpl sections.

The patch also fixes and re-organizes things left and right so that
this new mode works in a well integrated manner with the other parts
of the reader:

  - The load address of the binary is no more assumed to be the load
    address specified by the program header that is at offset zero.
    This is usually the case for user-space programs.  To handle Linux
    Kernel binaries, the load address is now the one specified by the
    program header that is at the smallest offset.

  - The patch now tries to populate the various symbol maps only when
    necessary.  That way, the new symbol maps defined for the ksymtab
    and ksymtab_gpl section are also loaded only when necessary; that
    is, when in Linux Kernel mode.

  - The patch (more) agressively suppresses non-member functions or
    variables that are not declarations and that have no associated
    ELF symbol.

The patch knows how to recognize and read relevant ELF symbol
information from __ksymtab and __ksymtab_gpl sections.

The patch makes abidiff and abidw detect that a binary is a
Linux Kernel binary (either a vmlinux or a module).  It does this by
detecting the presence of the speciall __ksymtab_strings section.

If it detects that a binary is a Linux Kernel binary then it only
considers functions and variables which are defined and exported in
the sense of ELF *AND* which ELF symbols are listed in the __ksymtab
and __ksymtab_gpl sections.

If users want abidiff and abidw to consider their input binaries as
normal ELF binaries then they can use the option --no-linux-kernel-mode.

	* include/abg-dwarf-reader.h (create_read_context): Take a new
	flag to say if the context is to read an ELF binary in linux
	kernel mode.
	* src/abg-dwarf-reader.cc (typedef address_set_type)
	(address_set_sptr): New typedefs.
	(get_binary_load_address):  The load address of the binary is
	the load address specified by the program header that is at the
	smallest offset; not by the program header that is at offset zero.
	(read_context::{ksymtab_section_, ksymtab_gpl_section_,
	linux_exported_fn_syms_, linux_exported_var_syms_,
	linux_exported_gpl_fn_syms_, linux_exported_gpl_var_syms_,
	load_in_linux_kernel_mode_}): New data members.
	(read_context::read_context): Initialize ksymtab_section_,
	ksymtab_gpl_section_ and load_in_linux_kernel_mode_.
	(read_context::{find_symbol_table_section, find_opd_section,
	lookup_elf_fn_symbol_from_address,
	lookup_elf_var_symbol_from_address, get_function_address,
	get_variable_address}): Make these const.
	(read_context::{find_ksymtab_section, find_ksymtab_gpl_section,
	lookup_elf_symbol_from_address, function_symbol_is_exported,
	variable_symbol_is_exported, linux_exported_fn_syms,
	create_or_get_linux_exported_fn_syms, linux_exported_var_syms,
	create_or_get_linux_exported_var_syms, linux_exported_gpl_fn_syms,
	linux_exported_gpl_var_syms,
	create_or_get_linux_exported_gpl_fn_syms,
	linux_exported_gpl_var_syms,
	create_or_get_linux_exported_gpl_var_syms, architecture_word_size,
	load_kernel_symbol_table, load_ksymtab_symbols,
	load_ksymtab_gpl_symbols,
	load_linux_specific_exported_symbol_maps,
	load_in_linux_kernel_mode}): New member functions.
	(read_context::read_int_from_array_of_bytes): Factorize this
	new member function out of ...
	(read_context::{lookup_ppc64_elf_fn_entry_point_address}):
	... this.  Make this function const too.
	(read_context::read_uint64_from_array_of_bytes): New function.
	Uses read_int_from_array_of_bytes above.
	(read_context::{fun_entry_addr_sym_map_sptr}): Try to load symbol
	maps only when it's necessary.
	(read_context::elf_architecture_is_big_endian): Fix logic.
	(read_context::{var_addr_sym_map}):  Express the const variant in
	terms of the non-const one.  In the non-const one, load the map
	only when necessary.
	(read_context::load_symbol_maps_from_symtab_section): Renamed
	load_symbol_maps into this.
	(read_context::is_linux_kernel_binary): Define new member
	function.
	(read_context::{function, variable}_symbol_is_exported): If we are
	not prevented from considering loading in linux kernel mode, then
	just looking at a linux kernel binary makes us consider the
	special kernel sections.
	(read_debug_info_into_corpus): Likewise.
	(build_ir_node_from_die): Take a new flag that says if the ir node
	is a declaration required by another concrete IR node.
	(enum read_context::kernel_symbol_table_kind): New enum.
	(read_context::load_symbol_maps): Support loading linux kernel
	specific sections too.
	(build_var_decl): Use the new
	read_context::variable_symbol_is_exported.
	(function_is_suppressed): Suppress non-member functions or
	variables that are not declarations and that have no symbol.
	(variable_is_suppressed, build_var_decl_if_not_suppressed): Take a
	new flag that says if the variable is a declaration required by a
	concrete variable.  If non member variable that is a declaration
	is not the specification of another concrete variable, then it's
	suppressed.
	(add_fn_symbols_to_map, add_var_symbols_to_map): New function
	definitions.
	(read_debug_info_into_corpus): If we are reading linux kernel or
	linux kernel modules, only set explicitely exported symbols (in
	the linux kernel binary sense) as exported function or variable
	symbols.
	(create_read_context): Take a new flag to say if the context is to
	read an ELF binary in linux kernel mode.
	* tools/abidiff.cc (options::options): Initialize
	options::linux_kernel_mode to true.
	(display_usage): Display usage of the --no-linux-kernel-mode option.
	(parse_command_line): Parse the --no-linux-kernel-mode option.
	* tools/abidw.cc (options::options): Initialize
	options::linux_kernel_mode to true.
	(display_usage): Display usage of --no-linux-kernel-mode option.
	(parse_command_line): Parse the --no-linux-kernel-mode option.
	* doc/manuals/abidiff.rst: Document the new --no-linux-kernel-mode
	options.
	* doc/manuals/abidw.rst: Likewise.
	* tests/data/test-diff-dwarf-abixml/test0-pr19026-libvtkIOSQL-6.1.so.1.abi:
	Adjust.
	* tests/data/test-read-dwarf/test9-pr18818-clang.so.abi: Adjust.
	* tests/data/test-read-dwarf/test10-pr18818-gcc.so.abi: Adjust.
	* tests/data/test-read-dwarf/test11-pr18828.so.abi: Adjust.
	* 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/test17-pr19027.so.abi: Likewise.
	* tests/data/test-read-dwarf/test18-pr19037-libvtkRenderingLIC-6.1.so.abi:
	Likewise.
	* tests/data/test-read-dwarf/test19-pr19023-libtcmalloc_and_profiler.so.abi:
	Likewise.
	* tests/data/test-read-dwarf/test20-pr19025-libvtkParallelCore-6.1.so.abi:
	Likewise.
	* tests/data/test-read-dwarf/test21-pr19092.so.abi: Likewise.
	* tests/data/test-read-dwarf/test22-pr19097-libstdc++.so.6.0.17.so.abi: Likewise.
	* tests/data/test-read-dwarf/libtest23.so.abi: Adjust.
	* tests/data/test-read-dwarf/libtest24-drop-fns-2.so.abi: Adjust.
	* tests/data/test-read-dwarf/libtest24-drop-fns.so.abi: Adjust.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2017-01-06 12:35:22 +01:00
Dodji Seketeli
3d267a6fbf Add debug routines to dump locations to a stream
* src/abg-writer.cc (dump_location): Define new function and one
	overload.
	(dump_decl_location): Re-write in terms of the new dump_location.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2017-01-06 01:48:33 +01:00
Dodji Seketeli
7a313fc9c9 Better de-duplicate classes, unions, enums in non-odr contexts
When reading an ELF/DWARF binary that doesn't support the One
Definition Rule[1] (aka ODR), type de-duplication is done on a
per-translation unit basis only.  That means that a type definition
must be unique only in a given translation unit, in that case.

[1]: https://en.wikipedia.org/wiki/One_Definition_Rule

When handling big C binaries like the Linux Kernel, this implies a lot
of type duplication still, as the same type can be re-defined in a lot
of different translation units.

This patch tries to de-duplicate types on a per-corpus basis, even in
cases where the ODR doesn't apply.  It does so by noting that if two
types of the same kind and name are seen in two different translation
units and yet have the same source location (are defined in the same
spot) then they are the same type.

The patch does this for class, union and enum types as these seem to
be the kinds of types which are duplicated the most and thus consume
the most memory and later take the most time to canonicalize.  In a
subsequent patch, we might want to try to de-duplicate typedef types
too, and see if gain anything.

Comparing two linux kernels shows that with this patch, we come back
to a speed (and memory consumption) that is comparable to when we were
considering C-based binaries as being suited to our (too aggressive)
ODR-based type de-duplication algorithm.

Below are the output of the comparison measured with /usr/bin/time
with the aggressive ODR-based type de-duplication algorithm and with
this patch.  We compare the vmlinux binary coming from the package
kernel-3.10.0-515 against the one from kernel-3.10.0-327.el7.x86_64.
We use the kabi whitelists provided by the relevant
kernel-abi-whitelists packages for these kernels to restrict the
comparison to a meaningful subset of interfaces.

52.66user 0.64system 0:53.34elapsed 99%CPU (0avgtext+0avgdata 944416maxresident)k 0inputs+48outputs (0major+250750minor)pagefaults 0swaps

vs:

51.04user 0.87system 0:51.91elapsed 100%CPU (0avgtext+0avgdata 972560maxresident)k
0inputs+232outputs (0major+279983minor)pagefaults 0swaps

The full invocation and results are available at:

http://people.redhat.com/~dseketel/kabidiff/vmlinuz-3.10.0-327.el7.x86_64--vmlinuz-3.10.0-515.el7.x86_64.diff.whitelisted.with-unions.txt

vs

http://people.redhat.com/~dseketel/kabidiff/vmlinuz-3.10.0-327.el7.x86_64--vmlinuz-3.10.0-515.el7.x86_64.diff.whitelisted.with-unions.with-non-odr-support.txt

Note that to be able to compare the two kernels, the current tree must
contain the necessary patches that make libabigail understand Linux
Kernel binaries.

	* src/abg-dwarf-reader.cc (build_enum_type)
	(add_or_update_class_type, add_or_update_union_type): When the ODR
	is not relevant, use the location of the type to detect if two
	enum, class or union types of the same name actually represent the
	same type.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2017-01-06 01:43:57 +01:00
Dodji Seketeli
bdac61cc32 Adjust some reference outputs of the test-read-dwarf test harness
* tests/data/test-read-dwarf/test12-pr18844.so.abi: Adjust.
	* tests/data/test-read-dwarf/test9-pr18818-clang.so.abi: Adjust.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2017-01-06 01:41:09 +01:00
Ondrej Oprala
5aff747c5e Bug 18754 - Add the "--no-added-syms" option to abidiff
With this option, abidiff is now able to filter out added
symbols just like abipkgdiff is.

	* doc/manuals/abidiff.rst: Document the new --no-added-syms
	option.
        * tools/abidiff.cc (struct options): Add show_added_syms and
        set it to true by default.
        (display_usage): Document the new options --no-added-syms. If
        this is the only suppression option specified, it is equivalent
        to specifying --show_{changed,deleted}_{fns,vars} as arguments
        to abidiff. If any of those options are specified before
        --no-added-syms, then it has no effect.
        (parse_command_line): Parse the new option and set
	show_added_{fns,vars,syms} and show_all_{fns,vars} to false if
	--no-added-syms is specified.
        * tests/test-diff-filter.cc: Add a test for the new option.
        * tests/data/test-diff-filter/test35-pr18754-no-added-syms-report-0.txt:
        Reference results for the new test.
        * tests/data/test-diff-filter/test35-pr18754-no-added-syms-report-1.txt:
        Likewise.
        * tests/data/Makefile.am: Add the above test files to the list of
        test data.

Signed-off-by: Ondrej Oprala <ondrej.oprala@gmail.com>
Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2017-01-05 13:44:25 +01:00
Dodji Seketeli
d198b27b64 Update copyright year on a bunch of files
* include/abg-corpus.h: Update copyright year to 2017.
	* src/abg-dwarf-reader.cc: Likewise.
	* src/abg-ir.cc: Likewise.
	* src/abg-reader.cc: Likewise.
	* src/abg-writer.cc: Likewise.
	* tools/abicompat.cc: Likewise.
	* tools/abidw.cc: Likewise.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2017-01-05 12:51:49 +01:00
Dodji Seketeli
bf138a22c3 [apidoc] Allow brief description at the top of class description pages
* doc/api/libabigail.doxy: Don't disable "brief member desc".

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2017-01-05 12:51:38 +01:00
Dodji Seketeli
4063dfe487 Misc style fixes
* include/abg-corpus.h: Remove corpus_sptr typedef. It's in
	abg-fwd.h now.
	* src/abg-ir.cc: Remove some unnecessary vertical space.
	* src/abg-reader.cc (build_function_decl): Cleanup some asserts.
	* src/abg-writer.cc (write_function_type): Each the inspection of
	the type id from within the debugger.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2017-01-05 12:51:30 +01:00
Dodji Seketeli
2d53328bf4 Misc comments and apidoc fixes
* src/abg-dwarf-reader.cc (lookup_symbol_from_gnu_hash_tab): Fix
	typo in comment.
	* tools/abicompat.cc (perform_compat_check_in_weak_mode): Better
	comments.
	* tools/abidw.cc (dislay_usage): Fix white spaces.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>

Conflicts:
	tools/abidw.cc
2017-01-05 12:51:08 +01:00
Dodji Seketeli
b23abed949 Speedup set_member_is_static
set_member_is_static dominates some performance profile because that
function compares data members before their types are canonicalizing.
This means the comparison is done structurally.  So it's potentially
super long.

This patch fixes the issue by comparing data members by just looking at
their names, and that should be enough.

	* src/abg-ir.cc (set_member_is_static): When comparing data
	members, consider only their names.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2017-01-05 12:47:20 +01:00
Dodji Seketeli
b8452d2d59 Avoid unnecessary updates to type lookup maps
In class_or_union::set_is_declaration_only we should update the type
lookup maps only when a class type that was previously a
declaration-only type is now a defined type.  Otherwise, updating the type
lookup maps is unnecessary and profiling shows that it takes a
significant amount of time.

This patch does away with the unnecessary attempts to update type
lookup maps.

	* src/abg-ir.cc (class_or_union::get_is_declaration_only): Try
          to update the type maps only when a declaration-only class
          type is now defined.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2017-01-05 12:47:20 +01:00
Dodji Seketeli
7c004d6922 Update tests/data/test-read-dwarf/*.abi files
After the preceding patch series to handle ABI corpora in which the
ODR is not applicable (and the inevitable fallouts) this patch updates
the reference output for the test-read-dwarf test harness.

	* tests/data/test-read-dwarf/test10-pr18818-gcc.so.abi: Adjust.
	* 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/test17-pr19027.so.abi: Likewise.
	* tests/data/test-read-dwarf/test18-pr19037-libvtkRenderingLIC-6.1.so.abi: Likewise.
	* tests/data/test-read-dwarf/test19-pr19023-libtcmalloc_and_profiler.so.abi: Likewise.
	* tests/data/test-read-dwarf/test20-pr19025-libvtkParallelCore-6.1.so.abi: Likewise.
	* tests/data/test-read-dwarf/test21-pr19092.so.abi: Likewise.
	* tests/data/test-read-dwarf/test22-pr19097-libstdc++.so.6.0.17.so.abi: Likewise.
	* tests/data/test-read-dwarf/test9-pr18818-clang.so.abi: Likewise.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2017-01-05 12:39:41 +01:00
Dodji Seketeli
f88dbad75d Update tests/data/test-diff-dwarf-abixml/test0-pr19026-libvtkIOSQL-6.1.so.1.abi
After the preceding patch series to handle ABI corpora in which the
ODR is not applicable (and the inevitable fallouts) this patch updates
the reference output for the test-diff-dwarf-abixml test harness.

	* tests/data/test-diff-dwarf-abixml/test0-pr19026-libvtkIOSQL-6.1.so.1.abi:
	Update.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2017-01-05 12:35:18 +01:00
Dodji Seketeli
ef3ecb295c [abixml writer] Make sure all function types are emitted
The abixml writer forgets to emit some function types that are only
referenced by other types.  Fixed thus.

Note that the necessary adjustment to reference outputs of abidw in
the regression test suite is not provided with this patch to ease
backporting.  Those adjustments are in a patch that comes at the end
of this patch series.

	* src/abg-writer.cc (write_translation_unit): Fix logic to avoid
	forgetting referenced function types.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2017-01-05 12:26:20 +01:00
Dodji Seketeli
f4a4794f29 [abixml writer] Fix comparison of pointer to types
When two type pointers designate two types with the same pretty
printed representatin don't already have an associated type id, the
comparison code was mistakenly associating them with empty type id.

This patch fixes that.

Note that the necessary adjustment to reference outputs of abidw in
the regression test suite is not provided with this patch to ease
backporting.  Those adjustments are in a patch that comes at the end
of this patch series.

	* src/abg-writer.cc (type_ptr_comp::operator()): Do not add an
	empty type id string to the type -> type id map when the entry for
	a given type is empty.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2017-01-05 12:26:20 +01:00
Dodji Seketeli
2e3a4dfb67 [dwarf-reader] Don't early canonicalize function types
Make sure we don't early-canonicalize function types.  We need to wait
after the end of building the ABI corpus before canonicalizing these.

Normally this should be taken care of by using
type_has_non_canonicalized_subtype but there are cases where that
function does not detect that a type has sub-types that are not
canonicalized.

Fixed thus.

	* src/abg-dwarf-reader.cc (maybe_canonicalize_type):
	Late-canonicalize function types.

signed-off-by: Dodji Seketeli <dodji@redhat.com>
2017-01-05 12:26:20 +01:00
Dodji Seketeli
ab37f767b7 Fix qualified name caching for some types
When ::get_qualified_name() is invoked for some types, the value is
cached for performance reasons.

One thing to keep in mind is that the structure of a type can change
between the time when the type is first built and the time when it's
canonicalized.  This is because the type can be built progressively,
with sub-types being added over time until the type is fully built.
Then it can be canonicalized.

So if ::get_qualified_name is invoked on a non-canonicalized type and
the result is cached, then that result might not reflect the state of
the type *after* its canonicalized.  So the cached value might be
wrong.

To address that issue, the solution is to *not* cache the result of
::get_qualified_name() until the type is canonicalized.  After the
type is canonicalized and so we know the structur of the type won't
change, then the result of ::get_qualified_name is cached.

And this is what this patch does for qualified, pointer and array
types.

Note that the necessary update to the regression test suite is not
provided with this patch.  It's provided by a separate patch at the
end of the current series of patches.

	* src/abg-ir.cc ({qualified, pointer,
	array}_type_def::get_qualified_name): Don't cache internal and
	non-internal qualified name when the type is not canonicalized.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2017-01-05 12:26:20 +01:00
Dodji Seketeli
bf62a050c7 Cleanup ODR-based type canonicalization optimization gating logic
During type canonicalization we use an ODR-based optimization which
consists of saying that if two types of the same kind have the same
name and are defined in the same ABI corpus, then they are the same
type -- whithout needing to actually perform a structural comparison
of both types.  This speeds up type canonicalization greatly for types
that are duplicated in the ABI corpus.

The condition to apply that ODR-based optimization is basically that
the binary we are looking at must be in C++.

This patch just makes that condition clearer.

	* src/abg-ir.cc (type_base::get_canonical_type_for): Make it clear
	that the ODR-based optimization is allowed only on C++ ABI
	corpora.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2017-01-05 12:26:20 +01:00
Dodji Seketeli
6734da6a04 Fix a typo in method name computation
It turns out we forget a "return" keyword when we want to return the
name of a method.  Ooops.

Fixed thus.

Please note that this patch doesn't come with its necessary update to
the tests/data/test-read-dwarf/test9-pr18818-clang.so.abi and
tests/data/test-read-dwarf/test22-pr19097-libstdc++.so.6.0.17.so.abi
files.  Those updates to regression tests are coming in a subsequent
patch.

	* src/abg-ir.cc (get_method_type_name): Really return the method
	name.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2017-01-05 12:26:20 +01:00
Dodji Seketeli
e95f8cbac2 Update tests/data/test-diff-pkg/libICE-1.0.6-1.el6.x86_64.rpm--libICE-1.0.9-2.el7.x86_64.rpm-report-0.txt
After the preceding patch series to handle ABI corpora in which the
ODR is not applicable (and the inevitable fallouts) this patch updates
the reference output for the test-diff-pkg test harness.

	* tests/data/test-diff-pkg/libICE-1.0.6-1.el6.x86_64.rpm--libICE-1.0.9-2.el7.x86_64.rpm-report-0.txt: Adjust.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2017-01-05 12:23:39 +01:00
Dodji Seketeli
772414848e Update tests/data/test-read-write/test27.xml
After the preceding patch series to handle ABI corpora in which the
ODR is not applicable (and the inevitable fallouts) this patch updates
the reference output for the test-read-write test harness.

	* tests/data/test-read-write/test27.xml: Adjust.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2017-01-05 12:22:54 +01:00
Dodji Seketeli
1fcdebe47a [dwarf-reader] Handle per translation-unit type de-duplication
Until now, when the elf/dwarf reader builds ABI artifacts, it performs
type de-duplication by considering that a type with a given name should
be defined only once in a given ABI corpus.  This is per-corpus
de-duplication.

The problem with that approach is that it assumes that the binary
respects the One Definition Rule[1], aka ODR.  But then many non-C++
binaries don't respect the ODR.

So, for non-c++ binaries, we shouldn't assume the ODR.  We should be
able to assume a per translation unit (aka per-tu) de-duplication.
That is, consider that a type with a given name is defined just once
in a given translation unit.  Or perform no de-deplication at all,
depending on the kind of type we are looking at.

And this is what this patch does.  It allows the ELF/DWARF reader to
perform per-tu type de-duplication by assuming that it's only in a given
translation unit that a type definition must be unique.  It also allows it
perform no de-duplication at all for some kind of types.

In practice, function types are de-duplicated on a per-tu basis if ODR
is not relevant, otherwise, they are de-duplicated on a per-corpus
basis when ODR is relevant.

For most of the other types, if ODR is not relevant, then no
de-duplication is performed at all.  Otherwise, for these types, if
ODR is relevant, per-corpus de-duplication is performed.

	* src/abg-dwarf-reader.cc
	(read_context::per_tu_name_artefacts_map_): New data member.
	(read_context::clear_per_translation_unit_data): Clear the new
	read_context::per_tu_name_artefacts_map_.
	(read_context::associate_die_to_decl): Take a flag to say if we
	should associate a DIE to its representation and another one to
	say if the association should be done per-tu or per-corpus.
	(read_context::lookup_{type_artifact, artifact}_from_die): Update
	apidoc.
	(read_context::lookup_artifact_from_die_representation): Likewise.
	(read_context::{associate_die_to_artifact_by_repr,
	associate_die_to_artifact_by_repr_internal,
	associate_die_to_type}): Take a flag to say if the associating
	should be done on a per-tu basis.
	(read_context::lookup_{type_artifact, artifact}_from_die_per_tu):
	New member functions.
	(read_context::{lookup_artifact_from_per_tu_die_representation,
	odr_is_relevant}): Likewise.
	(build_enum_type, add_or_update_class_type)
	(add_or_update_union_type): If ODR is not relevant, do not perform
	per-corpus de-duplication.
	(build_pointer_type_def, build_typedef_type): Do not associate the
	type to its representation as these kinds of typs are not
	de-duplicated.
	(build_function_type):  If ODR is not relevant, perform per-tu
	de-duplication.  When ODR is relevant, per-corpus de-duplication
	is performed.
	(build_or_get_fn_decl_if_not_suppressed): Function decls are
	always de-duplicated per-corpus.
	(build_ir_node_from_die): For data members, do not update the die
	representation map as data members are not de-duplicated.  Do not
	do it for function decls either.

[1]: https://en.wikipedia.org/wiki/One_Definition_Rule

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2017-01-05 12:18:33 +01:00
Dodji Seketeli
c495a5c5f0 Handle per translation unit and per corpus types maps
Today, whenever a type is added to its scope, a map that associates
the qualified type name to the type is updated.  There is only one
such map in a given ABI corpus.

So whenever a type is looked up from its name, it's that per-corpus
type map that is used.

This setup makes libabigail type lookup be tailored only for binaries
that respect the One Definition Rule of C++[1] (aka ODR) which
basically says that there should be only one type of a given name in
an ABI corpus.

It turns out that many binaries, especically C binaries, don't respect
the ODR.  So a type "struct foo" can be defined in a file a.c and
another *different* type "struct foo" can also be defined in b.c.
What a useful and safe feature! Not.

For those binaries, just having one type map doesn't work.  We need to
have one type map per translation unit, and one map per-corpus map.

This is the strategy implemented by this patch.

With this patch, whenever a type is added to its scope, a
per translation unit type map is updated.  The per corpus map is
updated as well.  If there are more than one type of a given name, the
entry in the per corpus type map for that type is left empty.

Type lookup now potentially becomes a two phases lookup.  Whenever a
type is looked up from its name, the per corpus type map is looked at
first.  If the type is not in that per corpus type map, then the per
translation unit type maps are lookup up, in sequence.

The patch thus re-visits the type maps updating and lookup routines to
adapt them to the new scheme.  The patch also updates the clients of
the type map updating and lookup code.

Note that this patch is part of a series of patches which aims to move
libabigails away from its ODR-centric organization to make it work
well also on binary where the ODR is not relevant.  As such, the patch
doesn't assure that "make check" passes.  To have "make check" pass,
you need to have all the patches of the series applied.

[1]: https://en.wikipedia.org/wiki/One_Definition_Rule

	* include/abg-fwd.h (lookup_type_in_corpus): Remove.  This is to
	be replaced by the new lookup_type below.
	(lookup_{basic, class, union, enum, typedef, qualified, pointer,
	reference, array, function, class_or_typedef,
	class_typedef_or_enum}_type):
	(lookup_class_type_through_scopes, lookup_type)
	(lookup_type_through_scopes, lookup_or_synthesize_fn_type)
	* src/abg-ir-priv.h (struct translation_unit::priv):  Move this
	private type here, from abg-ir.h.
	(synthesize_type_from_translation_unit): Declare new functions.
	* include/abg-ir.h (class type_maps): Define new type.
	(translation_unit::get_function_types): Remove.
	(translation_unit::get_types): Now return a type_maps.
	(translation_unit::get_live_fn_types): Declare new type.
	(class decl_base): Make canonicalize be a friend of this class.
	* src/abg-ir.cc (struct translation_unit::priv): Move this to
	abg-ir-priv.h
	(struct type_maps::priv): Define new type.
	(type_maps::{basic, class, union, enum, typedef, qualified,
	pointer, reference, array, function}_types): Define new accessors.
	(translation_unit::bind_function_type_life_time): Adjust.
	(translation_unit::get_function_types): Remove accessor.
	(translation_unit::get_types, get_live_fn_types): Define new
	accessors.
	(lookup_type_in_translation_unit)
	(lookup_class_type_in_translation_unit)
	(lookup_function_type_in_translation_unit)
	(synthesize_type_from_translation_unit)
	(synthesize_function_type_from_translation_unit)
	(lookup_class_type_in_translation_unit) Remove function
	definitions.
	(lookup_type_in_map): Define function template.
	(lookup_{basic, class, union, typedef, class_or_typedef,
	class_typedef_or_enum, qualified, pointer, reference, array,
	function}_type): Define functions.
	(lookup_function_type, lookup_type_through_scopes)
	(lookup_class_type_through_scopes)
	(lookup_basic_type_through_translation_units)
	(lookup_union_type_through_translation_units)
	(lookup_enum_type_through_translation_units)
	(lookup_class_type_through_translation_units)
	(lookup_typedef_type_through_translation_units)
	(lookup_qualified_type_through_translation_units)
	(lookup_pointer_type_through_translation_units)
	(lookup_reference_type_through_translation_units)
	(lookup_array_type_through_translation_units)
	(lookup_function_type_through_translation_units)
	(lookup_type_through_translation_units)
	(lookup_or_synthesize_fn_type, lookup_type): Likewise.
	(maybe_update_types_lookup_map)
	(maybe_update_types_lookup_map<class_decl>)
	(maybe_update_types_lookup_map<function_type>): Define function
	template, specilizations and functions.
	(synthesize_type_from_translation_unit)
	(synthesize_function_type_from_translation_unit): Define
	functions.
	* include/abg-corpus.h (corpus::get_types): Declare new accessor.
	* src/abg-corpus.cc (corpus::priv::get_types): Define new
	accessor.
	(corpus::get_types): Likewise.
	(lookup_type_in_corpus, lookup_class_type_in_corpus)
	(lookup_type_in_corpus, lookup_function_type_in_corpus)
	(maybe_update_types_lookup_map)
	(maybe_update_types_lookup_map<class_decl>)
	(maybe_update_types_lookup_map<function_type>): Remove.
	(lookup_{basic, class, union, enum, typedef, qualified, pointer,
	reference, array, function, class_or_typedef,
	class_typedef_or_enum}_type): Likewise.
	* src/abg-corpus-priv.h (corpus::priv::{basic, class, union,
	typedef, qualified, pointer, reference, array, function}_types):
	Remove these data members.
	(corpus::priv::get_scopes): Remove member function.
	(corpus::priv::get_{basic, class, union, enum, typedef, qualified,
	pointer, reference, array, function}_types): Remove member
	function declarations.
	(corpus::priv::types_): New data member.
	(corpus::priv::get_types): Declare new member function.
	(lookup_{basic, class, enum, typedef, class_or_typedef, qualified,
	pointer, reference, array, function}_type): Declare new functions.
	* src/abg-dwarf-reader.cc
	(read_context::resolve_declaration_only_classes)
	(build_translation_unit_and_add_to_ir): Adjust use of
	lookup_class_type.
	* src/abg-reader.cc (read_context::type_is_from_translation_unit):
	Adjust to the use of lookup_function_type_in_translation_unit that
	got renamed into lookup_function_type.
	* src/abg-writer.cc (type_ptr_cmp::operator()): New operator
	implementation.
	(read_context::sort_type): Add new overloads.
	(write_translation_unit): Adjust to get the function types from
	the new translation_unit::get_live_fn_types and sort them.
	* tools/abicompat.cc (perform_compat_check_in_weak_mode): Adjust
	to use the new lookup_or_synthesize_fn_type, in lieu of
	lookup_function_type_in_corpus.  Adjust to use lookup_type in lieu
	of lookup_type_in_corpus.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2017-01-05 12:18:33 +01:00
Dodji Seketeli
bca3f9d163 Make abg-fwd.h use *_sptr typedefs
Until now, the abg-fwd.h where the necessary forward generic
declarations where put didn't contain the convenience typedefs of the
form foo_sptr that designate a shared pointer to type foo.

This patch moves these convenience typedefs as well as the missing
forward declarations from abg-ir.h to abg-fwd.h.  The patch also
adjusts the function declarations in abg-fwd.h to make them use these
convenience typedefs.

	* include/abg-ir.h: Move convience typedef declarations and some
	necessary forward declarations to ...
	* include/abg-fwd.h: ... here.
	(is_enum_type, is_var_decl): Take a pointer to type_or_decl_base.
	(lookup_type_in_scope): Return a type_base_sptr.
	(lookup_type_through_scopes): Introduce this to later replace the
	overload of lookup_type_in_translation_unit that takes a list of
	strings.
	(lookup_type_in_scope): Return a type_base_sptr, not a
	decl_base_sptr.
	* src/abg-ir.cc (lookup_type_in_scope, lookup_node_in_scope)
	(lookup_var_decl_in_scope): Adjust.
	(is_enum_type, is_var_decl): Take a pointer to type_or_decl_base.
	(lookup_node_in_scope): Return a type_or_decl_base_sptr.
	(lookup_type_in_scope): Return a type_base_sptr.
	(lookup_node_in_translation_unit): Return a
	type_or_decl_base_sptr.
	(lookup_type_through_scopes): Replace
	lookup_type_in_translation_unit.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2017-01-05 12:18:32 +01:00
Chenxiong Qi
6167026544 Fix wrong variable name
* tools/fedabipkgdiff: (diff_latest_rpms_based_on_distros): Fix
	wrong variable name distro.

Signed-off-by: Chenxiong Qi <cqi@redhat.com>
2016-12-19 12:31:02 +01:00
Chenxiong Qi
a028c1735d Warn properly when cannot find peer RPM
* tools/fedabipkgdiff: (RPMCollection.get_peer_rpm): Return None
	when cannot find peer RPM due to nonexistent arch.

Signed-off-by: Chenxiong Qi <cqi@redhat.com>
2016-12-19 12:30:18 +01:00
Chenxiong Qi
f8ca17190b Read Koji config via Koji API
Besides reading Koji config via Koji API read_config, option --topdir is
also renamed to --topurl that is the correct one should be used.

	* tools/fedabipkgdiff: Read DEFAULT_KOJI_TOPURL and
	DEFAULT_KOJI_SERVER from Koji config via Koji API read_config.
	(build_commandline_args_parser): --topdir is renamed to
	--topurl.
	* doc/manuals/fedabipkgdiff.rst: Rename --topdir to --topurl.

Signed-off-by: Chenxiong Qi <cqi@redhat.com>
2016-12-19 12:29:22 +01:00
Chenxiong Qi
8ac5e078c5 Follow moved packages when download
This patch makes fedabipkgdiff able to follow the new place to download
packages.

	* tools/fedabipkgdiff: (download_rpm) Add --location to curl
	CLI.

Signed-off-by: Chenxiong Qi <cqi@redhat.com>
2016-12-19 12:28:55 +01:00
Chenxiong Qi
0011e5b0b6 More document for local RPMs comparison
* doc/manuals/fedabipkgdiff.rst: Add more document for local RPMs
	comparison. Also fixed a typo.

Signed-off-by: Chenxiong Qi <cqi@redhat.com>
2016-12-19 12:03:19 +01:00
Ondrej Oprala
ee00b09f21 Properly report missing files for abipkgdiff
Currently, if abipkgdiff is given a path to a nonexistent file,
it propagates all the way until package classification
and ends up being reported as "PKG should be a valid package file",
which doesn't hint it's not there at all.

        * tools/abipkgdiff.cc: (class options): Add the "nonexistent_file" flag
        (parse_command_line): Check if the files given exist.
        (main): Check the nonexistent_file flag. If any of the input
        files don't exist, report it and exit. Also, for present and future test
        uniformity, only show the base names of the packages when using their
        names in error output.
        * tests/test-diff-pkg.cc: Add a new regression test.
        * tests/data/test-diff-pkg/test-nonexistent-report-0.txt: The
        expected output of the above regression test.
        * tests/data/Makefile.am: Add the above file to the list.

Signed-off-by: Ondrej Oprala <ondrej.oprala@gmail.com>
2016-12-15 20:16:01 +01:00