platform/upstream/libabigail.git
8 years agoAdd a NEWS file
Dodji Seketeli [Tue, 5 Jan 2016 11:31:09 +0000 (12:31 +0100)]
Add a NEWS file

* NEWS: New file.
* Makefile.am: Add NEWS file to source distribution.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
8 years agoBug 19355 - Libabigail slow on r300_dri.so
Dodji Seketeli [Mon, 4 Jan 2016 16:47:19 +0000 (17:47 +0100)]
Bug 19355 - Libabigail slow on r300_dri.so

Profiling abidw --abidiff r300_dri.so, with a r30_dri.so that was run
through dwz shows that a great deal of the time is spent in trying to
get the logical parent of a DIE which has been imported.

To do that, we need to walk the translation unit DIEs again to know
where the DIE we are looking at has been imported.  And doing that
walking again and again, following the accessors of the DIE data
structure from elfutils takes time.

This patch reduces that time by constructing a "trace" of where units
have been imported.  So that looking for the logical parent of a given
DIE doesn't involve walking the DIE tree itself, but rather, walking
the trace, which is a vector.  This proves to be much faster.

In practice, the overall time spent is now less than 12 minutes.  It
was more than 50 minutes before.

* src/abg-dwarf-reader.cc (struct imported_unit_point): Define new
type.
(operator<(const imported_unit_point&, const
imported_unit_point&)): Define less-than operator for new
imported_unit_point& type.
(imported_unit_points_type, tu_die_imported_unit_points_map_type):
New typedefs.
(find_lower_bound_in_imported_unit_points): Define new static function.
(read_context::tu_die_imported_unit_points_map_): New data member.
(read_context::tu_die_imported_unit_points_map): New getter.
(die_die_attribute): Define new overload.
(build_die_parent_relations_under): Take imported_unit_points_type
output parameter and populate it along the way. Remove the
overload that takes a read_context as a parameter.
(build_primary_die_parent_relations_under)
(build_alternate_die_parent_relations_under): Remove.
(build_die_parent_maps): Pass an instance of
imported_unit_points_type to build_die_parent_relations_under.
(find_import_unit_point_between_dies): Rename one overload of
find_last_import_unit_point_before_die into this.  Adjust to make
it find the import point between two offsets.
(find_import_unit_point_before_die): Rename the other overload of
find_last_import_unit_point_before_die into this. Adjust to use
find_import_unit_point_between_dies.
(get_parent_die): Adjust to use find_import_unit_point_before_die.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
8 years agoSupport two different variables having the same underlying symbol
Dodji Seketeli [Mon, 4 Jan 2016 16:15:05 +0000 (17:15 +0100)]
Support two different variables having the same underlying symbol

Sometimes, two different variables A and B can have the same underlying
symbol, when for instance A is a reference that is initialized with
the address of B.

Until now, that was not supported by libabigail's ABI corpus.  Only
one (either A or B) variable is kept.  This is because the ID of the
variable, as returned by abigail::var_decl::get_id() is made of the
symbol name of the variable only.

This patch fixes the issue by including the name of the variable in
the ID.

* src/abg-ir.cc (var_decl::get_id()): Include the name of the
variable in the ID.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
8 years agoAvoid adding the same base class twice
Dodji Seketeli [Mon, 4 Jan 2016 15:48:33 +0000 (16:48 +0100)]
Avoid adding the same base class twice

When looking at bug
https://sourceware.org/bugzilla/show_bug.cgi?id=19355, it appears that
some class have the same base class more than once.

Here is why.

Sometime in the DWARF, a given class is declared briefly, and then
later, it's amended.  Sometimes, when the class is updated, the debug
info contains redundant information, like base classes that were
previously expressed, and which are expressed again in the updated
version of the class.  The DWARF reader needs to not add that
duplicated information.

It appears the DWARF reader fails to recognize redundant base class
specifiers.  The native xml reader which is supposed to recognize
those, has some logic error that prevents it from working correctly.

This patch fixes both the DWARF and native xml readers.

The patch has no test because the r300_dri.so binary is really big and
still takes too much time to process, for it to be a practical
candidate for the regression test suite.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
8 years agoSpeed up class_decl::find_base_class
Dodji Seketeli [Mon, 4 Jan 2016 14:36:54 +0000 (15:36 +0100)]
Speed up class_decl::find_base_class

This is useful for big debug info data set.  Also, this function is
going to be used extensively in subsequent patch that fixes a base
class representation related issue.

* src/abg-ir.cc (class_decl::priv::bases_map_): New data member.
(class_decl::add_base_specifier): Add the new base specifier to
the new class_decl::priv::bases_map_ data member.
(class_decl::find_base_class): Use the new
class_decl::priv::bases_map_ data member to speed up finding the
base class.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
8 years agoMake class_decl::base_spec class follow the pimpl pattern
Dodji Seketeli [Mon, 4 Jan 2016 13:48:36 +0000 (14:48 +0100)]
Make class_decl::base_spec class follow the pimpl pattern

* include/abg-ir.h (class_decl::base_spec::priv): Declare new
private data type.
(class_decl::base_spec::priv_): Declare new pimpl data member.
(class_decl::base_spec::{base_class_, offset_in_bits_,
is_virtual_}): Remove.
(class_decl::base_spec::{get_base_class, get_is_virtual,
get_offset_in_bits}): Make these member functions out of line.
* src/abg-ir.cc (struct class_decl::base_spec::priv): New type.
(class_decl::base_spec::{get_base_class, get_is_virtual,
get_offset_in_bits}): Define these functions here.
(class_decl::base_spec::base_spec): Adjust because now there is
only one pimpl data member to initialize.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
8 years agoAdd the option of printing the file, line and column information about a type being...
Ondrej Oprala [Mon, 16 Nov 2015 09:55:28 +0000 (10:55 +0100)]
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>
8 years agoFix a function doc
Ondrej Oprala [Mon, 16 Nov 2015 09:55:27 +0000 (10:55 +0100)]
Fix a function doc

* src/abg-ir.cc: (location_manager::expand_location): Fix a factual
error in the function documentation.

Signed-off-by: Ondrej Oprala <ooprala@redhat.com>
8 years ago[PERF] Speedup comparing declaration-only class_decls
Dodji Seketeli [Fri, 11 Dec 2015 10:14:06 +0000 (11:14 +0100)]
[PERF] Speedup comparing declaration-only class_decls

The structural comparison of declaration-only class_decl has show up
high on performance profiles while running abidw --abidiff on the
r300_dri.so binary.

The class_decl::get_is_declaration_only() function seems to be used
too many times.  The copying of the qualified name of the class_decl
showed up too.  Also, it looks like that the != operator on string is
slightly slower than than the == operator; OK, this is while looking
at a binary without optimizations, but still.

So the patch addresses the specific issues above.

* src/abg-ir.cc (equals): In the overload for class_decl, avoid
calling class_decl::get_is_declaration_only() several times.
Avoid copying the qualified name of the class_decl.  Also, use the
== operator to compare strings, rather than the != one.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
8 years ago[PERF] Access naked pointers for canonical types and function types
Dodji Seketeli [Fri, 11 Dec 2015 09:45:05 +0000 (10:45 +0100)]
[PERF] Access naked pointers for canonical types and function types

Performance profiling has shown that accessing shared_ptr to canonical
types and function type during type comparison was noticeable slowing
down the process.  This patch thus access naked pointers for canonical
types and function types at these performance hot spots.

The profiling took place while running abidw --abidiff on the
r300_dri.so binary.

* include/abg-ir.h (type_base::get_naked_canonical_type): Declare
new accessor.
(function_decl::get_naked_canonical_type): Likewise.
(function_decl::set_type): Pass a reference to the shared_ptr.
* src/abg-ir.cc (type_base::priv::naked_canonical_type): New data
member.
(type_base::priv::priv): Initialize it.
(canonicalize): Set the naked canonicalize type when we set its
shared pointer.
(type_base::get_naked_canonical_type): Define new accessor.
({pointer_type_def,reference_type_def,function_type,class_decl}::operator==):
Use naked canonical pointers rather than the slower shared_ptr to
canonical pointers.
(function_decl::priv::naked_type_): New data member.
(function_decl::priv::priv): Initialize it.
(function_decl::get_naked_type): Define new accessor.
(function_decl::set_type): Pass a reference to the shared_ptr .
(equals): In the overload for function_decl, use the faster naked
pointers to the type of the function.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
8 years ago[PERF] Turn some pimpl pointers into naked pointers
Dodji Seketeli [Fri, 11 Dec 2015 09:33:28 +0000 (10:33 +0100)]
[PERF] Turn some pimpl pointers into naked pointers

The private data pointers of libabigail IR types are usually managed
using shared_ptr.  But performance profiling has shown that
de-referencing some of these private data shared_ptr can have a
noticeable performance impact.  This is because de-referencing
shared_ptr involves some locking that show up on some performance
profile.

So, for decl_base, type_base, and function_decl, this patch replaces
the private data shared pointers by naked pointers.  This speeds up
the access to private data members, especially during comparison of
class pointer, reference and function types.  And that has a
noticeable impact when libabigail handles huge binaries with lots of
functions an type, like r300_dri.so.

* include/abg-ir.h ({decl_base, type_base, function_decl}::priv_)
Make this a naked pointer to priv, rather than a shared_ptr<priv>.
* src/abg-ir.cc (decl_base::~decl_base): Destroy the private data
pointer, aka pimpl pointer.
(type_base::~type_base): Likewise.
(function_decl::~function_decl): Likewise.
(class_decl::~class_decl): Likewise.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
8 years ago[PERF] Pass a bunch of perf-sensitive smart pointers by reference
Dodji Seketeli [Fri, 11 Dec 2015 08:57:36 +0000 (09:57 +0100)]
[PERF] Pass a bunch of perf-sensitive smart pointers by reference

* include/abg-fwd.h (lookup_type_in_corpus, lookup_type_in_scope)
(lookup_var_decl_in_scope): Pass the decls smart pointers by
reference.
* src/abg-ir.cc (lookup_type_in_corpus, lookup_type_in_scope)
(lookup_var_decl_in_scope): Pass the decls smart pointers by
reference, for performance reasons.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
8 years agoBug 19126 - abidw segv on a dwz compressed version of r300_dri.so
Dodji Seketeli [Thu, 10 Dec 2015 13:18:46 +0000 (14:18 +0100)]
Bug 19126 - abidw segv on a dwz compressed version of r300_dri.so

Suppose a declaration D (which locus is in a file F) is imported at an
offset offset of O1 into a compilation unit C1 and at an offset O2
(using DW_TAG_imported_unit) into a compilation unit C2.

When the DWARF reader creates the ABI artifact for D in O1, its
location is encoded by a location manager that is handled by C1.

At O2 (in C2) the ABI artifact for D (created at O1, in C1) is
re-used.  But then, to decode the location of D, the DWARF reader
wrongly uses the location manager that is handled by C2.  It should
use the location manager of C1, because that is the one used to encode
the location of D.

It picks the wrong location manager because it picks the wrong
translation unit for D. Right now, the translation unit for a given
declaration is the "current" translation unit at the moment the DIE
was being inspected.  And that is wrong when imported type units kick
in.

1/ More generally, each ABI artifact should be associated with its
translation unit, which is the current translation unit when the
artifact was created.  As there is just one copy of D, its translation
unit should always be the same.

2/ Also, the location should ensure that about the location manager used
to encode it is the same one used to decode it, so that this kind of
bug cannot arise.

This patch fixes the issue by doing 1/ and 2/.  The r300_dri.so test
case on which is was failing is not added to the test suite because
it's too big.  It was taking more than 55 minutes to have complete
abidw --abidiff complete on that binary, on my machine.  So I am going
to work on the performance side of things, I think.

* include/abg-ir.h (class location_manager): Forward declare it
before class location.
(location::loc_manager_): New data member.
(location::location): Take the location manager in one overload
and initialize the new loc_managers_ in all the overloads.
(location::get_location_manager): New getter.
(location::expand): New member function.
(location::*): Add API doc to all entry points.
(location_manager::expand_location): Take a const location.
(type_or_decl_base::set_corpus): Remove.
(type_or_decl_base::{get,set}_translation): New accessors.
(decl_base::{decl_base,get_location}): Take or return a reference
on location.
(scope_decl::scope_decl): Likewise.
(type_decl::type_decl): Likewise.
(namespace_decl::namespace_decl): Likewise.
(qualified_type_def::qualified_type_def): Likewise.
(pointer_type_def::pointer_type_def): Likewise.
(reference_type_def::reference_type_def): Likewise.
(array_type_def::subrange_type::{subrange_type,
get_location}): Likewise.
(enum_type_decl::enum_type_decl): Likewise.
(typedef_decl::typedef_decl): Likewise.
(var_decl::var_decl): Likewise.
(function_decl::function_decl): Likewise.
(function_decl::parameter::parameter): Likewise.
(template_decl::template_decl): Likewise.
(type_tparameter::type_tparameter): Likewise.
(non_type_tparameter::non_type_tparameter): Likewise.
(function_tdecl::function_tdecl): Likewise.
(class_tdecl::class_tdecl): Likewise.
(class_decl::class_decl): Likewise.
(class_decl::method_decl::method_decl): Likewise.
* src/abg-ir.cc (location::expand_location): Define new member
function.
(type_or_decl_base::priv::corpus_): Remove.
(type_or_decl_base::priv::translation_unit_): New data member.
(type_or_decl_base::priv::priv): Adjust.
(type_or_decl_base::set_corpus): Remove.
(type_or_decl_base::get_corpus): Adjust.
(type_or_decl_base::{get,set}_translation_unit): New member
functions.
(decl_base::priv::priv): Take a reference to location.
(decl_base::decl_base): Likewise.
(decl_base::get_location): Return a reference to location.
(location_manager::create_new_location): Adjust.
(location_manager::expand_location): Take a reference to location.
(translation_unit::get_global_scope()): Adjust.
(translation_unit::bind_function_type_life_time): Likewise.
(scope_decl::{add,insert}_member_decl): Adjust.
(get_translation_unit): Likewise.
(type_decl::type_decl): Take a reference to location.
(namespace_decl::namespace_decl): Likewise.
(qualified_type_def::qualified_type_def): Likewise.
(pointer_type_def::pointer_type_def): Likewise.
(reference_type_def::reference_type_def): Likewise.
(array_type_def::subrange_type::priv::priv): Likewise.
(array_type_def::subrange_type::{subrange_type,
get_location}): Likewise.
(enum_type_decl::enum_type_decl): Likewise.
(typedef_decl::typedef_decl): Likewise.
(var_decl::var_decl): Likewise.
(function_decl::function_decl): Likewise.
(function_decl::parameter::parameter): Likewise.
(template_decl::template_decl): Likewise.
(type_tparameter::type_tparameter): Likewise.
(non_type_tparameter::non_type_tparameter): Likewise.
(function_tdecl::function_tdecl): Likewise.
(class_tdecl::class_tdecl): Likewise.
(class_decl::class_decl): Likewise.
(class_decl::method_decl::method_decl): Likewise.
* src/abg-writer.cc (write_location): Take a reference to
location and adjust.
(write_array_type_def, write_function_decl, dump_decl_location):
Adjust.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
8 years agoFix some white space nits
Dodji Seketeli [Tue, 8 Dec 2015 11:53:24 +0000 (12:53 +0100)]
Fix some white space nits

* src/abg-comparison.cc (class_diff::report): Remove a useless
horizontal white space.
* src/abg-ir.cc (operator==): Add a vertical space.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
8 years agoFilter out harmless diagnostics glitches due to some ODR violation
Dodji Seketeli [Tue, 8 Dec 2015 11:38:13 +0000 (12:38 +0100)]
Filter out harmless diagnostics glitches due to some ODR violation

Suppose we have tree types which have the same name A.  The first A
comes from a binary B1 and the two others come from a binary B2.
Let's call them A{B1}{1}, A{B2}{1} and A{B2}{2}.

Suppose A{B1}{1} is different from A{B2}{1} (but both types are
compatible), just because one of their sub-types are different but are
compatible. So A{B1}{1} and A{B2}{1} are canonically different; they
have different canonical types.

But then, because of the One Definition Rule (ODR), A{B2}{1} and
A{B2}{2} are canonically equal.  But then let's suppose that A{B2}{2}
is structurally equal to A{B1}{1}.  So this implies that A{B1}{1} and
A{B2}{2} are canonically different, while being structurally equal.

Odd, but not impossible.  I noticed this while comparing the two
versions of libgromacs_d.so.0.0.0 involved in the comparison
referenced by bug https://bugzilla.redhat.com/show_bug.cgi?id=1283906.
But then that library is too big (and takes too much time) to be
included as a non regression test :(

Anyway, this patch detects this glitch and categorizes it so that the
resulting ABI change reports are filtered out.  Otherwise, this is
considered as an ABI change (because of the canonical different), for
which the reporter fails to provide details (because of the structural
equality).

* src/abg-comp-filter.cc
(class_diff_has_harmless_odr_violation_change): New static
function.
(harmless_filter::visit): Call it.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
8 years agoFix internal name for pointers, typedefs and arrays
Dodji Seketeli [Tue, 8 Dec 2015 11:19:57 +0000 (12:19 +0100)]
Fix internal name for pointers, typedefs and arrays

Internal names (and pretty representation) of types are used for type
canonicalization.  These were not being correctly computed for
pointers typedefs and arrays because we were forgetting sometimes to
use internal names of the underlying types, especially because of caching issues.

This patch addresses that.

Note that I noticed this while comparing the two versions of
libgromacs_d.so.0.0.0 involved in the comparison referenced by bug
https://bugzilla.redhat.com/show_bug.cgi?id=1283906.  But then that
library is too big (and takes too much time) to be included as a non
regression test :(

* include/abg-ir.h (pointer_type_def::priv_): New data structure.
The type is now pimpled.
(typedef_decl::priv_): Likewise.
* src/abg-ir.cc (struct pointer_type_def::priv): New struct.
(pointer_type_def::pointer_type_def): Adjust.
(pointer_type_def::get_pointed_to_type): Likewise.
(pointer_type_def::get_qualified_name): Store temporary/internal
names into different caches.
(array_type_def::priv::{temp_internal_qualified_name_,
internal_qualified_name_}): New data members.
(get_type_representation): In the overload for array_type_def,
take requests for internal names into account.
(array_type_def::get_qualified_name): Take requests for internal
names into account.  Store temporary/internal names into different
caches.
(typedef_decl::priv): New struct.
(typedef_decl::typedef_decl): Adjust.
(typedef_decl::get_underlying_type): Likewise.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
8 years agoAvoid try/catch code paths when that is possible
Dodji Seketeli [Tue, 8 Dec 2015 11:12:53 +0000 (12:12 +0100)]
Avoid try/catch code paths when that is possible

* src/abg-ir.cc (is_type, equals): Do not use try/catch based
dynamic_cast.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
8 years agoFix comparison in qualified_type_diff::has_changes
Dodji Seketeli [Tue, 8 Dec 2015 11:10:18 +0000 (12:10 +0100)]
Fix comparison in qualified_type_diff::has_changes

* src/abg-comparison.cc (qualified_type_diff::has_changes): Make
this stupid and simple, now that we have (fast) canonical type
based comparison.
* include/abg-ir.h (qualified_type_diff::operator==): Add an
overload for qualified_type_diff here.
(operator==): Likewise.
* src/abg-ir.cc (qualified_type_diff::operator==): Define it.
(operator==): Likewise.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
8 years agoBug 19336 - Better handle redundantly qualified reference types
Dodji Seketeli [Sun, 6 Dec 2015 17:54:02 +0000 (18:54 +0100)]
Bug 19336 - Better handle redundantly qualified reference types

Sometimes we can see const references in DWARF.  But then, a reference
is always const, so that qualified reference is redundant.
Furthermore, having that construct make its way into the internal
representation can cause awkward diagnostics.

The DWARF reader was thus eliding such redundant qualifiers in the
function "maybe_strip_qualification".  It was doing so by stripping
the qualifier from the qualified type. So const reference, for
instance, becomes a (non-qualified) reference.  In that case, we are
turning a qualified type into a non-qualified one.

But as the accompanying problem report suggests, this can cause issues
during the DWARF parsing.  This is because a given Debug Information
Entry (DIE) of qualified type kind can be referenced elsewhere, by
another type.  That other type expects that DIE to be a qualified
type.  And libabigail's DWARF reader code enforces that.  So the
internal representation of a type resulting from a qualified type DIE
must be a qualified type itself.

So the way the function "maybe_strip_qualification" was doing the
redundancy elision was wrong.  This patch fixes that by keeping the
type qualified, but introducing a "no-op" qualifier.  Actually, the IR
already has that "no-op" qualifier: abigail::ir::qualified_type_def::CV_NONE.

So now "maybe_strip_qualification" just turns the CV_CONST qualifier
into a CV_NONE one when the former is redundant.

Now that the libabigail type system actually *has* types qualified
with this no-op qualifier, we need to handle things like printing the
name of such qualified types.  When we are printing the name of the
type for internal reasons (i.e, for type canonicalization purposes) we
need to make a difference between the name of a no-op qualified type
and the name of the underlying type of the qualified type, otherwise,
the canonicalizer wrongly considers the two types as being equal.  But
then when we are printing the name of the no-op qualified type for
diagnostics reasons, then the name is the same as the name of its
underlying unqualified type.

* src/abg-dwarf-reader.cc (maybe_strip_qualification): Do not nuke
the qualified type.  Rather, just turn the redundant const
qualifier into a no-op one.
* src/abg-comparison.cc (compute_diff_for_types): Look through
no-op qualified types.
* include/abg-ir.h
(decl_base::{peek,set}_temporary_qualified_name): Declare new
accessors.
* src/abg-ir.cc (decl_base::priv::temporary_qualified_name_): New
data member.
(decl_base::{peek,set}_temporary_qualified_name): Define new
accessors.
(qualified_type_def::priv::{temporary_internal_name_,
internal_name}): New data members.
(qualified_type_def::build_name): For a no-op qualified type, the
internal name (which contains the 'none' qualifier) is different
from the non-internal name.
(qualified_type_def::get_qualified_name): Handle temporary names
and non-temporary names in two different caches.  Also handle
internal and non-internal names in two different caches.  This
makes four different caches.
(qualified_name_setter::do_update): Do not touch the non-internal,
non-temporary qualified name cache if the qualified parent name is
empty.
* tools/abidw.cc (main): change --check-alternate-debug-info to
make it *not* display the name/path to the alternate debug info,
when it's found.  Rather, only
--check-alternate-debug-info-base-name keeps displaying the base
name of the alternate debug info.
* tests/data/test-alt-dwarf-file/test1-libgromacs-debug-dir/*: New
test material.
* tests/data/Makefile.am: Add the new test material to the build
system.
* tests/test-alt-dwarf-file.cc (in_out_specs): Take the new test
input into account.
* tests/data/test-read-dwarf/test1.abi: Adjust.
* tests/data/test-read-dwarf/test7.so.abi: 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/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/test22-pr19097-libstdc++.so.6.0.17.so.abi:
Likewise.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
8 years agoDo not forget to peel qualified type off when peeling types
Dodji Seketeli [Sun, 6 Dec 2015 16:29:50 +0000 (17:29 +0100)]
Do not forget to peel qualified type off when peeling types

When peeling off typedefs, references and pointers to see if a type is
made of a class type, we forget to peel qualified types off.

This is in the context of parsing type info from DWARF and to
determine if we should delay type canonicalization (because a given
type is made of a class) or not.

Fixed thus.

* include/abg-fwd.h (peel_qualified_type): Declare new function
...
* src/abg-ir.cc (peel_qualified_type): ... and define it.
(peel_typedef_pointer_or_reference_type): Peel qualified types
here too.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
8 years agoFind more spots where to discriminate internal and non-internal names
Dodji Seketeli [Sun, 6 Dec 2015 16:19:00 +0000 (17:19 +0100)]
Find more spots where to discriminate internal and non-internal names

While looking at something else, I stumbled across spots where we
forget to discriminate between internal and non-internal type names.

This can lead to two types (that are equivalent) to be considered as
being different just because one is based on a struct foo, and the
other one is based on a class foo.

Fixed thus.

* src/abg-ir.cc (get_type_name, get_method_type_name)
({typedef_decl,var_decl,function_decl,class_decl}::get_pretty_representation):
Propagate the internal-ness to the call to get_qualified_name().

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
8 years agoConstify is_qualified_type()
Dodji Seketeli [Sun, 6 Dec 2015 16:12:43 +0000 (17:12 +0100)]
Constify is_qualified_type()

* include/abg-fwd.h (is_qualified_type): Make this take a const
parameter.
* src/abg-ir.cc (is_qualified_type): Likewise.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
8 years agoAdd missing new line to abidiff help message
Dodji Seketeli [Sat, 28 Nov 2015 09:06:05 +0000 (10:06 +0100)]
Add missing new line to abidiff help message

* tools/abidiff.cc (display_usage): Add missing new line.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
8 years agoDo not abort when there is no binary to compare in a package
Dodji Seketeli [Thu, 26 Nov 2015 08:50:51 +0000 (09:50 +0100)]
Do not abort when there is no binary to compare in a package

When given a package which has no binary to compare, abipkgdiff
aborts.  This patch fixes that.

* tests/data/test-diff-pkg/empty-pkg-libvirt-0.9.11.3-1.el7.ppc64.rpm:
New input test package.
* tests/data/test-diff-pkg/empty-pkg-libvirt-1.2.17-13.el7_2.2.ppc64.rpm:
Likewise.
* tests/data/test-diff-pkg/empty-pkg-report-0.txt: New test
reference output.
* data/Makefile.am: Add the new test material above to the build system.
* tests/test-diff-pkg.cc (int_out_specs): Add the new test inputs
to the set of tests.
* tools/abipkgdiff.cc (compare): Do not abort if there is no
binary to compare.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
8 years agoAbidiff: Remove doubled line in help.
Ondrej Oprala [Sat, 14 Nov 2015 17:08:35 +0000 (18:08 +0100)]
Abidiff: Remove doubled line in help.

* tools/abidiff.cc (display_usage): Remove a doubled help message.

Signed-off-by: Ondrej Oprala <ooprala@redhat.com>
8 years agoAdd bash-completion scripts for the libabigail tools
Ondrej Oprala [Sat, 14 Nov 2015 17:32:01 +0000 (18:32 +0100)]
Add bash-completion scripts for the libabigail tools

* Makefile.am: include bash-completion/Makefile.am
* bash-completion/Makefile.am: New makefile for the bash-completion
directory.
* bash-completion/abicompat: New completion script.
* bash-completion/abidiff: Likewise.
* bash-completion/abidw: Likewise.
* bash-completion/abilint: Likewise.
* bash-completion/abinilint: Likewise.
* bash-completion/abipkgdiff: Likewise.
* bash-completion/abisym: Likewise.
* configure.ac: Check for the bash-completion package. Handle
the new --enable-bash-completion[=WHEN] configure option.
* manuals/libabigail-tools.rst: Mention the scripts.

Signed-off-by: Ondrej Oprala <ooprala@redhat.com>
9 years agoRead enum values in the size_t and write them in ssize_t
Dodji Seketeli [Tue, 17 Nov 2015 15:01:23 +0000 (16:01 +0100)]
Read enum values in the size_t and write them in ssize_t

Make sure to read enum values in the widest possible integer (size_t)
but write them (in abixml writer) using a signed type to ease
comparison.

This makes the runtestreaddwarf pass on 32 bit x86, because we were
losing some precision reading enum values using a signed integer.

* include/abg-ir.h (enum_type_def::enumerator::get_value): Return
a size_t.
* src/abg-ir.cc (enum_type_decl::enumerator::get_value): Likewise.
* src/abg-dwarf-reader.cc (die_signed_constant_attribute): #if-out
this static function that is not used anymore.
(build_enum_type): Read the value of the enumerator using a size_t
value.
* src/abg-reader.cc (build_enum_type_decl): Read the enum value
using a long long int.
* src/abg-writer.cc (write_enum_type_decl): Write using a ssize_t.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
9 years agoBump version to release candidate 1.0.rc1
Dodji Seketeli [Tue, 17 Nov 2015 14:58:46 +0000 (15:58 +0100)]
Bump version to release candidate 1.0.rc1

* configure.ac: Bump version to release candidate 1.0.rc1

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
9 years agoDo not use designated initializers in abipkgdiff.cc
Dodji Seketeli [Tue, 17 Nov 2015 12:41:38 +0000 (13:41 +0100)]
Do not use designated initializers in abipkgdiff.cc

g++ 4.4.7 of el6 does not support designated initializers, so
libabigail fails to build on el6 for that reason.

* tools/abipkgdiff.cc (prepare_packages): Do not use designated
initializers syntax.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
9 years agoUpdate ChangeLog for 1.0.rc0 1.0.rc0
Dodji Seketeli [Mon, 16 Nov 2015 15:23:58 +0000 (16:23 +0100)]
Update ChangeLog for 1.0.rc0

* ChangeLog: Udpate using make update-changelog

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
9 years agoFix doxygen configuration file paths in doc/Makefile.am
Dodji Seketeli [Mon, 16 Nov 2015 15:20:36 +0000 (16:20 +0100)]
Fix doxygen configuration file paths in doc/Makefile.am

* doc/Makefile.am: There was an extra "/doc" in the path.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
9 years agoUpdate ChangeLog file in preparation of 1.0.rc0 release
Dodji Seketeli [Mon, 16 Nov 2015 11:55:54 +0000 (12:55 +0100)]
Update ChangeLog file in preparation of 1.0.rc0 release

* ChangeLog: Update using make update-changelog.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
9 years agoAdd --version option to several libabigail tools
Dodji Seketeli [Mon, 16 Nov 2015 10:39:15 +0000 (11:39 +0100)]
Add --version option to several libabigail tools

This patch changed the revision number of the libabigail library to
make it reflect the fact that we are not in "release candidate" mode,
before the first 1.0 release.  So the revision number is now "rc0".

The configuration manager has been updated to support version numbers
that are strings, so that it can supports things like "rc0".

Then, several libabigail tools have been modified to support the
--version option to display their version number.

* configure.ac: Set the version revision to "rc0".
* doc/manuals/abicompat.rst: Adjust manual for new --version
option.
* doc/manuals/abidiff.rst: Likewise.
* doc/manuals/abidw.rst: Likewise.
* doc/manuals/abilint.rst: Likewise.
* doc/manuals/abipkgdiff.rst: Likewise.
* include/abg-config.h (config::{m_format_minor, m_format_major}):
Make these be strings.
(config::{get,set}_format_minor_version_number): Make these return
strings.
(config::{get,set}_format_major_version_number): Make these return
or take strings.
(abigail_get_library_version): Make this take strings.
* src/abg-config.cc (config::config): Adjust.
(config::{get,set}_format_major_version_number): Make these return
or take strings.
(config::{get,set}_format_minor_version_number): Make these return
strings.
(abigail_get_library_version): Make this take strings.
* include/abg-version.h.in: Make the version variables be strings.
* src/abg-writer.cc (write_translation_unit): The version numbers
are now strings so adjust.
* tools/{abicompat,abidiff,abidw,abilint,abipkgdiff,abisym}.cc
(options::display_version): New data member.
(options::options): Initialize it.
(display_usage): Add documentation for new --version option.
(parse_command_line): Parse new --version option.
(main): Support --version.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
9 years agoCorrectly handle fn DIE with abstract_origin in alt debug info
Dodji Seketeli [Thu, 12 Nov 2015 12:44:59 +0000 (13:44 +0100)]
Correctly handle fn DIE with abstract_origin in alt debug info

When a function decl DIE is in the main DWARF file but has an abstract
origin that is in the alternate DWARF file, the dwarf reader
mistakenly considers the resulting function decl as being for a DIE
that is in the alternate DWARF file.

Fixed thus.

* src/abg-dwarf-reader.cc (build_ir_node_from_die): Consider that
the function decl is for a DIE in the alternate debug info file only if
the DIE itself comes from the alternate debug info file, not if
the specification or the origin of the function comes from the
alternate debug info file.
* tests/data/test-diff-pkg/qemu-img-rhev-2.3.0-20.el7.ppc64.rpm:
New test input rpm.
* tests/data/test-diff-pkg/qemu-img-rhev-2.3.0-7.el7.ppc64.rpm: Likewise.
* tests/data/test-diff-pkg/qemu-kvm-rhev-debuginfo-2.3.0-20.el7.ppc64.rpm: Likewise.
* tests/data/test-diff-pkg/qemu-kvm-rhev-debuginfo-2.3.0-7.el7.ppc64.rpm: Likewise.
* tests/data/test-diff-pkg/qemu-img-rhev-2.3.0-7.el7.ppc64--qemu-img-rhev-2.3.0-20.el7.ppc64-report-0.txt:
New test reference output.
* tests/data/Makefile.am: Add the new test material to the source
distribution.
* tests/test-diff-pkg.cc (in_out_specs): Use the new test rpm
inputs.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
9 years agoBug 19081 - abipkgdiff parallelization
Ondrej Oprala [Mon, 9 Nov 2015 10:02:45 +0000 (11:02 +0100)]
Bug 19081 - abipkgdiff parallelization

Abipkgdiff now attempts to extract packages and compare the resulting
ELF pairs in parallel. First off, a thread is spawned to extract each
package and each debuginfo package. After the ELF files are extracted,
mapped and the threads are successfully collected, the resulting
ELF vectors are traversed to identify existing pairs and a list of
arguments for future comparison is made. This list is then sorted
by size from largest to smallest. Unless --no-parallel is
specified on the command line, MIN(pairs,active_processors) threads
are spawned, sharing a single list of arguments. This list is
processed and a map of (ELF_PATH,DIFF_CORPUS) is created. Meanwhile,
the main thread checks this same map for results in the original order
of the ELF pairs, ensuring sequential output. After all the diffing
and reporting is done, the threads are collected again.

* doc/manuals/abipkgdiff.rst: Mention the new --no-parallel option.
* tools/Makefile.am: Add -pthread to abipkgdiffs link options.
* tools/abipkgdiff.cc (elf_file_paths_tls_key): New key for the
thread-local vector of ELF filepaths.
(reports_map): A map of the path of the first ELF of a compared pair
and a corpus representing the difference.
(env_map): A map of the corpus difference and a corresponding
environment needed to be kept alive until the diff is reported.
({arg,map}_lock): mutexes to control access to the comparison argument
list and the {reports,env}_map respectively.
(options): Add a new member "parallel" and set it to true in the ctor.
(elf_file): Add a new "size" member and set it in the ctor.
(package descriptor): Arguments passed to extract_package_set.
(compare_args): Arguments passed to the ELF comparison function.
(display_usage): Mention the new "--no-parallel" option.
(pthread_routine_extract_package): A wrapper function around
extract_package to be used in a multi-threaded environment.
({first_second}_package_tree_walker_callback_fn): Add the new ELF file
paths to a thread-specific vector.
(compare): In an overload of compare, verbose output is updated to
always mention the ELF files being compared for each reported stage.
Reporting is no longer done in this function, the resulting difference
is instead passed back to the calling function for reporting in the
main thread, along with a corresponding environment.
(pthread_routine_compare): Accept a pointer to a vector of comparison
arguments. This function is to be called NTHREAD times and share the
vector passed to it with its other invocations. Create the environment
for compare() and store its output in a map if there is a difference.
(create_maps_of_package_content): Allocate memory for a thread local
vector of ELF paths and dispose of it before returning.
(pthread_routine_extract_pkg_and_map_its_content): Renamed from
extract_package_and_map_its_content. Extract the debuginfo as well as
the regular package in this function. Spawn a separate thread for the
extraction of the debug package.
(pthread_join): A function handling thread joining throughout package
extractions.
(prepare_packages): Spawn a thread to extract each set of packages.
(elf_size_is_greater): New comparison function used to order ELF pairs
by size.
(compare): In the overload of compare, pass through the ELF path
vectors and identify pairs to be diffed. Put them in a vector and sort
it by the summed ELF pair size. Spawn comparison threads and safely
check for results in the proper order of the ELF pairs. Report any
differences ASAP and collect the threads after all the reporting is
done, checking their return status.
(parse_command_line): Check for the "--no-parallel" option.

Signed-off-by: Ondrej Oprala <ooprala@redhat.com>
9 years agoFix typo in test-diff-dwarf-abixml.cc
Dodji Seketeli [Tue, 10 Nov 2015 09:07:29 +0000 (10:07 +0100)]
Fix typo in test-diff-dwarf-abixml.cc

* tests/test-diff-dwarf-abixml.cc (main): Fix typo.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
9 years agoDocument abipkgdiff's option --no-abignore
Ondrej Oprala [Wed, 14 Oct 2015 15:34:11 +0000 (17:34 +0200)]
Document abipkgdiff's option --no-abignore

* doc/manuals/abipkgdiff.rst: Mention the new option.
* tools/abipkgdiff.cc: Likewise.

Signed-off-by: Ondrej Oprala <ooprala@redhat.com>
9 years agoAvoid canonicalizing function types too early
Dodji Seketeli [Mon, 9 Nov 2015 14:39:17 +0000 (15:39 +0100)]
Avoid canonicalizing function types too early

In the DWARF reader it can happen that a function type being built is
canonicalized too early, before the type is done building.  This leads
to some spurious type differences later at comparison time.  It
typically happens when a sub-type of the function type refers to the
function type itself.  We correctly handle similar cases for class
types, but not for function types.  Oops.

This patch handles this case for function types in the dwarf reader
and in the abixml reader.

* src/abg-dwarf-reader.cc (die_function_type_map_type): New
typedef.
*  ():
(read_context::die_wip_function_types_map_): New data member.
(read_context::{die_wip_function_types_map,
is_wip_function_type_die_offset}): New methods.
(build_function_type): Mark the function being built as "work in
progress".
(maybe_canonicalize_type): Do not early-canonicalize WIP function
types.
* src/abg-reader.cc (build_function_type): Mark the function being
built as "work in progress".
* tests/test-diff-dwarf-abixml.cc: New test harness.
* tests/Makefile.am: Add new test harness runtestdiffdwarfabixml
to the build system.
* tests/data/test-diff-dwarf-abixml/test0-pr19026-libvtkIOSQL-6.1.so.1:
New test binary input.
* tests/data/test-diff-dwarf-abixml/test0-pr19026-libvtkIOSQL-6.1.so.1.abi:
New test input.
* tests/data/Makefile.am: Add new test inputs to source
distribution.
* tests/data/test-read-dwarf/test17-pr19027.so.abi: Adjust.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
9 years agoPropagate environment property to base specifiers
Dodji Seketeli [Mon, 9 Nov 2015 13:22:25 +0000 (14:22 +0100)]
Propagate environment property to base specifiers

It appears that when setting a base class specifier for a given class,
the environment of the class is not propagated to the base specifier.

This patch fixes that.

* src/abg-comparison.cc (compute_diff): In the overload for
class_decl::base_spec_sptr, assert that the environment of the
base classes are equal and that the environment the base class is
the same as the environment of the base specifier.
* src/abg-ir.cc (add_base_specifier): Propagate the environment of
the class to its base specifiers.
* tests/data/test-types-stability/pr19026-libvtkIOSQL-6.1.so.1:
New test binary input.
* tests/data/Makefile.am: Add the new test input to the build
system.
* tests/test-types-stability.cc (elf_paths): Add new binary to the
test harness.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
9 years agoMisc style fixes
Dodji Seketeli [Mon, 9 Nov 2015 17:29:44 +0000 (18:29 +0100)]
Misc style fixes

Add missing spaces here and there.

* src/abg-comparison.cc (diff_context::mark_diff_as_visited): Add
missing space.
(corpus_diff::priv::ensure_lookup_tables_populated): Likewise.
* src/abg-dwarf-reader.cc (lookup_symbol_from_elf): Likewise.
(get_soname_of_elf_file, get_type_of_elf_file): Likewise.
* src/abg-ir.cc (var_decl::get_pretty_representation): Likewise.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
9 years agoSupport DW_AT_count DWARF attribute
Dodji Seketeli [Sat, 7 Nov 2015 21:52:10 +0000 (22:52 +0100)]
Support DW_AT_count DWARF attribute

Libabigail's DWARF reader does not support the DW_AT_count attribute
used to specify the number of elements in an array subrange.  Rather,
it uses the DW_AT_lower_bound and DW_AT_upper_bound attributes that
are emitted by GCC.  Recent versions of Clang, on the other hand, use
the DW_AT_count attribute.

This patch adds support for the DW_AT_count attribute too.

* src/abg-dwarf-reader.cc (get_default_array_lower_bound): Define
new static function.
(build_array_type): Support the DW_AT_count attribute.
* tests/data/test-diff-dwarf/test35-pr19173-libfoo-long-clang.so:
New test binary input.
* tests/data/test-diff-dwarf/test35-pr19173-libfoo-long-clang2.so: Likewise.
* tests/data/test-diff-dwarf/test35-pr19173-libfoo-long-clang-report-0.txt:
New test reference output.
* tests/data/test-diff-dwarf/test35-pr19173-libfoo-long-gcc.so:
New test binary input.
* tests/data/test-diff-dwarf/test35-pr19173-libfoo-long-gcc2.so:
New test binary input.
* tests/data/test-diff-dwarf/test35-pr19173-libfoo-long-gcc-report-0.txt:
New test reference output.
* tests/data/test-diff-dwarf/test35-pr19173-libfoo-long.c: Source
code for the binaries above.
* tests/data/Makefile.am: Add the new test material to the build
system.
* tests/test-diff-dwarf.cc (in_out_specs): Add the new test inputs
to the harness.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
9 years agoBug 19173 - Abidiff doesn't detect symbol size change in library
Dodji Seketeli [Sat, 7 Nov 2015 19:51:29 +0000 (20:51 +0100)]
Bug 19173 - Abidiff doesn't detect symbol size change in library

It appears that libabigail does not represent the size of ELF symbols,
so it doesn't detect when a symbol size changes without impacting the
size of the type of said symbol, as described by debug info.

It appears that Address Sanitizer as implemented by Clang does change
the size of variable symbols when it instruments those variables.  And
of course, the size of type of said symbols (as described by debug
information) remains unchanged.

This patch makes Libabigail become aware of symbol sizes, especially
for variables.  Symbol sizes for functions are ignored for now,
because a change in a function symbol size is not an ABI change.

The patch makes libabigail detect and report symbol size changes for
variables, but looking at the ELF information, independently from the
debug information.

The patch adjusts the existing tests and adds a new test using the
binaries that were filed in the bug report.

* include/abg-ir.h (elf_symbol::{elf_symbol, create}): Take a size
parameter.
(elf_symbol::{get,set}_size): New accessors.
* src/abg-ir.cc (elf_symbol::priv::size_): New data member.
(elf_symbol::priv::priv): Initialize it.
(elf_symbol::{elf_symbol, create}) Take a size parameter.
(textually_equals): Compare the size of variable symbols.
(elf_symbol::{get, set}_size): New accessors.
* src/abg-comparison.cc (maybe_report_diff_for_symbol): New static
function.
({function_decl_diff,var_diff}::report): Use it.
* src/abg-dwarf-reader.cc (lookup_symbol_from_sysv_hash_tab)
(lookup_symbol_from_gnu_hash_tab, lookup_symbol_from_symtab)
(read_context::lookup_elf_symbol_from_index): Set the size of the
elf symbols' internal representation.
* src/abg-reader.cc (build_elf_symbol): Read the size attribute if
present.
* src/abg-writer.cc (write_elf_symbol): Write the size attribute
for variable symbols, if it's not zero.
* tests/data/test-diff-dwarf/test34-pr19173-libfoo.so: New test
input binary.
* tests/data/test-diff-dwarf/test34-pr19173-libfoo2.so: Likewise.
* tests/data/test-diff-dwarf/test34-pr19173-libfoo-report-0.txt:
New reference test output.
* tests/data/Makefile.am: Add the new test input binaries to the
build system.
* tests/test-diff-dwarf.cc (in_out_specs): Add the new test input
above to the test harness.
* tests/data/test-diff-dwarf/test9-report.txt: Adjust.
* tests/data/test-diff-filter/test30-pr18904-rvalueref-report0.txt: Likewise.
* tests/data/test-read-dwarf/test0.abi: Likewise.
* tests/data/test-read-dwarf/test1.abi: 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/test15-pr18892.so.abi: Likewise.
* tests/data/test-read-dwarf/test16-pr18904.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/test6.so.abi: Likewise.
* tests/data/test-read-dwarf/test9-pr18818-clang.so.abi: Likewise.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
9 years agoAdd some needed vertical space
Dodji Seketeli [Sat, 7 Nov 2015 22:05:55 +0000 (23:05 +0100)]
Add some needed vertical space

* src/abg-dwarf-reader.cc (build_array_type): Add a new line after
this function.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
9 years agoPass a bunch of parameters by reference as they ought to be
Dodji Seketeli [Sat, 7 Nov 2015 22:04:01 +0000 (23:04 +0100)]
Pass a bunch of parameters by reference as they ought to be

* include/abg-ir.h (operator==): In the overload for
elf_symbol_sptr, pass the parameters by reference.
* src/abg-ir.cc (operator==): Do the same at definition site.
* src/abg-comparison.cc (maybe_report_diff_for_member): Pass
parameters by reference.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
9 years agoBug 19139 - DWARF reader doesn't handle garbage in function names
Dodji Seketeli [Thu, 5 Nov 2015 15:01:56 +0000 (16:01 +0100)]
Bug 19139 - DWARF reader doesn't handle garbage in function names

In this bug, the DWARF debug info of the binary (generated by Intel's
ICC compiler) has interesting constructs like:

     [ 6b5a0]    subprogram
 decl_line            (data2) 787
 decl_column          (data1) 15
 decl_file            (data1) 46
 declaration          (flag)
 accessibility        (data1) public (1)
 type                 (ref4) [ 6b56a]
 prototyped           (flag)
 name                 (string) "ldiv"
 MIPS_linkage_name    (string) "ldiv"
     [ 6b5b6]      formal_parameter
   type                 (ref4) [ 5f2aa]
   name                 (string) "$Ë2"
     [ 6b5bf]      formal_parameter
   type                 (ref4) [ 5f2aa]
   name                 (string) "$Ë3"

Note the strings that make up the name of the formal parameters of the
function, near the end:

     [ 6b5b6]      formal_parameter
   type                 (ref4) [ 5f2aa]
   name                 (string) "$Ë2"
     [ 6b5bf]      formal_parameter
   type                 (ref4) [ 5f2aa]
   name                 (string) "$Ë3"

The strings "$Ë2" and $Ë3" (which are the names of the
parameters of the function) are garbage.

Libabigail's DWARF reader naively uses those strings as names for the
function parameters, in the type of the function.

Then, the abixml writer emits an XML document, with these strings as
property values, representing the name of the type of the function.

And of course, the XML later chokes when it tries to read that XML
document, saying that the property is not valid UTF-8.

This patch addresses the issue by dropping those garbage names on the
floor, for function type names.  In that context, any string that is
not made of ASCII characters is considered as being garbage, for now.

The patch, in the abixml writer, also escapes function parameters
names so that they don't contain characters that are not allowed in
XML.  The abixml reader already handles the un-escaping of the names
it reads, so I think there is nothing to do there.

Ultimately, I guess I should get the unicode value of the characters
of that string, encode the string into UTF-8 and use the result as the
name for the parameter.  That would mean using UTF-8 strings for
function parameter names, and, for all declarations names.  But that
is too much for worfk too little gain for now.  The great majority of
the binaries we are dealing with are still using ASCII for declaration
names.

The patch also introduces a new test harness that runs "abidw
--abidiff" on a bunch of input binaries.  This harness runs over the
binaries that were submitted in this bug report.

* include/abg-tools-utils.h (string_is_ascii): Declare new
function ...
* src/abg-tools-utils.cc (string_is_ascii): ... and define it.
* src/abg-writer.cc (write_function_type): Escape forbidden XML
characters in function type names.
* src/abg-dwarf-reader.cc (build_function_type):  If a parameter
name is not ascii, drop it on the floor.
* tests/data/test-types-stability/pr19139-DomainNeighborMapInst.o:
New test input binary.
* tests/data/test-types-stability/pr19202-libmpi_gpfs.so.5.0:
Likewise.
* tests/data/Makefile.am: Add the new binaries above to the build
system.
* tests/test-types-stability.cc: New test harness.
* tests/Makefile.am: Add the new test harness to the build system.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
9 years agoIntroduce the name abixml in some comments
Dodji Seketeli [Thu, 5 Nov 2015 14:54:36 +0000 (15:54 +0100)]
Introduce the name abixml in some comments

Until now, the native XML format of libabigail didn't have a name.  I
am introducing the name "abixml" that I am slowing starting to use
these days.  So I am adding that name in comments of the files where
we emit and read that format.

* src/abg-reader.cc: Mention abixml in the comment at the top of
the file.
* src/abg-writer.cc: Likewise.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
9 years agoBug 19026 - Types with same name and different size considered equivalent
Dodji Seketeli [Sat, 17 Oct 2015 15:59:20 +0000 (17:59 +0200)]
Bug 19026 - Types with same name and different size considered equivalent

This is a second attempt at fixing this bug.  The previous attempt was
on the good path, but a thinko got in the way, oops.  We are not adding
the new binary of that bug report (which got re-opened) to the test
suite because it's too big and it takes too much time and memory to
abidw to analyze it.

* src/abg-ir.cc (type_base::get_canonical_type_for): Really
compare the size of the type to be canonicalized against the size
of the *current* potential canonical type of the same name.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
9 years agoAdd a script to update the reference output of runtestreaddwarf
Dodji Seketeli [Sat, 17 Oct 2015 13:59:55 +0000 (15:59 +0200)]
Add a script to update the reference output of runtestreaddwarf

This script parses the output of runtestreaddwarf (that output is
non-empty when the reference output *.abi files need updating, but
when there is no ABI change error).  As a result, the script emits a
series of "cp <source-file> <destination-file>" command to issue, to
update the reference output of the runtestreaddwarf test program.

To use this script to update the reference output *.abi files for
runtestreaddwarf,

    <build-dir>/tests/runtestreaddwarf > changed-output.txt
    python update-test-read-dwarf-output.py changed-output.txt > shell-update-commands.sh
    sh shell-update-commands.sh

* tests/update-test-read-dwarf-output.py: New helper python program.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
9 years agoStyle fixes in the abixml writer.
Dodji Seketeli [Sat, 17 Oct 2015 13:09:43 +0000 (15:09 +0200)]
Style fixes in the abixml writer.

* src/abg-writer.cc (write_var_decl): Use the var_decl_sptr
typedef.
(write_class_decl): Indent.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
9 years agoFix typo in test-read-dwarf.cc
Dodji Seketeli [Sat, 17 Oct 2015 13:05:41 +0000 (15:05 +0200)]
Fix typo in test-read-dwarf.cc

* tests/test-read-dwarf.cc (for test test21-pr19092.so.abi): Fix
typo in the output path of that test.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
9 years agoAdjust regression tests reference output for the current patch set
Dodji Seketeli [Sat, 17 Oct 2015 13:03:41 +0000 (15:03 +0200)]
Adjust regression tests reference output for the current patch set

This is the last patch of a series of patches which aims at fixing bug
libabigail/19097.  The short titles of the patches of the set are,
including this one:

    Don't canonicalize types not added to their context in abixml reader
    Support updating a class in the abixml reader
    Fix emitting of referenced type in abixml writer
    Use abidw --abidiff in test-read-dwarf.cc
    Adjust regression tests reference output for the current patch set

Below is the cover letter of the last patch of the set.

The current patch set needs big reference output adjustments, that we
are doing at the end, here.
* tests/data/test-read-dwarf/test22-pr19097-libstdc++.so.6.0.17.so:
New test input binary.
* tests/data/test-read-dwarf/test22-pr19097-libstdc++.so.6.0.17.so.abi:
New test reference output.
* tests/data/Makefile.am: Add the new test files above to the
source distribution.
* tests/test-read-dwarf.cc (in_out_specs): Add the two new test
files above to the set of test input files.
* tests/data/test-read-dwarf/test10-pr18818-gcc.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/test9-pr18818-clang.so.abi: Adjust.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
9 years agoUse abidw --abidiff in test-read-dwarf.cc
Dodji Seketeli [Sat, 17 Oct 2015 13:06:57 +0000 (15:06 +0200)]
Use abidw --abidiff in test-read-dwarf.cc

That test was doing several sub-tests that amount to just calling
abidw --abidiff.  So, let's use that, now that we have it.

* tests/test-read-dwarf.cc (handle_in_out_spec): Rather than
calling abilint on the abixml and abidiff-ing the .so file against
its .so.abi, call abidw --abidiff on the .so file and voila.  Ok,
it does one extra save of abixml, but then that won't hurt.  And
things are faster now than what they were anyway :-)

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
9 years agoFix emitting of referenced type in abixml writer
Dodji Seketeli [Sat, 17 Oct 2015 12:10:57 +0000 (14:10 +0200)]
Fix emitting of referenced type in abixml writer

There are several issues with the abixml writer in how it handles the
process of emitting referenced types that are not directly reachable
but just walking the scopes (namespaces) of the translation units;
think about member types of a class A that are not necessarily present
in all the declarations of A, in all translation units, for instance.

This patch addresses them all because they are all intermingled.

* Use of canonical pointers in the hash map of referenced types

The abixml writer was using canonical types pointer values to hash
referenced types in a map.  It was doing so "by hand"; and it was thus
messing things up for types without canonical types (like some class
declarations) etc.

This patch changes that by using the generic solution of
abigail::ir::hash_type_or_decl(), which also uses the same canonical
pointer type values.  For types with no canonical types, that
functions knows has to gracefully fallback.  At worst, it will just
make things slower, not wrong.

* Sorting of referenced types

The patch also changes the sorting function used for the hash map of
referenced types.  The previous solution was sorting the pretty
representation of types; but then when two types have the same pretty
representation (think, typedefs, for instance) then their relative
position in the sorted result was random.  This causes some stability
issues, in that emitting the abixml for the same binary several times
can lead to the some types being sorted differently -- they have the
same name, but not necessarily the same type *IDs*, as they are
different types.

The new sorting code handles this better; it also uses the pretty
representations of types, when they are equal, it uses the type IDs to
tell the types apart.  At least this brings stability in the abixml
output, for a given binary.

* Avoiding duplicating declaration-only types when emitting the
  context of referenced member types.

We don't keep track of declaration-only classes that are emitted.
This is because we allow a given class declaration (that carries no
definition) to appear several times in a given ABI corpus.  So when a
referenced type is a class declaration, it always appears as if that
referenced type has not been emitted.  So when we specifically emit
the not-emitted referenced types, it can happen that declaration-only
classes can appear a lot of times.  This is unnecessary duplication,
aka bloat.

This patch thus introduces a new hash map that tracks emitted
declaration-only classes, so that we can allow duplication of class
declarations when they follow what's done in the IR read from DWARF,
and disallow that duplication when it's totally artificial and
useless.

* Better tracking of referenced types

We were blatantly forgetting to mark some referenced types as such.
So those were missing in some abixml output.

This patch fixes the spots where we were forgetting that important
information.

* Better representation of the scopes of the referenced types that
  were specifically emitted.

The previous code was failing at properly representing the class scope
of some referenced types that were specifically emitted, or sometimes,
for member types, representing the scope would be so screwed that the
(referenced) member type itself wouldn't be emitted at all.

This is because I thought that to emit a given member type, just
emitting its parent scope would be enough. I thought that would
automatically trigger emitting the member type itself.  First, that
would emit too much information at times; the other members of the
scope are not necessarily needed.  And second the "duplication
detection code" would sometime refuse to emit the scope class, because
it has already been emitted earlier!  But the incarnation that got
emitted didn't have this member type as member, then.  Yes, in DWARF,
the same class A can be declared several times with different member
types in it.  The complete representation of A would be a union of all
those declarations of A that are seen.

This patch addresses this issue by carefully emitting just the
information that is needed from the scope of the referenced type.
Basically the scope is declared just to declare/define the type we are
interested in; period.  The abixml reader is now properly geared to
re-construct the scope by merging its different parts that are now
scattered around, in the ABI corpus.  That support is part of this
patch set.

instance, a member typedef would be emitted with the information of
its parent class badly formatted.

* src/abg-writer.cc (struct type_ptr_comp_functor): Remove this.
(sort_type_ptr_map): Likewise.
(write_context::record_type_as_referenced): Do not add the
canonical type of the type to record as referenced directly.
(write_context::type_is_referenced): Adjust accordingly.
(struct write_context::type_ptr_cmp): New comparison functor.
(write_context::sort_types): New sorting function.
(write_context::{record_decl_only_type_as_emitted,
decl_only_type_is_emitted}): New member functions.
(write_member_type_opening_tag): Factorize out of ...
(write_member_type): ... here.
(write_class_decl_opening_tag): Factorize out of ...
(write_class_decl): ... here.  Now, keep track also of
declaration-only classes that are emitted.
(write_decl_in_scope): Use the new write_member_type_opening_tag
and write_class_decl_opening_tag.  Now write class scopes
ourselves; they only contain the type declarations that we are
emitting.
(write_translation_unit): Use the new sorting code to sort the
referenced types to emit.  Do not emit referenced types that are
declaration-only classes that have already been emitted.  Handle
the fact that emitting the referenced types might make those
emitted type *reference* other types too! So handle those new
referenced types as such, and emit them too.
(write_qualified_type_def, write_typedef_decl, write_var_decl): Do
not forget to mark referenced types as such.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
9 years agoSupport updating a class in the abixml reader
Dodji Seketeli [Sat, 17 Oct 2015 11:26:41 +0000 (13:26 +0200)]
Support updating a class in the abixml reader

In DWARF, the same class declaration can be present several times but
with different "views", that is, it can be present in a first
translation unit, but without any member type; then in a subsequent
translation unit, its member types are defined.  In another, it'll be
completely defined, with all its data members and base classes.  The
DWARF reader knows how to amend the class to add new members to it, as
they show up in the debug information.

This patch adds the same functionality to the abixml reader.  The
writer has already started to write class declarations with different
"views" too, since it's started to avoid duplicating full class
definitions in every translation unit that uses them.

Without this patch, abixml misses some class members, and that is a
bug.

* include/abg-ir.h (class_decl::{find_base_class,
find_member_type, find_data_member}): Declare new member functions ..
* src/abg-ir.cc (class_decl::{find_base_class,
find_member_type, find_data_member}): ... and define them.
* src/abg-reader.cc (build_class_decl): Add the ability to update
a class to add new data members, member types and base classes to
it, if necessary.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
9 years agoDon't canonicalize types not added to their context in abixml reader
Dodji Seketeli [Sat, 17 Oct 2015 10:48:11 +0000 (12:48 +0200)]
Don't canonicalize types not added to their context in abixml reader

This is the first patch of a series which aims at fixing bug
libabigail/19097.

The problem in that report is a result of several underlying issues.
This patch series address them in isolation.  The patches do not
update the reference output of the regression test as they should,
because they are all needed to get to a sane working state.  The test
reference output are thus adjusted in the last patch of the series.
Here are the short titles of the patches of the set, including this
one:

    Don't canonicalize types not added to their context in abixml reader
    Support updating a class in the abixml reader
    Fix emitting of referenced type in abixml writer
    Use abidw --abidiff in test-read-dwarf.cc
    Adjust regression tests reference output for the current patch set

Below is the cover letter of the first patch of the set.

The abixml reader sometimes (wrongly) canonicalizes types that are not
(yet) added to their context.  This can lead to comparison issues
because some information carried by some types are dependant on their
context (e.g, access specifiers) and can be important for type
comparison.  Right now, access specifiers for member types are no more
taken into account when comparing member types because DWARF emitters
do not necessarily keep a correct track of those; but when they do, we
better be prepared.  And in any case, it's wrong to have type
canonicalization happen on half backed types anyway.

So this patch fixes several spots where type canonicalization happens
on types that are not added to their scope.

* src/abg-reader.cc (read_context::maybe_canonicalize_type):
Assert that a class type that is scheduled for canonicalization
must be in a scope.  We do this only for classes, for now.  The
assert here helped to spot (and fix)  a lot of places where we
were canonicalizing types without scope.
(read_context::build_or_get_type_decl):  Canonicalize types here,
when they are built and (hopefully) added to their scope.  There
might be cases here where we try to canonicalize types that are
not added to their scope.  That should bomb in the assert above,
at least for class types, for now.  We'll then fix the places where
the types are created, to make them properly scoped.
(build_type_decl, build_qualified_type_decl)
(build_pointer_type_def, build_reference_type_def)
(build_array_type_def, build_enum_type_decl, build_typedef_decl):
Do not try to canonicalize the types early, right when they are
created.  Canonicalization should happen at the point where (or
after) they are added to their scope.
(build_class_decl): Likewise.  Also, schedule member types for
canonicalization once they've been added to their scope.
(build_class_tdecl): Schedule the pattern of the class template
for canonicalization once it has been added to its scope.  I am
not sure I should do this, as the pattern is not yet a real type,
but I am taking my bet.
(build_type_composition): Schedule the composed type for
canonicalization once it's been added to its scope.
(handle_type_decl, handle_qualified_type_decl)
(handle_pointer_type_def, handle_reference_type_def)
(handle_function_type, handle_array_type_def)
(handle_enum_type_decl, handle_typedef_decl, handle_class_decl):
At this point, we should know if the type is to be added to a
scope or not.  If it's in a scope, then schedule for
canonicalization.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
9 years agoBug 19092 - abidw aborts on types that violate the ODR
Dodji Seketeli [Thu, 15 Oct 2015 14:06:35 +0000 (16:06 +0200)]
Bug 19092 - abidw aborts on types that violate the ODR

It appears that two different types from two different translation
units might have the same name in a DSO, like in the example of this
bug.  This violates the One Definition Rule, which we rely on to go
fast, and more importantly, it introduces type canonicalization errors.

This patch recognizes more of these ODR violation cases by looking at
the size of the types.  That is, if two types (from the same DSO) with
the same name have different sizes, then they are different.

* src/abg-ir.cc (type_base::get_canonical_type_for): Look at the
size of types with the same name which could be considered
ODR-equal, to spot possible violations that would induce a type
canonicalization error.
* tests/data/test-read-dwarf/test21-pr19092.so: New test input
binary.
* tests/data/test-read-dwarf/test21-pr19092.so.abi: New reference
abixml for the binary above.
* tests/data/Makefile.am: Add the new test input above to source
distribution.
* tests/data/test-read-dwarf/test9-pr18818-clang.so.abi: Adjust.
* tests/data/test-read-dwarf/test12-pr18844.so.abi: Likewise.
* tests/data/test-read-dwarf/test20-pr19025-libvtkParallelCore-6.1.so.abi:
Likewise.
* tests/test-read-dwarf.cc (int_out_specs): Add the two test input
above.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
9 years agoFix activation of Debian package support
Dodji Seketeli [Thu, 15 Oct 2015 10:51:33 +0000 (12:51 +0200)]
Fix activation of Debian package support

* configure.ac: If we cannot activate Debian package support, then
report it clearly.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
9 years agoMisc style cleanup
Dodji Seketeli [Thu, 15 Oct 2015 10:50:10 +0000 (12:50 +0200)]
Misc style cleanup

* include/abg-fwd.h: Remove unnecessary declaration of class
parameter.
* src/abg-ir.cc: Remove trailing space in a comment.
* src/abg-reader.cc: Fix a comment.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
9 years agoEmit statistics about resolved class declarations
Dodji Seketeli [Thu, 15 Oct 2015 10:47:24 +0000 (12:47 +0200)]
Emit statistics about resolved class declarations

This patch makes abidw --stats emit statitics about class declarations
that got resolved, and those that we missed.

* src/abg-dwarf-reader.cc
(read_context::resolve_declaration_only_classes): Emit statistics
about resolved classes and the missed ones.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
9 years agoAdd a missing xml text reader call
Dodji Seketeli [Thu, 15 Oct 2015 10:44:30 +0000 (12:44 +0200)]
Add a missing xml text reader call

* src/abg-reader.cc (read_corpus_from_input): Add the necessary
call to xmlTextReaderNext call after the xmlTextReaderExpand call.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
9 years agoPass some more parameters in reference
Dodji Seketeli [Thu, 15 Oct 2015 07:42:54 +0000 (09:42 +0200)]
Pass some more parameters in reference

Profiling as shown that we might gain some precious cycles by passing
some well chosen parameters by reference.

* include/abg-ir.h (operator==): For the type_base_sptr and
decl_base_sptr overloads, pass the parameters by reference.
({var,function}_decl::{set,get}_symbol): Pass the elf_symbol_ptr
by reference.
* src/abg-ir.cc (operator==): For the type_base_sptr and
decl_base_sptr overloads, pass the parameters by reference, now in
the definition.
({var,function}_decl::{set,get}_symbol): Pass the elf_symbol_ptr
by reference, now in the definition.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
9 years agoAdjust tests for the patchset
Dodji Seketeli [Thu, 15 Oct 2015 11:08:18 +0000 (13:08 +0200)]
Adjust tests for the patchset

This is the last patch of the series of patches whose titles are
(including this one):

    Force late canonicalizing of function types read from abixml
    Fix strip_typedef issues
    Do not compare access specs for member types & functions
    Fix "is-anonymous" abixml property impact on some tests
    Fix const-ness of a function parameter
    Handle aliased function decls when comparing decls in general
    Make canonicalization non sensitive to struct-ness of subtypes
    Set the corpus of all ABI artifact reads from abixml
    Implement fast type lookup in a corpus
    Accelerate a slow path in hash_type_or_decl()
    A series of small speed optimizations here and there
    Allow only one definition of a given type per corpus in abixml
    Make abidw --abidiff not show definitely harmless changes
    Adjust tests for the patchset

This patch carries the numerous adjustments necessary for the
regresion tests output after this patch set.

* tests/data/test-read-dwarf/test10-pr18818-gcc.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/test9-pr18818-clang.so.abi: Likewise.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
9 years agoMake abidw --abidiff not show definitely harmless changes
Dodji Seketeli [Thu, 15 Oct 2015 10:56:06 +0000 (12:56 +0200)]
Make abidw --abidiff not show definitely harmless changes

When comparing the ABI of the input ELF binary with that same ABI
saved to abixml and read back again, there can be some minor and
harmless changes that are seen, because libabigail makes some
approximations for performance reasons.  For instance, if there are
two types that are equivalent, but have different names (because of
typedefs) then libabigail will consider that they are the same type,
and might save them (to abixml) and read them back (from abixml) in
different order.

That can lead to subtle changes that are reported (and filtered out)
by the command "abidw --abixml".

This patch arranges for abidw --abixml to avoid emitting a report
saying that a filtered out change was detected, as those cases are
considered OK.

The patch also fixes a little issue where abidw would abort because
the user forgot to provide the binary to analyze, on the command line.

* tools/abidw.cc (set_diff_context): New function.
(main): Use that new function.  Do not show any output for
--abidiff if only compatible changes were detected.  Also, do not
abort if no input binary was giving.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
9 years agoAllow only one definition of a given type per corpus in abixml
Dodji Seketeli [Thu, 15 Oct 2015 09:13:19 +0000 (11:13 +0200)]
Allow only one definition of a given type per corpus in abixml

In abixml, the same type T can be defined in several translation
units.  This leads to a lot of duplication and, for some big binaries,
to a *lot* of memory use.  For instance, loading the abixml
representing the abi of the r300_dri.so library takes more that 10GB
or ram on a 64 bits system!

This patch addresses the issue by allowing declarations to be
duplicated, but by allowing only one definition per type, per corpus.
With it, loading the abixml of r300_dri.so now takes less than 2GB or
ram.

* src/abg-writer.cc (write_translation_unit): Do not clear some
important per-translation unit maps here.  There are needed to
keep track of the emitted and referenced types through the entire
corpus.  Avoid (wrongly) recording function types twice.
(write_array_type_def, write_function_decl, write_function_type):
Record referenced types.
(write_class_decl): Record referenced types, and, allow only
declarations to be duplicated in a corpus.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
9 years agoA series of small speed optimizations here and there
Dodji Seketeli [Thu, 15 Oct 2015 09:04:32 +0000 (11:04 +0200)]
A series of small speed optimizations here and there

These are small speed optimizations that are induced by some lesser
hot spot identified by profiling.

* src/abg-comparison.cc (var_diff::has_changes): Just compare the
two var_decl.  It's (way) faster now than using recursive hashing
for that.
* src/abg-ir.cc (elf_symbol::does_alias): Get out early if the two
main symbols are equal.
(equals): In the overload for function_decl, start by comparing
types.  This can be very fast for functions with different types,
as it amounts to a pointer comparison.  In the overload for
class_decl, avoid a map lookup when it's not necessary.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
9 years agoAccelerate a slow path in hash_type_or_decl()
Dodji Seketeli [Thu, 15 Oct 2015 08:50:36 +0000 (10:50 +0200)]
Accelerate a slow path in hash_type_or_decl()

Profiling shows that hash_type_or_decl() is very slow when hashing
function parameters and base class specifications.  This is because in
those two cases we use the slow recursive hashing algorithm to hash
types, rather than using the faster one based on using the pointer
values of canonical types when possible.

This was making corpora comparison very slow, as it uses
hash_type_or_decl() to hash diffs of ABI artifacts.

This patch fixes that.

* include/abg-ir.h (is_function_parameter, is_class_base_spec):
Declare new functions.
* src/abg-ir.cc (is_function_parameter, is_class_base_spec):
Define them.
(hash_type_or_decl): Handle hashing of function parameters are
class base specifications with the fast path of type hashing.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
9 years agoImplement fast type lookup in a corpus
Dodji Seketeli [Thu, 15 Oct 2015 08:14:22 +0000 (10:14 +0200)]
Implement fast type lookup in a corpus

Profiling has shown that on libraries with a lot of class types
declarations (more than 10K types), the phase of resolving those
declarations to their definition was a hot spot.  The lookup of the
type definition inside the entire corpus was the bottleneck.

This patch removes (or loosen) that bottleneck by doing away with the
graph-walking-based type lookup algorithm that was used.  Rather, maps
of name -> types are maintained by each scope, in each translation
unit. Those maps are updated each time a type is added to a scope.
And looking up a type amounts to a lookup in a map.  Way faster.

* include/abg-fwd.h (components_to_type_name): Declare new
function.
* include/abg-ir.h (string_type_base_wptr_map_type): New typedef.
(translation_unit::{get,set}_types): Declare new member functions.
* src/abg-ir.cc (translation_unit::priv::types_): New data member.
(translation_unit::{get,set}_types): Define these member
functions.
(maybe_update_types_lookup_map): Define new static function.
(components_to_type_name): Define new function.
(scope_decl::{add_member_decl, insert_member_decl}): Call the new
maybe_update_types_lookup_map.
(scope_decl::find_iterator_for_member): Fix logic.
(class_decl::set_is_declaration_only): When a class declaration
becomes a definition, update the name -> type map maintained in
the scope of the class.
(lookup_type_in_translation_unit): Use the hash map of qualified
name -> types that is now maintained in the translation unit.
This is way faster than the previous walking algorithm.
* src/abg-dwarf-reader.cc (build_translation_unit_and_add_to_ir):
When fixing up global variable declarations that need to be
re-added to the translation unit, use the new fast type lookup
function.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
9 years agoSet the corpus of all ABI artifact reads from abixml
Dodji Seketeli [Thu, 15 Oct 2015 07:47:58 +0000 (09:47 +0200)]
Set the corpus of all ABI artifact reads from abixml

It turns out we were not setting the corpus for all ABI artifact read
from abixml.  That was preventing the use of the ODR-based speed
optimization during type canonicalization, for corpora built from abixml.

Fixed thus.

* src/abg-reader.cc (read_translation_unit): Set the current
corpus to the current translation unit being built.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
9 years agoMake canonicalization non sensitive to struct-ness of subtypes
Dodji Seketeli [Wed, 14 Oct 2015 20:40:18 +0000 (22:40 +0200)]
Make canonicalization non sensitive to struct-ness of subtypes

In a previous patch, we made canonicalization independant from
struct-ness of class types.  This was in this commit:

    0e3416e Bug 19023 - Type canonicalization is sensitive to struct-ness

But then, that didn't handle the case of composite types which have a
subtype of class type T, where the same T was declared as "struct" and
as "class" in the same binary.

This patch handles that case by passing a flag to the functions that
build the pretty representation of types.  Note that the pretty
representation is used as a key in the hash map that contains
canonical types.  That flag is passed all the way down to the function
that builds the pretty representation for class types, which decides
to use either "struct" or "class" as a previx for the representation.

The type canonicalization code then passes that flag (properly set) to
the pretty representation function.

* include/abg-fwd.h (get_type_name, get_function_type_name)
(get_method_type_name, get_pretty_representation): Add an
"internal" flag to all overoads.
* include/abg-ir.h
({type_or_decl_base, decl_base, type_decl, scope_type_decl,
qualified_type_def, array_type_def, enum_type_decl, typedef_decl,
var_decl, function_decl, function_decl::parameter, function_type,
method_type, class_decl}::get_pretty_representation): Add an
'internal' flag.
({decl_base, qualified_type_def, pointer_type_def,
reference_type_def, array_type_def, enum_type_decl::enumerator,
function_decl::parameter}::get_qualified_name): Likewise.
(qualified_type_def::build_name): Likewise.
* src/abg-ir.cc ({decl_base, qualified_type_def, pointer_type_def,
reference_type_def, array_type_def, enum_type_decl,
enum_type_decl::enumerator,
function_decl::parameter}::get_qualified_name): Take an "internal"
flag.
(qualified_type_def::build_name): Likewise.
({decl_base, type_decl, namespace_decl, array_type_def,
enum_type_decl, typedef_decl, var_decl, function_type,
method_type, function_decl,
class_decl}::get_pretty_representation): Likewise.
(get_type_name, get_function_type_name, get_method_type_name)
(get_pretty_representation): Likewise.
(type_base::get_canonical_type_for): Call
get_pretty_representation() with the "internal" flag set to
"true", to get a pretty representation that is independant from
the struct-ness of the subtypes of the type being canonicalized.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
9 years agoHandle aliased function decls when comparing decls in general
Dodji Seketeli [Wed, 14 Oct 2015 18:49:55 +0000 (20:49 +0200)]
Handle aliased function decls when comparing decls in general

When comparing two declarations, we look at their linkage name. When
the linkage names are different, then we infer that the two decls are
different.

But then, for *function* decls, it can happen that two different
linkage names are actually for different symbols that do alias; the
(ELF) symbols are different but they have the same address; so they
point to the same "thing".  The two functions are not different, then.

And we were not supporting this last case of diffent linkage names
that are aliases of each other.

This patch adds support for that.

* include/abg-ir.h (is_function_decl): Add a const to the
reference parameter, making it comply with the definition.
* src/abg-ir.cc (equals): In the overload for decl_base, when the
two linkage names are different, consider the case of the decls
being aliased functions.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
9 years agoFix const-ness of a function parameter
Dodji Seketeli [Wed, 14 Oct 2015 18:44:18 +0000 (20:44 +0200)]
Fix const-ness of a function parameter

* include/abg-fwd.h (is_function_decl): Add a const to the
parameter to make it comply with the definition in abg-ir.cc.
Woops.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
9 years agoFix "is-anonymous" abixml property impact on some tests
Dodji Seketeli [Wed, 14 Oct 2015 12:52:08 +0000 (14:52 +0200)]
Fix "is-anonymous" abixml property impact on some tests

Since we started to rely on ODR for type canonicalization, we needed
to mark anonymous structures (and enums) as being anonymous, hence, a
new "is-anonymous" property was introduced in the abixml format.
While looking at something else, I noticed that some anonymous
structures in test files
tests/data/test-abidiff/test-corpus0-v{0,1}.so.abi were not marked as
anonymous, and that was causing some comparison issues.  This patch
adjusts those abixml files.  I forgot at the time to mention that
those files were coming from the libtirpc.so binary provided in bug
18166, so I am renaming the files now to reflect that.  Also, I am
adding the binary here.  I have thus re-generated a new abixml file
from that *.so file; it now has the proper "is-anonymous" properties.

* tests/data/test-abidiff/test-PR18166-libtirpc.so: New file.
* tests/data/test-abidiff/test-PR18166-libtirpc.so.abi: Likewise.
* tests/data/test-abidiff/test-corpus0-report0.txt: Renamed into
tests/data/test-abidiff/test-PR18166-libtirpc.so.report.txt.
* tests/data/test-abidiff/test-corpus0-v{0,1}.so.abi: Removed.
* tests/data/Makefile.am: Renamed test-corpus0-* files into
test-PR18166-libtirpc.so-* files.
* tests/test-abidiff.cc (specs): Adjust.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
9 years agoDo not compare access specs for member types & functions
Dodji Seketeli [Wed, 14 Oct 2015 11:49:29 +0000 (13:49 +0200)]
Do not compare access specs for member types & functions

It turns that in some DWARF (e.g, from the r300_dri.so binary in bug
libabigail/19024) the same class Foo can be declared as a struct, and
later defined as a class.  Or the other way around.

In some cases, Foo can be declared as a struct, have a member type
Foo::Type with no access specifier, and later that member type is
still present with no access specifier when Foo is defined as a class.
So when comparing Foo::Type (from struct Foo) against Foo::Type (from
class Foo) we must not consider the access specification of Type,
otherwise, as in the first case it's 'public' and in the second case
it's 'private', the two member types would be considered different.

And something similar happens for member function declarations too.

This patch thus avoids comparing access specifiers for member types
and functions.  Though it can be considered as a regression compared
to what was being done before, access specifiers don't have an impact
on ABI per se.  And they can cause noise in the result, as we are
seeing here.

* include/abg-fwd.h (is_function_decl): Declare a new overload.
* src/abg-ir.cc (is_function_decl): Define a new overload.
(equals): In the overload for decl_base, do not compare access
specifiers when comparing member functions and types.
* tests/data/test-diff-dwarf/test0-report.txt: Adjust.
* tests/data/test-diff-filter/test0-report.txt: Likewise.
* tests/data/test-diff-filter/test01-report.txt: Likewise.
* tests/data/test-diff-filter/test30-pr18904-rvalueref-report0.txt: Likewise.
* tests/data/test-diff-filter/test31-pr18535-libstdc++-report-0.txt: Likewise.
* tests/data/test-diff-filter/test4-report.txt: Likewise.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
9 years agoFix strip_typedef issues
Dodji Seketeli [Wed, 14 Oct 2015 11:34:35 +0000 (13:34 +0200)]
Fix strip_typedef issues

strip_typedef currently has at least two issues.  First, it was
triggering a potentially wrong early canonicalization.  Second, it was
asserting too eagerly that a return type should not be nil; the truth
is that there can be a short period of time where a function has an
empty result type; that is usually during the building of said
function type, before the return type is fully built.

This patch addresses those two issues.

* src/abg-ir.cc (strip_typedef): Do not canonicalize
the return type of the method type to typedef-strip.
Acknowledge that the return type can be nil.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
9 years agoForce late canonicalizing of function types read from abixml
Dodji Seketeli [Wed, 14 Oct 2015 13:00:27 +0000 (15:00 +0200)]
Force late canonicalizing of function types read from abixml

This is the first patch of a series which aims at fixing:

    Bug 19024 - abidw --abidiff fails and aborts when run against r300_dri.so

The issue reported in that bug is the manifestation of several
problems that different patches in the series address on a case by
case basis.

Suffice it to say abidw --abidiff on my X220 laptop was taking more
than 40 minutes, and north of 11GB or ram.  An rather than yielding
the empty set, it was emitting lots of false postives!

The patchset thus applies a series of optimizations to reduce the time
and memory taken, so that I can at least debug the issues that prevent
abidw --abidiff from yielding the empty set, as it should.  Then, with
those optimizations applied, I came up with a series of fixes.

With the series applies, abidw --abidiff now takes less than 8 minutes
and around of 4.8GB of ram.

The first seven patches are those fixes.  The next five patches are
the time and size optimization that allowed me to work on the first
fixes.  The thirteenth patch applies some needed modification (both
fixes and improvements) to abidw --abidiff itself. The last patch
carries the necessary adjustments to the regression tests output.

Here are the short titles of the patches of the set, including this one:

    Force late canonicalizing of function types read from abixml
    Fix strip_typedef issues
    Do not compare access specs for member types & functions
    Fix "is-anonymous" abixml property impact on some tests
    Fix const-ness of a function parameter
    Handle aliased function decls when comparing decls in general
    Make canonicalization non sensitive to struct-ness of subtypes
    Set the corpus of all ABI artifact reads from abixml
    Implement fast type lookup in a corpus
    Accelerate a slow path in hash_type_or_decl()
    A series of small speed optimizations here and there
    Allow only one definition of a given type per corpus in abixml
    Make abidw --abidiff not show definitely harmless changes
    Adjust tests for the patchset

We do not add the r300_dri.so library to the repository because of the
time it still takes to complete.

And now, here is the cover letter for this first patch.

When reading the abixml format, sometimes, function types can be
early-canonicalized.  This can be wrong especially is the function
type has sub-types that are not canonicalized yet.

So this patch forces those to be late-canonicalized.

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

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
9 years agoBug 19082 - Recognize suppression spec files
Ondrej Oprala [Tue, 13 Oct 2015 07:19:47 +0000 (09:19 +0200)]
Bug 19082 - Recognize suppression spec files

When abipkgdiff is invoked on a set of packages, the newer (second) one is also
inspected for files matching the pattern '*.abignore', whose contents are read
and interpreted as suppression specifications.

* tests/data/Makefile.am: Add new test material to the build system.
* tests/data/test-diff-pkg/dirpkg-{0-dir1,{1,2}-dir2}/dir.abignore:
A test suppression specification.
* tests/data/test-diff-pkg/dirpkg-{2,3}-dir2/.abignore: Likewise.
* tests/data/test-diff-pkg/dirpkg-3.suppr: Likewise.
* tests/data/test-diff-pkg/dirpkg-{1,2,3}-dir{1,2}/libobj-v0.so: New
binary test inputs.
* tests/data/test-diff-pkg/dirpkg-{1,2,3}-dir{1,2}/obj-v0.cc: New test
source files
* tests/data/test-diff-pkg/dirpkg-{1,2,3}-report-{0,1}.txt: New
reference outputs
* tests/test-diff-pkg.cc: Adjust to run the new tests.
* tools/abipkgdiff.cc (prog_options): New static pointer to struct
opts.
(file_tree_walker_callback_fn): Rename to
first_package_tree_walker_callback_fn.
(second_package_tree_walker_callback_fn): Check for ELF files just
like the previous function but additionally check for files
ending with ".abignore", unless disabled from the command line.
({create_maps_of_package,extract_package_and_map_its}_content):
Add a callback as a new argument.
(main) handle the new "--no-abignore" option, which turns off
the search for suppression files within the new package.

Signed-off-by: Ondrej Oprala <ooprala@redhat.com>
9 years agoBug 19024 - Failing to flag underlying type of enums as anonymous
Dodji Seketeli [Thu, 8 Oct 2015 16:15:55 +0000 (18:15 +0200)]
Bug 19024 - Failing to flag underlying type of enums as anonymous

The for now, the underlying type of an enum type is always assumed to
be anonymous by libabigail.  But then, the code of the DWARF reader
was failing to set the "is-anonymous" flag on it.  So type
canonicalizing code was comparing the enum underlying types by looking
at their names; they all have the same name -- as we forget that they
are anonymous; so they (wrongly) all look the same, within the same
ABI corpus.

This patch sets properly sets the is-anonymous flag on enumerator
underlying types again.

* src/abg-dwarf-raeder.cc (build_enum_type): Set the is-anonymous
flag on the underlying type of the enum.
* tests/data/test-read-dwarf/test0.abi: Adjust.
* tests/data/test-read-dwarf/test9-pr18818-clang.so.abi: 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/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.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
9 years agoBug 19025 - abixml writer forgets to emit some member types
Dodji Seketeli [Thu, 8 Oct 2015 10:57:04 +0000 (12:57 +0200)]
Bug 19025 - abixml writer forgets to emit some member types

When a member type (a type that is a member of a class) M is
referenced by some types emitted by abixml, but the context of M (the
class type which M is a member of) is not itself referenced by any ABI
artifact, then abixml forgets to emit the context of M and thus M
itself.

With this patch, when the abixml writer has emitted almost all ABI
artifacts for the current translation unit, it looks for types that
have been referenced by the emitted ABI artifacts, but that haven't
been emitted themselves.

It then emits those referenced-but-not-emitted types, and makes sure
their contexts are emitted as well.

* include/abg-fwd.h (is_namespace): Fix prototype.
* src/abg-writer.cc (struct type_ptr_comp_functor): New internal
type.
(sort_type_ptr_map): New static function.
(write_context::m_referenced_types_map): Renamed
m_referenced_fntypes_map data member into this.
(write_context::get_referenced_types): New member function.
(write_context::record_type_as_referenced): Renamed
record_fntype_as_referenced member function into this.  Adjust.
(write_context::type_is_referenced): Renamed fntype_is_referenced
into this.
(write_context::clear_referenced_types_map): Renamed
clear_referenced_fntypes_map member function into this.  Adjust.
(write_decl_in_scope): New static function.
(write_translation_unit): Use it here to emit types that are
referenced by other types in the TU, but that are not emitted.
Adjust.
(write_pointer_type_def, write_reference_type_def)
(write_typedef_decl): Record the underlying types referenced by
the emitted types as being, well, referenced.
* tests/data/test-read-dwarf/test20-pr19025-libvtkParallelCore-6.1.so:
New test binary input.
* tests/data/test-read-dwarf/test20-pr19025-libvtkParallelCore-6.1.so.abi:
New reference output of the binary input above.
* tests/data/Makefile.am: Add the new test material above to the
source distribution.
* tests/test-read-dwarf.cc (in_out_spec): Add the new test inputs.
* tests/data/test-read-dwarf/test9-pr18818-clang.so.abi: Adjust.
* tests/data/test-read-dwarf/test10-pr18818-gcc.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.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
9 years agoParallelize test read-dwarf.
Ondrej Oprala [Tue, 6 Oct 2015 12:35:14 +0000 (14:35 +0200)]
Parallelize test read-dwarf.

* tests/Makefile.am: Link runtestreaddwarf with libpthread.
* tests/test-read-dwarf.cc (main) Create worker threads corresponding
to the number of CPUs online, add a "--no-parallel" option and move
the main loop...
(handleInOutSpec) ...here.

Signed-off-by: Ondrej Oprala <ooprala@redhat.com>
9 years agoBug 19023 - Type canonicalization is sensitive to struct-ness
Dodji Seketeli [Tue, 6 Oct 2015 22:08:46 +0000 (00:08 +0200)]
Bug 19023 - Type canonicalization is sensitive to struct-ness

In some debug info of some shared library, the same type can be
present as a struct in some translation units, and as a class in
others.  As we are using the "pretty representation" of types to hash
types during type canonicalization, a "class foo" and "struct foo"
are (wrongly) considered different, because those pretty
representations are different.

This patch changes the canonicalization code to make it independent
from the struct-ness of the class being canonicalized.

* include/abg-ir.h (class_decl::is_struct): Declare a setter for the
"is-struct" property.
* src/abg-ir.cc (class_decl::is_struct): And define that setter
here.
(type_base::get_canonical_type_for): Temporarily set the
'is-struct' flag of the class type to 'false' before building its
pretty representation.
* tests/data/test-read-dwarf/test19-pr19023-libtcmalloc_and_profiler.so:
New test input binary.
* tests/data/test-read-dwarf/test19-pr19023-libtcmalloc_and_profiler.so.abi:
New test reference output.
* tests/data/Makefile.am: Add the new test material above to the
source distribution.
* tests/test-read-dwarf.cc (in_out_specs): Add the two new test
inputs to the list of test inputs to consider.
* tests/data/test-read-dwarf/test14-pr18893.so.abi: Adjust.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
9 years agoStyle adjustment in abg-corpus.cc
Dodji Seketeli [Tue, 6 Oct 2015 11:04:39 +0000 (13:04 +0200)]
Style adjustment in abg-corpus.cc

* src/abg-corpus.cc (corpus::exported_decls_builder::id_var_map_):
Renamed data member vars_map_ into this.
(corpus::exported_decls_builder::id_var_map): Renamed vars_map
into this.
(corpus::exported_decls_builder::var_id_is_in_id_var_map): Renamed
var_is_in_map into this.
(corpus::exported_decls_builder::{add_var_to_map,
add_var_to_exported, maybe_add_var_to_exported_vars}): Adjust.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
9 years agoBug 19037 - Make ABI corpus support several functions with same symbol
Dodji Seketeli [Tue, 6 Oct 2015 10:01:20 +0000 (12:01 +0200)]
Bug 19037 - Make ABI corpus support several functions with same symbol

It turns out that, in DWARF, there can be function template
instantiations foo<int>(int) and foo<TypedefOfInt>(TypedefOfInt) which
have the same symbol name, if TypedefOfInt is a typedef of int.

An ABI corpus retains only one function declaration per symbol
name.  So in the example of the bug the input DWARF has the two
instantiations, but libabigail is just keeping one of the two; so the
abixml only has one of the two template instantiations.

This patch changes the ABI corpus model so that it represents the fact
that there can be several function declarations for a given symbol.
The patch then adjust the comparison engine to make it know about this
new model.

* include/abg-corpus.h
(corpus::exported_decls_builder::str_{fn,var}_ptr_map_type):
Remove these typedefs from here as they only used internally in
abg-corpus.cc.  So we move them there instead.
* src/abg-corpus.cc (str_fn_ptrs_map_type): New typedef.
(str_var_ptr_map_type): Moved the typedef that was in
corpus::exported_decls_builder here.
(corpus::exported_decls_builder::id_fns_map_): Rename the fns_
data member into this.  Make it have a str_fn_ptrs_map_type as a
type.
(corpus::exported_decls_builder::id_fns_map): Renamed the
fns_map() accessor into this one.
(corpus::exported_decls_builder::{fn_id_is_in_id_fns_map,
fn_is_in_fns}): New member functions.
(corpus::exported_decls_builder::fn_is_in_id_fns_map): Rename
fn_is_in_map into this.
(corpus::exported_decls_builder::add_fn_to_id_fns_map): Rename
add_fn_to_map into this.
(corpus::exported_decls_builder::add_fn_to_exported): Adjust.
(corpus::exported_decls_builder::maybe_add_fn_to_exported_fns):
Adjust.
* src/abg-comparison.cc (function_decl_diff::report): Emit reports
about function name changes (for a given function ID) only if
there are sub-type changes to be reported for the function.  In
that case, do not forget to emit the sub-type changes after the
name changes have been reported.
(corpus_diff::priv::ensure_lookup_tables_populated): Several
functions of the same ID can be removed or added from/to the
corpus.
* tests/data/test-read-dwarf/test18-pr19037-libvtkRenderingLIC-6.1.so:
New test input binary.
* tests/data/test-read-dwarf/test18-pr19037-libvtkRenderingLIC-6.1.so.abi:
New test output reference.
* tests/data/Makefile.am: Add the new test materials to the source
distribution.
* tests/test-read-dwarf.cc (in_out_specs): Adjust to add the new
test inputs above.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
9 years agoDo not imply private access when building a struct from ABIXML.
Ondrej Oprala [Mon, 5 Oct 2015 13:01:04 +0000 (15:01 +0200)]
Do not imply private access when building a struct from ABIXML.

* src/abg-reader.cc (read_context): Abort if we run into an
unsupported access specifier.
(build_class_decl) Default to public access for the children
of a struct.

Signed-off-by: Ondrej Oprala <ooprala@redhat.com>
9 years agoFix minor warnings when building documentation.
Ondrej Oprala [Mon, 5 Oct 2015 06:40:20 +0000 (08:40 +0200)]
Fix minor warnings when building documentation.

* manuals/abilint.rst: Fix the "Literal block expected" warning.
* manuals/abipkgdiff.rst: Fix the "Title underline too short" warning.

Signed-off-by: Ondrej Oprala <ooprala@redhat.com>
9 years agoFix an "Unknown target name" error during make info.
Ondrej Oprala [Mon, 5 Oct 2015 06:33:46 +0000 (08:33 +0200)]
Fix an "Unknown target name" error during make info.

* doc/manuals/libabigail-overview.rst: Fix the reference to
"ELF symbols".

Signed-off-by: Ondrej Oprala <ooprala@redhat.com>
9 years agoFix a path in doc/Makefile.am
Ondrej Oprala [Mon, 5 Oct 2015 05:47:13 +0000 (07:47 +0200)]
Fix a path in doc/Makefile.am

* doc/Makefile.am: Prefix the path for DOXY_WEBSITE_SRC_CFG and
DOXY_WEBSITE_BLD_{CFG,DIR} with "/doc" to protect it against make
clean.

Signed-off-by: Ondrej Oprala <ooprala@redhat.com>
9 years agoMisc style cleanups
Dodji Seketeli [Sun, 4 Oct 2015 11:35:19 +0000 (13:35 +0200)]
Misc style cleanups

* src/abg-reader.cc (read_is_struct): Fix comment.
(build_type_decl): Use type_decl_sptr rather than
shared_ptr<type_decl>.
(build_type_decl): Use typedef_decl_sptr rather than
shared_ptr<typedef_decl>.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
9 years agoUse the ODR to speed up type canonicalization
Dodji Seketeli [Sun, 4 Oct 2015 10:34:13 +0000 (12:34 +0200)]
Use the ODR to speed up type canonicalization

This is the last patch of the series of 11 patches that started at the
patch with the subject:

    constify is_class_type()

And below starts the cover letter of this patch.

While analyzing some libraries like libmozjs.so[1] it appeared that
type canonicalization takes a significant time to comparing composite
types that are re-defined in each translation units again and again.

The One Definition Rule[2] says that two types with the same name
shall designate the same thing; so when a type T being canonicalized
has the same name of a canonical type C in the same ABI corpus, then
this patch considers C as being the canonical type of T, without
comparing T and C structurally.  This saves us from comparing T and C.

Before this patch, `abidw --noout libmozjs.so` was taking
approximatively 5 minutes; with the patch, it takes 1 minutes and 30
seconds.

To do this, the patch changes ABI artifacts to carry a pointer to the
corpus it belongs to.  Whenever an ABI artifact is added to a given
context, the corpus of that context is propagated to the artifact;
that is now possible as the artifact now carries the property of the
corpus it belongs to.

During type canonicalization the ODR-based optimization outlined above
is performed as we can now compare the corpus of a given type again
the one of another type; it's now possible to know if two types come
from the same corpus.

There are a few cases though were the optimization is not performed:
  - anonymous struct; when a struct is anonymous (it has no name, as
    described in the DWARF), the DWARF reader gives it a name
    nonetheless, so that diagnostics can refer to that anonymous type.
    But then all anonymous types in the system have the same name.  So
    when faced with two anonymous types (with the same name) from the
    same corpus, it's wrong to consider that they name the same thing.
    The patch added an "is_anonymous" property to types created by the
    DWARF reader so that such anonymous types can be detected by the
    type canonicalizer; they are thus not involved in this
    optimization.  Note that the abixml writer and reader have been
    updated to emit and read this property.
  - typedefs.  I have seen in some boost code two typedefs of the same
    name refer to different underlying types.  I believe this is a
    violation of ODR.  I'll need to investigate on this later.  And I
    think we really need to detect these ODR violations as part of
    this enhancement request:
    https://sourceware.org/bugzilla/show_bug.cgi?id=18941.
  - pointers, references, arrays and function types, as they can refer
    to the two exceptions above.

This is the last patch of the series which aimed at speeding up type
canonicalization in the context of types being re-defined a lot in
translation units.

[1]: Instruction to build libmozjs.so from the mongodb sources:
- git clone https://github.com/mongodb/mongo.git
- cd mongo
- scons --link-model=dynamic build/opt/third_party/mozjs-38/libmozjs.so

[2] One Definition Rule: https://en.wikipedia.org/wiki/One_Definition_Rule

* include/abg-fwd.h (class corpus): Forward-declare this.
(is_anonymous_type): Declare this new function.
* include/abg-ir.h (corpus_sptr, corpus_wptr): Declare these
typedefs here too.
(translation_unit::{g,s}et_corpus): Declare new member functions.
(type_or_decl_base::{g,s}et_corpus): Likewise.
* src/abg-ir.cc (translation_unit::priv::corpus): New data member.
(translation_unit::priv::priv): Initialize it.
(translation_unit::{g,s}et_corpus): Define new accessors.
(translation_unit::get_global_scope): Propagate the corpus of the
translation unit to its newly created global scope.
(translation_unit::bind_function_type_life_time): Propagate the
corpus of the translation_unit to the added function type.
(type_or_decl_base::priv::corpus_): Add new data member.
(type_or_decl_base::priv::priv): Initialize it.
(type_or_decl_base::{g,s}et_corpus): Define new accessors.
(scope_decl::{add,insert}_member_decl): Propagate the context's
corpus to the member added to the context.
(decl_base::priv::is_anonymous_): Add new data member.
(decl_base::priv::priv): Initialize it.
(decl_base::{s,g}et_is_anonymous): Define accessors.
(is_anonymous_type): Define a new test function.
(decl_base::set_name): Update the "is_anonymous" property.
(type_base::get_canonical_type_for): Implement the ODR-based
optimization to type canonicalization.
* src/abg-corpus.cc (corpus::add): When a translation unit is
added to a corpus, set the corpus of the translation unit.
* src/abg-dwarf-reader.cc (build_enum_type)
(build_class_type_and_add_to_ir): Set the "is_anonymous" flag on
anonymous enums and classes.
* src/abg-reader.cc (read_is_anonymous): Define new static
function.
(build_type_decl, build_enum_type, build_class_decl): Call the new
read_is_anonymous function and set the "is_anonymous" property on
the built type declaration.
* src/abg-writer.cc (write_is_anonymous): Define new static
function.
(write_type_decl, write_enum_type_decl, write_class_decl): Write
the "is_anonymous" property.
* tests/data/test-diff-filter/test31-pr18535-libstdc++-report-0.txt:
Adjust.
* tests/data/test-read-dwarf/test9-pr18818-clang.so.abi: 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/test17-pr19027.so.abi: Likewise.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
9 years agoLate canonicalize all types that reference classes when reading DWARF
Dodji Seketeli [Sun, 4 Oct 2015 10:08:08 +0000 (12:08 +0200)]
Late canonicalize all types that reference classes when reading DWARF

Until now, the DWARF reader would late canonicalize typedefs to
classes, as well as classes.  That is not enough.  Let's also
late-canonicalize pointers, references and array of classes too.  This
is because classes that might not be finished yet might be referenced
by those types, and so we want to wait until they are finished before
we canonicalize them.

* include/abg-fwd.h (peel_array_type): Declare new function.
* src/abg-ir.cc (peel_array_type): Define it.
(peel_typedef_pointer_or_reference_type): Peel arrays too, to get
the type of its element.
* src/abg-dwarf-reader.cc (maybe_canonicalize_type): If a pointer,
reference, array or typedef references a class, then do
late-canonicalize this type.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
9 years agoFix infinite loop in peel_typedef_pointer_or_reference_type
Dodji Seketeli [Sun, 4 Oct 2015 09:30:57 +0000 (11:30 +0200)]
Fix infinite loop in peel_typedef_pointer_or_reference_type

* src/abg-ir.cc (peel_typedef_pointer_or_reference_type): Make
sure the variable tested in the condition is the one updated by
the loop.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
9 years agoTry harder to hash_type_or_decl avoid the slow path
Dodji Seketeli [Fri, 2 Oct 2015 17:57:33 +0000 (19:57 +0200)]
Try harder to hash_type_or_decl avoid the slow path

In hash_type_or_decl, when we encounter a declaration-only class
(those have no canonical type), we not trying to get the canonical
type of the definition, when the class had a definition.  We were
instead going straight to the slow path of computing the recursive
hash of the type.

This patch tries to get the canonical type of the class definition,
when it exists.

* src/abg-ir.cc (hash_type_or_decl):  When a declaration-only
class has a definition, then use the canonical type of that
definition as a hash value.  If the class no definition, only
then, use the slow patfh of computing the recursive progressive
hash value of the type.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
9 years agoDo not use recursive type hashing when writing out function types
Dodji Seketeli [Fri, 2 Oct 2015 17:42:12 +0000 (19:42 +0200)]
Do not use recursive type hashing when writing out function types

When the abixml writer emits function types, it puts function
types that are referenced by pointers or references into a map on the
side.  Unfortunately, that map hashes types by recursively calculating
a progressive hash value.  That is dog slow and we avoid that
throughout the code base.

This patch changes that to use the numerical values of the canonical
type pointer of the function type as a hash, making abixml fast again,
again on big library as libmozjs.so.

* src/abg-writer.cc (typedef fn_shared_ptr_map): Remove.
(write_context::m_referenced_fntypes_map): Change the type of this
into type_ptr_map.
(write_context::{record_fntype_as_referenced,
fntype_is_referenced}): Use the pointer value of the canonical
type of the referenced type as key for the map.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
9 years agoPrevent build_function_type from not canonicalizing certain types
Dodji Seketeli [Fri, 2 Oct 2015 16:27:34 +0000 (18:27 +0200)]
Prevent build_function_type from not canonicalizing certain types

I noticed that in some cases in build_function_type, when building the
sub-types of the function type, the construction of a function type
for the same DIE could be triggered.  This happens frequently for
aggregate types that happen to be recursive.  In those cases, we must
arrange for the construction of the function type for the same DIE to
return the same type that is being currently built by
build_function_type; otherwise, several types are going to be built
for the same DIE, and only one of them is going to be canonicalized.
build_function_type was just not prepared for this.

This patch fixes that.

Please note that the patch changes the test output
/home/dodji/git/libabigail.git/merge/build/tests/output/test-read-dwarf/test12-pr18844.so.abi
but it's a later patch that adjust that file because several patches
are going to require an update to that file.  We are going to update
that patch in one go at the end of the patch series.

* src/abg-dwarf-reader.cc (build_function_type): Associate the
type being built with its DIE, before starting to build the
sub-types.  The current type is then amended with the sub-types
that are built later.
(build_ir_node_from_die): In the case for DW_TAG_subroutine_type,
do not associate the type to the DIE here, as it's been done in
build_function_type.
* src/abg-ir.cc (function_type::set_parameters): Adjust the index
of the parameters being set to the function: they start at 1,
unless the first parameter is artificial, in which case its index
starts at zero.  This is just like what is done when the function
type is constructed directly with the parameters passed as an
argument to the constructor.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
9 years agoFix detection of changes in pointer diff in the comparison engine
Dodji Seketeli [Fri, 2 Oct 2015 16:21:43 +0000 (18:21 +0200)]
Fix detection of changes in pointer diff in the comparison engine

* src/abg-comparison.cc (pointer_diff::has_changes): Just
comparing the underlying type might not be enough.  Let's just
compare the pointer itself.  Now that we have canonical types,
comparing the pointer itself is not slower.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
9 years agoDo not overly canonicalize types during typedef stripping
Dodji Seketeli [Fri, 2 Oct 2015 15:59:52 +0000 (17:59 +0200)]
Do not overly canonicalize types during typedef stripping

strip_typedef() canonicalizes the stripped typed, even if the input
type was not canonicalized.  This can lead to early canonicalization
that is not warranted.  For instance, is_compatible_with_class_type()
calls strip_typedef() and can be called during DWARF reading on types
that haven't been canonicalized yet; this was triggering a
canonicalization what was happening too early.

With this patch, strip_typedef() does not canonicalize a stripped type
if the input type wasn't itself canonicalized.

* src/abg-ir.cc (strip_typedef): Do not canonicalize the stripped
type if the input one is not canonicalized.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
9 years agoCleanup some IR type comparison operators
Dodji Seketeli [Fri, 2 Oct 2015 15:05:23 +0000 (17:05 +0200)]
Cleanup some IR type comparison operators

* include/abg-ir.h (operator==): In the overloads for type_decl,
enum and class_decl, turn the shared_ptr parameter into a const
reference to the shared_ptr.
* src/abg-ir.cc (operator==): Do the same in the definitions.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
9 years agoAdd missing deep equality operator for pointer and reference types
Dodji Seketeli [Fri, 2 Oct 2015 14:50:22 +0000 (16:50 +0200)]
Add missing deep equality operator for pointer and reference types

I noticed that abigail::ir::pointer_type_def_sptr and
abigail::ir::reference_type_def_sptr did not have any free form
operator '==' defined.  So writing a == b with a and b being either
pointer_type_def_sptr or reference_type_def_sptr was using pointer
value comparison, as opposed to deeply comparing the pointer and
reference instances.

This patch adds those two missing operators.

* include/abg-ir.h (pointer_type_def::operator==): Add an overload
for pointer_type_def.
(reference_type_def::operator==) Add an overload for
reference_type_def.
(operator==): Add an overload for pointer_type_def_sptr and
reference_type_def_sptr.
* src/abg-ir.cc (pointer_type_def::operator==): Make the overload
for type_base& use the overload for decl_base&.  Add a new
overload for pointer_type_def& and make is use the overload for
decl_base& too.
(operator==): Add free form overloads for pointer_type_def& and
reference_type_def&.
(reference_type_def::operator==): Add comments. Add an overload
for reference_type_def&.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
9 years agoconstify is_class_type()
Dodji Seketeli [Fri, 2 Oct 2015 18:08:27 +0000 (20:08 +0200)]
constify is_class_type()

This the first patch of a series of 11 patches which aims at speeding
up the time taken by "abidw --noout libmozjs.so".  That shared library
is built among by the mongodb project, among others.  And abidw is
taking around 5 minutes on my old Lenovo X220 laptop.  After the
series of patches, the same command is taking one minute and a half.

The core of the optimization is to speed up type canonicalization that
happens at the end of DWARF reading, once libabigail has built the IR
or the ABI of the entire elf binary.  The optimization comes from an
insight derived from the One Definition Rule of C++, as explained at
https://en.wikipedia.org/wiki/One_Definition_Rule.

But before being able to perform that optimization, several fixes and
code massaging were necessary.  I have split those changes up in the
first 10 patches of the series.  The last patch thus contains the crux
of the optimization.  Its cover letter also contains instructions on
how to build libmozjs.so, from mongodb, for those who want to
replicate the results I have seen.

Note that some of the first 10 patches incur adjustment in the test
suite, but don't carry those necessary adjustments.  All test suite
adjustments are carried by the last, 11Th patch.

The short description of the patches of the series are:

    constify is_class_type()
    Add missing deep equality operator for pointer and reference types
    Cleanup some IR type comparison operators
    Do not overly canonicalize types during typedef stripping
    Fix detection of changes in pointer diff in the comparison engine
    Prevent build_function_type from not canonicalizing certain types
    Do not use recursive type hashing when writing out function types
    Try harder to hash_type_or_decl avoid the slow path
    Fix infinite loop in peel_typedef_pointer_or_reference_type
    Late canonicalize all types that reference classes when reading DWARF
    Use the ODR to speed up type canonicalization

And below is the ChangeLog of this first patch.

* include/abg-fwd.h (is_class_type): Take a pointer to const.
* src/abg-ir.cc (is_class_type): Adjust.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
9 years agoBug 19027 - ABI asymmetry with enums over INT_MAX
Ondrej Oprala [Thu, 1 Oct 2015 09:06:15 +0000 (11:06 +0200)]
Bug 19027 - ABI asymmetry with enums over INT_MAX

* src/abg-reader.cc (build_enum_type_decl): Use strtol
instead of atoi to parse the values and check for overflow.
* tests/data/Makefile.am: Add the new test material to the build
system.
* tests/data/test-read-dwarf/test17-pr19027.so: New test file.
* tests/data/test-read-dwarf/test17-pr19027.so.abi: Likewise.
* tests/test-read-dwarf.cc: Adjust to launch the new test.

Signed-off-by: Ondrej Oprala <ooprala@redhat.com>
9 years agoEncourage people to use autoreconf -i
Dodji Seketeli [Thu, 1 Oct 2015 08:40:51 +0000 (10:40 +0200)]
Encourage people to use autoreconf -i

This lets autoreconf add stuff that might be missing, rather than just
bailing out.

* COMPILING: Mention autoreconf -i, rather than just autoreconf.

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